2001-08-02 19:03:31 -04:00
|
|
|
/* Map logical line numbers to (source file, line number) pairs.
|
|
|
|
Copyright (C) 2001
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
In other words, you are welcome to use, share and improve this program.
|
|
|
|
You are forbidden to forbid anyone else to use, share and improve
|
|
|
|
what you give them. Help stamp out software-hoarding! */
|
|
|
|
|
|
|
|
#ifndef GCC_LINE_MAP_H
|
|
|
|
#define GCC_LINE_MAP_H
|
|
|
|
|
2001-08-11 03:33:39 -04:00
|
|
|
/* Reason for adding a line change with add_line_map (). LC_ENTER is
|
|
|
|
when including a new file, e.g. a #include directive in C.
|
|
|
|
LC_LEAVE is when reaching a file's end. LC_RENAME is when a file
|
|
|
|
name or line number changes for neither of the above reasons
|
|
|
|
(e.g. a #line directive in C). */
|
|
|
|
enum lc_reason {LC_ENTER = 0, LC_LEAVE, LC_RENAME};
|
|
|
|
|
2001-08-02 19:03:31 -04:00
|
|
|
/* The logical line FROM_LINE maps to physical source file TO_FILE at
|
|
|
|
line TO_LINE, and subsequently one-to-one until the next line_map
|
2001-08-04 08:01:59 -04:00
|
|
|
structure in the set. INCLUDED_FROM is an index into the set that
|
|
|
|
gives the line mapping at whose end the current one was included.
|
2001-08-11 03:33:39 -04:00
|
|
|
File(s) at the bottom of the include stack have this set to -1.
|
|
|
|
REASON is the reason for creation of this line map, SYSP is one for
|
|
|
|
a system header, two for a C system header file that therefore
|
|
|
|
needs to be extern "C" protected in C++, and zero otherwise. */
|
2001-08-02 19:03:31 -04:00
|
|
|
struct line_map
|
|
|
|
{
|
|
|
|
const char *to_file;
|
|
|
|
unsigned int to_line;
|
|
|
|
unsigned int from_line;
|
|
|
|
int included_from;
|
2001-08-11 03:33:39 -04:00
|
|
|
ENUM_BITFIELD (lc_reason) reason : CHAR_BIT;
|
|
|
|
unsigned char sysp;
|
2001-08-02 19:03:31 -04:00
|
|
|
};
|
|
|
|
|
2001-08-04 08:01:59 -04:00
|
|
|
/* A set of chronological line_map structures. */
|
2001-08-02 19:03:31 -04:00
|
|
|
struct line_maps
|
|
|
|
{
|
|
|
|
struct line_map *maps;
|
|
|
|
unsigned int allocated;
|
|
|
|
unsigned int used;
|
2001-08-06 17:07:41 -04:00
|
|
|
|
|
|
|
/* The most recently listed include stack, if any, starts with
|
|
|
|
LAST_LISTED as the topmost including file. -1 indicates nothing
|
|
|
|
has been listed yet. */
|
|
|
|
int last_listed;
|
2001-08-21 17:17:48 -04:00
|
|
|
|
|
|
|
/* If true, prints an include trace a la -H. */
|
|
|
|
bool trace_includes;
|
2001-08-02 19:03:31 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Initialize a line map set. */
|
|
|
|
extern void init_line_maps
|
|
|
|
PARAMS ((struct line_maps *));
|
|
|
|
|
|
|
|
/* Free a line map set. */
|
|
|
|
extern void free_line_maps
|
|
|
|
PARAMS ((struct line_maps *));
|
|
|
|
|
|
|
|
/* Add a mapping of logical source line to physical source file and
|
2001-08-05 17:31:30 -04:00
|
|
|
line number. The text pointed to by TO_FILE must have a lifetime
|
2001-08-11 03:33:39 -04:00
|
|
|
at least as long as the line maps. If reason is LC_LEAVE, and
|
|
|
|
TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their
|
|
|
|
natural values considering the file we are returning to.
|
2001-08-02 19:03:31 -04:00
|
|
|
|
|
|
|
FROM_LINE should be monotonic increasing across calls to this
|
2001-08-07 13:55:01 -04:00
|
|
|
function. A call to this function can relocate the previous set of
|
|
|
|
maps, so any stored line_map pointers should not be used. */
|
2001-08-11 03:33:39 -04:00
|
|
|
extern const struct line_map *add_line_map
|
|
|
|
PARAMS ((struct line_maps *, enum lc_reason, unsigned int sysp,
|
2001-08-02 19:03:31 -04:00
|
|
|
unsigned int from_line, const char *to_file, unsigned int to_line));
|
|
|
|
|
|
|
|
/* Given a logical line, returns the map from which the corresponding
|
|
|
|
(source file, line) pair can be deduced. */
|
2001-08-11 03:33:39 -04:00
|
|
|
extern const struct line_map *lookup_line
|
2001-08-02 19:03:31 -04:00
|
|
|
PARAMS ((struct line_maps *, unsigned int));
|
|
|
|
|
2001-08-06 17:07:41 -04:00
|
|
|
/* Print the file names and line numbers of the #include commands
|
|
|
|
which led to the map MAP, if any, to stderr. Nothing is output if
|
|
|
|
the most recently listed stack is the same as the current one. */
|
|
|
|
extern void print_containing_files
|
2001-08-11 03:33:39 -04:00
|
|
|
PARAMS ((struct line_maps *, const struct line_map *));
|
2001-08-06 17:07:41 -04:00
|
|
|
|
2001-08-02 19:03:31 -04:00
|
|
|
/* Converts a map and logical line to source line. */
|
|
|
|
#define SOURCE_LINE(MAP, LINE) ((LINE) + (MAP)->to_line - (MAP)->from_line)
|
|
|
|
|
|
|
|
/* Returns the last source line within a map. This is the (last) line
|
|
|
|
of the #include, or other directive, that caused a map change. */
|
re PR preprocessor/3081 (Preprocessor merges 2 first lines when -imacros is being used)
PR preprocessor/3081
* c-lex.c (map): New.
(cb_file_change): Update map and use it.
(cb_def_pragma, cb_define, cb_undef): Use map and line.
(c_lex): Update to use map.
* cpperror.c (print_location): Move to using logical line numbers.
* cppfiles.c (stack_include_file): Update for new _cpp_do_file_change.
(cpp_make_system_header): Similarly.
(_cpp_execute_include): Stop line numbering hacks. Store the
line we will return to.
* cpphash.h (CPP_BUF_LINE): Remove.
(struct cpp_buffer): Remove lineno and pseudo_newlines.
Add map and return_to_line.
(_cpp_do_file_change): Update.
* cppinit.c (cpp_start_read): Update line kludge.
* cpplex.c (handle_newline): Don't update lineno and pseudo_newlines.
(trigraph_ok): Use logical line numbers for diagnostics.
(skip_block_comment): Likewise.
(skip_whitespace): Likewise.
(skip_line_comment): Use pfile->line instead.
(_cpp_lex_token): Update to use logical line numbering exclusively.
Handle BOL locally. Accept new lines in directives, but keep
pfile->line decremented. Diagnostics use logical lines. Update
directive handling.
* cpplib.c (SEEN_EOL): New.
(skip_rest_of_line, check_eol): Use it.
(end_directive): Increase line number when accepting the newline
at the end of a directive.
(run_directive): Simplify.
(do_line): Bad LC_LEAVEs become LC_RENAMEs. Update.
(_cpp_do_file_change): Update to take buffer line number as an
argument, and store the current map in the cpp_reader. Remove
line number kludges.
(_cpp_do__Pragma): Restore output position after a _Pragma.
(cpp_push_buffer): Don't set output line or lineno.
(_cpp_pop_buffer): Transfer more info from a faked buffer.
Remove line kludge. Set output_line.
* cppmacro.c (builtin_macro): Update handling of __LINE__.
(parse_arg): Use logical lines.
(save_lookahead_token): Save EOFs too now.
* cppmain.c (struct printer): Fix comments.
(printer_init): Simplify, let caller do errors.
(scan_translation_unit, check_multiline_token, dump_macro): Update.
(maybe_print_line): Simplify.
(print_line): Don't print a linemarker if -P.
(cb_define, cb_undef, cb_def_pragma, cb_ident, cb_include): Update.
(cb_file_change): Simplify.
* line-map.h (LAST_SOURCE_LINE): Fix.
(CURRENT_LINE_MAP): New.
* gcc.dg/cpp/19951025-1.c: Revert.
* gcc.dg/cpp/directiv.c: We no longer process directives that
interrupt macro arguments.
From-SVN: r44650
2001-08-05 13:31:25 -04:00
|
|
|
#define LAST_SOURCE_LINE(MAP) SOURCE_LINE ((MAP), (MAP)[1].from_line - 1)
|
2001-08-02 19:03:31 -04:00
|
|
|
|
2001-08-06 17:07:41 -04:00
|
|
|
/* Returns the map a given map was included from. */
|
|
|
|
#define INCLUDED_FROM(SET, MAP) (&(SET)->maps[(MAP)->included_from])
|
|
|
|
|
2001-08-04 08:01:59 -04:00
|
|
|
/* Non-zero if the map is at the bottom of the include stack. */
|
2001-08-02 19:03:31 -04:00
|
|
|
#define MAIN_FILE_P(MAP) ((MAP)->included_from < 0)
|
|
|
|
|
2001-08-05 17:31:30 -04:00
|
|
|
/* The current line map. Saves a call to lookup_line if the caller is
|
|
|
|
sure he is in the scope of the current map. */
|
re PR preprocessor/3081 (Preprocessor merges 2 first lines when -imacros is being used)
PR preprocessor/3081
* c-lex.c (map): New.
(cb_file_change): Update map and use it.
(cb_def_pragma, cb_define, cb_undef): Use map and line.
(c_lex): Update to use map.
* cpperror.c (print_location): Move to using logical line numbers.
* cppfiles.c (stack_include_file): Update for new _cpp_do_file_change.
(cpp_make_system_header): Similarly.
(_cpp_execute_include): Stop line numbering hacks. Store the
line we will return to.
* cpphash.h (CPP_BUF_LINE): Remove.
(struct cpp_buffer): Remove lineno and pseudo_newlines.
Add map and return_to_line.
(_cpp_do_file_change): Update.
* cppinit.c (cpp_start_read): Update line kludge.
* cpplex.c (handle_newline): Don't update lineno and pseudo_newlines.
(trigraph_ok): Use logical line numbers for diagnostics.
(skip_block_comment): Likewise.
(skip_whitespace): Likewise.
(skip_line_comment): Use pfile->line instead.
(_cpp_lex_token): Update to use logical line numbering exclusively.
Handle BOL locally. Accept new lines in directives, but keep
pfile->line decremented. Diagnostics use logical lines. Update
directive handling.
* cpplib.c (SEEN_EOL): New.
(skip_rest_of_line, check_eol): Use it.
(end_directive): Increase line number when accepting the newline
at the end of a directive.
(run_directive): Simplify.
(do_line): Bad LC_LEAVEs become LC_RENAMEs. Update.
(_cpp_do_file_change): Update to take buffer line number as an
argument, and store the current map in the cpp_reader. Remove
line number kludges.
(_cpp_do__Pragma): Restore output position after a _Pragma.
(cpp_push_buffer): Don't set output line or lineno.
(_cpp_pop_buffer): Transfer more info from a faked buffer.
Remove line kludge. Set output_line.
* cppmacro.c (builtin_macro): Update handling of __LINE__.
(parse_arg): Use logical lines.
(save_lookahead_token): Save EOFs too now.
* cppmain.c (struct printer): Fix comments.
(printer_init): Simplify, let caller do errors.
(scan_translation_unit, check_multiline_token, dump_macro): Update.
(maybe_print_line): Simplify.
(print_line): Don't print a linemarker if -P.
(cb_define, cb_undef, cb_def_pragma, cb_ident, cb_include): Update.
(cb_file_change): Simplify.
* line-map.h (LAST_SOURCE_LINE): Fix.
(CURRENT_LINE_MAP): New.
* gcc.dg/cpp/19951025-1.c: Revert.
* gcc.dg/cpp/directiv.c: We no longer process directives that
interrupt macro arguments.
From-SVN: r44650
2001-08-05 13:31:25 -04:00
|
|
|
#define CURRENT_LINE_MAP(MAPS) ((MAPS)->maps + (MAPS)->used - 1)
|
|
|
|
|
2001-08-02 19:03:31 -04:00
|
|
|
#endif /* !GCC_LINE_MAP_H */
|