Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/hof-next into 
lp:zorba.

Commit message:
moved FunctionItemIterator code to new function_item_iter.h/cpp files

Requested reviews:
  Markos Zaharioudakis (markos-za)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/hof-next/+merge/155677

moved FunctionItemIterator code to new function_item_iter.h/cpp files
-- 
https://code.launchpad.net/~zorba-coders/zorba/hof-next/+merge/155677
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/compiler/codegen/plan_visitor.cpp'
--- src/compiler/codegen/plan_visitor.cpp	2013-03-27 00:44:34 +0000
+++ src/compiler/codegen/plan_visitor.cpp	2013-03-27 07:59:30 +0000
@@ -93,6 +93,7 @@
 #endif
 #include "runtime/eval/eval.h"
 #include "runtime/hof/function_item.h"
+#include "runtime/hof/function_item_iter.h"
 #include "runtime/hof/fn_hof_functions.h"
 #include "runtime/hof/dynamic_fncall_iterator.h"
 #include "runtime/misc/materialize.h"

=== modified file 'src/runtime/CMakeLists.txt'
--- src/runtime/CMakeLists.txt	2013-03-26 23:32:03 +0000
+++ src/runtime/CMakeLists.txt	2013-03-27 07:59:30 +0000
@@ -141,6 +141,7 @@
   util/flowctl_exception.cpp
   util/doc_uri_heuristics.cpp
   hof/function_item.cpp
+  hof/function_item_iter.cpp
   hof/dynamic_fncall_iterator.cpp
   eval/eval.cpp
   collections/collections_base.cpp

=== modified file 'src/runtime/hof/function_item.cpp'
--- src/runtime/hof/function_item.cpp	2013-03-26 23:32:03 +0000
+++ src/runtime/hof/function_item.cpp	2013-03-27 07:59:30 +0000
@@ -47,8 +47,6 @@
 
 SERIALIZABLE_CLASS_VERSIONS(FunctionItem)
 
