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

Commit message:
fixed bugs related to casting to xs:QName and xs:token

Requested reviews:
  Markos Zaharioudakis (markos-za)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/162005

fixed bugs related to casting to xs:QName and xs:token
-- 
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/162005
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp	2013-04-30 22:57:18 +0000
+++ src/compiler/translator/translator.cpp	2013-05-02 00:32:32 +0000
@@ -9159,7 +9159,7 @@
 ********************************************************************************/
 expr* create_cast_expr(
     const QueryLoc& loc,
-    expr* node,
+    expr* inExpr,
     const xqtref_t& type,
     bool allowsEmpty,
     bool isCast)
@@ -9185,16 +9185,24 @@
 
   if (TypeOps::is_subtype(tm, *type, *theRTM.QNAME_TYPE_QUESTION, loc))
   {
-    if (node->get_expr_kind() == const_expr_kind)
+    if (inExpr->get_expr_kind() == const_expr_kind)
     {
-      const const_expr* ce = static_cast<const_expr*>(node);
+      const const_expr* ce = static_cast<const_expr*>(inExpr);
 
       if (ce->get_val()->getTypeCode() == store::XS_STRING)
       {
         store::Item_t result;
+        store::Item_t value = ce->get_val();
+        xqtref_t ptype = TypeOps::prime_type(tm, *type);
+
         try
         {
-          GenericCast::castToQName(result, ce->get_val(), theNSCtx, false, tm, loc);
+          GenericCast::castToAtomic(result,
+                                    value,
+                                    ptype.getp(),
+                                    tm,
+                                    theNSCtx,
+                                    loc);
         }
         catch (ZorbaException& e)
         {
@@ -9229,7 +9237,7 @@
       }
     }
 
-    xqtref_t inputType = node->get_return_type();
+    xqtref_t inputType = inExpr->get_return_type();
 
     if (theSctx->xquery_version() < StaticContextConsts::xquery_version_3_0)
     {
@@ -9239,21 +9247,21 @@
       {
         if (TypeOps::is_subtype(tm, *inputType, *theRTM.QNAME_TYPE_STAR, loc))
         {
-          return CREATE(cast)(theRootSctx, theUDF, loc, node, type, allowsEmpty);
+          return CREATE(cast)(theRootSctx, theUDF, loc, inExpr, type, allowsEmpty);
         }
         else
         {
-          return CREATE(treat)(theRootSctx, theUDF, loc, node, type, TREAT_TYPE_MATCH);
+          return CREATE(treat)(theRootSctx, theUDF, loc, inExpr, type, TREAT_TYPE_MATCH);
         }
       }
       else
       {
-        return CREATE(instanceof)(theRootSctx, theUDF, loc, node, type);
+        return CREATE(instanceof)(theRootSctx, theUDF, loc, inExpr, type);
       }
     }
 
-    expr* input = wrap_in_atomization(node);
-
+    expr* input = wrap_in_atomization(inExpr);
+    /*
     if (TypeOps::is_subtype(tm, *inputType, *theRTM.ANY_NODE_TYPE_PLUS, loc))
     {
       if (isCast)
@@ -9265,7 +9273,7 @@
         return CREATE(const)(theRootSctx, theUDF, loc, false);
       }
     }
-
+    */
     if (isCast)
       return CREATE(cast)(theRootSctx, theUDF, loc, input, type, allowsEmpty);
     else
@@ -9273,7 +9281,7 @@
   }
   else
   {
-    expr* input = wrap_in_atomization(node);
+    expr* input = wrap_in_atomization(inExpr);
 
     if (isCast)
       return CREATE(cast)(theRootSctx, theUDF, loc, input, type, allowsEmpty);

=== modified file 'src/runtime/booleans/BooleanImpl.cpp'
--- src/runtime/booleans/BooleanImpl.cpp	2013-04-04 01:37:05 +0000
+++ src/runtime/booleans/BooleanImpl.cpp	2013-05-02 00:32:32 +0000
@@ -636,23 +636,23 @@
     {
       GenericCast::castToBuiltinAtomic(castItem0, item0, store::XS_STRING, NULL, loc);
 
-      if (!GenericCast::promote(castItem1, item1, store::XS_STRING, tm, loc))
+      if (!GenericCast::promote(castItem1, item1, store::XS_STRING, NULL, tm, loc))
         castItem1.transfer(item1);
     }
   }
   else if (type1 == store::XS_UNTYPED_ATOMIC)
   {
-    if (!GenericCast::promote(castItem0, item0, store::XS_STRING, tm, loc))
+    if (!GenericCast::promote(castItem0, item0, store::XS_STRING, NULL, tm, loc))
       castItem0.transfer(item0);
 
     GenericCast::castToBuiltinAtomic(castItem1, item1, store::XS_STRING, NULL, loc);
   }
   else
   {
-    if (!GenericCast::promote(castItem0, item0, type1, tm, loc))
+    if (!GenericCast::promote(castItem0, item0, type1, NULL, tm, loc))
       castItem0.transfer(item0);
 
-    if (!GenericCast::promote(castItem1, item1, type0, tm, loc))
+    if (!GenericCast::promote(castItem1, item1, type0, NULL, tm, loc))
       castItem1.transfer(item1);
   }
 }
