← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~matthias-brantner/zorba/xqxq-sandbox into lp:~zorba-coders/zorba/zorba-experimental

 

Matthias Brantner has proposed merging lp:~matthias-brantner/zorba/xqxq-sandbox into lp:~zorba-coders/zorba/zorba-experimental.

Requested reviews:
  Zorba Coders (zorba-coders)

For more details, see:
https://code.launchpad.net/~matthias-brantner/zorba/xqxq-sandbox/+merge/80828
-- 
https://code.launchpad.net/~matthias-brantner/zorba/xqxq-sandbox/+merge/80828
Your team Zorba Coders is requested to review the proposed merge of lp:~matthias-brantner/zorba/xqxq-sandbox into lp:~zorba-coders/zorba/zorba-experimental.
=== modified file 'modules/ExternalModules.conf'
--- modules/ExternalModules.conf	2011-10-11 22:26:10 +0000
+++ modules/ExternalModules.conf	2011-10-31 17:53:26 +0000
@@ -39,3 +39,4 @@
 process         bzr  lp:zorba/process-module             zorba-2.0.3
 security        bzr  lp:zorba/security-module            zorba-2.0.3
 system          bzr  lp:zorba/system-module              zorba-2.0.3
+xqxq            bzr  lp:~juan457/zorba/xqxq-module-beta  zorba-2.0.3

