@@ -5197,24 +5197,29 @@ void GDScriptAnalyzer::reduce_unary_op(GDScriptParser::UnaryOpNode *p_unary_op)
5197
5197
}
5198
5198
5199
5199
Variant GDScriptAnalyzer::make_expression_reduced_value (GDScriptParser::ExpressionNode *p_expression, bool &is_reduced) {
5200
- Variant value;
5201
-
5202
5200
if (p_expression == nullptr ) {
5203
- return value ;
5201
+ return Variant () ;
5204
5202
}
5205
5203
5206
5204
if (p_expression->is_constant ) {
5207
5205
is_reduced = true ;
5208
- value = p_expression->reduced_value ;
5209
- } else if (p_expression->type == GDScriptParser::Node::ARRAY) {
5210
- value = make_array_reduced_value (static_cast <GDScriptParser::ArrayNode *>(p_expression), is_reduced);
5211
- } else if (p_expression->type == GDScriptParser::Node::DICTIONARY) {
5212
- value = make_dictionary_reduced_value (static_cast <GDScriptParser::DictionaryNode *>(p_expression), is_reduced);
5213
- } else if (p_expression->type == GDScriptParser::Node::SUBSCRIPT) {
5214
- value = make_subscript_reduced_value (static_cast <GDScriptParser::SubscriptNode *>(p_expression), is_reduced);
5206
+ return p_expression->reduced_value ;
5215
5207
}
5216
5208
5217
- return value;
5209
+ switch (p_expression->type ) {
5210
+ case GDScriptParser::Node::ARRAY:
5211
+ return make_array_reduced_value (static_cast <GDScriptParser::ArrayNode *>(p_expression), is_reduced);
5212
+ case GDScriptParser::Node::DICTIONARY:
5213
+ return make_dictionary_reduced_value (static_cast <GDScriptParser::DictionaryNode *>(p_expression), is_reduced);
5214
+ case GDScriptParser::Node::SUBSCRIPT:
5215
+ return make_subscript_reduced_value (static_cast <GDScriptParser::SubscriptNode *>(p_expression), is_reduced);
5216
+ case GDScriptParser::Node::CALL:
5217
+ return make_call_reduced_value (static_cast <GDScriptParser::CallNode *>(p_expression), is_reduced);
5218
+ default :
5219
+ break ;
5220
+ }
5221
+
5222
+ return Variant ();
5218
5223
}
5219
5224
5220
5225
Variant GDScriptAnalyzer::make_array_reduced_value (GDScriptParser::ArrayNode *p_array, bool &is_reduced) {
@@ -5306,6 +5311,53 @@ Variant GDScriptAnalyzer::make_subscript_reduced_value(GDScriptParser::Subscript
5306
5311
}
5307
5312
}
5308
5313
5314
+ Variant GDScriptAnalyzer::make_call_reduced_value (GDScriptParser::CallNode *p_call, bool &is_reduced) {
5315
+ if (p_call->get_callee_type () == GDScriptParser::Node::IDENTIFIER) {
5316
+ Variant::Type type = Variant::NIL;
5317
+ if (p_call->function_name == SNAME (" Array" )) {
5318
+ type = Variant::ARRAY;
5319
+ } else if (p_call->function_name == SNAME (" Dictionary" )) {
5320
+ type = Variant::DICTIONARY;
5321
+ } else {
5322
+ return Variant ();
5323
+ }
5324
+
5325
+ Vector<Variant> args;
5326
+ args.resize (p_call->arguments .size ());
5327
+ const Variant **argptrs = (const Variant **)alloca (sizeof (const Variant **) * args.size ());
5328
+ for (int i = 0 ; i < p_call->arguments .size (); i++) {
5329
+ bool is_arg_value_reduced = false ;
5330
+ Variant arg_value = make_expression_reduced_value (p_call->arguments [i], is_arg_value_reduced);
5331
+ if (!is_arg_value_reduced) {
5332
+ return Variant ();
5333
+ }
5334
+ args.write [i] = arg_value;
5335
+ argptrs[i] = &args[i];
5336
+ }
5337
+
5338
+ Variant result;
5339
+ Callable::CallError ce;
5340
+ Variant::construct (type, result, argptrs, args.size (), ce);
5341
+ if (ce.error ) {
5342
+ push_error (vformat (R"( Failed to construct "%s".)" , Variant::get_type_name (type)), p_call);
5343
+ return Variant ();
5344
+ }
5345
+
5346
+ if (type == Variant::ARRAY) {
5347
+ Array array = result;
5348
+ array.make_read_only ();
5349
+ } else if (type == Variant::DICTIONARY) {
5350
+ Dictionary dictionary = result;
5351
+ dictionary.make_read_only ();
5352
+ }
5353
+
5354
+ is_reduced = true ;
5355
+ return result;
5356
+ }
5357
+
5358
+ return Variant ();
5359
+ }
5360
+
5309
5361
Array GDScriptAnalyzer::make_array_from_element_datatype (const GDScriptParser::DataType &p_element_datatype, const GDScriptParser::Node *p_source_node) {
5310
5362
Array array;
5311
5363
0 commit comments