Bug 1935611 - Fix libyuv/libpng link failed for loongarch64. r=glandium,tnikkel,ng
[gecko.git] / dom / xslt / xpath / txPredicateList.cpp
blobad2804caefa19107b892bec493abcb852e3660ef
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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/. */
6 #include "txExpr.h"
7 #include "txNodeSet.h"
8 #include "txNodeSetContext.h"
11 * Represents an ordered list of Predicates,
12 * for use with Step and Filter Expressions
15 nsresult PredicateList::evaluatePredicates(txNodeSet* nodes,
16 txIMatchContext* aContext) {
17 NS_ASSERTION(nodes, "called evaluatePredicates with nullptr NodeSet");
18 nsresult rv = NS_OK;
20 uint32_t i, len = mPredicates.Length();
21 for (i = 0; i < len && !nodes->isEmpty(); ++i) {
22 txNodeSetContext predContext(nodes, aContext);
24 * add nodes to newNodes that match the expression
25 * or, if the result is a number, add the node with the right
26 * position
28 int32_t index = 0;
29 while (predContext.hasNext()) {
30 predContext.next();
31 RefPtr<txAExprResult> exprResult;
32 rv = mPredicates[i]->evaluate(&predContext, getter_AddRefs(exprResult));
33 NS_ENSURE_SUCCESS(rv, rv);
35 // handle default, [position() == numberValue()]
36 if (exprResult->getResultType() == txAExprResult::NUMBER) {
37 if ((double)predContext.position() == exprResult->numberValue()) {
38 nodes->mark(index);
40 } else if (exprResult->booleanValue()) {
41 nodes->mark(index);
43 ++index;
45 // sweep the non-marked nodes
46 nodes->sweep();
49 return NS_OK;
52 bool PredicateList::isSensitiveTo(Expr::ContextSensitivity aContext) {
53 // We're creating a new node/nodeset so we can ignore those bits.
54 Expr::ContextSensitivity context =
55 aContext & ~(Expr::NODE_CONTEXT | Expr::NODESET_CONTEXT);
56 if (context == Expr::NO_CONTEXT) {
57 return false;
60 uint32_t i, len = mPredicates.Length();
61 for (i = 0; i < len; ++i) {
62 if (mPredicates[i]->isSensitiveTo(context)) {
63 return true;
67 return false;
70 #ifdef TX_TO_STRING
71 void PredicateList::toString(nsAString& dest) {
72 for (uint32_t i = 0; i < mPredicates.Length(); ++i) {
73 dest.Append(char16_t('['));
74 mPredicates[i]->toString(dest);
75 dest.Append(char16_t(']'));
78 #endif