diff --git a/tools/qfcc/source/def.c b/tools/qfcc/source/def.c index c6ba34e83..962a472a5 100644 --- a/tools/qfcc/source/def.c +++ b/tools/qfcc/source/def.c @@ -439,17 +439,17 @@ initialize_def (symbol_t *sym, type_t *type, expr_t *init, defspace_t *space, sym->type = type; if (!sym->table) symtab_addsymbol (current_symtab, sym); - if (storage == st_global && init && is_scalar (type)) { - sym->sy_type = sy_const; - memset (&sym->s.value, 0, sizeof (&sym->s.value)); - if (init->type != ex_value) { //FIXME arrays/structs - error (0, "non-constant initializier"); - } else { - sym->s.value = init->e.value; - convert_value (&sym->s.value, sym->type); - } - return; - } +// if (storage == st_global && init && is_scalar (type)) { +// sym->sy_type = sy_const; +// memset (&sym->s.value, 0, sizeof (&sym->s.value)); +// if (init->type != ex_value) { //FIXME arrays/structs +// error (0, "non-constant initializier"); +// } else { +// sym->s.value = init->e.value; +// convert_value (&sym->s.value, sym->type); +// } +// return; +// } if (sym->s.def && sym->s.def->external) { //FIXME this really is not the right way relocs = sym->s.def->relocs; diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index 85839214a..d08766636 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -598,7 +598,9 @@ int is_constant (expr_t *e) { if (e->type == ex_nil || e->type == ex_value - || (e->type == ex_symbol && e->e.symbol->sy_type == sy_const)) + || (e->type == ex_symbol && e->e.symbol->sy_type == sy_const) + || (e->type == ex_symbol && e->e.symbol->sy_type == sy_var + && e->e.symbol->s.def->constant)) return 1; return 0; } @@ -670,6 +672,10 @@ expr_float (expr_t *e) if (e->type == ex_symbol && e->e.symbol->sy_type == sy_const && e->e.symbol->type->type == ev_float) return e->e.symbol->s.value.v.float_val; + if (e->type == ex_symbol && e->e.symbol->sy_type == sy_var + && e->e.symbol->s.def->constant + && is_float (e->e.symbol->s.def->type)) + return D_FLOAT (e->e.symbol->s.def); internal_error (e, "not a float constant"); } @@ -750,6 +756,10 @@ expr_integer (expr_t *e) && (e->e.symbol->type->type == ev_integer || is_enum (e->e.symbol->type))) return e->e.symbol->s.value.v.integer_val; + if (e->type == ex_symbol && e->e.symbol->sy_type == sy_var + && e->e.symbol->s.def->constant + && is_integral (e->e.symbol->s.def->type)) + return D_INT (e->e.symbol->s.def); internal_error (e, "not an integer constant"); } diff --git a/tools/qfcc/source/switch.c b/tools/qfcc/source/switch.c index 94a3ddbf9..c4878baee 100644 --- a/tools/qfcc/source/switch.c +++ b/tools/qfcc/source/switch.c @@ -133,7 +133,7 @@ case_label_expr (switch_block_t *switch_block, expr_t *value) if (!type_assignable (type, get_type (value))) return error (value, "type mismatch in case label"); if (is_integral (type) && is_integral (val_type)) { - // do nothing + value = new_integer_expr (expr_integer (value)); debug (value, "integeral label used in integral switch"); } else if (is_integral (type) && is_float (val_type)) { warning (value, "float label used in integral switch"); @@ -142,7 +142,7 @@ case_label_expr (switch_block_t *switch_block, expr_t *value) debug (value, "integeral label used in float switch"); value = new_float_expr (expr_integer (value)); } else if (is_float (type) && is_float (val_type)) { - // do nothing + value = new_float_expr (expr_float (value)); debug (value, "float label used in float switch"); } }