mirror of
https://github.com/westes/flex.git
synced 2026-01-26 15:39:06 +00:00
As of this commit, all mode symbolds are finally visible.
All symbols except a handful dependent on nultrans and the number of backups are now written in one visible group right at the start of m4 generation. The exception are exceptions because their values are not known until after DFA computation. Has comment diffs in generated test code due to one symbol rename and symbols beoming visible. Should be the last time the latter happens. #57 in the retargeting patch series
This commit is contained in:
parent
0fc45ce97c
commit
ea32296019
@ -49,7 +49,6 @@
|
||||
struct Buf userdef_buf; /**< for user #definitions triggered by cmd-line. */
|
||||
struct Buf defs_buf; /**< for #define's autogenerated. List of strings. */
|
||||
struct Buf yydmap_buf; /**< string buffer to hold yydmap elements */
|
||||
struct Buf m4defs_buf; /**< m4 definitions. List of strings. */
|
||||
struct Buf top_buf; /**< contains %top code. String buffer. */
|
||||
|
||||
struct Buf *buf_print_strings(struct Buf * buf, FILE* out)
|
||||
|
||||
@ -65,31 +65,31 @@ m4_changequote([[, ]])
|
||||
%not-for-header
|
||||
%if-c-only
|
||||
%if-not-reentrant
|
||||
m4_ifelse(M4_YY_PREFIX,yy,,
|
||||
#define yy_create_buffer M4_YY_PREFIX[[_create_buffer]]
|
||||
#define yy_delete_buffer M4_YY_PREFIX[[_delete_buffer]]
|
||||
#define yy_scan_buffer M4_YY_PREFIX[[_scan_buffer]]
|
||||
#define yy_scan_string M4_YY_PREFIX[[_scan_string]]
|
||||
#define yy_scan_bytes M4_YY_PREFIX[[_scan_bytes]]
|
||||
#define yy_init_buffer M4_YY_PREFIX[[_init_buffer]]
|
||||
#define yy_flush_buffer M4_YY_PREFIX[[_flush_buffer]]
|
||||
#define yy_load_buffer_state M4_YY_PREFIX[[_load_buffer_state]]
|
||||
#define yy_switch_to_buffer M4_YY_PREFIX[[_switch_to_buffer]]
|
||||
#define yypush_buffer_state M4_YY_PREFIX[[push_buffer_state]]
|
||||
#define yypop_buffer_state M4_YY_PREFIX[[pop_buffer_state]]
|
||||
#define yyensure_buffer_stack M4_YY_PREFIX[[ensure_buffer_stack]]
|
||||
#define yy_flex_debug M4_YY_PREFIX[[_flex_debug]]
|
||||
#define yyin M4_YY_PREFIX[[in]]
|
||||
#define yyleng M4_YY_PREFIX[[leng]]
|
||||
#define yylex M4_YY_PREFIX[[lex]]
|
||||
#define yylineno M4_YY_PREFIX[[lineno]]
|
||||
#define yyout M4_YY_PREFIX[[out]]
|
||||
#define yyrestart M4_YY_PREFIX[[restart]]
|
||||
#define yytext M4_YY_PREFIX[[text]]
|
||||
#define yywrap M4_YY_PREFIX[[wrap]]
|
||||
#define yyalloc M4_YY_PREFIX[[alloc]]
|
||||
#define yyrealloc M4_YY_PREFIX[[realloc]]
|
||||
#define yyfree M4_YY_PREFIX[[free]]
|
||||
m4_ifelse(M4_MODE_PREFIX,yy,,
|
||||
#define yy_create_buffer M4_MODE_PREFIX[[_create_buffer]]
|
||||
#define yy_delete_buffer M4_MODE_PREFIX[[_delete_buffer]]
|
||||
#define yy_scan_buffer M4_MODE_PREFIX[[_scan_buffer]]
|
||||
#define yy_scan_string M4_MODE_PREFIX[[_scan_string]]
|
||||
#define yy_scan_bytes M4_MODE_PREFIX[[_scan_bytes]]
|
||||
#define yy_init_buffer M4_MODE_PREFIX[[_init_buffer]]
|
||||
#define yy_flush_buffer M4_MODE_PREFIX[[_flush_buffer]]
|
||||
#define yy_load_buffer_state M4_MODE_PREFIX[[_load_buffer_state]]
|
||||
#define yy_switch_to_buffer M4_MODE_PREFIX[[_switch_to_buffer]]
|
||||
#define yypush_buffer_state M4_MODE_PREFIX[[push_buffer_state]]
|
||||
#define yypop_buffer_state M4_MODE_PREFIX[[pop_buffer_state]]
|
||||
#define yyensure_buffer_stack M4_MODE_PREFIX[[ensure_buffer_stack]]
|
||||
#define yy_flex_debug M4_MODE_PREFIX[[_flex_debug]]
|
||||
#define yyin M4_MODE_PREFIX[[in]]
|
||||
#define yyleng M4_MODE_PREFIX[[leng]]
|
||||
#define yylex M4_MODE_PREFIX[[lex]]
|
||||
#define yylineno M4_MODE_PREFIX[[lineno]]
|
||||
#define yyout M4_MODE_PREFIX[[out]]
|
||||
#define yyrestart M4_MODE_PREFIX[[restart]]
|
||||
#define yytext M4_MODE_PREFIX[[text]]
|
||||
#define yywrap M4_MODE_PREFIX[[wrap]]
|
||||
#define yyalloc M4_MODE_PREFIX[[alloc]]
|
||||
#define yyrealloc M4_MODE_PREFIX[[realloc]]
|
||||
#define yyfree M4_MODE_PREFIX[[free]]
|
||||
)
|
||||
%endif
|
||||
%endif
|
||||
@ -116,16 +116,16 @@ m4_ifdef( [[M4_YY_REENTRANT]], [[m4_define([[M4_YY_HAS_START_STACK_VARS]])]])
|
||||
%# the argument lists to each C function.
|
||||
|
||||
|
||||
m4_ifdef( [[M4_YY_PREFIX]],, [[m4_define([[M4_YY_PREFIX]], [[yy]])]])
|
||||
m4_ifdef( [[M4_MODE_PREFIX]],, [[m4_define([[M4_MODE_PREFIX]], [[yy]])]])
|
||||
|
||||
m4preproc_define(`M4_GEN_PREFIX',``
|
||||
[[#ifdef yy$1
|
||||
#define ]]M4_YY_PREFIX[[$1_ALREADY_DEFINED
|
||||
#define ]]M4_MODE_PREFIX[[$1_ALREADY_DEFINED
|
||||
#else
|
||||
#define yy$1 ]]M4_YY_PREFIX[[$1
|
||||
#define yy$1 ]]M4_MODE_PREFIX[[$1
|
||||
#endif]]
|
||||
'm4preproc_divert(1)`
|
||||
[[#ifndef ]]M4_YY_PREFIX[[$1_ALREADY_DEFINED
|
||||
[[#ifndef ]]M4_MODE_PREFIX[[$1_ALREADY_DEFINED
|
||||
#undef yy$1
|
||||
#endif]]'m4preproc_divert(0)')
|
||||
|
||||
@ -136,11 +136,11 @@ m4preproc_define(`M4_GEN_PREFIX',``
|
||||
* We will address this in a future release of flex, or omit the C++ scanner
|
||||
* altogether.
|
||||
*/
|
||||
#define yyFlexLexer M4_YY_PREFIX[[FlexLexer]]
|
||||
#define yyFlexLexer M4_MODE_PREFIX[[FlexLexer]]
|
||||
%endif
|
||||
|
||||
%if-c-only
|
||||
m4_ifelse(M4_YY_PREFIX,yy,,
|
||||
m4_ifelse(M4_MODE_PREFIX,yy,,
|
||||
M4_GEN_PREFIX(`_create_buffer')
|
||||
M4_GEN_PREFIX(`_delete_buffer')
|
||||
M4_GEN_PREFIX(`_scan_buffer')
|
||||
@ -192,14 +192,14 @@ m4_ifdef( [[<M4_YY_BISON_LLOC>]],
|
||||
]])
|
||||
|
||||
|
||||
m4_ifelse(M4_YY_PREFIX,yy,,
|
||||
m4_ifelse(M4_MODE_PREFIX,yy,,
|
||||
M4_GEN_PREFIX(`alloc')
|
||||
M4_GEN_PREFIX(`realloc')
|
||||
M4_GEN_PREFIX(`free')
|
||||
)
|
||||
|
||||
%if-c-only
|
||||
m4_ifelse(M4_YY_PREFIX,yy,,
|
||||
m4_ifelse(M4_MODE_PREFIX,yy,,
|
||||
m4_ifdef( [[M4_YY_NOT_REENTRANT]],
|
||||
[[
|
||||
M4_GEN_PREFIX(`text')
|
||||
@ -213,7 +213,7 @@ m4_ifdef( [[M4_YY_NOT_REENTRANT]],
|
||||
%endif
|
||||
|
||||
|
||||
m4_ifdef( [[M4_YY_TABLES_EXTERNAL]],
|
||||
m4_ifdef( [[M4_MODE_TABLESEXT]],
|
||||
[[
|
||||
M4_GEN_PREFIX(`tables_fload')
|
||||
M4_GEN_PREFIX(`tables_destroy')
|
||||
@ -657,10 +657,10 @@ m4_ifdef( [[M4_YY_NOT_IN_HEADER]],
|
||||
m4_ifdef( [[M4_MODE_NO_YYWRAP]], [[
|
||||
%if-c-only
|
||||
m4_ifdef([[M4_YY_REENTRANT]], [[
|
||||
#define M4_YY_PREFIX[[wrap]](yyscanner) (/*CONSTCOND*/1)
|
||||
#define M4_MODE_PREFIX[[wrap]](yyscanner) (/*CONSTCOND*/1)
|
||||
]])
|
||||
m4_ifdef([[M4_YY_NOT_REENTRANT]], [[
|
||||
#define M4_YY_PREFIX[[wrap]]() (/*CONSTCOND*/1)
|
||||
#define M4_MODE_PREFIX[[wrap]]() (/*CONSTCOND*/1)
|
||||
]])m4_dnl
|
||||
%endif
|
||||
#define YY_SKIP_YYWRAP
|
||||
@ -1030,7 +1030,7 @@ m4_ifdef( [[M4_MODE_USES_REJECT]], [[
|
||||
int yy_full_lp;
|
||||
int *yy_full_state;
|
||||
]])
|
||||
m4_ifdef( [[M4_YY_TEXT_IS_ARRAY]], [[
|
||||
m4_ifdef( [[M4_MODE_REENTRANT_TEXT_IS_ARRAY]], [[
|
||||
char yytext_r[YYLMAX];
|
||||
char *yytext_ptr;
|
||||
int yy_more_offset;
|
||||
@ -3498,7 +3498,7 @@ m4_ifdef( [[M4_MODE_USES_REJECT]],
|
||||
YY_G(yy_lp) = 0;
|
||||
]])
|
||||
|
||||
m4_ifdef( [[M4_YY_TEXT_IS_ARRAY]],
|
||||
m4_ifdef( [[M4_MODE_REENTRANT_TEXT_IS_ARRAY]],
|
||||
[[
|
||||
YY_G(yytext_ptr) = 0;
|
||||
YY_G(yy_more_offset) = 0;
|
||||
|
||||
@ -1124,9 +1124,7 @@ extern struct Buf *buf_print_strings(struct Buf * buf, FILE* out);
|
||||
extern struct Buf *buf_linedir(struct Buf *buf, const char* filename, int lineno);
|
||||
|
||||
extern struct Buf userdef_buf; /* a string buffer for #define's generated by user-options on cmd line. */
|
||||
extern struct Buf defs_buf; /* a char* buffer to save #define'd some symbols generated by flex. */
|
||||
extern struct Buf yydmap_buf; /* a string buffer to hold yydmap elements */
|
||||
extern struct Buf m4defs_buf; /* Holds m4 definitions. */
|
||||
extern struct Buf top_buf; /* contains %top code. String buffer. */
|
||||
extern bool no_section3_escape; /* True if the undocumented option --unsafe-no-m4-sect3-escape was passed */
|
||||
|
||||
|
||||
75
src/main.c
75
src/main.c
@ -661,17 +661,9 @@ void flexinit (int argc, char **argv)
|
||||
|
||||
/* Initialize any buffers. */
|
||||
buf_init (&userdef_buf, sizeof (char)); /* one long string */
|
||||
buf_init (&defs_buf, sizeof (char *)); /* list of strings */
|
||||
buf_init (&yydmap_buf, sizeof (char)); /* one long string */
|
||||
buf_init (&top_buf, sizeof (char)); /* one long string */
|
||||
|
||||
{
|
||||
const char * m4defs_init_str[] = {"m4_changequote\n",
|
||||
"m4_changequote([[, ]])\n"};
|
||||
buf_init (&m4defs_buf, sizeof (char *));
|
||||
buf_append (&m4defs_buf, &m4defs_init_str, 2);
|
||||
}
|
||||
|
||||
sf_init ();
|
||||
|
||||
/* initialize regex lib */
|
||||
@ -1160,8 +1152,6 @@ void readin (void)
|
||||
char *pname = 0;
|
||||
size_t nbytes = 0;
|
||||
|
||||
buf_m4_define (&m4defs_buf, "M4_YY_TABLES_EXTERNAL", NULL);
|
||||
|
||||
if (!tablesfilename) {
|
||||
nbytes = strlen (ctrl.prefix) + strlen (tablesfile_template) + 2;
|
||||
tablesfilename = pname = calloc(nbytes, 1);
|
||||
@ -1187,40 +1177,12 @@ void readin (void)
|
||||
if (env.skelname && (skelfile = fopen (env.skelname, "r")) == NULL)
|
||||
lerr (_("can't open skeleton file %s"), env.skelname);
|
||||
|
||||
if ( ctrl.bison_bridge_lval)
|
||||
buf_m4_define (&m4defs_buf, "M4_YY_BISON_LVAL", NULL);
|
||||
|
||||
if ( ctrl.bison_bridge_lloc)
|
||||
buf_m4_define (&m4defs_buf, "<M4_YY_BISON_LLOC>", NULL);
|
||||
|
||||
if (strchr(ctrl.prefix, '[') || strchr(ctrl.prefix, ']'))
|
||||
flexerror(_("Prefix cannot include '[' or ']'"));
|
||||
buf_m4_define(&m4defs_buf, "M4_YY_PREFIX", ctrl.prefix);
|
||||
|
||||
if (env.did_outfilename)
|
||||
line_directive_out (stdout, 0);
|
||||
|
||||
/* Define the start condition macros. */
|
||||
{
|
||||
struct Buf tmpbuf;
|
||||
int i;
|
||||
buf_init(&tmpbuf, sizeof(char));
|
||||
for (i = 1; i <= lastsc; i++) {
|
||||
char *str, *fmt = backend->int_define_fmt;
|
||||
size_t strsz;
|
||||
|
||||
strsz = strlen(fmt) + strlen(scname[i]) + (size_t)(1 + ceil (log10(i))) + 2;
|
||||
str = malloc(strsz);
|
||||
if (!str)
|
||||
flexfatal(_("allocation of macro definition failed"));
|
||||
snprintf(str, strsz, fmt, scname[i], i - 1);
|
||||
buf_strappend(&tmpbuf, str);
|
||||
free(str);
|
||||
}
|
||||
buf_m4_define(&m4defs_buf, "M4_YY_SC_DEFS", tmpbuf.elts);
|
||||
buf_destroy(&tmpbuf);
|
||||
}
|
||||
|
||||
/* This is where we begin writing to the file. */
|
||||
|
||||
backend->comment("A lexical scanner generated by flex\n");
|
||||
@ -1229,10 +1191,6 @@ void readin (void)
|
||||
if( top_buf.elts)
|
||||
outn((char*) top_buf.elts);
|
||||
|
||||
/* Dump the m4 definitions. */
|
||||
buf_print_strings(&m4defs_buf, stdout);
|
||||
m4defs_buf.nelts = 0; /* memory leak here. */
|
||||
|
||||
/* Place a bogus line directive, it will be fixed in the filter. */
|
||||
if (ctrl.gen_line_dirs && backend->trace_fmt) {
|
||||
char buf2[4096];
|
||||
@ -1355,6 +1313,9 @@ void readin (void)
|
||||
if (ctrl.useecs)
|
||||
ccl2ecl ();
|
||||
|
||||
out ("m4_changequote\n");
|
||||
out ("m4_changequote([[, ]])\n");
|
||||
|
||||
// These are used to conditionalize code in the lex skeleton
|
||||
// that historically used to be generated by C code in flex
|
||||
// itself; by shoving all this stuff out to the skeleton file
|
||||
@ -1362,6 +1323,34 @@ void readin (void)
|
||||
|
||||
backend->comment("m4 controls begin\n");
|
||||
|
||||
/* Define the start condition macros. */
|
||||
{
|
||||
struct Buf tmpbuf;
|
||||
int i;
|
||||
buf_init(&tmpbuf, sizeof(char));
|
||||
for (i = 1; i <= lastsc; i++) {
|
||||
char *str, *fmt = backend->int_define_fmt;
|
||||
size_t strsz;
|
||||
|
||||
strsz = strlen(fmt) + strlen(scname[i]) + (size_t)(1 + ceil (log10(i))) + 2;
|
||||
str = malloc(strsz);
|
||||
if (!str)
|
||||
flexfatal(_("allocation of macro definition failed"));
|
||||
snprintf(str, strsz, fmt, scname[i], i - 1);
|
||||
buf_strappend(&tmpbuf, str);
|
||||
free(str);
|
||||
}
|
||||
// FIXME: Not dumped visibly because we plan to do away with the indirection
|
||||
out_m4_define("M4_YY_SC_DEFS", tmpbuf.elts);
|
||||
buf_destroy(&tmpbuf);
|
||||
}
|
||||
|
||||
if (ctrl.bison_bridge_lval)
|
||||
visible_define("M4_YY_BISON_LVAL");
|
||||
|
||||
if (ctrl.bison_bridge_lloc)
|
||||
visible_define("<M4_YY_BISON_LLOC>");
|
||||
|
||||
if (extra_type != NULL)
|
||||
visible_define_str ("M4_EXTRA_TYPE_DEFS", extra_type);
|
||||
|
||||
@ -1371,7 +1360,7 @@ void readin (void)
|
||||
if (ctrl.reentrant) {
|
||||
visible_define ("M4_YY_REENTRANT");
|
||||
if (ctrl.yytext_is_array)
|
||||
visible_define ("M4_YY_TEXT_IS_ARRAY");
|
||||
visible_define ("M4_MODE_REENTRANT_TEXT_IS_ARRAY");
|
||||
} else
|
||||
visible_define ("M4_YY_NOT_REENTRANT");
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user