Package dev.cel.optimizer
Interface CelAstOptimizer
-
- All Known Implementing Classes:
ConstantFoldingOptimizer
public interface CelAstOptimizerPublic interface for performing a single, custom optimization on an AST.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description CelAbstractSyntaxTreeoptimize(CelNavigableAst navigableAst, Cel cel)Optimizes a single AST.default CelAbstractSyntaxTreereplaceSubtree(CelAbstractSyntaxTree ast, CelExpr newExpr, long exprIdToReplace)Replaces a subtree in the given AST.
-
-
-
Method Detail
-
optimize
CelAbstractSyntaxTree optimize(CelNavigableAst navigableAst, Cel cel) throws CelOptimizationException
Optimizes a single AST.- Throws:
CelOptimizationException
-
replaceSubtree
default CelAbstractSyntaxTree replaceSubtree(CelAbstractSyntaxTree ast, CelExpr newExpr, long exprIdToReplace)
Replaces a subtree in the given AST. This operation is intended for AST optimization purposes.This is a very dangerous operation. Callers should re-typecheck the mutated AST and additionally verify that the resulting AST is semantically valid.
All expression IDs will be renumbered in a stable manner to ensure there's no ID collision between the nodes. The renumbering occurs even if the subtree was not replaced.
This will scrub out the description, positions and line offsets from
CelSource. If the source contains macro calls, its call IDs will be to be consistent with the renumbered IDs in the AST.- Parameters:
ast- Original ast to mutate.newExpr- New CelExpr to replace the subtree with.exprIdToReplace- Expression id of the subtree that is getting replaced.
-
-