23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 package com.sun.tools.javac.main; |
26 package com.sun.tools.javac.main; |
27 |
27 |
|
28 import com.sun.tools.javac.comp.CompileStates; |
28 import java.io.*; |
29 import java.io.*; |
29 import java.util.HashMap; |
30 import java.util.HashMap; |
30 import java.util.HashSet; |
31 import java.util.HashSet; |
31 import java.util.LinkedHashMap; |
32 import java.util.LinkedHashMap; |
32 import java.util.LinkedHashSet; |
33 import java.util.LinkedHashSet; |
59 import com.sun.tools.javac.parser.*; |
60 import com.sun.tools.javac.parser.*; |
60 import com.sun.tools.javac.processing.*; |
61 import com.sun.tools.javac.processing.*; |
61 import com.sun.tools.javac.tree.*; |
62 import com.sun.tools.javac.tree.*; |
62 import com.sun.tools.javac.tree.JCTree.*; |
63 import com.sun.tools.javac.tree.JCTree.*; |
63 import com.sun.tools.javac.util.*; |
64 import com.sun.tools.javac.util.*; |
|
65 import com.sun.tools.javac.comp.CompileStates.CompileState; |
64 import com.sun.tools.javac.util.Log.WriterKind; |
66 import com.sun.tools.javac.util.Log.WriterKind; |
65 |
67 |
66 import static com.sun.tools.javac.code.TypeTag.CLASS; |
68 import static com.sun.tools.javac.code.TypeTag.CLASS; |
67 import static com.sun.tools.javac.main.Option.*; |
69 import static com.sun.tools.javac.main.Option.*; |
68 import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*; |
70 import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*; |
324 /** |
326 /** |
325 * Flag set if any implicit source files read. |
327 * Flag set if any implicit source files read. |
326 **/ |
328 **/ |
327 protected boolean implicitSourceFilesRead; |
329 protected boolean implicitSourceFilesRead; |
328 |
330 |
|
331 protected CompileStates compileStates; |
|
332 |
329 /** Construct a new compiler using a shared context. |
333 /** Construct a new compiler using a shared context. |
330 */ |
334 */ |
331 public JavaCompiler(Context context) { |
335 public JavaCompiler(Context context) { |
332 this.context = context; |
336 this.context = context; |
333 context.put(compilerKey, this); |
337 context.put(compilerKey, this); |
346 enter = Enter.instance(context); |
350 enter = Enter.instance(context); |
347 todo = Todo.instance(context); |
351 todo = Todo.instance(context); |
348 |
352 |
349 fileManager = context.get(JavaFileManager.class); |
353 fileManager = context.get(JavaFileManager.class); |
350 parserFactory = ParserFactory.instance(context); |
354 parserFactory = ParserFactory.instance(context); |
|
355 compileStates = CompileStates.instance(context); |
351 |
356 |
352 try { |
357 try { |
353 // catch completion problems with predefineds |
358 // catch completion problems with predefineds |
354 syms = Symtab.instance(context); |
359 syms = Symtab.instance(context); |
355 } catch (CompletionFailure ex) { |
360 } catch (CompletionFailure ex) { |
518 public Todo todo; |
523 public Todo todo; |
519 |
524 |
520 /** A list of items to be closed when the compilation is complete. |
525 /** A list of items to be closed when the compilation is complete. |
521 */ |
526 */ |
522 public List<Closeable> closeables = List.nil(); |
527 public List<Closeable> closeables = List.nil(); |
523 |
|
524 /** Ordered list of compiler phases for each compilation unit. */ |
|
525 public enum CompileState { |
|
526 INIT(0), |
|
527 PARSE(1), |
|
528 ENTER(2), |
|
529 PROCESS(3), |
|
530 ATTR(4), |
|
531 FLOW(5), |
|
532 TRANSTYPES(6), |
|
533 UNLAMBDA(7), |
|
534 LOWER(8), |
|
535 GENERATE(9); |
|
536 |
|
537 CompileState(int value) { |
|
538 this.value = value; |
|
539 } |
|
540 boolean isAfter(CompileState other) { |
|
541 return value > other.value; |
|
542 } |
|
543 public static CompileState max(CompileState a, CompileState b) { |
|
544 return a.value > b.value ? a : b; |
|
545 } |
|
546 private final int value; |
|
547 }; |
|
548 /** Partial map to record which compiler phases have been executed |
|
549 * for each compilation unit. Used for ATTR and FLOW phases. |
|
550 */ |
|
551 protected class CompileStates extends HashMap<Env<AttrContext>,CompileState> { |
|
552 private static final long serialVersionUID = 1812267524140424433L; |
|
553 boolean isDone(Env<AttrContext> env, CompileState cs) { |
|
554 CompileState ecs = get(env); |
|
555 return (ecs != null) && !cs.isAfter(ecs); |
|
556 } |
|
557 } |
|
558 private CompileStates compileStates = new CompileStates(); |
|
559 |
528 |
560 /** The set of currently compiled inputfiles, needed to ensure |
529 /** The set of currently compiled inputfiles, needed to ensure |
561 * we don't accidentally overwrite an input file when -s is set. |
530 * we don't accidentally overwrite an input file when -s is set. |
562 * initialized by `compile'. |
531 * initialized by `compile'. |
563 */ |
532 */ |
1393 class ScanNested extends TreeScanner { |
1362 class ScanNested extends TreeScanner { |
1394 Set<Env<AttrContext>> dependencies = new LinkedHashSet<Env<AttrContext>>(); |
1363 Set<Env<AttrContext>> dependencies = new LinkedHashSet<Env<AttrContext>>(); |
1395 @Override |
1364 @Override |
1396 public void visitClassDef(JCClassDecl node) { |
1365 public void visitClassDef(JCClassDecl node) { |
1397 Type st = types.supertype(node.sym.type); |
1366 Type st = types.supertype(node.sym.type); |
1398 if (st.hasTag(CLASS)) { |
1367 boolean envForSuperTypeFound = false; |
|
1368 while (!envForSuperTypeFound && st.hasTag(CLASS)) { |
1399 ClassSymbol c = st.tsym.outermostClass(); |
1369 ClassSymbol c = st.tsym.outermostClass(); |
1400 Env<AttrContext> stEnv = enter.getEnv(c); |
1370 Env<AttrContext> stEnv = enter.getEnv(c); |
1401 if (stEnv != null && env != stEnv) { |
1371 if (stEnv != null && env != stEnv) { |
1402 if (dependencies.add(stEnv)) |
1372 if (dependencies.add(stEnv)) { |
1403 scan(stEnv.tree); |
1373 scan(stEnv.tree); |
|
1374 } |
|
1375 envForSuperTypeFound = true; |
1404 } |
1376 } |
|
1377 st = types.supertype(st); |
1405 } |
1378 } |
1406 super.visitClassDef(node); |
1379 super.visitClassDef(node); |
1407 } |
1380 } |
1408 } |
1381 } |
1409 ScanNested scanner = new ScanNested(); |
1382 ScanNested scanner = new ScanNested(); |