Package org.basex.query.expr
Class Typeswitch
- java.lang.Object
-
- org.basex.query.expr.ExprInfo
-
- org.basex.query.expr.Expr
-
- org.basex.query.expr.ParseExpr
-
- org.basex.query.expr.Typeswitch
-
public final class Typeswitch extends ParseExpr
Typeswitch expression.- Author:
- BaseX Team 2005-22, BSD License, Christian Gruen
-
-
Constructor Summary
Constructors Constructor Description Typeswitch(InputInfo info, Expr cond, TypeswitchGroup[] groups)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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
checkUp()
Checks if the updating semantics are satisfied.Expr
compile(CompileContext cc)
Compiles and optimizes the expression, assigns types and cardinalities.Expr
copy(CompileContext cc, IntObjMap<Var> vm)
Copies an expression.VarUsage
count(Var var)
Checks how often a variable or context reference is used in this expression.boolean
ddo()
Indicates if this expression returns items in document order without duplicates.boolean
equals(Object obj)
This function is e.g.int
exprSize()
Counts the number of expressions in this expression's subtree.boolean
has(Flag... flags)
Indicates if an expression has one of the specified compiler properties.Expr
inline(InlineContext ic)
Inlines an expression into this one, replacing all variable or context references.boolean
inlineable(InlineContext ic)
Checks if inlining is possible.Item
item(QueryContext qc, InputInfo ii)
Evaluates the expression and returns the resulting item, orEmpty.VALUE
if the expression yields an empty sequence.Iter
iter(QueryContext qc)
Evaluates the expression and returns an iterator on the resulting items.void
markTailCalls(CompileContext cc)
Finds and marks tail calls, enabling TCO.Expr
optimize(CompileContext cc)
Optimizes an already compiled expression without recompiling its sub-expressions.Expr
simplifyFor(CompileContext.Simplify mode, CompileContext cc)
Simplifies the expression.void
toString(QueryString qs)
Creates a query string.void
toXml(QueryPlan plan)
Creates a query plan.Expr
typeCheck(TypeCheck tc, CompileContext cc)
Tries to push the given type check inside this expression.boolean
vacuous()
Tests if this is a vacuous expression (empty sequence or error function).Value
value(QueryContext qc)
Evaluates the expression and returns the resulting value.-
Methods inherited from class org.basex.query.expr.ParseExpr
adoptType, atomValue, checkAllUp, checkNoEmpty, checkNoEmpty, checkNoneUp, checkNoUp, checkType, checkType, checkUp, copyType, ctxValue, data, ebv, info, refineType, seqType, size, test, toArray, toArray, toAtomItem, toB64, toB64, toBin, toBin, toBoolean, toBoolean, toBytes, toBytes, toDouble, toDouble, toElem, toFloat, toFunction, toItem, toItem, toLong, toLong, toMap, toMap, toNode, toNode, toNodeOrNull, toNumber, toNumberOrNull, toQNm, toQNm, toString, toString, toStringOrNull, toToken, toToken, toTokenOrNull, toZeroToken
-
Methods inherited from class org.basex.query.expr.Expr
arg, args, atomItem, atomIter, funcType, hasFreeVars, indexAccessible, isSimple, mergeEbv, optimizePos, simplify, uses, visitAll
-
Methods inherited from class org.basex.query.expr.ExprInfo
description, toErrorString, toString
-
-
-
-
Constructor Detail
-
Typeswitch
public Typeswitch(InputInfo info, Expr cond, TypeswitchGroup[] groups)
Constructor.- Parameters:
info
- input infocond
- conditiongroups
- case groups (last one is default)
-
-
Method Detail
-
checkUp
public void checkUp() throws QueryException
Description copied from class:Expr
Checks if the updating semantics are satisfied. This function is only called if any updating expression was found in the query.- Specified by:
checkUp
in classExpr
- Throws:
QueryException
- query exception
-
compile
public Expr compile(CompileContext cc) throws QueryException
Description copied from class:Expr
Compiles and optimizes the expression, assigns types and cardinalities.- Specified by:
compile
in classExpr
- Parameters:
cc
- compilation context- Returns:
- optimized expression
- Throws:
QueryException
- query exception
-
optimize
public Expr optimize(CompileContext cc) throws QueryException
Description copied from class:Expr
Optimizes an already compiled expression without recompiling its sub-expressions.- Overrides:
optimize
in classExpr
- Parameters:
cc
- compilation context- Returns:
- optimized expression
- Throws:
QueryException
- query exception
-
simplifyFor
public Expr simplifyFor(CompileContext.Simplify mode, CompileContext cc) throws QueryException
Description copied from class:Expr
Simplifies the expression. Overwritten by many expressions; callsExpr.simplify(Simplify, CompileContext)
otherwise.- Overrides:
simplifyFor
in classExpr
- Parameters:
mode
- mode of simplificationcc
- compilation context- Returns:
- simplified or original expression
- Throws:
QueryException
- query exception- See Also:
CompileContext.Simplify
-
iter
public Iter iter(QueryContext qc) throws QueryException
Description copied from class:Expr
Evaluates the expression and returns an iterator on the resulting items. The implementation of this method is optional.- Overrides:
iter
in classParseExpr
- Parameters:
qc
- query context- Returns:
- iterator
- Throws:
QueryException
- query exception
-
value
public Value value(QueryContext qc) throws QueryException
Description copied from class:Expr
Evaluates the expression and returns the resulting value. If this method is not implemented,Expr.item(QueryContext, InputInfo)
must be implemented instead.- Overrides:
value
in classParseExpr
- Parameters:
qc
- query context- Returns:
- value
- Throws:
QueryException
- query exception
-
item
public Item item(QueryContext qc, InputInfo ii) throws QueryException
Description copied from class:Expr
Evaluates the expression and returns the resulting item, orEmpty.VALUE
if the expression yields an empty sequence. If this method is not implemented,Expr.value(QueryContext)
must be implemented instead.- Overrides:
item
in classParseExpr
- Parameters:
qc
- query contextii
- input info (only required bySeq
instances, which have no input info)- Returns:
- item or
Empty.VALUE
- Throws:
QueryException
- query exception
-
vacuous
public boolean vacuous()
Description copied from class:Expr
Tests if this is a vacuous expression (empty sequence or error function). This check is needed for updating queries.
-
ddo
public boolean ddo()
Description copied from class:Expr
Indicates if this expression returns items in document order without duplicates.
-
has
public boolean has(Flag... flags)
Description copied from class:Expr
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 returnstrue
if at least flag matches an expression.
-
inlineable
public boolean inlineable(InlineContext ic)
Description copied from class:Expr
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:- Specified by:
inlineable
in classExpr
- Parameters:
ic
- inlining context- Returns:
- result of check
-
count
public VarUsage count(Var var)
Description copied from class:Expr
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
public Expr inline(InlineContext ic) throws QueryException
Description copied from class:Expr
Inlines an expression into this one, replacing all variable or context references. This function is called byInlineContext.inline(Expr)
(see invocations of these functions for further inlinings). The variable reference is replaced in: The context is replaced in:- Specified by:
inline
in classExpr
- Parameters:
ic
- inlining context- Returns:
- resulting expression if something has changed,
null
otherwise - Throws:
QueryException
- query exception
-
typeCheck
public Expr typeCheck(TypeCheck tc, CompileContext cc) throws QueryException
Description copied from class:Expr
Tries to push the given type check inside this expression.- Overrides:
typeCheck
in classExpr
- Parameters:
tc
- type check to push into the expressioncc
- compilation context- Returns:
- the resulting expression if successful,
null
otherwise - Throws:
QueryException
- query exception
-
copy
public Expr copy(CompileContext cc, IntObjMap<Var> vm)
Description copied from class:Expr
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)
.- Specified by:
copy
in classExpr
- 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
-
markTailCalls
public void markTailCalls(CompileContext cc)
Description copied from class:Expr
Finds and marks tail calls, enabling TCO.- Overrides:
markTailCalls
in classExpr
- Parameters:
cc
- compilation context,null
if the changes should not be reported
-
accept
public boolean accept(ASTVisitor visitor)
Description copied from class:Expr
Traverses this expression, notifying the visitor of declared and used variables, and checking the tree for other recursive properties.
-
exprSize
public int exprSize()
Description copied from class:Expr
Counts the number of expressions in this expression's subtree. 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.
-
equals
public boolean equals(Object obj)
Description copied from class:Expr
This function is e.g. called by:If.optimize(CompileContext)
,Switch.optimize(CompileContext)
,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)
, in order to compare the start and end value.PathCache
, in order to find identical root values at runtime.
-
toXml
public void toXml(QueryPlan plan)
Description copied from class:ExprInfo
Creates a query plan.
-
toString
public void toString(QueryString qs)
Description copied from class:ExprInfo
Creates a query string.
-
-