Matthias Brantner has proposed merging 
lp:~zorba-coders/zorba/jsoniq-plan_serialization into 
lp:~zorba-coders/zorba/jsoniq.

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

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/jsoniq-plan_serialization/+merge/102275

- plan serializer for jsoniq items and iterators
- some fixes for the build without json (still not compiling because of 
problems with the collection functions)
-- 
https://code.launchpad.net/~zorba-coders/zorba/jsoniq-plan_serialization/+merge/102275
Your team Zorba Coders is subscribed to branch lp:~zorba-coders/zorba/jsoniq.
=== modified file 'include/zorba/pregenerated/diagnostic_list.h'
--- include/zorba/pregenerated/diagnostic_list.h	2012-04-11 20:22:52 +0000
+++ include/zorba/pregenerated/diagnostic_list.h	2012-04-17 10:09:20 +0000
@@ -800,13 +800,13 @@
 
 namespace jerr {
 
+#if defined(ZORBA_WITH_JSON)
 extern ZORBA_DLL_PUBLIC JSONiqErrorCode JNSE0012;
 
 extern ZORBA_DLL_PUBLIC JSONiqErrorCode JNSE0013;
 
 extern ZORBA_DLL_PUBLIC JSONiqErrorCode JNSE0014;
 
-#if defined(ZORBA_WITH_JSON)
 extern ZORBA_DLL_PUBLIC JSONiqErrorCode JNTY0002;
 
 extern ZORBA_DLL_PUBLIC JSONiqErrorCode JNTY0003;

=== modified file 'src/api/serialization/serializer.cpp'
--- src/api/serialization/serializer.cpp	2012-04-11 20:22:52 +0000
+++ src/api/serialization/serializer.cpp	2012-04-17 10:09:20 +0000
@@ -2741,8 +2741,11 @@
     // the "JSONIQ" method is consider "XML-based", although you will certainly
     // get errors if you attempt to serialize JDM this way.
     if (method != PARAMETER_VALUE_XML &&
-        method != PARAMETER_VALUE_XHTML &&
-        method != PARAMETER_VALUE_JSONIQ) {
+        method != PARAMETER_VALUE_XHTML
+#ifdef ZORBA_WITH_JSON
+        && method != PARAMETER_VALUE_JSONIQ
+#endif
+      ) {
       throw ZORBA_EXCEPTION(
         zerr::ZAPI0070_INVALID_SERIALIZATION_METHOD_FOR_SAX,
         ERROR_PARAMS( method )

=== modified file 'src/diagnostics/diagnostic_en.xml'
--- src/diagnostics/diagnostic_en.xml	2012-04-11 20:22:52 +0000
+++ src/diagnostics/diagnostic_en.xml	2012-04-17 10:09:20 +0000
@@ -2483,7 +2483,7 @@
 
     <!--////////// CloudScript ///////////////////////////////////////////-->
 
-    <diagnostic code="JNSE0012">
+    <diagnostic code="JNSE0012" if="defined(ZORBA_WITH_JSON)">
       <comment>It is a dynamic error to serialize a sequence of less
       or more than one item with the JSON output method if the
       cloudscript-serialization-multiple-items is set to no.
@@ -2492,7 +2492,7 @@
       <value>Cannot serialize multiple top-level items as JSON</value>
     </diagnostic>
 
-    <diagnostic code="JNSE0013">
+    <diagnostic code="JNSE0013" if="defined(ZORBA_WITH_JSON)">
       <comment>It is a dynamic error to serialize an atomic value not
       supported by JSON or a node with the JSON output method and with
       the cloudscript-serialization-extensions serialization parameter
@@ -2501,7 +2501,7 @@
       <value>Cannot serialize value as JSON: $1</value>
     </diagnostic>
 
-    <diagnostic code="JNSE0014">
+    <diagnostic code="JNSE0014" if="defined(ZORBA_WITH_JSON)">
       <comment>It is a dynamic error to serialize a function with the
       JSON output method.</comment>
       <value>Cannot serialize a function item as JSON</value>

=== modified file 'src/diagnostics/pregenerated/diagnostic_list.cpp'
--- src/diagnostics/pregenerated/diagnostic_list.cpp	2012-04-11 20:22:52 +0000
+++ src/diagnostics/pregenerated/diagnostic_list.cpp	2012-04-17 10:09:20 +0000
@@ -1176,6 +1176,7 @@
 
 namespace jerr {
 
+#if defined(ZORBA_WITH_JSON)
 JSONiqErrorCode JNSE0012( "JNSE0012" );
 
 
@@ -1185,7 +1186,6 @@
 JSONiqErrorCode JNSE0014( "JNSE0014" );
 
 
-#if defined(ZORBA_WITH_JSON)
 JSONiqErrorCode JNTY0002( "JNTY0002" );
 
 

=== modified file 'src/diagnostics/pregenerated/dict_en.cpp'
--- src/diagnostics/pregenerated/dict_en.cpp	2012-04-11 20:22:52 +0000
+++ src/diagnostics/pregenerated/dict_en.cpp	2012-04-17 10:09:20 +0000
@@ -98,9 +98,15 @@
 #if defined(ZORBA_WITH_JSON)
   { "JNDY0003", "\"$1\": pair with the same name already exists in object" },
 #endif
+#if defined(ZORBA_WITH_JSON)
   { "JNSE0012", "Cannot serialize multiple top-level items as JSON" },
+#endif
+#if defined(ZORBA_WITH_JSON)
   { "JNSE0013", "Cannot serialize value as JSON: $1" },
+#endif
+#if defined(ZORBA_WITH_JSON)
   { "JNSE0014", "Cannot serialize a function item as JSON" },
+#endif
 #if defined(ZORBA_WITH_JSON)
   { "JNTY0002", "$1" },
 #endif

=== modified file 'src/runtime/json/json_constructors.cpp'
--- src/runtime/json/json_constructors.cpp	2012-04-12 09:18:43 +0000
+++ src/runtime/json/json_constructors.cpp	2012-04-17 10:09:20 +0000
@@ -94,7 +94,7 @@
   serialize_baseclass(ar, 
   (NaryBaseIterator<JSONArrayIterator, JSONArrayIteratorState>*)this);
 
-  //ar & theCopyInputs; // TODO
+  SERIALIZE_BOOL_VEC(theCopyInputs);
 }
 
 
@@ -191,7 +191,7 @@
   serialize_baseclass(ar, 
   (NaryBaseIterator<JSONObjectIterator, JSONObjectIteratorState>*)this);
 
-  //ar & theCopyInputs; // TODO
+  SERIALIZE_BOOL_VEC(theCopyInputs);
   ar & theIsAccumulating;
 }
 
@@ -275,7 +275,7 @@
   serialize_baseclass(ar, 
   (NaryBaseIterator<JSONDirectObjectIterator, PlanIteratorState>*)this);
 
-  //ar & theCopyInputs; // TODO
+  SERIALIZE_BOOL_VEC(theCopyInputs);
 }
 
 

=== modified file 'src/runtime/json/jsoniq_functions_impl.cpp'
--- src/runtime/json/jsoniq_functions_impl.cpp	2012-04-12 09:18:43 +0000
+++ src/runtime/json/jsoniq_functions_impl.cpp	2012-04-17 10:09:20 +0000
@@ -523,7 +523,7 @@
   serialize_baseclass(ar, 
   (NaryBaseIterator<JSONObjectInsertIterator, PlanIteratorState>*)this);
 
-  //ar & theCopyInputs; // TODO
+  SERIALIZE_BOOL_VEC(theCopyInputs);
 }
 
 

