typename fix
[prop.git] / prop-src / parser-util.cc
blobdcb103fca18ae4d22dbbd2fceda7726d76dcdc7d
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 "parser-util.pcc".
5 ///////////////////////////////////////////////////////////////////////////////
7 #define PROP_PRINTER_USED
8 #define PROP_REGEXP_MATCHING_USED
9 #define PROP_PARSER_USED
10 #define PROP_QUARK_USED
11 #include <propdefs.h>
12 ///////////////////////////////////////////////////////////////////////////////
13 // Quark literals
14 ///////////////////////////////////////////////////////////////////////////////
15 static const Quark _p_a_r_s_e_rcn_u_t_i_lco_c_c_Q1("$$");
16 static const Quark _p_a_r_s_e_rcn_u_t_i_lco_c_c_Q2("$");
17 #line 1 "parser-util.pcc"
18 ///////////////////////////////////////////////////////////////////////////////
20 // This file implements the utility routines for the parser.
22 ///////////////////////////////////////////////////////////////////////////////
23 #include <new>
24 #include <iostream>
25 #include <AD/pretty/postream.h>
26 #include <strstream>
27 #include <string.h>
28 #include <stdlib.h>
29 #include "ir.h"
30 #include "ast.h"
31 #include "parser.h"
32 #include "type.h"
33 #include "matchcom.h"
34 #include "keywords.h"
35 #include "config.h"
36 #include "list.h"
37 #include "compiler.h"
38 #include "options.h"
40 ///////////////////////////////////////////////////////////////////////////////
42 // Explaination mechanism for parser error.
44 ///////////////////////////////////////////////////////////////////////////////
45 #line 28 "parser-util.pcc"
46 #line 28 "parser-util.pcc"
47 ///////////////////////////////////////////////////////////////////////////////
49 // Interface specification of datatype PropToken
51 ///////////////////////////////////////////////////////////////////////////////
52 #line 28 "parser-util.pcc"
53 ///////////////////////////////////////////////////////////////////////////////
55 // Pretty printing methods for PropToken
57 ///////////////////////////////////////////////////////////////////////////////
58 std::ostream& operator << (std::ostream& strm__, PropToken obj__);
59 PrettyOStream& operator << (PrettyOStream& strm__, PropToken obj__);
61 ///////////////////////////////////////////////////////////////////////////////
63 // Instantiation of datatype PropToken
65 ///////////////////////////////////////////////////////////////////////////////
66 #line 28 "parser-util.pcc"
67 ///////////////////////////////////////////////////////////////////////////////
69 // Pretty printing methods for PropToken
71 ///////////////////////////////////////////////////////////////////////////////
72 std::ostream& operator << (std::ostream& strm__, PropToken obj__)
73 { PrettyOStream S(strm__); S << obj__; return strm__; }
75 PrettyOStream& operator << (PrettyOStream& strm__, PropToken obj__)
77 switch (obj__)
79 case XX_r_e_w_r_i_t_eXX:
80 strm__ << "rewrite";
81 break;
82 case XX_i_n_f_e_r_e_n_c_eXX:
83 strm__ << "inference";
84 break;
85 case XX_m_a_t_c_hXX:
86 strm__ << "match";
87 break;
88 case XX_m_a_t_c_h_a_l_lXX:
89 strm__ << "matchall";
90 break;
91 case XX_m_a_t_c_h_s_c_a_nXX:
92 strm__ << "matchscan";
93 break;
94 case XX_r_e_f_i_n_eXX:
95 strm__ << "refine";
96 break;
97 case XX_c_l_a_s_s_o_fXX:
98 strm__ << "classof";
99 break;
100 case XX_t_y_p_eXX:
101 strm__ << "type";
102 break;
103 case XX_d_a_t_a_t_y_p_eXX:
104 strm__ << "datatype";
105 break;
106 case XX_i_n_s_t_a_n_t_i_a_t_eXX:
107 strm__ << "instantiate";
108 break;
109 case XX_l_e_x_e_m_eXX:
110 strm__ << "lexeme";
111 break;
112 case XX_b_i_t_f_i_e_l_dXX:
113 strm__ << "bitfield";
114 break;
115 case XX_b_e_g_i_nXX:
116 strm__ << "begin";
117 break;
118 case XX_s_y_n_t_a_xXX:
119 strm__ << "syntax";
120 break;
121 case XX_d_a_t_a_f_l_o_wXX:
122 strm__ << "dataflow";
123 break;
124 case XX_m_o_d_u_l_eXX:
125 strm__ << "module";
126 break;
127 case XX_s_i_g_n_a_t_u_r_eXX:
128 strm__ << "signature";
129 break;
130 case XX_c_o_n_s_t_r_a_i_n_tXX:
131 strm__ << "constraint";
132 break;
133 case XX_d_e_c_l_a_r_eXX:
134 strm__ << "declare";
135 break;
136 case XX_p_r_o_c_e_d_u_r_eXX:
137 strm__ << "procedure";
138 break;
139 case XX_f_u_nXX:
140 strm__ << "fun";
141 break;
142 case XX_f_u_n_c_t_i_o_nXX:
143 strm__ << "function";
144 break;
145 case XX_g_r_a_p_h_t_y_p_eXX:
146 strm__ << "graphtype";
147 break;
148 case XX_g_r_a_p_h_r_e_w_r_i_t_eXX:
149 strm__ << "graphrewrite";
150 break;
151 case XX_c_u_t_r_e_w_r_i_t_eXX:
152 strm__ << "cutrewrite";
153 break;
154 case XX_f_a_i_l_r_e_w_r_i_t_eXX:
155 strm__ << "failrewrite";
156 break;
157 case XX_a_t_t_r_i_b_u_t_e_g_r_a_m_m_a_rXX:
158 strm__ << "attributegrammar";
159 break;
160 case XX_i_fXX:
161 strm__ << "if";
162 break;
163 case XX_t_h_e_nXX:
164 strm__ << "then";
165 break;
166 case XX_e_l_s_eXX:
167 strm__ << "else";
168 break;
169 case XX_e_l_s_i_fXX:
170 strm__ << "elsif";
171 break;
172 case XX_w_h_i_l_eXX:
173 strm__ << "while";
174 break;
175 case XX_l_o_o_pXX:
176 strm__ << "loop";
177 break;
178 case XX_i_sXX:
179 strm__ << "is";
180 break;
181 case XX_c_l_a_s_sXX:
182 strm__ << "class";
183 break;
184 case XX_u_n_i_f_i_a_b_l_eXX:
185 strm__ << "unifiable";
186 break;
187 case XX_o_fXX:
188 strm__ << "of";
189 break;
190 case XX_d_oXX:
191 strm__ << "do";
192 break;
193 case XX_b_r_e_a_kXX:
194 strm__ << "break";
195 break;
196 case XX_c_o_n_t_i_n_u_eXX:
197 strm__ << "continue";
198 break;
199 case XX_g_o_t_oXX:
200 strm__ << "goto";
201 break;
202 case XX_w_h_e_r_eXX:
203 strm__ << "where";
204 break;
205 case XX_a_sXX:
206 strm__ << "as";
207 break;
208 case XX_p_u_b_l_i_cXX:
209 strm__ << "public";
210 break;
211 case XX_p_r_o_t_e_c_t_e_dXX:
212 strm__ << "protected";
213 break;
214 case XX_p_r_i_v_a_t_eXX:
215 strm__ << "private";
216 break;
217 case XX_c_o_n_s_tXX:
218 strm__ << "const";
219 break;
220 case XX_e_x_t_e_r_nXX:
221 strm__ << "extern";
222 break;
223 case XX_m_u_t_a_b_l_eXX:
224 strm__ << "mutable";
225 break;
226 case XX_a_p_p_l_i_c_a_t_i_v_eXX:
227 strm__ << "applicative";
228 break;
229 case XX_v_i_r_t_u_a_lXX:
230 strm__ << "virtual";
231 break;
232 case XX_t_r_u_eXX:
233 strm__ << "true";
234 break;
235 case XX_f_a_l_s_eXX:
236 strm__ << "false";
237 break;
238 case XX_c_o_l_l_e_c_t_a_b_l_eXX:
239 strm__ << "collectable";
240 break;
241 case XX_f_i_n_a_l_i_z_a_b_l_eXX:
242 strm__ << "finalizable";
243 break;
244 case XX_p_r_i_n_t_a_b_l_eXX:
245 strm__ << "printable";
246 break;
247 case XX_t_r_a_c_e_dXX:
248 strm__ << "traced";
249 break;
250 case XX_p_e_r_s_i_s_t_e_n_tXX:
251 strm__ << "persistent";
252 break;
253 case XX_t_r_e_e_p_a_r_s_e_rXX:
254 strm__ << "treeparser";
255 break;
256 case XX_i_n_l_i_n_eXX:
257 strm__ << "inline";
258 break;
259 case XX_w_i_t_hXX:
260 strm__ << "with";
261 break;
262 case XX_s_w_i_t_c_hXX:
263 strm__ << "switch";
264 break;
265 case XX_u_n_s_i_g_n_e_dXX:
266 strm__ << "unsigned";
267 break;
268 case XX_s_i_g_n_e_dXX:
269 strm__ << "signed";
270 break;
271 case XX_f_o_rXX:
272 strm__ << "for";
273 break;
274 case XX_c_a_t_e_g_o_r_yXX:
275 strm__ << "category";
276 break;
277 case XX_f_u_n_c_t_o_rXX:
278 strm__ << "functor";
279 break;
280 case XX_f_e_a_t_u_r_eXX:
281 strm__ << "feature";
282 break;
283 case XX_s_h_a_r_i_n_gXX:
284 strm__ << "sharing";
285 break;
286 case XX_r_e_l_a_t_i_o_nXX:
287 strm__ << "relation";
288 break;
289 case XX_v_i_e_wXX:
290 strm__ << "view";
291 break;
292 case XX_i_n_h_e_r_i_t_e_dXX:
293 strm__ << "inherited";
294 break;
295 case XX_r_e_t_u_r_nXX:
296 strm__ << "return";
297 break;
298 case XX_s_y_n_t_h_e_s_i_z_e_dXX:
299 strm__ << "synthesized";
300 break;
301 case XX_l_a_wXX:
302 strm__ << "law";
303 break;
304 case XX_l_e_f_tdkXX:
305 strm__ << "left:";
306 break;
307 case XX_r_i_g_h_tdkXX:
308 strm__ << "right:";
309 break;
310 case XX_e_x_p_e_c_tdkXX:
311 strm__ << "expect:";
312 break;
313 case XX_p_r_e_cdkXX:
314 strm__ << "prec:";
315 break;
316 case XX_m_a_p_o_fXX:
317 strm__ << "mapof";
318 break;
319 case XX_s_e_t_o_fXX:
320 strm__ << "setof";
321 break;
322 case XX_b_a_g_o_fXX:
323 strm__ << "bagof";
324 break;
325 case XX_m_u_l_t_i_m_a_p_o_fXX:
326 strm__ << "multimapof";
327 break;
328 case XX_l_i_s_t_o_fXX:
329 strm__ << "listof";
330 break;
331 case XX_p_r_i_q_u_e_u_e_o_fXX:
332 strm__ << "priqueueof";
333 break;
334 case XX_q_u_e_u_e_o_fXX:
335 strm__ << "queueof";
336 break;
337 case XX_d_e_q_u_e_o_fXX:
338 strm__ << "dequeof";
339 break;
340 case XX_t_u_p_l_e_o_fXX:
341 strm__ << "tupleof";
342 break;
343 case XX_f_o_r_a_l_lXX:
344 strm__ << "forall";
345 break;
346 case XX_e_x_i_s_t_sXX:
347 strm__ << "exists";
348 break;
349 case XX_d_o_mXX:
350 strm__ << "dom";
351 break;
352 case XX_r_a_nXX:
353 strm__ << "ran";
354 break;
355 case XX_a_r_bXX:
356 strm__ << "arb";
357 break;
358 case XX_l_e_s_sXX:
359 strm__ << "less";
360 break;
361 case XX_i_n_c_l_u_d_eXX:
362 strm__ << "include";
363 break;
364 case XX_l_f_pXX:
365 strm__ << "lfp";
366 break;
367 case XX_g_f_pXX:
368 strm__ << "gfp";
369 break;
370 case XX_h_o_mXX:
371 strm__ << "hom";
372 break;
373 case XX_i_m_p_l_i_e_sdkXX:
374 strm__ << "implies:";
375 break;
376 case XX_x_o_rdkXX:
377 strm__ << "xor:";
378 break;
379 case XX_e_q_u_i_vdkXX:
380 strm__ << "equiv:";
381 break;
382 case XX_t_i_m_edkXX:
383 strm__ << "time:";
384 break;
385 case XX_s_p_a_c_edkXX:
386 strm__ << "space:";
387 break;
388 case XX_n_o_d_e_sdkXX:
389 strm__ << "nodes:";
390 break;
391 case XX_e_d_g_e_sdkXX:
392 strm__ << "edges:";
393 break;
394 case XX_i_n_d_e_xdkXX:
395 strm__ << "index:";
396 break;
397 case XX_h_a_s_hdkXX:
398 strm__ << "hash:";
399 break;
400 case XX_e_q_u_a_l_i_t_ydkXX:
401 strm__ << "equality:";
402 break;
403 case XX_p_r_e_o_r_d_e_rdkXX:
404 strm__ << "preorder:";
405 break;
406 case XX_p_o_s_t_o_r_d_e_rdkXX:
407 strm__ << "postorder:";
408 break;
409 case XX_b_e_f_o_r_edkXX:
410 strm__ << "before:";
411 break;
412 case XX_t_o_p_d_o_w_ndkXX:
413 strm__ << "topdown:";
414 break;
415 case XX_b_o_t_t_o_m_u_pdkXX:
416 strm__ << "bottomup:";
417 break;
418 case XX_s_t_r_a_t_e_g_ydkXX:
419 strm__ << "strategy:";
420 break;
421 case XX_o_r_d_e_rdkXX:
422 strm__ << "order:";
423 break;
424 case XX_p_r_a_g_m_adkXX:
425 strm__ << "pragma:";
426 break;
427 case XX_c_a_s_eXX:
428 strm__ << "case";
429 break;
430 case XX_a_n_dXX:
431 strm__ << "and";
432 break;
433 case XX_e_n_dXX:
434 strm__ << "end";
435 break;
436 case XXcocoXX:
437 strm__ << "..";
438 break;
439 case XXcococoXX:
440 strm__ << "...";
441 break;
442 case XXdmcndoXX:
443 strm__ << "<->";
444 break;
445 case XXdkdkXX:
446 strm__ << "::";
447 break;
448 case XXcgcgXX:
449 strm__ << "&&";
450 break;
451 case XXhmhmXX:
452 strm__ << "||";
453 break;
454 case XXclclXX:
455 strm__ << "++";
456 break;
457 case XXcncnXX:
458 strm__ << "--";
459 break;
460 case XXcndoXX:
461 strm__ << "->";
462 break;
463 case XXdmdmXX:
464 strm__ << "<<";
465 break;
466 case XXdodoXX:
467 strm__ << ">>";
468 break;
469 case XXdodnXX:
470 strm__ << ">=";
471 break;
472 case XXdmdnXX:
473 strm__ << "<=";
474 break;
475 case XXcldnXX:
476 strm__ << "+=";
477 break;
478 case XXcndnXX:
479 strm__ << "-=";
480 break;
481 case XXckdnXX:
482 strm__ << "*=";
483 break;
484 case XXcpdnXX:
485 strm__ << "/=";
486 break;
487 case XXcfdnXX:
488 strm__ << "%=";
489 break;
490 case XXdndnXX:
491 strm__ << "==";
492 break;
493 case XXcbdnXX:
494 strm__ << "!=";
495 break;
496 case XXdmdmdnXX:
497 strm__ << "<<=";
498 break;
499 case XXdododnXX:
500 strm__ << ">>=";
501 break;
502 case XXcgdnXX:
503 strm__ << "&=";
504 break;
505 case XXhmdnXX:
506 strm__ << "|=";
507 break;
508 case XXfodnXX:
509 strm__ << "^=";
510 break;
511 case XXdndoXX:
512 strm__ << "=>";
513 break;
514 case XXdmcnXX:
515 strm__ << "<-";
516 break;
517 case XXdmdndoXX:
518 strm__ << "<=>";
519 break;
520 case XXdkdnXX:
521 strm__ << ":=";
522 break;
523 case XXdkcnXX:
524 strm__ << ":-";
525 break;
526 case LONG_BAR:
527 strm__ << "LONG_BAR";
528 break;
529 case CONS_TOK:
530 strm__ << "CONS_TOK";
531 break;
532 case DOMAIN_TOK:
533 strm__ << "DOMAIN_TOK";
534 break;
535 case CONS_EXP:
536 strm__ << "CONS_EXP";
537 break;
538 case META_QUOTE:
539 strm__ << "META_QUOTE";
540 break;
541 case POLY_DATATYPE:
542 strm__ << "POLY_DATATYPE";
543 break;
544 case ATTRIB_ID:
545 strm__ << "ATTRIB_ID";
546 break;
547 case XXcihmXX:
548 strm__ << "(|";
549 break;
550 case XXhmcjXX:
551 strm__ << "|)";
552 break;
553 case XXflhmXX:
554 strm__ << "[|";
555 break;
556 case XXhmfnXX:
557 strm__ << "|]";
558 break;
559 case XXhlhmXX:
560 strm__ << "{|";
561 break;
562 case XXhmhnXX:
563 strm__ << "|}";
564 break;
565 case XXcociXX:
566 strm__ << ".(";
567 break;
568 case XXcoflXX:
569 strm__ << ".[";
570 break;
571 case XXgagaXX:
572 strm__ << "``";
573 break;
574 case XXchchXX:
575 strm__ << "''";
576 break;
577 case INT_TOK:
578 strm__ << "INT_TOK";
579 break;
580 case REAL_TOK:
581 strm__ << "REAL_TOK";
582 break;
583 case CHAR_TOK:
584 strm__ << "CHAR_TOK";
585 break;
586 case STRING_TOK:
587 strm__ << "STRING_TOK";
588 break;
589 case ID_TOK:
590 strm__ << "ID_TOK";
591 break;
592 case REGEXP_TOK:
593 strm__ << "REGEXP_TOK";
594 break;
595 case QUARK_TOK:
596 strm__ << "QUARK_TOK";
597 break;
598 case BIGINT_TOK:
599 strm__ << "BIGINT_TOK";
600 break;
601 case PUNCTUATIONS:
602 strm__ << "PUNCTUATIONS";
603 break;
605 return strm__;
610 #line 28 "parser-util.pcc"
611 #line 28 "parser-util.pcc"
614 void PropParser::print_user_symbol(std::ostream& f, Symbol c)
615 { f << '"' << (PropToken)c << '"'; }
617 void PropParser::explain_error()
618 { nice_explain(std::cerr); std::cerr << '\n';
619 if (options.debug) debug_explain(std::cerr);
622 extern int match_rule;
623 ///////////////////////////////////////////////////////////////////////////////
625 // Destructor
627 ///////////////////////////////////////////////////////////////////////////////
628 PropParser::~PropParser() {}
630 ///////////////////////////////////////////////////////////////////////////////
632 // Method to initialize the parser
634 ///////////////////////////////////////////////////////////////////////////////
635 void PropParser::initialize(Compiler& C)
636 { compiler = &C;
637 graphtype_def = 0;
638 SCs_top = 0;
639 quote_top = 0;
640 levels_top = 0;
641 options.emit_code = true;
642 me_top = 0;
643 var_top = 0;
644 antecedent_count = 0;
645 in_rewrite = false;
646 rule_count = 0;
647 is_view_def = false;
648 symbol_count = 0;
649 item_count = 0;
650 nonterm_count = 0;
651 code_top = 0;
652 includes_top = 0;
653 included_count = 0;
654 program =
655 #line 70 "parser-util.pcc"
656 #line 70 "parser-util.pcc"
657 nil_1_
658 #line 70 "parser-util.pcc"
659 #line 70 "parser-util.pcc"
661 my_cons = NOcons;
662 my_exp = NOexp;
663 match_rule = 0;
664 rw_top = -1;
665 push_rw_stack();
668 ///////////////////////////////////////////////////////////////////////////////
669 // Method to push/pop the rw stack
670 ///////////////////////////////////////////////////////////////////////////////
671 void PropParser::push_rw_stack()
672 { ++rw_top;
673 if (rw_top >= MAX_LEXICAL_DEPTH) bug("rw stack overflow");
674 rw_stack[rw_top].mode = MatchRuleInfo::BOTTOMUP;
675 rw_stack[rw_top].option = MatchRuleInfo::NO_OPTIONS;
676 rw_stack[rw_top].qual = QUALnone;
679 void PropParser::pop_rw_stack()
680 { --rw_top;
681 if (rw_top < 0) bug("rw stack underflow");
684 ///////////////////////////////////////////////////////////////////////////////
685 // Functions to mark a tree with the current location.
686 ///////////////////////////////////////////////////////////////////////////////
687 Pat mark(Pat p) { p = MARKEDpat(Loc(),p); return p; }
688 Exp mark(Exp e) { e = MARKEDexp(Loc(),e); return e; }
689 Decl mark(Decl d) { if (d != NOdecl) d = MARKEDdecl(Loc(),d); return d; }
691 ///////////////////////////////////////////////////////////////////////////////
693 // Function to mark tuples used
695 ///////////////////////////////////////////////////////////////////////////////
696 void mark_tuple_used (int arity)
697 { if (arity <= 1 || arity > MAX_TUPLE_ARITY)
698 { bug("Illegal tuple arity: %i", arity); }
699 Used::tuple[arity] = true;
702 ///////////////////////////////////////////////////////////////////////////////
703 // Functions to build lists.
704 ///////////////////////////////////////////////////////////////////////////////
705 Pat mklistpat(Id cons, Id nil, Pats ps, Pat p = NOpat)
706 { return
707 #line 116 "parser-util.pcc"
708 #line 116 "parser-util.pcc"
709 LISTpat(lookup_cons(cons), lookup_cons(nil), ps, p)
710 #line 120 "parser-util.pcc"
711 #line 120 "parser-util.pcc"
714 Pat mkvecpat
715 (Id a, Pat len, Pat array, Pats ps, Bool flex1 = false, Bool flex2 = false)
716 { Used::vector = true;
717 return
718 #line 125 "parser-util.pcc"
719 #line 125 "parser-util.pcc"
720 VECTORpat(lookup_cons(a), len, array, ps, flex1, flex2)
721 #line 131 "parser-util.pcc"
722 #line 131 "parser-util.pcc"
725 Exp mklistexp(Id cons, Id nil, Exps es, Exp e = NOexp)
726 { return LISTexp(lookup_cons(cons), lookup_cons(nil), es, e);
728 Exp mkappexp(Exp a, Exp b)
729 { Cons c = NOcons;
731 match (a) and (b)
732 { IDexp id, RECORDexp _ | c = find_cons(id): { return CONSexp(c,#[],b); }
733 | _: { return APPexp(a,b); }
737 #line 144 "parser-util.pcc"
738 #line 146 "parser-util.pcc"
740 if (a) {
741 switch (a->tag__) {
742 case a_Exp::tag_IDexp: {
743 if (
744 #line 145 "parser-util.pcc"
745 (c = find_cons(((Exp_IDexp *)a)->IDexp))
746 #line 145 "parser-util.pcc"
749 #line 145 "parser-util.pcc"
750 return CONSexp(c,
751 #line 145 "parser-util.pcc"
752 #line 145 "parser-util.pcc"
753 nil_1_
754 #line 145 "parser-util.pcc"
755 #line 145 "parser-util.pcc"
756 ,b);
757 #line 145 "parser-util.pcc"
758 } else {
760 L1:;
761 #line 146 "parser-util.pcc"
762 return APPexp(a,b);
763 #line 146 "parser-util.pcc"
765 } break;
766 default: { goto L1; } break;
768 } else { goto L1; }
770 #line 147 "parser-util.pcc"
771 #line 147 "parser-util.pcc"
774 Exp mkvecexp(Id vec, Exps es)
775 { Used::vector = true;
776 return VECTORexp(lookup_cons(vec), es);
778 TermDef mklistterm(Id c, Ty a, Ty b, Decls d)
779 { //match (b)
780 //{ ! DEFVALty _: { b = DEFVALty(b,LITERALexp(INTlit(0))); }
781 //| _: // skip
783 return
784 #line 158 "parser-util.pcc"
785 #line 158 "parser-util.pcc"
786 TERMdef(c, mktuplety(list_1_(a,list_1_(b))), d, nil_1_, NOpat, nil_1_, OPTnone, QUALnone, NOexp)
787 #line 158 "parser-util.pcc"
788 #line 158 "parser-util.pcc"
792 Exp extupleexp(Exps es) { mark_tuple_used(length(es)); return EXTUPLEexp(es); }
793 Pat extuplepat(Pats ps) { mark_tuple_used(length(ps)); return EXTUPLEpat(ps); }
794 Ty extuplety(Tys ts) { mark_tuple_used(length(ts));
795 return TYCONty(EXTUPLEtycon,ts); }
797 ///////////////////////////////////////////////////////////////////////////////
798 // Function to build a piece of verbatim code.
799 ///////////////////////////////////////////////////////////////////////////////
800 Decls PropParser::mkcode(Decls decls)
801 { if (options.emit_code && scan.length() > 0) {
802 Decl code = OPAQUEdecl(str_pool(scan.text(),scan.length()));
803 decls =
804 #line 172 "parser-util.pcc"
805 #line 172 "parser-util.pcc"
806 list_1_(mark(code),decls)
807 #line 172 "parser-util.pcc"
808 #line 172 "parser-util.pcc"
811 scan.reset();
812 first_line = line;
813 return decls;
816 ///////////////////////////////////////////////////////////////////////////////
818 // Methods to increment the line count
820 ///////////////////////////////////////////////////////////////////////////////
821 void PropParser::count_lines ()
822 { for (const char * p = lexbuf.text(); *p; p++)
823 if (*p == '\n') line++;
826 ///////////////////////////////////////////////////////////////////////////////
827 // Method to lookup an expression from the pattern environment.
828 ///////////////////////////////////////////////////////////////////////////////
829 Exp PropParser::lookup_exp(Id id)
830 { Bool from_current;
831 Exp e = pv_env.lookup(id,&from_current);
833 #line 195 "parser-util.pcc"
834 #line 201 "parser-util.pcc"
836 char _V1 = id[0];
837 if (e) {
838 #line 201 "parser-util.pcc"
839 return e;
840 #line 201 "parser-util.pcc"
841 } else {
842 switch (_V1) {
843 case '#':
844 case '$': {
845 L2:;
846 #line 197 "parser-util.pcc"
847 error ("%Lpattern variable '%s' has no binding at this point\n", id);
848 return NOexp;
850 #line 199 "parser-util.pcc"
851 } break;
852 default: {
853 #line 200 "parser-util.pcc"
854 return IDexp(id);
855 #line 200 "parser-util.pcc"
860 #line 202 "parser-util.pcc"
861 #line 202 "parser-util.pcc"
865 ///////////////////////////////////////////////////////////////////////////////
866 // Type variable stack for building polymorphic type schemes.
867 ///////////////////////////////////////////////////////////////////////////////
868 Ty PropParser::lookup_tyvar(Id id)
869 { for (int i = 0; i < var_top; i++)
870 if (var_stack[i] == id) return INDty(id, i);
871 return mkidty(id,
872 #line 211 "parser-util.pcc"
873 #line 211 "parser-util.pcc"
874 nil_1_
875 #line 211 "parser-util.pcc"
876 #line 211 "parser-util.pcc"
880 Pat PropParser::lookup_patvar(Id id)
881 { for (int i = 0; i < var_top; i++)
882 if (var_stack[i] == id) {
883 return pat_stack[i] == NOpat
884 ? (pat_stack[i] = INDpat(id,i,mkvar())) : pat_stack[i];
886 Pat scheme = DatatypeCompiler::lookup_pat(id);
887 if (scheme != NOpat) {
888 return apply_pat(scheme,NOpat);
889 } else {
890 return IDpat(id,mkvar(),NOexp);
894 ///////////////////////////////////////////////////////////////////////////////
895 // Create a pattern from a constructor
896 ///////////////////////////////////////////////////////////////////////////////
897 Pat PropParser::mkconspat(Cons cons)
899 #line 232 "parser-util.pcc"
900 #line 242 "parser-util.pcc"
902 if (cons) {
903 if (cons->alg_ty) {
904 switch (cons->alg_ty->tag__) {
905 case a_Ty::tag_TYCONty: {
906 if (boxed(((Ty_TYCONty *)cons->alg_ty)->_1)) {
907 switch (((Ty_TYCONty *)cons->alg_ty)->_1->tag__) {
908 case a_TyCon::tag_DATATYPEtycon: {
909 if (
910 #line 235 "parser-util.pcc"
911 ((((TyCon_DATATYPEtycon *)((Ty_TYCONty *)cons->alg_ty)->_1)->qualifiers & QUALlexeme) && (match_kind[me_top] & MATCHscanner))
912 #line 235 "parser-util.pcc"
915 #line 236 "parser-util.pcc"
916 if (cons->lexeme_pattern == NOpat)
917 { error ("%Lpattern is undefined for lexeme %s\n",cons->name);
918 return NOpat;
919 } else
920 { return cons->lexeme_pattern; }
922 #line 241 "parser-util.pcc"
923 } else {
925 L3:;
926 #line 242 "parser-util.pcc"
927 return CONSpat(cons);
928 #line 242 "parser-util.pcc"
930 } break;
931 default: { goto L3; } break;
933 } else { goto L3; }
934 } break;
935 default: { goto L3; } break;
937 } else { goto L3; }
938 } else { goto L3; }
940 #line 243 "parser-util.pcc"
941 #line 243 "parser-util.pcc"
945 ///////////////////////////////////////////////////////////////////////////////
946 // Routine to add a new "$" variable binding
947 ///////////////////////////////////////////////////////////////////////////////
948 void PropParser::add_parse_stack_binding
949 (int item_number, int symbol_number, int nonterm_number)
950 { Ty junk_ty = NOty;
951 if (item_number <= 0)
952 pv_env.add(
953 #line 253 "parser-util.pcc"
954 #line 253 "parser-util.pcc"
955 _p_a_r_s_e_rcn_u_t_i_lco_c_c_Q1
956 #line 253 "parser-util.pcc"
957 #line 253 "parser-util.pcc"
958 ,SYNexp(0,-symbol_number,NOty,false),junk_ty);
959 else
960 pv_env.add(
961 #line 255 "parser-util.pcc"
962 #line 255 "parser-util.pcc"
963 _p_a_r_s_e_rcn_u_t_i_lco_c_c_Q2
964 #line 255 "parser-util.pcc"
965 #line 255 "parser-util.pcc"
966 + item_number,
967 SYNexp(nonterm_number,-symbol_number,NOty,false),junk_ty);
970 ///////////////////////////////////////////////////////////////////////////////
971 // Error handler for the parser
972 ///////////////////////////////////////////////////////////////////////////////
973 PropParser::ErrorAction PropParser::error_report(const char * message)
974 { if (meta.length() > 0)
975 { error ("%L%s at quotation text `%s`, ", message, meta.text());
976 meta.reset();
977 } else if (lexbuf.length() == 0)
978 { error ("%L%s at end of file, ", message);
979 } else
980 { error ("%L%s at token \"%s\", ", message, lexbuf.text());
982 return Retry;
985 ///////////////////////////////////////////////////////////////////////////////
987 // Method to initialize the lexer
989 ///////////////////////////////////////////////////////////////////////////////
990 void PropParser::initialize_lexer (const char * initial_file_name)
991 { if (initial_file_name == 0) initial_file_name = "<stdin>";
992 file = initial_file_name; line = first_line = 1;
993 SCs_top = 0;
994 levels_top = 0;
995 quote_top = 0;
996 options.emit_code = true;
997 program =
998 #line 286 "parser-util.pcc"
999 #line 286 "parser-util.pcc"
1000 nil_1_
1001 #line 286 "parser-util.pcc"
1002 #line 286 "parser-util.pcc"
1004 levels[levels_top++] = -1;
1005 lexbuf.set_context(C);
1006 lexbuf.set_stream(*input_stream);
1009 ///////////////////////////////////////////////////////////////////////////////
1011 // Method to cleanup the lexer
1013 ///////////////////////////////////////////////////////////////////////////////
1014 void PropParser::cleanup_lexer()
1015 { while (quote_top != 0)
1016 { const Quote& quote = quote_stack[--quote_top];
1017 Loc loc;
1018 loc.file_name = quote.file_name;
1019 loc.begin_line = quote.line_number;
1020 loc.end_line = quote.line_number;
1021 error ("%!unbalanced %c ... %c at end of file\n",
1022 &loc, (int)quote.open, (int)quote.close);
1026 ///////////////////////////////////////////////////////////////////////////////
1028 // Method to open a new include file
1030 ///////////////////////////////////////////////////////////////////////////////
1031 void PropParser::open_include_file(const char * file_name)
1032 { for (int i = 0; i < included_count; i++)
1033 if (included_files[i] == file_name) return;
1034 std::istream * new_stream = options.open_input_file(file_name);
1035 if (options.gen_dependences)
1036 IncludeDependency::add_dependency(str_pool[options.current_file_path]);
1037 if (new_stream == 0)
1038 { error ("%Lcan't find include file \"%s\"\n", file_name);
1039 return;
1041 if (includes_top >= MAX_INCLUDE_FILES) bug ("Include file stack overflow");
1042 if (included_count >= MAX_INCLUDE_FILES) bug ("Too many include files");
1043 included_files[included_count++] = file_name;
1044 includes[includes_top].file_stream = input_stream;
1045 includes[includes_top].file = file;
1046 includes[includes_top].line = line;
1047 includes[includes_top].first_line = first_line;
1048 includes[includes_top].scan = scan;
1049 includes[includes_top].doc = doc;
1050 includes[includes_top].meta = meta;
1051 includes_top++;
1052 line = 1;
1053 first_line = 1;
1054 file = file_name;
1055 options.emit_code = false;
1056 input_stream = new_stream;
1057 lexbuf.push_stream(*input_stream);
1058 lexbuf.set_context(C);
1061 ///////////////////////////////////////////////////////////////////////////////
1063 // Method to open a new include file
1065 ///////////////////////////////////////////////////////////////////////////////
1066 void PropParser::close_include_file()
1067 { if (includes_top <= 0) bug("Include file stack underflow");
1068 --includes_top;
1069 debug_msg("[Closing \"%s\" %i lines]\n", file, line-1);
1070 delete input_stream;
1071 input_stream = includes[includes_top].file_stream;
1072 file = includes[includes_top].file;
1073 line = includes[includes_top].line;
1074 first_line = includes[includes_top].first_line;
1075 scan = includes[includes_top].scan;
1076 doc = includes[includes_top].doc;
1077 meta = includes[includes_top].meta;
1078 options.emit_code = includes_top == 0;
1079 input_stream = &lexbuf.pop_stream();
1082 ///////////////////////////////////////////////////////////////////////////////
1084 // Methods to append text to the code buffer.
1086 ///////////////////////////////////////////////////////////////////////////////
1087 void PropParser::emit ()
1088 { emit(lexbuf.text(), lexbuf.length()); }
1090 void PropParser::emit (const char * t, long len)
1091 { if (options.emit_code) scan.emit(t,len); }
1093 void PropParser::emit (char c)
1094 { if (options.emit_code) scan.emit(c); }
1096 void PropParser::emit_header ()
1097 { if (options.emit_code)
1098 compiler->emit_header(lexbuf.text()+2,lexbuf.length()-2);
1101 // Append an expression
1102 void PropParser::emit(Exp e)
1103 { std::ostrstream b;
1104 std::ostream& f = b;
1105 f << e << std::ends;
1106 emit(b.str());
1107 b.rdbuf()->freeze(0); // free buffer
1110 // Append a constructor expression
1111 void PropParser::emit_cons(Id cons_name)
1112 { lookup_cons(cons_name);
1113 emit(mangle(cons_name));
1116 ///////////////////////////////////////////////////////////////////////////////
1118 // Methods to enter/exit a lexical context.
1120 ///////////////////////////////////////////////////////////////////////////////
1121 void PropParser::start_sc(LexicalContext c)
1122 { SCs[SCs_top++] = LexicalContext(lexbuf.context()); lexbuf.set_context(c);
1123 // if (options.debug) cerr << "[+context " << c << "]";
1126 void PropParser::end_sc()
1127 { if (SCs_top != 0)
1128 { --SCs_top; lexbuf.set_context(SCs[SCs_top]); }
1129 // if (options.debug) cerr << "[-context " << SCs[SCs_top] << "]";
1132 ///////////////////////////////////////////////////////////////////////////////
1134 // Methods to enter/exit a statement
1136 ///////////////////////////////////////////////////////////////////////////////
1137 void PropParser::start_statement()
1138 { levels[levels_top++] = quote_top; start_sc(C); }
1140 void PropParser::end_statement()
1141 { levels_top--; }
1143 ///////////////////////////////////////////////////////////////////////////////
1145 // Methods to push and pop from the quotation stack
1147 ///////////////////////////////////////////////////////////////////////////////
1148 void PropParser::start_quote(char a, char b)
1149 { quote_stack[quote_top++] = Quote(file,line,a,b);
1152 char PropParser::end_quote(char c)
1153 { if (quote_top == 0)
1154 { error("%Lunmatched ending quote %c\n",c);
1155 return c;
1156 } else
1157 { const Quote& quote = quote_stack[quote_top-1];
1158 if (quote.close != c)
1159 { error("%Lexpecting %c ... %c (from line %i) but found %c ... %c instead\n",
1160 (int)quote.open, (int)quote.close, quote.line_number,
1161 (int)quote.open, (int)c);
1163 quote_top--;
1164 return quote.close;
1167 #line 450 "parser-util.pcc"
1169 ------------------------------- Statistics -------------------------------
1170 Merge matching rules = yes
1171 Number of DFA nodes merged = 101
1172 Number of ifs generated = 7
1173 Number of switches generated = 4
1174 Number of labels = 3
1175 Number of gotos = 7
1176 Adaptive matching = enabled
1177 Fast string matching = disabled
1178 Inline downcasts = enabled
1179 --------------------------------------------------------------------------