Annotation of 43BSDTahoe/new/xns/compiler/symbols.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (C) 1984 by Eric C. Cooper.
                      3:  * All rights reserved.
                      4:  */
                      5: #ifndef lint
                      6: static char RCSid[] = "$Header: symbols.c,v 2.2 86/06/06 07:28:55 jqj Exp $";
                      7: #endif
                      8: 
                      9: /* $Log:       symbols.c,v $
                     10:  * Revision 2.2  86/06/06  07:28:55  jqj
                     11:  * many mods for better symbol table management:  added CurrentModule,
                     12:  *  made check_dependency, make_symbol, check_def set/use/use a symbol
                     13:  *  table instead of a module name string, etc.  Result is that we can
                     14:  *  now handle DEPENDS UPON 2 versions of same program.
                     15:  * 
                     16:  * Revision 2.1  86/05/16  05:47:08  jqj
                     17:  * make enumeration tags local to modules rather than global, to allow
                     18:  * DEPENDS UPON two versions of the same program.  For same reason, use
                     19:  * gensymed symbol names that include version number.
                     20:  * 
                     21:  * Revision 2.0  85/11/21  07:21:46  jqj
                     22:  * 4.3BSD standard release
                     23:  * 
                     24:  * Revision 1.4  85/03/26  06:10:36  jqj
                     25:  * *** empty log message ***
                     26:  * 
                     27:  * Revision 1.4  85/03/26  06:10:36  jqj
                     28:  * Revised public alpha-test version, released 26 March 1985
                     29:  * 
                     30:  * Revision 1.3  85/03/11  16:40:14  jqj
                     31:  * Public alpha-test version, released 11 March 1985
                     32:  * 
                     33:  * Revision 1.2  85/02/21  11:06:00  jqj
                     34:  * alpha test version
                     35:  * 
                     36:  * Revision 1.1  85/02/15  13:55:40  jqj
                     37:  * Initial revision
                     38:  * 
                     39:  */
                     40: 
                     41: /*
                     42:  * Symbol table management routines
                     43:  */
                     44: 
                     45: #include "compiler.h"
                     46: 
                     47: struct object *SymbolTables;
                     48: struct object *GlobalSymbols;
                     49: /*
                     50: 
                     51:  * Symbol table management.  Find a symbol given a known symbol table.
                     52:  * The routines lookup() and addsymbol() are the ONLY routines that
                     53:  * understand the format of the symbol table, and should be the only
                     54:  * routines that use ocar() and ocdr().
                     55:  */
                     56: static struct object *
                     57: lookup(name, symlist)
                     58:        char *name;
                     59:        struct object *symlist;
                     60: {
                     61:        struct object *op;
                     62: 
                     63:        for (op = symlist; op != ONIL; op = ocdr(op)) {
                     64:                if (streq(op->o_name, name))
                     65:                        return (op);
                     66:        }
                     67:        return (ONIL);
                     68: }
                     69: 
                     70: static struct object *
                     71: addsymbol(name,osymp)
                     72:        char *name;
                     73:        struct object **osymp;
                     74: {
                     75:        struct object *o;
                     76: 
                     77:        o = New(struct object);
                     78:        o->o_class = O_UNKNOWN;
                     79:        /* (jqj)? use binary-tree symboltable here */
                     80:        ocdr(o) = *osymp;
                     81:        *osymp = o;
                     82:        o->o_name = copy(name);
                     83:        return(o);
                     84: }
                     85: 
                     86: struct object *
                     87: make_symbol(name,osym)
                     88:        char *name;
                     89:        struct object *osym;
                     90: {
                     91:        struct object *rsym;
                     92: 
                     93:        if (osym == ONIL) {
                     94:                rsym = addsymbol(name, &(GlobalSymbols->o_symboltable->s_syms));
                     95:                rsym->o_module = "";    /* not NULL */
                     96:                rsym->o_modnumber = 0;
                     97:                rsym->o_modversion = 0;
                     98:                return(rsym);
                     99:        }
                    100:        else {
                    101:                rsym = addsymbol(name, &(osym->o_symboltable->s_syms));
                    102:                rsym->o_module = osym->o_module;
                    103:                rsym->o_modnumber = osym->o_modnumber;
                    104:                rsym->o_modversion = osym->o_modversion;
                    105:                return(rsym);
                    106:        }
                    107: }
                    108: 
                    109: struct object *
                    110: make_module(name,number,version)
                    111:        char *name;             /* Courier module name */
                    112:        char *number;           /* Courier program number */
                    113:        char *version;
                    114: {
                    115:        struct object *symbol;
                    116: 
                    117:        symbol = addsymbol(name, &SymbolTables);
                    118:        if (CurrentModule != (struct object *) NULL)
                    119:                CurrentModule->o_symboltable->s_dependencies =
                    120:                        cons((list)symbol, CurrentModule->o_symboltable->s_dependencies);
                    121:        symbol->o_class = O_SYMBOLTABLE;
                    122:        symbol->o_symboltable = New(struct symtab);
                    123:        symbol->o_name = name;
                    124:        symbol->o_module = name;
                    125:        symbol->o_modnumber = stringtocard(number);
                    126:        symbol->o_modversion = stringtocard(version);
                    127:        return(symbol);
                    128: }
                    129: 
                    130: /*
                    131:  * Check that a program name, number, version group is already defined.
                    132:  * Returns TRUE if name, number, and version all match
                    133:  */
                    134: struct object *
                    135: check_module_def(name,number,version)
                    136:        char *name, *number, *version;
                    137: {
                    138:        struct object *module;
                    139: 
                    140:        if ((module = lookup(name, SymbolTables)) == (struct object *) NULL)
                    141:                return(0);
                    142:        if (stringtocard(version) != module->o_modversion ||
                    143:            stringtocard(number) != module->o_modnumber)
                    144:                return(0);
                    145:        /* should check dependencies here! */
                    146:        if (CurrentModule != (struct object *) NULL)
                    147:                CurrentModule->o_symboltable->s_dependencies =
                    148:                        cons((list)module, CurrentModule->o_symboltable->s_dependencies);
                    149:        return(module);
                    150: }
                    151: 
                    152: /*
                    153:  * Check that a program name was listed in the DEPENDS UPON list.
                    154:  * returns a pointer to the symbol if defined, else 0.
                    155:  */
                    156: struct object *
                    157: check_dependency(name)
                    158:        char *name;
                    159: {
                    160:        list p;
                    161:        
                    162:        if (CurrentModule == ONIL)
                    163:                return(ONIL);
                    164:                
                    165:        for (p = CurrentModule->o_symboltable->s_dependencies;
                    166:             p != NIL; p = cdr(p))
                    167:                if (streq(name,name_of(car(p))))
                    168:                        return((struct object *)car(p));
                    169:        return(ONIL);
                    170: }
                    171: 
                    172: /* (jqj) */
                    173: struct object *
                    174: check_def(symbol,osym)
                    175:        char *symbol;           /* name of the symbol */
                    176:        struct object *osym;    /* symbol table to examine */
                    177: {
                    178:        if (osym == ONIL)
                    179:                osym = GlobalSymbols;
                    180:        return(lookup(symbol, osym->o_symboltable->s_syms));
                    181: }
                    182: 
                    183: 
                    184: static char gensymstr[MAXSTR];
                    185: 
                    186: char *
                    187: gensym(leader)
                    188:        char *leader;
                    189: {
                    190:        static int n;
                    191:        char buf[MAXSTR];
                    192: 
                    193:        (void) sprintf(buf, "%s%s_%d", leader, gensymstr, ++n);
                    194:        return (copy(buf));
                    195: }
                    196: 
                    197: setgensym(number,version)
                    198:        char *number, *version;
                    199: {
                    200:        (void) sprintf(gensymstr,"%s_%s",number,version);
                    201: }
                    202: 
                    203: define_enumeration_symbol(sym, value)
                    204:        struct object *sym;
                    205:        char *value;
                    206: {
                    207:        class_of(sym) = O_ENUMTAG;
                    208:        sym->o_enum = New(struct enumtag);
                    209:        sym->o_enum->en_name = make_full_name( sym->o_module,
                    210:                                sym->o_modversion, name_of(sym));
                    211:        sym->o_enum->en_value = stringtocard(value);
                    212: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.