From 0fc45ce97ce30c74f1a8b2024bed2ac3e491665e Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Fri, 2 Oct 2020 10:48:21 -0400 Subject: [PATCH] Clean up various sporadic symbol definitions that weren't going through ctrl. Includes handling of --nounistd, --always_interactive, --never_interactive, --stack, their corresponding lexer items, and and noinput. An unavoidable side effect is that the place where "#define YY_NO_INPUT 1" is inserted, if it's inserted. has to move because it's done by a different route - m4 expansion rather than the action_define function (which is now gone - this was the last use). I have put the new insertion point just iin time for the first reference to the macro. Otherwise the only diffs in generarted test code are symbol definitions becoming visible. #56 in the retargeting patch series --- src/cpp-flex.skl | 2 ++ src/flexdef.h | 12 +++++++----- src/gen.c | 2 +- src/main.c | 23 ++++++++++++++++++----- src/misc.c | 23 ----------------------- src/scan.l | 26 ++++++-------------------- 6 files changed, 34 insertions(+), 54 deletions(-) diff --git a/src/cpp-flex.skl b/src/cpp-flex.skl index 4d3af2cd..1042b020 100644 --- a/src/cpp-flex.skl +++ b/src/cpp-flex.skl @@ -1219,6 +1219,8 @@ static void yy_flex_strncpy ( char *, const char *, int M4_YY_PROTO_LAST_ARG); static int yy_flex_strlen ( const char * M4_YY_PROTO_LAST_ARG); #endif +m4_ifdef([[M4_MODE_NO_INPUT]], [[#define YY_NO_INPUT 1]]) + #ifndef YY_NO_INPUT %if-c-only Standard (non-C++) definition %not-for-header diff --git a/src/flexdef.h b/src/flexdef.h index 07d6078d..29d8dc39 100644 --- a/src/flexdef.h +++ b/src/flexdef.h @@ -356,6 +356,7 @@ extern struct flex_backend_t cpp_backend; * If it;s in this structure, it has a corresponding m4 symbol. */ struct ctrl_bundle_t { + bool always_interactive;// always use cheacter-by-character input FILE *backing_up_file; // file to summarize backing-up states to bool bison_bridge_lval; // (--bison-bridge), bison pure calling convention. bool bison_bridge_lloc; // (--bison-locations), bison yylloc. @@ -371,18 +372,22 @@ struct ctrl_bundle_t { bool fullspd; // (-F flag) use Jacobson method of table representation bool fulltbl; // (-Cf flag) don't compress the DFA state table bool gen_line_dirs; // (no -L flag) generate #line directives - trit interactive; // (-I) generate an interactive scanner + trit interactive; // (-I) generate an interactive scanner + bool never_interactive; // always use buffered input, don't check for tty/ bool lex_compat; // (-l), maximize compatibility with AT&T lex bool long_align; // (-Ca flag), favor long-word alignment for speed + bool no_input; // Suppress use of imnput() + bool no_unistd; // suppress inclusion of unistd.h bool posix_compat; // (-X) maximize compatibility with POSIX lex char *prefix; // prefix for externally visible names, default "yy" bool reentrant; // if true (-R), generate a reentrant C scanner + bool stack_used; // Enable use of start-condition stacks bool spprdflt; // (-s) suppress the default rule bool useecs; // (-Ce flag) use equivalence classes bool usemecs; // (-Cm flag), use meta-equivalence classes bool use_read; // (-f, -F, or -Cr) use read() for scanner input // otherwise, use fread(). - char *yyclass; // yyFlexLexer subclass to use for YY_DECL + char *yyclass; // yyFlexLexer subclass to use for YY_DECL bool yytext_is_array; // if true (i.e., %array directive), then declare // yytext as array instead of a character pointer. // Nice and inefficient. @@ -851,9 +856,6 @@ extern void usage(void); /* from file misc.c */ -/* Add a #define to the action file. */ -extern void action_define(const char *defname, int value); - /* Add the given text to the stored actions. */ extern void add_action(const char *new_text); diff --git a/src/gen.c b/src/gen.c index 940801ae..925b195e 100644 --- a/src/gen.c +++ b/src/gen.c @@ -65,7 +65,7 @@ static void geneoltbl (void) { int i; - outn ("m4_ifdef( [[M4_YY_USE_LINENO]],[["); + outn ("m4_ifdef( [[M4_MODE_YYLINENO]],[["); backend->comment ("Table of booleans, true if rule could match eol.\n"); footprint += backend->geneoltbl(num_rules + 1); diff --git a/src/main.c b/src/main.c index ffbf721f..559d8cd2 100644 --- a/src/main.c +++ b/src/main.c @@ -868,7 +868,7 @@ void flexinit (int argc, char **argv) break; case OPT_NO_UNISTD_H: - buf_m4_define( &m4defs_buf, "M4_YY_NO_UNISTD_H",0); + ctrl.no_unistd = true; break; case OPT_TABLES_FILE: @@ -917,11 +917,11 @@ void flexinit (int argc, char **argv) break; case OPT_ALWAYS_INTERACTIVE: - buf_m4_define (&m4defs_buf, "M4_YY_ALWAYS_INTERACTIVE", 0); + ctrl.always_interactive = true; break; case OPT_NEVER_INTERACTIVE: - buf_m4_define( &m4defs_buf, "M4_YY_NEVER_INTERACTIVE", 0); + ctrl.never_interactive = true; break; case OPT_ARRAY: @@ -974,7 +974,7 @@ void flexinit (int argc, char **argv) break; case OPT_STACK: - buf_m4_define( &m4defs_buf, "M4_YY_STACK_USED",0); + ctrl.stack_used = true; break; case OPT_STDINIT: @@ -1496,7 +1496,10 @@ void readin (void) visible_define ( "M4_MODE_TABLESEXT"); if (ctrl.prefix != NULL) visible_define_str ( "M4_MODE_PREFIX", ctrl.prefix); - + + if (ctrl.no_input) + visible_define("M4_MODE_NO_INPUT"); + if (ctrl.no_yy_push_state) visible_define("M4_YY_NO_PUSH_STATE"); if (ctrl.no_yy_pop_state) @@ -1554,6 +1557,16 @@ void readin (void) if (ctrl.no_set_debug) visible_define("M4_YY_NO_SET_DEBUG"); + if (ctrl.no_unistd) + visible_define("M4_YY_NO_UNISTD_H"); + + if (ctrl.always_interactive) + visible_define("M4_YY_ALWAYS_INTERACTIVE"); + if (ctrl.never_interactive) + visible_define("M4_YY_NEVER_INTERACTIVE"); + if (ctrl.stack_used) + visible_define("M4_YY_STACK_USED"); + backend->comment("m4 controls end\n"); out ("\n"); diff --git a/src/misc.c b/src/misc.c index 931db51d..40c23cac 100644 --- a/src/misc.c +++ b/src/misc.c @@ -88,29 +88,6 @@ static void sko_pop(bool* dc) flex_die("popped too many times in skeleton."); } -/* Append a constant declaration to the running buffer. */ -void action_define (const char *defname, int value) -{ - char buf[MAXLINE]; - char *cpy; - - if ((int) strlen (defname) > MAXLINE / 2) { - format_pinpoint_message (_ - ("name \"%s\" ridiculously long"), - defname); - return; - } - - snprintf (buf, sizeof(buf), backend->int_define_fmt, defname, value); - add_action (buf); - - /* track definitions so we can naybe undef them when we're done; - * this is only ever likely to work with the cpp back end. - */ - cpy = xstrdup(defname); - buf_append (&defs_buf, &cpy, 1); -} - /* Append "new_text" to the running buffer. */ void add_action (const char *new_text) { diff --git a/src/scan.l b/src/scan.l index cb1a477e..099d153a 100644 --- a/src/scan.l +++ b/src/scan.l @@ -50,23 +50,9 @@ extern const char *escaped_qstart, *escaped_qend; #define ESCAPED_QEND M4QEND "]" M4QSTART M4QEND "]" M4QSTART #define ACTION_ECHO add_action( yytext ) -#define ACTION_IFDEF(def, should_define) \ - { \ - if ( should_define ) \ - action_define( def, 1 ); \ - } - #define ACTION_ECHO_QSTART add_action (ESCAPED_QSTART) #define ACTION_ECHO_QEND add_action (ESCAPED_QEND) -#define ACTION_M4_IFDEF(def, should_define) \ - do{ \ - if ( should_define ) \ - buf_m4_define( &m4defs_buf, def, NULL);\ - else \ - buf_m4_undefine( &m4defs_buf, def);\ - } while(0) - #define MARK_END_OF_PROLOG mark_prolog(); #define YY_DECL \ @@ -364,7 +350,7 @@ M4QEND "]""]" align ctrl.long_align = option_sense; always-interactive { - ACTION_M4_IFDEF( "M4""_YY_ALWAYS_INTERACTIVE", option_sense ); + ctrl.always_interactive = option_sense; ctrl.interactive = (trit)option_sense; } array ctrl.yytext_is_array = option_sense; @@ -388,7 +374,7 @@ M4QEND "]""]" ctrl.useecs = ctrl.usemecs = false; ctrl.use_read = ctrl.fulltbl = true; } - input ACTION_IFDEF("YY_NO_INPUT", ! option_sense); + input ctrl.no_input = ! option_sense; interactive ctrl.interactive = (trit)option_sense; lex-compat ctrl.posix_compat = option_sense; posix-compat ctrl.posix_compat = option_sense; @@ -401,7 +387,7 @@ M4QEND "]""]" } meta-ecs ctrl.usemecs = option_sense; never-interactive { - ACTION_M4_IFDEF( "M4""_YY_NEVER_INTERACTIVE", option_sense ); + ctrl.never_interactive = option_sense; ctrl.interactive = (trit)!option_sense; } perf-report env.performance_hint += option_sense ? 1 : -1; @@ -409,14 +395,14 @@ M4QEND "]""]" read ctrl.use_read = option_sense; reentrant ctrl.reentrant = option_sense; reject reject_really_used = option_sense; - stack ACTION_M4_IFDEF( "M4""_YY_STACK_USED", option_sense ); + stack ctrl.stack_used = option_sense; stdinit ctrl.do_stdinit = option_sense; stdout env.use_stdout = option_sense; - unistd ACTION_IFDEF("YY_NO_UNISTD_H", ! option_sense); + unistd ctrl.no_unistd = ! option_sense; unput ctrl.no_unput = ! option_sense; verbose env.printstats = option_sense; warn env.nowarn = ! option_sense; - yylineno ctrl.do_yylineno = option_sense; ACTION_M4_IFDEF("M4""_YY_USE_LINENO", option_sense); + yylineno ctrl.do_yylineno = option_sense; yymore yymore_really_used = option_sense; yywrap ctrl.do_yywrap = option_sense;