Qt 4.8
Public Types | Public Functions | Static Public Functions | Properties | List of all members
QPatternist::CombineNodes Class Reference

Implements XPath 2.0's operators for combining node sequences: union, intersect and except. More...

#include <qcombinenodes_p.h>

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

Public Types

enum  Operator { Union = 1, Intersect = 2, Except = 4 }
 
- 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
 

Public Functions

virtual ExpressionVisitorResult::Ptr accept (const ExpressionVisitor::Ptr &visitor) const
 
 CombineNodes (const Expression::Ptr &operand1, const Operator op, const Expression::Ptr &operand2)
 
virtual bool evaluateEBV (const DynamicContext::Ptr &context) const
 
virtual Item::Iterator::Ptr evaluateSequence (const DynamicContext::Ptr &context) const
 
virtual Item evaluateSingleton (const DynamicContext::Ptr &context) const
 
virtual SequenceType::List expectedOperandTypes () const
 
virtual ID id () const
 
Operator operatorID () 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)
 
virtual Expression::Ptr compress (const StaticContext::Ptr &context)
 
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 void evaluateToSequenceReceiver (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 QList< QExplicitlySharedDataPointer< OptimizationPass > > optimizationPasses () 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 ()
 

Static Public Functions

static QString displayName (const Operator op)
 
- Static Public Functions inherited from QPatternist::Expression
static void rewrite (Expression::Ptr &old, const Expression::Ptr &New, const StaticContext::Ptr &context)
 

Properties

const Operator m_operator
 

Additional Inherited Members

- 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 operators for combining node sequences: union, intersect and except.

See also
XQuery 1.0: An XML Query Language, 3.3.3 Combining QXmlNodeModelIndex Sequences
Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 72 of file qcombinenodes_p.h.

Enumerations

◆ Operator

Enumerator
Union 
Intersect 
Except 

Definition at line 75 of file qcombinenodes_p.h.

Constructors and Destructors

◆ CombineNodes()

CombineNodes::CombineNodes ( const Expression::Ptr operand1,
const Operator  op,
const Expression::Ptr operand2 
)

Definition at line 56 of file qcombinenodes.cpp.

58  : PairContainer(operand1, operand2),
59  m_operator(op)
60 {
61  Q_ASSERT(op == Union ||
62  op == Except ||
63  op == Intersect);
64 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
PairContainer(const Expression::Ptr &operand1, const Expression::Ptr &operand2)

Functions

◆ accept()

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

Implements QPatternist::Expression.

Definition at line 162 of file qcombinenodes.cpp.

163 {
164  return visitor->visit(this);
165 }

◆ displayName()

QString CombineNodes::displayName ( const Operator  op)
static

Determines the string representation for operator op.

Returns
"union" if op is Union, "intersect" if op is Intersect and "except" if op is Except.

Definition at line 116 of file qcombinenodes.cpp.

117 {
118  switch(op)
119  {
120  case Intersect:
121  return QLatin1String("intersect");
122  case Except:
123  return QLatin1String("except");
124  default:
125  {
126  Q_ASSERT(op == Union);
127  return QLatin1String("union");
128  }
129  }
130 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

◆ evaluateEBV()

bool CombineNodes::evaluateEBV ( const DynamicContext::Ptr context) const
virtual

Determines the Effective Boolean Value of the expression.

The Effective Boolean Value of a value is not necessarily the same as converting the value to a new value of type xs:boolean.

Note that this function cannot return the empty sequence, evaluateSingleton() must be overridden in order to be able to do that.

The default implementation results in a type error. Hence, this function must be overridden if such behavior is not of interest.

See also
XML Path Language (XPath) 2.0, 2.4.3 Effective Boolean Value

Reimplemented from QPatternist::Expression.

Definition at line 102 of file qcombinenodes.cpp.

103 {
104  /* If it's the union operator, we can possibly avoid
105  * evaluating the second operand. */
106 
107  if(m_operator == Union)
108  {
109  return m_operand1->evaluateEBV(context) ||
110  m_operand2->evaluateEBV(context);
111  }
112  else
113  return PairContainer::evaluateEBV(context);
114 }
virtual bool evaluateEBV(const DynamicContext::Ptr &context) const

◆ evaluateSequence()

Item::Iterator::Ptr CombineNodes::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 66 of file qcombinenodes.cpp.

Referenced by evaluateSingleton().

67 {
68  const Item::Iterator::Ptr op1(m_operand1->evaluateSequence(context));
69  const Item::Iterator::Ptr op2(m_operand2->evaluateSequence(context));
70 
71  switch(m_operator)
72  {
73  case Intersect:
74  return Item::Iterator::Ptr(new IntersectIterator(op1, op2));
75  case Except:
76  return Item::Iterator::Ptr(new ExceptIterator(op1, op2));
77  default:
78  {
80  return Item::Iterator::Ptr(new UnionIterator(op1, op2));
81  }
82  }
83 }
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
Implements the except operator. That is, the computation of the sequence of nodes from one sequence...
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< Item > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.
Implements the except operator. That is, the computation of the sequence of nodes from one sequence...
virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const
Implements the intersect operator. That is, the computation of the intersection between two sequences...

◆ evaluateSingleton()

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

Reimplemented from QPatternist::Expression.

Definition at line 85 of file qcombinenodes.cpp.

86 {
87  return evaluateSequence(context)->next();
88 }
virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const

◆ expectedOperandTypes()

SequenceType::List CombineNodes::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 149 of file qcombinenodes.cpp.

150 {
151  SequenceType::List result;
154  return result;
155 }
static const SequenceType::Ptr ZeroOrMoreNodes
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 CombineNodes::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 167 of file qcombinenodes.cpp.

◆ operatorID()

CombineNodes::Operator CombineNodes::operatorID ( ) const

Definition at line 157 of file qcombinenodes.cpp.

158 {
159  return m_operator;
160 }

◆ staticType()

SequenceType::Ptr CombineNodes::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 132 of file qcombinenodes.cpp.

133 {
136 
137  Cardinality card;
138 
139  /* Optimization: the cardinality can be better inferred for
140  * Intersect and Except, although it's not trivial code. */
141  if(m_operator == Union)
142  card = t1->cardinality() | t2->cardinality();
143  else /* Except. */
144  card = Cardinality::zeroOrMore();
145 
146  return makeGenericSequenceType(t1->itemType() | t2->itemType(), card);
147 }
static Cardinality zeroOrMore()
virtual SequenceType::Ptr staticType() const =0
Represents a cardinality, a possible , often represented by occurrence indicators.

◆ typeCheck()

Expression::Ptr CombineNodes::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 90 of file qcombinenodes.cpp.

92 {
93 
94  const Expression::Ptr me(PairContainer::typeCheck(context, reqType));
95 
98 
99  return me;
100 }
virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
Definition: qexpression.cpp:70
static Expression::Ptr wrapAround(const Expression::Ptr &operand, const StaticContext::Ptr &context)
Definition: qnodesort.cpp:92

Properties

◆ m_operator

const Operator QPatternist::CombineNodes::m_operator
private

Definition at line 108 of file qcombinenodes_p.h.

Referenced by evaluateEBV(), evaluateSequence(), operatorID(), and staticType().


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