mirror of
https://github.com/golang/go
synced 2024-09-15 14:10:17 +00:00
[dev.typeparams] cmd/compile/internal/importer: implement position reading
This CL finishes importReader.pos's stub implementation to actually return syntax.Pos. New PosBase handling is analogous to typecheck/iimport.go, except for using syntax.PosBase instead of src.PosBase. Change-Id: I7629f9f5e69a38ffc2eec772504d6fb2169e1f12 Reviewed-on: https://go-review.googlesource.com/c/go/+/320614 Trust: Matthew Dempsky <mdempsky@google.com> Trust: Dan Scales <danscales@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
c92ae885d9
commit
fb79f6955e
|
@ -102,6 +102,7 @@ func iImportData(imports map[string]*types2.Package, data []byte, path string) (
|
||||||
stringData: stringData,
|
stringData: stringData,
|
||||||
stringCache: make(map[uint64]string),
|
stringCache: make(map[uint64]string),
|
||||||
pkgCache: make(map[uint64]*types2.Package),
|
pkgCache: make(map[uint64]*types2.Package),
|
||||||
|
posBaseCache: make(map[uint64]*syntax.PosBase),
|
||||||
|
|
||||||
declData: declData,
|
declData: declData,
|
||||||
pkgIndex: make(map[*types2.Package]map[string]uint64),
|
pkgIndex: make(map[*types2.Package]map[string]uint64),
|
||||||
|
@ -176,6 +177,7 @@ type iimporter struct {
|
||||||
stringData []byte
|
stringData []byte
|
||||||
stringCache map[uint64]string
|
stringCache map[uint64]string
|
||||||
pkgCache map[uint64]*types2.Package
|
pkgCache map[uint64]*types2.Package
|
||||||
|
posBaseCache map[uint64]*syntax.PosBase
|
||||||
|
|
||||||
declData []byte
|
declData []byte
|
||||||
pkgIndex map[*types2.Package]map[string]uint64
|
pkgIndex map[*types2.Package]map[string]uint64
|
||||||
|
@ -228,6 +230,16 @@ func (p *iimporter) pkgAt(off uint64) *types2.Package {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *iimporter) posBaseAt(off uint64) *syntax.PosBase {
|
||||||
|
if posBase, ok := p.posBaseCache[off]; ok {
|
||||||
|
return posBase
|
||||||
|
}
|
||||||
|
filename := p.stringAt(off)
|
||||||
|
posBase := syntax.NewFileBase(filename)
|
||||||
|
p.posBaseCache[off] = posBase
|
||||||
|
return posBase
|
||||||
|
}
|
||||||
|
|
||||||
func (p *iimporter) typAt(off uint64, base *types2.Named) types2.Type {
|
func (p *iimporter) typAt(off uint64, base *types2.Named) types2.Type {
|
||||||
if t, ok := p.typCache[off]; ok && (base == nil || !isInterface(t)) {
|
if t, ok := p.typCache[off]; ok && (base == nil || !isInterface(t)) {
|
||||||
return t
|
return t
|
||||||
|
@ -254,7 +266,7 @@ type importReader struct {
|
||||||
p *iimporter
|
p *iimporter
|
||||||
declReader bytes.Reader
|
declReader bytes.Reader
|
||||||
currPkg *types2.Package
|
currPkg *types2.Package
|
||||||
prevFile string
|
prevPosBase *syntax.PosBase
|
||||||
prevLine int64
|
prevLine int64
|
||||||
prevColumn int64
|
prevColumn int64
|
||||||
}
|
}
|
||||||
|
@ -439,12 +451,11 @@ func (r *importReader) pos() syntax.Pos {
|
||||||
r.posv0()
|
r.posv0()
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.prevFile == "" && r.prevLine == 0 && r.prevColumn == 0 {
|
if (r.prevPosBase == nil || r.prevPosBase.Filename() == "") && r.prevLine == 0 && r.prevColumn == 0 {
|
||||||
return syntax.Pos{}
|
return syntax.Pos{}
|
||||||
}
|
}
|
||||||
// TODO(gri) fix this
|
|
||||||
// return r.p.fake.pos(r.prevFile, int(r.prevLine), int(r.prevColumn))
|
return syntax.MakePos(r.prevPosBase, uint(r.prevLine), uint(r.prevColumn))
|
||||||
return syntax.Pos{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *importReader) posv0() {
|
func (r *importReader) posv0() {
|
||||||
|
@ -454,7 +465,7 @@ func (r *importReader) posv0() {
|
||||||
} else if l := r.int64(); l == -1 {
|
} else if l := r.int64(); l == -1 {
|
||||||
r.prevLine += deltaNewFile
|
r.prevLine += deltaNewFile
|
||||||
} else {
|
} else {
|
||||||
r.prevFile = r.string()
|
r.prevPosBase = r.posBase()
|
||||||
r.prevLine = l
|
r.prevLine = l
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -466,7 +477,7 @@ func (r *importReader) posv1() {
|
||||||
delta = r.int64()
|
delta = r.int64()
|
||||||
r.prevLine += delta >> 1
|
r.prevLine += delta >> 1
|
||||||
if delta&1 != 0 {
|
if delta&1 != 0 {
|
||||||
r.prevFile = r.string()
|
r.prevPosBase = r.posBase()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -482,6 +493,7 @@ func isInterface(t types2.Type) bool {
|
||||||
|
|
||||||
func (r *importReader) pkg() *types2.Package { return r.p.pkgAt(r.uint64()) }
|
func (r *importReader) pkg() *types2.Package { return r.p.pkgAt(r.uint64()) }
|
||||||
func (r *importReader) string() string { return r.p.stringAt(r.uint64()) }
|
func (r *importReader) string() string { return r.p.stringAt(r.uint64()) }
|
||||||
|
func (r *importReader) posBase() *syntax.PosBase { return r.p.posBaseAt(r.uint64()) }
|
||||||
|
|
||||||
func (r *importReader) doType(base *types2.Named) types2.Type {
|
func (r *importReader) doType(base *types2.Named) types2.Type {
|
||||||
switch k := r.kind(); k {
|
switch k := r.kind(); k {
|
||||||
|
|
Loading…
Reference in a new issue