org.basex.query.func
Class InlineFunc

java.lang.Object
  extended by org.basex.data.ExprInfo
      extended by org.basex.query.expr.Expr
          extended by org.basex.query.expr.ParseExpr
              extended by org.basex.query.expr.Single
                  extended by org.basex.query.func.InlineFunc
All Implemented Interfaces:
Scope

public final class InlineFunc
extends Single
implements Scope

Inline function.

Author:
BaseX Team 2005-12, BSD License, Leo Woerteler

Nested Class Summary
 
Nested classes/interfaces inherited from class org.basex.query.expr.Expr
Expr.Flag
 
Field Summary
 
Fields inherited from class org.basex.query.expr.Single
expr
 
Fields inherited from class org.basex.query.expr.ParseExpr
info, size, type
 
Constructor Summary
InlineFunc(InputInfo ii, SeqType r, Var[] v, Expr e, Ann a, StaticContext stc, VarScope scp)
          Constructor.
 
Method Summary
 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 all updating expressions are correctly placed.
 void compile(QueryContext ctx)
          Compiles the expression contained in this scope.
 Expr compile(QueryContext ctx, VarScope scp)
          Compiles and optimizes the expression, assigns data types and cardinalities.
 boolean compiled()
          Checks if this scope has already been compiled.
 Expr copy(QueryContext cx, VarScope scp, IntObjMap<Var> vs)
          Copies an expression.
 VarUsage count(Var v)
          Checks how often a variable is used in this expression.
 int exprSize()
          Counts the number of expressions in this expression's sub-tree.
 boolean has(Expr.Flag flag)
          Indicates if an expression has the specified compiler property.
 Expr inline(QueryContext ctx, VarScope scp, Var v, Expr e)
          Inlines an expression into this one, replacing all references to the given variable.
 boolean isVacuous()
          Tests if this is a vacuous expression (empty sequence or error function).
 FuncItem item(QueryContext ctx, InputInfo ii)
          Evaluates the expression and returns the resulting item or a null reference, if the expression yields an empty sequence.
 ValueIter iter(QueryContext ctx)
          Evaluates the expression and returns an iterator on the resulting items.
 Expr optimize(QueryContext ctx, VarScope scp)
          Optimizes an already compiled expression without recompiling its sub-expressions.
 void plan(FElem plan)
          Creates an expression tree.
 boolean removable(Var v)
          Checks if the specified variable is replaceable by a context item.
 java.lang.String toString()
           
 SeqType type()
          Returns the static type of the evaluated value.
 Value value(QueryContext ctx)
          Evaluates the expression and returns the resulting value.
 boolean visit(ASTVisitor visitor)
          Traverses this scope with the given ASTVisitor.
 
Methods inherited from class org.basex.query.expr.ParseExpr
checkAdmin, checkAllUp, checkBinary, checkBln, checkColl, checkCreate, checkCtx, checkDbl, checkDBNode, checkEStr, checkEStr, checkFunc, checkItem, checkItr, checkItr, checkMap, checkNode, checkNode, checkNode, checkNoEmpty, checkNoneUp, checkNoUp, checkQNm, checkStr, checkStr, checkStrBin, checkType, checkWrite, compBln, copyType, ebv, optPre, preEval, size, test
 
Methods inherited from class org.basex.query.expr.Expr
addText, compEbv, copy, hasFreeVars, indexAccessible, indexEquivalent, inlineAll, isEmpty, isFunction, isItem, isValue, iterable, markTailCalls, sameAs, uses, visitAll
 
Methods inherited from class org.basex.data.ExprInfo
addPlan, addPlan, description, info, planAttr, planElem
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InlineFunc

public InlineFunc(InputInfo ii,
                  SeqType r,
                  Var[] v,
                  Expr e,
                  Ann a,
                  StaticContext stc,
                  VarScope scp)
Constructor.

Parameters:
ii - input info
r - return type
v - arguments
e - function body
a - annotations
stc - static context
scp - scope
Method Detail

compile

public void compile(QueryContext ctx)
             throws QueryException
Description copied from interface: Scope
Compiles the expression contained in this scope.

Specified by:
compile in interface Scope
Parameters:
ctx - query context
Throws:
QueryException - compilation errors

compile

public Expr compile(QueryContext ctx,
                    VarScope scp)
             throws QueryException
Description copied from class: Expr
Compiles and optimizes the expression, assigns data types and cardinalities.

Overrides:
compile in class Single
Parameters:
ctx - query context
scp - variable scope
Returns:
optimized expression
Throws:
QueryException - query exception

optimize

public Expr optimize(QueryContext ctx,
                     VarScope scp)
              throws QueryException
Description copied from class: Expr
Optimizes an already compiled expression without recompiling its sub-expressions.

