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 "rwgen4.pcc".
5 ///////////////////////////////////////////////////////////////////////////////
7 #define PROP_STRCMP_USED
10 ///////////////////////////////////////////////////////////////////////////////
12 // This file implements the tree rewriting/tree parsing compiler.
13 // This is used to implement the rewrite class/rewrite constructs of Prop.
15 ///////////////////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////////////////
30 // Method to generate a set of pattern matching rules for a labeler
32 ///////////////////////////////////////////////////////////////////////////////
33 void RewritingCompiler::gen_auxiliary_rules
34 (FunctorMap
& F
, Ty ty
, MatchRuleInfo::RewritingMode mode
)
35 { if (F
.rule_maps
[mode
]->contains(ty
))
36 { MatchRules rules
= rev(MatchRules((*F
.rule_maps
[mode
])[ty
]));
37 debug_msg("%Lgenerating auxiliary rules for rewrite class %s type %T:\n",
39 for_each(MatchRule
,r
,rules
) debug_msg("%!\t%r\n",r
->loc(),r
);
43 list_1_(MATCHexp(IDexp(redex_name(ty
)),0))
50 ///////////////////////////////////////////////////////////////////////////////
52 // Method to generate the before rules of a labeler
54 ///////////////////////////////////////////////////////////////////////////////
55 void RewritingCompiler::gen_before_rules(FunctorMap
& F
, Ty ty
)
56 { gen_auxiliary_rules(F
,ty
,MatchRuleInfo::BEFORE
);
59 ///////////////////////////////////////////////////////////////////////////////
61 // Method to generate the preorder rules of a labeler
63 ///////////////////////////////////////////////////////////////////////////////
64 void RewritingCompiler::gen_preorder_rules(FunctorMap
& F
, Ty ty
)
65 { gen_auxiliary_rules(F
,ty
,MatchRuleInfo::PREORDER
);
68 ///////////////////////////////////////////////////////////////////////////////
70 // Method to generate the postorder rules of a labeler
72 ///////////////////////////////////////////////////////////////////////////////
73 void RewritingCompiler::gen_postorder_rules(FunctorMap
& F
, Ty ty
)
74 { gen_auxiliary_rules(F
,ty
,MatchRuleInfo::POSTORDER
);
77 ///////////////////////////////////////////////////////////////////////////////
79 // Method to generate the topdown rules of a labeler
81 ///////////////////////////////////////////////////////////////////////////////
82 void RewritingCompiler::gen_topdown_rules(FunctorMap
& F
, Ty ty
)
83 { gen_auxiliary_rules(F
,ty
,MatchRuleInfo::TOPDOWN
);
86 ///////////////////////////////////////////////////////////////////////////////
88 // Method to generate a tracing macro
90 ///////////////////////////////////////////////////////////////////////////////
91 void RewritingCompiler::gen_trace_macro(Id name
, FunctorMap
& F
)
95 "%n// This macro can be redefined by the user for debugging"
99 "%n#define DEBUG_%S(repl,redex,file,line,rule) repl"
101 "%nstatic const char * %S_file_name = \"%s\";"
103 name
, name
, name
, file
107 ///////////////////////////////////////////////////////////////////////////////
109 // Method to find out whether the replacement term is simple.
110 // A replacement term is simple if it is a projection/selection from
111 // the redex, or the redex itself.
113 ///////////////////////////////////////////////////////////////////////////////
114 Bool
is_simple_replacement(Exp exp
)
116 #line 100 "rwgen4.pcc"
117 #line 105 "rwgen4.pcc"
121 switch (exp
->tag__
) {
122 case a_Exp::tag_IDexp
: {
123 if (_equal_string(((Exp_IDexp
*)exp
)->IDexp
,"redex")) {
124 #line 101 "rwgen4.pcc"
126 #line 101 "rwgen4.pcc"
130 #line 105 "rwgen4.pcc"
132 #line 105 "rwgen4.pcc"
135 case a_Exp::tag_DOTexp
: {
136 if (((Exp_DOTexp
*)exp
)->_1
) {
137 switch (((Exp_DOTexp
*)exp
)->_1
->tag__
) {
138 case a_Exp::tag_SELECTORexp
: {
139 #line 102 "rwgen4.pcc"
140 exp
= ((Exp_SELECTORexp
*)((Exp_DOTexp
*)exp
)->_1
)->_1
;
141 #line 102 "rwgen4.pcc"
143 default: { goto L2
; } break;
147 case a_Exp::tag_SELECTORexp
: {
148 #line 103 "rwgen4.pcc"
149 exp
= ((Exp_SELECTORexp
*)exp
)->_1
;
150 #line 103 "rwgen4.pcc"
152 case a_Exp::tag_MARKEDexp
: {
153 #line 104 "rwgen4.pcc"
154 exp
= ((Exp_MARKEDexp
*)exp
)->_2
;
155 #line 104 "rwgen4.pcc"
157 default: { goto L2
; } break;
162 #line 106 "rwgen4.pcc"
163 #line 106 "rwgen4.pcc"
167 ///////////////////////////////////////////////////////////////////////////////
169 // Method to generate a replacement statement. We'll optimize all
170 // bottomup and after rewriting rules.
172 ///////////////////////////////////////////////////////////////////////////////
173 void RewritingCompiler::gen_replacement
174 (Exp exp
, MatchRuleInfo::RewritingMode mode
)
176 trs
&& trs
->gen_replacement(*this,current_rule
->rule_number
,exp
);
177 pr("%^{ redex = DEBUG_%S(%e,redex,%S_file_name,%i,%s);",
178 Fmap
->class_name
, (optimized
? IDexp("repl__") : exp
),
179 Fmap
->class_name
, current_rule_line(), current_rule_text()
181 pr ("%^ r__ = 1; goto replacement__; }");
184 ///////////////////////////////////////////////////////////////////////////////
186 // Method to generate a failrewrite statement.
188 ///////////////////////////////////////////////////////////////////////////////
189 void RewritingCompiler::gen_failrewrite (MatchRuleInfo::RewritingMode
)
191 pr("%^{ ++o__; goto accept__; }");
194 ///////////////////////////////////////////////////////////////////////////////
196 // Method to generate a cut/replacement statement
198 ///////////////////////////////////////////////////////////////////////////////
199 void RewritingCompiler::gen_cutreplacement
200 (Exp exp
, MatchRuleInfo::RewritingMode mode
)
202 { error("%Lcutrewrite is not used within a rewrite class: cutrewrite %e\n",
206 if (Fmap
->is_applicative
)
208 pr("%^{ s__ = 0; return redex; }");
210 pr("%^{ s__ = 0; return DEBUG_%S(%e,redex,%S_file_name,%i,%s); }",
211 Fmap
->class_name
, exp
, Fmap
->class_name
,
212 current_rule_line(), current_rule_text());
215 pr("%^{ s__ = 0; return; }");
217 pr("%^{ s__ = 0; redex = DEBUG_%S(%e,redex);"
219 Fmap
->class_name
, exp
, Fmap
->class_name
,
220 current_rule_line(), current_rule_text());
223 #line 165 "rwgen4.pcc"
225 ------------------------------- Statistics -------------------------------
226 Merge matching rules = yes
227 Number of DFA nodes merged = 71
228 Number of ifs generated = 3
229 Number of switches generated = 2
232 Adaptive matching = enabled
233 Fast string matching = disabled
234 Inline downcasts = enabled
235 --------------------------------------------------------------------------