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:163
027     * @production BitwiseExpr : {@link Binary};
028    
029     */
030    public abstract class BitwiseExpr extends Binary implements Cloneable {
031      /**
032       * @aspect TypeCheck
033       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeCheck.jrag:227
034       */
035      public void typeCheck() {
036        TypeDecl left = getLeftOperand().type();
037        TypeDecl right = getRightOperand().type();
038        if (left.isIntegralType() && right.isIntegralType()) {
039          return;
040        } else if (left.isBoolean() && right.isBoolean()) {
041          return;
042        } else {
043          errorf("%s is not compatible with %s", left.typeName(), right.typeName());
044        }
045      }
046      /**
047       * @declaredat ASTNode:1
048       */
049      public BitwiseExpr() {
050        super();
051      }
052      /**
053       * Initializes the child array to the correct size.
054       * Initializes List and Opt nta children.
055       * @apilevel internal
056       * @ast method
057       * @declaredat ASTNode:10
058       */
059      public void init$Children() {
060        children = new ASTNode[2];
061      }
062      /**
063       * @declaredat ASTNode:13
064       */
065      public BitwiseExpr(Expr p0, Expr p1) {
066        setChild(p0, 0);
067        setChild(p1, 1);
068      }
069      /**
070       * @apilevel low-level
071       * @declaredat ASTNode:20
072       */
073      protected int numChildren() {
074        return 2;
075      }
076      /**
077       * @apilevel internal
078       * @declaredat ASTNode:26
079       */
080      public boolean mayHaveRewrite() {
081        return false;
082      }
083      /**
084       * @apilevel internal
085       * @declaredat ASTNode:32
086       */
087      public void flushAttrCache() {
088        super.flushAttrCache();
089        type_reset();
090      }
091      /**
092       * @apilevel internal
093       * @declaredat ASTNode:39
094       */
095      public void flushCollectionCache() {
096        super.flushCollectionCache();
097      }
098      /**
099       * @apilevel internal
100       * @declaredat ASTNode:45
101       */
102      public void flushRewriteCache() {
103        super.flushRewriteCache();
104      }
105      /**
106       * @apilevel internal
107       * @declaredat ASTNode:51
108       */
109      public BitwiseExpr clone() throws CloneNotSupportedException {
110        BitwiseExpr node = (BitwiseExpr) super.clone();
111        return node;
112      }
113      /**
114       * Create a deep copy of the AST subtree at this node.
115       * The copy is dangling, i.e. has no parent.
116       * @return dangling copy of the subtree at this node
117       * @apilevel low-level
118       * @deprecated Please use treeCopy or treeCopyNoTransform instead
119       * @declaredat ASTNode:62
120       */
121      @Deprecated
122      public abstract BitwiseExpr fullCopy();
123      /**
124       * Create a deep copy of the AST subtree at this node.
125       * The copy is dangling, i.e. has no parent.
126       * @return dangling copy of the subtree at this node
127       * @apilevel low-level
128       * @declaredat ASTNode:70
129       */
130      public abstract BitwiseExpr treeCopyNoTransform();
131      /**
132       * Create a deep copy of the AST subtree at this node.
133       * The subtree of this node is traversed to trigger rewrites before copy.
134       * The copy is dangling, i.e. has no parent.
135       * @return dangling copy of the subtree at this node
136       * @apilevel low-level
137       * @declaredat ASTNode:78
138       */
139      public abstract BitwiseExpr treeCopy();
140      /**
141       * Replaces the LeftOperand child.
142       * @param node The new node to replace the LeftOperand child.
143       * @apilevel high-level
144       */
145      public void setLeftOperand(Expr node) {
146        setChild(node, 0);
147      }
148      /**
149       * Retrieves the LeftOperand child.
150       * @return The current node used as the LeftOperand child.
151       * @apilevel high-level
152       */
153      @ASTNodeAnnotation.Child(name="LeftOperand")
154      public Expr getLeftOperand() {
155        return (Expr) getChild(0);
156      }
157      /**
158       * Retrieves the LeftOperand child.
159       * <p><em>This method does not invoke AST transformations.</em></p>
160       * @return The current node used as the LeftOperand child.
161       * @apilevel low-level
162       */
163      public Expr getLeftOperandNoTransform() {
164        return (Expr) getChildNoTransform(0);
165      }
166      /**
167       * Replaces the RightOperand child.
168       * @param node The new node to replace the RightOperand child.
169       * @apilevel high-level
170       */
171      public void setRightOperand(Expr node) {
172        setChild(node, 1);
173      }
174      /**
175       * Retrieves the RightOperand child.
176       * @return The current node used as the RightOperand child.
177       * @apilevel high-level
178       */
179      @ASTNodeAnnotation.Child(name="RightOperand")
180      public Expr getRightOperand() {
181        return (Expr) getChild(1);
182      }
183      /**
184       * Retrieves the RightOperand child.
185       * <p><em>This method does not invoke AST transformations.</em></p>
186       * @return The current node used as the RightOperand child.
187       * @apilevel low-level
188       */
189      public Expr getRightOperandNoTransform() {
190        return (Expr) getChildNoTransform(1);
191      }
192      /**
193       * @apilevel internal
194       */
195      protected boolean type_computed = false;
196      /**
197       * @apilevel internal
198       */
199      protected TypeDecl type_value;
200      /**
201       * @apilevel internal
202       */
203      private void type_reset() {
204        type_computed = false;
205        type_value = null;
206      }
207      /**
208       * @attribute syn
209       * @aspect TypeAnalysis
210       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:302
211       */
212      @ASTNodeAnnotation.Attribute
213      public TypeDecl type() {
214        ASTNode$State state = state();
215        if (type_computed) {
216          return type_value;
217        }
218        boolean intermediate = state.INTERMEDIATE_VALUE;
219        state.INTERMEDIATE_VALUE = false;
220        int num = state.boundariesCrossed;
221        boolean isFinal = this.is$Final();
222        type_value = type_compute();
223        if (isFinal && num == state().boundariesCrossed) {
224          type_computed = true;
225        } else {
226        }
227        state.INTERMEDIATE_VALUE |= intermediate;
228    
229        return type_value;
230      }
231      /**
232       * @apilevel internal
233       */
234      private TypeDecl type_compute() {
235          if (getLeftOperand().type().isIntegralType() && getRightOperand().type().isIntegralType()) {
236            // 15.22.1
237            return getLeftOperand().type().binaryNumericPromotion(getRightOperand().type());
238          } else if (getLeftOperand().type().isBoolean() && getRightOperand().type().isBoolean()) {
239            // 15.22.2
240            return typeBoolean();
241          }
242          return unknownType();
243        }
244      /**
245       * @apilevel internal
246       */
247      public ASTNode rewriteTo() {
248        return super.rewriteTo();
249      }
250    }