Changeset: 1e725401483d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1e725401483d
Modified Files:
        pathfinder/compiler/Makefile.ag
        pathfinder/compiler/compile.c
        pathfinder/compiler/debug/abssynprint.c
        pathfinder/compiler/debug/coreprint.c
        pathfinder/compiler/debug/logdebug.c
        pathfinder/compiler/debug/physdebug.c
        pathfinder/compiler/debug/prettyp.c
        pathfinder/compiler/include/array.h
        pathfinder/compiler/include/logdebug.h
        pathfinder/compiler/include/plan_bundle.h
        pathfinder/compiler/include/prettyp.h
        pathfinder/compiler/include/sqlprint.h
        pathfinder/compiler/main_opt.c
        pathfinder/compiler/main_sql.c
        pathfinder/compiler/pf_ferry.c
        pathfinder/compiler/plan_bundle.c
        pathfinder/compiler/sql/sqlprint.c
Branch: default
Log Message:

Changed printing behavior & consolidated plan bundle printing

-- Changed the printing methods for the logical algebra:
   DOT, XML, and SQL output are now printed into a character array
   instead of into a file.

-- The PF/Ferry library now provides the correct result strings.

-- Consolidated the plan bundle printing by merging the printing
   in compile.c, logdebug.c, and main_sql.c into a common macro
   in plan_bundle.h.
   The helper function for the plan bundle property structure
   printing now resides in an additional file plan_bundle.c.


diffs (truncated from 1978 to 300 lines):

diff -r 8f7bb7f96978 -r 1e725401483d pathfinder/compiler/Makefile.ag
--- a/pathfinder/compiler/Makefile.ag   Tue Jun 15 16:17:50 2010 +0200
+++ b/pathfinder/compiler/Makefile.ag   Wed Jun 16 11:17:44 2010 +0200
@@ -41,6 +41,7 @@
              env.c \
              oops.c \
              pfstrings.c \
+             plan_bundle.c \
              qname.c \
              scope.c \
              timer.c \
@@ -53,6 +54,7 @@
              env.c \
              oops.c \
              pfstrings.c \
+             plan_bundle.c \
              qname.c \
              timer.c
 }
diff -r 8f7bb7f96978 -r 1e725401483d pathfinder/compiler/compile.c
--- a/pathfinder/compiler/compile.c     Tue Jun 15 16:17:50 2010 +0200
+++ b/pathfinder/compiler/compile.c     Wed Jun 16 11:17:44 2010 +0200
@@ -61,7 +61,6 @@
 #include "options.h"      /* extract option declarations from parse tree */
 #include "xquery_fo.h"    /* built-in XQuery F&O */
 #include "func_chk.h"     /* function resolution */
-#include "prettyp.h"
 #include "abssynprint.h"
 #include "coreprint.h"
 #include "logdebug.h"
