From 43a4b88cb7a35c539c6ac17689aee9caeb91a158 Mon Sep 17 00:00:00 2001
From: volodya-lombrozo
Date: Mon, 12 Aug 2024 11:01:55 +0300
Subject: [PATCH 01/11] feat(#376): rename Add node to Addition
---
.../opeo/ast/{Add.java => Addition.java} | 6 ++--
.../eolang/opeo/compilation/XmirParser.java | 4 +--
.../decompilation/handlers/AddHandler.java | 4 +--
.../ast/{AddTest.java => AdditionTest.java} | 28 +++++++++----------
.../eolang/opeo/ast/ArrayConstructorTest.java | 8 +++---
.../opeo/compilation/XmirParserTest.java | 10 +++----
.../decompilation/DecompilerMachineTest.java | 6 ++--
7 files changed, 33 insertions(+), 33 deletions(-)
rename src/main/java/org/eolang/opeo/ast/{Add.java => Addition.java} (94%)
rename src/test/java/org/eolang/opeo/ast/{AddTest.java => AdditionTest.java} (86%)
diff --git a/src/main/java/org/eolang/opeo/ast/Add.java b/src/main/java/org/eolang/opeo/ast/Addition.java
similarity index 94%
rename from src/main/java/org/eolang/opeo/ast/Add.java
rename to src/main/java/org/eolang/opeo/ast/Addition.java
index 906c97c1..8b1783d6 100644
--- a/src/main/java/org/eolang/opeo/ast/Add.java
+++ b/src/main/java/org/eolang/opeo/ast/Addition.java
@@ -41,7 +41,7 @@
*/
@EqualsAndHashCode
@ToString
-public final class Add implements AstNode, Typed {
+public final class Addition implements AstNode, Typed {
/**
* Left operand.
@@ -58,7 +58,7 @@ public final class Add implements AstNode, Typed {
* @param node XML node
* @param parser Parser
*/
- public Add(final XmlNode node, final Function parser) {
+ public Addition(final XmlNode node, final Function parser) {
this(
parser.apply(node.children().collect(Collectors.toList()).get(0)),
parser.apply(node.children().collect(Collectors.toList()).get(1))
@@ -70,7 +70,7 @@ public Add(final XmlNode node, final Function parser) {
* @param left Left operand
* @param right Right operand
*/
- public Add(final AstNode left, final AstNode right) {
+ public Addition(final AstNode left, final AstNode right) {
this.left = left;
this.right = right;
}
diff --git a/src/main/java/org/eolang/opeo/compilation/XmirParser.java b/src/main/java/org/eolang/opeo/compilation/XmirParser.java
index b713a855..64044f02 100644
--- a/src/main/java/org/eolang/opeo/compilation/XmirParser.java
+++ b/src/main/java/org/eolang/opeo/compilation/XmirParser.java
@@ -27,7 +27,7 @@
import java.util.List;
import java.util.stream.Collectors;
import org.eolang.jeo.representation.xmir.XmlNode;
-import org.eolang.opeo.ast.Add;
+import org.eolang.opeo.ast.Addition;
import org.eolang.opeo.ast.ArrayConstructor;
import org.eolang.opeo.ast.AstNode;
import org.eolang.opeo.ast.Attributes;
@@ -136,7 +136,7 @@ public AstNode parse(final XmlNode node) {
} else if ("duplicated".equals(base)) {
result = new Duplicate(this.parse(node.firstChild()));
} else if (".plus".equals(base)) {
- result = new Add(node, this::parse);
+ result = new Addition(node, this::parse);
} else if (".minus".equals(base)) {
result = new Substraction(node, this::parse);
} else if ("cast".equals(base)) {
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/AddHandler.java b/src/main/java/org/eolang/opeo/decompilation/handlers/AddHandler.java
index 7dd81fdc..006b52c9 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/AddHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/handlers/AddHandler.java
@@ -23,7 +23,7 @@
*/
package org.eolang.opeo.decompilation.handlers;
-import org.eolang.opeo.ast.Add;
+import org.eolang.opeo.ast.Addition;
import org.eolang.opeo.ast.AstNode;
import org.eolang.opeo.decompilation.DecompilerState;
import org.eolang.opeo.decompilation.InstructionHandler;
@@ -38,7 +38,7 @@ public final class AddHandler implements InstructionHandler {
public void handle(final DecompilerState state) {
final AstNode right = state.stack().pop();
final AstNode left = state.stack().pop();
- state.stack().push(new Add(left, right));
+ state.stack().push(new Addition(left, right));
}
}
diff --git a/src/test/java/org/eolang/opeo/ast/AddTest.java b/src/test/java/org/eolang/opeo/ast/AdditionTest.java
similarity index 86%
rename from src/test/java/org/eolang/opeo/ast/AddTest.java
rename to src/test/java/org/eolang/opeo/ast/AdditionTest.java
index 94aca802..cca090a9 100644
--- a/src/test/java/org/eolang/opeo/ast/AddTest.java
+++ b/src/test/java/org/eolang/opeo/ast/AdditionTest.java
@@ -34,14 +34,14 @@
import org.xembly.Xembler;
/**
- * Test case for {@link Add}.
+ * Test case for {@link Addition}.
* @since 0.1
*/
-final class AddTest {
+final class AdditionTest {
@Test
void convertsToXmir() throws ImpossibleModificationException {
- final String res = new Xembler(new Add(new Literal(1), new Literal(2)).toXmir()).xml();
+ final String res = new Xembler(new Addition(new Literal(1), new Literal(2)).toXmir()).xml();
MatcherAssert.assertThat(
String.format(
"Can't convert to correct XMIR, result is : %n%s%n",
@@ -60,42 +60,42 @@ void convertsToXmir() throws ImpossibleModificationException {
void determinesPrimitiveTypesCorrectly() {
MatcherAssert.assertThat(
"Can't determine the type of Add with two integer literals",
- new Add(new Literal(1), new Literal(2)).type(),
+ new Addition(new Literal(1), new Literal(2)).type(),
Matchers.equalTo(Type.INT_TYPE)
);
MatcherAssert.assertThat(
"Can't determine the type of Add with two long literals",
- new Add(new Literal(1L), new Literal(2L)).type(),
+ new Addition(new Literal(1L), new Literal(2L)).type(),
Matchers.equalTo(Type.LONG_TYPE)
);
MatcherAssert.assertThat(
"Can't determine the type of Add with two float literals",
- new Add(new Literal(1.0f), new Literal(2.0f)).type(),
+ new Addition(new Literal(1.0f), new Literal(2.0f)).type(),
Matchers.equalTo(Type.FLOAT_TYPE)
);
MatcherAssert.assertThat(
"Can't determine the type of Add with two double literals",
- new Add(new Literal(1.0), new Literal(2.0)).type(),
+ new Addition(new Literal(1.0), new Literal(2.0)).type(),
Matchers.equalTo(Type.DOUBLE_TYPE)
);
MatcherAssert.assertThat(
"Can't determine the type of Add with two integer and long literals",
- new Add(new Literal(1), new Literal(2L)).type(),
+ new Addition(new Literal(1), new Literal(2L)).type(),
Matchers.equalTo(Type.LONG_TYPE)
);
MatcherAssert.assertThat(
"Can't determine the type of Add with two integer and float literals",
- new Add(new Literal(1), new Literal(2.0f)).type(),
+ new Addition(new Literal(1), new Literal(2.0f)).type(),
Matchers.equalTo(Type.FLOAT_TYPE)
);
MatcherAssert.assertThat(
"Can't determine the type of Add with two integer and double literals",
- new Add(new Literal(1), new Literal(2.0)).type(),
+ new Addition(new Literal(1), new Literal(2.0)).type(),
Matchers.equalTo(Type.DOUBLE_TYPE)
);
MatcherAssert.assertThat(
"Can't determine the type of Add with two long and float literals",
- new Add(new Literal(1L), new Literal(2.0f)).type(),
+ new Addition(new Literal(1L), new Literal(2.0f)).type(),
Matchers.equalTo(Type.FLOAT_TYPE)
);
}
@@ -105,7 +105,7 @@ void retrievesOpcodesWithLeftAndRightNodesWithTheSameType() {
MatcherAssert.assertThat(
"Can't retrieve opcodes from Add with two literals",
new OpcodeNodes(
- new Add(
+ new Addition(
new Literal(1),
new Literal(2)
)
@@ -123,7 +123,7 @@ void retrievesOpcodesWithLeftAndRightNodesWithDifferentTypes() {
MatcherAssert.assertThat(
"Can't retrieve opcodes from Add with two literals of different types",
new OpcodeNodes(
- new Add(
+ new Addition(
new Literal(1L),
new Literal(1)
)
@@ -141,7 +141,7 @@ void retrievesOpcodesWithLeftAndRightNodesWithDoubleType() {
MatcherAssert.assertThat(
"Can't retrieve opcodes from Add with where one of the operands is double",
new OpcodeNodes(
- new Add(
+ new Addition(
new Literal(1.0),
new Literal(1)
)
diff --git a/src/test/java/org/eolang/opeo/ast/ArrayConstructorTest.java b/src/test/java/org/eolang/opeo/ast/ArrayConstructorTest.java
index c9f39145..dfbaa515 100644
--- a/src/test/java/org/eolang/opeo/ast/ArrayConstructorTest.java
+++ b/src/test/java/org/eolang/opeo/ast/ArrayConstructorTest.java
@@ -59,10 +59,10 @@ void createsArrayConstructorFromXmir() {
"Can't create array constructor from XMIR",
new ArrayConstructor(
new XmlNode(ArrayConstructorTest.XMIR),
- node -> new Add(new Literal(1), new Literal(2))
+ node -> new Addition(new Literal(1), new Literal(2))
),
Matchers.equalTo(
- new ArrayConstructor(new Add(new Literal(1), new Literal(2)), "java/lang/Integer")
+ new ArrayConstructor(new Addition(new Literal(1), new Literal(2)), "java/lang/Integer")
)
);
}
@@ -90,7 +90,7 @@ void compilesArrayWithComplexLength() {
"Can't compile array constructor with complex undefined length",
new OpcodeNodes(
new ArrayConstructor(
- new Add(new Literal(1), new Literal(2)),
+ new Addition(new Literal(1), new Literal(2)),
type
)
).opcodes(),
@@ -109,7 +109,7 @@ void convertsToXmir() throws ImpossibleModificationException {
final String type = "java/lang/Integer";
final String xmir = new Xembler(
new ArrayConstructor(
- new Add(new Literal(1), new Literal(2)),
+ new Addition(new Literal(1), new Literal(2)),
type
).toXmir()
).xml();
diff --git a/src/test/java/org/eolang/opeo/compilation/XmirParserTest.java b/src/test/java/org/eolang/opeo/compilation/XmirParserTest.java
index db8f67d3..9d46d8e3 100644
--- a/src/test/java/org/eolang/opeo/compilation/XmirParserTest.java
+++ b/src/test/java/org/eolang/opeo/compilation/XmirParserTest.java
@@ -27,7 +27,7 @@
import java.util.List;
import org.eolang.jeo.matchers.SameXml;
import org.eolang.jeo.representation.xmir.XmlNode;
-import org.eolang.opeo.ast.Add;
+import org.eolang.opeo.ast.Addition;
import org.eolang.opeo.ast.Attributes;
import org.eolang.opeo.ast.Field;
import org.eolang.opeo.ast.FieldAssignment;
@@ -70,7 +70,7 @@ void convertsOpcodesAsIs() {
@Test
void convertsAddition() {
final List nodes = new XmirParser(
- new Add(new Literal(1), new Literal(2))
+ new Addition(new Literal(1), new Literal(2))
).toJeoNodes();
MatcherAssert.assertThat(
String.format(
@@ -96,12 +96,12 @@ void convertsDeepAddition() {
MatcherAssert.assertThat(
"We expect to retrieve 7 opcodes, but got something else instead",
new XmirParser(
- new Add(
- new Add(
+ new Addition(
+ new Addition(
new Literal(1),
new Literal(2)
),
- new Add(
+ new Addition(
new Literal(3),
new Literal(4)
)
diff --git a/src/test/java/org/eolang/opeo/decompilation/DecompilerMachineTest.java b/src/test/java/org/eolang/opeo/decompilation/DecompilerMachineTest.java
index e24ffeb7..5c253d2b 100644
--- a/src/test/java/org/eolang/opeo/decompilation/DecompilerMachineTest.java
+++ b/src/test/java/org/eolang/opeo/decompilation/DecompilerMachineTest.java
@@ -29,7 +29,7 @@
import org.eolang.jeo.representation.xmir.AllLabels;
import org.eolang.opeo.LabelInstruction;
import org.eolang.opeo.OpcodeInstruction;
-import org.eolang.opeo.ast.Add;
+import org.eolang.opeo.ast.Addition;
import org.eolang.opeo.ast.ArrayConstructor;
import org.eolang.opeo.ast.AstNode;
import org.eolang.opeo.ast.Attributes;
@@ -258,7 +258,7 @@ void decompilesArrayCreation() throws ImpossibleModificationException {
new Xembler(
new Root(
new ArrayConstructor(
- new Add(new Literal(2), new Literal(3)),
+ new Addition(new Literal(2), new Literal(3)),
type
)
).toXmir()
@@ -317,7 +317,7 @@ void decompilesVariableAssignment() {
),
new VariableAssignment(
new LocalVariable(2, Type.INT_TYPE),
- new Add(
+ new Addition(
new LocalVariable(2, Type.INT_TYPE),
new Literal(2)
)
From 3d85e72b0543ddc5add8944c8b2ec815ab6c93aa Mon Sep 17 00:00:00 2001
From: volodya-lombrozo
Date: Mon, 12 Aug 2024 11:08:46 +0300
Subject: [PATCH 02/11] feat(#376) handlers -> agents
---
.../org/eolang/opeo/SelectiveDecompiler.java | 8 +-
.../java/org/eolang/opeo/ast/Labeled.java | 3 +-
.../opeo/compilation/SelectiveCompiler.java | 4 +-
...onHandler.java => DecompilationAgent.java} | 8 +-
.../opeo/decompilation/DecompilerMachine.java | 6 +-
.../AddHandler.java => agents/AddAgent.java} | 6 +-
.../BipushAgent.java} | 6 +-
.../CastAgent.java} | 8 +-
.../CheckCastAgent.java} | 6 +-
.../ConstAgent.java} | 16 +-
.../DupHandler.java => agents/DupAgent.java} | 6 +-
.../GetFieldAgent.java} | 6 +-
.../GetStaticAgent.java} | 6 +-
.../IfHandler.java => agents/IfAgent.java} | 6 +-
.../InvokedynamicAgent.java} | 6 +-
.../InvokeinterfaceAgent.java} | 6 +-
.../InvokespecialAgent.java} | 14 +-
.../InvokestaticAgent.java} | 6 +-
.../InvokevirtualAgent.java} | 6 +-
.../LabelAgent.java} | 6 +-
.../LdcHandler.java => agents/LdcAgent.java} | 6 +-
.../LoadAgent.java} | 8 +-
.../MulHandler.java => agents/MulAgent.java} | 8 +-
.../NewHandler.java => agents/NewAgent.java} | 6 +-
.../NewArrayAgent.java} | 6 +-
.../PopHandler.java => agents/PopAgent.java} | 6 +-
.../PutFieldAgent.java} | 6 +-
.../ReturnAgent.java} | 6 +-
.../decompilation/agents/RouterAgent.java | 200 ++++++++++++++++++
.../StoreAgent.java} | 8 +-
.../StoreToArrayAgent.java} | 8 +-
.../SubstractionAgent.java} | 6 +-
.../{handlers => agents}/package-info.java | 2 +-
.../decompilation/handlers/RouterHandler.java | 200 ------------------
.../SelectiveDecompilerTest.java | 4 +-
35 files changed, 310 insertions(+), 309 deletions(-)
rename src/main/java/org/eolang/opeo/decompilation/{InstructionHandler.java => DecompilationAgent.java} (83%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/AddHandler.java => agents/AddAgent.java} (90%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/BipushHandler.java => agents/BipushAgent.java} (89%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/CastHandler.java => agents/CastAgent.java} (89%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/CheckCastHandler.java => agents/CheckCastAgent.java} (90%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/ConstHandler.java => agents/ConstAgent.java} (93%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/DupHandler.java => agents/DupAgent.java} (90%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/GetFieldHandler.java => agents/GetFieldAgent.java} (91%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/GetStaticHnadler.java => agents/GetStaticAgent.java} (90%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/IfHandler.java => agents/IfAgent.java} (93%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/InvokedynamicHandler.java => agents/InvokedynamicAgent.java} (92%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/InvokeinterfaceHandler.java => agents/InvokeinterfaceAgent.java} (93%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/InvokespecialHandler.java => agents/InvokespecialAgent.java} (92%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/InvokestaticHander.java => agents/InvokestaticAgent.java} (92%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/InvokevirtualHandler.java => agents/InvokevirtualAgent.java} (93%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/LabelHandler.java => agents/LabelAgent.java} (90%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/LdcHandler.java => agents/LdcAgent.java} (89%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/LoadHandler.java => agents/LoadAgent.java} (90%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/MulHandler.java => agents/MulAgent.java} (91%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/NewHandler.java => agents/NewAgent.java} (89%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/NewArrayHandler.java => agents/NewArrayAgent.java} (90%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/PopHandler.java => agents/PopAgent.java} (90%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/PutFieldHnadler.java => agents/PutFieldAgent.java} (92%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/ReturnHandler.java => agents/ReturnAgent.java} (93%)
create mode 100644 src/main/java/org/eolang/opeo/decompilation/agents/RouterAgent.java
rename src/main/java/org/eolang/opeo/decompilation/{handlers/StoreHandler.java => agents/StoreAgent.java} (91%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/StoreToArrayHandler.java => agents/StoreToArrayAgent.java} (93%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers/SubstractionHandler.java => agents/SubstractionAgent.java} (90%)
rename src/main/java/org/eolang/opeo/decompilation/{handlers => agents}/package-info.java (96%)
delete mode 100644 src/main/java/org/eolang/opeo/decompilation/handlers/RouterHandler.java
diff --git a/src/main/java/org/eolang/opeo/SelectiveDecompiler.java b/src/main/java/org/eolang/opeo/SelectiveDecompiler.java
index 8f3d1400..b366304c 100644
--- a/src/main/java/org/eolang/opeo/SelectiveDecompiler.java
+++ b/src/main/java/org/eolang/opeo/SelectiveDecompiler.java
@@ -31,7 +31,7 @@
import java.util.stream.Collectors;
import org.eolang.opeo.decompilation.Decompiler;
import org.eolang.opeo.decompilation.WithoutAliases;
-import org.eolang.opeo.decompilation.handlers.RouterHandler;
+import org.eolang.opeo.decompilation.agents.RouterAgent;
import org.eolang.opeo.jeo.JeoDecompiler;
import org.eolang.opeo.storage.FileStorage;
import org.eolang.opeo.storage.Storage;
@@ -41,7 +41,7 @@
* Selective decompiler.
* Decompiler that decompiles ONLY fully understandable methods.
* These methods contain only instructions that are
- * supported by {@link org.eolang.opeo.decompilation.handlers.RouterHandler}.
+ * supported by {@link RouterAgent}.
*
* @since 0.1
*/
@@ -69,7 +69,7 @@ public final class SelectiveDecompiler implements Decompiler {
* @param modified Folder where to save the modified XMIRs.
*/
public SelectiveDecompiler(final Path input, final Path output, final Path modified) {
- this(input, output, modified, new RouterHandler(false).supportedOpcodes());
+ this(input, output, modified, new RouterAgent(false).supportedOpcodes());
}
/**
@@ -97,7 +97,7 @@ public SelectiveDecompiler(
public SelectiveDecompiler(
final Storage storage, final Storage modified
) {
- this(storage, modified, new RouterHandler(false).supportedOpcodes());
+ this(storage, modified, new RouterAgent(false).supportedOpcodes());
}
/**
diff --git a/src/main/java/org/eolang/opeo/ast/Labeled.java b/src/main/java/org/eolang/opeo/ast/Labeled.java
index 7e039e66..cb7bc593 100644
--- a/src/main/java/org/eolang/opeo/ast/Labeled.java
+++ b/src/main/java/org/eolang/opeo/ast/Labeled.java
@@ -30,6 +30,7 @@
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.eolang.jeo.representation.xmir.XmlNode;
+import org.eolang.opeo.decompilation.agents.InvokespecialAgent;
import org.objectweb.asm.Type;
import org.xembly.Directive;
import org.xembly.Directives;
@@ -39,7 +40,7 @@
* This class needed to avoid considering labels as separate nodes.
* Maybe it's wrong to do so, but it's easier to implement this way, at least for now.
* Pay attention, that {@link Labeled} class violates class hierarchy.
- * It is the most visible within {@link org.eolang.opeo.decompilation.handlers.InvokespecialHandler}
+ * It is the most visible within {@link InvokespecialAgent}
* implementation.
* @since 0.2
*/
diff --git a/src/main/java/org/eolang/opeo/compilation/SelectiveCompiler.java b/src/main/java/org/eolang/opeo/compilation/SelectiveCompiler.java
index e163470d..3855d156 100644
--- a/src/main/java/org/eolang/opeo/compilation/SelectiveCompiler.java
+++ b/src/main/java/org/eolang/opeo/compilation/SelectiveCompiler.java
@@ -27,7 +27,7 @@
import java.nio.file.Path;
import java.util.Arrays;
import java.util.stream.Collectors;
-import org.eolang.opeo.decompilation.handlers.RouterHandler;
+import org.eolang.opeo.decompilation.agents.RouterAgent;
import org.eolang.opeo.storage.CompilationStorage;
import org.eolang.opeo.storage.Storage;
import org.eolang.opeo.storage.XmirEntry;
@@ -65,7 +65,7 @@ public SelectiveCompiler(final Path xmirs, final Path output) {
*/
public SelectiveCompiler(final Storage storage) {
this.storage = storage;
- this.supported = new RouterHandler(false).supportedOpcodes();
+ this.supported = new RouterAgent(false).supportedOpcodes();
}
@Override
diff --git a/src/main/java/org/eolang/opeo/decompilation/InstructionHandler.java b/src/main/java/org/eolang/opeo/decompilation/DecompilationAgent.java
similarity index 83%
rename from src/main/java/org/eolang/opeo/decompilation/InstructionHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/DecompilationAgent.java
index 43cd23d5..ed253708 100644
--- a/src/main/java/org/eolang/opeo/decompilation/InstructionHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/DecompilationAgent.java
@@ -24,15 +24,15 @@
package org.eolang.opeo.decompilation;
/**
- * Instruction handler.
+ * An agent that tries to understand the current decompilation state and apply some changes to it.
* @since 0.1
*/
@FunctionalInterface
-public interface InstructionHandler {
+public interface DecompilationAgent {
/**
- * Handle instruction.
- * @param state Current instruction to handle together with operand stack and variables.
+ * Handle the current state.
+ * @param state Current state to handle together with operand stack and variables.
*/
void handle(DecompilerState state);
}
diff --git a/src/main/java/org/eolang/opeo/decompilation/DecompilerMachine.java b/src/main/java/org/eolang/opeo/decompilation/DecompilerMachine.java
index 79c91dbb..bc5cb600 100644
--- a/src/main/java/org/eolang/opeo/decompilation/DecompilerMachine.java
+++ b/src/main/java/org/eolang/opeo/decompilation/DecompilerMachine.java
@@ -29,7 +29,7 @@
import org.cactoos.list.ListOf;
import org.eolang.opeo.Instruction;
import org.eolang.opeo.ast.Root;
-import org.eolang.opeo.decompilation.handlers.RouterHandler;
+import org.eolang.opeo.decompilation.agents.RouterAgent;
import org.xembly.Directive;
/**
@@ -47,7 +47,7 @@ public final class DecompilerMachine {
/**
* Handler that redirects instructions.
*/
- private final RouterHandler router;
+ private final RouterAgent router;
/**
* Constructor.
@@ -73,7 +73,7 @@ public final class DecompilerMachine {
*/
public DecompilerMachine(final LocalVariables locals, final Map arguments) {
this.locals = locals;
- this.router = new RouterHandler(
+ this.router = new RouterAgent(
"true".equals(arguments.getOrDefault("counting", "true"))
);
}
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/AddHandler.java b/src/main/java/org/eolang/opeo/decompilation/agents/AddAgent.java
similarity index 90%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/AddHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/AddAgent.java
index 006b52c9..248cbcd2 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/AddHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/AddAgent.java
@@ -21,18 +21,18 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import org.eolang.opeo.ast.Addition;
import org.eolang.opeo.ast.AstNode;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
/**
* Add instruction handler.
* @since 0.1
*/
-public final class AddHandler implements InstructionHandler {
+public final class AddAgent implements DecompilationAgent {
@Override
public void handle(final DecompilerState state) {
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/BipushHandler.java b/src/main/java/org/eolang/opeo/decompilation/agents/BipushAgent.java
similarity index 89%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/BipushHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/BipushAgent.java
index e7a46414..3a9f62b0 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/BipushHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/BipushAgent.java
@@ -21,17 +21,17 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import org.eolang.opeo.ast.Literal;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
/**
* Bipush instruction handler.
* @since 0.1
*/
-public final class BipushHandler implements InstructionHandler {
+public final class BipushAgent implements DecompilationAgent {
@Override
public void handle(final DecompilerState state) {
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/CastHandler.java b/src/main/java/org/eolang/opeo/decompilation/agents/CastAgent.java
similarity index 89%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/CastHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/CastAgent.java
index d151c433..6c5228ad 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/CastHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/CastAgent.java
@@ -21,18 +21,18 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import org.eolang.opeo.ast.Cast;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
import org.objectweb.asm.Type;
/**
* Cast instruction handler.
* @since 0.2
*/
-public final class CastHandler implements InstructionHandler {
+public final class CastAgent implements DecompilationAgent {
/**
* Target type.
@@ -43,7 +43,7 @@ public final class CastHandler implements InstructionHandler {
* Constructor.
* @param target Target type
*/
- CastHandler(final Type target) {
+ CastAgent(final Type target) {
this.target = target;
}
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/CheckCastHandler.java b/src/main/java/org/eolang/opeo/decompilation/agents/CheckCastAgent.java
similarity index 90%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/CheckCastHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/CheckCastAgent.java
index 65f439e1..5d7cf152 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/CheckCastHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/CheckCastAgent.java
@@ -21,12 +21,12 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import org.eolang.opeo.ast.AstNode;
import org.eolang.opeo.ast.CheckCast;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
import org.objectweb.asm.Type;
/**
@@ -34,7 +34,7 @@
*
* @since 0.5
*/
-public final class CheckCastHandler implements InstructionHandler {
+public final class CheckCastAgent implements DecompilationAgent {
@Override
public void handle(final DecompilerState state) {
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/ConstHandler.java b/src/main/java/org/eolang/opeo/decompilation/agents/ConstAgent.java
similarity index 93%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/ConstHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/ConstAgent.java
index ecc40e89..2d1f42db 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/ConstHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/ConstAgent.java
@@ -21,12 +21,12 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import org.eolang.opeo.ast.AstNode;
import org.eolang.opeo.ast.Literal;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
@@ -34,7 +34,7 @@
* Iconst instruction handler.
* @since 0.1
*/
-public final class ConstHandler implements InstructionHandler {
+public final class ConstAgent implements DecompilationAgent {
/**
* Type of constant.
@@ -45,7 +45,7 @@ public final class ConstHandler implements InstructionHandler {
* Constructor.
* @param type Type of constant
*/
- ConstHandler(final Type type) {
+ ConstAgent(final Type type) {
this.type = type;
}
@@ -54,13 +54,13 @@ public void handle(final DecompilerState state) {
final int opcode = state.instruction().opcode();
final AstNode res;
if (this.type.equals(Type.INT_TYPE)) {
- res = ConstHandler.intConstant(opcode);
+ res = ConstAgent.intConstant(opcode);
} else if (this.type.equals(Type.LONG_TYPE)) {
- res = ConstHandler.longConstant(opcode);
+ res = ConstAgent.longConstant(opcode);
} else if (this.type.equals(Type.FLOAT_TYPE)) {
- res = ConstHandler.floatConstant(opcode);
+ res = ConstAgent.floatConstant(opcode);
} else if (this.type.equals(Type.DOUBLE_TYPE)) {
- res = ConstHandler.doubleConstant(opcode);
+ res = ConstAgent.doubleConstant(opcode);
} else {
throw new UnsupportedOperationException(
String.format("Type %s is not supported yet", this.type)
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/DupHandler.java b/src/main/java/org/eolang/opeo/decompilation/agents/DupAgent.java
similarity index 90%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/DupHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/DupAgent.java
index b9d681c3..3259bf98 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/DupHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/DupAgent.java
@@ -21,18 +21,18 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import org.eolang.opeo.ast.Duplicate;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
import org.eolang.opeo.decompilation.OperandStack;
/**
* Dup instruction handler.
* @since 0.1
*/
-public final class DupHandler implements InstructionHandler {
+public final class DupAgent implements DecompilationAgent {
@Override
public void handle(final DecompilerState state) {
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/GetFieldHandler.java b/src/main/java/org/eolang/opeo/decompilation/agents/GetFieldAgent.java
similarity index 91%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/GetFieldHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/GetFieldAgent.java
index 3f2544f2..0d98afef 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/GetFieldHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/GetFieldAgent.java
@@ -21,18 +21,18 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import org.eolang.opeo.ast.Attributes;
import org.eolang.opeo.ast.FieldRetrieval;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
/**
* Getfield instruction handler.
* @since 0.1
*/
-public final class GetFieldHandler implements InstructionHandler {
+public final class GetFieldAgent implements DecompilationAgent {
@Override
public void handle(final DecompilerState state) {
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/GetStaticHnadler.java b/src/main/java/org/eolang/opeo/decompilation/agents/GetStaticAgent.java
similarity index 90%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/GetStaticHnadler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/GetStaticAgent.java
index 329a832d..ba1712bb 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/GetStaticHnadler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/GetStaticAgent.java
@@ -21,17 +21,17 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import org.eolang.opeo.ast.ClassField;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
/**
* Getstatic instruction handler.
* @since 0.1
*/
-public final class GetStaticHnadler implements InstructionHandler {
+public final class GetStaticAgent implements DecompilationAgent {
@Override
public void handle(final DecompilerState state) {
final String klass = (String) state.operand(0);
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/IfHandler.java b/src/main/java/org/eolang/opeo/decompilation/agents/IfAgent.java
similarity index 93%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/IfHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/IfAgent.java
index edf49385..2f0dbdcc 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/IfHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/IfAgent.java
@@ -21,12 +21,12 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import org.eolang.opeo.ast.AstNode;
import org.eolang.opeo.ast.If;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
import org.eolang.opeo.decompilation.OperandStack;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
@@ -38,7 +38,7 @@
* (signed short constructed from unsigned bytes branchbyte1 << 8 | branchbyte2)
* @since 0.2
*/
-public final class IfHandler implements InstructionHandler {
+public final class IfAgent implements DecompilationAgent {
@Override
public void handle(final DecompilerState state) {
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/InvokedynamicHandler.java b/src/main/java/org/eolang/opeo/decompilation/agents/InvokedynamicAgent.java
similarity index 92%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/InvokedynamicHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/InvokedynamicAgent.java
index 81e2c8c2..4e055876 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/InvokedynamicHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/InvokedynamicAgent.java
@@ -21,14 +21,14 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import java.util.Collections;
import java.util.List;
import org.eolang.opeo.ast.AstNode;
import org.eolang.opeo.ast.DynamicInvocation;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Type;
@@ -36,7 +36,7 @@
* Invokedynamic instruction handler.
* @since 0.5
*/
-public final class InvokedynamicHandler implements InstructionHandler {
+public final class InvokedynamicAgent implements DecompilationAgent {
@Override
public void handle(final DecompilerState state) {
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/InvokeinterfaceHandler.java b/src/main/java/org/eolang/opeo/decompilation/agents/InvokeinterfaceAgent.java
similarity index 93%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/InvokeinterfaceHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/InvokeinterfaceAgent.java
index bd29b549..d8fd1d36 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/InvokeinterfaceHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/InvokeinterfaceAgent.java
@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import java.util.Collections;
import java.util.List;
@@ -29,7 +29,7 @@
import org.eolang.opeo.ast.Attributes;
import org.eolang.opeo.ast.InterfaceInvocation;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
import org.objectweb.asm.Type;
/**
@@ -48,7 +48,7 @@
*
* @since 0.2
*/
-public final class InvokeinterfaceHandler implements InstructionHandler {
+public final class InvokeinterfaceAgent implements DecompilationAgent {
@Override
public void handle(final DecompilerState state) {
final String owner = (String) state.operand(0);
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/InvokespecialHandler.java b/src/main/java/org/eolang/opeo/decompilation/agents/InvokespecialAgent.java
similarity index 92%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/InvokespecialHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/InvokespecialAgent.java
index d85e423e..977dbcc4 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/InvokespecialHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/InvokespecialAgent.java
@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import java.util.Collections;
import java.util.List;
@@ -34,7 +34,7 @@
import org.eolang.opeo.ast.Super;
import org.eolang.opeo.ast.This;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
import org.objectweb.asm.Type;
/**
@@ -42,14 +42,14 @@
*
* @since 0.1
* @todo #229:90min Is Labeled Class an Abstraction Failure?
- * As you can see in {@link InvokespecialHandler} we use many 'instanceof' checks.
+ * As you can see in {@link InvokespecialAgent} we use many 'instanceof' checks.
* This is a clear sign that the class hierarchy is not well designed.
* The original problem lies in the {@link Labeled} class.
* We need to find more elegant solutions to handle labels in AST.
* @checkstyle NoJavadocForOverriddenMethodsCheck (500 lines)
* @checkstyle MultilineJavadocTagsCheck (500 lines)
*/
-public final class InvokespecialHandler implements InstructionHandler {
+public final class InvokespecialAgent implements DecompilationAgent {
/**
* Handle invokespecial instruction.
@@ -84,7 +84,7 @@ public void handle(final DecompilerState state) {
);
Collections.reverse(args);
final AstNode target = state.stack().pop();
- if (InvokespecialHandler.isThis(target)) {
+ if (InvokespecialAgent.isThis(target)) {
state.stack().push(
new Super(target, args, descriptor, type, name)
);
@@ -135,9 +135,9 @@ private static boolean isThis(final AstNode candidate) {
if (candidate instanceof This) {
result = true;
} else if (candidate instanceof Labeled) {
- result = InvokespecialHandler.isThis(((Labeled) candidate).origin());
+ result = InvokespecialAgent.isThis(((Labeled) candidate).origin());
} else if (candidate instanceof Duplicate) {
- result = InvokespecialHandler.isThis(((Duplicate) candidate).origin());
+ result = InvokespecialAgent.isThis(((Duplicate) candidate).origin());
} else {
result = false;
}
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/InvokestaticHander.java b/src/main/java/org/eolang/opeo/decompilation/agents/InvokestaticAgent.java
similarity index 92%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/InvokestaticHander.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/InvokestaticAgent.java
index 00a8ced5..654c700f 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/InvokestaticHander.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/InvokestaticAgent.java
@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import java.util.Collections;
import java.util.List;
@@ -30,14 +30,14 @@
import org.eolang.opeo.ast.Owner;
import org.eolang.opeo.ast.StaticInvocation;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
import org.objectweb.asm.Type;
/**
* Invokestatic instruction handler.
* @since 0.1
*/
-public final class InvokestaticHander implements InstructionHandler {
+public final class InvokestaticAgent implements DecompilationAgent {
@Override
public void handle(final DecompilerState state) {
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/InvokevirtualHandler.java b/src/main/java/org/eolang/opeo/decompilation/agents/InvokevirtualAgent.java
similarity index 93%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/InvokevirtualHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/InvokevirtualAgent.java
index 31fa25fa..7e937de3 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/InvokevirtualHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/InvokevirtualAgent.java
@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import java.util.Collections;
import java.util.List;
@@ -29,7 +29,7 @@
import org.eolang.opeo.ast.Attributes;
import org.eolang.opeo.ast.Invocation;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
import org.objectweb.asm.Type;
/**
@@ -47,7 +47,7 @@
*
* @since 0.1
*/
-public final class InvokevirtualHandler implements InstructionHandler {
+public final class InvokevirtualAgent implements DecompilationAgent {
@Override
public void handle(final DecompilerState state) {
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/LabelHandler.java b/src/main/java/org/eolang/opeo/decompilation/agents/LabelAgent.java
similarity index 90%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/LabelHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/LabelAgent.java
index 5be17b5a..3d10b406 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/LabelHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/LabelAgent.java
@@ -21,19 +21,19 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import org.eolang.opeo.ast.AstNode;
import org.eolang.opeo.ast.Label;
import org.eolang.opeo.ast.Labeled;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
/**
* Label instruction handler.
* @since 0.1
*/
-public final class LabelHandler implements InstructionHandler {
+public final class LabelAgent implements DecompilationAgent {
@Override
public void handle(final DecompilerState state) {
final Labeled node = new Labeled(
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/LdcHandler.java b/src/main/java/org/eolang/opeo/decompilation/agents/LdcAgent.java
similarity index 89%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/LdcHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/LdcAgent.java
index 479e2a06..01861883 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/LdcHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/LdcAgent.java
@@ -21,17 +21,17 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import org.eolang.opeo.ast.Constant;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
/**
* Ldc instruction handler.
* @since 0.1
*/
-public final class LdcHandler implements InstructionHandler {
+public final class LdcAgent implements DecompilationAgent {
@Override
public void handle(final DecompilerState state) {
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/LoadHandler.java b/src/main/java/org/eolang/opeo/decompilation/agents/LoadAgent.java
similarity index 90%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/LoadHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/LoadAgent.java
index 1703958c..5c8e49d3 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/LoadHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/LoadAgent.java
@@ -21,10 +21,10 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
import org.objectweb.asm.Type;
/**
@@ -35,7 +35,7 @@
* ...
* @since 0.1
*/
-public final class LoadHandler implements InstructionHandler {
+public final class LoadAgent implements DecompilationAgent {
/**
* Type of the variable.
@@ -46,7 +46,7 @@ public final class LoadHandler implements InstructionHandler {
* Constructor.
* @param type Type of the variable.
*/
- public LoadHandler(final Type type) {
+ public LoadAgent(final Type type) {
this.type = type;
}
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/MulHandler.java b/src/main/java/org/eolang/opeo/decompilation/agents/MulAgent.java
similarity index 91%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/MulHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/MulAgent.java
index 280bb6f4..dd2c487f 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/MulHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/MulAgent.java
@@ -21,20 +21,20 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import org.eolang.opeo.ast.AstNode;
import org.eolang.opeo.ast.Multiplication;
import org.eolang.opeo.ast.Opcode;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
import org.objectweb.asm.Opcodes;
/**
* Mul instruction handler.
* @since 0.1
*/
-public final class MulHandler implements InstructionHandler {
+public final class MulAgent implements DecompilationAgent {
/**
* Do we put numbers to opcodes?
@@ -45,7 +45,7 @@ public final class MulHandler implements InstructionHandler {
* Constructor.
* @param counting Do we put numbers to opcodes?
*/
- MulHandler(final boolean counting) {
+ MulAgent(final boolean counting) {
this.counting = counting;
}
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/NewHandler.java b/src/main/java/org/eolang/opeo/decompilation/agents/NewAgent.java
similarity index 89%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/NewHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/NewAgent.java
index 9cf78c66..544f5ce2 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/NewHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/NewAgent.java
@@ -21,17 +21,17 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import org.eolang.opeo.ast.NewAddress;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
/**
* New instruction handler.
* @since 0.1
*/
-public final class NewHandler implements InstructionHandler {
+public final class NewAgent implements DecompilationAgent {
@Override
public void handle(final DecompilerState state) {
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/NewArrayHandler.java b/src/main/java/org/eolang/opeo/decompilation/agents/NewArrayAgent.java
similarity index 90%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/NewArrayHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/NewArrayAgent.java
index e6d5ab31..bc767e3e 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/NewArrayHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/NewArrayAgent.java
@@ -21,20 +21,20 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import org.eolang.opeo.ast.ArrayConstructor;
import org.eolang.opeo.ast.AstNode;
import org.eolang.opeo.ast.Reference;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
import org.eolang.opeo.decompilation.OperandStack;
/**
* New array instruction handler.
* @since 0.1
*/
-public final class NewArrayHandler implements InstructionHandler {
+public final class NewArrayAgent implements DecompilationAgent {
@Override
public void handle(final DecompilerState state) {
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/PopHandler.java b/src/main/java/org/eolang/opeo/decompilation/agents/PopAgent.java
similarity index 90%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/PopHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/PopAgent.java
index cb114de5..97cf73a7 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/PopHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/PopAgent.java
@@ -21,18 +21,18 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import org.eolang.opeo.ast.Popped;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
import org.eolang.opeo.decompilation.OperandStack;
/**
* Pop instruction handler.
* @since 0.1
*/
-public final class PopHandler implements InstructionHandler {
+public final class PopAgent implements DecompilationAgent {
@Override
public void handle(final DecompilerState state) {
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/PutFieldHnadler.java b/src/main/java/org/eolang/opeo/decompilation/agents/PutFieldAgent.java
similarity index 92%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/PutFieldHnadler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/PutFieldAgent.java
index b89060b3..2849d3a5 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/PutFieldHnadler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/PutFieldAgent.java
@@ -21,21 +21,21 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import org.eolang.opeo.ast.AstNode;
import org.eolang.opeo.ast.Attributes;
import org.eolang.opeo.ast.Field;
import org.eolang.opeo.ast.FieldAssignment;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
/**
* Putfield instruction handler.
* Stack [before]->[after]: "objectref, value →"
* @since 0.1
*/
-public final class PutFieldHnadler implements InstructionHandler {
+public final class PutFieldAgent implements DecompilationAgent {
@Override
public void handle(final DecompilerState state) {
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/ReturnHandler.java b/src/main/java/org/eolang/opeo/decompilation/agents/ReturnAgent.java
similarity index 93%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/ReturnHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/ReturnAgent.java
index fa3d7f00..eb56509d 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/ReturnHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/ReturnAgent.java
@@ -21,11 +21,11 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import org.eolang.opeo.ast.Return;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
import org.eolang.opeo.decompilation.OperandStack;
import org.objectweb.asm.Opcodes;
@@ -34,7 +34,7 @@
* @since 0.1
* @checkstyle ClassFanOutComplexityCheck (500 lines)
*/
-public final class ReturnHandler implements InstructionHandler {
+public final class ReturnAgent implements DecompilationAgent {
@Override
public void handle(final DecompilerState state) {
diff --git a/src/main/java/org/eolang/opeo/decompilation/agents/RouterAgent.java b/src/main/java/org/eolang/opeo/decompilation/agents/RouterAgent.java
new file mode 100644
index 00000000..c57090a1
--- /dev/null
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/RouterAgent.java
@@ -0,0 +1,200 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2016-2023 Objectionary.com
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package org.eolang.opeo.decompilation.agents;
+
+import java.util.Map;
+import org.cactoos.map.MapEntry;
+import org.cactoos.map.MapOf;
+import org.eolang.opeo.LabelInstruction;
+import org.eolang.opeo.ast.Opcode;
+import org.eolang.opeo.ast.OpcodeName;
+import org.eolang.opeo.decompilation.DecompilerState;
+import org.eolang.opeo.decompilation.DecompilationAgent;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Type;
+
+/**
+ * General Instruction Handler.
+ * This handler redirects handling of instructions depending on an incoming instruction.
+ * @since 0.2
+ * @checkstyle ClassFanOutComplexityCheck (500 lines)
+ */
+public final class RouterAgent implements DecompilationAgent {
+
+ /**
+ * Index of unimplemented handler.
+ */
+ private static final int UNIMPLEMENTED = -1;
+
+ /**
+ * ALl instruction handlers.
+ */
+ private final Map handlers;
+
+ /**
+ * Constructor.
+ * @param counting Do we put numbers to opcodes?
+ */
+ public RouterAgent(final boolean counting) {
+ this(
+ new MapOf(
+ new MapEntry<>(Opcodes.ICONST_M1, new ConstAgent(Type.INT_TYPE)),
+ new MapEntry<>(Opcodes.ICONST_0, new ConstAgent(Type.INT_TYPE)),
+ new MapEntry<>(Opcodes.ICONST_1, new ConstAgent(Type.INT_TYPE)),
+ new MapEntry<>(Opcodes.ICONST_2, new ConstAgent(Type.INT_TYPE)),
+ new MapEntry<>(Opcodes.ICONST_3, new ConstAgent(Type.INT_TYPE)),
+ new MapEntry<>(Opcodes.ICONST_4, new ConstAgent(Type.INT_TYPE)),
+ new MapEntry<>(Opcodes.ICONST_5, new ConstAgent(Type.INT_TYPE)),
+ new MapEntry<>(Opcodes.LCONST_0, new ConstAgent(Type.LONG_TYPE)),
+ new MapEntry<>(Opcodes.LCONST_1, new ConstAgent(Type.LONG_TYPE)),
+ new MapEntry<>(Opcodes.FCONST_0, new ConstAgent(Type.FLOAT_TYPE)),
+ new MapEntry<>(Opcodes.FCONST_1, new ConstAgent(Type.FLOAT_TYPE)),
+ new MapEntry<>(Opcodes.FCONST_2, new ConstAgent(Type.FLOAT_TYPE)),
+ new MapEntry<>(Opcodes.DCONST_0, new ConstAgent(Type.DOUBLE_TYPE)),
+ new MapEntry<>(Opcodes.DCONST_1, new ConstAgent(Type.DOUBLE_TYPE)),
+ new MapEntry<>(Opcodes.IADD, new AddAgent()),
+ new MapEntry<>(Opcodes.LADD, new AddAgent()),
+ new MapEntry<>(Opcodes.FADD, new AddAgent()),
+ new MapEntry<>(Opcodes.DADD, new AddAgent()),
+ new MapEntry<>(Opcodes.ISUB, new SubstractionAgent()),
+ new MapEntry<>(Opcodes.LSUB, new SubstractionAgent()),
+ new MapEntry<>(Opcodes.FSUB, new SubstractionAgent()),
+ new MapEntry<>(Opcodes.DSUB, new SubstractionAgent()),
+ new MapEntry<>(Opcodes.IMUL, new MulAgent(counting)),
+ new MapEntry<>(Opcodes.IF_ICMPGT, new IfAgent()),
+ new MapEntry<>(Opcodes.I2B, new CastAgent(Type.BYTE_TYPE)),
+ new MapEntry<>(Opcodes.I2C, new CastAgent(Type.CHAR_TYPE)),
+ new MapEntry<>(Opcodes.I2S, new CastAgent(Type.SHORT_TYPE)),
+ new MapEntry<>(Opcodes.I2L, new CastAgent(Type.LONG_TYPE)),
+ new MapEntry<>(Opcodes.I2F, new CastAgent(Type.FLOAT_TYPE)),
+ new MapEntry<>(Opcodes.I2D, new CastAgent(Type.DOUBLE_TYPE)),
+ new MapEntry<>(Opcodes.L2I, new CastAgent(Type.INT_TYPE)),
+ new MapEntry<>(Opcodes.L2F, new CastAgent(Type.FLOAT_TYPE)),
+ new MapEntry<>(Opcodes.L2D, new CastAgent(Type.DOUBLE_TYPE)),
+ new MapEntry<>(Opcodes.F2I, new CastAgent(Type.INT_TYPE)),
+ new MapEntry<>(Opcodes.F2L, new CastAgent(Type.LONG_TYPE)),
+ new MapEntry<>(Opcodes.F2D, new CastAgent(Type.DOUBLE_TYPE)),
+ new MapEntry<>(Opcodes.D2I, new CastAgent(Type.INT_TYPE)),
+ new MapEntry<>(Opcodes.D2L, new CastAgent(Type.LONG_TYPE)),
+ new MapEntry<>(Opcodes.D2F, new CastAgent(Type.FLOAT_TYPE)),
+ new MapEntry<>(Opcodes.ILOAD, new LoadAgent(Type.INT_TYPE)),
+ new MapEntry<>(Opcodes.LLOAD, new LoadAgent(Type.LONG_TYPE)),
+ new MapEntry<>(Opcodes.FLOAD, new LoadAgent(Type.FLOAT_TYPE)),
+ new MapEntry<>(Opcodes.DLOAD, new LoadAgent(Type.DOUBLE_TYPE)),
+ new MapEntry<>(Opcodes.ALOAD, new LoadAgent(Type.getType(Object.class))),
+ new MapEntry<>(Opcodes.ISTORE, new StoreAgent(Type.INT_TYPE)),
+ new MapEntry<>(Opcodes.LSTORE, new StoreAgent(Type.LONG_TYPE)),
+ new MapEntry<>(Opcodes.FSTORE, new StoreAgent(Type.FLOAT_TYPE)),
+ new MapEntry<>(Opcodes.DSTORE, new StoreAgent(Type.DOUBLE_TYPE)),
+ new MapEntry<>(Opcodes.ASTORE, new StoreAgent(Type.getType(Object.class))),
+ new MapEntry<>(Opcodes.AASTORE, new StoreToArrayAgent()),
+ new MapEntry<>(Opcodes.ANEWARRAY, new NewArrayAgent()),
+ new MapEntry<>(Opcodes.CHECKCAST, new CheckCastAgent()),
+ new MapEntry<>(Opcodes.NEW, new NewAgent()),
+ new MapEntry<>(Opcodes.DUP, new DupAgent()),
+ new MapEntry<>(Opcodes.BIPUSH, new BipushAgent()),
+ new MapEntry<>(Opcodes.INVOKESPECIAL, new InvokespecialAgent()),
+ new MapEntry<>(Opcodes.INVOKEVIRTUAL, new InvokevirtualAgent()),
+ new MapEntry<>(Opcodes.INVOKESTATIC, new InvokestaticAgent()),
+ new MapEntry<>(Opcodes.INVOKEINTERFACE, new InvokeinterfaceAgent()),
+ new MapEntry<>(Opcodes.INVOKEDYNAMIC, new InvokedynamicAgent()),
+ new MapEntry<>(Opcodes.GETFIELD, new GetFieldAgent()),
+ new MapEntry<>(Opcodes.PUTFIELD, new PutFieldAgent()),
+ new MapEntry<>(Opcodes.GETSTATIC, new GetStaticAgent()),
+ new MapEntry<>(Opcodes.LDC, new LdcAgent()),
+ new MapEntry<>(Opcodes.POP, new PopAgent()),
+ new MapEntry<>(Opcodes.RETURN, new ReturnAgent()),
+ new MapEntry<>(Opcodes.IRETURN, new ReturnAgent()),
+ new MapEntry<>(Opcodes.ARETURN, new ReturnAgent()),
+ new MapEntry<>(LabelInstruction.LABEL_OPCODE, new LabelAgent()),
+ new MapEntry<>(RouterAgent.UNIMPLEMENTED, new UnimplementedHandler(counting))
+ )
+ );
+ }
+
+ /**
+ * Constructor.
+ * @param handlers All handlers that will try to handle incoming instructions.
+ */
+ private RouterAgent(final Map handlers) {
+ this.handlers = handlers;
+ }
+
+ @Override
+ public void handle(final DecompilerState state) {
+ this.handler(state.instruction().opcode()).handle(state);
+ }
+
+ /**
+ * Get supported opcodes.
+ * @return Supported opcodes.
+ */
+ public String[] supportedOpcodes() {
+ return this.handlers.keySet()
+ .stream()
+ .map(OpcodeName::new)
+ .map(OpcodeName::simplified)
+ .toArray(String[]::new);
+ }
+
+ /**
+ * Get instruction handler.
+ * @param opcode Instruction opcode.
+ * @return Instruction handler.
+ */
+ private DecompilationAgent handler(final int opcode) {
+ return this.handlers.getOrDefault(opcode, this.handlers.get(RouterAgent.UNIMPLEMENTED));
+ }
+
+ /**
+ * Unimplemented instruction handler.
+ * @since 0.1
+ */
+ private static final class UnimplementedHandler implements DecompilationAgent {
+
+ /**
+ * Do we put numbers to opcodes?
+ */
+ private final boolean counting;
+
+ /**
+ * Constructor.
+ * @param counting Flag which decides if we need to count opcodes.
+ */
+ private UnimplementedHandler(final boolean counting) {
+ this.counting = counting;
+ }
+
+ @Override
+ public void handle(final DecompilerState state) {
+ state.stack().push(
+ new Opcode(
+ state.instruction().opcode(),
+ state.instruction().operands(),
+ this.counting
+ )
+ );
+ }
+ }
+}
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/StoreHandler.java b/src/main/java/org/eolang/opeo/decompilation/agents/StoreAgent.java
similarity index 91%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/StoreHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/StoreAgent.java
index 59cd86bc..63534e27 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/StoreHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/StoreAgent.java
@@ -21,14 +21,14 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import org.eolang.opeo.ast.AstNode;
import org.eolang.opeo.ast.LocalVariable;
import org.eolang.opeo.ast.Typed;
import org.eolang.opeo.ast.VariableAssignment;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
import org.eolang.opeo.decompilation.OperandStack;
import org.objectweb.asm.Type;
@@ -36,7 +36,7 @@
* Store instruction handler.
* @since 0.1
*/
-public final class StoreHandler implements InstructionHandler {
+public final class StoreAgent implements DecompilationAgent {
/**
* Type of the variable.
@@ -47,7 +47,7 @@ public final class StoreHandler implements InstructionHandler {
* Constructor.
* @param type Type of the variable.
*/
- public StoreHandler(final Type type) {
+ public StoreAgent(final Type type) {
this.type = type;
}
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/StoreToArrayHandler.java b/src/main/java/org/eolang/opeo/decompilation/agents/StoreToArrayAgent.java
similarity index 93%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/StoreToArrayHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/StoreToArrayAgent.java
index ec13b8d9..069c111d 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/StoreToArrayHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/StoreToArrayAgent.java
@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import org.eolang.opeo.ast.AstNode;
import org.eolang.opeo.ast.Duplicate;
@@ -30,7 +30,7 @@
import org.eolang.opeo.ast.Reference;
import org.eolang.opeo.ast.StoreArray;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
/**
* Store to array instruction handler.
@@ -38,12 +38,12 @@
* Opcodes: aastore
* Stack [before]->[after]: "arrayref, index, value →"
* @since 0.1
- * @todo #329:90min Avoid using 'instance of' in {@link StoreToArrayHandler#findRef(AstNode)}.
+ * @todo #329:90min Avoid using 'instance of' in {@link StoreToArrayAgent#findRef(AstNode)}.
* Here we use 'instance of' statement to find a Reference.
* The solution related to Reference looks incorrect, in general.
* We should invent a proper solution without the use of this statement.
*/
-public final class StoreToArrayHandler implements InstructionHandler {
+public final class StoreToArrayAgent implements DecompilationAgent {
@Override
public void handle(final DecompilerState state) {
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/SubstractionHandler.java b/src/main/java/org/eolang/opeo/decompilation/agents/SubstractionAgent.java
similarity index 90%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/SubstractionHandler.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/SubstractionAgent.java
index f5b66c0d..f3a841cf 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/SubstractionHandler.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/SubstractionAgent.java
@@ -21,18 +21,18 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
import org.eolang.opeo.ast.AstNode;
import org.eolang.opeo.ast.Substraction;
import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
+import org.eolang.opeo.decompilation.DecompilationAgent;
/**
* Substraction instruction handler.
* @since 0.1
*/
-public final class SubstractionHandler implements InstructionHandler {
+public final class SubstractionAgent implements DecompilationAgent {
@Override
public void handle(final DecompilerState state) {
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/package-info.java b/src/main/java/org/eolang/opeo/decompilation/agents/package-info.java
similarity index 96%
rename from src/main/java/org/eolang/opeo/decompilation/handlers/package-info.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/package-info.java
index a520f234..0eaf15e0 100644
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/package-info.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/package-info.java
@@ -29,4 +29,4 @@
* It would also be good to generalize some of the handlers. For example, AddHandler might
* handle all the types, not only Integer and Long.
*/
-package org.eolang.opeo.decompilation.handlers;
+package org.eolang.opeo.decompilation.agents;
diff --git a/src/main/java/org/eolang/opeo/decompilation/handlers/RouterHandler.java b/src/main/java/org/eolang/opeo/decompilation/handlers/RouterHandler.java
deleted file mode 100644
index 81e031a1..00000000
--- a/src/main/java/org/eolang/opeo/decompilation/handlers/RouterHandler.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2016-2023 Objectionary.com
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package org.eolang.opeo.decompilation.handlers;
-
-import java.util.Map;
-import org.cactoos.map.MapEntry;
-import org.cactoos.map.MapOf;
-import org.eolang.opeo.LabelInstruction;
-import org.eolang.opeo.ast.Opcode;
-import org.eolang.opeo.ast.OpcodeName;
-import org.eolang.opeo.decompilation.DecompilerState;
-import org.eolang.opeo.decompilation.InstructionHandler;
-import org.objectweb.asm.Opcodes;
-import org.objectweb.asm.Type;
-
-/**
- * General Instruction Handler.
- * This handler redirects handling of instructions depending on an incoming instruction.
- * @since 0.2
- * @checkstyle ClassFanOutComplexityCheck (500 lines)
- */
-public final class RouterHandler implements InstructionHandler {
-
- /**
- * Index of unimplemented handler.
- */
- private static final int UNIMPLEMENTED = -1;
-
- /**
- * ALl instruction handlers.
- */
- private final Map handlers;
-
- /**
- * Constructor.
- * @param counting Do we put numbers to opcodes?
- */
- public RouterHandler(final boolean counting) {
- this(
- new MapOf(
- new MapEntry<>(Opcodes.ICONST_M1, new ConstHandler(Type.INT_TYPE)),
- new MapEntry<>(Opcodes.ICONST_0, new ConstHandler(Type.INT_TYPE)),
- new MapEntry<>(Opcodes.ICONST_1, new ConstHandler(Type.INT_TYPE)),
- new MapEntry<>(Opcodes.ICONST_2, new ConstHandler(Type.INT_TYPE)),
- new MapEntry<>(Opcodes.ICONST_3, new ConstHandler(Type.INT_TYPE)),
- new MapEntry<>(Opcodes.ICONST_4, new ConstHandler(Type.INT_TYPE)),
- new MapEntry<>(Opcodes.ICONST_5, new ConstHandler(Type.INT_TYPE)),
- new MapEntry<>(Opcodes.LCONST_0, new ConstHandler(Type.LONG_TYPE)),
- new MapEntry<>(Opcodes.LCONST_1, new ConstHandler(Type.LONG_TYPE)),
- new MapEntry<>(Opcodes.FCONST_0, new ConstHandler(Type.FLOAT_TYPE)),
- new MapEntry<>(Opcodes.FCONST_1, new ConstHandler(Type.FLOAT_TYPE)),
- new MapEntry<>(Opcodes.FCONST_2, new ConstHandler(Type.FLOAT_TYPE)),
- new MapEntry<>(Opcodes.DCONST_0, new ConstHandler(Type.DOUBLE_TYPE)),
- new MapEntry<>(Opcodes.DCONST_1, new ConstHandler(Type.DOUBLE_TYPE)),
- new MapEntry<>(Opcodes.IADD, new AddHandler()),
- new MapEntry<>(Opcodes.LADD, new AddHandler()),
- new MapEntry<>(Opcodes.FADD, new AddHandler()),
- new MapEntry<>(Opcodes.DADD, new AddHandler()),
- new MapEntry<>(Opcodes.ISUB, new SubstractionHandler()),
- new MapEntry<>(Opcodes.LSUB, new SubstractionHandler()),
- new MapEntry<>(Opcodes.FSUB, new SubstractionHandler()),
- new MapEntry<>(Opcodes.DSUB, new SubstractionHandler()),
- new MapEntry<>(Opcodes.IMUL, new MulHandler(counting)),
- new MapEntry<>(Opcodes.IF_ICMPGT, new IfHandler()),
- new MapEntry<>(Opcodes.I2B, new CastHandler(Type.BYTE_TYPE)),
- new MapEntry<>(Opcodes.I2C, new CastHandler(Type.CHAR_TYPE)),
- new MapEntry<>(Opcodes.I2S, new CastHandler(Type.SHORT_TYPE)),
- new MapEntry<>(Opcodes.I2L, new CastHandler(Type.LONG_TYPE)),
- new MapEntry<>(Opcodes.I2F, new CastHandler(Type.FLOAT_TYPE)),
- new MapEntry<>(Opcodes.I2D, new CastHandler(Type.DOUBLE_TYPE)),
- new MapEntry<>(Opcodes.L2I, new CastHandler(Type.INT_TYPE)),
- new MapEntry<>(Opcodes.L2F, new CastHandler(Type.FLOAT_TYPE)),
- new MapEntry<>(Opcodes.L2D, new CastHandler(Type.DOUBLE_TYPE)),
- new MapEntry<>(Opcodes.F2I, new CastHandler(Type.INT_TYPE)),
- new MapEntry<>(Opcodes.F2L, new CastHandler(Type.LONG_TYPE)),
- new MapEntry<>(Opcodes.F2D, new CastHandler(Type.DOUBLE_TYPE)),
- new MapEntry<>(Opcodes.D2I, new CastHandler(Type.INT_TYPE)),
- new MapEntry<>(Opcodes.D2L, new CastHandler(Type.LONG_TYPE)),
- new MapEntry<>(Opcodes.D2F, new CastHandler(Type.FLOAT_TYPE)),
- new MapEntry<>(Opcodes.ILOAD, new LoadHandler(Type.INT_TYPE)),
- new MapEntry<>(Opcodes.LLOAD, new LoadHandler(Type.LONG_TYPE)),
- new MapEntry<>(Opcodes.FLOAD, new LoadHandler(Type.FLOAT_TYPE)),
- new MapEntry<>(Opcodes.DLOAD, new LoadHandler(Type.DOUBLE_TYPE)),
- new MapEntry<>(Opcodes.ALOAD, new LoadHandler(Type.getType(Object.class))),
- new MapEntry<>(Opcodes.ISTORE, new StoreHandler(Type.INT_TYPE)),
- new MapEntry<>(Opcodes.LSTORE, new StoreHandler(Type.LONG_TYPE)),
- new MapEntry<>(Opcodes.FSTORE, new StoreHandler(Type.FLOAT_TYPE)),
- new MapEntry<>(Opcodes.DSTORE, new StoreHandler(Type.DOUBLE_TYPE)),
- new MapEntry<>(Opcodes.ASTORE, new StoreHandler(Type.getType(Object.class))),
- new MapEntry<>(Opcodes.AASTORE, new StoreToArrayHandler()),
- new MapEntry<>(Opcodes.ANEWARRAY, new NewArrayHandler()),
- new MapEntry<>(Opcodes.CHECKCAST, new CheckCastHandler()),
- new MapEntry<>(Opcodes.NEW, new NewHandler()),
- new MapEntry<>(Opcodes.DUP, new DupHandler()),
- new MapEntry<>(Opcodes.BIPUSH, new BipushHandler()),
- new MapEntry<>(Opcodes.INVOKESPECIAL, new InvokespecialHandler()),
- new MapEntry<>(Opcodes.INVOKEVIRTUAL, new InvokevirtualHandler()),
- new MapEntry<>(Opcodes.INVOKESTATIC, new InvokestaticHander()),
- new MapEntry<>(Opcodes.INVOKEINTERFACE, new InvokeinterfaceHandler()),
- new MapEntry<>(Opcodes.INVOKEDYNAMIC, new InvokedynamicHandler()),
- new MapEntry<>(Opcodes.GETFIELD, new GetFieldHandler()),
- new MapEntry<>(Opcodes.PUTFIELD, new PutFieldHnadler()),
- new MapEntry<>(Opcodes.GETSTATIC, new GetStaticHnadler()),
- new MapEntry<>(Opcodes.LDC, new LdcHandler()),
- new MapEntry<>(Opcodes.POP, new PopHandler()),
- new MapEntry<>(Opcodes.RETURN, new ReturnHandler()),
- new MapEntry<>(Opcodes.IRETURN, new ReturnHandler()),
- new MapEntry<>(Opcodes.ARETURN, new ReturnHandler()),
- new MapEntry<>(LabelInstruction.LABEL_OPCODE, new LabelHandler()),
- new MapEntry<>(RouterHandler.UNIMPLEMENTED, new UnimplementedHandler(counting))
- )
- );
- }
-
- /**
- * Constructor.
- * @param handlers All handlers that will try to handle incoming instructions.
- */
- private RouterHandler(final Map handlers) {
- this.handlers = handlers;
- }
-
- @Override
- public void handle(final DecompilerState state) {
- this.handler(state.instruction().opcode()).handle(state);
- }
-
- /**
- * Get supported opcodes.
- * @return Supported opcodes.
- */
- public String[] supportedOpcodes() {
- return this.handlers.keySet()
- .stream()
- .map(OpcodeName::new)
- .map(OpcodeName::simplified)
- .toArray(String[]::new);
- }
-
- /**
- * Get instruction handler.
- * @param opcode Instruction opcode.
- * @return Instruction handler.
- */
- private InstructionHandler handler(final int opcode) {
- return this.handlers.getOrDefault(opcode, this.handlers.get(RouterHandler.UNIMPLEMENTED));
- }
-
- /**
- * Unimplemented instruction handler.
- * @since 0.1
- */
- private static final class UnimplementedHandler implements InstructionHandler {
-
- /**
- * Do we put numbers to opcodes?
- */
- private final boolean counting;
-
- /**
- * Constructor.
- * @param counting Flag which decides if we need to count opcodes.
- */
- private UnimplementedHandler(final boolean counting) {
- this.counting = counting;
- }
-
- @Override
- public void handle(final DecompilerState state) {
- state.stack().push(
- new Opcode(
- state.instruction().opcode(),
- state.instruction().operands(),
- this.counting
- )
- );
- }
- }
-}
diff --git a/src/test/java/org/eolang/opeo/decompilation/SelectiveDecompilerTest.java b/src/test/java/org/eolang/opeo/decompilation/SelectiveDecompilerTest.java
index d00db47b..38325c88 100644
--- a/src/test/java/org/eolang/opeo/decompilation/SelectiveDecompilerTest.java
+++ b/src/test/java/org/eolang/opeo/decompilation/SelectiveDecompilerTest.java
@@ -26,7 +26,7 @@
import java.util.stream.Collectors;
import org.cactoos.io.ResourceOf;
import org.eolang.opeo.SelectiveDecompiler;
-import org.eolang.opeo.decompilation.handlers.RouterHandler;
+import org.eolang.opeo.decompilation.agents.RouterAgent;
import org.eolang.opeo.storage.InMemoryStorage;
import org.eolang.opeo.storage.XmirEntry;
import org.hamcrest.MatcherAssert;
@@ -161,7 +161,7 @@ void avoidsDecompileLargeFileWithUnknownDependencies() {
void identifiesUnsupportedOpcodes() {
MatcherAssert.assertThat(
"We expect that the supported opcodes won't contain the 'GOTO' opcode since we don't support it yet.",
- new RouterHandler(false).supportedOpcodes(),
+ new RouterAgent(false).supportedOpcodes(),
Matchers.not(Matchers.arrayContaining("GOTO"))
);
}
From cc7e05baaafee8c8fd2b2b8f6f1d4cdebc6e68f0 Mon Sep 17 00:00:00 2001
From: volodya-lombrozo
Date: Mon, 12 Aug 2024 11:23:24 +0300
Subject: [PATCH 03/11] feat(#376): add several useful functions
---
.../org/eolang/opeo/SelectiveDecompiler.java | 8 +++---
.../opeo/compilation/SelectiveCompiler.java | 4 +--
.../opeo/decompilation/DecompilerMachine.java | 8 +++---
.../opeo/decompilation/OperandStack.java | 8 ++++++
.../{RouterAgent.java => AllAgents.java} | 27 +++++++++----------
.../SelectiveDecompilerTest.java | 4 +--
6 files changed, 33 insertions(+), 26 deletions(-)
rename src/main/java/org/eolang/opeo/decompilation/agents/{RouterAgent.java => AllAgents.java} (90%)
diff --git a/src/main/java/org/eolang/opeo/SelectiveDecompiler.java b/src/main/java/org/eolang/opeo/SelectiveDecompiler.java
index b366304c..7f9dbebc 100644
--- a/src/main/java/org/eolang/opeo/SelectiveDecompiler.java
+++ b/src/main/java/org/eolang/opeo/SelectiveDecompiler.java
@@ -31,7 +31,7 @@
import java.util.stream.Collectors;
import org.eolang.opeo.decompilation.Decompiler;
import org.eolang.opeo.decompilation.WithoutAliases;
-import org.eolang.opeo.decompilation.agents.RouterAgent;
+import org.eolang.opeo.decompilation.agents.AllAgents;
import org.eolang.opeo.jeo.JeoDecompiler;
import org.eolang.opeo.storage.FileStorage;
import org.eolang.opeo.storage.Storage;
@@ -41,7 +41,7 @@
* Selective decompiler.
* Decompiler that decompiles ONLY fully understandable methods.
* These methods contain only instructions that are
- * supported by {@link RouterAgent}.
+ * supported by {@link AllAgents}.
*
* @since 0.1
*/
@@ -69,7 +69,7 @@ public final class SelectiveDecompiler implements Decompiler {
* @param modified Folder where to save the modified XMIRs.
*/
public SelectiveDecompiler(final Path input, final Path output, final Path modified) {
- this(input, output, modified, new RouterAgent(false).supportedOpcodes());
+ this(input, output, modified, new AllAgents(false).supportedOpcodes());
}
/**
@@ -97,7 +97,7 @@ public SelectiveDecompiler(
public SelectiveDecompiler(
final Storage storage, final Storage modified
) {
- this(storage, modified, new RouterAgent(false).supportedOpcodes());
+ this(storage, modified, new AllAgents(false).supportedOpcodes());
}
/**
diff --git a/src/main/java/org/eolang/opeo/compilation/SelectiveCompiler.java b/src/main/java/org/eolang/opeo/compilation/SelectiveCompiler.java
index 3855d156..dfed49b0 100644
--- a/src/main/java/org/eolang/opeo/compilation/SelectiveCompiler.java
+++ b/src/main/java/org/eolang/opeo/compilation/SelectiveCompiler.java
@@ -27,7 +27,7 @@
import java.nio.file.Path;
import java.util.Arrays;
import java.util.stream.Collectors;
-import org.eolang.opeo.decompilation.agents.RouterAgent;
+import org.eolang.opeo.decompilation.agents.AllAgents;
import org.eolang.opeo.storage.CompilationStorage;
import org.eolang.opeo.storage.Storage;
import org.eolang.opeo.storage.XmirEntry;
@@ -65,7 +65,7 @@ public SelectiveCompiler(final Path xmirs, final Path output) {
*/
public SelectiveCompiler(final Storage storage) {
this.storage = storage;
- this.supported = new RouterAgent(false).supportedOpcodes();
+ this.supported = new AllAgents(false).supportedOpcodes();
}
@Override
diff --git a/src/main/java/org/eolang/opeo/decompilation/DecompilerMachine.java b/src/main/java/org/eolang/opeo/decompilation/DecompilerMachine.java
index bc5cb600..18e6a905 100644
--- a/src/main/java/org/eolang/opeo/decompilation/DecompilerMachine.java
+++ b/src/main/java/org/eolang/opeo/decompilation/DecompilerMachine.java
@@ -29,7 +29,7 @@
import org.cactoos.list.ListOf;
import org.eolang.opeo.Instruction;
import org.eolang.opeo.ast.Root;
-import org.eolang.opeo.decompilation.agents.RouterAgent;
+import org.eolang.opeo.decompilation.agents.AllAgents;
import org.xembly.Directive;
/**
@@ -47,7 +47,7 @@ public final class DecompilerMachine {
/**
* Handler that redirects instructions.
*/
- private final RouterAgent router;
+ private final AllAgents agents;
/**
* Constructor.
@@ -73,7 +73,7 @@ public final class DecompilerMachine {
*/
public DecompilerMachine(final LocalVariables locals, final Map arguments) {
this.locals = locals;
- this.router = new RouterAgent(
+ this.agents = new AllAgents(
"true".equals(arguments.getOrDefault("counting", "true"))
);
}
@@ -87,7 +87,7 @@ public DecompilerMachine(final LocalVariables locals, final Map
public Iterable decompile(final Instruction... instructions) {
final DecompilerState state = new DecompilerState(this.locals);
Arrays.stream(instructions)
- .forEach(inst -> this.router.handle(state.next(inst)));
+ .forEach(inst -> this.agents.handle(state.next(inst)));
return new Root(new ListOf<>(state.stack().descendingIterator())).toXmir();
}
}
diff --git a/src/main/java/org/eolang/opeo/decompilation/OperandStack.java b/src/main/java/org/eolang/opeo/decompilation/OperandStack.java
index f5d90d72..b96d9455 100644
--- a/src/main/java/org/eolang/opeo/decompilation/OperandStack.java
+++ b/src/main/java/org/eolang/opeo/decompilation/OperandStack.java
@@ -108,6 +108,14 @@ public List pop(final int number) {
return args;
}
+ /**
+ * Peek the higher value on the stack.
+ * @return Node.
+ */
+ public AstNode peek() {
+ return this.stack.peek();
+ }
+
/**
* Push one more node to the stack.
* @param node Node to add to the stack.
diff --git a/src/main/java/org/eolang/opeo/decompilation/agents/RouterAgent.java b/src/main/java/org/eolang/opeo/decompilation/agents/AllAgents.java
similarity index 90%
rename from src/main/java/org/eolang/opeo/decompilation/agents/RouterAgent.java
rename to src/main/java/org/eolang/opeo/decompilation/agents/AllAgents.java
index c57090a1..98ca7109 100644
--- a/src/main/java/org/eolang/opeo/decompilation/agents/RouterAgent.java
+++ b/src/main/java/org/eolang/opeo/decompilation/agents/AllAgents.java
@@ -35,15 +35,14 @@
import org.objectweb.asm.Type;
/**
- * General Instruction Handler.
- * This handler redirects handling of instructions depending on an incoming instruction.
+ * All agents that try to decompile incoming instructions.
* @since 0.2
* @checkstyle ClassFanOutComplexityCheck (500 lines)
*/
-public final class RouterAgent implements DecompilationAgent {
+public final class AllAgents implements DecompilationAgent {
/**
- * Index of unimplemented handler.
+ * Index of unimplemented agent.
*/
private static final int UNIMPLEMENTED = -1;
@@ -56,7 +55,7 @@ public final class RouterAgent implements DecompilationAgent {
* Constructor.
* @param counting Do we put numbers to opcodes?
*/
- public RouterAgent(final boolean counting) {
+ public AllAgents(final boolean counting) {
this(
new MapOf(
new MapEntry<>(Opcodes.ICONST_M1, new ConstAgent(Type.INT_TYPE)),
@@ -128,22 +127,22 @@ public RouterAgent(final boolean counting) {
new MapEntry<>(Opcodes.IRETURN, new ReturnAgent()),
new MapEntry<>(Opcodes.ARETURN, new ReturnAgent()),
new MapEntry<>(LabelInstruction.LABEL_OPCODE, new LabelAgent()),
- new MapEntry<>(RouterAgent.UNIMPLEMENTED, new UnimplementedHandler(counting))
+ new MapEntry<>(AllAgents.UNIMPLEMENTED, new UnimplementedAgent(counting))
)
);
}
/**
* Constructor.
- * @param handlers All handlers that will try to handle incoming instructions.
+ * @param agents All handlers that will try to handle incoming instructions.
*/
- private RouterAgent(final Map handlers) {
- this.handlers = handlers;
+ private AllAgents(final Map agents) {
+ this.handlers = agents;
}
@Override
public void handle(final DecompilerState state) {
- this.handler(state.instruction().opcode()).handle(state);
+ this.agent(state.instruction().opcode()).handle(state);
}
/**
@@ -163,15 +162,15 @@ public String[] supportedOpcodes() {
* @param opcode Instruction opcode.
* @return Instruction handler.
*/
- private DecompilationAgent handler(final int opcode) {
- return this.handlers.getOrDefault(opcode, this.handlers.get(RouterAgent.UNIMPLEMENTED));
+ private DecompilationAgent agent(final int opcode) {
+ return this.handlers.getOrDefault(opcode, this.handlers.get(AllAgents.UNIMPLEMENTED));
}
/**
* Unimplemented instruction handler.
* @since 0.1
*/
- private static final class UnimplementedHandler implements DecompilationAgent {
+ private static final class UnimplementedAgent implements DecompilationAgent {
/**
* Do we put numbers to opcodes?
@@ -182,7 +181,7 @@ private static final class UnimplementedHandler implements DecompilationAgent {
* Constructor.
* @param counting Flag which decides if we need to count opcodes.
*/
- private UnimplementedHandler(final boolean counting) {
+ private UnimplementedAgent(final boolean counting) {
this.counting = counting;
}
diff --git a/src/test/java/org/eolang/opeo/decompilation/SelectiveDecompilerTest.java b/src/test/java/org/eolang/opeo/decompilation/SelectiveDecompilerTest.java
index 38325c88..bb9753da 100644
--- a/src/test/java/org/eolang/opeo/decompilation/SelectiveDecompilerTest.java
+++ b/src/test/java/org/eolang/opeo/decompilation/SelectiveDecompilerTest.java
@@ -26,7 +26,7 @@
import java.util.stream.Collectors;
import org.cactoos.io.ResourceOf;
import org.eolang.opeo.SelectiveDecompiler;
-import org.eolang.opeo.decompilation.agents.RouterAgent;
+import org.eolang.opeo.decompilation.agents.AllAgents;
import org.eolang.opeo.storage.InMemoryStorage;
import org.eolang.opeo.storage.XmirEntry;
import org.hamcrest.MatcherAssert;
@@ -161,7 +161,7 @@ void avoidsDecompileLargeFileWithUnknownDependencies() {
void identifiesUnsupportedOpcodes() {
MatcherAssert.assertThat(
"We expect that the supported opcodes won't contain the 'GOTO' opcode since we don't support it yet.",
- new RouterAgent(false).supportedOpcodes(),
+ new AllAgents(false).supportedOpcodes(),
Matchers.not(Matchers.arrayContaining("GOTO"))
);
}
From 71c0739e00b8a5ae64fa2bfb69cdb8f09035f76d Mon Sep 17 00:00:00 2001
From: volodya-lombrozo
Date: Mon, 12 Aug 2024 13:55:05 +0300
Subject: [PATCH 04/11] feat(#376): try to modify all agents to be independent
---
src/main/java/org/eolang/opeo/ast/Opcode.java | 39 ++++++++
.../opeo/decompilation/DecompilerMachine.java | 18 +++-
.../opeo/decompilation/DecompilerState.java | 58 ++++-------
.../opeo/decompilation/OperandStack.java | 2 +-
.../opeo/decompilation/agents/AddAgent.java | 22 ++++-
.../opeo/decompilation/agents/AllAgents.java | 98 ++++++++++---------
.../decompilation/agents/BipushAgent.java | 14 ++-
.../opeo/decompilation/agents/CastAgent.java | 83 ++++++++++++----
.../decompilation/agents/CheckCastAgent.java | 18 +++-
.../opeo/decompilation/agents/ConstAgent.java | 53 +++++-----
.../opeo/decompilation/agents/DupAgent.java | 16 ++-
.../decompilation/agents/GetFieldAgent.java | 29 +++---
.../decompilation/agents/GetStaticAgent.java | 11 ++-
.../opeo/decompilation/agents/IfAgent.java | 18 ++--
.../agents/InvokedynamicAgent.java | 27 ++---
.../agents/InvokeinterfaceAgent.java | 45 +++++----
.../agents/InvokespecialAgent.java | 51 +++++-----
.../agents/InvokestaticAgent.java | 37 +++----
.../agents/InvokevirtualAgent.java | 43 ++++----
.../opeo/decompilation/agents/LabelAgent.java | 13 ++-
.../opeo/decompilation/agents/LdcAgent.java | 7 +-
.../opeo/decompilation/agents/LoadAgent.java | 55 ++++++++---
.../opeo/decompilation/agents/MulAgent.java | 36 +++----
.../opeo/decompilation/agents/NewAgent.java | 15 ++-
.../decompilation/agents/NewArrayAgent.java | 22 ++++-
.../opeo/decompilation/agents/PopAgent.java | 7 +-
.../decompilation/agents/PutFieldAgent.java | 36 +++----
.../opeo/decompilation/agents/StoreAgent.java | 70 ++++++++-----
.../agents/StoreToArrayAgent.java | 29 ++++--
.../agents/SubstractionAgent.java | 22 ++++-
30 files changed, 627 insertions(+), 367 deletions(-)
diff --git a/src/main/java/org/eolang/opeo/ast/Opcode.java b/src/main/java/org/eolang/opeo/ast/Opcode.java
index 334fec66..6609eb6c 100644
--- a/src/main/java/org/eolang/opeo/ast/Opcode.java
+++ b/src/main/java/org/eolang/opeo/ast/Opcode.java
@@ -35,6 +35,7 @@
import org.eolang.jeo.representation.xmir.XmlInstruction;
import org.eolang.jeo.representation.xmir.XmlNode;
import org.eolang.jeo.representation.xmir.XmlOperand;
+import org.eolang.opeo.Instruction;
import org.xembly.Directive;
/**
@@ -119,6 +120,10 @@ public Opcode(final XmlInstruction instruction) {
);
}
+ public Opcode(final Instruction instruction) {
+ this(instruction.opcode(), instruction.operands());
+ }
+
/**
* Constructor.
* @param bytecode Bytecode
@@ -141,6 +146,40 @@ public List opcodes() {
return Arrays.asList(this);
}
+ /**
+ * Opcode number.
+ * @return Opcode number.
+ */
+ public int opcode() {
+ return this.bytecode;
+ }
+
+ /**
+ * Opcode operands.
+ * @return Opcode operands.
+ */
+ public List