LCOV - code coverage report
Current view: top level - dom/xslt/xslt - txXSLTPatterns.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 39 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 27 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             : #ifndef TX_XSLT_PATTERNS_H
       7             : #define TX_XSLT_PATTERNS_H
       8             : 
       9             : #include "mozilla/Attributes.h"
      10             : #include "txExpandedName.h"
      11             : #include "txExpr.h"
      12             : #include "txXMLUtils.h"
      13             : 
      14             : class txPattern
      15             : {
      16             : public:
      17           0 :     txPattern()
      18           0 :     {
      19           0 :         MOZ_COUNT_CTOR(txPattern);
      20           0 :     }
      21           0 :     virtual ~txPattern()
      22           0 :     {
      23           0 :         MOZ_COUNT_DTOR(txPattern);
      24           0 :     }
      25             : 
      26             :     /*
      27             :      * Determines whether this Pattern matches the given node.
      28             :      */
      29             :     virtual nsresult matches(const txXPathNode& aNode,
      30             :                              txIMatchContext* aContext,
      31             :                              bool& aMatched) = 0;
      32             : 
      33             :     /*
      34             :      * Returns the default priority of this Pattern.
      35             :      *
      36             :      * Simple Patterns return the values as specified in XPath 5.5.
      37             :      * Returns -Inf for union patterns, as it shouldn't be called on them.
      38             :      */
      39             :     virtual double getDefaultPriority() = 0;
      40             : 
      41             :     /**
      42             :      * Returns the type of this pattern.
      43             :      */
      44             :     enum Type {
      45             :         STEP_PATTERN,
      46             :         UNION_PATTERN,
      47             :         OTHER_PATTERN
      48             :     };
      49           0 :     virtual Type getType()
      50             :     {
      51           0 :       return OTHER_PATTERN;
      52             :     }
      53             : 
      54             :     /**
      55             :      * Returns sub-expression at given position
      56             :      */
      57             :     virtual Expr* getSubExprAt(uint32_t aPos) = 0;
      58             : 
      59             :     /**
      60             :      * Replace sub-expression at given position. Does not delete the old
      61             :      * expression, that is the responsibility of the caller.
      62             :      */
      63             :     virtual void setSubExprAt(uint32_t aPos, Expr* aExpr) = 0;
      64             : 
      65             :     /**
      66             :      * Returns sub-pattern at given position
      67             :      */
      68             :     virtual txPattern* getSubPatternAt(uint32_t aPos) = 0;
      69             : 
      70             :     /**
      71             :      * Replace sub-pattern at given position. Does not delete the old
      72             :      * pattern, that is the responsibility of the caller.
      73             :      */
      74             :     virtual void setSubPatternAt(uint32_t aPos, txPattern* aPattern) = 0;
      75             : 
      76             : #ifdef TX_TO_STRING
      77             :     /*
      78             :      * Returns the String representation of this Pattern.
      79             :      * @param dest the String to use when creating the String
      80             :      * representation. The String representation will be appended to
      81             :      * any data in the destination String, to allow cascading calls to
      82             :      * other #toString() methods for Patterns.
      83             :      * @return the String representation of this Pattern.
      84             :      */
      85             :     virtual void toString(nsAString& aDest) = 0;
      86             : #endif
      87             : };
      88             : 
      89             : #define TX_DECL_PATTERN_BASE \
      90             :     nsresult matches(const txXPathNode& aNode, txIMatchContext* aContext, \
      91             :                      bool& aMatched) override; \
      92             :     double getDefaultPriority() override; \
      93             :     virtual Expr* getSubExprAt(uint32_t aPos) override; \
      94             :     virtual void setSubExprAt(uint32_t aPos, Expr* aExpr) override; \
      95             :     virtual txPattern* getSubPatternAt(uint32_t aPos) override; \
      96             :     virtual void setSubPatternAt(uint32_t aPos, txPattern* aPattern) override
      97             : 
      98             : #ifndef TX_TO_STRING
      99             : #define TX_DECL_PATTERN TX_DECL_PATTERN_BASE
     100             : #else
     101             : #define TX_DECL_PATTERN \
     102             :     TX_DECL_PATTERN_BASE; \
     103             :     void toString(nsAString& aDest) override
     104             : #endif
     105             : 
     106             : #define TX_IMPL_PATTERN_STUBS_NO_SUB_EXPR(_class)             \
     107             : Expr*                                                         \
     108             : _class::getSubExprAt(uint32_t aPos)                           \
     109             : {                                                             \
     110             :     return nullptr;                                            \
     111             : }                                                             \
     112             : void                                                          \
     113             : _class::setSubExprAt(uint32_t aPos, Expr* aExpr)              \
     114             : {                                                             \
     115             :     NS_NOTREACHED("setting bad subexpression index");         \
     116             : }
     117             : 
     118             : #define TX_IMPL_PATTERN_STUBS_NO_SUB_PATTERN(_class)          \
     119             : txPattern*                                                    \
     120             : _class::getSubPatternAt(uint32_t aPos)                        \
     121             : {                                                             \
     122             :     return nullptr;                                            \
     123             : }                                                             \
     124             : void                                                          \
     125             : _class::setSubPatternAt(uint32_t aPos, txPattern* aPattern)   \
     126             : {                                                             \
     127             :     NS_NOTREACHED("setting bad subexpression index");         \
     128             : }
     129             : 
     130           0 : class txUnionPattern : public txPattern
     131             : {
     132             : public:
     133           0 :     nsresult addPattern(txPattern* aPattern)
     134             :     {
     135           0 :         return mLocPathPatterns.AppendElement(aPattern) ?
     136           0 :             NS_OK : NS_ERROR_OUT_OF_MEMORY;
     137             :     }
     138             : 
     139             :     TX_DECL_PATTERN;
     140             :     Type getType() override;
     141             : 
     142             : private:
     143             :     txOwningArray<txPattern> mLocPathPatterns;
     144             : };
     145             : 
     146           0 : class txLocPathPattern : public txPattern
     147             : {
     148             : public:
     149             :     nsresult addStep(txPattern* aPattern, bool isChild);
     150             : 
     151             :     TX_DECL_PATTERN;
     152             : 
     153             : private:
     154           0 :     class Step {
     155             :     public:
     156             :         nsAutoPtr<txPattern> pattern;
     157             :         bool isChild;
     158             :     };
     159             : 
     160             :     nsTArray<Step> mSteps;
     161             : };
     162             : 
     163           0 : class txRootPattern : public txPattern
     164             : {
     165             : public:
     166             : #ifdef TX_TO_STRING
     167           0 :     txRootPattern()
     168           0 :         : mSerialize(true)
     169             :     {
     170           0 :     }
     171             : #endif
     172             : 
     173             :     TX_DECL_PATTERN;
     174             : 
     175             : #ifdef TX_TO_STRING
     176             : public:
     177           0 :     void setSerialize(bool aSerialize)
     178             :     {
     179           0 :         mSerialize = aSerialize;
     180           0 :     }
     181             : 
     182             : private:
     183             :     // Don't serialize txRootPattern if it's used in a txLocPathPattern
     184             :     bool mSerialize;
     185             : #endif
     186             : };
     187             : 
     188           0 : class txIdPattern : public txPattern
     189             : {
     190             : public:
     191             :     explicit txIdPattern(const nsAString& aString);
     192             : 
     193             :     TX_DECL_PATTERN;
     194             : 
     195             : private:
     196             :     nsCOMArray<nsIAtom> mIds;
     197             : };
     198             : 
     199           0 : class txKeyPattern : public txPattern
     200             : {
     201             : public:
     202           0 :     txKeyPattern(nsIAtom* aPrefix, nsIAtom* aLocalName,
     203             :                  int32_t aNSID, const nsAString& aValue)
     204           0 :         : mName(aNSID, aLocalName),
     205             : #ifdef TX_TO_STRING
     206             :           mPrefix(aPrefix),
     207             : #endif
     208           0 :           mValue(aValue)
     209             :     {
     210           0 :     }
     211             : 
     212             :     TX_DECL_PATTERN;
     213             : 
     214             : private:
     215             :     txExpandedName mName;
     216             : #ifdef TX_TO_STRING
     217             :     nsCOMPtr<nsIAtom> mPrefix;
     218             : #endif
     219             :     nsString mValue;
     220             : };
     221             : 
     222           0 : class txStepPattern : public txPattern,
     223             :                       public PredicateList
     224             : {
     225             : public:
     226           0 :     txStepPattern(txNodeTest* aNodeTest, bool isAttr)
     227           0 :         : mNodeTest(aNodeTest), mIsAttr(isAttr)
     228             :     {
     229           0 :     }
     230             : 
     231             :     TX_DECL_PATTERN;
     232             :     Type getType() override;
     233             : 
     234           0 :     txNodeTest* getNodeTest()
     235             :     {
     236           0 :       return mNodeTest;
     237             :     }
     238           0 :     void setNodeTest(txNodeTest* aNodeTest)
     239             :     {
     240           0 :       mNodeTest.forget();
     241           0 :       mNodeTest = aNodeTest;
     242           0 :     }
     243             : 
     244             : private:
     245             :     nsAutoPtr<txNodeTest> mNodeTest;
     246             :     bool mIsAttr;
     247             : };
     248             : 
     249             : #endif // TX_XSLT_PATTERNS_H

Generated by: LCOV version 1.13