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 SynchronizedStmt : {@link Stmt} ::= <span class="component">{@link Expr}</span> <span class="component">{@link Block}</span>;
015     * @ast node
016     * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/java.ast:217
017     */
018    public class SynchronizedStmt extends Stmt implements Cloneable, FinallyHost {
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 SynchronizedStmt clone() throws CloneNotSupportedException {
034        SynchronizedStmt node = (SynchronizedStmt)super.clone();
035        node.isDAafter_Variable_values = null;
036        node.isDUafter_Variable_values = null;
037        node.canCompleteNormally_computed = false;
038        node.label_begin_computed = false;
039        node.label_end_computed = false;
040        node.label_finally_computed = false;
041        node.label_finally_block_computed = false;
042        node.label_exception_handler_computed = false;
043        node.in$Circle(false);
044        node.is$Final(false);
045        return node;
046      }
047    /**
048     * @apilevel internal
049     */
050      @SuppressWarnings({"unchecked", "cast"})
051    public SynchronizedStmt copy() {
052      
053      try {
054        SynchronizedStmt node = (SynchronizedStmt) clone();
055        node.parent = null;
056        if(children != null)
057          node.children = (ASTNode[]) children.clone();
058        
059        return node;
060      } catch (CloneNotSupportedException e) {
061        throw new Error("Error: clone not supported for " + getClass().getName());
062      }
063      
064    }/**
065     * Create a deep copy of the AST subtree at this node.
066     * The copy is dangling, i.e. has no parent.
067     * @return dangling copy of the subtree at this node
068     * @apilevel low-level
069     */
070      @SuppressWarnings({"unchecked", "cast"})
071    public SynchronizedStmt fullCopy() {
072      
073      SynchronizedStmt tree = (SynchronizedStmt) copy();
074      if (children != null) {
075        for (int i = 0; i < children.length; ++i) {
076          
077          ASTNode child = (ASTNode) children[i];
078          if(child != null) {
079            child = child.fullCopy();
080            tree.setChild(child, i);
081          }
082        }
083      }
084      return tree;
085      
086    }  /**
087       * @ast method 
088       * @aspect BranchTarget
089       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/BranchTarget.jrag:206
090       */
091      public void collectFinally(Stmt branchStmt, ArrayList list) {
092        list.add(this);
093        super.collectFinally(branchStmt, list);
094      }
095      /**
096       * @ast method 
097       * @aspect PrettyPrint
098       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/PrettyPrint.jadd:699
099       */
100      public void toString(StringBuffer s) {
101        s.append(indent());
102        s.append("synchronized(");
103        getExpr().toString(s);
104        s.append(") ");
105        getBlock().toString(s);
106      }
107      /**
108       * @ast method 
109       * @aspect TypeCheck
110       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/TypeCheck.jrag:362
111       */
112      public void typeCheck() {
113        TypeDecl type = getExpr().type();
114        if(!type.isReferenceType() || type.isNull())
115          error("*** The type of the expression must be a reference");
116      }
117      /**
118       * @ast method 
119       * @aspect CodeGeneration
120       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CodeGeneration.jrag:817
121       */
122      public void emitMonitorEnter(CodeGeneration gen) {
123        gen.emitDup();
124        int num = localNum();
125        gen.emitStoreReference(num);
126        gen.emit(Bytecode.MONITORENTER);
127      }
128      /**
129       * @ast method 
130       * @aspect CodeGeneration
131       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CodeGeneration.jrag:823
132       */
133      public void emitExceptionHandler(CodeGeneration gen) {
134        // add 1 to stack depth
135        gen.changeStackDepth(1);
136        int num = localNum() + 1;
137        gen.emitStoreReference(num);
138        gen.emitJsr(label_finally_block());
139        gen.emitLoadReference(num);
140        gen.emit(Bytecode.ATHROW);
141      }
142      /**
143       * @ast method 
144       * @aspect CodeGeneration
145       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CodeGeneration.jrag:832
146       */
147      public void emitFinallyBlock(CodeGeneration gen) {
148        // add 1 to stack depth
149        gen.changeStackDepth(1);
150        int num = localNum() + 2;
151        gen.emitStoreReference(num);
152        gen.emitLoadReference(localNum()); // monitor
153        gen.emit(Bytecode.MONITOREXIT);
154        gen.emit(Bytecode.RET).add(num);
155      }
156      /**
157       * @ast method 
158       * @aspect CreateBCode
159       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:1539
160       */
161      public void createBCode(CodeGeneration gen) {
162        super.createBCode(gen);
163        getExpr().createBCode(gen);
164        emitMonitorEnter(gen);
165        gen.addLabel(label_begin());
166        getBlock().createBCode(gen);
167        gen.addLabel(label_finally());
168        if(getBlock().canCompleteNormally()) {
169          gen.emitJsr(label_finally_block());
170          gen.emitGoto(label_end());
171        }
172        gen.addLabel(label_exception_handler());
173        emitExceptionHandler(gen);
174        gen.addLabel(label_finally_block());
175        emitFinallyBlock(gen);
176        gen.addLabel(label_end());
177        gen.createExceptionTable(this);
178      }
179      /**
180       * @ast method 
181       * 
182       */
183      public SynchronizedStmt() {
184        super();
185    
186    
187      }
188      /**
189       * Initializes the child array to the correct size.
190       * Initializes List and Opt nta children.
191       * @apilevel internal
192       * @ast method
193       * @ast method 
194       * 
195       */
196      public void init$Children() {
197        children = new ASTNode[2];
198      }
199      /**
200       * @ast method 
201       * 
202       */
203      public SynchronizedStmt(Expr p0, Block p1) {
204        setChild(p0, 0);
205        setChild(p1, 1);
206      }
207      /**
208       * @apilevel low-level
209       * @ast method 
210       * 
211       */
212      protected int numChildren() {
213        return 2;
214      }
215      /**
216       * @apilevel internal
217       * @ast method 
218       * 
219       */
220      public boolean mayHaveRewrite() {
221        return false;
222      }
223      /**
224       * Replaces the Expr child.
225       * @param node The new node to replace the Expr child.
226       * @apilevel high-level
227       * @ast method 
228       * 
229       */
230      public void setExpr(Expr node) {
231        setChild(node, 0);
232      }
233      /**
234       * Retrieves the Expr child.
235       * @return The current node used as the Expr child.
236       * @apilevel high-level
237       * @ast method 
238       * 
239       */
240      public Expr getExpr() {
241        return (Expr)getChild(0);
242      }
243      /**
244       * Retrieves the Expr child.
245       * <p><em>This method does not invoke AST transformations.</em></p>
246       * @return The current node used as the Expr child.
247       * @apilevel low-level
248       * @ast method 
249       * 
250       */
251      public Expr getExprNoTransform() {
252        return (Expr)getChildNoTransform(0);
253      }
254      /**
255       * Replaces the Block child.
256       * @param node The new node to replace the Block child.
257       * @apilevel high-level
258       * @ast method 
259       * 
260       */
261      public void setBlock(Block node) {
262        setChild(node, 1);
263      }
264      /**
265       * Retrieves the Block child.
266       * @return The current node used as the Block child.
267       * @apilevel high-level
268       * @ast method 
269       * 
270       */
271      public Block getBlock() {
272        return (Block)getChild(1);
273      }
274      /**
275       * Retrieves the Block child.
276       * <p><em>This method does not invoke AST transformations.</em></p>
277       * @return The current node used as the Block child.
278       * @apilevel low-level
279       * @ast method 
280       * 
281       */
282      public Block getBlockNoTransform() {
283        return (Block)getChildNoTransform(1);
284      }
285      protected java.util.Map isDAafter_Variable_values;
286      /**
287       * @attribute syn
288       * @aspect DA
289       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:655
290       */
291      @SuppressWarnings({"unchecked", "cast"})
292      public boolean isDAafter(Variable v) {
293        Object _parameters = v;
294        if(isDAafter_Variable_values == null) isDAafter_Variable_values = new java.util.HashMap(4);
295        if(isDAafter_Variable_values.containsKey(_parameters)) {
296          return ((Boolean)isDAafter_Variable_values.get(_parameters)).booleanValue();
297        }
298          ASTNode$State state = state();
299      int num = state.boundariesCrossed;
300      boolean isFinal = this.is$Final();
301        boolean isDAafter_Variable_value = isDAafter_compute(v);
302      if(isFinal && num == state().boundariesCrossed){ isDAafter_Variable_values.put(_parameters, Boolean.valueOf(isDAafter_Variable_value)); }
303            return isDAafter_Variable_value;
304      }
305      /**
306       * @apilevel internal
307       */
308      private boolean isDAafter_compute(Variable v) {  return getBlock().isDAafter(v);  }
309      /**
310       * @attribute syn
311       * @aspect DU
312       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:915
313       */
314      public boolean isDUafterFinally(Variable v) {
315        ASTNode$State state = state();
316        try {  return true;  }
317        finally {
318        }
319      }
320      /**
321       * @attribute syn
322       * @aspect DU
323       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:918
324       */
325      public boolean isDAafterFinally(Variable v) {
326        ASTNode$State state = state();
327        try {  return false;  }
328        finally {
329        }
330      }
331      protected java.util.Map isDUafter_Variable_values;
332      /**
333       * @attribute syn
334       * @aspect DU
335       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:1178
336       */
337      @SuppressWarnings({"unchecked", "cast"})
338      public boolean isDUafter(Variable v) {
339        Object _parameters = v;
340        if(isDUafter_Variable_values == null) isDUafter_Variable_values = new java.util.HashMap(4);
341        if(isDUafter_Variable_values.containsKey(_parameters)) {
342          return ((Boolean)isDUafter_Variable_values.get(_parameters)).booleanValue();
343        }
344          ASTNode$State state = state();
345      int num = state.boundariesCrossed;
346      boolean isFinal = this.is$Final();
347        boolean isDUafter_Variable_value = isDUafter_compute(v);
348      if(isFinal && num == state().boundariesCrossed){ isDUafter_Variable_values.put(_parameters, Boolean.valueOf(isDUafter_Variable_value)); }
349            return isDUafter_Variable_value;
350      }
351      /**
352       * @apilevel internal
353       */
354      private boolean isDUafter_compute(Variable v) {  return getBlock().isDUafter(v);  }
355      /**
356       * @apilevel internal
357       */
358      protected boolean canCompleteNormally_computed = false;
359      /**
360       * @apilevel internal
361       */
362      protected boolean canCompleteNormally_value;
363      /**
364       * @attribute syn
365       * @aspect UnreachableStatements
366       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/UnreachableStatements.jrag:110
367       */
368      @SuppressWarnings({"unchecked", "cast"})
369      public boolean canCompleteNormally() {
370        if(canCompleteNormally_computed) {
371          return canCompleteNormally_value;
372        }
373          ASTNode$State state = state();
374      int num = state.boundariesCrossed;
375      boolean isFinal = this.is$Final();
376        canCompleteNormally_value = canCompleteNormally_compute();
377      if(isFinal && num == state().boundariesCrossed){ canCompleteNormally_computed = true; }
378            return canCompleteNormally_value;
379      }
380      /**
381       * @apilevel internal
382       */
383      private boolean canCompleteNormally_compute() {  return getBlock().canCompleteNormally();  }
384      /**
385       * @apilevel internal
386       */
387      protected boolean label_begin_computed = false;
388      /**
389       * @apilevel internal
390       */
391      protected int label_begin_value;
392      /**
393       * @attribute syn
394       * @aspect CreateBCode
395       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:1533
396       */
397      @SuppressWarnings({"unchecked", "cast"})
398      public int label_begin() {
399        if(label_begin_computed) {
400          return label_begin_value;
401        }
402          ASTNode$State state = state();
403      int num = state.boundariesCrossed;
404      boolean isFinal = this.is$Final();
405        label_begin_value = label_begin_compute();
406      if(isFinal && num == state().boundariesCrossed){ label_begin_computed = true; }
407            return label_begin_value;
408      }
409      /**
410       * @apilevel internal
411       */
412      private int label_begin_compute() {  return hostType().constantPool().newLabel();  }
413      /**
414       * @apilevel internal
415       */
416      protected boolean label_end_computed = false;
417      /**
418       * @apilevel internal
419       */
420      protected int label_end_value;
421      /**
422       * @attribute syn
423       * @aspect CreateBCode
424       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:1534
425       */
426      @SuppressWarnings({"unchecked", "cast"})
427      public int label_end() {
428        if(label_end_computed) {
429          return label_end_value;
430        }
431          ASTNode$State state = state();
432      int num = state.boundariesCrossed;
433      boolean isFinal = this.is$Final();
434        label_end_value = label_end_compute();
435      if(isFinal && num == state().boundariesCrossed){ label_end_computed = true; }
436            return label_end_value;
437      }
438      /**
439       * @apilevel internal
440       */
441      private int label_end_compute() {  return hostType().constantPool().newLabel();  }
442      /**
443       * @apilevel internal
444       */
445      protected boolean label_finally_computed = false;
446      /**
447       * @apilevel internal
448       */
449      protected int label_finally_value;
450      /**
451       * @attribute syn
452       * @aspect CreateBCode
453       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:1535
454       */
455      @SuppressWarnings({"unchecked", "cast"})
456      public int label_finally() {
457        if(label_finally_computed) {
458          return label_finally_value;
459        }
460          ASTNode$State state = state();
461      int num = state.boundariesCrossed;
462      boolean isFinal = this.is$Final();
463        label_finally_value = label_finally_compute();
464      if(isFinal && num == state().boundariesCrossed){ label_finally_computed = true; }
465            return label_finally_value;
466      }
467      /**
468       * @apilevel internal
469       */
470      private int label_finally_compute() {  return hostType().constantPool().newLabel();  }
471      /**
472       * @apilevel internal
473       */
474      protected boolean label_finally_block_computed = false;
475      /**
476       * @apilevel internal
477       */
478      protected int label_finally_block_value;
479      /**
480       * @attribute syn
481       * @aspect CreateBCode
482       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:1536
483       */
484      @SuppressWarnings({"unchecked", "cast"})
485      public int label_finally_block() {
486        if(label_finally_block_computed) {
487          return label_finally_block_value;
488        }
489          ASTNode$State state = state();
490      int num = state.boundariesCrossed;
491      boolean isFinal = this.is$Final();
492        label_finally_block_value = label_finally_block_compute();
493      if(isFinal && num == state().boundariesCrossed){ label_finally_block_computed = true; }
494            return label_finally_block_value;
495      }
496      /**
497       * @apilevel internal
498       */
499      private int label_finally_block_compute() {  return hostType().constantPool().newLabel();  }
500      /**
501       * @apilevel internal
502       */
503      protected boolean label_exception_handler_computed = false;
504      /**
505       * @apilevel internal
506       */
507      protected int label_exception_handler_value;
508      /**
509       * @attribute syn
510       * @aspect CreateBCode
511       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:1537
512       */
513      @SuppressWarnings({"unchecked", "cast"})
514      public int label_exception_handler() {
515        if(label_exception_handler_computed) {
516          return label_exception_handler_value;
517        }
518          ASTNode$State state = state();
519      int num = state.boundariesCrossed;
520      boolean isFinal = this.is$Final();
521        label_exception_handler_value = label_exception_handler_compute();
522      if(isFinal && num == state().boundariesCrossed){ label_exception_handler_computed = true; }
523            return label_exception_handler_value;
524      }
525      /**
526       * @apilevel internal
527       */
528      private int label_exception_handler_compute() {  return hostType().constantPool().newLabel();  }
529      /**
530       * @attribute syn
531       * @aspect PreciseRethrow
532       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/PreciseRethrow.jrag:55
533       */
534      public boolean modifiedInScope(Variable var) {
535        ASTNode$State state = state();
536        try {  return getBlock().modifiedInScope(var);  }
537        finally {
538        }
539      }
540      /**
541       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:657
542       * @apilevel internal
543       */
544      public boolean Define_boolean_isDAbefore(ASTNode caller, ASTNode child, Variable v) {
545        if(caller == getBlockNoTransform()) {
546          return getExpr().isDAafter(v);
547        }
548        else if(caller == getExprNoTransform()) {
549          return isDAbefore(v);
550        }
551        else {      return getParent().Define_boolean_isDAbefore(this, caller, v);
552        }
553      }
554      /**
555       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:1180
556       * @apilevel internal
557       */
558      public boolean Define_boolean_isDUbefore(ASTNode caller, ASTNode child, Variable v) {
559        if(caller == getBlockNoTransform()) {
560          return getExpr().isDUafter(v);
561        }
562        else if(caller == getExprNoTransform()) {
563          return isDUbefore(v);
564        }
565        else {      return getParent().Define_boolean_isDUbefore(this, caller, v);
566        }
567      }
568      /**
569       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/UnreachableStatements.jrag:111
570       * @apilevel internal
571       */
572      public boolean Define_boolean_reachable(ASTNode caller, ASTNode child) {
573        if(caller == getBlockNoTransform()) {
574          return reachable();
575        }
576        else {      return getParent().Define_boolean_reachable(this, caller);
577        }
578      }
579      /**
580       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/UnreachableStatements.jrag:157
581       * @apilevel internal
582       */
583      public boolean Define_boolean_reportUnreachable(ASTNode caller, ASTNode child) {
584        if(caller == getBlockNoTransform()) {
585          return reachable();
586        }
587        else {      return getParent().Define_boolean_reportUnreachable(this, caller);
588        }
589      }
590      /**
591       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/LocalNum.jrag:122
592       * @apilevel internal
593       */
594      public int Define_int_localNum(ASTNode caller, ASTNode child) {
595        if(caller == getBlockNoTransform()) {
596          return localNum() + 3;
597        }
598        else {      return getParent().Define_int_localNum(this, caller);
599        }
600      }
601      /**
602       * @apilevel internal
603       */
604      public ASTNode rewriteTo() {
605        return super.rewriteTo();
606      }
607    }