Skip to content

Commit

Permalink
Move almost all m4 symbol setting to one spot.
Browse files Browse the repository at this point in the history
Formerly, Flex's own lexer and the logic for pocessing command-line
options both did calls to write M4 conditionals to a buffer that was
later dumped into the befinning of the text that m4 expands, before
the body of the skel file.

This was bad layering.  Instead, both these places now set flags in
the ctrl structure.  Later, (almost) all the generated m4 conditionals
are shipped at once.

It's "almost" because there are a couple of awkward cases to be
cleaned up.  Again, this was the part that could be done
simply via almost mechanical cut and paste.

In generated code, there are some comment diffs because symbols that
used to be invisibly set are now visibly set - that is, shown at the
beginning of the generated C.

westes#55 in the retargeting patch series
  • Loading branch information
eric-s-raymond committed Oct 2, 2020
1 parent c5d0e40 commit 7e77d8f
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 55 deletions.
29 changes: 29 additions & 0 deletions src/flexdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,35 @@ struct ctrl_bundle_t {
bool yytext_is_array; // if true (i.e., %array directive), then declare
// yytext as array instead of a character pointer.
// Nice and inefficient.
// flags corresponding to the huge mass of --no-yy options
bool no_yy_push_state;
bool no_yy_pop_state;
bool no_yy_top_state;
bool no_unput;
bool no_yy_scan_buffer;
bool no_yy_scan_bytes;
bool no_yy_scan_string;
bool no_yyget_extra;
bool no_yyset_extra;
bool no_yyget_leng;
bool no_yyget_text;
bool no_yyget_lineno;
bool no_yyset_lineno;
bool no_yyget_column;
bool no_yyset_column;
bool no_yyget_in;
bool no_yyset_in;
bool no_yyget_out;
bool no_yyset_out;
bool no_yyget_lval;
bool no_yyset_lval;
bool no_yyget_lloc;
bool no_yyset_lloc;
bool no_flex_alloc;
bool no_flex_realloc;
bool no_flex_free;
bool no_get_debug;
bool no_set_debug;
};

