Qt 4.8
qaxisstep.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 "qbuiltintypes_p.h"
43 #include "qcommonsequencetypes_p.h"
44 #include "qitemmappingiterator_p.h"
45 #include "qgenericsequencetype_p.h"
46 #include "qparentnodeaxis_p.h"
47 
48 #include "qaxisstep_p.h"
49 
51 
52 using namespace QPatternist;
53 
54 namespace QPatternist
55 {
61  {
62  return QXmlNodeModelIndex::NodeKind(int(op1) | int(op2));
63  }
64 }
65 
70 {
74  QXmlNodeModelIndex::NodeKind(0), // self;
75  QXmlNodeModelIndex::NodeKind(0), // descendant-or-self;
77  QXmlNodeModelIndex::Document, // following;
79  QXmlNodeModelIndex::Document, // ancestor
80  QXmlNodeModelIndex::Document|QXmlNodeModelIndex::Attribute|QXmlNodeModelIndex::Namespace, // preceding-sibling;
81  QXmlNodeModelIndex::Document|QXmlNodeModelIndex::Attribute|QXmlNodeModelIndex::Namespace, // following-sibling;
82  QXmlNodeModelIndex::Document, // preceding;
83  QXmlNodeModelIndex::NodeKind(0) // ancestor-or-self;
84 };
85 
87 {
88  return (s_whenAxisNodeKindEmpty[(1 >> axis) - 1] & nodeKind) != 0;
89 }
90 
92  const ItemType::Ptr &nt) : m_axis(a),
93  m_nodeTest(nt)
94 {
97  "We assume we're a node type.");
98 }
99 
101  const DynamicContext::Ptr &context) const
102 {
103  Q_ASSERT(!node.isNull());
104  Q_ASSERT(Item(node).isNode());
105  Q_ASSERT(Item(node));
106  Q_UNUSED(context);
107 
108  if(m_nodeTest->itemMatches(Item(node)))
109  return Item(node);
110  else
111  return Item();
112 }
113 
115 {
116  /* If we don't have a focus, it's either a bug or our parent isn't a Path
117  * that have advanced the focus iterator. Hence, attempt to advance the focus on our own. */
118  if(!context->contextItem())
119  context->focusIterator()->next();
120 
121  Q_ASSERT(context->contextItem());
122 
124 
125  return makeItemMappingIterator<Item>(ConstPtr(this), source, context);
126 }
127 
129 {
130  /* If we don't have a focus, it's either a bug or our parent isn't a Path
131  * that have advanced the focus iterator. Hence, attempt to advance the focus on our own. */
132  if(!context->contextItem())
133  context->focusIterator()->next();
134 
135  Q_ASSERT(context->contextItem());
136 
138  QXmlNodeModelIndex next(it->next());
139 
140  while(!next.isNull())
141  {
142  const Item candidate(mapToItem(next, context));
143 
144  if(candidate)
145  return candidate;
146  else
147  next = it->next();
148  };
149 
150  return Item();
151 }
152 
154  const SequenceType::Ptr &reqType)
155 {
157  {
158  /* We only rewrite parent::node() to ParentNodeAxis. */
159  return rewrite(Expression::Ptr(new ParentNodeAxis()), context)->typeCheck(context, reqType);
160  }
161  /* TODO temporarily disabled
162  else if(isAlwaysEmpty(m_axis, static_cast<const AnyNodeType *>(m_nodeTest.data())->nodeKind()))
163  return EmptySequence::create(this, context);
164  */
165  else
166  return EmptyContainer::typeCheck(context, reqType);
167 }
168 
170 {
171  Cardinality cardinality;
172 
174  cardinality = Cardinality::zeroOrOne();
175  else
176  cardinality = Cardinality::zeroOrMore();
177 
178  return makeGenericSequenceType(m_nodeTest,
179  cardinality);
180 }
181 
183 {
184  SequenceType::List result;
186  return result;
187 }
188 
190 {
192 }
193 
195 {
196  return BuiltinTypes::node;
197 }
198 
200 {
201  return visitor->visit(this);
202 }
203 
205 {
206  return m_axis;
207 }
208 
210 {
211  const char *result = 0;
212 
213  switch(axis)
214  {
215  /* These must not be translated. */
216  case QXmlNodeModelIndex::AxisAncestorOrSelf: result = "ancestor-or-self"; break;
217  case QXmlNodeModelIndex::AxisAncestor: result = "ancestor"; break;
218  case QXmlNodeModelIndex::AxisAttributeOrTop: result = "attribute-or-top"; break;
219  case QXmlNodeModelIndex::AxisAttribute: result = "attribute"; break;
220  case QXmlNodeModelIndex::AxisChildOrTop: result = "child-or-top"; break;
221  case QXmlNodeModelIndex::AxisChild: result = "child"; break;
222  case QXmlNodeModelIndex::AxisDescendantOrSelf: result = "descendant-or-self"; break;
223  case QXmlNodeModelIndex::AxisDescendant: result = "descendant"; break;
224  case QXmlNodeModelIndex::AxisFollowing: result = "following"; break;
225  case QXmlNodeModelIndex::AxisFollowingSibling: result = "following-sibling"; break;
226  case QXmlNodeModelIndex::AxisNamespace: result = "namespace"; break;
227  case QXmlNodeModelIndex::AxisParent: result = "parent"; break;
228  case QXmlNodeModelIndex::AxisPreceding: result = "preceding"; break;
229  case QXmlNodeModelIndex::AxisPrecedingSibling: result = "preceding-sibling"; break;
230  case QXmlNodeModelIndex::AxisSelf: result = "self"; break;
231  }
232 
233  Q_ASSERT_X(result, Q_FUNC_INFO, "An unknown axis type was apparently encountered.");
234  return QString::fromLatin1(result);
235 }
236 
238 {
239  return static_cast<const AnyNodeType *>(m_nodeTest.data())->patternPriority();
240 }
241 
243 {
244  return IDAxisStep;
245 }
246 
static Cardinality zeroOrMore()
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
Definition: qaxisstep.cpp:153
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static bool isAlwaysEmpty(const QXmlNodeModelIndex::Axis axis, const QXmlNodeModelIndex::NodeKind nodeKind)
Definition: qaxisstep.cpp:86
Represents the node() item type.
static QXmlNodeModelIndex::NodeKind operator|(const QXmlNodeModelIndex::NodeKind &op1, const QXmlNodeModelIndex::NodeKind &op2)
Definition: qaxisstep.cpp:60
bool isNull() const
Returns true if this QXmlNodeModelIndex is a default constructed value, otherwise false...
#define it(className, varName)
virtual bool itemMatches(const Item &item) const =0
virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &) const
Definition: qaxisstep.cpp:114
QExplicitlySharedDataPointer< const AxisStep > ConstPtr
Definition: qaxisstep_p.h:137
virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
Definition: qexpression.cpp:70
static const SequenceType::Ptr ZeroOrMoreNodes
long ASN1_INTEGER_get ASN1_INTEGER * a
static const QXmlNodeModelIndex::NodeKind s_whenAxisNodeKindEmpty[]
Definition: qaxisstep_p.h:139
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual SequenceType::Ptr staticType() const
Definition: qaxisstep.cpp:169
virtual Properties properties() const
Definition: qaxisstep.cpp:189
virtual Item contextItem() const =0
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
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
ItemType::Ptr m_nodeTest
Definition: qaxisstep_p.h:154
static void rewrite(Expression::Ptr &old, const Expression::Ptr &New, const StaticContext::Ptr &context)
virtual SequenceType::List expectedOperandTypes() const
Definition: qaxisstep.cpp:182
static QString axisName(const QXmlNodeModelIndex::Axis axis)
Prints the EBNF name corresponding to axis.
Definition: qaxisstep.cpp:209
virtual ItemType::Ptr expectedContextItemType() const
Definition: qaxisstep.cpp:194
Item mapToItem(const QXmlNodeModelIndex &node, const DynamicContext::Ptr &context) const
Definition: qaxisstep.cpp:100
The namespace for the internal API of QtXmlPatterns.
#define nt(var, enu)
QXmlNodeModelIndex::Axis axis() const
Definition: qaxisstep.cpp:204
static const AnyNodeType::Ptr node
Corresponds to the expression parent::node().
virtual Item evaluateSingleton(const DynamicContext::Ptr &) const
Definition: qaxisstep.cpp:128
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
static Cardinality zeroOrOne()
const QXmlNodeModelIndex & asNode() const
Definition: qitem_p.h:379
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
NodeKind
Identifies a kind of node.
virtual ID id() const
Definition: qaxisstep.cpp:242
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
AxisStep(const QXmlNodeModelIndex::Axis axis, const ItemType::Ptr &nodeTest)
Definition: qaxisstep.cpp:91
virtual PatternPriority patternPriority() const
Definition: qaxisstep.cpp:237
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< QXmlNodeModelIndex > > iterate(const Axis axis) const
Definition: qitem_p.h:456
virtual Item::Iterator::Ptr focusIterator() const =0
Axis
Identify the axes emanating from a node.
Represents a cardinality, a possible , often represented by occurrence indicators.
The QFlags class provides a type-safe way of storing OR-combinations of enum values.
Definition: qglobal.h:2313
virtual ExpressionVisitorResult::Ptr accept(const ExpressionVisitor::Ptr &visitor) const
Definition: qaxisstep.cpp:199
xsDouble PatternPriority
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
#define Q_FUNC_INFO
Definition: qglobal.h:1871
QXmlNodeModelIndex::Axis m_axis
Definition: qaxisstep_p.h:153