summaryrefslogtreecommitdiff
path: root/modules/gdscript/gd_compiler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdscript/gd_compiler.cpp')
-rw-r--r--modules/gdscript/gd_compiler.cpp37
1 files changed, 33 insertions, 4 deletions
diff --git a/modules/gdscript/gd_compiler.cpp b/modules/gdscript/gd_compiler.cpp
index a62225f663..7b07010529 100644
--- a/modules/gdscript/gd_compiler.cpp
+++ b/modules/gdscript/gd_compiler.cpp
@@ -1156,6 +1156,10 @@ Error GDCompiler::_parse_block(CodeGen& codegen,const GDParser::BlockNode *p_blo
codegen.opcodes.push_back(GDFunction::OPCODE_ASSERT);
codegen.opcodes.push_back(ret);
} break;
+ case GDParser::Node::TYPE_BREAKPOINT: {
+ // try subblocks
+ codegen.opcodes.push_back(GDFunction::OPCODE_BREAKPOINT);
+ } break;
case GDParser::Node::TYPE_LOCAL_VAR: {
@@ -1181,7 +1185,7 @@ Error GDCompiler::_parse_block(CodeGen& codegen,const GDParser::BlockNode *p_blo
}
-Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode *p_class,const GDParser::FunctionNode *p_func) {
+Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode *p_class,const GDParser::FunctionNode *p_func,bool p_for_ready) {
Vector<int> bytecode;
CodeGen codegen;
@@ -1212,9 +1216,9 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode *
/* Parse initializer -if applies- */
- bool is_initializer=false || !p_func;
+ bool is_initializer=!p_for_ready && !p_func;
- if (!p_func || String(p_func->name)=="_init") {
+ if (is_initializer || (p_func && String(p_func->name)=="_init")) {
//parse initializer for class members
if (!p_func && p_class->extends_used && p_script->native.is_null()){
@@ -1232,6 +1236,17 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode *
}
+ if (p_for_ready || (p_func && String(p_func->name)=="_ready")) {
+ //parse initializer for class members
+ if (p_class->ready->statements.size()) {
+ Error err = _parse_block(codegen,p_class->ready,stack_level);
+ if (err)
+ return err;
+ }
+
+ }
+
+
/* Parse default argument code -if applies- */
Vector<int> defarg_addr;
@@ -1260,7 +1275,10 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode *
func_name=p_func->name;
} else {
- func_name="_init";
+ if (p_for_ready)
+ func_name="_ready";
+ else
+ func_name="_init";
}
codegen.opcodes.push_back(GDFunction::OPCODE_END);
@@ -1614,10 +1632,14 @@ Error GDCompiler::_parse_class(GDScript *p_script,GDScript *p_owner,const GDPars
//parse methods
bool has_initializer=false;
+ bool has_ready=false;
+
for(int i=0;i<p_class->functions.size();i++) {
if (!has_initializer && p_class->functions[i]->name=="_init")
has_initializer=true;
+ if (!has_ready && p_class->functions[i]->name=="_ready")
+ has_ready=true;
Error err = _parse_function(p_script,p_class,p_class->functions[i]);
if (err)
return err;
@@ -1640,6 +1662,13 @@ Error GDCompiler::_parse_class(GDScript *p_script,GDScript *p_owner,const GDPars
return err;
}
+ if (!has_ready && p_class->ready->statements.size()) {
+ //create a constructor
+ Error err = _parse_function(p_script,p_class,NULL,true);
+ if (err)
+ return err;
+ }
+
#ifdef DEBUG_ENABLED
//validate setters/getters if debug is enabled
for(int i=0;i<p_class->variables.size();i++) {