Overrides:
optimize in class Expr
Parameters:
ctx - query context
scp - variable scope
Returns:
optimized expression
Throws:
QueryException - query exception

count

public VarUsage count(Var v)
Description copied from class: Expr
Checks how often a variable is used in this expression.

Overrides:
count in class Single
Parameters:
v - variable to look for
Returns:
how often the variable is used, see VarUsage

inline

public Expr inline(QueryContext ctx,
                   VarScope scp,
                   Var v,
                   Expr e)
            throws QueryException
Description copied from class: Expr
Inlines an expression into this one, replacing all references to the given variable.

Overrides:
inline in class Single
Parameters:
ctx - query context for recompilation
scp - variable scope for recompilation
v - variable to replace
e - expression to inline
Returns:
resulting expression in something changed, null otherwise
Throws:
QueryException - query exception

copy

public Expr copy(QueryContext cx,
                 VarScope scp,
                 IntObjMap<Var> vs)
Description copied from class: Expr
Copies an expression. Will be useful for inlining functions, or for copying static queries.

Specified by:
copy in class Expr
Parameters:
cx - query context
scp - variable scope for creating new variables
vs - mapping from old variable IDs to new variable copies
Returns:
copied expression

item

public FuncItem item(QueryContext ctx,
                     InputInfo ii)
              throws QueryException
Description copied from class: Expr
Evaluates the expression and returns the resulting item or a null reference, if the expression yields an empty sequence. If this method is not overwritten, Expr.iter(org.basex.query.QueryContext) must be implemented by an expression, as it may be called by this method.

Overrides:
item in class ParseExpr
Parameters:
ctx - query context
ii - input info
Returns:
iterator
Throws:
QueryException - query exception

value

public Value value(QueryContext ctx)
            throws QueryException
Description copied from class: Expr
Evaluates the expression and returns the resulting value.

Overrides:
value in class ParseExpr
Parameters:
ctx - query context
Returns:
iterator
Throws:
QueryException - query exception

iter

public ValueIter iter(QueryContext ctx)
               throws QueryException
Description copied from class: Expr
Evaluates the expression and returns an iterator on the resulting items. If this method is not overwritten, Expr.item(org.basex.query.QueryContext, org.basex.util.InputInfo) must be implemented by an expression, as it may be called by this method.

Overrides:
iter in class ParseExpr
Parameters:
ctx - query context
Returns:
resulting item
Throws:
QueryException - query exception

has

public boolean has(Expr.Flag flag)
Description copied from class: Expr
Indicates if an expression has the specified compiler property. This method is called by numerous Expr.compile(org.basex.query.QueryContext, org.basex.query.var.VarScope) methods to test properties of sub-expressions. It returns true if at least one test is successful.

Overrides:
has in class Single
Parameters:
flag - flag to be found
Returns:
result of check

removable

public boolean removable(Var v)
Description copied from class: Expr
Checks if the specified variable is replaceable by a context item. The following tests might return false: This method is called by GFLWOR.compile(org.basex.query.QueryContext, org.basex.query.var.VarScope) to rewrite where clauses into predicates.

Overrides:
removable in class Single
Parameters:
v - variable to be replaced
Returns:
result of check

plan

public void plan(FElem plan)
Description copied from class: ExprInfo
Creates an expression tree.

Overrides:
plan in class Single
Parameters:
plan - root element

visit

public boolean visit(ASTVisitor visitor)
Description copied from interface: Scope
Traverses this scope with the given ASTVisitor.

Specified by:
visit in interface Scope
Parameters:
visitor - visitor
Returns:
continue flag

toString

public java.lang.String toString()
Specified by:
toString in class ExprInfo

checkUp

public void checkUp()
             throws QueryException
Description copied from class: Expr
Checks if all updating expressions are correctly placed. This function is only called if any updating expression was found in the query.

Overrides:
checkUp in class Single
Throws:
QueryException - query exception

isVacuous

public boolean isVacuous()
Description copied from class: Expr
Tests if this is a vacuous expression (empty sequence or error function). This check is needed for updating queries.

Overrides:
isVacuous in class Expr
Returns:
result of check

type

public SeqType type()
Description copied from class: Expr
Returns the static type of the evaluated value. For simplicity, some types have been merged to super types. As an example, many numeric types are treated as integers.

Overrides:
type in class ParseExpr
Returns:
result of check

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.

Overrides:
accept in class Single
Parameters:
visitor - visitor
Returns:
if the walk should be continued

exprSize

public int exprSize()
Description copied from class: Expr
Counts the number of expressions in this expression's sub-tree.

Overrides:
exprSize in class Single
Returns:
number of expressions

compiled

public boolean compiled()
Description copied from interface: Scope
Checks if this scope has already been compiled.

Specified by:
compiled in interface Scope
Returns:
result of check