Matthias Brantner has proposed merging lp:~zorba-coders/zorba/xquery3.0_funcs into lp:zorba.
Requested reviews: Matthias Brantner (matthias-brantner) Related bugs: Bug #950616 in Zorba: "XQuery 3.0 vs Zorba: has-children#0 not implemented" https://bugs.launchpad.net/zorba/+bug/950616 Bug #950617 in Zorba: "XQuery 3.0 vs Zorba: nilled#0 not implemented" https://bugs.launchpad.net/zorba/+bug/950617 Bug #950618 in Zorba: "XQuery 3.0 vs Zorba: path not implemented" https://bugs.launchpad.net/zorba/+bug/950618 For more details, see: https://code.launchpad.net/~zorba-coders/zorba/xquery3.0_funcs/+merge/104341 Added XQuery 3.0 Functions path, has-children#0, nilled#0 -- https://code.launchpad.net/~zorba-coders/zorba/xquery3.0_funcs/+merge/104341 Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog' --- ChangeLog 2012-05-01 15:54:27 +0000 +++ ChangeLog 2012-05-02 07:34:22 +0000 @@ -3,11 +3,15 @@ version 2.5 New Features: - * fn:available-environment-variables - * fn:environment-variables - * fn:uri-collection - * fn:unparsed-text - * fn:unparsed-text-available + * XQuery 3.0 functions + - fn:available-environment-variables + - fn:environment-variables + - fn:uri-collection + - fn:unparsed-text + - fn:unparsed-text-available + - fn:has-children#0 + - fn:nilled#0 + - fn:path * Extended API for Python, Java, PHP and Ruby. * Add jvm classpath to zorbacmd and to Zorba API. Tracked by #931816 * Added full-text module. @@ -15,14 +19,11 @@ * Added XQJ support. * Added CollectionManager and DocumentManager support for XQJ. -Optimization: - Bug Fixes/Other Changes: * Fixed bugs #931501 and #866987 (improved error messages for fn:format-number(). Additionally, the function now throws the FODF1310 error instead of XTDE1310, as the 3.0 spec requires) * Fixed bug 955170 (Catch clause with URILiteral-based wilcard NameTest) * Fixed bug 955135 (err:XQDY0044 not caught by try-catch expressions) - * Fixed bug #986075 (encountering flwor expr with no clauses; due to common - subexression being formed when inlining var in if-then-else expression) + * Fixed bug #986075 (encountering flwor expr with no clauses; due to common subexression being formed when inlining var in if-then-else expression) * Fixed bug #967864 (var substitution did not update theFreeVars property) * Fixed bug #891650 (context size var not always declared within path expr) * Fixed bug #948879 (--uri-path doesn't work with fetch:content()) @@ -36,17 +37,14 @@ * Fixed bug #988412 (date:current-dateTime daylight saving) * Fixed bug #912586, #912593 and #912722 (assertion failures with lax validation) * Fixed bug #921458 (file:read-text-lines() blocking) - * Fixed bug #981405 (do not hoist expr containing try-catch variables out of the - associated try-catch expression) - * Fixed bug #947627 (throw XQST0099 if more than one declarations of context item - type in same module) + * Fixed bug #981405 (do not hoist expr containing try-catch variables out of the associated try-catch expression) + * Fixed bug #947627 (throw XQST0099 if more than one declarations of context item type in same module) * Fixed bug #980526 (no-copy rule bug due to global var being set in "distant" udf) * Fixed bug #949910 (has-children may be invoked on all nodes). Internally, zorba::store::Item::getChildren() now returns NULL on node classes without offspring (instead of raising an error). - * Fixed Bug #933490: Error ItemFactoryImpl::createBase64Binary with istream + * Fixed Bug #933490 (Error ItemFactoryImpl::createBase64Binary with istream) * Fixed bug #867112 (Diagnostic Handler was not working on external APIs) * Fixed bug #857842 (Assertion failed with simple content element with comments) - version 2.2 New Features: === modified file 'modules/w3c/xpath_functions.xq' --- modules/w3c/xpath_functions.xq 2012-04-24 12:39:38 +0000 +++ modules/w3c/xpath_functions.xq 2012-05-02 07:34:22 +0000 @@ -522,6 +522,12 @@ declare function fn:parse-xml( $arg as xs:string?, $baseURI as xs:string) as document-node(element(*, xs:untyped)) external; (:~ + : @see for semantics please check <a href="http://www.w3.org/TR/xpath-functions-30/#func-parse-xml-fragment">fn:parse-xml-fragment</a> + :) +declare function fn:parse-xml-fragment( $arg as xs:string?) as document-node(element(*, xs:untyped)) external; + + +(:~ : @see for semantics please check <a href="http://www.w3.org/TR/xpath-functions-30/#func-prefix-from-QName">fn:prefix-from-QName</a> :) declare function fn:prefix-from-QName($arg as xs:QName?) as xs:NCName? external; @@ -864,6 +870,11 @@ (:~ : @see for semantics please check <a href="http://www.w3.org/TR/xpath-functions-30/#func-has-children">fn:has-children</a> :) +declare function fn:has-children() as xs:boolean external; + +(:~ + : @see for semantics please check <a href="http://www.w3.org/TR/xpath-functions-30/#func-has-children">fn:has-children</a> + :) declare function fn:has-children($node as node()?) as xs:boolean external; (:~ @@ -923,12 +934,17 @@ (:~ : @see for semantics please check <a href="http://www.w3.org/TR/xpath-functions-30/#func-namespace-uri">fn:namespace-uri</a> - :) + :) declare function fn:namespace-uri($arg as node()?) as xs:anyURI external; (:~ : @see for semantics please check <a href="http://www.w3.org/TR/xpath-functions-30/#func-nilled">fn:nilled</a> :) +declare function fn:nilled() as xs:boolean external; + +(:~ + : @see for semantics please check <a href="http://www.w3.org/TR/xpath-functions-30/#func-nilled">fn:nilled</a> + :) declare function fn:nilled($arg as node()?) as xs:boolean? external; (:~ === modified file 'src/compiler/translator/translator.cpp' --- src/compiler/translator/translator.cpp 2012-05-01 21:21:04 +0000 +++ src/compiler/translator/translator.cpp 2012-05-02 07:34:22 +0000 @@ -694,6 +694,10 @@ xquery_fns_def_dot.set(FunctionConsts::FN_DATA_0); xquery_fns_def_dot.set(FunctionConsts::FN_DOCUMENT_URI_0); xquery_fns_def_dot.set(FunctionConsts::FN_NODE_NAME_0); + xquery_fns_def_dot.set(FunctionConsts::FN_NILLED_0); + xquery_fns_def_dot.set(FunctionConsts::FN_HAS_CHILDREN_0); + xquery_fns_def_dot.set(FunctionConsts::FN_PATH_0); + op_concatenate = GET_BUILTIN_FUNCTION(OP_CONCATENATE_N); assert(op_concatenate != NULL); === modified file 'src/functions/pregenerated/func_accessors.cpp' --- src/functions/pregenerated/func_accessors.cpp 2012-04-24 12:39:38 +0000 +++ src/functions/pregenerated/func_accessors.cpp 2012-05-02 07:34:22 +0000 @@ -50,6 +50,15 @@ return new NodeNameIterator(sctx, loc, argv); } +PlanIter_t fn_nilled_3_0::codegen( + CompilerCB*, + static_context* sctx, + const QueryLoc& loc, + std::vector<PlanIter_t>& argv, + expr& ann) const +{ + return new NilledIterator(sctx, loc, argv); +} PlanIter_t fn_nilled::codegen( CompilerCB*, static_context* sctx, @@ -138,6 +147,17 @@ { + DECL_WITH_KIND(sctx, fn_nilled_3_0, + (createQName("http://www.w3.org/2005/xpath-functions","","nilled"), + GENV_TYPESYSTEM.BOOLEAN_TYPE_ONE), + FunctionConsts::FN_NILLED_0); + + } + + + { + + DECL_WITH_KIND(sctx, fn_nilled, (createQName("http://www.w3.org/2005/xpath-functions","","nilled"), GENV_TYPESYSTEM.ANY_NODE_TYPE_QUESTION, === modified file 'src/functions/pregenerated/func_accessors.h' --- src/functions/pregenerated/func_accessors.h 2012-04-24 12:39:38 +0000 +++ src/functions/pregenerated/func_accessors.h 2012-05-02 07:34:22 +0000 @@ -72,6 +72,22 @@ //fn:nilled +class fn_nilled_3_0 : public function +{ +public: + fn_nilled_3_0(const signature& sig, FunctionConsts::FunctionKind kind) + : + function(sig, kind) + { +theXQueryVersion = StaticContextConsts::xquery_version_3_0; + } + + bool mustCopyInputNodes(expr* fo, csize producer) const { return true; } + + CODEGEN_DECL(); +}; + +//fn:nilled class fn_nilled : public function { public: @@ -82,7 +98,7 @@ } - bool mustCopyInputNodes(expr* fo, csize producer) const { return false; } + bool mustCopyInputNodes(expr* fo, csize producer) const { return true; } CODEGEN_DECL(); }; === modified file 'src/functions/pregenerated/func_nodes.cpp' --- src/functions/pregenerated/func_nodes.cpp 2012-04-24 12:39:38 +0000 +++ src/functions/pregenerated/func_nodes.cpp 2012-05-02 07:34:22 +0000 @@ -231,6 +231,16 @@ return new LeastCommonAncestor(sctx, loc, argv); } +PlanIter_t fn_path_3_0::codegen( + CompilerCB*, + static_context* sctx, + const QueryLoc& loc, + std::vector<PlanIter_t>& argv, + expr& ann) const +{ + return new FnPathIterator(sctx, loc, argv); +} + void populate_context_nodes(static_context* sctx) { { @@ -356,6 +366,17 @@ DECL_WITH_KIND(sctx, fn_has_children_3_0, (createQName("http://www.w3.org/2005/xpath-functions","","has-children"), + GENV_TYPESYSTEM.BOOLEAN_TYPE_ONE), + FunctionConsts::FN_HAS_CHILDREN_0); + + } + + + { + + + DECL_WITH_KIND(sctx, fn_has_children_3_0, + (createQName("http://www.w3.org/2005/xpath-functions","","has-children"), GENV_TYPESYSTEM.ANY_NODE_TYPE_QUESTION, GENV_TYPESYSTEM.BOOLEAN_TYPE_ONE), FunctionConsts::FN_HAS_CHILDREN_1); @@ -538,6 +559,29 @@ } + + { + + + DECL_WITH_KIND(sctx, fn_path_3_0, + (createQName("http://www.w3.org/2005/xpath-functions","","path"), + GENV_TYPESYSTEM.STRING_TYPE_QUESTION), + FunctionConsts::FN_PATH_0); + + } + + + { + + + DECL_WITH_KIND(sctx, fn_path_3_0, + (createQName("http://www.w3.org/2005/xpath-functions","","path"), + GENV_TYPESYSTEM.ANY_NODE_TYPE_QUESTION, + GENV_TYPESYSTEM.STRING_TYPE_QUESTION), + FunctionConsts::FN_PATH_1); + + } + } === modified file 'src/functions/pregenerated/func_nodes.h' --- src/functions/pregenerated/func_nodes.h 2012-04-24 12:39:38 +0000 +++ src/functions/pregenerated/func_nodes.h 2012-05-02 07:34:22 +0000 @@ -372,6 +372,21 @@ }; +//fn:path +class fn_path_3_0 : public function +{ +public: + fn_path_3_0(const signature& sig, FunctionConsts::FunctionKind kind) + : + function(sig, kind) + { +theXQueryVersion = StaticContextConsts::xquery_version_3_0; + } + + CODEGEN_DECL(); +}; + + } //namespace zorba === modified file 'src/functions/pregenerated/func_parse_fragment.cpp' --- src/functions/pregenerated/func_parse_fragment.cpp 2012-04-24 12:39:38 +0000 +++ src/functions/pregenerated/func_parse_fragment.cpp 2012-05-02 07:34:22 +0000 @@ -38,7 +38,7 @@ std::vector<PlanIter_t>& argv, expr& ann) const { - return new FnParseXmlFragmentIterator(sctx, loc, argv); + return new FnZorbaParseXmlFragmentIterator(sctx, loc, argv); } void populate_context_parse_fragment(static_context* sctx) === modified file 'src/functions/pregenerated/function_enum.h' --- src/functions/pregenerated/function_enum.h 2012-04-26 13:25:13 +0000 +++ src/functions/pregenerated/function_enum.h 2012-05-02 07:34:22 +0000 @@ -22,6 +22,7 @@ // ****************************************** FN_NODE_NAME_0, FN_NODE_NAME_1, + FN_NILLED_0, FN_NILLED_1, FN_STRING_0, FN_STRING_1, @@ -251,6 +252,7 @@ FN_LANG_2, FN_NUMBER_0, FN_NUMBER_1, + FN_HAS_CHILDREN_0, FN_HAS_CHILDREN_1, FN_INNERMOST_1, FN_OUTERMOST_1, @@ -266,6 +268,8 @@ FN_ZORBA_NODE_PRECEDING_SIBLING_OF_2, FN_ZORBA_NODE_LEVEL_1, FN_ZORBA_NODE_LEAST_COMMON_ANCESTOR_2, + FN_PATH_0, + FN_PATH_1, FN_ABS_1, FN_CEILING_1, FN_FLOOR_1, === modified file 'src/runtime/accessors/accessors_impl.cpp' --- src/runtime/accessors/accessors_impl.cpp 2012-04-24 12:39:38 +0000 +++ src/runtime/accessors/accessors_impl.cpp 2012-05-02 07:34:22 +0000 @@ -79,8 +79,7 @@ if (consumeNext(inNode, theChildren[0].getp(), planState)) { if (inNode->isNode()) { - result = inNode->getNilled(); - STACK_PUSH(result != NULL, state); + STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, inNode->getNilled() != NULL), state); } else throw XQUERY_EXCEPTION( err::XPTY0004, === modified file 'src/runtime/collections/collections_impl.cpp' --- src/runtime/collections/collections_impl.cpp 2012-04-24 12:39:38 +0000 +++ src/runtime/collections/collections_impl.cpp 2012-05-02 07:34:22 +0000 @@ -2504,122 +2504,122 @@ /******************************************************************************* 14.8.5 fn:uri-collection ********************************************************************************/ - FnURICollectionIteratorState::~FnURICollectionIteratorState() - { - if(theIterator != NULL) - { - if(theIteratorOpened) - { - theIterator->close(); - theIteratorOpened = false; - } - theIterator = NULL; - } - } - - void FnURICollectionIteratorState::init(PlanState& planState) - { - PlanIteratorState::init(planState); - theIterator = NULL; - } - - void FnURICollectionIteratorState::reset(PlanState& planState) - { - PlanIteratorState::reset(planState); - - if(theIterator != NULL) - { - if(theIteratorOpened) - { - theIterator->close(); - theIteratorOpened = false; - } - theIterator = NULL; - } - } - - bool FnURICollectionIterator::nextImpl(store::Item_t& result, PlanState& planState) const - { - store::Item_t lURI, resolvedURIItem, lIte; - store::Collection_t coll; - std::auto_ptr<internal::Resource> lResource; - internal::CollectionResource* lCollResource; - zstring resolvedURIString; - zstring lErrorMessage; - zstring docuri; - - FnURICollectionIteratorState* state; - DEFAULT_STACK_INIT(FnURICollectionIteratorState, state, planState); - - if(theChildren.size() == 1 && - consumeNext(lURI, theChildren[0].getp(),planState)) - { - try - { - resolvedURIString= theSctx->resolve_relative_uri(lURI->getStringValue()); - } - catch (ZorbaException const&) - { - throw XQUERY_EXCEPTION( - err::FODC0004, - ERROR_PARAMS(lURI->getStringValue(), ZED( BadAnyURI ) ), - ERROR_LOC( loc ) - ); - } - } - else - { - resolvedURIItem = planState.theGlobalDynCtx->get_default_collection(); - - if ( NULL == resolvedURIItem ) - throw XQUERY_EXCEPTION( - err::FODC0002, - ERROR_PARAMS( ZED( DefaultCollection), ZED( NotDefInDynamicCtx ) ), - ERROR_LOC( loc ) - ); - - resolvedURIString = theSctx->resolve_relative_uri(resolvedURIItem->getStringValue()); - } - - lResource = theSctx->resolve_uri(resolvedURIString, - internal::EntityData::COLLECTION, - lErrorMessage); - - lCollResource = dynamic_cast<internal::CollectionResource*>(lResource.get()); - - if( lCollResource == 0 || !(coll = lCollResource->getCollection()) ) - { - throw XQUERY_EXCEPTION( - err::FODC0002, - ERROR_PARAMS( resolvedURIString, lErrorMessage ), - ERROR_LOC( loc ) - ); - } - - // return collection nodes - state->theIterator = coll->getIterator(); - ZORBA_ASSERT(state->theIterator != NULL); - state->theIterator->open(); - state->theIteratorOpened = true; - - //return the DocumentURI of the Collection - while(state->theIterator->next(lIte)) - { - lIte->getDocumentURI(docuri); - if(!docuri.empty()) - { - STACK_PUSH(GENV_ITEMFACTORY->createAnyURI(result, docuri), state); - } - } - - //close iterator - state->theIterator->close(); - state->theIteratorOpened = false; - - STACK_PUSH(false, state); - STACK_END(state); - - } +FnURICollectionIteratorState::~FnURICollectionIteratorState() +{ + if(theIterator != NULL) + { + if(theIteratorOpened) + { + theIterator->close(); + theIteratorOpened = false; + } + theIterator = NULL; + } +} + +void FnURICollectionIteratorState::init(PlanState& planState) +{ + PlanIteratorState::init(planState); + theIterator = NULL; +} + +void FnURICollectionIteratorState::reset(PlanState& planState) +{ + PlanIteratorState::reset(planState); + + if(theIterator != NULL) + { + if(theIteratorOpened) + { + theIterator->close(); + theIteratorOpened = false; + } + theIterator = NULL; + } +} + +bool FnURICollectionIterator::nextImpl(store::Item_t& result, PlanState& planState) const +{ + store::Item_t lURI, resolvedURIItem, lIte; + store::Collection_t coll; + std::auto_ptr<internal::Resource> lResource; + internal::CollectionResource* lCollResource; + zstring resolvedURIString; + zstring lErrorMessage; + zstring docuri; + + FnURICollectionIteratorState* state; + DEFAULT_STACK_INIT(FnURICollectionIteratorState, state, planState); + + if(theChildren.size() == 1 && + consumeNext(lURI, theChildren[0].getp(),planState)) + { + try + { + resolvedURIString= theSctx->resolve_relative_uri(lURI->getStringValue()); + } + catch (ZorbaException const&) + { + throw XQUERY_EXCEPTION( + err::FODC0004, + ERROR_PARAMS(lURI->getStringValue(), ZED( BadAnyURI ) ), + ERROR_LOC( loc ) + ); + } + } + else + { + resolvedURIItem = planState.theGlobalDynCtx->get_default_collection(); + + if ( NULL == resolvedURIItem ) + throw XQUERY_EXCEPTION( + err::FODC0002, + ERROR_PARAMS( ZED( DefaultCollection), ZED( NotDefInDynamicCtx ) ), + ERROR_LOC( loc ) + ); + + resolvedURIString = theSctx->resolve_relative_uri(resolvedURIItem->getStringValue()); + } + + lResource = theSctx->resolve_uri(resolvedURIString, + internal::EntityData::COLLECTION, + lErrorMessage); + + lCollResource = dynamic_cast<internal::CollectionResource*>(lResource.get()); + + if( lCollResource == 0 || !(coll = lCollResource->getCollection()) ) + { + throw XQUERY_EXCEPTION( + err::FODC0002, + ERROR_PARAMS( resolvedURIString, lErrorMessage ), + ERROR_LOC( loc ) + ); + } + + // return collection nodes + state->theIterator = coll->getIterator(); + ZORBA_ASSERT(state->theIterator != NULL); + state->theIterator->open(); + state->theIteratorOpened = true; + + //return the DocumentURI of the Collection + while(state->theIterator->next(lIte)) + { + lIte->getDocumentURI(docuri); + if(!docuri.empty()) + { + STACK_PUSH(GENV_ITEMFACTORY->createAnyURI(result, docuri), state); + } + } + + //close iterator + state->theIterator->close(); + state->theIteratorOpened = false; + + STACK_PUSH(false, state); + STACK_END(state); + +} } // namespace zorba === modified file 'src/runtime/collections/pregenerated/collections.h' --- src/runtime/collections/pregenerated/collections.h 2012-04-24 12:39:38 +0000 +++ src/runtime/collections/pregenerated/collections.h 2012-05-02 07:34:22 +0000 @@ -1469,9 +1469,9 @@ /** * - * Returns a sequence of xs:anyURI values representing the document URIs of the - * documents in a collection. - * + * Returns a sequence of xs:anyURI values representing the document URIs of the + * documents in a collection. + * * Author: Zorba Team */ class FnURICollectionIteratorState : public PlanIteratorState === modified file 'src/runtime/nodes/nodes_impl.cpp' --- src/runtime/nodes/nodes_impl.cpp 2012-04-24 12:39:38 +0000 +++ src/runtime/nodes/nodes_impl.cpp 2012-05-02 07:34:22 +0000 @@ -628,5 +628,122 @@ STACK_END (state); } +/******************************************************************************* +********************************************************************************/ +int getNodePosition(store::Item_t aNode) +{ + int count = 1; + store::Iterator_t lIterator = aNode->getParent()->getChildren(); + store::Item_t lItem; + lIterator->open(); + while(lIterator->next(lItem)) + { + if(lItem->getNodeKind() == aNode->getNodeKind()) + if(lItem->equals(aNode)) + break; + else + count++; + } + lIterator->close(); + return count; +} + +bool FnPathIterator::nextImpl(store::Item_t& result, PlanState& planState) const +{ + store::Item_t inNode; + store::Item_t nodeName; + store::NsBindings nsBindings; + zstring path; + zstring temp; + zstring zNamespace; + zstring zLocalName; + zstring zPosition; + bool rootIsDocument = false; + + PlanIteratorState* state; + DEFAULT_STACK_INIT(PlanIteratorState, state, planState); + + if (consumeNext(inNode, theChildren[0], planState)); + { + do + { + switch (inNode->getNodeKind()) + { + case store::StoreConsts::documentNode: + temp = path; + path = "/"; + path += temp; + rootIsDocument = true; + break; + case store::StoreConsts::elementNode: + nodeName = inNode->getNodeName(); + zNamespace = nodeName->getNamespace(); + zLocalName = nodeName->getLocalName(); + zPosition = ztd::to_string(getNodePosition(inNode)); + temp = path; + path = "\""+zNamespace+"\":"+zLocalName+"["+zPosition.c_str()+"]"; + path += temp; + break; + case store::StoreConsts::attributeNode: + nodeName = inNode->getNodeName(); + zNamespace =nodeName->getNamespace(); + zLocalName = nodeName->getLocalName(); + if(zNamespace != "") + { + temp = path; + path = "@\""+zNamespace+"\":"+zLocalName; + path += temp; + } + else + { + temp = path; + path = "@"+zLocalName; + path += temp; + } + break; + case store::StoreConsts::textNode: + zPosition = ztd::to_string(getNodePosition(inNode)); + temp = path; + path = "text()["+zPosition+"]"; + path += temp; + break; + case store::StoreConsts::commentNode: + zPosition = ztd::to_string(getNodePosition(inNode)); + temp = path; + path = "comment()["+zPosition+"]"; + path += temp; + break; + default: + if(inNode->isProcessingInstruction()) + { + nodeName = inNode->getNodeName(); + zLocalName = nodeName->getLocalName(); + zPosition = ztd::to_string(getNodePosition(inNode)); + temp = path; + path = "processing-instruction("+zLocalName+")["+zPosition+"]"; + path += temp; + } + break; + } + inNode = inNode->getParent(); + + if(inNode && inNode->getNodeKind() != store::StoreConsts::documentNode) + { + temp = path; + path = "/"; + path += temp; + } + + } while (inNode); + + if(rootIsDocument) + STACK_PUSH(GENV_ITEMFACTORY->createString(result, path), state); + else + throw XQUERY_EXCEPTION(err::FODC0001, ERROR_PARAMS("fn:path"), ERROR_LOC(loc)); + } + + STACK_END (state); +} + } // namespace zorba /* vim:set et sw=2 ts=2: */ === modified file 'src/runtime/nodes/pregenerated/nodes.cpp' --- src/runtime/nodes/pregenerated/nodes.cpp 2012-04-24 12:39:38 +0000 +++ src/runtime/nodes/pregenerated/nodes.cpp 2012-05-02 07:34:22 +0000 @@ -474,6 +474,28 @@ // </LeastCommonAncestor> +// <FnPathIterator> +FnPathIterator::class_factory<FnPathIterator> +FnPathIterator::g_class_factory; + + +void FnPathIterator::accept(PlanIterVisitor& v) const { + v.beginVisit(*this); + + std::vector<PlanIter_t>::const_iterator lIter = theChildren.begin(); + std::vector<PlanIter_t>::const_iterator lEnd = theChildren.end(); + for ( ; lIter != lEnd; ++lIter ){ + (*lIter)->accept(v); + } + + v.endVisit(*this); +} + +FnPathIterator::~FnPathIterator() {} + +// </FnPathIterator> + + } === modified file 'src/runtime/nodes/pregenerated/nodes.h' --- src/runtime/nodes/pregenerated/nodes.h 2012-04-24 12:39:38 +0000 +++ src/runtime/nodes/pregenerated/nodes.h 2012-05-02 07:34:22 +0000 @@ -720,6 +720,40 @@ }; +/** + * + * Author: Zorba Team + */ +class FnPathIterator : public NaryBaseIterator<FnPathIterator, PlanIteratorState> +{ +public: + SERIALIZABLE_CLASS(FnPathIterator); + + SERIALIZABLE_CLASS_CONSTRUCTOR2T(FnPathIterator, + NaryBaseIterator<FnPathIterator, PlanIteratorState>); + + void serialize( ::zorba::serialization::Archiver& ar) + { + serialize_baseclass(ar, + (NaryBaseIterator<FnPathIterator, PlanIteratorState>*)this); + } + + FnPathIterator( + static_context* sctx, + const QueryLoc& loc, + std::vector<PlanIter_t>& children) + : + NaryBaseIterator<FnPathIterator, PlanIteratorState>(sctx, loc, children) + {} + + virtual ~FnPathIterator(); + + void accept(PlanIterVisitor& v) const; + + bool nextImpl(store::Item_t& result, PlanState& aPlanState) const; +}; + + } #endif /* === modified file 'src/runtime/parsing_and_serializing/parse_fragment_impl.cpp' --- src/runtime/parsing_and_serializing/parse_fragment_impl.cpp 2012-04-24 12:39:38 +0000 +++ src/runtime/parsing_and_serializing/parse_fragment_impl.cpp 2012-05-02 07:34:22 +0000 @@ -170,11 +170,7 @@ } } -/******************************************************************************* - -********************************************************************************/ - -void FnParseXmlFragmentIteratorState::reset(PlanState& planState) +void FnZorbaParseXmlFragmentIteratorState::reset(PlanState& planState) { PlanIteratorState::reset(planState); theFragmentStream.reset(); @@ -184,20 +180,15 @@ docUri = ""; } - -/******************************************************************************* - -********************************************************************************/ - -bool FnParseXmlFragmentIterator::nextImpl(store::Item_t& result, PlanState& planState) const +bool FnZorbaParseXmlFragmentIterator::nextImpl(store::Item_t& result, PlanState& planState) const { store::Store& lStore = GENV.getStore(); zstring docString; store::Item_t tempItem; bool validated = true; - FnParseXmlFragmentIteratorState* state; - DEFAULT_STACK_INIT(FnParseXmlFragmentIteratorState, state, planState); + FnZorbaParseXmlFragmentIteratorState* state; + DEFAULT_STACK_INIT(FnZorbaParseXmlFragmentIteratorState, state, planState); if (consumeNext(result, theChildren[0].getp(), planState)) { @@ -311,5 +302,66 @@ } +/******************************************************************************* + 14.9.2 fn:parse-xml-fragment +********************************************************************************/ +/* +bool FnParseXmlFragmentIterator::nextImpl(store::Item_t& result, PlanState& planState) const +{ + zstring docString; + + FnParseXmlFragmentIteratorState* state; + DEFAULT_STACK_INIT(FnParseXmlFragmentIteratorState, state, planState); + + if (consumeNext(result, theChildren[0].getp(), planState)) + { + if (result->isStreamable()) + { + state->theFragmentStream.theStream = &result->getStream(); + } + else + { + result->getStringValue2(docString); + state->theFragmentStream.theIss = new std::istringstream(docString.c_str()); + state->theFragmentStream.theStream = state->theFragmentStream.theIss; + } + + state->theProperties.setBaseUri(theSctx->get_base_uri()); + state->baseUri = state->theProperties.getBaseUri(); + + state->theProperties.setParseExternalParsedEntity(true); + + while ( ! state->theFragmentStream.stream_is_consumed() ) + { + try { + state->theProperties.setStoreDocument(false); + result = GENV.getStore().loadDocument(state->baseUri, state->docUri, state->theFragmentStream, state->theProperties); + } catch (ZorbaException const& e) { + if( ! state->theProperties.getNoError()) + throw XQUERY_EXCEPTION(err::FODC0006, ERROR_PARAMS("fn:parse-xml-fragment()", e.what() ), ERROR_LOC(loc)); + else + result = NULL; + } + + if (result == NULL) + continue; + + STACK_PUSH(true, state); + } // while + } // if + + STACK_END(state) +} + +void FnParseXmlFragmentIteratorState::reset(PlanState& planState) +{ + PlanIteratorState::reset(planState); + theFragmentStream.reset(); + theProperties.reset(); + theProperties.setStoreDocument(false); + baseUri = ""; + docUri = ""; +} +*/ } /* namespace zorba */ === modified file 'src/runtime/parsing_and_serializing/parsing_and_serializing_impl.cpp' --- src/runtime/parsing_and_serializing/parsing_and_serializing_impl.cpp 2012-04-24 12:39:38 +0000 +++ src/runtime/parsing_and_serializing/parsing_and_serializing_impl.cpp 2012-05-02 07:34:22 +0000 @@ -118,7 +118,6 @@ STACK_END (state); } - /******************************************************************************* 14.9.2 fn:serialize ********************************************************************************/ === modified file 'src/runtime/parsing_and_serializing/pregenerated/parse_fragment.cpp' --- src/runtime/parsing_and_serializing/pregenerated/parse_fragment.cpp 2012-04-24 12:39:38 +0000 +++ src/runtime/parsing_and_serializing/pregenerated/parse_fragment.cpp 2012-05-02 07:34:22 +0000 @@ -32,12 +32,12 @@ namespace zorba { -// <FnParseXmlFragmentIterator> -FnParseXmlFragmentIterator::class_factory<FnParseXmlFragmentIterator> -FnParseXmlFragmentIterator::g_class_factory; - - -void FnParseXmlFragmentIterator::accept(PlanIterVisitor& v) const { +// <FnZorbaParseXmlFragmentIterator> +FnZorbaParseXmlFragmentIterator::class_factory<FnZorbaParseXmlFragmentIterator> +FnZorbaParseXmlFragmentIterator::g_class_factory; + + +void FnZorbaParseXmlFragmentIterator::accept(PlanIterVisitor& v) const { v.beginVisit(*this); std::vector<PlanIter_t>::const_iterator lIter = theChildren.begin(); @@ -49,17 +49,17 @@ v.endVisit(*this); } -FnParseXmlFragmentIterator::~FnParseXmlFragmentIterator() {} - -FnParseXmlFragmentIteratorState::FnParseXmlFragmentIteratorState() {} - -FnParseXmlFragmentIteratorState::~FnParseXmlFragmentIteratorState() {} - - -void FnParseXmlFragmentIteratorState::init(PlanState& planState) { +FnZorbaParseXmlFragmentIterator::~FnZorbaParseXmlFragmentIterator() {} + +FnZorbaParseXmlFragmentIteratorState::FnZorbaParseXmlFragmentIteratorState() {} + +FnZorbaParseXmlFragmentIteratorState::~FnZorbaParseXmlFragmentIteratorState() {} + + +void FnZorbaParseXmlFragmentIteratorState::init(PlanState& planState) { PlanIteratorState::init(planState); } -// </FnParseXmlFragmentIterator> +// </FnZorbaParseXmlFragmentIterator> === modified file 'src/runtime/parsing_and_serializing/pregenerated/parse_fragment.h' --- src/runtime/parsing_and_serializing/pregenerated/parse_fragment.h 2012-04-24 12:39:38 +0000 +++ src/runtime/parsing_and_serializing/pregenerated/parse_fragment.h 2012-05-02 07:34:22 +0000 @@ -39,7 +39,7 @@ * fn-zorba-xml:parse * Author: Zorba Team */ -class FnParseXmlFragmentIteratorState : public PlanIteratorState +class FnZorbaParseXmlFragmentIteratorState : public PlanIteratorState { public: FragmentIStream theFragmentStream; //the input fragment @@ -47,37 +47,37 @@ zstring baseUri; // zstring docUri; // - FnParseXmlFragmentIteratorState(); + FnZorbaParseXmlFragmentIteratorState(); - ~FnParseXmlFragmentIteratorState(); + ~FnZorbaParseXmlFragmentIteratorState(); void init(PlanState&); void reset(PlanState&); }; -class FnParseXmlFragmentIterator : public NaryBaseIterator<FnParseXmlFragmentIterator, FnParseXmlFragmentIteratorState> +class FnZorbaParseXmlFragmentIterator : public NaryBaseIterator<FnZorbaParseXmlFragmentIterator, FnZorbaParseXmlFragmentIteratorState> { public: - SERIALIZABLE_CLASS(FnParseXmlFragmentIterator); + SERIALIZABLE_CLASS(FnZorbaParseXmlFragmentIterator); - SERIALIZABLE_CLASS_CONSTRUCTOR2T(FnParseXmlFragmentIterator, - NaryBaseIterator<FnParseXmlFragmentIterator, FnParseXmlFragmentIteratorState>); + SERIALIZABLE_CLASS_CONSTRUCTOR2T(FnZorbaParseXmlFragmentIterator, + NaryBaseIterator<FnZorbaParseXmlFragmentIterator, FnZorbaParseXmlFragmentIteratorState>); void serialize( ::zorba::serialization::Archiver& ar) { serialize_baseclass(ar, - (NaryBaseIterator<FnParseXmlFragmentIterator, FnParseXmlFragmentIteratorState>*)this); + (NaryBaseIterator<FnZorbaParseXmlFragmentIterator, FnZorbaParseXmlFragmentIteratorState>*)this); } - FnParseXmlFragmentIterator( + FnZorbaParseXmlFragmentIterator( static_context* sctx, const QueryLoc& loc, std::vector<PlanIter_t>& children) : - NaryBaseIterator<FnParseXmlFragmentIterator, FnParseXmlFragmentIteratorState>(sctx, loc, children) + NaryBaseIterator<FnZorbaParseXmlFragmentIterator, FnZorbaParseXmlFragmentIteratorState>(sctx, loc, children) {} - virtual ~FnParseXmlFragmentIterator(); + virtual ~FnZorbaParseXmlFragmentIterator(); void accept(PlanIterVisitor& v) const; === modified file 'src/runtime/spec/accessors/accessors.xml' --- src/runtime/spec/accessors/accessors.xml 2012-04-24 12:39:38 +0000 +++ src/runtime/spec/accessors/accessors.xml 2012-05-02 07:34:22 +0000 @@ -62,13 +62,16 @@ <zorba:function> + <zorba:signature localname="nilled" prefix="fn" version="3.0"> + <zorba:output>xs:boolean</zorba:output> + </zorba:signature> <zorba:signature localname="nilled" prefix="fn"> <zorba:param>node()?</zorba:param> <zorba:output>xs:boolean?</zorba:output> </zorba:signature> - + <zorba:methods> - <zorba:mustCopyInputNodes value="false"/> + <zorba:mustCopyInputNodes value="true"/> </zorba:methods> </zorba:function> === modified file 'src/runtime/spec/collections/collections.xml' --- src/runtime/spec/collections/collections.xml 2012-04-24 12:39:38 +0000 +++ src/runtime/spec/collections/collections.xml 2012-05-02 07:34:22 +0000 @@ -1324,32 +1324,32 @@ 14.8.5 fn:uri-collection ********************************************************************************/ --> - <zorba:iterator name="FnURICollectionIterator"> - <zorba:description author="Zorba Team"> - Returns a sequence of xs:anyURI values representing the document URIs of the - documents in a collection. - </zorba:description> - - <zorba:function> - - <zorba:signature localname="uri-collection" prefix="fn" version="3.0"> - <zorba:output>xs:anyURI*</zorba:output> - </zorba:signature> - - <zorba:signature localname="uri-collection" prefix="fn" version="3.0"> - <zorba:param>xs:string?</zorba:param> - <zorba:output>xs:anyURI*</zorba:output> - </zorba:signature> - - </zorba:function> - - <zorba:state generateInit="false" generateReset="false" generateDestructor="false"> - <zorba:member type="store::Iterator_t" name="theIterator" - brief="the current iterator"/> - <zorba:member type="bool" name="theIteratorOpened" defaultValue="false" - brief="flag indicating whether theIterator was opened"/> - </zorba:state> +<zorba:iterator name="FnURICollectionIterator"> + <zorba:description author="Zorba Team"> + Returns a sequence of xs:anyURI values representing the document URIs of the + documents in a collection. + </zorba:description> + + <zorba:function> + + <zorba:signature localname="uri-collection" prefix="fn" version="3.0"> + <zorba:output>xs:anyURI*</zorba:output> + </zorba:signature> + + <zorba:signature localname="uri-collection" prefix="fn" version="3.0"> + <zorba:param>xs:string?</zorba:param> + <zorba:output>xs:anyURI*</zorba:output> + </zorba:signature> - </zorba:iterator> + </zorba:function> + + <zorba:state generateInit="false" generateReset="false" generateDestructor="false"> + <zorba:member type="store::Iterator_t" name="theIterator" + brief="the current iterator"/> + <zorba:member type="bool" name="theIteratorOpened" defaultValue="false" + brief="flag indicating whether theIterator was opened"/> + </zorba:state> + +</zorba:iterator> </zorba:iterators> === modified file 'src/runtime/spec/nodes/nodes.xml' --- src/runtime/spec/nodes/nodes.xml 2012-04-24 12:39:38 +0000 +++ src/runtime/spec/nodes/nodes.xml 2012-05-02 07:34:22 +0000 @@ -186,6 +186,11 @@ <zorba:description author="Zorba Team">fn:has-children</zorba:description> <zorba:function> + + <zorba:signature localname="has-children" prefix="fn" version="3.0"> + <zorba:output>xs:boolean</zorba:output> + </zorba:signature> + <zorba:signature localname="has-children" prefix="fn" version="3.0"> <zorba:param>node()?</zorba:param> <zorba:output>xs:boolean</zorba:output> @@ -515,4 +520,26 @@ </zorba:iterator> +<!-- +/******************************************************************************* +********************************************************************************/ +--> +<zorba:iterator name="FnPathIterator"> + + <zorba:description author="Zorba Team"></zorba:description> + + <zorba:function> + <zorba:signature localname="path" prefix="fn" version="3.0"> + <zorba:output>xs:string?</zorba:output> + </zorba:signature> + + <zorba:signature localname="path" prefix="fn" version="3.0"> + <zorba:param>node()?</zorba:param> + <zorba:output>xs:string?</zorba:output> + </zorba:signature> + + </zorba:function> + +</zorba:iterator> + </zorba:iterators> === modified file 'src/runtime/spec/parsing_and_serializing/parse_fragment.xml' --- src/runtime/spec/parsing_and_serializing/parse_fragment.xml 2012-04-24 12:39:38 +0000 +++ src/runtime/spec/parsing_and_serializing/parse_fragment.xml 2012-05-02 07:34:22 +0000 @@ -22,7 +22,7 @@ * 14.9.1 parse-xml:parse ********************************************************************************/ --> - <zorba:iterator name="FnParseXmlFragmentIterator"> + <zorba:iterator name="FnZorbaParseXmlFragmentIterator"> <zorba:description author="Zorba Team">fn-zorba-xml:parse</zorba:description> @@ -46,6 +46,35 @@ </zorba:state> </zorba:iterator> - - +<!-- +/******************************************************************************* + * 14.9.2 fn:parse-xml-fragment +********************************************************************************/ +--> + +<!-- +<zorba:iterator name="FnParseXmlFragmentIterator"> + + <zorba:description author="Zorba Team">fn:parse-xml-fragment</zorba:description> + + <zorba:function> + <zorba:signature localname="parse-xml-fragment" prefix="fn"> + <zorba:param>xs:string?</zorba:param> + <zorba:output>node()*</zorba:output> + </zorba:signature> + + <zorba:methods> + <zorba:accessesDynCtx returnValue="true"/> + </zorba:methods> + </zorba:function> + + <zorba:state generateReset="false"> + <zorba:member type="FragmentIStream" name="theFragmentStream" brief="the input fragment"/> + <zorba:member type="store::LoadProperties" name="theProperties" brief="loader properties"/> + <zorba:member type="zstring" name="baseUri"/> + <zorba:member type="zstring" name="docUri"/> + </zorba:state> + +</zorba:iterator> +--> </zorba:iterators> === modified file 'src/runtime/spec/parsing_and_serializing/parsing_and_serializing.xml' --- src/runtime/spec/parsing_and_serializing/parsing_and_serializing.xml 2012-04-24 12:39:38 +0000 +++ src/runtime/spec/parsing_and_serializing/parsing_and_serializing.xml 2012-05-02 07:34:22 +0000 @@ -43,10 +43,9 @@ </zorba:iterator> - <!-- /******************************************************************************* - * 14.9.2 fn:serialize + * 14.9.3 fn:serialize ********************************************************************************/ --> <zorba:iterator name="FnSerializeIterator"> @@ -79,5 +78,6 @@ </zorba:method> </zorba:iterator> - + + </zorba:iterators> === modified file 'src/runtime/visitors/pregenerated/planiter_visitor.h' --- src/runtime/visitors/pregenerated/planiter_visitor.h 2012-04-27 01:23:43 +0000 +++ src/runtime/visitors/pregenerated/planiter_visitor.h 2012-05-02 07:34:22 +0000 @@ -436,6 +436,8 @@ class LeastCommonAncestor; + class FnPathIterator; + class AbsIterator; class CeilingIterator; @@ -450,7 +452,7 @@ class FormatIntegerIterator; - class FnParseXmlFragmentIterator; + class FnZorbaParseXmlFragmentIterator; class FnParseXmlIterator; @@ -1259,6 +1261,9 @@ virtual void beginVisit ( const LeastCommonAncestor& ) = 0; virtual void endVisit ( const LeastCommonAncestor& ) = 0; + virtual void beginVisit ( const FnPathIterator& ) = 0; + virtual void endVisit ( const FnPathIterator& ) = 0; + virtual void beginVisit ( const AbsIterator& ) = 0; virtual void endVisit ( const AbsIterator& ) = 0; @@ -1280,8 +1285,8 @@ virtual void beginVisit ( const FormatIntegerIterator& ) = 0; virtual void endVisit ( const FormatIntegerIterator& ) = 0; - virtual void beginVisit ( const FnParseXmlFragmentIterator& ) = 0; - virtual void endVisit ( const FnParseXmlFragmentIterator& ) = 0; + virtual void beginVisit ( const FnZorbaParseXmlFragmentIterator& ) = 0; + virtual void endVisit ( const FnZorbaParseXmlFragmentIterator& ) = 0; virtual void beginVisit ( const FnParseXmlIterator& ) = 0; virtual void endVisit ( const FnParseXmlIterator& ) = 0; === modified file 'src/runtime/visitors/pregenerated/printer_visitor.cpp' --- src/runtime/visitors/pregenerated/printer_visitor.cpp 2012-04-24 18:22:23 +0000 +++ src/runtime/visitors/pregenerated/printer_visitor.cpp 2012-05-02 07:34:22 +0000 @@ -2870,6 +2870,20 @@ // </LeastCommonAncestor> +// <FnPathIterator> +void PrinterVisitor::beginVisit ( const FnPathIterator& a) { + thePrinter.startBeginVisit("FnPathIterator", ++theId); + printCommons( &a, theId ); + thePrinter.endBeginVisit( theId ); +} + +void PrinterVisitor::endVisit ( const FnPathIterator& ) { + thePrinter.startEndVisit(); + thePrinter.endEndVisit(); +} +// </FnPathIterator> + + // <AbsIterator> void PrinterVisitor::beginVisit ( const AbsIterator& a) { thePrinter.startBeginVisit("AbsIterator", ++theId); @@ -2968,18 +2982,18 @@ // </FormatIntegerIterator> -// <FnParseXmlFragmentIterator> -void PrinterVisitor::beginVisit ( const FnParseXmlFragmentIterator& a) { - thePrinter.startBeginVisit("FnParseXmlFragmentIterator", ++theId); +// <FnZorbaParseXmlFragmentIterator> +void PrinterVisitor::beginVisit ( const FnZorbaParseXmlFragmentIterator& a) { + thePrinter.startBeginVisit("FnZorbaParseXmlFragmentIterator", ++theId); printCommons( &a, theId ); thePrinter.endBeginVisit( theId ); } -void PrinterVisitor::endVisit ( const FnParseXmlFragmentIterator& ) { +void PrinterVisitor::endVisit ( const FnZorbaParseXmlFragmentIterator& ) { thePrinter.startEndVisit(); thePrinter.endEndVisit(); } -// </FnParseXmlFragmentIterator> +// </FnZorbaParseXmlFragmentIterator> // <FnParseXmlIterator> === modified file 'src/runtime/visitors/pregenerated/printer_visitor.h' --- src/runtime/visitors/pregenerated/printer_visitor.h 2012-04-24 18:22:23 +0000 +++ src/runtime/visitors/pregenerated/printer_visitor.h 2012-05-02 07:34:22 +0000 @@ -663,6 +663,9 @@ void beginVisit( const LeastCommonAncestor& ); void endVisit ( const LeastCommonAncestor& ); + void beginVisit( const FnPathIterator& ); + void endVisit ( const FnPathIterator& ); + void beginVisit( const AbsIterator& ); void endVisit ( const AbsIterator& ); @@ -684,8 +687,8 @@ void beginVisit( const FormatIntegerIterator& ); void endVisit ( const FormatIntegerIterator& ); - void beginVisit( const FnParseXmlFragmentIterator& ); - void endVisit ( const FnParseXmlFragmentIterator& ); + void beginVisit( const FnZorbaParseXmlFragmentIterator& ); + void endVisit ( const FnZorbaParseXmlFragmentIterator& ); void beginVisit( const FnParseXmlIterator& ); void endVisit ( const FnParseXmlIterator& );
-- Mailing list: https://launchpad.net/~zorba-coders Post to : zorba-coders@lists.launchpad.net Unsubscribe : https://launchpad.net/~zorba-coders More help : https://help.launchpad.net/ListHelp