java-decompiler - partial refactoring for statement

GitOrigin-RevId: 0b1bd6a86b63603a49b239e8ffb3c855a44cd04e
This commit is contained in:
Ilyas Selimov
2022-01-28 17:35:14 +07:00
committed by intellij-monorepo-bot
parent 2cf8098315
commit fad73b5ac3
13 changed files with 31 additions and 53 deletions

View File

@@ -821,7 +821,7 @@ public class ExprProcessor implements CodeConstants {
}
if (edge.labeled) {
buf.append(" label").append(edge.closure.id.toString());
buf.append(" label").append(Integer.toString(edge.closure.id));
}
buf.append(";").appendLineSeparator();
tracer.incrementCurrentSourceLine();

View File

@@ -30,7 +30,7 @@ public class DirectNode {
public DirectNode(@NotNull DirectNodeType type, @NotNull Statement statement, @NotNull BasicBlockStatement block) {
this.type = type;
this.statement = statement;
this.id = block.id.toString();
this.id = Integer.toString(block.id);
this.block = block;
}

View File

@@ -44,7 +44,7 @@ public class FlattenStatementsHelper {
// dummy exit node
Statement dummyexit = root.getDummyExit();
DirectNode node = new DirectNode(DirectNodeType.DIRECT, dummyexit, dummyexit.id.toString());
DirectNode node = new DirectNode(DirectNodeType.DIRECT, dummyexit, Integer.toString(dummyexit.id));
node.exprents = new ArrayList<>();
graph.nodes.addWithKey(node, node.id);
mapDestinationNodes.put(dummyexit.id, new String[]{node.id, null});
@@ -406,15 +406,15 @@ public class FlattenStatementsHelper {
mapShortRangeFinallyPathIds.computeIfAbsent(sourcenode.id, k -> new ArrayList<>()).add(new String[]{
finallyShortRangeSource.id,
destination.id.toString(),
finallyShortRangeEntry.id.toString(),
Integer.toString(destination.id),
Integer.toString(finallyShortRangeEntry.id),
isFinallyMonitorExceptionPath ? "1" : null,
isContinueEdge ? "1" : null});
mapLongRangeFinallyPathIds.computeIfAbsent(sourcenode.id, k -> new ArrayList<>()).add(new String[]{
finallyLongRangeSource.id,
destination.id.toString(),
finallyLongRangeEntry.id.toString(),
Integer.toString(destination.id),
Integer.toString(finallyLongRangeEntry.id),
isContinueEdge ? "1" : null});
}
}

View File

@@ -15,8 +15,7 @@ public class BasicBlockStatement extends Statement {
private final BasicBlock block;
public BasicBlockStatement(BasicBlock block) {
super(StatementType.BASIC_BLOCK);
id = block.id;
super(StatementType.BASIC_BLOCK, block.id);
this.block = block;
CounterContainer container = DecompilerContext.getCounterContainer();

View File

@@ -105,7 +105,7 @@ public final class CatchAllStatement extends Statement {
boolean labeled = isLabeled();
if (labeled) {
buf.appendIndent(indent).append("label").append(this.id.toString()).append(":").appendLineSeparator();
buf.appendIndent(indent).append("label").append(Integer.toString(id)).append(":").appendLineSeparator();
tracer.incrementCurrentSourceLine();
}

View File

@@ -139,7 +139,7 @@ public final class CatchStatement extends Statement {
buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer));
if (isLabeled()) {
buf.appendIndent(indent).append("label").append(this.id.toString()).append(":").appendLineSeparator();
buf.appendIndent(indent).append("label").append(Integer.toString(id)).append(":").appendLineSeparator();
tracer.incrementCurrentSourceLine();
}

View File

@@ -62,7 +62,7 @@ public final class DoStatement extends Statement {
TextBuffer buf = new TextBuffer();
buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer));
if (isLabeled()) {
buf.appendIndent(indent).append("label").append(this.id.toString()).append(":").appendLineSeparator();
buf.appendIndent(indent).append("label").append(Integer.toString(id)).append(":").appendLineSeparator();
tracer.incrementCurrentSourceLine();
}
switch (loopType) {

View File

@@ -44,7 +44,7 @@ public class GeneralStatement extends Statement {
TextBuffer buf = new TextBuffer();
if (isLabeled()) {
buf.appendIndent(indent).append("label").append(this.id.toString()).append(":").appendLineSeparator();
buf.appendIndent(indent).append("label").append(Integer.toString(id)).append(":").appendLineSeparator();
}
buf.appendIndent(indent).append("abstract statement {").appendLineSeparator();

View File

@@ -196,7 +196,7 @@ public final class IfStatement extends Statement {
buf.append(first.toJava(indent, tracer));
if (isLabeled()) {
buf.appendIndent(indent).append("label").append(this.id.toString()).append(":").appendLineSeparator();
buf.appendIndent(indent).append("label").append(Integer.toString(id)).append(":").appendLineSeparator();
tracer.incrementCurrentSourceLine();
}
@@ -217,7 +217,7 @@ public final class IfStatement extends Statement {
}
if (ifedge.labeled) {
buf.append(" label").append(ifedge.closure.id.toString());
buf.append(" label").append(Integer.toString(ifedge.closure.id));
}
}
if(semicolon) {

View File

@@ -93,7 +93,7 @@ public class SequenceStatement extends Statement {
buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer));
if (isLabeled) {
buf.appendIndent(indent++).append("label").append(this.id.toString()).append(": {").appendLineSeparator();
buf.appendIndent(indent++).append("label").append(Integer.toString(id)).append(": {").appendLineSeparator();
tracer.incrementCurrentSourceLine();
}

View File

@@ -26,17 +26,8 @@ import java.util.*;
import java.util.Map.Entry;
public abstract class Statement implements IMatchable {
// *****************************************************************************
// public fields
// *****************************************************************************
public StatementType type;
public Integer id;
// *****************************************************************************
// private fields
// *****************************************************************************
public int id;
private final Map<EdgeType, List<StatEdge>> mapSuccEdges = new HashMap<>();
private final Map<EdgeType, List<StatEdge>> mapPredEdges = new HashMap<>();
@@ -44,41 +35,24 @@ public abstract class Statement implements IMatchable {
private final Map<EdgeType, List<Statement>> mapSuccStates = new HashMap<>();
private final Map<EdgeType, List<Statement>> mapPredStates = new HashMap<>();
// statement as graph
protected final VBStyleCollection<Statement, Integer> stats = new VBStyleCollection<>();
protected Statement parent;
protected Statement first;
protected List<Exprent> exprents;
protected final HashSet<StatEdge> labelEdges = new HashSet<>();
protected final List<Exprent> varDefinitions = new ArrayList<>();
private final HashSet<StatEdge> labelEdges = new HashSet<>();
// copied statement, s. deobfuscating of irreducible CFGs
private boolean copied = false;
// statement as graph
protected final VBStyleCollection<Statement, Integer> stats = new VBStyleCollection<>();
protected Statement parent;
protected Statement first;
protected List<Exprent> exprents;
protected final List<Exprent> varDefinitions = new ArrayList<>();
// relevant for the first stage of processing only
// set to null after initializing of the statement structure
protected Statement post;
protected StatementType lastBasicType = StatementType.GENERAL;
protected boolean isMonitorEnter;
protected boolean containsMonitorExit;
protected HashSet<Statement> continueSet = new HashSet<>();
// *****************************************************************************
// initializers
// *****************************************************************************
{
// set statement id
id = DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.STATEMENT_COUNTER);
}
@@ -86,6 +60,11 @@ public abstract class Statement implements IMatchable {
this.type = type;
}
Statement(@NotNull StatementType type, int id) {
this.type = type;
this.id = id;
}
// *****************************************************************************
// public methods
// *****************************************************************************
@@ -810,7 +789,7 @@ public abstract class Statement implements IMatchable {
// helper methods
public String toString() {
return id.toString();
return Integer.toString(id);
}
// *****************************************************************************

View File

@@ -78,7 +78,7 @@ public final class SwitchStatement extends Statement {
buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer));
buf.append(first.toJava(indent, tracer));
if (isLabeled()) {
buf.appendIndent(indent).append("label").append(this.id.toString()).append(":").appendLineSeparator();
buf.appendIndent(indent).append("label").append(Integer.toString(id)).append(":").appendLineSeparator();
tracer.incrementCurrentSourceLine();
}
buf.appendIndent(indent).append(headExprent.toJava(indent, tracer)).append(" {").appendLineSeparator();

View File

@@ -64,7 +64,7 @@ public class SynchronizedStatement extends Statement {
buf.append(first.toJava(indent, tracer));
if (isLabeled()) {
buf.appendIndent(indent).append("label").append(this.id.toString()).append(":").appendLineSeparator();
buf.appendIndent(indent).append("label").append(Integer.toString(id)).append(":").appendLineSeparator();
tracer.incrementCurrentSourceLine();
}