Class CompileContext


  • public final class CompileContext
    extends Object
    Compilation context.
    Author:
    BaseX Team 2005-22, BSD License, Christian Gruen
    • Field Detail

      • MAX_PREEVAL

        public static final int MAX_PREEVAL
        Limit for the size of sequences that are pre-evaluated.
        See Also:
        Constant Field Values
      • dynamic

        public final boolean dynamic
        Dynamic compilation.
    • Constructor Detail

      • CompileContext

        public CompileContext​(QueryContext qc,
                              boolean dynamic)
        Constructor.
        Parameters:
        qc - query context
        dynamic - dynamic compilation
    • Method Detail

      • info

        public void info​(String string,
                         Object... ext)
        Adds some compilation info.
        Parameters:
        string - evaluation info
        ext - text text extensions
      • pushScope

        public void pushScope​(VarScope vs)
        Pushes a new variable scope to the stack.
        Parameters:
        vs - variable scope
      • removeScope

        public VarScope removeScope()
        Removes and returns the current variable scope.
        Returns:
        the removed element
      • removeScope

        public void removeScope​(Scope scope)
        Prepares the variable scope for being compiled. This method should be run after compiling a scope.
        Parameters:
        scope - scope
      • pushFocus

        public void pushFocus​(Expr expr)
        Pushes the current query focus onto the stack and, if possible, assigns a new dummy item.
        Parameters:
        expr - focus expression (can be null)
      • updateFocus

        public void updateFocus​(Expr expr)
        Assigns a new dummy item to the query focus.
        Parameters:
        expr - focus expression
      • get

        public Expr get​(Expr expr,
                        QuerySupplier<Expr> func)
                 throws QueryException
        Evaluates a function in the given focus.
        Parameters:
        expr - focus expression (can be null)
        func - function to evaluate
        Returns:
        resulting expression
        Throws:
        QueryException - query exception
      • ok

        public boolean ok​(Expr expr,
                          QuerySupplier<Boolean> func)
                   throws QueryException
        Evaluates a function in the given focus.
        Parameters:
        expr - focus expression (can be null)
        func - function to evaluate
        Returns:
        result of check
        Throws:
        QueryException - query exception
      • removeFocus

        public void removeFocus()
        Removes the current query focus from the stack.
      • nestedFocus

        public boolean nestedFocus()
        Indicates if the query focus is nested.
        Returns:
        result of check
      • vs

        public VarScope vs()
        Returns the current variable scope.
        Returns:
        variable scope
      • sc

        public StaticContext sc()
        Returns the current static context.
        Returns:
        static context
      • copy

        public Var copy​(Var var,
                        IntObjMap<Var> vm)
        Creates a new copy of the given variable in this scope.
        Parameters:
        var - variable to copy (can be null)
        vm - variable mapping (can be null)
        Returns:
        new variable, or null if the supplied variable is null
      • preEval

        public Expr preEval​(Expr expr)
                     throws QueryException
        Pre-evaluates the specified expression.
        Parameters:
        expr - expression
        Returns:
        optimized expression
        Throws:
        QueryException - query exception
      • emptySeq

        public Expr emptySeq​(Expr expr)
        Replaces the specified expression with an empty sequence.
        Parameters:
        expr - original expression
        Returns:
        optimized expression
      • simplify

        public Expr simplify​(Expr expr,
                             Expr result,
                             CompileContext.Simplify mode)
                      throws QueryException
        Replaces an expression with a simplified one and simplifies the result expression. As the simplified expression may have a different type, no type refinement is performed.
        Parameters:
        expr - original expression
        result - resulting expression
        mode - mode of simplification
        Returns:
        optimized expression
        Throws:
        QueryException - query exception
      • replaceWith

        public Expr replaceWith​(Expr expr,
                                Expr result)
        Replaces an expression with the specified one.
        Parameters:
        expr - original expression
        result - resulting expression
        Returns:
        optimized expression
      • error

        public StandardFunc error​(QueryException qe,
                                  Expr expr)
        Creates an error function instance.
        Parameters:
        qe - exception to be raised
        expr - expression that caused the error message
        Returns:
        function
      • compileOrError

        public Expr compileOrError​(Expr expr,
                                   boolean error)
                            throws QueryException
        Compiles an expression or creates an error.
        Parameters:
        expr - expression
        error - return error
        Returns:
        compiled expression or error.
        Throws:
        QueryException - query exception
      • function

        public Expr function​(AFunction function,
                             InputInfo ii,
                             Expr... exprs)
                      throws QueryException
        Creates and returns an optimized instance of the specified function.
        Parameters:
        function - function
        ii - input info
        exprs - expressions
        Returns:
        function
        Throws:
        QueryException - query exception
      • merge

        public Expr merge​(Expr expr,
                          Expr result,
                          InputInfo ii)
                   throws QueryException
        Creates a list expression from an expression to be swallowed and a result expression.
        Parameters:
        expr - expression to be swallowed
        result - result expression
        ii - input info
        Returns:
        function
        Throws:
        QueryException - query exception
      • replicate

        public Expr replicate​(Expr expr,
                              Expr count,
                              InputInfo ii)
                       throws QueryException
        Replicates an expression.
        Parameters:
        expr - expression
        count - count expression
        ii - input info
        Returns:
        function
        Throws:
        QueryException - query exception
      • unroll

        public ExprList unroll​(Expr expr,
                               boolean items)
        Returns an expression list for unrolling an expression.
        Parameters:
        expr - expression to analyze
        items - unroll lists only if all its expressions yield items the number of which do not exceed limit
        Returns:
        expression list or null