1 /* |
1 /* |
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
1014 if(stackMap == StackMapFormat.JSR202) { |
1014 if(stackMap == StackMapFormat.JSR202) { |
1015 code.lastFrame = null; |
1015 code.lastFrame = null; |
1016 code.frameBeforeLast = null; |
1016 code.frameBeforeLast = null; |
1017 } |
1017 } |
1018 |
1018 |
1019 //compress exception table |
1019 // Compress exception table |
1020 code.compressCatchTable(); |
1020 code.compressCatchTable(); |
|
1021 |
|
1022 // Fill in type annotation positions for exception parameters |
|
1023 code.fillExceptionParameterPositions(); |
1021 } |
1024 } |
1022 } |
1025 } |
1023 |
1026 |
1024 private int initCode(JCMethodDecl tree, Env<GenContext> env, boolean fatcode) { |
1027 private int initCode(JCMethodDecl tree, Env<GenContext> env, boolean fatcode) { |
1025 MethodSymbol meth = tree.sym; |
1028 MethodSymbol meth = tree.sym; |
1736 /* ************************************************************************ |
1739 /* ************************************************************************ |
1737 * Visitor methods for expressions |
1740 * Visitor methods for expressions |
1738 *************************************************************************/ |
1741 *************************************************************************/ |
1739 |
1742 |
1740 public void visitApply(JCMethodInvocation tree) { |
1743 public void visitApply(JCMethodInvocation tree) { |
|
1744 setTypeAnnotationPositions(tree.pos); |
1741 // Generate code for method. |
1745 // Generate code for method. |
1742 Item m = genExpr(tree.meth, methodType); |
1746 Item m = genExpr(tree.meth, methodType); |
1743 // Generate code for all arguments, where the expected types are |
1747 // Generate code for all arguments, where the expected types are |
1744 // the parameters of the method's external type (that is, any implicit |
1748 // the parameters of the method's external type (that is, any implicit |
1745 // outer instance of a super(...) call appears as first parameter). |
1749 // outer instance of a super(...) call appears as first parameter). |
1773 } |
1777 } |
1774 code.resolve(thenExit); |
1778 code.resolve(thenExit); |
1775 result = items.makeStackItem(pt); |
1779 result = items.makeStackItem(pt); |
1776 } |
1780 } |
1777 |
1781 |
|
1782 private void setTypeAnnotationPositions(int treePos) { |
|
1783 MethodSymbol meth = code.meth; |
|
1784 |
|
1785 for (Attribute.TypeCompound ta : meth.getRawTypeAttributes()) { |
|
1786 if (ta.position.pos == treePos) { |
|
1787 ta.position.offset = code.cp; |
|
1788 ta.position.lvarOffset = new int[] { code.cp }; |
|
1789 ta.position.isValidOffset = true; |
|
1790 } |
|
1791 } |
|
1792 |
|
1793 if (code.meth.getKind() != javax.lang.model.element.ElementKind.CONSTRUCTOR |
|
1794 && code.meth.getKind() != javax.lang.model.element.ElementKind.STATIC_INIT) |
|
1795 return; |
|
1796 |
|
1797 for (Attribute.TypeCompound ta : meth.owner.getRawTypeAttributes()) { |
|
1798 if (ta.position.pos == treePos) { |
|
1799 ta.position.offset = code.cp; |
|
1800 ta.position.lvarOffset = new int[] { code.cp }; |
|
1801 ta.position.isValidOffset = true; |
|
1802 } |
|
1803 } |
|
1804 |
|
1805 ClassSymbol clazz = meth.enclClass(); |
|
1806 for (Symbol s : new com.sun.tools.javac.model.FilteredMemberList(clazz.members())) { |
|
1807 if (!s.getKind().isField()) |
|
1808 continue; |
|
1809 for (Attribute.TypeCompound ta : s.getRawTypeAttributes()) { |
|
1810 if (ta.position.pos == treePos) { |
|
1811 ta.position.offset = code.cp; |
|
1812 ta.position.lvarOffset = new int[] { code.cp }; |
|
1813 ta.position.isValidOffset = true; |
|
1814 } |
|
1815 } |
|
1816 } |
|
1817 } |
|
1818 |
1778 public void visitNewClass(JCNewClass tree) { |
1819 public void visitNewClass(JCNewClass tree) { |
1779 // Enclosing instances or anonymous classes should have been eliminated |
1820 // Enclosing instances or anonymous classes should have been eliminated |
1780 // by now. |
1821 // by now. |
1781 Assert.check(tree.encl == null && tree.def == null); |
1822 Assert.check(tree.encl == null && tree.def == null); |
|
1823 setTypeAnnotationPositions(tree.pos); |
1782 |
1824 |
1783 code.emitop2(new_, makeRef(tree.pos(), tree.type)); |
1825 code.emitop2(new_, makeRef(tree.pos(), tree.type)); |
1784 code.emitop0(dup); |
1826 code.emitop0(dup); |
1785 |
1827 |
1786 // Generate code for all arguments, where the expected types are |
1828 // Generate code for all arguments, where the expected types are |
1791 items.makeMemberItem(tree.constructor, true).invoke(); |
1833 items.makeMemberItem(tree.constructor, true).invoke(); |
1792 result = items.makeStackItem(tree.type); |
1834 result = items.makeStackItem(tree.type); |
1793 } |
1835 } |
1794 |
1836 |
1795 public void visitNewArray(JCNewArray tree) { |
1837 public void visitNewArray(JCNewArray tree) { |
|
1838 setTypeAnnotationPositions(tree.pos); |
1796 |
1839 |
1797 if (tree.elems != null) { |
1840 if (tree.elems != null) { |
1798 Type elemtype = types.elemtype(tree.type); |
1841 Type elemtype = types.elemtype(tree.type); |
1799 loadIntConst(tree.elems.length()); |
1842 loadIntConst(tree.elems.length()); |
1800 Item arr = makeNewArray(tree.pos(), tree.type, 1); |
1843 Item arr = makeNewArray(tree.pos(), tree.type, 1); |
2120 return items.makeStackItem(optype.restype); |
2163 return items.makeStackItem(optype.restype); |
2121 } |
2164 } |
2122 } |
2165 } |
2123 |
2166 |
2124 public void visitTypeCast(JCTypeCast tree) { |
2167 public void visitTypeCast(JCTypeCast tree) { |
|
2168 setTypeAnnotationPositions(tree.pos); |
2125 result = genExpr(tree.expr, tree.clazz.type).load(); |
2169 result = genExpr(tree.expr, tree.clazz.type).load(); |
2126 // Additional code is only needed if we cast to a reference type |
2170 // Additional code is only needed if we cast to a reference type |
2127 // which is not statically a supertype of the expression's type. |
2171 // which is not statically a supertype of the expression's type. |
2128 // For basic types, the coerce(...) in genExpr(...) will do |
2172 // For basic types, the coerce(...) in genExpr(...) will do |
2129 // the conversion. |
2173 // the conversion. |
2136 public void visitWildcard(JCWildcard tree) { |
2180 public void visitWildcard(JCWildcard tree) { |
2137 throw new AssertionError(this.getClass().getName()); |
2181 throw new AssertionError(this.getClass().getName()); |
2138 } |
2182 } |
2139 |
2183 |
2140 public void visitTypeTest(JCInstanceOf tree) { |
2184 public void visitTypeTest(JCInstanceOf tree) { |
|
2185 setTypeAnnotationPositions(tree.pos); |
2141 genExpr(tree.expr, tree.expr.type).load(); |
2186 genExpr(tree.expr, tree.expr.type).load(); |
2142 code.emitop2(instanceof_, makeRef(tree.pos(), tree.clazz.type)); |
2187 code.emitop2(instanceof_, makeRef(tree.pos(), tree.clazz.type)); |
2143 result = items.makeStackItem(syms.booleanType); |
2188 result = items.makeStackItem(syms.booleanType); |
2144 } |
2189 } |
2145 |
2190 |
2182 if (tree.name == names._class) { |
2227 if (tree.name == names._class) { |
2183 Assert.check(target.hasClassLiterals()); |
2228 Assert.check(target.hasClassLiterals()); |
2184 code.emitop2(ldc2, makeRef(tree.pos(), tree.selected.type)); |
2229 code.emitop2(ldc2, makeRef(tree.pos(), tree.selected.type)); |
2185 result = items.makeStackItem(pt); |
2230 result = items.makeStackItem(pt); |
2186 return; |
2231 return; |
2187 } |
2232 } |
2188 |
2233 |
2189 Symbol ssym = TreeInfo.symbol(tree.selected); |
2234 Symbol ssym = TreeInfo.symbol(tree.selected); |
2190 |
2235 |
2191 // Are we selecting via super? |
2236 // Are we selecting via super? |
2192 boolean selectSuper = |
2237 boolean selectSuper = |