![]() |
Qt 4.8
|
Implements XPath 2.0 unary expression, (-|+)ValueExpr
.
More...
#include <qunaryexpression_p.h>
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.
Definition at line 96 of file qunaryexpression_p.h.
UnaryExpression::UnaryExpression | ( | const AtomicMathematician::Operator | op, |
const Expression::Ptr & | operand, | ||
const StaticContext::Ptr & | context | ||
) |
Definition at line 53 of file qunaryexpression.cpp.
|
virtual |
Reimplemented from QPatternist::ArithmeticExpression.
Definition at line 64 of file qunaryexpression.cpp.