cpperror.c (print_containing_files): Moved to line-map.c.
[official-gcc.git] / gcc / line-map.h
blobd5705c7561485300cdb577ae560cf2fe933fcace
1 /* Map logical line numbers to (source file, line number) pairs.
2 Copyright (C) 2001
3 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option) any
8 later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 In other words, you are welcome to use, share and improve this program.
20 You are forbidden to forbid anyone else to use, share and improve
21 what you give them. Help stamp out software-hoarding! */
23 #ifndef GCC_LINE_MAP_H
24 #define GCC_LINE_MAP_H
26 /* The logical line FROM_LINE maps to physical source file TO_FILE at
27 line TO_LINE, and subsequently one-to-one until the next line_map
28 structure in the set. INCLUDED_FROM is an index into the set that
29 gives the line mapping at whose end the current one was included.
30 File(s) at the bottom of the include stack have this set to -1. */
31 struct line_map
33 const char *to_file;
34 unsigned int to_line;
35 unsigned int from_line;
36 int included_from;
39 /* A set of chronological line_map structures. */
40 struct line_maps
42 struct line_map *maps;
43 unsigned int allocated;
44 unsigned int used;
46 /* The most recently listed include stack, if any, starts with
47 LAST_LISTED as the topmost including file. -1 indicates nothing
48 has been listed yet. */
49 int last_listed;
52 /* Reason for adding a line change with add_line_map (). LC_ENTER is
53 when including a new file, e.g. a #include directive in C.
54 LC_LEAVE is when reaching a file's end. LC_RENAME is when a file
55 name or line number changes for neither of the above reasons
56 (e.g. a #line directive in C). */
57 enum lc_reason {LC_ENTER = 0, LC_LEAVE, LC_RENAME};
59 /* Initialize a line map set. */
60 extern void init_line_maps
61 PARAMS ((struct line_maps *));
63 /* Free a line map set. */
64 extern void free_line_maps
65 PARAMS ((struct line_maps *));
67 /* Add a mapping of logical source line to physical source file and
68 line number. The text pointed to by TO_FILE must have a lifetime
69 at least as long as the final call to lookup_line ().
71 FROM_LINE should be monotonic increasing across calls to this
72 function. */
73 extern struct line_map *add_line_map
74 PARAMS ((struct line_maps *, enum lc_reason,
75 unsigned int from_line, const char *to_file, unsigned int to_line));
77 /* Given a logical line, returns the map from which the corresponding
78 (source file, line) pair can be deduced. */
79 extern struct line_map *lookup_line
80 PARAMS ((struct line_maps *, unsigned int));
82 /* Print the file names and line numbers of the #include commands
83 which led to the map MAP, if any, to stderr. Nothing is output if
84 the most recently listed stack is the same as the current one. */
85 extern void print_containing_files
86 PARAMS ((struct line_maps *, struct line_map *));
88 /* Converts a map and logical line to source line. */
89 #define SOURCE_LINE(MAP, LINE) ((LINE) + (MAP)->to_line - (MAP)->from_line)
91 /* Returns the last source line within a map. This is the (last) line
92 of the #include, or other directive, that caused a map change. */
93 #define LAST_SOURCE_LINE(MAP) SOURCE_LINE ((MAP), (MAP)[1].from_line - 1)
95 /* Returns the map a given map was included from. */
96 #define INCLUDED_FROM(SET, MAP) (&(SET)->maps[(MAP)->included_from])
98 /* Non-zero if the map is at the bottom of the include stack. */
99 #define MAIN_FILE_P(MAP) ((MAP)->included_from < 0)
101 /* The current line map. Saves a call to lookup_line if the caller is
102 sure he is in the scope of the current map. */
103 #define CURRENT_LINE_MAP(MAPS) ((MAPS)->maps + (MAPS)->used - 1)
105 #endif /* !GCC_LINE_MAP_H */