]> Cypherpunks repositories - gostls13.git/commitdiff
- ast.FilterExports: filter non-exported anonymous fields
authorRobert Griesemer <gri@golang.org>
Tue, 7 Jul 2009 19:02:54 +0000 (12:02 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 7 Jul 2009 19:02:54 +0000 (12:02 -0700)
- fixed typo in parser.go
- removed test w/ syntax errors from gofmt test script

R=rsc
DELTA=25  (21 added, 0 deleted, 4 changed)
OCL=31296
CL=31298

src/cmd/gofmt/test.sh
src/pkg/go/ast/filter.go
src/pkg/go/parser/parser.go

index 6dd1fc4bc19cf18dbc8e42530d3311638da99802..d37070bad15e04fd7ee668f29da8f7ca14507dc7 100755 (executable)
@@ -34,7 +34,7 @@ apply1() {
        test_errors.go | calc.go | method1.go | selftest1.go | func3.go | const2.go | \
        bug014.go | bug025.go | bug029.go | bug032.go | bug039.go | bug040.go | bug050.go |  bug068.go | \
        bug088.go | bug083.go | bug106.go | bug121.go | bug125.go | bug126.go | bug132.go | bug133.go | \
-       bug134.go | bug160.go | bug166.go ) ;;
+       bug134.go | bug160.go | bug163.go | bug166.go ) ;;
        * ) $1 $2; count $F;;
        esac
 }
index a9dd08015223acac69af68c579fbdef736bd07ac..8bb90d995598680e3be7f37f8b9fe83820bec91c 100644 (file)
@@ -22,6 +22,23 @@ func filterIdentList(list []*Ident) []*Ident {
 }
 
 
+// isExportedType assumes that typ is a correct type.
+func isExportedType(typ Expr) bool {
+       switch t := typ.(type) {
+       case *Ident:
+               return t.IsExported();
+       case *ParenExpr:
+               return isExportedType(t.X);
+       case *SelectorExpr:
+               // assume t.X is a typename
+               return t.Sel.IsExported();
+       case *StarExpr:
+               return isExportedType(t.X);
+       }
+       return false;
+}
+
+
 func filterType(typ Expr)
 
 func filterFieldList(list []*Field) []*Field {
@@ -30,8 +47,12 @@ func filterFieldList(list []*Field) []*Field {
                exported := false;
                if len(f.Names) == 0 {
                        // anonymous field
-                       // TODO(gri) check if the type is exported for anonymous field
-                       exported = true;
+                       // (Note that a non-exported anonymous field
+                       // may still refer to a type with exported
+                       // fields, so this is not absolutely correct.
+                       // However, this cannot be done w/o complete
+                       // type information.)
+                       exported = isExportedType(f.Type);
                } else {
                        f.Names = filterIdentList(f.Names);
                        exported = len(f.Names) > 0;
index 86b578b650a5d9313d557af2176b3efb6e9e0b46..273b36607be2064fae5db2dc19e0ce3932c0d044 100644 (file)
@@ -1094,7 +1094,7 @@ func (p *parser) parseCompositeLit(typ ast.Expr) ast.Expr {
 
 // TODO Consider different approach to checking syntax after parsing:
 //      Provide a arguments (set of flags) to parsing functions
-//      restricting what they are syupposed to accept depending
+//      restricting what they are supposed to accept depending
 //      on context.
 
 // checkExpr checks that x is an expression (and not a type).