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 <gpe@openrs2.dev>
bzip2
Graham 4 years ago
parent 0ae1ffb51d
commit c4df34102a
  1. 8
      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

Loading…
Cancel
Save