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

Proposed by Markos Zaharioudakis
Status: Merged
Approved by: Markos Zaharioudakis
Approved revision: 11042
Merged at revision: 11293
Proposed branch: lp:~zorba-coders/zorba/markos-scratch
Merge into: lp:zorba
Diff against target: 844 lines (+299/-146)
14 files modified
ChangeLog (+1/-0)
bin/zorbacmd.cpp (+3/-0)
src/api/staticcontextimpl.cpp (+1/-1)
src/compiler/translator/translator.cpp (+105/-77)
src/context/root_static_context.cpp (+2/-1)
src/context/static_context.cpp (+71/-16)
src/context/static_context.h (+17/-10)
src/functions/func_sequences_impl.cpp (+44/-0)
src/functions/pregenerated/func_sequences.cpp (+0/-9)
src/runtime/sequences/pregenerated/sequences.cpp (+2/-0)
src/runtime/sequences/pregenerated/sequences.h (+6/-2)
src/runtime/sequences/sequences_impl.cpp (+36/-26)
src/runtime/spec/sequences/sequences.xml (+9/-3)
test/rbkt/testdriver.cpp (+2/-1)
To merge this branch: bzr merge lp:~zorba-coders/zorba/markos-scratch
Reviewer Review Type Date Requested Status
Markos Zaharioudakis Approve
Review via email: mp+153930@code.launchpad.net

Commit message

1.In jsoniq mode, allow multiple default function namespaces and no need to use the xs prefix for naming builtin atomic types.
2. Optimization for indef-of function.

Description of the change

1.In jsoniq mode, allow multiple default function namespaces and no need to use the xs prefix for naming builtin atomic types.
2. Optimization for indef-of function.

To post a comment you must log in.
Revision history for this message
Markos Zaharioudakis (markos-za) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

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

text conflict in ChangeLog

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

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

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job markos-scratch-2013-03-18T22-04-45.483Z is finished.
  The final status was:

  6 tests did not succeed - changes not commited.

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

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

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

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job markos-scratch-2013-03-20T01-44-56.424Z is finished.
  The final status was:

  5 tests did not succeed - changes not commited.

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

11042. By Markos Zaharioudakis

