diff options
author | Teddy <[email protected]> | 2014-04-16 13:26:42 +0800 |
---|---|---|
committer | Teddy <[email protected]> | 2014-04-16 13:26:42 +0800 |
commit | 439797d6649bd185af99f5cd14774420dfd1b626 (patch) | |
tree | 23db0e6f4739288609375ec69f03977119914bc3 /semantics.c | |
parent | 442e485824c87bbef95836be1f3a0f6d86386445 (diff) |
fixed typedef bug
Diffstat (limited to 'semantics.c')
-rw-r--r-- | semantics.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/semantics.c b/semantics.c index 3dcb3f9..3d12162 100644 --- a/semantics.c +++ b/semantics.c @@ -851,6 +851,10 @@ ExpType exp_check_add(ExpType op1, ExpType op2, CNode *p, char kind) { n1->next = NULL; p->chd = n2; } + if (t1 == CPTR && calc_size(op1.type->rec.ref) == -1) + ERROR((p, "invalid use of undefined type")); + if (t2 == CPTR && calc_size(op2.type->rec.ref) == -1) + ERROR((p, "invalid use of undefined type")); if (kind == '-') { if (IS_PTR(t2) && !IS_PTR(t1)) @@ -866,15 +870,21 @@ ExpType exp_check_add(ExpType op1, ExpType op2, CNode *p, char kind) { int l = lch->ext.const_val, r = rch->ext.const_val, *a = &(p->ext.const_val); - if (!IS_PTR(t1) && !IS_PTR(t2)) + if (IS_PTR(t1)) + { + /* TODO: constant pointer folding */ + if (t1 == CPTR) + p->ext.const_val = op1.type->rec.ref->size * r; + else /* array */ + p->ext.const_val = op1.type->rec.arr.elem->size * r; + } + else + { switch (kind) { case '+': *a = l + r; break; case '-': *a = l - r; break; } - else - { - /* TODO: constant pointer folding */ } } op1.lval = 0; |