author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 16 Apr 2010 15:50:13 +0300 | |
changeset 18 | 2f34d5167611 |
parent 0 | 1918ee327afb |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtXmlPatterns module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
// |
|
43 |
// W A R N I N G |
|
44 |
// ------------- |
|
45 |
// |
|
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. |
|
49 |
// |
|
50 |
// We mean it. |
|
51 |
||
52 |
#ifndef Patternist_ExpressionFactory_H |
|
53 |
#define Patternist_ExpressionFactory_H |
|
54 |
||
55 |
#include <QXmlQuery> |
|
56 |
||
57 |
#include "qexpression_p.h" |
|
58 |
#include "qtokenizer_p.h" |
|
59 |
||
60 |
#include <QSharedData> |
|
61 |
#include <QUrl> |
|
62 |
||
63 |
QT_BEGIN_HEADER |
|
64 |
||
65 |
QT_BEGIN_NAMESPACE |
|
66 |
||
67 |
class QIODevice; |
|
68 |
||
69 |
namespace QPatternist |
|
70 |
{ |
|
71 |
/** |
|
72 |
* @short The central entry point for compiling expressions. |
|
73 |
* |
|
74 |
* @ingroup Patternist_expressions |
|
75 |
* @author Frans Englich <frans.englich@nokia.com> |
|
76 |
*/ |
|
77 |
class Q_AUTOTEST_EXPORT ExpressionFactory : public QSharedData |
|
78 |
{ |
|
79 |
public: |
|
80 |
typedef QExplicitlySharedDataPointer<ExpressionFactory> Ptr; |
|
81 |
||
82 |
/** |
|
83 |
* @short This constructor cannot be synthesized since we |
|
84 |
* use the Q_DISABLE_COPY macro. |
|
85 |
*/ |
|
86 |
inline ExpressionFactory() |
|
87 |
{ |
|
88 |
} |
|
89 |
||
90 |
virtual ~ExpressionFactory() |
|
91 |
{ |
|
92 |
} |
|
93 |
||
94 |
enum CompilationStage |
|
95 |
{ |
|
96 |
QueryBodyInitial = 1, |
|
97 |
QueryBodyTypeCheck = 1 << 1, |
|
98 |
QueryBodyCompression = 1 << 2, |
|
99 |
UserFunctionTypeCheck = 1 << 3, |
|
100 |
UserFunctionCompression = 1 << 4, |
|
101 |
GlobalVariableTypeCheck = 1 << 5 |
|
102 |
}; |
|
103 |
||
104 |
/** |
|
105 |
* Creates a compiled representation of the XPath expression @p expr, with Static |
|
106 |
* Context information supplied via @p context. This is for example whether the expression |
|
107 |
* is an XPath 1.0 or XPath 2.0 expression, or what functions that are available. |
|
108 |
* |
|
109 |
* @p requiredType specifies what type results of the evaluating the expression |
|
110 |
* must match. Passing CommonValues::ZeroOrMoreItems allows anything as result, while |
|
111 |
* passing CommonSequenceTypes::EBV means anything but an Effective %Boolean Value extractable |
|
112 |
* result is a type error, for example. |
|
113 |
* |
|
114 |
* @note An empty @p expr is an invalid XPath expression. It will be reported as such, |
|
115 |
* but it is neverthless the caller's resonsibility to ensure that it's not that(since |
|
116 |
* it is likely invalid already in the medium it was stored). |
|
117 |
*/ |
|
118 |
virtual Expression::Ptr createExpression(const QString &expr, |
|
119 |
const StaticContext::Ptr &context, |
|
120 |
const QXmlQuery::QueryLanguage lang, |
|
121 |
const SequenceType::Ptr &requiredType, |
|
122 |
const QUrl &queryURI, |
|
123 |
const QXmlName &initialTemplateName); |
|
124 |
||
125 |
virtual Expression::Ptr createExpression(QIODevice *const device, |
|
126 |
const StaticContext::Ptr &context, |
|
127 |
const QXmlQuery::QueryLanguage lang, |
|
128 |
const SequenceType::Ptr &requiredType, |
|
129 |
const QUrl &queryURI, |
|
130 |
const QXmlName &initialTemplateName); |
|
131 |
||
132 |
/** |
|
133 |
* Finds the last paths of a set of paths(if any) and tells the Path |
|
134 |
* so, such that it can generate the code for checking XPTY0018. |
|
135 |
* |
|
136 |
* Must be called before typeCheck() is called on the operand, since |
|
137 |
* the typeCheck() uses the information for type checking. |
|
138 |
*/ |
|
139 |
static void registerLastPath(const Expression::Ptr &operand); |
|
140 |
||
141 |
protected: |
|
142 |
enum TemplateCompilationStage |
|
143 |
{ |
|
144 |
TemplateInitial = 1, |
|
145 |
TemplateTypeCheck = 1 << 1, |
|
146 |
TemplateCompress = 1 << 2 |
|
147 |
}; |
|
148 |
||
149 |
/** |
|
150 |
* This function is called by createExpression() each time |
|
151 |
* after a pass on the AST has been completed. Under a typical |
|
152 |
* compilation this function is thus called three times: after the initial |
|
153 |
* build, after the Expression::typeCheck() stage, and after |
|
154 |
* Expression::compress(). @p tree is the AST after each pass. |
|
155 |
* |
|
156 |
* This mechanism is currently used for debugging, since it provides a |
|
157 |
* way of introspecting what the compilation process do to the tree. The |
|
158 |
* current implementation do nothing. |
|
159 |
*/ |
|
160 |
virtual void processTreePass(const Expression::Ptr &tree, |
|
161 |
const CompilationStage stage); |
|
162 |
||
163 |
virtual void processTemplateRule(const Expression::Ptr &body, |
|
164 |
const TemplatePattern::Ptr &pattern, |
|
165 |
const QXmlName &mode, |
|
166 |
const TemplateCompilationStage stage); |
|
167 |
||
168 |
virtual void processNamedTemplate(const QXmlName &name, |
|
169 |
const Expression::Ptr &tree, |
|
170 |
const TemplateCompilationStage stage); |
|
171 |
||
172 |
Expression::Ptr createExpression(const Tokenizer::Ptr &tokenizer, |
|
173 |
const StaticContext::Ptr &context, |
|
174 |
const QXmlQuery::QueryLanguage lang, |
|
175 |
const SequenceType::Ptr &requiredType, |
|
176 |
const QUrl &queryURI, |
|
177 |
const QXmlName &initialTemplateName); |
|
178 |
private: |
|
179 |
Q_DISABLE_COPY(ExpressionFactory) |
|
180 |
}; |
|
181 |
} |
|
182 |
||
183 |
QT_END_NAMESPACE |
|
184 |
||
185 |
QT_END_HEADER |
|
186 |
||
187 |
#endif |