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 ptree PROTO( (tree) );
21 static void plist PROTO( (void (*)(), list) );
22 static void pid PROTO( (id) );
23 static void pstr PROTO( (char *) );
24 static void pbool PROTO( (BOOLEAN) );
25 static void prbind PROTO( (binding) );
26 static void pttype PROTO( (ttype) );
27 static void patype PROTO( (atype) );
28 static void pentid PROTO( (entidt) );
29 static void prename PROTO( (list) );
30 static void pfixes PROTO( (void) );
31 static void ppbinding PROTO((pbinding));
32 static void pgrhses PROTO( (list) );
33 static void ppragma PROTO( (hpragma) );
34 static void pcoresyn PROTO((coresyn));
36 extern char *fixop PROTO((int));
37 extern char *fixtype PROTO((int));
39 extern char *input_filename;
40 extern BOOLEAN hashIds;
42 /* How to print tags */
45 #define PUTTAG(c) putchar(c);
46 #define PUTTAGSTR(s) printf("%s",(s));
48 #define PUTTAG(c) putchar(c); \
50 #define PUTTAGSTR(s) printf("%s",(s)); \
55 /* Performs a post order walk of the tree
67 /* print_string: we must escape \t and \\, as described in
68 char/string lexer comments. (WDP 94/11)
79 str_length = str->len;
82 for (i = 0; i < str_length; i++) {
87 } else if ( c == '\\' ) {
101 int c = (int)((str->bytes)[0]);
103 if (str->len != 1) { /* ToDo: assert */
104 fprintf(stderr, "get_character: length != 1? (%d: %s)\n", str->len, str->bytes);
108 c += 256; /* "This is not a hack" -- KH */
118 switch(tliteral(t)) {
133 pstr(gdoubleprim(t));
141 /* Changed %d to %u, since negative chars
142 make little sense -- KH @ 16/4/91
144 printf("#%u\t", get_character(gchar(t)));
148 printf("#%u\t", get_character(gcharprim(t)));
152 print_string(gstring(t));
156 print_string(gstringprim(t));
161 pstr(gclitlit_kind(t));
175 print_string(gnoreps(t));
178 error("Bad pliteral");
188 case par: t = gpare(t); goto again;
191 printf("#%u\t",ghmodline(t));
193 pstr(input_filename);
194 prbind(ghmodlist(t));
196 plist(prbind, ghimplist(t));
197 plist(pentid, ghexplist(t));
225 ptree(ginarg1((struct Sap *)t));
226 pid(gident(ginfun((struct Sap *)t)));
227 ptree(ginarg2((struct Sap *)t));
232 printf("#%u\t",glamline(t));
233 plist(ptree,glampats(t));
239 prbind(gletvdeflist(t));
245 plist(ppbinding, gcasebody(t));
255 plist(ptree,gtuplelist(t));
260 plist(ptree,gestep(t));
261 plist(ptree,geto(t));
265 plist(ptree,gllist(t));
274 plist(ptree,gcquals(t));
287 ptree(ggdef(t)); /* was: prbind (WDP 94/10) */
315 plist(ptree,gccargs(t));
319 print_string(gsccid(t));
326 plist(ptree,gpzfqual(t));
330 plist(ptree,gpod(t));
334 plist(ptree,gprocid(t));
363 if (tlist(l) == lcons) {
377 printf("!%u\t", hash_index(i));
379 printf("#%s\t", id_to_string(i));
393 switch(tbinding(b)) {
396 printf("#%u\t",gtline(b));
397 plist(pttype, gtbindc(b));
398 plist(pid, gtbindd(b));
400 plist(patype, gtbindl(b));
401 ppragma(gtpragma(b));
405 printf("#%u\t",gnline(b));
408 ppragma(gnpragma(b));
412 printf("#%u\t",gpline(b));
413 plist(ppbinding, gpbindl(b));
417 printf("#%u\t",gfline(b));
418 plist(ppbinding, gfbindl(b));
422 prbind(gabindfst(b));
423 prbind(gabindsnd(b));
427 printf("#%u\t",gcline(b));
428 plist(pttype,gcbindc(b));
431 ppragma(gcpragma(b));
435 printf("#%u\t",giline(b));
436 plist(pttype,gibindc(b));
440 ppragma(gipragma(b));
444 printf("#%u\t",gdline(b));
445 plist(pttype,gdbindts(b));
448 /* signature(-like) things, including user pragmas */
451 printf("#%u\t",gsline(b));
452 plist(pid,gsbindids(b));
454 ppragma(gspragma(b));
459 printf("#%u\t",gvspec_line(b));
461 plist(pttype,gvspec_tys(b));
465 printf("#%u\t",gispec_line(b));
467 pttype(gispec_ty(b));
471 printf("#%u\t",ginline_line(b));
473 plist(pid,ginline_howto(b));
477 printf("#%u\t",gdeforest_line(b));
478 pid(gdeforest_id(b));
482 printf("#%u\t",gmagicuf_line(b));
484 pid(gmagicuf_str(b));
488 printf("#%u\t",gabstract_line(b));
489 pid(gabstract_id(b));
493 printf("#%u\t",gdspec_line(b));
495 plist(pttype,gdspec_tys(b));
498 /* end of signature(-like) things */
502 printf("#%u\t",gmline(b));
504 plist(pentid,gmbindimp(b));
505 plist(prename,gmbindren(b));
509 printf("#%u\t",giebindline(b));
510 pstr(giebindfile(b));
512 plist(pentid,giebindexp(b));
513 plist(prename,giebindren(b));
514 prbind(giebinddef(b));
518 printf("#%u\t",gihbindline(b));
519 pstr(gihbindfile(b));
521 plist(pentid,gihbindexp(b));
522 plist(prename,gihbindren(b));
523 prbind(gihbinddef(b));
528 default : error("Bad prbind");
538 case tname : PUTTAG('T');
540 plist(pttype, gtypel(t));
542 case namedtvar : PUTTAG('y');
545 case tllist : PUTTAG(':');
548 case ttuple : PUTTAG(',');
549 plist(pttype,gttuple(t));
551 case tfun : PUTTAG('>');
555 case context : PUTTAG('3');
556 plist(pttype,gtcontextl(t));
557 pttype(gtcontextt(t));
560 case unidict : PUTTAGSTR("2A");
561 pid(gunidict_clas(t));
562 pttype(gunidict_ty(t));
564 case unityvartemplate : PUTTAGSTR("2B");
565 pid(gunityvartemplate(t));
567 case uniforall : PUTTAGSTR("2C");
568 plist(pid,guniforall_tv(t));
569 pttype(guniforall_ty(t));
572 case ty_maybe_nothing : PUTTAGSTR("2D");
574 case ty_maybe_just: PUTTAGSTR("2E");
575 pttype(gty_maybe(t));
581 plist(pttype,gtpid(t));
589 default : error("bad pttype");
600 printf("#%u\t",gatcline(a));
602 plist(pttype, gatctypel(a));
604 default : fprintf(stderr, "Bad tag in abstree %d\n", tatype(a));
614 switch (tentidt(i)) {
615 case entid : PUTTAG('x');
618 case enttype : PUTTAG('X');
621 case enttypeall : PUTTAG('z');
624 case entmod : PUTTAG('m');
627 case enttypecons: PUTTAG('8');
629 plist(pid,gctentcons(i));
631 case entclass : PUTTAG('9');
633 plist(pid,gcentops(i));
656 for(i = 0; i < m; i++) {
662 printf("#%u\t",precedence(i));
673 switch(tpbinding(p)) {
674 case pgrhs : PUTTAG('W');
675 printf("#%u\t",ggline(p));
678 plist(pgrhses,ggdexprs(p));
682 error("Bad pbinding");
691 ptree(lhd(l)); /* Guard */
692 ptree(lhd(ltl(l))); /* Expression */
699 switch(thpragma(p)) {
700 case no_pragma: PUTTAGSTR("PN");
702 case idata_pragma: PUTTAGSTR("Pd");
703 plist(patype, gprag_data_constrs(p));
704 plist(ppragma, gprag_data_specs(p));
706 case itype_pragma: PUTTAGSTR("Pt");
708 case iclas_pragma: PUTTAGSTR("Pc");
709 plist(ppragma, gprag_clas(p));
711 case iclasop_pragma: PUTTAGSTR("Po");
712 ppragma(gprag_dsel(p));
713 ppragma(gprag_defm(p));
716 case iinst_simpl_pragma: PUTTAGSTR("Pis");
717 pid(gprag_imod_simpl(p));
718 ppragma(gprag_dfun_simpl(p));
720 case iinst_const_pragma: PUTTAGSTR("Pic");
721 pid(gprag_imod_const(p));
722 ppragma(gprag_dfun_const(p));
723 plist(ppragma, gprag_constms(p));
725 case iinst_spec_pragma: PUTTAGSTR("PiS");
726 pid(gprag_imod_spec(p));
727 ppragma(gprag_dfun_spec(p));
728 plist(ppragma, gprag_inst_specs(p));
731 case igen_pragma: PUTTAGSTR("Pg");
732 ppragma(gprag_arity(p));
733 ppragma(gprag_update(p));
734 ppragma(gprag_deforest(p));
735 ppragma(gprag_strictness(p));
736 ppragma(gprag_unfolding(p));
737 plist(ppragma, gprag_specs(p));
739 case iarity_pragma: PUTTAGSTR("PA");
740 pid(gprag_arity_val(p));
742 case iupdate_pragma: PUTTAGSTR("Pu");
743 pid(gprag_update_val(p));
745 case ideforest_pragma: PUTTAGSTR("PD");
747 case istrictness_pragma: PUTTAGSTR("PS");
748 print_string(gprag_strict_spec(p));
749 ppragma(gprag_strict_wrkr(p));
751 case imagic_unfolding_pragma: PUTTAGSTR("PM");
752 pid(gprag_magic_str(p));
755 case iunfolding_pragma: PUTTAGSTR("PU");
756 ppragma(gprag_unfold_guide(p));
757 pcoresyn(gprag_unfold_core(p));
760 case iunfold_always: PUTTAGSTR("Px");
762 case iunfold_if_args: PUTTAGSTR("Py");
763 pid(gprag_unfold_if_t_args(p));
764 pid(gprag_unfold_if_v_args(p));
765 pid(gprag_unfold_if_con_args(p));
766 pid(gprag_unfold_if_size(p));
769 case iname_pragma_pr: PUTTAGSTR("P1");
770 pid(gprag_name_pr1(p));
771 ppragma(gprag_name_pr2(p));
773 case itype_pragma_pr: PUTTAGSTR("P2");
774 plist(pttype, gprag_type_pr1(p));
775 pid(gprag_type_pr2(p));
776 ppragma(gprag_type_pr3(p));
778 case iinst_pragma_3s: PUTTAGSTR("P3");
779 plist(pttype, gprag_inst_pt1(p));
780 pid(gprag_inst_pt2(p));
781 ppragma(gprag_inst_pt3(p));
782 plist(ppragma,gprag_inst_pt4(p));
785 case idata_pragma_4s: PUTTAGSTR("P4");
786 plist(pttype, gprag_data_spec(p));
789 default: error("Bad Pragma");
808 switch(tcoresyn(p)) {
809 case cobinder: PUTTAGSTR("Fa");
811 pttype(gcobinder_ty(p));
814 case colit: PUTTAGSTR("Fb");
817 case colocal: PUTTAGSTR("Fc");
818 pcoresyn(gcolocal_v(p));
821 case cononrec: PUTTAGSTR("Fd");
822 pcoresyn(gcononrec_b(p));
823 pcoresyn(gcononrec_rhs(p));
825 case corec: PUTTAGSTR("Fe");
826 plist(pcoresyn,gcorec(p));
828 case corec_pair: PUTTAGSTR("Ff");
829 pcoresyn(gcorec_b(p));
830 pcoresyn(gcorec_rhs(p));
833 case covar: PUTTAGSTR("Fg");
836 case coliteral: PUTTAGSTR("Fh");
837 pliteral(gcoliteral(p));
839 case cocon: PUTTAGSTR("Fi");
840 pcoresyn(gcocon_con(p));
841 plist(pttype, gcocon_tys(p));
842 plist(pcoresyn, gcocon_args(p));
844 case coprim: PUTTAGSTR("Fj");
845 pcoresyn(gcoprim_op(p));
846 plist(pttype, gcoprim_tys(p));
847 plist(pcoresyn, gcoprim_args(p));
849 case colam: PUTTAGSTR("Fk");
850 plist(pcoresyn, gcolam_vars(p));
851 pcoresyn(gcolam_body(p));
853 case cotylam: PUTTAGSTR("Fl");
854 plist(pid, gcotylam_tvs(p));
855 pcoresyn(gcotylam_body(p));
857 case coapp: PUTTAGSTR("Fm");
858 pcoresyn(gcoapp_fun(p));
859 plist(pcoresyn, gcoapp_args(p));
861 case cotyapp: PUTTAGSTR("Fn");
862 pcoresyn(gcotyapp_e(p));
863 pttype(gcotyapp_t(p));
865 case cocase: PUTTAGSTR("Fo");
866 pcoresyn(gcocase_s(p));
867 pcoresyn(gcocase_alts(p));
869 case colet: PUTTAGSTR("Fp");
870 pcoresyn(gcolet_bind(p));
871 pcoresyn(gcolet_body(p));
873 case coscc: PUTTAGSTR("Fz"); /* out of order! */
874 pcoresyn(gcoscc_scc(p));
875 pcoresyn(gcoscc_body(p));
878 case coalg_alts: PUTTAGSTR("Fq");
879 plist(pcoresyn, gcoalg_alts(p));
880 pcoresyn(gcoalg_deflt(p));
882 case coalg_alt: PUTTAGSTR("Fr");
883 pcoresyn(gcoalg_con(p));
884 plist(pcoresyn, gcoalg_bs(p));
885 pcoresyn(gcoalg_rhs(p));
887 case coprim_alts: PUTTAGSTR("Fs");
888 plist(pcoresyn, gcoprim_alts(p));
889 pcoresyn(gcoprim_deflt(p));
891 case coprim_alt: PUTTAGSTR("Ft");
892 pliteral(gcoprim_lit(p));
893 pcoresyn(gcoprim_rhs(p));
895 case conodeflt: PUTTAGSTR("Fu");
897 case cobinddeflt: PUTTAGSTR("Fv");
898 pcoresyn(gcobinddeflt_v(p));
899 pcoresyn(gcobinddeflt_rhs(p));
902 case co_primop: PUTTAGSTR("Fw");
905 case co_ccall: PUTTAGSTR("Fx");
906 pbool(gco_ccall_may_gc(p));
908 plist(pttype, gco_ccall_arg_tys(p));
909 pttype(gco_ccall_res_ty(p));
911 case co_casm: PUTTAGSTR("Fy");
912 pbool(gco_casm_may_gc(p));
913 pliteral(gco_casm(p));
914 plist(pttype, gco_casm_arg_tys(p));
915 pttype(gco_casm_res_ty(p));
918 /* Cost-centre stuff */
919 case co_preludedictscc: PUTTAGSTR("F?a");
920 pcoresyn(gco_preludedictscc_dupd(p));
922 case co_alldictscc: PUTTAGSTR("F?b");
923 print_string(gco_alldictscc_m(p));
924 print_string(gco_alldictscc_g(p));
925 pcoresyn(gco_alldictscc_dupd(p));
927 case co_usercc: PUTTAGSTR("F?c");
928 print_string(gco_usercc_n(p));
929 print_string(gco_usercc_m(p));
930 print_string(gco_usercc_g(p));
931 pcoresyn(gco_usercc_dupd(p));
932 pcoresyn(gco_usercc_cafd(p));
934 case co_autocc: PUTTAGSTR("F?d");
935 pcoresyn(gco_autocc_i(p));
936 print_string(gco_autocc_m(p));
937 print_string(gco_autocc_g(p));
938 pcoresyn(gco_autocc_dupd(p));
939 pcoresyn(gco_autocc_cafd(p));
941 case co_dictcc: PUTTAGSTR("F?e");
942 pcoresyn(gco_dictcc_i(p));
943 print_string(gco_dictcc_m(p));
944 print_string(gco_dictcc_g(p));
945 pcoresyn(gco_dictcc_dupd(p));
946 pcoresyn(gco_dictcc_cafd(p));
949 case co_scc_noncaf: PUTTAGSTR("F?f");
951 case co_scc_caf: PUTTAGSTR("F?g");
953 case co_scc_nondupd: PUTTAGSTR("F?h");
955 case co_scc_dupd: PUTTAGSTR("F?i");
959 case co_id: PUTTAGSTR("F1");
962 case co_orig_id: PUTTAGSTR("F9");
963 pid(gco_orig_id_m(p));
964 pid(gco_orig_id_n(p));
966 case co_sdselid: PUTTAGSTR("F2");
967 pid(gco_sdselid_c(p));
968 pid(gco_sdselid_sc(p));
970 case co_classopid: PUTTAGSTR("F3");
971 pid(gco_classopid_c(p));
972 pid(gco_classopid_o(p));
974 case co_defmid: PUTTAGSTR("F4");
975 pid(gco_defmid_c(p));
976 pid(gco_defmid_op(p));
978 case co_dfunid: PUTTAGSTR("F5");
979 pid(gco_dfunid_c(p));
980 pttype(gco_dfunid_ty(p));
982 case co_constmid: PUTTAGSTR("F6");
983 pid(gco_constmid_c(p));
984 pid(gco_constmid_op(p));
985 pttype(gco_constmid_ty(p));
987 case co_specid: PUTTAGSTR("F7");
988 pcoresyn(gco_specid_un(p));
989 plist(pttype,gco_specid_tys(p));
991 case co_wrkrid: PUTTAGSTR("F8");
992 pcoresyn(gco_wrkrid_un(p));
996 default : error("Bad Core syntax");