dom/xslt/xpath/txFilterExpr.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/xslt/xpath/txFilterExpr.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "txExpr.h"
    1.10 +#include "txNodeSet.h"
    1.11 +#include "txIXPathContext.h"
    1.12 +
    1.13 +//-- Implementation of FilterExpr --/
    1.14 +
    1.15 +  //-----------------------------/
    1.16 + //- Virtual methods from Expr -/
    1.17 +//-----------------------------/
    1.18 +
    1.19 +/**
    1.20 + * Evaluates this Expr based on the given context node and processor state
    1.21 + * @param context the context node for evaluation of this Expr
    1.22 + * @param ps the ProcessorState containing the stack information needed
    1.23 + * for evaluation
    1.24 + * @return the result of the evaluation
    1.25 + * @see Expr
    1.26 +**/
    1.27 +nsresult
    1.28 +FilterExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
    1.29 +{
    1.30 +    *aResult = nullptr;
    1.31 +
    1.32 +    nsRefPtr<txAExprResult> exprRes;
    1.33 +    nsresult rv = expr->evaluate(aContext, getter_AddRefs(exprRes));
    1.34 +    NS_ENSURE_SUCCESS(rv, rv);
    1.35 +
    1.36 +    NS_ENSURE_TRUE(exprRes->getResultType() == txAExprResult::NODESET,
    1.37 +                   NS_ERROR_XSLT_NODESET_EXPECTED);
    1.38 +
    1.39 +    nsRefPtr<txNodeSet> nodes =
    1.40 +        static_cast<txNodeSet*>(static_cast<txAExprResult*>(exprRes));
    1.41 +    // null out exprRes so that we can test for shared-ness
    1.42 +    exprRes = nullptr;
    1.43 +
    1.44 +    nsRefPtr<txNodeSet> nonShared;
    1.45 +    rv = aContext->recycler()->getNonSharedNodeSet(nodes,
    1.46 +                                                   getter_AddRefs(nonShared));
    1.47 +    NS_ENSURE_SUCCESS(rv, rv);
    1.48 +
    1.49 +    rv = evaluatePredicates(nonShared, aContext);
    1.50 +    NS_ENSURE_SUCCESS(rv, rv);
    1.51 +
    1.52 +    *aResult = nonShared;
    1.53 +    NS_ADDREF(*aResult);
    1.54 +
    1.55 +    return NS_OK;
    1.56 +} //-- evaluate
    1.57 +
    1.58 +TX_IMPL_EXPR_STUBS_BASE(FilterExpr, NODESET_RESULT)
    1.59 +
    1.60 +Expr*
    1.61 +FilterExpr::getSubExprAt(uint32_t aPos)
    1.62 +{
    1.63 +    if (aPos == 0) {
    1.64 +      return expr;
    1.65 +    }
    1.66 +    return PredicateList::getSubExprAt(aPos - 1);
    1.67 +}
    1.68 +
    1.69 +void
    1.70 +FilterExpr::setSubExprAt(uint32_t aPos, Expr* aExpr)
    1.71 +{
    1.72 +    if (aPos == 0) {
    1.73 +      expr.forget();
    1.74 +      expr = aExpr;
    1.75 +    }
    1.76 +    else {
    1.77 +      PredicateList::setSubExprAt(aPos - 1, aExpr);
    1.78 +    }
    1.79 +}
    1.80 +
    1.81 +bool
    1.82 +FilterExpr::isSensitiveTo(ContextSensitivity aContext)
    1.83 +{
    1.84 +    return expr->isSensitiveTo(aContext) ||
    1.85 +           PredicateList::isSensitiveTo(aContext);
    1.86 +}
    1.87 +
    1.88 +#ifdef TX_TO_STRING
    1.89 +void
    1.90 +FilterExpr::toString(nsAString& str)
    1.91 +{
    1.92 +    if ( expr ) expr->toString(str);
    1.93 +    else str.AppendLiteral("null");
    1.94 +    PredicateList::toString(str);
    1.95 +}
    1.96 +#endif
    1.97 +

mercurial