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