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

Contains data related to a template. More...

#include <qtemplate_p.h>

Inheritance diagram for QPatternist::Template:
QSharedData QPatternist::SourceLocationReflection

Public Types

typedef QExplicitlySharedDataPointer< TemplatePtr
 
typedef QVector< Template::PtrVector
 

Public Functions

virtual const SourceLocationReflectionactualReflection () const
 
void compileParameters (const StaticContext::Ptr &context)
 
DynamicContext::Ptr createContext (const TemplateInvoker *const invoker, const DynamicContext::Ptr &context, const bool isCallTemplate) const
 
Expression::Properties dependencies () const
 
Expression::Properties properties () const
 
 Template (const ImportPrecedence ip, const SequenceType::Ptr &reqType)
 
- 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 Functions inherited from QPatternist::SourceLocationReflection
virtual QString description () const
 
virtual QSourceLocation sourceLocation () const
 
 SourceLocationReflection ()
 
virtual ~SourceLocationReflection ()
 

Static Public Functions

static void raiseXTSE0680 (const ReportContext::Ptr &context, const QXmlName &name, const SourceLocationReflection *const reflection)
 

Public Variables

Expression::Ptr body
 
const ImportPrecedence importPrecedence
 
VariableDeclaration::List templateParameters
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 

Private Functions

DynamicContext::TemplateParameterHash parametersAsHash () const
 

Properties

const SequenceType::Ptr m_reqType
 

Detailed Description

Contains data related to a template.

A Template is associated with a mode, by being housed inside a TemplateMode instance.

Template has role very similar to UserFunction.

See also
TemplateMode
TemplatePattern
UserFunction
Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com
Since
4.5

Definition at line 84 of file qtemplate_p.h.

Typedefs

◆ Ptr

Definition at line 89 of file qtemplate_p.h.

◆ Vector

Definition at line 90 of file qtemplate_p.h.

Constructors and Destructors

◆ Template()

QPatternist::Template::Template ( const ImportPrecedence  ip,
const SequenceType::Ptr reqType 
)
inline

Definition at line 92 of file qtemplate_p.h.

93  : importPrecedence(ip)
94  , m_reqType(reqType)
95  {
96  }
const ImportPrecedence importPrecedence
Definition: qtemplate_p.h:105
const SequenceType::Ptr m_reqType
Definition: qtemplate_p.h:139

Functions

◆ actualReflection()

const SourceLocationReflection * Template::actualReflection ( ) const
virtual

Returns this.

Implements QPatternist::SourceLocationReflection.

Definition at line 51 of file qtemplate.cpp.

52 {
53  return this;
54 }

◆ compileParameters()

void Template::compileParameters ( const StaticContext::Ptr context)

Since we have our template parameters in templateParameters, we need this separate step to do the regular phases: Expression::typeCheck(), and Expression::compress().

Definition at line 172 of file qtemplate.cpp.

173 {
174  Q_ASSERT(context);
175 
176  const int len = templateParameters.count();
177 
178  for(int i = 0; i < len; ++i)
179  {
181 
182  /* If our value is required, we don't have a default value. */
183  if(at->expression())
184  {
185  // TODO why do we pass in its own type here?
186  at->setExpression(at->expression()->typeCheck(context, at->expression()->staticType()));
187 
188  at->setExpression(at->expression()->compress(context));
189  }
190  }
191 }
#define at(className, varName)
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
VariableDeclaration::List templateParameters
Definition: qtemplate_p.h:107

◆ createContext()

DynamicContext::Ptr Template::createContext ( const TemplateInvoker *const  invoker,
const DynamicContext::Ptr context,
const bool  isCallTemplate 
) const

If isCallTemplate, the caller is xsl:call-template, as opposed to for instance xsl:apply-templates. This affects error reporting.

Parameters or not, we must in any case create a new stack frame for the template invocation since otherwise we will trash our existing variables. Hence it's as with calling user functions.

This is especially reproducible with recursive functions.

Definition at line 81 of file qtemplate.cpp.

Referenced by QPatternist::CallTemplate::evaluateEBV(), QPatternist::CallTemplate::evaluateSequence(), QPatternist::ApplyTemplate::evaluateSequence(), and QPatternist::CallTemplate::evaluateToSequenceReceiver().

84 {
85  Q_ASSERT(invoker);
86  Q_ASSERT(context);
87 
88  /* We have:
89  * - xsl:params in the target template (if any) which may provide
90  * default values.
91  * - xsl:with-params in the caller (if any) which provides values.
92  *
93  * We need to, for each parameter:
94  * - If the called template provides no default value and the caller
95  * has no value, it's an error
96  * - If the called template has a default value and the caller provides
97  * none, it should be used
98  * - In any case the caller provides a value, it needs to be used.
99  *
100  * Problems to look out for:
101  *
102  * - Each xsl:param is in scope for the subsequent xsl:params. Hence,
103  * the evaluation of one xsl:param can depend on another xsl:param,
104  * and so on
105  * - The focus for xsl:params is different from the focus for
106  * the xsl:with-params
107  * - The xsl:with-params are not in scope for the xsl:params.
108  */
109 
110  WithParam::Hash withParams(invoker->withParams());
111 
119  DynamicContext::Ptr newStack(context->createStack());
120 
121  /* We have no parameters, and we have no further error checking to
122  * do in the case of not being xsl:apply-templates, so we need to do nothing. */
123  if(templateParameters.isEmpty() && (!isCallTemplate || withParams.isEmpty()))
124  return newStack;
125 
127  DynamicContext::TemplateParameterHash sewnTogether(hashedParams);
128 
129  const DynamicContext::TemplateParameterHash::iterator end(sewnTogether.end());
130 
131  for(DynamicContext::TemplateParameterHash::iterator it(sewnTogether.begin());
132  it != end;
133  ++it)
134  {
135  Expression::Ptr &param = it.value();
136 
137  WithParam::Ptr &withParam = withParams[it.key()];
138 
139  if(withParam)
140  param = Expression::Ptr(new DynamicContextStore(withParam->sourceExpression(), context));
141  else if(!param)
142  {
143  /* Ops, no xsl:with-param and no default value to cover up for it.
144  */
145  context->error(QtXmlPatterns::tr("The parameter %1 is required, but no corresponding %2 is supplied.")
146  .arg(formatKeyword(context->namePool(), it.key()),
147  formatKeyword(QLatin1String("xsl:with-param"))),
149  this);
150  }
151  }
152 
153  if(isCallTemplate)
154  {
155  /* Find xsl:with-param that has no corresponding xsl:param. */
156  /* Optimization: candidate for threading? */
157 
158  const WithParam::Hash::const_iterator end(withParams.constEnd());
159 
160  for(WithParam::Hash::const_iterator it(withParams.constBegin()); it != end; ++it)
161  {
162  if(!hashedParams.contains(it.key()))
163  raiseXTSE0680(context, it.key(), this);
164  }
165 
166  }
167 
168  newStack->templateParameterStore() = sewnTogether;
169  return newStack;
170 }
virtual NamePool::Ptr namePool() const =0
QString formatKeyword(const QString &keyword)
#define it(className, varName)
DynamicContext::TemplateParameterHash parametersAsHash() const
Definition: qtemplate.cpp:56
static void raiseXTSE0680(const ReportContext::Ptr &context, const QXmlName &name, const SourceLocationReflection *const reflection)
Definition: qtemplate.cpp:70
DynamicContext::Ptr createStack()
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void error(const QString &message, const ReportContext::ErrorCode errorCode, const QSourceLocation &sourceLocation)
VariableDeclaration::List templateParameters
Definition: qtemplate_p.h:107
QExplicitlySharedDataPointer< Expression > Ptr
A smart pointer wrapping mutable Expression instances.
const WithParam::Hash & withParams() const
Evaluates its operand with an assigned DynamicContext, not the one passed to one of the evaluation fu...
static const KeyPair *const end
friend class const_iterator
Definition: qhash.h:461

◆ dependencies()

Expression::Properties Template::dependencies ( ) const

Definition at line 213 of file qtemplate.cpp.

Referenced by QPatternist::CallTemplate::dependencies().

214 {
215  return Expression::DisableElimination; /* We're having issues with recursion detection, so this path currently loops infintely. */
216 
218 
220 
222  it != end;
223  ++it)
224  {
225  if((*it)->expression())
226  collect |= (*it)->expression()->dependencies();
227  }
228 
230 }
#define it(className, varName)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
Expression::Ptr body
Definition: qtemplate_p.h:98
VariableDeclaration::List templateParameters
Definition: qtemplate_p.h:107
The QFlags class provides a type-safe way of storing OR-combinations of enum values.
Definition: qglobal.h:2313
static const KeyPair *const end
virtual Properties dependencies() const
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ parametersAsHash()

DynamicContext::TemplateParameterHash Template::parametersAsHash ( ) const
private

Definition at line 56 of file qtemplate.cpp.

Referenced by createContext().

57 {
59  const int len = templateParameters.count();
60 
61  for(int i = 0; i < len; ++i)
62  {
64  retval.insert(at->name, at->expression());
65  }
66 
67  return retval;
68 }
#define at(className, varName)
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
VariableDeclaration::List templateParameters
Definition: qtemplate_p.h:107

◆ properties()

Expression::Properties Template::properties ( ) const

A value which takes into account the body and its template parameters.

Definition at line 193 of file qtemplate.cpp.

Referenced by QPatternist::CallTemplate::properties().

194 {
195  return Expression::DisableElimination; /* We're having issues with recursion detection, so this path currently loops infintely. */
196 
198 
200 
202  it != end;
203  ++it)
204  {
205  if((*it)->expression())
206  collect |= (*it)->expression()->properties();
207  }
208 
209  // TODO simplify.
211 }
#define it(className, varName)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
Expression::Ptr body
Definition: qtemplate_p.h:98
VariableDeclaration::List templateParameters
Definition: qtemplate_p.h:107
virtual Properties properties() const
The QFlags class provides a type-safe way of storing OR-combinations of enum values.
Definition: qglobal.h:2313
static const KeyPair *const end
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ raiseXTSE0680()

void Template::raiseXTSE0680 ( const ReportContext::Ptr context,
const QXmlName name,
const SourceLocationReflection *const  reflection 
)
static

Definition at line 70 of file qtemplate.cpp.

Referenced by createContext(), and QPatternist::CallTemplate::typeCheck().

73 {
74  context->error(QtXmlPatterns::tr("The parameter %1 is passed, but no corresponding %2 exists.")
75  .arg(formatKeyword(context->namePool(), name),
76  formatKeyword(QLatin1String("xsl:param"))),
78  reflection);
79 }
QString formatKeyword(const QString &keyword)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
const char * name

Properties

◆ body

Expression::Ptr QPatternist::Template::body

◆ importPrecedence

const ImportPrecedence QPatternist::Template::importPrecedence

Definition at line 105 of file qtemplate_p.h.

Referenced by QPatternist::ApplyTemplate::findTemplate().

◆ m_reqType

const SequenceType::Ptr QPatternist::Template::m_reqType
private

Definition at line 139 of file qtemplate_p.h.

◆ templateParameters

VariableDeclaration::List QPatternist::Template::templateParameters

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