|
@@ -92,11 +92,10 @@ GDScriptDataType GDScriptCompiler::_gdtype_from_datatype(const GDScriptParser::D
|
|
}
|
|
}
|
|
|
|
|
|
GDScriptDataType result;
|
|
GDScriptDataType result;
|
|
- result.has_type = true;
|
|
|
|
|
|
|
|
switch (p_datatype.kind) {
|
|
switch (p_datatype.kind) {
|
|
case GDScriptParser::DataType::VARIANT: {
|
|
case GDScriptParser::DataType::VARIANT: {
|
|
- result.has_type = false;
|
|
|
|
|
|
+ result.kind = GDScriptDataType::VARIANT;
|
|
} break;
|
|
} break;
|
|
case GDScriptParser::DataType::BUILTIN: {
|
|
case GDScriptParser::DataType::BUILTIN: {
|
|
result.kind = GDScriptDataType::BUILTIN;
|
|
result.kind = GDScriptDataType::BUILTIN;
|
|
@@ -207,7 +206,7 @@ GDScriptDataType GDScriptCompiler::_gdtype_from_datatype(const GDScriptParser::D
|
|
}
|
|
}
|
|
|
|
|
|
static bool _is_exact_type(const PropertyInfo &p_par_type, const GDScriptDataType &p_arg_type) {
|
|
static bool _is_exact_type(const PropertyInfo &p_par_type, const GDScriptDataType &p_arg_type) {
|
|
- if (!p_arg_type.has_type) {
|
|
|
|
|
|
+ if (!p_arg_type.has_type()) {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
if (p_par_type.type == Variant::NIL) {
|
|
if (p_par_type.type == Variant::NIL) {
|
|
@@ -583,7 +582,7 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code
|
|
GDScriptDataType cast_type = _gdtype_from_datatype(cn->get_datatype(), codegen.script, false);
|
|
GDScriptDataType cast_type = _gdtype_from_datatype(cn->get_datatype(), codegen.script, false);
|
|
|
|
|
|
GDScriptCodeGenerator::Address result;
|
|
GDScriptCodeGenerator::Address result;
|
|
- if (cast_type.has_type) {
|
|
|
|
|
|
+ if (cast_type.has_type()) {
|
|
// Create temporary for result first since it will be deleted last.
|
|
// Create temporary for result first since it will be deleted last.
|
|
result = codegen.add_temporary(cast_type);
|
|
result = codegen.add_temporary(cast_type);
|
|
|
|
|
|
@@ -692,7 +691,7 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code
|
|
}
|
|
}
|
|
if (is_awaited) {
|
|
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.kind != GDScriptDataType::VARIANT && base.type.kind != GDScriptDataType::BUILTIN) {
|
|
// Native method, use faster path.
|
|
// Native method, use faster path.
|
|
StringName class_name;
|
|
StringName class_name;
|
|
if (base.type.kind == GDScriptDataType::NATIVE) {
|
|
if (base.type.kind == GDScriptDataType::NATIVE) {
|
|
@@ -712,7 +711,7 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code
|
|
} else {
|
|
} else {
|
|
gen->write_call(result, base, call->function_name, arguments);
|
|
gen->write_call(result, base, call->function_name, arguments);
|
|
}
|
|
}
|
|
- } else if (base.type.has_type && base.type.kind == GDScriptDataType::BUILTIN) {
|
|
|
|
|
|
+ } else if (base.type.kind == GDScriptDataType::BUILTIN) {
|
|
gen->write_call_builtin_type(result, base, base.type.builtin_type, call->function_name, arguments);
|
|
gen->write_call_builtin_type(result, base, base.type.builtin_type, call->function_name, arguments);
|
|
} else {
|
|
} else {
|
|
gen->write_call(result, base, call->function_name, arguments);
|
|
gen->write_call(result, base, call->function_name, arguments);
|
|
@@ -967,7 +966,7 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code
|
|
return GDScriptCodeGenerator::Address();
|
|
return GDScriptCodeGenerator::Address();
|
|
}
|
|
}
|
|
|
|
|
|
- if (test_type.has_type) {
|
|
|
|
|
|
+ if (test_type.has_type()) {
|
|
gen->write_type_test(result, operand, test_type);
|
|
gen->write_type_test(result, operand, test_type);
|
|
} else {
|
|
} else {
|
|
gen->write_assign_true(result);
|
|
gen->write_assign_true(result);
|
|
@@ -1067,7 +1066,7 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code
|
|
|
|
|
|
// Get at (potential) root stack pos, so it can be returned.
|
|
// Get at (potential) root stack pos, so it can be returned.
|
|
GDScriptCodeGenerator::Address base = _parse_expression(codegen, r_error, chain.back()->get()->base);
|
|
GDScriptCodeGenerator::Address base = _parse_expression(codegen, r_error, chain.back()->get()->base);
|
|
- const bool base_known_type = base.type.has_type;
|
|
|
|
|
|
+ const bool base_known_type = base.type.has_type();
|
|
const bool base_is_shared = Variant::is_type_shared(base.type.builtin_type);
|
|
const bool base_is_shared = Variant::is_type_shared(base.type.builtin_type);
|
|
|
|
|
|
if (r_error) {
|
|
if (r_error) {
|
|
@@ -1171,7 +1170,7 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code
|
|
|
|
|
|
// Set back the values into their bases.
|
|
// Set back the values into their bases.
|
|
for (const ChainInfo &info : set_chain) {
|
|
for (const ChainInfo &info : set_chain) {
|
|
- bool known_type = assigned.type.has_type;
|
|
|
|
|
|
+ bool known_type = assigned.type.has_type();
|
|
bool is_shared = Variant::is_type_shared(assigned.type.builtin_type);
|
|
bool is_shared = Variant::is_type_shared(assigned.type.builtin_type);
|
|
|
|
|
|
if (!known_type || !is_shared) {
|
|
if (!known_type || !is_shared) {
|
|
@@ -1197,7 +1196,7 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code
|
|
assigned = info.base;
|
|
assigned = info.base;
|
|
}
|
|
}
|
|
|
|
|
|
- bool known_type = assigned.type.has_type;
|
|
|
|
|
|
+ bool known_type = assigned.type.has_type();
|
|
bool is_shared = Variant::is_type_shared(assigned.type.builtin_type);
|
|
bool is_shared = Variant::is_type_shared(assigned.type.builtin_type);
|
|
|
|
|
|
if (!known_type || !is_shared) {
|
|
if (!known_type || !is_shared) {
|
|
@@ -1445,7 +1444,6 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_match_pattern(CodeGen &c
|
|
|
|
|
|
// Equality is always a boolean.
|
|
// Equality is always a boolean.
|
|
GDScriptDataType equality_type;
|
|
GDScriptDataType equality_type;
|
|
- equality_type.has_type = true;
|
|
|
|
equality_type.kind = GDScriptDataType::BUILTIN;
|
|
equality_type.kind = GDScriptDataType::BUILTIN;
|
|
equality_type.builtin_type = Variant::BOOL;
|
|
equality_type.builtin_type = Variant::BOOL;
|
|
|
|
|
|
@@ -1526,7 +1524,6 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_match_pattern(CodeGen &c
|
|
|
|
|
|
// Equality is always a boolean.
|
|
// Equality is always a boolean.
|
|
GDScriptDataType equality_type;
|
|
GDScriptDataType equality_type;
|
|
- equality_type.has_type = true;
|
|
|
|
equality_type.kind = GDScriptDataType::BUILTIN;
|
|
equality_type.kind = GDScriptDataType::BUILTIN;
|
|
equality_type.builtin_type = Variant::BOOL;
|
|
equality_type.builtin_type = Variant::BOOL;
|
|
|
|
|
|
@@ -1611,7 +1608,6 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_match_pattern(CodeGen &c
|
|
|
|
|
|
// Equality is always a boolean.
|
|
// Equality is always a boolean.
|
|
GDScriptDataType temp_type;
|
|
GDScriptDataType temp_type;
|
|
- temp_type.has_type = true;
|
|
|
|
temp_type.kind = GDScriptDataType::BUILTIN;
|
|
temp_type.kind = GDScriptDataType::BUILTIN;
|
|
temp_type.builtin_type = Variant::BOOL;
|
|
temp_type.builtin_type = Variant::BOOL;
|
|
|
|
|
|
@@ -1709,7 +1705,6 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_match_pattern(CodeGen &c
|
|
|
|
|
|
// Equality is always a boolean.
|
|
// Equality is always a boolean.
|
|
GDScriptDataType temp_type;
|
|
GDScriptDataType temp_type;
|
|
- temp_type.has_type = true;
|
|
|
|
temp_type.kind = GDScriptDataType::BUILTIN;
|
|
temp_type.kind = GDScriptDataType::BUILTIN;
|
|
temp_type.builtin_type = Variant::BOOL;
|
|
temp_type.builtin_type = Variant::BOOL;
|
|
|
|
|
|
@@ -1929,7 +1924,6 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Sui
|
|
|
|
|
|
// Then, let's save the type of the value in the stack too, so we can reuse for later comparisons.
|
|
// Then, let's save the type of the value in the stack too, so we can reuse for later comparisons.
|
|
GDScriptDataType typeof_type;
|
|
GDScriptDataType typeof_type;
|
|
- typeof_type.has_type = true;
|
|
|
|
typeof_type.kind = GDScriptDataType::BUILTIN;
|
|
typeof_type.kind = GDScriptDataType::BUILTIN;
|
|
typeof_type.builtin_type = Variant::INT;
|
|
typeof_type.builtin_type = Variant::INT;
|
|
GDScriptCodeGenerator::Address type = codegen.add_local("@match_type", typeof_type);
|
|
GDScriptCodeGenerator::Address type = codegen.add_local("@match_type", typeof_type);
|
|
@@ -2236,7 +2230,7 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Sui
|
|
codegen.generator->pop_temporary();
|
|
codegen.generator->pop_temporary();
|
|
}
|
|
}
|
|
initialized = true;
|
|
initialized = true;
|
|
- } else if ((local_type.has_type && local_type.kind == GDScriptDataType::BUILTIN) || codegen.generator->is_local_dirty(local)) {
|
|
|
|
|
|
+ } else if (local_type.kind == GDScriptDataType::BUILTIN || codegen.generator->is_local_dirty(local)) {
|
|
// Initialize with default for the type. Built-in types must always be cleared (they cannot be `null`).
|
|
// Initialize with default for the type. Built-in types must always be cleared (they cannot be `null`).
|
|
// Objects and untyped variables are assigned to `null` only if the stack address has been reused and not cleared.
|
|
// Objects and untyped variables are assigned to `null` only if the stack address has been reused and not cleared.
|
|
codegen.generator->clear_address(local);
|
|
codegen.generator->clear_address(local);
|
|
@@ -2303,7 +2297,6 @@ GDScriptFunction *GDScriptCompiler::_parse_function(Error &r_error, GDScript *p_
|
|
bool is_static = false;
|
|
bool is_static = false;
|
|
Variant rpc_config;
|
|
Variant rpc_config;
|
|
GDScriptDataType return_type;
|
|
GDScriptDataType return_type;
|
|
- return_type.has_type = true;
|
|
|
|
return_type.kind = GDScriptDataType::BUILTIN;
|
|
return_type.kind = GDScriptDataType::BUILTIN;
|
|
return_type.builtin_type = Variant::NIL;
|
|
return_type.builtin_type = Variant::NIL;
|
|
|
|
|
|
@@ -2383,7 +2376,7 @@ GDScriptFunction *GDScriptCompiler::_parse_function(Error &r_error, GDScript *p_
|
|
}
|
|
}
|
|
|
|
|
|
GDScriptDataType field_type = _gdtype_from_datatype(field->get_datatype(), codegen.script);
|
|
GDScriptDataType field_type = _gdtype_from_datatype(field->get_datatype(), codegen.script);
|
|
- if (field_type.has_type) {
|
|
|
|
|
|
+ if (field_type.has_type()) {
|
|
codegen.generator->write_newline(field->start_line);
|
|
codegen.generator->write_newline(field->start_line);
|
|
|
|
|
|
GDScriptCodeGenerator::Address dst_address(GDScriptCodeGenerator::Address::MEMBER, codegen.script->member_indices[field->identifier->name].index, field_type);
|
|
GDScriptCodeGenerator::Address dst_address(GDScriptCodeGenerator::Address::MEMBER, codegen.script->member_indices[field->identifier->name].index, field_type);
|
|
@@ -2522,7 +2515,6 @@ GDScriptFunction *GDScriptCompiler::_parse_function(Error &r_error, GDScript *p_
|
|
method_info.return_val = p_func->get_datatype().to_property_info(String());
|
|
method_info.return_val = p_func->get_datatype().to_property_info(String());
|
|
} else {
|
|
} else {
|
|
gd_function->return_type = GDScriptDataType();
|
|
gd_function->return_type = GDScriptDataType();
|
|
- gd_function->return_type.has_type = true;
|
|
|
|
gd_function->return_type.kind = GDScriptDataType::BUILTIN;
|
|
gd_function->return_type.kind = GDScriptDataType::BUILTIN;
|
|
gd_function->return_type.builtin_type = Variant::NIL;
|
|
gd_function->return_type.builtin_type = Variant::NIL;
|
|
}
|
|
}
|
|
@@ -2555,7 +2547,6 @@ GDScriptFunction *GDScriptCompiler::_make_static_initializer(Error &r_error, GDS
|
|
bool is_static = true;
|
|
bool is_static = true;
|
|
Variant rpc_config;
|
|
Variant rpc_config;
|
|
GDScriptDataType return_type;
|
|
GDScriptDataType return_type;
|
|
- return_type.has_type = true;
|
|
|
|
return_type.kind = GDScriptDataType::BUILTIN;
|
|
return_type.kind = GDScriptDataType::BUILTIN;
|
|
return_type.builtin_type = Variant::NIL;
|
|
return_type.builtin_type = Variant::NIL;
|
|
|
|
|
|
@@ -2581,7 +2572,7 @@ GDScriptFunction *GDScriptCompiler::_make_static_initializer(Error &r_error, GDS
|
|
}
|
|
}
|
|
|
|
|
|
GDScriptDataType field_type = _gdtype_from_datatype(field->get_datatype(), codegen.script);
|
|
GDScriptDataType field_type = _gdtype_from_datatype(field->get_datatype(), codegen.script);
|
|
- if (field_type.has_type) {
|
|
|
|
|
|
+ if (field_type.has_type()) {
|
|
codegen.generator->write_newline(field->start_line);
|
|
codegen.generator->write_newline(field->start_line);
|
|
|
|
|
|
if (field_type.builtin_type == Variant::ARRAY && field_type.has_container_element_type(0)) {
|
|
if (field_type.builtin_type == Variant::ARRAY && field_type.has_container_element_type(0)) {
|
|
@@ -2876,7 +2867,7 @@ Error GDScriptCompiler::_prepare_compilation(GDScript *p_script, const GDScriptP
|
|
PropertyInfo export_info = variable->export_info;
|
|
PropertyInfo export_info = variable->export_info;
|
|
|
|
|
|
if (variable->exported) {
|
|
if (variable->exported) {
|
|
- if (!minfo.data_type.has_type) {
|
|
|
|
|
|
+ if (!minfo.data_type.has_type()) {
|
|
prop_info.type = export_info.type;
|
|
prop_info.type = export_info.type;
|
|
prop_info.class_name = export_info.class_name;
|
|
prop_info.class_name = export_info.class_name;
|
|
}
|
|
}
|
|
@@ -3071,7 +3062,6 @@ Error GDScriptCompiler::_compile_class(GDScript *p_script, const GDScriptParser:
|
|
p_script->placeholders.erase(psi); //remove placeholder
|
|
p_script->placeholders.erase(psi); //remove placeholder
|
|
|
|
|
|
GDScriptInstance *instance = memnew(GDScriptInstance);
|
|
GDScriptInstance *instance = memnew(GDScriptInstance);
|
|
- instance->base_ref_counted = Object::cast_to<RefCounted>(E->get());
|
|
|
|
instance->members.resize(p_script->member_indices.size());
|
|
instance->members.resize(p_script->member_indices.size());
|
|
instance->script = Ref<GDScript>(p_script);
|
|
instance->script = Ref<GDScript>(p_script);
|
|
instance->owner = E->get();
|
|
instance->owner = E->get();
|