Line data Source code
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 0 : BooleanExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
24 : {
25 0 : *aResult = nullptr;
26 :
27 : bool lval;
28 0 : nsresult rv = leftExpr->evaluateToBool(aContext, lval);
29 0 : NS_ENSURE_SUCCESS(rv, rv);
30 :
31 : // check for early decision
32 0 : if (op == OR && lval) {
33 0 : aContext->recycler()->getBoolResult(true, aResult);
34 :
35 0 : return NS_OK;
36 : }
37 0 : if (op == AND && !lval) {
38 0 : aContext->recycler()->getBoolResult(false, aResult);
39 :
40 0 : return NS_OK;
41 : }
42 :
43 : bool rval;
44 0 : rv = rightExpr->evaluateToBool(aContext, rval);
45 0 : NS_ENSURE_SUCCESS(rv, rv);
46 :
47 : // just use rval, since we already checked lval
48 0 : aContext->recycler()->getBoolResult(rval, aResult);
49 :
50 0 : return NS_OK;
51 : } //-- evaluate
52 :
53 0 : TX_IMPL_EXPR_STUBS_2(BooleanExpr, BOOLEAN_RESULT, leftExpr, rightExpr)
54 :
55 : bool
56 0 : BooleanExpr::isSensitiveTo(ContextSensitivity aContext)
57 : {
58 0 : return leftExpr->isSensitiveTo(aContext) ||
59 0 : rightExpr->isSensitiveTo(aContext);
60 : }
61 :
62 : #ifdef TX_TO_STRING
63 : void
64 0 : BooleanExpr::toString(nsAString& str)
65 : {
66 0 : if ( leftExpr ) leftExpr->toString(str);
67 0 : else str.AppendLiteral("null");
68 :
69 0 : switch ( op ) {
70 : case OR:
71 0 : str.AppendLiteral(" or ");
72 0 : break;
73 : default:
74 0 : str.AppendLiteral(" and ");
75 0 : break;
76 : }
77 0 : if ( rightExpr ) rightExpr->toString(str);
78 0 : else str.AppendLiteral("null");
79 :
80 0 : }
81 : #endif
|