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

Performs atomization. Effectively, it is an implementation of the fn:data() function. More...

#include <qatomizer_p.h>

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

Public Functions

virtual ExpressionVisitorResult::Ptr accept (const ExpressionVisitor::Ptr &visitor) const
 
virtual const SourceLocationReflectionactualReflection () const
 Returns this. More...
 
 Atomizer (const Expression::Ptr &operand)
 
virtual Item::Iterator::Ptr evaluateSequence (const DynamicContext::Ptr &) const
 
virtual Item evaluateSingleton (const DynamicContext::Ptr &) const
 
virtual SequenceType::List expectedOperandTypes () const
 
Item::Iterator::Ptr mapToSequence (const Item &item, const DynamicContext::Ptr &context) const
 
virtual SequenceType::Ptr staticType () const
 
virtual Expression::Ptr typeCheck (const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
 
- 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 void announceFocusType (const ItemType::Ptr &itemType)
 
virtual Expression::Ptr compress (const StaticContext::Ptr &context)
 
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 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 ~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 AtomizerConstPtr
 

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

Performs atomization. Effectively, it is an implementation of the fn:data() function.

See also
XQuery 1.0 and XPath 2.0 Functions and Operators, 2.4 fn:data
XML Path Language (XPath) 2.0, 2.4.2 Atomization
Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 76 of file qatomizer_p.h.

Typedefs

◆ ConstPtr

Definition at line 102 of file qatomizer_p.h.

Constructors and Destructors

◆ Atomizer()

Atomizer::Atomizer ( const Expression::Ptr operand)

Definition at line 54 of file qatomizer.cpp.

54  : SingleContainer(operand)
55 {
56 }
SingleContainer(const Expression::Ptr &operand)

Functions

◆ accept()

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

Implements QPatternist::Expression.

Definition at line 115 of file qatomizer.cpp.

116 {
117  return visitor->visit(this);
118 }

◆ actualReflection()

const SourceLocationReflection * Atomizer::actualReflection ( ) const
virtual

Returns this.

Reimplemented from QPatternist::Expression.

Definition at line 120 of file qatomizer.cpp.

121 {
122  return m_operand->actualReflection();
123 }
virtual const SourceLocationReflection * actualReflection() const
Returns this.

◆ evaluateSequence()

Item::Iterator::Ptr Atomizer::evaluateSequence ( const DynamicContext::Ptr context) const
virtual

Evaluate this Expression by iterating over it. This is a central function for evaluating expressions.

Expressions must always always return a valid QAbstractXmlForwardIterator and may never return 0. If an empty result is of interest to be returned, the EmptyIterator should be returned.

The default implementation returns a SingletonIterator over the item returned from evaluateSingleton().

Note
This function may raise an exception when calling, not only when QAbstractXmlForwardIterator::next() is called on the return value. This is because in some cases evaluateSingleton() is called directly.

Reimplemented from QPatternist::Expression.

Definition at line 67 of file qatomizer.cpp.

68 {
69  return makeSequenceMappingIterator<Item>(ConstPtr(this),
70  m_operand->evaluateSequence(context),
71  context);
72 }
QExplicitlySharedDataPointer< const Atomizer > ConstPtr
Definition: qatomizer_p.h:102
virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const

◆ evaluateSingleton()

Item Atomizer::evaluateSingleton ( const DynamicContext::Ptr context) const
virtual

Reimplemented from QPatternist::Expression.

Definition at line 74 of file qatomizer.cpp.

75 {
76  const Item item(m_operand->evaluateSingleton(context));
77 
78  if(!item) /* Empty is allowed, cardinality is considered '?' */
79  return Item();
80 
81  const Item::Iterator::Ptr it(mapToSequence(item, context));
82  Q_ASSERT_X(it, Q_FUNC_INFO, "A valid QAbstractXmlForwardIterator must always be returned.");
83 
84  Item result(it->next());
85  Q_ASSERT_X(!it->next(), Q_FUNC_INFO,
86  "evaluateSingleton should never be used if the cardinality is two or more");
87 
88  return result;
89 }
#define it(className, varName)
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
Item::Iterator::Ptr mapToSequence(const Item &item, const DynamicContext::Ptr &context) const
Definition: qatomizer.cpp:58
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ expectedOperandTypes()

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

Returns a list of Sequence Types, describing the type of each of the expression's operands. Hence, this function has a relationship to the operands() function:

- The lengths of the lists returned by expectedOperandTypes()
and operands() should always be equal in length, since one
cannot describe the type of a non-existent operand(and all
operands must have type information).
- A significant difference between the two functions is that while
the type of objects in the list returned by operands() may vary
between compilations/static context, simply because the particular
Expression is part of different XPath expressions, the
types in the list returned by expectedOperandTypes is always the same
since the function/operator signature never changes.

This function should not be confused with staticType(), which returns the static type of the expression itself, not its operands. The function call is an expression where this is clear: the type of the return value is not the same as the arguments' types. The static type of the operands supplied to the expression can be determined via the staticType() function of the instances returned by operands().

If the expression has no operands, an empty list should be returned.

Implements QPatternist::Expression.

Definition at line 108 of file qatomizer.cpp.

109 {
110  SequenceType::List result;
112  return result;
113 }
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

◆ mapToSequence()

Item::Iterator::Ptr Atomizer::mapToSequence ( const Item item,
const DynamicContext::Ptr context 
) const
inline

Definition at line 58 of file qatomizer.cpp.

Referenced by evaluateSingleton().

59 {
60  /* Function & Operators, 2.4.2 fn:data, says "If the node does not have a
61  * typed value an error is raised [err:FOTY0012]."
62  * When does a node not have a typed value? */
63  Q_ASSERT(item);
64  return item.sequencedTypedValue();
65 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Item::Iterator::Ptr sequencedTypedValue() const
Returns the typed value of this item.
Definition: qitem.cpp:50

◆ staticType()

SequenceType::Ptr Atomizer::staticType ( ) const
virtual
Returns
the static type of this Expression. For example, an 'and' expression have as static type xs:boolean

Implements QPatternist::Expression.

Definition at line 101 of file qatomizer.cpp.

102 {
103  const SequenceType::Ptr opt(m_operand->staticType());
104  return makeGenericSequenceType(opt->itemType()->atomizedType(),
105  opt->cardinality());
106 }
virtual SequenceType::Ptr staticType() const =0

◆ typeCheck()

Expression::Ptr Atomizer::typeCheck ( const StaticContext::Ptr context,
const SequenceType::Ptr reqType 
)
virtual

Makes an early compression, by returning the result of the type checked operand, if the operand has the static type xs:anyAtomicType(no atomization needed).

Reimplemented from QPatternist::Expression.

Definition at line 91 of file qatomizer.cpp.

93 {
94  /* Compress -- the earlier the better. */
96  return m_operand->typeCheck(context, reqType);
97 
98  return SingleContainer::typeCheck(context, reqType);
99 }
virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
Definition: qexpression.cpp:70
virtual SequenceType::Ptr staticType() const =0
static const AtomicType::Ptr xsAnyAtomicType
virtual ItemType::Ptr itemType() const =0

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