Qt 4.8
Public Functions | Private Functions | List of all members
QPatternist::ComparingAggregator< oper, result > Class Template Reference

Base class for the implementations of the fn:min() and fn:max() function. More...

#include <qcomparingaggregator_p.h>

Inheritance diagram for QPatternist::ComparingAggregator< oper, result >:
QPatternist::Aggregator QPatternist::ComparisonPlatform< ComparingAggregator< oper, result >, true, AtomicComparator::AsValueComparison, ReportContext::FORG0006 > QPatternist::CastingPlatform< ComparingAggregator< oper, result >, true > QPatternist::FunctionCall QPatternist::UnlimitedContainer QPatternist::Expression QSharedData QPatternist::CppCastingHelper< Expression > QPatternist::SourceLocationReflection

Public Functions

virtual Item evaluateSingleton (const DynamicContext::Ptr &context) const
 
AtomicComparator::Operator operatorID () const
 
ItemType::Ptr targetType () const
 
virtual Expression::Ptr typeCheck (const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
 
- Public Functions inherited from QPatternist::Aggregator
virtual SequenceType::Ptr staticType () const
 
- 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
 
- 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::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 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 Functions

Item applyNumericPromotion (const Item &old, const Item &nev, const Item &newVal) const
 

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< ComparingAggregator< oper, result >, true, AtomicComparator::AsValueComparison, ReportContext::FORG0006 >
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 Functions inherited from QPatternist::CastingPlatform< ComparingAggregator< oper, result >, true >
Item cast (const Item &sourceValue, const ReportContext::Ptr &context) const
 
 CastingPlatform (const ReportContext::ErrorCode code=ReportContext::FORG0001)
 
void checkTargetType (const ReportContext::Ptr &context) const
 
bool prepareCasting (const ReportContext::Ptr &context, const ItemType::Ptr &sourceType)
 
- Protected Variables inherited from QPatternist::UnlimitedContainer
Expression::List m_operands
 

Detailed Description

template<AtomicComparator::Operator oper, AtomicComparator::ComparisonResult result>
class QPatternist::ComparingAggregator< oper, result >

Base class for the implementations of the fn:min() and fn:max() function.

What function that more specifically is followed, depends on how the constructor is called.

See also
MaxFN
MinFN
Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 88 of file qcomparingaggregator_p.h.

Functions

◆ applyNumericPromotion()

template<AtomicComparator::Operator oper, AtomicComparator::ComparisonResult result>
Item QPatternist::ComparingAggregator< oper, result >::applyNumericPromotion ( const Item old,
const Item nev,
const Item newVal 
) const
inlineprivate

Definition at line 50 of file qcomparingaggregator.cpp.

Referenced by QPatternist::ComparingAggregator< oper, result >::targetType().

53 {
54  Q_ASSERT(old);
55  Q_ASSERT(nev);
56  Q_ASSERT(newVal);
57  const ItemType::Ptr to(old.type());
58  const ItemType::Ptr tn(nev.type());
59 
60  if(!(BuiltinTypes::numeric->xdtTypeMatches(to) && BuiltinTypes::numeric->xdtTypeMatches(tn)))
61  return newVal; /* At least one of them isn't numeric. */
62  else if(BuiltinTypes::xsDouble->xdtTypeMatches(to) || BuiltinTypes::xsDouble->xdtTypeMatches(tn))
63  return toItem(Double::fromValue(newVal.as<Numeric>()->toDouble()));
64  else if(BuiltinTypes::xsFloat->xdtTypeMatches(to) || BuiltinTypes::xsFloat->xdtTypeMatches(tn))
65  return toItem(Float::fromValue(newVal.as<Numeric>()->toDouble()));
66  else if(BuiltinTypes::xsInteger->xdtTypeMatches(to) &&
67  BuiltinTypes::xsInteger->xdtTypeMatches(tn))
68  return newVal; /* Both must be xs:integer. */
69  else
70  return toItem(Decimal::fromValue(newVal.as<Numeric>()->toDecimal()));
71 }
Item toItem(const QExplicitlySharedDataPointer< T > atomicValue)
Definition: qitem_p.h:431
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static const AtomicType::Ptr xsDouble
static Decimal::Ptr fromValue(const xsDecimal num)
Definition: qdecimal.cpp:59
QExplicitlySharedDataPointer< ItemType > Ptr
Definition: qitemtype_p.h:88
static const AtomicType::Ptr xsFloat
static Numeric::Ptr fromValue(const xsDouble num)
static const AtomicType::Ptr numeric
static const AtomicType::Ptr xsInteger

◆ evaluateSingleton()

template<AtomicComparator::Operator oper, AtomicComparator::ComparisonResult result>
Item QPatternist::ComparingAggregator< oper, result >::evaluateSingleton ( const DynamicContext::Ptr context) const
virtual

Reimplemented from QPatternist::Expression.

Definition at line 75 of file qcomparingaggregator.cpp.

76 {
77  const Item::Iterator::Ptr it(m_operands.first()->evaluateSequence(context));
78  Item largest;
79 
80  while(true)
81  {
82  Item next(it->next());
83 
84  if(!next)
85  {
86  return largest;
87  }
88 
90 
91  if(!comp)
92  {
93  ItemType::Ptr t1(next.type());
94  Q_ASSERT(t1);
95 
96  if(BuiltinTypes::xsUntypedAtomic->xdtTypeMatches(t1))
97  {
98  next = cast(next, context);
100  }
101 
102  if(!largest)
103  {
104  largest = next;
105  continue;
106  }
107 
108  Q_ASSERT(largest);
109  comp = fetchComparator(largest.type(), t1, context);
110  Q_ASSERT(comp);
111  }
112  else if(!largest)
113  {
114  largest = next;
115  continue;
116  }
117 
118  if(comp->compare(next, operatorID(), largest) == result)
119  {
120  largest = applyNumericPromotion(largest, next, next);
121  continue;
122  }
123 
124  const ItemType::Ptr t(next.type());
125 
126  if(BuiltinTypes::xsDouble->xdtTypeMatches(t) &&
127  next.as<Numeric>()->isNaN())
128  {
130  }
131  else if(BuiltinTypes::xsFloat->xdtTypeMatches(t) &&
132  next.as<Numeric>()->isNaN())
133  {
134  if(BuiltinTypes::xsDouble->xdtTypeMatches(largest.type()))
136 
137  /* If we have a xs:double somewhere, we must promote the NaN value to xs:double,
138  * and we really should raise error on invalid value. */
139  largest = it->next();
140 
141  while(largest)
142  {
143  const ItemType::Ptr tf(largest.type());
144  if(BuiltinTypes::xsDouble->xdtTypeMatches(tf))
146  else if(BuiltinTypes::xsUntypedAtomic->xdtTypeMatches(tf))
147  {
148  /* Attempt a convert, which will raise an error if it doesn't work out. */
149  cast(largest, context);
151  }
152  else if(!BuiltinTypes::numeric->xdtTypeMatches(tf))
153  {
155  }
156  else
157  largest = it->next();
158  };
159 
160  return CommonValues::FloatNaN;
161  }
162  else
163  largest = applyNumericPromotion(largest, next, largest);
164  }
165 }
Item cast(const Item &sourceValue, const ReportContext::Ptr &context) const
#define it(className, varName)
static const AtomicValue::Ptr DoubleNaN
static const AtomicValue::Ptr FloatNaN
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
AtomicComparator::Ptr fetchComparator(const ItemType::Ptr &type1, const ItemType::Ptr &type2, const ReportContext::Ptr &context) const
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< Item > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.
static const AtomicType::Ptr xsDouble
The Item is the most basic of all visual items in QML.
QExplicitlySharedDataPointer< AtomicComparator > Ptr
static const AtomicType::Ptr xsUntypedAtomic
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
QExplicitlySharedDataPointer< ItemType > Ptr
Definition: qitemtype_p.h:88
static const AtomicType::Ptr xsFloat
static const AtomicType::Ptr numeric
AtomicComparator::Operator operatorID() const
Item applyNumericPromotion(const Item &old, const Item &nev, const Item &newVal) const

◆ operatorID()

template<AtomicComparator::Operator oper, AtomicComparator::ComparisonResult result>
AtomicComparator::Operator QPatternist::ComparingAggregator< oper, result >::operatorID ( ) const
inline

Definition at line 99 of file qcomparingaggregator_p.h.

100  {
101  return oper;
102  }

◆ targetType()

template<AtomicComparator::Operator oper, AtomicComparator::ComparisonResult result>
ItemType::Ptr QPatternist::ComparingAggregator< oper, result >::targetType ( ) const
inline

Definition at line 104 of file qcomparingaggregator_p.h.

105  {
106  return BuiltinTypes::xsDouble;
107  }
static const AtomicType::Ptr xsDouble

◆ typeCheck()

template<AtomicComparator::Operator oper, AtomicComparator::ComparisonResult result>
Expression::Ptr QPatternist::ComparingAggregator< oper, result >::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 169 of file qcomparingaggregator.cpp.

171 {
174  const Expression::Ptr me(FunctionCall::typeCheck(context, reqType));
175 
176  ItemType::Ptr t1(m_operands.first()->staticType()->itemType());
177 
178  if(*CommonSequenceTypes::Empty == *t1)
179  return EmptySequence::create(this, context);
180  else if(*BuiltinTypes::xsAnyAtomicType == *t1 ||
181  BuiltinTypes::numeric->xdtTypeMatches(t1))
182  return me;
183  else if(BuiltinTypes::xsUntypedAtomic->xdtTypeMatches(t1))
184  {
185  m_operands.replace(0, Expression::Ptr(new UntypedAtomicConverter(m_operands.first(),
187  t1 = m_operands.first()->staticType()->itemType();
188  }
189  else if(!BuiltinTypes::xsString->xdtTypeMatches(t1) &&
190  !BuiltinTypes::xsAnyURI->xdtTypeMatches(t1) &&
191  !BuiltinTypes::xsDayTimeDuration->xdtTypeMatches(t1) &&
192  !BuiltinTypes::xsDate->xdtTypeMatches(t1) &&
193  !BuiltinTypes::xsTime->xdtTypeMatches(t1) &&
194  !BuiltinTypes::xsDateTime->xdtTypeMatches(t1) &&
195  !BuiltinTypes::xsYearMonthDuration->xdtTypeMatches(t1))
196  {
197  context->error(QtXmlPatterns::tr("The first argument to %1 cannot be of type %2.")
198  .arg(QPatternist::formatFunction(context->namePool(), signature()))
199  .arg(formatType(context->namePool(), m_operands.first()->staticType())),
201  return me;
202  }
203 
204  if(!m_operands.first()->staticType()->cardinality().allowsMany())
205  return m_operands.first();
206 
207  // explicit scope needed in RVCT
209 
210  return me;
211 }
virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
static const AtomicType::Ptr xsDayTimeDuration
QString formatType(const NamePool::Ptr &np, const T &type)
Formats ItemType and SequenceType.
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
static const AtomicType::Ptr xsYearMonthDuration
AtomicComparator::Ptr fetchComparator(const ItemType::Ptr &type1, const ItemType::Ptr &type2, const ReportContext::Ptr &context) const
static const AtomicType::Ptr xsString
static QString formatFunction(const NamePool::Ptr &np, const FunctionSignature::Ptr &func)
Formats FunctionSignature.
static const AtomicType::Ptr xsDateTime
static const AtomicType::Ptr xsDouble
virtual FunctionSignature::Ptr signature() const
void replace(int i, const T &t)
Replaces the item at index position i with value.
Definition: qlist.h:609
static const AtomicType::Ptr xsUntypedAtomic
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
QExplicitlySharedDataPointer< Expression > Ptr
A smart pointer wrapping mutable Expression instances.
QExplicitlySharedDataPointer< ItemType > Ptr
Definition: qitemtype_p.h:88
static const EmptySequenceType::Ptr Empty
static const AtomicType::Ptr numeric
static const AtomicType::Ptr xsTime
static const AtomicType::Ptr xsAnyAtomicType
static const AtomicType::Ptr xsDate
static const AtomicType::Ptr xsAnyURI

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