=== modified file 'src/compiler/codegen/plan_visitor.cpp'
--- src/compiler/codegen/plan_visitor.cpp	2011-09-16 19:36:18 +0000
+++ src/compiler/codegen/plan_visitor.cpp	2011-10-31 17:53:26 +0000
@@ -199,7 +199,10 @@
 
 
 /*******************************************************************************
-
+  A FlworClauseVarMap is created for each flwor clause that defines variables.
+  If M is such a clause, then for each variable Vi defined by M, theVarExprs[i]
+  and theVarRebinds[i] contain an entry for Vi. theVarExprs[i] contains the
+  var_expr representing the Vi definition. 
 ********************************************************************************/
 class FlworClauseVarMap : public SimpleRCObject
 {
@@ -207,7 +210,7 @@
   bool                          theIsGeneral;
   const flwor_clause          * theClause;
 
-  std::vector<const var_expr*>  theVarExprs;
+  std::vector<var_expr*>        theVarExprs;
   std::vector<VarRebind_t>      theVarRebinds;
 
 public:
@@ -222,8 +225,8 @@
 
   long find_var(const var_expr* var) const
   {
-    ulong numVars = (ulong)theVarExprs.size();
-    for (ulong i = 0; i < numVars; ++i)
+    csize numVars = theVarExprs.size();
+    for (csize i = 0; i < numVars; ++i)
     {
       if (theVarExprs[i] == var)
         return i;
@@ -759,7 +762,7 @@
         {
           varRebind = new VarRebind;
 
-          clauseVarMap->theVarExprs.push_back(&var);
+          clauseVarMap->theVarExprs.push_back(const_cast<var_expr*>(&var));
           clauseVarMap->theVarRebinds.push_back(varRebind);
 
           varRebind->theInputVar = varIter;
@@ -1189,14 +1192,14 @@
     const group_clause::rebind_list_t& grouping_vars = gbc->get_grouping_vars();
     const group_clause::rebind_list_t& nongrouping_vars = gbc->get_nongrouping_vars();
 
-    for (unsigned i = 0; i < grouping_vars.size(); i++)
+    for (unsigned i = 0; i < grouping_vars.size(); ++i)
     {
       VarRebind_t varRebind = new VarRebind;
       clauseVarMap->theVarExprs.push_back(grouping_vars[i].second.getp());
       clauseVarMap->theVarRebinds.push_back(varRebind);
     }
 
-    for (unsigned i = 0; i < nongrouping_vars.size(); i++)
+    for (unsigned i = 0; i < nongrouping_vars.size(); ++i)
     {
       VarRebind_t varRebind = new VarRebind;
       clauseVarMap->theVarExprs.push_back(nongrouping_vars[i].second.getp());
@@ -1363,22 +1366,17 @@
 
   xqtref_t colType = colExpr->get_return_type();
 
-  if (TypeOps::is_subtype(tm, *colType, *rtm.STRING_TYPE_STAR, loc) ||
-      TypeOps::is_subtype(tm, *colType, *rtm.DOUBLE_TYPE_STAR, loc) ||
-      TypeOps::is_subtype(tm, *colType, *rtm.FLOAT_TYPE_STAR, loc) ||
-      TypeOps::is_subtype(tm, *colType, *rtm.LONG_TYPE_STAR, loc) ||
-      TypeOps::is_subtype(tm, *colType, *rtm.UNSIGNED_LONG_TYPE_STAR, loc) ||
-      TypeOps::is_equal(tm,
-                        *TypeOps::prime_type(tm, *colType),
-                        *rtm.DECIMAL_TYPE_ONE,
-                        loc) ||
-      TypeOps::is_equal(tm,
-                        *TypeOps::prime_type(tm, *colType),
-                        *rtm.INTEGER_TYPE_ONE,
-                        loc) ||
-      TypeOps::is_subtype(tm, *colType, *rtm.DATE_TYPE_STAR, loc) ||
-      TypeOps::is_subtype(tm, *colType, *rtm.TIME_TYPE_STAR, loc) ||
-      TypeOps::is_subtype(tm, *colType, *rtm.DATETIME_TYPE_STAR, loc))
+  if (colType->type_kind() == XQType::NODE_TYPE_KIND)
+  {
+    colType = static_cast<const NodeXQType*>(colType.getp())->get_content_type();
+  }
+
+  if (colType != NULL &&
+      TypeOps::is_subtype(tm, *colType, *rtm.ANY_ATOMIC_TYPE_STAR, loc) &&
+      !TypeOps::is_equal(tm, 
+                         *TypeOps::prime_type(tm, *colType),
+                         *rtm.ANY_ATOMIC_TYPE_ONE,
+                         loc))
   {
     return true;
   }
@@ -1669,7 +1667,7 @@
     if (c.get_kind() != flwor_clause::where_clause)
     {
       ZORBA_ASSERT(!theClauseStack.empty());
-      ulong stackSize = (ulong)theClauseStack.size();
+      csize stackSize = theClauseStack.size();
 
       clauseVarMap = theClauseStack[stackSize-1];
       theClauseStack.resize(stackSize - 1);
@@ -1878,9 +1876,12 @@
     std::vector<flwor::NonGroupingSpec>& ngspecs)
 {
   const group_clause* gbc = static_cast<const group_clause*>(clauseVarMap->theClause);
+
   const group_clause::rebind_list_t& gvars = gbc->get_grouping_vars();
   const group_clause::rebind_list_t& ngvars = gbc->get_nongrouping_vars();
+
   const std::vector<std::string>& collations = gbc->get_collations();
+
   long numVars = (long)(gvars.size() + ngvars.size());
   long numGroupVars = (long)gvars.size();
   long i = numVars - 1;
@@ -1900,7 +1901,12 @@
 
     const std::vector<PlanIter_t>& varRefs = varRebind->theOutputVarRefs;
 
-    gspecs.push_back(flwor::GroupingSpec(pop_itstack(), varRefs, collations[i]));
+    bool fastComparison = nativeColumnSort(clauseVarMap->theVarExprs[i]);
+
+    gspecs.push_back(flwor::GroupingSpec(pop_itstack(),
+                                         varRefs,
+                                         collations[i],
+                                         fastComparison));
   }
 }
 

=== modified file 'src/compiler/expression/flwor_expr.cpp'
--- src/compiler/expression/flwor_expr.cpp	2011-08-15 14:17:09 +0000
+++ src/compiler/expression/flwor_expr.cpp	2011-10-31 17:53:26 +0000
@@ -616,26 +616,26 @@
   theNonGroupVars(ngvars),
   theCollations(collations)
 {
-  ulong numGVars = (ulong)theGroupVars.size();
-  ulong numNGVars = (ulong)theNonGroupVars.size();
+  csize numGVars = theGroupVars.size();
+  csize numNGVars = theNonGroupVars.size();
 
-  for (ulong i = 0; i < numGVars; ++i)
+  for (csize i = 0; i < numGVars; ++i)
     theGroupVars[i].second->set_flwor_clause(this);
 
-  for (ulong i = 0; i < numNGVars; ++i)
+  for (csize i = 0; i < numNGVars; ++i)
     theNonGroupVars[i].second->set_flwor_clause(this);
 }
 
 
 group_clause::~group_clause()
 {
-  ulong numGVars = (ulong)theGroupVars.size();
-  ulong numNGVars = (ulong)theNonGroupVars.size();
+  csize numGVars = theGroupVars.size();
+  csize numNGVars = theNonGroupVars.size();
 
-  for (ulong i = 0; i < numGVars; ++i)
+  for (csize i = 0; i < numGVars; ++i)
     theGroupVars[i].second->set_flwor_clause(NULL);
 
-  for (ulong i = 0; i < numNGVars; ++i)
+  for (csize i = 0; i < numNGVars; ++i)
     theNonGroupVars[i].second->set_flwor_clause(NULL);
 }
 
@@ -651,8 +651,8 @@
 
 expr* group_clause::get_input_for_group_var(const var_expr* var)
 {
-  ulong numVars = (ulong)theGroupVars.size();
-  for (ulong i = 0; i < numVars; ++i)
+  csize numVars = theGroupVars.size();
+  for (csize i = 0; i < numVars; ++i)
   {
     if (theGroupVars[i].second.getp() == var)
       return theGroupVars[i].first.getp();
@@ -664,8 +664,8 @@
 
 expr* group_clause::get_input_for_nongroup_var(const var_expr* var)
 {
-  ulong numVars = (ulong)theNonGroupVars.size();
-  for (ulong i = 0; i < numVars; ++i)
+  csize numVars = theNonGroupVars.size();
+  for (csize i = 0; i < numVars; ++i)
   {
     if (theNonGroupVars[i].second.getp() == var)
       return theNonGroupVars[i].first.getp();
@@ -677,20 +677,20 @@
 
 flwor_clause_t group_clause::clone(expr::substitution_t& subst) const
 {
-  ulong numGroupVars = (ulong)theGroupVars.size();
-  ulong numNonGroupVars = (ulong)theNonGroupVars.size();
+  csize numGroupVars = theGroupVars.size();
+  csize numNonGroupVars = theNonGroupVars.size();
 
   rebind_list_t cloneGroupVars(numGroupVars);
   rebind_list_t cloneNonGroupVars(numNonGroupVars);
 
-  for (ulong i = 0; i < numGroupVars; ++i)
+  for (csize i = 0; i < numGroupVars; ++i)
   {
     cloneGroupVars[i].first = theGroupVars[i].first->clone(subst);
     cloneGroupVars[i].second = new var_expr(*theGroupVars[i].second);
     subst[theGroupVars[i].second.getp()] = cloneGroupVars[i].second.getp();
   }
 
-  for (ulong i = 0; i < numNonGroupVars; ++i)
+  for (csize i = 0; i < numNonGroupVars; ++i)
   {
     cloneNonGroupVars[i].first = theNonGroupVars[i].first->clone(subst);
     cloneNonGroupVars[i].second = new var_expr(*theNonGroupVars[i].second);

=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp	2011-10-18 21:29:50 +0000
+++ src/compiler/translator/translator.cpp	2011-10-31 17:53:26 +0000
@@ -1305,11 +1305,25 @@
     if (qname != NULL)
     {
       RAISE_ERROR(zerr::ZDDY0025_INDEX_WRONG_NUMBER_OF_PROBE_ARGS, loc,
-      ERROR_PARAMS(qname->getStringValue()));
+      ERROR_PARAMS(
+        qname->getStringValue(),
+        "index",
+        n-1,
+        "multiple of 6"
+      )
+      );
     }
     else
     {
-      RAISE_ERROR_NO_PARAMS(zerr::ZDDY0025_INDEX_WRONG_NUMBER_OF_PROBE_ARGS, loc);
+      RAISE_ERROR(
+          zerr::ZDDY0025_INDEX_WRONG_NUMBER_OF_PROBE_ARGS, loc,
+          ERROR_PARAMS(
+            "anonymous",
+            "index",
+            n-1,
+            "multiple of 6"
+          )
+      );
     }
   }
 

=== modified file 'src/diagnostics/diagnostic_en.xml'
--- src/diagnostics/diagnostic_en.xml	2011-10-17 21:17:05 +0000
+++ src/diagnostics/diagnostic_en.xml	2011-10-31 17:53:26 +0000
@@ -1966,7 +1966,7 @@
     </diagnostic>
 
     <diagnostic code="ZDDY0025" name="INDEX_WRONG_NUMBER_OF_PROBE_ARGS">
-      <value>${"1": }invalid number of arguments in probe</value>
+      <value>"$1": invalid number of arguments to $2 operation; given $3 expected $4</value>
     </diagnostic>
 
     <diagnostic code="ZDDY0026" name="INDEX_RANGE_PROBE_NOT_ALLOWED">

=== modified file 'src/diagnostics/pregenerated/dict_en.cpp'
--- src/diagnostics/pregenerated/dict_en.cpp	2011-10-20 23:05:55 +0000
+++ src/diagnostics/pregenerated/dict_en.cpp	2011-10-31 17:53:26 +0000
@@ -286,7 +286,7 @@
   { "ZDDY0022", "\"$1\": index already exists" },
   { "ZDDY0023", "\"$1\": index does not exist" },
   { "ZDDY0024", "\"$1\": index uniqueness violation" },
-  { "ZDDY0025", "${\"1\": }invalid number of arguments in probe" },
+  { "ZDDY0025", "\"$1\": invalid number of arguments to $2 operation; given $3 expected $4" },
   { "ZDDY0026", "\"$1\": index range probe not allowed" },
   { "ZDDY0027", "\"$1\": index multiple creates" },
   { "ZDDY0028", "\"$1\": index domain has duplicate nodes" },

=== modified file 'src/runtime/core/flwor_iterator.cpp'
--- src/runtime/core/flwor_iterator.cpp	2011-06-28 15:07:06 +0000
+++ src/runtime/core/flwor_iterator.cpp	2011-10-31 17:53:26 +0000
@@ -18,6 +18,7 @@
 #include "zorbautils/fatal.h"
 #include "diagnostics/assert.h"
 #include "diagnostics/xquery_diagnostics.h"
+#include "diagnostics/util_macros.h"
 
 #include "context/static_context.h"
 
@@ -1474,9 +1475,9 @@
           store::Item_t temp;
           if (typedValueIter->next(temp))
           {
-            throw XQUERY_EXCEPTION(err::XPTY0004,
-                                   ERROR_PARAMS(ZED(SingletonExpected_2o),
-                                                ZED(AtomizationHasMoreThanOneValue)));
+            RAISE_ERROR(err::XPTY0004, loc,
+            ERROR_PARAMS(ZED(SingletonExpected_2o),
+                         ZED(AtomizationHasMoreThanOneValue)));
           }
         }
       }
@@ -1485,9 +1486,7 @@
       store::Item_t temp;
       if (consumeNext(temp, specIter->theInput, planState))
       {
-        throw XQUERY_EXCEPTION(
-          err::XPTY0004, ERROR_PARAMS(ZED(SingletonExpected_2o))
-        );
+        RAISE_ERROR(err::XPTY0004, loc, ERROR_PARAMS(ZED(SingletonExpected_2o)));
       }
     }
 

=== modified file 'src/runtime/core/gflwor/common.cpp'
--- src/runtime/core/gflwor/common.cpp	2011-06-14 17:26:33 +0000
+++ src/runtime/core/gflwor/common.cpp	2011-10-31 17:53:26 +0000
@@ -43,11 +43,13 @@
 GroupingSpec::GroupingSpec(
     PlanIter_t inputVar,
     const std::vector<PlanIter_t>& varRefs,
-    const std::string& collation)
+    const std::string& collation,
+    bool doFastComparison)
   :
   theInput(inputVar),
   theCollation(collation),
-  theCollator(NULL)
+  theCollator(NULL),
+  theDoFastComparison(doFastComparison)
 {
   castIterVector<ForVarIterator>(theVarRefs, varRefs);
 }
@@ -59,6 +61,7 @@
   ar & theVarRefs;
   ar & theCollation;
   ar & theCollator;
+  ar & theDoFastComparison;
 }
 
 
@@ -170,7 +173,7 @@
     const QueryLoc& loc,
     dynamic_context* dctx,
     const TypeManager* tm,
-    std::vector<GroupingSpec>* groupingSpecs) 
+    std::vector<GroupingSpec>* groupingSpecs)
   :
   theLocation(loc),
   theGroupingSpecs(groupingSpecs),
@@ -184,9 +187,9 @@
 {
   uint32_t hash = 0;
 
-  ulong numCols = (ulong)theGroupingSpecs->size();
+  csize numCols = theGroupingSpecs->size();
 
-  for (ulong i = 0; i < numCols; i++)
+  for (csize i = 0; i < numCols; i++)
   {
     if (t->theTypedValues[i] != NULL)
     {
@@ -229,19 +232,30 @@
 
       try
       {
-        if (!CompareIterator::valueEqual(theLocation,
-                                         item1,
-                                         item2,
-                                         theTypeManager,
-                                         theTimezone,
-                                         (*theGroupingSpecs)[i].theCollator))
-        {
-          return false;                                 
+        if ((*theGroupingSpecs)[i].theDoFastComparison)
+        {
+          if (!item1->equals(item2, theTimezone, (*theGroupingSpecs)[i].theCollator))
+          {
+            return false;
+          }
+        }
+        else
+        {
+          if (!CompareIterator::valueEqual(theLocation,
+                                           item1,
+                                           item2,
+                                           theTypeManager,
+                                           theTimezone,
+                                           (*theGroupingSpecs)[i].theCollator))
+          {
+            return false;                                 
+          }
         }
       }
       catch (ZorbaException const& e)
       {
-        if (e.diagnostic() == err::XPTY0004)
+        if (e.diagnostic() == err::XPTY0004 ||
+            e.diagnostic() == zerr::ZSTR0040_TYPE_ERROR)
           return false;
         else
           throw;

=== modified file 'src/runtime/core/gflwor/common.h'
--- src/runtime/core/gflwor/common.h	2011-06-14 17:26:33 +0000
+++ src/runtime/core/gflwor/common.h	2011-10-31 17:53:26 +0000
@@ -107,6 +107,7 @@
   std::vector<ForVarIter_t> theVarRefs;
   std::string               theCollation;
   XQPCollator             * theCollator;
+  bool                      theDoFastComparison;
 
 public:
   SERIALIZABLE_CLASS(GroupingSpec)
@@ -119,7 +120,8 @@
   GroupingSpec(
         PlanIter_t inputVar,
         const std::vector<PlanIter_t>& varRefs,
-        const std::string& aCollation);
+        const std::string& aCollation,
+        bool doFastComparison);
 
   virtual ~GroupingSpec() {}
 

=== modified file 'src/runtime/core/gflwor/groupby_iterator.cpp'
--- src/runtime/core/gflwor/groupby_iterator.cpp	2011-06-14 17:26:33 +0000
+++ src/runtime/core/gflwor/groupby_iterator.cpp	2011-10-31 17:53:26 +0000
@@ -18,6 +18,7 @@
 #include "zorbautils/fatal.h"
 #include "diagnostics/assert.h"
 #include "diagnostics/xquery_diagnostics.h"
+#include "diagnostics/util_macros.h"
 
 #include "context/static_context.h"
 
@@ -358,10 +359,10 @@
   std::vector<store::Item_t>& groupTupleItems = groupTuple->theItems;
   std::vector<store::Item_t>& groupTupleValues = groupTuple->theTypedValues;
 
-  ulong numVars = (ulong)theGroupingSpecs.size();
+  csize numVars = theGroupingSpecs.size();
 
   // For each grouping variable
-  for (ulong i = 0; i < numVars; ++i)
+  for (csize i = 0; i < numVars; ++i)
   {
     groupTupleItems.push_back(NULL);
     groupTupleValues.push_back(NULL);
@@ -379,11 +380,8 @@
       // than 1 item.
       if (consumeNext(temp, theGroupingSpecs[i].theInput.getp(), aPlanState)) 
       {
-        throw XQUERY_EXCEPTION(
-          err::XPTY0004,
-          ERROR_PARAMS( ZED( GroupByVarHasMoreThanOneItem_2 ) ),
-          ERROR_LOC( loc )
-        );
+        RAISE_ERROR(err::XPTY0004, loc,
+        ERROR_PARAMS(ZED(GroupByVarHasMoreThanOneItem_2)));
       }
 
       store::Iterator_t typedValueIter;
@@ -405,11 +403,8 @@
             
             if (typedValueIter->next(temp))
             {
-              throw XQUERY_EXCEPTION(
-                err::XPTY0004,
-                ERROR_PARAMS( ZED( AtomizationOfGroupByMakesMoreThanOneItem ) ),
-                ERROR_LOC( loc )
-              );
+              RAISE_ERROR(err::XPTY0004, loc,
+              ERROR_PARAMS(ZED(AtomizationOfGroupByMakesMoreThanOneItem)));
             }
           }
         }

=== modified file 'src/runtime/indexing/index_ddl.cpp'
--- src/runtime/indexing/index_ddl.cpp	2011-10-05 17:49:48 +0000
+++ src/runtime/indexing/index_ddl.cpp	2011-10-31 17:53:26 +0000
@@ -634,7 +634,12 @@
       if (state->theIndexDecl->getKeyExpressions().size() != numChildren-1)
       {
         RAISE_ERROR(zerr::ZDDY0025_INDEX_WRONG_NUMBER_OF_PROBE_ARGS, loc,
-        ERROR_PARAMS(qnameItem->getStringValue()));
+        ERROR_PARAMS(
+          qnameItem->getStringValue(),
+          "index",
+          numChildren-1,
+          state->theIndexDecl->getKeyExpressions().size())
+        );
       }
 
       state->theIndex = (state->theIndexDecl->isTemp() ?
@@ -800,7 +805,12 @@
           numChildren != 2)
       {
         RAISE_ERROR(zerr::ZDDY0025_INDEX_WRONG_NUMBER_OF_PROBE_ARGS, loc,
-        ERROR_PARAMS(qnameItem->getStringValue()));
+        ERROR_PARAMS(
+          qnameItem->getStringValue(),
+          "index",
+          numChildren-1,
+          state->theIndexDecl->getKeyExpressions().size())
+        );
       }
 
       state->theIndex = (state->theIndexDecl->isTemp() ?
@@ -973,13 +983,23 @@
     if ((numChildren-1) % 6 != 0)
     {
       RAISE_ERROR(zerr::ZDDY0025_INDEX_WRONG_NUMBER_OF_PROBE_ARGS, loc,
-      ERROR_PARAMS(qname->getStringValue()));
+      ERROR_PARAMS(
+        qname->getStringValue(),
+        "index",
+        numChildren-1,
+        "multiple of 6"
+      ));
     }
 
     if (indexDecl->getKeyExpressions().size() * 6 > numChildren-1)
     {
       RAISE_ERROR(zerr::ZDDY0025_INDEX_WRONG_NUMBER_OF_PROBE_ARGS, loc,
-      ERROR_PARAMS(qname->getStringValue()));
+      ERROR_PARAMS(
+        qname->getStringValue(),
+        "index",
+        numChildren-1,
+        indexDecl->getKeyExpressions().size() * 6
+      ));
     }
 
     state->theIndex = (indexDecl->isTemp() ?

=== modified file 'src/runtime/qnames/qnames_impl.cpp'
--- src/runtime/qnames/qnames_impl.cpp	2011-07-19 19:35:04 +0000
+++ src/runtime/qnames/qnames_impl.cpp	2011-10-31 17:53:26 +0000
@@ -1,12 +1,12 @@
 /*
  * Copyright 2006-2008 The FLWOR Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -52,7 +52,7 @@
   PlanIteratorState* state;
   DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
 
-  if (consumeNext(itemQName, theChild0.getp(), planState )) 
+  if (consumeNext(itemQName, theChild0.getp(), planState ))
   {
     itemQName->getStringValue2(qname);
 
@@ -60,7 +60,7 @@
 
     index = qname.find(":", 0, 1);
 
-    if (index != zstring::npos) 
+    if (index != zstring::npos)
     {
       resPre = qname.substr(0, index);
       resLocal = qname.substr(index+1, qname.size() - index);
@@ -70,7 +70,7 @@
         throw XQUERY_EXCEPTION(
           err::FOCA0002, ERROR_PARAMS( qname ), ERROR_LOC(loc)
         );
-    } 
+    }
     else
     {
       resLocal = qname;
@@ -80,8 +80,8 @@
           err::FOCA0002, ERROR_PARAMS( qname ), ERROR_LOC(loc)
         );
     }
-      
-    if (consumeNext(itemElem, theChild1, planState )) 
+
+    if (consumeNext(itemElem, theChild1, planState ))
     {
       itemElem->getNamespaceBindings(NamespaceBindings);
 
@@ -104,7 +104,7 @@
           err::FONS0004, ERROR_PARAMS( resPre ), ERROR_LOC( loc )
         );
     }
-    
+
     GENV_ITEMFACTORY->createQName(result, resNs, resPre, resLocal);
 
     STACK_PUSH(true, state);
@@ -128,7 +128,7 @@
   PlanIteratorState* state;
   DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
 
-  if (consumeNext(itemURI, theChild0.getp(), planState )) 
+  if (consumeNext(itemURI, theChild0.getp(), planState ))
   {
     itemURI->getStringValue2(resNs);
 
@@ -138,12 +138,12 @@
   consumeNext(itemQName, theChild1.getp(), planState );
 
   itemQName->getStringValue2(qname);
-  
+
   ascii::trim_whitespace(qname);
 
   index = qname.find(":", 0, 1);
 
-  if (index != zstring::npos) 
+  if (index != zstring::npos)
   {
     if (resNs.empty())
       throw XQUERY_EXCEPTION(
@@ -152,12 +152,12 @@
 
     resPre = qname.substr(0, index);
     resLocal = qname.substr(index+1, qname.size() - index);
-  } 
+  }
   else
   {
     resLocal = qname;
   }
-  
+
   if ((index != zstring::npos && ! GENV_GCAST.castableToNCName(resPre)) ||
       ! GENV_GCAST.castableToNCName(resLocal))
   {
@@ -209,7 +209,7 @@
 
 //11.2.2 fn:prefix-from-QName
 bool PrefixFromQNameIterator::nextImpl(
-    store::Item_t& result, 
+    store::Item_t& result,
     PlanState& planState) const
 {
   store::Item_t item;
@@ -232,8 +232,8 @@
 
 //11.2.3 fn:local-name-from-QName
 bool LocalNameFromQNameIterator::nextImpl(
-    store::Item_t& result, 
-    PlanState& planState) const 
+    store::Item_t& result,
+    PlanState& planState) const
 {
   store::Item_t item;
   zstring localName;
@@ -253,7 +253,7 @@
 //11.2.4 fn:namespace-uri-from-QName
 bool NamespaceUriFromQNameIterator::nextImpl(
     store::Item_t& result,
-    PlanState& planState) const 
+    PlanState& planState) const
 {
   store::Item_t item;
   zstring ns;
@@ -277,6 +277,7 @@
 {
   store::Item_t itemPrefix, itemElem;
   zstring resNs;
+  zstring prefix;
   bool found = false;
   store::NsBindings NamespaceBindings;
   store::NsBindings::const_iterator iter;
@@ -284,43 +285,35 @@
   PlanIteratorState* state;
   DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
 
-//  According to W3C bug #11590 comment #9
-//  http://www.w3.org/Bugs/Public/show_bug.cgi?id=11590#c9
-//  namespace-uri-for-prefix('', <a/>)
-//  and
-//  namespace-uri-for-prefix((), <a/>)
-//  should return the empty sequence
   if (!consumeNext(itemPrefix, theChildren[0].getp(), planState ))
   {
-    resNs = theSctx->default_elem_type_ns();
-    found = true;
-  }
-  else
-  {
-    if (!consumeNext(itemElem, theChildren[1].getp(), planState ))
-    {
-      ZORBA_ASSERT(false);
-    }
-    else 
-    {
-      itemElem->getNamespaceBindings(NamespaceBindings);
-
-      for (iter = NamespaceBindings.begin();
-           iter != NamespaceBindings.end();
-           ++iter)
-      {
-        zstring pre;
-        itemPrefix->getStringValue2(pre);
-
-        ascii::trim_whitespace(pre);
-
-        if ((*iter).first == pre)
+    prefix = "";
+  }
+  else
+  {
+    itemPrefix->getStringValue2(prefix);
+    ascii::trim_whitespace(prefix);
+  }
+
+  if (!consumeNext(itemElem, theChildren[1].getp(), planState ))
+  {
+    ZORBA_ASSERT(false);
+  }
+  else
+  {
+    itemElem->getNamespaceBindings(NamespaceBindings);
+
+    for (iter = NamespaceBindings.begin();
+         iter != NamespaceBindings.end();
+         ++iter)
+    {
+      if (((*iter).first == prefix) &&
+          !(*iter).second.empty())
         {
           resNs = (*iter).second;
           found = true;
           break;
         }
-      }
     }
   }
 

=== modified file 'src/runtime/store/maps_impl.cpp'
--- src/runtime/store/maps_impl.cpp	2011-08-17 23:04:48 +0000
+++ src/runtime/store/maps_impl.cpp	2011-10-31 17:53:26 +0000
@@ -241,7 +241,11 @@
   {
     throw XQUERY_EXCEPTION(
       zerr::ZDDY0025_INDEX_WRONG_NUMBER_OF_PROBE_ARGS,
-      ERROR_PARAMS( lQName->getStringValue() ),
+      ERROR_PARAMS(
+        lQName->getStringValue(),
+        "map",
+        theChildren.size() - 1,
+        lSpec.getNumColumns() ),
       ERROR_LOC( loc )
     );
   }
@@ -316,7 +320,11 @@
   {
     throw XQUERY_EXCEPTION(
       zerr::ZDDY0025_INDEX_WRONG_NUMBER_OF_PROBE_ARGS,
-      ERROR_PARAMS( lQName->getStringValue() ),
+      ERROR_PARAMS(
+        lQName->getStringValue(),
+        "map",
+        theChildren.size() - 2,
+        lSpec.getNumColumns() ),
       ERROR_LOC( loc )
     );
   }
@@ -386,7 +394,12 @@
   {
     throw XQUERY_EXCEPTION(
       zerr::ZDDY0025_INDEX_WRONG_NUMBER_OF_PROBE_ARGS,
-      ERROR_PARAMS( lQName->getStringValue() ),
+      ERROR_PARAMS(
+        lQName->getStringValue(),
+        "map",
+        theChildren.size() - 1,
+        lSpec.getNumColumns()
+      ),
       ERROR_LOC( loc )
     );
   }

=== modified file 'src/store/naive/atomic_items.cpp'
--- src/store/naive/atomic_items.cpp	2011-09-30 14:06:33 +0000
+++ src/store/naive/atomic_items.cpp	2011-10-31 17:53:26 +0000
@@ -562,6 +562,18 @@
 }
 
 
+bool UntypedAtomicItem::equals(
+    const store::Item* other,
+    long timezone,
+    const XQPCollator* collation) const
+{
+  if (collation == NULL || collation->doMemCmp())
+    return theValue == other->getString();
+
+  return (utf8::compare(theValue, other->getString(), collation) == 0);
+}
+
+
 store::Item_t UntypedAtomicItem::getEBV() const
 {
   bool b = ! ( theValue == "" );
@@ -598,11 +610,13 @@
   GET_STORE().getQNamePool().remove(this);
 }
 
+
 QNameItem* QNameItem::getNormalized() const
 {
   return (isNormalized() ? const_cast<QNameItem*>(this) : theNormQName.getp());
 }
 
+
 uint32_t QNameItem::hash(long timezone, const XQPCollator* aCollation) const
 {
   const void* tmp = getNormalized();
@@ -618,22 +632,20 @@
 
 store::Item_t QNameItem::getEBV() const
 {
-  throw XQUERY_EXCEPTION(
-    err::FORG0006,
-    ERROR_PARAMS(
-      ZED( OperationNotDef_23 ), ZED( EffectiveBooleanValue ), "QName"
-    )
-  );
+  throw XQUERY_EXCEPTION(err::FORG0006,
+  ERROR_PARAMS(ZED(OperationNotDef_23), ZED(EffectiveBooleanValue), "QName"));
 }
 
+
 bool QNameItem::equals(
-        const store::Item* item,
-        long timezone,
-        const XQPCollator* aCollation) const
+    const store::Item* item,
+    long timezone,
+    const XQPCollator* aCollation) const
 {
   return (getNormalized() == static_cast<const QNameItem*>(item)->getNormalized());
 }
 
+
 zstring QNameItem::getStringValue() const
 {
   if (thePrefix.empty())
@@ -742,7 +754,8 @@
                           long timezone,
                           const XQPCollator* aCollation) const
 {
-  return (theQName->getNormalized() == static_cast<const NotationItem*>(item)->theQName->getNormalized());
+  return (theQName->getNormalized() == 
+          static_cast<const NotationItem*>(item)->theQName->getNormalized());
 }
 
 
@@ -849,6 +862,8 @@
     long timezone,
     const XQPCollator* aCollation) const
 {
+  // Note: utf8::compare does byte comparison if the collation is null or
+  // requires byte comparison.
   return utf8::compare(theValue, other->getString(), aCollation);
 }
 
@@ -871,10 +886,11 @@
 }
 
 #ifndef ZORBA_NO_FULL_TEXT
-FTTokenIterator_t
-StringItem::getTokens( TokenizerProvider const &provider,
-                       Tokenizer::Numbers &numbers, iso639_1::type lang,
-                       bool wildcards ) const
+FTTokenIterator_t StringItem::getTokens( 
+    TokenizerProvider const &provider,
+    Tokenizer::Numbers &numbers,
+    iso639_1::type lang,
+    bool wildcards ) const
 {
   typedef NaiveFTTokenIterator::container_type tokens_t;
   unique_ptr<tokens_t> tokens( new tokens_t );
@@ -893,7 +909,8 @@
 ********************************************************************************/
 void StreamableStringItem::appendStringValue(zstring& aBuf) const
 {
-  if (!theIsMaterialized) {
+  if (!theIsMaterialized) 
+  {
     materialize();
   }
   aBuf += theValue;
@@ -905,7 +922,8 @@
     long aTimezone,
     const XQPCollator* aCollator) const
 {
-  if (!theIsMaterialized) {
+  if (!theIsMaterialized) 
+  {
     materialize();
   }
   return StringItem::compare(aOther, aTimezone, aCollator);
@@ -917,7 +935,8 @@
     long aTimezone,
     XQPCollator const* aCollator) const 
 {
-  if (!theIsMaterialized) {
+  if (!theIsMaterialized) 
+  {
     materialize();
   }
   return StringItem::equals(aItem, aTimezone, aCollator);
@@ -926,7 +945,8 @@
 
 store::Item_t StreamableStringItem::getEBV() const
 {
-  if (!theIsMaterialized) {
+  if (!theIsMaterialized) 
+  {
     materialize();
   }
   return StringItem::getEBV();
@@ -935,7 +955,8 @@
 
 zstring const& StreamableStringItem::getString() const
 {
-  if (!theIsMaterialized) {
+  if (!theIsMaterialized) 
+  {
     materialize();
   }
   return theValue;
@@ -944,7 +965,8 @@
 
 zstring StreamableStringItem::getStringValue() const
 {
-  if (!theIsMaterialized) {
+  if (!theIsMaterialized) 
+  {
     materialize();
   }
   return theValue;
@@ -953,7 +975,8 @@
 
 void StreamableStringItem::getStringValue2(zstring &val) const
 {
-  if (!theIsMaterialized) {
+  if (!theIsMaterialized) 
+  {
     materialize();
   }
   val = theValue;
@@ -964,7 +987,8 @@
     long aTimezone,
     XQPCollator const* aCollator) const
 {
-  if (!theIsMaterialized) {
+  if (!theIsMaterialized) 
+  {
     materialize();
   }
   return StringItem::hash(aTimezone, aCollator);
@@ -973,7 +997,8 @@
 
 zstring StreamableStringItem::show() const
 {
-  if (!theIsMaterialized) {
+  if (!theIsMaterialized) 
+  {
     materialize();
   }
   return StringItem::show();
@@ -1016,11 +1041,13 @@
   return theIstream;
 }
 
+
 StreamReleaser StreamableStringItem::getStreamReleaser()
 {
   return theStreamReleaser;
 }
 
+
 void StreamableStringItem::setStreamReleaser(StreamReleaser aReleaser)
 {
   theStreamReleaser = aReleaser;

=== modified file 'src/store/naive/atomic_items.h'
--- src/store/naive/atomic_items.h	2011-09-30 14:06:33 +0000
+++ src/store/naive/atomic_items.h	2011-10-31 17:53:26 +0000
@@ -308,12 +308,9 @@
   bool equals(
         const store::Item* other,
         long timezone = 0,
-        const XQPCollator* aCollation = 0) const
-  {
-    return theValue == other->getString();
-  }
+        const XQPCollator* collation = 0) const;
 
-  store::Item_t getEBV( ) const;
+  store::Item_t getEBV() const;
 
   zstring getStringValue() const { return theValue; }
 
@@ -637,7 +634,8 @@
 
   ~StreamableStringItem()
   {
-    if (theStreamReleaser) {
+    if (theStreamReleaser) 
+    {
       theStreamReleaser(&theIstream);
     }
   }

=== modified file 'src/types/casting.cpp'
--- src/types/casting.cpp	2011-07-29 22:38:19 +0000
+++ src/types/casting.cpp	2011-10-31 17:53:26 +0000
@@ -25,6 +25,7 @@
 
 #include "diagnostics/xquery_diagnostics.h"
 #include "diagnostics/assert.h"
+#include "diagnostics/util_macros.h"
 
 #include "context/namespace_context.h"
 
@@ -64,13 +65,18 @@
 
 struct ErrorInfo
 {
-  const XQType* theSourceType;
-  const XQType* theTargetType;
+  const XQType   * theSourceType;
+  const XQType   * theTargetType;
+  const QueryLoc & theLoc;
 };
 
 
-#define TYPE_EXCEPTION( ERROR_CODE, ERROR_INFO ) \
-  XQUERY_EXCEPTION( ERROR_CODE, ERROR_PARAMS( *(ERROR_INFO).theSourceType, ZED( NoCastTo_34o ), *(ERROR_INFO).theTargetType ) )
+#define TYPE_EXCEPTION( ERROR_CODE, ERROR_INFO )  \
+  XQUERY_EXCEPTION(ERROR_CODE,                    \
+  ERROR_PARAMS(*(ERROR_INFO).theSourceType,       \
+               ZED( NoCastTo_34o ),               \
+               *(ERROR_INFO).theTargetType ),     \
+  ERROR_LOC(ERROR_INFO.theLoc) )
 
 
 /*******************************************************************************
@@ -136,41 +142,49 @@
 
 T1_TO_T2(str, flt)
 {
-  try {
+  try 
+  {
     xs_float const n(strval.c_str());
     return aFactory->createFloat(result, n);
   }
-  catch ( std::invalid_argument const& ) {
-    throw TYPE_EXCEPTION( err::FORG0001, aErrorInfo );
+  catch (std::invalid_argument const&) 
+  {
+    throw TYPE_EXCEPTION(err::FORG0001, aErrorInfo);
   }
-  catch ( std::range_error const& ) {
-    throw XQUERY_EXCEPTION( err::FOAR0002, ERROR_PARAMS( strval ) );
+  catch ( std::range_error const& ) 
+  {
+    throw XQUERY_EXCEPTION(err::FOAR0002, ERROR_PARAMS(strval));
   }
 }
 
 
 T1_TO_T2(str, dbl)
 {
-  try {
+  try 
+  {
     xs_double const n(strval.c_str());
     return aFactory->createDouble(result, n);
   }
-  catch ( std::invalid_argument const& ) {
+  catch (std::invalid_argument const& ) 
+  {
     throw TYPE_EXCEPTION( err::FORG0001, aErrorInfo );
   }
-  catch ( std::range_error const& ) {
-    throw XQUERY_EXCEPTION( err::FOAR0002, ERROR_PARAMS( strval ) );
+  catch (std::range_error const& ) 
+  {
+    throw XQUERY_EXCEPTION(err::FOAR0002, ERROR_PARAMS(strval));
   }
 }
 
 
 T1_TO_T2(str, dec)
 {
-  try {
+  try 
+  {
     xs_decimal const n(strval.c_str());
     return aFactory->createDecimal(result, n);
   }
-  catch ( std::exception const& ) {
+  catch ( std::exception const& ) 
+  {
     throw TYPE_EXCEPTION( err::FORG0001, aErrorInfo );
   }
 }
@@ -178,14 +192,17 @@
 
 T1_TO_T2(str, int)
 {
-  try {
+  try 
+  {
     xs_integer const n(strval.c_str());
     return aFactory->createInteger(result, n);
   }
-  catch ( std::invalid_argument const& ) {
+  catch ( std::invalid_argument const& ) 
+  {
     throw TYPE_EXCEPTION( err::FORG0001, aErrorInfo );
   }
-  catch ( std::range_error const& ) {
+  catch ( std::range_error const& ) 
+  {
     throw TYPE_EXCEPTION( err::FOAR0002, aErrorInfo );
   }
 }
@@ -199,7 +216,7 @@
   if (0 == (err = Duration::parseDuration(strval.c_str(), strval.size(), d)))
     return aFactory->createDuration(result, &d);
 
-  throw TYPE_EXCEPTION( err::FORG0001, aErrorInfo );
+  throw TYPE_EXCEPTION(err::FORG0001, aErrorInfo);
 }
 
 
@@ -1669,7 +1686,7 @@
 
   const XQType* sourceType = rtm.STRING_TYPE_ONE.getp();
 
-  ErrorInfo lErrorInfo = {&*sourceType, aTargetType};
+  ErrorInfo lErrorInfo = {&*sourceType, aTargetType, loc};
 
   if (!TypeOps::is_atomic(tm, *aTargetType))
     throw XQUERY_EXCEPTION( err::XPST0051, ERROR_PARAMS( aTargetType ) );
@@ -1740,112 +1757,110 @@
 
 
 /*******************************************************************************
-  Cast, if possible, a given item SI to an atomic item TI of a given type TT.
-  If I1 is not
+  Cast, if possible, a given atomic item SI to an atomic item TI of a given 
+  type TT. If the cast is not allowed, the method raises an error. If the cast
+  is not possible, the method may raise an error or return false (TODO fix 
+  this!). Otherwise, it returns true.
 ********************************************************************************/
 bool GenericCast::castToAtomic(
     store::Item_t&       result,
     store::Item_t&       aItem,
-    const XQType*        aTargetType,
+    const XQType*        targetType,
     const TypeManager*   tm,
-    namespace_context*   aNCtx,
+    namespace_context*   nsCtx,
     const QueryLoc&      loc)
 {
   RootTypeManager& rtm = GENV_TYPESYSTEM;
-  store::ItemFactory* lFactory = GENV_ITEMFACTORY;
-
-  xqtref_t lSourceType = tm->create_named_type(aItem->getType(),
-                                               TypeConstants::QUANT_ONE,
-                                               QueryLoc::null,
-                                               err::XPTY0004);
+  store::ItemFactory* factory = GENV_ITEMFACTORY;
 
   ZORBA_ASSERT(aItem->isAtomic());
-  ZORBA_ASSERT(lSourceType != NULL);
-  ZORBA_ASSERT(TypeOps::is_atomic(tm, *lSourceType));
+
+  xqtref_t sourceType = tm->create_named_type(aItem->getType(),
+                                              TypeConstants::QUANT_ONE,
+                                              QueryLoc::null,
+                                              err::XPTY0004);
+  ZORBA_ASSERT(sourceType != NULL);
+  assert(TypeOps::is_atomic(tm, *sourceType));
 
   // std::cout << "-castToAtomic: " << aItem.getp()->getStringValue()->c_str()
-  //           << " srcType: " << lSourceType->get_qname()->getLocalName()->c_str()
-  //           << " @ " << lSourceType->get_qname()->getNamespace()->c_str() << "\n";
+  //           << " srcType: " << sourceType->get_qname()->getLocalName()->c_str()
+  //           << " @ " << sourceType->get_qname()->getNamespace()->c_str() << "\n";
   // std::cout << "\t\t  tgtType: " << aTargetType->get_qname()->getLocalName()->c_str()
   //           << " @ " << aTargetType->get_qname()->getNamespace()->c_str() << "\n";
 
-  ErrorInfo lErrorInfo = {&*lSourceType, aTargetType};
+  ErrorInfo errorInfo = {&*sourceType, targetType, loc};
 
-  if (!TypeOps::is_atomic(tm, *aTargetType))
-    throw XQUERY_EXCEPTION(err::XPST0051, ERROR_PARAMS(aTargetType));
+  if (!TypeOps::is_atomic(tm, *targetType))
+    RAISE_ERROR(err::XPST0051, loc, ERROR_PARAMS(targetType));
 
 #ifndef ZORBA_NO_XMLSCHEMA
-  if (aTargetType->type_kind() == XQType::USER_DEFINED_KIND)
+  if (targetType->type_kind() == XQType::USER_DEFINED_KIND)
   {
-    castToUserDefinedType(result, aItem, lSourceType.getp(), aTargetType, loc);
+    castToUserDefinedType(result, aItem, sourceType.getp(), targetType, loc);
     return result != NULL;
   }
 #endif // ZORBA_NO_XMLSCHEMA
 
+  sourceType = sourceType->getBaseBuiltinType();
+
   zstring sourceString;
-  ATOMIC_CODE_T lSourceTypeCode;
-  ATOMIC_CODE_T lTargetTypeCode = TypeOps::get_atomic_type_code(*aTargetType);
-
-  lSourceType = lSourceType->getBaseBuiltinType();
-
-  ZORBA_ASSERT(TypeOps::is_builtin_atomic(tm, *lSourceType));
-
-  lSourceTypeCode = TypeOps::get_atomic_type_code(*lSourceType);
-
-  if (lSourceTypeCode == lTargetTypeCode)
+  ATOMIC_CODE_T sourceTypeCode = TypeOps::get_atomic_type_code(*sourceType);
+  ATOMIC_CODE_T targetTypeCode = TypeOps::get_atomic_type_code(*targetType);
+
+  if (sourceTypeCode == targetTypeCode)
   {
     result.transfer(aItem);
     return true;
   }
 
-  if (theMapping[lSourceTypeCode] == theMapping[TypeConstants::XS_STRING])
+  if (targetTypeCode == TypeConstants::XS_NOTATION ||
+      targetTypeCode == TypeConstants::XS_ANY_ATOMIC)
+  {
+    RAISE_ERROR(err::XPST0080, loc,
+    ERROR_PARAMS(*errorInfo.theTargetType));
+  }
+
+  if (sourceTypeCode == TypeConstants::XS_ANY_ATOMIC)
+    throw TYPE_EXCEPTION(err::XPTY0004, errorInfo);
+
+  if (targetTypeCode == TypeConstants::XS_NCNAME &&
+      sourceTypeCode != TypeConstants::XS_STRING &&
+      sourceTypeCode != TypeConstants::XS_NCNAME &&
+      sourceTypeCode != TypeConstants::XS_UNTYPED_ATOMIC)
+    throw TYPE_EXCEPTION(err::XPTY0004, errorInfo);
+
+  CastFunc castFunc = theCastMatrix[theMapping[sourceTypeCode]]
+                                    [theMapping[targetTypeCode]];
+  if (castFunc == 0)
+    throw TYPE_EXCEPTION(err::XPTY0004, errorInfo);
+
+  if (theMapping[sourceTypeCode] == theMapping[TypeConstants::XS_STRING])
   {
     aItem->getStringValue2(sourceString);
   }
 
-  if (lTargetTypeCode == TypeConstants::XS_NOTATION ||
-      lTargetTypeCode == TypeConstants::XS_ANY_ATOMIC)
-  {
-    throw XQUERY_EXCEPTION(err::XPST0080,
-                           ERROR_PARAMS(*lErrorInfo.theTargetType),
-                           ERROR_LOC(loc));
-  }
-
-  if (lSourceTypeCode == TypeConstants::XS_ANY_ATOMIC)
-    throw TYPE_EXCEPTION(err::XPTY0004, lErrorInfo);
-
-  if (lTargetTypeCode == TypeConstants::XS_NCNAME &&
-      lSourceTypeCode != TypeConstants::XS_STRING &&
-      lSourceTypeCode != TypeConstants::XS_NCNAME &&
-      lSourceTypeCode != TypeConstants::XS_UNTYPED_ATOMIC)
-    throw TYPE_EXCEPTION(err::XPTY0004, lErrorInfo);
-
-  CastFunc lCastFunc = theCastMatrix[theMapping[lSourceTypeCode]]
-                                    [theMapping[lTargetTypeCode]];
-  if (lCastFunc == 0)
-    throw TYPE_EXCEPTION(err::XPTY0004, lErrorInfo);
-
-  bool valid = (*lCastFunc)(result,
-                            aItem,
-                            sourceString,
-                            lFactory,
-                            aNCtx,
-                            lErrorInfo);
-
-  DownCastFunc lDownCastFunc = theDownCastMatrix[theMapping[lTargetTypeCode]];
-
-  if (lDownCastFunc != 0 &&
-      lTargetTypeCode != TypeConstants::XS_STRING &&
-      lTargetTypeCode != TypeConstants::XS_INTEGER)
-  {
-    valid = (*lDownCastFunc)(result,
-                             &*result,
-                             rtm,
-                             lTargetTypeCode,
-                             lFactory,
-                             lErrorInfo);
-  }
-
+  bool valid = (*castFunc)(result,
+                           aItem,
+                           sourceString,
+                           factory,
+                           nsCtx,
+                           errorInfo);
+
+  DownCastFunc downCastFunc = theDownCastMatrix[theMapping[targetTypeCode]];
+
+  if (downCastFunc != 0 &&
+      targetTypeCode != TypeConstants::XS_STRING &&
+      targetTypeCode != TypeConstants::XS_INTEGER)
+  {
+    valid = (*downCastFunc)(result,
+                            &*result,
+                            rtm,
+                            targetTypeCode,
+                            factory,
+                            errorInfo);
+  }
+
+  assert(valid);
   return valid;
 }
 
@@ -1860,7 +1875,7 @@
     const XQType* aTargetType,
     const QueryLoc& loc)
 {
-  ErrorInfo lErrorInfo = {aSourceType, aTargetType};
+  ErrorInfo lErrorInfo = {aSourceType, aTargetType, loc};
 
   // std::cout << "-castToUserDefinedType: " << aItem.getp()->getStringValue()->c_str()
   //           << " srcType: " << aSourceType->get_qname()->getLocalName()->c_str()
@@ -1875,7 +1890,7 @@
   if (aSourceType->type_kind() != XQType::ATOMIC_TYPE_KIND ||
       (TypeOps::get_atomic_type_code(*aSourceType) != TypeConstants::XS_STRING))
   {
-    throw TYPE_EXCEPTION( err::FORG0001, lErrorInfo );
+    throw TYPE_EXCEPTION(err::FORG0001, lErrorInfo);
   }
 
   const UserDefinedXQType* udt =
@@ -1971,7 +1986,7 @@
     );
   }
 
-  ErrorInfo errorInfo = { sourceType.getp(), rtm.QNAME_TYPE_ONE.getp() };
+  ErrorInfo errorInfo = { sourceType.getp(), rtm.QNAME_TYPE_ONE.getp(), loc };
 
   zstring strval;
   item->getStringValue2(strval);
@@ -2405,14 +2420,15 @@
   if (TypeOps::is_equal(tm, *lItemType, *rtm.UNTYPED_ATOMIC_TYPE_ONE) &&
       ! TypeOps::is_equal(tm, *TypeOps::prime_type(tm, *aTargetType), *rtm.QNAME_TYPE_ONE))
   {
-    return GenericCast::castToAtomic(result, aItem, aTargetType, tm, NULL, loc);
+    // untyped --> target type
+    return castToAtomic(result, aItem, aTargetType, tm, NULL, loc);
   }
   else if (TypeOps::is_subtype(tm, *aTargetType, *rtm.FLOAT_TYPE_ONE))
   {
     // decimal --> xs:float
     if (TypeOps::is_subtype(tm, *lItemType, *rtm.DECIMAL_TYPE_ONE))
     {
-      return GenericCast::castToAtomic(result, aItem, aTargetType, tm, NULL, loc);
+      return castToAtomic(result, aItem, aTargetType, tm, NULL, loc);
     }
   }
   else if (TypeOps::is_subtype(tm, *aTargetType, *rtm.DOUBLE_TYPE_ONE))
@@ -2421,7 +2437,7 @@
     if (TypeOps::is_subtype(tm, *lItemType, *rtm.DECIMAL_TYPE_ONE) ||
         TypeOps::is_subtype(tm, *lItemType, *rtm.FLOAT_TYPE_ONE))
     {
-      return GenericCast::castToAtomic(result, aItem, aTargetType, tm, NULL, loc);
+      return castToAtomic(result, aItem, aTargetType, tm, NULL, loc);
     }
   }
   else if (TypeOps::is_subtype(tm, *aTargetType, *rtm.STRING_TYPE_ONE))
@@ -2429,7 +2445,7 @@
     // URI --> xs:String Promotion
     if (TypeOps::is_subtype(tm, *lItemType, *rtm.ANY_URI_TYPE_ONE))
     {
-      return GenericCast::castToAtomic(result, aItem, &*rtm.STRING_TYPE_ONE, tm, NULL, loc);
+      return castToAtomic(result, aItem, &*rtm.STRING_TYPE_ONE, tm, NULL, loc);
     }
   }
 

=== modified file 'src/types/schema/schema.cpp'
--- src/types/schema/schema.cpp	2011-07-22 07:23:17 +0000
+++ src/types/schema/schema.cpp	2011-10-31 17:53:26 +0000
@@ -1177,7 +1177,7 @@
   }
   else if ( XMLString::equals(SchemaSymbols::fgDT_MONTH, local) )
   {
-    result = GENV_TYPESYSTEM.GMONTH_DAY_TYPE_ONE;
+    result = GENV_TYPESYSTEM.GMONTH_TYPE_ONE;
   }
   else if ( XMLString::equals(SchemaSymbols::fgDT_DURATION, local) )
   {

=== modified file 'swig/CMakeLists.txt'
--- swig/CMakeLists.txt	2011-09-09 16:33:19 +0000
+++ swig/CMakeLists.txt	2011-10-31 17:53:26 +0000
@@ -26,6 +26,7 @@
   SET (SWIG_MODULE_zorba_api_EXTRA_DEPS ${SWIG_FILES})
   SET (SWIG_MODULE_libzorba_api_EXTRA_DEPS ${SWIG_FILES})
 
+  
   # on apple and cmake 2.8, the generated swig libraries are prefixed with "lib"
   SET (ZORBA_SWIG_LIB_PREFIX)
   IF (APPLE AND CMAKE_MINOR_VERSION GREATER 6)

=== added file 'swig/ItemFactory.h'
--- swig/ItemFactory.h	1970-01-01 00:00:00 +0000
+++ swig/ItemFactory.h	2011-10-31 17:53:26 +0000
@@ -0,0 +1,69 @@
+// Interface
+
+class ItemFactory
+{
+
+  private:
+    zorba::ItemFactory* theItemFactory;
+  public:
+    ItemFactory(): theItemFactory(0) {}
+    ItemFactory(zorba::ItemFactory* aItemFactory) : theItemFactory(aItemFactory) {}
+    ItemFactory(const ItemFactory& aItemFactory) : theItemFactory(aItemFactory.theItemFactory) {}
+
+    Item 	createAnyURI (const std::string &aURI);
+    Item 	createAttributeNode (Item aParent, Item aNodeName, Item aTypeName, Item aTypedValue);
+    Item 	createAttributeNode (Item aParent, Item aNodeName, Item aTypeName, std::vector< Item > aTypedValue);
+    Item 	createBase64Binary (const char *aBinData, size_t aLength);
+    Item 	createBase64Binary (std::istream &aStream);
+    Item 	createBase64Binary (const unsigned char *aBinData, size_t aLength);
+    Item 	createBoolean (bool aValue);
+    Item 	createByte (char aByte);
+    Item 	createDate (const std::string &aDate);
+    Item 	createDate (short aYear, short aMonth, short aDay);
+    Item 	createDateTime (const std::string &aDateTimeValue);
+    Item 	createDateTime (short aYear, short aMonth, short aDay, short aHour, short aMinute, double aSecond, short aTimeZone_hours);
+    Item 	createDecimal (const std::string &aValue);
+    Item 	createDecimalFromDouble (double aValue);
+    Item 	createDecimalFromLong (unsigned long aValue);
+    Item 	createDouble (const std::string &aValue);
+    Item 	createDouble (double aValue);
+    Item 	createDuration (const std::string &aValue);
+    Item 	createDuration (short aYear, short aMonths, short aDays, short aHours, short aMinutes, double aSeconds);
+    //Item 	createElementNode (Item &aParent, Item aNodeName, Item aTypeName, bool aHasTypedValue, bool aHasEmptyValue, std::vector< std::pair< std::string, std::string > > aNsBindings);
+    Item 	createFloat (const std::string &aValue);
+    Item 	createFloat (float aValue);
+    Item 	createGDay (const std::string &aValue);
+    Item 	createGDay (short aDay);
+    Item 	createGMonth (const std::string &aValue);
+    Item 	createGMonth (short aMonth);
+    Item 	createGMonthDay (const std::string &aValue);
+    Item 	createGMonthDay (short aMonth, short aDay);
+    Item 	createGYear (short aYear);
+    Item 	createGYear (const std::string &aValue);
+    Item 	createGYearMonth (const std::string &aValue);
+    Item 	createGYearMonth (short aYear, short aMonth);
+    Item 	createHexBinary (const char *aHexData, size_t aSize);
+    Item 	createInt (int aInt);
+    Item 	createInteger (const std::string &aInteger);
+    Item 	createInteger (long long aInteger);
+    Item 	createLong (long long aLong);
+    Item 	createNCName (const std::string &aValue);
+    Item 	createNegativeInteger (long long aValue);
+    Item 	createNonNegativeInteger (unsigned long long aValue);
+    Item 	createNonPositiveInteger (long long aValue);
+    Item 	createPositiveInteger (unsigned long long aValue);
+    Item 	createQName (const std::string &aNamespace, const std::string &aPrefix, const std::string &aLocalname);
+    Item 	createQName (const std::string &aNamespace, const std::string &aLocalname);
+    Item 	createQName (const std::string &aQNameString);
+    Item 	createShort (short aShort);
+    //Item 	createStreamableString (std::istream &stream, StreamReleaser streamReleaser, bool seekable=false);
+    Item 	createString (const std::string &aString);
+    Item 	createTextNode (Item parent, std::string content);
+    Item 	createTime (short aHour, short aMinute, double aSecond, short aTimeZone_hours);
+    Item 	createTime (short aHour, short aMinute, double aSecond);
+    Item 	createTime (const std::string &aValue);
+    Item 	createUnsignedByte (const unsigned char aValue);
+    Item 	createUnsignedInt (unsigned int aValue);
+    Item 	createUnsignedLong (unsigned long long aValue);
+    Item 	createUnsignedShort (unsigned short aValue);
+}; // class ItemFactory

=== added file 'swig/ItemFactory.i'
--- swig/ItemFactory.i	1970-01-01 00:00:00 +0000
+++ swig/ItemFactory.i	2011-10-31 17:53:26 +0000
@@ -0,0 +1,192 @@
+
+%{  // start Implementation
+
+
+ 
+  Item 	ItemFactory::createAnyURI (const std::string &aURI){
+    return Item(theItemFactory->createAnyURI(aURI));
+  }
+  
+  Item 	ItemFactory::createAttributeNode (Item aParent, Item aNodeName, Item aTypeName, Item aTypedValue){
+    return Item( theItemFactory->createAttributeNode( aParent.theItem, aNodeName.theItem, aTypeName.theItem, aTypedValue.theItem ));
+  }
+  
+  Item 	ItemFactory::createAttributeNode (Item aParent, Item aNodeName, Item aTypeName, std::vector< Item > aTypedValue){
+
+    std::vector< zorba::Item > typedValue;
+    typedValue.reserve(aTypedValue.size());
+    std::vector< Item >::iterator iter;
+    for(iter = aTypedValue.begin(); iter != aTypedValue.end(); iter++) {
+      typedValue.push_back((*iter).theItem);
+    }
+    return Item( theItemFactory->createAttributeNode (aParent.theItem, aNodeName.theItem, aTypeName.theItem, typedValue ));
+  }
+  
+  Item 	ItemFactory::createBase64Binary (const char *aBinData, size_t aLength){
+    return Item( theItemFactory->createBase64Binary(aBinData, aLength));
+  }
+  Item 	ItemFactory::createBase64Binary (std::istream &aStream){
+    return Item( theItemFactory->createBase64Binary(aStream));
+  }
+  Item 	ItemFactory::createBase64Binary (const unsigned char *aBinData, size_t aLength){
+    return Item( theItemFactory->createBase64Binary(aBinData, aLength));
+  }
+  Item 	ItemFactory::createBoolean (bool aValue){
+    return Item( theItemFactory->createBoolean(aValue));
+  }
+  Item 	ItemFactory::createByte (char aByte){
+    return Item( theItemFactory->createByte(aByte));
+  }
+  Item 	ItemFactory::createDate (const std::string &aDate){
+    return Item( theItemFactory->createDate(aDate));
+  }
+  Item 	ItemFactory::createDate (short aYear, short aMonth, short aDay){
+    return Item( theItemFactory->createDate (aYear, aMonth, aDay));
+  }
+  Item 	ItemFactory::createDateTime (const std::string &aDateTimeValue){
+    return Item( theItemFactory->createDateTime (aDateTimeValue));
+  }
+  Item 	ItemFactory::createDateTime (short aYear, short aMonth, short aDay, short aHour, short aMinute, double aSecond, short aTimeZone_hours){
+    return Item( theItemFactory->createDateTime (aYear, aMonth, aDay, aHour, aMinute, aSecond, aTimeZone_hours));
+  }
+  Item 	ItemFactory::createDecimal (const std::string &aValue){
+    return Item( theItemFactory->createDecimal (aValue));
+  }
+  Item 	ItemFactory::createDecimalFromDouble (double aValue){
+    return Item( theItemFactory->createDecimalFromDouble (aValue));
+  }
+  Item 	ItemFactory::createDecimalFromLong (unsigned long aValue){
+    return Item( theItemFactory->createDecimalFromLong (aValue));
+  }
+  Item 	ItemFactory::createDouble (const std::string &aValue){
+    return Item( theItemFactory->createDouble (aValue));
+  }
+  Item 	ItemFactory::createDouble (double aValue){
+    return Item( theItemFactory->createDouble (aValue));
+  }
+  Item 	ItemFactory::createDuration (const std::string &aValue){
+    return Item( theItemFactory->createDuration (aValue));
+  }
+  Item 	ItemFactory::createDuration (short aYear, short aMonths, short aDays, short aHours, short aMinutes, double aSeconds){
+    return Item( theItemFactory->createDuration (aYear, aMonths, aDays, aHours, aMinutes, aSeconds));
+  }
+  /*
+  Item 	ItemFactory::createElementNode (Item &aParent, Item aNodeName, Item aTypeName, bool aHasTypedValue, bool aHasEmptyValue, std::vector< std::pair< std::string, std::string > > aNsBindings){
+    return Item( theItemFactory->createElementNode (aParent.theItem, aNodeName.theItem, aTypeName.theItem, aHasTypedValue, aHasEmptyValue, aNsBindings));
+  }
+  */
+  Item 	ItemFactory::createFloat (const std::string &aValue){
+    return Item( theItemFactory->createFloat (aValue));
+  }
+  Item 	ItemFactory::createFloat (float aValue){
+    return Item( theItemFactory->createFloat (aValue));
+  }
+  Item 	ItemFactory::createGDay (const std::string &aValue){
+    return Item( theItemFactory->createGDay (aValue));
+  }
+  Item 	ItemFactory::createGDay (short aDay){
+    return Item( theItemFactory->createGDay (aDay));
+  }
+  Item 	ItemFactory::createGMonth (const std::string &aValue){
+    return Item( theItemFactory->createGMonth (aValue));
+  }
+  Item 	ItemFactory::createGMonth (short aMonth){
+    return Item( theItemFactory->createGMonth (aMonth));
+  }
+  Item 	ItemFactory::createGMonthDay (const std::string &aValue){
+    return Item( theItemFactory->createGMonthDay (aValue));
+  }
+  Item 	ItemFactory::createGMonthDay (short aMonth, short aDay){
+    return Item( theItemFactory->createGMonthDay (aMonth, aDay));
+  }
+  Item 	ItemFactory::createGYear (short aYear){
+    return Item( theItemFactory->createGYear (aYear));
+  }
+  Item 	ItemFactory::createGYear (const std::string &aValue){
+    return Item( theItemFactory->createGYear (aValue));
+  }
+  Item 	ItemFactory::createGYearMonth (const std::string &aValue){
+    return Item( theItemFactory->createGYearMonth (aValue));
+  }
+  Item 	ItemFactory::createGYearMonth (short aYear, short aMonth){
+    return Item( theItemFactory->createGYearMonth (aYear, aMonth));
+  }
+  Item 	ItemFactory::createHexBinary (const char *aHexData, size_t aSize){
+    return Item( theItemFactory->createHexBinary (aHexData, aSize));
+  }
+  Item 	ItemFactory::createInt (int aInt){
+    return Item( theItemFactory->createInt (aInt));
+  }
+  Item 	ItemFactory::createInteger (const std::string &aInteger){
+    return Item( theItemFactory->createInteger (aInteger));
+  }
+  Item 	ItemFactory::createInteger (long long aInteger){
+    return Item( theItemFactory->createInteger (aInteger));
+  }
+  Item 	ItemFactory::createLong (long long aLong){
+    return Item( theItemFactory->createLong (aLong));
+  }
+  Item 	ItemFactory::createNCName (const std::string &aValue){
+    return Item( theItemFactory->createNCName (aValue));
+  }
+  Item 	ItemFactory::createNegativeInteger (long long aValue){
+    return Item( theItemFactory->createNegativeInteger (aValue));
+  }
+  Item 	ItemFactory::createNonNegativeInteger (unsigned long long aValue){
+    return Item( theItemFactory->createNonNegativeInteger (aValue));
+  }
+  Item 	ItemFactory::createNonPositiveInteger (long long aValue){
+    return Item( theItemFactory->createNonPositiveInteger (aValue));
+  }
+  Item 	ItemFactory::createPositiveInteger (unsigned long long aValue){
+    return Item( theItemFactory->createPositiveInteger (aValue));
+  }
+  Item 	ItemFactory::createQName (const std::string &aNamespace, const std::string &aPrefix, const std::string &aLocalname){
+    return Item( theItemFactory->createQName (aNamespace, aPrefix, aLocalname));
+  }
+  Item 	ItemFactory::createQName (const std::string &aNamespace, const std::string &aLocalname){
+    return Item( theItemFactory->createQName (aNamespace, aLocalname));
+  }
+  Item 	ItemFactory::createQName (const std::string &aQNameString){
+    return Item( theItemFactory->createQName (aQNameString));
+  }
+  Item 	ItemFactory::createShort (short aShort){
+    return Item( theItemFactory->createShort (aShort));
+  }
+  /*
+  Item 	ItemFactory::createStreamableString (std::istream &stream, StreamReleaser streamReleaser, bool seekable=false){
+    return Item( theItemFactory->createStreamableString (std::istream &stream, StreamReleaser streamReleaser, seekable));
+  }
+  */
+  Item 	ItemFactory::createString (const std::string &aString){
+    return Item( theItemFactory->createString (aString));
+  }
+  Item 	ItemFactory::createTextNode (Item parent, std::string content){
+    return Item( theItemFactory->createTextNode (parent.theItem, content));
+  }
+  Item 	ItemFactory::createTime (short aHour, short aMinute, double aSecond, short aTimeZone_hours){
+    return Item( theItemFactory->createTime (aHour, aMinute, aSecond, aTimeZone_hours));
+  }
+  Item 	ItemFactory::createTime (short aHour, short aMinute, double aSecond){
+    return Item( theItemFactory->createTime (aHour, aMinute, aSecond));
+  }
+  Item 	ItemFactory::createTime (const std::string &aValue){
+    return Item( theItemFactory->createTime (aValue));
+  }
+  Item 	ItemFactory::createUnsignedByte (const unsigned char aValue){
+    return Item( theItemFactory->createUnsignedByte (aValue));
+  }
+  Item 	ItemFactory::createUnsignedInt (unsigned int aValue){
+    return Item( theItemFactory->createUnsignedInt (aValue));
+  }
+  Item 	ItemFactory::createUnsignedLong (unsigned long long aValue){
+    return Item( theItemFactory->createUnsignedLong (aValue));
+  }
+  Item 	ItemFactory::createUnsignedShort (unsigned short aValue){
+    return Item( theItemFactory->createUnsignedShort (aValue));
+  }
+
+
+%}  // end Implementation
+
+%include "ItemFactory.h"
\ No newline at end of file

=== added file 'swig/StaticContext.h'
--- swig/StaticContext.h	1970-01-01 00:00:00 +0000
+++ swig/StaticContext.h	2011-10-31 17:53:26 +0000
@@ -0,0 +1,69 @@
+#include <zorba/static_context_consts.h>
+
+class StaticContext 
+{
+friend class Zorba;
+friend class XQuery;
+
+private:
+  zorba::StaticContext_t theStaticContext;
+public:
+  StaticContext();
+  StaticContext(const StaticContext& aStaticContext);
+  StaticContext(zorba::StaticContext_t aStaticContext);
+  
+  virtual void addColation(const std::string& aURI); 
+  virtual bool addNamespace(const std::string& aPrefix,
+                            const std::string& aURI);
+  void addReference() const;
+  virtual bool containsFunction(const std::string &aFnNameUri, 
+                                const std::string &aFnNameLocal, 
+                                int arity) const;
+
+  virtual StaticContext createChildContext() const;
+  virtual void declareOption(const Item &aQName, 
+                             const std::string &aOptionVal);
+  virtual void disableFunction(const Item &aQName, int arity);
+
+  virtual void free ();
+  virtual std::string getBaseURI () const;
+  virtual zorba::boundary_space_mode_t getBoundarySpacePolicy () const;
+
+  virtual zorba::construction_mode_t getConstructionMode () const;
+  virtual void getCopyNamespacesMode (zorba::preserve_mode_t &aPreserve, zorba::inherit_mode_t &aInherit) const;
+  virtual std::string getDefaultCollation () const;
+  virtual std::string getDefaultElementAndTypeNamespace () const;
+  virtual std::string getDefaultFunctionNamespace () const;
+  virtual zorba::order_empty_mode_t getDefaultOrderForEmptySequences () const;
+
+  virtual std::string getNamespaceURIByPrefix(const std::string &aPrefix) const;
+  virtual bool getOption(const Item &aQName, std::string &aOptionValue) const;
+  virtual zorba::ordering_mode_t getOrderingMode() const;
+  long getRefCount() const;
+  virtual zorba::validation_mode_t getRevalidationMode();
+  virtual zorba::xpath1_0compatib_mode_t getXPath1_0CompatibMode () const;
+  virtual void loadProlog (const std::string & aProlog, 
+                           const CompilerHints &hints);
+
+  void removeReference ();
+  virtual void resetTraceStream ();
+  virtual bool setBaseURI (const std::string &aBaseURI);
+  virtual bool setBoundarySpacePolicy (zorba::boundary_space_mode_t aMode);
+
+  virtual bool setConstructionMode (zorba::construction_mode_t aMode);
+
+  virtual bool setCopyNamespacesMode (zorba::preserve_mode_t aPreserve, 
+                                      zorba::inherit_mode_t aInherit);
+  virtual void setDefaultCollation (const std::string &aURI);
+  virtual bool setDefaultElementAndTypeNamespace (const std::string &aURI);
+  virtual bool setDefaultFunctionNamespace (const std::string &aURI);
+  virtual bool setDefaultOrderForEmptySequences (zorba::order_empty_mode_t aMode);
+
+  virtual bool setOrderingMode (zorba::ordering_mode_t aMode);
+  virtual void setRevalidationMode (zorba::validation_mode_t aMode);
+
+  virtual bool setXPath1_0CompatibMode (zorba::xpath1_0compatib_mode_t aMode);
+
+  void destroy();
+}; // class StaticContext
+

=== modified file 'swig/StaticContext.i'
--- swig/StaticContext.i	2011-06-29 20:05:38 +0000
+++ swig/StaticContext.i	2011-10-31 17:53:26 +0000
@@ -20,149 +20,144 @@
 #include <zorba/static_context_consts.h>
 
 
-class StaticContext 
-{
-  friend class Zorba;
+StaticContext::StaticContext() {}
 
-private:
-  zorba::StaticContext_t theStaticContext;
-public:
-  StaticContext() {}
-  StaticContext(const StaticContext& aStaticContext) : 
+StaticContext::StaticContext(const StaticContext& aStaticContext) : 
     theStaticContext(aStaticContext.theStaticContext) {}
-  StaticContext(zorba::StaticContext_t aStaticContext) : 
+    
+StaticContext::StaticContext(zorba::StaticContext_t aStaticContext) : 
     theStaticContext(aStaticContext) {}
 
-  virtual void addColation(const std::string& aURI)
+void StaticContext::addColation(const std::string& aURI)
   { theStaticContext->addCollation(aURI); }
 
-  virtual bool addNamespace(const std::string& aPrefix, 
+bool StaticContext::addNamespace(const std::string& aPrefix, 
                             const std::string& aURI)
   { return theStaticContext->addNamespace(aPrefix, aURI); }
 
-  void addReference() const
+void StaticContext::addReference() const
   { theStaticContext->addReference(); }
   
-  virtual bool containsFunction(const std::string &aFnNameUri, 
+bool StaticContext::containsFunction(const std::string &aFnNameUri, 
                                 const std::string &aFnNameLocal, 
                                 int arity) const 
   { return theStaticContext->containsFunction(aFnNameUri, aFnNameLocal,
                                               arity); }
 
-  virtual StaticContext	createChildContext() const
+StaticContext	StaticContext::createChildContext() const
   { return StaticContext(theStaticContext->createChildContext()); }
   
-  virtual void 	declareOption (const Item &aQName, 
+void 	StaticContext::declareOption (const Item &aQName, 
                                const std::string &aOptionVal)
   { return theStaticContext->declareOption(aQName.theItem, aOptionVal); }
 
-  virtual void 	disableFunction (const Item &aQName, int arity)
+void 	StaticContext::disableFunction (const Item &aQName, int arity)
   { theStaticContext->disableFunction( aQName.theItem, arity); }
 
-  virtual void 	free ()
+void 	StaticContext::free ()
   { theStaticContext->free(); }
 
-  virtual std::string getBaseURI () const
+std::string StaticContext::getBaseURI () const
   { return std::string(theStaticContext->getBaseURI().c_str()); }
 
-  virtual zorba::boundary_space_mode_t getBoundarySpacePolicy() const
+zorba::boundary_space_mode_t StaticContext::getBoundarySpacePolicy() const
   { return theStaticContext->getBoundarySpacePolicy(); }
 
-  virtual zorba::construction_mode_t getConstructionMode () const 
+zorba::construction_mode_t StaticContext::getConstructionMode () const 
   { return theStaticContext->getConstructionMode(); }		
 
-  virtual void 	getCopyNamespacesMode (zorba::preserve_mode_t &aPreserve, zorba::inherit_mode_t &aInherit) const
+void 	StaticContext::getCopyNamespacesMode (zorba::preserve_mode_t &aPreserve, zorba::inherit_mode_t &aInherit) const
   { return theStaticContext->getCopyNamespacesMode(aPreserve, aInherit); }		
 
-  virtual std::string getDefaultCollation () const 
+std::string StaticContext::getDefaultCollation () const 
   { return std::string(theStaticContext->getDefaultCollation().c_str()); }
 
-  virtual std::string getDefaultElementAndTypeNamespace () const 
+std::string StaticContext::getDefaultElementAndTypeNamespace () const 
   { 
     return std::string(theStaticContext->getDefaultElementAndTypeNamespace().
                        c_str()); 
   }
 
-  virtual std::string getDefaultFunctionNamespace () const 
+std::string StaticContext::getDefaultFunctionNamespace () const 
   { 
     return std::string(theStaticContext->getDefaultFunctionNamespace().c_str());
   }
 
-  virtual zorba::order_empty_mode_t getDefaultOrderForEmptySequences() const
+zorba::order_empty_mode_t StaticContext::getDefaultOrderForEmptySequences() const
   { return theStaticContext->getDefaultOrderForEmptySequences(); }
 
-  virtual std::string getNamespaceURIByPrefix(const std::string &aPrefix) const
+std::string StaticContext::getNamespaceURIByPrefix(const std::string &aPrefix) const
   {
     return std::string(theStaticContext->getNamespaceURIByPrefix(aPrefix).
                        c_str());
   }
 
-  virtual bool getOption(const Item &aQName, std::string &aOptionValue) const
+bool StaticContext::getOption(const Item &aQName, std::string &aOptionValue) const
   { 
     zorba::String optVal = zorba::String(aOptionValue.c_str());
     return theStaticContext->getOption(aQName.theItem, optVal); 
   }
 
-  virtual zorba::ordering_mode_t getOrderingMode () const
+zorba::ordering_mode_t StaticContext::getOrderingMode () const
   { return theStaticContext->getOrderingMode(); }
 
-  long getRefCount () const
+long StaticContext::getRefCount () const
   { return theStaticContext->getRefCount(); }
 
-  virtual zorba::validation_mode_t getRevalidationMode ()
+zorba::validation_mode_t StaticContext::getRevalidationMode ()
   { return theStaticContext->getRevalidationMode(); }
 
-  virtual zorba::xpath1_0compatib_mode_t getXPath1_0CompatibMode () const
+zorba::xpath1_0compatib_mode_t StaticContext::getXPath1_0CompatibMode () const
   { return theStaticContext->getXPath1_0CompatibMode(); } 
 
-  virtual void loadProlog (const std::string & aProlog, 
+void StaticContext::loadProlog (const std::string & aProlog, 
                            const CompilerHints &hints)
   { theStaticContext->loadProlog( aProlog, hints.theCompilerHints); }
 
-  void removeReference ()
+void StaticContext::removeReference ()
   { theStaticContext->removeReference(); }
 
-  virtual void resetTraceStream ()
+void StaticContext::resetTraceStream ()
   { theStaticContext->resetTraceStream(); }
 
-  virtual bool setBaseURI (const std::string &aBaseURI)
+bool StaticContext::setBaseURI (const std::string &aBaseURI)
   { return theStaticContext->setBaseURI(aBaseURI); }
 
-  virtual bool setBoundarySpacePolicy (zorba::boundary_space_mode_t aMode)
+bool StaticContext::setBoundarySpacePolicy (zorba::boundary_space_mode_t aMode)
   { return theStaticContext->setBoundarySpacePolicy(aMode); } 
 
-  virtual bool setConstructionMode (zorba::construction_mode_t aMode)
+bool StaticContext::setConstructionMode (zorba::construction_mode_t aMode)
   { return theStaticContext->setConstructionMode(aMode); } 
 
-  virtual bool setCopyNamespacesMode (zorba::preserve_mode_t aPreserve, 
+bool StaticContext::setCopyNamespacesMode (zorba::preserve_mode_t aPreserve, 
     zorba::inherit_mode_t aInherit)
   { return theStaticContext->setCopyNamespacesMode(aPreserve, aInherit); }   
 
-  virtual void setDefaultCollation (const std::string &aURI)
+void StaticContext::setDefaultCollation (const std::string &aURI)
   { theStaticContext->setDefaultCollation(aURI); }
 
-  virtual bool setDefaultElementAndTypeNamespace (const std::string &aURI)
+bool StaticContext::setDefaultElementAndTypeNamespace (const std::string &aURI)
   { return theStaticContext->setDefaultElementAndTypeNamespace(aURI); }
 
-  virtual bool setDefaultFunctionNamespace (const std::string &aURI)
+bool StaticContext::setDefaultFunctionNamespace (const std::string &aURI)
   { return theStaticContext->setDefaultFunctionNamespace(aURI); }
 
-  virtual bool setDefaultOrderForEmptySequences (zorba::order_empty_mode_t aMode)
+bool StaticContext::setDefaultOrderForEmptySequences (zorba::order_empty_mode_t aMode)
   { return theStaticContext->setDefaultOrderForEmptySequences(aMode); } 
 
-  virtual bool setOrderingMode (zorba::ordering_mode_t aMode)
+bool StaticContext::setOrderingMode (zorba::ordering_mode_t aMode)
   { return theStaticContext->setOrderingMode(aMode); } 
 
-  virtual void setRevalidationMode (zorba::validation_mode_t aMode)
+void StaticContext::setRevalidationMode (zorba::validation_mode_t aMode)
   { return theStaticContext->setRevalidationMode(aMode); } 
 
-  virtual bool setXPath1_0CompatibMode (zorba::xpath1_0compatib_mode_t aMode)
+bool StaticContext::setXPath1_0CompatibMode (zorba::xpath1_0compatib_mode_t aMode)
   { return theStaticContext->setXPath1_0CompatibMode(aMode); }
 
-  void destroy() 
+void StaticContext::destroy() 
   { theStaticContext = 0; }
    
-}; // class StaticContext
+ // class StaticContext
 
 
 
@@ -209,63 +204,4 @@
 %rename(VALIDATE_LAX) validate_lax;
 %rename(VALIDATE_STRICT) validate_strict;
 
-#include <zorba/static_context_consts.h>
-
-
-class StaticContext 
-{
- public:
-  virtual void addColation(const std::string& aURI);  
-  virtual bool addNamespace(const std::string& aPrefix, 
-                            const std::string& aURI);
-  void addReference() const;
-  virtual bool containsFunction(const std::string &aFnNameUri, 
-                                const std::string &aFnNameLocal, 
-                                int arity) const;
-
-  virtual StaticContext createChildContext() const;
-  virtual void declareOption(const Item &aQName, 
-                             const std::string &aOptionVal);
-  virtual void disableFunction(const Item &aQName, int arity);
-
-  virtual void free ();
-  virtual std::string getBaseURI () const;
-  virtual zorba::boundary_space_mode_t getBoundarySpacePolicy () const;
-
-  virtual zorba::construction_mode_t getConstructionMode () const;
-  virtual void getCopyNamespacesMode (zorba::preserve_mode_t &aPreserve, zorba::inherit_mode_t &aInherit) const;
-  virtual std::string getDefaultCollation () const;
-  virtual std::string getDefaultElementAndTypeNamespace () const;
-  virtual std::string getDefaultFunctionNamespace () const;
-  virtual zorba::order_empty_mode_t getDefaultOrderForEmptySequences () const;
-
-  virtual std::string getNamespaceURIByPrefix(const std::string &aPrefix) const;
-  virtual bool getOption(const Item &aQName, std::string &aOptionValue) const;
-  virtual zorba::ordering_mode_t getOrderingMode() const;
-  long getRefCount() const;
-  virtual zorba::validation_mode_t getRevalidationMode();
-  virtual zorba::xpath1_0compatib_mode_t getXPath1_0CompatibMode () const;
-  virtual void loadProlog (const std::string &, 
-                           const Zorba_CompilerHints_t &hints);
-
-  void removeReference ();
-  virtual void resetTraceStream ();
-  virtual bool setBaseURI (const std::string &aBaseURI);
-  virtual bool setBoundarySpacePolicy (zorba::boundary_space_mode_t aMode);
-
-  virtual bool setConstructionMode (zorba::construction_mode_t aMode);
-
-  virtual bool setCopyNamespacesMode (zorba::preserve_mode_t aPreserve, 
-                                      zorba::inherit_mode_t aInherit);
-  virtual void setDefaultCollation (const std::string &aURI);
-  virtual bool setDefaultElementAndTypeNamespace (const std::string &aURI);
-  virtual bool setDefaultFunctionNamespace (const std::string &aURI);
-  virtual bool setDefaultOrderForEmptySequences (zorba::order_empty_mode_t aMode);
-
-  virtual bool setOrderingMode (zorba::ordering_mode_t aMode);
-  virtual void setRevalidationMode (zorba::validation_mode_t aMode);
-
-  virtual bool setXPath1_0CompatibMode (zorba::xpath1_0compatib_mode_t aMode);
-
-  void destroy();
-}; // class StaticContext
+%include "StaticContext.h"

=== modified file 'swig/XQuery.i'
--- swig/XQuery.i	2011-07-20 01:40:52 +0000
+++ swig/XQuery.i	2011-10-31 17:53:26 +0000
@@ -74,6 +74,7 @@
   friend class DocumentManager; 
   friend class SingletonIterator;
   friend class DynamicContext;
+  friend class ItemFactory;
 
 private:
   zorba::Item theItem;
@@ -209,6 +210,17 @@
     return lStream.str();
   }
 
+  void compile (const std::string &aQuery)
+  {
+    theQuery->compile(aQuery);
+  }
+
+  void compile (const std::string &aQuery, StaticContext &aStaticContext )
+  {
+    Zorba_CompilerHints_t hints;
+    theQuery->compile(aQuery, aStaticContext.theStaticContext, hints);
+  }
+
   std::string printPlanAsXML()
   {
     std::ostringstream lStream;
@@ -322,6 +334,8 @@
   std::string execute();
   std::string printPlanAsXML();
   std::string printPlanAsDOT();
+  void compile (const std::string &aQuery);
+  void compile (const std::string &aQuery, StaticContext &aStaticContext);
 
 #ifdef SWIGPYTHON
   void executeSAX(SAX2ContentHandlerProxy* contentHandlerProxy);

=== modified file 'swig/Zorba.i'
--- swig/Zorba.i	2011-07-13 21:24:04 +0000
+++ swig/Zorba.i	2011-10-31 17:53:26 +0000
@@ -16,6 +16,11 @@
     return Zorba(zorba::Zorba::getInstance(aStore.getStore()));
   }
   
+  ItemFactory getItemFactory()
+  {
+    return ItemFactory(theZorba->getItemFactory());
+  }
+
   StaticContext createStaticContext()
   {
     return StaticContext(theZorba->createStaticContext());
@@ -25,7 +30,25 @@
   {
     return XQuery(theZorba->compileQuery(aStr));
   }
-/*
+
+  XQuery createQuery() 
+  {
+    return XQuery(theZorba->createQuery());
+  }
+
+  XQuery compileQuery(
+    const std::string& aStr,
+    StaticContext &aStaticContext )
+  { 
+    return XQuery(
+      theZorba->compileQuery(
+        aStr,
+        aStaticContext.theStaticContext
+      )
+    );
+  }
+
+  /*
   //--->> DiagnosticHandler implementations are postponed
   XQuery compileQuery(
     const std::string& aStr,
@@ -85,7 +108,11 @@
  public:
   static Zorba getInstance(const Store&);
   StaticContext createStaticContext();
+  XQuery createQuery();
   XQuery compileQuery(const std::string& aStr);
+  XQuery compileQuery(const std::string& aStr, StaticContext &aStaticContext );
+  ItemFactory getItemFactory();
+  
   /*
   XQuery compileQuery(const std::string& aStr, DiagnosticHandler* aDiagnosticHandler);
   XQuery compileQuery(const std::string& aStr, StaticContext &aStaticContext, 

=== modified file 'swig/java/CMakeLists.txt'
--- swig/java/CMakeLists.txt	2011-09-02 19:58:59 +0000
+++ swig/java/CMakeLists.txt	2011-10-31 17:53:26 +0000
@@ -60,6 +60,8 @@
   MESSAGE(STATUS "Java module install path: " ${JAVA_SITEARCH_DIR})
 
   FILE(GLOB JAVA_SWIG_FILES "${CMAKE_CURRENT_BINARY_DIR}/*.java")
+  CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/../StaticContext.h" "${CMAKE_CURRENT_BINARY_DIR}/StaticContext.h")
+  CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/../ItemFactory.h" "${CMAKE_CURRENT_BINARY_DIR}/ItemFactory.h")
 
   IF ( APPLE )
     INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${ZORBA_SWIG_LIB_PREFIX}libzorba_api.jnilib DESTINATION ${JAVA_SITEARCH_DIR})

=== modified file 'swig/php/CMakeLists.txt'
--- swig/php/CMakeLists.txt	2011-09-02 19:58:59 +0000
+++ swig/php/CMakeLists.txt	2011-10-31 17:53:26 +0000
@@ -38,6 +38,9 @@
     SWIG_LINK_LIBRARIES (zorba_api ${PHP5_LIBRARY})
   ENDIF (WIN32)
 
+  CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/../StaticContext.h" "${CMAKE_CURRENT_BINARY_DIR}/StaticContext.h")
+  CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/../ItemFactory.h" "${CMAKE_CURRENT_BINARY_DIR}/ItemFactory.h")
+
   # The following fix was added because of the changes in CMake 2.8, which have the
   # result of naming the java binding library "liblibzorba_api.so" instead of "libzorba_api.so"
   SET_TARGET_PROPERTIES( ${SWIG_MODULE_zorba_api_REAL_NAME} PROPERTIES PROJECT_LABEL "Api_PHP" )

=== modified file 'swig/php/zorba_api.i'
--- swig/php/zorba_api.i	2011-07-12 00:51:50 +0000
+++ swig/php/zorba_api.i	2011-10-31 17:53:26 +0000
@@ -28,6 +28,12 @@
   #define PHP_COMPILER_ID "VC6"
 #endif
 #endif
+
+#if defined(_MSC_VER)
+#define strtoll _strtoi64
+#define strtoull _strtoui64
+#endif
+
 %}
 
 

=== modified file 'swig/python/CMakeLists.txt'
--- swig/python/CMakeLists.txt	2011-09-02 19:58:59 +0000
+++ swig/python/CMakeLists.txt	2011-10-31 17:53:26 +0000
@@ -29,6 +29,8 @@
   )
    
   SET (PYTHON_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}/share/python")
+  CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/../StaticContext.h" "${CMAKE_CURRENT_BINARY_DIR}/StaticContext.h")
+  CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/../ItemFactory.h" "${CMAKE_CURRENT_BINARY_DIR}/ItemFactory.h")
   MESSAGE (STATUS "SWIG Python: Python module install path: " ${PYTHON_INSTALL_PATH})
 
   IF (NOT WIN32)   

=== modified file 'swig/ruby/CMakeLists.txt'
--- swig/ruby/CMakeLists.txt	2011-09-02 19:58:59 +0000
+++ swig/ruby/CMakeLists.txt	2011-10-31 17:53:26 +0000
@@ -28,6 +28,13 @@
   ELSE (WIN32)
     SWIG_ADD_MODULE(zorba_api ruby zorba_api.i)
     SWIG_LINK_LIBRARIES(zorba_api zorba_simplestore ${RUBY_LIBRARY})
+    # Necessary because UseSWIG.cmake uses ADD_LIBRARY(..MODULE..), which
+    # apparently doesn't allow CMake's RPATH-rewriting magic to work.
+    GET_TARGET_PROPERTY(_rpath zorba_simplestore LOCATION)
+    GET_FILENAME_COMPONENT(_rpath "${_rpath}" PATH)
+    SET_TARGET_PROPERTIES(zorba_api PROPERTIES
+      INSTALL_RPATH "${CMAKE_INSTALL_RPATH}:${_rpath}"
+      BUILD_WITH_INSTALL_RPATH ON)
   ENDIF (WIN32)
 
   IF ( APPLE )
@@ -43,6 +50,8 @@
   EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['sitearchdir']"
     OUTPUT_VARIABLE RUBY_SITEARCH_DIR)
   #STRING(REPLACE "/usr/" "" RUBY_SITEARCH_DIR "${RUBY_SITEARCH_DIR}" )
+  CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/../StaticContext.h" "${CMAKE_CURRENT_BINARY_DIR}/StaticContext.h")
+  CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/../ItemFactory.h" "${CMAKE_CURRENT_BINARY_DIR}/ItemFactory.h")
   
   SET (RUBY_SITEARCH_DIR "${CMAKE_INSTALL_PREFIX}/share/ruby")
   
@@ -67,6 +76,7 @@
       
     ENDIF ( LINUX )
   ENDIF ( APPLE )
+
 ELSE (RUBY_LIBRARY AND RUBY_INCLUDE_PATH)
   MESSAGE(STATUS "SWIG Ruby: binding not generated because library and include files are not installed.")
 ENDIF (RUBY_LIBRARY AND RUBY_INCLUDE_PATH)

=== modified file 'swig/zorba_api.i'
--- swig/zorba_api.i	2011-07-13 21:24:04 +0000
+++ swig/zorba_api.i	2011-10-31 17:53:26 +0000
@@ -52,7 +52,6 @@
   class Item;
   class Iterator;
   class XQuery;
-  class StaticContext;
   class Store;
   class Zorba;
 
@@ -65,6 +64,9 @@
   class UserException;
   class ZorbaException;
 
+  #include "StaticContext.h"
+  #include "ItemFactory.h"
+
 %}
 
 
@@ -77,5 +79,6 @@
 %include "CompilerHints.i"
 %include "StaticContext.i"
 %include "Zorba.i"
+%include "ItemFactory.i"
 
 

=== modified file 'test/rbkt/Queries/CMakeLists.txt'
--- test/rbkt/Queries/CMakeLists.txt	2011-10-10 10:31:20 +0000
+++ test/rbkt/Queries/CMakeLists.txt	2011-10-31 17:53:26 +0000
@@ -1,11 +1,11 @@
 # Copyright 2006-2008 The FLWOR Foundation.
-# 
+#
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
-# 
+#
 # http://www.apache.org/licenses/LICENSE-2.0
-# 
+#
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,10 +18,10 @@
 
 MESSAGE(STATUS "Adding tests for CTest")
 
-FILE(GLOB_RECURSE TESTFILES FOLLOW_SYMLINKS 
+FILE(GLOB_RECURSE TESTFILES FOLLOW_SYMLINKS
   RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.xq")
 IF(ZORBA_TEST_XQUERYX)
-  FILE(GLOB_RECURSE TESTFILES_XQX FOLLOW_SYMLINKS 
+  FILE(GLOB_RECURSE TESTFILES_XQX FOLLOW_SYMLINKS
     RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS "*.xqx")
   IF (TESTFILES_XQX)
     LIST(APPEND TESTFILES ${TESTFILES_XQX})
@@ -94,7 +94,7 @@
     LIST(SORT CHAINED_TESTS_FILES)
 
     SET(TEST_NAME "test/rbkt/${TEST_NAME}")
-    
+
     # finally add the test
     ZORBA_ADD_TEST("${TEST_NAME}" testdriver ${CHAINED_TESTS_FILES})
 
@@ -143,7 +143,7 @@
       SET(SKIP_TEST 1)
     ENDIF(HTTP_CLIENT)
   ENDIF(NOT CURL_FOUND)
-  
+
   IF(NOT ZORBA_WITH_FILE_ACCESS)
     #these tests require the file module
     STRING(REGEX MATCH "file/" NEEDS_FILE "${TESTNAME}")
@@ -211,6 +211,7 @@
 IF (FOUND_XQTS AND NOT ZORBA_TEST_W3C_TO_SUBMIT_RESULTS)
 
   EXPECTED_FAILURE(test/rbkt/w3c_testsuite/XQuery/PathExpr/Steps/Steps-leading-lone-slash-8a 3408285)
+  EXPECTED_FAILURE(test/rbkt/w3c_testsuite/XQuery/Functions/QNameFunc/NamespaceURIForPrefixFunc/K2-NamespaceURIForPrefixFunc-2 872732)
 
   IF(NOT ZORBA_WITH_BIG_INTEGER)
     # These tests fail due to integer overflow.

=== modified file 'test/rbkt/Queries/w3c_known_failures.txt'
--- test/rbkt/Queries/w3c_known_failures.txt	2011-09-12 23:22:24 +0000
+++ test/rbkt/Queries/w3c_known_failures.txt	2011-10-31 17:53:26 +0000
@@ -107,6 +107,7 @@
 test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/MapPairs/map-pairs-001
 test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/MapPairs/map-pairs-008
 test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/MapPairs/map-pairs-902
+test/rbkt/w3c_testsuite/XQuery/Functions/QNameFunc/NamespaceURIForPrefixFunc/K2-NamespaceURIForPrefixFunc-2
 test/rbkt/w3c_testsuite/XQuery/SchemaValidation/ValidateExpression/validateexpr-28
 test/rbkt/w3c_testsuite/XQuery/exprSeqTypes/PrologExpr/VariableProlog/ExternalVariablesWith/K2-ExternalVariablesWith-22
 test/rbkt/w3c_testsuite/XQuery/StaticTyping/STFLWORExpr/ST-PITest-02


Follow ups