[ClavaLaraApi] Inliner introduces nop when return is before a label
@@ -272,6 +272,8 @@ class Inliner {
);
}
+ // Remove/replace return statements
+
if ($exprStmt.expr.instanceOf("binaryOp") && $exprStmt.expr.isAssignment) {
for (const $returnStmt of $newNodes.descendants("returnStmt")) {
if (
@@ -288,13 +290,34 @@ class Inliner {
}
}
} else if ($exprStmt.expr.instanceOf("call")) {
+ //println("INLINED BODY: " + $newNodes.code);
for (const $returnStmt of $newNodes.descendants("returnStmt")) {
- if ($returnStmt.expr !== null && $returnStmt.expr !== undefined) {
- $returnStmt.replaceWith(ClavaJoinPoints.exprStmt($returnStmt.expr));
+ //println("RETURN STMT CODE: " + $returnStmt.code);
+ //println("RETURN STMT EXPR: " + $returnStmt.returnExpr);
+ //println("RETURN STMT AST: " + $returnStmt.ast);
+ //if ($returnStmt.expr !== null && $returnStmt.expr !== undefined) {
+ //$returnStmt.replaceWith(ClavaJoinPoints.exprStmt($returnStmt.expr));
+ /*
+ if (
+ $returnStmt.returnExpr !== null &&
+ $returnStmt.returnExpr !== undefined
+ ) {
+ $returnStmt.replaceWith(
+ ClavaJoinPoints.exprStmt($returnStmt.returnExpr)
+ );
+ } else {
+ $returnStmt.detach();
+ }
+ */
+ // Replace the return with a nop (i.e. empty statement), in case there is a label before. Otherwise, just remove return
+ const left = $returnStmt.siblingsLeft;
+ if (left.length > 0 && left[left.length - 1].instanceOf("labelStmt")) {
+ $returnStmt.replaceWith(ClavaJoinPoints.emptyStmt());
} else {
$returnStmt.detach();
}
}
+ //println("INLINED BODY AFTER: " + $newNodes.code);
}
// Let the function body be on its own scope
