mirror of
https://github.com/golang/go
synced 2024-11-18 16:04:44 -07:00
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 .
|
||||
func (p *parser) parseParam(pkg *types.Package) (param *types.Var, isVariadic bool) {
|
||||
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' {
|
||||
// EscInfo = "<esc:" int ">" . (optional and ignored)
|
||||
p.next()
|
||||
@ -297,7 +301,14 @@ func (p *parser) parseParam(pkg *types.Package) (param *types.Var, isVariadic bo
|
||||
// Var = Name Type .
|
||||
func (p *parser) parseVar(pkg *types.Package) *types.Var {
|
||||
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 ")" .
|
||||
@ -551,10 +562,12 @@ func (p *parser) parseNamedType(nlist []int) types.Type {
|
||||
for p.tok == scanner.Ident {
|
||||
p.expectKeyword("func")
|
||||
if p.tok == '/' {
|
||||
// Skip a /*nointerface*/ comment.
|
||||
// Skip a /*nointerface*/ or /*asm ID */ comment.
|
||||
p.expect('/')
|
||||
p.expect('*')
|
||||
p.expect(scanner.Ident)
|
||||
if p.expect(scanner.Ident) == "asm" {
|
||||
p.parseUnquotedString()
|
||||
}
|
||||
p.expect('*')
|
||||
p.expect('/')
|
||||
}
|
||||
@ -740,15 +753,29 @@ func (p *parser) parseFunctionType(pkg *types.Package, nlist []int) *types.Signa
|
||||
|
||||
// Func = Name FunctionType [InlineBody] .
|
||||
func (p *parser) parseFunc(pkg *types.Package) *types.Func {
|
||||
name := p.parseName()
|
||||
if strings.ContainsRune(name, '$') {
|
||||
// This is a Type$equal or Type$hash function, which we don't want to parse,
|
||||
// except for the types.
|
||||
p.discardDirectiveWhileParsingTypes(pkg)
|
||||
return nil
|
||||
if p.tok == '/' {
|
||||
// Skip an /*asm ID */ comment.
|
||||
p.expect('/')
|
||||
p.expect('*')
|
||||
if p.expect(scanner.Ident) == "asm" {
|
||||
p.parseUnquotedString()
|
||||
}
|
||||
p.expect('*')
|
||||
p.expect('/')
|
||||
}
|
||||
|
||||
name := p.parseName()
|
||||
f := types.NewFunc(token.NoPos, pkg, name, p.parseFunctionType(pkg, nil))
|
||||
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
|
||||
}
|
||||
|
||||
@ -769,7 +796,9 @@ func (p *parser) parseInterfaceType(pkg *types.Package, nlist []int) types.Type
|
||||
embeddeds = append(embeddeds, p.parseType(pkg))
|
||||
} else {
|
||||
method := p.parseFunc(pkg)
|
||||
methods = append(methods, method)
|
||||
if method != nil {
|
||||
methods = append(methods, method)
|
||||
}
|
||||
}
|
||||
p.expect(';')
|
||||
}
|
||||
@ -1061,22 +1090,6 @@ func (p *parser) parsePackageInit() PackageInit {
|
||||
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.
|
||||
func (p *parser) maybeCreatePackage() {
|
||||
if p.pkgname != "" && p.pkgpath != "" {
|
||||
@ -1214,7 +1227,9 @@ func (p *parser) parseDirective() {
|
||||
case "var":
|
||||
p.next()
|
||||
v := p.parseVar(p.pkg)
|
||||
p.pkg.Scope().Insert(v)
|
||||
if v != nil {
|
||||
p.pkg.Scope().Insert(v)
|
||||
}
|
||||
p.expectEOL()
|
||||
|
||||
case "const":
|
||||
|
Loading…
Reference in New Issue
Block a user