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