Qt 4.8
Public Functions | Public Variables | Protected Functions | List of all members
QPatternist::TemplateInvoker Class Reference

Base class for classes that invokes templates, such as CallTemplate and ApplyTemplate. More...

#include <qtemplateinvoker_p.h>

Inheritance diagram for QPatternist::TemplateInvoker:
QPatternist::CallSite QPatternist::UnlimitedContainer QPatternist::Expression QSharedData QPatternist::CppCastingHelper< Expression > QPatternist::SourceLocationReflection QPatternist::ApplyTemplate QPatternist::CallTemplate

Public Functions

virtual Expression::Ptr compress (const StaticContext::Ptr &context)
 
virtual SequenceType::List expectedOperandTypes () const
 
const WithParam::HashwithParams () const
 
- Public Functions inherited from QPatternist::CallSite
virtual Expression::Ptr body () const =0
 Returns the body of the function/template/component that is being called. More...
 
virtual CallTargetDescription::Ptr callTargetDescription () const =0
 
virtual bool configureRecursion (const CallTargetDescription::Ptr &sign)=0
 
bool isRecursive () const
 
QXmlName name () const
 
void setIsRecursive (const bool value)
 
- Public Functions inherited from QPatternist::UnlimitedContainer
virtual bool compressOperands (const StaticContext::Ptr &)
 
virtual Expression::List operands () const
 
virtual void setOperands (const Expression::List &list)
 
 UnlimitedContainer (const Expression::List &operands=Expression::List())
 
- Public Functions inherited from QPatternist::Expression
virtual ExpressionVisitorResult::Ptr accept (const ExpressionVisitor::Ptr &visitor) const =0
 
virtual const SourceLocationReflectionactualReflection () const
 Returns this. More...
 
virtual void announceFocusType (const ItemType::Ptr &itemType)
 
Properties deepProperties () const
 Computes the union of properties for this Expression and all its descending children. More...
 
virtual Properties dependencies () const
 
virtual QString description () const
 
virtual bool evaluateEBV (const DynamicContext::Ptr &context) const
 
virtual Item::Iterator::Ptr evaluateSequence (const DynamicContext::Ptr &context) const
 
virtual Item evaluateSingleton (const DynamicContext::Ptr &context) const
 
virtual void evaluateToSequenceReceiver (const DynamicContext::Ptr &context) const
 
virtual ItemType::Ptr expectedContextItemType () const
 
 Expression ()
 
bool has (const Property prop) const
 
bool hasDependency (const Property prop) const
 
virtual ID id () const
 
bool is (const ID id) const
 
bool isEvaluated () const
 
virtual ItemType::Ptr newFocusType () const
 
virtual QList< QExplicitlySharedDataPointer< OptimizationPass > > optimizationPasses () const
 
virtual PatternPriority patternPriority () const
 
virtual Properties properties () const
 
const Expression::Ptrrewrite (const Expression::Ptr &to, const StaticContext::Ptr &context) const
 Rewrites this Expression to to, and return to. More...
 
virtual SequenceType::Ptr staticType () const =0
 
virtual Expression::Ptr typeCheck (const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
 
virtual ~Expression ()
 
- 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::CppCastingHelper< Expression >
const TCastTarget * as () const
 
TCastTarget * as ()
 
- Public Functions inherited from QPatternist::SourceLocationReflection
virtual QSourceLocation sourceLocation () const
 
 SourceLocationReflection ()
 
virtual ~SourceLocationReflection ()
 

Public Variables

WithParam::Hash m_withParams
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 

Protected Functions

 TemplateInvoker (const WithParam::Hash &withParams, const QXmlName &name=QXmlName())
 
- Protected Functions inherited from QPatternist::CallSite
 CallSite (const QXmlName &name=QXmlName())
 
- Protected Functions inherited from QPatternist::UnlimitedContainer
template<CardinalityComputation suppliedCard>
SequenceType::Ptr operandsUnionType () const
 
- Protected Functions inherited from QPatternist::Expression
void typeCheckOperands (const StaticContext::Ptr &context)
 
- Protected Functions inherited from QPatternist::CppCastingHelper< Expression >
 CppCastingHelper ()
 

Additional Inherited Members

- Public Types inherited from QPatternist::UnlimitedContainer
enum  CardinalityComputation { ProductOfCardinality, UnionOfCardinality }
 
- Public Types inherited from QPatternist::Expression
typedef QExplicitlySharedDataPointer< const ExpressionConstPtr
 A smart pointer wrapping const Expression instances. More...
 
enum  ID {
  IDBooleanValue = 1, IDCountFN, IDEmptyFN, IDExistsFN,
  IDExpressionSequence, IDGeneralComparison, IDIfThenClause, IDIgnorableExpression,
  IDIntegerValue, IDPositionFN, IDStringValue, IDValueComparison,
  IDRangeVariableReference, IDContextItem, IDUserFunctionCallsite, IDExpressionVariableReference,
  IDAttributeConstructor, IDUpperCaseFN, IDLowerCaseFN, IDFirstItemPredicate,
  IDEmptySequence, IDReturnOrderBy, IDLetClause, IDForClause,
  IDPath, IDNamespaceConstructor, IDArgumentReference, IDGenericPredicate,
  IDAxisStep, IDFloat, IDCombineNodes, IDUnresolvedVariableReference,
  IDCardinalityVerifier
}
 
typedef QList< Expression::PtrList
 
typedef QFlags< PropertyProperties
 
enum  Property {
  UseContextItem = 1, DisableElimination = 1 << 1, IsEvaluated = 1 << 2, DisableTypingDeduction = 1 << 3,
  EmptynessFollowsChild = 1 << 4, RewriteToEmptyOnEmpty = 1 << 5, RequiresFocus = 1 << 6, AffectsOrderOnly = 1 << 7,
  RequiresContextItem = (1 << 8) | RequiresFocus, CreatesFocusForLast = 1 << 9, LastOperandIsCollation = 1 << 10, DependsOnLocalVariable = (1 << 11) | DisableElimination,
  EvaluationCacheRedundant = (1 << 12), IsNodeConstructor = 1 << 13, RequiresCurrentItem = 1 << 14
}
 
typedef QExplicitlySharedDataPointer< ExpressionPtr
 A smart pointer wrapping mutable Expression instances. More...
 
typedef ::QAbstractXmlForwardIterator< Expression::PtrQAbstractXmlForwardIterator
 
typedef QVector< Expression::PtrVector
 
- Static Public Functions inherited from QPatternist::Expression
static void rewrite (Expression::Ptr &old, const Expression::Ptr &New, const StaticContext::Ptr &context)
 
- Protected Variables inherited from QPatternist::UnlimitedContainer
Expression::List m_operands
 

Detailed Description

Base class for classes that invokes templates, such as CallTemplate and ApplyTemplate.

TemplateInvoker has the member m_withParams, which is the xsl:with-param instructions of the caller. The definite source for the expressions is m_withParams, not Expression::operands(). However, the order of operands() is defined, while m_withParams is not since it's a hash. Therefore operands() is definite on order.

TemplateInvoker is intended to be sub-classed.

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

Definition at line 79 of file qtemplateinvoker_p.h.

Constructors and Destructors

◆ TemplateInvoker()

TemplateInvoker::TemplateInvoker ( const WithParam::Hash withParams,
const QXmlName name = QXmlName() 
)
protected

withParams may be empty.

Definition at line 48 of file qtemplateinvoker.cpp.

49  : CallSite(name)
50  , m_withParams(withParams)
51 {
53 
55  {
56  /* In the case of for instance:
57  * <xsl:with-param name="empty_seq" as="item()"/>
58  *
59  * we have no default expression. */
60  Q_ASSERT(it.value()->sourceExpression());
61  m_operands.append(it.value()->sourceExpression());
62  }
63 }
#define it(className, varName)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
static const KeyPair *const end
CallSite(const QXmlName &name=QXmlName())
Definition: qcallsite.cpp:48
friend class const_iterator
Definition: qhash.h:461

Functions

◆ compress()

Expression::Ptr TemplateInvoker::compress ( const StaticContext::Ptr context)
virtual

compress() is the last stage performs in compiling an expression, done after the initial AST build and calling typeCheck(). compress() performs crucial simplifications, either by having drastic performance implications or that some expressions depend on it for proper behavior.

The default implementation performs a sparse conditional constant propagation. In short, a recursive process is performed in the AST which examines if the Expression's operands are constant values, and if so, performs a const fold(AST rewrite) into the result of evaluating the expression in question. This default behavior can be disabled by letting properties() return DisableElimination.

This compress() stage can be relative effective due to the design of XPath, in part because intrinsic functions are heavily used. Many Expressions override compress() and do optimizations specific to what they do. Also, many Expressions performs optimizations in their typeCheck().

Parameters
contextthe static context. Supplies compile time information, and is the channel for communicating error messages.
See also
Wikipedia, the free encyclopedia, Sparse conditional constant propagation
Wikipedia, the free encyclopedia, Intrinsic function
Wikipedia, the free encyclopedia, Compiler optimization

Reimplemented from QPatternist::Expression.

Reimplemented in QPatternist::ApplyTemplate.

Definition at line 65 of file qtemplateinvoker.cpp.

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

66 {
67  /* CallSite::compress() may have changed our children, so update
68  * our m_withParams. */
69  const Expression::Ptr me(CallSite::compress(context));
71  int exprIndex = -1;
72 
74  {
75  if(it.value()->sourceExpression())
76  {
77  ++exprIndex;
78  it.value()->setSourceExpression(m_operands.at(exprIndex));
79  }
80  }
81 
82  return me;
83 }
#define it(className, varName)
virtual Expression::Ptr compress(const StaticContext::Ptr &context)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
static const KeyPair *const end
friend class const_iterator
Definition: qhash.h:461

◆ expectedOperandTypes()

SequenceType::List TemplateInvoker::expectedOperandTypes ( ) const
virtual

This is a bit complicated by that we have two required types, one specified by xsl:param in the template declaration, and one on xsl:with-param.

See also
UserFunctionCallsite::expectedOperandTypes()
XSL Transformations (XSLT) Version 2.0, 10.1.1 Passing Parameters to Templates

Implements QPatternist::Expression.

Definition at line 85 of file qtemplateinvoker.cpp.

86 {
87  SequenceType::List result;
88 
89  /* We don't return the type of the m_template->templateParameters(), we
90  * return the type of the @c xsl:with-param first. @em After that, we
91  * manually apply the parameter types in typeCheck(). */
93 
95  {
96  /* We're not guaranteed to have a with-param, we may be using the
97  * default value of the xsl:param. Tunnel parameters may also play
98  * in. */
99  result.append(it.value()->type());
100  }
101 
102  return result;
103 }
#define it(className, varName)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
static const KeyPair *const end
friend class const_iterator
Definition: qhash.h:461
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ withParams()

const WithParam::Hash & QPatternist::TemplateInvoker::withParams ( ) const
inline

Definition at line 108 of file qtemplateinvoker_p.h.

Referenced by QPatternist::Template::createContext().

109  {
110  return m_withParams;
111  }

Properties

◆ m_withParams

WithParam::Hash QPatternist::TemplateInvoker::m_withParams

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