From 63d47979eff3736da8c479cf3eea6399c0179736 Mon Sep 17 00:00:00 2001 From: Teddy Date: Sun, 13 Apr 2014 18:27:30 +0800 Subject: ... --- semantics.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'semantics.c') diff --git a/semantics.c b/semantics.c index 9013aac..27d5db7 100644 --- a/semantics.c +++ b/semantics.c @@ -21,7 +21,8 @@ } while (0) /* pointer to function conversion (std 6.3.2/4) */ -#define FUNC_POINTER_CONV(t) \ +/* also convert array to pointer */ +#define POINTER_CONV(t, p) \ do { \ if ((t)->type == CFUNC) \ { \ @@ -29,6 +30,13 @@ f->rec.ref = t; \ t = f; \ } \ + else if ((t)->type == CARR) \ + { \ + CType_t a = ctype_create("", CPTR, p); \ + a->rec.ref = t->rec.arr.elem; \ + free(t); \ + t = a; \ + } \ } while (0) #define CHECK_CVOID(name, ast) \ @@ -596,12 +604,12 @@ CVar_t semantics_params(CNode *p, CScope_t scope) { #else CTable_t tparams = ctable_create(bkdr_hash); #endif - FUNC_POINTER_CONV(params->type); + POINTER_CONV(params->type, p); ctable_insert(tparams, params->name, params, 0); for (p = p->next; p; p = p->next) { CVar_t var = semantics_p_decl(p, scope); - FUNC_POINTER_CONV(var->type); + POINTER_CONV(var->type, p); if (scope) /* params inside a function definition */ if (!ctable_insert(tparams, var->name, var, 0)) ERROR((var->ast, "redefinition of parameter '%s'", var->name)); @@ -1227,7 +1235,7 @@ ExpType semantics_exp(CNode *p, CScope_t scope) { p->ext.type = lu->rec.type; res.type = p->ext.type; res.lval = res.type->type == CFUNC; - FUNC_POINTER_CONV(res.type); + POINTER_CONV(res.type, p); } p->ext.is_const = 0; } -- cgit v1.2.3