← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/serializer into lp:zorba

 

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

Requested reviews:
  Markos Zaharioudakis (markos-za)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/serializer/+merge/99243

comments and cosmetic changes
-- 
https://code.launchpad.net/~zorba-coders/zorba/serializer/+merge/99243
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/api/xqueryimpl.cpp'
--- src/api/xqueryimpl.cpp	2012-03-23 17:32:07 +0000
+++ src/api/xqueryimpl.cpp	2012-03-26 01:27:27 +0000
@@ -211,7 +211,6 @@
     theIsClosed = false;
 
     theCompilerCB->theXQueryDiagnostics = theXQueryDiagnostics;
-
   }
 
 #ifdef ZORBA_WITH_DEBUGGER

=== modified file 'src/compiler/api/compilercb.cpp'
--- src/compiler/api/compilercb.cpp	2012-03-23 17:32:07 +0000
+++ src/compiler/api/compilercb.cpp	2012-03-26 01:27:27 +0000
@@ -172,21 +172,31 @@
 {
 }
 
-//compile all the user_functions so the expr tree is stable at serialize
+
+/*******************************************************************************
+  Compile all the user_functions so the expr tree is stable at serialize.
+
+  Called from XQueryImpl::serialize(), if serializing out.
+********************************************************************************/
 void CompilerCB::prepare_for_serialize()
 {
   rclist<user_function*>::iterator udf_it;
-  for(udf_it=theLocalUdfs->begin(); udf_it != theLocalUdfs->end(); udf_it++)
+  for (udf_it = theLocalUdfs->begin(); udf_it != theLocalUdfs->end(); udf_it++)
   {
     (*udf_it)->prepare_for_serialize(this);
   }
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 rchandle<rclist<user_function*> >  CompilerCB::get_local_udfs()
 {
   return theLocalUdfs;
 }
 
+
 /*******************************************************************************
 
 ********************************************************************************/

=== modified file 'src/compiler/expression/expr.h'
--- src/compiler/expression/expr.h	2012-03-23 17:32:07 +0000
+++ src/compiler/expression/expr.h	2012-03-26 01:27:27 +0000
@@ -1178,8 +1178,10 @@
 
 protected:
   expr_t                      theExpr;
+
   std::vector<var_expr_t>     theVars;
   std::vector<expr_t>         theArgs;
+
   expr_script_kind_t          theInnerScriptingKind;
   bool                        theDoNodeCopy;
 

=== modified file 'src/compiler/expression/expr_put.cpp'
--- src/compiler/expression/expr_put.cpp	2012-03-23 17:32:07 +0000
+++ src/compiler/expression/expr_put.cpp	2012-03-26 01:27:27 +0000
@@ -456,7 +456,8 @@
   {
     os << indent << "using $" << theVars[i]->get_name()->getStringValue() << " := [";
     os << endl << inc_indent;
-    theArgs[i]->put(os);
+    if (theArgs[i])
+      theArgs[i]->put(os);
     os << dec_indent << indent << "]" << endl; 
   }
   theExpr->put (os);

=== modified file 'src/compiler/rewriter/tools/udf_graph.cpp'
--- src/compiler/rewriter/tools/udf_graph.cpp	2012-03-23 17:32:07 +0000
+++ src/compiler/rewriter/tools/udf_graph.cpp	2012-03-26 01:27:27 +0000
@@ -310,7 +310,6 @@
       }
       else
       {
-        assert(false);
         deterministic = node->theUDF->isDeterministic();
       }
     }

=== modified file 'src/context/static_context.cpp'
--- src/context/static_context.cpp	2012-03-23 17:32:07 +0000
+++ src/context/static_context.cpp	2012-03-26 01:27:27 +0000
@@ -183,7 +183,7 @@
 *******************************************************************************/
 void static_context::ctx_module_t::serialize(serialization::Archiver& ar)
 {
-  if(ar.is_serializing_out())
+  if (ar.is_serializing_out())
   {
     // serialize out: the uri of the module that is used in this plan
 

=== modified file 'src/functions/udf.cpp'
--- src/functions/udf.cpp	2012-03-23 17:32:07 +0000
+++ src/functions/udf.cpp	2012-03-26 01:27:27 +0000
@@ -96,20 +96,31 @@
 }
 
 
-void user_function::prepare_for_serialize(CompilerCB *compilerCB)
+/*******************************************************************************
+
+********************************************************************************/
+void user_function::prepare_for_serialize(CompilerCB* compilerCB)
 {
   uint32_t planStateSize;
   getPlan(compilerCB, planStateSize);
+
   std::vector<user_function*>::iterator udf_it;
+<<<<<<< TREE
   for(udf_it = theMutuallyRecursiveUDFs.begin();
       udf_it != theMutuallyRecursiveUDFs.end();
       ++udf_it)
+=======
+  for (udf_it = theMutuallyRecursiveUDFs.begin(); 
+       udf_it != theMutuallyRecursiveUDFs.end();
+       udf_it++)
+>>>>>>> MERGE-SOURCE
   {
     if ((*udf_it)->thePlan == NULL)
       (*udf_it)->prepare_for_serialize(compilerCB);
   }
 }
 
+
 /*******************************************************************************
 
 ********************************************************************************/

=== modified file 'src/functions/udf.h'
--- src/functions/udf.h	2012-03-23 17:32:07 +0000
+++ src/functions/udf.h	2012-03-26 01:27:27 +0000
@@ -132,7 +132,7 @@
   bool                        theCacheResults;
   bool                        theCacheComputed;
 
-  rchandle<rclist<user_function*> >    theLocalUdfs;//for plan serializer
+  rchandle<rclist<user_function*> > theLocalUdfs;//for plan serializer
 
 public:
   SERIALIZABLE_CLASS(user_function)

=== modified file 'src/store/naive/atomic_items.h'
--- src/store/naive/atomic_items.h	2012-03-23 17:32:07 +0000
+++ src/store/naive/atomic_items.h	2012-03-26 01:27:27 +0000
@@ -1460,6 +1460,7 @@
 
   xs_integer getIntegerValue() const { return theValue; }
 
+<<<<<<< TREE
   xs_long getLongValue() const; 
 
   xs_unsignedInt getUnsignedIntValue() const;
@@ -1474,6 +1475,19 @@
   store::SchemaTypeCode getTypeCode() const { return store::XS_INTEGER; }
 
   store::Item* getType() const;
+=======
+  xs_long getLongValue() const;
+
+  zstring getStringValue() const;
+
+  void getStringValue2(zstring& val) const;
+
+  void appendStringValue(zstring& buf) const;
+
+  virtual store::SchemaTypeCode getTypeCode() const { return store::XS_INTEGER; }
+
+  virtual store::Item* getType() const;
+>>>>>>> MERGE-SOURCE
 
   uint32_t hash(long = 0, const XQPCollator* aCollation = 0) const;
 
@@ -1487,9 +1501,22 @@
         long timezone = 0,
         const XQPCollator* aCollation = 0) const;
 
+<<<<<<< TREE
   bool getEBV() const;
 
   zstring show() const;
+=======
+  long compare(
+        const Item* other,
+        long timezone = 0,
+        const XQPCollator* aCollation = 0) const;
+
+  bool getEBV( ) const;
+
+  bool isNaN() const { return false; }
+
+  virtual zstring show() const;
+>>>>>>> MERGE-SOURCE
 };
 
 

=== modified file 'src/system/zorba_properties.txt'
--- src/system/zorba_properties.txt	2012-03-23 17:32:07 +0000
+++ src/system/zorba_properties.txt	2012-03-26 01:27:27 +0000
@@ -29,7 +29,11 @@
       ("loop-hoisting", po::value<bool>()->default_value (true), "hoist expressions out of loops (1=enabled (default), 0=off)")
       ("infer-joins", po::value<bool>()->default_value (true), "infer joins (1=enabled (default), 0=off)")
       ("no-copy-optim", po::value<bool>()->default_value(true), "no copy optim (1=enabled (default), 0=off)")
+<<<<<<< TREE
       ("serialize-only-query", po::value<int>()->default_value(-1), "serialize-only query (1=true, 0=false, -1 unknown (default))")
+=======
+      ("serialize-only-query", po::value<int>()->default_value(-1), "serialize-only query (1=true, 0=false (default))")
+>>>>>>> MERGE-SOURCE
 #ifndef NDEBUG
       ("trace-translator,l", "trace the translator")
       ("trace-codegen,c", "trace the codegenerator")

