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

Go to the documentation of this file.
00001 #
00002 /*
00003  *  add_id(defnode, scopenode);
00004  *  NODE * defnode, scopenode;
00005  *
00006  *  defnode   - Definition node.
00007  *  scopenode - The root of the subtree for which this definition is valid.
00008  *
00009  *  Add the new definiton of the id to the symbol table and adjust Idtable.
00010  *  The basic operations are:
00011  *      idnode->last_definition = defnode (local type ids only)
00012  *      idnode->use_list = current use list
00013  *      defnode->previous_definition = previous definition (from Idtable)
00014  *      Update Idtable
00015  *      if declaration or parameter, defnode->scope = scopenode
00016  *
00017  *  Nothing is done if idnode is NIL, e.g. in the case of anonymous 
00018  *  parameters.
00019  */
00020 
00021 # include "parm.h"
00022 # include "pass1/stt/sttdefs.h"
00023 # include "stree/ststructs.mh"
00024 # include "Idtable.h"
00025 
00026 extern NODE * usl_ptr;
00027 
00028 static NODE * idnode;
00029 static NODE ** prevdef_field;
00030 
00031 Identry * retrieve();
00032 
00033 add_id(defnode, scopenode)
00034 NODE * defnode, * scopenode;
00035 {   Identry * ip;
00036 
00037     findfields(defnode);
00038     /* update scope fields and set last_definition for local type ids */
00039         switch(defnode->kind) {
00040             case DECLARATION:
00041                 defnode->decl_scope = scopenode;
00042                 break;
00043             case PARAMETER:
00044                 defnode->par_scope = scopenode;
00045                 break;
00046             default:
00047                 if (idnode != NIL) idnode -> id_last_definition = defnode;
00048                 break;
00049         }
00050 
00051     if (idnode == NIL) return;
00052     idnode->id_use_list = usl_ptr;
00053     ip = retrieve(idnode->id_str_table_index);
00054     *prevdef_field = ip->i_value;
00055     ip->i_value = defnode;
00056 }
00057 
00058 /*
00059  *  Given a definition node for an identifier,
00060  *
00061  *  set 
00062  *     idnode to point to the identifier node for the declareed identifier
00063  *     prevdef_field to the address of the field pointing to an enclosing
00064  *          declaration.
00065  */
00066 
00067 static findfields(defnode)
00068 NODE * defnode;
00069 {
00070     switch(defnode->kind) {
00071             case DECLARATION:
00072                 idnode = defnode->decl_id;
00073                 prevdef_field = &(defnode->decl_previous_definition);
00074                 break;
00075             case PARAMETER:
00076                 idnode = defnode->par_id;
00077                 prevdef_field = &(defnode->par_previous_definition);
00078                 break;
00079             case TYPESIGNATURE:
00080                 idnode = defnode->ts_local_type_id;
00081                 prevdef_field = &(defnode->ts_previous_definition);
00082                 break;
00083             case UNIONCONSTRUCTION:
00084             case PRODCONSTRUCTION:
00085                 idnode = defnode->prod_local_type_id;
00086                 prevdef_field = &(defnode->prod_previous_definition);
00087                 break;
00088             case MODPRIMARY:
00089                 {
00090                     NODE * modifier = defnode -> mp_type_modifier;
00091 
00092                     switch(modifier -> kind){
00093                         case WITHLIST:
00094                             idnode = modifier->wl_local_type_id;
00095                             prevdef_field = &(modifier->wl_previous_definition);
00096                             break;
00097                         case EXPORTLIST:
00098                         case HIDELIST:
00099                             idnode = modifier->el_local_type_id;
00100                             prevdef_field = &(modifier->el_previous_definition);
00101                             break;
00102                     }
00103                 }
00104                 break;
00105 #         ifdef DEBUG
00106             default:
00107                     dbgmsg("add_id: bad defnode: kind=%s\n",
00108                             kindname(defnode->kind));
00109 #         endif
00110     }
00111 }

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