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 TRANSFRMX_TXEXECUTIONSTATE_H
7 : #define TRANSFRMX_TXEXECUTIONSTATE_H
8 :
9 : #include "txCore.h"
10 : #include "txStack.h"
11 : #include "txXMLUtils.h"
12 : #include "txIXPathContext.h"
13 : #include "txVariableMap.h"
14 : #include "nsTHashtable.h"
15 : #include "nsHashKeys.h"
16 : #include "txKey.h"
17 : #include "txStylesheet.h"
18 : #include "txXPathTreeWalker.h"
19 : #include "nsTArray.h"
20 :
21 : class txAOutputHandlerFactory;
22 : class txAXMLEventHandler;
23 : class txInstruction;
24 :
25 : class txLoadedDocumentEntry : public nsStringHashKey
26 : {
27 : public:
28 0 : explicit txLoadedDocumentEntry(KeyTypePointer aStr) : nsStringHashKey(aStr),
29 0 : mLoadResult(NS_OK)
30 : {
31 0 : }
32 : txLoadedDocumentEntry(const txLoadedDocumentEntry& aToCopy)
33 : : nsStringHashKey(aToCopy)
34 : {
35 : NS_ERROR("We're horked.");
36 : }
37 0 : ~txLoadedDocumentEntry()
38 0 : {
39 0 : if (mDocument) {
40 0 : txXPathNodeUtils::release(mDocument);
41 : }
42 0 : }
43 0 : bool LoadingFailed()
44 : {
45 0 : NS_ASSERTION(NS_SUCCEEDED(mLoadResult) || !mDocument,
46 : "Load failed but we still got a document?");
47 :
48 0 : return NS_FAILED(mLoadResult);
49 : }
50 :
51 : nsAutoPtr<txXPathNode> mDocument;
52 : nsresult mLoadResult;
53 : };
54 :
55 : class txLoadedDocumentsHash : public nsTHashtable<txLoadedDocumentEntry>
56 : {
57 : public:
58 0 : txLoadedDocumentsHash()
59 0 : : nsTHashtable<txLoadedDocumentEntry>(4),
60 0 : mSourceDocument(nullptr)
61 : {
62 0 : }
63 : ~txLoadedDocumentsHash();
64 : MOZ_MUST_USE nsresult init(txXPathNode* aSourceDocument);
65 :
66 : private:
67 : friend class txExecutionState;
68 : txXPathNode* mSourceDocument;
69 : };
70 :
71 :
72 : class txExecutionState : public txIMatchContext
73 : {
74 : public:
75 : txExecutionState(txStylesheet* aStylesheet, bool aDisableLoads);
76 : ~txExecutionState();
77 : nsresult init(const txXPathNode& aNode,
78 : txOwningExpandedNameMap<txIGlobalParameter>* aGlobalParams);
79 : nsresult end(nsresult aResult);
80 :
81 : TX_DECL_MATCH_CONTEXT;
82 :
83 : /**
84 : * Struct holding information about a current template rule
85 : */
86 0 : class TemplateRule {
87 : public:
88 : txStylesheet::ImportFrame* mFrame;
89 : int32_t mModeNsId;
90 : nsCOMPtr<nsIAtom> mModeLocalName;
91 : txVariableMap* mParams;
92 : };
93 :
94 : // Stack functions
95 : nsresult pushEvalContext(txIEvalContext* aContext);
96 : txIEvalContext* popEvalContext();
97 :
98 : /**
99 : * Helper that deletes all entries before |aContext| and then
100 : * pops it off the stack. The caller must delete |aContext| if
101 : * desired.
102 : */
103 : void popAndDeleteEvalContextUntil(txIEvalContext* aContext);
104 :
105 : nsresult pushBool(bool aBool);
106 : bool popBool();
107 : nsresult pushResultHandler(txAXMLEventHandler* aHandler);
108 : txAXMLEventHandler* popResultHandler();
109 : void pushTemplateRule(txStylesheet::ImportFrame* aFrame,
110 : const txExpandedName& aMode,
111 : txVariableMap* aParams);
112 : void popTemplateRule();
113 : nsresult pushParamMap(txVariableMap* aParams);
114 : txVariableMap* popParamMap();
115 :
116 : // state-getting functions
117 : txIEvalContext* getEvalContext();
118 : const txXPathNode* retrieveDocument(const nsAString& aUri);
119 : nsresult getKeyNodes(const txExpandedName& aKeyName,
120 : const txXPathNode& aRoot,
121 : const nsAString& aKeyValue, bool aIndexIfNotFound,
122 : txNodeSet** aResult);
123 : TemplateRule* getCurrentTemplateRule();
124 0 : const txXPathNode& getSourceDocument()
125 : {
126 0 : NS_ASSERTION(mLoadedDocuments.mSourceDocument,
127 : "Need a source document!");
128 :
129 0 : return *mLoadedDocuments.mSourceDocument;
130 : }
131 :
132 : // state-modification functions
133 : txInstruction* getNextInstruction();
134 : nsresult runTemplate(txInstruction* aInstruction);
135 : nsresult runTemplate(txInstruction* aInstruction,
136 : txInstruction* aReturnTo);
137 : void gotoInstruction(txInstruction* aNext);
138 : void returnFromTemplate();
139 : nsresult bindVariable(const txExpandedName& aName,
140 : txAExprResult* aValue);
141 : void removeVariable(const txExpandedName& aName);
142 :
143 : txAXMLEventHandler* mOutputHandler;
144 : txAXMLEventHandler* mResultHandler;
145 : nsAutoPtr<txAXMLEventHandler> mObsoleteHandler;
146 : txAOutputHandlerFactory* mOutputHandlerFactory;
147 :
148 : nsAutoPtr<txVariableMap> mTemplateParams;
149 :
150 : RefPtr<txStylesheet> mStylesheet;
151 :
152 : private:
153 : txStack mReturnStack;
154 : txStack mLocalVarsStack;
155 : txStack mEvalContextStack;
156 : nsTArray<bool> mBoolStack;
157 : txStack mResultHandlerStack;
158 : txStack mParamStack;
159 : txInstruction* mNextInstruction;
160 : txVariableMap* mLocalVariables;
161 : txVariableMap mGlobalVariableValues;
162 : RefPtr<txAExprResult> mGlobalVarPlaceholderValue;
163 : int32_t mRecursionDepth;
164 :
165 : AutoTArray<TemplateRule, 10> mTemplateRules;
166 :
167 : txIEvalContext* mEvalContext;
168 : txIEvalContext* mInitialEvalContext;
169 : //Document* mRTFDocument;
170 : txOwningExpandedNameMap<txIGlobalParameter>* mGlobalParams;
171 :
172 : txLoadedDocumentsHash mLoadedDocuments;
173 : txKeyHash mKeyHash;
174 : RefPtr<txResultRecycler> mRecycler;
175 : bool mDisableLoads;
176 :
177 : static const int32_t kMaxRecursionDepth;
178 : };
179 :
180 : #endif
|