Matthias Brantner has proposed merging lp:~zorba-coders/zorba/feature-node_copy 
into lp:zorba.

Requested reviews:
  Matthias Brantner (matthias-brantner)
  Markos Zaharioudakis (markos-za)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/feature-node_copy/+merge/103890

node:copy function
-- 
https://code.launchpad.net/~zorba-coders/zorba/feature-node_copy/+merge/103890
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2012-04-25 17:16:48 +0000
+++ ChangeLog	2012-04-27 14:41:19 +0000
@@ -12,6 +12,7 @@
   * Add jvm classpath to zorbacmd and to Zorba API. Tracked by #931816
   * Added support for NO_ICU (to not use ICU for unicode processing)
   * Added XQJ support.
+  * Added a node copy function to the node module
 
 Optimization:
 

=== modified file 'modules/com/zorba-xquery/www/modules/node.xq'
--- modules/com/zorba-xquery/www/modules/node.xq	2012-04-24 12:39:38 +0000
+++ modules/com/zorba-xquery/www/modules/node.xq	2012-04-27 14:41:19 +0000
@@ -164,3 +164,16 @@
 declare function node:least-common-ancestor(
   $node1 as node(),
   $node2 as node()) as node()? external;
+
+(:~
+ : Return a deep copy of every given node according to the properties
+ : specified in the static context of the invoking module.
+ :
+ : Please note that a copy of a node is parentless.
+ :
+ : @param $input the node to copy
+ :
+ : @return a deep copy of every node in the input sequence or the empty sequence if
+ :   $input is the empty sequence.
+ :)
+declare function node:copy($input as node()*) as node()* external;

=== modified file 'src/functions/CMakeLists.txt'
--- src/functions/CMakeLists.txt	2012-04-24 12:39:38 +0000
+++ src/functions/CMakeLists.txt	2012-04-27 14:41:19 +0000
@@ -74,6 +74,7 @@
     func_hoist.cpp
     func_index_ddl.cpp
     func_node_sort_distinct.cpp
+    func_nodes_impl.cpp
     func_numerics_impl.cpp
     func_sequences_impl.cpp
     func_strings_impl.cpp

=== added file 'src/functions/func_nodes_impl.cpp'
--- src/functions/func_nodes_impl.cpp	1970-01-01 00:00:00 +0000
+++ src/functions/func_nodes_impl.cpp	2012-04-27 14:41:19 +0000
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2006-2008 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ #include "stdafx.h"
+
+#include <typeinfo>
+
+#include "functions/func_nodes.h"
+
+#include "system/globalenv.h"
+
+#include "compiler/expression/expr.h"
+#include "compiler/expression/fo_expr.h"
+#include "compiler/expression/path_expr.h"
+
+#include "types/typeops.h"
+
+namespace zorba
+{
+
+
+/*******************************************************************************
+
+********************************************************************************/
+xqtref_t fn_zorba_node_copy::getReturnType(const fo_expr* caller) const
+{
+  return caller->get_arg(0)->get_return_type();
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+bool fn_zorba_node_copy::mustCopyInputNodes(expr* fo, csize input) const
+{
+  static_context* lSctx = fo->get_sctx();
+  return lSctx->preserve_mode() == StaticContextConsts::no_preserve_ns;
+}
+
+} /* namespace zorba */
+/* vim:set et sw=2 ts=2: */
+

=== 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-04-27 14:41:19 +0000
@@ -231,6 +231,16 @@
   return new LeastCommonAncestor(sctx, loc, argv);
 }
 
