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

Does node copying in a parameterized way, in order to deal with namespace preservation/inheritance. More...

#include <qcopyof_p.h>

Inheritance diagram for QPatternist::CopyOf:
QPatternist::SingleContainer QPatternist::Expression QSharedData QPatternist::CppCastingHelper< Expression > QPatternist::SourceLocationReflection

Public Functions

virtual ExpressionVisitorResult::Ptr accept (const ExpressionVisitor::Ptr &visitor) const
 
virtual Expression::Ptr compress (const StaticContext::Ptr &context)
 
 CopyOf (const Expression::Ptr &operand, const bool inheritNSS, const bool preserveNSS)
 
virtual void evaluateToSequenceReceiver (const DynamicContext::Ptr &context) const
 
virtual ItemType::Ptr expectedContextItemType () const
 
virtual SequenceType::List expectedOperandTypes () const
 
Item mapToItem (const Item &source, const DynamicContext::Ptr &context) const
 
virtual Properties properties () const
 
virtual SequenceType::Ptr staticType () const
 
- Public Functions inherited from QPatternist::SingleContainer
virtual bool compressOperands (const StaticContext::Ptr &)
 
virtual Expression::List operands () const
 
virtual void setOperands (const Expression::List &operands)
 
- Public Functions inherited from QPatternist::Expression
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
 
 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
 
const Expression::Ptrrewrite (const Expression::Ptr &to, const StaticContext::Ptr &context) const
 Rewrites this Expression to to, and return to. More...
 
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 ()
 

Private Types

typedef QExplicitlySharedDataPointer< const CopyOfConstPtr
 

Properties

const bool m_inheritNamespaces
 
const bool m_preserveNamespaces
 
const QAbstractXmlNodeModel::NodeCopySettings m_settings
 

Additional Inherited Members

- 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)
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 
- Protected Functions inherited from QPatternist::SingleContainer
 SingleContainer (const Expression::Ptr &operand)
 
- Protected Functions inherited from QPatternist::Expression
void typeCheckOperands (const StaticContext::Ptr &context)
 
- Protected Functions inherited from QPatternist::CppCastingHelper< Expression >
 CppCastingHelper ()
 
- Protected Variables inherited from QPatternist::SingleContainer
Expression::Ptr m_operand
 

Detailed Description

Does node copying in a parameterized way, in order to deal with namespace preservation/inheritance.

If someone tries to call evaluateEBV(), evaluateSingleton() or evaluateSequence() on us, we will infinitely loop. But apparently that's not possible because we're always a child of ElementConstructor, currently.

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

Definition at line 75 of file qcopyof_p.h.

Typedefs

◆ ConstPtr

Definition at line 110 of file qcopyof_p.h.

Constructors and Destructors

◆ CopyOf()

CopyOf::CopyOf ( const Expression::Ptr operand,
const bool  inheritNSS,
const bool  preserveNSS 
)

Creats a CopyOf where it is checked that the expression operand conforms to the type reqType.

Definition at line 52 of file qcopyof.cpp.

54  : SingleContainer(operand)
55  , m_inheritNamespaces(inheritNSS)
56  , m_preserveNamespaces(preserveNSS)
59 {
60 }
SingleContainer(const Expression::Ptr &operand)
const bool m_inheritNamespaces
Definition: qcopyof_p.h:111
const bool m_preserveNamespaces
Definition: qcopyof_p.h:112
The QFlags class provides a type-safe way of storing OR-combinations of enum values.
Definition: qglobal.h:2313
const QAbstractXmlNodeModel::NodeCopySettings m_settings
Definition: qcopyof_p.h:113

Functions

◆ accept()

ExpressionVisitorResult::Ptr CopyOf::accept ( const ExpressionVisitor::Ptr visitor) const
virtual

Implements QPatternist::Expression.

Definition at line 103 of file qcopyof.cpp.

104 {
105  return visitor->visit(this);
106 }

◆ compress()

Expression::Ptr CopyOf::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.

Definition at line 62 of file qcopyof.cpp.

63 {
64  /* We have zero effect if we have these settings. */
66  return m_operand->compress(context);
67  else
68  {
70  /* We have no effect on the empty sequence or atomic values. */
71  if(BuiltinTypes::xsAnyAtomicType->xdtTypeMatches(t)
73  return m_operand->compress(context);
74  else
75  return SingleContainer::compress(context);
76  }
77 }
virtual Expression::Ptr compress(const StaticContext::Ptr &context)
const bool m_inheritNamespaces
Definition: qcopyof_p.h:111
virtual SequenceType::Ptr staticType() const =0
static const EmptySequenceType::Ptr Empty
const bool m_preserveNamespaces
Definition: qcopyof_p.h:112
static const AtomicType::Ptr xsAnyAtomicType
virtual ItemType::Ptr itemType() const =0

◆ evaluateToSequenceReceiver()

void CopyOf::evaluateToSequenceReceiver ( const DynamicContext::Ptr context) const
virtual

Evaluates this Expression by sending its output to DynamicContext::outputReceiver().

Reimplemented from QPatternist::Expression.

Definition at line 79 of file qcopyof.cpp.

80 {
81  /* Optimization: this completely breaks streaming. We get a call to
82  * evaluateToSequenceReceiver() but we require heap allocations by calling
83  * evaluateSequence(). */
84 
86  QAbstractXmlReceiver *const receiver = context->outputReceiver();
87  Item next(it->next());
88 
89  while(next)
90  {
91  if(next.isNode())
92  {
93  const QXmlNodeModelIndex &asNode = next.asNode();
94  asNode.model()->copyNodeTo(asNode, receiver, m_settings);
95  }
96  else
97  receiver->item(next);
98 
99  next = it->next();
100  }
101 }
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
A push interface for the XPath Data Model. Similar to SAX&#39;s ContentHandler.
#define it(className, varName)
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
const QAbstractXmlNodeModel * model() const
Returns the QAbstractXmlNodeModel that this node index refers to.
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
virtual QAbstractXmlReceiver * outputReceiver() const =0
const QAbstractXmlNodeModel::NodeCopySettings m_settings
Definition: qcopyof_p.h:113
virtual void copyNodeTo(const QXmlNodeModelIndex &node, QAbstractXmlReceiver *const receiver, const NodeCopySettings &) const
virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const

◆ expectedContextItemType()

ItemType::Ptr CopyOf::expectedContextItemType ( ) const
virtual

Returns the required type the context item must be an instance of.

If this Expression requires a focus, meaning its properties() function returns RequiresContextItem, it must return a type from this function. If any type is ok, BuiltinTypes::item should be returned.

In other words, this function must only be re-implemented if the focus is used. The default implementation performs an assert crash.

Reimplemented from QPatternist::Expression.

Definition at line 129 of file qcopyof.cpp.

130 {
132 }
virtual ItemType::Ptr expectedContextItemType() const

◆ expectedOperandTypes()

SequenceType::List CopyOf::expectedOperandTypes ( ) const
virtual
Returns
a list containing one CommonSequenceTypes::ZeroOrMoreItems

Implements QPatternist::Expression.

Definition at line 113 of file qcopyof.cpp.

114 {
115  SequenceType::List result;
117  return result;
118 }
static const SequenceType::Ptr ZeroOrMoreItems
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ mapToItem()

Item QPatternist::CopyOf::mapToItem ( const Item source,
const DynamicContext::Ptr context 
) const
inline

◆ properties()

Expression::Properties CopyOf::properties ( ) const
virtual
Returns
a bitwise OR'd value of properties, describing the characteristics of the expression. These properties affects how this Expression is treated in for example type checking stages.

The default implementation returns 0. Override and let the function return a different value, if that's of interest.

An important decision when re-implementing properties() is whether to OR in the properties() of ones operands. For instance, if an operand has RequiresFocus set, that flag nost likely applies to the apparent as well, since it depends on its operand.

See also
deepProperties()
Returns
Expression::None, meaning no special properties

Reimplemented from QPatternist::Expression.

Definition at line 120 of file qcopyof.cpp.

121 {
122  /* We have the content of node constructors as children, but even though
123  * createCopyOf() typically avoids creating us, we can still end up with an operand
124  * that allows compression. We must always avoid that, because we don't have
125  * implementation of evaluateSequence(), and so on. */
127 }
virtual Properties properties() const

◆ staticType()

SequenceType::Ptr CopyOf::staticType ( ) const
virtual
Returns
always the SequenceType passed in the constructor to this class. That is, the SequenceType that the operand must conform to.

Implements QPatternist::Expression.

Definition at line 108 of file qcopyof.cpp.

109 {
110  return m_operand->staticType();
111 }
virtual SequenceType::Ptr staticType() const =0

Properties

◆ m_inheritNamespaces

const bool QPatternist::CopyOf::m_inheritNamespaces
private

Definition at line 111 of file qcopyof_p.h.

Referenced by compress().

◆ m_preserveNamespaces

const bool QPatternist::CopyOf::m_preserveNamespaces
private

Definition at line 112 of file qcopyof_p.h.

Referenced by compress().

◆ m_settings

const QAbstractXmlNodeModel::NodeCopySettings QPatternist::CopyOf::m_settings
private

Definition at line 113 of file qcopyof_p.h.

Referenced by evaluateToSequenceReceiver().


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