Qt 4.8
Public Functions | Static Public Functions | Properties | List of all members
QPatternist::ValueComparison Class Reference

Implements XPath 2.0 value comparions, such as the eq operator. More...

#include <qvaluecomparison_p.h>

Inheritance diagram for QPatternist::ValueComparison:
QPatternist::PairContainer QPatternist::ComparisonPlatform< ValueComparison, true > 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 Item evaluateSingleton (const DynamicContext::Ptr &) const
 
virtual SequenceType::List expectedOperandTypes () const
 
virtual ID id () const
 
AtomicComparator::Operator operatorID () const
 
virtual QList< QExplicitlySharedDataPointer< OptimizationPass > > optimizationPasses () const
 
virtual SequenceType::Ptr staticType () const
 
virtual Expression::Ptr typeCheck (const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
 
 ValueComparison (const Expression::Ptr &op1, const AtomicComparator::Operator op, const Expression::Ptr &op2)
 
- 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 bool evaluateEBV (const DynamicContext::Ptr &context) 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
 
bool is (const ID id) const
 
bool isEvaluated () const
 
virtual ItemType::Ptr newFocusType () 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 ()
 

Static Public Functions

static bool isCaseInsensitiveCompare (Expression::Ptr &op1, Expression::Ptr &op2)
 
- Static Public Functions inherited from QPatternist::Expression
static void rewrite (Expression::Ptr &old, const Expression::Ptr &New, const StaticContext::Ptr &context)
 

Properties

const AtomicComparator::Operator m_operator
 

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 Functions inherited from QPatternist::ComparisonPlatform< ValueComparison, true >
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::PairContainer
Expression::Ptr m_operand1
 
Expression::Ptr m_operand2
 

Detailed Description

Implements XPath 2.0 value comparions, such as the eq operator.

ComparisonPlatform is inherited with protected scope because ComparisonPlatform must access members of ValueComparison.

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

Definition at line 77 of file qvaluecomparison_p.h.

Constructors and Destructors

◆ ValueComparison()

ValueComparison::ValueComparison ( const Expression::Ptr op1,
const AtomicComparator::Operator  op,
const Expression::Ptr op2 
)

Definition at line 55 of file qvaluecomparison.cpp.

57  : PairContainer(op1, op2),
58  m_operator(op)
59 {
60 }
const AtomicComparator::Operator m_operator
PairContainer(const Expression::Ptr &operand1, const Expression::Ptr &operand2)

Functions

◆ accept()

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

Implements QPatternist::Expression.

Definition at line 153 of file qvaluecomparison.cpp.

154 {
155  return visitor->visit(this);
156 }

◆ compress()

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

Overridden to optimize case-insensitive compares.

Reimplemented from QPatternist::Expression.

Definition at line 97 of file qvaluecomparison.cpp.

98 {
99  const Expression::Ptr me(PairContainer::compress(context));
100 
101  if(me != this)
102  return me;
103 
106 
107  return me;
108 }
virtual Expression::Ptr compress(const StaticContext::Ptr &context)
static bool isCaseInsensitiveCompare(Expression::Ptr &op1, Expression::Ptr &op2)

◆ evaluateSingleton()

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

Reimplemented from QPatternist::Expression.

Definition at line 62 of file qvaluecomparison.cpp.

63 {
64  const Item it1(m_operand1->evaluateSingleton(context));
65  if(!it1)
66  return Item();
67 
68  const Item it2(m_operand2->evaluateSingleton(context));
69  if(!it2)
70  return Item();
71 
72  return Boolean::fromValue(flexibleCompare(it1, it2, context));
73 }
static Boolean::Ptr fromValue(const bool value)
Definition: qboolean.cpp:115
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
bool flexibleCompare(const Item &it1, const Item &it2, const DynamicContext::Ptr &context) const
Compares it1 against it2, using comparator() and operatorID().
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const

◆ expectedOperandTypes()

SequenceType::List ValueComparison::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 136 of file qvaluecomparison.cpp.

137 {
138  SequenceType::List result;
141  return result;
142 }
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
static const SequenceType::Ptr ZeroOrOneAtomicType
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ id()

Expression::ID ValueComparison::id ( ) const
virtual
Returns
IDValueComparison

Reimplemented from QPatternist::Expression.

Definition at line 158 of file qvaluecomparison.cpp.

◆ isCaseInsensitiveCompare()

bool ValueComparison::isCaseInsensitiveCompare ( Expression::Ptr op1,
Expression::Ptr op2 
)
static

It is considered that the string value from op1 will be compared against op2. This function determines whether the user intends the comparison to be case insensitive. If that is the case true is returned, and the operands are re-written appropriately.

This is a helper function for Expression classes that compares strings.

See also
ComparisonPlatform::useCaseInsensitiveComparator()

Definition at line 110 of file qvaluecomparison.cpp.

Referenced by QPatternist::ComparesCaseAware::compress(), compress(), QPatternist::GeneralComparison::compress(), and operatorID().

111 {
112  Q_ASSERT(op1);
113  Q_ASSERT(op2);
114 
115  const ID iD = op1->id();
116 
117  if((iD == IDLowerCaseFN || iD == IDUpperCaseFN) && iD == op2->id())
118  {
119  /* Both are either fn:lower-case() or fn:upper-case(). */
120 
121  /* Replace the calls to the functions with its operands. */
122  op1 = op1->operands().first();
123  op2 = op2->operands().first();
124 
125  return true;
126  }
127  else
128  return false;
129 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual ID id() const
virtual Expression::List operands() const =0
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282

◆ operatorID()

AtomicComparator::Operator QPatternist::ValueComparison::operatorID ( ) const
inline
Returns
the operator that this ValueComparison is using.

Definition at line 113 of file qvaluecomparison_p.h.

Referenced by QPatternist::ComparisonIdentifier::matches().

114  {
115  return m_operator;
116  }
const AtomicComparator::Operator m_operator

◆ optimizationPasses()

OptimizationPass::List ValueComparison::optimizationPasses ( ) const
virtual

Returns the OptimizationPasses that applies for this Expression. The default implementation returns an empty list. Sub-classes can re-implement this function and return actual OptimizationPasses.

Returns
always an empty list.

Reimplemented from QPatternist::Expression.

Definition at line 131 of file qvaluecomparison.cpp.

132 {
134 }
OptimizationPass::List comparisonPasses

◆ staticType()

SequenceType::Ptr ValueComparison::staticType ( ) const
virtual
Returns
always CommonSequenceTypes::ExactlyOneBoolean

Implements QPatternist::Expression.

Definition at line 144 of file qvaluecomparison.cpp.

145 {
149  else
151 }
virtual Cardinality cardinality() const =0
static const SequenceType::Ptr ZeroOrOneBoolean
static const SequenceType::Ptr ExactlyOneBoolean
virtual SequenceType::Ptr staticType() const =0

◆ typeCheck()

Expression::Ptr ValueComparison::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::Expression.

Definition at line 75 of file qvaluecomparison.cpp.

77 {
78  const Expression::Ptr me(PairContainer::typeCheck(context, reqType));
81  Q_ASSERT(t1);
82  Q_ASSERT(t2);
83 
84  if(*CommonSequenceTypes::Empty == *t1 ||
86  {
87  return EmptySequence::create(this, context);
88  }
89  else
90  {
91  prepareComparison(fetchComparator(t1, t2, context));
92 
93  return me;
94  }
95 }
virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
Definition: qexpression.cpp:70
static Expression::Ptr create(const Expression *const replacementFor, const StaticContext::Ptr &context)
Creates an EmptySequence that is a replacement for replacementFor.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
AtomicComparator::Ptr fetchComparator(const ItemType::Ptr &type1, const ItemType::Ptr &type2, const ReportContext::Ptr &context) const
virtual SequenceType::Ptr staticType() const =0
static const EmptySequenceType::Ptr Empty
virtual ItemType::Ptr itemType() const =0
void prepareComparison(const AtomicComparator::Ptr &comparator)

Properties

◆ m_operator

const AtomicComparator::Operator QPatternist::ValueComparison::m_operator
private

Definition at line 130 of file qvaluecomparison_p.h.

Referenced by operatorID().


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