Package org.basex.query.var
Class Var
- java.lang.Object
-
- org.basex.query.expr.ExprInfo
-
- org.basex.query.var.Var
-
public final class Var extends ExprInfo
Variable expression.- Author:
- BaseX Team 2005-23, BSD License, Christian Gruen, Leo Woerteler
-
-
Constructor Summary
Constructors Constructor Description Var(QNm name, SeqType declType, QueryContext qc, StaticContext sc, InputInfo info)
Constructor.Var(QNm name, SeqType declType, QueryContext qc, StaticContext sc, InputInfo info, boolean param)
Constructor.Var(QNm name, SeqType declType, QueryContext qc, StaticContext sc, InputInfo info, boolean param, int slot, ExprType exprType)
Constructor for a variable with an already known stack slot.Var(Var var, QueryContext qc, StaticContext sc)
Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
adoptCheck(SeqType st, boolean prom)
Tries to adopt the given type check.Expr
checked(Expr expr, CompileContext cc)
Returns an equivalent to the given expression that checks this variable's type.boolean
checkType()
Determines if this variable checks the type of the expression bound to it.void
checkType(Expr expr)
Checks if the type of the specified expression could be converted to the sequence type of this variable.Value
checkType(Value value, QueryContext qc, boolean opt)
Checks the type of this value and casts/promotes it when necessary.Data
data()
Returns the data reference bound to this variable.boolean
ddo()
Returns the distinct document order flag.SeqType
declaredType()
Declared type of this variable.boolean
equals(Object obj)
void
expr(Expr expr)
Attaches an input expression.int
hashCode()
byte[]
id()
Returns a unique representation of the variable.boolean
is(Var var)
Checks whether the given variable is identical to this one, i.e.boolean
promotes()
Checks if this variable performs function conversion on its bound values.void
refineType(SeqType st, long size, CompileContext cc)
Tries to refine the type of this variable through the type of the bound expression.void
refineType(SeqType st, CompileContext cc)
Tries to refine the type of this variable through the type of the bound expression.SeqType
seqType()
Sequence type of values bound to this variable.long
size()
Returns the result size.String
toErrorString()
Returns a string representation of the expression that can be embedded in error messages.void
toString(QueryString qs)
Creates a query string.void
toXml(QueryPlan plan)
Creates a query plan.-
Methods inherited from class org.basex.query.expr.ExprInfo
description, info, toString
-
-
-
-
Constructor Detail
-
Var
public Var(QNm name, SeqType declType, QueryContext qc, StaticContext sc, InputInfo info, boolean param, int slot, ExprType exprType)
Constructor for a variable with an already known stack slot.- Parameters:
name
- variable namedeclType
- declared type,null
for no checkqc
- query context, used for generating a variable IDsc
- static contextinfo
- input infoparam
- function parameter flagslot
- stack slot (-1
if unused)exprType
- expression type (can benull
)
-
Var
public Var(QNm name, SeqType declType, QueryContext qc, StaticContext sc, InputInfo info)
Constructor.- Parameters:
name
- variable namedeclType
- declared sequence type,null
for no checkqc
- query context, used for generating a variable IDsc
- static contextinfo
- input info
-
Var
public Var(QNm name, SeqType declType, QueryContext qc, StaticContext sc, InputInfo info, boolean param)
Constructor.- Parameters:
name
- variable namedeclType
- declared sequence type,null
for no checkqc
- query context, used for generating a variable IDsc
- static contextinfo
- input infoparam
- function parameter flag
-
Var
public Var(Var var, QueryContext qc, StaticContext sc)
Copy constructor.- Parameters:
var
- variable to copyqc
- query contextsc
- static context
-
-
Method Detail
-
seqType
public SeqType seqType()
Sequence type of values bound to this variable.- Returns:
- sequence type
-
expr
public void expr(Expr expr)
Attaches an input expression.- Parameters:
expr
- input expression
-
size
public long size()
Returns the result size.- Returns:
- result size
-
ddo
public boolean ddo()
Returns the distinct document order flag. SeeExpr.ddo()
for details.- Returns:
- result of check
-
data
public Data data()
Returns the data reference bound to this variable. SeeExpr.data()
for details.- Returns:
- data reference (can be
null
)
-
declaredType
public SeqType declaredType()
Declared type of this variable.- Returns:
- declared type
-
refineType
public void refineType(SeqType st, CompileContext cc) throws QueryException
Tries to refine the type of this variable through the type of the bound expression.- Parameters:
st
- sequence type of the bound expressioncc
- compilation context (can benull
)- Throws:
QueryException
- query exception
-
refineType
public void refineType(SeqType st, long size, CompileContext cc) throws QueryException
Tries to refine the type of this variable through the type of the bound expression.- Parameters:
st
- sequence type of the bound expressionsize
- size (can be-1
)cc
- compilation context (can benull
)- Throws:
QueryException
- query exception
-
checkType
public boolean checkType()
Determines if this variable checks the type of the expression bound to it.- Returns:
true
if the type is checked or promoted,false
otherwise
-
checked
public Expr checked(Expr expr, CompileContext cc) throws QueryException
Returns an equivalent to the given expression that checks this variable's type.- Parameters:
expr
- expressioncc
- compilation context- Returns:
- checked expression
- Throws:
QueryException
- query exception
-
checkType
public Value checkType(Value value, QueryContext qc, boolean opt) throws QueryException
Checks the type of this value and casts/promotes it when necessary.- Parameters:
value
- value to be checkedqc
- query contextopt
- if the result should be optimized- Returns:
- checked and possibly cast value
- Throws:
QueryException
- if the check failed
-
checkType
public void checkType(Expr expr) throws QueryException
Checks if the type of the specified expression could be converted to the sequence type of this variable. Due to insufficient typing, the check will only be performed if:- The variable type is an instance of the specified type. This way, expressions with super types like item() will not be rejected.
- The expression is to be promoted, and it is not of type node (eg: function-declaration-016)
- Parameters:
expr
- expression- Throws:
QueryException
- query exception
-
is
public boolean is(Var var)
Checks whether the given variable is identical to this one, i.e. has the same id.- Parameters:
var
- variable to check- Returns:
true
if the IDs are equal,false
otherwise
-
promotes
public boolean promotes()
Checks if this variable performs function conversion on its bound values.- Returns:
- result of check
-
adoptCheck
public boolean adoptCheck(SeqType st, boolean prom)
Tries to adopt the given type check.- Parameters:
st
- type to checkprom
- if function conversion should be applied- Returns:
true
if the check could be adopted,false
otherwise
-
toXml
public void toXml(QueryPlan plan)
Description copied from class:ExprInfo
Creates a query plan.
-
id
public byte[] id()
Returns a unique representation of the variable.- Returns:
- variable id
-
toString
public void toString(QueryString qs)
Description copied from class:ExprInfo
Creates a query string.
-
toErrorString
public String toErrorString()
Description copied from class:ExprInfo
Returns a string representation of the expression that can be embedded in error messages. Defaults toExprInfo.toString()
.- Overrides:
toErrorString
in classExprInfo
- Returns:
- class name
-
-