C:/Users/Dennis/src/lang/russell.orig/src/pass2/build_symtab.c

Go to the documentation of this file.
00001 # include <stdio.h>
00002 # include "parm.h"
00003 # include "stree/ststructs.mh"
00004 # include "datatypes/stack.h"
00005 # include "stree/is_ptr.h"
00006 
00007 
00008 extern add_id(), restore();
00009 
00010 /*   Stack of enclosing type signature nodes.
00011  * Used in determining the defining nodes
00012  * for identifiers with a -1 string table index.
00013  * (See streedefs.h.) 
00014  * NOT NEEDED - see process_id.c
00015    STACK lti_stack = emptystack();
00016  */
00017 
00018 /*  Pointer to next surrounding use list.  Used  */
00019 /* to set fields in identifier, string and       */
00020 /* use list nodes.                               */
00021 NODE * usl_ptr = NIL;
00022 
00023 
00024 /*
00025  *  Insert the links comprising the symbol table into the syntax tree.
00026  */
00027 
00028 build_symtab(x)
00029 NODE * x;
00030 {
00031 
00032     if (x == NIL)
00033         /* Ignore missing clauses. */
00034             return;
00035 
00036     switch ( x -> kind ) {
00037 
00038         case LISTHEADER:
00039             /* Process every element on the list. */
00040                 maplist(v, x, build_symtab(v));
00041             break;
00042 
00043 
00044         case DECLARATION: /* Only for program body declaration. */
00045             /* Add id to symtab. */
00046                 add_id(x, x);
00047 
00048             /* Process program body. Leave decl_block pointing to NIL. */
00049                 build_symtab(x->decl_denotation);
00050             break;
00051 
00052 
00053         case PARAMETER:
00054             /* Should never get here. */
00055                 bs_error(x);
00056 
00057 
00058         case RECORDELEMENT:
00059             /* Should never get here. */
00060                 bs_error(x);
00061 
00062 
00063         case VARSIGNATURE:
00064             /* Process denotation. */
00065                 build_symtab(x->var_denotation);
00066             break;
00067 
00068 
00069         case VALSIGNATURE:
00070             /* Process denotation. */
00071                 build_symtab(x->val_denotation);
00072             break;
00073 
00074 
00075         case FUNCSIGNATURE:
00076             /* Add the parameter identifiers to symtab. */
00077                 maplist(v, x->fsig_param_list, add_id(v, x));
00078 
00079             /* Process the parameter signatures and the function */
00080             /* result signature.                                 */
00081                 maplist(v, x->fsig_param_list,
00082                         build_symtab(v->par_signature));
00083                 build_symtab(x->fsig_result_sig);
00084 
00085             /* Restore surrounding scope. */
00086                 maplist(v, x->fsig_param_list, restore(v));
00087             break;
00088              
00089 
00090         case TYPESIGNATURE:
00091             /* Add local id to symtab. */
00092                 add_id(x, x);
00093                 /* push(x,lti_stack); */
00094             /* Process each component signature. */
00095                 maplist(v, x->ts_clist,
00096                             switch (v->kind) {
00097                                 case TSCOMPONENT:
00098                                     /* v -> tsc_id -> id_last_definition = NIL; */
00099                                     build_symtab(v->tsc_signature);
00100                                     break;
00101                                 case DEFCHARSIGS:
00102                                     /* Ignore. */
00103                                     break;
00104                                 default:
00105                                     bs_error(v);
00106                             } );
00107 
00108             /* Restore surrounding scope. */
00109                 restore(x);
00110                 /* pop(lti_stack); */
00111             break;
00112 
00113 
00114         case TSCOMPONENT:
00115             /* Should never get here. */
00116                 bs_error(x);
00117 
00118 
00119         case BLOCKDENOTATION:
00120             /* Add declaration identifiers to symtab. */
00121                 maplist(v, x->bld_declaration_list, add_id(v, x));
00122 
00123             /* Process declaration signatures, declaration denotations, */
00124             /* and the block denotation.                                */
00125                 maplist(v, x->bld_declaration_list,
00126                         { build_symtab(v->decl_signature);
00127                           build_symtab(v->decl_denotation); });
00128                 build_symtab(x->bld_den_seq);
00129 
00130             /* Restore surrounding scope. */
00131                 maplist(v, x->bld_declaration_list, restore(v));
00132             break;
00133 
00134 
00135         case USELIST:
00136             x->usl_previous_list = usl_ptr;
00137             /* Process list of types with old use list. */
00138                 build_symtab(x->usl_type_list);
00139             /* Process body with new use list */
00140                 usl_ptr = x;
00141                 build_symtab(x->usl_den_seq);
00142             /* restore old usl_ptr value */
00143                 usl_ptr = x->usl_previous_list;
00144             break;
00145 
00146 
00147         case APPLICATION:
00148             /* Process operator and args. */
00149                 build_symtab(x->ap_operator);
00150                 build_symtab(x->ap_args);
00151             break;
00152 
00153 
00154         case ENUMERATION:
00155             maplist(v, x -> enum_id_list, {
00156                 x -> id_last_definition = x;
00157             });
00158             break;
00159 
00160 
00161         case EXTENSION:
00162             /* Process denotation. */
00163                 build_symtab(x->ext_denotation);
00164             break;
00165 
00166 
00167         case UNIONCONSTRUCTION:
00168         case PRODCONSTRUCTION:
00169             /* Add local type name to symtab. */
00170                 add_id(x, x);
00171             if (x -> kind == PRODCONSTRUCTION) {
00172               /* Add field names to symtab. */
00173                 maplist(v, x -> prod_components,
00174                         add_id(v,x));
00175             }
00176 
00177             /* Process the component signatures */
00178                 maplist(v, x->prod_components,
00179                         build_symtab(v->par_signature));
00180 
00181             /* Restore surrounding scope. */
00182                 restore(x);
00183                 if (x -> kind == PRODCONSTRUCTION) {
00184                   maplist(v, x -> prod_components,
00185                           restore(v));
00186                 }
00187 
00188             break;
00189              
00190 
00191         case RECORDCONSTRUCTION:
00192             /* Process record component denotations. */
00193                 maplist(v, x->rec_component_list, {
00194                     v -> re_id -> id_last_definition = v -> re_id;
00195                     build_symtab(v->re_denotation);
00196                 });
00197             break;
00198 
00199 
00200         case WITHLIST:
00201             /* Process declaration denotations. */
00202                 maplist(v, x->wl_component_list,
00203                         { 
00204                           v -> decl_id -> id_last_definition = NIL;
00205                           build_symtab(v->decl_signature);
00206                           build_symtab(v->decl_denotation);
00207                         } );
00208 
00209             break;
00210 
00211 
00212         case MODPRIMARY:
00213             /* Process primary and modifier. */
00214                 build_symtab(x->mp_primary);
00215 
00216                 /* add local id to symtab */
00217                     add_id(x,x);
00218 
00219                 build_symtab(x->mp_type_modifier);
00220 
00221                 /* restore surrounding scope */
00222                     restore(x);
00223             break;
00224 
00225 
00226         case EXPORTLIST:
00227         case HIDELIST:
00228             /* Process the export element list. */
00229                 build_symtab(x->el_export_element_list);
00230             break;
00231 
00232         case EXPORTELEMENT:
00233             x -> ee_id -> id_last_definition = x -> ee_id;
00234             build_symtab(x -> ee_signature);
00235             build_symtab(x -> ee_export_list);
00236             break;
00237 
00238         case ALLCONSTANTS:
00239             /* Nothing to do. */
00240             break;
00241 
00242 
00243         case WORDELSE:
00244             /* Nothing to do. */
00245             break;
00246 
00247 
00248         case WORDCAND:
00249             /* Nothing to do. */
00250             break;
00251 
00252 
00253         case WORDCOR:
00254             /* Nothing to do. */
00255             break;
00256 
00257 
00258         case GUARDEDLIST:
00259             /* Process guarded list. */
00260                 build_symtab(x->gl_list);
00261             break;
00262 
00263 
00264         case LOOPDENOTATION:
00265             /* Process guarded list. */
00266                 build_symtab(x->gl_list);
00267             break;
00268 
00269 
00270         case GUARDEDELEMENT:
00271             /* Process guard and element. */
00272                 build_symtab(x->ge_guard);
00273                 build_symtab(x->ge_element);
00274             break;
00275 
00276 
00277         case OPRID: /* Just a use, not a definition. */
00278         case LETTERID:
00279             /* Process selection type and signature */
00280                 build_symtab(x->sel_type);
00281                 build_symtab(x->signature);
00282             /* Fill in last definition field. */
00283                 process_id(x);
00284             break;
00285 
00286 
00287         case QSTR:
00288         case UQSTR:
00289             /* process selection type */
00290                 build_symtab(x -> sel_type);
00291 
00292             /* fill in use list field */
00293                 x->str_use_list = usl_ptr;
00294             break;
00295 
00296 
00297         case FUNCCONSTR:
00298             /* Add the parameter identifiers to symtab. */
00299 #               ifdef DEBUG
00300                   if(!is_ptr(x -> signature) || x -> signature == NIL) {
00301                     dbgmsg("build_symtab: bad fn signature\n");
00302                     abort();
00303                   }
00304 #               endif
00305                 maplist(v, x->signature->fsig_param_list, add_id(v, x));
00306 
00307             /* Process the parameter signatures, the function result */
00308             /* signature, and the function body.                     */
00309                 maplist(v, x->signature->fsig_param_list,
00310                         build_symtab(v->par_signature));
00311                 build_symtab(x->signature->fsig_result_sig);
00312                 build_symtab(x->fc_body);
00313 
00314             /* Restore surrounding scope. */
00315                 maplist(v, x->signature->fsig_param_list, restore(v));
00316             break;
00317 
00318         case REXTERNDEF:
00319         case EXTERNDEF:
00320             break;
00321 
00322     }
00323 }
00324 
00325 
00326 /*
00327  *  bs_error(x)
00328  *
00329  *  Print an error message and abort.
00330  */
00331 bs_error(x)
00332 NODE * x;
00333 {
00334     dbgmsg("build_symtab: bad node: node addr = %o, kind = %s",
00335             x, kindname(x->kind));
00336     abort();
00337 }
00338 
00339 

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