Skip to content

Commit

Permalink
feat(objectionary#376): fix all qulice suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Aug 12, 2024
1 parent e1c3237 commit 7253c75
Show file tree
Hide file tree
Showing 24 changed files with 74 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public final class DecompilerState {
* Current operand stack.
* It might have some values inside.
*/
private final OperandStack stack;
private final OperandStack ostack;

/**
* Method local variables.
Expand Down Expand Up @@ -88,7 +88,7 @@ public DecompilerState(
final LocalVariables vars
) {
this.opcodes = opcodes;
this.stack = stack;
this.ostack = stack;
this.vars = vars;
}

Expand Down Expand Up @@ -142,6 +142,6 @@ public AstNode variable(final int index, final Type type) {
* @return Operand stack.
*/
public OperandStack stack() {
return this.stack;
return this.ostack;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import java.util.Set;
import org.eolang.opeo.ast.Addition;
import org.eolang.opeo.ast.AstNode;
import org.eolang.opeo.decompilation.DecompilerState;
import org.eolang.opeo.decompilation.DecompilationAgent;
import org.eolang.opeo.decompilation.DecompilerState;
import org.objectweb.asm.Opcodes;

/**
Expand All @@ -38,6 +38,9 @@
*/
public final class AddAgent implements DecompilationAgent {

/**
* Supported opcodes.
*/
private static final Set<Integer> SUPPORTED = new HashSet<>(
Arrays.asList(
Opcodes.IADD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@
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.eolang.opeo.decompilation.DecompilerState;
import org.objectweb.asm.Opcodes;

/**
* All agents that try to decompile incoming instructions.
* @since 0.2
* @checkstyle ClassFanOutComplexityCheck (500 lines)
* @todo #376:90min Decompilation Finish Condition.
* Currently we decompile until we out of instructions.
* But this might be incorrect when we start decompile high-level constructs.
Expand All @@ -48,6 +47,7 @@
* We should refactor it to a more elegant solution.
* For example, each agent might provide a list of instructions it can decompile.
* By doing this we can infer the entire list of supported and unsupported instructions.
* @checkstyle ClassFanOutComplexityCheck (500 lines)
*/
public final class AllAgents implements DecompilationAgent {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import java.util.HashSet;
import java.util.Set;
import org.eolang.opeo.ast.Literal;
import org.eolang.opeo.decompilation.DecompilerState;
import org.eolang.opeo.decompilation.DecompilationAgent;
import org.eolang.opeo.decompilation.DecompilerState;
import org.objectweb.asm.Opcodes;

/**
Expand All @@ -37,6 +37,9 @@
*/
public final class BipushAgent implements DecompilationAgent {

/**
* Supported opcodes.
*/
private static final Set<Integer> SUPPORTED = new HashSet<>(
Arrays.asList(
Opcodes.BIPUSH
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/org/eolang/opeo/decompilation/agents/ConstAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@
import java.util.Set;
import org.eolang.opeo.ast.AstNode;
import org.eolang.opeo.ast.Literal;
import org.eolang.opeo.decompilation.DecompilerState;
import org.eolang.opeo.decompilation.DecompilationAgent;
import org.eolang.opeo.decompilation.DecompilerState;
import org.objectweb.asm.Opcodes;

/**
* Iconst instruction handler.
* @since 0.1
* @checkstyle CyclomaticComplexityCheck (500 lines)
*/
public final class ConstAgent implements DecompilationAgent {

private final Set<Integer> SUPPORTED = new HashSet<>(
/**
* Supported opcodes.
*/
private static final Set<Integer> SUPPORTED = new HashSet<>(
Arrays.asList(
Opcodes.ICONST_M1,
Opcodes.ICONST_0,
Expand All @@ -60,7 +64,7 @@ public final class ConstAgent implements DecompilationAgent {
@Override
public void handle(final DecompilerState state) {
final int opcode = state.instruction().opcode();
if (this.SUPPORTED.contains(opcode)) {
if (ConstAgent.SUPPORTED.contains(opcode)) {
final AstNode res;
switch (opcode) {
case Opcodes.ICONST_M1:
Expand Down Expand Up @@ -89,10 +93,16 @@ public void handle(final DecompilerState state) {
res = ConstAgent.doubleConstant(opcode);
state.stack().push(res);
break;
default:
throw new UnsupportedOperationException(
String.format(
"Constant handler for opcode %s is not supported yet",
opcode
)
);
}
state.popInstruction();
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import java.util.HashSet;
import java.util.Set;
import org.eolang.opeo.ast.Duplicate;
import org.eolang.opeo.decompilation.DecompilerState;
import org.eolang.opeo.decompilation.DecompilationAgent;
import org.eolang.opeo.decompilation.DecompilerState;
import org.eolang.opeo.decompilation.OperandStack;
import org.objectweb.asm.Opcodes;

Expand All @@ -38,6 +38,9 @@
*/
public final class DupAgent implements DecompilationAgent {

/**
* Supported opcodes.
*/
private static final Set<Integer> SUPPORTED = new HashSet<>(
Arrays.asList(
Opcodes.DUP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

import org.eolang.opeo.ast.Attributes;
import org.eolang.opeo.ast.FieldRetrieval;
import org.eolang.opeo.decompilation.DecompilerState;
import org.eolang.opeo.decompilation.DecompilationAgent;
import org.eolang.opeo.decompilation.DecompilerState;
import org.objectweb.asm.Opcodes;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
package org.eolang.opeo.decompilation.agents;

import org.eolang.opeo.ast.ClassField;
import org.eolang.opeo.decompilation.DecompilerState;
import org.eolang.opeo.decompilation.DecompilationAgent;
import org.eolang.opeo.decompilation.DecompilerState;
import org.objectweb.asm.Opcodes;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import java.util.Set;
import org.eolang.opeo.ast.AstNode;
import org.eolang.opeo.ast.If;
import org.eolang.opeo.decompilation.DecompilerState;
import org.eolang.opeo.decompilation.DecompilationAgent;
import org.eolang.opeo.decompilation.DecompilerState;
import org.eolang.opeo.decompilation.OperandStack;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
Expand All @@ -43,6 +43,9 @@
*/
public final class IfAgent implements DecompilationAgent {

/**
* Supported opcodes.
*/
private static final Set<Integer> SUPPORTED = new HashSet<>(
Arrays.asList(
Opcodes.IF_ICMPGT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
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.DecompilationAgent;
import org.eolang.opeo.decompilation.DecompilerState;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import org.eolang.opeo.ast.NewAddress;
import org.eolang.opeo.ast.Super;
import org.eolang.opeo.ast.This;
import org.eolang.opeo.decompilation.DecompilerState;
import org.eolang.opeo.decompilation.DecompilationAgent;
import org.eolang.opeo.decompilation.DecompilerState;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import org.eolang.opeo.ast.Attributes;
import org.eolang.opeo.ast.Owner;
import org.eolang.opeo.ast.StaticInvocation;
import org.eolang.opeo.decompilation.DecompilerState;
import org.eolang.opeo.decompilation.DecompilationAgent;
import org.eolang.opeo.decompilation.DecompilerState;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import org.eolang.opeo.ast.AstNode;
import org.eolang.opeo.ast.Attributes;
import org.eolang.opeo.ast.Invocation;
import org.eolang.opeo.decompilation.DecompilerState;
import org.eolang.opeo.decompilation.DecompilationAgent;
import org.eolang.opeo.decompilation.DecompilerState;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
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.DecompilationAgent;
import org.eolang.opeo.decompilation.DecompilerState;

/**
* Label instruction handler.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
package org.eolang.opeo.decompilation.agents;

import org.eolang.opeo.ast.Constant;
import org.eolang.opeo.decompilation.DecompilerState;
import org.eolang.opeo.decompilation.DecompilationAgent;
import org.eolang.opeo.decompilation.DecompilerState;
import org.objectweb.asm.Opcodes;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.eolang.opeo.decompilation.DecompilerState;
import org.eolang.opeo.decompilation.DecompilationAgent;
import org.eolang.opeo.decompilation.DecompilerState;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
*/
public final class MulAgent implements DecompilationAgent {

/**
* Supported opcodes.
*/
private static final Set<Integer> SUPPORTED = new HashSet<>(
Arrays.asList(
Opcodes.IMUL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import java.util.HashSet;
import java.util.Set;
import org.eolang.opeo.ast.NewAddress;
import org.eolang.opeo.decompilation.DecompilerState;
import org.eolang.opeo.decompilation.DecompilationAgent;
import org.eolang.opeo.decompilation.DecompilerState;
import org.objectweb.asm.Opcodes;

/**
Expand All @@ -37,13 +37,15 @@
*/
public final class NewAgent implements DecompilationAgent {

/**
* Supported opcodes.
*/
private static final Set<Integer> SUPPORTED = new HashSet<>(
Arrays.asList(
Opcodes.NEW
)
);


@Override
public void handle(final DecompilerState state) {
if (NewAgent.SUPPORTED.contains(state.instruction().opcode())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
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.DecompilationAgent;
import org.eolang.opeo.decompilation.DecompilerState;
import org.eolang.opeo.decompilation.OperandStack;
import org.objectweb.asm.Opcodes;

Expand All @@ -40,6 +40,9 @@
*/
public final class NewArrayAgent implements DecompilationAgent {

/**
* Supported opcodes.
*/
private static final Set<Integer> SUPPORTED = new HashSet<>(
Arrays.asList(
Opcodes.ANEWARRAY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
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.DecompilationAgent;
import org.eolang.opeo.decompilation.DecompilerState;
import org.objectweb.asm.Opcodes;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import java.util.HashSet;
import java.util.Set;
import org.eolang.opeo.ast.Return;
import org.eolang.opeo.decompilation.DecompilerState;
import org.eolang.opeo.decompilation.DecompilationAgent;
import org.eolang.opeo.decompilation.DecompilerState;
import org.eolang.opeo.decompilation.OperandStack;
import org.objectweb.asm.Opcodes;

Expand All @@ -39,7 +39,10 @@
*/
public final class ReturnAgent implements DecompilationAgent {

private final Set<Integer> SUPPORTED = new HashSet<>(
/**
* Supported opcodes.
*/
private static final Set<Integer> SUPPORTED = new HashSet<>(
Arrays.asList(
Opcodes.RETURN,
Opcodes.IRETURN,
Expand All @@ -53,7 +56,7 @@ public final class ReturnAgent implements DecompilationAgent {
@Override
public void handle(final DecompilerState state) {
final int opcode = state.instruction().opcode();
if (this.SUPPORTED.contains(opcode)) {
if (ReturnAgent.SUPPORTED.contains(opcode)) {
final OperandStack stack = state.stack();
if (opcode == Opcodes.RETURN) {
stack.push(new Return());
Expand Down
Loading

0 comments on commit 7253c75

Please sign in to comment.