]> Cypherpunks repositories - gostls13.git/commitdiff
go/ast: fix FuncType.Pos() impl. and FuncType.Params documentation
authorRobert Griesemer <gri@golang.org>
Wed, 22 May 2013 20:36:43 +0000 (13:36 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 22 May 2013 20:36:43 +0000 (13:36 -0700)
As pointed out by adonovan.

R=golang-dev, adonovan
CC=golang-dev
https://golang.org/cl/9662045

src/pkg/go/ast/ast.go
src/pkg/go/ast/filter.go

index bf533d1d24faf8cfd66d19ccbfb7c9a40ceaff75..e8599184a67fb46bda432828f57b56c68580a665 100644 (file)
@@ -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).
index 71c9ed7766b193de5614c8780cacccba4d8e8b93..fc3eeb4a1db73d5c9c5b42f0688df43cd9746596 100644 (file)
@@ -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.