← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/bug-1047538 into lp:zorba

 

Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/bug-1047538 into lp:zorba.

Requested reviews:
  Markos Zaharioudakis (markos-za)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug-1047538/+merge/124076

Fixed bug #1047538 (jsoniq: SourceFinder::findLocalNodeSources missing json expressions)
Fixed bug #1043976 (compiler warning in serialiser code)
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug-1047538/+merge/124076
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2012-09-12 08:06:26 +0000
+++ ChangeLog	2012-09-12 22:32:25 +0000
@@ -35,8 +35,11 @@
   * Fixed bug #1039488 (inserting more than one pair at once in a JSON object)
   * Fixed bug #1042840 (qname pool free-list corruption)
   * Fixed bug #866984 (better error message for an eval error)
+  * Fixed bug #1047538 (jsoniq: SourceFinder::findLocalNodeSources missing
+    json expressions)
   * Fixed bug #932884 (HTML and XHTML serialization of empty elements)
   * Fixed bug #1045902 (file:last-modified returns current date time)
+  * Fixed bug #1043976 (compiler warning in serialiser code)
 
 
 version 2.6

=== modified file 'src/api/serialization/serializer.cpp'
--- src/api/serialization/serializer.cpp	2012-09-12 08:06:26 +0000
+++ src/api/serialization/serializer.cpp	2012-09-12 22:32:25 +0000
@@ -587,8 +587,8 @@
   }
   default:
   {
-    ZORBA_ASSERT(false);
-    tr << "node of type: " << item->getNodeKind();
+    int k = static_cast<int>(item->getNodeKind());
+    ZORBA_ASSERT_WITH_MSG(false, BUILD_STRING("node of type: ", k));
   }
   }
 }
@@ -1475,11 +1475,16 @@
 {
   const store::Item* element_parent = item->getParent();
 
-  if( item->getNodeKind() == store::StoreConsts::documentNode)
+  store::NodeKind kind = item->getNodeKind();
+
+  switch (kind)
+  {
+  case store::StoreConsts::documentNode:
   {
     emit_node_children(item, depth);
+    break;
   }
-  else if (item->getNodeKind() == store::StoreConsts::elementNode)
+  case store::StoreConsts::elementNode:
   {
     store::Item* qnameItem = item->getNodeName();
 
@@ -1568,8 +1573,10 @@
     }
 
     previous_item = PREVIOUS_ITEM_WAS_NODE;
+
+    break;
   }
-  else if (item->getNodeKind() == store::StoreConsts::attributeNode)
+  case store::StoreConsts::attributeNode:
   {
     // The HTML output method MUST output boolean attributes (that is attributes
     // with only a single allowed value that is equal to the name of the
@@ -1593,8 +1600,10 @@
     }
 
     previous_item = PREVIOUS_ITEM_WAS_NODE;
+
+    break;
   }
-  else if (item->getNodeKind() == store::StoreConsts::textNode)
+  case store::StoreConsts::textNode:
   {
     bool expand = true;
 
@@ -1623,23 +1632,27 @@
     }
 
     previous_item = PREVIOUS_ITEM_WAS_TEXT;
+    break;
   }
-  else if (item->getNodeKind() == store::StoreConsts::commentNode)
+  case store::StoreConsts::commentNode:
   {
     tr << "<!--" << item->getStringValue() << "-->";
 
     previous_item = PREVIOUS_ITEM_WAS_NODE;
+    break;
   }
-  else if (item->getNodeKind() == store::StoreConsts::piNode )
+  case store::StoreConsts::piNode:
   {
     tr << "<?" << item->getTarget() << " " << item->getStringValue() << "?>";
 
     previous_item = PREVIOUS_ITEM_WAS_NODE;
+    break;
   }
-  else
+  default:
   {
-    tr << "node of type: " << item->getNodeKind();
-    assert(0);
+    int k = static_cast<int>(kind);
+    ZORBA_ASSERT_WITH_MSG(false, BUILD_STRING("node of type: ", k));
+  }
   }
 }
 

=== modified file 'src/compiler/rewriter/tools/dataflow_annotations.cpp'
--- src/compiler/rewriter/tools/dataflow_annotations.cpp	2012-09-10 22:53:04 +0000
+++ src/compiler/rewriter/tools/dataflow_annotations.cpp	2012-09-12 22:32:25 +0000
@@ -1311,7 +1311,7 @@
 
 
 /*******************************************************************************
-
+  This method is called when we serialize a udf, if the query has an eval expr.
 ********************************************************************************/
 void SourceFinder::findLocalNodeSources(
     expr* node,
@@ -1494,6 +1494,17 @@
     return;
   }
 
