From 7cf0ba5aa88bf09c2a91690dce29721ba7147b65 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Sat, 22 Dec 2012 18:09:33 +0100 Subject: [PATCH] 'noreturn' is now an attribute and parsed as [[noreturn]] --- parser.c | 36 +++++++++++++++++++++++++++++++++--- tests/noreturn.qc | 2 +- tests/noreturn1.tmpl | 2 +- tests/noreturn2.tmpl | 2 +- 4 files changed, 36 insertions(+), 6 deletions(-) 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]] -- 2.39.2