Qt 4.8
Public Functions | List of all members
QPatternist::Existence< Id > Class Template Reference

Implements the functions fn:exists() and fn:empty(). More...

#include <qsequencefns_p.h>

Inheritance diagram for QPatternist::Existence< Id >:
QPatternist::FunctionCall QPatternist::UnlimitedContainer QPatternist::Expression QSharedData QPatternist::CppCastingHelper< Expression > QPatternist::SourceLocationReflection

Public Functions

virtual Expression::Ptr compress (const StaticContext::Ptr &context)
 
virtual bool evaluateEBV (const DynamicContext::Ptr &context) 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
 
virtual SequenceType::Ptr staticType () const
 
virtual Expression::Ptr typeCheck (const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
 
- 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)
 
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 Variables inherited from QPatternist::UnlimitedContainer
Expression::List m_operands
 

Detailed Description

template<const Expression::ID Id>
class QPatternist::Existence< Id >

Implements the functions fn:exists() and fn:empty().

Existence is a template value class. Appropriate implementations are achieved by instantiating it with either IDExistsFN or IDEmptyFN.

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

Definition at line 132 of file qsequencefns_p.h.

Functions

◆ compress()

template<const Expression::ID Id>
virtual Expression::Ptr QPatternist::Existence< Id >::compress ( const StaticContext::Ptr context)
inlinevirtual

Attempts to rewrite to false or true by looking at the static cardinality of its operand.

Reimplemented from QPatternist::Expression.

Definition at line 147 of file qsequencefns_p.h.

148  {
149  // RVCT doesn't like using template parameter in trinary operator when the trinary operator result is
150  // passed directly into another constructor.
151  Q_ASSERT(Id == IDExistsFN || Id == IDEmptyFN);
152 
153  const Expression::Ptr me(FunctionCall::compress(context));
154 
155  if(me != this)
156  return me;
157 
158  // RVCT doesn't like using template parameter in trinary operator when the trinary operator result is
159  // passed directly into another constructor.
160  Expression::ID tempId = Id;
161  const Cardinality myCard((tempId == IDExistsFN) ? Cardinality::oneOrMore() : Cardinality::empty());
162 
163  const Cardinality card(m_operands.first()->staticType()->cardinality());
164  if(myCard.isMatch(card))
165  { /* Since the dynamic type always is narrower than the static type or equal, and that the
166  static type is in scope, it means we will always be true. */
167  return wrapLiteral(CommonValues::BooleanTrue, context, this);
168  }
169  else
170  {
171  /* Is it even possible to hit? */
172  if(myCard.canMatch(card))
173  {
174  return me;
175  }
176  else
177  { /* We can never hit. */
178  return wrapLiteral(CommonValues::BooleanFalse, context, this);
179  }
180  }
181  }
static const AtomicValue::Ptr BooleanTrue
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual Expression::Ptr compress(const StaticContext::Ptr &context)
static Cardinality empty()
static Cardinality oneOrMore()
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.
static const AtomicValue::Ptr BooleanFalse

◆ evaluateEBV()

template<const Expression::ID Id>
virtual bool QPatternist::Existence< Id >::evaluateEBV ( const DynamicContext::Ptr context) const
inlinevirtual

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 135 of file qsequencefns_p.h.

136  {
137  if(Id == IDExistsFN)
138  return !m_operands.first()->evaluateSequence(context)->isEmpty();
139  else
140  return m_operands.first()->evaluateSequence(context)->isEmpty();
141  }
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282

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