feat(ClavaLaraApi): Add call decomposition to StatementDecomposer
@@ -158,6 +158,10 @@ class StatementDecomposer {
return this.decomposeTernaryOp($expr);
}
+ if ($expr.instanceOf("call")) {
+ return this.decomposeCall($expr);
+ }
+
if ($expr.numChildren === 0) {
//if($expr.instanceOf("varref") || $expr.instanceOf("literal")) {
return new DecomposeResult([], $expr);
@@ -166,6 +170,24 @@ class StatementDecomposer {
this.#throwNotImplemented("expressions", $expr.joinPointType);
}
+ decomposeCall($call) {
+ const argResults = $call.args.map(($arg) => this.decomposeExpr($arg));
+
+ const precedingStmts = argResults.flatMap((res) => res.precedingStmts);
+ const succeedingStmts = argResults.flatMap((res) => res.succeedingStmts);
+
+ const newArgs = argResults.map((res) => res.$resultExpr);
+ const $newCall = ClavaJoinPoints.call($call.function, ...newArgs);
+ const tempVarname = this.#newTempVarname();
+ const tempVarDecl = ClavaJoinPoints.varDecl(tempVarname, $newCall);
+
+ return new DecomposeResult(
+ [...precedingStmts, tempVarDecl.stmt],
+ ClavaJoinPoints.varRef(tempVarDecl),
+ succeedingStmts
+ );
+ }
+
decomposeBinaryOp($binaryOp) {
if ($binaryOp.isAssignment) {
return this.decomposeAssignment($binaryOp);
