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_ExpressionFactory_H |
51 | #define Patternist_ExpressionFactory_H |
52 | |
53 | #include <QXmlQuery> |
54 | |
55 | #include <private/qexpression_p.h> |
56 | #include <private/qtokenizer_p.h> |
57 | |
58 | #include <QSharedData> |
59 | #include <QUrl> |
60 | |
61 | QT_BEGIN_NAMESPACE |
62 | |
63 | class QIODevice; |
64 | |
65 | namespace QPatternist |
66 | { |
67 | /** |
68 | * @short The central entry point for compiling expressions. |
69 | * |
70 | * @ingroup Patternist_expressions |
71 | * @author Frans Englich <frans.englich@nokia.com> |
72 | */ |
73 | class Q_AUTOTEST_EXPORT ExpressionFactory : public QSharedData |
74 | { |
75 | public: |
76 | typedef QExplicitlySharedDataPointer<ExpressionFactory> Ptr; |
77 | |
78 | /** |
79 | * @short This constructor cannot be synthesized since we |
80 | * use the Q_DISABLE_COPY macro. |
81 | */ |
82 | inline ExpressionFactory() |
83 | { |
84 | } |
85 | |
86 | virtual ~ExpressionFactory() |
87 | { |
88 | } |
89 | |
90 | enum CompilationStage |
91 | { |
92 | QueryBodyInitial = 1, |
93 | QueryBodyTypeCheck = 1 << 1, |
94 | QueryBodyCompression = 1 << 2, |
95 | UserFunctionTypeCheck = 1 << 3, |
96 | UserFunctionCompression = 1 << 4, |
97 | GlobalVariableTypeCheck = 1 << 5 |
98 | }; |
99 | |
100 | /** |
101 | * Creates a compiled representation of the XPath expression @p expr, with Static |
102 | * Context information supplied via @p context. This is for example whether the expression |
103 | * is an XPath 1.0 or XPath 2.0 expression, or what functions that are available. |
104 | * |
105 | * @p requiredType specifies what type results of the evaluating the expression |
106 | * must match. Passing CommonValues::ZeroOrMoreItems allows anything as result, while |
107 | * passing CommonSequenceTypes::EBV means anything but an Effective %Boolean Value extractable |
108 | * result is a type error, for example. |
109 | * |
110 | * @note An empty @p expr is an invalid XPath expression. It will be reported as such, |
111 | * but it is neverthless the caller's resonsibility to ensure that it's not that(since |
112 | * it is likely invalid already in the medium it was stored). |
113 | */ |
114 | virtual Expression::Ptr createExpression(const QString &expr, |
115 | const StaticContext::Ptr &context, |
116 | const QXmlQuery::QueryLanguage lang, |
117 | const SequenceType::Ptr &requiredType, |
118 | const QUrl &queryURI, |
119 | const QXmlName &initialTemplateName); |
120 | |
121 | virtual Expression::Ptr createExpression(QIODevice *const device, |
122 | const StaticContext::Ptr &context, |
123 | const QXmlQuery::QueryLanguage lang, |
124 | const SequenceType::Ptr &requiredType, |
125 | const QUrl &queryURI, |
126 | const QXmlName &initialTemplateName); |
127 | |
128 | /** |
129 | * Finds the last paths of a set of paths(if any) and tells the Path |
130 | * so, such that it can generate the code for checking XPTY0018. |
131 | * |
132 | * Must be called before typeCheck() is called on the operand, since |
133 | * the typeCheck() uses the information for type checking. |
134 | */ |
135 | static void registerLastPath(const Expression::Ptr &operand); |
136 | |
137 | protected: |
138 | enum TemplateCompilationStage |
139 | { |
140 | TemplateInitial = 1, |
141 | TemplateTypeCheck = 1 << 1, |
142 | TemplateCompress = 1 << 2 |
143 | }; |
144 | |
145 | /** |
146 | * This function is called by createExpression() each time |
147 | * after a pass on the AST has been completed. Under a typical |
148 | * compilation this function is thus called three times: after the initial |
149 | * build, after the Expression::typeCheck() stage, and after |
150 | * Expression::compress(). @p tree is the AST after each pass. |
151 | * |
152 | * This mechanism is currently used for debugging, since it provides a |
153 | * way of introspecting what the compilation process do to the tree. The |
154 | * current implementation do nothing. |
155 | */ |
156 | virtual void processTreePass(const Expression::Ptr &tree, |
157 | const CompilationStage stage); |
158 | |
159 | virtual void processTemplateRule(const Expression::Ptr &body, |
160 | const TemplatePattern::Ptr &pattern, |
161 | const QXmlName &mode, |
162 | const TemplateCompilationStage stage); |
163 | |
164 | virtual void processNamedTemplate(const QXmlName &name, |
165 | const Expression::Ptr &tree, |
166 | const TemplateCompilationStage stage); |
167 | |
168 | Expression::Ptr createExpression(const Tokenizer::Ptr &tokenizer, |
169 | const StaticContext::Ptr &context, |
170 | const QXmlQuery::QueryLanguage lang, |
171 | const SequenceType::Ptr &requiredType, |
172 | const QUrl &queryURI, |
173 | const QXmlName &initialTemplateName); |
174 | private: |
175 | Q_DISABLE_COPY(ExpressionFactory) |
176 | }; |
177 | } |
178 | |
179 | QT_END_NAMESPACE |
180 | |
181 | #endif |
182 | |