/* Environment variables. These control the lexer operation, but do
Expand Down
104 changes: 81 additions & 23 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1022,74 +1022,75 @@ void flexinit (int argc, char **argv)
break;

case OPT_NO_YY_PUSH_STATE:
buf_m4_define( &m4defs_buf, "M4_YY_NO_PUSH_STATE",0);
ctrl.no_yy_push_state = true;
break;
case OPT_NO_YY_POP_STATE:
buf_m4_define( &m4defs_buf, "M4_YY_NO_POP_STATE",0);
ctrl.no_yy_pop_state = true;
break;
case OPT_NO_YY_TOP_STATE:
buf_m4_define( &m4defs_buf, "M4_YY_NO_TOP_STATE",0);
ctrl.no_yy_top_state = true;
break;
case OPT_NO_UNPUT:
buf_m4_define( &m4defs_buf, "M4_YY_NO_UNPUT",0);
ctrl.no_unput = true;
break;
case OPT_NO_YY_SCAN_BUFFER:
buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_BUFFER",0);
ctrl.no_yy_scan_buffer = true;
break;
case OPT_NO_YY_SCAN_BYTES:
buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_BYTES",0);
ctrl.no_yy_scan_bytes = true;
break;
case OPT_NO_YY_SCAN_STRING:
buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_STRING",0);
ctrl.no_yy_scan_string = true;
break;
case OPT_NO_YYGET_EXTRA:
buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_EXTRA",0);
ctrl.no_yyget_extra = true;
break;
case OPT_NO_YYSET_EXTRA:
buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_EXTRA",0);
ctrl.no_yyset_extra = true;
break;
case OPT_NO_YYGET_LENG:
buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LENG",0);
ctrl.no_yyget_leng = true;
break;
case OPT_NO_YYGET_TEXT:
buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_TEXT",0);
ctrl.no_yyget_text = true;
break;
case OPT_NO_YYGET_LINENO:
buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LINENO",0);
ctrl.no_yyget_lineno = true;
break;
case OPT_NO_YYSET_LINENO:
buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LINENO",0);
ctrl.no_yyset_lineno = true;
break;
case OPT_NO_YYGET_COLUMN:
buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_COLUMN",0);
ctrl.no_yyget_column = true;
break;
case OPT_NO_YYSET_COLUMN:
buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_COLUMN",0);
ctrl.no_yyset_column = true;
break;
case OPT_NO_YYGET_IN:
buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_IN",0);
ctrl.no_yyget_in = true;
break;
case OPT_NO_YYSET_IN:
buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_IN",0);
ctrl.no_yyset_in = true;
break;
case OPT_NO_YYGET_OUT:
buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_OUT",0);
ctrl.no_yyget_out = true;
break;
case OPT_NO_YYSET_OUT:
buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_OUT",0);
ctrl.no_yyset_out = true;
break;
case OPT_NO_YYGET_LVAL:
buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LVAL",0);
ctrl.no_yyget_lval = true;
break;
case OPT_NO_YYSET_LVAL:
buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LVAL",0);
ctrl.no_yyset_lval = true;
break;
case OPT_NO_YYGET_LLOC:
buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LLOC",0);
ctrl.no_yyget_lloc = true;
break;
case OPT_NO_YYSET_LLOC:
buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LLOC",0);
ctrl.no_yyset_lloc = true;
break;

case OPT_HEX:
env.trace_hex = true;
break;
Expand Down Expand Up @@ -1496,6 +1497,63 @@ void readin (void)
if (ctrl.prefix != NULL)
visible_define_str ( "M4_MODE_PREFIX", ctrl.prefix);

if (ctrl.no_yy_push_state)
visible_define("M4_YY_NO_PUSH_STATE");
if (ctrl.no_yy_pop_state)
visible_define("M4_YY_NO_POP_STATE");
if (ctrl.no_yy_top_state)
visible_define("M4_YY_NO_TOP_STATE");
if (ctrl.no_unput)
visible_define("M4_YY_NO_UNPUT");
if (ctrl.no_yy_scan_buffer)
visible_define("M4_YY_NO_SCAN_BUFFER");
if (ctrl.no_yy_scan_bytes)
visible_define("M4_YY_NO_SCAN_BYTES");
if (ctrl.no_yy_scan_string)
visible_define("M4_YY_NO_SCAN_STRING");
if (ctrl.no_yyget_extra)
visible_define("M4_YY_NO_GET_EXTRA");
if (ctrl.no_yyset_extra)
visible_define("M4_YY_NO_SET_EXTRA");
if (ctrl.no_yyget_leng)
visible_define("M4_YY_NO_GET_LENG");
if (ctrl.no_yyget_text)
visible_define("M4_YY_NO_GET_TEXT");
if (ctrl.no_yyget_lineno)
visible_define("M4_YY_NO_GET_LINENO");
if (ctrl.no_yyset_lineno)
visible_define("M4_YY_NO_SET_LINENO");
if (ctrl.no_yyget_column)
visible_define("M4_YY_NO_GET_COLUMN");
if (ctrl.no_yyset_column)
visible_define("M4_YY_NO_SET_COLUMN");
if (ctrl.no_yyget_in)
visible_define("M4_YY_NO_GET_IN");
if (ctrl.no_yyset_in)
visible_define("M4_YY_NO_SET_IN");
if (ctrl.no_yyget_out)
visible_define("M4_YY_NO_GET_OUT");
if (ctrl.no_yyset_out)
visible_define("M4_YY_NO_SET_OUT");
if (ctrl.no_yyget_lval)
visible_define("M4_YY_NO_GET_LVAL");
if (ctrl.no_yyset_lval)
visible_define("M4_YY_NO_SET_LVAL");
if (ctrl.no_yyget_lloc)
visible_define("M4_YY_NO_GET_LLOC");
if (ctrl.no_yyset_lloc)
visible_define("M4_YY_NO_SET_LLOC");
if (ctrl.no_flex_alloc)
visible_define("M4_YY_NO_FLEX_ALLOC");
if (ctrl.no_flex_realloc)
visible_define("M4_YY_NO_FLEX_REALLOC");
if (ctrl.no_flex_free)
visible_define("M4_YY_NO_FLEX_FREE");
if (ctrl.no_get_debug)
visible_define("M4_YY_NO_GET_DEBUG");
if (ctrl.no_set_debug)
visible_define("M4_YY_NO_SET_DEBUG");

backend->comment("m4 controls end\n");
out ("\n");

Expand Down
64 changes: 32 additions & 32 deletions src/scan.l
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ M4QEND "]""]"
posix-compat ctrl.posix_compat = option_sense;
line ctrl.gen_line_dirs = option_sense;
main {
ACTION_M4_IFDEF( "M4""_YY_MAIN", option_sense);
ctrl.do_main = option_sense;
/* Override yywrap */
if( option_sense == true )
ctrl.do_yywrap = false;
Expand All @@ -413,43 +413,43 @@ M4QEND "]""]"
stdinit ctrl.do_stdinit = option_sense;
stdout env.use_stdout = option_sense;
unistd ACTION_IFDEF("YY_NO_UNISTD_H", ! option_sense);
unput ACTION_M4_IFDEF("M4""_YY_NO_UNPUT", ! 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);
yymore yymore_really_used = option_sense;
yywrap ctrl.do_yywrap = option_sense;

yy_push_state ACTION_M4_IFDEF("M4""_YY_NO_PUSH_STATE", ! option_sense);
yy_pop_state ACTION_M4_IFDEF("M4""_YY_NO_POP_STATE", ! option_sense);
yy_top_state ACTION_M4_IFDEF("M4""_YY_NO_TOP_STATE", ! option_sense);

