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 | // |
41 | // W A R N I N G |
42 | // ------------- |
43 | // |
44 | // This file is not part of the Qt API. It exists purely as an |
45 | // implementation detail. This header file may change from version to |
46 | // version without notice, or even be removed. |
47 | // |
48 | // We mean it. |
49 | |
50 | #ifndef Patternist_StaticContext_H |
51 | #define Patternist_StaticContext_H |
52 | |
53 | #include <private/qexternalvariableloader_p.h> |
54 | #include <private/qitemtype_p.h> |
55 | #include <private/qnamepool_p.h> |
56 | #include <private/qnamespaceresolver_p.h> |
57 | #include <private/qreportcontext_p.h> |
58 | #include <private/qresourceloader_p.h> |
59 | |
60 | QT_BEGIN_NAMESPACE |
61 | |
62 | class QUrl; |
63 | template<typename Key, typename T> class QHash; |
64 | |
65 | namespace QPatternist |
66 | { |
67 | class DynamicContext; |
68 | class Expression; |
69 | class FunctionFactory; |
70 | class SchemaTypeFactory; |
71 | |
72 | /** |
73 | * @short Carries information and facilities used at compilation time. |
74 | * |
75 | * A representation of the Static Context in XPath 2.0. The Static Context |
76 | * contains information which doesn't change and is the "outer scope" of the |
77 | * expression. It provides for example a base URI the expression can relate to and |
78 | * what functions and variables that are available for the expression. |
79 | * |
80 | * @see <a href="http://www.w3.org/TR/xpath20/#static_context">XML Path |
81 | * Language (XPath) 2.0, 2.1.1 Static Context</a> |
82 | * @author Frans Englich <frans.englich@nokia.com> |
83 | */ |
84 | class StaticContext : public ReportContext |
85 | { |
86 | public: |
87 | /** |
88 | * A smart pointer wrapping StaticContext instances. |
89 | */ |
90 | typedef QExplicitlySharedDataPointer<StaticContext> Ptr; |
91 | |
92 | /** |
93 | * @see <a href="http://www.w3.org/TR/xquery/#id-boundary-space-decls">XQuery 1.0: |
94 | * An XML Query Language, 4.3 Boundary-space Declaration</a> |
95 | * @see <a href="http://www.w3.org/TR/xquery/#dt-boundary-space-policy">XQuery 1.0: |
96 | * An XML Query Language, Definition: Boundary-space policy</a> |
97 | */ |
98 | enum BoundarySpacePolicy |
99 | { |
100 | BSPPreserve, |
101 | BSPStrip |
102 | }; |
103 | |
104 | /** |
105 | * @see <a href="http://www.w3.org/TR/xquery/#id-construction-declaration">XQuery 1.0: |
106 | * An XML Query Language, 4.6 Construction Declaration</a> |
107 | * @see <a href="http://www.w3.org/TR/xquery/#dt-construction-mode">XQuery 1.0: |
108 | * An XML Query Language, Definition: Construction mode</a> |
109 | */ |
110 | enum ConstructionMode |
111 | { |
112 | CMPreserve, |
113 | CMStrip |
114 | }; |
115 | |
116 | /** |
117 | * @see <a href="http://www.w3.org/TR/xquery/#id-default-ordering-decl">XQuery 1.0: |
118 | * An XML Query Language, 4.7 Ordering Mode Declaration</a> |
119 | * @see <a href="http://www.w3.org/TR/xquery/#dt-ordering-mode">XQuery 1.0: |
120 | * An XML Query Language, Definition: Ordering mode</a> |
121 | */ |
122 | enum OrderingMode |
123 | { |
124 | Ordered, |
125 | Unordered |
126 | }; |
127 | |
128 | /** |
129 | * @see <a href="http://www.w3.org/TR/xquery/#id-empty-order-decl">XQuery 1.0: |
130 | * An XML Query Language, 4.8 Empty Order Declaration</a> |
131 | * @see <a href="http://www.w3.org/TR/xquery/#dt-default-empty-order">XQuery 1.0: |
132 | * An XML Query Language, Definition: Default order for empty sequences</a> |
133 | */ |
134 | enum OrderingEmptySequence |
135 | { |
136 | Greatest, |
137 | Least |
138 | }; |
139 | |
140 | enum InheritMode |
141 | { |
142 | Inherit, |
143 | NoInherit |
144 | }; |
145 | |
146 | enum PreserveMode |
147 | { |
148 | Preserve, |
149 | NoPreserve |
150 | }; |
151 | |
152 | inline StaticContext() |
153 | { |
154 | } |
155 | |
156 | virtual ~StaticContext(); |
157 | |
158 | virtual NamespaceResolver::Ptr namespaceBindings() const = 0; |
159 | virtual void setNamespaceBindings(const NamespaceResolver::Ptr &) = 0; |
160 | virtual QExplicitlySharedDataPointer<FunctionFactory> functionSignatures() const = 0; |
161 | virtual QExplicitlySharedDataPointer<SchemaTypeFactory> schemaDefinitions() const = 0; |
162 | |
163 | /** |
164 | * The base URI of the context. Typically, this is the base URI |
165 | * if of the element that contained the expression. |
166 | * |
167 | * The base URI is in this implementation is never undefined, but is |
168 | * always valid. |
169 | */ |
170 | virtual QUrl baseURI() const = 0; |
171 | |
172 | virtual void setBaseURI(const QUrl &uri) = 0; |
173 | |
174 | /** |
175 | * @returns always the standard function namespace defined in |
176 | * <a href="http://www.w3.org/TR/xpath-functions/">XQuery 1.0 and |
177 | * XPath 2.0 Functions and Operators</a> |
178 | */ |
179 | virtual QString defaultFunctionNamespace() const = 0; |
180 | virtual void setDefaultFunctionNamespace(const QString &ns) = 0; |
181 | |
182 | virtual QString defaultElementNamespace() const = 0; |
183 | virtual void setDefaultElementNamespace(const QString &ns) = 0; |
184 | |
185 | /** |
186 | * @returns the URI identifying the default collation. The function |
187 | * is responsible for ensuring a collation is always returned. If |
188 | * a collation is not provided by the user or the host language in the |
189 | * context, the Unicode codepoint URI should be returned. |
190 | */ |
191 | virtual QUrl defaultCollation() const = 0; |
192 | |
193 | virtual void setDefaultCollation(const QUrl &uri) = 0; |
194 | |
195 | /** |
196 | * Determine whether Backwards Compatible Mode is used. |
197 | * |
198 | * @see <a href="http://www.w3.org/TR/xpath20/#id-backwards-compatibility">XML Path |
199 | * Language (XPath) 2.0, I Backwards Compatibility with XPath 1.0 (Non-Normative)</a> |
200 | * @see <a href="http://www.w3.org/TR/xpath20/#dt-xpath-compat-mode">XML Path |
201 | * Language (XPath) 2.0, Definition: XPath 1.0 compatibility mode</a> |
202 | */ |
203 | virtual bool compatModeEnabled() const = 0; |
204 | |
205 | virtual void setCompatModeEnabled(const bool newVal) = 0; |
206 | |
207 | /** |
208 | * This is the DynamicContext that is used for pre-evaluation at |
209 | * compilation time, const-folding at the static stage. |
210 | */ |
211 | virtual QExplicitlySharedDataPointer<DynamicContext> dynamicContext() const = 0; |
212 | |
213 | virtual BoundarySpacePolicy boundarySpacePolicy() const = 0; |
214 | virtual void setBoundarySpacePolicy(const BoundarySpacePolicy policy) = 0; |
215 | |
216 | virtual ConstructionMode constructionMode() const = 0; |
217 | virtual void setConstructionMode(const ConstructionMode mode) = 0; |
218 | |
219 | virtual OrderingMode orderingMode() const = 0; |
220 | virtual void setOrderingMode(const OrderingMode mode) = 0; |
221 | virtual OrderingEmptySequence orderingEmptySequence() const = 0; |
222 | virtual void setOrderingEmptySequence(const OrderingEmptySequence ordering) = 0; |
223 | |
224 | virtual InheritMode inheritMode() const = 0; |
225 | virtual void setInheritMode(const InheritMode mode) = 0; |
226 | |
227 | virtual PreserveMode preserveMode() const = 0; |
228 | virtual void setPreserveMode(const PreserveMode mode) = 0; |
229 | |
230 | /** |
231 | * @short The static type of the context item. |
232 | * |
233 | * Different StaticContext instances are used for different nodes in the |
234 | * AST to properly reflect the type of the focus. If the focus is undefined, |
235 | * this function must return @c null. |
236 | * |
237 | * @see <a href="http://www.w3.org/TR/xquery/#dt-context-item-static-type">XQuery |
238 | * 1.0: An XML Query Language, Definition: Context item static type</a> |
239 | */ |
240 | virtual ItemType::Ptr contextItemType() const = 0; |
241 | |
242 | /** |
243 | * @short The static type of the current item, as returned by @c |
244 | * fn:current(). |
245 | */ |
246 | virtual ItemType::Ptr currentItemType() const = 0; |
247 | |
248 | /** |
249 | * Copies this StaticContext and returns the copy. |
250 | * |
251 | * The copy and original must not be independent. Since the StaticContext is modified |
252 | * during the compilation process, the copy must be independent from the original |
253 | * to the degree that is required for the subclass in question. |
254 | */ |
255 | virtual StaticContext::Ptr copy() const = 0; |
256 | |
257 | virtual ExternalVariableLoader::Ptr externalVariableLoader() const = 0; |
258 | virtual ResourceLoader::Ptr resourceLoader() const = 0; |
259 | virtual NamePool::Ptr namePool() const = 0; |
260 | |
261 | /** |
262 | * @short Adds @p location for @p reflection. |
263 | */ |
264 | virtual void addLocation(const SourceLocationReflection *const reflection, |
265 | const QSourceLocation &location) = 0; |
266 | |
267 | /** |
268 | * @short Returns a hash of the contained locations. |
269 | * |
270 | * The key is the address for the expression, and the value is its location. Note |
271 | * that the key cannot be dereferenced, there's no guarantee the |
272 | * Expression is in scope. The key is merely an identifier. |
273 | */ |
274 | virtual LocationHash sourceLocations() const = 0; |
275 | |
276 | virtual VariableSlotID currentRangeSlot() const = 0; |
277 | virtual VariableSlotID allocateRangeSlot() = 0; |
278 | |
279 | /** |
280 | * @short Ensures source locations are handled in such a manner that @p |
281 | * existingNode wraps @p newNode. |
282 | * |
283 | * Ensures that the source locations for @p existingNode, applies to |
284 | * @p newNode. |
285 | */ |
286 | void wrapExpressionWith(const SourceLocationReflection *const existingNode, |
287 | const QExplicitlySharedDataPointer<Expression> &newNode); |
288 | }; |
289 | } |
290 | |
291 | QT_END_NAMESPACE |
292 | |
293 | #endif |
294 | |