go/internal/gccgoimporter: update package to match std lib version
Import changes from std lib version, specifically https://golang.org/cl/181118 related to importing inlinable function bodies. Change-Id: Ie5fe1db508f7ec2cbef2dcdc96e2136c8e4f23ad Reviewed-on: https://go-review.googlesource.com/c/tools/+/181120 Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
0139d5756a
commit
5aed7825b1
|
@ -272,6 +272,10 @@ func (p *parser) parseField(pkg *types.Package) (field *types.Var, tag string) {
|
||||||
// Param = Name ["..."] Type .
|
// Param = Name ["..."] Type .
|
||||||
func (p *parser) parseParam(pkg *types.Package) (param *types.Var, isVariadic bool) {
|
func (p *parser) parseParam(pkg *types.Package) (param *types.Var, isVariadic bool) {
|
||||||
name := p.parseName()
|
name := p.parseName()
|
||||||
|
// Ignore names invented for inlinable functions.
|
||||||
|
if strings.HasPrefix(name, "p.") || strings.HasPrefix(name, "r.") || strings.HasPrefix(name, "$ret") {
|
||||||
|
name = ""
|
||||||
|
}
|
||||||
if p.tok == '<' && p.scanner.Peek() == 'e' {
|
if p.tok == '<' && p.scanner.Peek() == 'e' {
|
||||||
// EscInfo = "<esc:" int ">" . (optional and ignored)
|
// EscInfo = "<esc:" int ">" . (optional and ignored)
|
||||||
p.next()
|
p.next()
|
||||||
|
@ -297,7 +301,14 @@ func (p *parser) parseParam(pkg *types.Package) (param *types.Var, isVariadic bo
|
||||||
// Var = Name Type .
|
// Var = Name Type .
|
||||||
func (p *parser) parseVar(pkg *types.Package) *types.Var {
|
func (p *parser) parseVar(pkg *types.Package) *types.Var {
|
||||||
name := p.parseName()
|
name := p.parseName()
|
||||||
return types.NewVar(token.NoPos, pkg, name, p.parseType(pkg))
|
v := types.NewVar(token.NoPos, pkg, name, p.parseType(pkg))
|
||||||
|
if name[0] == '.' || name[0] == '<' {
|
||||||
|
// This is an unexported variable,
|
||||||
|
// or a variable defined in a different package.
|
||||||
|
// We only want to record exported variables.
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
// Conversion = "convert" "(" Type "," ConstValue ")" .
|
// Conversion = "convert" "(" Type "," ConstValue ")" .
|
||||||
|
@ -551,10 +562,12 @@ func (p *parser) parseNamedType(nlist []int) types.Type {
|
||||||
for p.tok == scanner.Ident {
|
for p.tok == scanner.Ident {
|
||||||
p.expectKeyword("func")
|
p.expectKeyword("func")
|
||||||
if p.tok == '/' {
|
if p.tok == '/' {
|
||||||
// Skip a /*nointerface*/ comment.
|
// Skip a /*nointerface*/ or /*asm ID */ comment.
|
||||||
p.expect('/')
|
p.expect('/')
|
||||||
p.expect('*')
|
p.expect('*')
|
||||||
p.expect(scanner.Ident)
|
if p.expect(scanner.Ident) == "asm" {
|
||||||
|
p.parseUnquotedString()
|
||||||
|
}
|
||||||
p.expect('*')
|
p.expect('*')
|
||||||
p.expect('/')
|
p.expect('/')
|
||||||
}
|
}
|
||||||
|
@ -740,15 +753,29 @@ func (p *parser) parseFunctionType(pkg *types.Package, nlist []int) *types.Signa
|
||||||
|
|
||||||
// Func = Name FunctionType [InlineBody] .
|
// Func = Name FunctionType [InlineBody] .
|
||||||
func (p *parser) parseFunc(pkg *types.Package) *types.Func {
|
func (p *parser) parseFunc(pkg *types.Package) *types.Func {
|
||||||
name := p.parseName()
|
if p.tok == '/' {
|
||||||
if strings.ContainsRune(name, '$') {
|
// Skip an /*asm ID */ comment.
|
||||||
// This is a Type$equal or Type$hash function, which we don't want to parse,
|
p.expect('/')
|
||||||
// except for the types.
|
p.expect('*')
|
||||||
p.discardDirectiveWhileParsingTypes(pkg)
|
if p.expect(scanner.Ident) == "asm" {
|
||||||
return nil
|
p.parseUnquotedString()
|
||||||
}
|
}
|
||||||
|
p.expect('*')
|
||||||
|
p.expect('/')
|
||||||
|
}
|
||||||
|
|
||||||
|
name := p.parseName()
|
||||||
f := types.NewFunc(token.NoPos, pkg, name, p.parseFunctionType(pkg, nil))
|
f := types.NewFunc(token.NoPos, pkg, name, p.parseFunctionType(pkg, nil))
|
||||||
p.skipInlineBody()
|
p.skipInlineBody()
|
||||||
|
|
||||||
|
if name[0] == '.' || name[0] == '<' || strings.ContainsRune(name, '$') {
|
||||||
|
// This is an unexported function,
|
||||||
|
// or a function defined in a different package,
|
||||||
|
// or a type$equal or type$hash function.
|
||||||
|
// We only want to record exported functions.
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -769,8 +796,10 @@ func (p *parser) parseInterfaceType(pkg *types.Package, nlist []int) types.Type
|
||||||
embeddeds = append(embeddeds, p.parseType(pkg))
|
embeddeds = append(embeddeds, p.parseType(pkg))
|
||||||
} else {
|
} else {
|
||||||
method := p.parseFunc(pkg)
|
method := p.parseFunc(pkg)
|
||||||
|
if method != nil {
|
||||||
methods = append(methods, method)
|
methods = append(methods, method)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
p.expect(';')
|
p.expect(';')
|
||||||
}
|
}
|
||||||
p.expect('}')
|
p.expect('}')
|
||||||
|
@ -1061,22 +1090,6 @@ func (p *parser) parsePackageInit() PackageInit {
|
||||||
return PackageInit{Name: name, InitFunc: initfunc, Priority: priority}
|
return PackageInit{Name: name, InitFunc: initfunc, Priority: priority}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Throw away tokens until we see a ';'. If we see a '<', attempt to parse as a type.
|
|
||||||
func (p *parser) discardDirectiveWhileParsingTypes(pkg *types.Package) {
|
|
||||||
for {
|
|
||||||
switch p.tok {
|
|
||||||
case '\n', ';':
|
|
||||||
return
|
|
||||||
case '<':
|
|
||||||
p.parseType(pkg)
|
|
||||||
case scanner.EOF:
|
|
||||||
p.error("unexpected EOF")
|
|
||||||
default:
|
|
||||||
p.next()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the package if we have parsed both the package path and package name.
|
// Create the package if we have parsed both the package path and package name.
|
||||||
func (p *parser) maybeCreatePackage() {
|
func (p *parser) maybeCreatePackage() {
|
||||||
if p.pkgname != "" && p.pkgpath != "" {
|
if p.pkgname != "" && p.pkgpath != "" {
|
||||||
|
@ -1214,7 +1227,9 @@ func (p *parser) parseDirective() {
|
||||||
case "var":
|
case "var":
|
||||||
p.next()
|
p.next()
|
||||||
v := p.parseVar(p.pkg)
|
v := p.parseVar(p.pkg)
|
||||||
|
if v != nil {
|
||||||
p.pkg.Scope().Insert(v)
|
p.pkg.Scope().Insert(v)
|
||||||
|
}
|
||||||
p.expectEOL()
|
p.expectEOL()
|
||||||
|
|
||||||
case "const":
|
case "const":
|
||||||
|
|
Loading…
Reference in New Issue