go/internal/gcimporter: support reading column details from export data

Mirrors the changes in the main repo.

Updates golang/go#28259.

Change-Id: I0cc9bc2f120d513f2f3d4ab503981c653e4ee7c2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/197678
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Matthew Dempsky 2019-09-26 17:38:16 -07:00
parent c7cf430b80
commit db0687cefd
2 changed files with 36 additions and 12 deletions

View File

@ -332,7 +332,7 @@ func (p *importer) pos() token.Pos {
p.prevFile = file p.prevFile = file
p.prevLine = line p.prevLine = line
return p.fake.pos(file, line) return p.fake.pos(file, line, 0)
} }
// Synthesize a token.Pos // Synthesize a token.Pos
@ -341,7 +341,9 @@ type fakeFileSet struct {
files map[string]*token.File files map[string]*token.File
} }
func (s *fakeFileSet) pos(file string, line int) token.Pos { func (s *fakeFileSet) pos(file string, line, column int) token.Pos {
// TODO(mdempsky): Make use of column.
// Since we don't know the set of needed file positions, we // Since we don't know the set of needed file positions, we
// reserve maxlines positions per file. // reserve maxlines positions per file.
const maxlines = 64 * 1024 const maxlines = 64 * 1024

View File

@ -63,8 +63,8 @@ const (
// If the export data version is not recognized or the format is otherwise // If the export data version is not recognized or the format is otherwise
// compromised, an error is returned. // compromised, an error is returned.
func IImportData(fset *token.FileSet, imports map[string]*types.Package, data []byte, path string) (_ int, pkg *types.Package, err error) { func IImportData(fset *token.FileSet, imports map[string]*types.Package, data []byte, path string) (_ int, pkg *types.Package, err error) {
const currentVersion = 0 const currentVersion = 1
version := -1 version := int64(-1)
defer func() { defer func() {
if e := recover(); e != nil { if e := recover(); e != nil {
if version > currentVersion { if version > currentVersion {
@ -77,9 +77,9 @@ func IImportData(fset *token.FileSet, imports map[string]*types.Package, data []
r := &intReader{bytes.NewReader(data), path} r := &intReader{bytes.NewReader(data), path}
version = int(r.uint64()) version = int64(r.uint64())
switch version { switch version {
case currentVersion: case currentVersion, 0:
default: default:
errorf("unknown iexport format version %d", version) errorf("unknown iexport format version %d", version)
} }
@ -93,7 +93,8 @@ func IImportData(fset *token.FileSet, imports map[string]*types.Package, data []
r.Seek(sLen+dLen, io.SeekCurrent) r.Seek(sLen+dLen, io.SeekCurrent)
p := iimporter{ p := iimporter{
ipath: path, ipath: path,
version: int(version),
stringData: stringData, stringData: stringData,
stringCache: make(map[uint64]string), stringCache: make(map[uint64]string),
@ -175,7 +176,8 @@ func IImportData(fset *token.FileSet, imports map[string]*types.Package, data []
} }
type iimporter struct { type iimporter struct {
ipath string ipath string
version int
stringData []byte stringData []byte
stringCache map[uint64]string stringCache map[uint64]string
@ -255,6 +257,7 @@ type importReader struct {
currPkg *types.Package currPkg *types.Package
prevFile string prevFile string
prevLine int64 prevLine int64
prevColumn int64
} }
func (r *importReader) obj(name string) { func (r *importReader) obj(name string) {
@ -448,6 +451,19 @@ func (r *importReader) qualifiedIdent() (*types.Package, string) {
} }
func (r *importReader) pos() token.Pos { func (r *importReader) pos() token.Pos {
if r.p.version >= 1 {
r.posv1()
} else {
r.posv0()
}
if r.prevFile == "" && r.prevLine == 0 && r.prevColumn == 0 {
return token.NoPos
}
return r.p.fake.pos(r.prevFile, int(r.prevLine), int(r.prevColumn))
}
func (r *importReader) posv0() {
delta := r.int64() delta := r.int64()
if delta != deltaNewFile { if delta != deltaNewFile {
r.prevLine += delta r.prevLine += delta
@ -457,12 +473,18 @@ func (r *importReader) pos() token.Pos {
r.prevFile = r.string() r.prevFile = r.string()
r.prevLine = l r.prevLine = l
} }
}
if r.prevFile == "" && r.prevLine == 0 { func (r *importReader) posv1() {
return token.NoPos delta := r.int64()
r.prevColumn += delta >> 1
if delta&1 != 0 {
delta = r.int64()
r.prevLine += delta >> 1
if delta&1 != 0 {
r.prevFile = r.string()
}
} }
return r.p.fake.pos(r.prevFile, int(r.prevLine))
} }
func (r *importReader) typ() types.Type { func (r *importReader) typ() types.Type {