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

A reference to a variable declared with declare variable or let. More...

#include <qexpressionvariablereference_p.h>

Inheritance diagram for QPatternist::ExpressionVariableReference:
QPatternist::VariableReference QPatternist::EmptyContainer QPatternist::Expression QSharedData QPatternist::CppCastingHelper< Expression > QPatternist::SourceLocationReflection

Public Functions

virtual ExpressionVisitorResult::Ptr accept (const ExpressionVisitor::Ptr &visitor) 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
 
 ExpressionVariableReference (const VariableSlotID slot, const VariableDeclaration *varDecl)
 
virtual ID id () const
 
const Expression::PtrsourceExpression () const
 
virtual SequenceType::Ptr staticType () const
 
virtual Expression::Ptr typeCheck (const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
 
const VariableDeclarationvariableDeclaration () const
 
- Public Functions inherited from QPatternist::VariableReference
virtual Properties properties () const
 
VariableSlotID slot () const
 
 VariableReference (const VariableSlotID slot)
 
- Public Functions inherited from QPatternist::EmptyContainer
virtual Expression::List operands () const
 
virtual void setOperands (const 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 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 ()
 

Properties

const VariableDeclarationm_varDecl
 

Additional Inherited Members

- Public Types inherited from QPatternist::VariableReference
typedef QList< VariableReference::PtrList
 
typedef QExplicitlySharedDataPointer< VariableReferencePtr
 
- 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::EmptyContainer
virtual bool compressOperands (const StaticContext::Ptr &context)
 
virtual SequenceType::List expectedOperandTypes () const
 
- Protected Functions inherited from QPatternist::Expression
void typeCheckOperands (const StaticContext::Ptr &context)
 
- Protected Functions inherited from QPatternist::CppCastingHelper< Expression >
 CppCastingHelper ()
 

Detailed Description

A reference to a variable declared with declare variable or let.

It's also used by variable bindings in case branches of the typeswitch expression.

This AST node is only used up until the typeCheck() stage. Therefore it has no functions for evaluation, such as evaluateSequence().

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

Definition at line 76 of file qexpressionvariablereference_p.h.

Constructors and Destructors

◆ ExpressionVariableReference()

ExpressionVariableReference::ExpressionVariableReference ( const VariableSlotID  slot,
const VariableDeclaration varDecl 
)

Definition at line 49 of file qexpressionvariablereference.cpp.

50  : VariableReference(slotP)
51  , m_varDecl(varDecl)
52 {
53 }
VariableReference(const VariableSlotID slot)

Functions

◆ accept()

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

Implements QPatternist::Expression.

Definition at line 83 of file qexpressionvariablereference.cpp.

84 {
85  return visitor->visit(this);
86 }

◆ evaluateEBV()

bool ExpressionVariableReference::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 55 of file qexpressionvariablereference.cpp.

56 {
57  return context->expressionVariable(slot())->evaluateEBV(context);
58 }
virtual bool evaluateEBV(const DynamicContext::Ptr &context) const
virtual QExplicitlySharedDataPointer< Expression > expressionVariable(const VariableSlotID slot) const =0

◆ evaluateSequence()

Item::Iterator::Ptr ExpressionVariableReference::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 65 of file qexpressionvariablereference.cpp.

66 {
67  return context->expressionVariable(slot())->evaluateSequence(context);
68 }
virtual QExplicitlySharedDataPointer< Expression > expressionVariable(const VariableSlotID slot) const =0
virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const

◆ evaluateSingleton()

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

Reimplemented from QPatternist::Expression.

Definition at line 60 of file qexpressionvariablereference.cpp.

61 {
62  return context->expressionVariable(slot())->evaluateSingleton(context);
63 }
virtual QExplicitlySharedDataPointer< Expression > expressionVariable(const VariableSlotID slot) const =0
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const

◆ id()

Expression::ID ExpressionVariableReference::id ( ) const
virtual

This property, which has no setter, returns an enum value that uniquely identifies this Expression. Patternist makes no use of C++'s dynamic_cast feature, but uses this polymorphic function instead.

Returns
always IgnorableExpression.

Reimplemented from QPatternist::Expression.

Definition at line 78 of file qexpressionvariablereference.cpp.

◆ sourceExpression()

const Expression::Ptr & QPatternist::ExpressionVariableReference::sourceExpression ( ) const
inline

Definition at line 98 of file qexpressionvariablereference_p.h.

Referenced by QPatternist::checkVariableCircularity().

99  {
100  return m_varDecl->expression();
101  }
const Expression::Ptr & expression() const

◆ staticType()

SequenceType::Ptr ExpressionVariableReference::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 88 of file qexpressionvariablereference.cpp.

89 {
90  return m_varDecl->expression()->staticType();
91 }
virtual SequenceType::Ptr staticType() const =0
const Expression::Ptr & expression() const

◆ typeCheck()

Expression::Ptr ExpressionVariableReference::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::Expression.

Definition at line 69 of file qexpressionvariablereference.cpp.

71 {
73  return m_varDecl->expression()->typeCheck(context, reqType);
74  else
75  return VariableReference::typeCheck(context, reqType);
76 }
virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
Definition: qexpression.cpp:70
bool canSourceRewrite
Whether a reference can rewrite itself to expression().
const Expression::Ptr & expression() const

◆ variableDeclaration()

const VariableDeclaration * QPatternist::ExpressionVariableReference::variableDeclaration ( ) const
inline

Definition at line 103 of file qexpressionvariablereference_p.h.

Referenced by QPatternist::checkVariableCircularity().

104  {
105  return m_varDecl;
106  }

Properties

◆ m_varDecl

const VariableDeclaration* QPatternist::ExpressionVariableReference::m_varDecl
private

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