@@ -808,7 +808,7 @@
     {
       GenericCast::castToBuiltinAtomic(castItem0, item0, store::XS_DOUBLE, NULL, loc);
 
-      GenericCast::promote(castItem1, item1, store::XS_DOUBLE, tm, loc);
+      GenericCast::promote(castItem1, item1, store::XS_DOUBLE, NULL, tm, loc);
     }
     else if (type1 == store::XS_UNTYPED_ATOMIC)
     {
@@ -831,7 +831,7 @@
     if (TypeOps::is_numeric(type0))
     {
       GenericCast::castToBuiltinAtomic(castItem1, item1, store::XS_DOUBLE, NULL, loc);
-      GenericCast::promote(castItem0, item0, store::XS_DOUBLE, tm, loc);
+      GenericCast::promote(castItem0, item0, store::XS_DOUBLE, NULL, tm, loc);
     }
     else if (TypeOps::is_subtype(type0, store::XS_STRING))
     {
@@ -846,10 +846,10 @@
   }
   else
   {
-    if (!GenericCast::promote(castItem0, item0, type1, tm, loc))
+    if (!GenericCast::promote(castItem0, item0, type1, NULL, tm, loc))
       castItem0.transfer(item0);
 
-    if (!GenericCast::promote(castItem1, item1, type0, tm, loc))
+    if (!GenericCast::promote(castItem1, item1, type0, NULL, tm, loc))
       castItem1.transfer(item1);
   }
 }

=== modified file 'src/runtime/core/sequencetypes.cpp'
--- src/runtime/core/sequencetypes.cpp	2013-04-23 10:58:29 +0000
+++ src/runtime/core/sequencetypes.cpp	2013-05-02 00:32:32 +0000
@@ -377,7 +377,8 @@
   :
   UnaryBaseIterator<PromoteIterator, PlanIteratorState>(sctx, loc, child),
   theErrorKind(err),
-  theQName(qname)
+  theQName(qname),
+  theNsCtx(theSctx)
 {
   thePromoteType = TypeOps::prime_type(sctx->get_typemanager(), *promoteType);
   theQuantifier = promoteType->get_quantifier(); 
@@ -398,6 +399,8 @@
   SERIALIZE_ENUM(TypeConstants::quantifier_t, theQuantifier);
   SERIALIZE_ENUM(PromoteErrorKind, theErrorKind);
   ar & theQName;
+
+  theNsCtx.setStaticContext(theSctx);
 }
 
 
@@ -428,7 +431,7 @@
     }
 
     // catch exceptions to add/change the error location
