Qt 4.8
Public Functions | Properties | List of all members
QPatternist::ReturnOrderBy Class Reference

Together with OrderBy, it implements XQuery 1.0's order by expression. More...

#include <qreturnorderby_p.h>

Inheritance diagram for QPatternist::ReturnOrderBy:
QPatternist::UnlimitedContainer 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 bool evaluateEBV (const DynamicContext::Ptr &context) const
 
virtual Item evaluateSingleton (const DynamicContext::Ptr &context) const
 
virtual SequenceType::List expectedOperandTypes () const
 
virtual ID id () const
 
OrderBy::OrderSpec::Vector orderSpecs () const
 
virtual Properties properties () const
 
 ReturnOrderBy (const OrderBy::Stability stability, const OrderBy::OrderSpec::Vector &oSpecs, const Expression::List &operands)
 
void setStay (const bool a)
 
OrderBy::Stability stability () const
 
virtual SequenceType::Ptr staticType () const
 
- Public Functions inherited from QPatternist::UnlimitedContainer
virtual bool compressOperands (const StaticContext::Ptr &)
 
virtual Expression::List operands () const
 
virtual void setOperands (const Expression::List &list)
 
 UnlimitedContainer (const Expression::List &operands=Expression::List())
 
- 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 Item::Iterator::Ptr evaluateSequence (const DynamicContext::Ptr &context) 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
 
const Expression::Ptrrewrite (const Expression::Ptr &to, const StaticContext::Ptr &context) const
 Rewrites this Expression to to, and return to. More...
 
virtual Expression::Ptr typeCheck (const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
 
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 ()
 

Properties

bool m_flyAway
 
OrderBy::OrderSpec::Vector m_orderSpecs
 
const OrderBy::Stability m_stability
 

Additional Inherited Members

- Public Types inherited from QPatternist::UnlimitedContainer
enum  CardinalityComputation { ProductOfCardinality, UnionOfCardinality }
 
- 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::UnlimitedContainer
template<CardinalityComputation suppliedCard>
SequenceType::Ptr operandsUnionType () const
 
- 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::UnlimitedContainer
Expression::List m_operands
 

Detailed Description

Together with OrderBy, it implements XQuery 1.0's order by expression.

ReturnOrderBy evaluates the sort keys and values, and hands it over to OrderBy, which is an AST ancestor, using SortTuples.

Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 73 of file qreturnorderby_p.h.

Constructors and Destructors

◆ ReturnOrderBy()

ReturnOrderBy::ReturnOrderBy ( const OrderBy::Stability  stability,
const OrderBy::OrderSpec::Vector oSpecs,
const Expression::List operands 
)

In operands the first item is the return expression, and the rest, which is at least one, are the sort keys.

Definition at line 52 of file qreturnorderby.cpp.

54  : UnlimitedContainer(ops)
55  , m_stability(aStability)
56  , m_orderSpecs(oSpecs)
57  , m_flyAway(true)
58 {
60  "ReturnOrderBy must have the return expression, and at least one sort key.");
61  Q_ASSERT(m_orderSpecs.size() == ops.size() - 1);
62 }
OrderBy::OrderSpec::Vector m_orderSpecs
const OrderBy::Stability m_stability
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
UnlimitedContainer(const Expression::List &operands=Expression::List())
#define Q_FUNC_INFO
Definition: qglobal.h:1871

Functions

◆ accept()

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

Implements QPatternist::Expression.

Definition at line 110 of file qreturnorderby.cpp.

111 {
112  return visitor->visit(this);
113 }

◆ compress()

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

compress() is the last stage performs in compiling an expression, done after the initial AST build and calling typeCheck(). compress() performs crucial simplifications, either by having drastic performance implications or that some expressions depend on it for proper behavior.

The default implementation performs a sparse conditional constant propagation. In short, a recursive process is performed in the AST which examines if the Expression's operands are constant values, and if so, performs a const fold(AST rewrite) into the result of evaluating the expression in question. This default behavior can be disabled by letting properties() return DisableElimination.

This compress() stage can be relative effective due to the design of XPath, in part because intrinsic functions are heavily used. Many Expressions override compress() and do optimizations specific to what they do. Also, many Expressions performs optimizations in their typeCheck().

Parameters
contextthe static context. Supplies compile time information, and is the channel for communicating error messages.
See also
Wikipedia, the free encyclopedia, Sparse conditional constant propagation
Wikipedia, the free encyclopedia, Intrinsic function
Wikipedia, the free encyclopedia, Compiler optimization

Reimplemented from QPatternist::Expression.

Definition at line 86 of file qreturnorderby.cpp.

87 {
88  /* We first did this in typeCheck(), but that broke due to that type checks were
89  * missed, which other pieces relied on. */
90  if(m_flyAway)
91  {
92  /* We only want the return expression, not the sort keys. */
93  return m_operands.first()->compress(context);
94  }
95  else
96  {
97  /* We don't need the members, so don't keep a reference to them. */
99 
100  return UnlimitedContainer::compress(context);
101  }
102 }
OrderBy::OrderSpec::Vector m_orderSpecs
virtual Expression::Ptr compress(const StaticContext::Ptr &context)
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282

