1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
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 "qexpression_p.h"
58 #include "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)