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 an ArrayInitializer. 
024     */
025    
026    public class ArrayInit extends VarInit
027    {
028      public /*@ non_null @*/ VarInitVec elems;
029    
030      //@ invariant locOpenBrace != javafe.util.Location.NULL;
031      public int locOpenBrace;
032    
033      //@ invariant locCloseBrace != javafe.util.Location.NULL;
034      public int locCloseBrace;
035    
036      public int getStartLoc() { return locOpenBrace; }
037      public int getEndLoc() { return locCloseBrace; }
038    
039    
040    // Generated boilerplate constructors:
041    
042      /**
043       * Construct a raw ArrayInit whose class invariant(s) have not
044       * yet been established.  It is the caller's job to
045       * initialize the returned node's fields so that any
046       * class invariants hold.
047       */
048      //@ requires I_will_establish_invariants_afterwards;
049      protected ArrayInit() {}    //@ nowarn Invariant,NonNullInit;
050    
051    
052    // Generated boilerplate methods:
053    
054      public final int childCount() {
055         int sz = 0;
056         if (this.elems != null) sz += this.elems.size();
057         return sz + 0;
058      }
059    
060      public final Object childAt(int index) {
061              /*throws IndexOutOfBoundsException*/
062         if (index < 0)
063            throw new IndexOutOfBoundsException("AST child index " + index);
064         int indexPre = index;
065    
066         int sz;
067    
068         sz = (this.elems == null ? 0 : this.elems.size());
069         if (0 <= index && index < sz)
070            return this.elems.elementAt(index);
071         else index -= sz;
072    
073         throw new IndexOutOfBoundsException("AST child index " + indexPre);
074      }   //@ nowarn Exception;
075    
076      public final String toString() {
077         return "[ArrayInit"
078            + " elems = " + this.elems
079            + " locOpenBrace = " + this.locOpenBrace
080            + " locCloseBrace = " + this.locCloseBrace
081            + "]";
082      }
083    
084      public final int getTag() {
085         return TagConstants.ARRAYINIT;
086      }
087    
088      public final void accept(Visitor v) { v.visitArrayInit(this); }
089    
090      public final Object accept(VisitorArgResult v, Object o) {return v.visitArrayInit(this, o); }
091    
092      public void check() {
093         super.check();
094         for(int i = 0; i < this.elems.size(); i++)
095            this.elems.elementAt(i).check();
096      }
097    
098      //@ requires locOpenBrace != javafe.util.Location.NULL;
099      //@ requires locCloseBrace != javafe.util.Location.NULL;
100      //@ ensures \result != null;
101      public static ArrayInit make(/*@ non_null @*/ VarInitVec elems, int locOpenBrace, int locCloseBrace) {
102         //@ set I_will_establish_invariants_afterwards = true;
103         ArrayInit result = new ArrayInit();
104         result.elems = elems;
105         result.locOpenBrace = locOpenBrace;
106         result.locCloseBrace = locCloseBrace;
107         return result;
108      }
109    }