1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
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 The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "qbuiltintypes_p.h" |
41 | #include "qcommonsequencetypes_p.h" |
42 | #include "qcurrentitemcontext_p.h" |
43 | #include "qstaticcurrentcontext_p.h" |
44 | |
45 | #include "qcurrentitemstore_p.h" |
46 | |
47 | QT_BEGIN_NAMESPACE |
48 | |
49 | using namespace QPatternist; |
50 | |
51 | CurrentItemStore::CurrentItemStore(const Expression::Ptr &operand) : SingleContainer(operand) |
52 | { |
53 | } |
54 | |
55 | DynamicContext::Ptr CurrentItemStore::createContext(const DynamicContext::Ptr &old) const |
56 | { |
57 | return DynamicContext::Ptr(new CurrentItemContext(old->contextItem(), old)); |
58 | } |
59 | |
60 | bool CurrentItemStore::evaluateEBV(const DynamicContext::Ptr &context) const |
61 | { |
62 | return m_operand->evaluateEBV(context: createContext(old: context)); |
63 | } |
64 | |
65 | Item::Iterator::Ptr CurrentItemStore::evaluateSequence(const DynamicContext::Ptr &context) const |
66 | { |
67 | return m_operand->evaluateSequence(context: createContext(old: context)); |
68 | } |
69 | |
70 | Item CurrentItemStore::evaluateSingleton(const DynamicContext::Ptr &context) const |
71 | { |
72 | return m_operand->evaluateSingleton(context: createContext(old: context)); |
73 | } |
74 | |
75 | SequenceType::Ptr CurrentItemStore::staticType() const |
76 | { |
77 | return m_operand->staticType(); |
78 | } |
79 | |
80 | SequenceType::List CurrentItemStore::expectedOperandTypes() const |
81 | { |
82 | SequenceType::List result; |
83 | result.append(t: CommonSequenceTypes::ZeroOrMoreItems); |
84 | return result; |
85 | } |
86 | |
87 | StaticContext::Ptr CurrentItemStore::newStaticContext(const StaticContext::Ptr &context) |
88 | { |
89 | /* It might be we are generated despite there is no focus. In that case |
90 | * an error will reported in case current() is used, but in any case we cannot |
91 | * crash, so use item() in case we have no focus. |
92 | * |
93 | * Such a case is when we're inside a named template, and it's invoked |
94 | * without focus. */ |
95 | const ItemType::Ptr t(context->contextItemType()); |
96 | return StaticContext::Ptr(new StaticCurrentContext(t ? t : BuiltinTypes::item, context)); |
97 | } |
98 | |
99 | Expression::Ptr CurrentItemStore::compress(const StaticContext::Ptr &context) |
100 | { |
101 | const Expression::Ptr me(SingleContainer::compress(context: newStaticContext(context))); |
102 | |
103 | if(me != this) |
104 | return me; |
105 | else |
106 | { |
107 | /* If fn:current() isn't called, there's no point in us sticking |
108 | * around. */ |
109 | if(m_operand->deepProperties().testFlag(flag: RequiresCurrentItem)) |
110 | return me; |
111 | else |
112 | return m_operand; |
113 | } |
114 | } |
115 | |
116 | Expression::Ptr CurrentItemStore::typeCheck(const StaticContext::Ptr &context, |
117 | const SequenceType::Ptr &reqType) |
118 | { |
119 | return SingleContainer::typeCheck(context: newStaticContext(context), reqType); |
120 | } |
121 | |
122 | ExpressionVisitorResult::Ptr CurrentItemStore::accept(const ExpressionVisitor::Ptr &visitor) const |
123 | { |
124 | return visitor->visit(this); |
125 | } |
126 | |
127 | const SourceLocationReflection *CurrentItemStore::actualReflection() const |
128 | { |
129 | return m_operand->actualReflection(); |
130 | } |
131 | |
132 | Expression::Properties CurrentItemStore::properties() const |
133 | { |
134 | return m_operand->properties() & (RequiresFocus | IsEvaluated | DisableElimination); |
135 | } |
136 | |
137 | QT_END_NAMESPACE |
138 | |