Skip to content

Commit 4bb9a6d

Browse files
committed
go/gcimporter: update to latest copy from master
Backport of CL 41619. Generated by copying bimport.go and reverting the chunk containing the "This file is a copy" comment near the top. Fixes golang/go#20121 Change-Id: If24c97d01a550318ab919c37cd0c4a8f34d776c7 Reviewed-on: https://go-review.googlesource.com/41756 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 518248c commit 4bb9a6d

File tree

1 file changed

+65
-25
lines changed

1 file changed

+65
-25
lines changed

go/gcimporter15/bimport.go

Lines changed: 65 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ import (
2121
)
2222

2323
type importer struct {
24-
imports map[string]*types.Package
25-
data []byte
26-
path string
27-
buf []byte // for reading strings
28-
version int // export format version
24+
imports map[string]*types.Package
25+
data []byte
26+
importpath string
27+
buf []byte // for reading strings
28+
version int // export format version
2929

3030
// object lists
3131
strList []string // in order of appearance
32+
pathList []string // in order of appearance
3233
pkgList []*types.Package // in order of appearance
3334
typList []types.Type // in order of appearance
3435
interfaceList []*types.Interface // for delayed completion only
@@ -62,13 +63,14 @@ func BImportData(fset *token.FileSet, imports map[string]*types.Package, data []
6263
}()
6364

6465
p := importer{
65-
imports: imports,
66-
data: data,
67-
path: path,
68-
version: -1, // unknown version
69-
strList: []string{""}, // empty string is mapped to 0
70-
fset: fset,
71-
files: make(map[string]*token.File),
66+
imports: imports,
67+
data: data,
68+
importpath: path,
69+
version: -1, // unknown version
70+
strList: []string{""}, // empty string is mapped to 0
71+
pathList: []string{""}, // empty string is mapped to 0
72+
fset: fset,
73+
files: make(map[string]*token.File),
7274
}
7375

7476
// read version info
@@ -102,10 +104,10 @@ func BImportData(fset *token.FileSet, imports map[string]*types.Package, data []
102104

103105
// read version specific flags - extend as necessary
104106
switch p.version {
105-
// case 5:
107+
// case 6:
106108
// ...
107109
// fallthrough
108-
case 4, 3, 2, 1:
110+
case 5, 4, 3, 2, 1:
109111
p.debugFormat = p.rawStringln(p.rawByte()) == "debug"
110112
p.trackAllTypes = p.int() != 0
111113
p.posInfoFormat = p.int() != 0
@@ -171,12 +173,17 @@ func (p *importer) pkg() *types.Package {
171173

172174
// otherwise, i is the package tag (< 0)
173175
if i != packageTag {
174-
errorf("unexpected package tag %d", i)
176+
errorf("unexpected package tag %d version %d", i, p.version)
175177
}
176178

177179
// read package data
178180
name := p.string()
179-
path := p.string()
181+
var path string
182+
if p.version >= 5 {
183+
path = p.path()
184+
} else {
185+
path = p.string()
186+
}
180187

181188
// we should never see an empty package name
182189
if name == "" {
@@ -191,7 +198,7 @@ func (p *importer) pkg() *types.Package {
191198

192199
// if the package was imported before, use that one; otherwise create a new one
193200
if path == "" {
194-
path = p.path
201+
path = p.importpath
195202
}
196203
pkg := p.imports[path]
197204
if pkg == nil {
@@ -285,22 +292,35 @@ func (p *importer) obj(tag int) {
285292
}
286293
}
287294

295+
const deltaNewFile = -64 // see cmd/compile/internal/gc/bexport.go
296+
288297
func (p *importer) pos() token.Pos {
289298
if !p.posInfoFormat {
290299
return token.NoPos
291300
}
292301

293302
file := p.prevFile
294303
line := p.prevLine
295-
if delta := p.int(); delta != 0 {
296-
// line changed
297-
line += delta
298-
} else if n := p.int(); n >= 0 {
299-
// file changed
300-
file = p.prevFile[:n] + p.string()
301-
p.prevFile = file
302-
line = p.int()
304+
delta := p.int()
305+
line += delta
306+
if p.version >= 5 {
307+
if delta == deltaNewFile {
308+
if n := p.int(); n >= 0 {
309+
// file changed
310+
file = p.path()
311+
line = n
312+
}
313+
}
314+
} else {
315+
if delta == 0 {
316+
if n := p.int(); n >= 0 {
317+
// file changed
318+
file = p.prevFile[:n] + p.string()
319+
line = p.int()
320+
}
321+
}
303322
}
323+
p.prevFile = file
304324
p.prevLine = line
305325

306326
// Synthesize a token.Pos
@@ -778,6 +798,26 @@ func (p *importer) int64() int64 {
778798
return p.rawInt64()
779799
}
780800

801+
func (p *importer) path() string {
802+
if p.debugFormat {
803+
p.marker('p')
804+
}
805+
// if the path was seen before, i is its index (>= 0)
806+
// (the empty string is at index 0)
807+
i := p.rawInt64()
808+
if i >= 0 {
809+
return p.pathList[i]
810+
}
811+
// otherwise, i is the negative path length (< 0)
812+
a := make([]string, -i)
813+
for n := range a {
814+
a[n] = p.string()
815+
}
816+
s := strings.Join(a, "/")
817+
p.pathList = append(p.pathList, s)
818+
return s
819+
}
820+
781821
func (p *importer) string() string {
782822
if p.debugFormat {
783823
p.marker('s')

0 commit comments

Comments
 (0)