source: trunk/src/xmlpatterns/parser/qparsercontext_p.h@ 686

Last change on this file since 686 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 13.6 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtXmlPatterns module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** 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 have questions regarding the use of this file, please contact
37** Nokia 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_ParserContext_H
53#define Patternist_ParserContext_H
54
55#include <QFlags>
56#include <QSharedData>
57#include <QStack>
58#include <QStringList>
59#include <QtGlobal>
60#include <QXmlQuery>
61
62#include "qbuiltintypes_p.h"
63#include "qfunctionsignature_p.h"
64#include "qorderby_p.h"
65#include "qtemplatemode_p.h"
66#include "quserfunctioncallsite_p.h"
67#include "quserfunction_p.h"
68#include "qvariabledeclaration_p.h"
69
70QT_BEGIN_HEADER
71
72QT_BEGIN_NAMESPACE
73
74namespace QPatternist
75{
76 class Tokenizer;
77
78 /**
79 * @short Contains data used when parsing and tokenizing.
80 *
81 * When ExpressionFactory::create() is called, an instance of this class
82 * is passed to the scanner and parser. It holds all information that is
83 * needed to create the expression.
84 *
85 * @author Frans Englich <[email protected]>
86 */
87 class ParserContext : public QSharedData
88 {
89 public:
90 typedef QExplicitlySharedDataPointer<ParserContext> Ptr;
91
92 enum PrologDeclaration
93 {
94 BoundarySpaceDecl = 1,
95 DefaultCollationDecl = 2,
96 BaseURIDecl = 4,
97 ConstructionDecl = 8,
98 OrderingModeDecl = 16,
99 EmptyOrderDecl = 32,
100 CopyNamespacesDecl = 64,
101 DeclareDefaultElementNamespace = 128,
102 DeclareDefaultFunctionNamespace = 256
103 };
104
105 typedef QFlags<PrologDeclaration> PrologDeclarations;
106
107 /**
108 * Constructs a ParserContext instance.
109 *
110 * @param context the static context as defined in XPath. This contain
111 * namespace bindings, error handler, and other information necessary
112 * for creating an XPath expression.
113 * @param lang the particular XPath language sub-set that should be parsed
114 * @param tokenizer the Tokenizer to use.
115 * @see ExpressionFactory::LanguageAccent
116 */
117 ParserContext(const StaticContext::Ptr &context,
118 const QXmlQuery::QueryLanguage lang,
119 Tokenizer *const tokenizer);
120
121 /**
122 * @short Removes the recently pushed variables from
123 * scope. The amount of removed variables is @p amount.
124 *
125 * finalizePushedVariable() can be seen as popping the variable.
126 *
127 */
128 void finalizePushedVariable(const int amount = 1,
129 const bool shouldPop = true);
130
131 inline VariableSlotID allocatePositionalSlot()
132 {
133 ++m_positionSlot;
134 return m_positionSlot;
135 }
136
137 inline VariableSlotID allocateExpressionSlot()
138 {
139 const VariableSlotID retval = m_expressionSlot;
140 ++m_expressionSlot;
141 return retval;
142 }
143
144 inline VariableSlotID allocateGlobalVariableSlot()
145 {
146 ++m_globalVariableSlot;
147 return m_globalVariableSlot;
148 }
149
150 inline bool hasDeclaration(const PrologDeclaration decl) const
151 {
152 return m_prologDeclarations.testFlag(decl);
153 }
154
155 inline void registerDeclaration(const PrologDeclaration decl)
156 {
157 m_prologDeclarations |= decl;
158 }
159
160 /**
161 * The namespaces declared with <tt>declare namespace</tt>.
162 */
163 QStringList declaredPrefixes;