with debug
[prop.git] / prop-src / compiler.cc
blob38d99ebf11e5ce0be292576aab6c0d2e2b31b47b
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 "compiler.pcc".
5 ///////////////////////////////////////////////////////////////////////////////
7 #line 1 "compiler.pcc"
8 ///////////////////////////////////////////////////////////////////////////////
9 //
10 // The file implements the class Compiler and this is the main entry
11 // point of the Prop -> C++ translator.
13 ///////////////////////////////////////////////////////////////////////////////
14 #include <iostream>
15 #include "ir.h"
16 #include "ast.h"
17 #include "type.h"
18 #include "compiler.h"
19 #include "options.h"
21 ///////////////////////////////////////////////////////////////////////////////
23 // Constructor and destructor
25 ///////////////////////////////////////////////////////////////////////////////
26 Compiler:: Compiler(TyOpt opt, int embedded_tags)
27 : DatatypeCompiler (opt,embedded_tags) {}
28 Compiler::~Compiler() {}
30 ///////////////////////////////////////////////////////////////////////////////
32 // Emit header info
34 ///////////////////////////////////////////////////////////////////////////////
35 void Compiler::emit_header(const char * text, int n) { header.emit(text,n); }
36 void Compiler::emit_header_text()
37 { const char * header_text = header.text();
38 if (header_text) pr("%s",header_text);
41 ///////////////////////////////////////////////////////////////////////////////
43 // Additional printing method
45 ///////////////////////////////////////////////////////////////////////////////
46 va_list Compiler::printer(char fmt, va_list arg)
48 #line 40 "compiler.pcc"
49 #line 44 "compiler.pcc"
51 switch (fmt) {
52 case '&': {
53 #line 42 "compiler.pcc"
54 gen(va_arg(arg,Decls));
55 #line 42 "compiler.pcc"
56 } break;
57 case 'D': {
58 #line 43 "compiler.pcc"
59 gen(va_arg(arg,Decl));
60 #line 43 "compiler.pcc"
61 } break;
62 case 'm': {
63 #line 41 "compiler.pcc"
64 MatchCompiler::gen(va_arg(arg,Match));
65 #line 41 "compiler.pcc"
66 } break;
67 default: {
68 #line 44 "compiler.pcc"
69 bug("undefined print format '%%%c'\n", (int)fmt);
70 #line 44 "compiler.pcc"
74 #line 45 "compiler.pcc"
75 #line 45 "compiler.pcc"
77 return arg;
80 ///////////////////////////////////////////////////////////////////////////////
82 // Top level code generation method
84 ///////////////////////////////////////////////////////////////////////////////
85 void Compiler::generate(Decls ds)
87 // generate the quark literals
88 if (quark_map.size() > 0)
89 { pr ("%^%/"
90 "%^// Quark literals"
91 "%^%/");
92 foreach_entry (e, quark_map)
93 { Id name = (Id)quark_map.key(e);
94 Id quark = (Id)quark_map.value(e);
95 pr ("%^static const Quark %s(%s);\n", quark, name);
99 // now generate the main program.
100 gen(ds);
102 // finally, generate any outstanding rewriters
103 gen_rewriters();
105 // if the visualization is on then print GDL
106 if (options.visualization) print_definitions_as_GDL();
109 ///////////////////////////////////////////////////////////////////////////////
111 // Method to generate a list of declarations.
113 ///////////////////////////////////////////////////////////////////////////////
114 void Compiler::gen(Decls ds)
115 { Bool line_prefix = true;
116 Bool line_suffix = true;
118 #line 86 "compiler.pcc"
119 #line 94 "compiler.pcc"
121 for (;;) {
122 if (ds) {
123 #line 88 "compiler.pcc"
125 #line 88 "compiler.pcc"
126 #line 90 "compiler.pcc"
128 Decl _V1 = ds->_1;
129 if (_V1) {
130 switch (_V1->tag__) {
131 case a_Decl::tag_TYPEEXPdecl: {
132 #line 89 "compiler.pcc"
133 line_suffix = line_prefix; line_prefix = false;
134 #line 89 "compiler.pcc"
135 } break;
136 default: {
137 L2:;
138 #line 90 "compiler.pcc"
139 line_suffix = line_prefix; line_prefix = true;
140 #line 90 "compiler.pcc"
141 } break;
143 } else { goto L2; }
145 #line 91 "compiler.pcc"
146 #line 91 "compiler.pcc"
148 gen(ds->_1,line_prefix,line_suffix);
149 ds = ds->_2;
151 #line 94 "compiler.pcc"
152 } else { goto L1; }
154 L1:;
156 #line 95 "compiler.pcc"
157 #line 95 "compiler.pcc"
161 ///////////////////////////////////////////////////////////////////////////////
163 // Method to generate one declaration.
165 ///////////////////////////////////////////////////////////////////////////////
166 void Compiler::gen(Decl d, Bool line_prefix, Bool line_suffix)
168 #line 104 "compiler.pcc"
169 #line 175 "compiler.pcc"
171 if (d) {
172 switch (d->tag__) {
173 case a_Decl::tag_OPAQUEdecl: {
174 #line 106 "compiler.pcc"
175 pr ("%C",((Decl_OPAQUEdecl *)d)->OPAQUEdecl);
176 #line 106 "compiler.pcc"
177 } break;
178 case a_Decl::tag_DATATYPEdecl: {
179 #line 107 "compiler.pcc"
180 gen_datatype(((Decl_DATATYPEdecl *)d)->_1,((Decl_DATATYPEdecl *)d)->_2,((Decl_DATATYPEdecl *)d)->_3,((Decl_DATATYPEdecl *)d)->_4);
181 #line 107 "compiler.pcc"
182 } break;
183 case a_Decl::tag_INSTANTIATEdecl: {
184 #line 108 "compiler.pcc"
185 instantiate_datatypes(((Decl_INSTANTIATEdecl *)d)->_1,((Decl_INSTANTIATEdecl *)d)->_2);
186 #line 108 "compiler.pcc"
187 } break;
188 case a_Decl::tag_CLASSDEFdecl: {
189 #line 123 "compiler.pcc"
190 ((Decl_CLASSDEFdecl *)d)->CLASSDEFdecl->gen_class_definition(*this);
191 #line 123 "compiler.pcc"
192 } break;
193 case a_Decl::tag_INFERENCEdecl: {
194 #line 115 "compiler.pcc"
195 gen_inference_rules(((Decl_INFERENCEdecl *)d)->_1, ((Decl_INFERENCEdecl *)d)->_2);
196 #line 115 "compiler.pcc"
197 } break;
198 case a_Decl::tag_REWRITEdecl: {
199 #line 109 "compiler.pcc"
200 gen_rewrite(((Decl_REWRITEdecl *)d)->_1, ((Decl_REWRITEdecl *)d)->_2, ((Decl_REWRITEdecl *)d)->_3);
201 #line 109 "compiler.pcc"
202 } break;
203 case a_Decl::tag_REWRITINGdecl: {
204 #line 110 "compiler.pcc"
205 gen_rewriting(((Decl_REWRITINGdecl *)d)->_1,((Decl_REWRITINGdecl *)d)->_2,((Decl_REWRITINGdecl *)d)->_3,((Decl_REWRITINGdecl *)d)->_4,((Decl_REWRITINGdecl *)d)->_5,((Decl_REWRITINGdecl *)d)->_6);
206 #line 110 "compiler.pcc"
207 } break;
208 case a_Decl::tag_REPLACEMENTdecl: {
209 #line 119 "compiler.pcc"
210 gen_replacement(((Decl_REPLACEMENTdecl *)d)->_1,((Decl_REPLACEMENTdecl *)d)->_2);
211 #line 119 "compiler.pcc"
212 } break;
213 case a_Decl::tag_CUTREWRITEdecl: {
214 #line 120 "compiler.pcc"
215 gen_cutreplacement(((Decl_CUTREWRITEdecl *)d)->_1,((Decl_CUTREWRITEdecl *)d)->_2);
216 #line 120 "compiler.pcc"
217 } break;
218 case a_Decl::tag_FAILREWRITEdecl: {
219 #line 121 "compiler.pcc"
220 gen_failrewrite(((Decl_FAILREWRITEdecl *)d)->FAILREWRITEdecl);
221 #line 121 "compiler.pcc"
222 } break;
223 case a_Decl::tag_INJECTdecl: {
224 if (((Decl_INJECTdecl *)d)->direction) {
226 #line 154 "compiler.pcc"
227 pr (" if (i__) insert_alpha(%i,fact__); else remove_alpha(%i,fact__); ",
228 ((Decl_INJECTdecl *)d)->node_number, ((Decl_INJECTdecl *)d)->node_number);
229 #line 155 "compiler.pcc"
230 } else {
232 #line 157 "compiler.pcc"
233 pr (" if (i__) insert_beta(%i,f__); else remove_beta(%i,f__); ",
234 ((Decl_INJECTdecl *)d)->node_number, ((Decl_INJECTdecl *)d)->node_number);
235 #line 158 "compiler.pcc"
237 } break;
238 case a_Decl::tag_GOTOdecl: {
239 #line 151 "compiler.pcc"
240 pr ("%^goto %s;\n", ((Decl_GOTOdecl *)d)->GOTOdecl);
241 #line 151 "compiler.pcc"
242 } break;
243 case a_Decl::tag_SETSTATEdecl: {
244 #line 152 "compiler.pcc"
245 pr ("s__ = %i;", ((Decl_SETSTATEdecl *)d)->SETSTATEdecl);
246 #line 152 "compiler.pcc"
247 } break;
248 case a_Decl::tag_SYNTAXdecl: {
249 #line 113 "compiler.pcc"
250 gen_parser(((Decl_SYNTAXdecl *)d)->_1,((Decl_SYNTAXdecl *)d)->_2);
251 #line 113 "compiler.pcc"
252 } break;
253 case a_Decl::tag_ATTRIBUTEGRAMMARdecl: {
254 #line 114 "compiler.pcc"
255 gen_attribute_grammar(((Decl_ATTRIBUTEGRAMMARdecl *)d)->_1,((Decl_ATTRIBUTEGRAMMARdecl *)d)->_2);
256 #line 114 "compiler.pcc"
257 } break;
258 case a_Decl::tag_FUNdecl: {
259 #line 111 "compiler.pcc"
260 gen_fun_def(((Decl_FUNdecl *)d)->FUNdecl);
261 #line 111 "compiler.pcc"
262 } break;
263 case a_Decl::tag_MATCHdecl: {
264 #line 112 "compiler.pcc"
265 gen_match_stmt(((Decl_MATCHdecl *)d)->_1,((Decl_MATCHdecl *)d)->_2,((Decl_MATCHdecl *)d)->_3,((Decl_MATCHdecl *)d)->_4);
266 #line 112 "compiler.pcc"
267 } break;
268 case a_Decl::tag_SETLSTMTdecl: {
269 #line 116 "compiler.pcc"
270 gen_setl(((Decl_SETLSTMTdecl *)d)->SETLSTMTdecl);
271 #line 116 "compiler.pcc"
272 } break;
273 case a_Decl::tag_SETLDEFdecl: {
274 #line 117 "compiler.pcc"
275 gen_setl(((Decl_SETLDEFdecl *)d)->SETLDEFdecl);
276 #line 117 "compiler.pcc"
277 } break;
278 case a_Decl::tag_CLASSOFdecl: {
279 #line 125 "compiler.pcc"
281 #line 125 "compiler.pcc"
282 #line 147 "compiler.pcc"
284 Ty _V2 = lookup_ty(((Decl_CLASSOFdecl *)d)->CLASSOFdecl);
285 if (_V2) {
286 switch (_V2->tag__) {
287 case a_Ty::tag_TYCONty: {
288 if (boxed(((Ty_TYCONty *)_V2)->_1)) {
289 switch (((Ty_TYCONty *)_V2)->_1->tag__) {
290 case a_TyCon::tag_DATATYPEtycon: {
291 #line 127 "compiler.pcc"
292 pr ("a_%s", ((TyCon_DATATYPEtycon *)((Ty_TYCONty *)_V2)->_1)->id);
293 #line 127 "compiler.pcc"
294 } break;
295 default: {
296 L3:;
297 #line 147 "compiler.pcc"
298 error ("%Ltype %s has unknown class: %T\n",((Decl_CLASSOFdecl *)d)->CLASSOFdecl, _V2);
299 #line 147 "compiler.pcc"
300 } break;
302 } else { goto L3; }
303 } break;
304 default: { goto L3; } break;
306 } else {
307 #line 129 "compiler.pcc"
309 #line 129 "compiler.pcc"
310 #line 143 "compiler.pcc"
312 Cons _V3 = find_cons(((Decl_CLASSOFdecl *)d)->CLASSOFdecl);
313 if (_V3) {
314 if (
315 #line 132 "compiler.pcc"
316 (_V3->opt & OPTunboxed)
317 #line 132 "compiler.pcc"
320 if (_V3->ty) {
321 #line 133 "compiler.pcc"
322 error ("%Lthe class representation of constructor %s has been elided\n", ((Decl_CLASSOFdecl *)d)->CLASSOFdecl);
323 #line 133 "compiler.pcc"
324 } else {
325 L4:;
326 #line 131 "compiler.pcc"
327 error ("%Lconstructor %s is not a class\n", ((Decl_CLASSOFdecl *)d)->CLASSOFdecl);
328 #line 131 "compiler.pcc"
330 } else {
332 if (_V3->alg_ty) {
333 switch (_V3->alg_ty->tag__) {
334 case a_Ty::tag_TYCONty: {
335 if (_V3->ty) {
336 if (boxed(((Ty_TYCONty *)_V3->alg_ty)->_1)) {
337 switch (((Ty_TYCONty *)_V3->alg_ty)->_1->tag__) {
338 case a_TyCon::tag_DATATYPEtycon: {
339 L5:;
340 #line 139 "compiler.pcc"
341 if (((TyCon_DATATYPEtycon *)((Ty_TYCONty *)_V3->alg_ty)->_1)->opt & OPTsubclassless) pr ("a_%s", ((TyCon_DATATYPEtycon *)((Ty_TYCONty *)_V3->alg_ty)->_1)->id);
342 else pr ("%s_%S", ((TyCon_DATATYPEtycon *)((Ty_TYCONty *)_V3->alg_ty)->_1)->id, _V3->name);
344 #line 141 "compiler.pcc"
345 } break;
346 default: {
347 L6:;
348 #line 143 "compiler.pcc"
349 error ("%Ltype or constructor %s is undefined\n", ((Decl_CLASSOFdecl *)d)->CLASSOFdecl);
350 #line 143 "compiler.pcc"
351 } break;
353 } else { goto L6; }
354 } else { goto L4; }
355 } break;
356 default: {
357 L7:;
358 if (_V3->ty) { goto L6; } else { goto L4; }
359 } break;
361 } else { goto L7; }
363 } else { goto L6; }
365 #line 144 "compiler.pcc"
366 #line 144 "compiler.pcc"
369 #line 145 "compiler.pcc"
372 #line 148 "compiler.pcc"
373 #line 148 "compiler.pcc"
376 #line 149 "compiler.pcc"
377 } break;
378 case a_Decl::tag_TYPEEXPdecl: {
379 #line 150 "compiler.pcc"
380 pr ("%t", ((Decl_TYPEEXPdecl *)d)->TYPEEXPdecl,"");
381 #line 150 "compiler.pcc"
382 } break;
383 case a_Decl::tag_EXPdecl: {
384 if (((Decl_EXPdecl *)d)->exp) {
385 switch (((Decl_EXPdecl *)d)->exp->tag__) {
386 case a_Exp::tag_THISSYNexp:
387 case a_Exp::tag_SYNexp: {
388 #line 164 "compiler.pcc"
389 pr ("%e", ((Decl_EXPdecl *)d)->exp);
390 #line 164 "compiler.pcc"
391 } break;
392 default: {
393 L8:;
394 #line 166 "compiler.pcc"
395 pr ("%^%s%e%s", (((Decl_EXPdecl *)d)->prefix ? ((Decl_EXPdecl *)d)->prefix : ""),((Decl_EXPdecl *)d)->exp, (((Decl_EXPdecl *)d)->suffix ? ((Decl_EXPdecl *)d)->suffix : ""));
396 #line 166 "compiler.pcc"
397 } break;
399 } else { goto L8; }
400 } break;
401 case a_Decl::tag_MARKEDdecl: {
402 #line 168 "compiler.pcc"
403 line = ((Decl_MARKEDdecl *)d)->_1.begin_line;
404 file = ((Decl_MARKEDdecl *)d)->_1.file_name;
405 if (line_prefix) pr ("%#",line,file);
406 gen(((Decl_MARKEDdecl *)d)->_2);
407 line = ((Decl_MARKEDdecl *)d)->_1.end_line;
408 if (line_suffix) pr ("%#",line,file);
410 #line 174 "compiler.pcc"
411 } break;
412 default: {
413 #line 175 "compiler.pcc"
414 bug("Unimplemented feature");
415 #line 175 "compiler.pcc"
416 } break;
418 } else {
419 #line 105 "compiler.pcc"
420 /* skip */
421 #line 105 "compiler.pcc"
424 #line 176 "compiler.pcc"
425 #line 176 "compiler.pcc"
429 ///////////////////////////////////////////////////////////////////////////////
431 // Method to generate a report.
433 ///////////////////////////////////////////////////////////////////////////////
434 std::ostream& Compiler::print_report(std::ostream& f)
435 { f <<
436 "------------------------------- Statistics -------------------------------"
437 << "\nMerge matching rules = " << (options.merge_match ? "yes" : "no")
438 << "\nNumber of DFA nodes merged = " << merges
439 << "\nNumber of ifs generated = " << ifs
440 << "\nNumber of switches generated = " << switches
441 << "\nNumber of labels = " << goto_labels
442 << "\nNumber of gotos = " << gotos
443 << "\nAdaptive matching = " << (options.adaptive_matching ? "enabled" : "disabled")
444 << "\nFast string matching = " << (options.fast_string_match ? "enabled" : "disabled")
445 << "\nInline downcasts = " << (options.inline_casts ? "enabled" : "disabled")
446 << "\n"
447 "--------------------------------------------------------------------------"
448 "\n"
450 return f;
452 #line 202 "compiler.pcc"
454 ------------------------------- Statistics -------------------------------
455 Merge matching rules = yes
456 Number of DFA nodes merged = 398
457 Number of ifs generated = 14
458 Number of switches generated = 8
459 Number of labels = 7
460 Number of gotos = 10
461 Adaptive matching = enabled
462 Fast string matching = disabled
463 Inline downcasts = enabled
464 --------------------------------------------------------------------------