From 29df4ac7eedfef00c1a03d293e66c67d4b37460c Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 26 Jun 2013 08:40:25 +0900 Subject: [PATCH] Fix case label lookup. It looks like I had forgotten that the compare function is supposed to return true/false (unlike memcmp's sorting ability). Also, avoid the pointers in the value struct as they can change without notice. Using enums in switches now works nicely, including warnings for unused enum values. --- tools/qfcc/TODO | 2 +- tools/qfcc/source/switch.c | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/qfcc/TODO b/tools/qfcc/TODO index f9867c2b3..368ea6e77 100644 --- a/tools/qfcc/TODO +++ b/tools/qfcc/TODO @@ -6,13 +6,13 @@ I = in progress W = waiting on other work X fix object files +X fix enums in switch statements (use tables (treat as int), check missing) M arrays in structures M unnamed function parameters for prototypes/typdefs etc. I optimizations (esp CSE) I fix used/uninitialized warnings o id id; o vec = [x, y, z]; expressions (nice feature in fteqcc) -o fix enums in switch statements (use tables (treat as int), check missing) o arrays in entities o optional arguments for functions (alternative to overloading) vector(vector fwd, optional vector up) vectoangles = #51; diff --git a/tools/qfcc/source/switch.c b/tools/qfcc/source/switch.c index f2665b63d..dee8bac5f 100644 --- a/tools/qfcc/source/switch.c +++ b/tools/qfcc/source/switch.c @@ -68,6 +68,8 @@ get_value (expr_t *e) { if (e->type == ex_symbol) return e->e.symbol->s.value; + if (e->type != ex_value) + internal_error (e, "bogus case label"); return e->e.value; } @@ -80,7 +82,7 @@ get_hash (const void *_cl, void *unused) if (!cl->value) return 0; val = get_value (cl->value); - return Hash_Buffer (val, sizeof (*val)); + return Hash_Buffer (&val->v, sizeof (val->v)) + val->type; } static int @@ -99,8 +101,10 @@ compare (const void *_cla, const void *_clb, void *unused) if (extract_type (v1) != extract_type (v2)) return 0; val1 = get_value (v1); - val2 = get_value (v1); - return memcmp (val1, val2, sizeof (*val1)); + val2 = get_value (v2); + if (val1->type != val2->type) + return 0; + return memcmp (&val1->v, &val2->v, sizeof (val1->v)) == 0; } struct expr_s *