+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
[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)
])
-# 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;
])])
[$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;
}
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)];
# 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
])
]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.
// 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([
<< 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;
}
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);
-/*-----------------------------------------------.
-| 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);
}
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. |
`--------------------------------------*/
{
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);
}