public final class Closure extends Single implements Scope, XQFunctionExpr
Constructor and Description |
---|
Closure(InputInfo info,
SeqType ret,
Var[] args,
Expr expr,
AnnList anns,
Map<Var,Expr> nonLocal,
StaticContext sc,
VarScope scope)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(ASTVisitor visitor)
Traverses this expression, notifying the visitor of declared and used variables,
and checking the tree for other recursive properties.
|
void |
adoptSignature(FuncType ft)
Fixes the function type of this closure after it was generated for a function literal during
parsing.
|
AnnList |
annotations()
Annotations of this function.
|
QNm |
argName(int pos)
Name of the argument at the given position.
|
int |
arity()
Number of arguments this function takes.
|
void |
checkUp()
Checks if all updating expressions are correctly placed.
|
void |
compile(QueryContext qc)
Compiles the expression contained in this scope.
|
Expr |
compile(QueryContext qc,
VarScope scp)
Compiles and optimizes the expression, assigns types and cardinalities.
|
boolean |
compiled()
Checks if this scope has already been compiled.
|
Expr |
copy(QueryContext qc,
VarScope scp,
IntObjMap<Var> vs)
Copies an expression.
|
VarUsage |
count(Var var)
Checks how often a variable is used in this expression.
|
int |
exprSize()
Counts the number of expressions in this expression's sub-tree.
|
QNm |
funcName()
Name of this function,
null means anonymous function. |
FuncType |
funcType()
Type of this function.
|
boolean |
has(Expr.Flag flag)
Indicates if an expression has the specified compiler property.
|
Expr |
inline(QueryContext qc,
VarScope scp,
Var var,
Expr ex)
Inlines an expression into this one, replacing all references to the given variable.
|
Expr |
inlineExpr(Expr[] exprs,
QueryContext qc,
VarScope scp,
InputInfo ii)
Tries to inline this function with the given argument expressions.
|
boolean |
isVacuous()
Tests if this is a vacuous expression (empty sequence or error function).
|
FuncItem |
item(QueryContext qc,
InputInfo ii)
Evaluates the expression and returns the resulting item,
or a
null reference if the expression yields an empty sequence. |
ValueIter |
iter(QueryContext qc)
Evaluates the expression and returns an iterator on the resulting items.
|
Iterator<Map.Entry<Var,Expr>> |
nonLocalBindings()
Returns an iterator over the non-local bindings of this closure.
|
Expr |
optimize(QueryContext qc,
VarScope scp)
Optimizes an already compiled expression without recompiling its sub-expressions.
|
void |
plan(FElem plan)
Creates an expression tree.
|
boolean |
removable(Var var)
Checks if the specified variable is replaceable by a context value.
|
String |
toString() |
static Closure |
unknownLit(QNm name,
int arity,
QueryContext qc,
StaticContext sc,
InputInfo ii)
Creates a function literal for a function that was not yet encountered while parsing.
|
Value |
value(QueryContext qc)
Evaluates the expression and returns the resulting value.
|
boolean |
visit(ASTVisitor visitor)
Traverses this scope with the given
ASTVisitor . |
atomItem, atomValue, checkAtomic, checkNoEmpty, checkNoEmpty, checkNoneUp, checkNoUp, checkType, compBln, copyType, ctxValue, ebv, optPre, optPre, preEval, seqType, seqType, size, test, toArray, toArray, toAtomItem, toB64, toB64, toBin, toBin, toBoolean, toBoolean, toBytes, toBytes, toDouble, toDouble, toElem, toEmptyNode, toEmptyToken, toFloat, toFunc, toItem, toLong, toLong, toMap, toMap, toNode, toNode, toNumber, toQNm, toQNm, toToken, toToken
atomIter, data, hasFreeVars, indexAccessible, inlineAll, isEmpty, isFunction, isValue, iterable, markTailCalls, optimizeEbv, sameAs, typeCheck, uses, visitAll
addPlan, addPlan, description, planAttr, planElem, toErrorString
public Closure(InputInfo info, SeqType ret, Var[] args, Expr expr, AnnList anns, Map<Var,Expr> nonLocal, StaticContext sc, VarScope scope)
info
- input inforet
- return typeargs
- argumentsexpr
- function bodyanns
- annotationsnonLocal
- bindings for non-local variablessc
- static contextscope
- scopepublic int arity()
XQFunctionExpr
arity
in interface XQFunctionExpr
public QNm funcName()
XQFunctionExpr
null
means anonymous function.funcName
in interface XQFunctionExpr
null
public QNm argName(int pos)
XQFunctionExpr
argName
in interface XQFunctionExpr
pos
- position of the argumentpublic FuncType funcType()
XQFunctionExpr
funcType
in interface XQFunctionExpr
public AnnList annotations()
XQFunctionExpr
annotations
in interface XQFunctionExpr
public void compile(QueryContext qc) throws QueryException
Scope
compile
in interface Scope
qc
- query contextQueryException
- compilation errorspublic Expr compile(QueryContext qc, VarScope scp) throws QueryException
Expr
QueryContext.compile()
.compile
in class Single
qc
- query contextscp
- variable scopeQueryException
- query exceptionpublic Expr optimize(QueryContext qc, VarScope scp) throws QueryException
Expr
optimize
in class Expr
qc
- query contextscp
- variable scopeQueryException
- query exceptionpublic VarUsage count(Var var)
Expr
SwitchCase.countCases(org.basex.query.var.Var)
or (indirectly)
GFLWOR.inlineLets(org.basex.query.QueryContext, org.basex.query.var.VarScope)
.public Expr inline(QueryContext qc, VarScope scp, Var var, Expr ex) throws QueryException
Expr
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)
.inline
in class Single
qc
- query context for reoptimizationscp
- variable scope for reoptimizationvar
- variable to replaceex
- expression to inlinenull
otherwiseQueryException
- query exceptionpublic Expr copy(QueryContext qc, VarScope scp, IntObjMap<Var> vs)
Expr
public Expr inlineExpr(Expr[] exprs, QueryContext qc, VarScope scp, InputInfo ii) throws QueryException
XQFunctionExpr
inlineExpr
in interface XQFunctionExpr
exprs
- argument expressionsqc
- query contextscp
- variable scopeii
- input infonull
otherwiseQueryException
- query exceptionpublic FuncItem item(QueryContext qc, InputInfo ii) throws QueryException
Expr
null
reference if the expression yields an empty sequence.
If this method is not overwritten, Expr.iter(QueryContext)
must be implemented by an
expression, as it may be called by this method.item
in class ParseExpr
qc
- query contextii
- input infonull
QueryException
- query exceptionpublic Value value(QueryContext qc) throws QueryException
Expr
value
in class ParseExpr
qc
- query contextQueryException
- query exceptionpublic ValueIter iter(QueryContext qc) throws QueryException
Expr
Expr.item(QueryContext, InputInfo)
must be implemented
by an expression, as it may be called by this method.iter
in class ParseExpr
qc
- query contextQueryException
- query exceptionpublic boolean has(Expr.Flag flag)
Expr
true
if at least one test is successful.public boolean removable(Var var)
Expr
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.public void plan(FElem plan)
ExprInfo
public boolean visit(ASTVisitor visitor)
Scope
ASTVisitor
.public void checkUp() throws QueryException
Expr
checkUp
in class Single
QueryException
- query exceptionpublic boolean isVacuous()
Expr
public boolean accept(ASTVisitor visitor)
Expr
public int exprSize()
Expr
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.public boolean compiled()
Scope
public Iterator<Map.Entry<Var,Expr>> nonLocalBindings()
public void adoptSignature(FuncType ft)
ft
- function typepublic static Closure unknownLit(QNm name, int arity, QueryContext qc, StaticContext sc, InputInfo ii) throws QueryException
name
- function namearity
- function arityqc
- query contextsc
- static contextii
- input infoQueryException
- query exceptionCopyright © 2005–2015 BaseX Team. All rights reserved.