Qt 4.8
Public Functions | Private Types | Private Functions | Properties | List of all members
QPatternist::ForClause Class Reference

Implements XPath 2.0's for expression. More...

#include <qforclause_p.h>

Inheritance diagram for QPatternist::ForClause:
QPatternist::PairContainer QPatternist::Expression QSharedData QPatternist::CppCastingHelper< Expression > QPatternist::SourceLocationReflection

Public Functions

virtual ExpressionVisitorResult::Ptr accept (const ExpressionVisitor::Ptr &visitor) const
 
virtual Expression::Ptr compress (const StaticContext::Ptr &context)
 
virtual Item::Iterator::Ptr evaluateSequence (const DynamicContext::Ptr &context) const
 
virtual Item evaluateSingleton (const DynamicContext::Ptr &context) const
 
virtual void evaluateToSequenceReceiver (const DynamicContext::Ptr &context) const
 
virtual SequenceType::List expectedOperandTypes () const
 
 ForClause (const VariableSlotID varSlot, const Expression::Ptr &bindingSequence, const Expression::Ptr &returnExpression, const VariableSlotID positionSlot)
 
virtual ID id () const
 
Item mapToItem (const Item &item, const DynamicContext::Ptr &context) const
 
Item::Iterator::Ptr mapToSequence (const Item &item, const DynamicContext::Ptr &context) const
 
virtual QList< QExplicitlySharedDataPointer< OptimizationPass > > optimizationPasses () const
 
virtual SequenceType::Ptr staticType () const
 
