Package com.google.javascript.jscomp
Class AbstractCompiler
- java.lang.Object
-
- com.google.javascript.jscomp.AbstractCompiler
-
- All Implemented Interfaces:
CompilerInputProvider
,SourceExcerptProvider
- Direct Known Subclasses:
Compiler
public abstract class AbstractCompiler extends java.lang.Object implements SourceExcerptProvider, CompilerInputProvider
An abstract compiler, to help remove the circular dependency of passes on JSCompiler.This is an abstract class, so that we can make the methods package-private.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractCompiler.LifeCycleStage
What point in optimizations we're in.-
Nested classes/interfaces inherited from interface com.google.javascript.jscomp.SourceExcerptProvider
SourceExcerptProvider.ExcerptFormatter, SourceExcerptProvider.SourceExcerpt
-
-
Constructor Summary
Constructors Constructor Description AbstractCompiler()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
addExportedNames(java.util.Set<java.lang.String> exportedVariableNames)
Adds exported names to keep track.abstract void
addInputSourceMap(java.lang.String name, SourceMapInput sourceMap)
Adds aSourceMapInput
for the givensourceFileName
, to be used for error reporting and source map combining.abstract void
clearJSTypeRegistry()
com.google.javascript.jscomp.AstFactory
createAstFactory()
Returns a new AstFactory that will add type information to the nodes it creates if and only if type checking has already happened and types have not been converted into colors.com.google.javascript.jscomp.AstFactory
createAstFactoryWithoutTypes()
Returns a new AstFactory that will not add type information, regardless of whether type checking has already happened.com.google.javascript.jscomp.ExpressionDecomposer
createDefaultExpressionDecomposer()
com.google.javascript.jscomp.ExpressionDecomposer
createExpressionDecomposer(com.google.common.base.Supplier<java.lang.String> uniqueNameIdSupplier, com.google.common.collect.ImmutableSet<java.lang.String> knownConstantFunctions, Scope scope)
LogFile
createOrReopenIndexedLog(java.lang.Class<?> owner, java.lang.String firstNamePart, java.lang.String... restNameParts)
Provides logging access to a file with the specified name, differentiated by the index of the current pass.LogFile
createOrReopenLog(java.lang.Class<?> owner, java.lang.String firstNamePart, java.lang.String... restNameParts)
Provides logging access to a file with the specified name.AstAnalyzer
getAstAnalyzer()
Returns a new AstAnalyzer configured correctly to answer questions about Nodes in the AST currently being compiled.abstract CodingConvention
getCodingConvention()
Gets the current coding convention.abstract ColorRegistry
getColorRegistry()
Gets a central registry of colors from deserialized JS types.abstract IdGenerator
getCrossModuleIdGenerator()
Gets the id generator for cross-module motion.abstract ErrorManager
getErrorManager()
Gets the error manager.abstract java.util.Set<java.lang.String>
getExportedNames()
Gets the names that have been exported.abstract com.google.common.collect.ImmutableSet<java.lang.String>
getExternProperties()
Gets the names of the properties defined in externs or null if GatherExternProperties pass was not run yet.abstract CompilerInput
getInput(InputId inputId)
Looks up an input (possibly an externs input) by input id.AbstractCompiler.LifeCycleStage
getLifeCycleStage()
Returns the current life-cycle stage of the AST we're working on.abstract ModuleMap
getModuleMap()
abstract ModuleMetadataMap
getModuleMetadataMap()
abstract double
getProgress()
abstract ReverseAbstractInterpreter
getReverseAbstractInterpreter()
Get an interpreter for type analysis.abstract Node
getRoot()
Returns the root node of the AST, which includes both externs and source.abstract Node
getScriptNode(java.lang.String filename)
abstract TypedScope
getTopScope()
Gets the top scope.abstract java.lang.Iterable<TypeMismatch>
getTypeMismatches()
Gets the central registry of type violations.abstract JSTypeRegistry
getTypeRegistry()
Gets a central registry of type information from the compiled JS.abstract boolean
hasOptimizationColors()
Whether the AST has been annotated with optimization colors.abstract boolean
hasTypeCheckingRun()
Returns whether the typechecking passes have runvoid
initRuntimeLibraryTypedAsts(com.google.common.base.Optional<ColorPool.Builder> colorPoolBuilder)
Deserialize runtime libraries from a TypedAST packaged as a JAR resource and reconcile their Colors with the current inputs.boolean
isDebugLoggingEnabled()
static boolean
isFillFileName(java.lang.String fileName)
Returns whether a file name was created bycreateFillFileName(java.lang.String)
.abstract boolean
isTypeRegistryCleared()
Returns `true` when type checking has run, but the type registry has been cleared.abstract Node
parseSyntheticCode(java.lang.String filename, java.lang.String code)
Parses code for injecting, and associate it with a given source file.abstract void
report(JSError error)
Report an error or warning.abstract void
reportChangeToChangeScope(Node changeScopeRoot)
Mark modifications in a scope that is different than the Compiler.currentScope use this (eg, InlineVariables and many others)abstract void
reportChangeToEnclosingScope(Node n)
Passes that make modifications in a scope that is different than the Compiler.currentScope use this (eg, InlineVariables and many others)abstract void
setAccessorSummary(com.google.javascript.jscomp.AccessorSummary summary)
Sets the summary of properties with getters and setters.abstract void
setAnonymousFunctionNameMap(VariableMap functionMap)
Sets the naming map for anonymous functionsabstract void
setColorRegistry(ColorRegistry registry)
Sets the color registryabstract void
setCssNames(java.util.Map<java.lang.String,java.lang.Integer> newCssNames)
Sets the css names found during compilation.abstract void
setIdGeneratorMap(java.lang.String serializedIdMappings)
Sets the id generator for cross-module motion.abstract void
setInstrumentationMapping(VariableMap instrumentationMapping)
Sets the mapping for instrumentation parameter encoding.abstract void
setModuleMap(ModuleMap moduleMap)
abstract void
setModuleMetadataMap(ModuleMetadataMap moduleMetadataMap)
abstract void
setPropertyMap(VariableMap propertyMap)
Sets the property renaming mapabstract void
setStringMap(VariableMap stringMap)
Sets the string replacement mapabstract void
setVariableMap(VariableMap variableMap)
Sets the variable renaming mapabstract java.lang.String
toSource()
Prints a node to source code.abstract java.lang.String
toSource(Node root)
Prints a node to source code.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.google.javascript.jscomp.SourceExcerptProvider
getSourceLine, getSourceLines, getSourceMapping, getSourceRegion
-
-
-
-
Method Detail
-
getInput
public abstract CompilerInput getInput(InputId inputId)
Looks up an input (possibly an externs input) by input id. May return null.- Specified by:
getInput
in interfaceCompilerInputProvider
-
getScriptNode
@Nullable public abstract Node getScriptNode(java.lang.String filename)
-
addExportedNames
public abstract void addExportedNames(java.util.Set<java.lang.String> exportedVariableNames)
Adds exported names to keep track.
-
getExportedNames
public abstract java.util.Set<java.lang.String> getExportedNames()
Gets the names that have been exported.
-
setVariableMap
public abstract void setVariableMap(VariableMap variableMap)
Sets the variable renaming map
-
setPropertyMap
public abstract void setPropertyMap(VariableMap propertyMap)
Sets the property renaming map
-
setStringMap
public abstract void setStringMap(VariableMap stringMap)
Sets the string replacement map
-
setCssNames
public abstract void setCssNames(java.util.Map<java.lang.String,java.lang.Integer> newCssNames)
Sets the css names found during compilation.
-
setInstrumentationMapping
public abstract void setInstrumentationMapping(VariableMap instrumentationMapping)
Sets the mapping for instrumentation parameter encoding.
-
setIdGeneratorMap
public abstract void setIdGeneratorMap(java.lang.String serializedIdMappings)
Sets the id generator for cross-module motion.
-
getCrossModuleIdGenerator
public abstract IdGenerator getCrossModuleIdGenerator()
Gets the id generator for cross-module motion.
-
setAnonymousFunctionNameMap
public abstract void setAnonymousFunctionNameMap(VariableMap functionMap)
Sets the naming map for anonymous functions
-
hasTypeCheckingRun
public abstract boolean hasTypeCheckingRun()
Returns whether the typechecking passes have run
-
hasOptimizationColors
public abstract boolean hasOptimizationColors()
Whether the AST has been annotated with optimization colors.
-
isTypeRegistryCleared
public abstract boolean isTypeRegistryCleared()
Returns `true` when type checking has run, but the type registry has been cleared.See also `clearJSTypeRegistry()`.
-
getTypeRegistry
public abstract JSTypeRegistry getTypeRegistry()
Gets a central registry of type information from the compiled JS.
-
clearJSTypeRegistry
public abstract void clearJSTypeRegistry()
-
getColorRegistry
public abstract ColorRegistry getColorRegistry()
Gets a central registry of colors from deserialized JS types.
-
setColorRegistry
public abstract void setColorRegistry(ColorRegistry registry)
Sets the color registry
-
getTopScope
public abstract TypedScope getTopScope()
Gets the top scope.
-
report
public abstract void report(JSError error)
Report an error or warning.
-
getCodingConvention
public abstract CodingConvention getCodingConvention()
Gets the current coding convention.
-
reportChangeToEnclosingScope
public abstract void reportChangeToEnclosingScope(Node n)
Passes that make modifications in a scope that is different than the Compiler.currentScope use this (eg, InlineVariables and many others)
-
reportChangeToChangeScope
public abstract void reportChangeToChangeScope(Node changeScopeRoot)
Mark modifications in a scope that is different than the Compiler.currentScope use this (eg, InlineVariables and many others)
-
getTypeMismatches
public abstract java.lang.Iterable<TypeMismatch> getTypeMismatches()
Gets the central registry of type violations.
-
parseSyntheticCode
public abstract Node parseSyntheticCode(java.lang.String filename, java.lang.String code)
Parses code for injecting, and associate it with a given source file.
-
toSource
public abstract java.lang.String toSource()
Prints a node to source code.
-
toSource
public abstract java.lang.String toSource(Node root)
Prints a node to source code.
-
getReverseAbstractInterpreter
public abstract ReverseAbstractInterpreter getReverseAbstractInterpreter()
Get an interpreter for type analysis.
-
getLifeCycleStage
public AbstractCompiler.LifeCycleStage getLifeCycleStage()
Returns the current life-cycle stage of the AST we're working on.
-
isFillFileName
public static boolean isFillFileName(java.lang.String fileName)
Returns whether a file name was created bycreateFillFileName(java.lang.String)
.
-
initRuntimeLibraryTypedAsts
public void initRuntimeLibraryTypedAsts(com.google.common.base.Optional<ColorPool.Builder> colorPoolBuilder)
Deserialize runtime libraries from a TypedAST packaged as a JAR resource and reconcile their Colors with the current inputs.This method must be called anywhere that Colors are reconciled for application to the AST. Otherwise Color information won't be consistent. `colorPoolBuilder` must be the same builder as used for the other inputs, and the caller retains ownership.
- Parameters:
colorPoolBuilder
- if present, includes inferred optimization colors on the deserialized ASTs. If absent, does not include colors.
-
getErrorManager
public abstract ErrorManager getErrorManager()
Gets the error manager.
-
getRoot
public abstract Node getRoot()
Returns the root node of the AST, which includes both externs and source.
-
getProgress
public abstract double getProgress()
- Returns:
- a number in [0,1] range indicating an approximate progress of the last compile. Note this should only be used as a hint and no assumptions should be made on accuracy, even a completed compile may choose not to set this to 1.0 at the end.
-
getExternProperties
public abstract com.google.common.collect.ImmutableSet<java.lang.String> getExternProperties()
Gets the names of the properties defined in externs or null if GatherExternProperties pass was not run yet.
-
addInputSourceMap
public abstract void addInputSourceMap(java.lang.String name, SourceMapInput sourceMap)
Adds aSourceMapInput
for the givensourceFileName
, to be used for error reporting and source map combining.
-
setAccessorSummary
public abstract void setAccessorSummary(com.google.javascript.jscomp.AccessorSummary summary)
Sets the summary of properties with getters and setters.
-
createAstFactory
public final com.google.javascript.jscomp.AstFactory createAstFactory()
Returns a new AstFactory that will add type information to the nodes it creates if and only if type checking has already happened and types have not been converted into colors.Note that the AstFactory will /not/ add colors to the AST if types have been converted into colors. The AstFactory does not understand colors, although color support could certainly be added if it proves useful.
-
createAstFactoryWithoutTypes
public final com.google.javascript.jscomp.AstFactory createAstFactoryWithoutTypes()
Returns a new AstFactory that will not add type information, regardless of whether type checking has already happened.
-
getAstAnalyzer
public AstAnalyzer getAstAnalyzer()
Returns a new AstAnalyzer configured correctly to answer questions about Nodes in the AST currently being compiled.
-
createDefaultExpressionDecomposer
public com.google.javascript.jscomp.ExpressionDecomposer createDefaultExpressionDecomposer()
-
createExpressionDecomposer
public com.google.javascript.jscomp.ExpressionDecomposer createExpressionDecomposer(com.google.common.base.Supplier<java.lang.String> uniqueNameIdSupplier, com.google.common.collect.ImmutableSet<java.lang.String> knownConstantFunctions, Scope scope)
-
getModuleMetadataMap
public abstract ModuleMetadataMap getModuleMetadataMap()
-
setModuleMetadataMap
public abstract void setModuleMetadataMap(ModuleMetadataMap moduleMetadataMap)
-
getModuleMap
public abstract ModuleMap getModuleMap()
-
setModuleMap
public abstract void setModuleMap(ModuleMap moduleMap)
-
isDebugLoggingEnabled
public final boolean isDebugLoggingEnabled()
-
createOrReopenLog
@MustBeClosed public final LogFile createOrReopenLog(java.lang.Class<?> owner, java.lang.String firstNamePart, java.lang.String... restNameParts)
Provides logging access to a file with the specified name.
-
createOrReopenIndexedLog
@MustBeClosed public final LogFile createOrReopenIndexedLog(java.lang.Class<?> owner, java.lang.String firstNamePart, java.lang.String... restNameParts)
Provides logging access to a file with the specified name, differentiated by the index of the current pass.Indexing helps in separating logs from different pass loops. The filename pattern is "[debug_log_directory]/[owner_name]/([name_part[i]]/){0,n-1}[pass_index]_[name_part[n]]".
-
-