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

Implements XPath 2.0's to expression. More...

#include <qrangeexpression_p.h>

Inheritance diagram for QPatternist::RangeExpression:
QPatternist::PairContainer QPatternist::Expression QSharedData QPatternist::CppCastingHelper< Expression > QPatternist::SourceLocationReflection

Public Functions

virtual ExpressionVisitorResult::Ptr accept (const ExpressionVisitor::Ptr &visitor) const
 
virtual Item::Iterator::Ptr evaluateSequence (const DynamicContext::Ptr &) const
 
virtual Item evaluateSingleton (const DynamicContext::Ptr &) const
 
virtual SequenceType::List expectedOperandTypes () const
 
virtual Expression::Properties properties () const
 
 RangeExpression (const Expression::Ptr &operand1, const Expression::Ptr &operand2)
 
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)
 
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
 
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
 
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 ()
 

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
 
- 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::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 XPath 2.0's to expression.

Despite its name, RangeExpression is not related to RangeVariableDeclaration.

See also
XML Path Language (XPath) 2.0, 3.3.1 Constructing Sequences
RangeIterator
Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 75 of file qrangeexpression_p.h.

Constructors and Destructors

◆ RangeExpression()

RangeExpression::RangeExpression ( const Expression::Ptr operand1,
const Expression::Ptr operand2 
)

Definition at line 56 of file qrangeexpression.cpp.

57  : PairContainer(operand1, operand2)
58 {
59 }
PairContainer(const Expression::Ptr &operand1, const Expression::Ptr &operand2)

Functions

◆ accept()

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

Implements QPatternist::Expression.

Definition at line 165 of file qrangeexpression.cpp.

166 {
167  return visitor->visit(this);
168 }

◆ evaluateSequence()

Item::Iterator::Ptr RangeExpression::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 61 of file qrangeexpression.cpp.

62 {
63  const Item s(m_operand1->evaluateSingleton(context));
64 
65  if(!s)
67 
68  const Item e(m_operand2->evaluateSingleton(context));
69  if(!e)
71 
72  const xsInteger start = s.as<Numeric>()->toInteger();
73  const xsInteger end = e.as<Numeric>()->toInteger();
74 
75  if(start > end)
77  else if(start == end)
78  return makeSingletonIterator(s);
79  else
81 }
qint64 xsInteger
static const EmptyIterator< Item >::Ptr emptyIterator
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< Item > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.
RangeIterator represents a sequence of integers between a start and end value.
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
Base class for all numeric values.
static const KeyPair *const end
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const

◆ evaluateSingleton()

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

It's likely that this function gets called if staticType() inferred the cardinality to an exact number. In that case, we know that the first arguments is the same as the second argument.

Reimplemented from QPatternist::Expression.

Definition at line 83 of file qrangeexpression.cpp.

84 {
85  return m_operand1->evaluateSingleton(context);
86 }
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const

◆ expectedOperandTypes()

SequenceType::List RangeExpression::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 88 of file qrangeexpression.cpp.

89 {
90  SequenceType::List result;
93  return result;
94 }
static const SequenceType::Ptr ZeroOrOneInteger
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

◆ properties()

Expression::Properties RangeExpression::properties ( ) const
virtual

Disables compression for optimization reasons. For example, the expression "1 to 1000" would consume thousand allocated instances of Integer, and RangeIterator is well suited for dynamic evaluation.

Returns
Expression::DisableElimination

Reimplemented from QPatternist::Expression.

Definition at line 160 of file qrangeexpression.cpp.

◆ staticType()

SequenceType::Ptr RangeExpression::staticType ( ) const
virtual
Returns
always CommonSequenceTypes::ZeroOrMoreIntegers

Implements QPatternist::Expression.

Definition at line 96 of file qrangeexpression.cpp.

97 {
98  /* This logic makes the Cardinality more specific. */
99  Cardinality::Count from;
100  bool hasFrom;
101 
103  {
104  from = m_operand1->as<Literal>()->item().as<Integer>()->toInteger();
105  hasFrom = true;
106  }
107  else
108  {
109  hasFrom = false;
110  from = 0;
111  }
112 
113  /* We can't check whether to is -1 since maybe the user wrote -1. Hence
114  * hasTo is required. */
115  bool hasTo;
117 
119  {
120  const xsInteger asInt = m_operand2->as<Literal>()->item().as<Integer>()->toInteger();
121  to = asInt;
122 
123  if(to == asInt)
124  hasTo = true;
125  else
126  {
127  /* Cardinality::Count is not the same as type xsInteger. We had overflow. */
128  to = -1;
129  hasTo = false;
130  }
131  }
132  else
133  {
134  to = -1;
135  hasTo = false;
136  }
137 
138  if(hasTo && hasFrom)
139  {
140  if(from > to)
141  {
142  /* The query is incorrectly written, we'll evaluate to the empty sequence.
143  * Just return what's correct. */
145  }
146  else
147  {
148  Cardinality::Count count = (to - from) + 1; /* + 1, since it's inclusive. */
149  return makeGenericSequenceType(BuiltinTypes::xsInteger, Cardinality::fromExact(count));
150  }
151  }
152  else
153  {
154  /* We can't do fromExact(from, -1) since the latter can evaluate to a value that actually is
155  * lower than from, although that unfortunately is very unlikely. */
157  }
158 }
qint64 xsInteger
static Cardinality fromExact(const Count count)
static const SequenceType::Ptr ZeroOrMoreIntegers
const TCastTarget * as() const
Houses an AtomicValue, making it available as an Expression.
Definition: qliteral_p.h:74
static const AtomicType::Ptr xsInteger
Implements the value instance of the xs:integer type.
Definition: qinteger_p.h:70
bool is(const ID id) const

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