Merge lp:~zorba-coders/zorba/markos-scratch into lp:zorba
- markos-scratch
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Markos Zaharioudakis |
Approved revision: | 11042 |
Merged at revision: | 11293 |
Proposed branch: | lp:~zorba-coders/zorba/markos-scratch |
Merge into: | lp:zorba |
Diff against target: |
844 lines (+299/-146) 14 files modified
ChangeLog (+1/-0) bin/zorbacmd.cpp (+3/-0) src/api/staticcontextimpl.cpp (+1/-1) src/compiler/translator/translator.cpp (+105/-77) src/context/root_static_context.cpp (+2/-1) src/context/static_context.cpp (+71/-16) src/context/static_context.h (+17/-10) src/functions/func_sequences_impl.cpp (+44/-0) src/functions/pregenerated/func_sequences.cpp (+0/-9) src/runtime/sequences/pregenerated/sequences.cpp (+2/-0) src/runtime/sequences/pregenerated/sequences.h (+6/-2) src/runtime/sequences/sequences_impl.cpp (+36/-26) src/runtime/spec/sequences/sequences.xml (+9/-3) test/rbkt/testdriver.cpp (+2/-1) |
To merge this branch: | bzr merge lp:~zorba-coders/zorba/markos-scratch |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Markos Zaharioudakis | Approve | ||
Review via email: mp+153930@code.launchpad.net |
Commit message
1.In jsoniq mode, allow multiple default function namespaces and no need to use the xs prefix for naming builtin atomic types.
2. Optimization for indef-of function.
Description of the change
1.In jsoniq mode, allow multiple default function namespaces and no need to use the xs prefix for naming builtin atomic types.
2. Optimization for indef-of function.
Markos Zaharioudakis (markos-za) : | # |
Zorba Build Bot (zorba-buildbot) wrote : | # |
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
The attempt to merge lp:~zorba-coders/zorba/markos-scratch into lp:zorba failed. Below is the output from the failed tests.
CMake Error at /home/ceej/
Validation queue job markos-
The final status was:
6 tests did not succeed - changes not commited.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
The attempt to merge lp:~zorba-coders/zorba/markos-scratch into lp:zorba failed. Below is the output from the failed tests.
CMake Error at /home/ceej/
Validation queue job markos-
The final status was:
5 tests did not succeed - changes not commited.
Error in read script: /home/ceej/
- 11042. By Markos Zaharioudakis
-
a bug fix for index-of
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue job markos-
All tests succeeded!
Preview Diff
1 | === modified file 'ChangeLog' |
2 | --- ChangeLog 2013-03-16 20:55:24 +0000 |
3 | +++ ChangeLog 2013-03-20 02:47:23 +0000 |
4 | @@ -15,6 +15,7 @@ |
5 | for streamable strings and base64Binary. |
6 | * Added millis-to-dateTime() function in datetime module. |
7 | * fn:trace outputs "empty-sequence()" if the input is the empty-sequence. |
8 | + * Allow multiple default function namespaces. |
9 | * Added xqxq:variable-value function. |
10 | * Added canonicalize function to modules/xml. |
11 | * Added support for xs:dateTimeStamp type from XMLSchema 1.1, bug #924754. |
12 | |
13 | === modified file 'bin/zorbacmd.cpp' |
14 | --- bin/zorbacmd.cpp 2013-02-07 17:24:36 +0000 |
15 | +++ bin/zorbacmd.cpp 2013-03-20 02:47:23 +0000 |
16 | @@ -673,6 +673,8 @@ |
17 | std::auto_ptr<std::fstream> planFile; |
18 | std::fstream* planFilep = NULL; |
19 | |
20 | + lHints.jsoniq_mode = (qfilepath.rfind(".jq") == qfilepath.size() - 3); |
21 | + |
22 | if (serializePlan) |
23 | { |
24 | if (savePlan || loadPlan) |
25 | @@ -724,6 +726,7 @@ |
26 | } |
27 | |
28 | Zorba_SerializerOptions lSerOptions = Zorba_SerializerOptions::SerializerOptionsFromStringParams(properties.getSerializerParameters()); |
29 | + |
30 | createSerializerOptions(lSerOptions, properties); |
31 | |
32 | zorba::XQuery_t query; |
33 | |
34 | === modified file 'src/api/staticcontextimpl.cpp' |
35 | --- src/api/staticcontextimpl.cpp 2013-02-07 17:24:36 +0000 |
36 | +++ src/api/staticcontextimpl.cpp 2013-03-20 02:47:23 +0000 |
37 | @@ -316,7 +316,7 @@ |
38 | |
39 | ********************************************************************************/ |
40 | String |
41 | -StaticContextImpl::getDefaultFunctionNamespace( ) const |
42 | +StaticContextImpl::getDefaultFunctionNamespace() const |
43 | { |
44 | try |
45 | { |
46 | |
47 | === modified file 'src/compiler/translator/translator.cpp' |
48 | --- src/compiler/translator/translator.cpp 2013-03-08 00:09:46 +0000 |
49 | +++ src/compiler/translator/translator.cpp 2013-03-20 02:47:23 +0000 |
50 | @@ -1031,6 +1031,11 @@ |
51 | Convert a lexical qname identifying a function to an expanded qname item. |
52 | If the lexical qname does not have a prefix, the default function namespace |
53 | (if any) will be used to build the expanded qname item. |
54 | + |
55 | + Raise error is the prefix is non-empty and there is no ns associated with it. |
56 | + |
57 | + This method is used during the processing of function declarations (when the |
58 | + function object is not supposed to exist already). |
59 | ********************************************************************************/ |
60 | void expand_function_qname( |
61 | store::Item_t& qnameItem, |
62 | @@ -1297,7 +1302,7 @@ |
63 | ********************************************************************************/ |
64 | void bind_fn( |
65 | function_t& f, |
66 | - ulong nargs, |
67 | + csize nargs, |
68 | const QueryLoc& loc) |
69 | { |
70 | theSctx->bind_fn(f, nargs, loc); |
71 | @@ -1313,14 +1318,17 @@ |
72 | |
73 | /******************************************************************************* |
74 | Lookup in the sctx the function object for a function with a given prefix |
75 | - local name and arity. Return NULL if such a function is not found |
76 | + local name and arity. Raise error if the prefix is non-empty and does not have |
77 | + an associated namespace. Return NULL if such a function is not found. |
78 | ********************************************************************************/ |
79 | -function* lookup_fn(const QName* qname, ulong arity, const QueryLoc& loc) |
80 | +function* lookup_fn(const QName* qname, csize arity, const QueryLoc& loc) |
81 | { |
82 | - store::Item_t qnameItem; |
83 | - expand_function_qname(qnameItem, qname, loc); |
84 | - |
85 | - return theSctx->lookup_fn(qnameItem, arity); |
86 | + return theSctx->lookup_fn(qname->get_namespace(), |
87 | + qname->get_prefix(), |
88 | + qname->get_localname(), |
89 | + arity, |
90 | + theCCB->theConfig.jsoniq_mode, |
91 | + loc); |
92 | } |
93 | |
94 | |
95 | @@ -4140,10 +4148,10 @@ |
96 | |
97 | //bool recognised = false; |
98 | |
99 | - store::Item_t lExpandedQName; |
100 | - expand_function_qname(lExpandedQName, v.get_qname(), loc); |
101 | + store::Item_t expandedQName; |
102 | + expand_function_qname(expandedQName, v.get_qname(), loc); |
103 | |
104 | - zstring annotNS = lExpandedQName->getNamespace(); |
105 | + zstring annotNS = expandedQName->getNamespace(); |
106 | |
107 | if (annotNS == static_context::W3C_XML_NS || |
108 | annotNS == XML_SCHEMA_NS || |
109 | @@ -4152,10 +4160,10 @@ |
110 | annotNS == XQUERY_MATH_FN_NS || |
111 | annotNS == ZORBA_ANNOTATIONS_NS) |
112 | { |
113 | - if (AnnotationInternal::lookup(lExpandedQName) == AnnotationInternal::zann_end) |
114 | + if (AnnotationInternal::lookup(expandedQName) == AnnotationInternal::zann_end) |
115 | { |
116 | RAISE_ERROR(err::XQST0045, loc, |
117 | - ERROR_PARAMS(lExpandedQName->getLocalName(), ZED(ANNOTATION), annotNS)); |
118 | + ERROR_PARAMS(expandedQName->getLocalName(), ZED(ANNOTATION), annotNS)); |
119 | } |
120 | |
121 | //recognised = true; |
122 | @@ -4177,7 +4185,7 @@ |
123 | } |
124 | |
125 | //if (recognised) |
126 | - theAnnotations->push_back(lExpandedQName, lLiterals); |
127 | + theAnnotations->push_back(expandedQName, lLiterals); |
128 | } |
129 | |
130 | |
131 | @@ -8640,9 +8648,19 @@ |
132 | |
133 | rchandle<QName> qname = v.get_qname(); |
134 | store::Item_t qnameItem; |
135 | - expand_elem_qname(qnameItem, qname, loc); |
136 | + |
137 | + if (!qname->get_prefix().empty() || !theCCB->theConfig.jsoniq_mode) |
138 | + { |
139 | + expand_elem_qname(qnameItem, qname, loc); |
140 | + } |
141 | + else |
142 | + { |
143 | + GENV_ITEMFACTORY-> |
144 | + createQName(qnameItem, XML_SCHEMA_NS, "", qname->get_localname()); |
145 | + } |
146 | |
147 | xqtref_t t = CTX_TM->create_named_simple_type(qnameItem); |
148 | + |
149 | if (t == NULL) |
150 | { |
151 | if (theSctx->xquery_version() < StaticContextConsts::xquery_version_3_0) |
152 | @@ -10738,20 +10756,6 @@ |
153 | |
154 | TypeManager* tm = CTX_TM; |
155 | |
156 | - // Expand the function qname |
157 | - rchandle<QName> qname = v.get_fname(); |
158 | - |
159 | - store::Item_t qnameItem; |
160 | - expand_function_qname(qnameItem, qname, loc); |
161 | - |
162 | - const zstring& fn_ns = qnameItem->getNamespace(); |
163 | - |
164 | - if (static_context::is_reserved_module(fn_ns)) |
165 | - { |
166 | - RAISE_ERROR(zerr::ZXQP0016_RESERVED_MODULE_TARGET_NAMESPACE, loc, |
167 | - ERROR_PARAMS(fn_ns)); |
168 | - } |
169 | - |
170 | // Collect the arguments of this function in reverse order |
171 | std::vector<expr*> arguments; |
172 | |
173 | @@ -10767,17 +10771,73 @@ |
174 | |
175 | csize numArgs = arguments.size(); |
176 | |
177 | + // Lookup the function |
178 | + store::Item_t qnameItem; |
179 | + const QName* qname = v.get_fname(); |
180 | + |
181 | function* f = lookup_fn(qname, numArgs, loc); |
182 | |
183 | + zstring fn_ns; |
184 | + |
185 | + if (f != NULL) |
186 | + { |
187 | + qnameItem = f->getName(); |
188 | + fn_ns = qnameItem->getNamespace(); |
189 | + |
190 | + if (static_context::is_reserved_module(fn_ns)) |
191 | + { |
192 | + RAISE_ERROR(zerr::ZXQP0016_RESERVED_MODULE_TARGET_NAMESPACE, loc, |
193 | + ERROR_PARAMS(fn_ns)); |
194 | + } |
195 | + } |
196 | + else |
197 | + { |
198 | + // Check if this is a call to a type constructor function |
199 | + expand_function_qname(qnameItem, qname, loc); |
200 | + |
201 | + xqtref_t type = CTX_TM->create_named_type(qnameItem, |
202 | + TypeConstants::QUANT_QUESTION, |
203 | + loc); |
204 | + |
205 | + if (type != NULL) |
206 | + { |
207 | + if (numArgs != 1 || |
208 | + TypeOps::is_equal(tm, *type, *GENV_TYPESYSTEM.NOTATION_TYPE_QUESTION, loc) || |
209 | + TypeOps::is_equal(tm, *type, *GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_QUESTION, loc)) |
210 | + { |
211 | + RAISE_ERROR(err::XPST0017, loc, |
212 | + ERROR_PARAMS(qname->get_qname(), ZED(FunctionUndeclared_3), numArgs)); |
213 | + } |
214 | + |
215 | + push_nodestack(create_cast_expr(loc, arguments[0], type, true, true)); |
216 | + |
217 | + return; |
218 | + } |
219 | + |
220 | + if (theHaveModuleImportCycle) |
221 | + { |
222 | + fn_ns = qnameItem->getNamespace(); |
223 | + |
224 | + std::map<zstring, zstring>::const_iterator ite = theModulesStack.begin(); |
225 | + std::map<zstring, zstring>::const_iterator end = theModulesStack.end(); |
226 | + |
227 | + --end; |
228 | + assert((*end).second == theModuleNamespace); |
229 | + |
230 | + for (; ite != end; ++ite) |
231 | + { |
232 | + if ((*ite).second == fn_ns) |
233 | + RAISE_ERROR(err::XQST0093, loc, ERROR_PARAMS(theModuleNamespace)); |
234 | + } |
235 | + } |
236 | + |
237 | + RAISE_ERROR(err::XPST0017, loc, |
238 | + ERROR_PARAMS(qname->get_qname(), ZED(FunctionUndeclared_3), numArgs)); |
239 | + } |
240 | + |
241 | if (fn_ns == static_context::W3C_FN_NS) |
242 | { |
243 | // Some special processing is required for certain "fn" functions |
244 | - if (f == NULL) |
245 | - { |
246 | - RAISE_ERROR(err::XPST0017, loc, |
247 | - ERROR_PARAMS(qname->get_qname(), ZED(FunctionUndeclared_3), numArgs)); |
248 | - } |
249 | - |
250 | switch (f->getKind()) |
251 | { |
252 | case FunctionConsts::FN_HEAD_1: |
253 | @@ -11062,48 +11122,7 @@ |
254 | |
255 | numArgs = arguments.size(); // recompute size |
256 | |
257 | - // Check if this is a call to a type constructor function |
258 | - xqtref_t type = CTX_TM->create_named_type(qnameItem, |
259 | - TypeConstants::QUANT_QUESTION, |
260 | - loc); |
261 | - |
262 | - if (type != NULL) |
263 | - { |
264 | - if (numArgs != 1 || |
265 | - TypeOps::is_equal(tm, *type, *GENV_TYPESYSTEM.NOTATION_TYPE_QUESTION, loc) || |
266 | - TypeOps::is_equal(tm, *type, *GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_QUESTION, loc)) |
267 | - { |
268 | - RAISE_ERROR(err::XPST0017, loc, |
269 | - ERROR_PARAMS(qname->get_qname(), ZED(FunctionUndeclared_3), numArgs)); |
270 | - } |
271 | - |
272 | - push_nodestack(create_cast_expr(loc, arguments[0], type, true, true)); |
273 | - } |
274 | - |
275 | - // It is not a builtin constructor function |
276 | - else |
277 | - { |
278 | - if (f == NULL) |
279 | - { |
280 | - if (theHaveModuleImportCycle) |
281 | - { |
282 | - std::map<zstring, zstring>::const_iterator ite = theModulesStack.begin(); |
283 | - std::map<zstring, zstring>::const_iterator end = theModulesStack.end(); |
284 | - |
285 | - --end; |
286 | - assert((*end).second == theModuleNamespace); |
287 | - |
288 | - for (; ite != end; ++ite) |
289 | - { |
290 | - if ((*ite).second == fn_ns) |
291 | - RAISE_ERROR(err::XQST0093, loc, ERROR_PARAMS(theModuleNamespace)); |
292 | - } |
293 | - } |
294 | - |
295 | - RAISE_ERROR(err::XPST0017, loc, |
296 | - ERROR_PARAMS(qname->get_qname(), ZED(FunctionUndeclared_3), numArgs)); |
297 | - } |
298 | - |
299 | + { |
300 | // If this is a udf that is invoked from another udf, mark that other udf |
301 | // as a non-leaf function. |
302 | if (f->isUdf()) |
303 | @@ -13084,7 +13103,16 @@ |
304 | |
305 | rchandle<QName> qname = v.get_qname(); |
306 | store::Item_t qnameItem; |
307 | - expand_elem_qname(qnameItem, qname, loc); |
308 | + |
309 | + if (!qname->get_prefix().empty() || !theCCB->theConfig.jsoniq_mode) |
310 | + { |
311 | + expand_elem_qname(qnameItem, qname, loc); |
312 | + } |
313 | + else |
314 | + { |
315 | + GENV_ITEMFACTORY-> |
316 | + createQName(qnameItem, XML_SCHEMA_NS, "", qname->get_localname()); |
317 | + } |
318 | |
319 | xqtref_t t = CTX_TM->create_named_simple_type(qnameItem); |
320 | |
321 | |
322 | === modified file 'src/context/root_static_context.cpp' |
323 | --- src/context/root_static_context.cpp 2013-02-07 17:24:36 +0000 |
324 | +++ src/context/root_static_context.cpp 2013-03-20 02:47:23 +0000 |
325 | @@ -157,7 +157,8 @@ |
326 | |
327 | set_default_elem_type_ns(zstring(), true, loc); |
328 | |
329 | - set_default_function_ns(W3C_FN_NS, true, loc); |
330 | + set_default_function_ns(JSONIQ_FN_NS, false, loc); |
331 | + set_default_function_ns(W3C_FN_NS, false, loc); |
332 | |
333 | add_collation(ZORBA_DEF_COLLATION_NS, QueryLoc::null); |
334 | add_collation(W3C_CODEPT_COLLATION_NS, QueryLoc::null); |
335 | |
336 | === modified file 'src/context/static_context.cpp' |
337 | --- src/context/static_context.cpp 2013-02-26 04:12:43 +0000 |
338 | +++ src/context/static_context.cpp 2013-03-20 02:47:23 +0000 |
339 | @@ -677,7 +677,6 @@ |
340 | theExternalModulesMap(NULL), |
341 | theNamespaceBindings(NULL), |
342 | theHaveDefaultElementNamespace(false), |
343 | - theHaveDefaultFunctionNamespace(false), |
344 | theContextItemType(NULL), |
345 | theVariablesMap(NULL), |
346 | theImportedPrivateVariablesMap(NULL), |
347 | @@ -724,7 +723,6 @@ |
348 | theExternalModulesMap(NULL), |
349 | theNamespaceBindings(NULL), |
350 | theHaveDefaultElementNamespace(false), |
351 | - theHaveDefaultFunctionNamespace(false), |
352 | theContextItemType(NULL), |
353 | theVariablesMap(NULL), |
354 | theImportedPrivateVariablesMap(NULL), |
355 | @@ -776,7 +774,6 @@ |
356 | theExternalModulesMap(NULL), |
357 | theNamespaceBindings(NULL), |
358 | theHaveDefaultElementNamespace(false), |
359 | - theHaveDefaultFunctionNamespace(false), |
360 | theContextItemType(NULL), |
361 | theVariablesMap(NULL), |
362 | theImportedPrivateVariablesMap(NULL), |
363 | @@ -1086,8 +1083,7 @@ |
364 | ar & theNamespaceBindings; |
365 | ar & theDefaultElementNamespace; |
366 | ar & theHaveDefaultElementNamespace; |
367 | - ar & theDefaultFunctionNamespace; |
368 | - ar & theHaveDefaultFunctionNamespace; |
369 | + ar & theDefaultFunctionNamespaces; |
370 | |
371 | ar & theContextItemType; |
372 | |
373 | @@ -2039,9 +2035,9 @@ |
374 | ********************************************************************************/ |
375 | const zstring& static_context::default_function_ns() const |
376 | { |
377 | - if (theHaveDefaultFunctionNamespace || theParent == NULL) |
378 | + if (!theDefaultFunctionNamespaces.empty() || theParent == NULL) |
379 | { |
380 | - return theDefaultFunctionNamespace; |
381 | + return theDefaultFunctionNamespaces[0]; |
382 | } |
383 | else |
384 | { |
385 | @@ -2058,10 +2054,9 @@ |
386 | bool raiseError, |
387 | const QueryLoc& loc) |
388 | { |
389 | - if (!theHaveDefaultFunctionNamespace) |
390 | + if (theDefaultFunctionNamespaces.empty()) |
391 | { |
392 | - theDefaultFunctionNamespace = ns; |
393 | - theHaveDefaultFunctionNamespace = true; |
394 | + theDefaultFunctionNamespaces.push_back(ns); |
395 | } |
396 | else if (raiseError) |
397 | { |
398 | @@ -2069,7 +2064,7 @@ |
399 | } |
400 | else |
401 | { |
402 | - theDefaultFunctionNamespace = ns; |
403 | + theDefaultFunctionNamespaces.insert(theDefaultFunctionNamespaces.begin(), ns); |
404 | } |
405 | } |
406 | |
407 | @@ -2429,7 +2424,7 @@ |
408 | ********************************************************************************/ |
409 | void static_context::bind_fn( |
410 | function_t& f, |
411 | - ulong arity, |
412 | + csize arity, |
413 | const QueryLoc& loc) |
414 | { |
415 | store::Item* qname = f->getName(); |
416 | @@ -2441,7 +2436,7 @@ |
417 | |
418 | if (theFunctionMap == NULL) |
419 | { |
420 | - ulong size = (is_global_root_sctx() ? 500 : 32); |
421 | + csize size = (is_global_root_sctx() ? 500 : 32); |
422 | theFunctionMap = new FunctionMap(HashMapItemPointerCmp(0, NULL), size, false); |
423 | } |
424 | |
425 | @@ -2503,7 +2498,7 @@ |
426 | ********************************************************************************/ |
427 | void static_context::unbind_fn( |
428 | const store::Item* qname, |
429 | - ulong arity) |
430 | + csize arity) |
431 | { |
432 | ZORBA_ASSERT(!is_global_root_sctx()); |
433 | |
434 | @@ -2563,6 +2558,66 @@ |
435 | } |
436 | |
437 | |
438 | +/******************************************************************************* |
439 | + Search in the sctx, starting from "this" and moving upwards, for the function |
440 | + object for a function with a given prefix local name and arity. Raise error if |
441 | + the prefix is non-empty and does not have an associated namespace. Return NULL |
442 | + if such a function is not found. |
443 | +********************************************************************************/ |
444 | +function* static_context::lookup_fn( |
445 | + const zstring& ns, |
446 | + const zstring& pre, |
447 | + const zstring& local, |
448 | + csize arity, |
449 | + bool allowMultipleDefaultNamespaces, |
450 | + const QueryLoc& loc) |
451 | +{ |
452 | + store::Item_t qnameItem; |
453 | + std::vector<zstring>::const_iterator ite; |
454 | + std::vector<zstring>::const_iterator end; |
455 | + function* f = NULL; |
456 | + |
457 | + if (!ns.empty()) |
458 | + { |
459 | + ITEM_FACTORY->createQName(qnameItem, ns, "", local); |
460 | + |
461 | + f = lookup_fn(qnameItem, arity, true); |
462 | + } |
463 | + else if (!pre.empty()) |
464 | + { |
465 | + expand_qname(qnameItem, "", pre, local, loc); |
466 | + |
467 | + f = lookup_fn(qnameItem, arity, true); |
468 | + } |
469 | + else if (allowMultipleDefaultNamespaces) |
470 | + { |
471 | + static_context* sctx = this; |
472 | + |
473 | + while (f == NULL && sctx != NULL) |
474 | + { |
475 | + ite = sctx->theDefaultFunctionNamespaces.begin(); |
476 | + end = sctx->theDefaultFunctionNamespaces.end(); |
477 | + |
478 | + for (; f == NULL && ite != end; ++ite) |
479 | + { |
480 | + ITEM_FACTORY->createQName(qnameItem, *ite, "", local); |
481 | + f = lookup_fn(qnameItem, arity, true); |
482 | + } |
483 | + |
484 | + sctx = sctx->theParent; |
485 | + } |
486 | + } |
487 | + else |
488 | + { |
489 | + expand_qname(qnameItem, default_function_ns(), pre, local, loc); |
490 | + |
491 | + f = lookup_fn(qnameItem, arity, true); |
492 | + } |
493 | + |
494 | + return f; |
495 | +} |
496 | + |
497 | + |
498 | /***************************************************************************//** |
499 | Search the static-context tree, starting from "this" and moving upwards, |
500 | looking for the 1st sctx obj that contains a binding for a function with |
501 | @@ -2572,7 +2627,7 @@ |
502 | ********************************************************************************/ |
503 | function* static_context::lookup_fn( |
504 | const store::Item* qname, |
505 | - ulong arity, |
506 | + csize arity, |
507 | bool skipDisabled) |
508 | { |
509 | FunctionInfo fi; |
510 | @@ -2627,7 +2682,7 @@ |
511 | ********************************************************************************/ |
512 | function* static_context::lookup_local_fn( |
513 | const store::Item* qname, |
514 | - ulong arity, |
515 | + csize arity, |
516 | bool skipDisabled) |
517 | { |
518 | FunctionInfo fi; |
519 | |
520 | === modified file 'src/context/static_context.h' |
521 | --- src/context/static_context.h 2013-02-26 04:12:43 +0000 |
522 | +++ src/context/static_context.h 2013-03-20 02:47:23 +0000 |
523 | @@ -352,9 +352,9 @@ |
524 | ---------------------------- |
525 | The namespace URI to be used for element and type qnames whose prefix is empty. |
526 | |
527 | - theDefaultFunctionNamespace : |
528 | - ----------------------------- |
529 | - The namespace URI to be used for function qnames whose prefix is empty. |
530 | + theDefaultFunctionNamespaces : |
531 | + ------------------------------ |
532 | + The namespace URIs to be used for function qnames whose prefix is empty. |
533 | |
534 | theContextItemType : |
535 | -------------------- |
536 | @@ -598,8 +598,7 @@ |
537 | zstring theDefaultElementNamespace; |
538 | bool theHaveDefaultElementNamespace; |
539 | |
540 | - zstring theDefaultFunctionNamespace; |
541 | - bool theHaveDefaultFunctionNamespace; |
542 | + std::vector<zstring> theDefaultFunctionNamespaces; |
543 | |
544 | xqtref_t theContextItemType; |
545 | |
546 | @@ -893,18 +892,26 @@ |
547 | // |
548 | // Functions |
549 | // |
550 | - void bind_fn(function_t& f, ulong arity, const QueryLoc& loc); |
551 | - |
552 | - void unbind_fn(const store::Item* qname, ulong arity); |
553 | + void bind_fn(function_t& f, csize arity, const QueryLoc& loc); |
554 | + |
555 | + void unbind_fn(const store::Item* qname, csize arity); |
556 | + |
557 | + function* lookup_fn( |
558 | + const zstring& ns, |
559 | + const zstring& pre, |
560 | + const zstring& local, |
561 | + csize arity, |
562 | + bool allowMultipleDefaultNamespaces, |
563 | + const QueryLoc& loc); |
564 | |
565 | function* lookup_fn( |
566 | const store::Item* qname, |
567 | - ulong arity, |
568 | + csize arity, |
569 | bool skipDisabled = true); |
570 | |
571 | function* lookup_local_fn( |
572 | const store::Item* qname, |
573 | - ulong arity, |
574 | + csize arity, |
575 | bool skipDisabled = true); |
576 | |
577 | void get_functions(std::vector<function*>& functions) const; |
578 | |
579 | === modified file 'src/functions/func_sequences_impl.cpp' |
580 | --- src/functions/func_sequences_impl.cpp 2013-02-07 17:24:36 +0000 |
581 | +++ src/functions/func_sequences_impl.cpp 2013-03-20 02:47:23 +0000 |
582 | @@ -492,6 +492,50 @@ |
583 | /******************************************************************************* |
584 | |
585 | ********************************************************************************/ |
586 | +PlanIter_t fn_index_of::codegen( |
587 | + CompilerCB*, |
588 | + static_context* sctx, |
589 | + const QueryLoc& loc, |
590 | + std::vector<PlanIter_t>& argv, |
591 | + expr& caller) const |
592 | +{ |
593 | + TypeManager* tm = caller.get_type_manager(); |
594 | + RootTypeManager& rtm = GENV_TYPESYSTEM; |
595 | + |
596 | + fo_expr* fo = static_cast<fo_expr*>(&caller); |
597 | + expr* seqArg = fo->get_arg(0); |
598 | + expr* keyArg = fo->get_arg(1); |
599 | + xqtref_t seqType = seqArg->get_return_type(); |
600 | + xqtref_t pseqType = TypeOps::prime_type(tm, *seqType); |
601 | + xqtref_t keyType = keyArg->get_return_type(); |
602 | + |
603 | + if (TypeOps::is_equal(tm, *keyType, *rtm.ANY_ATOMIC_TYPE_ONE) || |
604 | + TypeOps::is_equal(tm, *pseqType, *rtm.ANY_ATOMIC_TYPE_ONE)) |
605 | + { |
606 | + return new FnIndexOfIterator(sctx, loc, argv, 0); |
607 | + } |
608 | + |
609 | + if (TypeOps::is_subtype(tm, *keyType, *seqType) || |
610 | + (TypeOps::is_subtype(tm, *keyType, *rtm.UNTYPED_ATOMIC_TYPE_ONE) && |
611 | + TypeOps::is_subtype(tm, *seqType, *rtm.STRING_TYPE_STAR)) || |
612 | + (TypeOps::is_subtype(tm, *keyType, *rtm.STRING_TYPE_ONE) && |
613 | + TypeOps::is_subtype(tm, *seqType, *rtm.UNTYPED_ATOMIC_TYPE_STAR))) |
614 | + { |
615 | + return new FnIndexOfIterator(sctx, loc, argv, 1); |
616 | + } |
617 | + |
618 | + if (TypeOps::is_subtype(tm, *pseqType, *keyType)) |
619 | + { |
620 | + return new FnIndexOfIterator(sctx, loc, argv, 2); |
621 | + } |
622 | + |
623 | + return new FnIndexOfIterator(sctx, loc, argv, 0); |
624 | +} |
625 | + |
626 | + |
627 | +/******************************************************************************* |
628 | + |
629 | +********************************************************************************/ |
630 | xqtref_t fn_subsequence::getReturnType(const fo_expr* caller) const |
631 | { |
632 | TypeManager* tm = caller->get_type_manager(); |
633 | |
634 | === modified file 'src/functions/pregenerated/func_sequences.cpp' |
635 | --- src/functions/pregenerated/func_sequences.cpp 2013-03-05 23:11:50 +0000 |
636 | +++ src/functions/pregenerated/func_sequences.cpp 2013-03-20 02:47:23 +0000 |
637 | @@ -44,15 +44,6 @@ |
638 | return new FnConcatIterator(sctx, loc, argv); |
639 | } |
640 | |
641 | -PlanIter_t fn_index_of::codegen( |
642 | - CompilerCB*, |
643 | - static_context* sctx, |
644 | - const QueryLoc& loc, |
645 | - std::vector<PlanIter_t>& argv, |
646 | - expr& ann) const |
647 | -{ |
648 | - return new FnIndexOfIterator(sctx, loc, argv); |
649 | -} |
650 | |
651 | PlanIter_t fn_empty::codegen( |
652 | CompilerCB*, |
653 | |
654 | === modified file 'src/runtime/sequences/pregenerated/sequences.cpp' |
655 | --- src/runtime/sequences/pregenerated/sequences.cpp 2013-03-05 23:11:50 +0000 |
656 | +++ src/runtime/sequences/pregenerated/sequences.cpp 2013-03-20 02:47:23 +0000 |
657 | @@ -72,6 +72,8 @@ |
658 | { |
659 | serialize_baseclass(ar, |
660 | (NaryBaseIterator<FnIndexOfIterator, FnIndexOfIteratorState>*)this); |
661 | + |
662 | + ar & theFastComp; |
663 | } |
664 | |
665 | |
666 | |
667 | === modified file 'src/runtime/sequences/pregenerated/sequences.h' |
668 | --- src/runtime/sequences/pregenerated/sequences.h 2013-03-05 23:11:50 +0000 |
669 | +++ src/runtime/sequences/pregenerated/sequences.h 2013-03-20 02:47:23 +0000 |
670 | @@ -124,6 +124,8 @@ |
671 | |
672 | class FnIndexOfIterator : public NaryBaseIterator<FnIndexOfIterator, FnIndexOfIteratorState> |
673 | { |
674 | +protected: |
675 | + int theFastComp; // |
676 | public: |
677 | SERIALIZABLE_CLASS(FnIndexOfIterator); |
678 | |
679 | @@ -135,9 +137,11 @@ |
680 | FnIndexOfIterator( |
681 | static_context* sctx, |
682 | const QueryLoc& loc, |
683 | - std::vector<PlanIter_t>& children) |
684 | + std::vector<PlanIter_t>& children, |
685 | + int fastComp) |
686 | : |
687 | - NaryBaseIterator<FnIndexOfIterator, FnIndexOfIteratorState>(sctx, loc, children) |
688 | + NaryBaseIterator<FnIndexOfIterator, FnIndexOfIteratorState>(sctx, loc, children), |
689 | + theFastComp(fastComp) |
690 | {} |
691 | |
692 | virtual ~FnIndexOfIterator(); |
693 | |
694 | === modified file 'src/runtime/sequences/sequences_impl.cpp' |
695 | --- src/runtime/sequences/sequences_impl.cpp 2013-03-05 12:34:19 +0000 |
696 | +++ src/runtime/sequences/sequences_impl.cpp 2013-03-20 02:47:23 +0000 |
697 | @@ -76,18 +76,16 @@ |
698 | store::Item_t temp; |
699 | |
700 | if (!PlanIterator::consumeNext(lCollationItem, iter, planState)) |
701 | - throw XQUERY_EXCEPTION( |
702 | - err::XPTY0004, |
703 | - ERROR_PARAMS( ZED( NoEmptySeqAsCollationParam ) ), |
704 | - ERROR_LOC( loc ) |
705 | - ); |
706 | + { |
707 | + RAISE_ERROR(err::XPTY0004, loc, |
708 | + ERROR_PARAMS(ZED(NoEmptySeqAsCollationParam))); |
709 | + } |
710 | |
711 | if (PlanIterator::consumeNext(temp, iter, planState)) |
712 | - throw XQUERY_EXCEPTION( |
713 | - err::XPTY0004, |
714 | - ERROR_PARAMS( ZED( NoSeqAsCollationParam ) ), |
715 | - ERROR_LOC( loc ) |
716 | - ); |
717 | + { |
718 | + RAISE_ERROR(err::XPTY0004, loc, |
719 | + ERROR_PARAMS(ZED(NoSeqAsCollationParam))); |
720 | + } |
721 | |
722 | return sctx->get_collator(lCollationItem->getStringValue().str(), loc); |
723 | } |
724 | @@ -147,11 +145,9 @@ |
725 | bool |
726 | FnIndexOfIterator::nextImpl(store::Item_t& result, PlanState& planState) const |
727 | { |
728 | - store::Item_t lSequenceItem; |
729 | - store::Item_t lCollationItem; |
730 | - xqtref_t lCollationItemType; |
731 | + store::Item_t seqItem; |
732 | store::Item_t searchItem; |
733 | - TypeManager* typemgr = theSctx->get_typemanager(); |
734 | + TypeManager* tm = theSctx->get_typemanager(); |
735 | long timezone = 0; |
736 | bool found; |
737 | |
738 | @@ -163,26 +159,39 @@ |
739 | RAISE_ERROR(err::FORG0006, loc, ERROR_PARAMS(ZED(EmptySeqNoSearchItem))); |
740 | } |
741 | |
742 | - if ( theChildren.size() == 3 ) |
743 | - state->theCollator = getCollator(theSctx, loc, |
744 | - planState, theChildren[2].getp()); |
745 | + if (theChildren.size() == 3) |
746 | + { |
747 | + state->theCollator = |
748 | + getCollator(theSctx, loc, planState, theChildren[2].getp()); |
749 | + } |
750 | |
751 | - while ( consumeNext(lSequenceItem, theChildren[0].getp(), planState)) |
752 | + while (consumeNext(seqItem, theChildren[0].getp(), planState)) |
753 | { |
754 | // inc the position in the sequence; do it at the beginning of the loop |
755 | // because index-of starts with one |
756 | ++state->theCurrentPos; |
757 | |
758 | - searchItem = state->theSearchItem; |
759 | - |
760 | try |
761 | { |
762 | - found = CompareIterator::valueEqual(loc, |
763 | - lSequenceItem, |
764 | - searchItem, |
765 | - typemgr, |
766 | - timezone, |
767 | - state->theCollator); |
768 | + if (theFastComp == 1) |
769 | + { |
770 | + found = seqItem->equals(state->theSearchItem, timezone, state->theCollator); |
771 | + } |
772 | + else if (theFastComp == 2) |
773 | + { |
774 | + found = state->theSearchItem->equals(seqItem, timezone, state->theCollator); |
775 | + } |
776 | + else |
777 | + { |
778 | + searchItem = state->theSearchItem; |
779 | + |
780 | + found = CompareIterator::valueEqual(loc, |
781 | + seqItem, |
782 | + searchItem, |
783 | + tm, |
784 | + timezone, |
785 | + state->theCollator); |
786 | + } |
787 | } |
788 | catch (ZorbaException const& e) |
789 | { |
790 | @@ -203,6 +212,7 @@ |
791 | STACK_END(state); |
792 | } |
793 | |
794 | + |
795 | /******************************************************************************* |
796 | 15.1.4 fn:empty |
797 | ********************************************************************************/ |
798 | |
799 | === modified file 'src/runtime/spec/sequences/sequences.xml' |
800 | --- src/runtime/spec/sequences/sequences.xml 2013-02-07 17:24:36 +0000 |
801 | +++ src/runtime/spec/sequences/sequences.xml 2013-03-20 02:47:23 +0000 |
802 | @@ -102,7 +102,7 @@ |
803 | The result sequence is in ascending numeric order. |
804 | </zorba:description> |
805 | |
806 | - <zorba:function > |
807 | + <zorba:function generateCodegen="false"> |
808 | |
809 | <zorba:signature localname="index-of" prefix="fn"> |
810 | <zorba:param>xs:anyAtomicType*</zorba:param> |
811 | @@ -124,12 +124,18 @@ |
812 | brief="the current position in the sequence"/> |
813 | |
814 | <zorba:member type="store::Item_t" name="theSearchItem" defaultValue="NULL" |
815 | - brief="the item to search for"/> |
816 | + brief="the item to search for"/> |
817 | |
818 | <zorba:member type="XQPCollator*" name="theCollator" defaultValue="0" |
819 | - brief="the collator"/> |
820 | + brief="the collator"/> |
821 | </zorba:state> |
822 | |
823 | + <zorba:constructor> |
824 | + <zorba:parameter type="int" name="fastComp"/> |
825 | + </zorba:constructor> |
826 | + |
827 | + <zorba:member type="int" name="theFastComp"/> |
828 | + |
829 | </zorba:iterator> |
830 | |
831 | <!-- |
832 | |
833 | === modified file 'test/rbkt/testdriver.cpp' |
834 | --- test/rbkt/testdriver.cpp 2013-03-16 00:58:28 +0000 |
835 | +++ test/rbkt/testdriver.cpp 2013-03-20 02:47:23 +0000 |
836 | @@ -325,7 +325,8 @@ |
837 | lQuery = engine->createQuery(&errHandler); |
838 | lQuery->setFileName(lQueryFile.get_path()); |
839 | |
840 | - bool lJSONiqMode = lQueryFile.get_path().rfind(".jq") == lQueryFile.get_path().size() - 3; |
841 | + bool lJSONiqMode = |
842 | + (lQueryFile.get_path().rfind(".jq") == lQueryFile.get_path().size() - 3); |
843 | |
844 | lQuery->compile(lQueryString.c_str(), lContext, getCompilerHints(lJSONiqMode)); |
845 |
Attempt to merge into lp:zorba failed due to conflicts:
text conflict in ChangeLog