[ClavaLaraApi] Inliner adds forward decls. for calls in inlined code
laraImport("clava.ClavaJoinPoints");
+laraImport("lara.util.StringSet");
class Inliner {
#options;
@@ -301,6 +302,24 @@ class Inliner {
}
}
+ // For any calls inside $newNodes, add forward declarations before the function
+ const $parentFunction = $call.ancestor("function");
+ const addedDeclarations = new StringSet();
+ for (const $newCall of Query.searchFrom($newNodes, "call")) {
+ if (addedDeclarations.has($newCall.function.id)) {
+ continue;
+ }
+
+ addedDeclarations.add($newCall.function.id);
+
+ const $newFunctionDecl = ClavaJoinPoints.functionDeclFromType(
+ $newCall.function.name,
+ $newCall.function.functionType
+ );
+
+ $parentFunction.insertBefore($newFunctionDecl);
+ }
+
// Let the function body be on its own scope
// If the function uses local labels they must appear at the beginning of the scope
const inlinedScope =
