summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2020-10-15 06:43:21 -0400
committerEric S. Raymond <esr@thyrsus.com>2020-10-15 06:43:21 -0400
commitdd60560bfd804f430924647bab625f9e887c367d (patch)
treeb3b192e92a87cf44a6dd633cf9427a6c3cfd82d0
parent20779d47a7762e707b07889b48647cd08f97fb0f (diff)
downloadflex-git-dd60560bfd804f430924647bab625f9e887c367d.tar.gz
Refactor filter.c to use line_directive_out().
To make this work, use line_directive_out() had to be servered from its deoendence on hidden globaks. Which was a good idea anyway, No diffs in generated test code from this commit. Yet another well-hidden C assumption. I begin to woner if I will expire of old age before fkushing out all of these.
-rw-r--r--src/filter.c2
-rw-r--r--src/flexdef.h2
-rw-r--r--src/main.c14
-rw-r--r--src/misc.c11
-rw-r--r--src/nfa.c2
-rw-r--r--src/parse.y2
-rw-r--r--src/scan.l6
7 files changed, 19 insertions, 20 deletions
diff --git a/src/filter.c b/src/filter.c
index 2f31484..ddf68af 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -291,7 +291,7 @@ int filter_tee_header (struct filter *chain)
/* write a fake line number. It will get fixed by the linedir filter. */
if (ctrl.gen_line_dirs)
- fprintf (to_h, "m4_ifdef([[M4_HOOK_TRACE_LINE_FORMAT]], [[M4_HOOK_TRACE_LINE_FORMAT([[4000]], [[M4_YY_OUTFILE_NAME]])]])");
+ line_directive_out (to_h, NULL, 4000);
if (backend == &cpp_backend) {
fprintf (to_h, "#undef %sIN_HEADER\n", ctrl.prefix);
diff --git a/src/flexdef.h b/src/flexdef.h
index 775b6ad..2a92f9e 100644
--- a/src/flexdef.h
+++ b/src/flexdef.h
@@ -909,7 +909,7 @@ extern void lerr_fatal(const char *, ...)
;
/* Spit out a "#line" statement. */
-extern void line_directive_out(FILE *, int);
+extern void line_directive_out(FILE *, char *, int);
/* Mark the current position in the action array as the end of the section 1
* user defs.
diff --git a/src/main.c b/src/main.c
index a36339a..b6ad5be 100644
--- a/src/main.c
+++ b/src/main.c
@@ -219,21 +219,21 @@ int flex_main (int argc, char *argv[])
out (&action_array[defs1_offset]);
- line_directive_out (stdout, 0);
+ line_directive_out (stdout, NULL, linenum);
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);
+ line_directive_out (stdout, NULL, linenum);
skelout (true); /* %% [5.0] - main loop of matching-engine code gets dumped here */
/* Copy actions to output file. */
out (&action_array[action_offset]);
- line_directive_out (stdout, 0);
+ line_directive_out (stdout, NULL, linenum);
/* generate cases for any missing EOF rules */
for (i = 1; i <= lastsc; ++i)
@@ -253,7 +253,7 @@ int flex_main (int argc, char *argv[])
/* Copy remainder of input to output. */
- line_directive_out (stdout, 1);
+ line_directive_out (stdout, infilename, linenum);
if (sectnum == 3) {
OUT_BEGIN_CODE ();
@@ -1209,7 +1209,7 @@ void flexinit (int argc, char **argv)
void readin (void)
{
- line_directive_out(NULL, 1);
+ line_directive_out(NULL, infilename, linenum);
if (yyparse ()) {
pinpoint_message (_("fatal parse error"));
@@ -1265,7 +1265,7 @@ void readin (void)
flexerror(_("Prefix cannot include '[' or ']'"));
if (env.did_outfilename)
- line_directive_out (stdout, 0);
+ line_directive_out (stdout, NULL, linenum);
/* This is where we begin writing to the file. */
@@ -1278,7 +1278,7 @@ void readin (void)
outn((char*) top_buf.elts);
/* Place a bogus line directive, it will be fixed in the filter. */
- line_directive_out(0, false);
+ line_directive_out(NULL, NULL, 0);
/* User may want to set the scanner prototype */
if (ctrl.yydecl != NULL) {
diff --git a/src/misc.c b/src/misc.c
index 6057587..9cecd5c 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -262,9 +262,8 @@ void lerr_fatal (const char *msg, ...)
}
-/* line_directive_out - spit out a "#line" statement */
-
-void line_directive_out (FILE *output_file, int do_infile)
+/* line_directive_out - spit out a "#line" statement or equivalent */
+void line_directive_out (FILE *output_file, char *path, int linenum)
{
char *trace_fmt = "m4_ifdef([[M4_HOOK_TRACE_LINE_FORMAT]], [[M4_HOOK_TRACE_LINE_FORMAT([[%d]], [[%s]])]])";
char directive[MAXLINE*2], filename[MAXLINE];
@@ -273,9 +272,9 @@ void line_directive_out (FILE *output_file, int do_infile)
if (!ctrl.gen_line_dirs)
return;
- s1 = do_infile ? infilename : "M4_YY_OUTFILE_NAME";
+ s1 = (path != NULL) ? path : "M4_YY_OUTFILE_NAME";
- if (do_infile && !s1)
+ if ((path != NULL) && !s1)
s1 = "<stdin>";
s2 = filename;
@@ -291,7 +290,7 @@ void line_directive_out (FILE *output_file, int do_infile)
*s2 = '\0';
- if (do_infile)
+ if (path != NULL)
snprintf (directive, sizeof(directive), trace_fmt, linenum, filename);
else {
snprintf (directive, sizeof(directive), trace_fmt, 0, filename);
diff --git a/src/nfa.c b/src/nfa.c
index 57a6634..f6e8300 100644
--- a/src/nfa.c
+++ b/src/nfa.c
@@ -286,7 +286,7 @@ void finish_rule (int mach, int variable_trail_rule, int headcnt, int trailcn
if (!continued_action)
add_action ("YY_RULE_SETUP\n");
- line_directive_out(NULL, 1);
+ line_directive_out(NULL, infilename, linenum);
add_action("[[");
}
diff --git a/src/parse.y b/src/parse.y
index 2bb9b1c..9cd764c 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -989,7 +989,7 @@ void build_eof_action(void)
}
}
- line_directive_out(NULL, 1);
+ line_directive_out(NULL, infilename, linenum);
add_action("[[");
/* This isn't a normal rule after all - don't count it as
diff --git a/src/scan.l b/src/scan.l
index af6f4ce..08a4842 100644
--- a/src/scan.l
+++ b/src/scan.l
@@ -100,7 +100,7 @@ extern const char *escaped_qstart, *escaped_qend;
/* Emit the needed line directive... */\
if (indented_code == false) { \
linenum++; \
- line_directive_out(NULL, 1); \
+ line_directive_out(NULL, infilename, linenum); \
} \
add_action(M4QSTART); \
yy_push_state(CODEBLOCK); \
@@ -110,7 +110,7 @@ extern const char *escaped_qstart, *escaped_qend;
#define END_CODEBLOCK do { \
yy_pop_state();\
add_action(M4QEND); \
- if (!indented_code) line_directive_out(NULL, 0);\
+ if (!indented_code) line_directive_out(NULL, NULL, linenum); \
} while (0)
%}
@@ -187,7 +187,7 @@ M4QEND "]""]"
sectnum = 2;
bracelevel = 0;
mark_defs1();
- line_directive_out(NULL, 1);
+ line_directive_out(NULL, infilename, linenum);
BEGIN(SECT2PROLOG);
return SECTEND;
}