use typename
[prop.git] / prop-src / funmap.ph.old
blobbbbf4d02dbfaebff6f70c4580701c4ca0929d5a6
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 //  This file decribes the functor map data structure, which is 
4 //  used internally during rewriting compilation.
5 //
6 ///////////////////////////////////////////////////////////////////////////////
7 #ifndef functor_map_h
8 #define functor_map_h
9 #include <AD/automata/treegram.h>
10 #include "ir.h"
11 #include "type.h"
12 #include "hashtab.h"
14 ///////////////////////////////////////////////////////////////////////////////
16 //  Import some type definitions from the tree grammar and hash table
17 //  classes.
19 ///////////////////////////////////////////////////////////////////////////////
20 class ostream;
21 class TreeAutomaton;
22 typedef TreeGrammar::Functor        Functor;
23 typedef TreeGrammar::Variable       Variable;
25 ///////////////////////////////////////////////////////////////////////////////
27 //  Vector Id 
29 ///////////////////////////////////////////////////////////////////////////////
30 datatype VectorId : MEM = vector_id { cons : Cons, ty : Ty, arity : int };
32 ///////////////////////////////////////////////////////////////////////////////
34 //  Functor mapping table.
36 ///////////////////////////////////////////////////////////////////////////////
37 class FunctorMap {
38    FunctorMap(const FunctorMap&);      // no copy constructor
39    void operator = (const FunctorMap&);  // no assignment
40 public:
41    ////////////////////////////////////////////////////////////////////////////
42    //  Internals
43    ////////////////////////////////////////////////////////////////////////////
44    HashTable       literal_map; // mapping from literals to Functors
45    HashTable       type_map;    // mapping from types to Functors
46    HashTable       vector_map;  // mapping from vector constructors to Functors
47    HashTable       var_map;     // mapping from non-terminals to Functors
48    HashTable       rule_map;    // mapping from types to rule lists
49    HashTable       protocols;   // mapping from type to type
50    HashTable       nonterm_map; // mapping from (lhs) nonterminal to type
51    TreeGrammar::Functor         functors;    // number of functors
52    TreeGrammar::Variable        variables;   // number of variables
53    TreeAutomaton * tree_gen;    // the tree generator
54    Bool        use_compression; // should we use index compression?
55    Bool        has_guard;       // the set of rules contain guards?
56    Bool        has_cost;        // the set of rules contain costs?
57    Bool        has_cost_exp;    // the set of rules contain cost exprs?
58    Bool        has_syn_attrib;  // do we have synthesized attributes?
59    Bool        use_stack;       // should we use the attribute stack?
60    Bool        iso_tree;        // should we build an isomorphic tree?      
61    Bool        gen_traversal;   // should we generate a second traversal pass
62    int         N;               // number of rules
63    int         max_arity;       // maximum arity of patterns.
64    Id          class_name;      // name of rewrite class
65    Id *        functor_names;   // names of functors
66    Id *        variable_names;  // names of variables
68    ////////////////////////////////////////////////////////////////////////////
69    //
70    //  Constructor 
71    //
72    ////////////////////////////////////////////////////////////////////////////
73    FunctorMap(int n, Id name);
75    ////////////////////////////////////////////////////////////////////////////
76    //
77    //  Check whether a type known to the compiler?
78    //
79    ////////////////////////////////////////////////////////////////////////////
80    Bool is_known_type      (Ty);    
81    Bool is_rewritable_type (Ty);    
83    ////////////////////////////////////////////////////////////////////////////
84    //
85    //  Encoding methods
86    //
87    ////////////////////////////////////////////////////////////////////////////
88    void FunctorMap::encode (Ty);  // encode a type 
89    void FunctorMap::encode (Pat); // encode a pattern
90    void FunctorMap::encode (Id);  // encode a non-terminal
92    ////////////////////////////////////////////////////////////////////////////
93    //
94    //  Translation methods
95    //
96    ////////////////////////////////////////////////////////////////////////////
97    TreeTerm trans(Pat);
99    ////////////////////////////////////////////////////////////////////////////
100    //
101    //  Method to partition a set of rules according to the types of the
102    //  top level pattern, also encode the pattern in the process.
103    //
104    ////////////////////////////////////////////////////////////////////////////
105    void partition_rules (MatchRules);
107    ////////////////////////////////////////////////////////////////////////////
108    //
109    //  Method to compute the functor and variable names
110    //
111    ////////////////////////////////////////////////////////////////////////////
112    void compute_names (Id fun_names[], Id var_names[]);
114    ////////////////////////////////////////////////////////////////////////////
115    //
116    //  Method to print a report detailing the functor/variable encoding,
117    //  the tree grammar and the generated table size
118    //
119    ////////////////////////////////////////////////////////////////////////////
120    void print_report(ostream&);
123 ///////////////////////////////////////////////////////////////////////////////
125 //  Rewrite class environments
127 ///////////////////////////////////////////////////////////////////////////////
128 extern HashTable rewrite_env, rewrite_qual;
130 #endif