Extract values from constant defs.

This commit is contained in:
Bill Currie 2011-04-09 12:42:41 +09:00
parent cc714864a8
commit 57ed603658

View file

@ -620,17 +620,31 @@ expr_t *
constant_expr (expr_t *e) constant_expr (expr_t *e)
{ {
expr_t *new; expr_t *new;
symbol_t *sym;
ex_value_t value;
if (!is_constant (e)) if (!is_constant (e))
return e; return e;
if (e->type == ex_nil || e->type == ex_value) if (e->type == ex_nil || e->type == ex_value)
return e; return e;
if (e->type != ex_symbol || e->e.symbol->sy_type != sy_const) if (e->type != ex_symbol)
return e; return e;
sym = e->e.symbol;
if (sym->sy_type == sy_const) {
value = sym->s.value;
} else if (sym->sy_type == sy_var && sym->s.def->constant) {
//FIXME pointers and fields
memset (&value, 0, sizeof (value));
memcpy (&value.v, &D_INT (sym->s.def),
type_size (sym->s.def->type) * sizeof (pr_type_t));
} else {
return e;
}
new = new_expr (); new = new_expr ();
new->type = ex_value; new->type = ex_value;
new->line = e->line; new->line = e->line;
new->file = e->file; new->file = e->file;
new->e.value = e->e.symbol->s.value; new->e.value = value;
return new; return new;
} }