57 * If you write code that depends on this, you do so at your own risk. |
57 * If you write code that depends on this, you do so at your own risk. |
58 * This code and its internal interfaces are subject to change or |
58 * This code and its internal interfaces are subject to change or |
59 * deletion without notice.</b> |
59 * deletion without notice.</b> |
60 */ |
60 */ |
61 public class Gen extends JCTree.Visitor { |
61 public class Gen extends JCTree.Visitor { |
62 protected static final Context.Key<Gen> genKey = |
62 protected static final Context.Key<Gen> genKey = new Context.Key<>(); |
63 new Context.Key<Gen>(); |
|
64 |
63 |
65 private final Log log; |
64 private final Log log; |
66 private final Symtab syms; |
65 private final Symtab syms; |
67 private final Check chk; |
66 private final Check chk; |
68 private final Resolve rs; |
67 private final Resolve rs; |
120 methodType = new MethodType(null, null, null, syms.methodClass); |
119 methodType = new MethodType(null, null, null, syms.methodClass); |
121 allowGenerics = Source.instance(context).allowGenerics(); |
120 allowGenerics = Source.instance(context).allowGenerics(); |
122 stringBufferType = target.useStringBuilder() |
121 stringBufferType = target.useStringBuilder() |
123 ? syms.stringBuilderType |
122 ? syms.stringBuilderType |
124 : syms.stringBufferType; |
123 : syms.stringBufferType; |
125 stringBufferAppend = new HashMap<Type,Symbol>(); |
124 stringBufferAppend = new HashMap<>(); |
126 accessDollar = names. |
125 accessDollar = names. |
127 fromString("access" + target.syntheticNameChar()); |
126 fromString("access" + target.syntheticNameChar()); |
128 lower = Lower.instance(context); |
127 lower = Lower.instance(context); |
129 |
128 |
130 Options options = Options.instance(context); |
129 Options options = Options.instance(context); |
473 * method. |
472 * method. |
474 * @param defs The list of class member declarations. |
473 * @param defs The list of class member declarations. |
475 * @param c The enclosing class. |
474 * @param c The enclosing class. |
476 */ |
475 */ |
477 List<JCTree> normalizeDefs(List<JCTree> defs, ClassSymbol c) { |
476 List<JCTree> normalizeDefs(List<JCTree> defs, ClassSymbol c) { |
478 ListBuffer<JCStatement> initCode = new ListBuffer<JCStatement>(); |
477 ListBuffer<JCStatement> initCode = new ListBuffer<>(); |
479 ListBuffer<Attribute.TypeCompound> initTAs = new ListBuffer<Attribute.TypeCompound>(); |
478 ListBuffer<Attribute.TypeCompound> initTAs = new ListBuffer<>(); |
480 ListBuffer<JCStatement> clinitCode = new ListBuffer<JCStatement>(); |
479 ListBuffer<JCStatement> clinitCode = new ListBuffer<>(); |
481 ListBuffer<Attribute.TypeCompound> clinitTAs = new ListBuffer<Attribute.TypeCompound>(); |
480 ListBuffer<Attribute.TypeCompound> clinitTAs = new ListBuffer<>(); |
482 ListBuffer<JCTree> methodDefs = new ListBuffer<JCTree>(); |
481 ListBuffer<JCTree> methodDefs = new ListBuffer<>(); |
483 // Sort definitions into three listbuffers: |
482 // Sort definitions into three listbuffers: |
484 // - initCode for instance initializers |
483 // - initCode for instance initializers |
485 // - clinitCode for class initializers |
484 // - clinitCode for class initializers |
486 // - methodDefs for method definitions |
485 // - methodDefs for method definitions |
487 for (List<JCTree> l = defs; l.nonEmpty(); l = l.tail) { |
486 for (List<JCTree> l = defs; l.nonEmpty(); l = l.tail) { |
560 return methodDefs.toList(); |
559 return methodDefs.toList(); |
561 } |
560 } |
562 |
561 |
563 private List<Attribute.TypeCompound> getAndRemoveNonFieldTAs(VarSymbol sym) { |
562 private List<Attribute.TypeCompound> getAndRemoveNonFieldTAs(VarSymbol sym) { |
564 List<TypeCompound> tas = sym.getRawTypeAttributes(); |
563 List<TypeCompound> tas = sym.getRawTypeAttributes(); |
565 ListBuffer<Attribute.TypeCompound> fieldTAs = new ListBuffer<Attribute.TypeCompound>(); |
564 ListBuffer<Attribute.TypeCompound> fieldTAs = new ListBuffer<>(); |
566 ListBuffer<Attribute.TypeCompound> nonfieldTAs = new ListBuffer<Attribute.TypeCompound>(); |
565 ListBuffer<Attribute.TypeCompound> nonfieldTAs = new ListBuffer<>(); |
567 for (TypeCompound ta : tas) { |
566 for (TypeCompound ta : tas) { |
568 if (ta.getPosition().type == TargetType.FIELD) { |
567 if (ta.getPosition().type == TargetType.FIELD) { |
569 fieldTAs.add(ta); |
568 fieldTAs.add(ta); |
570 } else { |
569 } else { |
571 if (typeAnnoAsserts) { |
570 if (typeAnnoAsserts) { |
601 void normalizeMethod(JCMethodDecl md, List<JCStatement> initCode, List<TypeCompound> initTAs) { |
600 void normalizeMethod(JCMethodDecl md, List<JCStatement> initCode, List<TypeCompound> initTAs) { |
602 if (md.name == names.init && TreeInfo.isInitialConstructor(md)) { |
601 if (md.name == names.init && TreeInfo.isInitialConstructor(md)) { |
603 // We are seeing a constructor that does not call another |
602 // We are seeing a constructor that does not call another |
604 // constructor of the same class. |
603 // constructor of the same class. |
605 List<JCStatement> stats = md.body.stats; |
604 List<JCStatement> stats = md.body.stats; |
606 ListBuffer<JCStatement> newstats = new ListBuffer<JCStatement>(); |
605 ListBuffer<JCStatement> newstats = new ListBuffer<>(); |
607 |
606 |
608 if (stats.nonEmpty()) { |
607 if (stats.nonEmpty()) { |
609 // Copy initializers of synthetic variables generated in |
608 // Copy initializers of synthetic variables generated in |
610 // the translation of inner classes. |
609 // the translation of inner classes. |
611 while (TreeInfo.isSyntheticInit(stats.head)) { |
610 while (TreeInfo.isSyntheticInit(stats.head)) { |
1483 code.emitop0(monitorexit); |
1482 code.emitop0(monitorexit); |
1484 code.state.unlock(lockVar.reg); |
1483 code.state.unlock(lockVar.reg); |
1485 } |
1484 } |
1486 } |
1485 } |
1487 }; |
1486 }; |
1488 syncEnv.info.gaps = new ListBuffer<Integer>(); |
1487 syncEnv.info.gaps = new ListBuffer<>(); |
1489 genTry(tree.body, List.<JCCatch>nil(), syncEnv); |
1488 genTry(tree.body, List.<JCCatch>nil(), syncEnv); |
1490 code.endScopes(limit); |
1489 code.endScopes(limit); |
1491 } |
1490 } |
1492 |
1491 |
1493 public void visitTry(final JCTry tree) { |
1492 public void visitTry(final JCTry tree) { |
1527 } |
1526 } |
1528 boolean hasFinalizer() { |
1527 boolean hasFinalizer() { |
1529 return tree.finalizer != null; |
1528 return tree.finalizer != null; |
1530 } |
1529 } |
1531 }; |
1530 }; |
1532 tryEnv.info.gaps = new ListBuffer<Integer>(); |
1531 tryEnv.info.gaps = new ListBuffer<>(); |
1533 genTry(tree.body, tree.catchers, tryEnv); |
1532 genTry(tree.body, tree.catchers, tryEnv); |
1534 } |
1533 } |
1535 //where |
1534 //where |
1536 /** Generate code for a try or synchronized statement |
1535 /** Generate code for a try or synchronized statement |
1537 * @param body The body of the try or synchronized statement. |
1536 * @param body The body of the try or synchronized statement. |
2503 implementInterfaceMethods(c); |
2502 implementInterfaceMethods(c); |
2504 cdef.defs = normalizeDefs(cdef.defs, c); |
2503 cdef.defs = normalizeDefs(cdef.defs, c); |
2505 c.pool = pool; |
2504 c.pool = pool; |
2506 pool.reset(); |
2505 pool.reset(); |
2507 generateReferencesToPrunedTree(c, pool); |
2506 generateReferencesToPrunedTree(c, pool); |
2508 Env<GenContext> localEnv = |
2507 Env<GenContext> localEnv = new Env<>(cdef, new GenContext()); |
2509 new Env<GenContext>(cdef, new GenContext()); |
|
2510 localEnv.toplevel = env.toplevel; |
2508 localEnv.toplevel = env.toplevel; |
2511 localEnv.enclClass = cdef; |
2509 localEnv.enclClass = cdef; |
2512 |
2510 |
2513 /* We must not analyze synthetic methods |
2511 /* We must not analyze synthetic methods |
2514 */ |
2512 */ |