Skip to content

Commit

Permalink
go/internal: gofmt
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
rsc authored and gopherbot committed Apr 12, 2022
1 parent b900e88 commit fbebf43
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 113 deletions.
1 change: 0 additions & 1 deletion go/internal/cgo/cgo.go
Expand Up @@ -69,7 +69,6 @@ import (

// 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 {
Expand Down
145 changes: 99 additions & 46 deletions go/internal/gccgoimporter/parser.go
Expand Up @@ -127,8 +127,10 @@ func (p *parser) parseString() string {
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")
Expand Down Expand Up @@ -163,7 +165,10 @@ func (p *parser) parseUnquotedQualifiedName() (path, name string) {
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) {
Expand Down Expand Up @@ -191,7 +196,6 @@ func (p *parser) parseQualifiedNameStr(unquotedName string) (pkgpath, name strin
// 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" {
Expand All @@ -208,7 +212,7 @@ func (p *parser) getPkg(pkgpath, name string) *types.Package {
// 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
Expand All @@ -222,7 +226,9 @@ func (p *parser) parseExportedName() (pkg *types.Package, name string) {
return
}

// Name = QualifiedName | "?" .
// parseName parses a Name:
//
// Name = QualifiedName | "?" .
func (p *parser) parseName() string {
if p.tok == '?' {
// Anonymous.
Expand All @@ -241,7 +247,9 @@ func deref(typ types.Type) types.Type {
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)
Expand Down Expand Up @@ -269,7 +277,9 @@ func (p *parser) parseField(pkg *types.Package) (field *types.Var, tag string) {
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.
Expand Down Expand Up @@ -298,7 +308,9 @@ func (p *parser) parseParam(pkg *types.Package) (param *types.Var, isVariadic bo
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))
Expand All @@ -311,7 +323,9 @@ func (p *parser) parseVar(pkg *types.Package) *types.Var {
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('(')
Expand All @@ -322,8 +336,10 @@ func (p *parser) parseConversion(pkg *types.Package) (val constant.Value, typ ty
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.
Expand Down Expand Up @@ -429,7 +445,9 @@ func (p *parser) parseConstValue(pkg *types.Package) (val constant.Value, typ ty
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
Expand Down Expand Up @@ -510,9 +528,11 @@ func (p *parser) update(t types.Type, nlist []interface{}) {
}
}

// 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()
Expand Down Expand Up @@ -629,7 +649,9 @@ func (p *parser) parseInt() int {
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 == ']' {
Expand All @@ -652,7 +674,9 @@ func (p *parser) parseArrayOrSliceType(pkg *types.Package, nlist []interface{})
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")

Expand All @@ -668,7 +692,9 @@ func (p *parser) parseMapType(pkg *types.Package, nlist []interface{}) types.Typ
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")

Expand All @@ -695,7 +721,9 @@ func (p *parser) parseChanType(pkg *types.Package, nlist []interface{}) types.Ty
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")

Expand All @@ -718,7 +746,9 @@ func (p *parser) parseStructType(pkg *types.Package, nlist []interface{}) types.
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
Expand All @@ -742,7 +772,9 @@ func (p *parser) parseParamList(pkg *types.Package) (*types.Tuple, bool) {
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 '<':
Expand All @@ -762,7 +794,9 @@ func (p *parser) parseResultList(pkg *types.Package) *types.Tuple {
}
}

// 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)
Expand All @@ -774,7 +808,9 @@ func (p *parser) parseFunctionType(pkg *types.Package, nlist []interface{}) *typ
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.
Expand Down Expand Up @@ -802,7 +838,9 @@ func (p *parser) parseFunc(pkg *types.Package) *types.Func {
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")

Expand Down Expand Up @@ -831,7 +869,9 @@ func (p *parser) parseInterfaceType(pkg *types.Package, nlist []interface{}) typ
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 {
Expand All @@ -849,7 +889,9 @@ func (p *parser) parsePointerType(pkg *types.Package, nlist []interface{}) types
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:
Expand Down Expand Up @@ -935,10 +977,11 @@ func lookupBuiltinType(typ int) types.Type {
}[typ]
}

// Type = "<" "type" ( "-" int | int [ TypeSpec ] ) ">" .
// parseType parses a Type:
//
// parseType updates the type map to t for all type numbers n.
// 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...)
Expand Down Expand Up @@ -1028,7 +1071,9 @@ func (p *parser) skipInlineBody() {
}
}

// 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()
Expand Down Expand Up @@ -1102,7 +1147,9 @@ func (p *parser) parseSavedType(pkg *types.Package, i int, nlist []interface{})
}
}

// PackageInit = unquotedString unquotedString int .
// parsePackageInit parses a PackageInit:
//
// PackageInit = unquotedString unquotedString int .
func (p *parser) parsePackageInit() PackageInit {
name := p.parseUnquotedString()
initfunc := p.parseUnquotedString()
Expand All @@ -1120,10 +1167,12 @@ func (p *parser) maybeCreatePackage() {
}
}

// 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
Expand Down Expand Up @@ -1173,16 +1222,18 @@ func (p *parser) parseInitDataDirective() {
}
}

// 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
Expand Down Expand Up @@ -1266,7 +1317,9 @@ func (p *parser) parseDirective() {
}
}

// Package = { Directive } .
// parsePackage parses a Package:
//
// Package = { Directive } .
func (p *parser) parsePackage() *types.Package {
for p.tok != scanner.EOF {
p.parseDirective()
Expand Down
4 changes: 2 additions & 2 deletions go/internal/gccgoimporter/testenv_test.go
Expand Up @@ -12,7 +12,7 @@ import (
"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 {
Expand Down Expand Up @@ -40,7 +40,7 @@ func HasExec() bool {
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) {
Expand Down

0 comments on commit fbebf43

Please sign in to comment.