aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-12-08 14:12:52 +0000
committergingerBill <bill@gingerbill.org>2018-12-08 14:12:52 +0000
commitd05837ab6dc291ee8ee3d94b33f86a6472c5847f (patch)
tree67192ab848409750fa6371eabf7680a4800ce8d3 /src/parser.cpp
parent4369a1714e9e039abc09bdb095b8044ad2f5d2ff (diff)
Labels for block and if statements (break only)
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index bce0260cb..dc1a22780 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -223,9 +223,11 @@ Ast *clone_ast(Ast *node) {
n->IncDecStmt.expr = clone_ast(n->IncDecStmt.expr);
break;
case Ast_BlockStmt:
+ n->BlockStmt.label = clone_ast(n->BlockStmt.label);
n->BlockStmt.stmts = clone_ast_array(n->BlockStmt.stmts);
break;
case Ast_IfStmt:
+ n->IfStmt.label = clone_ast(n->IfStmt.label);
n->IfStmt.init = clone_ast(n->IfStmt.init);
n->IfStmt.cond = clone_ast(n->IfStmt.cond);
n->IfStmt.body = clone_ast(n->IfStmt.body);
@@ -2637,6 +2639,8 @@ Ast *parse_simple_stmt(AstFile *f, u32 flags) {
expect_token_after(f, Token_Colon, "identifier list");
if ((flags&StmtAllowFlag_Label) && lhs.count == 1) {
switch (f->curr_token.kind) {
+ case Token_OpenBrace: // block statement
+ case Token_if:
case Token_for:
case Token_switch: {
Ast *name = lhs[0];
@@ -2644,6 +2648,8 @@ Ast *parse_simple_stmt(AstFile *f, u32 flags) {
Ast *stmt = parse_stmt(f);
#define _SET_LABEL(Kind_, label_) case GB_JOIN2(Ast_, Kind_): (stmt->Kind_).label = label_; break
switch (stmt->kind) {
+ _SET_LABEL(BlockStmt, label);
+ _SET_LABEL(IfStmt, label);
_SET_LABEL(ForStmt, label);
_SET_LABEL(RangeStmt, label);
_SET_LABEL(SwitchStmt, label);