mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 12:52:46 +00:00
Support enum results for boolean expressions.
eg enum BOOL x = a && b;
This commit is contained in:
parent
c06dd776d2
commit
c12211d8bb
3 changed files with 38 additions and 0 deletions
|
@ -52,6 +52,8 @@ struct symbol_s *find_enum (struct symbol_s *tag);
|
|||
struct symtab_s *start_enum (struct symbol_s *enm);
|
||||
void add_enum (struct symbol_s *enm, struct symbol_s *name,
|
||||
struct expr_s *val);
|
||||
int enum_as_bool (struct type_s *enm, struct expr_s **zero,
|
||||
struct expr_s **one);
|
||||
|
||||
struct symbol_s *make_structure (const char *name, int su, struct_def_t *defs,
|
||||
struct type_s *type);
|
||||
|
|
|
@ -1107,6 +1107,8 @@ convert_from_bool (expr_t *e, type_t *type)
|
|||
} else if (type == &type_integer) {
|
||||
one = new_integer_expr (1);
|
||||
zero = new_integer_expr (0);
|
||||
} else if (is_enum (type) && enum_as_bool (type, &zero, &one)) {
|
||||
// don't need to do anything
|
||||
// } else if (type == &type_uinteger) {
|
||||
// one = new_uinteger_expr (1);
|
||||
// zero = new_uinteger_expr (0);
|
||||
|
|
|
@ -191,6 +191,40 @@ add_enum (symbol_t *enm, symbol_t *name, expr_t *val)
|
|||
symtab_addsymbol (enum_tab->parent, sym);
|
||||
}
|
||||
|
||||
int
|
||||
enum_as_bool (type_t *enm, expr_t **zero, expr_t **one)
|
||||
{
|
||||
symtab_t *symtab = enm->t.symtab;
|
||||
symbol_t *zero_sym = 0;
|
||||
symbol_t *one_sym = 0;
|
||||
symbol_t *sym;
|
||||
int val, v;
|
||||
|
||||
if (!symtab)
|
||||
return 0;
|
||||
for (sym = symtab->symbols; sym; sym = sym->next) {
|
||||
if (sym->sy_type != sy_const)
|
||||
continue;
|
||||
val = sym->s.value.v.integer_val;
|
||||
if (!val) {
|
||||
zero_sym = sym;
|
||||
} else {
|
||||
if (one_sym) {
|
||||
v = one_sym->s.value.v.integer_val;
|
||||
if (val * val > v * v)
|
||||
continue;
|
||||
}
|
||||
one_sym = sym;
|
||||
}
|
||||
|
||||
}
|
||||
if (!zero_sym || !one_sym)
|
||||
return 0;
|
||||
*zero = new_symbol_expr (zero_sym);
|
||||
*one = new_symbol_expr (one_sym);
|
||||
return 1;
|
||||
}
|
||||
|
||||
symbol_t *
|
||||
make_structure (const char *name, int su, struct_def_t *defs, type_t *type)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue