Update of /cvsroot/monetdb/pathfinder/compiler/core
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv790/compiler/core
Modified Files:
coreopt.brg
Log Message:
propagated changes of Tuesday Feb 20 2007 - Wednesday Feb 21 2007
from the XQuery_0-16 branch to the development trunk
Index: coreopt.brg
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/core/coreopt.brg,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- coreopt.brg 20 Feb 2007 14:25:46 -0000 1.44
+++ coreopt.brg 21 Feb 2007 14:25:51 -0000 1.45
@@ -653,7 +653,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;
}
@@ -662,11 +662,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