1
0
mirror of https://github.com/golang/go synced 2024-11-26 06:57:56 -07:00

- ast.FilterExports: filter non-exported anonymous fields

- 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
This commit is contained in:
Robert Griesemer 2009-07-07 12:02:54 -07:00
parent a1b64821f8
commit 61824ff3a4
3 changed files with 25 additions and 4 deletions

View File

@ -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
}

View 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;

View 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).