From: Akim Demaille Date: Mon, 10 Jun 2002 08:36:49 +0000 (+0000) Subject: * src/symtab.c, src/symtab.c (symbol_type_set) X-Git-Tag: BISON-1_49b~201 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/3ae2b51f0851bfd63f73ca4bc263292839d757b1 * src/symtab.c, src/symtab.c (symbol_type_set) (symbol_precedence_set): New. * src/reader.c (parse_type_decl, parse_assoc_decl): Use them. (value_components_used): Remove, unused. --- diff --git a/ChangeLog b/ChangeLog index 02a0e19d..45aaf92d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2002-06-10 Akim Demaille + + * src/symtab.c, src/symtab.c (symbol_type_set) + (symbol_precedence_set): New. + * src/reader.c (parse_type_decl, parse_assoc_decl): Use them. + (value_components_used): Remove, unused. + 2002-06-09 Akim Demaille Move symbols handling code out of the reader. diff --git a/TODO b/TODO index d5fb1f39..14bd676f 100644 --- a/TODO +++ b/TODO @@ -3,6 +3,11 @@ * URGENT: Documenting C++ output Write a first documentation for C++ output. +* value_components_used +Was defined but not used: where was it coming from? It can't be to +check if %union is used, since the user is free to $n on her +union, doesn't she? + * yyerror, yyprint interface It should be improved, in particular when using Bison features such as locations, and YYPARSE_PARAMS. For the time being, it is recommended diff --git a/src/reader.c b/src/reader.c index 63d993f9..70629837 100644 --- a/src/reader.c +++ b/src/reader.c @@ -52,10 +52,6 @@ int lineno; static symbol_list *grammar = NULL; static int start_flag = 0; -/* Nonzero if components of semantic values are used, implying - they must be unions. */ -static int value_components_used; - /* Nonzero if %union has been seen. */ static int typed = 0; @@ -378,7 +374,6 @@ copy_dollar (FILE *fin, struct obstack *oout, { read_type_name (fin); type_name = token_buffer; - value_components_used = 1; c = getc (fin); } @@ -525,7 +520,6 @@ parse_token_decl (symbol_class what_is, symbol_class what_is_not) if (token == tok_typename) { typename = xstrdup (token_buffer); - value_components_used = 1; symbol = NULL; } else if (token == tok_identifier && *symval->tag == '\"' && symbol) @@ -630,17 +624,12 @@ parse_type_decl (void) switch (t) { - case tok_comma: case tok_semicolon: break; case tok_identifier: - if (symval->type_name == NULL) - symval->type_name = name; - else if (strcmp (name, symval->type_name) != 0) - complain (_("type redeclaration for %s"), symval->tag); - + symbol_type_set (symval, name); break; default: @@ -689,10 +678,6 @@ parse_assoc_decl (associativity assoc) break; case tok_identifier: - if (symval->prec != 0) - complain (_("redefining precedence of %s"), symval->tag); - symval->prec = lastprec; - symval->assoc = assoc; if (symval->class == nterm_sym) complain (_("symbol %s redefined"), symval->tag); if (symval->number == NUMBER_UNDEFINED) @@ -700,13 +685,9 @@ parse_assoc_decl (associativity assoc) symval->number = ntokens++; symval->class = token_sym; } + symbol_precedence_set (symval, lastprec, assoc); if (name) - { /* record the type, if one is specified */ - if (symval->type_name == NULL) - symval->type_name = name; - else if (strcmp (name, symval->type_name) != 0) - complain (_("type redeclaration for %s"), symval->tag); - } + symbol_type_set (symval, name); break; case tok_number: @@ -851,7 +832,6 @@ parse_thong_decl (void) if (token == tok_typename) { typename = xstrdup (token_buffer); - value_components_used = 1; token = lex (); /* fetch first token */ } diff --git a/src/symtab.c b/src/symtab.c index 217b8e0a..08571d83 100644 --- a/src/symtab.c +++ b/src/symtab.c @@ -59,6 +59,34 @@ symbol_new (const char *tag) } +/*-----------------------------------------. +| Set the TYPE_NAME associated to SYMBOL. | +`-----------------------------------------*/ + +void +symbol_type_set (symbol_t *symbol, char *type_name) +{ + if (symbol->type_name) + complain (_("type redeclaration for %s"), symbol->tag); + symbol->type_name = type_name; +} + + +/*------------------------------------------. +| Set the PRECEDENCE associated to SYMBOL. | +`------------------------------------------*/ + +void +symbol_precedence_set (symbol_t *symbol, + int prec, associativity assoc) +{ + if (symbol->prec != 0) + complain (_("redefining precedence of %s"), symbol->tag); + symbol->prec = prec; + symbol->assoc = assoc; +} + + /*------------. | Free THIS. | `------------*/ diff --git a/src/symtab.h b/src/symtab.h index b7a9fbc8..4ca81465 100644 --- a/src/symtab.h +++ b/src/symtab.h @@ -89,6 +89,13 @@ symbol_t *getsym PARAMS ((const char *key)); void symbol_make_alias PARAMS ((symbol_t *symbol, symbol_t *symval, char *typename)); +/* Set the TYPE_NAME associated to SYMBOL. */ +void symbol_type_set PARAMS ((symbol_t *symbol, char *type_name)); + +/* Set the PRECEDENCE associated to SYMBOL. */ +void symbol_precedence_set PARAMS ((symbol_t *symbol, + int prec, associativity assoc)); + /* Distinguished symbols. AXIOM is the real start symbol, that used by the automaton. STARTSYMBOL is the one specified by the user. */