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

Implements XPath 2.0's instance of expression. More...

#include <qinstanceof_p.h>

Inheritance diagram for QPatternist::InstanceOf:
QPatternist::SingleContainer 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 bool evaluateEBV (const DynamicContext::Ptr &) const
 
virtual SequenceType::List expectedOperandTypes () const
 
 InstanceOf (const Expression::Ptr &operand, const SequenceType::Ptr &targetType)
 
virtual SequenceType::Ptr staticType () const
 
SequenceType::Ptr targetType () const
 
- Public Functions inherited from QPatternist::SingleContainer
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 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
 
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
 
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::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 ()
 

Properties

const SequenceType::Ptr m_targetType
 

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::SingleContainer
 SingleContainer (const Expression::Ptr &operand)
 
- 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::SingleContainer
Expression::Ptr m_operand
 

Detailed Description

Implements XPath 2.0's instance of expression.

See also
XML Path Language (XPath) 2.0, 3.10.1 Instance Of
Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 72 of file qinstanceof_p.h.

Constructors and Destructors

◆ InstanceOf()

InstanceOf::InstanceOf ( const Expression::Ptr operand,
const SequenceType::Ptr targetType 
)

Definition at line 53 of file qinstanceof.cpp.

54  : SingleContainer(operand)
55  , m_targetType(tType)
56 {
58 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
SingleContainer(const Expression::Ptr &operand)
const SequenceType::Ptr m_targetType
Definition: qinstanceof_p.h:93

Functions

◆ accept()

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

Implements QPatternist::Expression.

Definition at line 124 of file qinstanceof.cpp.

125 {
126  return visitor->visit(this);
127 }

◆ compress()

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

compress() is the last stage performs in compiling an expression, done after the initial AST build and calling typeCheck(). compress() performs crucial simplifications, either by having drastic performance implications or that some expressions depend on it for proper behavior.

The default implementation performs a sparse conditional constant propagation. In short, a recursive process is performed in the AST which examines if the Expression's operands are constant values, and if so, performs a const fold(AST rewrite) into the result of evaluating the expression in question. This default behavior can be disabled by letting properties() return DisableElimination.

This compress() stage can be relative effective due to the design of XPath, in part because intrinsic functions are heavily used. Many Expressions override compress() and do optimizations specific to what they do. Also, many Expressions performs optimizations in their typeCheck().

Parameters
contextthe static context. Supplies compile time information, and is the channel for communicating error messages.
See also
Wikipedia, the free encyclopedia, Sparse conditional constant propagation
Wikipedia, the free encyclopedia, Intrinsic function
Wikipedia, the free encyclopedia, Compiler optimization

Reimplemented from QPatternist::Expression.

Definition at line 84 of file qinstanceof.cpp.

85 {
86  const Expression::Ptr me(SingleContainer::compress(context));
87 
88  if(me != this || m_operand->has(DisableTypingDeduction))
89  return me;
90 
91  const SequenceType::Ptr opType(m_operand->staticType());
93  const ItemType::Ptr operandType(opType->itemType());
94 
95  if(m_targetType->cardinality().isMatch(opType->cardinality()))
96  {
97  if(*operandType == *CommonSequenceTypes::Empty || targetType->xdtTypeMatches(operandType))
98  return wrapLiteral(CommonValues::BooleanTrue, context, this);
99  else if(!operandType->xdtTypeMatches(targetType))
100  return wrapLiteral(CommonValues::BooleanFalse, context, this);
101  }
102  /* Optimization: rule out the case where instance of will always fail. */
103 
104  return me;
105 }
static const AtomicValue::Ptr BooleanTrue
bool has(const Property prop) const
virtual Expression::Ptr compress(const StaticContext::Ptr &context)
virtual Cardinality cardinality() const =0
virtual SequenceType::Ptr staticType() const =0
static const EmptySequenceType::Ptr Empty
SequenceType::Ptr targetType() const
virtual ItemType::Ptr itemType() const =0
bool isMatch(const Cardinality &other) const
static const AtomicValue::Ptr BooleanFalse
const SequenceType::Ptr m_targetType
Definition: qinstanceof_p.h:93

◆ evaluateEBV()

bool InstanceOf::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 60 of file qinstanceof.cpp.

61 {
63  Item item(it->next());
64  unsigned int count = 1;
65 
66  if(!item)
68 
69  do
70  {
71  if(!m_targetType->itemType()->itemMatches(item))
72  return false;
73 
74  if(count == 2 && !m_targetType->cardinality().allowsMany())
75  return false;
76 
77  item = it->next();
78  ++count;
79  } while(item);
80 
81  return true;
82 }
#define it(className, varName)
virtual bool itemMatches(const Item &item) const =0
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
virtual Cardinality cardinality() const =0
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
virtual ItemType::Ptr itemType() const =0
const SequenceType::Ptr m_targetType
Definition: qinstanceof_p.h:93
virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const

◆ expectedOperandTypes()

SequenceType::List InstanceOf::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 117 of file qinstanceof.cpp.

118 {
119  SequenceType::List result;
121  return result;
122 }
static const SequenceType::Ptr ZeroOrMoreItems
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

◆ staticType()

SequenceType::Ptr InstanceOf::staticType ( ) const
virtual
Returns
the static type of this Expression. For example, an 'and' expression have as static type xs:boolean

Implements QPatternist::Expression.

Definition at line 112 of file qinstanceof.cpp.

113 {
115 }
static const SequenceType::Ptr ExactlyOneBoolean

◆ targetType()

SequenceType::Ptr InstanceOf::targetType ( ) const
Returns
the SequenceType that this instance of Expression is testing its operand against.

Definition at line 107 of file qinstanceof.cpp.

Referenced by compress().

108 {
109  return m_targetType;
110 }
const SequenceType::Ptr m_targetType
Definition: qinstanceof_p.h:93

Properties

◆ m_targetType

const SequenceType::Ptr QPatternist::InstanceOf::m_targetType
private

Definition at line 93 of file qinstanceof_p.h.

Referenced by compress(), evaluateEBV(), InstanceOf(), and targetType().


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