dom/xslt/xpath/txFilterExpr.cpp

branch
TOR_BUG_9701
changeset 8
97036ab72558
equal deleted inserted replaced
-1:000000000000 0:bf4d3ffde5fe
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 FilterExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
26 {
27 *aResult = nullptr;
28
29 nsRefPtr<txAExprResult> exprRes;
30 nsresult rv = expr->evaluate(aContext, getter_AddRefs(exprRes));
31 NS_ENSURE_SUCCESS(rv, rv);
32
33 NS_ENSURE_TRUE(exprRes->getResultType() == txAExprResult::NODESET,
34 NS_ERROR_XSLT_NODESET_EXPECTED);
35
36 nsRefPtr<txNodeSet> nodes =
37 static_cast<txNodeSet*>(static_cast<txAExprResult*>(exprRes));
38 // null out exprRes so that we can test for shared-ness
39 exprRes = nullptr;
40
41 nsRefPtr<txNodeSet> nonShared;
42 rv = aContext->recycler()->getNonSharedNodeSet(nodes,
43 getter_AddRefs(nonShared));
44 NS_ENSURE_SUCCESS(rv, rv);
45
46 rv = evaluatePredicates(nonShared, aContext);
47 NS_ENSURE_SUCCESS(rv, rv);
48
49 *aResult = nonShared;
50 NS_ADDREF(*aResult);
51
52 return NS_OK;
53 } //-- evaluate
54
55 TX_IMPL_EXPR_STUBS_BASE(FilterExpr, NODESET_RESULT)
56
57 Expr*
58 FilterExpr::getSubExprAt(uint32_t aPos)
59 {
60 if (aPos == 0) {
61 return expr;
62 }
63 return PredicateList::getSubExprAt(aPos - 1);
64 }
65
66 void
67 FilterExpr::setSubExprAt(uint32_t aPos, Expr* aExpr)
68 {
69 if (aPos == 0) {
70 expr.forget();
71 expr = aExpr;
72 }
73 else {
74 PredicateList::setSubExprAt(aPos - 1, aExpr);
75 }
76 }
77
78 bool
79 FilterExpr::isSensitiveTo(ContextSensitivity aContext)
80 {
81 return expr->isSensitiveTo(aContext) ||
82 PredicateList::isSensitiveTo(aContext);
83 }
84
85 #ifdef TX_TO_STRING
86 void
87 FilterExpr::toString(nsAString& str)
88 {
89 if ( expr ) expr->toString(str);
90 else str.AppendLiteral("null");
91 PredicateList::toString(str);
92 }
93 #endif
94

mercurial