Skip to content

Commit

Permalink
Factor out completeCompilation()
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=154895757
  • Loading branch information
brad4d committed May 3, 2017
1 parent e68b081 commit 3112349
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 20 deletions.
14 changes: 8 additions & 6 deletions src/com/google/javascript/jscomp/AbstractCommandLineRunner.java
Expand Up @@ -1131,30 +1131,32 @@ private Result performFullCompilationWithModules(
B options, List<SourceFile> externs, List<JSModule> modules) { B options, List<SourceFile> externs, List<JSModule> modules) {
try { try {
compiler.initModules(externs, modules, options); compiler.initModules(externs, modules, options);
if (compiler.hasErrors()) { if (!compiler.hasErrors()) {
return compiler.getResult(); compiler.checkAndTranspileAndOptimize();
compiler.completeCompilation();
} }
return compiler.checkAndTranspileAndOptimize();
} finally { } finally {
// Make sure we generate a report of errors and warnings even if the compiler throws an // Make sure we generate a report of errors and warnings even if the compiler throws an
// exception somewhere. // exception somewhere.
compiler.generateReport(); compiler.generateReport();
} }
return compiler.getResult();
} }


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


/** /**
Expand Down
49 changes: 35 additions & 14 deletions src/com/google/javascript/jscomp/Compiler.java
Expand Up @@ -760,13 +760,14 @@ public <T1 extends SourceFile, T2 extends SourceFile> Result initAndCheckAndTran


try { try {
init(externs, inputs, options); init(externs, inputs, options);
if (hasErrors()) { if (!hasErrors()) {
return getResult(); checkAndTranspileAndOptimize();
completeCompilation();
} }
return checkAndTranspileAndOptimize();
} finally { } finally {
generateReport(); generateReport();
} }
return getResult();
} }


/** /**
Expand Down Expand Up @@ -796,20 +797,23 @@ public <T extends SourceFile> Result initModulesAndCheckAndTranspileAndOptimize(


try { try {
initModules(externs, modules, options); initModules(externs, modules, options);
if (hasErrors()) { if (!hasErrors()) {
return getResult(); checkAndTranspileAndOptimize();
completeCompilation();
} }
return checkAndTranspileAndOptimize();
} finally { } finally {
generateReport(); generateReport();
} }
return getResult();
} }


/** /**
* Generates a report of all warnings and errors found during compilation to stderr. * Generates a report of all warnings and errors found during compilation to stderr.
* *
* <p>Client code must call this method explicitly if it doesn't use one of the convenience * <p>Client code must call this method explicitly if it doesn't use one of the convenience
* methods that do so automatically. * methods that do so automatically.
* <p>Always call this method, even if the compiler throws an exception. The report will include
* information about the exception.
*/ */
public void generateReport() { public void generateReport() {
Tracer t = newTracer("generateReport"); Tracer t = newTracer("generateReport");
Expand All @@ -836,15 +840,14 @@ public <T extends SourceFile> Result compileModules(
* report of warnings and errors to stderr. See the invocation in * report of warnings and errors to stderr. See the invocation in
* {@link #initAndCheckAndTranspileAndOptimize} for a good example. * {@link #initAndCheckAndTranspileAndOptimize} for a good example.
* <p> TODO(bradfordcsmith): Break this up into checkAndTranspile() and optimize(). * <p> TODO(bradfordcsmith): Break this up into checkAndTranspile() and optimize().
* @return compilation results.
*/ */
public Result checkAndTranspileAndOptimize() { public void checkAndTranspileAndOptimize() {
checkState( checkState(
inputs != null && !inputs.isEmpty(), "No inputs. Did you call init() or initModules()?"); inputs != null && !inputs.isEmpty(), "No inputs. Did you call init() or initModules()?");
return runInCompilerThread( runInCompilerThread(
new Callable<Result>() { new Callable<Void>() {
@Override @Override
public Result call() throws Exception { public Void call() throws Exception {
parseForCompilation(); parseForCompilation();
if (!hasErrors()) { if (!hasErrors()) {
if (options.getInstrumentForCoverageOnly()) { if (options.getInstrumentForCoverageOnly()) {
Expand All @@ -856,8 +859,7 @@ public Result call() throws Exception {
} }
} }
} }
completeCompilation(); return null;
return getResult();
} }
}); });
} }
Expand Down Expand Up @@ -899,10 +901,29 @@ private void performChecksAndTranspilation() {
} }
} }


/**
* Performs all the bookkeeping required at the end of a compilation.
*
* <p>This method must be called if the compilation makes it as far as doing checks.
* <p> DON'T call it if the compiler threw an exception.
* <p> DO call it even when {@code hasErrors()} returns true.
*/
public void completeCompilation() {
runInCompilerThread(new Callable<Void>() {

@Override
public Void call() throws Exception {
completeCompilationInternal();
return null;
}

});
}

/** /**
* Performs all the bookkeeping required at the end of a compilation. * Performs all the bookkeeping required at the end of a compilation.
*/ */
private void completeCompilation() { private void completeCompilationInternal() {
if (options.recordFunctionInformation) { if (options.recordFunctionInformation) {
recordFunctionInformation(); recordFunctionInformation();
} }
Expand Down

0 comments on commit 3112349

Please sign in to comment.