mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
Change the handling of the symbols in the skeletons.
Before we were using tables which lines were the symbols and which columns were things like number, tag, type-name etc. It is was difficult to extend: each time a column was added, all the numbers had to be updated (you asked for colon $2, not for "tag"). Also, it was hard to filter these tables when only a subset of the symbols (say the tokens, or the nterms, or the tokens that have and external number *and* a type-name) was of interest. Now instead of monolithic tables, we define one macro per cell. For instance "b4_symbol(0, tag)" is a macro name which contents is self-decriptive. The macro "b4_symbol" provides easier access to these cells. * src/output.c (type_names_output): Remove. (symbol_numbers_output, symbol_definitions_output): New. (muscles_output): Call them. (prepare_symbols): Define b4_symbols_number.
This commit is contained in:
21
ChangeLog
21
ChangeLog
@@ -1,3 +1,24 @@
|
||||
2008-11-10 Akim Demaille <demaille@gostai.com>
|
||||
|
||||
Change the handling of the symbols in the skeletons.
|
||||
Before we were using tables which lines were the symbols and which
|
||||
columns were things like number, tag, type-name etc. It is was
|
||||
difficult to extend: each time a column was added, all the numbers had
|
||||
to be updated (you asked for colon $2, not for "tag"). Also, it was
|
||||
hard to filter these tables when only a subset of the symbols (say the
|
||||
tokens, or the nterms, or the tokens that have and external number
|
||||
*and* a type-name) was of interest.
|
||||
|
||||
Now instead of monolithic tables, we define one macro per cell. For
|
||||
instance "b4_symbol(0, tag)" is a macro name which contents is
|
||||
self-decriptive. The macro "b4_symbol" provides easier access to
|
||||
these cells.
|
||||
|
||||
* src/output.c (type_names_output): Remove.
|
||||
(symbol_numbers_output, symbol_definitions_output): New.
|
||||
(muscles_output): Call them.
|
||||
(prepare_symbols): Define b4_symbols_number.
|
||||
|
||||
2008-11-10 Akim Demaille <demaille@gostai.com>
|
||||
|
||||
--trace=muscles
|
||||
|
||||
@@ -105,6 +105,14 @@ m4_define([b4_rhs_location],
|
||||
[b4_rhs_data([$1], [$2]).location])
|
||||
|
||||
|
||||
# b4_symbol(NUM, FIELD)
|
||||
# ---------------------
|
||||
# Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
|
||||
# undefined.
|
||||
m4_define([b4_symbol],
|
||||
[m4_indir([b4_symbol($1, $2)])])
|
||||
|
||||
|
||||
# b4_symbol_actions(FILENAME, LINENO,
|
||||
# SYMBOL-TAG, SYMBOL-NUM,
|
||||
# SYMBOL-ACTION, SYMBOL-TYPENAME)
|
||||
@@ -124,13 +132,15 @@ m4_popdef([b4_dollar_dollar])dnl
|
||||
])
|
||||
|
||||
|
||||
# b4_symbol_action_(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
|
||||
# ----------------------------------------------------------
|
||||
# b4_symbol_action_(NUM)
|
||||
# ----------------------
|
||||
# Invoke b4_dollar_dollar(SYMBOL_TYPENAME) for each symbol.
|
||||
m4_define([b4_symbol_action_],
|
||||
[m4_ifval($3,
|
||||
[ case $2: // $1
|
||||
b4_dollar_dollar($@);
|
||||
[m4_ifval(b4_symbol([$1], [type_name]),
|
||||
[ case b4_symbol([$1], [number]): // b4_symbol([$1], [tag])
|
||||
b4_dollar_dollar([b4_symbol([$1], [number])],
|
||||
[b4_symbol([$1], [tag])],
|
||||
[b4_symbol([$1], [type_name])]);
|
||||
break;
|
||||
])])
|
||||
|
||||
@@ -144,7 +154,7 @@ m4_define([b4_symbol_variant],
|
||||
[$2.$3<$][3>(m4_shift3($@))])dnl
|
||||
switch ($1)
|
||||
{
|
||||
m4_map([b4_symbol_action_], m4_defn([b4_type_names]))
|
||||
m4_map([b4_symbol_action_], m4_defn([b4_symbol_numbers]))
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -166,8 +176,8 @@ m4_define([_b4_char_sizeof_dummy],
|
||||
dummy[]_b4_char_sizeof_counter])
|
||||
|
||||
|
||||
# b4_char_sizeof(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
|
||||
# -------------------------------------------------------
|
||||
# b4_char_sizeof(SYMBOL-NUM)
|
||||
# --------------------------
|
||||
# To be mapped on the list of type names to produce:
|
||||
#
|
||||
# char dummy1[sizeof(type_name_1)];
|
||||
@@ -176,9 +186,9 @@ dummy[]_b4_char_sizeof_counter])
|
||||
# for defined type names.
|
||||
# $3 is doubly-quoted, do not quote it again.
|
||||
m4_define([b4_char_sizeof],
|
||||
[m4_ifval($3,
|
||||
[m4_ifval(b4_symbol([$1], [type_name]),
|
||||
[
|
||||
char _b4_char_sizeof_dummy@{sizeof($3)@}; // $1])dnl
|
||||
char _b4_char_sizeof_dummy@{sizeof([b4_symbol([$1], [type_name])])@}; // b4_symbol([$1], [tag])])dnl
|
||||
])
|
||||
|
||||
|
||||
@@ -358,7 +368,7 @@ do { \
|
||||
]b4_variant_if(
|
||||
[ /// An auxiliary type to compute the largest semantic type.
|
||||
union union_type
|
||||
{]m4_map([b4_char_sizeof], m4_defn([b4_type_names]))[
|
||||
{]m4_map([b4_char_sizeof], m4_defn([b4_symbol_numbers]))[
|
||||
};
|
||||
|
||||
/// Symbol semantic values.
|
||||
@@ -844,7 +854,7 @@ b4_percent_code_get[]dnl
|
||||
// User destructor.
|
||||
switch (yytype)
|
||||
{
|
||||
]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
|
||||
]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
|
||||
default:
|
||||
break;
|
||||
}]b4_variant_if([
|
||||
@@ -865,7 +875,7 @@ b4_percent_code_get[]dnl
|
||||
<< yysym.location << ": ";
|
||||
switch (yytype)
|
||||
{
|
||||
]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
|
||||
]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
|
||||
[ default:
|
||||
break;
|
||||
}
|
||||
|
||||
65
src/output.c
65
src/output.c
@@ -143,6 +143,7 @@ prepare_symbols (void)
|
||||
MUSCLE_INSERT_BOOL ("token_table", token_table_flag);
|
||||
MUSCLE_INSERT_INT ("tokens_number", ntokens);
|
||||
MUSCLE_INSERT_INT ("nterms_number", nvars);
|
||||
MUSCLE_INSERT_INT ("symbols_number", nsyms);
|
||||
MUSCLE_INSERT_INT ("undef_token_number", undeftoken->number);
|
||||
MUSCLE_INSERT_INT ("user_token_number_max", max_user_token_number);
|
||||
|
||||
@@ -283,26 +284,17 @@ prepare_states (void)
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------.
|
||||
| For each symbol type, its tags and type name. |
|
||||
`-----------------------------------------------*/
|
||||
/*-------------------------------------.
|
||||
| The list of all the symbol numbers. |
|
||||
`-------------------------------------*/
|
||||
|
||||
static void
|
||||
type_names_output (FILE *out)
|
||||
symbol_numbers_output (FILE *out)
|
||||
{
|
||||
int i;
|
||||
|
||||
fputs ("m4_define([b4_type_names],\n[", out);
|
||||
fputs ("m4_define([b4_symbol_numbers],\n[", out);
|
||||
for (i = 0; i < nsyms; ++i)
|
||||
{
|
||||
symbol *sym = symbols[i];
|
||||
/* Symbol-name, Symbol-number, optional typename. */
|
||||
fprintf (out, "%s[", i ? ",\n" : "");
|
||||
escaped_output (out, sym->tag);
|
||||
fprintf (out, ", %d, [[%s]]]",
|
||||
sym->number,
|
||||
sym->type_name ? sym->type_name : "");
|
||||
}
|
||||
fprintf (out, "%s[%d]", i ? ", " : "", i);
|
||||
fputs ("])\n\n", out);
|
||||
}
|
||||
|
||||
@@ -351,6 +343,42 @@ merger_output (FILE *out)
|
||||
fputs ("]])\n\n", out);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------.
|
||||
| Output the symbol definitions to OUT. |
|
||||
`---------------------------------------*/
|
||||
|
||||
static void
|
||||
symbol_definitions_output (FILE *out)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < nsyms; ++i)
|
||||
{
|
||||
symbol *sym = symbols[i];
|
||||
const char *key;
|
||||
|
||||
#define SET_KEY(Entry) \
|
||||
obstack_fgrow2 (&format_obstack, "symbol(%d, %s)", i, Entry); \
|
||||
obstack_1grow (&format_obstack, 0); \
|
||||
key = obstack_finish (&format_obstack);
|
||||
|
||||
SET_KEY("tag");
|
||||
MUSCLE_INSERT_STRING (key, sym->tag);
|
||||
|
||||
SET_KEY("user_number");
|
||||
MUSCLE_INSERT_INT (key, sym->user_token_number);
|
||||
|
||||
SET_KEY("number");
|
||||
MUSCLE_INSERT_INT (key, sym->number);
|
||||
|
||||
SET_KEY("type_name");
|
||||
MUSCLE_INSERT_STRING (key, sym->type_name ? sym->type_name : "");
|
||||
|
||||
#undef SET_KEY
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------------------.
|
||||
| Output the tokens definition to OUT. |
|
||||
`--------------------------------------*/
|
||||
@@ -496,12 +524,13 @@ muscles_output (FILE *out)
|
||||
{
|
||||
fputs ("m4_init()\n", out);
|
||||
|
||||
type_names_output (out);
|
||||
user_actions_output (out);
|
||||
merger_output (out);
|
||||
token_definitions_output (out);
|
||||
symbol_code_props_output (out, "destructors", &symbol_destructor_get);
|
||||
symbol_code_props_output (out, "printers", &symbol_printer_get);
|
||||
symbol_definitions_output (out);
|
||||
symbol_numbers_output (out);
|
||||
token_definitions_output (out);
|
||||
user_actions_output (out);
|
||||
|
||||
muscles_m4_output (out);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user