-SERIALIZABLE_CLASS_VERSIONS(FunctionItemIterator)
-
 
 /*******************************************************************************
 
@@ -283,228 +281,5 @@
 }
 
 
-
-/*******************************************************************************
-
-********************************************************************************/
-FunctionItemIterator::FunctionItemIterator(
-      static_context* sctx,
-      const QueryLoc& loc,
-      FunctionItemInfo* fnInfo)
-  :
-  NaryBaseIterator<FunctionItemIterator, PlanIteratorState>(sctx, loc, fnInfo->theScopedVarsIterators),
-  theFunctionItemInfo(fnInfo)
-{
-}
-
-
-FunctionItemIterator::~FunctionItemIterator()
-{
-}
-
-
-void FunctionItemIterator::serialize(::zorba::serialization::Archiver& ar)
-{
-  serialize_baseclass(ar,
-  (NaryBaseIterator<FunctionItemIterator, PlanIteratorState>*)this);
-  ar & theFunctionItemInfo;
-}
-
-
-bool FunctionItemIterator::nextImpl(store::Item_t& result, PlanState& planState) const
-{
-  PlanIteratorState* state;
-  DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
-
-  // This portion is taken from the eval iterator
-  {
-    // Create the dynamic context for the eval query
-    std::auto_ptr<dynamic_context> evalDctx;
-    evalDctx.reset(new dynamic_context(planState.theGlobalDynCtx));
-
-    // Import the outer environment.
-    importOuterEnv(planState,
-                   theFunctionItemInfo->theCCB,
-                   theFunctionItemInfo->theClosureSctx,
-                   evalDctx.get());
-
-    if (theFunctionItemInfo->theIsCoercion)
-    {
-      FunctionItemIterator* child = dynamic_cast<FunctionItemIterator*>(theChildren[0].getp());
-      if (child != NULL)
-        theFunctionItemInfo->theQName = child->theFunctionItemInfo->theQName;
-    }
-
-    result = new FunctionItem(theFunctionItemInfo, evalDctx.release());
-  }
-
-  STACK_PUSH ( result != NULL, state );
-  STACK_END (state);
-}
-
-
-/********************************************************************************
-
-  These functions are copied from the EvalIterator -- maybe they could be shared.
-
-********************************************************************************/
-
-/****************************************************************************//**
-  This method imports a static and dynamic environment from the quter query into
-  the eval query. In particular:
-
-  (a) imports into the importSctx all the outer vars of the eval query
-  (b) imports into the importSctx all the ns bindings of the outer query at the
-      place where the eval call appears at
-  (c) Copies all the var values from the outer-query global dctx into the eval-
-      query dctx.
-  (d) For each of the non-global outer vars, places its value into the eval dctx.
-      The var value is represented as a PlanIteratorWrapper over the subplan that
-      evaluates the domain expr of the eval var.
-  (e) Computes the max var id of all the var values set in steps (c) and (d).
-      This max varid will be passed to the compiler of the eval query so that
-      the varids that will be generated for the eval query will not conflict with
-      the varids of the outer vars and the outer-query global vars.
-********************************************************************************/
-void FunctionItemIterator::importOuterEnv(
-    PlanState& planState,
-    CompilerCB* evalCCB,
-    static_context* importSctx,
-    dynamic_context* evalDctx) const
-{
-  ulong maxOuterVarId = 1;
-
-  // Copy all the var values from the outer-query global dctx into the eval-query
-  // dctx. This is need to handle the following scenario: (a) $x is an outer-query
-  // global var that is not among the outer vars of the eval query (because $x was
-  // hidden at the point where the eval call is made inside the outer query), and
-  // (b) foo() is a function decalred in the outer query that accessed $x and is
-  // invoked by the eval query. The copying must be done using the same positions
-  // (i.e., var ids) in the eval dctx as in the outer-query dctx.
-
-  dynamic_context* outerDctx = evalDctx->getParent();
-
-  const std::vector<dynamic_context::VarValue>& outerGlobalValues =
-  outerDctx->get_variables();
-
-  csize numOuterGlobalVars = outerGlobalValues.size();
-
-  for (csize i = 0; i < numOuterGlobalVars; ++i)
-  {
-    const dynamic_context::VarValue& outerVar = outerGlobalValues[i];
-
-    if (!outerVar.isSet())
-      continue;
-
-    ulong outerVarId = static_cast<ulong>(i);
-
-    if (outerVarId > maxOuterVarId)
-      maxOuterVarId = outerVarId;
-
-    store::Item_t itemValue;
-    store::TempSeq_t seqValue;
-
-    if (outerVar.hasItemValue())
-    {
-      store::Item_t value = outerVar.theValue.item;
-      evalDctx->add_variable(outerVarId, value);
-    }
-    else
-    {
-      store::Iterator_t iteValue = outerVar.theValue.temp_seq->getIterator();
-      evalDctx->add_variable(outerVarId, iteValue);
-    }
-  }
-
-  ++maxOuterVarId;
-
-  // Import the outer vars. Specifically, for each outer var:
-  // (a) create a declaration inside the importSctx.
-  // (b) Set its var id
-  // (c) If it is not a global one, set its value within the eval dctx.
-  csize curChild = -1;
-
-  csize numOuterVars = theFunctionItemInfo->theScopedVarsNames.size();
-
-
-  for (csize i = 0; i < numOuterVars; ++i)
-  {
-    if (!theFunctionItemInfo->theIsGlobalVar[i])
-    {
-      ++curChild;
-
-      store::Iterator_t iter = new PlanIteratorWrapper(theChildren[curChild], planState);
-
-      evalDctx->add_variable(theFunctionItemInfo->theVarId[i], iter);
-    }
-  }
-
-  // Import the outer-query ns bindings
-  store::NsBindings::const_iterator ite = theFunctionItemInfo->theLocalBindings.begin();
-  store::NsBindings::const_iterator end = theFunctionItemInfo->theLocalBindings.end();
-
-  for (; ite != end; ++ite)
-  {
-    importSctx->bind_ns(ite->first, ite->second, loc);
-  }
-}
-
-
-/****************************************************************************//**
-
-********************************************************************************/
-void FunctionItemIterator::setExternalVariables(
-    CompilerCB* ccb,
-    static_context* importSctx,
-    dynamic_context* evalDctx) const
-{
-  std::vector<VarInfo*> innerVars;
-
-  CompilerCB::SctxMap::const_iterator sctxIte = ccb->theSctxMap.begin();
-  CompilerCB::SctxMap::const_iterator sctxEnd = ccb->theSctxMap.end();
-
-  for (; sctxIte != sctxEnd; ++sctxIte)
-  {
-    sctxIte->second->getVariables(innerVars, true, false, true);
-  }
-
-  FOR_EACH(std::vector<VarInfo*>, ite, innerVars)
-  {
-    VarInfo* innerVar = (*ite);
-
-    if (!innerVar->isExternal())
-      continue;
-
-    ulong innerVarId = innerVar->getId();
-
-    VarInfo* outerVar = importSctx->lookup_var(innerVar->getName());
-
-    if (!outerVar)
-      continue;
-
-    store::Item_t itemValue;
-    store::TempSeq_t seqValue;
-
-    evalDctx->get_variable(outerVar->getId(),
-                           outerVar->getName(),
-                           loc,
-                           itemValue,
-                           seqValue);
-
-    if (itemValue != NULL)
-    {
-      evalDctx->add_variable(innerVarId, itemValue);
-    }
-    else
-    {
-      store::Iterator_t iteValue = seqValue->getIterator();
-      evalDctx->add_variable(innerVarId, iteValue);
-    }
-  }
-}
-
-NARY_ACCEPT(FunctionItemIterator)
-
-
 } //namespace zorba
 /* vim:set et sw=2 ts=2: */

