}
var v Val
- v.Ctype = CTFLT
v.U = oldv
overflow(v, t)
case OLSH, ORSH:
convlit1(&n.Left, t, explicit && isideal(n.Left.Type))
t = n.Left.Type
- if t != nil && t.Etype == TIDEAL && n.Val.Ctype != CTINT {
+ if t != nil && t.Etype == TIDEAL && n.Val.Ctype() != CTINT {
n.Val = toint(n.Val)
}
if t != nil && !Isint[t.Etype] {
if n.Type.Etype == TUNSAFEPTR {
n.Val.U = new(Mpint)
Mpmovecfix(n.Val.U.(*Mpint), 0)
- n.Val.Ctype = CTINT
} else {
goto bad
}
if n.Type.Etype == TUNSAFEPTR && t.Etype != TUINTPTR {
goto bad
}
- ct := int(n.Val.Ctype)
+ ct := int(n.Val.Ctype())
if Isint[et] {
switch ct {
default:
}
func copyval(v Val) Val {
- switch v.Ctype {
+ switch v.Ctype() {
case CTINT, CTRUNE:
i := new(Mpint)
mpmovefixfix(i, v.U.(*Mpint))
+ i.Rune = v.U.(*Mpint).Rune
v.U = i
case CTFLT:
}
func tocplx(v Val) Val {
- switch v.Ctype {
+ switch v.Ctype() {
case CTINT, CTRUNE:
c := new(Mpcplx)
Mpmovefixflt(&c.Real, v.U.(*Mpint))
Mpmovecflt(&c.Imag, 0.0)
- v.Ctype = CTCPLX
v.U = c
case CTFLT:
c := new(Mpcplx)
mpmovefltflt(&c.Real, v.U.(*Mpflt))
Mpmovecflt(&c.Imag, 0.0)
- v.Ctype = CTCPLX
v.U = c
}
}
func toflt(v Val) Val {
- switch v.Ctype {
+ switch v.Ctype() {
case CTINT, CTRUNE:
f := newMpflt()
Mpmovefixflt(f, v.U.(*Mpint))
- v.Ctype = CTFLT
v.U = f
case CTCPLX:
if mpcmpfltc(&v.U.(*Mpcplx).Imag, 0) != 0 {
Yyerror("constant %v%vi truncated to real", Fconv(&v.U.(*Mpcplx).Real, obj.FmtSharp), Fconv(&v.U.(*Mpcplx).Imag, obj.FmtSharp|obj.FmtSign))
}
- v.Ctype = CTFLT
v.U = f
}
}
func toint(v Val) Val {
- switch v.Ctype {
+ switch v.Ctype() {
case CTRUNE:
- v.Ctype = CTINT
+ i := new(Mpint)
+ mpmovefixfix(i, v.U.(*Mpint))
+ v.U = i
case CTFLT:
i := new(Mpint)
if mpmovefltfix(i, v.U.(*Mpflt)) < 0 {
Yyerror("constant %v truncated to integer", Fconv(v.U.(*Mpflt), obj.FmtSharp))
}
- v.Ctype = CTINT
v.U = i
case CTCPLX:
if mpcmpfltc(&v.U.(*Mpcplx).Imag, 0) != 0 {
Yyerror("constant %v%vi truncated to real", Fconv(&v.U.(*Mpcplx).Real, obj.FmtSharp), Fconv(&v.U.(*Mpcplx).Imag, obj.FmtSharp|obj.FmtSign))
}
- v.Ctype = CTINT
v.U = i
}
}
func doesoverflow(v Val, t *Type) bool {
- switch v.Ctype {
+ switch v.Ctype() {
case CTINT, CTRUNE:
if !Isint[t.Etype] {
Fatal("overflow: %v integer constant", t)
return
}
- switch v.Ctype {
+ switch v.Ctype() {
case CTINT, CTRUNE:
Yyerror("constant %v overflows %v", v.U.(*Mpint), t)
}
func tostr(v Val) Val {
- switch v.Ctype {
+ switch v.Ctype() {
case CTINT, CTRUNE:
if Mpcmpfixfix(v.U.(*Mpint), Minintval[TINT]) < 0 || Mpcmpfixfix(v.U.(*Mpint), Maxintval[TINT]) > 0 {
Yyerror("overflow in int -> string")
}
r := uint(Mpgetfix(v.U.(*Mpint)))
v = Val{}
- v.Ctype = CTSTR
v.U = string(r)
case CTFLT:
case CTNIL:
v = Val{}
- v.Ctype = CTSTR
v.U = ""
}
if n == nil || n.Op != OLITERAL {
return -1
}
- return int(n.Val.Ctype)
+ return int(n.Val.Ctype())
}
func Isconst(n *Node, ct int) bool {
nl = Nod(OXXX, nil, nil)
*nl = *l1.N
nl.Orig = nl
- nl.Val.Ctype = CTSTR
nl.Val.U = strings.Join(strs, "")
l1.N = nl
l1.Next = l2
v = copyval(v)
}
- switch uint32(n.Op)<<16 | uint32(v.Ctype) {
+ switch uint32(n.Op)<<16 | uint32(v.Ctype()) {
default:
if n.Diag == 0 {
Yyerror("illegal constant expression %v %v", Oconv(int(n.Op), 0), nl.Type)
if nr.Type != nil && (Issigned[nr.Type.Etype] || !Isint[nr.Type.Etype]) {
goto illegal
}
- if nl.Val.Ctype != CTRUNE {
+ if nl.Val.Ctype() != CTRUNE {
nl.Val = toint(nl.Val)
}
nr.Val = toint(nr.Val)
rv = nr.Val
// convert to common ideal
- if v.Ctype == CTCPLX || rv.Ctype == CTCPLX {
+ if v.Ctype() == CTCPLX || rv.Ctype() == CTCPLX {
v = tocplx(v)
rv = tocplx(rv)
}
- if v.Ctype == CTFLT || rv.Ctype == CTFLT {
+ if v.Ctype() == CTFLT || rv.Ctype() == CTFLT {
v = toflt(v)
rv = toflt(rv)
}
// Rune and int turns into rune.
- if v.Ctype == CTRUNE && rv.Ctype == CTINT {
- rv.Ctype = CTRUNE
+ if v.Ctype() == CTRUNE && rv.Ctype() == CTINT {
+ i := new(Mpint)
+ mpmovefixfix(i, rv.U.(*Mpint))
+ i.Rune = true
+ rv.U = i
}
- if v.Ctype == CTINT && rv.Ctype == CTRUNE {
+ if v.Ctype() == CTINT && rv.Ctype() == CTRUNE {
if n.Op == OLSH || n.Op == ORSH {
- rv.Ctype = CTINT
+ i := new(Mpint)
+ mpmovefixfix(i, rv.U.(*Mpint))
+ rv.U = i
} else {
- v.Ctype = CTRUNE
+ i := new(Mpint)
+ mpmovefixfix(i, v.U.(*Mpint))
+ i.Rune = true
+ v.U = i
}
}
- if v.Ctype != rv.Ctype {
+ if v.Ctype() != rv.Ctype() {
// Use of undefined name as constant?
- if (v.Ctype == 0 || rv.Ctype == 0) && nerrors > 0 {
+ if (v.Ctype() == 0 || rv.Ctype() == 0) && nerrors > 0 {
return
}
- Fatal("constant type mismatch %v(%d) %v(%d)", nl.Type, v.Ctype, nr.Type, rv.Ctype)
+ Fatal("constant type mismatch %v(%d) %v(%d)", nl.Type, v.Ctype(), nr.Type, rv.Ctype())
}
// run op
- switch uint32(n.Op)<<16 | uint32(v.Ctype) {
+ switch uint32(n.Op)<<16 | uint32(v.Ctype()) {
default:
goto illegal
lineno = int32(lno)
// truncate precision for non-ideal float.
- if v.Ctype == CTFLT && n.Type.Etype != TIDEAL {
+ if v.Ctype() == CTFLT && n.Type.Etype != TIDEAL {
n.Val.U = truncfltlit(v.U.(*Mpflt), n.Type)
}
return
func nodlit(v Val) *Node {
n := Nod(OLITERAL, nil, nil)
n.Val = v
- switch v.Ctype {
+ switch v.Ctype() {
default:
- Fatal("nodlit ctype %d", v.Ctype)
+ Fatal("nodlit ctype %d", v.Ctype())
case CTSTR:
n.Type = idealstring
n := Nod(OLITERAL, nil, nil)
n.Type = Types[TIDEAL]
n.Val.U = c
- n.Val.Ctype = CTCPLX
- if r.Ctype != CTFLT || i.Ctype != CTFLT {
- Fatal("nodcplxlit ctype %d/%d", r.Ctype, i.Ctype)
+ if r.Ctype() != CTFLT || i.Ctype() != CTFLT {
+ Fatal("nodcplxlit ctype %d/%d", r.Ctype(), i.Ctype())
}
mpmovefltflt(&c.Real, r.U.(*Mpflt))
return CTxxx
case OLITERAL:
- return int(n.Val.Ctype)
+ return int(n.Val.Ctype())
// numeric kinds.
case OADD,
return
}
- if n.Val.Ctype == CTNIL {
+ if n.Val.Ctype() == CTNIL {
lineno = int32(lno)
if n.Diag == 0 {
Yyerror("use of untyped nil")
break
}
- if n.Val.Ctype == CTSTR {
+ if n.Val.Ctype() == CTSTR {
t1 := Types[TSTRING]
Convlit(np, t1)
break
con.Val = n.Val
if Isint[tt] {
- con.Val.Ctype = CTINT
con.Val.U = new(Mpint)
var i int64
- switch n.Val.Ctype {
+ switch n.Val.Ctype() {
default:
- Fatal("convconst ctype=%d %v", n.Val.Ctype, Tconv(t, obj.FmtLong))
+ Fatal("convconst ctype=%d %v", n.Val.Ctype(), Tconv(t, obj.FmtLong))
case CTINT, CTRUNE:
i = Mpgetfix(n.Val.U.(*Mpint))
if Isfloat[tt] {
con.Val = toflt(con.Val)
- if con.Val.Ctype != CTFLT {
- Fatal("convconst ctype=%d %v", con.Val.Ctype, t)
+ if con.Val.Ctype() != CTFLT {
+ Fatal("convconst ctype=%d %v", con.Val.Ctype(), t)
}
if tt == TFLOAT32 {
con.Val.U = truncfltlit(con.Val.U.(*Mpflt), t)
}
case OLITERAL:
- if n.Val.Ctype != CTNIL {
+ if n.Val.Ctype() != CTNIL {
return true
}
case ONAME:
l := n.Sym.Def
- if l != nil && l.Op == OLITERAL && n.Val.Ctype != CTNIL {
+ if l != nil && l.Op == OLITERAL && n.Val.Ctype() != CTNIL {
return true
}