mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-18 00:33:03 +00:00
Classify symbols by type-name.
* src/uniqstr.h (UNIQSTR_CMP): New. * src/output.c (symbol_type_name_cmp, symbols_by_type_name) (type_names_output): New. (muscles_output): Use it. * data/lalr1.cc (b4_symbol_action_): Remove. (b4_symbol_case_, b4_type_action_): New. Adjust uses of b4_symbol_action_ to use b4_type_action_.
This commit is contained in:
11
ChangeLog
11
ChangeLog
@@ -1,3 +1,14 @@
|
|||||||
|
2008-11-10 Akim Demaille <demaille@gostai.com>
|
||||||
|
|
||||||
|
Classify symbols by type-name.
|
||||||
|
* src/uniqstr.h (UNIQSTR_CMP): New.
|
||||||
|
* src/output.c (symbol_type_name_cmp, symbols_by_type_name)
|
||||||
|
(type_names_output): New.
|
||||||
|
(muscles_output): Use it.
|
||||||
|
* data/lalr1.cc (b4_symbol_action_): Remove.
|
||||||
|
(b4_symbol_case_, b4_type_action_): New.
|
||||||
|
Adjust uses of b4_symbol_action_ to use b4_type_action_.
|
||||||
|
|
||||||
2008-11-10 Akim Demaille <demaille@gostai.com>
|
2008-11-10 Akim Demaille <demaille@gostai.com>
|
||||||
|
|
||||||
Change the handling of the symbols in the skeletons.
|
Change the handling of the symbols in the skeletons.
|
||||||
|
|||||||
@@ -132,17 +132,25 @@ m4_popdef([b4_dollar_dollar])dnl
|
|||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
# b4_symbol_action_(NUM)
|
# b4_symbol_case_(SYMBOL-NUM)
|
||||||
# ----------------------
|
# ---------------------------
|
||||||
# Invoke b4_dollar_dollar(SYMBOL_TYPENAME) for each symbol.
|
# Issue a "case NUM" for SYMBOL-NUM.
|
||||||
m4_define([b4_symbol_action_],
|
m4_define([b4_symbol_case_],
|
||||||
[m4_ifval(b4_symbol([$1], [type_name]),
|
|
||||||
[ case b4_symbol([$1], [number]): // b4_symbol([$1], [tag])
|
[ case b4_symbol([$1], [number]): // b4_symbol([$1], [tag])
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_type_action_(NUMS)
|
||||||
|
# ---------------------
|
||||||
|
# Run actions for the symbol NUMS that all have the same type-name.
|
||||||
|
m4_define([b4_type_action_],
|
||||||
|
[m4_map([b4_symbol_case_], [$@])[]dnl
|
||||||
b4_dollar_dollar([b4_symbol([$1], [number])],
|
b4_dollar_dollar([b4_symbol([$1], [number])],
|
||||||
[b4_symbol([$1], [tag])],
|
[b4_symbol([$1], [tag])],
|
||||||
[b4_symbol([$1], [type_name])]);
|
[b4_symbol([$1], [type_name])]);
|
||||||
break;
|
break;
|
||||||
])])
|
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
# b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
|
# b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
|
||||||
@@ -154,7 +162,7 @@ m4_define([b4_symbol_variant],
|
|||||||
[$2.$3<$][3>(m4_shift3($@))])dnl
|
[$2.$3<$][3>(m4_shift3($@))])dnl
|
||||||
switch ($1)
|
switch ($1)
|
||||||
{
|
{
|
||||||
m4_map([b4_symbol_action_], m4_defn([b4_symbol_numbers]))
|
m4_map([b4_type_action_], m4_defn([b4_type_names]))[]dnl
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -860,7 +868,7 @@ b4_percent_code_get[]dnl
|
|||||||
}]b4_variant_if([
|
}]b4_variant_if([
|
||||||
|
|
||||||
// Type destructor.
|
// Type destructor.
|
||||||
b4_symbol_variant([[yytype]], [[yysym.value]], [[template destroy]])])[
|
b4_symbol_variant([[yytype]], [[yysym.value]], [[template destroy]])])[
|
||||||
}
|
}
|
||||||
|
|
||||||
#if YYDEBUG
|
#if YYDEBUG
|
||||||
|
|||||||
68
src/output.c
68
src/output.c
@@ -283,6 +283,69 @@ prepare_states (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------------------------------------------.
|
||||||
|
| Compare two symbols by type-name, and then by number. |
|
||||||
|
`-------------------------------------------------------*/
|
||||||
|
|
||||||
|
int
|
||||||
|
symbol_type_name_cmp (const symbol **lhs, const symbol **rhs)
|
||||||
|
{
|
||||||
|
int res = UNIQSTR_CMP((*lhs)->type_name, (*rhs)->type_name);
|
||||||
|
if (res)
|
||||||
|
return res;
|
||||||
|
return (*lhs)->number - (*rhs)->number;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------.
|
||||||
|
| Return a (malloc'ed) table of the symbols sorted by type-name. |
|
||||||
|
`----------------------------------------------------------------*/
|
||||||
|
|
||||||
|
static symbol **
|
||||||
|
symbols_by_type_name ()
|
||||||
|
{
|
||||||
|
typedef int (*qcmp_type) (const void *, const void *);
|
||||||
|
symbol **res = xmemdup (symbols, nsyms * sizeof *res);
|
||||||
|
qsort (res, nsyms, sizeof *res, (qcmp_type) &symbol_type_name_cmp);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------.
|
||||||
|
| Define b4_type_names, which is a list of (lists of the numbers of |
|
||||||
|
| symbols with same type-name). |
|
||||||
|
`------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
static void
|
||||||
|
type_names_output (FILE *out)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
const char *isep = "";
|
||||||
|
symbol **syms = symbols_by_type_name ();
|
||||||
|
fputs ("m4_define([b4_type_names],\n[", out);
|
||||||
|
for (i = 0; i < nsyms; )
|
||||||
|
if (syms[i]->type_name)
|
||||||
|
{
|
||||||
|
int j;
|
||||||
|
const char *jsep = "";
|
||||||
|
fprintf (out, "%s[", isep);
|
||||||
|
isep = ",\n";
|
||||||
|
for (j = i; j < nsyms; ++j)
|
||||||
|
{
|
||||||
|
if (syms[i]->type_name != syms[j]->type_name)
|
||||||
|
break;
|
||||||
|
fprintf (out, "%s%d", jsep, syms[j]->number);
|
||||||
|
jsep = ", ";
|
||||||
|
}
|
||||||
|
fputs ("]", out);
|
||||||
|
i = j;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
++i;
|
||||||
|
fputs ("])\n\n", out);
|
||||||
|
free (syms);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------------.
|
/*-------------------------------------.
|
||||||
| The list of all the symbol numbers. |
|
| The list of all the symbol numbers. |
|
||||||
@@ -523,15 +586,15 @@ static void
|
|||||||
muscles_output (FILE *out)
|
muscles_output (FILE *out)
|
||||||
{
|
{
|
||||||
fputs ("m4_init()\n", out);
|
fputs ("m4_init()\n", out);
|
||||||
|
|
||||||
merger_output (out);
|
merger_output (out);
|
||||||
symbol_code_props_output (out, "destructors", &symbol_destructor_get);
|
symbol_code_props_output (out, "destructors", &symbol_destructor_get);
|
||||||
symbol_code_props_output (out, "printers", &symbol_printer_get);
|
symbol_code_props_output (out, "printers", &symbol_printer_get);
|
||||||
symbol_definitions_output (out);
|
symbol_definitions_output (out);
|
||||||
symbol_numbers_output (out);
|
symbol_numbers_output (out);
|
||||||
token_definitions_output (out);
|
token_definitions_output (out);
|
||||||
|
type_names_output (out);
|
||||||
user_actions_output (out);
|
user_actions_output (out);
|
||||||
|
// Must be last.
|
||||||
muscles_m4_output (out);
|
muscles_m4_output (out);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -630,7 +693,6 @@ output_skeleton (void)
|
|||||||
free (full_m4bison);
|
free (full_m4bison);
|
||||||
free (full_skeleton);
|
free (full_skeleton);
|
||||||
|
|
||||||
|
|
||||||
if (trace_flag & trace_muscles)
|
if (trace_flag & trace_muscles)
|
||||||
muscles_output (stderr);
|
muscles_output (stderr);
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* Keeping a unique copy of strings.
|
/* Keeping a unique copy of strings.
|
||||||
|
|
||||||
Copyright (C) 2002, 2003 Free Software Foundation, Inc.
|
Copyright (C) 2002, 2003, 2008 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of Bison, the GNU Compiler Compiler.
|
This file is part of Bison, the GNU Compiler Compiler.
|
||||||
|
|
||||||
@@ -32,6 +32,10 @@ uniqstr uniqstr_new (char const *str);
|
|||||||
/* Two uniqstr values have the same value iff they are the same. */
|
/* Two uniqstr values have the same value iff they are the same. */
|
||||||
#define UNIQSTR_EQ(USTR1, USTR2) ((USTR1) == (USTR2))
|
#define UNIQSTR_EQ(USTR1, USTR2) ((USTR1) == (USTR2))
|
||||||
|
|
||||||
|
/* Compare two uniqstr a la strlen: negative for <, nul for =, and
|
||||||
|
positive for >. */
|
||||||
|
#define UNIQSTR_CMP(USTR1, USTR2) ((USTR1) - (USTR2))
|
||||||
|
|
||||||
/*--------------------------------------.
|
/*--------------------------------------.
|
||||||
| Initializing, destroying, debugging. |
|
| Initializing, destroying, debugging. |
|
||||||
`--------------------------------------*/
|
`--------------------------------------*/
|
||||||
|
|||||||
Reference in New Issue
Block a user