diff options
| author | Eric S. Raymond <esr@thyrsus.com> | 2020-09-23 22:06:32 -0400 |
|---|---|---|
| committer | Eric S. Raymond <esr@thyrsus.com> | 2020-09-23 22:21:03 -0400 |
| commit | 5cb26ac3f98c1e72cc3785a929e7b2ce00dd3bbe (patch) | |
| tree | 826cee9cf39810a8e690d0ce711bd39eb0e1f3b1 | |
| parent | c9ade3f92bb952da5fac35f474f445d84dc18bd1 (diff) | |
| download | flex-git-5cb26ac3f98c1e72cc3785a929e7b2ce00dd3bbe.tar.gz | |
Conditionalization of the debug flag moves to m4.
Turned out to be mildly trick because %if/%endif pairs have push/pop
behavior rather than combining.
In generated code, the location of the debug declarations moves,
and that's all.
#34 in the retargeting patch series
| -rw-r--r-- | src/cpp-flex.skl | 8 | ||||
| -rw-r--r-- | src/flexdef.h | 2 | ||||
| -rw-r--r-- | src/gen.c | 17 | ||||
| -rw-r--r-- | src/main.c | 2 |
4 files changed, 21 insertions, 8 deletions
diff --git a/src/cpp-flex.skl b/src/cpp-flex.skl index 707e013..b3838b1 100644 --- a/src/cpp-flex.skl +++ b/src/cpp-flex.skl @@ -724,6 +724,14 @@ m4_ifdef([[M4_MODE_YYTEXT_IS_ARRAY]], [[ \ ]]) \ YY_G(yy_c_buf_p) = yy_cp; +%if-not-reentrant +m4_ifdef( [[M4_MODE_C_ONLY]], +[[ +extern int yy_flex_debug; +int yy_flex_debug = m4_ifdef([[M4_MODE_DEBUG]],[[1]])m4_ifdef([[M4_MODE_NO_DEBUG]],[[1]]); +]]) +%endif + %% [2.0] code to fiddle yytext and yyleng for yymore() goes here \ %% [3.0] code to copy yytext_ptr to yytext[] goes here, if %array \ %% [4.0] data tables for the DFA and the user's section 1 definitions go here diff --git a/src/flexdef.h b/src/flexdef.h index f8575a6..15250b6 100644 --- a/src/flexdef.h +++ b/src/flexdef.h @@ -350,6 +350,8 @@ struct flex_backend_t { extern bool gentables; +extern struct flex_backend_t cpp_backend; + /* Declarations for global variables. */ @@ -992,11 +992,22 @@ void make_tables (void) if (ddebug) out_m4_define( "M4_MODE_DEBUG", NULL); + else + out_m4_define( "M4_MODE_NO_DEBUG", NULL); + + // Kluge to get around the fact that the %if-not-reentrant and + // %if-c-only gates can;t be combined by nesting one inside the + // other. + if (backend == &cpp_backend && !C_plus_plus) + out_m4_define( "M4_MODE_C_ONLY", NULL); // FIXME: This probaby should be done in pure m4 out_m4_define("M4_YYL_BASE", yymore_used ? (yytext_is_array ? "YY_G(yy_prev_more_offset)" : "YY_G(yy_more_len)") : "0"); + // There are a couple more modes we can't compute until after + // tables have been generated. + out_dec ("#define YY_NUM_RULES %d\n", num_rules); out_dec ("#define YY_END_OF_BUFFER %d\n", num_rules + 1); @@ -1173,12 +1184,6 @@ void make_tables (void) } } - if (!C_plus_plus && !reentrant) { - indent_puts ("extern int yy_flex_debug;"); - indent_put2s ("int yy_flex_debug = %s;\n", - ddebug ? "1" : "0"); - } - if (reject) { outn ("m4_ifdef( [[M4_MODE_USES_REJECT]],\n[["); /* Declare state buffer variables. */ @@ -46,8 +46,6 @@ void flexinit(int, char **); void readin(void); void set_up_initial_allocations(void); -extern struct flex_backend_t cpp_backend; - /* these globals are all defined and commented in flexdef.h */ int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, spprdflt; int interactive, lex_compat, posix_compat, do_yylineno, |
