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

Implements XPath 2.0 unary expression, (-|+)ValueExpr. More...

#include <qunaryexpression_p.h>

Inheritance diagram for QPatternist::UnaryExpression:
QPatternist::ArithmeticExpression QPatternist::PairContainer QPatternist::Expression QSharedData QPatternist::CppCastingHelper< Expression > QPatternist::SourceLocationReflection

Public Functions

virtual Item evaluateSingleton (const DynamicContext::Ptr &context) const
 
 UnaryExpression (const AtomicMathematician::Operator op, const Expression::Ptr &operand, const StaticContext::Ptr &context)
 
- Public Functions inherited from QPatternist::ArithmeticExpression
virtual ExpressionVisitorResult::Ptr accept (const ExpressionVisitor::Ptr &visitor) const
 
 ArithmeticExpression (const Expression::Ptr &operand1, const AtomicMathematician::Operator op, const Expression::Ptr &operand2)
 
virtual SequenceType::List expectedOperandTypes () const
 
AtomicMathematician::Operator operatorID () const
 
virtual SequenceType::Ptr staticType () const
 
virtual Expression::Ptr typeCheck (const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
 
- 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)
 
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 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 ()
 

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::ArithmeticExpression
static AtomicMathematician::Ptr fetchMathematician (Expression::Ptr &t1, Expression::Ptr &t2, const AtomicMathematician::Operator op, const bool issueError, const ReportContext::Ptr &context, const SourceLocationReflection *const reflection, const ReportContext::ErrorCode code=ReportContext::XPTY0004, const bool isCompat=false)
 
static Item flexiblyCalculate (const Item &op1, const AtomicMathematician::Operator op, const Item &op2, const AtomicMathematician::Ptr &mather, const DynamicContext::Ptr &context, const SourceLocationReflection *const reflection, const ReportContext::ErrorCode code=ReportContext::XPTY0004, const bool isCompat=false)
 
- 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 unary expression, (-|+)ValueExpr.

UnaryExpression is implemented by rewriting the expression operator [expr] to the ArithmeticExpression 0 operator [expr]. For example, the expression +3 becomes 0 + 3, and -nodetest becomes 0 - nodetest.

On top of that expression ArithmeticExpression does the usual type checking conversion. The only thing this class do, is to overide evaluateSingleton() and calls Numeric::toNegated(). The reason this UnaryExpression is needed at all and that 0 - [expr] is insufficent is that 0 - xs:double(0) needs to return -0, instead of 0. I know no other difference.

In most cases the constant propagation optimization rewrites UnaryExpression into a value, an instance of a sub-class of the Numeric class, wrapped with Literal.

Beyond the mathematical implication the unary expression have, it also have the significant effect that it may invoke type promotion or that an expression may contain a type error. For example, the expression "+'a string'" contains a type error, since no unary operator is defined for xs:string. This is the reason why the '+' unary operator isn't ignored.

See also
XML Path Language (XPath) 2.0, 3.4 Arithmetic Expressions
XQuery 1.0 and XPath 2.0 Functions and Operators, 6.2.7 op:numeric-unary-plus
XQuery 1.0 and XPath 2.0 Functions and Operators, 6.2.8 op:numeric-unary-minus
Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 96 of file qunaryexpression_p.h.

Constructors and Destructors

◆ UnaryExpression()

UnaryExpression::UnaryExpression ( const AtomicMathematician::Operator  op,
const Expression::Ptr operand,
const StaticContext::Ptr context 
)

Definition at line 53 of file qunaryexpression.cpp.

55  : ArithmeticExpression(wrapLiteral(CommonValues::IntegerZero, context, operand.data()),
56  op,
57  operand)
58 {
61  Q_ASSERT(context);
62 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static const Item IntegerZero
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
ArithmeticExpression(const Expression::Ptr &operand1, const AtomicMathematician::Operator op, const Expression::Ptr &operand2)

Functions

◆ evaluateSingleton()

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

Reimplemented from QPatternist::ArithmeticExpression.

Definition at line 64 of file qunaryexpression.cpp.

65 {
67  {
68  const Item item(m_operand2->evaluateSingleton(context));
69 
70  if(item)
71  return item.as<Numeric>()->toNegated();
72  else
73  return Item();
74  }
75  else
76  return m_operand2->evaluateSingleton(context);
77 }
AtomicMathematician::Operator operatorID() const
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
Base class for all numeric values.
TCastTarget * as() const
Definition: qitem_p.h:278
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const

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