src/share/classes/com/sun/tools/javac/jvm/Gen.java

Print this page

        

@@ -45,10 +45,12 @@
 import static com.sun.tools.javac.code.Kinds.*;
 import static com.sun.tools.javac.code.TypeTags.*;
 import static com.sun.tools.javac.jvm.ByteCodes.*;
 import static com.sun.tools.javac.jvm.CRTFlags.*;
 import static com.sun.tools.javac.main.OptionName.*;
+import static com.sun.tools.javac.tree.JCTree.Tag.*;
+import static com.sun.tools.javac.tree.JCTree.Tag.BLOCK;
 
 /** This pass maps flat Java (i.e. without inner classes) to bytecodes.
  *
  *  <p><b>This is NOT part of any supported API.
  *  If you write code that depends on this, you do so at your own risk.

@@ -431,11 +433,11 @@
      *  @param target      The tree representing the structure that's aborted
      *  @param env         The environment current at the non-local exit.
      */
     boolean hasFinally(JCTree target, Env<GenContext> env) {
         while (env.tree != target) {
-            if (env.tree.getTag() == JCTree.TRY && env.info.finalize.hasFinalizer())
+            if (env.tree.hasTag(TRY) && env.info.finalize.hasFinalizer())
                 return true;
             env = env.next;
         }
         return false;
     }

