mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/cgo: mangle names before rewriting calls
Move name mangling before rewriting calls rather than after. This is in preparation for later changes. Change-Id: I74bc351f4290dad7ebf6d0d361bb684087786053 Reviewed-on: https://go-review.googlesource.com/c/142881 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
5ddec24888
commit
19b264e7bf
1 changed files with 22 additions and 17 deletions
|
|
@ -188,6 +188,7 @@ func (p *Package) Translate(f *File) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
p.prepareNames(f)
|
||||||
if p.rewriteCalls(f) {
|
if p.rewriteCalls(f) {
|
||||||
// Add `import _cgo_unsafe "unsafe"` after the package statement.
|
// Add `import _cgo_unsafe "unsafe"` after the package statement.
|
||||||
f.Edit.Insert(f.offset(f.AST.Name.End()), "; import _cgo_unsafe \"unsafe\"")
|
f.Edit.Insert(f.offset(f.AST.Name.End()), "; import _cgo_unsafe \"unsafe\"")
|
||||||
|
|
@ -679,6 +680,27 @@ func (p *Package) recordTypedefs1(dtype dwarf.Type, visited map[dwarf.Type]bool)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prepareNames finalizes the Kind field of not-type names and sets
|
||||||
|
// the mangled name of all names.
|
||||||
|
func (p *Package) prepareNames(f *File) {
|
||||||
|
for _, n := range f.Name {
|
||||||
|
if n.Kind == "not-type" {
|
||||||
|
if n.Define == "" {
|
||||||
|
n.Kind = "var"
|
||||||
|
} else {
|
||||||
|
n.Kind = "macro"
|
||||||
|
n.FuncType = &FuncType{
|
||||||
|
Result: n.Type,
|
||||||
|
Go: &ast.FuncType{
|
||||||
|
Results: &ast.FieldList{List: []*ast.Field{{Type: n.Type.Go}}},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.mangleName(n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// mangleName does name mangling to translate names
|
// mangleName does name mangling to translate names
|
||||||
// from the original Go source files to the names
|
// from the original Go source files to the names
|
||||||
// used in the final Go files generated by cgo.
|
// used in the final Go files generated by cgo.
|
||||||
|
|
@ -1130,24 +1152,7 @@ func (p *Package) rewriteRef(f *File) {
|
||||||
// code for them.
|
// code for them.
|
||||||
functions := make(map[string]bool)
|
functions := make(map[string]bool)
|
||||||
|
|
||||||
// Assign mangled names.
|
|
||||||
for _, n := range f.Name {
|
for _, n := range f.Name {
|
||||||
if n.Kind == "not-type" {
|
|
||||||
if n.Define == "" {
|
|
||||||
n.Kind = "var"
|
|
||||||
} else {
|
|
||||||
n.Kind = "macro"
|
|
||||||
n.FuncType = &FuncType{
|
|
||||||
Result: n.Type,
|
|
||||||
Go: &ast.FuncType{
|
|
||||||
Results: &ast.FieldList{List: []*ast.Field{{Type: n.Type.Go}}},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if n.Mangle == "" {
|
|
||||||
p.mangleName(n)
|
|
||||||
}
|
|
||||||
if n.Kind == "func" {
|
if n.Kind == "func" {
|
||||||
functions[n.Go] = false
|
functions[n.Go] = false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue