< prev index next >

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

Print this page




  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  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.tree.TreeInfo.PosKind;
  29 import com.sun.tools.javac.util.*;
  30 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
  31 import com.sun.tools.javac.util.List;
  32 import com.sun.tools.javac.code.*;

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


2316 
2317 /* ************************************************************************
2318  * main method
2319  *************************************************************************/
2320 
2321     /** Generate code for a class definition.
2322      *  @param env   The attribution environment that belongs to the
2323      *               outermost class containing this class definition.
2324      *               We need this for resolving some additional symbols.
2325      *  @param cdef  The tree representing the class definition.
2326      *  @return      True if code is generated with no errors.
2327      */
2328     public boolean genClass(Env<AttrContext> env, JCClassDecl cdef) {
2329         try {
2330             attrEnv = env;
2331             ClassSymbol c = cdef.sym;
2332             this.toplevel = env.toplevel;
2333             this.endPosTable = toplevel.endPositions;
2334             c.pool = pool;
2335             pool.reset();







2336             /* method normalizeDefs() can add references to external classes into the constant pool
2337              */
2338             cdef.defs = normalizeDefs(cdef.defs, c);
2339             generateReferencesToPrunedTree(c, pool);
2340             Env<GenContext> localEnv = new Env<>(cdef, new GenContext());
2341             localEnv.toplevel = env.toplevel;
2342             localEnv.enclClass = cdef;
2343 
2344             for (List<JCTree> l = cdef.defs; l.nonEmpty(); l = l.tail) {
2345                 genDef(l.head, localEnv);
2346             }
2347             if (pool.numEntries() > Pool.MAX_ENTRIES) {
2348                 log.error(cdef.pos(), Errors.LimitPool);
2349                 nerrs++;
2350             }
2351             if (nerrs != 0) {
2352                 // if errors, discard code
2353                 for (List<JCTree> l = cdef.defs; l.nonEmpty(); l = l.tail) {
2354                     if (l.head.hasTag(METHODDEF))
2355                         ((JCMethodDecl) l.head).sym.code = null;




  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  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.tree.TreeInfo.PosKind;
  29 import com.sun.tools.javac.util.*;
  30 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
  31 import com.sun.tools.javac.util.List;
  32 import com.sun.tools.javac.code.*;
  33 import com.sun.tools.javac.code.Attribute.Compound;
  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.*;


2317 
2318 /* ************************************************************************
2319  * main method
2320  *************************************************************************/
2321 
2322     /** Generate code for a class definition.
2323      *  @param env   The attribution environment that belongs to the
2324      *               outermost class containing this class definition.
2325      *               We need this for resolving some additional symbols.
2326      *  @param cdef  The tree representing the class definition.
2327      *  @return      True if code is generated with no errors.
2328      */
2329     public boolean genClass(Env<AttrContext> env, JCClassDecl cdef) {
2330         try {
2331             attrEnv = env;
2332             ClassSymbol c = cdef.sym;
2333             this.toplevel = env.toplevel;
2334             this.endPosTable = toplevel.endPositions;
2335             c.pool = pool;
2336             pool.reset();
2337             if (c.isRecord()) {
2338                 Attribute.Compound attribute = c.attribute(syms.dataAnnotationType.tsym);
2339                 if (attribute == null) {
2340                     attribute = new Attribute.Compound(syms.dataAnnotationType, List.nil());
2341                     c.appendAttributes(List.of(attribute));
2342                 }
2343             }
2344             /* method normalizeDefs() can add references to external classes into the constant pool
2345              */
2346             cdef.defs = normalizeDefs(cdef.defs, c);
2347             generateReferencesToPrunedTree(c, pool);
2348             Env<GenContext> localEnv = new Env<>(cdef, new GenContext());
2349             localEnv.toplevel = env.toplevel;
2350             localEnv.enclClass = cdef;
2351 
2352             for (List<JCTree> l = cdef.defs; l.nonEmpty(); l = l.tail) {
2353                 genDef(l.head, localEnv);
2354             }
2355             if (pool.numEntries() > Pool.MAX_ENTRIES) {
2356                 log.error(cdef.pos(), Errors.LimitPool);
2357                 nerrs++;
2358             }
2359             if (nerrs != 0) {
2360                 // if errors, discard code
2361                 for (List<JCTree> l = cdef.defs; l.nonEmpty(); l = l.tail) {
2362                     if (l.head.hasTag(METHODDEF))
2363                         ((JCMethodDecl) l.head).sym.code = null;


< prev index next >