1 19 20 package jode.flow; 21 import jode.expr.*; 22 import jode.type.Type; 23 import jode.decompiler.LocalInfo; 24 25 public class CreateCheckNull { 26 27 38 39 48 public static boolean transformJavac(InstructionContainer ic, 49 StructuredBlock last) { 50 if (!(last.outer instanceof SequentialBlock) 51 || !(ic.getInstruction() instanceof Operator) 52 || !(last.outer.getSubBlocks()[0] instanceof SpecialBlock)) 53 return false; 54 55 SpecialBlock dup = (SpecialBlock) last.outer.getSubBlocks()[0]; 56 if (dup.type != SpecialBlock.DUP 57 || dup.count != 1 || dup.depth != 0) 58 return false; 59 60 Operator ce = (Operator) ic.getInstruction(); 61 62 if (!(ce.getOperator() instanceof PopOperator) 63 || !(ce.getSubExpressions()[0] instanceof InvokeOperator)) 64 return false; 65 66 InvokeOperator getClassCall 67 = (InvokeOperator) ce.getSubExpressions()[0]; 68 if (!getClassCall.getMethodName().equals("getClass") 69 || !(getClassCall.getMethodType().toString() 70 .equals("()Ljava/lang/Class;"))) 71 return false; 72 73 LocalInfo li = new LocalInfo(); 74 ic.setInstruction(new CheckNullOperator(Type.tUObject, li)); 75 last.replace(last.outer); 76 return true; 77 } 78 79 91 public static boolean transformJikes(IfThenElseBlock ifBlock, 92 StructuredBlock last) { 93 if (!(last.outer instanceof SequentialBlock) 94 || !(last.outer.getSubBlocks()[0] instanceof SpecialBlock) 95 || ifBlock.elseBlock != null 96 || !(ifBlock.thenBlock instanceof ThrowBlock)) 97 return false; 98 99 SpecialBlock dup = (SpecialBlock) last.outer.getSubBlocks()[0]; 100 if (dup.type != SpecialBlock.DUP 101 || dup.count != 1 || dup.depth != 0) 102 return false; 103 104 if (!(ifBlock.cond instanceof CompareUnaryOperator)) 105 return false; 106 CompareUnaryOperator cmpOp = (CompareUnaryOperator) ifBlock.cond; 107 if (cmpOp.getOperatorIndex() != Operator.EQUALS_OP 108 || !(cmpOp.getCompareType().isOfType(Type.tUObject))) 109 return false; 110 111 LocalInfo li = new LocalInfo(); 112 InstructionContainer ic = 113 new InstructionBlock(new CheckNullOperator(Type.tUObject, li)); 114 ifBlock.flowBlock.removeSuccessor(ifBlock.thenBlock.jump); 115 ic.moveJump(ifBlock.jump); 116 if (last == ifBlock) { 117 ic.replace(last.outer); 118 last = ic; 119 } else { 120 ic.replace(ifBlock); 121 last.replace(last.outer); 122 } 123 return true; 124 } 125 } 126 | Popular Tags |