OSDN Git Service

* config/xtensa/xtensa.c (function_arg): Generalize logic so that it
[pf3gnuchains/gcc-fork.git] / gcc / line-map.h
1 /* Map logical line numbers to (source file, line number) pairs.
2    Copyright (C) 2001, 2003, 2004
3    Free Software Foundation, Inc.
4
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.
9
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.
14
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.
18
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!  */
22
23 #ifndef GCC_LINE_MAP_H
24 #define GCC_LINE_MAP_H
25
26 /* Reason for adding a line change with add_line_map ().  LC_ENTER is
27    when including a new file, e.g. a #include directive in C.
28    LC_LEAVE is when reaching a file's end.  LC_RENAME is when a file
29    name or line number changes for neither of the above reasons
30    (e.g. a #line directive in C).  */
31 enum lc_reason {LC_ENTER = 0, LC_LEAVE, LC_RENAME};
32
33 /* A logical line number, i,e, an "index" into a line_map.  */
34 /* Long-term, we want to use this to replace struct location_s (in input.h),
35    and effectively typedef source_location location_t.  */
36 typedef unsigned int source_location;
37 typedef source_location fileline; /* deprecated name */
38
39 /* The logical line FROM_LINE maps to physical source file TO_FILE at
40    line TO_LINE, and subsequently one-to-one until the next line_map
41    structure in the set.  INCLUDED_FROM is an index into the set that
42    gives the line mapping at whose end the current one was included.
43    File(s) at the bottom of the include stack have this set to -1.
44    REASON is the reason for creation of this line map, SYSP is one for
45    a system header, two for a C system header file that therefore
46    needs to be extern "C" protected in C++, and zero otherwise.  */
47 struct line_map
48 {
49   const char *to_file;
50   unsigned int to_line;
51   source_location from_line;
52   int included_from;
53   ENUM_BITFIELD (lc_reason) reason : CHAR_BIT;
54   unsigned char sysp;
55 };
56
57 /* A set of chronological line_map structures.  */
58 struct line_maps
59 {
60   struct line_map *maps;
61   unsigned int allocated;
62   unsigned int used;
63
64   unsigned int cache;
65
66   /* The most recently listed include stack, if any, starts with
67      LAST_LISTED as the topmost including file.  -1 indicates nothing
68      has been listed yet.  */
69   int last_listed;
70
71   /* Depth of the include stack, including the current file.  */
72   unsigned int depth;
73
74   /* If true, prints an include trace a la -H.  */
75   bool trace_includes;
76 };
77
78 /* Initialize a line map set.  */
79 extern void linemap_init (struct line_maps *);
80
81 /* Free a line map set.  */
82 extern void linemap_free (struct line_maps *);
83
84 /* Add a mapping of logical source line to physical source file and
85    line number.
86
87    The text pointed to by TO_FILE must have a lifetime
88    at least as long as the final call to lookup_line ().  An empty
89    TO_FILE means standard input.  If reason is LC_LEAVE, and
90    TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their
91    natural values considering the file we are returning to.
92
93    FROM_LINE should be monotonic increasing across calls to this
94    function.  A call to this function can relocate the previous set of
95    maps, so any stored line_map pointers should not be used.  */
96 extern const struct line_map *linemap_add
97   (struct line_maps *, enum lc_reason, unsigned int sysp,
98    source_location from_line, const char *to_file, unsigned int to_line);
99
100 /* Given a logical line, returns the map from which the corresponding
101    (source file, line) pair can be deduced.  */
102 extern const struct line_map *linemap_lookup
103   (struct line_maps *, source_location);
104
105 /* Print the file names and line numbers of the #include commands
106    which led to the map MAP, if any, to stderr.  Nothing is output if
107    the most recently listed stack is the same as the current one.  */
108 extern void linemap_print_containing_files (struct line_maps *,
109                                             const struct line_map *);
110
111 /* Converts a map and logical line to source line.  */
112 #define SOURCE_LINE(MAP, LINE) ((LINE) + (MAP)->to_line - (MAP)->from_line)
113
114 /* Returns the last source line within a map.  This is the (last) line
115    of the #include, or other directive, that caused a map change.  */
116 #define LAST_SOURCE_LINE(MAP) SOURCE_LINE ((MAP), (MAP)[1].from_line - 1)
117
118 /* Returns the map a given map was included from.  */
119 #define INCLUDED_FROM(SET, MAP) (&(SET)->maps[(MAP)->included_from])
120
121 /* Nonzero if the map is at the bottom of the include stack.  */
122 #define MAIN_FILE_P(MAP) ((MAP)->included_from < 0)
123
124 /* The current line map.  Saves a call to lookup_line if the caller is
125    sure he is in the scope of the current map.  */
126 #define CURRENT_LINE_MAP(MAPS) ((MAPS)->maps + (MAPS)->used - 1)
127
128 #endif /* !GCC_LINE_MAP_H  */