mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-17 16:23:04 +00:00
Use the new code_props interface for destructors and printers.
* src/symtab.h (symbol, semantic_type): Remove destructor_location and printer_location members, and change the type of the destructor and printer members to code_props. (symbol_destructor_set, symbol_destructor_get, symbol_printer_set, symbol_printer_get, semantic_type_destructor_set, semantic_type_printer_set, default_tagged_destructor_set, default_tagless_destructor_set, default_tagged_printer_set, default_tagless_printer_set): Use code_props in arguments and return types in place of char const * and location. (symbol_destructor_location_get, symbol_printer_location_get): Remove since the locations are now contained in the return of symbol_destructor_get and symbol_printer_get. * src/output.c (symbol_destructors_output, symbol_printers_output): Replace with... (symbol_code_props_output): ... this to eliminate duplicate code. (output_skeleton): Update to use symbol_code_props_output. * src/reader.c (symbol_should_be_used): Update use of symbol_destructor_get. * src/symlist.c (symbol_list_destructor_set, symbol_list_printer_set): Update uses of the various _destructor_set and _printer_set functions. * src/symtab.c: (default_tagged_destructor_location, default_tagless_destructor_location, default_tagged_printer_location, default_tagless_printer_location): Remove since we... (default_tagged_destructor, default_tagless_destructor, default_tagged_printer, default_tagless_printer): ... change the type of these to code_props. (symbol_new, semantic_type_new, symbol_destructor_set, semantic_type_destructor_set, symbol_destructor_get, symbol_printer_set, semantic_type_printer_set, symbol_printer_get, symbol_check_alias_consistency, default_tagged_destructor_set, default_tagless_destructor_set, default_tagged_printer_set, default_tagless_printer_set): Update. (symbol_destructor_location_get, symbol_printer_location_get): Remove. (SYMBOL_CODE_PRINT): New similar to SYMBOL_ATTR_PRINT but for code_props members. (symbol_print): Use SYMBOL_CODE_PRINT.
This commit is contained in:
44
ChangeLog
44
ChangeLog
@@ -1,3 +1,43 @@
|
|||||||
|
2007-01-03 Joel E. Denny <jdenny@ces.clemson.edu>
|
||||||
|
|
||||||
|
Use the new code_props interface for destructors and printers.
|
||||||
|
* src/symtab.h (symbol, semantic_type): Remove destructor_location and
|
||||||
|
printer_location members, and change the type of the destructor and
|
||||||
|
printer members to code_props.
|
||||||
|
(symbol_destructor_set, symbol_destructor_get, symbol_printer_set,
|
||||||
|
symbol_printer_get, semantic_type_destructor_set,
|
||||||
|
semantic_type_printer_set, default_tagged_destructor_set,
|
||||||
|
default_tagless_destructor_set, default_tagged_printer_set,
|
||||||
|
default_tagless_printer_set): Use code_props in arguments and return
|
||||||
|
types in place of char const * and location.
|
||||||
|
(symbol_destructor_location_get, symbol_printer_location_get): Remove
|
||||||
|
since the locations are now contained in the return of
|
||||||
|
symbol_destructor_get and symbol_printer_get.
|
||||||
|
* src/output.c (symbol_destructors_output, symbol_printers_output):
|
||||||
|
Replace with...
|
||||||
|
(symbol_code_props_output): ... this to eliminate duplicate code.
|
||||||
|
(output_skeleton): Update to use symbol_code_props_output.
|
||||||
|
* src/reader.c (symbol_should_be_used): Update use of
|
||||||
|
symbol_destructor_get.
|
||||||
|
* src/symlist.c (symbol_list_destructor_set, symbol_list_printer_set):
|
||||||
|
Update uses of the various _destructor_set and _printer_set functions.
|
||||||
|
* src/symtab.c: (default_tagged_destructor_location,
|
||||||
|
default_tagless_destructor_location, default_tagged_printer_location,
|
||||||
|
default_tagless_printer_location): Remove since we...
|
||||||
|
(default_tagged_destructor, default_tagless_destructor,
|
||||||
|
default_tagged_printer, default_tagless_printer): ... change the type
|
||||||
|
of these to code_props.
|
||||||
|
(symbol_new, semantic_type_new, symbol_destructor_set,
|
||||||
|
semantic_type_destructor_set, symbol_destructor_get,
|
||||||
|
symbol_printer_set, semantic_type_printer_set, symbol_printer_get,
|
||||||
|
symbol_check_alias_consistency, default_tagged_destructor_set,
|
||||||
|
default_tagless_destructor_set, default_tagged_printer_set,
|
||||||
|
default_tagless_printer_set): Update.
|
||||||
|
(symbol_destructor_location_get, symbol_printer_location_get): Remove.
|
||||||
|
(SYMBOL_CODE_PRINT): New similar to SYMBOL_ATTR_PRINT but for
|
||||||
|
code_props members.
|
||||||
|
(symbol_print): Use SYMBOL_CODE_PRINT.
|
||||||
|
|
||||||
2007-01-03 Joel E. Denny <jdenny@ces.clemson.edu>
|
2007-01-03 Joel E. Denny <jdenny@ces.clemson.edu>
|
||||||
|
|
||||||
Use the new code_props interface for rule actions.
|
Use the new code_props interface for rule actions.
|
||||||
@@ -18400,8 +18440,8 @@
|
|||||||
-----
|
-----
|
||||||
|
|
||||||
Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996,
|
Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996,
|
||||||
1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free
|
1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
|
||||||
Software Foundation, Inc.
|
Free Software Foundation, Inc.
|
||||||
|
|
||||||
Copying and distribution of this file, with or without
|
Copying and distribution of this file, with or without
|
||||||
modification, are permitted provided the copyright notice and this
|
modification, are permitted provided the copyright notice and this
|
||||||
|
|||||||
91
src/output.c
91
src/output.c
@@ -373,70 +373,41 @@ token_definitions_output (FILE *out)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------.
|
/*---------------------------------------------------.
|
||||||
| Output the symbol destructors to OUT. |
|
| Output the symbol destructors or printers to OUT. |
|
||||||
`---------------------------------------*/
|
`---------------------------------------------------*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
symbol_destructors_output (FILE *out)
|
symbol_code_props_output (FILE *out, char const *what,
|
||||||
|
code_props const *(*get)(symbol const *))
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char const *sep = "";
|
char const *sep = "";
|
||||||
|
|
||||||
fputs ("m4_define([b4_symbol_destructors], \n[", out);
|
fputs ("m4_define([b4_symbol_", out);
|
||||||
|
fputs (what, out);
|
||||||
|
fputs ("], \n[", out);
|
||||||
for (i = 0; i < nsyms; ++i)
|
for (i = 0; i < nsyms; ++i)
|
||||||
if (symbol_destructor_get (symbols[i]))
|
{
|
||||||
{
|
symbol *sym = symbols[i];
|
||||||
symbol *sym = symbols[i];
|
char const *code = (*get) (sym)->code;
|
||||||
|
if (code)
|
||||||
/* Filename, lineno,
|
{
|
||||||
Symbol-name, Symbol-number,
|
location loc = (*get) (sym)->location;
|
||||||
destructor, optional typename. */
|
/* Filename, lineno,
|
||||||
fprintf (out, "%s[", sep);
|
Symbol-name, Symbol-number,
|
||||||
sep = ",\n";
|
code, optional typename. */
|
||||||
escaped_output (out, symbol_destructor_location_get (sym).start.file);
|
fprintf (out, "%s[", sep);
|
||||||
fprintf (out, ", %d, ",
|
sep = ",\n";
|
||||||
symbol_destructor_location_get (sym).start.line);
|
escaped_output (out, loc.start.file);
|
||||||
escaped_output (out, sym->tag);
|
fprintf (out, ", %d, ", loc.start.line);
|
||||||
fprintf (out, ", %d, [[%s]]", sym->number,
|
escaped_output (out, sym->tag);
|
||||||
symbol_destructor_get (sym));
|
fprintf (out, ", %d, [[%s]]", sym->number, code);
|
||||||
if (sym->type_name)
|
if (sym->type_name)
|
||||||
fprintf (out, ", [[%s]]", sym->type_name);
|
fprintf (out, ", [[%s]]", sym->type_name);
|
||||||
fputc (']', out);
|
fputc (']', out);
|
||||||
}
|
}
|
||||||
fputs ("])\n\n", out);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------.
|
|
||||||
| Output the symbol printers to OUT. |
|
|
||||||
`------------------------------------*/
|
|
||||||
|
|
||||||
static void
|
|
||||||
symbol_printers_output (FILE *out)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char const *sep = "";
|
|
||||||
|
|
||||||
fputs ("m4_define([b4_symbol_printers], \n[", out);
|
|
||||||
for (i = 0; i < nsyms; ++i)
|
|
||||||
if (symbol_printer_get (symbols[i]))
|
|
||||||
{
|
|
||||||
symbol *sym = symbols[i];
|
|
||||||
|
|
||||||
/* Filename, lineno,
|
|
||||||
Symbol-name, Symbol-number,
|
|
||||||
printer, optional typename. */
|
|
||||||
fprintf (out, "%s[", sep);
|
|
||||||
sep = ",\n";
|
|
||||||
escaped_output (out, symbol_printer_location_get (sym).start.file);
|
|
||||||
fprintf (out, ", %d, ", symbol_printer_location_get (sym).start.line);
|
|
||||||
escaped_output (out, sym->tag);
|
|
||||||
fprintf (out, ", %d, [[%s]]", sym->number, symbol_printer_get (sym));
|
|
||||||
if (sym->type_name)
|
|
||||||
fprintf (out, ", [[%s]]", sym->type_name);
|
|
||||||
fputc (']', out);
|
|
||||||
}
|
|
||||||
fputs ("])\n\n", out);
|
fputs ("])\n\n", out);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -561,8 +532,8 @@ output_skeleton (void)
|
|||||||
user_actions_output (out);
|
user_actions_output (out);
|
||||||
merger_output (out);
|
merger_output (out);
|
||||||
token_definitions_output (out);
|
token_definitions_output (out);
|
||||||
symbol_destructors_output (out);
|
symbol_code_props_output (out, "destructors", &symbol_destructor_get);
|
||||||
symbol_printers_output (out);
|
symbol_code_props_output (out, "printers", &symbol_printer_get);
|
||||||
|
|
||||||
muscles_m4_output (out);
|
muscles_m4_output (out);
|
||||||
|
|
||||||
@@ -604,10 +575,10 @@ prepare (void)
|
|||||||
MUSCLE_INSERT_BOOL ("nondeterministic_flag", nondeterministic_parser);
|
MUSCLE_INSERT_BOOL ("nondeterministic_flag", nondeterministic_parser);
|
||||||
MUSCLE_INSERT_BOOL ("pull_flag", pull_parser);
|
MUSCLE_INSERT_BOOL ("pull_flag", pull_parser);
|
||||||
MUSCLE_INSERT_BOOL ("pure_flag", pure_parser);
|
MUSCLE_INSERT_BOOL ("pure_flag", pure_parser);
|
||||||
MUSCLE_INSERT_BOOL ("use_push_for_pull_flag", use_push_for_pull_flag);
|
|
||||||
MUSCLE_INSERT_BOOL ("push_flag", push_parser);
|
MUSCLE_INSERT_BOOL ("push_flag", push_parser);
|
||||||
MUSCLE_INSERT_BOOL ("synclines_flag", !no_lines_flag);
|
MUSCLE_INSERT_BOOL ("synclines_flag", !no_lines_flag);
|
||||||
MUSCLE_INSERT_BOOL ("tag_seen_flag", tag_seen);
|
MUSCLE_INSERT_BOOL ("tag_seen_flag", tag_seen);
|
||||||
|
MUSCLE_INSERT_BOOL ("use_push_for_pull_flag", use_push_for_pull_flag);
|
||||||
MUSCLE_INSERT_BOOL ("yacc_flag", yacc_flag);
|
MUSCLE_INSERT_BOOL ("yacc_flag", yacc_flag);
|
||||||
|
|
||||||
/* File names. */
|
/* File names. */
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ grammar_current_rule_begin (symbol *lhs, location loc)
|
|||||||
static bool
|
static bool
|
||||||
symbol_should_be_used (symbol_list const *s)
|
symbol_should_be_used (symbol_list const *s)
|
||||||
{
|
{
|
||||||
if (symbol_destructor_get (s->content.sym))
|
if (symbol_destructor_get (s->content.sym)->code)
|
||||||
return true;
|
return true;
|
||||||
if (warnings_flag & warnings_midrule_values)
|
if (warnings_flag & warnings_midrule_values)
|
||||||
return ((s->midrule && s->midrule->action_props.is_value_used)
|
return ((s->midrule && s->midrule->action_props.is_value_used)
|
||||||
|
|||||||
@@ -207,27 +207,25 @@ symbol_list_n_type_name_get (symbol_list *l, location loc, int n)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
symbol_list_destructor_set (symbol_list *node, char const *code,
|
symbol_list_destructor_set (symbol_list *node, char const *code, location loc)
|
||||||
location loc)
|
|
||||||
{
|
{
|
||||||
code_props destructor;
|
code_props destructor;
|
||||||
code_props_symbol_action_init (&destructor, code, loc);
|
code_props_symbol_action_init (&destructor, code, loc);
|
||||||
code_props_translate_code (&destructor);
|
code_props_translate_code (&destructor);
|
||||||
code = destructor.code;
|
|
||||||
switch (node->content_type)
|
switch (node->content_type)
|
||||||
{
|
{
|
||||||
case SYMLIST_SYMBOL:
|
case SYMLIST_SYMBOL:
|
||||||
symbol_destructor_set (node->content.sym, code, loc);
|
symbol_destructor_set (node->content.sym, &destructor);
|
||||||
break;
|
break;
|
||||||
case SYMLIST_TYPE:
|
case SYMLIST_TYPE:
|
||||||
semantic_type_destructor_set (
|
semantic_type_destructor_set (
|
||||||
semantic_type_get (node->content.type_name), code, loc);
|
semantic_type_get (node->content.type_name), &destructor);
|
||||||
break;
|
break;
|
||||||
case SYMLIST_DEFAULT_TAGGED:
|
case SYMLIST_DEFAULT_TAGGED:
|
||||||
default_tagged_destructor_set (code, loc);
|
default_tagged_destructor_set (&destructor);
|
||||||
break;
|
break;
|
||||||
case SYMLIST_DEFAULT_TAGLESS:
|
case SYMLIST_DEFAULT_TAGLESS:
|
||||||
default_tagless_destructor_set (code, loc);
|
default_tagless_destructor_set (&destructor);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -238,21 +236,20 @@ symbol_list_printer_set (symbol_list *node, char const *code, location loc)
|
|||||||
code_props printer;
|
code_props printer;
|
||||||
code_props_symbol_action_init (&printer, code, loc);
|
code_props_symbol_action_init (&printer, code, loc);
|
||||||
code_props_translate_code (&printer);
|
code_props_translate_code (&printer);
|
||||||
code = printer.code;
|
|
||||||
switch (node->content_type)
|
switch (node->content_type)
|
||||||
{
|
{
|
||||||
case SYMLIST_SYMBOL:
|
case SYMLIST_SYMBOL:
|
||||||
symbol_printer_set (node->content.sym, code, loc);
|
symbol_printer_set (node->content.sym, &printer);
|
||||||
break;
|
break;
|
||||||
case SYMLIST_TYPE:
|
case SYMLIST_TYPE:
|
||||||
semantic_type_printer_set (
|
semantic_type_printer_set (
|
||||||
semantic_type_get (node->content.type_name), code, loc);
|
semantic_type_get (node->content.type_name), &printer);
|
||||||
break;
|
break;
|
||||||
case SYMLIST_DEFAULT_TAGGED:
|
case SYMLIST_DEFAULT_TAGGED:
|
||||||
default_tagged_printer_set (code, loc);
|
default_tagged_printer_set (&printer);
|
||||||
break;
|
break;
|
||||||
case SYMLIST_DEFAULT_TAGLESS:
|
case SYMLIST_DEFAULT_TAGLESS:
|
||||||
default_tagless_printer_set (code, loc);
|
default_tagless_printer_set (&printer);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
262
src/symtab.c
262
src/symtab.c
@@ -1,6 +1,6 @@
|
|||||||
/* Symbol table manager for Bison.
|
/* Symbol table manager for Bison.
|
||||||
|
|
||||||
Copyright (C) 1984, 1989, 2000, 2001, 2002, 2004, 2005, 2006 Free
|
Copyright (C) 1984, 1989, 2000, 2001, 2002, 2004, 2005, 2006, 2007 Free
|
||||||
Software Foundation, Inc.
|
Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of Bison, the GNU Compiler Compiler.
|
This file is part of Bison, the GNU Compiler Compiler.
|
||||||
@@ -45,15 +45,10 @@ location startsymbol_location;
|
|||||||
| Default %destructor's and %printer's. |
|
| Default %destructor's and %printer's. |
|
||||||
`---------------------------------------*/
|
`---------------------------------------*/
|
||||||
|
|
||||||
static const char *default_tagged_destructor = NULL;
|
static code_props default_tagged_destructor = CODE_PROPS_NONE_INIT;
|
||||||
static location default_tagged_destructor_location;
|
static code_props default_tagless_destructor = CODE_PROPS_NONE_INIT;
|
||||||
static const char *default_tagless_destructor = NULL;
|
static code_props default_tagged_printer = CODE_PROPS_NONE_INIT;
|
||||||
static location default_tagless_destructor_location;
|
static code_props default_tagless_printer = CODE_PROPS_NONE_INIT;
|
||||||
|
|
||||||
static const char *default_tagged_printer = NULL;
|
|
||||||
static location default_tagged_printer_location;
|
|
||||||
static const char *default_tagless_printer = NULL;
|
|
||||||
static location default_tagless_printer_location;
|
|
||||||
|
|
||||||
/*---------------------------------.
|
/*---------------------------------.
|
||||||
| Create a new symbol, named TAG. |
|
| Create a new symbol, named TAG. |
|
||||||
@@ -69,8 +64,8 @@ symbol_new (uniqstr tag, location loc)
|
|||||||
res->location = loc;
|
res->location = loc;
|
||||||
|
|
||||||
res->type_name = NULL;
|
res->type_name = NULL;
|
||||||
res->destructor = NULL;
|
code_props_none_init (&res->destructor);
|
||||||
res->printer = NULL;
|
code_props_none_init (&res->printer);
|
||||||
|
|
||||||
res->number = NUMBER_UNDEFINED;
|
res->number = NUMBER_UNDEFINED;
|
||||||
res->prec = 0;
|
res->prec = 0;
|
||||||
@@ -99,8 +94,8 @@ semantic_type_new (uniqstr tag)
|
|||||||
|
|
||||||
uniqstr_assert (tag);
|
uniqstr_assert (tag);
|
||||||
res->tag = tag;
|
res->tag = tag;
|
||||||
res->destructor = NULL;
|
code_props_none_init (&res->destructor);
|
||||||
res->printer = NULL;
|
code_props_none_init (&res->printer);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -114,6 +109,10 @@ semantic_type_new (uniqstr tag)
|
|||||||
if (s->Attr) \
|
if (s->Attr) \
|
||||||
fprintf (f, " %s { %s }", #Attr, s->Attr)
|
fprintf (f, " %s { %s }", #Attr, s->Attr)
|
||||||
|
|
||||||
|
#define SYMBOL_CODE_PRINT(Attr) \
|
||||||
|
if (s->Attr.code) \
|
||||||
|
fprintf (f, " %s { %s }", #Attr, s->Attr.code)
|
||||||
|
|
||||||
void
|
void
|
||||||
symbol_print (symbol *s, FILE *f)
|
symbol_print (symbol *s, FILE *f)
|
||||||
{
|
{
|
||||||
@@ -121,14 +120,15 @@ symbol_print (symbol *s, FILE *f)
|
|||||||
{
|
{
|
||||||
fprintf (f, "\"%s\"", s->tag);
|
fprintf (f, "\"%s\"", s->tag);
|
||||||
SYMBOL_ATTR_PRINT (type_name);
|
SYMBOL_ATTR_PRINT (type_name);
|
||||||
SYMBOL_ATTR_PRINT (destructor);
|
SYMBOL_CODE_PRINT (destructor);
|
||||||
SYMBOL_ATTR_PRINT (printer);
|
SYMBOL_CODE_PRINT (printer);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
fprintf (f, "<NULL>");
|
fprintf (f, "<NULL>");
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef SYMBOL_ATTR_PRINT
|
#undef SYMBOL_ATTR_PRINT
|
||||||
|
#undef SYMBOL_CODE_PRINT
|
||||||
|
|
||||||
/*------------------------------------------------------------------.
|
/*------------------------------------------------------------------.
|
||||||
| Complain that S's WHAT is redeclared at SECOND, and was first set |
|
| Complain that S's WHAT is redeclared at SECOND, and was first set |
|
||||||
@@ -171,170 +171,117 @@ symbol_type_set (symbol *sym, uniqstr type_name, location loc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------.
|
/*-----------------------------------------.
|
||||||
| Set the DESTRUCTOR associated with SYM. Do nothing if passed 0. |
|
| Set the DESTRUCTOR associated with SYM. |
|
||||||
`------------------------------------------------------------------*/
|
`-----------------------------------------*/
|
||||||
|
|
||||||
void
|
void
|
||||||
symbol_destructor_set (symbol *sym, const char *destructor, location loc)
|
symbol_destructor_set (symbol *sym, code_props const *destructor)
|
||||||
{
|
{
|
||||||
if (destructor)
|
if (sym->destructor.code)
|
||||||
{
|
symbol_redeclaration (sym, "%destructor", sym->destructor.location,
|
||||||
if (sym->destructor)
|
destructor->location);
|
||||||
symbol_redeclaration (sym, "%destructor", sym->destructor_location,
|
sym->destructor = *destructor;
|
||||||
loc);
|
|
||||||
sym->destructor = destructor;
|
|
||||||
sym->destructor_location = loc;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------.
|
/*------------------------------------------.
|
||||||
| Set the DESTRUCTOR associated with TYPE. Do nothing if passed 0. |
|
| Set the DESTRUCTOR associated with TYPE. |
|
||||||
`-------------------------------------------------------------------*/
|
`------------------------------------------*/
|
||||||
|
|
||||||
void
|
void
|
||||||
semantic_type_destructor_set (semantic_type *type, const char *destructor,
|
semantic_type_destructor_set (semantic_type *type,
|
||||||
location loc)
|
code_props const *destructor)
|
||||||
{
|
{
|
||||||
if (destructor)
|
if (type->destructor.code)
|
||||||
{
|
semantic_type_redeclaration (type, "%destructor",
|
||||||
if (type->destructor)
|
type->destructor.location,
|
||||||
semantic_type_redeclaration (type, "%destructor",
|
destructor->location);
|
||||||
type->destructor_location, loc);
|
type->destructor = *destructor;
|
||||||
type->destructor = destructor;
|
|
||||||
type->destructor_location = loc;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------.
|
/*---------------------------------------.
|
||||||
| Get the computed %destructor for SYM. |
|
| Get the computed %destructor for SYM. |
|
||||||
`---------------------------------------*/
|
`---------------------------------------*/
|
||||||
|
|
||||||
const char *
|
code_props const *
|
||||||
symbol_destructor_get (symbol *sym)
|
symbol_destructor_get (symbol const *sym)
|
||||||
{
|
{
|
||||||
/* Per-symbol %destructor. */
|
/* Per-symbol %destructor. */
|
||||||
if (sym->destructor != NULL)
|
if (sym->destructor.code)
|
||||||
return sym->destructor;
|
return &sym->destructor;
|
||||||
|
|
||||||
/* Per-type %destructor. */
|
/* Per-type %destructor. */
|
||||||
if (sym->type_name)
|
if (sym->type_name)
|
||||||
{
|
{
|
||||||
semantic_type *type = semantic_type_get (sym->type_name);
|
code_props const *destructor =
|
||||||
if (type->destructor)
|
&semantic_type_get (sym->type_name)->destructor;
|
||||||
return type->destructor;
|
if (destructor->code)
|
||||||
|
return destructor;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Apply default %destructor's only to user-defined symbols. */
|
/* Apply default %destructor's only to user-defined symbols. */
|
||||||
if (sym->tag[0] == '$' || sym == errtoken)
|
if (sym->tag[0] == '$' || sym == errtoken)
|
||||||
return NULL;
|
return &code_props_none;
|
||||||
|
|
||||||
if (sym->type_name)
|
if (sym->type_name)
|
||||||
return default_tagged_destructor;
|
return &default_tagged_destructor;
|
||||||
return default_tagless_destructor;
|
return &default_tagless_destructor;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------.
|
/*--------------------------------------.
|
||||||
| Get the grammar location of the %destructor computed for SYM. |
|
| Set the PRINTER associated with SYM. |
|
||||||
`---------------------------------------------------------------*/
|
`--------------------------------------*/
|
||||||
|
|
||||||
location
|
|
||||||
symbol_destructor_location_get (symbol *sym)
|
|
||||||
{
|
|
||||||
if (sym->destructor != NULL)
|
|
||||||
return sym->destructor_location;
|
|
||||||
if (sym->type_name)
|
|
||||||
{
|
|
||||||
semantic_type *type = semantic_type_get (sym->type_name);
|
|
||||||
if (type->destructor)
|
|
||||||
return type->destructor_location;
|
|
||||||
return default_tagged_destructor_location;
|
|
||||||
}
|
|
||||||
return default_tagless_destructor_location;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------.
|
|
||||||
| Set the PRINTER associated with SYM. Do nothing if passed 0. |
|
|
||||||
`---------------------------------------------------------------*/
|
|
||||||
|
|
||||||
void
|
void
|
||||||
symbol_printer_set (symbol *sym, const char *printer, location loc)
|
symbol_printer_set (symbol *sym, code_props const *printer)
|
||||||
{
|
{
|
||||||
if (printer)
|
if (sym->printer.code)
|
||||||
{
|
symbol_redeclaration (sym, "%printer",
|
||||||
if (sym->printer)
|
sym->printer.location, printer->location);
|
||||||
symbol_redeclaration (sym, "%printer", sym->printer_location, loc);
|
sym->printer = *printer;
|
||||||
sym->printer = printer;
|
|
||||||
sym->printer_location = loc;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------.
|
/*---------------------------------------.
|
||||||
| Set the PRINTER associated with TYPE. Do nothing if passed 0. |
|
| Set the PRINTER associated with TYPE. |
|
||||||
`----------------------------------------------------------------*/
|
`---------------------------------------*/
|
||||||
|
|
||||||
void
|
void
|
||||||
semantic_type_printer_set (semantic_type *type, const char *printer,
|
semantic_type_printer_set (semantic_type *type, code_props const *printer)
|
||||||
location loc)
|
|
||||||
{
|
{
|
||||||
if (printer)
|
if (type->printer.code)
|
||||||
{
|
semantic_type_redeclaration (type, "%printer",
|
||||||
if (type->printer)
|
type->printer.location, printer->location);
|
||||||
semantic_type_redeclaration (type, "%printer", type->printer_location,
|
type->printer = *printer;
|
||||||
loc);
|
|
||||||
type->printer = printer;
|
|
||||||
type->printer_location = loc;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------.
|
/*------------------------------------.
|
||||||
| Get the computed %printer for SYM. |
|
| Get the computed %printer for SYM. |
|
||||||
`------------------------------------*/
|
`------------------------------------*/
|
||||||
|
|
||||||
const char *
|
code_props const *
|
||||||
symbol_printer_get (symbol *sym)
|
symbol_printer_get (symbol const *sym)
|
||||||
{
|
{
|
||||||
/* Per-symbol %printer. */
|
/* Per-symbol %printer. */
|
||||||
if (sym->printer != NULL)
|
if (sym->printer.code)
|
||||||
return sym->printer;
|
return &sym->printer;
|
||||||
|
|
||||||
/* Per-type %printer. */
|
/* Per-type %printer. */
|
||||||
if (sym->type_name)
|
if (sym->type_name)
|
||||||
{
|
{
|
||||||
semantic_type *type = semantic_type_get (sym->type_name);
|
code_props const *printer = &semantic_type_get (sym->type_name)->printer;
|
||||||
if (type->printer)
|
if (printer->code)
|
||||||
return type->printer;
|
return printer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Apply the default %printer only to user-defined symbols. */
|
/* Apply the default %printer only to user-defined symbols. */
|
||||||
if (sym->tag[0] == '$' || sym == errtoken)
|
if (sym->tag[0] == '$' || sym == errtoken)
|
||||||
return NULL;
|
return &code_props_none;
|
||||||
|
|
||||||
if (sym->type_name)
|
if (sym->type_name)
|
||||||
return default_tagged_printer;
|
return &default_tagged_printer;
|
||||||
return default_tagless_printer;
|
return &default_tagless_printer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------.
|
|
||||||
| Get the grammar location of the %printer computed for SYM. |
|
|
||||||
`------------------------------------------------------------*/
|
|
||||||
|
|
||||||
location
|
|
||||||
symbol_printer_location_get (symbol *sym)
|
|
||||||
{
|
|
||||||
if (sym->printer != NULL)
|
|
||||||
return sym->printer_location;
|
|
||||||
if (sym->type_name)
|
|
||||||
{
|
|
||||||
semantic_type *type = semantic_type_get (sym->type_name);
|
|
||||||
if (type->printer)
|
|
||||||
return type->printer_location;
|
|
||||||
return default_tagged_printer_location;
|
|
||||||
}
|
|
||||||
return default_tagless_printer_location;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------.
|
/*-----------------------------------------------------------------.
|
||||||
| Set the PRECEDENCE associated with SYM. Does nothing if invoked |
|
| Set the PRECEDENCE associated with SYM. Does nothing if invoked |
|
||||||
| with UNDEF_ASSOC as ASSOC. |
|
| with UNDEF_ASSOC as ASSOC. |
|
||||||
@@ -498,22 +445,20 @@ symbol_check_alias_consistency (symbol *this)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (orig->destructor || alias->destructor)
|
if (orig->destructor.code || alias->destructor.code)
|
||||||
{
|
{
|
||||||
if (orig->destructor)
|
if (orig->destructor.code)
|
||||||
symbol_destructor_set (alias, orig->destructor,
|
symbol_destructor_set (alias, &orig->destructor);
|
||||||
orig->destructor_location);
|
|
||||||
else
|
else
|
||||||
symbol_destructor_set (orig, alias->destructor,
|
symbol_destructor_set (orig, &alias->destructor);
|
||||||
alias->destructor_location);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (orig->printer || alias->printer)
|
if (orig->printer.code || alias->printer.code)
|
||||||
{
|
{
|
||||||
if (orig->printer)
|
if (orig->printer.code)
|
||||||
symbol_printer_set (alias, orig->printer, orig->printer_location);
|
symbol_printer_set (alias, &orig->printer);
|
||||||
else
|
else
|
||||||
symbol_printer_set (orig, alias->printer, alias->printer_location);
|
symbol_printer_set (orig, &alias->printer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (alias->prec || orig->prec)
|
if (alias->prec || orig->prec)
|
||||||
@@ -942,53 +887,54 @@ symbols_pack (void)
|
|||||||
`--------------------------------------------------*/
|
`--------------------------------------------------*/
|
||||||
|
|
||||||
void
|
void
|
||||||
default_tagged_destructor_set (const char *destructor, location loc)
|
default_tagged_destructor_set (code_props const *destructor)
|
||||||
{
|
{
|
||||||
if (default_tagged_destructor != NULL)
|
if (default_tagged_destructor.code)
|
||||||
{
|
{
|
||||||
complain_at (loc, _("redeclaration for default tagged %%destructor"));
|
complain_at (destructor->location,
|
||||||
complain_at (default_tagged_destructor_location,
|
_("redeclaration for default tagged %%destructor"));
|
||||||
|
complain_at (default_tagged_destructor.location,
|
||||||
_("previous declaration"));
|
_("previous declaration"));
|
||||||
}
|
}
|
||||||
default_tagged_destructor = destructor;
|
default_tagged_destructor = *destructor;
|
||||||
default_tagged_destructor_location = loc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
default_tagless_destructor_set (const char *destructor, location loc)
|
default_tagless_destructor_set (code_props const *destructor)
|
||||||
{
|
{
|
||||||
if (default_tagless_destructor != NULL)
|
if (default_tagless_destructor.code)
|
||||||
{
|
{
|
||||||
complain_at (loc, _("redeclaration for default tagless %%destructor"));
|
complain_at (destructor->location,
|
||||||
complain_at (default_tagless_destructor_location,
|
_("redeclaration for default tagless %%destructor"));
|
||||||
|
complain_at (default_tagless_destructor.location,
|
||||||
_("previous declaration"));
|
_("previous declaration"));
|
||||||
}
|
}
|
||||||
default_tagless_destructor = destructor;
|
default_tagless_destructor = *destructor;
|
||||||
default_tagless_destructor_location = loc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
default_tagged_printer_set (const char *printer, location loc)
|
default_tagged_printer_set (code_props const *printer)
|
||||||
{
|
{
|
||||||
if (default_tagged_printer != NULL)
|
if (default_tagged_printer.code)
|
||||||
{
|
{
|
||||||
complain_at (loc, _("redeclaration for default tagged %%printer"));
|
complain_at (printer->location,
|
||||||
complain_at (default_tagged_printer_location,
|
_("redeclaration for default tagged %%printer"));
|
||||||
|
complain_at (default_tagged_printer.location,
|
||||||
_("previous declaration"));
|
_("previous declaration"));
|
||||||
}
|
}
|
||||||
default_tagged_printer = printer;
|
default_tagged_printer = *printer;
|
||||||
default_tagged_printer_location = loc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
default_tagless_printer_set (const char *printer, location loc)
|
default_tagless_printer_set (code_props const *printer)
|
||||||
{
|
{
|
||||||
if (default_tagless_printer != NULL)
|
if (default_tagless_printer.code)
|
||||||
{
|
{
|
||||||
complain_at (loc, _("redeclaration for default tagless %%printer"));
|
complain_at (printer->location,
|
||||||
complain_at (default_tagless_printer_location,
|
_("redeclaration for default tagless %%printer"));
|
||||||
|
complain_at (default_tagless_printer.location,
|
||||||
_("previous declaration"));
|
_("previous declaration"));
|
||||||
}
|
}
|
||||||
default_tagless_printer = printer;
|
default_tagless_printer = *printer;
|
||||||
default_tagless_printer_location = loc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
68
src/symtab.h
68
src/symtab.h
@@ -1,6 +1,6 @@
|
|||||||
/* Definitions for symtab.c and callers, part of Bison.
|
/* Definitions for symtab.c and callers, part of Bison.
|
||||||
|
|
||||||
Copyright (C) 1984, 1989, 1992, 2000, 2001, 2002, 2004, 2005, 2006
|
Copyright (C) 1984, 1989, 1992, 2000, 2001, 2002, 2004, 2005, 2006, 2007
|
||||||
Free Software Foundation, Inc.
|
Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of Bison, the GNU Compiler Compiler.
|
This file is part of Bison, the GNU Compiler Compiler.
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
# include "assoc.h"
|
# include "assoc.h"
|
||||||
# include "location.h"
|
# include "location.h"
|
||||||
|
# include "scan-code.h"
|
||||||
# include "uniqstr.h"
|
# include "uniqstr.h"
|
||||||
|
|
||||||
/*----------.
|
/*----------.
|
||||||
@@ -72,25 +73,13 @@ struct symbol
|
|||||||
example, if <tt>symbol::destructor = NULL</tt>, a default \c \%destructor
|
example, if <tt>symbol::destructor = NULL</tt>, a default \c \%destructor
|
||||||
or a per-type \c \%destructor might be appropriate, and
|
or a per-type \c \%destructor might be appropriate, and
|
||||||
\c symbol_destructor_get will compute the correct one. */
|
\c symbol_destructor_get will compute the correct one. */
|
||||||
const char *destructor;
|
code_props destructor;
|
||||||
|
|
||||||
/** The location of \c symbol::destructor.
|
|
||||||
|
|
||||||
Access this field only through <tt>symbol</tt>'s interface functions.
|
|
||||||
\sa symbol::destructor */
|
|
||||||
location destructor_location;
|
|
||||||
|
|
||||||
/** Any \c \%printer declared specifically for this symbol.
|
/** Any \c \%printer declared specifically for this symbol.
|
||||||
|
|
||||||
Access this field only through <tt>symbol</tt>'s interface functions.
|
Access this field only through <tt>symbol</tt>'s interface functions.
|
||||||
\sa symbol::destructor */
|
\sa symbol::destructor */
|
||||||
const char *printer;
|
code_props printer;
|
||||||
|
|
||||||
/** The location of \c symbol::printer.
|
|
||||||
|
|
||||||
Access this field only through <tt>symbol</tt>'s interface functions.
|
|
||||||
\sa symbol::destructor */
|
|
||||||
location printer_location;
|
|
||||||
|
|
||||||
symbol_number number;
|
symbol_number number;
|
||||||
location prec_location;
|
location prec_location;
|
||||||
@@ -144,26 +133,18 @@ void symbol_make_alias (symbol *sym, symbol *symval, location loc);
|
|||||||
void symbol_type_set (symbol *sym, uniqstr type_name, location loc);
|
void symbol_type_set (symbol *sym, uniqstr type_name, location loc);
|
||||||
|
|
||||||
/** Set the \c destructor associated with \c sym. */
|
/** Set the \c destructor associated with \c sym. */
|
||||||
void symbol_destructor_set (symbol *sym, const char *destructor, location loc);
|
void symbol_destructor_set (symbol *sym, code_props const *destructor);
|
||||||
|
|
||||||
/** Get the computed \c \%destructor for \c sym, or \c NULL if none. */
|
/** Get the computed \c \%destructor for \c sym, which was initialized with
|
||||||
const char *symbol_destructor_get (symbol *sym);
|
\c code_props_none_init if there's no \c \%destructor. */
|
||||||
|
code_props const *symbol_destructor_get (symbol const *sym);
|
||||||
/** Get the grammar location of the computed \c \%destructor for \c sym.
|
|
||||||
|
|
||||||
\pre <tt>symbol_destructor_get (sym) != NULL</tt> */
|
|
||||||
location symbol_destructor_location_get (symbol *sym);
|
|
||||||
|
|
||||||
/** Set the \c printer associated with \c sym. */
|
/** Set the \c printer associated with \c sym. */
|
||||||
void symbol_printer_set (symbol *sym, const char *printer, location loc);
|
void symbol_printer_set (symbol *sym, code_props const *printer);
|
||||||
|
|
||||||
/** Get the computed \c \%printer for \c sym, or \c NULL if none. */
|
/** Get the computed \c \%printer for \c sym, which was initialized with
|
||||||
const char *symbol_printer_get (symbol *sym);
|
\c code_props_none_init if there's no \c \%printer. */
|
||||||
|
code_props const *symbol_printer_get (symbol const *sym);
|
||||||
/** Get the grammar location of the computed \c \%printer for \c sym.
|
|
||||||
|
|
||||||
\pre <tt>symbol_printer_get (sym) != NULL</tt> */
|
|
||||||
location symbol_printer_location_get (symbol *sym);
|
|
||||||
|
|
||||||
/* Set the \c precedence associated with \c sym.
|
/* Set the \c precedence associated with \c sym.
|
||||||
|
|
||||||
@@ -209,14 +190,9 @@ typedef struct {
|
|||||||
uniqstr tag;
|
uniqstr tag;
|
||||||
|
|
||||||
/** Any \c %destructor declared for this semantic type. */
|
/** Any \c %destructor declared for this semantic type. */
|
||||||
const char *destructor;
|
code_props destructor;
|
||||||
/** The location of \c semantic_type::destructor. */
|
|
||||||
location destructor_location;
|
|
||||||
|
|
||||||
/** Any \c %printer declared for this semantic type. */
|
/** Any \c %printer declared for this semantic type. */
|
||||||
const char *printer;
|
code_props printer;
|
||||||
/** The location of \c semantic_type::printer. */
|
|
||||||
location printer_location;
|
|
||||||
} semantic_type;
|
} semantic_type;
|
||||||
|
|
||||||
/** Fetch (or create) the semantic type associated to KEY. */
|
/** Fetch (or create) the semantic type associated to KEY. */
|
||||||
@@ -226,12 +202,12 @@ semantic_type *semantic_type_from_uniqstr (const uniqstr key);
|
|||||||
semantic_type *semantic_type_get (const char *key);
|
semantic_type *semantic_type_get (const char *key);
|
||||||
|
|
||||||
/** Set the \c destructor associated with \c type. */
|
/** Set the \c destructor associated with \c type. */
|
||||||
void semantic_type_destructor_set (semantic_type *type, const char *destructor,
|
void semantic_type_destructor_set (semantic_type *type,
|
||||||
location loc);
|
code_props const *destructor);
|
||||||
|
|
||||||
/** Set the \c printer associated with \c type. */
|
/** Set the \c printer associated with \c type. */
|
||||||
void semantic_type_printer_set (semantic_type *type, const char *printer,
|
void semantic_type_printer_set (semantic_type *type,
|
||||||
location loc);
|
code_props const *printer);
|
||||||
|
|
||||||
/*----------------------------------.
|
/*----------------------------------.
|
||||||
| Symbol and semantic type tables. |
|
| Symbol and semantic type tables. |
|
||||||
@@ -260,13 +236,13 @@ void symbols_pack (void);
|
|||||||
`---------------------------------------*/
|
`---------------------------------------*/
|
||||||
|
|
||||||
/** Set the default \c \%destructor for tagged values. */
|
/** Set the default \c \%destructor for tagged values. */
|
||||||
void default_tagged_destructor_set (const char *destructor, location loc);
|
void default_tagged_destructor_set (code_props const *destructor);
|
||||||
/** Set the default \c \%destructor for tagless values. */
|
/** Set the default \c \%destructor for tagless values. */
|
||||||
void default_tagless_destructor_set (const char *destructor, location loc);
|
void default_tagless_destructor_set (code_props const *destructor);
|
||||||
|
|
||||||
/** Set the default \c \%printer for tagged values. */
|
/** Set the default \c \%printer for tagged values. */
|
||||||
void default_tagged_printer_set (const char *printer, location loc);
|
void default_tagged_printer_set (code_props const *printer);
|
||||||
/** Set the default \c \%printer for tagless values. */
|
/** Set the default \c \%printer for tagless values. */
|
||||||
void default_tagless_printer_set (const char *printer, location loc);
|
void default_tagless_printer_set (code_props const *printer);
|
||||||
|
|
||||||
#endif /* !SYMTAB_H_ */
|
#endif /* !SYMTAB_H_ */
|
||||||
|
|||||||
Reference in New Issue
Block a user