From: Wolfgang Bumiller Date: Sat, 22 Dec 2012 17:09:33 +0000 (+0100) Subject: 'noreturn' is now an attribute and parsed as [[noreturn]] X-Git-Tag: 0.2~12^2~6 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=7cf0ba5aa88bf09c2a91690dce29721ba7147b65;p=xonotic%2Fgmqcc.git 'noreturn' is now an attribute and parsed as [[noreturn]] --- diff --git a/parser.c b/parser.c index 64e189c..a941f03 100644 --- 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; } diff --git a/tests/noreturn.qc b/tests/noreturn.qc index 1437b06..e56cc88 100644 --- a/tests/noreturn.qc +++ b/tests/noreturn.qc @@ -1,5 +1,5 @@ #ifndef NORETURN -#define NORETURN noreturn +#define NORETURN [[noreturn]] #endif void print(...) = #1; diff --git a/tests/noreturn1.tmpl b/tests/noreturn1.tmpl index db507dd..0f6aad1 100644 --- a/tests/noreturn1.tmpl +++ b/tests/noreturn1.tmpl @@ -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]] diff --git a/tests/noreturn2.tmpl b/tests/noreturn2.tmpl index d5d73c2..8d7ad09 100644 --- a/tests/noreturn2.tmpl +++ b/tests/noreturn2.tmpl @@ -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]]