dom/xslt/xpath/txBooleanExpr.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     7 /**
     8  * Represents a BooleanExpr, a binary expression that
     9  * performs a boolean operation between its lvalue and rvalue.
    10 **/
    12 #include "txExpr.h"
    13 #include "txIXPathContext.h"
    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;
    27     bool lval;
    28     nsresult rv = leftExpr->evaluateToBool(aContext, lval);
    29     NS_ENSURE_SUCCESS(rv, rv);
    31     // check for early decision
    32     if (op == OR && lval) {
    33         aContext->recycler()->getBoolResult(true, aResult);
    35         return NS_OK;
    36     }
    37     if (op == AND && !lval) {
    38         aContext->recycler()->getBoolResult(false, aResult);
    40         return NS_OK;
    41     }
    43     bool rval;
    44     rv = rightExpr->evaluateToBool(aContext, rval);
    45     NS_ENSURE_SUCCESS(rv, rv);
    47     // just use rval, since we already checked lval
    48     aContext->recycler()->getBoolResult(rval, aResult);
    50     return NS_OK;
    51 } //-- evaluate
    53 TX_IMPL_EXPR_STUBS_2(BooleanExpr, BOOLEAN_RESULT, leftExpr, rightExpr)
    55 bool
    56 BooleanExpr::isSensitiveTo(ContextSensitivity aContext)
    57 {
    58     return leftExpr->isSensitiveTo(aContext) ||
    59            rightExpr->isSensitiveTo(aContext);
    60 }
    62 #ifdef TX_TO_STRING
    63 void
    64 BooleanExpr::toString(nsAString& str)
    65 {
    66     if ( leftExpr ) leftExpr->toString(str);
    67     else str.AppendLiteral("null");
    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");
    80 }
    81 #endif

mercurial