1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qbuiltintypes_p.h"
|
---|
43 | #include "qcommonsequencetypes_p.h"
|
---|
44 | #include "qgenericsequencetype_p.h"
|
---|
45 | #include "qnodesort_p.h"
|
---|
46 | #include "qpatternistlocale_p.h"
|
---|
47 | #include "qsequencemappingiterator_p.h"
|
---|
48 | #include "qtypechecker_p.h"
|
---|
49 |
|
---|
50 | #include "qpath_p.h"
|
---|
51 |
|
---|
52 | QT_BEGIN_NAMESPACE
|
---|
53 |
|
---|
54 | using namespace QPatternist;
|
---|
55 |
|
---|
56 | Path::Path(const Expression::Ptr &operand1,
|
---|
57 | const Expression::Ptr &operand2,
|
---|
58 | const Kind kind) : PairContainer(operand1, operand2)
|
---|
59 | , m_hasCreatedSorter(kind != RegularPath)
|
---|
60 | , m_isLast(false)
|
---|
61 | , m_checkXPTY0018(kind == RegularPath)
|
---|
62 | , m_kind(kind)
|
---|
63 | {
|
---|
64 | }
|
---|
65 |
|
---|
66 | Item::Iterator::Ptr Path::mapToSequence(const Item &item,
|
---|
67 | const DynamicContext::Ptr &context) const
|
---|
68 | {
|
---|
69 | /* item is the focus here. That is in <e/>/1, item is <e/>. However,
|
---|
70 | * we don't use it, since the context item is accessed through
|
---|
71 | * DynamicContext::focusIterator() and friends. */
|
---|
72 | Q_ASSERT(item);
|
---|
73 | Q_UNUSED(item); /* Needed when compiling in release mode. */
|
---|
74 | return m_operand2->evaluateSequence(context);
|
---|
75 | }
|
---|
76 |
|
---|
77 | Item::Iterator::Ptr Path::evaluateSequence(const DynamicContext::Ptr &context) const
|
---|
78 | {
|
---|
79 | /* Note, we use the old context for m_operand1. */
|
---|
80 | const Item::Iterator::Ptr source(m_operand1->evaluateSequence(context));
|
---|
81 |
|
---|
82 | const DynamicContext::Ptr focus(context->createFocus());
|
---|
83 | focus->setFocusIterator(source);
|
---|
84 |
|
---|
85 | const Item::Iterator::Ptr result(makeSequenceMappingIterator<Item>(ConstPtr(this), source, focus));
|
---|
86 |
|
---|
87 | if(m_checkXPTY0018)
|
---|
88 | {
|
---|
89 | /* This is an expensive code path, but it should happen very rarely. */
|
---|
90 |
|
---|
91 | enum FoundItem
|
---|
92 | {
|
---|
93 | FoundNone,
|
---|
94 | FoundNode,
|
---|
95 | FoundAtomicValue
|
---|
96 | } hasFound = FoundNone;
|
---|
97 |
|
---|
98 | Item::List whenChecked;
|
---|
99 |
|
---|
100 | Item next(result->next());
|
---|
101 |
|
---|
102 | while(next)
|
---|
103 | {
|
---|
104 | const FoundItem found = next.isAtomicValue() ? FoundAtomicValue : FoundNode;
|
---|
105 |
|
---|
106 | if(hasFound != FoundNone && hasFound != found)
|
---|
107 | {
|
---|
108 | /* It's an atomic value and we've already found a node. Mixed content. */
|
---|
109 | context->error(QtXmlPatterns::tr("The last step in a path must contain either nodes "
|
---|
110 | "or atomic values. It cannot be a mixture between the two."),
|
---|
111 | ReportContext::XPTY0018, this);
|
---|
112 | }
|
---|
113 | else
|
---|
114 | hasFound = found;
|
---|
115 |
|
---|
116 | whenChecked.append(next);
|
---|
117 | next = result->next();
|
---|
118 | }
|
---|
|
---|