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 ppbinding PROTO((pbinding));
30 /* static void ppragma PROTO( (hpragma) ); */
31 static void pqid PROTO( (qid) );
32 static void prbind PROTO( (binding) );
33 static void pstr PROTO( (char *) );
34 static void ptree PROTO( (tree) );
35 static void pttype PROTO( (ttype) );
36 static void plineno PROTO( (long) );
38 extern char *input_filename;
39 extern BOOLEAN hashIds;
41 /* How to print tags */
44 #define PUTTAG(c) putchar(c);
45 #define PUTTAGSTR(s) printf("%s",(s));
47 #define PUTTAG(c) putchar(c); \
49 #define PUTTAGSTR(s) printf("%s",(s)); \
54 /* Performs a post order walk of the tree
66 /* print_string: we must escape \t and \\, as described in
67 char/string lexer comments. (WDP 94/11)
70 print_string(hstring str)
77 str_length = str->len;
80 for (i = 0; i < str_length; i++) {
85 } else if ( c == '\\' ) {
105 get_character(hstring str)
107 int c = (int)((str->bytes)[0]);
109 if (str->len != 1) { /* ToDo: assert */
110 fprintf(stderr, "get_character: length != 1? (%ld: %s)\n", str->len, str->bytes);
114 c += 256; /* "This is not a hack" -- KH */
123 switch(tliteral(t)) {
138 pstr(gdoubleprim(t));
146 /* Changed %d to %u, since negative chars
147 make little sense -- KH @ 16/4/91
149 printf("#%u\t", get_character(gchar(t)));
153 printf("#%u\t", get_character(gcharprim(t)));
157 print_string(gstring(t));
161 print_string(gstringprim(t));
166 /* pstr(gclitlit_kind(t)); */
169 error("Bad pliteral");
181 plineno(ghmodline(t));
183 printf("#%lu\t",ghversion(t));
184 pstr(input_filename);
185 prbind(ghmodlist(t));
187 plist(prbind, ghimplist(t));
188 pmaybe_list(pentid, ghexplist(t));
193 printf("%lu\t%lu",gfixinfx(t),gfixprec(t));
221 plineno(glamline(t));
222 plist(ptree,glampats(t));
228 prbind(gletvdefs(t));
233 plineno(gcaseline(t));
235 plist(ppbinding, gcasebody(t));
246 plist(ptree, gdo(t));
250 plineno(gdobindline(t));
251 ptree(gdobindpat(t));
252 ptree(gdobindexp(t));
256 plineno(gdoexpline(t));
266 plist(prbind,grbinds(t));
272 plist(prbind,gupdbinds(t));
278 pmaybe(ptree,grbindexp(t));
281 case par: t = gpare(t); goto again;
303 plist(ptree,gtuplelist(t));
307 plist(ptree,gllist(t));
312 pmaybe(ptree,gestep(t));
313 pmaybe(ptree,geto(t));
318 plist(ptree,gcquals(t));
343 plist(ptree,gccargs(t));
347 print_string(gsccid(t));
357 void (*fun)(/* NOT WORTH IT: void * */);
360 if (tlist(l) == lnil) {
371 void (*fun)(/* NOT WORTH IT: void * */);
374 if (tmaybe(m) == nothing) {
384 void (*fun)(/* NOT WORTH IT: void * */);
387 if (tmaybe(m) == nothing) {
391 plist(fun, gthing(m));
400 printf("!%lu\t", hash_index(i));
402 printf("#%s\t", id_to_string(i));
410 printf("!%lu\t", hash_index(qid_to_id(i)));
412 printf("#%s\t", qid_to_string(i));
426 switch(tbinding(b)) {
430 plist(pttype, gtbindc(b));
431 pmaybe_list(pid, gtbindd(b));
433 plist(pconstr, gtbindl(b));
438 plist(pttype,gntbindcty(b));
439 pmaybe_list(pid, gntbindd(b));
440 pttype(gntbindid(b));
441 plist(pconstr, gntbindcty(b));
452 plist(ppbinding, gpbindl(b));
457 plist(ppbinding, gfbindl(b));
461 prbind(gabindfst(b));
462 prbind(gabindsnd(b));
467 plist(pttype,gibindc(b));
471 /* ppragma(gipragma(b)); */
476 plist(pttype,gdbindts(b));
482 plist(pttype,gcbindc(b));
487 /* signature(-like) things, including user pragmas */
491 plist(pqid,gsbindids(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(gdeforest_line(b));
540 pqid(gdeforest_id(b));
544 plineno(gmagicuf_line(b));
545 pqid(gmagicuf_id(b));
546 pid(gmagicuf_str(b));
550 plineno(gdspec_line(b));
552 plist(pttype,gdspec_tys(b));
555 /* end of signature(-like) things */
561 plist(pentid,gmbindimp(b));
564 default : error("Bad prbind");
574 case tname : PUTTAG('T');
577 case namedtvar : PUTTAG('y');
580 case tllist : PUTTAG(':');
583 case ttuple : PUTTAG(',');
584 plist(pttype,gttuple(t));
586 case tfun : PUTTAG('>');
590 case tapp : PUTTAG('@');
594 case tbang : PUTTAG('!');
597 case context : PUTTAG('3');
598 plist(pttype,gtcontextl(t));
599 pttype(gtcontextt(t));
601 default : error("bad pttype");
609 switch (tconstr(a)) {
612 plineno(gconcline(a));
614 plist(pttype, gconctypel(a));
618 plineno(gconiline(a));
626 plineno(gconrline(a));
628 plist(pqid,gconrfieldl(a));
632 plineno(gconnline(a));
638 plist(pqid,gfieldn(a));
641 default : fprintf(stderr, "Bad tag in abstree %d\n", tconstr(a));
651 switch (tentidt(i)) {
652 case entid : PUTTAG('x');
655 case enttype : PUTTAG('X');
658 case enttypeall : PUTTAG('z');
661 case enttypenamed:PUTTAG('8');
663 plist(pqid,gnentnames(i));
665 case entmod : PUTTAG('m');
678 switch(tpbinding(p)) {
679 case pgrhs : PUTTAG('W');
683 ppbinding(ggdexprs(p));
692 plist(ptree, gpguards(p));
696 plist(ptree, gpguard(p)); /* Experimental: pattern guards */
700 error("Bad pbinding");
709 ptree(lhd(l)); /* Guard */
710 ptree(lhd(ltl(l))); /* Expression */
717 switch(thpragma(p)) {
718 case no_pragma: PUTTAGSTR("PN");
720 case idata_pragma: PUTTAGSTR("Pd");
721 plist(pconstr, gprag_data_constrs(p));
722 plist(ppragma, gprag_data_specs(p));
724 case itype_pragma: PUTTAGSTR("Pt");
726 case iclas_pragma: PUTTAGSTR("Pc");
727 plist(ppragma, gprag_clas(p));
729 case iclasop_pragma: PUTTAGSTR("Po");
730 ppragma(gprag_dsel(p));
731 ppragma(gprag_defm(p));
734 case iinst_simpl_pragma: PUTTAGSTR("Pis");
735 / * pid(gprag_imod_simpl(p));
736 * / ppragma(gprag_dfun_simpl(p));
738 case iinst_const_pragma: PUTTAGSTR("Pic");
739 / * pid(gprag_imod_const(p));
740 * / ppragma(gprag_dfun_const(p));
741 plist(ppragma, gprag_constms(p));
744 case igen_pragma: PUTTAGSTR("Pg");
745 ppragma(gprag_arity(p));
746 ppragma(gprag_update(p));
747 ppragma(gprag_deforest(p));
748 ppragma(gprag_strictness(p));
749 ppragma(gprag_unfolding(p));
750 plist(ppragma, gprag_specs(p));
752 case iarity_pragma: PUTTAGSTR("PA");
753 pid(gprag_arity_val(p));
755 case iupdate_pragma: PUTTAGSTR("Pu");
756 pid(gprag_update_val(p));
758 case ideforest_pragma: PUTTAGSTR("PD");
760 case istrictness_pragma: PUTTAGSTR("PS");
761 print_string(gprag_strict_spec(p));
762 ppragma(gprag_strict_wrkr(p));
764 case imagic_unfolding_pragma: PUTTAGSTR("PM");
765 pid(gprag_magic_str(p));
768 case iunfolding_pragma: PUTTAGSTR("PU");
769 ppragma(gprag_unfold_guide(p));
770 pcoresyn(gprag_unfold_core(p));
773 case iunfold_always: PUTTAGSTR("Px");
775 case iunfold_if_args: PUTTAGSTR("Py");
776 pid(gprag_unfold_if_t_args(p));
777 pid(gprag_unfold_if_v_args(p));
778 pid(gprag_unfold_if_con_args(p));
779 pid(gprag_unfold_if_size(p));
782 case iname_pragma_pr: PUTTAGSTR("P1");
783 pid(gprag_name_pr1(p));
784 ppragma(gprag_name_pr2(p));
786 case itype_pragma_pr: PUTTAGSTR("P2");
787 plist(pttype, gprag_type_pr1(p));
788 pid(gprag_type_pr2(p));
789 ppragma(gprag_type_pr3(p));
792 case idata_pragma_4s: PUTTAGSTR("P4");
793 plist(pttype, gprag_data_spec(p));
796 default: error("Bad Pragma");