-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
693 additions
and
429 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
plugins/kotlin/src/main/java/org/vineflower/kotlin/pass/CollapseStringConcatPass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.vineflower.kotlin.pass; | ||
|
||
import org.jetbrains.java.decompiler.api.plugin.pass.Pass; | ||
import org.jetbrains.java.decompiler.api.plugin.pass.PassContext; | ||
import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent; | ||
import org.jetbrains.java.decompiler.modules.decompiler.exps.FunctionExprent; | ||
import org.jetbrains.java.decompiler.modules.decompiler.stats.BasicBlockStatement; | ||
import org.jetbrains.java.decompiler.modules.decompiler.stats.IfStatement; | ||
import org.jetbrains.java.decompiler.modules.decompiler.stats.Statement; | ||
import org.vineflower.kotlin.expr.KFunctionExprent; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class CollapseStringConcatPass implements Pass { | ||
@Override | ||
public boolean run(PassContext ctx) { | ||
return run(ctx.getRoot()); | ||
} | ||
|
||
private static boolean run(Statement stat) { | ||
boolean res = false; | ||
|
||
for (Statement st : stat.getStats()) { | ||
res |= run(st); | ||
} | ||
|
||
List<Exprent> exprs = List.of(); | ||
if (stat instanceof BasicBlockStatement) { | ||
exprs = stat.getExprents(); | ||
} else if (stat instanceof IfStatement) { | ||
exprs = ((IfStatement)stat).getHeadexprentList(); | ||
} | ||
|
||
for (Exprent ex : exprs) { | ||
res |= run(ex); | ||
} | ||
|
||
return res; | ||
} | ||
|
||
private static boolean run(Exprent ex) { | ||
boolean res = false; | ||
|
||
for (Exprent e : ex.getAllExprents()) { | ||
res |= run(e); | ||
} | ||
|
||
if (ex instanceof KFunctionExprent kex && kex.getFuncType() == FunctionExprent.FunctionType.STR_CONCAT) { | ||
List<Exprent> operands = new ArrayList<>(kex.getLstOperands()); | ||
List<Exprent> lstOperands = kex.getLstOperands(); | ||
for (Exprent child : operands) { | ||
if (child instanceof KFunctionExprent childKex && childKex.getFuncType() == FunctionExprent.FunctionType.STR_CONCAT) { | ||
lstOperands.addAll(lstOperands.indexOf(child), childKex.getLstOperands()); | ||
lstOperands.remove(child); | ||
res = true; | ||
} | ||
} | ||
} | ||
|
||
return res; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.