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

Implements the function fn:id(). More...

#include <qsequencegeneratingfns_p.h>

Inheritance diagram for QPatternist::IdFN:
QPatternist::ContextNodeChecker QPatternist::FunctionCall QPatternist::UnlimitedContainer QPatternist::Expression QSharedData QPatternist::CppCastingHelper< Expression > QPatternist::SourceLocationReflection

Public Types

typedef QPair< DynamicContext::Ptr, const QAbstractXmlNodeModel * > IDContext
 
- Public Types inherited from QPatternist::FunctionCall
typedef QExplicitlySharedDataPointer< FunctionCallPtr
 
- 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
 

Public Functions

virtual Item::Iterator::Ptr evaluateSequence (const DynamicContext::Ptr &context) const
 
 IdFN ()
 
Item mapToItem (const QString &id, const IDContext &context) const
 
virtual Expression::Ptr typeCheck (const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
 
- Public Functions inherited from QPatternist::FunctionCall
virtual ExpressionVisitorResult::Ptr accept (const ExpressionVisitor::Ptr &visitor) const
 
virtual SequenceType::List expectedOperandTypes () const
 
virtual ID id () const
 
virtual Expression::Properties properties () const
 
virtual void setSignature (const FunctionSignature::Ptr &sign)
 
virtual FunctionSignature::Ptr signature () const
 
virtual SequenceType::Ptr staticType () const
 
- 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 const SourceLocationReflectionactualReflection () const
 Returns this. More...
 
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 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
 
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 ()
 
- 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 IdFNConstPtr
 

Properties

bool m_hasCreatedSorter
 

Additional Inherited Members

- 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::ContextNodeChecker
void checkTargetNode (const QXmlNodeModelIndex &node, const DynamicContext::Ptr &context, const ReportContext::ErrorCode) const
 Checks that the root node of node is a document node, and otherwise issues an error. More...
 
- 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 ()
 
- Protected Variables inherited from QPatternist::UnlimitedContainer
Expression::List m_operands
 

Detailed Description

Implements the function fn:id().

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

Definition at line 80 of file qsequencegeneratingfns_p.h.

Typedefs

◆ ConstPtr

Definition at line 95 of file qsequencegeneratingfns_p.h.

◆ IDContext

Definition at line 84 of file qsequencegeneratingfns_p.h.

Constructors and Destructors

◆ IdFN()

IdFN::IdFN ( )

Definition at line 62 of file qsequencegeneratingfns.cpp.

62  : m_hasCreatedSorter(false)
63 {
64 }

Functions

◆ evaluateSequence()

Item::Iterator::Ptr IdFN::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 168 of file qsequencegeneratingfns.cpp.

169 {
170  const Item::Iterator::Ptr idrefs(m_operands.first()->evaluateSequence(context));
171  const Item node(m_operands.last()->evaluateSingleton(context));
172 
173  checkTargetNode(node.asNode(), context, ReportContext::FODC0001);
174 
175  return makeItemMappingIterator<Item,
176  QString,
178  IDContext>(ConstPtr(this),
179  StringSplitter::Ptr(new StringSplitter(idrefs)),
180  qMakePair(context, node.asNode().model()));
181 }
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
QExplicitlySharedDataPointer< const IdFN > ConstPtr
The QString class provides a Unicode character string.
Definition: qstring.h:83
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< QString > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.
QPair< DynamicContext::Ptr, const QAbstractXmlNodeModel * > IDContext
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
void checkTargetNode(const QXmlNodeModelIndex &node, const DynamicContext::Ptr &context, const ReportContext::ErrorCode) const
Checks that the root node of node is a document node, and otherwise issues an error.
Helper class for IdFN.
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const
virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const

◆ mapToItem()

Item IdFN::mapToItem ( const QString id,
const IDContext context 
) const
inline

Definition at line 66 of file qsequencegeneratingfns.cpp.

68 {
69  return context.second->elementById(context.first->namePool()->allocateQName(QString(), id));
70 }
The QString class provides a Unicode character string.
Definition: qstring.h:83

◆ typeCheck()

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

This implementation guarantees to never rewrite away this Expression, but at most rewrite it as a child of another expression(that presumably have a type checking role). It is therefore always safe to override this function and call this implementation and not worry about that this Expression becomes deleted.

Many Expressions override typeCheck() and performs optimizations, as opposed to doing it in the compress() stage. This is due to that the design of those Expressions often are tied to that certain simplifications are done at the typeCheck() stage of the compilation process or that it in some other way is related to what the typeCheck() do. Also, the earlier the AST can be simplified, the better the chances are for subsequent optimizations.

It is important that the super class's typeCheck() is called before doing any custom type checking, since the call can change the children(notably, the childrens' static types). For example, if the Expression, MyExpression in the example, does not match the required type, typeCheck returns the Expression wrapped in for example ItemVerifier, CardinalityVerifier, or both.

typeCheck() may be called many times. typeCheck() must either raise an error if this Expression is an invalid expression. Thus, it is guaranteed that an Expression is valid after typeCheck() is called.

Parameters
contextsupplies information, such as namespace bindings and available function signatures, that can be needed at compilation time. context is guaranteed by the caller to never null.
reqTypethe static type that this Expression must match when evaluated. reqType is guaranteed by the caller to never null.
Returns
an Expression that can be this Expression, or another expression, which somehow is necessary for making this Expression conforming to reqType

Reimplemented from QPatternist::FunctionCall.

Definition at line 183 of file qsequencegeneratingfns.cpp.

185 {
187  return FunctionCall::typeCheck(context, reqType);
188  else
189  {
190  const Expression::Ptr newMe(new NodeSortExpression(Expression::Ptr(this)));
191  context->wrapExpressionWith(this, newMe);
192  m_hasCreatedSorter = true;
193  return newMe->typeCheck(context, reqType);
194  }
195 }
virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
De-duplicates and sorts in document order the content that its operand returns.
Definition: qnodesort_p.h:70
void wrapExpressionWith(const SourceLocationReflection *const existingNode, const QExplicitlySharedDataPointer< Expression > &newNode)
Ensures source locations are handled in such a manner that existingNode wraps newNode.

Properties

◆ m_hasCreatedSorter

bool QPatternist::IdFN::m_hasCreatedSorter
private

Definition at line 96 of file qsequencegeneratingfns_p.h.


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