]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
'noreturn' is now an attribute and parsed as [[noreturn]]
authorWolfgang Bumiller <blub@speed.at>
Sat, 22 Dec 2012 17:09:33 +0000 (18:09 +0100)
committerWolfgang Bumiller <blub@speed.at>
Sat, 22 Dec 2012 17:09:56 +0000 (18:09 +0100)
parser.c
tests/noreturn.qc
tests/noreturn1.tmpl
tests/noreturn2.tmpl

index 64e189ce6301aba18b7cfc23dccb968142dfb8f9..a941f032e17d0fa08ec880e16080491ce93fc6f7 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -2350,8 +2350,40 @@ static bool parse_var_qualifiers(parser_t *parser, bool with_local, int *cvq, bo
     bool had_noref = false;
     bool had_noreturn = false;
 
+    *cvq = CV_WRONG;
     for (;;) {
-        if (!strcmp(parser_tokval(parser), "const"))
+        if (parser->tok == TOKEN_ATTRIBUTE_OPEN) {
+            /* parse an attribute */
+            if (!parser_next(parser)) {
+                parseerror(parser, "expected attribute after `[[`");
+                return false;
+            }
+            if (!strcmp(parser_tokval(parser), "noreturn")) {
+                had_noreturn = true;
+                if (!parser_next(parser) || parser->tok != TOKEN_ATTRIBUTE_CLOSE) {
+                    parseerror(parser, "`noreturn` attribute has no parameters, expected `]]`");
+                    return false;
+                }
+            }
+            else if (!strcmp(parser_tokval(parser), "noref")) {
+                had_noref = true;
+                if (!parser_next(parser) || parser->tok != TOKEN_ATTRIBUTE_CLOSE) {
+                    parseerror(parser, "`noref` attribute has no parameters, expected `]]`");
+                    return false;
+                }
+            }
+            else
+            {
+                /* Skip tokens until we hit a ]] */
+                while (parser->tok != TOKEN_ATTRIBUTE_CLOSE) {
+                    if (!parser_next(parser)) {
+                        parseerror(parser, "error inside attribute");
+                        return false;
+                    }
+                }
+            }
+        }
+        else if (!strcmp(parser_tokval(parser), "const"))
             had_const = true;
         else if (!strcmp(parser_tokval(parser), "var"))
             had_var = true;
@@ -2359,8 +2391,6 @@ static bool parse_var_qualifiers(parser_t *parser, bool with_local, int *cvq, bo
             had_var = true;
         else if (!strcmp(parser_tokval(parser), "noref"))
             had_noref = true;
-        else if (!strcmp(parser_tokval(parser), "noreturn"))
-            had_noreturn = true;
         else if (!had_const && !had_var && !had_noref && !had_noreturn) {
             return false;
         }
index 1437b0611ec4f3d2b435091d29d17f358fd87d7f..e56cc8810059c346211642e1653a6f98332cb389 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef NORETURN
-#define NORETURN noreturn
+#define NORETURN [[noreturn]]
 #endif
 
 void          print(...)  = #1;
index db507dd86f069fbb7d6eca6695f45868174538a4..0f6aad138a292c0c283a489a09367a10b38d3546 100644 (file)
@@ -1,4 +1,4 @@
 I: noreturn.qc
 D: noreturn keyword - should work
 T: -compile
-C: -std=fteqcc -Wall -Werror -DTEST=1 -DNORETURN=noreturn
+C: -std=fteqcc -Wall -Werror -DTEST=1 -DNORETURN=[[noreturn]]
index d5d73c2dd8e8dc73e3e062f764bb1a8e66bdd738..8d7ad09c55f572f8c7a1808e80ad227fbfbfbfda 100644 (file)
@@ -1,4 +1,4 @@
 I: noreturn.qc
 D: noreturn keyword - should fail
 T: -compile
-C: -std=fteqcc -Wall -Werror -DTEST=2 -DNORETURN=noreturn
+C: -std=fteqcc -Wall -Werror -DTEST=2 -DNORETURN=[[noreturn]]