for-loop
.
More...
#include <forexpression.h>
Public Member Functions | |
ForExpression (VarExpression *_var, VarExpression *_varexp, Expression *_exp) | |
Constructor. | |
ForExpression (VarExpression *_var, VarStepExpression *_varstep, Expression *_exp) | |
Constructor. | |
virtual | ~ForExpression () |
virtual void | scopeCheck (vector< unsigned > &def_vars, vector< unsigned > &introduced_vars, vector< unsigned > &violating_vars) |
virtual void | replaceVarId (unsigned old_id, unsigned new_id) |
virtual void | mergeSequences () |
virtual void | extractFSAMap (FSAMap *fsamap, unsigned parent_var) |
virtual void | extractParVarMap (ParVarMap *parvarmap) |
virtual void | extractDependencies (vector< DependencySet * > *depset) |
virtual Expression * | placeSignOffs (vector< SignOffExpression * > &signoffs) |
virtual void | rewriteWhereExps () |
virtual void | rewriteEmptyFuncts () |
virtual void | rewriteVarstepCondExps () |
virtual void | rewriteAggregateFuncts () |
virtual void | rewriteVarsteps () |
virtual void | print (OutputStream &dos) const |
virtual void | init (BufferNode *root) |
virtual void | eval (OutputStream &eos, Environment *env, unsigned modus) |
virtual void | evalSignOffForBinding (OutputStream &eos, Environment *env, BufferNode *cur) |
Executes all signOff statements in a for-loop. | |
virtual bool | containsDirectOutput () |
Private Attributes | |
VarExpression * | var |
The entered VarExpression. | |
VarExpression * | varexp |
The entered VarExpression. | |
VarStepExpression * | varstep |
The entered VarStepExpression. | |
Expression * | exp |
The entered Expression. | |
BufferIterator * | bit |
The initialized BufferIterator for the entered VarExpression or VarStepExpression. |
for-loop
.
Represents an XQuery for-loop
, which takes a VarExpression, a VarExpression or a VarStepExpression and a Expression, e.g. for $x in /bib//book return $x/title
or for $y in $x return $y//book
, as arguments and introduces a new variable or returns the next new variable binding of the entered VarExpression or VarStepExpression respectively.
Definition at line 54 of file forexpression.h.
ForExpression::ForExpression | ( | VarExpression * | _var, | |
VarExpression * | _varexp, | |||
Expression * | _exp | |||
) |
Constructor.
Constructor - creating object for two VarExpression and a Expression.
[in] | _var | Pointer to a VarExpression object. |
[in] | _varexp | Pointer to a VarExpression object. |
[in] | _exp | Pointer to a Expression object. |
Definition at line 37 of file forexpression.cpp.
Referenced by rewriteVarsteps().
ForExpression::ForExpression | ( | VarExpression * | _var, | |
VarStepExpression * | _varstep, | |||
Expression * | _exp | |||
) |
Constructor.
Constructor - creating object for a VarExpression, a VarStepExpression an a Expression.
[in] | _var | Pointer to a VarExpression object. |
[in] | _varstep | Pointer to a VarStepExpression object. |
[in] | _exp | Pointer to a Expression object. |
Definition at line 42 of file forexpression.cpp.
ForExpression::~ForExpression | ( | ) | [virtual] |
bool ForExpression::containsDirectOutput | ( | ) | [virtual] |
Returns if the corresponding expression produces direct output.
Returns if the corresponding expression produces direct output. Direct output is meant that this subexpression produces output such as node constructs or strings.
bool | true if the corresponding expression produces direct output, false otherwise. |
Reimplemented from Expression.
Definition at line 292 of file forexpression.cpp.
References Expression::containsDirectOutput(), exp, and Expression::getType().
Referenced by extractParVarMap().
void ForExpression::eval | ( | OutputStream & | eos, | |
Environment * | env, | |||
unsigned | modus | |||
) | [virtual] |
Evaluates the expression in the given environment.
Evaluates the expression in the given environment. The evaluation takes place in the environment that is passed to this method. In addition, the parameter modus is one of the following: EVAL_QUERY, EVAL_QUERY_SILENT or EVAL_SIGNOFF (see also the corresponding defines for more information). This method implements the XQuery semantics for the standard expression types, but also the GCX specific extensions like signOff-statements.
[in] | eos | Pointer to a OutputStream object. |
[in] | env | Pointer to an Environment object. |
[in] | modus | The query evaluation mode. |
RuntimeException | If illegal evaluation mode. |
Reimplemented from Expression.
Definition at line 228 of file forexpression.cpp.
References bit, BufferIterator::clear(), Environment::clone(), Expression::eval(), EVAL_QUERY, EVAL_SIGNOFF, exp, VarExpression::getId(), BufferIterator::getNext(), Environment::getNodeBinding(), BufferIterator::init(), Environment::insertNodeBinding(), LOCK_CONTEXT_ALWAYS_CLEAR, READ_UP_TO_CLOSE_NONE, var, varexp, and varstep.
Referenced by AggregateFunctVarSampExpression::eval(), AggregateFunctVarPopExpression::eval(), AggregateFunctSumExpression::eval(), AggregateFunctStdDevSampExpression::eval(), AggregateFunctStdDevPopExpression::eval(), AggregateFunctMinExpression::eval(), AggregateFunctMedianExpression::eval(), AggregateFunctMaxExpression::eval(), AggregateFunctCountExpression::eval(), and AggregateFunctAvgExpression::eval().
void ForExpression::evalSignOffForBinding | ( | OutputStream & | eos, | |
Environment * | env, | |||
BufferNode * | cur | |||
) | [virtual] |
Executes all signOff statements in a for-loop.
Executes all signOff statements in a for-loop by binding the for-loop iteration variable to a BufferNode (creating a new Environment) and executing all SignOffExpression in this Environment.
[in] | eos | Pointer to a OutputStream object. |
[in] | env | Pointer to a Environment object. |
[in] | cur | Pointer to a BufferNode object. |
void |
Definition at line 282 of file forexpression.cpp.
References Environment::clone(), Expression::eval(), EVAL_SIGNOFF, exp, VarExpression::getId(), Environment::insertNodeBinding(), and var.
Referenced by AggregateFunctVarSampExpression::calculateValue(), AggregateFunctVarPopExpression::calculateValue(), AggregateFunctSumExpression::calculateValue(), AggregateFunctStdDevSampExpression::calculateValue(), AggregateFunctStdDevPopExpression::calculateValue(), AggregateFunctMinExpression::calculateValue(), AggregateFunctMedianExpression::calculateValue(), AggregateFunctMaxExpression::calculateValue(), AggregateFunctCountExpression::calculateValue(), and AggregateFunctAvgExpression::calculateValue().
void ForExpression::extractDependencies | ( | vector< DependencySet * > * | depset | ) | [virtual] |
Extracts the needed dependencies of a query.
Extracts the needed dependencies of a query, which are needed for constructing the ProjectionTree.
[in,out] | depset | Pointer to a vector containing Pointer to DependencySet objects. |
void |
Reimplemented from Expression.
Definition at line 146 of file forexpression.cpp.
References exp, and Expression::extractDependencies().
Referenced by AggregateFunctExpression::extractDependencies().
void ForExpression::extractFSAMap | ( | FSAMap * | fsamap, | |
unsigned | parent_var | |||
) | [virtual] |
Extracts the needed first straight ancestor (FSA) variables map.
Extracts the needed first straight ancestor (FSA) variables map, which is needed for correct insertion of SignOffExpression.
[in,out] | fsamap | Pointer to a FSAMap object. |
[in] | parent_var | Parent variable. |
void |
Reimplemented from Expression.
Definition at line 117 of file forexpression.cpp.
References exp, Expression::extractFSAMap(), FSAMap::getFSA(), VarExpression::getId(), FSAMap::insertFSA(), var, varexp, and varstep.
Referenced by AggregateFunctExpression::extractFSAMap().
void ForExpression::extractParVarMap | ( | ParVarMap * | parvarmap | ) | [virtual] |
Extracts the needed parent variable (ParVar) map.
Extracts the needed parent variable (ParVar) map, which is needed for constructing the VariableTree.
[in,out] | parvarmap | Pointer to a ParVarMap object. |
void |
Reimplemented from Expression.
Definition at line 134 of file forexpression.cpp.
References containsDirectOutput(), exp, Expression::extractParVarMap(), VarExpression::getId(), VarStepExpression::getPath(), ParVarMap::insertParVar(), var, varexp, and varstep.
Referenced by AggregateFunctExpression::extractParVarMap().
void ForExpression::init | ( | BufferNode * | root | ) | [virtual] |
Initializes the query for evaluation.
Initializes the query for evaluation. Up to now only all required BufferIterator objects are created to speed up query evaluation.
[in] | root | Pointer to a BufferNode object. |
void |
Reimplemented from Expression.
Definition at line 218 of file forexpression.cpp.
References bit, exp, Expression::init(), varexp, and varstep.
Referenced by AggregateFunctExpression::init().
void ForExpression::mergeSequences | ( | ) | [virtual] |
Merges belonging together XQuery sequences into a single sequence.
Merges belonging together XQuery sequences into a single sequence, which is done because of better/nicer output look.
void |
Reimplemented from Expression.
Definition at line 113 of file forexpression.cpp.
References exp, and Expression::mergeSequences().
Expression * ForExpression::placeSignOffs | ( | vector< SignOffExpression * > & | signoffs | ) | [virtual] |
Places all signOff-statements in the corresponding query.
Places all signOff-statements in the corresponding query, which are needed for active garbage collection by removing Role from the BufferNode.
[in] | signoffs | Pointer to a vector containing Pointer to SignOffExpression objects. |
Expression* | Pointer to a Expression object (following expression in the corresponding query). |
Reimplemented from Expression.
Definition at line 150 of file forexpression.cpp.
References exp, VarExpression::getId(), Expression::placeSignOffs(), and var.
Referenced by AggregateFunctExpression::placeSignOffs().
void ForExpression::print | ( | OutputStream & | dos | ) | const [virtual] |
Prints the expression.
Prints the expression.
[in] | dos | Pointer to a OutputStream object. |
void |
Implements Expression.
Definition at line 195 of file forexpression.cpp.
References decrementIndents(), exp, Expression::getType(), incrementIndents(), NEWLINE, varexp, and writeIndents().
void ForExpression::replaceVarId | ( | unsigned | old_id, | |
unsigned | new_id | |||
) | [virtual] |
Replaces all matching variable IDs by a new one.
Replaces all matching variable IDs by a new one, which is needed in case of calling method rewriteVarsteps().
[in] | old_id | Old variable ID. |
[in] | new_id | New variable ID, which should be introduced instead. |
void |
Reimplemented from Expression.
Definition at line 98 of file forexpression.cpp.
References exp, VarExpression::getId(), VarName::getInstance(), Expression::replaceVarId(), VarExpression::replaceVarId(), TAGID_ROOT, var, varexp, and varstep.
void ForExpression::rewriteAggregateFuncts | ( | ) | [virtual] |
Rewrites all arguments of all aggregate functions into an equivalent for-clause (with return-clause).
Rewrites all arguments of all aggregate functions into an equivalent for-clause (with return-clause).
void |
Reimplemented from Expression.
Definition at line 176 of file forexpression.cpp.
References exp, and Expression::rewriteAggregateFuncts().
void ForExpression::rewriteEmptyFuncts | ( | ) | [virtual] |
Rewrites all fn:empty
XQuery functions into equivalent fn:not(fn:exists)
XQuery functions.
Rewrites all fn:empty
XQuery functions into equivalent fn:not(fn:exists)
XQuery functions.
void |
Reimplemented from Expression.
Definition at line 168 of file forexpression.cpp.
References exp, and Expression::rewriteEmptyFuncts().
void ForExpression::rewriteVarstepCondExps | ( | ) | [virtual] |
Rewrites all if($x)
if-conditions into equivalent if(fn:not(fn:empty($x)))
XQuery expressions.
Rewrites all if($x)
if-conditions into equivalent if(fn:not(fn:empty($x)))
XQuery expressions.
void |
Reimplemented from Expression.
Definition at line 172 of file forexpression.cpp.
References exp, and Expression::rewriteVarstepCondExps().
void ForExpression::rewriteVarsteps | ( | ) | [virtual] |
Rewrites all varstep expressions, which produces output into an equivalent for-clause (with return-clause).
Rewrites all varstep expressions, which produces output into an equivalent for-clause (with return-clause). This method belongs to the 'earlier execution of signoff-statements' optimization.
void |
Reimplemented from Expression.
Definition at line 180 of file forexpression.cpp.
References VarExpression::clone(), exp, ForExpression(), VarName::getInstance(), Expression::getType(), and Expression::rewriteVarsteps().
void ForExpression::rewriteWhereExps | ( | ) | [virtual] |
Rewrites all where-clauses in the query into equivalent if-expressions.
Rewrites all where-clauses in the query into equivalent if-expressions, i.e. rewrites all WhereExpression into equivalent IfExpression.
void |
Reimplemented from Expression.
Definition at line 164 of file forexpression.cpp.
References exp, and Expression::rewriteWhereExps().
void ForExpression::scopeCheck | ( | vector< unsigned > & | def_vars, | |
vector< unsigned > & | introduced_vars, | |||
vector< unsigned > & | violating_vars | |||
) | [virtual] |
Returns if all used variables were previously (through a for-clause) defined or if a variable leaves their defined scope.
Returns if all used variables were previously (through a for-clause) defined or if a variable leaves their defined scope.
[in] | def_vars | Vector containing all previously defined variables. |
[in] | introduced_vars | Vector containing all up to this expression defined variables. |
[in] | violating_vars | Vector containing all variables which violates the scope condition. |
void |
Reimplemented from Expression.
Definition at line 55 of file forexpression.cpp.
References exp, VarExpression::getId(), VarName::getInstance(), VarName::getVarname(), VarName::insertVarname(), Expression::replaceVarId(), Expression::scopeCheck(), VarExpression::scopeCheck(), VarExpression::setId(), TAGID_ROOT, var, varexp, and varstep.
BufferIterator * ForExpression::bit [private] |
The initialized BufferIterator for the entered VarExpression or VarStepExpression.
The initialized BufferIterator for the entered VarExpression or VarStepExpression after calling method init(). This member variable is NULL
on creation of object but should not be NULL
anymore after method init() has been executed.
Definition at line 211 of file forexpression.h.
Referenced by eval(), init(), and ~ForExpression().
Expression * ForExpression::exp [private] |
The entered Expression.
The entered Expression, which is the third argument of the constructor and defines the return-clause
of a for-loop
.
Definition at line 203 of file forexpression.h.
Referenced by containsDirectOutput(), eval(), evalSignOffForBinding(), extractDependencies(), extractFSAMap(), extractParVarMap(), init(), mergeSequences(), placeSignOffs(), print(), replaceVarId(), rewriteAggregateFuncts(), rewriteEmptyFuncts(), rewriteVarstepCondExps(), rewriteVarsteps(), rewriteWhereExps(), scopeCheck(), and ~ForExpression().
VarExpression * ForExpression::var [private] |
The entered VarExpression.
The entered VarExpression, which is the first argument of the constructor and defines a new introduced variable of a for-loop
.
Definition at line 180 of file forexpression.h.
Referenced by eval(), evalSignOffForBinding(), extractFSAMap(), extractParVarMap(), placeSignOffs(), replaceVarId(), scopeCheck(), and ~ForExpression().
VarExpression * ForExpression::varexp [private] |
The entered VarExpression.
The entered VarExpression, which is the second argument of the constructor and defines the iteration base, i.e. the sequence of nodes for iteration, of a for-loop
. This member variable is NULL
if the constructor was called with a VarStepExpression.
Definition at line 188 of file forexpression.h.
Referenced by eval(), extractFSAMap(), extractParVarMap(), init(), print(), replaceVarId(), scopeCheck(), and ~ForExpression().
VarStepExpression * ForExpression::varstep [private] |
The entered VarStepExpression.
The entered VarStepExpression, which is the second argument of the constructor and defines the iteration base, i.e. the sequence of nodes for iteration, of a for-loop
. This member variable is NULL
if the constructor was called with a VarExpression.
Definition at line 196 of file forexpression.h.
Referenced by eval(), extractFSAMap(), extractParVarMap(), init(), replaceVarId(), scopeCheck(), and ~ForExpression().