]> de.git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
-frelaxed-switch to enable switch on non-constant cases
authorWolfgang (Blub) Bumiller <blub@speed.at>
Mon, 19 Nov 2012 21:27:58 +0000 (22:27 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Mon, 19 Nov 2012 21:27:58 +0000 (22:27 +0100)
opts.def
parser.c

index 9b648336207458f33064568e9118af08fb74248b..705eb0c4faee396beb2876f362254f314bd70959 100644 (file)
--- a/opts.def
+++ b/opts.def
@@ -32,6 +32,7 @@
     GMQCC_DEFINE_FLAG(OMIT_NULL_BYTES)
     GMQCC_DEFINE_FLAG(ADJUST_VECTOR_FIELDS)
     GMQCC_DEFINE_FLAG(FTEPP)
+    GMQCC_DEFINE_FLAG(RELAXED_SWITCH)
 #endif
 
 /* warning flags */
index b45fe62bb266a7a24e4fe5dfcaf26492b568a9e2..99b7eb7bace4f651eb2fbf37d221cd18a14444cb 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1741,6 +1741,7 @@ static bool parse_break_continue(parser_t *parser, ast_block *block, ast_express
 static bool parse_switch(parser_t *parser, ast_block *block, ast_expression **out)
 {
     ast_expression *operand;
+    ast_value      *opval;
     ast_switch     *switchnode;
     ast_switch_case swcase;
 
@@ -1762,6 +1763,15 @@ static bool parse_switch(parser_t *parser, ast_block *block, ast_expression **ou
     if (!operand)
         return false;
 
+    if (!OPTS_FLAG(RELAXED_SWITCH)) {
+        opval = (ast_value*)operand;
+        if (!ast_istype(operand, ast_value) || !opval->isconst) {
+            parseerror(parser, "case on non-constant values need to be explicitly enabled via -frelaxed-switch");
+            ast_unref(operand);
+            return false;
+        }
+    }
+
     switchnode = ast_switch_new(ctx, operand);
 
     /* closing paren */
@@ -1988,9 +1998,11 @@ static bool GMQCC_WARN parser_pop_local(parser_t *parser)
     varentry_t *ve;
 
     ve = &vec_last(parser->locals);
-    if (ast_istype(ve->var, ast_value) && !(((ast_value*)(ve->var))->uses)) {
-        if (parsewarning(parser, WARN_UNUSED_VARIABLE, "unused variable: `%s`", ve->name))
-            rv = false;
+    if (!parser->errors) {
+        if (ast_istype(ve->var, ast_value) && !(((ast_value*)(ve->var))->uses)) {
+            if (parsewarning(parser, WARN_UNUSED_VARIABLE, "unused variable: `%s`", ve->name))
+                rv = false;
+        }
     }
     mem_d(ve->name);
     vec_pop(parser->locals);