001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package EDU.purdue.cs.bloat.tree;
022:
023: import EDU.purdue.cs.bloat.cfg.*;
024:
025: /**
026: * IfStmt is a super class of statements in which some expression is evaluated
027: * and one of two branches is taken.
028: *
029: * @see IfCmpStmt
030: * @see IfZeroStmt
031: */
032: public abstract class IfStmt extends JumpStmt {
033: int comparison; // Type of comparison that is performed
034:
035: Block trueTarget; // Code to jump to if IfStmt is true
036:
037: Block falseTarget; // Code to jump to if IfStmt is false
038:
039: // Compairson operators...
040: public static final int EQ = 0;
041:
042: public static final int NE = 1;
043:
044: public static final int GT = 2;
045:
046: public static final int GE = 3;
047:
048: public static final int LT = 4;
049:
050: public static final int LE = 5;
051:
052: /**
053: * Constructor.
054: *
055: * @param comparison
056: * Comparison operator used in this if statement.
057: * @param trueTarget
058: * Basic Block that is executed when if statement is true.
059: * @param falseTarget
060: * Basic Block that is executed when if statement is false.
061: */
062: public IfStmt(final int comparison, final Block trueTarget,
063: final Block falseTarget) {
064: this .comparison = comparison;
065: this .trueTarget = trueTarget;
066: this .falseTarget = falseTarget;
067: }
068:
069: /**
070: * @return Comparison operator for this if statement.
071: */
072: public int comparison() {
073: return comparison;
074: }
075:
076: /**
077: * Set the comparison operator for this if statement to its logical
078: * negative.
079: */
080: public void negate() {
081: switch (comparison) {
082: case EQ:
083: comparison = IfStmt.NE;
084: break;
085: case NE:
086: comparison = IfStmt.EQ;
087: break;
088: case LT:
089: comparison = IfStmt.GE;
090: break;
091: case GE:
092: comparison = IfStmt.LT;
093: break;
094: case GT:
095: comparison = IfStmt.LE;
096: break;
097: case LE:
098: comparison = IfStmt.GT;
099: break;
100: }
101:
102: final Block t = trueTarget;
103: trueTarget = falseTarget;
104: falseTarget = t;
105: }
106:
107: public void setTrueTarget(final Block target) {
108: this .trueTarget = target;
109: }
110:
111: public void setFalseTarget(final Block target) {
112: this .falseTarget = target;
113: }
114:
115: public Block trueTarget() {
116: return trueTarget;
117: }
118:
119: public Block falseTarget() {
120: return falseTarget;
121: }
122: }
|