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

Proposed by Markos Zaharioudakis
Status: Merged
Approved by: Markos Zaharioudakis
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
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

optimized switch expression

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

Validation queue job 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
=== modified file 'ChangeLog'
--- ChangeLog 2013-06-08 05:33:57 +0000
+++ ChangeLog 2013-06-11 09:57:50 +0000
@@ -13,6 +13,8 @@
13 * Optimized implementation of fn:deep-equal13 * Optimized implementation of fn:deep-equal
14 * No need to apply document ordering on the domain expression of a FOR clause14 * No need to apply document ordering on the domain expression of a FOR clause
15 if the FOR clause is followed by an orderby or groupby clause.15 if the FOR clause is followed by an orderby or groupby clause.
16 * Replaced use of create_value_type() in runtime with getTypeCode().
17 * Optimized switch expression
1618
17Bug Fixes/Other Changes:19Bug Fixes/Other Changes:
18 * Fixed bug #1117952 (Improve XML error output format)20 * Fixed bug #1117952 (Improve XML error output format)
1921
=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp 2013-06-09 08:09:40 +0000
+++ src/compiler/translator/translator.cpp 2013-06-11 09:57:50 +0000
@@ -7977,41 +7977,16 @@
79777977
7978 se = wrap_in_atomization(se);7978 se = wrap_in_atomization(se);
79797979
7980 // atomizedFlwor = [let $atomv := data(E) return NULL]7980 se = CREATE(treat)(theRootSctx, theUDF, loc,
7981 var_expr* atomv = create_temp_var(v.get_switch_expr()->get_location(),7981 se,
7982 var_expr::let_var);7982 theRTM.ANY_ATOMIC_TYPE_QUESTION,
79837983 TREAT_TYPE_MATCH,
7984 expr* atomizedFlwor = wrap_in_let_flwor(se, atomv, NULL);7984 false);
79857985
7986 // TODO: cast as xs:string should not really be necessary7986 // flworExpr = [let $sv := data(E) treat as xs:anyAtomicType? return NULL]
7987 // atomizedFlwor =
7988 // [let $atomv := data(E)
7989 // return
7990 // let $sv :=
7991 // if ($atomv instanceof xs:untypedAtomic)
7992 // then $atomv cast as xs:string
7993 // else $atomv
7994 // return NULL]
7995 static_cast<flwor_expr*>(atomizedFlwor)->set_return_expr(
7996 CREATE(if)(theRootSctx,
7997 theUDF,
7998 loc,
7999 CREATE(instanceof)(theRootSctx,
8000 theUDF,
8001 loc,
8002 atomv,
8003 theRTM.UNTYPED_ATOMIC_TYPE_ONE),
8004 CREATE(cast)(theRootSctx,
8005 theUDF,
8006 loc,
8007 atomv,
8008 theRTM.STRING_TYPE_ONE,
8009 false),
8010 atomv));
8011
8012 // flworExpr = [let $sv := atomizedFlwor return NULL]
8013 var_expr* sv = create_temp_var(v.get_switch_expr()->get_location(), var_expr::let_var);7987 var_expr* sv = create_temp_var(v.get_switch_expr()->get_location(), var_expr::let_var);
8014 expr* flworExpr = wrap_in_let_flwor(atomizedFlwor, sv, NULL);7988
7989 expr* flworExpr = wrap_in_let_flwor(se, sv, NULL);
80157990
8016 // retExpr = [Ed]7991 // retExpr = [Ed]
8017 v.get_default_expr()->accept(*this);7992 v.get_default_expr()->accept(*this);
@@ -8039,7 +8014,7 @@
8039 operand->accept(*this);8014 operand->accept(*this);
80408015
8041 expr* operandExpr = pop_nodestack();8016 expr* operandExpr = pop_nodestack();
8042 operandExpr = wrap_in_atomization(operandExpr);8017
8043 operandExpr = CREATE(fo)(theRootSctx,8018 operandExpr = CREATE(fo)(theRootSctx,
8044 theUDF,8019 theUDF,
8045 loc,8020 loc,
@@ -8047,6 +8022,8 @@
8047 sv,8022 sv,
8048 operandExpr);8023 operandExpr);
8049 8024
8025 normalize_fo(static_cast<fo_expr*>(operandExpr));
8026
8050 condOperands.push_back(operandExpr);8027 condOperands.push_back(operandExpr);
8051 } // for8028 } // for
80528029
@@ -8056,20 +8033,15 @@
8056 }8033 }
8057 else if (condOperands.size() > 1)8034 else if (condOperands.size() > 1)
8058 {8035 {
8059 condExpr = theExprManager->8036 condExpr = CREATE(fo)(theRootSctx, theUDF, loc,
8060 create_fo_expr(theRootSctx,8037 BUILTIN_FUNC(OP_OR_N), condOperands);
8061 theUDF,
8062 loc,
8063 BUILTIN_FUNC(OP_OR_N),
8064 condOperands);
8065 }8038 }
80668039
8067 switchCaseClause->get_return_expr()->accept(*this);8040 switchCaseClause->get_return_expr()->accept(*this);
8068 expr* caseReturnExpr = pop_nodestack();8041 expr* caseReturnExpr = pop_nodestack();
80698042
8070 // retExpr = [if (condExpr) then caseReturnExpr else retExpr]8043 // retExpr = [if (condExpr) then caseReturnExpr else retExpr]
8071 retExpr = theExprManager->8044 retExpr = CREATE(if)(theRootSctx, theUDF, loc, condExpr, caseReturnExpr, retExpr);
8072 create_if_expr(theRootSctx, theUDF, loc, condExpr, caseReturnExpr, retExpr);
80738045
8074 } // for8046 } // for
80758047
@@ -8088,6 +8060,7 @@
8088 ZORBA_ASSERT (false);8060 ZORBA_ASSERT (false);
8089}8061}
80908062
8063
8091void* begin_visit(const SwitchCaseClause& v)8064void* begin_visit(const SwitchCaseClause& v)
8092{8065{
8093 TRACE_VISIT();8066 TRACE_VISIT();
@@ -8095,7 +8068,7 @@
8095 return NULL;8068 return NULL;
8096}8069}
80978070
8098void end_visit (const SwitchCaseClause& v, void* /*visit_state*/)8071void end_visit(const SwitchCaseClause& v, void* /*visit_state*/)
8099{8072{
8100 TRACE_VISIT_OUT ();8073 TRACE_VISIT_OUT ();
8101 // shouldn't get here, begin_visit() rejects visitor8074 // shouldn't get here, begin_visit() rejects visitor
81028075
=== modified file 'src/functions/func_booleans_impl.cpp'
--- src/functions/func_booleans_impl.cpp 2013-02-07 17:24:36 +0000
+++ src/functions/func_booleans_impl.cpp 2013-06-11 09:57:50 +0000
@@ -868,8 +868,8 @@
868// http://www.w3.org/TR/xquery-11/#dt-equivalence-two-atomic-values868// http://www.w3.org/TR/xquery-11/#dt-equivalence-two-atomic-values
869DECL(sctx, op_atomic_values_equivalent,869DECL(sctx, op_atomic_values_equivalent,
870 (createQName(zorba_ns, "", "atomic-values-equivalent"),870 (createQName(zorba_ns, "", "atomic-values-equivalent"),
871 GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_STAR,871 GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_QUESTION,
872 GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_STAR,872 GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_QUESTION,
873 GENV_TYPESYSTEM.BOOLEAN_TYPE_ONE));873 GENV_TYPESYSTEM.BOOLEAN_TYPE_ONE));
874874
875}875}
876876
=== modified file 'src/runtime/booleans/BooleanImpl.cpp'
--- src/runtime/booleans/BooleanImpl.cpp 2013-05-08 20:14:47 +0000
+++ src/runtime/booleans/BooleanImpl.cpp 2013-06-11 09:57:50 +0000
@@ -121,7 +121,6 @@
121 // node => true121 // node => true
122 result = negate ^ true;122 result = negate ^ true;
123 }123 }
124#ifdef ZORBA_WITH_JSON
125 else if (item->isJSONItem())124 else if (item->isJSONItem())
126 {125 {
127 xqtref_t type = tm->create_value_type(item);126 xqtref_t type = tm->create_value_type(item);
@@ -129,7 +128,6 @@
129 RAISE_ERROR(err::FORG0006, loc,128 RAISE_ERROR(err::FORG0006, loc,
130 ERROR_PARAMS(ZED(BadArgTypeForFn_2o34o), *type, "fn:boolean" ));129 ERROR_PARAMS(ZED(BadArgTypeForFn_2o34o), *type, "fn:boolean" ));
131 }130 }
132#endif
133 else131 else
134 {132 {
135 store::SchemaTypeCode type = item->getTypeCode();133 store::SchemaTypeCode type = item->getTypeCode();
@@ -1221,86 +1219,67 @@
1221 store::Item_t& result,1219 store::Item_t& result,
1222 PlanState& planState) const1220 PlanState& planState) const
1223{1221{
1224 store::Item_t lItem0, lItem1, tItem0, tItem1;1222 store::Item_t lItem0, lItem1;
1225 int count0, count1;1223 store::SchemaTypeCode type0;
1226 xqtref_t type0, type1;1224 store::SchemaTypeCode type1;
1227 bool are_equivalent;1225 bool are_equivalent;
12281226
1229 RootTypeManager& rtm = GENV_TYPESYSTEM;
1230 TypeManager* tm = theSctx->get_typemanager();
1231
1232 PlanIteratorState* state;1227 PlanIteratorState* state;
1233 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);1228 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
12341229
1235 count0 = 0;
1236 count1 = 0;
1237
1238 if (consumeNext(lItem0, theChild0.getp(), planState))1230 if (consumeNext(lItem0, theChild0.getp(), planState))
1239 count0 = 1;1231 {
12401232 if (consumeNext(lItem1, theChild1.getp(), planState))
1241 if (count0 && consumeNext(tItem0, theChild0.getp(), planState))1233 {
1242 throw XQUERY_EXCEPTION(1234 type0 = lItem0->getTypeCode();
1243 err::XPTY0004,1235 type1 = lItem1->getTypeCode();
1244 ERROR_PARAMS( ZED( NoSeqTestedForAtomicEquiv ) ),1236
1245 ERROR_LOC( loc )1237 if ((TypeOps::is_subtype(type0, store::XS_FLOAT) ||
1246 );1238 TypeOps::is_subtype(type0, store::XS_DOUBLE))
12471239 &&
1248 if (consumeNext(lItem1, theChild1.getp(), planState))1240 (TypeOps::is_subtype(type1, store::XS_FLOAT) ||
1249 count1 = 1;1241 TypeOps::is_subtype(type1, store::XS_DOUBLE))
12501242 &&
1251 if (count1 && consumeNext(tItem1, theChild1.getp(), planState))1243 lItem0->isNaN() && lItem1->isNaN())
1252 throw XQUERY_EXCEPTION(1244 {
1253 err::XPTY0004,1245 STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, true), state);
1254 ERROR_PARAMS( ZED( NoSeqTestedForAtomicEquiv ) ),1246 }
1255 ERROR_LOC( loc )1247 else
1256 );1248 {
12571249 try
1258 if (count0 == 0 && count1 == 0)1250 {
1251 are_equivalent = CompareIterator::valueEqual(loc,
1252 lItem0,
1253 lItem1,
1254 theTypeManager,
1255 theTimezone,
1256 theCollation);
1257 }
1258 catch (ZorbaException const& e)
1259 {
1260 if (e.diagnostic() == err::XPTY0004)
1261 are_equivalent = false;
1262 else
1263 throw;
1264 }
1265
1266 STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, are_equivalent),
1267 state);
1268 }
1269 }
1270 else
1271 {
1272 STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, false), state);
1273 }
1274 }
1275 else if (consumeNext(lItem1, theChild1.getp(), planState))
1276 {
1277 STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, false), state);
1278 }
1279 else
1259 {1280 {
1260 STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, true), state);1281 STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, true), state);
1261 }1282 }
1262 else if ((count0 == 0 && count1 == 1) || (count0 == 1 && count1 == 0))
1263 {
1264 STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, false), state);
1265 }
1266 else
1267 {
1268 type0 = theTypeManager->create_value_type(lItem0.getp());
1269 type1 = theTypeManager->create_value_type(lItem1.getp());
1270
1271 if ((TypeOps::is_subtype(tm, *type0, *rtm.FLOAT_TYPE_ONE) ||
1272 TypeOps::is_subtype(tm, *type0, *rtm.DOUBLE_TYPE_ONE))
1273 &&
1274 (TypeOps::is_subtype(tm, *type1, *rtm.FLOAT_TYPE_ONE) ||
1275 TypeOps::is_subtype(tm, *type1, *rtm.DOUBLE_TYPE_ONE))
1276 &&
1277 lItem0->isNaN() && lItem1->isNaN())
1278 {
1279 STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, true), state);
1280 }
1281 else
1282 {
1283 try
1284 {
1285 are_equivalent = CompareIterator::valueEqual(loc,
1286 lItem0,
1287 lItem1,
1288 theTypeManager,
1289 theTimezone,
1290 theCollation);
1291 }
1292 catch (ZorbaException const& e)
1293 {
1294 if (e.diagnostic() == err::XPTY0004)
1295 are_equivalent = false;
1296 else
1297 throw;
1298 }
1299
1300 STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, are_equivalent),
1301 state);
1302 }
1303 }
13041283
1305 STACK_END(state);1284 STACK_END(state);
1306}1285}
13071286
=== modified file 'src/runtime/core/arithmetic_impl.cpp'
--- src/runtime/core/arithmetic_impl.cpp 2013-05-08 20:14:47 +0000
+++ src/runtime/core/arithmetic_impl.cpp 2013-06-11 09:57:50 +0000
@@ -167,16 +167,16 @@
167 assert(n0->isAtomic());167 assert(n0->isAtomic());
168 assert(n1->isAtomic());168 assert(n1->isAtomic());
169169
170 xqtref_t type0 = tm->create_value_type(n0);170 store::SchemaTypeCode type0 = n0->getTypeCode();
171 xqtref_t type1 = tm->create_value_type(n1);171 store::SchemaTypeCode type1 = n1->getTypeCode();
172 172
173 if (TypeOps::is_numeric(tm, *type0) &&173 if (TypeOps::is_numeric(type0) &&
174 (TypeOps::is_subtype(tm, *type1, *rtm.YM_DURATION_TYPE_ONE) ||174 (TypeOps::is_subtype(type1, store::XS_YM_DURATION) ||
175 TypeOps::is_subtype(tm, *type1, *rtm.DT_DURATION_TYPE_ONE)))175 TypeOps::is_subtype(type1, store::XS_DT_DURATION)))
176 {176 {
177 GenericCast::castToAtomic(n0, n0, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, aLoc);177 GenericCast::castToAtomic(n0, n0, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, aLoc);
178178
179 if (TypeOps::is_subtype(tm, *type1, *rtm.YM_DURATION_TYPE_ONE))179 if (TypeOps::is_subtype(type1, store::XS_YM_DURATION))
180 {180 {
181 return Operation::template181 return Operation::template
182 compute<store::XS_DOUBLE, store::XS_YM_DURATION>182 compute<store::XS_DOUBLE, store::XS_YM_DURATION>
@@ -189,44 +189,44 @@
189 (result, dctx, tm, &aLoc, n0, n1);189 (result, dctx, tm, &aLoc, n0, n1);
190 }190 }
191 }191 }
192 else if (TypeOps::is_subtype(tm, *type0, *rtm.DT_DURATION_TYPE_ONE) &&192 else if (TypeOps::is_subtype(type0, store::XS_DT_DURATION) &&
193 TypeOps::is_subtype(tm, *type1, *rtm.TIME_TYPE_ONE))193 TypeOps::is_subtype(type1, store::XS_TIME))
194 {194 {
195 return Operation::template195 return Operation::template
196 compute<store::XS_DURATION,store::XS_TIME>196 compute<store::XS_DURATION,store::XS_TIME>
197 (result, dctx, tm, &aLoc, n0, n1);197 (result, dctx, tm, &aLoc, n0, n1);
198 }198 }
199 else if (TypeOps::is_subtype(tm, *type0, *rtm.YM_DURATION_TYPE_ONE))199 else if (TypeOps::is_subtype(type0, store::XS_YM_DURATION))
200 {200 {
201 if(TypeOps::is_numeric(tm, *type1))201 if (TypeOps::is_numeric(type1))
202 {202 {
203 GenericCast::castToAtomic(n1, n1, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, aLoc);203 GenericCast::castToAtomic(n1, n1, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, aLoc);
204 return Operation::template204 return Operation::template
205 compute<store::XS_YM_DURATION,store::XS_DOUBLE>205 compute<store::XS_YM_DURATION,store::XS_DOUBLE>
206 (result, dctx, tm, &aLoc, n0, n1);206 (result, dctx, tm, &aLoc, n0, n1);
207 }207 }
208 else if (TypeOps::is_subtype(tm, *type1, *rtm.DATETIME_TYPE_ONE))208 else if (TypeOps::is_subtype(type1, store::XS_DATETIME))
209 {209 {
210 return Operation::template210 return Operation::template
211 compute<store::XS_DURATION,store::XS_DATETIME>211 compute<store::XS_DURATION,store::XS_DATETIME>
212 (result, dctx, tm, &aLoc, n0, n1);212 (result, dctx, tm, &aLoc, n0, n1);
213 }213 }
214 else if (TypeOps::is_subtype(tm, *type1, *rtm.DATE_TYPE_ONE))214 else if (TypeOps::is_subtype(type1, store::XS_DATE))
215 {215 {
216 return Operation::template216 return Operation::template
217 compute<store::XS_DURATION,store::XS_DATE>217 compute<store::XS_DURATION,store::XS_DATE>
218 (result, dctx, tm, &aLoc, n0, n1);218 (result, dctx, tm, &aLoc, n0, n1);
219 }219 }
220 else if (TypeOps::is_equal(tm, *type0, *type1))220 else if (type0 == type1)
221 {221 {
222 return Operation::template222 return Operation::template
223 computeSingleType<store::XS_YM_DURATION>223 computeSingleType<store::XS_YM_DURATION>
224 (result, dctx, tm, &aLoc, n0, n1);224 (result, dctx, tm, &aLoc, n0, n1);
225 }225 }
226 }226 }
227 else if (TypeOps::is_subtype(tm, *type0, *rtm.DT_DURATION_TYPE_ONE))227 else if (TypeOps::is_subtype(type0, store::XS_DT_DURATION))
228 {228 {
229 if(TypeOps::is_numeric(tm, *type1))229 if (TypeOps::is_numeric(type1))
230 {230 {
231 GenericCast::castToAtomic(n1, n1, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, aLoc);231 GenericCast::castToAtomic(n1, n1, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, aLoc);
232232
@@ -234,94 +234,96 @@
234 compute<store::XS_DT_DURATION,store::XS_DOUBLE>234 compute<store::XS_DT_DURATION,store::XS_DOUBLE>
235 (result, dctx, tm, &aLoc, n0, n1);235 (result, dctx, tm, &aLoc, n0, n1);
236 }236 }
237 else if (TypeOps::is_subtype(tm, *type1, *rtm.DATETIME_TYPE_ONE))237 else if (TypeOps::is_subtype(type1, store::XS_DATETIME))
238 {238 {
239 return Operation::template 239 return Operation::template
240 compute<store::XS_DURATION,store::XS_DATETIME>240 compute<store::XS_DURATION,store::XS_DATETIME>
241 (result, dctx, tm, &aLoc, n0, n1);241 (result, dctx, tm, &aLoc, n0, n1);
242 }242 }
243 else if (TypeOps::is_subtype(tm, *type1, *rtm.DATE_TYPE_ONE))243 else if (TypeOps::is_subtype(type1, store::XS_DATE))
244 {244 {
245 return Operation::template245 return Operation::template
246 compute<store::XS_DURATION,store::XS_DATE>246 compute<store::XS_DURATION,store::XS_DATE>
247 (result, dctx, tm, &aLoc, n0, n1);247 (result, dctx, tm, &aLoc, n0, n1);
248 }248 }
249 else if (TypeOps::is_equal(tm, *type0, *type1))249 else if (type0 == type1)
250 {250 {
251 return Operation::template251 return Operation::template
252 computeSingleType<store::XS_DT_DURATION>252 computeSingleType<store::XS_DT_DURATION>
253 (result, dctx, tm, &aLoc, n0, n1);253 (result, dctx, tm, &aLoc, n0, n1);
254 }254 }
255 }255 }
256 else if(TypeOps::is_subtype(tm, *type0, *rtm.DATETIME_TYPE_ONE))256 else if (TypeOps::is_subtype(type0, store::XS_DATETIME))
257 {257 {
258 if(TypeOps::is_subtype(tm, *type1, *rtm.DATETIME_TYPE_ONE))258 if (TypeOps::is_subtype(type1, store::XS_DATETIME))
259 {259 {
260 return Operation::template260 return Operation::template
261 compute<store::XS_DATETIME,store::XS_DATETIME>261 compute<store::XS_DATETIME,store::XS_DATETIME>
262 (result, dctx, tm, &aLoc, n0, n1);262 (result, dctx, tm, &aLoc, n0, n1);
263 }263 }
264 else if (TypeOps::is_subtype(tm, *type1, *rtm.YM_DURATION_TYPE_ONE ))264 else if (TypeOps::is_subtype(type1, store::XS_YM_DURATION))
265 {265 {
266 return Operation::template266 return Operation::template
267 compute<store::XS_DATETIME,store::XS_DURATION>267 compute<store::XS_DATETIME,store::XS_DURATION>
268 (result, dctx, tm, &aLoc, n0, n1);268 (result, dctx, tm, &aLoc, n0, n1);
269 }269 }
270 else if (TypeOps::is_subtype(tm, *type1, *rtm.DT_DURATION_TYPE_ONE ))270 else if (TypeOps::is_subtype(type1, store::XS_DT_DURATION))
271 {271 {
272 return Operation::template272 return Operation::template
273 compute<store::XS_DATETIME,store::XS_DURATION>273 compute<store::XS_DATETIME,store::XS_DURATION>
274 (result, dctx, tm, &aLoc, n0, n1);274 (result, dctx, tm, &aLoc, n0, n1);
275 }275 }
276 }276 }
277 else if(TypeOps::is_subtype(tm, *type0, *rtm.DATE_TYPE_ONE))277 else if (TypeOps::is_subtype(type0, store::XS_DATE))
278 {278 {
279 if (TypeOps::is_subtype(tm, *type1, *rtm.DATE_TYPE_ONE))279 if (TypeOps::is_subtype(type1, store::XS_DATE))
280 {280 {
281 return Operation::template281 return Operation::template
282 compute<store::XS_DATE,store::XS_DATE>282 compute<store::XS_DATE,store::XS_DATE>
283 (result, dctx, tm, &aLoc, n0, n1);283 (result, dctx, tm, &aLoc, n0, n1);
284 }284 }
285 else if (TypeOps::is_subtype(tm, *type1, *rtm.YM_DURATION_TYPE_ONE))285 else if (TypeOps::is_subtype(type1, store::XS_YM_DURATION))
286 {286 {
287 return Operation::template287 return Operation::template
288 compute<store::XS_DATE,store::XS_DURATION>288 compute<store::XS_DATE,store::XS_DURATION>
289 (result, dctx, tm, &aLoc, n0, n1);289 (result, dctx, tm, &aLoc, n0, n1);
290 }290 }
291 else if (TypeOps::is_subtype(tm, *type1, *rtm.DT_DURATION_TYPE_ONE))291 else if (TypeOps::is_subtype(type1, store::XS_DT_DURATION))
292 {292 {
293 return Operation::template293 return Operation::template
294 compute<store::XS_DATE,store::XS_DURATION>294 compute<store::XS_DATE,store::XS_DURATION>
295 (result, dctx, tm, &aLoc, n0, n1);295 (result, dctx, tm, &aLoc, n0, n1);
296 }296 }
297 }297 }
298 else if(TypeOps::is_subtype(tm, *type0, *rtm.TIME_TYPE_ONE))298 else if (TypeOps::is_subtype(type0, store::XS_TIME))
299 {299 {
300 if(TypeOps::is_subtype(tm, *type1, *rtm.TIME_TYPE_ONE))300 if (TypeOps::is_subtype(type1, store::XS_TIME))
301 {301 {
302 return Operation::template302 return Operation::template
303 compute<store::XS_TIME,store::XS_TIME>303 compute<store::XS_TIME,store::XS_TIME>
304 (result, dctx, tm, &aLoc, n0, n1);304 (result, dctx, tm, &aLoc, n0, n1);
305 }305 }
306 else if (TypeOps::is_subtype(tm, *type1, *rtm.DT_DURATION_TYPE_ONE))306 else if (TypeOps::is_subtype(type1, store::XS_DT_DURATION))
307 {307 {
308 return Operation::template 308 return Operation::template
309 compute<store::XS_TIME,store::XS_DURATION>309 compute<store::XS_TIME,store::XS_DURATION>
310 (result, dctx, tm, &aLoc, n0, n1);310 (result, dctx, tm, &aLoc, n0, n1);
311 }311 }
312 }312 }
313 else if ((TypeOps::is_numeric(tm, *type0) ||313 else if ((TypeOps::is_numeric(type0) || type0 == store::XS_UNTYPED_ATOMIC) &&
314 TypeOps::is_subtype(tm, *type0, *rtm.UNTYPED_ATOMIC_TYPE_ONE)) &&314 (TypeOps::is_numeric(type1) || type1 == store::XS_UNTYPED_ATOMIC))
315 ( TypeOps::is_numeric(tm, *type1) ||
316 TypeOps::is_subtype(tm, *type1, *rtm.UNTYPED_ATOMIC_TYPE_ONE)))
317 {315 {
318 return NumArithIterator<Operation>::316 return NumArithIterator<Operation>::
319 computeAtomic(result, dctx, tm, aLoc, n0, type0, n1, type1);317 computeAtomic(result, dctx, tm, aLoc, n0, type0, n1, type1);
320 }318 }
321 319
322 320 {
323 RAISE_ERROR(err::XPTY0004, aLoc,321 xqtref_t type0 = tm->create_value_type(n0);
324 ERROR_PARAMS(ZED(ArithOpNotDefinedBetween_23), *type0, *type1));322 xqtref_t type1 = tm->create_value_type(n1);
323
324 RAISE_ERROR(err::XPTY0004, aLoc,
325 ERROR_PARAMS(ZED(ArithOpNotDefinedBetween_23), *type0, *type1));
326 }
325327
326 return false; // suppresses wanring328 return false; // suppresses wanring
327}329}
328330
=== modified file 'src/runtime/indexing/index_ddl.cpp'
--- src/runtime/indexing/index_ddl.cpp 2013-05-02 18:34:27 +0000
+++ src/runtime/indexing/index_ddl.cpp 2013-06-11 09:57:50 +0000
@@ -70,7 +70,8 @@
7070
7171
72/*******************************************************************************72/*******************************************************************************
7373 This function is called from the probe function to chaeck that the type of
74 the probing key is consistent with the index declaration.
74********************************************************************************/75********************************************************************************/
75static void checkKeyType(76static void checkKeyType(
76 const QueryLoc& loc,77 const QueryLoc& loc,
@@ -138,6 +139,7 @@
138 {139 {
139 GENV_STORE.getItemFactory()->140 GENV_STORE.getItemFactory()->
140 createDouble(searchKey, xs_float(searchKey->getDecimalValue()));141 createDouble(searchKey, xs_float(searchKey->getDecimalValue()));
142
141 return;143 return;
142 }144 }
143145
@@ -1217,7 +1219,6 @@
1217 PlanState& planState) const1219 PlanState& planState) const
1218{1220{
1219 TypeManager* tm = theSctx->get_typemanager();1221 TypeManager* tm = theSctx->get_typemanager();
1220 RootTypeManager& rtm = GENV_TYPESYSTEM;
1221 store::IndexCondition_t cond;1222 store::IndexCondition_t cond;
1222 csize numChildren = theChildren.size();1223 csize numChildren = theChildren.size();
1223 csize numNonKeyParams = (theSkip ? 2 : 1);1224 csize numNonKeyParams = (theSkip ? 2 : 1);
@@ -1262,37 +1263,37 @@
1262 if (state->theIndexDecl->isGeneral() &&1263 if (state->theIndexDecl->isGeneral() &&
1263 (state->theIndexDecl->getKeyTypes())[keyNo] == NULL)1264 (state->theIndexDecl->getKeyTypes())[keyNo] == NULL)
1264 {1265 {
1265 xqtref_t leftType;1266 store::SchemaTypeCode leftType;
1266 xqtref_t rightType;1267 store::SchemaTypeCode rightType;
12671268
1268 if (tempLeft != NULL)1269 if (tempLeft != NULL)
1269 {1270 {
1270 leftType = tm->create_value_type(tempLeft);1271 leftType = tempLeft->getTypeCode();
1271 1272
1272 if (TypeOps::is_equal(tm, *leftType, *rtm.UNTYPED_ATOMIC_TYPE_ONE))1273 if (leftType == store::XS_UNTYPED_ATOMIC)
1273 {1274 {
1274 zstring str = tempLeft->getStringValue();1275 zstring str = tempLeft->getStringValue();
1275 GENV_ITEMFACTORY->createString(tempLeft, str);1276 GENV_ITEMFACTORY->createString(tempLeft, str);
1276 leftType = rtm.STRING_TYPE_ONE;1277 leftType = store::XS_STRING;
1277 }1278 }
1278 }1279 }
1279 1280
1280 if (tempRight != NULL)1281 if (tempRight != NULL)
1281 {1282 {
1282 rightType = tm->create_value_type(tempRight);1283 rightType = tempRight->getTypeCode();
1283 1284
1284 if (TypeOps::is_equal(tm, *rightType, *rtm.UNTYPED_ATOMIC_TYPE_ONE))1285 if (rightType == store::XS_UNTYPED_ATOMIC)
1285 {1286 {
1286 zstring str = tempRight->getStringValue();1287 zstring str = tempRight->getStringValue();
1287 GENV_ITEMFACTORY->createString(tempRight, str);1288 GENV_ITEMFACTORY->createString(tempRight, str);
1288 rightType = rtm.STRING_TYPE_ONE;1289 rightType = store::XS_STRING;
1289 }1290 }
1290 }1291 }
1291 1292
1292 if (leftType != NULL && rightType != NULL)1293 if (tempLeft != NULL && tempRight != NULL)
1293 {1294 {
1294 if (!TypeOps::is_subtype(tm, *leftType, *rightType) &&1295 if (!TypeOps::is_subtype(leftType, rightType) &&
1295 !TypeOps::is_subtype(tm, *rightType, *leftType))1296 !TypeOps::is_subtype(rightType, leftType))
1296 {1297 {
1297 RAISE_ERROR(zerr::ZDDY0034_INDEX_RANGE_VALUE_PROBE_BAD_KEY_TYPES, loc,1298 RAISE_ERROR(zerr::ZDDY0034_INDEX_RANGE_VALUE_PROBE_BAD_KEY_TYPES, loc,
1298 ERROR_PARAMS(state->theIndexDecl->getName()->getStringValue()));1299 ERROR_PARAMS(state->theIndexDecl->getName()->getStringValue()));
12991300
=== modified file 'src/runtime/maths/maths_impl.cpp'
--- src/runtime/maths/maths_impl.cpp 2013-02-07 17:24:36 +0000
+++ src/runtime/maths/maths_impl.cpp 2013-06-11 09:57:50 +0000
@@ -30,6 +30,8 @@
30#include "store/api/item.h"30#include "store/api/item.h"
3131
32#include "diagnostics/xquery_diagnostics.h"32#include "diagnostics/xquery_diagnostics.h"
33#include "diagnostics/util_macros.h"
34
33#include "zorbatypes/numconversions.h"35#include "zorbatypes/numconversions.h"
3436
35namespace zorba {37namespace zorba {
@@ -345,44 +347,27 @@
345 {347 {
346 if (consumeNext(n1, this->theChild1.getp(), planState))348 if (consumeNext(n1, this->theChild1.getp(), planState))
347 {349 {
350 assert(n1->isAtomic());
351
348 {352 {
349 xqtref_t type;
350
351 const TypeManager* tm = theSctx->get_typemanager();353 const TypeManager* tm = theSctx->get_typemanager();
352
353 const RootTypeManager& rtm = GENV_TYPESYSTEM;354 const RootTypeManager& rtm = GENV_TYPESYSTEM;
355
354 xs_double doub1 = n0->getDoubleValue();356 xs_double doub1 = n0->getDoubleValue();
355 //xs_double doub2 = n1->getDoubleValue();357
356358 store::SchemaTypeCode type1 = n1->getTypeCode();
357 //GENV_ITEMFACTORY->createDouble(result, doub1.pow(doub2));359
358360 if (type1 == store::XS_UNTYPED_ATOMIC)
359 assert(n1->isAtomic());
360
361 type = tm->create_value_type(n1);
362
363 if (TypeOps::is_subtype(tm, *type, *rtm.UNTYPED_ATOMIC_TYPE_ONE))
364 {361 {
365 GenericCast::castToAtomic(result, result, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, loc);362 GenericCast::castToAtomic(result, result, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, loc);
366 type = tm->create_value_type(result);363
367 }364 GENV_ITEMFACTORY->createDouble(result, doub1.pow(n1->getDoubleValue()));
368365 }
369 if (TypeOps::is_subtype(tm, *type, *rtm.DOUBLE_TYPE_ONE))366 else if (type1 == store::XS_DOUBLE || type1 == store::XS_FLOAT)
370 {367 {
371 GENV_ITEMFACTORY->createDouble(result, doub1.pow(n1->getDoubleValue()));368 GENV_ITEMFACTORY->createDouble(result, doub1.pow(n1->getDoubleValue()));
372 }369 }
373 else if (TypeOps::is_subtype(tm, *type, *rtm.FLOAT_TYPE_ONE))370 else if (type1 == store::XS_INTEGER)
374 {
375 store::Item_t n1_double;
376 GenericCast::castToAtomic(n1_double,
377 n1,
378 rtm.DOUBLE_TYPE_ONE.getp(),
379 tm,
380 NULL,
381 loc);
382
383 GENV_ITEMFACTORY->createDouble(result, doub1.pow(n1_double->getDoubleValue()));
384 }
385 else if (TypeOps::is_subtype(tm, *type, *rtm.INTEGER_TYPE_ONE))
386 {371 {
387 xs_integer n1_integer = n1->getIntegerValue();372 xs_integer n1_integer = n1->getIntegerValue();
388 try373 try
@@ -390,16 +375,13 @@
390 xs_int const n1_int = to_xs_int(n1_integer);375 xs_int const n1_int = to_xs_int(n1_integer);
391 GENV_ITEMFACTORY->createDouble(result, doub1.pow(n1_int));376 GENV_ITEMFACTORY->createDouble(result, doub1.pow(n1_int));
392 }377 }
393 catch ( std::range_error const& )378 catch (std::range_error const&)
394 {379 {
395 throw XQUERY_EXCEPTION(380 RAISE_ERROR(err::XPTY0004, loc,
396 err::XPTY0004,381 ERROR_PARAMS(ZED(NoCastToCInt_2), n1_integer));
397 ERROR_PARAMS( ZED( NoCastToCInt_2 ), n1_integer ),
398 ERROR_LOC( loc )
399 );
400 }382 }
401 }383 }
402 else if (TypeOps::is_subtype(tm, *type, *rtm.DECIMAL_TYPE_ONE))384 else if (type1 == store::XS_DECIMAL)
403 {385 {
404 store::Item_t n1_double;386 store::Item_t n1_double;
405 GenericCast::castToAtomic(n1_double,387 GenericCast::castToAtomic(n1_double,
@@ -413,19 +395,13 @@
413 }395 }
414 else396 else
415 {397 {
416 throw XQUERY_EXCEPTION(398 xqtref_t type = tm->create_value_type(n1);
417 err::XPTY0004,399
418 ERROR_PARAMS( ZED( BadTypeFor_23 ), type, "math:pow" ),400 RAISE_ERROR(err::XPTY0004, loc,
419 ERROR_LOC( loc )401 ERROR_PARAMS(ZED(BadTypeFor_23), type, "math:pow"));
420 );
421 }402 }
422 }403 }
423404
424 if (consumeNext(n0, this->theChild0.getp(), planState) ||
425 consumeNext(n1, this->theChild1.getp(), planState))
426 throw XQUERY_EXCEPTION(
427 err::XPTY0004, ERROR_PARAMS( ZED( NoSeqForFnOp_2 ), "math:pow" )
428 );
429 STACK_PUSH(true, state);405 STACK_PUSH(true, state);
430 }406 }
431 }407 }
432408
=== modified file 'src/runtime/numerics/NumericsImpl.cpp'
--- src/runtime/numerics/NumericsImpl.cpp 2013-05-05 03:16:33 +0000
+++ src/runtime/numerics/NumericsImpl.cpp 2013-06-11 09:57:50 +0000
@@ -687,8 +687,8 @@
687 assert(n0->isAtomic());687 assert(n0->isAtomic());
688 assert(n1->isAtomic());688 assert(n1->isAtomic());
689689
690 xqtref_t type0 = tm->create_value_type(n0);690 store::SchemaTypeCode type0 = n0->getTypeCode();
691 xqtref_t type1 = tm->create_value_type(n1);691 store::SchemaTypeCode type1 = n1->getTypeCode();
692692
693 return computeAtomic(result, dctx, tm, aLoc, n0, type0, n1, type1);693 return computeAtomic(result, dctx, tm, aLoc, n0, type0, n1, type1);
694}694}
@@ -701,9 +701,9 @@
701 const TypeManager* tm,701 const TypeManager* tm,
702 const QueryLoc& aLoc,702 const QueryLoc& aLoc,
703 store::Item_t& item0,703 store::Item_t& item0,
704 xqtref_t type0,704 store::SchemaTypeCode type0,
705 store::Item_t& item1,705 store::Item_t& item1,
706 xqtref_t type1)706 store::SchemaTypeCode type1)
707{707{
708 bool res;708 bool res;
709 store::Item_t n0;709 store::Item_t n0;
@@ -711,14 +711,14 @@
711711
712 bool isDivision = Operation::getOperationKind() == ArithmeticConsts::DIVISION;712 bool isDivision = Operation::getOperationKind() == ArithmeticConsts::DIVISION;
713713
714 xqtref_t resultType = TypeOps::arithmetic_type(tm, *type0, *type1, isDivision);714 store::SchemaTypeCode resultType = TypeOps::arithmetic_type(type0, type1, isDivision);
715715
716 switch (TypeOps::get_atomic_type_code(*resultType))716 switch (resultType)
717 {717 {
718 case store::XS_DOUBLE:718 case store::XS_DOUBLE:
719 {719 {
720 GenericCast::castToAtomic(n0, item0, &*resultType, tm, NULL, aLoc);720 GenericCast::castToBuiltinAtomic(n0, item0, resultType, NULL, aLoc);
721 GenericCast::castToAtomic(n1, item1, &*resultType, tm, NULL, aLoc);721 GenericCast::castToBuiltinAtomic(n1, item1, resultType, NULL, aLoc);
722 722
723 res = Operation::template723 res = Operation::template
724 computeSingleType<store::XS_DOUBLE>724 computeSingleType<store::XS_DOUBLE>
@@ -727,8 +727,8 @@
727 }727 }
728 case store::XS_FLOAT:728 case store::XS_FLOAT:
729 {729 {
730 GenericCast::castToAtomic(n0, item0, &*resultType, tm, NULL, aLoc);730 GenericCast::castToBuiltinAtomic(n0, item0, resultType, NULL, aLoc);
731 GenericCast::castToAtomic(n1, item1, &*resultType, tm, NULL, aLoc);731 GenericCast::castToBuiltinAtomic(n1, item1, resultType, NULL, aLoc);
732732
733 res = Operation::template 733 res = Operation::template
734 computeSingleType<store::XS_FLOAT>734 computeSingleType<store::XS_FLOAT>
@@ -737,8 +737,8 @@
737 }737 }
738 case store::XS_DECIMAL:738 case store::XS_DECIMAL:
739 {739 {
740 GenericCast::castToAtomic(n0, item0, &*resultType, tm, NULL, aLoc);740 GenericCast::castToBuiltinAtomic(n0, item0, resultType, NULL, aLoc);
741 GenericCast::castToAtomic(n1, item1, &*resultType, tm, NULL, aLoc);741 GenericCast::castToBuiltinAtomic(n1, item1, resultType, NULL, aLoc);
742742
743 res = Operation::template743 res = Operation::template
744 computeSingleType<store::XS_DECIMAL>744 computeSingleType<store::XS_DECIMAL>
@@ -747,8 +747,8 @@
747 }747 }
748 case store::XS_INTEGER:748 case store::XS_INTEGER:
749 {749 {
750 GenericCast::castToAtomic(n0, item0, &*resultType, tm, NULL, aLoc);750 GenericCast::castToBuiltinAtomic(n0, item0, resultType, NULL, aLoc);
751 GenericCast::castToAtomic(n1, item1, &*resultType, tm, NULL, aLoc);751 GenericCast::castToBuiltinAtomic(n1, item1, resultType, NULL, aLoc);
752752
753 res = Operation::template 753 res = Operation::template
754 computeSingleType<store::XS_INTEGER>754 computeSingleType<store::XS_INTEGER>
@@ -757,11 +757,13 @@
757 }757 }
758 default:758 default:
759 {759 {
760 throw XQUERY_EXCEPTION(760 xqtref_t type0 = tm->create_value_type(item0);
761 err::XPTY0004,761 xqtref_t type1 = tm->create_value_type(item1);
762 ERROR_PARAMS( ZED( ArithOpNotDefinedBetween_23 ), *type0, *type1 ),762
763 ERROR_LOC( aLoc )763 RAISE_ERROR(err::XPTY0004, aLoc,
764 );764 ERROR_PARAMS(ZED(ArithOpNotDefinedBetween_23),
765 type0->toSchemaString(),
766 type1->toSchemaString()));
765 }767 }
766 }768 }
767769
@@ -896,9 +898,8 @@
896bool OpNumericUnaryIterator::nextImpl(store::Item_t& result, PlanState& planState) const898bool OpNumericUnaryIterator::nextImpl(store::Item_t& result, PlanState& planState) const
897{899{
898 store::Item_t item;900 store::Item_t item;
899 xqtref_t type;901 store::SchemaTypeCode type;
900902
901 const RootTypeManager& rtm = GENV_TYPESYSTEM;
902 const TypeManager* tm = theSctx->get_typemanager();903 const TypeManager* tm = theSctx->get_typemanager();
903904
904 PlanIteratorState* state;905 PlanIteratorState* state;
@@ -908,35 +909,35 @@
908 {909 {
909 assert(item->isAtomic());910 assert(item->isAtomic());
910911
911 type = tm->create_value_type(item);912 type = item->getTypeCode();
912913
913 if (TypeOps::is_subtype(tm, *type, *rtm.UNTYPED_ATOMIC_TYPE_ONE ) )914 if (type == store::XS_UNTYPED_ATOMIC)
914 {915 {
915 GenericCast::castToAtomic(item, item, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, loc);916 GenericCast::castToBuiltinAtomic(item, item, store::XS_DOUBLE, NULL, loc);
916 type = rtm.DOUBLE_TYPE_ONE;917 type = store::XS_DOUBLE;
917 }918 }
918 919
919 // TODO Optimizations (e.g. if item has already the correct type and value,920 // TODO Optimizations (e.g. if item has already the correct type and value,
920 // it does not have to be created newly)921 // it does not have to be created newly)
921 if (TypeOps::is_subtype(tm, *type, *rtm.DOUBLE_TYPE_ONE))922 if (TypeOps::is_subtype(type, store::XS_DOUBLE))
922 {923 {
923 GENV_ITEMFACTORY->924 GENV_ITEMFACTORY->
924 createDouble(result,925 createDouble(result,
925 (thePlus ? item->getDoubleValue() : -item->getDoubleValue()));926 (thePlus ? item->getDoubleValue() : -item->getDoubleValue()));
926 }927 }
927 else if ( TypeOps::is_subtype(tm, *type, *rtm.FLOAT_TYPE_ONE ) )928 else if (TypeOps::is_subtype(type, store::XS_FLOAT))
928 {929 {
929 GENV_ITEMFACTORY->930 GENV_ITEMFACTORY->
930 createFloat(result,931 createFloat(result,
931 (thePlus ? item->getFloatValue() : -item->getFloatValue()));932 (thePlus ? item->getFloatValue() : -item->getFloatValue()));
932 }933 }
933 else if ( TypeOps::is_subtype(tm, *type, *rtm.INTEGER_TYPE_ONE ) )934 else if (TypeOps::is_subtype(type, store::XS_INTEGER))
934 {935 {
935 GENV_ITEMFACTORY->936 GENV_ITEMFACTORY->
936 createInteger(result,937 createInteger(result,
937 (thePlus ? item->getIntegerValue() : -item->getIntegerValue()));938 (thePlus ? item->getIntegerValue() : -item->getIntegerValue()));
938 }939 }
939 else if ( TypeOps::is_subtype(tm, *type, *rtm.DECIMAL_TYPE_ONE ) )940 else if (TypeOps::is_subtype(type, store::XS_DECIMAL))
940 {941 {
941 GENV_ITEMFACTORY->942 GENV_ITEMFACTORY->
942 createDecimal(result,943 createDecimal(result,
@@ -944,8 +945,9 @@
944 }945 }
945 else946 else
946 {947 {
948 xqtref_t type = tm->create_value_type(item);
947 RAISE_ERROR(err::XPTY0004, loc,949 RAISE_ERROR(err::XPTY0004, loc,
948 ERROR_PARAMS(ZED(BadTypeFor_23), type, ZED(UnaryArithOp)));950 ERROR_PARAMS(ZED(BadTypeFor_23), type->toSchemaString(), ZED(UnaryArithOp)));
949 }951 }
950 952
951 STACK_PUSH(true, state);953 STACK_PUSH(true, state);
@@ -985,7 +987,7 @@
985 PlanIteratorState* state;987 PlanIteratorState* state;
986 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);988 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
987989
988 if (consumeNext(item, theChild.getp(), planState ))990 if (consumeNext(item, theChild.getp(), planState))
989 {991 {
990 assert(item->isAtomic());992 assert(item->isAtomic());
991993
992994
=== modified file 'src/runtime/numerics/NumericsImpl.h'
--- src/runtime/numerics/NumericsImpl.h 2013-02-07 17:24:36 +0000
+++ src/runtime/numerics/NumericsImpl.h 2013-06-11 09:57:50 +0000
@@ -61,9 +61,9 @@
61 const TypeManager* tm,61 const TypeManager* tm,
62 const QueryLoc&,62 const QueryLoc&,
63 store::Item_t& item0,63 store::Item_t& item0,
64 xqtref_t type0,64 store::SchemaTypeCode type0,
65 store::Item_t& item1,65 store::Item_t& item1,
66 xqtref_t type1);66 store::SchemaTypeCode type1);
6767
68public:68public:
69 NumArithIterator(static_context* sctx, const QueryLoc&, PlanIter_t&, PlanIter_t&);69 NumArithIterator(static_context* sctx, const QueryLoc&, PlanIter_t&, PlanIter_t&);
7070
=== modified file 'src/runtime/numerics/numerics_impl.cpp'
--- src/runtime/numerics/numerics_impl.cpp 2013-05-02 18:34:27 +0000
+++ src/runtime/numerics/numerics_impl.cpp 2013-06-11 09:57:50 +0000
@@ -52,12 +52,9 @@
52AbsIterator::nextImpl(store::Item_t& result, PlanState& planState) const52AbsIterator::nextImpl(store::Item_t& result, PlanState& planState) const
53{53{
54 store::Item_t item;54 store::Item_t item;
55 xqtref_t type;55 store::SchemaTypeCode type;
56
57 const TypeManager* tm = theSctx->get_typemanager();56 const TypeManager* tm = theSctx->get_typemanager();
5857
59 const RootTypeManager& rtm = GENV_TYPESYSTEM;
60
61 PlanIteratorState* state;58 PlanIteratorState* state;
62 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);59 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
6360
@@ -65,31 +62,31 @@
65 {62 {
66 assert(result->isAtomic());63 assert(result->isAtomic());
6764
68 type = tm->create_value_type(result);65 type = result->getTypeCode();
6966
70 if (TypeOps::is_subtype(tm, *type, *rtm.UNTYPED_ATOMIC_TYPE_ONE))67 if (type == store::XS_UNTYPED_ATOMIC)
71 {68 {
72 GenericCast::castToAtomic(result, result, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, loc);69 GenericCast::castToBuiltinAtomic(result, result, store::XS_DOUBLE, NULL, loc);
73 type = tm->create_value_type(result);70 type = store::XS_DOUBLE;
74 }71 }
7572
76 if (TypeOps::is_subtype(tm, *type, *rtm.DOUBLE_TYPE_ONE))73 if (TypeOps::is_subtype(type, store::XS_DOUBLE))
77 {74 {
78 if (result->getDoubleValue().isPos() || result->getDoubleValue().isPosZero())75 if (result->getDoubleValue().isPos() || result->getDoubleValue().isPosZero())
79 {76 {
80 if ( !TypeOps::is_equal(tm, *type, *rtm.DOUBLE_TYPE_ONE))77 if (type != store::XS_DOUBLE)
81 GENV_ITEMFACTORY->createDouble (result, result->getDoubleValue());78 GENV_ITEMFACTORY->createDouble(result, result->getDoubleValue());
82 }79 }
83 else80 else
84 {81 {
85 GENV_ITEMFACTORY->createDouble(result, -result->getDoubleValue());82 GENV_ITEMFACTORY->createDouble(result, -result->getDoubleValue());
86 }83 }
87 }84 }
88 else if (TypeOps::is_subtype(tm, *type, *rtm.FLOAT_TYPE_ONE))85 else if (TypeOps::is_subtype(type, store::XS_FLOAT))
89 {86 {
90 if ( result->getFloatValue().isPos() || result->getFloatValue().isPosZero())87 if ( result->getFloatValue().isPos() || result->getFloatValue().isPosZero())
91 {88 {
92 if ( !TypeOps::is_equal(tm, *type, *rtm.FLOAT_TYPE_ONE))89 if (type != store::XS_FLOAT)
93 GENV_ITEMFACTORY->createFloat (result, result->getFloatValue());90 GENV_ITEMFACTORY->createFloat (result, result->getFloatValue());
94 }91 }
95 else92 else
@@ -97,11 +94,11 @@
97 GENV_ITEMFACTORY->createFloat(result, -result->getFloatValue());94 GENV_ITEMFACTORY->createFloat(result, -result->getFloatValue());
98 }95 }
99 }96 }
100 else if (TypeOps::is_subtype(tm, *type, *rtm.INTEGER_TYPE_ONE))97 else if (TypeOps::is_subtype(type, store::XS_INTEGER))
101 {98 {
102 if (result->getIntegerValue().sign() >= 0)99 if (result->getIntegerValue().sign() >= 0)
103 {100 {
104 if ( !TypeOps::is_equal(tm, *type, *rtm.INTEGER_TYPE_ONE))101 if (type != store::XS_INTEGER)
105 GENV_ITEMFACTORY->createInteger(result, result->getIntegerValue());102 GENV_ITEMFACTORY->createInteger(result, result->getIntegerValue());
106 }103 }
107 else104 else
@@ -109,28 +106,23 @@
109 GENV_ITEMFACTORY->createInteger(result, -result->getIntegerValue());106 GENV_ITEMFACTORY->createInteger(result, -result->getIntegerValue());
110 }107 }
111 }108 }
112 else if (TypeOps::is_subtype(tm, *type, *rtm.DECIMAL_TYPE_ONE))109 else if (TypeOps::is_subtype(type, store::XS_DECIMAL))
113 {110 {
114 if ( result->getDecimalValue().sign() >= 0)111 if ( result->getDecimalValue().sign() >= 0)
115 {112 {
116 if ( !TypeOps::is_equal(tm, *type, *rtm.DECIMAL_TYPE_ONE))113 if (type != store::XS_DECIMAL)
117 GENV_ITEMFACTORY->createDecimal(result, result->getDecimalValue());114 GENV_ITEMFACTORY->createDecimal(result, result->getDecimalValue());
118 }115 }
119 else116 else
120 {117 {
121 GENV_ITEMFACTORY->createDecimal (result, -result->getDecimalValue());118 GENV_ITEMFACTORY->createDecimal(result, -result->getDecimalValue());
122 }119 }
123 }120 }
124 else121 else
125 {122 {
126 RAISE_ERROR(err::XPTY0004, loc,123 xqtref_t type = tm->create_value_type(result);
127 ERROR_PARAMS(ZED(BadTypeFor_23), type, "fn:abs" ));124 RAISE_ERROR(err::XPTY0004, loc,
128 }125 ERROR_PARAMS(ZED(BadTypeFor_23), type->toSchemaString(), "fn:abs" ));
129
130 if ( consumeNext(item, theChildren[0].getp(), planState ))
131 {
132 RAISE_ERROR(err::XPTY0004, loc,
133 ERROR_PARAMS(ZED(NoSeqForFnOp_2), "fn:abs"));
134 }126 }
135127
136 STACK_PUSH(true, state);128 STACK_PUSH(true, state);
@@ -138,15 +130,15 @@
138 STACK_END(state);130 STACK_END(state);
139}131}
140132
133
141//6.4.2 fn:ceiling134//6.4.2 fn:ceiling
142bool135bool
143CeilingIterator::nextImpl(store::Item_t& result, PlanState& planState) const136CeilingIterator::nextImpl(store::Item_t& result, PlanState& planState) const
144{137{
145 store::Item_t item;138 store::Item_t item;
146 xqtref_t type;139 store::SchemaTypeCode type;
147140
148 const TypeManager* tm = theSctx->get_typemanager();141 const TypeManager* tm = theSctx->get_typemanager();
149 const RootTypeManager& rtm = GENV_TYPESYSTEM;
150142
151 PlanIteratorState* state;143 PlanIteratorState* state;
152 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);144 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
@@ -156,116 +148,109 @@
156 //get the value and the type of the item148 //get the value and the type of the item
157 assert(result->isAtomic());149 assert(result->isAtomic());
158150
159 type = tm->create_value_type(result);151 type = result->getTypeCode();
160152
161 //Parameters of type xs:untypedAtomic are always promoted to xs:double153 //Parameters of type xs:untypedAtomic are always promoted to xs:double
162 if ( TypeOps::is_subtype(tm, *type, *rtm.UNTYPED_ATOMIC_TYPE_ONE))154 if (TypeOps::is_subtype(type, store::XS_UNTYPED_ATOMIC))
163 {155 {
164 GenericCast::castToAtomic(result, result, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, loc);156 GenericCast::castToBuiltinAtomic(result, result, store::XS_DOUBLE, NULL, loc);
165 type = tm->create_value_type(result);157 type = store::XS_DOUBLE;
166 }158 }
167159
168 //item type is subtype of DOUBLE160 if (TypeOps::is_subtype(type, store::XS_DOUBLE))
169 if ( TypeOps::is_subtype(tm, *type, *rtm.DOUBLE_TYPE_ONE))161 {
170 GENV_ITEMFACTORY->createDouble(result, result->getDoubleValue().ceil());162 GENV_ITEMFACTORY->createDouble(result, result->getDoubleValue().ceil());
171163 }
172 //item type is subtype of FLOAT164 else if (TypeOps::is_subtype(type, store::XS_FLOAT))
173 else if ( TypeOps::is_subtype(tm, *type, *rtm.FLOAT_TYPE_ONE))165 {
174 GENV_ITEMFACTORY->createFloat(result, result->getFloatValue().ceil());166 GENV_ITEMFACTORY->createFloat(result, result->getFloatValue().ceil());
175167 }
176 //item type is subtype of INTEGER168 else if (TypeOps::is_subtype(type, store::XS_INTEGER))
177 else if(TypeOps::is_subtype(tm, *type, *rtm.INTEGER_TYPE_ONE))169 {
178 { /* do nothing */ }170 /* do nothing */
179171 }
180 //item type is subtype of DECIMAL172 else if (TypeOps::is_subtype(type, store::XS_DECIMAL))
181 else if (TypeOps::is_subtype(tm, *type, *rtm.DECIMAL_TYPE_ONE))173 {
182 GENV_ITEMFACTORY->createDecimal(result, result->getDecimalValue().ceil());174 GENV_ITEMFACTORY->createDecimal(result, result->getDecimalValue().ceil());
183175 }
184 else176 else
185 {177 {
178 xqtref_t type = tm->create_value_type(result);
186 RAISE_ERROR(err::XPTY0004, loc,179 RAISE_ERROR(err::XPTY0004, loc,
187 ERROR_PARAMS(ZED(BadTypeFor_23), type, "fn:ceiling" ));180 ERROR_PARAMS(ZED(BadTypeFor_23), type, "fn:ceiling" ));
188 }181 }
189182
190 if ( consumeNext(item, theChildren[0].getp(), planState ))
191 {
192 RAISE_ERROR(err::XPTY0004, loc,
193 ERROR_PARAMS(ZED(NoSeqForFnOp_2), "fn:ceiling"));
194 }
195 STACK_PUSH(true, state);183 STACK_PUSH(true, state);
196 }184 }
185
197 STACK_END(state);186 STACK_END(state);
198}187}
199188
189
200//6.4.3 fn:floor190//6.4.3 fn:floor
201bool191bool
202FloorIterator::nextImpl(store::Item_t& result, PlanState& planState) const192FloorIterator::nextImpl(store::Item_t& result, PlanState& planState) const
203{193{
204 store::Item_t item;194 store::Item_t item;
205 xqtref_t type;195 store::SchemaTypeCode type;
206196
207 const TypeManager* tm = theSctx->get_typemanager();197 const TypeManager* tm = theSctx->get_typemanager();
208 const RootTypeManager& rtm = GENV_TYPESYSTEM;
209198
210 PlanIteratorState* state;199 PlanIteratorState* state;
211 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);200 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
212201
213 if (consumeNext(result, theChildren[0].getp(), planState))202 if (consumeNext(result, theChildren[0].getp(), planState))
214 {203 {
215 //get the value and the type of the item
216 assert(result->isAtomic());204 assert(result->isAtomic());
217205
218 type = tm->create_value_type(result);206 type = result->getTypeCode();
219207
220 //Parameters of type xs:untypedAtomic are always promoted to xs:double208 //Parameters of type xs:untypedAtomic are always promoted to xs:double
221 if (TypeOps::is_subtype(tm, *type, *rtm.UNTYPED_ATOMIC_TYPE_ONE))209 if (TypeOps::is_subtype(type, store::XS_UNTYPED_ATOMIC))
222 {210 {
223 GenericCast::castToAtomic(result, result, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, loc);211 GenericCast::castToBuiltinAtomic(result, result, store::XS_DOUBLE, NULL, loc);
224 type = tm->create_value_type(result);212 type = store::XS_DOUBLE;
225 }213 }
226214
227 //item type is subtype of DOUBLE215 if (TypeOps::is_subtype(type, store::XS_DOUBLE))
228 if (TypeOps::is_subtype(tm, *type, *rtm.DOUBLE_TYPE_ONE))216 {
229 GENV_ITEMFACTORY->createDouble(result, result->getDoubleValue().floor());217 GENV_ITEMFACTORY->createDouble(result, result->getDoubleValue().floor());
230218 }
231 //item type is subtype of FLOAT219 else if (TypeOps::is_subtype(type, store::XS_FLOAT))
232 else if (TypeOps::is_subtype(tm, *type, *rtm.FLOAT_TYPE_ONE))220 {
233 GENV_ITEMFACTORY->createFloat(result, result->getFloatValue().floor());221 GENV_ITEMFACTORY->createFloat(result, result->getFloatValue().floor());
234222 }
235 //item type is subtype of INTEGER223 else if(TypeOps::is_subtype(type, store::XS_INTEGER))
236 else if(TypeOps::is_subtype(tm, *type, *rtm.INTEGER_TYPE_ONE))224 {
237 { /* do nothing */ }225 /* do nothing */
238226 }
239 //item type is subtype of DECIMAL227 else if (TypeOps::is_subtype(type, store::XS_DECIMAL))
240 else if (TypeOps::is_subtype(tm, *type, *rtm.DECIMAL_TYPE_ONE))228 {
241 GENV_ITEMFACTORY->createDecimal(result, result->getDecimalValue().floor());229 GENV_ITEMFACTORY->createDecimal(result, result->getDecimalValue().floor());
242230 }
243 else231 else
244 {232 {
233 xqtref_t type = tm->create_value_type(result);
245 RAISE_ERROR(err::XPTY0004, loc,234 RAISE_ERROR(err::XPTY0004, loc,
246 ERROR_PARAMS(ZED(BadTypeFor_23), type, "fn:floor"));235 ERROR_PARAMS(ZED(BadTypeFor_23), type, "fn:floor"));
247 }236 }
248237
249 if ( consumeNext(item, theChildren[0].getp(), planState ) )238 STACK_PUSH(true, state);
250 {
251 RAISE_ERROR(err::XPTY0004, loc,
252 ERROR_PARAMS(ZED(NoSeqForFnOp_2), "fn:floor" ));
253 }
254 STACK_PUSH (true, state );
255 }239 }
256 STACK_END (state);240
241 STACK_END(state);
257}242}
258243
244
259bool245bool
260RoundIterator::nextImpl(store::Item_t& result, PlanState& planState) const246RoundIterator::nextImpl(store::Item_t& result, PlanState& planState) const
261{247{
262 store::Item_t item;248 store::Item_t item;
263 xqtref_t type;249 store::SchemaTypeCode type;
264 store::Item_t precision;250 store::Item_t precision;
265 Integer precision_integer(0);251 Integer precision_integer(0);
266252
267 const TypeManager* tm = theSctx->get_typemanager();253 const TypeManager* tm = theSctx->get_typemanager();
268 const RootTypeManager& rtm = GENV_TYPESYSTEM;
269254
270 PlanIteratorState* state;255 PlanIteratorState* state;
271 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);256 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
@@ -280,125 +265,120 @@
280 precision_integer = precision->getIntegerValue();265 precision_integer = precision->getIntegerValue();
281 }266 }
282267
283 //get the value and the type of the item
284 assert(result->isAtomic());268 assert(result->isAtomic());
285269
286 type = tm->create_value_type(result);270 type = result->getTypeCode();
287271
288 //Parameters of type xs:untypedAtomic are always promoted to xs:double272 if (TypeOps::is_subtype(type, store::XS_UNTYPED_ATOMIC))
289 if ( TypeOps::is_subtype(tm, *type, *rtm.UNTYPED_ATOMIC_TYPE_ONE))273 {
290 {274 GenericCast::castToBuiltinAtomic(result, result, store::XS_DOUBLE, NULL, loc);
291 GenericCast::castToAtomic(result, result, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, loc);275 type = store::XS_DOUBLE;
292 type = tm->create_value_type(result);276 }
293 }277
294278 if (TypeOps::is_subtype(type, store::XS_DOUBLE))
295 //item type is subtype of DOUBLE279 {
296 if ( TypeOps::is_subtype(tm, *type, *rtm.DOUBLE_TYPE_ONE))280 GENV_ITEMFACTORY->
297 GENV_ITEMFACTORY->createDouble(result, result->getDoubleValue().round(precision_integer));281 createDouble(result, result->getDoubleValue().round(precision_integer));
298282 }
299 //item type is subtype of FLOAT283 else if (TypeOps::is_subtype(type, store::XS_FLOAT))
300 else if ( TypeOps::is_subtype(tm, *type, *rtm.FLOAT_TYPE_ONE))284 {
301 GENV_ITEMFACTORY->createFloat(result, result->getFloatValue().round(precision_integer));285 GENV_ITEMFACTORY->
302286 createFloat(result, result->getFloatValue().round(precision_integer));
303 //item type is subtype of INTEGER287 }
304 else if(TypeOps::is_subtype(tm, *type, *rtm.INTEGER_TYPE_ONE))288 else if (TypeOps::is_subtype(type, store::XS_INTEGER))
305 {289 {
306 if(precision_integer.sign() < 0)290 if (precision_integer.sign() < 0)
307 GENV_ITEMFACTORY->createInteger(result, result->getIntegerValue().round(precision_integer));291 GENV_ITEMFACTORY->
308 }292 createInteger(result, result->getIntegerValue().round(precision_integer));
309293 }
310 //item type is subtype of DECIMAL294
311 else if (TypeOps::is_subtype(tm, *type, *rtm.DECIMAL_TYPE_ONE))295 else if (TypeOps::is_subtype(type, store::XS_DECIMAL))
312 GENV_ITEMFACTORY->createDecimal(result, result->getDecimalValue().round(precision_integer));296 {
313297 GENV_ITEMFACTORY->
298 createDecimal(result, result->getDecimalValue().round(precision_integer));
299 }
314 else300 else
315 {301 {
302 xqtref_t type = tm->create_value_type(result);
316 RAISE_ERROR(err::XPTY0004, loc,303 RAISE_ERROR(err::XPTY0004, loc,
317 ERROR_PARAMS(ZED(BadTypeFor_23), type, "fn:round"));304 ERROR_PARAMS(ZED(BadTypeFor_23), type, "fn:round"));
318 }305 }
319306
320 if ( consumeNext(item, theChildren[0].getp(), planState ))307 STACK_PUSH(true, state);
321 {
322 RAISE_ERROR(err::XPTY0004, loc,
323 ERROR_PARAMS(ZED(NoSeqForFnOp_2), "fn:round" ));
324 }
325 STACK_PUSH (true, state );
326 }308 }
327 STACK_END (state);309
310 STACK_END(state);
328}311}
329312
313
330//6.4.5 fn:round-half-to-even314//6.4.5 fn:round-half-to-even
331bool RoundHalfToEvenIterator::nextImpl( store::Item_t &result,315bool RoundHalfToEvenIterator::nextImpl(
332 PlanState& planState ) const {316 store::Item_t& result,
317 PlanState& planState ) const
318{
333 store::Item_t item;319 store::Item_t item;
334 xs_integer precision;320 xs_integer precision;
335 RootTypeManager const &rtm = GENV_TYPESYSTEM;
336 TypeManager const *const tm = theSctx->get_typemanager();321 TypeManager const *const tm = theSctx->get_typemanager();
337 xqtref_t type;322 store::SchemaTypeCode type;
338323
339 PlanIteratorState *state;324 PlanIteratorState* state;
340 DEFAULT_STACK_INIT( PlanIteratorState, state, planState );325 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
341326
342 if ( consumeNext( result, theChildren [0].getp(), planState ) ) {327 if (consumeNext(result, theChildren [0].getp(), planState))
343 assert( result->isAtomic() );328 {
344 type = tm->create_value_type( result );329 assert(result->isAtomic());
345330 type = result->getTypeCode();
346 if ( theChildren.size() == 2 ) {331
347 consumeNext( item, theChildren[1].getp(), planState );332 if (theChildren.size() == 2)
348 assert( item->isAtomic() );333 {
334 consumeNext(item, theChildren[1].getp(), planState);
335 assert(item->isAtomic());
349 precision = item->getIntegerValue();336 precision = item->getIntegerValue();
350 }337 }
351338
352 if ( TypeOps::is_subtype( tm, *type, *rtm.UNTYPED_ATOMIC_TYPE_ONE ) ) {339 if (TypeOps::is_subtype(type, store::XS_UNTYPED_ATOMIC))
340 {
353 //341 //
354 // XQuery 3.0 3.1.5.2: Each item in the atomic sequence that is of type342 // XQuery 3.0 3.1.5.2: Each item in the atomic sequence that is of type
355 // xs:untypedAtomic is cast to the expected generalized atomic type. For343 // xs:untypedAtomic is cast to the expected generalized atomic type. For
356 // built-in functions where the expected type is specified as numeric,344 // built-in functions where the expected type is specified as numeric,
357 // arguments of type xs:untypedAtomic are cast to xs:double.345 // arguments of type xs:untypedAtomic are cast to xs:double.
358 //346 //
359 GenericCast::castToAtomic(347 GenericCast::castToBuiltinAtomic(result, result, store::XS_DOUBLE, NULL, loc);
360 result, result, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, loc348 type = store::XS_DOUBLE;
361 );349 }
362 type = tm->create_value_type( result );350
363 }351 if (TypeOps::is_subtype(type, store::XS_DOUBLE))
364352 {
365 if ( TypeOps::is_subtype( tm, *type, *rtm.DOUBLE_TYPE_ONE ) )353 GENV_ITEMFACTORY->
366 GENV_ITEMFACTORY->createDouble(354 createDouble(result, result->getDoubleValue().roundHalfToEven(precision));
367 result, result->getDoubleValue().roundHalfToEven( precision )355 }
368 );356 else if (TypeOps::is_subtype(type, store::XS_FLOAT))
369357 {
370 else if ( TypeOps::is_subtype( tm, *type, *rtm.FLOAT_TYPE_ONE ) )358 GENV_ITEMFACTORY->
371 GENV_ITEMFACTORY->createFloat(359 createFloat(result, result->getFloatValue().roundHalfToEven(precision));
372 result, result->getFloatValue().roundHalfToEven( precision )360 }
373 );361 else if (TypeOps::is_subtype(type, store::XS_INTEGER))
374362 {
375 else if ( TypeOps::is_subtype( tm, *type, *rtm.INTEGER_TYPE_ONE ) )363 GENV_ITEMFACTORY->
376 GENV_ITEMFACTORY->createInteger(364 createInteger(result, result->getIntegerValue().roundHalfToEven(precision));
377 result, result->getIntegerValue().roundHalfToEven( precision )365 }
378 );366 else if (TypeOps::is_subtype(type, store::XS_DECIMAL))
379367 {
380 else if ( TypeOps::is_subtype( tm, *type, *rtm.DECIMAL_TYPE_ONE ) )368 GENV_ITEMFACTORY->
381 GENV_ITEMFACTORY->createDecimal(369 createDecimal(result, result->getDecimalValue().roundHalfToEven(precision));
382 result, result->getDecimalValue().roundHalfToEven( precision )370 }
383 );
384
385 else371 else
386 throw XQUERY_EXCEPTION(372 {
387 err::XPTY0004,373 xqtref_t type = tm->create_value_type(result);
388 ERROR_PARAMS( ZED( BadTypeFor_23 ), type, "fn:round-half-to-even" ),374 RAISE_ERROR(err::XPTY0004, loc,
389 ERROR_LOC( loc )375 ERROR_PARAMS(ZED(BadTypeFor_23), type, "fn:round-half-to-even"));
390 );376 }
391377
392 if ( consumeNext( item, theChildren [0].getp(), planState ) ) {378 STACK_PUSH(true, state);
393 throw XQUERY_EXCEPTION(
394 err::XPTY0004,
395 ERROR_PARAMS( ZED( NoSeqForFnOp_2 ), "fn:round-half-to-even" ),
396 ERROR_LOC( loc )
397 );
398 }
399 STACK_PUSH( true, state );
400 }379 }
401 STACK_END( state );380
381 STACK_END(state);
402}382}
403383
404} // namespace zorba384} // namespace zorba
405385
=== modified file 'src/runtime/sequences/SequencesImpl.cpp'
--- src/runtime/sequences/SequencesImpl.cpp 2013-05-15 23:22:01 +0000
+++ src/runtime/sequences/SequencesImpl.cpp 2013-06-11 09:57:50 +0000
@@ -62,35 +62,6 @@
6262
63NARY_ACCEPT(FnMinMaxIterator);63NARY_ACCEPT(FnMinMaxIterator);
6464
65namespace sequences_impl_ns{
66static XQPCollator* getCollator(
67 static_context* sctx,
68 const QueryLoc& loc,
69 PlanState& planState,
70 const PlanIterator* iter)
71{
72 store::Item_t lCollationItem;
73 store::Item_t temp;
74
75 if (!PlanIterator::consumeNext(lCollationItem, iter, planState))
76 throw XQUERY_EXCEPTION(
77 err::XPTY0004,
78 ERROR_PARAMS( ZED( NoEmptySeqAsCollationParam ) ),
79 ERROR_LOC( loc )
80 );
81
82 if (PlanIterator::consumeNext(temp, iter, planState))
83 throw XQUERY_EXCEPTION(
84 err::XPTY0004,
85 ERROR_PARAMS( ZED( NoSeqAsCollationParam ) ),
86 ERROR_LOC( loc )
87 );
88
89 xqtref_t lCollationItemType = sctx->get_typemanager()->create_value_type(lCollationItem);
90
91 return sctx->get_collator(lCollationItem->getStringValue().str(), loc);
92}
93}
9465
95/////////////////////////////////////////////////////////////////////////////////66/////////////////////////////////////////////////////////////////////////////////
96// //67// //
@@ -121,104 +92,108 @@
121bool92bool
122FnMinMaxIterator::nextImpl(store::Item_t& result, PlanState& planState) const93FnMinMaxIterator::nextImpl(store::Item_t& result, PlanState& planState) const
123{94{
124 store::Item_t lRunningItem = NULL;95 store::Item_t runningItem = NULL;
125 xqtref_t lMaxType;96 store::SchemaTypeCode maxType = store::XS_LAST;
12697
127 const TypeManager* tm = theSctx->get_typemanager();98 const TypeManager* tm = theSctx->get_typemanager();
128 const RootTypeManager& rtm = GENV_TYPESYSTEM;
129
130 long timezone = planState.theLocalDynCtx->get_implicit_timezone();99 long timezone = planState.theLocalDynCtx->get_implicit_timezone();
131 XQPCollator* lCollator = 0;100 XQPCollator* collator = 0;
132 unsigned elems_in_seq = 0;101 unsigned elems_in_seq = 0;
133 result = NULL;102 result = NULL;
134103
135 try104 try
136 {105 {
137 PlanIteratorState* state;106 PlanIteratorState* state;
138 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);107 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
139108
140 if (theChildren.size() == 2)109 if (theChildren.size() == 2)
141 lCollator = sequences_impl_ns::getCollator(theSctx, loc, planState, theChildren[1].getp());110 {
142 else111 store::Item_t collationItem;
143 lCollator = theSctx->get_default_collator(loc);112 consumeNext(collationItem, theChildren[1], planState);
144113 collator = theSctx->get_collator(collationItem->getStringValue().str(), loc);
145 if (consumeNext(lRunningItem, theChildren[0].getp(), planState))114 }
146 {115 else
147 do116 {
148 {117 collator = theSctx->get_default_collator(loc);
149 // casting of untyped atomic118 }
150 xqtref_t lRunningType = tm->create_value_type(lRunningItem);119
151120 if (consumeNext(runningItem, theChildren[0], planState))
152 if (TypeOps::is_subtype(tm, *lRunningType, *rtm.UNTYPED_ATOMIC_TYPE_ONE))121 {
153 {122 do
154 GenericCast::castToAtomic(lRunningItem,123 {
155 lRunningItem,124 // casting of untyped atomic
156 &*rtm.DOUBLE_TYPE_ONE,125 store::SchemaTypeCode runningType = runningItem->getTypeCode();
157 tm,126
158 NULL,127 if (runningType == store::XS_UNTYPED_ATOMIC)
159 loc);128 {
160 lRunningType = rtm.DOUBLE_TYPE_ONE;129 GenericCast::castToBuiltinAtomic(runningItem,
161 }130 runningItem,
162131 store::XS_DOUBLE,
163 // implementation dependent: return the first occurence)132 NULL,
164 if (lRunningItem->isNaN())133 loc);
165 {134 runningType = store::XS_DOUBLE;
166 /** It must be checked if the sequence contains any135 }
167 * xs:double("NaN") [xs:double("NaN") is returned] or136
168 * only xs:float("NaN")'s [xs:float("NaN") is returned]'.137 // implementation dependent: return the first occurence)
169 */138 if (runningItem->isNaN())
170 result = lRunningItem;139 {
171 if (TypeOps::is_subtype(tm, *lRunningType, *rtm.DOUBLE_TYPE_ONE))140 // It must be checked if the sequence contains any
172 break;141 // xs:double("NaN") [xs:double("NaN") is returned] or
173142 // only xs:float("NaN")'s [xs:float("NaN") is returned]'.
174 lMaxType = tm->create_value_type(result);143
175 }144 result = runningItem;
176145 if (TypeOps::is_subtype(runningType, store::XS_DOUBLE))
177 if (result != 0)146 break;
178 {147
179 // Type Promotion148 maxType = runningType;
180 store::Item_t lItemCur;149 }
181 if (!GenericCast::promote(lItemCur, lRunningItem, &*lMaxType, NULL, tm, loc))150
182 {151 if (result != 0)
183 if (GenericCast::promote(lItemCur, result, &*lRunningType, NULL, tm, loc))152 {
153 // Type Promotion
154 store::Item_t lItemCur;
155 if (!GenericCast::promote(lItemCur, runningItem, maxType, NULL, tm, loc))
184 {156 {
185 result.transfer(lItemCur);157 if (GenericCast::promote(lItemCur, result, runningType, NULL, tm, loc))
186 lMaxType = tm->create_value_type(result);158 {
159 result.transfer(lItemCur);
160 maxType = result->getTypeCode();
161 }
162 else
163 {
164 RAISE_ERROR(err::FORG0006, loc,
165 ERROR_PARAMS(ZED(PromotionImpossible)));
166 }
187 }167 }
188 else168 else
189 {169 {
190 RAISE_ERROR(err::FORG0006, loc,170 runningItem.transfer(lItemCur);
191 ERROR_PARAMS(ZED(PromotionImpossible)));171 runningType = runningItem->getTypeCode();
172 }
173
174 store::Item_t current_copy(runningItem);
175 store::Item_t max_copy(result);
176 if (CompareIterator::valueComparison(loc,
177 current_copy,
178 max_copy,
179 theCompareType,
180 tm,
181 timezone,
182 collator))
183 {
184 maxType = runningType;
185 result.transfer(runningItem);
192 }186 }
193 }187 }
194 else188 else
195 {189 {
196 lRunningItem.transfer(lItemCur);190 maxType = runningType;
197 lRunningType = tm->create_value_type(lRunningItem);191 result.transfer(runningItem);
198 }192 }
199193
200 store::Item_t current_copy(lRunningItem);194 elems_in_seq++;
201 store::Item_t max_copy(result);195 }
202 if (CompareIterator::valueComparison(loc,196 while (consumeNext(runningItem, theChildren[0], planState));
203 current_copy,
204 max_copy,
205 theCompareType,
206 tm,
207 timezone,
208 lCollator) )
209 {
210 lMaxType = lRunningType;
211 result.transfer(lRunningItem);
212 }
213 }
214 else
215 {
216 lMaxType = lRunningType;
217 result.transfer(lRunningItem);
218 }
219
220 elems_in_seq++;
221 } while (consumeNext(lRunningItem, theChildren[0].getp(), planState));
222197
223 if (elems_in_seq == 1)198 if (elems_in_seq == 1)
224 {199 {
@@ -231,7 +206,7 @@
231 theCompareType,206 theCompareType,
232 tm,207 tm,
233 timezone,208 timezone,
234 lCollator);209 collator);
235 }210 }
236211
237 STACK_PUSH(result != NULL, state);212 STACK_PUSH(result != NULL, state);
238213
=== modified file 'src/runtime/sequences/sequences_impl.cpp'
--- src/runtime/sequences/sequences_impl.cpp 2013-06-05 00:37:35 +0000
+++ src/runtime/sequences/sequences_impl.cpp 2013-06-11 09:57:50 +0000
@@ -1438,7 +1438,7 @@
1438{1438{
1439 store::Item_t lSumItem;1439 store::Item_t lSumItem;
1440 store::Item_t lRunningItem;1440 store::Item_t lRunningItem;
1441 xqtref_t lRunningType;1441 store::SchemaTypeCode lRunningType;
1442 store::Item_t countItem;1442 store::Item_t countItem;
1443 int lCount = 0;1443 int lCount = 0;
1444 bool lHitNumeric = false, lHitYearMonth = false, lHitDayTime = false;1444 bool lHitNumeric = false, lHitYearMonth = false, lHitDayTime = false;
@@ -1446,86 +1446,101 @@
1446 const TypeManager* tm = theSctx->get_typemanager();1446 const TypeManager* tm = theSctx->get_typemanager();
1447 const RootTypeManager& rtm = GENV_TYPESYSTEM;1447 const RootTypeManager& rtm = GENV_TYPESYSTEM;
14481448
1449 xqtref_t lUntypedAtomic = rtm.UNTYPED_ATOMIC_TYPE_ONE;
1450 xqtref_t lYearMonthDuration = rtm.YM_DURATION_TYPE_ONE;
1451 xqtref_t lDayTimeDuration = rtm.DT_DURATION_TYPE_ONE;
1452
1453 PlanIteratorState* state;1449 PlanIteratorState* state;
1454 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);1450 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
14551451
1456 while (consumeNext(lRunningItem, theChildren[0].getp(), planState))1452 while (consumeNext(lRunningItem, theChildren[0].getp(), planState))
1457 {1453 {
1458 lRunningType = tm->create_value_type(lRunningItem);1454 lRunningType = lRunningItem->getTypeCode();
14591455
1460 if (TypeOps::is_numeric(tm, *lRunningType) ||1456 if (TypeOps::is_numeric(lRunningType) ||
1461 TypeOps::is_equal(tm, *lRunningType, *lUntypedAtomic))1457 lRunningType == store::XS_UNTYPED_ATOMIC)
1462 {1458 {
1463 lHitNumeric = true;1459 lHitNumeric = true;
14641460
1465 if ( lHitYearMonth )1461 if (lHitYearMonth)
1462 {
1463 xqtref_t type = tm->create_value_type(lRunningItem);
1466 RAISE_ERROR(err::FORG0006, loc,1464 RAISE_ERROR(err::FORG0006, loc,
1467 ERROR_PARAMS(ZED(BadArgTypeForFn_2o34o),1465 ERROR_PARAMS(ZED(BadArgTypeForFn_2o34o),
1468 *lRunningType,1466 *type,
1469 "fn:avg",1467 "fn:avg",
1470 ZED(ExpectedType_5),1468 ZED(ExpectedType_5),
1471 *lYearMonthDuration));1469 *rtm.YM_DURATION_TYPE_ONE));
1470 }
14721471
1473 if ( lHitDayTime )1472 if (lHitDayTime)
1473 {
1474 xqtref_t type = tm->create_value_type(lRunningItem);
1474 RAISE_ERROR(err::FORG0006, loc,1475 RAISE_ERROR(err::FORG0006, loc,
1475 ERROR_PARAMS(ZED( BadArgTypeForFn_2o34o ),1476 ERROR_PARAMS(ZED( BadArgTypeForFn_2o34o ),
1476 *lRunningType,1477 *type,
1477 "fn:avg",1478 "fn:avg",
1478 ZED( ExpectedType_5 ),1479 ZED( ExpectedType_5 ),
1479 *lDayTimeDuration));1480 *rtm.DT_DURATION_TYPE_ONE));
1481 }
1480 }1482 }
1481 else if (TypeOps::is_equal(tm, *lRunningType, *lYearMonthDuration))1483 else if (lRunningType == store::XS_YM_DURATION)
1482 {1484 {
1483 lHitYearMonth = true;1485 lHitYearMonth = true;
14841486
1485 if (lHitNumeric)1487 if (lHitNumeric)
1488 {
1489 xqtref_t type = tm->create_value_type(lRunningItem);
1486 RAISE_ERROR(err::FORG0006, loc,1490 RAISE_ERROR(err::FORG0006, loc,
1487 ERROR_PARAMS(ZED(BadArgTypeForFn_2o34o),1491 ERROR_PARAMS(ZED(BadArgTypeForFn_2o34o),
1488 *lRunningType,1492 *type,
1489 "fn:avg",1493 "fn:avg",
1490 ZED(ExpectedNumericType)));1494 ZED(ExpectedNumericType)));
1495 }
14911496
1492 if (lHitDayTime)1497 if (lHitDayTime)
1498 {
1499 xqtref_t type = tm->create_value_type(lRunningItem);
1493 RAISE_ERROR(err::FORG0006, loc,1500 RAISE_ERROR(err::FORG0006, loc,
1494 ERROR_PARAMS(ZED( BadArgTypeForFn_2o34o ),1501 ERROR_PARAMS(ZED( BadArgTypeForFn_2o34o ),
1495 *lRunningType,1502 *type,
1496 "fn:avg",1503 "fn:avg",
1497 ZED( ExpectedType_5 ),1504 ZED( ExpectedType_5 ),
1498 *lDayTimeDuration));1505 *rtm.DT_DURATION_TYPE_ONE));
1506 }
1499 }1507 }
1500 else if (TypeOps::is_equal(tm, *lRunningType, *lDayTimeDuration))1508 else if (lRunningType == store::XS_DT_DURATION)
1501 {1509 {
1502 lHitDayTime = true;1510 lHitDayTime = true;
15031511
1504 if ( lHitNumeric )1512 if (lHitNumeric)
1513 {
1514 xqtref_t type = tm->create_value_type(lRunningItem);
1505 RAISE_ERROR(err::FORG0006, loc,1515 RAISE_ERROR(err::FORG0006, loc,
1506 ERROR_PARAMS(ZED(BadArgTypeForFn_2o34o),1516 ERROR_PARAMS(ZED(BadArgTypeForFn_2o34o),
1507 *lRunningType,1517 *type,
1508 "fn:avg",1518 "fn:avg",
1509 ZED(ExpectedNumericType)));1519 ZED(ExpectedNumericType)));
1520 }
15101521
1511 if ( lHitYearMonth )1522 if (lHitYearMonth)
1523 {
1524 xqtref_t type = tm->create_value_type(lRunningItem);
1512 RAISE_ERROR(err::FORG0006, loc,1525 RAISE_ERROR(err::FORG0006, loc,
1513 ERROR_PARAMS(ZED(BadArgTypeForFn_2o34o),1526 ERROR_PARAMS(ZED(BadArgTypeForFn_2o34o),
1514 *lRunningType,1527 *type,
1515 "fn:avg",1528 "fn:avg",
1516 ZED(ExpectedType_5),1529 ZED(ExpectedType_5),
1517 *lYearMonthDuration));1530 *rtm.YM_DURATION_TYPE_ONE));
1531 }
1518 }1532 }
1519 else1533 else
1520 {1534 {
1535 xqtref_t type = tm->create_value_type(lRunningItem);
1521 RAISE_ERROR(err::FORG0006, loc,1536 RAISE_ERROR(err::FORG0006, loc,
1522 ERROR_PARAMS(ZED(BadArgTypeForFn_2o34o),1537 ERROR_PARAMS(ZED(BadArgTypeForFn_2o34o),
1523 *lRunningType,1538 *type,
1524 "fn:avg",1539 "fn:avg",
1525 ZED(ExpectedNumericOrDurationType)));1540 ZED(ExpectedNumericOrDurationType)));
1526 }1541 }
15271542
1528 if ( lCount++ == 0 )1543 if (lCount++ == 0)
1529 {1544 {
1530 lSumItem = lRunningItem;1545 lSumItem = lRunningItem;
1531 }1546 }
@@ -1559,17 +1574,17 @@
1559 STACK_END (state);1574 STACK_END (state);
1560}1575}
15611576
1577
1562/*******************************************************************************1578/*******************************************************************************
1563 15.4.5 fn:sum - Generic1579 15.4.5 fn:sum - Generic
1564********************************************************************************/1580********************************************************************************/
1565bool FnSumIterator::nextImpl(store::Item_t& result, PlanState& planState) const1581bool FnSumIterator::nextImpl(store::Item_t& result, PlanState& planState) const
1566{1582{
1567 store::Item_t lRunningItem;1583 store::Item_t lRunningItem;
1568 xqtref_t lResultType;1584 store::SchemaTypeCode lResultType;
1569 xqtref_t lRunningType;1585 store::SchemaTypeCode lRunningType;
15701586
1571 const TypeManager* tm = theSctx->get_typemanager();1587 const TypeManager* tm = theSctx->get_typemanager();
1572 const RootTypeManager& rtm = GENV_TYPESYSTEM;
15731588
1574 PlanIteratorState* state;1589 PlanIteratorState* state;
1575 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);1590 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
@@ -1577,37 +1592,37 @@
1577 if (consumeNext(result, theChildren[0].getp(), planState))1592 if (consumeNext(result, theChildren[0].getp(), planState))
1578 {1593 {
1579 // casting of untyped atomic1594 // casting of untyped atomic
1580 lResultType = tm->create_value_type(result);1595 lResultType = result->getTypeCode();
15811596
1582 if (TypeOps::is_subtype(tm, *lResultType, *rtm.UNTYPED_ATOMIC_TYPE_ONE))1597 if (lResultType == store::XS_UNTYPED_ATOMIC)
1583 {1598 {
1584 GenericCast::castToAtomic(result, result, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, loc);1599 GenericCast::castToBuiltinAtomic(result, result, store::XS_DOUBLE, NULL, loc);
1585 lResultType = rtm.DOUBLE_TYPE_ONE;1600 lResultType = store::XS_DOUBLE;
1586 }1601 }
15871602
1588 if (!TypeOps::is_numeric(tm, *lResultType) &&1603 if (!TypeOps::is_numeric(lResultType) &&
1589 (!TypeOps::is_subtype(tm, *lResultType, *rtm.DURATION_TYPE_ONE) ||1604 (!TypeOps::is_subtype(lResultType, store::XS_DURATION) ||
1590 TypeOps::is_equal(tm, *lResultType, *rtm.DURATION_TYPE_ONE)))1605 lResultType == store::XS_DURATION))
1591 {1606 {
1607 xqtref_t type = tm->create_value_type(result);
1592 RAISE_ERROR(err::FORG0006, loc,1608 RAISE_ERROR(err::FORG0006, loc,
1593 ERROR_PARAMS(ZED(BadArgTypeForFn_2o34o), *lResultType, "fn:sum"));1609 ERROR_PARAMS(ZED(BadArgTypeForFn_2o34o), *type, "fn:sum"));
1594 }1610 }
15951611
1596 while (consumeNext(lRunningItem, theChildren[0].getp(), planState))1612 while (consumeNext(lRunningItem, theChildren[0].getp(), planState))
1597 {1613 {
1598 // casting of untyped atomic1614 // casting of untyped atomic
1599 lRunningType = tm->create_value_type(lRunningItem);1615 lRunningType = lRunningItem->getTypeCode();
16001616
1601 if (TypeOps::is_subtype(tm, *lRunningType, *rtm.UNTYPED_ATOMIC_TYPE_ONE))1617 if (lRunningType == store::XS_UNTYPED_ATOMIC)
1602 {1618 {
1603 GenericCast::castToAtomic(lRunningItem,1619 GenericCast::castToBuiltinAtomic(lRunningItem,
1604 lRunningItem,1620 lRunningItem,
1605 &*rtm.DOUBLE_TYPE_ONE,1621 store::XS_DOUBLE,
1606 tm,1622 NULL,
1607 NULL,1623 loc);
1608 loc);
16091624
1610 lRunningType = rtm.DOUBLE_TYPE_ONE;1625 lRunningType = store::XS_DOUBLE;
1611 }1626 }
16121627
1613 // handling of NaN1628 // handling of NaN
@@ -1617,12 +1632,12 @@
1617 break;1632 break;
1618 }1633 }
16191634
1620 if((TypeOps::is_numeric(tm, *lResultType) &&1635 if ((TypeOps::is_numeric(lResultType) &&
1621 TypeOps::is_numeric(tm, *lRunningType)) ||1636 TypeOps::is_numeric(lRunningType)) ||
1622 (TypeOps::is_subtype(tm, *lResultType, *rtm.YM_DURATION_TYPE_ONE) &&1637 (TypeOps::is_subtype(lResultType, store::XS_YM_DURATION) &&
1623 TypeOps::is_subtype(tm, *lRunningType, *rtm.YM_DURATION_TYPE_ONE)) ||1638 TypeOps::is_subtype(lRunningType, store::XS_YM_DURATION)) ||
1624 (TypeOps::is_subtype(tm, *lResultType, *rtm.DT_DURATION_TYPE_ONE) &&1639 (TypeOps::is_subtype(lResultType, store::XS_DT_DURATION) &&
1625 TypeOps::is_subtype(tm, *lRunningType, *rtm.DT_DURATION_TYPE_ONE)))1640 TypeOps::is_subtype(lRunningType, store::XS_DT_DURATION)))
1626 {1641 {
1627 GenericArithIterator<AddOperation>::compute(result,1642 GenericArithIterator<AddOperation>::compute(result,
1628 planState.theLocalDynCtx,1643 planState.theLocalDynCtx,
@@ -1633,13 +1648,10 @@
1633 }1648 }
1634 else1649 else
1635 {1650 {
1636 throw XQUERY_EXCEPTION(1651 xqtref_t type1 = tm->create_value_type(result);
1637 err::FORG0006,1652 xqtref_t type2 = tm->create_value_type(lRunningItem);
1638 ERROR_PARAMS(1653 RAISE_ERROR(err::FORG0006, loc,
1639 ZED( SumImpossibleWithTypes_23 ), *lResultType, *lRunningType1654 ERROR_PARAMS(ZED( SumImpossibleWithTypes_23 ), *type1, *type2));
1640 ),
1641 ERROR_LOC( loc )
1642 );
1643 }1655 }
1644 }1656 }
16451657
@@ -1657,18 +1669,16 @@
1657 }1669 }
1658 else1670 else
1659 {1671 {
1660 STACK_PUSH(1672 STACK_PUSH(GENV_ITEMFACTORY->
1661 GENV_ITEMFACTORY->createInteger(1673 createInteger(result, numeric_consts<xs_integer>::zero()),
1662 result, numeric_consts<xs_integer>::zero()1674 state);
1663 ),
1664 state
1665 );
1666 }1675 }
1667 }1676 }
16681677
1669 STACK_END (state);1678 STACK_END(state);
1670}1679}
16711680
1681
1672/*******************************************************************************1682/*******************************************************************************
1673 15.4.5 fn:sum - Double1683 15.4.5 fn:sum - Double
1674********************************************************************************/1684********************************************************************************/
@@ -1766,6 +1776,7 @@
1766 STACK_END (state);1776 STACK_END (state);
1767}1777}
17681778
1779
1769/*******************************************************************************1780/*******************************************************************************
1770 15.4.5 fn:sum - Decimal1781 15.4.5 fn:sum - Decimal
1771********************************************************************************/1782********************************************************************************/
@@ -1814,6 +1825,7 @@
1814 STACK_END (state);1825 STACK_END (state);
1815}1826}
18161827
1828
1817/*******************************************************************************1829/*******************************************************************************
1818 15.4.5 fn:sum - Integer1830 15.4.5 fn:sum - Integer
1819********************************************************************************/1831********************************************************************************/
@@ -1823,8 +1835,8 @@
1823{1835{
1824 xs_integer sum;1836 xs_integer sum;
1825 store::Item_t item;1837 store::Item_t item;
1826 xqtref_t lResultType;1838 store::SchemaTypeCode lResultType;
1827 xqtref_t lTmpType;1839 store::SchemaTypeCode lTmpType;
18281840
1829 const TypeManager* tm = theSctx->get_typemanager();1841 const TypeManager* tm = theSctx->get_typemanager();
18301842
@@ -1833,13 +1845,15 @@
18331845
1834 if (consumeNext(item, theChildren[0].getp(), planState))1846 if (consumeNext(item, theChildren[0].getp(), planState))
1835 {1847 {
1836 lResultType = tm->create_value_type(item);1848 lResultType = item->getTypeCode();
1849
1837 sum = item->getIntegerValue();1850 sum = item->getIntegerValue();
18381851
1839 while (consumeNext(item, theChildren[0].getp(), planState))1852 while (consumeNext(item, theChildren[0].getp(), planState))
1840 {1853 {
1841 lTmpType = tm->create_value_type(item);1854 lTmpType = item->getTypeCode();
1842 if(TypeOps::is_subtype(tm, *lResultType, *lTmpType))1855
1856 if (TypeOps::is_subtype(lResultType, lTmpType))
1843 lResultType = lTmpType;1857 lResultType = lTmpType;
18441858
1845 if (item->isNaN())1859 if (item->isNaN())
@@ -1852,7 +1866,8 @@
1852 }1866 }
18531867
1854 GENV_ITEMFACTORY->createInteger(result, sum);1868 GENV_ITEMFACTORY->createInteger(result, sum);
1855 GenericCast::castToAtomic(result, result, &*lResultType, tm, NULL, loc);1869
1870 GenericCast::castToBuiltinAtomic(result, result, lResultType, NULL, loc);
18561871
1857 STACK_PUSH(true, state);1872 STACK_PUSH(true, state);
1858 }1873 }
@@ -1872,6 +1887,7 @@
1872 STACK_END (state);1887 STACK_END (state);
1873}1888}
18741889
1890
1875/*******************************************************************************1891/*******************************************************************************
1876 15.5.1 op:to1892 15.5.1 op:to
1877********************************************************************************/1893********************************************************************************/
@@ -1906,6 +1922,7 @@
1906 STACK_END (state);1922 STACK_END (state);
1907}1923}
19081924
1925
1909/*******************************************************************************1926/*******************************************************************************
1910 15.5.4 fn:doc1927 15.5.4 fn:doc
1911********************************************************************************/1928********************************************************************************/
19121929
=== modified file 'src/runtime/store/maps_impl.cpp'
--- src/runtime/store/maps_impl.cpp 2013-05-08 20:14:47 +0000
+++ src/runtime/store/maps_impl.cpp 2013-06-11 09:57:50 +0000
@@ -77,10 +77,7 @@
77 loc ) )77 loc ) )
78 {78 {
79 RAISE_ERROR(zerr::ZXQD0005_INVALID_KEY_FOR_MAP, loc,79 RAISE_ERROR(zerr::ZXQD0005_INVALID_KEY_FOR_MAP, loc,
80 ERROR_PARAMS(*searchKeyType,80 ERROR_PARAMS(*searchKeyType, *indexKeyType, aQName->getStringValue()));
81 *indexKeyType,
82 aQName->getStringValue())
83 );
84 }81 }
85 else82 else
86 {83 {
@@ -91,10 +88,7 @@
91 if ( e.diagnostic() == err::FORG0001 )88 if ( e.diagnostic() == err::FORG0001 )
92 {89 {
93 RAISE_ERROR(zerr::ZXQD0005_INVALID_KEY_FOR_MAP, loc,90 RAISE_ERROR(zerr::ZXQD0005_INVALID_KEY_FOR_MAP, loc,
94 ERROR_PARAMS(*searchKeyType,91 ERROR_PARAMS(*searchKeyType, *indexKeyType, aQName->getStringValue()));
95 *indexKeyType,
96 aQName->getStringValue())
97 );
98 }92 }
99 throw;93 throw;
100 }94 }
10195
=== modified file 'src/types/typeops.cpp'
--- src/types/typeops.cpp 2013-06-03 23:03:58 +0000
+++ src/types/typeops.cpp 2013-06-11 09:57:50 +0000
@@ -1151,7 +1151,6 @@
11511151
1152 RootTypeManager& rtm = GENV_TYPESYSTEM;1152 RootTypeManager& rtm = GENV_TYPESYSTEM;
11531153
1154 xqtref_t resultType;
1155 TypeConstants::quantifier_t resultQuant = TypeConstants::QUANT_ONE;1154 TypeConstants::quantifier_t resultQuant = TypeConstants::QUANT_ONE;
11561155
1157 TypeConstants::quantifier_t quant1 = type1.get_quantifier();1156 TypeConstants::quantifier_t quant1 = type1.get_quantifier();
@@ -1166,43 +1165,43 @@
1166 }1165 }
11671166
1168 if (division &&1167 if (division &&
1169 TypeOps::is_subtype(tm, type1, *rtm.INTEGER_TYPE_STAR) &&1168 is_subtype(tm, type1, *rtm.INTEGER_TYPE_STAR) &&
1170 TypeOps::is_subtype(tm, type2, *rtm.INTEGER_TYPE_STAR))1169 is_subtype(tm, type2, *rtm.INTEGER_TYPE_STAR))
1171 {1170 {
1172 return (resultQuant == TypeConstants::QUANT_ONE ?1171 return (resultQuant == TypeConstants::QUANT_ONE ?
1173 rtm.DECIMAL_TYPE_ONE : rtm.DECIMAL_TYPE_QUESTION); 1172 rtm.DECIMAL_TYPE_ONE : rtm.DECIMAL_TYPE_QUESTION);
1174 }1173 }
11751174
1176 if (TypeOps::is_subtype(tm, type1, *rtm.UNTYPED_ATOMIC_TYPE_STAR) ||1175 if (is_subtype(tm, type1, *rtm.UNTYPED_ATOMIC_TYPE_STAR) ||
1177 TypeOps::is_subtype(tm, type2, *rtm.UNTYPED_ATOMIC_TYPE_STAR)) 1176 is_subtype(tm, type2, *rtm.UNTYPED_ATOMIC_TYPE_STAR))
1178 {1177 {
1179 return (resultQuant == TypeConstants::QUANT_ONE ?1178 return (resultQuant == TypeConstants::QUANT_ONE ?
1180 rtm.DOUBLE_TYPE_ONE : rtm.DOUBLE_TYPE_QUESTION);1179 rtm.DOUBLE_TYPE_ONE : rtm.DOUBLE_TYPE_QUESTION);
1181 }1180 }
1182 1181
1183 if (TypeOps::is_subtype(tm, type1, *rtm.DOUBLE_TYPE_STAR) ||1182 if (is_subtype(tm, type1, *rtm.DOUBLE_TYPE_STAR) ||
1184 TypeOps::is_subtype(tm, type2, *rtm.DOUBLE_TYPE_STAR)) 1183 is_subtype(tm, type2, *rtm.DOUBLE_TYPE_STAR))
1185 {1184 {
1186 return (resultQuant == TypeConstants::QUANT_ONE ?1185 return (resultQuant == TypeConstants::QUANT_ONE ?
1187 rtm.DOUBLE_TYPE_ONE : rtm.DOUBLE_TYPE_QUESTION);1186 rtm.DOUBLE_TYPE_ONE : rtm.DOUBLE_TYPE_QUESTION);
1188 }1187 }
1189 1188
1190 if (TypeOps::is_subtype(tm, type1, *rtm.FLOAT_TYPE_STAR) ||1189 if (is_subtype(tm, type1, *rtm.FLOAT_TYPE_STAR) ||
1191 TypeOps::is_subtype(tm, type2, *rtm.FLOAT_TYPE_STAR)) 1190 is_subtype(tm, type2, *rtm.FLOAT_TYPE_STAR))
1192 {1191 {
1193 return (resultQuant == TypeConstants::QUANT_ONE ?1192 return (resultQuant == TypeConstants::QUANT_ONE ?
1194 rtm.FLOAT_TYPE_ONE : rtm.FLOAT_TYPE_QUESTION);1193 rtm.FLOAT_TYPE_ONE : rtm.FLOAT_TYPE_QUESTION);
1195 }1194 }
11961195
1197 if (TypeOps::is_subtype(tm, type1, *rtm.INTEGER_TYPE_STAR) &&1196 if (is_subtype(tm, type1, *rtm.INTEGER_TYPE_STAR) &&
1198 TypeOps::is_subtype(tm, type2, *rtm.INTEGER_TYPE_STAR)) 1197 is_subtype(tm, type2, *rtm.INTEGER_TYPE_STAR))
1199 {1198 {
1200 return (resultQuant == TypeConstants::QUANT_ONE ?1199 return (resultQuant == TypeConstants::QUANT_ONE ?
1201 rtm.INTEGER_TYPE_ONE : rtm.INTEGER_TYPE_QUESTION);1200 rtm.INTEGER_TYPE_ONE : rtm.INTEGER_TYPE_QUESTION);
1202 }1201 }
12031202
1204 if (TypeOps::is_subtype(tm, type1, *rtm.DECIMAL_TYPE_STAR) &&1203 if (is_subtype(tm, type1, *rtm.DECIMAL_TYPE_STAR) &&
1205 TypeOps::is_subtype(tm, type2, *rtm.DECIMAL_TYPE_STAR)) 1204 is_subtype(tm, type2, *rtm.DECIMAL_TYPE_STAR))
1206 {1205 {
1207 return (resultQuant == TypeConstants::QUANT_ONE ?1206 return (resultQuant == TypeConstants::QUANT_ONE ?
1208 rtm.DECIMAL_TYPE_ONE : rtm.DECIMAL_TYPE_QUESTION); 1207 rtm.DECIMAL_TYPE_ONE : rtm.DECIMAL_TYPE_QUESTION);
@@ -1215,6 +1214,50 @@
1215/*******************************************************************************1214/*******************************************************************************
12161215
1217********************************************************************************/1216********************************************************************************/
1217store::SchemaTypeCode TypeOps::arithmetic_type(
1218 store::SchemaTypeCode type1,
1219 store::SchemaTypeCode type2,
1220 bool division)
1221{
1222 if (division &&
1223 is_subtype(type1, store::XS_INTEGER) &&
1224 is_subtype(type2, store::XS_INTEGER))
1225 {
1226 return store::XS_DECIMAL;
1227 }
1228
1229 if (type1 == store::XS_UNTYPED_ATOMIC || type2 == store::XS_UNTYPED_ATOMIC)
1230 {
1231 return store::XS_DOUBLE;
1232 }
1233
1234 if (is_subtype(type1, store::XS_DOUBLE) || is_subtype(type2, store::XS_DOUBLE))
1235 {
1236 return store::XS_DOUBLE;
1237 }
1238
1239 if (is_subtype(type1, store::XS_FLOAT) || is_subtype(type2, store::XS_FLOAT))
1240 {
1241 return store::XS_FLOAT;
1242 }
1243
1244 if (is_subtype(type1, store::XS_INTEGER) && is_subtype(type2, store::XS_INTEGER))
1245 {
1246 return store::XS_INTEGER;
1247 }
1248
1249 if (is_subtype(type1, store::XS_DECIMAL) && is_subtype(type2, store::XS_DECIMAL))
1250 {
1251 return store::XS_DECIMAL;
1252 }
1253
1254 return store::XS_ANY_ATOMIC;
1255}
1256
1257
1258/*******************************************************************************
1259
1260********************************************************************************/
1218static inline IdentTypes::quantifier_t get_typeident_quant(1261static inline IdentTypes::quantifier_t get_typeident_quant(
1219 TypeConstants::quantifier_t quant)1262 TypeConstants::quantifier_t quant)
1220{1263{
12211264
=== modified file 'src/types/typeops.h'
--- src/types/typeops.h 2013-02-07 17:24:36 +0000
+++ src/types/typeops.h 2013-06-11 09:57:50 +0000
@@ -181,6 +181,11 @@
181 const XQType& type2,181 const XQType& type2,
182 bool division);182 bool division);
183183
184 static store::SchemaTypeCode arithmetic_type(
185 store::SchemaTypeCode type1,
186 store::SchemaTypeCode type2,
187 bool division);
188
184 /*189 /*
185 * Returns a type identifier that represents the given type.190 * Returns a type identifier that represents the given type.
186 * The invariant that is guaranteed is:191 * The invariant that is guaranteed is:

Subscribers

People subscribed via source and target branches