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