Merge lp:~zorba-coders/zorba/collection-counting into lp:zorba

Proposed by Markos Zaharioudakis
Status: Merged
Approved by: Markos Zaharioudakis
Approved revision: 10496
Merged at revision: 10522
Proposed branch: lp:~zorba-coders/zorba/collection-counting
Merge into: lp:zorba
Diff against target: 3342 lines (+882/-405)
29 files modified
ChangeLog (+1/-0)
src/context/default_url_resolvers.cpp (+6/-0)
src/functions/func_sequences_impl.cpp (+100/-46)
src/functions/function_impl.h (+4/-4)
src/functions/pregenerated/func_sequences.cpp (+0/-9)
src/runtime/base/binarybase.h (+19/-9)
src/runtime/base/narybase.h (+16/-11)
src/runtime/base/plan_iterator.h (+60/-60)
src/runtime/base/unarybase.h (+15/-10)
src/runtime/collections/collections_base.h (+16/-16)
src/runtime/collections/collections_impl.cpp (+244/-88)
src/runtime/collections/collections_impl.h (+78/-0)
src/runtime/collections/pregenerated/collections.h (+2/-0)
src/runtime/sequences/pregenerated/sequences.h (+23/-23)
src/runtime/spec/collections/collections.xml (+9/-8)
src/runtime/spec/sequences/sequences.xml (+112/-112)
src/runtime/visitors/planiter_visitor_impl_code.h (+2/-0)
src/runtime/visitors/planiter_visitor_impl_include.h (+2/-0)
src/runtime/visitors/printer_visitor_impl.cpp (+12/-9)
src/runtime/visitors/printer_visitor_impl.h (+2/-0)
test/rbkt/ExpCompilerResults/IterPlan/zorba/collections/count_dynamic_zorba_collection.iter (+25/-0)
test/rbkt/ExpCompilerResults/IterPlan/zorba/collections/count_static_zorba_collection.iter (+61/-0)
test/rbkt/ExpCompilerResults/IterPlan/zorba/collections/count_w3c_collection.iter (+35/-0)
test/rbkt/ExpQueryResults/zorba/collections/count_dynamic_zorba_collection.xml.res (+2/-0)
test/rbkt/ExpQueryResults/zorba/collections/count_static_zorba_collection.xml.res (+2/-0)
test/rbkt/ExpQueryResults/zorba/collections/count_w3c_collection.xml.res (+2/-0)
test/rbkt/Queries/zorba/collections/count_dynamic_zorba_collection.xq (+10/-0)
test/rbkt/Queries/zorba/collections/count_static_zorba_collection.xq (+14/-0)
test/rbkt/Queries/zorba/collections/count_w3c_collection.xq (+8/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/collection-counting
Reviewer Review Type Date Requested Status
Markos Zaharioudakis Approve
Matthias Brantner Approve
Review via email: mp+79765@code.launchpad.net

Commit message

Optimization for count(collection("foo")) expression

To post a comment you must log in.
Revision history for this message
Matthias Brantner (matthias-brantner) wrote :

Why do all the generate files show up as changed?

review: Needs Information
Revision history for this message
Chris Hillery (ceejatec) wrote :

> Why do all the generate files show up as changed?

That's showing up as a problem on one of Rodolfo's branches also. I assume it's line-ending problems but I can't imagine how it's happening.

Revision history for this message
Markos Zaharioudakis (markos-za) wrote :

Carlos, let's try to finis this today and commit to the main trunk. So, please add a test for w3c collections, and also update the ChangeLog file with a one-line description of the change.

Revision history for this message
Matthias Brantner (matthias-brantner) wrote :

One question: Why is the iterator not generated using the runtime code generation?

Revision history for this message
Markos Zaharioudakis (markos-za) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Attempt to merge into lp:zorba failed due to conflicts:

text conflict in ChangeLog

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
Markos Zaharioudakis (markos-za) :
review: Approve
Revision history for this message
Markos Zaharioudakis (markos-za) :
review: Approve
Revision history for this message
Markos Zaharioudakis (markos-za) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/collection-counting into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:272 (message):
  Validation queue job collection-counting-2011-10-20T23-16-14.372Z is
  finished. The final status was:

  3 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

10496. By Markos Zaharioudakis

fixed failing iter tests

Revision history for this message
Markos Zaharioudakis (markos-za) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job collection-counting-2011-10-21T00-49-13.645Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2011-10-17 21:30:33 +0000
3+++ ChangeLog 2011-10-21 00:32:19 +0000
4@@ -50,6 +50,7 @@
5 different nodes cannot have the same identifier.
6 * Fixed bug #872697 (segmentation fault with validation of NMTOKENS)
7 * Added undo for node revalidation
8+ * Optimization for count(collection()) expressions
9 * Fixed bug #872796 (validate-in-place can interfere with other update primitives)
10 * Fixed bug #872799 (validate-in-place can set incorrect types)
11 * Fixed bug #855715 (Invalid escaped characters in regex not caught)
12
13=== modified file 'src/context/default_url_resolvers.cpp'
14--- src/context/default_url_resolvers.cpp 2011-08-20 01:30:48 +0000
15+++ src/context/default_url_resolvers.cpp 2011-10-21 00:32:19 +0000
16@@ -41,6 +41,9 @@
17 HTTPURLResolver::resolveURL
18 (zstring const& aUrl, EntityData const* aEntityData)
19 {
20+ if (aEntityData->getKind() == impl::EntityData::COLLECTION)
21+ return NULL;
22+
23 uri::scheme lScheme = uri::get_scheme(aUrl);
24 switch (lScheme) {
25 case uri::http:
26@@ -79,6 +82,9 @@
27 FileURLResolver::resolveURL
28 (zstring const& aUrl, EntityData const* aEntityData)
29 {
30+ if (aEntityData->getKind() == impl::EntityData::COLLECTION)
31+ return NULL;
32+
33 uri::scheme lScheme = uri::get_scheme(aUrl);
34 if (lScheme != uri::file) {
35 return NULL;
36
37=== modified file 'src/functions/func_sequences_impl.cpp'
38--- src/functions/func_sequences_impl.cpp 2011-06-14 17:26:33 +0000
39+++ src/functions/func_sequences_impl.cpp 2011-10-21 00:32:19 +0000
40@@ -15,6 +15,8 @@
41 */
42 #include "stdafx.h"
43
44+#include <typeinfo>
45+
46 #include "functions/func_sequences.h"
47 #include "functions/func_sequences_impl.h"
48
49@@ -22,6 +24,9 @@
50 #include "runtime/sequences/SequencesImpl.h"
51 #include "runtime/core/var_iterators.h"
52
53+#include "runtime/collections/collections_impl.h"
54+#include "runtime/collections/collections.h"
55+
56 #include "system/globalenv.h"
57
58 #include "compiler/expression/expr.h"
59@@ -30,7 +35,7 @@
60
61 #include "types/typeops.h"
62
63-namespace zorba
64+namespace zorba
65 {
66
67
68@@ -39,7 +44,7 @@
69 ********************************************************************************/
70 xqtref_t op_concatenate::getReturnType(
71 const TypeManager* tm,
72- const std::vector<xqtref_t>& arg_types) const
73+ const std::vector<xqtref_t>& arg_types) const
74 {
75 ulong sz = (ulong)arg_types.size();
76
77@@ -47,11 +52,11 @@
78 {
79 return GENV_TYPESYSTEM.EMPTY_TYPE;
80 }
81- else
82+ else
83 {
84 xqtref_t t = arg_types[0];
85 TypeConstants::quantifier_t q = TypeConstants::QUANT_STAR;
86- for (ulong i = 1; i < sz; i++)
87+ for (ulong i = 1; i < sz; i++)
88 {
89 t = TypeOps::union_type(*t, *arg_types[i], tm);
90 TypeConstants::quantifier_t pq = TypeOps::quantifier(*t);
91@@ -65,14 +70,14 @@
92 }
93 }
94
95-
96-BoolAnnotationValue op_concatenate::ignoresSortedNodes(expr* fo, ulong input) const
97+
98+BoolAnnotationValue op_concatenate::ignoresSortedNodes(expr* fo, ulong input) const
99 {
100 return fo->getIgnoresSortedNodes();
101 }
102
103
104-BoolAnnotationValue op_concatenate::ignoresDuplicateNodes(expr* fo, ulong input) const
105+BoolAnnotationValue op_concatenate::ignoresDuplicateNodes(expr* fo, ulong input) const
106 {
107 return fo->getIgnoresDuplicateNodes();
108 }
109@@ -81,13 +86,13 @@
110 /*******************************************************************************
111
112 ********************************************************************************/
113-BoolAnnotationValue fn_empty::ignoresSortedNodes(expr* fo, ulong input) const
114+BoolAnnotationValue fn_empty::ignoresSortedNodes(expr* fo, ulong input) const
115 {
116 return ANNOTATION_TRUE;
117 }
118
119
120-BoolAnnotationValue fn_empty::ignoresDuplicateNodes(expr* fo, ulong input) const
121+BoolAnnotationValue fn_empty::ignoresDuplicateNodes(expr* fo, ulong input) const
122 {
123 return ANNOTATION_TRUE;
124 }
125@@ -96,13 +101,13 @@
126 /*******************************************************************************
127
128 ********************************************************************************/
129-BoolAnnotationValue fn_exists::ignoresSortedNodes(expr* fo, ulong input) const
130+BoolAnnotationValue fn_exists::ignoresSortedNodes(expr* fo, ulong input) const
131 {
132 return ANNOTATION_TRUE;
133 }
134
135
136-BoolAnnotationValue fn_exists::ignoresDuplicateNodes(expr* fo, ulong input) const
137+BoolAnnotationValue fn_exists::ignoresDuplicateNodes(expr* fo, ulong input) const
138 {
139 return ANNOTATION_TRUE;
140 }
141@@ -120,8 +125,8 @@
142
143
144 BoolAnnotationValue fn_distinct_values::ignoresSortedNodes(
145- expr* fo,
146- ulong input) const
147+ expr* fo,
148+ ulong input) const
149 {
150 if (input == 0)
151 return fo->getIgnoresSortedNodes();
152@@ -132,7 +137,7 @@
153
154 BoolAnnotationValue fn_distinct_values::ignoresDuplicateNodes(
155 expr* fo,
156- ulong input) const
157+ ulong input) const
158 {
159 if (input == 0)
160 return ANNOTATION_TRUE;
161@@ -146,7 +151,7 @@
162 ********************************************************************************/
163 BoolAnnotationValue fn_insert_before::ignoresSortedNodes(
164 expr* fo,
165- ulong input) const
166+ ulong input) const
167 {
168 if (input == 0 || input == 2)
169 return fo->getIgnoresSortedNodes();
170@@ -157,7 +162,7 @@
171
172 BoolAnnotationValue fn_insert_before::ignoresDuplicateNodes(
173 expr* fo,
174- ulong input) const
175+ ulong input) const
176 {
177 if (input == 0 || input == 2)
178 return fo->getIgnoresSortedNodes();
179@@ -179,7 +184,7 @@
180
181 BoolAnnotationValue fn_remove::ignoresSortedNodes(
182 expr* fo,
183- ulong input) const
184+ ulong input) const
185 {
186 if (input == 0)
187 return ANNOTATION_FALSE;
188@@ -190,7 +195,7 @@
189
190 BoolAnnotationValue fn_remove::ignoresDuplicateNodes(
191 expr* fo,
192- ulong input) const
193+ ulong input) const
194 {
195 return ANNOTATION_FALSE;
196 }
197@@ -209,7 +214,7 @@
198
199 BoolAnnotationValue fn_reverse::ignoresSortedNodes(
200 expr* fo,
201- ulong input) const
202+ ulong input) const
203 {
204 return fo->getIgnoresSortedNodes();
205 }
206@@ -217,7 +222,7 @@
207
208 BoolAnnotationValue fn_reverse::ignoresDuplicateNodes(
209 expr* fo,
210- ulong input) const
211+ ulong input) const
212 {
213 return fo->getIgnoresSortedNodes();
214 }
215@@ -250,7 +255,7 @@
216 const expr* lenExpr = (subseqExpr.num_args() > 2 ? subseqExpr.get_arg(2) : NULL);
217
218 if (inputExpr->get_expr_kind() == relpath_expr_kind &&
219- posExpr->get_expr_kind() == const_expr_kind &&
220+ posExpr->get_expr_kind() == const_expr_kind &&
221 lenExpr != NULL &&
222 lenExpr->get_expr_kind() == const_expr_kind)
223 {
224@@ -281,6 +286,55 @@
225
226
227 /******************************************************************************
228+fn:count
229+*******************************************************************************/
230+PlanIter_t fn_count::codegen(
231+ CompilerCB*,
232+ static_context* sctx,
233+ const QueryLoc& loc,
234+ std::vector<PlanIter_t>& argv,
235+ AnnotationHolder& ann) const
236+{
237+ const std::type_info& counted_type = typeid(*argv[0]);
238+
239+ if (typeid(ZorbaCollectionIterator) == counted_type)
240+ {
241+ ZorbaCollectionIterator& collection =
242+ static_cast<ZorbaCollectionIterator&>(*argv[0]);
243+
244+ if (collection.isDynamic())
245+ {
246+ return new CountCollectionIterator(sctx,
247+ loc,
248+ collection.getChildren(),
249+ CountCollectionIterator::ZORBADYNAMIC);
250+ }
251+ else
252+ {
253+ return new CountCollectionIterator(sctx,
254+ loc,
255+ collection.getChildren(),
256+ CountCollectionIterator::ZORBASTATIC);
257+ }
258+ }
259+ else if (typeid(FnCollectionIterator) == counted_type)
260+ {
261+ FnCollectionIterator& collection =
262+ static_cast<FnCollectionIterator&>(*argv[0]);
263+
264+ return new CountCollectionIterator(sctx,
265+ loc,
266+ collection.getChildren(),
267+ CountCollectionIterator::W3C);
268+ }
269+ else
270+ {
271+ return new FnCountIterator(sctx, loc, argv);
272+ }
273+}
274+
275+
276+/******************************************************************************
277
278 *******************************************************************************/
279 xqtref_t op_zorba_subsequence_int::getReturnType(
280@@ -310,7 +364,7 @@
281 CtxVarIterator* ctxVarIter;
282
283 if (inputExpr->get_expr_kind() == relpath_expr_kind &&
284- posExpr->get_expr_kind() == const_expr_kind &&
285+ posExpr->get_expr_kind() == const_expr_kind &&
286 lenExpr != NULL &&
287 lenExpr->get_expr_kind() == const_expr_kind)
288 {
289@@ -402,14 +456,14 @@
290 if (inputExpr->get_expr_kind() == relpath_expr_kind)
291 {
292 const relpath_expr* pathExpr = static_cast<const relpath_expr*>(inputExpr);
293-
294+
295 ulong numSteps = pathExpr->numSteps();
296
297 if (pos > 0 && numSteps == 2)
298 {
299 AxisIteratorHelper* input = dynamic_cast<AxisIteratorHelper*>(aArgs[0].getp());
300 assert(input != NULL);
301-
302+
303 if (input->setTargetPos(pos-1))
304 return aArgs[0];
305 }
306@@ -436,7 +490,7 @@
307 else if ((inputVarIter = dynamic_cast<LetVarIterator*>(aArgs[0].getp())) != NULL)
308 {
309 const var_expr* inputVar = inputExpr->get_var();
310-
311+
312 if (inputVar != NULL &&
313 (inputVar->get_kind() == var_expr::let_var ||
314 inputVar->get_kind() == var_expr::win_var ||
315@@ -496,7 +550,7 @@
316 }
317
318
319-BoolAnnotationValue fn_zero_or_one::ignoresSortedNodes(expr* fo, ulong input) const
320+BoolAnnotationValue fn_zero_or_one::ignoresSortedNodes(expr* fo, ulong input) const
321 {
322 return ANNOTATION_TRUE;
323 }
324@@ -528,13 +582,13 @@
325 }
326
327
328-BoolAnnotationValue fn_one_or_more::ignoresSortedNodes(expr* fo, ulong input) const
329+BoolAnnotationValue fn_one_or_more::ignoresSortedNodes(expr* fo, ulong input) const
330 {
331 return fo->getIgnoresSortedNodes();
332 }
333
334
335-BoolAnnotationValue fn_one_or_more::ignoresDuplicateNodes(expr* fo, ulong input) const
336+BoolAnnotationValue fn_one_or_more::ignoresDuplicateNodes(expr* fo, ulong input) const
337 {
338 return fo->getIgnoresDuplicateNodes();
339 }
340@@ -589,7 +643,7 @@
341 PlanIter_t fn_intersect::codegen(
342 CompilerCB* /*cb*/,
343 static_context* sctx,
344- const QueryLoc& loc,
345+ const QueryLoc& loc,
346 std::vector<PlanIter_t>& argv,
347 AnnotationHolder& ann) const
348 {
349@@ -626,7 +680,7 @@
350 /*******************************************************************************
351
352 ********************************************************************************/
353-BoolAnnotationValue fn_count::ignoresSortedNodes(expr* fo, ulong input) const
354+BoolAnnotationValue fn_count::ignoresSortedNodes(expr* fo, ulong input) const
355 {
356 return ANNOTATION_TRUE;
357 }
358@@ -635,7 +689,7 @@
359 /*******************************************************************************
360
361 ********************************************************************************/
362-BoolAnnotationValue fn_avg::ignoresSortedNodes(expr* fo, ulong input) const
363+BoolAnnotationValue fn_avg::ignoresSortedNodes(expr* fo, ulong input) const
364 {
365 return ANNOTATION_TRUE;
366 }
367@@ -672,7 +726,7 @@
368 /*******************************************************************************
369
370 ********************************************************************************/
371-BoolAnnotationValue fn_sum::ignoresSortedNodes(expr* fo, ulong input) const
372+BoolAnnotationValue fn_sum::ignoresSortedNodes(expr* fo, ulong input) const
373 {
374 return ANNOTATION_TRUE;
375 }
376@@ -766,13 +820,13 @@
377 /*******************************************************************************
378
379 ********************************************************************************/
380-BoolAnnotationValue fn_id::ignoresSortedNodes(expr* fo, ulong input) const
381+BoolAnnotationValue fn_id::ignoresSortedNodes(expr* fo, ulong input) const
382 {
383 return ANNOTATION_TRUE;
384 }
385
386
387-BoolAnnotationValue fn_id::ignoresDuplicateNodes(expr* fo, ulong input) const
388+BoolAnnotationValue fn_id::ignoresDuplicateNodes(expr* fo, ulong input) const
389 {
390 if (input == 0)
391 return ANNOTATION_TRUE;
392@@ -786,7 +840,7 @@
393 ********************************************************************************/
394 BoolAnnotationValue fn_element_with_id::ignoresSortedNodes(
395 expr* fo,
396- ulong input) const
397+ ulong input) const
398 {
399 return ANNOTATION_TRUE;
400 }
401@@ -794,7 +848,7 @@
402
403 BoolAnnotationValue fn_element_with_id::ignoresDuplicateNodes(
404 expr* fo,
405- ulong input) const
406+ ulong input) const
407 {
408 if (input == 0)
409 return ANNOTATION_TRUE;
410@@ -806,13 +860,13 @@
411 /*******************************************************************************
412
413 ********************************************************************************/
414-BoolAnnotationValue fn_idref::ignoresSortedNodes(expr* fo, ulong input) const
415+BoolAnnotationValue fn_idref::ignoresSortedNodes(expr* fo, ulong input) const
416 {
417 return ANNOTATION_TRUE;
418 }
419
420
421-BoolAnnotationValue fn_idref::ignoresDuplicateNodes(expr* fo, ulong input) const
422+BoolAnnotationValue fn_idref::ignoresDuplicateNodes(expr* fo, ulong input) const
423 {
424 if (input == 0)
425 return ANNOTATION_TRUE;
426@@ -867,7 +921,7 @@
427
428 DECL(sctx, fn_exactly_one,
429 (createQName(fn_ns, "", "exactly-one"),
430- GENV_TYPESYSTEM.ITEM_TYPE_STAR,
431+ GENV_TYPESYSTEM.ITEM_TYPE_STAR,
432 GENV_TYPESYSTEM.ITEM_TYPE_ONE));
433
434 DECL(sctx, fn_exactly_one_noraise,
435@@ -895,9 +949,9 @@
436
437 DECL(sctx, fn_max,
438 (createQName(fn_ns,"","max"),
439- GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_STAR,
440+ GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_STAR,
441 GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_QUESTION));
442-
443+
444 DECL(sctx, fn_max,
445 (createQName(fn_ns,"","max"),
446 GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_STAR,
447@@ -906,23 +960,23 @@
448
449 DECL(sctx, fn_min,
450 (createQName(fn_ns,"","min"),
451- GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_STAR,
452+ GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_STAR,
453 GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_QUESTION));
454
455 DECL(sctx, fn_min,
456 (createQName(fn_ns,"","min"),
457- GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_STAR,
458- GENV_TYPESYSTEM.STRING_TYPE_ONE,
459+ GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_STAR,
460+ GENV_TYPESYSTEM.STRING_TYPE_ONE,
461 GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_QUESTION));
462
463 DECL(sctx, fn_head,
464 (createQName(fn_ns,"","head"),
465- GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_STAR,
466+ GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_STAR,
467 GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_QUESTION));
468
469 DECL(sctx, fn_tail,
470 (createQName(fn_ns,"","tail"),
471- GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_STAR,
472+ GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_STAR,
473 GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_STAR));
474
475 }
476
477=== modified file 'src/functions/function_impl.h'
478--- src/functions/function_impl.h 2011-06-14 17:26:33 +0000
479+++ src/functions/function_impl.h 2011-10-21 00:32:19 +0000
480@@ -1,12 +1,12 @@
481 /*
482 * Copyright 2006-2008 The FLWOR Foundation.
483- *
484+ *
485 * Licensed under the Apache License, Version 2.0 (the "License");
486 * you may not use this file except in compliance with the License.
487 * You may obtain a copy of the License at
488- *
489+ *
490 * http://www.apache.org/licenses/LICENSE-2.0
491- *
492+ *
493 * Unless required by applicable law or agreed to in writing, software
494 * distributed under the License is distributed on an "AS IS" BASIS,
495 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
496@@ -125,7 +125,7 @@
497
498
499
500-namespace zorba
501+namespace zorba
502 {
503
504 static inline store::Item_t createQName(
505
506=== modified file 'src/functions/pregenerated/func_sequences.cpp'
507--- src/functions/pregenerated/func_sequences.cpp 2011-06-17 14:40:56 +0000
508+++ src/functions/pregenerated/func_sequences.cpp 2011-10-21 00:32:19 +0000
509@@ -138,15 +138,6 @@
510 return new FnDeepEqualIterator(sctx, loc, argv);
511 }
512
513-PlanIter_t fn_count::codegen(
514- CompilerCB*,
515- static_context* sctx,
516- const QueryLoc& loc,
517- std::vector<PlanIter_t>& argv,
518- AnnotationHolder& ann) const
519-{
520- return new FnCountIterator(sctx, loc, argv);
521-}
522
523 PlanIter_t fn_avg::codegen(
524 CompilerCB*,
525
526=== modified file 'src/runtime/base/binarybase.h'
527--- src/runtime/base/binarybase.h 2011-06-14 17:26:33 +0000
528+++ src/runtime/base/binarybase.h 2011-10-21 00:32:19 +0000
529@@ -1,12 +1,12 @@
530 /*
531 * Copyright 2006-2008 The FLWOR Foundation.
532- *
533+ *
534 * Licensed under the Apache License, Version 2.0 (the "License");
535 * you may not use this file except in compliance with the License.
536 * You may obtain a copy of the License at
537- *
538+ *
539 * http://www.apache.org/licenses/LICENSE-2.0
540- *
541+ *
542 * Unless required by applicable law or agreed to in writing, software
543 * distributed under the License is distributed on an "AS IS" BASIS,
544 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
545@@ -29,7 +29,7 @@
546
547 /*******************************************************************************
548 Superclass for all iterators which have 2 child iterators and no additional
549- data members.
550+ data members.
551 ********************************************************************************/
552 template <class IterType, class StateType>
553 class BinaryBaseIterator : public Batcher<IterType>
554@@ -52,7 +52,7 @@
555 BinaryBaseIterator(
556 static_context* sctx,
557 const QueryLoc& loc,
558- PlanIter_t& child0,
559+ PlanIter_t& child0,
560 PlanIter_t& child1)
561 :
562 Batcher<IterType>(sctx, loc),
563@@ -63,9 +63,19 @@
564
565 virtual ~BinaryBaseIterator() {}
566
567- virtual uint32_t getStateSize() const
568- {
569- return StateTraitsImpl<StateType>::getStateSize();
570+ PlanIter_t& getChild0()
571+ {
572+ return theChild0;
573+ }
574+
575+ PlanIter_t& getChild1()
576+ {
577+ return theChild1;
578+ }
579+
580+ virtual uint32_t getStateSize() const
581+ {
582+ return StateTraitsImpl<StateType>::getStateSize();
583 }
584
585 virtual uint32_t getStateSizeOfSubtree() const
586@@ -179,7 +189,7 @@
587 ********************************************************************************/
588
589 #define BINARY_ITER(name) \
590-BINARY_ITER_STATE(name, PlanIteratorState)
591+BINARY_ITER_STATE(name, PlanIteratorState)
592
593
594
595
596=== modified file 'src/runtime/base/narybase.h'
597--- src/runtime/base/narybase.h 2011-06-14 17:26:33 +0000
598+++ src/runtime/base/narybase.h 2011-10-21 00:32:19 +0000
599@@ -1,12 +1,12 @@
600 /*
601 * Copyright 2006-2008 The FLWOR Foundation.
602- *
603+ *
604 * Licensed under the Apache License, Version 2.0 (the "License");
605 * you may not use this file except in compliance with the License.
606 * You may obtain a copy of the License at
607- *
608+ *
609 * http://www.apache.org/licenses/LICENSE-2.0
610- *
611+ *
612 * Unless required by applicable law or agreed to in writing, software
613 * distributed under the License is distributed on an "AS IS" BASIS,
614 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
615@@ -34,7 +34,7 @@
616
617 /*******************************************************************************
618 Superclass for all iterators which have N child iterators and no additional
619- data members.
620+ data members.
621 ********************************************************************************/
622 template <class IterType, class StateType>
623 class NaryBaseIterator : public Batcher<IterType>
624@@ -59,11 +59,16 @@
625
626 virtual ~NaryBaseIterator(){}
627
628+ std::vector<PlanIter_t>& getChildren()
629+ {
630+ return theChildren;
631+ }
632+
633 virtual uint32_t getStateSize() const
634 {
635 return StateTraitsImpl<StateType>::getStateSize();
636 }
637-
638+
639 virtual uint32_t getStateSizeOfSubtree() const;
640
641 void openImpl(PlanState& planState, uint32_t& offset);
642@@ -101,7 +106,7 @@
643 {
644 uint32_t size = 0;
645
646- std::vector<PlanIter_t>::const_iterator lIter = theChildren.begin();
647+ std::vector<PlanIter_t>::const_iterator lIter = theChildren.begin();
648 std::vector<PlanIter_t>::const_iterator lEnd = theChildren.end();
649 for (; lIter != lEnd; ++lIter )
650 {
651@@ -116,12 +121,12 @@
652 void
653 NaryBaseIterator<IterType, StateType>::openImpl(
654 PlanState& planState,
655- uint32_t& offset)
656+ uint32_t& offset)
657 {
658 StateTraitsImpl<StateType>::createState(planState, this->theStateOffset, offset);
659 StateTraitsImpl<StateType>::initState(planState, this->theStateOffset);
660
661- std::vector<PlanIter_t>::iterator lIter = theChildren.begin();
662+ std::vector<PlanIter_t>::iterator lIter = theChildren.begin();
663 std::vector<PlanIter_t>::iterator lEnd = theChildren.end();
664 for ( ; lIter != lEnd; ++lIter )
665 {
666@@ -136,7 +141,7 @@
667 {
668 StateTraitsImpl<StateType>::reset(planState, this->theStateOffset);
669
670- std::vector<PlanIter_t>::const_iterator lIter = theChildren.begin();
671+ std::vector<PlanIter_t>::const_iterator lIter = theChildren.begin();
672 std::vector<PlanIter_t>::const_iterator lEnd = theChildren.end();
673 for ( ; lIter != lEnd; ++lIter )
674 {
675@@ -149,7 +154,7 @@
676 void
677 NaryBaseIterator<IterType, StateType>::closeImpl(PlanState& planState)
678 {
679- std::vector<PlanIter_t>::const_iterator lIter = theChildren.begin();
680+ std::vector<PlanIter_t>::const_iterator lIter = theChildren.begin();
681 std::vector<PlanIter_t>::const_iterator lEnd = theChildren.end();
682 for ( ; lIter != lEnd; ++lIter )
683 {
684@@ -214,7 +219,7 @@
685 ********************************************************************************/
686
687 #define NARY_ITER(name) \
688-NARY_ITER_STATE(name, PlanIteratorState)
689+NARY_ITER_STATE(name, PlanIteratorState)
690
691
692 } /* namespace zorba */
693
694=== modified file 'src/runtime/base/plan_iterator.h'
695--- src/runtime/base/plan_iterator.h 2011-07-12 20:15:01 +0000
696+++ src/runtime/base/plan_iterator.h 2011-10-21 00:32:19 +0000
697@@ -1,12 +1,12 @@
698 /*
699 * Copyright 2006-2008 The FLWOR Foundation.
700- *
701+ *
702 * Licensed under the Apache License, Version 2.0 (the "License");
703 * you may not use this file except in compliance with the License.
704 * You may obtain a copy of the License at
705- *
706+ *
707 * http://www.apache.org/licenses/LICENSE-2.0
708- *
709+ *
710 * Unless required by applicable law or agreed to in writing, software
711 * distributed under the License is distributed on an "AS IS" BASIS,
712 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
713@@ -40,7 +40,7 @@
714
715 /*******************************************************************************
716
717- Macros to automate Duff's Device and separation of code and state.
718+ Macros to automate Duff's Device and separation of code and state.
719
720 These macros are used in the nextImpl() method of each iterator. In general,
721 the nextImpl() method will be called multiple times, and during each invocation,
722@@ -48,18 +48,18 @@
723 info about what the previous invocation(s) did). The Duff's device is a
724 techique by which the point where each invocation exited from is remembered,
725 and during the next invocation, execution of the method resumes at that point.
726- In general, this simplifies the implementation of the method.
727+ In general, this simplifies the implementation of the method.
728
729 DEFUALT_STACK_INIT : Gets a pointer to the iterator's state in the state block
730 and "starts" the duff's device.
731 STACK_PUSH : Causes the nextImpl() method to return with the given
732- status and saves the current line in the source file
733+ status and saves the current line in the source file
734 into the duffs line so that when the nextImpl method
735 is called again, execution will start right after the
736 STACK_PUSH macro.
737 STACK_END : Causes the nextImpl() method to return with false,
738 indicating that there are no more results to produce.
739- It also saves the current line in the source file into
740+ It also saves the current line in the source file into
741 the duffs line so that if the nextImpl method is called
742 again, an exception will be raised.
743 ********************************************************************************/
744@@ -104,7 +104,7 @@
745
746
747 /*******************************************************************************
748- Class to represent state that is shared by all plan iterators.
749+ Class to represent state that is shared by all plan iterators.
750
751 theBlock : Pointer to the memory block that stores the local state of
752 each individual plan iterator.
753@@ -125,11 +125,11 @@
754 uint32_t theStackDepth;
755
756 uint32_t theMaxStackDepth;
757-
758+
759 // TODO this guy should become const because nothing can change anymore during
760 // runtime. We need to make all accessor in the control block and static context
761 // (see also shortcut below) const before doing that
762- CompilerCB * theCompilerCB;
763+ CompilerCB * theCompilerCB;
764
765 XQueryImpl * theQuery;
766
767@@ -179,7 +179,7 @@
768 #endif
769
770 public:
771- PlanIteratorState()
772+ PlanIteratorState()
773 :
774 theDuffsLine(DUFFS_ALLOCATE_RESOURCES)
775 #if ZORBA_BATCHING_TYPE == 1
776@@ -196,8 +196,8 @@
777
778 uint32_t getDuffsLine() const { return theDuffsLine; }
779
780- /**
781- * Initialize the current state object.
782+ /**
783+ * Initialize the current state object.
784 *
785 * This method is invoked be the openImpl() method of the associated iterator
786 * to initialize the state info needed by the iterator. All initialization of
787@@ -208,15 +208,15 @@
788 * Each subclass implementation of this method must call the init() method of
789 * their parent class explicitly in order to guarantee proper initialization.
790 */
791- void init(PlanState&)
792- {
793+ void init(PlanState&)
794+ {
795 theDuffsLine = DUFFS_ALLOCATE_RESOURCES;
796 #if ZORBA_BATCHING_TYPE == 1
797 theCurrItem = ZORBA_BATCHING_BATCHSIZE;
798 #endif
799 }
800
801- /**
802+ /**
803 * Reset the current state object.
804 *
805 * This method is invoked by the resetImpl() method of the associated iterator.
806@@ -225,17 +225,17 @@
807 * the first time.
808 *
809 * Classes that inherit from PlanIteratorState must reimplement this method.
810- * Each subclass implementation of this method must call the reset() method
811+ * Each subclass implementation of this method must call the reset() method
812 * of their parent class explicitly in order to guarantee proper reset.
813 */
814- void reset(PlanState&)
815- {
816- theDuffsLine = DUFFS_ALLOCATE_RESOURCES;
817+ void reset(PlanState&)
818+ {
819+ theDuffsLine = DUFFS_ALLOCATE_RESOURCES;
820 #if ZORBA_BATCHING_TYPE == 1
821 theCurrItem = ZORBA_BATCHING_BATCHSIZE;
822 // seeting the first item to NULL only is sufficient so
823 // that produceNext knows that it's not finished yet
824- theBatch[0] = NULL;
825+ theBatch[0] = NULL;
826 #endif
827 }
828 };
829@@ -251,9 +251,9 @@
830 StateTraitsImpl() {} // prevent instantiation
831
832 public:
833- static uint32_t getStateSize()
834- {
835- return sizeof(T);
836+ static uint32_t getStateSize()
837+ {
838+ return sizeof(T);
839 }
840
841 static T* getState(PlanState& planState, uint32_t stateOffset)
842@@ -270,7 +270,7 @@
843
844 static void initState(PlanState& planState, uint32_t& stateOffset)
845 {
846- getState(planState, stateOffset)->init(planState);
847+ getState(planState, stateOffset)->init(planState);
848 }
849
850 static void reset(PlanState& planState, uint32_t stateOffset)
851@@ -278,9 +278,9 @@
852 (reinterpret_cast<T*>(planState.theBlock+ stateOffset))->reset(planState);
853 }
854
855- static void destroyState(PlanState& planState, uint32_t stateOffset)
856- {
857- (reinterpret_cast<T*>(planState.theBlock + stateOffset))->~T();
858+ static void destroyState(PlanState& planState, uint32_t stateOffset)
859+ {
860+ (reinterpret_cast<T*>(planState.theBlock + stateOffset))->~T();
861 }
862 };
863
864@@ -318,17 +318,17 @@
865 void serialize(::zorba::serialization::Archiver& ar);
866
867 public:
868- PlanIterator(static_context* aContext, const QueryLoc& aLoc)
869+ PlanIterator(static_context* aContext, const QueryLoc& aLoc)
870 :
871 theStateOffset(0),
872 loc(aLoc),
873 theSctx(aContext)
874 {
875 }
876-
877- PlanIterator(const PlanIterator& it)
878- :
879- SimpleRCObject(it),
880+
881+ PlanIterator(const PlanIterator& it)
882+ :
883+ SimpleRCObject(it),
884 theStateOffset(0),
885 loc(it.loc),
886 theSctx(it.theSctx)
887@@ -346,17 +346,17 @@
888
889 /**
890 * Accept method for the PlanIterator-Tree-Visitor
891- *
892+ *
893 * @param PlanIterVisitor
894 */
895 virtual void accept(PlanIterVisitor&) const = 0;
896
897- /**
898+ /**
899 * Returns the size of the state which must be saved for the current iterator
900 * on the state block
901 */
902 virtual uint32_t getStateSize() const = 0;
903-
904+
905 /**
906 * Returns the size of the state for this iterator and all its sub-iterators.
907 */
908@@ -368,15 +368,15 @@
909 */
910 virtual void open(PlanState& planState, uint32_t& offset) = 0;
911
912- /**
913- * Restarts the iterator so that the next 'produceNext' call will start
914- * again from the beginning (should not release any resources).
915+ /**
916+ * Restarts the iterator so that the next 'produceNext' call will start
917+ * again from the beginning (should not release any resources).
918 *
919 * @param planState
920 */
921 virtual void reset(PlanState& planState) const = 0;
922
923- /**
924+ /**
925 * Finish the execution of the iterator. Releases all resources and destroys
926 * the according plan state* objects. Make sure that no exception is throw
927 * when destroying the states. Otherwise we will have a lot of memory leaks.
928@@ -384,14 +384,14 @@
929 * @param planState
930 */
931 virtual void close(PlanState& planState) = 0;
932-
933+
934
935 #if ZORBA_BATCHING_TYPE == 1
936
937- /**
938+ /**
939 * Produce the next batch of items and place them in the batch buffer.
940 * Implicitly, the first call of producNext() initializes the iterator and
941- * allocates resources (main memory, file descriptors, etc.).
942+ * allocates resources (main memory, file descriptors, etc.).
943 *
944 * @param stateBLock
945 */
946@@ -401,7 +401,7 @@
947 * Static Method: Retreives the next item from the batch buffer of the given
948 * iterator and returns it to the caller. If all the items from the iterator's
949 * batch buffer have been consumed already, then it makes the iterator produce
950- * its next batch of results and retrieves the 1st item from this new batch.
951+ * its next batch of results and retrieves the 1st item from this new batch.
952 */
953 static store::Item_t consumeNext(
954 store::Item_t& result,
955@@ -411,7 +411,7 @@
956 try
957 {
958 // use the given iterator's planstate to access it's batch
959- PlanIteratorState* lState =
960+ PlanIteratorState* lState =
961 StateTraitsImpl<PlanIteratorState>::getState(planState, iter->getStateOffset());
962
963 if ( lState->theCurrItem == ZORBA_BATCHING_BATCHSIZE )
964@@ -435,10 +435,10 @@
965
966 #else // ZORBA_BATCHING_TYPE
967
968- /**
969+ /**
970 * Produce the next item and return it to the caller. Implicitly, the first
971- * call of 'producNext' initializes the iterator and allocates resources
972- * (main memory, file descriptors, etc.).
973+ * call of 'producNext' initializes the iterator and allocates resources
974+ * (main memory, file descriptors, etc.).
975 *
976 * @param stateBLock
977 */
978@@ -446,20 +446,20 @@
979
980 /**
981 * Static Method: Makes the given iterator produce its next result and returns
982- * that result to the caller.
983+ * that result to the caller.
984 */
985 #ifndef NDEBUG
986 static bool consumeNext(
987- store::Item_t& result,
988+ store::Item_t& result,
989 const PlanIterator* iter,
990 PlanState& planState);
991 #else
992 static bool consumeNext(
993- store::Item_t& result,
994+ store::Item_t& result,
995 const PlanIterator* iter,
996 PlanState& planState)
997 {
998- if (planState.theHasToQuit)
999+ if (planState.theHasToQuit)
1000 {
1001 // Quit the execution
1002 throw FlowCtlException(FlowCtlException::INTERRUPT);
1003@@ -499,14 +499,14 @@
1004 ~Batcher() {}
1005
1006
1007-#if ZORBA_BATCHING_TYPE == 1
1008+#if ZORBA_BATCHING_TYPE == 1
1009
1010- void produceNext(PlanState& planState) const
1011+ void produceNext(PlanState& planState) const
1012 {
1013 PlanIteratorState* lState =
1014 StateTraitsImpl<PlanIteratorState>::getState(planState, stateOffset);
1015 #ifndef NDEBUG
1016- ZORBA_ASSERT(lState->theIsOpened);
1017+ ZORBA_ASSERT(lState->theIsOpened);
1018 #endif
1019 bool more;
1020 uint32_t i = 0;
1021@@ -516,7 +516,7 @@
1022 // call consumeNext() on one or more of this iterator's child iterators.
1023 more = static_cast<const IterType*>(this)->nextImpl(lState->theBatch[i], planState);
1024 }
1025- while ( more && ++i < ZORBA_BATCHING_BATCHSIZE );
1026+ while ( more && ++i < ZORBA_BATCHING_BATCHSIZE );
1027 }
1028
1029 #else
1030@@ -526,7 +526,7 @@
1031 #ifndef NDEBUG
1032 PlanIteratorState* lState =
1033 StateTraitsImpl<PlanIteratorState>::getState(planState, theStateOffset);
1034- ZORBA_ASSERT(lState->theIsOpened);
1035+ ZORBA_ASSERT(lState->theIsOpened);
1036 #endif
1037 return static_cast<const IterType*>(this)->nextImpl(result, planState);
1038 }
1039@@ -548,9 +548,9 @@
1040 void reset(PlanState& planState) const
1041 {
1042 #ifndef NDEBUG
1043- PlanIteratorState* lState =
1044+ PlanIteratorState* lState =
1045 StateTraitsImpl<PlanIteratorState>::getState(planState, theStateOffset);
1046- ZORBA_ASSERT( lState->theIsOpened );
1047+ ZORBA_ASSERT( lState->theIsOpened );
1048 #endif
1049 static_cast<const IterType*>(this)->resetImpl(planState);
1050 }
1051@@ -558,7 +558,7 @@
1052 void close(PlanState& planState)
1053 {
1054 #ifndef NDEBUG
1055- PlanIteratorState* lState =
1056+ PlanIteratorState* lState =
1057 StateTraitsImpl<PlanIteratorState>::getState(planState, theStateOffset);
1058 static_cast<IterType*>(this)->closeImpl(planState);
1059 lState->theIsOpened = false;
1060
1061=== modified file 'src/runtime/base/unarybase.h'
1062--- src/runtime/base/unarybase.h 2011-06-14 17:26:33 +0000
1063+++ src/runtime/base/unarybase.h 2011-10-21 00:32:19 +0000
1064@@ -1,12 +1,12 @@
1065 /*
1066 * Copyright 2006-2008 The FLWOR Foundation.
1067- *
1068+ *
1069 * Licensed under the Apache License, Version 2.0 (the "License");
1070 * you may not use this file except in compliance with the License.
1071 * You may obtain a copy of the License at
1072- *
1073+ *
1074 * http://www.apache.org/licenses/LICENSE-2.0
1075- *
1076+ *
1077 * Unless required by applicable law or agreed to in writing, software
1078 * distributed under the License is distributed on an "AS IS" BASIS,
1079 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1080@@ -51,7 +51,7 @@
1081 public:
1082 UnaryBaseIterator(
1083 static_context* sctx,
1084- const QueryLoc& loc,
1085+ const QueryLoc& loc,
1086 const PlanIter_t& child)
1087 :
1088 Batcher<IterType>(sctx, loc),
1089@@ -64,9 +64,14 @@
1090
1091 virtual ~UnaryBaseIterator() {}
1092
1093- virtual uint32_t getStateSize() const
1094- {
1095- return StateTraitsImpl<StateType>::getStateSize();
1096+ const PlanIter_t& getChild()
1097+ {
1098+ return theChild;
1099+ }
1100+
1101+ virtual uint32_t getStateSize() const
1102+ {
1103+ return StateTraitsImpl<StateType>::getStateSize();
1104 }
1105
1106 virtual uint32_t getStateSizeOfSubtree() const
1107@@ -100,8 +105,8 @@
1108 UnaryBaseIterator<IterType, StateType>::resetImpl(PlanState& planState) const
1109 {
1110 StateTraitsImpl<StateType>::reset(planState, this->theStateOffset);
1111-
1112- theChild->reset(planState);
1113+
1114+ theChild->reset(planState);
1115 }
1116
1117
1118@@ -159,7 +164,7 @@
1119 ********************************************************************************/
1120
1121 #define UNARY_ITER(name) \
1122-UNARY_ITER_STATE(name, PlanIteratorState)
1123+UNARY_ITER_STATE(name, PlanIteratorState)
1124
1125
1126 }; /* namespace zorba*/
1127
1128=== modified file 'src/runtime/collections/collections_base.h'
1129--- src/runtime/collections/collections_base.h 2011-06-28 23:34:08 +0000
1130+++ src/runtime/collections/collections_base.h 2011-10-21 00:32:19 +0000
1131@@ -5,7 +5,7 @@
1132 * you may not use this file except in compliance with the License.
1133 * You may obtain a copy of the License at
1134 *
1135- * http://www.apache.org/licenses/LICENSE-2.0
1136+ * http://www.apache.org/licenses/LICENSE2.0
1137 *
1138 * Unless required by applicable law or agreed to in writing, software
1139 * distributed under the License is distributed on an "AS IS" BASIS,
1140@@ -32,12 +32,12 @@
1141
1142
1143 /*******************************************************************************
1144- Check that the type of a node to be inserted into a collection matches with
1145+ Check that the type of a node to be inserted into a collection matches with
1146 the statically declared type of the collection nodes. If not, raise an error.
1147 ********************************************************************************/
1148 void checkNodeType(
1149 const static_context* sctx,
1150- const store::Item_t& node,
1151+ const store::Item_t& node,
1152 const StaticallyKnownCollection* collectionDecl,
1153 const QueryLoc& loc,
1154 bool dyn_coll);
1155@@ -52,7 +52,7 @@
1156 ******************************************************************************/
1157 template <class Iter, class State>
1158 class ZorbaCollectionIteratorHelper : public NaryBaseIterator<Iter, State>
1159-{
1160+{
1161 protected:
1162 //whether it's the function of the dynamic or the static collection module
1163 bool theDynamicCollection;
1164@@ -66,7 +66,7 @@
1165 store::Collection_t& coll) const
1166 {
1167 const StaticallyKnownCollection* collectionDecl = aSctx->lookup_collection(aName);
1168- if (collectionDecl == 0 && !aDynamicCollection)
1169+ if (collectionDecl == 0 && !aDynamicCollection)
1170 {
1171 throw XQUERY_EXCEPTION(
1172 zerr::ZDDY0001_COLLECTION_NOT_DECLARED,
1173@@ -74,10 +74,10 @@
1174 ERROR_LOC( aLoc )
1175 );
1176 }
1177-
1178+
1179 coll = GENV_STORE.getCollection(aName, aDynamicCollection);
1180-
1181- if (coll == NULL)
1182+
1183+ if (coll == NULL)
1184 {
1185 throw XQUERY_EXCEPTION(
1186 zerr::ZDDY0003_COLLECTION_DOES_NOT_EXIST,
1187@@ -85,7 +85,7 @@
1188 ERROR_LOC( aLoc )
1189 );
1190 }
1191-
1192+
1193 return collectionDecl;
1194 }
1195
1196@@ -102,21 +102,21 @@
1197 store::Item_t node;
1198 store::Item_t copyNode;
1199 xs_integer targetPos;
1200-
1201+
1202 store::CopyMode lCopyMode;
1203-
1204+
1205 this->consumeNext(collName, this->theChildren[0].getp(), planState);
1206-
1207+
1208 collectionDecl = getCollection(
1209 this->theSctx, collName, this->loc, theDynamicCollection, collection);
1210
1211 if (beforeOrAfter) {
1212- if(!this->consumeNext(targetNode, this->theChildren[this->theChildren.size()-2].getp(), planState))
1213+ if(!this->consumeNext(targetNode, this->theChildren[this->theChildren.size()-2].getp(), planState))
1214 {
1215 ZORBA_ASSERT(false);
1216 }
1217
1218- if (!collection->findNode(targetNode.getp(), targetPos))
1219+ if (!collection->findNode(targetNode.getp(), targetPos))
1220 {
1221 throw XQUERY_EXCEPTION(
1222 zerr::ZDDY0011_COLLECTION_NODE_NOT_FOUND,
1223@@ -125,9 +125,9 @@
1224 );
1225 }
1226 }
1227-
1228+
1229 getCopyMode(lCopyMode, this->theSctx);
1230-
1231+
1232 while (this->consumeNext(node, this->theChildren[this->theChildren.size()-1].getp(), planState))
1233 {
1234 checkNodeType(this->theSctx, node, collectionDecl, this->loc, theDynamicCollection);
1235
1236=== modified file 'src/runtime/collections/collections_impl.cpp'
1237--- src/runtime/collections/collections_impl.cpp 2011-10-03 19:38:22 +0000
1238+++ src/runtime/collections/collections_impl.cpp 2011-10-21 00:32:19 +0000
1239@@ -1,12 +1,12 @@
1240 /*
1241 * Copyright 2006-2008 The FLWOR Foundation.
1242- *
1243+ *
1244 * Licensed under the Apache License, Version 2.0 (the "License");
1245 * you may not use this file except in compliance with the License.
1246 * You may obtain a copy of the License at
1247- *
1248+ *
1249 * http://www.apache.org/licenses/LICENSE-2.0
1250- *
1251+ *
1252 * Unless required by applicable law or agreed to in writing, software
1253 * distributed under the License is distributed on an "AS IS" BASIS,
1254 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1255@@ -33,7 +33,10 @@
1256 #include "compiler/xqddf/value_ic.h"
1257
1258 #include "runtime/collections/collections.h"
1259+#include "runtime/collections/collections_impl.h"
1260 #include "runtime/core/apply_updates.h"
1261+#include "runtime/base/plan_iterator.h"
1262+#include "runtime/visitors/planiter_visitor.h"
1263
1264 #include "store/api/pul.h"
1265 #include "store/api/item.h"
1266@@ -56,7 +59,7 @@
1267
1268 void checkNodeType(
1269 const static_context* aSctx,
1270- const store::Item_t& aNode,
1271+ const store::Item_t& aNode,
1272 const StaticallyKnownCollection* aColl,
1273 const QueryLoc& aLoc,
1274 bool dyn_coll);
1275@@ -68,11 +71,11 @@
1276 ********************************************************************************/
1277 FnCollectionIteratorState::~FnCollectionIteratorState()
1278 {
1279- if ( theIterator != NULL )
1280+ if ( theIterator != NULL )
1281 {
1282 // closing the iterator is necessary here if an exception occurs
1283 // in the producer or if the iterator is not fully consumed
1284- if (theIteratorOpened)
1285+ if (theIteratorOpened)
1286 {
1287 theIterator->close();
1288 theIteratorOpened = false;
1289@@ -93,11 +96,11 @@
1290 {
1291 PlanIteratorState::reset(planState);
1292
1293- if ( theIterator != NULL )
1294+ if ( theIterator != NULL )
1295 {
1296 // closing the iterator is necessary here if an exception occurs
1297 // in the producer or if the iterator is not fully consumed
1298- if (theIteratorOpened)
1299+ if (theIteratorOpened)
1300 {
1301 theIterator->close();
1302 theIteratorOpened = false;
1303@@ -120,13 +123,13 @@
1304 DEFAULT_STACK_INIT(FnCollectionIteratorState, state, planState);
1305
1306 if (theChildren.size() == 1 &&
1307- consumeNext(lURI, theChildren[0].getp(), planState))
1308+ consumeNext(lURI, theChildren[0].getp(), planState))
1309 {
1310- try
1311+ try
1312 {
1313 resolvedURIString = theSctx->resolve_relative_uri(lURI->getStringValue());
1314 }
1315- catch (ZorbaException const&)
1316+ catch (ZorbaException const&)
1317 {
1318 throw XQUERY_EXCEPTION(
1319 err::FODC0004,
1320@@ -135,21 +138,26 @@
1321 );
1322 }
1323 }
1324- else
1325+ else
1326 {
1327 resolvedURIItem = planState.theGlobalDynCtx->get_default_collection();
1328+
1329+ if (NULL == resolvedURIItem)
1330+ throw XQUERY_EXCEPTION(
1331+ err::FODC0002,
1332+ ERROR_PARAMS( ZED( DefaultCollation ), ZED( NotDefInDynamicCtx ) ),
1333+ ERROR_LOC( loc )
1334+ );
1335+
1336 resolvedURIString = theSctx->resolve_relative_uri(resolvedURIItem->getStringValue());
1337-
1338- if( NULL == resolvedURIItem)
1339- throw XQUERY_EXCEPTION(
1340- err::FODC0002,
1341- ERROR_PARAMS( ZED( DefaultCollation ), ZED( NotDefInDynamicCtx ) ),
1342- ERROR_LOC( loc )
1343- );
1344 }
1345
1346- lResource = theSctx->resolve_uri( resolvedURIString, impl::EntityData::COLLECTION, lErrorMessage );
1347+ lResource = theSctx->resolve_uri(resolvedURIString,
1348+ impl::EntityData::COLLECTION,
1349+ lErrorMessage);
1350+
1351 lCollResource = dynamic_cast<impl::CollectionResource*>(lResource.get());
1352+
1353 if ( lCollResource == 0 || !(coll = lCollResource->getCollection()) )
1354 {
1355 throw XQUERY_EXCEPTION(
1356@@ -177,14 +185,162 @@
1357
1358
1359 /*******************************************************************************
1360+ Iterator for optimizing fn:count when applied to collections
1361+********************************************************************************/
1362+CountCollectionIterator::CountCollectionIterator(
1363+ static_context* sctx,
1364+ const QueryLoc& loc,
1365+ std::vector<PlanIter_t>& children,
1366+ CollectionType collectionType)
1367+ :
1368+ NaryBaseIterator<CountCollectionIterator, PlanIteratorState>(sctx, loc, children),
1369+ theCollectionType(collectionType)
1370+{
1371+}
1372+
1373+
1374+CountCollectionIterator::~CountCollectionIterator()
1375+{
1376+}
1377+
1378+
1379+void CountCollectionIterator::serialize(::zorba::serialization::Archiver& ar)
1380+{
1381+ serialize_baseclass(ar,
1382+ (NaryBaseIterator<CountCollectionIterator, PlanIteratorState>*)this);
1383+
1384+ SERIALIZE_ENUM(enum CollectionType, theCollectionType);
1385+}
1386+
1387+
1388+bool CountCollectionIterator::nextImpl(store::Item_t& result, PlanState& planState) const
1389+{
1390+ store::Collection_t coll;
1391+ store::Item_t qName;
1392+
1393+ PlanIteratorState* state;
1394+ DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
1395+
1396+ if (this->isZorbaCollection())
1397+ coll = getZorbaCollection(planState);
1398+ else
1399+ coll = getW3CCollection(planState);
1400+
1401+ STACK_PUSH(GENV_ITEMFACTORY->createInteger(result, coll->size()), state);
1402+
1403+ STACK_END(state);
1404+}
1405+
1406+
1407+store::Collection_t CountCollectionIterator::getW3CCollection(PlanState& planState) const
1408+{
1409+ store::Item_t lURI;
1410+ store::Collection_t coll;
1411+ std::auto_ptr<impl::Resource> lResource;
1412+ impl::CollectionResource* lCollResource;
1413+ zstring resolvedURIString;
1414+ zstring lErrorMessage;
1415+
1416+ if (!theChildren.empty()) //if a URI was given
1417+ {
1418+ ZORBA_ASSERT(consumeNext(lURI, theChildren[0].getp(), planState));
1419+
1420+ try
1421+ {
1422+ resolvedURIString = theSctx->resolve_relative_uri(lURI->getStringValue());
1423+ }
1424+ catch (ZorbaException const&)
1425+ {
1426+ throw XQUERY_EXCEPTION(
1427+ err::FODC0004,
1428+ ERROR_PARAMS(lURI->getStringValue(), ZED(BadAnyURI)),
1429+ ERROR_LOC( loc )
1430+ );
1431+ }
1432+ }
1433+ else
1434+ {
1435+ lURI = planState.theGlobalDynCtx->get_default_collection();
1436+
1437+ if( NULL == lURI)
1438+ throw XQUERY_EXCEPTION(
1439+ err::FODC0002,
1440+ ERROR_PARAMS( ZED( DefaultCollation ), ZED( NotDefInDynamicCtx ) ),
1441+ ERROR_LOC( loc )
1442+ );
1443+
1444+ resolvedURIString = theSctx->resolve_relative_uri(lURI->getStringValue());
1445+ }
1446+
1447+
1448+ lResource = theSctx->resolve_uri(resolvedURIString,
1449+ impl::EntityData::COLLECTION,
1450+ lErrorMessage);
1451+
1452+ lCollResource = dynamic_cast<impl::CollectionResource*>(lResource.get());
1453+
1454+ if ( lCollResource == 0 || !(coll = lCollResource->getCollection()) )
1455+ {
1456+ throw XQUERY_EXCEPTION(
1457+ err::FODC0004,
1458+ ERROR_PARAMS(resolvedURIString, lErrorMessage),
1459+ ERROR_LOC( loc )
1460+ );
1461+ }
1462+
1463+ return coll;
1464+}
1465+
1466+
1467+store::Collection_t CountCollectionIterator::getZorbaCollection(
1468+ PlanState& planState) const
1469+{
1470+ store::Item_t qName;
1471+ store::Collection_t coll;
1472+
1473+ ZORBA_ASSERT(consumeNext(qName, theChildren[0].getp(), planState));
1474+
1475+ if (theSctx->lookup_collection(qName) == 0 && ! this->isDynamicCollection())
1476+ {
1477+ throw XQUERY_EXCEPTION(
1478+ zerr::ZDDY0001_COLLECTION_NOT_DECLARED,
1479+ ERROR_PARAMS( qName->getStringValue() ),
1480+ ERROR_LOC( loc )
1481+ );
1482+ }
1483+
1484+ coll = GENV_STORE.getCollection(qName, isDynamicCollection());
1485+
1486+ if (coll == NULL)
1487+ {
1488+ throw XQUERY_EXCEPTION(
1489+ zerr::ZDDY0003_COLLECTION_DOES_NOT_EXIST,
1490+ ERROR_PARAMS( qName->getStringValue() ),
1491+ ERROR_LOC( loc )
1492+ );
1493+ }
1494+
1495+ return coll;
1496+}
1497+
1498+
1499+SERIALIZABLE_CLASS_VERSIONS(CountCollectionIterator)
1500+END_SERIALIZABLE_CLASS_VERSIONS(CountCollectionIterator)
1501+
1502+
1503+NARY_ACCEPT(CountCollectionIterator);
1504+
1505+
1506+/*******************************************************************************
1507+
1508 ********************************************************************************/
1509 ZorbaCollectionIteratorState::~ZorbaCollectionIteratorState()
1510 {
1511- if ( theIterator != NULL )
1512+ if ( theIterator != NULL )
1513 {
1514 // closing the iterator is necessary here if an exception occurs
1515 // in the producer or if the iterator is not fully consumed
1516- if (theIteratorOpened)
1517+ if (theIteratorOpened)
1518 {
1519 theIterator->close();
1520 theIteratorOpened = false;
1521@@ -205,11 +361,11 @@
1522 {
1523 PlanIteratorState::reset(planState);
1524
1525- if (theIterator != NULL)
1526+ if (theIterator != NULL)
1527 {
1528 // closing the iterator is necessary here if an exception occurs
1529 // in the producer or if the iterator is not fully consumed
1530- if (theIteratorOpened)
1531+ if (theIteratorOpened)
1532 {
1533 theIterator->close();
1534 theIteratorOpened = false;
1535@@ -258,7 +414,7 @@
1536 store::Collection_t& coll) const
1537 {
1538 const StaticallyKnownCollection* collectionDecl = aSctx->lookup_collection(aName);
1539- if (collectionDecl == 0 && !aDynamicCollection)
1540+ if (collectionDecl == 0 && !aDynamicCollection)
1541 {
1542 throw XQUERY_EXCEPTION(
1543 zerr::ZDDY0001_COLLECTION_NOT_DECLARED,
1544@@ -269,7 +425,7 @@
1545
1546 coll = GENV_STORE.getCollection(aName, aDynamicCollection);
1547
1548- if (coll == NULL)
1549+ if (coll == NULL)
1550 {
1551 throw XQUERY_EXCEPTION(
1552 zerr::ZDDY0003_COLLECTION_DOES_NOT_EXIST,
1553@@ -287,7 +443,7 @@
1554 $target as node()) as xs:integer
1555
1556 The function will return the index of the $target node within the collection
1557- identified by $name. Note: the function uses index numbers starting at 1.
1558+ identified by $name. Note: the function uses index numbers starting at 1.
1559 ********************************************************************************/
1560 bool ZorbaIndexOfIterator::nextImpl(
1561 store::Item_t& result,
1562@@ -326,7 +482,7 @@
1563 store::Collection_t& coll) const
1564 {
1565 const StaticallyKnownCollection* collectionDecl = aSctx->lookup_collection(aName);
1566- if (collectionDecl == 0 && !aDynamicCollection)
1567+ if (collectionDecl == 0 && !aDynamicCollection)
1568 {
1569 throw XQUERY_EXCEPTION(
1570 zerr::ZDDY0001_COLLECTION_NOT_DECLARED,
1571@@ -337,7 +493,7 @@
1572
1573 coll = GENV_STORE.getCollection(aName, aDynamicCollection);
1574
1575- if (coll == NULL)
1576+ if (coll == NULL)
1577 {
1578 throw XQUERY_EXCEPTION(
1579 zerr::ZDDY0003_COLLECTION_DOES_NOT_EXIST,
1580@@ -446,7 +602,7 @@
1581 }
1582
1583 // also add some optional nodes to the collection
1584- if (theChildren.size() == 2)
1585+ if (theChildren.size() == 2)
1586 {
1587 store::CopyMode copymode;
1588 getCopyMode(copymode, theSctx);
1589@@ -481,7 +637,7 @@
1590 store::Collection_t& coll) const
1591 {
1592 const StaticallyKnownCollection* collectionDecl = aSctx->lookup_collection(aName);
1593- if (collectionDecl == 0 && !aDynamicCollection)
1594+ if (collectionDecl == 0 && !aDynamicCollection)
1595 {
1596 throw XQUERY_EXCEPTION(
1597 zerr::ZDDY0001_COLLECTION_NOT_DECLARED,
1598@@ -534,7 +690,7 @@
1599 store::Collection_t& coll) const
1600 {
1601 const StaticallyKnownCollection* collectionDecl = aSctx->lookup_collection(aName);
1602- if (collectionDecl == 0 && !aDynamicCollection)
1603+ if (collectionDecl == 0 && !aDynamicCollection)
1604 {
1605 throw XQUERY_EXCEPTION(
1606 zerr::ZDDY0001_COLLECTION_NOT_DECLARED,
1607@@ -543,7 +699,7 @@
1608 );
1609 }
1610 coll = GENV_STORE.getCollection(aName, aDynamicCollection);
1611- if (coll == NULL)
1612+ if (coll == NULL)
1613 {
1614 throw XQUERY_EXCEPTION(
1615 zerr::ZDDY0003_COLLECTION_DOES_NOT_EXIST,
1616@@ -605,21 +761,21 @@
1617 throw XQUERY_EXCEPTION(
1618 zerr::ZDDY0004_COLLECTION_CONST_UPDATE,
1619 ERROR_PARAMS( aName->getStringValue() ),
1620- ERROR_LOC( loc )
1621+ ERROR_LOC( loc )
1622 );
1623
1624 case StaticContextConsts::decl_append_only:
1625 throw XQUERY_EXCEPTION(
1626 zerr::ZDDY0005_COLLECTION_APPEND_BAD_INSERT,
1627 ERROR_PARAMS( aName->getStringValue() ),
1628- ERROR_LOC( loc )
1629+ ERROR_LOC( loc )
1630 );
1631
1632 case StaticContextConsts::decl_queue:
1633 throw XQUERY_EXCEPTION(
1634 zerr::ZDDY0006_COLLECTION_QUEUE_BAD_INSERT,
1635 ERROR_PARAMS( aName->getStringValue() ),
1636- ERROR_LOC( loc )
1637+ ERROR_LOC( loc )
1638 );
1639
1640 case StaticContextConsts::decl_mutable:
1641@@ -689,21 +845,21 @@
1642 throw XQUERY_EXCEPTION(
1643 zerr::ZDDY0004_COLLECTION_CONST_UPDATE,
1644 ERROR_PARAMS( aName->getStringValue() ),
1645- ERROR_LOC( loc )
1646+ ERROR_LOC( loc )
1647 );
1648
1649 case StaticContextConsts::decl_append_only:
1650 throw XQUERY_EXCEPTION(
1651 zerr::ZDDY0005_COLLECTION_APPEND_BAD_INSERT,
1652 ERROR_PARAMS( aName->getStringValue() ),
1653- ERROR_LOC( loc )
1654+ ERROR_LOC( loc )
1655 );
1656
1657 case StaticContextConsts::decl_queue:
1658 throw XQUERY_EXCEPTION(
1659 zerr::ZDDY0006_COLLECTION_QUEUE_BAD_INSERT,
1660 ERROR_PARAMS( aName->getStringValue() ),
1661- ERROR_LOC( loc )
1662+ ERROR_LOC( loc )
1663 );
1664
1665 case StaticContextConsts::decl_mutable:
1666@@ -730,7 +886,7 @@
1667 insert-nodes-last($name as xs:QName, $newnode as node()*) as none
1668
1669 The function will insert the given node(s) as the last node(s) of the given
1670- collection. If multiple nodes are inserted, the nodes remain adjacent and
1671+ collection. If multiple nodes are inserted, the nodes remain adjacent and
1672 their order preserves the node ordering of the source expression.
1673
1674 Error conditions:
1675@@ -739,7 +895,7 @@
1676 - If the specified collection does not exist, an error is raised
1677 (ZAPI0006_COLLECTION_NOT_FOUND - collection does not exist).
1678 - If the node is already in the collection, an error is raised
1679- (ZAPI0031_NODE_ALREADY_IN_COLLECTION)
1680+ (ZAPI0031_NODE_ALREADY_IN_COLLECTION)
1681 ********************************************************************************/
1682 bool ZorbaInsertNodesLastIterator::nextImpl(
1683 store::Item_t& result,
1684@@ -781,13 +937,13 @@
1685 aSctx, aName, aLoc, aDynamicCollection, coll);
1686
1687 if (!aDynamicCollection) {
1688- switch(collectionDecl->getUpdateProperty())
1689+ switch(collectionDecl->getUpdateProperty())
1690 {
1691 case StaticContextConsts::decl_const:
1692 throw XQUERY_EXCEPTION(
1693 zerr::ZDDY0004_COLLECTION_CONST_UPDATE,
1694 ERROR_PARAMS( aName->getStringValue() ),
1695- ERROR_LOC( loc )
1696+ ERROR_LOC( loc )
1697 );
1698
1699 case StaticContextConsts::decl_append_only:
1700@@ -866,27 +1022,27 @@
1701 aSctx, aName, aLoc, aDynamicCollection, coll);
1702
1703 if (!aDynamicCollection) {
1704- switch(collectionDecl->getUpdateProperty())
1705+ switch(collectionDecl->getUpdateProperty())
1706 {
1707 case StaticContextConsts::decl_const:
1708 throw XQUERY_EXCEPTION(
1709 zerr::ZDDY0004_COLLECTION_CONST_UPDATE,
1710 ERROR_PARAMS( aName->getStringValue() ),
1711- ERROR_LOC( loc )
1712+ ERROR_LOC( loc )
1713 );
1714
1715 case StaticContextConsts::decl_append_only:
1716 throw XQUERY_EXCEPTION(
1717 zerr::ZDDY0005_COLLECTION_APPEND_BAD_INSERT,
1718 ERROR_PARAMS( aName->getStringValue() ),
1719- ERROR_LOC( loc )
1720+ ERROR_LOC( loc )
1721 );
1722
1723 case StaticContextConsts::decl_queue:
1724 throw XQUERY_EXCEPTION(
1725 zerr::ZDDY0006_COLLECTION_QUEUE_BAD_INSERT,
1726 ERROR_PARAMS( aName->getStringValue() ),
1727- ERROR_LOC( loc )
1728+ ERROR_LOC( loc )
1729 );
1730
1731 case StaticContextConsts::decl_mutable:
1732@@ -910,12 +1066,12 @@
1733 }
1734
1735 /*******************************************************************************
1736- declare updating function
1737+ declare updating function
1738 insert-nodes-after($name as xs:QName,
1739 $target as node(),
1740 $newnode as node()*)
1741
1742- The inserted nodes become the following nodes of the $target. The $target
1743+ The inserted nodes become the following nodes of the $target. The $target
1744 should be a non-updating expression (e.g. an XPath expression) identifying a
1745 node that is part of the given collection at the top-level. If multiple nodes
1746 are inserted by a single insert expression, the nodes remain adjacent and
1747@@ -972,21 +1128,21 @@
1748 throw XQUERY_EXCEPTION(
1749 zerr::ZDDY0004_COLLECTION_CONST_UPDATE,
1750 ERROR_PARAMS( aName->getStringValue() ),
1751- ERROR_LOC( loc )
1752+ ERROR_LOC( loc )
1753 );
1754
1755 case StaticContextConsts::decl_append_only:
1756 throw XQUERY_EXCEPTION(
1757 zerr::ZDDY0005_COLLECTION_APPEND_BAD_INSERT,
1758 ERROR_PARAMS( aName->getStringValue() ),
1759- ERROR_LOC( loc )
1760+ ERROR_LOC( loc )
1761 );
1762
1763 case StaticContextConsts::decl_queue:
1764 throw XQUERY_EXCEPTION(
1765 zerr::ZDDY0006_COLLECTION_QUEUE_BAD_INSERT,
1766 ERROR_PARAMS( aName->getStringValue() ),
1767- ERROR_LOC( loc )
1768+ ERROR_LOC( loc )
1769 );
1770
1771 case StaticContextConsts::decl_mutable:
1772@@ -1069,7 +1225,7 @@
1773 ++(state->iterator);
1774 STACK_PUSH(true, state);
1775 }
1776-
1777+
1778 STACK_PUSH(false, state);
1779
1780
1781@@ -1135,7 +1291,7 @@
1782 ++(state->iterator);
1783 STACK_PUSH(true, state);
1784 }
1785-
1786+
1787 STACK_PUSH(false, state);
1788
1789 STACK_END(state);
1790@@ -1200,7 +1356,7 @@
1791 ++(state->iterator);
1792 STACK_PUSH(true, state);
1793 }
1794-
1795+
1796 STACK_PUSH(false, state);
1797
1798 STACK_END(state);
1799@@ -1267,7 +1423,7 @@
1800 ++(state->iterator);
1801 STACK_PUSH(true, state);
1802 }
1803-
1804+
1805 STACK_PUSH(false, state);
1806
1807
1808@@ -1334,7 +1490,7 @@
1809 ++(state->iterator);
1810 STACK_PUSH(true, state);
1811 }
1812-
1813+
1814 STACK_PUSH(false, state);
1815
1816
1817@@ -1342,7 +1498,7 @@
1818 }
1819
1820 /*******************************************************************************
1821- declare updating function
1822+ declare updating function
1823 delete-nodes($name as xs:QName, $target as node()*)
1824
1825 The function will remove the node(s) identified by the $target expression
1826@@ -1363,7 +1519,7 @@
1827 PlanIteratorState* state;
1828 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
1829
1830- while (consumeNext(node, theChildren[theChildren.size()-1].getp(), planState))
1831+ while (consumeNext(node, theChildren[theChildren.size()-1].getp(), planState))
1832 {
1833 if (! node->getCollection()) {
1834 throw XQUERY_EXCEPTION( zerr::ZDDY0017_NODE_IS_ORPHAN, ERROR_LOC( loc ) );
1835@@ -1412,7 +1568,7 @@
1836 store::Collection_t& coll) const
1837 {
1838 const StaticallyKnownCollection* collectionDecl = aSctx->lookup_collection(aName);
1839- if (collectionDecl == 0 && !aDynamicCollection)
1840+ if (collectionDecl == 0 && !aDynamicCollection)
1841 {
1842 throw XQUERY_EXCEPTION(
1843 zerr::ZDDY0001_COLLECTION_NOT_DECLARED,
1844@@ -1422,27 +1578,27 @@
1845 }
1846
1847 if (!aDynamicCollection) {
1848- switch(collectionDecl->getUpdateProperty())
1849+ switch(collectionDecl->getUpdateProperty())
1850 {
1851 case StaticContextConsts::decl_const:
1852 throw XQUERY_EXCEPTION(
1853 zerr::ZDDY0004_COLLECTION_CONST_UPDATE,
1854 ERROR_PARAMS( aName->getStringValue() ),
1855- ERROR_LOC( loc )
1856+ ERROR_LOC( loc )
1857 );
1858
1859 case StaticContextConsts::decl_append_only:
1860 throw XQUERY_EXCEPTION(
1861 zerr::ZDDY0007_COLLECTION_APPEND_BAD_DELETE,
1862 ERROR_PARAMS( aName->getStringValue() ),
1863- ERROR_LOC( loc )
1864+ ERROR_LOC( loc )
1865 );
1866
1867 case StaticContextConsts::decl_queue:
1868 throw XQUERY_EXCEPTION(
1869 zerr::ZDDY0009_COLLECTION_QUEUE_BAD_DELETE,
1870 ERROR_PARAMS( aName->getStringValue() ),
1871- ERROR_LOC( loc )
1872+ ERROR_LOC( loc )
1873 );
1874
1875 case StaticContextConsts::decl_mutable:
1876@@ -1454,7 +1610,7 @@
1877 }
1878 }
1879 coll = GENV_STORE.getCollection(aName, aDynamicCollection);
1880- if (coll == NULL)
1881+ if (coll == NULL)
1882 {
1883 throw XQUERY_EXCEPTION(
1884 zerr::ZDDY0003_COLLECTION_DOES_NOT_EXIST,
1885@@ -1530,7 +1686,7 @@
1886 store::Collection_t& coll) const
1887 {
1888 const StaticallyKnownCollection* collectionDecl = aSctx->lookup_collection(aName);
1889- if (collectionDecl == 0 && !aDynamicCollection)
1890+ if (collectionDecl == 0 && !aDynamicCollection)
1891 {
1892 throw XQUERY_EXCEPTION(
1893 zerr::ZDDY0001_COLLECTION_NOT_DECLARED,
1894@@ -1540,20 +1696,20 @@
1895 }
1896
1897 if (!aDynamicCollection) {
1898- switch(collectionDecl->getUpdateProperty())
1899+ switch(collectionDecl->getUpdateProperty())
1900 {
1901 case StaticContextConsts::decl_const:
1902 throw XQUERY_EXCEPTION(
1903 zerr::ZDDY0004_COLLECTION_CONST_UPDATE,
1904 ERROR_PARAMS( aName->getStringValue() ),
1905- ERROR_LOC( loc )
1906+ ERROR_LOC( loc )
1907 );
1908
1909 case StaticContextConsts::decl_append_only:
1910 throw XQUERY_EXCEPTION(
1911 zerr::ZDDY0007_COLLECTION_APPEND_BAD_DELETE,
1912 ERROR_PARAMS( aName->getStringValue() ),
1913- ERROR_LOC( loc )
1914+ ERROR_LOC( loc )
1915 );
1916
1917 case StaticContextConsts::decl_queue:
1918@@ -1566,7 +1722,7 @@
1919 }
1920 }
1921 coll = GENV_STORE.getCollection(aName, aDynamicCollection);
1922- if (coll == NULL)
1923+ if (coll == NULL)
1924 {
1925 throw XQUERY_EXCEPTION(
1926 zerr::ZDDY0003_COLLECTION_DOES_NOT_EXIST,
1927@@ -1574,7 +1730,7 @@
1928 ERROR_LOC( aLoc )
1929 );
1930 }
1931- if (collectionDecl &&
1932+ if (collectionDecl &&
1933 collectionDecl->getOrderProperty() == StaticContextConsts::decl_unordered)
1934 {
1935 throw XQUERY_EXCEPTION(
1936@@ -1617,7 +1773,7 @@
1937 numNodes = numNodesItem->getIntegerValue();
1938 }
1939
1940- if (collection->size() < numNodes)
1941+ if (collection->size() < numNodes)
1942 {
1943 throw XQUERY_EXCEPTION(
1944 zerr::ZDDY0011_COLLECTION_NODE_NOT_FOUND,
1945@@ -1681,7 +1837,7 @@
1946 store::Collection_t& coll) const
1947 {
1948 const StaticallyKnownCollection* collectionDecl = aSctx->lookup_collection(aName);
1949- if (collectionDecl == 0 && !aDynamicCollection)
1950+ if (collectionDecl == 0 && !aDynamicCollection)
1951 {
1952 throw XQUERY_EXCEPTION(
1953 zerr::ZDDY0001_COLLECTION_NOT_DECLARED,
1954@@ -1691,27 +1847,27 @@
1955 }
1956
1957 if (!aDynamicCollection) {
1958- switch(collectionDecl->getUpdateProperty())
1959+ switch(collectionDecl->getUpdateProperty())
1960 {
1961 case StaticContextConsts::decl_const:
1962 throw XQUERY_EXCEPTION(
1963 zerr::ZDDY0004_COLLECTION_CONST_UPDATE,
1964 ERROR_PARAMS( aName->getStringValue() ),
1965- ERROR_LOC( loc )
1966+ ERROR_LOC( loc )
1967 );
1968
1969 case StaticContextConsts::decl_append_only:
1970 throw XQUERY_EXCEPTION(
1971 zerr::ZDDY0007_COLLECTION_APPEND_BAD_DELETE,
1972 ERROR_PARAMS( aName->getStringValue() ),
1973- ERROR_LOC( loc )
1974+ ERROR_LOC( loc )
1975 );
1976
1977 case StaticContextConsts::decl_queue:
1978 throw XQUERY_EXCEPTION(
1979 zerr::ZDDY0008_COLLECTION_QUEUE_BAD_DELETE,
1980 ERROR_PARAMS( aName->getStringValue() ),
1981- ERROR_LOC( loc )
1982+ ERROR_LOC( loc )
1983 );
1984
1985 case StaticContextConsts::decl_mutable:
1986@@ -1723,7 +1879,7 @@
1987 }
1988 }
1989 coll = GENV_STORE.getCollection(aName, aDynamicCollection);
1990- if (coll == NULL)
1991+ if (coll == NULL)
1992 {
1993 throw XQUERY_EXCEPTION(
1994 zerr::ZDDY0003_COLLECTION_DOES_NOT_EXIST,
1995@@ -1760,7 +1916,7 @@
1996
1997 consumeNext(lName, theChildren[0].getp(), planState);
1998
1999- try
2000+ try
2001 {
2002 (void)getCollection(theSctx, lName, loc, theDynamicCollection, lCollection);
2003 }
2004@@ -1791,7 +1947,7 @@
2005 store::Collection_t& coll) const
2006 {
2007 const StaticallyKnownCollection* collectionDecl = aSctx->lookup_collection(aName);
2008- if (collectionDecl == 0 && !aDynamicCollection)
2009+ if (collectionDecl == 0 && !aDynamicCollection)
2010 {
2011 throw XQUERY_EXCEPTION(
2012 zerr::ZDDY0001_COLLECTION_NOT_DECLARED,
2013@@ -1800,7 +1956,7 @@
2014 );
2015 }
2016 coll = GENV_STORE.getCollection(aName, aDynamicCollection);
2017- if (coll == NULL)
2018+ if (coll == NULL)
2019 {
2020 throw XQUERY_EXCEPTION(
2021 zerr::ZDDY0003_COLLECTION_DOES_NOT_EXIST,
2022@@ -1816,7 +1972,7 @@
2023 ********************************************************************************/
2024 AvailableCollectionsIteratorState::~AvailableCollectionsIteratorState()
2025 {
2026- if ( nameItState != NULL )
2027+ if ( nameItState != NULL )
2028 {
2029 nameItState->close();
2030 nameItState = NULL;
2031@@ -1852,7 +2008,7 @@
2032 if (theDynamicCollection)
2033 {
2034 for ((state->nameItState = GENV_STORE.listCollectionNames(theDynamicCollection))->open ();
2035- state->nameItState->next(nameItem);)
2036+ state->nameItState->next(nameItem);)
2037 {
2038 result = nameItem;
2039 STACK_PUSH( true, state);
2040@@ -1862,7 +2018,7 @@
2041 {
2042 // static collections have to exist and need to be declared
2043 for ((state->nameItState = theSctx->collection_names())->open ();
2044- state->nameItState->next(nameItem);)
2045+ state->nameItState->next(nameItem);)
2046 {
2047 if (!GENV_STORE.getCollection(nameItem.getp()))
2048 {
2049@@ -1946,7 +2102,7 @@
2050 DEFAULT_STACK_INIT(AvailableIndexesIteratorState, state, planState);
2051
2052 for ((state->nameItState = GENV_STORE.listIndexNames())->open ();
2053- state->nameItState->next(nameItem); )
2054+ state->nameItState->next(nameItem); )
2055 {
2056 result = nameItem;
2057 STACK_PUSH( true, state);
2058@@ -1959,7 +2115,7 @@
2059
2060 /*******************************************************************************
2061 *******************************************************************************/
2062-bool IsActivatedICIterator::nextImpl(store::Item_t& result,
2063+bool IsActivatedICIterator::nextImpl(store::Item_t& result,
2064 PlanState& planState) const
2065 {
2066 PlanIteratorState *state;
2067@@ -2009,7 +2165,7 @@
2068 }
2069
2070 bool
2071-ActivatedICsIterator::nextImpl(store::Item_t& result,
2072+ActivatedICsIterator::nextImpl(store::Item_t& result,
2073 PlanState& planState) const
2074 {
2075 store::Item_t nameItem;
2076@@ -2018,7 +2174,7 @@
2077 DEFAULT_STACK_INIT(ActivatedICsIteratorState, state, planState);
2078
2079 for ((state->nameItState = GENV_STORE.listActiveICNames())->open ();
2080- state->nameItState->next(nameItem); )
2081+ state->nameItState->next(nameItem); )
2082 {
2083 result = nameItem;
2084 STACK_PUSH( true, state);
2085
2086=== added file 'src/runtime/collections/collections_impl.h'
2087--- src/runtime/collections/collections_impl.h 1970-01-01 00:00:00 +0000
2088+++ src/runtime/collections/collections_impl.h 2011-10-21 00:32:19 +0000
2089@@ -0,0 +1,78 @@
2090+/*
2091+ * Copyright 2006-2008 The FLWOR Foundation.
2092+ *
2093+ * Licensed under the Apache License, Version 2.0 (the "License");
2094+ * you may not use this file except in compliance with the License.
2095+ * You may obtain a copy of the License at
2096+ *
2097+ * http://www.apache.org/licenses/LICENSE2.0
2098+ *
2099+ * Unless required by applicable law or agreed to in writing, software
2100+ * distributed under the License is distributed on an "AS IS" BASIS,
2101+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2102+ * See the License for the specific language governing permissions and
2103+ * limitations under the License.
2104+ */
2105+#pragma once
2106+#ifndef ZORBA_RUNTIME_COLLECTIONS_COLLECTIONS_IMPL_H
2107+#define ZORBA_RUNTIME_COLLECTIONS_COLLECTIONS_IMPL_H
2108+
2109+#include "common/shared_types.h"
2110+
2111+#include "runtime/base/unarybase.h"
2112+#include "runtime/collections/collections_base.h"
2113+
2114+namespace zorba{
2115+
2116+/*******************************************************************************
2117+ Iterator to optimize a fn:count(collection) expression
2118+
2119+ theCollectionType:
2120+ ------------------
2121+ Whether the Collection is a W3C or Zorba Collection and if it's dynamic or
2122+ static collection module.
2123+********************************************************************************/
2124+class CountCollectionIterator : public NaryBaseIterator<CountCollectionIterator,
2125+ PlanIteratorState>
2126+{
2127+public:
2128+ enum CollectionType { W3C = 0, ZORBASTATIC = 1, ZORBADYNAMIC = 2 };
2129+
2130+protected:
2131+ CollectionType theCollectionType;
2132+
2133+public:
2134+ SERIALIZABLE_CLASS(CountCollectionIterator);
2135+
2136+ SERIALIZABLE_CLASS_CONSTRUCTOR2T(CountCollectionIterator,
2137+ NaryBaseIterator<CountCollectionIterator, PlanIteratorState>);
2138+
2139+ void serialize(::zorba::serialization::Archiver& ar);
2140+
2141+public:
2142+ CountCollectionIterator(
2143+ static_context* sctx,
2144+ const QueryLoc& loc,
2145+ std::vector<PlanIter_t>& children,
2146+ CollectionType collectionType);
2147+
2148+ ~CountCollectionIterator();
2149+
2150+ bool isZorbaCollection() const { return W3C != theCollectionType; }
2151+
2152+ bool isDynamicCollection() const { return ZORBADYNAMIC == theCollectionType; }
2153+
2154+ void accept(PlanIterVisitor& v) const;
2155+
2156+ bool nextImpl(store::Item_t& result, PlanState& aPlanState) const;
2157+
2158+protected:
2159+ store::Collection_t getZorbaCollection(PlanState& planState) const;
2160+
2161+ store::Collection_t getW3CCollection(PlanState& planState) const;
2162+};
2163+
2164+} //namespace zorba
2165+#endif /* ZORBA_RUNTIME_COLLECTIONS_COLLECTIONS_IMPL_H */
2166+/* vim:set et sw=2 ts=2: */
2167+
2168
2169=== modified file 'src/runtime/collections/pregenerated/collections.h'
2170--- src/runtime/collections/pregenerated/collections.h 2011-08-12 16:07:57 +0000
2171+++ src/runtime/collections/pregenerated/collections.h 2011-10-21 00:32:19 +0000
2172@@ -134,6 +134,8 @@
2173
2174 virtual ~ZorbaCollectionIterator();
2175
2176+ bool isDynamic() const { return theDynamicCollection; }
2177+
2178 public:
2179 const StaticallyKnownCollection* getCollection(const static_context* sctx, const store::Item_t& name, const QueryLoc& loc, bool dyn_coll, store::Collection_t& coll) const;
2180 void accept(PlanIterVisitor& v) const;
2181
2182=== modified file 'src/runtime/sequences/pregenerated/sequences.h'
2183--- src/runtime/sequences/pregenerated/sequences.h 2011-05-05 15:10:24 +0000
2184+++ src/runtime/sequences/pregenerated/sequences.h 2011-10-21 00:32:19 +0000
2185@@ -92,22 +92,22 @@
2186
2187 /**
2188 *
2189- * Summary: Returns a sequence of positive integers giving the positions
2190- * within the sequence $seqParam of items that are equal to $srchParam.
2191- *
2192- * The collation used by the invocation of this function is determined
2193- * according to the rules in 7.3.1 Collations. The collation is used when
2194- * string comparison is required.
2195- *
2196- * The items in the sequence $seqParam are compared with $srchParam under
2197- * the rules for the 'eq' operator. Values that cannot be compared, i.e.
2198- * the 'eq' operator is not defined for their types, are considered to be
2199- * distinct. If an item compares equal, then the position of that item in
2200- * the sequence $seqParam is included in the result.
2201- *
2202- * If the value of $seqParam is the empty sequence, or if no item in
2203- * $seqParam matches $srchParam, then the empty sequence is returned.
2204- *
2205+ * Summary: Returns a sequence of positive integers giving the positions
2206+ * within the sequence $seqParam of items that are equal to $srchParam.
2207+ *
2208+ * The collation used by the invocation of this function is determined
2209+ * according to the rules in 7.3.1 Collations. The collation is used when
2210+ * string comparison is required.
2211+ *
2212+ * The items in the sequence $seqParam are compared with $srchParam under
2213+ * the rules for the 'eq' operator. Values that cannot be compared, i.e.
2214+ * the 'eq' operator is not defined for their types, are considered to be
2215+ * distinct. If an item compares equal, then the position of that item in
2216+ * the sequence $seqParam is included in the result.
2217+ *
2218+ * If the value of $seqParam is the empty sequence, or if no item in
2219+ * $seqParam matches $srchParam, then the empty sequence is returned.
2220+ *
2221 * The first item in a sequence is at position 1, not position 0.
2222 * The result sequence is in ascending numeric order.
2223 *
2224@@ -197,7 +197,7 @@
2225
2226 /**
2227 *
2228- * If the value of $arg is not the empty sequence, the function returns true;
2229+ * If the value of $arg is not the empty sequence, the function returns true;
2230 * otherwise, the function returns false.
2231 *
2232 * Author: Zorba Team
2233@@ -234,7 +234,7 @@
2234
2235 /**
2236 *
2237- * Returns the sequence that results from removing from arg all but one of a
2238+ * Returns the sequence that results from removing from arg all but one of a
2239 * set of values that are eq to one other. Values of type xs:untypedAtomic are
2240 * compared as if they were of type xs:string. Values that cannot be compared,
2241 * i.e. the eq operator is not defined for their types, are considered to be
2242@@ -763,8 +763,8 @@
2243 /**
2244 *
2245 * Hashing semi/anti join iterator.
2246- *
2247- * First producer goes in the result if a match in the second producer is
2248+ *
2249+ * First producer goes in the result if a match in the second producer is
2250 * found/not found. The order of the first producer is retained. No duplicate
2251 * elimination is performed.
2252 *
2253@@ -826,7 +826,7 @@
2254 * First producer goes in the result if a match in the second producer is found.
2255 * Precondition: both inputs must be sorted.
2256 * Postcondition: the order of the first producer is retained.
2257- *
2258+ *
2259 * If either of the inputs is guaranteed to contain no duplicates, then the
2260 * output will be duplicate-free. Otherwise the output may contain duplicates.
2261 *
2262@@ -934,7 +934,7 @@
2263
2264 /**
2265 *
2266- * Returns a value obtained by adding together the values in $arg. If $zero is
2267+ * Returns a value obtained by adding together the values in $arg. If $zero is
2268 * not specified, then the value returned for an empty sequence is the xs:integer
2269 * value 0. If $zero is specified, then the value returned for an empty sequence
2270 * is $zero.
2271@@ -1167,7 +1167,7 @@
2272 /**
2273 *
2274 * Returns the sequence of element nodes that are in the target document and have
2275- * an ID value matching the value of one or more of the IDREF values supplied in
2276+ * an ID value matching the value of one or more of the IDREF values supplied in
2277 * $arg. The target document is the document containing $node, or the document
2278 * containing the context item (.) if the second argument is omitted.
2279 *
2280
2281=== modified file 'src/runtime/spec/collections/collections.xml'
2282--- src/runtime/spec/collections/collections.xml 2011-08-12 16:07:57 +0000
2283+++ src/runtime/spec/collections/collections.xml 2011-10-21 00:32:19 +0000
2284@@ -10,7 +10,7 @@
2285 xmlns:zorba="http://www.zorba-xquery.com"
2286 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2287 xsi:schemaLocation="http://www.zorba-xquery.com ../runtime.xsd">
2288-
2289+
2290 <zorba:source>
2291 <zorba:include form="Quoted">store/api/iterator.h</zorba:include>
2292 </zorba:source>
2293@@ -54,7 +54,7 @@
2294 <zorba:member type="bool" name="theIteratorOpened" defaultValue="false"
2295 brief="flag indicating whether theIterator was opened"/>
2296 </zorba:state>
2297-
2298+
2299 </zorba:iterator>
2300
2301 <!--
2302@@ -81,7 +81,7 @@
2303
2304 <zorba:methods>
2305 <zorba:accessesDynCtx returnValue="true"/>
2306- <zorba:isSource returnValue="true"/>
2307+ <zorba:isSource returnValue="true"/>
2308 <zorba:producesDistinctNodes returnValue="YES"/>
2309 <zorba:producesSortedNodes returnValue="YES"/>
2310 </zorba:methods>
2311@@ -102,6 +102,7 @@
2312 </zorba:method>
2313
2314 <zorba:member type="bool" name="theDynamicCollection"
2315+ getterName="isDynamic"
2316 brief="whether it's the function of the dynamic or the static collection module"/>
2317
2318 <zorba:state generateInit="false" generateReset="false" generateDestructor="false">
2319@@ -110,7 +111,7 @@
2320 <zorba:member type="bool" name="theIteratorOpened" defaultValue="false"
2321 brief="flag indicating whether theIterator was opened"/>
2322 </zorba:state>
2323-
2324+
2325 </zorba:iterator>
2326
2327 <!--
2328@@ -296,7 +297,7 @@
2329
2330 <zorba:methods>
2331 <zorba:getScriptingKind returnValue="UPDATING_EXPR"/>
2332- <zorba:accessesDynCtx returnValue="true"/>
2333+ <zorba:accessesDynCtx returnValue="true"/>
2334 </zorba:methods>
2335
2336 </zorba:function>
2337@@ -735,7 +736,7 @@
2338 </zorba:state>
2339
2340 </zorba:iterator>
2341-
2342+
2343
2344 <!--
2345 /*******************************************************************************
2346@@ -1110,8 +1111,8 @@
2347 </zorba:methods>
2348 </zorba:function>
2349
2350- <zorba:state generateInit="false"
2351- generateReset="false"
2352+ <zorba:state generateInit="false"
2353+ generateReset="false"
2354 generateDestructor="false">
2355 <zorba:member type="store::Iterator_t" name="nameItState"
2356 brief="the current iterator"/>
2357
2358=== modified file 'src/runtime/spec/sequences/sequences.xml'
2359--- src/runtime/spec/sequences/sequences.xml 2011-06-17 14:40:56 +0000
2360+++ src/runtime/spec/sequences/sequences.xml 2011-10-21 00:32:19 +0000
2361@@ -22,7 +22,7 @@
2362 <zorba:source>
2363 <zorba:include form="Quoted">runtime/util/handle_hashset_item_value.h</zorba:include>
2364 </zorba:source>
2365-
2366+
2367 <zorba:codegen>
2368 <zorba:cpp>
2369 <zorba:include form="Quoted">system/globalenv.h</zorba:include>
2370@@ -72,35 +72,35 @@
2371 /*******************************************************************************
2372 15.1.3 fn:index-of($seqParam as xs:anyAtomicType*,
2373 $srchParam as xs:anyAtomicType) as xs:integer*
2374-
2375+
2376 fn:index-of($seqParam as xs:anyAtomicType*,
2377 $srchParam as xs:anyAtomicType,
2378 $collation as xs:string) as xs:integer*
2379 ********************************************************************************/
2380 -->
2381 <zorba:iterator name="FnIndexOfIterator">
2382-
2383+
2384 <zorba:description author="Zorba Team">
2385- Summary: Returns a sequence of positive integers giving the positions
2386- within the sequence $seqParam of items that are equal to $srchParam.
2387-
2388- The collation used by the invocation of this function is determined
2389- according to the rules in 7.3.1 Collations. The collation is used when
2390- string comparison is required.
2391-
2392- The items in the sequence $seqParam are compared with $srchParam under
2393- the rules for the 'eq' operator. Values that cannot be compared, i.e.
2394- the 'eq' operator is not defined for their types, are considered to be
2395- distinct. If an item compares equal, then the position of that item in
2396- the sequence $seqParam is included in the result.
2397-
2398- If the value of $seqParam is the empty sequence, or if no item in
2399- $seqParam matches $srchParam, then the empty sequence is returned.
2400-
2401+ Summary: Returns a sequence of positive integers giving the positions
2402+ within the sequence $seqParam of items that are equal to $srchParam.
2403+
2404+ The collation used by the invocation of this function is determined
2405+ according to the rules in 7.3.1 Collations. The collation is used when
2406+ string comparison is required.
2407+
2408+ The items in the sequence $seqParam are compared with $srchParam under
2409+ the rules for the 'eq' operator. Values that cannot be compared, i.e.
2410+ the 'eq' operator is not defined for their types, are considered to be
2411+ distinct. If an item compares equal, then the position of that item in
2412+ the sequence $seqParam is included in the result.
2413+
2414+ If the value of $seqParam is the empty sequence, or if no item in
2415+ $seqParam matches $srchParam, then the empty sequence is returned.
2416+
2417 The first item in a sequence is at position 1, not position 0.
2418 The result sequence is in ascending numeric order.
2419 </zorba:description>
2420-
2421+
2422 <zorba:function >
2423
2424 <zorba:signature localname="index-of" prefix="fn">
2425@@ -137,12 +137,12 @@
2426 ********************************************************************************/
2427 -->
2428 <zorba:iterator name="FnEmptyIterator">
2429-
2430+
2431 <zorba:description author="Zorba Team">
2432 If the value of $arg is the empty sequence, the function returns true;
2433 otherwise, the function returns false.
2434 </zorba:description>
2435-
2436+
2437 <zorba:function>
2438
2439 <zorba:signature localname="empty" prefix="fn">
2440@@ -151,13 +151,13 @@
2441 </zorba:signature>
2442
2443 <zorba:methods>
2444- <zorba:ignoresSortedNodes/>
2445- <zorba:ignoresDuplicateNodes/>
2446+ <zorba:ignoresSortedNodes/>
2447+ <zorba:ignoresDuplicateNodes/>
2448 </zorba:methods>
2449
2450 </zorba:function>
2451
2452-</zorba:iterator>
2453+</zorba:iterator>
2454
2455 <!--
2456 /*******************************************************************************
2457@@ -165,12 +165,12 @@
2458 ********************************************************************************/
2459 -->
2460 <zorba:iterator name="FnExistsIterator">
2461-
2462+
2463 <zorba:description author="Zorba Team">
2464- If the value of $arg is not the empty sequence, the function returns true;
2465+ If the value of $arg is not the empty sequence, the function returns true;
2466 otherwise, the function returns false.
2467 </zorba:description>
2468-
2469+
2470 <zorba:function >
2471 <zorba:signature localname="exists" prefix="fn">
2472 <zorba:param>item()*</zorba:param>
2473@@ -178,8 +178,8 @@
2474 </zorba:signature>
2475
2476 <zorba:methods>
2477- <zorba:ignoresSortedNodes/>
2478- <zorba:ignoresDuplicateNodes/>
2479+ <zorba:ignoresSortedNodes/>
2480+ <zorba:ignoresDuplicateNodes/>
2481 </zorba:methods>
2482 </zorba:function>
2483
2484@@ -194,9 +194,9 @@
2485 ********************************************************************************/
2486 -->
2487 <zorba:iterator name="FnDistinctValuesIterator">
2488-
2489+
2490 <zorba:description author="Zorba Team">
2491- Returns the sequence that results from removing from arg all but one of a
2492+ Returns the sequence that results from removing from arg all but one of a
2493 set of values that are eq to one other. Values of type xs:untypedAtomic are
2494 compared as if they were of type xs:string. Values that cannot be compared,
2495 i.e. the eq operator is not defined for their types, are considered to be
2496@@ -206,7 +206,7 @@
2497 </zorba:description>
2498
2499 <zorba:function>
2500-
2501+
2502 <zorba:signature localname="distinct-values" prefix="fn">
2503 <zorba:param>xs:anyAtomicType*</zorba:param>
2504 <zorba:param>xs:string</zorba:param>
2505@@ -221,7 +221,7 @@
2506 <zorba:methods>
2507 <zorba:getReturnType/>
2508 <zorba:ignoresSortedNodes/>
2509- <zorba:ignoresDuplicateNodes/>
2510+ <zorba:ignoresDuplicateNodes/>
2511 </zorba:methods>
2512
2513 </zorba:function>
2514@@ -244,16 +244,16 @@
2515 15.1.7 fn:insert-before($target as item()*,
2516 $position as xs:integer,
2517 $inserts as item()*) as item()*
2518-********************************************************************************/
2519+********************************************************************************/
2520 -->
2521 <zorba:iterator name="FnInsertBeforeIterator">
2522-
2523+
2524 <zorba:description author="Zorba Team">
2525 Returns a new sequence constructed from the value of the first parameter with
2526 the value of third parameter inserted at the position specified by the value
2527 of the second parameter.
2528 </zorba:description>
2529-
2530+
2531 <zorba:function>
2532
2533 <zorba:signature localname="insert-before" prefix="fn">
2534@@ -265,7 +265,7 @@
2535
2536 <zorba:methods>
2537 <zorba:ignoresSortedNodes/>
2538- <zorba:ignoresDuplicateNodes/>
2539+ <zorba:ignoresDuplicateNodes/>
2540 </zorba:methods>
2541
2542 </zorba:function>
2543@@ -289,12 +289,12 @@
2544 ********************************************************************************/
2545 -->
2546 <zorba:iterator name="FnRemoveIterator">
2547-
2548+
2549 <zorba:description author="Zorba Team">
2550 Returns a new sequence constructed from the value of aTarget with the item at
2551 the position specified by the value of aPosition removed.
2552 </zorba:description>
2553-
2554+
2555 <zorba:function>
2556
2557 <zorba:signature localname="remove" prefix="fn">
2558@@ -309,7 +309,7 @@
2559 <zorba:propagatesDistinctNodes producer="0"/>
2560 <zorba:propagatesSortedNodes producer="0"/>
2561 <zorba:ignoresSortedNodes/>
2562- <zorba:ignoresDuplicateNodes/>
2563+ <zorba:ignoresDuplicateNodes/>
2564 </zorba:methods>
2565
2566 </zorba:function>
2567@@ -317,10 +317,10 @@
2568 <zorba:state>
2569 <zorba:member type="xs_integer" name="theCurrentPos"
2570 defaultValue="xs_integer::zero()" brief="the current position in the sequence"/>
2571-
2572+
2573 <zorba:member type="xs_integer" name="thePosition"
2574 defaultValue="xs_integer::zero()" brief="the position to delete"/>
2575-
2576+
2577 <zorba:member type="XQPCollator*" name="theCollator"
2578 defaultValue="0" brief="the collator"/>
2579 </zorba:state>
2580@@ -333,23 +333,23 @@
2581 ********************************************************************************/
2582 -->
2583 <zorba:iterator name="FnReverseIterator">
2584-
2585+
2586 <zorba:description author="Zorba Team">
2587 fn:reverse
2588 </zorba:description>
2589-
2590+
2591 <zorba:function>
2592
2593- <zorba:signature localname="reverse" prefix="fn">
2594+ <zorba:signature localname="reverse" prefix="fn">
2595 <zorba:param>item()*</zorba:param>
2596- <zorba:output>item()*</zorba:output>
2597+ <zorba:output>item()*</zorba:output>
2598 </zorba:signature>
2599
2600 <zorba:methods>
2601 <zorba:getReturnType/>
2602 <zorba:propagatesDistinctNodes producer="0"/>
2603 <zorba:ignoresSortedNodes/>
2604- <zorba:ignoresDuplicateNodes/>
2605+ <zorba:ignoresDuplicateNodes/>
2606 </zorba:methods>
2607
2608 </zorba:function>
2609@@ -371,13 +371,13 @@
2610 $length as xs:double) as item()*
2611 ********************************************************************************/
2612 -->
2613-<zorba:iterator name="FnSubsequenceIterator"
2614+<zorba:iterator name="FnSubsequenceIterator"
2615 generateResetImpl="true">
2616-
2617+
2618 <zorba:description author="Zorba Team">
2619 fn:subsequence
2620 </zorba:description>
2621-
2622+
2623 <zorba:function generateCodegen="false">
2624
2625 <zorba:signature localname="subsequence" prefix="fn">
2626@@ -409,7 +409,7 @@
2627 <zorba:member type="bool" name="theIsChildReset" defaultValue="false"/>
2628
2629 </zorba:state>
2630-
2631+
2632 </zorba:iterator>
2633
2634
2635@@ -418,13 +418,13 @@
2636 zorbaop:subsequence-int
2637 ********************************************************************************/
2638 -->
2639-<zorba:iterator name="SubsequenceIntIterator"
2640+<zorba:iterator name="SubsequenceIntIterator"
2641 generateResetImpl="true">
2642-
2643+
2644 <zorba:description author="Zorba Team">
2645 zorbaop:subsequence-int
2646 </zorba:description>
2647-
2648+
2649 <zorba:function generateCodegen="false">
2650
2651 <zorba:signature localname="subsequence-int" prefix="op-zorba">
2652@@ -455,7 +455,7 @@
2653 <zorba:member type="bool" name="theIsChildReset" defaultValue="false"/>
2654
2655 </zorba:state>
2656-
2657+
2658 </zorba:iterator>
2659
2660
2661@@ -467,11 +467,11 @@
2662 -->
2663 <zorba:iterator name="SequencePointAccessIterator"
2664 generateResetImpl="true">
2665-
2666+
2667 <zorba:description author="Zorba Team">
2668 zorbaop:sequence-point-access
2669 </zorba:description>
2670-
2671+
2672 <zorba:function generateCodegen="false">
2673
2674 <zorba:signature localname="sequence-point-access" prefix="op-zorba">
2675@@ -483,7 +483,7 @@
2676 <zorba:methods>
2677 <zorba:getReturnType/>
2678 <zorba:propagatesDistinctNodes producer="0"/>
2679- <zorba:propagatesSortedNodes producer="0"/>
2680+ <zorba:propagatesSortedNodes producer="0"/>
2681 </zorba:methods>
2682
2683 </zorba:function>
2684@@ -491,7 +491,7 @@
2685 <zorba:state>
2686 <zorba:member type="bool" name="theIsChildReset" defaultValue="false"/>
2687 </zorba:state>
2688-
2689+
2690 </zorba:iterator>
2691
2692
2693@@ -510,11 +510,11 @@
2694 ********************************************************************************/
2695 -->
2696 <zorba:iterator name="FnZeroOrOneIterator">
2697-
2698+
2699 <zorba:description author="Zorba Team">
2700 Returns $arg if it contains zero or one items. Otherwise, raises err:FORG0003.
2701 </zorba:description>
2702-
2703+
2704 <zorba:function generateCodegen="false">
2705 <zorba:signature localname="zero-or-one" prefix="fn">
2706 <zorba:param>item()*</zorba:param>
2707@@ -531,9 +531,9 @@
2708 <zorba:constructor>
2709 <zorba:parameter type="bool" name="doDistinct" defaultValue="false"/>
2710 </zorba:constructor>
2711-
2712+
2713 <zorba:member type="bool" name="theDoDistinct" brief=""/>
2714-
2715+
2716 </zorba:iterator>
2717
2718 <!--
2719@@ -542,25 +542,25 @@
2720 ********************************************************************************/
2721 -->
2722 <zorba:iterator name="FnOneOrMoreIterator">
2723-
2724+
2725 <zorba:description author="Zorba Team">
2726 Returns $arg if it contains one or more items. Otherwise, raises err:FORG0004.
2727 </zorba:description>
2728-
2729+
2730 <zorba:function>
2731
2732 <zorba:signature localname="one-or-more" prefix="fn">
2733 <zorba:param>item()*</zorba:param>
2734- <zorba:output>item()+</zorba:output>
2735+ <zorba:output>item()+</zorba:output>
2736 </zorba:signature>
2737
2738 <zorba:methods>
2739 <zorba:getReturnType/>
2740 <zorba:isMap producer="0"/>
2741 <zorba:propagatesDistinctNodes producer="0"/>
2742- <zorba:propagatesSortedNodes producer="0"/>
2743+ <zorba:propagatesSortedNodes producer="0"/>
2744 <zorba:ignoresSortedNodes/>
2745- <zorba:ignoresDuplicateNodes/>
2746+ <zorba:ignoresDuplicateNodes/>
2747 </zorba:methods>
2748
2749 </zorba:function>
2750@@ -573,19 +573,19 @@
2751 ********************************************************************************/
2752 -->
2753 <zorba:iterator name="FnExactlyOneIterator" generateCodegen="false">
2754-
2755+
2756 <zorba:description author="Zorba Team">
2757 Returns $arg if it contains exactly one item. Otherwise, raises err:FORG0005.
2758 </zorba:description>
2759-
2760+
2761 <zorba:constructor>
2762 <zorba:parameter type="bool" name="raiseError" defaultValue="true"/>
2763 <zorba:parameter type="bool" name="doDistinct" defaultValue="false"/>
2764 </zorba:constructor>
2765-
2766+
2767 <zorba:member type="bool" name="theRaiseError" brief=""/>
2768 <zorba:member type="bool" name="theDoDistinct" brief=""/>
2769-
2770+
2771 </zorba:iterator>
2772
2773 <!--
2774@@ -599,14 +599,14 @@
2775 ********************************************************************************/
2776 -->
2777 <zorba:iterator name="FnDeepEqualIterator">
2778-
2779+
2780 <zorba:description author="Zorba Team">
2781 This function assesses whether two sequences are deep-equal to each other. To
2782 be deep-equal, they must contain items that are pairwise deep-equal; and for
2783 two items to be deep-equal, they must either be atomic values that compare equal,
2784 or nodes of the same kind, with the same name, whose children are deep-equal.
2785 </zorba:description>
2786-
2787+
2788 <zorba:function>
2789
2790 <zorba:signature localname="deep-equal" prefix="fn">
2791@@ -654,13 +654,13 @@
2792 ********************************************************************************/
2793 -->
2794
2795-<zorba:iterator name="HashSemiJoinIterator"
2796+<zorba:iterator name="HashSemiJoinIterator"
2797 generateCodegen="false">
2798-
2799+
2800 <zorba:description author="Zorba Team">
2801 Hashing semi/anti join iterator.
2802-
2803- First producer goes in the result if a match in the second producer is
2804+
2805+ First producer goes in the result if a match in the second producer is
2806 found/not found. The order of the first producer is retained. No duplicate
2807 elimination is performed.
2808 </zorba:description>
2809@@ -673,37 +673,37 @@
2810 <zorba:constructor>
2811 <zorba:parameter type="bool" name="antijoin" defaultValue="false"/>
2812 </zorba:constructor>
2813-
2814+
2815 <zorba:member type="bool" name="theAntijoin" brief=""/>
2816-
2817-</zorba:iterator>
2818-
2819-
2820-<zorba:iterator name="SortSemiJoinIterator"
2821+
2822+</zorba:iterator>
2823+
2824+
2825+<zorba:iterator name="SortSemiJoinIterator"
2826 generateCodegen="false">
2827-
2828+
2829 <zorba:description author="Zorba Team">
2830 Sortmerge based semijoin iterator.
2831
2832 First producer goes in the result if a match in the second producer is found.
2833 Precondition: both inputs must be sorted.
2834 Postcondition: the order of the first producer is retained.
2835-
2836+
2837 If either of the inputs is guaranteed to contain no duplicates, then the
2838 output will be duplicate-free. Otherwise the output may contain duplicates.
2839 </zorba:description>
2840 </zorba:iterator>
2841-
2842+
2843 <!--
2844 /*******************************************************************************
2845 15.4.1 fn:count($arg as item()*) as xs:integer
2846 ********************************************************************************/
2847 -->
2848 <zorba:iterator name="FnCountIterator">
2849-
2850+
2851 <zorba:description author="Zorba Team">fn:count</zorba:description>
2852-
2853- <zorba:function>
2854+
2855+ <zorba:function generateCodegen="false">
2856 <zorba:signature localname="count" prefix="fn">
2857 <zorba:param>item()*</zorba:param>
2858 <zorba:output>xs:integer</zorba:output>
2859@@ -716,18 +716,18 @@
2860 </zorba:function>
2861
2862 </zorba:iterator>
2863-
2864+
2865 <!--
2866 /*******************************************************************************
2867 15.4.2 fn:avg($arg as xs:anyAtomicType*) as xs:anyAtomicType?
2868 ********************************************************************************/
2869 -->
2870 <zorba:iterator name="FnAvgIterator">
2871-
2872+
2873 <zorba:description author="Zorba Team">
2874 fn:avg
2875 </zorba:description>
2876-
2877+
2878 <zorba:function >
2879 <zorba:signature localname="avg" prefix="fn">
2880 <zorba:param>xs:anyAtomicType*</zorba:param>
2881@@ -746,7 +746,7 @@
2882 /*******************************************************************************
2883 15.4.3 fn:max($arg as xs:anyAtomicType*) as xs:anyAtomicType?
2884
2885- fn:max($arg as xs:anyAtomicType*,
2886+ fn:max($arg as xs:anyAtomicType*,
2887 $collation as string) as xs:anyAtomicType?
2888 ********************************************************************************/
2889 -->
2890@@ -756,7 +756,7 @@
2891 /*******************************************************************************
2892 15.4.4 fn:min($arg as xs:anyAtomicType*) as xs:anyAtomicType?
2893
2894- fn:min($arg as xs:anyAtomicType*,
2895+ fn:min($arg as xs:anyAtomicType*,
2896 $collation as string) as xs:anyAtomicType?
2897 ********************************************************************************/
2898 -->
2899@@ -771,14 +771,14 @@
2900 ********************************************************************************/
2901 -->
2902 <zorba:iterator name="FnSumIterator">
2903-
2904+
2905 <zorba:description author="Zorba Team">
2906- Returns a value obtained by adding together the values in $arg. If $zero is
2907+ Returns a value obtained by adding together the values in $arg. If $zero is
2908 not specified, then the value returned for an empty sequence is the xs:integer
2909 value 0. If $zero is specified, then the value returned for an empty sequence
2910 is $zero.
2911 </zorba:description>
2912-
2913+
2914 <zorba:function specializable="true">
2915
2916 <zorba:signature localname="sum" prefix="fn">
2917@@ -802,11 +802,11 @@
2918
2919
2920 <zorba:iterator name="FnSumDoubleIterator">
2921-
2922+
2923 <zorba:description author="Zorba Team">
2924 fn:sum with arguments xs:double
2925 </zorba:description>
2926-
2927+
2928 <zorba:function>
2929
2930 <zorba:signature localname="sum_double" prefix="op">
2931@@ -830,11 +830,11 @@
2932
2933
2934 <zorba:iterator name="FnSumFloatIterator">
2935-
2936+
2937 <zorba:description author="Zorba Team">
2938 fn:sum with arguments xs:float
2939 </zorba:description>
2940-
2941+
2942 <zorba:function >
2943
2944 <zorba:signature localname="sum_float" prefix="op">
2945@@ -858,11 +858,11 @@
2946
2947
2948 <zorba:iterator name="FnSumDecimalIterator">
2949-
2950+
2951 <zorba:description author="Zorba Team">
2952 fn:sum with arguments xs:decimal
2953 </zorba:description>
2954-
2955+
2956 <zorba:function >
2957
2958 <zorba:signature localname="sum_decimal" prefix="op">
2959@@ -886,11 +886,11 @@
2960
2961
2962 <zorba:iterator name="FnSumIntegerIterator">
2963-
2964+
2965 <zorba:description author="Zorba Team">
2966 fn:sum with arguments xs:integer
2967 </zorba:description>
2968-
2969+
2970 <zorba:function >
2971
2972 <zorba:signature localname="sum_integer" prefix="op">
2973@@ -955,7 +955,7 @@
2974
2975 <zorba:description author="Zorba Team">
2976 Returns the sequence of element nodes that are in the target document and have
2977- an ID value matching the value of one or more of the IDREF values supplied in
2978+ an ID value matching the value of one or more of the IDREF values supplied in
2979 $arg. The target document is the document containing $node, or the document
2980 containing the context item (.) if the second argument is omitted.
2981 </zorba:description>
2982@@ -1089,9 +1089,9 @@
2983 ********************************************************************************/
2984 -->
2985 <zorba:iterator name="FnDocIterator">
2986-
2987+
2988 <zorba:description author="Zorba Team">fn:doc</zorba:description>
2989-
2990+
2991 <zorba:function>
2992
2993 <zorba:signature localname="doc" prefix="fn">
2994@@ -1115,9 +1115,9 @@
2995 ********************************************************************************/
2996 -->
2997 <zorba:iterator name="FnDocAvailableIterator">
2998-
2999+
3000 <zorba:description author="Zorba Team">fn:doc-available</zorba:description>
3001-
3002+
3003 <zorba:function>
3004 <zorba:signature localname="doc-available" prefix="fn">
3005 <zorba:param>xs:string?</zorba:param>
3006
3007=== modified file 'src/runtime/visitors/planiter_visitor_impl_code.h'
3008--- src/runtime/visitors/planiter_visitor_impl_code.h 2011-06-14 17:26:33 +0000
3009+++ src/runtime/visitors/planiter_visitor_impl_code.h 2011-10-21 00:32:19 +0000
3010@@ -355,4 +355,6 @@
3011 PLAN_ITER_VISITOR(ExitIterator);
3012 PLAN_ITER_VISITOR(ExitCatcherIterator);
3013 PLAN_ITER_VISITOR(FlowCtlIterator);
3014+
3015+PLAN_ITER_VISITOR(CountCollectionIterator);
3016 /* vim:set et sw=2 ts=2: */
3017
3018=== modified file 'src/runtime/visitors/planiter_visitor_impl_include.h'
3019--- src/runtime/visitors/planiter_visitor_impl_include.h 2011-06-14 17:26:33 +0000
3020+++ src/runtime/visitors/planiter_visitor_impl_include.h 2011-10-21 00:32:19 +0000
3021@@ -177,6 +177,8 @@
3022 class LoopIterator;
3023 class FlowCtlIterator;
3024
3025+class CountCollectionIterator;
3026+
3027 #define PLAN_ITER_VISITOR(class) \
3028 virtual void beginVisit ( const class& ) = 0; \
3029 virtual void endVisit ( const class& ) = 0
3030
3031=== modified file 'src/runtime/visitors/printer_visitor_impl.cpp'
3032--- src/runtime/visitors/printer_visitor_impl.cpp 2011-07-29 06:13:28 +0000
3033+++ src/runtime/visitors/printer_visitor_impl.cpp 2011-10-21 00:32:19 +0000
3034@@ -56,6 +56,7 @@
3035 #include "runtime/eval/eval.h"
3036 #include "runtime/misc/materialize.h"
3037 #include "runtime/scripting/scripting.h"
3038+#include "runtime/collections/collections_impl.h"
3039
3040 #ifdef ZORBA_WITH_DEBUGGER
3041 #include "debugger/debugger_commons.h"
3042@@ -186,7 +187,7 @@
3043 thePrinter.endEndVisit();
3044 }
3045
3046-void PrinterVisitor::beginVisit ( const TreatIterator& a )
3047+void PrinterVisitor::beginVisit ( const TreatIterator& a )
3048 {
3049 thePrinter.startBeginVisit("TreatIterator", ++theId);
3050 if (a.theCheckPrime)
3051@@ -197,13 +198,13 @@
3052 thePrinter.endBeginVisit(theId);
3053 }
3054
3055-void PrinterVisitor::endVisit ( const TreatIterator& )
3056+void PrinterVisitor::endVisit ( const TreatIterator& )
3057 {
3058 thePrinter.startEndVisit();
3059 thePrinter.endEndVisit();
3060 }
3061
3062-void PrinterVisitor::beginVisit ( const NumArithIterator<AddOperation>& a )
3063+void PrinterVisitor::beginVisit ( const NumArithIterator<AddOperation>& a )
3064 {
3065 thePrinter.startBeginVisit("NumArithIterator_AddOperation", ++theId);
3066 printCommons( &a, theId );
3067@@ -1116,7 +1117,7 @@
3068 }
3069
3070
3071-void PrinterVisitor::beginVisit(const CastIterator& a)
3072+void PrinterVisitor::beginVisit(const CastIterator& a)
3073 {
3074 thePrinter.startBeginVisit("CastIterator", ++theId);
3075 std::ostringstream lStream;
3076@@ -1154,26 +1155,26 @@
3077 thePrinter.endBeginVisit(theId);
3078 }
3079
3080-void PrinterVisitor::endVisit(const CastableIterator&)
3081+void PrinterVisitor::endVisit(const CastableIterator&)
3082 {
3083 thePrinter.startEndVisit();
3084 thePrinter.endEndVisit();
3085 }
3086
3087-void PrinterVisitor::beginVisit(const FTContainsIterator& a)
3088+void PrinterVisitor::beginVisit(const FTContainsIterator& a)
3089 {
3090 thePrinter.startBeginVisit("FTContainsIterator", ++theId);
3091 // TODO
3092 thePrinter.endBeginVisit(theId);
3093 }
3094
3095-void PrinterVisitor::endVisit(const FTContainsIterator&)
3096+void PrinterVisitor::endVisit(const FTContainsIterator&)
3097 {
3098 thePrinter.startEndVisit();
3099 thePrinter.endEndVisit();
3100 }
3101
3102-void PrinterVisitor::beginVisit(const flwor::OuterForIterator& a)
3103+void PrinterVisitor::beginVisit(const flwor::OuterForIterator& a)
3104 {
3105 thePrinter.startBeginVisit("flwor::OuterForIterator", ++theId);
3106 thePrinter.addAttribute("varname", a.getVarName()->getStringValue().str());
3107@@ -1181,7 +1182,7 @@
3108 thePrinter.endBeginVisit(theId);
3109 }
3110
3111-void PrinterVisitor::endVisit(const flwor::OuterForIterator&)
3112+void PrinterVisitor::endVisit(const flwor::OuterForIterator&)
3113 {
3114 thePrinter.startEndVisit();
3115 thePrinter.endEndVisit();
3116@@ -1389,5 +1390,7 @@
3117 PRINTER_VISITOR_DEFINITION(ExitCatcherIterator);
3118 PRINTER_VISITOR_DEFINITION(LoopIterator);
3119 PRINTER_VISITOR_DEFINITION(FlowCtlIterator);
3120+
3121+ PRINTER_VISITOR_DEFINITION(CountCollectionIterator);
3122 }
3123 /* vim:set et sw=2 ts=2: */
3124
3125=== modified file 'src/runtime/visitors/printer_visitor_impl.h'
3126--- src/runtime/visitors/printer_visitor_impl.h 2011-06-14 17:26:33 +0000
3127+++ src/runtime/visitors/printer_visitor_impl.h 2011-10-21 00:32:19 +0000
3128@@ -307,4 +307,6 @@
3129 DECLARE_VISITOR(ExitCatcherIterator);
3130 DECLARE_VISITOR(LoopIterator);
3131 DECLARE_VISITOR(FlowCtlIterator);
3132+
3133+ DECLARE_VISITOR(CountCollectionIterator);
3134 /* vim:set et sw=2 ts=2: */
3135
3136=== added directory 'test/rbkt/ExpCompilerResults/IterPlan/zorba/collections'
3137=== added file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/collections/count_dynamic_zorba_collection.iter'
3138--- test/rbkt/ExpCompilerResults/IterPlan/zorba/collections/count_dynamic_zorba_collection.iter 1970-01-01 00:00:00 +0000
3139+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/collections/count_dynamic_zorba_collection.iter 2011-10-21 00:32:19 +0000
3140@@ -0,0 +1,25 @@
3141+Iterator tree for main query:
3142+<SequentialIterator>
3143+ <CtxVarDeclareIterator varid="2" varname="coll">
3144+ <SingletonIterator value="xs:QName(,,collection)"/>
3145+ </CtxVarDeclareIterator>
3146+ <SequentialIterator>
3147+ <ApplyIterator>
3148+ <ZorbaCreateCollectionIterator>
3149+ <PromoteIterator type="xs:QName">
3150+ <FnDataIterator>
3151+ <CtxVarIterator varid="2" varname="coll" varkind="global"/>
3152+ </FnDataIterator>
3153+ </PromoteIterator>
3154+ </ZorbaCreateCollectionIterator>
3155+ </ApplyIterator>
3156+ <CountCollectionIterator>
3157+ <PromoteIterator type="xs:QName">
3158+ <FnDataIterator>
3159+ <CtxVarIterator varid="2" varname="coll" varkind="global"/>
3160+ </FnDataIterator>
3161+ </PromoteIterator>
3162+ </CountCollectionIterator>
3163+ </SequentialIterator>
3164+</SequentialIterator>
3165+
3166
3167=== added file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/collections/count_static_zorba_collection.iter'
3168--- test/rbkt/ExpCompilerResults/IterPlan/zorba/collections/count_static_zorba_collection.iter 1970-01-01 00:00:00 +0000
3169+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/collections/count_static_zorba_collection.iter 2011-10-21 00:32:19 +0000
3170@@ -0,0 +1,61 @@
3171+Iterator tree for main query:
3172+<SequentialIterator>
3173+ <CtxVarDeclareIterator varid="2" varname="ns:collection_1">
3174+ <SingletonIterator value="xs:QName(http://example.org/datamodule/,ns,collection_1)"/>
3175+ </CtxVarDeclareIterator>
3176+ <TreatIterator type="xs:QName" quant="">
3177+ <CtxVarIterator varid="2" varname="ns:collection_1" varkind="global"/>
3178+ </TreatIterator>
3179+ <CtxVarDeclareIterator varid="3" varname="ns:collection_2">
3180+ <SingletonIterator value="xs:QName(http://example.org/datamodule/,ns,collection_2)"/>
3181+ </CtxVarDeclareIterator>
3182+ <TreatIterator type="xs:QName" quant="">
3183+ <CtxVarIterator varid="3" varname="ns:collection_2" varkind="global"/>
3184+ </TreatIterator>
3185+ <CtxVarDeclareIterator varid="4" varname="ns:http">
3186+ <SingletonIterator value="xs:QName(http://example.org/datamodule/,ns,http)"/>
3187+ </CtxVarDeclareIterator>
3188+ <TreatIterator type="xs:QName" quant="">
3189+ <CtxVarIterator varid="4" varname="ns:http" varkind="global"/>
3190+ </TreatIterator>
3191+ <CtxVarDeclareIterator varid="5" varname="ns:test1">
3192+ <SingletonIterator value="xs:QName(http://example.org/datamodule/,ns,test1)"/>
3193+ </CtxVarDeclareIterator>
3194+ <TreatIterator type="xs:QName" quant="">
3195+ <CtxVarIterator varid="5" varname="ns:test1" varkind="global"/>
3196+ </TreatIterator>
3197+ <CtxVarDeclareIterator varid="6" varname="ns:test2">
3198+ <SingletonIterator value="xs:QName(http://example.org/datamodule/,ns,test2)"/>
3199+ </CtxVarDeclareIterator>
3200+ <TreatIterator type="xs:QName" quant="">
3201+ <CtxVarIterator varid="6" varname="ns:test2" varkind="global"/>
3202+ </TreatIterator>
3203+ <CtxVarDeclareIterator varid="7" varname="ns:test3">
3204+ <SingletonIterator value="xs:QName(http://example.org/datamodule/,ns,test3)"/>
3205+ </CtxVarDeclareIterator>
3206+ <TreatIterator type="xs:QName" quant="">
3207+ <CtxVarIterator varid="7" varname="ns:test3" varkind="global"/>
3208+ </TreatIterator>
3209+ <CtxVarDeclareIterator varid="8" varname="coll">
3210+ <SingletonIterator value="xs:QName(http://example.org/datamodule/,ns,test1)"/>
3211+ </CtxVarDeclareIterator>
3212+ <SequentialIterator>
3213+ <ApplyIterator>
3214+ <ZorbaCreateCollectionIterator>
3215+ <PromoteIterator type="xs:QName">
3216+ <FnDataIterator>
3217+ <CtxVarIterator varid="8" varname="coll" varkind="global"/>
3218+ </FnDataIterator>
3219+ </PromoteIterator>
3220+ </ZorbaCreateCollectionIterator>
3221+ </ApplyIterator>
3222+ <CountCollectionIterator>
3223+ <PromoteIterator type="xs:QName">
3224+ <FnDataIterator>
3225+ <CtxVarIterator varid="8" varname="coll" varkind="global"/>
3226+ </FnDataIterator>
3227+ </PromoteIterator>
3228+ </CountCollectionIterator>
3229+ </SequentialIterator>
3230+</SequentialIterator>
3231+
3232
3233=== added file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/collections/count_w3c_collection.iter'
3234--- test/rbkt/ExpCompilerResults/IterPlan/zorba/collections/count_w3c_collection.iter 1970-01-01 00:00:00 +0000
3235+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/collections/count_w3c_collection.iter 2011-10-21 00:32:19 +0000
3236@@ -0,0 +1,35 @@
3237+Iterator tree for main query:
3238+<SequentialIterator>
3239+ <CtxVarDeclareIterator varid="2" varname="coll">
3240+ <SingletonIterator value="xs:string(http://www.zorba-xquery.com/collection)"/>
3241+ </CtxVarDeclareIterator>
3242+ <SequentialIterator>
3243+ <ApplyIterator>
3244+ <UDFunctionCallIterator>
3245+ <PromoteIterator type="xs:string">
3246+ <FnDataIterator>
3247+ <CtxVarIterator varid="2" varname="coll" varkind="global"/>
3248+ </FnDataIterator>
3249+ </PromoteIterator>
3250+ </UDFunctionCallIterator>
3251+ </ApplyIterator>
3252+ <CountCollectionIterator>
3253+ <PromoteIterator type="xs:string">
3254+ <FnDataIterator>
3255+ <CtxVarIterator varid="2" varname="coll" varkind="global"/>
3256+ </FnDataIterator>
3257+ </PromoteIterator>
3258+ </CountCollectionIterator>
3259+ </SequentialIterator>
3260+</SequentialIterator>
3261+
3262+Iterator tree for ddl:create:
3263+<ZorbaCreateCollectionIterator>
3264+ <FunctionTraceIterator>
3265+ <QNameIterator>
3266+ <LetVarIterator varname="coll-name"/>
3267+ <SingletonIterator value="xs:string(zorba-internal-name-for-w3c-collections)"/>
3268+ </QNameIterator>
3269+ </FunctionTraceIterator>
3270+</ZorbaCreateCollectionIterator>
3271+
3272
3273=== added file 'test/rbkt/ExpQueryResults/zorba/collections/count_dynamic_zorba_collection.xml.res'
3274--- test/rbkt/ExpQueryResults/zorba/collections/count_dynamic_zorba_collection.xml.res 1970-01-01 00:00:00 +0000
3275+++ test/rbkt/ExpQueryResults/zorba/collections/count_dynamic_zorba_collection.xml.res 2011-10-21 00:32:19 +0000
3276@@ -0,0 +1,2 @@
3277+<?xml version="1.0" encoding="UTF-8"?>
3278+0
3279\ No newline at end of file
3280
3281=== added file 'test/rbkt/ExpQueryResults/zorba/collections/count_static_zorba_collection.xml.res'
3282--- test/rbkt/ExpQueryResults/zorba/collections/count_static_zorba_collection.xml.res 1970-01-01 00:00:00 +0000
3283+++ test/rbkt/ExpQueryResults/zorba/collections/count_static_zorba_collection.xml.res 2011-10-21 00:32:19 +0000
3284@@ -0,0 +1,2 @@
3285+<?xml version="1.0" encoding="UTF-8"?>
3286+0
3287\ No newline at end of file
3288
3289=== added file 'test/rbkt/ExpQueryResults/zorba/collections/count_w3c_collection.xml.res'
3290--- test/rbkt/ExpQueryResults/zorba/collections/count_w3c_collection.xml.res 1970-01-01 00:00:00 +0000
3291+++ test/rbkt/ExpQueryResults/zorba/collections/count_w3c_collection.xml.res 2011-10-21 00:32:19 +0000
3292@@ -0,0 +1,2 @@
3293+<?xml version="1.0" encoding="UTF-8"?>
3294+0
3295\ No newline at end of file
3296
3297=== added file 'test/rbkt/Queries/zorba/collections/count_dynamic_zorba_collection.xq'
3298--- test/rbkt/Queries/zorba/collections/count_dynamic_zorba_collection.xq 1970-01-01 00:00:00 +0000
3299+++ test/rbkt/Queries/zorba/collections/count_dynamic_zorba_collection.xq 2011-10-21 00:32:19 +0000
3300@@ -0,0 +1,10 @@
3301+import module namespace ddl =
3302+ "http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl";
3303+import module namespace dml =
3304+ "http://www.zorba-xquery.com/modules/store/dynamic/collections/dml";
3305+
3306+declare variable $coll := xs:QName("collection");
3307+
3308+ddl:create($coll);
3309+
3310+fn:count(dml:collection($coll))
3311
3312=== added file 'test/rbkt/Queries/zorba/collections/count_static_zorba_collection.xq'
3313--- test/rbkt/Queries/zorba/collections/count_static_zorba_collection.xq 1970-01-01 00:00:00 +0000
3314+++ test/rbkt/Queries/zorba/collections/count_static_zorba_collection.xq 2011-10-21 00:32:19 +0000
3315@@ -0,0 +1,14 @@
3316+import module namespace ddl =
3317+ "http://www.zorba-xquery.com/modules/store/static/collections/ddl";
3318+
3319+import module namespace dml =
3320+ "http://www.zorba-xquery.com/modules/store/static/collections/dml";
3321+
3322+import module namespace ns = "http://example.org/datamodule/"
3323+ at "collections.xqdata";
3324+
3325+declare variable $coll := xs:QName("ns:test1");
3326+
3327+ddl:create($coll);
3328+
3329+fn:count(dml:collection($coll))
3330
3331=== added file 'test/rbkt/Queries/zorba/collections/count_w3c_collection.xq'
3332--- test/rbkt/Queries/zorba/collections/count_w3c_collection.xq 1970-01-01 00:00:00 +0000
3333+++ test/rbkt/Queries/zorba/collections/count_w3c_collection.xq 2011-10-21 00:32:19 +0000
3334@@ -0,0 +1,8 @@
3335+import module namespace ddl =
3336+ "http://www.zorba-xquery.com/modules/store/dynamic/collections/w3c/ddl";
3337+
3338+declare variable $coll := "http://www.zorba-xquery.com/collection";
3339+
3340+ddl:create($coll);
3341+
3342+fn:count(fn:collection($coll))

Subscribers

People subscribed via source and target branches