+PlanIter_t fn_zorba_node_copy::codegen(
+  CompilerCB*,
+  static_context* sctx,
+  const QueryLoc& loc,
+  std::vector<PlanIter_t>& argv,
+  expr& ann) const
+{
+  return new NodeCopyIterator(sctx, loc, argv);
+}
+
 void populate_context_nodes(static_context* sctx)
 {
   {
@@ -538,6 +548,18 @@
 
   }
 
+
+  {
+    
+
+    DECL_WITH_KIND(sctx, fn_zorba_node_copy,
+        (createQName("http://www.zorba-xquery.com/modules/node","","copy";), 
+        GENV_TYPESYSTEM.ANY_NODE_TYPE_STAR, 
+        GENV_TYPESYSTEM.ANY_NODE_TYPE_STAR),
+        FunctionConsts::FN_ZORBA_NODE_COPY_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-04-27 14:41:19 +0000
@@ -372,6 +372,25 @@
 };
 
 
+//fn-zorba-node:copy
+class fn_zorba_node_copy : public function
+{
+public:
+  fn_zorba_node_copy(const signature& sig, FunctionConsts::FunctionKind kind)
+    : 
+    function(sig, kind)
+  {
+
+  }
+
+  bool mustCopyInputNodes(expr* fo, csize producer) const;
+
+  xqtref_t getReturnType(const fo_expr* caller) const;
+
+  CODEGEN_DECL();
+};
+
+
 } //namespace zorba
 
 

=== modified file 'src/functions/pregenerated/function_enum.h'
--- src/functions/pregenerated/function_enum.h	2012-04-24 12:39:38 +0000
+++ src/functions/pregenerated/function_enum.h	2012-04-27 14:41:19 +0000
@@ -247,6 +247,7 @@
   FN_ZORBA_NODE_PRECEDING_SIBLING_OF_2,
   FN_ZORBA_NODE_LEVEL_1,
   FN_ZORBA_NODE_LEAST_COMMON_ANCESTOR_2,
+  FN_ZORBA_NODE_COPY_1,
   FN_ABS_1,
   FN_CEILING_1,
   FN_FLOOR_1,

=== 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-04-27 14:41:19 +0000
@@ -19,11 +19,13 @@
 #include "zorbamisc/ns_consts.h"
 
 #include "system/globalenv.h"
+#include "context/static_context.h"
 
 #include "store/api/item.h"
 #include "store/api/iterator.h"
 #include "store/api/item_factory.h"
 #include "store/api/store.h"
+#include "store/api/copymode.h"
 
 #include "util/string_util.h"
 #include "util/uri_util.h"
@@ -628,5 +630,29 @@
   STACK_END (state);
 }
 
+/*******************************************************************************
+********************************************************************************/
+bool
+NodeCopyIterator::nextImpl(store::Item_t& result, PlanState& planState) const
+{
+  store::Item_t lItem;
+  store::CopyMode lCopyMode;
+  lCopyMode.set(true, 
+    theSctx->construction_mode() == StaticContextConsts::cons_preserve,
+    theSctx->preserve_mode() == StaticContextConsts::preserve_ns,
+    theSctx->inherit_mode() == StaticContextConsts::inherit_ns);
+
+  PlanIteratorState *state;
+  DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
+
+  while (consumeNext(lItem, theChildren[0].getp(), planState))
+  {
+    result = lItem->copy(0, lCopyMode);
+    STACK_PUSH(true, state);
+  }
+
+  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-04-27 14:41:19 +0000
@@ -474,6 +474,34 @@
 // </LeastCommonAncestor>
 
 
+// <NodeCopyIterator>
+const char* NodeCopyIterator::class_name_str = "NodeCopyIterator";
+NodeCopyIterator::class_factory<NodeCopyIterator>
+NodeCopyIterator::g_class_factory;
+
+const serialization::ClassVersion 
+NodeCopyIterator::class_versions[] ={{ 1, 0x000905, false}};
+
+const int NodeCopyIterator::class_versions_count =
+sizeof(NodeCopyIterator::class_versions)/sizeof(struct serialization::ClassVersion);
+
+void NodeCopyIterator::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);
+}
+
+NodeCopyIterator::~NodeCopyIterator() {}
+
+// </NodeCopyIterator>
+
+
 
 }
 

=== 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-04-27 14:41:19 +0000
@@ -720,6 +720,40 @@
 };
 
 
+/**
+ * 
+ * Author: Zorba Team
+ */
+class NodeCopyIterator : public NaryBaseIterator<NodeCopyIterator, PlanIteratorState>
+{ 
+public:
+  SERIALIZABLE_CLASS(NodeCopyIterator);
+
+  SERIALIZABLE_CLASS_CONSTRUCTOR2T(NodeCopyIterator,
+    NaryBaseIterator<NodeCopyIterator, PlanIteratorState>);
+
+  void serialize( ::zorba::serialization::Archiver& ar)
+  {
+    serialize_baseclass(ar,
+    (NaryBaseIterator<NodeCopyIterator, PlanIteratorState>*)this);
+  }
+
+  NodeCopyIterator(
+    static_context* sctx,
+    const QueryLoc& loc,
+    std::vector<PlanIter_t>& children)
+    : 
+    NaryBaseIterator<NodeCopyIterator, PlanIteratorState>(sctx, loc, children)
+  {}
+
+  virtual ~NodeCopyIterator();
+
+  void accept(PlanIterVisitor& v) const;
+
+  bool nextImpl(store::Item_t& result, PlanState& aPlanState) const;
+};
+
+
 }
 #endif
 /*

=== 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-04-27 14:41:19 +0000
@@ -515,4 +515,27 @@
 
 </zorba:iterator>
 
+  <!--
+/*******************************************************************************
+********************************************************************************/
+-->
+<zorba:iterator name="NodeCopyIterator">
+
+  <zorba:description author="Zorba Team"></zorba:description>
+
+  <zorba:function>
+    <zorba:signature localname="copy" prefix="fn-zorba-node">
+      <zorba:param>node()*</zorba:param>
+      <zorba:output>node()*</zorba:output>
+    </zorba:signature>
+
+    <zorba:methods>
+      <zorba:mustCopyInputNodes/>
+      <zorba:getReturnType/>
+    </zorba:methods>
+
+  </zorba:function>
+
+</zorba:iterator>
+
 </zorba:iterators>