virtual Expression::Ptr typeCheck (const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
 
- Public Functions inherited from QPatternist::PairContainer
virtual bool compressOperands (const StaticContext::Ptr &)
 
virtual Expression::List operands () const
 
virtual void setOperands (const Expression::List &operands)
 
- Public Functions inherited from QPatternist::Expression
virtual const SourceLocationReflectionactualReflection () const
 Returns this. More...
 
virtual void announceFocusType (const ItemType::Ptr &itemType)
 
Properties deepProperties () const
 Computes the union of properties for this Expression and all its descending children. More...
 
virtual Properties dependencies () const
 
virtual QString description () const
 
virtual bool evaluateEBV (const DynamicContext::Ptr &context) const
 
virtual ItemType::Ptr expectedContextItemType () const
 
 Expression ()
 
bool has (const Property prop) const
 
bool hasDependency (const Property prop) const
 
bool is (const ID id) const
 
bool isEvaluated () const
 
virtual ItemType::Ptr newFocusType () const
 
virtual PatternPriority patternPriority () const
 
virtual Properties properties () const
 
const Expression::Ptrrewrite (const Expression::Ptr &to, const StaticContext::Ptr &context) const
 Rewrites this Expression to to, and return to. More...
 
virtual ~Expression ()
 
- Public Functions inherited from QSharedData
 QSharedData ()
 Constructs a QSharedData object with a reference count of 0. More...
 
 QSharedData (const QSharedData &)
 Constructs a QSharedData object with reference count 0. More...
 
- Public Functions inherited from QPatternist::CppCastingHelper< Expression >
const TCastTarget * as () const
 
TCastTarget * as ()
 
- Public Functions inherited from QPatternist::SourceLocationReflection
virtual QSourceLocation sourceLocation () const
 
 SourceLocationReflection ()
 
virtual ~SourceLocationReflection ()
 

Private Types

typedef QExplicitlySharedDataPointer< const ForClauseConstPtr
 

Private Functions

void riggPositionalVariable (const DynamicContext::Ptr &context, const Item::Iterator::Ptr &source) const
 

Properties

bool m_allowsMany
 
const VariableSlotID m_positionSlot
 
const VariableSlotID m_varSlot
 

Additional Inherited Members

- Public Types inherited from QPatternist::Expression
typedef QExplicitlySharedDataPointer< const ExpressionConstPtr
 A smart pointer wrapping const Expression instances. More...
 
enum  ID {
  IDBooleanValue = 1, IDCountFN, IDEmptyFN, IDExistsFN,
  IDExpressionSequence, IDGeneralComparison, IDIfThenClause, IDIgnorableExpression,
  IDIntegerValue, IDPositionFN, IDStringValue, IDValueComparison,
  IDRangeVariableReference, IDContextItem, IDUserFunctionCallsite, IDExpressionVariableReference,
  IDAttributeConstructor, IDUpperCaseFN, IDLowerCaseFN, IDFirstItemPredicate,
  IDEmptySequence, IDReturnOrderBy, IDLetClause, IDForClause,
  IDPath, IDNamespaceConstructor, IDArgumentReference, IDGenericPredicate,
  IDAxisStep, IDFloat, IDCombineNodes, IDUnresolvedVariableReference,
  IDCardinalityVerifier
}
 
typedef QList< Expression::PtrList
 
typedef QFlags< PropertyProperties
 
enum  Property {
  UseContextItem = 1, DisableElimination = 1 << 1, IsEvaluated = 1 << 2, DisableTypingDeduction = 1 << 3,
  EmptynessFollowsChild = 1 << 4, RewriteToEmptyOnEmpty = 1 << 5, RequiresFocus = 1 << 6, AffectsOrderOnly = 1 << 7,
  RequiresContextItem = (1 << 8) | RequiresFocus, CreatesFocusForLast = 1 << 9, LastOperandIsCollation = 1 << 10, DependsOnLocalVariable = (1 << 11) | DisableElimination,
  EvaluationCacheRedundant = (1 << 12), IsNodeConstructor = 1 << 13, RequiresCurrentItem = 1 << 14
}
 
typedef QExplicitlySharedDataPointer< ExpressionPtr
 A smart pointer wrapping mutable Expression instances. More...
 
typedef ::QAbstractXmlForwardIterator< Expression::PtrQAbstractXmlForwardIterator
 
typedef QVector< Expression::PtrVector
 
- Static Public Functions inherited from QPatternist::Expression
static void rewrite (Expression::Ptr &old, const Expression::Ptr &New, const StaticContext::Ptr &context)
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 
- Protected Functions inherited from QPatternist::PairContainer
 PairContainer (const Expression::Ptr &operand1, const Expression::Ptr &operand2)
 
- Protected Functions inherited from QPatternist::Expression
void typeCheckOperands (const StaticContext::Ptr &context)
 
- Protected Functions inherited from QPatternist::CppCastingHelper< Expression >
 CppCastingHelper ()
 
- Protected Variables inherited from QPatternist::PairContainer
Expression::Ptr m_operand1
 
Expression::Ptr m_operand2
 

Detailed Description

Implements XPath 2.0's for expression.

See also
XML Path Language (XPath) 2.0, 3.7 For Expressions
Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 72 of file qforclause_p.h.

Typedefs

◆ ConstPtr

Definition at line 108 of file qforclause_p.h.

Constructors and Destructors

◆ ForClause()

ForClause::ForClause ( const VariableSlotID  varSlot,
const Expression::Ptr bindingSequence,
const Expression::Ptr returnExpression,
const VariableSlotID  positionSlot 
)

If positionSlot is -1, no positional variable will be used.

Definition at line 55 of file qforclause.cpp.

58  : PairContainer(bindingSequence, returnExpression),
59  m_varSlot(varSlot),
60  m_positionSlot(positionSlot),
61  m_allowsMany(true)
62 {
64 }
const VariableSlotID m_positionSlot
Definition: qforclause_p.h:110
const VariableSlotID m_varSlot
Definition: qforclause_p.h:109
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
PairContainer(const Expression::Ptr &operand1, const Expression::Ptr &operand2)

Functions

◆ accept()

ExpressionVisitorResult::Ptr ForClause::accept ( const ExpressionVisitor::Ptr visitor) const
virtual

Implements QPatternist::Expression.

Definition at line 185 of file qforclause.cpp.

186 {
187  return visitor->visit(this);
188 }

◆ compress()

Expression::Ptr ForClause::compress ( const StaticContext::Ptr context)
virtual

Sets m_allowsMany properly.

Reimplemented from QPatternist::Expression.

Definition at line 151 of file qforclause.cpp.

152 {
153  const Expression::Ptr me(PairContainer::compress(context));
154  if(me != this)
155  return me;
156 
157  /* This is done after calling PairContainer::typeCheck(). The advantage of this is that
158  * m_allowsMany is updated according to what the operand says after it has compressed. However,
159  * if it was initialized to false(as it once was..), ForClause::evaluateSequence()
160  * would potentially have been called by PairContainer::compress(), and it would have
161  * used an unsafe branch. */
163 
164  return me;
165 }
virtual Expression::Ptr compress(const StaticContext::Ptr &context)
virtual Cardinality cardinality() const =0
virtual SequenceType::Ptr staticType() const =0

◆ evaluateSequence()

Item::Iterator::Ptr ForClause::evaluateSequence ( const DynamicContext::Ptr context) const
virtual

Evaluate this Expression by iterating over it. This is a central function for evaluating expressions.

Expressions must always always return a valid QAbstractXmlForwardIterator and may never return 0. If an empty result is of interest to be returned, the EmptyIterator should be returned.

The default implementation returns a SingletonIterator over the item returned from evaluateSingleton().

Note
This function may raise an exception when calling, not only when QAbstractXmlForwardIterator::next() is called on the return value. This is because in some cases evaluateSingleton() is called directly.

Reimplemented from QPatternist::Expression.

Definition at line 87 of file qforclause.cpp.

Referenced by evaluateSingleton().

88 {
89  const Item::Iterator::Ptr source(m_operand1->evaluateSequence(context));
90 
91  riggPositionalVariable(context, source);
92 
93  if(m_allowsMany)
94  {
95  return makeSequenceMappingIterator<Item>(ConstPtr(this),
96  source,
97  context);
98  }
99  else
100  {
101  return makeItemMappingIterator<Item>(ConstPtr(this),
102  source,
103  context);
104  }
105 }
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
QExplicitlySharedDataPointer< const ForClause > ConstPtr
Definition: qforclause_p.h:108
void riggPositionalVariable(const DynamicContext::Ptr &context, const Item::Iterator::Ptr &source) const
Definition: qforclause.cpp:80
virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const

◆ evaluateSingleton()

Item ForClause::evaluateSingleton ( const DynamicContext::Ptr context) const
virtual

Reimplemented from QPatternist::Expression.

Definition at line 107 of file qforclause.cpp.

108 {
109  return evaluateSequence(context)->next();
110 }
virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const
Definition: qforclause.cpp:87

◆ evaluateToSequenceReceiver()

void ForClause::evaluateToSequenceReceiver ( const DynamicContext::Ptr context) const
virtual

Evaluates this Expression by sending its output to DynamicContext::outputReceiver().

Reimplemented from QPatternist::Expression.

Definition at line 112 of file qforclause.cpp.

113 {
115  const Item::Iterator::Ptr source(m_operand1->evaluateSequence(context));
116 
117  riggPositionalVariable(context, source);
118 
119  Item next(source->next());
120 
121  while(next)
122  {
123  context->setRangeVariable(m_varSlot, next);
125  next = source->next();
126  }
127 }
#define it(className, varName)
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
const VariableSlotID m_varSlot
Definition: qforclause_p.h:109
virtual void setRangeVariable(const VariableSlotID slot, const Item &newValue)=0
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
void riggPositionalVariable(const DynamicContext::Ptr &context, const Item::Iterator::Ptr &source) const
Definition: qforclause.cpp:80
virtual void evaluateToSequenceReceiver(const DynamicContext::Ptr &context) const
virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const

◆ expectedOperandTypes()

SequenceType::List ForClause::expectedOperandTypes ( ) const
virtual

Returns a list of Sequence Types, describing the type of each of the expression's operands. Hence, this function has a relationship to the operands() function:

- The lengths of the lists returned by expectedOperandTypes()
and operands() should always be equal in length, since one
cannot describe the type of a non-existent operand(and all
operands must have type information).
- A significant difference between the two functions is that while
the type of objects in the list returned by operands() may vary
between compilations/static context, simply because the particular
Expression is part of different XPath expressions, the
types in the list returned by expectedOperandTypes is always the same
since the function/operator signature never changes.

This function should not be confused with staticType(), which returns the static type of the expression itself, not its operands. The function call is an expression where this is clear: the type of the return value is not the same as the arguments' types. The static type of the operands supplied to the expression can be determined via the staticType() function of the instances returned by operands().

If the expression has no operands, an empty list should be returned.

Implements QPatternist::Expression.

Definition at line 177 of file qforclause.cpp.

178 {
179  SequenceType::List result;
182  return result;
183 }
static const SequenceType::Ptr ZeroOrMoreItems
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ id()

Expression::ID ForClause::id ( ) const
virtual

This property, which has no setter, returns an enum value that uniquely identifies this Expression. Patternist makes no use of C++'s dynamic_cast feature, but uses this polymorphic function instead.

Returns
always IgnorableExpression.

Reimplemented from QPatternist::Expression.

Definition at line 195 of file qforclause.cpp.

◆ mapToItem()

Item ForClause::mapToItem ( const Item item,
const DynamicContext::Ptr context 
) const
inline

Definition at line 66 of file qforclause.cpp.

68 {
69  context->setRangeVariable(m_varSlot, item);
70  return m_operand2->evaluateSingleton(context);
71 }
const VariableSlotID m_varSlot
Definition: qforclause_p.h:109
virtual void setRangeVariable(const VariableSlotID slot, const Item &newValue)=0
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const

◆ mapToSequence()

Item::Iterator::Ptr ForClause::mapToSequence ( const Item item,
const DynamicContext::Ptr context 
) const
inline

Definition at line 73 of file qforclause.cpp.

75 {
76  context->setRangeVariable(m_varSlot, item);
77  return m_operand2->evaluateSequence(context);
78 }
const VariableSlotID m_varSlot
Definition: qforclause_p.h:109
virtual void setRangeVariable(const VariableSlotID slot, const Item &newValue)=0
virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const

◆ optimizationPasses()

OptimizationPass::List ForClause::optimizationPasses ( ) const
virtual

Returns the OptimizationPasses that applies for this Expression. The default implementation returns an empty list. Sub-classes can re-implement this function and return actual OptimizationPasses.

Returns
always an empty list.

Reimplemented from QPatternist::Expression.

Definition at line 190 of file qforclause.cpp.

191 {
193 }

◆ riggPositionalVariable()

void ForClause::riggPositionalVariable ( const DynamicContext::Ptr context,
const Item::Iterator::Ptr source 
) const
inlineprivate

Definition at line 80 of file qforclause.cpp.

Referenced by evaluateSequence(), and evaluateToSequenceReceiver().

82 {
83  if(m_positionSlot > -1)
84  context->setPositionIterator(m_positionSlot, source);
85 }
const VariableSlotID m_positionSlot
Definition: qforclause_p.h:110
virtual void setPositionIterator(const VariableSlotID slot, const Item::Iterator::Ptr &newValue)=0

◆ staticType()

SequenceType::Ptr ForClause::staticType ( ) const
virtual
Returns
the static type of this Expression. For example, an 'and' expression have as static type xs:boolean

Implements QPatternist::Expression.

Definition at line 167 of file qforclause.cpp.

168 {
169  const SequenceType::Ptr returnType(m_operand2->staticType());
170 
171  return makeGenericSequenceType(returnType->itemType(),
173  * /* multiply operator */
174  returnType->cardinality());
175 }
virtual Cardinality cardinality() const =0
virtual SequenceType::Ptr staticType() const =0

◆ typeCheck()

Expression::Ptr ForClause::typeCheck ( const StaticContext::Ptr context,
const SequenceType::Ptr reqType 
)
virtual

This implementation guarantees to never rewrite away this Expression, but at most rewrite it as a child of another expression(that presumably have a type checking role). It is therefore always safe to override this function and call this implementation and not worry about that this Expression becomes deleted.

Many Expressions override typeCheck() and performs optimizations, as opposed to doing it in the compress() stage. This is due to that the design of those Expressions often are tied to that certain simplifications are done at the typeCheck() stage of the compilation process or that it in some other way is related to what the typeCheck() do. Also, the earlier the AST can be simplified, the better the chances are for subsequent optimizations.

It is important that the super class's typeCheck() is called before doing any custom type checking, since the call can change the children(notably, the childrens' static types). For example, if the Expression, MyExpression in the example, does not match the required type, typeCheck returns the Expression wrapped in for example ItemVerifier, CardinalityVerifier, or both.

typeCheck() may be called many times. typeCheck() must either raise an error if this Expression is an invalid expression. Thus, it is guaranteed that an Expression is valid after typeCheck() is called.

Parameters
contextsupplies information, such as namespace bindings and available function signatures, that can be needed at compilation time. context is guaranteed by the caller to never null.
reqTypethe static type that this Expression must match when evaluated. reqType is guaranteed by the caller to never null.
Returns
an Expression that can be this Expression, or another expression, which somehow is necessary for making this Expression conforming to reqType

Reimplemented from QPatternist::Expression.

Definition at line 129 of file qforclause.cpp.

131 {
132  const Expression::Ptr me(PairContainer::typeCheck(context, reqType));
133  const Cardinality card(m_operand1->staticType()->cardinality());
134 
135  /* If our source is empty we will always evaluate to the empty sequence, so rewrite. */
136  if(card.isEmpty())
137  return EmptySequence::create(this, context);
138  else
139  return me;
140 
141  /* This breaks because the variable references haven't rewritten themselves, so
142  * they dangle. When this is fixed, evaluateSingleton can be removed. */
143  /*
144  else if(card->allowsMany())
145  return me;
146  else
147  return m_operand2;
148  */
149 }
virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
Definition: qexpression.cpp:70
static Expression::Ptr create(const Expression *const replacementFor, const StaticContext::Ptr &context)
Creates an EmptySequence that is a replacement for replacementFor.
virtual Cardinality cardinality() const =0
virtual SequenceType::Ptr staticType() const =0
Represents a cardinality, a possible , often represented by occurrence indicators.

Properties

◆ m_allowsMany

bool QPatternist::ForClause::m_allowsMany
private

Initialized to false. This default is always safe.

Definition at line 114 of file qforclause_p.h.

Referenced by compress(), and evaluateSequence().

◆ m_positionSlot

const VariableSlotID QPatternist::ForClause::m_positionSlot
private

Definition at line 110 of file qforclause_p.h.

Referenced by ForClause(), and riggPositionalVariable().

◆ m_varSlot

const VariableSlotID QPatternist::ForClause::m_varSlot
private

Definition at line 109 of file qforclause_p.h.

Referenced by evaluateToSequenceReceiver(), mapToItem(), and mapToSequence().


The documentation for this class was generated from the following files: