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

changeset 308
03944ee4fac4
parent 267
e2722bd43f3a
child 310
7c154fdc3547
equal deleted inserted replaced
307:ca063536e4a6 308:03944ee4fac4
23 * have any questions. 23 * have any questions.
24 */ 24 */
25 25
26 package com.sun.tools.javac.jvm; 26 package com.sun.tools.javac.jvm;
27 import java.util.*; 27 import java.util.*;
28
29 import javax.lang.model.element.ElementKind;
28 30
29 import com.sun.tools.javac.util.*; 31 import com.sun.tools.javac.util.*;
30 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 32 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
31 import com.sun.tools.javac.util.List; 33 import com.sun.tools.javac.util.List;
32 import com.sun.tools.javac.code.*; 34 import com.sun.tools.javac.code.*;
937 code.crt.put(tree.body, 939 code.crt.put(tree.body,
938 CRT_BLOCK, 940 CRT_BLOCK,
939 startpcCrt, 941 startpcCrt,
940 code.curPc()); 942 code.curPc());
941 943
942 // End the scope of all local variables in variable info.
943 code.endScopes(0); 944 code.endScopes(0);
944 945
945 // If we exceeded limits, panic 946 // If we exceeded limits, panic
946 if (code.checkLimits(tree.pos(), log)) { 947 if (code.checkLimits(tree.pos(), log)) {
947 nerrs++; 948 nerrs++;
1437 } 1438 }
1438 1439
1439 // Resolve all breaks. 1440 // Resolve all breaks.
1440 code.resolve(exitChain); 1441 code.resolve(exitChain);
1441 1442
1442 // End the scopes of all try-local variables in variable info.
1443 code.endScopes(limit); 1443 code.endScopes(limit);
1444 } 1444 }
1445 1445
1446 /** Generate code for a catch clause. 1446 /** Generate code for a catch clause.
1447 * @param tree The catch clause. 1447 * @param tree The catch clause.
1670 /* ************************************************************************ 1670 /* ************************************************************************
1671 * Visitor methods for expressions 1671 * Visitor methods for expressions
1672 *************************************************************************/ 1672 *************************************************************************/
1673 1673
1674 public void visitApply(JCMethodInvocation tree) { 1674 public void visitApply(JCMethodInvocation tree) {
1675 setTypeAnnotationPositions(tree.pos);
1675 // Generate code for method. 1676 // Generate code for method.
1676 Item m = genExpr(tree.meth, methodType); 1677 Item m = genExpr(tree.meth, methodType);
1677 // Generate code for all arguments, where the expected types are 1678 // Generate code for all arguments, where the expected types are
1678 // the parameters of the method's external type (that is, any implicit 1679 // the parameters of the method's external type (that is, any implicit
1679 // outer instance of a super(...) call appears as first parameter). 1680 // outer instance of a super(...) call appears as first parameter).
1705 } 1706 }
1706 code.resolve(thenExit); 1707 code.resolve(thenExit);
1707 result = items.makeStackItem(pt); 1708 result = items.makeStackItem(pt);
1708 } 1709 }
1709 1710
1711 private void setTypeAnnotationPositions(int treePos) {
1712 MethodSymbol meth = code.meth;
1713
1714 for (Attribute.TypeCompound ta : meth.typeAnnotations) {
1715 if (ta.position.pos == treePos) {
1716 ta.position.offset = code.cp;
1717 ta.position.lvarOffset[0] = code.cp;
1718 }
1719 }
1720
1721 if (code.meth.getKind() != ElementKind.CONSTRUCTOR
1722 && code.meth.getKind() != ElementKind.STATIC_INIT)
1723 return;
1724
1725 for (Attribute.TypeCompound ta : meth.owner.typeAnnotations) {
1726 if (ta.position.pos == treePos) {
1727 ta.position.offset = code.cp;
1728 ta.position.lvarOffset[0] = code.cp;
1729 }
1730 }
1731
1732 ClassSymbol clazz = meth.enclClass();
1733 for (Symbol s : new com.sun.tools.javac.model.FilteredMemberList(clazz.members())) {
1734 if (!s.getKind().isField())
1735 continue;
1736 for (Attribute.TypeCompound ta : s.typeAnnotations) {
1737 if (ta.position.pos == treePos) {
1738 ta.position.offset = code.cp;
1739 ta.position.lvarOffset[0] = code.cp;
1740 }
1741 }
1742 }
1743 }
1744
1710 public void visitNewClass(JCNewClass tree) { 1745 public void visitNewClass(JCNewClass tree) {
1711 // Enclosing instances or anonymous classes should have been eliminated 1746 // Enclosing instances or anonymous classes should have been eliminated
1712 // by now. 1747 // by now.
1713 assert tree.encl == null && tree.def == null; 1748 assert tree.encl == null && tree.def == null;
1749 setTypeAnnotationPositions(tree.pos);
1714 1750
1715 code.emitop2(new_, makeRef(tree.pos(), tree.type)); 1751 code.emitop2(new_, makeRef(tree.pos(), tree.type));
1716 code.emitop0(dup); 1752 code.emitop0(dup);
1717 1753
1718 // Generate code for all arguments, where the expected types are 1754 // Generate code for all arguments, where the expected types are
1723 items.makeMemberItem(tree.constructor, true).invoke(); 1759 items.makeMemberItem(tree.constructor, true).invoke();
1724 result = items.makeStackItem(tree.type); 1760 result = items.makeStackItem(tree.type);
1725 } 1761 }
1726 1762
1727 public void visitNewArray(JCNewArray tree) { 1763 public void visitNewArray(JCNewArray tree) {
1764 setTypeAnnotationPositions(tree.pos);
1765
1728 if (tree.elems != null) { 1766 if (tree.elems != null) {
1729 Type elemtype = types.elemtype(tree.type); 1767 Type elemtype = types.elemtype(tree.type);
1730 loadIntConst(tree.elems.length()); 1768 loadIntConst(tree.elems.length());
1731 Item arr = makeNewArray(tree.pos(), tree.type, 1); 1769 Item arr = makeNewArray(tree.pos(), tree.type, 1);
1732 int i = 0; 1770 int i = 0;
2051 return items.makeStackItem(optype.restype); 2089 return items.makeStackItem(optype.restype);
2052 } 2090 }
2053 } 2091 }
2054 2092
2055 public void visitTypeCast(JCTypeCast tree) { 2093 public void visitTypeCast(JCTypeCast tree) {
2094 setTypeAnnotationPositions(tree.pos);
2056 result = genExpr(tree.expr, tree.clazz.type).load(); 2095 result = genExpr(tree.expr, tree.clazz.type).load();
2057 // Additional code is only needed if we cast to a reference type 2096 // Additional code is only needed if we cast to a reference type
2058 // which is not statically a supertype of the expression's type. 2097 // which is not statically a supertype of the expression's type.
2059 // For basic types, the coerce(...) in genExpr(...) will do 2098 // For basic types, the coerce(...) in genExpr(...) will do
2060 // the conversion. 2099 // the conversion.
2067 public void visitWildcard(JCWildcard tree) { 2106 public void visitWildcard(JCWildcard tree) {
2068 throw new AssertionError(this.getClass().getName()); 2107 throw new AssertionError(this.getClass().getName());
2069 } 2108 }
2070 2109
2071 public void visitTypeTest(JCInstanceOf tree) { 2110 public void visitTypeTest(JCInstanceOf tree) {
2111 setTypeAnnotationPositions(tree.pos);
2112
2072 genExpr(tree.expr, tree.expr.type).load(); 2113 genExpr(tree.expr, tree.expr.type).load();
2073 code.emitop2(instanceof_, makeRef(tree.pos(), tree.clazz.type)); 2114 code.emitop2(instanceof_, makeRef(tree.pos(), tree.clazz.type));
2074 result = items.makeStackItem(syms.booleanType); 2115 result = items.makeStackItem(syms.booleanType);
2075 } 2116 }
2076 2117
2108 public void visitSelect(JCFieldAccess tree) { 2149 public void visitSelect(JCFieldAccess tree) {
2109 Symbol sym = tree.sym; 2150 Symbol sym = tree.sym;
2110 2151
2111 if (tree.name == names._class) { 2152 if (tree.name == names._class) {
2112 assert target.hasClassLiterals(); 2153 assert target.hasClassLiterals();
2154 setTypeAnnotationPositions(tree.pos);
2113 code.emitop2(ldc2, makeRef(tree.pos(), tree.selected.type)); 2155 code.emitop2(ldc2, makeRef(tree.pos(), tree.selected.type));
2114 result = items.makeStackItem(pt); 2156 result = items.makeStackItem(pt);
2115 return; 2157 return;
2116 } 2158 }
2117 2159

mercurial