1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #include "txExpr.h"
7 #include "txIXPathContext.h"
8
9 /*
10 * Evaluates this Expr based on the given context node and processor state
11 * @param context the context node for evaluation of this Expr
12 * @param ps the ContextState containing the stack information needed
13 * for evaluation.
14 * @return the result of the evaluation.
15 */
evaluate(txIEvalContext * aContext,txAExprResult ** aResult)16 nsresult UnaryExpr::evaluate(txIEvalContext* aContext,
17 txAExprResult** aResult) {
18 *aResult = nullptr;
19
20 RefPtr<txAExprResult> exprRes;
21 nsresult rv = expr->evaluate(aContext, getter_AddRefs(exprRes));
22 NS_ENSURE_SUCCESS(rv, rv);
23
24 double value = exprRes->numberValue();
25 #ifdef HPUX
26 /*
27 * Negation of a zero doesn't produce a negative
28 * zero on HPUX. Perform the operation by multiplying with
29 * -1.
30 */
31 return aContext->recycler()->getNumberResult(-1 * value, aResult);
32 #else
33 return aContext->recycler()->getNumberResult(-value, aResult);
34 #endif
35 }
36
TX_IMPL_EXPR_STUBS_1(UnaryExpr,NODESET_RESULT,expr)37 TX_IMPL_EXPR_STUBS_1(UnaryExpr, NODESET_RESULT, expr)
38
39 bool UnaryExpr::isSensitiveTo(ContextSensitivity aContext) {
40 return expr->isSensitiveTo(aContext);
41 }
42
43 #ifdef TX_TO_STRING
toString(nsAString & str)44 void UnaryExpr::toString(nsAString& str) {
45 if (!expr) return;
46 str.Append(char16_t('-'));
47 expr->toString(str);
48 }
49 #endif
50