You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//#TODO throw warning on empty array passed to params?
240
+
if (!it.children.empty() && std::holds_alternative<ScriptConstantArray>(it.value)) // is array, and is not empty
241
+
{
242
+
// it is a [name, default, allowedTypes] array
243
+
auto& paramArguments = it.children;
244
+
245
+
if (paramArguments.size() < 2) // only [name], no defaults, don't care
246
+
continue;
247
+
248
+
if (std::holds_alternative<ScriptConstantArray>(paramArguments[1].value))
249
+
{
250
+
// !!! [name, []] the array will be passed down by ref if parameter is not provided, and cause changes to propagate/persist to compiled code if modified by reference
251
+
// We know that this will be a problem, lets insert a array copy
252
+
253
+
// replace ourselves with a + unary
254
+
255
+
// move our array out so we can move it over instead of copying
256
+
auto myArgumentsArray = std::move(node.children[0]);
257
+
// our only child is now default initialized, we have no children
258
+
node.children.clear();
259
+
260
+
// convert ourselves to a unary + and add the array as argument
261
+
OptimizerModuleBase::Node copyNode;
262
+
copyNode.type = InstructionType::callUnary;
263
+
copyNode.constant = false; // Lets prevent optimizing this copy out, shouldn't be done anyway but better be safe
264
+
copyNode.value = STRINGTYPE("+"); // value is name of command
265
+
copyNode.file = node.file;
266
+
copyNode.line = myArgumentsArray.line;
267
+
copyNode.offset = myArgumentsArray.offset;
268
+
copyNode.children.emplace_back(std::move(myArgumentsArray)); // Add the arguments array back
269
+
270
+
node.children.emplace_back(std::move(copyNode));
271
+
272
+
// now changed params [...] to params +[...]
273
+
break; // paramsList has been invalidated, cannot keep iterating
274
+
}
275
+
}
276
+
}
277
+
231
278
}
232
279
};
233
280
281
+
//#TODO optimize param too, if non-array constant default value, see params array checking
0 commit comments