mirror of
https://github.com/westes/flex.git
synced 2026-01-26 15:39:06 +00:00
Eliminate all uses of buf_strdefine().
There were only two left, for YY_MAIN, and that definition was moved so it's in the visible controls. This is a step towards making *all* conditionalization symbols viible in generated comments. This commit also cleans up some misnamed mode symbols. There are still a couple of duplicative pairs, to be cleaned up in a later commit. We can now report generated M4 symbols with values in the "m4 controls" part of a generated file. Partly as a result, the following symbols become visible in generare code from the tests: M4_MODE_PREFIX, M4_YY_TABLES_VERIFY, M4_YY_REENTRANT, and M4_MODE_PREFIX. No other diffs. #51 in the retargeting patch series. #50 was accidentally unnumbered.
This commit is contained in:
parent
7877454e42
commit
5c6661bb2e
12
src/buf.c
12
src/buf.c
@ -146,18 +146,6 @@ struct Buf *buf_strappend (struct Buf *buf, const char *str)
|
||||
return buf_strnappend (buf, str, (int) strlen (str));
|
||||
}
|
||||
|
||||
/* appends "#define str def\n" */
|
||||
struct Buf *buf_strdefine (struct Buf *buf, const char *str, const char *def)
|
||||
{
|
||||
buf_strappend (buf, "#define ");
|
||||
buf_strappend (buf, " ");
|
||||
buf_strappend (buf, str);
|
||||
buf_strappend (buf, " ");
|
||||
buf_strappend (buf, def);
|
||||
buf_strappend (buf, "\n");
|
||||
return buf;
|
||||
}
|
||||
|
||||
/** Pushes "m4_define( [[def]], [[val]])m4_dnl" to end of buffer.
|
||||
* @param buf A buffer as a list of strings.
|
||||
* @param def The m4 symbol to define.
|
||||
|
||||
@ -1683,7 +1683,7 @@ M4_GEN_START_STATE
|
||||
/* Generate the code to find the next match. */
|
||||
%# Conditional indirection through an equivalence map
|
||||
m4_ifdef([[M4_MODE_USEECS]], m4_define([[M4_EC]], [[*(yy_ec+$1)]]))
|
||||
m4_ifdef([[M4_NOT_MODE_USEECS]], [[m4_define([[M4_EC]], [[$1]])]])
|
||||
m4_ifdef([[M4_MODE_NO_USEECS]], [[m4_define([[M4_EC]], [[$1]])]])
|
||||
|
||||
m4_ifdef([[M4_MODE_FIND_ACTION_FULLTBL]], [[m4_dnl
|
||||
m4_ifdef([[M4_MODE_GENTABLES]], [[m4_dnl
|
||||
|
||||
@ -384,6 +384,8 @@ extern struct flex_backend_t cpp_backend;
|
||||
* yytext as a array instead of a character pointer. Nice and inefficient.
|
||||
* do_yywrap - do yywrap() processing on EOF. If false, EOF treated as
|
||||
* "no more files".
|
||||
* do_main - generate a trivial main part to make the lexer standalone.
|
||||
* Note that 0 is unset, 1 corresponds to --no-main, and 2 to --main.
|
||||
* csize - size of character set for the scanner we're generating;
|
||||
* 128 for 7-bit chars and 256 for 8-bit
|
||||
* yymore_used - if true, yymore() is used in input rules
|
||||
@ -406,7 +408,7 @@ extern int useecs, fulltbl, usemecs, fullspd;
|
||||
extern int gen_line_dirs, performance_report, backing_up_report;
|
||||
extern int reentrant, bison_bridge_lval, bison_bridge_lloc;
|
||||
extern int C_plus_plus, long_align, use_read, yytext_is_array, do_yywrap;
|
||||
extern int csize;
|
||||
extern int csize, do_main;
|
||||
extern int yymore_used, reject, real_reject, continued_action, in_rule;
|
||||
|
||||
extern int yymore_really_used, reject_really_used;
|
||||
@ -778,7 +780,10 @@ extern void mkechar(int, int[], int[]);
|
||||
extern void do_indent(void); /* indent to the current level */
|
||||
|
||||
/* Set a conmditional amd make it visible in generated code */
|
||||
extern void visible_define (const char *symname);
|
||||
extern void visible_define (const char *);
|
||||
|
||||
/* And again, with an explicit value part. */
|
||||
extern void visible_define_str (const char *, const char *);
|
||||
|
||||
/* Generate full speed compressed transition table. */
|
||||
extern void genctbl(void);
|
||||
@ -1071,7 +1076,6 @@ extern struct Buf *buf_append(struct Buf * buf, const void *ptr, int n_elem);
|
||||
extern struct Buf *buf_concat(struct Buf* dest, const struct Buf* src);
|
||||
extern struct Buf *buf_strappend(struct Buf *, const char *str);
|
||||
extern struct Buf *buf_strnappend(struct Buf *, const char *str, int nchars);
|
||||
extern struct Buf *buf_strdefine(struct Buf * buf, const char *str, const char *def);
|
||||
extern struct Buf *buf_prints(struct Buf *buf, const char *fmt, const char* s);
|
||||
extern struct Buf *buf_m4_define(struct Buf *buf, const char* def, const char* val);
|
||||
extern struct Buf *buf_m4_undefine(struct Buf *buf, const char* def);
|
||||
|
||||
@ -810,6 +810,15 @@ void visible_define (const char *symname)
|
||||
outc ('\n');
|
||||
}
|
||||
|
||||
void visible_define_str (const char *symname, const char *val)
|
||||
{
|
||||
char buf[128];
|
||||
out_m4_define(symname, val);
|
||||
snprintf(buf, sizeof(buf), "%s = %s", symname, val);
|
||||
backend->comment(buf);
|
||||
outc ('\n');
|
||||
}
|
||||
|
||||
/* make_tables - generate transition tables and finishes generating output file
|
||||
*/
|
||||
|
||||
|
||||
67
src/main.c
67
src/main.c
@ -51,7 +51,7 @@ int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, spprdflt;
|
||||
int interactive, lex_compat, posix_compat, do_yylineno,
|
||||
useecs, fulltbl, usemecs;
|
||||
int fullspd, gen_line_dirs, performance_report, backing_up_report;
|
||||
int C_plus_plus, long_align, use_read, yytext_is_array, do_yywrap,
|
||||
int C_plus_plus, long_align, use_read, yytext_is_array, do_yywrap, do_main,
|
||||
csize;
|
||||
int reentrant, bison_bridge_lval, bison_bridge_lloc;
|
||||
int yymore_used, reject, real_reject, continued_action, in_rule;
|
||||
@ -312,9 +312,6 @@ void check_options (void)
|
||||
}
|
||||
}
|
||||
|
||||
if (extra_type)
|
||||
buf_m4_define( &m4defs_buf, "M4_EXTRA_TYPE_DEFS", extra_type);
|
||||
|
||||
if (!use_stdout) {
|
||||
FILE *prev_stdout;
|
||||
|
||||
@ -826,12 +823,12 @@ void flexinit (int argc, char **argv)
|
||||
break;
|
||||
|
||||
case OPT_MAIN:
|
||||
buf_strdefine (&userdef_buf, "YY_MAIN", "1");
|
||||
do_yywrap = false;
|
||||
do_main = 2;
|
||||
break;
|
||||
|
||||
case OPT_NO_MAIN:
|
||||
buf_strdefine (&userdef_buf, "YY_MAIN", "0");
|
||||
do_main = 1;
|
||||
break;
|
||||
|
||||
case OPT_NO_LINE:
|
||||
@ -884,7 +881,6 @@ void flexinit (int argc, char **argv)
|
||||
break;
|
||||
|
||||
case OPT_NO_UNISTD_H:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_UNISTD_H", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_UNISTD_H",0);
|
||||
break;
|
||||
|
||||
@ -991,7 +987,6 @@ void flexinit (int argc, char **argv)
|
||||
break;
|
||||
|
||||
case OPT_STACK:
|
||||
//buf_strdefine (&userdef_buf, "YY_STACK_USED", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_STACK_USED",0);
|
||||
break;
|
||||
|
||||
@ -1040,95 +1035,72 @@ void flexinit (int argc, char **argv)
|
||||
break;
|
||||
|
||||
case OPT_NO_YY_PUSH_STATE:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_PUSH_STATE", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_PUSH_STATE",0);
|
||||
break;
|
||||
case OPT_NO_YY_POP_STATE:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_POP_STATE", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_POP_STATE",0);
|
||||
break;
|
||||
case OPT_NO_YY_TOP_STATE:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_TOP_STATE", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_TOP_STATE",0);
|
||||
break;
|
||||
case OPT_NO_UNPUT:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_UNPUT", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_UNPUT",0);
|
||||
break;
|
||||
case OPT_NO_YY_SCAN_BUFFER:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_SCAN_BUFFER", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_BUFFER",0);
|
||||
break;
|
||||
case OPT_NO_YY_SCAN_BYTES:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_SCAN_BYTES", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_BYTES",0);
|
||||
break;
|
||||
case OPT_NO_YY_SCAN_STRING:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_SCAN_STRING", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_STRING",0);
|
||||
break;
|
||||
case OPT_NO_YYGET_EXTRA:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_GET_EXTRA", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_EXTRA",0);
|
||||
break;
|
||||
case OPT_NO_YYSET_EXTRA:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_SET_EXTRA", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_EXTRA",0);
|
||||
break;
|
||||
case OPT_NO_YYGET_LENG:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_GET_LENG", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LENG",0);
|
||||
break;
|
||||
case OPT_NO_YYGET_TEXT:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_GET_TEXT", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_TEXT",0);
|
||||
break;
|
||||
case OPT_NO_YYGET_LINENO:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_GET_LINENO", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LINENO",0);
|
||||
break;
|
||||
case OPT_NO_YYSET_LINENO:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_SET_LINENO", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LINENO",0);
|
||||
break;
|
||||
case OPT_NO_YYGET_COLUMN:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_GET_COLUMN", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_COLUMN",0);
|
||||
break;
|
||||
case OPT_NO_YYSET_COLUMN:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_SET_COLUMN", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_COLUMN",0);
|
||||
break;
|
||||
case OPT_NO_YYGET_IN:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_GET_IN", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_IN",0);
|
||||
break;
|
||||
case OPT_NO_YYSET_IN:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_SET_IN", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_IN",0);
|
||||
break;
|
||||
case OPT_NO_YYGET_OUT:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_GET_OUT", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_OUT",0);
|
||||
break;
|
||||
case OPT_NO_YYSET_OUT:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_SET_OUT", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_OUT",0);
|
||||
break;
|
||||
case OPT_NO_YYGET_LVAL:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_GET_LVAL", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LVAL",0);
|
||||
break;
|
||||
case OPT_NO_YYSET_LVAL:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_SET_LVAL", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LVAL",0);
|
||||
break;
|
||||
case OPT_NO_YYGET_LLOC:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_GET_LLOC", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LLOC",0);
|
||||
break;
|
||||
case OPT_NO_YYSET_LLOC:
|
||||
//buf_strdefine (&userdef_buf, "YY_NO_SET_LLOC", "1");
|
||||
buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LLOC",0);
|
||||
break;
|
||||
case OPT_HEX:
|
||||
@ -1186,8 +1158,6 @@ void readin (void)
|
||||
yyout = stdout;
|
||||
|
||||
|
||||
/* always generate the tablesverify flag. */
|
||||
buf_m4_define (&m4defs_buf, "M4_YY_TABLES_VERIFY", tablesverify ? "1" : "0");
|
||||
if (tablesext)
|
||||
gentables = false;
|
||||
|
||||
@ -1229,13 +1199,6 @@ void readin (void)
|
||||
if (skelname && (skelfile = fopen (skelname, "r")) == NULL)
|
||||
lerr (_("can't open skeleton file %s"), skelname);
|
||||
|
||||
if (reentrant) {
|
||||
buf_m4_define (&m4defs_buf, "M4_YY_REENTRANT", NULL);
|
||||
if (yytext_is_array)
|
||||
buf_m4_define (&m4defs_buf, "M4_YY_TEXT_IS_ARRAY", NULL);
|
||||
} else
|
||||
buf_m4_define (&m4defs_buf, "M4_YY_NOT_REENTRANT", NULL);
|
||||
|
||||
if ( bison_bridge_lval)
|
||||
buf_m4_define (&m4defs_buf, "M4_YY_BISON_LVAL", NULL);
|
||||
|
||||
@ -1411,6 +1374,24 @@ void readin (void)
|
||||
|
||||
backend->comment("m4 controls begin\n");
|
||||
|
||||
if (extra_type != NULL)
|
||||
visible_define_str ("M4_EXTRA_TYPE_DEFS", extra_type);
|
||||
|
||||
/* always generate the tablesverify flag. */
|
||||
visible_define_str ("M4_YY_TABLES_VERIFY", tablesverify ? "1" : "0");
|
||||
|
||||
if (reentrant) {
|
||||
visible_define ("M4_YY_REENTRANT");
|
||||
if (yytext_is_array)
|
||||
visible_define ("M4_YY_TEXT_IS_ARRAY");
|
||||
} else
|
||||
visible_define ("M4_YY_NOT_REENTRANT");
|
||||
|
||||
if (do_main == 2)
|
||||
visible_define_str ( "YY_MAIN", "1");
|
||||
else if (do_main == 1)
|
||||
visible_define_str ( "YY_MAIN", "0");
|
||||
|
||||
if (do_stdinit)
|
||||
visible_define ( "M4_MODE_DO_STDINIT");
|
||||
else
|
||||
@ -1482,7 +1463,7 @@ void readin (void)
|
||||
if (useecs)
|
||||
visible_define ( "M4_MODE_USEECS");
|
||||
else
|
||||
visible_define ( "M4_NOT_MODE_USEECS");
|
||||
visible_define ( "M4_MODE_NO_USEECS");
|
||||
|
||||
// mode switches for getting next action
|
||||
if (gentables)
|
||||
@ -1507,7 +1488,7 @@ void readin (void)
|
||||
visible_define ( "M4_MODE_DEBUG");
|
||||
|
||||
if (lex_compat)
|
||||
visible_define ( "M4_LEX_COMPAT");
|
||||
visible_define ( "M4_MODE_LEX_COMPAT");
|
||||
|
||||
if (do_yywrap)
|
||||
visible_define ( "M4_MODE_YYWRAP");
|
||||
@ -1526,7 +1507,7 @@ void readin (void)
|
||||
if (tablesext)
|
||||
visible_define ( "M4_MODE_TABLESEXT");
|
||||
if (prefix != NULL)
|
||||
out_m4_define ( "M4_MODE_PREFIX", prefix); // FIXME: should be visible
|
||||
visible_define_str ( "M4_MODE_PREFIX", prefix);
|
||||
|
||||
backend->comment("m4 controls end\n");
|
||||
out ("\n");
|
||||
|
||||
@ -88,7 +88,7 @@ static void sko_pop(bool* dc)
|
||||
flex_die("popped too many times in skeleton.");
|
||||
}
|
||||
|
||||
/* Append "#define defname value\n" to the running buffer. */
|
||||
/* Append a constant declaration to the running buffer. */
|
||||
void action_define (const char *defname, int value)
|
||||
{
|
||||
char buf[MAXLINE];
|
||||
@ -104,7 +104,9 @@ void action_define (const char *defname, int value)
|
||||
snprintf (buf, sizeof(buf), backend->int_define_fmt, defname, value);
|
||||
add_action (buf);
|
||||
|
||||
/* track #defines so we can undef them when we're done. */
|
||||
/* 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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user