1 ///////////////////////////////////////////////////////////////////////////////
3 // This file decribes the functor map data structure, which is
4 // used internally during rewriting compilation.
6 ///////////////////////////////////////////////////////////////////////////////
9 #include <AD/automata/treegram.h>
14 ///////////////////////////////////////////////////////////////////////////////
16 // Import some type definitions from the tree grammar and hash table
19 ///////////////////////////////////////////////////////////////////////////////
22 typedef TreeGrammar::Functor Functor;
23 typedef TreeGrammar::Variable Variable;
25 ///////////////////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////////////////////
30 datatype VectorId : MEM = vector_id { cons : Cons, ty : Ty, arity : int };
32 ///////////////////////////////////////////////////////////////////////////////
34 // Functor mapping table.
36 ///////////////////////////////////////////////////////////////////////////////
38 FunctorMap(const FunctorMap&); // no copy constructor
39 void operator = (const FunctorMap&); // no assignment
41 ////////////////////////////////////////////////////////////////////////////
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 ////////////////////////////////////////////////////////////////////////////
72 ////////////////////////////////////////////////////////////////////////////
73 FunctorMap(int n, Id name);
75 ////////////////////////////////////////////////////////////////////////////
77 // Check whether a type known to the compiler?
79 ////////////////////////////////////////////////////////////////////////////
80 Bool is_known_type (Ty);
81 Bool is_rewritable_type (Ty);
83 ////////////////////////////////////////////////////////////////////////////
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 ////////////////////////////////////////////////////////////////////////////
94 // Translation methods
96 ////////////////////////////////////////////////////////////////////////////
99 ////////////////////////////////////////////////////////////////////////////
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.
104 ////////////////////////////////////////////////////////////////////////////
105 void partition_rules (MatchRules);
107 ////////////////////////////////////////////////////////////////////////////
109 // Method to compute the functor and variable names
111 ////////////////////////////////////////////////////////////////////////////
112 void compute_names (Id fun_names[], Id var_names[]);
114 ////////////////////////////////////////////////////////////////////////////
116 // Method to print a report detailing the functor/variable encoding,
117 // the tree grammar and the generated table size
119 ////////////////////////////////////////////////////////////////////////////
120 void print_report(ostream&);
123 ///////////////////////////////////////////////////////////////////////////////
125 // Rewrite class environments
127 ///////////////////////////////////////////////////////////////////////////////
128 extern HashTable rewrite_env, rewrite_qual;