=== modified file 'src/runtime/visitors/pregenerated/planiter_visitor.h'
--- src/runtime/visitors/pregenerated/planiter_visitor.h	2012-04-26 20:54:34 +0000
+++ src/runtime/visitors/pregenerated/planiter_visitor.h	2012-04-27 14:41:19 +0000
@@ -397,6 +397,8 @@
 
     class LeastCommonAncestor;
 
+    class NodeCopyIterator;
+
     class AbsIterator;
 
     class CeilingIterator;
@@ -1168,6 +1170,9 @@
     virtual void beginVisit ( const LeastCommonAncestor& ) = 0;
     virtual void endVisit   ( const LeastCommonAncestor& ) = 0;
 
+    virtual void beginVisit ( const NodeCopyIterator& ) = 0;
+    virtual void endVisit   ( const NodeCopyIterator& ) = 0;
+
     virtual void beginVisit ( const AbsIterator& ) = 0;
     virtual void endVisit   ( const AbsIterator& ) = 0;
 

=== modified file 'src/runtime/visitors/pregenerated/printer_visitor.cpp'
--- src/runtime/visitors/pregenerated/printer_visitor.cpp	2012-04-24 12:39:38 +0000
+++ src/runtime/visitors/pregenerated/printer_visitor.cpp	2012-04-27 14:41:19 +0000
@@ -2674,6 +2674,20 @@
 // </LeastCommonAncestor>
 
 
+// <NodeCopyIterator>
+void PrinterVisitor::beginVisit ( const NodeCopyIterator& a) {
+  thePrinter.startBeginVisit("NodeCopyIterator", ++theId);
+  printCommons( &a, theId );
+  thePrinter.endBeginVisit( theId );
+}
+
+void PrinterVisitor::endVisit ( const NodeCopyIterator& ) {
+  thePrinter.startEndVisit();
+  thePrinter.endEndVisit();
+}
+// </NodeCopyIterator>
+
+
 // <AbsIterator>
 void PrinterVisitor::beginVisit ( const AbsIterator& a) {
   thePrinter.startBeginVisit("AbsIterator", ++theId);

=== modified file 'src/runtime/visitors/pregenerated/printer_visitor.h'
--- src/runtime/visitors/pregenerated/printer_visitor.h	2012-04-24 12:39:38 +0000
+++ src/runtime/visitors/pregenerated/printer_visitor.h	2012-04-27 14:41:19 +0000
@@ -598,6 +598,9 @@
     void beginVisit( const LeastCommonAncestor& );
     void endVisit  ( const LeastCommonAncestor& );
 
+    void beginVisit( const NodeCopyIterator& );
+    void endVisit  ( const NodeCopyIterator& );
+
     void beginVisit( const AbsIterator& );
     void endVisit  ( const AbsIterator& );
 

=== added file 'test/rbkt/ExpQueryResults/zorba/nodes/copy01.xml.res'
--- test/rbkt/ExpQueryResults/zorba/nodes/copy01.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/nodes/copy01.xml.res	2012-04-27 14:41:19 +0000
@@ -0,0 +1,1 @@
+false

=== added file 'test/rbkt/Queries/zorba/nodes/copy01.xq'
--- test/rbkt/Queries/zorba/nodes/copy01.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/nodes/copy01.xq	2012-04-27 14:41:19 +0000
@@ -0,0 +1,10 @@
+import module namespace node = "http://www.zorba-xquery.com/modules/node";;
+
+let $node :=
+  <a>
+    <b>
+      <c/>
+    </b>
+  </a>
+let $new-node := node:copy($node/b)
+return ($node/b is $new-node, $new-node/parent::a)

-- 
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

Reply via email to