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:153
027     * @production ModExpr : {@link MultiplicativeExpr};
028    
029     */
030    public class ModExpr extends MultiplicativeExpr implements Cloneable {
031      /**
032       * @aspect CodeGenerationBinaryOperations
033       * @declaredat /home/jesper/git/extendj/java4/backend/CodeGeneration.jrag:666
034       */
035      void emitOperation(CodeGeneration gen) { type().rem(gen); }
036      /**
037       * @declaredat ASTNode:1
038       */
039      public ModExpr() {
040        super();
041      }
042      /**
043       * Initializes the child array to the correct size.
044       * Initializes List and Opt nta children.
045       * @apilevel internal
046       * @ast method
047       * @declaredat ASTNode:10
048       */
049      public void init$Children() {
050        children = new ASTNode[2];
051      }
052      /**
053       * @declaredat ASTNode:13
054       */
055      public ModExpr(Expr p0, Expr p1) {
056        setChild(p0, 0);
057        setChild(p1, 1);
058      }
059      /**
060       * @apilevel low-level
061       * @declaredat ASTNode:20
062       */
063      protected int numChildren() {
064        return 2;
065      }
066      /**
067       * @apilevel internal
068       * @declaredat ASTNode:26
069       */
070      public boolean mayHaveRewrite() {
071        return false;
072      }
073      /**
074       * @apilevel internal
075       * @declaredat ASTNode:32
076       */
077      public void flushAttrCache() {
078        super.flushAttrCache();
079        isConstant_reset();
080      }
081      /**
082       * @apilevel internal
083       * @declaredat ASTNode:39
084       */
085      public void flushCollectionCache() {
086        super.flushCollectionCache();
087      }
088      /**
089       * @apilevel internal
090       * @declaredat ASTNode:45
091       */
092      public void flushRewriteCache() {
093        super.flushRewriteCache();
094      }
095      /**
096       * @apilevel internal
097       * @declaredat ASTNode:51
098       */
099      public ModExpr clone() throws CloneNotSupportedException {
100        ModExpr node = (ModExpr) super.clone();
101        return node;
102      }
103      /**
104       * @apilevel internal
105       * @declaredat ASTNode:58
106       */
107      public ModExpr copy() {
108        try {
109          ModExpr node = (ModExpr) clone();
110          node.parent = null;
111          if (children != null) {
112            node.children = (ASTNode[]) children.clone();
113          }
114          return node;
115        } catch (CloneNotSupportedException e) {
116          throw new Error("Error: clone not supported for " + getClass().getName());
117        }
118      }
119      /**
120       * Create a deep copy of the AST subtree at this node.
121       * The copy is dangling, i.e. has no parent.
122       * @return dangling copy of the subtree at this node
123       * @apilevel low-level
124       * @deprecated Please use treeCopy or treeCopyNoTransform instead
125       * @declaredat ASTNode:77
126       */
127      @Deprecated
128      public ModExpr fullCopy() {
129        return treeCopyNoTransform();
130      }
131      /**
132       * Create a deep copy of the AST subtree at this node.
133       * The copy is dangling, i.e. has no parent.
134       * @return dangling copy of the subtree at this node
135       * @apilevel low-level
136       * @declaredat ASTNode:87
137       */
138      public ModExpr treeCopyNoTransform() {
139        ModExpr tree = (ModExpr) copy();
140        if (children != null) {
141          for (int i = 0; i < children.length; ++i) {
142            ASTNode child = (ASTNode) children[i];
143            if (child != null) {
144              child = child.treeCopyNoTransform();
145              tree.setChild(child, i);
146            }
147          }
148        }
149        return tree;
150      }
151      /**
152       * Create a deep copy of the AST subtree at this node.
153       * The subtree of this node is traversed to trigger rewrites before copy.
154       * The copy is dangling, i.e. has no parent.
155       * @return dangling copy of the subtree at this node
156       * @apilevel low-level
157       * @declaredat ASTNode:107
158       */
159      public ModExpr treeCopy() {
160        doFullTraversal();
161        return treeCopyNoTransform();
162      }
163      /**
164       * @apilevel internal
165       * @declaredat ASTNode:114
166       */
167      protected boolean is$Equal(ASTNode node) {
168        return super.is$Equal(node);    
169      }
170      /**
171       * Replaces the LeftOperand child.
172       * @param node The new node to replace the LeftOperand child.
173       * @apilevel high-level
174       */
175      public void setLeftOperand(Expr node) {
176        setChild(node, 0);
177      }
178      /**
179       * Retrieves the LeftOperand child.
180       * @return The current node used as the LeftOperand child.
181       * @apilevel high-level
182       */
183      @ASTNodeAnnotation.Child(name="LeftOperand")
184      public Expr getLeftOperand() {
185        return (Expr) getChild(0);
186      }
187      /**
188       * Retrieves the LeftOperand child.
189       * <p><em>This method does not invoke AST transformations.</em></p>
190       * @return The current node used as the LeftOperand child.
191       * @apilevel low-level
192       */
193      public Expr getLeftOperandNoTransform() {
194        return (Expr) getChildNoTransform(0);
195      }
196      /**
197       * Replaces the RightOperand child.
198       * @param node The new node to replace the RightOperand child.
199       * @apilevel high-level
200       */
201      public void setRightOperand(Expr node) {
202        setChild(node, 1);
203      }
204      /**
205       * Retrieves the RightOperand child.
206       * @return The current node used as the RightOperand child.
207       * @apilevel high-level
208       */
209      @ASTNodeAnnotation.Child(name="RightOperand")
210      public Expr getRightOperand() {
211        return (Expr) getChild(1);
212      }
213      /**
214       * Retrieves the RightOperand child.
215       * <p><em>This method does not invoke AST transformations.</em></p>
216       * @return The current node used as the RightOperand child.
217       * @apilevel low-level
218       */
219      public Expr getRightOperandNoTransform() {
220        return (Expr) getChildNoTransform(1);
221      }
222      /**
223       * @attribute syn
224       * @aspect ConstantExpression
225       * @declaredat /home/jesper/git/extendj/java4/frontend/ConstantExpression.jrag:32
226       */
227      @ASTNodeAnnotation.Attribute
228      public Constant constant() {
229        Constant constant_value = type().mod(getLeftOperand().constant(), getRightOperand().constant());
230    
231        return constant_value;
232      }
233      /**
234       * @apilevel internal
235       */
236      protected int isConstant_visited = -1;
237      /**
238       * @apilevel internal
239       */
240      private void isConstant_reset() {
241        isConstant_computed = false;
242        isConstant_initialized = false;
243        isConstant_visited = -1;
244      }
245      /**
246       * @apilevel internal
247       */
248      protected boolean isConstant_computed = false;
249      /**
250       * @apilevel internal
251       */
252      protected boolean isConstant_initialized = false;
253      /**
254       * @apilevel internal
255       */
256      protected boolean isConstant_value;
257      @ASTNodeAnnotation.Attribute
258      public boolean isConstant() {
259        if (isConstant_computed) {
260          return isConstant_value;
261        }
262        ASTNode$State state = state();
263        boolean new_isConstant_value;
264        if (!isConstant_initialized) {
265          isConstant_initialized = true;
266          isConstant_value = false;
267        }
268        if (!state.IN_CIRCLE) {
269          state.IN_CIRCLE = true;
270          int num = state.boundariesCrossed;
271          boolean isFinal = this.is$Final();
272          do {
273            isConstant_visited = state.CIRCLE_INDEX;
274            state.CHANGE = false;
275            new_isConstant_value = getLeftOperand().isConstant() && getRightOperand().isConstant() && !(getRightOperand().type().isInt() && getRightOperand().constant().intValue() == 0);
276            if (new_isConstant_value != isConstant_value) {
277              state.CHANGE = true;
278            }
279            isConstant_value = new_isConstant_value;
280            state.CIRCLE_INDEX++;
281          } while (state.CHANGE);
282          if (isFinal && num == state().boundariesCrossed) {
283            isConstant_computed = true;
284          } else {
285            state.RESET_CYCLE = true;
286            boolean $tmp = getLeftOperand().isConstant() && getRightOperand().isConstant() && !(getRightOperand().type().isInt() && getRightOperand().constant().intValue() == 0);
287            state.RESET_CYCLE = false;
288            isConstant_computed = false;
289            isConstant_initialized = false;
290          }
291          state.IN_CIRCLE = false;
292          state.INTERMEDIATE_VALUE = false;
293          return isConstant_value;
294        }
295        if (isConstant_visited != state.CIRCLE_INDEX) {
296          isConstant_visited = state.CIRCLE_INDEX;
297          if (state.RESET_CYCLE) {
298            isConstant_computed = false;
299            isConstant_initialized = false;
300            isConstant_visited = -1;
301            return isConstant_value;
302          }
303          new_isConstant_value = getLeftOperand().isConstant() && getRightOperand().isConstant() && !(getRightOperand().type().isInt() && getRightOperand().constant().intValue() == 0);
304          if (new_isConstant_value != isConstant_value) {
305            state.CHANGE = true;
306          }
307          isConstant_value = new_isConstant_value;
308          state.INTERMEDIATE_VALUE = true;
309          return isConstant_value;
310        }
311        state.INTERMEDIATE_VALUE = true;
312        return isConstant_value;
313      }
314      /** The operator string used for pretty printing this expression. 
315       * @attribute syn
316       * @aspect PrettyPrintUtil
317       * @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrintUtil.jrag:270
318       */
319      @ASTNodeAnnotation.Attribute
320      public String printOp() {
321        String printOp_value = "%";
322    
323        return printOp_value;
324      }
325      /**
326       * @apilevel internal
327       */
328      public ASTNode rewriteTo() {
329        return super.rewriteTo();
330      }
331    }