dom/xslt/xpath/txBooleanExpr.cpp

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:05bdc77238ee
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
7 /**
8 * Represents a BooleanExpr, a binary expression that
9 * performs a boolean operation between its lvalue and rvalue.
10 **/
11
12 #include "txExpr.h"
13 #include "txIXPathContext.h"
14
15 /**
16 * Evaluates this Expr based on the given context node and processor state
17 * @param context the context node for evaluation of this Expr
18 * @param ps the ContextState containing the stack information needed
19 * for evaluation
20 * @return the result of the evaluation
21 **/
22 nsresult
23 BooleanExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
24 {
25 *aResult = nullptr;
26
27 bool lval;
28 nsresult rv = leftExpr->evaluateToBool(aContext, lval);
29 NS_ENSURE_SUCCESS(rv, rv);
30
31 // check for early decision
32 if (op == OR && lval) {
33 aContext->recycler()->getBoolResult(true, aResult);
34
35 return NS_OK;
36 }
37 if (op == AND && !lval) {
38 aContext->recycler()->getBoolResult(false, aResult);
39
40 return NS_OK;
41 }
42
43 bool rval;
44 rv = rightExpr->evaluateToBool(aContext, rval);
45 NS_ENSURE_SUCCESS(rv, rv);
46
47 // just use rval, since we already checked lval
48 aContext->recycler()->getBoolResult(rval, aResult);
49
50 return NS_OK;
51 } //-- evaluate
52
53 TX_IMPL_EXPR_STUBS_2(BooleanExpr, BOOLEAN_RESULT, leftExpr, rightExpr)
54
55 bool
56 BooleanExpr::isSensitiveTo(ContextSensitivity aContext)
57 {
58 return leftExpr->isSensitiveTo(aContext) ||
59 rightExpr->isSensitiveTo(aContext);
60 }
61
62 #ifdef TX_TO_STRING
63 void
64 BooleanExpr::toString(nsAString& str)
65 {
66 if ( leftExpr ) leftExpr->toString(str);
67 else str.AppendLiteral("null");
68
69 switch ( op ) {
70 case OR:
71 str.AppendLiteral(" or ");
72 break;
73 default:
74 str.AppendLiteral(" and ");
75 break;
76 }
77 if ( rightExpr ) rightExpr->toString(str);
78 else str.AppendLiteral("null");
79
80 }
81 #endif

mercurial