C:/Users/Dennis/src/lang/russell.orig/src/stree/unparse.c

Go to the documentation of this file.
00001 # include "parm.h"
00002 # include <stdio.h>
00003 # include "stree/ststructs.mh"
00004 # include "pass4/sigs.h"
00005 
00006 FILE * unparse_file;
00007 
00008 /*
00009  * Write out a brief human readable version of the syntax tree headed
00010  * by p onto unparse_file.  Abbreviations are used wherever it is likely
00011  * to be appropriate.  The aim is for the output to be no longer
00012  * than a few hundred characters, and to be much shorter for a typical
00013  * signature.
00014  * An uninitialized unparse_file is interpreted as stderr.
00015  */
00016 
00017 unparse(p)
00018 register NODE * p;
00019 {
00020 register NODE * v;
00021 
00022     if (unparse_file == (FILE *)0) {
00023         unparse_file = stderr;
00024     }
00025     if (p == NIL) return;
00026     if (p == ERR_SIG) {
00027         fprintf(unparse_file, "(erroneous)");
00028         return;
00029     }
00030 
00031     switch ( p -> kind ) {
00032 
00033         case BLOCKDENOTATION:
00034                 if (p -> bld_declaration_list == NIL
00035                     || is_empty(p -> bld_declaration_list)) {
00036                     if (p -> bld_den_seq == NIL) {
00037                         fprintf(unparse_file, "<place holder>");
00038                     } else {
00039                       if (length(p -> bld_den_seq) == 1) {
00040                         unparse(first(p -> bld_den_seq));
00041                       } else {
00042                         fprintf(unparse_file, "(");
00043                         unparse(first(p -> bld_den_seq));
00044                         fprintf(unparse_file, "; ... )");
00045                       }
00046                     }
00047                 } else {
00048                     fprintf(unparse_file, "let ");
00049                     unparse(first(p -> bld_declaration_list) -> decl_id);
00050                     fprintf(unparse_file, " == ... in ... ni");
00051                 }
00052                 break;
00053 
00054         case APPLICATION:
00055                 unparse(p -> ap_operator);
00056                 fprintf(unparse_file, "[");
00057                 maplist(v, p->ap_args, {
00058                     unparse(v);
00059                     if(v != last(p -> ap_args)) {
00060                         fprintf(unparse_file, ",");
00061                     }
00062                 });
00063                 fprintf(unparse_file, "]");
00064                 break;
00065 
00066         case LOOPDENOTATION:
00067                 fprintf(unparse_file, "do ");
00068                 if (!is_empty(p -> gl_list)) {
00069                     unparse(first(p -> gl_list) -> ge_guard);
00070                     fprintf(unparse_file, " ==> ... ");
00071                 }
00072                 fprintf(unparse_file, "od");
00073                 break;
00074 
00075         case GUARDEDLIST:
00076                 fprintf(unparse_file, "if ");
00077                 if (!is_empty(p -> gl_list)) {
00078                     unparse(first(p -> gl_list) -> ge_guard);
00079                     fprintf(unparse_file, " ==> ... ");
00080                 }
00081                 fprintf(unparse_file, "fi");
00082                 break;
00083 
00084         case OPRID:
00085         case LETTERID:
00086                 if (p -> id_str_table_index == -1) {
00087                     fprintf(unparse_file, "(local id)");
00088                 } else if (((int) p -> id_str_table_index) <= 0) {
00089                     fprintf(unparse_file, "(anonymous)");
00090                 } else {
00091                     fprintf(unparse_file, "%s", getname(p -> id_str_table_index));
00092                 }
00093                 break;
00094 
00095         case FUNCCONSTR:
00096                 fprintf(unparse_file, "func[");
00097                 if (!is_empty(p -> signature -> fsig_param_list)) {
00098                     fprintf(unparse_file, "... ");
00099                 }
00100                 fprintf(unparse_file, "] {");
00101                 unparse(p -> fc_body);
00102                 fprintf(unparse_file, "}");
00103                 break;
00104 
00105         case USELIST:
00106                 fprintf(unparse_file, "use ... in ");
00107                 unparse(first(p -> usl_den_seq));
00108                 if (length(p -> usl_den_seq) != 1) {
00109                     fprintf(unparse_file, "; ...");
00110                 }
00111                 fprintf(unparse_file, " ni");
00112                 break;
00113 
00114         case MODPRIMARY:
00115                 unparse(p -> mp_primary);
00116                 if (p -> mp_type_modifier != NIL) {
00117                     switch( p -> mp_type_modifier -> kind ) {
00118                         case EXPORTLIST:
00119                             fprintf(unparse_file, " export ...");
00120                             break;
00121                         case HIDELIST:
00122                             fprintf(unparse_file, " hide ...");
00123                             break;
00124                         case WITHLIST:
00125                             fprintf(unparse_file, " with ...");
00126                             break;
00127                     }
00128                 }
00129                 break;
00130 
00131         case QSTR:
00132                 fprintf(unparse_file, "\"");
00133                 fprintf(unparse_file, p -> str_string);
00134                 fprintf(unparse_file, "\"");
00135                 break;
00136 
00137         case UQSTR:
00138                 fprintf(unparse_file, p -> str_string);
00139                 break;
00140 
00141         case ENUMERATION:
00142                 fprintf(unparse_file, "enum{ ... }");
00143                 break;
00144 
00145         case PRODCONSTRUCTION:
00146                 fprintf(unparse_file, "prod{ ... }");
00147                 break;
00148 
00149         case UNIONCONSTRUCTION:
00150                 fprintf(unparse_file, "union{ ... }");
00151                 break;
00152 
00153         case RECORDCONSTRUCTION:
00154                 fprintf(unparse_file, "record{ ... }");
00155                 break;
00156 
00157         case WORDELSE:
00158                 fprintf(unparse_file, "else");
00159                 break;
00160 
00161         case EXTERNDEF:
00162                 fprintf(unparse_file, "extern \"");
00163                 fprintf(unparse_file, p -> ext_name);
00164                 fprintf(unparse_file, "\"");
00165                 break;
00166 
00167         case REXTERNDEF:
00168                 fprintf(unparse_file, "extern {\"");
00169                 fprintf(unparse_file, p -> r_ext_name);
00170                 fprintf(unparse_file, "\"}");
00171                 break;
00172 
00173         case PARAMETER:
00174                 unparse(p -> par_id);
00175                 fprintf(unparse_file, ":");
00176                 unparse(p -> par_signature);
00177                 break;
00178 
00179         case TSCOMPONENT:
00180                 unparse(p -> tsc_id);
00181                 break;
00182     
00183         case DEFCHARSIGS:
00184                 {
00185                     unsigned *q = &(p -> dcs_0);
00186                     boolean has_consts = FALSE;
00187 
00188                     while (q < &(p -> dcs_0) + NVECTORS) {
00189                         if (*q != 0) has_consts = TRUE;
00190                         q++;
00191                     }
00192                     if (has_consts) {
00193                         fprintf(unparse_file, "(constants)");
00194                     }
00195                     break;
00196                 }
00197 
00198         case EXTENSION:
00199                 fprintf(unparse_file, "extend{");
00200                 unparse(p -> ext_denotation);
00201                 fprintf(unparse_file, "}");
00202                 break;
00203 
00204         case FUNCSIGNATURE:
00205                 fprintf(unparse_file, "func[");
00206                 maplist(s, p -> fsig_param_list, {
00207                     unparse(s);
00208                     if (s != last(p -> fsig_param_list)) {
00209                         fprintf(unparse_file, ";");
00210                     }
00211                 });
00212                 fprintf(unparse_file, "]");
00213                 unparse(p -> fsig_result_sig);
00214                 break;
00215 
00216         case VARSIGNATURE:
00217                 fprintf(unparse_file, "var ");
00218                 unparse(p -> var_denotation);
00219                 break;
00220 
00221         case VALSIGNATURE:
00222                 fprintf(unparse_file, "val ");
00223                 unparse(p -> val_denotation);
00224                 break;
00225 
00226         case SIGNATURESIG:
00227                 fprintf(unparse_file, "signature");
00228                 break;
00229 
00230         case TYPESIGNATURE:
00231                 fprintf(unparse_file, "type ");
00232                 unparse(p -> ts_local_type_id);
00233                 fprintf(unparse_file, "{");
00234                 maplist(s, p -> ts_clist, {
00235                     unparse(s);
00236                     if (s != last(p -> ts_clist)) {
00237                         fprintf(unparse_file, ";");
00238                     }
00239                 });
00240                 fprintf(unparse_file, "}");
00241                 break;
00242 
00243         default:
00244                 dbgmsg("unparse: bad kind, kind = %d\n", p -> kind);
00245                 abort();
00246 
00247     };
00248     return;
00249 }

Generated on Fri Jan 25 10:39:48 2008 for russell by  doxygen 1.5.4