@@ -458,21 +460,21 @@
         //  - clinitCode for class initializers
         //  - methodDefs for method definitions
         for (List<JCTree> l = defs; l.nonEmpty(); l = l.tail) {
             JCTree def = l.head;
             switch (def.getTag()) {
-            case JCTree.BLOCK:
+            case BLOCK:
                 JCBlock block = (JCBlock)def;
                 if ((block.flags & STATIC) != 0)
                     clinitCode.append(block);
                 else
                     initCode.append(block);
                 break;
-            case JCTree.METHODDEF:
+            case METHODDEF:
                 methodDefs.append(def);
                 break;
-            case JCTree.VARDEF:
+            case VARDEF:
                 JCVariableDecl vdef = (JCVariableDecl) def;
                 VarSymbol sym = vdef.sym;
                 checkDimension(vdef.pos(), sym.type);
                 if (vdef.init != null) {
                     if ((sym.flags() & STATIC) == 0) {

@@ -705,21 +707,21 @@
             genStat(tree, env);
             return;
         }
         int startpc = code.curPc();
         genStat(tree, env);
-        if (tree.getTag() == JCTree.BLOCK) crtFlags |= CRT_BLOCK;
+        if (tree.hasTag(BLOCK)) crtFlags |= CRT_BLOCK;
         code.crt.put(tree, crtFlags, startpc, code.curPc());
     }
 
     /** Derived visitor method: generate code for a statement.
      */
     public void genStat(JCTree tree, Env<GenContext> env) {
         if (code.isAlive()) {
             code.statBegin(tree.pos);
             genDef(tree, env);
-        } else if (env.info.isSwitch && tree.getTag() == JCTree.VARDEF) {
+        } else if (env.info.isSwitch && tree.hasTag(VARDEF)) {
             // variables whose declarations are in a switch
             // can be used even if the decl is unreachable.
             code.newLocal(((JCVariableDecl) tree).sym);
         }
     }

@@ -782,11 +784,11 @@
      *                      should contain a proper tree to generate
      *                      CharacterRangeTable branches for them.
      */
     public CondItem genCond(JCTree _tree, boolean markBranches) {
         JCTree inner_tree = TreeInfo.skipParens(_tree);
-        if (inner_tree.getTag() == JCTree.CONDEXPR) {
+        if (inner_tree.hasTag(CONDEXPR)) {
             JCConditional tree = (JCConditional)inner_tree;
             CondItem cond = genCond(tree.cond, CRT_FLOW_CONTROLLER);
             if (cond.isTrue()) {
                 code.resolve(cond.trueJumps);
                 CondItem result = genCond(tree.truepart, CRT_FLOW_TARGET);

@@ -1031,11 +1033,11 @@
     public void visitBlock(JCBlock tree) {
         int limit = code.nextreg;
         Env<GenContext> localEnv = env.dup(tree, new GenContext());
         genStats(tree.stats, localEnv);
         // End the scope of all block-local variables in variable info.
-        if (env.tree.getTag() != JCTree.METHODDEF) {
+        if (!env.tree.hasTag(METHODDEF)) {
             code.statBegin(tree.endpos);
             code.endScopes(limit);
             code.pendingStatPos = Position.NOPOS;
         }
     }

@@ -1626,15 +1628,15 @@
 
     public void visitExec(JCExpressionStatement tree) {
         // Optimize x++ to ++x and x-- to --x.
         JCExpression e = tree.expr;
         switch (e.getTag()) {
-            case JCTree.POSTINC:
-                ((JCUnary) e).setTag(JCTree.PREINC);
+            case POSTINC:
+                ((JCUnary) e).setTag(PREINC);
                 break;
-            case JCTree.POSTDEC:
-                ((JCUnary) e).setTag(JCTree.PREDEC);
+            case POSTDEC:
+                ((JCUnary) e).setTag(PREDEC);
                 break;
         }
         genExpr(tree.expr, tree.expr.type).drop();
     }
 

@@ -1817,17 +1819,17 @@
             l = genExpr(tree.lhs, tree.lhs.type);
 
             // If we have an increment of -32768 to +32767 of a local
             // int variable we can use an incr instruction instead of
             // proceeding further.
-            if ((tree.getTag() == JCTree.PLUS_ASG || tree.getTag() == JCTree.MINUS_ASG) &&
+            if ((tree.hasTag(PLUS_ASG) || tree.hasTag(MINUS_ASG)) &&
                 l instanceof LocalItem &&
                 tree.lhs.type.tag <= INT &&
                 tree.rhs.type.tag <= INT &&
                 tree.rhs.type.constValue() != null) {
                 int ival = ((Number) tree.rhs.type.constValue()).intValue();
-                if (tree.getTag() == JCTree.MINUS_ASG) ival = -ival;
+                if (tree.hasTag(MINUS_ASG)) ival = -ival;
                 ((LocalItem)l).incr(ival);
                 result = l;
                 return;
             }
             // Otherwise, duplicate expression, load one copy

@@ -1839,33 +1841,33 @@
         result = items.makeAssignItem(l);
     }
 
     public void visitUnary(JCUnary tree) {
         OperatorSymbol operator = (OperatorSymbol)tree.operator;
-        if (tree.getTag() == JCTree.NOT) {
+        if (tree.hasTag(NOT)) {
             CondItem od = genCond(tree.arg, false);
             result = od.negate();
         } else {
             Item od = genExpr(tree.arg, operator.type.getParameterTypes().head);
             switch (tree.getTag()) {
-            case JCTree.POS:
+            case POS:
                 result = od.load();
                 break;
-            case JCTree.NEG:
+            case NEG:
                 result = od.load();
                 code.emitop0(operator.opcode);
                 break;
-            case JCTree.COMPL:
+            case COMPL:
                 result = od.load();
                 emitMinusOne(od.typecode);
                 code.emitop0(operator.opcode);
                 break;
-            case JCTree.PREINC: case JCTree.PREDEC:
+            case PREINC: case PREDEC:
                 od.duplicate();
                 if (od instanceof LocalItem &&
                     (operator.opcode == iadd || operator.opcode == isub)) {
-                    ((LocalItem)od).incr(tree.getTag() == JCTree.PREINC ? 1 : -1);
+                    ((LocalItem)od).incr(tree.hasTag(PREINC) ? 1 : -1);
                     result = od;
                 } else {
                     od.load();
                     code.emitop0(one(od.typecode));
                     code.emitop0(operator.opcode);

@@ -1875,16 +1877,16 @@
                         Code.truncate(od.typecode) == INTcode)
                       code.emitop0(int2byte + od.typecode - BYTEcode);
                     result = items.makeAssignItem(od);
                 }
                 break;
-            case JCTree.POSTINC: case JCTree.POSTDEC:
+            case POSTINC: case POSTDEC:
                 od.duplicate();
                 if (od instanceof LocalItem &&
                     (operator.opcode == iadd || operator.opcode == isub)) {
                     Item res = od.load();
-                    ((LocalItem)od).incr(tree.getTag() == JCTree.POSTINC ? 1 : -1);
+                    ((LocalItem)od).incr(tree.hasTag(POSTINC) ? 1 : -1);
                     result = res;
                 } else {
                     Item res = od.load();
                     od.stash(od.typecode);
                     code.emitop0(one(od.typecode));

@@ -1896,11 +1898,11 @@
                       code.emitop0(int2byte + od.typecode - BYTEcode);
                     od.store();
                     result = res;
                 }
                 break;
-            case JCTree.NULLCHK:
+            case NULLCHK:
                 result = od.load();
                 code.emitop0(dup);
                 genNullCheck(tree.pos());
                 break;
             default:

@@ -1924,11 +1926,11 @@
             // Append all strings to buffer.
             appendStrings(tree);
             // Convert buffer to string.
             bufferToString(tree.pos());
             result = items.makeStackItem(syms.stringType);
-        } else if (tree.getTag() == JCTree.AND) {
+        } else if (tree.hasTag(AND)) {
             CondItem lcond = genCond(tree.lhs, CRT_FLOW_CONTROLLER);
             if (!lcond.isFalse()) {
                 Chain falseJumps = lcond.jumpFalse();
                 code.resolve(lcond.trueJumps);
                 CondItem rcond = genCond(tree.rhs, CRT_FLOW_TARGET);

@@ -1938,11 +1940,11 @@
                                  Code.mergeChains(falseJumps,
                                                   rcond.falseJumps));
             } else {
                 result = lcond;
             }
-        } else if (tree.getTag() == JCTree.OR) {
+        } else if (tree.hasTag(OR)) {
             CondItem lcond = genCond(tree.lhs, CRT_FLOW_CONTROLLER);
             if (!lcond.isTrue()) {
                 Chain trueJumps = lcond.jumpTrue();
                 code.resolve(lcond.falseJumps);
                 CondItem rcond = genCond(tree.rhs, CRT_FLOW_TARGET);

@@ -1995,11 +1997,11 @@
 
         /** Add all strings in tree to string buffer.
          */
         void appendStrings(JCTree tree) {
             tree = TreeInfo.skipParens(tree);
-            if (tree.getTag() == JCTree.PLUS && tree.type.constValue() == null) {
+            if (tree.hasTag(PLUS) && tree.type.constValue() == null) {
                 JCBinary op = (JCBinary) tree;
                 if (op.operator.kind == MTH &&
                     ((OperatorSymbol) op.operator).opcode == string_add) {
                     appendStrings(op.lhs);
                     appendStrings(op.rhs);

@@ -2238,11 +2240,11 @@
                 nerrs++;
             }
             if (nerrs != 0) {
                 // if errors, discard code
                 for (List<JCTree> l = cdef.defs; l.nonEmpty(); l = l.tail) {
-                    if (l.head.getTag() == JCTree.METHODDEF)
+                    if (l.head.hasTag(METHODDEF))
                         ((JCMethodDecl) l.head).sym.code = null;
                 }
             }
             cdef.defs = List.nil(); // discard trees
             return nerrs == 0;