01: /* CompareBinaryOperator Copyright (C) 1998-2002 Jochen Hoenicke.
02: *
03: * This program is free software; you can redistribute it and/or modify
04: * it under the terms of the GNU Lesser General Public License as published by
05: * the Free Software Foundation; either version 2, or (at your option)
06: * any later version.
07: *
08: * This program is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11: * GNU General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public License
14: * along with this program; see the file COPYING.LESSER. If not, write to
15: * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
16: *
17: * $Id: CompareBinaryOperator.java,v 4.11.2.1 2002/05/28 17:34:06 hoenicke Exp $
18: */
19:
20: package jode.expr;
21:
22: import jode.type.Type;
23: import jode.decompiler.TabbedPrintWriter;
24:
25: public class CompareBinaryOperator extends Operator {
26: boolean allowsNaN = false;
27: Type compareType;
28:
29: public CompareBinaryOperator(Type type, int op) {
30: super (Type.tBoolean, op);
31: compareType = type;
32: initOperands(2);
33: }
34:
35: public CompareBinaryOperator(Type type, int op, boolean allowsNaN) {
36: super (Type.tBoolean, op);
37: compareType = type;
38: this .allowsNaN = allowsNaN;
39: initOperands(2);
40: }
41:
42: public int getPriority() {
43: switch (getOperatorIndex()) {
44: case 26:
45: case 27:
46: return 500;
47: case 28:
48: case 29:
49: case 30:
50: case 31:
51: return 550;
52: }
53: throw new RuntimeException("Illegal operator");
54: }
55:
56: public Type getCompareType() {
57: return compareType;
58: }
59:
60: public void updateSubTypes() {
61: subExpressions[0].setType(Type.tSubType(compareType));
62: subExpressions[1].setType(Type.tSubType(compareType));
63: }
64:
65: public void updateType() {
66: Type leftType = Type.tSuperType(subExpressions[0].getType());
67: Type rightType = Type.tSuperType(subExpressions[1].getType());
68: compareType = compareType.intersection(leftType).intersection(
69: rightType);
70: subExpressions[0].setType(Type.tSubType(rightType));
71: subExpressions[1].setType(Type.tSubType(leftType));
72: /* propagate hints? XXX */
73: }
74:
75: public Expression negate() {
76: if (!allowsNaN || getOperatorIndex() <= NOTEQUALS_OP) {
77: setOperatorIndex(getOperatorIndex() ^ 1);
78: return this ;
79: }
80: return super .negate();
81: }
82:
83: public boolean opEquals(Operator o) {
84: return (o instanceof CompareBinaryOperator)
85: && o.operatorIndex == operatorIndex;
86: }
87:
88: public void dumpExpression(TabbedPrintWriter writer)
89: throws java.io.IOException {
90: subExpressions[0].dumpExpression(writer, getPriority() + 1);
91: writer.breakOp();
92: writer.print(getOperatorString());
93: subExpressions[1].dumpExpression(writer, getPriority() + 1);
94: }
95: }
|