diff options
author | Russ Cox <rsc@golang.org> | 2009-07-30 16:53:08 -0700 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2009-07-30 16:53:08 -0700 |
commit | 83248a03783f1c6817fe9656db578c70be986aca (patch) | |
tree | 866108ee0abf9f91cb1da1cc04efff54c5312cd4 /src/cmd/gc/const.c | |
parent | 60f3d4a0e7d763a455e119fa39b8c301c62ad336 (diff) | |
download | golang-83248a03783f1c6817fe9656db578c70be986aca.tar.gz |
typechecking checkpoint.
started to move typechecking to another file.
can build entire tree still, but lots of work
is duplicated. much to clean up.
R=ken
OCL=32536
CL=32543
Diffstat (limited to 'src/cmd/gc/const.c')
-rw-r--r-- | src/cmd/gc/const.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/cmd/gc/const.c b/src/cmd/gc/const.c index 02f17b7d5..8b4046bf5 100644 --- a/src/cmd/gc/const.c +++ b/src/cmd/gc/const.c @@ -89,12 +89,17 @@ convlit1(Node **np, Type *t, int explicit) switch(n->op) { default: + if(n->type->etype == TIDEAL) { + convlit(&n->left, t); + convlit(&n->right, t); + n->type = t; + } return; case OLITERAL: break; case OLSH: case ORSH: - convlit1(&n->left, t, explicit); + convlit(&n->left, t); n->type = n->left->type; return; } @@ -259,11 +264,15 @@ overflow(Val v, Type *t) return; switch(v.ctype) { case CTINT: + if(!isint[t->etype]) + fatal("overflow: %T integer constant", t); if(mpcmpfixfix(v.u.xval, minintval[t->etype]) < 0 || mpcmpfixfix(v.u.xval, maxintval[t->etype]) > 0) yyerror("constant %B overflows %T", v.u.xval, t); break; case CTFLT: + if(!isfloat[t->etype]) + fatal("overflow: %T floating-point constant", t); if(mpcmpfltflt(v.u.fval, minfltval[t->etype]) < 0 || mpcmpfltflt(v.u.fval, maxfltval[t->etype]) > 0) yyerror("constant %#F overflows %T", v.u.fval, t); @@ -325,6 +334,11 @@ evconst(Node *n) Val v; Mpint b; + switch(n->op) { + case OMAKE: + return; + } + nl = n->left; if(nl == N || nl->type == T) return; @@ -590,6 +604,7 @@ unary: case TUP(OCONV, CTINT): case TUP(OCONV, CTFLT): case TUP(OCONV, CTSTR): + case TUP(OCONV, CTNIL): convlit1(&nl, n->type, 1); break; @@ -711,6 +726,11 @@ defaultlit(Node **np, Type *t) defaultlit(&n->left, t); n->type = n->left->type; return; + default: + defaultlit(&n->left, t); + defaultlit(&n->right, t); + n->type = n->left->type; + return; } lno = lineno; @@ -753,7 +773,7 @@ defaultlit(Node **np, Type *t) * get the same type going out. */ void -defaultlit2(Node **lp, Node **rp) +defaultlit2(Node **lp, Node **rp, int force) { Node *l, *r; @@ -769,6 +789,8 @@ defaultlit2(Node **lp, Node **rp) convlit(lp, r->type); return; } + if(!force) + return; if(isconst(l, CTFLT) || isconst(r, CTFLT)) { convlit(lp, types[TFLOAT]); convlit(rp, types[TFLOAT]); |