1
0
mirror of https://github.com/golang/go synced 2024-11-25 15:08:02 -07:00

gc: minor const simplifications

R=ken2
CC=golang-dev
https://golang.org/cl/217069
This commit is contained in:
Russ Cox 2010-02-21 11:18:09 -08:00
parent f59cb49a5a
commit ed13d39972

View File

@ -173,6 +173,7 @@ convlit1(Node **np, Type *t, int explicit)
if(isint[et]) { if(isint[et]) {
switch(ct) { switch(ct) {
default: default:
goto bad;
case CTCPLX: case CTCPLX:
case CTFLT: case CTFLT:
n->val = toint(n->val); n->val = toint(n->val);
@ -185,6 +186,7 @@ convlit1(Node **np, Type *t, int explicit)
if(isfloat[et]) { if(isfloat[et]) {
switch(ct) { switch(ct) {
default: default:
goto bad;
case CTCPLX: case CTCPLX:
case CTINT: case CTINT:
n->val = toflt(n->val); n->val = toflt(n->val);
@ -966,43 +968,28 @@ defaultlit(Node **np, Type *t)
break; break;
case CTINT: case CTINT:
n->type = types[TINT]; n->type = types[TINT];
if(t != T) { goto num;
if(isint[t->etype])
n->type = t;
else
if(isfloat[t->etype]) {
n->type = t;
n->val = toflt(n->val);
}
}
overflow(n->val, n->type);
break;
case CTFLT: case CTFLT:
n->type = types[TFLOAT]; n->type = types[TFLOAT];
goto num;
case CTCPLX:
n->type = types[TCOMPLEX];
goto num;
num:
if(t != T) { if(t != T) {
if(isfloat[t->etype])
n->type = t;
else
if(isint[t->etype]) { if(isint[t->etype]) {
n->type = t; n->type = t;
n->val = toint(n->val); n->val = toint(n->val);
} }
}
overflow(n->val, n->type);
break;
case CTCPLX:
n->type = types[TCOMPLEX];
if(t != T) {
if(iscomplex[t->etype])
n->type = t;
else else
if(isfloat[t->etype]) { if(isfloat[t->etype]) {
n->type = t; n->type = t;
n->val = toflt(n->val); n->val = toflt(n->val);
} else }
if(isint[t->etype]) { else
if(iscomplex[t->etype]) {
n->type = t; n->type = t;
n->val = toint(n->val); n->val = tocplx(n->val);
} }
} }
overflow(n->val, n->type); overflow(n->val, n->type);
@ -1015,6 +1002,7 @@ defaultlit(Node **np, Type *t)
* defaultlit on both nodes simultaneously; * defaultlit on both nodes simultaneously;
* if they're both ideal going in they better * if they're both ideal going in they better
* get the same type going out. * get the same type going out.
* force means must assign concrete (non-ideal) type.
*/ */
void void
defaultlit2(Node **lp, Node **rp, int force) defaultlit2(Node **lp, Node **rp, int force)
@ -1192,13 +1180,8 @@ convconst(Node *con, Type *t, Val *val)
if(isfloat[tt]) { if(isfloat[tt]) {
con->val = toflt(con->val); con->val = toflt(con->val);
// if(con->val.ctype == CTINT) { if(con->val.ctype != CTFLT)
// con->val.ctype = CTFLT; fatal("convconst ctype=%d %T", con->val.ctype, t);
// con->val.u.fval = mal(sizeof *con->val.u.fval);
// mpmovefixflt(con->val.u.fval, val->u.xval);
// }
// if(con->val.ctype != CTFLT)
// fatal("convconst ctype=%d %T", con->val.ctype, t);
if(tt == TFLOAT32) if(tt == TFLOAT32)
con->val.u.fval = truncfltlit(con->val.u.fval, t); con->val.u.fval = truncfltlit(con->val.u.fval, t);
return; return;