Update copyright year in license headers.
[profile/ivi/qtxmlpatterns.git] / src / xmlpatterns / expr / qexpressionfactory_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
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 ** 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.
17 **
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.
21 **
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.
29 **
30 ** Other Usage
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.
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 <private/qexpression_p.h>
58 #include <private/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