diff options
-rw-r--r-- | cibic.y | 5 | ||||
-rw-r--r-- | semantics.c | 18 | ||||
-rw-r--r-- | semantics.h | 2 |
3 files changed, 18 insertions, 7 deletions
@@ -72,7 +72,10 @@ init_declarators init_declarator : declarator { $$ = cnode_add_loc(cnode_create_init_declr($1, cnode_create_nop()), @$); } - | declarator '=' initializer { $$ = cnode_add_loc(cnode_create_init_declr($1, $3), @$); } + | declarator { def_exit(); } '=' initializer { + $$ = cnode_add_loc(cnode_create_init_declr($1, $4), @$); + def_enter(FORCE_ID); + } initializer : assignment_expression { $$ = cnode_add_loc(cnode_create_initr(INITR_NORM, $1), @$); } 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; diff --git a/semantics.h b/semantics.h index df6eeaf..d301ab0 100644 --- a/semantics.h +++ b/semantics.h @@ -61,9 +61,7 @@ CType_t ctype_create(const char *name, int type, CNode *ast); void ctype_debug_print(CType_t ct); typedef unsigned int (*Hashfunc_t) (const char *); -#ifdef CIBIC_DEBUG typedef const char *(*Printfunc_t) (void *); -#endif typedef struct CTNode CTNode; struct CTNode { |