// There may be multiple functions named "_". In those
// cases, we can't use their individual Closgens as it
// would lead to name clashes.
- if !isblank(outerfunc.Func.Nname) {
+ if !outerfunc.Func.Nname.isBlank() {
gen = &outerfunc.Func.Closgen
}
}
return vi.Int64()
}
-// Is n a Go language constant (as opposed to a compile-time constant)?
+// isGoConst reports whether n is a Go language constant (as opposed to a
+// compile-time constant).
+//
// Expressions derived from nil, like string([]byte(nil)), while they
// may be known at compile time, are not Go language constants.
// Only called for expressions known to evaluated to compile-time
// constants.
-func isgoconst(n *Node) bool {
+func (n *Node) isGoConst() bool {
if n.Orig != nil {
n = n.Orig
}
OCOMPLEX,
OREAL,
OIMAG:
- if isgoconst(n.Left) && (n.Right == nil || isgoconst(n.Right)) {
+ if n.Left.isGoConst() && (n.Right == nil || n.Right.isGoConst()) {
return true
}
case OCONV:
- if okforconst[n.Type.Etype] && isgoconst(n.Left) {
+ if okforconst[n.Type.Etype] && n.Left.isGoConst() {
return true
}
case OLEN, OCAP:
l := n.Left
- if isgoconst(l) {
+ if l.isGoConst() {
return true
}
return
}
- if isblank(n) {
+ if n.isBlank() {
return
}
declare(v, dclcontext)
v.Name.Param.Ntype = t
- if e != nil || Curfn != nil || isblank(v) {
+ if e != nil || Curfn != nil || v.isBlank() {
if Curfn != nil {
init = append(init, nod(ODCL, v, nil))
}
var nnew, nerr int
for i, n := range left {
- if isblank(n) {
+ if n.isBlank() {
continue
}
if !colasname(n) {
Fatalf("ifacedcl")
}
- if isblank(n.Left) {
+ if n.Left.isBlank() {
yyerror("methods must have a unique non-blank name")
}
}
// TODO: n->left->missing = 1;
n.Left.Op = ONAME
- if isblank(n.Left) {
+ if n.Left.isBlank() {
// Give it a name so we can assign to it during return. ~b stands for 'blank'.
// The name must be different from ~r above because if you have
// func f() (_ int)
// evaluated in curfn. For expr==nil, dst must still be examined for
// evaluations inside it (e.g *f(x) = y)
func (e *EscState) escassign(dst, src *Node, step *EscStep) {
- if isblank(dst) || dst == nil || src == nil || src.Op == ONONAME || src.Op == OXXX {
+ if dst.isBlank() || dst == nil || src == nil || src.Op == ONONAME || src.Op == OXXX {
return
}
Fatalf("Func.initLSym called twice")
}
- if nam := f.Nname; !isblank(nam) {
+ if nam := f.Nname; !nam.isBlank() {
f.lsym = nam.Sym.Linksym()
if f.Pragma&Systemstack != 0 {
f.lsym.Set(obj.AttrCFunc, true)
switch ln.Op {
case ODCLFUNC, ODCLCONST, ODCLTYPE, OEMPTY:
case OAS:
- if !isblank(ln.Left) || !candiscard(ln.Right) {
+ if !ln.Left.isBlank() || !candiscard(ln.Right) {
return true
}
default:
}
func tinlvar(t *types.Field, inlvars map[*Node]*Node) *Node {
- if asNode(t.Nname) != nil && !isblank(asNode(t.Nname)) {
+ if asNode(t.Nname) != nil && !asNode(t.Nname).isBlank() {
inlvar := inlvars[asNode(t.Nname)]
if inlvar == nil {
Fatalf("missing inlvar for %v\n", asNode(t.Nname))
for i, t := range fn.Type.Results().Fields().Slice() {
var m *Node
var mpos src.XPos
- if t != nil && asNode(t.Nname) != nil && !isblank(asNode(t.Nname)) {
+ if t != nil && asNode(t.Nname) != nil && !asNode(t.Nname).isBlank() {
mpos = asNode(t.Nname).Pos
m = inlvar(asNode(t.Nname))
m = typecheck(m, Erv)
n := p.nod(expr, OTYPESW, nil, p.expr(expr.X))
if expr.Lhs != nil {
n.Left = p.declName(expr.Lhs)
- if isblank(n.Left) {
+ if n.Left.isBlank() {
yyerror("invalid variable name %v in type switch", n.Left)
}
}
m.Right = o.copyExpr(m.Right, m.Right.Type, false)
}
fallthrough
- case instrumenting && n.Op == OAS2FUNC && !isblank(m):
+ case instrumenting && n.Op == OAS2FUNC && !m.isBlank():
t := o.newTemp(m.Type, false)
n.List.SetIndex(i, t)
a := nod(OAS, m, t)
Fatalf("orderstmt range %v", n.Type)
case TARRAY, TSLICE:
- if n.List.Len() < 2 || isblank(n.List.Second()) {
+ if n.List.Len() < 2 || n.List.Second().isBlank() {
// for i := range x will only use x once, to compute len(x).
// No need to copy it.
break
// temporary per distinct type, sharing the temp among all receives
// with that temp. Similarly one ok bool could be shared among all
// the x,ok receives. Not worth doing until there's a clear need.
- if r.Left != nil && isblank(r.Left) {
+ if r.Left != nil && r.Left.isBlank() {
r.Left = nil
}
if r.Left != nil {
n2.Ninit.Append(tmp2)
}
- if r.List.Len() != 0 && isblank(r.List.First()) {
+ if r.List.Len() != 0 && r.List.First().isBlank() {
r.List.Set(nil)
}
if r.List.Len() != 0 {
// okas creates and returns an assignment of val to ok,
// including an explicit conversion if necessary.
func okas(ok, val *Node) *Node {
- if !isblank(ok) {
+ if !ok.isBlank() {
val = conv(val, ok.Type)
}
return nod(OAS, ok, val)
tmplist := []*Node{}
left := []*Node{}
for _, l := range n.List.Slice() {
- if !isblank(l) {
+ if !l.isBlank() {
tmp := o.newTemp(l.Type, types.Haspointers(l.Type))
tmplist = append(tmplist, tmp)
left = append(left, l)
ti := 0
for ni, l := range n.List.Slice() {
- if !isblank(l) {
+ if !l.isBlank() {
n.List.SetIndex(ni, tmplist[ti])
ti++
}
// Just like as2, this also adds temporaries to ensure left-to-right assignment.
func (o *Order) okAs2(n *Node) {
var tmp1, tmp2 *Node
- if !isblank(n.List.First()) {
+ if !n.List.First().isBlank() {
typ := n.Rlist.First().Type
tmp1 = o.newTemp(typ, types.Haspointers(typ))
}
- if !isblank(n.List.Second()) {
+ if !n.List.Second().isBlank() {
tmp2 = o.newTemp(types.Types[TBOOL], false)
}
// "if the second iteration variable is the blank identifier, the range
// clause is equivalent to the same clause with only the first variable
// present."
- if isblank(v2) {
+ if v2.isBlank() {
if v1 != nil {
n.List.Set1(v1)
}
v2 = n.List.Second()
}
- if isblank(v2) {
+ if v2.isBlank() {
v2 = nil
}
- if isblank(v1) && v2 == nil {
+ if v1.isBlank() && v2 == nil {
v1 = nil
}
return false
}
elemsize := n.Type.Elem().Width
- if elemsize <= 0 || !iszero(stmt.Right) {
+ if elemsize <= 0 || !isZero(stmt.Right) {
return false
}
switch n.Class() {
case PEXTERN, PFUNC:
default:
- if isblank(n) && n.Name.Curfn == nil && n.Name.Defn != nil && n.Name.Defn.Initorder() == InitNotStarted {
+ if n.isBlank() && n.Name.Curfn == nil && n.Name.Defn != nil && n.Name.Defn.Initorder() == InitNotStarted {
// blank names initialization is part of init() but not
// when they are inside a function.
break
Dump("defn", defn)
Fatalf("init1: bad defn")
}
- if isblank(defn.Left) && candiscard(defn.Right) {
+ if defn.Left.isBlank() && candiscard(defn.Right) {
defn.Op = OEMPTY
defn.Left = nil
defn.Right = nil
if Debug['j'] != 0 {
fmt.Printf("%v\n", n.Sym)
}
- if isblank(n) || !staticinit(n, out) {
+ if n.isBlank() || !staticinit(n, out) {
if Debug['%'] != 0 {
Dump("nonstatic", defn)
}
return true
case OLITERAL:
- if iszero(r) {
+ if isZero(r) {
return true
}
gdata(l, r, int(l.Type.Width))
return staticcopy(l, r, out)
case OLITERAL:
- if iszero(r) {
+ if isZero(r) {
return true
}
gdata(l, r, int(l.Type.Width))
return n
}
-func isliteral(n *Node) bool {
+func isLiteral(n *Node) bool {
// Treat nils as zeros rather than literals.
return n.Op == OLITERAL && n.Val().Ctype() != CTNIL
}
func getdyn(n *Node, top bool) initGenType {
switch n.Op {
default:
- if isliteral(n) {
+ if isLiteral(n) {
return initConst
}
return initDynamic
continue
}
- islit := isliteral(value)
+ islit := isLiteral(value)
if (kind == initKindStatic && !islit) || (kind == initKindDynamic && islit) {
continue
}
continue
}
- if isliteral(value) {
+ if isLiteral(value) {
continue
}
func addvalue(p *InitPlan, xoffset int64, n *Node) {
// special case: zero can be dropped entirely
- if iszero(n) {
+ if isZero(n) {
return
}
p.E = append(p.E, InitEntry{Xoffset: xoffset, Expr: n})
}
-func iszero(n *Node) bool {
+func isZero(n *Node) bool {
switch n.Op {
case OLITERAL:
switch u := n.Val().U.(type) {
default:
Dump("unexpected literal", n)
- Fatalf("iszero")
+ Fatalf("isZero")
case *NilVal:
return true
case string:
if n1.Op == OKEY {
n1 = n1.Right
}
- if !iszero(n1) {
+ if !isZero(n1) {
return false
}
}
case OSTRUCTLIT:
for _, n1 := range n.List.Slice() {
- if !iszero(n1.Left) {
+ if !isZero(n1.Left) {
return false
}
}
// All literals with nonzero fields have already been
// rewritten during walk. Any that remain are just T{}
// or equivalents. Use the zero value.
- if !iszero(rhs) {
+ if !isZero(rhs) {
Fatalf("literal with nonzero value in SSA: %v", rhs)
}
rhs = nil
}
}
- if isblank(n.Left) {
+ if n.Left.isBlank() {
// _ = rhs
// Just evaluate rhs for side-effects.
if rhs != nil {
// All literals with nonzero fields have already been
// rewritten during walk. Any that remain are just T{}
// or equivalents. Use the zero value.
- if !iszero(n.Left) {
+ if !isZero(n.Left) {
Fatalf("literal with nonzero value in SSA: %v", n.Left)
}
return s.zeroVal(n.Type)
// All literals with nonzero fields have already been
// rewritten during walk. Any that remain are just T{}
// or equivalents. Use the zero value.
- if !iszero(n) {
+ if !isZero(n) {
Fatalf("literal with nonzero value in SSA: %v", n)
}
return s.zeroVal(n.Type)
// If deref is true and right == nil, just do left = 0.
// skip indicates assignments (at the top level) that can be avoided.
func (s *state) assign(left *Node, right *ssa.Value, deref bool, skip skipMask) {
- if left.Op == ONAME && isblank(left) {
+ if left.Op == ONAME && left.isBlank() {
return
}
t := left.Type
}
}
-// isnil reports whether n represents the universal untyped zero value "nil".
-func isnil(n *Node) bool {
+// isNil reports whether n represents the universal untyped zero value "nil".
+func (n *Node) isNil() bool {
// Check n.Orig because constant propagation may produce typed nil constants,
// which don't exist in the Go spec.
return Isconst(n.Orig, CTNIL)
return true
}
-func isblank(n *Node) bool {
+func (n *Node) isBlank() bool {
if n == nil {
return false
}
if t != nil && !t.IsInterface() {
yyerrorl(n.Pos, "cannot type switch on non-interface value %L", n.Left.Right)
}
- if v := n.Left.Left; v != nil && !isblank(v) && n.List.Len() == 0 {
+ if v := n.Left.Left; v != nil && !v.isBlank() && n.List.Len() == 0 {
// We don't actually declare the type switch's guarded
// declaration itself. So if there are no cases, we
// won't notice that it went unused.
} else {
yyerrorl(ncase.Pos, "invalid case %v in switch (mismatched types %v and bool)", n1, n1.Type)
}
- case nilonly != "" && !isnil(n1):
+ case nilonly != "" && !n1.isNil():
yyerrorl(ncase.Pos, "invalid case %v in switch (can only compare %s %v to nil)", n1, nilonly, n.Left)
case t.IsInterface() && !n1.Type.IsInterface() && !IsComparable(n1.Type):
yyerrorl(ncase.Pos, "invalid case %L in switch (incomparable type)", n1)
if top&Easgn == 0 {
// not a write to the variable
- if isblank(n) {
+ if n.isBlank() {
yyerror("cannot use _ as value")
n.Type = nil
return n
return n
}
- if l.Type.IsSlice() && !isnil(l) && !isnil(r) {
+ if l.Type.IsSlice() && !l.isNil() && !r.isNil() {
yyerror("invalid operation: %v (slice can only be compared to nil)", n)
n.Type = nil
return n
}
- if l.Type.IsMap() && !isnil(l) && !isnil(r) {
+ if l.Type.IsMap() && !l.isNil() && !r.isNil() {
yyerror("invalid operation: %v (map can only be compared to nil)", n)
n.Type = nil
return n
}
- if l.Type.Etype == TFUNC && !isnil(l) && !isnil(r) {
+ if l.Type.Etype == TFUNC && !l.isNil() && !r.isNil() {
yyerror("invalid operation: %v (func can only be compared to nil)", n)
n.Type = nil
return n
if n.Left.Typecheck() == 0 {
n.Left = typecheck(n.Left, Erv|Easgn)
}
- if !isblank(n.Left) {
+ if !n.Left.isBlank() {
checkwidth(n.Left.Type) // ensure width is calculated for backend
}
}
goto ret
}
- if e.Type != nil && e.Op != OLITERAL || !isgoconst(e) {
+ if e.Type != nil && e.Op != OLITERAL || !e.isGoConst() {
if !e.Diag() {
yyerror("const initializer %v is not a constant", e)
e.SetDiag(true)
break
}
- if !instrumenting && iszero(n.Right) {
+ if !instrumenting && isZero(n.Right) {
break
}
walkexprlistsafe(n.List.Slice(), init)
r.Left = walkexpr(r.Left, init)
var n1 *Node
- if isblank(n.List.First()) {
+ if n.List.First().isBlank() {
n1 = nodnil()
} else {
n1 = nod(OADDR, n.List.First(), nil)
// mapaccess2* returns a typed bool, but due to spec changes,
// the boolean result of i.(T) is now untyped so we make it the
// same type as the variable on the lhs.
- if ok := n.List.Second(); !isblank(ok) && ok.Type.IsBoolean() {
+ if ok := n.List.Second(); !ok.isBlank() && ok.Type.IsBoolean() {
r.Type.Field(1).Type = ok.Type
}
n.Rlist.Set1(r)
n.Op = OAS2FUNC
// don't generate a = *var if a is _
- if !isblank(a) {
+ if !a.isBlank() {
var_ := temp(types.NewPtr(t.Val()))
var_.SetTypecheck(1)
var_.SetNonNil(true) // mapaccess always returns a non-nil pointer
n.Left = walkexpr(n.Left, init)
low, high, max := n.SliceBounds()
low = walkexpr(low, init)
- if low != nil && iszero(low) {
+ if low != nil && isZero(low) {
// Reduce x[0:j] to x[:j] and x[0:j:k] to x[:j:k].
low = nil
}
var nn, mm Nodes
for i, l := range nl.Slice() {
- if isblank(l) {
+ if l.isBlank() {
continue
}
r := nr.Field(i)
// Rewrite argument named _ to __,
// or else the assignment to _ will be
// discarded during code generation.
- if isblank(n) {
+ if n.isBlank() {
n.Sym = lookup("__")
}
return n
}
- if isblank(n.Left) {
+ if n.Left.isBlank() {
n.Right = defaultlit(n.Right, nil)
return n
}