Skip to content

Commit 28b40f3

Browse files
committed
go/types: add doc strings to various undocumented exported objects
Fixes #22747. Change-Id: I498cb29f18bd9b59b13dc2ddc3a613cc12ac2a14 Reviewed-on: https://go-review.googlesource.com/110975 Reviewed-by: Matthew Dempsky <[email protected]>
1 parent e8d417d commit 28b40f3

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

src/go/types/object.go

+29-9
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,31 @@ type object struct {
8181
scopePos_ token.Pos
8282
}
8383

84-
func (obj *object) Parent() *Scope { return obj.parent }
85-
func (obj *object) Pos() token.Pos { return obj.pos }
86-
func (obj *object) Pkg() *Package { return obj.pkg }
87-
func (obj *object) Name() string { return obj.name }
88-
func (obj *object) Type() Type { return obj.typ }
89-
func (obj *object) Exported() bool { return ast.IsExported(obj.name) }
90-
func (obj *object) Id() string { return Id(obj.pkg, obj.name) }
84+
// Parent returns the scope in which the object is declared.
85+
// The result is nil for methods and struct fields.
86+
func (obj *object) Parent() *Scope { return obj.parent }
87+
88+
// Pos returns the declaration position of the object's identifier.
89+
func (obj *object) Pos() token.Pos { return obj.pos }
90+
91+
// Pkg returns the package to which the object belongs.
92+
// The result is nil for labels and objects in the Universe scope.
93+
func (obj *object) Pkg() *Package { return obj.pkg }
94+
95+
// Name returns the object's (package-local, unqualified) name.
96+
func (obj *object) Name() string { return obj.name }
97+
98+
// Type returns the object's type.
99+
func (obj *object) Type() Type { return obj.typ }
100+
101+
// Exported reports whether the object is exported (starts with a capital letter).
102+
// It doesn't take into account whether the object is in a local (function) scope
103+
// or not.
104+
func (obj *object) Exported() bool { return ast.IsExported(obj.name) }
105+
106+
// Id is a wrapper for Id(obj.Pkg(), obj.Name()).
107+
func (obj *object) Id() string { return Id(obj.pkg, obj.name) }
108+
91109
func (obj *object) String() string { panic("abstract") }
92110
func (obj *object) order() uint32 { return obj.order_ }
93111
func (obj *object) scopePos() token.Pos { return obj.scopePos_ }
@@ -149,10 +167,12 @@ func NewConst(pos token.Pos, pkg *Package, name string, typ Type, val constant.V
149167
return &Const{object{nil, pos, pkg, name, typ, 0, token.NoPos}, val, false}
150168
}
151169

170+
// Val returns the constant's value.
152171
func (obj *Const) Val() constant.Value { return obj.val }
153-
func (*Const) isDependency() {} // a constant may be a dependency of an initialization expression
154172

155-
// A TypeName represents a name for a (named or alias) type.
173+
func (*Const) isDependency() {} // a constant may be a dependency of an initialization expression
174+
175+
// A TypeName represents a name for a (defined or alias) type.
156176
type TypeName struct {
157177
object
158178
}

src/go/types/universe.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@ import (
1212
"strings"
1313
)
1414

15+
// The Universe scope contains all predeclared objects of Go.
16+
// It is the outermost scope of any chain of nested scopes.
17+
var Universe *Scope
18+
19+
// The Unsafe package is the package returned by an importer
20+
// for the import path "unsafe".
21+
var Unsafe *Package
22+
1523
var (
16-
Universe *Scope
17-
Unsafe *Package
1824
universeIota *Const
1925
universeByte *Basic // uint8 alias, but has name "byte"
2026
universeRune *Basic // int32 alias, but has name "rune"

0 commit comments

Comments
 (0)