X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/f5632b7a394d43734e650b5854257b4ffef0e851..ad7871609881e73855d0b04da49b486cd93efca7:/usr/src/usr.bin/pascal/pdx/symtab/symtab.c diff --git a/usr/src/usr.bin/pascal/pdx/symtab/symtab.c b/usr/src/usr.bin/pascal/pdx/symtab/symtab.c index 188a91eb6f..64b7946e79 100644 --- a/usr/src/usr.bin/pascal/pdx/symtab/symtab.c +++ b/usr/src/usr.bin/pascal/pdx/symtab/symtab.c @@ -1,9 +1,42 @@ -/* Copyright (c) 1982 Regents of the University of California */ +/*- + * Copyright (c) 1980, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ -static char sccsid[] = "@(#)symtab.c 1.1 %G%"; +#ifndef lint +static char sccsid[] = "@(#)symtab.c 8.1 (Berkeley) 6/6/93"; +#endif /* not lint */ /* - * symbol table implementation + * Symbol table implementation. */ #include "defs.h" @@ -13,21 +46,21 @@ static char sccsid[] = "@(#)symtab.c 1.1 %G%"; #include "sym/sym.rep" /* - * symbol table structure definition, no deletions allowed. + * The symbol table structure is currently assumes no deletions. */ -#define MAXHASHSIZE 1009 /* largest allowable hash table */ +#define MAXHASHSIZE 1009 /* largest allowable hash table */ struct symtab { - int size; - int hshsize; - SYM **symhsh; - SYM *symarray; - int symindex; + int size; + int hshsize; + SYM **symhsh; + SYM *symarray; + int symindex; }; /* - * symbol table hash macro + * Macro to hash a string. * * The hash value is returned through the "h" parameter which should * an unsigned integer. The other parameters are the symbol table, "st", @@ -36,13 +69,13 @@ struct symtab { #define hash(h, st, name) \ { \ - register char *cp; \ + register char *cp; \ \ - h = 0; \ - for (cp = name; *cp != '\0'; cp++) { \ - h = (h << 1) | (*cp); \ - } \ - h %= st->hshsize; \ + h = 0; \ + for (cp = name; *cp != '\0'; cp++) { \ + h = (h << 1) | (*cp); \ + } \ + h %= st->hshsize; \ } /* @@ -53,30 +86,30 @@ struct symtab { SYMTAB *st_creat(size) int size; { - register SYMTAB *st; - register int i; - - st = alloc(1, SYMTAB); - st->size = size; - st->hshsize = 2*size + 1; - if (st->hshsize > MAXHASHSIZE) { - st->hshsize = MAXHASHSIZE; - } - st->symhsh = alloc(st->hshsize, SYM *); - st->symarray = alloc(st->size, SYM); - st->symindex = 0; - for (i = 0; i < st->hshsize; i++) { - st->symhsh[i] = NIL; - } - return(st); + register SYMTAB *st; + register int i; + + st = alloc(1, SYMTAB); + st->size = size; + st->hshsize = 2*size + 1; + if (st->hshsize > MAXHASHSIZE) { + st->hshsize = MAXHASHSIZE; + } + st->symhsh = alloc(st->hshsize, SYM *); + st->symarray = alloc(st->size, SYM); + st->symindex = 0; + for (i = 0; i < st->hshsize; i++) { + st->symhsh[i] = NIL; + } + return(st); } st_destroy(st) SYMTAB *st; { - dispose(st->symhsh); - dispose(st->symarray); - dispose(st); + dispose(st->symhsh); + dispose(st->symarray); + dispose(st); } /* @@ -87,23 +120,23 @@ SYM *st_insert(st, name) register SYMTAB *st; char *name; { - register SYM *s; - register unsigned int h; - static SYM zerosym; - - if (st == NIL) { - panic("tried to insert into NIL table"); - } - if (st->symindex >= st->size) { - panic("too many symbols"); - } - hash(h, st, name); - s = &(st->symarray[st->symindex++]); - *s = zerosym; - s->symbol = name; - s->next_sym = st->symhsh[h]; - st->symhsh[h] = s; - return(s); + register SYM *s; + register unsigned int h; + static SYM zerosym; + + if (st == NIL) { + panic("tried to insert into NIL table"); + } + if (st->symindex >= st->size) { + panic("too many symbols"); + } + hash(h, st, name); + s = &(st->symarray[st->symindex++]); + *s = zerosym; + s->symbol = name; + s->next_sym = st->symhsh[h]; + st->symhsh[h] = s; + return(s); } /* @@ -114,19 +147,19 @@ SYM *st_lookup(st, name) SYMTAB *st; char *name; { - register SYM *s; - register unsigned int h; - - if (st == NIL) { - panic("tried to lookup in NIL table"); + register SYM *s; + register unsigned int h; + + if (st == NIL) { + panic("tried to lookup in NIL table"); + } + hash(h, st, name); + for (s = st->symhsh[h]; s != NIL; s = s->next_sym) { + if (strcmp(s->symbol, name) == 0) { + break; } - hash(h, st, name); - for (s = st->symhsh[h]; s != NIL; s = s->next_sym) { - if (strcmp(s->symbol, name) == 0) { - break; - } - } - return(s); + } + return(s); } /* @@ -142,17 +175,17 @@ dumpvars(f, frame) SYM *f; FRAME *frame; { - register SYM *s; - SYM *first, *last; - - first = symtab->symarray; - last = first + symtab->symindex - 1; - for (s = first; s <= last; s++) { - if (should_print(s, f)) { - printv(s, frame); - putchar('\n'); - } + register SYM *s; + SYM *first, *last; + + first = symtab->symarray; + last = first + symtab->symindex - 1; + for (s = first; s <= last; s++) { + if (should_print(s, f)) { + printv(s, frame); + putchar('\n'); } + } } /* @@ -166,19 +199,19 @@ enter_alias(table, new, old) SYMTAB *table; char *new, *old; { - SYM *s, *t; - - if ((s = st_lookup(table, old)) == NIL) { - error("%s is not a known command", old); - } - if (st_lookup(table, new) != NIL) { - error("cannot alias command names"); - } - make_keyword(table, new, s->symvalue.token.toknum); - t = st_insert(table, new); - t->blkno = 1; - t->symvalue.token.toknum = s->symvalue.token.toknum; - t->type = s; + SYM *s, *t; + + if ((s = st_lookup(table, old)) == NIL) { + error("%s is not a known command", old); + } + if (st_lookup(table, new) != NIL) { + error("cannot alias command names"); + } + make_keyword(table, new, s->symvalue.token.toknum); + t = st_insert(table, new); + t->blkno = 1; + t->symvalue.token.toknum = s->symvalue.token.toknum; + t->type = s; } /* @@ -191,24 +224,24 @@ print_alias(table, name) SYMTAB *table; char *name; { - SYM *s, *t; - SYM *first, *last; - - if (name != NIL) { - s = st_lookup(table, name); - if (s == NIL) { - error("\"%s\" is not an alias", name); - } - printf("%s\n", s->type->symbol); - } else { - first = table->symarray; - last = first + table->symindex - 1; - for (s = first; s <= last; s++) { - if (s->blkno == 1) { - printf("%s\t%s\n", s->symbol, s->type->symbol); - } - } + SYM *s; + SYM *first, *last; + + if (name != NIL) { + s = st_lookup(table, name); + if (s == NIL) { + error("\"%s\" is not an alias", name); } + printf("%s\n", s->type->symbol); + } else { + first = table->symarray; + last = first + table->symindex - 1; + for (s = first; s <= last; s++) { + if (s->blkno == 1) { + printf("%s\t%s\n", s->symbol, s->type->symbol); + } + } + } } /* @@ -216,26 +249,26 @@ char *name; * This is necessary because of the way pi keeps symbols. */ -#define NSYMS_BACK 20 /* size of local context to try */ +#define NSYMS_BACK 20 /* size of local context to try */ LOCAL SYM *search(); SYM *findtype(t) SYM *t; { - SYM *s; - SYM *first, *last; - SYM *lower; - - first = symtab->symarray; - last = first + symtab->symindex - 1; - if ((lower = t - NSYMS_BACK) < first) { - lower = first; - } - if ((s = search(t, lower, last)) == NIL) { - s = search(t, first, last); - } - return(s); + SYM *s; + SYM *first, *last; + SYM *lower; + + first = symtab->symarray; + last = first + symtab->symindex - 1; + if ((lower = t - NSYMS_BACK) < first) { + lower = first; + } + if ((s = search(t, lower, last)) == NIL) { + s = search(t, first, last); + } + return(s); } /* @@ -247,12 +280,12 @@ LOCAL SYM *search(t, first, last) SYM *t; register SYM *first, *last; { - register SYM *s; + register SYM *s; - for (s = first; s <= last; s++) { - if (s->class == TYPE && s->type == t && s->symbol != NIL) { - return(s); - } + for (s = first; s <= last; s++) { + if (s->class == TYPE && s->type == t && s->symbol != NIL) { + return(s); } - return(NIL); + } + return(NIL); }