Compiling the following file:
package p
//line c.go:10
const C = 0 // file line = 4
//line t.go:20
type T int // file line = 7
//line v.go:30
var V T // file line = 10
//line f.go:40
func F() {} // file line = 13
records the following positions in the export data:
C c.go 4
T /Users/gri/tmp/x.go 14
V v.go 10
F f.go 13
Except for V they are all surprising, one way or the other. The output from the syntax package is as follows in this case:
$ go test -v -run Dump -src=$HOME/tmp/x.go
=== RUN TestDump
1 *syntax.File {
2 . PkgName: p @ /Users/gri/tmp/x.go:1
3 . DeclList: []syntax.Decl (4 entries) {
4 . . 0: *syntax.ConstDecl {
5 . . . NameList: []*syntax.Name (1 entries) {
6 . . . . 0: C @ c.go:10[/Users/gri/tmp/x.go:3]
7 . . . }
8 . . . Type: nil
9 . . . Values: *syntax.BasicLit {
10 . . . . Value: "0"
11 . . . . Kind: 0
12 . . . }
13 . . . Group: nil
14 . . }
15 . . 1: *syntax.TypeDecl {
16 . . . Name: T @ t.go:20[/Users/gri/tmp/x.go:6]
17 . . . Alias: false
18 . . . Type: int @ t.go:20[/Users/gri/tmp/x.go:6]
19 . . . Group: nil
20 . . . Pragma: 0
21 . . }
22 . . 2: *syntax.VarDecl {
23 . . . NameList: []*syntax.Name (1 entries) {
24 . . . . 0: V @ v.go:30[/Users/gri/tmp/x.go:9]
25 . . . }
26 . . . Type: T @ v.go:30[/Users/gri/tmp/x.go:9]
27 . . . Values: nil
28 . . . Group: nil
29 . . }
30 . . 3: *syntax.FuncDecl {
31 . . . Attr: map[]
32 . . . Recv: nil
33 . . . Name: F @ f.go:40[/Users/gri/tmp/x.go:12]
34 . . . Type: *syntax.FuncType {
35 . . . . ParamList: nil
36 . . . . ResultList: nil
37 . . . }
38 . . . Body: []syntax.Stmt (1 entries) {
39 . . . . 0: *syntax.EmptyStmt {
40 . . . . }
41 . . . }
42 . . . Pragma: 0
43 . . . EndLine: 13
44 . . }
45 . }
46 . Lines: 14
47 }
--- PASS: TestDump (0.18s)
which shows consistent positions with the Name nodes (albeit they are off by 1).
Compiling the following file:
records the following positions in the export data:
Except for V they are all surprising, one way or the other. The output from the syntax package is as follows in this case:
which shows consistent positions with the Name nodes (albeit they are off by 1).