◆ evaluateEBV()

bool ReturnOrderBy::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 80 of file qreturnorderby.cpp.

81 {
82  // TODO This is temporary code.
83  return m_operands.first()->evaluateEBV(context);
84 }
virtual bool evaluateEBV(const DynamicContext::Ptr &context) const
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282

◆ evaluateSingleton()

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

Reimplemented from QPatternist::Expression.

Definition at line 64 of file qreturnorderby.cpp.

65 {
66  Q_ASSERT(m_operands.size() > 1);
67  const Item::Iterator::Ptr value(makeListIterator(m_operands.first()->evaluateSequence(context)->toList()));
68  Item::Vector sortKeys;
69 
70  /* We're skipping the first operand. */
71  const int len = m_operands.size() - 1;
72  sortKeys.resize(len);
73 
74  for(int i = 1; i <= len; ++i)
75  sortKeys[i - 1] = m_operands.at(i)->evaluateSingleton(context);
76 
77  return Item(new SortTuple(value, sortKeys));
78 }
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
QAbstractXmlForwardIterator< T >::Ptr makeListIterator(const QList< T > &list)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QVector< Item > Vector
Definition: qitem_p.h:200
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
Represents a value and its sort keys in FLOWR&#39;s order by clause.
Definition: qsorttuple_p.h:81
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const
virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const

◆ expectedOperandTypes()

SequenceType::List ReturnOrderBy::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 120 of file qreturnorderby.cpp.

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

◆ id()

Expression::ID ReturnOrderBy::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 128 of file qreturnorderby.cpp.

◆ orderSpecs()

OrderBy::OrderSpec::Vector QPatternist::ReturnOrderBy::orderSpecs ( ) const
inline

Definition at line 92 of file qreturnorderby_p.h.

Referenced by QPatternist::yyparse().

93  {
94  return m_orderSpecs;
95  }
OrderBy::OrderSpec::Vector m_orderSpecs

◆ properties()

Expression::Properties ReturnOrderBy::properties ( ) const
virtual
Returns
a bitwise OR'd value of properties, describing the characteristics of the expression. These properties affects how this Expression is treated in for example type checking stages.

The default implementation returns 0. Override and let the function return a different value, if that's of interest.

An important decision when re-implementing properties() is whether to OR in the properties() of ones operands. For instance, if an operand has RequiresFocus set, that flag nost likely applies to the apparent as well, since it depends on its operand.

See also
deepProperties()
Returns
Expression::None, meaning no special properties

Reimplemented from QPatternist::Expression.

Definition at line 104 of file qreturnorderby.cpp.

Referenced by setStay().

105 {
106  /* For some unknown reason this is necessary for XQTS test case orderBy18. */
107  return DisableElimination;
108 }

◆ setStay()

void QPatternist::ReturnOrderBy::setStay ( const bool  a)
inline

In the case of that we don't have a for-expression beloning us, but only a let clause, this ReturnOrderBy breaks if it stays in the AST. So, by default we assume that we should write ourselves away, unless this function is called. The associated ForClause will call it during typeCheck(), if it exists.

Definition at line 109 of file qreturnorderby_p.h.

Referenced by QPatternist::OrderBy::compress(), and QPatternist::OrderBy::typeCheck().

110  {
111  m_flyAway = !a;
112  }
long ASN1_INTEGER_get ASN1_INTEGER * a

◆ stability()

OrderBy::Stability QPatternist::ReturnOrderBy::stability ( ) const
inline

Definition at line 97 of file qreturnorderby_p.h.

Referenced by QPatternist::yyparse().

98  {
99  return m_stability;
100  }
const OrderBy::Stability m_stability

◆ staticType()

SequenceType::Ptr ReturnOrderBy::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 115 of file qreturnorderby.cpp.

116 {
117  return m_operands.first()->staticType();
118 }
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
virtual SequenceType::Ptr staticType() const =0

Properties

◆ m_flyAway

bool QPatternist::ReturnOrderBy::m_flyAway
private
See also
stay()

Definition at line 128 of file qreturnorderby_p.h.

Referenced by compress(), and setStay().

◆ m_orderSpecs

OrderBy::OrderSpec::Vector QPatternist::ReturnOrderBy::m_orderSpecs
private

Definition at line 123 of file qreturnorderby_p.h.

Referenced by compress(), orderSpecs(), and ReturnOrderBy().

◆ m_stability

const OrderBy::Stability QPatternist::ReturnOrderBy::m_stability
private

This variable is unfortunately only used at compile time. However, it's tricky to get rid of it due to how QueryTransformParser would have to be adapted.

Definition at line 121 of file qreturnorderby_p.h.

Referenced by stability().


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