diff --git a/tools/qfcc/include/value.h b/tools/qfcc/include/value.h index 8edc6850c..941423ef7 100644 --- a/tools/qfcc/include/value.h +++ b/tools/qfcc/include/value.h @@ -54,7 +54,8 @@ struct ex_value_s *new_uinteger_val (int uinteger_val); struct ex_value_s *new_short_val (short short_val); struct ex_value_s *new_nil_val (struct type_s *type); -void convert_value (struct ex_value_s *value, struct type_s *type); +struct ex_value_s * convert_value (struct ex_value_s *value, + struct type_s *type); struct def_s *emit_value (struct ex_value_s *value, struct def_s *def); int ReuseString (const char *str); diff --git a/tools/qfcc/source/def.c b/tools/qfcc/source/def.c index e6825374a..c56641534 100644 --- a/tools/qfcc/source/def.c +++ b/tools/qfcc/source/def.c @@ -569,14 +569,14 @@ initialize_def (symbol_t *sym, type_t *type, expr_t *init, defspace_t *space, if (init->e.value->v.pointer.def) reloc_def_field (init->e.value->v.pointer.def, sym->s.def); } else { - ex_value_t v = *init->e.value; + ex_value_t *v = init->e.value; if (is_scalar (sym->type)) - convert_value (&v, sym->type); - if (v.type == ev_string) { + v = convert_value (v, sym->type); + if (v->type == ev_string) { EMIT_STRING (sym->s.def->space, D_STRING (sym->s.def), - v.v.string_val); + v->v.string_val); } else { - memcpy (D_POINTER (void, sym->s.def), &v.v, + memcpy (D_POINTER (void, sym->s.def), &v->v, type_size (type) * sizeof (pr_type_t)); } } diff --git a/tools/qfcc/source/value.c b/tools/qfcc/source/value.c index 332981157..6234a1ce6 100644 --- a/tools/qfcc/source/value.c +++ b/tools/qfcc/source/value.c @@ -373,30 +373,26 @@ value_as_uint (ex_value_t *value) return 0; } -void +ex_value_t * convert_value (ex_value_t *value, type_t *type) { if (!is_scalar (type) || !is_scalar (ev_types[value->type])) { error (0, "unable to convert non-scalar value"); - return; + return value; } if (is_float (type)) { float val = value_as_float (value); - value->type = ev_float; - value->v.float_val = val; + return new_float_val (val); } else if (type->type == ev_short) { int val = value_as_int (value); - value->type = ev_short; - value->v.short_val = val; + return new_short_val (val); } else if (type->type == ev_uinteger) { unsigned val = value_as_uint (value); - value->type = ev_uinteger; - value->v.uinteger_val = val; + return new_uinteger_val (val); } else { //FIXME handle enums separately? int val = value_as_int (value); - value->type = ev_integer; - value->v.integer_val = val; + return new_integer_val (val); } }