Qt 4.8
qreturnorderby.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qcommonsequencetypes_p.h"
43 #include "qexpressionsequence_p.h"
44 #include "qsorttuple_p.h"
45 
46 #include "qreturnorderby_p.h"
47 
49 
50 using namespace QPatternist;
51 
53  const OrderBy::OrderSpec::Vector &oSpecs,
54  const Expression::List &ops) : 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 }
63 
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 }
79 
81 {
82  // TODO This is temporary code.
83  return m_operands.first()->evaluateEBV(context);
84 }
85 
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 }
103 
105 {
106  /* For some unknown reason this is necessary for XQTS test case orderBy18. */
107  return DisableElimination;
108 }
109 
111 {
112  return visitor->visit(this);
113 }
114 
116 {
117  return m_operands.first()->staticType();
118 }
119 
121 {
122  SequenceType::List result;
125  return result;
126 }
127 
129 {
130  return IDReturnOrderBy;
131 }
132 
virtual bool evaluateEBV(const DynamicContext::Ptr &context) const
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
virtual Properties properties() const
OrderBy::OrderSpec::Vector m_orderSpecs
static const SequenceType::Ptr ZeroOrMoreItems
virtual bool evaluateEBV(const DynamicContext::Ptr &context) const
QAbstractXmlForwardIterator< T >::Ptr makeListIterator(const QList< T > &list)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual SequenceType::List expectedOperandTypes() const
virtual Expression::Ptr compress(const StaticContext::Ptr &context)
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
virtual ExpressionVisitorResult::Ptr accept(const ExpressionVisitor::Ptr &visitor) const
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The namespace for the internal API of QtXmlPatterns.
virtual Expression::Ptr compress(const StaticContext::Ptr &context)
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
virtual SequenceType::Ptr staticType() const =0
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
virtual SequenceType::Ptr staticType() const
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
Base class for expressions that has any amount of operands.
The QFlags class provides a type-safe way of storing OR-combinations of enum values.
Definition: qglobal.h:2313
static const SequenceType::Ptr ZeroOrOneAtomicType
ReturnOrderBy(const OrderBy::Stability stability, const OrderBy::OrderSpec::Vector &oSpecs, const Expression::List &operands)
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const
virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const
#define Q_FUNC_INFO
Definition: qglobal.h:1871