Commit 42dcba34 by Neil Booth Committed by Neil Booth

cpplib.h, line-map.h: Update comments.

	* cpplib.h, line-map.h: Update comments.
	* cppmain.c (printer_init): Move inline.
	(maybe_print_line, print_line): Take a map pointer.
	(cb_ident, cb_define, cb_undef, cb_include, cb_def_pragma): Update.
	(cb_file_change): Don't use prior value of print.map.

From-SVN: r44697
parent e8515283
2001-08-07 Neil Booth <neil@daikokuya.demon.co.uk>
* cpplib.h, line-map.h: Update comments.
* cppmain.c (printer_init): Move inline.
(maybe_print_line, print_line): Take a map pointer.
(cb_ident, cb_define, cb_undef, cb_include, cb_def_pragma): Update.
(cb_file_change): Don't use prior value of print.map.
2001-08-07 David Edelsohn <edelsohn@gnu.org> 2001-08-07 David Edelsohn <edelsohn@gnu.org>
* doc/install.texi: Document fine-grained multilib configuration. * doc/install.texi: Document fine-grained multilib configuration.
......
...@@ -390,7 +390,7 @@ struct cpp_options ...@@ -390,7 +390,7 @@ struct cpp_options
typedef struct cpp_file_change cpp_file_change; typedef struct cpp_file_change cpp_file_change;
struct cpp_file_change struct cpp_file_change
{ {
struct line_map *map; /* Line map to use until next callback. */ struct line_map *map; /* Line map, valid until next callback. */
unsigned int line; /* Logical line number of next line. */ unsigned int line; /* Logical line number of next line. */
enum lc_reason reason; /* Reason for change. */ enum lc_reason reason; /* Reason for change. */
unsigned char sysp; /* Nonzero if system header. */ unsigned char sysp; /* Nonzero if system header. */
......
...@@ -32,9 +32,9 @@ struct printer ...@@ -32,9 +32,9 @@ struct printer
{ {
FILE *outf; /* Stream to write to. */ FILE *outf; /* Stream to write to. */
const char *syshdr_flags; /* System header flags, if any. */ const char *syshdr_flags; /* System header flags, if any. */
struct line_map *map; /* Logical to physical line mappings. */
unsigned int line; /* Line currently being written. */ unsigned int line; /* Line currently being written. */
unsigned char printed; /* Nonzero if something output at line. */ unsigned char printed; /* Nonzero if something output at line. */
struct line_map *map; /* Logical to physical line mappings. */
}; };
int main PARAMS ((int, char **)); int main PARAMS ((int, char **));
...@@ -45,11 +45,11 @@ static void setup_callbacks PARAMS ((void)); ...@@ -45,11 +45,11 @@ static void setup_callbacks PARAMS ((void));
/* General output routines. */ /* General output routines. */
static void scan_translation_unit PARAMS ((cpp_reader *)); static void scan_translation_unit PARAMS ((cpp_reader *));
static void check_multiline_token PARAMS ((cpp_string *)); static void check_multiline_token PARAMS ((cpp_string *));
static void printer_init PARAMS ((void));
static int dump_macro PARAMS ((cpp_reader *, cpp_hashnode *, void *)); static int dump_macro PARAMS ((cpp_reader *, cpp_hashnode *, void *));
static void print_line PARAMS ((unsigned int, const char *)); static void print_line PARAMS ((struct line_map *, unsigned int,
static void maybe_print_line PARAMS ((unsigned int)); const char *));
static void maybe_print_line PARAMS ((struct line_map *, unsigned int));
/* Callback routines for the parser. Most of these are active only /* Callback routines for the parser. Most of these are active only
in specific modes. */ in specific modes. */
...@@ -139,14 +139,26 @@ do_preprocessing (argc, argv) ...@@ -139,14 +139,26 @@ do_preprocessing (argc, argv)
if (options->help_only) if (options->help_only)
return; return;
/* Initialize the printer structure. Setting print.line to -1 here
is a trick to guarantee that the first token of the file will
cause a linemarker to be output by maybe_print_line. */
print.line = (unsigned int) -1;
print.printed = 0;
print.map = 0;
/* Open the output now. We must do so even if no_output is on, /* Open the output now. We must do so even if no_output is on,
because there may be other output than from the actual because there may be other output than from the actual
preprocessing (e.g. from -dM). */ preprocessing (e.g. from -dM). */
printer_init (); if (options->out_fname[0] == '\0')
if (print.outf == NULL) print.outf = stdout;
else
{ {
cpp_notice_from_errno (pfile, options->out_fname); print.outf = fopen (options->out_fname, "w");
return; if (print.outf == NULL)
{
cpp_notice_from_errno (pfile, options->out_fname);
return;
}
} }
setup_callbacks (); setup_callbacks ();
...@@ -226,7 +238,7 @@ scan_translation_unit (pfile) ...@@ -226,7 +238,7 @@ scan_translation_unit (pfile)
column. Don't bother trying to reconstruct tabs; we can't column. Don't bother trying to reconstruct tabs; we can't
get it right in general, and nothing ought to care. (Yes, get it right in general, and nothing ought to care. (Yes,
some things do care; the fault lies with them.) */ some things do care; the fault lies with them.) */
maybe_print_line (line); maybe_print_line (print.map, line);
if (col > 1) if (col > 1)
{ {
if (token->flags & PREV_WHITE) if (token->flags & PREV_WHITE)
...@@ -267,29 +279,13 @@ check_multiline_token (str) ...@@ -267,29 +279,13 @@ check_multiline_token (str)
print.line++; print.line++;
} }
/* Initialize a cpp_printer structure. As a side effect, open the
output file. If print.outf is NULL an error occurred. */
static void
printer_init ()
{
/* Setting print.line to -1 here guarantees that the first token of
the file will cause a linemarker to be output by maybe_print_line. */
print.line = (unsigned int) -1;
print.printed = 0;
print.map = 0;
if (options->out_fname[0] == '\0')
print.outf = stdout;
else
print.outf = fopen (options->out_fname, "w");
}
/* If the token read on logical line LINE needs to be output on a /* If the token read on logical line LINE needs to be output on a
different line to the current one, output the required newlines or different line to the current one, output the required newlines or
a line marker, and return 1. Otherwise return 0. */ a line marker, and return 1. Otherwise return 0. */
static void static void
maybe_print_line (line) maybe_print_line (map, line)
struct line_map *map;
unsigned int line; unsigned int line;
{ {
/* End the previous line of text. */ /* End the previous line of text. */
...@@ -309,11 +305,12 @@ maybe_print_line (line) ...@@ -309,11 +305,12 @@ maybe_print_line (line)
} }
} }
else else
print_line (line, ""); print_line (map, line, "");
} }
static void static void
print_line (line, special_flags) print_line (map, line, special_flags)
struct line_map *map;
unsigned int line; unsigned int line;
const char *special_flags; const char *special_flags;
{ {
...@@ -325,8 +322,8 @@ print_line (line, special_flags) ...@@ -325,8 +322,8 @@ print_line (line, special_flags)
print.line = line; print.line = line;
if (! options->no_line_commands) if (! options->no_line_commands)
fprintf (print.outf, "# %u \"%s\"%s%s\n", fprintf (print.outf, "# %u \"%s\"%s%s\n",
SOURCE_LINE (print.map, print.line), SOURCE_LINE (map, print.line), map->to_file,
print.map->to_file, special_flags, print.syshdr_flags); special_flags, print.syshdr_flags);
} }
/* Callbacks. */ /* Callbacks. */
...@@ -337,7 +334,7 @@ cb_ident (pfile, line, str) ...@@ -337,7 +334,7 @@ cb_ident (pfile, line, str)
unsigned int line; unsigned int line;
const cpp_string * str; const cpp_string * str;
{ {
maybe_print_line (line); maybe_print_line (print.map, line);
fprintf (print.outf, "#ident \"%s\"\n", str->text); fprintf (print.outf, "#ident \"%s\"\n", str->text);
print.line++; print.line++;
} }
...@@ -348,7 +345,7 @@ cb_define (pfile, line, node) ...@@ -348,7 +345,7 @@ cb_define (pfile, line, node)
unsigned int line; unsigned int line;
cpp_hashnode *node; cpp_hashnode *node;
{ {
maybe_print_line (line); maybe_print_line (print.map, line);
fputs ("#define ", print.outf); fputs ("#define ", print.outf);
/* -dD command line option. */ /* -dD command line option. */
...@@ -367,7 +364,7 @@ cb_undef (pfile, line, node) ...@@ -367,7 +364,7 @@ cb_undef (pfile, line, node)
unsigned int line; unsigned int line;
cpp_hashnode *node; cpp_hashnode *node;
{ {
maybe_print_line (line); maybe_print_line (print.map, line);
fprintf (print.outf, "#undef %s\n", NODE_NAME (node)); fprintf (print.outf, "#undef %s\n", NODE_NAME (node));
print.line++; print.line++;
} }
...@@ -379,11 +376,14 @@ cb_include (pfile, line, dir, header) ...@@ -379,11 +376,14 @@ cb_include (pfile, line, dir, header)
const unsigned char *dir; const unsigned char *dir;
const cpp_token *header; const cpp_token *header;
{ {
maybe_print_line (line); maybe_print_line (print.map, line);
fprintf (print.outf, "#%s %s\n", dir, cpp_token_as_text (pfile, header)); fprintf (print.outf, "#%s %s\n", dir, cpp_token_as_text (pfile, header));
print.line++; print.line++;
} }
/* The file name, line number or system header flags have changed, as
described in FC. NB: the old print.map must be considered invalid. */
static void static void
cb_file_change (pfile, fc) cb_file_change (pfile, fc)
cpp_reader *pfile ATTRIBUTE_UNUSED; cpp_reader *pfile ATTRIBUTE_UNUSED;
...@@ -395,7 +395,7 @@ cb_file_change (pfile, fc) ...@@ -395,7 +395,7 @@ cb_file_change (pfile, fc)
change callback specially, so that a first line of "# 1 "foo.c" change callback specially, so that a first line of "# 1 "foo.c"
in file foo.i outputs just the foo.c line, and not a foo.i line. */ in file foo.i outputs just the foo.c line, and not a foo.i line. */
if (fc->reason == LC_ENTER && !first_time) if (fc->reason == LC_ENTER && !first_time)
maybe_print_line (fc->line - 1); maybe_print_line (fc->map - 1, fc->line - 1);
print.map = fc->map; print.map = fc->map;
if (fc->externc) if (fc->externc)
...@@ -414,7 +414,7 @@ cb_file_change (pfile, fc) ...@@ -414,7 +414,7 @@ cb_file_change (pfile, fc)
else if (fc->reason == LC_LEAVE) else if (fc->reason == LC_LEAVE)
flags = " 2"; flags = " 2";
print_line (fc->line, flags); print_line (print.map, fc->line, flags);
} }
} }
...@@ -425,7 +425,7 @@ cb_def_pragma (pfile, line) ...@@ -425,7 +425,7 @@ cb_def_pragma (pfile, line)
cpp_reader *pfile; cpp_reader *pfile;
unsigned int line; unsigned int line;
{ {
maybe_print_line (line); maybe_print_line (print.map, line);
fputs ("#pragma ", print.outf); fputs ("#pragma ", print.outf);
cpp_output_line (pfile, print.outf); cpp_output_line (pfile, print.outf);
print.line++; print.line++;
......
...@@ -69,7 +69,8 @@ extern void free_line_maps ...@@ -69,7 +69,8 @@ extern void free_line_maps
at least as long as the final call to lookup_line (). at least as long as the final call to lookup_line ().
FROM_LINE should be monotonic increasing across calls to this FROM_LINE should be monotonic increasing across calls to this
function. */ function. A call to this function can relocate the previous set of
maps, so any stored line_map pointers should not be used. */
extern struct line_map *add_line_map extern struct line_map *add_line_map
PARAMS ((struct line_maps *, enum lc_reason, PARAMS ((struct line_maps *, enum lc_reason,
unsigned int from_line, const char *to_file, unsigned int to_line)); unsigned int from_line, const char *to_file, unsigned int to_line));
......
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