1 19 20 package jode.flow; 21 import jode.expr.*; 22 import jode.type.Type; 23 import jode.decompiler.LocalInfo; 24 25 public class CreateClassField { 26 27 28 public static boolean transform(IfThenElseBlock ifBlock, 29 StructuredBlock last) { 30 if (!(ifBlock.cond instanceof CompareUnaryOperator) 37 || !(((Operator)ifBlock.cond) 38 .getOperatorIndex() == Operator.EQUALS_OP) 39 || !(ifBlock.thenBlock instanceof InstructionBlock) 40 || ifBlock.elseBlock != null) 41 return false; 42 43 if (ifBlock.thenBlock.jump != null 44 && (ifBlock.jump == null 45 || (ifBlock.jump.destination 46 != ifBlock.thenBlock.jump.destination))) 47 return false; 48 49 CompareUnaryOperator cmp = (CompareUnaryOperator) ifBlock.cond; 50 Expression instr = 51 ((InstructionBlock)ifBlock.thenBlock).getInstruction(); 52 if (!(cmp.getSubExpressions()[0] instanceof GetFieldOperator) 53 || !(instr instanceof StoreInstruction)) 54 return false; 55 56 StoreInstruction store = (StoreInstruction) instr; 57 if (!(store.getLValue() instanceof PutFieldOperator)) 58 return false; 59 PutFieldOperator put = (PutFieldOperator) store.getLValue(); 60 if (put.getField() == null 61 || !put.matches((GetFieldOperator)cmp.getSubExpressions()[0]) 62 || !(store.getSubExpressions()[1] instanceof InvokeOperator)) 63 return false; 64 65 InvokeOperator invoke = (InvokeOperator) store.getSubExpressions()[1]; 66 if (!invoke.isGetClass()) 67 return false; 68 69 Expression param = invoke.getSubExpressions()[0]; 70 71 if (param instanceof ConstOperator 72 && ((ConstOperator)param).getValue() instanceof String ) { 73 String clazz = (String ) ((ConstOperator)param).getValue(); 74 if (put.getField().setClassConstant(clazz)) { 75 cmp.setSubExpressions 76 (0, new ClassFieldOperator(clazz.charAt(0) == '[' 77 ? Type.tType(clazz) 78 : Type.tClass(clazz))); 79 EmptyBlock empty = new EmptyBlock(); 80 empty.moveJump(ifBlock.thenBlock.jump); 81 ifBlock.setThenBlock(empty); 82 return true; 83 } 84 } 85 return false; 86 } 87 } 88 | Popular Tags |