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 AssertStmt : {@link Stmt} ::= <span class="component">first:{@link Expr}</span> <span class="component">[{@link Expr}]</span>;
015     * @ast node
016     * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/java.ast:221
017     */
018    public class AssertStmt extends Stmt 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 AssertStmt clone() throws CloneNotSupportedException {
034        AssertStmt node = (AssertStmt)super.clone();
035        node.isDAafter_Variable_values = null;
036        node.isDUafter_Variable_values = null;
037        node.in$Circle(false);
038        node.is$Final(false);
039        return node;
040      }
041    /**
042     * @apilevel internal
043     */
044      @SuppressWarnings({"unchecked", "cast"})
045    public AssertStmt copy() {
046      
047      try {
048        AssertStmt node = (AssertStmt) clone();
049        node.parent = null;
050        if(children != null)
051          node.children = (ASTNode[]) children.clone();
052        
053        return node;
054      } catch (CloneNotSupportedException e) {
055        throw new Error("Error: clone not supported for " + getClass().getName());
056      }
057      
058    }/**
059     * Create a deep copy of the AST subtree at this node.
060     * The copy is dangling, i.e. has no parent.
061     * @return dangling copy of the subtree at this node
062     * @apilevel low-level
063     */
064      @SuppressWarnings({"unchecked", "cast"})
065    public AssertStmt fullCopy() {
066      
067      AssertStmt tree = (AssertStmt) copy();
068      if (children != null) {
069        for (int i = 0; i < children.length; ++i) {
070          
071          ASTNode child = (ASTNode) children[i];
072          if(child != null) {
073            child = child.fullCopy();
074            tree.setChild(child, i);
075          }
076        }
077      }
078      return tree;
079      
080    }  /**
081       * @ast method 
082       * @aspect PrettyPrint
083       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/PrettyPrint.jadd:729
084       */
085      public void toString(StringBuffer s) {
086        s.append(indent());
087        s.append("assert ");
088        getfirst().toString(s);
089        if(hasExpr()) {
090          s.append(" : ");
091          getExpr().toString(s);
092        }
093        s.append(";");
094      }
095      /**
096       * @ast method 
097       * @aspect TypeCheck
098       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/TypeCheck.jrag:378
099       */
100      public void typeCheck() {
101        // 14.10
102        if(!getfirst().type().isBoolean())
103          error("Assert requires boolean condition");
104        if(hasExpr() && getExpr().type().isVoid())
105          error("The second part of an assert statement may not be void");
106      }
107      /**
108       * Assert statement bytecode is generated through the transformed
109       * version of the assert statement!
110       *
111       * @see Java1.4Backend/Transformations.jrag
112       * @ast method 
113       * @aspect CreateBCode
114       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:1564
115       */
116      public void createBCode(CodeGeneration gen) {
117        throw new UnsupportedOperationException("Assert not implemented yet");
118      }
119      /**
120       * @ast method 
121       * @aspect Transformations
122       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/Transformations.jrag:170
123       */
124      public void transformation() {
125        super.transformation();
126        // add field to hold cached result as a side-effect
127        FieldDeclaration f = hostType().topLevelType().createStaticClassField(hostType().topLevelType().referenceClassFieldName());
128        FieldDeclaration assertionsDisabled = hostType().createAssertionsDisabled();
129        Expr condition = (Expr)getfirst().fullCopy();
130        List args = new List();
131        if(hasExpr())
132          if(getExpr().type().isString())
133            args.add(new CastExpr(new TypeAccess("java.lang", "Object"), (Expr)getExpr().fullCopy()));
134          else
135            args.add(getExpr().fullCopy());
136        Stmt stmt = 
137          new IfStmt(
138            new LogNotExpr(
139              new ParExpr(
140                new OrLogicalExpr(
141                  new BoundFieldAccess(assertionsDisabled),
142                  condition
143                )
144              )
145            ),
146            new ThrowStmt(
147              new ClassInstanceExpr(
148                lookupType("java.lang", "AssertionError").createQualifiedAccess(),
149                args,
150                new Opt()
151              )
152            ),
153            new Opt()
154          );
155         
156        replace(this).with(stmt);
157        stmt.transformation();
158      }
159      /**
160       * @ast method 
161       * 
162       */
163      public AssertStmt() {
164        super();
165    
166    
167      }
168      /**
169       * Initializes the child array to the correct size.
170       * Initializes List and Opt nta children.
171       * @apilevel internal
172       * @ast method
173       * @ast method 
174       * 
175       */
176      public void init$Children() {
177        children = new ASTNode[2];
178        setChild(new Opt(), 1);
179      }
180      /**
181       * @ast method 
182       * 
183       */
184      public AssertStmt(Expr p0, Opt<Expr> p1) {
185        setChild(p0, 0);
186        setChild(p1, 1);
187      }
188      /**
189       * @apilevel low-level
190       * @ast method 
191       * 
192       */
193      protected int numChildren() {
194        return 2;
195      }
196      /**
197       * @apilevel internal
198       * @ast method 
199       * 
200       */
201      public boolean mayHaveRewrite() {
202        return false;
203      }
204      /**
205       * Replaces the first child.
206       * @param node The new node to replace the first child.
207       * @apilevel high-level
208       * @ast method 
209       * 
210       */
211      public void setfirst(Expr node) {
212        setChild(node, 0);
213      }
214      /**
215       * Retrieves the first child.
216       * @return The current node used as the first child.
217       * @apilevel high-level
218       * @ast method 
219       * 
220       */
221      public Expr getfirst() {
222        return (Expr)getChild(0);
223      }
224      /**
225       * Retrieves the first child.
226       * <p><em>This method does not invoke AST transformations.</em></p>
227       * @return The current node used as the first child.
228       * @apilevel low-level
229       * @ast method 
230       * 
231       */
232      public Expr getfirstNoTransform() {
233        return (Expr)getChildNoTransform(0);
234      }
235      /**
236       * Replaces the optional node for the Expr child. This is the {@code Opt} node containing the child Expr, not the actual child!
237       * @param opt The new node to be used as the optional node for the Expr child.
238       * @apilevel low-level
239       * @ast method 
240       * 
241       */
242      public void setExprOpt(Opt<Expr> opt) {
243        setChild(opt, 1);
244      }
245      /**
246       * Check whether the optional Expr child exists.
247       * @return {@code true} if the optional Expr child exists, {@code false} if it does not.
248       * @apilevel high-level
249       * @ast method 
250       * 
251       */
252      public boolean hasExpr() {
253        return getExprOpt().getNumChild() != 0;
254      }
255      /**
256       * Retrieves the (optional) Expr child.
257       * @return The Expr child, if it exists. Returns {@code null} otherwise.
258       * @apilevel low-level
259       * @ast method 
260       * 
261       */
262      @SuppressWarnings({"unchecked", "cast"})
263      public Expr getExpr() {
264        return (Expr)getExprOpt().getChild(0);
265      }
266      /**
267       * Replaces the (optional) Expr child.
268       * @param node The new node to be used as the Expr child.
269       * @apilevel high-level
270       * @ast method 
271       * 
272       */
273      public void setExpr(Expr node) {
274        getExprOpt().setChild(node, 0);
275      }
276      /**
277       * @apilevel low-level
278       * @ast method 
279       * 
280       */
281      @SuppressWarnings({"unchecked", "cast"})
282      public Opt<Expr> getExprOpt() {
283        return (Opt<Expr>)getChild(1);
284      }
285      /**
286       * Retrieves the optional node for child Expr. This is the {@code Opt} node containing the child Expr, not the actual child!
287       * <p><em>This method does not invoke AST transformations.</em></p>
288       * @return The optional node for child Expr.
289       * @apilevel low-level
290       * @ast method 
291       * 
292       */
293      @SuppressWarnings({"unchecked", "cast"})
294      public Opt<Expr> getExprOptNoTransform() {
295        return (Opt<Expr>)getChildNoTransform(1);
296      }
297      protected java.util.Map isDAafter_Variable_values;
298      /**
299       * @attribute syn
300       * @aspect DA
301       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:418
302       */
303      @SuppressWarnings({"unchecked", "cast"})
304      public boolean isDAafter(Variable v) {
305        Object _parameters = v;
306        if(isDAafter_Variable_values == null) isDAafter_Variable_values = new java.util.HashMap(4);
307        if(isDAafter_Variable_values.containsKey(_parameters)) {
308          return ((Boolean)isDAafter_Variable_values.get(_parameters)).booleanValue();
309        }
310          ASTNode$State state = state();
311      int num = state.boundariesCrossed;
312      boolean isFinal = this.is$Final();
313        boolean isDAafter_Variable_value = isDAafter_compute(v);
314      if(isFinal && num == state().boundariesCrossed){ isDAafter_Variable_values.put(_parameters, Boolean.valueOf(isDAafter_Variable_value)); }
315            return isDAafter_Variable_value;
316      }
317      /**
318       * @apilevel internal
319       */
320      private boolean isDAafter_compute(Variable v) {  return getfirst().isDAafter(v);  }
321      protected java.util.Map isDUafter_Variable_values;
322      /**
323       * @attribute syn
324       * @aspect DU
325       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:866
326       */
327      @SuppressWarnings({"unchecked", "cast"})
328      public boolean isDUafter(Variable v) {
329        Object _parameters = v;
330        if(isDUafter_Variable_values == null) isDUafter_Variable_values = new java.util.HashMap(4);
331        if(isDUafter_Variable_values.containsKey(_parameters)) {
332          return ((Boolean)isDUafter_Variable_values.get(_parameters)).booleanValue();
333        }
334          ASTNode$State state = state();
335      int num = state.boundariesCrossed;
336      boolean isFinal = this.is$Final();
337        boolean isDUafter_Variable_value = isDUafter_compute(v);
338      if(isFinal && num == state().boundariesCrossed){ isDUafter_Variable_values.put(_parameters, Boolean.valueOf(isDUafter_Variable_value)); }
339            return isDUafter_Variable_value;
340      }
341      /**
342       * @apilevel internal
343       */
344      private boolean isDUafter_compute(Variable v) {  return getfirst().isDUafter(v);  }
345      /**
346       * @attribute syn
347       * @aspect PreciseRethrow
348       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/PreciseRethrow.jrag:55
349       */
350      public boolean modifiedInScope(Variable var) {
351        ASTNode$State state = state();
352        try {  return false;  }
353        finally {
354        }
355      }
356      /**
357       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:419
358       * @apilevel internal
359       */
360      public boolean Define_boolean_isDAbefore(ASTNode caller, ASTNode child, Variable v) {
361        if(caller == getExprOptNoTransform()) {
362          return getfirst().isDAafter(v);
363        }
364        else {      return getParent().Define_boolean_isDAbefore(this, caller, v);
365        }
366      }
367      /**
368       * @apilevel internal
369       */
370      public ASTNode rewriteTo() {
371        return super.rewriteTo();
372      }
373    }