/* Symbol table manager for Bison.
- Copyright (C) 1984, 1989, 2000, 2001, 2002, 2004, 2005, 2006 Free
- Software Foundation, Inc.
+ Copyright (C) 1984, 1989, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008
+ Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
- Bison is free software; you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
- Bison is distributed in the hope that it will be useful,
+ This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with Bison; see the file COPYING. If not, write to
- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA. */
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include "system.h"
if (s->Attr) \
fprintf (f, " %s { %s }", #Attr, s->Attr)
-#define SYMBOL_CODE_PRINT(Attr) \
- if (code_props_code_get (s->Attr)) \
- fprintf (f, " %s { %s }", #Attr, code_props_code_get(s->Attr))
+#define SYMBOL_CODE_PRINT(Attr) \
+ if (s->Attr.code) \
+ fprintf (f, " %s { %s }", #Attr, s->Attr.code)
void
symbol_print (symbol *s, FILE *f)
}
}
+/*-----------------------------------.
+| Get the CLASS associated with SYM. |
+`-----------------------------------*/
+
+const char *
+symbol_class_get_string (symbol *sym)
+{
+ if (sym->class)
+ {
+ if (sym->class == token_sym)
+ return "terminal";
+ else if (sym->class == nterm_sym)
+ return "nonterminal";
+ }
+ return "unknown";
+}
+
/*-----------------------------------------.
| Set the DESTRUCTOR associated with SYM. |
`-----------------------------------------*/
void
-symbol_destructor_set (symbol *sym, code_props destructor)
+symbol_destructor_set (symbol *sym, code_props const *destructor)
{
- if (code_props_code_get (sym->destructor))
- symbol_redeclaration (sym, "%destructor",
- code_props_location_get (sym->destructor),
- code_props_location_get (destructor));
- sym->destructor = destructor;
+ if (sym->destructor.code)
+ symbol_redeclaration (sym, "%destructor", sym->destructor.location,
+ destructor->location);
+ sym->destructor = *destructor;
}
/*------------------------------------------.
`------------------------------------------*/
void
-semantic_type_destructor_set (semantic_type *type, code_props destructor)
+semantic_type_destructor_set (semantic_type *type,
+ code_props const *destructor)
{
- if (code_props_code_get (type->destructor))
+ if (type->destructor.code)
semantic_type_redeclaration (type, "%destructor",
- code_props_location_get (type->destructor),
- code_props_location_get (destructor));
- type->destructor = destructor;
+ type->destructor.location,
+ destructor->location);
+ type->destructor = *destructor;
}
/*---------------------------------------.
| Get the computed %destructor for SYM. |
`---------------------------------------*/
-code_props
-symbol_destructor_get (symbol *sym)
+code_props const *
+symbol_destructor_get (symbol const *sym)
{
/* Per-symbol %destructor. */
- if (code_props_code_get (sym->destructor))
- return sym->destructor;
+ if (sym->destructor.code)
+ return &sym->destructor;
/* Per-type %destructor. */
if (sym->type_name)
{
- code_props destructor = semantic_type_get (sym->type_name)->destructor;
- if (code_props_code_get (destructor))
+ code_props const *destructor =
+ &semantic_type_get (sym->type_name)->destructor;
+ if (destructor->code)
return destructor;
}
/* Apply default %destructor's only to user-defined symbols. */
if (sym->tag[0] == '$' || sym == errtoken)
- return code_props_none;
+ return &code_props_none;
if (sym->type_name)
- return default_tagged_destructor;
- return default_tagless_destructor;
+ return &default_tagged_destructor;
+ return &default_tagless_destructor;
}
/*--------------------------------------.
`--------------------------------------*/
void
-symbol_printer_set (symbol *sym, code_props printer)
+symbol_printer_set (symbol *sym, code_props const *printer)
{
- if (code_props_code_get (sym->printer))
+ if (sym->printer.code)
symbol_redeclaration (sym, "%printer",
- code_props_location_get (sym->printer),
- code_props_location_get (printer));
- sym->printer = printer;
+ sym->printer.location, printer->location);
+ sym->printer = *printer;
}
/*---------------------------------------.
`---------------------------------------*/
void
-semantic_type_printer_set (semantic_type *type, code_props printer)
+semantic_type_printer_set (semantic_type *type, code_props const *printer)
{
- if (code_props_code_get (type->printer))
+ if (type->printer.code)
semantic_type_redeclaration (type, "%printer",
- code_props_location_get (type->printer),
- code_props_location_get (printer));
- type->printer = printer;
+ type->printer.location, printer->location);
+ type->printer = *printer;
}
/*------------------------------------.
| Get the computed %printer for SYM. |
`------------------------------------*/
-code_props
-symbol_printer_get (symbol *sym)
+code_props const *
+symbol_printer_get (symbol const *sym)
{
/* Per-symbol %printer. */
- if (code_props_code_get (sym->printer))
- return sym->printer;
+ if (sym->printer.code)
+ return &sym->printer;
/* Per-type %printer. */
if (sym->type_name)
{
- code_props printer = semantic_type_get (sym->type_name)->printer;
- if (code_props_code_get (printer))
+ code_props const *printer = &semantic_type_get (sym->type_name)->printer;
+ if (printer->code)
return printer;
}
/* Apply the default %printer only to user-defined symbols. */
if (sym->tag[0] == '$' || sym == errtoken)
- return code_props_none;
+ return &code_props_none;
if (sym->type_name)
- return default_tagged_printer;
- return default_tagless_printer;
+ return &default_tagged_printer;
+ return &default_tagless_printer;
}
/*-----------------------------------------------------------------.
{
int *user_token_numberp;
- aver (sym->class == token_sym);
-
if (sym->user_token_number != USER_NUMBER_ALIAS)
user_token_numberp = &sym->user_token_number;
else
}
- if (code_props_code_get (orig->destructor)
- || code_props_code_get (alias->destructor))
+ if (orig->destructor.code || alias->destructor.code)
{
- if (code_props_code_get (orig->destructor))
- symbol_destructor_set (alias, orig->destructor);
+ if (orig->destructor.code)
+ symbol_destructor_set (alias, &orig->destructor);
else
- symbol_destructor_set (orig, alias->destructor);
+ symbol_destructor_set (orig, &alias->destructor);
}
- if (code_props_code_get (orig->printer)
- || code_props_code_get (alias->printer))
+ if (orig->printer.code || alias->printer.code)
{
- if (code_props_code_get (orig->printer))
- symbol_printer_set (alias, orig->printer);
+ if (orig->printer.code)
+ symbol_printer_set (alias, &orig->printer);
else
- symbol_printer_set (orig, alias->printer);
+ symbol_printer_set (orig, &alias->printer);
}
if (alias->prec || orig->prec)
token_translations = xnmalloc (max_user_token_number + 1,
sizeof *token_translations);
- /* Initialize all entries for literal tokens to 2, the internal
- token number for $undefined, which represents all invalid inputs.
- */
+ /* Initialize all entries for literal tokens to the internal token
+ number for $undefined, which represents all invalid inputs. */
for (i = 0; i < max_user_token_number + 1; i++)
token_translations[i] = undeftoken->number;
symbols_do (symbol_translation_processor, NULL);
`--------------------------------------------------*/
void
-default_tagged_destructor_set (code_props destructor)
+default_tagged_destructor_set (code_props const *destructor)
{
- if (code_props_code_get (default_tagged_destructor))
+ if (default_tagged_destructor.code)
{
- complain_at (code_props_location_get (destructor),
+ complain_at (destructor->location,
_("redeclaration for default tagged %%destructor"));
- complain_at (code_props_location_get (default_tagged_destructor),
+ complain_at (default_tagged_destructor.location,
_("previous declaration"));
}
- default_tagged_destructor = destructor;
+ default_tagged_destructor = *destructor;
}
void
-default_tagless_destructor_set (code_props destructor)
+default_tagless_destructor_set (code_props const *destructor)
{
- if (code_props_code_get (default_tagless_destructor))
+ if (default_tagless_destructor.code)
{
- complain_at (code_props_location_get (destructor),
+ complain_at (destructor->location,
_("redeclaration for default tagless %%destructor"));
- complain_at (code_props_location_get (default_tagless_destructor),
+ complain_at (default_tagless_destructor.location,
_("previous declaration"));
}
- default_tagless_destructor = destructor;
+ default_tagless_destructor = *destructor;
}
void
-default_tagged_printer_set (code_props printer)
+default_tagged_printer_set (code_props const *printer)
{
- if (code_props_code_get (default_tagged_printer))
+ if (default_tagged_printer.code)
{
- complain_at (code_props_location_get (printer),
+ complain_at (printer->location,
_("redeclaration for default tagged %%printer"));
- complain_at (code_props_location_get (default_tagged_printer),
+ complain_at (default_tagged_printer.location,
_("previous declaration"));
}
- default_tagged_printer = printer;
+ default_tagged_printer = *printer;
}
void
-default_tagless_printer_set (code_props printer)
+default_tagless_printer_set (code_props const *printer)
{
- if (code_props_code_get (default_tagless_printer))
+ if (default_tagless_printer.code)
{
- complain_at (code_props_location_get (printer),
+ complain_at (printer->location,
_("redeclaration for default tagless %%printer"));
- complain_at (code_props_location_get (default_tagless_printer),
+ complain_at (default_tagless_printer.location,
_("previous declaration"));
}
- default_tagless_printer = printer;
+ default_tagless_printer = *printer;
}
-