X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/95e36146a5be4c921c14f82ab80e3612866c4518..e9f87b5b7df2e328d2e4196d276c0d96594c906b:/src/symtab.c diff --git a/src/symtab.c b/src/symtab.c index 08361539..57ef636e 100644 --- a/src/symtab.c +++ b/src/symtab.c @@ -1,5 +1,5 @@ /* Symbol table manager for Bison, - Copyright (C) 1984, 1989, 2000 Free Software Foundation, Inc. + Copyright 1984, 1989, 2000, 2001 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -20,7 +20,6 @@ #include "system.h" -#include "xalloc.h" #include "symtab.h" #include "gram.h" @@ -43,6 +42,31 @@ hash (const char *key) return k % TABSIZE; } +/*--------------------------------------------------------------. +| Create a new symbol, named TAG, which hash value is HASHVAL. | +`--------------------------------------------------------------*/ + +static bucket * +bucket_new (const char *tag, int hashval) +{ + bucket *res = XMALLOC (bucket, 1); + + res->link = symtab[hashval]; + res->next = NULL; + res->tag = xstrdup (tag); + res->type_name = NULL; + res->value = -1; + res->prec = 0; + res->assoc = right_assoc; + res->user_token_number = SUNDEF; + res->alias = NULL; + res->class = unknown_sym; + + nsyms++; + + return res; +} + void tabinit (void) @@ -54,6 +78,11 @@ tabinit (void) } +/*----------------------------------------------------------------. +| Find the symbol named KEY, and return it. If it does not exist | +| yet, create it. | +`----------------------------------------------------------------*/ + bucket * getsym (const char *key) { @@ -75,13 +104,7 @@ getsym (const char *key) if (found == 0) { - nsyms++; - - bp = XCALLOC (bucket, 1); - bp->link = symtab[hashval]; - bp->next = NULL; - bp->tag = xstrdup (key); - bp->class = unknown_sym; + bp = bucket_new (key, hashval); if (firstsymbol == NULL) { @@ -119,6 +142,7 @@ free_symtab (void) if (bp->type_name) XFREE (bp->type_name); #endif + XFREE (bp->tag); XFREE (bp); bp = bptmp; }