summaryrefslogtreecommitdiff
path: root/gcc/line-map.h
diff options
context:
space:
mode:
authorneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2001-08-02 23:03:31 +0000
committerneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2001-08-02 23:03:31 +0000
commit386924596ca616f5ccd2725191d07828c8c6652f (patch)
treeaedb0e3e4381261de71d4d7cee777f2ccde7880d /gcc/line-map.h
parent5aea2c55a9ec5db0a3159aa12ba14f0795b32bc1 (diff)
downloadgcc-386924596ca616f5ccd2725191d07828c8c6652f.tar.gz
* line-map.c: New.
* line-map.h: New. * Makefile.in (line-map.o): New. (LIBCPP_OBJS, LIBCPP_DEPS): Update. * c-lex.c (cb_file_change): Update for new cpp_file_change structure. * cpperror.c (print_containing_files): Similarly. (print_location): Update. Don't output a space before _Pragma. * cppfiles.c (stack_include_file): Set to line 1 immediately. (stack_include_filee, cpp_make_system_header): Update. (_cpp_execute_include): Get logical line number right for calling as-yet-unterminated #include. * cpphash.h (struct cpp_reader): Add line_maps. (_cpp_do_file_change): Update. * cppinit.c (cpp_create_reader): Initialize line maps. (cpp_destroy): Destroy line maps. (cpp_start_read): Get logical line number right. * cpplex.c (parse_string): Only warn once for multi-line strings. Use boolean variable for null warning. * cpplib.c (_cpp_handle_directive): End the directive if it isn't already. (do_include_common): End the directive early. (do_line): Don't warn about out-of-range lines in preprocessed source. Update. Remove unused variables. (_cpp_do_file_change): Update for new line mapping. (pragma_cb): New typedef. (cpp_register_pragma): Stop looking ahead before calling the handler. Clean up. (do_pragma_system_header): End directive early. (cpp_get_line_maps): New. (cpp_pop_buffer): Fudge logical line. Update. * cpplib.h: Include line-map.h (enum cpp_fc_reason): Remove. (struct cpp_file_change): Update. (cpp_get_line_maps): New. * cppmain.c (struct_printer): New member map. (cb_file_change): Update for new mappings. * fix-header.c (cb_file_change): Similarly. testsuite: * gcc.dg/cpp/19951025-1.c: Update. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@44584 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/line-map.h')
-rw-r--r--gcc/line-map.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/gcc/line-map.h b/gcc/line-map.h
new file mode 100644
index 00000000000..fe5e3cc6c9d
--- /dev/null
+++ b/gcc/line-map.h
@@ -0,0 +1,80 @@
+/* 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
+
+/* 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
+ structure in the set. */
+struct line_map
+{
+ const char *to_file;
+ unsigned int to_line;
+ unsigned int from_line;
+ int included_from;
+};
+
+/* Contains a sequence of chronological line_map structures. */
+struct line_maps
+{
+ struct line_map *maps;
+ unsigned int allocated;
+ unsigned int used;
+};
+
+/* Reason for adding a line change with add_line_map (). */
+enum lc_reason {LC_ENTER = 0, LC_LEAVE, LC_RENAME};
+
+/* 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
+ line number. Ther text pointed to by TO_FILE must have a lifetime
+ at least as long as the final call to lookup_line ().
+
+ FROM_LINE should be monotonic increasing across calls to this
+ function. */
+extern struct line_map *add_line_map
+ PARAMS ((struct line_maps *, enum lc_reason,
+ 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. */
+extern struct line_map *lookup_line
+ PARAMS ((struct line_maps *, unsigned int));
+
+/* 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. */
+#define LAST_SOURCE_LINE(MAP) SOURCE_LINE (MAP, (MAP)[1].from_line - 1)
+
+#define MAIN_FILE_P(MAP) ((MAP)->included_from < 0)
+
+#endif /* !GCC_LINE_MAP_H */