cmd/compile: use t.IsFoo() instead of Isfoo[t.Etype]
This allows us to get rid of Isptr and Issigned. Still some code to
clean up for Isint, Isfloat, and Iscomplex.
CL produced mechanically using gofmt -w -r.
Passes toolstash -cmp.
Change-Id: If4f807bb7f2b357288d2547be2380eb511875786
Reviewed-on: https://go-review.googlesource.com/21339
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
diff --git a/src/cmd/compile/internal/gc/bexport.go b/src/cmd/compile/internal/gc/bexport.go
index 24812ab..22de0a6 100644
--- a/src/cmd/compile/internal/gc/bexport.go
+++ b/src/cmd/compile/internal/gc/bexport.go
@@ -635,7 +635,7 @@
func basetypeName(t *Type) string {
s := t.Sym
- if s == nil && Isptr[t.Etype] {
+ if s == nil && t.IsPtr() {
s = t.Elem().Sym // deref
}
if s != nil {
diff --git a/src/cmd/compile/internal/gc/bimport.go b/src/cmd/compile/internal/gc/bimport.go
index 0ecd15a..65eec96 100644
--- a/src/cmd/compile/internal/gc/bimport.go
+++ b/src/cmd/compile/internal/gc/bimport.go
@@ -361,7 +361,7 @@
} else {
// anonymous field - typ must be T or *T and T must be a type name
s := typ.Sym
- if s == nil && Isptr[typ.Etype] {
+ if s == nil && typ.IsPtr() {
s = typ.Type.Sym // deref
}
pkg := importpkg
@@ -491,7 +491,7 @@
case floatTag:
f := newMpflt()
p.float(f)
- if typ == idealint || Isint[typ.Etype] {
+ if typ == idealint || typ.IsInteger() {
// uncommon case: large int encoded as float
u := new(Mpint)
u.SetFloat(f)
diff --git a/src/cmd/compile/internal/gc/cgen.go b/src/cmd/compile/internal/gc/cgen.go
index 5d84f14..d9c37df 100644
--- a/src/cmd/compile/internal/gc/cgen.go
+++ b/src/cmd/compile/internal/gc/cgen.go
@@ -127,7 +127,7 @@
f = false
}
- if !Iscomplex[n.Type.Etype] && Ctxt.Arch.Regsize == 8 && !wb {
+ if !n.Type.IsComplex() && Ctxt.Arch.Regsize == 8 && !wb {
a := Thearch.Optoas(OAS, res.Type)
var addr obj.Addr
if Thearch.Sudoaddable(a, res, &addr) {
@@ -206,7 +206,7 @@
if Ctxt.Arch.Thechar == '5' { // TODO(rsc): Maybe more often?
// if both are addressable, move
if n.Addable && res.Addable {
- if Is64(n.Type) || Is64(res.Type) || n.Op == OREGISTER || res.Op == OREGISTER || Iscomplex[n.Type.Etype] || Iscomplex[res.Type.Etype] {
+ if Is64(n.Type) || Is64(res.Type) || n.Op == OREGISTER || res.Op == OREGISTER || n.Type.IsComplex() || res.Type.IsComplex() {
Thearch.Gmove(n, res)
} else {
var n1 Node
@@ -268,7 +268,7 @@
}
// if n is sudoaddable generate addr and move
- if Ctxt.Arch.Thechar == '5' && !Is64(n.Type) && !Is64(res.Type) && !Iscomplex[n.Type.Etype] && !Iscomplex[res.Type.Etype] {
+ if Ctxt.Arch.Thechar == '5' && !Is64(n.Type) && !Is64(res.Type) && !n.Type.IsComplex() && !res.Type.IsComplex() {
a := Thearch.Optoas(OAS, n.Type)
var addr obj.Addr
if Thearch.Sudoaddable(a, n, &addr) {
@@ -329,12 +329,12 @@
}
}
- if Thearch.Cgen_float != nil && nl != nil && Isfloat[n.Type.Etype] && Isfloat[nl.Type.Etype] {
+ if Thearch.Cgen_float != nil && nl != nil && n.Type.IsFloat() && nl.Type.IsFloat() {
Thearch.Cgen_float(n, res)
return
}
- if !Iscomplex[n.Type.Etype] && Ctxt.Arch.Regsize == 8 {
+ if !n.Type.IsComplex() && Ctxt.Arch.Regsize == 8 {
a := Thearch.Optoas(OAS, n.Type)
var addr obj.Addr
if Thearch.Sudoaddable(a, n, &addr) {
@@ -388,7 +388,7 @@
return
case OMINUS:
- if Isfloat[nl.Type.Etype] {
+ if nl.Type.IsFloat() {
nr = Nodintconst(-1)
nr = convlit(nr, n.Type)
a = Thearch.Optoas(OMUL, nl.Type)
@@ -470,14 +470,14 @@
Regalloc(&n1, nl.Type, res)
Thearch.Gmove(nl, &n1)
} else {
- if n.Type.Width > int64(Widthptr) || Is64(nl.Type) || Isfloat[nl.Type.Etype] {
+ if n.Type.Width > int64(Widthptr) || Is64(nl.Type) || nl.Type.IsFloat() {
Tempname(&n1, nl.Type)
} else {
Regalloc(&n1, nl.Type, res)
}
Cgen(nl, &n1)
}
- if n.Type.Width > int64(Widthptr) || Is64(n.Type) || Isfloat[n.Type.Etype] {
+ if n.Type.Width > int64(Widthptr) || Is64(n.Type) || n.Type.IsFloat() {
Tempname(&n2, n.Type)
} else {
Regalloc(&n2, n.Type, nil)
@@ -653,7 +653,7 @@
cgen_callret(n, res)
case OMOD, ODIV:
- if Isfloat[n.Type.Etype] || Thearch.Dodiv == nil {
+ if n.Type.IsFloat() || Thearch.Dodiv == nil {
a = Thearch.Optoas(n.Op, nl.Type)
goto abop
}
@@ -904,7 +904,7 @@
Tempname(n1, n.Type)
Cgen(n, n1)
- if n.Type.Width <= int64(Widthptr) || Isfloat[n.Type.Etype] {
+ if n.Type.Width <= int64(Widthptr) || n.Type.IsFloat() {
n2 := *n1
Regalloc(n1, n.Type, rg)
Thearch.Gmove(&n2, n1)
@@ -1215,7 +1215,7 @@
// i is in register n1, extend to 32 bits.
t := Types[TUINT32]
- if Issigned[n1.Type.Etype] {
+ if n1.Type.IsSigned() {
t = Types[TINT32]
}
@@ -1395,7 +1395,7 @@
// type of the index
t := Types[TUINT64]
- if Issigned[n1.Type.Etype] {
+ if n1.Type.IsSigned() {
t = Types[TINT64]
}
@@ -1690,10 +1690,10 @@
// Could do the same for slice except that we need
// to use the real index for the bounds checking.
case OINDEX:
- if n.Left.Type.IsArray() || (Isptr[n.Left.Type.Etype] && n.Left.Left.Type.IsArray()) {
+ if n.Left.Type.IsArray() || (n.Left.Type.IsPtr() && n.Left.Left.Type.IsArray()) {
if Isconst(n.Right, CTINT) {
// Compute &a.
- if !Isptr[n.Left.Type.Etype] {
+ if !n.Left.Type.IsPtr() {
Igen(n.Left, a, res)
} else {
var n1 Node
@@ -1798,7 +1798,7 @@
Genlist(n.Ninit)
}
- if Thearch.Bgen_float != nil && n.Left != nil && Isfloat[n.Left.Type.Etype] {
+ if Thearch.Bgen_float != nil && n.Left != nil && n.Left.Type.IsFloat() {
if genval {
bvgenjump(n, res, wantTrue, false)
return
@@ -1916,7 +1916,7 @@
op := n.Op
if !wantTrue {
- if Isfloat[nr.Type.Etype] {
+ if nr.Type.IsFloat() {
// Brcom is not valid on floats when NaN is involved.
ll := n.Ninit // avoid re-genning Ninit
n.Ninit.Set(nil)
@@ -1972,7 +1972,7 @@
return
}
- if Iscomplex[nl.Type.Etype] {
+ if nl.Type.IsComplex() {
complexbool(op, nl, nr, res, wantTrue, likely, to)
return
}
@@ -2044,7 +2044,7 @@
l, r := nl, nr
// On x86, only < and <= work right with NaN; reverse if needed
- if Ctxt.Arch.Thechar == '6' && Isfloat[nl.Type.Etype] && (op == OGT || op == OGE) {
+ if Ctxt.Arch.Thechar == '6' && nl.Type.IsFloat() && (op == OGT || op == OGE) {
l, r = r, l
op = Brrev(op)
}
@@ -2061,7 +2061,7 @@
// Handle floating point special cases.
// Note that 8g has Bgen_float and is handled above.
- if Isfloat[nl.Type.Etype] {
+ if nl.Type.IsFloat() {
switch Ctxt.Arch.Thechar {
case '5':
if genval {
@@ -2195,7 +2195,7 @@
case ODOT:
t := n.Left.Type
- if Isptr[t.Etype] {
+ if t.IsPtr() {
break
}
off := stkof(n.Left)
@@ -2220,7 +2220,7 @@
case OCALLMETH, OCALLINTER, OCALLFUNC:
t := n.Left.Type
- if Isptr[t.Etype] {
+ if t.IsPtr() {
t = t.Elem()
}
@@ -2575,7 +2575,7 @@
// res = &return value from call.
func cgen_aret(n *Node, res *Node) {
t := n.Left.Type
- if Isptr[t.Etype] {
+ if t.IsPtr() {
t = t.Elem()
}
diff --git a/src/cmd/compile/internal/gc/closure.go b/src/cmd/compile/internal/gc/closure.go
index 738a83a..1c5c5eb 100644
--- a/src/cmd/compile/internal/gc/closure.go
+++ b/src/cmd/compile/internal/gc/closure.go
@@ -489,7 +489,7 @@
p = fmt.Sprintf("(%v).(%v)-fm", Tconv(rcvrtype, FmtLeft|FmtShort), Sconv(meth, FmtLeft))
}
basetype := rcvrtype
- if Isptr[rcvrtype.Etype] {
+ if rcvrtype.IsPtr() {
basetype = basetype.Elem()
}
if !basetype.IsInterface() && basetype.Sym == nil {
@@ -582,7 +582,7 @@
ptr.Xoffset = 0
xfunc.Func.Dcl = append(xfunc.Func.Dcl, ptr)
var body []*Node
- if Isptr[rcvrtype.Etype] || rcvrtype.IsInterface() {
+ if rcvrtype.IsPtr() || rcvrtype.IsInterface() {
ptr.Name.Param.Ntype = typenod(rcvrtype)
body = append(body, Nod(OAS, ptr, cv))
} else {
diff --git a/src/cmd/compile/internal/gc/const.go b/src/cmd/compile/internal/gc/const.go
index e93c3f9..af75580 100644
--- a/src/cmd/compile/internal/gc/const.go
+++ b/src/cmd/compile/internal/gc/const.go
@@ -162,7 +162,7 @@
if t != nil && t.Etype == TIDEAL && n.Val().Ctype() != CTINT {
n.SetVal(toint(n.Val()))
}
- if t != nil && !Isint[t.Etype] {
+ if t != nil && !t.IsInteger() {
Yyerror("invalid operation: %v (shift of type %v)", n, t)
t = nil
}
@@ -421,7 +421,7 @@
func doesoverflow(v Val, t *Type) bool {
switch v.Ctype() {
case CTINT, CTRUNE:
- if !Isint[t.Etype] {
+ if !t.IsInteger() {
Fatalf("overflow: %v integer constant", t)
}
if v.U.(*Mpint).Cmp(Minintval[t.Etype]) < 0 || v.U.(*Mpint).Cmp(Maxintval[t.Etype]) > 0 {
@@ -429,7 +429,7 @@
}
case CTFLT:
- if !Isfloat[t.Etype] {
+ if !t.IsFloat() {
Fatalf("overflow: %v floating-point constant", t)
}
if v.U.(*Mpflt).Cmp(minfltval[t.Etype]) <= 0 || v.U.(*Mpflt).Cmp(maxfltval[t.Etype]) >= 0 {
@@ -437,7 +437,7 @@
}
case CTCPLX:
- if !Iscomplex[t.Etype] {
+ if !t.IsComplex() {
Fatalf("overflow: %v complex constant", t)
}
if v.U.(*Mpcplx).Real.Cmp(minfltval[t.Etype]) <= 0 || v.U.(*Mpcplx).Real.Cmp(maxfltval[t.Etype]) >= 0 || v.U.(*Mpcplx).Imag.Cmp(minfltval[t.Etype]) <= 0 || v.U.(*Mpcplx).Imag.Cmp(maxfltval[t.Etype]) >= 0 {
@@ -773,7 +773,7 @@
nr = defaultlit(nr, Types[TUINT])
n.Right = nr
- if nr.Type != nil && (Issigned[nr.Type.Etype] || !Isint[nr.Type.Etype]) {
+ if nr.Type != nil && (nr.Type.IsSigned() || !nr.Type.IsInteger()) {
goto illegal
}
if nl.Val().Ctype() != CTRUNE {
@@ -1332,13 +1332,13 @@
// in the case of an untyped non-constant value, like 1<<i.
v1 := n.Val()
if t != nil {
- if Isint[t.Etype] {
+ if t.IsInteger() {
t1 = t
v1 = toint(n.Val())
- } else if Isfloat[t.Etype] {
+ } else if t.IsFloat() {
t1 = t
v1 = toflt(n.Val())
- } else if Iscomplex[t.Etype] {
+ } else if t.IsComplex() {
t1 = t
v1 = tocplx(n.Val())
}
@@ -1683,7 +1683,7 @@
// function calls or channel receive operations.
t := l.Type
- if t != nil && Isptr[t.Etype] {
+ if t != nil && t.IsPtr() {
t = t.Elem()
}
if t != nil && t.IsArray() && !hascallchan(l) {
diff --git a/src/cmd/compile/internal/gc/cplx.go b/src/cmd/compile/internal/gc/cplx.go
index 4d89fb7..b0fa70b 100644
--- a/src/cmd/compile/internal/gc/cplx.go
+++ b/src/cmd/compile/internal/gc/cplx.go
@@ -229,20 +229,20 @@
n.SetVal(Val{fval})
n.Type = t
- if !Isfloat[t.Etype] {
+ if !t.IsFloat() {
Fatalf("nodfconst: bad type %v", t)
}
}
func Complexop(n *Node, res *Node) bool {
if n != nil && n.Type != nil {
- if Iscomplex[n.Type.Etype] {
+ if n.Type.IsComplex() {
goto maybe
}
}
if res != nil && res.Type != nil {
- if Iscomplex[res.Type.Etype] {
+ if res.Type.IsComplex() {
goto maybe
}
}
diff --git a/src/cmd/compile/internal/gc/dcl.go b/src/cmd/compile/internal/gc/dcl.go
index 9be0b14..f107a4e 100644
--- a/src/cmd/compile/internal/gc/dcl.go
+++ b/src/cmd/compile/internal/gc/dcl.go
@@ -715,14 +715,14 @@
return
}
- if t.Sym == nil && Isptr[t.Etype] {
+ if t.Sym == nil && t.IsPtr() {
t = t.Elem()
if t.IsInterface() {
Yyerror("embedded type cannot be a pointer to interface")
}
}
- if Isptr[t.Etype] {
+ if t.IsPtr() {
Yyerror("embedded type cannot be a pointer")
} else if t.Etype == TFORW && t.Embedlineno == 0 {
t.Embedlineno = lineno
@@ -1017,7 +1017,7 @@
return false
}
t := rcvr.Type
- if !Isptr[t.Etype] {
+ if !t.IsPtr() {
return false
}
t = t.Elem()
@@ -1075,7 +1075,7 @@
goto bad
}
s = t.Sym
- if s == nil && Isptr[t.Etype] {
+ if s == nil && t.IsPtr() {
t = t.Elem()
if t == nil {
goto bad
@@ -1103,13 +1103,13 @@
}
if (spkg == nil || nsym.Pkg != spkg) && !exportname(nsym.Name) {
- if t0.Sym == nil && Isptr[t0.Etype] {
+ if t0.Sym == nil && t0.IsPtr() {
p = fmt.Sprintf("(%v).%s.%s%s", Tconv(t0, FmtLeft|FmtShort), nsym.Pkg.Prefix, nsym.Name, suffix)
} else {
p = fmt.Sprintf("%v.%s.%s%s", Tconv(t0, FmtLeft|FmtShort), nsym.Pkg.Prefix, nsym.Name, suffix)
}
} else {
- if t0.Sym == nil && Isptr[t0.Etype] {
+ if t0.Sym == nil && t0.IsPtr() {
p = fmt.Sprintf("(%v).%s%s", Tconv(t0, FmtLeft|FmtShort), nsym.Name, suffix)
} else {
p = fmt.Sprintf("%v.%s%s", Tconv(t0, FmtLeft|FmtShort), nsym.Name, suffix)
@@ -1192,7 +1192,7 @@
return
}
if t != nil {
- if Isptr[t.Etype] {
+ if t.IsPtr() {
if t.Sym != nil {
Yyerror("invalid receiver type %v (%v is a pointer type)", pa, t)
return
@@ -1209,7 +1209,7 @@
return
}
- if Isptr[t.Etype] {
+ if t.IsPtr() {
Yyerror("invalid receiver type %v (%v is a pointer type)", pa, t)
return
}
diff --git a/src/cmd/compile/internal/gc/esc.go b/src/cmd/compile/internal/gc/esc.go
index e73649c..e6f543f 100644
--- a/src/cmd/compile/internal/gc/esc.go
+++ b/src/cmd/compile/internal/gc/esc.go
@@ -697,7 +697,7 @@
// it is also a dereference, because it is implicitly
// dereferenced (see #12588)
if n.Type.IsArray() &&
- !(Isptr[n.Right.Type.Etype] && Eqtype(n.Right.Type.Elem(), n.Type)) {
+ !(n.Right.Type.IsPtr() && Eqtype(n.Right.Type.Elem(), n.Type)) {
escassignNilWhy(e, n.List.Second(), n.Right, "range")
} else {
escassignDereference(e, n.List.Second(), n.Right, e.stepAssign(nil, n.List.Second(), n.Right, "range-deref"))
diff --git a/src/cmd/compile/internal/gc/export.go b/src/cmd/compile/internal/gc/export.go
index 8e4cc3e8..ce86fa0 100644
--- a/src/cmd/compile/internal/gc/export.go
+++ b/src/cmd/compile/internal/gc/export.go
@@ -149,7 +149,7 @@
t := n.Left.Type
if t != Types[t.Etype] && t != idealbool && t != idealstring {
- if Isptr[t.Etype] {
+ if t.IsPtr() {
t = t.Elem()
}
if t != nil && t.Sym != nil && t.Sym.Def != nil && !exportedsym(t.Sym) {
@@ -163,7 +163,7 @@
case OLITERAL:
t := n.Type
if t != Types[n.Type.Etype] && t != idealbool && t != idealstring {
- if Isptr[t.Etype] {
+ if t.IsPtr() {
t = t.Elem()
}
if t != nil && t.Sym != nil && t.Sym.Def != nil && !exportedsym(t.Sym) {
diff --git a/src/cmd/compile/internal/gc/fmt.go b/src/cmd/compile/internal/gc/fmt.go
index 7f7b20a..b6136b2 100644
--- a/src/cmd/compile/internal/gc/fmt.go
+++ b/src/cmd/compile/internal/gc/fmt.go
@@ -1095,7 +1095,7 @@
if n.Type != nil && n.Type.Etype != TIDEAL && n.Type.Etype != TNIL && n.Type != idealbool && n.Type != idealstring {
// Need parens when type begins with what might
// be misinterpreted as a unary operator: * or <-.
- if Isptr[n.Type.Etype] || (n.Type.IsChan() && n.Type.Chan == Crecv) {
+ if n.Type.IsPtr() || (n.Type.IsChan() && n.Type.Chan == Crecv) {
return fmt.Sprintf("(%v)(%v)", n.Type, Vconv(n.Val(), 0))
} else {
return fmt.Sprintf("%v(%v)", n.Type, Vconv(n.Val(), 0))
@@ -1118,7 +1118,7 @@
// but for export, this should be rendered as (*pkg.T).meth.
// These nodes have the special property that they are names with a left OTYPE and a right ONAME.
if fmtmode == FExp && n.Left != nil && n.Left.Op == OTYPE && n.Right != nil && n.Right.Op == ONAME {
- if Isptr[n.Left.Type.Etype] {
+ if n.Left.Type.IsPtr() {
return fmt.Sprintf("(%v).%v", n.Left.Type, Sconv(n.Right.Sym, FmtShort|FmtByte))
} else {
return fmt.Sprintf("%v.%v", n.Left.Type, Sconv(n.Right.Sym, FmtShort|FmtByte))
@@ -1181,7 +1181,7 @@
return fmt.Sprintf("%v { %v }", n.Type, n.Name.Param.Closure.Nbody)
case OCOMPLIT:
- ptrlit := n.Right != nil && n.Right.Implicit && n.Right.Type != nil && Isptr[n.Right.Type.Etype]
+ ptrlit := n.Right != nil && n.Right.Implicit && n.Right.Type != nil && n.Right.Type.IsPtr()
if fmtmode == FErr {
if n.Right != nil && n.Right.Type != nil && !n.Implicit {
if ptrlit {
diff --git a/src/cmd/compile/internal/gc/gen.go b/src/cmd/compile/internal/gc/gen.go
index 37db6d7..1de63ae 100644
--- a/src/cmd/compile/internal/gc/gen.go
+++ b/src/cmd/compile/internal/gc/gen.go
@@ -1078,7 +1078,7 @@
nodl.Type = t
nodl.Xoffset = lbase + offset
nodr.Type = t
- if Isfloat[t.Etype] {
+ if t.IsFloat() {
// TODO(rsc): Cache zero register like we do for integers?
Clearslim(&nodl)
} else {
diff --git a/src/cmd/compile/internal/gc/go.go b/src/cmd/compile/internal/gc/go.go
index b9fc815..117836d 100644
--- a/src/cmd/compile/internal/gc/go.go
+++ b/src/cmd/compile/internal/gc/go.go
@@ -277,12 +277,10 @@
var Simtype [NTYPE]EType
var (
- Isptr [NTYPE]bool
isforw [NTYPE]bool
Isint [NTYPE]bool
Isfloat [NTYPE]bool
Iscomplex [NTYPE]bool
- Issigned [NTYPE]bool
issimple [NTYPE]bool
)
diff --git a/src/cmd/compile/internal/gc/inl.go b/src/cmd/compile/internal/gc/inl.go
index e5b02c4..292113a 100644
--- a/src/cmd/compile/internal/gc/inl.go
+++ b/src/cmd/compile/internal/gc/inl.go
@@ -38,7 +38,7 @@
// method
rcvr := fn.Type.Recv().Type
- if Isptr[rcvr.Etype] {
+ if rcvr.IsPtr() {
rcvr = rcvr.Elem()
}
if rcvr.Sym == nil {
diff --git a/src/cmd/compile/internal/gc/order.go b/src/cmd/compile/internal/gc/order.go
index 4017e96..8410a23 100644
--- a/src/cmd/compile/internal/gc/order.go
+++ b/src/cmd/compile/internal/gc/order.go
@@ -375,11 +375,11 @@
}
if t.Note != nil && *t.Note == unsafeUintptrTag {
xp := n.List.Addr(i)
- for (*xp).Op == OCONVNOP && !Isptr[(*xp).Type.Etype] {
+ for (*xp).Op == OCONVNOP && !(*xp).Type.IsPtr() {
xp = &(*xp).Left
}
x := *xp
- if Isptr[x.Type.Etype] {
+ if x.Type.IsPtr() {
x = ordercopyexpr(x, x.Type, order, 0)
x.Name.Keepalive = true
*xp = x
diff --git a/src/cmd/compile/internal/gc/parser.go b/src/cmd/compile/internal/gc/parser.go
index a0aae5a..ba30061 100644
--- a/src/cmd/compile/internal/gc/parser.go
+++ b/src/cmd/compile/internal/gc/parser.go
@@ -3153,7 +3153,7 @@
ss.SetVal(s3)
} else {
s := s2.Sym
- if s == nil && Isptr[s2.Etype] {
+ if s == nil && s2.IsPtr() {
s = s2.Elem().Sym
}
pkg := importpkg
diff --git a/src/cmd/compile/internal/gc/pgen.go b/src/cmd/compile/internal/gc/pgen.go
index 9ff2311..66c87b0 100644
--- a/src/cmd/compile/internal/gc/pgen.go
+++ b/src/cmd/compile/internal/gc/pgen.go
@@ -318,7 +318,7 @@
}
// Ideally we wouldn't see any integer types here, but we do.
- if n.Type == nil || (!Isptr[n.Type.Etype] && !Isint[n.Type.Etype] && n.Type.Etype != TUNSAFEPTR) {
+ if n.Type == nil || (!n.Type.IsPtr() && !n.Type.IsInteger() && n.Type.Etype != TUNSAFEPTR) {
Dump("checknil", n)
Fatalf("bad checknil")
}
diff --git a/src/cmd/compile/internal/gc/range.go b/src/cmd/compile/internal/gc/range.go
index 7517874..e97a628 100644
--- a/src/cmd/compile/internal/gc/range.go
+++ b/src/cmd/compile/internal/gc/range.go
@@ -38,7 +38,7 @@
}
}
- if Isptr[t.Etype] && t.Elem().IsArray() {
+ if t.IsPtr() && t.Elem().IsArray() {
t = t.Elem()
}
n.Type = t
diff --git a/src/cmd/compile/internal/gc/reflect.go b/src/cmd/compile/internal/gc/reflect.go
index 05cc568..636ef9c 100644
--- a/src/cmd/compile/internal/gc/reflect.go
+++ b/src/cmd/compile/internal/gc/reflect.go
@@ -306,10 +306,10 @@
// method does not apply.
this := f.Type.Recv().Type
- if Isptr[this.Etype] && this.Elem() == t {
+ if this.IsPtr() && this.Elem() == t {
continue
}
- if Isptr[this.Etype] && !Isptr[t.Etype] && f.Embedded != 2 && !isifacemethod(f.Type) {
+ if this.IsPtr() && !t.IsPtr() && f.Embedded != 2 && !isifacemethod(f.Type) {
continue
}
@@ -791,7 +791,7 @@
}
tptr := Ptrto(t)
- if !Isptr[t.Etype] && (t.Sym != nil || methods(tptr) != nil) {
+ if !t.IsPtr() && (t.Sym != nil || methods(tptr) != nil) {
sptr := dtypesym(tptr)
r := obj.Addrel(Linksym(s))
r.Off = 0
@@ -918,7 +918,7 @@
}
func typenamesym(t *Type) *Sym {
- if t == nil || (Isptr[t.Etype] && t.Elem() == nil) || isideal(t) {
+ if t == nil || (t.IsPtr() && t.Elem() == nil) || isideal(t) {
Fatalf("typename %v", t)
}
s := typesym(t)
@@ -946,7 +946,7 @@
}
func itabname(t, itype *Type) *Node {
- if t == nil || (Isptr[t.Etype] && t.Elem() == nil) || isideal(t) {
+ if t == nil || (t.IsPtr() && t.Elem() == nil) || isideal(t) {
Fatalf("itabname %v", t)
}
s := Pkglookup(Tconv(t, FmtLeft)+","+Tconv(itype, FmtLeft), itabpkg)
@@ -1091,7 +1091,7 @@
// emit the type structures for int, float, etc.
tbase := t
- if Isptr[t.Etype] && t.Sym == nil && t.Elem().Sym != nil {
+ if t.IsPtr() && t.Sym == nil && t.Elem().Sym != nil {
tbase = t.Elem()
}
dupok := 0
diff --git a/src/cmd/compile/internal/gc/sinit.go b/src/cmd/compile/internal/gc/sinit.go
index 21e5d12..2901e59 100644
--- a/src/cmd/compile/internal/gc/sinit.go
+++ b/src/cmd/compile/internal/gc/sinit.go
@@ -1007,7 +1007,7 @@
Fatalf("anylit: not lit")
case OPTRLIT:
- if !Isptr[t.Etype] {
+ if !t.IsPtr() {
Fatalf("anylit: not ptr")
}
diff --git a/src/cmd/compile/internal/gc/subr.go b/src/cmd/compile/internal/gc/subr.go
index b9671a6..c552dd0 100644
--- a/src/cmd/compile/internal/gc/subr.go
+++ b/src/cmd/compile/internal/gc/subr.go
@@ -460,7 +460,7 @@
n.Val().U.(*Mpint).SetInt64(v)
n.Type = t
- if Isfloat[t.Etype] {
+ if t.IsFloat() {
Fatalf("nodconst: bad type %v", t)
}
}
@@ -562,7 +562,7 @@
if t == nil {
return false
}
- if !Isptr[t.Etype] {
+ if !t.IsPtr() {
return false
}
t = t.Elem()
@@ -617,7 +617,7 @@
}
// strip away pointer if it's there
- if Isptr[t.Etype] {
+ if t.IsPtr() {
if t.Sym != nil {
return nil
}
@@ -947,14 +947,14 @@
// 3. src and dst are unnamed pointer types
// and their base types have identical underlying types.
- if Isptr[src.Etype] && Isptr[dst.Etype] && src.Sym == nil && dst.Sym == nil {
+ if src.IsPtr() && dst.IsPtr() && src.Sym == nil && dst.Sym == nil {
if Eqtype(src.Elem().Orig, dst.Elem().Orig) {
return OCONVNOP
}
}
// 4. src and dst are both integer or floating point types.
- if (Isint[src.Etype] || Isfloat[src.Etype]) && (Isint[dst.Etype] || Isfloat[dst.Etype]) {
+ if (src.IsInteger() || src.IsFloat()) && (dst.IsInteger() || dst.IsFloat()) {
if Simtype[src.Etype] == Simtype[dst.Etype] {
return OCONVNOP
}
@@ -962,7 +962,7 @@
}
// 5. src and dst are both complex types.
- if Iscomplex[src.Etype] && Iscomplex[dst.Etype] {
+ if src.IsComplex() && dst.IsComplex() {
if Simtype[src.Etype] == Simtype[dst.Etype] {
return OCONVNOP
}
@@ -971,7 +971,7 @@
// 6. src is an integer or has type []byte or []rune
// and dst is a string type.
- if Isint[src.Etype] && dst.IsString() {
+ if src.IsInteger() && dst.IsString() {
return ORUNESTR
}
@@ -996,12 +996,12 @@
}
// 8. src is a pointer or uintptr and dst is unsafe.Pointer.
- if (Isptr[src.Etype] || src.Etype == TUINTPTR) && dst.Etype == TUNSAFEPTR {
+ if (src.IsPtr() || src.Etype == TUINTPTR) && dst.Etype == TUNSAFEPTR {
return OCONVNOP
}
// 9. src is unsafe.Pointer and dst is a pointer or uintptr.
- if src.Etype == TUNSAFEPTR && (Isptr[dst.Etype] || dst.Etype == TUINTPTR) {
+ if src.Etype == TUNSAFEPTR && (dst.IsPtr() || dst.Etype == TUINTPTR) {
return OCONVNOP
}
@@ -1265,7 +1265,7 @@
}
// common mistake: *struct and *interface.
- if tl != nil && tr != nil && Isptr[tl.Etype] && Isptr[tr.Etype] {
+ if tl != nil && tr != nil && tl.IsPtr() && tr.IsPtr() {
if tl.Elem().IsStruct() && tr.Elem().IsInterface() {
fmt_ += "\n\t(*struct vs *interface)"
} else if tl.Elem().IsInterface() && tr.Elem().IsStruct() {
@@ -1432,7 +1432,7 @@
// (if save is not nil).
func lookdot0(s *Sym, t *Type, save **Field, ignorecase bool) int {
u := t
- if Isptr[u.Etype] {
+ if u.IsPtr() {
u = u.Elem()
}
@@ -1488,7 +1488,7 @@
}
u = t
- if Isptr[u.Etype] {
+ if u.IsPtr() {
u = u.Elem()
}
if !u.IsStruct() && !u.IsInterface() {
@@ -1597,7 +1597,7 @@
func expand0(t *Type, followptr bool) {
u := t
- if Isptr[u.Etype] {
+ if u.IsPtr() {
followptr = true
u = u.Elem()
}
@@ -1637,7 +1637,7 @@
}
u := t
- if Isptr[u.Etype] {
+ if u.IsPtr() {
followptr = true
u = u.Elem()
}
@@ -1814,7 +1814,7 @@
methodrcvr := method.Type.Recv().Type
// generate nil pointer check for better error
- if Isptr[rcvr.Etype] && rcvr.Elem() == methodrcvr {
+ if rcvr.IsPtr() && rcvr.Elem() == methodrcvr {
// generating wrapper from *T to T.
n := Nod(OIF, nil, nil)
@@ -1840,11 +1840,11 @@
dot := adddot(NodSym(OXDOT, this.Left, method.Sym))
// generate call
- if !instrumenting && Isptr[rcvr.Etype] && Isptr[methodrcvr.Etype] && method.Embedded != 0 && !isifacemethod(method.Type) {
+ if !instrumenting && rcvr.IsPtr() && methodrcvr.IsPtr() && method.Embedded != 0 && !isifacemethod(method.Type) {
// generate tail call: adjust pointer receiver and jump to embedded method.
dot = dot.Left // skip final .M
// TODO(mdempsky): Remove dependency on dotlist.
- if !Isptr[dotlist[0].field.Type.Etype] {
+ if !dotlist[0].field.Type.IsPtr() {
dot = Nod(OADDR, dot, nil)
}
as := Nod(OAS, this.Left, Nod(OCONVNOP, dot, nil))
@@ -1877,7 +1877,7 @@
testdclstack()
// wrappers where T is anonymous (struct or interface) can be duplicated.
- if rcvr.IsStruct() || rcvr.IsInterface() || Isptr[rcvr.Etype] && rcvr.Elem().IsStruct() {
+ if rcvr.IsStruct() || rcvr.IsInterface() || rcvr.IsPtr() && rcvr.Elem().IsStruct() {
fn.Func.Dupok = true
}
fn = typecheck(fn, Etop)
@@ -1922,7 +1922,7 @@
}
for _, d := range path {
- if Isptr[d.field.Type.Etype] {
+ if d.field.Type.IsPtr() {
*followptr = true
break
}
@@ -1994,7 +1994,7 @@
// the method does not exist for value types.
rcvr := tm.Type.Recv().Type
- if Isptr[rcvr.Etype] && !Isptr[t0.Etype] && !followptr && !isifacemethod(tm.Type) {
+ if rcvr.IsPtr() && !t0.IsPtr() && !followptr && !isifacemethod(tm.Type) {
if false && Debug['r'] != 0 {
Yyerror("interface pointer mismatch")
}
@@ -2056,7 +2056,7 @@
if n == nil || n.Op != OLITERAL || n.Type == nil {
return -1
}
- if !Isint[n.Type.Etype] {
+ if !n.Type.IsInteger() {
return -1
}
@@ -2069,7 +2069,7 @@
b = b << 1
}
- if !Issigned[n.Type.Etype] {
+ if !n.Type.IsSigned() {
return -1
}
diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go
index e7b0e3c..9102f5b 100644
--- a/src/cmd/compile/internal/gc/typecheck.go
+++ b/src/cmd/compile/internal/gc/typecheck.go
@@ -360,7 +360,7 @@
v = toint(l.Val())
default:
- if l.Type != nil && Isint[l.Type.Etype] && l.Op != OLITERAL {
+ if l.Type != nil && l.Type.IsInteger() && l.Op != OLITERAL {
Yyerror("non-constant array bound %v", l)
} else {
Yyerror("invalid array bound %v", l)
@@ -473,7 +473,7 @@
break OpSwitch
}
- if !Isptr[t.Etype] {
+ if !t.IsPtr() {
if top&(Erv|Etop) != 0 {
Yyerror("invalid indirect of %v", Nconv(n.Left, FmtLong))
n.Type = nil
@@ -546,14 +546,14 @@
r = defaultlit(r, Types[TUINT])
n.Right = r
t := r.Type
- if !Isint[t.Etype] || Issigned[t.Etype] {
+ if !t.IsInteger() || t.IsSigned() {
Yyerror("invalid operation: %v (shift count type %v, must be unsigned integer)", n, r.Type)
n.Type = nil
return n
}
t = l.Type
- if t != nil && t.Etype != TIDEAL && !Isint[t.Etype] {
+ if t != nil && t.Etype != TIDEAL && !t.IsInteger() {
Yyerror("invalid operation: %v (shift of type %v)", n, t)
n.Type = nil
return n
@@ -864,7 +864,7 @@
break OpSwitch
}
- if Isptr[t.Etype] && !t.Elem().IsInterface() {
+ if t.IsPtr() && !t.Elem().IsInterface() {
t = t.Elem()
if t == nil {
n.Type = nil
@@ -886,7 +886,7 @@
case isnilinter(t):
Yyerror("%v undefined (type %v is interface with no methods)", n, n.Left.Type)
- case Isptr[t.Etype] && t.Elem().IsInterface():
+ case t.IsPtr() && t.Elem().IsInterface():
// Pointer to interface is almost always a mistake.
Yyerror("%v undefined (type %v is pointer to interface, not interface)", n, n.Left.Type)
@@ -1000,7 +1000,7 @@
}
}
- if n.Right.Type != nil && !Isint[n.Right.Type.Etype] {
+ if n.Right.Type != nil && !n.Right.Type.IsInteger() {
Yyerror("non-integer %s index %v", why, n.Right)
break
}
@@ -1124,7 +1124,7 @@
if Istype(t, TSTRING) {
n.Type = t
n.Op = OSLICESTR
- } else if Isptr[t.Etype] && t.Elem().IsArray() {
+ } else if t.IsPtr() && t.Elem().IsArray() {
tp = t.Elem()
n.Type = typSlice(tp.Elem())
dowidth(n.Type)
@@ -1189,7 +1189,7 @@
}
var tp *Type
- if Isptr[t.Etype] && t.Elem().IsArray() {
+ if t.IsPtr() && t.Elem().IsArray() {
tp = t.Elem()
n.Type = typSlice(tp.Elem())
dowidth(n.Type)
@@ -1381,7 +1381,7 @@
}
case OREAL, OIMAG:
- if !Iscomplex[t.Etype] {
+ if !t.IsComplex() {
goto badcall1
}
if Isconst(l, CTCPLX) {
@@ -2204,7 +2204,7 @@
if t == nil {
return false
}
- if !Isint[t.Etype] {
+ if !t.IsInteger() {
Yyerror("invalid slice index %v (type %v)", r, t)
return false
}
@@ -2296,7 +2296,7 @@
func implicitstar(n *Node) *Node {
// insert implicit * if needed for fixed array
t := n.Type
- if t == nil || !Isptr[t.Etype] {
+ if t == nil || !t.IsPtr() {
return n
}
t = t.Elem()
@@ -2377,7 +2377,7 @@
if r != nil {
if errnode != nil {
Yyerror("ambiguous selector %v", errnode)
- } else if Isptr[t.Etype] {
+ } else if t.IsPtr() {
Yyerror("ambiguous selector (%v).%v", t, s)
} else {
Yyerror("ambiguous selector %v.%v", t, s)
@@ -2421,7 +2421,7 @@
}
// disallow T.m if m requires *T receiver
- if Isptr[f2.Type.Recv().Type.Etype] && !Isptr[t.Etype] && f2.Embedded != 2 && !isifacemethod(f2.Type) {
+ if f2.Type.Recv().Type.IsPtr() && !t.IsPtr() && f2.Embedded != 2 && !isifacemethod(f2.Type) {
Yyerror("invalid method expression %v (needs pointer receiver: (*%v).%v)", n, t, Sconv(f2.Sym, FmtShort))
return false
}
@@ -2485,7 +2485,7 @@
dotField[typeSym{t.Orig, s}] = f1
}
if t.IsInterface() {
- if Isptr[n.Left.Type.Etype] {
+ if n.Left.Type.IsPtr() {
n.Left = Nod(OIND, n.Left, nil) // implicitstar
n.Left.Implicit = true
n.Left = typecheck(n.Left, Erv)
@@ -2538,7 +2538,7 @@
pll = ll
ll = ll.Left
}
- if pll.Implicit && Isptr[ll.Type.Etype] && ll.Type.Sym != nil && ll.Type.Sym.Def != nil && ll.Type.Sym.Def.Op == OTYPE {
+ if pll.Implicit && ll.Type.IsPtr() && ll.Type.Sym != nil && ll.Type.Sym.Def != nil && ll.Type.Sym.Def.Op == OTYPE {
// It is invalid to automatically dereference a named pointer type when selecting a method.
// Make n->left == ll to clarify error message.
n.Left = ll
@@ -2910,7 +2910,7 @@
nerr := nerrors
n.Type = t
- if Isptr[t.Etype] {
+ 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.
if !n.Right.Implicit {
@@ -3126,7 +3126,7 @@
}
n.Orig = norig
- if Isptr[n.Type.Etype] {
+ if n.Type.IsPtr() {
n = Nod(OPTRLIT, n, nil)
n.Typecheck = 1
n.Type = n.Left.Type
@@ -3534,7 +3534,7 @@
if embedlineno != 0 {
lineno = embedlineno
- if Isptr[t.Etype] {
+ if t.IsPtr() {
Yyerror("embedded type cannot be a pointer")
}
}
@@ -3814,7 +3814,7 @@
}
}
- if !Isint[n.Type.Etype] && n.Type.Etype != TIDEAL {
+ if !n.Type.IsInteger() && n.Type.Etype != TIDEAL {
Yyerror("non-integer %s argument in make(%v) - %v", arg, t, n.Type)
return false
}
diff --git a/src/cmd/compile/internal/gc/universe.go b/src/cmd/compile/internal/gc/universe.go
index 20c1c8c..c2ba9c9 100644
--- a/src/cmd/compile/internal/gc/universe.go
+++ b/src/cmd/compile/internal/gc/universe.go
@@ -184,17 +184,8 @@
Iscomplex[TCOMPLEX64] = true
Iscomplex[TCOMPLEX128] = true
- Isptr[TPTR32] = true
- Isptr[TPTR64] = true
-
isforw[TFORW] = true
- Issigned[TINT] = true
- Issigned[TINT8] = true
- Issigned[TINT16] = true
- Issigned[TINT32] = true
- Issigned[TINT64] = true
-
// initialize okfor
for et := EType(0); et < NTYPE; et++ {
if Isint[et] || et == TIDEAL {
diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go
index 425128e..bab9c00 100644
--- a/src/cmd/compile/internal/gc/walk.go
+++ b/src/cmd/compile/internal/gc/walk.go
@@ -541,7 +541,7 @@
// delayed until now to preserve side effects.
t := n.Left.Type
- if Isptr[t.Etype] {
+ if t.IsPtr() {
t = t.Elem()
}
if t.IsArray() {
@@ -1057,7 +1057,7 @@
case OCONV, OCONVNOP:
if Thearch.Thechar == '5' {
- if Isfloat[n.Left.Type.Etype] {
+ if n.Left.Type.IsFloat() {
if n.Type.Etype == TINT64 {
n = mkcall("float64toint64", n.Type, init, conv(n.Left, Types[TFLOAT64]))
break
@@ -1069,7 +1069,7 @@
}
}
- if Isfloat[n.Type.Etype] {
+ if n.Type.IsFloat() {
if n.Left.Type.Etype == TINT64 {
n = mkcall("int64tofloat64", n.Type, init, conv(n.Left, Types[TINT64]))
break
@@ -1154,7 +1154,7 @@
break
}
t := n.Left.Type
- if t != nil && Isptr[t.Etype] {
+ if t != nil && t.IsPtr() {
t = t.Elem()
}
if t.IsArray() {
@@ -1930,7 +1930,7 @@
on = syslook("printiface")
}
on = substArgTypes(on, n.Type) // any-1
- } else if Isptr[et] || et == TCHAN || et == TMAP || et == TFUNC || et == TUNSAFEPTR {
+ } else if n.Type.IsPtr() || et == TCHAN || et == TMAP || et == TFUNC || et == TUNSAFEPTR {
on = syslook("printpointer")
on = substArgTypes(on, n.Type) // any-1
} else if n.Type.IsSlice() {
@@ -3277,7 +3277,7 @@
l := n.Left
r := n.Right
- if (n.Op != OOR && n.Op != OXOR) || (l.Op != OLSH && l.Op != ORSH) || (r.Op != OLSH && r.Op != ORSH) || n.Type == nil || Issigned[n.Type.Etype] || l.Op == r.Op {
+ if (n.Op != OOR && n.Op != OXOR) || (l.Op != OLSH && l.Op != ORSH) || (r.Op != OLSH && r.Op != ORSH) || n.Type == nil || n.Type.IsSigned() || l.Op == r.Op {
return n
}
@@ -3322,7 +3322,7 @@
// The result of walkmul MUST be assigned back to n, e.g.
// n.Left = walkmul(n.Left, init)
func walkmul(n *Node, init *Nodes) *Node {
- if !Isint[n.Type.Etype] {
+ if !n.Type.IsInteger() {
return n
}
@@ -3434,7 +3434,7 @@
var m Magic
m.W = w
- if Issigned[nl.Type.Etype] {
+ if nl.Type.IsSigned() {
m.Sd = nr.Val().U.(*Mpint).Int64()
Smagic(&m)
} else {
@@ -3555,7 +3555,7 @@
}
default:
- if Issigned[n.Type.Etype] {
+ if n.Type.IsSigned() {
if n.Op == OMOD {
// signed modulo 2^pow is like ANDing
// with the last pow bits, but if nl < 0,
@@ -3652,11 +3652,11 @@
// return 1 if integer n must be in range [0, max), 0 otherwise
func bounded(n *Node, max int64) bool {
- if n.Type == nil || !Isint[n.Type.Etype] {
+ if n.Type == nil || !n.Type.IsInteger() {
return false
}
- sign := Issigned[n.Type.Etype]
+ sign := n.Type.IsSigned()
bits := int32(8 * n.Type.Width)
if Smallintconst(n) {
@@ -3772,7 +3772,7 @@
}
t := n.Left.Type
- if Isptr[t.Etype] {
+ if t.IsPtr() {
t = t.Elem()
}
field := dotField[typeSym{t.Orig, n.Sym}]
@@ -3784,7 +3784,7 @@
}
outer := n.Left.Type
- if Isptr[outer.Etype] {
+ if outer.IsPtr() {
outer = outer.Elem()
}
if outer.Sym == nil {