1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
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 <[email protected]>
|
---|
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
|
---|