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

Implements the node comparison operators >>, <<, and is. More...

#include <qnodecomparison_p.h>

Inheritance diagram for QPatternist::NodeComparison:
QPatternist::PairContainer 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)
 
virtual bool evaluateEBV (const DynamicContext::Ptr &) const
 
virtual Item evaluateSingleton (const DynamicContext::Ptr &) const
 
virtual SequenceType::List expectedOperandTypes () const
 
 NodeComparison (const Expression::Ptr &operand1, const QXmlNodeModelIndex::DocumentOrder op, const Expression::Ptr &operand2)
 
virtual QXmlNodeModelIndex::DocumentOrder operatorID () const
 
virtual SequenceType::Ptr staticType () const
 
- Public Functions inherited from QPatternist::PairContainer
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 Item::Iterator::Ptr evaluateSequence (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::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 ()
 

Static Public Functions

static QString displayName (const QXmlNodeModelIndex::DocumentOrder op)
 
- Static Public Functions inherited from QPatternist::Expression
static void rewrite (Expression::Ptr &old, const Expression::Ptr &New, const StaticContext::Ptr &context)
 

Private Types

enum  Result { Empty, True, False }
 

Private Functions

Result evaluate (const DynamicContext::Ptr &context) const
 

Properties

const QXmlNodeModelIndex::DocumentOrder m_op
 

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::PairContainer
 PairContainer (const Expression::Ptr &operand1, const Expression::Ptr &operand2)
 
- 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::PairContainer
Expression::Ptr m_operand1
 
Expression::Ptr m_operand2
 

Detailed Description

Implements the node comparison operators >>, <<, and is.

See also
XML Path Language (XPath) 2.0, 3.5.3 QXmlNodeModelIndex Comparisons
Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 72 of file qnodecomparison_p.h.

Enumerations

◆ Result

Enumerator
Empty 
True 
False 

Definition at line 110 of file qnodecomparison_p.h.

Constructors and Destructors

◆ NodeComparison()

NodeComparison::NodeComparison ( const Expression::Ptr operand1,
const QXmlNodeModelIndex::DocumentOrder  op,
const Expression::Ptr operand2 
)

Definition at line 55 of file qnodecomparison.cpp.

58  : PairContainer(operand1, operand2)
59  , m_op(op)
60 {
64 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
PairContainer(const Expression::Ptr &operand1, const Expression::Ptr &operand2)
const QXmlNodeModelIndex::DocumentOrder m_op

Functions

◆ accept()

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

Implements QPatternist::Expression.

Definition at line 179 of file qnodecomparison.cpp.

180 {
181  return visitor->visit(this);
182 }

◆ compress()

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

If any operator is the empty sequence, the NodeComparison rewrites into that, since the empty sequence is always the result in that case.

Reimplemented from QPatternist::Expression.

Definition at line 129 of file qnodecomparison.cpp.

130 {
131  const Expression::Ptr me(PairContainer::compress(context));
132 
133  if(me != this)
134  /* We're already rewritten. */
135  return me;
136 
139  {
140  // TODO issue a warning in the @p context saying that one of the operands
141  // were empty, and that the expression always result in the empty sequence
142  // (which never is the intent, right?).
143  return EmptySequence::create(this, context);
144  }
145 
146  return Expression::Ptr(this);
147 }
static Expression::Ptr create(const Expression *const replacementFor, const StaticContext::Ptr &context)
Creates an EmptySequence that is a replacement for replacementFor.
virtual Expression::Ptr compress(const StaticContext::Ptr &context)
virtual Cardinality cardinality() const =0
QExplicitlySharedDataPointer< Expression > Ptr
A smart pointer wrapping mutable Expression instances.
virtual SequenceType::Ptr staticType() const =0

◆ displayName()

QString NodeComparison::displayName ( const QXmlNodeModelIndex::DocumentOrder  op)
static

Determines the string representation for a node comparison operator.

Returns
  • "<<" if op is Precedes
  • ">>" if op is Follows
  • "is" if op is Is

Definition at line 149 of file qnodecomparison.cpp.

150 {
151  switch(op)
152  {
154  return QLatin1String("is");
156  return QLatin1String("<<");
157  default:
158  {
160  return QLatin1String(">>");
161  }
162  }
163 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

◆ evaluate()

NodeComparison::Result NodeComparison::evaluate ( const DynamicContext::Ptr context) const
inlineprivate

Definition at line 91 of file qnodecomparison.cpp.

Referenced by evaluateEBV(), and evaluateSingleton().

92 {
93  const Item op1(m_operand1->evaluateSingleton(context));
94  if(!op1)
95  return Empty;
96 
97  const Item op2(m_operand2->evaluateSingleton(context));
98  if(!op2)
99  return Empty;
100 
101  /* We just returns an arbitrary value, since there's no order defined for nodes from different
102  * models, except for that the return value must be stable. */
103  if(op1.asNode().model() != op2.asNode().model())
104  return False;
105 
106  switch(m_op)
107  {
109  return op1.asNode().is(op2.asNode()) ? True : False;
111  return op1.asNode().compareOrder(op2.asNode()) == QXmlNodeModelIndex::Precedes ? True : False;
112  default:
113  {
115  return op1.asNode().compareOrder(op2.asNode()) == QXmlNodeModelIndex::Follows ? True : False;
116  }
117  }
118 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
const QXmlNodeModelIndex::DocumentOrder m_op
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const

◆ evaluateEBV()

bool NodeComparison::evaluateEBV ( const DynamicContext::Ptr context) const
virtual

Determines the Effective Boolean Value of the expression.

The Effective Boolean Value of a value is not necessarily the same as converting the value to a new value of type xs:boolean.

Note that this function cannot return the empty sequence, evaluateSingleton() must be overridden in order to be able to do that.

The default implementation results in a type error. Hence, this function must be overridden if such behavior is not of interest.

See also
XML Path Language (XPath) 2.0, 2.4.3 Effective Boolean Value

Reimplemented from QPatternist::Expression.

Definition at line 79 of file qnodecomparison.cpp.

80 {
81  switch(evaluate(context))
82  {
83  case True:
84  return true;
85  default:
86  /* We include the empty sequence here. */
87  return false;
88  }
89 }
Result evaluate(const DynamicContext::Ptr &context) const

◆ evaluateSingleton()

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

Reimplemented from QPatternist::Expression.

Definition at line 66 of file qnodecomparison.cpp.

67 {
68  switch(evaluate(context))
69  {
70  case True:
72  case False:
74  default:
75  return Item();
76  }
77 }
static const AtomicValue::Ptr BooleanTrue
Result evaluate(const DynamicContext::Ptr &context) const
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
static const AtomicValue::Ptr BooleanFalse

◆ expectedOperandTypes()

SequenceType::List NodeComparison::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 121 of file qnodecomparison.cpp.

122 {
123  SequenceType::List result;
126  return result;
127 }
static const SequenceType::Ptr ZeroOrOneNode
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

◆ operatorID()

QXmlNodeModelIndex::DocumentOrder NodeComparison::operatorID ( ) const
virtual

Definition at line 174 of file qnodecomparison.cpp.

175 {
176  return m_op;
177 }
const QXmlNodeModelIndex::DocumentOrder m_op

◆ staticType()

SequenceType::Ptr NodeComparison::staticType ( ) const
virtual
Returns
either CommonSequenceTypes::ZeroOrOneBoolean or CommonSequenceTypes::ExactlyOneBoolean depending on the static cardinality of its operands.

Implements QPatternist::Expression.

Definition at line 165 of file qnodecomparison.cpp.

166 {
170  else
172 }
virtual Cardinality cardinality() const =0
static const SequenceType::Ptr ZeroOrOneBoolean
static const SequenceType::Ptr ExactlyOneBoolean
virtual SequenceType::Ptr staticType() const =0

Properties

◆ m_op

const QXmlNodeModelIndex::DocumentOrder QPatternist::NodeComparison::m_op
private

Definition at line 118 of file qnodecomparison_p.h.

Referenced by evaluate(), and operatorID().


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