Package org.basex.query.expr
Class Expr
java.lang.Object
org.basex.query.expr.ExprInfo
org.basex.query.expr.Expr
Abstract class for representing XQuery expressions.
Expression are divided into
ParseExpr and Value classes.- Author:
- BaseX Team 2005-21, BSD License, Christian Gruen
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract booleanaccept(ASTVisitor visitor) Traverses this expression, notifying the visitor of declared and used variables, and checking the tree for other recursive properties.final Exprarg(int i) Returns the specified argument/operand of an expression (function, list, etc).Expr[]args()Returns the arguments/operands of an expression (function, list, etc).atomItem(QueryContext qc, InputInfo ii) Evaluates the expression and returns the resulting, atomized item, orEmpty.VALUEif the expression yields an empty sequence.atomIter(QueryContext qc, InputInfo ii) Evaluates the expression and returns an iterator on the resulting, atomized items.abstract ValueatomValue(QueryContext qc, InputInfo ii) Evaluates the expression and returns the atomized items.abstract voidcheckUp()Checks if the updating semantics are satisfied.abstract ExprCompiles and optimizes the expression, assigns types and cardinalities.abstract Exprcopy(CompileContext cc, IntObjMap<Var> vm) Copies an expression.abstract VarUsageChecks how often a variable or context reference is used in this expression.data()Returns the data reference bound to this expression.voidAssigns a data reference, if supported.booleanddo()Indicates if this expression returns nodes in document order without duplicates.abstract Itemebv(QueryContext qc, InputInfo ii) Checks if the effective boolean value can be computed for this expression:abstract booleanThis function is e.g.abstract intexprSize()Counts the number of expressions in this expression's sub-tree.funcType()Returns the function type of this expression.abstract booleanIndicates if an expression has one of the specified compiler properties.protected booleanChecks if this expression has free variables.booleanChecks if an expression can be rewritten to an index access.abstract Exprinline(InlineContext ic) Inlines an expression into this one, replacing all variable or context references.abstract booleanChecks if inlining is possible.final booleanisSimple()Checks if this expression is deterministic, performs no updates, does not access the context value and position, and calls no higher-order function.abstract Itemitem(QueryContext qc, InputInfo ii) Evaluates the expression and returns the resulting item, orEmpty.VALUEif the expression yields an empty sequence.abstract Iteriter(QueryContext qc) Evaluates the expression and returns an iterator on the resulting items.voidFinds and marks tail calls, enabling TCO.mergeEbv(Expr expr, boolean or, CompileContext cc) Tries to merge two expressions that are part of an EBV test.Optimizes an already compiled expression without recompiling its sub-expressions.abstract voidrefineType(Expr expr) Refines the expression type.abstract SeqTypeseqType()Returns the static type of the resulting value.simplifyFor(CompileContext.Simplify mode, CompileContext cc) This function is called at compile time for expressions whose operands might be simplified.abstract longsize()Returns the result size, or-1if the size is unknown.abstract Itemtest(QueryContext qc, InputInfo ii) Performs a predicate test and returns the item if the test was successful.protected ExprtypeCheck(TypeCheck tc, CompileContext cc) Tries to push the given type check inside this expression.final booleanChecks if the given variable is used by this expression.booleanvacuous()Tests if this is a vacuous expression (empty sequence or error function).abstract Valuevalue(QueryContext qc) Evaluates the expression and returns the resulting value.protected static booleanvisitAll(ASTVisitor visitor, Expr... exprs) Visit all given expressions with the given visitor.Methods inherited from class org.basex.query.expr.ExprInfo
description, plan, plan, toErrorString, toString
-
Constructor Details
-
Expr
public Expr()
-
-
Method Details
-
checkUp
Checks if the updating semantics are satisfied. This function is only called if any updating expression was found in the query.- Throws:
QueryException- query exception
-
compile
Compiles and optimizes the expression, assigns types and cardinalities.- Parameters:
cc- compilation context- Returns:
- optimized expression
- Throws:
QueryException- query exception
-
optimize
Optimizes an already compiled expression without recompiling its sub-expressions.- Parameters:
cc- compilation context- Returns:
- optimized expression
- Throws:
QueryException- query exception
-
iter
Evaluates the expression and returns an iterator on the resulting items. The implementation of this method is optional.- Parameters:
qc- query context- Returns:
- iterator
- Throws:
QueryException- query exception
-
value
Evaluates the expression and returns the resulting value. If this method is not implemented,item(QueryContext, InputInfo)must be implemented instead.- Parameters:
qc- query context- Returns:
- value
- Throws:
QueryException- query exception
-
item
Evaluates the expression and returns the resulting item, orEmpty.VALUEif the expression yields an empty sequence. If this method is not implemented,value(QueryContext)must be implemented instead.- Parameters:
qc- query contextii- input info (only required bySeqinstances, which have no input info)- Returns:
- item or
Empty.VALUE - Throws:
QueryException- query exception
-
atomIter
Evaluates the expression and returns an iterator on the resulting, atomized items.- Parameters:
qc- query contextii- input info- Returns:
- iterator
- Throws:
QueryException- query exception
-
atomItem
Evaluates the expression and returns the resulting, atomized item, orEmpty.VALUEif the expression yields an empty sequence.- Parameters:
qc- query contextii- input info (only required bySeqinstances, which have no input info)- Returns:
- item or
Empty.VALUE - Throws:
QueryException- query exception
-
atomValue
Evaluates the expression and returns the atomized items.- Parameters:
qc- query contextii- input info (only required bySeqinstances, which have no input info)- Returns:
- atomized item
- Throws:
QueryException- query exception
-
ebv
Checks if the effective boolean value can be computed for this expression:
- If it yields an empty sequence,
Bln.FALSEwill be returned. - If it yields a single item, this item will be returned.
- If it yields nodes, the first node will be returned.
- Otherwise, an error will be raised.
A single numeric item may later be evaluated as positional predicate.
- Parameters:
qc- query contextii- input info (required forSeqinstances, which have no input info)- Returns:
- item
- Throws:
QueryException- query exception
- If it yields an empty sequence,
-
test
Performs a predicate test and returns the item if the test was successful. The returned item is required for full-text scoring.- Parameters:
qc- query contextii- input info (required forSeqinstances, which have no input info)- Returns:
- item or
null - Throws:
QueryException- query exception
-
vacuous
public boolean vacuous()Tests if this is a vacuous expression (empty sequence or error function). This check is needed for updating queries.- Returns:
- result of check
-
data
Returns the data reference bound to this expression. This method is currently overwritten byDBNode,DBNodeSeq,AxisPathandVarRef.- Returns:
- data reference (can be
null)
-
data
Assigns a data reference, if supported.- Parameters:
dt- data reference
-
size
public abstract long size()Returns the result size, or-1if the size is unknown.- Returns:
- result of check
-
has
Indicates if an expression has one of the specified compiler properties. This method must only be called at compile time. It is invoked to test properties of sub-expressions. It returnstrueif at least flag matches an expression.- Parameters:
flags- flags to be checked- Returns:
- result of check
-
uses
Checks if the given variable is used by this expression.- Parameters:
var- variable to be checked- Returns:
trueif the variable is used
-
inlineable
Checks if inlining is possible. This function is called byInlineContext.inlineable(org.basex.query.expr.Expr...)and:CNode.inlineable(org.basex.query.InlineContext)returns false if the new expression construct new nodes. The following tests might reject inlining if the expression is a context reference:- Parameters:
ic- inlining context- Returns:
- result of check
-
count
Checks how often a variable or context reference is used in this expression. This function is called by:-
Closure.optimize(org.basex.query.CompileContext) -
GFLWOR.inlineForLet(org.basex.query.CompileContext) -
GFLWOR.optimizePos(org.basex.query.CompileContext) -
GFLWOR.simplify(org.basex.query.CompileContext) -
GFLWOR.unusedVars(org.basex.query.CompileContext) -
SimpleMap.optimize(org.basex.query.CompileContext) -
TypeswitchGroup.optimize(org.basex.query.CompileContext)
-
-
inline
Inlines an expression into this one, replacing all variable or context references. This function is called byInlineContext.inline(Expr)(see invocations of this functions for further inlinings). The variable reference is replaced in: The context is replaced in:- Parameters:
ic- inlining context- Returns:
- resulting expression if something has changed,
nullotherwise - Throws:
QueryException- query exception
-
copy
Copies an expression. Used for inlining functions, or for copying static queries. It is utilized byVarRef.inline(org.basex.query.InlineContext),FuncItem.inline(org.basex.query.expr.Expr[], org.basex.query.CompileContext),Closure.inline(org.basex.query.InlineContext)andStaticFunc.inline(org.basex.query.expr.Expr[], org.basex.query.CompileContext).- Parameters:
cc- compilation contextvm- mapping from old variable IDs to new variable copies. Required byClosure.copy(org.basex.query.CompileContext, org.basex.util.hash.IntObjMap<org.basex.query.var.Var>)andVarRef.copy(org.basex.query.CompileContext, org.basex.util.hash.IntObjMap<org.basex.query.var.Var>)- Returns:
- copied expression
-
simplifyFor
This function is called at compile time for expressions whose operands might be simplified.- Parameters:
mode- mode of simplificationcc- compilation context- Returns:
- simplified or original expression
- Throws:
QueryException- query exception- See Also:
-
seqType
Returns the static type of the resulting value.- Returns:
- result of check
-
funcType
Returns the function type of this expression.- Returns:
- function type, or
nullif expression yields no functions
-
ddo
public boolean ddo()Indicates if this expression returns nodes in document order without duplicates.- Returns:
- result of check
-
args
Returns the arguments/operands of an expression (function, list, etc).- Returns:
- arguments or
null
-
arg
Returns the specified argument/operand of an expression (function, list, etc).- Parameters:
i- index of argument- Returns:
- arguments or
null
-
indexAccessible
Checks if an expression can be rewritten to an index access. If so, the index expression will be bound toIndexInfo.expr. This method will be called by thePathexpression.- Parameters:
ii- index info- Returns:
- true if an index can be used
- Throws:
QueryException- query exception
-
isSimple
public final boolean isSimple()Checks if this expression is deterministic, performs no updates, does not access the context value and position, and calls no higher-order function.- Returns:
- result of check
-
hasFreeVars
protected boolean hasFreeVars()Checks if this expression has free variables.- Returns:
trueif there are variables which are used but not declared in this expression,falseotherwise
-
mergeEbv
Tries to merge two expressions that are part of an EBV test. Called byAnd,Or),StepandFilter. Overwritten byCmpG,CmpIR,CmpR,CmpSR,ItrPos,Posand others.- Parameters:
expr- second expressionor- union or intersectioncc- compilation context- Returns:
- optimized expression or
null - Throws:
QueryException- query exception
-
markTailCalls
Finds and marks tail calls, enabling TCO.- Parameters:
cc- compilation context,nullif the changes should not be reported
-
accept
Traverses this expression, notifying the visitor of declared and used variables, and checking the tree for other recursive properties.- Parameters:
visitor- visitor- Returns:
- if the walk should be continued
-
visitAll
Visit all given expressions with the given visitor.- Parameters:
visitor- visitorexprs- expressions to visit- Returns:
- success flag
-
exprSize
public abstract int exprSize()Counts the number of expressions in this expression's sub-tree. This method is e.g. called byStaticFunc.inline(org.basex.query.expr.Expr[], org.basex.query.CompileContext)to check if an expression is small enough to be inlined.- Returns:
- number of expressions
-
refineType
Refines the expression type.- Parameters:
expr- original expression
-
typeCheck
Tries to push the given type check inside this expression.- Parameters:
tc- type check to push into the expressioncc- compilation context- Returns:
- the resulting expression if successful,
nullotherwise - Throws:
QueryException- query exception
-
equals
This function is e.g. called by:If.optimize(CompileContext),Switch.optimize(CompileContext),Typeswitch.optimize(CompileContext), in order to discard identical expressions.CmpR.mergeEbv(Expr, boolean, CompileContext)orCmpSR.mergeEbv(Expr, boolean, CompileContext), in order to merge expressions with identical input.CmpG.optimize(CompileContext)orCmpV.optimize(CompileContext), in order to pre-evaluate equality tests.CmpG.optimize(CompileContext)orPos.get(Expr, CmpV.OpV, InputInfo, CompileContext), in order to compare the start and end value.PathCache, in order to find identical root values at runtime.
-