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

Implements XPath 2.0's logical expression and. More...

#include <qandexpression_p.h>

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

Public Functions

virtual ExpressionVisitorResult::Ptr accept (const ExpressionVisitor::Ptr &visitor) const
 
 AndExpression (const Expression::Ptr &operand1, const Expression::Ptr &operand2)
 
virtual Expression::Ptr compress (const StaticContext::Ptr &context)
 
virtual bool evaluateEBV (const DynamicContext::Ptr &context) const
 
virtual SequenceType::List expectedOperandTypes () const
 
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)
 
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 ()
 

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 logical expression and.

The and expression is the same in XQuery 1.0 as in XPath 2.0.

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

Definition at line 74 of file qandexpression_p.h.

Constructors and Destructors

◆ AndExpression()

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

Definition at line 53 of file qandexpression.cpp.

54  : PairContainer(operand1, operand2)
55 {
56 }
PairContainer(const Expression::Ptr &operand1, const Expression::Ptr &operand2)

Functions

◆ accept()

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

Implements QPatternist::Expression.

Reimplemented in QPatternist::OrExpression.

Definition at line 92 of file qandexpression.cpp.

93 {
94  return visitor->visit(this);
95 }

◆ compress()

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

Reimplemented in QPatternist::OrExpression.

Definition at line 63 of file qandexpression.cpp.

64 {
65  const Expression::Ptr newMe(PairContainer::compress(context));
66 
67  if(newMe != this)
68  return newMe;
69 
70  /* Both operands mustn't be evaluated in order to be able to compress. */
72  return wrapLiteral(CommonValues::BooleanFalse, context, this);
73  else if(m_operand2->isEvaluated() && !m_operand2->evaluateEBV(context->dynamicContext()))
74  return wrapLiteral(CommonValues::BooleanFalse, context, this);
75  else
76  return Expression::Ptr(this);
77 }
virtual bool evaluateEBV(const DynamicContext::Ptr &context) const
virtual Expression::Ptr compress(const StaticContext::Ptr &context)
QExplicitlySharedDataPointer< Expression > Ptr
A smart pointer wrapping mutable Expression instances.
virtual QExplicitlySharedDataPointer< DynamicContext > dynamicContext() const =0
static const AtomicValue::Ptr BooleanFalse

◆ evaluateEBV()

bool AndExpression::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.

Reimplemented in QPatternist::OrExpression.

Definition at line 58 of file qandexpression.cpp.

59 {
60  return m_operand1->evaluateEBV(context) && m_operand2->evaluateEBV(context);
61 }
virtual bool evaluateEBV(const DynamicContext::Ptr &context) const

◆ expectedOperandTypes()

SequenceType::List AndExpression::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 79 of file qandexpression.cpp.

80 {
81  SequenceType::List result;
84  return result;
85 }
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
static const SequenceType::Ptr EBV
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ staticType()

SequenceType::Ptr AndExpression::staticType ( ) const
virtual
Returns
always CommonSequenceTypes::ExactlyOneBoolean

Implements QPatternist::Expression.

Definition at line 87 of file qandexpression.cpp.

88 {
90 }
static const SequenceType::Ptr ExactlyOneBoolean

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