    001    /* Copyright 2000, 2001, Compaq Computer Corporation */
    002
    003    package javafe.ast;
    004
    005    import javafe.util.Assert;
    006
    007    /**
    008     * <code>OperatorTags</code> is a class defining a partially-opaque
    009     * type for tags used in the AST.  See <code>TagConstants</code> for
    010     * more information.
    011     */
    012
    013    public class OperatorTags extends GeneratedTags
    014    {
    015        // Binary operator tags
    016        public static final int FIRST_TAG = javafe.ast.GeneratedTags.LAST_TAG + 1;
    017        public static final int OR = FIRST_TAG;
    018        public static final int AND = OR + 1;
    019        public static final int BITOR = AND + 1;
    020        public static final int BITXOR = BITOR + 1;
    021        public static final int BITAND = BITXOR + 1;
    022        public static final int NE = BITAND + 1;
    023        public static final int EQ = NE + 1;
    024        public static final int GE = EQ + 1;
    025        public static final int GT = GE + 1;
    026        public static final int LE = GT + 1;
    027        public static final int LT = LE + 1;
    028        public static final int LSHIFT = LT + 1;
    029        public static final int RSHIFT = LSHIFT + 1;
    030        public static final int URSHIFT = RSHIFT + 1;
    031        public static final int ADD = URSHIFT + 1;
    032        public static final int SUB = ADD + 1;
    033        public static final int DIV = SUB + 1;
    034        public static final int MOD = DIV + 1;
    035        public static final int STAR = MOD + 1;
    036
    037        // Assignment-operator tags
    038        public static final int ASSIGN = STAR + 1;
    039        public static final int ASGMUL = ASSIGN + 1;
    040        public static final int ASGDIV = ASGMUL + 1;
    041        public static final int ASGREM = ASGDIV + 1;
    042        public static final int ASGADD = ASGREM + 1;
    043        public static final int ASGSUB = ASGADD + 1;
    044        public static final int ASGLSHIFT = ASGSUB + 1;
    045        public static final int ASGRSHIFT = ASGLSHIFT + 1;
    046        public static final int ASGURSHIFT = ASGRSHIFT + 1;
    047        public static final int ASGBITAND = ASGURSHIFT + 1;
    048        public static final int ASGBITOR = ASGBITAND + 1;
    049        public static final int ASGBITXOR = ASGBITOR + 1;
    050
    051        // Unary operator tags
    052        public static final int UNARYADD = ASGBITXOR + 1;
    053        public static final int UNARYSUB = UNARYADD + 1;
    054        public static final int NOT = UNARYSUB + 1;
    055        public static final int BITNOT = NOT + 1;
    056        public static final int INC = BITNOT + 1;
    057        public static final int DEC = INC + 1;
    058
    059        // Postfix unary operators
    060        public static final int POSTFIXINC = DEC + 1;
    061        public static final int POSTFIXDEC = POSTFIXINC + 1;
    062
    063        public static final int LAST_TAG = POSTFIXDEC;
    064
    065        /**
    066         * @return the text representation of <code>code</code>.  For
    067         * example, return the string "=" for the tag {@link #ASSIGN}.
    068         */
    069        //@ ensures \result != null;
    070        public static String toString(int opTag) {
    071            if (FIRST_TAG <= opTag && opTag <= LAST_TAG)
    072                return opStrings[opTag - FIRST_TAG];
    073
    074            if (opTag < FIRST_TAG)
    075                return GeneratedTags.toString(opTag);
    076
    077            return "Unknown tag <" + opTag + ">";
    078        }
    079
    080    //    private static final /*@ non_null @*/ int[] opTags = {
    081    //        OR, AND, BITOR, BITXOR, BITAND, NE, EQ, GE, GT, LE, LT,
    082    //        LSHIFT, RSHIFT, URSHIFT, ADD, SUB, DIV, MOD, STAR,
    083    //        ASSIGN, ASGMUL, ASGDIV, ASGREM, ASGADD, ASGSUB,
    084    //        ASGLSHIFT, ASGRSHIFT, ASGURSHIFT, ASGBITAND, ASGBITOR, ASGBITXOR,
    085    //        UNARYADD, UNARYSUB, NOT, BITNOT, INC, DEC, POSTFIXINC, POSTFIXDEC
    086    //    };
    087
    088        //@ private invariant \nonnullelements(opStrings);
    089    //    //@ private invariant opTags.length == opStrings.length;
    090        private static final /*@ non_null @*/ String[] opStrings = {
    091            "||", "&&", "|", "^", "&", "!=", "==", ">=", ">", "<=", "<",
    092            "<<", ">>", ">>>", "+", "-", "/", "%", "*",
    093            "=", "*=", "/=", "%=", "+=", "-=",
    094            "<<=", ">>=", ">>>=", "&=", "|=", "^=",
    095            "+", "-", "!", "~", "++", "--", "++", "--"
    096        };
    097
    098    }