mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-20 01:33:03 +00:00
Rename all the bucket's as symbol_t'.
* src/gram.c, src/gram.h, src/lex.c, src/lex.h, src/output.c, * src/reader.c, src/reader.h, src/reduce.c, src/state.h, * src/symtab.c, src/symtab.h (bucket): Rename as... (symbol_t): this. (symbol_list_new, bucket_check_defined, bucket_make_alias) (bucket_check_alias_consistence, bucket_pack, bucket_translation) (bucket_new, bucket_free, hash_compare_bucket, hash_bucket) (buckets_new, buckets_free, buckets_do): Rename as... (symbol_list_new, symbol_check_defined, symbol_make_alias) (symbol_check_alias_consistence, symbol_pack, symbol_translation) (symbol_new, symbol_free, hash_compare_symbol_t, hash_symbol_t) (symbols_new, symbols_free, symbols_do): these.
This commit is contained in:
18
ChangeLog
18
ChangeLog
@@ -1,3 +1,21 @@
|
|||||||
|
2002-04-07 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
Rename all the `bucket's as `symbol_t'.
|
||||||
|
|
||||||
|
* src/gram.c, src/gram.h, src/lex.c, src/lex.h, src/output.c,
|
||||||
|
* src/reader.c, src/reader.h, src/reduce.c, src/state.h,
|
||||||
|
* src/symtab.c, src/symtab.h (bucket): Rename as...
|
||||||
|
(symbol_t): this.
|
||||||
|
(symbol_list_new, bucket_check_defined, bucket_make_alias)
|
||||||
|
(bucket_check_alias_consistence, bucket_pack, bucket_translation)
|
||||||
|
(bucket_new, bucket_free, hash_compare_bucket, hash_bucket)
|
||||||
|
(buckets_new, buckets_free, buckets_do): Rename as...
|
||||||
|
(symbol_list_new, symbol_check_defined, symbol_make_alias)
|
||||||
|
(symbol_check_alias_consistence, symbol_pack, symbol_translation)
|
||||||
|
(symbol_new, symbol_free, hash_compare_symbol_t, hash_symbol_t)
|
||||||
|
(symbols_new, symbols_free, symbols_do): these.
|
||||||
|
|
||||||
|
|
||||||
2002-04-07 Akim Demaille <akim@epita.fr>
|
2002-04-07 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
Use lib/hash for the symbol table.
|
Use lib/hash for the symbol table.
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ int nritems = 0;
|
|||||||
|
|
||||||
rule_t *rules = NULL;
|
rule_t *rules = NULL;
|
||||||
|
|
||||||
struct bucket **symbols = NULL;
|
symbol_t **symbols = NULL;
|
||||||
short *token_translations = NULL;
|
short *token_translations = NULL;
|
||||||
|
|
||||||
int start_symbol = 0;
|
int start_symbol = 0;
|
||||||
|
|||||||
@@ -125,14 +125,14 @@ typedef struct rule_s
|
|||||||
except if some rules are useless. */
|
except if some rules are useless. */
|
||||||
short number;
|
short number;
|
||||||
|
|
||||||
bucket *lhs;
|
symbol_t *lhs;
|
||||||
short *rhs;
|
short *rhs;
|
||||||
|
|
||||||
/* This symbol provides both the associativity, and the precedence. */
|
/* This symbol provides both the associativity, and the precedence. */
|
||||||
bucket *prec;
|
symbol_t *prec;
|
||||||
|
|
||||||
/* This symbol was attached to the rule via %prec. */
|
/* This symbol was attached to the rule via %prec. */
|
||||||
bucket *precsym;
|
symbol_t *precsym;
|
||||||
|
|
||||||
short line;
|
short line;
|
||||||
bool useful;
|
bool useful;
|
||||||
@@ -147,7 +147,7 @@ typedef struct rule_s
|
|||||||
extern struct rule_s *rules;
|
extern struct rule_s *rules;
|
||||||
|
|
||||||
/* Table of the symbols, indexed by the symbol number. */
|
/* Table of the symbols, indexed by the symbol number. */
|
||||||
extern struct bucket **symbols;
|
extern symbol_t **symbols;
|
||||||
|
|
||||||
/* token translation table: indexed by a token number as returned by
|
/* token translation table: indexed by a token number as returned by
|
||||||
the user's yylex routine, it yields the internal token number used
|
the user's yylex routine, it yields the internal token number used
|
||||||
|
|||||||
@@ -32,12 +32,12 @@
|
|||||||
static struct obstack token_obstack;
|
static struct obstack token_obstack;
|
||||||
const char *token_buffer = NULL;
|
const char *token_buffer = NULL;
|
||||||
|
|
||||||
bucket *symval = NULL;
|
symbol_t *symval = NULL;
|
||||||
int numval;
|
int numval;
|
||||||
|
|
||||||
/* A token to be reread, see unlex and lex. */
|
/* A token to be reread, see unlex and lex. */
|
||||||
static token_t unlexed = tok_undef;
|
static token_t unlexed = tok_undef;
|
||||||
static bucket *unlexed_symval = NULL;
|
static symbol_t *unlexed_symval = NULL;
|
||||||
static const char *unlexed_token_buffer = NULL;
|
static const char *unlexed_token_buffer = NULL;
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ typedef enum token_e
|
|||||||
} token_t;
|
} token_t;
|
||||||
|
|
||||||
extern const char *token_buffer;
|
extern const char *token_buffer;
|
||||||
extern bucket *symval;
|
extern symbol_t *symval;
|
||||||
extern int numval;
|
extern int numval;
|
||||||
|
|
||||||
void lex_init PARAMS ((void));
|
void lex_init PARAMS ((void));
|
||||||
|
|||||||
@@ -561,7 +561,7 @@ token_definitions_output (FILE *out)
|
|||||||
int first = 1;
|
int first = 1;
|
||||||
for (i = 0; i < ntokens; ++i)
|
for (i = 0; i < ntokens; ++i)
|
||||||
{
|
{
|
||||||
bucket *symbol = symbols[i];
|
symbol_t *symbol = symbols[i];
|
||||||
int number = symbol->user_token_number;
|
int number = symbol->user_token_number;
|
||||||
|
|
||||||
if (number == SALIAS)
|
if (number == SALIAS)
|
||||||
|
|||||||
64
src/reader.c
64
src/reader.c
@@ -38,7 +38,7 @@
|
|||||||
typedef struct symbol_list
|
typedef struct symbol_list
|
||||||
{
|
{
|
||||||
struct symbol_list *next;
|
struct symbol_list *next;
|
||||||
bucket *sym;
|
symbol_t *sym;
|
||||||
int line;
|
int line;
|
||||||
|
|
||||||
/* The action is attached to the LHS of a rule. */
|
/* The action is attached to the LHS of a rule. */
|
||||||
@@ -48,13 +48,13 @@ typedef struct symbol_list
|
|||||||
/* The guard is attached to the LHS of a rule. */
|
/* The guard is attached to the LHS of a rule. */
|
||||||
const char *guard;
|
const char *guard;
|
||||||
int guard_line;
|
int guard_line;
|
||||||
bucket *ruleprec;
|
symbol_t *ruleprec;
|
||||||
} symbol_list;
|
} symbol_list;
|
||||||
|
|
||||||
int lineno;
|
int lineno;
|
||||||
static symbol_list *grammar = NULL;
|
static symbol_list *grammar = NULL;
|
||||||
static int start_flag = 0;
|
static int start_flag = 0;
|
||||||
static bucket *startval = NULL;
|
static symbol_t *startval = NULL;
|
||||||
|
|
||||||
/* Nonzero if components of semantic values are used, implying
|
/* Nonzero if components of semantic values are used, implying
|
||||||
they must be unions. */
|
they must be unions. */
|
||||||
@@ -66,13 +66,13 @@ static int typed = 0;
|
|||||||
/* Incremented for each %left, %right or %nonassoc seen */
|
/* Incremented for each %left, %right or %nonassoc seen */
|
||||||
static int lastprec = 0;
|
static int lastprec = 0;
|
||||||
|
|
||||||
bucket *errtoken = NULL;
|
symbol_t *errtoken = NULL;
|
||||||
bucket *undeftoken = NULL;
|
symbol_t *undeftoken = NULL;
|
||||||
bucket *eoftoken = NULL;
|
symbol_t *eoftoken = NULL;
|
||||||
bucket *axiom = NULL;
|
symbol_t *axiom = NULL;
|
||||||
|
|
||||||
static symbol_list *
|
static symbol_list *
|
||||||
symbol_list_new (bucket *sym)
|
symbol_list_new (symbol_t *sym)
|
||||||
{
|
{
|
||||||
symbol_list *res = XMALLOC (symbol_list, 1);
|
symbol_list *res = XMALLOC (symbol_list, 1);
|
||||||
res->next = NULL;
|
res->next = NULL;
|
||||||
@@ -87,7 +87,7 @@ symbol_list_new (bucket *sym)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------.
|
/*------------------------.
|
||||||
| Operations on buckets. |
|
| Operations on symbols. |
|
||||||
`------------------------*/
|
`------------------------*/
|
||||||
|
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ symbol_list_new (bucket *sym)
|
|||||||
`-----------------------------------------------------------*/
|
`-----------------------------------------------------------*/
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
bucket_check_defined (bucket *this)
|
symbol_check_defined (symbol_t *this)
|
||||||
{
|
{
|
||||||
if (this->class == unknown_sym)
|
if (this->class == unknown_sym)
|
||||||
{
|
{
|
||||||
@@ -118,7 +118,7 @@ bucket_check_defined (bucket *this)
|
|||||||
`-------------------------------------------------------------------*/
|
`-------------------------------------------------------------------*/
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
bucket_make_alias (bucket *symbol, char *typename)
|
symbol_make_alias (symbol_t *symbol, char *typename)
|
||||||
{
|
{
|
||||||
if (symval->alias)
|
if (symval->alias)
|
||||||
warn (_("symbol `%s' used more than once as a literal string"),
|
warn (_("symbol `%s' used more than once as a literal string"),
|
||||||
@@ -151,7 +151,7 @@ bucket_make_alias (bucket *symbol, char *typename)
|
|||||||
`---------------------------------------------------------*/
|
`---------------------------------------------------------*/
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
bucket_check_alias_consistence (bucket *this)
|
symbol_check_alias_consistence (symbol_t *this)
|
||||||
{
|
{
|
||||||
/* Check only those who _are_ the aliases. */
|
/* Check only those who _are_ the aliases. */
|
||||||
if (this->alias && this->user_token_number == SALIAS)
|
if (this->alias && this->user_token_number == SALIAS)
|
||||||
@@ -188,7 +188,7 @@ bucket_check_alias_consistence (bucket *this)
|
|||||||
`-------------------------------------------------------------------*/
|
`-------------------------------------------------------------------*/
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
bucket_pack (bucket *this)
|
symbol_pack (symbol_t *this)
|
||||||
{
|
{
|
||||||
if (getenv ("DEBUG"))
|
if (getenv ("DEBUG"))
|
||||||
fprintf (stderr, "Packing %s, %s, number = %d\n",
|
fprintf (stderr, "Packing %s, %s, number = %d\n",
|
||||||
@@ -237,7 +237,7 @@ bucket_pack (bucket *this)
|
|||||||
`--------------------------------------------------*/
|
`--------------------------------------------------*/
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
bucket_translation (bucket *this)
|
symbol_translation (symbol_t *this)
|
||||||
{
|
{
|
||||||
if (getenv ("DEBUG"))
|
if (getenv ("DEBUG"))
|
||||||
fprintf (stderr, "Considering Setting UserVal %s = %d (val = %d)\n",
|
fprintf (stderr, "Considering Setting UserVal %s = %d (val = %d)\n",
|
||||||
@@ -677,7 +677,7 @@ parse_token_decl (symbol_class what_is, symbol_class what_is_not)
|
|||||||
char *typename = NULL;
|
char *typename = NULL;
|
||||||
|
|
||||||
/* The symbol being defined. */
|
/* The symbol being defined. */
|
||||||
struct bucket *symbol = NULL;
|
symbol_t *symbol = NULL;
|
||||||
|
|
||||||
/* After `%token' and `%nterm', any number of symbols maybe be
|
/* After `%token' and `%nterm', any number of symbols maybe be
|
||||||
defined. */
|
defined. */
|
||||||
@@ -706,7 +706,7 @@ parse_token_decl (symbol_class what_is, symbol_class what_is_not)
|
|||||||
}
|
}
|
||||||
else if (token == tok_identifier && *symval->tag == '\"' && symbol)
|
else if (token == tok_identifier && *symval->tag == '\"' && symbol)
|
||||||
{
|
{
|
||||||
bucket_make_alias (symbol, typename);
|
symbol_make_alias (symbol, typename);
|
||||||
symbol = NULL;
|
symbol = NULL;
|
||||||
}
|
}
|
||||||
else if (token == tok_identifier)
|
else if (token == tok_identifier)
|
||||||
@@ -1023,7 +1023,7 @@ static void
|
|||||||
parse_thong_decl (void)
|
parse_thong_decl (void)
|
||||||
{
|
{
|
||||||
token_t token;
|
token_t token;
|
||||||
struct bucket *symbol;
|
symbol_t *symbol;
|
||||||
char *typename = 0;
|
char *typename = 0;
|
||||||
int usrtoknum = SUNDEF;
|
int usrtoknum = SUNDEF;
|
||||||
|
|
||||||
@@ -1365,14 +1365,14 @@ parse_guard (symbol_list *rule, int stack_offset)
|
|||||||
| with the user's names. |
|
| with the user's names. |
|
||||||
`-------------------------------------------------------------------*/
|
`-------------------------------------------------------------------*/
|
||||||
|
|
||||||
static bucket *
|
static symbol_t *
|
||||||
gensym (void)
|
gensym (void)
|
||||||
{
|
{
|
||||||
/* Incremented for each generated symbol */
|
/* Incremented for each generated symbol */
|
||||||
static int gensym_count = 0;
|
static int gensym_count = 0;
|
||||||
static char buf[256];
|
static char buf[256];
|
||||||
|
|
||||||
bucket *sym;
|
symbol_t *sym;
|
||||||
|
|
||||||
sprintf (buf, "@%d", ++gensym_count);
|
sprintf (buf, "@%d", ++gensym_count);
|
||||||
token_buffer = buf;
|
token_buffer = buf;
|
||||||
@@ -1404,7 +1404,7 @@ static void
|
|||||||
readgram (void)
|
readgram (void)
|
||||||
{
|
{
|
||||||
token_t t;
|
token_t t;
|
||||||
bucket *lhs = NULL;
|
symbol_t *lhs = NULL;
|
||||||
symbol_list *p = NULL;
|
symbol_list *p = NULL;
|
||||||
symbol_list *p1 = NULL;
|
symbol_list *p1 = NULL;
|
||||||
|
|
||||||
@@ -1423,7 +1423,7 @@ readgram (void)
|
|||||||
/* Number of symbols in rhs of this rule so far */
|
/* Number of symbols in rhs of this rule so far */
|
||||||
int rulelength = 0;
|
int rulelength = 0;
|
||||||
int xactions = 0; /* JF for error checking */
|
int xactions = 0; /* JF for error checking */
|
||||||
bucket *first_rhs = 0;
|
symbol_t *first_rhs = 0;
|
||||||
|
|
||||||
if (t == tok_identifier)
|
if (t == tok_identifier)
|
||||||
{
|
{
|
||||||
@@ -1494,7 +1494,7 @@ readgram (void)
|
|||||||
If one does, exit this rule now. */
|
If one does, exit this rule now. */
|
||||||
if (t == tok_identifier)
|
if (t == tok_identifier)
|
||||||
{
|
{
|
||||||
bucket *ssave;
|
symbol_t *ssave;
|
||||||
token_t t1;
|
token_t t1;
|
||||||
|
|
||||||
ssave = symval;
|
ssave = symval;
|
||||||
@@ -1523,7 +1523,7 @@ readgram (void)
|
|||||||
inserting the new rule before it. */
|
inserting the new rule before it. */
|
||||||
|
|
||||||
/* Make a dummy nonterminal, a gensym. */
|
/* Make a dummy nonterminal, a gensym. */
|
||||||
bucket *sdummy = gensym ();
|
symbol_t *sdummy = gensym ();
|
||||||
|
|
||||||
/* Make a new rule, whose body is empty, before the
|
/* Make a new rule, whose body is empty, before the
|
||||||
current one, so that the action just read can
|
current one, so that the action just read can
|
||||||
@@ -1638,7 +1638,7 @@ readgram (void)
|
|||||||
fatal (_("no rules in the input grammar"));
|
fatal (_("no rules in the input grammar"));
|
||||||
|
|
||||||
/* Report any undefined symbols and consider them nonterminals. */
|
/* Report any undefined symbols and consider them nonterminals. */
|
||||||
buckets_do (bucket_check_defined, NULL);
|
symbols_do (symbol_check_defined, NULL);
|
||||||
|
|
||||||
/* Insert the initial rule, which line is that of the first rule
|
/* Insert the initial rule, which line is that of the first rule
|
||||||
(not that of the start symbol):
|
(not that of the start symbol):
|
||||||
@@ -1705,7 +1705,7 @@ token_translations_init (void)
|
|||||||
/* Set the user numbers. */
|
/* Set the user numbers. */
|
||||||
for (i = 0; i < ntokens; ++i)
|
for (i = 0; i < ntokens; ++i)
|
||||||
{
|
{
|
||||||
bucket *this = symbols[i];
|
symbol_t *this = symbols[i];
|
||||||
if (getenv ("DEBUG"))
|
if (getenv ("DEBUG"))
|
||||||
fprintf (stderr, "UserVal %s = %d (val = %d)\n",
|
fprintf (stderr, "UserVal %s = %d (val = %d)\n",
|
||||||
this->tag, this->user_token_number, this->number);
|
this->tag, this->user_token_number, this->number);
|
||||||
@@ -1726,7 +1726,7 @@ token_translations_init (void)
|
|||||||
for (i = 0; i < max_user_token_number + 1; i++)
|
for (i = 0; i < max_user_token_number + 1; i++)
|
||||||
token_translations[i] = 2;
|
token_translations[i] = 2;
|
||||||
|
|
||||||
buckets_do (bucket_translation, NULL);
|
symbols_do (symbol_translation, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1738,10 +1738,10 @@ token_translations_init (void)
|
|||||||
static void
|
static void
|
||||||
packsymbols (void)
|
packsymbols (void)
|
||||||
{
|
{
|
||||||
symbols = XCALLOC (bucket *, nsyms);
|
symbols = XCALLOC (symbol_t *, nsyms);
|
||||||
|
|
||||||
buckets_do (bucket_check_alias_consistence, NULL);
|
symbols_do (symbol_check_alias_consistence, NULL);
|
||||||
buckets_do (bucket_pack, NULL);
|
symbols_do (symbol_pack, NULL);
|
||||||
|
|
||||||
token_translations_init ();
|
token_translations_init ();
|
||||||
|
|
||||||
@@ -1781,7 +1781,7 @@ packgram (void)
|
|||||||
p = grammar;
|
p = grammar;
|
||||||
while (p)
|
while (p)
|
||||||
{
|
{
|
||||||
bucket *ruleprec = p->ruleprec;
|
symbol_t *ruleprec = p->ruleprec;
|
||||||
rules[ruleno].user_number = ruleno;
|
rules[ruleno].user_number = ruleno;
|
||||||
rules[ruleno].number = ruleno;
|
rules[ruleno].number = ruleno;
|
||||||
rules[ruleno].lhs = p->sym;
|
rules[ruleno].lhs = p->sym;
|
||||||
@@ -1845,7 +1845,7 @@ reader (void)
|
|||||||
obstack_init (&muscle_obstack);
|
obstack_init (&muscle_obstack);
|
||||||
|
|
||||||
/* Initialize the symbol table. */
|
/* Initialize the symbol table. */
|
||||||
buckets_new ();
|
symbols_new ();
|
||||||
|
|
||||||
/* Construct the axiom symbol. */
|
/* Construct the axiom symbol. */
|
||||||
axiom = getsym ("$axiom");
|
axiom = getsym ("$axiom");
|
||||||
@@ -1913,5 +1913,5 @@ grammar_free (void)
|
|||||||
XFREE (ritem);
|
XFREE (ritem);
|
||||||
free (rules + 1);
|
free (rules + 1);
|
||||||
/* Free the symbol table data structure. */
|
/* Free the symbol table data structure. */
|
||||||
buckets_free ();
|
symbols_free ();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,9 +36,9 @@ void grammar_free PARAMS ((void));
|
|||||||
|
|
||||||
extern int lineno;
|
extern int lineno;
|
||||||
|
|
||||||
extern bucket *errtoken;
|
extern symbol_t *errtoken;
|
||||||
extern bucket *undeftoken;
|
extern symbol_t *undeftoken;
|
||||||
extern bucket *eoftoken;
|
extern symbol_t *eoftoken;
|
||||||
extern bucket *axiom;
|
extern symbol_t *axiom;
|
||||||
|
|
||||||
#endif /* !READER_H_ */
|
#endif /* !READER_H_ */
|
||||||
|
|||||||
@@ -299,7 +299,7 @@ nonterminals_reduce (void)
|
|||||||
|
|
||||||
/* Shuffle elements of tables indexed by symbol number. */
|
/* Shuffle elements of tables indexed by symbol number. */
|
||||||
{
|
{
|
||||||
bucket **symbols_sorted = XMALLOC (bucket *, nvars) - ntokens;
|
symbol_t **symbols_sorted = XMALLOC (symbol_t *, nvars) - ntokens;
|
||||||
|
|
||||||
for (i = ntokens; i < nsyms; i++)
|
for (i = ntokens; i < nsyms; i++)
|
||||||
symbols[i]->number = nontermmap[i];
|
symbols[i]->number = nontermmap[i];
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
Each core contains a vector of nitems items which are the indices
|
Each core contains a vector of nitems items which are the indices
|
||||||
in the ritems vector of the items that are selected in this state.
|
in the ritems vector of the items that are selected in this state.
|
||||||
|
|
||||||
The link field is used for chaining buckets that hash states by
|
The link field is used for chaining symbols that hash states by
|
||||||
their itemsets. This is for recognizing equivalent states and
|
their itemsets. This is for recognizing equivalent states and
|
||||||
combining them when the states are generated.
|
combining them when the states are generated.
|
||||||
|
|
||||||
|
|||||||
54
src/symtab.c
54
src/symtab.c
@@ -28,10 +28,10 @@
|
|||||||
| Create a new symbol, named TAG. |
|
| Create a new symbol, named TAG. |
|
||||||
`---------------------------------*/
|
`---------------------------------*/
|
||||||
|
|
||||||
static bucket *
|
static symbol_t *
|
||||||
bucket_new (const char *tag)
|
symbol_new (const char *tag)
|
||||||
{
|
{
|
||||||
bucket *res = XMALLOC (bucket, 1);
|
symbol_t *res = XMALLOC (symbol_t, 1);
|
||||||
|
|
||||||
res->tag = xstrdup (tag);
|
res->tag = xstrdup (tag);
|
||||||
res->type_name = NULL;
|
res->type_name = NULL;
|
||||||
@@ -56,7 +56,7 @@ bucket_new (const char *tag)
|
|||||||
`------------*/
|
`------------*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bucket_free (bucket *this)
|
symbol_free (symbol_t *this)
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
/* This causes crashes because one string can appear more
|
/* This causes crashes because one string can appear more
|
||||||
@@ -70,39 +70,39 @@ bucket_free (bucket *this)
|
|||||||
|
|
||||||
|
|
||||||
/*----------------------.
|
/*----------------------.
|
||||||
| A bucket hash table. |
|
| A symbol_t hash table. |
|
||||||
`----------------------*/
|
`----------------------*/
|
||||||
|
|
||||||
/* Initial capacity of buckets hash table. */
|
/* Initial capacity of symbols hash table. */
|
||||||
#define HT_INITIAL_CAPACITY 257
|
#define HT_INITIAL_CAPACITY 257
|
||||||
|
|
||||||
static struct hash_table *bucket_table = NULL;
|
static struct hash_table *symbol_table = NULL;
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
hash_compare_bucket (const bucket *m1, const bucket *m2)
|
hash_compare_symbol_t (const symbol_t *m1, const symbol_t *m2)
|
||||||
{
|
{
|
||||||
return strcmp (m1->tag, m2->tag) ? FALSE : TRUE;
|
return strcmp (m1->tag, m2->tag) ? FALSE : TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int
|
static unsigned int
|
||||||
hash_bucket (const bucket *m, unsigned int tablesize)
|
hash_symbol_t (const symbol_t *m, unsigned int tablesize)
|
||||||
{
|
{
|
||||||
return hash_string (m->tag, tablesize);
|
return hash_string (m->tag, tablesize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------.
|
/*-------------------------------.
|
||||||
| Create the bucket hash table. |
|
| Create the symbol_t hash table. |
|
||||||
`-------------------------------*/
|
`-------------------------------*/
|
||||||
|
|
||||||
void
|
void
|
||||||
buckets_new (void)
|
symbols_new (void)
|
||||||
{
|
{
|
||||||
bucket_table = hash_initialize (HT_INITIAL_CAPACITY,
|
symbol_table = hash_initialize (HT_INITIAL_CAPACITY,
|
||||||
NULL,
|
NULL,
|
||||||
(Hash_hasher) hash_bucket,
|
(Hash_hasher) hash_symbol_t,
|
||||||
(Hash_comparator) hash_compare_bucket,
|
(Hash_comparator) hash_compare_symbol_t,
|
||||||
(Hash_data_freer) bucket_free);
|
(Hash_data_freer) symbol_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -111,45 +111,45 @@ buckets_new (void)
|
|||||||
| yet, create it. |
|
| yet, create it. |
|
||||||
`----------------------------------------------------------------*/
|
`----------------------------------------------------------------*/
|
||||||
|
|
||||||
bucket *
|
symbol_t *
|
||||||
getsym (const char *key)
|
getsym (const char *key)
|
||||||
{
|
{
|
||||||
bucket probe;
|
symbol_t probe;
|
||||||
bucket *entry;
|
symbol_t *entry;
|
||||||
|
|
||||||
(const char *) probe.tag = key;
|
(const char *) probe.tag = key;
|
||||||
entry = hash_lookup (bucket_table, &probe);
|
entry = hash_lookup (symbol_table, &probe);
|
||||||
|
|
||||||
if (!entry)
|
if (!entry)
|
||||||
{
|
{
|
||||||
/* First insertion in the hash. */
|
/* First insertion in the hash. */
|
||||||
entry = bucket_new (key);
|
entry = symbol_new (key);
|
||||||
hash_insert (bucket_table, entry);
|
hash_insert (symbol_table, entry);
|
||||||
}
|
}
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-------------------.
|
/*-------------------.
|
||||||
| Free the buckets. |
|
| Free the symbols. |
|
||||||
`-------------------*/
|
`-------------------*/
|
||||||
|
|
||||||
void
|
void
|
||||||
buckets_free (void)
|
symbols_free (void)
|
||||||
{
|
{
|
||||||
hash_free (bucket_table);
|
hash_free (symbol_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------.
|
/*---------------------------------------------------------------.
|
||||||
| Look for undefined buckets, report an error, and consider them |
|
| Look for undefined symbols, report an error, and consider them |
|
||||||
| terminals. |
|
| terminals. |
|
||||||
`---------------------------------------------------------------*/
|
`---------------------------------------------------------------*/
|
||||||
|
|
||||||
void
|
void
|
||||||
buckets_do (bucket_processor processor, void *processor_data)
|
symbols_do (symbol_processor processor, void *processor_data)
|
||||||
{
|
{
|
||||||
hash_do_for_each (bucket_table,
|
hash_do_for_each (symbol_table,
|
||||||
(Hash_processor) processor,
|
(Hash_processor) processor,
|
||||||
processor_data);
|
processor_data);
|
||||||
}
|
}
|
||||||
|
|||||||
18
src/symtab.h
18
src/symtab.h
@@ -44,7 +44,7 @@ typedef enum
|
|||||||
#define SUNDEF -1 /* For undefined user number. */
|
#define SUNDEF -1 /* For undefined user number. */
|
||||||
#define SALIAS -9991 /* for symbol generated with an alias */
|
#define SALIAS -9991 /* for symbol generated with an alias */
|
||||||
|
|
||||||
typedef struct bucket
|
struct symbol_s
|
||||||
{
|
{
|
||||||
/* The key, name of the symbol. */
|
/* The key, name of the symbol. */
|
||||||
char *tag;
|
char *tag;
|
||||||
@@ -58,17 +58,19 @@ typedef struct bucket
|
|||||||
/* Points to the other in the identifier-symbol pair for an
|
/* Points to the other in the identifier-symbol pair for an
|
||||||
alias. Special value SALIAS in the identifier half of the
|
alias. Special value SALIAS in the identifier half of the
|
||||||
identifier-symbol pair for an alias. */
|
identifier-symbol pair for an alias. */
|
||||||
struct bucket *alias;
|
struct symbol_s *alias;
|
||||||
symbol_class class;
|
symbol_class class;
|
||||||
} bucket;
|
};
|
||||||
|
|
||||||
|
typedef struct symbol_s symbol_t;
|
||||||
|
|
||||||
/* A function to apply to each symbol. */
|
/* A function to apply to each symbol. */
|
||||||
typedef bool (*bucket_processor) PARAMS ((bucket *));
|
typedef bool (*symbol_processor) PARAMS ((symbol_t *));
|
||||||
|
|
||||||
bucket *getsym PARAMS ((const char *));
|
symbol_t *getsym PARAMS ((const char *));
|
||||||
|
|
||||||
void buckets_new PARAMS ((void));
|
void symbols_new PARAMS ((void));
|
||||||
void buckets_do PARAMS ((bucket_processor processor, void *processor_data));
|
void symbols_do PARAMS ((symbol_processor processor, void *processor_data));
|
||||||
void buckets_free PARAMS ((void));
|
void symbols_free PARAMS ((void));
|
||||||
|
|
||||||
#endif /* !SYMTAB_H_ */
|
#endif /* !SYMTAB_H_ */
|
||||||
|
|||||||
Reference in New Issue
Block a user