a bug fix for index-of

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-03-20T02-52-48.899Z 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-03-16 20:55:24 +0000
+++ ChangeLog 2013-03-20 02:47:23 +0000
@@ -15,6 +15,7 @@
15 for streamable strings and base64Binary.15 for streamable strings and base64Binary.
16 * Added millis-to-dateTime() function in datetime module.16 * Added millis-to-dateTime() function in datetime module.
17 * fn:trace outputs "empty-sequence()" if the input is the empty-sequence.17 * fn:trace outputs "empty-sequence()" if the input is the empty-sequence.
18 * Allow multiple default function namespaces.
18 * Added xqxq:variable-value function.19 * Added xqxq:variable-value function.
19 * Added canonicalize function to modules/xml.20 * Added canonicalize function to modules/xml.
20 * Added support for xs:dateTimeStamp type from XMLSchema 1.1, bug #924754.21 * Added support for xs:dateTimeStamp type from XMLSchema 1.1, bug #924754.
2122
=== modified file 'bin/zorbacmd.cpp'
--- bin/zorbacmd.cpp 2013-02-07 17:24:36 +0000
+++ bin/zorbacmd.cpp 2013-03-20 02:47:23 +0000
@@ -673,6 +673,8 @@
673 std::auto_ptr<std::fstream> planFile;673 std::auto_ptr<std::fstream> planFile;
674 std::fstream* planFilep = NULL;674 std::fstream* planFilep = NULL;
675675
676 lHints.jsoniq_mode = (qfilepath.rfind(".jq") == qfilepath.size() - 3);
677
676 if (serializePlan)678 if (serializePlan)
677 {679 {
678 if (savePlan || loadPlan)680 if (savePlan || loadPlan)
@@ -724,6 +726,7 @@
724 }726 }
725727
726 Zorba_SerializerOptions lSerOptions = Zorba_SerializerOptions::SerializerOptionsFromStringParams(properties.getSerializerParameters());728 Zorba_SerializerOptions lSerOptions = Zorba_SerializerOptions::SerializerOptionsFromStringParams(properties.getSerializerParameters());
729
727 createSerializerOptions(lSerOptions, properties);730 createSerializerOptions(lSerOptions, properties);
728731
729 zorba::XQuery_t query;732 zorba::XQuery_t query;
730733
=== modified file 'src/api/staticcontextimpl.cpp'
--- src/api/staticcontextimpl.cpp 2013-02-07 17:24:36 +0000
+++ src/api/staticcontextimpl.cpp 2013-03-20 02:47:23 +0000
@@ -316,7 +316,7 @@
316316
317********************************************************************************/317********************************************************************************/
318String318String
319StaticContextImpl::getDefaultFunctionNamespace( ) const319StaticContextImpl::getDefaultFunctionNamespace() const
320{320{
321 try321 try
322 {322 {
323323
=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp 2013-03-08 00:09:46 +0000
+++ src/compiler/translator/translator.cpp 2013-03-20 02:47:23 +0000
@@ -1031,6 +1031,11 @@
1031 Convert a lexical qname identifying a function to an expanded qname item.1031 Convert a lexical qname identifying a function to an expanded qname item.
1032 If the lexical qname does not have a prefix, the default function namespace1032 If the lexical qname does not have a prefix, the default function namespace
1033 (if any) will be used to build the expanded qname item.1033 (if any) will be used to build the expanded qname item.
1034
1035 Raise error is the prefix is non-empty and there is no ns associated with it.
1036
1037 This method is used during the processing of function declarations (when the
1038 function object is not supposed to exist already).
1034********************************************************************************/1039********************************************************************************/
1035void expand_function_qname(1040void expand_function_qname(
1036 store::Item_t& qnameItem,1041 store::Item_t& qnameItem,
@@ -1297,7 +1302,7 @@
1297********************************************************************************/1302********************************************************************************/
1298void bind_fn(1303void bind_fn(
1299 function_t& f,1304 function_t& f,
1300 ulong nargs,1305 csize nargs,
1301 const QueryLoc& loc)1306 const QueryLoc& loc)
1302{1307{
1303 theSctx->bind_fn(f, nargs, loc);1308 theSctx->bind_fn(f, nargs, loc);
@@ -1313,14 +1318,17 @@
13131318
1314/*******************************************************************************1319/*******************************************************************************
1315 Lookup in the sctx the function object for a function with a given prefix1320 Lookup in the sctx the function object for a function with a given prefix
1316 local name and arity. Return NULL if such a function is not found1321 local name and arity. Raise error if the prefix is non-empty and does not have
1322 an associated namespace. Return NULL if such a function is not found.
1317********************************************************************************/1323********************************************************************************/
1318function* lookup_fn(const QName* qname, ulong arity, const QueryLoc& loc)1324function* lookup_fn(const QName* qname, csize arity, const QueryLoc& loc)
1319{1325{
1320 store::Item_t qnameItem;1326 return theSctx->lookup_fn(qname->get_namespace(),
1321 expand_function_qname(qnameItem, qname, loc);1327 qname->get_prefix(),
13221328 qname->get_localname(),
1323 return theSctx->lookup_fn(qnameItem, arity);1329 arity,
1330 theCCB->theConfig.jsoniq_mode,
1331 loc);
1324}1332}
13251333
13261334
@@ -4140,10 +4148,10 @@
41404148
4141 //bool recognised = false;4149 //bool recognised = false;
41424150
4143 store::Item_t lExpandedQName;4151 store::Item_t expandedQName;
4144 expand_function_qname(lExpandedQName, v.get_qname(), loc);4152 expand_function_qname(expandedQName, v.get_qname(), loc);
41454153
4146 zstring annotNS = lExpandedQName->getNamespace();4154 zstring annotNS = expandedQName->getNamespace();
41474155
4148 if (annotNS == static_context::W3C_XML_NS ||4156 if (annotNS == static_context::W3C_XML_NS ||
4149 annotNS == XML_SCHEMA_NS ||4157 annotNS == XML_SCHEMA_NS ||
@@ -4152,10 +4160,10 @@
4152 annotNS == XQUERY_MATH_FN_NS ||4160 annotNS == XQUERY_MATH_FN_NS ||
4153 annotNS == ZORBA_ANNOTATIONS_NS)4161 annotNS == ZORBA_ANNOTATIONS_NS)
4154 {4162 {
4155 if (AnnotationInternal::lookup(lExpandedQName) == AnnotationInternal::zann_end)4163 if (AnnotationInternal::lookup(expandedQName) == AnnotationInternal::zann_end)
4156 {4164 {
4157 RAISE_ERROR(err::XQST0045, loc,4165 RAISE_ERROR(err::XQST0045, loc,
4158 ERROR_PARAMS(lExpandedQName->getLocalName(), ZED(ANNOTATION), annotNS));4166 ERROR_PARAMS(expandedQName->getLocalName(), ZED(ANNOTATION), annotNS));
4159 }4167 }
41604168
4161 //recognised = true;4169 //recognised = true;
@@ -4177,7 +4185,7 @@
4177 }4185 }
41784186
4179 //if (recognised)4187 //if (recognised)
4180 theAnnotations->push_back(lExpandedQName, lLiterals);4188 theAnnotations->push_back(expandedQName, lLiterals);
4181}4189}
41824190
41834191
@@ -8640,9 +8648,19 @@
86408648
8641 rchandle<QName> qname = v.get_qname();8649 rchandle<QName> qname = v.get_qname();
8642 store::Item_t qnameItem;8650 store::Item_t qnameItem;
8643 expand_elem_qname(qnameItem, qname, loc);8651
8652 if (!qname->get_prefix().empty() || !theCCB->theConfig.jsoniq_mode)
8653 {
8654 expand_elem_qname(qnameItem, qname, loc);
8655 }
8656 else
8657 {
8658 GENV_ITEMFACTORY->
8659 createQName(qnameItem, XML_SCHEMA_NS, "", qname->get_localname());
8660 }
86448661
8645 xqtref_t t = CTX_TM->create_named_simple_type(qnameItem);8662 xqtref_t t = CTX_TM->create_named_simple_type(qnameItem);
8663
8646 if (t == NULL)8664 if (t == NULL)
8647 {8665 {
8648 if (theSctx->xquery_version() < StaticContextConsts::xquery_version_3_0)8666 if (theSctx->xquery_version() < StaticContextConsts::xquery_version_3_0)
@@ -10738,20 +10756,6 @@
1073810756
10739 TypeManager* tm = CTX_TM;10757 TypeManager* tm = CTX_TM;
1074010758
10741 // Expand the function qname
10742 rchandle<QName> qname = v.get_fname();
10743
10744 store::Item_t qnameItem;
10745 expand_function_qname(qnameItem, qname, loc);
10746
10747 const zstring& fn_ns = qnameItem->getNamespace();
10748
10749 if (static_context::is_reserved_module(fn_ns))
10750 {
10751 RAISE_ERROR(zerr::ZXQP0016_RESERVED_MODULE_TARGET_NAMESPACE, loc,
10752 ERROR_PARAMS(fn_ns));
10753 }
10754
10755 // Collect the arguments of this function in reverse order10759 // Collect the arguments of this function in reverse order
10756 std::vector<expr*> arguments;10760 std::vector<expr*> arguments;
1075710761
@@ -10767,17 +10771,73 @@
1076710771
10768 csize numArgs = arguments.size();10772 csize numArgs = arguments.size();
1076910773
10774 // Lookup the function
10775 store::Item_t qnameItem;
10776 const QName* qname = v.get_fname();
10777
10770 function* f = lookup_fn(qname, numArgs, loc);10778 function* f = lookup_fn(qname, numArgs, loc);
1077110779
10780 zstring fn_ns;
10781
10782 if (f != NULL)
10783 {
10784 qnameItem = f->getName();
10785 fn_ns = qnameItem->getNamespace();
10786
10787 if (static_context::is_reserved_module(fn_ns))
10788 {
10789 RAISE_ERROR(zerr::ZXQP0016_RESERVED_MODULE_TARGET_NAMESPACE, loc,
10790 ERROR_PARAMS(fn_ns));
10791 }
10792 }
10793 else
10794 {
10795 // Check if this is a call to a type constructor function
10796 expand_function_qname(qnameItem, qname, loc);
10797
10798 xqtref_t type = CTX_TM->create_named_type(qnameItem,
10799 TypeConstants::QUANT_QUESTION,
10800 loc);
10801
10802 if (type != NULL)
10803 {
10804 if (numArgs != 1 ||
10805 TypeOps::is_equal(tm, *type, *GENV_TYPESYSTEM.NOTATION_TYPE_QUESTION, loc) ||
10806 TypeOps::is_equal(tm, *type, *GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_QUESTION, loc))
10807 {
10808 RAISE_ERROR(err::XPST0017, loc,
10809 ERROR_PARAMS(qname->get_qname(), ZED(FunctionUndeclared_3), numArgs));
10810 }
10811
10812 push_nodestack(create_cast_expr(loc, arguments[0], type, true, true));
10813
10814 return;
10815 }
10816
10817 if (theHaveModuleImportCycle)
10818 {
10819 fn_ns = qnameItem->getNamespace();
10820
10821 std::map<zstring, zstring>::const_iterator ite = theModulesStack.begin();
10822 std::map<zstring, zstring>::const_iterator end = theModulesStack.end();
10823
10824 --end;
10825 assert((*end).second == theModuleNamespace);
10826
10827 for (; ite != end; ++ite)
10828 {
10829 if ((*ite).second == fn_ns)
10830 RAISE_ERROR(err::XQST0093, loc, ERROR_PARAMS(theModuleNamespace));
10831 }
10832 }
10833
10834 RAISE_ERROR(err::XPST0017, loc,
10835 ERROR_PARAMS(qname->get_qname(), ZED(FunctionUndeclared_3), numArgs));
10836 }
10837
10772 if (fn_ns == static_context::W3C_FN_NS)10838 if (fn_ns == static_context::W3C_FN_NS)
10773 {10839 {
10774 // Some special processing is required for certain "fn" functions10840 // Some special processing is required for certain "fn" functions
10775 if (f == NULL)
10776 {
10777 RAISE_ERROR(err::XPST0017, loc,
10778 ERROR_PARAMS(qname->get_qname(), ZED(FunctionUndeclared_3), numArgs));
10779 }
10780
10781 switch (f->getKind())10841 switch (f->getKind())
10782 {10842 {
10783 case FunctionConsts::FN_HEAD_1:10843 case FunctionConsts::FN_HEAD_1:
@@ -11062,48 +11122,7 @@
1106211122
11063 numArgs = arguments.size(); // recompute size11123 numArgs = arguments.size(); // recompute size
1106411124
11065 // Check if this is a call to a type constructor function11125 {
11066 xqtref_t type = CTX_TM->create_named_type(qnameItem,
11067 TypeConstants::QUANT_QUESTION,
11068 loc);
11069
11070 if (type != NULL)
11071 {
11072 if (numArgs != 1 ||
11073 TypeOps::is_equal(tm, *type, *GENV_TYPESYSTEM.NOTATION_TYPE_QUESTION, loc) ||
11074 TypeOps::is_equal(tm, *type, *GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_QUESTION, loc))
11075 {
11076 RAISE_ERROR(err::XPST0017, loc,
11077 ERROR_PARAMS(qname->get_qname(), ZED(FunctionUndeclared_3), numArgs));
11078 }
11079
11080 push_nodestack(create_cast_expr(loc, arguments[0], type, true, true));
11081 }
11082
11083 // It is not a builtin constructor function
11084 else
11085 {
11086 if (f == NULL)
11087 {
11088 if (theHaveModuleImportCycle)
11089 {
11090 std::map<zstring, zstring>::const_iterator ite = theModulesStack.begin();
11091 std::map<zstring, zstring>::const_iterator end = theModulesStack.end();
11092
11093 --end;
11094 assert((*end).second == theModuleNamespace);
11095
11096 for (; ite != end; ++ite)
11097 {
11098 if ((*ite).second == fn_ns)
11099 RAISE_ERROR(err::XQST0093, loc, ERROR_PARAMS(theModuleNamespace));
11100 }
11101 }
11102
11103 RAISE_ERROR(err::XPST0017, loc,
11104 ERROR_PARAMS(qname->get_qname(), ZED(FunctionUndeclared_3), numArgs));
11105 }
11106
11107 // If this is a udf that is invoked from another udf, mark that other udf11126 // If this is a udf that is invoked from another udf, mark that other udf
11108 // as a non-leaf function.11127 // as a non-leaf function.
11109 if (f->isUdf())11128 if (f->isUdf())
@@ -13084,7 +13103,16 @@
1308413103
13085 rchandle<QName> qname = v.get_qname();13104 rchandle<QName> qname = v.get_qname();
13086 store::Item_t qnameItem;13105 store::Item_t qnameItem;
13087 expand_elem_qname(qnameItem, qname, loc);13106
13107 if (!qname->get_prefix().empty() || !theCCB->theConfig.jsoniq_mode)
13108 {
13109 expand_elem_qname(qnameItem, qname, loc);
13110 }
13111 else
13112 {
13113 GENV_ITEMFACTORY->
13114 createQName(qnameItem, XML_SCHEMA_NS, "", qname->get_localname());
13115 }
1308813116
13089 xqtref_t t = CTX_TM->create_named_simple_type(qnameItem);13117 xqtref_t t = CTX_TM->create_named_simple_type(qnameItem);
1309013118
1309113119
=== modified file 'src/context/root_static_context.cpp'
--- src/context/root_static_context.cpp 2013-02-07 17:24:36 +0000
+++ src/context/root_static_context.cpp 2013-03-20 02:47:23 +0000
@@ -157,7 +157,8 @@
157157
158 set_default_elem_type_ns(zstring(), true, loc); 158 set_default_elem_type_ns(zstring(), true, loc);
159159
160 set_default_function_ns(W3C_FN_NS, true, loc);160 set_default_function_ns(JSONIQ_FN_NS, false, loc);
161 set_default_function_ns(W3C_FN_NS, false, loc);
161162
162 add_collation(ZORBA_DEF_COLLATION_NS, QueryLoc::null);163 add_collation(ZORBA_DEF_COLLATION_NS, QueryLoc::null);
163 add_collation(W3C_CODEPT_COLLATION_NS, QueryLoc::null);164 add_collation(W3C_CODEPT_COLLATION_NS, QueryLoc::null);
164165
=== modified file 'src/context/static_context.cpp'
--- src/context/static_context.cpp 2013-02-26 04:12:43 +0000
+++ src/context/static_context.cpp 2013-03-20 02:47:23 +0000
@@ -677,7 +677,6 @@
677 theExternalModulesMap(NULL),677 theExternalModulesMap(NULL),
678 theNamespaceBindings(NULL),678 theNamespaceBindings(NULL),
679 theHaveDefaultElementNamespace(false),679 theHaveDefaultElementNamespace(false),
680 theHaveDefaultFunctionNamespace(false),
681 theContextItemType(NULL),680 theContextItemType(NULL),
682 theVariablesMap(NULL),681 theVariablesMap(NULL),
683 theImportedPrivateVariablesMap(NULL),682 theImportedPrivateVariablesMap(NULL),
@@ -724,7 +723,6 @@
724 theExternalModulesMap(NULL),723 theExternalModulesMap(NULL),
725 theNamespaceBindings(NULL),724 theNamespaceBindings(NULL),
726 theHaveDefaultElementNamespace(false),725 theHaveDefaultElementNamespace(false),
727 theHaveDefaultFunctionNamespace(false),
728 theContextItemType(NULL),726 theContextItemType(NULL),
729 theVariablesMap(NULL),727 theVariablesMap(NULL),
730 theImportedPrivateVariablesMap(NULL),728 theImportedPrivateVariablesMap(NULL),
@@ -776,7 +774,6 @@
776 theExternalModulesMap(NULL),774 theExternalModulesMap(NULL),
777 theNamespaceBindings(NULL),775 theNamespaceBindings(NULL),
778 theHaveDefaultElementNamespace(false),776 theHaveDefaultElementNamespace(false),
779 theHaveDefaultFunctionNamespace(false),
780 theContextItemType(NULL),777 theContextItemType(NULL),
781 theVariablesMap(NULL),778 theVariablesMap(NULL),
782 theImportedPrivateVariablesMap(NULL),779 theImportedPrivateVariablesMap(NULL),
@@ -1086,8 +1083,7 @@
1086 ar & theNamespaceBindings;1083 ar & theNamespaceBindings;
1087 ar & theDefaultElementNamespace;1084 ar & theDefaultElementNamespace;
1088 ar & theHaveDefaultElementNamespace;1085 ar & theHaveDefaultElementNamespace;
1089 ar & theDefaultFunctionNamespace;1086 ar & theDefaultFunctionNamespaces;
1090 ar & theHaveDefaultFunctionNamespace;
10911087
1092 ar & theContextItemType;1088 ar & theContextItemType;
10931089
@@ -2039,9 +2035,9 @@
2039********************************************************************************/2035********************************************************************************/
2040const zstring& static_context::default_function_ns() const2036const zstring& static_context::default_function_ns() const
2041{2037{
2042 if (theHaveDefaultFunctionNamespace || theParent == NULL)2038 if (!theDefaultFunctionNamespaces.empty() || theParent == NULL)
2043 {2039 {
2044 return theDefaultFunctionNamespace;2040 return theDefaultFunctionNamespaces[0];
2045 }2041 }
2046 else2042 else
2047 {2043 {
@@ -2058,10 +2054,9 @@
2058 bool raiseError,2054 bool raiseError,
2059 const QueryLoc& loc)2055 const QueryLoc& loc)
2060{2056{
2061 if (!theHaveDefaultFunctionNamespace)2057 if (theDefaultFunctionNamespaces.empty())
2062 {2058 {
2063 theDefaultFunctionNamespace = ns;2059 theDefaultFunctionNamespaces.push_back(ns);
2064 theHaveDefaultFunctionNamespace = true;
2065 }2060 }
2066 else if (raiseError)2061 else if (raiseError)
2067 {2062 {
@@ -2069,7 +2064,7 @@
2069 }2064 }
2070 else2065 else
2071 {2066 {
2072 theDefaultFunctionNamespace = ns;2067 theDefaultFunctionNamespaces.insert(theDefaultFunctionNamespaces.begin(), ns);
2073 }2068 }
2074}2069}
20752070
@@ -2429,7 +2424,7 @@
2429********************************************************************************/2424********************************************************************************/
2430void static_context::bind_fn(2425void static_context::bind_fn(
2431 function_t& f,2426 function_t& f,
2432 ulong arity,2427 csize arity,
2433 const QueryLoc& loc)2428 const QueryLoc& loc)
2434{2429{
2435 store::Item* qname = f->getName();2430 store::Item* qname = f->getName();
@@ -2441,7 +2436,7 @@
24412436
2442 if (theFunctionMap == NULL)2437 if (theFunctionMap == NULL)
2443 {2438 {
2444 ulong size = (is_global_root_sctx() ? 500 : 32);2439 csize size = (is_global_root_sctx() ? 500 : 32);
2445 theFunctionMap = new FunctionMap(HashMapItemPointerCmp(0, NULL), size, false);2440 theFunctionMap = new FunctionMap(HashMapItemPointerCmp(0, NULL), size, false);
2446 }2441 }
24472442
@@ -2503,7 +2498,7 @@
2503********************************************************************************/2498********************************************************************************/
2504void static_context::unbind_fn(2499void static_context::unbind_fn(
2505 const store::Item* qname,2500 const store::Item* qname,
2506 ulong arity)2501 csize arity)
2507{2502{
2508 ZORBA_ASSERT(!is_global_root_sctx());2503 ZORBA_ASSERT(!is_global_root_sctx());
25092504
@@ -2563,6 +2558,66 @@
2563}2558}
25642559
25652560
2561/*******************************************************************************
2562 Search in the sctx, starting from "this" and moving upwards, for the function
2563 object for a function with a given prefix local name and arity. Raise error if
2564 the prefix is non-empty and does not have an associated namespace. Return NULL
2565 if such a function is not found.
2566********************************************************************************/
2567function* static_context::lookup_fn(
2568 const zstring& ns,
2569 const zstring& pre,
2570 const zstring& local,
2571 csize arity,
2572 bool allowMultipleDefaultNamespaces,
2573 const QueryLoc& loc)
2574{
2575 store::Item_t qnameItem;
2576 std::vector<zstring>::const_iterator ite;
2577 std::vector<zstring>::const_iterator end;
2578 function* f = NULL;
2579
2580 if (!ns.empty())
2581 {
2582 ITEM_FACTORY->createQName(qnameItem, ns, "", local);
2583
2584 f = lookup_fn(qnameItem, arity, true);
2585 }
2586 else if (!pre.empty())
2587 {
2588 expand_qname(qnameItem, "", pre, local, loc);
2589
2590 f = lookup_fn(qnameItem, arity, true);
2591 }
2592 else if (allowMultipleDefaultNamespaces)
2593 {
2594 static_context* sctx = this;
2595
2596 while (f == NULL && sctx != NULL)
2597 {
2598 ite = sctx->theDefaultFunctionNamespaces.begin();
2599 end = sctx->theDefaultFunctionNamespaces.end();
2600
2601 for (; f == NULL && ite != end; ++ite)
2602 {
2603 ITEM_FACTORY->createQName(qnameItem, *ite, "", local);
2604 f = lookup_fn(qnameItem, arity, true);
2605 }
2606
2607 sctx = sctx->theParent;
2608 }
2609 }
2610 else
2611 {
2612 expand_qname(qnameItem, default_function_ns(), pre, local, loc);
2613
2614 f = lookup_fn(qnameItem, arity, true);
2615 }
2616
2617 return f;
2618}
2619
2620
2566/***************************************************************************//**2621/***************************************************************************//**
2567 Search the static-context tree, starting from "this" and moving upwards,2622 Search the static-context tree, starting from "this" and moving upwards,
2568 looking for the 1st sctx obj that contains a binding for a function with2623 looking for the 1st sctx obj that contains a binding for a function with
@@ -2572,7 +2627,7 @@
2572********************************************************************************/2627********************************************************************************/
2573function* static_context::lookup_fn(2628function* static_context::lookup_fn(
2574 const store::Item* qname,2629 const store::Item* qname,
2575 ulong arity,2630 csize arity,
2576 bool skipDisabled)2631 bool skipDisabled)
2577{2632{
2578 FunctionInfo fi;2633 FunctionInfo fi;
@@ -2627,7 +2682,7 @@
2627********************************************************************************/2682********************************************************************************/
2628function* static_context::lookup_local_fn(2683function* static_context::lookup_local_fn(
2629 const store::Item* qname,2684 const store::Item* qname,
2630 ulong arity,2685 csize arity,
2631 bool skipDisabled)2686 bool skipDisabled)
2632{2687{
2633 FunctionInfo fi;2688 FunctionInfo fi;
26342689
=== modified file 'src/context/static_context.h'
--- src/context/static_context.h 2013-02-26 04:12:43 +0000
+++ src/context/static_context.h 2013-03-20 02:47:23 +0000
@@ -352,9 +352,9 @@
352 ----------------------------352 ----------------------------
353 The namespace URI to be used for element and type qnames whose prefix is empty.353 The namespace URI to be used for element and type qnames whose prefix is empty.
354354
355 theDefaultFunctionNamespace :355 theDefaultFunctionNamespaces :
356 -----------------------------356 ------------------------------
357 The namespace URI to be used for function qnames whose prefix is empty.357 The namespace URIs to be used for function qnames whose prefix is empty.
358358
359 theContextItemType :359 theContextItemType :
360 --------------------360 --------------------
@@ -598,8 +598,7 @@
598 zstring theDefaultElementNamespace;598 zstring theDefaultElementNamespace;
599 bool theHaveDefaultElementNamespace;599 bool theHaveDefaultElementNamespace;
600600
601 zstring theDefaultFunctionNamespace;601 std::vector<zstring> theDefaultFunctionNamespaces;
602 bool theHaveDefaultFunctionNamespace;
603602
604 xqtref_t theContextItemType;603 xqtref_t theContextItemType;
605604
@@ -893,18 +892,26 @@
893 //892 //
894 // Functions893 // Functions
895 //894 //
896 void bind_fn(function_t& f, ulong arity, const QueryLoc& loc);895 void bind_fn(function_t& f, csize arity, const QueryLoc& loc);
897896
898 void unbind_fn(const store::Item* qname, ulong arity);897 void unbind_fn(const store::Item* qname, csize arity);
898
899 function* lookup_fn(
900 const zstring& ns,
901 const zstring& pre,
902 const zstring& local,
903 csize arity,
904 bool allowMultipleDefaultNamespaces,
905 const QueryLoc& loc);
899906
900 function* lookup_fn(907 function* lookup_fn(
901 const store::Item* qname,908 const store::Item* qname,
902 ulong arity,909 csize arity,
903 bool skipDisabled = true);910 bool skipDisabled = true);
904911
905 function* lookup_local_fn(912 function* lookup_local_fn(
906 const store::Item* qname,913 const store::Item* qname,
907 ulong arity,914 csize arity,
908 bool skipDisabled = true);915 bool skipDisabled = true);
909916
910 void get_functions(std::vector<function*>& functions) const;917 void get_functions(std::vector<function*>& functions) const;
911918
=== modified file 'src/functions/func_sequences_impl.cpp'
--- src/functions/func_sequences_impl.cpp 2013-02-07 17:24:36 +0000
+++ src/functions/func_sequences_impl.cpp 2013-03-20 02:47:23 +0000
@@ -492,6 +492,50 @@
492/*******************************************************************************492/*******************************************************************************
493493
494********************************************************************************/494********************************************************************************/
495PlanIter_t fn_index_of::codegen(
496 CompilerCB*,
497 static_context* sctx,
498 const QueryLoc& loc,
499 std::vector<PlanIter_t>& argv,
500 expr& caller) const
501{
502 TypeManager* tm = caller.get_type_manager();
503 RootTypeManager& rtm = GENV_TYPESYSTEM;
504
505 fo_expr* fo = static_cast<fo_expr*>(&caller);
506 expr* seqArg = fo->get_arg(0);
507 expr* keyArg = fo->get_arg(1);
508 xqtref_t seqType = seqArg->get_return_type();
509 xqtref_t pseqType = TypeOps::prime_type(tm, *seqType);
510 xqtref_t keyType = keyArg->get_return_type();
511
512 if (TypeOps::is_equal(tm, *keyType, *rtm.ANY_ATOMIC_TYPE_ONE) ||
513 TypeOps::is_equal(tm, *pseqType, *rtm.ANY_ATOMIC_TYPE_ONE))
514 {
515 return new FnIndexOfIterator(sctx, loc, argv, 0);
516 }
517
518 if (TypeOps::is_subtype(tm, *keyType, *seqType) ||
519 (TypeOps::is_subtype(tm, *keyType, *rtm.UNTYPED_ATOMIC_TYPE_ONE) &&
520 TypeOps::is_subtype(tm, *seqType, *rtm.STRING_TYPE_STAR)) ||
521 (TypeOps::is_subtype(tm, *keyType, *rtm.STRING_TYPE_ONE) &&
522 TypeOps::is_subtype(tm, *seqType, *rtm.UNTYPED_ATOMIC_TYPE_STAR)))
523 {
524 return new FnIndexOfIterator(sctx, loc, argv, 1);
525 }
526
527 if (TypeOps::is_subtype(tm, *pseqType, *keyType))
528 {
529 return new FnIndexOfIterator(sctx, loc, argv, 2);
530 }
531
532 return new FnIndexOfIterator(sctx, loc, argv, 0);
533}
534
535
536/*******************************************************************************
537
538********************************************************************************/
495xqtref_t fn_subsequence::getReturnType(const fo_expr* caller) const539xqtref_t fn_subsequence::getReturnType(const fo_expr* caller) const
496{540{
497 TypeManager* tm = caller->get_type_manager();541 TypeManager* tm = caller->get_type_manager();
498542
=== modified file 'src/functions/pregenerated/func_sequences.cpp'
--- src/functions/pregenerated/func_sequences.cpp 2013-03-05 23:11:50 +0000
+++ src/functions/pregenerated/func_sequences.cpp 2013-03-20 02:47:23 +0000
@@ -44,15 +44,6 @@
44 return new FnConcatIterator(sctx, loc, argv);44 return new FnConcatIterator(sctx, loc, argv);
45}45}
4646
47PlanIter_t fn_index_of::codegen(
48 CompilerCB*,
49 static_context* sctx,
50 const QueryLoc& loc,
51 std::vector<PlanIter_t>& argv,
52 expr& ann) const
53{
54 return new FnIndexOfIterator(sctx, loc, argv);
55}
5647
57PlanIter_t fn_empty::codegen(48PlanIter_t fn_empty::codegen(
58 CompilerCB*,49 CompilerCB*,
5950
=== modified file 'src/runtime/sequences/pregenerated/sequences.cpp'
--- src/runtime/sequences/pregenerated/sequences.cpp 2013-03-05 23:11:50 +0000
+++ src/runtime/sequences/pregenerated/sequences.cpp 2013-03-20 02:47:23 +0000
@@ -72,6 +72,8 @@
72{72{
73 serialize_baseclass(ar,73 serialize_baseclass(ar,
74 (NaryBaseIterator<FnIndexOfIterator, FnIndexOfIteratorState>*)this);74 (NaryBaseIterator<FnIndexOfIterator, FnIndexOfIteratorState>*)this);
75
76 ar & theFastComp;
75}77}
7678
7779
7880
=== modified file 'src/runtime/sequences/pregenerated/sequences.h'
--- src/runtime/sequences/pregenerated/sequences.h 2013-03-05 23:11:50 +0000
+++ src/runtime/sequences/pregenerated/sequences.h 2013-03-20 02:47:23 +0000
@@ -124,6 +124,8 @@
124124
125class FnIndexOfIterator : public NaryBaseIterator<FnIndexOfIterator, FnIndexOfIteratorState>125class FnIndexOfIterator : public NaryBaseIterator<FnIndexOfIterator, FnIndexOfIteratorState>
126{ 126{
127protected:
128 int theFastComp; //
127public:129public:
128 SERIALIZABLE_CLASS(FnIndexOfIterator);130 SERIALIZABLE_CLASS(FnIndexOfIterator);
129131
@@ -135,9 +137,11 @@
135 FnIndexOfIterator(137 FnIndexOfIterator(
136 static_context* sctx,138 static_context* sctx,
137 const QueryLoc& loc,139 const QueryLoc& loc,
138 std::vector<PlanIter_t>& children)140 std::vector<PlanIter_t>& children,
141 int fastComp)
139 : 142 :
140 NaryBaseIterator<FnIndexOfIterator, FnIndexOfIteratorState>(sctx, loc, children)143 NaryBaseIterator<FnIndexOfIterator, FnIndexOfIteratorState>(sctx, loc, children),
144 theFastComp(fastComp)
141 {}145 {}
142146
143 virtual ~FnIndexOfIterator();147 virtual ~FnIndexOfIterator();
144148
=== modified file 'src/runtime/sequences/sequences_impl.cpp'
--- src/runtime/sequences/sequences_impl.cpp 2013-03-05 12:34:19 +0000
+++ src/runtime/sequences/sequences_impl.cpp 2013-03-20 02:47:23 +0000
@@ -76,18 +76,16 @@
76 store::Item_t temp;76 store::Item_t temp;
7777
78 if (!PlanIterator::consumeNext(lCollationItem, iter, planState))78 if (!PlanIterator::consumeNext(lCollationItem, iter, planState))
79 throw XQUERY_EXCEPTION(79 {
80 err::XPTY0004,80 RAISE_ERROR(err::XPTY0004, loc,
81 ERROR_PARAMS( ZED( NoEmptySeqAsCollationParam ) ),81 ERROR_PARAMS(ZED(NoEmptySeqAsCollationParam)));
82 ERROR_LOC( loc )82 }
83 );
8483
85 if (PlanIterator::consumeNext(temp, iter, planState))84 if (PlanIterator::consumeNext(temp, iter, planState))
86 throw XQUERY_EXCEPTION(85 {
87 err::XPTY0004,86 RAISE_ERROR(err::XPTY0004, loc,
88 ERROR_PARAMS( ZED( NoSeqAsCollationParam ) ),87 ERROR_PARAMS(ZED(NoSeqAsCollationParam)));
89 ERROR_LOC( loc )88 }
90 );
9189
92 return sctx->get_collator(lCollationItem->getStringValue().str(), loc);90 return sctx->get_collator(lCollationItem->getStringValue().str(), loc);
93}91}
@@ -147,11 +145,9 @@
147bool145bool
148FnIndexOfIterator::nextImpl(store::Item_t& result, PlanState& planState) const146FnIndexOfIterator::nextImpl(store::Item_t& result, PlanState& planState) const
149{147{
150 store::Item_t lSequenceItem;148 store::Item_t seqItem;
151 store::Item_t lCollationItem;
152 xqtref_t lCollationItemType;
153 store::Item_t searchItem;149 store::Item_t searchItem;
154 TypeManager* typemgr = theSctx->get_typemanager();150 TypeManager* tm = theSctx->get_typemanager();
155 long timezone = 0;151 long timezone = 0;
156 bool found;152 bool found;
157153
@@ -163,26 +159,39 @@
163 RAISE_ERROR(err::FORG0006, loc, ERROR_PARAMS(ZED(EmptySeqNoSearchItem)));159 RAISE_ERROR(err::FORG0006, loc, ERROR_PARAMS(ZED(EmptySeqNoSearchItem)));
164 }160 }
165161
166 if ( theChildren.size() == 3 )162 if (theChildren.size() == 3)
167 state->theCollator = getCollator(theSctx, loc,163 {
168 planState, theChildren[2].getp());164 state->theCollator =
165 getCollator(theSctx, loc, planState, theChildren[2].getp());
166 }
169167
170 while ( consumeNext(lSequenceItem, theChildren[0].getp(), planState))168 while (consumeNext(seqItem, theChildren[0].getp(), planState))
171 {169 {
172 // inc the position in the sequence; do it at the beginning of the loop170 // inc the position in the sequence; do it at the beginning of the loop
173 // because index-of starts with one171 // because index-of starts with one
174 ++state->theCurrentPos;172 ++state->theCurrentPos;
175173
176 searchItem = state->theSearchItem;
177
178 try174 try
179 {175 {
180 found = CompareIterator::valueEqual(loc,176 if (theFastComp == 1)
181 lSequenceItem,177 {
182 searchItem,178 found = seqItem->equals(state->theSearchItem, timezone, state->theCollator);
183 typemgr,179 }
184 timezone,180 else if (theFastComp == 2)
185 state->theCollator);181 {
182 found = state->theSearchItem->equals(seqItem, timezone, state->theCollator);
183 }
184 else
185 {
186 searchItem = state->theSearchItem;
187
188 found = CompareIterator::valueEqual(loc,
189 seqItem,
190 searchItem,
191 tm,
192 timezone,
193 state->theCollator);
194 }
186 }195 }
187 catch (ZorbaException const& e)196 catch (ZorbaException const& e)
188 {197 {
@@ -203,6 +212,7 @@
203 STACK_END(state);212 STACK_END(state);
204}213}
205214
215
206/*******************************************************************************216/*******************************************************************************
207 15.1.4 fn:empty217 15.1.4 fn:empty
208********************************************************************************/218********************************************************************************/
209219
=== modified file 'src/runtime/spec/sequences/sequences.xml'
--- src/runtime/spec/sequences/sequences.xml 2013-02-07 17:24:36 +0000
+++ src/runtime/spec/sequences/sequences.xml 2013-03-20 02:47:23 +0000
@@ -102,7 +102,7 @@
102 The result sequence is in ascending numeric order.102 The result sequence is in ascending numeric order.
103 </zorba:description>103 </zorba:description>
104104
105 <zorba:function >105 <zorba:function generateCodegen="false">
106106
107 <zorba:signature localname="index-of" prefix="fn">107 <zorba:signature localname="index-of" prefix="fn">
108 <zorba:param>xs:anyAtomicType*</zorba:param>108 <zorba:param>xs:anyAtomicType*</zorba:param>
@@ -124,12 +124,18 @@
124 brief="the current position in the sequence"/>124 brief="the current position in the sequence"/>
125125
126 <zorba:member type="store::Item_t" name="theSearchItem" defaultValue="NULL"126 <zorba:member type="store::Item_t" name="theSearchItem" defaultValue="NULL"
127 brief="the item to search for"/>127 brief="the item to search for"/>
128128
129 <zorba:member type="XQPCollator*" name="theCollator" defaultValue="0"129 <zorba:member type="XQPCollator*" name="theCollator" defaultValue="0"
130 brief="the collator"/>130 brief="the collator"/>
131 </zorba:state>131 </zorba:state>
132132
133 <zorba:constructor>
134 <zorba:parameter type="int" name="fastComp"/>
135 </zorba:constructor>
136
137 <zorba:member type="int" name="theFastComp"/>
138
133</zorba:iterator>139</zorba:iterator>
134140
135<!--141<!--
136142
=== modified file 'test/rbkt/testdriver.cpp'
--- test/rbkt/testdriver.cpp 2013-03-16 00:58:28 +0000
+++ test/rbkt/testdriver.cpp 2013-03-20 02:47:23 +0000
@@ -325,7 +325,8 @@
325 lQuery = engine->createQuery(&errHandler);325 lQuery = engine->createQuery(&errHandler);
326 lQuery->setFileName(lQueryFile.get_path());326 lQuery->setFileName(lQueryFile.get_path());
327327
328 bool lJSONiqMode = lQueryFile.get_path().rfind(".jq") == lQueryFile.get_path().size() - 3;328 bool lJSONiqMode =
329 (lQueryFile.get_path().rfind(".jq") == lQueryFile.get_path().size() - 3);
329330
330 lQuery->compile(lQueryString.c_str(), lContext, getCompilerHints(lJSONiqMode));331 lQuery->compile(lQueryString.c_str(), lContext, getCompilerHints(lJSONiqMode));
331332

Subscribers

People subscribed via source and target branches