=== modified file 'src/zorbaserialization/serialize_basic_types.h'
--- src/zorbaserialization/serialize_basic_types.h	2012-04-04 09:57:46 +0000
+++ src/zorbaserialization/serialize_basic_types.h	2012-04-17 10:09:20 +0000
@@ -79,6 +79,34 @@
     ar.set_is_temp_field_one_level(false);        \
   }
 
+#define SERIALIZE_BOOL_VEC(vec)                   \
+  {                                               \
+    ar.set_is_temp_field_one_level(true);         \
+    csize lSize = 0;                              \
+    if (ar.is_serializing_out())                  \
+    {                                             \
+      lSize = vec.size();                         \
+      ar & lSize;                                 \
+      for (csize i = 0; i < lSize; ++i)           \
+      {                                           \
+        bool b = vec[i];                          \
+        ar & b;                                   \
+      }                                           \
+    }                                             \
+    else                                          \
+    {                                             \
+      ar & lSize;                                 \
+      vec.reserve(lSize);                         \
+      for (csize i = 0; i < lSize; ++i)           \
+      {                                           \
+        bool b;                                   \
+        ar & b;                                   \
+        vec.push_back(b);                         \
+      }                                           \
+    }                                             \
+    ar.set_is_temp_field_one_level(false);        \
+  }
+
 
 } // namespace serialization
 } // namespace zorba

