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

Implements XPath 2.0's treat as expression. More...

#include <qtreatas_p.h>

Inheritance diagram for QPatternist::TreatAs:
QPatternist::SingleContainer QPatternist::Expression QSharedData QPatternist::CppCastingHelper< Expression > QPatternist::SourceLocationReflection

Public Functions

virtual ExpressionVisitorResult::Ptr accept (const ExpressionVisitor::Ptr &visitor) const
 
virtual SequenceType::List expectedOperandTypes () const
 
virtual SequenceType::Ptr staticType () const
 
 TreatAs (const Expression::Ptr &operand, const SequenceType::Ptr &reqType)
 
virtual Expression::Ptr typeCheck (const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
 
- 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)
 
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 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 ()
 
- 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_reqType
 

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 treat as expression.

TreatAs is always a compile-time class only, and is always deallocated by re-writing to CardinalityVerifier or ItemVerifier or both, by calling TypeChecker::applyFunctionConversion().

One approach could be to skip instantiating TreatAs and simply let the return value of TypeChecker::applyFunctionConversion() be inserted into the AST, but that wouldn't handle type checking the context item properly, which depends on that the StaticContext have been set by the parent Expression.

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

Definition at line 82 of file qtreatas_p.h.

Constructors and Destructors

◆ TreatAs()

TreatAs::TreatAs ( const Expression::Ptr operand,
const SequenceType::Ptr reqType 
)

Creats a TreatAs where it is checked that the expression operand conforms to the type reqType.

Definition at line 51 of file qtreatas.cpp.

52  : SingleContainer(operand),
53  m_reqType(reqType)
54 {
55  Q_ASSERT(reqType);
56 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
SingleContainer(const Expression::Ptr &operand)
const SequenceType::Ptr m_reqType
Definition: qtreatas_p.h:114

Functions

◆ accept()

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

Implements QPatternist::Expression.

Definition at line 75 of file qtreatas.cpp.

76 {
77  return visitor->visit(this);
78 }

◆ expectedOperandTypes()

SequenceType::List TreatAs::expectedOperandTypes ( ) const
virtual
Returns
a list containing one CommonSequenceTypes::ZeroOrMoreItems

Implements QPatternist::Expression.

Definition at line 85 of file qtreatas.cpp.

86 {
87  SequenceType::List result;
89  return result;
90 }
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 TreatAs::staticType ( ) const
virtual
Returns
always the SequenceType passed in the constructor to this class. That is, the SequenceType that the operand must conform to.

Implements QPatternist::Expression.

Definition at line 80 of file qtreatas.cpp.

81 {
82  return m_reqType;
83 }
const SequenceType::Ptr m_reqType
Definition: qtreatas_p.h:114

◆ typeCheck()

Expression::Ptr TreatAs::typeCheck ( const StaticContext::Ptr context,
const SequenceType::Ptr reqType 
)
virtual

This function rewrites always. First the type that this TreatAs expression tests for is verified. Then, the type the treat as expression itself must match, reqType, is verified.

Reimplemented from QPatternist::Expression.

Definition at line 58 of file qtreatas.cpp.

60 {
61  Q_ASSERT(context);
62  Q_ASSERT(reqType);
63 
64  /* Apply function conversion with the special error code XPDY0050. After that, we
65  * let the regular typeCheck() function be invoked on the operand before we rewrite
66  * to it. Hence is applyFunctionConversion() called twice, which doesn't break anything,
67  * but indeed is redundant. */
69  m_reqType,
70  context,
72  return treated->typeCheck(context, reqType);
73 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const SequenceType::Ptr m_reqType
Definition: qtreatas_p.h:114
static Expression::Ptr applyFunctionConversion(const Expression::Ptr &operand, const SequenceType::Ptr &reqType, const StaticContext::Ptr &context, const ReportContext::ErrorCode code=ReportContext::XPTY0004, const Options=Options(AutomaticallyConvert|CheckFocus))
Builds a pipeline of artificial AST nodes that ensures operand conforms to the type reqType by applyi...

Properties

◆ m_reqType

const SequenceType::Ptr QPatternist::TreatAs::m_reqType
private

Definition at line 114 of file qtreatas_p.h.

Referenced by staticType(), and typeCheck().


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