mirror of https://github.com/golang/go.git
[dev.regabi] cmd/compile/internal/types: add pos/sym/typ params to NewField
These are almost always set, so might as well expect callers to
provide them. They're also all required by go/types's corresponding
New{Field,Func,Param,Var} functions, so this eases API compatibility.
Passes toolstash-check.
Change-Id: Ib3fa355d4961243cd285b41915e87652ae2c22f6
Reviewed-on: https://go-review.googlesource.com/c/go/+/272386
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
762eda346a
commit
e1047302bd
|
|
@ -74,11 +74,8 @@ func expandiface(t *types.Type) {
|
||||||
// (including broken ones, if any) and add to t's
|
// (including broken ones, if any) and add to t's
|
||||||
// method set.
|
// method set.
|
||||||
for _, t1 := range m.Type.Fields().Slice() {
|
for _, t1 := range m.Type.Fields().Slice() {
|
||||||
f := types.NewField()
|
// Use m.Pos rather than t1.Pos to preserve embedding position.
|
||||||
f.Pos = m.Pos // preserve embedding position
|
f := types.NewField(m.Pos, t1.Sym, t1.Type)
|
||||||
f.Sym = t1.Sym
|
|
||||||
f.Type = t1.Type
|
|
||||||
f.SetBroke(t1.Broke())
|
|
||||||
addMethod(f, false)
|
addMethod(f, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ package gc
|
||||||
import (
|
import (
|
||||||
"cmd/compile/internal/syntax"
|
"cmd/compile/internal/syntax"
|
||||||
"cmd/compile/internal/types"
|
"cmd/compile/internal/types"
|
||||||
|
"cmd/internal/src"
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -266,10 +267,8 @@ func transformclosure(xfunc *Node) {
|
||||||
v.SetClass(PPARAM)
|
v.SetClass(PPARAM)
|
||||||
decls = append(decls, v)
|
decls = append(decls, v)
|
||||||
|
|
||||||
fld := types.NewField()
|
fld := types.NewField(src.NoXPos, v.Sym, v.Type)
|
||||||
fld.Nname = asTypesNode(v)
|
fld.Nname = asTypesNode(v)
|
||||||
fld.Type = v.Type
|
|
||||||
fld.Sym = v.Sym
|
|
||||||
params = append(params, fld)
|
params = append(params, fld)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -543,35 +543,19 @@ func structfield(n *Node) *types.Field {
|
||||||
Fatalf("structfield: oops %v\n", n)
|
Fatalf("structfield: oops %v\n", n)
|
||||||
}
|
}
|
||||||
|
|
||||||
f := types.NewField()
|
|
||||||
f.Pos = n.Pos
|
|
||||||
f.Sym = n.Sym
|
|
||||||
|
|
||||||
if n.Left != nil {
|
if n.Left != nil {
|
||||||
n.Left = typecheck(n.Left, ctxType)
|
n.Left = typecheck(n.Left, ctxType)
|
||||||
n.Type = n.Left.Type
|
n.Type = n.Left.Type
|
||||||
n.Left = nil
|
n.Left = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
f.Type = n.Type
|
f := types.NewField(n.Pos, n.Sym, n.Type)
|
||||||
if f.Type == nil {
|
|
||||||
f.SetBroke(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
if n.Embedded() {
|
if n.Embedded() {
|
||||||
checkembeddedtype(n.Type)
|
checkembeddedtype(n.Type)
|
||||||
f.Embedded = 1
|
f.Embedded = 1
|
||||||
} else {
|
|
||||||
f.Embedded = 0
|
|
||||||
}
|
}
|
||||||
|
if n.HasVal() {
|
||||||
switch u := n.Val().U.(type) {
|
f.Note = n.Val().U.(string)
|
||||||
case string:
|
|
||||||
f.Note = u
|
|
||||||
default:
|
|
||||||
yyerror("field tag must be a string")
|
|
||||||
case nil:
|
|
||||||
// no-op
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lineno = lno
|
lineno = lno
|
||||||
|
|
@ -671,13 +655,7 @@ func interfacefield(n *Node) *types.Field {
|
||||||
n.Left = nil
|
n.Left = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
f := types.NewField()
|
f := types.NewField(n.Pos, n.Sym, n.Type)
|
||||||
f.Pos = n.Pos
|
|
||||||
f.Sym = n.Sym
|
|
||||||
f.Type = n.Type
|
|
||||||
if f.Type == nil {
|
|
||||||
f.SetBroke(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
lineno = lno
|
lineno = lno
|
||||||
return f
|
return f
|
||||||
|
|
@ -705,9 +683,7 @@ func fakeRecv() *Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
func fakeRecvField() *types.Field {
|
func fakeRecvField() *types.Field {
|
||||||
f := types.NewField()
|
return types.NewField(src.NoXPos, nil, types.FakeRecvType())
|
||||||
f.Type = types.FakeRecvType()
|
|
||||||
return f
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// isifacemethod reports whether (field) m is
|
// isifacemethod reports whether (field) m is
|
||||||
|
|
@ -920,10 +896,7 @@ func addmethod(msym *types.Sym, t *types.Type, local, nointerface bool) *types.F
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
f := types.NewField()
|
f := types.NewField(lineno, msym, t)
|
||||||
f.Pos = lineno
|
|
||||||
f.Sym = msym
|
|
||||||
f.Type = t
|
|
||||||
f.SetNointerface(nointerface)
|
f.SetNointerface(nointerface)
|
||||||
|
|
||||||
mt.Methods().Append(f)
|
mt.Methods().Append(f)
|
||||||
|
|
|
||||||
|
|
@ -327,11 +327,7 @@ func (r *importReader) doDecl(n *Node) {
|
||||||
recv := r.param()
|
recv := r.param()
|
||||||
mtyp := r.signature(recv)
|
mtyp := r.signature(recv)
|
||||||
|
|
||||||
f := types.NewField()
|
ms[i] = types.NewField(mpos, msym, mtyp)
|
||||||
f.Pos = mpos
|
|
||||||
f.Sym = msym
|
|
||||||
f.Type = mtyp
|
|
||||||
ms[i] = f
|
|
||||||
|
|
||||||
m := newfuncnamel(mpos, methodSym(recv.Type, msym))
|
m := newfuncnamel(mpos, methodSym(recv.Type, msym))
|
||||||
m.Type = mtyp
|
m.Type = mtyp
|
||||||
|
|
@ -547,10 +543,7 @@ func (r *importReader) typ1() *types.Type {
|
||||||
emb := r.bool()
|
emb := r.bool()
|
||||||
note := r.string()
|
note := r.string()
|
||||||
|
|
||||||
f := types.NewField()
|
f := types.NewField(pos, sym, typ)
|
||||||
f.Pos = pos
|
|
||||||
f.Sym = sym
|
|
||||||
f.Type = typ
|
|
||||||
if emb {
|
if emb {
|
||||||
f.Embedded = 1
|
f.Embedded = 1
|
||||||
}
|
}
|
||||||
|
|
@ -571,10 +564,7 @@ func (r *importReader) typ1() *types.Type {
|
||||||
pos := r.pos()
|
pos := r.pos()
|
||||||
typ := r.typ()
|
typ := r.typ()
|
||||||
|
|
||||||
f := types.NewField()
|
embeddeds[i] = types.NewField(pos, nil, typ)
|
||||||
f.Pos = pos
|
|
||||||
f.Type = typ
|
|
||||||
embeddeds[i] = f
|
|
||||||
}
|
}
|
||||||
|
|
||||||
methods := make([]*types.Field, r.uint64())
|
methods := make([]*types.Field, r.uint64())
|
||||||
|
|
@ -583,11 +573,7 @@ func (r *importReader) typ1() *types.Type {
|
||||||
sym := r.ident()
|
sym := r.ident()
|
||||||
typ := r.signature(fakeRecvField())
|
typ := r.signature(fakeRecvField())
|
||||||
|
|
||||||
f := types.NewField()
|
methods[i] = types.NewField(pos, sym, typ)
|
||||||
f.Pos = pos
|
|
||||||
f.Sym = sym
|
|
||||||
f.Type = typ
|
|
||||||
methods[i] = f
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t := types.New(TINTER)
|
t := types.New(TINTER)
|
||||||
|
|
@ -624,11 +610,7 @@ func (r *importReader) paramList() []*types.Field {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *importReader) param() *types.Field {
|
func (r *importReader) param() *types.Field {
|
||||||
f := types.NewField()
|
return types.NewField(r.pos(), r.ident(), r.typ())
|
||||||
f.Pos = r.pos()
|
|
||||||
f.Sym = r.ident()
|
|
||||||
f.Type = r.typ()
|
|
||||||
return f
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *importReader) bool() bool {
|
func (r *importReader) bool() bool {
|
||||||
|
|
|
||||||
|
|
@ -73,10 +73,8 @@ func uncommonSize(t *types.Type) int { // Sizeof(runtime.uncommontype{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func makefield(name string, t *types.Type) *types.Field {
|
func makefield(name string, t *types.Type) *types.Field {
|
||||||
f := types.NewField()
|
sym := (*types.Pkg)(nil).Lookup(name)
|
||||||
f.Type = t
|
return types.NewField(src.NoXPos, sym, t)
|
||||||
f.Sym = (*types.Pkg)(nil).Lookup(name)
|
|
||||||
return f
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// bmap makes the map bucket type given the type of the map.
|
// bmap makes the map bucket type given the type of the map.
|
||||||
|
|
@ -301,13 +299,11 @@ func hiter(t *types.Type) *types.Type {
|
||||||
// stksize bytes of args.
|
// stksize bytes of args.
|
||||||
func deferstruct(stksize int64) *types.Type {
|
func deferstruct(stksize int64) *types.Type {
|
||||||
makefield := func(name string, typ *types.Type) *types.Field {
|
makefield := func(name string, typ *types.Type) *types.Field {
|
||||||
f := types.NewField()
|
|
||||||
f.Type = typ
|
|
||||||
// Unlike the global makefield function, this one needs to set Pkg
|
// Unlike the global makefield function, this one needs to set Pkg
|
||||||
// because these types might be compared (in SSA CSE sorting).
|
// because these types might be compared (in SSA CSE sorting).
|
||||||
// TODO: unify this makefield and the global one above.
|
// TODO: unify this makefield and the global one above.
|
||||||
f.Sym = &types.Sym{Name: name, Pkg: localpkg}
|
sym := &types.Sym{Name: name, Pkg: localpkg}
|
||||||
return f
|
return types.NewField(src.NoXPos, sym, typ)
|
||||||
}
|
}
|
||||||
argtype := types.NewArray(types.Types[TUINT8], stksize)
|
argtype := types.NewArray(types.Types[TUINT8], stksize)
|
||||||
argtype.Width = stksize
|
argtype.Width = stksize
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,10 @@
|
||||||
|
|
||||||
package gc
|
package gc
|
||||||
|
|
||||||
import "cmd/compile/internal/types"
|
import (
|
||||||
|
"cmd/compile/internal/types"
|
||||||
|
"cmd/internal/src"
|
||||||
|
)
|
||||||
|
|
||||||
// builtinpkg is a fake package that declares the universe block.
|
// builtinpkg is a fake package that declares the universe block.
|
||||||
var builtinpkg *types.Pkg
|
var builtinpkg *types.Pkg
|
||||||
|
|
@ -355,16 +358,14 @@ func typeinit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeErrorInterface() *types.Type {
|
func makeErrorInterface() *types.Type {
|
||||||
field := types.NewField()
|
sig := functypefield(fakeRecvField(), nil, []*types.Field{
|
||||||
field.Type = types.Types[TSTRING]
|
types.NewField(src.NoXPos, nil, types.Types[TSTRING]),
|
||||||
f := functypefield(fakeRecvField(), nil, []*types.Field{field})
|
})
|
||||||
|
|
||||||
field = types.NewField()
|
method := types.NewField(src.NoXPos, lookup("Error"), sig)
|
||||||
field.Sym = lookup("Error")
|
|
||||||
field.Type = f
|
|
||||||
|
|
||||||
t := types.New(TINTER)
|
t := types.New(TINTER)
|
||||||
t.SetInterface([]*types.Field{field})
|
t.SetInterface([]*types.Field{method})
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -583,10 +583,17 @@ func NewFuncArgs(f *Type) *Type {
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewField() *Field {
|
func NewField(pos src.XPos, sym *Sym, typ *Type) *Field {
|
||||||
return &Field{
|
f := &Field{
|
||||||
|
Pos: pos,
|
||||||
|
Sym: sym,
|
||||||
|
Type: typ,
|
||||||
Offset: BADWIDTH,
|
Offset: BADWIDTH,
|
||||||
}
|
}
|
||||||
|
if typ == nil {
|
||||||
|
f.SetBroke(true)
|
||||||
|
}
|
||||||
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubstAny walks t, replacing instances of "any" with successive
|
// SubstAny walks t, replacing instances of "any" with successive
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue