Qt 4.8
Public Types | Public Functions | Public Variables | Private Types | Properties | List of all members
QPatternist::ParserContext Class Reference

Contains data used when parsing and tokenizing. More...

#include <qparsercontext_p.h>

Inheritance diagram for QPatternist::ParserContext:
QSharedData

Public Types

enum  PrologDeclaration {
  BoundarySpaceDecl = 1, DefaultCollationDecl = 2, BaseURIDecl = 4, ConstructionDecl = 8,
  OrderingModeDecl = 16, EmptyOrderDecl = 32, CopyNamespacesDecl = 64, DeclareDefaultElementNamespace = 128,
  DeclareDefaultFunctionNamespace = 256
}
 
typedef QFlags< PrologDeclarationPrologDeclarations
 
typedef QExplicitlySharedDataPointer< ParserContextPtr
 

Public Functions

VariableSlotID allocateCacheSlot ()
 
VariableSlotID allocateCacheSlots (const int count)
 
VariableSlotID allocateExpressionSlot ()
 
VariableSlotID allocateGlobalVariableSlot ()
 
VariableSlotID allocatePositionalSlot ()
 
TemplatePattern::ID allocateTemplateID ()
 
VariableSlotID currentExpressionSlot () const
 
VariableSlotID currentPositionSlot () const
 
void endParsingWithParam ()
 
void finalizePushedVariable (const int amount=1, const bool shouldPop=true)
 Removes the recently pushed variables from scope. The amount of removed variables is amount. More...
 
bool hasDeclaration (const PrologDeclaration decl) const
 
bool isFirstTemplate () const
 
bool isParsingWithParam () const
 
bool isXSLT () const
 
TemplateMode::Ptr modeFor (const QXmlName &modeName)
 Returns the TemplateMode for modeName or null if the mode being asked for is #current. More...
 
 ParserContext (const StaticContext::Ptr &context, const QXmlQuery::QueryLanguage lang, Tokenizer *const tokenizer)
 
void registerDeclaration (const PrologDeclaration decl)
 
void restoreNodeTestSource ()
 
void startParsingWithParam ()
 
void templateParametersHandled ()
 
void templateWithParametersHandled ()
 
- Public Functions inherited from QSharedData
 QSharedData ()
 Constructs a QSharedData object with a reference count of 0. More...
 
 QSharedData (const QSharedData &)
 Constructs a QSharedData object with reference count 0. More...
 

Public Variables

ImportPrecedence currentImportPrecedence
 
QStringList declaredPrefixes
 
VariableDeclaration::List declaredVariables
 
int elementConstructorDepth
 
bool hasSecondPrologPart
 
bool inheritNamespacesMode
 
QXmlName initialTemplateName
 
QStack< bool > isBackwardsCompat
 
bool isParsingPattern
 
bool isPreviousEnclosedExpr
 
const QXmlQuery::QueryLanguage languageAccent
 
QXmlName::NamespaceCode moduleNamespace
 
QHash< QXmlName, Template::PtrnamedTemplates
 
ItemType::Ptr nodeTestSource
 
QStack< OrderBy::StabilityorderStability
 
bool preserveNamespacesMode
 
Expression::Ptr queryBody
 
QStack< NamespaceResolver::Ptrresolvers
 
QStack< bool > scanOnlyStack
 
const StaticContext::Ptr staticContext
 
QStack< QXmlNametagStack
 
QVector< Expression::PtrtemplateCalls
 
VariableDeclaration::List templateParameters
 
QHash< QXmlName, TemplateMode::PtrtemplateRules
 
WithParam::Hash templateWithParams
 
Tokenizer *const tokenizer
 
QStack< Expression::PtrtypeswitchSource
 
QMultiHash< QXmlName, Expression::PtrunresolvedVariableReferences
 
UserFunctionCallsite::List userFunctionCallsites
 
UserFunction::List userFunctions
 
VariableDeclaration::Stack variables
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 

Private Types

enum  { InitialTemplateID = -1 }
 

Properties

TemplatePattern::ID m_currentTemplateID
 
VariableSlotID m_evaluationCacheSlot
 
VariableSlotID m_expressionSlot
 
VariableSlotID m_globalVariableSlot
 
QStack< bool > m_isParsingWithParam
 
VariableSlotID m_positionSlot
 
PrologDeclarations m_prologDeclarations
 

Detailed Description

Contains data used when parsing and tokenizing.

When ExpressionFactory::create() is called, an instance of this class is passed to the scanner and parser. It holds all information that is needed to create the expression.

Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 87 of file qparsercontext_p.h.

Typedefs

◆ PrologDeclarations

Definition at line 105 of file qparsercontext_p.h.

◆ Ptr

Definition at line 90 of file qparsercontext_p.h.

Enumerations

◆ anonymous enum

anonymous enum
private
Enumerator
InitialTemplateID 

Definition at line 408 of file qparsercontext_p.h.

◆ PrologDeclaration

Constructors and Destructors

◆ ParserContext()

ParserContext::ParserContext ( const StaticContext::Ptr context,
const QXmlQuery::QueryLanguage  lang,
Tokenizer *const  tokenizer 
)

Constructs a ParserContext instance.

Parameters
contextthe static context as defined in XPath. This contain namespace bindings, error handler, and other information necessary for creating an XPath expression.
langthe particular XPath language sub-set that should be parsed
tokenizerthe Tokenizer to use.
See also
ExpressionFactory::LanguageAccent

Definition at line 54 of file qparsercontext.cpp.

56  : staticContext(context)
57  , tokenizer(tokener)
58  , languageAccent(lang)
61  , isPreviousEnclosedExpr(false)
63  , hasSecondPrologPart(false)
65  , inheritNamespacesMode(true)
66  , isParsingPattern(false)
69  , m_expressionSlot(0)
70  , m_positionSlot(-1)
73 {
74  resolvers.push(context->namespaceBindings());
75  Q_ASSERT(tokenizer);
76  Q_ASSERT(context);
78  isBackwardsCompat.push(false);
79 }
QStack< NamespaceResolver::Ptr > resolvers
TemplatePattern::ID m_currentTemplateID
QXmlName::NamespaceCode moduleNamespace
ImportPrecedence currentImportPrecedence
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual NamespaceResolver::Ptr namespaceBindings() const =0
QStack< bool > m_isParsingWithParam
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
const QXmlQuery::QueryLanguage languageAccent
const StaticContext::Ptr staticContext
VariableSlotID m_globalVariableSlot
static const ItemType::Ptr element
VariableSlotID m_evaluationCacheSlot

Functions

◆ allocateCacheSlot()

VariableSlotID QPatternist::ParserContext::allocateCacheSlot ( )
inline

Definition at line 234 of file qparsercontext_p.h.

Referenced by QPatternist::pushVariable().

235  {
236  return ++m_evaluationCacheSlot;
237  }
VariableSlotID m_evaluationCacheSlot

◆ allocateCacheSlots()

VariableSlotID QPatternist::ParserContext::allocateCacheSlots ( const int  count)
inline

Definition at line 239 of file qparsercontext_p.h.

240  {
241  const VariableSlotID retval = m_evaluationCacheSlot + 1;
242  m_evaluationCacheSlot += count + 1;
243  return retval;
244  }
qint32 VariableSlotID
VariableSlotID m_evaluationCacheSlot

◆ allocateExpressionSlot()

VariableSlotID QPatternist::ParserContext::allocateExpressionSlot ( )
inline

Definition at line 137 of file qparsercontext_p.h.

Referenced by QPatternist::pushVariable().

138  {
139  const VariableSlotID retval = m_expressionSlot;
141  return retval;
142  }
qint32 VariableSlotID

◆ allocateGlobalVariableSlot()

VariableSlotID QPatternist::ParserContext::allocateGlobalVariableSlot ( )
inline

Definition at line 144 of file qparsercontext_p.h.

Referenced by QPatternist::pushVariable().

145  {
147  return m_globalVariableSlot;
148  }
VariableSlotID m_globalVariableSlot

◆ allocatePositionalSlot()

VariableSlotID QPatternist::ParserContext::allocatePositionalSlot ( )
inline

Definition at line 131 of file qparsercontext_p.h.

Referenced by QPatternist::pushVariable().

132  {
133  ++m_positionSlot;
134  return m_positionSlot;
135  }

◆ allocateTemplateID()

TemplatePattern::ID QPatternist::ParserContext::allocateTemplateID ( )
inline

Definition at line 347 of file qparsercontext_p.h.

348  {
350  return m_currentTemplateID;
351  }
TemplatePattern::ID m_currentTemplateID

◆ currentExpressionSlot()

VariableSlotID QPatternist::ParserContext::currentExpressionSlot ( ) const
inline

Definition at line 224 of file qparsercontext_p.h.

225  {
226  return m_expressionSlot;
227  }

◆ currentPositionSlot()

VariableSlotID QPatternist::ParserContext::currentPositionSlot ( ) const
inline

Definition at line 219 of file qparsercontext_p.h.

220  {
221  return m_positionSlot;
222  }

◆ endParsingWithParam()

void QPatternist::ParserContext::endParsingWithParam ( )
inline

Definition at line 384 of file qparsercontext_p.h.

385  {
387  }
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
QStack< bool > m_isParsingWithParam

◆ finalizePushedVariable()

void ParserContext::finalizePushedVariable ( const int  amount = 1,
const bool  shouldPop = true 
)

Removes the recently pushed variables from scope. The amount of removed variables is amount.

finalizePushedVariable() can be seen as popping the variable.

Definition at line 81 of file qparsercontext.cpp.

Referenced by templateParametersHandled().

83 {
84  for(int i = 0; i < amount; ++i)
85  {
86  const VariableDeclaration::Ptr var(shouldPop ? variables.pop() : variables.top());
87  Q_ASSERT(var);
88 
89  if(var->isUsed())
90  continue;
91  else
92  {
93  staticContext->warning(QtXmlPatterns::tr("The variable %1 is unused")
94  .arg(formatKeyword(var, staticContext->namePool())));
95  }
96  }
97 }
QString formatKeyword(const QString &keyword)
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
virtual NamePool::Ptr namePool() const =0
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
VariableDeclaration::Stack variables
const StaticContext::Ptr staticContext
void warning(const QString &message, const QSourceLocation &sourceLocation=QSourceLocation())
T & top()
Returns a reference to the stack&#39;s top item.
Definition: qstack.h:72

◆ hasDeclaration()

bool QPatternist::ParserContext::hasDeclaration ( const PrologDeclaration  decl) const
inline

Definition at line 150 of file qparsercontext_p.h.

151  {
152  return m_prologDeclarations.testFlag(decl);
153  }
PrologDeclarations m_prologDeclarations
bool testFlag(Enum f) const
Returns true if the flag is set, otherwise false.
Definition: qglobal.h:2345

◆ isFirstTemplate()

bool QPatternist::ParserContext::isFirstTemplate ( ) const
inline

Definition at line 397 of file qparsercontext_p.h.

◆ isParsingWithParam()

bool QPatternist::ParserContext::isParsingWithParam ( ) const
inline

Definition at line 374 of file qparsercontext_p.h.

375  {
376  return m_isParsingWithParam.top();
377  }
QStack< bool > m_isParsingWithParam
T & top()
Returns a reference to the stack&#39;s top item.
Definition: qstack.h:72

◆ isXSLT()

bool QPatternist::ParserContext::isXSLT ( ) const
inline

◆ modeFor()

TemplateMode::Ptr QPatternist::ParserContext::modeFor ( const QXmlName modeName)
inline

Returns the TemplateMode for modeName or null if the mode being asked for is #current.

Definition at line 329 of file qparsercontext_p.h.

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  }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
QExplicitlySharedDataPointer< TemplateMode > Ptr
QHash< QXmlName, TemplateMode::Ptr > templateRules

◆ registerDeclaration()

void QPatternist::ParserContext::registerDeclaration ( const PrologDeclaration  decl)
inline

Definition at line 155 of file qparsercontext_p.h.

156  {
157  m_prologDeclarations |= decl;
158  }
PrologDeclarations m_prologDeclarations

◆ restoreNodeTestSource()

void QPatternist::ParserContext::restoreNodeTestSource ( )
inline

Definition at line 229 of file qparsercontext_p.h.

230  {
232  }
static const ItemType::Ptr element

◆ startParsingWithParam()

void QPatternist::ParserContext::startParsingWithParam ( )
inline

Definition at line 379 of file qparsercontext_p.h.

380  {
382  }
QStack< bool > m_isParsingWithParam
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60

◆ templateParametersHandled()

void QPatternist::ParserContext::templateParametersHandled ( )
inline

Definition at line 363 of file qparsercontext_p.h.

364  {
367  }
VariableDeclaration::List templateParameters
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
void clear()
Removes all items from the list.
Definition: qlist.h:764
void finalizePushedVariable(const int amount=1, const bool shouldPop=true)
Removes the recently pushed variables from scope. The amount of removed variables is amount...

◆ templateWithParametersHandled()

void QPatternist::ParserContext::templateWithParametersHandled ( )
inline

Definition at line 369 of file qparsercontext_p.h.

370  {
372  }
void clear()
Removes all items from the hash.
Definition: qhash.h:574
WithParam::Hash templateWithParams

Properties

◆ currentImportPrecedence

ImportPrecedence QPatternist::ParserContext::currentImportPrecedence

Definition at line 395 of file qparsercontext_p.h.

◆ declaredPrefixes

QStringList QPatternist::ParserContext::declaredPrefixes

The namespaces declared with declare namespace.

Definition at line 163 of file qparsercontext_p.h.

◆ declaredVariables

VariableDeclaration::List QPatternist::ParserContext::declaredVariables

All variables declared with declare variable.

Definition at line 217 of file qparsercontext_p.h.

◆ elementConstructorDepth

int QPatternist::ParserContext::elementConstructorDepth

Definition at line 273 of file qparsercontext_p.h.

◆ hasSecondPrologPart

bool QPatternist::ParserContext::hasSecondPrologPart

Whether any prolog declaration that must occur after the first group has been encountered.

Definition at line 283 of file qparsercontext_p.h.

◆ inheritNamespacesMode

bool QPatternist::ParserContext::inheritNamespacesMode

Definition at line 286 of file qparsercontext_p.h.

Referenced by QPatternist::createCopyOf().

◆ initialTemplateName

QXmlName QPatternist::ParserContext::initialTemplateName

Only used in the case of XSL-T. Is the name of the initial template to call. If null, no name was provided, and regular template matching should be done.

Definition at line 190 of file qparsercontext_p.h.

◆ isBackwardsCompat

QStack<bool> QPatternist::ParserContext::isBackwardsCompat

Whether we're processing XSL-T 1.0 code.

Definition at line 405 of file qparsercontext_p.h.

Referenced by QPatternist::XSLTTokenizer::handleXSLTVersion(), and ParserContext().

◆ isParsingPattern

bool QPatternist::ParserContext::isParsingPattern

This is used to deal with XSL-T's exception to the node() type, which doesn't match document nodes.

Definition at line 393 of file qparsercontext_p.h.

◆ isPreviousEnclosedExpr

bool QPatternist::ParserContext::isPreviousEnclosedExpr

This is used for handling the following obscene case:

  • <e>{1}{1}<\/e> produce <e>11</e>
  • <e>{1, 1}<\/e> produce <e>1 1</e>

This boolean tracks whether the previous reduction inside element content was done with an enclosed expression.

Definition at line 271 of file qparsercontext_p.h.

◆ languageAccent

const QXmlQuery::QueryLanguage QPatternist::ParserContext::languageAccent

Definition at line 183 of file qparsercontext_p.h.

Referenced by QPatternist::allowedIn(), and isXSLT().

◆ m_currentTemplateID

TemplatePattern::ID QPatternist::ParserContext::m_currentTemplateID
private

Definition at line 418 of file qparsercontext_p.h.

Referenced by allocateTemplateID(), and isFirstTemplate().

◆ m_evaluationCacheSlot

VariableSlotID QPatternist::ParserContext::m_evaluationCacheSlot
private

Definition at line 413 of file qparsercontext_p.h.

Referenced by allocateCacheSlot(), and allocateCacheSlots().

◆ m_expressionSlot

VariableSlotID QPatternist::ParserContext::m_expressionSlot
private

Definition at line 414 of file qparsercontext_p.h.

Referenced by allocateExpressionSlot(), and currentExpressionSlot().

◆ m_globalVariableSlot

VariableSlotID QPatternist::ParserContext::m_globalVariableSlot
private

Definition at line 417 of file qparsercontext_p.h.

Referenced by allocateGlobalVariableSlot().

◆ m_isParsingWithParam

QStack<bool> QPatternist::ParserContext::m_isParsingWithParam
private

The default is false. If we're not parsing xsl:with-param, hence parsing xsl:param, the value has changed.

Definition at line 424 of file qparsercontext_p.h.

Referenced by endParsingWithParam(), isParsingWithParam(), ParserContext(), and startParsingWithParam().

◆ m_positionSlot

VariableSlotID QPatternist::ParserContext::m_positionSlot
private

Definition at line 415 of file qparsercontext_p.h.

Referenced by allocatePositionalSlot(), and currentPositionSlot().

◆ m_prologDeclarations

PrologDeclarations QPatternist::ParserContext::m_prologDeclarations
private

Definition at line 416 of file qparsercontext_p.h.

Referenced by hasDeclaration(), and registerDeclaration().

◆ moduleNamespace

QXmlName::NamespaceCode QPatternist::ParserContext::moduleNamespace

The library module namespace set with declare module.

Definition at line 253 of file qparsercontext_p.h.

◆ namedTemplates

QHash<QXmlName, Template::Ptr> QPatternist::ParserContext::namedTemplates

