Interface CelAstOptimizer

  • All Known Implementing Classes:
    ConstantFoldingOptimizer

    public interface CelAstOptimizer
    Public interface for performing a single, custom optimization on an AST.
    • Method Detail

      • 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.