001    /* Copyright 2000, 2001, Compaq Computer Corporation */
002    
003    /* IF THIS IS A JAVA FILE, DO NOT EDIT IT!  
004    
005       Most Java files in this directory which are part of the Javafe AST
006       are automatically generated using the astgen comment (see
007       ESCTools/Javafe/astgen) from the input file 'hierarchy.h'.  If you
008       wish to modify AST classes or introduce new ones, modify
009       'hierarchy.j.'
010     */
011    
012    package javafe.ast;
013    
014    import javafe.util.Assert;
015    import javafe.util.Location;
016    import javafe.util.ErrorSet;
017    
018    // Convention: unless otherwise noted, integer fields named "loc" refer
019    // to the location of the first character of the syntactic unit
020    
021    
022    /**
023     * Represents a try-catch statement.
024     */
025    
026    public class TryCatchStmt extends Stmt
027    {
028      public /*@ non_null @*/ Stmt tryClause;
029    
030      public /*@ non_null @*/ CatchClauseVec catchClauses;
031    
032      //@ invariant loc != javafe.util.Location.NULL;
033      public int loc;
034    
035    
036      private void postCheck() {
037        int t = tryClause.getTag();
038        Assert.notFalse(t != TagConstants.SWITCHLABEL       //@ nowarn Pre;
039                        && t != TagConstants.CONSTRUCTORINVOCATION
040                        && t != TagConstants.VARDECLSTMT);
041      }
042      public int getStartLoc() { return loc; }
043      public int getEndLoc() { 
044        if (catchClauses == null || catchClauses.size()<1)
045          return tryClause.getEndLoc();
046    
047        return catchClauses.elementAt(catchClauses.size()-1).getEndLoc();
048      }
049    
050    
051    // Generated boilerplate constructors:
052    
053      /**
054       * Construct a raw TryCatchStmt whose class invariant(s) have not
055       * yet been established.  It is the caller's job to
056       * initialize the returned node's fields so that any
057       * class invariants hold.
058       */
059      //@ requires I_will_establish_invariants_afterwards;
060      protected TryCatchStmt() {}    //@ nowarn Invariant,NonNullInit;
061    
062    
063    // Generated boilerplate methods:
064    
065      public final int childCount() {
066         int sz = 0;
067         if (this.catchClauses != null) sz += this.catchClauses.size();
068         return sz + 1;
069      }
070    
071      public final Object childAt(int index) {
072              /*throws IndexOutOfBoundsException*/
073         if (index < 0)
074            throw new IndexOutOfBoundsException("AST child index " + index);
075         int indexPre = index;
076    
077         int sz;
078    
079         if (index == 0) return this.tryClause;
080         else index--;
081    
082         sz = (this.catchClauses == null ? 0 : this.catchClauses.size());
083         if (0 <= index && index < sz)
084            return this.catchClauses.elementAt(index);
085         else index -= sz;
086    
087         throw new IndexOutOfBoundsException("AST child index " + indexPre);
088      }   //@ nowarn Exception;
089    
090      public final String toString() {
091         return "[TryCatchStmt"
092            + " tryClause = " + this.tryClause
093            + " catchClauses = " + this.catchClauses
094            + " loc = " + this.loc
095            + "]";
096      }
097    
098      public final int getTag() {
099         return TagConstants.TRYCATCHSTMT;
100      }
101    
102      public final void accept(Visitor v) { v.visitTryCatchStmt(this); }
103    
104      public final Object accept(VisitorArgResult v, Object o) {return v.visitTryCatchStmt(this, o); }
105    
106      public void check() {
107         super.check();
108         this.tryClause.check();
109         for(int i = 0; i < this.catchClauses.size(); i++)
110            this.catchClauses.elementAt(i).check();
111         postCheck();
112      }
113    
114      //@ requires loc != javafe.util.Location.NULL;
115      //@ ensures \result != null;
116      public static TryCatchStmt make(/*@ non_null @*/ Stmt tryClause, /*@ non_null @*/ CatchClauseVec catchClauses, int loc) {
117         //@ set I_will_establish_invariants_afterwards = true;
118         TryCatchStmt result = new TryCatchStmt();
119         result.tryClause = tryClause;
120         result.catchClauses = catchClauses;
121         result.loc = loc;
122         return result;
123      }
124    }