Contains all named templates. Since named templates can also have rules, each body may also be in templateRules.

Definition at line 292 of file qparsercontext_p.h.

Referenced by QPatternist::registerNamedTemplate().

◆ nodeTestSource

ItemType::Ptr QPatternist::ParserContext::nodeTestSource

Definition at line 246 of file qparsercontext_p.h.

Referenced by restoreNodeTestSource().

◆ orderStability

QStack<OrderBy::Stability> QPatternist::ParserContext::orderStability

Definition at line 277 of file qparsercontext_p.h.

◆ preserveNamespacesMode

bool QPatternist::ParserContext::preserveNamespacesMode

Definition at line 285 of file qparsercontext_p.h.

Referenced by QPatternist::createCopyOf().

◆ queryBody

Expression::Ptr QPatternist::ParserContext::queryBody

The actual expression, the Query. This member may be null, such as in the case of an XQuery library module.

Definition at line 202 of file qparsercontext_p.h.

◆ resolvers

QStack<NamespaceResolver::Ptr> QPatternist::ParserContext::resolvers

When a direct element constructor is processed, resolvers are created in order to carry the namespace declarations. In such case, the old resolver is pushed here.

Definition at line 260 of file qparsercontext_p.h.

Referenced by ParserContext().

◆ scanOnlyStack

QStack<bool> QPatternist::ParserContext::scanOnlyStack

Definition at line 275 of file qparsercontext_p.h.

◆ staticContext

const StaticContext::Ptr QPatternist::ParserContext::staticContext

◆ tagStack

QStack<QXmlName> QPatternist::ParserContext::tagStack

Used when parsing direct element constructors. It is used for ensuring tags are well-balanced.

Definition at line 196 of file qparsercontext_p.h.

◆ templateCalls

QVector<Expression::Ptr> QPatternist::ParserContext::templateCalls

All the xsl:call-template instructions that we have encountered.

Definition at line 297 of file qparsercontext_p.h.

◆ templateParameters

VariableDeclaration::List QPatternist::ParserContext::templateParameters

The xsl:param appearing inside template.

Definition at line 356 of file qparsercontext_p.h.

◆ templateRules

QHash<QXmlName, TemplateMode::Ptr> QPatternist::ParserContext::templateRules

Contains the encountered template rules, as opposed to named templates.

The key is the name of the template mode. If it's a default constructed value, it's the default mode.

Since templates rules may also be named, each body may also be in namedTemplates.

To be specific, the values are not the templates, the values are modes, and the TemplateMode contains the patterns and bodies.

Definition at line 323 of file qparsercontext_p.h.

◆ templateWithParams

WithParam::Hash QPatternist::ParserContext::templateWithParams

The xsl:with-param appearing in template calling instruction.

Definition at line 361 of file qparsercontext_p.h.

◆ tokenizer

Tokenizer* const QPatternist::ParserContext::tokenizer

We don't store a Tokenizer::Ptr here, because then we would get a circular referencing between ParserContext and XSLTTokenizer, and hence they would never destruct.

Definition at line 182 of file qparsercontext_p.h.

Referenced by QPatternist::fromYYLTYPE(), ParserContext(), and QPatternist::XPathlex().

◆ typeswitchSource

QStack<Expression::Ptr> QPatternist::ParserContext::typeswitchSource

Definition at line 248 of file qparsercontext_p.h.

◆ unresolvedVariableReferences

QMultiHash<QXmlName, Expression::Ptr> QPatternist::ParserContext::unresolvedVariableReferences

If we're in XSL-T, and a variable reference is encountered which isn't in-scope, it's added to this hash since a global variable declaration may appear later on.

We use a multi hash, since we can encounter several references to the same variable before it's declared.

Definition at line 307 of file qparsercontext_p.h.

Referenced by QPatternist::resolveVariable().

◆ userFunctionCallsites

UserFunctionCallsite::List QPatternist::ParserContext::userFunctionCallsites

Contains all calls to user defined functions.

Definition at line 212 of file qparsercontext_p.h.

◆ userFunctions

UserFunction::List QPatternist::ParserContext::userFunctions

The user functions declared in the prolog.

Definition at line 207 of file qparsercontext_p.h.

◆ variables

VariableDeclaration::Stack QPatternist::ParserContext::variables

This is a temporary stack, used for keeping variables in scope, such as for function arguments & let clauses.

Definition at line 169 of file qparsercontext_p.h.

Referenced by finalizePushedVariable(), QPatternist::pushVariable(), and QPatternist::variableByName().


The documentation for this class was generated from the following files: