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 : #include "txExpr.h"
7 : #include "txNodeSet.h"
8 : #include "txIXPathContext.h"
9 :
10 : //-- Implementation of FilterExpr --/
11 :
12 : //-----------------------------/
13 : //- Virtual methods from Expr -/
14 : //-----------------------------/
15 :
16 : /**
17 : * Evaluates this Expr based on the given context node and processor state
18 : * @param context the context node for evaluation of this Expr
19 : * @param ps the ProcessorState containing the stack information needed
20 : * for evaluation
21 : * @return the result of the evaluation
22 : * @see Expr
23 : **/
24 : nsresult
25 0 : FilterExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
26 : {
27 0 : *aResult = nullptr;
28 :
29 0 : RefPtr<txAExprResult> exprRes;
30 0 : nsresult rv = expr->evaluate(aContext, getter_AddRefs(exprRes));
31 0 : NS_ENSURE_SUCCESS(rv, rv);
32 :
33 0 : NS_ENSURE_TRUE(exprRes->getResultType() == txAExprResult::NODESET,
34 : NS_ERROR_XSLT_NODESET_EXPECTED);
35 :
36 : RefPtr<txNodeSet> nodes =
37 0 : static_cast<txNodeSet*>(static_cast<txAExprResult*>(exprRes));
38 : // null out exprRes so that we can test for shared-ness
39 0 : exprRes = nullptr;
40 :
41 0 : RefPtr<txNodeSet> nonShared;
42 0 : rv = aContext->recycler()->getNonSharedNodeSet(nodes,
43 0 : getter_AddRefs(nonShared));
44 0 : NS_ENSURE_SUCCESS(rv, rv);
45 :
46 0 : rv = evaluatePredicates(nonShared, aContext);
47 0 : NS_ENSURE_SUCCESS(rv, rv);
48 :
49 0 : *aResult = nonShared;
50 0 : NS_ADDREF(*aResult);
51 :
52 0 : return NS_OK;
53 : } //-- evaluate
54 :
55 0 : TX_IMPL_EXPR_STUBS_BASE(FilterExpr, NODESET_RESULT)
56 :
57 : Expr*
58 0 : FilterExpr::getSubExprAt(uint32_t aPos)
59 : {
60 0 : if (aPos == 0) {
61 0 : return expr;
62 : }
63 0 : return PredicateList::getSubExprAt(aPos - 1);
64 : }
65 :
66 : void
67 0 : FilterExpr::setSubExprAt(uint32_t aPos, Expr* aExpr)
68 : {
69 0 : if (aPos == 0) {
70 0 : expr.forget();
71 0 : expr = aExpr;
72 : }
73 : else {
74 0 : PredicateList::setSubExprAt(aPos - 1, aExpr);
75 : }
76 0 : }
77 :
78 : bool
79 0 : FilterExpr::isSensitiveTo(ContextSensitivity aContext)
80 : {
81 0 : return expr->isSensitiveTo(aContext) ||
82 0 : PredicateList::isSensitiveTo(aContext);
83 : }
84 :
85 : #ifdef TX_TO_STRING
86 : void
87 0 : FilterExpr::toString(nsAString& str)
88 : {
89 0 : if ( expr ) expr->toString(str);
90 0 : else str.AppendLiteral("null");
91 0 : PredicateList::toString(str);
92 0 : }
93 : #endif
94 :
|