← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/markos-scratch into lp:zorba

 

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

Commit message:
make sure the promote iterator works only with atomic items and types

Requested reviews:
  Markos Zaharioudakis (markos-za)

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

make sure the promote iterator works only with atomic items and types
-- 
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/126921
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/compiler/expression/expr.cpp'
--- src/compiler/expression/expr.cpp	2012-09-19 18:18:02 +0000
+++ src/compiler/expression/expr.cpp	2012-09-28 10:55:34 +0000
@@ -421,6 +421,9 @@
   theErrorKind(err),
   theQName(qname)
 {
+  assert(TypeOps::is_subtype(sctx->get_typemanager(),
+                             *type,
+                             *GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_STAR));
 }
 
 

=== modified file 'src/compiler/expression/expr.h'
--- src/compiler/expression/expr.h	2012-09-19 18:18:02 +0000
+++ src/compiler/expression/expr.h	2012-09-28 10:55:34 +0000
@@ -202,8 +202,8 @@
   friend class expr;
 
 protected:
-  expr*   theInputExpr;
-  xqtref_t theTargetType;
+  expr     * theInputExpr;
+  xqtref_t   theTargetType;
 
 protected:
   cast_or_castable_base_expr(
@@ -333,17 +333,20 @@
   1. Let "input sequence" be the result of theInputExpr, and "output sequence"
      be the result of the promote_expr.
 
-  2. Raise error if the cardinality of the input sequence is not compatible with
+  2. The input sequence is assumed to be mepty or consist of atomic items only.
+
+  4. theTargetType is always a subtype of xs:anyAtomicType*
+
+  5. Raise error if the cardinality of the input sequence is not compatible with
      the quantifier of theTargetType.
 
-  3. For each item I in the input sequence, let F(I) be the result of the
+  6. For each item I in the input sequence, let F(I) be the result of the
      function defined as follows:
 
      - Let "actual type" be the dynamic type of I, and "target type" be the prime
        type of theTargetType.
-     - If the target type is the NONE type, F(I) = error, else
+     - If the target type is the NONE type, F(I) = raise error, else
      - If the actual type is a subtype of the target type, F(I) = I, else
-     - If the target type is not an atomic type, F(I) = error, else
      - If the actual type is untypedAtomic and the target type is not QName,
        F(I) = cast(I, target type), else
      - If the actual type is (subtype of) decimal and the target type is float,
@@ -352,7 +355,7 @@
        F(I) = cast(I, target type), else
      - If the actual type is anyURI and the target type is string,
        F(I) = cast(I, string), else
-     - F(I) = error
+     - F(I) = raise error
 
   4. Put F(I) in the output sequence.
 

=== modified file 'src/compiler/expression/expr_iter.cpp'
--- src/compiler/expression/expr_iter.cpp	2012-09-17 00:36:37 +0000
+++ src/compiler/expression/expr_iter.cpp	2012-09-28 10:55:34 +0000
@@ -46,7 +46,7 @@
 do                                                                  \
 {                                                                   \
   theState = __LINE__;                                              \
-  theCurrentChild = reinterpret_cast<expr**>(&(subExprHandle));    \
+  theCurrentChild = reinterpret_cast<expr**>(&(subExprHandle));     \
                                                                     \
   if ((subExprHandle) != NULL)                                      \
   {                                                                 \

=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp	2012-09-26 13:19:15 +0000
+++ src/compiler/translator/translator.cpp	2012-09-28 10:55:34 +0000
@@ -1450,7 +1450,6 @@
                               *theRTM.ANY_ATOMIC_TYPE_STAR,
                               loc))
       {
-        argExpr = wrap_in_atomization(argExpr);
         argExpr = wrap_in_type_promotion(argExpr,
                                          paramType,
                                          PromoteIterator::FUNC_PARAM,
@@ -1477,9 +1476,9 @@
 expr* wrap_in_atomization(expr* e)
 {
   return theExprManager->create_fo_expr(theRootSctx,
-                     e->get_loc(),
-                     GET_BUILTIN_FUNCTION(FN_DATA_1),
-                     e);
+                                        e->get_loc(),
+                                        GET_BUILTIN_FUNCTION(FN_DATA_1),
+                                        e);
 }
 
 
@@ -1492,6 +1491,8 @@
     PromoteIterator::ErrorKind errorKind,
     store::Item* qname = NULL)
 {
+  e = wrap_in_atomization(e);
+
   return theExprManager->create_promote_expr(theRootSctx,
                                              e->get_loc(),
                                              e,
@@ -3780,8 +3781,6 @@
 
     if (TypeOps::is_builtin_simple(CTX_TM, *returnType))
     {
-      body = wrap_in_atomization(body);
-
       body = wrap_in_type_promotion(body,
                                     returnType,
                                     PromoteIterator::FUNC_RETURN,
@@ -10874,10 +10873,9 @@
         flwor_expr* flworExpr = theExprManager->create_flwor_expr(theRootSctx, loc, false);
 
         // wrap function's QName
-        expr* qnameExpr = wrap_in_atomization(arguments[0]);
-        qnameExpr        = wrap_in_type_promotion(arguments[0],
-                                                  theRTM.QNAME_TYPE_ONE,
-                                                  PromoteIterator::TYPE_PROMOTION);
+        expr* qnameExpr = wrap_in_type_promotion(arguments[0],
+                                                 theRTM.QNAME_TYPE_ONE,
+                                                 PromoteIterator::TYPE_PROMOTION);
 
         for (csize i = 0; i < numArgs ; ++i)
         {
@@ -11325,7 +11323,6 @@
 
   if (TypeOps::is_builtin_simple(CTX_TM, *returnType))
   {
-    body = wrap_in_atomization(body);
     body = wrap_in_type_promotion(body, returnType, PromoteIterator::TYPE_PROMOTION);
   }
   else
@@ -11502,9 +11499,6 @@
   DirectObjectConstructor ::= "{" PairConstructor ("," PairConstructor )* "}"
 
   PairConstructor ::= ExprSingle ":" ExprSingle
-
-  The 1st ExprSingle must return exactly one string.
-  The 2nd ExprSingle must contain exactly one item of any kind.
 ********************************************************************************/
 void* begin_visit(const JSONDirectObjectConstructor& v)
 {
@@ -11559,8 +11553,10 @@
   The PairConstructor production can appear only on the RHS of a 
   DirectObjectConstructor or in the source list of a JSONObjectInsertExpr
 
-  The 1st ExprSingle must return exactly one string.
-  The 2nd ExprSingle must contain exactly one item of any kind.
+  The 1st ExprSingle must return exactly one item castable to string after
+  atomization. The 2nd ExprSingle may return any kind of sequence; if the 
+  sequence is empty, it is replaced by the null item; if the sequence contains
+  more than one item, it is boxed into an array.
 ********************************************************************************/
 void* begin_visit(const JSONPairConstructor& v)
 {
@@ -13377,8 +13373,6 @@
   expr* targetExpr = pop_nodestack();
   expr* sourceExpr = pop_nodestack();
 
-  posExpr = wrap_in_atomization(posExpr);
-
   posExpr = wrap_in_type_promotion(posExpr,
                                    rtm.INTEGER_TYPE_ONE,
                                    PromoteIterator::JSONIQ_ARRAY_SELECTOR); // JNUP0007
@@ -14010,9 +14004,10 @@
   TRACE_VISIT_OUT ();
 #ifndef ZORBA_NO_FULL_TEXT
   expr* e( pop_nodestack() );
-  push_nodestack( wrap_in_type_promotion(e,
-                                         theRTM.ANY_NODE_TYPE_STAR,
-                                         PromoteIterator::TYPE_PROMOTION));
+  push_nodestack( wrap_in_type_match(e,
+                                     theRTM.ANY_NODE_TYPE_STAR,
+                                     e->get_loc(),
+                                     TreatIterator::TYPE_MATCH));
 #endif /* ZORBA_NO_FULL_TEXT */
 }
 
@@ -14187,13 +14182,11 @@
   }
 
   if ( e1 ) {
-    e1 = wrap_in_atomization( e1 );
     e1 = wrap_in_type_promotion(e1,
                                 theRTM.INTEGER_TYPE_ONE,
                                 PromoteIterator::TYPE_PROMOTION);
   }
   if ( e2 ) {
-    e2 = wrap_in_atomization( e2 );
     e2 = wrap_in_type_promotion(e2,
                                 theRTM.INTEGER_TYPE_ONE,
                                 PromoteIterator::TYPE_PROMOTION);
@@ -14454,7 +14447,6 @@
   TRACE_VISIT_OUT ();
 #ifndef ZORBA_NO_FULL_TEXT
   expr* e( pop_nodestack() );
-  e = wrap_in_atomization( e );
   e = wrap_in_type_promotion(e,
                              theRTM.DOUBLE_TYPE_ONE,
                              PromoteIterator::TYPE_PROMOTION);
@@ -14491,7 +14483,6 @@
   TRACE_VISIT_OUT ();
 #ifndef ZORBA_NO_FULL_TEXT
   expr* e( pop_nodestack() );
-  e = wrap_in_atomization( e );
   e = wrap_in_type_promotion(e,
                              theRTM.INTEGER_TYPE_ONE,
                              PromoteIterator::TYPE_PROMOTION);
@@ -14509,7 +14500,6 @@
   TRACE_VISIT_OUT ();
 #ifndef ZORBA_NO_FULL_TEXT
   expr* e( pop_nodestack() );
-  e = wrap_in_atomization( e );
   e = wrap_in_type_promotion(e,
                              theRTM.STRING_TYPE_STAR,
                              PromoteIterator::TYPE_PROMOTION);

=== modified file 'src/runtime/core/sequencetypes.cpp'
--- src/runtime/core/sequencetypes.cpp	2012-09-26 05:00:36 +0000
+++ src/runtime/core/sequencetypes.cpp	2012-09-28 10:55:34 +0000
@@ -386,7 +386,7 @@
 
 bool PromoteIterator::nextImpl(store::Item_t& result, PlanState& planState) const
 {
-  store::Item_t lItem;
+  store::Item_t item;
   store::Item_t temp;
 
   const TypeManager* tm = theSctx->get_typemanager();
@@ -394,7 +394,7 @@
   PlanIteratorState* state;
   DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
 
-  if (!consumeNext(lItem, theChild.getp(), planState))
+  if (!consumeNext(item, theChild.getp(), planState))
   {
     if (theQuantifier == TypeConstants::QUANT_PLUS ||
         theQuantifier == TypeConstants::QUANT_ONE)
@@ -411,9 +411,9 @@
     }
 
     // catch exceptions to add/change the error location
-    if (! GenericCast::promote(result, lItem, thePromoteType, tm, loc))
+    if (! GenericCast::promote(result, item, thePromoteType, tm, loc))
     {
-      zstring valueType = tm->create_value_type(lItem)->toSchemaString();
+      zstring valueType = tm->create_value_type(item)->toSchemaString();
       raiseError(valueType);
     }
 
@@ -423,9 +423,9 @@
   {
     do
     {
-      if (! GenericCast::promote(result, lItem, thePromoteType, tm, loc))
+      if (! GenericCast::promote(result, item, thePromoteType, tm, loc))
       {
-        zstring valueType = tm->create_value_type(lItem)->toSchemaString();
+        zstring valueType = tm->create_value_type(item)->toSchemaString();
         raiseError(valueType);
       }
       else
@@ -433,7 +433,7 @@
         STACK_PUSH(true, state);
       }
     }
-    while (consumeNext(lItem, theChild.getp(), planState));
+    while (consumeNext(item, theChild.getp(), planState));
   }
 
   STACK_END(state);

=== modified file 'src/types/casting.cpp'
--- src/types/casting.cpp	2012-09-17 00:36:37 +0000
+++ src/types/casting.cpp	2012-09-28 10:55:34 +0000
@@ -2813,6 +2813,9 @@
 {
   RootTypeManager& rtm = GENV_TYPESYSTEM;
 
+  assert(item->isAtomic());
+
+  // If the target type is a builtin atomic type
   if (targetType->type_kind() == XQType::ATOMIC_TYPE_KIND)
   {
     return promote(result, 


Follow ups