1 /**
  2  * @fileoverview A class representing operations on unary expressions.
  3  */
  4 
  5 goog.provide('xrx.xpath.UnaryExpr');
  6 
  7 goog.require('xrx.xpath.DataType');
  8 goog.require('xrx.xpath.Expr');
  9 
 10 
 11 
 12 /**
 13  * Constructor for UnaryExpr.
 14  *
 15  * @param {!xrx.xpath.Expr} expr The unary expression.
 16  * @extends {xrx.xpath.Expr}
 17  * @constructor
 18  */
 19 xrx.xpath.UnaryExpr = function(expr) {
 20   xrx.xpath.Expr.call(this, xrx.xpath.DataType.NUMBER);
 21 
 22   /**
 23    * @private
 24    * @type {!xrx.xpath.Expr}
 25    */
 26   this.expr_ = expr;
 27 
 28   this.setNeedContextPosition(expr.doesNeedContextPosition());
 29   this.setNeedContextNode(expr.doesNeedContextNode());
 30 };
 31 goog.inherits(xrx.xpath.UnaryExpr, xrx.xpath.Expr);
 32 
 33 
 34 /**
 35  * @override
 36  * @return {number} The number result.
 37  */
 38 xrx.xpath.UnaryExpr.prototype.evaluate = function(ctx) {
 39   return -this.expr_.asNumber(ctx);
 40 };
 41 
 42 
 43 /**
 44  * @override
 45  */
 46 xrx.xpath.UnaryExpr.prototype.toString = function() {
 47   return 'Unary Expression: -' + xrx.xpath.Expr.indent(this.expr_);
 48 };
 49