    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 binary expressions (eg +,-,|,%=, etc).
    024     * The tag is one of the binary operator tags or assignment operator
    025     * tags defined in OperatorTags.
    026     */
    027
    028    public class BinaryExpr extends Expr
    029    {
    030      /*@ invariant (op == TagConstants.OR || op == TagConstants.AND
    031           || op == TagConstants.BITOR || op == TagConstants.BITXOR
    032           || op == TagConstants.BITAND
    033           || op == TagConstants.NE || op == TagConstants.EQ
    034           || op == TagConstants.GE || op == TagConstants.GT
    035           || op == TagConstants.LE || op == TagConstants.LT
    036           || op == TagConstants.LSHIFT || op == TagConstants.RSHIFT
    037           || op == TagConstants.URSHIFT || op == TagConstants.ADD
    038           || op == TagConstants.SUB || op == TagConstants.DIV
    039           || op == TagConstants.MOD || op == TagConstants.STAR
    040           || op == TagConstants.ASSIGN || op == TagConstants.ASGMUL
    041           || op == TagConstants.ASGDIV || op == TagConstants.ASGREM
    042           || op == TagConstants.ASGADD || op == TagConstants.ASGSUB
    043           || op == TagConstants.ASGLSHIFT || op == TagConstants.ASGRSHIFT
    044           || op == TagConstants.ASGURSHIFT || op == TagConstants.ASGBITAND); */
    045      public int op;
    046
    047
    048      public /*@ non_null @*/ Expr left;
    049
    050      public /*@ non_null @*/ Expr right;
    051
    052      //@ invariant locOp != javafe.util.Location.NULL;
    053      public int locOp;
    054
    055
    056      public final int getTag() { return op; }
    057
    058      private void postCheck() {
    059        boolean goodtag =
    060          (op == TagConstants.OR || op == TagConstants.AND
    061           || op == TagConstants.BITOR || op == TagConstants.BITXOR
    062           || op == TagConstants.BITAND
    063           || op == TagConstants.NE || op == TagConstants.EQ
    064           || op == TagConstants.GE || op == TagConstants.GT
    065           || op == TagConstants.LE || op == TagConstants.LT
    066           || op == TagConstants.LSHIFT || op == TagConstants.RSHIFT
    067           || op == TagConstants.URSHIFT || op == TagConstants.ADD
    068           || op == TagConstants.SUB || op == TagConstants.DIV
    069           || op == TagConstants.MOD || op == TagConstants.STAR
    070           || op == TagConstants.ASSIGN || op == TagConstants.ASGMUL
    071           || op == TagConstants.ASGDIV || op == TagConstants.ASGREM
    072           || op == TagConstants.ASGADD || op == TagConstants.ASGSUB
    073           || op == TagConstants.ASGLSHIFT || op == TagConstants.ASGRSHIFT
    074           || op == TagConstants.ASGURSHIFT || op == TagConstants.ASGBITAND
    075           || op == TagConstants.ASGBITOR || op == TagConstants.ASGBITXOR);
    076        Assert.notFalse(goodtag);
    077      }
    078      public int getStartLoc() { return left.getStartLoc(); }
    079      public int getEndLoc() { return right.getEndLoc(); }
    080
    081      /*@ requires (op == TagConstants.OR || op == TagConstants.AND
    082           || op == TagConstants.BITOR || op == TagConstants.BITXOR
    083           || op == TagConstants.BITAND
    084           || op == TagConstants.NE || op == TagConstants.EQ
    085           || op == TagConstants.GE || op == TagConstants.GT
    086           || op == TagConstants.LE || op == TagConstants.LT
    087           || op == TagConstants.LSHIFT || op == TagConstants.RSHIFT
    088           || op == TagConstants.URSHIFT || op == TagConstants.ADD
    089           || op == TagConstants.SUB || op == TagConstants.DIV
    090           || op == TagConstants.MOD || op == TagConstants.STAR
    091           || op == TagConstants.ASSIGN || op == TagConstants.ASGMUL
    092           || op == TagConstants.ASGDIV || op == TagConstants.ASGREM
    093           || op == TagConstants.ASGADD || op == TagConstants.ASGSUB
    094           || op == TagConstants.ASGLSHIFT || op == TagConstants.ASGRSHIFT
    095           || op == TagConstants.ASGURSHIFT || op == TagConstants.ASGBITAND); */
    096      //
    097      //@ requires locOp != javafe.util.Location.NULL;
    098      //@ ensures \result != null;
    099      public static BinaryExpr make(int op,
    100                                    /*@ non_null @*/ Expr left,
    101                                    /*@ non_null @*/ Expr right,
    102                                    int locOp) {
    103         //@ set I_will_establish_invariants_afterwards = true;
    104         BinaryExpr result = new BinaryExpr();
    105         result.op = op;
    106         result.left = left;
    107         result.right = right;
    108         result.locOp = locOp;
    109         return result;
    110      }
    111
    112
    113    // Generated boilerplate constructors:
    114
    115      /**
    116       * Construct a raw BinaryExpr whose class invariant(s) have not
    117       * yet been established.  It is the caller's job to
    118       * initialize the returned node's fields so that any
    119       * class invariants hold.
    120       */
    121      //@ requires I_will_establish_invariants_afterwards;
    122      protected BinaryExpr() {}    //@ nowarn Invariant,NonNullInit;
    123
    124
    125    // Generated boilerplate methods:
    126
    127      public final int childCount() {
    128         return 2;
    129      }
    130
    131      public final Object childAt(int index) {
    132              /*throws IndexOutOfBoundsException*/
    133         if (index < 0)
    134            throw new IndexOutOfBoundsException("AST child index " + index);
    135         int indexPre = index;
    136
    137         int sz;
    138
    139         if (index == 0) return this.left;
    140         else index--;
    141
    142         if (index == 0) return this.right;
    143         else index--;
    144
    145         throw new IndexOutOfBoundsException("AST child index " + indexPre);
    146      }   //@ nowarn Exception;
    147
    148      public final String toString() {
    149         return "[BinaryExpr"
    150            + " op = " + this.op
    151            + " left = " + this.left
    152            + " right = " + this.right
    153            + " locOp = " + this.locOp
    154            + "]";
    155      }
    156
    157      public final void accept(Visitor v) { v.visitBinaryExpr(this); }
    158
    159      public final Object accept(VisitorArgResult v, Object o) {return v.visitBinaryExpr(this, o); }
    160
    161      public void check() {
    162         super.check();
    163         this.left.check();
    164         this.right.check();
    165         postCheck();
    166      }
    167
    168    }