From c4df34102ae4589b0fc9bb8eff9cc6b6e08186ec Mon Sep 17 00:00:00 2001 From: Graham Date: Thu, 6 Aug 2020 22:43:19 +0100 Subject: [PATCH] Run IfElseTransformer until we reach a fixed point It'd be nice if we could make it run a single pass (and there are probably some improvements to reduce the number of required passes, as I'm not convinced I'm running the transformations in a particularly sensible order). However, I think making it run in a single pass would be quite difficult as some of the transformations need to propagate through else if chains or nested if blocks. It's much easier to just run all the transformations until they settle than fixing each individual transformation. Signed-off-by: Graham --- .../dev/openrs2/deob/ast/transform/IfElseTransformer.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IfElseTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IfElseTransformer.kt index a490ce905e..7f70e1cdf4 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IfElseTransformer.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IfElseTransformer.kt @@ -21,6 +21,14 @@ import javax.inject.Singleton @Singleton class IfElseTransformer : Transformer() { override fun transformUnit(group: LibraryGroup, library: Library, unit: CompilationUnit) { + var oldUnit: CompilationUnit + do { + oldUnit = unit.clone() + transform(unit) + } while (unit != oldUnit) + } + + private fun transform(unit: CompilationUnit) { unit.walk { stmt: IfStmt -> stmt.elseStmt.ifPresent { elseStmt: Statement -> val condition = stmt.condition