1
0
mirror of https://github.com/golang/go synced 2024-10-03 10:11:22 -06:00

- bug fix: do not strip lower-case parameter and result names in signatures

- display: show '...' if a struct/interface has fields/methods removed; show
  struct/interface w/o {}'s if all fields/methods were removed; and show the
  {}'s if the struct/interface was empty to begin with

R=rsc
DELTA=41  (36 added, 0 deleted, 5 changed)
OCL=31201
CL=31204
This commit is contained in:
Robert Griesemer 2009-07-06 11:39:48 -07:00
parent d3a2925bb2
commit 4f40f5eaab

View File

@ -4,7 +4,10 @@
package ast package ast
import "go/ast" import (
"go/ast";
"go/token";
)
func filterIdentList(list []*Ident) []*Ident { func filterIdentList(list []*Ident) []*Ident {
@ -39,21 +42,54 @@ func filterFieldList(list []*Field) []*Field {
j++; j++;
} }
} }
if j > 0 && j < len(list) {
// fields have been stripped but there is at least one left;
// add a '...' anonymous field instead
list[j] = &ast.Field{nil, nil, &ast.Ellipsis{}, nil, nil};
j++;
}
return list[0 : j]; return list[0 : j];
} }
func filterParamList(list []*Field) {
for _, f := range list {
filterType(f.Type);
}
}
var noPos token.Position;
func filterType(typ Expr) { func filterType(typ Expr) {
switch t := typ.(type) { switch t := typ.(type) {
case *ArrayType: case *ArrayType:
filterType(t.Elt); filterType(t.Elt);
case *StructType: case *StructType:
// don't change if empty struct
if len(t.Fields) > 0 {
t.Fields = filterFieldList(t.Fields); t.Fields = filterFieldList(t.Fields);
if len(t.Fields) == 0 {
// all fields have been stripped - make look like forward-decl
t.Lbrace = noPos;
t.Fields = nil;
t.Rbrace = noPos;
}
}
case *FuncType: case *FuncType:
t.Params = filterFieldList(t.Params); filterParamList(t.Params);
t.Results = filterFieldList(t.Results); filterParamList(t.Results);
case *InterfaceType: case *InterfaceType:
// don't change if empty interface
if len(t.Methods) > 0 {
t.Methods = filterFieldList(t.Methods); t.Methods = filterFieldList(t.Methods);
if len(t.Methods) == 0 {
// all methods have been stripped - make look like forward-decl
t.Lbrace = noPos;
t.Methods = nil;
t.Rbrace = noPos;
}
}
case *MapType: case *MapType:
filterType(t.Key); filterType(t.Key);
filterType(t.Value); filterType(t.Value);