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));
}

if (config.skipNormalOutputs) {
compiler.initModules(externs, modules, options);
compiler.orderInputsWithLargeStack();
} else {
result = performFullCompilationWithModules(options, externs, modules);
}
compiler.initModules(externs, modules, options);
} else {
if (config.skipNormalOutputs) {
compiler.init(externs, inputs, options);
compiler.orderInputsWithLargeStack();
} else {
result = performFullCompilation(options, externs, inputs);
}
compiler.init(externs, inputs, options);
}

// TODO(rluble): Add save and restore cases here.
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) {
Expand All @@ -1127,21 +1131,14 @@ protected int doRun() throws IOException {
return processResults(result, modules, options);
}

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

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

/**
Expand Down

0 comments on commit 60fb923

Please sign in to comment.