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 CondExpr extends Expr
024    {
025      public /*@ non_null @*/ Expr test;
026    
027      public /*@ non_null @*/ Expr thn;
028    
029      public /*@ non_null @*/ Expr els;
030    
031      //@ invariant locQuestion != javafe.util.Location.NULL;
032      public int locQuestion;
033    
034      //@ invariant locColon != javafe.util.Location.NULL;
035      public int locColon;
036    
037    
038      //@ public represents startLoc <- test.getStartLoc();
039      public /*@ pure @*/ int getStartLoc() { return test.getStartLoc(); }
040      //@ also public normal_behavior
041      //@ ensures \result == Math.max(thn.getEndLoc(), els.getEndLoc());
042      public /*@ pure @*/ int getEndLoc() { 
043        int thenL = thn.getEndLoc();
044        int elseL = els.getEndLoc();
045        return Math.max(thenL, elseL);
046      }
047    
048    
049    // Generated boilerplate constructors:
050    
051      //@ ensures this.test == test;
052      //@ ensures this.thn == thn;
053      //@ ensures this.els == els;
054      //@ ensures this.locQuestion == locQuestion;
055      //@ ensures this.locColon == locColon;
056      protected CondExpr(/*@ non_null @*/ Expr test, /*@ non_null @*/ Expr thn, /*@ non_null @*/ Expr els, int locQuestion, int locColon) {
057         super();
058         this.test = test;
059         this.thn = thn;
060         this.els = els;
061         this.locQuestion = locQuestion;
062         this.locColon = locColon;
063      }
064    
065    // Generated boilerplate methods:
066    
067      public final int childCount() {
068         return 3;
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.test;
080         else index--;
081    
082         if (index == 0) return this.thn;
083         else index--;
084    
085         if (index == 0) return this.els;
086         else index--;
087    
088         throw new IndexOutOfBoundsException("AST child index " + indexPre);
089      }   //@ nowarn Exception;
090    
091      public final /*@non_null*/String toString() {
092         return "[CondExpr"
093            + " test = " + this.test
094            + " thn = " + this.thn
095            + " els = " + this.els
096            + " locQuestion = " + this.locQuestion
097            + " locColon = " + this.locColon
098            + "]";
099      }
100    
101      public final int getTag() {
102         return TagConstants.CONDEXPR;
103      }
104    
105      public final void accept(Visitor v) { v.visitCondExpr(this); }
106    
107      public final Object accept(VisitorArgResult v, Object o) {return v.visitCondExpr(this, o); }
108    
109      public void check() {
110         super.check();
111         this.test.check();
112         this.thn.check();
113         this.els.check();
114      }
115    
116      //@ requires locQuestion != javafe.util.Location.NULL;
117      //@ requires locColon != javafe.util.Location.NULL;
118      //@ ensures \result != null;
119      public static CondExpr make(/*@ non_null @*/ Expr test, /*@ non_null @*/ Expr thn, /*@ non_null @*/ Expr els, int locQuestion, int locColon) {
120         CondExpr result = new CondExpr(test, thn, els, locQuestion, locColon);
121         return result;
122      }
123    }