Update of /cvsroot/monetdb/pathfinder/compiler/core
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv749/compiler/core

Modified Files:
      Tag: XQuery_0-16
        coreopt.brg 
Log Message:
-- Fixing bug 1637867:

   * mps.c: Remove numeric seqcast.

   * coreopt.brg: Replaced typeswitch by an if-then-else whenever we only 
     need to split up empty sequences from the rest. (As a side effect the
     typeswitch testing for type numeric is gone as well.)


Index: coreopt.brg
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/core/coreopt.brg,v
retrieving revision 1.42
retrieving revision 1.42.2.1
diff -u -d -r1.42 -r1.42.2.1
--- coreopt.brg 19 Jan 2007 09:35:16 -0000      1.42
+++ coreopt.brg 21 Feb 2007 13:30:00 -0000      1.42.2.1
@@ -667,7 +667,7 @@
              * If we statically know that the type of an expression matches
              * a typeswitch case, we can remove the typeswitch.
              */
-            if (PFty_subtype (L(p)->type, RLL(p)->type)) {
+            if (PFty_subtype (TY(L(p)), TY(RLL(p)))) {
                 *p = *RLR(p);
                 rewritten = true;
             }
@@ -676,11 +676,47 @@
              * can never match a typeswitch case, we can remove the
              * typeswitch.
              */
-            else if (PFty_disjoint (L(p)->type, RLL(p)->type)) {
+            else if (PFty_disjoint (TY(L(p)), TY(RLL(p)))) {
                 *p = *RRL(p);
                 rewritten = true;
             }
 
+            /*
+             * If the opt occurrence indicator is the only part
+             * in the typeswitch we cannot decide statically
+             * we can replace the typeswitch by a call to fn:exists ().
+             */
+            else if (L(p)->kind == c_var &&
+                R(p)->kind == c_cases &&
+                RL(p)->kind == c_case &&
+                PFty_subtype (TY(RLL(p)), PFty_item ()) &&
+                PFty_subtype (TY(L(p)), PFty_opt(TY(RLL(p))))) {
+                PFvar_t *v = PFcore_new_var (NULL);
+                PFfun_t *fn_exists
+                    = PFcore_function (PFqname (PFns_fn, "exists"));
+
+                /* if the input is not empty choose the case branch
+                   else choose the default branch */
+                *p = *flwr (let (letbind (
+                                     var (v),
+                                     apply (fn_exists, arg (L(p), nil ()))),
+                                 nil ()),
+                            if_ (var (v), then_else (RLR(p), RRL(p))));
+
+                /* type-check what we just created */
+                PFty_check (p);
+
+                rewritten = true;
+
+                /*
+                 * Re-label entire subtree. Type-checking may have
+                 * modified all the state labels in the subtree, so
+                 * we have to restore them.
+                 */
+                PFcoreopt_label (p);
+                break;
+            }
+
             break;
 
         /* CoreExpr:           seq (seq (CoreExpr, CoreExpr), CoreExpr) */


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Monetdb-pf-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-pf-checkins

Reply via email to