Make symbols use the new value struct for constants.

This commit is contained in:
Bill Currie 2011-01-19 11:09:54 +09:00
parent e08efe036b
commit f2ef24d0cc
5 changed files with 18 additions and 15 deletions

View file

@ -32,6 +32,8 @@
#ifndef __symtab_h
#define __symtab_h
#include "expr.h"
/** \defgroup qfcc_symtab Symbol Table Management
\ingroup qfcc
*/
@ -60,7 +62,8 @@ typedef struct symbol_s {
struct type_s *type; ///< type of object to which symbol refers
struct param_s *params; ///< the parameters if a function
union {
int value;
int offset;
struct ex_value_s value;
struct expr_s *expr;
struct function_s *func;
} s;

View file

@ -705,7 +705,7 @@ expr_float (expr_t *e)
return e->e.value.v.float_val;
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;
return e->e.symbol->s.value.v.float_val;
internal_error (e, "not a float constant");
}
@ -729,9 +729,9 @@ expr_vector (expr_t *e)
return vec3_origin;
if (e->type == ex_value && e->e.value.type == ev_vector)
return e->e.value.v.vector_val;
//if (e->type == ex_symbol && e->e.symbol->sy_type == sy_const
// && e->e.symbol->type->type == ev_vector)
// return e->e.symbol->s.value;
if (e->type == ex_symbol && e->e.symbol->sy_type == sy_const
&& e->e.symbol->type->type == ev_vector)
return e->e.symbol->s.value.v.vector_val;
internal_error (e, "not a vector constant");
}
@ -755,9 +755,9 @@ expr_quaternion (expr_t *e)
return quat_origin;
if (e->type == ex_value && e->e.value.type == ev_quat)
return e->e.value.v.quaternion_val;
//if (e->type == ex_symbol && e->e.symbol->sy_type == sy_const
// && e->e.symbol->type->type == ev_quat)
// return e->e.symbol->s.value;
if (e->type == ex_symbol && e->e.symbol->sy_type == sy_const
&& e->e.symbol->type->type == ev_quat)
return e->e.symbol->s.value.v.quaternion_val;
internal_error (e, "not a quaternion constant");
}
@ -783,7 +783,7 @@ expr_integer (expr_t *e)
return e->e.value.v.integer_val;
if (e->type == ex_symbol && e->e.symbol->sy_type == sy_const
&& e->e.symbol->type->type == ev_integer)
return e->e.symbol->s.value;
return e->e.symbol->s.value.v.integer_val;
internal_error (e, "not an integer constant");
}
@ -809,7 +809,7 @@ expr_short (expr_t *e)
return e->e.value.v.short_val;
if (e->type == ex_symbol && e->e.symbol->sy_type == sy_const
&& e->e.symbol->type->type == ev_short)
return e->e.symbol->s.value;
return e->e.symbol->s.value.v.short_val;
internal_error (e, "not a short constant");
}

View file

@ -114,7 +114,7 @@ build_struct (int su, symbol_t *tag, symtab_t *symtab, type_t *type)
if (s->sy_type != sy_var)
continue;
if (su == 's') {
s->s.value = symtab->size;
s->s.offset = symtab->size;
symtab->size += type_size (s->type);
} else {
int size = type_size (s->type);
@ -160,7 +160,7 @@ add_enum (symbol_t *enm, symbol_t *name, expr_t *val)
enum_tab = enum_type->t.symtab;
value = 0;
if (*enum_tab->symtail)
value = ((symbol_t *)(*enum_tab->symtail))->s.value + 1;
value = ((symbol_t *)(*enum_tab->symtail))->s.value.v.integer_val + 1;
if (val) {
val = constant_expr (val);
if (!is_constant (val))
@ -170,7 +170,7 @@ add_enum (symbol_t *enm, symbol_t *name, expr_t *val)
else
value = expr_integer (val);
}
name->s.value = value;
name->s.value.v.integer_val = value;
symtab_addsymbol (enum_tab, name);
}

View file

@ -69,7 +69,7 @@ static uintptr_t
get_value (expr_t *e)
{
if (e->type == ex_symbol)
return e->e.symbol->s.value;
return e->e.symbol->s.value.v.integer_val; //FIXME pointer
return e->e.value.v.integer_val;
}

View file

@ -406,7 +406,7 @@ encode_enum (dstring_t *encoding, type_t *type, int level)
dasprintf (encoding, "{%s#", name);
if (level < 2) {
for (e = enm->symbols; e; e = e->next) {
dasprintf (encoding, "%s=%d%s", e->name, e->s.value,
dasprintf (encoding, "%s=%d%s", e->name, e->s.value.v.integer_val,
e->next ? "," : "");
}
}