Commit 80e9dcb4 by Zack Weinberg Committed by Zack Weinberg

cpplib.c (output_line_command): Drop CONDITIONAL argument.

1999-04-19 14:51 -0400  Zack Weinberg  <zack@rabi.columbia.edu>
	* cpplib.c (output_line_command): Drop CONDITIONAL argument.
	We can omit unnecessary line commands if file_change ==
	same_file and pfile->lineno != 0.  All callers changed.
	(cpp_get_token [case '\n']): Don't bump pfile->lineno if
	CPP_OPTIONS (pfile)->no_line_commands is set.
	* cpplib.h: Fix prototype of output_line_command.

From-SVN: r26547
parent a3f406ce
1999-04-19 14:51 -0400 Zack Weinberg <zack@rabi.columbia.edu>
* cpplib.c (output_line_command): Drop CONDITIONAL argument.
We can omit unnecessary line commands if file_change ==
same_file and pfile->lineno != 0. All callers changed.
(cpp_get_token [case '\n']): Don't bump pfile->lineno if
CPP_OPTIONS (pfile)->no_line_commands is set.
* cpplib.h: Fix prototype of output_line_command.
1999-04-18 17:46 -0400 Zack Weinberg <zack@rabi.columbia.edu> 1999-04-18 17:46 -0400 Zack Weinberg <zack@rabi.columbia.edu>
* cppfiles.c (find_position, read_and_prescan): Use `unsigned * cppfiles.c (find_position, read_and_prescan): Use `unsigned
......
...@@ -505,7 +505,7 @@ dump_special_to_buffer (pfile, macro_name) ...@@ -505,7 +505,7 @@ dump_special_to_buffer (pfile, macro_name)
{ {
static char define_directive[] = "#define "; static char define_directive[] = "#define ";
int macro_name_length = strlen (macro_name); int macro_name_length = strlen (macro_name);
output_line_command (pfile, 0, same_file); output_line_command (pfile, same_file);
CPP_RESERVE (pfile, sizeof(define_directive) + macro_name_length); CPP_RESERVE (pfile, sizeof(define_directive) + macro_name_length);
CPP_PUTS_Q (pfile, define_directive, sizeof(define_directive)-1); CPP_PUTS_Q (pfile, define_directive, sizeof(define_directive)-1);
CPP_PUTS_Q (pfile, macro_name, macro_name_length); CPP_PUTS_Q (pfile, macro_name, macro_name_length);
...@@ -814,7 +814,7 @@ cpp_start_read (pfile, fname) ...@@ -814,7 +814,7 @@ cpp_start_read (pfile, fname)
while (p) while (p)
{ {
if (opts->debug_output) if (opts->debug_output)
output_line_command (pfile, 0, same_file); output_line_command (pfile, same_file);
if (p->undef) if (p->undef)
cpp_undef (pfile, p->arg); cpp_undef (pfile, p->arg);
else else
...@@ -829,7 +829,7 @@ cpp_start_read (pfile, fname) ...@@ -829,7 +829,7 @@ cpp_start_read (pfile, fname)
while (p) while (p)
{ {
if (opts->debug_output) if (opts->debug_output)
output_line_command (pfile, 0, same_file); output_line_command (pfile, same_file);
if (p->undef) if (p->undef)
cpp_unassert (pfile, p->arg); cpp_unassert (pfile, p->arg);
else else
...@@ -980,7 +980,7 @@ cpp_start_read (pfile, fname) ...@@ -980,7 +980,7 @@ cpp_start_read (pfile, fname)
ih_fake->limit = 0; ih_fake->limit = 0;
if (!finclude (pfile, f, ih_fake)) if (!finclude (pfile, f, ih_fake))
return 0; return 0;
output_line_command (pfile, 0, same_file); output_line_command (pfile, same_file);
pfile->only_seen_white = 2; pfile->only_seen_white = 2;
/* The -imacros files can be scanned now, but the -include files /* The -imacros files can be scanned now, but the -include files
...@@ -1043,7 +1043,7 @@ cpp_start_read (pfile, fname) ...@@ -1043,7 +1043,7 @@ cpp_start_read (pfile, fname)
ih_fake->buf = (char *)-1; ih_fake->buf = (char *)-1;
ih_fake->limit = 0; ih_fake->limit = 0;
if (finclude (pfile, fd, ih_fake)) if (finclude (pfile, fd, ih_fake))
output_line_command (pfile, 0, enter_file); output_line_command (pfile, enter_file);
q = p->next; q = p->next;
free (p); free (p);
...@@ -1094,6 +1094,25 @@ cpp_finish (pfile) ...@@ -1094,6 +1094,25 @@ cpp_finish (pfile)
} }
} }
} }
if (opts->dump_macros == dump_only)
{
int i;
HASHNODE *h;
MACRODEF m;
for (i = HASHSIZE; --i >= 0;)
{
for (h = pfile->hashtab[i]; h; h = h->next)
if (h->type == T_MACRO)
{
m.defn = h->value.defn;
m.symnam = h->name;
m.symlen = h->length;
dump_definition (pfile, m);
CPP_PUTC (pfile, '\n');
}
}
}
} }
/* Handle one command-line option in (argc, argv). /* Handle one command-line option in (argc, argv).
......
...@@ -896,19 +896,15 @@ cpp_file_buffer (pfile) ...@@ -896,19 +896,15 @@ cpp_file_buffer (pfile)
/* /*
* write out a #line command, for instance, after an #include file. * write out a #line command, for instance, after an #include file.
* If CONDITIONAL is nonzero, we can omit the #line if it would
* appear to be a no-op, and we can output a few newlines instead
* if we want to increase the line number by a small amount.
* FILE_CHANGE says whether we are entering a file, leaving, or neither. * FILE_CHANGE says whether we are entering a file, leaving, or neither.
*/ */
void void
output_line_command (pfile, conditional, file_change) output_line_command (pfile, file_change)
cpp_reader *pfile; cpp_reader *pfile;
int conditional;
enum file_change_code file_change; enum file_change_code file_change;
{ {
long line, col; long line;
cpp_buffer *ip = CPP_BUFFER (pfile); cpp_buffer *ip = CPP_BUFFER (pfile);
if (ip->fname == NULL) if (ip->fname == NULL)
...@@ -918,9 +914,15 @@ output_line_command (pfile, conditional, file_change) ...@@ -918,9 +914,15 @@ output_line_command (pfile, conditional, file_change)
|| CPP_OPTIONS (pfile)->no_output) || CPP_OPTIONS (pfile)->no_output)
return; return;
cpp_buf_line_and_col (CPP_BUFFER (pfile), &line, &col); cpp_buf_line_and_col (CPP_BUFFER (pfile), &line, NULL);
if (conditional) /* If the current file has not changed, we omit the #line if it would
appear to be a no-op, and we output a few newlines instead
if we want to increase the line number by a small amount.
We cannot do this if pfile->lineno is zero, because that means we
haven't output any line commands yet. (The very first line command
output is a `same_file' command.) */
if (file_change == same_file && pfile->lineno != 0)
{ {
if (line == pfile->lineno) if (line == pfile->lineno)
return; return;
...@@ -1232,7 +1234,7 @@ do_include (pfile, keyword) ...@@ -1232,7 +1234,7 @@ do_include (pfile, keyword)
if (finclude (pfile, fd, ihash)) if (finclude (pfile, fd, ihash))
{ {
output_line_command (pfile, 0, enter_file); output_line_command (pfile, enter_file);
pfile->only_seen_white = 2; pfile->only_seen_white = 2;
} }
...@@ -1357,7 +1359,7 @@ do_line (pfile, keyword) ...@@ -1357,7 +1359,7 @@ do_line (pfile, keyword)
we must store a line number now that is one less. */ we must store a line number now that is one less. */
ip->lineno = new_lineno - 1; ip->lineno = new_lineno - 1;
CPP_SET_WRITTEN (pfile, old_written); CPP_SET_WRITTEN (pfile, old_written);
output_line_command (pfile, 0, file_change); output_line_command (pfile, file_change);
return 0; return 0;
bad_line_directive: bad_line_directive:
...@@ -1647,7 +1649,7 @@ do_elif (pfile, keyword) ...@@ -1647,7 +1649,7 @@ do_elif (pfile, keyword)
skip_if_group (pfile); skip_if_group (pfile);
else { else {
++pfile->if_stack->if_succeeded; /* continue processing input */ ++pfile->if_stack->if_succeeded; /* continue processing input */
output_line_command (pfile, 1, same_file); output_line_command (pfile, same_file);
} }
} }
return 0; return 0;
...@@ -1786,7 +1788,7 @@ conditional_skip (pfile, skip, type, control_macro) ...@@ -1786,7 +1788,7 @@ conditional_skip (pfile, skip, type, control_macro)
return; return;
} else { } else {
++pfile->if_stack->if_succeeded; ++pfile->if_stack->if_succeeded;
output_line_command (pfile, 1, same_file); output_line_command (pfile, same_file);
} }
} }
...@@ -1881,7 +1883,7 @@ skip_if_group (pfile) ...@@ -1881,7 +1883,7 @@ skip_if_group (pfile)
{ {
CPP_PUTS (pfile, "#failed\n", 8); CPP_PUTS (pfile, "#failed\n", 8);
pfile->lineno++; pfile->lineno++;
output_line_command (pfile, 1, same_file); output_line_command (pfile, same_file);
} }
old_written = CPP_WRITTEN (pfile); old_written = CPP_WRITTEN (pfile);
...@@ -1986,7 +1988,7 @@ do_else (pfile, keyword) ...@@ -1986,7 +1988,7 @@ do_else (pfile, keyword)
skip_if_group (pfile); skip_if_group (pfile);
else { else {
++pfile->if_stack->if_succeeded; /* continue processing input */ ++pfile->if_stack->if_succeeded; /* continue processing input */
output_line_command (pfile, 1, same_file); output_line_command (pfile, same_file);
} }
return 0; return 0;
} }
...@@ -2041,7 +2043,7 @@ do_endif (pfile, keyword) ...@@ -2041,7 +2043,7 @@ do_endif (pfile, keyword)
} }
} }
free (temp); free (temp);
output_line_command (pfile, 1, same_file); output_line_command (pfile, same_file);
} }
return 0; return 0;
} }
...@@ -2101,7 +2103,7 @@ cpp_get_token (pfile) ...@@ -2101,7 +2103,7 @@ cpp_get_token (pfile)
cpp_buffer *cur_buffer = CPP_BUFFER (pfile); cpp_buffer *cur_buffer = CPP_BUFFER (pfile);
CPP_BUFFER (pfile) = next_buf; CPP_BUFFER (pfile) = next_buf;
pfile->input_stack_listing_current = 0; pfile->input_stack_listing_current = 0;
output_line_command (pfile, 0, leave_file); output_line_command (pfile, leave_file);
CPP_BUFFER (pfile) = cur_buffer; CPP_BUFFER (pfile) = cur_buffer;
} }
return CPP_POP; return CPP_POP;
...@@ -2157,7 +2159,7 @@ cpp_get_token (pfile) ...@@ -2157,7 +2159,7 @@ cpp_get_token (pfile)
/* OK, now bring us back to the state we were in before we entered /* OK, now bring us back to the state we were in before we entered
this branch. We need #line because the newline for the pragma this branch. We need #line because the newline for the pragma
could mess things up. */ could mess things up. */
output_line_command (pfile, 0, same_file); output_line_command (pfile, same_file);
*(obp++) = ' '; /* just in case, if comments are copied thru */ *(obp++) = ' '; /* just in case, if comments are copied thru */
*(obp++) = '/'; *(obp++) = '/';
} }
...@@ -2527,9 +2529,12 @@ cpp_get_token (pfile) ...@@ -2527,9 +2529,12 @@ cpp_get_token (pfile)
if (pfile->only_seen_white == 0) if (pfile->only_seen_white == 0)
pfile->only_seen_white = 1; pfile->only_seen_white = 1;
CPP_BUMP_LINE (pfile); CPP_BUMP_LINE (pfile);
pfile->lineno++; if (! CPP_OPTIONS (pfile)->no_line_commands)
if (CPP_BUFFER (pfile)->lineno != pfile->lineno) {
output_line_command (pfile, 1, same_file); pfile->lineno++;
if (CPP_BUFFER (pfile)->lineno != pfile->lineno)
output_line_command (pfile, same_file);
}
return CPP_VSPACE; return CPP_VSPACE;
case '(': token = CPP_LPAREN; goto char1; case '(': token = CPP_LPAREN; goto char1;
......
...@@ -726,7 +726,7 @@ extern int check_macro_name PARAMS ((cpp_reader *, U_CHAR *, int)); ...@@ -726,7 +726,7 @@ extern int check_macro_name PARAMS ((cpp_reader *, U_CHAR *, int));
/* Last arg to output_line_command. */ /* Last arg to output_line_command. */
enum file_change_code {same_file, enter_file, leave_file}; enum file_change_code {same_file, enter_file, leave_file};
extern void output_line_command PARAMS ((cpp_reader *, int, extern void output_line_command PARAMS ((cpp_reader *,
enum file_change_code)); enum file_change_code));
/* From cpperror.c */ /* From cpperror.c */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment