[ClavaLaraApi] SimplifyLoops supports an option object, and 'for-to-while'
@@ -7,19 +7,31 @@ laraImport("weaver.Query");
class SimplifyLoops extends Pass {
#statementDecomposer;
+ #options;
#label_suffix = 0;
- constructor(statementDecomposer) {
+ /**
+ *
+ * @param {*} statementDecomposer
+ * @param {object} options - Object with options. Supported options: 'for-to-while' (default: true), transforms for loops into while loops
+ */
+ constructor(statementDecomposer, options) {
super("SimplifyLoops");
this.#statementDecomposer = statementDecomposer;
+ this.#options = options ?? {};
+ this.#options["for-to-while"] ??= true;
}
_apply_impl($jp) {
let appliedPass = false;
for (const $loop of this._findLoops($jp)) {
appliedPass = true;
+ if (this.#options["for-to-while"]) {
const $whileLoop = this.#makeWhileLoop($loop);
this.#transform($whileLoop);
+ } else {
+ this.#transform($loop);
+ }
}
return new PassResult(this.name, {
