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

changeset 1138
7375d4979bd3
parent 1127
ca49d50318dc
child 1157
3809292620c9
equal deleted inserted replaced
1137:c1238fcc9515 1138:7375d4979bd3
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 28
29 import javax.lang.model.element.ElementKind;
30
31 import com.sun.tools.javac.util.*; 29 import com.sun.tools.javac.util.*;
32 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 30 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
33 import com.sun.tools.javac.util.List; 31 import com.sun.tools.javac.util.List;
34 import com.sun.tools.javac.code.*; 32 import com.sun.tools.javac.code.*;
35 import com.sun.tools.javac.comp.*; 33 import com.sun.tools.javac.comp.*;
37 35
38 import com.sun.tools.javac.code.Symbol.*; 36 import com.sun.tools.javac.code.Symbol.*;
39 import com.sun.tools.javac.code.Type.*; 37 import com.sun.tools.javac.code.Type.*;
40 import com.sun.tools.javac.jvm.Code.*; 38 import com.sun.tools.javac.jvm.Code.*;
41 import com.sun.tools.javac.jvm.Items.*; 39 import com.sun.tools.javac.jvm.Items.*;
40 import com.sun.tools.javac.parser.EndPosTable;
42 import com.sun.tools.javac.tree.JCTree.*; 41 import com.sun.tools.javac.tree.JCTree.*;
43 42
44 import static com.sun.tools.javac.code.Flags.*; 43 import static com.sun.tools.javac.code.Flags.*;
45 import static com.sun.tools.javac.code.Kinds.*; 44 import static com.sun.tools.javac.code.Kinds.*;
46 import static com.sun.tools.javac.code.TypeTags.*; 45 import static com.sun.tools.javac.code.TypeTags.*;
195 194
196 /** The number of code-gen errors in this class. 195 /** The number of code-gen errors in this class.
197 */ 196 */
198 private int nerrs = 0; 197 private int nerrs = 0;
199 198
200 /** A hash table mapping syntax trees to their ending source positions. 199 /** An object containing mappings of syntax trees to their
201 */ 200 * ending source positions.
202 private Map<JCTree, Integer> endPositions; 201 */
202 EndPosTable endPosTable;
203 203
204 /** Generate code to load an integer constant. 204 /** Generate code to load an integer constant.
205 * @param n The integer to be loaded. 205 * @param n The integer to be loaded.
206 */ 206 */
207 void loadIntConst(int n) { 207 void loadIntConst(int n) {
480 if ((sym.flags() & STATIC) == 0) { 480 if ((sym.flags() & STATIC) == 0) {
481 // Always initialize instance variables. 481 // Always initialize instance variables.
482 JCStatement init = make.at(vdef.pos()). 482 JCStatement init = make.at(vdef.pos()).
483 Assignment(sym, vdef.init); 483 Assignment(sym, vdef.init);
484 initCode.append(init); 484 initCode.append(init);
485 if (endPositions != null) { 485 endPosTable.replaceTree(vdef, init);
486 Integer endPos = endPositions.remove(vdef);
487 if (endPos != null) endPositions.put(init, endPos);
488 }
489 } else if (sym.getConstValue() == null) { 486 } else if (sym.getConstValue() == null) {
490 // Initialize class (static) variables only if 487 // Initialize class (static) variables only if
491 // they are not compile-time constants. 488 // they are not compile-time constants.
492 JCStatement init = make.at(vdef.pos). 489 JCStatement init = make.at(vdef.pos).
493 Assignment(sym, vdef.init); 490 Assignment(sym, vdef.init);
494 clinitCode.append(init); 491 clinitCode.append(init);
495 if (endPositions != null) { 492 endPosTable.replaceTree(vdef, init);
496 Integer endPos = endPositions.remove(vdef);
497 if (endPos != null) endPositions.put(init, endPos);
498 }
499 } else { 493 } else {
500 checkStringConstant(vdef.init.pos(), sym.getConstValue()); 494 checkStringConstant(vdef.init.pos(), sym.getConstValue());
501 } 495 }
502 } 496 }
503 break; 497 break;
2215 public boolean genClass(Env<AttrContext> env, JCClassDecl cdef) { 2209 public boolean genClass(Env<AttrContext> env, JCClassDecl cdef) {
2216 try { 2210 try {
2217 attrEnv = env; 2211 attrEnv = env;
2218 ClassSymbol c = cdef.sym; 2212 ClassSymbol c = cdef.sym;
2219 this.toplevel = env.toplevel; 2213 this.toplevel = env.toplevel;
2220 this.endPositions = toplevel.endPositions; 2214 this.endPosTable = toplevel.endPositions;
2221 // If this is a class definition requiring Miranda methods, 2215 // If this is a class definition requiring Miranda methods,
2222 // add them. 2216 // add them.
2223 if (generateIproxies && 2217 if (generateIproxies &&
2224 (c.flags() & (INTERFACE|ABSTRACT)) == ABSTRACT 2218 (c.flags() & (INTERFACE|ABSTRACT)) == ABSTRACT
2225 && !allowGenerics // no Miranda methods available with generics 2219 && !allowGenerics // no Miranda methods available with generics
2251 } finally { 2245 } finally {
2252 // note: this method does NOT support recursion. 2246 // note: this method does NOT support recursion.
2253 attrEnv = null; 2247 attrEnv = null;
2254 this.env = null; 2248 this.env = null;
2255 toplevel = null; 2249 toplevel = null;
2256 endPositions = null; 2250 endPosTable = null;
2257 nerrs = 0; 2251 nerrs = 0;
2258 } 2252 }
2259 } 2253 }
2260 2254
2261 /* ************************************************************************ 2255 /* ************************************************************************

mercurial