case TFUNCARGS:
t1 := t.Type
- w = widstruct(t.Type, getthisx(t1), 0, 0)
- w = widstruct(t.Type, getinargx(t1), w, Widthreg)
- w = widstruct(t.Type, getoutargx(t1), w, Widthreg)
+ w = widstruct(t.Type, t1.Recv(), 0, 0)
+ w = widstruct(t.Type, t1.Params(), w, Widthreg)
+ w = widstruct(t.Type, t1.Results(), w, Widthreg)
t1.Argwid = w
if w%int64(Widthreg) != 0 {
Warn("bad type %v %d\n", t1, w)
func Argsize(t *Type) int {
var w int64
- for fp, ip := IterFields(getoutargx(t)); fp != nil; fp = ip.Next() {
+ for fp, ip := IterFields(t.Results()); fp != nil; fp = ip.Next() {
if x := fp.Width + fp.Type.Width; x > w {
w = x
}
for _, m := range methods {
p.string(m.Sym.Name)
- p.paramList(getthisx(m.Type))
- p.paramList(getinargx(m.Type))
- p.paramList(getoutargx(m.Type))
+ p.paramList(m.Type.Recv())
+ p.paramList(m.Type.Params())
+ p.paramList(m.Type.Results())
p.inlinedBody(m.Type.Nname)
if p.trace && m.Down != nil {
case TFUNC:
p.tag(signatureTag)
- p.paramList(getinargx(t))
- p.paramList(getoutargx(t))
+ p.paramList(t.Params())
+ p.paramList(t.Results())
case TINTER:
p.tag(interfaceTag)
// TODO(gri) For functions signatures, we use p.typ() to export
// so we could share the same type with multiple functions. Do
// the same here, or never try to do this for functions.
- p.paramList(getinargx(m.Type))
- p.paramList(getoutargx(m.Type))
+ p.paramList(m.Type.Params())
+ p.paramList(m.Type.Results())
}
// fieldName is like qualifiedName but it doesn't record the package
cgen_callinter(n, nil, 0)
}
- fp, _ := IterFields(getoutargx(n.Left.Type))
+ fp, _ := IterFields(n.Left.Type.Results())
*a = Node{}
a.Op = OINDREG
a.Reg = int16(Thearch.REGSP)
t = t.Type
}
- t, _ = IterFields(getoutargx(t))
+ t, _ = IterFields(t.Results())
if t != nil {
return t.Width + Ctxt.FixedFrameSize()
}
t = t.Type
}
- fp, _ := IterFields(getoutargx(t))
+ fp, _ := IterFields(t.Results())
if fp == nil {
Fatalf("cgen_callret: nil")
}
t = t.Type
}
- fp, _ := IterFields(getoutargx(t))
+ fp, _ := IterFields(t.Results())
if fp == nil {
Fatalf("cgen_aret: nil")
}
// Get pointer to input arguments.
// We are going to insert captured variables before input args.
- param := &getinargx(f.Type).Type
+ param := &f.Type.Params().Type
original_args := *param // old input args
original_dcl := xfunc.Func.Dcl
xfunc.Func.Dcl = nil
Curfn = xfunc
var fld *Node
var n *Node
- for t := getinargx(t0).Type; t != nil; t = t.Down {
+ for t, it := IterFields(t0.Params()); t != nil; t = it.Next() {
n = newname(Lookupf("a%d", i))
i++
n.Class = PPARAM
i = 0
l = nil
var retargs []*Node
- for t := getoutargx(t0).Type; t != nil; t = t.Down {
+ for t, it := IterFields(t0.Results()); t != nil; t = it.Next() {
n = newname(Lookupf("r%d", i))
i++
n.Class = PPARAMOUT
}
if t.Thistuple != 0 {
- var n *Node
- for ft := getthisx(t).Type; ft != nil; ft = ft.Down {
+ for ft, it := IterFields(t.Recv()); ft != nil; ft = it.Next() {
if ft.Nname == nil || ft.Nname.Sym == nil {
continue
}
- n = ft.Nname // no need for newname(ft->nname->sym)
+ n := ft.Nname // no need for newname(ft->nname->sym)
n.Type = ft.Type
declare(n, PPARAM)
}
}
if t.Intuple != 0 {
- var n *Node
- for ft := getinargx(t).Type; ft != nil; ft = ft.Down {
+ for ft, it := IterFields(t.Params()); ft != nil; ft = it.Next() {
if ft.Nname == nil || ft.Nname.Sym == nil {
continue
}
- n = ft.Nname
+ n := ft.Nname
n.Type = ft.Type
declare(n, PPARAM)
}
}
if t.Outtuple != 0 {
- var n *Node
- for ft := getoutargx(t).Type; ft != nil; ft = ft.Down {
+ for ft, it := IterFields(t.Results()); ft != nil; ft = it.Next() {
if ft.Nname == nil || ft.Nname.Sym == nil {
continue
}
- n = ft.Nname
+ n := ft.Nname
n.Type = ft.Type
declare(n, PPARAMOUT)
}
// Those methods have an anonymous *struct{} as the receiver.
// (See fakethis above.)
func isifacemethod(f *Type) bool {
- rcvr := getthisx(f).Type
+ rcvr := f.Recv().Type
if rcvr.Sym != nil {
return false
}
if this != nil {
rcvr = []*Node{this}
}
- t.Type = tofunargs(rcvr)
- t.Type.Down = tofunargs(out)
- t.Type.Down.Down = tofunargs(in)
+ *t.RecvP() = tofunargs(rcvr)
+ *t.ResultsP() = tofunargs(out)
+ *t.ParamsP() = tofunargs(in)
uniqgen++
- checkdupfields(t.Type.Type, "argument")
- checkdupfields(t.Type.Down.Type, "argument")
- checkdupfields(t.Type.Down.Down.Type, "argument")
+ checkdupfields(t.Recv().Type, "argument")
+ checkdupfields(t.Results().Type, "argument")
+ checkdupfields(t.Params().Type, "argument")
- if t.Type.Broke || t.Type.Down.Broke || t.Type.Down.Down.Broke {
+ if t.Recv().Broke || t.Results().Broke || t.Params().Broke {
t.Broke = true
}
}
// get parent type sym
- pa := getthisx(t).Type // ptr to this structure
+ pa := t.Recv().Type // ptr to this structure
if pa == nil {
Yyerror("missing receiver")
return
i := 0
nE := e.nodeEscState(n)
nE.Escretval.Set(nil) // Suspect this is not nil for indirect calls.
- for t := getoutargx(fntype).Type; t != nil; t = t.Down {
+ for t, it := IterFields(fntype.Results()); t != nil; t = it.Next() {
src := Nod(ONAME, nil, nil)
buf := fmt.Sprintf(".out%d", i)
i++
initEscretval(e, n, fntype)
// If there is a receiver, it also leaks to heap.
if n.Op != OCALLFUNC {
- t := getthisx(fntype).Type
+ t := fntype.Recv().Type
src := n.Left.Left
if haspointers(t.Type) {
escassign(e, &e.theSink, src)
// Receiver.
if n.Op != OCALLFUNC {
- t := getthisx(fntype).Type
+ t := fntype.Recv().Type
src := n.Left.Left
if haspointers(t.Type) {
escassignfromtag(e, t.Note, nE.Escretval, src)
var src *Node
it := nodeSeqIterate(ll)
- for t := getinargx(fntype).Type; !it.Done(); it.Next() {
+ for t := fntype.Params().Type; !it.Done(); it.Next() {
src = it.N()
if t.Isddd && !n.Isddd {
// Introduce ODDDARG node to represent ... allocation.
// unless //go:noescape is given before the declaration.
if len(func_.Nbody.Slice()) == 0 {
if func_.Noescape {
- for t := getinargx(func_.Type).Type; t != nil; t = t.Down {
+ for t, it := IterFields(func_.Type.Params()); t != nil; t = it.Next() {
if haspointers(t.Type) {
t.Note = mktag(EscNone)
}
// but we are reusing the ability to annotate an individual function
// argument and pass those annotations along to importing code.
narg := 0
- for t := getinargx(func_.Type).Type; t != nil; t = t.Down {
+ for t, it := IterFields(func_.Type.Params()); t != nil; t = it.Next() {
narg++
if t.Type.Etype == TUINTPTR {
if Debug['m'] != 0 {
if Debug['l'] < 2 {
typecheckinl(f.Type.Nname)
}
- exportf("\tfunc (%v) %v %v { %v }\n", Tconv(getthisx(f.Type).Type, obj.FmtSharp), Sconv(f.Sym, obj.FmtShort|obj.FmtByte|obj.FmtSharp), Tconv(f.Type, obj.FmtShort|obj.FmtSharp), Hconv(f.Type.Nname.Func.Inl, obj.FmtSharp))
+ exportf("\tfunc (%v) %v %v { %v }\n", Tconv(f.Type.Recv().Type, obj.FmtSharp), Sconv(f.Sym, obj.FmtShort|obj.FmtByte|obj.FmtSharp), Tconv(f.Type, obj.FmtShort|obj.FmtSharp), Hconv(f.Type.Nname.Func.Inl, obj.FmtSharp))
reexportdeplist(f.Type.Nname.Func.Inl)
} else {
- exportf("\tfunc (%v) %v %v\n", Tconv(getthisx(f.Type).Type, obj.FmtSharp), Sconv(f.Sym, obj.FmtShort|obj.FmtByte|obj.FmtSharp), Tconv(f.Type, obj.FmtShort|obj.FmtSharp))
+ exportf("\tfunc (%v) %v %v\n", Tconv(f.Type.Recv().Type, obj.FmtSharp), Sconv(f.Sym, obj.FmtShort|obj.FmtByte|obj.FmtSharp), Tconv(f.Type, obj.FmtShort|obj.FmtSharp))
}
}
}
} else {
if t.Thistuple != 0 {
buf.WriteString("method")
- buf.WriteString(Tconv(getthisx(t), 0))
+ buf.WriteString(Tconv(t.Recv(), 0))
buf.WriteString(" ")
}
buf.WriteString("func")
}
- buf.WriteString(Tconv(getinargx(t), 0))
+ buf.WriteString(Tconv(t.Params(), 0))
switch t.Outtuple {
case 0:
case 1:
if fmtmode != FExp {
buf.WriteString(" ")
- buf.WriteString(Tconv(getoutargx(t).Type.Type, 0)) // struct->field->field's type
+ buf.WriteString(Tconv(t.Results().Type.Type, 0)) // struct->field->field's type
break
}
fallthrough
default:
buf.WriteString(" ")
- buf.WriteString(Tconv(getoutargx(t), 0))
+ buf.WriteString(Tconv(t.Results(), 0))
}
return buf.String()
r1.Type = byteptr
r2.Type = byteptr
setNodeSeq(&call.List, list(list(list1(&r1), &r2), typename(n.Left.Type)))
- setNodeSeq(&call.List, ascompatte(OCALLFUNC, call, false, getinarg(fn.Type), call.List.Slice(), 0, nil))
+ setNodeSeq(&call.List, ascompatte(OCALLFUNC, call, false, fn.Type.ParamsP(), call.List.Slice(), 0, nil))
gen(call)
Regfree(&r1)
Regfree(&r2)
dowidth(fn.Type)
call := Nod(OCALLFUNC, fn, nil)
setNodeSeq(&call.List, list(list(list1(&r1), &r2), typename(n.Left.Type)))
- setNodeSeq(&call.List, ascompatte(OCALLFUNC, call, false, getinarg(fn.Type), call.List.Slice(), 0, nil))
+ setNodeSeq(&call.List, ascompatte(OCALLFUNC, call, false, fn.Type.ParamsP(), call.List.Slice(), 0, nil))
gen(call)
Regfree(&r1)
Regfree(&r2)
func fnpkg(fn *Node) *Pkg {
if fn.Type.Thistuple != 0 {
// method
- rcvr := getthisx(fn.Type).Type.Type
+ rcvr := fn.Type.Recv().Type.Type
if Isptr[rcvr.Etype] {
rcvr = rcvr.Type
// can't handle ... args yet
if Debug['l'] < 3 {
- for t := fn.Type.Type.Down.Down.Type; t != nil; t = t.Down {
+ for t, it := IterFields(fn.Type.Params()); t != nil; t = it.Next() {
if t.Isddd {
return
}
// temporaries for return values.
var m *Node
- for t := getoutargx(fn.Type).Type; t != nil; t = t.Down {
+ for t, it := IterFields(fn.Type.Results()); t != nil; t = it.Next() {
if t != nil && t.Nname != nil && !isblank(t.Nname) {
m = inlvar(t.Nname)
typecheck(&m, Erv)
var as *Node
if fn.Type.Thistuple != 0 && n.Left.Op == ODOTMETH {
// method call with a receiver.
- t := getthisx(fn.Type).Type
+ t := fn.Type.Recv().Type
if t != nil && t.Nname != nil && !isblank(t.Nname) && t.Nname.Name.Inlvar == nil {
Fatalf("missing inlvar for %v\n", t.Nname)
var varargtype *Type
varargcount := 0
- for t := fn.Type.Type.Down.Down.Type; t != nil; t = t.Down {
+ for t, it := IterFields(fn.Type.Params()); t != nil; t = it.Next() {
if t.Isddd {
variadic = true
varargtype = t.Type
}
// append receiver inlvar to LHS.
- t := getthisx(fn.Type).Type
+ t := fn.Type.Recv().Type
if t != nil && t.Nname != nil && !isblank(t.Nname) && t.Nname.Name.Inlvar == nil {
Fatalf("missing inlvar for %v\n", t.Nname)
if !chkargcount {
// 0 or 1 expression on RHS.
var i int
- for t := getinargx(fn.Type).Type; t != nil; t = t.Down {
+ for t, it2 := IterFields(fn.Type.Params()); t != nil; t = it2.Next() {
if variadic && t.Isddd {
vararg = tinlvar(t)
for i = 0; i < varargcount && it.Len() != 0; i++ {
} else {
// match arguments except final variadic (unless the call is dotted itself)
var t *Type
- for t = getinargx(fn.Type).Type; t != nil; {
+ for t = fn.Type.Params().Type; t != nil; {
if it.Done() {
break
}
}
if !it.Done() || t != nil {
- Fatalf("arg count mismatch: %v vs %v\n", Tconv(getinargx(fn.Type), obj.FmtSharp), Hconv(n.List, obj.FmtComma))
+ Fatalf("arg count mismatch: %v vs %v\n", Tconv(fn.Type.Params(), obj.FmtSharp), Hconv(n.List, obj.FmtComma))
}
}
out.Type.Type = Types[TSTRING]
out.Funarg = true
f := typ(TFUNC)
- *getthis(f) = rcvr
- *Getoutarg(f) = out
- *getinarg(f) = in
+ *f.RecvP() = rcvr
+ *f.ResultsP() = out
+ *f.ParamsP() = in
f.Thistuple = 1
f.Intuple = 0
f.Outnamed = false
setNodeSeq(&n.List, ordercallargs(n.List, order))
if n.Op == OCALLFUNC {
- t := getinargx(n.Left.Type).Type
+ t := n.Left.Type.Params().Type
for it := nodeSeqIterate(n.List); !it.Done() && t != nil; it.Next() {
// Check for "unsafe-uintptr" tag provided by escape analysis.
// If present and the argument is really a pointer being converted
var xoffset int64
if Curfn.Type.Thistuple > 0 {
xoffset = 0
- onebitwalktype1(getthisx(Curfn.Type), &xoffset, bv)
+ onebitwalktype1(Curfn.Type.Recv(), &xoffset, bv)
}
if Curfn.Type.Intuple > 0 {
xoffset = 0
- onebitwalktype1(getinargx(Curfn.Type), &xoffset, bv)
+ onebitwalktype1(Curfn.Type.Params(), &xoffset, bv)
}
for j := 0; int32(j) < bv.n; j += 32 {
}
if Curfn.Type.Outtuple > 0 {
xoffset = 0
- onebitwalktype1(getoutargx(Curfn.Type), &xoffset, bv)
+ onebitwalktype1(Curfn.Type.Results(), &xoffset, bv)
for j := 0; int32(j) < bv.n; j += 32 {
off = duint32(sym, off, bv.b[j/32])
}
if Curfn.Type.Outnamed {
// add clearing of the output parameters
- for t, it := IterFields(getoutargx(Curfn.Type)); t != nil; t = it.Next() {
+ for t, it := IterFields(Curfn.Type.Results()); t != nil; t = it.Next() {
if t.Nname != nil {
n := Nod(OAS, t.Nname, nil)
typecheck(&n, Etop)
// If the receiver or arguments are unnamed, they will be omitted
// from the list above. Preserve those values - even though they are unused -
// in order to keep their addresses live for use in stack traces.
- thisargtype := getthisx(lv.fn.Type)
+ thisargtype := lv.fn.Type.Recv()
if thisargtype != nil {
xoffset = 0
onebitwalktype1(thisargtype, &xoffset, args)
}
- inargtype := getinargx(lv.fn.Type)
+ inargtype := lv.fn.Type.Params()
if inargtype != nil {
xoffset = 0
onebitwalktype1(inargtype, &xoffset, args)
a = Nod(OAS2, nil, nil)
setNodeSeq(&a.List, []*Node{hv1, hv2})
fn := syslook("stringiter2")
- setNodeSeq(&a.Rlist, []*Node{mkcall1(fn, getoutargx(fn.Type), nil, ha, hv1)})
+ setNodeSeq(&a.Rlist, []*Node{mkcall1(fn, fn.Type.Results(), nil, ha, hv1)})
}
n.Left = Nod(ONE, hv1, Nodintconst(0))
}
var d *Node
- for t := getinargx(f).Type; t != nil; t = t.Down {
+ for t, it := IterFields(f.Params()); t != nil; t = it.Next() {
d = Nod(ODCLFIELD, nil, nil)
d.Type = t.Type
d.Isddd = t.Isddd
}
var out []*Node
- for t := getoutargx(f).Type; t != nil; t = t.Down {
+ for t, it := IterFields(f.Results()); t != nil; t = it.Next() {
d = Nod(ODCLFIELD, nil, nil)
d.Type = t.Type
out = append(out, d)
if f.Type.Etype != TFUNC || f.Type.Thistuple == 0 {
Fatalf("non-method on %v method %v %v\n", mt, f.Sym, f)
}
- if getthisx(f.Type).Type == nil {
+ if f.Type.Recv().Type == nil {
Fatalf("receiver with no type on %v method %v %v\n", mt, f.Sym, f)
}
if f.Nointerface {
// if pointer receiver but non-pointer t and
// this is not an embedded pointer inside a struct,
// method does not apply.
- this := getthisx(f.Type).Type.Type
+ this := f.Type.Recv().Type.Type
if Isptr[this.Etype] && this.Type == t {
continue
// imethods returns the methods of the interface type t, sorted by name.
func imethods(t *Type) []*Sig {
var methods []*Sig
- for f := t.Type; f != nil; f = f.Down {
+ for f, it := IterFields(t); f != nil; f = it.Next() {
if f.Etype != TFIELD {
Fatalf("imethods: not field")
}
case TSTRUCT:
ret = false
- for t1 := t.Type; t1 != nil; t1 = t1.Down {
+ for t1, it := IterFields(t); t1 != nil; t1 = it.Next() {
if haspointers(t1.Type) {
ret = true
break
case TSTRUCT:
// Find the last field that has pointers.
var lastPtrField *Type
- for t1 := t.Type; t1 != nil; t1 = t1.Down {
+ for t1, it := IterFields(t); t1 != nil; t1 = it.Next() {
if haspointers(t1.Type) {
lastPtrField = t1
}
return isreflexive(t.Type)
case TSTRUCT:
- for t1 := t.Type; t1 != nil; t1 = t1.Down {
+ for t1, it := IterFields(t); t1 != nil; t1 = it.Next() {
if !isreflexive(t1.Type) {
return false
}
return needkeyupdate(t.Type)
case TSTRUCT:
- for t1 := t.Type; t1 != nil; t1 = t1.Down {
+ for t1, it := IterFields(t); t1 != nil; t1 = it.Next() {
if needkeyupdate(t1.Type) {
return true
}
ot = dextratype(s, ot, t, 0)
case TFUNC:
- for t1 := getthisx(t).Type; t1 != nil; t1 = t1.Down {
+ for t1, it := IterFields(t.Recv()); t1 != nil; t1 = it.Next() {
dtypesym(t1.Type)
}
isddd := false
- for t1 := getinargx(t).Type; t1 != nil; t1 = t1.Down {
+ for t1, it := IterFields(t.Params()); t1 != nil; t1 = it.Next() {
isddd = t1.Isddd
dtypesym(t1.Type)
}
- for t1 := getoutargx(t).Type; t1 != nil; t1 = t1.Down {
+ for t1, it := IterFields(t.Results()); t1 != nil; t1 = it.Next() {
dtypesym(t1.Type)
}
ot = dextratype(s, ot, t, dataAdd)
// Array of rtype pointers follows funcType.
- for t1 := getthisx(t).Type; t1 != nil; t1 = t1.Down {
+ for t1, it := IterFields(t.Recv()); t1 != nil; t1 = it.Next() {
ot = dsymptr(s, ot, dtypesym(t1.Type), 0)
}
- for t1 := getinargx(t).Type; t1 != nil; t1 = t1.Down {
+ for t1, it := IterFields(t.Params()); t1 != nil; t1 = it.Next() {
ot = dsymptr(s, ot, dtypesym(t1.Type), 0)
}
- for t1 := getoutargx(t).Type; t1 != nil; t1 = t1.Down {
+ for t1, it := IterFields(t.Results()); t1 != nil; t1 = it.Next() {
ot = dsymptr(s, ot, dtypesym(t1.Type), 0)
}
case TSTRUCT:
n := 0
- for t1 := t.Type; t1 != nil; t1 = t1.Down {
+ for t1, it := IterFields(t); t1 != nil; t1 = it.Next() {
dtypesym(t1.Type)
n++
}
dataAdd := n * structfieldSize()
ot = dextratype(s, ot, t, dataAdd)
- for t1 := t.Type; t1 != nil; t1 = t1.Down {
- // ../../../../runtime/type.go:/structfield
+ for t1, it := IterFields(t); t1 != nil; t1 = it.Next() {
+ // ../../../../runtime/type.go:/structField
if t1.Sym != nil && t1.Embedded == 0 {
ot = dgostringptr(s, ot, t1.Sym.Name)
if exportname(t1.Sym.Name) {
p.w.Repeat(elem.Width/int64(Widthptr), count-1)
case TSTRUCT:
- for t1 := t.Type; t1 != nil; t1 = t1.Down {
+ for t1, it := IterFields(t); t1 != nil; t1 = it.Next() {
p.emit(t1.Type, offset+t1.Width)
}
}
// Start exit block, find address of result.
s.startBlock(bNext)
- fp, _ := IterFields(getoutargx(n.Left.Type))
+ fp, _ := IterFields(n.Left.Type.Results())
if fp == nil || k != callNormal {
// call has no return value. Continue with the next statement.
return nil
}
var a []*Type
- for f := t.Type; f != nil; f = f.Down {
+ for f, it := IterFields(t); f != nil; f = it.Next() {
a = append(a, f)
}
sort.Sort(methcmp(a))
// Loop over structs: receiver, in, out.
case TFUNC:
- t1 = t1.Type
- t2 = t2.Type
- for ; t1 != nil && t2 != nil; t1, t2 = t1.Down, t2.Down {
- if t1.Etype != TSTRUCT || t2.Etype != TSTRUCT {
- Fatalf("func missing struct: %v %v", t1, t2)
- }
-
+ for _, f := range [...]func(*Type) *Type{(*Type).Recv, (*Type).Results, (*Type).Params} {
// Loop over fields in structs, ignoring argument names.
- ta := t1.Type
- tb := t2.Type
- for ; ta != nil && tb != nil; ta, tb = ta.Down, tb.Down {
- if ta.Etype != TFIELD || tb.Etype != TFIELD {
- Fatalf("func struct missing field: %v %v", ta, tb)
- }
+ ta, ia := IterFields(f(t1))
+ tb, ib := IterFields(f(t2))
+ for ; ta != nil && tb != nil; ta, tb = ia.Next(), ib.Next() {
if ta.Isddd != tb.Isddd || !eqtype1(ta.Type, tb.Type, assumedEqual) {
return false
}
}
-
if ta != nil || tb != nil {
return false
}
}
-
- if t1 == nil && t2 == nil {
- return true
- }
- return false
+ return true
case TARRAY:
if t1.Bound != t2.Bound {
continue
case TFUNC:
- substAny(&t.Type, types)
- substAny(&t.Type.Down.Down, types)
- substAny(&t.Type.Down, types)
+ substAny(t.RecvP(), types)
+ substAny(t.ParamsP(), types)
+ substAny(t.ResultsP(), types)
case TSTRUCT:
for t = t.Type; t != nil; t = t.Down {
case TFUNC:
nt = shallow(t)
- nt.Type = deep(t.Type)
- nt.Type.Down = deep(t.Type.Down)
- nt.Type.Down.Down = deep(t.Type.Down.Down)
+ *nt.RecvP() = deep(t.Recv())
+ *nt.ResultsP() = deep(t.Results())
+ *nt.ParamsP() = deep(t.Params())
case TSTRUCT:
nt = shallow(t)
this := Nod(ODCLFIELD, newname(Lookup(".this")), typenod(rcvr))
this.Left.Name.Param.Ntype = this.Right
- in := structargs(getinarg(method.Type), 1)
- out := structargs(Getoutarg(method.Type), 0)
+ in := structargs(method.Type.ParamsP(), 1)
+ out := structargs(method.Type.ResultsP(), 0)
t := Nod(OTFUNC, nil, nil)
l := []*Node{this}
isddd = n.Left.Isddd
}
- methodrcvr := getthisx(method.Type).Type.Type
+ methodrcvr := method.Type.Recv().Type.Type
// generate nil pointer check for better error
if Isptr[rcvr.Etype] && rcvr.Type == methodrcvr {
// if pointer receiver in method,
// the method does not exist for value types.
- rcvr = getthisx(tm.Type).Type.Type
+ rcvr = tm.Type.Recv().Type.Type
if Isptr[rcvr.Etype] && !Isptr[t0.Etype] && !followptr && !isifacemethod(tm.Type) {
if false && Debug['r'] != 0 {
if t.Etype != TFUNC {
Fatalf("IterParams: type %v does not have params", t)
}
- i := Iter{a: getthisx(t).Type, b: getinargx(t).Type}
+ i := Iter{a: t.Recv().Type, b: t.Params().Type}
f := i.Next()
return f, i
}
return t
}
-func getthis(t *Type) **Type {
- if t.Etype != TFUNC {
- Fatalf("getthis: not a func %v", t)
+func (t *Type) wantEtype(et EType) {
+ if t.Etype != et {
+ Fatalf("want %v, but have %v", et, t)
}
- return &t.Type
}
-func Getoutarg(t *Type) **Type {
- if t.Etype != TFUNC {
- Fatalf("getoutarg: not a func %v", t)
- }
- return &t.Type.Down
+func (t *Type) RecvP() **Type {
+ t.wantEtype(TFUNC)
+ return &t.Type
}
-func getinarg(t *Type) **Type {
- if t.Etype != TFUNC {
- Fatalf("getinarg: not a func %v", t)
- }
+func (t *Type) ParamsP() **Type {
+ t.wantEtype(TFUNC)
return &t.Type.Down.Down
}
-func getthisx(t *Type) *Type {
- return *getthis(t)
-}
-
-func getoutargx(t *Type) *Type {
- return *Getoutarg(t)
+func (t *Type) ResultsP() **Type {
+ t.wantEtype(TFUNC)
+ return &t.Type.Down
}
-func getinargx(t *Type) *Type {
- return *getinarg(t)
-}
+func (t *Type) Recv() *Type { return *t.RecvP() }
+func (t *Type) Params() *Type { return *t.ParamsP() }
+func (t *Type) Results() *Type { return *t.ResultsP() }
func (t *Type) Size() int64 {
dowidth(t)
fallthrough
case TINTER:
- t1 := t.Type
- x1 := x.Type
- for ; t1 != nil && x1 != nil; t1, x1 = t1.Down, x1.Down {
+ t1, ti := IterFields(t)
+ x1, xi := IterFields(x)
+ for ; t1 != nil && x1 != nil; t1, x1 = ti.Next(), xi.Next() {
if t1.Embedded != x1.Embedded {
- if t1.Embedded < x1.Embedded {
- return ssa.CMPlt
- }
- return ssa.CMPgt
+ return cmpForNe(t1.Embedded < x1.Embedded)
}
if t1.Note != x1.Note {
if t1.Note == nil {
return ssa.CMPgt
}
if *t1.Note != *x1.Note {
- if *t1.Note < *x1.Note {
- return ssa.CMPlt
- }
- return ssa.CMPgt
+ return cmpForNe(*t1.Note < *x1.Note)
}
}
- c := t1.Sym.cmpsym(x1.Sym)
- if c != ssa.CMPeq {
+ if c := t1.Sym.cmpsym(x1.Sym); c != ssa.CMPeq {
return c
}
- c = t1.Type.cmp(x1.Type)
- if c != ssa.CMPeq {
+ if c := t1.Type.cmp(x1.Type); c != ssa.CMPeq {
return c
}
}
- if t1 == x1 {
- return ssa.CMPeq
+ if t1 != x1 {
+ return cmpForNe(t1 == nil)
}
- if t1 == nil {
- return ssa.CMPlt
- }
- return ssa.CMPgt
+ return ssa.CMPeq
case TFUNC:
- t1 := t.Type
- t2 := x.Type
- for ; t1 != nil && t2 != nil; t1, t2 = t1.Down, t2.Down {
+ for _, f := range [...]func(*Type) *Type{(*Type).Recv, (*Type).Results, (*Type).Params} {
// Loop over fields in structs, ignoring argument names.
- ta := t1.Type
- tb := t2.Type
- for ; ta != nil && tb != nil; ta, tb = ta.Down, tb.Down {
+ ta, ia := IterFields(f(t))
+ tb, ib := IterFields(f(x))
+ for ; ta != nil && tb != nil; ta, tb = ia.Next(), ib.Next() {
if ta.Isddd != tb.Isddd {
- if ta.Isddd {
- return ssa.CMPgt
- }
- return ssa.CMPlt
+ return cmpForNe(!ta.Isddd)
}
- c := ta.Type.cmp(tb.Type)
- if c != ssa.CMPeq {
+ if c := ta.Type.cmp(tb.Type); c != ssa.CMPeq {
return c
}
}
-
if ta != tb {
- if t1 == nil {
- return ssa.CMPlt
- }
- return ssa.CMPgt
- }
- }
- if t1 != t2 {
- if t1 == nil {
- return ssa.CMPlt
+ return cmpForNe(ta == nil)
}
- return ssa.CMPgt
}
return ssa.CMPeq
// information further down the call chain to know if we
// were testing a method receiver for unexported fields.
// It isn't necessary, so just do a sanity check.
- tp := getthisx(t).Type.Type
+ tp := t.Recv().Type.Type
if l.Left == nil || !Eqtype(l.Left.Type, tp) {
Fatalf("method receiver")
}
}
- typecheckaste(OCALL, n.Left, n.Isddd, getinargx(t), n.List, func() string { return fmt.Sprintf("argument to %v", n.Left) })
+ typecheckaste(OCALL, n.Left, n.Isddd, t.Params(), n.List, func() string { return fmt.Sprintf("argument to %v", n.Left) })
ok |= Etop
if t.Outtuple == 0 {
break OpSwitch
}
ok |= Erv
if t.Outtuple == 1 {
- t := getoutargx(l.Type).Type
+ t := l.Type.Results().Type
if t == nil {
n.Type = nil
return
break OpSwitch
}
- n.Type = getoutargx(l.Type)
+ n.Type = l.Type.Results()
break OpSwitch
if Curfn.Type.Outnamed && nodeSeqLen(n.List) == 0 {
break OpSwitch
}
- typecheckaste(ORETURN, nil, false, getoutargx(Curfn.Type), n.List, func() string { return "return argument" })
+ typecheckaste(ORETURN, nil, false, Curfn.Type.Results(), n.List, func() string { return "return argument" })
break OpSwitch
case ORETJMP:
}
// disallow T.m if m requires *T receiver
- if Isptr[getthisx(f2.Type).Type.Type.Etype] && !Isptr[t.Etype] && f2.Embedded != 2 && !isifacemethod(f2.Type) {
+ if Isptr[f2.Type.Recv().Type.Type.Etype] && !Isptr[t.Etype] && f2.Embedded != 2 && !isifacemethod(f2.Type) {
Yyerror("invalid method expression %v (needs pointer receiver: (*%v).%v)", n, t, Sconv(f2.Sym, obj.FmtShort))
return false
}
}
tt := n.Left.Type
dowidth(tt)
- rcvr := getthisx(f2.Type).Type.Type
+ rcvr := f2.Type.Recv().Type.Type
if !Eqtype(rcvr, tt) {
if rcvr.Etype == Tptr && Eqtype(rcvr.Type, tt) {
checklvalue(n.Left, "call pointer method on")
}
n.Type = t
t.Nname = n.Func.Nname
- rcvr := getthisx(t).Type
+ rcvr := t.Recv().Type
if rcvr != nil && n.Func.Shortname != nil {
addmethod(n.Func.Shortname.Sym, t, true, n.Func.Nname.Nointerface)
}
// value of its argument, a specific implementation of I may
// care. The _ would suppress the assignment to that argument
// while generating a call, so remove it.
- for t := getinargx(nt.Type).Type; t != nil; t = t.Down {
+ for t, it := IterFields(nt.Type.Params()); t != nil; t = it.Next() {
if t.Sym != nil && t.Sym.Name == "_" {
t.Sym = nil
}
break
}
- ll := ascompatte(n.Op, nil, false, Getoutarg(Curfn.Type), n.List.Slice(), 1, &n.Ninit)
+ ll := ascompatte(n.Op, nil, false, Curfn.Type.ResultsP(), n.List.Slice(), 1, &n.Ninit)
setNodeSeq(&n.List, ll)
case ORETJMP:
}
walkexpr(&n.Left, init)
walkexprlist(n.List.Slice(), init)
- ll := ascompatte(n.Op, n, n.Isddd, getinarg(t), n.List.Slice(), 0, init)
+ ll := ascompatte(n.Op, n, n.Isddd, t.ParamsP(), n.List.Slice(), 0, init)
setNodeSeq(&n.List, reorder1(ll))
case OCALLFUNC:
// Update type of OCALLFUNC node.
// Output arguments had not changed, but their offsets could.
if n.Left.Type.Outtuple == 1 {
- t := getoutargx(n.Left.Type).Type
+ t := n.Left.Type.Results().Type
if t.Etype == TFIELD {
t = t.Type
}
n.Type = t
} else {
- n.Type = getoutargx(n.Left.Type)
+ n.Type = n.Left.Type.Results()
}
}
}
}
- ll := ascompatte(n.Op, n, n.Isddd, getinarg(t), n.List.Slice(), 0, init)
+ ll := ascompatte(n.Op, n, n.Isddd, t.ParamsP(), n.List.Slice(), 0, init)
setNodeSeq(&n.List, reorder1(ll))
case OCALLMETH:
}
walkexpr(&n.Left, init)
walkexprlist(n.List.Slice(), init)
- ll := ascompatte(n.Op, n, false, getthis(t), []*Node{n.Left.Left}, 0, init)
- lr := ascompatte(n.Op, n, n.Isddd, getinarg(t), n.List.Slice(), 0, init)
+ ll := ascompatte(n.Op, n, false, t.RecvP(), []*Node{n.Left.Left}, 0, init)
+ lr := ascompatte(n.Op, n, n.Isddd, t.ParamsP(), n.List.Slice(), 0, init)
ll = append(ll, lr...)
n.Left.Left = nil
ullmancalc(n.Left)
a := nodeSeqFirst(n.List)
fn := mapfn(p, t)
- r = mkcall1(fn, getoutargx(fn.Type), init, typename(t), r.Left, key)
+ r = mkcall1(fn, fn.Type.Results(), init, typename(t), r.Left, key)
// mapaccess2* returns a typed bool, but due to spec changes,
// the boolean result of i.(T) is now untyped so we make it the
continue
}
- t = getinargx(on.Type)
+ t = on.Type.Params()
if t != nil {
t = t.Type
}
func heapmoves() {
lno := lineno
lineno = Curfn.Lineno
- nn := paramstoheap(getthis(Curfn.Type), 0)
- nn = append(nn, paramstoheap(getinarg(Curfn.Type), 0)...)
- nn = append(nn, paramstoheap(Getoutarg(Curfn.Type), 1)...)
+ nn := paramstoheap(Curfn.Type.RecvP(), 0)
+ nn = append(nn, paramstoheap(Curfn.Type.ParamsP(), 0)...)
+ nn = append(nn, paramstoheap(Curfn.Type.ResultsP(), 1)...)
Curfn.Func.Enter.Append(nn...)
lineno = Curfn.Func.Endlineno
- Curfn.Func.Exit.Append(returnsfromheap(Getoutarg(Curfn.Type))...)
+ Curfn.Func.Exit.Append(returnsfromheap(Curfn.Type.ResultsP())...)
lineno = lno
}