gcc config
[prop.git] / prop-src / rwgen2.cc
blob8f2b380c2925e4621c774ae5b77c01b67e2bedb3
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 "rwgen2.pcc".
5 ///////////////////////////////////////////////////////////////////////////////
7 #define PROP_QUARK_USED
8 #include <propdefs.h>
9 ///////////////////////////////////////////////////////////////////////////////
10 // Quark literals
11 ///////////////////////////////////////////////////////////////////////////////
12 static const Quark _r_w_g_e_n_2co_c_c_Q2("() {}\n");
13 static const Quark _r_w_g_e_n_2co_c_c_Q1("\npublic:\n inline ");
14 #line 1 "rwgen2.pcc"
15 ///////////////////////////////////////////////////////////////////////////////
17 // This file implements the 'rewrite (x) { ... }' construct.
18 // We'll transform this construct into the equivalent 'rewrite class ...'
19 // and 'rewrite id { ... };' statements.
21 ///////////////////////////////////////////////////////////////////////////////
22 #include <iostream>
23 #include "ir.h"
24 #include "ast.h"
25 #include "type.h"
26 #include "rwgen.h"
27 #include "options.h"
29 ///////////////////////////////////////////////////////////////////////////////
31 // Method for compiling a 'rewrite (x) { ... }' statement.
33 ///////////////////////////////////////////////////////////////////////////////
34 void RewritingCompiler::gen_rewriting
35 ( Protocols protocols,
36 Exp exp,
37 Exp dest,
38 RewriteIndexings Is,
39 MatchRules rules,
40 TyQual qualifiers
42 { MEM::use_global_pools();
43 Id rewriter_name = Quark(options.mangled_file_prefix,vars.new_label());
44 Ty exp_ty = NOty;
45 Ty ret_ty = NOty;
46 TyQual qual =
47 (qualifiers & ~QUALapplicative) |
48 (dest == NOexp ? QUALnone : QUALapplicative);
50 // Get the return and argument types
52 #line 37 "rwgen2.pcc"
53 #line 40 "rwgen2.pcc"
55 if (dest) {
56 if (protocols) {
57 L1:;
58 L2:;
59 #line 39 "rwgen2.pcc"
60 exp_ty = ret_ty = protocols->_1->ty;
61 #line 39 "rwgen2.pcc"
62 } else {
63 L3:;
64 #line 40 "rwgen2.pcc"
65 error("%Lempty type list in rewrite (...) ...");
66 #line 40 "rwgen2.pcc"
68 } else {
69 if (protocols) {
70 #line 38 "rwgen2.pcc"
71 exp_ty = protocols->_1->ty; ret_ty = void_ty;
72 #line 38 "rwgen2.pcc"
73 } else { goto L3; }
76 #line 41 "rwgen2.pcc"
77 #line 41 "rwgen2.pcc"
80 // If it is destructive, use call by reference
81 if (! (qual & QUALapplicative)) exp_ty = mkrefty(exp_ty);
83 // Print the interface to the auxiliary function
84 pr("%+%^extern %t %s_rewrite(%t);", ret_ty, "", rewriter_name, exp_ty, "");
86 // Generate the rewriting call
88 #line 50 "rwgen2.pcc"
89 #line 52 "rwgen2.pcc"
91 if (dest) {
92 #line 52 "rwgen2.pcc"
93 pr("%^%e = %s_rewrite(%e);", dest, rewriter_name, exp);
94 #line 52 "rwgen2.pcc"
95 } else {
96 #line 51 "rwgen2.pcc"
97 pr("%^%s_rewrite(%e);", rewriter_name, exp);
98 #line 51 "rwgen2.pcc"
101 #line 53 "rwgen2.pcc"
102 #line 53 "rwgen2.pcc"
105 pr("%-");
107 // Add to the list of outstanding rewriting classes
108 Decl body = OPAQUEdecl(
110 #line 59 "rwgen2.pcc"
111 #line 59 "rwgen2.pcc"
112 _r_w_g_e_n_2co_c_c_Q1
113 #line 59 "rwgen2.pcc"
114 #line 59 "rwgen2.pcc"
115 + rewriter_name +
116 #line 59 "rwgen2.pcc"
117 #line 59 "rwgen2.pcc"
118 _r_w_g_e_n_2co_c_c_Q2
119 #line 59 "rwgen2.pcc"
120 #line 59 "rwgen2.pcc"
122 Decl new_def =
123 CLASSDEFdecl(new RewriteClass(rewriter_name,protocols,
124 #line 61 "rwgen2.pcc"
125 #line 61 "rwgen2.pcc"
126 nil_1_
127 #line 61 "rwgen2.pcc"
128 #line 61 "rwgen2.pcc"
129 ,qual,
130 #line 61 "rwgen2.pcc"
131 #line 61 "rwgen2.pcc"
132 list_1_(body)
133 #line 61 "rwgen2.pcc"
134 #line 61 "rwgen2.pcc"
136 rewriters =
137 #line 62 "rwgen2.pcc"
138 #line 62 "rwgen2.pcc"
139 list_1_(new_def,list_1_(REWRITEdecl(rewriter_name,Is,rules),rewriters))
140 #line 62 "rwgen2.pcc"
141 #line 62 "rwgen2.pcc"
143 MEM::use_local_pools();
146 ///////////////////////////////////////////////////////////////////////////////
148 // Method for compiling rewrite classes for the 'rewrite (...) { ... }'
149 // construct.
151 ///////////////////////////////////////////////////////////////////////////////
152 void RewritingCompiler::gen_rewriters()
154 debug_msg("[Generating the rewriters in this file]\n");
155 for_each (Decl, d, rewriters)
156 { pr ("%D", d);
158 #line 77 "rwgen2.pcc"
159 #line 111 "rwgen2.pcc"
161 if (d) {
162 switch (d->tag__) {
163 case a_Decl::tag_CLASSDEFdecl: {
164 if (
165 #line 78 "rwgen2.pcc"
166 ((((Decl_CLASSDEFdecl *)d)->CLASSDEFdecl->class_type == ClassDefinition::REWRITE_CLASS) && ((Decl_CLASSDEFdecl *)d)->CLASSDEFdecl->protocols)
167 #line 80 "rwgen2.pcc"
170 #line 81 "rwgen2.pcc"
171 Id id = ((Decl_CLASSDEFdecl *)d)->CLASSDEFdecl->class_name;
172 Ty ty = ((Decl_CLASSDEFdecl *)d)->CLASSDEFdecl->protocols->_1->ty;
173 TyQual qual = ((Decl_CLASSDEFdecl *)d)->CLASSDEFdecl->qualifiers;
174 // If it is destructive, use call by reference
175 Bool is_applicative = qual & QUALapplicative;
176 Bool do_traversal = qual & QUALtreeparser;
177 Ty exp_ty = is_applicative ? ty : mkrefty(ty);
178 Ty ret_ty = is_applicative ? ty : void_ty;
180 // protocol
181 pr ("%^%t %s_rewrite(%t _x_) ", ret_ty, "", id, exp_ty, "");
182 // declare the rewriter
183 pr ("%^{ %s _r_;", id);
184 // call the labeler
185 if (do_traversal)
186 { if (is_applicative)
187 { pr ("%^ return _r_.reduce(_r_(_x_));"); }
188 else
189 { pr ("%^ _r_(_x_); %s_r_.reduce(_x_);",
190 ret_ty == void_ty ? "" : "return ");
192 } else
193 { if (is_applicative)
194 { pr ("%^ return _r_(_x_);"); }
195 else
196 { pr ("%^ _r_(_x_);"); }
198 pr ("%^}\n\n");
200 #line 109 "rwgen2.pcc"
201 } else {
203 L4:; }
204 } break;
205 default: { goto L4; } break;
207 } else { goto L4; }
209 #line 111 "rwgen2.pcc"
210 #line 111 "rwgen2.pcc"
213 debug_msg("[Finished generating the rewriters in this file]\n");
215 #line 115 "rwgen2.pcc"
217 ------------------------------- Statistics -------------------------------
218 Merge matching rules = yes
219 Number of DFA nodes merged = 287
220 Number of ifs generated = 6
221 Number of switches generated = 1
222 Number of labels = 4
223 Number of gotos = 3
224 Adaptive matching = enabled
225 Fast string matching = disabled
226 Inline downcasts = enabled
227 --------------------------------------------------------------------------