Skip to content

Commit

Permalink
feat(objectionary#376) handlers -> agents
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Aug 12, 2024
1 parent 43a4b88 commit 3d85e72
Show file tree
Hide file tree
Showing 35 changed files with 310 additions and 309 deletions.
8 changes: 4 additions & 4 deletions src/main/java/org/eolang/opeo/SelectiveDecompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
*/
Expand Down Expand Up @@ -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());
}

/**
Expand Down Expand Up @@ -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());
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/eolang/opeo/ast/Labeled.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -47,7 +47,7 @@ public final class DecompilerMachine {
/**
* Handler that redirects instructions.
*/
private final RouterHandler router;
private final RouterAgent router;

/**
* Constructor.
Expand All @@ -73,7 +73,7 @@ public final class DecompilerMachine {
*/
public DecompilerMachine(final LocalVariables locals, final Map<String, String> arguments) {
this.locals = locals;
this.router = new RouterHandler(
this.router = new RouterAgent(
"true".equals(arguments.getOrDefault("counting", "true"))
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.CheckCast;
import org.eolang.opeo.decompilation.DecompilerState;
import org.eolang.opeo.decompilation.InstructionHandler;
import org.eolang.opeo.decompilation.DecompilationAgent;
import org.objectweb.asm.Type;

/**
* CheckCast instruction handler.
*
* @since 0.5
*/
public final class CheckCastHandler implements InstructionHandler {
public final class CheckCastAgent implements DecompilationAgent {

@Override
public void handle(final DecompilerState state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.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;

/**
* Iconst instruction handler.
* @since 0.1
*/
public final class ConstHandler implements InstructionHandler {
public final class ConstAgent implements DecompilationAgent {

/**
* Type of constant.
Expand All @@ -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;
}

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@
* 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;

/**
* 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) {
Expand Down
Loading

0 comments on commit 3d85e72

Please sign in to comment.