Commit 3124439b authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: make more use of exported position information

Updates #19683.

Change-Id: I64b3b93a3ab14518a5376e1270bdd2a94bdd67ef
Reviewed-on: https://go-review.googlesource.com/59611
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
parent d30f9964
...@@ -326,29 +326,29 @@ func idealType(typ *types.Type) *types.Type { ...@@ -326,29 +326,29 @@ func idealType(typ *types.Type) *types.Type {
func (p *importer) obj(tag int) { func (p *importer) obj(tag int) {
switch tag { switch tag {
case constTag: case constTag:
p.pos() pos := p.pos()
sym := p.qualifiedName() sym := p.qualifiedName()
typ := p.typ() typ := p.typ()
val := p.value(typ) val := p.value(typ)
importconst(p.imp, sym, idealType(typ), nodlit(val)) importconst(p.imp, sym, idealType(typ), npos(pos, nodlit(val)))
case aliasTag: case aliasTag:
p.pos() pos := p.pos()
sym := p.qualifiedName() sym := p.qualifiedName()
typ := p.typ() typ := p.typ()
importalias(p.imp, sym, typ) importalias(pos, p.imp, sym, typ)
case typeTag: case typeTag:
p.typ() p.typ()
case varTag: case varTag:
p.pos() pos := p.pos()
sym := p.qualifiedName() sym := p.qualifiedName()
typ := p.typ() typ := p.typ()
importvar(p.imp, sym, typ) importvar(pos, p.imp, sym, typ)
case funcTag: case funcTag:
p.pos() pos := p.pos()
sym := p.qualifiedName() sym := p.qualifiedName()
params := p.paramList() params := p.paramList()
result := p.paramList() result := p.paramList()
...@@ -364,7 +364,7 @@ func (p *importer) obj(tag int) { ...@@ -364,7 +364,7 @@ func (p *importer) obj(tag int) {
break break
} }
n := newfuncname(sym) n := newfuncnamel(pos, sym)
n.Type = sig n.Type = sig
declare(n, PFUNC) declare(n, PFUNC)
p.funcList = append(p.funcList, n) p.funcList = append(p.funcList, n)
...@@ -479,10 +479,10 @@ func (p *importer) typ() *types.Type { ...@@ -479,10 +479,10 @@ func (p *importer) typ() *types.Type {
var t *types.Type var t *types.Type
switch i { switch i {
case namedTag: case namedTag:
p.pos() pos := p.pos()
tsym := p.qualifiedName() tsym := p.qualifiedName()
t = pkgtype(p.imp, tsym) t = pkgtype(pos, p.imp, tsym)
p.typList = append(p.typList, t) p.typList = append(p.typList, t)
dup := !t.IsKind(types.TFORW) // type already imported dup := !t.IsKind(types.TFORW) // type already imported
...@@ -502,7 +502,7 @@ func (p *importer) typ() *types.Type { ...@@ -502,7 +502,7 @@ func (p *importer) typ() *types.Type {
// read associated methods // read associated methods
for i := p.int(); i > 0; i-- { for i := p.int(); i > 0; i-- {
p.pos() mpos := p.pos()
sym := p.fieldSym() sym := p.fieldSym()
// during import unexported method names should be in the type's package // during import unexported method names should be in the type's package
...@@ -525,7 +525,7 @@ func (p *importer) typ() *types.Type { ...@@ -525,7 +525,7 @@ func (p *importer) typ() *types.Type {
continue continue
} }
n := newfuncname(methodname(sym, recv[0].Type)) n := newfuncnamel(mpos, methodname(sym, recv[0].Type))
n.Type = mt n.Type = mt
checkwidth(n.Type) checkwidth(n.Type)
p.funcList = append(p.funcList, n) p.funcList = append(p.funcList, n)
...@@ -626,7 +626,7 @@ func (p *importer) fieldList() (fields []*types.Field) { ...@@ -626,7 +626,7 @@ func (p *importer) fieldList() (fields []*types.Field) {
} }
func (p *importer) field() *types.Field { func (p *importer) field() *types.Field {
p.pos() pos := p.pos()
sym, alias := p.fieldName() sym, alias := p.fieldName()
typ := p.typ() typ := p.typ()
note := p.string() note := p.string()
...@@ -646,7 +646,7 @@ func (p *importer) field() *types.Field { ...@@ -646,7 +646,7 @@ func (p *importer) field() *types.Field {
} }
f.Sym = sym f.Sym = sym
f.Nname = asTypesNode(newname(sym)) f.Nname = asTypesNode(newnamel(pos, sym))
f.Type = typ f.Type = typ
f.Note = note f.Note = note
...@@ -670,14 +670,14 @@ func (p *importer) methodList() (methods []*types.Field) { ...@@ -670,14 +670,14 @@ func (p *importer) methodList() (methods []*types.Field) {
} }
func (p *importer) method() *types.Field { func (p *importer) method() *types.Field {
p.pos() pos := p.pos()
sym := p.methodName() sym := p.methodName()
params := p.paramList() params := p.paramList()
result := p.paramList() result := p.paramList()
f := types.NewField() f := types.NewField()
f.Sym = sym f.Sym = sym
f.Nname = asTypesNode(newname(sym)) f.Nname = asTypesNode(newnamel(pos, sym))
f.Type = functypefield(fakeRecvField(), params, result) f.Type = functypefield(fakeRecvField(), params, result)
return f return f
} }
......
...@@ -212,7 +212,13 @@ func newnoname(s *types.Sym) *Node { ...@@ -212,7 +212,13 @@ func newnoname(s *types.Sym) *Node {
// newfuncname generates a new name node for a function or method. // newfuncname generates a new name node for a function or method.
// TODO(rsc): Use an ODCLFUNC node instead. See comment in CL 7360. // TODO(rsc): Use an ODCLFUNC node instead. See comment in CL 7360.
func newfuncname(s *types.Sym) *Node { func newfuncname(s *types.Sym) *Node {
n := newname(s) return newfuncnamel(lineno, s)
}
// newfuncnamel generates a new name node for a function or method.
// TODO(rsc): Use an ODCLFUNC node instead. See comment in CL 7360.
func newfuncnamel(pos src.XPos, s *types.Sym) *Node {
n := newnamel(pos, s)
n.Func = new(Func) n.Func = new(Func)
n.Func.SetIsHiddenClosure(Curfn != nil) n.Func.SetIsHiddenClosure(Curfn != nil)
return n return n
...@@ -227,11 +233,15 @@ func dclname(s *types.Sym) *Node { ...@@ -227,11 +233,15 @@ func dclname(s *types.Sym) *Node {
} }
func typenod(t *types.Type) *Node { func typenod(t *types.Type) *Node {
return typenodl(lineno, t)
}
func typenodl(pos src.XPos, t *types.Type) *Node {
// if we copied another type with *t = *u // if we copied another type with *t = *u
// then t->nod might be out of date, so // then t->nod might be out of date, so
// check t->nod->type too // check t->nod->type too
if asNode(t.Nod) == nil || asNode(t.Nod).Type != t { if asNode(t.Nod) == nil || asNode(t.Nod).Type != t {
t.Nod = asTypesNode(nod(OTYPE, nil, nil)) t.Nod = asTypesNode(nodl(pos, OTYPE, nil, nil))
asNode(t.Nod).Type = t asNode(t.Nod).Type = t
asNode(t.Nod).Sym = t.Sym asNode(t.Nod).Sym = t.Sym
} }
......
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"bytes" "bytes"
"cmd/compile/internal/types" "cmd/compile/internal/types"
"cmd/internal/bio" "cmd/internal/bio"
"cmd/internal/src"
"fmt" "fmt"
"unicode" "unicode"
"unicode/utf8" "unicode/utf8"
...@@ -280,12 +281,12 @@ func importsym(pkg *types.Pkg, s *types.Sym, op Op) { ...@@ -280,12 +281,12 @@ func importsym(pkg *types.Pkg, s *types.Sym, op Op) {
// pkgtype returns the named type declared by symbol s. // pkgtype returns the named type declared by symbol s.
// If no such type has been declared yet, a forward declaration is returned. // If no such type has been declared yet, a forward declaration is returned.
// pkg is the package being imported // pkg is the package being imported
func pkgtype(pkg *types.Pkg, s *types.Sym) *types.Type { func pkgtype(pos src.XPos, pkg *types.Pkg, s *types.Sym) *types.Type {
importsym(pkg, s, OTYPE) importsym(pkg, s, OTYPE)
if asNode(s.Def) == nil || asNode(s.Def).Op != OTYPE { if asNode(s.Def) == nil || asNode(s.Def).Op != OTYPE {
t := types.New(TFORW) t := types.New(TFORW)
t.Sym = s t.Sym = s
s.Def = asTypesNode(typenod(t)) s.Def = asTypesNode(typenodl(pos, t))
asNode(s.Def).Name = new(Name) asNode(s.Def).Name = new(Name)
} }
...@@ -326,7 +327,7 @@ func importconst(pkg *types.Pkg, s *types.Sym, t *types.Type, n *Node) { ...@@ -326,7 +327,7 @@ func importconst(pkg *types.Pkg, s *types.Sym, t *types.Type, n *Node) {
// importvar declares symbol s as an imported variable with type t. // importvar declares symbol s as an imported variable with type t.
// pkg is the package being imported // pkg is the package being imported
func importvar(pkg *types.Pkg, s *types.Sym, t *types.Type) { func importvar(pos src.XPos, pkg *types.Pkg, s *types.Sym, t *types.Type) {
importsym(pkg, s, ONAME) importsym(pkg, s, ONAME)
if asNode(s.Def) != nil && asNode(s.Def).Op == ONAME { if asNode(s.Def) != nil && asNode(s.Def).Op == ONAME {
if eqtype(t, asNode(s.Def).Type) { if eqtype(t, asNode(s.Def).Type) {
...@@ -335,7 +336,7 @@ func importvar(pkg *types.Pkg, s *types.Sym, t *types.Type) { ...@@ -335,7 +336,7 @@ func importvar(pkg *types.Pkg, s *types.Sym, t *types.Type) {
yyerror("inconsistent definition for var %v during import\n\t%v (in %q)\n\t%v (in %q)", s, asNode(s.Def).Type, s.Importdef.Path, t, pkg.Path) yyerror("inconsistent definition for var %v during import\n\t%v (in %q)\n\t%v (in %q)", s, asNode(s.Def).Type, s.Importdef.Path, t, pkg.Path)
} }
n := newname(s) n := newnamel(pos, s)
s.Importdef = pkg s.Importdef = pkg
n.Type = t n.Type = t
declare(n, PEXTERN) declare(n, PEXTERN)
...@@ -347,7 +348,7 @@ func importvar(pkg *types.Pkg, s *types.Sym, t *types.Type) { ...@@ -347,7 +348,7 @@ func importvar(pkg *types.Pkg, s *types.Sym, t *types.Type) {
// importalias declares symbol s as an imported type alias with type t. // importalias declares symbol s as an imported type alias with type t.
// pkg is the package being imported // pkg is the package being imported
func importalias(pkg *types.Pkg, s *types.Sym, t *types.Type) { func importalias(pos src.XPos, pkg *types.Pkg, s *types.Sym, t *types.Type) {
importsym(pkg, s, OTYPE) importsym(pkg, s, OTYPE)
if asNode(s.Def) != nil && asNode(s.Def).Op == OTYPE { if asNode(s.Def) != nil && asNode(s.Def).Op == OTYPE {
if eqtype(t, asNode(s.Def).Type) { if eqtype(t, asNode(s.Def).Type) {
...@@ -356,7 +357,7 @@ func importalias(pkg *types.Pkg, s *types.Sym, t *types.Type) { ...@@ -356,7 +357,7 @@ func importalias(pkg *types.Pkg, s *types.Sym, t *types.Type) {
yyerror("inconsistent definition for type alias %v during import\n\t%v (in %q)\n\t%v (in %q)", s, asNode(s.Def).Type, s.Importdef.Path, t, pkg.Path) yyerror("inconsistent definition for type alias %v during import\n\t%v (in %q)\n\t%v (in %q)", s, asNode(s.Def).Type, s.Importdef.Path, t, pkg.Path)
} }
n := newname(s) n := newnamel(pos, s)
n.Op = OTYPE n.Op = OTYPE
s.Importdef = pkg s.Importdef = pkg
n.Type = t n.Type = t
......
...@@ -874,7 +874,7 @@ func loadsys() { ...@@ -874,7 +874,7 @@ func loadsys() {
n.Type = typ n.Type = typ
declare(n, PFUNC) declare(n, PFUNC)
case varTag: case varTag:
importvar(Runtimepkg, sym, typ) importvar(lineno, Runtimepkg, sym, typ)
default: default:
Fatalf("unhandled declaration tag %v", d.tag) Fatalf("unhandled declaration tag %v", d.tag)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment