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

A step in a path expression that with an axis and a node test evaluates to a sequence of nodes from the context item. More...

#include <qaxisstep_p.h>

Inheritance diagram for QPatternist::AxisStep:
QPatternist::EmptyContainer QPatternist::Expression QSharedData QPatternist::CppCastingHelper< Expression > QPatternist::SourceLocationReflection

Public Functions

virtual ExpressionVisitorResult::Ptr accept (const ExpressionVisitor::Ptr &visitor) const
 
QXmlNodeModelIndex::Axis axis () const
 
 AxisStep (const QXmlNodeModelIndex::Axis axis, const ItemType::Ptr &nodeTest)
 
virtual Item::Iterator::Ptr evaluateSequence (const DynamicContext::Ptr &) const
 
virtual Item evaluateSingleton (const DynamicContext::Ptr &) const
 
virtual ItemType::Ptr expectedContextItemType () const
 
virtual SequenceType::List expectedOperandTypes () const
 
virtual ID id () const
 
Item mapToItem (const QXmlNodeModelIndex &node, const DynamicContext::Ptr &context) const
 
ItemType::Ptr nodeTest () const
 
virtual PatternPriority patternPriority () const
 
virtual Properties properties () const
 
void setAxis (const QXmlNodeModelIndex::Axis newAxis)
 
void setNodeTest (const ItemType::Ptr &nev)
 
virtual SequenceType::Ptr staticType () const
 
virtual Expression::Ptr typeCheck (const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
 
- Public Functions inherited from QPatternist::EmptyContainer
virtual Expression::List operands () const
 
virtual void setOperands (const 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 void evaluateToSequenceReceiver (const DynamicContext::Ptr &context) 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
 
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 ()
 

Static Public Functions

static QString axisName (const QXmlNodeModelIndex::Axis axis)
 Prints the EBNF name corresponding to axis. More...
 
- Static Public Functions inherited from QPatternist::Expression
static void rewrite (Expression::Ptr &old, const Expression::Ptr &New, const StaticContext::Ptr &context)
 

Private Types

typedef QExplicitlySharedDataPointer< const AxisStepConstPtr
 

Static Private Functions

static bool isAlwaysEmpty (const QXmlNodeModelIndex::Axis axis, const QXmlNodeModelIndex::NodeKind nodeKind)
 

Properties

QXmlNodeModelIndex::Axis m_axis
 
ItemType::Ptr m_nodeTest
 

Static Private Attributes

static const QXmlNodeModelIndex::NodeKind s_whenAxisNodeKindEmpty []
 

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

Detailed Description

A step in a path expression that with an axis and a node test evaluates to a sequence of nodes from the context item.

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

Definition at line 71 of file qaxisstep_p.h.

Typedefs

◆ ConstPtr

Definition at line 137 of file qaxisstep_p.h.

Constructors and Destructors

◆ AxisStep()

AxisStep::AxisStep ( const QXmlNodeModelIndex::Axis  axis,
const ItemType::Ptr nodeTest 
)

Definition at line 91 of file qaxisstep.cpp.

92  : m_axis(a),
93  m_nodeTest(nt)
94 {
97  "We assume we're a node type.");
98 }
long ASN1_INTEGER_get ASN1_INTEGER * a
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
ItemType::Ptr m_nodeTest
Definition: qaxisstep_p.h:154
#define nt(var, enu)
static const AnyNodeType::Ptr node
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
#define Q_FUNC_INFO
Definition: qglobal.h:1871
QXmlNodeModelIndex::Axis m_axis
Definition: qaxisstep_p.h:153

Functions

◆ accept()

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

Implements QPatternist::Expression.

Definition at line 199 of file qaxisstep.cpp.

200 {
201  return visitor->visit(this);
202 }

◆ axis()

QXmlNodeModelIndex::Axis AxisStep::axis ( ) const
Returns
the axis this step is using.

Definition at line 204 of file qaxisstep.cpp.

Referenced by QPatternist::changeToTopAxis().

205 {
206  return m_axis;
207 }
QXmlNodeModelIndex::Axis m_axis
Definition: qaxisstep_p.h:153

◆ axisName()

QString AxisStep::axisName ( const QXmlNodeModelIndex::Axis  axis)
static

Prints the EBNF name corresponding to axis.

For instance, for QXmlNodeModelIndex::Child, "child" is returned.

Apart from being used in this class, it is used in the SDK.

Definition at line 209 of file qaxisstep.cpp.

Referenced by QPatternist::yyparse().

210 {
211  const char *result = 0;
212 
213  switch(axis)
214  {
215  /* These must not be translated. */
216  case QXmlNodeModelIndex::AxisAncestorOrSelf: result = "ancestor-or-self"; break;
217  case QXmlNodeModelIndex::AxisAncestor: result = "ancestor"; break;
218  case QXmlNodeModelIndex::AxisAttributeOrTop: result = "attribute-or-top"; break;
219  case QXmlNodeModelIndex::AxisAttribute: result = "attribute"; break;
220  case QXmlNodeModelIndex::AxisChildOrTop: result = "child-or-top"; break;
221  case QXmlNodeModelIndex::AxisChild: result = "child"; break;
222  case QXmlNodeModelIndex::AxisDescendantOrSelf: result = "descendant-or-self"; break;
223  case QXmlNodeModelIndex::AxisDescendant: result = "descendant"; break;
224  case QXmlNodeModelIndex::AxisFollowing: result = "following"; break;
225  case QXmlNodeModelIndex::AxisFollowingSibling: result = "following-sibling"; break;
226  case QXmlNodeModelIndex::AxisNamespace: result = "namespace"; break;
227  case QXmlNodeModelIndex::AxisParent: result = "parent"; break;
228  case QXmlNodeModelIndex::AxisPreceding: result = "preceding"; break;
229  case QXmlNodeModelIndex::AxisPrecedingSibling: result = "preceding-sibling"; break;
230  case QXmlNodeModelIndex::AxisSelf: result = "self"; break;
231  }
232 
233  Q_ASSERT_X(result, Q_FUNC_INFO, "An unknown axis type was apparently encountered.");
234  return QString::fromLatin1(result);
235 }
QXmlNodeModelIndex::Axis axis() const
Definition: qaxisstep.cpp:204
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ evaluateSequence()

Item::Iterator::Ptr AxisStep::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 114 of file qaxisstep.cpp.

115 {
116  /* If we don't have a focus, it's either a bug or our parent isn't a Path
117  * that have advanced the focus iterator. Hence, attempt to advance the focus on our own. */
118  if(!context->contextItem())
119  context->focusIterator()->next();
120 
121  Q_ASSERT(context->contextItem());
122 
124 
125  return makeItemMappingIterator<Item>(ConstPtr(this), source, context);
126 }
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
QExplicitlySharedDataPointer< const AxisStep > ConstPtr
Definition: qaxisstep_p.h:137
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual Item contextItem() const =0
const QXmlNodeModelIndex & asNode() const
Definition: qitem_p.h:379
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< QXmlNodeModelIndex > > iterate(const Axis axis) const
Definition: qitem_p.h:456
virtual Item::Iterator::Ptr focusIterator() const =0
QXmlNodeModelIndex::Axis m_axis
Definition: qaxisstep_p.h:153

◆ evaluateSingleton()

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

Reimplemented from QPatternist::Expression.

Definition at line 128 of file qaxisstep.cpp.

129 {
130  /* If we don't have a focus, it's either a bug or our parent isn't a Path
131  * that have advanced the focus iterator. Hence, attempt to advance the focus on our own. */
132  if(!context->contextItem())
133  context->focusIterator()->next();
134 
135  Q_ASSERT(context->contextItem());
136 
138  QXmlNodeModelIndex next(it->next());
139 
140  while(!next.isNull())
141  {
142  const Item candidate(mapToItem(next, context));
143 
144  if(candidate)
145  return candidate;
146  else
147  next = it->next();
148  };
149 
150  return Item();
151 }
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
#define it(className, varName)
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual Item contextItem() const =0
Item mapToItem(const QXmlNodeModelIndex &node, const DynamicContext::Ptr &context) const
Definition: qaxisstep.cpp:100
const QXmlNodeModelIndex & asNode() const
Definition: qitem_p.h:379
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< QXmlNodeModelIndex > > iterate(const Axis axis) const
Definition: qitem_p.h:456
virtual Item::Iterator::Ptr focusIterator() const =0
QXmlNodeModelIndex::Axis m_axis
Definition: qaxisstep_p.h:153

◆ expectedContextItemType()

ItemType::Ptr AxisStep::expectedContextItemType ( ) const
virtual
Returns
always BuiltinTypes::node;

Reimplemented from QPatternist::Expression.

Definition at line 194 of file qaxisstep.cpp.

195 {
196  return BuiltinTypes::node;
197 }
static const AnyNodeType::Ptr node

◆ expectedOperandTypes()

SequenceType::List AxisStep::expectedOperandTypes ( ) const
virtual
Returns
always an empty list since it has no operands.

Reimplemented from QPatternist::EmptyContainer.

Definition at line 182 of file qaxisstep.cpp.

183 {
184  SequenceType::List result;
186  return result;
187 }
static const SequenceType::Ptr ZeroOrMoreNodes
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

◆ id()

Expression::ID AxisStep::id ( ) const
virtual

This property, which has no setter, returns an enum value that uniquely identifies this Expression. Patternist makes no use of C++'s dynamic_cast feature, but uses this polymorphic function instead.

Returns
always IgnorableExpression.

Reimplemented from QPatternist::Expression.

Definition at line 242 of file qaxisstep.cpp.

◆ isAlwaysEmpty()

bool AxisStep::isAlwaysEmpty ( const QXmlNodeModelIndex::Axis  axis,
const QXmlNodeModelIndex::NodeKind  nodeKind 
)
staticprivate
Returns
true when the axis axis and a node test testing node of type nodeKind always produces an empty sequence. One such example is attribute::comment().

Definition at line 86 of file qaxisstep.cpp.

87 {
88  return (s_whenAxisNodeKindEmpty[(1 >> axis) - 1] & nodeKind) != 0;
89 }
static const QXmlNodeModelIndex::NodeKind s_whenAxisNodeKindEmpty[]
Definition: qaxisstep_p.h:139
QXmlNodeModelIndex::Axis axis() const
Definition: qaxisstep.cpp:204

◆ mapToItem()

Item AxisStep::mapToItem ( const QXmlNodeModelIndex node,
const DynamicContext::Ptr context 
) const
inline

Returns node if it matches the node test this step is using, otherwise null.

Definition at line 100 of file qaxisstep.cpp.

Referenced by evaluateSingleton().

102 {
103  Q_ASSERT(!node.isNull());
104  Q_ASSERT(Item(node).isNode());
105  Q_ASSERT(Item(node));
106  Q_UNUSED(context);
107 
108  if(m_nodeTest->itemMatches(Item(node)))
109  return Item(node);
110  else
111  return Item();
112 }
bool isNull() const
Returns true if this QXmlNodeModelIndex is a default constructed value, otherwise false...
virtual bool itemMatches(const Item &item) const =0
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
ItemType::Ptr m_nodeTest
Definition: qaxisstep_p.h:154
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ nodeTest()

ItemType::Ptr QPatternist::AxisStep::nodeTest ( ) const
inline
Returns
the node test this step is using.

Definition at line 112 of file qaxisstep_p.h.

Referenced by QPatternist::yyparse().

113  {
114  return m_nodeTest;
115  }
ItemType::Ptr m_nodeTest
Definition: qaxisstep_p.h:154

◆ patternPriority()

PatternPriority AxisStep::patternPriority ( ) const
virtual

By default 0.5 is returned.

Reimplemented from QPatternist::Expression.

Definition at line 237 of file qaxisstep.cpp.

238 {
239  return static_cast<const AnyNodeType *>(m_nodeTest.data())->patternPriority();
240 }
Represents the node() item type.
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
ItemType::Ptr m_nodeTest
Definition: qaxisstep_p.h:154
virtual PatternPriority patternPriority() const
Definition: qaxisstep.cpp:237

◆ properties()

Expression::Properties AxisStep::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 189 of file qaxisstep.cpp.

◆ setAxis()

void QPatternist::AxisStep::setAxis ( const QXmlNodeModelIndex::Axis  newAxis)
inline

Definition at line 157 of file qaxisstep_p.h.

Referenced by QPatternist::changeToTopAxis(), QPatternist::createPatternPath(), and QPatternist::yyparse().

158  {
159  m_axis = newAxis;
160  }
QXmlNodeModelIndex::Axis m_axis
Definition: qaxisstep_p.h:153

◆ setNodeTest()

void QPatternist::AxisStep::setNodeTest ( const ItemType::Ptr nev)
inline

Definition at line 117 of file qaxisstep_p.h.

Referenced by QPatternist::yyparse().

118  {
119  m_nodeTest = nev;
120  }
ItemType::Ptr m_nodeTest
Definition: qaxisstep_p.h:154

◆ staticType()

SequenceType::Ptr AxisStep::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 169 of file qaxisstep.cpp.

170 {
171  Cardinality cardinality;
172 
174  cardinality = Cardinality::zeroOrOne();
175  else
176  cardinality = Cardinality::zeroOrMore();
177 
178  return makeGenericSequenceType(m_nodeTest,
179  cardinality);
180 }
static Cardinality zeroOrMore()
ItemType::Ptr m_nodeTest
Definition: qaxisstep_p.h:154
static Cardinality zeroOrOne()
Represents a cardinality, a possible , often represented by occurrence indicators.
QXmlNodeModelIndex::Axis m_axis
Definition: qaxisstep_p.h:153

◆ typeCheck()

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

Rewrites to ParentNodeAxis, if possible.

Reimplemented from QPatternist::Expression.

Definition at line 153 of file qaxisstep.cpp.

155 {
157  {
158  /* We only rewrite parent::node() to ParentNodeAxis. */
159  return rewrite(Expression::Ptr(new ParentNodeAxis()), context)->typeCheck(context, reqType);
160  }
161  /* TODO temporarily disabled
162  else if(isAlwaysEmpty(m_axis, static_cast<const AnyNodeType *>(m_nodeTest.data())->nodeKind()))
163  return EmptySequence::create(this, context);
164  */
165  else
166  return EmptyContainer::typeCheck(context, reqType);
167 }
virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
Definition: qexpression.cpp:70
ItemType::Ptr m_nodeTest
Definition: qaxisstep_p.h:154
static void rewrite(Expression::Ptr &old, const Expression::Ptr &New, const StaticContext::Ptr &context)
static const AnyNodeType::Ptr node
Corresponds to the expression parent::node().
QXmlNodeModelIndex::Axis m_axis
Definition: qaxisstep_p.h:153

Properties

◆ m_axis

QXmlNodeModelIndex::Axis QPatternist::AxisStep::m_axis
private

The reason this variable is mutable, is that in the case of XSL-T patterns, we do quite some reordering.

Definition at line 153 of file qaxisstep_p.h.

Referenced by axis(), evaluateSequence(), evaluateSingleton(), staticType(), and typeCheck().

◆ m_nodeTest

ItemType::Ptr QPatternist::AxisStep::m_nodeTest
private

Definition at line 154 of file qaxisstep_p.h.

Referenced by AxisStep(), mapToItem(), patternPriority(), staticType(), and typeCheck().

◆ s_whenAxisNodeKindEmpty

const QXmlNodeModelIndex::NodeKind AxisStep::s_whenAxisNodeKindEmpty
staticprivate

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