Package org.basex.query
Class CompileContext
- java.lang.Object
-
- org.basex.query.CompileContext
-
public final class CompileContext extends Object
Compilation context.- Author:
- BaseX Team 2005-23, BSD License, Christian Gruen
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CompileContext.Simplify
Compile-time simplifications.
-
Field Summary
Fields Modifier and Type Field Description boolean
dynamic
Dynamic compilation.static int
MAX_PREEVAL
Limit for the size of sequences that are pre-evaluated.QueryContext
qc
Query context.
-
Constructor Summary
Constructors Constructor Description CompileContext(QueryContext qc, boolean dynamic)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Expr
compileOrError(Expr expr, boolean error)
Compiles an expression or creates an error.Var
copy(Var var, IntObjMap<Var> vm)
Creates a new copy of the given variable in this scope.Expr
emptySeq(Expr expr)
Replaces the specified expression with an empty sequence.StandardFunc
error(QueryException qe, Expr expr)
Creates an error function instance.Expr
function(AFunction function, InputInfo ii, Expr... exprs)
Creates and returns an optimized instance of the specified function.Expr
get(Expr expr, QuerySupplier<Expr> func)
Evaluates a function within the focus of the supplied expression.void
info(String string, Object... ext)
Adds some compilation info.Expr
merge(Expr expr, Expr result, InputInfo ii)
Creates a list expression from an expression to be swallowed and a result expression.boolean
nestedFocus()
Indicates if the query focus is nested.boolean
ok(Expr expr, QuerySupplier<Boolean> func)
Evaluates a function within the focus of the supplied expression.Expr
preEval(Expr expr)
Pre-evaluates the specified expression.void
pushFocus(Expr expr)
Pushes the current query focus onto the stack and, if possible, assigns a new dummy item.void
pushScope(VarScope vs)
Pushes a new variable scope to the stack.void
removeFocus()
Removes the current query focus from the stack.VarScope
removeScope()
Removes and returns the current variable scope.void
removeScope(Scope scope)
Prepares the variable scope for being compiled.Expr
replaceWith(Expr expr, Expr result)
Replaces an expression with the specified one.Expr
replicate(Expr expr, Expr count, InputInfo ii)
Replicates an expression.StaticContext
sc()
Returns the current static context.Expr
simplify(Expr expr, Expr result, CompileContext.Simplify mode)
Replaces an expression with a simplified one and simplifies the result expression.ExprList
unroll(Expr expr, boolean items)
Returns an expression list for unrolling an expression.void
updateFocus(Expr expr)
Assigns a new dummy item to the query focus.VarScope
vs()
Returns the current variable scope.
-
-
-
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
-
qc
public final QueryContext qc
Query context.
-
dynamic
public final boolean dynamic
Dynamic compilation.
-
-
Constructor Detail
-
CompileContext
public CompileContext(QueryContext qc, boolean dynamic)
Constructor.- Parameters:
qc
- query contextdynamic
- dynamic compilation
-
-
Method Detail
-
info
public void info(String string, Object... ext)
Adds some compilation info.- Parameters:
string
- evaluation infoext
- 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 benull
)
-
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 within the focus of the supplied expression.- Parameters:
expr
- focus expression (can benull
)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 within the focus of the supplied expression.- Parameters:
expr
- focus expression (can benull
)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 benull
)vm
- variable mapping (can benull
)- Returns:
- new variable, or
null
if the supplied variable isnull
-
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 expressionresult
- resulting expressionmode
- 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 expressionresult
- resulting expression- Returns:
- optimized expression
-
error
public StandardFunc error(QueryException qe, Expr expr)
Creates an error function instance.- Parameters:
qe
- exception to be raisedexpr
- 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
- expressionerror
- 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
- functionii
- input infoexprs
- 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 swallowedresult
- result expressionii
- 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
- expressioncount
- count expressionii
- input info- Returns:
- function
- Throws:
QueryException
- query exception
-
-