git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@26 379699f6-c40d-0410-875b-85095c16579estable
parent
fe217fd8ac
commit
de468af3b8
@ -0,0 +1,74 @@ |
||||
/* |
||||
* CombineIfGotoExpressions (c) 1998 Jochen Hoenicke |
||||
* |
||||
* You may distribute under the terms of the GNU General Public License. |
||||
* |
||||
* IN NO EVENT SHALL JOCHEN HOENICKE BE LIABLE TO ANY PARTY FOR DIRECT, |
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF |
||||
* THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JOCHEN HOENICKE |
||||
* HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
* JOCHEN HOENICKE SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
||||
* PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" |
||||
* BASIS, AND JOCHEN HOENICKE HAS NO OBLIGATION TO PROVIDE MAINTENANCE, |
||||
* SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
||||
* |
||||
* $Id$ |
||||
*/ |
||||
|
||||
package jode.flow; |
||||
import java.util.Vector; |
||||
import jode.Expression; |
||||
import jode.MyType; |
||||
import jode.BinaryOperator; |
||||
|
||||
public class CombineIfGotoExpressions implements Transformation{ |
||||
|
||||
public boolean transform(FlowBlock flow) { |
||||
Expression[] e; |
||||
ConditionalBlock cb; |
||||
Jump prevJump; |
||||
int operator; |
||||
try { |
||||
cb = (ConditionalBlock) flow.lastModified; |
||||
SequentialBlock sequBlock = (SequentialBlock) cb.outer; |
||||
if (sequBlock.subBlocks[1] != cb) |
||||
return false; |
||||
|
||||
// jode.Assert.assert(sequBlock.jump == null)
|
||||
|
||||
ConditionalBlock cbprev = |
||||
(ConditionalBlock) sequBlock.subBlocks[0]; |
||||
|
||||
if (cbprev.jump != null) |
||||
return false; |
||||
|
||||
prevJump = ((EmptyBlock) cbprev.trueBlock).jump; |
||||
|
||||
if (prevJump.destination == cb.jump.destination) { |
||||
e = new Expression[2]; |
||||
operator = BinaryOperator.LOG_AND_OP; |
||||
e[1] = (Expression)cb.getInstruction(); |
||||
e[0] = ((Expression)cbprev.getInstruction()).negate(); |
||||
} else if (prevJump.destination |
||||
== ((EmptyBlock) cb.trueBlock).jump.destination) { |
||||
e = new Expression[2]; |
||||
operator = BinaryOperator.LOG_OR_OP; |
||||
e[1] = (Expression)cb.getInstruction(); |
||||
e[0] = (Expression)cbprev.getInstruction(); |
||||
} else |
||||
return false; |
||||
} catch (ClassCastException ex) { |
||||
return false; |
||||
} catch (NullPointerException ex) { |
||||
return false; |
||||
} |
||||
prevJump.prev.removeJump(); |
||||
Expression cond = |
||||
new Expression(new BinaryOperator(MyType.tBoolean, operator), e); |
||||
cb.setInstruction(cond); |
||||
cb.replace(cb.outer); |
||||
return true; |
||||
} |
||||
} |
@ -0,0 +1,95 @@ |
||||
/* |
||||
* CreateNewConstructor (c) 1998 Jochen Hoenicke |
||||
* |
||||
* You may distribute under the terms of the GNU General Public License. |
||||
* |
||||
* IN NO EVENT SHALL JOCHEN HOENICKE BE LIABLE TO ANY PARTY FOR DIRECT, |
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF |
||||
* THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JOCHEN HOENICKE |
||||
* HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
* JOCHEN HOENICKE SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
||||
* PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" |
||||
* BASIS, AND JOCHEN HOENICKE HAS NO OBLIGATION TO PROVIDE MAINTENANCE, |
||||
* SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
||||
* |
||||
* $Id$ |
||||
*/ |
||||
|
||||
package jode.flow; |
||||
import jode.InvokeOperator; |
||||
import jode.Expression; |
||||
import jode.ConstructorOperator; |
||||
import jode.DupOperator; |
||||
import jode.NewOperator; |
||||
|
||||
public class CreateNewConstructor implements Transformation{ |
||||
|
||||
public boolean transform(FlowBlock flow) { |
||||
SequentialBlock sequBlock; |
||||
InvokeOperator constrCall; |
||||
Expression exprs[]; |
||||
try { |
||||
InstructionBlock block; |
||||
block = (InstructionBlock) flow.lastModified; |
||||
constrCall = (InvokeOperator) block.getInstruction(); |
||||
if (!constrCall.isConstructor()) |
||||
return false; |
||||
int params = constrCall.getOperandCount(); |
||||
exprs = new Expression[params]; |
||||
|
||||
sequBlock = (SequentialBlock) block.outer; |
||||
if (sequBlock.getSubBlocks()[1] != block) |
||||
return false; |
||||
|
||||
for (int i = params-1; i>0; i--) { |
||||
|
||||
block = (InstructionBlock) sequBlock.getSubBlocks()[0]; |
||||
if (block.jump != null) |
||||
return false; |
||||
|
||||
exprs[i] = (Expression) block.getInstruction(); |
||||
if (exprs[i].isVoid()) { |
||||
if (i == params-1) |
||||
return false; |
||||
Expression e = exprs[i+1].tryToCombine(exprs[i]); |
||||
if (e == null) |
||||
return false; |
||||
i++; |
||||
SequentialBlock subExprBlock = |
||||
(SequentialBlock) sequBlock.getSubBlocks()[1]; |
||||
subExprBlock.replace(sequBlock); |
||||
sequBlock = subExprBlock; |
||||
((InstructionContainer)subExprBlock.getSubBlocks()[0]). |
||||
setInstruction(e); |
||||
exprs[i] = e; |
||||
} |
||||
sequBlock = (SequentialBlock)sequBlock.outer; |
||||
} |
||||
block = (InstructionBlock) sequBlock.getSubBlocks()[0]; |
||||
DupOperator dup = (DupOperator) block.getInstruction(); |
||||
if (dup.getCount() != 1 && dup.getDepth() != 0) |
||||
return false; |
||||
sequBlock = (SequentialBlock)sequBlock.outer; |
||||
block = (InstructionBlock) sequBlock.getSubBlocks()[0]; |
||||
exprs[0] = (Expression) block.getInstruction(); |
||||
if (exprs[0].isVoid()) |
||||
return false; |
||||
NewOperator op = (NewOperator) exprs[0].getOperator(); |
||||
if (constrCall.getClassType() != op.getType()) |
||||
return false; |
||||
} catch (ClassCastException ex) { |
||||
return false; |
||||
} catch (NullPointerException ex) { |
||||
return false; |
||||
} |
||||
((InstructionContainer) flow.lastModified).setInstruction |
||||
(new Expression(new ConstructorOperator(constrCall.getClassType(), |
||||
constrCall.getField()), |
||||
exprs)); |
||||
|
||||
flow.lastModified.replace(sequBlock); |
||||
return true; |
||||
} |
||||
} |
@ -0,0 +1,30 @@ |
||||
/* |
||||
* SimplifyExpression (c) 1998 Jochen Hoenicke |
||||
* |
||||
* You may distribute under the terms of the GNU General Public License. |
||||
* |
||||
* IN NO EVENT SHALL JOCHEN HOENICKE BE LIABLE TO ANY PARTY FOR DIRECT, |
||||
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF |
||||
* THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JOCHEN HOENICKE |
||||
* HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
* JOCHEN HOENICKE SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
||||
* PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" |
||||
* BASIS, AND JOCHEN HOENICKE HAS NO OBLIGATION TO PROVIDE MAINTENANCE, |
||||
* SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
||||
* |
||||
* $Id$ |
||||
*/ |
||||
|
||||
package jode.flow; |
||||
|
||||
public class SimplifyExpression implements Transformation { |
||||
public boolean transform(FlowBlock flow) { |
||||
if (flow.lastModified instanceof InstructionContainer) { |
||||
InstructionContainer ic = (InstructionContainer) flow.lastModified; |
||||
ic.setInstruction(ic.getInstruction().simplify()); |
||||
} |
||||
return false; |
||||
} |
||||
} |
Loading…
Reference in new issue