123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005 |
- /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
- /* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
- #ifndef TRANSFRMX_EXPR_H
- #define TRANSFRMX_EXPR_H
- #include "mozilla/Attributes.h"
- #include "nsAutoPtr.h"
- #include "txExprResult.h"
- #include "txCore.h"
- #include "nsString.h"
- #include "txOwningArray.h"
- #include "nsIAtom.h"
- #ifdef DEBUG
- #define TX_TO_STRING
- #endif
- /*
- XPath class definitions.
- Much of this code was ported from XSL:P.
- */
- class nsIAtom;
- class txIMatchContext;
- class txIEvalContext;
- class txNodeSet;
- class txXPathNode;
- /**
- * A Base Class for all XSL Expressions
- **/
- class Expr
- {
- public:
- Expr()
- {
- MOZ_COUNT_CTOR(Expr);
- }
- virtual ~Expr()
- {
- MOZ_COUNT_DTOR(Expr);
- }
- /**
- * Evaluates this Expr based on the given context node and processor state
- * @param context the context node for evaluation of this Expr
- * @param ps the ContextState containing the stack information needed
- * for evaluation
- * @return the result of the evaluation
- **/
- virtual nsresult evaluate(txIEvalContext* aContext,
- txAExprResult** aResult) = 0;
- /**
- * Returns the type of this expression.
- */
- enum ExprType {
- LOCATIONSTEP_EXPR,
- PATH_EXPR,
- UNION_EXPR,
- LITERAL_EXPR,
- OTHER_EXPR
- };
- virtual ExprType getType()
- {
- return OTHER_EXPR;
- }
- /**
- * Returns the type or types of results this Expr return.
- */
- typedef uint16_t ResultType;
- enum {
- NODESET_RESULT = 0x01,
- BOOLEAN_RESULT = 0x02,
- NUMBER_RESULT = 0x04,
- STRING_RESULT = 0x08,
- RTF_RESULT = 0x10,
- ANY_RESULT = 0xFFFF
- };
- virtual ResultType getReturnType() = 0;
- bool canReturnType(ResultType aType)
- {
- return (getReturnType() & aType) != 0;
- }
- typedef uint16_t ContextSensitivity;
- enum {
- NO_CONTEXT = 0x00,
- NODE_CONTEXT = 0x01,
- POSITION_CONTEXT = 0x02,
- SIZE_CONTEXT = 0x04,
- NODESET_CONTEXT = POSITION_CONTEXT | SIZE_CONTEXT,
- VARIABLES_CONTEXT = 0x08,
- PRIVATE_CONTEXT = 0x10,
- ANY_CONTEXT = 0xFFFF
- };
- /**
- * Returns true if this expression is sensitive to *any* of
- * the requested contexts in aContexts.
- */
- virtual bool isSensitiveTo(ContextSensitivity aContexts) = 0;
- /**
- * Returns sub-expression at given position
- */
- virtual Expr* getSubExprAt(uint32_t aPos) = 0;
- /**
- * Replace sub-expression at given position. Does not delete the old
- * expression, that is the responsibility of the caller.
- */
- virtual void setSubExprAt(uint32_t aPos, Expr* aExpr) = 0;
- virtual nsresult evaluateToBool(txIEvalContext* aContext,
- bool& aResult);
- virtual nsresult evaluateToString(txIEvalContext* aContext,
- nsString& aResult);
- #ifdef TX_TO_STRING
- /**
- * Returns the String representation of this Expr.
- * @param dest the String to use when creating the String
- * representation. The String representation will be appended to
- * any data in the destination String, to allow cascading calls to
- * other #toString() methods for Expressions.
- * @return the String representation of this Expr.
- **/
- virtual void toString(nsAString& str) = 0;
- #endif
- }; //-- Expr
- #ifdef TX_TO_STRING
- #define TX_DECL_TOSTRING \
- void toString(nsAString& aDest) override;
- #define TX_DECL_GETNAMEATOM \
- nsresult getNameAtom(nsIAtom** aAtom) override;
- #else
- #define TX_DECL_TOSTRING
- #define TX_DECL_GETNAMEATOM
- #endif
- #define TX_DECL_EXPR_BASE \
- nsresult evaluate(txIEvalContext* aContext, txAExprResult** aResult) override; \
- ResultType getReturnType() override; \
- bool isSensitiveTo(ContextSensitivity aContexts) override;
- #define TX_DECL_EXPR \
- TX_DECL_EXPR_BASE \
- TX_DECL_TOSTRING \
- Expr* getSubExprAt(uint32_t aPos) override; \
- void setSubExprAt(uint32_t aPos, Expr* aExpr) override;
- #define TX_DECL_OPTIMIZABLE_EXPR \
- TX_DECL_EXPR \
- ExprType getType() override;
- #define TX_DECL_FUNCTION \
- TX_DECL_GETNAMEATOM \
- TX_DECL_EXPR_BASE
- #define TX_IMPL_EXPR_STUBS_BASE(_class, _ReturnType) \
- Expr::ResultType \
- _class::getReturnType() \
- { \
- return _ReturnType; \
- }
- #define TX_IMPL_EXPR_STUBS_0(_class, _ReturnType) \
- TX_IMPL_EXPR_STUBS_BASE(_class, _ReturnType) \
- Expr* \
- _class::getSubExprAt(uint32_t aPos) \
- { \
- return nullptr; \
- } \
- void \
- _class::setSubExprAt(uint32_t aPos, Expr* aExpr) \
- { \
- NS_NOTREACHED("setting bad subexpression index"); \
- }
- #define TX_IMPL_EXPR_STUBS_1(_class, _ReturnType, _Expr1) \
- TX_IMPL_EXPR_STUBS_BASE(_class, _ReturnType) \
- Expr* \
- _class::getSubExprAt(uint32_t aPos) \
- { \
- if (aPos == 0) { \
- return _Expr1; \
- } \
- return nullptr; \
- } \
- void \
- _class::setSubExprAt(uint32_t aPos, Expr* aExpr) \
- { \
- NS_ASSERTION(aPos < 1, "setting bad subexpression index");\
- _Expr1.forget(); \
- _Expr1 = aExpr; \
- }
- #define TX_IMPL_EXPR_STUBS_2(_class, _ReturnType, _Expr1, _Expr2) \
- TX_IMPL_EXPR_STUBS_BASE(_class, _ReturnType) \
- Expr* \
- _class::getSubExprAt(uint32_t aPos) \
- { \
- switch(aPos) { \
- case 0: \
- return _Expr1; \
- case 1: \
- return _Expr2; \
- default: \
- break; \
- } \
- return nullptr; \
- } \
- void \
- _class::setSubExprAt(uint32_t aPos, Expr* aExpr) \
- { \
- NS_ASSERTION(aPos < 2, "setting bad subexpression index");\
- if (aPos == 0) { \
- _Expr1.forget(); \
- _Expr1 = aExpr; \
- } \
- else { \
- _Expr2.forget(); \
- _Expr2 = aExpr; \
- } \
- }
- #define TX_IMPL_EXPR_STUBS_LIST(_class, _ReturnType, _ExprList) \
- TX_IMPL_EXPR_STUBS_BASE(_class, _ReturnType) \
- Expr* \
- _class::getSubExprAt(uint32_t aPos) \
- { \
- return _ExprList.SafeElementAt(aPos); \
- } \
- void \
- _class::setSubExprAt(uint32_t aPos, Expr* aExpr) \
- { \
- NS_ASSERTION(aPos < _ExprList.Length(), \
- "setting bad subexpression index"); \
- _ExprList[aPos] = aExpr; \
- }
- /**
- * This class represents a FunctionCall as defined by the XPath 1.0
- * Recommendation.
- **/
- class FunctionCall : public Expr
- {
- public:
- /**
- * Adds the given parameter to this FunctionCall's parameter list.
- * The ownership of the given Expr is passed over to the FunctionCall,
- * even on failure.
- * @param aExpr the Expr to add to this FunctionCall's parameter list
- * @return nsresult indicating out of memory
- */
- nsresult addParam(Expr* aExpr)
- {
- return mParams.AppendElement(aExpr) ?
- NS_OK : NS_ERROR_OUT_OF_MEMORY;
- }
- /**
- * Check if the number of parameters falls within a range.
- *
- * @param aParamCountMin minimum number of required parameters.
- * @param aParamCountMax maximum number of parameters. If aParamCountMax
- * is negative the maximum number is not checked.
- * @return boolean representing whether the number of parameters falls
- * within the expected range or not.
- *
- * XXX txIEvalContext should be txIParseContest, bug 143291
- */
- virtual bool requireParams(int32_t aParamCountMin,
- int32_t aParamCountMax,
- txIEvalContext* aContext);
- TX_DECL_TOSTRING
- Expr* getSubExprAt(uint32_t aPos) override;
- void setSubExprAt(uint32_t aPos, Expr* aExpr) override;
- protected:
- txOwningArray<Expr> mParams;
- /*
- * Evaluates the given Expression and converts its result to a number.
- */
- static nsresult evaluateToNumber(Expr* aExpr, txIEvalContext* aContext,
- double* aResult);
- /*
- * Evaluates the given Expression and converts its result to a NodeSet.
- * If the result is not a NodeSet an error is returned.
- */
- static nsresult evaluateToNodeSet(Expr* aExpr, txIEvalContext* aContext,
- txNodeSet** aResult);
- /**
- * Returns true if any argument is sensitive to the given context.
- */
- bool argsSensitiveTo(ContextSensitivity aContexts);
- #ifdef TX_TO_STRING
- /*
- * Returns the name of the function as an atom.
- */
- virtual nsresult getNameAtom(nsIAtom** aAtom) = 0;
- #endif
- };
- class txCoreFunctionCall : public FunctionCall
- {
- public:
- // This must be ordered in the same order as descriptTable in
- // txCoreFunctionCall.cpp. If you change one, change the other.
- enum eType {
- COUNT = 0, // count()
- ID, // id()
- LAST, // last()
- LOCAL_NAME, // local-name()
- NAMESPACE_URI, // namespace-uri()
- NAME, // name()
- POSITION, // position()
- CONCAT, // concat()
- CONTAINS, // contains()
- NORMALIZE_SPACE, // normalize-space()
- STARTS_WITH, // starts-with()
- STRING, // string()
- STRING_LENGTH, // string-length()
- SUBSTRING, // substring()
- SUBSTRING_AFTER, // substring-after()
- SUBSTRING_BEFORE, // substring-before()
- TRANSLATE, // translate()
- NUMBER, // number()
- ROUND, // round()
- FLOOR, // floor()
- CEILING, // ceiling()
- SUM, // sum()
- BOOLEAN, // boolean()
- _FALSE, // false()
- LANG, // lang()
- _NOT, // not()
- _TRUE // true()
- };
- /*
- * Creates a txCoreFunctionCall of the given type
- */
- explicit txCoreFunctionCall(eType aType) : mType(aType)
- {
- }
- TX_DECL_FUNCTION
- static bool getTypeFromAtom(nsIAtom* aName, eType& aType);
- private:
- eType mType;
- };
- /*
- * This class represents a NodeTest as defined by the XPath spec
- */
- class txNodeTest
- {
- public:
- txNodeTest()
- {
- MOZ_COUNT_CTOR(txNodeTest);
- }
- virtual ~txNodeTest()
- {
- MOZ_COUNT_DTOR(txNodeTest);
- }
- /*
- * Virtual methods
- * pretty much a txPattern, but not supposed to be used
- * standalone. The NodeTest node() is different to the
- * Pattern "node()" (document node isn't matched)
- */
- virtual bool matches(const txXPathNode& aNode,
- txIMatchContext* aContext) = 0;
- virtual double getDefaultPriority() = 0;
- /**
- * Returns the type of this nodetest.
- */
- enum NodeTestType {
- NAME_TEST,
- NODETYPE_TEST,
- OTHER_TEST
- };
- virtual NodeTestType getType()
- {
- return OTHER_TEST;
- }
- /**
- * Returns true if this expression is sensitive to *any* of
- * the requested flags.
- */
- virtual bool isSensitiveTo(Expr::ContextSensitivity aContext) = 0;
- #ifdef TX_TO_STRING
- virtual void toString(nsAString& aDest) = 0;
- #endif
- };
- #define TX_DECL_NODE_TEST \
- TX_DECL_TOSTRING \
- bool matches(const txXPathNode& aNode, txIMatchContext* aContext) override; \
- double getDefaultPriority() override; \
- bool isSensitiveTo(Expr::ContextSensitivity aContext) override;
- /*
- * This class represents a NameTest as defined by the XPath spec
- */
- class txNameTest : public txNodeTest
- {
- public:
- /*
- * Creates a new txNameTest with the given type and the given
- * principal node type
- */
- txNameTest(nsIAtom* aPrefix, nsIAtom* aLocalName, int32_t aNSID,
- uint16_t aNodeType);
- NodeTestType getType() override;
- TX_DECL_NODE_TEST
- nsCOMPtr<nsIAtom> mPrefix;
- nsCOMPtr<nsIAtom> mLocalName;
- int32_t mNamespace;
- private:
- uint16_t mNodeType;
- };
- /*
- * This class represents a NodeType as defined by the XPath spec
- */
- class txNodeTypeTest : public txNodeTest
- {
- public:
- enum NodeType {
- COMMENT_TYPE,
- TEXT_TYPE,
- PI_TYPE,
- NODE_TYPE
- };
- /*
- * Creates a new txNodeTypeTest of the given type
- */
- explicit txNodeTypeTest(NodeType aNodeType)
- : mNodeType(aNodeType)
- {
- }
- /*
- * Sets the name of the node to match. Only availible for pi nodes
- */
- void setNodeName(const nsAString& aName)
- {
- mNodeName = NS_Atomize(aName);
- }
- NodeType getNodeTestType()
- {
- return mNodeType;
- }
- NodeTestType getType() override;
- TX_DECL_NODE_TEST
- private:
- NodeType mNodeType;
- nsCOMPtr<nsIAtom> mNodeName;
- };
- /**
- * Class representing a nodetest combined with a predicate. May only be used
- * if the predicate is not sensitive to the context-nodelist.
- */
- class txPredicatedNodeTest : public txNodeTest
- {
- public:
- txPredicatedNodeTest(txNodeTest* aNodeTest, Expr* aPredicate);
- TX_DECL_NODE_TEST
- private:
- nsAutoPtr<txNodeTest> mNodeTest;
- nsAutoPtr<Expr> mPredicate;
- };
- /**
- * Represents an ordered list of Predicates,
- * for use with Step and Filter Expressions
- **/
- class PredicateList {
- public:
- /**
- * Adds the given Expr to the list.
- * The ownership of the given Expr is passed over the PredicateList,
- * even on failure.
- * @param aExpr the Expr to add to the list
- * @return nsresult indicating out of memory
- */
- nsresult add(Expr* aExpr)
- {
- NS_ASSERTION(aExpr, "missing expression");
- return mPredicates.AppendElement(aExpr) ?
- NS_OK : NS_ERROR_OUT_OF_MEMORY;
- }
- nsresult evaluatePredicates(txNodeSet* aNodes, txIMatchContext* aContext);
- /**
- * Drops the first predicate without deleting it.
- */
- void dropFirst()
- {
- mPredicates.RemoveElementAt(0);
- }
- /**
- * returns true if this predicate list is empty
- **/
- bool isEmpty()
- {
- return mPredicates.IsEmpty();
- }
- #ifdef TX_TO_STRING
- /**
- * Returns the String representation of this PredicateList.
- * @param dest the String to use when creating the String
- * representation. The String representation will be appended to
- * any data in the destination String, to allow cascading calls to
- * other #toString() methods for Expressions.
- * @return the String representation of this PredicateList.
- **/
- void toString(nsAString& dest);
- #endif
- protected:
- bool isSensitiveTo(Expr::ContextSensitivity aContext);
- Expr* getSubExprAt(uint32_t aPos)
- {
- return mPredicates.SafeElementAt(aPos);
- }
- void setSubExprAt(uint32_t aPos, Expr* aExpr)
- {
- NS_ASSERTION(aPos < mPredicates.Length(),
- "setting bad subexpression index");
- mPredicates[aPos] = aExpr;
- }
- //-- list of predicates
- txOwningArray<Expr> mPredicates;
- }; //-- PredicateList
- class LocationStep : public Expr,
- public PredicateList
- {
- public:
- enum LocationStepType {
- ANCESTOR_AXIS = 0,
- ANCESTOR_OR_SELF_AXIS,
- ATTRIBUTE_AXIS,
- CHILD_AXIS,
- DESCENDANT_AXIS,
- DESCENDANT_OR_SELF_AXIS,
- FOLLOWING_AXIS,
- FOLLOWING_SIBLING_AXIS,
- NAMESPACE_AXIS,
- PARENT_AXIS,
- PRECEDING_AXIS,
- PRECEDING_SIBLING_AXIS,
- SELF_AXIS
- };
- /**
- * Creates a new LocationStep using the given NodeExpr and Axis Identifier
- * @param nodeExpr the NodeExpr to use when matching Nodes
- * @param axisIdentifier the Axis Identifier in which to search for nodes
- **/
- LocationStep(txNodeTest* aNodeTest,
- LocationStepType aAxisIdentifier)
- : mNodeTest(aNodeTest),
- mAxisIdentifier(aAxisIdentifier)
- {
- }
- TX_DECL_OPTIMIZABLE_EXPR
- txNodeTest* getNodeTest()
- {
- return mNodeTest;
- }
- void setNodeTest(txNodeTest* aNodeTest)
- {
- mNodeTest.forget();
- mNodeTest = aNodeTest;
- }
- LocationStepType getAxisIdentifier()
- {
- return mAxisIdentifier;
- }
- void setAxisIdentifier(LocationStepType aAxisIdentifier)
- {
- mAxisIdentifier = aAxisIdentifier;
- }
- private:
- void fromDescendants(const txXPathNode& aNode, txIMatchContext* aCs,
- txNodeSet* aNodes);
- void fromDescendantsRev(const txXPathNode& aNode, txIMatchContext* aCs,
- txNodeSet* aNodes);
- nsAutoPtr<txNodeTest> mNodeTest;
- LocationStepType mAxisIdentifier;
- };
- class FilterExpr : public Expr,
- public PredicateList
- {
- public:
- /**
- * Creates a new FilterExpr using the given Expr
- * @param expr the Expr to use for evaluation
- */
- explicit FilterExpr(Expr* aExpr)
- : expr(aExpr)
- {
- }
- TX_DECL_EXPR
- private:
- nsAutoPtr<Expr> expr;
- }; //-- FilterExpr
- class txLiteralExpr : public Expr {
- public:
- explicit txLiteralExpr(double aDbl)
- : mValue(new NumberResult(aDbl, nullptr))
- {
- }
- explicit txLiteralExpr(const nsAString& aStr)
- : mValue(new StringResult(aStr, nullptr))
- {
- }
- explicit txLiteralExpr(txAExprResult* aValue)
- : mValue(aValue)
- {
- }
- TX_DECL_EXPR
- private:
- RefPtr<txAExprResult> mValue;
- };
- /**
- * Represents an UnaryExpr. Returns the negative value of its expr.
- **/
- class UnaryExpr : public Expr {
- public:
- explicit UnaryExpr(Expr* aExpr)
- : expr(aExpr)
- {
- }
- TX_DECL_EXPR
- private:
- nsAutoPtr<Expr> expr;
- }; //-- UnaryExpr
- /**
- * Represents a BooleanExpr, a binary expression that
- * performs a boolean operation between its lvalue and rvalue.
- **/
- class BooleanExpr : public Expr
- {
- public:
- //-- BooleanExpr Types
- enum _BooleanExprType { AND = 1, OR };
- BooleanExpr(Expr* aLeftExpr, Expr* aRightExpr, short aOp)
- : leftExpr(aLeftExpr),
- rightExpr(aRightExpr),
- op(aOp)
- {
- }
- TX_DECL_EXPR
- private:
- nsAutoPtr<Expr> leftExpr, rightExpr;
- short op;
- }; //-- BooleanExpr
- /**
- * Represents a MultiplicativeExpr, a binary expression that
- * performs a multiplicative operation between its lvalue and rvalue:
- * * : multiply
- * mod : modulus
- * div : divide
- *
- **/
- class txNumberExpr : public Expr
- {
- public:
- enum eOp { ADD, SUBTRACT, DIVIDE, MULTIPLY, MODULUS };
- txNumberExpr(Expr* aLeftExpr, Expr* aRightExpr, eOp aOp)
- : mLeftExpr(aLeftExpr),
- mRightExpr(aRightExpr),
- mOp(aOp)
- {
- }
- TX_DECL_EXPR
- private:
- nsAutoPtr<Expr> mLeftExpr, mRightExpr;
- eOp mOp;
- }; //-- MultiplicativeExpr
- /**
- * Represents a RelationalExpr, an expression that compares its lvalue
- * to its rvalue using:
- * = : equal to
- * < : less than
- * > : greater than
- * <= : less than or equal to
- * >= : greater than or equal to
- *
- **/
- class RelationalExpr : public Expr
- {
- public:
- enum RelationalExprType {
- EQUAL,
- NOT_EQUAL,
- LESS_THAN,
- GREATER_THAN,
- LESS_OR_EQUAL,
- GREATER_OR_EQUAL
- };
- RelationalExpr(Expr* aLeftExpr, Expr* aRightExpr, RelationalExprType aOp)
- : mLeftExpr(aLeftExpr),
- mRightExpr(aRightExpr),
- mOp(aOp)
- {
- }
- TX_DECL_EXPR
- private:
- bool compareResults(txIEvalContext* aContext, txAExprResult* aLeft,
- txAExprResult* aRight);
- nsAutoPtr<Expr> mLeftExpr;
- nsAutoPtr<Expr> mRightExpr;
- RelationalExprType mOp;
- };
- /**
- * VariableRefExpr
- * Represents a variable reference ($refname)
- **/
- class VariableRefExpr : public Expr {
- public:
- VariableRefExpr(nsIAtom* aPrefix, nsIAtom* aLocalName, int32_t aNSID);
- TX_DECL_EXPR
- private:
- nsCOMPtr<nsIAtom> mPrefix;
- nsCOMPtr<nsIAtom> mLocalName;
- int32_t mNamespace;
- };
- /**
- * Represents a PathExpr
- **/
- class PathExpr : public Expr {
- public:
- //-- Path Operators
- //-- RELATIVE_OP is the default
- //-- LF, changed from static const short to enum
- enum PathOperator { RELATIVE_OP, DESCENDANT_OP };
- /**
- * Adds the Expr to this PathExpr
- * The ownership of the given Expr is passed over the PathExpr,
- * even on failure.
- * @param aExpr the Expr to add to this PathExpr
- * @return nsresult indicating out of memory
- */
- nsresult addExpr(Expr* aExpr, PathOperator pathOp);
- /**
- * Removes and deletes the expression at the given index.
- */
- void deleteExprAt(uint32_t aPos)
- {
- NS_ASSERTION(aPos < mItems.Length(),
- "killing bad expression index");
- mItems.RemoveElementAt(aPos);
- }
- TX_DECL_OPTIMIZABLE_EXPR
- PathOperator getPathOpAt(uint32_t aPos)
- {
- NS_ASSERTION(aPos < mItems.Length(), "getting bad pathop index");
- return mItems[aPos].pathOp;
- }
- void setPathOpAt(uint32_t aPos, PathOperator aPathOp)
- {
- NS_ASSERTION(aPos < mItems.Length(), "setting bad pathop index");
- mItems[aPos].pathOp = aPathOp;
- }
- private:
- class PathExprItem {
- public:
- nsAutoPtr<Expr> expr;
- PathOperator pathOp;
- };
- nsTArray<PathExprItem> mItems;
- /*
- * Selects from the descendants of the context node
- * all nodes that match the Expr
- */
- nsresult evalDescendants(Expr* aStep, const txXPathNode& aNode,
- txIMatchContext* aContext,
- txNodeSet* resNodes);
- };
- /**
- * This class represents a RootExpr, which only matches the Document node
- **/
- class RootExpr : public Expr {
- public:
- /**
- * Creates a new RootExpr
- */
- RootExpr()
- #ifdef TX_TO_STRING
- : mSerialize(true)
- #endif
- {
- }
- TX_DECL_EXPR
- #ifdef TX_TO_STRING
- public:
- void setSerialize(bool aSerialize)
- {
- mSerialize = aSerialize;
- }
- private:
- // When a RootExpr is used in a PathExpr it shouldn't be serialized
- bool mSerialize;
- #endif
- }; //-- RootExpr
- /**
- * Represents a UnionExpr
- **/
- class UnionExpr : public Expr {
- public:
- /**
- * Adds the PathExpr to this UnionExpr
- * The ownership of the given Expr is passed over the UnionExpr,
- * even on failure.
- * @param aExpr the Expr to add to this UnionExpr
- * @return nsresult indicating out of memory
- */
- nsresult addExpr(Expr* aExpr)
- {
- return mExpressions.AppendElement(aExpr) ?
- NS_OK : NS_ERROR_OUT_OF_MEMORY;
- }
- /**
- * Removes and deletes the expression at the given index.
- */
- void deleteExprAt(uint32_t aPos)
- {
- NS_ASSERTION(aPos < mExpressions.Length(),
- "killing bad expression index");
- delete mExpressions[aPos];
- mExpressions.RemoveElementAt(aPos);
- }
- TX_DECL_OPTIMIZABLE_EXPR
- private:
- txOwningArray<Expr> mExpressions;
- }; //-- UnionExpr
- /**
- * Class specializing in executing expressions like "@foo" where we are
- * interested in different result-types, and expressions like "@foo = 'hi'"
- */
- class txNamedAttributeStep : public Expr
- {
- public:
- txNamedAttributeStep(int32_t aNsID, nsIAtom* aPrefix,
- nsIAtom* aLocalName);
- TX_DECL_EXPR
- private:
- int32_t mNamespace;
- nsCOMPtr<nsIAtom> mPrefix;
- nsCOMPtr<nsIAtom> mLocalName;
- };
- /**
- *
- */
- class txUnionNodeTest : public txNodeTest
- {
- public:
- nsresult addNodeTest(txNodeTest* aNodeTest)
- {
- return mNodeTests.AppendElement(aNodeTest) ?
- NS_OK : NS_ERROR_OUT_OF_MEMORY;
- }
- TX_DECL_NODE_TEST
- private:
- txOwningArray<txNodeTest> mNodeTests;
- };
- /**
- * Expression that failed to parse
- */
- class txErrorExpr : public Expr
- {
- public:
- #ifdef TX_TO_STRING
- explicit txErrorExpr(const nsAString& aStr)
- : mStr(aStr)
- {
- }
- #endif
- TX_DECL_EXPR
- #ifdef TX_TO_STRING
- private:
- nsString mStr;
- #endif
- };
- #endif
|