From 3714549529bdca2350bdc94f2b1b0718d7bb7603 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 29 Sep 1998 11:28:11 +0000 Subject: [PATCH] Initial revision git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@41 379699f6-c40d-0410-875b-85095c16579e --- jode/jode/expr/ComplexExpression.java | 311 ++++++++++++++++++++++++++ 1 file changed, 311 insertions(+) create mode 100644 jode/jode/expr/ComplexExpression.java diff --git a/jode/jode/expr/ComplexExpression.java b/jode/jode/expr/ComplexExpression.java new file mode 100644 index 0000000..0de1e24 --- /dev/null +++ b/jode/jode/expr/ComplexExpression.java @@ -0,0 +1,311 @@ +/* + * Expression (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; +import sun.tools.java.Type; +import sun.tools.java.Constants; +import sun.tools.java.FieldDefinition; + +public class ComplexExpression extends Expression { + Operator operator; + Expression[] subExpressions; + + public ComplexExpression(Operator op, Expression[] sub) { + super(MyType.tUnknown); + operator = op; + subExpressions = sub; + operator.setExpression(this); + if (subExpressions.length != op.getOperandCount()) + throw new AssertError ("Operand count mismatch: "+ + subExpressions.length + " != " + + op.getOperandCount()); + if (subExpressions.length > 0) { + Type types[] = new Type[subExpressions.length]; + for (int i=0; i < types.length; i++) { + subExpressions[i].parent = this; + types[i] = subExpressions[i].getType(); + } + operator.setOperandType(types); + updateSubTypes(); + } + this.type = operator.getType(); + } + + public Expression negate() { + if (operator.operator >= operator.COMPARE_OP && + operator.operator < operator.COMPARE_OP+6) { + operator.setOperatorIndex(operator.getOperatorIndex() ^ 1); + return this; + } else if (operator.getOperatorIndex() == operator.LOG_AND_OP || + operator.getOperatorIndex() == operator.LOG_OR_OP) { + operator.setOperatorIndex(operator.getOperatorIndex() ^ 1); + for (int i=0; i< subExpressions.length; i++) { + subExpressions[i] = subExpressions[i].negate(); + } + return this; + } else if (operator.operator == operator.LOG_NOT_OP) { + return subExpressions[0]; + } + + Operator negop = + new UnaryOperator(Type.tBoolean, Operator.LOG_NOT_OP); + Expression[] e = { this }; + return new ComplexExpression(negop, e); + } + + public Expression tryToCombine(Expression e) { + if (e instanceof ComplexExpression + && e.getOperator() instanceof StoreInstruction) { + ComplexExpression ce = (ComplexExpression) e; + StoreInstruction store = (StoreInstruction) e.getOperator(); + if (store.matches(operator)) { + int i; + for (i=0; i < ce.subExpressions.length-1; i++) { + if (!ce.subExpressions[i].equals(subExpressions[i])) + break; + } + if (i == ce.subExpressions.length-1) { + operator = + new AssignOperator(store.getOperatorIndex(), store); + subExpressions = ce.subExpressions; + return this; + } + } + for (int i=0; i < subExpressions.length; i++) { + Expression combined = subExpressions[i].tryToCombine(e); + if (combined != null) { + subExpressions[i] = combined; + return this; + } + } + } + return null; + } + + public Operator getOperator() { + return operator; + } + + public Expression[] getSubExpressions() { + return subExpressions; + } + + void updateSubTypes() { + for (int i=0; i < subExpressions.length; i++) { + subExpressions[i].setType(operator.getOperandType(i)); + } + } + + public void setType(Type newType) { + newType = MyType.intersection(type, newType); + if (newType != type) { + type = newType; + operator.setType(type); + } + } + + public boolean isVoid() { + return operator.getType() == Type.tVoid; + } + + public String toString() { + String[] expr = new String[subExpressions.length]; + for (int i=0; i