GDScript: Fix checking if a call is awaited in compiler

This commit is contained in:
Dmitrii Maganov 2023-03-01 08:47:09 +02:00
parent 2e530c1317
commit 55a2ad25bf
2 changed files with 8 additions and 6 deletions

View File

@ -511,6 +511,7 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code
} break; } break;
case GDScriptParser::Node::CALL: { case GDScriptParser::Node::CALL: {
const GDScriptParser::CallNode *call = static_cast<const GDScriptParser::CallNode *>(p_expression); const GDScriptParser::CallNode *call = static_cast<const GDScriptParser::CallNode *>(p_expression);
bool is_awaited = p_expression == awaited_node;
GDScriptDataType type = _gdtype_from_datatype(call->get_datatype(), codegen.script); GDScriptDataType type = _gdtype_from_datatype(call->get_datatype(), codegen.script);
GDScriptCodeGenerator::Address result; GDScriptCodeGenerator::Address result;
if (p_root) { if (p_root) {
@ -565,13 +566,13 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code
} else if ((codegen.function_node && codegen.function_node->is_static) || call->function_name == "new") { } else if ((codegen.function_node && codegen.function_node->is_static) || call->function_name == "new") {
GDScriptCodeGenerator::Address self; GDScriptCodeGenerator::Address self;
self.mode = GDScriptCodeGenerator::Address::CLASS; self.mode = GDScriptCodeGenerator::Address::CLASS;
if (within_await) { if (is_awaited) {
gen->write_call_async(result, self, call->function_name, arguments); gen->write_call_async(result, self, call->function_name, arguments);
} else { } else {
gen->write_call(result, self, call->function_name, arguments); gen->write_call(result, self, call->function_name, arguments);
} }
} else { } else {
if (within_await) { if (is_awaited) {
gen->write_call_self_async(result, call->function_name, arguments); gen->write_call_self_async(result, call->function_name, arguments);
} else { } else {
gen->write_call_self(result, call->function_name, arguments); gen->write_call_self(result, call->function_name, arguments);
@ -593,7 +594,7 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code
if (r_error) { if (r_error) {
return GDScriptCodeGenerator::Address(); return GDScriptCodeGenerator::Address();
} }
if (within_await) { if (is_awaited) {
gen->write_call_async(result, base, call->function_name, arguments); gen->write_call_async(result, base, call->function_name, arguments);
} else if (base.type.has_type && base.type.kind != GDScriptDataType::BUILTIN) { } else if (base.type.has_type && base.type.kind != GDScriptDataType::BUILTIN) {
// Native method, use faster path. // Native method, use faster path.
@ -666,9 +667,10 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code
const GDScriptParser::AwaitNode *await = static_cast<const GDScriptParser::AwaitNode *>(p_expression); const GDScriptParser::AwaitNode *await = static_cast<const GDScriptParser::AwaitNode *>(p_expression);
GDScriptCodeGenerator::Address result = codegen.add_temporary(_gdtype_from_datatype(p_expression->get_datatype(), codegen.script)); GDScriptCodeGenerator::Address result = codegen.add_temporary(_gdtype_from_datatype(p_expression->get_datatype(), codegen.script));
within_await = true; GDScriptParser::ExpressionNode *previous_awaited_node = awaited_node;
awaited_node = await->to_await;
GDScriptCodeGenerator::Address argument = _parse_expression(codegen, r_error, await->to_await); GDScriptCodeGenerator::Address argument = _parse_expression(codegen, r_error, await->to_await);
within_await = false; awaited_node = previous_awaited_node;
if (r_error) { if (r_error) {
return GDScriptCodeGenerator::Address(); return GDScriptCodeGenerator::Address();
} }

View File

@ -137,7 +137,7 @@ class GDScriptCompiler {
int err_column = 0; int err_column = 0;
StringName source; StringName source;
String error; String error;
bool within_await = false; GDScriptParser::ExpressionNode *awaited_node = nullptr;
public: public:
static void convert_to_initializer_type(Variant &p_variant, const GDScriptParser::VariableNode *p_node); static void convert_to_initializer_type(Variant &p_variant, const GDScriptParser::VariableNode *p_node);