go/internal: gofmt
Gofmt to update doc comments to the new formatting.
(There are so many files in x/tools I am breaking up the
gofmt'ing into multiple CLs.)
For golang/go#51082.
Change-Id: Ibb9d8a38c0bf6973419cb1efc13f0775000a607a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/399364
Run-TryBot: Russ Cox <rsc@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
diff --git a/go/internal/cgo/cgo.go b/go/internal/cgo/cgo.go
index d01fb04..3fce480 100644
--- a/go/internal/cgo/cgo.go
+++ b/go/internal/cgo/cgo.go
@@ -69,7 +69,6 @@
// ProcessFiles invokes the cgo preprocessor on bp.CgoFiles, parses
// the output and returns the resulting ASTs.
-//
func ProcessFiles(bp *build.Package, fset *token.FileSet, DisplayPath func(path string) string, mode parser.Mode) ([]*ast.File, error) {
tmpdir, err := ioutil.TempDir("", strings.Replace(bp.ImportPath, "/", "_", -1)+"_C")
if err != nil {
diff --git a/go/internal/gccgoimporter/parser.go b/go/internal/gccgoimporter/parser.go
index 7f07553..5c24845 100644
--- a/go/internal/gccgoimporter/parser.go
+++ b/go/internal/gccgoimporter/parser.go
@@ -127,8 +127,10 @@
return str
}
-// unquotedString = { unquotedStringChar } .
-// unquotedStringChar = <neither a whitespace nor a ';' char> .
+// parseUnquotedString parses an UnquotedString:
+//
+// unquotedString = { unquotedStringChar } .
+// unquotedStringChar = <neither a whitespace nor a ';' char> .
func (p *parser) parseUnquotedString() string {
if p.tok == scanner.EOF {
p.error("unexpected EOF")
@@ -163,7 +165,10 @@
return p.parseQualifiedNameStr(p.parseUnquotedString())
}
-// qualifiedName = [ ["."] unquotedString "." ] unquotedString .
+// parseQualifiedNameStr is given the leading name (unquoted by the caller if necessary)
+// and then parses the remainder of a qualified name:
+//
+// qualifiedName = [ ["."] unquotedString "." ] unquotedString .
//
// The above production uses greedy matching.
func (p *parser) parseQualifiedNameStr(unquotedName string) (pkgpath, name string) {
@@ -191,7 +196,6 @@
// getPkg returns the package for a given path. If the package is
// not found but we have a package name, create the package and
// add it to the p.imports map.
-//
func (p *parser) getPkg(pkgpath, name string) *types.Package {
// package unsafe is not in the imports map - handle explicitly
if pkgpath == "unsafe" {
@@ -208,7 +212,7 @@
// parseExportedName is like parseQualifiedName, but
// the package path is resolved to an imported *types.Package.
//
-// ExportedName = string [string] .
+// ExportedName = string [string] .
func (p *parser) parseExportedName() (pkg *types.Package, name string) {
path, name := p.parseQualifiedName()
var pkgname string
@@ -222,7 +226,9 @@
return
}
-// Name = QualifiedName | "?" .
+// parseName parses a Name:
+//
+// Name = QualifiedName | "?" .
func (p *parser) parseName() string {
if p.tok == '?' {
// Anonymous.
@@ -241,7 +247,9 @@
return typ
}
-// Field = Name Type [string] .
+// parseField parses a Field:
+//
+// Field = Name Type [string] .
func (p *parser) parseField(pkg *types.Package) (field *types.Var, tag string) {
name := p.parseName()
typ, n := p.parseTypeExtended(pkg)
@@ -269,7 +277,9 @@
return
}
-// Param = Name ["..."] Type .
+// parseParam parses a Param:
+//
+// Param = Name ["..."] Type .
func (p *parser) parseParam(pkg *types.Package) (param *types.Var, isVariadic bool) {
name := p.parseName()
// Ignore names invented for inlinable functions.
@@ -298,7 +308,9 @@
return
}
-// Var = Name Type .
+// parseVar parses a Var:
+//
+// Var = Name Type .
func (p *parser) parseVar(pkg *types.Package) *types.Var {
name := p.parseName()
v := types.NewVar(token.NoPos, pkg, name, p.parseType(pkg))
@@ -311,7 +323,9 @@
return v
}
-// Conversion = "convert" "(" Type "," ConstValue ")" .
+// parseConversion parses a Conversion:
+//
+// Conversion = "convert" "(" Type "," ConstValue ")" .
func (p *parser) parseConversion(pkg *types.Package) (val constant.Value, typ types.Type) {
p.expectKeyword("convert")
p.expect('(')
@@ -322,8 +336,10 @@
return
}
-// ConstValue = string | "false" | "true" | ["-"] (int ["'"] | FloatOrComplex) | Conversion .
-// FloatOrComplex = float ["i" | ("+"|"-") float "i"] .
+// parseConstValue parses a ConstValue:
+//
+// ConstValue = string | "false" | "true" | ["-"] (int ["'"] | FloatOrComplex) | Conversion .
+// FloatOrComplex = float ["i" | ("+"|"-") float "i"] .
func (p *parser) parseConstValue(pkg *types.Package) (val constant.Value, typ types.Type) {
// v3 changed to $false, $true, $convert, to avoid confusion
// with variable names in inline function bodies.
@@ -429,7 +445,9 @@
return
}
-// Const = Name [Type] "=" ConstValue .
+// parseConst parses a Const:
+//
+// Const = Name [Type] "=" ConstValue .
func (p *parser) parseConst(pkg *types.Package) *types.Const {
name := p.parseName()
var typ types.Type
@@ -510,9 +528,11 @@
}
}
-// NamedType = TypeName [ "=" ] Type { Method } .
-// TypeName = ExportedName .
-// Method = "func" "(" Param ")" Name ParamList ResultList [InlineBody] ";" .
+// parseNamedType parses a NamedType:
+//
+// NamedType = TypeName [ "=" ] Type { Method } .
+// TypeName = ExportedName .
+// Method = "func" "(" Param ")" Name ParamList ResultList [InlineBody] ";" .
func (p *parser) parseNamedType(nlist []interface{}) types.Type {
pkg, name := p.parseExportedName()
scope := pkg.Scope()
@@ -629,7 +649,9 @@
return int(n)
}
-// ArrayOrSliceType = "[" [ int ] "]" Type .
+// parseArrayOrSliceType parses an ArrayOrSliceType:
+//
+// ArrayOrSliceType = "[" [ int ] "]" Type .
func (p *parser) parseArrayOrSliceType(pkg *types.Package, nlist []interface{}) types.Type {
p.expect('[')
if p.tok == ']' {
@@ -652,7 +674,9 @@
return t
}
-// MapType = "map" "[" Type "]" Type .
+// parseMapType parses a MapType:
+//
+// MapType = "map" "[" Type "]" Type .
func (p *parser) parseMapType(pkg *types.Package, nlist []interface{}) types.Type {
p.expectKeyword("map")
@@ -668,7 +692,9 @@
return t
}
-// ChanType = "chan" ["<-" | "-<"] Type .
+// parseChanType parses a ChanType:
+//
+// ChanType = "chan" ["<-" | "-<"] Type .
func (p *parser) parseChanType(pkg *types.Package, nlist []interface{}) types.Type {
p.expectKeyword("chan")
@@ -695,7 +721,9 @@
return t
}
-// StructType = "struct" "{" { Field } "}" .
+// parseStructType parses a StructType:
+//
+// StructType = "struct" "{" { Field } "}" .
func (p *parser) parseStructType(pkg *types.Package, nlist []interface{}) types.Type {
p.expectKeyword("struct")
@@ -718,7 +746,9 @@
return t
}
-// ParamList = "(" [ { Parameter "," } Parameter ] ")" .
+// parseParamList parses a ParamList:
+//
+// ParamList = "(" [ { Parameter "," } Parameter ] ")" .
func (p *parser) parseParamList(pkg *types.Package) (*types.Tuple, bool) {
var list []*types.Var
isVariadic := false
@@ -742,7 +772,9 @@
return types.NewTuple(list...), isVariadic
}
-// ResultList = Type | ParamList .
+// parseResultList parses a ResultList:
+//
+// ResultList = Type | ParamList .
func (p *parser) parseResultList(pkg *types.Package) *types.Tuple {
switch p.tok {
case '<':
@@ -762,7 +794,9 @@
}
}
-// FunctionType = ParamList ResultList .
+// parseFunctionType parses a FunctionType:
+//
+// FunctionType = ParamList ResultList .
func (p *parser) parseFunctionType(pkg *types.Package, nlist []interface{}) *types.Signature {
t := new(types.Signature)
p.update(t, nlist)
@@ -774,7 +808,9 @@
return t
}
-// Func = Name FunctionType [InlineBody] .
+// parseFunc parses a Func:
+//
+// Func = Name FunctionType [InlineBody] .
func (p *parser) parseFunc(pkg *types.Package) *types.Func {
if p.tok == '/' {
// Skip an /*asm ID */ comment.
@@ -802,7 +838,9 @@
return f
}
-// InterfaceType = "interface" "{" { ("?" Type | Func) ";" } "}" .
+// parseInterfaceType parses an InterfaceType:
+//
+// InterfaceType = "interface" "{" { ("?" Type | Func) ";" } "}" .
func (p *parser) parseInterfaceType(pkg *types.Package, nlist []interface{}) types.Type {
p.expectKeyword("interface")
@@ -831,7 +869,9 @@
return t
}
-// PointerType = "*" ("any" | Type) .
+// parsePointerType parses a PointerType:
+//
+// PointerType = "*" ("any" | Type) .
func (p *parser) parsePointerType(pkg *types.Package, nlist []interface{}) types.Type {
p.expect('*')
if p.tok == scanner.Ident {
@@ -849,7 +889,9 @@
return t
}
-// TypeSpec = NamedType | MapType | ChanType | StructType | InterfaceType | PointerType | ArrayOrSliceType | FunctionType .
+// parseTypeSpec parses a TypeSpec:
+//
+// TypeSpec = NamedType | MapType | ChanType | StructType | InterfaceType | PointerType | ArrayOrSliceType | FunctionType .
func (p *parser) parseTypeSpec(pkg *types.Package, nlist []interface{}) types.Type {
switch p.tok {
case scanner.String:
@@ -935,10 +977,11 @@
}[typ]
}
-// Type = "<" "type" ( "-" int | int [ TypeSpec ] ) ">" .
+// parseType parses a Type:
+//
+// Type = "<" "type" ( "-" int | int [ TypeSpec ] ) ">" .
//
// parseType updates the type map to t for all type numbers n.
-//
func (p *parser) parseType(pkg *types.Package, n ...interface{}) types.Type {
p.expect('<')
t, _ := p.parseTypeAfterAngle(pkg, n...)
@@ -1028,7 +1071,9 @@
}
}
-// Types = "types" maxp1 exportedp1 (offset length)* .
+// parseTypes parses a Types:
+//
+// Types = "types" maxp1 exportedp1 (offset length)* .
func (p *parser) parseTypes(pkg *types.Package) {
maxp1 := p.parseInt()
exportedp1 := p.parseInt()
@@ -1102,7 +1147,9 @@
}
}
-// PackageInit = unquotedString unquotedString int .
+// parsePackageInit parses a PackageInit:
+//
+// PackageInit = unquotedString unquotedString int .
func (p *parser) parsePackageInit() PackageInit {
name := p.parseUnquotedString()
initfunc := p.parseUnquotedString()
@@ -1120,10 +1167,12 @@
}
}
-// InitDataDirective = ( "v1" | "v2" | "v3" ) ";" |
-// "priority" int ";" |
-// "init" { PackageInit } ";" |
-// "checksum" unquotedString ";" .
+// parseInitDateDirective parses an InitDataDirective:
+//
+// InitDataDirective = ( "v1" | "v2" | "v3" ) ";" |
+// "priority" int ";" |
+// "init" { PackageInit } ";" |
+// "checksum" unquotedString ";" .
func (p *parser) parseInitDataDirective() {
if p.tok != scanner.Ident {
// unexpected token kind; panic
@@ -1173,16 +1222,18 @@
}
}
-// Directive = InitDataDirective |
-// "package" unquotedString [ unquotedString ] [ unquotedString ] ";" |
-// "pkgpath" unquotedString ";" |
-// "prefix" unquotedString ";" |
-// "import" unquotedString unquotedString string ";" |
-// "indirectimport" unquotedString unquotedstring ";" |
-// "func" Func ";" |
-// "type" Type ";" |
-// "var" Var ";" |
-// "const" Const ";" .
+// parseDirective parses a Directive:
+//
+// Directive = InitDataDirective |
+// "package" unquotedString [ unquotedString ] [ unquotedString ] ";" |
+// "pkgpath" unquotedString ";" |
+// "prefix" unquotedString ";" |
+// "import" unquotedString unquotedString string ";" |
+// "indirectimport" unquotedString unquotedstring ";" |
+// "func" Func ";" |
+// "type" Type ";" |
+// "var" Var ";" |
+// "const" Const ";" .
func (p *parser) parseDirective() {
if p.tok != scanner.Ident {
// unexpected token kind; panic
@@ -1266,7 +1317,9 @@
}
}
-// Package = { Directive } .
+// parsePackage parses a Package:
+//
+// Package = { Directive } .
func (p *parser) parsePackage() *types.Package {
for p.tok != scanner.EOF {
p.parseDirective()
diff --git a/go/internal/gccgoimporter/testenv_test.go b/go/internal/gccgoimporter/testenv_test.go
index 7afa464..9be8dcb 100644
--- a/go/internal/gccgoimporter/testenv_test.go
+++ b/go/internal/gccgoimporter/testenv_test.go
@@ -12,7 +12,7 @@
"testing"
)
-// HasGoBuild reports whether the current system can build programs with ``go build''
+// HasGoBuild reports whether the current system can build programs with “go build”
// and then run them with os.StartProcess or exec.Command.
func HasGoBuild() bool {
switch runtime.GOOS {
@@ -40,7 +40,7 @@
return true
}
-// MustHaveGoBuild checks that the current system can build programs with ``go build''
+// MustHaveGoBuild checks that the current system can build programs with “go build”
// and then run them with os.StartProcess or exec.Command.
// If not, MustHaveGoBuild calls t.Skip with an explanation.
func MustHaveGoBuild(t *testing.T) {
diff --git a/go/internal/gcimporter/bexport.go b/go/internal/gcimporter/bexport.go
index 0a3cdb9..196cb3f 100644
--- a/go/internal/gcimporter/bexport.go
+++ b/go/internal/gcimporter/bexport.go
@@ -35,16 +35,18 @@
const debugFormat = false // default: false
// Current export format version. Increase with each format change.
+//
// Note: The latest binary (non-indexed) export format is at version 6.
-// This exporter is still at level 4, but it doesn't matter since
-// the binary importer can handle older versions just fine.
-// 6: package height (CL 105038) -- NOT IMPLEMENTED HERE
-// 5: improved position encoding efficiency (issue 20080, CL 41619) -- NOT IMPLEMEMTED HERE
-// 4: type name objects support type aliases, uses aliasTag
-// 3: Go1.8 encoding (same as version 2, aliasTag defined but never used)
-// 2: removed unused bool in ODCL export (compiler only)
-// 1: header format change (more regular), export package for _ struct fields
-// 0: Go1.7 encoding
+// This exporter is still at level 4, but it doesn't matter since
+// the binary importer can handle older versions just fine.
+//
+// 6: package height (CL 105038) -- NOT IMPLEMENTED HERE
+// 5: improved position encoding efficiency (issue 20080, CL 41619) -- NOT IMPLEMENTED HERE
+// 4: type name objects support type aliases, uses aliasTag
+// 3: Go1.8 encoding (same as version 2, aliasTag defined but never used)
+// 2: removed unused bool in ODCL export (compiler only)
+// 1: header format change (more regular), export package for _ struct fields
+// 0: Go1.7 encoding
const exportVersion = 4
// trackAllTypes enables cycle tracking for all types, not just named
diff --git a/go/internal/gcimporter/gcimporter.go b/go/internal/gcimporter/gcimporter.go
index 3ab6683..493bfa0 100644
--- a/go/internal/gcimporter/gcimporter.go
+++ b/go/internal/gcimporter/gcimporter.go
@@ -45,7 +45,6 @@
// the build.Default build.Context). A relative srcDir is interpreted
// relative to the current working directory.
// If no file was found, an empty filename is returned.
-//
func FindPkg(path, srcDir string) (filename, id string) {
if path == "" {
return
@@ -109,7 +108,6 @@
// If packages[id] contains the completely imported package, that package
// can be used directly, and there is no need to call this function (but
// there is also no harm but for extra time used).
-//
func ImportData(packages map[string]*types.Package, filename, id string, data io.Reader) (pkg *types.Package, err error) {
// support for parser error handling
defer func() {
@@ -133,7 +131,6 @@
// Import imports a gc-generated package given its import path and srcDir, adds
// the corresponding package object to the packages map, and returns the object.
// The packages map must contain all packages already imported.
-//
func Import(packages map[string]*types.Package, path, srcDir string, lookup func(path string) (io.ReadCloser, error)) (pkg *types.Package, err error) {
var rc io.ReadCloser
var filename, id string
@@ -348,8 +345,9 @@
// ----------------------------------------------------------------------------
// Qualified and unqualified names
-// PackageId = string_lit .
+// parsePackageID parses a PackageId:
//
+// PackageId = string_lit .
func (p *parser) parsePackageID() string {
id, err := strconv.Unquote(p.expect(scanner.String))
if err != nil {
@@ -363,13 +361,16 @@
return id
}
-// PackageName = ident .
+// parsePackageName parse a PackageName:
//
+// PackageName = ident .
func (p *parser) parsePackageName() string {
return p.expect(scanner.Ident)
}
-// dotIdentifier = ( ident | '·' ) { ident | int | '·' } .
+// parseDotIdent parses a dotIdentifier:
+//
+// dotIdentifier = ( ident | '·' ) { ident | int | '·' } .
func (p *parser) parseDotIdent() string {
ident := ""
if p.tok != scanner.Int {
@@ -386,8 +387,9 @@
return ident
}
-// QualifiedName = "@" PackageId "." ( "?" | dotIdentifier ) .
+// parseQualifiedName parses a QualifiedName:
//
+// QualifiedName = "@" PackageId "." ( "?" | dotIdentifier ) .
func (p *parser) parseQualifiedName() (id, name string) {
p.expect('@')
id = p.parsePackageID()
@@ -410,7 +412,6 @@
// id identifies a package, usually by a canonical package path like
// "encoding/json" but possibly by a non-canonical import path like
// "./json".
-//
func (p *parser) getPkg(id, name string) *types.Package {
// package unsafe is not in the packages maps - handle explicitly
if id == "unsafe" {
@@ -446,7 +447,6 @@
// parseExportedName is like parseQualifiedName, but
// the package id is resolved to an imported *types.Package.
-//
func (p *parser) parseExportedName() (pkg *types.Package, name string) {
id, name := p.parseQualifiedName()
pkg = p.getPkg(id, "")
@@ -456,8 +456,9 @@
// ----------------------------------------------------------------------------
// Types
-// BasicType = identifier .
+// parseBasicType parses a BasicType:
//
+// BasicType = identifier .
func (p *parser) parseBasicType() types.Type {
id := p.expect(scanner.Ident)
obj := types.Universe.Lookup(id)
@@ -468,8 +469,9 @@
return nil
}
-// ArrayType = "[" int_lit "]" Type .
+// parseArrayType parses an ArrayType:
//
+// ArrayType = "[" int_lit "]" Type .
func (p *parser) parseArrayType(parent *types.Package) types.Type {
// "[" already consumed and lookahead known not to be "]"
lit := p.expect(scanner.Int)
@@ -482,8 +484,9 @@
return types.NewArray(elem, n)
}
-// MapType = "map" "[" Type "]" Type .
+// parseMapType parses a MapType:
//
+// MapType = "map" "[" Type "]" Type .
func (p *parser) parseMapType(parent *types.Package) types.Type {
p.expectKeyword("map")
p.expect('[')
@@ -493,7 +496,9 @@
return types.NewMap(key, elem)
}
-// Name = identifier | "?" | QualifiedName .
+// parseName parses a Name:
+//
+// Name = identifier | "?" | QualifiedName .
//
// For unqualified and anonymous names, the returned package is the parent
// package unless parent == nil, in which case the returned package is the
@@ -505,7 +510,6 @@
// it doesn't exist yet) unless materializePkg is set (which creates an
// unnamed package with valid package path). In the latter case, a
// subsequent import clause is expected to provide a name for the package.
-//
func (p *parser) parseName(parent *types.Package, materializePkg bool) (pkg *types.Package, name string) {
pkg = parent
if pkg == nil {
@@ -539,8 +543,9 @@
return typ
}
-// Field = Name Type [ string_lit ] .
+// parseField parses a Field:
//
+// Field = Name Type [ string_lit ] .
func (p *parser) parseField(parent *types.Package) (*types.Var, string) {
pkg, name := p.parseName(parent, true)
@@ -583,9 +588,10 @@
return types.NewField(token.NoPos, pkg, name, typ, anonymous), tag
}
-// StructType = "struct" "{" [ FieldList ] "}" .
-// FieldList = Field { ";" Field } .
+// parseStructType parses a StructType:
//
+// StructType = "struct" "{" [ FieldList ] "}" .
+// FieldList = Field { ";" Field } .
func (p *parser) parseStructType(parent *types.Package) types.Type {
var fields []*types.Var
var tags []string
@@ -610,8 +616,9 @@
return types.NewStruct(fields, tags)
}
-// Parameter = ( identifier | "?" ) [ "..." ] Type [ string_lit ] .
+// parseParameter parses a Parameter:
//
+// Parameter = ( identifier | "?" ) [ "..." ] Type [ string_lit ] .
func (p *parser) parseParameter() (par *types.Var, isVariadic bool) {
_, name := p.parseName(nil, false)
// remove gc-specific parameter numbering
@@ -635,9 +642,10 @@
return
}
-// Parameters = "(" [ ParameterList ] ")" .
-// ParameterList = { Parameter "," } Parameter .
+// parseParameters parses a Parameters:
//
+// Parameters = "(" [ ParameterList ] ")" .
+// ParameterList = { Parameter "," } Parameter .
func (p *parser) parseParameters() (list []*types.Var, isVariadic bool) {
p.expect('(')
for p.tok != ')' && p.tok != scanner.EOF {
@@ -658,9 +666,10 @@
return
}
-// Signature = Parameters [ Result ] .
-// Result = Type | Parameters .
+// parseSignature parses a Signature:
//
+// Signature = Parameters [ Result ] .
+// Result = Type | Parameters .
func (p *parser) parseSignature(recv *types.Var) *types.Signature {
params, isVariadic := p.parseParameters()
@@ -677,14 +686,15 @@
return types.NewSignature(recv, types.NewTuple(params...), types.NewTuple(results...), isVariadic)
}
-// InterfaceType = "interface" "{" [ MethodList ] "}" .
-// MethodList = Method { ";" Method } .
-// Method = Name Signature .
+// parseInterfaceType parses an InterfaceType:
+//
+// InterfaceType = "interface" "{" [ MethodList ] "}" .
+// MethodList = Method { ";" Method } .
+// Method = Name Signature .
//
// The methods of embedded interfaces are always "inlined"
// by the compiler and thus embedded interfaces are never
// visible in the export data.
-//
func (p *parser) parseInterfaceType(parent *types.Package) types.Type {
var methods []*types.Func
@@ -705,8 +715,9 @@
return newInterface(methods, nil).Complete()
}
-// ChanType = ( "chan" [ "<-" ] | "<-" "chan" ) Type .
+// parseChanType parses a ChanType:
//
+// ChanType = ( "chan" [ "<-" ] | "<-" "chan" ) Type .
func (p *parser) parseChanType(parent *types.Package) types.Type {
dir := types.SendRecv
if p.tok == scanner.Ident {
@@ -724,17 +735,18 @@
return types.NewChan(dir, elem)
}
-// Type =
-// BasicType | TypeName | ArrayType | SliceType | StructType |
-// PointerType | FuncType | InterfaceType | MapType | ChanType |
-// "(" Type ")" .
+// parseType parses a Type:
//
-// BasicType = ident .
-// TypeName = ExportedName .
-// SliceType = "[" "]" Type .
-// PointerType = "*" Type .
-// FuncType = "func" Signature .
+// Type =
+// BasicType | TypeName | ArrayType | SliceType | StructType |
+// PointerType | FuncType | InterfaceType | MapType | ChanType |
+// "(" Type ")" .
//
+// BasicType = ident .
+// TypeName = ExportedName .
+// SliceType = "[" "]" Type .
+// PointerType = "*" Type .
+// FuncType = "func" Signature .
func (p *parser) parseType(parent *types.Package) types.Type {
switch p.tok {
case scanner.Ident:
@@ -786,16 +798,18 @@
// ----------------------------------------------------------------------------
// Declarations
-// ImportDecl = "import" PackageName PackageId .
+// parseImportDecl parses an ImportDecl:
//
+// ImportDecl = "import" PackageName PackageId .
func (p *parser) parseImportDecl() {
p.expectKeyword("import")
name := p.parsePackageName()
p.getPkg(p.parsePackageID(), name)
}
-// int_lit = [ "+" | "-" ] { "0" ... "9" } .
+// parseInt parses an int_lit:
//
+// int_lit = [ "+" | "-" ] { "0" ... "9" } .
func (p *parser) parseInt() string {
s := ""
switch p.tok {
@@ -808,8 +822,9 @@
return s + p.expect(scanner.Int)
}
-// number = int_lit [ "p" int_lit ] .
+// parseNumber parses a number:
//
+// number = int_lit [ "p" int_lit ] .
func (p *parser) parseNumber() (typ *types.Basic, val constant.Value) {
// mantissa
mant := constant.MakeFromLiteral(p.parseInt(), token.INT, 0)
@@ -844,13 +859,14 @@
return
}
-// ConstDecl = "const" ExportedName [ Type ] "=" Literal .
-// Literal = bool_lit | int_lit | float_lit | complex_lit | rune_lit | string_lit .
-// bool_lit = "true" | "false" .
-// complex_lit = "(" float_lit "+" float_lit "i" ")" .
-// rune_lit = "(" int_lit "+" int_lit ")" .
-// string_lit = `"` { unicode_char } `"` .
+// parseConstDecl parses a ConstDecl:
//
+// ConstDecl = "const" ExportedName [ Type ] "=" Literal .
+// Literal = bool_lit | int_lit | float_lit | complex_lit | rune_lit | string_lit .
+// bool_lit = "true" | "false" .
+// complex_lit = "(" float_lit "+" float_lit "i" ")" .
+// rune_lit = "(" int_lit "+" int_lit ")" .
+// string_lit = `"` { unicode_char } `"` .
func (p *parser) parseConstDecl() {
p.expectKeyword("const")
pkg, name := p.parseExportedName()
@@ -920,8 +936,9 @@
pkg.Scope().Insert(types.NewConst(token.NoPos, pkg, name, typ0, val))
}
-// TypeDecl = "type" ExportedName Type .
+// parseTypeDecl parses a TypeDecl:
//
+// TypeDecl = "type" ExportedName Type .
func (p *parser) parseTypeDecl() {
p.expectKeyword("type")
pkg, name := p.parseExportedName()
@@ -939,8 +956,9 @@
}
}
-// VarDecl = "var" ExportedName Type .
+// parseVarDecl parses a VarDecl:
//
+// VarDecl = "var" ExportedName Type .
func (p *parser) parseVarDecl() {
p.expectKeyword("var")
pkg, name := p.parseExportedName()
@@ -948,9 +966,10 @@
pkg.Scope().Insert(types.NewVar(token.NoPos, pkg, name, typ))
}
-// Func = Signature [ Body ] .
-// Body = "{" ... "}" .
+// parseFunc parses a Func:
//
+// Func = Signature [ Body ] .
+// Body = "{" ... "}" .
func (p *parser) parseFunc(recv *types.Var) *types.Signature {
sig := p.parseSignature(recv)
if p.tok == '{' {
@@ -967,9 +986,10 @@
return sig
}
-// MethodDecl = "func" Receiver Name Func .
-// Receiver = "(" ( identifier | "?" ) [ "*" ] ExportedName ")" .
+// parseMethodDecl parses a MethodDecl:
//
+// MethodDecl = "func" Receiver Name Func .
+// Receiver = "(" ( identifier | "?" ) [ "*" ] ExportedName ")" .
func (p *parser) parseMethodDecl() {
// "func" already consumed
p.expect('(')
@@ -992,8 +1012,9 @@
base.AddMethod(types.NewFunc(token.NoPos, pkg, name, sig))
}
-// FuncDecl = "func" ExportedName Func .
+// parseFuncDecl parses a FuncDecl:
//
+// FuncDecl = "func" ExportedName Func .
func (p *parser) parseFuncDecl() {
// "func" already consumed
pkg, name := p.parseExportedName()
@@ -1001,8 +1022,9 @@
pkg.Scope().Insert(types.NewFunc(token.NoPos, pkg, name, typ))
}
-// Decl = [ ImportDecl | ConstDecl | TypeDecl | VarDecl | FuncDecl | MethodDecl ] "\n" .
+// parseDecl parses a Decl:
//
+// Decl = [ ImportDecl | ConstDecl | TypeDecl | VarDecl | FuncDecl | MethodDecl ] "\n" .
func (p *parser) parseDecl() {
if p.tok == scanner.Ident {
switch p.lit {
@@ -1029,9 +1051,10 @@
// ----------------------------------------------------------------------------
// Export
-// Export = "PackageClause { Decl } "$$" .
-// PackageClause = "package" PackageName [ "safe" ] "\n" .
+// parseExport parses an Export:
//
+// Export = "PackageClause { Decl } "$$" .
+// PackageClause = "package" PackageName [ "safe" ] "\n" .
func (p *parser) parseExport() *types.Package {
p.expectKeyword("package")
name := p.parsePackageName()