yy_scan_buffer ACTION_M4_IFDEF("M4""_YY_NO_SCAN_BUFFER", ! option_sense);
yy_scan_bytes ACTION_M4_IFDEF("M4""_YY_NO_SCAN_BYTES", ! option_sense);
yy_scan_string ACTION_M4_IFDEF("M4""_YY_NO_SCAN_STRING", ! option_sense);

yyalloc ACTION_M4_IFDEF("M4""_YY_NO_FLEX_ALLOC", ! option_sense);
yyrealloc ACTION_M4_IFDEF("M4""_YY_NO_FLEX_REALLOC", ! option_sense);
yyfree ACTION_M4_IFDEF("M4""_YY_NO_FLEX_FREE", ! option_sense);

yyget_debug ACTION_M4_IFDEF("M4""_YY_NO_GET_DEBUG", ! option_sense);
yyset_debug ACTION_M4_IFDEF("M4""_YY_NO_SET_DEBUG", ! option_sense);
yyget_extra ACTION_M4_IFDEF("M4""_YY_NO_GET_EXTRA", ! option_sense);
yyset_extra ACTION_M4_IFDEF("M4""_YY_NO_SET_EXTRA", ! option_sense);
yyget_leng ACTION_M4_IFDEF("M4""_YY_NO_GET_LENG", ! option_sense);
yyget_text ACTION_M4_IFDEF("M4""_YY_NO_GET_TEXT", ! option_sense);
yyget_column ACTION_M4_IFDEF("M4""_YY_NO_GET_COLUMN", ! option_sense);
yyset_column ACTION_M4_IFDEF("M4""_YY_NO_SET_COLUMN", ! option_sense);
yyget_lineno ACTION_M4_IFDEF("M4""_YY_NO_GET_LINENO", ! option_sense);
yyset_lineno ACTION_M4_IFDEF("M4""_YY_NO_SET_LINENO", ! option_sense);
yyget_in ACTION_M4_IFDEF("M4""_YY_NO_GET_IN", ! option_sense);
yyset_in ACTION_M4_IFDEF("M4""_YY_NO_SET_IN", ! option_sense);
yyget_out ACTION_M4_IFDEF("M4""_YY_NO_GET_OUT", ! option_sense);
yyset_out ACTION_M4_IFDEF("M4""_YY_NO_SET_OUT", ! option_sense);
yyget_lval ACTION_M4_IFDEF("M4""_YY_NO_GET_LVAL", ! option_sense);
yyset_lval ACTION_M4_IFDEF("M4""_YY_NO_SET_LVAL", ! option_sense);
yyget_lloc ACTION_M4_IFDEF("M4""_YY_NO_GET_LLOC", ! option_sense);
yyset_lloc ACTION_M4_IFDEF("M4""_YY_NO_SET_LLOC", ! option_sense);
yy_push_state ctrl.no_yy_push_state = ! option_sense;
yy_pop_state ctrl.no_yy_pop_state = ! option_sense;
yy_top_state ctrl.no_yy_top_state = ! option_sense;

yy_scan_buffer ctrl.no_yy_scan_buffer = ! option_sense;
yy_scan_bytes ctrl.no_yy_scan_bytes = ! option_sense;
yy_scan_string ctrl.no_yy_scan_string = ! option_sense;

yyalloc ctrl.no_flex_alloc = ! option_sense;
yyrealloc ctrl.no_flex_realloc = ! option_sense;
yyfree ctrl.no_flex_free = ! option_sense;

yyget_debug ctrl.no_get_debug = ! option_sense;
yyset_debug ctrl.no_set_debug = ! option_sense;
yyget_extra ctrl.no_yyget_extra = ! option_sense;
yyset_extra ctrl.no_yyset_extra = ! option_sense;
yyget_leng ctrl.no_yyget_leng = ! option_sense;
yyget_text ctrl.no_yyget_text = ! option_sense;
yyget_column ctrl.no_yyget_column = ! option_sense;
yyset_column ctrl.no_yyset_column = ! option_sense;
yyget_lineno ctrl.no_yyget_lineno = ! option_sense;
yyset_lineno ctrl.no_yyset_lineno = ! option_sense;
yyget_in ctrl.no_yyget_in = ! option_sense;
yyset_in ctrl.no_yyset_in = ! option_sense;
yyget_out ctrl.no_yyget_out = ! option_sense;
yyset_out ctrl.no_yyset_out = ! option_sense;
yyget_lval ctrl.no_yyget_lval = ! option_sense;
yyset_lval ctrl.no_yyset_lval = ! option_sense;
yyget_lloc ctrl.no_yyget_lloc = ! option_sense;
yyset_lloc ctrl.no_yyset_lloc = ! option_sense;

extra-type return TOK_EXTRA_TYPE;
outfile return TOK_OUTFILE;
Expand Down

0 comments on commit 7e77d8f

Please sign in to comment.