--- /dev/null
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+/*
+long double x = 0;
+*/
+import "C"
+
+func main() {
+ _ = C.x // ERROR HERE
+ _ = C.x
+}
f.Package = ast1.Name.Name
f.Name = make(map[string]*Name)
+ f.NamePos = make(map[*Name]token.Pos)
// In ast1, find the import "C" line and get any extra C preamble.
sawC := false
Go: goname,
}
f.Name[goname] = name
+ f.NamePos[name] = sel.Pos()
}
f.Ref = append(f.Ref, &Ref{
Name: name,
for i, n := range names {
switch sniff[i] &^ notSignedIntConst {
default:
- var tpos token.Pos
- for _, ref := range f.Ref {
- if ref.Name == n {
- tpos = ref.Pos()
- break
- }
- }
- error_(tpos, "could not determine kind of name for C.%s", fixGo(n.Go))
+ error_(f.NamePos[n], "could not determine kind of name for C.%s", fixGo(n.Go))
case notStrLiteral | notType:
if sniff[i]¬SignedIntConst != 0 {
n.Kind = "uconst"
// Scan DWARF info for top-level TagVariable entries with AttrName __cgo__i.
types := make([]dwarf.Type, len(names))
- nameToRef := make(map[*Name]*Ref)
- for _, ref := range f.Ref {
- nameToRef[ref.Name] = ref
- }
r := d.Reader()
for {
e, err := r.Next()
if types[i] == nil {
continue
}
- pos := token.NoPos
- if ref, ok := nameToRef[n]; ok {
- pos = ref.Pos()
- }
+ pos := f.NamePos[n]
f, fok := types[i].(*dwarf.FuncType)
if n.Kind != "type" && fok {
n.Kind = "func"
Calls []*Call // all calls to C.xxx in AST
ExpFunc []*ExpFunc // exported functions for this file
Name map[string]*Name // map from Go name to Name
+ NamePos map[*Name]token.Pos // map from Name to position of the first reference
}
func nameKeys(m map[string]*Name) []string {