ignore .lib and .exe
[prop.git] / prop-src / visual2.pcc
blobf69412f6fcfbabb5e7c5eced6b0817c211c21edc
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 //  This file implements the datatype definitions layout generator
4 //  for visualizing datatype definitions using vcg.
5 //
6 //////////////////////////////////////////////////////////////////////////////
7 #include <AD/strings/quark.h>
8 #include "ir.ph"
9 #include "type.h"
10 #include "classdef.h"
11 #include "datatype.h"
12 #include "hashtab.h"
13 #include "visualize.h"
15 //////////////////////////////////////////////////////////////////////////////
17 //  This method visualizes all the class definitions.
19 //////////////////////////////////////////////////////////////////////////////
20 void PropVisualizer::visualize_datatype_definitions()
21 {  const char * Datatypes = "All datatypes definitions";
23    begin_node(Datatypes);
24    label     (Datatypes);
25    end_node  (Datatypes);
27    for (HashTable::Entry * e = ClassDefinition::defined_classes.first();
28         e != 0; e = ClassDefinition::defined_classes.next(e))
29    {  
30       ClassDefinition * C = (ClassDefinition *)(e->v);
31       C->visualize(*this);
32    }
35 //////////////////////////////////////////////////////////////////////////////
37 //  This method a particular class definitions.
39 //////////////////////////////////////////////////////////////////////////////
40 void ClassDefinition::visualize(PropVisualizer& v)
41 {  v . begin_node (class_name);
42    v . add_label  ("%s %s", class_type_name[class_type], class_name);
43    v . make_label ();
44    v . end_node   (class_name);
47 //////////////////////////////////////////////////////////////////////////////
49 //  This method visualizes a datatype hierarchy.
51 //////////////////////////////////////////////////////////////////////////////
52 void DatatypeHierarchy::visualize(PropVisualizer& v)
53 {  v . begin_node (datatype_name);
54    v . add_label  ("datatype %s%V\n", datatype_name, parameters);
55    v . add_label  ("(\"%s\" line %i)\n", file_name, begin_line);
56    for (int i = 0; i < arity; i++)
57    {  Cons c = constructor_terms[i];
58       v . add_label(" %s\n", constructor_terms[i]->name);
59    }
60    v . make_label ();
62    int offset = 2;
64    // Make a node for each of the constructors.
65    for (int i = 0; i < arity; i++)
66    {  Cons c = constructor_terms[i];
67       if (c->ty == NOty) // unit constructors
68       {  v . begin_node(c->name);
69          v . label(c->name);
70          v . end_node(c->name);
71       }
72       v . begin_edge(datatype_name, c->name);
73       v . color (VCG::darkblue);
74       v . arrowcolor (VCG::red);
75       v . thickness (4);
76       //v . anchor(offset + i + 1);
77       v . end_edge(datatype_name, c->name);
78    }
80    v . end_node (datatype_name);
82    // Argument constructors
84    // Generate the only argument 
85    if (cons != NOcons) DatatypeClass::visualize(v);
88 //////////////////////////////////////////////////////////////////////////////
90 //  This method visualizes a datatype subclass
92 //////////////////////////////////////////////////////////////////////////////
93 void DatatypeClass::visualize(PropVisualizer& v)
94 {  v . begin_node (constructor_name);
95    v . add_label  ("%s\n", constructor_name); 
97    // Print each type on a single line
98    int anchor = 2;
99    match (cons->ty)
100    {  TUPLEty tys:
101       {  for_each(Ty, t, tys) 
102            { v . add_type(constructor_name,0,t,anchor++); } }
103    |  RECORDty (labels,_,tys):
104       {  Ids ls; Tys ts;
105          for(ls = labels, ts = tys; ls && ts; ls = ls->#2, ts = ts->#2)
106          { v . add_type(constructor_name,ls->#1, ts->#1,anchor++); }
107       }
108    |  ty:  { v . add_type(constructor_name,0,ty,anchor); }
109    }
111    v . make_label ();
112    v . end_node   (constructor_name);
115 //////////////////////////////////////////////////////////////////////////////
117 //  This method adds a type component for a datatype constructor
119 //////////////////////////////////////////////////////////////////////////////
120 void PropVisualizer::add_type(Id cons_name, Id label, Ty ty, int anch)
122    add_label("  ");
123    if (label != 0) add_label("%s : ", label);
124    add_label("%T\n", ty);
126    // Create a has-a edge
127    match (deref_all(ty))
128    {  DATATYPEty ({ id ... }, _):
129       {  // begin_edge(cons_name,id);
130          // color (lightgreen);
131          // anchor(anch);
132          // end_edge(cons_name,id);
133       }
134    |  _: // skip
135    }