=== modified file 'src/zorbaserialization/archiver.cpp'
--- src/zorbaserialization/archiver.cpp	2012-03-23 17:32:07 +0000
+++ src/zorbaserialization/archiver.cpp	2012-03-26 01:27:27 +0000
@@ -35,301 +35,460 @@
 {
 
 
-/////////////////////////////////////////
-//////////////////////////////////////////////////////
+/*******************************************************************************
 
-archive_field::archive_field(const char *type, bool is_simple, bool is_class,
-              const void *value, const void *assoc_ptr,
-              int version, enum ArchiveFieldTreat  field_treat,
-              archive_field *refered,
-              int only_for_eval,
-              ENUM_ALLOW_DELAY allow_delay,
-              unsigned int level)
+********************************************************************************/
+archive_field::archive_field(
+    const char* type,
+    bool is_simple,
+    bool is_class,
+    const void* value,
+    const void* assoc_ptr,
+    int version,
+    enum ArchiveFieldKind  kind,
+    archive_field* refered,
+    int only_for_eval,
+    ENUM_ALLOW_DELAY allow_delay,
+    unsigned int level)
 {
-  this->type = strdup(type);
-  this->type_str_pos_in_pool = 0;//initialy is the number of references to this field
-  this->is_simple = is_simple;
-  this->is_class = is_class;
-  if(value)
-  {
-    this->value = strdup((char*)value);
-  }
+  theKind = kind;
+
+  theIsSimple = is_simple;
+  theIsClass = is_class;
+
+  theClassVersion = version;
+
+  theTypeName = strdup(type);
+  theTypeNamePosInPool = 0;//initialy is the number of references to this field
+
+  if (value)
+    theValue = strdup((char*)value);
   else
-    this->value = NULL;
+    theValue = NULL;
+
   this->assoc_ptr = assoc_ptr;
-  this->version = version;
-  this->field_treat = field_treat;
-  this->referencing = refered ? refered->id : 0;
-
-  next = NULL;
-  first_child = NULL;
-  last_child = NULL;
-  parent = NULL;
-  this->refered = refered;
-
-  this->only_for_eval = only_for_eval;
-  this->allow_delay2 = allow_delay;
-
-  this->level = level;
+
+  theReferredField = refered;
+
+  this->referencing = refered ? refered->theId : 0;
+
+  theLevel = level;
+
+  theNextSibling = NULL;
+  theFirstChild = NULL;
+  theLastChild = NULL;
+  theParent = NULL;
+
+  theOnlyForEval = only_for_eval;
+
+  theAllowDelay2 = allow_delay;
+
 #ifdef ZORBA_PLAN_SERIALIZER_STATISTICS
-  bytes_saved = 0;
-  objects_saved = 0;
+  theBytesSaved = 0;
+  theObjectsSaved = 0;
 #endif
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 archive_field::~archive_field()
 {
-  free(type);
-  if(value)
-    free((void*)value);
-  archive_field *temp1;
-  archive_field *temp2;
-  temp1 = first_child;
+  free(theTypeName);
+
+  if (theValue)
+    free((void*)theValue);
+
+  archive_field* temp1 = theFirstChild;
+  archive_field* temp2;
+
   while(temp1)
   {
-    temp2 = temp1->next;
+    temp2 = temp1->theNextSibling;
     delete temp1;
     temp1 = temp2;
   }
 }
 
-/////////////////////////////////////////
-//////////////////////////////////////////////////////
-
+
+/*******************************************************************************
+
+********************************************************************************/
 Archiver::Archiver(bool is_serializing_out, bool internal_archive)
-  : serializing_out(is_serializing_out),
-    serialize_base_class(false),
-    all_reference_list(0),
-    archive_version(g_zorba_classes_version),
-    out_fields(0),
-    current_compound_field(0),
-    simple_hashout_fields(0),
-    hash_out_fields(0),
-    nr_ids(0),
-    current_class_version(0),
-    read_optional(false),
-    is_temp_field(0),
-    //is_temp_field_one_level(false),
-    current_level(0),
-    internal_archive(internal_archive),
-    theUserCallback(0),
-    //compiler_cb(0),
-    dont_allow_delay_for_plan_sctx(false)
+  :
+  theSerializingOut(is_serializing_out),
+  serialize_base_class(false),
+  all_reference_list(0),
+  theArchiveVersion(g_zorba_classes_version),
+  theRootField(0),
+  current_compound_field(0),
+  simple_hashout_fields(0),
+  hash_out_fields(0),
+  nr_ids(0),
+  current_class_version(0),
+  read_optional(false),
+  theIsTempField(0),
+  theCurrentLevel(0),
+  internal_archive(internal_archive),
+  theOnlyForEval(0),
+  theSerializeEverything(false),
+  loading_hardcoded_objects(false),
+  theAllowDelay2(ALLOW_DELAY),
+  theUserCallback(0),
+  dont_allow_delay_for_plan_sctx(false)
 {
-
-  if(is_serializing_out)
+  if (theSerializingOut)
   {
     //create the top most field
-    out_fields = new archive_field("", false, false, NULL, NULL, 0, ARCHIVE_FIELD_NORMAL, NULL, false, ALLOW_DELAY, 0);
-    current_compound_field = out_fields;
-  }
-
-  if (!internal_archive)
-  {
-    Archiver *har = ClassSerializer::getInstance()->harcoded_objects_archive;
-    nr_ids = har->get_nr_ids();
-  }
-
-  if(is_serializing_out)
-  {
+    theRootField = new archive_field("",
+                                     false, // is_simple
+                                     false, // is_class
+                                     NULL,  // value
+                                     NULL,  // assoc_ptr
+                                     0,     // version
+                                     ARCHIVE_FIELD_NORMAL,
+                                     NULL,  // referred
+                                     false, // only for eval
+                                     ALLOW_DELAY,
+                                     0);    // level
+
+    current_compound_field = theRootField;
+
     simple_hashout_fields = new HashMap<SIMPLE_HASHOUT_FIELD, archive_field*,
                                         SimpleHashoutFieldCompare>(1000, false);
     hash_out_fields = new hash64map<archive_field*>(10000, 0.6f);
   }
 
-
-  this->only_for_eval = 0;
-  this->serialize_everything = false;
-  loading_hardcoded_objects = false;
-  allow_delay2 = ALLOW_DELAY;
+  if (!internal_archive)
+  {
+    Archiver* har = ClassSerializer::getInstance()->harcoded_objects_archive;
+    nr_ids = har->get_nr_ids();
+  }
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 Archiver::~Archiver()
 {
-  delete out_fields;
-  delete []all_reference_list;
+  delete theRootField;
+  delete [] all_reference_list;
   delete simple_hashout_fields;
   delete hash_out_fields;
 
-  std::list<fwd_ref>::iterator    it;
-  for(it = fwd_reference_list.begin(); it != fwd_reference_list.end(); it++)
+  std::list<fwd_ref>::iterator it;
+  for (it = fwd_reference_list.begin(); it != fwd_reference_list.end(); ++it)
   {
-    if((*it).class_name)
+    if ((*it).class_name)
       free((*it).class_name);
   }
 
   std::vector<archive_field*>::const_iterator orphan_it;
-  for(orphan_it = orphan_fields.begin(); orphan_it != orphan_fields.end(); orphan_it++)
+  for (orphan_it = orphan_fields.begin(); orphan_it != orphan_fields.end(); ++orphan_it)
   {
     delete (*orphan_it);
   }
 }
 
 
-void Archiver::create_archive(const char *archive_name,
-                            const char *archive_info,
-                            int archive_version)
-{
-  this->archive_name = strdup(archive_name);
-  this->archive_info = strdup(archive_info);
-  this->archive_version = archive_version;
-}
-
-//return true if field is not referencing
-bool Archiver::add_simple_field(const char *type,
-                            const char *value,
-                            const void *orig_ptr,
-                            enum ArchiveFieldTreat field_treat
-                            )
-{
-  current_level++;
-  archive_field  *new_field;
-  archive_field  *ref_field = NULL;
-  bool      exch_fields = false;
-  //int id = 0;
-  if(!orig_ptr)
-  {
-    field_treat = ARCHIVE_FIELD_IS_NULL;
-  }
-  else if((field_treat != ARCHIVE_FIELD_IS_BASECLASS) && orig_ptr &&
-    !get_is_temp_field() && (!get_is_temp_field_one_level() || ((field_treat == ARCHIVE_FIELD_IS_PTR) && !get_is_temp_field_also_for_ptr())))
-    ref_field = check_nonclass_pointer(type, orig_ptr);
-  if(ref_field)
-  {
-    assert((field_treat != ARCHIVE_FIELD_NORMAL) || (ref_field->field_treat != ARCHIVE_FIELD_NORMAL));
-    if(get_is_temp_field_one_level() && (field_treat == ARCHIVE_FIELD_IS_PTR) && (allow_delay2 == ALLOW_DELAY))
-      allow_delay2 = DONT_ALLOW_DELAY;
-    if(field_treat == ARCHIVE_FIELD_NORMAL)
-    {
-      //special case
-      //move the prev field into this one
+/*******************************************************************************
+  Return the left sibling of a given field (NULL if there is no left sibling).
+********************************************************************************/
+archive_field* Archiver::get_prev(archive_field* field)
+{
+  archive_field* temp;
+  temp = field->theParent->theFirstChild;
+
+  if (temp == field)
+    return NULL;
+
+  while (temp)
+  {
+    if (temp->theNextSibling == field)
+      return temp;
+
+    temp = temp->theNextSibling;
+  }
+
+  assert(false);
+  return NULL;
+}
+
+
+/*******************************************************************************
+  Check whether there exists already a field for the simple object at the given
+  memory address.
+********************************************************************************/
+archive_field* Archiver::lookup_nonclass_field(const char* type, const void* ptr)
+{
+  if (!ptr)
+    return NULL;
+
+  archive_field* duplicate_field = NULL;
+
+  SIMPLE_HASHOUT_FIELD f(type, ptr);
+
+  simple_hashout_fields->get(f, duplicate_field);
+
+  if (!duplicate_field)
+  {
+    Archiver* har = ::zorba::serialization::ClassSerializer::getInstance()->
+    getArchiverForHardcodedObjects();
+
+    if (har != this)
+      duplicate_field = har->lookup_nonclass_field(type, ptr);
+  }
+
+  return duplicate_field;
+}
+
+
+/*******************************************************************************
+  Create a "simple" field (ARCHIVE_FIELD_IS_PTR, or ARCHIVE_FIELD_IS_NUL, or
+  ARCHIVE_FIELD_NORMAL).
+
+  @param type : The type of the object to serialize.
+  @param value : The value of the object to serialize, if it is not a pointer).
+  @param ptr : Pointer to the object being serialized (may be NULL)
+  @param fieldKind : The kind of the field (if ptr is NULL, then the fieldKind is
+         set unconditionally to ARCHIVE_FIELD_IS_NUL).
+
+  Return true if field is not referencing
+********************************************************************************/
+bool Archiver::add_simple_field(
+    const char* type,
+    const char* value,
+    const void* ptr,
+    enum ArchiveFieldKind fieldKind)
+{
+  archive_field* new_field;
+  archive_field* ref_field = NULL;
+  bool exch_fields = false;
+
+  assert(fieldKind != ARCHIVE_FIELD_IS_BASECLASS);
+  assert(fieldKind != ARCHIVE_FIELD_IS_REFERENCING);
+
+  theCurrentLevel++;
+
+  if (!ptr)
+  {
+    fieldKind = ARCHIVE_FIELD_IS_NULL;
+  }
+  else if (!get_is_temp_field() &&
+           (!get_is_temp_field_one_level() ||
+            (fieldKind == ARCHIVE_FIELD_IS_PTR && !get_is_temp_field_also_for_ptr())))
+  {
+    ref_field = lookup_nonclass_field(type, ptr);
+  }
+
+  if (ref_field)
+  {
+    assert(fieldKind != ARCHIVE_FIELD_NORMAL ||
+           ref_field->theKind != ARCHIVE_FIELD_NORMAL);
+
+    if (get_is_temp_field_one_level() &&
+        fieldKind == ARCHIVE_FIELD_IS_PTR &&
+        theAllowDelay2 == ALLOW_DELAY)
+    {
+      theAllowDelay2 = DONT_ALLOW_DELAY;
+    }
+
+    if (fieldKind == ARCHIVE_FIELD_NORMAL)
+    {
+      //special case: move the prev field into this one
       exch_fields = true;
     }
-    field_treat = ARCHIVE_FIELD_IS_REFERENCING;
+
+    fieldKind = ARCHIVE_FIELD_IS_REFERENCING;
     value = NULL;
-    orig_ptr = NULL;
+    ptr = NULL;
   }
 
-
-  new_field = new archive_field(type, true, false, value, orig_ptr, 0, field_treat, ref_field, get_serialize_only_for_eval(), allow_delay2, current_level);
-  allow_delay2 = ALLOW_DELAY;
-  if(!ref_field && (field_treat != ARCHIVE_FIELD_IS_BASECLASS) && orig_ptr &&
-    !get_is_temp_field() && (!get_is_temp_field_one_level() || ((field_treat == ARCHIVE_FIELD_IS_PTR) && !get_is_temp_field_also_for_ptr())))
+  new_field = new archive_field(type,
+                                true,       // is_simple
+                                false,      // is_class
+                                value,
+                                ptr,
+                                0,          // version
+                                fieldKind,
+                                ref_field,
+                                get_serialize_only_for_eval(),
+                                theAllowDelay2,
+                                theCurrentLevel);
+
+  theAllowDelay2 = ALLOW_DELAY;
+
+  if (!ref_field &&
+      ptr &&
+      !get_is_temp_field() &&
+      (!get_is_temp_field_one_level() ||
+       (fieldKind == ARCHIVE_FIELD_IS_PTR && !get_is_temp_field_also_for_ptr())))
   {
-    SIMPLE_HASHOUT_FIELD  f(type, orig_ptr);
+    SIMPLE_HASHOUT_FIELD f(type, ptr);
     simple_hashout_fields->insert(f, new_field);
   }
-  if(!exch_fields)
+
+  if (!exch_fields)
   {
-    new_field->parent = current_compound_field;
-    new_field->id = ++nr_ids;
-    new_field->order = new_field->id;
-    if(current_compound_field->last_child)
-      current_compound_field->last_child->next = new_field;
+    new_field->theId = ++nr_ids;
+    new_field->theOrder = new_field->theId;
+
+    new_field->theParent = current_compound_field;
+
+    if (current_compound_field->theLastChild)
+      current_compound_field->theLastChild->theNextSibling = new_field;
     else
-      current_compound_field->first_child = new_field;
-    current_compound_field->last_child = new_field;
+      current_compound_field->theFirstChild = new_field;
+
+    current_compound_field->theLastChild = new_field;
   }
   else
   {
     exchange_fields(new_field, ref_field);
   }
-  current_level--;
+
+  theCurrentLevel--;
+
   return ref_field != NULL;
 }
 
-void Archiver::replace_field(archive_field  *new_field, archive_field  *ref_field)
+
+/*******************************************************************************
+
+********************************************************************************/
+void Archiver::replace_field(archive_field* new_field, archive_field* ref_field)
 {
-  archive_field  *ref_field_parent = ref_field->parent;
-  archive_field  *ref_field_prev = ref_field_parent->first_child;
-  if(ref_field_prev == ref_field)//is first child
+  archive_field* ref_field_parent = ref_field->theParent;
+  archive_field* ref_field_prev = ref_field_parent->theFirstChild;
+
+  if (ref_field_prev == ref_field)//is first child
   {
-    ref_field_parent->first_child = new_field;
-    new_field->next = ref_field->next;
+    ref_field_parent->theFirstChild = new_field;
+    new_field->theNextSibling = ref_field->theNextSibling;
   }
   else
   {
-    while(ref_field_prev->next != ref_field)
-      ref_field_prev = ref_field_prev->next;
-    ref_field_prev->next = new_field;
-    new_field->next = ref_field->next;
+    while (ref_field_prev->theNextSibling != ref_field)
+      ref_field_prev = ref_field_prev->theNextSibling;
+
+    ref_field_prev->theNextSibling = new_field;
+    new_field->theNextSibling = ref_field->theNextSibling;
   }
-  new_field->parent = ref_field_parent;
-  if(ref_field_parent->last_child == ref_field)
-    ref_field_parent->last_child = new_field;
-  new_field->order = ref_field->order;
+
+  new_field->theParent = ref_field_parent;
+
+  if (ref_field_parent->theLastChild == ref_field)
+    ref_field_parent->theLastChild = new_field;
+
+  new_field->theOrder = ref_field->theOrder;
 }
 
-void Archiver::exchange_fields(archive_field  *new_field, archive_field  *ref_field)
+
+/*******************************************************************************
+
+********************************************************************************/
+void Archiver::exchange_fields(archive_field* new_field, archive_field* ref_field)
 {
-  new_field->field_treat = ARCHIVE_FIELD_IS_REFERENCING;
-  ref_field->field_treat = ARCHIVE_FIELD_NORMAL;
-//  new_field->id = ref_field->id;
-//  ref_field->id = ++nr_ids;
-  new_field->id = ++nr_ids;
-  new_field->referencing = ref_field->id;
+  new_field->theKind = ARCHIVE_FIELD_IS_REFERENCING;
+  ref_field->theKind = ARCHIVE_FIELD_NORMAL;
+
+  new_field->theId = ++nr_ids;
+  new_field->referencing = ref_field->theId;
 
   replace_field(new_field, ref_field);
 
-  ref_field->parent = current_compound_field;
-  if(current_compound_field->last_child)
-    current_compound_field->last_child->next = ref_field;
+  ref_field->theParent = current_compound_field;
+  if(current_compound_field->theLastChild)
+    current_compound_field->theLastChild->theNextSibling = ref_field;
   else
-    current_compound_field->first_child = ref_field;
-  ref_field->next = NULL;
-  current_compound_field->last_child = ref_field;
-  ref_field->order = nr_ids;
+    current_compound_field->theFirstChild = ref_field;
+  ref_field->theNextSibling = NULL;
+  current_compound_field->theLastChild = ref_field;
+  ref_field->theOrder = nr_ids;
 
-  new_field->allow_delay2 = ref_field->allow_delay2;
+  new_field->theAllowDelay2 = ref_field->theAllowDelay2;
 }
 
-bool Archiver::add_compound_field(const char *type,
-                              int version,
-                              bool is_class,
-                              const void *info,
-                              const void *ptr,//for classes, pointer to SerializeBaseClass
-                              enum ArchiveFieldTreat field_treat
-                              )
+
+/*******************************************************************************
+
+********************************************************************************/
+bool Archiver::add_compound_field(
+    const char* type,
+    int version,
+    bool is_class,
+    const void* info,
+    const void* ptr,//for classes, pointer to SerializeBaseClass
+    enum ArchiveFieldKind fieldKind)
 {
-  current_level++;
-  archive_field  *new_field;
-  archive_field  *ref_field = NULL;
-  bool      exch_fields = false;
-  //int id = 0;
-  if(!ptr)
+  archive_field* new_field;
+  archive_field* ref_field = NULL;
+  bool exch_fields = false;
+
+  theCurrentLevel++;
+
+  if (!ptr)
   {
-    field_treat = ARCHIVE_FIELD_IS_NULL;
-    current_level--;
+    fieldKind = ARCHIVE_FIELD_IS_NULL;
+    theCurrentLevel--;
   }
-  else if((field_treat != ARCHIVE_FIELD_IS_BASECLASS) && ptr &&
-    !get_is_temp_field() && (!get_is_temp_field_one_level() || ((field_treat == ARCHIVE_FIELD_IS_PTR) && !get_is_temp_field_also_for_ptr())))
+  else if(fieldKind != ARCHIVE_FIELD_IS_BASECLASS &&
+          ptr &&
+          !get_is_temp_field() &&
+          (!get_is_temp_field_one_level() ||
+           (fieldKind == ARCHIVE_FIELD_IS_PTR && !get_is_temp_field_also_for_ptr())))
   {
-    if(!is_class)
-      ref_field = check_nonclass_pointer(type, ptr);
+    if (!is_class)
+      ref_field = lookup_nonclass_field(type, ptr);
     else
-      ref_field = check_class_pointer((SerializeBaseClass*)ptr);
+      ref_field = lookup_class_field((SerializeBaseClass*)ptr);
   }
-  if(ref_field)
+
+  if (ref_field)
   {
-    assert((field_treat != ARCHIVE_FIELD_NORMAL) || (ref_field->field_treat != ARCHIVE_FIELD_NORMAL));
-    if(get_is_temp_field_one_level() && (field_treat == ARCHIVE_FIELD_IS_PTR) && (allow_delay2 == ALLOW_DELAY))
-      allow_delay2 = DONT_ALLOW_DELAY;
-    if(field_treat == ARCHIVE_FIELD_NORMAL)
+    assert(fieldKind != ARCHIVE_FIELD_NORMAL ||
+           ref_field->theKind != ARCHIVE_FIELD_NORMAL);
+
+    if (get_is_temp_field_one_level() && 
+        fieldKind == ARCHIVE_FIELD_IS_PTR &&
+        theAllowDelay2 == ALLOW_DELAY)
+      theAllowDelay2 = DONT_ALLOW_DELAY;
+
+    if(fieldKind == ARCHIVE_FIELD_NORMAL)
     {
       //special case
       //move the prev field into this one
       exch_fields = true;
     }
-    field_treat = ARCHIVE_FIELD_IS_REFERENCING;
+
+    fieldKind = ARCHIVE_FIELD_IS_REFERENCING;
+
     ptr = NULL;
   }
 
-  new_field = new archive_field(type, false, is_class, info, ptr, version, field_treat, ref_field, get_serialize_only_for_eval(), allow_delay2, current_level);
-  allow_delay2 = ALLOW_DELAY;
-  if(!ref_field && (field_treat != ARCHIVE_FIELD_IS_BASECLASS) && ptr &&
-      !get_is_temp_field() && (!get_is_temp_field_one_level() || ((field_treat == ARCHIVE_FIELD_IS_PTR) && !get_is_temp_field_also_for_ptr())))
+  new_field = new archive_field(type,
+                                false,
+                                is_class,
+                                info,
+                                ptr,
+                                version,
+                                fieldKind,
+                                ref_field,
+                                get_serialize_only_for_eval(), 
+                                theAllowDelay2,
+                                theCurrentLevel);
+  theAllowDelay2 = ALLOW_DELAY;
+
+  if (!ref_field &&
+      fieldKind != ARCHIVE_FIELD_IS_BASECLASS &&
+      ptr &&
+      !get_is_temp_field() &&
+      (!get_is_temp_field_one_level() ||
+       (fieldKind == ARCHIVE_FIELD_IS_PTR && !get_is_temp_field_also_for_ptr())))
   {
-    if(!is_class)
+    if (!is_class)
     {
       SIMPLE_HASHOUT_FIELD  f(type, ptr);
       simple_hashout_fields->insert(f, new_field);
@@ -339,16 +498,17 @@
       hash_out_fields->put((uint64_t)ptr, new_field);
     }
   }
-  if(!exch_fields)
+
+  if (!exch_fields)
   {
-    new_field->parent = current_compound_field;
-    new_field->id = ++nr_ids;
-    new_field->order = new_field->id;
-    if(current_compound_field->last_child)
-      current_compound_field->last_child->next = new_field;
+    new_field->theParent = current_compound_field;
+    new_field->theId = ++nr_ids;
+    new_field->theOrder = new_field->theId;
+    if(current_compound_field->theLastChild)
+      current_compound_field->theLastChild->theNextSibling = new_field;
     else
-      current_compound_field->first_child = new_field;
-    current_compound_field->last_child = new_field;
+      current_compound_field->theFirstChild = new_field;
+    current_compound_field->theLastChild = new_field;
     if(!ref_field && ptr)
       current_compound_field = new_field;
   }
@@ -356,245 +516,224 @@
   {
     exchange_fields(new_field, ref_field);
   }
-  if(ref_field)
-    current_level--;
+
+  if (ref_field)
+    theCurrentLevel--;
+
   return ref_field != NULL;
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 void Archiver::add_end_compound_field()
 {
-  current_compound_field = current_compound_field->parent;
-  current_level--;
-}
-
-void Archiver::set_class_type(const char *class_name)
-{
-  free(current_compound_field->type);
-  current_compound_field->type = strdup(class_name);
-}
-
-archive_field* Archiver::check_nonclass_pointer(const char *type, const void *ptr)
-{
-  if(!ptr)
-    return NULL;
-
-  //return check_nonclass_pointer_internal(ptr, out_fields);
-  archive_field *duplicate_field = NULL;
-  //hash_out_fields->get((uint64_t)ptr, duplicate_field);
-  SIMPLE_HASHOUT_FIELD  f(type, ptr);
-  simple_hashout_fields->get(f, duplicate_field);
-  if(!duplicate_field)
-  {
-    Archiver *har = ::zorba::serialization::ClassSerializer::getInstance()->getArchiverForHardcodedObjects();
-    if(har != this)
-      duplicate_field = har->check_nonclass_pointer(type, ptr);
-  }
-  return duplicate_field;
-}
-/*
-archive_field* Archiver::check_nonclass_pointer_internal(const void *ptr, archive_field *fields)
-{
-  archive_field *child;
-  child = fields->first_child;
-  while(child)
-  {
-    if(child->is_simple || !child->is_class)
-      if(child->assoc_ptr == ptr)
-        return child;
-    if(!child->is_simple)
-    {
-      archive_field* ref_field = check_nonclass_pointer_internal(ptr, child);
-      if(ref_field)
-        return ref_field;
-    }
-    child = child->next;
-  }
-  return 0;
-}
-*/
-archive_field* Archiver::check_class_pointer(const SerializeBaseClass *ptr)
-{
-  if(!ptr)
-    return NULL;
-  //return check_class_pointer_internal(ptr, out_fields);
-  archive_field *duplicate_field = NULL;
+  current_compound_field = current_compound_field->theParent;
+  theCurrentLevel--;
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void Archiver::set_class_type(const char* class_name)
+{
+  free(current_compound_field->theTypeName);
+  current_compound_field->theTypeName = strdup(class_name);
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+archive_field* Archiver::lookup_class_field(const SerializeBaseClass* ptr)
+{
+  if(!ptr)
+    return NULL;
+
+  archive_field* duplicate_field = NULL;
+
   hash_out_fields->get((uint64_t)ptr, duplicate_field);
+
   if(!duplicate_field)
   {
-    Archiver *har = ::zorba::serialization::ClassSerializer::getInstance()->getArchiverForHardcodedObjects();
-    if(har != this)
-      duplicate_field = har->check_class_pointer(ptr);
+    Archiver* har = ::zorba::serialization::ClassSerializer::getInstance()->
+    getArchiverForHardcodedObjects();
+
+    if (har != this)
+      duplicate_field = har->lookup_class_field(ptr);
   }
+
   return duplicate_field;
 }
-/*
-archive_field* Archiver::check_class_pointer_internal(const SerializeBaseClass *ptr, archive_field *fields)
-{
-
-  archive_field *child;
-  child = fields->first_child;
-  while(child)
-  {
-    if(child->is_class)
-      if(child->assoc_class_ptr == ptr)
-        return child;
-    if(!child->is_simple)
-    {
-      archive_field* ref_field = check_class_pointer_internal(ptr, child);
-      if(ref_field)
-        return ref_field;
-    }
-    child = child->next;
-  }
-  return 0;
-}
-*/
-
-bool Archiver::read_next_field( char **type,
-                              std::string *value,
-                              int *id,
-                              int *version,
-                              bool *is_simple,
-                              bool *is_class,
-                              enum ArchiveFieldTreat *field_treat,
-                              int *referencing)
-{
-  bool retval = read_next_field_impl(type, value, id, version, is_simple, is_class, field_treat, referencing);
-  if(retval && !*is_simple && (*field_treat != ARCHIVE_FIELD_IS_REFERENCING))
-    current_level++;
+
+
+/*******************************************************************************
+
+********************************************************************************/
+bool Archiver::read_next_field(
+    char** type,
+    std::string* value,
+    int* id,
+    int* version,
+    bool* is_simple,
+    bool* is_class,
+    enum ArchiveFieldKind* fieldKind,
+    int* referencing)
+{
+  bool retval = read_next_field_impl(type, value, id, version, is_simple, is_class, fieldKind, referencing);
+  if(retval && !*is_simple && (*fieldKind != ARCHIVE_FIELD_IS_REFERENCING))
+    theCurrentLevel++;
   return retval;
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 void Archiver::read_end_current_level()
 {
-  current_level--;
+  theCurrentLevel--;
   read_end_current_level_impl();
 }
 
 
-void Archiver::check_simple_field(bool retval,
-                                  const char *type,
-                                  const char *required_type,
-                                  bool is_simple,
-                                  enum ArchiveFieldTreat  field_treat,
-                                  enum ArchiveFieldTreat  required_field_treat,
-                                  int id)
-{
-  if(!retval)
-  {
-    throw ZORBA_EXCEPTION(
-      zerr::ZCSE0001_NONEXISTENT_INPUT_FIELD, ERROR_PARAMS( id )
-    );
-  }
-#ifndef NDEBUG
-  if(!is_simple)
-  {
-    throw ZORBA_EXCEPTION(
-      zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
-    );
-  }
-#endif
-  if(field_treat == ARCHIVE_FIELD_IS_NULL)
-    return;
-#ifndef NDEBUG
-  if(strcmp(type, required_type))
-  {
-    throw ZORBA_EXCEPTION(
-      zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
-    );
-  }
-#endif
-  if((required_field_treat != (enum ArchiveFieldTreat)-1) && (field_treat != required_field_treat))
-  {
-    throw ZORBA_EXCEPTION(
-      zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
-    );
-  }
-}
-
-void Archiver::check_nonclass_field(bool retval,
-                                  const char *type,
-                                  const char *required_type,
-                                  bool is_simple,
-                                  bool is_class,
-                                  enum ArchiveFieldTreat  field_treat,
-                                  enum ArchiveFieldTreat  required_field_treat,
-                                  int id)
-{
-  if(!retval)
-  {
-    throw ZORBA_EXCEPTION(
-      zerr::ZCSE0001_NONEXISTENT_INPUT_FIELD, ERROR_PARAMS( id )
-    );
-  }
-#ifndef NDEBUG
-  if(is_simple || is_class)
-  {
-    throw ZORBA_EXCEPTION(
-      zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
-    );
-  }
-#endif
-  if(field_treat == ARCHIVE_FIELD_IS_NULL)
-    return;
-#ifndef NDEBUG
-  if(strcmp(type, required_type))
-  {
-    throw ZORBA_EXCEPTION(
-      zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
-    );
-  }
-#endif
-  if((required_field_treat != (enum ArchiveFieldTreat)-1) && (field_treat != required_field_treat))
-  {
-    throw ZORBA_EXCEPTION(
-      zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
-    );
-  }
-}
-
-void Archiver::check_class_field(bool retval,
-                                  const char *type,
-                                  const char *required_type,
-                                  bool is_simple,
-                                  bool is_class,
-                                  enum ArchiveFieldTreat  field_treat,
-                                  enum ArchiveFieldTreat  required_field_treat,
-                                  int id)
-{
-  if(!retval)
-  {
-    throw ZORBA_EXCEPTION(
-      zerr::ZCSE0001_NONEXISTENT_INPUT_FIELD, ERROR_PARAMS( id )
-    );
-  }
-#ifndef NDEBUG
-  if(is_simple || !is_class)
-  {
-    throw ZORBA_EXCEPTION(
-      zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
-    );
-  }
-#endif
-  if(field_treat == ARCHIVE_FIELD_IS_NULL)
-    return;
-#ifndef NDEBUG
-  if(strcmp(type, required_type))
-  {
-    throw ZORBA_EXCEPTION(
-      zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
-    );
-  }
-#endif
-  if((required_field_treat != (enum ArchiveFieldTreat)-1) && (field_treat != required_field_treat))
-  {
-    throw ZORBA_EXCEPTION(
-      zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
-    );
-  }
-}
-
-void Archiver::register_reference(int id, enum ArchiveFieldTreat field_treat, const void *ptr)
+/*******************************************************************************
+
+********************************************************************************/
+void Archiver::check_simple_field(
+    bool retval,
+    const char* type,
+    const char* required_type,
+    bool is_simple,
+    enum ArchiveFieldKind field_treat,
+    enum ArchiveFieldKind required_field_treat,
+    int id)
+{
+  if (!retval)
+  {
+    throw ZORBA_EXCEPTION(zerr::ZCSE0001_NONEXISTENT_INPUT_FIELD, ERROR_PARAMS(id));
+  }
+
+#ifndef NDEBUG
+  if (!is_simple)
+  {
+    throw ZORBA_EXCEPTION(zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS(id));
+  }
+#endif
+
+  if(field_treat == ARCHIVE_FIELD_IS_NULL)
+    return;
+
+#ifndef NDEBUG
+  if (strcmp(type, required_type))
+  {
+    throw ZORBA_EXCEPTION(zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS(id));
+  }
+#endif
+
+  if ((required_field_treat != (enum ArchiveFieldKind)-1) &&
+      field_treat != required_field_treat)
+  {
+    throw ZORBA_EXCEPTION(zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS(id));
+  }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void Archiver::check_nonclass_field(
+    bool retval,
+    const char* type,
+    const char* required_type,
+    bool is_simple,
+    bool is_class,
+    enum ArchiveFieldKind field_treat,
+    enum ArchiveFieldKind required_field_treat,
+    int id)
+{
+  if (!retval)
+  {
+    throw ZORBA_EXCEPTION(zerr::ZCSE0001_NONEXISTENT_INPUT_FIELD, ERROR_PARAMS(id));
+  }
+
+#ifndef NDEBUG
+  if (is_simple || is_class)
+  {
+    throw ZORBA_EXCEPTION(zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS(id));
+  }
+#endif
+
+  if (field_treat == ARCHIVE_FIELD_IS_NULL)
+    return;
+
+#ifndef NDEBUG
+  if (strcmp(type, required_type))
+  {
+    throw ZORBA_EXCEPTION(zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS(id));
+  }
+#endif
+
+  if ((required_field_treat != (enum ArchiveFieldKind)-1) &&
+      field_treat != required_field_treat)
+  {
+    throw ZORBA_EXCEPTION(zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS(id));
+  }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void Archiver::check_class_field(
+    bool retval,
+    const char* type,
+    const char* required_type,
+    bool is_simple,
+    bool is_class,
+    enum ArchiveFieldKind field_treat,
+    enum ArchiveFieldKind required_field_treat,
+    int id)
+{
+  if (!retval)
+  {
+    throw ZORBA_EXCEPTION(zerr::ZCSE0001_NONEXISTENT_INPUT_FIELD, ERROR_PARAMS(id));
+  }
+
+#ifndef NDEBUG
+  if (is_simple || !is_class)
+  {
+    throw ZORBA_EXCEPTION(zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS(id));
+  }
+#endif
+
+  if (field_treat == ARCHIVE_FIELD_IS_NULL)
+    return;
+
+#ifndef NDEBUG
+  if (strcmp(type, required_type))
+  {
+    throw ZORBA_EXCEPTION(zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS(id));
+  }
+#endif
+
+  if ((required_field_treat != (enum ArchiveFieldKind)-1) && 
+     field_treat != required_field_treat)
+  {
+    throw ZORBA_EXCEPTION(zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS(id));
+  }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void Archiver::register_reference(
+    int id,
+    enum ArchiveFieldKind field_treat,
+    const void* ptr)
 {
   if(get_is_temp_field())// && (field_treat != ARCHIVE_FIELD_IS_PTR))
     return;
@@ -605,16 +744,26 @@
   all_reference_list[id] = (void*)ptr;
 
 }
+
+
+/*******************************************************************************
+
+********************************************************************************/
 void Archiver::register_item(store::Item* i)
 {
   if(i)
     registered_items.push_back(i);
 }
 
-void Archiver::register_delay_reference(void **ptr,
-                                        bool is_class,
-                                        const char *class_name,
-                                        int referencing)
+
+/*******************************************************************************
+
+********************************************************************************/
+void Archiver::register_delay_reference(
+    void** ptr,
+    bool is_class,
+    const char* class_name,
+    int referencing)
 {
   struct fwd_ref    fid;
   fid.referencing = referencing;
@@ -630,7 +779,14 @@
   fwd_reference_list.push_back(fid);
 }
 
-void Archiver::reconf_last_delayed_rcobject(void **last_obj, void **new_last_obj, bool to_add_ref)
+
+/*******************************************************************************
+
+********************************************************************************/
+void Archiver::reconf_last_delayed_rcobject(
+    void** last_obj,
+    void** new_last_obj,
+    bool to_add_ref)
 {
   if(fwd_reference_list.size() > 0)
   {
@@ -644,45 +800,58 @@
   }
 }
 
-void Archiver::register_pointers_internal(archive_field *fields)
+
+/*******************************************************************************
+
+********************************************************************************/
+void Archiver::register_pointers_internal(archive_field* fields)
 {
-  archive_field *child;
-  child = fields->first_child;
+  archive_field* child;
+  child = fields->theFirstChild;
   while(child)
   {
-    register_reference(child->id, child->field_treat, child->assoc_ptr);
-    if(!child->is_simple)
+    register_reference(child->theId, child->theKind, child->assoc_ptr);
+    if(!child->theIsSimple)
     {
       register_pointers_internal(child);
     }
-    child = child->next;
+    child = child->theNextSibling;
   }
 }
 
-void *Archiver::get_reference_value(int refid)
+
+/*******************************************************************************
+
+********************************************************************************/
+void* Archiver::get_reference_value(int refid)
 {
   if(internal_archive && !all_reference_list)
   {
     //construct all_reference_list
     root_tag_is_read();
-    register_pointers_internal(out_fields);
+    register_pointers_internal(theRootField);
   }
-  void *assoc_ptr = NULL;
+
+  void* assoc_ptr = NULL;
   //if(!all_reference_list->get((uint32_t)refid, assoc_ptr))
-  if(!(assoc_ptr=all_reference_list[refid]))
+  if(!(assoc_ptr = all_reference_list[refid]))
   {
-    Archiver *har = ::zorba::serialization::ClassSerializer::getInstance()->getArchiverForHardcodedObjects();
+    Archiver* har = ::zorba::serialization::ClassSerializer::getInstance()->getArchiverForHardcodedObjects();
     if(har != this)
       assoc_ptr = har->get_reference_value(refid);
   }
   return assoc_ptr;
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 void Archiver::finalize_input_serialization()
 {
-  std::list<fwd_ref>::iterator    it;
-  void  *ptr;
-  for(it = fwd_reference_list.begin(); it != fwd_reference_list.end(); it++)
+  std::list<fwd_ref>::iterator it;
+  void* ptr;
+  for (it = fwd_reference_list.begin(); it != fwd_reference_list.end(); it++)
   {
     ptr = get_reference_value((*it).referencing);
     if(!ptr)
@@ -755,58 +924,88 @@
   }
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 int Archiver::get_class_version()
 {
   return current_class_version;
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 void Archiver::set_class_version(int new_class_version)
 {
   current_class_version = new_class_version;
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 void Archiver::root_tag_is_read()
 {
-  if(archive_version != g_zorba_classes_version)
+  if (theArchiveVersion != g_zorba_classes_version)
   {
-    throw ZORBA_EXCEPTION(
-      zerr::ZCSE0012_INCOMPATIBLE_ARCHIVE_VERSION,
-      ERROR_PARAMS( archive_version, g_zorba_classes_version )
-    );
+    throw ZORBA_EXCEPTION(zerr::ZCSE0012_INCOMPATIBLE_ARCHIVE_VERSION,
+    ERROR_PARAMS(theArchiveVersion, g_zorba_classes_version));
   }
-  //all_reference_list = new hash32map<void*>(nr_ids*2, 0.6f);
+
   all_reference_list = new void*[nr_ids+1];
   memset(all_reference_list, 0, sizeof(void*)*(nr_ids+1));
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 int Archiver::get_nr_ids()
 {
   return nr_ids;
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 void Archiver::prepare_serialize_out()
 {
-  if(!is_serialize_everything())
+  if (!is_serialize_everything())
   {
-    check_compound_fields(out_fields);
+    check_compound_fields(theRootField);
   }
-  while(check_allowed_delays(out_fields))
-  {}
 
+  while(check_allowed_delays(theRootField))
+  {
+  }
 }
 
-archive_field* Archiver::replace_with_null(archive_field *current_field)
+
+/*******************************************************************************
+
+********************************************************************************/
+archive_field* Archiver::replace_with_null(archive_field* current_field)
 {
-  if(current_field->parent)
+  if (current_field->theParent)
   {
-    archive_field   *null_field = new archive_field("NULL",
-                                                    current_field->is_simple,
-                                                    current_field->is_class, "", NULL, 0,
-                                                    ARCHIVE_FIELD_IS_NULL, NULL, false, ALLOW_DELAY, current_field->level);
-    null_field->id = ++nr_ids;
+    archive_field* null_field = new archive_field("NULL",
+                                                  current_field->theIsSimple,
+                                                  current_field->theIsClass,
+                                                  "",
+                                                  NULL,
+                                                  0,
+                                                  ARCHIVE_FIELD_IS_NULL,
+                                                  NULL,
+                                                  false,
+                                                  ALLOW_DELAY,
+                                                  current_field->theLevel);
+    null_field->theId = ++nr_ids;
     replace_field(null_field, current_field);
-    current_field->parent = NULL;
-    current_field->next = NULL;
+    current_field->theParent = NULL;
+    current_field->theNextSibling = NULL;
 
     return null_field;
   }
@@ -814,59 +1013,71 @@
   return NULL;
 }
 
-int Archiver::compute_field_depth(archive_field *field)
+
+/*******************************************************************************
+
+********************************************************************************/
+int Archiver::compute_field_depth(archive_field* field)
 {
   archive_field *temp;
   int i=0;
-  temp = field->parent;
+  temp = field->theParent;
   while(temp)
   {
-    temp = temp->parent;
+    temp = temp->theParent;
     i++;
   }
   return i;
 }
 
-int Archiver::get_only_for_eval(archive_field *field)
+
+/*******************************************************************************
+
+********************************************************************************/
+int Archiver::get_only_for_eval(archive_field* field)
 {
-  if(field->only_for_eval)
-    return field->only_for_eval;
+  if(field->theOnlyForEval)
+    return field->theOnlyForEval;
   archive_field *child;
-  for(child = field->first_child; child; child = child->next)
+  for(child = field->theFirstChild; child; child = child->theNextSibling)
   {
-    if(child->only_for_eval)
-      return child->only_for_eval;
+    if(child->theOnlyForEval)
+      return child->theOnlyForEval;
   }
   return 0;
 }
 
-archive_field* Archiver::find_top_most_eval_only_field(archive_field *parent_field)
+
+/*******************************************************************************
+
+********************************************************************************/
+archive_field* Archiver::find_top_most_eval_only_field(archive_field* parent_field)
 {
   int ref_depth = -1;
   archive_field *refering_field = NULL;
   archive_field *child;
-  child = parent_field->first_child;
+  child = parent_field->theFirstChild;
   while(child)
   {
-    if(child->only_for_eval)
+    if(child->theOnlyForEval)
     {
     }
-    else if((child->field_treat == ARCHIVE_FIELD_IS_REFERENCING) &&
-        get_only_for_eval(child->refered))
+    else if((child->theKind == ARCHIVE_FIELD_IS_REFERENCING) &&
+        get_only_for_eval(child->theReferredField))
     {
-      int new_depth = compute_field_depth(child->refered);
+      int new_depth = compute_field_depth(child->theReferredField);
       if(!refering_field || (ref_depth > new_depth))
       {
         ref_depth = new_depth;
         refering_field = child;
       }
     }
-    else if(!child->is_simple && !child->refered)
+    else if(!child->theIsSimple && !child->theReferredField)
     {
       archive_field *new_refering = find_top_most_eval_only_field(child);
       if(new_refering)
       {
-        int new_depth = compute_field_depth(new_refering->refered);
+        int new_depth = compute_field_depth(new_refering->theReferredField);
         if(!refering_field || (ref_depth > new_depth))
         {
           ref_depth = new_depth;
@@ -874,49 +1085,57 @@
         }
       }
     }
-    child = child->next;
+    child = child->theNextSibling;
   }
   return refering_field;
 }
 
-void Archiver::exchange_mature_fields(archive_field *field1, archive_field *field2)
+
+/*******************************************************************************
+
+********************************************************************************/
+void Archiver::exchange_mature_fields(archive_field* field1, archive_field* field2)
 {
   archive_field *field1_prev = get_prev(field1);
-  archive_field *field1_next = field1->next;
-  archive_field *field1_parent = field1->parent;
+  archive_field *field1_next = field1->theNextSibling;
+  archive_field *field1_parent = field1->theParent;
   archive_field *field2_prev = get_prev(field2);
-  archive_field *field2_parent = field2->parent;
-  archive_field *field2_next = field2->next;
+  archive_field *field2_parent = field2->theParent;
+  archive_field *field2_next = field2->theNextSibling;
   //move field2
   if(field1_prev)
-    field1_prev->next = field2;
+    field1_prev->theNextSibling = field2;
   else
-    field1_parent->first_child = field2;
-  field2->next = field1_next;
+    field1_parent->theFirstChild = field2;
+  field2->theNextSibling = field1_next;
   if(!field1_next)
-    field1_parent->last_child = field2;
-  field2->parent = field1_parent;
+    field1_parent->theLastChild = field2;
+  field2->theParent = field1_parent;
   //move field1
   if(field2_prev)
-    field2_prev->next = field1;
+    field2_prev->theNextSibling = field1;
   else
-    field2_parent->first_child = field1;
-  field1->next = field2_next;
+    field2_parent->theFirstChild = field1;
+  field1->theNextSibling = field2_next;
   if(!field2_next)
-    field2_parent->last_child = field1;
-  field1->parent = field2_parent;
+    field2_parent->theLastChild = field1;
+  field1->theParent = field2_parent;
 
-  ENUM_ALLOW_DELAY temp_delay = field1->allow_delay2;
-  field1->allow_delay2 = field2->allow_delay2;
-  field2->allow_delay2 = temp_delay;
+  ENUM_ALLOW_DELAY temp_delay = field1->theAllowDelay2;
+  field1->theAllowDelay2 = field2->theAllowDelay2;
+  field2->theAllowDelay2 = temp_delay;
 
   unsigned int  temp_order;
-  temp_order = field1->order;
-  field1->order = field2->order;
-  field2->order = temp_order;
+  temp_order = field1->theOrder;
+  field1->theOrder = field2->theOrder;
+  field2->theOrder = temp_order;
 }
 
-void Archiver::check_compound_fields(archive_field *parent_field)
+
+/*******************************************************************************
+
+********************************************************************************/
+void Archiver::check_compound_fields(archive_field* parent_field)
 {
   //resolve all references first
   //iterate: find the reference to the top most eval_only field and resolve it
@@ -927,75 +1146,83 @@
     if(!refering_field)
       break;
 
-    if((refering_field->refered->allow_delay2 != ALLOW_DELAY) ||
-      (refering_field->refered->field_treat == ARCHIVE_FIELD_NORMAL) ||
-      !refering_field->refered->only_for_eval)
+    if((refering_field->theReferredField->theAllowDelay2 != ALLOW_DELAY) ||
+      (refering_field->theReferredField->theKind == ARCHIVE_FIELD_NORMAL) ||
+      !refering_field->theReferredField->theOnlyForEval)
     {
       //must preserve this serialization
-      archive_field *temp_field = refering_field->refered->parent;
+      archive_field *temp_field = refering_field->theReferredField->theParent;
       while(temp_field)
       {
-        temp_field->only_for_eval = 0;
-        temp_field = temp_field->parent;
+        temp_field->theOnlyForEval = 0;
+        temp_field = temp_field->theParent;
       }
     }
     else
     {
-      exchange_mature_fields(refering_field, refering_field->refered);
-      refering_field->only_for_eval = refering_field->refered->only_for_eval;
+      exchange_mature_fields(refering_field, refering_field->theReferredField);
+      refering_field->theOnlyForEval = refering_field->theReferredField->theOnlyForEval;
     }
-    clean_only_for_eval(refering_field->refered, get_only_for_eval(refering_field->refered));
+    clean_only_for_eval(refering_field->theReferredField, get_only_for_eval(refering_field->theReferredField));
   }
   while(check_only_for_eval_nondelay_referencing(parent_field))
   {}
   replace_only_for_eval_with_null(parent_field);
 }
 
-bool Archiver::check_only_for_eval_nondelay_referencing(archive_field   *parent_field)
+
+/*******************************************************************************
+
+********************************************************************************/
+bool Archiver::check_only_for_eval_nondelay_referencing(archive_field* parent_field)
 {
-  archive_field   *current_field = parent_field->first_child;
+  archive_field   *current_field = parent_field->theFirstChild;
   while(current_field)
   {
-    if(current_field->only_for_eval && (current_field->field_treat != ARCHIVE_FIELD_NORMAL))
+    if(current_field->theOnlyForEval && (current_field->theKind != ARCHIVE_FIELD_NORMAL))
     {
-      if((current_field->field_treat == ARCHIVE_FIELD_IS_REFERENCING) &&
-        (current_field->allow_delay2 != ALLOW_DELAY) &&
-        (!current_field->refered->only_for_eval))
+      if((current_field->theKind == ARCHIVE_FIELD_IS_REFERENCING) &&
+        (current_field->theAllowDelay2 != ALLOW_DELAY) &&
+        (!current_field->theReferredField->theOnlyForEval))
       {
         //exchange fields
-      //  exchange_mature_fields(current_field, current_field->refered);
-      //  current_field->only_for_eval = false;
+      //  exchange_mature_fields(current_field, current_field->theReferredField);
+      //  current_field->theOnlyForEval = false;
 
         //must preserve this serialization
-        archive_field *temp_field = current_field->parent;
+        archive_field *temp_field = current_field->theParent;
         while(temp_field)
         {
-          temp_field->only_for_eval = 0;
-          temp_field = temp_field->parent;
+          temp_field->theOnlyForEval = 0;
+          temp_field = temp_field->theParent;
         }
-        clean_only_for_eval(current_field, current_field->only_for_eval);
+        clean_only_for_eval(current_field, current_field->theOnlyForEval);
         return true;
       }
     }
 
-    if(!current_field->is_simple)
+    if(!current_field->theIsSimple)
     {
       if(check_only_for_eval_nondelay_referencing(current_field))
         return true;
     }
-    current_field = current_field->next;
+    current_field = current_field->theNextSibling;
   }
   return false;
 }
 
-void Archiver::replace_only_for_eval_with_null(archive_field   *parent_field)
+
+/*******************************************************************************
+
+********************************************************************************/
+void Archiver::replace_only_for_eval_with_null(archive_field* parent_field)
 {
-  archive_field   *current_field = parent_field->first_child;
+  archive_field   *current_field = parent_field->theFirstChild;
   while(current_field)
   {
-    if(current_field->only_for_eval &&
-      (current_field->field_treat != ARCHIVE_FIELD_NORMAL) &&
-      (current_field->field_treat != ARCHIVE_FIELD_IS_BASECLASS))
+    if(current_field->theOnlyForEval &&
+      (current_field->theKind != ARCHIVE_FIELD_NORMAL) &&
+      (current_field->theKind != ARCHIVE_FIELD_IS_BASECLASS))
     {
     //don't save it, replace it with NULL if possible
       archive_field *null_field = replace_with_null(current_field);
@@ -1004,50 +1231,57 @@
       current_field = null_field;
     }
 
-    if(!current_field->is_simple)
+    if(!current_field->theIsSimple)
     {
       replace_only_for_eval_with_null(current_field);
     }
-    current_field = current_field->next;
+    current_field = current_field->theNextSibling;
   }
 }
 
-void Archiver::clean_only_for_eval(archive_field *field, int substract_value)
+
+/*******************************************************************************
+
+********************************************************************************/
+void Archiver::clean_only_for_eval(archive_field* field, int substract_value)
 {
-  if(field->only_for_eval >= substract_value)
-    field->only_for_eval -= substract_value;
+  if(field->theOnlyForEval >= substract_value)
+    field->theOnlyForEval -= substract_value;
   else
-    field->only_for_eval = 0;
-  if(!field->is_simple)
+    field->theOnlyForEval = 0;
+  if(!field->theIsSimple)
   {
-    archive_field   *child = field->first_child;
+    archive_field   *child = field->theFirstChild;
     while(child)
     {
       clean_only_for_eval(child, substract_value);
-      child = child->next;
+      child = child->theNextSibling;
     }
   }
 }
-/*
+
+
+/*******************************************************************************
   return 0 if not found
   return -1 if field1 is before field2
   return 1  if field1 is after field2
-*/
-int Archiver::check_order(archive_field *parent_field,
-                           archive_field *field1,
-                           archive_field *field2)
+********************************************************************************/
+int Archiver::check_order(
+    archive_field* parent_field,
+    archive_field* field1,
+    archive_field* field2)
 {
 
-  if(field1->order < field2->order)
+  if(field1->theOrder < field2->theOrder)
     return -1;
-  else if(field1->order == field2->order)
+  else if(field1->theOrder == field2->theOrder)
     return 0;
   else
     return 1;
 /*
   archive_field *child;
   int check_ret;
-  child = parent_field->first_child;
+  child = parent_field->theFirstChild;
   while(child)
   {
     if(child == field1)
@@ -1060,61 +1294,55 @@
       if(check_ret)
         return check_ret;
     }
-    child = child->next;
+    child = child->theNextSibling;
   }
   return 0;
 */
 }
 
-archive_field* Archiver::get_prev(archive_field* field)
-{
-  archive_field *temp;
-  temp = field->parent->first_child;
-  if(temp == field)
-    return NULL;
-  while(temp)
-  {
-    if(temp->next == field)
-      return temp;
-    temp = temp->next;
-  }
-  assert(false);//unreachable
-  return NULL;
-}
-
-bool Archiver::check_allowed_delays(archive_field *parent_field)
+
+/*******************************************************************************
+
+********************************************************************************/
+bool Archiver::check_allowed_delays(archive_field* parent_field)
 {
   //check all fields with dont_allow_delay and see if they are delayed
   //exchange field with the reference then
-  archive_field   *child;
-  child = parent_field->first_child;
-  while(child)
+  archive_field* child;
+  child = parent_field->theFirstChild;
+
+  while (child)
   {
-    if((child->field_treat == ARCHIVE_FIELD_IS_REFERENCING) &&
-       (((child->allow_delay2 == DONT_ALLOW_DELAY) && (check_order(out_fields, child, child->refered) < 1) && (child->allow_delay2 == DONT_ALLOW_DELAY)) ||
-       (child->allow_delay2 == SERIALIZE_NOW)))
+    if (child->theKind == ARCHIVE_FIELD_IS_REFERENCING &&
+       ((child->theAllowDelay2 == DONT_ALLOW_DELAY &&
+         check_order(theRootField, child, child->theReferredField) < 1 &&
+         child->theAllowDelay2 == DONT_ALLOW_DELAY) ||
+        child->theAllowDelay2 == SERIALIZE_NOW))
     {
-      if(child->allow_delay2 == SERIALIZE_NOW)
+      if (child->theAllowDelay2 == SERIALIZE_NOW)
       {
       }
-      if((child->refered->field_treat == ARCHIVE_FIELD_NORMAL) ||
-        (child->refered->allow_delay2 == SERIALIZE_NOW))
+
+      if (child->theReferredField->theKind == ARCHIVE_FIELD_NORMAL ||
+          child->theReferredField->theAllowDelay2 == SERIALIZE_NOW)
       {
         //impossible to solve situation
         //need to change the serialization order somewhere
         throw ZORBA_EXCEPTION(zerr::ZCSE0014_INFINITE_CIRCULAR_DEPENDENCIES);
       }
       //exchange fields
-      exchange_mature_fields(child, child->refered);
+      exchange_mature_fields(child, child->theReferredField);
 
-    //  child->refered->allow_delay2 = ALLOW_DELAY;
-      child = child->refered;
+      //  child->theReferredField->theAllowDelay2 = ALLOW_DELAY;
+      child = child->theReferredField;
 
       return true;
     }
-    if(check_allowed_delays(child))
+
+    if (check_allowed_delays(child))
       return true;
-    child = child->next;
+
+    child = child->theNextSibling;
   }
 
   return false;

=== modified file 'src/zorbaserialization/archiver.h'
--- src/zorbaserialization/archiver.h	2012-03-23 17:32:07 +0000
+++ src/zorbaserialization/archiver.h	2012-03-26 01:27:27 +0000
@@ -18,13 +18,13 @@
 #define ZORBA_BINARY_SERIALIZATION_ARCHIVER
 
 #include "util/hashmap32.h"
-//#include "zorbautils/hashmap.h"
 #include <stack>
 
 #include "zorbaserialization/class_serializer.h"
 #include "zorbaserialization/plan_settings.h"
 
-namespace zorba{
+namespace zorba
+{
 
 namespace store
 {
@@ -46,18 +46,44 @@
 /*
   Archiver is working with fields. One archive contains a sequence of fields.
   They can be simple fields or combo fields.
+
   Simple fields: have values of simple types.
   Combo fields: contain a sequence of fields. Are like list, vector, class etc.
   
   Each field has a unique id.
 
-  Special field is a field that points to a previous field. This is to resolve serialization 
-  of pointers to the same object.
+  Special field is a field that points to a previous field. This is to resolve
+  serialization of pointers to the same object.
 */
 
 class ClassSerializer;
 
-enum ArchiveFieldTreat
+
+/*******************************************************************************
+
+  ARCHIVE_FIELD_IS_REFERENCING :
+  ------------------------------
+  A field A that references another field B, where both A and B represent the
+  "same" object.
+
+  ARCHIVE_FIELD_IS_BASECLASS :
+  ----------------------------
+  A field representing a "partial" class object: If an obj O belong to a class C
+  and C is a subclass of a base class B, then a field of ARCHIVE_FIELD_IS_BASECLASS
+  kind is created to represent the serialization of the data members of B.
+
+  ARCHIVE_FIELD_IS_PTR :
+  ----------------------
+
+  ARCHIVE_FIELD_IS_NULL :
+  -----------------------
+  A field representing a NULL pointer.
+
+  ARCHIVE_FIELD_NORMAL :
+  ----------------------
+
+********************************************************************************/
+enum ArchiveFieldKind
 {
   ARCHIVE_FIELD_NORMAL,
   ARCHIVE_FIELD_IS_PTR,
@@ -66,6 +92,21 @@
   ARCHIVE_FIELD_IS_REFERENCING
 };
 
+
+/*******************************************************************************
+
+********************************************************************************/
+enum ENUM_ALLOW_DELAY  
+{
+  ALLOW_DELAY,
+  DONT_ALLOW_DELAY,
+  SERIALIZE_NOW
+};
+
+
+/*******************************************************************************
+
+********************************************************************************/
 struct fwd_ref
 {
   int referencing;
@@ -76,371 +117,557 @@
   bool to_add_ref;
 };
 
-enum ENUM_ALLOW_DELAY  
-{
-  ALLOW_DELAY,
-  DONT_ALLOW_DELAY,
-  SERIALIZE_NOW
-};
-
+
+/*******************************************************************************
+  theId :
+  -------
+  The unique id of the field. Not initialized by constructor.
+
+  theIsSimple:
+  ------------
+  Whether this field represents a "simple" obj or a "compound" obj. 
+
+  theIsClass:
+  -----------
+  Whether this field represents a class obj or not. Class objs are always 
+  considered as "compound", so if theIsClass is true, theIsSimple is false. 
+  However, the reverse is not true: a non-class obj may be simple or compound.
+
+  theClassVersion:
+  ----------------
+  If this field represents a class obj, the class version of that obj.
+
+  theKind:
+  --------
+  The kind of the field. See ArchiveFieldKind enum above.
+
+  theTypeName:
+  ------------
+
+  theTypeNamePosInPool:
+  ---------------------
+
+  theValue:
+  ---------
+  For simple fields
+
+  theValuePosInPool:
+  ------------------
+  Not initialized by constructor.
+
+  thePtr :
+  --------
+  Pointer to the obj represented by this field. NULL if this field is referencing
+  another field that represents the same obj.
+
+  theReferredField:
+  -----------------
+
+  referencing:
+  ------------
+
+  theOrder:
+  ---------
+  Order in the tree. Not initialized by constructor.
+
+  theLevel:
+  ---------
+  The level of this field, i.e., the nuber of fields in the paths from this
+  field to the root. The root is at level 0.
+
+  theNextSibling:
+  ---------------
+
+  theFirstChild:
+  --------------
+
+  theLastChild:
+  -------------
+
+  theParent:
+  ----------
+
+  theOnlyForEval:
+  ---------------
+
+  theAllowDelay2:
+  ---------------
+
+  theBytesSaved:
+  --------------
+
+  theObjectsSaved:
+  ----------------
+
+  The following data members are serialized:
+
+  1. theTypeName  : only if theKind is PTR
+  2. theValue     : except if theKind is REFERENCING
+  3. theReferedId : only if theKind is REFERENCING
+  4. theKind
+  5. theId
+********************************************************************************/
 class archive_field
 {
 public:
-  char  *type;
-  unsigned int   type_str_pos_in_pool;
-  bool  is_simple;
-  unsigned int   version;//for classes
-  enum ArchiveFieldTreat  field_treat;
-  unsigned int   referencing;
-  unsigned int   id;
-  unsigned int   order;///order in the tree
-  unsigned int   level;
-  bool  is_class;
-  const char  *value;//for simple fields
-  unsigned int   value_str_pos_in_pool;
-  union{
-    const SerializeBaseClass  *assoc_class_ptr;
-    const void  *assoc_ptr;
+  unsigned int                 theId;
+
+  bool                         theIsSimple;
+  bool                         theIsClass;
+  unsigned int                 theClassVersion;
+
+  enum ArchiveFieldKind        theKind;
+
+  char                       * theTypeName;
+  unsigned int                 theTypeNamePosInPool;
+
+  const char                 * theValue;
+  unsigned int                 theValuePosInPool;
+
+  union
+  {
+    const SerializeBaseClass * assoc_class_ptr;
+    const void               * assoc_ptr;
   };
 
-  class archive_field  *next;
-  class archive_field  *first_child;
-  class archive_field  *last_child;
-  class archive_field  *parent;
-  class archive_field  *refered;
-
-  int  only_for_eval;
-  ENUM_ALLOW_DELAY  allow_delay2;
+  class archive_field        * theReferredField;
+  unsigned int                 referencing;
+
+  unsigned int                 theOrder;
+
+  unsigned int                 theLevel;
+
+  class archive_field        * theNextSibling;
+  class archive_field        * theFirstChild;
+  class archive_field        * theLastChild;
+  class archive_field        * theParent;
+
+  int                          theOnlyForEval;
+
+  ENUM_ALLOW_DELAY             theAllowDelay2;
+
 #ifdef ZORBA_PLAN_SERIALIZER_STATISTICS
-  unsigned int    bytes_saved;
-  unsigned int    objects_saved;
+  unsigned int                 theBytesSaved;
+  unsigned int                 theObjectsSaved;
 #endif
+
 public:
-  archive_field(const char *type, bool is_simple, bool is_class, 
-                const void *value, const void *assoc_ptr,
-                int version, enum ArchiveFieldTreat  field_treat,
-                archive_field *refered,
-                int only_for_eval,
-                ENUM_ALLOW_DELAY allow_delay,
-                unsigned int level);
+  archive_field(
+      const char* type,
+      bool is_simple,
+      bool is_class, 
+      const void* value,
+      const void* assoc_ptr,
+      int version, 
+      enum ArchiveFieldKind  field_treat,
+      archive_field* refered,
+      int only_for_eval,
+      ENUM_ALLOW_DELAY allow_delay,
+      unsigned int level);
+
   ~archive_field();
 };
 
-//base class
+
+/*******************************************************************************
+
+  theArchiveName:
+  ---------------
+
+  theArchiveInfo:
+  ---------------
+
+  theArchiveVersion:
+  ------------------
+
+  theSerializingOut :
+  -------------------
+  Whether the archiver is used to serialize or deserialize a plan.
+
+  theRootField :
+  --------------
+  The root of the fields tree.
+
+  theCurrentLevel:
+  ----------------
+  The tree level of the most recently added field
+
+********************************************************************************/
 class Archiver
 {
   friend class ClassSerializer;
+
   struct SIMPLE_HASHOUT_FIELD
   {
-    std::string   type;
-    const void *  ptr;
+    std::string    type;
+    const void   * ptr;
+
     SIMPLE_HASHOUT_FIELD() {}
-    SIMPLE_HASHOUT_FIELD(const char *typestr, const void *ptrptr)
+
+    SIMPLE_HASHOUT_FIELD(const char* typestr, const void* ptrptr)
     {
       type = typestr;
-      if(type[type.length()-1] == '*')
+
+      if (type[type.length()-1] == '*')
         type.resize(type.length()-1);
+
       ptr = ptrptr;
-
     }
   };
+
   class SimpleHashoutFieldCompare
   {
   public: 
     uint32_t hash(const SIMPLE_HASHOUT_FIELD& f) const
     {
-      uint32_t  h = 0;
+      uint32_t h = 0;
       h = hashfun::h32(f.type);
       h = hashfun::h32((void*)&f.ptr, sizeof(void*), h);
       return h;
     }
+
     bool equal(const SIMPLE_HASHOUT_FIELD& f1, const SIMPLE_HASHOUT_FIELD& f2) const
     {
-      if((f1.ptr == f2.ptr) && (f1.type == f2.type))
+      if (f1.ptr == f2.ptr && f1.type == f2.type)
         return true;
       else
         return false;
     }
   };
+
+  typedef HashMap<SIMPLE_HASHOUT_FIELD, 
+                  archive_field*,
+                  SimpleHashoutFieldCompare> SimpleFieldMap;
+
 protected:
-  bool  serializing_out;
-  //ClassSerializer *ser;
-
-  int  serialize_base_class;
-
-  //std::list<struct field_ptr_vs_id>   all_reference_list;
-  //hash32map<void*>       *all_reference_list;//key is id, value is assoc_ptr
-  void*                      *all_reference_list;
+  bool                          theSerializingOut;
+
+  int                           serialize_base_class;
+
+  void                       ** all_reference_list;
   
-  std::list<struct fwd_ref>   fwd_reference_list;
-
-  std::string archive_name;
-  std::string archive_info;
-  unsigned long       archive_version;
-
-  class archive_field  *out_fields;
-  class archive_field  *current_compound_field;
-  HashMap<SIMPLE_HASHOUT_FIELD, archive_field*, SimpleHashoutFieldCompare> *simple_hashout_fields;//for simple types
-  hash64map<archive_field*>       *hash_out_fields;//key is ptr, value is archive_field*, for non-simple types
-  std::vector<archive_field*>     orphan_fields;
-
-  int   nr_ids;
-  int   current_class_version;
-
-  bool  read_optional;
-  int   is_temp_field;
-  //bool  is_temp_field_one_level;
-  unsigned int   current_level;
+  std::list<struct fwd_ref>     fwd_reference_list;
+
+  std::string                   theArchiveName;
+  std::string                   theArchiveInfo;
+  unsigned long                 theArchiveVersion;
+
+  archive_field               * theRootField;
+
+  archive_field               * current_compound_field;
+
+  SimpleFieldMap              * simple_hashout_fields;//for simple types
+
+  hash64map<archive_field*>   * hash_out_fields;//key is ptr, value is archive_field*, for non-simple types
+  std::vector<archive_field*>   orphan_fields;
+
+  int                           nr_ids;
+
+  int                           current_class_version;
+
+  bool                          read_optional;
+
+  int                           theIsTempField;
+
+  unsigned int                  theCurrentLevel;
+
   std::stack< std::pair<unsigned int, bool> >   limit_temp_level_stack;
-  bool  internal_archive;
-  int   only_for_eval;
-  bool  serialize_everything;
-  bool  loading_hardcoded_objects;
-  ENUM_ALLOW_DELAY  allow_delay2;
-
-  std::vector<store::Item*>   registered_items;
-  SerializationCallback*      theUserCallback;
+
+  bool                          internal_archive;
+
+  int                           theOnlyForEval;
+
+  bool                          theSerializeEverything;
+
+  bool                          loading_hardcoded_objects;
+
+  ENUM_ALLOW_DELAY              theAllowDelay2;
+
+  std::vector<store::Item*>     registered_items;
+
+  SerializationCallback       * theUserCallback;
 
 public:
-  //CompilerCB  *compiler_cb;///to workaround user defined function compile-at-runtime
-  bool        dont_allow_delay_for_plan_sctx;
+  bool                          dont_allow_delay_for_plan_sctx;
+
 public:
   Archiver(bool is_serializing_out, bool internal_archive=false);
+
   virtual ~Archiver();
 
-public:
-  SerializationCallback*
-  getUserCallback() const { return theUserCallback; }
-
-  void
-  setUserCallback(SerializationCallback* aCallback) { theUserCallback = aCallback; }
-
-public:
-  bool add_simple_field( const char *type, 
-                        const char *value,
-                        const void *orig_ptr,
-                        enum ArchiveFieldTreat field_treat);
-
-  bool add_compound_field( const char *type,
-                          int version,
-                          bool is_class,
-                          const void *info,
-                          const void *ptr,//for classes, pointer to SerializeBaseClass
-                          enum ArchiveFieldTreat field_treat
-                          );
+  bool is_serializing_out() { return theSerializingOut; }
+
+  SerializationCallback* getUserCallback() const { return theUserCallback; }
+
+  void setUserCallback(SerializationCallback* cb) { theUserCallback = cb; }
+
+  bool add_simple_field( 
+      const char* type, 
+      const char* value,
+      const void* orig_ptr,
+      enum ArchiveFieldKind field_treat);
+
+  bool add_compound_field( 
+      const char* type,
+      int version,
+      bool is_class,
+      const void* info,
+      const void* ptr,//for classes, pointer to SerializeBaseClass
+      enum ArchiveFieldKind field_treat);
 
   void add_end_compound_field();
 
-  void set_class_type(const char *class_name);
-
-  //return the id of previous object if it is the same
-  archive_field* check_nonclass_pointer(const char *type, const void *ptr);
-  archive_field* check_class_pointer(const SerializeBaseClass *ptr);
-  
-
-  bool read_next_field( char **type, 
-                        std::string *value,
-                        int *id, 
-                        int *version, 
-                        bool *is_simple, 
-                        bool *is_class,
-                        enum ArchiveFieldTreat *field_treat,
-                        int *referencing);
+  void set_class_type(const char* class_name);
+
+  bool read_next_field( 
+      char** type, 
+      std::string* value,
+      int* id, 
+      int* version, 
+      bool* is_simple, 
+      bool* is_class,
+      enum ArchiveFieldKind* field_treat,
+      int* referencing);
 
   void read_end_current_level();
 
-  virtual bool read_next_field_impl( char **type, 
-                                std::string *value,
-                                int *id, 
-                                int *version, 
-                                bool *is_simple, 
-                                bool *is_class,
-                                enum ArchiveFieldTreat *field_treat,
-                                int *referencing) = 0;
+  virtual bool read_next_field_impl(
+      char** type, 
+      std::string* value,
+      int* id, 
+      int* version, 
+      bool* is_simple, 
+      bool* is_class,
+      enum ArchiveFieldKind* field_treat,
+      int* referencing) = 0;
 
   virtual void read_end_current_level_impl() = 0;
 
 
 protected:
+  archive_field* lookup_nonclass_field(const char* type, const void* ptr);
 
-  virtual void create_archive(const char *archive_name, 
-                              const char *archive_info,
-                              int archive_version);
+  archive_field* lookup_class_field(const SerializeBaseClass* ptr);
 
   virtual void serialize_out() = 0;
 
-  virtual void read_archive_description(std::string *archive_name,
-                                        std::string *archive_info,
-                                        int *archive_version, 
-                                        int *nr_ids)
+  virtual void read_archive_description(
+      std::string* archive_name,
+      std::string* archive_info,
+      int* archive_version, 
+      int* nr_ids)
   {
-    *archive_name = this->archive_name;
-    *archive_info = this->archive_info;
-    *archive_version = this->archive_version;
+    *archive_name = theArchiveName;
+    *archive_info = theArchiveInfo;
+    *archive_version = theArchiveVersion;
     *nr_ids = this->nr_ids;
   }
 
+  void replace_field(archive_field* new_field, archive_field* ref_field);
 
-protected:
-  archive_field* check_nonclass_pointer_internal(const void *ptr, archive_field *fields);
-  archive_field* check_class_pointer_internal(const SerializeBaseClass *ptr, archive_field *fields);
-  void replace_field(archive_field  *new_field, archive_field  *ref_field);
-  void exchange_fields(archive_field  *new_field, archive_field  *ref_field);
+  void exchange_fields(archive_field* new_field, archive_field* ref_field);
 
   void root_tag_is_read();
-  void register_pointers_internal(archive_field *fields);
+
+  void register_pointers_internal(archive_field* fields);
+
   void prepare_serialize_out();
-  archive_field* replace_with_null(archive_field *current_field);
-  int compute_field_depth(archive_field *field);
-  int get_only_for_eval(archive_field *field);
-  archive_field* find_top_most_eval_only_field(archive_field *parent_field);
-  void check_compound_fields(archive_field   *parent_field);
-  bool check_only_for_eval_nondelay_referencing(archive_field   *parent_field);
-  void replace_only_for_eval_with_null(archive_field   *parent_field);
-  void clean_only_for_eval(archive_field *field, int substract_value);
-  void exchange_mature_fields(archive_field *field1, archive_field *field2);
+
+  archive_field* replace_with_null(archive_field* current_field);
+
+  int compute_field_depth(archive_field* field);
+
+  int get_only_for_eval(archive_field* field);
+
+  archive_field* find_top_most_eval_only_field(archive_field* parent_field);
+
+  void check_compound_fields(archive_field* parent_field);
+
+  bool check_only_for_eval_nondelay_referencing(archive_field* parent_field);
+
+  void replace_only_for_eval_with_null(archive_field* parent_field);
+
+  void clean_only_for_eval(archive_field* field, int substract_value);
+
+  void exchange_mature_fields(archive_field* field1, archive_field* field2);
+
   archive_field* get_prev(archive_field* field);
-  int check_order(archive_field *parent_field,
-                  archive_field *field1,
-                  archive_field *field2);
-  bool check_allowed_delays(archive_field *parent_field);
+
+  int check_order(
+      archive_field* parent_field,
+      archive_field* field1,
+      archive_field* field2);
+
+  bool check_allowed_delays(archive_field* parent_field);
 
 public:
-  void check_simple_field(bool retval, 
-                                  const char *type,
-                                  const char *required_type, 
-                                  bool is_simple, 
-                                  enum ArchiveFieldTreat  field_treat,
-                                  enum ArchiveFieldTreat  required_field_treat,
-                                  int id);
-  void check_nonclass_field(bool retval, 
-                                  const char *type,
-                                  const char *required_type, 
-                                  bool is_simple, 
-                                  bool is_class, 
-                                  enum ArchiveFieldTreat  field_treat,
-                                  enum ArchiveFieldTreat  required_field_treat,
-                                  int id);
-  void check_class_field(bool retval, 
-                                  const char *type,
-                                  const char *required_type, 
-                                  bool is_simple, 
-                                  bool is_class, 
-                                  enum ArchiveFieldTreat  field_treat,
-                                  enum ArchiveFieldTreat  required_field_treat,
-                                  int id);
-  void register_reference(int id, enum ArchiveFieldTreat field_treat, const void *ptr);
-  void register_delay_reference(void **ptr, bool is_class, const char *class_name, int referencing);
-  void reconf_last_delayed_rcobject(void **last_obj, void **new_last_obj, bool to_add_ref);
+  void check_simple_field(
+      bool retval, 
+      const char* type,
+      const char* required_type, 
+      bool is_simple, 
+      enum ArchiveFieldKind field_treat,
+      enum ArchiveFieldKind required_field_treat,
+      int id);
+
+  void check_nonclass_field(
+      bool retval, 
+      const char* type,
+      const char* required_type, 
+      bool is_simple, 
+      bool is_class, 
+      enum ArchiveFieldKind field_treat,
+      enum ArchiveFieldKind required_field_treat,
+      int id);
+
+  void check_class_field(
+      bool retval, 
+      const char* type,
+      const char* required_type, 
+      bool is_simple, 
+      bool is_class, 
+      enum ArchiveFieldKind field_treat,
+      enum ArchiveFieldKind required_field_treat,
+      int id);
+
+  void register_reference(
+      int id, 
+      enum ArchiveFieldKind field_treat,
+      const void* ptr);
+
+  void register_delay_reference(
+      void** ptr,
+      bool is_class,
+      const char* class_name,
+      int referencing);
+
+  void reconf_last_delayed_rcobject(
+      void** last_obj, 
+      void** new_last_obj,
+      bool to_add_ref);
+
   void register_item(store::Item* i);
 
   int get_class_version();
+
   void set_class_version(int new_class_version);
 
-
   //to help check class name at runtime
-  void    set_serialize_base_class(bool s)
+  void  set_serialize_base_class(bool s)
   {
     if(s)
       serialize_base_class++;
     else
       serialize_base_class--;
+
     assert(serialize_base_class >= 0);
     assert(serialize_base_class <= 1);
   }
-  bool    is_serialize_base_class()
-  {
-    return serialize_base_class > 0;
-  }
-  bool  is_serializing_out()//true out, false in
-  {
-    return serializing_out;
-  }
-//  ClassSerializer*  get_serializer()
-//  {
-//    return ser;
-//  }
-  void *get_reference_value(int refid);
+
+  bool is_serialize_base_class() { return serialize_base_class > 0; }
+
+  void* get_reference_value(int refid);
+
   void finalize_input_serialization();
 
   void set_read_optional_field(bool activate_optional)
   {
     this->read_optional = activate_optional;
   }
+
   bool get_read_optional_field() { return this->read_optional; }
+
   void set_is_temp_field(bool is_temp)
   {
-    if(is_temp)
-      this->is_temp_field++;
+    if (is_temp)
+      theIsTempField++;
     else
-      this->is_temp_field--;
-    assert(is_temp_field >= 0);
+      theIsTempField--;
+
+    assert(theIsTempField >= 0);
   }
-  bool get_is_temp_field() { return (this->is_temp_field > 0); }
+
+  bool get_is_temp_field() { return (theIsTempField > 0); }
+
   void set_is_temp_field_one_level(bool is_temp, bool also_for_ptr = false)
   {
-    if(is_temp)
-      limit_temp_level_stack.push(std::pair<int, bool>(current_level + 1, also_for_ptr));
+    if (is_temp)
+      limit_temp_level_stack.push(std::pair<int, bool>(theCurrentLevel + 1,
+                                                       also_for_ptr));
     else
       limit_temp_level_stack.pop();
   }
+
   bool get_is_temp_field_one_level() 
   {
-    //if(get_is_temp_field()) return true;
-    if(limit_temp_level_stack.empty())
+    if (limit_temp_level_stack.empty())
+    {
       return false;
-    else if(limit_temp_level_stack.top().first == current_level)
+    }
+    else if (limit_temp_level_stack.top().first == theCurrentLevel)
+    {
       return true;
+    }
     else
     {
-      unsigned int   lastlevel = limit_temp_level_stack.top().first;
-      archive_field   *temp_field = current_compound_field;
-      while(temp_field && (temp_field->level >= lastlevel))
+      unsigned int lastlevel = limit_temp_level_stack.top().first;
+      archive_field* temp_field = current_compound_field;
+
+      while (temp_field && (temp_field->theLevel >= lastlevel))
       {
-        if((temp_field->field_treat == ARCHIVE_FIELD_IS_PTR) ||
-           (temp_field->field_treat == ARCHIVE_FIELD_IS_REFERENCING))
+        if (temp_field->theKind == ARCHIVE_FIELD_IS_PTR ||
+            temp_field->theKind == ARCHIVE_FIELD_IS_REFERENCING)
            return false;
-        temp_field = temp_field->parent;
+
+        temp_field = temp_field->theParent;
       }
-      if(temp_field)
+
+      if (temp_field)
         return true;
       else
         return false;
     }
   } 
-  bool get_is_temp_field_also_for_ptr() {return (limit_temp_level_stack.top().first == current_level) && limit_temp_level_stack.top().second;} 
+
+  bool get_is_temp_field_also_for_ptr() 
+  {
+    return (limit_temp_level_stack.top().first == theCurrentLevel &&
+            limit_temp_level_stack.top().second);
+  } 
 
   int get_nr_ids();
 
-  bool is_serialize_everything() {return this->serialize_everything;}
-  void set_serialize_everything() {this->serialize_everything = true;}
-
-  int get_serialize_only_for_eval() {return only_for_eval;}
+  bool is_serialize_everything() { return theSerializeEverything; }
+
+  void set_serialize_everything() { theSerializeEverything = true; }
+
+  int get_serialize_only_for_eval() { return theOnlyForEval; }
+
   void set_serialize_only_for_eval(bool evalonly)
   {
-    if(evalonly)
-      only_for_eval++;
+    if (evalonly)
+      theOnlyForEval++;
     else
-      only_for_eval--;
-    assert(only_for_eval >= 0);
+      theOnlyForEval--;
+
+    assert(theOnlyForEval >= 0);
   }
+
   void set_loading_hardcoded_objects(bool set_hardcoded)
   {
     this->loading_hardcoded_objects = set_hardcoded;
   }
-  bool is_loading_hardcoded_objects()
-  {
-    return loading_hardcoded_objects;
-  }
+
+  bool is_loading_hardcoded_objects() { return loading_hardcoded_objects; }
+
   void dont_allow_delay(ENUM_ALLOW_DELAY d = DONT_ALLOW_DELAY)
   {
-    this->allow_delay2 = d;
-  }
-  void reset_allow_delay()
-  {
-    this->allow_delay2 = ALLOW_DELAY;
-  }
-  ENUM_ALLOW_DELAY get_allow_delay() {return this->allow_delay2;}
+    theAllowDelay2 = d;
+  }
+
+  void reset_allow_delay() { theAllowDelay2 = ALLOW_DELAY; }
+
+  ENUM_ALLOW_DELAY get_allow_delay() { return theAllowDelay2; }
 };
 
   

=== modified file 'src/zorbaserialization/bin_archiver.cpp'
--- src/zorbaserialization/bin_archiver.cpp	2012-03-23 17:32:07 +0000
+++ src/zorbaserialization/bin_archiver.cpp	2012-03-26 01:27:27 +0000
@@ -19,15 +19,22 @@
 #include "diagnostics/xquery_diagnostics.h"
 #include <fstream>
 
-namespace zorba{
-  namespace serialization{
+namespace zorba
+{
+
+namespace serialization
+{
 
 #define ZORBA_BIN_SERIALIZED_PLAN_STRING    "ZORBA-XQUERY BINARY SERIALIZED PLAN"
 #define BUFFER_SEGMENT_SIZE  2*1024*1024
 
-BinArchiver::BinArchiver(std::istream *is) : Archiver(false)
+/*******************************************************************************
+  Open archiver for input
+********************************************************************************/
+BinArchiver::BinArchiver(std::istream* is) 
+  :
+  Archiver(false)
 {
-  //open archiver for input
   this->is = is;
   this->os = NULL;
   this->last_id = 0;
@@ -68,9 +75,9 @@
   }
   in_current = in_buffer;
 
-  read_string(archive_name);
-  read_string(archive_info);
-  archive_version = read_int();
+  read_string(theArchiveName);
+  read_string(theArchiveInfo);
+  theArchiveVersion = read_int();
   nr_ids = read_int();
   unsigned int is_release = read_int();
 #ifndef NDEBUG
@@ -88,12 +95,16 @@
   read_string_pool();
 
   root_tag_is_read();
-
 }
 
-BinArchiver::BinArchiver(std::ostream *os) : Archiver(true)
+
+/*******************************************************************************
+  Open archiver for output
+********************************************************************************/
+BinArchiver::BinArchiver(std::ostream* os)
+  :
+  Archiver(true)
 {
-  //open archiver for output
   this->is = NULL;
   this->os = os;
   this->last_id = 0;
@@ -103,13 +114,21 @@
   in_buffer = NULL;
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 BinArchiver::~BinArchiver()
 {
-  if(in_buffer)
+  if (in_buffer)
     free(in_buffer);
 }
 
+
 #ifdef ZORBA_PLAN_SERIALIZER_STATISTICS
+/*******************************************************************************
+
+********************************************************************************/
 void add_indentation(std::ostream &os, unsigned int indent)
 {
   while(indent--)
@@ -118,7 +137,11 @@
   }
 }
 
-void write_xml_name(std::ostream &os, const char *type)
+
+/*******************************************************************************
+
+********************************************************************************/
+void write_xml_name(std::ostream& os, const char* type)
 {
   if(!type || !*type)
   {
@@ -135,29 +158,36 @@
   }
 }
 
-void output_statistics_archive_field(std::ostream &os, unsigned int indent, archive_field *parent)
+
+/*******************************************************************************
+
+********************************************************************************/
+void output_statistics_archive_field(
+    std::ostream& os,
+    unsigned int indent,
+    archive_field* parent)
 {
   add_indentation(os, indent);
   os << "<";
-  write_xml_name(os, parent->type);
+  write_xml_name(os, parent->theTypeName);
   os << " n=\"" << parent->objects_saved << "\"";
-  os << " s=\"" << parent->bytes_saved << "\"";
-  if(parent->field_treat == ARCHIVE_FIELD_IS_REFERENCING)
+  os << " s=\"" << parent->thebytesSaved << "\"";
+  if(parent->theKind == ARCHIVE_FIELD_IS_REFERENCING)
       os << " t=\"ref\"";
-  else if(parent->field_treat == ARCHIVE_FIELD_IS_PTR)
+  else if(parent->theKind == ARCHIVE_FIELD_IS_PTR)
       os << " t=\"ptr\"";
-  if((!parent->is_simple) && (parent->field_treat != ARCHIVE_FIELD_IS_REFERENCING))
+  if((!parent->theIsSimple) && (parent->theKind != ARCHIVE_FIELD_IS_REFERENCING))
   {
     os << ">" << std::endl;
     archive_field   *current_field = parent->first_child;
     while(current_field)
     {
       output_statistics_archive_field(os, indent+2, current_field);
-      current_field = current_field->next;
+      current_field = current_field->theNextSibling;
     }
     add_indentation(os, indent);
     os << "</";
-    write_xml_name(os, parent->type);
+    write_xml_name(os, parent->theTypeName);
     os << ">" << std::endl;
   }
   else
@@ -167,9 +197,13 @@
 }
 #endif
 
+
+/*******************************************************************************
+
+********************************************************************************/
 void BinArchiver::serialize_out()
 {
-  if(!os)
+  if (!os)
   {
     throw ZORBA_EXCEPTION(zerr::ZCSE0007_INPUT_ARCHIVE_USED_FOR_OUT_SERIALIZATION);
   }
@@ -185,10 +219,12 @@
 
   os->write(ZORBA_BIN_SERIALIZED_PLAN_STRING, sizeof(ZORBA_BIN_SERIALIZED_PLAN_STRING));
 
-  os->write(archive_name.c_str(), (std::streamsize)archive_name.length()+1);
-  os->write(archive_info.c_str(), (std::streamsize)archive_info.length()+1);
-  write_int(archive_version);
+  os->write(theArchiveName.c_str(), (std::streamsize)theArchiveName.length()+1);
+  os->write(theArchiveInfo.c_str(), (std::streamsize)theArchiveInfo.length()+1);
+  write_int(theArchiveVersion);
+
   write_int(nr_ids);
+
 #ifndef NDEBUG
   write_int(0);//for debug
 #else
@@ -196,13 +232,15 @@
 #endif
 
   //first gather all strings in a string pool
-  collect_strings(out_fields);
+  collect_strings(theRootField);
+
   //now serialize the string pool
   serialize_out_string_pool();
 
   //now serialize the fields
-  serialize_compound_fields(out_fields);
-  if(bitfill)
+  serialize_compound_fields(theRootField);
+
+  if (bitfill)
   {
     current_byte <<= (8-bitfill);
     os->write((char*)&current_byte, 1);
@@ -210,6 +248,7 @@
     bytes_saved++;
 #endif
   }
+
 #ifdef ZORBA_PLAN_SERIALIZER_STATISTICS
   std::ofstream   plan_xml("plan.xml");
   plan_xml << "<plan objects_saved=\"" << objects_saved << "\""
@@ -229,6 +268,10 @@
 #endif
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 int BinArchiver::add_to_string_pool(const char *str)
 {
   if(!str)
@@ -252,42 +295,52 @@
   return str_pos;
 }
 
-void BinArchiver::collect_strings(archive_field   *parent_field)
+
+/*******************************************************************************
+
+********************************************************************************/
+void BinArchiver::collect_strings(archive_field* parent_field)
 {
-  archive_field   *current_field = parent_field->first_child;
-  while(current_field)
+  archive_field* current_field = parent_field->theFirstChild;
+  while (current_field)
   {
-    if(current_field->field_treat != ARCHIVE_FIELD_IS_NULL)
+    if(current_field->theKind != ARCHIVE_FIELD_IS_NULL)
     {
 #ifdef NDEBUG
-      if(current_field->is_class && (current_field->field_treat == ARCHIVE_FIELD_IS_PTR))
+      if(current_field->theIsClass && (current_field->theKind == ARCHIVE_FIELD_IS_PTR))
 #endif
-        current_field->type_str_pos_in_pool = add_to_string_pool(current_field->type);
-      if(current_field->field_treat != ARCHIVE_FIELD_IS_REFERENCING)
+        current_field->theTypeNamePosInPool = add_to_string_pool(current_field->theTypeName);
+      if(current_field->theKind != ARCHIVE_FIELD_IS_REFERENCING)
       {
-        current_field->value_str_pos_in_pool = add_to_string_pool(current_field->value);
+        current_field->theValuePosInPool = add_to_string_pool(current_field->theValue);
       }
     }
-    if(!current_field->is_simple)
+
+    if(!current_field->theIsSimple)
     {
-      if(current_field->field_treat != ARCHIVE_FIELD_IS_REFERENCING)
+      if(current_field->theKind != ARCHIVE_FIELD_IS_REFERENCING)
       {
         collect_strings(current_field);
       }
     }
-    current_field = current_field->next;
+
+    current_field = current_field->theNextSibling;
   }
 }
 
-void   BinArchiver::serialize_out_string_pool()
+
+/*******************************************************************************
+
+********************************************************************************/
+void BinArchiver::serialize_out_string_pool()
 {
   //sort strings based on use count
   unsigned int i,j;
-  for(i=0;i<strings_pos.size();i++)
+  for (i = 0; i < strings_pos.size(); i++)
   {
-    for(j=i+1;j<strings_pos.size();j++)
+    for (j = i+1; j < strings_pos.size(); j++)
     {
-      if(strings.at(strings_pos[i]).count < strings.at(strings_pos[j]).count)
+      if (strings.at(strings_pos[i]).count < strings.at(strings_pos[j]).count)
       {
         unsigned int temp;
         temp = strings_pos[i];
@@ -317,70 +370,79 @@
   }
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 void BinArchiver::serialize_compound_fields(archive_field   *parent_field)
 {
 #ifdef ZORBA_PLAN_SERIALIZER_STATISTICS
   unsigned int    bytes_saved1 = bytes_saved;
   unsigned int    objects_saved1 = objects_saved;
 #endif
-  archive_field   *current_field = parent_field->first_child;
+  archive_field* current_field = parent_field->theFirstChild;
+
   while(current_field)
   {
 #ifndef NDEBUG
     unsigned char tempbyte;
     tempbyte = 0;
-    tempbyte |= current_field->is_simple ? 1 : 0;
-    tempbyte |= current_field->is_class ? 1<<1 : 0;
-    tempbyte |= (current_field->field_treat&0x0F)<<4;
+    tempbyte |= current_field->theIsSimple ? 1 : 0;
+    tempbyte |= current_field->theIsClass ? 1<<1 : 0;
+    tempbyte |= (current_field->theKind&0x0F)<<4;
     write_bits(tempbyte, 8);
 #else
-    //write_bit(current_field->is_class ? 1 : 0);
-    //write_bits(current_field->field_treat, 3);
     unsigned char small_treat = 0;
-    switch(current_field->field_treat)
+    switch(current_field->theKind)
     {
     case ARCHIVE_FIELD_IS_NULL:          small_treat = 1;break;
     case ARCHIVE_FIELD_IS_REFERENCING:   small_treat = 2;break;
     case ARCHIVE_FIELD_IS_BASECLASS:     small_treat = 3;break;//??
     default: break;
     }
+
     write_bits(small_treat, 2);
 #endif
-    if(current_field->field_treat != ARCHIVE_FIELD_IS_NULL)
+
+    if(current_field->theKind != ARCHIVE_FIELD_IS_NULL)
     {
 #ifdef NDEBUG
-      if(current_field->is_class && (current_field->field_treat == ARCHIVE_FIELD_IS_PTR))
+      if (current_field->theIsClass && (current_field->theKind == ARCHIVE_FIELD_IS_PTR))
 #endif
       {
-        if(!current_field->type)
+        if (!current_field->theTypeName)
           write_int_exp2(0);
         else
-          write_int_exp2(strings.at(current_field->type_str_pos_in_pool-1).final_pos);
+          write_int_exp2(strings.at(current_field->theTypeNamePosInPool-1).final_pos);
       }
-      write_int_exp(current_field->id - this->last_id);
-      last_id = current_field->id;
-      if(current_field->field_treat != ARCHIVE_FIELD_IS_REFERENCING)
+
+      write_int_exp(current_field->theId - this->last_id);
+
+      last_id = current_field->theId;
+
+      if(current_field->theKind != ARCHIVE_FIELD_IS_REFERENCING)
       {
 #ifndef NDEBUG
-        write_int(current_field->version);
+        write_int(current_field->theClassVersion);
 #endif
-        if(!current_field->value_str_pos_in_pool)
-          write_int_exp2(current_field->value_str_pos_in_pool);
+        if(!current_field->theValuePosInPool)
+          write_int_exp2(current_field->theValuePosInPool);
         else
-          write_int_exp2(strings.at(current_field->value_str_pos_in_pool-1).final_pos);
+          write_int_exp2(strings.at(current_field->theValuePosInPool-1).final_pos);
       }
       else
         write_int(current_field->referencing);
     }
+
 #ifdef ZORBA_PLAN_SERIALIZER_STATISTICS
     objects_saved++;
-    if(current_field->field_treat == ARCHIVE_FIELD_IS_PTR)
+    if(current_field->theKind == ARCHIVE_FIELD_IS_PTR)
       nr_ptrs++;
 #endif
 
-    if(!current_field->is_simple)
+    if (!current_field->theIsSimple)
     {
-      if(current_field->field_treat != ARCHIVE_FIELD_IS_REFERENCING)
+      if(current_field->theKind != ARCHIVE_FIELD_IS_REFERENCING)
       {
         serialize_compound_fields(current_field);
 #ifndef NDEBUG
@@ -390,16 +452,21 @@
 #endif
       }
     }
-    current_field = current_field->next;
+
+    current_field = current_field->theNextSibling;
   }
 
 #ifdef ZORBA_PLAN_SERIALIZER_STATISTICS
   //gather statistics for this node
-  parent_field->bytes_saved = bytes_saved - bytes_saved1;
-  parent_field->objects_saved = objects_saved - objects_saved1;
+  parent_field->thebytesSaved = bytes_saved - bytes_saved1;
+  parent_field->theObjectsSaved = objects_saved - objects_saved1;
 #endif
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 void BinArchiver::write_string(const char *str)
 {
   os->write(str, (std::streamsize)strlen(str)+1);
@@ -408,6 +475,10 @@
 #endif
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 void BinArchiver::write_bit(unsigned char bit)
 {
   current_byte <<= 1;
@@ -424,6 +495,10 @@
   }
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 void BinArchiver::write_bits(unsigned int value, unsigned int bits)
 {
   while(bits)
@@ -433,6 +508,10 @@
   }
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 void BinArchiver::write_int(unsigned int intval)
 {
   //write 7 bits per byte, only significant bits
@@ -449,9 +528,12 @@
   tmp = (intval & 0x7F) | 0x80;
   //os->write((char*)&tmp, 1);
   write_bits(tmp, 8);
-
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 void BinArchiver::write_int_exp(unsigned int intval)
 {
   if(intval == 1)
@@ -480,6 +562,10 @@
   }
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 void BinArchiver::write_int_exp2(unsigned int intval)
 {
   if(intval < (1<<4))
@@ -511,6 +597,9 @@
 
 ////////////reading archive
 
+/*******************************************************************************
+
+********************************************************************************/
 void BinArchiver::read_string(std::string &str)
 {
   //char c;
@@ -534,6 +623,10 @@
   in_current++;
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 void BinArchiver::read_string(char* str)
 {
   //char c;
@@ -561,6 +654,10 @@
   in_current++;
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 unsigned char BinArchiver::read_bit()
 {
   if(bitfill == 0)
@@ -575,6 +672,10 @@
   return result;
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 unsigned int BinArchiver::read_bits(unsigned int bits)
 {
   unsigned int result = 0;
@@ -608,6 +709,10 @@
   return result;
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 unsigned int BinArchiver::read_int()
 {
   unsigned int outval = 0;
@@ -624,6 +729,10 @@
   return outval;
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 unsigned int BinArchiver::read_int_exp()
 {
   unsigned char bit;
@@ -642,6 +751,10 @@
     return read_bits(32);
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 unsigned int BinArchiver::read_int_exp2()
 {
   unsigned char bit;
@@ -661,6 +774,10 @@
 
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 void BinArchiver::read_string_pool()
 {
   strings.clear();
@@ -682,16 +799,21 @@
   bitfill = 8;
 }
 
-bool BinArchiver::read_next_field_impl( char **type, 
-                              std::string *value,
-                              int *id, 
-                              int *version, 
-                              bool *is_simple, 
-                              bool *is_class,
-                              enum ArchiveFieldTreat *field_treat,
-                              int *referencing)
+
+/*******************************************************************************
+
+********************************************************************************/
+bool BinArchiver::read_next_field_impl(
+    char** type, 
+    std::string* value,
+    int* id, 
+    int* version, 
+    bool* is_simple, 
+    bool* is_class,
+    enum ArchiveFieldKind* field_treat,
+    int* referencing)
 {
-  if(!is)
+  if (!is)
   {
     throw ZORBA_EXCEPTION(zerr::ZCSE0008_OUTPUT_ARCHIVE_USED_FOR_IN_SERIALIZATION);
   }
@@ -702,7 +824,7 @@
 #ifndef NDEBUG 
   *is_simple = false; 
   *is_class = false;
-  *field_treat = (enum ArchiveFieldTreat)-1;
+  *field_treat = (enum ArchiveFieldKind)-1;
 #endif
   *referencing = -1;
 
@@ -714,11 +836,12 @@
     return false;
   *is_simple = tempbyte & 0x01 ? true : false;
   *is_class = tempbyte & 0x02 ? true : false;
-  *field_treat = (enum ArchiveFieldTreat)((tempbyte>>4)&0x0F);
+  *field_treat = (enum ArchiveFieldKind)((tempbyte>>4)&0x0F);
 #else
   //*is_class = read_bit();
-  //*field_treat = (enum ArchiveFieldTreat)read_bits(3);
+  //*field_treat = (enum ArchiveFieldKind)read_bits(3);
   unsigned char small_treat = read_bits(2);
+
   switch(small_treat)
   {
   case 1: *field_treat = ARCHIVE_FIELD_IS_NULL;break;
@@ -727,6 +850,7 @@
   }
 #endif
   assert(*field_treat <= ARCHIVE_FIELD_IS_REFERENCING);
+
   if(*field_treat != ARCHIVE_FIELD_IS_NULL)
   {
 #ifdef NDEBUG
@@ -761,8 +885,9 @@
 }
 
 
-
-
+/*******************************************************************************
+
+********************************************************************************/
 void BinArchiver::read_end_current_level_impl()
 {
 #ifndef NDEBUG

=== modified file 'src/zorbaserialization/bin_archiver.h'
--- src/zorbaserialization/bin_archiver.h	2012-03-23 17:32:07 +0000
+++ src/zorbaserialization/bin_archiver.h	2012-03-26 01:27:27 +0000
@@ -29,83 +29,98 @@
 
 class BinArchiver : public Archiver
 {
-  std::istream *is;
-  std::ostream *os;
-
-//  int   read_tag_level;
-//  char  field_type[1000];
-  bool  has_attributes;
-  bool  is_compound_field_without_children;
-
-  HashCharPtrObj<int>    string_pool;
+  std::istream             * is;
+
+  std::ostream             * os;
+
+  bool                       has_attributes;
+  bool                       is_compound_field_without_children;
+
+  HashCharPtrObj<int>        string_pool;
+
   typedef struct
   {
     std::string   str;
     unsigned int  count;
     unsigned int  final_pos;//1 based
-  }STRING_POS;
+  } STRING_POS;
+
   std::vector<STRING_POS>    strings;
   std::vector<unsigned int>  strings_pos;
 
-  unsigned int last_id;
-  unsigned char current_byte;
-  unsigned char bitfill;
+  unsigned int               last_id;
+  unsigned char              current_byte;
+  unsigned char              bitfill;
 
-  unsigned char *in_buffer;
-  unsigned char *in_current;
-  size_t        size_read;
+  unsigned char            * in_buffer;
+  unsigned char            * in_current;
+  size_t                     size_read;
 
 #ifdef ZORBA_PLAN_SERIALIZER_STATISTICS
-  unsigned int    bytes_saved;
-  unsigned int    objects_saved;
-  unsigned int    nr_ptrs;
-  unsigned int    strings_saved;
+  unsigned int               bytes_saved;
+  unsigned int               objects_saved;
+  unsigned int               nr_ptrs;
+  unsigned int               strings_saved;
 #endif
 
 public:
-  BinArchiver(std::istream *is);
-  BinArchiver(std::ostream *os);
+  BinArchiver(std::istream* is);
+
+  BinArchiver(std::ostream* os);
+
   virtual ~BinArchiver();
 
-  virtual bool read_next_field_impl( char **type, 
-                                std::string *value,
-                                int *id, 
-                                int *version, 
-                                bool *is_simple, 
-                                bool *is_class,
-                                enum ArchiveFieldTreat *field_treat,
-                                int *referencing);
+  virtual bool read_next_field_impl( 
+      char** type, 
+      std::string* value,
+      int* id, 
+      int* version, 
+      bool* is_simple, 
+      bool* is_class,
+      enum ArchiveFieldKind* field_treat,
+      int* referencing);
 
   virtual void read_end_current_level_impl();
 
-
-///////////////////////////////////
   virtual void serialize_out();
 
-
 protected:
   //writing
-  int add_to_string_pool(const char *str);
-  void collect_strings(archive_field   *parent_field);
+  int add_to_string_pool(const char* str);
+
+  void collect_strings(archive_field* parent_field);
+
   void serialize_out_string_pool();
-  void serialize_compound_fields(archive_field   *parent_field);
-  //void encode_string(const char *value);
-  //const char *get_field_treat_string(enum ArchiveFieldTreat field_treat);
-  void write_string(const char *str);
+
+  void serialize_compound_fields(archive_field* parent_field);
+
+  void write_string(const char* str);
+
   void write_bit(unsigned char bit);
+
   void write_bits(unsigned int value, unsigned int bits);
+
   void write_int(unsigned int intval);
+
   void write_int_exp(unsigned int intval);
+
   void write_int_exp2(unsigned int intval);
 
   //reading
-  void read_string(std::string &str);
+  void read_string(std::string& str);
+
   void read_string(char* str);
+
   unsigned char read_bit();
-  unsigned int  read_bits(unsigned int bits);
-  unsigned int  read_int();
-  unsigned int  read_int_exp();
-  unsigned int  read_int_exp2();
+
+  unsigned int read_bits(unsigned int bits);
+
+  unsigned int read_int();
+
+  unsigned int read_int_exp();
+
+  unsigned int read_int_exp2();
+
   void read_string_pool();
 };
 

=== modified file 'src/zorbaserialization/class_serializer.cpp'
--- src/zorbaserialization/class_serializer.cpp	2012-03-23 17:32:07 +0000
+++ src/zorbaserialization/class_serializer.cpp	2012-03-26 01:27:27 +0000
@@ -25,9 +25,16 @@
 
 #include "zorbatypes/floatimpl.h"
 
-namespace zorba{
-  namespace serialization{
-
+namespace zorba
+{
+
+namespace serialization
+{
+
+
+/*******************************************************************************
+
+********************************************************************************/
 class ClassFactoriesCompare
 {
 public: 
@@ -47,6 +54,9 @@
 };
 
 
+/*******************************************************************************
+
+********************************************************************************/
 class ClassFactoriesMap : public zorba::HashMap<const char *, class_deserializer  *, ClassFactoriesCompare>
 {
 public:
@@ -57,6 +67,10 @@
 
 //////////////////////////////////////////////
 ///////////////////////////////////////////Global serialization Operators
+
+/*******************************************************************************
+
+********************************************************************************/
 ClassSerializer::ClassSerializer() : class_names(1000), class_names_count(0)
 {
 /*
@@ -72,6 +86,10 @@
   harcoded_objects_archive = new MemArchiver(true, true);//simulate serialize out
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 ClassSerializer::~ClassSerializer()
 {
 /*
@@ -82,6 +100,9 @@
 }
 
 
+/*******************************************************************************
+
+********************************************************************************/
 ClassSerializer* ClassSerializer::getInstance()
 {
   static ClassSerializer theInstance;
@@ -89,6 +110,9 @@
 }
 
 
+/*******************************************************************************
+
+********************************************************************************/
 void ClassSerializer::register_class_factory(
     const char *class_name,
     class_deserializer *class_factory)
@@ -130,6 +154,10 @@
   t1 = clock();
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 class_deserializer *ClassSerializer::get_class_factory(const char *classname)
 {
 /*
@@ -157,12 +185,18 @@
 }
 
 
+/*******************************************************************************
+
+********************************************************************************/
 Archiver* ClassSerializer::getArchiverForHardcodedObjects()
 {
   return harcoded_objects_archive;
 }
 
 
+/*******************************************************************************
+
+********************************************************************************/
 void ClassSerializer::destroyArchiverForHardcodedObjects()
 {
   delete harcoded_objects_archive;
@@ -172,6 +206,10 @@
 
 //////////////////////////////////////////////
 ///////////////////////////////////////////Global serialization Operators
+
+/*******************************************************************************
+
+********************************************************************************/
 void operator&(Archiver &ar, int &obj)
 {
   if(ar.is_serializing_out())
@@ -189,7 +227,7 @@
     int   version;
     bool  is_simple = true;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
@@ -203,6 +241,9 @@
 }
 
 
+/*******************************************************************************
+
+********************************************************************************/
 void operator&(Archiver &ar, uint32_t &obj)
 {
   if(ar.is_serializing_out())
@@ -220,7 +261,7 @@
     int   version;
     bool  is_simple = true;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
@@ -233,6 +274,10 @@
   }
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 void operator&(Archiver &ar, long &obj)
 {
   if(ar.is_serializing_out())
@@ -250,7 +295,7 @@
     int   version;
     bool  is_simple = true;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
@@ -263,6 +308,10 @@
   }
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 void operator&(Archiver &ar, unsigned long &obj)
 {
   if(ar.is_serializing_out())
@@ -280,7 +329,7 @@
     int   version;
     bool  is_simple = true;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
@@ -293,6 +342,10 @@
   }
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 void operator&(Archiver &ar, long long &obj)
 {
   if(ar.is_serializing_out())
@@ -310,7 +363,7 @@
     int   version;
     bool  is_simple = true;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
@@ -323,6 +376,10 @@
   }
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 void operator&(Archiver &ar, unsigned long long &obj)
 {
   if(ar.is_serializing_out())
@@ -340,7 +397,7 @@
     int   version;
     bool  is_simple = true;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
@@ -353,9 +410,13 @@
   }
 }
 
-void operator&(Archiver &ar, short &obj)
+
+/*******************************************************************************
+
+********************************************************************************/
+void operator&(Archiver& ar, short& obj)
 {
-  if(ar.is_serializing_out())
+  if (ar.is_serializing_out())
   {
     char  strtemp[30];
     sprintf(strtemp, "%hd", obj);
@@ -364,28 +425,38 @@
   }
   else
   {
-    char  *type;
+    char* type;
     std::string value;
     int   id;
     int   version;
     bool  is_simple = true;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
-    retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
-    if(!retval && ar.get_read_optional_field())
+
+    retval = ar.read_next_field(&type, &value, &id, &version,
+                                &is_simple, &is_class, &field_treat, &referencing);
+
+    if (!retval && ar.get_read_optional_field())
       return;
-    ar.check_simple_field(retval, type, "number", is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
+    ar.check_simple_field(retval, type, "number", 
+                          is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
     sscanf(value.c_str(), "%hd", &obj);
 
     ar.register_reference(id, field_treat, &obj);
   }
 }
 
-void operator&(Archiver &ar, unsigned short &obj)
+
+/*******************************************************************************
+
+********************************************************************************/
+void operator&(Archiver& ar, unsigned short& obj)
 {
-  if(ar.is_serializing_out())
+  if (ar.is_serializing_out())
   {
     char  strtemp[30];
     sprintf(strtemp, "%hu", obj);
@@ -394,49 +465,65 @@
   }
   else
   {
-    char  *type;
+    char* type;
     std::string value;
     int   id;
     int   version;
     bool  is_simple = true;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
-    retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
-    if(!retval && ar.get_read_optional_field())
+
+    retval = ar.read_next_field(&type, &value, &id, &version,
+                                &is_simple, &is_class, &field_treat, &referencing);
+
+    if (!retval && ar.get_read_optional_field())
       return;
-    ar.check_simple_field(retval, type, "unsigned number", is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
+    ar.check_simple_field(retval, type, "unsigned number",
+                          is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
     sscanf(value.c_str(), "%hu", &obj);
 
     ar.register_reference(id, field_treat, &obj);
   }
 }
 
-void operator&(Archiver &ar, char &obj)
+
+/*******************************************************************************
+
+********************************************************************************/
+void operator&(Archiver& ar, char& obj)
 {
-  if(ar.is_serializing_out())
+  if (ar.is_serializing_out())
   {
-    char  strtemp[30];
+    char strtemp[30];
     sprintf(strtemp, "%d", (int)obj);
 
     ar.add_simple_field("char", strtemp, &obj, ARCHIVE_FIELD_NORMAL);
   }
   else
   {
-    char  *type;
+    char* type;
     std::string value;
     int   id;
     int   version;
     bool  is_simple = true;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
-    retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
-    if(!retval && ar.get_read_optional_field())
+
+    retval = ar.read_next_field(&type, &value, &id, &version,
+                                &is_simple, &is_class, &field_treat, &referencing);
+
+    if (!retval && ar.get_read_optional_field())
       return;
-    ar.check_simple_field(retval, type, "char", is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
+    ar.check_simple_field(retval, type, "char",
+                          is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
     int   int_obj;
     sscanf(value.c_str(), "%d", &int_obj);
     obj = (char)int_obj;
@@ -445,9 +532,13 @@
   }
 }
 
-void operator&(Archiver &ar, signed char &obj)
+
+/*******************************************************************************
+
+********************************************************************************/
+void operator&(Archiver& ar, signed char& obj)
 {
-  if(ar.is_serializing_out())
+  if (ar.is_serializing_out())
   {
     char  strtemp[30];
     sprintf(strtemp, "%d", (int)obj);
@@ -456,20 +547,26 @@
   }
   else
   {
-    char  *type;
+    char* type;
     std::string value;
     int   id;
     int   version;
     bool  is_simple = true;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
-    retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
-    if(!retval && ar.get_read_optional_field())
+
+    retval = ar.read_next_field(&type, &value, &id, &version,
+                                &is_simple, &is_class, &field_treat, &referencing);
+
+    if (!retval && ar.get_read_optional_field())
       return;
-    ar.check_simple_field(retval, type, "char", is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
-    int   int_obj;
+
+    ar.check_simple_field(retval, type, "char",
+                          is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
+    int int_obj;
     sscanf(value.c_str(), "%d", &int_obj);
     obj = (signed char)int_obj;
 
@@ -477,30 +574,40 @@
   }
 }
 
-void operator&(Archiver &ar, unsigned char &obj)
+
+/*******************************************************************************
+
+********************************************************************************/
+void operator&(Archiver& ar, unsigned char& obj)
 {
-  if(ar.is_serializing_out())
+  if (ar.is_serializing_out())
   {
-    char  strtemp[30];
+    char strtemp[30];
     sprintf(strtemp, "%u", (unsigned int)obj);
 
     ar.add_simple_field("unsigned char", strtemp, &obj, ARCHIVE_FIELD_NORMAL);
   }
   else
   {
-    char  *type;
+    char* type;
     std::string value;
     int   id;
     int   version;
     bool  is_simple = true;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
-    retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
-    if(!retval && ar.get_read_optional_field())
+
+    retval = ar.read_next_field(&type, &value, &id, &version,
+                                &is_simple, &is_class, &field_treat, &referencing);
+
+    if (!retval && ar.get_read_optional_field())
       return;
-    ar.check_simple_field(retval, type, "unsigned char", is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
+    ar.check_simple_field(retval, type, "unsigned char",
+                          is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
     unsigned int int_obj;
     sscanf(value.c_str(), "%u", &int_obj);
     obj = (unsigned char)int_obj;
@@ -510,14 +617,19 @@
 }
 
 
-void operator&(Archiver &ar, float &obj)
+/*******************************************************************************
+
+********************************************************************************/
+void operator&(Archiver& ar, float& obj)
 {
-  if(ar.is_serializing_out())
+  if (ar.is_serializing_out())
   {
-    char  strtemp[100];
+    char strtemp[100];
+
     FloatImpl<float> zorba_float(obj);
     zstring float_str = zorba_float.toString();
-    if(isdigit(float_str.c_str()[0]))
+
+    if (isdigit(float_str.c_str()[0]))
       sprintf(strtemp, "%.7e", (double)obj);
     else
       strcpy(strtemp, float_str.c_str());
@@ -526,20 +638,25 @@
   }
   else
   {
-    char  *type;
+    char* type;
     std::string value;
     int   id;
     int   version;
     bool  is_simple = true;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
-    retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
-    if(!retval && ar.get_read_optional_field())
+
+    retval = ar.read_next_field(&type, &value, &id, &version,
+                                &is_simple, &is_class, &field_treat, &referencing);
+
+    if (!retval && ar.get_read_optional_field())
       return;
-    ar.check_simple_field(retval, type, "float", is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
-    //+sscanf(value.c_str(), "%e", &obj);
+
+    ar.check_simple_field(retval, type, "float",
+                          is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
     FloatImpl<float> zorba_float(value.c_str());
     obj = zorba_float.getNumber();
 
@@ -547,14 +664,19 @@
   }
 }
 
-void operator&(Archiver &ar, double &obj)
+
+/*******************************************************************************
+
+********************************************************************************/
+void operator&(Archiver& ar, double& obj)
 {
-  if(ar.is_serializing_out())
+  if (ar.is_serializing_out())
   {
-    char  strtemp[100];
-    FloatImpl<double>    zorba_double(obj);
-    zstring   double_str = zorba_double.toString();
-    if(isdigit(double_str.c_str()[0]))
+    char strtemp[100];
+    FloatImpl<double> zorba_double(obj);
+    zstring double_str = zorba_double.toString();
+
+    if (isdigit(double_str.c_str()[0]))
       sprintf(strtemp, "%.16e", obj);
     else
       strcpy(strtemp, double_str.c_str());
@@ -563,20 +685,25 @@
   }
   else
   {
-    char  *type;
+    char* type;
     std::string value;
     int   id;
     int   version;
     bool  is_simple = true;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
-    retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
-    if(!retval && ar.get_read_optional_field())
+
+    retval = ar.read_next_field(&type, &value, &id, &version,
+                                &is_simple, &is_class, &field_treat, &referencing);
+
+    if (!retval && ar.get_read_optional_field())
       return;
-    ar.check_simple_field(retval, type, "double", is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
-    //+sscanf(value.c_str(), "%le", &obj);
+
+    ar.check_simple_field(retval, type, "double", 
+                          is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
     FloatImpl<double> zorba_double(value.c_str());
     obj = zorba_double.getNumber();
 
@@ -584,104 +711,94 @@
   }
 }
 
-void operator&(Archiver &ar, bool &obj)
+
+/*******************************************************************************
+
+********************************************************************************/
+void operator&(Archiver& ar, bool& obj)
 {
-  if(ar.is_serializing_out())
+  if (ar.is_serializing_out())
   {
     ar.add_simple_field("bool", obj ? "true" : "false", &obj, ARCHIVE_FIELD_NORMAL);
   }
   else
   {
-    char  *type;
+    char* type;
     std::string value;
     int   id;
     int   version;
     bool  is_simple = true;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
-    retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
-    if(!retval && ar.get_read_optional_field())
+
+    retval = ar.read_next_field(&type, &value, &id, &version,
+                                &is_simple, &is_class, &field_treat, &referencing);
+
+    if (!retval && ar.get_read_optional_field())
       return;
-    ar.check_simple_field(retval, type, "bool", is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
-    if(value == "true")
+
+    ar.check_simple_field(retval, type, "bool",
+                          is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
+
+    if (value == "true")
     {
       obj = true;
     }
-    else if(value == "false")
+    else if (value == "false")
     {
       obj = false;
     }
     else
     {
-      throw ZORBA_EXCEPTION(
-        zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
-      );
+      throw ZORBA_EXCEPTION(zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS(id));
     }
 
     ar.register_reference(id, field_treat, &obj);
   }
 }
 
-void operator&(Archiver &ar, std::string &obj)
-{
-  if(ar.is_serializing_out())
-  {
-    ar.add_simple_field("string", obj.c_str(), &obj, ARCHIVE_FIELD_NORMAL);
-  }
-  else
-  {
-    char  *type;
-    std::string value;
-    int   id;
-    int   version;
-    bool  is_simple = true;
-    bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
-    int   referencing;
-    bool  retval;
-    retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
-    if(!retval && ar.get_read_optional_field())
-      return;
-    ar.check_simple_field(retval, type, "string", is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
-    obj = value;
-
-    ar.register_reference(id, field_treat, &obj);
-  }
-}
-
-
-#if 0
-void operator&(Archiver &ar, zstring &obj)
-{
-  if(ar.is_serializing_out())
-  {
-    ar.add_simple_field("string", obj.c_str(), &obj, ARCHIVE_FIELD_NORMAL);
-  }
-  else
-  {
-    char  *type;
-    std::string value;
-    int   id;
-    int   version;
-    bool  is_simple = true;
-    bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
-    int   referencing;
-    bool  retval;
-    retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
-    if(!retval && ar.get_read_optional_field())
-      return;
-    ar.check_simple_field(retval, type, "string", is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
-    obj = value;
-
-    ar.register_reference(id, field_treat, &obj);
-  }
-}
-#endif
-
-
+
+/*******************************************************************************
+
+********************************************************************************/
+void operator&(Archiver& ar, std::string& obj)
+{
+  if(ar.is_serializing_out())
+  {
+    ar.add_simple_field("string", obj.c_str(), &obj, ARCHIVE_FIELD_NORMAL);
+  }
+  else
+  {
+    char* type;
+    std::string value;
+    int   id;
+    int   version;
+    bool  is_simple = true;
+    bool  is_class = false;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
+    int   referencing;
+    bool  retval;
+
+    retval = ar.read_next_field(&type, &value, &id, &version,
+                                &is_simple, &is_class, &field_treat, &referencing);
+
+    if (!retval && ar.get_read_optional_field())
+      return;
+
+    ar.check_simple_field(retval, type, "string",
+                          is_simple, field_treat, ARCHIVE_FIELD_NORMAL, id);
+    obj = value;
+
+    ar.register_reference(id, field_treat, &obj);
+  }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
 void operator&(Archiver &ar, std::string* &obj)
 {
   if(ar.is_serializing_out())
@@ -698,13 +815,13 @@
     int   version;
     bool  is_simple = true;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_IS_PTR;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_IS_PTR;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
     if(!retval && ar.get_read_optional_field())
       return;
-    ar.check_simple_field(retval, type, "std::string*", is_simple, field_treat, (ArchiveFieldTreat)-1, id);
+    ar.check_simple_field(retval, type, "std::string*", is_simple, field_treat, (ArchiveFieldKind)-1, id);
     if(field_treat == ARCHIVE_FIELD_IS_NULL)
     {
       obj = NULL;
@@ -727,6 +844,9 @@
 }
 
 
+/*******************************************************************************
+
+********************************************************************************/
 void operator&(Archiver &ar, char* &obj)//like char *p=strdup("io");
 {
   if(ar.is_serializing_out())
@@ -741,13 +861,13 @@
     int   version;
     bool  is_simple = true;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_IS_PTR;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_IS_PTR;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
     if(!retval && ar.get_read_optional_field())
       return;
-    ar.check_simple_field(retval, type, "char*", is_simple, field_treat, (ArchiveFieldTreat)-1, id);
+    ar.check_simple_field(retval, type, "char*", is_simple, field_treat, (ArchiveFieldKind)-1, id);
     if(field_treat == ARCHIVE_FIELD_IS_NULL)
     {
       obj = NULL;
@@ -769,6 +889,10 @@
   }
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
 void serialize_array(Archiver &ar, unsigned char *obj, int len)//like char p[20]
 {
   if(ar.is_serializing_out())
@@ -787,7 +911,7 @@
     int   version;
     bool  is_simple = true;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);

=== modified file 'src/zorbaserialization/class_serializer.h'
--- src/zorbaserialization/class_serializer.h	2012-03-23 17:32:07 +0000
+++ src/zorbaserialization/class_serializer.h	2012-03-26 01:27:27 +0000
@@ -439,8 +439,6 @@
 
   void operator&(Archiver &ar, std::string* &obj);
 
-  // void operator&(Archiver &ar, zstring &obj);
-
   void operator&(Archiver &ar, char* &obj);//like char *p=strdup("io");
 
 //  template<class T>
@@ -468,46 +466,9 @@
           ar.set_is_temp_field_one_level(false);\
         }
 
-/*
-#define  SERIALIZE_FUNCTION(f)                      \
-  {                                                 \
-    bool is_uf = false;                             \
-    user_function *uf = NULL;                       \
-    try{                                            \
-      if(ar.is_serializing_out())                   \
-      {                                             \
-        uf = dynamic_cast<user_function*>(f);       \
-        if(uf)                                      \
-          is_uf = true;                             \
-      }                                             \
-    }catch(...)                                     \
-    {                                               \
-    }                                               \
-    ar.set_is_temp_field(true);                     \
-    ar & is_uf;                                     \
-    ar.set_is_temp_field(false);                    \
-    if(is_uf)                                       \
-    {                                               \
-      ar & f;                                       \
-    }                                               \
-    else if(!ar.is_serializing_out())               \
-      f = NULL;                                     \
-  }
-*/
+
 #define  SERIALIZE_FUNCTION(f)    ar & f;
-/*
-#define SERIALIZE_RAW_PTR(ptr)                      \
-  if(!ar.is_serializing_out())                      \
-     ptr = NULL;                                    \
-  try{                                              \
-    ar & ptr;                                       \
-  }catch(...)                                       \
-  {                                                 \
-    if(!ar.is_serializing_out())                    \
-     delete ptr;                                    \
-    throw;                                          \
-  }
-*/
+
 
 } // namespace serialization
 } // namespace zorba

=== modified file 'src/zorbaserialization/mem_archiver.cpp'
--- src/zorbaserialization/mem_archiver.cpp	2012-03-23 17:32:07 +0000
+++ src/zorbaserialization/mem_archiver.cpp	2012-03-26 01:27:27 +0000
@@ -17,60 +17,68 @@
 
 #include "zorbaserialization/mem_archiver.h"
 
-namespace zorba{
-  namespace serialization{
+namespace zorba
+{
+
+namespace serialization
+{
 
 void MemArchiver::reset_serialize_in()
 {
-  serializing_out = false;
-  current_level = 0;
+  theSerializingOut = false;
+  theCurrentLevel = 0;
 
-  current_field = out_fields->first_child;
+  current_field = theRootField->theFirstChild;
   root_tag_is_read();
 }
 
-bool MemArchiver::read_next_field_impl( char **type, 
-                      std::string *value,
-                      int *id, 
-                      int *version, 
-                      bool *is_simple, 
-                      bool *is_class,
-                      enum ArchiveFieldTreat *field_treat,
-                      int *referencing)
+
+bool MemArchiver::read_next_field_impl( 
+    char** type, 
+    std::string* value,
+    int* id, 
+    int* version, 
+    bool* is_simple, 
+    bool* is_class,
+    enum ArchiveFieldKind* field_treat,
+    int* referencing)
 {
-  if((current_field == NULL) || is_after_last)
+  if (current_field == NULL || is_after_last)
     return false;
-  *type = current_field->type;
-  *value = current_field->value;
-  *id = current_field->id;
-  *version = current_field->version;
-  *is_simple = current_field->is_simple;
-  *is_class = current_field->is_class;
-  *field_treat = current_field->field_treat;
+
+  *type = current_field->theTypeName;
+  *value = current_field->theValue;
+  *id = current_field->theId;
+  *version = current_field->theClassVersion;
+  *is_simple = current_field->theIsSimple;
+  *is_class = current_field->theIsClass;
+  *field_treat = current_field->theKind;
   *referencing = current_field->referencing;
 
   is_after_last = false;
-  if(current_field->first_child)
-    current_field = current_field->first_child;
+  if(current_field->theFirstChild)
+    current_field = current_field->theFirstChild;
   else if(!*is_simple && ((*field_treat == ARCHIVE_FIELD_IS_BASECLASS) || (*field_treat == ARCHIVE_FIELD_IS_PTR)))
   {
     //class without childs
-    temp_field.parent = current_field;
+    temp_field.theParent = current_field;
     current_field = &temp_field;//prepare for read_end_current_level()
   }
-  else if(current_field->next)
-    current_field = current_field->next;
+  else if(current_field->theNextSibling)
+    current_field = current_field->theNextSibling;
   else
     is_after_last = true;
   return true;
 }
 
+
 void MemArchiver::read_end_current_level_impl()
 {
   is_after_last = false;
-  current_field = current_field->parent;
-  if(current_field->next)
-    current_field = current_field->next;
+  current_field = current_field->theParent;
+
+  if(current_field->theNextSibling)
+    current_field = current_field->theNextSibling;
   else
     is_after_last = true;
 }

=== modified file 'src/zorbaserialization/mem_archiver.h'
--- src/zorbaserialization/mem_archiver.h	2012-03-23 17:32:07 +0000
+++ src/zorbaserialization/mem_archiver.h	2012-03-26 01:27:27 +0000
@@ -41,7 +41,7 @@
                                 int *version, 
                                 bool *is_simple, 
                                 bool *is_class,
-                                enum ArchiveFieldTreat *field_treat,
+                                enum ArchiveFieldKind *field_treat,
                                 int *referencing);
 
   virtual void read_end_current_level_impl();

=== modified file 'src/zorbaserialization/template_serializer.h'
--- src/zorbaserialization/template_serializer.h	2012-03-23 17:32:07 +0000
+++ src/zorbaserialization/template_serializer.h	2012-03-26 01:27:27 +0000
@@ -74,7 +74,7 @@
       int   version;
       bool  is_simple = true;
       bool  is_class = false;
-      enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+      enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
       int   referencing;
       bool  retval;
       retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
@@ -143,7 +143,7 @@
     int   version;
     bool  is_simple = false;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
@@ -196,7 +196,7 @@
     int   version;
     bool  is_simple = false;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
@@ -260,13 +260,13 @@
     int   version;
     bool  is_simple = false;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_IS_PTR;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_IS_PTR;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
     if(!retval && ar.get_read_optional_field())
       return;
-    ar.check_nonclass_field(retval, type, "std::vector<T>*", is_simple, is_class, field_treat, (ArchiveFieldTreat)-1, id);
+    ar.check_nonclass_field(retval, type, "std::vector<T>*", is_simple, is_class, field_treat, (ArchiveFieldKind)-1, id);
     if(field_treat == ARCHIVE_FIELD_IS_NULL)
     {
       obj = NULL;
@@ -349,7 +349,7 @@
     int   version;
     bool  is_simple = false;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
@@ -393,7 +393,7 @@
     int   version;
     bool  is_simple = false;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
@@ -442,13 +442,13 @@
     int   version;
     bool  is_simple = false;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_IS_PTR;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_IS_PTR;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
     if(!retval && ar.get_read_optional_field())
       return;
-    ar.check_nonclass_field(retval, type, "std::pair<T1, T2>", is_simple, is_class, field_treat, (ArchiveFieldTreat)-1, id);
+    ar.check_nonclass_field(retval, type, "std::pair<T1, T2>", is_simple, is_class, field_treat, (ArchiveFieldKind)-1, id);
     if(field_treat == ARCHIVE_FIELD_IS_NULL)
     {
       obj = NULL;
@@ -533,13 +533,13 @@
     int   version;
     bool  is_simple = false;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_IS_PTR;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_IS_PTR;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
     if(!retval && ar.get_read_optional_field())
       return;
-    ar.check_nonclass_field(retval, type, "std::map<T1, T2>", is_simple, is_class, field_treat, (ArchiveFieldTreat)-1, id);
+    ar.check_nonclass_field(retval, type, "std::map<T1, T2>", is_simple, is_class, field_treat, (ArchiveFieldKind)-1, id);
     if(field_treat == ARCHIVE_FIELD_IS_NULL)
     {
       obj = NULL;
@@ -634,7 +634,7 @@
     int   version;
     bool  is_simple = false;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
@@ -688,7 +688,7 @@
     int   version;
     bool  is_simple = false;
     bool  is_class = true;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
@@ -795,13 +795,13 @@
     int   version;
     bool  is_simple = false;
     bool  is_class = true;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_IS_PTR;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_IS_PTR;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
     if(!retval && ar.get_read_optional_field())
       return;
-    ar.check_class_field(retval, "", "", is_simple, is_class, field_treat, (ArchiveFieldTreat)-1, id);
+    ar.check_class_field(retval, "", "", is_simple, is_class, field_treat, (ArchiveFieldKind)-1, id);
     if(field_treat == ARCHIVE_FIELD_IS_NULL)
     {
       assert(!ar.is_serialize_base_class());

=== modified file 'src/zorbaserialization/xml_archiver.cpp'
--- src/zorbaserialization/xml_archiver.cpp	2012-03-23 17:32:07 +0000
+++ src/zorbaserialization/xml_archiver.cpp	2012-03-26 01:27:27 +0000
@@ -18,10 +18,16 @@
 #include "zorbaserialization/xml_archiver.h"
 #include "diagnostics/xquery_diagnostics.h"
 
-namespace zorba{
-  namespace serialization{
-
-XmlArchiver::XmlArchiver(std::istream *is) : Archiver(false)
+namespace zorba
+{
+
+namespace serialization
+{
+
+
+XmlArchiver::XmlArchiver(std::istream* is) 
+  :
+  Archiver(false)
 {
   //open archiver for input
   this->is = is;
@@ -60,6 +66,7 @@
   read_tag_level++;
 }
 
+
 XmlArchiver::XmlArchiver(std::ostream *os) : Archiver(true)
 {
   //open archiver for output
@@ -71,6 +78,7 @@
   indent_off = sizeof(indent_spaces)-1;
 }
 
+
 void XmlArchiver::serialize_out()
 {
   if(!os)
@@ -82,56 +90,56 @@
 
   write_string("<?xml version=\"1.0\"?>\n");
   write_string("<zorba_archive archive_name=\"");
-  encode_string(archive_name.c_str());
+  encode_string(theArchiveName.c_str());
   write_string("\" ");
   write_string("archive_info=\"");
-  encode_string(archive_info.c_str());
+  encode_string(theArchiveInfo.c_str());
   write_string("\" ");
-  *os << "archive_version=\"" << archive_version << "\" ";
+  *os << "archive_version=\"" << theArchiveVersion << "\" ";
   *os << "nr_ids=\"" << nr_ids << "\" >" << std::endl;
-  serialize_compound_fields(out_fields);
+  serialize_compound_fields(theRootField);
   write_string("</zorba_archive>\n");
-
 }
 
+
 void XmlArchiver::serialize_compound_fields(archive_field   *parent_field)
 {
-  archive_field   *current_field = parent_field->first_child;
+  archive_field   *current_field = parent_field->theFirstChild;
   char strtemp[100];
   while(current_field)
   {
     write_string(indent_off >= 0 ? indent_spaces+indent_off : indent_spaces);
     write_string("<obj_field is_simple=\"");
-    write_string(current_field->is_simple ? "true" : "false");
+    write_string(current_field->theIsSimple ? "true" : "false");
     write_string("\" ");
     write_string("type=\"");
-    write_string(current_field->type);
+    write_string(current_field->theTypeName);
     write_string("\" ");
     write_string("version=\"");
-    sprintf(strtemp, "%d", current_field->version);
+    sprintf(strtemp, "%d", current_field->theClassVersion);
     write_string(strtemp);
     write_string("\" ");
     write_string("field_treat=\"");
-    write_string(get_field_treat_string(current_field->field_treat));
+    write_string(get_field_treat_string(current_field->theKind));
     write_string("\" ");
     write_string("referencing=\"");
     sprintf(strtemp, "%d", current_field->referencing);
     write_string(strtemp);
     write_string("\" ");
     write_string("id=\"");
-    sprintf(strtemp, "%d", current_field->id);
+    sprintf(strtemp, "%d", current_field->theId);
     write_string(strtemp);
     write_string("\" ");
     write_string("is_class=\"");
-    write_string(current_field->is_class ? "true" : "false");
+    write_string(current_field->theIsClass ? "true" : "false");
     write_string("\" ");
     write_string("value=\"");
-    encode_string(current_field->value);
+    encode_string(current_field->theValue);
     write_string("\" ");
 
-    if(current_field->is_simple || 
-      (current_field->field_treat == ARCHIVE_FIELD_IS_REFERENCING) ||
-      (current_field->first_child == NULL))
+    if(current_field->theIsSimple || 
+      (current_field->theKind == ARCHIVE_FIELD_IS_REFERENCING) ||
+      (current_field->theFirstChild == NULL))
     {
       write_string("/>\n");
     }
@@ -144,10 +152,11 @@
       write_string(indent_off >= 0 ? indent_spaces+indent_off : indent_spaces);
       write_string("</obj_field>\n");
     }
-    current_field = current_field->next;
+    current_field = current_field->theNextSibling;
   }
 }
 
+
 void XmlArchiver::encode_string(const char *value)
 {
   if(!value)
@@ -164,12 +173,14 @@
   }
 }
 
+
 void XmlArchiver::write_string(const char *str)
 {
   os->write(str, (std::streamsize)strlen(str));
 }
 
-const char *XmlArchiver::get_field_treat_string(enum ArchiveFieldTreat field_treat)
+
+const char *XmlArchiver::get_field_treat_string(enum ArchiveFieldKind field_treat)
 {
   switch(field_treat)
   {
@@ -185,14 +196,15 @@
 
 ////////////reading archive
 
-bool XmlArchiver::read_next_field_impl( char **type, 
-                              std::string *value,
-                              int *id, 
-                              int *version, 
-                              bool *is_simple, 
-                              bool *is_class,
-                              enum ArchiveFieldTreat *field_treat,
-                              int *referencing)
+bool XmlArchiver::read_next_field_impl(
+    char **type, 
+    std::string *value,
+    int *id, 
+    int *version, 
+    bool *is_simple, 
+    bool *is_class,
+    enum ArchiveFieldKind *field_treat,
+    int *referencing)
 {
   if(!is)
   {
@@ -204,7 +216,7 @@
   *version = -1; 
   *is_simple = false; 
   *is_class = false,
-  *field_treat = (enum ArchiveFieldTreat)-1;
+  *field_treat = (enum ArchiveFieldKind)-1;
   *referencing = -1;
 
   if(is_compound_field_without_children)
@@ -253,14 +265,14 @@
 
   while(read_attrib_name(attrib_name))
   {
-//    write_string("<obj_field is_simple=\"" << (current_field->is_simple ? "true" : "false") << "\" "
-//        <<"type=\"" << current_field->type << "\" "
+//    write_string("<obj_field is_simple=\"" << (current_field->theIsSimple ? "true" : "false") << "\" "
+//        <<"type=\"" << current_field->theTypeName << "\" "
 //        <<"version=\"" << current_field->version << "\" "
-//        <<"field_treat=\"" << get_field_treat_string(current_field->field_treat) << "\" "
+//        <<"field_treat=\"" << get_field_treat_string(current_field->theKind) << "\" "
 //        <<"referencing=\"" << current_field->referencing << "\" "
 //        <<"id=\"" << current_field->id << "\" "
-//        <<"is_class=\"" << current_field->is_class << "\" "
-//        <<"value=\"" ;//<< current_field->value ? current_field->value : "" << "\" ";
+//        <<"is_class=\"" << current_field->theIsClass << "\" "
+//        <<"value=\"" ;//<< current_field->theValue ? current_field->theValue : "" << "\" ";
 process_attr:
     switch(attr_index)
     {
@@ -378,7 +390,6 @@
 }
 
 
-
 bool XmlArchiver::read_root_tag(char c)
 {
   if(!match_string(c, "zorba_archive"))
@@ -400,16 +411,16 @@
   {
     if(!strcmp(attrib_name, "archive_name"))
     {
-      read_attrib_value(&archive_name);
+      read_attrib_value(&theArchiveName);
     }
     else if(!strcmp(attrib_name, "archive_info"))
     {
-      read_attrib_value(&archive_info);
+      read_attrib_value(&theArchiveInfo);
     }
     else if(!strcmp(attrib_name, "archive_version"))
     {
       read_attrib_value(attrib_value);
-      archive_version = atoi(attrib_value);
+      theArchiveVersion = atoi(attrib_value);
     }
     else if(!strcmp(attrib_name, "nr_ids"))
     {
@@ -421,6 +432,7 @@
   return true;
 }
 
+
 void XmlArchiver::read_end_current_level_impl()
 {
   if(is_compound_field_without_children)
@@ -470,6 +482,7 @@
   return;
 }
 
+
 bool XmlArchiver::match_string(char c, const char *match)
 {
   if(match[0] != c)
@@ -490,6 +503,7 @@
   return true;
 }
 
+
 bool XmlArchiver::read_attrib_name(char *attrib_name)
 {
   char c;
@@ -540,6 +554,7 @@
   return true;
 }
 
+
 void XmlArchiver::read_attrib_value(char *attrib_value)
 {
   char c = 0;
@@ -651,6 +666,7 @@
   *attrib_value = 0;
 }
 
+
 void XmlArchiver::read_attrib_value(std::string *attrib_value)
 {
   char c = 0;
@@ -755,6 +771,7 @@
   }
 }
 
+
 void XmlArchiver::skip_tag()
 {
   std::string   temp_val;
@@ -778,6 +795,7 @@
   }
 }
 
+
 void XmlArchiver::skip_comment_tag()
 {
   char c;

=== modified file 'src/zorbaserialization/xml_archiver.h'
--- src/zorbaserialization/xml_archiver.h	2012-03-23 17:32:07 +0000
+++ src/zorbaserialization/xml_archiver.h	2012-03-26 01:27:27 +0000
@@ -45,7 +45,7 @@
                                 int *version, 
                                 bool *is_simple, 
                                 bool *is_class,
-                                enum ArchiveFieldTreat *field_treat,
+                                enum ArchiveFieldKind *field_treat,
                                 int *referencing);
 
   virtual void read_end_current_level_impl();
@@ -59,7 +59,7 @@
   //writing
   void serialize_compound_fields(archive_field   *parent_field);
   void encode_string(const char *value);
-  const char *get_field_treat_string(enum ArchiveFieldTreat field_treat);
+  const char *get_field_treat_string(enum ArchiveFieldKind field_treat);
   void write_string(const char *str);
 
   //reading

=== modified file 'src/zorbaserialization/zorba_class_serializer.cpp'
--- src/zorbaserialization/zorba_class_serializer.cpp	2012-03-23 17:32:07 +0000
+++ src/zorbaserialization/zorba_class_serializer.cpp	2012-03-26 01:27:27 +0000
@@ -130,7 +130,7 @@
     int   version;
     bool  is_simple = true;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_IS_PTR;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_IS_PTR;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
@@ -191,7 +191,7 @@
     int   version;
     bool  is_simple = true;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
@@ -241,11 +241,11 @@
     std::vector<store::Item_t>::iterator  child_it;
     int child_count = (int)childs.size();
     ar & child_count;
-//    ar.set_is_temp_field(false);
+
     for(child_it = childs.begin(); child_it != childs.end(); child_it++)
     {
       store::Item*  p = (*child_it).getp();
-    //  ar.set_is_temp_field_one_level(true);
+
       ar.dont_allow_delay(SERIALIZE_NOW);
       //ar & p;
       serialize_node_tree(ar, p, false);
@@ -255,7 +255,7 @@
   {
     int child_count;
     ar & child_count;
-//    ar.set_is_temp_field(false);
+
     for(int i=0;i<child_count;i++)
     {
       store::Item*  p = NULL; 
@@ -263,7 +263,6 @@
       serialize_node_tree(ar, p, false);
     }
   }
-//  ar.set_is_temp_field(true);
 }
 
 void serialize_my_children2(Archiver &ar, store::Iterator_t iter)
@@ -303,17 +302,17 @@
       serialize_node_tree(ar, parent, false);
 
 #define FINALIZE_SERIALIZE(create_func, func_params)                    \
-    if(!ar.is_serializing_out())                                        \
-    {                                                                   \
-      store::Item_t result;                                             \
-      GENV_ITEMFACTORY->create_func func_params;                        \
-      obj = result.getp();                                              \
-      if(obj)                                                           \
-        obj->addReference();                                            \
-      ar.set_is_temp_field(false);                                      \
-      ar.register_reference(id, ARCHIVE_FIELD_IS_PTR, obj);             \
-      ar.set_is_temp_field(true);                                       \
-    }      
+  if (!ar.is_serializing_out())                                         \
+  {                                                                     \
+    store::Item_t result;                                               \
+    GENV_ITEMFACTORY->create_func func_params;                          \
+    obj = result.getp();                                                \
+    if(obj)                                                             \
+      obj->addReference();                                              \
+    ar.set_is_temp_field(false);                                        \
+    ar.register_reference(id, ARCHIVE_FIELD_IS_PTR, obj);               \
+    ar.set_is_temp_field(true);                                         \
+  }      
 
 
 void operator&(Archiver &ar, store::Item* &obj)
@@ -326,12 +325,12 @@
   int  is_function = 0;
   
   int   id;
-  enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_IS_PTR;
+  enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_IS_PTR;
   int   referencing;
 
-  if(ar.is_serializing_out())
+  if (ar.is_serializing_out())
   {
-    if(obj == NULL)
+    if (obj == NULL)
     {
       ar.add_compound_field("store::Item*", 
                             1 ,//class_version
@@ -340,25 +339,35 @@
                             ARCHIVE_FIELD_IS_NULL);
       return;
     }
+
     char  strtemp[100];
     is_node = obj->isNode();
     is_atomic = obj->isAtomic();
     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)
+
+    if (is_node || is_function)
       ar.set_is_temp_field(true);
-    is_ref = ar.add_compound_field("store::Item*", 0, FIELD_IS_CLASS, strtemp, obj, ARCHIVE_FIELD_IS_PTR);
-    if(is_node || is_function)
+
+    is_ref = ar.add_compound_field("store::Item*",
+                                   0,
+                                   FIELD_IS_CLASS,
+                                   strtemp,
+                                   obj,
+                                   ARCHIVE_FIELD_IS_PTR);
+
+    if (is_node || is_function)
       ar.set_is_temp_field(false);
-
   }
   else
   {
-    char  *type;
+    char* type;
     std::string value;
     int   version;
     bool  is_simple = false;
@@ -367,7 +376,7 @@
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
     if(!retval && ar.get_read_optional_field())
       return;
-    ar.check_class_field(retval, type, "store::Item*", is_simple, is_class, field_treat, (enum  ArchiveFieldTreat)-1, id);
+    ar.check_class_field(retval, type, "store::Item*", is_simple, is_class, field_treat, (enum  ArchiveFieldKind)-1, id);
     if(field_treat == ARCHIVE_FIELD_IS_NULL)
     {
       obj = NULL;
@@ -389,16 +398,17 @@
     }
   }
 
-  if(!is_ref)
+  if (!is_ref)
   {
     ar.set_is_temp_field(true);
     ar.set_is_temp_field_one_level(true);
 
-    if(is_atomic)
+    if (is_atomic)
     {
       store::Item_t type;
       zstring name_of_type;
       bool is_qname;
+
       if(ar.is_serializing_out())
       {
         type = obj->getType();
@@ -407,9 +417,10 @@
         is_qname = (name_of_type == "QName" && 
                     ns == "http://www.w3.org/2001/XMLSchema";);
       }
+
       ar & is_qname;
 
-      if(!is_qname)
+      if (!is_qname)
       {
         ar.dont_allow_delay();
         ar & type;//save qname of type
@@ -431,7 +442,7 @@
           goto EndAtomicItem;
         }
       }
-      else if(!ar.is_serializing_out())
+      else if (!ar.is_serializing_out())
       {
         GENV_ITEMFACTORY->createQName(type, "http://www.w3.org/2001/XMLSchema";, "xs", "QName");
       }
@@ -439,12 +450,10 @@
       if(!ar.is_serializing_out())
         name_of_type = type->getLocalName();
 
-      if(name_of_type == "untyped")
+      if (name_of_type == "untyped")
       {
-        throw ZORBA_EXCEPTION(
-          zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE,
-          ERROR_PARAMS( name_of_type )
-        );
+        throw ZORBA_EXCEPTION(zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE,
+        ERROR_PARAMS(name_of_type));
       }
       else if(name_of_type == "untypedAtomic")
       {
@@ -453,10 +462,8 @@
       }
       else if(name_of_type == "anyType")
       {
-        throw ZORBA_EXCEPTION(
-          zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE,
-          ERROR_PARAMS( name_of_type )
-        );
+        throw ZORBA_EXCEPTION(zerr::ZCSE0010_ITEM_TYPE_NOT_SERIALIZABLE,
+        ERROR_PARAMS(name_of_type));
       }
       else if(name_of_type == "anySimpleType")
       {
@@ -833,9 +840,11 @@
     }
     serialize_node_tree(ar, parent, false);
   }
+
   ar.set_is_temp_field(false);
+
   int   id;
-  enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_IS_PTR;
+  enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_IS_PTR;
   int   referencing;
   bool is_ref;
   if(ar.is_serializing_out())
@@ -870,7 +879,7 @@
       ar.set_is_temp_field(true);
       return;
     }
-    ar.check_class_field(retval, type, "store::Item*", is_simple, is_class, field_treat, (enum  ArchiveFieldTreat)-1, id);
+    ar.check_class_field(retval, type, "store::Item*", is_simple, is_class, field_treat, (enum  ArchiveFieldKind)-1, id);
     //ar.register_reference(id, &obj);
     if((field_treat != ARCHIVE_FIELD_IS_PTR) && (field_treat != ARCHIVE_FIELD_IS_REFERENCING))
     {
@@ -1081,13 +1090,13 @@
     int   version;
     bool  is_simple = false;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_IS_PTR;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_IS_PTR;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
     if(!retval && ar.get_read_optional_field())
       return;
-    ar.check_nonclass_field(retval, type, "Diagnostic*", is_simple, is_class, field_treat, (ArchiveFieldTreat)-1, id);
+    ar.check_nonclass_field(retval, type, "Diagnostic*", is_simple, is_class, field_treat, (ArchiveFieldKind)-1, id);
     if(field_treat == ARCHIVE_FIELD_IS_NULL)
     {
       assert(!ar.is_serialize_base_class());
@@ -1187,13 +1196,13 @@
     int   version;
     bool  is_simple = false;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_IS_PTR;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_IS_PTR;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
     if(!retval && ar.get_read_optional_field())
       return;
-    ar.check_nonclass_field(retval, type, "ZorbaException*", is_simple, is_class, field_treat, (ArchiveFieldTreat)-1, id);
+    ar.check_nonclass_field(retval, type, "ZorbaException*", is_simple, is_class, field_treat, (ArchiveFieldKind)-1, id);
     if(field_treat == ARCHIVE_FIELD_IS_NULL)
     {
       assert(!ar.is_serialize_base_class());
@@ -1278,7 +1287,7 @@
     int   version;
     bool  is_simple = false;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
@@ -1319,7 +1328,7 @@
     int   version;
     bool  is_simple = false;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
@@ -1356,7 +1365,7 @@
     int   version;
     bool  is_simple = false;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
@@ -1399,7 +1408,7 @@
     int   version;
     bool  is_simple = false;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);

=== modified file 'src/zorbaserialization/zorba_class_serializer.h'
--- src/zorbaserialization/zorba_class_serializer.h	2012-03-23 17:32:07 +0000
+++ src/zorbaserialization/zorba_class_serializer.h	2012-03-26 01:27:27 +0000
@@ -33,7 +33,8 @@
 #include <stdio.h>
 #include <map>
 
-namespace zorba{
+namespace zorba
+{
   class XQType;
   class function;
   class Diagnostic;
@@ -44,8 +45,9 @@
   template<typename IntType> class IntegerImpl;
 #endif /* ZORBA_WITH_BIG_INTEGER */
 
-  namespace serialization{
-//void operator&(Archiver &ar, XQType *&obj);
+namespace serialization
+{
+
 void operator&(Archiver &ar, const XQType *&obj);
 void operator&(Archiver &ar, MAPM &obj);
 #ifdef ZORBA_WITH_BIG_INTEGER
@@ -57,7 +59,7 @@
 
 void operator&(Archiver &ar, XQPCollator *&obj);
 void operator&(Archiver &ar, store::Item* &obj);
-//void operator&(Archiver &ar, std::vector<rchandle<function> >*& obj);
+
 void operator&(Archiver &ar, const Diagnostic *&obj);
 void operator&(Archiver &ar, ZorbaException *&obj);
 void operator&(Archiver &ar, zorba::internal::diagnostic::location &obj);
@@ -65,7 +67,6 @@
 void operator&(Archiver &ar, zorba::XQueryStackTrace &obj);
 void operator&(Archiver &ar, zorba::XQueryStackTrace::Entry &obj);
 
-//void serialize_qname(Archiver &ar, store::Item_t &qname);
 
 #define SERIALIZE_TYPEMANAGER(type_mgr_type, type_mgr)                             \
   bool is_root_type_mgr = ar.is_serializing_out() && (!GENV.isRootStaticContextInitialized() || ((TypeManager*)type_mgr == (TypeManager*)&GENV_TYPESYSTEM)) && ar.is_serializing_out();            \
@@ -127,7 +128,7 @@
     int   version;
     bool  is_simple = false;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
@@ -189,7 +190,7 @@
     int   version;
     bool  is_simple = false;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
@@ -262,7 +263,7 @@
     int   version;
     bool  is_simple = false;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
@@ -337,7 +338,7 @@
     int   version;
     bool  is_simple = false;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
@@ -372,156 +373,7 @@
 
   }
 }
-/*
-template<class T>
-void operator&(Archiver &ar, rchandle<T> *&obj)
-{
-  if(ar.is_serializing_out())
-  {
-    if((obj == NULL))
-    {
-      ar.add_compound_field("NULL", 
-                            1 ,//class_version
-                            !FIELD_IS_CLASS, "NULL", 
-                            NULL,//(SerializeBaseClass*)obj, 
-                            ARCHIVE_FIELD_IS_NULL);
-      return;
-    }
-    //char  strtemp[20];
-    //sprintf(strtemp, "%d", 0);
-    bool is_ref;
-    ENUM_ALLOW_DELAY allow_delay = ar.get_allow_delay();
-    
-    is_ref = ar.add_compound_field("rchandle<T>", 
-                                    1, 
-                                    !FIELD_IS_CLASS, "0",//strtemp, 
-                                    obj, 
-                                    ar.is_serialize_base_class() ? ARCHIVE_FIELD_IS_BASECLASS : ARCHIVE_FIELD_IS_PTR);
-    if(ar.is_serialize_base_class())                                     
-      ar.set_serialize_base_class(false);                                
-    if(!is_ref)
-    {
-      T *p = obj->getp();
-      if(allow_delay != ALLOW_DELAY)
-        ar.dont_allow_delay(allow_delay);
-      bool is_temp = false;
-      if(ar.get_is_temp_field_one_level())
-      {
-        is_temp = true;
-        ar.set_is_temp_field_one_level(true, ar.get_is_temp_field_also_for_ptr());
-        if(!ar.get_is_temp_field_also_for_ptr() && (allow_delay == ALLOW_DELAY))
-          ar.dont_allow_delay();
-      }
-      ar & p;
-      if(is_temp)
-        ar.set_is_temp_field_one_level(false);
-      ar.add_end_compound_field();
-    }
-  }
-  else
-  {
-    char  *type;
-    std::string value;
-    int   id;
-    int   version;
-    bool  is_simple = false;
-    bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_IS_PTR;
-    int   referencing;
-    bool  retval;
-    retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);
-    if(!retval && ar.get_read_optional_field())
-      return;
-    ar.check_nonclass_field(retval, type, "rchandle<T>", is_simple, is_class, field_treat, (ArchiveFieldTreat)-1, id);
-    if(field_treat == ARCHIVE_FIELD_IS_NULL)
-    {
-      assert(!ar.is_serialize_base_class());
-      obj = NULL;
-      ar.read_end_current_level();
-      return;
-    }
-    if(ar.is_serialize_base_class())                                     
-      ar.set_serialize_base_class(false);                                
-
-    if(ar.is_serialize_base_class())
-    {
-      if(field_treat != ARCHIVE_FIELD_IS_BASECLASS)
-      {
-        throw ZORBA_EXCEPTION(
-          zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
-        );
-      }
-    }
-    else
-    {
-      if((field_treat != ARCHIVE_FIELD_IS_PTR) && (field_treat != ARCHIVE_FIELD_IS_REFERENCING))
-      {
-        throw ZORBA_EXCEPTION(
-          zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
-        );
-      }
-    }
-
-    SerializeBaseClass  *new_obj = NULL;
-    if((field_treat == ARCHIVE_FIELD_IS_PTR) ||
-      (field_treat == ARCHIVE_FIELD_IS_BASECLASS))
-    {
-      throw ZORBA_EXCEPTION(
-        zerr::ZCSE0009_CLASS_NOT_SERIALIZABLE, ERROR_PARAMS( "rchandle<T>*" )
-      );
-
-      bool is_temp = false;
-      if(ar.get_is_temp_field_one_level())
-      {
-        is_temp = true;
-        ar.set_is_temp_field_one_level(true, ar.get_is_temp_field_also_for_ptr());
-      }
-      T *p;
-      ar & p;
-      if(field_treat == ARCHIVE_FIELD_IS_PTR)
-      {
-        obj = new rchandle<T>(p);
-        ar.register_reference(id, field_treat, new_obj);
-      }
-      if(is_temp)
-        ar.set_is_temp_field_one_level(false);
-      if(p == NULL)
-      {
-        //workaround for the strict_aliasing warning in gcc
-        union 
-        {
-          T **t;
-          void **v;
-        }u_p;
-        u_p.t = &p;
-        ar.reconf_last_delayed_rcobject(u_p.v, obj->getp_ref().v, true);
-      }
-      ar.read_end_current_level();
-    }
-    else if((new_obj = (SerializeBaseClass*)ar.get_reference_value(referencing)))// ARCHIVE_FIELD_IS_REFERENCING
-    {
-      try{
-        obj = dynamic_cast<rchandle<T>*>(new_obj);
-      }catch(...)
-      {
-        throw ZORBA_EXCEPTION(
-          zerr::ZCSE0004_UNRESOLVED_FIELD_REFERENCE, ERROR_PARAMS( id )
-        );
-      }
-      if(!obj)
-      {
-        throw ZORBA_EXCEPTION(
-          zerr::ZCSE0002_INCOMPATIBLE_INPUT_FIELD, ERROR_PARAMS( id )
-        );
-      }
-    }
-    else
-    {
-      ar.register_delay_reference((void**)&obj, !FIELD_IS_CLASS, "rchandle<T>", referencing);
-    }
-  }
-}
-*/
+
 
 template<typename StringType>
 void operator&(Archiver &ar, zorba::internal::VariableQName<StringType> &obj)
@@ -550,7 +402,7 @@
     int   version;
     bool  is_simple = false;
     bool  is_class = false;
-    enum  ArchiveFieldTreat field_treat = ARCHIVE_FIELD_NORMAL;
+    enum  ArchiveFieldKind field_treat = ARCHIVE_FIELD_NORMAL;
     int   referencing;
     bool  retval;
     retval = ar.read_next_field(&type, &value, &id, &version, &is_simple, &is_class, &field_treat, &referencing);

=== modified file 'test/rbkt/testdriver.cpp'
--- test/rbkt/testdriver.cpp	2012-03-23 17:32:07 +0000
+++ test/rbkt/testdriver.cpp	2012-03-26 01:27:27 +0000
@@ -26,7 +26,7 @@
 #include <time.h>
 #endif
 
-//#define ZORBA_TEST_PLAN_SERIALIZATION
+#define ZORBA_TEST_PLAN_SERIALIZATION
 
 #include "testdriverconfig.h" // SRC and BIN dir definitions
 #include "specification.h" // parsing spec files


Follow ups