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 SwitchLabel syntactic unit.  If expr is null, then
024     * represents the "default" label, otherwise represents a case
025     * label.
026     *
027     * <p> We infer a default: break at the end of each switch statement
028     * that does not contain a default case to simplify translation.  Such
029     * inferred cases will have their location equal to the location of
030     * the closing bracket of the switch statement they are contained in.
031     */
032    
033    public class SwitchLabel extends Stmt
034    {
035      public Expr expr;
036    
037      //@ invariant loc != javafe.util.Location.NULL;
038      public int loc;
039    
040      public int getStartLoc() { return loc; }
041    
042    
043    // Generated boilerplate constructors:
044    
045      /**
046       * Construct a raw SwitchLabel whose class invariant(s) have not
047       * yet been established.  It is the caller's job to
048       * initialize the returned node's fields so that any
049       * class invariants hold.
050       */
051      //@ requires I_will_establish_invariants_afterwards;
052      protected SwitchLabel() {}    //@ nowarn Invariant,NonNullInit;
053    
054    
055    // Generated boilerplate methods:
056    
057      public final int childCount() {
058         return 1;
059      }
060    
061      public final Object childAt(int index) {
062              /*throws IndexOutOfBoundsException*/
063         if (index < 0)
064            throw new IndexOutOfBoundsException("AST child index " + index);
065         int indexPre = index;
066    
067         int sz;
068    
069         if (index == 0) return this.expr;
070         else index--;
071    
072         throw new IndexOutOfBoundsException("AST child index " + indexPre);
073      }   //@ nowarn Exception;
074    
075      public final String toString() {
076         return "[SwitchLabel"
077            + " expr = " + this.expr
078            + " loc = " + this.loc
079            + "]";
080      }
081    
082      public final int getTag() {
083         return TagConstants.SWITCHLABEL;
084      }
085    
086      public final void accept(Visitor v) { v.visitSwitchLabel(this); }
087    
088      public final Object accept(VisitorArgResult v, Object o) {return v.visitSwitchLabel(this, o); }
089    
090      public void check() {
091         super.check();
092         if (this.expr != null)
093            this.expr.check();
094      }
095    
096      //@ requires loc != javafe.util.Location.NULL;
097      //@ ensures \result != null;
098      public static SwitchLabel make(Expr expr, int loc) {
099         //@ set I_will_establish_invariants_afterwards = true;
100         SwitchLabel result = new SwitchLabel();
101         result.expr = expr;
102         result.loc = loc;
103         return result;
104      }
105    }