/src/mozilla-central/dom/xslt/xpath/txBooleanExpr.cpp
Line | Count | Source (jump to first uncovered line) |
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 | 0 | { |
25 | 0 | *aResult = nullptr; |
26 | 0 |
|
27 | 0 | bool lval; |
28 | 0 | nsresult rv = leftExpr->evaluateToBool(aContext, lval); |
29 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
30 | 0 |
|
31 | 0 | // check for early decision |
32 | 0 | if (op == OR && lval) { |
33 | 0 | aContext->recycler()->getBoolResult(true, aResult); |
34 | 0 |
|
35 | 0 | return NS_OK; |
36 | 0 | } |
37 | 0 | if (op == AND && !lval) { |
38 | 0 | aContext->recycler()->getBoolResult(false, aResult); |
39 | 0 |
|
40 | 0 | return NS_OK; |
41 | 0 | } |
42 | 0 | |
43 | 0 | bool rval; |
44 | 0 | rv = rightExpr->evaluateToBool(aContext, rval); |
45 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
46 | 0 |
|
47 | 0 | // just use rval, since we already checked lval |
48 | 0 | aContext->recycler()->getBoolResult(rval, aResult); |
49 | 0 |
|
50 | 0 | return NS_OK; |
51 | 0 | } //-- evaluate |
52 | | |
53 | | TX_IMPL_EXPR_STUBS_2(BooleanExpr, BOOLEAN_RESULT, leftExpr, rightExpr) |
54 | | |
55 | | bool |
56 | | BooleanExpr::isSensitiveTo(ContextSensitivity aContext) |
57 | 0 | { |
58 | 0 | return leftExpr->isSensitiveTo(aContext) || |
59 | 0 | rightExpr->isSensitiveTo(aContext); |
60 | 0 | } |
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 |