1 /**********************************************************************
4 * Syntax Tree Printing Routines *
7 **********************************************************************/
10 #define COMPACT TRUE /* No spaces in output -- #undef this for debugging */
16 #include "constants.h"
19 /* fwd decls, necessary and otherwise */
20 static void pbool PROTO( (BOOLEAN) );
21 static void pconstr PROTO( (constr) );
22 /* static void pcoresyn PROTO((coresyn)); */
23 static void pentid PROTO( (entidt) );
24 static void pgrhses PROTO( (list) );
25 static void pid PROTO( (id) );
26 static void plist PROTO( (void (*)(/*NOT WORTH IT: void * */), list) );
27 static void pmaybe PROTO( (void (*)(), maybe) );
28 static void pmaybe_list PROTO( (void (*)(), maybe) );
29 /* static void ppragma PROTO( (hpragma) ); */
30 static void pqid PROTO( (qid) );
31 static void prbind PROTO( (binding) );
32 static void pstr PROTO( (char *) );
33 static void ptree PROTO( (tree) );
34 static void ppgdexp PROTO( (gdexp) );
35 static void pgrhsb PROTO( (grhsb) );
36 static void ppmatch PROTO( (match) );
37 static void pttype PROTO( (ttype) );
38 static void plineno PROTO( (long) );
40 extern char *input_filename;
41 extern BOOLEAN hashIds;
43 /* How to print tags */
46 #define PUTTAG(c) putchar(c);
47 #define PUTTAGSTR(s) printf("%s",(s));
49 #define PUTTAG(c) putchar(c); \
51 #define PUTTAGSTR(s) printf("%s",(s)); \
56 /* Performs a post order walk of the tree
68 /* print_string: we must escape \t and \\, as described in
69 char/string lexer comments. (WDP 94/11)
72 print_string(hstring str)
79 str_length = str->len;
82 for (i = 0; i < str_length; i++) {
87 } else if ( c == '\\' ) {
107 get_character(hstring str)
109 int c = (int)((str->bytes)[0]);
111 if (str->len != 1) { /* ToDo: assert */
112 fprintf(stderr, "get_character: length != 1? (%ld: %s)\n", str->len, str->bytes);
116 c += 256; /* "This is not a hack" -- KH */
125 switch(tliteral(t)) {
140 pstr(gdoubleprim(t));
148 /* Changed %d to %u, since negative chars
149 make little sense -- KH @ 16/4/91
151 printf("#%u\t", get_character(gchar(t)));
155 printf("#%u\t", get_character(gcharprim(t)));
159 print_string(gstring(t));
163 print_string(gstringprim(t));
168 /* pstr(gclitlit_kind(t)); */
171 error("Bad pliteral");
183 plineno(ghmodline(t));
185 printf("#%lu\t",ghversion(t));
186 pstr(input_filename);
187 prbind(ghmodlist(t));
189 plist(prbind, ghimplist(t));
190 pmaybe_list(pentid, ghexplist(t));
218 ppmatch(glammatch(t));
223 prbind(gletvdefs(t));
228 plineno(gcaseline(t));
230 plist(ppmatch, gcasebody(t));
241 plist(ptree, gdo(t));
245 plineno(gdobindline(t));
246 ptree(gdobindpat(t));
247 ptree(gdobindexp(t));
251 plineno(gdoexpline(t));
261 plist(prbind,grbinds(t));
267 plist(prbind,gupdbinds(t));
273 pmaybe(ptree,grbindexp(t));
276 case par: t = gpare(t); goto again;
298 plist(ptree,gtuplelist(t));
302 plist(ptree,gllist(t));
307 pmaybe(ptree,gestep(t));
308 pmaybe(ptree,geto(t));
313 plist(ptree,gcquals(t));
338 plist(ptree,gccargs(t));
342 print_string(gsccid(t));
352 void (*fun)(/* NOT WORTH IT: void * */);
355 if (tlist(l) == lnil) {
366 void (*fun)(/* NOT WORTH IT: void * */);
369 if (tmaybe(m) == nothing) {
379 void (*fun)(/* NOT WORTH IT: void * */);
382 if (tmaybe(m) == nothing) {
386 plist(fun, gthing(m));
395 printf("!%lu\t", hash_index(i));
397 printf("#%s\t", id_to_string(i));
405 printf("!%lu\t", hash_index(qid_to_id(i)));
407 printf("#%s\t", qid_to_string(i));
421 switch(tbinding(b)) {
425 plist(pttype, gtbindc(b));
426 pmaybe_list(pid, gtbindd(b));
428 plist(pconstr, gtbindl(b));
433 plist(pttype,gntbindcty(b));
434 pmaybe_list(pid, gntbindd(b));
435 pttype(gntbindid(b));
436 plist(pconstr, gntbindcty(b));
447 pgrhsb( gpbindr(b) );
452 plist(ppmatch, gfbindm(b));
457 prbind(gabindfst(b));
458 prbind(gabindsnd(b));
465 /* ppragma(gipragma(b)); */
470 plist(pttype,gdbindts(b));
476 plist(pttype,gcbindc(b));
481 /* signature(-like) things, including user pragmas */
485 plist(pqid,gsbindids(b));
496 printf("%lu\t%lu",gfixinfx(b),gfixprec(b));
501 plineno(gibindline(b));
502 /* pid(gibindfile(b)); */
504 printf("#%lu\t",gibindqual(b)); /* 1 -- qualified */
505 printf("#%lu\t",gibindsource(b)); /* 1 -- from source */
506 pmaybe(pid, gibindas(b));
507 pmaybe(pconstr, gibindspec(b));
508 /* plist(pentid,giebindexp(b)); ??? */
509 /* prbind(giebinddef(b)); ???? */
512 /* User pragmas till the end */
516 plineno(gvspec_line(b));
518 plist(pttype,gvspec_tys(b));
520 case vspec_ty_and_id:
522 pttype(gvspec_ty(b));
523 pmaybe(pttype,gvspec_tyid(b));
528 plineno(gispec_line(b));
529 pttype(gispec_ty(b));
533 plineno(ginline_line(b));
538 plineno(gmagicuf_line(b));
539 pqid(gmagicuf_id(b));
540 pid(gmagicuf_str(b));
544 plineno(gdspec_line(b));
546 plist(pttype,gdspec_tys(b));
549 /* end of signature(-like) things */
555 plist(pentid,gmbindimp(b));
558 default : error("Bad prbind");
568 case tname : PUTTAG('T');
571 case namedtvar : PUTTAG('y');
574 case tllist : PUTTAG(':');
577 case ttuple : PUTTAG(',');
578 plist(pttype,gttuple(t));
580 case tfun : PUTTAG('>');
584 case tapp : PUTTAG('@');
588 case tbang : PUTTAG('!');
591 case forall : PUTTAG('3');
592 plist(pstr, gtforalltv(t));
593 plist(pttype,gtforallctxt(t));
594 pttype(gtforallt(t));
596 default : error("bad pttype");
604 switch (tconstr(a)) {
607 plineno(gconcline(a));
609 plist(pttype, gconctypel(a));
613 plineno(gconiline(a));
621 plineno(gconrline(a));
623 plist(pqid,gconrfieldl(a));
627 plineno(gconnline(a));
633 plist(pqid,gfieldn(a));
636 default : fprintf(stderr, "Bad tag in abstree %d\n", tconstr(a));
646 switch (tentidt(i)) {
647 case entid : PUTTAG('x');
650 case enttype : PUTTAG('X');
653 case enttypeall : PUTTAG('z');
656 case enttypenamed:PUTTAG('8');
658 plist(pqid,gnentnames(i));
660 case entmod : PUTTAG('m');
669 static void ppmatch(l) match l; { fprintf( stderr, "printtree.c: ppmatch" ); }
670 static void ppgdexp(l) gdexp l; { fprintf( stderr, "printtree.c: ppgdexp" ); }
671 static void pgrhsb(l) grhsb l; { fprintf( stderr, "printtree.c: pgrhsb" ); }
677 ptree(lhd(l)); /* Guard */
678 ptree(lhd(ltl(l))); /* Expression */
685 switch(thpragma(p)) {
686 case no_pragma: PUTTAGSTR("PN");
688 case idata_pragma: PUTTAGSTR("Pd");
689 plist(pconstr, gprag_data_constrs(p));
690 plist(ppragma, gprag_data_specs(p));
692 case itype_pragma: PUTTAGSTR("Pt");
694 case iclas_pragma: PUTTAGSTR("Pc");
695 plist(ppragma, gprag_clas(p));
697 case iclasop_pragma: PUTTAGSTR("Po");
698 ppragma(gprag_dsel(p));
699 ppragma(gprag_defm(p));
702 case iinst_simpl_pragma: PUTTAGSTR("Pis");
703 / * pid(gprag_imod_simpl(p));
704 * / ppragma(gprag_dfun_simpl(p));
706 case iinst_const_pragma: PUTTAGSTR("Pic");
707 / * pid(gprag_imod_const(p));
708 * / ppragma(gprag_dfun_const(p));
709 plist(ppragma, gprag_constms(p));
712 case igen_pragma: PUTTAGSTR("Pg");
713 ppragma(gprag_arity(p));
714 ppragma(gprag_update(p));
715 ppragma(gprag_strictness(p));
716 ppragma(gprag_unfolding(p));
717 plist(ppragma, gprag_specs(p));
719 case iarity_pragma: PUTTAGSTR("PA");
720 pid(gprag_arity_val(p));
722 case iupdate_pragma: PUTTAGSTR("Pu");
723 pid(gprag_update_val(p));
725 case istrictness_pragma: PUTTAGSTR("PS");
726 print_string(gprag_strict_spec(p));
727 ppragma(gprag_strict_wrkr(p));
729 case imagic_unfolding_pragma: PUTTAGSTR("PM");
730 pid(gprag_magic_str(p));
733 case iunfolding_pragma: PUTTAGSTR("PU");
734 ppragma(gprag_unfold_guide(p));
735 pcoresyn(gprag_unfold_core(p));
738 case iunfold_always: PUTTAGSTR("Px");
740 case iunfold_if_args: PUTTAGSTR("Py");
741 pid(gprag_unfold_if_t_args(p));
742 pid(gprag_unfold_if_v_args(p));
743 pid(gprag_unfold_if_con_args(p));
744 pid(gprag_unfold_if_size(p));
747 case iname_pragma_pr: PUTTAGSTR("P1");
748 pid(gprag_name_pr1(p));
749 ppragma(gprag_name_pr2(p));
751 case itype_pragma_pr: PUTTAGSTR("P2");
752 plist(pttype, gprag_type_pr1(p));
753 pid(gprag_type_pr2(p));
754 ppragma(gprag_type_pr3(p));
757 case idata_pragma_4s: PUTTAGSTR("P4");
758 plist(pttype, gprag_data_spec(p));
761 default: error("Bad Pragma");