Expression rework (ComplexExpression removed)

FieldAnalyzer.setClassConstant used


git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@770 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent b5e13adfe1
commit afd13f2bf5
  1. 38
      jode/jode/flow/CreateClassField.java

@ -33,10 +33,9 @@ public class CreateClassField {
// to // to
// if (classname.class == null) { // if (classname.class == null) {
// } // }
if (!(ifBlock.cond instanceof ComplexExpression) if (!(ifBlock.cond instanceof CompareUnaryOperator)
|| !(ifBlock.cond.getOperator() instanceof CompareUnaryOperator) || !(((Operator)ifBlock.cond)
|| !(ifBlock.cond.getOperator().getOperatorIndex() .getOperatorIndex() == Operator.EQUALS_OP)
== Operator.EQUALS_OP)
|| !(ifBlock.thenBlock instanceof InstructionBlock) || !(ifBlock.thenBlock instanceof InstructionBlock)
|| ifBlock.elseBlock != null) || ifBlock.elseBlock != null)
return false; return false;
@ -47,39 +46,32 @@ public class CreateClassField {
!= ifBlock.thenBlock.jump.destination))) != ifBlock.thenBlock.jump.destination)))
return false; return false;
ComplexExpression cmp = (ComplexExpression) ifBlock.cond; CompareUnaryOperator cmp = (CompareUnaryOperator) ifBlock.cond;
Expression instr = Expression instr =
((InstructionBlock)ifBlock.thenBlock).getInstruction(); ((InstructionBlock)ifBlock.thenBlock).getInstruction();
if (!(cmp.getSubExpressions()[0] instanceof GetFieldOperator) if (!(cmp.getSubExpressions()[0] instanceof GetFieldOperator)
|| !(instr instanceof ComplexExpression) || !(instr instanceof StoreInstruction))
|| !(instr.getOperator() instanceof PutFieldOperator))
return false; return false;
ComplexExpression ass = (ComplexExpression) instr; StoreInstruction store = (StoreInstruction) instr;
PutFieldOperator put = (PutFieldOperator) ass.getOperator(); if (!(store.getLValue() instanceof PutFieldOperator))
if (!put.getField().isSynthetic() return false;
PutFieldOperator put = (PutFieldOperator) store.getLValue();
if (put.getField() == null
|| !put.matches((GetFieldOperator)cmp.getSubExpressions()[0]) || !put.matches((GetFieldOperator)cmp.getSubExpressions()[0])
|| !(ass.getSubExpressions()[0] instanceof ComplexExpression) || !(store.getSubExpressions()[1] instanceof InvokeOperator))
|| !(ass.getSubExpressions()[0].getOperator()
instanceof InvokeOperator))
return false; return false;
InvokeOperator invoke = (InvokeOperator) InvokeOperator invoke = (InvokeOperator) store.getSubExpressions()[1];
ass.getSubExpressions()[0].getOperator(); Expression param = invoke.getSubExpressions()[0];
Expression param =
((ComplexExpression)ass.getSubExpressions()[0])
.getSubExpressions()[0];
if (invoke.isGetClass() if (invoke.isGetClass()
&& param instanceof ConstOperator && param instanceof ConstOperator
&& param.getType().equals(Type.tString)) { && param.getType().equals(Type.tString)) {
String clazz = ((ConstOperator)param).getValue(); String clazz = ((ConstOperator)param).getValue();
if (put.getFieldName() if (put.getField().setClassConstant(clazz)) {
.equals("class$" + clazz.replace('.', '$'))
|| put.getFieldName()
.equals("class$L" + clazz.replace('.', '$'))) {
cmp.setSubExpressions cmp.setSubExpressions
(0, new ClassFieldOperator(Type.tClass(clazz))); (0, new ClassFieldOperator(Type.tClass(clazz)));
put.getField().analyzedSynthetic();
EmptyBlock empty = new EmptyBlock(); EmptyBlock empty = new EmptyBlock();
empty.moveJump(ifBlock.thenBlock.jump); empty.moveJump(ifBlock.thenBlock.jump);
ifBlock.setThenBlock(empty); ifBlock.setThenBlock(empty);

Loading…
Cancel
Save