Qt 4.8
Public Functions | List of all members
QPatternist::DeepEqualFN Class Reference

Implements the function fn:deep-equal(). More...

#include <qdeepequalfn_p.h>

Inheritance diagram for QPatternist::DeepEqualFN:
QPatternist::FunctionCall QPatternist::ComparisonPlatform< DeepEqualFN, false > QPatternist::UnlimitedContainer QPatternist::Expression QSharedData QPatternist::CppCastingHelper< Expression > QPatternist::SourceLocationReflection

Public Functions

 DeepEqualFN ()
 
virtual bool evaluateEBV (const DynamicContext::Ptr &context) const
 
AtomicComparator::Operator operatorID () 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 Item::Iterator::Ptr evaluateSequence (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 ()
 

Additional Inherited Members

- 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
 
- 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::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 Functions inherited from QPatternist::ComparisonPlatform< DeepEqualFN, false >
const AtomicComparator::Ptrcomparator () const
 
bool compare (const Item &i1, const Item &i2, const AtomicComparator::Ptr &comp, const AtomicComparator::Operator op) const
 Compares i1 and i2 with operator op, using comparator comp. All input arguments must be valid, and not null. More...
 
 ComparisonPlatform ()
 
AtomicComparator::ComparisonResult detailedFlexibleCompare (const Item &it1, const Item &it2, const DynamicContext::Ptr &context) const
 like flexibleCompare(), but returns the result as an AtomicComparator::Operator instead of bool. More...
 
AtomicComparator::Ptr fetchComparator (const ItemType::Ptr &type1, const ItemType::Ptr &type2, const ReportContext::Ptr &context) const
 
bool flexibleCompare (const Item &it1, const Item &it2, const DynamicContext::Ptr &context) const
 Compares it1 against it2, using comparator() and operatorID(). More...
 
void prepareComparison (const AtomicComparator::Ptr &comparator)
 
void useCaseInsensitiveComparator ()
 
- Protected Variables inherited from QPatternist::UnlimitedContainer
Expression::List m_operands
 

Detailed Description

Implements the function fn:deep-equal().

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

Definition at line 71 of file qdeepequalfn_p.h.

Constructors and Destructors

◆ DeepEqualFN()

QPatternist::DeepEqualFN::DeepEqualFN ( )
inline

Definition at line 75 of file qdeepequalfn_p.h.

75  : ComparisonPlatform<DeepEqualFN, false>()
76  {
77  }

Functions

◆ evaluateEBV()

bool DeepEqualFN::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 54 of file qdeepequalfn.cpp.

Referenced by DeepEqualFN().

55 {
57  const Item::Iterator::Ptr it2(m_operands.at(1)->evaluateSequence(context));
58 
59  while(true)
60  {
61  const Item item1(it1->next());
62  const Item item2(it2->next());
63 
64  if(!item1)
65  {
66  if(item2)
67  return false;
68  else
69  return true;
70  }
71  else if(!item2)
72  {
73  if(item1)
74  return false;
75  else
76  return true;
77  }
78  else if(item1.isNode())
79  {
80  if(item2.isNode())
81  {
82  if(item1.asNode().isDeepEqual(item2.asNode()))
83  continue;
84  else
85  return false;
86  }
87  else
88  return false;
89  }
90  else if(item2.isNode())
91  {
92  /* We know that item1 is not a node due to the check above. */
93  return false;
94  }
95  else if(flexibleCompare(item1, item2, context))
96  continue;
97  else if(BuiltinTypes::numeric->itemMatches(item1) &&
98  item1.as<Numeric>()->isNaN() &&
99  item2.as<Numeric>()->isNaN())
100  {
101  // TODO
102  /* Handle the specific NaN circumstances. item2 isn't checked whether it's of
103  * type numeric, since the AtomicComparator lookup would have failed if both weren't
104  * numeric. */
105  continue;
106  }
107  else
108  return false;
109  };
110 }
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
const TCastTarget * as() const
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
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
Base class for all numeric values.
static const AtomicType::Ptr numeric
bool flexibleCompare(const Item &it1, const Item &it2, const DynamicContext::Ptr &context) const
Compares it1 against it2, using comparator() and operatorID().
virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const

◆ operatorID()

AtomicComparator::Operator QPatternist::DeepEqualFN::operatorID ( ) const
inline

◆ typeCheck()

Expression::Ptr DeepEqualFN::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 112 of file qdeepequalfn.cpp.

Referenced by DeepEqualFN().

114 {
115  const Expression::Ptr me(FunctionCall::typeCheck(context, reqType));
117  const ItemType::Ptr t2(m_operands.at(1)->staticType()->itemType());
118  /* TODO This can be much more improved, and the optimizations should be moved
119  * to compress(). */
120 
121  if(*CommonSequenceTypes::Empty == *t1)
122  {
123  if(*CommonSequenceTypes::Empty == *t2)
124  return wrapLiteral(CommonValues::BooleanTrue, context, this);
125  else
126  return me;
127  }
128  else if(*CommonSequenceTypes::Empty == *t2)
129  {
130  if(*CommonSequenceTypes::Empty == *t1)
131  return wrapLiteral(CommonValues::BooleanTrue, context, this);
132  else
133  return me;
134  }
135  else if(BuiltinTypes::node->xdtTypeMatches(t1) &&
136  BuiltinTypes::node->xdtTypeMatches(t2))
137  return me; /* We're comparing nodes. */
138  else if(BuiltinTypes::xsAnyAtomicType->xdtTypeMatches(t1) &&
139  BuiltinTypes::xsAnyAtomicType->xdtTypeMatches(t2))
140  {
141  prepareComparison(fetchComparator(t1, t2, context));
142  return me;
143  }
144  else
145  {
146  if ((BuiltinTypes::node->xdtTypeMatches(t1) && BuiltinTypes::xsAnyAtomicType->xdtTypeMatches(t2))
147  || (BuiltinTypes::node->xdtTypeMatches(t2) && BuiltinTypes::xsAnyAtomicType->xdtTypeMatches(t1)))
148  {
149  /* One operand contains nodes and the other atomic values, or vice versa. They can never
150  * be identical. */
151  // TODO warn?
152  return wrapLiteral(CommonValues::BooleanFalse, context, this);
153  }
154  else
155  {
156  // TODO Warn?
157  return me;
158  }
159  }
160 }
virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
static const AtomicValue::Ptr BooleanTrue
AtomicComparator::Ptr fetchComparator(const ItemType::Ptr &type1, const ItemType::Ptr &type2, const ReportContext::Ptr &context) const
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static const AnyNodeType::Ptr node
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
virtual SequenceType::Ptr staticType() const =0
static const EmptySequenceType::Ptr Empty
static const AtomicType::Ptr xsAnyAtomicType
virtual ItemType::Ptr itemType() const =0
static const AtomicValue::Ptr BooleanFalse
void prepareComparison(const AtomicComparator::Ptr &comparator)

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