From: Robert Griesemer Date: Wed, 22 May 2013 20:36:43 +0000 (-0700) Subject: go/ast: fix FuncType.Pos() impl. and FuncType.Params documentation X-Git-Tag: go1.2rc2~1436 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=75b62e367bfe0b4935fb08f5941f3a9a99932dae;p=gostls13.git go/ast: fix FuncType.Pos() impl. and FuncType.Params documentation As pointed out by adonovan. R=golang-dev, adonovan CC=golang-dev https://golang.org/cl/9662045 --- diff --git a/src/pkg/go/ast/ast.go b/src/pkg/go/ast/ast.go index bf533d1d24..e8599184a6 100644 --- a/src/pkg/go/ast/ast.go +++ b/src/pkg/go/ast/ast.go @@ -385,8 +385,8 @@ type ( // A FuncType node represents a function type. FuncType struct { - Func token.Pos // position of "func" keyword - Params *FieldList // (incoming) parameters; or nil + Func token.Pos // position of "func" keyword (token.NoPos if there is no "func") + Params *FieldList // (incoming) parameters; non-nil Results *FieldList // (outgoing) results; or nil } @@ -407,7 +407,7 @@ type ( // A ChanType node represents a channel type. ChanType struct { Begin token.Pos // position of "chan" keyword or "<-" (whichever comes first) - Arrow token.Pos // position of "<-" (noPos if there is no "<-") + Arrow token.Pos // position of "<-" (token.NoPos if there is no "<-") Dir ChanDir // channel direction Value Expr // value type } @@ -438,10 +438,15 @@ func (x *BinaryExpr) Pos() token.Pos { return x.X.Pos() } func (x *KeyValueExpr) Pos() token.Pos { return x.Key.Pos() } func (x *ArrayType) Pos() token.Pos { return x.Lbrack } func (x *StructType) Pos() token.Pos { return x.Struct } -func (x *FuncType) Pos() token.Pos { return x.Func } -func (x *InterfaceType) Pos() token.Pos { return x.Interface } -func (x *MapType) Pos() token.Pos { return x.Map } -func (x *ChanType) Pos() token.Pos { return x.Begin } +func (x *FuncType) Pos() token.Pos { + if x.Func.IsValid() { + return x.Func + } + return x.Params.Pos() // interface method declarations have no "func" keyword +} +func (x *InterfaceType) Pos() token.Pos { return x.Interface } +func (x *MapType) Pos() token.Pos { return x.Map } +func (x *ChanType) Pos() token.Pos { return x.Begin } func (x *BadExpr) End() token.Pos { return x.To } func (x *Ident) End() token.Pos { return token.Pos(int(x.NamePos) + len(x.Name)) } @@ -511,12 +516,10 @@ func (*ChanType) exprNode() {} // ---------------------------------------------------------------------------- // Convenience functions for Idents -var noPos token.Pos - // NewIdent creates a new Ident without position. // Useful for ASTs generated by code other than the Go parser. // -func NewIdent(name string) *Ident { return &Ident{noPos, name, nil} } +func NewIdent(name string) *Ident { return &Ident{token.NoPos, name, nil} } // IsExported returns whether name is an exported Go symbol // (i.e., whether it begins with an uppercase letter). diff --git a/src/pkg/go/ast/filter.go b/src/pkg/go/ast/filter.go index 71c9ed7766..fc3eeb4a1d 100644 --- a/src/pkg/go/ast/filter.go +++ b/src/pkg/go/ast/filter.go @@ -308,7 +308,7 @@ func nameOf(f *FuncDecl) string { // separator is an empty //-style comment that is interspersed between // different comment groups when they are concatenated into a single group // -var separator = &Comment{noPos, "//"} +var separator = &Comment{token.NoPos, "//"} // MergePackageFiles creates a file AST by merging the ASTs of the // files belonging to a package. The mode flags control merging behavior.