mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-22 02:11:19 +00:00
Make convert_value create a new value.
It operating in-place proved to be troublesome.
This commit is contained in:
parent
a099847026
commit
7071a46936
3 changed files with 13 additions and 16 deletions
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue