compress parsref code a little

This commit is contained in:
Quentin Carbonneaux 2015-07-30 21:58:52 -04:00
parent 92be2fdd17
commit 390045cae1

View file

@ -275,36 +275,28 @@ varref(char *v)
static Ref static Ref
parseref() parseref()
{ {
int64_t val; int i;
char *label; Const c;
int i, ty;
switch (next()) { switch (next()) {
case TVar: case TVar:
return varref(tokval.str); return varref(tokval.str);
case TNum: case TNum:
ty = CNum; c = (Const){.type = CNum, .val = tokval.num};
val = tokval.num; strcpy(c.label, "");
label = ""; if (0) {
for (i=0; i<ncst; i++)
if (cst[i].type == CNum)
if (cst[i].val == val)
return CONST(i);
goto New;
case TAddr: case TAddr:
ty = CAddr; c = (Const){.type = CAddr, .val = 0};
val = 0; strcpy(c.label, tokval.str);
label = tokval.str; }
for (i=0; i<ncst; i++) for (i=0; i<ncst; i++)
if (cst[i].type == CAddr) if (cst[i].type == c.type
if (strcmp(cst[i].label, label) == 0) && cst[i].val == c.val
&& strcmp(cst[i].label, c.label) == 0)
return CONST(i); return CONST(i);
New:
if (i >= NCst) if (i >= NCst)
err("too many constants"); err("too many constants");
cst[i].type = ty; cst[i] = c;
cst[i].val = val;
strcpy(cst[i].label, label);
ncst++; ncst++;
return CONST(i); return CONST(i);
default: default: