break, continue outside of a loop, match statement handled
(cherry picked from commit c076a2b7e9
)
This commit is contained in:
parent
000899647a
commit
9ee77179b5
|
@ -3092,6 +3092,8 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
|
||||||
|
|
||||||
cf_while->body = alloc_node<BlockNode>();
|
cf_while->body = alloc_node<BlockNode>();
|
||||||
cf_while->body->parent_block = p_block;
|
cf_while->body->parent_block = p_block;
|
||||||
|
cf_while->body->can_break = true;
|
||||||
|
cf_while->body->can_continue = true;
|
||||||
p_block->sub_blocks.push_back(cf_while->body);
|
p_block->sub_blocks.push_back(cf_while->body);
|
||||||
|
|
||||||
if (!_enter_indent_block(cf_while->body)) {
|
if (!_enter_indent_block(cf_while->body)) {
|
||||||
|
@ -3211,6 +3213,8 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
|
||||||
|
|
||||||
cf_for->body = alloc_node<BlockNode>();
|
cf_for->body = alloc_node<BlockNode>();
|
||||||
cf_for->body->parent_block = p_block;
|
cf_for->body->parent_block = p_block;
|
||||||
|
cf_for->body->can_break = true;
|
||||||
|
cf_for->body->can_continue = true;
|
||||||
p_block->sub_blocks.push_back(cf_for->body);
|
p_block->sub_blocks.push_back(cf_for->body);
|
||||||
|
|
||||||
if (!_enter_indent_block(cf_for->body)) {
|
if (!_enter_indent_block(cf_for->body)) {
|
||||||
|
@ -3240,6 +3244,20 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
|
||||||
p_block->statements.push_back(cf_for);
|
p_block->statements.push_back(cf_for);
|
||||||
} break;
|
} break;
|
||||||
case GDScriptTokenizer::TK_CF_CONTINUE: {
|
case GDScriptTokenizer::TK_CF_CONTINUE: {
|
||||||
|
BlockNode *upper_block = p_block;
|
||||||
|
bool is_continue_valid = false;
|
||||||
|
while (upper_block) {
|
||||||
|
if (upper_block->can_continue) {
|
||||||
|
is_continue_valid = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
upper_block = upper_block->parent_block;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_continue_valid) {
|
||||||
|
_set_error("Unexpected keyword \"continue\" outside a loop.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_mark_line_as_safe(tokenizer->get_token_line());
|
_mark_line_as_safe(tokenizer->get_token_line());
|
||||||
tokenizer->advance();
|
tokenizer->advance();
|
||||||
|
@ -3252,6 +3270,20 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case GDScriptTokenizer::TK_CF_BREAK: {
|
case GDScriptTokenizer::TK_CF_BREAK: {
|
||||||
|
BlockNode *upper_block = p_block;
|
||||||
|
bool is_break_valid = false;
|
||||||
|
while (upper_block) {
|
||||||
|
if (upper_block->can_break) {
|
||||||
|
is_break_valid = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
upper_block = upper_block->parent_block;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_break_valid) {
|
||||||
|
_set_error("Unexpected keyword \"break\" outside a loop.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_mark_line_as_safe(tokenizer->get_token_line());
|
_mark_line_as_safe(tokenizer->get_token_line());
|
||||||
tokenizer->advance();
|
tokenizer->advance();
|
||||||
|
@ -3320,6 +3352,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
|
||||||
BlockNode *compiled_branches = alloc_node<BlockNode>();
|
BlockNode *compiled_branches = alloc_node<BlockNode>();
|
||||||
compiled_branches->parent_block = p_block;
|
compiled_branches->parent_block = p_block;
|
||||||
compiled_branches->parent_class = p_block->parent_class;
|
compiled_branches->parent_class = p_block->parent_class;
|
||||||
|
compiled_branches->can_continue = true;
|
||||||
|
|
||||||
p_block->sub_blocks.push_back(compiled_branches);
|
p_block->sub_blocks.push_back(compiled_branches);
|
||||||
|
|
||||||
|
|
|
@ -240,7 +240,9 @@ public:
|
||||||
BlockNode *parent_block;
|
BlockNode *parent_block;
|
||||||
List<Node *> statements;
|
List<Node *> statements;
|
||||||
Map<StringName, LocalVarNode *> variables;
|
Map<StringName, LocalVarNode *> variables;
|
||||||
bool has_return;
|
bool has_return = false;
|
||||||
|
bool can_break = false;
|
||||||
|
bool can_continue = false;
|
||||||
|
|
||||||
Node *if_condition; //tiny hack to improve code completion on if () blocks
|
Node *if_condition; //tiny hack to improve code completion on if () blocks
|
||||||
|
|
||||||
|
@ -253,7 +255,6 @@ public:
|
||||||
end_line = -1;
|
end_line = -1;
|
||||||
parent_block = NULL;
|
parent_block = NULL;
|
||||||
parent_class = NULL;
|
parent_class = NULL;
|
||||||
has_return = false;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue