mirror of
https://github.com/golang/go
synced 2024-11-20 07:14:40 -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:
parent
a1b64821f8
commit
61824ff3a4
@ -34,7 +34,7 @@ apply1() {
|
|||||||
test_errors.go | calc.go | method1.go | selftest1.go | func3.go | const2.go | \
|
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 | \
|
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 | \
|
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;;
|
* ) $1 $2; count $F;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
@ -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 filterType(typ Expr)
|
||||||
|
|
||||||
func filterFieldList(list []*Field) []*Field {
|
func filterFieldList(list []*Field) []*Field {
|
||||||
@ -30,8 +47,12 @@ func filterFieldList(list []*Field) []*Field {
|
|||||||
exported := false;
|
exported := false;
|
||||||
if len(f.Names) == 0 {
|
if len(f.Names) == 0 {
|
||||||
// anonymous field
|
// anonymous field
|
||||||
// TODO(gri) check if the type is exported for anonymous field
|
// (Note that a non-exported anonymous field
|
||||||
exported = true;
|
// 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 {
|
} else {
|
||||||
f.Names = filterIdentList(f.Names);
|
f.Names = filterIdentList(f.Names);
|
||||||
exported = len(f.Names) > 0;
|
exported = len(f.Names) > 0;
|
||||||
|
@ -1094,7 +1094,7 @@ func (p *parser) parseCompositeLit(typ ast.Expr) ast.Expr {
|
|||||||
|
|
||||||
// TODO Consider different approach to checking syntax after parsing:
|
// TODO Consider different approach to checking syntax after parsing:
|
||||||
// Provide a arguments (set of flags) to parsing functions
|
// 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.
|
// on context.
|
||||||
|
|
||||||
// checkExpr checks that x is an expression (and not a type).
|
// checkExpr checks that x is an expression (and not a type).
|
||||||
|
Loading…
Reference in New Issue
Block a user