404 completionFailureName = |
404 completionFailureName = |
405 options.isSet("failcomplete") |
405 options.isSet("failcomplete") |
406 ? names.fromString(options.get("failcomplete")) |
406 ? names.fromString(options.get("failcomplete")) |
407 : null; |
407 : null; |
408 |
408 |
409 shouldStopPolicy = |
409 shouldStopPolicyIfError = |
410 options.isSet("shouldStopPolicy") |
410 options.isSet("shouldStopPolicy") // backwards compatible |
411 ? CompileState.valueOf(options.get("shouldStopPolicy")) |
411 ? CompileState.valueOf(options.get("shouldStopPolicy")) |
412 : null; |
412 : options.isSet("shouldStopPolicyIfError") |
|
413 ? CompileState.valueOf(options.get("shouldStopPolicyIfError")) |
|
414 : CompileState.INIT; |
|
415 shouldStopPolicyIfNoError = |
|
416 options.isSet("shouldStopPolicyIfNoError") |
|
417 ? CompileState.valueOf(options.get("shouldStopPolicyIfNoError")) |
|
418 : CompileState.GENERATE; |
|
419 |
413 if (options.isUnset("oldDiags")) |
420 if (options.isUnset("oldDiags")) |
414 log.setDiagnosticFormatter(RichDiagnosticFormatter.instance(context)); |
421 log.setDiagnosticFormatter(RichDiagnosticFormatter.instance(context)); |
415 } |
422 } |
416 |
423 |
417 /* Switches: |
424 /* Switches: |
484 * Report activity related to compilePolicy |
491 * Report activity related to compilePolicy |
485 */ |
492 */ |
486 public boolean verboseCompilePolicy; |
493 public boolean verboseCompilePolicy; |
487 |
494 |
488 /** |
495 /** |
489 * Policy of how far to continue processing. null means until first |
496 * Policy of how far to continue compilation after errors have occurred. |
490 * error. |
497 * Set this to minimum CompileState (INIT) to stop as soon as possible |
491 */ |
498 * after errors. |
492 public CompileState shouldStopPolicy; |
499 */ |
493 |
500 public CompileState shouldStopPolicyIfError; |
494 /** A queue of all as yet unattributed classes. |
501 |
|
502 /** |
|
503 * Policy of how far to continue compilation when no errors have occurred. |
|
504 * Set this to maximum CompileState (GENERATE) to perform full compilation. |
|
505 * Set this lower to perform partial compilation, such as -proc:only. |
|
506 */ |
|
507 public CompileState shouldStopPolicyIfNoError; |
|
508 |
|
509 /** A queue of all as yet unattributed classes.oLo |
495 */ |
510 */ |
496 public Todo todo; |
511 public Todo todo; |
497 |
512 |
498 /** A list of items to be closed when the compilation is complete. |
513 /** A list of items to be closed when the compilation is complete. |
499 */ |
514 */ |
500 public List<Closeable> closeables = List.nil(); |
515 public List<Closeable> closeables = List.nil(); |
501 |
516 |
502 /** Ordered list of compiler phases for each compilation unit. */ |
517 /** Ordered list of compiler phases for each compilation unit. */ |
503 public enum CompileState { |
518 public enum CompileState { |
|
519 INIT(0), |
504 PARSE(1), |
520 PARSE(1), |
505 ENTER(2), |
521 ENTER(2), |
506 PROCESS(3), |
522 PROCESS(3), |
507 ATTR(4), |
523 ATTR(4), |
508 FLOW(5), |
524 FLOW(5), |
510 LOWER(7), |
526 LOWER(7), |
511 GENERATE(8); |
527 GENERATE(8); |
512 CompileState(int value) { |
528 CompileState(int value) { |
513 this.value = value; |
529 this.value = value; |
514 } |
530 } |
515 boolean isDone(CompileState other) { |
531 boolean isAfter(CompileState other) { |
516 return value >= other.value; |
532 return value > other.value; |
|
533 } |
|
534 public static CompileState max(CompileState a, CompileState b) { |
|
535 return a.value > b.value ? a : b; |
517 } |
536 } |
518 private int value; |
537 private int value; |
519 }; |
538 }; |
520 /** Partial map to record which compiler phases have been executed |
539 /** Partial map to record which compiler phases have been executed |
521 * for each compilation unit. Used for ATTR and FLOW phases. |
540 * for each compilation unit. Used for ATTR and FLOW phases. |
522 */ |
541 */ |
523 protected class CompileStates extends HashMap<Env<AttrContext>,CompileState> { |
542 protected class CompileStates extends HashMap<Env<AttrContext>,CompileState> { |
524 private static final long serialVersionUID = 1812267524140424433L; |
543 private static final long serialVersionUID = 1812267524140424433L; |
525 boolean isDone(Env<AttrContext> env, CompileState cs) { |
544 boolean isDone(Env<AttrContext> env, CompileState cs) { |
526 CompileState ecs = get(env); |
545 CompileState ecs = get(env); |
527 return ecs != null && ecs.isDone(cs); |
546 return (ecs != null) && !cs.isAfter(ecs); |
528 } |
547 } |
529 } |
548 } |
530 private CompileStates compileStates = new CompileStates(); |
549 private CompileStates compileStates = new CompileStates(); |
531 |
550 |
532 /** The set of currently compiled inputfiles, needed to ensure |
551 /** The set of currently compiled inputfiles, needed to ensure |
534 * initialized by `compile'. |
553 * initialized by `compile'. |
535 */ |
554 */ |
536 protected Set<JavaFileObject> inputFiles = new HashSet<JavaFileObject>(); |
555 protected Set<JavaFileObject> inputFiles = new HashSet<JavaFileObject>(); |
537 |
556 |
538 protected boolean shouldStop(CompileState cs) { |
557 protected boolean shouldStop(CompileState cs) { |
539 if (shouldStopPolicy == null) |
558 CompileState shouldStopPolicy = (errorCount() > 0 || unrecoverableError()) |
540 return (errorCount() > 0 || unrecoverableError()); |
559 ? shouldStopPolicyIfError |
541 else |
560 : shouldStopPolicyIfNoError; |
542 return cs.ordinal() > shouldStopPolicy.ordinal(); |
561 return cs.isAfter(shouldStopPolicy); |
543 } |
562 } |
544 |
563 |
545 /** The number of errors reported so far. |
564 /** The number of errors reported so far. |
546 */ |
565 */ |
547 public int errorCount() { |
566 public int errorCount() { |
919 filesSoFar.add(fileObject); |
938 filesSoFar.add(fileObject); |
920 trees.append(parse(fileObject)); |
939 trees.append(parse(fileObject)); |
921 } |
940 } |
922 } |
941 } |
923 return trees.toList(); |
942 return trees.toList(); |
|
943 } |
|
944 |
|
945 /** |
|
946 * Enter the symbols found in a list of parse trees if the compilation |
|
947 * is expected to proceed beyond anno processing into attr. |
|
948 * As a side-effect, this puts elements on the "todo" list. |
|
949 * Also stores a list of all top level classes in rootClasses. |
|
950 */ |
|
951 public List<JCCompilationUnit> enterTreesIfNeeded(List<JCCompilationUnit> roots) { |
|
952 if (shouldStop(CompileState.ATTR)) |
|
953 return List.nil(); |
|
954 return enterTrees(roots); |
924 } |
955 } |
925 |
956 |
926 /** |
957 /** |
927 * Enter the symbols found in a list of parse trees. |
958 * Enter the symbols found in a list of parse trees. |
928 * As a side-effect, this puts elements on the "todo" list. |
959 * As a side-effect, this puts elements on the "todo" list. |
1646 keepComments = prev.keepComments; |
1677 keepComments = prev.keepComments; |
1647 start_msec = prev.start_msec; |
1678 start_msec = prev.start_msec; |
1648 hasBeenUsed = true; |
1679 hasBeenUsed = true; |
1649 closeables = prev.closeables; |
1680 closeables = prev.closeables; |
1650 prev.closeables = List.nil(); |
1681 prev.closeables = List.nil(); |
|
1682 shouldStopPolicyIfError = prev.shouldStopPolicyIfError; |
|
1683 shouldStopPolicyIfNoError = prev.shouldStopPolicyIfNoError; |
1651 } |
1684 } |
1652 |
1685 |
1653 public static void enableLogging() { |
1686 public static void enableLogging() { |
1654 Logger logger = Logger.getLogger(com.sun.tools.javac.Main.class.getPackage().getName()); |
1687 Logger logger = Logger.getLogger(com.sun.tools.javac.Main.class.getPackage().getName()); |
1655 logger.setLevel(Level.ALL); |
1688 logger.setLevel(Level.ALL); |