public class Compiler extends AbstractCompiler
| Modifier and Type | Class and Description |
|---|---|
static class |
Compiler.CodeBuilder
Stores a buffer of text to which more can be appended.
|
private static class |
Compiler.SyntheticExternsPosition |
AbstractCompiler.ConfigContext, AbstractCompiler.LifeCycleStageSourceExcerptProvider.ExcerptFormatter, SourceExcerptProvider.SourceExcerpt| Modifier and Type | Field and Description |
|---|---|
private ReverseAbstractInterpreter |
abstractInterpreter |
private java.util.List<CodeChangeHandler> |
codeChangeHandlers |
private java.util.Map<java.lang.String,java.util.List<Comment>> |
commentsPerFile |
private CompilerExecutor |
compilerExecutor |
private static java.lang.String |
CONFIG_RESOURCE |
(package private) static java.lang.String |
CROSS_MODULE_CODE_MOTION_NAME |
(package private) static java.lang.String |
CROSS_MODULE_METHOD_MOTION_NAME |
private java.lang.String |
currentPassName |
private Tracer |
currentTracer |
private java.lang.StringBuilder |
debugLog
Debugging information
|
(package private) CodingConvention |
defaultCodingConvention
Detects Google-specific coding conventions.
|
private com.google.common.collect.ImmutableMap<java.lang.String,Node> |
defaultDefineValues |
private ErrorReporter |
defaultErrorReporter |
private SimpleDefinitionFinder |
defFinder |
(package private) static DiagnosticType |
DUPLICATE_EXTERN_INPUT |
(package private) static DiagnosticType |
DUPLICATE_INPUT |
private static DiagnosticType |
EMPTY_MODULE_LIST_ERROR |
private static DiagnosticType |
EMPTY_ROOT_MODULE_ERROR |
private ErrorManager |
errorManager |
(package private) Node |
externAndJsRoot |
private java.lang.String |
externExports
The externs created from the exports.
|
private java.util.Set<java.lang.String> |
externProperties |
private java.util.List<CompilerInput> |
externs |
private Config |
externsParserConfig |
(package private) Node |
externsRoot |
private FunctionInformationMap |
functionInformationMap
The function information map
|
private GlobalVarReferenceMap |
globalRefMap |
private boolean |
hasRegExpGlobalReferences
Whether to assume there are references to the RegExp Global object
properties.
|
private java.util.Map<java.lang.String,Node> |
injectedLibraries |
private java.util.List<CompilerInput> |
inputs |
private java.util.Map<InputId,CompilerInput> |
inputsById |
(package private) Node |
jsRoot |
private CompilerOptions.LanguageMode |
languageMode |
private java.lang.String |
lastJsSource |
private java.lang.String |
lastPassName |
private static java.util.logging.Logger |
logger
Logger for the whole com.google.javascript.jscomp domain -
setting configuration for this logger affects all loggers
in other classes within the compiler.
|
(package private) static DiagnosticType |
MISSING_ENTRY_ERROR |
(package private) static DiagnosticType |
MISSING_MODULE_ERROR |
(package private) static DiagnosticType |
MODULE_DEPENDENCY_ERROR |
private JSModuleGraph |
moduleGraph |
private java.util.List<JSModule> |
modules |
static DiagnosticType |
MOTION_ITERATIONS_ERROR |
private ErrorReporter |
oldErrorReporter |
static DiagnosticType |
OPTIMIZE_LOOP_ERROR
Error strings used for reporting JSErrors
|
(package private) CompilerOptions |
options |
private com.google.common.base.Function<java.lang.String,SourceFile> |
originalSourcesLoader |
private java.io.PrintStream |
outStream |
private Config |
parserConfig |
(package private) static java.lang.String |
PARSING_PASS_NAME |
private PassConfig |
passes |
private static com.google.common.base.Joiner |
pathJoiner |
private PhaseOptimizer |
phaseOptimizer |
private double |
progress |
protected RecentChange |
recentChange |
private PassFactory |
sanityCheck |
(package private) static java.lang.String |
SINGLETON_MODULE_NAME |
private SourceMap |
sourceMap
The source code map
|
private java.util.concurrent.ConcurrentHashMap<java.lang.String,SourceFile> |
sourceMapOriginalSources |
private GlobalTypeInfo |
symbolTable |
private CompilerInput |
synthesizedExternsInput |
private CompilerInput |
synthesizedExternsInputAtEnd |
(package private) static java.lang.String |
SYNTHETIC_EXTERNS
Name of the synthetic input that holds synthesized externs.
|
(package private) static java.lang.String |
SYNTHETIC_EXTERNS_AT_END
Name of the synthetic input that holds synthesized externs which
must be at the end of the externs AST.
|
private int |
syntheticCodeId |
PerformanceTracker |
tracker |
private JSTypeRegistry |
typeRegistry |
private TypeValidator |
typeValidator |
private int |
uniqueNameId
Ids for function inlining so that each declared name remains
unique.
|
private WarningsGuard |
warningsGuard |
needsEs6DartRuntime, needsEs6Runtime, READ_ERROR| Constructor and Description |
|---|
Compiler()
Creates a Compiler that reports errors and warnings to its logger.
|
Compiler(ErrorManager errorManager)
Creates a Compiler that uses a custom error manager.
|
Compiler(java.io.PrintStream stream)
Creates a Compiler that reports errors and warnings to an output stream.
|
| Modifier and Type | Method and Description |
|---|---|
(package private) void |
addChangeHandler(CodeChangeHandler handler)
Register a listener for code change events.
|
(package private) void |
addComments(java.lang.String filename,
java.util.List<Comment> comments) |
void |
addNewScript(JsAst ast)
Adds a new Script AST to the compile state.
|
(package private) boolean |
addNewSourceAst(JsAst ast)
Add a new source input dynamically.
|
(package private) void |
addToDebugLog(java.lang.String str)
Called from the compiler passes, adds debug info
|
(package private) void |
afterPass(java.lang.String passName)
Will be called after each pass finishes.
|
(package private) boolean |
areNodesEqualForInlining(Node n1,
Node n2)
Are the nodes equal for the purpose of inlining?
If type aware optimizations are on, type equality is checked.
|
(package private) void |
beforePass(java.lang.String passName)
Will be called before each pass runs.
|
SymbolTable |
buildKnownSymbolTable() |
void |
check() |
private void |
checkFirstModule(java.util.List<JSModule> modules)
Verifies that at least one module has been provided and that the first one
has at least one source code input.
|
private Result |
compile() |
<T1 extends SourceFile,T2 extends SourceFile> |
compile(java.util.List<T1> externs,
java.util.List<T2> inputs,
CompilerOptions options)
Compiles a list of inputs.
|
Result |
compile(SourceFile extern,
SourceFile input,
CompilerOptions options) |
private void |
compileInternal() |
<T extends SourceFile> |
compileModules(java.util.List<T> externs,
java.util.List<JSModule> modules,
CompilerOptions options)
Compiles a list of modules.
|
(package private) ControlFlowGraph<Node> |
computeCFG()
Control Flow Analysis.
|
protected Config |
createConfig(Config.LanguageMode mode) |
(package private) static java.lang.String |
createFillFileName(java.lang.String moduleName)
Empty modules get an empty "fill" file, so that we can move code into
an empty module.
|
private MessageFormatter |
createMessageFormatter()
Creates a message formatter instance corresponding to the value of
CompilerOptions. |
(package private) PassConfig |
createPassConfigInternal()
Create the passes object.
|
void |
disableThreads()
Disable threads.
|
(package private) void |
endPass()
Marks the end of a pass.
|
(package private) DefaultPassConfig |
ensureDefaultPassConfig() |
(package private) Node |
ensureLibraryInjected(java.lang.String resourceName,
boolean normalizeAndUniquifyNames)
The subdir js/ contains libraries of code that we inject
at compile-time only if requested by this function.
|
private void |
externExports() |
private static void |
fillEmptyModules(java.util.List<JSModule> modules)
Fill any empty modules with a place holder file.
|
(package private) void |
forwardDeclareType(java.lang.String typeName) |
private static java.util.List<CompilerInput> |
getAllInputsFromModules(java.util.List<JSModule> modules)
Builds a single list of all module inputs.
|
java.lang.String |
getAstDotGraph()
Gets the DOT graph of the AST generated at the end of compilation.
|
private PassConfig |
getCleanupPassConfig() |
CodingConvention |
getCodingConvention()
Gets the current coding convention.
|
java.util.List<Comment> |
getComments(java.lang.String filename)
Returns all the comments from the given file.
|
(package private) CssRenamingMap |
getCssRenamingMap()
Gets the CssRenamingMap.
|
(package private) com.google.common.collect.ImmutableMap<java.lang.String,Node> |
getDefaultDefineValues()
Gets a map of default @define values.
|
(package private) ErrorReporter |
getDefaultErrorReporter()
Gets a default error reporter for injecting into Rhino.
|
(package private) JSModuleGraph |
getDegenerateModuleGraph()
Gets a module graph.
|
protected DiagnosticGroups |
getDiagnosticGroups()
The warning classes that are available from the command-line, and
are suppressible by the
@suppress annotation. |
int |
getErrorCount()
Gets the number of errors.
|
CheckLevel |
getErrorLevel(JSError error) |
ErrorManager |
getErrorManager()
Gets the error manager.
|
JSError[] |
getErrors()
Returns the array of errors (never null).
|
(package private) java.util.Set<java.lang.String> |
getExternProperties()
Gets the names of the properties defined in externs or null if
GatherExternProperties pass was not run yet.
|
(package private) java.util.List<CompilerInput> |
getExternsForTesting() |
(package private) java.util.List<CompilerInput> |
getExternsInOrder()
Gets the externs in the order in which they are being processed.
|
(package private) FunctionInformationMap |
getFunctionalInformationMap() |
(package private) GlobalVarReferenceMap |
getGlobalVarReferences()
This can be used to get the list of all references to all global variables
based on all previous calls to
updateGlobalVarReferences. |
(package private) java.lang.Iterable<TypeValidator.TypeMismatch> |
getImplicitInterfaceUses()
Gets all types that are used implicitly as a
matching structural interface type.
|
CompilerInput |
getInput(InputId id)
Looks up an input (possibly an externs input) by input id.
|
java.util.Map<InputId,CompilerInput> |
getInputsById()
Returns an unmodifiable view of the compiler inputs indexed by id.
|
(package private) java.util.List<CompilerInput> |
getInputsForTesting() |
(package private) java.util.List<CompilerInput> |
getInputsInOrder()
Gets the inputs in the order in which they are being processed.
|
(package private) Node |
getJsRoot()
Returns the root of the source tree, ignoring externs
|
(package private) CompilerOptions.LanguageMode |
getLanguageMode()
The language mode of the current root node.
|
(package private) java.lang.String |
getLastPassName()
Gets the last pass name set by setProgress.
|
(package private) JSModuleGraph |
getModuleGraph()
Gets the module graph.
|
(package private) Node |
getNodeForCodeInsertion(JSModule module)
Gets a suitable SCRIPT node to serve as a parent for code insertion.
|
(package private) CompilerOptions |
getOptions() |
(package private) Config |
getParserConfig(AbstractCompiler.ConfigContext context)
Returns the parser configuration for the specified context.
|
(package private) PassConfig |
getPassConfig() |
double |
getProgress() |
(package private) VariableMap |
getPropertyMap() |
private static java.lang.String |
getRelativeTo(java.lang.String relative,
java.lang.String base)
Returns the relative path, resolved relative to the base path, where the
base path is interpreted as a filename rather than a directory.
|
static java.lang.String |
getReleaseDate()
Returns the compiler date baked into the jar.
|
static java.lang.String |
getReleaseVersion()
Returns the compiler version baked into the jar.
|
Result |
getResult()
Returns the result of the compilation.
|
ReverseAbstractInterpreter |
getReverseAbstractInterpreter()
Get an interpreter for type analysis.
|
Node |
getRoot()
Returns the root node of the AST, which includes both externs and source.
|
(package private) SimpleDefinitionFinder |
getSimpleDefinitionFinder()
Used by three passes that run in sequence (optimize-returns,
optimize-parameters, remove-unused-variables), to avoid having them
recompute it independently.
|
(package private) SourceFile |
getSourceFileByName(java.lang.String sourceName)
Looks up a source file by name.
|
java.lang.String |
getSourceLine(java.lang.String sourceName,
int lineNumber)
Get the line indicated by the line number.
|
SourceMap |
getSourceMap() |
Mapping.OriginalMapping |
getSourceMapping(java.lang.String sourceName,
int lineNumber,
int columnNumber)
If the source file is associated with an inputSourceMap, does a lookup
for the original file position based on this source map.
|
Region |
getSourceRegion(java.lang.String sourceName,
int lineNumber)
Get a region around the indicated line number.
|
(package private) GlobalTypeInfo |
getSymbolTable()
Used only by the new type inference
|
(package private) CompilerInput |
getSynthesizedExternsInput() |
(package private) CompilerInput |
getSynthesizedExternsInputAtEnd() |
TypedScope |
getTopScope()
Gets the top scope.
|
MemoizedScopeCreator |
getTypedScopeCreator()
Gets a memoized scope creator with type information.
|
TypeIRegistry |
getTypeIRegistry() |
(package private) java.lang.Iterable<TypeValidator.TypeMismatch> |
getTypeMismatches()
Gets the central registry of type violations.
|
JSTypeRegistry |
getTypeRegistry()
Gets a central registry of type information from the compiled JS.
|
(package private) TypeValidator |
getTypeValidator()
Only used by passes in the old type checker.
|
(package private) com.google.common.base.Supplier<java.lang.String> |
getUniqueNameIdSupplier()
Generates unique ids.
|
(package private) VariableMap |
getVariableMap() |
int |
getWarningCount()
Gets the number of warnings.
|
JSError[] |
getWarnings()
Returns the array of warnings (never null).
|
boolean |
hasErrors()
Consults the
ErrorManager to see if we've encountered errors
that should halt compilation. |
(package private) boolean |
hasHaltingErrors() |
(package private) boolean |
hasRegExpGlobalReferences() |
(package private) boolean |
hasScopeChanged(Node n)
True iff a function changed since the last time a pass was run
|
(package private) void |
hoistExterns()
Hoists inputs with the @externs annotation into the externs list.
|
(package private) void |
hoistNoCompileFiles()
Hoists inputs with the @nocompile annotation out of the inputs.
|
<T1 extends SourceFile,T2 extends SourceFile> |
init(java.util.List<T1> externs,
java.util.List<T2> inputs,
CompilerOptions options)
Initializes the instance state needed for a compile job.
|
private void |
initAST()
Sets up the skeleton of the AST (the externs and root).
|
private void |
initBasedOnOptions()
Do any initialization that is dependent on the compiler options.
|
(package private) void |
initCompilerOptionsIfTesting() |
(package private) void |
initInputsByIdMap()
Creates a map to make looking up an input by name fast.
|
<T extends SourceFile> |
initModules(java.util.List<T> externs,
java.util.List<JSModule> modules,
CompilerOptions options)
Initializes the instance state needed for a compile job if the sources
are in modules.
|
void |
initOptions(CompilerOptions options)
Initializes the compiler options.
|
(package private) void |
initWarningsGuard(WarningsGuard warningsGuard) |
boolean |
isIdeMode()
Returns true if compiling in IDE mode.
|
static java.lang.String |
joinPathParts(java.lang.String... pathParts)
Creates an OS specific path string from parts
|
(package private) Node |
loadLibraryCode(java.lang.String resourceName,
boolean normalizeAndUniquifyNames)
Load a library as a resource
|
private <T extends SourceFile> |
makeCompilerInput(java.util.List<T> files,
boolean isExtern) |
private void |
maybeSanityCheck() |
protected CompilerOptions |
newCompilerOptions()
Allow subclasses to override the default CompileOptions object.
|
(package private) CompilerInput |
newExternInput(java.lang.String name,
Compiler.SyntheticExternsPosition pos) |
(package private) Tracer |
newTracer(java.lang.String passName)
Returns a new tracer for the given pass name.
|
private int |
nextUniqueNameId()
Creates a new id for making unique names.
|
void |
normalize() |
void |
optimize() |
(package private) void |
orderInputs() |
void |
parse() |
Node |
parse(SourceFile file) |
(package private) Node |
parseInputs()
Parses the externs and main inputs.
|
(package private) Node |
parseSyntheticCode(java.lang.String js)
Parses code for injecting.
|
(package private) Node |
parseSyntheticCode(java.lang.String fileName,
java.lang.String js)
Parses code for injecting, and associate it with a given source file.
|
(package private) Node |
parseTestCode(java.lang.String js)
Parses code for testing.
|
(package private) boolean |
precheck()
Carry out any special checks or procedures that need to be done before
proceeding with rest of the compilation process.
|
(package private) void |
prepareAst(Node root)
Normalizes the types of AST nodes in the given tree, and
annotates any nodes to which the coding convention applies so that passes
can read the annotations instead of using the coding convention.
|
(package private) void |
process(CompilerPass p)
Runs a given compiler-pass by calling its
process() method. |
(package private) void |
processAMDAndCommonJSModules()
Transforms AMD and CJS modules to something closure compiler can
process and creates JSModules and the corresponding dependency tree
on the way.
|
(package private) void |
processEs6Modules() |
private void |
processNewScript(JsAst ast,
Node originalRoot) |
(package private) CompilerInput |
putCompilerInput(InputId id,
CompilerInput input) |
void |
rebuildInputsFromModules()
Rebuilds the internal list of inputs by iterating over all modules.
|
protected void |
reconcileOptionsWithGuards()
When the CompilerOptions and its WarningsGuard overlap, reconcile
any discrepencies.
|
(package private) void |
recordFunctionInformation() |
(package private) void |
removeChangeHandler(CodeChangeHandler handler)
Remove a listener for code change events.
|
protected void |
removeExternInput(InputId id)
Removes an input file from AST.
|
private void |
removeSyntheticVarsInput() |
private void |
repartitionInputs() |
(package private) boolean |
replaceIncrementalSourceAst(JsAst ast)
Replace a source input dynamically.
|
void |
replaceScript(JsAst ast)
Replaces one file in a hot-swap mode.
|
void |
report(JSError error)
Report an error or warning.
|
(package private) void |
reportChangeToEnclosingScope(Node n)
Passes that do cross-scope modifications use this (eg, InlineVariables)
|
void |
reportCodeChange()
Report code changes.
|
(package private) void |
resetUniqueNameId()
Resets the unique name id counter
|
private void |
runCustomPasses(CustomPassExecutionTime executionTime)
Runs custom passes that are designated to run at a particular time.
|
private void |
runHotSwap(Node originalRoot,
Node js,
PassConfig passConfig)
Execute the passes from a PassConfig instance over a single replaced file.
|
private void |
runHotSwapPass(Node originalRoot,
Node js,
PassFactory passFactory) |
(package private) <T> T |
runInCompilerThread(java.util.concurrent.Callable<T> callable) |
private void |
runSanityCheck() |
(package private) void |
setCssRenamingMap(CssRenamingMap map)
Sets the CssRenamingMap.
|
(package private) void |
setDefaultDefineValues(com.google.common.collect.ImmutableMap<java.lang.String,Node> values)
Stores a map of default @define values.
|
void |
setErrorManager(ErrorManager errorManager)
Sets the error manager.
|
(package private) void |
setExternProperties(java.util.Set<java.lang.String> externProperties)
Sets the names of the properties defined in externs.
|
(package private) void |
setHasRegExpGlobalReferences(boolean references)
Set if RegExp global properties are used.
|
(package private) void |
setLanguageMode(CompilerOptions.LanguageMode mode) |
static void |
setLoggingLevel(java.util.logging.Level level)
Sets the logging level for the com.google.javascript.jscomp package.
|
(package private) void |
setOriginalSourcesLoader(com.google.common.base.Function<java.lang.String,SourceFile> originalSourcesLoader) |
void |
setPassConfig(PassConfig passes) |
(package private) void |
setPhaseOptimizer(PhaseOptimizer po)
Some tests don't want to call the compiler "wholesale," they may not want
to call check and/or optimize.
|
(package private) void |
setProgress(double newProgress,
java.lang.String passName)
Sets the progress percentage as well as the name of the last pass that
ran (if available).
|
(package private) void |
setScope(Node n)
Let the PhaseOptimizer know which scope a pass is currently analyzing
|
(package private) void |
setSimpleDefinitionFinder(SimpleDefinitionFinder defFinder) |
(package private) void |
setSymbolTable(GlobalTypeInfo symbolTable) |
void |
setTimeout(int timeout)
Sets the timeout when Compiler is run in a thread
|
(package private) void |
startPass(java.lang.String passName)
Marks the beginning of a pass.
|
(package private) void |
stopTracer(Tracer t,
java.lang.String passName) |
(package private) void |
stripCode(java.util.Set<java.lang.String> stripTypes,
java.util.Set<java.lang.String> stripNameSuffixes,
java.util.Set<java.lang.String> stripTypePrefixes,
java.util.Set<java.lang.String> stripNamePrefixes)
Strips code for smaller compiled code.
|
(package private) void |
throwInternalError(java.lang.String message,
java.lang.Exception cause)
Report an internal error.
|
java.lang.String |
toSource()
Converts the main parse tree back to JS code.
|
void |
toSource(Compiler.CodeBuilder cb,
int inputSeqNum,
Node root)
Writes out JS code from a root node.
|
java.lang.String |
toSource(JSModule module)
Converts the parse tree for a module back to JS code.
|
java.lang.String |
toSource(Node n)
Generates JavaScript source code for an AST, doesn't generate source
map info.
|
private java.lang.String |
toSource(Node n,
SourceMap sourceMap,
boolean firstOutput)
Generates JavaScript source code for an AST.
|
java.lang.String[] |
toSourceArray()
Converts the parse tree for each input back to JS code.
|
java.lang.String[] |
toSourceArray(JSModule module)
Converts the parse tree for each input in a module back to JS code.
|
(package private) void |
updateGlobalVarReferences(java.util.Map<Var,ReferenceCollectingCallback.ReferenceCollection> refMapPatch,
Node collectionRoot)
Updates the list of references for variables in global scope.
|
getLifeCycleStage, setLifeCycleStagestatic final java.lang.String SINGLETON_MODULE_NAME
static final DiagnosticType MODULE_DEPENDENCY_ERROR
static final DiagnosticType MISSING_ENTRY_ERROR
static final DiagnosticType MISSING_MODULE_ERROR
static final java.lang.String PARSING_PASS_NAME
static final java.lang.String CROSS_MODULE_CODE_MOTION_NAME
static final java.lang.String CROSS_MODULE_METHOD_MOTION_NAME
private static final java.lang.String CONFIG_RESOURCE
CompilerOptions options
private PassConfig passes
private java.util.List<CompilerInput> externs
private java.util.List<JSModule> modules
private JSModuleGraph moduleGraph
private java.util.List<CompilerInput> inputs
private ErrorManager errorManager
private WarningsGuard warningsGuard
private final java.util.Map<java.lang.String,Node> injectedLibraries
Node externsRoot
Node jsRoot
Node externAndJsRoot
private java.lang.String lastJsSource
private CompilerOptions.LanguageMode languageMode
getLanguageMode()private java.util.Map<InputId,CompilerInput> inputsById
private com.google.common.base.Function<java.lang.String,SourceFile> originalSourcesLoader
private java.util.concurrent.ConcurrentHashMap<java.lang.String,SourceFile> sourceMapOriginalSources
private java.util.Map<java.lang.String,java.util.List<Comment>> commentsPerFile
private SourceMap sourceMap
private java.lang.String externExports
private int uniqueNameId
private boolean hasRegExpGlobalReferences
private FunctionInformationMap functionInformationMap
private final java.lang.StringBuilder debugLog
CodingConvention defaultCodingConvention
private JSTypeRegistry typeRegistry
private Config parserConfig
private Config externsParserConfig
private ReverseAbstractInterpreter abstractInterpreter
private TypeValidator typeValidator
private PhaseOptimizer phaseOptimizer
public PerformanceTracker tracker
private SimpleDefinitionFinder defFinder
private GlobalTypeInfo symbolTable
private final ErrorReporter oldErrorReporter
private final ErrorReporter defaultErrorReporter
public static final DiagnosticType OPTIMIZE_LOOP_ERROR
public static final DiagnosticType MOTION_ITERATIONS_ERROR
private final CompilerExecutor compilerExecutor
private static final java.util.logging.Logger logger
private final java.io.PrintStream outStream
private GlobalVarReferenceMap globalRefMap
private volatile double progress
private java.lang.String lastPassName
private java.util.Set<java.lang.String> externProperties
private static final com.google.common.base.Joiner pathJoiner
private static final DiagnosticType EMPTY_MODULE_LIST_ERROR
private static final DiagnosticType EMPTY_ROOT_MODULE_ERROR
static final DiagnosticType DUPLICATE_INPUT
static final DiagnosticType DUPLICATE_EXTERN_INPUT
private final PassFactory sanityCheck
private Tracer currentTracer
private java.lang.String currentPassName
private int syntheticCodeId
protected final RecentChange recentChange
private final java.util.List<CodeChangeHandler> codeChangeHandlers
static final java.lang.String SYNTHETIC_EXTERNS
static final java.lang.String SYNTHETIC_EXTERNS_AT_END
private CompilerInput synthesizedExternsInput
private CompilerInput synthesizedExternsInputAtEnd
private com.google.common.collect.ImmutableMap<java.lang.String,Node> defaultDefineValues
public Compiler()
public Compiler(java.io.PrintStream stream)
public Compiler(ErrorManager errorManager)
public void setErrorManager(ErrorManager errorManager)
errorManager - the error manager, it cannot be nullprivate MessageFormatter createMessageFormatter()
CompilerOptions.void setOriginalSourcesLoader(com.google.common.base.Function<java.lang.String,SourceFile> originalSourcesLoader)
public void initOptions(CompilerOptions options)
void initWarningsGuard(WarningsGuard warningsGuard)
protected void reconcileOptionsWithGuards()
public <T1 extends SourceFile,T2 extends SourceFile> void init(java.util.List<T1> externs, java.util.List<T2> inputs, CompilerOptions options)
public <T extends SourceFile> void initModules(java.util.List<T> externs, java.util.List<JSModule> modules, CompilerOptions options)
private void initBasedOnOptions()
private <T extends SourceFile> java.util.List<CompilerInput> makeCompilerInput(java.util.List<T> files, boolean isExtern)
private void checkFirstModule(java.util.List<JSModule> modules)
static java.lang.String createFillFileName(java.lang.String moduleName)
public static java.lang.String joinPathParts(java.lang.String... pathParts)
private static void fillEmptyModules(java.util.List<JSModule> modules)
public void rebuildInputsFromModules()
init(List, List, CompilerOptions) call.private static java.util.List<CompilerInput> getAllInputsFromModules(java.util.List<JSModule> modules)
private static java.lang.String getRelativeTo(java.lang.String relative,
java.lang.String base)
void initInputsByIdMap()
private void initAST()
public Result compile(SourceFile extern, SourceFile input, CompilerOptions options)
public <T1 extends SourceFile,T2 extends SourceFile> Result compile(java.util.List<T1> externs, java.util.List<T2> inputs, CompilerOptions options)
public <T extends SourceFile> Result compileModules(java.util.List<T> externs, java.util.List<JSModule> modules, CompilerOptions options)
private Result compile()
public void disableThreads()
public void setTimeout(int timeout)
timeout - seconds to wait before timeout<T> T runInCompilerThread(java.util.concurrent.Callable<T> callable)
private void compileInternal()
public void parse()
PassConfig getPassConfig()
PassConfig createPassConfigInternal()
public void setPassConfig(PassConfig passes)
passes - The PassConfig to use with this Compiler.java.lang.NullPointerException - if passes is nulljava.lang.IllegalStateException - if this.passes has already been assignedboolean precheck()
public void check()
private void externExports()
void process(CompilerPass p)
AbstractCompilerprocess() method.process in class AbstractCompilerp - The pass to be run.private void maybeSanityCheck()
private void runSanityCheck()
void stripCode(java.util.Set<java.lang.String> stripTypes,
java.util.Set<java.lang.String> stripNameSuffixes,
java.util.Set<java.lang.String> stripTypePrefixes,
java.util.Set<java.lang.String> stripNamePrefixes)
private void runCustomPasses(CustomPassExecutionTime executionTime)
void startPass(java.lang.String passName)
void endPass()
final void beforePass(java.lang.String passName)
AbstractCompilerbeforePass in class AbstractCompilerfinal void afterPass(java.lang.String passName)
AbstractCompilerafterPass in class AbstractCompilerTracer newTracer(java.lang.String passName)
void stopTracer(Tracer t, java.lang.String passName)
public Result getResult()
public JSError[] getErrors()
public JSError[] getWarnings()
public Node getRoot()
AbstractCompilergetRoot in class AbstractCompilerCompilerOptions.LanguageMode getLanguageMode()
AbstractCompilerCompilerOptions before transpilation happens, and
match the languageOut field after transpilation.getLanguageMode in class AbstractCompilervoid setLanguageMode(CompilerOptions.LanguageMode mode)
setLanguageMode in class AbstractCompilerprivate int nextUniqueNameId()
void resetUniqueNameId()
com.google.common.base.Supplier<java.lang.String> getUniqueNameIdSupplier()
AbstractCompilergetUniqueNameIdSupplier in class AbstractCompilerboolean areNodesEqualForInlining(Node n1, Node n2)
AbstractCompilerareNodesEqualForInlining in class AbstractCompilerpublic CompilerInput getInput(InputId id)
AbstractCompilergetInput in class AbstractCompilerprotected void removeExternInput(InputId id)
id - The id of the input to be removed.CompilerInput newExternInput(java.lang.String name, Compiler.SyntheticExternsPosition pos)
CompilerInput putCompilerInput(InputId id, CompilerInput input)
boolean replaceIncrementalSourceAst(JsAst ast)
boolean addNewSourceAst(JsAst ast)
If the new source input doesn't parse, it will not be added, and a false will be returned.
ast - the JS Source to add.java.lang.IllegalStateException - if an input for this ast already exists.JSModuleGraph getModuleGraph()
AbstractCompilergetModuleGraph in class AbstractCompilerJSModuleGraph getDegenerateModuleGraph()
public TypeIRegistry getTypeIRegistry()
getTypeIRegistry in class AbstractCompilerpublic JSTypeRegistry getTypeRegistry()
AbstractCompilergetTypeRegistry in class AbstractCompilervoid forwardDeclareType(java.lang.String typeName)
forwardDeclareType in class AbstractCompilerpublic MemoizedScopeCreator getTypedScopeCreator()
AbstractCompilergetTypedScopeCreator in class AbstractCompilerDefaultPassConfig ensureDefaultPassConfig()
public SymbolTable buildKnownSymbolTable()
public TypedScope getTopScope()
AbstractCompilergetTopScope in class AbstractCompilerpublic ReverseAbstractInterpreter getReverseAbstractInterpreter()
AbstractCompilergetReverseAbstractInterpreter in class AbstractCompilerTypeValidator getTypeValidator()
AbstractCompilergetTypeValidator in class AbstractCompilerjava.lang.Iterable<TypeValidator.TypeMismatch> getTypeMismatches()
AbstractCompilergetTypeMismatches in class AbstractCompilerjava.lang.Iterable<TypeValidator.TypeMismatch> getImplicitInterfaceUses()
AbstractCompilergetImplicitInterfaceUses in class AbstractCompilerGlobalTypeInfo getSymbolTable()
AbstractCompilergetSymbolTable in class AbstractCompilervoid setSymbolTable(GlobalTypeInfo symbolTable)
setSymbolTable in class AbstractCompilerSimpleDefinitionFinder getSimpleDefinitionFinder()
AbstractCompilergetSimpleDefinitionFinder in class AbstractCompilervoid setSimpleDefinitionFinder(SimpleDefinitionFinder defFinder)
setSimpleDefinitionFinder in class AbstractCompilerNode parseInputs()
void orderInputs()
void hoistExterns()
void hoistNoCompileFiles()
private void repartitionInputs()
void processEs6Modules()
void processAMDAndCommonJSModules()
public Node parse(SourceFile file)
Node parseSyntheticCode(java.lang.String js)
AbstractCompilerparseSyntheticCode in class AbstractCompilerprotected CompilerOptions newCompilerOptions()
void initCompilerOptionsIfTesting()
Node parseSyntheticCode(java.lang.String fileName, java.lang.String js)
AbstractCompilerparseSyntheticCode in class AbstractCompilerNode parseTestCode(java.lang.String js)
AbstractCompilerparseTestCode in class AbstractCompilerErrorReporter getDefaultErrorReporter()
AbstractCompilergetDefaultErrorReporter in class AbstractCompilerpublic java.lang.String toSource()
public java.lang.String[] toSourceArray()
public java.lang.String toSource(JSModule module)
public java.lang.String[] toSourceArray(JSModule module)
public void toSource(Compiler.CodeBuilder cb, int inputSeqNum, Node root)
public java.lang.String toSource(Node n)
toSource in class AbstractCompilerprivate java.lang.String toSource(Node n, SourceMap sourceMap, boolean firstOutput)
public void optimize()
void setCssRenamingMap(CssRenamingMap map)
AbstractCompilersetCssRenamingMap in class AbstractCompilerCssRenamingMap getCssRenamingMap()
AbstractCompilergetCssRenamingMap in class AbstractCompilerControlFlowGraph<Node> computeCFG()
public void normalize()
void prepareAst(Node root)
AbstractCompilerprepareAst in class AbstractCompilervoid recordFunctionInformation()
void addChangeHandler(CodeChangeHandler handler)
AbstractCompileraddChangeHandler in class AbstractCompilervoid removeChangeHandler(CodeChangeHandler handler)
AbstractCompilerremoveChangeHandler in class AbstractCompilervoid setScope(Node n)
AbstractCompilersetScope in class AbstractCompilerNode getJsRoot()
AbstractCompilergetJsRoot in class AbstractCompilerboolean hasScopeChanged(Node n)
AbstractCompilerhasScopeChanged in class AbstractCompilervoid reportChangeToEnclosingScope(Node n)
AbstractCompilerreportChangeToEnclosingScope in class AbstractCompilervoid setPhaseOptimizer(PhaseOptimizer po)
public void reportCodeChange()
AbstractCompilerreportCodeChange in class AbstractCompilerpublic CodingConvention getCodingConvention()
AbstractCompilergetCodingConvention in class AbstractCompilerpublic boolean isIdeMode()
AbstractCompilerisIdeMode in class AbstractCompilerConfig getParserConfig(AbstractCompiler.ConfigContext context)
AbstractCompilergetParserConfig in class AbstractCompilerprotected Config createConfig(Config.LanguageMode mode)
protected DiagnosticGroups getDiagnosticGroups()
@suppress annotation.public void report(JSError error)
AbstractCompilerreport in class AbstractCompilerpublic CheckLevel getErrorLevel(JSError error)
getErrorLevel in class AbstractCompilervoid throwInternalError(java.lang.String message,
java.lang.Exception cause)
throwInternalError in class AbstractCompilerpublic int getErrorCount()
public int getWarningCount()
boolean hasHaltingErrors()
hasHaltingErrors in class AbstractCompilerpublic boolean hasErrors()
ErrorManager to see if we've encountered errors
that should halt compilation.
If CompilerOptions.ideMode is true, this function
always returns false without consulting the error manager. The
error manager will continue to be told about new errors and warnings, but
the compiler will complete compilation of all inputs.
void addToDebugLog(java.lang.String str)
addToDebugLog in class AbstractCompilerSourceFile getSourceFileByName(java.lang.String sourceName)
AbstractCompilergetSourceFileByName in class AbstractCompilerpublic Mapping.OriginalMapping getSourceMapping(java.lang.String sourceName, int lineNumber, int columnNumber)
SourceExcerptProviderpublic java.lang.String getSourceLine(java.lang.String sourceName,
int lineNumber)
SourceExcerptProviderlineNumber - the line number, 1 being the first line of the filenull if it does not existpublic Region getSourceRegion(java.lang.String sourceName, int lineNumber)
SourceExcerptProviderlineNumber - the line number, 1 being the first line of the filenull
if it does not existNode getNodeForCodeInsertion(JSModule module)
AbstractCompilermodule contains any inputs, the returned node will be the SCRIPT
node corresponding to its first input. If module is empty, on the
other hand, then the returned node will be the first SCRIPT node in a
non-empty module that module depends on (the deepest one possible).getNodeForCodeInsertion in class AbstractCompilermodule - A module. If null, will return the first SCRIPT node of all
modules.public SourceMap getSourceMap()
VariableMap getVariableMap()
VariableMap getPropertyMap()
CompilerOptions getOptions()
getOptions in class AbstractCompilerFunctionInformationMap getFunctionalInformationMap()
public static void setLoggingLevel(java.util.logging.Level level)
public java.lang.String getAstDotGraph()
throws java.io.IOException
java.io.IOExceptionpublic ErrorManager getErrorManager()
AbstractCompilergetErrorManager in class AbstractCompilerjava.util.List<CompilerInput> getInputsInOrder()
AbstractCompilerAbstractCompilerRunner.getInputsInOrder in class AbstractCompilerpublic java.util.Map<InputId,CompilerInput> getInputsById()
java.util.List<CompilerInput> getExternsInOrder()
java.util.List<CompilerInput> getInputsForTesting()
java.util.List<CompilerInput> getExternsForTesting()
boolean hasRegExpGlobalReferences()
hasRegExpGlobalReferences in class AbstractCompilervoid setHasRegExpGlobalReferences(boolean references)
AbstractCompilersetHasRegExpGlobalReferences in class AbstractCompilerreferences - Whether there are references to the RegExp global object
properties.void updateGlobalVarReferences(java.util.Map<Var,ReferenceCollectingCallback.ReferenceCollection> refMapPatch, Node collectionRoot)
AbstractCompilerupdateGlobalVarReferences in class AbstractCompilerrefMapPatch - Maps each variable to all of its references; may contain
references collected from the whole AST or only a SCRIPT sub-tree.collectionRoot - The root of sub-tree in which reference collection
has been done. This should either be a SCRIPT node (if collection is
done on a single file) or it is assumed that collection is on full AST.GlobalVarReferenceMap getGlobalVarReferences()
AbstractCompilerupdateGlobalVarReferences.getGlobalVarReferences in class AbstractCompilerCompilerInput getSynthesizedExternsInput()
getSynthesizedExternsInput in class AbstractCompilerCompilerInput getSynthesizedExternsInputAtEnd()
getSynthesizedExternsInputAtEnd in class AbstractCompilerpublic double getProgress()
getProgress in class AbstractCompilerjava.lang.String getLastPassName()
AbstractCompilergetLastPassName in class AbstractCompilervoid setProgress(double newProgress,
java.lang.String passName)
AbstractCompilersetProgress in class AbstractCompilernewProgress - A precentage expressed as a double in the range [0, 1].
Use -1 if you just want to set the last pass name.void setExternProperties(java.util.Set<java.lang.String> externProperties)
AbstractCompilersetExternProperties in class AbstractCompilerexternProperties - The set of property names defined in externs.java.util.Set<java.lang.String> getExternProperties()
AbstractCompilergetExternProperties in class AbstractCompilerpublic void replaceScript(JsAst ast)
ast - the ast of the file that is being replacedpublic void addNewScript(JsAst ast)
ast - the ast of the new fileprivate void runHotSwap(Node originalRoot, Node js, PassConfig passConfig)
private void runHotSwapPass(Node originalRoot, Node js, PassFactory passFactory)
private PassConfig getCleanupPassConfig()
private void removeSyntheticVarsInput()
Node ensureLibraryInjected(java.lang.String resourceName, boolean normalizeAndUniquifyNames)
AbstractCompilerensureLibraryInjected in class AbstractCompilerresourceName - The name of the library. For example, if "base" is
is specified, then we load js/base.jsnormalizeAndUniquifyNames - Whether to normalize the library code and make
names unique.Node loadLibraryCode(java.lang.String resourceName, boolean normalizeAndUniquifyNames)
@GwtIncompatible(value="java.util.ResourceBundle") public static java.lang.String getReleaseVersion()
@GwtIncompatible(value="java.util.ResourceBundle") public static java.lang.String getReleaseDate()
void addComments(java.lang.String filename,
java.util.List<Comment> comments)
addComments in class AbstractCompilerpublic java.util.List<Comment> getComments(java.lang.String filename)
AbstractCompilergetComments in class AbstractCompilervoid setDefaultDefineValues(com.google.common.collect.ImmutableMap<java.lang.String,Node> values)
AbstractCompilersetDefaultDefineValues in class AbstractCompilercom.google.common.collect.ImmutableMap<java.lang.String,Node> getDefaultDefineValues()
AbstractCompilergetDefaultDefineValues in class AbstractCompiler