-    if (! GenericCast::promote(result, item, thePromoteType, tm, loc))
+    if (! GenericCast::promote(result, item, thePromoteType, &theNsCtx, tm, loc))
     {
       zstring valueType = tm->create_value_type(item)->toSchemaString();
       raiseError(valueType);
@@ -440,7 +443,7 @@
   {
     do
     {
-      if (! GenericCast::promote(result, item, thePromoteType, tm, loc))
+      if (! GenericCast::promote(result, item, thePromoteType, &theNsCtx, tm, loc))
       {
         zstring valueType = tm->create_value_type(item)->toSchemaString();
         raiseError(valueType);

=== modified file 'src/runtime/core/sequencetypes.h'
--- src/runtime/core/sequencetypes.h	2013-02-07 17:24:36 +0000
+++ src/runtime/core/sequencetypes.h	2013-05-02 00:32:32 +0000
@@ -168,6 +168,7 @@
   TypeConstants::quantifier_t theQuantifier;
   PromoteErrorKind            theErrorKind;
   store::Item_t								theQName; 
+  namespace_context           theNsCtx;
 
 public:
   SERIALIZABLE_CLASS(PromoteIterator);

=== modified file 'src/runtime/sequences/SequencesImpl.cpp'
--- src/runtime/sequences/SequencesImpl.cpp	2013-02-07 17:24:36 +0000
+++ src/runtime/sequences/SequencesImpl.cpp	2013-05-02 00:32:32 +0000
@@ -21,7 +21,10 @@
 #include <sstream>
 
 #include "zorbautils/fatal.h"
+
 #include "diagnostics/xquery_diagnostics.h"
+#include "diagnostics/util_macros.h"
+
 #include "zorbatypes/URI.h"
 
 // For timing
@@ -175,20 +178,17 @@
       {
         // Type Promotion
         store::Item_t lItemCur;
-        if (!GenericCast::promote(lItemCur, lRunningItem, &*lMaxType, tm, loc))
+        if (!GenericCast::promote(lItemCur, lRunningItem, &*lMaxType, NULL, tm, loc))
         {
-          if (GenericCast::promote(lItemCur, result, &*lRunningType, tm, loc))
+          if (GenericCast::promote(lItemCur, result, &*lRunningType, NULL, tm, loc))
           {
             result.transfer(lItemCur);
             lMaxType = tm->create_value_type(result);
           }
           else
           {
-						throw XQUERY_EXCEPTION(
-							err::FORG0006,
-							ERROR_PARAMS( ZED( PromotionImpossible ) ),
-							ERROR_LOC( loc )
-						);
+						RAISE_ERROR(err::FORG0006, loc,
+						ERROR_PARAMS(ZED(PromotionImpossible)));
           }
         }
         else

=== modified file 'src/types/casting.cpp'
--- src/types/casting.cpp	2013-04-30 23:29:51 +0000
+++ src/types/casting.cpp	2013-05-02 00:32:32 +0000
@@ -907,6 +907,14 @@
 }
 
 
+T1_TO_T2(uA, QN)
+{
+  zstring strval2;
+  aItem->getStringValue2(strval2);
+  str_QN(result, aItem, strval2, aFactory, nsCtx, errInfo);
+}
+
+
 T1_TO_T2(flt, uA)
 {
   zstring strval2;
@@ -1715,11 +1723,43 @@
   }
   case store::XS_TOKEN:
   {
-    if (GenericCast::instance()->castableToToken(strval))
+    char ch;
+    zstring::size_type sz = strval.size();
+
+    ascii::trim_whitespace(strval);
+
+    bool spaceSeen = false;
+
+    for (zstring::size_type i = 0; i < sz; ++i)
     {
-      factory->createToken(result, strval);
-      return;
+      ch = strval[i];
+
+      if (ch == '\r' || ch == '\n' || ch == '\t')
+      {
+        strval[i] = ' ';
+        ch = ' ';
+      }
+
+      if (ch == ' ')
+      {
+        if (spaceSeen)
+        {
+          strval.erase(i, 1);
+          --i;
+          --sz;
+        }
+
+        spaceSeen = true;
+      }
+      else
+      {
+        spaceSeen = false;
+      }
     }
+
+    factory->createToken(result, strval);
+    return;
+
     break;
   }
   case store::XS_LANGUAGE:
@@ -2102,7 +2142,7 @@
 
 {&uA_uA,    &uA_str,   &uA_flt,  &uA_dbl ,   &uA_dec ,  &uA_int,   &uA_dur,  &uA_yMD,
  &uA_dTD,   &uA_dT,    &uA_tim,  &uA_dat,    &uA_gYM ,  &uA_gYr ,  &uA_gMD,  &uA_gDay,
- &uA_gMon,  &uA_bool,  &uA_b64,  &uA_hxB,    &uA_aURI,  0,         0,        &uA_uint,
+ &uA_gMon,  &uA_bool,  &uA_b64,  &uA_hxB,    &uA_aURI,  &uA_QN,    0,        &uA_uint,
  0,         &uA_dTSt}, // uA
 
 {&str_uA,   &str_str,  &str_flt,  &str_dbl,  &str_dec,  &str_int,  &str_dur, &str_yMD,
@@ -2716,8 +2756,6 @@
   {
     ch = str[i];
 
-    // do not contain the carriage return (#xD), line feed (#xA) nor tab (#x9)
-    // characters */
     if (ch == '\r' || ch == '\n' || ch == '\t')
     {
       return false;
@@ -3006,6 +3044,7 @@
     store::Item_t& result,
     store::Item_t& item,
     const XQType* targetType,
+    const namespace_context* nsCtx,
     const TypeManager* tm,
     const QueryLoc& loc)
 {
@@ -3019,6 +3058,7 @@
     return promote(result, 
                    item,
                    static_cast<const AtomicXQType*>(targetType)->get_type_code(),
+                   nsCtx,
                    tm,
                    loc);
   }
@@ -3038,7 +3078,7 @@
   if (TypeOps::is_equal(tm, *itemType, *rtm.UNTYPED_ATOMIC_TYPE_ONE) &&
       ! TypeOps::is_equal(tm, *TypeOps::prime_type(tm, *targetType), *rtm.QNAME_TYPE_ONE))
   {
-    return castToAtomic(result, item, targetType, tm, NULL, loc);
+    return castToAtomic(result, item, targetType, tm, nsCtx, loc);
   }
 
     // Decimal/Float --> xs:double
@@ -3087,6 +3127,7 @@
     store::Item_t& result,
     store::Item_t& item,
     store::SchemaTypeCode targetType,
+    const namespace_context* nsCtx,
     const TypeManager* tm,
     const QueryLoc& loc)
 {

=== modified file 'src/types/casting.h'
--- src/types/casting.h	2013-03-12 17:03:31 +0000
+++ src/types/casting.h	2013-05-02 00:32:32 +0000
@@ -74,6 +74,7 @@
         store::Item_t& result,
         store::Item_t& item,
         const XQType* targetType,
+        const namespace_context* nsCtx,
         const TypeManager* tm,
         const QueryLoc& loc);
 
@@ -81,6 +82,7 @@
         store::Item_t& result,
         store::Item_t& item,
         store::SchemaTypeCode targetType,
+        const namespace_context* nsCtx,
         const TypeManager* tm,
         const QueryLoc& loc);
 

=== modified file 'src/types/schema/schema.cpp'
--- src/types/schema/schema.cpp	2013-04-25 12:49:22 +0000
+++ src/types/schema/schema.cpp	2013-05-02 00:32:32 +0000
@@ -1746,9 +1746,8 @@
       }
 
       // workaround for validating xs:NOTATION with Xerces
-      if (theTypeManager != NULL
-          &&
-          udXQType->isSubTypeOf(theTypeManager, *GENV_TYPESYSTEM.NOTATION_TYPE_ONE))
+      if (theTypeManager != NULL &&
+          udXQType->isSubTypeOf(theTypeManager, *GENV_TYPESYSTEM.NOTATION_TYPE_STAR))
       {
         // textValue must be in the form of URI:LOCAL
         size_t colonIndex = textValue.find_first_of(":");

=== modified file 'test/fots/CMakeLists.txt'
--- test/fots/CMakeLists.txt	2013-05-01 22:25:33 +0000
+++ test/fots/CMakeLists.txt	2013-05-02 00:32:32 +0000
@@ -265,10 +265,9 @@
 EXPECTED_FOTS_FAILURE (prod-Annotation annotation-assertion-9 0)
 EXPECTED_FOTS_FAILURE (prod-Annotation annotation-assertion-10 0)
 EXPECTED_FOTS_FAILURE (prod-BaseURIDecl K2-BaseURIProlog-5 0)
-EXPECTED_FOTS_FAILURE (prod-CastExpr CastAs674a 0)
-EXPECTED_FOTS_FAILURE (prod-CastExpr K-SeqExprCast-71b 0)
+EXPECTED_FOTS_FAILURE (prod-CastExpr CastAsNamespaceSensitiveType-11 0)
+EXPECTED_FOTS_FAILURE (prod-CastExpr CastAsNamespaceSensitiveType-12 0)
 EXPECTED_FOTS_FAILURE (prod-CastExpr.derived cbcl-cast-ncname-001 0)
-EXPECTED_FOTS_FAILURE (prod-CastExpr.derived cbcl-cast-token-001 0)
 EXPECTED_FOTS_FAILURE (prod-CastExpr.schema CastAs-UnionType-17 0)
 EXPECTED_FOTS_FAILURE (prod-CastExpr.schema CastAs-UnionType-22 0)
 EXPECTED_FOTS_FAILURE (prod-CastExpr.schema CastAs-UnionType-23 0)
@@ -295,7 +294,6 @@
 EXPECTED_FOTS_FAILURE (prod-FunctionCall FunctionCall-005 0)
 EXPECTED_FOTS_FAILURE (prod-FunctionCall FunctionCall-007 0)
 EXPECTED_FOTS_FAILURE (prod-FunctionCall FunctionCall-008 0)
-EXPECTED_FOTS_FAILURE (prod-FunctionCall FunctionCall-015 0)
 EXPECTED_FOTS_FAILURE (prod-FunctionCall FunctionCall-031 0)
 EXPECTED_FOTS_FAILURE (prod-FunctionCall FunctionCall-033 0)
 EXPECTED_FOTS_FAILURE (prod-FunctionCall FunctionCall-037 0)
@@ -373,8 +371,6 @@
 EXPECTED_FOTS_FAILURE (xs-anyURI cbcl-anyURI-002 0)
 EXPECTED_FOTS_FAILURE (xs-anyURI cbcl-anyURI-006 0)
 EXPECTED_FOTS_FAILURE (xs-base64Binary base64-115 0)
-EXPECTED_FOTS_FAILURE (xs-token cbcl-token-002 0)
-EXPECTED_FOTS_FAILURE (xs-token cbcl-token-004 0)
 EXPECTED_FOTS_FAILURE (fn-fold-left fold-left-009 0)
 EXPECTED_FOTS_FAILURE (fn-function-lookup fn-function-lookup-062 0)
 EXPECTED_FOTS_FAILURE (fn-map-pairs fn-map-pairs-026 0)

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to