Update of /cvsroot/monetdb/pathfinder/compiler/semantics
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23023/compiler/semantics

Modified Files:
      Tag: PF_ROX
        ns.c typecheck.brg 
Log Message:
propagated changes of Wednesday Jan 30 2008 - Saturday Feb 09 2008
from the development trunk to the PF_ROX branch


Index: ns.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/semantics/ns.c,v
retrieving revision 1.37
retrieving revision 1.37.4.1
diff -u -d -r1.37 -r1.37.4.1
--- ns.c        11 Jan 2008 10:47:16 -0000      1.37
+++ ns.c        9 Feb 2008 08:40:35 -0000       1.37.4.1
@@ -1024,12 +1024,10 @@
 
 
 /**
- * Resolve NS usage in a query.
- *
- * @param root root of query abstract syntax tree
+ * Initialize the namespaces.
  */
 void
-PFns_resolve (PFpnode_t *root)
+PFns_init (void)
 {
     stat_known_ns = PFarray (sizeof (PFns_t));
 
@@ -1058,7 +1056,17 @@
 
     /* allow any namespace for declarations in queries */
     target_ns = PFns_wild;
+}
+
 
+/**
+ * Resolve NS usage in a query.
+ *
+ * @param root root of query abstract syntax tree
+ */
+void
+PFns_resolve (PFpnode_t *root)
+{
     /* initiate the actual NS resolution */
     ns_resolve (root); 
 }

Index: typecheck.brg
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/semantics/typecheck.brg,v
retrieving revision 1.64
retrieving revision 1.64.4.1
diff -u -d -r1.64 -r1.64.4.1
--- typecheck.brg       11 Jan 2008 10:47:16 -0000      1.64
+++ typecheck.brg       9 Feb 2008 08:40:35 -0000       1.64.4.1
@@ -1367,11 +1367,12 @@
 static PFfun_t *
 overload (PFqname_t qn, PFcnode_t *args)
 {
+    PFty_t     zoo_ty;
     PFarray_t *fns;
     PFcnode_t *arg;
     PFfun_t *fn;
     unsigned int i, a;
-    bool match;
+    bool match, zoo_match, arg_match;
 
     assert (args && (args->kind == c_nil || args->kind == c_arg));
 
@@ -1386,7 +1387,10 @@
          * expected formal parameter types?
          */
         if (fn->sig_count == 1) {
-            for (a = 0, match = true; a < fn->arity; a++) {
+            match     = true;
+            zoo_match = true;
+            a         = 0;
+            while (a < fn->arity) {
                 /* test if function has at least the same
                    number of arguments as the tested function */
                 if (arg->kind == c_nil)
@@ -1395,12 +1399,69 @@
                     break;
                 }
 
-                match = match && PFty_promotable (arg->child[0]->type,
-                        (fn->sigs[0].par_ty)[a]);
-                if (!match)
+                arg_match = PFty_promotable (arg->child[0]->type,
+                                             (fn->sigs[0].par_ty)[a]);
+                
+                match = match && arg_match;
+                
+                /* apply function zero-or-one on the type of the argument */
+                zoo_ty = *PFty_simplify (
+                              PFty_opt (
+                                  PFty_prime (
+                                      PFty_defn (
+                                          arg->child[0]->type))));
+                
+                /* and check if this type would be ok */
+                zoo_match = PFty_promotable (zoo_ty, (fn->sigs[0].par_ty)[a]);
+
+                /* if neither the original type
+                   nor the zero-or-one type match
+                   we give up */
+                if (!match && !zoo_match)
                     break;
 
-                arg = arg->child[1];
+                /* if the original type does not match
+                   but the zero-or-one type matches 
+                   we apply function zero-or-one on the input
+                   and check the argument again */
+                if (!arg_match && zoo_match) {
+                    /* create the function fn:zero-or-one */
+                    PFfun_t *zoo = function (PFqname (PFns_fn, "zero-or-one"));
+                    PFcnode_t *ret = PFcore_apply (
+                                         zoo,
+                                         PFcore_arg (
+                                             L(arg),
+                                             PFcore_nil ()));
+                    
+                    /* Set state label correctly before we return. */
+                    STATE_LABEL(LR(ret)) = PFtypecheck_state (
+                                               OP_LABEL(LR(ret)), 0, 0);
+                    STATE_LABEL(L(ret))  = PFtypecheck_state (
+                                               OP_LABEL(L(ret)),
+                                               STATE_LABEL(LL(ret)),
+                                               STATE_LABEL(LR(ret)));
+                    STATE_LABEL(ret)     = PFtypecheck_state (
+                                               OP_LABEL(ret),
+                                               STATE_LABEL(L(ret)),
+                                               0);
+                    
+                    /* fix the types correctly */
+                    TY(L(ret)) = TY(L(arg));
+                    TY(ret)    = zoo_ty;
+                    TY(arg)    = zoo_ty;
+                    
+                    /* replace the argument by the function
+                       zero-or-one applied to the argument */
+                    L(arg) = ret;
+
+                    /* re-check */
+                }
+                else {
+                    /* continue */
+                    a++;
+                    arg = arg->child[1];
+                }
+                
                 assert (arg);
             }
 


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Monetdb-pf-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-pf-checkins

Reply via email to