break
}
}
+ p.prepareNames(f)
if p.rewriteCalls(f) {
// Add `import _cgo_unsafe "unsafe"` after the package statement.
f.Edit.Insert(f.offset(f.AST.Name.End()), "; import _cgo_unsafe \"unsafe\"")
}
}
+// 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
// from the original Go source files to the names
// used in the final Go files generated by cgo.
// code for them.
functions := make(map[string]bool)
- // Assign mangled names.
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" {
functions[n.Go] = false
}