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_ExpressionFactory_H
53 #define Patternist_ExpressionFactory_H
57 #include <private/qexpression_p.h>
58 #include <private/qtokenizer_p.h>
60 #include <QSharedData>
72 * @short The central entry point for compiling expressions.
74 * @ingroup Patternist_expressions
75 * @author Frans Englich <frans.englich@nokia.com>
77 class Q_AUTOTEST_EXPORT ExpressionFactory : public QSharedData
80 typedef QExplicitlySharedDataPointer<ExpressionFactory> Ptr;
83 * @short This constructor cannot be synthesized since we
84 * use the Q_DISABLE_COPY macro.
86 inline ExpressionFactory()
90 virtual ~ExpressionFactory()
97 QueryBodyTypeCheck = 1 << 1,
98 QueryBodyCompression = 1 << 2,
99 UserFunctionTypeCheck = 1 << 3,
100 UserFunctionCompression = 1 << 4,
101 GlobalVariableTypeCheck = 1 << 5
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.
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.
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).
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);
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);
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.
136 * Must be called before typeCheck() is called on the operand, since
137 * the typeCheck() uses the information for type checking.
139 static void registerLastPath(const Expression::Ptr &operand);
142 enum TemplateCompilationStage
145 TemplateTypeCheck = 1 << 1,
146 TemplateCompress = 1 << 2
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.
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.
160 virtual void processTreePass(const Expression::Ptr &tree,
161 const CompilationStage stage);
163 virtual void processTemplateRule(const Expression::Ptr &body,
164 const TemplatePattern::Ptr &pattern,
165 const QXmlName &mode,
166 const TemplateCompilationStage stage);
168 virtual void processNamedTemplate(const QXmlName &name,
169 const Expression::Ptr &tree,
170 const TemplateCompilationStage stage);
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);
179 Q_DISABLE_COPY(ExpressionFactory)