LCOV - code coverage report
Current view: top level - dom/xslt/xpath - txPredicateList.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 36 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          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 "txNodeSetContext.h"
       9             : 
      10             : /*
      11             :  * Represents an ordered list of Predicates,
      12             :  * for use with Step and Filter Expressions
      13             :  */
      14             : 
      15             : nsresult
      16           0 : PredicateList::evaluatePredicates(txNodeSet* nodes,
      17             :                                   txIMatchContext* aContext)
      18             : {
      19           0 :     NS_ASSERTION(nodes, "called evaluatePredicates with nullptr NodeSet");
      20           0 :     nsresult rv = NS_OK;
      21             : 
      22           0 :     uint32_t i, len = mPredicates.Length();
      23           0 :     for (i = 0; i < len && !nodes->isEmpty(); ++i) {
      24           0 :         txNodeSetContext predContext(nodes, aContext);
      25             :         /*
      26             :          * add nodes to newNodes that match the expression
      27             :          * or, if the result is a number, add the node with the right
      28             :          * position
      29             :          */
      30           0 :         int32_t index = 0;
      31           0 :         while (predContext.hasNext()) {
      32           0 :             predContext.next();
      33           0 :             RefPtr<txAExprResult> exprResult;
      34           0 :             rv = mPredicates[i]->evaluate(&predContext,
      35           0 :                                           getter_AddRefs(exprResult));
      36           0 :             NS_ENSURE_SUCCESS(rv, rv);
      37             : 
      38             :             // handle default, [position() == numberValue()]
      39           0 :             if (exprResult->getResultType() == txAExprResult::NUMBER) {
      40           0 :                 if ((double)predContext.position() == exprResult->numberValue()) {
      41           0 :                     nodes->mark(index);
      42             :                 }
      43             :             }
      44           0 :             else if (exprResult->booleanValue()) {
      45           0 :                 nodes->mark(index);
      46             :             }
      47           0 :             ++index;
      48             :         }
      49             :         // sweep the non-marked nodes
      50           0 :         nodes->sweep();
      51             :     }
      52             : 
      53           0 :     return NS_OK;
      54             : }
      55             : 
      56             : bool
      57           0 : PredicateList::isSensitiveTo(Expr::ContextSensitivity aContext)
      58             : {
      59             :     // We're creating a new node/nodeset so we can ignore those bits.
      60             :     Expr::ContextSensitivity context =
      61           0 :         aContext & ~(Expr::NODE_CONTEXT | Expr::NODESET_CONTEXT);
      62           0 :     if (context == Expr::NO_CONTEXT) {
      63           0 :         return false;
      64             :     }
      65             : 
      66           0 :     uint32_t i, len = mPredicates.Length();
      67           0 :     for (i = 0; i < len; ++i) {
      68           0 :         if (mPredicates[i]->isSensitiveTo(context)) {
      69           0 :             return true;
      70             :         }
      71             :     }
      72             : 
      73           0 :     return false;
      74             : }
      75             : 
      76             : #ifdef TX_TO_STRING
      77           0 : void PredicateList::toString(nsAString& dest)
      78             : {
      79           0 :     for (uint32_t i = 0; i < mPredicates.Length(); ++i) {
      80           0 :         dest.Append(char16_t('['));
      81           0 :         mPredicates[i]->toString(dest);
      82           0 :         dest.Append(char16_t(']'));
      83             :     }
      84           0 : }
      85             : #endif

Generated by: LCOV version 1.13