Skip to content

Commit

Permalink
feat: Support pattern matching for instanceof.
Browse files Browse the repository at this point in the history
  • Loading branch information
teletha committed Feb 28, 2023
1 parent a2d81cd commit 10f7218
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
16 changes: 9 additions & 7 deletions src/main/java/reincarnation/JavaMethodDecompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
package reincarnation;

import static org.objectweb.asm.Opcodes.*;
import static reincarnation.Node.Termination;
import static reincarnation.Node.*;
import static reincarnation.OperandCondition.*;
import static reincarnation.OperandUtil.load;
import static reincarnation.OperandUtil.*;

import java.lang.reflect.Executable;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -1341,9 +1341,8 @@ public void visitJumpInsn(int opcode, Label label) {
case IF_ACMPNE:
// instanceof with cast produces special bytecode, so we must handle it by special way.
if (match(ALOAD, CHECKCAST, DUP, ASTORE, ALOAD, LABEL, CHECKCAST, IF_ACMPNE)) {
debugger.print(nodes);
OperandLocalVariable target = current.remove(0).as(OperandLocalVariable.class).exact();
Operand assign = current.remove(0);
current.remove(0);
current.remove(0);
OperandLocalVariable casted = current.remove(0).as(OperandLocalVariable.class).exact();
current.peek(0).children(OperandInstanceOf.class).to(o -> {
casted.type.set(o.type);
Expand Down Expand Up @@ -1569,6 +1568,8 @@ public void visitTypeInsn(int opcode, String type) {
// recode current instruction
record(opcode);

Class clazz = load(type);

switch (opcode) {
case NEW:
if (assertNew) {
Expand All @@ -1593,11 +1594,12 @@ public void visitTypeInsn(int opcode, String type) {
break;

case CHECKCAST:

current.peek(0).fix(clazz);
current.addOperand(new OperandCast(current.remove(0), clazz));
break;

case INSTANCEOF:
current.addOperand(new OperandInstanceOf(current.remove(0), load(type)));
current.addOperand(new OperandInstanceOf(current.remove(0), clazz));
break;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/reincarnation/Operand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@

public abstract class Operand implements Code<Operand> {

/** The reusable operand for null literal. */
public static final Operand Null = new OperandExpression(null).fix(Object.class);

/** The infered type. */
protected Variable<Class> type = Variable.of(Object.class);

/** The flag for operand duplication. */
boolean duplicated = false;
protected boolean duplicated = false;

/** The comment. */
private String comment;
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/reincarnation/OperandCast.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

import reincarnation.coder.Coder;

/**
* @version 2018/10/14 9:56:07
*/
class OperandCast extends Operand {

/** The actual value. */
Expand Down

0 comments on commit 10f7218

Please sign in to comment.