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 various kinds of unary expressions.
024     * The tag is one of the constants:
025     *      ADD SUB NOT BITNOT INC DEC POSTFIXINC POSTFIXDEC
026     * defined in OperatorTags.
027     */
028    
029    public class UnaryExpr extends Expr
030    {
031      /*@ invariant (op == TagConstants.UNARYADD || op == TagConstants.UNARYSUB
032           || op == TagConstants.NOT || op == TagConstants.BITNOT
033           || op == TagConstants.INC || op == TagConstants.DEC
034           || op == TagConstants.POSTFIXINC || op == TagConstants.POSTFIXDEC); */
035      public int op;
036    
037    
038      public /*@ non_null @*/ Expr expr;
039    
040      //@ invariant locOp != javafe.util.Location.NULL;
041      public int locOp;
042    
043    
044      public final int getTag() { return op; }
045    
046      private void postCheck() {
047        boolean goodtag =
048          (op == TagConstants.UNARYADD || op == TagConstants.UNARYSUB
049           || op == TagConstants.NOT || op == TagConstants.BITNOT
050           || op == TagConstants.INC || op == TagConstants.DEC
051           || op == TagConstants.POSTFIXINC || op == TagConstants.POSTFIXDEC);
052        Assert.notFalse(goodtag);
053      }
054      public int getStartLoc() { 
055        int le = expr.getStartLoc(); 
056        return le < locOp ? le : locOp;
057      }
058    
059      public int getEndLoc() { 
060        int le = expr.getEndLoc(); 
061        return le < locOp ? locOp : le;
062      }
063    
064      /*@ requires (op == TagConstants.UNARYADD || op == TagConstants.UNARYSUB
065           || op == TagConstants.NOT || op == TagConstants.BITNOT
066           || op == TagConstants.INC || op == TagConstants.DEC
067           || op == TagConstants.POSTFIXINC || op == TagConstants.POSTFIXDEC); */
068      //
069      //@ requires locOp != javafe.util.Location.NULL;
070      //@ ensures \result != null;
071      public static UnaryExpr make(int op, /*@ non_null @*/ Expr expr, int locOp) {
072         //@ set I_will_establish_invariants_afterwards = true;
073         UnaryExpr result = new UnaryExpr();
074         result.op = op;
075         result.expr = expr;
076         result.locOp = locOp;
077         return result;
078      }
079    
080    
081    // Generated boilerplate constructors:
082    
083      /**
084       * Construct a raw UnaryExpr whose class invariant(s) have not
085       * yet been established.  It is the caller's job to
086       * initialize the returned node's fields so that any
087       * class invariants hold.
088       */
089      //@ requires I_will_establish_invariants_afterwards;
090      protected UnaryExpr() {}    //@ nowarn Invariant,NonNullInit;
091    
092    
093    // Generated boilerplate methods:
094    
095      public final int childCount() {
096         return 1;
097      }
098    
099      public final Object childAt(int index) {
100              /*throws IndexOutOfBoundsException*/
101         if (index < 0)
102            throw new IndexOutOfBoundsException("AST child index " + index);
103         int indexPre = index;
104    
105         int sz;
106    
107         if (index == 0) return this.expr;
108         else index--;
109    
110         throw new IndexOutOfBoundsException("AST child index " + indexPre);
111      }   //@ nowarn Exception;
112    
113      public final String toString() {
114         return "[UnaryExpr"
115            + " op = " + this.op
116            + " expr = " + this.expr
117            + " locOp = " + this.locOp
118            + "]";
119      }
120    
121      public final void accept(Visitor v) { v.visitUnaryExpr(this); }
122    
123      public final Object accept(VisitorArgResult v, Object o) {return v.visitUnaryExpr(this, o); }
124    
125      public void check() {
126         super.check();
127         this.expr.check();
128         postCheck();
129      }
130    
131    }