Skip to content

Commit

Permalink
AbstractCommandLineRunner: Refactor to allow for save/restore impleme…
Browse files Browse the repository at this point in the history
…ntation.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=155714284
  • Loading branch information
brad4d authored and dimvar committed May 11, 2017
1 parent b8c4be3 commit 60fb923
Showing 1 changed file with 30 additions and 44 deletions.
74 changes: 30 additions & 44 deletions src/com/google/javascript/jscomp/AbstractCommandLineRunner.java
Expand Up @@ -1092,19 +1092,23 @@ protected int doRun() throws IOException {
outputFileNames.add(getModuleOutputFileName(m)); outputFileNames.add(getModuleOutputFileName(m));
} }


if (config.skipNormalOutputs) { compiler.initModules(externs, modules, options);
compiler.initModules(externs, modules, options);
compiler.orderInputsWithLargeStack();
} else {
result = performFullCompilationWithModules(options, externs, modules);
}
} else { } else {
if (config.skipNormalOutputs) { compiler.init(externs, inputs, options);
compiler.init(externs, inputs, options); }
compiler.orderInputsWithLargeStack();
} else { // TODO(rluble): Add save and restore cases here.
result = performFullCompilation(options, externs, inputs); if (config.skipNormalOutputs) {
} // TODO(bradfordcsmith): Should we be ignoring possible init/initModules() errors here?
compiler.orderInputsWithLargeStack();
} else if (compiler.hasErrors()) {
// init() or initModules() encountered an error.
compiler.generateReport();
result = compiler.getResult();
} else if (options.getInstrumentForCoverageOnly()) {
result = instrumentForCoverage();
} else {
result = performFullCompilation();
} }


if (createCommonJsModules) { if (createCommonJsModules) {
Expand All @@ -1127,21 +1131,14 @@ protected int doRun() throws IOException {
return processResults(result, modules, options); return processResults(result, modules, options);
} }


private Result performFullCompilationWithModules( private Result performFullCompilation() {
B options, List<SourceFile> externs, List<JSModule> modules) { Result result;
try { try {
compiler.initModules(externs, modules, options); compiler.parseForCompilation();
if (!compiler.hasErrors()) { if (!compiler.hasErrors()) {
compiler.parseForCompilation(); compiler.stage1Passes();
} if (!compiler.hasErrors()) {
if (!compiler.hasErrors()) { compiler.stage2Passes();
if (options.getInstrumentForCoverageOnly()) {
compiler.instrumentForCoverage();
} else {
compiler.stage1Passes();
if (!compiler.hasErrors()) {
compiler.stage2Passes();
}
} }
compiler.completeCompilation(); compiler.completeCompilation();
} }
Expand All @@ -1150,33 +1147,22 @@ private Result performFullCompilationWithModules(
// exception somewhere. // exception somewhere.
compiler.generateReport(); compiler.generateReport();
} }
return compiler.getResult(); result = compiler.getResult();
return result;
} }


private Result performFullCompilation( private Result instrumentForCoverage() {
B options, List<SourceFile> externs, List<SourceFile> inputs) { Result result;
try { try {
compiler.init(externs, inputs, options); compiler.parseForCompilation();
if (!compiler.hasErrors()) { if (!compiler.hasErrors()) {
compiler.parseForCompilation(); compiler.instrumentForCoverage();
}
if (!compiler.hasErrors()) {
if (options.getInstrumentForCoverageOnly()) {
compiler.instrumentForCoverage();
} else {
compiler.stage1Passes();
if (!compiler.hasErrors()) {
compiler.stage2Passes();
}
}
compiler.completeCompilation();
} }
} finally { } finally {
// Make sure we generate a report of errors and warnings even if the compiler throws an
// exception somewhere.
compiler.generateReport(); compiler.generateReport();
} }
return compiler.getResult(); result = compiler.getResult();
return result;
} }


/** /**
Expand Down

0 comments on commit 60fb923

Please sign in to comment.