Merge lp:~zorba-coders/zorba/expr-memman into lp:zorba
- expr-memman
- Merge into trunk
Proposed by
Markos Zaharioudakis
Status: | Merged |
---|---|
Merged at revision: | 11007 |
Proposed branch: | lp:~zorba-coders/zorba/expr-memman |
Merge into: | lp:zorba |
Diff against target: |
50289 lines (+40515/-1677) 106 files modified
bin/zorbacmd.cpp (+34/-0) doc/c/examples/ccontext.c (+6/-5) src/api/auditimpl.cpp (+5/-0) src/api/dynamiccontextimpl.cpp (+28/-27) src/api/dynamiccontextimpl.h (+5/-4) src/api/staticcontextimpl.cpp (+25/-11) src/api/staticcontextimpl.h (+3/-1) src/api/xqueryimpl.cpp (+45/-38) src/compiler/api/compiler_api.cpp (+40/-21) src/compiler/api/compilercb.cpp (+16/-8) src/compiler/api/compilercb.h (+18/-8) src/compiler/codegen/plan_visitor.cpp (+27/-16) src/compiler/expression/CMakeLists.txt (+3/-1) src/compiler/expression/expr.cpp (+161/-125) src/compiler/expression/expr.h (+190/-121) src/compiler/expression/expr_base.cpp (+21/-17) src/compiler/expression/expr_base.h (+13/-5) src/compiler/expression/expr_classes.h (+23/-23) src/compiler/expression/expr_consts.h (+9/-9) src/compiler/expression/expr_manager.cpp (+884/-0) src/compiler/expression/expr_manager.h (+506/-0) src/compiler/expression/flwor_expr.cpp (+64/-33) src/compiler/expression/flwor_expr.h (+15/-4) src/compiler/expression/fo_expr.cpp (+15/-9) src/compiler/expression/fo_expr.h (+11/-4) src/compiler/expression/ft_expr.cpp (+8/-5) src/compiler/expression/ft_expr.h (+8/-5) src/compiler/expression/function_item_expr.cpp (+12/-8) src/compiler/expression/function_item_expr.h (+20/-11) src/compiler/expression/json_exprs.cpp (+17/-13) src/compiler/expression/json_exprs.h (+19/-10) src/compiler/expression/mem_manager.cpp (+57/-0) src/compiler/expression/mem_manager.h (+99/-0) src/compiler/expression/path_expr.cpp (+19/-17) src/compiler/expression/path_expr.h (+25/-19) src/compiler/expression/script_exprs.cpp (+41/-33) src/compiler/expression/script_exprs.h (+63/-38) src/compiler/expression/update_exprs.cpp (+33/-24) src/compiler/expression/update_exprs.h (+73/-52) src/compiler/expression/var_expr.cpp (+81/-44) src/compiler/expression/var_expr.h (+27/-21) src/compiler/rewriter/framework/rewriter_context.cpp (+4/-1) src/compiler/rewriter/framework/rewriter_context.h (+11/-8) src/compiler/rewriter/rules/expr_minimize_rules.cpp (+14/-14) src/compiler/rewriter/rules/flwor_rules.cpp (+38/-32) src/compiler/rewriter/rules/fold_rules.cpp (+53/-50) src/compiler/rewriter/rules/hoist_rules.cpp (+18/-18) src/compiler/rewriter/rules/index_join_rule.cpp (+30/-30) src/compiler/rewriter/rules/nodeid_rules.cpp (+12/-6) src/compiler/rewriter/rules/path_rules.cpp (+9/-9) src/compiler/rewriter/rules/type_rules.cpp (+15/-13) src/compiler/rewriter/tools/udf_graph.cpp (+1/-1) src/compiler/translator/translator.cpp (+483/-364) src/compiler/translator/translator.h (+4/-4) src/compiler/xqddf/value_index.cpp (+32/-35) src/compiler/xqddf/value_index.h (+34/-31) src/context/static_context.cpp (+137/-61) src/context/static_context.h (+72/-19) src/debugger/debugger_runtime.cpp (+21/-14) src/functions/udf.cpp (+15/-15) src/functions/udf.h (+3/-3) src/runtime/core/fncall_iterator.cpp (+1/-1) src/runtime/eval/eval.cpp (+131/-89) src/runtime/eval/eval.h (+49/-16) src/runtime/function_item/function_item.cpp (+20/-20) src/runtime/function_item/function_item.h (+6/-6) src/runtime/introspection/pregenerated/sctx.cpp (+0/-1) src/runtime/introspection/pregenerated/sctx.h (+3/-2) src/runtime/introspection/sctx_impl.cpp (+1/-3) src/runtime/spec/introspection/sctx.xml (+7/-4) src/store/naive/string_pool.cpp (+10/-7) src/unit_tests/CMakeLists.txt (+4/-0) src/unit_tests/memory_manager.cpp (+204/-0) src/unit_tests/unit_test_list.h (+4/-0) src/unit_tests/unit_tests.cpp (+6/-3) src/zorbaserialization/archiver_consts.h (+1/-0) src/zorbautils/hashmap.h (+9/-0) test/rbkt/Queries/zorba/functx/functx-x-1.xqlib (+182/-0) test/rbkt/Queries/zorba/functx/functx-x-10.xqlib (+1663/-0) test/rbkt/Queries/zorba/functx/functx-x-2.xqlib (+345/-0) test/rbkt/Queries/zorba/functx/functx-x-3.xqlib (+511/-0) test/rbkt/Queries/zorba/functx/functx-x-4.xqlib (+675/-0) test/rbkt/Queries/zorba/functx/functx-x-5.xqlib (+841/-0) test/rbkt/Queries/zorba/functx/functx-x-6.xqlib (+1007/-0) test/rbkt/Queries/zorba/functx/functx-x-7.xqlib (+1170/-0) test/rbkt/Queries/zorba/functx/functx-x-8.xqlib (+1335/-0) test/rbkt/Queries/zorba/functx/functx-x-9.xqlib (+1500/-0) test/rbkt/Queries/zorba/functx/functx-x-call.xq (+44/-0) test/rbkt/Queries/zorba/functx/functx-x-x.xq (+33/-0) test/rbkt/Queries/zorba/functx/functx1.xqlib (+2695/-0) test/rbkt/Queries/zorba/functx/functx10.xqlib (+2695/-0) test/rbkt/Queries/zorba/functx/functx2.xqlib (+2695/-0) test/rbkt/Queries/zorba/functx/functx3.xqlib (+2695/-0) test/rbkt/Queries/zorba/functx/functx4.xqlib (+2695/-0) test/rbkt/Queries/zorba/functx/functx5.xqlib (+2695/-0) test/rbkt/Queries/zorba/functx/functx6.xqlib (+2695/-0) test/rbkt/Queries/zorba/functx/functx7.xqlib (+2695/-0) test/rbkt/Queries/zorba/functx/functx8.xqlib (+2695/-0) test/rbkt/Queries/zorba/functx/functx9.xqlib (+2695/-0) test/rbkt/Queries/zorba/modules/extvarModule-A.xqlib (+1/-0) test/rbkt/Queries/zorba/reflection/client.xqlib (+8/-3) test/rbkt/Queries/zorba/reflection/reflection-eval-04.spec (+1/-0) test/rbkt/Queries/zorba/reflection/reflection-eval-04.xq (+5/-0) test/rbkt/Queries/zorba/xqddf/test1_mod2.xqlib (+3/-0) test/rbkt/Queries/zorba/xqddf/test4.xqlib (+6/-1) test/unit/CMakeLists.txt (+4/-3) |
To merge this branch: | bzr merge lp:~zorba-coders/zorba/expr-memman |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Markos Zaharioudakis | Pending | ||
Review via email: mp+112184@code.launchpad.net |
Commit message
New memory management for compiler expressions
Description of the change
New memory management for compiler expressions
To post a comment you must log in.
- 10875. By Carlos Manuel Lopez
-
Made all constructors for exprs protected, made more calls for new exprs into factory calls. Exprs now contain a pointer to the ExprManager that created them.
- 10876. By Carlos Manuel Lopez
-
Changed the way in which objects are deleted.
- 10877. By Carlos Manuel Lopez
-
Merged Markos changes and trunk, and fixed all conflicts.
- 10878. By Carlos Manuel Lopez
-
Fixed a few issues remaining from the previous merge.
- 10879. By Carlos Manuel Lopez
-
Merged trunk.
- 10880. By Carlos Manuel Lopez
-
Fixed a conflict.
- 10881. By Carlos Manuel Lopez
-
Merged Marko's code changes.
- 10882. By Carlos Manuel Lopez
-
Made Exprs contain a CompilerCB instead of the ExprManager.
- 10883. By Carlos Manuel Lopez
-
Merged Marko's changes, fixed a few conflicts.
- 10884. By Carlos Manuel Lopez
-
Merged trunk.
- 10885. By Carlos Manuel Lopez
-
Merged marko's changes.
- 10886. By Markos Zaharioudakis
-
merged MemPage class into MemoryManager
- 10887. By Markos Zaharioudakis
-
disabled auditing in zorbacmd
- 10888. By Markos Zaharioudakis
-
merge from trunk
- 10889. By Markos Zaharioudakis
-
merge from markos-scratch
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'bin/zorbacmd.cpp' |
2 | --- bin/zorbacmd.cpp 2012-07-24 08:48:48 +0000 |
3 | +++ bin/zorbacmd.cpp 2012-08-10 11:20:27 +0000 |
4 | @@ -39,6 +39,9 @@ |
5 | #include <zorba/xquery_functions.h> |
6 | #include <zorba/uri_resolvers.h> |
7 | #include <zorba/serialization_callback.h> |
8 | +#include <zorba/audit.h> |
9 | +#include <zorba/audit_scoped.h> |
10 | + |
11 | #include <zorba/store_manager.h> |
12 | |
13 | //#define DO_AUDIT |
14 | @@ -66,6 +69,8 @@ |
15 | # include "system/properties.h" |
16 | #endif |
17 | |
18 | +//#define DO_AUDIT |
19 | + |
20 | using namespace zorba; |
21 | namespace zorbatm = zorba::time; |
22 | |
23 | @@ -181,6 +186,35 @@ |
24 | } |
25 | } |
26 | |
27 | +#ifdef DO_AUDIT |
28 | + zorba::audit::Provider* lAuditProvider = zorba->getAuditProvider(); |
29 | + zorba::audit::Configuration* config = lAuditProvider->createConfiguration(); |
30 | + std::vector<zorba::String> property_names; |
31 | + zorba::audit::Configuration::getPropertyNames(property_names); |
32 | + |
33 | + bool lIsStatic; |
34 | + |
35 | + lIsStatic = zorba::audit::Configuration:: |
36 | + enableProperty(config, property_names, "xquery/compilation/parse-duration"); |
37 | + assert(lIsStatic); |
38 | + |
39 | + lIsStatic = zorba::audit::Configuration:: |
40 | + enableProperty(config, property_names, "xquery/compilation/translation-duration"); |
41 | + assert(lIsStatic); |
42 | + |
43 | + lIsStatic = zorba::audit::Configuration:: |
44 | + enableProperty(config, property_names, "xquery/compilation/optimization-duration"); |
45 | + assert(lIsStatic); |
46 | + |
47 | + lIsStatic = zorba::audit::Configuration:: |
48 | + enableProperty(config, property_names, "xquery/compilation/codegeneration-duration"); |
49 | + assert(lIsStatic); |
50 | + |
51 | + zorba::audit::Event* event = lAuditProvider->createEvent(config); |
52 | + |
53 | + sctx->setAuditEvent(event); |
54 | +#endif // DO_AUDIT |
55 | + |
56 | #ifndef ZORBA_NO_FULL_TEXT |
57 | { |
58 | ZorbaCMDProperties::FullText_t::const_iterator lIter = props.stopWordsBegin(); |
59 | |
60 | === modified file 'doc/c/examples/ccontext.c' |
61 | --- doc/c/examples/ccontext.c 2012-07-24 08:48:48 +0000 |
62 | +++ doc/c/examples/ccontext.c 2012-08-10 11:20:27 +0000 |
63 | @@ -207,7 +207,8 @@ |
64 | lExpr2->execute(lExpr2, lContext, &lSequence2); |
65 | |
66 | // iterate over the result two times |
67 | - while ( lSequence2->next(lSequence2) != XQC_END_OF_SEQUENCE ) { |
68 | + while ( lSequence2->next(lSequence2) != XQC_END_OF_SEQUENCE ) |
69 | + { |
70 | lSequence2->string_value(lSequence2, &lStringValue); |
71 | printf("%s ", lStringValue); |
72 | } |
73 | @@ -349,7 +350,7 @@ |
74 | |
75 | if ( zorba_implementation(&impl, store) != XQC_NO_ERROR) |
76 | return 1; |
77 | - |
78 | + /* |
79 | printf("executing C example 1\n"); |
80 | res = ccontext_example_1(impl); |
81 | if (!res) { impl->free(impl); return 1; }; |
82 | @@ -364,12 +365,12 @@ |
83 | res = ccontext_example_3(impl); |
84 | if (!res) { impl->free(impl); return 1; }; |
85 | printf("\n"); |
86 | - |
87 | + */ |
88 | printf("executing C example 4\n"); |
89 | res = ccontext_example_4(impl); |
90 | if (!res) { impl->free(impl); return 1; }; |
91 | printf("\n"); |
92 | - |
93 | + /* |
94 | printf("executing C example 5\n"); |
95 | res = ccontext_example_5(impl); |
96 | if (!res) { impl->free(impl); return 1; }; |
97 | @@ -379,7 +380,7 @@ |
98 | res = ccontext_example_6(impl); |
99 | if (!res) { impl->free(impl); return 1; }; |
100 | printf("\n"); |
101 | - |
102 | + */ |
103 | impl->free(impl); |
104 | shutdown_store(store); |
105 | return 0; |
106 | |
107 | === modified file 'src/api/auditimpl.cpp' |
108 | --- src/api/auditimpl.cpp 2012-07-24 08:48:48 +0000 |
109 | +++ src/api/auditimpl.cpp 2012-08-10 11:20:27 +0000 |
110 | @@ -59,14 +59,19 @@ |
111 | //************************************************************************ |
112 | |
113 | const PropertyImpl INVALID(""); |
114 | + |
115 | const PropertyImpl XQUERY_COMPILATION_FILENAME( |
116 | XQUERY_COMPILATION, "filename", 0, Property::STRING); |
117 | + |
118 | const PropertyImpl XQUERY_COMPILATION_PARSE_DURATION( |
119 | XQUERY_COMPILATION, "parse-duration", 1, Property::INT); |
120 | + |
121 | const PropertyImpl XQUERY_COMPILATION_TRANSLATION_DURATION( |
122 | XQUERY_COMPILATION, "translation-duration", 2, Property::INT); |
123 | + |
124 | const PropertyImpl XQUERY_COMPILATION_OPTIMIZATION_DURATION( |
125 | XQUERY_COMPILATION, "optimization-duration", 3, Property::INT); |
126 | + |
127 | const PropertyImpl XQUERY_COMPILATION_CODEGENERATION_DURATION( |
128 | XQUERY_COMPILATION, "codegeneration-duration", 4, Property::INT); |
129 | |
130 | |
131 | === modified file 'src/api/dynamiccontextimpl.cpp' |
132 | --- src/api/dynamiccontextimpl.cpp 2012-07-24 08:48:48 +0000 |
133 | +++ src/api/dynamiccontextimpl.cpp 2012-08-10 11:20:27 +0000 |
134 | @@ -38,7 +38,6 @@ |
135 | #include "compiler/parser/query_loc.h" |
136 | #include "compiler/parsetree/parsenodes.h" |
137 | #include "compiler/api/compilercb.h" |
138 | -#include "compiler/expression/var_expr.h" |
139 | |
140 | #include "runtime/util/item_iterator.h" |
141 | |
142 | @@ -98,9 +97,9 @@ |
143 | tree. The var_expr can be found within the static context that the variable |
144 | belongs to. In the case of a lexical QName, this method will only attempt to |
145 | look up the namespace prefix in the main module's static context. For a clark |
146 | - name, it will call to the other form of get_var_expr(). |
147 | + name, it will call to the other form of get_var_info(). |
148 | ********************************************************************************/ |
149 | -var_expr* DynamicContextImpl::get_var_expr(const zstring& inVarName) |
150 | +VarInfo* DynamicContextImpl::get_var_info(const zstring& inVarName) |
151 | { |
152 | // First check for universal name. |
153 | zstring nsUri; |
154 | @@ -109,7 +108,7 @@ |
155 | // Looks like it is a universal name; jump over to other form. |
156 | zstring localname; |
157 | xml::clark_localname(inVarName, &localname); |
158 | - return get_var_expr(nsUri, localname); |
159 | + return get_var_info(nsUri, localname); |
160 | } |
161 | |
162 | ZORBA_ASSERT(theStaticContext); |
163 | @@ -125,11 +124,9 @@ |
164 | QueryLoc::null); |
165 | |
166 | // Note: lookup_var will return NULL if the variable is not known. |
167 | - var_expr* var = theStaticContext->lookup_var(qnameItem, |
168 | - QueryLoc::null, |
169 | - zerr::ZXQP0000_NO_ERROR); |
170 | + VarInfo* var = theStaticContext->lookup_var(qnameItem); |
171 | |
172 | - if (var == NULL) |
173 | + if (!var) |
174 | { |
175 | throw XQUERY_EXCEPTION(err::XPST0008, |
176 | ERROR_PARAMS(BUILD_STRING('{', |
177 | @@ -150,33 +147,34 @@ |
178 | the variable belongs to. This method will search through all static contexts, |
179 | including library modules, for a matching variable declaration. |
180 | ********************************************************************************/ |
181 | -var_expr* DynamicContextImpl::get_var_expr( |
182 | +VarInfo* DynamicContextImpl::get_var_info( |
183 | const zstring& inVarUri, |
184 | const zstring& inVarLocalName) const |
185 | { |
186 | - var_expr* var = NULL; |
187 | - |
188 | store::Item_t qname; |
189 | GENV_ITEMFACTORY->createQName(qname, inVarUri, zstring(), inVarLocalName); |
190 | |
191 | + VarInfo* var = NULL; |
192 | + |
193 | if (theQuery != NULL) |
194 | { |
195 | CompilerCB::SctxMap& lMap = theQuery->theCompilerCB->theSctxMap; |
196 | CompilerCB::SctxMap::const_iterator ite; |
197 | + |
198 | for (ite = lMap.begin(); ite != lMap.end(); ++ite) |
199 | { |
200 | - var = ite->second->lookup_var(qname, QueryLoc::null, zerr::ZXQP0000_NO_ERROR); |
201 | + var = ite->second->lookup_var(qname); |
202 | |
203 | if (var) |
204 | - break; |
205 | + return var; |
206 | } |
207 | } |
208 | else |
209 | { |
210 | - var = theStaticContext->lookup_var(qname, QueryLoc::null, zerr::ZXQP0000_NO_ERROR); |
211 | + var = theStaticContext->lookup_var(qname); |
212 | } |
213 | |
214 | - if (var == NULL) |
215 | + if (!var) |
216 | { |
217 | throw XQUERY_EXCEPTION(err::XPST0008, |
218 | ERROR_PARAMS(BUILD_STRING('{', inVarUri, '}', inVarLocalName ), ZED(Variable))); |
219 | @@ -200,13 +198,14 @@ |
220 | const zstring& nameSpace = Unmarshaller::getInternalString(inNamespace); |
221 | const zstring& localName = Unmarshaller::getInternalString(inLocalname); |
222 | |
223 | - var_expr* var = get_var_expr(nameSpace, localName); |
224 | - ulong varId = var->get_unique_id(); |
225 | + VarInfo* var = get_var_info(nameSpace, localName); |
226 | + |
227 | + ulong varId = var->getId(); |
228 | |
229 | store::Item_t item; |
230 | store::TempSeq_t tempseq; |
231 | |
232 | - theCtx->get_variable(varId, var->get_name(), QueryLoc::null, item, tempseq); |
233 | + theCtx->get_variable(varId, var->getName(), QueryLoc::null, item, tempseq); |
234 | |
235 | if (! item.isNull()) |
236 | { |
237 | @@ -248,11 +247,11 @@ |
238 | const zstring& localName = Unmarshaller::getInternalString(inLocalname); |
239 | store::Iterator_t value = Unmarshaller::getInternalIterator(inValue.get()); |
240 | |
241 | - var_expr* var; |
242 | + VarInfo* var = NULL; |
243 | |
244 | try |
245 | { |
246 | - var = get_var_expr(nameSpace, localName); |
247 | + var = get_var_info(nameSpace, localName); |
248 | } |
249 | catch (ZorbaException const& e) |
250 | { |
251 | @@ -266,7 +265,7 @@ |
252 | throw; |
253 | } |
254 | |
255 | - ulong varId = var->get_unique_id(); |
256 | + ulong varId = var->getId(); |
257 | |
258 | theCtx->add_variable(varId, value); |
259 | |
260 | @@ -292,7 +291,6 @@ |
261 | const zstring& varName = Unmarshaller::getInternalString(inVarName); |
262 | store::Item_t value(Unmarshaller::getInternalItem(inValue)); |
263 | ZorbaImpl::checkItem(value); |
264 | - var_expr* var; |
265 | |
266 | // For string items, check that the value is a valid Unicode codepoint sequence |
267 | const char* invalid_char; |
268 | @@ -311,9 +309,11 @@ |
269 | << (static_cast<unsigned int>(*invalid_char) & 0xFF)) )); |
270 | } |
271 | |
272 | + VarInfo* var = NULL; |
273 | + |
274 | try |
275 | { |
276 | - var = get_var_expr(varName); |
277 | + var = get_var_info(varName); |
278 | } |
279 | catch (ZorbaException const& e) |
280 | { |
281 | @@ -327,7 +327,7 @@ |
282 | throw; |
283 | } |
284 | |
285 | - ulong varId = var->get_unique_id(); |
286 | + ulong varId = var->getId(); |
287 | |
288 | // add it to the internal context |
289 | theCtx->add_variable(varId, value); |
290 | @@ -358,11 +358,12 @@ |
291 | |
292 | const zstring& varName = Unmarshaller::getInternalString(inVarName); |
293 | store::Iterator_t value = Unmarshaller::getInternalIterator(inValue.get()); |
294 | - var_expr* var; |
295 | + |
296 | + VarInfo* var = NULL; |
297 | |
298 | try |
299 | { |
300 | - var = get_var_expr(varName); |
301 | + var = get_var_info(varName); |
302 | } |
303 | catch (ZorbaException const& e) |
304 | { |
305 | @@ -376,7 +377,7 @@ |
306 | throw; |
307 | } |
308 | |
309 | - ulong varId = var->get_unique_id(); |
310 | + ulong varId = var->getId(); |
311 | |
312 | theCtx->add_variable(varId, value); |
313 | |
314 | |
315 | === modified file 'src/api/dynamiccontextimpl.h' |
316 | --- src/api/dynamiccontextimpl.h 2012-07-24 08:48:48 +0000 |
317 | +++ src/api/dynamiccontextimpl.h 2012-08-10 11:20:27 +0000 |
318 | @@ -26,6 +26,7 @@ |
319 | |
320 | class DiagnosticHandler; |
321 | class XQueryImpl; |
322 | +class VarInfo; |
323 | |
324 | |
325 | /******************************************************************************* |
326 | @@ -138,10 +139,10 @@ |
327 | getExternalFunctionParam(const String& aName, void*&) const; |
328 | |
329 | virtual bool |
330 | - addExternalFunctionParameter ( const String& aName, ExternalFunctionParameter* aParam ); |
331 | + addExternalFunctionParameter(const String& aName, ExternalFunctionParameter* aParam); |
332 | |
333 | virtual ExternalFunctionParameter* |
334 | - getExternalFunctionParameter ( const String& aName ) const; |
335 | + getExternalFunctionParameter(const String& aName) const; |
336 | |
337 | virtual bool |
338 | isBoundExternalVariable(const String& aNamespace, const String& aLocalname) const; |
339 | @@ -153,9 +154,9 @@ |
340 | void checkNoIterators() const; |
341 | |
342 | private: |
343 | - var_expr* get_var_expr(const zstring& inVarName); |
344 | + VarInfo* get_var_info(const zstring& varName); |
345 | |
346 | - var_expr* get_var_expr(const zstring& inVarUri, const zstring& inVarLocalName) const; |
347 | + VarInfo* get_var_info(const zstring& varUri, const zstring& varLocalName) const; |
348 | }; |
349 | |
350 | } /* namespace zorba */ |
351 | |
352 | === modified file 'src/api/staticcontextimpl.cpp' |
353 | --- src/api/staticcontextimpl.cpp 2012-07-24 08:48:48 +0000 |
354 | +++ src/api/staticcontextimpl.cpp 2012-08-10 11:20:27 +0000 |
355 | @@ -73,6 +73,7 @@ |
356 | ********************************************************************************/ |
357 | StaticContextImpl::StaticContextImpl(DiagnosticHandler* aDiagnosticHandler) |
358 | : |
359 | + theCompilerCB(NULL), |
360 | theMaxVarId(2), |
361 | theDiagnosticHandler(aDiagnosticHandler), |
362 | theUserDiagnosticHandler(true), |
363 | @@ -98,6 +99,7 @@ |
364 | DiagnosticHandler* aDiagnosticHandler) |
365 | : |
366 | theCtx(aCtx), |
367 | + theCompilerCB(NULL), |
368 | theMaxVarId(2), |
369 | theDiagnosticHandler(aDiagnosticHandler), |
370 | theUserDiagnosticHandler(true), |
371 | @@ -120,6 +122,7 @@ |
372 | StaticContextImpl::StaticContextImpl(const StaticContextImpl& aStaticContext) |
373 | : |
374 | StaticContext(), |
375 | + theCompilerCB(NULL), |
376 | theMaxVarId(2), |
377 | theDiagnosticHandler(aStaticContext.theDiagnosticHandler), |
378 | theUserDiagnosticHandler(aStaticContext.theUserDiagnosticHandler), |
379 | @@ -151,6 +154,11 @@ |
380 | { |
381 | delete theCollectionMgr; |
382 | } |
383 | + |
384 | + theCtx = NULL; |
385 | + |
386 | + if (theCompilerCB) |
387 | + delete theCompilerCB; |
388 | } |
389 | |
390 | |
391 | @@ -1015,6 +1023,8 @@ |
392 | const String& prolog, |
393 | const Zorba_CompilerHints_t& hints) |
394 | { |
395 | + ZORBA_ASSERT(theCompilerCB == NULL); |
396 | + |
397 | // Create and compile an internal query whose prolog is the given prolog and |
398 | // its body is just the emtpy sequence expression: "()". |
399 | XQueryImpl impl; |
400 | @@ -1023,7 +1033,9 @@ |
401 | // Copy theSctxMap of the internal query into "this". When "this" is then passed |
402 | // as an input to a user query Q, theSctxMap of Q will be initialized as a copy |
403 | // of this->theSctxMap. |
404 | - theSctxMap = impl.theCompilerCB->theSctxMap; |
405 | + //theSctxMap = impl.theCompilerCB->theSctxMap; |
406 | + theCompilerCB = impl.theCompilerCB; |
407 | + impl.theCompilerCB = NULL; |
408 | } |
409 | |
410 | |
411 | @@ -1531,29 +1543,31 @@ |
412 | StaticContextImpl::getExternalVariables(Iterator_t& aVarsIter) const |
413 | { |
414 | ZORBA_TRY |
415 | - std::vector<var_expr_t> lVars; |
416 | - theCtx->getVariables(lVars, true, false, true); |
417 | - |
418 | - std::vector<var_expr_t>::const_iterator lIte = lVars.begin(); |
419 | - std::vector<var_expr_t>::const_iterator lEnd = lVars.end(); |
420 | - std::vector<store::Item_t> lExVars; |
421 | - |
422 | - for (; lIte != lEnd; ++lIte) |
423 | + std::vector<VarInfo*> vars; |
424 | + theCtx->getVariables(vars, true, false, true); |
425 | + |
426 | + std::vector<VarInfo*>::const_iterator ite = vars.begin(); |
427 | + std::vector<VarInfo*>::const_iterator end = vars.end(); |
428 | + std::vector<store::Item_t> extVars; |
429 | + |
430 | + for (; ite != end; ++ite) |
431 | { |
432 | - lExVars.push_back(lIte->getp()->get_name()); |
433 | + extVars.push_back((*ite)->getName()); |
434 | } |
435 | |
436 | - Iterator_t vIter = new VectorIterator(lExVars, theDiagnosticHandler); |
437 | + Iterator_t vIter = new VectorIterator(extVars, theDiagnosticHandler); |
438 | aVarsIter = vIter; |
439 | ZORBA_CATCH |
440 | } |
441 | |
442 | + |
443 | Item |
444 | StaticContextImpl::fetch(const String& aURI) const |
445 | { |
446 | return fetch(aURI, "SOME_CONTENT", "UTF-8"); |
447 | } |
448 | |
449 | + |
450 | Item |
451 | StaticContextImpl::fetch( |
452 | const String& aURI, |
453 | |
454 | === modified file 'src/api/staticcontextimpl.h' |
455 | --- src/api/staticcontextimpl.h 2012-07-24 08:48:48 +0000 |
456 | +++ src/api/staticcontextimpl.h 2012-08-10 11:20:27 +0000 |
457 | @@ -65,7 +65,9 @@ |
458 | protected: |
459 | static_context_t theCtx; |
460 | |
461 | - std::map<csize, static_context_t> theSctxMap; |
462 | + CompilerCB * theCompilerCB; |
463 | + |
464 | + //std::map<csize, static_context_t> theSctxMap; |
465 | |
466 | ulong theMaxVarId; |
467 | |
468 | |
469 | === modified file 'src/api/xqueryimpl.cpp' |
470 | --- src/api/xqueryimpl.cpp 2012-07-24 08:48:48 +0000 |
471 | +++ src/api/xqueryimpl.cpp 2012-08-10 11:20:27 +0000 |
472 | @@ -55,7 +55,6 @@ |
473 | |
474 | #include "compiler/api/compiler_api.h" |
475 | #include "compiler/api/compilercb.h" |
476 | -#include "compiler/expression/var_expr.h" |
477 | |
478 | #include "runtime/base/plan_iterator.h" |
479 | #include "runtime/api/plan_wrapper.h" |
480 | @@ -191,13 +190,11 @@ |
481 | delete theCompilerCB; |
482 | theCompilerCB = NULL; |
483 | } |
484 | - else |
485 | - { |
486 | - ar.set_ccb(theCompilerCB); |
487 | - } |
488 | - |
489 | + |
490 | ar & theCompilerCB; |
491 | + |
492 | ar & thePlanProxy; |
493 | + |
494 | ar & theStaticContext; |
495 | |
496 | if (!ar.is_serializing_out()) |
497 | @@ -489,11 +486,13 @@ |
498 | |
499 | // If the static context results from loadProlog, we need all the contexts |
500 | // that were created when compiling the load-prolog query |
501 | - theCompilerCB->theSctxMap = |
502 | - static_cast<StaticContextImpl*>(aStaticContext.get())->theSctxMap; |
503 | - |
504 | - ulong nextVarId = |
505 | - static_cast<StaticContextImpl*>(aStaticContext.get())->getMaxVarId(); |
506 | + StaticContextImpl* externalSctx = |
507 | + static_cast<StaticContextImpl*>(aStaticContext.get()); |
508 | + |
509 | + if (externalSctx->theCompilerCB) |
510 | + theCompilerCB->theSctxMap = externalSctx->theCompilerCB->theSctxMap; |
511 | + |
512 | + ulong nextVarId = externalSctx->getMaxVarId(); |
513 | |
514 | std::istringstream lQueryStream(aQuery.c_str()); |
515 | |
516 | @@ -522,11 +521,13 @@ |
517 | |
518 | // if the static context results from loadProlog, we need all the context |
519 | // that were created when compiling the load-prolog query |
520 | - theCompilerCB->theSctxMap = |
521 | - static_cast<StaticContextImpl*>(aStaticContext.get())->theSctxMap; |
522 | - |
523 | - ulong nextVarId = |
524 | - static_cast<StaticContextImpl*>(aStaticContext.get())->getMaxVarId(); |
525 | + StaticContextImpl* externalSctx = |
526 | + static_cast<StaticContextImpl*>(aStaticContext.get()); |
527 | + |
528 | + if (externalSctx->theCompilerCB) |
529 | + theCompilerCB->theSctxMap = externalSctx->theCompilerCB->theSctxMap; |
530 | + |
531 | + ulong nextVarId = externalSctx->getMaxVarId(); |
532 | |
533 | doCompile(aQuery, aHints, true, nextVarId); |
534 | } |
535 | @@ -762,26 +763,26 @@ |
536 | checkNotClosed(); |
537 | checkCompiled(); |
538 | |
539 | - std::vector<var_expr_t> lVars; |
540 | - |
541 | - CompilerCB::SctxMap::const_iterator lIte = theCompilerCB->theSctxMap.begin(); |
542 | - CompilerCB::SctxMap::const_iterator lEnd = theCompilerCB->theSctxMap.end(); |
543 | - |
544 | - for(; lIte != lEnd; ++lIte) |
545 | + std::vector<VarInfo*> vars; |
546 | + |
547 | + CompilerCB::SctxMap::const_iterator ite = theCompilerCB->theSctxMap.begin(); |
548 | + CompilerCB::SctxMap::const_iterator end = theCompilerCB->theSctxMap.end(); |
549 | + |
550 | + for(; ite != end; ++ite) |
551 | { |
552 | - lIte->second.getp()->getVariables(lVars, false, false, true); |
553 | + ite->second.getp()->getVariables(vars, false, false, true); |
554 | } |
555 | |
556 | - std::vector<var_expr_t>::const_iterator lVarIte = lVars.begin(); |
557 | - std::vector<var_expr_t>::const_iterator lVarEnd = lVars.end(); |
558 | - std::vector<store::Item_t> lExVars; |
559 | + std::vector<VarInfo*>::const_iterator lVarIte = vars.begin(); |
560 | + std::vector<VarInfo*>::const_iterator lVarEnd = vars.end(); |
561 | + std::vector<store::Item_t> extVars; |
562 | |
563 | for(; lVarIte != lVarEnd; ++lVarIte) |
564 | { |
565 | - lExVars.push_back((*lVarIte)->get_name()); |
566 | + extVars.push_back((*lVarIte)->getName()); |
567 | } |
568 | |
569 | - Iterator_t vIter = new VectorIterator(lExVars, theDiagnosticHandler); |
570 | + Iterator_t vIter = new VectorIterator(extVars, theDiagnosticHandler); |
571 | |
572 | aVarsIter = vIter; |
573 | |
574 | @@ -801,34 +802,40 @@ |
575 | checkNotClosed(); |
576 | checkCompiled(); |
577 | |
578 | - var_expr* var = NULL; |
579 | - |
580 | zstring& nameSpace = Unmarshaller::getInternalString(aNamespace); |
581 | zstring& localName = Unmarshaller::getInternalString(aLocalname); |
582 | |
583 | store::Item_t qname; |
584 | GENV_ITEMFACTORY->createQName(qname, nameSpace, zstring(), localName); |
585 | |
586 | + VarInfo* var = NULL; |
587 | + |
588 | CompilerCB::SctxMap& lMap = theCompilerCB->theSctxMap; |
589 | - CompilerCB::SctxMap::const_iterator lIte = lMap.begin(); |
590 | - CompilerCB::SctxMap::const_iterator lEnd = lMap.end(); |
591 | + CompilerCB::SctxMap::const_iterator ite = lMap.begin(); |
592 | + CompilerCB::SctxMap::const_iterator end = lMap.end(); |
593 | |
594 | - for (; lIte != lEnd; ++lIte) |
595 | + for (; ite != end; ++ite) |
596 | { |
597 | - var = lIte->second->lookup_var(qname, QueryLoc::null, zerr::ZXQP0000_NO_ERROR); |
598 | + var = ite->second->lookup_var(qname); |
599 | |
600 | - if(var) |
601 | + if (var) |
602 | break; |
603 | } |
604 | |
605 | - if(var == NULL) |
606 | + if (!var) |
607 | + { |
608 | throw XQUERY_EXCEPTION(zerr::ZAPI0011_ELEMENT_NOT_DECLARED, |
609 | - ERROR_PARAMS(BUILD_STRING('{', qname->getNamespace(), '}', qname->getLocalName()), ZED(Variable))); |
610 | + ERROR_PARAMS(BUILD_STRING('{', |
611 | + qname->getNamespace(), |
612 | + '}', |
613 | + qname->getLocalName()), |
614 | + ZED(Variable))); |
615 | + } |
616 | |
617 | if (var->hasInitializer()) |
618 | return true; |
619 | |
620 | - ulong varId = var->get_unique_id(); |
621 | + ulong varId = var->getId(); |
622 | |
623 | if (theDynamicContext->is_set_variable(varId)) |
624 | return true; |
625 | |
626 | === modified file 'src/compiler/api/compiler_api.cpp' |
627 | --- src/compiler/api/compiler_api.cpp 2012-07-24 08:48:48 +0000 |
628 | +++ src/compiler/api/compiler_api.cpp 2012-08-10 11:20:27 +0000 |
629 | @@ -154,8 +154,8 @@ |
630 | |
631 | if(xqxconvertor->isXQueryX((char*)xquery_str.c_str())) |
632 | { |
633 | - // identify XQueryX by content: |
634 | - // root tag = |
635 | + // identify XQueryX by content: |
636 | + // root tag = |
637 | // "<prefix:module ... xmlns:prefix="http://www.w3.org/2005/XQueryX" ... > " |
638 | |
639 | is_xqueryx = true; |
640 | @@ -211,18 +211,17 @@ |
641 | zorba::audit::ScopedRecord sar(ae); |
642 | |
643 | const char* lFileName = aFileName.c_str(); |
644 | - zorba::audit::ScopedAuditor<const char*> filenameAudit( |
645 | - sar, zorba::audit::XQUERY_COMPILATION_FILENAME, lFileName); |
646 | + |
647 | + audit::ScopedAuditor<const char*> |
648 | + filenameAudit(sar, zorba::audit::XQUERY_COMPILATION_FILENAME, lFileName); |
649 | |
650 | parsenode_t lAST; |
651 | |
652 | { |
653 | time::Timer lTimer; |
654 | |
655 | - audit::DurationAuditor |
656 | - durationAudit(sar, |
657 | - audit::XQUERY_COMPILATION_PARSE_DURATION, |
658 | - lTimer); |
659 | + audit::DurationAuditor |
660 | + durationAudit(sar, audit::XQUERY_COMPILATION_PARSE_DURATION, lTimer); |
661 | |
662 | lAST = parse(aXQuery, aFileName); |
663 | |
664 | @@ -252,7 +251,7 @@ |
665 | { |
666 | time::Timer lTimer; |
667 | |
668 | - audit::DurationAuditor |
669 | + audit::DurationAuditor |
670 | durationAudit(aAuditRecord, |
671 | audit::XQUERY_COMPILATION_TRANSLATION_DURATION, |
672 | lTimer); |
673 | @@ -276,6 +275,7 @@ |
674 | #endif |
675 | |
676 | PlanIter_t plan; |
677 | + |
678 | { |
679 | time::Timer lTimer; |
680 | |
681 | @@ -287,6 +287,8 @@ |
682 | plan = codegen("main query", rootExpr, theCompilerCB, nextDynamicVarId); |
683 | } |
684 | |
685 | + //theCompilerCB->getExprManager()->garbageCollect(); |
686 | + |
687 | return plan; |
688 | } |
689 | |
690 | @@ -307,6 +309,10 @@ |
691 | expr_t lExpr = translate(*aParsenode, theCompilerCB); |
692 | |
693 | #if 0 |
694 | + std::cout << "Num exprs after translation = " |
695 | + << theCompilerCB->getExprManager()->numExprs() |
696 | + << std::endl << std::endl; |
697 | + |
698 | time::get_current_walltime(stopTime); |
699 | elapsedTime = time::get_walltime_elapsed(startTime, stopTime); |
700 | std::cout << "Translation time = " << elapsedTime << std::endl; |
701 | @@ -356,13 +362,19 @@ |
702 | if ( theCompilerCB->theConfig.optimize_cb != NULL ) |
703 | theCompilerCB->theConfig.optimize_cb(lExpr.getp(), "main query"); |
704 | |
705 | +#if 0 |
706 | + std::cout << "Num exprs after optimization = " |
707 | + << theCompilerCB->getExprManager()->numExprs() |
708 | + << std::endl << std::endl; |
709 | +#endif |
710 | + |
711 | return lExpr; |
712 | } |
713 | |
714 | |
715 | /****************************************************************************** |
716 | This is a small helper class used when the user wants to compile a library |
717 | - module. The ONLY place it is used (and should be used) is in the |
718 | + module. The ONLY place it is used (and should be used) is in the |
719 | XQueryCompiler::createMainModule method below. |
720 | QQQ When we have the ability to compile a library module indepedently, this |
721 | rather hacky class can go away. At that time, we can also eliminate the |
722 | @@ -372,20 +384,27 @@ |
723 | class FakeLibraryModuleURLResolver : public internal::URLResolver |
724 | { |
725 | public: |
726 | - FakeLibraryModuleURLResolver |
727 | - (zstring const& aLibraryModuleNamespace, |
728 | - zstring const& aLibraryModuleFilename, std::istream& aStream) |
729 | - : theLibraryModuleNamespace(aLibraryModuleNamespace), |
730 | - theLibraryModuleFilename(aLibraryModuleFilename), |
731 | - theStream(aStream) |
732 | - {} |
733 | + FakeLibraryModuleURLResolver( |
734 | + zstring const& aLibraryModuleNamespace, |
735 | + zstring const& aLibraryModuleFilename, |
736 | + std::istream& aStream) |
737 | + : |
738 | + theLibraryModuleNamespace(aLibraryModuleNamespace), |
739 | + theLibraryModuleFilename(aLibraryModuleFilename), |
740 | + theStream(aStream) |
741 | + { |
742 | + } |
743 | + |
744 | virtual ~FakeLibraryModuleURLResolver() |
745 | - {} |
746 | + { |
747 | + } |
748 | |
749 | - virtual internal::Resource* resolveURL |
750 | - (zstring const& aUrl, internal::EntityData const* aEntityData) |
751 | + virtual internal::Resource* resolveURL( |
752 | + zstring const& aUrl, |
753 | + internal::EntityData const* aEntityData) |
754 | { |
755 | - if (aUrl != theLibraryModuleNamespace) { |
756 | + if (aUrl != theLibraryModuleNamespace) |
757 | + { |
758 | return NULL; |
759 | } |
760 | assert (theStream.good()); |
761 | |
762 | === modified file 'src/compiler/api/compilercb.cpp' |
763 | --- src/compiler/api/compilercb.cpp 2012-07-24 08:48:48 +0000 |
764 | +++ src/compiler/api/compilercb.cpp 2012-08-10 11:20:27 +0000 |
765 | @@ -1,12 +1,12 @@ |
766 | /* |
767 | * Copyright 2006-2008 The FLWOR Foundation. |
768 | - * |
769 | + * |
770 | * Licensed under the Apache License, Version 2.0 (the "License"); |
771 | * you may not use this file except in compliance with the License. |
772 | * You may obtain a copy of the License at |
773 | - * |
774 | + * |
775 | * http://www.apache.org/licenses/LICENSE-2.0 |
776 | - * |
777 | + * |
778 | * Unless required by applicable law or agreed to in writing, software |
779 | * distributed under the License is distributed on an "AS IS" BASIS, |
780 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
781 | @@ -30,7 +30,7 @@ |
782 | #include "zorbaserialization/serialize_zorba_types.h" |
783 | |
784 | |
785 | -namespace zorba |
786 | +namespace zorba |
787 | { |
788 | |
789 | SERIALIZABLE_CLASS_VERSIONS(CompilerCB) |
790 | @@ -80,7 +80,7 @@ |
791 | /******************************************************************************* |
792 | |
793 | ********************************************************************************/ |
794 | -CompilerCB::config::config(::zorba::serialization::Archiver& ar) |
795 | +CompilerCB::config::config(::zorba::serialization::Archiver& ar) |
796 | : |
797 | parse_cb(NULL), |
798 | translate_cb(NULL), |
799 | @@ -121,6 +121,8 @@ |
800 | theTimeout(timeout), |
801 | theTempIndexCounter(0) |
802 | { |
803 | + theEM = new ExprManager(this); |
804 | + |
805 | if (timeout >= 0) |
806 | theHaveTimeout = true; |
807 | } |
808 | @@ -128,7 +130,7 @@ |
809 | |
810 | /******************************************************************************* |
811 | Used by the eval iterator to create a new ccb as a copy of the ccb of the |
812 | - enclosing query. |
813 | + enclosing query. |
814 | *******************************************************************************/ |
815 | CompilerCB::CompilerCB(const CompilerCB& cb) |
816 | : |
817 | @@ -148,6 +150,7 @@ |
818 | theTempIndexCounter(0), |
819 | theConfig(cb.theConfig) |
820 | { |
821 | + theEM = new ExprManager(this); |
822 | } |
823 | |
824 | |
825 | @@ -165,14 +168,17 @@ |
826 | theHasEval(false), |
827 | theIsEval(false) |
828 | { |
829 | + theEM = new ExprManager(this); |
830 | } |
831 | |
832 | |
833 | /******************************************************************************* |
834 | |
835 | ********************************************************************************/ |
836 | -CompilerCB::~CompilerCB() |
837 | +CompilerCB::~CompilerCB() |
838 | { |
839 | + theSctxMap.clear(); |
840 | + delete theEM; |
841 | } |
842 | |
843 | |
844 | @@ -181,6 +187,8 @@ |
845 | ********************************************************************************/ |
846 | void CompilerCB::serialize(::zorba::serialization::Archiver& ar) |
847 | { |
848 | + ar.set_ccb(this); |
849 | + |
850 | ar & theHasEval; |
851 | ar & theIsEval; |
852 | ar & theIsLoadProlog; |
853 | @@ -190,7 +198,7 @@ |
854 | #ifdef ZORBA_WITH_DEBUGGER |
855 | ar & theDebuggerCommons; |
856 | #endif |
857 | - if (!ar.is_serializing_out()) |
858 | + if (!ar.is_serializing_out()) |
859 | { |
860 | //don't serialize this |
861 | theXQueryDiagnostics = NULL; |
862 | |
863 | === modified file 'src/compiler/api/compilercb.h' |
864 | --- src/compiler/api/compilercb.h 2012-07-24 08:48:48 +0000 |
865 | +++ src/compiler/api/compilercb.h 2012-08-10 11:20:27 +0000 |
866 | @@ -1,12 +1,12 @@ |
867 | /* |
868 | * Copyright 2006-2008 The FLWOR Foundation. |
869 | - * |
870 | + * |
871 | * Licensed under the Apache License, Version 2.0 (the "License"); |
872 | * you may not use this file except in compliance with the License. |
873 | * You may obtain a copy of the License at |
874 | - * |
875 | + * |
876 | * http://www.apache.org/licenses/LICENSE-2.0 |
877 | - * |
878 | + * |
879 | * Unless required by applicable law or agreed to in writing, software |
880 | * distributed under the License is distributed on an "AS IS" BASIS, |
881 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
882 | @@ -32,6 +32,9 @@ |
883 | |
884 | #include "zorbaserialization/class_serializer.h" |
885 | |
886 | +#include "compiler/expression/mem_manager.h" |
887 | +#include "compiler/expression/expr_manager.h" |
888 | + |
889 | namespace zorba { |
890 | |
891 | #ifdef ZORBA_WITH_DEBUGGER |
892 | @@ -57,7 +60,7 @@ |
893 | A query-level (or eval-level) map that stores the sctx objs that need to be |
894 | kept around for the whole duration of a query (including runtime). In non- |
895 | DEBUGGER mode, the map stores only for root sctx of each module. In DEBUGGER |
896 | - mode, it stores all the sctxs created by each module. Each sctx stored in |
897 | + mode, it stores all the sctxs created by each module. Each sctx stored in |
898 | this map has an associated numeric id, and theSctxMap actually maps these |
899 | numeric ids to their associated sctx objs. The map is modified by the methods |
900 | TranslatorImpl::end_visit(ModuleImport) and TranslatorImpl::push_scope(). |
901 | @@ -89,7 +92,7 @@ |
902 | |
903 | theIsUpdating : |
904 | --------------- |
905 | - Set to true if the root expr of the query or eval expr is an updating expr. |
906 | + Set to true if the root expr of the query or eval expr is an updating expr. |
907 | |
908 | theTimeout : |
909 | ------------ |
910 | @@ -124,13 +127,13 @@ |
911 | public: |
912 | struct config : public zorba::serialization::SerializeBaseClass |
913 | { |
914 | - typedef enum |
915 | + typedef enum |
916 | { |
917 | O0, |
918 | O1, |
919 | O2 |
920 | } opt_level_t; |
921 | - |
922 | + |
923 | typedef void (* expr_callback) (const expr *, const std::string& name); |
924 | |
925 | typedef void (* ast_callback) (const parsenode *, const std::string& name); |
926 | @@ -157,7 +160,9 @@ |
927 | |
928 | typedef std::map<csize, static_context_t> SctxMap; |
929 | |
930 | -public: |
931 | +public: |
932 | + ExprManager * theEM; |
933 | + |
934 | XQueryDiagnostics * theXQueryDiagnostics; |
935 | |
936 | SctxMap theSctxMap; |
937 | @@ -211,6 +216,11 @@ |
938 | bool isSequential() const { return theIsSequential;} |
939 | |
940 | static_context* getStaticContext(int id); |
941 | + |
942 | + ExprManager* getExprManager() const { return theEM; } |
943 | + |
944 | + MemoryManager& getMemoryManager() const { return theEM->getMemory(); } |
945 | + |
946 | }; |
947 | |
948 | |
949 | |
950 | === modified file 'src/compiler/codegen/plan_visitor.cpp' |
951 | --- src/compiler/codegen/plan_visitor.cpp 2012-07-24 08:48:48 +0000 |
952 | +++ src/compiler/codegen/plan_visitor.cpp 2012-08-10 11:20:27 +0000 |
953 | @@ -2075,18 +2075,24 @@ |
954 | |
955 | csize numVars = v.var_count(); |
956 | |
957 | - checked_vector<PlanIter_t> args(numVars+1); |
958 | - checked_vector<store::Item_t> varnames(numVars); |
959 | - checked_vector<xqtref_t> vartypes(numVars); |
960 | + checked_vector<PlanIter_t> args; |
961 | + args.reserve(numVars+1); |
962 | + |
963 | + std::vector<store::Item_t> varNames(numVars); |
964 | + std::vector<xqtref_t> varTypes(numVars); |
965 | + std::vector<int> isGlobalVar(numVars); |
966 | |
967 | for (csize i = 0; i < numVars; ++i) |
968 | { |
969 | - varnames[i] = v.get_var(i)->get_name(); |
970 | - vartypes[i] = v.get_var(i)->get_type(); |
971 | - args[i] = pop_itstack(); |
972 | + varNames[i] = v.get_var(i)->get_name(); |
973 | + varTypes[i] = v.get_var(i)->get_type(); |
974 | + isGlobalVar[i] = (v.get_arg_expr(i) == NULL); |
975 | + |
976 | + if (!isGlobalVar[i]) |
977 | + args.push_back(pop_itstack()); |
978 | } |
979 | |
980 | - args[numVars] = pop_itstack(); |
981 | + args.push_back(pop_itstack()); |
982 | reverse(args.begin(), args.end()); |
983 | |
984 | store::NsBindings localBindings; |
985 | @@ -2095,8 +2101,9 @@ |
986 | push_itstack(new EvalIterator(sctx, |
987 | qloc, |
988 | args, |
989 | - varnames, |
990 | - vartypes, |
991 | + varNames, |
992 | + varTypes, |
993 | + isGlobalVar, |
994 | v.get_inner_scripting_kind(), |
995 | localBindings, |
996 | v.getNodeCopy(), |
997 | @@ -2127,14 +2134,17 @@ |
998 | std::vector<PlanIter_t> argvEvalIter; |
999 | |
1000 | csize numVars = v.var_count(); |
1001 | - std::vector<store::Item_t> varnames(numVars); |
1002 | - std::vector<xqtref_t> vartypes(numVars); |
1003 | + std::vector<store::Item_t> varNames(numVars); |
1004 | + std::vector<xqtref_t> varTypes(numVars); |
1005 | + std::vector<int> isGlobalVar(numVars); |
1006 | |
1007 | //create the eval iterator children |
1008 | for (csize i = 0; i < numVars; i++) |
1009 | { |
1010 | - varnames[i] = v.get_var(i)->get_name(); |
1011 | - vartypes[i] = v.get_var(i)->get_type(); |
1012 | + varNames[i] = v.get_var(i)->get_name(); |
1013 | + varTypes[i] = v.get_var(i)->get_type(); |
1014 | + isGlobalVar[i] = (v.get_var(i)->get_kind() == var_expr::prolog_var); |
1015 | + |
1016 | argvEvalIter.push_back(pop_itstack()); |
1017 | } |
1018 | |
1019 | @@ -2167,15 +2177,16 @@ |
1020 | argv.push_back(new EvalIterator(sctx, |
1021 | qloc, |
1022 | argvEvalIter, |
1023 | - varnames, |
1024 | - vartypes, |
1025 | + varNames, |
1026 | + varTypes, |
1027 | + isGlobalVar, |
1028 | SEQUENTIAL_FUNC_EXPR, |
1029 | localBindings, |
1030 | true, |
1031 | true)); |
1032 | |
1033 | lDebugIterator->setChildren(&argv); |
1034 | - lDebugIterator->setVariables(varnames, vartypes); |
1035 | + lDebugIterator->setVariables(varNames, varTypes); |
1036 | |
1037 | // link all debugger iterators in the tree |
1038 | if (!theDebuggerStack.empty()) |
1039 | |
1040 | === modified file 'src/compiler/expression/CMakeLists.txt' |
1041 | --- src/compiler/expression/CMakeLists.txt 2012-07-24 08:48:48 +0000 |
1042 | +++ src/compiler/expression/CMakeLists.txt 2012-08-10 11:20:27 +0000 |
1043 | @@ -26,7 +26,9 @@ |
1044 | fo_expr.cpp |
1045 | script_exprs.cpp |
1046 | update_exprs.cpp |
1047 | - function_item_expr.cpp) |
1048 | + function_item_expr.cpp |
1049 | + mem_manager.cpp |
1050 | + expr_manager.cpp) |
1051 | |
1052 | IF (NOT ZORBA_NO_FULL_TEXT) |
1053 | LIST(APPEND EXPRESSION_SRCS |
1054 | |
1055 | === modified file 'src/compiler/expression/expr.cpp' |
1056 | --- src/compiler/expression/expr.cpp 2012-07-24 08:48:48 +0000 |
1057 | +++ src/compiler/expression/expr.cpp 2012-08-10 11:20:27 +0000 |
1058 | @@ -1,12 +1,12 @@ |
1059 | /* |
1060 | * Copyright 2006-2008 The FLWOR Foundation. |
1061 | - * |
1062 | + * |
1063 | * Licensed under the Apache License, Version 2.0 (the "License"); |
1064 | * you may not use this file except in compliance with the License. |
1065 | * You may obtain a copy of the License at |
1066 | - * |
1067 | + * |
1068 | * http://www.apache.org/licenses/LICENSE-2.0 |
1069 | - * |
1070 | + * |
1071 | * Unless required by applicable law or agreed to in writing, software |
1072 | * distributed under the License is distributed on an "AS IS" BASIS, |
1073 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
1074 | @@ -43,12 +43,15 @@ |
1075 | #include "compiler/expression/expr_utils.h" |
1076 | #include "compiler/expression/expr_visitor.h" |
1077 | #include "compiler/parser/parse_constants.h" |
1078 | +#include "compiler/expression/expr_manager.h" |
1079 | + |
1080 | #include "compiler/api/compilercb.h" |
1081 | |
1082 | #include "store/api/store.h" |
1083 | #include "store/api/item_factory.h" |
1084 | |
1085 | -namespace zorba |
1086 | + |
1087 | +namespace zorba |
1088 | { |
1089 | |
1090 | |
1091 | @@ -88,23 +91,24 @@ |
1092 | [68] IfExpr ::= "if" "(" Expr ")" "then" ExprSingle "else" ExprSingle |
1093 | ********************************************************************************/ |
1094 | if_expr::if_expr( |
1095 | + CompilerCB* ccb, |
1096 | static_context* sctx, |
1097 | const QueryLoc& loc, |
1098 | expr_t condExpr, |
1099 | expr_t thenExpr, |
1100 | expr_t elseExpr) |
1101 | : |
1102 | - expr(sctx, loc, if_expr_kind), |
1103 | + expr(ccb, sctx, loc, if_expr_kind), |
1104 | theThenExpr(thenExpr), |
1105 | theElseExpr(elseExpr) |
1106 | { |
1107 | if (sctx != NULL && |
1108 | - !TypeOps::is_equal(sctx->get_typemanager(), |
1109 | + !TypeOps::is_equal(sctx->get_typemanager(), |
1110 | *condExpr->get_return_type(), |
1111 | *GENV_TYPESYSTEM.BOOLEAN_TYPE_ONE, |
1112 | loc)) |
1113 | { |
1114 | - fo_expr* boolExpr = new fo_expr(sctx, |
1115 | + fo_expr* boolExpr = theCCB->theEM->create_fo_expr(sctx, |
1116 | loc, |
1117 | GET_BUILTIN_FUNCTION(FN_BOOLEAN_1), |
1118 | condExpr); |
1119 | @@ -153,7 +157,7 @@ |
1120 | { |
1121 | theScriptingKind = VACUOUS_EXPR; |
1122 | } |
1123 | - else |
1124 | + else |
1125 | { |
1126 | theScriptingKind = SIMPLE_EXPR; |
1127 | } |
1128 | @@ -162,9 +166,9 @@ |
1129 | } |
1130 | |
1131 | |
1132 | -expr_t if_expr::clone(substitution_t& subst) const |
1133 | +expr_t if_expr::clone(substitution_t& subst) const |
1134 | { |
1135 | - return new if_expr(theSctx, |
1136 | + return theCCB->theEM->create_if_expr(theSctx, |
1137 | get_loc(), |
1138 | get_cond_expr()->clone(subst), |
1139 | get_then_expr()->clone(subst), |
1140 | @@ -176,12 +180,13 @@ |
1141 | |
1142 | ********************************************************************************/ |
1143 | order_expr::order_expr( |
1144 | + CompilerCB* ccb, |
1145 | static_context* sctx, |
1146 | const QueryLoc& loc, |
1147 | order_type_t type, |
1148 | expr_t inExpr) |
1149 | : |
1150 | - expr(sctx, loc, order_expr_kind), |
1151 | + expr(ccb, sctx, loc, order_expr_kind), |
1152 | theType(type), |
1153 | theExpr(inExpr) |
1154 | { |
1155 | @@ -200,7 +205,7 @@ |
1156 | |
1157 | expr_t order_expr::clone(substitution_t& subst) const |
1158 | { |
1159 | - return new order_expr(theSctx, get_loc(), get_type(), get_expr()->clone(subst)); |
1160 | + return theCCB->theEM->create_order_expr(theSctx, get_loc(), get_type(), get_expr()->clone(subst)); |
1161 | } |
1162 | |
1163 | |
1164 | @@ -208,6 +213,7 @@ |
1165 | |
1166 | ********************************************************************************/ |
1167 | validate_expr::validate_expr( |
1168 | + CompilerCB* ccb, |
1169 | static_context* sctx, |
1170 | const QueryLoc& loc, |
1171 | enum ParseConstants::validation_mode_t mode, |
1172 | @@ -215,7 +221,7 @@ |
1173 | expr_t inExpr, |
1174 | rchandle<TypeManager> typemgr) |
1175 | : |
1176 | - expr(sctx, loc, validate_expr_kind), |
1177 | + expr(ccb, sctx, loc, validate_expr_kind), |
1178 | theMode(mode), |
1179 | theTypeName(typeName), |
1180 | theTypeMgr(typemgr), |
1181 | @@ -238,7 +244,7 @@ |
1182 | |
1183 | expr_t validate_expr::clone(substitution_t& subst) const |
1184 | { |
1185 | - return new validate_expr(theSctx, |
1186 | + return theCCB->theEM->create_validate_expr(theSctx, |
1187 | get_loc(), |
1188 | get_valmode(), |
1189 | const_cast<store::Item*>(get_type_name()), |
1190 | @@ -251,12 +257,13 @@ |
1191 | Base for expression classes that require a namespace context |
1192 | ********************************************************************************/ |
1193 | namespace_context_base_expr::namespace_context_base_expr( |
1194 | + CompilerCB* ccb, |
1195 | static_context* sctx, |
1196 | const QueryLoc& loc, |
1197 | expr_kind_t kind, |
1198 | const namespace_context* aNSCtx) |
1199 | : |
1200 | - expr(sctx, loc, kind), |
1201 | + expr(ccb, sctx, loc, kind), |
1202 | theNSCtx(const_cast<namespace_context*>(aNSCtx)) |
1203 | { |
1204 | } |
1205 | @@ -264,7 +271,7 @@ |
1206 | |
1207 | const namespace_context* namespace_context_base_expr::getNSCtx() const |
1208 | { |
1209 | - return theNSCtx.getp(); |
1210 | + return theNSCtx.getp(); |
1211 | } |
1212 | |
1213 | |
1214 | @@ -273,13 +280,14 @@ |
1215 | Base for cast, treat, promote, castable, instanceof |
1216 | ********************************************************************************/ |
1217 | cast_or_castable_base_expr::cast_or_castable_base_expr( |
1218 | + CompilerCB* ccb, |
1219 | static_context* sctx, |
1220 | const QueryLoc& loc, |
1221 | expr_kind_t kind, |
1222 | const expr_t& input, |
1223 | const xqtref_t& type) |
1224 | : |
1225 | - expr(sctx, loc, kind), |
1226 | + expr(ccb, sctx, loc, kind), |
1227 | theInputExpr(input), |
1228 | theTargetType(type) |
1229 | { |
1230 | @@ -290,13 +298,13 @@ |
1231 | } |
1232 | |
1233 | |
1234 | -xqtref_t cast_or_castable_base_expr::get_target_type() const |
1235 | +xqtref_t cast_or_castable_base_expr::get_target_type() const |
1236 | { |
1237 | return theTargetType; |
1238 | } |
1239 | |
1240 | |
1241 | -void cast_or_castable_base_expr::set_target_type(xqtref_t target) |
1242 | +void cast_or_castable_base_expr::set_target_type(xqtref_t target) |
1243 | { |
1244 | theTargetType = target; |
1245 | } |
1246 | @@ -317,13 +325,14 @@ |
1247 | Base for cast, treat, promote |
1248 | ********************************************************************************/ |
1249 | cast_base_expr::cast_base_expr( |
1250 | + CompilerCB* ccb, |
1251 | static_context* sctx, |
1252 | const QueryLoc& loc, |
1253 | expr_kind_t kind, |
1254 | const expr_t& input, |
1255 | const xqtref_t& type) |
1256 | - : |
1257 | - cast_or_castable_base_expr(sctx, loc, kind, input, type) |
1258 | + : |
1259 | + cast_or_castable_base_expr(ccb, sctx, loc, kind, input, type) |
1260 | { |
1261 | setNonDiscardable(ANNOTATION_TRUE_FIXED); |
1262 | } |
1263 | @@ -335,37 +344,39 @@ |
1264 | SingleType ::= AtomicType "?"? |
1265 | ********************************************************************************/ |
1266 | cast_expr::cast_expr( |
1267 | + CompilerCB* ccb, |
1268 | static_context* sctx, |
1269 | const QueryLoc& loc, |
1270 | const expr_t& inputExpr, |
1271 | const xqtref_t& type) |
1272 | : |
1273 | - cast_base_expr(sctx, loc, cast_expr_kind, inputExpr, type) |
1274 | + cast_base_expr(ccb, sctx, loc, cast_expr_kind, inputExpr, type) |
1275 | { |
1276 | assert(type->get_quantifier() == TypeConstants::QUANT_ONE || |
1277 | type->get_quantifier() == TypeConstants::QUANT_QUESTION); |
1278 | } |
1279 | |
1280 | |
1281 | -bool cast_expr::is_optional() const |
1282 | +bool cast_expr::is_optional() const |
1283 | { |
1284 | - return theTargetType->get_quantifier() == TypeConstants::QUANT_QUESTION; |
1285 | + return theTargetType->get_quantifier() == TypeConstants::QUANT_QUESTION; |
1286 | } |
1287 | |
1288 | |
1289 | expr_t cast_expr::clone(substitution_t& subst) const |
1290 | { |
1291 | - return new cast_expr(theSctx, |
1292 | + return theCCB->theEM->create_cast_expr(theSctx, |
1293 | get_loc(), |
1294 | - get_input()->clone(subst), |
1295 | + get_input()->clone(subst), |
1296 | get_target_type()); |
1297 | } |
1298 | |
1299 | |
1300 | /***************************************************************************//** |
1301 | - TreatExpr ::= CastableExpr ( "treat" "as" SequenceType )? |
1302 | + TreatExpr ::= CastableExpr ( "treat" "as" SequenceType )? |
1303 | ********************************************************************************/ |
1304 | treat_expr::treat_expr( |
1305 | + CompilerCB* ccb, |
1306 | static_context* sctx, |
1307 | const QueryLoc& loc, |
1308 | const expr_t& inputExpr, |
1309 | @@ -374,7 +385,7 @@ |
1310 | bool check_prime, |
1311 | store::Item* qname) |
1312 | : |
1313 | - cast_base_expr(sctx, loc, treat_expr_kind, inputExpr, type), |
1314 | + cast_base_expr(ccb, sctx, loc, treat_expr_kind, inputExpr, type), |
1315 | theErrorKind(err), |
1316 | theCheckPrime(check_prime), |
1317 | theQName(qname) |
1318 | @@ -384,9 +395,9 @@ |
1319 | |
1320 | expr_t treat_expr::clone(substitution_t& subst) const |
1321 | { |
1322 | - return new treat_expr(theSctx, |
1323 | + return theCCB->theEM->create_treat_expr(theSctx, |
1324 | get_loc(), |
1325 | - get_input()->clone(subst), |
1326 | + get_input()->clone(subst), |
1327 | get_target_type(), |
1328 | get_err(), |
1329 | get_check_prime(), |
1330 | @@ -398,6 +409,7 @@ |
1331 | |
1332 | ********************************************************************************/ |
1333 | promote_expr::promote_expr( |
1334 | + CompilerCB* ccb, |
1335 | static_context* sctx, |
1336 | const QueryLoc& loc, |
1337 | const expr_t& input, |
1338 | @@ -405,7 +417,7 @@ |
1339 | PromoteIterator::ErrorKind err, |
1340 | store::Item* qname) |
1341 | : |
1342 | - cast_base_expr(sctx, loc, promote_expr_kind, input, type), |
1343 | + cast_base_expr(ccb, sctx, loc, promote_expr_kind, input, type), |
1344 | theErrorKind(err), |
1345 | theQName(qname) |
1346 | { |
1347 | @@ -414,7 +426,7 @@ |
1348 | |
1349 | expr_t promote_expr::clone(substitution_t& subst) const |
1350 | { |
1351 | - return new promote_expr(theSctx, |
1352 | + return theCCB->theEM->create_promote_expr(theSctx, |
1353 | get_loc(), |
1354 | get_input()->clone(subst), |
1355 | get_target_type(), |
1356 | @@ -427,13 +439,14 @@ |
1357 | Base for castable, instanceof |
1358 | ********************************************************************************/ |
1359 | castable_base_expr::castable_base_expr( |
1360 | + CompilerCB* ccb, |
1361 | static_context* sctx, |
1362 | const QueryLoc& loc, |
1363 | expr_kind_t kind, |
1364 | const expr_t& input, |
1365 | const xqtref_t& type) |
1366 | : |
1367 | - cast_or_castable_base_expr(sctx, loc, kind, input, type) |
1368 | + cast_or_castable_base_expr(ccb, sctx, loc, kind, input, type) |
1369 | { |
1370 | } |
1371 | |
1372 | @@ -444,25 +457,26 @@ |
1373 | SingleType ::= AtomicType "?"? |
1374 | ********************************************************************************/ |
1375 | castable_expr::castable_expr( |
1376 | + CompilerCB* ccb, |
1377 | static_context* sctx, |
1378 | const QueryLoc& loc, |
1379 | const expr_t& inputExpr, |
1380 | const xqtref_t& type) |
1381 | : |
1382 | - castable_base_expr (sctx, loc, castable_expr_kind, inputExpr, type) |
1383 | + castable_base_expr (ccb, sctx, loc, castable_expr_kind, inputExpr, type) |
1384 | { |
1385 | } |
1386 | |
1387 | |
1388 | -bool castable_expr::is_optional() const |
1389 | +bool castable_expr::is_optional() const |
1390 | { |
1391 | - return theTargetType->get_quantifier() == TypeConstants::QUANT_QUESTION; |
1392 | + return theTargetType->get_quantifier() == TypeConstants::QUANT_QUESTION; |
1393 | } |
1394 | |
1395 | |
1396 | expr_t castable_expr::clone(substitution_t& subst) const |
1397 | { |
1398 | - return new castable_expr(theSctx, |
1399 | + return theCCB->theEM->create_castable_expr(theSctx, |
1400 | get_loc(), |
1401 | get_input()->clone(subst), |
1402 | get_target_type()); |
1403 | @@ -470,16 +484,17 @@ |
1404 | |
1405 | |
1406 | /***************************************************************************//** |
1407 | - InstanceofExpr ::= TreatExpr ( "instance" "of" SequenceType )? |
1408 | + InstanceofExpr ::= TreatExpr ( "instance" "of" SequenceType )? |
1409 | ********************************************************************************/ |
1410 | instanceof_expr::instanceof_expr( |
1411 | + CompilerCB* ccb, |
1412 | static_context* sctx, |
1413 | const QueryLoc& loc, |
1414 | const expr_t& inputExpr, |
1415 | const xqtref_t& type, |
1416 | bool checkPrimeOnly) |
1417 | : |
1418 | - castable_base_expr(sctx, loc, instanceof_expr_kind, inputExpr, type), |
1419 | + castable_base_expr(ccb, sctx, loc, instanceof_expr_kind, inputExpr, type), |
1420 | theCheckPrimeOnly(checkPrimeOnly) |
1421 | { |
1422 | } |
1423 | @@ -487,7 +502,7 @@ |
1424 | |
1425 | expr_t instanceof_expr::clone(substitution_t& subst) const |
1426 | { |
1427 | - return new instanceof_expr(theSctx, |
1428 | + return theCCB->theEM->create_instanceof_expr(theSctx, |
1429 | get_loc(), |
1430 | get_input()->clone(subst), |
1431 | get_target_type()); |
1432 | @@ -498,13 +513,14 @@ |
1433 | |
1434 | ********************************************************************************/ |
1435 | name_cast_expr::name_cast_expr( |
1436 | + CompilerCB* ccb, |
1437 | static_context* sctx, |
1438 | const QueryLoc& loc, |
1439 | expr_t inputExpr, |
1440 | const namespace_context* aNSCtx, |
1441 | bool isAttrName) |
1442 | : |
1443 | - namespace_context_base_expr(sctx, loc, name_cast_expr_kind, aNSCtx), |
1444 | + namespace_context_base_expr(ccb, sctx, loc, name_cast_expr_kind, aNSCtx), |
1445 | theInputExpr(inputExpr), |
1446 | theIsAttrName(isAttrName) |
1447 | { |
1448 | @@ -525,7 +541,7 @@ |
1449 | |
1450 | expr_t name_cast_expr::clone(substitution_t& subst) const |
1451 | { |
1452 | - return new name_cast_expr(theSctx, |
1453 | + return theCCB->theEM->create_name_cast_expr(theSctx, |
1454 | get_loc(), |
1455 | get_input()->clone(subst), |
1456 | getNSCtx(), |
1457 | @@ -537,12 +553,13 @@ |
1458 | CompDocConstructor ::= "document" "{" Expr "}" |
1459 | ********************************************************************************/ |
1460 | doc_expr::doc_expr( |
1461 | + CompilerCB* ccb, |
1462 | static_context* sctx, |
1463 | const QueryLoc& loc, |
1464 | expr* aContent, |
1465 | bool copyNodes) |
1466 | : |
1467 | - expr(sctx, loc, doc_expr_kind), |
1468 | + expr(ccb, sctx, loc, doc_expr_kind), |
1469 | theContent(aContent), |
1470 | theCopyInputNodes(copyNodes) |
1471 | { |
1472 | @@ -563,7 +580,7 @@ |
1473 | |
1474 | expr_t doc_expr::clone(substitution_t& subst) const |
1475 | { |
1476 | - doc_expr* clone = new doc_expr(theSctx, |
1477 | + doc_expr* clone = theCCB->theEM->create_doc_expr(theSctx, |
1478 | get_loc(), |
1479 | CLONE(getContent(), subst), |
1480 | theCopyInputNodes); |
1481 | @@ -575,6 +592,7 @@ |
1482 | |
1483 | ********************************************************************************/ |
1484 | elem_expr::elem_expr( |
1485 | + CompilerCB* ccb, |
1486 | static_context* sctx, |
1487 | const QueryLoc& aLoc, |
1488 | expr* aQNameExpr, |
1489 | @@ -583,7 +601,7 @@ |
1490 | const namespace_context* aNSCtx, |
1491 | bool copyNodes) |
1492 | : |
1493 | - namespace_context_base_expr(sctx, aLoc, elem_expr_kind, aNSCtx), |
1494 | + namespace_context_base_expr(ccb, sctx, aLoc, elem_expr_kind, aNSCtx), |
1495 | theQNameExpr(aQNameExpr), |
1496 | theAttrs(attrs), |
1497 | theContent(content), |
1498 | @@ -596,6 +614,7 @@ |
1499 | |
1500 | |
1501 | elem_expr::elem_expr( |
1502 | + CompilerCB* ccb, |
1503 | static_context* sctx, |
1504 | const QueryLoc& aLoc, |
1505 | expr* aQNameExpr, |
1506 | @@ -603,7 +622,7 @@ |
1507 | const namespace_context* aNSCtx, |
1508 | bool copyNodes) |
1509 | : |
1510 | - namespace_context_base_expr(sctx, aLoc, elem_expr_kind, aNSCtx), |
1511 | + namespace_context_base_expr(ccb, sctx, aLoc, elem_expr_kind, aNSCtx), |
1512 | theQNameExpr(aQNameExpr), |
1513 | theAttrs(0), |
1514 | theContent(content), |
1515 | @@ -613,7 +632,7 @@ |
1516 | |
1517 | setUnfoldable(ANNOTATION_TRUE_FIXED); |
1518 | } |
1519 | - |
1520 | + |
1521 | |
1522 | void elem_expr::compute_scripting_kind() |
1523 | { |
1524 | @@ -643,7 +662,7 @@ |
1525 | |
1526 | expr_t elem_expr::clone(substitution_t& subst) const |
1527 | { |
1528 | - elem_expr* clone = new elem_expr(theSctx, |
1529 | + elem_expr* clone = theCCB->theEM->create_elem_expr(theSctx, |
1530 | get_loc(), |
1531 | CLONE(getQNameExpr(), subst), |
1532 | CLONE(getAttrs(), subst), |
1533 | @@ -658,12 +677,13 @@ |
1534 | |
1535 | ********************************************************************************/ |
1536 | attr_expr::attr_expr( |
1537 | + CompilerCB* ccb, |
1538 | static_context* sctx, |
1539 | const QueryLoc& loc, |
1540 | expr_t aQNameExpr, |
1541 | expr_t aValueExpr) |
1542 | : |
1543 | - expr(sctx, loc, attr_expr_kind), |
1544 | + expr(ccb, sctx, loc, attr_expr_kind), |
1545 | theQNameExpr(aQNameExpr), |
1546 | theValueExpr(aValueExpr) |
1547 | { |
1548 | @@ -709,7 +729,7 @@ |
1549 | |
1550 | expr_t attr_expr::clone(substitution_t& subst) const |
1551 | { |
1552 | - return new attr_expr(theSctx, |
1553 | + return theCCB->theEM->create_attr_expr(theSctx, |
1554 | get_loc(), |
1555 | CLONE(getQNameExpr(), subst), |
1556 | CLONE(getValueExpr(), subst)); |
1557 | @@ -723,12 +743,13 @@ |
1558 | |
1559 | ********************************************************************************/ |
1560 | text_expr::text_expr( |
1561 | + CompilerCB* ccb, |
1562 | static_context* sctx, |
1563 | const QueryLoc& loc, |
1564 | text_constructor_type type_arg, |
1565 | expr_t content) |
1566 | : |
1567 | - expr(sctx, loc, text_expr_kind), |
1568 | + expr(ccb, sctx, loc, text_expr_kind), |
1569 | type(type_arg), |
1570 | theContentExpr(content) |
1571 | { |
1572 | @@ -751,7 +772,7 @@ |
1573 | |
1574 | expr_t text_expr::clone(substitution_t& subst) const |
1575 | { |
1576 | - return new text_expr(theSctx, get_loc(), get_type(), CLONE(get_text(), subst)); |
1577 | + return theCCB->theEM->create_text_expr(theSctx, get_loc(), get_type(), CLONE(get_text(), subst)); |
1578 | } |
1579 | |
1580 | |
1581 | @@ -759,12 +780,13 @@ |
1582 | |
1583 | ********************************************************************************/ |
1584 | pi_expr::pi_expr( |
1585 | + CompilerCB* ccb, |
1586 | static_context* sctx, |
1587 | const QueryLoc& loc, |
1588 | expr_t targetExpr, |
1589 | expr_t contentExpr) |
1590 | : |
1591 | - expr(sctx, loc, pi_expr_kind), |
1592 | + expr(ccb, sctx, loc, pi_expr_kind), |
1593 | theTargetExpr(targetExpr), |
1594 | theContentExpr(contentExpr) |
1595 | { |
1596 | @@ -800,7 +822,7 @@ |
1597 | |
1598 | expr_t pi_expr::clone(substitution_t& subst) const |
1599 | { |
1600 | - return new pi_expr(theSctx, |
1601 | + return theCCB->theEM->create_pi_expr(theSctx, |
1602 | get_loc(), |
1603 | CLONE(get_target_expr(), subst), |
1604 | CLONE(get_content_expr(), subst)); |
1605 | @@ -812,9 +834,9 @@ |
1606 | Normally, it is used to wrap a var_expr in order to represent a var reference |
1607 | (see var_expr.h). But it may wrap any other kind of expr as well. |
1608 | ********************************************************************************/ |
1609 | -wrapper_expr::wrapper_expr(static_context* sctx, const QueryLoc& loc, expr_t wrapped) |
1610 | +wrapper_expr::wrapper_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc& loc, expr_t wrapped) |
1611 | : |
1612 | - expr(sctx, loc, wrapper_expr_kind), |
1613 | + expr(ccb, sctx, loc, wrapper_expr_kind), |
1614 | theWrappedExpr(wrapped) |
1615 | { |
1616 | compute_scripting_kind(); |
1617 | @@ -835,67 +857,69 @@ |
1618 | e->get_expr_kind() != var_expr_kind) |
1619 | return e; |
1620 | else |
1621 | - return new wrapper_expr(theSctx, get_loc(), e); |
1622 | + return theCCB->theEM->create_wrapper_expr(theSctx, get_loc(), e); |
1623 | } |
1624 | |
1625 | |
1626 | /***************************************************************************//** |
1627 | |
1628 | ********************************************************************************/ |
1629 | -const_expr::const_expr(static_context* sctx, const QueryLoc& loc, zstring& v) |
1630 | - : |
1631 | - expr(sctx, loc, const_expr_kind) |
1632 | -{ |
1633 | - GENV_ITEMFACTORY->createString(theValue, v); |
1634 | - theScriptingKind = SIMPLE_EXPR; |
1635 | -} |
1636 | - |
1637 | - |
1638 | -const_expr::const_expr(static_context* sctx, const QueryLoc& loc, const std::string& v) |
1639 | - : |
1640 | - expr(sctx, loc, const_expr_kind) |
1641 | -{ |
1642 | - zstring tmp(v); |
1643 | - GENV_ITEMFACTORY->createString(theValue, tmp); |
1644 | - theScriptingKind = SIMPLE_EXPR; |
1645 | -} |
1646 | - |
1647 | - |
1648 | -const_expr::const_expr(static_context* sctx, const QueryLoc& loc, const char* v) |
1649 | - : |
1650 | - expr(sctx, loc, const_expr_kind) |
1651 | -{ |
1652 | - zstring tmp(v); |
1653 | - GENV_ITEMFACTORY->createString(theValue, tmp); |
1654 | - theScriptingKind = SIMPLE_EXPR; |
1655 | -} |
1656 | - |
1657 | - |
1658 | -const_expr::const_expr(static_context* sctx, const QueryLoc& loc, xs_integer v) |
1659 | - : |
1660 | - expr(sctx, loc, const_expr_kind) |
1661 | +const_expr::const_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc& loc, zstring& v) |
1662 | + : |
1663 | + expr(ccb, sctx, loc, const_expr_kind) |
1664 | +{ |
1665 | + GENV_ITEMFACTORY->createString(theValue, v); |
1666 | + theScriptingKind = SIMPLE_EXPR; |
1667 | +} |
1668 | + |
1669 | + |
1670 | +const_expr::const_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc& loc, const std::string& v) |
1671 | + : |
1672 | + expr(ccb, sctx, loc, const_expr_kind) |
1673 | +{ |
1674 | + zstring tmp(v); |
1675 | + GENV_ITEMFACTORY->createString(theValue, tmp); |
1676 | + theScriptingKind = SIMPLE_EXPR; |
1677 | +} |
1678 | + |
1679 | + |
1680 | +const_expr::const_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc& loc, const char* v) |
1681 | + : |
1682 | + expr(ccb, sctx, loc, const_expr_kind) |
1683 | +{ |
1684 | + zstring tmp(v); |
1685 | + GENV_ITEMFACTORY->createString(theValue, tmp); |
1686 | + theScriptingKind = SIMPLE_EXPR; |
1687 | +} |
1688 | + |
1689 | + |
1690 | +const_expr::const_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc& loc, xs_integer v) |
1691 | + : |
1692 | + expr(ccb, sctx, loc, const_expr_kind) |
1693 | { |
1694 | GENV_ITEMFACTORY->createInteger(theValue, v); |
1695 | theScriptingKind = SIMPLE_EXPR; |
1696 | } |
1697 | |
1698 | const_expr::const_expr( |
1699 | + CompilerCB* ccb, |
1700 | static_context* sctx, |
1701 | const QueryLoc& loc, |
1702 | xs_decimal v) |
1703 | : |
1704 | - expr(sctx, loc, const_expr_kind) |
1705 | + expr(ccb, sctx, loc, const_expr_kind) |
1706 | { |
1707 | GENV_ITEMFACTORY->createDecimal(theValue, v); |
1708 | theScriptingKind = SIMPLE_EXPR; |
1709 | } |
1710 | |
1711 | const_expr::const_expr( |
1712 | + CompilerCB* ccb, |
1713 | static_context* sctx, |
1714 | const QueryLoc& loc, |
1715 | xs_double v) |
1716 | : |
1717 | - expr(sctx, loc, const_expr_kind) |
1718 | + expr(ccb, sctx, loc, const_expr_kind) |
1719 | { |
1720 | GENV_ITEMFACTORY->createDouble(theValue, v); |
1721 | theScriptingKind = SIMPLE_EXPR; |
1722 | @@ -903,11 +927,12 @@ |
1723 | |
1724 | |
1725 | const_expr::const_expr( |
1726 | + CompilerCB* ccb, |
1727 | static_context* sctx, |
1728 | const QueryLoc& loc, |
1729 | xs_boolean v) |
1730 | : |
1731 | - expr(sctx, loc, const_expr_kind) |
1732 | + expr(ccb, sctx, loc, const_expr_kind) |
1733 | { |
1734 | GENV_ITEMFACTORY->createBoolean(theValue, v); |
1735 | theScriptingKind = SIMPLE_EXPR; |
1736 | @@ -915,11 +940,12 @@ |
1737 | |
1738 | |
1739 | const_expr::const_expr( |
1740 | + CompilerCB* ccb, |
1741 | static_context* sctx, |
1742 | const QueryLoc& loc, |
1743 | store::Item_t v) |
1744 | : |
1745 | - expr(sctx, loc, const_expr_kind), |
1746 | + expr(ccb, sctx, loc, const_expr_kind), |
1747 | theValue(v) |
1748 | { |
1749 | theScriptingKind = SIMPLE_EXPR; |
1750 | @@ -927,13 +953,14 @@ |
1751 | |
1752 | |
1753 | const_expr::const_expr( |
1754 | + CompilerCB* ccb, |
1755 | static_context* sctx, |
1756 | - const QueryLoc& aLoc, |
1757 | + const QueryLoc& aLoc, |
1758 | const char* aNamespace, |
1759 | - const char* aPrefix, |
1760 | + const char* aPrefix, |
1761 | const char* aLocal) |
1762 | : |
1763 | - expr(sctx, aLoc, const_expr_kind) |
1764 | + expr(ccb, sctx, aLoc, const_expr_kind) |
1765 | { |
1766 | GENV_ITEMFACTORY->createQName(theValue, aNamespace, aPrefix, aLocal); |
1767 | theScriptingKind = SIMPLE_EXPR; |
1768 | @@ -948,7 +975,7 @@ |
1769 | |
1770 | expr_t const_expr::clone(substitution_t&) const |
1771 | { |
1772 | - return new const_expr(theSctx, get_loc(), theValue); |
1773 | + return theCCB->theEM->create_const_expr(theSctx, get_loc(), theValue); |
1774 | } |
1775 | |
1776 | |
1777 | @@ -964,21 +991,23 @@ |
1778 | |
1779 | |
1780 | extension_expr::extension_expr( |
1781 | + CompilerCB* ccb, |
1782 | static_context* sctx, |
1783 | const QueryLoc& loc) |
1784 | : |
1785 | - expr(sctx, loc, extension_expr_kind) |
1786 | + expr(ccb, sctx, loc, extension_expr_kind) |
1787 | { |
1788 | compute_scripting_kind(); |
1789 | } |
1790 | |
1791 | |
1792 | extension_expr::extension_expr( |
1793 | + CompilerCB* ccb, |
1794 | static_context* sctx, |
1795 | const QueryLoc& loc, |
1796 | expr_t e) |
1797 | : |
1798 | - expr(sctx, loc, extension_expr_kind), |
1799 | + expr(ccb, sctx, loc, extension_expr_kind), |
1800 | theExpr(e) |
1801 | { |
1802 | compute_scripting_kind(); |
1803 | @@ -996,16 +1025,16 @@ |
1804 | } |
1805 | |
1806 | |
1807 | -expr_t extension_expr::clone(substitution_t& subst) const |
1808 | +expr_t extension_expr::clone(substitution_t& subst) const |
1809 | { |
1810 | rchandle<extension_expr> lClone(0); |
1811 | lClone = ( |
1812 | - theExpr == 0 ? new extension_expr(theSctx, get_loc()) |
1813 | - : new extension_expr(theSctx, get_loc(), theExpr->clone()) ); |
1814 | + theExpr == 0 ? theCCB->theEM->create_extension_expr(theSctx, get_loc()) |
1815 | + : theCCB->theEM->create_extension_expr(theSctx, get_loc(), theExpr->clone()) ); |
1816 | // pragm doesn't contain expressions. Thus, it is not cloned. |
1817 | for ( std::vector<rchandle<pragma> >::const_iterator lIter = thePragmas.begin(); |
1818 | lIter != thePragmas.end(); |
1819 | - ++lIter ) |
1820 | + ++lIter ) |
1821 | { |
1822 | lClone->add(*lIter); |
1823 | } |
1824 | @@ -1015,7 +1044,7 @@ |
1825 | |
1826 | ///////////////////////////////////////////////////////////////////////// |
1827 | // // |
1828 | -// XQuery 3.0 expressions // |
1829 | +// XQuery 3.0 expressions // |
1830 | // [http://www.w3.org/TR/xquery-3/] // |
1831 | // // |
1832 | ///////////////////////////////////////////////////////////////////////// |
1833 | @@ -1030,11 +1059,12 @@ |
1834 | |
1835 | |
1836 | trycatch_expr::trycatch_expr( |
1837 | + CompilerCB* ccb, |
1838 | static_context* sctx, |
1839 | const QueryLoc& loc, |
1840 | expr_t tryExpr) |
1841 | : |
1842 | - expr(sctx, loc, trycatch_expr_kind), |
1843 | + expr(ccb, sctx, loc, trycatch_expr_kind), |
1844 | theTryExpr(tryExpr) |
1845 | { |
1846 | compute_scripting_kind(); |
1847 | @@ -1068,7 +1098,7 @@ |
1848 | |
1849 | csize numCatchClauses = theCatchClauses.size(); |
1850 | |
1851 | - for (csize i = 0; i < numCatchClauses; ++i) |
1852 | + for (csize i = 0; i < numCatchClauses; ++i) |
1853 | { |
1854 | const expr* catchExpr = theCatchExprs[i].getp(); |
1855 | short catchKind = catchExpr->get_scripting_detail(); |
1856 | @@ -1085,7 +1115,7 @@ |
1857 | RAISE_ERROR(err::XUST0001, catchExpr->get_loc(), |
1858 | ERROR_PARAMS(ZED(XUST0001_TRYCATCH))); |
1859 | } |
1860 | - |
1861 | + |
1862 | if (!is_updating() && !is_vacuous() && (catchKind & UPDATING_EXPR)) |
1863 | { |
1864 | RAISE_ERROR(err::XUST0001, catchExpr->get_loc(), |
1865 | @@ -1115,13 +1145,13 @@ |
1866 | |
1867 | for (nt_list_t::const_iterator lIter = theNameTests.begin(); |
1868 | lIter != theNameTests.end(); |
1869 | - ++lIter) |
1870 | + ++lIter) |
1871 | { |
1872 | lClause->add_nametest_h(lIter->getp()); |
1873 | } |
1874 | for (var_map_t::const_iterator lIter = theVarMap.begin(); |
1875 | lIter != theVarMap.end(); |
1876 | - ++lIter) |
1877 | + ++lIter) |
1878 | { |
1879 | lClause->add_var((catch_clause::var_type)lIter->first, lIter->second.getp()); |
1880 | } |
1881 | @@ -1133,16 +1163,16 @@ |
1882 | expr_t trycatch_expr::clone(substitution_t& subst) const |
1883 | { |
1884 | std::auto_ptr<trycatch_expr> lTryCatch( |
1885 | - new trycatch_expr(theSctx, get_loc(), theTryExpr->clone(subst))); |
1886 | + theCCB->theEM->create_trycatch_expr(theSctx, get_loc(), theTryExpr->clone(subst))); |
1887 | |
1888 | for (std::vector<expr_t>::const_iterator lIter = theCatchExprs.begin(); |
1889 | lIter != theCatchExprs.end(); |
1890 | - ++lIter) |
1891 | + ++lIter) |
1892 | { |
1893 | lTryCatch->add_catch_expr((*lIter)->clone(subst)); |
1894 | } |
1895 | |
1896 | - for (uint32_t i = 0; i < clause_count(); ++i) |
1897 | + for (uint32_t i = 0; i < clause_count(); ++i) |
1898 | { |
1899 | lTryCatch->add_clause(theCatchClauses[i]->clone(subst)); |
1900 | } |
1901 | @@ -1155,14 +1185,15 @@ |
1902 | |
1903 | ********************************************************************************/ |
1904 | eval_expr::eval_expr( |
1905 | + CompilerCB* creating_ccb, |
1906 | CompilerCB* ccb, |
1907 | static_context* sctx, |
1908 | - const QueryLoc& loc, |
1909 | + const QueryLoc& loc, |
1910 | const expr_t& e, |
1911 | expr_script_kind_t scriptingKind, |
1912 | namespace_context* nsCtx) |
1913 | : |
1914 | - namespace_context_base_expr(sctx, loc, eval_expr_kind, nsCtx), |
1915 | + namespace_context_base_expr(creating_ccb, sctx, loc, eval_expr_kind, nsCtx), |
1916 | theExpr(e), |
1917 | theInnerScriptingKind(scriptingKind), |
1918 | theDoNodeCopy(false) |
1919 | @@ -1174,9 +1205,9 @@ |
1920 | } |
1921 | |
1922 | |
1923 | -expr_script_kind_t eval_expr::get_inner_scripting_kind() const |
1924 | +expr_script_kind_t eval_expr::get_inner_scripting_kind() const |
1925 | { |
1926 | - return theInnerScriptingKind; |
1927 | + return theInnerScriptingKind; |
1928 | } |
1929 | |
1930 | |
1931 | @@ -1198,9 +1229,10 @@ |
1932 | |
1933 | expr_t eval_expr::clone(substitution_t& s) const |
1934 | { |
1935 | - rchandle<eval_expr> new_eval = new eval_expr(NULL, |
1936 | - theSctx, |
1937 | - theLoc, |
1938 | + rchandle<eval_expr> new_eval = theCCB->theEM->create_eval_expr( |
1939 | + NULL, |
1940 | + theSctx, |
1941 | + theLoc, |
1942 | theExpr->clone(s), |
1943 | theInnerScriptingKind, |
1944 | theNSCtx.getp()); |
1945 | @@ -1210,7 +1242,7 @@ |
1946 | { |
1947 | var_expr_t cloneVar = dynamic_cast<var_expr*>(theVars[i]->clone(s).getp()); |
1948 | assert(cloneVar != NULL); |
1949 | - new_eval->add_var(cloneVar, theArgs[i]->clone(s)); |
1950 | + new_eval->add_var(cloneVar, (theArgs[i] ? theArgs[i]->clone(s) : NULL)); |
1951 | } |
1952 | |
1953 | return new_eval.getp(); |
1954 | @@ -1222,13 +1254,14 @@ |
1955 | |
1956 | ********************************************************************************/ |
1957 | debugger_expr::debugger_expr( |
1958 | + CompilerCB* ccb, |
1959 | static_context* sctx, |
1960 | const QueryLoc& loc, |
1961 | const expr_t& aChild, |
1962 | namespace_context* nsCtx, |
1963 | bool aIsVarDeclaration) |
1964 | : |
1965 | - namespace_context_base_expr(sctx, loc, debugger_expr_kind, nsCtx), |
1966 | + namespace_context_base_expr(ccb, sctx, loc, debugger_expr_kind, nsCtx), |
1967 | theExpr(aChild), |
1968 | theIsVarDeclaration(aIsVarDeclaration) |
1969 | { |
1970 | @@ -1248,11 +1281,12 @@ |
1971 | |
1972 | ********************************************************************************/ |
1973 | function_trace_expr::function_trace_expr( |
1974 | + CompilerCB* ccb, |
1975 | static_context* sctx, |
1976 | const QueryLoc& loc, |
1977 | expr_t aChild) |
1978 | : |
1979 | - expr(sctx, loc, function_trace_expr_kind), |
1980 | + expr(ccb, sctx, loc, aChild->get_expr_kind()), |
1981 | theExpr(aChild), |
1982 | theFunctionArity(0) |
1983 | { |
1984 | @@ -1264,7 +1298,7 @@ |
1985 | |
1986 | function_trace_expr::function_trace_expr(expr_t aExpr) |
1987 | : |
1988 | - expr(aExpr->get_sctx(), aExpr->get_loc(), function_trace_expr_kind), |
1989 | + expr(aExpr->get_ccb(), aExpr->get_sctx(), aExpr->get_loc(), function_trace_expr_kind), |
1990 | theExpr(aExpr), |
1991 | theFunctionArity(0) |
1992 | { |
1993 | @@ -1274,7 +1308,7 @@ |
1994 | } |
1995 | |
1996 | |
1997 | -function_trace_expr::~function_trace_expr() |
1998 | +function_trace_expr::~function_trace_expr() |
1999 | { |
2000 | } |
2001 | |
2002 | @@ -1287,12 +1321,14 @@ |
2003 | |
2004 | expr_t function_trace_expr::clone(substitution_t& s) const |
2005 | { |
2006 | - function_trace_expr* clone = new function_trace_expr(theExpr->clone(s)); |
2007 | + function_trace_expr* clone = theCCB->theEM-> |
2008 | + create_function_trace_expr(theExpr->clone(s)); |
2009 | |
2010 | clone->theFunctionName = theFunctionName; |
2011 | clone->theFunctionLocation = theFunctionLocation; |
2012 | clone->theFunctionCallLocation = theFunctionCallLocation; |
2013 | clone->theFunctionArity = theFunctionArity; |
2014 | + |
2015 | return clone; |
2016 | } |
2017 | |
2018 | |
2019 | === modified file 'src/compiler/expression/expr.h' |
2020 | --- src/compiler/expression/expr.h 2012-07-24 08:48:48 +0000 |
2021 | +++ src/compiler/expression/expr.h 2012-08-10 11:20:27 +0000 |
2022 | @@ -1,12 +1,12 @@ |
2023 | /* |
2024 | * Copyright 2006-2008 The FLWOR Foundation. |
2025 | - * |
2026 | + * |
2027 | * Licensed under the Apache License, Version 2.0 (the "License"); |
2028 | * you may not use this file except in compliance with the License. |
2029 | * You may obtain a copy of the License at |
2030 | - * |
2031 | + * |
2032 | * http://www.apache.org/licenses/LICENSE-2.0 |
2033 | - * |
2034 | + * |
2035 | * Unless required by applicable law or agreed to in writing, software |
2036 | * distributed under the License is distributed on an "AS IS" BASIS, |
2037 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
2038 | @@ -39,20 +39,20 @@ |
2039 | |
2040 | #include "runtime/core/sequencetypes.h" |
2041 | |
2042 | -namespace zorba |
2043 | +namespace zorba |
2044 | { |
2045 | |
2046 | +class ExprManager; |
2047 | class expr_visitor; |
2048 | class NodeNameTest; |
2049 | class signature; |
2050 | |
2051 | - |
2052 | - |
2053 | /******************************************************************************* |
2054 | [68] IfExpr ::= "if" "(" Expr ")" "then" ExprSingle "else" ExprSingle |
2055 | ********************************************************************************/ |
2056 | -class if_expr : public expr |
2057 | +class if_expr : public expr |
2058 | { |
2059 | + friend class ExprManager; |
2060 | friend class ExprIterator; |
2061 | friend class expr; |
2062 | |
2063 | @@ -61,14 +61,16 @@ |
2064 | expr_t theThenExpr; |
2065 | expr_t theElseExpr; |
2066 | |
2067 | -public: |
2068 | +protected: |
2069 | if_expr( |
2070 | + CompilerCB* ccb, |
2071 | static_context* sctx, |
2072 | const QueryLoc& loc, |
2073 | expr_t c, |
2074 | expr_t t, |
2075 | expr_t e); |
2076 | |
2077 | +public: |
2078 | expr* get_cond_expr() const { return theCondExpr.getp(); } |
2079 | |
2080 | expr* get_then_expr() const { return theThenExpr.getp(); } |
2081 | @@ -88,13 +90,14 @@ |
2082 | /***************************************************************************//** |
2083 | |
2084 | ********************************************************************************/ |
2085 | -class order_expr : public expr |
2086 | +class order_expr : public expr |
2087 | { |
2088 | + friend class ExprManager; |
2089 | friend class ExprIterator; |
2090 | friend class expr; |
2091 | |
2092 | public: |
2093 | - enum order_type_t |
2094 | + enum order_type_t |
2095 | { |
2096 | ordered, |
2097 | unordered |
2098 | @@ -104,9 +107,10 @@ |
2099 | order_type_t theType; |
2100 | expr_t theExpr; |
2101 | |
2102 | +protected: |
2103 | + order_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc&, order_type_t, expr_t); |
2104 | + |
2105 | public: |
2106 | - order_expr(static_context* sctx, const QueryLoc&, order_type_t, expr_t); |
2107 | - |
2108 | order_type_t get_type() const { return theType; } |
2109 | |
2110 | expr* get_expr() const { return theExpr.getp(); } |
2111 | @@ -124,8 +128,9 @@ |
2112 | /***************************************************************************//** |
2113 | |
2114 | ********************************************************************************/ |
2115 | -class validate_expr : public expr |
2116 | +class validate_expr : public expr |
2117 | { |
2118 | + friend class ExprManager; |
2119 | friend class ExprIterator; |
2120 | friend class expr; |
2121 | |
2122 | @@ -135,8 +140,9 @@ |
2123 | rchandle<TypeManager> theTypeMgr; |
2124 | expr_t theExpr; |
2125 | |
2126 | -public: |
2127 | +protected: |
2128 | validate_expr( |
2129 | + CompilerCB* ccb, |
2130 | static_context* sctx, |
2131 | const QueryLoc&, |
2132 | ParseConstants::validation_mode_t, |
2133 | @@ -144,6 +150,7 @@ |
2134 | expr_t, |
2135 | rchandle<TypeManager>); |
2136 | |
2137 | +public: |
2138 | expr* get_expr() const { return theExpr.getp(); } |
2139 | |
2140 | const store::Item* get_type_name() const { return theTypeName; } |
2141 | @@ -174,6 +181,7 @@ |
2142 | |
2143 | protected: |
2144 | namespace_context_base_expr( |
2145 | + CompilerCB* ccb, |
2146 | static_context* sctx, |
2147 | const QueryLoc& loc, |
2148 | expr_kind_t kind, |
2149 | @@ -187,7 +195,7 @@ |
2150 | /***************************************************************************//** |
2151 | Base for cast, treat, promote, castable, instanceof |
2152 | ********************************************************************************/ |
2153 | -class cast_or_castable_base_expr : public expr |
2154 | +class cast_or_castable_base_expr : public expr |
2155 | { |
2156 | friend class ExprIterator; |
2157 | friend class expr; |
2158 | @@ -198,12 +206,13 @@ |
2159 | |
2160 | protected: |
2161 | cast_or_castable_base_expr( |
2162 | + CompilerCB* ccb, |
2163 | static_context* sctx, |
2164 | const QueryLoc& loc, |
2165 | expr_kind_t kind, |
2166 | const expr_t& input, |
2167 | const xqtref_t& type); |
2168 | - |
2169 | + |
2170 | public: |
2171 | expr* get_input() const { return theInputExpr.getp(); } |
2172 | |
2173 | @@ -222,13 +231,14 @@ |
2174 | { |
2175 | friend class ExprIterator; |
2176 | |
2177 | -public: |
2178 | +protected: |
2179 | cast_base_expr( |
2180 | - static_context* sctx, |
2181 | - const QueryLoc& loc, |
2182 | - expr_kind_t kind, |
2183 | - const expr_t& input, |
2184 | - const xqtref_t& type); |
2185 | + CompilerCB* ccb, |
2186 | + static_context* sctx, |
2187 | + const QueryLoc& loc, |
2188 | + expr_kind_t kind, |
2189 | + const expr_t& input, |
2190 | + const xqtref_t& type); |
2191 | }; |
2192 | |
2193 | |
2194 | @@ -239,12 +249,19 @@ |
2195 | ********************************************************************************/ |
2196 | class cast_expr : public cast_base_expr |
2197 | { |
2198 | + friend class ExprManager; |
2199 | friend class ExprIterator; |
2200 | friend class expr; |
2201 | |
2202 | +protected: |
2203 | + cast_expr( |
2204 | + CompilerCB* ccb, |
2205 | + static_context* sctx, |
2206 | + const QueryLoc&, |
2207 | + const expr_t&, |
2208 | + const xqtref_t&); |
2209 | + |
2210 | public: |
2211 | - cast_expr(static_context* sctx, const QueryLoc&, const expr_t&, const xqtref_t&); |
2212 | - |
2213 | bool is_optional() const; |
2214 | |
2215 | expr_t clone(substitution_t& s) const; |
2216 | @@ -256,7 +273,7 @@ |
2217 | |
2218 | |
2219 | /***************************************************************************//** |
2220 | - TreatExpr ::= CastableExpr ( "treat" "as" SequenceType )? |
2221 | + TreatExpr ::= CastableExpr ( "treat" "as" SequenceType )? |
2222 | |
2223 | theCheckPrime : Normally, this is true. If false, then during runtime, only |
2224 | the cardinality of theInputExpr will be checked w.r.t. the |
2225 | @@ -265,11 +282,12 @@ |
2226 | static type of theInputExpr is a subtype of the prime type of |
2227 | theTargetType. |
2228 | |
2229 | - theFnQName : Stores the QName of the function, if the treat expr is used |
2230 | + theFnQName : Stores the QName of the function, if the treat expr is used |
2231 | to cast the function's body to its result type |
2232 | ********************************************************************************/ |
2233 | -class treat_expr : public cast_base_expr |
2234 | +class treat_expr : public cast_base_expr |
2235 | { |
2236 | + friend class ExprManager; |
2237 | friend class ExprIterator; |
2238 | friend class expr; |
2239 | |
2240 | @@ -278,16 +296,18 @@ |
2241 | bool theCheckPrime; |
2242 | store::Item_t theQName; |
2243 | |
2244 | -public: |
2245 | +protected: |
2246 | treat_expr( |
2247 | - static_context* sctx, |
2248 | - const QueryLoc& loc, |
2249 | - const expr_t& input, |
2250 | - const xqtref_t& type, |
2251 | + CompilerCB* ccb, |
2252 | + static_context* sctx, |
2253 | + const QueryLoc&, |
2254 | + const expr_t&, |
2255 | + const xqtref_t&, |
2256 | TreatIterator::ErrorKind err, |
2257 | bool check_prime = true, |
2258 | store::Item* qname = NULL); |
2259 | |
2260 | +public: |
2261 | TreatIterator::ErrorKind get_err() const { return theErrorKind; } |
2262 | |
2263 | bool get_check_prime() const { return theCheckPrime; } |
2264 | @@ -323,7 +343,7 @@ |
2265 | - If the target type is the NONE type, F(I) = error, else |
2266 | - If the actual type is a subtype of the target type, F(I) = I, else |
2267 | - If the target type is not an atomic type, F(I) = error, else |
2268 | - - If the actual type is untypedAtomic and the target type is not QName, |
2269 | + - If the actual type is untypedAtomic and the target type is not QName, |
2270 | F(I) = cast(I, target type), else |
2271 | - If the actual type is (subtype of) decimal and the target type is float, |
2272 | F(I) = cast(I, target type), else |
2273 | @@ -339,26 +359,29 @@ |
2274 | ----------- |
2275 | Stores the QName of the function, if the promote expr is used to cast the |
2276 | function's body to its result type |
2277 | - |
2278 | + |
2279 | ********************************************************************************/ |
2280 | class promote_expr : public cast_base_expr |
2281 | { |
2282 | + friend class ExprManager; |
2283 | friend class ExprIterator; |
2284 | friend class expr; |
2285 | |
2286 | protected: |
2287 | PromoteIterator::ErrorKind theErrorKind; |
2288 | - store::Item_t theQName; |
2289 | - |
2290 | -public: |
2291 | + store::Item_t theQName; |
2292 | + |
2293 | +protected: |
2294 | promote_expr( |
2295 | - static_context* sctx, |
2296 | - const QueryLoc& loc, |
2297 | - const expr_t& input, |
2298 | - const xqtref_t& type, |
2299 | + CompilerCB* ccb, |
2300 | + static_context* sctx, |
2301 | + const QueryLoc& loc, |
2302 | + const expr_t& input, |
2303 | + const xqtref_t& type, |
2304 | PromoteIterator::ErrorKind err, |
2305 | store::Item* qname); |
2306 | |
2307 | +public: |
2308 | expr_t clone(substitution_t& s) const; |
2309 | |
2310 | PromoteIterator::ErrorKind get_err() const { return theErrorKind; } |
2311 | @@ -376,12 +399,13 @@ |
2312 | /***************************************************************************//** |
2313 | Base for castable, instanceof |
2314 | ********************************************************************************/ |
2315 | -class castable_base_expr : public cast_or_castable_base_expr |
2316 | +class castable_base_expr : public cast_or_castable_base_expr |
2317 | { |
2318 | friend class ExprIterator; |
2319 | |
2320 | -public: |
2321 | +protected: |
2322 | castable_base_expr( |
2323 | + CompilerCB* ccb, |
2324 | static_context* sctx, |
2325 | const QueryLoc&, |
2326 | expr_kind_t kind, |
2327 | @@ -395,14 +419,21 @@ |
2328 | |
2329 | SingleType ::= AtomicType "?"? |
2330 | ********************************************************************************/ |
2331 | -class castable_expr : public castable_base_expr |
2332 | +class castable_expr : public castable_base_expr |
2333 | { |
2334 | + friend class ExprManager; |
2335 | friend class ExprIterator; |
2336 | friend class expr; |
2337 | |
2338 | +protected: |
2339 | + castable_expr( |
2340 | + CompilerCB* ccb, |
2341 | + static_context* sctx, |
2342 | + const QueryLoc&, |
2343 | + const expr_t&, |
2344 | + const xqtref_t&); |
2345 | + |
2346 | public: |
2347 | - castable_expr(static_context* sctx, const QueryLoc&, const expr_t&, const xqtref_t&); |
2348 | - |
2349 | bool is_optional() const; |
2350 | |
2351 | expr_t clone(substitution_t& s) const; |
2352 | @@ -414,30 +445,33 @@ |
2353 | |
2354 | |
2355 | /***************************************************************************//** |
2356 | - InstanceofExpr ::= TreatExpr ( "instance" "of" SequenceType )? |
2357 | + InstanceofExpr ::= TreatExpr ( "instance" "of" SequenceType )? |
2358 | |
2359 | - theCheckPrimeOnly : |
2360 | + theCheckPrimeOnly : |
2361 | Normally, this is false. It is set to true only if this is an instanceof expr |
2362 | that is created during the translation of a PredicateList (see translator.cpp). |
2363 | This flag is used during the PartialEval rule. |
2364 | |
2365 | ********************************************************************************/ |
2366 | -class instanceof_expr : public castable_base_expr |
2367 | +class instanceof_expr : public castable_base_expr |
2368 | { |
2369 | + friend class ExprManager; |
2370 | friend class ExprIterator; |
2371 | friend class expr; |
2372 | |
2373 | protected: |
2374 | bool theCheckPrimeOnly; |
2375 | |
2376 | -public: |
2377 | +protected: |
2378 | instanceof_expr( |
2379 | + CompilerCB* ccb, |
2380 | static_context* sctx, |
2381 | - const QueryLoc&, |
2382 | - const expr_t&, |
2383 | + const QueryLoc&, |
2384 | + const expr_t&, |
2385 | const xqtref_t&, |
2386 | bool checkPrimeOnly = false); |
2387 | |
2388 | +public: |
2389 | bool getCheckPrimeOnly() const { return theCheckPrimeOnly; } |
2390 | |
2391 | expr_t clone(substitution_t& s) const; |
2392 | @@ -460,6 +494,7 @@ |
2393 | ********************************************************************************/ |
2394 | class name_cast_expr : public namespace_context_base_expr |
2395 | { |
2396 | + friend class ExprManager; |
2397 | friend class ExprIterator; |
2398 | friend class expr; |
2399 | |
2400 | @@ -467,14 +502,16 @@ |
2401 | expr_t theInputExpr; |
2402 | bool theIsAttrName; |
2403 | |
2404 | -public: |
2405 | +protected: |
2406 | name_cast_expr( |
2407 | + CompilerCB* ccb, |
2408 | static_context* sctx, |
2409 | const QueryLoc&, |
2410 | expr_t, |
2411 | const namespace_context*, |
2412 | bool isAttr); |
2413 | |
2414 | +public: |
2415 | expr* get_input() const { return theInputExpr.getp(); } |
2416 | |
2417 | bool is_attr_name() const { return theIsAttrName; } |
2418 | @@ -492,8 +529,9 @@ |
2419 | /***************************************************************************//** |
2420 | CompDocConstructor ::= "document" "{" Expr "}" |
2421 | ********************************************************************************/ |
2422 | -class doc_expr : public expr |
2423 | +class doc_expr : public expr |
2424 | { |
2425 | + friend class ExprManager; |
2426 | friend class ExprIterator; |
2427 | friend class expr; |
2428 | |
2429 | @@ -501,9 +539,10 @@ |
2430 | expr_t theContent; |
2431 | bool theCopyInputNodes; |
2432 | |
2433 | +protected: |
2434 | + doc_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc&, expr* content, bool copyNodes); |
2435 | + |
2436 | public: |
2437 | - doc_expr(static_context* sctx, const QueryLoc&, expr* content, bool copyNodes); |
2438 | - |
2439 | expr* getContent() const { return theContent.getp(); } |
2440 | |
2441 | bool copyInputNodes() const { return theCopyInputNodes; } |
2442 | @@ -548,6 +587,7 @@ |
2443 | ********************************************************************************/ |
2444 | class elem_expr : public namespace_context_base_expr |
2445 | { |
2446 | + friend class ExprManager; |
2447 | friend class ExprIterator; |
2448 | friend class expr; |
2449 | |
2450 | @@ -557,8 +597,9 @@ |
2451 | expr_t theContent; |
2452 | bool theCopyInputNodes; |
2453 | |
2454 | -public: |
2455 | +protected: |
2456 | elem_expr( |
2457 | + CompilerCB* ccb, |
2458 | static_context* sctx, |
2459 | const QueryLoc&, |
2460 | expr* qnameExpr, |
2461 | @@ -566,15 +607,17 @@ |
2462 | expr* content, |
2463 | const namespace_context* nsCtx, |
2464 | bool copyNodes); |
2465 | - |
2466 | + |
2467 | elem_expr( |
2468 | + CompilerCB* ccb, |
2469 | static_context* sctx, |
2470 | const QueryLoc&, |
2471 | expr* qnameExpr, |
2472 | expr* content, |
2473 | const namespace_context* nsCtx, |
2474 | bool copyNodes); |
2475 | - |
2476 | + |
2477 | +public: |
2478 | expr* getQNameExpr() const { return theQNameExpr.getp(); } |
2479 | |
2480 | expr* getContent() const { return theContent.getp(); } |
2481 | @@ -586,8 +629,8 @@ |
2482 | void setCopyInputNodes() { theCopyInputNodes = true; } |
2483 | |
2484 | void compute_scripting_kind(); |
2485 | - |
2486 | - expr_t clone(substitution_t& s) const; |
2487 | + |
2488 | + expr_t clone(substitution_t& s) const; |
2489 | |
2490 | void accept(expr_visitor&); |
2491 | |
2492 | @@ -619,8 +662,9 @@ |
2493 | CommonContent ::= PredefinedEntityRef | CharRef | "{{" | "}}" | EnclosedExpr |
2494 | |
2495 | ********************************************************************************/ |
2496 | -class attr_expr : public expr |
2497 | +class attr_expr : public expr |
2498 | { |
2499 | + friend class ExprManager; |
2500 | friend class ExprIterator; |
2501 | friend class expr; |
2502 | |
2503 | @@ -628,13 +672,15 @@ |
2504 | expr_t theQNameExpr; |
2505 | expr_t theValueExpr; |
2506 | |
2507 | -public: |
2508 | +protected: |
2509 | attr_expr( |
2510 | + CompilerCB* ccb, |
2511 | static_context* sctx, |
2512 | const QueryLoc& loc, |
2513 | expr_t aQNameExpr, |
2514 | expr_t aValueExpr); |
2515 | |
2516 | +public: |
2517 | expr* getQNameExpr() const { return theQNameExpr.getp(); } |
2518 | |
2519 | expr* getValueExpr() const { return theValueExpr.getp(); } |
2520 | @@ -654,13 +700,14 @@ |
2521 | /***************************************************************************//** |
2522 | |
2523 | ********************************************************************************/ |
2524 | -class text_expr : public expr |
2525 | +class text_expr : public expr |
2526 | { |
2527 | + friend class ExprManager; |
2528 | friend class ExprIterator; |
2529 | friend class expr; |
2530 | |
2531 | public: |
2532 | - typedef enum |
2533 | + typedef enum |
2534 | { |
2535 | text_constructor, |
2536 | comment_constructor |
2537 | @@ -670,20 +717,22 @@ |
2538 | text_constructor_type type; |
2539 | expr_t theContentExpr; |
2540 | |
2541 | -public: |
2542 | +protected: |
2543 | text_expr( |
2544 | + CompilerCB* ccb, |
2545 | static_context* sctx, |
2546 | const QueryLoc&, |
2547 | text_constructor_type, |
2548 | expr_t); |
2549 | |
2550 | +public: |
2551 | expr* get_text() const { return theContentExpr.getp(); } |
2552 | |
2553 | text_constructor_type get_type() const { return type; } |
2554 | |
2555 | void compute_scripting_kind(); |
2556 | |
2557 | - expr_t clone(substitution_t& s) const; |
2558 | + expr_t clone(substitution_t& s) const; |
2559 | |
2560 | void accept(expr_visitor&); |
2561 | |
2562 | @@ -694,8 +743,9 @@ |
2563 | /***************************************************************************//** |
2564 | |
2565 | ********************************************************************************/ |
2566 | -class pi_expr : public expr |
2567 | +class pi_expr : public expr |
2568 | { |
2569 | + friend class ExprManager; |
2570 | friend class ExprIterator; |
2571 | friend class expr; |
2572 | |
2573 | @@ -703,16 +753,17 @@ |
2574 | expr_t theTargetExpr; |
2575 | expr_t theContentExpr; |
2576 | |
2577 | +protected: |
2578 | + pi_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc&, expr_t, expr_t); |
2579 | + |
2580 | public: |
2581 | - pi_expr(static_context* sctx, const QueryLoc&, expr_t, expr_t); |
2582 | - |
2583 | expr* get_target_expr() const { return theTargetExpr.getp(); } |
2584 | |
2585 | expr* get_content_expr() const { return theContentExpr.getp(); } |
2586 | |
2587 | void compute_scripting_kind(); |
2588 | - |
2589 | - expr_t clone(substitution_t& s) const; |
2590 | + |
2591 | + expr_t clone(substitution_t& s) const; |
2592 | |
2593 | void accept(expr_visitor&); |
2594 | |
2595 | @@ -723,33 +774,35 @@ |
2596 | /***************************************************************************//** |
2597 | |
2598 | ********************************************************************************/ |
2599 | -class const_expr : public expr |
2600 | +class const_expr : public expr |
2601 | { |
2602 | + friend class ExprManager; |
2603 | friend class ExprIterator; |
2604 | friend class expr; |
2605 | |
2606 | protected: |
2607 | store::Item_t theValue; |
2608 | |
2609 | +protected: |
2610 | + const_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc&, zstring& sval); |
2611 | + |
2612 | + const_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc&, const std::string& sval); |
2613 | + |
2614 | + const_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc&, const char* sval); |
2615 | + |
2616 | + const_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc&, xs_integer); |
2617 | + |
2618 | + const_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc&, xs_decimal); |
2619 | + |
2620 | + const_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc&, xs_double); |
2621 | + |
2622 | + const_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc&, xs_boolean); |
2623 | + |
2624 | + const_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc&, store::Item_t); |
2625 | + |
2626 | + const_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc&, const char* ns, const char* pre, const char* local); |
2627 | + |
2628 | public: |
2629 | - const_expr(static_context* sctx, const QueryLoc&, zstring& sval); |
2630 | - |
2631 | - const_expr(static_context* sctx, const QueryLoc&, const std::string& sval); |
2632 | - |
2633 | - const_expr(static_context* sctx, const QueryLoc&, const char* sval); |
2634 | - |
2635 | - const_expr(static_context* sctx, const QueryLoc&, xs_integer); |
2636 | - |
2637 | - const_expr(static_context* sctx, const QueryLoc&, xs_decimal); |
2638 | - |
2639 | - const_expr(static_context* sctx, const QueryLoc&, xs_double); |
2640 | - |
2641 | - const_expr(static_context* sctx, const QueryLoc&, xs_boolean); |
2642 | - |
2643 | - const_expr(static_context* sctx, const QueryLoc&, store::Item_t); |
2644 | - |
2645 | - const_expr(static_context* sctx, const QueryLoc&, const char* ns, const char* pre, const char* local); |
2646 | - |
2647 | store::Item* get_val() const { return theValue.getp(); } |
2648 | |
2649 | void compute_scripting_kind(); |
2650 | @@ -781,8 +834,9 @@ |
2651 | /***************************************************************************//** |
2652 | |
2653 | ********************************************************************************/ |
2654 | -class extension_expr : public expr |
2655 | +class extension_expr : public expr |
2656 | { |
2657 | + friend class ExprManager; |
2658 | friend class ExprIterator; |
2659 | friend class expr; |
2660 | |
2661 | @@ -790,11 +844,12 @@ |
2662 | std::vector<rchandle<pragma> > thePragmas; |
2663 | expr_t theExpr; |
2664 | |
2665 | +protected: |
2666 | + extension_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc&); |
2667 | + |
2668 | + extension_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc&, expr_t); |
2669 | + |
2670 | public: |
2671 | - extension_expr(static_context* sctx, const QueryLoc&); |
2672 | - |
2673 | - extension_expr(static_context* sctx, const QueryLoc&, expr_t); |
2674 | - |
2675 | void add(rchandle<pragma> p) { thePragmas.push_back(p); } |
2676 | |
2677 | expr* get_expr() const { return theExpr.getp(); } |
2678 | @@ -811,7 +866,7 @@ |
2679 | |
2680 | ///////////////////////////////////////////////////////////////////////// |
2681 | // // |
2682 | -// XQuery 3.0 expressions // |
2683 | +// XQuery 3.0 expressions // |
2684 | // [http://www.w3.org/TR/xquery-3/] // |
2685 | // // |
2686 | ///////////////////////////////////////////////////////////////////////// |
2687 | @@ -836,7 +891,7 @@ |
2688 | typedef rchandle<catch_clause> catch_clause_t; |
2689 | |
2690 | |
2691 | -class catch_clause : public SimpleRCObject |
2692 | +class catch_clause : public SimpleRCObject |
2693 | { |
2694 | friend class expr; |
2695 | friend class trycatch_expr; |
2696 | @@ -861,28 +916,30 @@ |
2697 | protected: |
2698 | nt_list_t theNameTests; |
2699 | var_map_t theVarMap; |
2700 | - |
2701 | + |
2702 | public: |
2703 | catch_clause(); |
2704 | - |
2705 | + |
2706 | +public: |
2707 | void set_nametests(nt_list_t& a) { theNameTests = a; } |
2708 | |
2709 | nt_list_t& get_nametests() { return theNameTests; } |
2710 | - |
2711 | + |
2712 | void add_nametest_h(nt_t n) { theNameTests.push_back(n); } |
2713 | |
2714 | void set_vars(var_map_t& a) { theVarMap = a; } |
2715 | |
2716 | var_map_t& get_vars() { return theVarMap; } |
2717 | - |
2718 | + |
2719 | void add_var(var_type v, var_expr_t n) { theVarMap[v] = n; } |
2720 | - |
2721 | + |
2722 | catch_clause_t clone(expr::substitution_t& subst) const; |
2723 | }; |
2724 | |
2725 | |
2726 | -class trycatch_expr : public expr |
2727 | +class trycatch_expr : public expr |
2728 | { |
2729 | + friend class ExprManager; |
2730 | friend class ExprIterator; |
2731 | friend class expr; |
2732 | |
2733 | @@ -891,9 +948,10 @@ |
2734 | std::vector<expr_t> theCatchExprs; |
2735 | std::vector<catch_clause_t> theCatchClauses; |
2736 | |
2737 | +protected: |
2738 | + trycatch_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc&, expr_t tryExpr); |
2739 | + |
2740 | public: |
2741 | - trycatch_expr(static_context* sctx, const QueryLoc&, expr_t tryExpr); |
2742 | - |
2743 | expr* get_try_expr() const { return theTryExpr.getp(); } |
2744 | |
2745 | void set_try_expr(expr* e) { theTryExpr = e; } |
2746 | @@ -903,9 +961,9 @@ |
2747 | void add_catch_expr(expr_t e); |
2748 | |
2749 | void add_clause(catch_clause_t cc); |
2750 | - |
2751 | + |
2752 | csize clause_count() const { return theCatchClauses.size(); } |
2753 | - |
2754 | + |
2755 | const catch_clause_t& operator[](csize i) const { return theCatchClauses[i]; } |
2756 | |
2757 | void compute_scripting_kind(); |
2758 | @@ -920,7 +978,7 @@ |
2759 | |
2760 | ///////////////////////////////////////////////////////////////////////// |
2761 | // // |
2762 | -// Zorba expressions // |
2763 | +// Zorba expressions // |
2764 | // // |
2765 | ///////////////////////////////////////////////////////////////////////// |
2766 | |
2767 | @@ -929,17 +987,19 @@ |
2768 | Normally, it is used to wrap a var_expr in order to represent a var reference |
2769 | (see var_expr.h). But it may wrap any other kind of expr as well. |
2770 | ********************************************************************************/ |
2771 | -class wrapper_expr : public expr |
2772 | +class wrapper_expr : public expr |
2773 | { |
2774 | friend class ExprIterator; |
2775 | friend class expr; |
2776 | + friend class ExprManager; |
2777 | |
2778 | protected: |
2779 | expr_t theWrappedExpr; |
2780 | |
2781 | +protected: |
2782 | + wrapper_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc& loc, expr_t wrapped); |
2783 | + |
2784 | public: |
2785 | - wrapper_expr(static_context* sctx, const QueryLoc& loc, expr_t wrapped); |
2786 | - |
2787 | expr* get_expr() const { return theWrappedExpr.getp(); } |
2788 | |
2789 | void set_expr(const expr* e) { theWrappedExpr = e; } |
2790 | @@ -961,6 +1021,7 @@ |
2791 | { |
2792 | friend class ExprIterator; |
2793 | friend class expr; |
2794 | + friend class ExprManager; |
2795 | |
2796 | protected: |
2797 | expr_t theExpr; |
2798 | @@ -969,14 +1030,16 @@ |
2799 | QueryLoc theFunctionCallLocation; |
2800 | unsigned int theFunctionArity; |
2801 | |
2802 | -public: |
2803 | +protected: |
2804 | function_trace_expr( |
2805 | + CompilerCB* ccb, |
2806 | static_context* sctx, |
2807 | const QueryLoc& loc, |
2808 | expr_t aChild); |
2809 | |
2810 | function_trace_expr(expr_t aExpr); |
2811 | |
2812 | +public: |
2813 | virtual ~function_trace_expr(); |
2814 | |
2815 | void compute_scripting_kind(); |
2816 | @@ -1018,7 +1081,7 @@ |
2817 | { |
2818 | return theFunctionCallLocation; |
2819 | } |
2820 | - |
2821 | + |
2822 | void setFunctionArity(unsigned int arity) |
2823 | { |
2824 | theFunctionArity = arity; |
2825 | @@ -1041,8 +1104,8 @@ |
2826 | |
2827 | theVars: |
2828 | -------- |
2829 | - There is one "eval" var for each non-global var that is in scope where the call |
2830 | - to the eval function appears at. |
2831 | + There is one "eval" var (of kind var_expr::eval_var) for each var that is in |
2832 | + scope where the call to the eval function appears at. |
2833 | |
2834 | theArgs: |
2835 | -------- |
2836 | @@ -1061,6 +1124,7 @@ |
2837 | { |
2838 | friend class ExprIterator; |
2839 | friend class expr; |
2840 | + friend class ExprManager; |
2841 | |
2842 | protected: |
2843 | expr_t theExpr; |
2844 | @@ -1071,15 +1135,17 @@ |
2845 | expr_script_kind_t theInnerScriptingKind; |
2846 | bool theDoNodeCopy; |
2847 | |
2848 | -public: |
2849 | +protected: |
2850 | eval_expr( |
2851 | + CompilerCB* creating_ccb, |
2852 | CompilerCB* ccb, |
2853 | static_context* sctx, |
2854 | - const QueryLoc& loc, |
2855 | + const QueryLoc& loc, |
2856 | const expr_t& e, |
2857 | expr_script_kind_t scriptingKind, |
2858 | namespace_context* nsCtx); |
2859 | |
2860 | +public: |
2861 | expr* get_expr() const { return theExpr.getp(); } |
2862 | |
2863 | expr* get_arg_expr(csize i) { return theArgs[i].getp(); } |
2864 | @@ -1088,7 +1154,7 @@ |
2865 | |
2866 | const var_expr* get_var(csize i) const { return theVars[i]; } |
2867 | |
2868 | - void add_var(const var_expr_t& var, const expr_t& arg) |
2869 | + void add_var(const var_expr_t& var, const expr_t& arg) |
2870 | { |
2871 | theVars.push_back(var); |
2872 | theArgs.push_back(arg); |
2873 | @@ -1131,6 +1197,7 @@ |
2874 | { |
2875 | friend class ExprIterator; |
2876 | friend class expr; |
2877 | + friend class ExprManager; |
2878 | |
2879 | private: |
2880 | expr_t theExpr; |
2881 | @@ -1138,14 +1205,16 @@ |
2882 | std::vector<expr_t> theArgs; |
2883 | bool theIsVarDeclaration; |
2884 | |
2885 | -public: |
2886 | +protected: |
2887 | debugger_expr( |
2888 | + CompilerCB* ccb, |
2889 | static_context* sctx, |
2890 | const QueryLoc& loc, |
2891 | const expr_t& aChild, |
2892 | namespace_context* nsCtx, |
2893 | bool aIsVarDeclaration); |
2894 | |
2895 | +public: |
2896 | expr* get_expr() const { return theExpr.getp(); } |
2897 | |
2898 | bool isVarDeclaration() const { return theIsVarDeclaration; } |
2899 | @@ -1158,7 +1227,7 @@ |
2900 | |
2901 | const var_expr* get_var(csize i) const { return theVars[i]; } |
2902 | |
2903 | - void add_var(const var_expr_t& var, const expr_t& arg) |
2904 | + void add_var(const var_expr_t& var, const expr_t& arg) |
2905 | { |
2906 | theVars.push_back(var); |
2907 | theArgs.push_back(arg); |
2908 | |
2909 | === modified file 'src/compiler/expression/expr_base.cpp' |
2910 | --- src/compiler/expression/expr_base.cpp 2012-07-24 08:48:48 +0000 |
2911 | +++ src/compiler/expression/expr_base.cpp 2012-08-10 11:20:27 +0000 |
2912 | @@ -23,6 +23,9 @@ |
2913 | #include "compiler/expression/path_expr.h" |
2914 | #include "compiler/expression/expr_iter.h" |
2915 | #include "compiler/expression/expr_visitor.h" |
2916 | +#include "compiler/expression/expr_manager.h" |
2917 | + |
2918 | +#include "compiler/api/compilercb.h" |
2919 | |
2920 | #include "functions/function.h" |
2921 | #include "functions/library.h" |
2922 | @@ -85,7 +88,7 @@ |
2923 | return (theScriptingKind & (VAR_SETTING_EXPR | |
2924 | APPLYING_EXPR | |
2925 | EXITING_EXPR | |
2926 | - BREAKING_EXPR | |
2927 | + BREAKING_EXPR | |
2928 | SEQUENTIAL_FUNC_EXPR)) != 0; |
2929 | } |
2930 | |
2931 | @@ -94,7 +97,7 @@ |
2932 | { |
2933 | if (e != 0 && e->is_updating()) |
2934 | { |
2935 | - throw XQUERY_EXCEPTION(err::XUST0001, |
2936 | + throw XQUERY_EXCEPTION(err::XUST0001, |
2937 | ERROR_PARAMS(ZED(XUST0001_Generic)), |
2938 | ERROR_LOC(e->get_loc())); |
2939 | } |
2940 | @@ -105,7 +108,7 @@ |
2941 | { |
2942 | if (e != 0 && e->is_updating()) |
2943 | { |
2944 | - throw XQUERY_EXCEPTION(err::XUST0001, |
2945 | + throw XQUERY_EXCEPTION(err::XUST0001, |
2946 | ERROR_PARAMS(ZED(XUST0001_Generic)), |
2947 | ERROR_LOC(e->get_loc())); |
2948 | } |
2949 | @@ -120,12 +123,13 @@ |
2950 | /******************************************************************************* |
2951 | |
2952 | ********************************************************************************/ |
2953 | -expr::expr(static_context* sctx, const QueryLoc& loc, expr_kind_t k) |
2954 | +expr::expr(CompilerCB* ccb, static_context* sctx, const QueryLoc& loc, expr_kind_t k) |
2955 | : |
2956 | theSctx(sctx), |
2957 | theLoc(loc), |
2958 | theKind(k), |
2959 | - theFlags1(0) |
2960 | + theFlags1(0), |
2961 | + theCCB(ccb) |
2962 | { |
2963 | theScriptingKind = UNKNOWN_SCRIPTING_KIND; |
2964 | |
2965 | @@ -146,9 +150,9 @@ |
2966 | /******************************************************************************* |
2967 | |
2968 | ********************************************************************************/ |
2969 | -TypeManager* expr::get_type_manager() const |
2970 | +TypeManager* expr::get_type_manager() const |
2971 | { |
2972 | - return theSctx->get_typemanager(); |
2973 | + return theSctx->get_typemanager(); |
2974 | } |
2975 | |
2976 | |
2977 | @@ -541,11 +545,11 @@ |
2978 | |
2979 | |
2980 | /******************************************************************************* |
2981 | - This annotation tells whether the expr must produce nodes that belong to |
2982 | - "standalone" trees or not. A tree is standalone if it does not contain |
2983 | - references to other trees. Such references are created when the optimizer |
2984 | + This annotation tells whether the expr must produce nodes that belong to |
2985 | + "standalone" trees or not. A tree is standalone if it does not contain |
2986 | + references to other trees. Such references are created when the optimizer |
2987 | decides that it is ok to avoid copying the referenced subtree (as would be |
2988 | - required by required by a strict implementation of the spec, eg., during |
2989 | + required by required by a strict implementation of the spec, eg., during |
2990 | node construction). |
2991 | ********************************************************************************/ |
2992 | BoolAnnotationValue expr::getMustCopyNodes() const |
2993 | @@ -791,13 +795,13 @@ |
2994 | if (found) |
2995 | return true; |
2996 | |
2997 | - if (this == e) |
2998 | + if (this == e) |
2999 | { |
3000 | found = true; |
3001 | return true; |
3002 | } |
3003 | |
3004 | - switch(get_expr_kind()) |
3005 | + switch(get_expr_kind()) |
3006 | { |
3007 | #ifdef ZORBA_WITH_DEBUGGER |
3008 | case debugger_expr_kind: |
3009 | @@ -829,13 +833,13 @@ |
3010 | const function* func = foExpr->get_func(); |
3011 | csize numArgs = foExpr->num_args(); |
3012 | |
3013 | - for (csize i = 0; i < numArgs; ++i) |
3014 | + for (csize i = 0; i < numArgs; ++i) |
3015 | { |
3016 | const expr* argExpr = foExpr->get_arg(i); |
3017 | |
3018 | - if (func->isMap(i)) |
3019 | + if (func->isMap(i)) |
3020 | { |
3021 | - if (argExpr->is_map_internal(e, found) && found) |
3022 | + if (argExpr->is_map_internal(e, found) && found) |
3023 | { |
3024 | return true; |
3025 | } |
3026 | @@ -1166,7 +1170,7 @@ |
3027 | ********************************************************************************/ |
3028 | xqtref_t expr::get_return_type_with_empty_input(const expr* input) const |
3029 | { |
3030 | - expr_t emptyExpr = new fo_expr(input->get_sctx(), |
3031 | + expr_t emptyExpr = theCCB->theEM->create_fo_expr(input->get_sctx(), |
3032 | QueryLoc::null, |
3033 | GET_BUILTIN_FUNCTION(OP_CONCATENATE_N)); |
3034 | expr::substitution_t subst; |
3035 | |
3036 | === modified file 'src/compiler/expression/expr_base.h' |
3037 | --- src/compiler/expression/expr_base.h 2012-07-24 08:48:48 +0000 |
3038 | +++ src/compiler/expression/expr_base.h 2012-08-10 11:20:27 +0000 |
3039 | @@ -45,6 +45,7 @@ |
3040 | |
3041 | class expr_visitor; |
3042 | |
3043 | +class CompilerCB; |
3044 | |
3045 | enum expr_kind_t |
3046 | { |
3047 | @@ -85,7 +86,7 @@ |
3048 | order_expr_kind, |
3049 | |
3050 | #ifndef ZORBA_NO_FULL_TEXT |
3051 | - ft_expr_kind, |
3052 | + ft_expr_kind, |
3053 | #endif /* ZORBA_NO_FULL_TEXT */ |
3054 | |
3055 | delete_expr_kind, |
3056 | @@ -187,6 +188,8 @@ |
3057 | |
3058 | FreeVars theFreeVars; |
3059 | |
3060 | + CompilerCB * theCCB; |
3061 | + |
3062 | public: |
3063 | static bool is_sequential(unsigned short theScriptingKind); |
3064 | |
3065 | @@ -194,13 +197,18 @@ |
3066 | |
3067 | static void checkNonUpdating(const expr* e); |
3068 | |
3069 | + virtual void free() {} |
3070 | + |
3071 | +protected: |
3072 | + expr(CompilerCB*, static_context*, const QueryLoc&, expr_kind_t); |
3073 | + |
3074 | + expr() : theSctx(NULL), theFlags1(0), theCCB(NULL) {} |
3075 | + |
3076 | public: |
3077 | - expr() : theSctx(NULL), theFlags1(0) {} |
3078 | - |
3079 | - expr(static_context*, const QueryLoc&, expr_kind_t); |
3080 | - |
3081 | virtual ~expr(); |
3082 | |
3083 | + CompilerCB* get_ccb() {return theCCB;} |
3084 | + |
3085 | expr_kind_t get_expr_kind() const { return static_cast<expr_kind_t>(theKind); } |
3086 | |
3087 | const QueryLoc& get_loc() const { return theLoc; } |
3088 | |
3089 | === modified file 'src/compiler/expression/expr_classes.h' |
3090 | --- src/compiler/expression/expr_classes.h 2012-07-24 08:48:48 +0000 |
3091 | +++ src/compiler/expression/expr_classes.h 2012-08-10 11:20:27 +0000 |
3092 | @@ -1,12 +1,12 @@ |
3093 | /* |
3094 | * Copyright 2006-2008 The FLWOR Foundation. |
3095 | - * |
3096 | + * |
3097 | * Licensed under the Apache License, Version 2.0 (the "License"); |
3098 | * you may not use this file except in compliance with the License. |
3099 | * You may obtain a copy of the License at |
3100 | - * |
3101 | + * |
3102 | * http://www.apache.org/licenses/LICENSE-2.0 |
3103 | - * |
3104 | + * |
3105 | * Unless required by applicable law or agreed to in writing, software |
3106 | * distributed under the License is distributed on an "AS IS" BASIS, |
3107 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
3108 | @@ -17,38 +17,38 @@ |
3109 | #include <zorba/config.h> |
3110 | #include "common/shared_types.h" |
3111 | |
3112 | -namespace zorba |
3113 | +namespace zorba |
3114 | { |
3115 | - class order_modifier; |
3116 | - class flwor_expr; |
3117 | - class case_clause; |
3118 | - class if_expr; |
3119 | + class order_modifier; |
3120 | + class flwor_expr; |
3121 | + class case_clause; |
3122 | + class if_expr; |
3123 | class fo_expr; |
3124 | #ifndef ZORBA_NO_FULL_TEXT |
3125 | class ftcontains_expr; |
3126 | #endif /* ZORBA_NO_FULL_TEXT */ |
3127 | class promote_expr; |
3128 | - class instanceof_expr; |
3129 | - class treat_expr; |
3130 | - class castable_expr; |
3131 | - class cast_expr; |
3132 | + class instanceof_expr; |
3133 | + class treat_expr; |
3134 | + class castable_expr; |
3135 | + class cast_expr; |
3136 | class name_cast_expr; |
3137 | - class validate_expr; |
3138 | - class extension_expr; |
3139 | + class validate_expr; |
3140 | + class extension_expr; |
3141 | class relpath_expr; |
3142 | - class axis_step_expr; |
3143 | - class match_expr; |
3144 | + class axis_step_expr; |
3145 | + class match_expr; |
3146 | class const_expr; |
3147 | - class order_expr; |
3148 | + class order_expr; |
3149 | |
3150 | - class elem_expr; |
3151 | + class elem_expr; |
3152 | class doc_expr; |
3153 | class attr_expr; |
3154 | class text_expr; |
3155 | class pi_expr; |
3156 | |
3157 | class trycatch_expr; |
3158 | - class function_item_expr; |
3159 | + class function_item_expr; |
3160 | class dynamic_function_invocation_expr; |
3161 | |
3162 | class insert_expr; |
3163 | @@ -57,16 +57,16 @@ |
3164 | class rename_expr; |
3165 | class transform_expr; |
3166 | |
3167 | - class block_expr; |
3168 | + class block_expr; |
3169 | class apply_expr; |
3170 | class var_decl_expr; |
3171 | class var_set_expr; |
3172 | class exit_expr; |
3173 | - class exit_catcher_expr; |
3174 | - class while_expr; |
3175 | + class exit_catcher_expr; |
3176 | + class while_expr; |
3177 | class flowctl_expr; |
3178 | |
3179 | - class eval_expr; |
3180 | + class eval_expr; |
3181 | class debugger_expr; |
3182 | class function_trace_expr; |
3183 | class wrapper_expr; |
3184 | |
3185 | === modified file 'src/compiler/expression/expr_consts.h' |
3186 | --- src/compiler/expression/expr_consts.h 2012-07-24 08:48:48 +0000 |
3187 | +++ src/compiler/expression/expr_consts.h 2012-08-10 11:20:27 +0000 |
3188 | @@ -1,12 +1,12 @@ |
3189 | /* |
3190 | * Copyright 2006-2008 The FLWOR Foundation. |
3191 | - * |
3192 | + * |
3193 | * Licensed under the Apache License, Version 2.0 (the "License"); |
3194 | * you may not use this file except in compliance with the License. |
3195 | * You may obtain a copy of the License at |
3196 | - * |
3197 | + * |
3198 | * http://www.apache.org/licenses/LICENSE-2.0 |
3199 | - * |
3200 | + * |
3201 | * Unless required by applicable law or agreed to in writing, software |
3202 | * distributed under the License is distributed on an "AS IS" BASIS, |
3203 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
3204 | @@ -17,7 +17,7 @@ |
3205 | #ifndef ZORBA_COMPILER_EXPR_CONSTS_H |
3206 | #define ZORBA_COMPILER_EXPR_CONSTS_H |
3207 | |
3208 | -namespace zorba |
3209 | +namespace zorba |
3210 | { |
3211 | |
3212 | |
3213 | @@ -77,16 +77,16 @@ |
3214 | // expr may return non-empty XDM as well. |
3215 | |
3216 | VAR_SETTING_EXPR = 8, // An expr E during the evaluation of which a |
3217 | - // var may be set and that var is declared |
3218 | + // var may be set and that var is declared |
3219 | // outside the innermost block that contains E. |
3220 | |
3221 | - APPLYING_EXPR = 16, // An expr during the evaluation of which a |
3222 | + APPLYING_EXPR = 16, // An expr during the evaluation of which a |
3223 | // PUL may get applied. |
3224 | |
3225 | EXITING_EXPR = 32, // An expr during the evaluation of which an |
3226 | // exit expression may be executed. |
3227 | |
3228 | - BREAKING_EXPR = 64, // An expr E during the evaluation of which |
3229 | + BREAKING_EXPR = 64, // An expr E during the evaluation of which |
3230 | // a break or continue expr may be executed |
3231 | // and the the while or flwor expr being |
3232 | // broken or continued contains E. |
3233 | @@ -105,7 +105,7 @@ |
3234 | }; |
3235 | |
3236 | |
3237 | -class CompareConsts |
3238 | +class CompareConsts |
3239 | { |
3240 | public: |
3241 | enum CompareType |
3242 | @@ -121,7 +121,7 @@ |
3243 | }; |
3244 | |
3245 | |
3246 | -class ArithmeticConsts |
3247 | +class ArithmeticConsts |
3248 | { |
3249 | public: |
3250 | enum OperationKind |
3251 | |
3252 | === added file 'src/compiler/expression/expr_manager.cpp' |
3253 | --- src/compiler/expression/expr_manager.cpp 1970-01-01 00:00:00 +0000 |
3254 | +++ src/compiler/expression/expr_manager.cpp 2012-08-10 11:20:27 +0000 |
3255 | @@ -0,0 +1,884 @@ |
3256 | +/* |
3257 | + * Copyright 2006-2012 The FLWOR Foundation. |
3258 | + * |
3259 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
3260 | + * you may not use this file except in compliance with the License. |
3261 | + * You may obtain a copy of the License at |
3262 | + * |
3263 | + * http://www.apache.org/licenses/LICENSE-2.0 |
3264 | + * |
3265 | + * Unless required by applicable law or agreed to in writing, software |
3266 | + * distributed under the License is distributed on an "AS IS" BASIS, |
3267 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
3268 | + * See the License for the specific language governing permissions and |
3269 | + * limitations under the License. |
3270 | + */ |
3271 | + |
3272 | +#include "expr_manager.h" |
3273 | + |
3274 | +#include "mem_manager.h" |
3275 | + |
3276 | +#include "expr.h" |
3277 | +#include "ftnode.h" |
3278 | +#include "var_expr.h" |
3279 | +#include "flwor_expr.h" |
3280 | +#include "fo_expr.h" |
3281 | +#include "ft_expr.h" |
3282 | +#include "function_item_expr.h" |
3283 | +#include "path_expr.h" |
3284 | +#include "script_exprs.h" |
3285 | +#include "update_exprs.h" |
3286 | +#include "json_exprs.h" |
3287 | + |
3288 | +namespace zorba |
3289 | +{ |
3290 | + |
3291 | +//A simple expression that can just be deallocated without calling the |
3292 | +//destructor. |
3293 | +class NullExpr : public expr |
3294 | +{ |
3295 | +public: |
3296 | + NullExpr() : expr(NULL, NULL, QueryLoc(), unknown_expr_kind){} |
3297 | + void accept(expr_visitor& v){} |
3298 | + void compute_scripting_kind(){} |
3299 | + std::ostream& put(std::ostream& stream) const{return stream;} |
3300 | +}; |
3301 | + |
3302 | + |
3303 | +ExprManager::ExprManager(CompilerCB* ccb) |
3304 | + : |
3305 | + theCCB(ccb) |
3306 | +{ |
3307 | + theExprs.reserve(1024); |
3308 | +} |
3309 | + |
3310 | + |
3311 | +//calls on the destructors and also keeps tracks of certain numbers |
3312 | +ExprManager::~ExprManager() |
3313 | +{ |
3314 | + for(std::vector<expr*>::iterator iter = theExprs.begin(); |
3315 | + iter != theExprs.end(); |
3316 | + ++iter) |
3317 | + { |
3318 | + //Here we delete all remaining exprs, we assume that they may be "held" |
3319 | + //by a reference somewhere. |
3320 | + //To prevent deleting an already deleted expr, we replace them with |
3321 | + //a NullExpr |
3322 | + |
3323 | + expr* exp = *iter; |
3324 | + |
3325 | + exp->~expr(); |
3326 | + |
3327 | + //constructs a new NULLExpr where the old expr existed |
3328 | + new (exp) NullExpr(); |
3329 | + } |
3330 | +} |
3331 | + |
3332 | + |
3333 | +void ExprManager::garbageCollect() |
3334 | +{ |
3335 | + unsigned long numTotalBytes = 0; |
3336 | + unsigned long numDeadBytes = 0; |
3337 | + unsigned long numTotalExprs = theExprs.size(); |
3338 | + unsigned long numDeadExprs = 0; |
3339 | + |
3340 | + while (theExprs.size() > 0) |
3341 | + { |
3342 | + bool deleted_expr = false; |
3343 | + |
3344 | + for(std::vector<expr*>::iterator iter = theExprs.begin(); |
3345 | + iter != theExprs.end(); |
3346 | + ++iter) |
3347 | + { |
3348 | + expr* exp = *iter; |
3349 | + |
3350 | + if (exp->getRefCount() <= 0) |
3351 | + { |
3352 | + deleted_expr = true; |
3353 | + unsigned long bytes = sizeof *exp; |
3354 | + |
3355 | + numTotalBytes += bytes; |
3356 | + numDeadBytes += bytes; |
3357 | + ++numDeadExprs; |
3358 | + |
3359 | + exp->~expr(); |
3360 | + iter = theExprs.erase(iter); |
3361 | + --iter; |
3362 | + } |
3363 | + } |
3364 | + |
3365 | + if (!deleted_expr) |
3366 | + break; |
3367 | + } |
3368 | + |
3369 | + for(std::vector<expr*>::iterator iter = theExprs.begin(); |
3370 | + iter != theExprs.end(); |
3371 | + ++iter) |
3372 | + { |
3373 | + expr* exp = *iter; |
3374 | + numTotalBytes += sizeof *exp; |
3375 | + } |
3376 | + |
3377 | + std::cout << "Num Total Exprs = " << numTotalExprs |
3378 | + << " Num Total Bytes = " << numTotalBytes << std::endl |
3379 | + << "Num Dead Exprs = " << numDeadExprs |
3380 | + << " Num Dead Bytes = " << numDeadBytes << std::endl << std::endl; |
3381 | +} |
3382 | + |
3383 | + |
3384 | +expr* ExprManager::reg(expr* exp) |
3385 | +{ |
3386 | + theExprs.push_back(exp); |
3387 | + return exp; |
3388 | +} |
3389 | + |
3390 | + |
3391 | +//////////////////////////////////////////////////////////////////////////////// |
3392 | + |
3393 | +#define CREATE_AND_RETURN_EXPR(EXPRTYPE, ...) \ |
3394 | + EXPRTYPE* EXPPTR = new (theMemoryMgr) EXPRTYPE(theCCB, __VA_ARGS__); \ |
3395 | + reg(EXPPTR); \ |
3396 | + return EXPPTR |
3397 | + |
3398 | +#define CREATE_AND_RETURN(TYPE, ...) \ |
3399 | + TYPE* EXPPTR = new (theMemoryMgr) TYPE(__VA_ARGS__); \ |
3400 | + return EXPPTR |
3401 | + |
3402 | + |
3403 | +//////////////////////////////////////////////////////////////////////////////// |
3404 | + |
3405 | + |
3406 | +if_expr* ExprManager::create_if_expr( |
3407 | + static_context* sctx, |
3408 | + const QueryLoc& loc, |
3409 | + expr_t cond_expr, |
3410 | + expr_t then_expr, |
3411 | + expr_t else_expr) |
3412 | +{ |
3413 | + CREATE_AND_RETURN_EXPR(if_expr, sctx, loc, cond_expr, then_expr, else_expr); |
3414 | +} |
3415 | + |
3416 | + |
3417 | +order_expr* ExprManager::create_order_expr( |
3418 | + static_context* sctx, |
3419 | + const QueryLoc& loc, |
3420 | + order_expr::order_type_t order, |
3421 | + expr_t exp) |
3422 | +{ |
3423 | + CREATE_AND_RETURN_EXPR(order_expr, sctx, loc, order, exp); |
3424 | +} |
3425 | + |
3426 | + |
3427 | +validate_expr* ExprManager::create_validate_expr( |
3428 | + static_context* sctx, |
3429 | + const QueryLoc& loc, |
3430 | + ParseConstants::validation_mode_t mode, |
3431 | + const store::Item_t& aTypeName, |
3432 | + expr_t validated, |
3433 | + rchandle<TypeManager> tm) |
3434 | +{ |
3435 | + CREATE_AND_RETURN_EXPR(validate_expr, sctx, loc, mode, aTypeName, validated, tm); |
3436 | +} |
3437 | + |
3438 | + |
3439 | +cast_expr* ExprManager::create_cast_expr( |
3440 | + static_context* sctx, |
3441 | + const QueryLoc& loc, |
3442 | + expr_t casted, |
3443 | + xqtref_t type) |
3444 | +{ |
3445 | + CREATE_AND_RETURN_EXPR(cast_expr, sctx, loc, casted, type); |
3446 | +} |
3447 | + |
3448 | + |
3449 | +treat_expr* ExprManager::create_treat_expr( |
3450 | + static_context* sctx, |
3451 | + const QueryLoc& loc, |
3452 | + const expr_t& treated, |
3453 | + const xqtref_t& type, |
3454 | + TreatIterator::ErrorKind err, |
3455 | + bool check_prime, |
3456 | + store::Item* qname) |
3457 | +{ |
3458 | + CREATE_AND_RETURN_EXPR(treat_expr, |
3459 | + sctx, loc, treated, type, err, check_prime, qname); |
3460 | +} |
3461 | + |
3462 | + |
3463 | +promote_expr* ExprManager::create_promote_expr( |
3464 | + static_context* sctx, |
3465 | + const QueryLoc& loc, |
3466 | + const expr_t& promoted, |
3467 | + const xqtref_t& type, |
3468 | + PromoteIterator::ErrorKind err, |
3469 | + store::Item* qname) |
3470 | +{ |
3471 | + CREATE_AND_RETURN_EXPR(promote_expr, sctx, loc, promoted, type, err, qname); |
3472 | +} |
3473 | + |
3474 | + |
3475 | +castable_expr* ExprManager::create_castable_expr( |
3476 | + static_context* sctx, |
3477 | + const QueryLoc& loc, |
3478 | + expr_t castable, |
3479 | + xqtref_t type) |
3480 | +{ |
3481 | + CREATE_AND_RETURN_EXPR(castable_expr, sctx, loc, castable, type); |
3482 | +} |
3483 | + |
3484 | + |
3485 | +instanceof_expr* ExprManager::create_instanceof_expr( |
3486 | + static_context* sctx, |
3487 | + const QueryLoc& loc, |
3488 | + expr_t instanced, |
3489 | + xqtref_t type, |
3490 | + bool checkPrimeOnly) |
3491 | +{ |
3492 | + CREATE_AND_RETURN_EXPR(instanceof_expr, |
3493 | + sctx, loc, instanced, type, checkPrimeOnly); |
3494 | +} |
3495 | + |
3496 | + |
3497 | +name_cast_expr* ExprManager::create_name_cast_expr( |
3498 | + static_context* sctx, |
3499 | + const QueryLoc& loc, |
3500 | + expr_t casted, |
3501 | + const namespace_context* ns, |
3502 | + bool isAttr) |
3503 | +{ |
3504 | + CREATE_AND_RETURN_EXPR(name_cast_expr, sctx, loc, casted, ns, isAttr); |
3505 | +} |
3506 | + |
3507 | + |
3508 | +doc_expr* ExprManager::create_doc_expr( |
3509 | + static_context* sctx, |
3510 | + const QueryLoc& loc, |
3511 | + expr* content, |
3512 | + bool copyNodes) |
3513 | +{ |
3514 | + CREATE_AND_RETURN_EXPR(doc_expr, sctx, loc, content, copyNodes); |
3515 | +} |
3516 | + |
3517 | + |
3518 | +elem_expr* ExprManager::create_elem_expr( |
3519 | + static_context* sctx, |
3520 | + const QueryLoc& loc, |
3521 | + expr* qnameExpr, |
3522 | + expr* attrs, |
3523 | + expr* content, |
3524 | + const namespace_context* nsCtx, |
3525 | + bool copyNodes) |
3526 | +{ |
3527 | + CREATE_AND_RETURN_EXPR(elem_expr, |
3528 | + sctx, loc, qnameExpr, attrs, content, nsCtx, copyNodes); |
3529 | +} |
3530 | + |
3531 | + |
3532 | +elem_expr* ExprManager::create_elem_expr( |
3533 | + static_context* sctx, |
3534 | + const QueryLoc& loc, |
3535 | + expr* qnameExpr, |
3536 | + expr* content, |
3537 | + const namespace_context* nsCtx, |
3538 | + bool copyNodes) |
3539 | +{ |
3540 | + CREATE_AND_RETURN_EXPR(elem_expr, |
3541 | + sctx, loc, qnameExpr, content, nsCtx, copyNodes); |
3542 | +} |
3543 | + |
3544 | + |
3545 | +attr_expr* ExprManager::create_attr_expr( |
3546 | + static_context* sctx, |
3547 | + const QueryLoc& loc, |
3548 | + expr_t aQNameExpr, |
3549 | + expr_t aValueExpr) |
3550 | +{ |
3551 | + CREATE_AND_RETURN_EXPR(attr_expr, sctx, loc, aQNameExpr, aValueExpr); |
3552 | +} |
3553 | + |
3554 | + |
3555 | +text_expr* ExprManager::create_text_expr( |
3556 | + static_context* sctx, |
3557 | + const QueryLoc& loc, |
3558 | + text_expr::text_constructor_type textType, |
3559 | + expr_t text) |
3560 | +{ |
3561 | + CREATE_AND_RETURN_EXPR(text_expr, sctx, loc, textType, text); |
3562 | +} |
3563 | + |
3564 | + |
3565 | +pi_expr* ExprManager::create_pi_expr( |
3566 | + static_context* sctx, |
3567 | + const QueryLoc& loc, |
3568 | + expr_t targetExpr, |
3569 | + expr_t contentExpr) |
3570 | +{ |
3571 | + CREATE_AND_RETURN_EXPR(pi_expr, sctx, loc, targetExpr, contentExpr); |
3572 | +} |
3573 | + |
3574 | + |
3575 | +const_expr* ExprManager::create_const_expr( |
3576 | + static_context* sctx, |
3577 | + const QueryLoc& loc, |
3578 | + zstring& sval) |
3579 | +{ |
3580 | + CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, sval); |
3581 | +} |
3582 | + |
3583 | + |
3584 | +const_expr* ExprManager::create_const_expr( |
3585 | + static_context* sctx, |
3586 | + const QueryLoc& loc, |
3587 | + const std::string& sval) |
3588 | +{ |
3589 | + CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, sval); |
3590 | +} |
3591 | + |
3592 | + |
3593 | +const_expr* ExprManager::create_const_expr( |
3594 | + static_context* sctx, |
3595 | + const QueryLoc& loc, |
3596 | + const char* sval) |
3597 | +{ |
3598 | + CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, sval); |
3599 | +} |
3600 | + |
3601 | + |
3602 | +const_expr* ExprManager::create_const_expr( |
3603 | + static_context* sctx, |
3604 | + const QueryLoc& loc, |
3605 | + xs_integer val) |
3606 | +{ |
3607 | + CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, val); |
3608 | +} |
3609 | + |
3610 | + |
3611 | +const_expr* ExprManager::create_const_expr( |
3612 | + static_context* sctx, |
3613 | + const QueryLoc& loc, |
3614 | + xs_decimal val) |
3615 | +{ |
3616 | + CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, val); |
3617 | +} |
3618 | + |
3619 | + |
3620 | +const_expr* ExprManager::create_const_expr( |
3621 | + static_context* sctx, |
3622 | + const QueryLoc& loc, |
3623 | + xs_double val) |
3624 | +{ |
3625 | + CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, val); |
3626 | +} |
3627 | + |
3628 | + |
3629 | +const_expr* ExprManager::create_const_expr( |
3630 | + static_context* sctx, |
3631 | + const QueryLoc& loc, |
3632 | + xs_boolean val) |
3633 | +{ |
3634 | + CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, val); |
3635 | +} |
3636 | + |
3637 | + |
3638 | +const_expr* ExprManager::create_const_expr( |
3639 | + static_context* sctx, |
3640 | + const QueryLoc& loc, |
3641 | + store::Item_t val) |
3642 | +{ |
3643 | + CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, val); |
3644 | +} |
3645 | + |
3646 | + |
3647 | +const_expr* ExprManager::create_const_expr( |
3648 | + static_context* sctx, |
3649 | + const QueryLoc& loc, |
3650 | + const char* ns, |
3651 | + const char* pre, |
3652 | + const char* local) |
3653 | +{ |
3654 | + CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, ns, pre, local); |
3655 | +} |
3656 | + |
3657 | + |
3658 | +extension_expr* ExprManager::create_extension_expr( |
3659 | + static_context* sctx, |
3660 | + const QueryLoc& loc) |
3661 | +{ |
3662 | + CREATE_AND_RETURN_EXPR(extension_expr, sctx, loc); |
3663 | +} |
3664 | + |
3665 | + |
3666 | +extension_expr* ExprManager::create_extension_expr( |
3667 | + static_context* sctx, |
3668 | + const QueryLoc& loc, |
3669 | + expr_t extended) |
3670 | +{ |
3671 | + CREATE_AND_RETURN_EXPR(extension_expr, sctx, loc, extended); |
3672 | +} |
3673 | + |
3674 | + |
3675 | +catch_clause* ExprManager::create_catch_clause() |
3676 | +{ |
3677 | + CREATE_AND_RETURN(catch_clause); |
3678 | +} |
3679 | + |
3680 | + |
3681 | +trycatch_expr* ExprManager::create_trycatch_expr( |
3682 | + static_context* sctx, |
3683 | + const QueryLoc& loc, |
3684 | + expr_t tryExpr) |
3685 | +{ |
3686 | + CREATE_AND_RETURN_EXPR(trycatch_expr, sctx, loc, tryExpr); |
3687 | +} |
3688 | + |
3689 | + |
3690 | +wrapper_expr* ExprManager::create_wrapper_expr( |
3691 | + static_context* sctx, |
3692 | + const QueryLoc& loc, |
3693 | + expr_t wrapped) |
3694 | +{ |
3695 | + CREATE_AND_RETURN_EXPR(wrapper_expr, sctx, loc, wrapped); |
3696 | +} |
3697 | + |
3698 | + |
3699 | +function_trace_expr* ExprManager::create_function_trace_expr( |
3700 | + static_context* sctx, |
3701 | + const QueryLoc& loc, |
3702 | + expr_t aChild) |
3703 | +{ |
3704 | + CREATE_AND_RETURN_EXPR(function_trace_expr, sctx, loc, aChild); |
3705 | +} |
3706 | + |
3707 | + |
3708 | +function_trace_expr* ExprManager::create_function_trace_expr(expr_t aExpr) |
3709 | +{ |
3710 | + //this function gets the ExprManager from the expression it recieves. |
3711 | + return static_cast<function_trace_expr*> |
3712 | + (reg(new (theMemoryMgr) function_trace_expr(aExpr))); |
3713 | +} |
3714 | + |
3715 | + |
3716 | +eval_expr* ExprManager::create_eval_expr( |
3717 | + CompilerCB* ccb, |
3718 | + static_context* sctx, |
3719 | + const QueryLoc& loc, |
3720 | + const expr_t& e, |
3721 | + expr_script_kind_t scriptingKind, |
3722 | + namespace_context* nsCtx) |
3723 | +{ |
3724 | + CREATE_AND_RETURN_EXPR(eval_expr, ccb, sctx, loc, e, scriptingKind, nsCtx); |
3725 | +} |
3726 | + |
3727 | +#ifdef ZORBA_WITH_DEBUGGER |
3728 | + |
3729 | +debugger_expr* ExprManager::create_debugger_expr( |
3730 | + static_context* sctx, |
3731 | + const QueryLoc& loc, |
3732 | + const expr_t& aChild, |
3733 | + namespace_context* nsCtx, |
3734 | + bool aIsVarDeclaration) |
3735 | +{ |
3736 | + CREATE_AND_RETURN_EXPR(debugger_expr, |
3737 | + sctx, loc, aChild, nsCtx, aIsVarDeclaration); |
3738 | +} |
3739 | + |
3740 | +#endif |
3741 | + |
3742 | +//////////////////////////////////////////////////////////////////////////////// |
3743 | + |
3744 | +var_expr* ExprManager::create_var_expr( |
3745 | + static_context* sctx, |
3746 | + const QueryLoc& loc, |
3747 | + var_expr::var_kind k, |
3748 | + store::Item* name) |
3749 | +{ |
3750 | + CREATE_AND_RETURN_EXPR(var_expr, sctx, loc, k, name); |
3751 | +} |
3752 | + |
3753 | + |
3754 | +var_expr* ExprManager::create_var_expr(const var_expr& source) |
3755 | +{ |
3756 | + return static_cast<var_expr*>(reg(new (theMemoryMgr) var_expr(source))); |
3757 | +} |
3758 | + |
3759 | + |
3760 | +//////////////////////////////////////////////////////////////////////////////// |
3761 | + |
3762 | + |
3763 | +insert_expr* ExprManager::create_insert_expr( |
3764 | + static_context* sctx, |
3765 | + const QueryLoc& loc, |
3766 | + store::UpdateConsts::InsertType insertType, |
3767 | + const expr_t& aSourceExpr, |
3768 | + const expr_t& aTargetExpr) |
3769 | +{ |
3770 | + CREATE_AND_RETURN_EXPR(insert_expr, |
3771 | + sctx, loc, insertType, aSourceExpr, aTargetExpr); |
3772 | +} |
3773 | + |
3774 | + |
3775 | +delete_expr* ExprManager::create_delete_expr( |
3776 | + static_context* sctx, |
3777 | + const QueryLoc& loc, |
3778 | + const expr_t& aTargetExpr) |
3779 | +{ |
3780 | + CREATE_AND_RETURN_EXPR(delete_expr, sctx, loc, aTargetExpr); |
3781 | +} |
3782 | + |
3783 | + |
3784 | +replace_expr* ExprManager::create_replace_expr( |
3785 | + static_context* sctx, |
3786 | + const QueryLoc& loc, |
3787 | + store::UpdateConsts::ReplaceType aType, |
3788 | + const expr_t& aSourceExpr, |
3789 | + const expr_t& aTargetExpr) |
3790 | +{ |
3791 | + CREATE_AND_RETURN_EXPR(replace_expr, sctx, loc, aType, aSourceExpr, aTargetExpr); |
3792 | +} |
3793 | + |
3794 | + |
3795 | +rename_expr* ExprManager::create_rename_expr( |
3796 | + static_context* sctx, |
3797 | + const QueryLoc& loc, |
3798 | + const expr_t& aSourceExpr, |
3799 | + const expr_t& aTargetExpr) |
3800 | +{ |
3801 | + CREATE_AND_RETURN_EXPR(rename_expr, sctx, loc, aSourceExpr, aTargetExpr); |
3802 | +} |
3803 | + |
3804 | + |
3805 | +copy_clause* ExprManager::create_copy_clause(var_expr_t aVar, expr_t aExpr) |
3806 | +{ |
3807 | + CREATE_AND_RETURN(copy_clause, aVar, aExpr); |
3808 | +} |
3809 | + |
3810 | + |
3811 | +transform_expr* ExprManager::create_transform_expr( |
3812 | + static_context* sctx, |
3813 | + const QueryLoc& loc) |
3814 | +{ |
3815 | + CREATE_AND_RETURN_EXPR(transform_expr, sctx, loc); |
3816 | +} |
3817 | + |
3818 | + |
3819 | +block_expr* ExprManager::create_block_expr( |
3820 | + static_context* sctx, |
3821 | + const QueryLoc& loc, |
3822 | + bool allowLastUpdating, |
3823 | + std::vector<expr_t>& seq, |
3824 | + std::vector<var_expr*>* assignedVars) |
3825 | +{ |
3826 | + CREATE_AND_RETURN_EXPR(block_expr, |
3827 | + sctx, loc, allowLastUpdating, seq, assignedVars); |
3828 | +} |
3829 | + |
3830 | + |
3831 | +apply_expr* ExprManager::create_apply_expr( |
3832 | + static_context* sctx, |
3833 | + const QueryLoc& loc, |
3834 | + const expr_t& inExpr, |
3835 | + bool discardXDM) |
3836 | +{ |
3837 | + CREATE_AND_RETURN_EXPR(apply_expr, sctx, loc, inExpr, discardXDM); |
3838 | +} |
3839 | + |
3840 | + |
3841 | +var_decl_expr* ExprManager::create_var_decl_expr( |
3842 | + static_context* sctx, |
3843 | + const QueryLoc& loc, |
3844 | + const var_expr_t& varExpr, |
3845 | + const expr_t& initExpr) |
3846 | +{ |
3847 | + CREATE_AND_RETURN_EXPR(var_decl_expr, sctx, loc, varExpr, initExpr); |
3848 | +} |
3849 | + |
3850 | + |
3851 | +var_set_expr* ExprManager::create_var_set_expr( |
3852 | + static_context* sctx, |
3853 | + const QueryLoc& loc, |
3854 | + const var_expr_t& varExpr, |
3855 | + const expr_t& setExpr) |
3856 | +{ |
3857 | + CREATE_AND_RETURN_EXPR(var_set_expr, sctx, loc, varExpr, setExpr); |
3858 | +} |
3859 | + |
3860 | + |
3861 | +exit_expr* ExprManager::create_exit_expr( |
3862 | + static_context* sctx, |
3863 | + const QueryLoc& loc, |
3864 | + const expr_t& inExpr) |
3865 | +{ |
3866 | + CREATE_AND_RETURN_EXPR(exit_expr, sctx, loc, inExpr); |
3867 | +} |
3868 | + |
3869 | + |
3870 | +exit_catcher_expr* ExprManager::create_exit_catcher_expr( |
3871 | + static_context* sctx, |
3872 | + const QueryLoc& loc, |
3873 | + const expr_t& inExpr, |
3874 | + std::vector<expr*>& exitExprs) |
3875 | +{ |
3876 | + CREATE_AND_RETURN_EXPR(exit_catcher_expr, sctx, loc, inExpr, exitExprs); |
3877 | +} |
3878 | + |
3879 | + |
3880 | +flowctl_expr* ExprManager::create_flowctl_expr( |
3881 | + static_context* sctx, |
3882 | + const QueryLoc& loc, |
3883 | + flowctl_expr::action action) |
3884 | +{ |
3885 | + CREATE_AND_RETURN_EXPR(flowctl_expr, sctx, loc, action); |
3886 | +} |
3887 | + |
3888 | + |
3889 | +while_expr* ExprManager::create_while_expr( |
3890 | + static_context* sctx, const QueryLoc& loc, expr_t body) |
3891 | +{ |
3892 | + CREATE_AND_RETURN_EXPR(while_expr, sctx, loc, body); |
3893 | +} |
3894 | + |
3895 | + |
3896 | +//////////////////////////////////////////////////////////////////////////////// |
3897 | + |
3898 | +relpath_expr* ExprManager::create_relpath_expr( |
3899 | + static_context* sctx, |
3900 | + const QueryLoc& loc) |
3901 | +{ |
3902 | + CREATE_AND_RETURN_EXPR(relpath_expr, sctx, loc); |
3903 | +} |
3904 | + |
3905 | + |
3906 | +axis_step_expr* ExprManager::create_axis_step_expr( |
3907 | + static_context* sctx, |
3908 | + const QueryLoc& loc) |
3909 | +{ |
3910 | + CREATE_AND_RETURN_EXPR(axis_step_expr, sctx, loc); |
3911 | +} |
3912 | + |
3913 | + |
3914 | +match_expr* ExprManager::create_match_expr( |
3915 | + static_context* sctx, |
3916 | + const QueryLoc& loc) |
3917 | +{ |
3918 | + CREATE_AND_RETURN_EXPR(match_expr, sctx, loc); |
3919 | +} |
3920 | + |
3921 | + |
3922 | +//////////////////////////////////////////////////////////////////////////////// |
3923 | + |
3924 | +dynamic_function_invocation_expr* |
3925 | +ExprManager::create_dynamic_function_invocation_expr( |
3926 | + static_context* sctx, |
3927 | + const QueryLoc& loc, |
3928 | + const expr_t& anExpr, |
3929 | + const std::vector<expr_t>& args) |
3930 | +{ |
3931 | + CREATE_AND_RETURN_EXPR(dynamic_function_invocation_expr, sctx, loc, anExpr, args); |
3932 | +} |
3933 | + |
3934 | + |
3935 | +function_item_expr* ExprManager::create_function_item_expr( |
3936 | + static_context* sctx, |
3937 | + const QueryLoc& loc, |
3938 | + const store::Item* aQName, |
3939 | + function* f, |
3940 | + uint32_t aArity) |
3941 | +{ |
3942 | + CREATE_AND_RETURN_EXPR(function_item_expr, sctx, loc, aQName, f, aArity); |
3943 | +} |
3944 | + |
3945 | + |
3946 | +function_item_expr* ExprManager::create_function_item_expr( |
3947 | + static_context* sctx, |
3948 | + const QueryLoc& loc) |
3949 | +{ |
3950 | + CREATE_AND_RETURN_EXPR(function_item_expr, sctx, loc); |
3951 | +} |
3952 | + |
3953 | + |
3954 | +ftcontains_expr* ExprManager::create_ftcontains_expr( |
3955 | + static_context* sctx, |
3956 | + QueryLoc const& loc, |
3957 | + expr_t range, |
3958 | + ftnode *ftselection, |
3959 | + expr_t ftignore) |
3960 | +{ |
3961 | + CREATE_AND_RETURN_EXPR(ftcontains_expr, sctx, loc, range, ftselection, ftignore); |
3962 | +} |
3963 | + |
3964 | + |
3965 | +//////////////////////////////////////////////////////////////////////////////// |
3966 | + |
3967 | +//this calls the static create_seq within fo_expr |
3968 | +fo_expr* ExprManager::create_seq(static_context* sctx, const QueryLoc& loc) |
3969 | +{ |
3970 | + //TODO make fo_expr use this factory to generate everything |
3971 | + return fo_expr::create_seq(theCCB, sctx, loc); |
3972 | +} |
3973 | + |
3974 | + |
3975 | +fo_expr* ExprManager::create_fo_expr( |
3976 | + static_context* sctx, |
3977 | + const QueryLoc& loc, |
3978 | + const function* f, |
3979 | + const expr* arg) |
3980 | +{ |
3981 | + CREATE_AND_RETURN_EXPR(fo_expr, sctx, loc, f, arg); |
3982 | +} |
3983 | + |
3984 | + |
3985 | +fo_expr* ExprManager::create_fo_expr( |
3986 | + static_context* sctx, |
3987 | + const QueryLoc& loc, |
3988 | + const function* f, |
3989 | + const expr* arg1, |
3990 | + const expr* arg2) |
3991 | +{ |
3992 | + CREATE_AND_RETURN_EXPR(fo_expr, sctx, loc, f, arg1, arg2); |
3993 | +} |
3994 | + |
3995 | + |
3996 | +fo_expr* ExprManager::create_fo_expr( |
3997 | + static_context* sctx, |
3998 | + const QueryLoc& loc, |
3999 | + const function* f, |
4000 | + const std::vector<expr_t>& args) |
4001 | +{ |
4002 | + CREATE_AND_RETURN_EXPR(fo_expr, sctx, loc, f, args); |
4003 | +} |
4004 | + |
4005 | +fo_expr* ExprManager::create_fo_expr( |
4006 | + static_context* sctx, |
4007 | + const QueryLoc& loc, |
4008 | + const function* f) |
4009 | +{ |
4010 | + |
4011 | + CREATE_AND_RETURN_EXPR(fo_expr, sctx, loc, f); |
4012 | +} |
4013 | +//////////////////////////////////////////////////////////////////////////////// |
4014 | + |
4015 | +for_clause* ExprManager::create_for_clause( |
4016 | + static_context* sctx, |
4017 | + const QueryLoc& loc, |
4018 | + var_expr_t varExpr, |
4019 | + expr_t domainExpr, |
4020 | + var_expr_t posVarExpr, |
4021 | + var_expr_t scoreVarExpr, |
4022 | + bool isOuter) |
4023 | +{ |
4024 | + CREATE_AND_RETURN(for_clause, |
4025 | + sctx, theCCB, loc, varExpr, domainExpr, posVarExpr, scoreVarExpr, isOuter); |
4026 | +} |
4027 | + |
4028 | +let_clause* ExprManager::create_let_clause( |
4029 | + static_context* sctx, |
4030 | + const QueryLoc& loc, |
4031 | + var_expr_t varExpr, |
4032 | + expr_t domainExpr, |
4033 | + bool lazy) |
4034 | +{ |
4035 | + CREATE_AND_RETURN(let_clause, sctx, theCCB, loc, varExpr, domainExpr, lazy); |
4036 | +} |
4037 | + |
4038 | +window_clause* ExprManager::create_window_clause( |
4039 | + static_context* sctx, |
4040 | + const QueryLoc& loc, |
4041 | + window_clause::window_t winKind, |
4042 | + var_expr_t varExpr, |
4043 | + expr_t domainExpr, |
4044 | + flwor_wincond_t winStart, |
4045 | + flwor_wincond_t winStop, |
4046 | + bool lazy) |
4047 | +{ |
4048 | + CREATE_AND_RETURN(window_clause, |
4049 | + sctx, theCCB, loc, winKind, varExpr, domainExpr, winStart, winStop, lazy); |
4050 | +} |
4051 | + |
4052 | +flwor_wincond* ExprManager::create_flwor_wincond( |
4053 | + static_context* sctx, |
4054 | + bool isOnly, |
4055 | + const flwor_wincond::vars& in_vars, |
4056 | + const flwor_wincond::vars& out_vars, |
4057 | + expr_t cond) |
4058 | +{ |
4059 | + CREATE_AND_RETURN(flwor_wincond, theCCB, sctx, isOnly, in_vars, out_vars, cond); |
4060 | +} |
4061 | + |
4062 | +group_clause* ExprManager::create_group_clause( |
4063 | + static_context* sctx, |
4064 | + const QueryLoc& loc, |
4065 | + const flwor_clause::rebind_list_t& gvars, |
4066 | + flwor_clause::rebind_list_t ngvars, |
4067 | + const std::vector<std::string>& collations) |
4068 | +{ |
4069 | + CREATE_AND_RETURN(group_clause, sctx, loc, gvars, ngvars, collations); |
4070 | +} |
4071 | + |
4072 | +orderby_clause* ExprManager::create_orderby_clause( |
4073 | + static_context* sctx, |
4074 | + const QueryLoc& loc, |
4075 | + bool stable, |
4076 | + const std::vector<OrderModifier>& modifiers, |
4077 | + const std::vector<expr_t>& orderingExprs) |
4078 | +{ |
4079 | + CREATE_AND_RETURN(orderby_clause, sctx, loc, stable, modifiers, orderingExprs); |
4080 | +} |
4081 | + |
4082 | +materialize_clause* ExprManager::create_materialize_clause( |
4083 | + static_context* sctx, const QueryLoc& loc) |
4084 | +{ |
4085 | + CREATE_AND_RETURN(materialize_clause, sctx, loc); |
4086 | +} |
4087 | + |
4088 | +count_clause* ExprManager::create_count_clause( |
4089 | + static_context* sctx, const QueryLoc& loc, var_expr_t var) |
4090 | +{ |
4091 | + CREATE_AND_RETURN(count_clause, sctx, loc, var); |
4092 | +} |
4093 | + |
4094 | +where_clause* ExprManager::create_where_clause( |
4095 | + static_context* sctx, const QueryLoc& loc, expr_t where) |
4096 | +{ |
4097 | + CREATE_AND_RETURN(where_clause, sctx, loc, where); |
4098 | +} |
4099 | + |
4100 | +flwor_expr* ExprManager::create_flwor_expr( |
4101 | + static_context* sctx, const QueryLoc& loc, bool general) |
4102 | +{ |
4103 | + CREATE_AND_RETURN_EXPR(flwor_expr, sctx, loc, general); |
4104 | +} |
4105 | + |
4106 | +//////////////////////////////////////////////////////////////////////////////// |
4107 | + |
4108 | +#ifdef ZORBA_WITH_JSON |
4109 | + |
4110 | +json_array_expr* ExprManager::create_json_array_expr( |
4111 | + static_context* sctx, |
4112 | + const QueryLoc& loc, |
4113 | + const expr_t& content) |
4114 | +{ |
4115 | + CREATE_AND_RETURN_EXPR(json_array_expr, sctx, loc, content); |
4116 | +} |
4117 | + |
4118 | +json_object_expr* ExprManager::create_json_object_expr( |
4119 | + static_context* sctx, |
4120 | + const QueryLoc& loc, |
4121 | + const expr_t& content, |
4122 | + bool accumulate) |
4123 | +{ |
4124 | + CREATE_AND_RETURN_EXPR(json_object_expr, sctx, loc, content, accumulate); |
4125 | +} |
4126 | + |
4127 | +json_direct_object_expr* ExprManager::create_json_direct_object_expr( |
4128 | + static_context* sctx, |
4129 | + const QueryLoc& loc, |
4130 | + std::vector<expr_t>& names, |
4131 | + std::vector<expr_t>& values) |
4132 | +{ |
4133 | + CREATE_AND_RETURN_EXPR(json_direct_object_expr, sctx, loc, names, values); |
4134 | +} |
4135 | + |
4136 | +#endif // ZORBA_WITH_JSON |
4137 | + |
4138 | +} // namespace zorba |
4139 | + |
4140 | |
4141 | === added file 'src/compiler/expression/expr_manager.h' |
4142 | --- src/compiler/expression/expr_manager.h 1970-01-01 00:00:00 +0000 |
4143 | +++ src/compiler/expression/expr_manager.h 2012-08-10 11:20:27 +0000 |
4144 | @@ -0,0 +1,506 @@ |
4145 | +/* |
4146 | + * Copyright 2006-2012 The FLWOR Foundation. |
4147 | + * |
4148 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
4149 | + * you may not use this file except in compliance with the License. |
4150 | + * You may obtain a copy of the License at |
4151 | + * |
4152 | + * http://www.apache.org/licenses/LICENSE-2.0 |
4153 | + * |
4154 | + * Unless required by applicable law or agreed to in writing, software |
4155 | + * distributed under the License is distributed on an "AS IS" BASIS, |
4156 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
4157 | + * See the License for the specific language governing permissions and |
4158 | + * limitations under the License. |
4159 | + */ |
4160 | + |
4161 | +#pragma once |
4162 | +#ifndef ZORBA_COMPILER_EXPRMANAGER_H |
4163 | +#define ZORBA_COMPILER_EXPRMANAGER_H |
4164 | + |
4165 | +#include "expr_classes.h" |
4166 | +#include "expr.h" |
4167 | +#include "script_exprs.h" |
4168 | +#include "flwor_expr.h" |
4169 | +#include "ftnode.h" |
4170 | + |
4171 | +#include "mem_manager.h" |
4172 | + |
4173 | +namespace zorba |
4174 | +{ |
4175 | + |
4176 | +class CompilerCB; |
4177 | + |
4178 | +class ExprManager |
4179 | +{ |
4180 | +private: |
4181 | + std::vector<expr*> theExprs; |
4182 | + MemoryManager theMemoryMgr; |
4183 | + CompilerCB * theCCB; |
4184 | + |
4185 | +public: |
4186 | + ExprManager(CompilerCB* ccb); |
4187 | + |
4188 | + ~ExprManager(); |
4189 | + |
4190 | + expr* reg(expr*); |
4191 | + |
4192 | +private: |
4193 | + //An ExprManager is the only objecto to handle a collection of Exprs and |
4194 | + //the memory in which they recide. It makes no sense to copy it. |
4195 | + ExprManager(const ExprManager&); |
4196 | + ExprManager& operator= (const ExprManager&); |
4197 | + |
4198 | +public: |
4199 | + MemoryManager& getMemory() { return theMemoryMgr; } |
4200 | + |
4201 | + csize numExprs() const { return theExprs.size(); } |
4202 | + |
4203 | + void garbageCollect(); |
4204 | + |
4205 | +public: |
4206 | + if_expr* create_if_expr( |
4207 | + static_context* sctx, |
4208 | + const QueryLoc& loc, |
4209 | + expr_t cond_expr, |
4210 | + expr_t then_expr, |
4211 | + expr_t else_expr); |
4212 | + |
4213 | + order_expr* create_order_expr( |
4214 | + static_context* sctx, |
4215 | + const QueryLoc& loc, |
4216 | + order_expr::order_type_t, |
4217 | + expr_t); |
4218 | + |
4219 | + validate_expr* create_validate_expr( |
4220 | + static_context*, |
4221 | + const QueryLoc&, |
4222 | + ParseConstants::validation_mode_t, |
4223 | + const store::Item_t& aTypeName, |
4224 | + expr_t validated, |
4225 | + rchandle<TypeManager>); |
4226 | + |
4227 | + cast_expr* create_cast_expr( |
4228 | + static_context* sctx, |
4229 | + const QueryLoc&, |
4230 | + expr_t, |
4231 | + xqtref_t); |
4232 | + |
4233 | + treat_expr* create_treat_expr( |
4234 | + static_context* sctx, |
4235 | + const QueryLoc& loc, |
4236 | + const expr_t& input, |
4237 | + const xqtref_t& type, |
4238 | + TreatIterator::ErrorKind err, |
4239 | + bool check_prime = true, |
4240 | + store::Item* qnname = NULL); |
4241 | + |
4242 | + |
4243 | + promote_expr* create_promote_expr( |
4244 | + static_context* sctx, |
4245 | + const QueryLoc& loc, |
4246 | + const expr_t& input, |
4247 | + const xqtref_t& type, |
4248 | + PromoteIterator::ErrorKind err, |
4249 | + store::Item* qname); |
4250 | + |
4251 | + castable_expr* create_castable_expr( |
4252 | + static_context* sctx, |
4253 | + const QueryLoc&, |
4254 | + expr_t, |
4255 | + xqtref_t); |
4256 | + |
4257 | + instanceof_expr* create_instanceof_expr( |
4258 | + static_context* sctx, |
4259 | + const QueryLoc&, |
4260 | + expr_t, |
4261 | + xqtref_t, |
4262 | + bool checkPrimeOnly = false); |
4263 | + |
4264 | + name_cast_expr* create_name_cast_expr( |
4265 | + static_context* sctx, |
4266 | + const QueryLoc&, |
4267 | + expr_t, |
4268 | + const namespace_context*, |
4269 | + bool isAttr); |
4270 | + |
4271 | + doc_expr* create_doc_expr( |
4272 | + static_context* sctx, |
4273 | + const QueryLoc&, |
4274 | + expr* content, |
4275 | + bool copyNodes); |
4276 | + |
4277 | + elem_expr* create_elem_expr( |
4278 | + static_context* sctx, |
4279 | + const QueryLoc&, |
4280 | + expr* qnameExpr, |
4281 | + expr* attrs, |
4282 | + expr* content, |
4283 | + const namespace_context* nsCtx, |
4284 | + bool copyNodes); |
4285 | + |
4286 | + elem_expr* create_elem_expr( |
4287 | + static_context* sctx, |
4288 | + const QueryLoc&, |
4289 | + expr* qnameExpr, |
4290 | + expr* content, |
4291 | + const namespace_context* nsCtx, |
4292 | + bool copyNodes); |
4293 | + |
4294 | + attr_expr* create_attr_expr( |
4295 | + static_context* sctx, |
4296 | + const QueryLoc& loc, |
4297 | + expr_t aQNameExpr, |
4298 | + expr_t aValueExpr); |
4299 | + |
4300 | + text_expr* create_text_expr( |
4301 | + static_context* sctx, |
4302 | + const QueryLoc&, |
4303 | + text_expr::text_constructor_type, |
4304 | + expr_t); |
4305 | + |
4306 | + pi_expr* create_pi_expr( |
4307 | + static_context* sctx, |
4308 | + const QueryLoc&, |
4309 | + expr_t, |
4310 | + expr_t); |
4311 | + |
4312 | + const_expr* create_const_expr( |
4313 | + static_context* sctx, |
4314 | + const QueryLoc&, |
4315 | + zstring& sval); |
4316 | + |
4317 | + const_expr* create_const_expr( |
4318 | + static_context* sctx, |
4319 | + const QueryLoc&, |
4320 | + const std::string& sval); |
4321 | + |
4322 | + const_expr* create_const_expr( |
4323 | + static_context* sctx, |
4324 | + const QueryLoc&, |
4325 | + const char* sval); |
4326 | + |
4327 | + const_expr* create_const_expr( |
4328 | + static_context* sctx, |
4329 | + const QueryLoc&, |
4330 | + xs_integer); |
4331 | + |
4332 | + const_expr* create_const_expr( |
4333 | + static_context* sctx, |
4334 | + const QueryLoc&, |
4335 | + xs_decimal); |
4336 | + |
4337 | + const_expr* create_const_expr( |
4338 | + static_context* sctx, |
4339 | + const QueryLoc&, |
4340 | + xs_double); |
4341 | + |
4342 | + const_expr* create_const_expr( |
4343 | + static_context* sctx, |
4344 | + const QueryLoc&, |
4345 | + xs_boolean); |
4346 | + |
4347 | + const_expr* create_const_expr( |
4348 | + static_context* sctx, |
4349 | + const QueryLoc&, |
4350 | + store::Item_t); |
4351 | + |
4352 | + const_expr* create_const_expr( |
4353 | + static_context* sctx, |
4354 | + const QueryLoc&, |
4355 | + const char* ns, |
4356 | + const char* pre, |
4357 | + const char* local); |
4358 | + |
4359 | + extension_expr* create_extension_expr( |
4360 | + static_context* sctx, |
4361 | + const QueryLoc&); |
4362 | + |
4363 | + extension_expr* create_extension_expr( |
4364 | + static_context* sctx, |
4365 | + const QueryLoc&, |
4366 | + expr_t); |
4367 | + |
4368 | + catch_clause* create_catch_clause(); |
4369 | + |
4370 | + trycatch_expr* create_trycatch_expr( |
4371 | + static_context* sctx, |
4372 | + const QueryLoc&, |
4373 | + expr_t tryExpr); |
4374 | + |
4375 | + wrapper_expr* create_wrapper_expr( |
4376 | + static_context* sctx, |
4377 | + const QueryLoc& loc, |
4378 | + expr_t wrapped); |
4379 | + |
4380 | + function_trace_expr* create_function_trace_expr( |
4381 | + static_context* sctx, |
4382 | + const QueryLoc& loc, |
4383 | + expr_t aChild); |
4384 | + |
4385 | + function_trace_expr* create_function_trace_expr(expr_t aExpr); |
4386 | + |
4387 | + eval_expr* create_eval_expr( |
4388 | + CompilerCB* ccb, |
4389 | + static_context* sctx, |
4390 | + const QueryLoc& loc, |
4391 | + const expr_t& e, |
4392 | + expr_script_kind_t scriptingKind, |
4393 | + namespace_context* nsCtx); |
4394 | + |
4395 | +#ifdef ZORBA_WITH_DEBUGGER |
4396 | + debugger_expr* create_debugger_expr( |
4397 | + static_context* sctx, |
4398 | + const QueryLoc& loc, |
4399 | + const expr_t& aChild, |
4400 | + namespace_context* nsCtx, |
4401 | + bool aIsVarDeclaration); |
4402 | +#endif |
4403 | + |
4404 | +//////////////////////////////////////////////////////////////////////////////// |
4405 | + |
4406 | + var_expr* create_var_expr( |
4407 | + static_context* sctx, |
4408 | + const QueryLoc& loc, |
4409 | + var_expr::var_kind k, |
4410 | + store::Item* name); |
4411 | + |
4412 | + var_expr* create_var_expr(const var_expr& source); |
4413 | + |
4414 | +//////////////////////////////////////////////////////////////////////////////// |
4415 | + |
4416 | + insert_expr* create_insert_expr( |
4417 | + static_context* sctx, |
4418 | + const QueryLoc&, |
4419 | + store::UpdateConsts::InsertType, |
4420 | + const expr_t& aSourceExpr, |
4421 | + const expr_t& aTargetExpr); |
4422 | + |
4423 | + delete_expr* create_delete_expr( |
4424 | + static_context* sctx, |
4425 | + const QueryLoc&, |
4426 | + const expr_t&); |
4427 | + |
4428 | + replace_expr* create_replace_expr( |
4429 | + static_context* sctx, |
4430 | + const QueryLoc&, |
4431 | + store::UpdateConsts::ReplaceType aType, |
4432 | + const expr_t&, |
4433 | + const expr_t&); |
4434 | + |
4435 | + rename_expr* create_rename_expr( |
4436 | + static_context* sctx, |
4437 | + const QueryLoc&, |
4438 | + const expr_t&, |
4439 | + const expr_t&); |
4440 | + |
4441 | + copy_clause* create_copy_clause(var_expr_t aVar, expr_t aExpr); |
4442 | + |
4443 | + transform_expr* create_transform_expr( |
4444 | + static_context* sctx, |
4445 | + const QueryLoc& loc); |
4446 | + |
4447 | + block_expr* create_block_expr( |
4448 | + static_context* sctx, |
4449 | + const QueryLoc& loc, |
4450 | + bool allowLastUpdating, |
4451 | + std::vector<expr_t>& seq, |
4452 | + std::vector<var_expr*>* assignedVars); |
4453 | + |
4454 | + apply_expr* create_apply_expr( |
4455 | + static_context* sctx, |
4456 | + const QueryLoc& loc, |
4457 | + const expr_t& inExpr, |
4458 | + bool discardXDM); |
4459 | + |
4460 | + var_decl_expr* create_var_decl_expr( |
4461 | + static_context* sctx, |
4462 | + const QueryLoc& loc, |
4463 | + const var_expr_t& varExpr, |
4464 | + const expr_t& initExpr); |
4465 | + |
4466 | + var_set_expr* create_var_set_expr( |
4467 | + static_context* sctx, |
4468 | + const QueryLoc& loc, |
4469 | + const var_expr_t& varExpr, |
4470 | + const expr_t& setExpr); |
4471 | + |
4472 | + exit_expr* create_exit_expr( |
4473 | + static_context* sctx, |
4474 | + const QueryLoc& loc, |
4475 | + const expr_t& inExpr); |
4476 | + |
4477 | + exit_catcher_expr* create_exit_catcher_expr( |
4478 | + static_context* sctx, |
4479 | + const QueryLoc& loc, |
4480 | + const expr_t& inExpr, |
4481 | + std::vector<expr*>& exitExprs); |
4482 | + |
4483 | + flowctl_expr* create_flowctl_expr( |
4484 | + static_context* sctx, |
4485 | + const QueryLoc& loc, |
4486 | + flowctl_expr::action action); |
4487 | + |
4488 | + while_expr* create_while_expr( |
4489 | + static_context* sctx, |
4490 | + const QueryLoc& loc, |
4491 | + expr_t body); |
4492 | + |
4493 | +//////////////////////////////////////////////////////////////////////////////// |
4494 | + |
4495 | + relpath_expr* create_relpath_expr(static_context* sctx, const QueryLoc& loc); |
4496 | + |
4497 | + axis_step_expr* create_axis_step_expr(static_context* sctx, const QueryLoc&); |
4498 | + |
4499 | + match_expr* create_match_expr(static_context* sctx, const QueryLoc&); |
4500 | + |
4501 | +//////////////////////////////////////////////////////////////////////////////// |
4502 | + |
4503 | + dynamic_function_invocation_expr* create_dynamic_function_invocation_expr( |
4504 | + static_context* sctx, |
4505 | + const QueryLoc& loc, |
4506 | + const expr_t& anExpr, |
4507 | + const std::vector<expr_t>& args); |
4508 | + |
4509 | + function_item_expr* create_function_item_expr( |
4510 | + static_context* sctx, |
4511 | + const QueryLoc& loc, |
4512 | + const store::Item* aQName, |
4513 | + function* f, |
4514 | + uint32_t aArity); |
4515 | + |
4516 | + function_item_expr* create_function_item_expr( |
4517 | + static_context* sctx, |
4518 | + const QueryLoc& loc); |
4519 | + |
4520 | + ftcontains_expr* create_ftcontains_expr( |
4521 | + static_context*, |
4522 | + QueryLoc const&, |
4523 | + expr_t range, |
4524 | + ftnode *ftselection, |
4525 | + expr_t ftignore); |
4526 | + |
4527 | +//////////////////////////////////////////////////////////////////////////////// |
4528 | + |
4529 | + //this calls the static create_seq within fo_expr |
4530 | + fo_expr* create_seq(static_context* sctx, const QueryLoc &); |
4531 | + |
4532 | + fo_expr* create_fo_expr( |
4533 | + static_context* sctx, |
4534 | + const QueryLoc& loc, |
4535 | + const function* f, |
4536 | + const expr* arg); |
4537 | + |
4538 | + fo_expr* create_fo_expr( |
4539 | + static_context* sctx, |
4540 | + const QueryLoc& loc, |
4541 | + const function* f, |
4542 | + const expr* arg1, |
4543 | + const expr* arg2); |
4544 | + |
4545 | + fo_expr* create_fo_expr( |
4546 | + static_context* sctx, |
4547 | + const QueryLoc& loc, |
4548 | + const function* f, |
4549 | + const std::vector<expr_t>& args); |
4550 | + |
4551 | + fo_expr* create_fo_expr( |
4552 | + static_context* sctx, |
4553 | + const QueryLoc& loc, |
4554 | + const function* f); |
4555 | + |
4556 | +//////////////////////////////////////////////////////////////////////////////// |
4557 | + |
4558 | + for_clause* create_for_clause( |
4559 | + static_context* sctx, |
4560 | + const QueryLoc& loc, |
4561 | + var_expr_t varExpr, |
4562 | + expr_t domainExpr, |
4563 | + var_expr_t posVarExpr = NULL, |
4564 | + var_expr_t scoreVarExpr = NULL, |
4565 | + bool isOuter = false); |
4566 | + |
4567 | + let_clause* create_let_clause( |
4568 | + static_context* sctx, |
4569 | + const QueryLoc& loc, |
4570 | + var_expr_t varExpr, |
4571 | + expr_t domainExpr, |
4572 | + bool lazy = false); |
4573 | + |
4574 | + window_clause* create_window_clause( |
4575 | + static_context* sctx, |
4576 | + const QueryLoc& loc, |
4577 | + window_clause::window_t winKind, |
4578 | + var_expr_t varExpr, |
4579 | + expr_t domainExpr, |
4580 | + flwor_wincond_t winStart, |
4581 | + flwor_wincond_t winStop, |
4582 | + bool lazy = false); |
4583 | + |
4584 | + flwor_wincond* create_flwor_wincond( |
4585 | + static_context* sctx, |
4586 | + bool isOnly, |
4587 | + const flwor_wincond::vars& in_vars, |
4588 | + const flwor_wincond::vars& out_vars, |
4589 | + expr_t cond); |
4590 | + |
4591 | + group_clause* create_group_clause( |
4592 | + static_context* sctx, |
4593 | + const QueryLoc& loc, |
4594 | + const flwor_clause::rebind_list_t& gvars, |
4595 | + flwor_clause::rebind_list_t ngvars, |
4596 | + const std::vector<std::string>& collations); |
4597 | + |
4598 | + orderby_clause * create_orderby_clause ( |
4599 | + static_context* sctx, |
4600 | + const QueryLoc& loc, |
4601 | + bool stable, |
4602 | + const std::vector<OrderModifier>& modifiers, |
4603 | + const std::vector<expr_t>& orderingExprs); |
4604 | + |
4605 | + materialize_clause* create_materialize_clause( |
4606 | + static_context* sctx, |
4607 | + const QueryLoc& loc); |
4608 | + |
4609 | + count_clause* create_count_clause( |
4610 | + static_context* sctx, |
4611 | + const QueryLoc& loc, |
4612 | + var_expr_t var); |
4613 | + |
4614 | + where_clause* create_where_clause( |
4615 | + static_context* sctx, |
4616 | + const QueryLoc& loc, |
4617 | + expr_t where); |
4618 | + |
4619 | + flwor_expr* create_flwor_expr( |
4620 | + static_context* sctx, |
4621 | + const QueryLoc& loc, |
4622 | + bool general); |
4623 | +}; |
4624 | + |
4625 | +//////////////////////////////////////////////////////////////////////////////// |
4626 | + |
4627 | +#ifdef ZORBA_WITH_JSON |
4628 | + |
4629 | +json_array_expr* create_json_array_expr( |
4630 | + static_context* sctx, |
4631 | + const QueryLoc& loc, |
4632 | + const expr_t& content); |
4633 | + |
4634 | +json_object_expr* create_json_object_expr( |
4635 | + static_context* sctx, |
4636 | + const QueryLoc& loc, |
4637 | + const expr_t& content, |
4638 | + bool accumulate); |
4639 | + |
4640 | +json_direct_object_expr* create_json_direct_object_expr( |
4641 | + static_context* sctx, |
4642 | + const QueryLoc& loc, |
4643 | + std::vector<expr_t>& names, |
4644 | + std::vector<expr_t>& values); |
4645 | + |
4646 | +#endif |
4647 | + |
4648 | +} // namespace zorba |
4649 | + |
4650 | +#endif // ZORBA_COMPILER_EXPRMANAGER_H |
4651 | |
4652 | === modified file 'src/compiler/expression/flwor_expr.cpp' |
4653 | --- src/compiler/expression/flwor_expr.cpp 2012-07-24 08:48:48 +0000 |
4654 | +++ src/compiler/expression/flwor_expr.cpp 2012-08-10 11:20:27 +0000 |
4655 | @@ -26,6 +26,8 @@ |
4656 | #include "compiler/expression/expr.h" |
4657 | #include "compiler/expression/expr_visitor.h" |
4658 | |
4659 | +#include "compiler/api/compilercb.h" |
4660 | + |
4661 | #include "types/root_typemanager.h" |
4662 | #include "types/typeops.h" |
4663 | |
4664 | @@ -44,6 +46,7 @@ |
4665 | ********************************************************************************/ |
4666 | forletwin_clause::forletwin_clause( |
4667 | static_context* sctx, |
4668 | + CompilerCB* ccb, |
4669 | const QueryLoc& loc, |
4670 | flwor_clause::ClauseKind kind, |
4671 | var_expr_t varExpr, |
4672 | @@ -51,7 +54,8 @@ |
4673 | : |
4674 | flwor_clause(sctx, loc, kind), |
4675 | theVarExpr(varExpr), |
4676 | - theDomainExpr(domainExpr) |
4677 | + theDomainExpr(domainExpr), |
4678 | + theCCB(ccb) |
4679 | { |
4680 | if (theVarExpr != NULL) |
4681 | theVarExpr->set_flwor_clause(this); |
4682 | @@ -87,6 +91,7 @@ |
4683 | ********************************************************************************/ |
4684 | for_clause::for_clause( |
4685 | static_context* sctx, |
4686 | + CompilerCB* ccb, |
4687 | const QueryLoc& loc, |
4688 | var_expr_t varExpr, |
4689 | expr_t domainExpr, |
4690 | @@ -94,7 +99,7 @@ |
4691 | var_expr_t scoreVarExpr, |
4692 | bool isAllowingEmpty) |
4693 | : |
4694 | - forletwin_clause(sctx, loc, flwor_clause::for_clause, varExpr, domainExpr), |
4695 | + forletwin_clause(sctx, ccb, loc, flwor_clause::for_clause, varExpr, domainExpr), |
4696 | thePosVarExpr(posVarExpr), |
4697 | theScoreVarExpr(scoreVarExpr), |
4698 | theAllowingEmpty(isAllowingEmpty) |
4699 | @@ -137,11 +142,11 @@ |
4700 | *declaredType)); |
4701 | } |
4702 | |
4703 | - domainExpr = new treat_expr(sctx, |
4704 | - loc, |
4705 | - domainExpr, |
4706 | - declaredType, |
4707 | - TreatIterator::TYPE_MATCH); |
4708 | + domainExpr = theCCB->theEM->create_treat_expr(sctx, |
4709 | + loc, |
4710 | + domainExpr, |
4711 | + declaredType, |
4712 | + TreatIterator::TYPE_MATCH); |
4713 | |
4714 | set_expr(domainExpr); |
4715 | } |
4716 | @@ -193,14 +198,14 @@ |
4717 | { |
4718 | expr_t domainCopy = theDomainExpr->clone(subst); |
4719 | |
4720 | - var_expr_t varCopy(new var_expr(*theVarExpr)); |
4721 | + var_expr_t varCopy = theCCB->theEM->create_var_expr(*theVarExpr); |
4722 | subst[theVarExpr.getp()] = varCopy.getp(); |
4723 | |
4724 | var_expr_t posvarCopy; |
4725 | var_expr* pos_var_ptr = thePosVarExpr.getp(); |
4726 | if (pos_var_ptr) |
4727 | { |
4728 | - posvarCopy = new var_expr(*pos_var_ptr); |
4729 | + posvarCopy = theCCB->theEM->create_var_expr(*pos_var_ptr); |
4730 | subst[pos_var_ptr] = posvarCopy.getp(); |
4731 | } |
4732 | |
4733 | @@ -208,11 +213,12 @@ |
4734 | var_expr* score_var_ptr = theScoreVarExpr.getp(); |
4735 | if (score_var_ptr) |
4736 | { |
4737 | - scorevarCopy = new var_expr(*score_var_ptr); |
4738 | + scorevarCopy = theCCB->theEM->create_var_expr(*score_var_ptr); |
4739 | subst[score_var_ptr] = scorevarCopy.getp(); |
4740 | } |
4741 | |
4742 | return new for_clause(theContext, |
4743 | + theCCB, |
4744 | get_loc(), |
4745 | varCopy, |
4746 | domainCopy, |
4747 | @@ -227,12 +233,13 @@ |
4748 | ********************************************************************************/ |
4749 | let_clause::let_clause( |
4750 | static_context* sctx, |
4751 | + CompilerCB* ccb, |
4752 | const QueryLoc& loc, |
4753 | var_expr_t varExpr, |
4754 | expr_t domainExpr, |
4755 | bool lazy) |
4756 | : |
4757 | - forletwin_clause(sctx, loc, flwor_clause::let_clause, varExpr, domainExpr), |
4758 | + forletwin_clause(sctx, ccb, loc, flwor_clause::let_clause, varExpr, domainExpr), |
4759 | theScoreVarExpr(NULL), |
4760 | theLazyEval(lazy) |
4761 | { |
4762 | @@ -259,7 +266,7 @@ |
4763 | ERROR_PARAMS(ZED(BadType_23o), *domainType, ZED(NoTreatAs_4), *declaredType)); |
4764 | } |
4765 | |
4766 | - domainExpr = new treat_expr(sctx, |
4767 | + domainExpr = theCCB->theEM->create_treat_expr(sctx, |
4768 | loc, |
4769 | domainExpr, |
4770 | declaredType, |
4771 | @@ -297,7 +304,7 @@ |
4772 | { |
4773 | expr_t domainCopy = theDomainExpr->clone(subst); |
4774 | |
4775 | - var_expr_t varCopy(new var_expr(*theVarExpr)); |
4776 | + var_expr_t varCopy = theCCB->theEM->create_var_expr(*theVarExpr); |
4777 | subst[theVarExpr.getp()] = varCopy.getp(); |
4778 | |
4779 | #if 0 |
4780 | @@ -310,7 +317,12 @@ |
4781 | } |
4782 | #endif |
4783 | |
4784 | - return new let_clause(theContext, get_loc(), varCopy, domainCopy, theLazyEval); |
4785 | + return new let_clause(theContext, |
4786 | + theCCB, |
4787 | + get_loc(), |
4788 | + varCopy, |
4789 | + domainCopy, |
4790 | + theLazyEval); |
4791 | } |
4792 | |
4793 | |
4794 | @@ -320,6 +332,7 @@ |
4795 | ********************************************************************************/ |
4796 | window_clause::window_clause( |
4797 | static_context* sctx, |
4798 | + CompilerCB* ccb, |
4799 | const QueryLoc& loc, |
4800 | window_t winKind, |
4801 | var_expr_t varExpr, |
4802 | @@ -328,7 +341,7 @@ |
4803 | flwor_wincond_t winStop, |
4804 | bool lazy) |
4805 | : |
4806 | - forletwin_clause(sctx, loc, flwor_clause::window_clause, varExpr, domainExpr), |
4807 | + forletwin_clause(sctx, ccb, loc, flwor_clause::window_clause, varExpr, domainExpr), |
4808 | theWindowKind(winKind), |
4809 | theWinStartCond(winStart), |
4810 | theWinStopCond(winStop), |
4811 | @@ -356,7 +369,7 @@ |
4812 | if (!TypeOps::is_subtype(tm, *rtm.ITEM_TYPE_STAR, *varType, loc) && |
4813 | !TypeOps::is_subtype(tm, *domainType, *varType, loc)) |
4814 | { |
4815 | - domainExpr = new treat_expr(sctx, |
4816 | + domainExpr = theCCB->theEM->create_treat_expr(sctx, |
4817 | loc, |
4818 | domainExpr, |
4819 | varType, |
4820 | @@ -399,7 +412,7 @@ |
4821 | { |
4822 | expr_t domainCopy = theDomainExpr->clone(subst); |
4823 | |
4824 | - var_expr_t varCopy(new var_expr(*theVarExpr)); |
4825 | + var_expr_t varCopy = theCCB->theEM->create_var_expr(*theVarExpr); |
4826 | subst[theVarExpr.getp()] = varCopy.getp(); |
4827 | |
4828 | flwor_wincond_t cloneStartCond; |
4829 | @@ -412,6 +425,7 @@ |
4830 | cloneStopCond = theWinStopCond->clone(subst); |
4831 | |
4832 | return new window_clause(theContext, |
4833 | + theCCB, |
4834 | get_loc(), |
4835 | theWindowKind, |
4836 | varCopy, |
4837 | @@ -426,6 +440,7 @@ |
4838 | |
4839 | ********************************************************************************/ |
4840 | flwor_wincond::flwor_wincond( |
4841 | + CompilerCB* ccb, |
4842 | static_context* sctx, |
4843 | bool isOnly, |
4844 | const vars& in_vars, |
4845 | @@ -435,7 +450,8 @@ |
4846 | theIsOnly(isOnly), |
4847 | theInputVars(in_vars), |
4848 | theOutputVars(out_vars), |
4849 | - theCondExpr(cond) |
4850 | + theCondExpr(cond), |
4851 | + theCCB(ccb) |
4852 | { |
4853 | expr::checkSimpleExpr(theCondExpr); |
4854 | |
4855 | @@ -450,7 +466,7 @@ |
4856 | *GENV_TYPESYSTEM.BOOLEAN_TYPE_ONE, |
4857 | theCondExpr->get_loc())) |
4858 | { |
4859 | - theCondExpr = new fo_expr(theCondExpr->get_sctx(), |
4860 | + theCondExpr = theCCB->theEM->create_fo_expr(theCondExpr->get_sctx(), |
4861 | theCondExpr->get_loc(), |
4862 | GET_BUILTIN_FUNCTION(FN_BOOLEAN_1), |
4863 | theCondExpr); |
4864 | @@ -485,33 +501,34 @@ |
4865 | |
4866 | |
4867 | void flwor_wincond::vars::clone( |
4868 | + ExprManager* mgr, |
4869 | flwor_wincond::vars& cloneVars, |
4870 | expr::substitution_t& subst) const |
4871 | { |
4872 | if (posvar != NULL) |
4873 | { |
4874 | - var_expr_t varCopy(new var_expr(*posvar)); |
4875 | + var_expr_t varCopy = mgr->create_var_expr(*posvar); |
4876 | subst[posvar.getp()] = varCopy.getp(); |
4877 | cloneVars.posvar = varCopy; |
4878 | } |
4879 | |
4880 | if (curr != NULL) |
4881 | { |
4882 | - var_expr_t varCopy(new var_expr(*curr)); |
4883 | + var_expr_t varCopy = mgr->create_var_expr(*curr); |
4884 | subst[curr.getp()] = varCopy.getp(); |
4885 | cloneVars.curr = varCopy; |
4886 | } |
4887 | |
4888 | if (prev != NULL) |
4889 | { |
4890 | - var_expr_t varCopy(new var_expr(*prev)); |
4891 | + var_expr_t varCopy = mgr->create_var_expr(*prev); |
4892 | subst[prev.getp()] = varCopy.getp(); |
4893 | cloneVars.prev = varCopy; |
4894 | } |
4895 | |
4896 | if (next != NULL) |
4897 | { |
4898 | - var_expr_t varCopy(new var_expr(*next)); |
4899 | + var_expr_t varCopy = mgr->create_var_expr(*next); |
4900 | subst[next.getp()] = varCopy.getp(); |
4901 | cloneVars.next = varCopy; |
4902 | } |
4903 | @@ -530,12 +547,17 @@ |
4904 | flwor_wincond::vars cloneInVars; |
4905 | flwor_wincond::vars cloneOutVars; |
4906 | |
4907 | - theInputVars.clone(cloneInVars, subst); |
4908 | - theOutputVars.clone(cloneOutVars, subst); |
4909 | + theInputVars.clone(theCCB->theEM, cloneInVars, subst); |
4910 | + theOutputVars.clone(theCCB->theEM, cloneOutVars, subst); |
4911 | |
4912 | expr_t cloneCondExpr = theCondExpr->clone(subst); |
4913 | |
4914 | - return new flwor_wincond(NULL, theIsOnly, cloneInVars, cloneOutVars, cloneCondExpr); |
4915 | + return new flwor_wincond(theCCB, |
4916 | + NULL, |
4917 | + theIsOnly, |
4918 | + cloneInVars, |
4919 | + cloneOutVars, |
4920 | + cloneCondExpr); |
4921 | } |
4922 | |
4923 | |
4924 | @@ -612,17 +634,24 @@ |
4925 | rebind_list_t cloneGroupVars(numGroupVars); |
4926 | rebind_list_t cloneNonGroupVars(numNonGroupVars); |
4927 | |
4928 | + ExprManager* exprMgr = NULL; |
4929 | + |
4930 | + if (numGroupVars > 0) |
4931 | + exprMgr = theGroupVars[0].first->get_ccb()->theEM; |
4932 | + else if (numNonGroupVars > 0) |
4933 | + exprMgr = theNonGroupVars[0].first->get_ccb()->theEM; |
4934 | + |
4935 | for (csize i = 0; i < numGroupVars; ++i) |
4936 | { |
4937 | cloneGroupVars[i].first = theGroupVars[i].first->clone(subst); |
4938 | - cloneGroupVars[i].second = new var_expr(*theGroupVars[i].second); |
4939 | + cloneGroupVars[i].second = exprMgr->create_var_expr(*theGroupVars[i].second); |
4940 | subst[theGroupVars[i].second.getp()] = cloneGroupVars[i].second.getp(); |
4941 | } |
4942 | |
4943 | for (csize i = 0; i < numNonGroupVars; ++i) |
4944 | { |
4945 | cloneNonGroupVars[i].first = theNonGroupVars[i].first->clone(subst); |
4946 | - cloneNonGroupVars[i].second = new var_expr(*theNonGroupVars[i].second); |
4947 | + cloneNonGroupVars[i].second = exprMgr->create_var_expr(*theNonGroupVars[i].second); |
4948 | subst[theNonGroupVars[i].second.getp()] = cloneNonGroupVars[i].second.getp(); |
4949 | } |
4950 | |
4951 | @@ -722,7 +751,9 @@ |
4952 | |
4953 | flwor_clause_t count_clause::clone(expr::substitution_t& subst) const |
4954 | { |
4955 | - var_expr_t cloneVar = new var_expr(*theVarExpr); |
4956 | + ExprManager* exprMgr = theVarExpr->get_ccb()->theEM; |
4957 | + |
4958 | + var_expr_t cloneVar = exprMgr->create_var_expr(*theVarExpr); |
4959 | subst[theVarExpr.getp()] = cloneVar; |
4960 | |
4961 | return new count_clause(theContext, get_loc(), cloneVar); |
4962 | @@ -758,9 +789,9 @@ |
4963 | /******************************************************************************* |
4964 | |
4965 | ********************************************************************************/ |
4966 | -flwor_expr::flwor_expr(static_context* sctx, const QueryLoc& loc, bool general) |
4967 | +flwor_expr::flwor_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc& loc, bool general) |
4968 | : |
4969 | - expr(sctx, loc, (general ? gflwor_expr_kind : flwor_expr_kind)), |
4970 | + expr(ccb, sctx, loc, (general ? gflwor_expr_kind : flwor_expr_kind)), |
4971 | theIsGeneral(general), |
4972 | theHasSequentialClauses(false) |
4973 | { |
4974 | @@ -1045,7 +1076,7 @@ |
4975 | if (k == flwor_clause::for_clause || |
4976 | k == flwor_clause::let_clause || |
4977 | k == flwor_clause::window_clause) |
4978 | - { |
4979 | + { |
4980 | const forletwin_clause* c2 = static_cast<const forletwin_clause*>(c); |
4981 | |
4982 | theScriptingKind |= c2->get_expr()->get_scripting_detail(); |
4983 | @@ -1090,7 +1121,7 @@ |
4984 | { |
4985 | ulong numClauses = num_clauses(); |
4986 | |
4987 | - flwor_expr_t cloneFlwor = new flwor_expr(theSctx, get_loc(), theIsGeneral); |
4988 | + flwor_expr_t cloneFlwor = theCCB->theEM->create_flwor_expr(theSctx, get_loc(), theIsGeneral); |
4989 | |
4990 | for (ulong i = 0; i < numClauses; ++i) |
4991 | { |
4992 | |
4993 | === modified file 'src/compiler/expression/flwor_expr.h' |
4994 | --- src/compiler/expression/flwor_expr.h 2012-07-24 08:48:48 +0000 |
4995 | +++ src/compiler/expression/flwor_expr.h 2012-08-10 11:20:27 +0000 |
4996 | @@ -23,10 +23,11 @@ |
4997 | #include "compiler/expression/var_expr.h" |
4998 | #include "compiler/expression/expr_utils.h" |
4999 | |
5000 | - |
The diff has been truncated for viewing.