1
0
mirror of https://github.com/golang/go synced 2024-11-18 22:44:48 -07:00

go.tools/go/types: add Var.IsField() accessor, and print "field" not "var".

R=gri
CC=golang-dev
https://golang.org/cl/16780043
This commit is contained in:
Alan Donovan 2013-10-24 17:07:11 -04:00
parent c20165988a
commit 96bdcd22e3

View File

@ -169,6 +169,7 @@ type Var struct {
anonymous bool // if set, the variable is an anonymous struct field, and name is the type name
visited bool // for initialization cycle detection
isField bool // var is struct field
}
func NewVar(pos token.Pos, pkg *Package, name string, typ Type) *Var {
@ -180,11 +181,18 @@ func NewParam(pos token.Pos, pkg *Package, name string, typ Type) *Var {
}
func NewField(pos token.Pos, pkg *Package, name string, typ Type, anonymous bool) *Var {
return &Var{object: object{nil, pos, pkg, name, typ, false}, anonymous: anonymous}
return &Var{object: object{nil, pos, pkg, name, typ, false}, anonymous: anonymous, isField: true}
}
func (obj *Var) Anonymous() bool { return obj.anonymous }
func (obj *Var) String() string { return obj.toString("var", obj.typ) }
func (obj *Var) String() string {
kind := "var"
if obj.isField {
kind = "field"
}
return obj.toString(kind, obj.typ)
}
func (obj *Var) IsField() bool { return obj.isField }
// A Func represents a declared function, concrete method, or abstract
// (interface) method. Its Type() is always a *Signature.