1 ///////////////////////////////////////////////////////////////////////////////
2 // This file is generated automatically using Prop (version 2.3.6),
3 // last updated on Nov 2, 1999.
4 // The original source file is "funmap.ph".
5 ///////////////////////////////////////////////////////////////////////////////
8 ///////////////////////////////////////////////////////////////////////////////
10 // This file decribes the functor map data structure, which is
11 // used internally during rewriting compilation.
13 ///////////////////////////////////////////////////////////////////////////////
17 #include <AD/automata/treegram.h>
22 #include "functortab.h"
25 ///////////////////////////////////////////////////////////////////////////////
27 // Import some type definitions from the tree grammar and hash table
30 ///////////////////////////////////////////////////////////////////////////////
33 typedef TreeGrammar::Functor Functor
;
34 typedef TreeGrammar::Variable Variable
;
36 ///////////////////////////////////////////////////////////////////////////////
40 ///////////////////////////////////////////////////////////////////////////////
43 ///////////////////////////////////////////////////////////////////////////////
45 // Forward class definition for VectorId
47 ///////////////////////////////////////////////////////////////////////////////
48 #ifndef datatype_VectorId_defined
49 #define datatype_VectorId_defined
51 typedef a_VectorId
* VectorId
;
54 ///////////////////////////////////////////////////////////////////////////////
56 // Class for datatype constructor VectorId::vector_id
58 ///////////////////////////////////////////////////////////////////////////////
59 class a_VectorId
: public MEM
{
62 Cons cons
; Ty ty
; int arity
;
63 a_VectorId (Cons x_cons
, Ty x_ty
, int x_arity
);
65 inline int boxed(const a_VectorId
*) { return 1; }
66 inline int untag(const a_VectorId
*) { return 0; }
67 ///////////////////////////////////////////////////////////////////////////////
69 // Datatype constructor functions for VectorId
71 ///////////////////////////////////////////////////////////////////////////////
72 extern a_VectorId
* vector_id (Cons x_cons
, Ty x_ty
, int x_arity
);
78 ///////////////////////////////////////////////////////////////////////////////
80 // Functor mapping table.
82 ///////////////////////////////////////////////////////////////////////////////
84 FunctorMap(const FunctorMap
&); // no copy constructor
85 void operator = (const FunctorMap
&); // no assignment
87 ////////////////////////////////////////////////////////////////////////////
89 ////////////////////////////////////////////////////////////////////////////
90 FunctorTable literal_map
; // mapping from literals to Functors
91 FunctorTable type_map
; // mapping from types to Functors
92 FunctorTable vector_map
; // mapping from vector constructors to Functors
93 FunctorTable var_map
; // mapping from non-terminals to Functors
94 HashTable rule_map
; // mapping from types to rule lists
95 HashTable topdown_rule_map
; // mapping from types to topdown rules
96 HashTable before_rule_map
; // mapping from types to before rules
97 HashTable preorder_rule_map
; // mapping from types to preorder rules
98 HashTable postorder_rule_map
; // mapping from types to postorder rules
99 HashTable
* rule_maps
[MatchRuleInfo::LAST_REWRITING_MODE
]; // rule maps
100 HashTable protocols
; // mapping from type to type
101 HashTable nonterm_map
; // mapping from (lhs) nonterminal to type
102 HashTable nonterm_rules
;// mapping from (lhs) nonterminal to rules.
103 HashTable nonterm_rules_bits
;// mapping from (lhs) nonterminal to size of rules.
104 HashTable chain_rules
; // mapping of rhs to rules of form lhs -> rhs
105 TreeGrammar G
; // the current tree grammar
106 TreeGrammar::Functor functors
; // number of functors
107 TreeGrammar::Variable variables
; // number of variables
108 TreeAutomaton
* tree_gen
; // the tree automaton generator
109 TopDownGen
* topdown_gen
; // topdown tree automaton generator
110 Bool use_compression
; // should we use index compression?
111 Bool has_guard
; // the set of rules contain guards?
112 Bool has_cost
; // the set of rules contain costs?
113 Bool has_cost_exp
; // the set of rules contain cost exprs?
114 Bool has_syn_attrib
; // are we using synthesized attributes?
115 Bool has_replacement
; // the set of rules have replacements?
116 Bool is_applicative
; // Is rewriting done applicatively?
117 Bool gen_reducers
; // Should we generate a reducer?
118 Bool dynamic_search
; // Use runtime search?
119 int N
; // number of rules
120 int max_arity
; // maximum arity of patterns.
121 Id class_name
; // name of rewrite class
122 Id
* functor_names
; // names of functors
123 Id
* variable_names
; // names of variables
124 Bool is_ok
; // no errors found?
125 MatchRules bottomup_rules
; // only the bottomup rules are here
127 ////////////////////////////////////////////////////////////////////////////
131 ////////////////////////////////////////////////////////////////////////////
132 FunctorMap(Id name
, MatchRules rules
);
134 ////////////////////////////////////////////////////////////////////////////
136 // Check whether we have an error
138 ////////////////////////////////////////////////////////////////////////////
139 inline Bool
ok() const { return is_ok
; }
141 ////////////////////////////////////////////////////////////////////////////
143 // Check whether a type known to the compiler?
145 ////////////////////////////////////////////////////////////////////////////
146 Bool
is_known_type (Ty
);
147 Bool
is_rewritable_type (Ty
);
149 ////////////////////////////////////////////////////////////////////////////
151 // Methods to compute the cost expression of a pattern.
153 ////////////////////////////////////////////////////////////////////////////
154 Exp
cost_expr (Id
, Pat
);
155 Exp
cost_expr (Id
, Pat
, Exp
);
156 Exp
cost_expr (Id
, Pats
, Exp
);
157 Exp
cost_expr (Id
, LabPats
, Exp
);
159 ////////////////////////////////////////////////////////////////////////////
161 // Method to print a report detailing the functor/variable encoding,
162 // the tree grammar and the generated table size
164 ////////////////////////////////////////////////////////////////////////////
165 void print_report(std::ostream
&);
168 ////////////////////////////////////////////////////////////////////////////
170 // Methods to build the protocol list
172 ////////////////////////////////////////////////////////////////////////////
173 void enter_protocols ();
174 void check_for_missing_protocols ();
176 ////////////////////////////////////////////////////////////////////////////
178 // Methods to convert literal patterns into guards
180 ////////////////////////////////////////////////////////////////////////////
181 void make_guard (MatchRules
);
182 Pat
make_guard (Pat
, Exp
&);
183 Pats
make_guard (Pats
, Exp
&);
184 LabPats
make_guard (LabPats
, Exp
&);
186 ////////////////////////////////////////////////////////////////////////////
188 // Method to build the tree grammar
190 ////////////////////////////////////////////////////////////////////////////
191 void build_tree_grammar (MatchRules
);
193 ////////////////////////////////////////////////////////////////////////////
197 ////////////////////////////////////////////////////////////////////////////
198 void encode (Ty
); // encode a type
199 void encode (Pat
); // encode a pattern
200 void encode (Id
); // encode a non-terminal
201 Id
chain_rule_rhs (Pat
);
203 ////////////////////////////////////////////////////////////////////////////
205 // Translation methods
207 ////////////////////////////////////////////////////////////////////////////
210 ////////////////////////////////////////////////////////////////////////////
212 // Method to partition a set of rules according to the types of the
213 // top level pattern, also encode the pattern in the process.
215 ////////////////////////////////////////////////////////////////////////////
216 MatchRules
partition_rules (MatchRules
);
218 ////////////////////////////////////////////////////////////////////////////
220 // Method to compute the functor and variable names
222 ////////////////////////////////////////////////////////////////////////////
223 void compute_names ();
227 #line 185 "funmap.ph"
229 ------------------------------- Statistics -------------------------------
230 Merge matching rules = yes
231 Number of DFA nodes merged = 0
232 Number of ifs generated = 0
233 Number of switches generated = 0
236 Adaptive matching = enabled
237 Fast string matching = disabled
238 Inline downcasts = enabled
239 --------------------------------------------------------------------------