Merge lp:~zorba-coders/zorba/markos-scratch into lp:zorba

Proposed by Markos Zaharioudakis on 2013-06-11
Status: Merged
Approved by: Markos Zaharioudakis on 2013-06-11
Approved revision: 11139
Merged at revision: 11500
Proposed branch: lp:~zorba-coders/zorba/markos-scratch
Merge into: lp:zorba
Diff against target: 2148 lines (+586/-637)
15 files modified
ChangeLog (+2/-0)
src/compiler/translator/translator.cpp (+17/-44)
src/functions/func_booleans_impl.cpp (+2/-2)
src/runtime/booleans/BooleanImpl.cpp (+52/-73)
src/runtime/core/arithmetic_impl.cpp (+39/-37)
src/runtime/indexing/index_ddl.cpp (+14/-13)
src/runtime/maths/maths_impl.cpp (+25/-49)
src/runtime/numerics/NumericsImpl.cpp (+33/-31)
src/runtime/numerics/NumericsImpl.h (+2/-2)
src/runtime/numerics/numerics_impl.cpp (+151/-171)
src/runtime/sequences/SequencesImpl.cpp (+87/-112)
src/runtime/sequences/sequences_impl.cpp (+89/-72)
src/runtime/store/maps_impl.cpp (+2/-8)
src/types/typeops.cpp (+66/-23)
src/types/typeops.h (+5/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/markos-scratch
Reviewer Review Type Date Requested Status
Markos Zaharioudakis Approve on 2013-06-11
Review via email: mp+168595@code.launchpad.net

Commit Message

1. optimization: replaced use of create_value_type() in runtime with getTypeCode()
2. optimized switch expression

Description of the Change

1. optimization: replaced use of create_value_type() in runtime with getTypeCode()
2. optimized switch expression

To post a comment you must log in.
11139. By Markos Zaharioudakis on 2013-06-11

optimized switch expression

review: Approve
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job markos-scratch-2013-06-11T10-20-00.706Z 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 2013-06-08 05:33:57 +0000
3+++ ChangeLog 2013-06-11 09:57:50 +0000
4@@ -13,6 +13,8 @@
5 * Optimized implementation of fn:deep-equal
6 * No need to apply document ordering on the domain expression of a FOR clause
7 if the FOR clause is followed by an orderby or groupby clause.
8+ * Replaced use of create_value_type() in runtime with getTypeCode().
9+ * Optimized switch expression
10
11 Bug Fixes/Other Changes:
12 * Fixed bug #1117952 (Improve XML error output format)
13
14=== modified file 'src/compiler/translator/translator.cpp'
15--- src/compiler/translator/translator.cpp 2013-06-09 08:09:40 +0000
16+++ src/compiler/translator/translator.cpp 2013-06-11 09:57:50 +0000
17@@ -7977,41 +7977,16 @@
18
19 se = wrap_in_atomization(se);
20
21- // atomizedFlwor = [let $atomv := data(E) return NULL]
22- var_expr* atomv = create_temp_var(v.get_switch_expr()->get_location(),
23- var_expr::let_var);
24-
25- expr* atomizedFlwor = wrap_in_let_flwor(se, atomv, NULL);
26-
27- // TODO: cast as xs:string should not really be necessary
28- // atomizedFlwor =
29- // [let $atomv := data(E)
30- // return
31- // let $sv :=
32- // if ($atomv instanceof xs:untypedAtomic)
33- // then $atomv cast as xs:string
34- // else $atomv
35- // return NULL]
36- static_cast<flwor_expr*>(atomizedFlwor)->set_return_expr(
37- CREATE(if)(theRootSctx,
38- theUDF,
39- loc,
40- CREATE(instanceof)(theRootSctx,
41- theUDF,
42- loc,
43- atomv,
44- theRTM.UNTYPED_ATOMIC_TYPE_ONE),
45- CREATE(cast)(theRootSctx,
46- theUDF,
47- loc,
48- atomv,
49- theRTM.STRING_TYPE_ONE,
50- false),
51- atomv));
52-
53- // flworExpr = [let $sv := atomizedFlwor return NULL]
54+ se = CREATE(treat)(theRootSctx, theUDF, loc,
55+ se,
56+ theRTM.ANY_ATOMIC_TYPE_QUESTION,
57+ TREAT_TYPE_MATCH,
58+ false);
59+
60+ // flworExpr = [let $sv := data(E) treat as xs:anyAtomicType? return NULL]
61 var_expr* sv = create_temp_var(v.get_switch_expr()->get_location(), var_expr::let_var);
62- expr* flworExpr = wrap_in_let_flwor(atomizedFlwor, sv, NULL);
63+
64+ expr* flworExpr = wrap_in_let_flwor(se, sv, NULL);
65
66 // retExpr = [Ed]
67 v.get_default_expr()->accept(*this);
68@@ -8039,7 +8014,7 @@
69 operand->accept(*this);
70
71 expr* operandExpr = pop_nodestack();
72- operandExpr = wrap_in_atomization(operandExpr);
73+
74 operandExpr = CREATE(fo)(theRootSctx,
75 theUDF,
76 loc,
77@@ -8047,6 +8022,8 @@
78 sv,
79 operandExpr);
80
81+ normalize_fo(static_cast<fo_expr*>(operandExpr));
82+
83 condOperands.push_back(operandExpr);
84 } // for
85
86@@ -8056,20 +8033,15 @@
87 }
88 else if (condOperands.size() > 1)
89 {
90- condExpr = theExprManager->
91- create_fo_expr(theRootSctx,
92- theUDF,
93- loc,
94- BUILTIN_FUNC(OP_OR_N),
95- condOperands);
96+ condExpr = CREATE(fo)(theRootSctx, theUDF, loc,
97+ BUILTIN_FUNC(OP_OR_N), condOperands);
98 }
99
100 switchCaseClause->get_return_expr()->accept(*this);
101 expr* caseReturnExpr = pop_nodestack();
102
103 // retExpr = [if (condExpr) then caseReturnExpr else retExpr]
104- retExpr = theExprManager->
105- create_if_expr(theRootSctx, theUDF, loc, condExpr, caseReturnExpr, retExpr);
106+ retExpr = CREATE(if)(theRootSctx, theUDF, loc, condExpr, caseReturnExpr, retExpr);
107
108 } // for
109
110@@ -8088,6 +8060,7 @@
111 ZORBA_ASSERT (false);
112 }
113
114+
115 void* begin_visit(const SwitchCaseClause& v)
116 {
117 TRACE_VISIT();
118@@ -8095,7 +8068,7 @@
119 return NULL;
120 }
121
122-void end_visit (const SwitchCaseClause& v, void* /*visit_state*/)
123+void end_visit(const SwitchCaseClause& v, void* /*visit_state*/)
124 {
125 TRACE_VISIT_OUT ();
126 // shouldn't get here, begin_visit() rejects visitor
127
128=== modified file 'src/functions/func_booleans_impl.cpp'
129--- src/functions/func_booleans_impl.cpp 2013-02-07 17:24:36 +0000
130+++ src/functions/func_booleans_impl.cpp 2013-06-11 09:57:50 +0000
131@@ -868,8 +868,8 @@
132 // http://www.w3.org/TR/xquery-11/#dt-equivalence-two-atomic-values
133 DECL(sctx, op_atomic_values_equivalent,
134 (createQName(zorba_ns, "", "atomic-values-equivalent"),
135- GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_STAR,
136- GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_STAR,
137+ GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_QUESTION,
138+ GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_QUESTION,
139 GENV_TYPESYSTEM.BOOLEAN_TYPE_ONE));
140
141 }
142
143=== modified file 'src/runtime/booleans/BooleanImpl.cpp'
144--- src/runtime/booleans/BooleanImpl.cpp 2013-05-08 20:14:47 +0000
145+++ src/runtime/booleans/BooleanImpl.cpp 2013-06-11 09:57:50 +0000
146@@ -121,7 +121,6 @@
147 // node => true
148 result = negate ^ true;
149 }
150-#ifdef ZORBA_WITH_JSON
151 else if (item->isJSONItem())
152 {
153 xqtref_t type = tm->create_value_type(item);
154@@ -129,7 +128,6 @@
155 RAISE_ERROR(err::FORG0006, loc,
156 ERROR_PARAMS(ZED(BadArgTypeForFn_2o34o), *type, "fn:boolean" ));
157 }
158-#endif
159 else
160 {
161 store::SchemaTypeCode type = item->getTypeCode();
162@@ -1221,86 +1219,67 @@
163 store::Item_t& result,
164 PlanState& planState) const
165 {
166- store::Item_t lItem0, lItem1, tItem0, tItem1;
167- int count0, count1;
168- xqtref_t type0, type1;
169+ store::Item_t lItem0, lItem1;
170+ store::SchemaTypeCode type0;
171+ store::SchemaTypeCode type1;
172 bool are_equivalent;
173
174- RootTypeManager& rtm = GENV_TYPESYSTEM;
175- TypeManager* tm = theSctx->get_typemanager();
176-
177 PlanIteratorState* state;
178 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
179
180- count0 = 0;
181- count1 = 0;
182-
183 if (consumeNext(lItem0, theChild0.getp(), planState))
184- count0 = 1;
185-
186- if (count0 && consumeNext(tItem0, theChild0.getp(), planState))
187- throw XQUERY_EXCEPTION(
188- err::XPTY0004,
189- ERROR_PARAMS( ZED( NoSeqTestedForAtomicEquiv ) ),
190- ERROR_LOC( loc )
191- );
192-
193- if (consumeNext(lItem1, theChild1.getp(), planState))
194- count1 = 1;
195-
196- if (count1 && consumeNext(tItem1, theChild1.getp(), planState))
197- throw XQUERY_EXCEPTION(
198- err::XPTY0004,
199- ERROR_PARAMS( ZED( NoSeqTestedForAtomicEquiv ) ),
200- ERROR_LOC( loc )
201- );
202-
203- if (count0 == 0 && count1 == 0)
204+ {
205+ if (consumeNext(lItem1, theChild1.getp(), planState))
206+ {
207+ type0 = lItem0->getTypeCode();
208+ type1 = lItem1->getTypeCode();
209+
210+ if ((TypeOps::is_subtype(type0, store::XS_FLOAT) ||
211+ TypeOps::is_subtype(type0, store::XS_DOUBLE))
212+ &&
213+ (TypeOps::is_subtype(type1, store::XS_FLOAT) ||
214+ TypeOps::is_subtype(type1, store::XS_DOUBLE))
215+ &&
216+ lItem0->isNaN() && lItem1->isNaN())
217+ {
218+ STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, true), state);
219+ }
220+ else
221+ {
222+ try
223+ {
224+ are_equivalent = CompareIterator::valueEqual(loc,
225+ lItem0,
226+ lItem1,
227+ theTypeManager,
228+ theTimezone,
229+ theCollation);
230+ }
231+ catch (ZorbaException const& e)
232+ {
233+ if (e.diagnostic() == err::XPTY0004)
234+ are_equivalent = false;
235+ else
236+ throw;
237+ }
238+
239+ STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, are_equivalent),
240+ state);
241+ }
242+ }
243+ else
244+ {
245+ STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, false), state);
246+ }
247+ }
248+ else if (consumeNext(lItem1, theChild1.getp(), planState))
249+ {
250+ STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, false), state);
251+ }
252+ else
253 {
254 STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, true), state);
255 }
256- else if ((count0 == 0 && count1 == 1) || (count0 == 1 && count1 == 0))
257- {
258- STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, false), state);
259- }
260- else
261- {
262- type0 = theTypeManager->create_value_type(lItem0.getp());
263- type1 = theTypeManager->create_value_type(lItem1.getp());
264-
265- if ((TypeOps::is_subtype(tm, *type0, *rtm.FLOAT_TYPE_ONE) ||
266- TypeOps::is_subtype(tm, *type0, *rtm.DOUBLE_TYPE_ONE))
267- &&
268- (TypeOps::is_subtype(tm, *type1, *rtm.FLOAT_TYPE_ONE) ||
269- TypeOps::is_subtype(tm, *type1, *rtm.DOUBLE_TYPE_ONE))
270- &&
271- lItem0->isNaN() && lItem1->isNaN())
272- {
273- STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, true), state);
274- }
275- else
276- {
277- try
278- {
279- are_equivalent = CompareIterator::valueEqual(loc,
280- lItem0,
281- lItem1,
282- theTypeManager,
283- theTimezone,
284- theCollation);
285- }
286- catch (ZorbaException const& e)
287- {
288- if (e.diagnostic() == err::XPTY0004)
289- are_equivalent = false;
290- else
291- throw;
292- }
293-
294- STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, are_equivalent),
295- state);
296- }
297- }
298
299 STACK_END(state);
300 }
301
302=== modified file 'src/runtime/core/arithmetic_impl.cpp'
303--- src/runtime/core/arithmetic_impl.cpp 2013-05-08 20:14:47 +0000
304+++ src/runtime/core/arithmetic_impl.cpp 2013-06-11 09:57:50 +0000
305@@ -167,16 +167,16 @@
306 assert(n0->isAtomic());
307 assert(n1->isAtomic());
308
309- xqtref_t type0 = tm->create_value_type(n0);
310- xqtref_t type1 = tm->create_value_type(n1);
311+ store::SchemaTypeCode type0 = n0->getTypeCode();
312+ store::SchemaTypeCode type1 = n1->getTypeCode();
313
314- if (TypeOps::is_numeric(tm, *type0) &&
315- (TypeOps::is_subtype(tm, *type1, *rtm.YM_DURATION_TYPE_ONE) ||
316- TypeOps::is_subtype(tm, *type1, *rtm.DT_DURATION_TYPE_ONE)))
317+ if (TypeOps::is_numeric(type0) &&
318+ (TypeOps::is_subtype(type1, store::XS_YM_DURATION) ||
319+ TypeOps::is_subtype(type1, store::XS_DT_DURATION)))
320 {
321 GenericCast::castToAtomic(n0, n0, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, aLoc);
322
323- if (TypeOps::is_subtype(tm, *type1, *rtm.YM_DURATION_TYPE_ONE))
324+ if (TypeOps::is_subtype(type1, store::XS_YM_DURATION))
325 {
326 return Operation::template
327 compute<store::XS_DOUBLE, store::XS_YM_DURATION>
328@@ -189,44 +189,44 @@
329 (result, dctx, tm, &aLoc, n0, n1);
330 }
331 }
332- else if (TypeOps::is_subtype(tm, *type0, *rtm.DT_DURATION_TYPE_ONE) &&
333- TypeOps::is_subtype(tm, *type1, *rtm.TIME_TYPE_ONE))
334+ else if (TypeOps::is_subtype(type0, store::XS_DT_DURATION) &&
335+ TypeOps::is_subtype(type1, store::XS_TIME))
336 {
337 return Operation::template
338 compute<store::XS_DURATION,store::XS_TIME>
339 (result, dctx, tm, &aLoc, n0, n1);
340 }
341- else if (TypeOps::is_subtype(tm, *type0, *rtm.YM_DURATION_TYPE_ONE))
342+ else if (TypeOps::is_subtype(type0, store::XS_YM_DURATION))
343 {
344- if(TypeOps::is_numeric(tm, *type1))
345+ if (TypeOps::is_numeric(type1))
346 {
347 GenericCast::castToAtomic(n1, n1, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, aLoc);
348 return Operation::template
349 compute<store::XS_YM_DURATION,store::XS_DOUBLE>
350 (result, dctx, tm, &aLoc, n0, n1);
351 }
352- else if (TypeOps::is_subtype(tm, *type1, *rtm.DATETIME_TYPE_ONE))
353+ else if (TypeOps::is_subtype(type1, store::XS_DATETIME))
354 {
355 return Operation::template
356 compute<store::XS_DURATION,store::XS_DATETIME>
357 (result, dctx, tm, &aLoc, n0, n1);
358 }
359- else if (TypeOps::is_subtype(tm, *type1, *rtm.DATE_TYPE_ONE))
360+ else if (TypeOps::is_subtype(type1, store::XS_DATE))
361 {
362 return Operation::template
363 compute<store::XS_DURATION,store::XS_DATE>
364 (result, dctx, tm, &aLoc, n0, n1);
365 }
366- else if (TypeOps::is_equal(tm, *type0, *type1))
367+ else if (type0 == type1)
368 {
369 return Operation::template
370 computeSingleType<store::XS_YM_DURATION>
371 (result, dctx, tm, &aLoc, n0, n1);
372 }
373 }
374- else if (TypeOps::is_subtype(tm, *type0, *rtm.DT_DURATION_TYPE_ONE))
375+ else if (TypeOps::is_subtype(type0, store::XS_DT_DURATION))
376 {
377- if(TypeOps::is_numeric(tm, *type1))
378+ if (TypeOps::is_numeric(type1))
379 {
380 GenericCast::castToAtomic(n1, n1, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, aLoc);
381
382@@ -234,94 +234,96 @@
383 compute<store::XS_DT_DURATION,store::XS_DOUBLE>
384 (result, dctx, tm, &aLoc, n0, n1);
385 }
386- else if (TypeOps::is_subtype(tm, *type1, *rtm.DATETIME_TYPE_ONE))
387+ else if (TypeOps::is_subtype(type1, store::XS_DATETIME))
388 {
389 return Operation::template
390 compute<store::XS_DURATION,store::XS_DATETIME>
391 (result, dctx, tm, &aLoc, n0, n1);
392 }
393- else if (TypeOps::is_subtype(tm, *type1, *rtm.DATE_TYPE_ONE))
394+ else if (TypeOps::is_subtype(type1, store::XS_DATE))
395 {
396 return Operation::template
397 compute<store::XS_DURATION,store::XS_DATE>
398 (result, dctx, tm, &aLoc, n0, n1);
399 }
400- else if (TypeOps::is_equal(tm, *type0, *type1))
401+ else if (type0 == type1)
402 {
403 return Operation::template
404 computeSingleType<store::XS_DT_DURATION>
405 (result, dctx, tm, &aLoc, n0, n1);
406 }
407 }
408- else if(TypeOps::is_subtype(tm, *type0, *rtm.DATETIME_TYPE_ONE))
409+ else if (TypeOps::is_subtype(type0, store::XS_DATETIME))
410 {
411- if(TypeOps::is_subtype(tm, *type1, *rtm.DATETIME_TYPE_ONE))
412+ if (TypeOps::is_subtype(type1, store::XS_DATETIME))
413 {
414 return Operation::template
415 compute<store::XS_DATETIME,store::XS_DATETIME>
416 (result, dctx, tm, &aLoc, n0, n1);
417 }
418- else if (TypeOps::is_subtype(tm, *type1, *rtm.YM_DURATION_TYPE_ONE ))
419+ else if (TypeOps::is_subtype(type1, store::XS_YM_DURATION))
420 {
421 return Operation::template
422 compute<store::XS_DATETIME,store::XS_DURATION>
423 (result, dctx, tm, &aLoc, n0, n1);
424 }
425- else if (TypeOps::is_subtype(tm, *type1, *rtm.DT_DURATION_TYPE_ONE ))
426+ else if (TypeOps::is_subtype(type1, store::XS_DT_DURATION))
427 {
428 return Operation::template
429 compute<store::XS_DATETIME,store::XS_DURATION>
430 (result, dctx, tm, &aLoc, n0, n1);
431 }
432 }
433- else if(TypeOps::is_subtype(tm, *type0, *rtm.DATE_TYPE_ONE))
434+ else if (TypeOps::is_subtype(type0, store::XS_DATE))
435 {
436- if (TypeOps::is_subtype(tm, *type1, *rtm.DATE_TYPE_ONE))
437+ if (TypeOps::is_subtype(type1, store::XS_DATE))
438 {
439 return Operation::template
440 compute<store::XS_DATE,store::XS_DATE>
441 (result, dctx, tm, &aLoc, n0, n1);
442 }
443- else if (TypeOps::is_subtype(tm, *type1, *rtm.YM_DURATION_TYPE_ONE))
444+ else if (TypeOps::is_subtype(type1, store::XS_YM_DURATION))
445 {
446 return Operation::template
447 compute<store::XS_DATE,store::XS_DURATION>
448 (result, dctx, tm, &aLoc, n0, n1);
449 }
450- else if (TypeOps::is_subtype(tm, *type1, *rtm.DT_DURATION_TYPE_ONE))
451+ else if (TypeOps::is_subtype(type1, store::XS_DT_DURATION))
452 {
453 return Operation::template
454 compute<store::XS_DATE,store::XS_DURATION>
455 (result, dctx, tm, &aLoc, n0, n1);
456 }
457 }
458- else if(TypeOps::is_subtype(tm, *type0, *rtm.TIME_TYPE_ONE))
459+ else if (TypeOps::is_subtype(type0, store::XS_TIME))
460 {
461- if(TypeOps::is_subtype(tm, *type1, *rtm.TIME_TYPE_ONE))
462+ if (TypeOps::is_subtype(type1, store::XS_TIME))
463 {
464 return Operation::template
465 compute<store::XS_TIME,store::XS_TIME>
466 (result, dctx, tm, &aLoc, n0, n1);
467 }
468- else if (TypeOps::is_subtype(tm, *type1, *rtm.DT_DURATION_TYPE_ONE))
469+ else if (TypeOps::is_subtype(type1, store::XS_DT_DURATION))
470 {
471 return Operation::template
472 compute<store::XS_TIME,store::XS_DURATION>
473 (result, dctx, tm, &aLoc, n0, n1);
474 }
475 }
476- else if ((TypeOps::is_numeric(tm, *type0) ||
477- TypeOps::is_subtype(tm, *type0, *rtm.UNTYPED_ATOMIC_TYPE_ONE)) &&
478- ( TypeOps::is_numeric(tm, *type1) ||
479- TypeOps::is_subtype(tm, *type1, *rtm.UNTYPED_ATOMIC_TYPE_ONE)))
480+ else if ((TypeOps::is_numeric(type0) || type0 == store::XS_UNTYPED_ATOMIC) &&
481+ (TypeOps::is_numeric(type1) || type1 == store::XS_UNTYPED_ATOMIC))
482 {
483 return NumArithIterator<Operation>::
484 computeAtomic(result, dctx, tm, aLoc, n0, type0, n1, type1);
485 }
486-
487-
488- RAISE_ERROR(err::XPTY0004, aLoc,
489- ERROR_PARAMS(ZED(ArithOpNotDefinedBetween_23), *type0, *type1));
490+
491+ {
492+ xqtref_t type0 = tm->create_value_type(n0);
493+ xqtref_t type1 = tm->create_value_type(n1);
494+
495+ RAISE_ERROR(err::XPTY0004, aLoc,
496+ ERROR_PARAMS(ZED(ArithOpNotDefinedBetween_23), *type0, *type1));
497+ }
498
499 return false; // suppresses wanring
500 }
501
502=== modified file 'src/runtime/indexing/index_ddl.cpp'
503--- src/runtime/indexing/index_ddl.cpp 2013-05-02 18:34:27 +0000
504+++ src/runtime/indexing/index_ddl.cpp 2013-06-11 09:57:50 +0000
505@@ -70,7 +70,8 @@
506
507
508 /*******************************************************************************
509-
510+ This function is called from the probe function to chaeck that the type of
511+ the probing key is consistent with the index declaration.
512 ********************************************************************************/
513 static void checkKeyType(
514 const QueryLoc& loc,
515@@ -138,6 +139,7 @@
516 {
517 GENV_STORE.getItemFactory()->
518 createDouble(searchKey, xs_float(searchKey->getDecimalValue()));
519+
520 return;
521 }
522
523@@ -1217,7 +1219,6 @@
524 PlanState& planState) const
525 {
526 TypeManager* tm = theSctx->get_typemanager();
527- RootTypeManager& rtm = GENV_TYPESYSTEM;
528 store::IndexCondition_t cond;
529 csize numChildren = theChildren.size();
530 csize numNonKeyParams = (theSkip ? 2 : 1);
531@@ -1262,37 +1263,37 @@
532 if (state->theIndexDecl->isGeneral() &&
533 (state->theIndexDecl->getKeyTypes())[keyNo] == NULL)
534 {
535- xqtref_t leftType;
536- xqtref_t rightType;
537+ store::SchemaTypeCode leftType;
538+ store::SchemaTypeCode rightType;
539
540 if (tempLeft != NULL)
541 {
542- leftType = tm->create_value_type(tempLeft);
543+ leftType = tempLeft->getTypeCode();
544
545- if (TypeOps::is_equal(tm, *leftType, *rtm.UNTYPED_ATOMIC_TYPE_ONE))
546+ if (leftType == store::XS_UNTYPED_ATOMIC)
547 {
548 zstring str = tempLeft->getStringValue();
549 GENV_ITEMFACTORY->createString(tempLeft, str);
550- leftType = rtm.STRING_TYPE_ONE;
551+ leftType = store::XS_STRING;
552 }
553 }
554
555 if (tempRight != NULL)
556 {
557- rightType = tm->create_value_type(tempRight);
558+ rightType = tempRight->getTypeCode();
559
560- if (TypeOps::is_equal(tm, *rightType, *rtm.UNTYPED_ATOMIC_TYPE_ONE))
561+ if (rightType == store::XS_UNTYPED_ATOMIC)
562 {
563 zstring str = tempRight->getStringValue();
564 GENV_ITEMFACTORY->createString(tempRight, str);
565- rightType = rtm.STRING_TYPE_ONE;
566+ rightType = store::XS_STRING;
567 }
568 }
569
570- if (leftType != NULL && rightType != NULL)
571+ if (tempLeft != NULL && tempRight != NULL)
572 {
573- if (!TypeOps::is_subtype(tm, *leftType, *rightType) &&
574- !TypeOps::is_subtype(tm, *rightType, *leftType))
575+ if (!TypeOps::is_subtype(leftType, rightType) &&
576+ !TypeOps::is_subtype(rightType, leftType))
577 {
578 RAISE_ERROR(zerr::ZDDY0034_INDEX_RANGE_VALUE_PROBE_BAD_KEY_TYPES, loc,
579 ERROR_PARAMS(state->theIndexDecl->getName()->getStringValue()));
580
581=== modified file 'src/runtime/maths/maths_impl.cpp'
582--- src/runtime/maths/maths_impl.cpp 2013-02-07 17:24:36 +0000
583+++ src/runtime/maths/maths_impl.cpp 2013-06-11 09:57:50 +0000
584@@ -30,6 +30,8 @@
585 #include "store/api/item.h"
586
587 #include "diagnostics/xquery_diagnostics.h"
588+#include "diagnostics/util_macros.h"
589+
590 #include "zorbatypes/numconversions.h"
591
592 namespace zorba {
593@@ -345,44 +347,27 @@
594 {
595 if (consumeNext(n1, this->theChild1.getp(), planState))
596 {
597+ assert(n1->isAtomic());
598+
599 {
600- xqtref_t type;
601-
602 const TypeManager* tm = theSctx->get_typemanager();
603-
604 const RootTypeManager& rtm = GENV_TYPESYSTEM;
605+
606 xs_double doub1 = n0->getDoubleValue();
607- //xs_double doub2 = n1->getDoubleValue();
608-
609- //GENV_ITEMFACTORY->createDouble(result, doub1.pow(doub2));
610-
611- assert(n1->isAtomic());
612-
613- type = tm->create_value_type(n1);
614-
615- if (TypeOps::is_subtype(tm, *type, *rtm.UNTYPED_ATOMIC_TYPE_ONE))
616+
617+ store::SchemaTypeCode type1 = n1->getTypeCode();
618+
619+ if (type1 == store::XS_UNTYPED_ATOMIC)
620 {
621 GenericCast::castToAtomic(result, result, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, loc);
622- type = tm->create_value_type(result);
623- }
624-
625- if (TypeOps::is_subtype(tm, *type, *rtm.DOUBLE_TYPE_ONE))
626- {
627- GENV_ITEMFACTORY->createDouble(result, doub1.pow(n1->getDoubleValue()));
628- }
629- else if (TypeOps::is_subtype(tm, *type, *rtm.FLOAT_TYPE_ONE))
630- {
631- store::Item_t n1_double;
632- GenericCast::castToAtomic(n1_double,
633- n1,
634- rtm.DOUBLE_TYPE_ONE.getp(),
635- tm,
636- NULL,
637- loc);
638-
639- GENV_ITEMFACTORY->createDouble(result, doub1.pow(n1_double->getDoubleValue()));
640- }
641- else if (TypeOps::is_subtype(tm, *type, *rtm.INTEGER_TYPE_ONE))
642+
643+ GENV_ITEMFACTORY->createDouble(result, doub1.pow(n1->getDoubleValue()));
644+ }
645+ else if (type1 == store::XS_DOUBLE || type1 == store::XS_FLOAT)
646+ {
647+ GENV_ITEMFACTORY->createDouble(result, doub1.pow(n1->getDoubleValue()));
648+ }
649+ else if (type1 == store::XS_INTEGER)
650 {
651 xs_integer n1_integer = n1->getIntegerValue();
652 try
653@@ -390,16 +375,13 @@
654 xs_int const n1_int = to_xs_int(n1_integer);
655 GENV_ITEMFACTORY->createDouble(result, doub1.pow(n1_int));
656 }
657- catch ( std::range_error const& )
658+ catch (std::range_error const&)
659 {
660- throw XQUERY_EXCEPTION(
661- err::XPTY0004,
662- ERROR_PARAMS( ZED( NoCastToCInt_2 ), n1_integer ),
663- ERROR_LOC( loc )
664- );
665+ RAISE_ERROR(err::XPTY0004, loc,
666+ ERROR_PARAMS(ZED(NoCastToCInt_2), n1_integer));
667 }
668 }
669- else if (TypeOps::is_subtype(tm, *type, *rtm.DECIMAL_TYPE_ONE))
670+ else if (type1 == store::XS_DECIMAL)
671 {
672 store::Item_t n1_double;
673 GenericCast::castToAtomic(n1_double,
674@@ -413,19 +395,13 @@
675 }
676 else
677 {
678- throw XQUERY_EXCEPTION(
679- err::XPTY0004,
680- ERROR_PARAMS( ZED( BadTypeFor_23 ), type, "math:pow" ),
681- ERROR_LOC( loc )
682- );
683+ xqtref_t type = tm->create_value_type(n1);
684+
685+ RAISE_ERROR(err::XPTY0004, loc,
686+ ERROR_PARAMS(ZED(BadTypeFor_23), type, "math:pow"));
687 }
688 }
689
690- if (consumeNext(n0, this->theChild0.getp(), planState) ||
691- consumeNext(n1, this->theChild1.getp(), planState))
692- throw XQUERY_EXCEPTION(
693- err::XPTY0004, ERROR_PARAMS( ZED( NoSeqForFnOp_2 ), "math:pow" )
694- );
695 STACK_PUSH(true, state);
696 }
697 }
698
699=== modified file 'src/runtime/numerics/NumericsImpl.cpp'
700--- src/runtime/numerics/NumericsImpl.cpp 2013-05-05 03:16:33 +0000
701+++ src/runtime/numerics/NumericsImpl.cpp 2013-06-11 09:57:50 +0000
702@@ -687,8 +687,8 @@
703 assert(n0->isAtomic());
704 assert(n1->isAtomic());
705
706- xqtref_t type0 = tm->create_value_type(n0);
707- xqtref_t type1 = tm->create_value_type(n1);
708+ store::SchemaTypeCode type0 = n0->getTypeCode();
709+ store::SchemaTypeCode type1 = n1->getTypeCode();
710
711 return computeAtomic(result, dctx, tm, aLoc, n0, type0, n1, type1);
712 }
713@@ -701,9 +701,9 @@
714 const TypeManager* tm,
715 const QueryLoc& aLoc,
716 store::Item_t& item0,
717- xqtref_t type0,
718+ store::SchemaTypeCode type0,
719 store::Item_t& item1,
720- xqtref_t type1)
721+ store::SchemaTypeCode type1)
722 {
723 bool res;
724 store::Item_t n0;
725@@ -711,14 +711,14 @@
726
727 bool isDivision = Operation::getOperationKind() == ArithmeticConsts::DIVISION;
728
729- xqtref_t resultType = TypeOps::arithmetic_type(tm, *type0, *type1, isDivision);
730+ store::SchemaTypeCode resultType = TypeOps::arithmetic_type(type0, type1, isDivision);
731
732- switch (TypeOps::get_atomic_type_code(*resultType))
733+ switch (resultType)
734 {
735 case store::XS_DOUBLE:
736 {
737- GenericCast::castToAtomic(n0, item0, &*resultType, tm, NULL, aLoc);
738- GenericCast::castToAtomic(n1, item1, &*resultType, tm, NULL, aLoc);
739+ GenericCast::castToBuiltinAtomic(n0, item0, resultType, NULL, aLoc);
740+ GenericCast::castToBuiltinAtomic(n1, item1, resultType, NULL, aLoc);
741
742 res = Operation::template
743 computeSingleType<store::XS_DOUBLE>
744@@ -727,8 +727,8 @@
745 }
746 case store::XS_FLOAT:
747 {
748- GenericCast::castToAtomic(n0, item0, &*resultType, tm, NULL, aLoc);
749- GenericCast::castToAtomic(n1, item1, &*resultType, tm, NULL, aLoc);
750+ GenericCast::castToBuiltinAtomic(n0, item0, resultType, NULL, aLoc);
751+ GenericCast::castToBuiltinAtomic(n1, item1, resultType, NULL, aLoc);
752
753 res = Operation::template
754 computeSingleType<store::XS_FLOAT>
755@@ -737,8 +737,8 @@
756 }
757 case store::XS_DECIMAL:
758 {
759- GenericCast::castToAtomic(n0, item0, &*resultType, tm, NULL, aLoc);
760- GenericCast::castToAtomic(n1, item1, &*resultType, tm, NULL, aLoc);
761+ GenericCast::castToBuiltinAtomic(n0, item0, resultType, NULL, aLoc);
762+ GenericCast::castToBuiltinAtomic(n1, item1, resultType, NULL, aLoc);
763
764 res = Operation::template
765 computeSingleType<store::XS_DECIMAL>
766@@ -747,8 +747,8 @@
767 }
768 case store::XS_INTEGER:
769 {
770- GenericCast::castToAtomic(n0, item0, &*resultType, tm, NULL, aLoc);
771- GenericCast::castToAtomic(n1, item1, &*resultType, tm, NULL, aLoc);
772+ GenericCast::castToBuiltinAtomic(n0, item0, resultType, NULL, aLoc);
773+ GenericCast::castToBuiltinAtomic(n1, item1, resultType, NULL, aLoc);
774
775 res = Operation::template
776 computeSingleType<store::XS_INTEGER>
777@@ -757,11 +757,13 @@
778 }
779 default:
780 {
781- throw XQUERY_EXCEPTION(
782- err::XPTY0004,
783- ERROR_PARAMS( ZED( ArithOpNotDefinedBetween_23 ), *type0, *type1 ),
784- ERROR_LOC( aLoc )
785- );
786+ xqtref_t type0 = tm->create_value_type(item0);
787+ xqtref_t type1 = tm->create_value_type(item1);
788+
789+ RAISE_ERROR(err::XPTY0004, aLoc,
790+ ERROR_PARAMS(ZED(ArithOpNotDefinedBetween_23),
791+ type0->toSchemaString(),
792+ type1->toSchemaString()));
793 }
794 }
795
796@@ -896,9 +898,8 @@
797 bool OpNumericUnaryIterator::nextImpl(store::Item_t& result, PlanState& planState) const
798 {
799 store::Item_t item;
800- xqtref_t type;
801+ store::SchemaTypeCode type;
802
803- const RootTypeManager& rtm = GENV_TYPESYSTEM;
804 const TypeManager* tm = theSctx->get_typemanager();
805
806 PlanIteratorState* state;
807@@ -908,35 +909,35 @@
808 {
809 assert(item->isAtomic());
810
811- type = tm->create_value_type(item);
812+ type = item->getTypeCode();
813
814- if (TypeOps::is_subtype(tm, *type, *rtm.UNTYPED_ATOMIC_TYPE_ONE ) )
815+ if (type == store::XS_UNTYPED_ATOMIC)
816 {
817- GenericCast::castToAtomic(item, item, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, loc);
818- type = rtm.DOUBLE_TYPE_ONE;
819+ GenericCast::castToBuiltinAtomic(item, item, store::XS_DOUBLE, NULL, loc);
820+ type = store::XS_DOUBLE;
821 }
822
823 // TODO Optimizations (e.g. if item has already the correct type and value,
824 // it does not have to be created newly)
825- if (TypeOps::is_subtype(tm, *type, *rtm.DOUBLE_TYPE_ONE))
826+ if (TypeOps::is_subtype(type, store::XS_DOUBLE))
827 {
828 GENV_ITEMFACTORY->
829 createDouble(result,
830 (thePlus ? item->getDoubleValue() : -item->getDoubleValue()));
831 }
832- else if ( TypeOps::is_subtype(tm, *type, *rtm.FLOAT_TYPE_ONE ) )
833+ else if (TypeOps::is_subtype(type, store::XS_FLOAT))
834 {
835 GENV_ITEMFACTORY->
836 createFloat(result,
837 (thePlus ? item->getFloatValue() : -item->getFloatValue()));
838 }
839- else if ( TypeOps::is_subtype(tm, *type, *rtm.INTEGER_TYPE_ONE ) )
840+ else if (TypeOps::is_subtype(type, store::XS_INTEGER))
841 {
842 GENV_ITEMFACTORY->
843 createInteger(result,
844 (thePlus ? item->getIntegerValue() : -item->getIntegerValue()));
845 }
846- else if ( TypeOps::is_subtype(tm, *type, *rtm.DECIMAL_TYPE_ONE ) )
847+ else if (TypeOps::is_subtype(type, store::XS_DECIMAL))
848 {
849 GENV_ITEMFACTORY->
850 createDecimal(result,
851@@ -944,8 +945,9 @@
852 }
853 else
854 {
855+ xqtref_t type = tm->create_value_type(item);
856 RAISE_ERROR(err::XPTY0004, loc,
857- ERROR_PARAMS(ZED(BadTypeFor_23), type, ZED(UnaryArithOp)));
858+ ERROR_PARAMS(ZED(BadTypeFor_23), type->toSchemaString(), ZED(UnaryArithOp)));
859 }
860
861 STACK_PUSH(true, state);
862@@ -985,7 +987,7 @@
863 PlanIteratorState* state;
864 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
865
866- if (consumeNext(item, theChild.getp(), planState ))
867+ if (consumeNext(item, theChild.getp(), planState))
868 {
869 assert(item->isAtomic());
870
871
872=== modified file 'src/runtime/numerics/NumericsImpl.h'
873--- src/runtime/numerics/NumericsImpl.h 2013-02-07 17:24:36 +0000
874+++ src/runtime/numerics/NumericsImpl.h 2013-06-11 09:57:50 +0000
875@@ -61,9 +61,9 @@
876 const TypeManager* tm,
877 const QueryLoc&,
878 store::Item_t& item0,
879- xqtref_t type0,
880+ store::SchemaTypeCode type0,
881 store::Item_t& item1,
882- xqtref_t type1);
883+ store::SchemaTypeCode type1);
884
885 public:
886 NumArithIterator(static_context* sctx, const QueryLoc&, PlanIter_t&, PlanIter_t&);
887
888=== modified file 'src/runtime/numerics/numerics_impl.cpp'
889--- src/runtime/numerics/numerics_impl.cpp 2013-05-02 18:34:27 +0000
890+++ src/runtime/numerics/numerics_impl.cpp 2013-06-11 09:57:50 +0000
891@@ -52,12 +52,9 @@
892 AbsIterator::nextImpl(store::Item_t& result, PlanState& planState) const
893 {
894 store::Item_t item;
895- xqtref_t type;
896-
897+ store::SchemaTypeCode type;
898 const TypeManager* tm = theSctx->get_typemanager();
899
900- const RootTypeManager& rtm = GENV_TYPESYSTEM;
901-
902 PlanIteratorState* state;
903 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
904
905@@ -65,31 +62,31 @@
906 {
907 assert(result->isAtomic());
908
909- type = tm->create_value_type(result);
910+ type = result->getTypeCode();
911
912- if (TypeOps::is_subtype(tm, *type, *rtm.UNTYPED_ATOMIC_TYPE_ONE))
913+ if (type == store::XS_UNTYPED_ATOMIC)
914 {
915- GenericCast::castToAtomic(result, result, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, loc);
916- type = tm->create_value_type(result);
917+ GenericCast::castToBuiltinAtomic(result, result, store::XS_DOUBLE, NULL, loc);
918+ type = store::XS_DOUBLE;
919 }
920
921- if (TypeOps::is_subtype(tm, *type, *rtm.DOUBLE_TYPE_ONE))
922+ if (TypeOps::is_subtype(type, store::XS_DOUBLE))
923 {
924 if (result->getDoubleValue().isPos() || result->getDoubleValue().isPosZero())
925 {
926- if ( !TypeOps::is_equal(tm, *type, *rtm.DOUBLE_TYPE_ONE))
927- GENV_ITEMFACTORY->createDouble (result, result->getDoubleValue());
928+ if (type != store::XS_DOUBLE)
929+ GENV_ITEMFACTORY->createDouble(result, result->getDoubleValue());
930 }
931 else
932 {
933 GENV_ITEMFACTORY->createDouble(result, -result->getDoubleValue());
934 }
935 }
936- else if (TypeOps::is_subtype(tm, *type, *rtm.FLOAT_TYPE_ONE))
937+ else if (TypeOps::is_subtype(type, store::XS_FLOAT))
938 {
939 if ( result->getFloatValue().isPos() || result->getFloatValue().isPosZero())
940 {
941- if ( !TypeOps::is_equal(tm, *type, *rtm.FLOAT_TYPE_ONE))
942+ if (type != store::XS_FLOAT)
943 GENV_ITEMFACTORY->createFloat (result, result->getFloatValue());
944 }
945 else
946@@ -97,11 +94,11 @@
947 GENV_ITEMFACTORY->createFloat(result, -result->getFloatValue());
948 }
949 }
950- else if (TypeOps::is_subtype(tm, *type, *rtm.INTEGER_TYPE_ONE))
951+ else if (TypeOps::is_subtype(type, store::XS_INTEGER))
952 {
953 if (result->getIntegerValue().sign() >= 0)
954 {
955- if ( !TypeOps::is_equal(tm, *type, *rtm.INTEGER_TYPE_ONE))
956+ if (type != store::XS_INTEGER)
957 GENV_ITEMFACTORY->createInteger(result, result->getIntegerValue());
958 }
959 else
960@@ -109,28 +106,23 @@
961 GENV_ITEMFACTORY->createInteger(result, -result->getIntegerValue());
962 }
963 }
964- else if (TypeOps::is_subtype(tm, *type, *rtm.DECIMAL_TYPE_ONE))
965+ else if (TypeOps::is_subtype(type, store::XS_DECIMAL))
966 {
967 if ( result->getDecimalValue().sign() >= 0)
968 {
969- if ( !TypeOps::is_equal(tm, *type, *rtm.DECIMAL_TYPE_ONE))
970+ if (type != store::XS_DECIMAL)
971 GENV_ITEMFACTORY->createDecimal(result, result->getDecimalValue());
972 }
973 else
974 {
975- GENV_ITEMFACTORY->createDecimal (result, -result->getDecimalValue());
976+ GENV_ITEMFACTORY->createDecimal(result, -result->getDecimalValue());
977 }
978 }
979 else
980 {
981- RAISE_ERROR(err::XPTY0004, loc,
982- ERROR_PARAMS(ZED(BadTypeFor_23), type, "fn:abs" ));
983- }
984-
985- if ( consumeNext(item, theChildren[0].getp(), planState ))
986- {
987- RAISE_ERROR(err::XPTY0004, loc,
988- ERROR_PARAMS(ZED(NoSeqForFnOp_2), "fn:abs"));
989+ xqtref_t type = tm->create_value_type(result);
990+ RAISE_ERROR(err::XPTY0004, loc,
991+ ERROR_PARAMS(ZED(BadTypeFor_23), type->toSchemaString(), "fn:abs" ));
992 }
993
994 STACK_PUSH(true, state);
995@@ -138,15 +130,15 @@
996 STACK_END(state);
997 }
998
999+
1000 //6.4.2 fn:ceiling
1001 bool
1002 CeilingIterator::nextImpl(store::Item_t& result, PlanState& planState) const
1003 {
1004 store::Item_t item;
1005- xqtref_t type;
1006+ store::SchemaTypeCode type;
1007
1008 const TypeManager* tm = theSctx->get_typemanager();
1009- const RootTypeManager& rtm = GENV_TYPESYSTEM;
1010
1011 PlanIteratorState* state;
1012 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
1013@@ -156,116 +148,109 @@
1014 //get the value and the type of the item
1015 assert(result->isAtomic());
1016
1017- type = tm->create_value_type(result);
1018+ type = result->getTypeCode();
1019
1020 //Parameters of type xs:untypedAtomic are always promoted to xs:double
1021- if ( TypeOps::is_subtype(tm, *type, *rtm.UNTYPED_ATOMIC_TYPE_ONE))
1022+ if (TypeOps::is_subtype(type, store::XS_UNTYPED_ATOMIC))
1023 {
1024- GenericCast::castToAtomic(result, result, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, loc);
1025- type = tm->create_value_type(result);
1026+ GenericCast::castToBuiltinAtomic(result, result, store::XS_DOUBLE, NULL, loc);
1027+ type = store::XS_DOUBLE;
1028 }
1029
1030- //item type is subtype of DOUBLE
1031- if ( TypeOps::is_subtype(tm, *type, *rtm.DOUBLE_TYPE_ONE))
1032+ if (TypeOps::is_subtype(type, store::XS_DOUBLE))
1033+ {
1034 GENV_ITEMFACTORY->createDouble(result, result->getDoubleValue().ceil());
1035-
1036- //item type is subtype of FLOAT
1037- else if ( TypeOps::is_subtype(tm, *type, *rtm.FLOAT_TYPE_ONE))
1038+ }
1039+ else if (TypeOps::is_subtype(type, store::XS_FLOAT))
1040+ {
1041 GENV_ITEMFACTORY->createFloat(result, result->getFloatValue().ceil());
1042-
1043- //item type is subtype of INTEGER
1044- else if(TypeOps::is_subtype(tm, *type, *rtm.INTEGER_TYPE_ONE))
1045- { /* do nothing */ }
1046-
1047- //item type is subtype of DECIMAL
1048- else if (TypeOps::is_subtype(tm, *type, *rtm.DECIMAL_TYPE_ONE))
1049+ }
1050+ else if (TypeOps::is_subtype(type, store::XS_INTEGER))
1051+ {
1052+ /* do nothing */
1053+ }
1054+ else if (TypeOps::is_subtype(type, store::XS_DECIMAL))
1055+ {
1056 GENV_ITEMFACTORY->createDecimal(result, result->getDecimalValue().ceil());
1057-
1058+ }
1059 else
1060 {
1061+ xqtref_t type = tm->create_value_type(result);
1062 RAISE_ERROR(err::XPTY0004, loc,
1063 ERROR_PARAMS(ZED(BadTypeFor_23), type, "fn:ceiling" ));
1064 }
1065
1066- if ( consumeNext(item, theChildren[0].getp(), planState ))
1067- {
1068- RAISE_ERROR(err::XPTY0004, loc,
1069- ERROR_PARAMS(ZED(NoSeqForFnOp_2), "fn:ceiling"));
1070- }
1071 STACK_PUSH(true, state);
1072 }
1073+
1074 STACK_END(state);
1075 }
1076
1077+
1078 //6.4.3 fn:floor
1079 bool
1080 FloorIterator::nextImpl(store::Item_t& result, PlanState& planState) const
1081 {
1082 store::Item_t item;
1083- xqtref_t type;
1084+ store::SchemaTypeCode type;
1085
1086 const TypeManager* tm = theSctx->get_typemanager();
1087- const RootTypeManager& rtm = GENV_TYPESYSTEM;
1088
1089 PlanIteratorState* state;
1090 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
1091
1092 if (consumeNext(result, theChildren[0].getp(), planState))
1093 {
1094- //get the value and the type of the item
1095 assert(result->isAtomic());
1096
1097- type = tm->create_value_type(result);
1098+ type = result->getTypeCode();
1099
1100 //Parameters of type xs:untypedAtomic are always promoted to xs:double
1101- if (TypeOps::is_subtype(tm, *type, *rtm.UNTYPED_ATOMIC_TYPE_ONE))
1102+ if (TypeOps::is_subtype(type, store::XS_UNTYPED_ATOMIC))
1103 {
1104- GenericCast::castToAtomic(result, result, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, loc);
1105- type = tm->create_value_type(result);
1106+ GenericCast::castToBuiltinAtomic(result, result, store::XS_DOUBLE, NULL, loc);
1107+ type = store::XS_DOUBLE;
1108 }
1109
1110- //item type is subtype of DOUBLE
1111- if (TypeOps::is_subtype(tm, *type, *rtm.DOUBLE_TYPE_ONE))
1112+ if (TypeOps::is_subtype(type, store::XS_DOUBLE))
1113+ {
1114 GENV_ITEMFACTORY->createDouble(result, result->getDoubleValue().floor());
1115-
1116- //item type is subtype of FLOAT
1117- else if (TypeOps::is_subtype(tm, *type, *rtm.FLOAT_TYPE_ONE))
1118+ }
1119+ else if (TypeOps::is_subtype(type, store::XS_FLOAT))
1120+ {
1121 GENV_ITEMFACTORY->createFloat(result, result->getFloatValue().floor());
1122-
1123- //item type is subtype of INTEGER
1124- else if(TypeOps::is_subtype(tm, *type, *rtm.INTEGER_TYPE_ONE))
1125- { /* do nothing */ }
1126-
1127- //item type is subtype of DECIMAL
1128- else if (TypeOps::is_subtype(tm, *type, *rtm.DECIMAL_TYPE_ONE))
1129+ }
1130+ else if(TypeOps::is_subtype(type, store::XS_INTEGER))
1131+ {
1132+ /* do nothing */
1133+ }
1134+ else if (TypeOps::is_subtype(type, store::XS_DECIMAL))
1135+ {
1136 GENV_ITEMFACTORY->createDecimal(result, result->getDecimalValue().floor());
1137-
1138+ }
1139 else
1140 {
1141+ xqtref_t type = tm->create_value_type(result);
1142 RAISE_ERROR(err::XPTY0004, loc,
1143 ERROR_PARAMS(ZED(BadTypeFor_23), type, "fn:floor"));
1144 }
1145
1146- if ( consumeNext(item, theChildren[0].getp(), planState ) )
1147- {
1148- RAISE_ERROR(err::XPTY0004, loc,
1149- ERROR_PARAMS(ZED(NoSeqForFnOp_2), "fn:floor" ));
1150- }
1151- STACK_PUSH (true, state );
1152+ STACK_PUSH(true, state);
1153 }
1154- STACK_END (state);
1155+
1156+ STACK_END(state);
1157 }
1158
1159+
1160 bool
1161 RoundIterator::nextImpl(store::Item_t& result, PlanState& planState) const
1162 {
1163 store::Item_t item;
1164- xqtref_t type;
1165+ store::SchemaTypeCode type;
1166 store::Item_t precision;
1167 Integer precision_integer(0);
1168
1169 const TypeManager* tm = theSctx->get_typemanager();
1170- const RootTypeManager& rtm = GENV_TYPESYSTEM;
1171
1172 PlanIteratorState* state;
1173 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
1174@@ -280,125 +265,120 @@
1175 precision_integer = precision->getIntegerValue();
1176 }
1177
1178- //get the value and the type of the item
1179 assert(result->isAtomic());
1180
1181- type = tm->create_value_type(result);
1182-
1183- //Parameters of type xs:untypedAtomic are always promoted to xs:double
1184- if ( TypeOps::is_subtype(tm, *type, *rtm.UNTYPED_ATOMIC_TYPE_ONE))
1185- {
1186- GenericCast::castToAtomic(result, result, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, loc);
1187- type = tm->create_value_type(result);
1188- }
1189-
1190- //item type is subtype of DOUBLE
1191- if ( TypeOps::is_subtype(tm, *type, *rtm.DOUBLE_TYPE_ONE))
1192- GENV_ITEMFACTORY->createDouble(result, result->getDoubleValue().round(precision_integer));
1193-
1194- //item type is subtype of FLOAT
1195- else if ( TypeOps::is_subtype(tm, *type, *rtm.FLOAT_TYPE_ONE))
1196- GENV_ITEMFACTORY->createFloat(result, result->getFloatValue().round(precision_integer));
1197-
1198- //item type is subtype of INTEGER
1199- else if(TypeOps::is_subtype(tm, *type, *rtm.INTEGER_TYPE_ONE))
1200- {
1201- if(precision_integer.sign() < 0)
1202- GENV_ITEMFACTORY->createInteger(result, result->getIntegerValue().round(precision_integer));
1203- }
1204-
1205- //item type is subtype of DECIMAL
1206- else if (TypeOps::is_subtype(tm, *type, *rtm.DECIMAL_TYPE_ONE))
1207- GENV_ITEMFACTORY->createDecimal(result, result->getDecimalValue().round(precision_integer));
1208-
1209+ type = result->getTypeCode();
1210+
1211+ if (TypeOps::is_subtype(type, store::XS_UNTYPED_ATOMIC))
1212+ {
1213+ GenericCast::castToBuiltinAtomic(result, result, store::XS_DOUBLE, NULL, loc);
1214+ type = store::XS_DOUBLE;
1215+ }
1216+
1217+ if (TypeOps::is_subtype(type, store::XS_DOUBLE))
1218+ {
1219+ GENV_ITEMFACTORY->
1220+ createDouble(result, result->getDoubleValue().round(precision_integer));
1221+ }
1222+ else if (TypeOps::is_subtype(type, store::XS_FLOAT))
1223+ {
1224+ GENV_ITEMFACTORY->
1225+ createFloat(result, result->getFloatValue().round(precision_integer));
1226+ }
1227+ else if (TypeOps::is_subtype(type, store::XS_INTEGER))
1228+ {
1229+ if (precision_integer.sign() < 0)
1230+ GENV_ITEMFACTORY->
1231+ createInteger(result, result->getIntegerValue().round(precision_integer));
1232+ }
1233+
1234+ else if (TypeOps::is_subtype(type, store::XS_DECIMAL))
1235+ {
1236+ GENV_ITEMFACTORY->
1237+ createDecimal(result, result->getDecimalValue().round(precision_integer));
1238+ }
1239 else
1240 {
1241+ xqtref_t type = tm->create_value_type(result);
1242 RAISE_ERROR(err::XPTY0004, loc,
1243 ERROR_PARAMS(ZED(BadTypeFor_23), type, "fn:round"));
1244 }
1245
1246- if ( consumeNext(item, theChildren[0].getp(), planState ))
1247- {
1248- RAISE_ERROR(err::XPTY0004, loc,
1249- ERROR_PARAMS(ZED(NoSeqForFnOp_2), "fn:round" ));
1250- }
1251- STACK_PUSH (true, state );
1252+ STACK_PUSH(true, state);
1253 }
1254- STACK_END (state);
1255+
1256+ STACK_END(state);
1257 }
1258
1259+
1260 //6.4.5 fn:round-half-to-even
1261-bool RoundHalfToEvenIterator::nextImpl( store::Item_t &result,
1262- PlanState& planState ) const {
1263+bool RoundHalfToEvenIterator::nextImpl(
1264+ store::Item_t& result,
1265+ PlanState& planState ) const
1266+{
1267 store::Item_t item;
1268 xs_integer precision;
1269- RootTypeManager const &rtm = GENV_TYPESYSTEM;
1270 TypeManager const *const tm = theSctx->get_typemanager();
1271- xqtref_t type;
1272-
1273- PlanIteratorState *state;
1274- DEFAULT_STACK_INIT( PlanIteratorState, state, planState );
1275-
1276- if ( consumeNext( result, theChildren [0].getp(), planState ) ) {
1277- assert( result->isAtomic() );
1278- type = tm->create_value_type( result );
1279-
1280- if ( theChildren.size() == 2 ) {
1281- consumeNext( item, theChildren[1].getp(), planState );
1282- assert( item->isAtomic() );
1283+ store::SchemaTypeCode type;
1284+
1285+ PlanIteratorState* state;
1286+ DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
1287+
1288+ if (consumeNext(result, theChildren [0].getp(), planState))
1289+ {
1290+ assert(result->isAtomic());
1291+ type = result->getTypeCode();
1292+
1293+ if (theChildren.size() == 2)
1294+ {
1295+ consumeNext(item, theChildren[1].getp(), planState);
1296+ assert(item->isAtomic());
1297 precision = item->getIntegerValue();
1298 }
1299
1300- if ( TypeOps::is_subtype( tm, *type, *rtm.UNTYPED_ATOMIC_TYPE_ONE ) ) {
1301+ if (TypeOps::is_subtype(type, store::XS_UNTYPED_ATOMIC))
1302+ {
1303 //
1304 // XQuery 3.0 3.1.5.2: Each item in the atomic sequence that is of type
1305 // xs:untypedAtomic is cast to the expected generalized atomic type. For
1306 // built-in functions where the expected type is specified as numeric,
1307 // arguments of type xs:untypedAtomic are cast to xs:double.
1308 //
1309- GenericCast::castToAtomic(
1310- result, result, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, loc
1311- );
1312- type = tm->create_value_type( result );
1313- }
1314-
1315- if ( TypeOps::is_subtype( tm, *type, *rtm.DOUBLE_TYPE_ONE ) )
1316- GENV_ITEMFACTORY->createDouble(
1317- result, result->getDoubleValue().roundHalfToEven( precision )
1318- );
1319-
1320- else if ( TypeOps::is_subtype( tm, *type, *rtm.FLOAT_TYPE_ONE ) )
1321- GENV_ITEMFACTORY->createFloat(
1322- result, result->getFloatValue().roundHalfToEven( precision )
1323- );
1324-
1325- else if ( TypeOps::is_subtype( tm, *type, *rtm.INTEGER_TYPE_ONE ) )
1326- GENV_ITEMFACTORY->createInteger(
1327- result, result->getIntegerValue().roundHalfToEven( precision )
1328- );
1329-
1330- else if ( TypeOps::is_subtype( tm, *type, *rtm.DECIMAL_TYPE_ONE ) )
1331- GENV_ITEMFACTORY->createDecimal(
1332- result, result->getDecimalValue().roundHalfToEven( precision )
1333- );
1334-
1335+ GenericCast::castToBuiltinAtomic(result, result, store::XS_DOUBLE, NULL, loc);
1336+ type = store::XS_DOUBLE;
1337+ }
1338+
1339+ if (TypeOps::is_subtype(type, store::XS_DOUBLE))
1340+ {
1341+ GENV_ITEMFACTORY->
1342+ createDouble(result, result->getDoubleValue().roundHalfToEven(precision));
1343+ }
1344+ else if (TypeOps::is_subtype(type, store::XS_FLOAT))
1345+ {
1346+ GENV_ITEMFACTORY->
1347+ createFloat(result, result->getFloatValue().roundHalfToEven(precision));
1348+ }
1349+ else if (TypeOps::is_subtype(type, store::XS_INTEGER))
1350+ {
1351+ GENV_ITEMFACTORY->
1352+ createInteger(result, result->getIntegerValue().roundHalfToEven(precision));
1353+ }
1354+ else if (TypeOps::is_subtype(type, store::XS_DECIMAL))
1355+ {
1356+ GENV_ITEMFACTORY->
1357+ createDecimal(result, result->getDecimalValue().roundHalfToEven(precision));
1358+ }
1359 else
1360- throw XQUERY_EXCEPTION(
1361- err::XPTY0004,
1362- ERROR_PARAMS( ZED( BadTypeFor_23 ), type, "fn:round-half-to-even" ),
1363- ERROR_LOC( loc )
1364- );
1365+ {
1366+ xqtref_t type = tm->create_value_type(result);
1367+ RAISE_ERROR(err::XPTY0004, loc,
1368+ ERROR_PARAMS(ZED(BadTypeFor_23), type, "fn:round-half-to-even"));
1369+ }
1370
1371- if ( consumeNext( item, theChildren [0].getp(), planState ) ) {
1372- throw XQUERY_EXCEPTION(
1373- err::XPTY0004,
1374- ERROR_PARAMS( ZED( NoSeqForFnOp_2 ), "fn:round-half-to-even" ),
1375- ERROR_LOC( loc )
1376- );
1377- }
1378- STACK_PUSH( true, state );
1379+ STACK_PUSH(true, state);
1380 }
1381- STACK_END( state );
1382+
1383+ STACK_END(state);
1384 }
1385
1386 } // namespace zorba
1387
1388=== modified file 'src/runtime/sequences/SequencesImpl.cpp'
1389--- src/runtime/sequences/SequencesImpl.cpp 2013-05-15 23:22:01 +0000
1390+++ src/runtime/sequences/SequencesImpl.cpp 2013-06-11 09:57:50 +0000
1391@@ -62,35 +62,6 @@
1392
1393 NARY_ACCEPT(FnMinMaxIterator);
1394
1395-namespace sequences_impl_ns{
1396-static XQPCollator* getCollator(
1397- static_context* sctx,
1398- const QueryLoc& loc,
1399- PlanState& planState,
1400- const PlanIterator* iter)
1401-{
1402- store::Item_t lCollationItem;
1403- store::Item_t temp;
1404-
1405- if (!PlanIterator::consumeNext(lCollationItem, iter, planState))
1406- throw XQUERY_EXCEPTION(
1407- err::XPTY0004,
1408- ERROR_PARAMS( ZED( NoEmptySeqAsCollationParam ) ),
1409- ERROR_LOC( loc )
1410- );
1411-
1412- if (PlanIterator::consumeNext(temp, iter, planState))
1413- throw XQUERY_EXCEPTION(
1414- err::XPTY0004,
1415- ERROR_PARAMS( ZED( NoSeqAsCollationParam ) ),
1416- ERROR_LOC( loc )
1417- );
1418-
1419- xqtref_t lCollationItemType = sctx->get_typemanager()->create_value_type(lCollationItem);
1420-
1421- return sctx->get_collator(lCollationItem->getStringValue().str(), loc);
1422-}
1423-}
1424
1425 /////////////////////////////////////////////////////////////////////////////////
1426 // //
1427@@ -121,104 +92,108 @@
1428 bool
1429 FnMinMaxIterator::nextImpl(store::Item_t& result, PlanState& planState) const
1430 {
1431- store::Item_t lRunningItem = NULL;
1432- xqtref_t lMaxType;
1433+ store::Item_t runningItem = NULL;
1434+ store::SchemaTypeCode maxType = store::XS_LAST;
1435
1436 const TypeManager* tm = theSctx->get_typemanager();
1437- const RootTypeManager& rtm = GENV_TYPESYSTEM;
1438-
1439 long timezone = planState.theLocalDynCtx->get_implicit_timezone();
1440- XQPCollator* lCollator = 0;
1441+ XQPCollator* collator = 0;
1442 unsigned elems_in_seq = 0;
1443 result = NULL;
1444
1445 try
1446 {
1447- PlanIteratorState* state;
1448- DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
1449-
1450- if (theChildren.size() == 2)
1451- lCollator = sequences_impl_ns::getCollator(theSctx, loc, planState, theChildren[1].getp());
1452- else
1453- lCollator = theSctx->get_default_collator(loc);
1454-
1455- if (consumeNext(lRunningItem, theChildren[0].getp(), planState))
1456- {
1457- do
1458- {
1459- // casting of untyped atomic
1460- xqtref_t lRunningType = tm->create_value_type(lRunningItem);
1461-
1462- if (TypeOps::is_subtype(tm, *lRunningType, *rtm.UNTYPED_ATOMIC_TYPE_ONE))
1463- {
1464- GenericCast::castToAtomic(lRunningItem,
1465- lRunningItem,
1466- &*rtm.DOUBLE_TYPE_ONE,
1467- tm,
1468- NULL,
1469- loc);
1470- lRunningType = rtm.DOUBLE_TYPE_ONE;
1471- }
1472-
1473- // implementation dependent: return the first occurence)
1474- if (lRunningItem->isNaN())
1475- {
1476- /** It must be checked if the sequence contains any
1477- * xs:double("NaN") [xs:double("NaN") is returned] or
1478- * only xs:float("NaN")'s [xs:float("NaN") is returned]'.
1479- */
1480- result = lRunningItem;
1481- if (TypeOps::is_subtype(tm, *lRunningType, *rtm.DOUBLE_TYPE_ONE))
1482- break;
1483-
1484- lMaxType = tm->create_value_type(result);
1485- }
1486-
1487- if (result != 0)
1488- {
1489- // Type Promotion
1490- store::Item_t lItemCur;
1491- if (!GenericCast::promote(lItemCur, lRunningItem, &*lMaxType, NULL, tm, loc))
1492- {
1493- if (GenericCast::promote(lItemCur, result, &*lRunningType, NULL, tm, loc))
1494+ PlanIteratorState* state;
1495+ DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
1496+
1497+ if (theChildren.size() == 2)
1498+ {
1499+ store::Item_t collationItem;
1500+ consumeNext(collationItem, theChildren[1], planState);
1501+ collator = theSctx->get_collator(collationItem->getStringValue().str(), loc);
1502+ }
1503+ else
1504+ {
1505+ collator = theSctx->get_default_collator(loc);
1506+ }
1507+
1508+ if (consumeNext(runningItem, theChildren[0], planState))
1509+ {
1510+ do
1511+ {
1512+ // casting of untyped atomic
1513+ store::SchemaTypeCode runningType = runningItem->getTypeCode();
1514+
1515+ if (runningType == store::XS_UNTYPED_ATOMIC)
1516+ {
1517+ GenericCast::castToBuiltinAtomic(runningItem,
1518+ runningItem,
1519+ store::XS_DOUBLE,
1520+ NULL,
1521+ loc);
1522+ runningType = store::XS_DOUBLE;
1523+ }
1524+
1525+ // implementation dependent: return the first occurence)
1526+ if (runningItem->isNaN())
1527+ {
1528+ // It must be checked if the sequence contains any
1529+ // xs:double("NaN") [xs:double("NaN") is returned] or
1530+ // only xs:float("NaN")'s [xs:float("NaN") is returned]'.
1531+
1532+ result = runningItem;
1533+ if (TypeOps::is_subtype(runningType, store::XS_DOUBLE))
1534+ break;
1535+
1536+ maxType = runningType;
1537+ }
1538+
1539+ if (result != 0)
1540+ {
1541+ // Type Promotion
1542+ store::Item_t lItemCur;
1543+ if (!GenericCast::promote(lItemCur, runningItem, maxType, NULL, tm, loc))
1544 {
1545- result.transfer(lItemCur);
1546- lMaxType = tm->create_value_type(result);
1547+ if (GenericCast::promote(lItemCur, result, runningType, NULL, tm, loc))
1548+ {
1549+ result.transfer(lItemCur);
1550+ maxType = result->getTypeCode();
1551+ }
1552+ else
1553+ {
1554+ RAISE_ERROR(err::FORG0006, loc,
1555+ ERROR_PARAMS(ZED(PromotionImpossible)));
1556+ }
1557 }
1558 else
1559 {
1560- RAISE_ERROR(err::FORG0006, loc,
1561- ERROR_PARAMS(ZED(PromotionImpossible)));
1562+ runningItem.transfer(lItemCur);
1563+ runningType = runningItem->getTypeCode();
1564+ }
1565+
1566+ store::Item_t current_copy(runningItem);
1567+ store::Item_t max_copy(result);
1568+ if (CompareIterator::valueComparison(loc,
1569+ current_copy,
1570+ max_copy,
1571+ theCompareType,
1572+ tm,
1573+ timezone,
1574+ collator))
1575+ {
1576+ maxType = runningType;
1577+ result.transfer(runningItem);
1578 }
1579 }
1580 else
1581 {
1582- lRunningItem.transfer(lItemCur);
1583- lRunningType = tm->create_value_type(lRunningItem);
1584- }
1585-
1586- store::Item_t current_copy(lRunningItem);
1587- store::Item_t max_copy(result);
1588- if (CompareIterator::valueComparison(loc,
1589- current_copy,
1590- max_copy,
1591- theCompareType,
1592- tm,
1593- timezone,
1594- lCollator) )
1595- {
1596- lMaxType = lRunningType;
1597- result.transfer(lRunningItem);
1598- }
1599- }
1600- else
1601- {
1602- lMaxType = lRunningType;
1603- result.transfer(lRunningItem);
1604- }
1605-
1606- elems_in_seq++;
1607- } while (consumeNext(lRunningItem, theChildren[0].getp(), planState));
1608+ maxType = runningType;
1609+ result.transfer(runningItem);
1610+ }
1611+
1612+ elems_in_seq++;
1613+ }
1614+ while (consumeNext(runningItem, theChildren[0], planState));
1615
1616 if (elems_in_seq == 1)
1617 {
1618@@ -231,7 +206,7 @@
1619 theCompareType,
1620 tm,
1621 timezone,
1622- lCollator);
1623+ collator);
1624 }
1625
1626 STACK_PUSH(result != NULL, state);
1627
1628=== modified file 'src/runtime/sequences/sequences_impl.cpp'
1629--- src/runtime/sequences/sequences_impl.cpp 2013-06-05 00:37:35 +0000
1630+++ src/runtime/sequences/sequences_impl.cpp 2013-06-11 09:57:50 +0000
1631@@ -1438,7 +1438,7 @@
1632 {
1633 store::Item_t lSumItem;
1634 store::Item_t lRunningItem;
1635- xqtref_t lRunningType;
1636+ store::SchemaTypeCode lRunningType;
1637 store::Item_t countItem;
1638 int lCount = 0;
1639 bool lHitNumeric = false, lHitYearMonth = false, lHitDayTime = false;
1640@@ -1446,86 +1446,101 @@
1641 const TypeManager* tm = theSctx->get_typemanager();
1642 const RootTypeManager& rtm = GENV_TYPESYSTEM;
1643
1644- xqtref_t lUntypedAtomic = rtm.UNTYPED_ATOMIC_TYPE_ONE;
1645- xqtref_t lYearMonthDuration = rtm.YM_DURATION_TYPE_ONE;
1646- xqtref_t lDayTimeDuration = rtm.DT_DURATION_TYPE_ONE;
1647-
1648 PlanIteratorState* state;
1649 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
1650
1651 while (consumeNext(lRunningItem, theChildren[0].getp(), planState))
1652 {
1653- lRunningType = tm->create_value_type(lRunningItem);
1654+ lRunningType = lRunningItem->getTypeCode();
1655
1656- if (TypeOps::is_numeric(tm, *lRunningType) ||
1657- TypeOps::is_equal(tm, *lRunningType, *lUntypedAtomic))
1658+ if (TypeOps::is_numeric(lRunningType) ||
1659+ lRunningType == store::XS_UNTYPED_ATOMIC)
1660 {
1661 lHitNumeric = true;
1662
1663- if ( lHitYearMonth )
1664+ if (lHitYearMonth)
1665+ {
1666+ xqtref_t type = tm->create_value_type(lRunningItem);
1667 RAISE_ERROR(err::FORG0006, loc,
1668 ERROR_PARAMS(ZED(BadArgTypeForFn_2o34o),
1669- *lRunningType,
1670+ *type,
1671 "fn:avg",
1672 ZED(ExpectedType_5),
1673- *lYearMonthDuration));
1674+ *rtm.YM_DURATION_TYPE_ONE));
1675+ }
1676
1677- if ( lHitDayTime )
1678+ if (lHitDayTime)
1679+ {
1680+ xqtref_t type = tm->create_value_type(lRunningItem);
1681 RAISE_ERROR(err::FORG0006, loc,
1682 ERROR_PARAMS(ZED( BadArgTypeForFn_2o34o ),
1683- *lRunningType,
1684+ *type,
1685 "fn:avg",
1686 ZED( ExpectedType_5 ),
1687- *lDayTimeDuration));
1688+ *rtm.DT_DURATION_TYPE_ONE));
1689+ }
1690 }
1691- else if (TypeOps::is_equal(tm, *lRunningType, *lYearMonthDuration))
1692+ else if (lRunningType == store::XS_YM_DURATION)
1693 {
1694 lHitYearMonth = true;
1695
1696 if (lHitNumeric)
1697+ {
1698+ xqtref_t type = tm->create_value_type(lRunningItem);
1699 RAISE_ERROR(err::FORG0006, loc,
1700 ERROR_PARAMS(ZED(BadArgTypeForFn_2o34o),
1701- *lRunningType,
1702+ *type,
1703 "fn:avg",
1704 ZED(ExpectedNumericType)));
1705+ }
1706
1707 if (lHitDayTime)
1708+ {
1709+ xqtref_t type = tm->create_value_type(lRunningItem);
1710 RAISE_ERROR(err::FORG0006, loc,
1711 ERROR_PARAMS(ZED( BadArgTypeForFn_2o34o ),
1712- *lRunningType,
1713+ *type,
1714 "fn:avg",
1715 ZED( ExpectedType_5 ),
1716- *lDayTimeDuration));
1717+ *rtm.DT_DURATION_TYPE_ONE));
1718+ }
1719 }
1720- else if (TypeOps::is_equal(tm, *lRunningType, *lDayTimeDuration))
1721+ else if (lRunningType == store::XS_DT_DURATION)
1722 {
1723 lHitDayTime = true;
1724
1725- if ( lHitNumeric )
1726+ if (lHitNumeric)
1727+ {
1728+ xqtref_t type = tm->create_value_type(lRunningItem);
1729 RAISE_ERROR(err::FORG0006, loc,
1730 ERROR_PARAMS(ZED(BadArgTypeForFn_2o34o),
1731- *lRunningType,
1732+ *type,
1733 "fn:avg",
1734 ZED(ExpectedNumericType)));
1735+ }
1736
1737- if ( lHitYearMonth )
1738+ if (lHitYearMonth)
1739+ {
1740+ xqtref_t type = tm->create_value_type(lRunningItem);
1741 RAISE_ERROR(err::FORG0006, loc,
1742 ERROR_PARAMS(ZED(BadArgTypeForFn_2o34o),
1743- *lRunningType,
1744+ *type,
1745 "fn:avg",
1746 ZED(ExpectedType_5),
1747- *lYearMonthDuration));
1748+ *rtm.YM_DURATION_TYPE_ONE));
1749+ }
1750 }
1751 else
1752 {
1753+ xqtref_t type = tm->create_value_type(lRunningItem);
1754 RAISE_ERROR(err::FORG0006, loc,
1755 ERROR_PARAMS(ZED(BadArgTypeForFn_2o34o),
1756- *lRunningType,
1757+ *type,
1758 "fn:avg",
1759 ZED(ExpectedNumericOrDurationType)));
1760 }
1761
1762- if ( lCount++ == 0 )
1763+ if (lCount++ == 0)
1764 {
1765 lSumItem = lRunningItem;
1766 }
1767@@ -1559,17 +1574,17 @@
1768 STACK_END (state);
1769 }
1770
1771+
1772 /*******************************************************************************
1773 15.4.5 fn:sum - Generic
1774 ********************************************************************************/
1775 bool FnSumIterator::nextImpl(store::Item_t& result, PlanState& planState) const
1776 {
1777 store::Item_t lRunningItem;
1778- xqtref_t lResultType;
1779- xqtref_t lRunningType;
1780+ store::SchemaTypeCode lResultType;
1781+ store::SchemaTypeCode lRunningType;
1782
1783 const TypeManager* tm = theSctx->get_typemanager();
1784- const RootTypeManager& rtm = GENV_TYPESYSTEM;
1785
1786 PlanIteratorState* state;
1787 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
1788@@ -1577,37 +1592,37 @@
1789 if (consumeNext(result, theChildren[0].getp(), planState))
1790 {
1791 // casting of untyped atomic
1792- lResultType = tm->create_value_type(result);
1793+ lResultType = result->getTypeCode();
1794
1795- if (TypeOps::is_subtype(tm, *lResultType, *rtm.UNTYPED_ATOMIC_TYPE_ONE))
1796+ if (lResultType == store::XS_UNTYPED_ATOMIC)
1797 {
1798- GenericCast::castToAtomic(result, result, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, loc);
1799- lResultType = rtm.DOUBLE_TYPE_ONE;
1800+ GenericCast::castToBuiltinAtomic(result, result, store::XS_DOUBLE, NULL, loc);
1801+ lResultType = store::XS_DOUBLE;
1802 }
1803
1804- if (!TypeOps::is_numeric(tm, *lResultType) &&
1805- (!TypeOps::is_subtype(tm, *lResultType, *rtm.DURATION_TYPE_ONE) ||
1806- TypeOps::is_equal(tm, *lResultType, *rtm.DURATION_TYPE_ONE)))
1807+ if (!TypeOps::is_numeric(lResultType) &&
1808+ (!TypeOps::is_subtype(lResultType, store::XS_DURATION) ||
1809+ lResultType == store::XS_DURATION))
1810 {
1811+ xqtref_t type = tm->create_value_type(result);
1812 RAISE_ERROR(err::FORG0006, loc,
1813- ERROR_PARAMS(ZED(BadArgTypeForFn_2o34o), *lResultType, "fn:sum"));
1814+ ERROR_PARAMS(ZED(BadArgTypeForFn_2o34o), *type, "fn:sum"));
1815 }
1816
1817 while (consumeNext(lRunningItem, theChildren[0].getp(), planState))
1818 {
1819 // casting of untyped atomic
1820- lRunningType = tm->create_value_type(lRunningItem);
1821+ lRunningType = lRunningItem->getTypeCode();
1822
1823- if (TypeOps::is_subtype(tm, *lRunningType, *rtm.UNTYPED_ATOMIC_TYPE_ONE))
1824+ if (lRunningType == store::XS_UNTYPED_ATOMIC)
1825 {
1826- GenericCast::castToAtomic(lRunningItem,
1827- lRunningItem,
1828- &*rtm.DOUBLE_TYPE_ONE,
1829- tm,
1830- NULL,
1831- loc);
1832+ GenericCast::castToBuiltinAtomic(lRunningItem,
1833+ lRunningItem,
1834+ store::XS_DOUBLE,
1835+ NULL,
1836+ loc);
1837
1838- lRunningType = rtm.DOUBLE_TYPE_ONE;
1839+ lRunningType = store::XS_DOUBLE;
1840 }
1841
1842 // handling of NaN
1843@@ -1617,12 +1632,12 @@
1844 break;
1845 }
1846
1847- if((TypeOps::is_numeric(tm, *lResultType) &&
1848- TypeOps::is_numeric(tm, *lRunningType)) ||
1849- (TypeOps::is_subtype(tm, *lResultType, *rtm.YM_DURATION_TYPE_ONE) &&
1850- TypeOps::is_subtype(tm, *lRunningType, *rtm.YM_DURATION_TYPE_ONE)) ||
1851- (TypeOps::is_subtype(tm, *lResultType, *rtm.DT_DURATION_TYPE_ONE) &&
1852- TypeOps::is_subtype(tm, *lRunningType, *rtm.DT_DURATION_TYPE_ONE)))
1853+ if ((TypeOps::is_numeric(lResultType) &&
1854+ TypeOps::is_numeric(lRunningType)) ||
1855+ (TypeOps::is_subtype(lResultType, store::XS_YM_DURATION) &&
1856+ TypeOps::is_subtype(lRunningType, store::XS_YM_DURATION)) ||
1857+ (TypeOps::is_subtype(lResultType, store::XS_DT_DURATION) &&
1858+ TypeOps::is_subtype(lRunningType, store::XS_DT_DURATION)))
1859 {
1860 GenericArithIterator<AddOperation>::compute(result,
1861 planState.theLocalDynCtx,
1862@@ -1633,13 +1648,10 @@
1863 }
1864 else
1865 {
1866- throw XQUERY_EXCEPTION(
1867- err::FORG0006,
1868- ERROR_PARAMS(
1869- ZED( SumImpossibleWithTypes_23 ), *lResultType, *lRunningType
1870- ),
1871- ERROR_LOC( loc )
1872- );
1873+ xqtref_t type1 = tm->create_value_type(result);
1874+ xqtref_t type2 = tm->create_value_type(lRunningItem);
1875+ RAISE_ERROR(err::FORG0006, loc,
1876+ ERROR_PARAMS(ZED( SumImpossibleWithTypes_23 ), *type1, *type2));
1877 }
1878 }
1879
1880@@ -1657,18 +1669,16 @@
1881 }
1882 else
1883 {
1884- STACK_PUSH(
1885- GENV_ITEMFACTORY->createInteger(
1886- result, numeric_consts<xs_integer>::zero()
1887- ),
1888- state
1889- );
1890+ STACK_PUSH(GENV_ITEMFACTORY->
1891+ createInteger(result, numeric_consts<xs_integer>::zero()),
1892+ state);
1893 }
1894 }
1895
1896- STACK_END (state);
1897+ STACK_END(state);
1898 }
1899
1900+
1901 /*******************************************************************************
1902 15.4.5 fn:sum - Double
1903 ********************************************************************************/
1904@@ -1766,6 +1776,7 @@
1905 STACK_END (state);
1906 }
1907
1908+
1909 /*******************************************************************************
1910 15.4.5 fn:sum - Decimal
1911 ********************************************************************************/
1912@@ -1814,6 +1825,7 @@
1913 STACK_END (state);
1914 }
1915
1916+
1917 /*******************************************************************************
1918 15.4.5 fn:sum - Integer
1919 ********************************************************************************/
1920@@ -1823,8 +1835,8 @@
1921 {
1922 xs_integer sum;
1923 store::Item_t item;
1924- xqtref_t lResultType;
1925- xqtref_t lTmpType;
1926+ store::SchemaTypeCode lResultType;
1927+ store::SchemaTypeCode lTmpType;
1928
1929 const TypeManager* tm = theSctx->get_typemanager();
1930
1931@@ -1833,13 +1845,15 @@
1932
1933 if (consumeNext(item, theChildren[0].getp(), planState))
1934 {
1935- lResultType = tm->create_value_type(item);
1936+ lResultType = item->getTypeCode();
1937+
1938 sum = item->getIntegerValue();
1939
1940 while (consumeNext(item, theChildren[0].getp(), planState))
1941 {
1942- lTmpType = tm->create_value_type(item);
1943- if(TypeOps::is_subtype(tm, *lResultType, *lTmpType))
1944+ lTmpType = item->getTypeCode();
1945+
1946+ if (TypeOps::is_subtype(lResultType, lTmpType))
1947 lResultType = lTmpType;
1948
1949 if (item->isNaN())
1950@@ -1852,7 +1866,8 @@
1951 }
1952
1953 GENV_ITEMFACTORY->createInteger(result, sum);
1954- GenericCast::castToAtomic(result, result, &*lResultType, tm, NULL, loc);
1955+
1956+ GenericCast::castToBuiltinAtomic(result, result, lResultType, NULL, loc);
1957
1958 STACK_PUSH(true, state);
1959 }
1960@@ -1872,6 +1887,7 @@
1961 STACK_END (state);
1962 }
1963
1964+
1965 /*******************************************************************************
1966 15.5.1 op:to
1967 ********************************************************************************/
1968@@ -1906,6 +1922,7 @@
1969 STACK_END (state);
1970 }
1971
1972+
1973 /*******************************************************************************
1974 15.5.4 fn:doc
1975 ********************************************************************************/
1976
1977=== modified file 'src/runtime/store/maps_impl.cpp'
1978--- src/runtime/store/maps_impl.cpp 2013-05-08 20:14:47 +0000
1979+++ src/runtime/store/maps_impl.cpp 2013-06-11 09:57:50 +0000
1980@@ -77,10 +77,7 @@
1981 loc ) )
1982 {
1983 RAISE_ERROR(zerr::ZXQD0005_INVALID_KEY_FOR_MAP, loc,
1984- ERROR_PARAMS(*searchKeyType,
1985- *indexKeyType,
1986- aQName->getStringValue())
1987- );
1988+ ERROR_PARAMS(*searchKeyType, *indexKeyType, aQName->getStringValue()));
1989 }
1990 else
1991 {
1992@@ -91,10 +88,7 @@
1993 if ( e.diagnostic() == err::FORG0001 )
1994 {
1995 RAISE_ERROR(zerr::ZXQD0005_INVALID_KEY_FOR_MAP, loc,
1996- ERROR_PARAMS(*searchKeyType,
1997- *indexKeyType,
1998- aQName->getStringValue())
1999- );
2000+ ERROR_PARAMS(*searchKeyType, *indexKeyType, aQName->getStringValue()));
2001 }
2002 throw;
2003 }
2004
2005=== modified file 'src/types/typeops.cpp'
2006--- src/types/typeops.cpp 2013-06-03 23:03:58 +0000
2007+++ src/types/typeops.cpp 2013-06-11 09:57:50 +0000
2008@@ -1151,7 +1151,6 @@
2009
2010 RootTypeManager& rtm = GENV_TYPESYSTEM;
2011
2012- xqtref_t resultType;
2013 TypeConstants::quantifier_t resultQuant = TypeConstants::QUANT_ONE;
2014
2015 TypeConstants::quantifier_t quant1 = type1.get_quantifier();
2016@@ -1166,43 +1165,43 @@
2017 }
2018
2019 if (division &&
2020- TypeOps::is_subtype(tm, type1, *rtm.INTEGER_TYPE_STAR) &&
2021- TypeOps::is_subtype(tm, type2, *rtm.INTEGER_TYPE_STAR))
2022+ is_subtype(tm, type1, *rtm.INTEGER_TYPE_STAR) &&
2023+ is_subtype(tm, type2, *rtm.INTEGER_TYPE_STAR))
2024 {
2025 return (resultQuant == TypeConstants::QUANT_ONE ?
2026 rtm.DECIMAL_TYPE_ONE : rtm.DECIMAL_TYPE_QUESTION);
2027 }
2028
2029- if (TypeOps::is_subtype(tm, type1, *rtm.UNTYPED_ATOMIC_TYPE_STAR) ||
2030- TypeOps::is_subtype(tm, type2, *rtm.UNTYPED_ATOMIC_TYPE_STAR))
2031- {
2032- return (resultQuant == TypeConstants::QUANT_ONE ?
2033- rtm.DOUBLE_TYPE_ONE : rtm.DOUBLE_TYPE_QUESTION);
2034- }
2035-
2036- if (TypeOps::is_subtype(tm, type1, *rtm.DOUBLE_TYPE_STAR) ||
2037- TypeOps::is_subtype(tm, type2, *rtm.DOUBLE_TYPE_STAR))
2038- {
2039- return (resultQuant == TypeConstants::QUANT_ONE ?
2040- rtm.DOUBLE_TYPE_ONE : rtm.DOUBLE_TYPE_QUESTION);
2041- }
2042-
2043- if (TypeOps::is_subtype(tm, type1, *rtm.FLOAT_TYPE_STAR) ||
2044- TypeOps::is_subtype(tm, type2, *rtm.FLOAT_TYPE_STAR))
2045+ if (is_subtype(tm, type1, *rtm.UNTYPED_ATOMIC_TYPE_STAR) ||
2046+ is_subtype(tm, type2, *rtm.UNTYPED_ATOMIC_TYPE_STAR))
2047+ {
2048+ return (resultQuant == TypeConstants::QUANT_ONE ?
2049+ rtm.DOUBLE_TYPE_ONE : rtm.DOUBLE_TYPE_QUESTION);
2050+ }
2051+
2052+ if (is_subtype(tm, type1, *rtm.DOUBLE_TYPE_STAR) ||
2053+ is_subtype(tm, type2, *rtm.DOUBLE_TYPE_STAR))
2054+ {
2055+ return (resultQuant == TypeConstants::QUANT_ONE ?
2056+ rtm.DOUBLE_TYPE_ONE : rtm.DOUBLE_TYPE_QUESTION);
2057+ }
2058+
2059+ if (is_subtype(tm, type1, *rtm.FLOAT_TYPE_STAR) ||
2060+ is_subtype(tm, type2, *rtm.FLOAT_TYPE_STAR))
2061 {
2062 return (resultQuant == TypeConstants::QUANT_ONE ?
2063 rtm.FLOAT_TYPE_ONE : rtm.FLOAT_TYPE_QUESTION);
2064 }
2065
2066- if (TypeOps::is_subtype(tm, type1, *rtm.INTEGER_TYPE_STAR) &&
2067- TypeOps::is_subtype(tm, type2, *rtm.INTEGER_TYPE_STAR))
2068+ if (is_subtype(tm, type1, *rtm.INTEGER_TYPE_STAR) &&
2069+ is_subtype(tm, type2, *rtm.INTEGER_TYPE_STAR))
2070 {
2071 return (resultQuant == TypeConstants::QUANT_ONE ?
2072 rtm.INTEGER_TYPE_ONE : rtm.INTEGER_TYPE_QUESTION);
2073 }
2074
2075- if (TypeOps::is_subtype(tm, type1, *rtm.DECIMAL_TYPE_STAR) &&
2076- TypeOps::is_subtype(tm, type2, *rtm.DECIMAL_TYPE_STAR))
2077+ if (is_subtype(tm, type1, *rtm.DECIMAL_TYPE_STAR) &&
2078+ is_subtype(tm, type2, *rtm.DECIMAL_TYPE_STAR))
2079 {
2080 return (resultQuant == TypeConstants::QUANT_ONE ?
2081 rtm.DECIMAL_TYPE_ONE : rtm.DECIMAL_TYPE_QUESTION);
2082@@ -1215,6 +1214,50 @@
2083 /*******************************************************************************
2084
2085 ********************************************************************************/
2086+store::SchemaTypeCode TypeOps::arithmetic_type(
2087+ store::SchemaTypeCode type1,
2088+ store::SchemaTypeCode type2,
2089+ bool division)
2090+{
2091+ if (division &&
2092+ is_subtype(type1, store::XS_INTEGER) &&
2093+ is_subtype(type2, store::XS_INTEGER))
2094+ {
2095+ return store::XS_DECIMAL;
2096+ }
2097+
2098+ if (type1 == store::XS_UNTYPED_ATOMIC || type2 == store::XS_UNTYPED_ATOMIC)
2099+ {
2100+ return store::XS_DOUBLE;
2101+ }
2102+
2103+ if (is_subtype(type1, store::XS_DOUBLE) || is_subtype(type2, store::XS_DOUBLE))
2104+ {
2105+ return store::XS_DOUBLE;
2106+ }
2107+
2108+ if (is_subtype(type1, store::XS_FLOAT) || is_subtype(type2, store::XS_FLOAT))
2109+ {
2110+ return store::XS_FLOAT;
2111+ }
2112+
2113+ if (is_subtype(type1, store::XS_INTEGER) && is_subtype(type2, store::XS_INTEGER))
2114+ {
2115+ return store::XS_INTEGER;
2116+ }
2117+
2118+ if (is_subtype(type1, store::XS_DECIMAL) && is_subtype(type2, store::XS_DECIMAL))
2119+ {
2120+ return store::XS_DECIMAL;
2121+ }
2122+
2123+ return store::XS_ANY_ATOMIC;
2124+}
2125+
2126+
2127+/*******************************************************************************
2128+
2129+********************************************************************************/
2130 static inline IdentTypes::quantifier_t get_typeident_quant(
2131 TypeConstants::quantifier_t quant)
2132 {
2133
2134=== modified file 'src/types/typeops.h'
2135--- src/types/typeops.h 2013-02-07 17:24:36 +0000
2136+++ src/types/typeops.h 2013-06-11 09:57:50 +0000
2137@@ -181,6 +181,11 @@
2138 const XQType& type2,
2139 bool division);
2140
2141+ static store::SchemaTypeCode arithmetic_type(
2142+ store::SchemaTypeCode type1,
2143+ store::SchemaTypeCode type2,
2144+ bool division);
2145+
2146 /*
2147 * Returns a type identifier that represents the given type.
2148 * The invariant that is guaranteed is:

Subscribers

People subscribed via source and target branches