MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / reduce_call

Method reduce_call

modules/gdscript/gdscript_analyzer.cpp:3224–3770  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3222#endif // SUGGEST_GODOT4_RENAMES
3223
3224void GDScriptAnalyzer::reduce_call(GDScriptParser::CallNode *p_call, bool p_is_await, bool p_is_root) {
3225 bool all_is_constant = true;
3226 HashMap<int, GDScriptParser::ArrayNode *> arrays; // For array literal to potentially type when passing.
3227 HashMap<int, GDScriptParser::DictionaryNode *> dictionaries; // Same, but for dictionaries.
3228 for (int i = 0; i < p_call->arguments.size(); i++) {
3229 reduce_expression(p_call->arguments[i]);
3230 if (p_call->arguments[i]->type == GDScriptParser::Node::ARRAY) {
3231 arrays[i] = static_cast<GDScriptParser::ArrayNode *>(p_call->arguments[i]);
3232 } else if (p_call->arguments[i]->type == GDScriptParser::Node::DICTIONARY) {
3233 dictionaries[i] = static_cast<GDScriptParser::DictionaryNode *>(p_call->arguments[i]);
3234 }
3235 all_is_constant = all_is_constant && p_call->arguments[i]->is_constant;
3236 }
3237
3238 GDScriptParser::Node::Type callee_type = p_call->get_callee_type();
3239 GDScriptParser::DataType call_type;
3240
3241 if (!p_call->is_super && callee_type == GDScriptParser::Node::IDENTIFIER) {
3242 // Call to name directly.
3243 StringName function_name = p_call->function_name;
3244
3245 if (function_name == SNAME("Object")) {
3246 push_error(R"*(Invalid constructor "Object()", use "Object.new()" instead.)*", p_call);
3247 p_call->set_datatype(call_type);
3248 return;
3249 }
3250
3251 Variant::Type builtin_type = GDScriptParser::get_builtin_type(function_name);
3252 if (builtin_type < Variant::VARIANT_MAX) {
3253 // Is a builtin constructor.
3254 call_type.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT;
3255 call_type.kind = GDScriptParser::DataType::BUILTIN;
3256 call_type.builtin_type = builtin_type;
3257
3258 bool safe_to_fold = true;
3259 switch (builtin_type) {
3260 // Those are stored by reference so not suited for compile-time construction.
3261 // Because in this case they would be the same reference in all constructed values.
3262 case Variant::OBJECT:
3263 case Variant::DICTIONARY:
3264 case Variant::ARRAY:
3265 case Variant::PACKED_BYTE_ARRAY:
3266 case Variant::PACKED_INT32_ARRAY:
3267 case Variant::PACKED_INT64_ARRAY:
3268 case Variant::PACKED_FLOAT32_ARRAY:
3269 case Variant::PACKED_FLOAT64_ARRAY:
3270 case Variant::PACKED_STRING_ARRAY:
3271 case Variant::PACKED_VECTOR2_ARRAY:
3272 case Variant::PACKED_VECTOR3_ARRAY:
3273 case Variant::PACKED_COLOR_ARRAY:
3274 case Variant::PACKED_VECTOR4_ARRAY:
3275 safe_to_fold = false;
3276 break;
3277 default:
3278 break;
3279 }
3280
3281 if (all_is_constant && safe_to_fold) {

Callers

nothing calls this directly

Calls 15

vformatFunction · 0.85
itosFunction · 0.85
info_from_utility_funcFunction · 0.85
make_builtin_meta_typeFunction · 0.85
get_callee_typeMethod · 0.80
set_datatypeMethod · 0.80
is_hard_typeMethod · 0.80
is_variantMethod · 0.80
to_string_strictMethod · 0.80
get_memberMethod · 0.80
TypeEnum · 0.70

Tested by

no test coverage detected