=== modified file 'src/runtime/hof/function_item.h'
--- src/runtime/hof/function_item.h	2013-03-26 23:32:03 +0000
+++ src/runtime/hof/function_item.h	2013-03-27 07:59:30 +0000
@@ -22,8 +22,6 @@
 
 #include "store/api/item.h"
 
-#include "runtime/base/narybase.h"
-
 
 namespace zorba
 {
@@ -234,52 +232,6 @@
 };
 
 
-/*******************************************************************************
-  An iterator that creates and returns dynamic function items
-********************************************************************************/
-class FunctionItemIterator : public NaryBaseIterator<FunctionItemIterator, PlanIteratorState>
-{
-protected:
-  FunctionItemInfo_t theFunctionItemInfo;
-
-public:
-  SERIALIZABLE_CLASS(FunctionItemIterator)
-  SERIALIZABLE_CLASS_CONSTRUCTOR2T(FunctionItemIterator,
-  NaryBaseIterator<FunctionItemIterator, PlanIteratorState>)
-  void serialize(::zorba::serialization::Archiver& ar);
-
-public:
-  FunctionItemIterator(
-      static_context* sctx,
-      const QueryLoc& loc,
-      FunctionItemInfo* fnInfo);
-
-  virtual ~FunctionItemIterator();
-
-  // Used for pretty-printing of the iterator tree
-  const FunctionItemInfo_t getFunctionItemInfo() const
-  {
-    return theFunctionItemInfo;
-  }
-
-  void accept(PlanIterVisitor& v) const;
-
-  bool nextImpl(store::Item_t& result, PlanState& planState) const;
-
-public:
-  void importOuterEnv(PlanState& planState,
-      CompilerCB* evalCCB,
-      static_context* importSctx,
-      dynamic_context* evalDctx) const;
-
-private:
-  void setExternalVariables(
-      CompilerCB* ccb,
-      static_context* importSctx,
-      dynamic_context* evalDctx) const;
-};
-
-
 }//end of zorba namespace
 
 #endif

