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 <bradfitz@golang.org>
diff --git a/go/gcimporter15/bimport.go b/go/gcimporter15/bimport.go
index 369dfb6..1936a7f 100644
--- a/go/gcimporter15/bimport.go
+++ b/go/gcimporter15/bimport.go
@@ -21,14 +21,15 @@
)
type importer struct {
- imports map[string]*types.Package
- data []byte
- path string
- buf []byte // for reading strings
- version int // export format version
+ imports map[string]*types.Package
+ data []byte
+ importpath string
+ buf []byte // for reading strings
+ version int // export format version
// object lists
strList []string // in order of appearance
+ pathList []string // in order of appearance
pkgList []*types.Package // in order of appearance
typList []types.Type // in order of appearance
interfaceList []*types.Interface // for delayed completion only
@@ -62,13 +63,14 @@
}()
p := importer{
- imports: imports,
- data: data,
- path: path,
- version: -1, // unknown version
- strList: []string{""}, // empty string is mapped to 0
- fset: fset,
- files: make(map[string]*token.File),
+ imports: imports,
+ data: data,
+ importpath: path,
+ version: -1, // unknown version
+ strList: []string{""}, // empty string is mapped to 0
+ pathList: []string{""}, // empty string is mapped to 0
+ fset: fset,
+ files: make(map[string]*token.File),
}
// read version info
@@ -102,10 +104,10 @@
// read version specific flags - extend as necessary
switch p.version {
- // case 5:
+ // case 6:
// ...
// fallthrough
- case 4, 3, 2, 1:
+ case 5, 4, 3, 2, 1:
p.debugFormat = p.rawStringln(p.rawByte()) == "debug"
p.trackAllTypes = p.int() != 0
p.posInfoFormat = p.int() != 0
@@ -171,12 +173,17 @@
// otherwise, i is the package tag (< 0)
if i != packageTag {
- errorf("unexpected package tag %d", i)
+ errorf("unexpected package tag %d version %d", i, p.version)
}
// read package data
name := p.string()
- path := p.string()
+ var path string
+ if p.version >= 5 {
+ path = p.path()
+ } else {
+ path = p.string()
+ }
// we should never see an empty package name
if name == "" {
@@ -191,7 +198,7 @@
// if the package was imported before, use that one; otherwise create a new one
if path == "" {
- path = p.path
+ path = p.importpath
}
pkg := p.imports[path]
if pkg == nil {
@@ -285,6 +292,8 @@
}
}
+const deltaNewFile = -64 // see cmd/compile/internal/gc/bexport.go
+
func (p *importer) pos() token.Pos {
if !p.posInfoFormat {
return token.NoPos
@@ -292,15 +301,26 @@
file := p.prevFile
line := p.prevLine
- if delta := p.int(); delta != 0 {
- // line changed
- line += delta
- } else if n := p.int(); n >= 0 {
- // file changed
- file = p.prevFile[:n] + p.string()
- p.prevFile = file
- line = p.int()
+ delta := p.int()
+ line += delta
+ if p.version >= 5 {
+ if delta == deltaNewFile {
+ if n := p.int(); n >= 0 {
+ // file changed
+ file = p.path()
+ line = n
+ }
+ }
+ } else {
+ if delta == 0 {
+ if n := p.int(); n >= 0 {
+ // file changed
+ file = p.prevFile[:n] + p.string()
+ line = p.int()
+ }
+ }
}
+ p.prevFile = file
p.prevLine = line
// Synthesize a token.Pos
@@ -778,6 +798,26 @@
return p.rawInt64()
}
+func (p *importer) path() string {
+ if p.debugFormat {
+ p.marker('p')
+ }
+ // if the path was seen before, i is its index (>= 0)
+ // (the empty string is at index 0)
+ i := p.rawInt64()
+ if i >= 0 {
+ return p.pathList[i]
+ }
+ // otherwise, i is the negative path length (< 0)
+ a := make([]string, -i)
+ for n := range a {
+ a[n] = p.string()
+ }
+ s := strings.Join(a, "/")
+ p.pathList = append(p.pathList, s)
+ return s
+}
+
func (p *importer) string() string {
if p.debugFormat {
p.marker('s')