    001    /* Copyright 2000, 2001, Compaq Computer Corporation */
    002
    003    package javafe.ast;
    004
    005    /**
    006     * <code>TagConstants</code> is a class defining a partially-opaque
    007     * type for tags used in the AST.  "Partially opaque" means that the
    008     * representation of this type is known -- it's an <code>int</code> --
    009     * but code should not depend on the detailed mapping of operator tags
    010     * to integers.
    011     *
    012     * @see OperatorTags
    013     * @see GeneratedTags
    014     */
    015
    016    public class TagConstants extends OperatorTags
    017    {
    018        /**
    019         * Used to indicate that no tag applies, for example, when looking
    020         * up the tag associated with a string.
    021         */
    022        public static final int NULL = -1;
    023
    024        public static final int IDENT = javafe.ast.OperatorTags.LAST_TAG + 1;
    025
    026        public static final int ERRORTYPE = IDENT + 1;
    027        public static final int BOOLEANTYPE = ERRORTYPE + 1;
    028        public static final int CHARTYPE = BOOLEANTYPE + 1;
    029        public static final int VOIDTYPE = CHARTYPE + 1;
    030        public static final int NULLTYPE = VOIDTYPE + 1;
    031        // The following must be in the order of implicit promotion
    032        public static final int BYTETYPE = NULLTYPE + 1;
    033        public static final int SHORTTYPE = BYTETYPE + 1;
    034        public static final int INTTYPE = SHORTTYPE + 1;
    035        public static final int LONGTYPE = INTTYPE + 1;
    036        public static final int FLOATTYPE = LONGTYPE + 1;
    037        public static final int DOUBLETYPE = FLOATTYPE + 1;
    038
    039        public static final int BOOLEANLIT = DOUBLETYPE +1;
    040        public static final int INTLIT = BOOLEANLIT + 1;
    041        public static final int LONGLIT = INTLIT + 1;
    042        public static final int CHARLIT = LONGLIT + 1;
    043        public static final int FLOATLIT = CHARLIT + 1;
    044        public static final int DOUBLELIT = FLOATLIT + 1;
    045        public static final int STRINGLIT = DOUBLELIT + 1;
    046        public static final int NULLLIT = STRINGLIT + 1;
    047        public static final int BYTELIT = NULLLIT + 1;
    048        public static final int SHORTLIT = BYTELIT + 1;
    049
    050        public static final int LAST_TAG = NULLLIT;
    051
    052        //@ private invariant \nonnullelements(tags);
    053        private static final /*@ non_null @*/ String[] tags = {
    054            "IDENT", "ERRORTYPE",
    055            "BOOLEANTYPE", "CHARTYPE", "VOIDTYPE", "NULLTYPE",
    056            "BYTETYPE", "SHORTTYPE", "INTTYPE", "LONGTYPE",
    057            "FLOATTYPE", "DOUBLETYPE",
    058            "BOOLEANLIT", "INTLIT", "LONGLIT", "CHARLIT",
    059            "FLOATLIT", "DOUBLELIT", "STRINGLIT", "NULLLIT" };
    060
    061        //@ requires tag <= LAST_TAG;
    062        //@ ensures \result != null;
    063        public static String toString(int tag) {
    064            if (IDENT <= tag && tag <= LAST_TAG)
    065                return tags[tag - IDENT];
    066
    067            return OperatorTags.toString(tag);
    068        }
    069    }