=== modified file 'src/zorbaserialization/serialize_zorba_types.cpp'
--- src/zorbaserialization/serialize_zorba_types.cpp	2012-04-10 20:10:08 +0000
+++ src/zorbaserialization/serialize_zorba_types.cpp	2012-04-17 10:09:20 +0000
@@ -20,6 +20,7 @@
 #include <zorba/internal/qname.h>
 #include <zorba/item.h>
 #include <zorba/user_exception.h>
+#include <zorba/store_consts.h>
 
 #include "zorbaserialization/serialize_zorba_types.h"
 #include "zorbaserialization/serialize_template_types.h"
@@ -33,6 +34,7 @@
 #include "store/api/item_handle.h"
 #include "store/api/iterator.h"
 #include "store/api/item_factory.h"
+#include "store/api/copymode.h"
 //#include "store/api/tuples.h"
 
 #include "zorbatypes/datetime.h"
@@ -264,6 +266,9 @@
 }
 
 void serialize_node_tree(Archiver &ar, store::Item *&obj, bool all_tree);
+#ifdef ZORBA_WITH_JSON
+void serialize_json_tree(Archiver &ar, store::Item *&obj);
+#endif
 
 
 /*******************************************************************************
@@ -367,6 +372,7 @@
   int  is_pul = 0;
   int  is_error = 0;
   int  is_function = 0;
+  int  is_json = 0;
   
   int   id;
   enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_PTR;
@@ -389,13 +395,16 @@
     is_pul = obj->isPul();
     is_error = obj->isError();
     is_function = obj->isFunction();
-
-    assert(is_node || is_atomic || is_pul || is_error || is_function);
-
-    sprintf(strtemp, "n%da%dp%de%df%d",
-                    is_node, is_atomic, is_pul, is_error, is_function);
-
-    if (is_node || is_function)
+#ifdef ZORBA_WITH_JSON
+    is_json = obj->isJSONItem();
+#endif
+
+    assert(is_node || is_atomic || is_pul || is_error || is_function || is_json);
+
+    sprintf(strtemp, "n%da%dp%de%df%dj%d",
+                    is_node, is_atomic, is_pul, is_error, is_function, is_json);
+
+    if (is_node || is_function || is_json)
       ar.set_is_temp_field(true);
 
     is_ref = ar.add_compound_field("store::Item*",
@@ -404,7 +413,7 @@
                                    obj,
                                    ARCHIVE_FIELD_PTR);
 
-    if (is_node || is_function)
+    if (is_node || is_function || is_json)
       ar.set_is_temp_field(false);
   }
   else
@@ -440,8 +449,8 @@
 
     if (!is_ref)
     {
-      sscanf(value.c_str(), "n%da%dp%de%df%d",
-                    &is_node, &is_atomic, &is_pul, &is_error, &is_function);
+      sscanf(value.c_str(), "n%da%dp%de%df%dj%d",
+                    &is_node, &is_atomic, &is_pul, &is_error, &is_function, &is_json);
     }
   }
 
@@ -771,6 +780,18 @@
         SERIALIZE_FIELD(bool, value, getBooleanValue());
         FINALIZE_SERIALIZE(createBoolean, (result, value));
       }
+#ifdef ZORBA_WITH_JSON
+      else if(name_of_type == "null")
+      {
+        if (!ar.is_serializing_out())
+        {
+          store::Item_t lRes;
+          GENV_ITEMFACTORY->createJSONNull(lRes);
+          obj = lRes.getp();
+          obj->addReference();
+        }
+      }
+#endif
       else
       {
         throw ZORBA_EXCEPTION(
@@ -784,6 +805,12 @@
     {
       serialize_node_tree(ar, obj, true);
     }
+#ifdef ZORBA_WITH_JSON
+    else if(is_json)
+    {
+      serialize_json_tree(ar, obj);
+    }
+#endif
     else if(is_pul)
     {
       throw ZORBA_EXCEPTION(
@@ -1088,6 +1115,126 @@
 }
 
 
+#ifdef ZORBA_WITH_JSON
+/*******************************************************************************
+
+********************************************************************************/
+void serialize_json_object(Archiver &ar, store::Item *&obj)
+{
+  xs_integer lSize = 0;
+  if (ar.is_serializing_out())
+  {
+    lSize = obj->getSize();
+  }
+  ar & lSize;
+
+  if (ar.is_serializing_out())
+  {
+    store::Iterator_t lIter = obj->getPairs();
+    lIter->open();
+    store::Item_t lPair;
+    while (lIter->next(lPair))
+    {
+      store::Item* lName = lPair->getName();
+      store::Item* lValue = lPair->getValue();
+      ar & lName;
+      ar & lValue;
+    }
+    lIter->close();
+  }
+  else
+  {
+    csize num = to_xs_unsignedInt(lSize);
+    std::vector<store::Item_t> lNames, lValues;
+    lNames.reserve(num);
+    lValues.reserve(num);
+
+    store::Item* lName, *lValue;
+    for (csize i = 0; i < num; ++i)
+    {
+      ar & lName;
+      ar & lValue;
+      lNames.push_back(lName);
+      lValues.push_back(lValue);
+    }
+    store::Item_t lRes;
+    GENV_ITEMFACTORY->createJSONObject(lRes, lNames, lValues); 
+    obj = lRes.getp();
+    obj->addReference();
+  }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void serialize_json_array(Archiver &ar, store::Item *&obj)
+{
+  xs_integer lSize = 0;
+  if (ar.is_serializing_out())
+  {
+    lSize = obj->getSize();
+  }
+  ar & lSize;
+
+  if (ar.is_serializing_out())
+  {
+    store::Iterator_t lIter = obj->getMembers();
+    lIter->open();
+    store::Item_t lMember;
+    while (lIter->next(lMember))
+    {
+      store::Item* lTmp = lMember.getp();
+      ar & lTmp;
+    }
+    lIter->close();
+  }
+  else
+  {
+    csize num = to_xs_unsignedInt(lSize);
+    std::vector<store::Item_t> lValues;
+    lValues.reserve(num);
+
+    store::Item* lValue;
+    for (csize i = 0; i < num; ++i)
+    {
+      ar & lValue;
+      lValues.push_back(lValue);
+    }
+    store::Item_t lRes;
+    GENV_ITEMFACTORY->createJSONArray(lRes, lValues); 
+    obj = lRes.getp();
+    obj->addReference();
+  }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void serialize_json_tree(Archiver &ar, store::Item *&obj)
+{
+  store::StoreConsts::JSONItemKind lKind = store::StoreConsts::jsonItem;
+  if (ar.is_serializing_out())
+  {
+    lKind = obj->getJSONItemKind();
+  }
+  SERIALIZE_ENUM(store::StoreConsts::JSONItemKind, lKind);
+
+  switch (lKind)
+  {
+  case store::StoreConsts::jsonObject:
+    serialize_json_object(ar, obj);
+    break;
+  case store::StoreConsts::jsonArray:
+    serialize_json_array(ar, obj);
+    break;
+  default: assert(false);
+  }
+}
+#endif // ZORBA_WITH_JSON
+
+
 /*******************************************************************************
 
 ********************************************************************************/
@@ -1120,11 +1267,22 @@
     UserError *user_err = dynamic_cast<UserError*>(diagnostic);
     XQueryErrorCode *xquery_err = dynamic_cast<XQueryErrorCode*>(diagnostic);
     ZorbaErrorCode *zorba_err = dynamic_cast<ZorbaErrorCode*>(diagnostic);
+#ifdef ZORBA_WITH_JSON
+    JSONiqErrorCode* jsoniq_err = dynamic_cast<JSONiqErrorCode*>(diagnostic);
+#endif
     char err_type[20];
+#ifdef ZORBA_WITH_JSON
+    sprintf(err_type, "u%dx%dz%dj%d", 
+            user_err != NULL ? 1 : 0,
+            xquery_err != NULL ? 1 : 0,
+            zorba_err != NULL ? 1 : 0,
+            jsoniq_err != NULL ? 1 : 0);
+#else
     sprintf(err_type, "u%dx%dz%d", 
             user_err != NULL ? 1 : 0,
             xquery_err != NULL ? 1 : 0,
             zorba_err != NULL ? 1 : 0);
+#endif
     is_ref = ar.add_compound_field("Diagnostic*", 
                                    !FIELD_IS_CLASS, err_type, 
                                    obj, 
@@ -1171,14 +1329,23 @@
     if(field_treat == ARCHIVE_FIELD_PTR)
     {
       int is_user, is_xquery, is_zorba;
+#ifdef ZORBA_WITH_JSON
+      int is_jsoniq;
+      sscanf(value.c_str(), "u%dx%dz%dj%d", &is_user, &is_xquery, &is_zorba, &is_jsoniq);
+#else
       sscanf(value.c_str(), "u%dx%dz%d", &is_user, &is_xquery, &is_zorba);
+#endif
       if(is_user)
       {
         UserError *user_error = new UserError(ar);
         ar & user_error->qname_;
         obj = user_error;
       }
-      else if(is_xquery || is_zorba)
+      else if(is_xquery || is_zorba
+#ifdef ZORBA_WITH_JSON
+          || is_jsoniq
+#endif
+      )
       {
         ar.set_is_temp_field(true);
         char*   local;

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