[ClavaLaraApi] SimplifyReturnStmts fix, was removing empty returns
@@ -13,8 +13,11 @@ class SimplifyReturnStmts extends Pass {
_apply_impl($jp) {
let appliedPass = false;
for (const $returnStmt of this.#findStmts($jp)) {
+ const transformed = this.#transform($returnStmt);
+ // If any change, mark as applied
+ if (transformed) {
appliedPass = true;
- this.#transform($returnStmt);
+ }
}
return new PassResult(this.name, {
@@ -28,14 +31,25 @@ class SimplifyReturnStmts extends Pass {
return Query.searchFromInclusive($jp, "returnStmt");
}
+ /**
+ *
+ * @param {$returnStmt} $returnStmt
+ * @returns true if there were changes, false otherwise
+ */
#transform($returnStmt) {
const decomposeResult = this.#statementDecomposer.decompose($returnStmt);
+ if (decomposeResult.length === 0) {
+ return false;
+ }
+
// Returns a list of stmts, replace with current return
for (const stmt of decomposeResult) {
$returnStmt.insertBefore(stmt);
}
$returnStmt.detach();
+
+ return true;
}
}
