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    public class CastExpr extends Expr
024    {
025      public /*@ non_null @*/ Expr expr;
026    
027      //@ invariant type.syntax;
028      public /*@ non_null @*/ Type type;
029    
030      //@ invariant locOpenParen != javafe.util.Location.NULL;
031      public int locOpenParen;
032    
033      //@ invariant locCloseParen != javafe.util.Location.NULL;
034      public int locCloseParen;
035    
036    
037      //@ public represents startLoc <- locOpenParen;
038      public /*@ pure @*/ int getStartLoc() { return locOpenParen; }
039      //@ also public normal_behavior
040      //@ ensures \result == expr.getEndLoc();
041      public /*@ pure @*/ int getEndLoc() { return expr.getEndLoc(); }
042    
043    
044    // Generated boilerplate constructors:
045    
046      //@ ensures this.expr == expr;
047      //@ ensures this.type == type;
048      //@ ensures this.locOpenParen == locOpenParen;
049      //@ ensures this.locCloseParen == locCloseParen;
050      protected CastExpr(/*@ non_null @*/ Expr expr, /*@ non_null @*/ Type type, int locOpenParen, int locCloseParen) {
051         super();
052         this.expr = expr;
053         this.type = type;
054         this.locOpenParen = locOpenParen;
055         this.locCloseParen = locCloseParen;
056      }
057    
058    // Generated boilerplate methods:
059    
060      public final int childCount() {
061         return 2;
062      }
063    
064      public final Object childAt(int index) {
065              /*throws IndexOutOfBoundsException*/
066         if (index < 0)
067            throw new IndexOutOfBoundsException("AST child index " + index);
068         int indexPre = index;
069    
070         int sz;
071    
072         if (index == 0) return this.expr;
073         else index--;
074    
075         if (index == 0) return this.type;
076         else index--;
077    
078         throw new IndexOutOfBoundsException("AST child index " + indexPre);
079      }   //@ nowarn Exception;
080    
081      public final /*@non_null*/String toString() {
082         return "[CastExpr"
083            + " expr = " + this.expr
084            + " type = " + this.type
085            + " locOpenParen = " + this.locOpenParen
086            + " locCloseParen = " + this.locCloseParen
087            + "]";
088      }
089    
090      public final int getTag() {
091         return TagConstants.CASTEXPR;
092      }
093    
094      public final void accept(Visitor v) { v.visitCastExpr(this); }
095    
096      public final Object accept(VisitorArgResult v, Object o) {return v.visitCastExpr(this, o); }
097    
098      public void check() {
099         super.check();
100         this.expr.check();
101         this.type.check();
102      }
103    
104      //@ requires type.syntax;
105      //@ requires locOpenParen != javafe.util.Location.NULL;
106      //@ requires locCloseParen != javafe.util.Location.NULL;
107      //@ ensures \result != null;
108      public static CastExpr make(/*@ non_null @*/ Expr expr, /*@ non_null @*/ Type type, int locOpenParen, int locCloseParen) {
109         CastExpr result = new CastExpr(expr, type, locOpenParen, locCloseParen);
110         return result;
111      }
112    }