< prev index next >

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

Print this page




  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.jvm;
  27 
  28 import com.sun.tools.javac.jvm.PoolConstant.LoadableConstant;
  29 import com.sun.tools.javac.tree.TreeInfo.PosKind;
  30 import com.sun.tools.javac.util.*;
  31 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
  32 import com.sun.tools.javac.util.List;
  33 import com.sun.tools.javac.code.*;

  34 import com.sun.tools.javac.code.Attribute.TypeCompound;
  35 import com.sun.tools.javac.code.Symbol.VarSymbol;
  36 import com.sun.tools.javac.comp.*;
  37 import com.sun.tools.javac.tree.*;
  38 
  39 import com.sun.tools.javac.code.Symbol.*;
  40 import com.sun.tools.javac.code.Type.*;
  41 import com.sun.tools.javac.jvm.Code.*;
  42 import com.sun.tools.javac.jvm.Items.*;
  43 import com.sun.tools.javac.resources.CompilerProperties.Errors;
  44 import com.sun.tools.javac.tree.EndPosTable;
  45 import com.sun.tools.javac.tree.JCTree.*;
  46 
  47 import static com.sun.tools.javac.code.Flags.*;
  48 import static com.sun.tools.javac.code.Kinds.Kind.*;
  49 import static com.sun.tools.javac.code.TypeTag.*;
  50 import static com.sun.tools.javac.jvm.ByteCodes.*;
  51 import static com.sun.tools.javac.jvm.CRTFlags.*;
  52 import static com.sun.tools.javac.main.Option.*;
  53 import static com.sun.tools.javac.tree.JCTree.Tag.*;


2199         result = genExpr(tree.expr, tree.clazz.type).load();
2200         setTypeAnnotationPositions(tree.pos);
2201         // Additional code is only needed if we cast to a reference type
2202         // which is not statically a supertype of the expression's type.
2203         // For basic types, the coerce(...) in genExpr(...) will do
2204         // the conversion.
2205         if (!tree.clazz.type.isPrimitive() &&
2206            !types.isSameType(tree.expr.type, tree.clazz.type) &&
2207            types.asSuper(tree.expr.type, tree.clazz.type.tsym) == null) {
2208             code.emitop2(checkcast, checkDimension(tree.pos(), tree.clazz.type), PoolWriter::putClass);
2209         }
2210     }
2211 
2212     public void visitWildcard(JCWildcard tree) {
2213         throw new AssertionError(this.getClass().getName());
2214     }
2215 
2216     public void visitTypeTest(JCInstanceOf tree) {
2217         genExpr(tree.expr, tree.expr.type).load();
2218         setTypeAnnotationPositions(tree.pos);
2219         code.emitop2(instanceof_, makeRef(tree.pos(), tree.clazz.type));
2220         result = items.makeStackItem(syms.booleanType);
2221     }
2222 
2223     public void visitIndexed(JCArrayAccess tree) {
2224         genExpr(tree.indexed, tree.indexed.type).load();
2225         genExpr(tree.index, syms.intType).load();
2226         result = items.makeIndexedItem(tree.type);
2227     }
2228 
2229     public void visitIdent(JCIdent tree) {
2230         Symbol sym = tree.sym;
2231         if (tree.name == names._this || tree.name == names._super) {
2232             Item res = tree.name == names._this
2233                 ? items.makeThisItem()
2234                 : items.makeSuperItem();
2235             if (sym.kind == MTH) {
2236                 // Generate code to address the constructor.
2237                 res.load();
2238                 res = items.makeMemberItem(sym, true);
2239             }




  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.jvm;
  27 
  28 import com.sun.tools.javac.jvm.PoolConstant.LoadableConstant;
  29 import com.sun.tools.javac.tree.TreeInfo.PosKind;
  30 import com.sun.tools.javac.util.*;
  31 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
  32 import com.sun.tools.javac.util.List;
  33 import com.sun.tools.javac.code.*;
  34 import com.sun.tools.javac.code.Attribute.Compound;
  35 import com.sun.tools.javac.code.Attribute.TypeCompound;
  36 import com.sun.tools.javac.code.Symbol.VarSymbol;
  37 import com.sun.tools.javac.comp.*;
  38 import com.sun.tools.javac.tree.*;
  39 
  40 import com.sun.tools.javac.code.Symbol.*;
  41 import com.sun.tools.javac.code.Type.*;
  42 import com.sun.tools.javac.jvm.Code.*;
  43 import com.sun.tools.javac.jvm.Items.*;
  44 import com.sun.tools.javac.resources.CompilerProperties.Errors;
  45 import com.sun.tools.javac.tree.EndPosTable;
  46 import com.sun.tools.javac.tree.JCTree.*;
  47 
  48 import static com.sun.tools.javac.code.Flags.*;
  49 import static com.sun.tools.javac.code.Kinds.Kind.*;
  50 import static com.sun.tools.javac.code.TypeTag.*;
  51 import static com.sun.tools.javac.jvm.ByteCodes.*;
  52 import static com.sun.tools.javac.jvm.CRTFlags.*;
  53 import static com.sun.tools.javac.main.Option.*;
  54 import static com.sun.tools.javac.tree.JCTree.Tag.*;


2200         result = genExpr(tree.expr, tree.clazz.type).load();
2201         setTypeAnnotationPositions(tree.pos);
2202         // Additional code is only needed if we cast to a reference type
2203         // which is not statically a supertype of the expression's type.
2204         // For basic types, the coerce(...) in genExpr(...) will do
2205         // the conversion.
2206         if (!tree.clazz.type.isPrimitive() &&
2207            !types.isSameType(tree.expr.type, tree.clazz.type) &&
2208            types.asSuper(tree.expr.type, tree.clazz.type.tsym) == null) {
2209             code.emitop2(checkcast, checkDimension(tree.pos(), tree.clazz.type), PoolWriter::putClass);
2210         }
2211     }
2212 
2213     public void visitWildcard(JCWildcard tree) {
2214         throw new AssertionError(this.getClass().getName());
2215     }
2216 
2217     public void visitTypeTest(JCInstanceOf tree) {
2218         genExpr(tree.expr, tree.expr.type).load();
2219         setTypeAnnotationPositions(tree.pos);
2220         code.emitop2(instanceof_, makeRef(tree.pos(), tree.pattern.type));
2221         result = items.makeStackItem(syms.booleanType);
2222     }
2223 
2224     public void visitIndexed(JCArrayAccess tree) {
2225         genExpr(tree.indexed, tree.indexed.type).load();
2226         genExpr(tree.index, syms.intType).load();
2227         result = items.makeIndexedItem(tree.type);
2228     }
2229 
2230     public void visitIdent(JCIdent tree) {
2231         Symbol sym = tree.sym;
2232         if (tree.name == names._this || tree.name == names._super) {
2233             Item res = tree.name == names._this
2234                 ? items.makeThisItem()
2235                 : items.makeSuperItem();
2236             if (sym.kind == MTH) {
2237                 // Generate code to address the constructor.
2238                 res.load();
2239                 res = items.makeMemberItem(sym, true);
2240             }


< prev index next >