This change does a bulk rename of several identifiers in the compiler.
See #27167 and https://docs.google.com/document/d/19_ExiylD9MRfeAjKIfEsMU1_RGhuxB9sA0b5Zv7byVI/
for context and for discussion of these particular renames.
Commands run to generate this change:
gorename -from '"cmd/compile/internal/gc".OPROC' -to OGO
gorename -from '"cmd/compile/internal/gc".OCOM' -to OBITNOT
gorename -from '"cmd/compile/internal/gc".OMINUS' -to ONEG
gorename -from '"cmd/compile/internal/gc".OIND' -to ODEREF
gorename -from '"cmd/compile/internal/gc".OARRAYBYTESTR' -to OBYTES2STR
gorename -from '"cmd/compile/internal/gc".OARRAYBYTESTRTMP' -to OBYTES2STRTMP
gorename -from '"cmd/compile/internal/gc".OARRAYRUNESTR' -to ORUNES2STR
gorename -from '"cmd/compile/internal/gc".OSTRARRAYBYTE' -to OSTR2BYTES
gorename -from '"cmd/compile/internal/gc".OSTRARRAYBYTETMP' -to OSTR2BYTESTMP
gorename -from '"cmd/compile/internal/gc".OSTRARRAYRUNE' -to OSTR2RUNES
gorename -from '"cmd/compile/internal/gc".Etop' -to ctxStmt
gorename -from '"cmd/compile/internal/gc".Erv' -to ctxExpr
gorename -from '"cmd/compile/internal/gc".Ecall' -to ctxCallee
gorename -from '"cmd/compile/internal/gc".Efnstruct' -to ctxMultiOK
gorename -from '"cmd/compile/internal/gc".Easgn' -to ctxAssign
gorename -from '"cmd/compile/internal/gc".Ecomplit' -to ctxCompLit
Not altered: parameters and local variables (mostly in typecheck.go) named top,
which should probably now be called ctx (and which should probably have a named type).
Also not altered: Field called Top in gc.Func.
gorename -from '"cmd/compile/internal/gc".Node.Isddd' -to IsDDD
gorename -from '"cmd/compile/internal/gc".Node.SetIsddd' -to SetIsDDD
gorename -from '"cmd/compile/internal/gc".nodeIsddd' -to nodeIsDDD
gorename -from '"cmd/compile/internal/types".Field.Isddd' -to IsDDD
gorename -from '"cmd/compile/internal/types".Field.SetIsddd' -to SetIsDDD
gorename -from '"cmd/compile/internal/types".fieldIsddd' -to fieldIsDDD
Not altered: function gc.hasddd, params and local variables called isddd
Also not altered: fmt.go prints nodes using "isddd(%v)".
cd cmd/compile/internal/gc; go generate
I then manually found impacted comments using exact string match
and fixed them up by hand. The comment changes were trivial.
Passes toolstash-check.
Fixes #27167. If this experiment is deemed a success,
we will open a new tracking issue for renames to do
at the end of the 1.13 cycles.
Change-Id: I2dc541533d2ab0d06cb3d31d65df205ecfb151e8
Reviewed-on: https://go-review.googlesource.com/c/150140
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
// pure memory.
hashel := hashfor(t.Elem())
- n := nod(ORANGE, nil, nod(OIND, np, nil))
+ n := nod(ORANGE, nil, nod(ODEREF, np, nil))
ni := newname(lookup("i"))
ni.Type = types.Types[TINT]
n.List.Set1(ni)
funcbody()
fn.Func.SetDupok(true)
- fn = typecheck(fn, Etop)
+ fn = typecheck(fn, ctxStmt)
Curfn = fn
- typecheckslice(fn.Nbody.Slice(), Etop)
+ typecheckslice(fn.Nbody.Slice(), ctxStmt)
Curfn = nil
if debug_dclstack != 0 {
// pure memory. Even if we unrolled the range loop,
// each iteration would be a function call, so don't bother
// unrolling.
- nrange := nod(ORANGE, nil, nod(OIND, np, nil))
+ nrange := nod(ORANGE, nil, nod(ODEREF, np, nil))
ni := newname(lookup("i"))
ni.Type = types.Types[TINT]
funcbody()
fn.Func.SetDupok(true)
- fn = typecheck(fn, Etop)
+ fn = typecheck(fn, ctxStmt)
Curfn = fn
- typecheckslice(fn.Nbody.Slice(), Etop)
+ typecheckslice(fn.Nbody.Slice(), ctxStmt)
Curfn = nil
if debug_dclstack != 0 {
func eqmem(p *Node, q *Node, field *types.Sym, size int64) *Node {
nx := nod(OADDR, nodSym(OXDOT, p, field), nil)
ny := nod(OADDR, nodSym(OXDOT, q, field), nil)
- nx = typecheck(nx, Erv)
- ny = typecheck(ny, Erv)
+ nx = typecheck(nx, ctxExpr)
+ ny = typecheck(ny, ctxExpr)
fn, needsize := eqmemfunc(size, nx.Type.Elem())
call := nod(OCALL, fn, nil)
xfunc.Func.Nname.Sym = closurename(Curfn)
disableExport(xfunc.Func.Nname.Sym)
declare(xfunc.Func.Nname, PFUNC)
- xfunc = typecheck(xfunc, Etop)
+ xfunc = typecheck(xfunc, ctxStmt)
clo.Func.Ntype = typecheck(clo.Func.Ntype, Etype)
clo.Type = clo.Func.Ntype.Type
Curfn = xfunc
olddd := decldepth
decldepth = 1
- typecheckslice(xfunc.Nbody.Slice(), Etop)
+ typecheckslice(xfunc.Nbody.Slice(), ctxStmt)
decldepth = olddd
Curfn = oldfn
}
Warnl(v.Pos, "%v capturing by %s: %v (addr=%v assign=%v width=%d)", name, how, v.Sym, outermost.Addrtaken(), outermost.Assigned(), int32(v.Type.Width))
}
- outer = typecheck(outer, Erv)
+ outer = typecheck(outer, ctxExpr)
clo.Func.Enter.Append(outer)
}
lineno = xfunc.Pos
clo := xfunc.Func.Closure
- if clo.Func.Top&Ecall != 0 {
+ if clo.Func.Top&ctxCallee != 0 {
// If the closure is directly called, we transform it to a plain function call
// with variables passed as args. This avoids allocation of a closure object.
// Here we do only a part of the transformation. Walk of OCALLFUNC(OCLOSURE)
}
if len(body) > 0 {
- typecheckslice(body, Etop)
+ typecheckslice(body, ctxStmt)
xfunc.Func.Enter.Set(body)
xfunc.Func.SetNeedctxt(true)
}
typ := closureType(clo)
- clos := nod(OCOMPLIT, nil, nod(OIND, typenod(typ), nil))
+ clos := nod(OCOMPLIT, nil, nod(ODEREF, typenod(typ), nil))
clos.Esc = clo.Esc
clos.Right.SetImplicit(true)
clos.List.Set(append([]*Node{nod(OCFUNC, xfunc.Func.Nname, nil)}, clo.Func.Enter.Slice()...))
call := nod(OCALL, nodSym(OXDOT, ptr, meth), nil)
call.List.Set(paramNnames(tfn.Type))
- call.SetIsddd(tfn.Type.IsVariadic())
+ call.SetIsDDD(tfn.Type.IsVariadic())
if t0.NumResults() != 0 {
n := nod(ORETURN, nil, nil)
n.List.Set1(call)
xfunc.Nbody.Set(body)
funcbody()
- xfunc = typecheck(xfunc, Etop)
+ xfunc = typecheck(xfunc, ctxStmt)
sym.Def = asTypesNode(xfunc)
xtop = append(xtop, xfunc)
Curfn = savecurfn
typ := partialCallType(n)
- clos := nod(OCOMPLIT, nil, nod(OIND, typenod(typ), nil))
+ clos := nod(OCOMPLIT, nil, nod(ODEREF, typenod(typ), nil))
clos.Esc = n.Esc
clos.Right.SetImplicit(true)
clos.List.Set2(nod(OCFUNC, n.Func.Nname, nil), n.Left)
// Pick off just the opcodes that can be constant evaluated.
switch op := n.Op; op {
- case OPLUS, OMINUS, OCOM, ONOT:
+ case OPLUS, ONEG, OBITNOT, ONOT:
if nl.Op == OLITERAL {
setconst(n, unaryOp(op, nl.Val(), n.Type))
}
setconst(n, convlit1(nl, n.Type, true, false).Val())
}
- case OARRAYBYTESTR:
+ case OBYTES2STR:
// string([]byte(nil)) or string([]rune(nil))
if nl.Op == OLITERAL && nl.Val().Ctype() == CTNIL {
setconst(n, Val{U: ""})
return x
}
- case OMINUS:
+ case ONEG:
switch x.Ctype() {
case CTINT, CTRUNE:
x := x.U.(*Mpint)
return Val{U: u}
}
- case OCOM:
+ case OBITNOT:
x := x.U.(*Mpint)
u := new(Mpint)
case OADD,
OAND,
OANDNOT,
- OCOM,
+ OBITNOT,
ODIV,
- OMINUS,
+ ONEG,
OMOD,
OMUL,
OSUB,
OAND,
OANDAND,
OANDNOT,
- OCOM,
+ OBITNOT,
ODIV,
OEQ,
OGE,
OLE,
OLSH,
OLT,
- OMINUS,
+ ONEG,
OMOD,
OMUL,
ONE,
c = newname(s)
c.SetClass(PAUTOHEAP)
c.SetIsClosureVar(true)
- c.SetIsddd(n.Isddd())
+ c.SetIsDDD(n.IsDDD())
c.Name.Defn = n
c.SetAddable(false)
n.Right = newnamel(n.Pos, n.Sym)
n.Right.Name.Param.Ntype = n.Left
- n.Right.SetIsddd(n.Isddd())
+ n.Right.SetIsDDD(n.IsDDD())
declare(n.Right, ctxt)
vargen++
n := newnamel(f.Pos, f.Sym)
f.Nname = asTypesNode(n)
n.Type = f.Type
- n.SetIsddd(f.Isddd())
+ n.SetIsDDD(f.IsDDD())
declare(n, ctxt)
}
fields := make([]*types.Field, len(l))
for i, n := range l {
f := structfield(n)
- f.SetIsddd(n.Isddd())
+ f.SetIsDDD(n.IsDDD())
if n.Right != nil {
n.Right.Type = f.Type
f.Nname = asTypesNode(n.Right)
// when we evaluate it for dst and for src.
// dst is ONAME dereference.
- if dst.Op != OIND && dst.Op != ODOTPTR || dst.Left.Op != ONAME {
+ if dst.Op != ODEREF && dst.Op != ODOTPTR || dst.Left.Op != ONAME {
return false
}
// src is a slice operation.
return false
}
// slice is applied to ONAME dereference.
- if src.Left.Op != OIND && src.Left.Op != ODOTPTR || src.Left.Left.Op != ONAME {
+ if src.Left.Op != ODEREF && src.Left.Op != ODOTPTR || src.Left.Left.Op != ONAME {
return false
}
// dst and src reference the same base ONAME.
return e.mayAffectMemory(n.Left) || e.mayAffectMemory(n.Right)
// Left group.
- case ODOT, ODOTPTR, OIND, OCONVNOP, OCONV, OLEN, OCAP,
- ONOT, OCOM, OPLUS, OMINUS, OALIGNOF, OOFFSETOF, OSIZEOF:
+ case ODOT, ODOTPTR, ODEREF, OCONVNOP, OCONV, OLEN, OCAP,
+ ONOT, OBITNOT, OPLUS, ONEG, OALIGNOF, OOFFSETOF, OSIZEOF:
return e.mayAffectMemory(n.Left)
default:
e.escassignSinkWhy(n, arg, "defer func arg")
}
- case OPROC:
+ case OGO:
// go f(x) - f and x escape
e.escassignSinkWhy(n, n.Left.Left, "go func")
e.escassignSinkWhy(n, n.Left.Right, "go func ...") // ODDDARG for call
e.escassignSinkWhy(n, n.Left, "panic")
case OAPPEND:
- if !n.Isddd() {
+ if !n.IsDDD() {
for _, nn := range n.List.Slice()[1:] {
e.escassignSinkWhy(n, nn, "appended to slice") // lose track of assign to dereference
}
a = nod(OADDR, a, nil)
a.Pos = v.Pos
e.nodeEscState(a).Loopdepth = e.loopdepth
- a = typecheck(a, Erv)
+ a = typecheck(a, ctxExpr)
}
e.escassignWhyWhere(n, a, "captured by a closure", n)
OMAKEMAP,
OMAKESLICE,
ONEW,
- OARRAYRUNESTR,
- OARRAYBYTESTR,
- OSTRARRAYRUNE,
- OSTRARRAYBYTE,
+ ORUNES2STR,
+ OBYTES2STR,
+ OSTR2RUNES,
+ OSTR2BYTES,
ORUNESTR:
e.track(n)
dstwhy = "slice-element-equals"
dst = &e.theSink // lose track of dereference
- case OIND:
+ case ODEREF:
dstwhy = "star-equals"
dst = &e.theSink // lose track of dereference
switch src.Op {
case OADDR, // dst = &x
- OIND, // dst = *x
+ ODEREF, // dst = *x
ODOTPTR, // dst = (*x).f
ONAME,
ODDDARG,
OMAKECHAN,
OMAKEMAP,
OMAKESLICE,
- OARRAYRUNESTR,
- OARRAYBYTESTR,
- OSTRARRAYRUNE,
- OSTRARRAYBYTE,
+ ORUNES2STR,
+ OBYTES2STR,
+ OSTR2RUNES,
+ OSTR2BYTES,
OADDSTR,
ONEW,
OCALLPART,
case OCONV,
OCONVNOP,
ODOTMETH,
- // treat recv.meth as a value with recv in it, only happens in ODEFER and OPROC
+ // treat recv.meth as a value with recv in it, only happens in ODEFER and OGO
// iface.method already leaks iface in esccall, no need to put in extra ODOTINTER edge here
OSLICE,
OSLICE3,
OAND,
OANDNOT,
OPLUS,
- OMINUS,
- OCOM:
+ ONEG,
+ OBITNOT:
e.escassign(dst, src.Left, e.stepAssign(step, originalDst, src, dstwhy))
e.escassign(dst, src.Right, e.stepAssign(step, originalDst, src, dstwhy))
e.escassign(dst, e.addDereference(src), step)
}
-// addDereference constructs a suitable OIND note applied to src.
+// addDereference constructs a suitable ODEREF note applied to src.
// Because this is for purposes of escape accounting, not execution,
// some semantically dubious node combinations are (currently) possible.
func (e *EscState) addDereference(n *Node) *Node {
- ind := nod(OIND, n, nil)
+ ind := nod(ODEREF, n, nil)
e.nodeEscState(ind).Loopdepth = e.nodeEscState(n).Loopdepth
ind.Pos = n.Pos
t := n.Type
if t.IsPtr() || t.IsSlice() {
- // This should model our own sloppy use of OIND to encode
+ // This should model our own sloppy use of ODEREF to encode
// decreasing levels of indirection; i.e., "indirecting" a slice
// yields the type of an element.
t = t.Elem()
continue
}
arg := args[0]
- if n.Isddd() && !call.Isddd() {
+ if n.IsDDD() && !call.IsDDD() {
// Introduce ODDDARG node to represent ... allocation.
arg = nod(ODDDARG, nil, nil)
arr := types.NewArray(n.Type.Elem(), int64(len(args)))
for i, param := range fntype.Params().FieldSlice() {
note := param.Note
var arg *Node
- if param.Isddd() && !call.Isddd() {
+ if param.IsDDD() && !call.IsDDD() {
rest := args[i:]
if len(rest) == 0 {
break
}
}
- if types.Haspointers(param.Type) && e.escassignfromtag(note, cE.Retval, arg, call)&EscMask == EscNone && parent.Op != ODEFER && parent.Op != OPROC {
+ if types.Haspointers(param.Type) && e.escassignfromtag(note, cE.Retval, arg, call)&EscMask == EscNone && parent.Op != ODEFER && parent.Op != OGO {
a := arg
for a.Op == OCONVNOP {
a = a.Left
case OMAKECHAN,
OMAKEMAP,
OMAKESLICE,
- OARRAYRUNESTR,
- OARRAYBYTESTR,
- OSTRARRAYRUNE,
- OSTRARRAYBYTE,
+ ORUNES2STR,
+ OBYTES2STR,
+ OSTR2RUNES,
+ OSTR2BYTES,
OADDSTR,
OMAPLIT,
ONEW,
e.escwalk(level.inc(), dst, src.Left, e.stepWalk(dst, src.Left, "dot of pointer", step))
case OINDEXMAP:
e.escwalk(level.inc(), dst, src.Left, e.stepWalk(dst, src.Left, "map index", step))
- case OIND:
+ case ODEREF:
e.escwalk(level.inc(), dst, src.Left, e.stepWalk(dst, src.Left, "indirection", step))
// In this case a link went directly to a call, but should really go
default:
// Unexpected Op, probably due to a previous type error. Ignore.
- case OIND, ODOTPTR:
+ case ODEREF, ODOTPTR:
// Nothing to do.
case ONAME:
f.Note = uintptrEscapesTag
}
- if f.Isddd() && f.Type.Elem().Etype == TUINTPTR {
+ if f.IsDDD() && f.Type.Elem().Etype == TUINTPTR {
// final argument is ...uintptr.
if Debug['m'] != 0 {
Warnl(fn.Pos, "%v marking %v as escaping ...uintptr", funcSym(fn), name(f.Sym, narg))
OCASE: "case",
OCLOSE: "close",
OCOMPLEX: "complex",
- OCOM: "^",
+ OBITNOT: "^",
OCONTINUE: "continue",
OCOPY: "copy",
ODELETE: "delete",
OGT: ">",
OIF: "if",
OIMAG: "imag",
- OIND: "*",
+ ODEREF: "*",
OLEN: "len",
OLE: "<=",
OLSH: "<<",
OLT: "<",
OMAKE: "make",
- OMINUS: "-",
+ ONEG: "-",
OMOD: "%",
OMUL: "*",
ONEW: "new",
fmt.Fprintf(s, " tc(%d)", n.Typecheck())
}
- if n.Isddd() {
- fmt.Fprintf(s, " isddd(%v)", n.Isddd())
+ if n.IsDDD() {
+ fmt.Fprintf(s, " isddd(%v)", n.IsDDD())
}
if n.Implicit() {
case ORETJMP:
mode.Fprintf(s, "retjmp %v", n.Sym)
- case OPROC:
+ case OGO:
mode.Fprintf(s, "go %v", n.Left)
case ODEFER:
}
var opprec = []int{
- OALIGNOF: 8,
- OAPPEND: 8,
- OARRAYBYTESTR: 8,
- OARRAYLIT: 8,
- OSLICELIT: 8,
- OARRAYRUNESTR: 8,
- OCALLFUNC: 8,
- OCALLINTER: 8,
- OCALLMETH: 8,
- OCALL: 8,
- OCAP: 8,
- OCLOSE: 8,
- OCONVIFACE: 8,
- OCONVNOP: 8,
- OCONV: 8,
- OCOPY: 8,
- ODELETE: 8,
- OGETG: 8,
- OLEN: 8,
- OLITERAL: 8,
- OMAKESLICE: 8,
- OMAKE: 8,
- OMAPLIT: 8,
- ONAME: 8,
- ONEW: 8,
- ONONAME: 8,
- OOFFSETOF: 8,
- OPACK: 8,
- OPANIC: 8,
- OPAREN: 8,
- OPRINTN: 8,
- OPRINT: 8,
- ORUNESTR: 8,
- OSIZEOF: 8,
- OSTRARRAYBYTE: 8,
- OSTRARRAYRUNE: 8,
- OSTRUCTLIT: 8,
- OTARRAY: 8,
- OTCHAN: 8,
- OTFUNC: 8,
- OTINTER: 8,
- OTMAP: 8,
- OTSTRUCT: 8,
- OINDEXMAP: 8,
- OINDEX: 8,
- OSLICE: 8,
- OSLICESTR: 8,
- OSLICEARR: 8,
- OSLICE3: 8,
- OSLICE3ARR: 8,
- OSLICEHEADER: 8,
- ODOTINTER: 8,
- ODOTMETH: 8,
- ODOTPTR: 8,
- ODOTTYPE2: 8,
- ODOTTYPE: 8,
- ODOT: 8,
- OXDOT: 8,
- OCALLPART: 8,
- OPLUS: 7,
- ONOT: 7,
- OCOM: 7,
- OMINUS: 7,
- OADDR: 7,
- OIND: 7,
- ORECV: 7,
- OMUL: 6,
- ODIV: 6,
- OMOD: 6,
- OLSH: 6,
- ORSH: 6,
- OAND: 6,
- OANDNOT: 6,
- OADD: 5,
- OSUB: 5,
- OOR: 5,
- OXOR: 5,
- OEQ: 4,
- OLT: 4,
- OLE: 4,
- OGE: 4,
- OGT: 4,
- ONE: 4,
- OSEND: 3,
- OANDAND: 2,
- OOROR: 1,
+ OALIGNOF: 8,
+ OAPPEND: 8,
+ OBYTES2STR: 8,
+ OARRAYLIT: 8,
+ OSLICELIT: 8,
+ ORUNES2STR: 8,
+ OCALLFUNC: 8,
+ OCALLINTER: 8,
+ OCALLMETH: 8,
+ OCALL: 8,
+ OCAP: 8,
+ OCLOSE: 8,
+ OCONVIFACE: 8,
+ OCONVNOP: 8,
+ OCONV: 8,
+ OCOPY: 8,
+ ODELETE: 8,
+ OGETG: 8,
+ OLEN: 8,
+ OLITERAL: 8,
+ OMAKESLICE: 8,
+ OMAKE: 8,
+ OMAPLIT: 8,
+ ONAME: 8,
+ ONEW: 8,
+ ONONAME: 8,
+ OOFFSETOF: 8,
+ OPACK: 8,
+ OPANIC: 8,
+ OPAREN: 8,
+ OPRINTN: 8,
+ OPRINT: 8,
+ ORUNESTR: 8,
+ OSIZEOF: 8,
+ OSTR2BYTES: 8,
+ OSTR2RUNES: 8,
+ OSTRUCTLIT: 8,
+ OTARRAY: 8,
+ OTCHAN: 8,
+ OTFUNC: 8,
+ OTINTER: 8,
+ OTMAP: 8,
+ OTSTRUCT: 8,
+ OINDEXMAP: 8,
+ OINDEX: 8,
+ OSLICE: 8,
+ OSLICESTR: 8,
+ OSLICEARR: 8,
+ OSLICE3: 8,
+ OSLICE3ARR: 8,
+ OSLICEHEADER: 8,
+ ODOTINTER: 8,
+ ODOTMETH: 8,
+ ODOTPTR: 8,
+ ODOTTYPE2: 8,
+ ODOTTYPE: 8,
+ ODOT: 8,
+ OXDOT: 8,
+ OCALLPART: 8,
+ OPLUS: 7,
+ ONOT: 7,
+ OBITNOT: 7,
+ ONEG: 7,
+ OADDR: 7,
+ ODEREF: 7,
+ ORECV: 7,
+ OMUL: 6,
+ ODIV: 6,
+ OMOD: 6,
+ OLSH: 6,
+ ORSH: 6,
+ OAND: 6,
+ OANDNOT: 6,
+ OADD: 5,
+ OSUB: 5,
+ OOR: 5,
+ OXOR: 5,
+ OEQ: 4,
+ OLT: 4,
+ OLE: 4,
+ OGE: 4,
+ OGT: 4,
+ ONE: 4,
+ OSEND: 3,
+ OANDAND: 2,
+ OOROR: 1,
// Statements handled by stmtfmt
OAS: -1,
OGOTO: -1,
OIF: -1,
OLABEL: -1,
- OPROC: -1,
+ OGO: -1,
ORANGE: -1,
ORETURN: -1,
OSELECT: -1,
}
func (n *Node) exprfmt(s fmt.State, prec int, mode fmtMode) {
- for n != nil && n.Implicit() && (n.Op == OIND || n.Op == OADDR) {
+ for n != nil && n.Implicit() && (n.Op == ODEREF || n.Op == OADDR) {
n = n.Left
}
case OCONV,
OCONVIFACE,
OCONVNOP,
- OARRAYBYTESTR,
- OARRAYRUNESTR,
- OSTRARRAYBYTE,
- OSTRARRAYRUNE,
+ OBYTES2STR,
+ ORUNES2STR,
+ OSTR2BYTES,
+ OSTR2RUNES,
ORUNESTR:
if n.Type == nil || n.Type.Sym == nil {
mode.Fprintf(s, "(%v)", n.Type)
mode.Fprintf(s, "%#v(%v)", n.Op, n.Left)
return
}
- if n.Isddd() {
+ if n.IsDDD() {
mode.Fprintf(s, "%#v(%.v...)", n.Op, n.List)
return
}
case OCALL, OCALLFUNC, OCALLINTER, OCALLMETH, OGETG:
n.Left.exprfmt(s, nprec, mode)
- if n.Isddd() {
+ if n.IsDDD() {
mode.Fprintf(s, "(%.v...)", n.List)
return
}
}
mode.Fprintf(s, "make(%v)", n.Type)
- case OPLUS, OMINUS, OADDR, OCOM, OIND, ONOT, ORECV:
+ case OPLUS, ONEG, OADDR, OBITNOT, ODEREF, ONOT, ORECV:
// Unary
mode.Fprintf(s, "%#v", n.Op)
if n.Left != nil && n.Left.Op == n.Op {
}
var typ string
- if f.Isddd() {
+ if f.IsDDD() {
var et *types.Type
if f.Type != nil {
et = f.Type.Elem()
case OLITERAL:
// Constant.
- n = typecheck(n, Erv)
+ n = typecheck(n, ctxExpr)
w.tag('C')
w.pos(n.Pos)
w.value(n.Type, n.Val())
w.paramList(t.Params().FieldSlice())
w.paramList(t.Results().FieldSlice())
if n := t.Params().NumFields(); n > 0 {
- w.bool(t.Params().Field(n - 1).Isddd())
+ w.bool(t.Params().Field(n - 1).IsDDD())
}
}
// case ORETJMP:
// unreachable - generated by compiler for trampolin routines
- case OPROC, ODEFER:
+ case OGO, ODEFER:
w.op(op)
w.pos(n.Pos)
w.expr(n.Left)
// }
// from exprfmt (fmt.go)
- for n.Op == OPAREN || n.Implicit() && (n.Op == OIND || n.Op == OADDR || n.Op == ODOT || n.Op == ODOTPTR) {
+ for n.Op == OPAREN || n.Implicit() && (n.Op == ODEREF || n.Op == OADDR || n.Op == ODOT || n.Op == ODOTPTR) {
n = n.Left
}
w.expr(n.Right)
w.op(OEND)
- case OCONV, OCONVIFACE, OCONVNOP, OARRAYBYTESTR, OARRAYRUNESTR, OSTRARRAYBYTE, OSTRARRAYRUNE, ORUNESTR:
+ case OCONV, OCONVIFACE, OCONVNOP, OBYTES2STR, ORUNES2STR, OSTR2BYTES, OSTR2RUNES, ORUNESTR:
w.op(OCONV)
w.pos(n.Pos)
w.expr(n.Left)
}
// only append() calls may contain '...' arguments
if op == OAPPEND {
- w.bool(n.Isddd())
- } else if n.Isddd() {
+ w.bool(n.IsDDD())
+ } else if n.IsDDD() {
Fatalf("exporter: unexpected '...' with %v call", op)
}
w.pos(n.Pos)
w.expr(n.Left)
w.exprList(n.List)
- w.bool(n.Isddd())
+ w.bool(n.IsDDD())
case OMAKEMAP, OMAKECHAN, OMAKESLICE:
w.op(op) // must keep separate from OMAKE for importer
}
// unary expressions
- case OPLUS, OMINUS, OADDR, OCOM, OIND, ONOT, ORECV:
+ case OPLUS, ONEG, OADDR, OBITNOT, ODEREF, ONOT, ORECV:
w.op(op)
w.pos(n.Pos)
w.expr(n.Left)
params := r.paramList()
results := r.paramList()
if n := len(params); n > 0 {
- params[n-1].SetIsddd(r.bool())
+ params[n-1].SetIsDDD(r.bool())
}
t := functypefield(recv, params, results)
t.SetPkg(r.currPkg)
if !r.bool() /* !implicit, i.e. '&' operator */ {
if n.Op == OCOMPLIT {
// Special case for &T{...}: turn into (*T){...}.
- n.Right = nodl(pos, OIND, n.Right, nil)
+ n.Right = nodl(pos, ODEREF, n.Right, nil)
n.Right.SetImplicit(true)
} else {
n = nodl(pos, OADDR, n, nil)
n.SetSliceBounds(low, high, max)
return n
- // case OCONV, OCONVIFACE, OCONVNOP, OARRAYBYTESTR, OARRAYRUNESTR, OSTRARRAYBYTE, OSTRARRAYRUNE, ORUNESTR:
+ // case OCONV, OCONVIFACE, OCONVNOP, OBYTES2STR, ORUNES2STR, OSTR2BYTES, OSTR2RUNES, ORUNESTR:
// unreachable - mapped to OCONV case below by exporter
case OCONV:
n := npos(r.pos(), builtinCall(op))
n.List.Set(r.exprList())
if op == OAPPEND {
- n.SetIsddd(r.bool())
+ n.SetIsDDD(r.bool())
}
return n
case OCALL:
n := nodl(r.pos(), OCALL, r.expr(), nil)
n.List.Set(r.exprList())
- n.SetIsddd(r.bool())
+ n.SetIsDDD(r.bool())
return n
case OMAKEMAP, OMAKECHAN, OMAKESLICE:
return n
// unary expressions
- case OPLUS, OMINUS, OADDR, OCOM, OIND, ONOT, ORECV:
+ case OPLUS, ONEG, OADDR, OBITNOT, ODEREF, ONOT, ORECV:
return nodl(r.pos(), op, r.expr(), nil)
// binary expressions
// case ORETJMP:
// unreachable - generated by compiler for trampolin routines (not exported)
- case OPROC, ODEFER:
+ case OGO, ODEFER:
return nodl(r.pos(), op, r.expr(), nil)
case OIF:
rhs := asNode(s.Def)
rhs.checkInitFuncSignature()
as := nod(OAS, lhs, rhs)
- as = typecheck(as, Etop)
+ as = typecheck(as, ctxStmt)
genAsStatic(as)
}
loop.Nbody.Set1(body)
loop.Ninit.Set1(zero)
- loop = typecheck(loop, Etop)
+ loop = typecheck(loop, ctxStmt)
r = append(r, loop)
}
funcbody()
Curfn = fn
- fn = typecheck(fn, Etop)
- typecheckslice(r, Etop)
+ fn = typecheck(fn, ctxStmt)
+ typecheckslice(r, ctxStmt)
Curfn = nil
funccompile(fn)
}
savefn := Curfn
Curfn = fn
- typecheckslice(fn.Func.Inl.Body, Etop)
+ typecheckslice(fn.Func.Inl.Body, ctxStmt)
Curfn = savefn
// During typechecking, declarations are added to
OFORUNTIL,
OSELECT,
OTYPESW,
- OPROC,
+ OGO,
ODEFER,
ODCLTYPE, // can't print yet
OBREAK,
switch n.Op {
// inhibit inlining of their argument
- case ODEFER, OPROC:
+ case ODEFER, OGO:
switch n.Left.Op {
case OCALLFUNC, OCALLMETH:
n.Left.SetNoInline(true)
n.Rlist.Set(inlconv2list(n.Rlist.First()))
n.Op = OAS2
n.SetTypecheck(0)
- n = typecheck(n, Etop)
+ n = typecheck(n, ctxStmt)
} else {
s := n.Rlist.Slice()
for i1, n1 := range s {
return inlvar
}
- return typecheck(nblank, Erv|Easgn)
+ return typecheck(nblank, ctxExpr|ctxAssign)
}
var inlgen int
}
if v.Name.Byval() {
- iv := typecheck(inlvar(v), Erv)
+ iv := typecheck(inlvar(v), ctxExpr)
ninit.Append(nod(ODCL, iv, nil))
- ninit.Append(typecheck(nod(OAS, iv, o), Etop))
+ ninit.Append(typecheck(nod(OAS, iv, o), ctxStmt))
inlvars[v] = iv
} else {
addr := newname(lookup("&" + v.Sym.Name))
addr.Type = types.NewPtr(v.Type)
- ia := typecheck(inlvar(addr), Erv)
+ ia := typecheck(inlvar(addr), ctxExpr)
ninit.Append(nod(ODCL, ia, nil))
- ninit.Append(typecheck(nod(OAS, ia, nod(OADDR, o, nil)), Etop))
+ ninit.Append(typecheck(nod(OAS, ia, nod(OADDR, o, nil)), ctxStmt))
inlvars[addr] = ia
// When capturing by reference, all occurrence of the captured var
// must be substituted with dereference of the temporary address
- inlvars[v] = typecheck(nod(OIND, ia, nil), Erv)
+ inlvars[v] = typecheck(nod(ODEREF, ia, nil), ctxExpr)
}
}
}
if ln.isParamStackCopy() { // ignore the on-stack copy of a parameter that moved to the heap
continue
}
- inlvars[ln] = typecheck(inlvar(ln), Erv)
+ inlvars[ln] = typecheck(inlvar(ln), ctxExpr)
if ln.Class() == PPARAM || ln.Name.Param.Stackcopy != nil && ln.Name.Param.Stackcopy.Class() == PPARAM {
ninit.Append(nod(ODCL, inlvars[ln], nil))
}
mpos := t.Pos
if n := asNode(t.Nname); n != nil && !n.isBlank() {
m = inlvar(n)
- m = typecheck(m, Erv)
+ m = typecheck(m, ctxExpr)
inlvars[n] = m
} else {
// anonymous return values, synthesize names for use in assignment that replaces return
Fatalf("method call without receiver: %+v", n)
}
ras := nod(OAS, tinlvar(rcv, inlvars), n.Left.Left)
- ras = typecheck(ras, Etop)
+ ras = typecheck(ras, ctxStmt)
ninit.Append(ras)
} else {
// For T.M(...), add the receiver parameter to
// For ordinary parameters or variadic parameters in
// dotted calls, just add the variable to the
// assignment list, and we're done.
- if !param.Isddd() || n.Isddd() {
+ if !param.IsDDD() || n.IsDDD() {
as.List.Append(tinlvar(param, inlvars))
continue
}
}
if as.Rlist.Len() != 0 {
- as = typecheck(as, Etop)
+ as = typecheck(as, ctxStmt)
ninit.Append(as)
}
if vas != nil {
- vas = typecheck(vas, Etop)
+ vas = typecheck(vas, ctxStmt)
ninit.Append(vas)
}
// Zero the return parameters.
for _, n := range retvars {
ras := nod(OAS, n, nil)
- ras = typecheck(ras, Etop)
+ ras = typecheck(ras, ctxStmt)
ninit.Append(ras)
}
lab := nodSym(OLABEL, nil, retlabel)
body = append(body, lab)
- typecheckslice(body, Etop)
+ typecheckslice(body, ctxStmt)
if genDwarfInline > 0 {
for _, v := range inlfvars {
as.List.Append(n)
}
as.Rlist.Set(subst.list(n.List))
- as = typecheck(as, Etop)
+ as = typecheck(as, ctxStmt)
m.Ninit.Append(as)
}
- typecheckslice(m.Ninit.Slice(), Etop)
- m = typecheck(m, Etop)
+ typecheckslice(m.Ninit.Slice(), ctxStmt)
+ m = typecheck(m, ctxStmt)
// dump("Return after substitution", m);
return m
for i := 0; i < len(xtop); i++ {
n := xtop[i]
if op := n.Op; op != ODCL && op != OAS && op != OAS2 && (op != ODCLTYPE || !n.Left.Name.Param.Alias) {
- xtop[i] = typecheck(n, Etop)
+ xtop[i] = typecheck(n, ctxStmt)
}
}
for i := 0; i < len(xtop); i++ {
n := xtop[i]
if op := n.Op; op == ODCL || op == OAS || op == OAS2 || op == ODCLTYPE && n.Left.Name.Param.Alias {
- xtop[i] = typecheck(n, Etop)
+ xtop[i] = typecheck(n, ctxStmt)
}
}
resumecheckwidth()
Curfn = n
decldepth = 1
saveerrors()
- typecheckslice(Curfn.Nbody.Slice(), Etop)
+ typecheckslice(Curfn.Nbody.Slice(), ctxStmt)
checkreturn(Curfn)
if nerrors != 0 {
Curfn.Nbody.Set(nil) // type errors; do not compile
timings.Start("be", "externaldcls")
for i, n := range externdcl {
if n.Op == ONAME {
- externdcl[i] = typecheck(externdcl[i], Erv)
+ externdcl[i] = typecheck(externdcl[i], ctxExpr)
}
}
// Check the map keys again, since we typechecked the external
typ.Op = OTARRAY
typ.Right = typ.Left
typ.Left = nil
- n.SetIsddd(true)
+ n.SetIsDDD(true)
if n.Left != nil {
- n.Left.SetIsddd(true)
+ n.Left.SetIsDDD(true)
}
}
x = unparen(x) // TODO(mdempsky): Needed?
if x.Op == OCOMPLIT {
// Special case for &T{...}: turn into (*T){...}.
- x.Right = p.nod(expr, OIND, x.Right, nil)
+ x.Right = p.nod(expr, ODEREF, x.Right, nil)
x.Right.SetImplicit(true)
return x
}
case *syntax.CallExpr:
n := p.nod(expr, OCALL, p.expr(expr.Fun), nil)
n.List.Set(p.exprs(expr.ArgList))
- n.SetIsddd(expr.HasDots)
+ n.SetIsDDD(expr.HasDots)
return n
case *syntax.ArrayType:
n.SetEmbedded(true)
if isStar {
- n.Left = p.nod(op, OIND, n.Left, nil)
+ n.Left = p.nod(op, ODEREF, n.Left, nil)
}
return n
}
case syntax.Defer:
op = ODEFER
case syntax.Go:
- op = OPROC
+ op = OGO
default:
panic("unhandled CallStmt")
}
var unOps = [...]Op{
syntax.Recv: ORECV,
- syntax.Mul: OIND,
+ syntax.Mul: ODEREF,
syntax.And: OADDR,
syntax.Not: ONOT,
- syntax.Xor: OCOM,
+ syntax.Xor: OBITNOT,
syntax.Add: OPLUS,
- syntax.Sub: OMINUS,
+ syntax.Sub: ONEG,
}
func (p *noder) unOp(op syntax.Operator) Op {
import "strconv"
-const _Op_name = "XXXNAMENONAMETYPEPACKLITERALADDSUBORXORADDSTRADDRANDANDAPPENDARRAYBYTESTRARRAYBYTESTRTMPARRAYRUNESTRSTRARRAYBYTESTRARRAYBYTETMPSTRARRAYRUNEASAS2AS2FUNCAS2RECVAS2MAPRAS2DOTTYPEASOPCALLCALLFUNCCALLMETHCALLINTERCALLPARTCAPCLOSECLOSURECOMPLITMAPLITSTRUCTLITARRAYLITSLICELITPTRLITCONVCONVIFACECONVNOPCOPYDCLDCLFUNCDCLFIELDDCLCONSTDCLTYPEDELETEDOTDOTPTRDOTMETHDOTINTERXDOTDOTTYPEDOTTYPE2EQNELTLEGEGTINDINDEXINDEXMAPKEYSTRUCTKEYLENMAKEMAKECHANMAKEMAPMAKESLICEMULDIVMODLSHRSHANDANDNOTNEWNOTCOMPLUSMINUSORORPANICPRINTPRINTNPARENSENDSLICESLICEARRSLICESTRSLICE3SLICE3ARRSLICEHEADERRECOVERRECVRUNESTRSELRECVSELRECV2IOTAREALIMAGCOMPLEXALIGNOFOFFSETOFSIZEOFBLOCKBREAKCASEXCASECONTINUEDEFEREMPTYFALLFORFORUNTILGOTOIFLABELPROCRANGERETURNSELECTSWITCHTYPESWTCHANTMAPTSTRUCTTINTERTFUNCTARRAYDDDDDDARGINLCALLEFACEITABIDATASPTRCLOSUREVARCFUNCCHECKNILVARDEFVARKILLVARLIVEINDREGSPRETJMPGETGEND"
+const _Op_name = "XXXNAMENONAMETYPEPACKLITERALADDSUBORXORADDSTRADDRANDANDAPPENDBYTES2STRBYTES2STRTMPRUNES2STRSTR2BYTESSTR2BYTESTMPSTR2RUNESASAS2AS2FUNCAS2RECVAS2MAPRAS2DOTTYPEASOPCALLCALLFUNCCALLMETHCALLINTERCALLPARTCAPCLOSECLOSURECOMPLITMAPLITSTRUCTLITARRAYLITSLICELITPTRLITCONVCONVIFACECONVNOPCOPYDCLDCLFUNCDCLFIELDDCLCONSTDCLTYPEDELETEDOTDOTPTRDOTMETHDOTINTERXDOTDOTTYPEDOTTYPE2EQNELTLEGEGTDEREFINDEXINDEXMAPKEYSTRUCTKEYLENMAKEMAKECHANMAKEMAPMAKESLICEMULDIVMODLSHRSHANDANDNOTNEWNOTBITNOTPLUSNEGORORPANICPRINTPRINTNPARENSENDSLICESLICEARRSLICESTRSLICE3SLICE3ARRSLICEHEADERRECOVERRECVRUNESTRSELRECVSELRECV2IOTAREALIMAGCOMPLEXALIGNOFOFFSETOFSIZEOFBLOCKBREAKCASEXCASECONTINUEDEFEREMPTYFALLFORFORUNTILGOTOIFLABELGORANGERETURNSELECTSWITCHTYPESWTCHANTMAPTSTRUCTTINTERTFUNCTARRAYDDDDDDARGINLCALLEFACEITABIDATASPTRCLOSUREVARCFUNCCHECKNILVARDEFVARKILLVARLIVEINDREGSPRETJMPGETGEND"
-var _Op_index = [...]uint16{0, 3, 7, 13, 17, 21, 28, 31, 34, 36, 39, 45, 49, 55, 61, 73, 88, 100, 112, 127, 139, 141, 144, 151, 158, 165, 175, 179, 183, 191, 199, 208, 216, 219, 224, 231, 238, 244, 253, 261, 269, 275, 279, 288, 295, 299, 302, 309, 317, 325, 332, 338, 341, 347, 354, 362, 366, 373, 381, 383, 385, 387, 389, 391, 393, 396, 401, 409, 412, 421, 424, 428, 436, 443, 452, 455, 458, 461, 464, 467, 470, 476, 479, 482, 485, 489, 494, 498, 503, 508, 514, 519, 523, 528, 536, 544, 550, 559, 570, 577, 581, 588, 595, 603, 607, 611, 615, 622, 629, 637, 643, 648, 653, 657, 662, 670, 675, 680, 684, 687, 695, 699, 701, 706, 710, 715, 721, 727, 733, 739, 744, 748, 755, 761, 766, 772, 775, 781, 788, 793, 797, 802, 806, 816, 821, 829, 835, 842, 849, 857, 863, 867, 870}
+var _Op_index = [...]uint16{0, 3, 7, 13, 17, 21, 28, 31, 34, 36, 39, 45, 49, 55, 61, 70, 82, 91, 100, 112, 121, 123, 126, 133, 140, 147, 157, 161, 165, 173, 181, 190, 198, 201, 206, 213, 220, 226, 235, 243, 251, 257, 261, 270, 277, 281, 284, 291, 299, 307, 314, 320, 323, 329, 336, 344, 348, 355, 363, 365, 367, 369, 371, 373, 375, 380, 385, 393, 396, 405, 408, 412, 420, 427, 436, 439, 442, 445, 448, 451, 454, 460, 463, 466, 472, 476, 479, 483, 488, 493, 499, 504, 508, 513, 521, 529, 535, 544, 555, 562, 566, 573, 580, 588, 592, 596, 600, 607, 614, 622, 628, 633, 638, 642, 647, 655, 660, 665, 669, 672, 680, 684, 686, 691, 693, 698, 704, 710, 716, 722, 727, 731, 738, 744, 749, 755, 758, 764, 771, 776, 780, 785, 789, 799, 804, 812, 818, 825, 832, 840, 846, 850, 853}
func (i Op) String() string {
if i >= Op(len(_Op_index)-1) {
}
if clear {
a := nod(OAS, v, nil)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
o.out = append(o.out, a)
}
func (o *Order) copyExpr(n *Node, t *types.Type, clear bool) *Node {
v := o.newTemp(t, clear)
a := nod(OAS, v, n)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
o.out = append(o.out, a)
return v
}
}
a := n.sepcopy()
a.Left = l
- return typecheck(a, Erv)
+ return typecheck(a, ctxExpr)
}
return o.copyExpr(n, n.Type, false)
}
a := n.sepcopy()
a.Left = l
- return typecheck(a, Erv)
+ return typecheck(a, ctxExpr)
- case ODOTPTR, OIND:
+ case ODOTPTR, ODEREF:
l := o.cheapExpr(n.Left)
if l == n.Left {
return n
}
a := n.sepcopy()
a.Left = l
- return typecheck(a, Erv)
+ return typecheck(a, ctxExpr)
case OINDEX, OINDEXMAP:
var l *Node
a := n.sepcopy()
a.Left = l
a.Right = r
- return typecheck(a, Erv)
+ return typecheck(a, ctxExpr)
default:
Fatalf("ordersafeexpr %v", n.Op)
if out != nil {
Fatalf("staticassign of const generated code: %+v", n)
}
- vstat = typecheck(vstat, Erv)
+ vstat = typecheck(vstat, ctxExpr)
return vstat
}
if isaddrokay(n) {
return n
}
-// mapKeyReplaceStrConv replaces OARRAYBYTESTR by OARRAYBYTESTRTMP
+// mapKeyReplaceStrConv replaces OBYTES2STR by OBYTES2STRTMP
// in n to avoid string allocations for keys in map lookups.
// Returns a bool that signals if a modification was made.
//
func mapKeyReplaceStrConv(n *Node) bool {
var replaced bool
switch n.Op {
- case OARRAYBYTESTR:
- n.Op = OARRAYBYTESTRTMP
+ case OBYTES2STR:
+ n.Op = OBYTES2STRTMP
replaced = true
case OSTRUCTLIT:
for _, elem := range n.List.Slice() {
n.Name.SetKeepalive(false)
n.SetAddrtaken(true) // ensure SSA keeps the n variable
live := nod(OVARLIVE, n, nil)
- live = typecheck(live, Etop)
+ live = typecheck(live, ctxStmt)
out = append(out, live)
}
kill := nod(OVARKILL, n, nil)
- kill = typecheck(kill, Etop)
+ kill = typecheck(kill, ctxStmt)
out = append(out, kill)
}
return out
as := nod(OAS2, nil, nil)
as.List.Set(l1)
as.Rlist.Set1(n)
- as = typecheck(as, Etop)
+ as = typecheck(as, ctxStmt)
o.stmt(as)
return l2
for i, t := range n.Left.Type.Params().FieldSlice() {
// Check for "unsafe-uintptr" tag provided by escape analysis.
- if t.Isddd() && !n.Isddd() {
+ if t.IsDDD() && !n.IsDDD() {
if t.Note == uintptrEscapesTag {
for ; i < n.List.Len(); i++ {
keepAlive(i)
t := o.newTemp(m.Type, false)
n.List.SetIndex(i, t)
a := nod(OAS, m, t)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
post = append(post, a)
}
}
}
l = o.copyExpr(l, n.Left.Type, false)
n.Right = nod(n.SubOp(), l, n.Right)
- n.Right = typecheck(n.Right, Erv)
+ n.Right = typecheck(n.Right, ctxExpr)
n.Right = o.expr(n.Right, nil)
n.Op = OAS
tmp2 := o.newTemp(types.Types[TBOOL], false)
o.out = append(o.out, n)
r := nod(OAS, n.List.First(), tmp1)
- r = typecheck(r, Etop)
+ r = typecheck(r, ctxStmt)
o.mapAssign(r)
r = okas(n.List.Second(), tmp2)
- r = typecheck(r, Etop)
+ r = typecheck(r, ctxStmt)
o.mapAssign(r)
n.List.Set2(tmp1, tmp2)
o.cleanTemp(t)
o.cleanTemp(t)
// Special: order arguments to inner call but not call itself.
- case ODEFER, OPROC:
+ case ODEFER, OGO:
t := o.markTemp()
o.call(n.Left)
o.out = append(o.out, n)
// Mark []byte(str) range expression to reuse string backing storage.
// It is safe because the storage cannot be mutated.
- if n.Right.Op == OSTRARRAYBYTE {
- n.Right.Op = OSTRARRAYBYTETMP
+ if n.Right.Op == OSTR2BYTES {
+ n.Right.Op = OSTR2BYTESTMP
}
t := o.markTemp()
if r.Type.IsString() && r.Type != types.Types[TSTRING] {
r = nod(OCONV, r, nil)
r.Type = types.Types[TSTRING]
- r = typecheck(r, Erv)
+ r = typecheck(r, ctxExpr)
}
n.Right = o.copyExpr(r, r.Type, false)
if r.Colas() {
tmp2 := nod(ODCL, tmp1, nil)
- tmp2 = typecheck(tmp2, Etop)
+ tmp2 = typecheck(tmp2, ctxStmt)
n2.Ninit.Append(tmp2)
}
r.Left = o.newTemp(r.Right.Left.Type.Elem(), types.Haspointers(r.Right.Left.Type.Elem()))
tmp2 := nod(OAS, tmp1, r.Left)
- tmp2 = typecheck(tmp2, Etop)
+ tmp2 = typecheck(tmp2, ctxStmt)
n2.Ninit.Append(tmp2)
}
tmp1 := r.List.First()
if r.Colas() {
tmp2 := nod(ODCL, tmp1, nil)
- tmp2 = typecheck(tmp2, Etop)
+ tmp2 = typecheck(tmp2, ctxStmt)
n2.Ninit.Append(tmp2)
}
r.List.Set1(o.newTemp(types.Types[TBOOL], false))
tmp2 := okas(tmp1, r.List.First())
- tmp2 = typecheck(tmp2, Etop)
+ tmp2 = typecheck(tmp2, ctxStmt)
n2.Ninit.Append(tmp2)
}
orderBlock(&n2.Ninit, o.free)
haslit := false
for _, n1 := range n.List.Slice() {
- hasbyte = hasbyte || n1.Op == OARRAYBYTESTR
+ hasbyte = hasbyte || n1.Op == OBYTES2STR
haslit = haslit || n1.Op == OLITERAL && len(n1.Val().U.(string)) != 0
}
if haslit && hasbyte {
for _, n2 := range n.List.Slice() {
- if n2.Op == OARRAYBYTESTR {
- n2.Op = OARRAYBYTESTRTMP
+ if n2.Op == OBYTES2STR {
+ n2.Op = OBYTES2STRTMP
}
}
}
ONEW,
OREAL,
ORECOVER,
- OSTRARRAYBYTE,
- OSTRARRAYBYTETMP,
- OSTRARRAYRUNE:
+ OSTR2BYTES,
+ OSTR2BYTESTMP,
+ OSTR2RUNES:
if isRuneCount(n) {
// len([]rune(s)) is rewritten to runtime.countrunes(s) later.
// Mark string(byteSlice) arguments to reuse byteSlice backing
// buffer during conversion. String comparison does not
// memorize the strings for later use, so it is safe.
- if n.Left.Op == OARRAYBYTESTR {
- n.Left.Op = OARRAYBYTESTRTMP
+ if n.Left.Op == OBYTES2STR {
+ n.Left.Op = OBYTES2STRTMP
}
- if n.Right.Op == OARRAYBYTESTR {
- n.Right.Op = OARRAYBYTESTRTMP
+ if n.Right.Op == OBYTES2STR {
+ n.Right.Op = OBYTES2STRTMP
}
case t.IsStruct() || t.IsArray():
as := nod(OAS2, nil, nil)
as.List.Set(left)
as.Rlist.Set(tmplist)
- as = typecheck(as, Etop)
+ as = typecheck(as, ctxStmt)
o.stmt(as)
}
if tmp1 != nil {
r := nod(OAS, n.List.First(), tmp1)
- r = typecheck(r, Etop)
+ r = typecheck(r, ctxStmt)
o.mapAssign(r)
n.List.SetFirst(tmp1)
}
if tmp2 != nil {
r := okas(n.List.Second(), tmp2)
- r = typecheck(r, Etop)
+ r = typecheck(r, ctxStmt)
o.mapAssign(r)
n.List.SetSecond(tmp2)
}
ls := n.List.Slice()
for i1, n1 := range ls {
if n1.Typecheck() == 0 {
- ls[i1] = typecheck(ls[i1], Erv|Easgn)
+ ls[i1] = typecheck(ls[i1], ctxExpr|ctxAssign)
}
}
decldepth++
- typecheckslice(n.Nbody.Slice(), Etop)
+ typecheckslice(n.Nbody.Slice(), ctxStmt)
decldepth--
}
func typecheckrangeExpr(n *Node) {
- n.Right = typecheck(n.Right, Erv)
+ n.Right = typecheck(n.Right, ctxExpr)
t := n.Right.Type
if t == nil {
ls := n.List.Slice()
for i1, n1 := range ls {
if n1.Name == nil || n1.Name.Defn != n {
- ls[i1] = typecheck(ls[i1], Erv|Easgn)
+ ls[i1] = typecheck(ls[i1], ctxExpr|ctxAssign)
}
}
// of the form "v1, a[v1] := range".
a := nod(OAS2, nil, nil)
a.List.Set2(v1, v2)
- a.Rlist.Set2(hv1, nod(OIND, hp, nil))
+ a.Rlist.Set2(hv1, nod(ODEREF, hp, nil))
body = append(body, a)
// Advance pointer as part of the late increment.
// advancing the pointer is safe and won't go past the
// end of the allocation.
a = nod(OAS, hp, addptr(hp, t.Elem().Width))
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
n.List.Set1(a)
case TMAP:
n.Right = mkcall1(fn, nil, nil, nod(OADDR, hit, nil))
key := nodSym(ODOT, hit, keysym)
- key = nod(OIND, key, nil)
+ key = nod(ODEREF, key, nil)
if v1 == nil {
body = nil
} else if v2 == nil {
body = []*Node{nod(OAS, v1, key)}
} else {
val := nodSym(ODOT, hit, valsym)
- val = nod(OIND, val, nil)
+ val = nod(ODEREF, val, nil)
a := nod(OAS2, nil, nil)
a.List.Set2(v1, v2)
a.Rlist.Set2(key, val)
}
n.Op = translatedLoopOp
- typecheckslice(init, Etop)
+ typecheckslice(init, ctxStmt)
if ifGuard != nil {
ifGuard.Ninit.Append(init...)
- ifGuard = typecheck(ifGuard, Etop)
+ ifGuard = typecheck(ifGuard, ctxStmt)
} else {
n.Ninit.Append(init...)
}
- typecheckslice(n.Left.Ninit.Slice(), Etop)
+ typecheckslice(n.Left.Ninit.Slice(), ctxStmt)
- n.Left = typecheck(n.Left, Erv)
+ n.Left = typecheck(n.Left, ctxExpr)
n.Left = defaultlit(n.Left, nil)
- n.Right = typecheck(n.Right, Etop)
- typecheckslice(body, Etop)
+ n.Right = typecheck(n.Right, ctxStmt)
+ typecheckslice(body, ctxStmt)
n.Nbody.Prepend(body...)
if ifGuard != nil {
fn = substArgTypes(fn, t.Key(), t.Elem())
n := mkcall1(fn, nil, nil, typename(t), m)
- n = typecheck(n, Etop)
+ n = typecheck(n, ctxStmt)
n = walkstmt(n)
return n
n.Nbody.Append(v1)
- n.Left = typecheck(n.Left, Erv)
+ n.Left = typecheck(n.Left, ctxExpr)
n.Left = defaultlit(n.Left, nil)
- typecheckslice(n.Nbody.Slice(), Etop)
+ typecheckslice(n.Nbody.Slice(), ctxStmt)
n = walkstmt(n)
return true
}
for _, t := range f.Params().Fields().Slice() {
d := anonfield(t.Type)
- d.SetIsddd(t.Isddd())
+ d.SetIsDDD(t.IsDDD())
in = append(in, d)
}
}
isddd := false
for _, t1 := range t.Params().Fields().Slice() {
- isddd = t1.Isddd()
+ isddd = t1.IsDDD()
dtypesym(t1.Type)
}
for _, t1 := range t.Results().Fields().Slice() {
func typecheckselect(sel *Node) {
var def *Node
lno := setlineno(sel)
- typecheckslice(sel.Ninit.Slice(), Etop)
+ typecheckslice(sel.Ninit.Slice(), ctxStmt)
for _, ncase := range sel.List.Slice() {
if ncase.Op != OXCASE {
setlineno(ncase)
} else if ncase.List.Len() > 1 {
yyerrorl(ncase.Pos, "select cases cannot be lists")
} else {
- ncase.List.SetFirst(typecheck(ncase.List.First(), Etop))
+ ncase.List.SetFirst(typecheck(ncase.List.First(), ctxStmt))
n := ncase.List.First()
ncase.Left = n
ncase.List.Set(nil)
}
}
- typecheckslice(ncase.Nbody.Slice(), Etop)
+ typecheckslice(ncase.Nbody.Slice(), ctxStmt)
}
lineno = lno
}
if n.Left == nil {
- nblank = typecheck(nblank, Erv|Easgn)
+ nblank = typecheck(nblank, ctxExpr|ctxAssign)
n.Left = nblank
}
n.Right = nil
n.Left = nil
n.SetTypecheck(0)
- n = typecheck(n, Etop)
+ n = typecheck(n, ctxStmt)
}
// if ch == nil { block() }; n;
ln.Set(l)
a.Nbody.Set1(mkcall("block", nil, &ln))
l = ln.Slice()
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
l = append(l, a, n)
}
switch n.Op {
case OSEND:
n.Right = nod(OADDR, n.Right, nil)
- n.Right = typecheck(n.Right, Erv)
+ n.Right = typecheck(n.Right, ctxExpr)
case OSELRECV, OSELRECV2:
if n.Op == OSELRECV2 && n.List.Len() == 0 {
if n.Left != nil {
n.Left = nod(OADDR, n.Left, nil)
- n.Left = typecheck(n.Left, Erv)
+ n.Left = typecheck(n.Left, ctxExpr)
}
}
}
elem = nodnil()
}
receivedp := nod(OADDR, n.List.First(), nil)
- receivedp = typecheck(receivedp, Erv)
+ receivedp = typecheck(receivedp, ctxExpr)
r.Left = mkcall1(chanfn("selectnbrecv2", 2, ch.Type), types.Types[TBOOL], &r.Ninit, elem, receivedp, ch)
}
- r.Left = typecheck(r.Left, Erv)
+ r.Left = typecheck(r.Left, ctxExpr)
r.Nbody.Set(cas.Nbody.Slice())
r.Rlist.Set(append(dflt.Ninit.Slice(), dflt.Nbody.Slice()...))
return []*Node{r, nod(OBREAK, nil, nil)}
lineno = sellineno
selv := temp(types.NewArray(scasetype(), int64(n)))
r := nod(OAS, selv, nil)
- r = typecheck(r, Etop)
+ r = typecheck(r, ctxStmt)
init = append(init, r)
order := temp(types.NewArray(types.Types[TUINT16], 2*int64(n)))
r = nod(OAS, order, nil)
- r = typecheck(r, Etop)
+ r = typecheck(r, ctxStmt)
init = append(init, r)
// register cases
setField := func(f string, val *Node) {
r := nod(OAS, nodSym(ODOT, nod(OINDEX, selv, nodintconst(int64(i))), lookup(f)), val)
- r = typecheck(r, Etop)
+ r = typecheck(r, ctxStmt)
init = append(init, r)
}
r.List.Set2(chosen, recvOK)
fn := syslook("selectgo")
r.Rlist.Set1(mkcall1(fn, fn.Type.Results(), nil, bytePtrToIndex(selv, 0), bytePtrToIndex(order, 0), nodintconst(int64(n))))
- r = typecheck(r, Etop)
+ r = typecheck(r, ctxStmt)
init = append(init, r)
// selv and order are no longer alive after selectgo.
setlineno(cas)
cond := nod(OEQ, chosen, nodintconst(int64(i)))
- cond = typecheck(cond, Erv)
+ cond = typecheck(cond, ctxExpr)
cond = defaultlit(cond, nil)
r = nod(OIF, cond, nil)
if n := cas.Left; n != nil && n.Op == OSELRECV2 {
x := nod(OAS, n.List.First(), recvOK)
- x = typecheck(x, Etop)
+ x = typecheck(x, ctxStmt)
r.Nbody.Append(x)
}
}
//dump("not static ptrlit", r);
- case OSTRARRAYBYTE:
+ case OSTR2BYTES:
if l.Class() == PEXTERN && r.Left.Op == OLITERAL {
sval := r.Left.Val().U.(string)
slicebytes(l, sval, len(sval))
func litas(l *Node, r *Node, init *Nodes) {
a := nod(OAS, l, r)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
a = walkexpr(a, init)
init.Append(a)
}
// build list of assignments: var[index] = expr
setlineno(value)
a = nod(OAS, a, value)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
switch kind {
case initKindStatic:
genAsStatic(a)
fixedlit(ctxt, initKindDynamic, n, vstat, init)
// copy static to slice
- var_ = typecheck(var_, Erv|Easgn)
+ var_ = typecheck(var_, ctxExpr|ctxAssign)
var nam Node
if !stataddr(&nam, var_) || nam.Class() != PEXTERN {
Fatalf("slicelit: %v", var_)
if vstat == nil {
a = nod(OAS, x, nil)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
init.Append(a) // zero new temp
} else {
// Declare that we're about to initialize all of x.
a = temp(t)
if vstat == nil {
a = nod(OAS, temp(t), nil)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
init.Append(a) // zero new temp
a = a.Left
} else {
}
a = nod(OAS, vauto, a)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
a = walkexpr(a, init)
init.Append(a)
if vstat != nil {
// copy static to heap (4)
- a = nod(OIND, vauto, nil)
+ a = nod(ODEREF, vauto, nil)
a = nod(OAS, a, vstat)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
a = walkexpr(a, init)
init.Append(a)
}
setlineno(value)
a = nod(OAS, a, value)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
a = orderStmtInPlace(a, map[string][]*Node{})
a = walkstmt(a)
init.Append(a)
// make slice out of heap (6)
a = nod(OAS, var_, nod(OSLICE, vauto, nil))
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
a = orderStmtInPlace(a, map[string][]*Node{})
a = walkstmt(a)
init.Append(a)
loop.Nbody.Set1(body)
loop.Ninit.Set1(zero)
- loop = typecheck(loop, Etop)
+ loop = typecheck(loop, ctxStmt)
loop = walkstmt(loop)
init.Append(loop)
} else {
setlineno(index)
a := nod(OAS, key, index)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
a = walkstmt(a)
init.Append(a)
setlineno(value)
a = nod(OAS, val, value)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
a = walkstmt(a)
init.Append(a)
setlineno(val)
a = nod(OAS, nod(OINDEX, m, key), val)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
a = walkstmt(a)
init.Append(a)
}
a := nod(OVARKILL, key, nil)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
init.Append(a)
a = nod(OVARKILL, val, nil)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
init.Append(a)
}
// n.Right is stack temporary used as backing store.
init.Append(nod(OAS, n.Right, nil)) // zero backing store, just in case (#18410)
r = nod(OADDR, n.Right, nil)
- r = typecheck(r, Erv)
+ r = typecheck(r, ctxExpr)
} else {
r = nod(ONEW, nil, nil)
r.SetTypecheck(1)
r = walkexpr(r, init)
a := nod(OAS, var_, r)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
init.Append(a)
- var_ = nod(OIND, var_, nil)
- var_ = typecheck(var_, Erv|Easgn)
+ var_ = nod(ODEREF, var_, nil)
+ var_ = typecheck(var_, ctxExpr|ctxAssign)
anylit(n.Left, var_, init)
case OSTRUCTLIT, OARRAYLIT:
// copy static to var
a := nod(OAS, var_, vstat)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
a = walkexpr(a, init)
init.Append(a)
// initialization of an array or struct with unspecified components (missing fields or arrays)
if var_.isSimpleName() || int64(n.List.Len()) < components {
a := nod(OAS, var_, nil)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
a = walkexpr(a, init)
init.Append(a)
}
}
case ODEFER:
s.call(n.Left, callDefer)
- case OPROC:
+ case OGO:
s.call(n.Left, callGo)
case OAS2DOTTYPE:
opAndType{ONOT, TBOOL}: ssa.OpNot,
- opAndType{OMINUS, TINT8}: ssa.OpNeg8,
- opAndType{OMINUS, TUINT8}: ssa.OpNeg8,
- opAndType{OMINUS, TINT16}: ssa.OpNeg16,
- opAndType{OMINUS, TUINT16}: ssa.OpNeg16,
- opAndType{OMINUS, TINT32}: ssa.OpNeg32,
- opAndType{OMINUS, TUINT32}: ssa.OpNeg32,
- opAndType{OMINUS, TINT64}: ssa.OpNeg64,
- opAndType{OMINUS, TUINT64}: ssa.OpNeg64,
- opAndType{OMINUS, TFLOAT32}: ssa.OpNeg32F,
- opAndType{OMINUS, TFLOAT64}: ssa.OpNeg64F,
-
- opAndType{OCOM, TINT8}: ssa.OpCom8,
- opAndType{OCOM, TUINT8}: ssa.OpCom8,
- opAndType{OCOM, TINT16}: ssa.OpCom16,
- opAndType{OCOM, TUINT16}: ssa.OpCom16,
- opAndType{OCOM, TINT32}: ssa.OpCom32,
- opAndType{OCOM, TUINT32}: ssa.OpCom32,
- opAndType{OCOM, TINT64}: ssa.OpCom64,
- opAndType{OCOM, TUINT64}: ssa.OpCom64,
+ opAndType{ONEG, TINT8}: ssa.OpNeg8,
+ opAndType{ONEG, TUINT8}: ssa.OpNeg8,
+ opAndType{ONEG, TINT16}: ssa.OpNeg16,
+ opAndType{ONEG, TUINT16}: ssa.OpNeg16,
+ opAndType{ONEG, TINT32}: ssa.OpNeg32,
+ opAndType{ONEG, TUINT32}: ssa.OpNeg32,
+ opAndType{ONEG, TINT64}: ssa.OpNeg64,
+ opAndType{ONEG, TUINT64}: ssa.OpNeg64,
+ opAndType{ONEG, TFLOAT32}: ssa.OpNeg32F,
+ opAndType{ONEG, TFLOAT64}: ssa.OpNeg64F,
+
+ opAndType{OBITNOT, TINT8}: ssa.OpCom8,
+ opAndType{OBITNOT, TUINT8}: ssa.OpCom8,
+ opAndType{OBITNOT, TINT16}: ssa.OpCom16,
+ opAndType{OBITNOT, TUINT16}: ssa.OpCom16,
+ opAndType{OBITNOT, TINT32}: ssa.OpCom32,
+ opAndType{OBITNOT, TUINT32}: ssa.OpCom32,
+ opAndType{OBITNOT, TINT64}: ssa.OpCom64,
+ opAndType{OBITNOT, TUINT64}: ssa.OpCom64,
opAndType{OIMAG, TCOMPLEX64}: ssa.OpComplexImag,
opAndType{OIMAG, TCOMPLEX128}: ssa.OpComplexImag,
s.stmtList(n.Ninit)
switch n.Op {
- case OARRAYBYTESTRTMP:
+ case OBYTES2STRTMP:
slice := s.expr(n.Left)
ptr := s.newValue1(ssa.OpSlicePtr, s.f.Config.Types.BytePtr, slice)
len := s.newValue1(ssa.OpSliceLen, types.Types[TINT], slice)
return s.newValue2(ssa.OpStringMake, n.Type, ptr, len)
- case OSTRARRAYBYTETMP:
+ case OSTR2BYTESTMP:
str := s.expr(n.Left)
ptr := s.newValue1(ssa.OpStringPtr, s.f.Config.Types.BytePtr, str)
len := s.newValue1(ssa.OpStringLen, types.Types[TINT], str)
return s.newValue2(ssa.OpComplexMake, n.Type, r, i)
// unary ops
- case OMINUS:
+ case ONEG:
a := s.expr(n.Left)
if n.Type.IsComplex() {
tp := floatForComplex(n.Type)
s.newValue1(negop, tp, s.newValue1(ssa.OpComplexImag, tp, a)))
}
return s.newValue1(s.ssaOp(n.Op, n.Type), a.Type, a)
- case ONOT, OCOM:
+ case ONOT, OBITNOT:
a := s.expr(n.Left)
return s.newValue1(s.ssaOp(n.Op, n.Type), a.Type, a)
case OIMAG, OREAL:
addr := s.constOffPtrSP(types.NewPtr(n.Type), n.Xoffset)
return s.load(n.Type, addr)
- case OIND:
+ case ODEREF:
p := s.exprPtr(n.Left, false, n.Pos)
return s.load(n.Type, p)
args[0], args[1] = args[1], args[0]
case ssa.OpSub32F,
ssa.OpSub64F:
- args[1] = s.newValue1(s.ssaOp(OMINUS, types.Types[callDef.rtype]), args[1].Type, args[1])
+ args[1] = s.newValue1(s.ssaOp(ONEG, types.Types[callDef.rtype]), args[1].Type, args[1])
}
result := s.rtcall(callDef.rtfn, true, []*types.Type{types.Types[callDef.rtype]}, args...)[0]
if !instrumenting {
add("runtime", "slicebytetostringtmp",
func(s *state, n *Node, args []*ssa.Value) *ssa.Value {
- // Compiler frontend optimizations emit OARRAYBYTESTRTMP nodes
+ // Compiler frontend optimizations emit OBYTES2STRTMP nodes
// for the backend instead of slicebytetostringtmp calls
// when not instrumenting.
slice := args[0]
}
return s.newValue2(ssa.OpPtrIndex, types.NewPtr(n.Left.Type.Elem()), a, i)
}
- case OIND:
+ case ODEREF:
return s.exprPtr(n.Left, bounded, n.Pos)
case ODOT:
p := s.addr(n.Left, bounded)
if src.IsSlice() && dst.IsString() {
if src.Elem().Etype == types.Bytetype.Etype {
- return OARRAYBYTESTR
+ return OBYTES2STR
}
if src.Elem().Etype == types.Runetype.Etype {
- return OARRAYRUNESTR
+ return ORUNES2STR
}
}
// String to slice.
if src.IsString() && dst.IsSlice() {
if dst.Elem().Etype == types.Bytetype.Etype {
- return OSTRARRAYBYTE
+ return OSTR2BYTES
}
if dst.Elem().Etype == types.Runetype.Etype {
- return OSTRARRAYRUNE
+ return OSTR2RUNES
}
}
return true
}
case OINDEX, OSLICE, OSLICEARR, OSLICE3, OSLICE3ARR, OSLICESTR,
- OIND, ODOTPTR, ODOTTYPE, ODIV, OMOD:
+ ODEREF, ODOTPTR, ODOTTYPE, ODIV, OMOD:
// These ops might panic, make sure they are done
// before we start marshaling args for a call. See issue 16760.
return true
// When using soft-float, these ops might be rewritten to function calls
// so we ensure they are evaluated first.
- case OADD, OSUB, OMINUS, OMUL:
+ case OADD, OSUB, ONEG, OMUL:
if thearch.SoftFloat && (isFloat[n.Type.Etype] || isComplex[n.Type.Etype]) {
return true
}
}
r := n.copy()
r.Left = l
- r = typecheck(r, Erv)
+ r = typecheck(r, ctxExpr)
r = walkexpr(r, init)
return r
- case ODOTPTR, OIND:
+ case ODOTPTR, ODEREF:
l := safeexpr(n.Left, init)
if l == n.Left {
return n
func copyexpr(n *Node, t *types.Type, init *Nodes) *Node {
l := temp(t)
a := nod(OAS, l, n)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
a = walkexpr(a, init)
init.Append(a)
return l
// will give shortest unique addressing.
// modify the tree with missing type names.
func adddot(n *Node) *Node {
- n.Left = typecheck(n.Left, Etype|Erv)
+ n.Left = typecheck(n.Left, Etype|ctxExpr)
if n.Left.Diag() {
n.SetDiag(true)
}
}
a := symfield(s, t.Type)
a.Pos = t.Pos
- a.SetIsddd(t.Isddd())
+ a.SetIsDDD(t.IsDDD())
args = append(args, a)
}
fn.Func.SetWrapper(true) // ignore frame for panic+recover matching
call := nod(OCALL, dot, nil)
call.List.Set(paramNnames(tfn.Type))
- call.SetIsddd(tfn.Type.IsVariadic())
+ call.SetIsDDD(tfn.Type.IsVariadic())
if method.Type.NumResults() > 0 {
n := nod(ORETURN, nil, nil)
n.List.Set1(call)
testdclstack()
}
- fn = typecheck(fn, Etop)
+ fn = typecheck(fn, ctxStmt)
Curfn = fn
- typecheckslice(fn.Nbody.Slice(), Etop)
+ typecheckslice(fn.Nbody.Slice(), ctxStmt)
// Inline calls within (*T).M wrappers. This is safe because we only
// generate those wrappers within the same compilation unit as (T).M.
x = walkexpr(x, nil) // caller has not done this yet
if x.Type.IsInterface() {
x = nod(OITAB, x, nil)
- x = typecheck(x, Erv)
+ x = typecheck(x, ctxExpr)
}
n := nod(OCHECKNIL, x, nil)
ptr.Type = types.NewPtr(t)
ptr.SetBounded(true)
ptr.SetTypecheck(1)
- ind := nod(OIND, ptr, nil)
+ ind := nod(ODEREF, ptr, nil)
ind.Type = t
ind.SetTypecheck(1)
return ind
// typecheckswitch typechecks a switch statement.
func typecheckswitch(n *Node) {
- typecheckslice(n.Ninit.Slice(), Etop)
+ typecheckslice(n.Ninit.Slice(), ctxStmt)
var nilonly string
var top int
if n.Left != nil && n.Left.Op == OTYPESW {
// type switch
top = Etype
- n.Left.Right = typecheck(n.Left.Right, Erv)
+ n.Left.Right = typecheck(n.Left.Right, ctxExpr)
t = n.Left.Right.Type
if t != nil && !t.IsInterface() {
yyerrorl(n.Pos, "cannot type switch on non-interface value %L", n.Left.Right)
}
} else {
// expression switch
- top = Erv
+ top = ctxExpr
if n.Left != nil {
- n.Left = typecheck(n.Left, Erv)
+ n.Left = typecheck(n.Left, ctxExpr)
n.Left = defaultlit(n.Left, nil)
t = n.Left.Type
} else {
ls := ncase.List.Slice()
for i1, n1 := range ls {
setlineno(n1)
- ls[i1] = typecheck(ls[i1], Erv|Etype)
+ ls[i1] = typecheck(ls[i1], ctxExpr|Etype)
n1 = ls[i1]
if n1.Type == nil || t == nil {
continue
setlineno(ncase)
switch top {
// expression switch
- case Erv:
+ case ctxExpr:
ls[i1] = defaultlit(ls[i1], t)
n1 = ls[i1]
switch {
nvar.Type = n.Type
}
- nvar = typecheck(nvar, Erv|Easgn)
+ nvar = typecheck(nvar, ctxExpr|ctxAssign)
ncase.Rlist.SetFirst(nvar)
}
}
- typecheckslice(ncase.Nbody.Slice(), Etop)
+ typecheckslice(ncase.Nbody.Slice(), ctxStmt)
}
switch top {
// expression switch
- case Erv:
+ case ctxExpr:
checkDupExprCases(n.Left, n.List.Slice())
}
}
// convert switch {...} to switch true {...}
if sw.Left == nil {
sw.Left = nodbool(true)
- sw.Left = typecheck(sw.Left, Erv)
+ sw.Left = typecheck(sw.Left, ctxExpr)
sw.Left = defaultlit(sw.Left, nil)
}
// because walkexpr will lower the string
// conversion into a runtime call.
// See issue 24937 for more discussion.
- if cond.Op == OARRAYBYTESTR {
+ if cond.Op == OBYTES2STR {
ok := true
for _, cas := range sw.List.Slice() {
if cas.Op != OCASE {
}
}
if ok {
- cond.Op = OARRAYBYTESTRTMP
+ cond.Op = OBYTES2STRTMP
}
}
} else {
s.exprname = temp(cond.Type)
cas = []*Node{nod(OAS, s.exprname, cond)}
- typecheckslice(cas, Etop)
+ typecheckslice(cas, ctxStmt)
}
// Enumerate the cases and prepare the default case.
// s.kind == switchKindFalse
a.Left = nod(ONOT, n.Left, nil) // if !val
}
- a.Left = typecheck(a.Left, Erv)
+ a.Left = typecheck(a.Left, ctxExpr)
a.Left = defaultlit(a.Left, nil)
a.Nbody.Set1(n.Right) // goto l
} else {
a.Left = le
}
- a.Left = typecheck(a.Left, Erv)
+ a.Left = typecheck(a.Left, ctxExpr)
a.Left = defaultlit(a.Left, nil)
a.Nbody.Set1(s.walkCases(cc[:half]))
a.Rlist.Set1(s.walkCases(cc[half:]))
nod(ODCL, n.Rlist.First(), nil),
nod(OAS, n.Rlist.First(), typeswvar),
}
- typecheckslice(l, Etop)
+ typecheckslice(l, ctxStmt)
stat = append(stat, l...)
}
stat = append(stat, n.Nbody.Slice()...)
s.facename = temp(cond.Right.Type)
a := nod(OAS, s.facename, cond.Right)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
cas = append(cas, a)
s.okname = temp(types.Types[TBOOL])
- s.okname = typecheck(s.okname, Erv)
+ s.okname = typecheck(s.okname, ctxExpr)
s.hashname = temp(types.Types[TUINT32])
- s.hashname = typecheck(s.hashname, Erv)
+ s.hashname = typecheck(s.hashname, ctxExpr)
// set up labels and jumps
casebody(sw, s.facename)
blk.List.Set2(nodSym(OLABEL, nil, lbl), def)
def = blk
}
- i.Left = typecheck(i.Left, Erv)
+ i.Left = typecheck(i.Left, ctxExpr)
i.Left = defaultlit(i.Left, nil)
cas = append(cas, i)
}
h.SetBounded(true) // guaranteed not to fault
a = nod(OAS, s.hashname, h)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
cas = append(cas, a)
cc := clauses.list
var init Nodes
if t.Rlist.Len() == 0 {
name = nblank
- nblank = typecheck(nblank, Erv|Easgn)
+ nblank = typecheck(nblank, ctxExpr|ctxAssign)
} else {
name = t.Rlist.First()
init.Append(nod(ODCL, name, nil))
a := nod(OAS, name, nil)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
init.Append(a)
}
b := nod(ODOTTYPE, s.facename, nil)
b.Type = t.Left.Type // interface.(type)
a.Rlist.Set1(b)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
a = walkexpr(a, &init)
init.Append(a)
}
a := nod(OIF, nil, nil)
a.Left = nod(OEQ, s.hashname, nodintconst(int64(c.hash)))
- a.Left = typecheck(a.Left, Erv)
+ a.Left = typecheck(a.Left, ctxExpr)
a.Left = defaultlit(a.Left, nil)
a.Nbody.Set1(n.Right)
cas = append(cas, a)
half := len(cc) / 2
a := nod(OIF, nil, nil)
a.Left = nod(OLE, s.hashname, nodintconst(int64(cc[half-1].hash)))
- a.Left = typecheck(a.Left, Erv)
+ a.Left = typecheck(a.Left, ctxExpr)
a.Left = defaultlit(a.Left, nil)
a.Nbody.Set1(s.walkCases(cc[:half]))
a.Rlist.Set1(s.walkCases(cc[half:]))
_, nodeAssigned // is the variable ever assigned to
_, nodeAddrtaken // address taken, even if not moved to heap
_, nodeImplicit
- _, nodeIsddd // is the argument variadic
+ _, nodeIsDDD // is the argument variadic
_, nodeDiag // already printed error about this
_, nodeColas // OAS resulting from :=
_, nodeNonNil // guaranteed to be non-nil
func (n *Node) Assigned() bool { return n.flags&nodeAssigned != 0 }
func (n *Node) Addrtaken() bool { return n.flags&nodeAddrtaken != 0 }
func (n *Node) Implicit() bool { return n.flags&nodeImplicit != 0 }
-func (n *Node) Isddd() bool { return n.flags&nodeIsddd != 0 }
+func (n *Node) IsDDD() bool { return n.flags&nodeIsDDD != 0 }
func (n *Node) Diag() bool { return n.flags&nodeDiag != 0 }
func (n *Node) Colas() bool { return n.flags&nodeColas != 0 }
func (n *Node) NonNil() bool { return n.flags&nodeNonNil != 0 }
func (n *Node) SetAssigned(b bool) { n.flags.set(nodeAssigned, b) }
func (n *Node) SetAddrtaken(b bool) { n.flags.set(nodeAddrtaken, b) }
func (n *Node) SetImplicit(b bool) { n.flags.set(nodeImplicit, b) }
-func (n *Node) SetIsddd(b bool) { n.flags.set(nodeIsddd, b) }
+func (n *Node) SetIsDDD(b bool) { n.flags.set(nodeIsDDD, b) }
func (n *Node) SetDiag(b bool) { n.flags.set(nodeDiag, b) }
func (n *Node) SetColas(b bool) { n.flags.set(nodeColas, b) }
func (n *Node) SetNonNil(b bool) { n.flags.set(nodeNonNil, b) }
FieldTrack map[*types.Sym]struct{}
DebugInfo *ssa.FuncDebug
Ntype *Node // signature
- Top int // top context (Ecall, Eproc, etc)
+ Top int // top context (ctxCallee, etc)
Closure *Node // OCLOSURE <-> ODCLFUNC
Nname *Node
lsym *obj.LSym
OLITERAL // literal
// expressions
- OADD // Left + Right
- OSUB // Left - Right
- OOR // Left | Right
- OXOR // Left ^ Right
- OADDSTR // +{List} (string addition, list elements are strings)
- OADDR // &Left
- OANDAND // Left && Right
- OAPPEND // append(List); after walk, Left may contain elem type descriptor
- OARRAYBYTESTR // Type(Left) (Type is string, Left is a []byte)
- OARRAYBYTESTRTMP // Type(Left) (Type is string, Left is a []byte, ephemeral)
- OARRAYRUNESTR // Type(Left) (Type is string, Left is a []rune)
- OSTRARRAYBYTE // Type(Left) (Type is []byte, Left is a string)
- OSTRARRAYBYTETMP // Type(Left) (Type is []byte, Left is a string, ephemeral)
- OSTRARRAYRUNE // Type(Left) (Type is []rune, Left is a string)
- OAS // Left = Right or (if Colas=true) Left := Right
- OAS2 // List = Rlist (x, y, z = a, b, c)
- OAS2FUNC // List = Rlist (x, y = f())
- OAS2RECV // List = Rlist (x, ok = <-c)
- OAS2MAPR // List = Rlist (x, ok = m["foo"])
- OAS2DOTTYPE // List = Rlist (x, ok = I.(int))
- OASOP // Left Etype= Right (x += y)
- OCALL // Left(List) (function call, method call or type conversion)
+ OADD // Left + Right
+ OSUB // Left - Right
+ OOR // Left | Right
+ OXOR // Left ^ Right
+ OADDSTR // +{List} (string addition, list elements are strings)
+ OADDR // &Left
+ OANDAND // Left && Right
+ OAPPEND // append(List); after walk, Left may contain elem type descriptor
+ OBYTES2STR // Type(Left) (Type is string, Left is a []byte)
+ OBYTES2STRTMP // Type(Left) (Type is string, Left is a []byte, ephemeral)
+ ORUNES2STR // Type(Left) (Type is string, Left is a []rune)
+ OSTR2BYTES // Type(Left) (Type is []byte, Left is a string)
+ OSTR2BYTESTMP // Type(Left) (Type is []byte, Left is a string, ephemeral)
+ OSTR2RUNES // Type(Left) (Type is []rune, Left is a string)
+ OAS // Left = Right or (if Colas=true) Left := Right
+ OAS2 // List = Rlist (x, y, z = a, b, c)
+ OAS2FUNC // List = Rlist (x, y = f())
+ OAS2RECV // List = Rlist (x, ok = <-c)
+ OAS2MAPR // List = Rlist (x, ok = m["foo"])
+ OAS2DOTTYPE // List = Rlist (x, ok = I.(int))
+ OASOP // Left Etype= Right (x += y)
+ OCALL // Left(List) (function call, method call or type conversion)
// OCALLFUNC, OCALLMETH, and OCALLINTER have the same structure.
// Prior to walk, they are: Left(List), where List is all regular arguments.
OLE // Left <= Right
OGE // Left >= Right
OGT // Left > Right
- OIND // *Left
+ ODEREF // *Left
OINDEX // Left[Right] (index of array or slice)
OINDEXMAP // Left[Right] (index of map)
OKEY // Left:Right (key:value in struct/array/map literal)
OANDNOT // Left &^ Right
ONEW // new(Left)
ONOT // !Left
- OCOM // ^Left
+ OBITNOT // ^Left
OPLUS // +Left
- OMINUS // -Left
+ ONEG // -Left
OOROR // Left || Right
OPANIC // panic(Left)
OPRINT // print(List)
OGOTO // goto Sym
OIF // if Ninit; Left { Nbody } else { Rlist }
OLABEL // Sym:
- OPROC // go Left (Left must be call)
+ OGO // go Left (Left must be call)
ORANGE // for List = range Right { Nbody }
ORETURN // return List
OSELECT // select { List } (List is list of OXCASE or OCASE)
}
const (
- Etop = 1 << iota // evaluated at statement level
- Erv // evaluated in value context
- Etype // evaluated in type context
- Ecall // call-only expressions are ok
- Efnstruct // multivalue function returns are ok
- Easgn // assigning to expression
- Ecomplit // type in composite literal
+ ctxStmt = 1 << iota // evaluated at statement level
+ ctxExpr // evaluated in value context
+ Etype // evaluated in type context
+ ctxCallee // call-only expressions are ok
+ ctxMultiOK // multivalue function returns are ok
+ ctxAssign // assigning to expression
+ ctxCompLit // type in composite literal
)
// type checks the whole tree of an expression.
switch n.Op {
// We can already diagnose variables used as types.
case ONAME:
- if top&(Erv|Etype) == Etype {
+ if top&(ctxExpr|Etype) == Etype {
yyerror("%v is not a type", n)
}
}
case OLITERAL:
- if top&(Erv|Etype) == Etype {
+ if top&(ctxExpr|Etype) == Etype {
yyerror("%v is not a type", n)
break
}
break
}
- if n.Op == ONAME && n.SubOp() != 0 && top&Ecall == 0 {
+ if n.Op == ONAME && n.SubOp() != 0 && top&ctxCallee == 0 {
yyerror("use of builtin %v not in function call", n.Sym)
n.Type = nil
return n
// names
case OLITERAL:
- ok |= Erv
+ ok |= ctxExpr
if n.Type == nil && n.Val().Ctype() == CTSTR {
n.Type = types.Idealstring
}
case ONONAME:
- ok |= Erv
+ ok |= ctxExpr
case ONAME:
if n.Name.Decldepth == 0 {
n.Name.Decldepth = decldepth
}
if n.SubOp() != 0 {
- ok |= Ecall
+ ok |= ctxCallee
break
}
- if top&Easgn == 0 {
+ if top&ctxAssign == 0 {
// not a write to the variable
if n.isBlank() {
yyerror("cannot use _ as value")
n.Name.SetUsed(true)
}
- ok |= Erv
+ ok |= ctxExpr
case OPACK:
yyerror("use of package %v without selector", n.Sym)
case ODDD:
break
- // types (OIND is with exprs)
+ // types (ODEREF is with exprs)
case OTYPE:
ok |= Etype
if n.Left == nil {
t = types.NewSlice(r.Type)
} else if n.Left.Op == ODDD {
- if top&Ecomplit == 0 {
+ if top&ctxCompLit == 0 {
if !n.Diag() {
n.SetDiag(true)
yyerror("use of [...] array outside of array literal")
}
t = types.NewDDDArray(r.Type)
} else {
- n.Left = indexlit(typecheck(n.Left, Erv))
+ n.Left = indexlit(typecheck(n.Left, ctxExpr))
l := n.Left
if consttype(l) != CTINT {
switch {
n.Rlist.Set(nil)
// type or expr
- case OIND:
- n.Left = typecheck(n.Left, Erv|Etype|top&Ecomplit)
+ case ODEREF:
+ n.Left = typecheck(n.Left, ctxExpr|Etype|top&ctxCompLit)
l := n.Left
t := l.Type
if t == nil {
}
if !t.IsPtr() {
- if top&(Erv|Etop) != 0 {
+ if top&(ctxExpr|ctxStmt) != 0 {
yyerror("invalid indirect of %L", n.Left)
n.Type = nil
return n
break
}
- ok |= Erv
+ ok |= ctxExpr
n.Type = t.Elem()
// arithmetic exprs
var op Op
var r *Node
if n.Op == OASOP {
- ok |= Etop
- n.Left = typecheck(n.Left, Erv)
- n.Right = typecheck(n.Right, Erv)
+ ok |= ctxStmt
+ n.Left = typecheck(n.Left, ctxExpr)
+ n.Right = typecheck(n.Right, ctxExpr)
l = n.Left
r = n.Right
checkassign(n, n.Left)
// TODO(marvin): Fix Node.EType type union.
op = n.SubOp()
} else {
- ok |= Erv
- n.Left = typecheck(n.Left, Erv)
- n.Right = typecheck(n.Right, Erv)
+ ok |= ctxExpr
+ n.Left = typecheck(n.Left, ctxExpr)
+ n.Right = typecheck(n.Right, ctxExpr)
l = n.Left
r = n.Right
if l.Type == nil || r.Type == nil {
n.Type = t
- case OCOM, OMINUS, ONOT, OPLUS:
- ok |= Erv
- n.Left = typecheck(n.Left, Erv)
+ case OBITNOT, ONEG, ONOT, OPLUS:
+ ok |= ctxExpr
+ n.Left = typecheck(n.Left, ctxExpr)
l := n.Left
t := l.Type
if t == nil {
// exprs
case OADDR:
- ok |= Erv
+ ok |= ctxExpr
- n.Left = typecheck(n.Left, Erv)
+ n.Left = typecheck(n.Left, ctxExpr)
if n.Left.Type == nil {
n.Type = nil
return n
n.Type = types.NewPtr(t)
case OCOMPLIT:
- ok |= Erv
+ ok |= ctxExpr
n = typecheckcomplit(n)
if n.Type == nil {
return n
}
}
- n.Left = typecheck(n.Left, Erv|Etype)
+ n.Left = typecheck(n.Left, ctxExpr|Etype)
n.Left = defaultlit(n.Left, nil)
if n.Type == nil {
return n
}
- ok = Erv
+ ok = ctxExpr
break
}
switch n.Op {
case ODOTINTER, ODOTMETH:
- if top&Ecall != 0 {
- ok |= Ecall
+ if top&ctxCallee != 0 {
+ ok |= ctxCallee
} else {
typecheckpartialcall(n, s)
- ok |= Erv
+ ok |= ctxExpr
}
default:
- ok |= Erv
+ ok |= ctxExpr
}
case ODOTTYPE:
- ok |= Erv
- n.Left = typecheck(n.Left, Erv)
+ ok |= ctxExpr
+ n.Left = typecheck(n.Left, ctxExpr)
n.Left = defaultlit(n.Left, nil)
l := n.Left
t := l.Type
}
case OINDEX:
- ok |= Erv
- n.Left = typecheck(n.Left, Erv)
+ ok |= ctxExpr
+ n.Left = typecheck(n.Left, ctxExpr)
n.Left = defaultlit(n.Left, nil)
n.Left = implicitstar(n.Left)
l := n.Left
- n.Right = typecheck(n.Right, Erv)
+ n.Right = typecheck(n.Right, ctxExpr)
r := n.Right
t := l.Type
if t == nil || r.Type == nil {
}
case ORECV:
- ok |= Etop | Erv
- n.Left = typecheck(n.Left, Erv)
+ ok |= ctxStmt | ctxExpr
+ n.Left = typecheck(n.Left, ctxExpr)
n.Left = defaultlit(n.Left, nil)
l := n.Left
t := l.Type
n.Type = t.Elem()
case OSEND:
- ok |= Etop
- n.Left = typecheck(n.Left, Erv)
- n.Right = typecheck(n.Right, Erv)
+ ok |= ctxStmt
+ n.Left = typecheck(n.Left, ctxExpr)
+ n.Right = typecheck(n.Right, ctxExpr)
n.Left = defaultlit(n.Left, nil)
t := n.Left.Type
if t == nil {
// can construct an OSLICEHEADER node.
// Components used in OSLICEHEADER that are supplied by parsed source code
// have already been typechecked in e.g. OMAKESLICE earlier.
- ok |= Erv
+ ok |= ctxExpr
t := n.Type
if t == nil {
Fatalf("expected 2 params (len, cap) for OSLICEHEADER, got %d", x)
}
- n.Left = typecheck(n.Left, Erv)
- l := typecheck(n.List.First(), Erv)
- c := typecheck(n.List.Second(), Erv)
+ n.Left = typecheck(n.Left, ctxExpr)
+ l := typecheck(n.List.First(), ctxExpr)
+ c := typecheck(n.List.Second(), ctxExpr)
l = defaultlit(l, types.Types[TINT])
c = defaultlit(c, types.Types[TINT])
n.List.SetSecond(c)
case OSLICE, OSLICE3:
- ok |= Erv
- n.Left = typecheck(n.Left, Erv)
+ ok |= ctxExpr
+ n.Left = typecheck(n.Left, ctxExpr)
low, high, max := n.SliceBounds()
hasmax := n.Op.IsSlice3()
- low = typecheck(low, Erv)
- high = typecheck(high, Erv)
- max = typecheck(max, Erv)
+ low = typecheck(low, ctxExpr)
+ high = typecheck(high, ctxExpr)
+ max = typecheck(max, ctxExpr)
n.Left = defaultlit(n.Left, nil)
low = indexlit(low)
high = indexlit(high)
n.Left = nod(OADDR, n.Left, nil)
n.Left.SetImplicit(true)
- n.Left = typecheck(n.Left, Erv)
+ n.Left = typecheck(n.Left, ctxExpr)
l = n.Left
}
t := l.Type
// call and call like
case OCALL:
- n.Left = typecheck(n.Left, Erv|Etype|Ecall)
+ n.Left = typecheck(n.Left, ctxExpr|Etype|ctxCallee)
if n.Left.Diag() {
n.SetDiag(true)
}
l := n.Left
if l.Op == ONAME && l.SubOp() != 0 {
- if n.Isddd() && l.SubOp() != OAPPEND {
+ if n.IsDDD() && l.SubOp() != OAPPEND {
yyerror("invalid use of ... with builtin %v", l)
}
n.Left = defaultlit(n.Left, nil)
l = n.Left
if l.Op == OTYPE {
- if n.Isddd() || l.Type.IsDDDArray() {
+ if n.IsDDD() || l.Type.IsDDDArray() {
if !l.Type.Broke() {
yyerror("invalid use of ... in type conversion to %v", l.Type)
}
}
// pick off before type-checking arguments
- ok |= Erv
+ ok |= ctxExpr
// turn CALL(type, arg) into CONV(arg) w/ type
n.Left = nil
return n
}
- if n.List.Len() == 1 && !n.Isddd() {
- n.List.SetFirst(typecheck(n.List.First(), Erv|Efnstruct))
+ if n.List.Len() == 1 && !n.IsDDD() {
+ n.List.SetFirst(typecheck(n.List.First(), ctxExpr|ctxMultiOK))
} else {
- typecheckslice(n.List.Slice(), Erv)
+ typecheckslice(n.List.Slice(), ctxExpr)
}
t := l.Type
if t == nil {
}
}
- typecheckaste(OCALL, n.Left, n.Isddd(), t.Params(), n.List, func() string { return fmt.Sprintf("argument to %v", n.Left) })
- ok |= Etop
+ typecheckaste(OCALL, n.Left, n.IsDDD(), t.Params(), n.List, func() string { return fmt.Sprintf("argument to %v", n.Left) })
+ ok |= ctxStmt
if t.NumResults() == 0 {
break
}
- ok |= Erv
+ ok |= ctxExpr
if t.NumResults() == 1 {
n.Type = l.Type.Results().Field(0).Type
}
// multiple return
- if top&(Efnstruct|Etop) == 0 {
+ if top&(ctxMultiOK|ctxStmt) == 0 {
yyerror("multiple-value %v() in single-value context", l)
break
}
n.Type = l.Type.Results()
case OALIGNOF, OOFFSETOF, OSIZEOF:
- ok |= Erv
+ ok |= ctxExpr
if !onearg(n, "%v", n.Op) {
n.Type = nil
return n
setintconst(n, evalunsafe(n))
case OCAP, OLEN:
- ok |= Erv
+ ok |= ctxExpr
if !onearg(n, "%v", n.Op) {
n.Type = nil
return n
}
- n.Left = typecheck(n.Left, Erv)
+ n.Left = typecheck(n.Left, ctxExpr)
n.Left = defaultlit(n.Left, nil)
n.Left = implicitstar(n.Left)
l := n.Left
}
case OREAL, OIMAG:
- ok |= Erv
+ ok |= ctxExpr
if !onearg(n, "%v", n.Op) {
n.Type = nil
return n
}
- n.Left = typecheck(n.Left, Erv)
+ n.Left = typecheck(n.Left, ctxExpr)
l := n.Left
t := l.Type
if t == nil {
}
case OCOMPLEX:
- ok |= Erv
+ ok |= ctxExpr
var r *Node
var l *Node
if n.List.Len() == 1 {
- typecheckslice(n.List.Slice(), Efnstruct)
+ typecheckslice(n.List.Slice(), ctxMultiOK)
if n.List.First().Op != OCALLFUNC && n.List.First().Op != OCALLMETH {
yyerror("invalid operation: complex expects two arguments")
n.Type = nil
n.Type = nil
return n
}
- n.Left = typecheck(n.Left, Erv)
- n.Right = typecheck(n.Right, Erv)
+ n.Left = typecheck(n.Left, ctxExpr)
+ n.Right = typecheck(n.Right, ctxExpr)
l = n.Left
r = n.Right
if l.Type == nil || r.Type == nil {
n.Type = nil
return n
}
- n.Left = typecheck(n.Left, Erv)
+ n.Left = typecheck(n.Left, ctxExpr)
n.Left = defaultlit(n.Left, nil)
l := n.Left
t := l.Type
return n
}
- ok |= Etop
+ ok |= ctxStmt
case ODELETE:
args := n.List
return n
}
- ok |= Etop
- typecheckslice(args.Slice(), Erv)
+ ok |= ctxStmt
+ typecheckslice(args.Slice(), ctxExpr)
l := args.First()
r := args.Second()
if l.Type != nil && !l.Type.IsMap() {
args.SetSecond(assignconv(r, l.Type.Key(), "delete"))
case OAPPEND:
- ok |= Erv
+ ok |= ctxExpr
args := n.List
if args.Len() == 0 {
yyerror("missing arguments to append")
return n
}
- if args.Len() == 1 && !n.Isddd() {
- args.SetFirst(typecheck(args.First(), Erv|Efnstruct))
+ if args.Len() == 1 && !n.IsDDD() {
+ args.SetFirst(typecheck(args.First(), ctxExpr|ctxMultiOK))
} else {
- typecheckslice(args.Slice(), Erv)
+ typecheckslice(args.Slice(), ctxExpr)
}
t := args.First().Type
return n
}
- if n.Isddd() {
+ if n.IsDDD() {
if args.Len() == 1 {
yyerror("cannot use ... on first argument to append")
n.Type = nil
}
case OCOPY:
- ok |= Etop | Erv
+ ok |= ctxStmt | ctxExpr
args := n.List
if args.Len() < 2 {
yyerror("missing arguments to copy")
n.Right = args.Second()
n.List.Set(nil)
n.Type = types.Types[TINT]
- n.Left = typecheck(n.Left, Erv)
- n.Right = typecheck(n.Right, Erv)
+ n.Left = typecheck(n.Left, ctxExpr)
+ n.Right = typecheck(n.Right, ctxExpr)
if n.Left.Type == nil || n.Right.Type == nil {
n.Type = nil
return n
}
case OCONV:
- ok |= Erv
+ ok |= ctxExpr
checkwidth(n.Type) // ensure width is calculated for backend
- n.Left = typecheck(n.Left, Erv)
+ n.Left = typecheck(n.Left, ctxExpr)
n.Left = convlit1(n.Left, n.Type, true, noReuse)
t := n.Left.Type
if t == nil || n.Type == nil {
// do not convert to []byte literal. See CL 125796.
// generated code and compiler memory footprint is better without it.
- case OSTRARRAYBYTE:
+ case OSTR2BYTES:
break
- case OSTRARRAYRUNE:
+ case OSTR2RUNES:
if n.Left.Op == OLITERAL {
n = stringtoruneslit(n)
}
}
case OMAKE:
- ok |= Erv
+ ok |= ctxExpr
args := n.List.Slice()
if len(args) == 0 {
yyerror("missing argument to make")
l = args[i]
i++
- l = typecheck(l, Erv)
+ l = typecheck(l, ctxExpr)
var r *Node
if i < len(args) {
r = args[i]
i++
- r = typecheck(r, Erv)
+ r = typecheck(r, ctxExpr)
}
if l.Type == nil || (r != nil && r.Type == nil) {
if i < len(args) {
l = args[i]
i++
- l = typecheck(l, Erv)
+ l = typecheck(l, ctxExpr)
l = defaultlit(l, types.Types[TINT])
if l.Type == nil {
n.Type = nil
if i < len(args) {
l = args[i]
i++
- l = typecheck(l, Erv)
+ l = typecheck(l, ctxExpr)
l = defaultlit(l, types.Types[TINT])
if l.Type == nil {
n.Type = nil
n.Type = t
case ONEW:
- ok |= Erv
+ ok |= ctxExpr
args := n.List
if args.Len() == 0 {
yyerror("missing argument to new")
n.Type = types.NewPtr(t)
case OPRINT, OPRINTN:
- ok |= Etop
- typecheckslice(n.List.Slice(), Erv)
+ ok |= ctxStmt
+ typecheckslice(n.List.Slice(), ctxExpr)
ls := n.List.Slice()
for i1, n1 := range ls {
// Special case for print: int constant is int64, not int.
}
case OPANIC:
- ok |= Etop
+ ok |= ctxStmt
if !onearg(n, "panic") {
n.Type = nil
return n
}
- n.Left = typecheck(n.Left, Erv)
+ n.Left = typecheck(n.Left, ctxExpr)
n.Left = defaultlit(n.Left, types.Types[TINTER])
if n.Left.Type == nil {
n.Type = nil
}
case ORECOVER:
- ok |= Erv | Etop
+ ok |= ctxExpr | ctxStmt
if n.List.Len() != 0 {
yyerror("too many arguments to recover")
n.Type = nil
n.Type = types.Types[TINTER]
case OCLOSURE:
- ok |= Erv
+ ok |= ctxExpr
typecheckclosure(n, top)
if n.Type == nil {
return n
}
case OITAB:
- ok |= Erv
- n.Left = typecheck(n.Left, Erv)
+ ok |= ctxExpr
+ n.Left = typecheck(n.Left, ctxExpr)
t := n.Left.Type
if t == nil {
n.Type = nil
Fatalf("cannot typecheck interface data %v", n)
case OSPTR:
- ok |= Erv
- n.Left = typecheck(n.Left, Erv)
+ ok |= ctxExpr
+ n.Left = typecheck(n.Left, ctxExpr)
t := n.Left.Type
if t == nil {
n.Type = nil
}
case OCLOSUREVAR:
- ok |= Erv
+ ok |= ctxExpr
case OCFUNC:
- ok |= Erv
- n.Left = typecheck(n.Left, Erv)
+ ok |= ctxExpr
+ n.Left = typecheck(n.Left, ctxExpr)
n.Type = types.Types[TUINTPTR]
case OCONVNOP:
- ok |= Erv
- n.Left = typecheck(n.Left, Erv)
+ ok |= ctxExpr
+ n.Left = typecheck(n.Left, ctxExpr)
// statements
case OAS:
- ok |= Etop
+ ok |= ctxStmt
typecheckas(n)
}
case OAS2:
- ok |= Etop
+ ok |= ctxStmt
typecheckas2(n)
case OBREAK,
OFALL,
OVARKILL,
OVARLIVE:
- ok |= Etop
+ ok |= ctxStmt
case OLABEL:
- ok |= Etop
+ ok |= ctxStmt
decldepth++
if n.Sym.IsBlank() {
// Empty identifier is valid but useless.
}
case ODEFER:
- ok |= Etop
- n.Left = typecheck(n.Left, Etop|Erv)
+ ok |= ctxStmt
+ n.Left = typecheck(n.Left, ctxStmt|ctxExpr)
if !n.Left.Diag() {
checkdefergo(n)
}
- case OPROC:
- ok |= Etop
- n.Left = typecheck(n.Left, Etop|Erv)
+ case OGO:
+ ok |= ctxStmt
+ n.Left = typecheck(n.Left, ctxStmt|ctxExpr)
checkdefergo(n)
case OFOR, OFORUNTIL:
- ok |= Etop
- typecheckslice(n.Ninit.Slice(), Etop)
+ ok |= ctxStmt
+ typecheckslice(n.Ninit.Slice(), ctxStmt)
decldepth++
- n.Left = typecheck(n.Left, Erv)
+ n.Left = typecheck(n.Left, ctxExpr)
n.Left = defaultlit(n.Left, nil)
if n.Left != nil {
t := n.Left.Type
yyerror("non-bool %L used as for condition", n.Left)
}
}
- n.Right = typecheck(n.Right, Etop)
+ n.Right = typecheck(n.Right, ctxStmt)
if n.Op == OFORUNTIL {
- typecheckslice(n.List.Slice(), Etop)
+ typecheckslice(n.List.Slice(), ctxStmt)
}
- typecheckslice(n.Nbody.Slice(), Etop)
+ typecheckslice(n.Nbody.Slice(), ctxStmt)
decldepth--
case OIF:
- ok |= Etop
- typecheckslice(n.Ninit.Slice(), Etop)
- n.Left = typecheck(n.Left, Erv)
+ ok |= ctxStmt
+ typecheckslice(n.Ninit.Slice(), ctxStmt)
+ n.Left = typecheck(n.Left, ctxExpr)
n.Left = defaultlit(n.Left, nil)
if n.Left != nil {
t := n.Left.Type
yyerror("non-bool %L used as if condition", n.Left)
}
}
- typecheckslice(n.Nbody.Slice(), Etop)
- typecheckslice(n.Rlist.Slice(), Etop)
+ typecheckslice(n.Nbody.Slice(), ctxStmt)
+ typecheckslice(n.Rlist.Slice(), ctxStmt)
case ORETURN:
- ok |= Etop
+ ok |= ctxStmt
if n.List.Len() == 1 {
- typecheckslice(n.List.Slice(), Erv|Efnstruct)
+ typecheckslice(n.List.Slice(), ctxExpr|ctxMultiOK)
} else {
- typecheckslice(n.List.Slice(), Erv)
+ typecheckslice(n.List.Slice(), ctxExpr)
}
if Curfn == nil {
yyerror("return outside function")
typecheckaste(ORETURN, nil, false, Curfn.Type.Results(), n.List, func() string { return "return argument" })
case ORETJMP:
- ok |= Etop
+ ok |= ctxStmt
case OSELECT:
- ok |= Etop
+ ok |= ctxStmt
typecheckselect(n)
case OSWITCH:
- ok |= Etop
+ ok |= ctxStmt
typecheckswitch(n)
case ORANGE:
- ok |= Etop
+ ok |= ctxStmt
typecheckrange(n)
case OTYPESW:
return n
case OXCASE:
- ok |= Etop
- typecheckslice(n.List.Slice(), Erv)
- typecheckslice(n.Nbody.Slice(), Etop)
+ ok |= ctxStmt
+ typecheckslice(n.List.Slice(), ctxExpr)
+ typecheckslice(n.Nbody.Slice(), ctxStmt)
case ODCLFUNC:
- ok |= Etop
+ ok |= ctxStmt
typecheckfunc(n)
case ODCLCONST:
- ok |= Etop
- n.Left = typecheck(n.Left, Erv)
+ ok |= ctxStmt
+ n.Left = typecheck(n.Left, ctxExpr)
case ODCLTYPE:
- ok |= Etop
+ ok |= ctxStmt
n.Left = typecheck(n.Left, Etype)
checkwidth(n.Left.Type)
if n.Left.Type != nil && n.Left.Type.NotInHeap() && n.Left.Name.Param.Pragma&NotInHeap == 0 {
return n
}
- if top&(Erv|Etype) == Etype && n.Op != OTYPE {
+ if top&(ctxExpr|Etype) == Etype && n.Op != OTYPE {
yyerror("%v is not a type", n)
n.Type = nil
return n
}
// TODO(rsc): simplify
- if (top&(Ecall|Erv|Etype) != 0) && top&Etop == 0 && ok&(Erv|Etype|Ecall) == 0 {
+ if (top&(ctxCallee|ctxExpr|Etype) != 0) && top&ctxStmt == 0 && ok&(ctxExpr|Etype|ctxCallee) == 0 {
yyerror("%v used as value", n)
n.Type = nil
return n
}
- if (top&Etop != 0) && top&(Ecall|Erv|Etype) == 0 && ok&Etop == 0 {
+ if (top&ctxStmt != 0) && top&(ctxCallee|ctxExpr|Etype) == 0 && ok&ctxStmt == 0 {
if !n.Diag() {
yyerror("%v evaluated but not used", n)
n.SetDiag(true)
func checkdefergo(n *Node) {
what := "defer"
- if n.Op == OPROC {
+ if n.Op == OGO {
what = "go"
}
if !t.IsArray() {
return n
}
- n = nod(OIND, n, nil)
+ n = nod(ODEREF, n, nil)
n.SetImplicit(true)
- n = typecheck(n, Erv)
+ n = typecheck(n, ctxExpr)
return n
}
}
if t.IsInterface() {
if n.Left.Type.IsPtr() {
- n.Left = nod(OIND, n.Left, nil) // implicitstar
+ n.Left = nod(ODEREF, n.Left, nil) // implicitstar
n.Left.SetImplicit(true)
- n.Left = typecheck(n.Left, Erv)
+ n.Left = typecheck(n.Left, ctxExpr)
}
n.Op = ODOTINTER
checklvalue(n.Left, "call pointer method on")
n.Left = nod(OADDR, n.Left, nil)
n.Left.SetImplicit(true)
- n.Left = typecheck(n.Left, Etype|Erv)
+ n.Left = typecheck(n.Left, Etype|ctxExpr)
} else if tt.IsPtr() && !rcvr.IsPtr() && types.Identical(tt.Elem(), rcvr) {
- n.Left = nod(OIND, n.Left, nil)
+ n.Left = nod(ODEREF, n.Left, nil)
n.Left.SetImplicit(true)
- n.Left = typecheck(n.Left, Etype|Erv)
+ n.Left = typecheck(n.Left, Etype|ctxExpr)
} else if tt.IsPtr() && tt.Elem().IsPtr() && types.Identical(derefall(tt), derefall(rcvr)) {
yyerror("calling method %v with receiver %L requires explicit dereference", n.Sym, n.Left)
for tt.IsPtr() {
if rcvr.IsPtr() && !tt.Elem().IsPtr() {
break
}
- n.Left = nod(OIND, n.Left, nil)
+ n.Left = nod(ODEREF, n.Left, nil)
n.Left.SetImplicit(true)
- n.Left = typecheck(n.Left, Etype|Erv)
+ n.Left = typecheck(n.Left, Etype|ctxExpr)
tt = tt.Elem()
}
} else {
pll := n
ll := n.Left
- for ll.Left != nil && (ll.Op == ODOT || ll.Op == ODOTPTR || ll.Op == OIND) {
+ for ll.Left != nil && (ll.Op == ODOT || ll.Op == ODOTPTR || ll.Op == ODEREF) {
pll = ll
ll = ll.Left
}
func hasddd(t *types.Type) bool {
for _, tl := range t.Fields().Slice() {
- if tl.Isddd() {
+ if tl.IsDDD() {
return true
}
}
rfs := n.Type.FieldSlice()
var why string
for i, tl := range lfs {
- if tl.Isddd() {
+ if tl.IsDDD() {
for _, tn := range rfs[i:] {
if assignop(tn.Type, tl.Type.Elem(), &why) == 0 {
if call != nil {
i = 0
for _, tl := range tstruct.Fields().Slice() {
t = tl.Type
- if tl.Isddd() {
+ if tl.IsDDD() {
if isddd {
if i >= nl.Len() {
goto notenough
norig := n.copy()
setlineno(n.Right)
- n.Right = typecheck(n.Right, Etype|Ecomplit)
+ n.Right = typecheck(n.Right, Etype|ctxCompLit)
l := n.Right // sic
t := l.Type
if t == nil {
if t.IsPtr() {
// For better or worse, we don't allow pointers as the composite literal type,
- // except when using the &T syntax, which sets implicit on the OIND.
+ // except when using the &T syntax, which sets implicit on the ODEREF.
if !n.Right.Implicit() {
yyerror("invalid pointer type %v for composite literal (use &%v instead)", t, t.Elem())
n.Type = nil
setlineno(l)
vp := &nl[i2]
if l.Op == OKEY {
- l.Left = typecheck(l.Left, Erv)
+ l.Left = typecheck(l.Left, ctxExpr)
evconst(l.Left)
i = nonnegintconst(l.Left)
if i < 0 && !l.Left.Diag() {
r := *vp
pushtype(r, t.Elem())
- r = typecheck(r, Erv)
+ r = typecheck(r, ctxExpr)
r = defaultlit(r, t.Elem())
*vp = assignconv(r, t.Elem(), "array or slice literal")
for i3, l := range n.List.Slice() {
setlineno(l)
if l.Op != OKEY {
- n.List.SetIndex(i3, typecheck(l, Erv))
+ n.List.SetIndex(i3, typecheck(l, ctxExpr))
yyerror("missing key in map literal")
continue
}
r := l.Left
pushtype(r, t.Key())
- r = typecheck(r, Erv)
+ r = typecheck(r, ctxExpr)
r = defaultlit(r, t.Key())
l.Left = assignconv(r, t.Key(), "map key")
if l.Left.Op != OCONV {
r = l.Right
pushtype(r, t.Elem())
- r = typecheck(r, Erv)
+ r = typecheck(r, ctxExpr)
r = defaultlit(r, t.Elem())
l.Right = assignconv(r, t.Elem(), "map value")
}
ls := n.List.Slice()
for i, n1 := range ls {
setlineno(n1)
- n1 = typecheck(n1, Erv)
+ n1 = typecheck(n1, ctxExpr)
ls[i] = n1
if i >= t.NumFields() {
if !errored {
// is never a valid struct literal key.
if key.Sym == nil || key.Op == OXDOT || key.Sym.IsBlank() {
yyerror("invalid field name %v in struct initializer", key)
- l.Left = typecheck(l.Left, Erv)
+ l.Left = typecheck(l.Left, ctxExpr)
continue
}
yyerror("mixture of field:value and value initializers")
errored = true
}
- ls[i] = typecheck(ls[i], Erv)
+ ls[i] = typecheck(ls[i], ctxExpr)
continue
}
l.Xoffset = f.Offset
// No pushtype allowed here. Tried and rejected.
- l.Left = typecheck(l.Left, Erv)
+ l.Left = typecheck(l.Left, ctxExpr)
l.Left = assignconv(l.Left, f.Type, "field value")
}
}
return false
}
fallthrough
- case OIND, ODOTPTR, OCLOSUREVAR:
+ case ODEREF, ODOTPTR, OCLOSUREVAR:
return true
case ODOT:
case ODOT, ODOTPTR:
return l.Sym != nil && r.Sym != nil && l.Sym == r.Sym && samesafeexpr(l.Left, r.Left)
- case OIND, OCONVNOP,
- ONOT, OCOM, OPLUS, OMINUS:
+ case ODEREF, OCONVNOP,
+ ONOT, OBITNOT, OPLUS, ONEG:
return samesafeexpr(l.Left, r.Left)
case OCONV:
n.Left = resolve(n.Left)
if n.Left.Name == nil || n.Left.Name.Defn != n || n.Left.Name.Param.Ntype != nil {
- n.Left = typecheck(n.Left, Erv|Easgn)
+ n.Left = typecheck(n.Left, ctxExpr|ctxAssign)
}
- // Use Efnstruct so we can emit an "N variables but M values" error
+ // Use ctxMultiOK so we can emit an "N variables but M values" error
// to be consistent with typecheckas2 (#26616).
- n.Right = typecheck(n.Right, Erv|Efnstruct)
+ n.Right = typecheck(n.Right, ctxExpr|ctxMultiOK)
checkassign(n, n.Left)
if n.Right != nil && n.Right.Type != nil {
if n.Right.Type.IsFuncArgStruct() {
n.SetTypecheck(1)
if n.Left.Typecheck() == 0 {
- n.Left = typecheck(n.Left, Erv|Easgn)
+ n.Left = typecheck(n.Left, ctxExpr|ctxAssign)
}
if !n.Left.isBlank() {
checkwidth(n.Left.Type) // ensure width is calculated for backend
ls[i1] = n1
if n1.Name == nil || n1.Name.Defn != n || n1.Name.Param.Ntype != nil {
- ls[i1] = typecheck(ls[i1], Erv|Easgn)
+ ls[i1] = typecheck(ls[i1], ctxExpr|ctxAssign)
}
}
cl := n.List.Len()
cr := n.Rlist.Len()
if cl > 1 && cr == 1 {
- n.Rlist.SetFirst(typecheck(n.Rlist.First(), Erv|Efnstruct))
+ n.Rlist.SetFirst(typecheck(n.Rlist.First(), ctxExpr|ctxMultiOK))
} else {
- typecheckslice(n.Rlist.Slice(), Erv)
+ typecheckslice(n.Rlist.Slice(), ctxExpr)
}
checkassignlist(n, n.List)
ls = n.List.Slice()
for i1, n1 := range ls {
if n1.Typecheck() == 0 {
- ls[i1] = typecheck(ls[i1], Erv|Easgn)
+ ls[i1] = typecheck(ls[i1], ctxExpr|ctxAssign)
}
}
}
}
}
- n.Func.Nname = typecheck(n.Func.Nname, Erv|Easgn)
+ n.Func.Nname = typecheck(n.Func.Nname, ctxExpr|ctxAssign)
t := n.Func.Nname.Type
if t == nil {
return
nn := nod(OCOMPLIT, nil, typenod(n.Type))
nn.List.Set(l)
- nn = typecheck(nn, Erv)
+ nn = typecheck(nn, ctxExpr)
return nn
}
yyerrorl(n.Pos, "xxx")
}
- e = typecheck(e, Erv)
+ e = typecheck(e, ctxExpr)
if Isconst(e, CTNIL) {
yyerrorl(n.Pos, "const initializer cannot be nil")
goto ret
}
if n.Name.Defn.Op == ONAME {
- n.Name.Defn = typecheck(n.Name.Defn, Erv)
+ n.Name.Defn = typecheck(n.Name.Defn, ctxExpr)
n.Type = n.Name.Defn.Type
break
}
- n.Name.Defn = typecheck(n.Name.Defn, Etop) // fills in n.Type
+ n.Name.Defn = typecheck(n.Name.Defn, ctxStmt) // fills in n.Type
case OTYPE:
if p := n.Name.Param; p.Alias {
okfor[ORSH] = okforand[:]
// unary
- okfor[OCOM] = okforand[:]
- okfor[OMINUS] = okforarith[:]
+ okfor[OBITNOT] = okforand[:]
+ okfor[ONEG] = okforarith[:]
okfor[ONOT] = okforbool[:]
okfor[OPLUS] = okforarith[:]
func evalunsafe(n *Node) int64 {
switch n.Op {
case OALIGNOF, OSIZEOF:
- n.Left = typecheck(n.Left, Erv)
+ n.Left = typecheck(n.Left, ctxExpr)
n.Left = defaultlit(n.Left, nil)
tr := n.Left.Type
if tr == nil {
// Remember base of selector to find it back after dot insertion.
// Since r->left may be mutated by typechecking, check it explicitly
// first to track it correctly.
- n.Left.Left = typecheck(n.Left.Left, Erv)
+ n.Left.Left = typecheck(n.Left.Left, ctxExpr)
base := n.Left.Left
- n.Left = typecheck(n.Left, Erv)
+ n.Left = typecheck(n.Left, ctxExpr)
if n.Left.Type == nil {
return 0
}
// Final typecheck for any unused variables.
for i, ln := range fn.Func.Dcl {
if ln.Op == ONAME && (ln.Class() == PAUTO || ln.Class() == PAUTOHEAP) {
- ln = typecheck(ln, Erv|Easgn)
+ ln = typecheck(ln, ctxExpr|ctxAssign)
fn.Func.Dcl[i] = ln
}
}
}
nn := nod(OAS, v.Name.Param.Heapaddr, prealloc[v])
nn.SetColas(true)
- nn = typecheck(nn, Etop)
+ nn = typecheck(nn, ctxStmt)
return walkstmt(nn)
}
case ODEFER:
Curfn.Func.SetHasDefer(true)
fallthrough
- case OPROC:
+ case OGO:
switch n.Left.Op {
case OPRINT, OPRINTN:
n.Left = wrapCall(n.Left, &n.Ninit)
}
if cl == PPARAMOUT {
if ln.isParamStackCopy() {
- ln = walkexpr(typecheck(nod(OIND, ln.Name.Param.Heapaddr, nil), Erv), nil)
+ ln = walkexpr(typecheck(nod(ODEREF, ln.Name.Param.Heapaddr, nil), ctxExpr), nil)
}
rl = append(rl, ln)
}
}
if n.Op == ONAME && n.Class() == PAUTOHEAP {
- nn := nod(OIND, n.Name.Param.Heapaddr, nil)
- nn = typecheck(nn, Erv)
+ nn := nod(ODEREF, n.Name.Param.Heapaddr, nil)
+ nn = typecheck(nn, ctxExpr)
nn = walkexpr(nn, init)
nn.Left.SetNonNil(true)
return nn
// If these return early, make sure to still call
// stringsym for constant strings.
- case ONOT, OMINUS, OPLUS, OCOM, OREAL, OIMAG, ODOTMETH, ODOTINTER,
- OIND, OSPTR, OITAB, OIDATA, OADDR:
+ case ONOT, ONEG, OPLUS, OBITNOT, OREAL, OIMAG, ODOTMETH, ODOTINTER,
+ ODEREF, OSPTR, OITAB, OIDATA, OADDR:
n.Left = walkexpr(n.Left, init)
case OEFACE, OAND, OSUB, OMUL, OADD, OOR, OXOR, OLSH, ORSH:
if n.Op == OASOP {
// Rewrite x op= y into x = x op y.
n.Right = nod(n.SubOp(), n.Left, n.Right)
- n.Right = typecheck(n.Right, Erv)
+ n.Right = typecheck(n.Right, ctxExpr)
n.Op = OAS
n.ResetAux()
case isAppendOfMake(r):
// x = append(y, make([]T, y)...)
r = extendslice(r, init)
- case r.Isddd():
+ case r.IsDDD():
r = appendslice(r, init) // also works for append(slice, string).
default:
r = walkappend(r, init, n)
ok := n.List.Second()
call := mkcall1(fn, ok.Type, init, r.Left, n1)
n = nod(OAS, ok, call)
- n = typecheck(n, Etop)
+ n = typecheck(n, ctxStmt)
// a,b = m[i]
case OAS2MAPR:
n.List.SetFirst(var_)
n = walkexpr(n, init)
init.Append(n)
- n = nod(OAS, a, nod(OIND, var_, nil))
+ n = nod(OAS, a, nod(ODEREF, var_, nil))
}
- n = typecheck(n, Etop)
+ n = typecheck(n, ctxStmt)
n = walkexpr(n, init)
case ODELETE:
case !fromType.IsInterface() && n.Esc == EscNone && fromType.Width <= 1024:
// n.Left does not escape. Use a stack temporary initialized to n.Left.
value = temp(fromType)
- init.Append(typecheck(nod(OAS, value, n.Left), Etop))
+ init.Append(typecheck(nod(OAS, value, n.Left), ctxStmt))
}
if value != nil {
// Value is identical to n.Left.
// Construct the interface directly: {type/itab, &value}.
- l := nod(OEFACE, typeword(), typecheck(nod(OADDR, value, nil), Erv))
+ l := nod(OEFACE, typeword(), typecheck(nod(OADDR, value, nil), ctxExpr))
l.Type = toType
l.SetTypecheck(n.Typecheck())
n = l
// Get the itab out of the interface.
tmp := temp(types.NewPtr(types.Types[TUINT8]))
- init.Append(nod(OAS, tmp, typecheck(nod(OITAB, c, nil), Erv)))
+ init.Append(nod(OAS, tmp, typecheck(nod(OITAB, c, nil), ctxExpr)))
// Get the type out of the itab.
- nif := nod(OIF, typecheck(nod(ONE, tmp, nodnil()), Erv), nil)
+ nif := nod(OIF, typecheck(nod(ONE, tmp, nodnil()), ctxExpr), nil)
nif.Nbody.Set1(nod(OAS, tmp, itabType(tmp)))
init.Append(nif)
dowidth(fn.Type)
call := nod(OCALL, fn, nil)
call.List.Set1(n.Left)
- call = typecheck(call, Erv)
+ call = typecheck(call, ctxExpr)
call = walkexpr(call, init)
call = safeexpr(call, init)
e := nod(OEFACE, typeword(), call)
dowidth(fn.Type)
n = nod(OCALL, fn, nil)
n.List.Set2(tab, v)
- n = typecheck(n, Erv)
+ n = typecheck(n, ctxExpr)
n = walkexpr(n, init)
case OCONV, OCONVNOP:
case OANDNOT:
n.Left = walkexpr(n.Left, init)
n.Op = OAND
- n.Right = nod(OCOM, n.Right, nil)
- n.Right = typecheck(n.Right, Erv)
+ n.Right = nod(OBITNOT, n.Right, nil)
+ n.Right = typecheck(n.Right, ctxExpr)
n.Right = walkexpr(n.Right, init)
case ODIV, OMOD:
}
n.Type = types.NewPtr(t.Elem())
n.SetNonNil(true) // mapaccess1* and mapassign always return non-nil pointers.
- n = nod(OIND, n, nil)
+ n = nod(ODEREF, n, nil)
n.Type = t.Elem()
n.SetTypecheck(1)
}
r := temp(n.Type.Elem())
r = nod(OAS, r, nil) // zero temp
- r = typecheck(r, Etop)
+ r = typecheck(r, ctxStmt)
init.Append(r)
r = nod(OADDR, r.Left, nil)
- r = typecheck(r, Erv)
+ r = typecheck(r, ctxExpr)
n = r
} else {
n = callnew(n.Type.Elem())
// var hv hmap
hv := temp(hmapType)
zero := nod(OAS, hv, nil)
- zero = typecheck(zero, Etop)
+ zero = typecheck(zero, ctxStmt)
init.Append(zero)
// h = &hv
h = nod(OADDR, hv, nil)
bv := temp(bmap(t))
zero = nod(OAS, bv, nil)
- zero = typecheck(zero, Etop)
+ zero = typecheck(zero, ctxStmt)
init.Append(zero)
// b = &bv
// h.buckets = b
bsym := hmapType.Field(5).Sym // hmap.buckets see reflect.go:hmap
na := nod(OAS, nodSym(ODOT, h, bsym), b)
- na = typecheck(na, Etop)
+ na = typecheck(na, ctxStmt)
init.Append(na)
}
}
rand := mkcall("fastrand", types.Types[TUINT32], init)
hashsym := hmapType.Field(4).Sym // hmap.hash0 see reflect.go:hmap
a := nod(OAS, nodSym(ODOT, h, hashsym), rand)
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
a = walkexpr(a, init)
init.Append(a)
n = convnop(h, t)
t = types.NewArray(t.Elem(), nonnegintconst(r)) // [r]T
var_ := temp(t)
a := nod(OAS, var_, nil) // zero temp
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
init.Append(a)
r := nod(OSLICE, var_, nil) // arr[:l]
r.SetSliceBounds(nil, l, nil)
r = conv(r, n.Type) // in case n.Type is named.
- r = typecheck(r, Erv)
+ r = typecheck(r, ctxExpr)
r = walkexpr(r, init)
n = r
} else {
m.Left.SetNonNil(true)
m.List.Set2(conv(len, types.Types[TINT]), conv(cap, types.Types[TINT]))
- m = typecheck(m, Erv)
+ m = typecheck(m, ctxExpr)
m = walkexpr(m, init)
n = m
}
// intstring(*[4]byte, rune)
n = mkcall("intstring", n.Type, init, a, conv(n.Left, types.Types[TINT64]))
- case OARRAYBYTESTR:
+ case OBYTES2STR:
a := nodnil()
if n.Esc == EscNone {
// Create temporary buffer for string on stack.
n = mkcall("slicebytetostring", n.Type, init, a, n.Left)
// slicebytetostringtmp([]byte) string;
- case OARRAYBYTESTRTMP:
+ case OBYTES2STRTMP:
n.Left = walkexpr(n.Left, init)
if !instrumenting {
- // Let the backend handle OARRAYBYTESTRTMP directly
+ // Let the backend handle OBYTES2STRTMP directly
// to avoid a function call to slicebytetostringtmp.
break
}
n = mkcall("slicebytetostringtmp", n.Type, init, n.Left)
// slicerunetostring(*[32]byte, []rune) string;
- case OARRAYRUNESTR:
+ case ORUNES2STR:
a := nodnil()
if n.Esc == EscNone {
n = mkcall("slicerunetostring", n.Type, init, a, n.Left)
- case OSTRARRAYBYTE:
+ case OSTR2BYTES:
s := n.Left
if Isconst(s, CTSTR) {
sc := s.Val().U.(string)
a = callnew(t)
}
p := temp(t.PtrTo()) // *[n]byte
- init.Append(typecheck(nod(OAS, p, a), Etop))
+ init.Append(typecheck(nod(OAS, p, a), ctxStmt))
// Copy from the static string data to the [n]byte.
if len(sc) > 0 {
as := nod(OAS,
- nod(OIND, p, nil),
- nod(OIND, convnop(nod(OSPTR, s, nil), t.PtrTo()), nil))
- as = typecheck(as, Etop)
+ nod(ODEREF, p, nil),
+ nod(ODEREF, convnop(nod(OSPTR, s, nil), t.PtrTo()), nil))
+ as = typecheck(as, ctxStmt)
as = walkstmt(as)
init.Append(as)
}
// stringtoslicebyte(*32[byte], string) []byte;
n = mkcall("stringtoslicebyte", n.Type, init, a, conv(s, types.Types[TSTRING]))
- case OSTRARRAYBYTETMP:
+ case OSTR2BYTESTMP:
// []byte(string) conversion that creates a slice
// referring to the actual string bytes.
// This conversion is handled later by the backend and
n.Left = walkexpr(n.Left, init)
// stringtoslicerune(*[32]rune, string) []rune
- case OSTRARRAYRUNE:
+ case OSTR2RUNES:
a := nodnil()
if n.Esc == EscNone {
vstat.Name.SetReadonly(true)
fixedlit(inInitFunction, initKindStatic, n, vstat, init)
n = vstat
- n = typecheck(n, Erv)
+ n = typecheck(n, ctxExpr)
break
}
var_ := temp(n.Type)
Fatalf("evconst changed Type: %v had type %v, now %v", n, t, n.Type)
}
if n.Op == OLITERAL {
- n = typecheck(n, Erv)
+ n = typecheck(n, ctxExpr)
// Emit string symbol now to avoid emitting
// any concurrently during the backend.
if s, ok := n.Val().U.(string); ok {
// deferred until all the returned values have been read.
if fncall(l, r.Type) {
tmp := temp(r.Type)
- tmp = typecheck(tmp, Erv)
+ tmp = typecheck(tmp, ctxExpr)
a := nod(OAS, l, tmp)
a = convas(a, &mm)
mm.Append(a)
}
n.List.Set(args)
n.Esc = esc
- n = typecheck(n, Erv)
+ n = typecheck(n, ctxExpr)
if n.Type == nil {
Fatalf("mkdotargslice: typecheck failed")
}
// parameter) and this is not a ... call expression,
// then assign the remaining arguments as a slice.
if nf := params.NumFields(); nf > 0 {
- if last := params.Field(nf - 1); last.Isddd() && !n.Isddd() {
+ if last := params.Field(nf - 1); last.IsDDD() && !n.IsDDD() {
tail := args[nf-1:]
slice := mkdotargslice(last.Type, tail, init, n.Right)
// Allow immediate GC.
calls = append(calls, mkcall("printunlock", nil, init))
- typecheckslice(calls, Etop)
+ typecheckslice(calls, ctxStmt)
walkexprlist(calls, init)
r := nod(OEMPTY, nil, nil)
- r = typecheck(r, Etop)
+ r = typecheck(r, ctxStmt)
r = walkexpr(r, init)
r.Ninit.Set(calls)
return r
all[i] = convas(all[i], &mapinit)
}
- case OIND, ODOTPTR:
+ case ODEREF, ODOTPTR:
l.Left = reorder3save(l.Left, all, i, &early)
}
q := temp(n.Type)
q = nod(OAS, q, n)
- q = typecheck(q, Etop)
+ q = typecheck(q, ctxStmt)
*early = append(*early, q)
return q.Left
}
OAND,
OANDNOT,
OPLUS,
- OMINUS,
- OCOM,
+ ONEG,
+ OBITNOT,
OPAREN,
OANDAND,
OOROR,
if stackcopy := v.Name.Param.Stackcopy; stackcopy != nil {
nn = append(nn, walkstmt(nod(ODCL, v, nil)))
if stackcopy.Class() == PPARAM {
- nn = append(nn, walkstmt(typecheck(nod(OAS, v, stackcopy), Etop)))
+ nn = append(nn, walkstmt(typecheck(nod(OAS, v, stackcopy), ctxStmt)))
}
}
}
continue
}
if stackcopy := v.Name.Param.Stackcopy; stackcopy != nil && stackcopy.Class() == PPARAMOUT {
- nn = append(nn, walkstmt(typecheck(nod(OAS, stackcopy, v), Etop)))
+ nn = append(nn, walkstmt(typecheck(nod(OAS, stackcopy, v), ctxStmt)))
}
}
r := nod(OCALL, fn, nil)
r.List.Set(va)
if fn.Type.NumResults() > 0 {
- r = typecheck(r, Erv|Efnstruct)
+ r = typecheck(r, ctxExpr|ctxMultiOK)
} else {
- r = typecheck(r, Etop)
+ r = typecheck(r, ctxStmt)
}
r = walkexpr(r, init)
r.Type = t
}
n = nod(OCONV, n, nil)
n.Type = t
- n = typecheck(n, Erv)
+ n = typecheck(n, ctxExpr)
return n
}
// convnop converts node n to type t using the OCONVNOP op
-// and typechecks the result with Erv.
+// and typechecks the result with ctxExpr.
func convnop(n *Node, t *types.Type) *Node {
n = nod(OCONVNOP, n, nil)
n.Type = t
- n = typecheck(n, Erv)
+ n = typecheck(n, ctxExpr)
return n
}
cat := syslook(fn)
r := nod(OCALL, cat, nil)
r.List.Set(args)
- r = typecheck(r, Erv)
+ r = typecheck(r, ctxExpr)
r = walkexpr(r, init)
r.Type = n.Type
}
ln := append(nodes.Slice(), ncopy)
- typecheckslice(ln, Etop)
+ typecheckslice(ln, ctxStmt)
walkstmtlist(ln)
init.Append(ln...)
return s
Fatalf("missing typecheck: %+v", n)
}
- if n.Op != OAPPEND || !n.Isddd() || n.List.Len() != 2 {
+ if n.Op != OAPPEND || !n.IsDDD() || n.List.Len() != 2 {
return false
}
func extendslice(n *Node, init *Nodes) *Node {
// isAppendOfMake made sure l2 fits in an int.
l2 := conv(n.List.Second().Left, types.Types[TINT])
- l2 = typecheck(l2, Erv)
+ l2 = typecheck(l2, ctxExpr)
n.List.SetSecond(l2) // walkAppendArgs expects l2 in n.List.Second().
walkAppendArgs(n, init)
nodes = append(nodes, clr.Slice()...)
}
- typecheckslice(nodes, Etop)
+ typecheckslice(nodes, ctxStmt)
walkstmtlist(nodes)
init.Append(nodes...)
return s
}
}
- typecheckslice(l, Etop)
+ typecheckslice(l, ctxStmt)
walkstmtlist(l)
init.Append(l...)
return ns
call := mkcall1(fn, nil, init, nto, nfrm, nwid)
ne.Nbody.Append(call)
- typecheckslice(l, Etop)
+ typecheckslice(l, ctxStmt)
walkstmtlist(l)
init.Append(l...)
return nlen
// eq algs take pointers
pl := temp(types.NewPtr(t))
al := nod(OAS, pl, nod(OADDR, cmpl, nil))
- al = typecheck(al, Etop)
+ al = typecheck(al, ctxStmt)
init.Append(al)
pr := temp(types.NewPtr(t))
ar := nod(OAS, pr, nod(OADDR, cmpr, nil))
- ar = typecheck(ar, Etop)
+ ar = typecheck(ar, ctxStmt)
init.Append(ar)
fn, needsize := eqfor(t)
// an expression which might panic. See issue 23837.
t := temp(cmpl.Type)
a1 := nod(OAS, t, cmpl)
- a1 = typecheck(a1, Etop)
+ a1 = typecheck(a1, ctxStmt)
a2 := nod(OAS, t, cmpr)
- a2 = typecheck(a2, Etop)
+ a2 = typecheck(a2, ctxStmt)
init.Append(a1, a2)
}
n = finishcompare(n, expr, init)
// The result of finishcompare MUST be assigned back to n, e.g.
// n.Left = finishcompare(n.Left, x, r, init)
func finishcompare(n, r *Node, init *Nodes) *Node {
- r = typecheck(r, Erv)
+ r = typecheck(r, ctxExpr)
r = conv(r, n.Type)
r = walkexpr(r, init)
return r
cmp = addinit(cmp, l.Ninit.Slice())
cmp = addinit(cmp, r.Ninit.Slice())
// Typecheck the AST rooted at cmp...
- cmp = typecheck(cmp, Erv)
+ cmp = typecheck(cmp, ctxExpr)
// ...but then reset cmp's type to match n's type.
cmp.Type = n.Type
cmp = walkexpr(cmp, init)
OADDSTR,
OADDR,
OANDAND,
- OARRAYBYTESTR,
- OARRAYRUNESTR,
- OSTRARRAYBYTE,
- OSTRARRAYRUNE,
+ OBYTES2STR,
+ ORUNES2STR,
+ OSTR2BYTES,
+ OSTR2RUNES,
OCAP,
OCOMPLIT,
OMAPLIT,
OANDNOT,
ONEW,
ONOT,
- OCOM,
+ OBITNOT,
OPLUS,
- OMINUS,
+ ONEG,
OOROR,
OPAREN,
ORUNESTR,
a := nod(n.Op, nil, nil)
a.List.Set(paramNnames(t.Type))
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
fn.Nbody.Set1(a)
funcbody()
- fn = typecheck(fn, Etop)
- typecheckslice(fn.Nbody.Slice(), Etop)
+ fn = typecheck(fn, ctxStmt)
+ typecheckslice(fn.Nbody.Slice(), ctxStmt)
xtop = append(xtop, fn)
a = nod(OCALL, nil, nil)
a.Left = fn.Func.Nname
a.List.Set(n.List.Slice())
- a = typecheck(a, Etop)
+ a = typecheck(a, ctxStmt)
a = walkexpr(a, init)
return a
}
// isRuneCount reports whether n is of the form len([]rune(string)).
// These are optimized into a call to runtime.countrunes.
func isRuneCount(n *Node) bool {
- return Debug['N'] == 0 && !instrumenting && n.Op == OLEN && n.Left.Op == OSTRARRAYRUNE
+ return Debug['N'] == 0 && !instrumenting && n.Op == OLEN && n.Left.Op == OSTR2RUNES
}
}
for i, f1 := range fs1 {
f2 := fs2[i]
- if f1.Isddd() != f2.Isddd() || !identical(f1.Type, f2.Type, cmpTags, assumedEqual) {
+ if f1.IsDDD() != f2.IsDDD() || !identical(f1.Type, f2.Type, cmpTags, assumedEqual) {
return false
}
}
}
const (
- fieldIsddd = 1 << iota // field is ... argument
+ fieldIsDDD = 1 << iota // field is ... argument
fieldBroke // broken field definition
fieldNointerface
)
-func (f *Field) Isddd() bool { return f.flags&fieldIsddd != 0 }
+func (f *Field) IsDDD() bool { return f.flags&fieldIsDDD != 0 }
func (f *Field) Broke() bool { return f.flags&fieldBroke != 0 }
func (f *Field) Nointerface() bool { return f.flags&fieldNointerface != 0 }
-func (f *Field) SetIsddd(b bool) { f.flags.set(fieldIsddd, b) }
+func (f *Field) SetIsDDD(b bool) { f.flags.set(fieldIsDDD, b) }
func (f *Field) SetBroke(b bool) { f.flags.set(fieldBroke, b) }
func (f *Field) SetNointerface(b bool) { f.flags.set(fieldNointerface, b) }
// IsVariadic reports whether function type t is variadic.
func (t *Type) IsVariadic() bool {
n := t.NumParams()
- return n > 0 && t.Params().Field(n-1).Isddd()
+ return n > 0 && t.Params().Field(n-1).IsDDD()
}
// Recv returns the receiver of function type t, if any.
for i := 0; i < len(tfs) && i < len(xfs); i++ {
ta := tfs[i]
tb := xfs[i]
- if ta.Isddd() != tb.Isddd() {
- return cmpForNe(!ta.Isddd())
+ if ta.IsDDD() != tb.IsDDD() {
+ return cmpForNe(!ta.IsDDD())
}
if c := ta.Type.cmp(tb.Type); c != CMPeq {
return c