=== added file 'src/runtime/hof/function_item_iter.cpp'
--- src/runtime/hof/function_item_iter.cpp	1970-01-01 00:00:00 +0000
+++ src/runtime/hof/function_item_iter.cpp	2013-03-27 07:59:30 +0000
@@ -0,0 +1,198 @@
+/*
+ * 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"
+
+// This include needs to be kept in order to make sure the
+// auto_ptr<dynamic_context> manages to dealocate the
+// dynamic_context object.
+#include "context/dynamic_context.h"
+
+
+#include "runtime/hof/function_item.h"
+#include "runtime/hof/function_item_iter.h"
+#include "runtime/api/plan_iterator_wrapper.h"
+#include "runtime/visitors/planiter_visitor.h"
+
+#include "store/api/item.h"
+#include "store/api/temp_seq.h"
+
+namespace zorba
+{
+
+SERIALIZABLE_CLASS_VERSIONS(FunctionItemIterator)
+
+/*******************************************************************************
+
+********************************************************************************/
+FunctionItemIterator::FunctionItemIterator(
+      static_context* sctx,
+      const QueryLoc& loc,
+      FunctionItemInfo* fnInfo)
+  :
+  NaryBaseIterator<FunctionItemIterator, PlanIteratorState>(sctx, loc, fnInfo->theScopedVarsIterators),
+  theFunctionItemInfo(fnInfo)
+{
+}
+
+
+FunctionItemIterator::~FunctionItemIterator()
+{
+}
+
+
+void FunctionItemIterator::serialize(::zorba::serialization::Archiver& ar)
+{
+  serialize_baseclass(ar,
+  (NaryBaseIterator<FunctionItemIterator, PlanIteratorState>*)this);
+  ar & theFunctionItemInfo;
+}
+
+
+bool FunctionItemIterator::nextImpl(store::Item_t& result, PlanState& planState) const
+{
+  PlanIteratorState* state;
+  DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
+
+  // This portion is taken from the eval iterator
+  {
+    // Create the dynamic context for the eval query
+    std::auto_ptr<dynamic_context> evalDctx;
+    evalDctx.reset(new dynamic_context(planState.theGlobalDynCtx));
+
+    // Import the outer environment.
+    importOuterEnv(planState,
+                   theFunctionItemInfo->theCCB,
+                   theFunctionItemInfo->theClosureSctx,
+                   evalDctx.get());
+
+    if (theFunctionItemInfo->theIsCoercion)
+    {
+      FunctionItemIterator* child = dynamic_cast<FunctionItemIterator*>(theChildren[0].getp());
+      if (child != NULL)
+        theFunctionItemInfo->theQName = child->theFunctionItemInfo->theQName;
+    }
+
+    result = new FunctionItem(theFunctionItemInfo, evalDctx.release());
+  }
+
+  STACK_PUSH ( result != NULL, state );
+  STACK_END (state);
+}
+
+
+/********************************************************************************
+
+  These functions are copied from the EvalIterator -- maybe they could be shared.
+
+********************************************************************************/
+
+/****************************************************************************//**
+  This method imports a static and dynamic environment from the quter query into
+  the eval query. In particular:
+
+  (a) imports into the importSctx all the outer vars of the eval query
+  (b) imports into the importSctx all the ns bindings of the outer query at the
+      place where the eval call appears at
+  (c) Copies all the var values from the outer-query global dctx into the eval-
+      query dctx.
+  (d) For each of the non-global outer vars, places its value into the eval dctx.
+      The var value is represented as a PlanIteratorWrapper over the subplan that
+      evaluates the domain expr of the eval var.
+  (e) Computes the max var id of all the var values set in steps (c) and (d).
+      This max varid will be passed to the compiler of the eval query so that
+      the varids that will be generated for the eval query will not conflict with
+      the varids of the outer vars and the outer-query global vars.
+********************************************************************************/
+void FunctionItemIterator::importOuterEnv(
+    PlanState& planState,
+    CompilerCB* evalCCB,
+    static_context* importSctx,
+    dynamic_context* evalDctx) const
+{
+  ulong maxOuterVarId = 1;
+
+  // Copy all the var values from the outer-query global dctx into the eval-query
+  // dctx. This is need to handle the following scenario: (a) $x is an outer-query
+  // global var that is not among the outer vars of the eval query (because $x was
+  // hidden at the point where the eval call is made inside the outer query), and
+  // (b) foo() is a function decalred in the outer query that accessed $x and is
+  // invoked by the eval query. The copying must be done using the same positions
+  // (i.e., var ids) in the eval dctx as in the outer-query dctx.
+
+  dynamic_context* outerDctx = evalDctx->getParent();
+
+  const std::vector<dynamic_context::VarValue>& outerGlobalValues =
+  outerDctx->get_variables();
+
+  csize numOuterGlobalVars = outerGlobalValues.size();
+
+  for (csize i = 0; i < numOuterGlobalVars; ++i)
+  {
+    const dynamic_context::VarValue& outerVar = outerGlobalValues[i];
+
+    if (!outerVar.isSet())
+      continue;
+
+    ulong outerVarId = static_cast<ulong>(i);
+
+    if (outerVarId > maxOuterVarId)
+      maxOuterVarId = outerVarId;
+
+    store::Item_t itemValue;
+    store::TempSeq_t seqValue;
+
+    if (outerVar.hasItemValue())
+    {
+      store::Item_t value = outerVar.theValue.item;
+      evalDctx->add_variable(outerVarId, value);
+    }
+    else
+    {
+      store::Iterator_t iteValue = outerVar.theValue.temp_seq->getIterator();
+      evalDctx->add_variable(outerVarId, iteValue);
+    }
+  }
+
+  ++maxOuterVarId;
+
+  // Import the outer vars. Specifically, for each outer var:
+  // (a) create a declaration inside the importSctx.
+  // (b) Set its var id
+  // (c) If it is not a global one, set its value within the eval dctx.
+  csize curChild = -1;
+
+  csize numOuterVars = theFunctionItemInfo->theScopedVarsNames.size();
+
+
+  for (csize i = 0; i < numOuterVars; ++i)
+  {
+    if (!theFunctionItemInfo->theIsGlobalVar[i])
+    {
+      ++curChild;
+
+      store::Iterator_t iter = new PlanIteratorWrapper(theChildren[curChild], planState);
+
+      evalDctx->add_variable(theFunctionItemInfo->theVarId[i], iter);
+    }
+  }
+}
+
+
+NARY_ACCEPT(FunctionItemIterator)
+
+
+}
+

