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 pqid(gispec_clas(b));
530 pttype(gispec_ty(b));
534 plineno(ginline_line(b));
539 plineno(gmagicuf_line(b));
540 pqid(gmagicuf_id(b));
541 pid(gmagicuf_str(b));
545 plineno(gdspec_line(b));
547 plist(pttype,gdspec_tys(b));
550 /* end of signature(-like) things */
556 plist(pentid,gmbindimp(b));
559 default : error("Bad prbind");
569 case tname : PUTTAG('T');
572 case namedtvar : PUTTAG('y');
575 case tllist : PUTTAG(':');
578 case ttuple : PUTTAG(',');
579 plist(pttype,gttuple(t));
581 case tfun : PUTTAG('>');
585 case tapp : PUTTAG('@');
589 case tbang : PUTTAG('!');
592 case forall : PUTTAG('3');
593 plist(pstr, gtforalltv(t));
594 plist(pttype,gtforallctxt(t));
595 pttype(gtforallt(t));
597 default : error("bad pttype");
605 switch (tconstr(a)) {
608 plineno(gconcline(a));
610 plist(pttype, gconctypel(a));
614 plineno(gconiline(a));
622 plineno(gconrline(a));
624 plist(pqid,gconrfieldl(a));
628 plineno(gconnline(a));
634 plist(pqid,gfieldn(a));
637 default : fprintf(stderr, "Bad tag in abstree %d\n", tconstr(a));
647 switch (tentidt(i)) {
648 case entid : PUTTAG('x');
651 case enttype : PUTTAG('X');
654 case enttypeall : PUTTAG('z');
657 case enttypenamed:PUTTAG('8');
659 plist(pqid,gnentnames(i));
661 case entmod : PUTTAG('m');
670 static void ppmatch(l) match l; { fprintf( stderr, "printtree.c: ppmatch" ); }
671 static void ppgdexp(l) gdexp l; { fprintf( stderr, "printtree.c: ppgdexp" ); }
672 static void pgrhsb(l) grhsb l; { fprintf( stderr, "printtree.c: pgrhsb" ); }
678 ptree(lhd(l)); /* Guard */
679 ptree(lhd(ltl(l))); /* Expression */
686 switch(thpragma(p)) {
687 case no_pragma: PUTTAGSTR("PN");
689 case idata_pragma: PUTTAGSTR("Pd");
690 plist(pconstr, gprag_data_constrs(p));
691 plist(ppragma, gprag_data_specs(p));
693 case itype_pragma: PUTTAGSTR("Pt");
695 case iclas_pragma: PUTTAGSTR("Pc");
696 plist(ppragma, gprag_clas(p));
698 case iclasop_pragma: PUTTAGSTR("Po");
699 ppragma(gprag_dsel(p));
700 ppragma(gprag_defm(p));
703 case iinst_simpl_pragma: PUTTAGSTR("Pis");
704 / * pid(gprag_imod_simpl(p));
705 * / ppragma(gprag_dfun_simpl(p));
707 case iinst_const_pragma: PUTTAGSTR("Pic");
708 / * pid(gprag_imod_const(p));
709 * / ppragma(gprag_dfun_const(p));
710 plist(ppragma, gprag_constms(p));
713 case igen_pragma: PUTTAGSTR("Pg");
714 ppragma(gprag_arity(p));
715 ppragma(gprag_update(p));
716 ppragma(gprag_strictness(p));
717 ppragma(gprag_unfolding(p));
718 plist(ppragma, gprag_specs(p));
720 case iarity_pragma: PUTTAGSTR("PA");
721 pid(gprag_arity_val(p));
723 case iupdate_pragma: PUTTAGSTR("Pu");
724 pid(gprag_update_val(p));
726 case istrictness_pragma: PUTTAGSTR("PS");
727 print_string(gprag_strict_spec(p));
728 ppragma(gprag_strict_wrkr(p));
730 case imagic_unfolding_pragma: PUTTAGSTR("PM");
731 pid(gprag_magic_str(p));
734 case iunfolding_pragma: PUTTAGSTR("PU");
735 ppragma(gprag_unfold_guide(p));
736 pcoresyn(gprag_unfold_core(p));
739 case iunfold_always: PUTTAGSTR("Px");
741 case iunfold_if_args: PUTTAGSTR("Py");
742 pid(gprag_unfold_if_t_args(p));
743 pid(gprag_unfold_if_v_args(p));
744 pid(gprag_unfold_if_con_args(p));
745 pid(gprag_unfold_if_size(p));
748 case iname_pragma_pr: PUTTAGSTR("P1");
749 pid(gprag_name_pr1(p));
750 ppragma(gprag_name_pr2(p));
752 case itype_pragma_pr: PUTTAGSTR("P2");
753 plist(pttype, gprag_type_pr1(p));
754 pid(gprag_type_pr2(p));
755 ppragma(gprag_type_pr3(p));
758 case idata_pragma_4s: PUTTAGSTR("P4");
759 plist(pttype, gprag_data_spec(p));
762 default: error("Bad Pragma");