PreviousUpNext

15.4.235  src/lib/compiler/back/low/display/dot.pkg

## dot.pkg
#
# Interface to the 'dot' tool from the grpahviz package.

# Compiled by:
#     src/lib/compiler/back/low/lib/visual.lib



stipulate
    package glo =  graph_layout;                        # graph_layout          is from   src/lib/compiler/back/low/display/graph-layout.pkg
    package odg =  oop_digraph;                         # oop_digraph   is from   src/lib/graph/oop-digraph.pkg
herein

    package dot: (weak)  Graph_Display {                # Graph_Display         is from   src/lib/compiler/back/low/display/graph-display.api


       fun suffix () = ".dot";
       fun program () = "dotty";

       fun visualize out (odg::DIGRAPH graph)
           =
           {   spaces = "                                           ";
               fun int n  = out (int::to_string n); 
               fun tab t  = out (string::substring (spaces, 0, t)) except _ => out spaces; end ;
               fun semi () = out ";";

               fun name n
                   =
                   if   (n < 0   )   out "XX";   int (-n);
                                else   out "X";    int   n;     fi;

               fun attributes t a
                   =
                   {   out "[ shape=box";
                       do_attribs t ", " a; out "]";
                   }

               also
               fun do_attrib t comma (glo::LABEL "")
                       =>
                       FALSE;

                   do_attrib t comma (glo::LABEL l)
                       =>
                       {   out comma;
                           tab t;
                           label l;
                           TRUE;
                       };

                   do_attrib t comma (glo::COLOR c)
                       => 
                       {   out comma;
                           tab t;
                           out "color=\"";
                           out c;
                           out "\"";
                           TRUE;
                       };

                   do_attrib t comma _
                       =>
                       FALSE;
               end 

               also
               fun do_attribs t comma []
                       =>
                       ();

                   do_attribs t comma (l ! ls)
                       =>
                       do_attribs t (if (do_attrib t comma l ) ",\n"; else comma;fi) ls;
               end 

               also
               fun label l
                   =
                   {   out "label=\"";
                       out (string::to_string l);
                       out "\"\n";
                   };

               fun do_node t (n, a)
                   =
                   {   tab t;
                       name n;
                       attributes t a;
                       semi();
                   };

               fun do_edge t (i, j, a)
                   =
                   {   tab t;
                       name i;
                       out "-> ";
                       name j;
                       attributes t a;
                       semi();
                   };

               out("digraph " + graph.name + " {\n");
               graph.forall_nodes (do_node 2);
               graph.forall_edges (do_edge 2);
               out "}\n" ;
            };
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext