Modifier and Type | Class and Description |
---|---|
static class |
Expr.Flag
Flags that influence query compilation.
|
Constructor and Description |
---|
Expr() |
Modifier and Type | Method and Description |
---|---|
abstract boolean |
accept(ASTVisitor visitor)
Traverses this expression, notifying the visitor of declared and used variables,
and checking the tree for other recursive properties.
|
abstract Item |
atomItem(QueryContext qc,
InputInfo ii)
Evaluates the expression and returns zero or one atomized item, or an error.
|
Iter |
atomIter(QueryContext qc,
InputInfo ii)
Evaluates the expression and returns zero or one atomized item, or an error.
|
abstract Value |
atomValue(QueryContext qc,
InputInfo ii)
Evaluates the expression and returns the atomized items.
|
abstract void |
checkUp()
Checks if all updating expressions are correctly placed.
|
abstract Expr |
compile(QueryContext qc,
VarScope scp)
Compiles and optimizes the expression, assigns types and cardinalities.
|
abstract Expr |
copy(QueryContext qc,
VarScope scp,
IntObjMap<Var> vs)
Copies an expression.
|
abstract VarUsage |
count(Var var)
Checks how often a variable is used in this expression.
|
Data |
data()
Returns the data reference bound to this expression.
|
abstract Item |
ebv(QueryContext qc,
InputInfo ii)
Checks if the effective boolean value can be computed for this expression:
If it yields an empty sequence,
Bln.FALSE will be returned. |
abstract int |
exprSize()
Counts the number of expressions in this expression's sub-tree.
|
abstract boolean |
has(Expr.Flag flag)
Indicates if an expression has the specified compiler property.
|
protected boolean |
hasFreeVars()
Checks if this expression has free variables.
|
boolean |
indexAccessible(IndexInfo ii)
Checks if an expression can be rewritten to an index access.
|
abstract Expr |
inline(QueryContext qc,
VarScope scp,
Var var,
Expr ex)
Inlines an expression into this one, replacing all references to the given variable.
|
protected static boolean |
inlineAll(QueryContext qc,
VarScope scp,
Expr[] arr,
Var var,
Expr ex)
Inlines the given expression into all elements of the given array.
|
boolean |
isEmpty()
Tests if this is an empty sequence.
|
boolean |
isFunction(Function func)
Checks if this expression is a certain function.
|
boolean |
isVacuous()
Tests if this is a vacuous expression (empty sequence or error function).
|
boolean |
isValue()
Tests if this is a value.
|
abstract Item |
item(QueryContext qc,
InputInfo ii)
Evaluates the expression and returns the resulting item,
or a
null reference if the expression yields an empty sequence. |
abstract Iter |
iter(QueryContext qc)
Evaluates the expression and returns an iterator on the resulting items.
|
boolean |
iterable()
Indicates if the items returned by this expression are iterable, i.e., if returned nodes are
in document order and contain no duplicates.
|
void |
markTailCalls(QueryContext qc)
Finds and marks tail calls, enabling TCO.
|
Expr |
optimize(QueryContext qc,
VarScope scp)
Optimizes an already compiled expression without recompiling its sub-expressions.
|
Expr |
optimizeEbv(QueryContext qc,
VarScope scp)
|
abstract boolean |
removable(Var var)
Checks if the specified variable is replaceable by a context value.
|
boolean |
sameAs(Expr cmp)
Compares the current and specified expression for equality.
|
abstract SeqType |
seqType()
Returns the static type of the resulting value.
|
abstract long |
size()
Returns the sequence size or 1.
|
abstract Item |
test(QueryContext qc,
InputInfo ii)
Performs a predicate test and returns the item the if test was successful.
|
protected Expr |
typeCheck(TypeCheck tc,
QueryContext qc,
VarScope scp)
Tries to push the given type check inside this expression.
|
boolean |
uses(Var var)
Checks if the given variable is used by this expression.
|
abstract Value |
value(QueryContext qc)
Evaluates the expression and returns the resulting value.
|
protected static boolean |
visitAll(ASTVisitor visitor,
Expr... exprs)
Visit all given expressions with the given visitor.
|
addPlan, addPlan, description, plan, planAttr, planElem, toErrorString, toString
public abstract void checkUp() throws QueryException
QueryException
- query exceptionpublic abstract Expr compile(QueryContext qc, VarScope scp) throws QueryException
QueryContext.compile()
.qc
- query contextscp
- variable scopeQueryException
- query exceptionpublic Expr optimize(QueryContext qc, VarScope scp) throws QueryException
qc
- query contextscp
- variable scopeQueryException
- query exceptionpublic abstract Iter iter(QueryContext qc) throws QueryException
item(QueryContext, InputInfo)
must be implemented
by an expression, as it may be called by this method.qc
- query contextQueryException
- query exceptionpublic abstract Item item(QueryContext qc, InputInfo ii) throws QueryException
null
reference if the expression yields an empty sequence.
If this method is not overwritten, iter(QueryContext)
must be implemented by an
expression, as it may be called by this method.qc
- query contextii
- input infonull
QueryException
- query exceptionpublic abstract Value value(QueryContext qc) throws QueryException
qc
- query contextQueryException
- query exceptionpublic final Iter atomIter(QueryContext qc, InputInfo ii) throws QueryException
qc
- query contextii
- input infoQueryException
- query exceptionpublic abstract Item atomItem(QueryContext qc, InputInfo ii) throws QueryException
qc
- query contextii
- input infoQueryException
- query exceptionpublic abstract Value atomValue(QueryContext qc, InputInfo ii) throws QueryException
qc
- query contextii
- input infoQueryException
- query exceptionpublic abstract Item ebv(QueryContext qc, InputInfo ii) throws QueryException
Checks if the effective boolean value can be computed for this expression:
Bln.FALSE
will be returned.
A single numeric item may later be evaluated as positional predicate.
qc
- query contextii
- input infoQueryException
- query exceptionpublic abstract Item test(QueryContext qc, InputInfo ii) throws QueryException
qc
- query contextii
- input infoQueryException
- query exceptionpublic boolean isEmpty()
Empty
class, which represents the empty sequence.public boolean isVacuous()
public boolean isValue()
public Data data()
DBNode
and DBNodeSeq
and some more expressions.public abstract long size()
public abstract boolean has(Expr.Flag flag)
true
if at least one test is successful.flag
- flag to be foundpublic final boolean uses(Var var)
var
- variable to be checkedtrue
if the variable is used, false
otherwisepublic abstract boolean removable(Var var)
Preds.removable(org.basex.query.var.Var)
if one of the variables is used within a predicate.Path.removable(org.basex.query.var.Var)
if the variable occurs within the path.GFLWOR.compile(QueryContext, VarScope)
to rewrite where
clauses into predicates.var
- variable to be replacedpublic abstract VarUsage count(Var var)
SwitchCase.countCases(org.basex.query.var.Var)
or (indirectly)
GFLWOR.inlineLets(org.basex.query.QueryContext, org.basex.query.var.VarScope)
.var
- variable to look forVarUsage
public abstract Expr inline(QueryContext qc, VarScope scp, Var var, Expr ex) throws QueryException
GFLWOR.inlineLets(org.basex.query.QueryContext, org.basex.query.var.VarScope)
and For.toPredicate(org.basex.query.QueryContext, org.basex.query.var.VarScope, org.basex.query.expr.Expr)
,
and the variable reference is replaced in VarRef.inline(org.basex.query.QueryContext, org.basex.query.var.VarScope, org.basex.query.var.Var, org.basex.query.expr.Expr)
.qc
- query context for reoptimizationscp
- variable scope for reoptimizationvar
- variable to replaceex
- expression to inlinenull
otherwiseQueryException
- query exceptionprotected static boolean inlineAll(QueryContext qc, VarScope scp, Expr[] arr, Var var, Expr ex) throws QueryException
qc
- query contextscp
- variable scopearr
- arrayvar
- variable to replaceex
- expression to inlinetrue
if the array has changed, false
otherwiseQueryException
- query exceptionpublic abstract Expr copy(QueryContext qc, VarScope scp, IntObjMap<Var> vs)
qc
- query contextscp
- variable scope for creating new variablesvs
- mapping from old variable IDs to new variable copiespublic Expr optimizeEbv(QueryContext qc, VarScope scp) throws QueryException
This method is e.g. overwritten by expressions like CmpG
, CmpV
,
FnBoolean
, FnExists
, Path
or Filter
.
It is called at compile time by expressions that perform
effective boolean value tests (e.g. If
or Preds
).
If the arguments of the called expression return a boolean anyway,
the expression will be simplified.
Example in CmpV
:
if($x eq true())
is rewritten to if($x)
if $x
is known to return a single boolean.
qc
- query contextscp
- variable scopeQueryException
- query exceptionpublic abstract SeqType seqType()
public boolean iterable()
AxisPath
.public boolean indexAccessible(IndexInfo ii) throws QueryException
IndexInfo.expr
.
This method will be called by Path.index(org.basex.query.QueryContext, org.basex.query.value.Value)
.ii
- index infoQueryException
- query exceptionpublic boolean sameAs(Expr cmp)
cmp
- expression to be comparedpublic boolean isFunction(Function func)
func
- function definitionprotected boolean hasFreeVars()
true
if there are variables which are used but not declared in this expression,
false
otherwisepublic void markTailCalls(QueryContext qc)
qc
- query context, null
if the changes should not be reportedpublic abstract boolean accept(ASTVisitor visitor)
visitor
- visitorprotected static boolean visitAll(ASTVisitor visitor, Expr... exprs)
visitor
- visitorexprs
- expressions to visitpublic abstract int exprSize()
StaticFunc.inline(org.basex.query.QueryContext, org.basex.query.util.list.AnnList, org.basex.query.expr.Expr)
to check if an expression
is small enough to be inlined.protected Expr typeCheck(TypeCheck tc, QueryContext qc, VarScope scp) throws QueryException
tc
- type check to push into the expressionqc
- query contextscp
- variable scopenull
otherwiseQueryException
- query exceptionCopyright © 2005–2015 BaseX Team. All rights reserved.