aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-05-01 17:59:30 +0100
committergingerBill <bill@gingerbill.org>2021-05-01 17:59:30 +0100
commitced7700cdb45ac4a5850e8eaf6fa2dd4cba4b1cf (patch)
treed2fadf8de0ea276bce9705ad516dfed61ad0d8c2 /src/parser.cpp
parent406d2ab6ba8a5906df634fc5f00c40b6983a0c39 (diff)
Add extra check for `#no_bounds_check` etc being followed by a newline or empty statement
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index c9275c7f2..12f0fb9be 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -4341,6 +4341,16 @@ Ast *parse_unrolled_for_loop(AstFile *f, Token unroll_token) {
return ast_unroll_range_stmt(f, unroll_token, for_token, val0, val1, in_token, expr, body);
}
+void parse_check_directive_for_empty_statement(Ast *s, Token const &name) {
+ if (s != nullptr && s->kind == Ast_EmptyStmt) {
+ if (s->EmptyStmt.token.string == "\n") {
+ syntax_error(name, "#%.*s cannot be followed by a newline", LIT(name.string));
+ } else {
+ syntax_error(name, "#%.*s cannot be applied to an empty statement ';'", LIT(name.string));
+ }
+ }
+}
+
Ast *parse_stmt(AstFile *f) {
Ast *s = nullptr;
Token token = f->curr_token;
@@ -4447,6 +4457,7 @@ Ast *parse_stmt(AstFile *f) {
if (tag == "bounds_check") {
s = parse_stmt(f);
+ parse_check_directive_for_empty_statement(s, name);
s->state_flags |= StateFlag_bounds_check;
if ((s->state_flags & StateFlag_no_bounds_check) != 0) {
syntax_error(token, "#bounds_check and #no_bounds_check cannot be applied together");
@@ -4454,27 +4465,12 @@ Ast *parse_stmt(AstFile *f) {
return s;
} else if (tag == "no_bounds_check") {
s = parse_stmt(f);
+ parse_check_directive_for_empty_statement(s, name);
s->state_flags |= StateFlag_no_bounds_check;
if ((s->state_flags & StateFlag_bounds_check) != 0) {
syntax_error(token, "#bounds_check and #no_bounds_check cannot be applied together");
}
return s;
- } else if (tag == "complete") {
- s = parse_stmt(f);
- switch (s->kind) {
- case Ast_SwitchStmt:
- s->SwitchStmt.partial = false;
- syntax_warning(token, "#complete is now the default and has been replaced with its opposite: #partial");
- break;
- case Ast_TypeSwitchStmt:
- s->TypeSwitchStmt.partial = false;
- syntax_warning(token, "#complete is now the default and has been replaced with its opposite: #partial");
- break;
- default:
- syntax_error(token, "#complete can only be applied to a switch statement");
- break;
- }
- return s;
} else if (tag == "partial") {
s = parse_stmt(f);
switch (s->kind) {
@@ -4484,6 +4480,9 @@ Ast *parse_stmt(AstFile *f) {
case Ast_TypeSwitchStmt:
s->TypeSwitchStmt.partial = true;
break;
+ case Ast_EmptyStmt:
+ parse_check_directive_for_empty_statement(s, name);
+ break;
default:
syntax_error(token, "#partial can only be applied to a switch statement");
break;