Qt 4.8
qparsercontext_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7 **
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.
16 **
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.
24 **
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.
28 **
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.
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_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"
67 #include "quserfunction_p.h"
68 #include "qvariabledeclaration_p.h"
69 
71 
73 
74 namespace QPatternist
75 {
76  class Tokenizer;
77 
87  class ParserContext : public QSharedData
88  {
89  public:
91 
93  {
103  };
104 
106 
117  ParserContext(const StaticContext::Ptr &context,
118  const QXmlQuery::QueryLanguage lang,
119  Tokenizer *const tokenizer);
120 
128  void finalizePushedVariable(const int amount = 1,
129  const bool shouldPop = true);
130 
132  {
133  ++m_positionSlot;
134  return m_positionSlot;
135  }
136 
138  {
139  const VariableSlotID retval = m_expressionSlot;
141  return retval;
142  }
143 
145  {
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 
164 
170 
171  inline bool isXSLT() const
172  {
174  }
175 
184 
191 
197 
203 
208 
213 
218 
220  {
221  return m_positionSlot;
222  }
223 
225  {
226  return m_expressionSlot;
227  }
228 
229  inline void restoreNodeTestSource()
230  {
232  }
233 
235  {
236  return ++m_evaluationCacheSlot;
237  }
238 
239  inline VariableSlotID allocateCacheSlots(const int count)
240  {
241  const VariableSlotID retval = m_evaluationCacheSlot + 1;
242  m_evaluationCacheSlot += count + 1;
243  return retval;
244  }
245 
247 
249 
254 
261 
272 
274 
276 
278 
284 
287 
293 
298 
308 
324 
330  {
331  /* #current is not a mode, so it cannot contain templates. #current
332  * specifies how to look up templates wrt. mode. This check helps
333  * code that calls us, asking for the mode it needs to lookup in.
334  */
336  return TemplateMode::Ptr();
337 
338  TemplateMode::Ptr &mode = templateRules[modeName];
339 
340  if(!mode)
341  mode = TemplateMode::Ptr(new TemplateMode(modeName));
342 
343  Q_ASSERT(templateRules[modeName]);
344  return mode;
345  }
346 
348  {
350  return m_currentTemplateID;
351  }
352 
357 
362 
364  {
365  finalizePushedVariable(templateParameters.count());
366  templateParameters.clear();
367  }
368 
370  {
371  templateWithParams.clear();
372  }
373 
374  inline bool isParsingWithParam() const
375  {
376  return m_isParsingWithParam.top();
377  }
378 
380  {
382  }
383 
385  {
387  }
388 
394 
396 
397  bool isFirstTemplate() const
398  {
400  }
401 
406 
407  private:
408  enum
409  {
411  };
412 
416  PrologDeclarations m_prologDeclarations;
419 
426  };
427 }
428 
430 
432 
433 #endif
qint32 VariableSlotID
The QMultiHash class is a convenience QHash subclass that provides multi-valued hashes.
Definition: qcontainerfwd.h:58
VariableSlotID allocateGlobalVariableSlot()
VariableSlotID allocateCacheSlot()
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QStack< NamespaceResolver::Ptr > resolvers
void clear()
Removes all items from the hash.
Definition: qhash.h:574
TemplatePattern::ID m_currentTemplateID
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
QXmlName::NamespaceCode moduleNamespace
VariableSlotID currentPositionSlot() const
QHash< QXmlName, Template::Ptr > namedTemplates
QStack< QXmlName > tagStack
PrologDeclarations m_prologDeclarations
QueryLanguage
Specifies whether you want QXmlQuery to interpret the input to setQuery() as an XQuery or as an XSLT ...
Definition: qxmlquery.h:82
qint16 NamespaceCode
Definition: qxmlname.h:82
VariableSlotID currentExpressionSlot() const
QMultiHash< QXmlName, Expression::Ptr > unresolvedVariableReferences
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
bool testFlag(Enum f) const
Returns true if the flag is set, otherwise false.
Definition: qglobal.h:2345
QFlags< PrologDeclaration > PrologDeclarations
VariableDeclaration::List templateParameters
ImportPrecedence currentImportPrecedence
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
TemplateMode::Ptr modeFor(const QXmlName &modeName)
Returns the TemplateMode for modeName or null if the mode being asked for is #current.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void registerDeclaration(const PrologDeclaration decl)
bool hasDeclaration(const PrologDeclaration decl) const
UserFunctionCallsite::List userFunctionCallsites
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
VariableDeclaration::Stack variables
TemplatePattern::ID allocateTemplateID()
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
The namespace for the internal API of QtXmlPatterns.
WithParam::Hash templateWithParams
QStack< Expression::Ptr > typeswitchSource
Houses the data specific to the templates for a certain mode.
void clear()
Removes all items from the list.
Definition: qlist.h:764
QStack< bool > m_isParsingWithParam
Contains data used when parsing and tokenizing.
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
const QXmlQuery::QueryLanguage languageAccent
QStack< OrderBy::Stability > orderStability
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
QExplicitlySharedDataPointer< ParserContext > Ptr
The QSharedData class is a base class for shared data objects.
Definition: qshareddata.h:56
VariableSlotID allocateCacheSlots(const int count)
UserFunction::List userFunctions
QExplicitlySharedDataPointer< TemplateMode > Ptr
QHash< QXmlName, TemplateMode::Ptr > templateRules
const StaticContext::Ptr staticContext
QVector< Expression::Ptr > templateCalls
VariableDeclaration::List declaredVariables
VariableSlotID allocatePositionalSlot()
VariableSlotID m_globalVariableSlot
Base class for all tokenizers.
Definition: qtokenizer_p.h:155
#define QT_END_HEADER
Definition: qglobal.h:137
VariableSlotID allocateExpressionSlot()
static const ItemType::Ptr element
void finalizePushedVariable(const int amount=1, const bool shouldPop=true)
Removes the recently pushed variables from scope. The amount of removed variables is amount...
int ImportPrecedence
VariableSlotID m_evaluationCacheSlot
T & top()
Returns a reference to the stack&#39;s top item.
Definition: qstack.h:72
ParserContext(const StaticContext::Ptr &context, const QXmlQuery::QueryLanguage lang, Tokenizer *const tokenizer)