OptimizerContext
OptimizerContext embeds an environment and expression factory for type-safe AST rewrites.
Generated subexpressions use ids consistent with parsed expressions, and copied macro metadata is coordinated with the ids assigned to copied expression trees.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new OptimizerContext(
options):OptimizerContext
constructor initializes a context for a single static optimization run.
Parameters
Section titled “Parameters”options
Section titled “options”idSeed
Section titled “idSeed”number
sourceInfo
Section titled “sourceInfo”Returns
Section titled “Returns”OptimizerContext
Methods
Section titled “Methods”ast(
expr):AST
ast creates an AST from an expression using source info managed by this context.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”bindMacro()
Section titled “bindMacro()”bindMacro(
options):MacroExpressionPair
bindMacro creates an expanded cel.bind expression and its unexpanded macro signature.
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”call()
Section titled “call()”call(
options):Expr
call creates a global function call invocation expression.
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”clearMacroCall()
Section titled “clearMacroCall()”clearMacroCall(
id):void
clearMacroCall clears the macro at the given expression id.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
copyAst()
Section titled “copyAst()”copyAst(
input):object
copyAst creates a renumbered copy of an input AST’s expression and source info.
Use this method before merging an expression from one AST into another.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”object
expr:
Expr
sourceInfo
Section titled “sourceInfo”sourceInfo:
SourceInfo
copyAstAndMetadata()
Section titled “copyAstAndMetadata()”copyAstAndMetadata(
input):Expr
copyAstAndMetadata copies an AST and propagates its macro and offset metadata.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”env():
Env
env returns the environment currently associated with the optimizer context.
Returns
Section titled “Returns”extendEnv()
Section titled “extendEnv()”extendEnv(
options?):void
extendEnv augments the context environment with additional option-object configuration.
Parameters
Section titled “Parameters”options?
Section titled “options?”EnvOptions = {}
Returns
Section titled “Returns”void
hasMacro()
Section titled “hasMacro()”hasMacro(
options):MacroExpressionPair
hasMacro creates a test-only select and an unexpanded has macro signature.
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”ident()
Section titled “ident()”ident(
name):Expr
ident creates an identifier expression.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”list()
Section titled “list()”list(
options):Expr
list creates a list expression with optional element indices.
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”literal()
Section titled “literal()”literal(
value):Expr
literal creates a CEL literal expression.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”macroCalls()
Section titled “macroCalls()”macroCalls():
Map<number,Expr>
macroCalls returns the macro calls currently tracked by the context.
Returns
Section titled “Returns”Map<number, Expr>
map(
entries):Expr
map creates a map from entry expressions.
Parameters
Section titled “Parameters”entries
Section titled “entries”Returns
Section titled “Returns”mapEntry()
Section titled “mapEntry()”mapEntry(
options):EntryExpr
mapEntry creates a map entry expression.
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”memberCall()
Section titled “memberCall()”memberCall(
options):Expr
memberCall creates a receiver-style function call invocation expression.
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”select()
Section titled “select()”select(
options):Expr
select creates a field selection expression.
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”setMacroCall()
Section titled “setMacroCall()”setMacroCall(
options):void
setMacroCall sets macro call metadata for the given expression id.
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”void
struct()
Section titled “struct()”struct(
options):Expr
struct creates a typed struct expression.
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”structField()
Section titled “structField()”structField(
options):EntryExpr
structField creates a struct field initializer.
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”updateExpr()
Section titled “updateExpr()”updateExpr(
options):void
updateExpr updates a target expression while preserving macro metadata.
The update handles every combination of macro and non-macro target and replacement nodes.
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”void