mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
Use the symbol properties to output the printer/destructor for lalr1.cc.
Instead of defining complex list of tuples to define various properties of the symbols, we now prefer to define symbols as "structs" in m4: using the symbol key (its number), and the property name, b4_symbol gives it value. Use this to handle destructors and printers. * src/output.c (CODE_PROP): New. (prepare_symbol_definitions): Use it to define the printer and destructor related attributes of the symbols. * data/lalr1.cc (b4_symbol_actions): Rename as... (b4_symbol_action): this. Use b4_symbol instead of 6 arguments. (b4_symbol_printer, b4_symbol_destructor): New. Use them instead of b4_symbol_actions.
This commit is contained in:
17
ChangeLog
17
ChangeLog
@@ -1,3 +1,20 @@
|
|||||||
|
2008-12-01 Akim Demaille <demaille@gostai.com>
|
||||||
|
|
||||||
|
Use the symbol properties to output the printer/destructor for lalr1.cc.
|
||||||
|
Instead of defining complex list of tuples to define various properties of
|
||||||
|
the symbols, we now prefer to define symbols as "structs" in m4: using the
|
||||||
|
symbol key (its number), and the property name, b4_symbol gives it value.
|
||||||
|
Use this to handle destructors and printers.
|
||||||
|
|
||||||
|
* src/output.c (CODE_PROP): New.
|
||||||
|
(prepare_symbol_definitions): Use it to define the printer and
|
||||||
|
destructor related attributes of the symbols.
|
||||||
|
* data/lalr1.cc (b4_symbol_actions): Rename as...
|
||||||
|
(b4_symbol_action): this.
|
||||||
|
Use b4_symbol instead of 6 arguments.
|
||||||
|
(b4_symbol_printer, b4_symbol_destructor): New.
|
||||||
|
Use them instead of b4_symbol_actions.
|
||||||
|
|
||||||
2008-12-01 Akim Demaille <demaille@gostai.com>
|
2008-12-01 Akim Demaille <demaille@gostai.com>
|
||||||
|
|
||||||
Avoid capturing variables too easily.
|
Avoid capturing variables too easily.
|
||||||
|
|||||||
@@ -152,23 +152,33 @@ m4_define([b4_symbol_if],
|
|||||||
[m4_fatal([$0: field $2 of $1 is not a Boolean:] b4_symbol([$1], [$2]))])])
|
[m4_fatal([$0: field $2 of $1 is not a Boolean:] b4_symbol([$1], [$2]))])])
|
||||||
|
|
||||||
|
|
||||||
# b4_symbol_actions(FILENAME, LINENO,
|
# b4_symbol_action(SYMBOL-NUM, KIND)
|
||||||
# SYMBOL-TAG, SYMBOL-NUM,
|
# ----------------------------------
|
||||||
# SYMBOL-ACTION, SYMBOL-TYPENAME)
|
# Run the action KIND (destructor or printer) for SYMBOL-NUM.
|
||||||
# -------------------------------------------------
|
|
||||||
# Same as in C, but using references instead of pointers.
|
# Same as in C, but using references instead of pointers.
|
||||||
m4_define([b4_symbol_actions],
|
m4_define([b4_symbol_action],
|
||||||
|
[b4_symbol_if([$1], [has_$2],
|
||||||
[m4_pushdef([b4_dollar_dollar],
|
[m4_pushdef([b4_dollar_dollar],
|
||||||
[b4_symbol_value_template([yysym.value], [$6])])dnl
|
[b4_symbol_value_template([yysym.value],
|
||||||
|
b4_symbol_if([$1], [has_type],
|
||||||
|
[b4_symbol([$1], [type])]))])dnl
|
||||||
m4_pushdef([b4_at_dollar], [yysym.location])dnl
|
m4_pushdef([b4_at_dollar], [yysym.location])dnl
|
||||||
case $4: // $3
|
case $1: // b4_symbol([$1], [tag])
|
||||||
b4_syncline([$2], [$1])
|
b4_syncline([b4_symbol([$1], [$2_line])], ["b4_symbol([$1], [$2_file])"])
|
||||||
$5;
|
b4_symbol([$1], [$2])
|
||||||
b4_syncline([@oline@], [@ofile@])
|
b4_syncline([@oline@], [@ofile@])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
m4_popdef([b4_at_dollar])dnl
|
m4_popdef([b4_at_dollar])dnl
|
||||||
m4_popdef([b4_dollar_dollar])dnl
|
m4_popdef([b4_dollar_dollar])dnl
|
||||||
])
|
])])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_symbol_destructor(SYMBOL-NUM)
|
||||||
|
# b4_symbol_printer(SYMBOL-NUM)
|
||||||
|
# --------------------------------
|
||||||
|
m4_define([b4_symbol_destructor], [b4_symbol_action([$1], [destructor])])
|
||||||
|
m4_define([b4_symbol_printer], [b4_symbol_action([$1], [printer])])
|
||||||
|
|
||||||
|
|
||||||
# b4_symbol_case_(SYMBOL-NUM)
|
# b4_symbol_case_(SYMBOL-NUM)
|
||||||
@@ -1027,9 +1037,9 @@ b4_percent_code_get[]dnl
|
|||||||
// User destructor.
|
// User destructor.
|
||||||
switch (yytype)
|
switch (yytype)
|
||||||
{
|
{
|
||||||
]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
|
]m4_map([b4_symbol_destructor], m4_defn([b4_symbol_numbers]))dnl
|
||||||
default:
|
[ default:
|
||||||
break;
|
break;
|
||||||
}]b4_variant_if([
|
}]b4_variant_if([
|
||||||
|
|
||||||
// Type destructor.
|
// Type destructor.
|
||||||
@@ -1048,8 +1058,8 @@ b4_percent_code_get[]dnl
|
|||||||
<< yysym.location << ": "])[;
|
<< yysym.location << ": "])[;
|
||||||
switch (yytype)
|
switch (yytype)
|
||||||
{
|
{
|
||||||
]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))[
|
]m4_map([b4_symbol_printer], m4_defn([b4_symbol_numbers]))dnl
|
||||||
default:
|
[ default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
yyo << ')';
|
yyo << ')';
|
||||||
|
|||||||
22
src/output.c
22
src/output.c
@@ -428,6 +428,28 @@ prepare_symbol_definitions (void)
|
|||||||
SET_KEY("type");
|
SET_KEY("type");
|
||||||
MUSCLE_INSERT_STRING (key, sym->type_name ? sym->type_name : "");
|
MUSCLE_INSERT_STRING (key, sym->type_name ? sym->type_name : "");
|
||||||
|
|
||||||
|
#define CODE_PROP(PropName) \
|
||||||
|
do { \
|
||||||
|
code_props const *p = symbol_ ## PropName ## _get (sym); \
|
||||||
|
SET_KEY("has_" #PropName); \
|
||||||
|
MUSCLE_INSERT_INT (key, !!p->code); \
|
||||||
|
\
|
||||||
|
if (p->code) \
|
||||||
|
{ \
|
||||||
|
SET_KEY(#PropName "_file"); \
|
||||||
|
MUSCLE_INSERT_STRING (key, p->location.start.file); \
|
||||||
|
\
|
||||||
|
SET_KEY(#PropName "_line"); \
|
||||||
|
MUSCLE_INSERT_INT (key, p->location.start.line); \
|
||||||
|
\
|
||||||
|
SET_KEY(#PropName); \
|
||||||
|
MUSCLE_INSERT_STRING_RAW (key, p->code); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
CODE_PROP(destructor);
|
||||||
|
CODE_PROP(printer);
|
||||||
|
#undef CODE_PROP
|
||||||
#undef SET_KEY
|
#undef SET_KEY
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user