001    /* This file was generated with JastAdd2 (http://jastadd.org) version 2.1.13-12-g880e696 */
002    package org.extendj.ast;
003    
004    import java.util.HashSet;
005    import java.io.File;
006    import java.util.Set;
007    import java.util.Collections;
008    import java.util.Collection;
009    import java.util.ArrayList;
010    import beaver.*;
011    import java.util.*;
012    import java.io.ByteArrayOutputStream;
013    import java.io.PrintStream;
014    import java.lang.reflect.InvocationTargetException;
015    import java.lang.reflect.Method;
016    import org.jastadd.util.*;
017    import java.util.zip.*;
018    import java.io.*;
019    import org.jastadd.util.PrettyPrintable;
020    import org.jastadd.util.PrettyPrinter;
021    import java.io.FileNotFoundException;
022    import java.io.BufferedInputStream;
023    import java.io.DataInputStream;
024    /**
025     * @ast node
026     * @declaredat /home/jesper/git/extendj/java4/grammar/Java.ast:178
027     * @production EqualityExpr : {@link RelationalExpr};
028    
029     */
030    public abstract class EqualityExpr extends RelationalExpr implements Cloneable {
031      /**
032       * @aspect TypeCheck
033       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeCheck.jrag:260
034       */
035      public void typeCheck() {
036        TypeDecl left = getLeftOperand().type();
037        TypeDecl right = getRightOperand().type();
038        if (left.isNumericType() && right.isNumericType()) {
039          return;
040        } else if (left.isBoolean() && right.isBoolean()) {
041          return;
042        } else if ((left.isReferenceType() || left.isNull()) && (right.isReferenceType() || right.isNull())) {
043          if (left.castingConversionTo(right) || right.castingConversionTo(left)) {
044            return;
045          }
046        }
047        errorf("%s can not be compared to %s", left.typeName(), right.typeName());
048      }
049      /**
050       * @aspect AutoBoxingCodegen
051       * @declaredat /home/jesper/git/extendj/java5/backend/AutoBoxingCodegen.jrag:382
052       */
053      public void branchTrue(CodeGeneration gen, int target) {
054        // branch when true
055        if (isConstant()) {
056          if (isTrue()) {
057            gen.emitGoto(target);
058            //gen.GOTO(target);
059            return;
060          }
061        } else {
062          TypeDecl type = getLeftOperand().type();
063          if (type.isNumericType() && !(type.isReferenceType() && getRightOperand().type().isReferenceType())) {
064            type = binaryNumericPromotedType();
065            getLeftOperand().createBCode(gen);
066            getLeftOperand().type().emitCastTo(gen, type); // Binary numeric promotion
067            getRightOperand().createBCode(gen);
068            getRightOperand().type().emitCastTo(gen, type); // Binary numeric promotion
069          } else if (type.isBoolean() && type != getRightOperand().type()) {
070            type = binaryNumericPromotedType();
071            getLeftOperand().createBCode(gen);
072            getLeftOperand().type().emitCastTo(gen, type); // Binary numeric promotion
073            getRightOperand().createBCode(gen);
074            getRightOperand().type().emitCastTo(gen, type); // Binary numeric promotion
075          } else {
076            getLeftOperand().createBCode(gen);
077            getRightOperand().createBCode(gen);
078          }
079          compareBranch(gen, target, type);
080        }
081      }
082      /**
083       * @aspect AutoBoxingCodegen
084       * @declaredat /home/jesper/git/extendj/java5/backend/AutoBoxingCodegen.jrag:412
085       */
086      public void branchFalse(CodeGeneration gen, int target) {
087        // branch when false
088        if (isConstant()) {
089          if (isFalse()) {
090            gen.emitGoto(target);
091            //gen.GOTO(target);
092            return;
093          }
094        } else {
095          TypeDecl type = getLeftOperand().type();
096          if (type.isNumericType() && !(type.isReferenceType() && getRightOperand().type().isReferenceType())) {
097            type = binaryNumericPromotedType();
098            getLeftOperand().createBCode(gen);
099            getLeftOperand().type().emitCastTo(gen, type); // Binary numeric promotion
100            getRightOperand().createBCode(gen);
101            getRightOperand().type().emitCastTo(gen, type); // Binary numeric promotion
102          } else if (type.isBoolean() && type != getRightOperand().type()) {
103            type = binaryNumericPromotedType();
104            getLeftOperand().createBCode(gen);
105            getLeftOperand().type().emitCastTo(gen, type); // Binary numeric promotion
106            getRightOperand().createBCode(gen);
107            getRightOperand().type().emitCastTo(gen, type); // Binary numeric promotion
108          } else {
109            getLeftOperand().createBCode(gen);
110            getRightOperand().createBCode(gen);
111          }
112          compareNotBranch(gen, target, type);
113        }
114      }
115      /**
116       * @declaredat ASTNode:1
117       */
118      public EqualityExpr() {
119        super();
120      }
121      /**
122       * Initializes the child array to the correct size.
123       * Initializes List and Opt nta children.
124       * @apilevel internal
125       * @ast method
126       * @declaredat ASTNode:10
127       */
128      public void init$Children() {
129        children = new ASTNode[2];
130      }
131      /**
132       * @declaredat ASTNode:13
133       */
134      public EqualityExpr(Expr p0, Expr p1) {
135        setChild(p0, 0);
136        setChild(p1, 1);
137      }
138      /**
139       * @apilevel low-level
140       * @declaredat ASTNode:20
141       */
142      protected int numChildren() {
143        return 2;
144      }
145      /**
146       * @apilevel internal
147       * @declaredat ASTNode:26
148       */
149      public boolean mayHaveRewrite() {
150        return false;
151      }
152      /**
153       * @apilevel internal
154       * @declaredat ASTNode:32
155       */
156      public void flushAttrCache() {
157        super.flushAttrCache();
158      }
159      /**
160       * @apilevel internal
161       * @declaredat ASTNode:38
162       */
163      public void flushCollectionCache() {
164        super.flushCollectionCache();
165      }
166      /**
167       * @apilevel internal
168       * @declaredat ASTNode:44
169       */
170      public void flushRewriteCache() {
171        super.flushRewriteCache();
172      }
173      /**
174       * @apilevel internal
175       * @declaredat ASTNode:50
176       */
177      public EqualityExpr clone() throws CloneNotSupportedException {
178        EqualityExpr node = (EqualityExpr) super.clone();
179        return node;
180      }
181      /**
182       * Create a deep copy of the AST subtree at this node.
183       * The copy is dangling, i.e. has no parent.
184       * @return dangling copy of the subtree at this node
185       * @apilevel low-level
186       * @deprecated Please use treeCopy or treeCopyNoTransform instead
187       * @declaredat ASTNode:61
188       */
189      @Deprecated
190      public abstract EqualityExpr fullCopy();
191      /**
192       * Create a deep copy of the AST subtree at this node.
193       * The copy is dangling, i.e. has no parent.
194       * @return dangling copy of the subtree at this node
195       * @apilevel low-level
196       * @declaredat ASTNode:69
197       */
198      public abstract EqualityExpr treeCopyNoTransform();
199      /**
200       * Create a deep copy of the AST subtree at this node.
201       * The subtree of this node is traversed to trigger rewrites before copy.
202       * The copy is dangling, i.e. has no parent.
203       * @return dangling copy of the subtree at this node
204       * @apilevel low-level
205       * @declaredat ASTNode:77
206       */
207      public abstract EqualityExpr treeCopy();
208      /**
209       * Replaces the LeftOperand child.
210       * @param node The new node to replace the LeftOperand child.
211       * @apilevel high-level
212       */
213      public void setLeftOperand(Expr node) {
214        setChild(node, 0);
215      }
216      /**
217       * Retrieves the LeftOperand child.
218       * @return The current node used as the LeftOperand child.
219       * @apilevel high-level
220       */
221      @ASTNodeAnnotation.Child(name="LeftOperand")
222      public Expr getLeftOperand() {
223        return (Expr) getChild(0);
224      }
225      /**
226       * Retrieves the LeftOperand child.
227       * <p><em>This method does not invoke AST transformations.</em></p>
228       * @return The current node used as the LeftOperand child.
229       * @apilevel low-level
230       */
231      public Expr getLeftOperandNoTransform() {
232        return (Expr) getChildNoTransform(0);
233      }
234      /**
235       * Replaces the RightOperand child.
236       * @param node The new node to replace the RightOperand child.
237       * @apilevel high-level
238       */
239      public void setRightOperand(Expr node) {
240        setChild(node, 1);
241      }
242      /**
243       * Retrieves the RightOperand child.
244       * @return The current node used as the RightOperand child.
245       * @apilevel high-level
246       */
247      @ASTNodeAnnotation.Child(name="RightOperand")
248      public Expr getRightOperand() {
249        return (Expr) getChild(1);
250      }
251      /**
252       * Retrieves the RightOperand child.
253       * <p><em>This method does not invoke AST transformations.</em></p>
254       * @return The current node used as the RightOperand child.
255       * @apilevel low-level
256       */
257      public Expr getRightOperandNoTransform() {
258        return (Expr) getChildNoTransform(1);
259      }
260      /**
261       * @apilevel internal
262       */
263      public ASTNode rewriteTo() {
264        return super.rewriteTo();
265      }
266    }