1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
46 // This file is not part of the Qt API. It exists purely as an
47 // implementation detail. This header file may change from version to
48 // version without notice, or even be removed.
52 #ifndef Patternist_StaticContext_H
53 #define Patternist_StaticContext_H
55 #include <private/qexternalvariableloader_p.h>
56 #include <private/qitemtype_p.h>
57 #include <private/qnamepool_p.h>
58 #include <private/qnamespaceresolver_p.h>
59 #include <private/qreportcontext_p.h>
60 #include <private/qresourceloader_p.h>
67 template<typename Key, typename T> class QHash;
73 class FunctionFactory;
74 class SchemaTypeFactory;
77 * @short Carries information and facilities used at compilation time.
79 * A representation of the Static Context in XPath 2.0. The Static Context
80 * contains information which doesn't change and is the "outer scope" of the
81 * expression. It provides for example a base URI the expression can relate to and
82 * what functions and variables that are available for the expression.
84 * @see <a href="http://www.w3.org/TR/xpath20/#static_context">XML Path
85 * Language (XPath) 2.0, 2.1.1 Static Context</a>
86 * @author Frans Englich <frans.englich@nokia.com>
88 class StaticContext : public ReportContext
92 * A smart pointer wrapping StaticContext instances.
94 typedef QExplicitlySharedDataPointer<StaticContext> Ptr;
97 * @see <a href="http://www.w3.org/TR/xquery/#id-boundary-space-decls">XQuery 1.0:
98 * An XML Query Language, 4.3 Boundary-space Declaration</a>
99 * @see <a href="http://www.w3.org/TR/xquery/#dt-boundary-space-policy">XQuery 1.0:
100 * An XML Query Language, Definition: Boundary-space policy</a>
102 enum BoundarySpacePolicy
109 * @see <a href="http://www.w3.org/TR/xquery/#id-construction-declaration">XQuery 1.0:
110 * An XML Query Language, 4.6 Construction Declaration</a>
111 * @see <a href="http://www.w3.org/TR/xquery/#dt-construction-mode">XQuery 1.0:
112 * An XML Query Language, Definition: Construction mode</a>
114 enum ConstructionMode
121 * @see <a href="http://www.w3.org/TR/xquery/#id-default-ordering-decl">XQuery 1.0:
122 * An XML Query Language, 4.7 Ordering Mode Declaration</a>
123 * @see <a href="http://www.w3.org/TR/xquery/#dt-ordering-mode">XQuery 1.0:
124 * An XML Query Language, Definition: Ordering mode</a>
133 * @see <a href="http://www.w3.org/TR/xquery/#id-empty-order-decl">XQuery 1.0:
134 * An XML Query Language, 4.8 Empty Order Declaration</a>
135 * @see <a href="http://www.w3.org/TR/xquery/#dt-default-empty-order">XQuery 1.0:
136 * An XML Query Language, Definition: Default order for empty sequences</a>
138 enum OrderingEmptySequence
156 inline StaticContext()
160 virtual ~StaticContext();
162 virtual NamespaceResolver::Ptr namespaceBindings() const = 0;
163 virtual void setNamespaceBindings(const NamespaceResolver::Ptr &) = 0;
164 virtual QExplicitlySharedDataPointer<FunctionFactory> functionSignatures() const = 0;
165 virtual QExplicitlySharedDataPointer<SchemaTypeFactory> schemaDefinitions() const = 0;
168 * The base URI of the context. Typically, this is the base URI
169 * if of the element that contained the expression.
171 * The base URI is in this implementation is never undefined, but is
174 virtual QUrl baseURI() const = 0;
176 virtual void setBaseURI(const QUrl &uri) = 0;
179 * @returns always the standard function namespace defined in
180 * <a href="http://www.w3.org/TR/xpath-functions/">XQuery 1.0 and
181 * XPath 2.0 Functions and Operators</a>
183 virtual QString defaultFunctionNamespace() const = 0;
184 virtual void setDefaultFunctionNamespace(const QString &ns) = 0;
186 virtual QString defaultElementNamespace() const = 0;
187 virtual void setDefaultElementNamespace(const QString &ns) = 0;
190 * @returns the URI identifying the default collation. The function
191 * is responsible for ensuring a collation is always returned. If
192 * a collation is not provided by the user or the host language in the
193 * context, the Unicode codepoint URI should be returned.
195 virtual QUrl defaultCollation() const = 0;
197 virtual void setDefaultCollation(const QUrl &uri) = 0;
200 * Determine whether Backwards Compatible Mode is used.
202 * @see <a href="http://www.w3.org/TR/xpath20/#id-backwards-compatibility">XML Path
203 * Language (XPath) 2.0, I Backwards Compatibility with XPath 1.0 (Non-Normative)</a>
204 * @see <a href="http://www.w3.org/TR/xpath20/#dt-xpath-compat-mode">XML Path
205 * Language (XPath) 2.0, Definition: XPath 1.0 compatibility mode</a>
207 virtual bool compatModeEnabled() const = 0;
209 virtual void setCompatModeEnabled(const bool newVal) = 0;
212 * This is the DynamicContext that is used for pre-evaluation at
213 * compilation time, const-folding at the static stage.
215 virtual QExplicitlySharedDataPointer<DynamicContext> dynamicContext() const = 0;
217 virtual BoundarySpacePolicy boundarySpacePolicy() const = 0;
218 virtual void setBoundarySpacePolicy(const BoundarySpacePolicy policy) = 0;
220 virtual ConstructionMode constructionMode() const = 0;
221 virtual void setConstructionMode(const ConstructionMode mode) = 0;
223 virtual OrderingMode orderingMode() const = 0;
224 virtual void setOrderingMode(const OrderingMode mode) = 0;
225 virtual OrderingEmptySequence orderingEmptySequence() const = 0;
226 virtual void setOrderingEmptySequence(const OrderingEmptySequence ordering) = 0;
228 virtual InheritMode inheritMode() const = 0;
229 virtual void setInheritMode(const InheritMode mode) = 0;
231 virtual PreserveMode preserveMode() const = 0;
232 virtual void setPreserveMode(const PreserveMode mode) = 0;
235 * @short The static type of the context item.
237 * Different StaticContext instances are used for different nodes in the
238 * AST to properly reflect the type of the focus. If the focus is undefined,
239 * this function must return @c null.
241 * @see <a href="http://www.w3.org/TR/xquery/#dt-context-item-static-type">XQuery
242 * 1.0: An XML Query Language, Definition: Context item static type</a>
244 virtual ItemType::Ptr contextItemType() const = 0;
247 * @short The static type of the current item, as returned by @c
250 virtual ItemType::Ptr currentItemType() const = 0;
253 * Copies this StaticContext and returns the copy.
255 * The copy and original must not be independent. Since the StaticContext is modified
256 * during the compilation process, the copy must be independent from the original
257 * to the degree that is required for the subclass in question.
259 virtual StaticContext::Ptr copy() const = 0;
261 virtual ExternalVariableLoader::Ptr externalVariableLoader() const = 0;
262 virtual ResourceLoader::Ptr resourceLoader() const = 0;
263 virtual NamePool::Ptr namePool() const = 0;
266 * @short Adds @p location for @p reflection.
268 virtual void addLocation(const SourceLocationReflection *const reflection,
269 const QSourceLocation &location) = 0;
272 * @short Returns a hash of the contained locations.
274 * The key is the address for the expression, and the value is its location. Note
275 * that the key cannot be dereferenced, there's no guarantee the
276 * Expression is in scope. The key is merely an identifier.
278 virtual LocationHash sourceLocations() const = 0;
280 virtual VariableSlotID currentRangeSlot() const = 0;
281 virtual VariableSlotID allocateRangeSlot() = 0;
284 * @short Ensures source locations are handled in such a manner that @p
285 * existingNode wraps @p newNode.
287 * Ensures that the source locations for @p existingNode, applies to
290 void wrapExpressionWith(const SourceLocationReflection *const existingNode,
291 const QExplicitlySharedDataPointer<Expression> &newNode);