mirror of
https://github.com/westes/flex.git
synced 2026-01-26 15:39:06 +00:00
Replace the comment method with a hook macro.
This required addin a new 0.0 breakpoint right after the M4_HOOK_* definitions so they will be visible early. Produces no diffs in generated test code. #62 in the retargeting patch series
This commit is contained in:
parent
83d8bd5fb9
commit
fafc0ef10c
@ -64,6 +64,9 @@ m4_changequote([[, ]])
|
||||
|
||||
%# Macro hooks used by Flex start here
|
||||
|
||||
m4_define([[M4_HOOK_COMMENT_OPEN]], [[/*]])
|
||||
m4_define([[M4_HOOK_COMMENT_CLOSE]], [[*/]])
|
||||
|
||||
%# If this is not defined, no trace lines will be generated.
|
||||
m4_define([[M4_HOOK_TRACE_LINE_FORMAT]], [[#line $1 "$2"
|
||||
]])
|
||||
@ -87,7 +90,7 @@ m4_define([[M4_HOOK_CONST_DEFINE]], [[#define $1 $2
|
||||
|
||||
m4_define([[M4_HOOK_STATE_DYAD]], [[ {$1, $2},]])
|
||||
|
||||
%# Macro hooks used by lex end here
|
||||
%% [0.0] Make hook macros available to Flex
|
||||
|
||||
%not-for-header
|
||||
%if-c-only
|
||||
|
||||
@ -88,21 +88,6 @@ static const char *cpp_suffix (void)
|
||||
return suffix;
|
||||
}
|
||||
|
||||
static void cpp_comment(const char *txt)
|
||||
{
|
||||
char buf[MAXLINE];
|
||||
bool eol;
|
||||
|
||||
strncpy(buf, txt, MAXLINE-1);
|
||||
eol = buf[strlen(buf)-1] == '\n';
|
||||
|
||||
if (eol)
|
||||
buf[strlen(buf)-1] = '\0';
|
||||
out_str("/* [[%s]] */", buf);
|
||||
if (eol)
|
||||
outc ('\n');
|
||||
}
|
||||
|
||||
static void cpp_ntod(size_t num_full_table_rows)
|
||||
// Generate nxt table for ntod
|
||||
{
|
||||
@ -280,7 +265,6 @@ const char *cpp_skel[] = {
|
||||
struct flex_backend_t cpp_backend = {
|
||||
.suffix = cpp_suffix,
|
||||
.skel = cpp_skel,
|
||||
.comment = cpp_comment,
|
||||
.ntod = cpp_ntod,
|
||||
.mkctbl = cpp_mkctbl,
|
||||
.gen_yy_trans = cpp_gen_yy_trans,
|
||||
|
||||
@ -306,8 +306,6 @@
|
||||
struct flex_backend_t {
|
||||
const char *(*suffix)(void); // Generate suffix for lexer source code
|
||||
const char **skel;
|
||||
// Language syntax generation
|
||||
void (*comment)(const char *); // Wrap a comment line
|
||||
// Flex table generation
|
||||
void (*ntod)(size_t); // Generate nxt table initializer start (fulltbl mode)
|
||||
void (*mkctbl)(size_t); // Make full-speed compressed table initializer start
|
||||
@ -953,7 +951,7 @@ extern void out_m4_define(const char* def, const char* val);
|
||||
extern char *readable_form(int);
|
||||
|
||||
/* Write out one section of the skeleton file. */
|
||||
extern void skelout(void);
|
||||
extern void skelout(bool);
|
||||
|
||||
/* Output a yy_trans_info structure. */
|
||||
extern void transition_struct_out(int, int);
|
||||
@ -1029,6 +1027,8 @@ extern void lwarn(const char *); /* report a warning */
|
||||
extern void yyerror(const char *); /* report a parse error */
|
||||
extern int yyparse(void); /* the YACC parser */
|
||||
|
||||
/* Ship a comment to the generated output */
|
||||
extern void comment(const char *);
|
||||
|
||||
/* from file scan.l */
|
||||
|
||||
|
||||
10
src/gen.c
10
src/gen.c
@ -844,7 +844,7 @@ void gentabs (void)
|
||||
void visible_define (const char *symname)
|
||||
{
|
||||
out_m4_define(symname, NULL);
|
||||
backend->comment(symname);
|
||||
comment(symname);
|
||||
outc ('\n');
|
||||
}
|
||||
|
||||
@ -853,7 +853,7 @@ 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);
|
||||
comment(buf);
|
||||
outc ('\n');
|
||||
}
|
||||
|
||||
@ -924,13 +924,13 @@ void make_tables (void)
|
||||
gentabs ();
|
||||
|
||||
snprintf(buf, sizeof(buf), "footprint: %ld bytes\n", footprint);
|
||||
backend->comment(buf);
|
||||
comment(buf);
|
||||
outc ('\n');
|
||||
|
||||
// Only at this point do we know if the automaton has backups.
|
||||
// Some m4 conditionals require this information.
|
||||
|
||||
backend->comment("m4 controls begin\n");
|
||||
comment("m4 controls begin\n");
|
||||
|
||||
if (num_backing_up > 0)
|
||||
visible_define ( "M4_MODE_HAS_BACKING_UP");
|
||||
@ -941,7 +941,7 @@ void make_tables (void)
|
||||
if ((num_backing_up > 0 && !reject) && (ctrl.fullspd || ctrl.fulltbl))
|
||||
visible_define ( "M4_MODE_NULTRANS_WRAP");
|
||||
|
||||
backend->comment("m4 controls end\n");
|
||||
comment("m4 controls end\n");
|
||||
out ("\n");
|
||||
|
||||
if (ctrl.do_yylineno) {
|
||||
|
||||
31
src/main.c
31
src/main.c
@ -164,7 +164,7 @@ int flex_main (int argc, char *argv[])
|
||||
|
||||
readin ();
|
||||
|
||||
skelout (); /* %% [1.0] DFA */
|
||||
skelout (true); /* %% [1.0] DFA */
|
||||
footprint += ntod ();
|
||||
|
||||
for (i = 1; i <= num_rules; ++i)
|
||||
@ -177,7 +177,7 @@ int flex_main (int argc, char *argv[])
|
||||
("-s option given but default rule can be matched"),
|
||||
rule_linenum[default_rule]);
|
||||
|
||||
backend->comment("START of m4 controls\n");
|
||||
comment("START of m4 controls\n");
|
||||
|
||||
// mode switches for yy_trans_info specification
|
||||
// nultrans
|
||||
@ -195,10 +195,10 @@ int flex_main (int argc, char *argv[])
|
||||
visible_define ( "M4_MODE_NO_NULTRANS_FULLSPD");
|
||||
}
|
||||
|
||||
backend->comment("END of m4 controls\n");
|
||||
comment("END of m4 controls\n");
|
||||
out ("\n");
|
||||
|
||||
backend->comment("START of Flex-generated definitions\n");
|
||||
comment("START of Flex-generated definitions\n");
|
||||
out_str_dec ("M4_HOOK_CONST_DEFINE(%s, %d)", "YY_NUM_RULES", num_rules);
|
||||
out_str_dec ("M4_HOOK_CONST_DEFINE(%s, %d)", "YY_END_OF_BUFFER", num_rules + 1);
|
||||
out_str_dec ("M4_HOOK_CONST_DEFINE(%s, %d)", "YY_JAMBASE", jambase);
|
||||
@ -208,27 +208,27 @@ int flex_main (int argc, char *argv[])
|
||||
* enough to hold the biggest offset.
|
||||
*/
|
||||
out_str3 ("M4_HOOK_CONST_DEFINE(%s, %s)", "YY_OFFSET_TYPE", backend->trans_offset_type(tblend + numecs + 1), "");
|
||||
backend->comment("END of Flex-generated definitions\n");
|
||||
comment("END of Flex-generated definitions\n");
|
||||
|
||||
skelout (); /* %% [2.0] - tables get dumped here */
|
||||
skelout (true); /* %% [2.0] - tables get dumped here */
|
||||
|
||||
/* Generate the C state transition tables from the DFA. */
|
||||
make_tables ();
|
||||
|
||||
skelout (); /* %% [3.0] - mode-dependent static declarations get dumped here */
|
||||
skelout (true); /* %% [3.0] - mode-dependent static declarations get dumped here */
|
||||
|
||||
out (&action_array[defs1_offset]);
|
||||
|
||||
line_directive_out (stdout, 0);
|
||||
|
||||
skelout (); /* %% [4.0] - various random yylex internals get dumped here */
|
||||
skelout (true); /* %% [4.0] - various random yylex internals get dumped here */
|
||||
|
||||
/* Copy prolog to output file. */
|
||||
out (&action_array[prolog_offset]);
|
||||
|
||||
line_directive_out (stdout, 0);
|
||||
|
||||
skelout (); /* %% [5.0] - main loop of matching-engine code gets dumped here */
|
||||
skelout (true); /* %% [5.0] - main loop of matching-engine code gets dumped here */
|
||||
|
||||
/* Copy actions to output file. */
|
||||
out (&action_array[action_offset]);
|
||||
@ -249,7 +249,7 @@ int flex_main (int argc, char *argv[])
|
||||
out ("M4_HOOK_EOF_STATE_CASE_TERMINATE");
|
||||
}
|
||||
|
||||
skelout ();
|
||||
skelout (true);
|
||||
|
||||
/* Copy remainder of input to output. */
|
||||
|
||||
@ -1270,7 +1270,9 @@ void readin (void)
|
||||
|
||||
/* This is where we begin writing to the file. */
|
||||
|
||||
backend->comment("A lexical scanner generated by flex\n");
|
||||
skelout(false); /* [0.0] Make hook macros available, silently */
|
||||
|
||||
comment("A lexical scanner generated by flex\n");
|
||||
|
||||
/* Dump the %top code. */
|
||||
if( top_buf.elts)
|
||||
@ -1394,15 +1396,12 @@ 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
|
||||
// we make it easier to retarget the code generation.
|
||||
|
||||
backend->comment("START of m4 controls\n");
|
||||
comment("START of m4 controls\n");
|
||||
|
||||
/* Define the start condition macros. */
|
||||
{
|
||||
@ -1642,7 +1641,7 @@ void readin (void)
|
||||
if (ctrl.stack_used)
|
||||
visible_define("M4_YY_STACK_USED");
|
||||
|
||||
backend->comment("END of m4 controls\n");
|
||||
comment("END of m4 controls\n");
|
||||
out ("\n");
|
||||
}
|
||||
|
||||
|
||||
32
src/misc.c
32
src/misc.c
@ -667,7 +667,7 @@ void *reallocate_array (void *array, int size, size_t element_size)
|
||||
* Copies skelfile or skel array to stdout until a line beginning with
|
||||
* "%%" or EOF is found.
|
||||
*/
|
||||
void skelout (void)
|
||||
void skelout (bool announce)
|
||||
{
|
||||
char buf_storage[MAXLINE];
|
||||
char *buf = buf_storage;
|
||||
@ -696,10 +696,10 @@ void skelout (void)
|
||||
if (ctrl.ddebug && buf[1] != '#') {
|
||||
bool escaped = buf[strlen (buf) - 1] == '\\';
|
||||
if (escaped) {
|
||||
backend->comment(buf);
|
||||
comment(buf);
|
||||
out ("\\\n");
|
||||
} else {
|
||||
backend->comment(buf);
|
||||
comment(buf);
|
||||
outc ('\n');
|
||||
}
|
||||
}
|
||||
@ -716,8 +716,10 @@ void skelout (void)
|
||||
}
|
||||
else if (buf[1] == '%') {
|
||||
/* %% is a break point for skelout() */
|
||||
backend->comment(buf);
|
||||
outc ('\n');
|
||||
if (announce) {
|
||||
comment(buf);
|
||||
outc ('\n');
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (cmd_match (CMD_PUSH)){
|
||||
@ -725,7 +727,7 @@ void skelout (void)
|
||||
if(ctrl.ddebug){
|
||||
char buf2[MAXLINE];
|
||||
snprintf(buf2, sizeof(buf2), "(state = (%s)\n",do_copy?"true":"false");
|
||||
backend->comment(buf2);
|
||||
comment(buf2);
|
||||
}
|
||||
out_str("%s\n", buf[strlen (buf) - 1] =='\\' ? "\\" : "");
|
||||
}
|
||||
@ -734,7 +736,7 @@ void skelout (void)
|
||||
if(ctrl.ddebug){
|
||||
char buf2[MAXLINE];
|
||||
snprintf(buf2, sizeof(buf2), "(state = (%s)\n",do_copy?"true":"false");
|
||||
backend->comment(buf2);
|
||||
comment(buf2);
|
||||
}
|
||||
out_str("%s\n", buf[strlen (buf) - 1] =='\\' ? "\\" : "");
|
||||
}
|
||||
@ -865,3 +867,19 @@ char *chomp (char *str)
|
||||
*p-- = 0;
|
||||
return str;
|
||||
}
|
||||
|
||||
void comment(const char *txt)
|
||||
{
|
||||
char buf[MAXLINE];
|
||||
bool eol;
|
||||
|
||||
strncpy(buf, txt, MAXLINE-1);
|
||||
eol = buf[strlen(buf)-1] == '\n';
|
||||
|
||||
if (eol)
|
||||
buf[strlen(buf)-1] = '\0';
|
||||
out_str("M4_HOOK_COMMENT_OPEN [[%s]] M4_HOOK_COMMENT_CLOSE", buf);
|
||||
if (eol)
|
||||
outc ('\n');
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user