=== added file 'src/runtime/hof/function_item_iter.h'
--- src/runtime/hof/function_item_iter.h	1970-01-01 00:00:00 +0000
+++ src/runtime/hof/function_item_iter.h	2013-03-27 07:59:30 +0000
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+#ifndef ZORBA_RUNTIME_FUNCTION_ITEM_ITER_H
+#define ZORBA_RUNTIME_FUNCTION_ITEM_ITER_H
+
+#include "common/shared_types.h"
+
+#include "runtime/base/narybase.h"
+
+namespace zorba
+{
+
+class FunctionItemInfo;
+
+typedef rchandle<FunctionItemInfo> FunctionItemInfo_t;
+
+
+/*******************************************************************************
+  An iterator that creates and returns dynamic function items
+********************************************************************************/
+class FunctionItemIterator : public NaryBaseIterator<FunctionItemIterator,
+                                                     PlanIteratorState>
+{
+protected:
+  FunctionItemInfo_t theFunctionItemInfo;
+
+public:
+  SERIALIZABLE_CLASS(FunctionItemIterator)
+  SERIALIZABLE_CLASS_CONSTRUCTOR2T(FunctionItemIterator,
+  NaryBaseIterator<FunctionItemIterator, PlanIteratorState>)
+  void serialize(::zorba::serialization::Archiver& ar);
+
+public:
+  FunctionItemIterator(
+      static_context* sctx,
+      const QueryLoc& loc,
+      FunctionItemInfo* fnInfo);
+
+  virtual ~FunctionItemIterator();
+
+  const FunctionItemInfo_t getFunctionItemInfo() const
+  {
+    return theFunctionItemInfo;
+  }
+
+  void accept(PlanIterVisitor& v) const;
+
+  bool nextImpl(store::Item_t& result, PlanState& planState) const;
+
+protected:
+  void importOuterEnv(
+      PlanState& planState,
+      CompilerCB* evalCCB,
+      static_context* importSctx,
+      dynamic_context* evalDctx) const;
+};
+
+
+}//end of zorba namespace
+
+#endif
+/* vim:set et sw=2 ts=2: */

=== modified file 'src/runtime/visitors/printer_visitor_impl.cpp'
--- src/runtime/visitors/printer_visitor_impl.cpp	2013-03-26 23:32:03 +0000
+++ src/runtime/visitors/printer_visitor_impl.cpp	2013-03-27 07:59:30 +0000
@@ -52,6 +52,7 @@
 #endif
 #include "runtime/indexing/index_ddl.h"
 #include "runtime/hof/dynamic_fncall_iterator.h"
+#include "runtime/hof/function_item_iter.h"
 #include "runtime/visitors/iterprinter.h"
 #include "runtime/update/update.h"
 #include "runtime/eval/eval.h"

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