1 19 20 package jode.flow; 21 import jode.GlobalOptions; 22 import jode.expr.*; 23 import jode.type.Type; 24 25 public class CreateConstantArray { 26 27 public static boolean transform(InstructionContainer ic, 28 StructuredBlock last) { 29 35 if (last.outer instanceof SequentialBlock) { 36 37 SequentialBlock sequBlock = (SequentialBlock) last.outer; 38 39 if (!(ic.getInstruction() instanceof StoreInstruction) 40 || ic.getInstruction().getFreeOperandCount() != 1 41 || !(sequBlock.subBlocks[0] instanceof SpecialBlock) 42 || !(sequBlock.outer instanceof SequentialBlock)) 43 return false; 44 45 StoreInstruction store = (StoreInstruction) ic.getInstruction(); 46 47 if (!(store.getLValue() instanceof ArrayStoreOperator)) 48 return false; 49 50 ArrayStoreOperator lvalue = (ArrayStoreOperator) store.getLValue(); 51 52 if (!(lvalue.getSubExpressions()[0] instanceof NopOperator) 53 || !(lvalue.getSubExpressions()[1] instanceof ConstOperator)) 54 return false; 55 56 Expression expr = store.getSubExpressions()[1]; 57 ConstOperator indexOp 58 = (ConstOperator) lvalue.getSubExpressions()[1]; 59 SpecialBlock dup = (SpecialBlock) sequBlock.subBlocks[0]; 60 sequBlock = (SequentialBlock) sequBlock.outer; 61 62 if (dup.type != SpecialBlock.DUP 63 || dup.depth != 0 || dup.count != 1 64 || !(indexOp.getValue() instanceof Integer ) 65 || !(sequBlock.subBlocks[0] instanceof InstructionBlock)) 66 return false; 67 68 int index = ((Integer ) indexOp.getValue()).intValue(); 69 InstructionBlock ib = (InstructionBlock)sequBlock.subBlocks[0]; 70 71 if (ib.getInstruction() instanceof NewArrayOperator) { 72 73 NewArrayOperator newArray = 74 (NewArrayOperator) ib.getInstruction(); 75 if (newArray.getDimensions() != 1 76 || !(newArray.getSubExpressions()[0] 77 instanceof ConstOperator)) 78 return false; 79 80 ConstOperator countop = 81 (ConstOperator) newArray.getSubExpressions()[0]; 82 if (!(countop.getValue() instanceof Integer )) 83 return false; 84 85 int arraylength = ((Integer ) countop.getValue()).intValue(); 86 if (arraylength <= index) 87 return false; 88 89 if (GlobalOptions.verboseLevel > 0) 90 GlobalOptions.err.print('a'); 91 92 ConstantArrayOperator cao 93 = new ConstantArrayOperator(newArray.getType(), 94 arraylength); 95 cao.setValue(index, expr); 96 ic.setInstruction(cao); 97 ic.moveDefinitions(sequBlock, last); 98 last.replace(sequBlock); 99 return true; 100 101 } else if (ib.getInstruction() instanceof ConstantArrayOperator) { 102 ConstantArrayOperator cao 103 = (ConstantArrayOperator) ib.getInstruction(); 104 if (cao.setValue(index, expr)) { 105 106 ic.setInstruction(cao); 107 ic.moveDefinitions(sequBlock, last); 108 last.replace(sequBlock); 109 return true; 110 } 111 } 112 113 } 114 return false; 115 } 116 } 117 | Popular Tags |