Compare commits

...
Author SHA1 Message Date
Akim Demaille 52ca964032 m4: optimize.
* data/bison.m4, data/java.m4, data/variant.hh: m4_map_args is reported
to be faster than m4_map.
2012-07-22 12:00:44 +02:00
Akim Demaille 485b319598 autoconf: update.
* submodules/autoconf: here.
No significant changes for our use of m4sugar.m4.
2012-07-22 11:53:31 +02:00
Akim Demaille 1ed94b7c84 fixup! output: use the token list to define the yytokentype 2012-07-22 09:19:55 +02:00
Akim Demaille b119971aef output: no longer use b4_tokens.
* data/glr.c, data/glr.cc, data/lalr1.cc, data/lalr1.java, data/yacc.c:
Since the previous commit, b4_tokens_define and the like no longer need
b4_tokens.
* src/output.c (token_definitions_output): Remove.
2012-07-22 09:13:36 +02:00
Akim Demaille 2a0f5b17b4 output: use the token list to define the yytokentype
There are currently two systems used to pass information about tokens to
m4: the original one, and another, which is used for instance for
printers and destructors, variants etc.  Move to using only the latter.

* data/bison.m4 (b4_symbol_map, b4_token_visible_if)
(b4_token_has_definition, b4_any_token_visible_if, b4_token_format): New.
* data/c++.m4, data/c.m4, data/glr.c, data/java.m4: Adjust to use them.
2012-07-22 09:11:37 +02:00
13 changed files with 103 additions and 105 deletions
-5
View File
@@ -2,11 +2,6 @@
** Variable names.
What should we name `variant' and `lex_symbol'?
** Use b4_symbol in all the skeleton
Move its definition in the more standard places and deploy it in other
skeletons. Then remove the older system, including the tables
generated by output.c
** Update the documentation on gnu.org
** Get rid of fake #lines [Bison: ...]
+47 -1
View File
@@ -326,6 +326,13 @@ b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated.
## Symbols. ##
## --------- ##
# In order to unify the handling of the various aspects of symbols
# (tag, type_name, whether terminal, etc.), bison.exe defines one
# macro per (token, field), where field can has_id, id, etc.: see
# src/output.c:prepare_symbols_definitions().
#
# The following macros provide access to these values.
# b4_symbol_(NUM, FIELD)
# ----------------------
# Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
@@ -406,6 +413,45 @@ m4_define([b4_symbol_case_],
m4_define([b4_symbol_foreach],
[m4_map([$1], m4_defn([b4_symbol_numbers]))])
# b4_symbol_map(MACRO)
# --------------------
# Return a list (possibly empty elements) of MACRO invoked for each
# SYMBOL-NUM.
m4_define([b4_symbol_map],
[m4_map_args_sep([$1(], [)], [,], b4_symbol_numbers)])
# b4_token_visible_if(NUM, IF-TRUE, IF-FALSE)
# -------------------------------------------
# Whether NUM denotes a token that has an exported definition (i.e.,
# shows in enum yytokentype).
m4_define([b4_token_visible_if],
[b4_symbol_if([$1], [is_token],
[b4_symbol_if([$1], [has_id], [$2], [$3])],
[$3])])
# b4_token_has_definition(NUM)
# ----------------------------
# 1 if NUM is visible, nothing otherwise.
m4_define([b4_token_has_definition],
[b4_token_visible_if([$1], [1])])
# b4_any_token_visible_if([IF-TRUE], [IF-FALSE])
# ----------------------------------------------
# Whether there is a token that needs to be defined.
m4_define([b4_any_token_visible_if],
[m4_ifval(b4_symbol_foreach([b4_token_has_definition]),
[$1], [$2])])
# b4_token_format(FORMAT, NUM)
# ----------------------------
m4_define([b4_token_format],
[b4_token_visible_if([$2],
[m4_quote(m4_format([$1],
[b4_symbol([$2], [id])],
[b4_symbol([$2], [user_number])]))])])
## ------- ##
## Types. ##
@@ -417,7 +463,7 @@ m4_define([b4_symbol_foreach],
# Skip NUMS that have no type-name.
m4_define([b4_type_action_],
[b4_symbol_if([$1], [has_type],
[m4_map([b4_symbol_case_], [$@])[]dnl
[m4_map_args([b4_symbol_case_], $@)[]dnl
b4_dollar_dollar([b4_symbol([$1], [number])],
[b4_symbol([$1], [tag])],
[b4_symbol([$1], [type])]);
+10 -10
View File
@@ -86,17 +86,17 @@ m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref[ ]),
[::\([^][:]\|:[^:]\)*], [} ])[} // ]b4_namespace_ref])])
# b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
# -----------------------------------------------------
# b4_token_enums
# --------------
# Output the definition of the tokens as enums.
m4_define([b4_token_enums],
[/* Tokens. */
enum yytokentype {
m4_map_sep([ b4_token_enum], [,
],
[$@])
};
])
[[/* Tokens. */
enum yytokentype {
]m4_join([,
],
b4_symbol_map([b4_token_enum]))[
};
]])
@@ -143,7 +143,7 @@ m4_define([b4_public_types_declare],
/// Tokens.
struct token
{
]b4_token_enums(b4_tokens)[
]b4_token_enums[
};
/// Token type.
+27 -32
View File
@@ -250,57 +250,52 @@ static const b4_int_type_for([$2]) yy$1[[]] =
## Assigning token numbers. ##
## ------------------------- ##
# b4_token_define(TOKEN-NAME, TOKEN-NUMBER)
# -----------------------------------------
# b4_token_define(TOKEN-NUM)
# --------------------------
# Output the definition of this token as #define.
m4_define([b4_token_define],
[#define b4_percent_define_get([api.tokens.prefix])$1 $2
])
[b4_token_format([#define %s %s], [$1])])
# b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
# -------------------------------------------------------
# Output the definition of the tokens (if there are) as #defines.
# b4_token_defines
# ----------------
# Output the definition of the tokens.
m4_define([b4_token_defines],
[m4_if([$#$1], [1], [],
[/* Tokens. */
m4_map([b4_token_define], [$@])])
])
[b4_any_token_visible_if([/* Tokens. */
m4_join([
], b4_symbol_map([b4_token_define]))])])
# b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)
# ---------------------------------------
# b4_token_enum(TOKEN-NUM)
# ------------------------
# Output the definition of this token as an enum.
m4_define([b4_token_enum],
[b4_percent_define_get([api.tokens.prefix])$1 = $2])
[b4_token_format([ %s = %s], [$1])])
# b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
# -----------------------------------------------------
# b4_token_enums
# --------------
# Output the definition of the tokens (if there are) as enums.
m4_define([b4_token_enums],
[m4_if([$#$1], [1], [],
[[/* Tokens. */
[b4_any_token_visible_if([[/* Tokens. */
#ifndef ]b4_api_PREFIX[TOKENTYPE
# define ]b4_api_PREFIX[TOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum ]b4_api_prefix[tokentype {
]m4_map_sep([ b4_token_enum], [,
],
[$@])
};[
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum ]b4_api_prefix[tokentype {
]m4_join([,
],
b4_symbol_map([b4_token_enum]))[
};
#endif
]])])
# b4_token_enums_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
# -------------------------------------------------------------
# Output the definition of the tokens (if there are any) as enums and, if POSIX
# Yacc is enabled, as #defines.
# b4_token_enums_defines
# ----------------------
# Output the definition of the tokens (if there are any) as enums and,
# if POSIX Yacc is enabled, as #defines.
m4_define([b4_token_enums_defines],
[b4_token_enums($@)b4_yacc_if([b4_token_defines($@)], [])
])
[b4_token_enums[]b4_yacc_if([b4_token_defines])])
## ----------------- ##
+1 -1
View File
@@ -176,7 +176,7 @@ m4_define([b4_rhs_location],
m4_define([b4_shared_declarations],
[b4_declare_yydebug[
]b4_percent_code_get([[requires]])[
]b4_token_enums(b4_tokens)[
]b4_token_enums[
]b4_declare_yylstype[
]b4_c_ansi_function_decl(b4_prefix[parse], [int], b4_parse_param)[
]b4_percent_code_get([[provides]])[]dnl
+1 -1
View File
@@ -300,7 +300,7 @@ b4_copyright([Skeleton interface for Bison GLR parsers in C++],
]dnl Redirections for glr.c.
b4_percent_define_flag_if([[global_tokens_and_yystype]],
[b4_token_defines(b4_tokens)])
[b4_token_defines])
[
#ifndef ]b4_api_PREFIX[STYPE
# define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class_name[::semantic_type
+12 -15
View File
@@ -142,23 +142,20 @@ m4_define([b4_integral_parser_table_define],
## Assigning token numbers. ##
## ------------------------- ##
# b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)
# ---------------------------------------
# b4_token_enum(TOKEN-NUM)
# ------------------------
# Output the definition of this token as an enum.
m4_define([b4_token_enum],
[ /** Token number, to be returned by the scanner. */
static final int b4_percent_define_get([api.tokens.prefix])$1 = $2;
])
[b4_token_format([ /** Token number, to be returned by the scanner. */
static final int %s = %s;
], [$1])])
# b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
# -----------------------------------------------------
# b4_token_enums
# --------------
# Output the definition of the tokens (if there are) as enums.
m4_define([b4_token_enums],
[m4_if([$#$1], [1], [],
[/* Tokens. */
m4_map([b4_token_enum], [$@])])
])
[b4_any_token_visible_if([/* Tokens. */
b4_symbol_foreach([b4_token_enum])])])
# b4-case(ID, CODE)
# -----------------
@@ -263,7 +260,7 @@ m4_define([b4_lex_param_decl],
[$1])])
m4_define([b4_param_decls],
[m4_map([b4_param_decl], [$@])])
[m4_map_args([b4_param_decl], $@)])
m4_define([b4_param_decl], [, $1])
m4_define([b4_remove_comma], [m4_ifval(m4_quote($1), [$1, ], [])m4_shift2($@)])
@@ -290,7 +287,7 @@ m4_define([b4_lex_param_call],
b4_param_calls(b4_lex_param))],
[$1])])
m4_define([b4_param_calls],
[m4_map([b4_param_call], [$@])])
[m4_map_args([b4_param_call], $@)])
m4_define([b4_param_call], [, $2])
@@ -303,7 +300,7 @@ m4_define([b4_parse_param_cons],
[b4_constructor_calls(b4_parse_param)])])
m4_define([b4_constructor_calls],
[m4_map([b4_constructor_call], [$@])])
[m4_map_args([b4_constructor_call], $@)])
m4_define([b4_constructor_call],
[this.$2 = $2;
])
+1 -1
View File
@@ -333,7 +333,7 @@ b4_public_types_define])[
]b4_namespace_close[
]b4_percent_define_flag_if([[global_tokens_and_yystype]],
[b4_token_defines(b4_tokens)
[b4_token_defines
#ifndef ]b4_api_PREFIX[STYPE
/* Redirection for backward compatibility. */
+1 -1
View File
@@ -133,7 +133,7 @@ b4_locations_if([[
/** Token returned by the scanner to signal the end of its input. */
public static final int EOF = 0;
]b4_token_enums(b4_tokens)[
]b4_token_enums[
]b4_locations_if([[/**
* Method to retrieve the beginning position of the last scanned token.
+1 -1
View File
@@ -69,7 +69,7 @@ m4_define([b4_char_sizeof_],
m4_define([b4_char_sizeof],
[b4_symbol_if([$1], [has_type],
[
m4_map([b4_char_sizeof_], [$@])dnl
m4_map_args([b4_char_sizeof_], $@)dnl
char _b4_char_sizeof_dummy@{sizeof([b4_symbol([$1], [type])])@};
])])
+1 -1
View File
@@ -284,7 +284,7 @@ m4_define([b4_shared_declarations],
[b4_cpp_guard_open([b4_spec_defines_file])[
]b4_declare_yydebug[
]b4_percent_code_get([[requires]])[
]b4_token_enums_defines(b4_tokens)[
]b4_token_enums_defines[
]b4_declare_yylstype[
]b4_declare_yyparse[
]b4_percent_code_get([[provides]])[
-35
View File
@@ -469,40 +469,6 @@ prepare_symbol_definitions (void)
}
/*--------------------------------------.
| Output the tokens definition to OUT. |
`--------------------------------------*/
static void
token_definitions_output (FILE *out)
{
int i;
char const *sep = "";
fputs ("m4_define([b4_tokens], \n[", out);
for (i = 0; i < ntokens; ++i)
{
symbol *sym = symbols[i];
int number = sym->user_token_number;
uniqstr id = symbol_id_get (sym);
/* At this stage, if there are literal string aliases, they are
part of SYMBOLS, so we should not find their aliased symbols
here. */
aver (number != USER_NUMBER_HAS_STRING_ALIAS);
/* Skip error token and tokens without identifier. */
if (sym != errtoken && id)
{
fprintf (out, "%s[[[%s]], %d]",
sep, id, number);
sep = ",\n";
}
}
fputs ("])\n\n", out);
}
static void
prepare_actions (void)
{
@@ -561,7 +527,6 @@ muscles_output (FILE *out)
fputs ("m4_init()\n", out);
merger_output (out);
symbol_numbers_output (out);
token_definitions_output (out);
type_names_output (out);
user_actions_output (out);
// Must be last.