@@ -301,17 +300,17 @@
 int
 PFcompile (char *url, FILE *pfout, PFstate_t *status)
 {
-    PFpnode_t *proot  = NULL;
-    PFcnode_t *croot  = NULL;
+    PFpnode_t      *proot  = NULL;
+    PFcnode_t      *croot  = NULL;
     /* We either have a plan bundle in @a lapb
        or a logical query plan in @a laroot. */
-    PFla_pb_t *lapb   = NULL;
-    PFla_op_t *laroot = NULL;
-    PFpa_op_t *paroot = NULL;
-    PFmil_t   *mroot  = NULL;
-    PFarray_t *mil_program = NULL;
-    char      *xquery = NULL;
-    int        module_base;
+    PFla_pb_t      *lapb   = NULL;
+    PFla_op_t      *laroot = NULL;
+    PFpa_op_t      *paroot = NULL;
+    PFmil_t        *mroot  = NULL;
+    PFchar_array_t *mil_program = NULL;
+    char           *xquery = NULL;
+    int             module_base;
 
     /* elapsed time for compiler phase */
     long tm, tm_first = 0;
@@ -680,46 +679,26 @@
     /* Split Point: SQL Code Generation */
     /************************************/
     if (status->output_format == PFoutput_format_sql) {
-        unsigned int i = 0, c;
-        /* plan bundle emits SQL code wrapped in XML tags */ 
-        if (lapb)
-            fprintf (pfout, "<query_plan_bundle>\n");
-        /* If we have a plan bundle we have to generate
-           a SQL query for each query plan. */
-        do {
-            /* plan bundle emits SQL code wrapped in XML tags
-               with additional column and linking information */ 
-            if (lapb) {
-                laroot = PFla_pb_op_at (lapb, i);
-                assert (laroot->kind == la_serialize_rel);
+        PFchar_array_t *sql_str = PFchar_array (4096);
 
-                fprintf (pfout, "<query_plan id=\"%i\"",
-                         PFla_pb_id_at (lapb, i));
-                if (PFla_pb_idref_at (lapb, i) != -1)
-                    fprintf (pfout, " idref=\"%i\" colref=\"%i\"",
-                             PFla_pb_idref_at (lapb, i),
-                             PFla_pb_colref_at (lapb, i));
-                fprintf (pfout, ">\n");
-                fprintf (pfout,
-                         "<schema>\n"
-                         "  <column name=\"%s\" function=\"iter\"/>\n",
-                         PFcol_str (laroot->sem.ser_rel.iter));
-                for (c = 0; c < clsize (laroot->sem.ser_rel.items); c++)
-                    fprintf (pfout,
-                             "  <column name=\"%s\" new=\"false\""
-                                      " function=\"item\""
-                                      " position=\"%u\"/>\n",
-                             PFcol_str (clat (laroot->sem.ser_rel.items, c)),
-                             c);
-                fprintf (pfout, "</schema>\n"
-                                "<query>"
+        /**
+         * Iterate over the plan_bundle list lapb and bind every item to 
laroot_.
+         *
+         * BEWARE: macro has to be used in combination with macro PFla_pb_end.
+         */
+        PFla_pb_foreach (sql_str, laroot_, lapb, laroot)
+
+
+
+            /* plan bundle emits SQL code wrapped in XML tags */ 
+            if (lapb)
+                PFarray_printf (sql_str, 
+                                "    <query>"
                                 "<![CDATA[\n");
-                i++;
-            }
 
             /* generate the SQL code */
             tm = PFtimer_start ();
-            PFsql_t *sqlroot = PFlalg2sql(laroot);
+            PFsql_t *sqlroot = PFlalg2sql(laroot_);
             tm = PFtimer_stop (tm);
             if (status->timing)
                 PFlog ("Compilation to SQL:\t\t\t %s", PFtimer_str (tm));
@@ -739,23 +718,28 @@
 
             /* serialize the internal SQL query tree */
             tm = PFtimer_start ();
-            PFsql_print (pfout, sqlroot);
+            PFsql_print (sql_str, sqlroot);
             tm = PFtimer_stop (tm);
             if (status->timing)
                 PFlog ("SQL Code generation:\t\t\t %s", PFtimer_str (tm));
 
             /* plan bundle emits SQL code wrapped in XML tags */ 
             if (lapb)
-                fprintf (pfout, "]]>"
-                                "</query>\n"
-                                "</query_plan>\n");
+                PFarray_printf (sql_str, 
+                                "]]>"
+                                "</query>\n");
 
-        /* iterate over the plans in the plan bundle */
-        } while (lapb && i < PFla_pb_size (lapb));
 
-        /* plan bundle emits SQL code wrapped in XML tags */ 
-        if (lapb)
-            fprintf (pfout, "</query_plan_bundle>\n");
+
+        /**
+         * Iterate over the plan_bundle list lapb and bind every item to 
laroot_.
+         *
+         * BEWARE: macro has to be used in combination with macro 
PFla_pb_foreach.
+         */
+        PFla_pb_foreach_end (sql_str, lapb)
+
+        /* print the resulting string to the output stream */
+        fputs (sql_str->base, pfout);
 
         goto bailout;
     }
@@ -919,26 +903,28 @@
 
     /* print algebra tree if requested */
     if (status->print_la_tree) {
+        PFchar_array_t *out_str = PFchar_array (4096);
         if (laroot) {
             if (status->print_pretty) {
                 PFinfo (OOPS_WARNING,
                         "Cannot prettyprint logical algebra tree. Sorry.");
             }
             if (status->print_dot)
-                PFla_dot (pfout, laroot, status->format);
+                PFla_dot (out_str, laroot, status->format);
             if (status->print_xml)
-                PFla_xml (pfout, laroot, status->format);
+                PFla_xml (out_str, laroot, status->format);
         }
         else if (lapb) {
             if (status->print_dot)
-                PFla_dot_bundle (pfout, lapb, status->format);
+                PFla_dot_bundle (out_str, lapb, status->format);
             if (status->print_xml)
-                PFla_xml_bundle (pfout, lapb, status->format);
+                PFla_xml_bundle (out_str, lapb, status->format);
         }
         else
             PFinfo (OOPS_NOTICE,
                     "logical algebra tree not available "
                     "at this point of compilation");
+        fputs (out_str->base, pfout);
     }
 
     /* print MIL algebra tree if requested */
@@ -990,10 +976,10 @@
         long timing;
         int module_base;
         /* for ALGEBRA (PFoutput_format_mil) & SQL (PFoutput_format_sql) */
-        PFla_op_t  *laroot = NULL;
-        PFpa_op_t  *paroot = NULL;
-        PFmil_t    *mroot  = NULL;
-        PFarray_t  *serialized_mil_code = NULL;
+        PFla_op_t      *laroot = NULL;
+        PFpa_op_t      *paroot = NULL;
+        PFmil_t        *mroot  = NULL;
+        PFchar_array_t *serialized_mil_code = NULL;
         PFguide_list_t *guide_list = NULL; /* guide list */
         /* for MILPRINT_SUMMER (PFoutput_format_milprint_summer) */
         char *intern_prologue = NULL,
diff -r 8f7bb7f96978 -r 1e725401483d pathfinder/compiler/debug/abssynprint.c
--- a/pathfinder/compiler/debug/abssynprint.c   Tue Jun 15 16:17:50 2010 +0200
+++ b/pathfinder/compiler/debug/abssynprint.c   Wed Jun 16 11:17:44 2010 +0200
@@ -563,11 +563,14 @@
 void
 PFabssyn_pretty (FILE *f, PFpnode_t *t, bool qnames_resolved)
 {
+        PFchar_array_t *a = PFchar_array (500);
+
         PFprettyprintf ("%c", START_BLOCK);
         abssyn_pretty (t, qnames_resolved);
         PFprettyprintf ("%c", END_BLOCK);
 
-        (void) PFprettyp (f);
+        PFprettyp (a);
+        fputs (a->base, f);
 
         fputc ('\n', f);
 }
diff -r 8f7bb7f96978 -r 1e725401483d pathfinder/compiler/debug/coreprint.c
--- a/pathfinder/compiler/debug/coreprint.c     Tue Jun 15 16:17:50 2010 +0200
+++ b/pathfinder/compiler/debug/coreprint.c     Wed Jun 16 11:17:44 2010 +0200
@@ -51,7 +51,6 @@
 /* PFesc_string */
 #include "pfstrings.h"
 
-#include "prettyp.h"
 #include <assert.h>
 
 /* Easily access subtree-parts */
@@ -348,9 +347,8 @@
         fprintf (f, "%s", n->sem.tru ? "stable" : "unstable");
         break;
     case c_orderspecs:
-        fprintf (f, "%s,%c %c%s", n->sem.mode.dir == p_desc ?
+        fprintf (f, "%s, %s", n->sem.mode.dir == p_desc ?
                                       "descending" : "ascending",
-                                      END_BLOCK, START_BLOCK,
                                       n->sem.mode.empty == p_greatest ?
                                       "greatest" : "least");
         break;
diff -r 8f7bb7f96978 -r 1e725401483d pathfinder/compiler/debug/logdebug.c
--- a/pathfinder/compiler/debug/logdebug.c      Tue Jun 15 16:17:50 2010 +0200
+++ b/pathfinder/compiler/debug/logdebug.c      Wed Jun 16 11:17:44 2010 +0200
@@ -46,7 +46,6 @@
 
 #include "alg_dag.h"
 #include "mem.h"
-#include "prettyp.h"
 #include "oops.h"
 #include "pfstrings.h"
 
@@ -211,7 +210,7 @@
 static char *
 literal (PFalg_atom_t a)
 {
-    PFarray_t *s = PFarray (sizeof (char), 50);
+    PFchar_array_t *s = PFchar_array (50);
 
     switch (a.type) {
 
@@ -262,7 +261,7 @@
 static char *
 xml_literal (PFalg_atom_t a)
 {
-    PFarray_t *s = PFarray (sizeof (char), 50);
+    PFchar_array_t *s = PFchar_array (50);
 
     if (a.type == aat_nat)
         PFarray_printf (
@@ -314,7 +313,7 @@
 xml_literal_list (PFalg_simple_type_t ty)
 {
     bool first = true;
-    PFarray_t *s = PFarray (sizeof (char), 50);
+    PFchar_array_t *s = PFchar_array (50);
 
     if (ty & aat_update)
         PFarray_printf (s, "update");
@@ -379,7 +378,7 @@
  * @param n The current node to print (function is recursive)
  */
 static void
-la_dot (PFarray_t *dot, PFarray_t *side_effects,
+la_dot (PFchar_array_t *dot, PFchar_array_t *side_effects,
         PFla_op_t *n, bool print_frag_info, char *prop_args, int id)
 {
 #define DOT (n->bit_in ? dot : side_effects)
@@ -1592,7 +1591,7 @@
  * @param n The current node to print (function is recursive)
  */
 static void
-la_xml (PFarray_t *xml, PFla_op_t *n, char *prop_args)
+la_xml (PFchar_array_t *xml, PFla_op_t *n, char *prop_args)
 {
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to