001    /* This file was generated with JastAdd2 (http://jastadd.org) version R20130213 */
002    package AST;
003    
004    import java.util.HashSet;
005    import java.io.File;
006    import java.util.*;
007    import beaver.*;
008    import java.util.ArrayList;
009    import java.util.zip.*;
010    import java.io.*;
011    import java.io.FileNotFoundException;
012    import java.util.Collection;
013    /**
014     * @production RelationalExpr : {@link Binary};
015     * @ast node
016     * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/java.ast:175
017     */
018    public abstract class RelationalExpr extends Binary implements Cloneable {
019      /**
020       * @apilevel low-level
021       */
022      public void flushCache() {
023      }
024      /**
025       * @apilevel internal
026       */
027      public void flushCollectionCache() {
028      }
029      /**
030       * @apilevel internal
031       */
032      @SuppressWarnings({"unchecked", "cast"})
033      public RelationalExpr clone() throws CloneNotSupportedException {
034        RelationalExpr node = (RelationalExpr)super.clone();
035        node.type_computed = false;
036        node.type_value = null;
037        node.in$Circle(false);
038        node.is$Final(false);
039        return node;
040      }
041      /**
042       * @ast method 
043       * @aspect TypeCheck
044       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/TypeCheck.jrag:204
045       */
046      public void typeCheck() {
047        if(!getLeftOperand().type().isNumericType())
048          error(getLeftOperand().type().typeName() + " is not numeric");
049        if(!getRightOperand().type().isNumericType())
050          error(getRightOperand().type().typeName() + " is not numeric");
051      }
052      /**
053       * @ast method 
054       * @aspect CreateBCode
055       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:1027
056       */
057      public void createBCode(CodeGeneration gen) { emitBooleanCondition(gen); }
058      /**
059       * @ast method 
060       * @aspect CreateBCode
061       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:1123
062       */
063      public void emitEvalBranch(CodeGeneration gen) {
064        if(isTrue())
065          gen.emitGoto(true_label());
066        else if(isFalse())
067          gen.emitGoto(false_label());
068        else {
069          TypeDecl type = getLeftOperand().type();
070          if(type.isNumericType()) {
071            type = binaryNumericPromotedType();
072            getLeftOperand().createBCode(gen);
073            getLeftOperand().type().emitCastTo(gen, type); // Binary numeric promotion
074            getRightOperand().createBCode(gen);
075            getRightOperand().type().emitCastTo(gen, type); // Binary numeric promotion
076          }
077          else {
078            getLeftOperand().createBCode(gen);
079            getRightOperand().createBCode(gen);
080          }
081          compareBranch(gen, true_label(), type);
082          gen.emitGoto(false_label());
083          // compareNotBranch does not work for float comparison with NaN
084          //compareNotBranch(gen, false_label(), type);
085          //gen.emitGoto(true_label());
086        }
087      }
088      /**
089       * @ast method 
090       * @aspect CreateBCode
091       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:1149
092       */
093      public void compareBranch(CodeGeneration gen, int label, TypeDecl typeDecl) {
094        throw new Error("compareBranch not supported for " + getClass().getName());
095      }
096      /**
097       * @ast method 
098       * @aspect CreateBCode
099       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:1159
100       */
101      public void compareNotBranch(CodeGeneration gen, int label, TypeDecl typeDecl) {
102        throw new Error("compareBranch not supported for " + getClass().getName());
103      }
104      /**
105       * @ast method 
106       * 
107       */
108      public RelationalExpr() {
109        super();
110    
111    
112      }
113      /**
114       * Initializes the child array to the correct size.
115       * Initializes List and Opt nta children.
116       * @apilevel internal
117       * @ast method
118       * @ast method 
119       * 
120       */
121      public void init$Children() {
122        children = new ASTNode[2];
123      }
124      /**
125       * @ast method 
126       * 
127       */
128      public RelationalExpr(Expr p0, Expr p1) {
129        setChild(p0, 0);
130        setChild(p1, 1);
131      }
132      /**
133       * @apilevel low-level
134       * @ast method 
135       * 
136       */
137      protected int numChildren() {
138        return 2;
139      }
140      /**
141       * @apilevel internal
142       * @ast method 
143       * 
144       */
145      public boolean mayHaveRewrite() {
146        return false;
147      }
148      /**
149       * Replaces the LeftOperand child.
150       * @param node The new node to replace the LeftOperand child.
151       * @apilevel high-level
152       * @ast method 
153       * 
154       */
155      public void setLeftOperand(Expr node) {
156        setChild(node, 0);
157      }
158      /**
159       * Retrieves the LeftOperand child.
160       * @return The current node used as the LeftOperand child.
161       * @apilevel high-level
162       * @ast method 
163       * 
164       */
165      public Expr getLeftOperand() {
166        return (Expr)getChild(0);
167      }
168      /**
169       * Retrieves the LeftOperand child.
170       * <p><em>This method does not invoke AST transformations.</em></p>
171       * @return The current node used as the LeftOperand child.
172       * @apilevel low-level
173       * @ast method 
174       * 
175       */
176      public Expr getLeftOperandNoTransform() {
177        return (Expr)getChildNoTransform(0);
178      }
179      /**
180       * Replaces the RightOperand child.
181       * @param node The new node to replace the RightOperand child.
182       * @apilevel high-level
183       * @ast method 
184       * 
185       */
186      public void setRightOperand(Expr node) {
187        setChild(node, 1);
188      }
189      /**
190       * Retrieves the RightOperand child.
191       * @return The current node used as the RightOperand child.
192       * @apilevel high-level
193       * @ast method 
194       * 
195       */
196      public Expr getRightOperand() {
197        return (Expr)getChild(1);
198      }
199      /**
200       * Retrieves the RightOperand child.
201       * <p><em>This method does not invoke AST transformations.</em></p>
202       * @return The current node used as the RightOperand child.
203       * @apilevel low-level
204       * @ast method 
205       * 
206       */
207      public Expr getRightOperandNoTransform() {
208        return (Expr)getChildNoTransform(1);
209      }
210      /**
211       * @apilevel internal
212       */
213      protected boolean type_computed = false;
214      /**
215       * @apilevel internal
216       */
217      protected TypeDecl type_value;
218      /**
219       * @attribute syn
220       * @aspect TypeAnalysis
221       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/TypeAnalysis.jrag:344
222       */
223      @SuppressWarnings({"unchecked", "cast"})
224      public TypeDecl type() {
225        if(type_computed) {
226          return type_value;
227        }
228          ASTNode$State state = state();
229      int num = state.boundariesCrossed;
230      boolean isFinal = this.is$Final();
231        type_value = type_compute();
232      if(isFinal && num == state().boundariesCrossed){ type_computed = true; }
233            return type_value;
234      }
235      /**
236       * @apilevel internal
237       */
238      private TypeDecl type_compute() {  return typeBoolean();  }
239      /**
240       * @attribute syn
241       * @aspect CreateBCode
242       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:946
243       */
244      public boolean definesLabel() {
245        ASTNode$State state = state();
246        try {  return false;  }
247        finally {
248        }
249      }
250      /**
251       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:994
252       * @apilevel internal
253       */
254      public int Define_int_condition_false_label(ASTNode caller, ASTNode child) {
255        if(caller == getRightOperandNoTransform()) {
256          return false_label();
257        }
258        else if(caller == getLeftOperandNoTransform()) {
259          return false_label();
260        }
261        else {      return getParent().Define_int_condition_false_label(this, caller);
262        }
263      }
264      /**
265       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:995
266       * @apilevel internal
267       */
268      public int Define_int_condition_true_label(ASTNode caller, ASTNode child) {
269        if(caller == getRightOperandNoTransform()) {
270          return true_label();
271        }
272        else if(caller == getLeftOperandNoTransform()) {
273          return true_label();
274        }
275        else {      return getParent().Define_int_condition_true_label(this, caller);
276        }
277      }
278      /**
279       * @apilevel internal
280       */
281      public ASTNode rewriteTo() {
282        return super.rewriteTo();
283      }
284    }