+#ifdef ZORBA_WITH_JSON
+  case json_direct_object_expr_kind:
+  case json_object_expr_kind:
+  case json_array_expr_kind:
+  {
+    // TODO? We need to drill inside a json pair or array constructor only
+    // if we are coming from an unbox or flatten call ????
+    break;
+  }
+#endif
+
   case relpath_expr_kind:
   {
     relpath_expr* e = static_cast<relpath_expr *>(node);

=== modified file 'src/functions/func_jsoniq_functions_impl.cpp'
--- src/functions/func_jsoniq_functions_impl.cpp	2012-09-11 15:53:52 +0000
+++ src/functions/func_jsoniq_functions_impl.cpp	2012-09-12 22:32:25 +0000
@@ -134,24 +134,6 @@
 }
 
 
-#if 1
-/*******************************************************************************
-
-********************************************************************************/
-bool op_zorba_json_box::mustCopyInputNodes(expr* fo, csize producer) const
-{
-  static_context* sctx = fo->get_sctx();
-
-  if (sctx->preserve_mode() != StaticContextConsts::no_preserve_ns ||
-      sctx->construction_mode() != StaticContextConsts::cons_preserve)
-  {
-    return true;
-  }
-
-  return false;
-}
-
-
 /*******************************************************************************
 
 ********************************************************************************/
@@ -167,7 +149,6 @@
 
   return theSignature.returnType();
 }
-#endif
 
 
 /*******************************************************************************

=== modified file 'src/functions/pregenerated/func_jsoniq_functions.h'
--- src/functions/pregenerated/func_jsoniq_functions.h	2012-09-11 15:53:52 +0000
+++ src/functions/pregenerated/func_jsoniq_functions.h	2012-09-12 22:32:25 +0000
@@ -357,7 +357,7 @@
 
   bool propagatesInputNodes(expr* fo, csize producer) const { return true; }
 
-  bool mustCopyInputNodes(expr* fo, csize producer) const;
+  bool mustCopyInputNodes(expr* fo, csize producer) const { return false; }
 
   CODEGEN_DECL();
 };

=== modified file 'src/runtime/function_item/dynamic_fncall_iterator.cpp'
--- src/runtime/function_item/dynamic_fncall_iterator.cpp	2012-09-10 22:53:04 +0000
+++ src/runtime/function_item/dynamic_fncall_iterator.cpp	2012-09-12 22:32:25 +0000
@@ -141,7 +141,10 @@
     PlanState& planState) const
 {
   store::Item_t item;
-  store::Item_t funcItem;
+  store::Item_t targetItem;
+  store::Item_t selectorItem;
+  xs_integer pos;
+  bool selectorError;
   FunctionItem* fnItem;
   std::vector<PlanIter_t> argIters;
   std::vector<PlanIter_t>::iterator ite;
@@ -154,7 +157,7 @@
 
   // first child must return exactly one item which is a function item
   // otherwise XPTY0004 is raised
-  if (!consumeNext(funcItem, theChildren[0], planState))
+  if (!consumeNext(targetItem, theChildren[0], planState))
   {
     RAISE_ERROR(err::XPTY0004, loc, 
     ERROR_PARAMS(ZED(XPTY0004_TypePromotion),
@@ -162,17 +165,128 @@
                  GENV_TYPESYSTEM.ANY_FUNCTION_TYPE_ONE->toSchemaString()));
   }
 
-  if (consumeNext(item, theChildren[0], planState))
-  {
-    RAISE_ERROR(err::XPTY0004, loc, 
-    ERROR_PARAMS(ZED(XPTY0004_NoMultiSeqTypePromotion),
-                 GENV_TYPESYSTEM.ANY_FUNCTION_TYPE_ONE->toSchemaString()));
-  }
-
-  if (!funcItem->isFunction())
+  if (targetItem->isFunction())
+  {
+    if (consumeNext(item, theChildren[0], planState))
+    {
+      RAISE_ERROR(err::XPTY0004, loc, 
+      ERROR_PARAMS(ZED(XPTY0004_NoMultiSeqTypePromotion),
+                   GENV_TYPESYSTEM.ANY_FUNCTION_TYPE_ONE->toSchemaString()));
+    }
+
+    fnItem = static_cast<FunctionItem*>(targetItem.getp());
+
+    argIters.resize(theChildren.size() - 1 + fnItem->getVariables().size());
+
+    ite = argIters.begin();
+
+    ite2 = theChildren.begin();
+    end2 = theChildren.end();
+    ++ite2;
+
+    for (; ite2 != end2; ++ite2, ++ite)
+    {
+      *ite = *ite2;
+    }
+
+    ite2 = fnItem->getVariables().begin();
+    end2 = fnItem->getVariables().end();
+
+    for(; ite2 != end2; ++ite2, ++ite) 
+    {
+      *ite = *ite2;
+    }
+    
+    state->thePlan = fnItem->getImplementation(argIters);
+    
+    // must be opened after vars and params are set
+    state->thePlan->open(planState, state->theUDFStateOffset);
+    state->theIsOpen = true;
+    
+    while(consumeNext(result, state->thePlan, planState)) 
+    {
+      STACK_PUSH(true, state);
+    }
+
+    // need to close here early in case the plan is completely
+    // consumed. Otherwise, the plan would still be opened
+    // if destroyed from the state's destructor.
+    state->thePlan->close(planState);
+    state->theIsOpen = false;
+  }
+#ifdef ZORBA_WITH_JSON
+  else if (targetItem->isJSONObject() || targetItem->isJSONArray())
+  {
+    if (theChildren.size() != 2)
+    {
+      RAISE_ERROR_NO_PARAMS(err::JNTY0018, loc);
+    }
+
+    selectorError = false;
+
+    consumeNext(item, theChildren[1], planState);
+
+    if (item->isNode())
+    {
+      store::Iterator_t iter;
+
+      item->getTypedValue(item, iter);
+
+      if (iter != NULL)
+      {
+        if iter->next(item);
+      }
+    }
+
+    if (!item->isAtomic())
+    {
+      selectorError = true;
+    }
+    else if (targetItem->isJSONObject())
+    {
+      try
+      {
+        selectorError = ! GenericCast::castToAtomic(selectorItem,
+                                                    item,
+                                                    store::XS_STRING,
+                                                    tm,
+                                                    NULL,
+                                                    loc);
+      }
+      catch (...)
+      {
+        selectorError = true;
+      }
+    }
+    else
+    {
+      try
+      {
+        pos = selectorItem->getIntegerValue();
+      }
+      catch (...)
+      {
+        selectorError = true;
+      }
+    }
+
+    if (selectorError)
+    {
+      RAISE_ERROR_NO_PARAMS(err::XPTY0004, loc);
+    }
+
+    if (targetItem->isJSONObject())
+      result = targetItem->getObjectValue(selectorItem);
+    else
+      result = getArrayValue(pos);
+
+    STACK_PUSH(true, state);
+  }
+#endif
+  else
   {
     const TypeManager* tm = theSctx->get_typemanager();
-    xqtref_t type = tm->create_value_type(funcItem);
+    xqtref_t type = tm->create_value_type(targetItem);
 
     RAISE_ERROR(err::XPTY0004, loc, 
     ERROR_PARAMS(ZED(XPTY0004_TypePromotion),
@@ -180,46 +294,6 @@
                  GENV_TYPESYSTEM.ANY_FUNCTION_TYPE_ONE->toSchemaString()));
   }
 
-  fnItem = static_cast<FunctionItem*>(funcItem.getp());
-
-  argIters.resize(theChildren.size() - 1 + fnItem->getVariables().size());
-
-  ite = argIters.begin();
-
-  ite2 = theChildren.begin();
-  end2 = theChildren.end();
-  ++ite2;
-
-  for (; ite2 != end2; ++ite2, ++ite)
-  {
-    *ite = *ite2;
-  }
-
-  ite2 = fnItem->getVariables().begin();
-  end2 = fnItem->getVariables().end();
-
-  for(; ite2 != end2; ++ite2, ++ite) 
-  {
-    *ite = *ite2;
-  }
-
-  state->thePlan = fnItem->getImplementation(argIters);
-
-  // must be opened after vars and params are set
-  state->thePlan->open(planState, state->theUDFStateOffset);
-  state->theIsOpen = true;
-  
-  while(consumeNext(result, state->thePlan, planState)) 
-  {
-    STACK_PUSH(true, state);
-  }
-
-  // need to close here early in case the plan is completely
-  // consumed. Otherwise, the plan would still be opened
-  // if destroyed from the state's destructor.
-  state->thePlan->close(planState);
-  state->theIsOpen = false;
-
   STACK_END(state);
 };
 

=== modified file 'src/runtime/function_item/dynamic_fncall_iterator.h'
--- src/runtime/function_item/dynamic_fncall_iterator.h	2012-09-10 22:53:04 +0000
+++ src/runtime/function_item/dynamic_fncall_iterator.h	2012-09-12 22:32:25 +0000
@@ -65,10 +65,11 @@
     (NaryBaseIterator<DynamicFnCallIterator, DynamicFnCallIteratorState>*)this);
   }
 
+public:
   DynamicFnCallIterator(
-        static_context* sctx,
-        const QueryLoc& loc,
-        std::vector<PlanIter_t>& args)
+      static_context* sctx,
+      const QueryLoc& loc,
+      std::vector<PlanIter_t>& args)
     :
     NaryBaseIterator<DynamicFnCallIterator, DynamicFnCallIteratorState>(sctx, loc, args)
   {

=== modified file 'src/runtime/spec/json/jsoniq_functions.xml'
--- src/runtime/spec/json/jsoniq_functions.xml	2012-09-11 16:33:21 +0000
+++ src/runtime/spec/json/jsoniq_functions.xml	2012-09-12 22:32:25 +0000
@@ -503,7 +503,7 @@
         <zorba:getReturnType/>
         <zorba:accessesDynCtx returnValue="true"/>
         <zorba:propagatesInputNodes value="true"/>
-        <zorba:mustCopyInputNodes/>
+        <zorba:mustCopyInputNodes value="false"/>
       </zorba:methods>
 
     </zorba:function>


Follow ups