annotate libcpp/include/line-map.h @ 120:f93fa5091070

fix conv1.c
author mir3636
date Thu, 08 Mar 2018 14:53:42 +0900
parents 04ced10e8804
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents: 67
diff changeset
1 /* Map (unsigned int) keys to (source file, line, column) triples.
kono
parents: 67
diff changeset
2 Copyright (C) 2001-2017 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify it
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 under the terms of the GNU General Public License as published by the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 Free Software Foundation; either version 3, or (at your option) any
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 later version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 GNU General Public License for more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 along with this program; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 <http://www.gnu.org/licenses/>.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 In other words, you are welcome to use, share and improve this program.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 You are forbidden to forbid anyone else to use, share and improve
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 what you give them. Help stamp out software-hoarding! */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #ifndef LIBCPP_LINE_MAP_H
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 #define LIBCPP_LINE_MAP_H
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 #ifndef GTY
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 #define GTY(x) /* nothing */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
111
kono
parents: 67
diff changeset
29 /* Reason for creating a new line map with linemap_add. LC_ENTER is
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 when including a new file, e.g. a #include directive in C.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 LC_LEAVE is when reaching a file's end. LC_RENAME is when a file
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 name or line number changes for neither of the above reasons
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
33 (e.g. a #line directive in C); LC_RENAME_VERBATIM is like LC_RENAME
111
kono
parents: 67
diff changeset
34 but a filename of "" is not specially interpreted as standard
kono
parents: 67
diff changeset
35 input. LC_ENTER_MACRO is when a macro expansion is about to start. */
kono
parents: 67
diff changeset
36 enum lc_reason
kono
parents: 67
diff changeset
37 {
kono
parents: 67
diff changeset
38 LC_ENTER = 0,
kono
parents: 67
diff changeset
39 LC_LEAVE,
kono
parents: 67
diff changeset
40 LC_RENAME,
kono
parents: 67
diff changeset
41 LC_RENAME_VERBATIM,
kono
parents: 67
diff changeset
42 LC_ENTER_MACRO
kono
parents: 67
diff changeset
43 /* FIXME: add support for stringize and paste. */
kono
parents: 67
diff changeset
44 };
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 /* The type of line numbers. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 typedef unsigned int linenum_type;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48
111
kono
parents: 67
diff changeset
49 /* The typedef "source_location" is a key within the location database,
kono
parents: 67
diff changeset
50 identifying a source location or macro expansion, along with range
kono
parents: 67
diff changeset
51 information, and (optionally) a pointer for use by gcc.
kono
parents: 67
diff changeset
52
kono
parents: 67
diff changeset
53 This key only has meaning in relation to a line_maps instance. Within
kono
parents: 67
diff changeset
54 gcc there is a single line_maps instance: "line_table", declared in
kono
parents: 67
diff changeset
55 gcc/input.h and defined in gcc/input.c.
kono
parents: 67
diff changeset
56
kono
parents: 67
diff changeset
57 The values of the keys are intended to be internal to libcpp,
kono
parents: 67
diff changeset
58 but for ease-of-understanding the implementation, they are currently
kono
parents: 67
diff changeset
59 assigned as follows:
kono
parents: 67
diff changeset
60
kono
parents: 67
diff changeset
61 Actual | Value | Meaning
kono
parents: 67
diff changeset
62 -----------+-------------------------------+-------------------------------
kono
parents: 67
diff changeset
63 0x00000000 | UNKNOWN_LOCATION (gcc/input.h)| Unknown/invalid location.
kono
parents: 67
diff changeset
64 -----------+-------------------------------+-------------------------------
kono
parents: 67
diff changeset
65 0x00000001 | BUILTINS_LOCATION | The location for declarations
kono
parents: 67
diff changeset
66 | (gcc/input.h) | in "<built-in>"
kono
parents: 67
diff changeset
67 -----------+-------------------------------+-------------------------------
kono
parents: 67
diff changeset
68 0x00000002 | RESERVED_LOCATION_COUNT | The first location to be
kono
parents: 67
diff changeset
69 | (also | handed out, and the
kono
parents: 67
diff changeset
70 | ordmap[0]->start_location) | first line in ordmap 0
kono
parents: 67
diff changeset
71 -----------+-------------------------------+-------------------------------
kono
parents: 67
diff changeset
72 | ordmap[1]->start_location | First line in ordmap 1
kono
parents: 67
diff changeset
73 | ordmap[1]->start_location+32 | First column in that line
kono
parents: 67
diff changeset
74 | (assuming range_bits == 5) |
kono
parents: 67
diff changeset
75 | ordmap[1]->start_location+64 | 2nd column in that line
kono
parents: 67
diff changeset
76 | ordmap[1]->start_location+4096| Second line in ordmap 1
kono
parents: 67
diff changeset
77 | (assuming column_bits == 12)
kono
parents: 67
diff changeset
78 |
kono
parents: 67
diff changeset
79 | Subsequent lines are offset by (1 << column_bits),
kono
parents: 67
diff changeset
80 | e.g. 4096 for 12 bits, with a column value of 0 representing
kono
parents: 67
diff changeset
81 | "the whole line".
kono
parents: 67
diff changeset
82 |
kono
parents: 67
diff changeset
83 | Within a line, the low "range_bits" (typically 5) are used for
kono
parents: 67
diff changeset
84 | storing short ranges, so that there's an offset of
kono
parents: 67
diff changeset
85 | (1 << range_bits) between individual columns within a line,
kono
parents: 67
diff changeset
86 | typically 32.
kono
parents: 67
diff changeset
87 | The low range_bits store the offset of the end point from the
kono
parents: 67
diff changeset
88 | start point, and the start point is found by masking away
kono
parents: 67
diff changeset
89 | the range bits.
kono
parents: 67
diff changeset
90 |
kono
parents: 67
diff changeset
91 | For example:
kono
parents: 67
diff changeset
92 | ordmap[1]->start_location+64 "2nd column in that line"
kono
parents: 67
diff changeset
93 | above means a caret at that location, with a range
kono
parents: 67
diff changeset
94 | starting and finishing at the same place (the range bits
kono
parents: 67
diff changeset
95 | are 0), a range of length 1.
kono
parents: 67
diff changeset
96 |
kono
parents: 67
diff changeset
97 | By contrast:
kono
parents: 67
diff changeset
98 | ordmap[1]->start_location+68
kono
parents: 67
diff changeset
99 | has range bits 0x4, meaning a caret with a range starting at
kono
parents: 67
diff changeset
100 | that location, but with endpoint 4 columns further on: a range
kono
parents: 67
diff changeset
101 | of length 5.
kono
parents: 67
diff changeset
102 |
kono
parents: 67
diff changeset
103 | Ranges that have caret != start, or have an endpoint too
kono
parents: 67
diff changeset
104 | far away to fit in range_bits are instead stored as ad-hoc
kono
parents: 67
diff changeset
105 | locations. Hence for range_bits == 5 we can compactly store
kono
parents: 67
diff changeset
106 | tokens of length <= 32 without needing to use the ad-hoc
kono
parents: 67
diff changeset
107 | table.
kono
parents: 67
diff changeset
108 |
kono
parents: 67
diff changeset
109 | This packing scheme means we effectively have
kono
parents: 67
diff changeset
110 | (column_bits - range_bits)
kono
parents: 67
diff changeset
111 | of bits for the columns, typically (12 - 5) = 7, for 128
kono
parents: 67
diff changeset
112 | columns; longer line widths are accomodated by starting a
kono
parents: 67
diff changeset
113 | new ordmap with a higher column_bits.
kono
parents: 67
diff changeset
114 |
kono
parents: 67
diff changeset
115 | ordmap[2]->start_location-1 | Final location in ordmap 1
kono
parents: 67
diff changeset
116 -----------+-------------------------------+-------------------------------
kono
parents: 67
diff changeset
117 | ordmap[2]->start_location | First line in ordmap 2
kono
parents: 67
diff changeset
118 | ordmap[3]->start_location-1 | Final location in ordmap 2
kono
parents: 67
diff changeset
119 -----------+-------------------------------+-------------------------------
kono
parents: 67
diff changeset
120 | | (etc)
kono
parents: 67
diff changeset
121 -----------+-------------------------------+-------------------------------
kono
parents: 67
diff changeset
122 | ordmap[n-1]->start_location | First line in final ord map
kono
parents: 67
diff changeset
123 | | (etc)
kono
parents: 67
diff changeset
124 | set->highest_location - 1 | Final location in that ordmap
kono
parents: 67
diff changeset
125 -----------+-------------------------------+-------------------------------
kono
parents: 67
diff changeset
126 | set->highest_location | Location of the where the next
kono
parents: 67
diff changeset
127 | | ordinary linemap would start
kono
parents: 67
diff changeset
128 -----------+-------------------------------+-------------------------------
kono
parents: 67
diff changeset
129 | |
kono
parents: 67
diff changeset
130 | VVVVVVVVVVVVVVVVVVVVVVVVVVV
kono
parents: 67
diff changeset
131 | Ordinary maps grow this way
kono
parents: 67
diff changeset
132 |
kono
parents: 67
diff changeset
133 | (unallocated integers)
kono
parents: 67
diff changeset
134 |
kono
parents: 67
diff changeset
135 0x60000000 | LINE_MAP_MAX_LOCATION_WITH_COLS
kono
parents: 67
diff changeset
136 | Beyond this point, ordinary linemaps have 0 bits per column:
kono
parents: 67
diff changeset
137 | each increment of the value corresponds to a new source line.
kono
parents: 67
diff changeset
138 |
kono
parents: 67
diff changeset
139 0x70000000 | LINE_MAP_MAX_SOURCE_LOCATION
kono
parents: 67
diff changeset
140 | Beyond the point, we give up on ordinary maps; attempts to
kono
parents: 67
diff changeset
141 | create locations in them lead to UNKNOWN_LOCATION (0).
kono
parents: 67
diff changeset
142 |
kono
parents: 67
diff changeset
143 | (unallocated integers)
kono
parents: 67
diff changeset
144 |
kono
parents: 67
diff changeset
145 | Macro maps grow this way
kono
parents: 67
diff changeset
146 | ^^^^^^^^^^^^^^^^^^^^^^^^
kono
parents: 67
diff changeset
147 | |
kono
parents: 67
diff changeset
148 -----------+-------------------------------+-------------------------------
kono
parents: 67
diff changeset
149 | LINEMAPS_MACRO_LOWEST_LOCATION| Locations within macro maps
kono
parents: 67
diff changeset
150 | macromap[m-1]->start_location | Start of last macro map
kono
parents: 67
diff changeset
151 | |
kono
parents: 67
diff changeset
152 -----------+-------------------------------+-------------------------------
kono
parents: 67
diff changeset
153 | macromap[m-2]->start_location | Start of penultimate macro map
kono
parents: 67
diff changeset
154 -----------+-------------------------------+-------------------------------
kono
parents: 67
diff changeset
155 | macromap[1]->start_location | Start of macro map 1
kono
parents: 67
diff changeset
156 -----------+-------------------------------+-------------------------------
kono
parents: 67
diff changeset
157 | macromap[0]->start_location | Start of macro map 0
kono
parents: 67
diff changeset
158 0x7fffffff | MAX_SOURCE_LOCATION | Also used as a mask for
kono
parents: 67
diff changeset
159 | | accessing the ad-hoc data table
kono
parents: 67
diff changeset
160 -----------+-------------------------------+-------------------------------
kono
parents: 67
diff changeset
161 0x80000000 | Start of ad-hoc values; the lower 31 bits are used as an index
kono
parents: 67
diff changeset
162 ... | into the line_table->location_adhoc_data_map.data array.
kono
parents: 67
diff changeset
163 0xffffffff | UINT_MAX |
kono
parents: 67
diff changeset
164 -----------+-------------------------------+-------------------------------
kono
parents: 67
diff changeset
165
kono
parents: 67
diff changeset
166 Examples of location encoding.
kono
parents: 67
diff changeset
167
kono
parents: 67
diff changeset
168 Packed ranges
kono
parents: 67
diff changeset
169 =============
kono
parents: 67
diff changeset
170
kono
parents: 67
diff changeset
171 Consider encoding the location of a token "foo", seen underlined here
kono
parents: 67
diff changeset
172 on line 523, within an ordinary line_map that starts at line 500:
kono
parents: 67
diff changeset
173
kono
parents: 67
diff changeset
174 11111111112
kono
parents: 67
diff changeset
175 12345678901234567890
kono
parents: 67
diff changeset
176 522
kono
parents: 67
diff changeset
177 523 return foo + bar;
kono
parents: 67
diff changeset
178 ^~~
kono
parents: 67
diff changeset
179 524
kono
parents: 67
diff changeset
180
kono
parents: 67
diff changeset
181 The location's caret and start are both at line 523, column 11; the
kono
parents: 67
diff changeset
182 location's finish is on the same line, at column 13 (an offset of 2
kono
parents: 67
diff changeset
183 columns, for length 3).
kono
parents: 67
diff changeset
184
kono
parents: 67
diff changeset
185 Line 523 is offset 23 from the starting line of the ordinary line_map.
kono
parents: 67
diff changeset
186
kono
parents: 67
diff changeset
187 caret == start, and the offset of the finish fits within 5 bits, so
kono
parents: 67
diff changeset
188 this can be stored as a packed range.
kono
parents: 67
diff changeset
189
kono
parents: 67
diff changeset
190 This is encoded as:
kono
parents: 67
diff changeset
191 ordmap->start
kono
parents: 67
diff changeset
192 + (line_offset << ordmap->m_column_and_range_bits)
kono
parents: 67
diff changeset
193 + (column << ordmap->m_range_bits)
kono
parents: 67
diff changeset
194 + (range_offset);
kono
parents: 67
diff changeset
195 i.e. (for line offset 23, column 11, range offset 2):
kono
parents: 67
diff changeset
196 ordmap->start
kono
parents: 67
diff changeset
197 + (23 << 12)
kono
parents: 67
diff changeset
198 + (11 << 5)
kono
parents: 67
diff changeset
199 + 2;
kono
parents: 67
diff changeset
200 i.e.:
kono
parents: 67
diff changeset
201 ordmap->start + 0x17162
kono
parents: 67
diff changeset
202 assuming that the line_map uses the default of 7 bits for columns and
kono
parents: 67
diff changeset
203 5 bits for packed range (giving 12 bits for m_column_and_range_bits).
kono
parents: 67
diff changeset
204
kono
parents: 67
diff changeset
205
kono
parents: 67
diff changeset
206 "Pure" locations
kono
parents: 67
diff changeset
207 ================
kono
parents: 67
diff changeset
208
kono
parents: 67
diff changeset
209 These are a special case of the above, where
kono
parents: 67
diff changeset
210 caret == start == finish
kono
parents: 67
diff changeset
211 They are stored as packed ranges with offset == 0.
kono
parents: 67
diff changeset
212 For example, the location of the "f" of "foo" could be stored
kono
parents: 67
diff changeset
213 as above, but with range offset 0, giving:
kono
parents: 67
diff changeset
214 ordmap->start
kono
parents: 67
diff changeset
215 + (23 << 12)
kono
parents: 67
diff changeset
216 + (11 << 5)
kono
parents: 67
diff changeset
217 + 0;
kono
parents: 67
diff changeset
218 i.e.:
kono
parents: 67
diff changeset
219 ordmap->start + 0x17160
kono
parents: 67
diff changeset
220
kono
parents: 67
diff changeset
221
kono
parents: 67
diff changeset
222 Unoptimized ranges
kono
parents: 67
diff changeset
223 ==================
kono
parents: 67
diff changeset
224
kono
parents: 67
diff changeset
225 Consider encoding the location of the binary expression
kono
parents: 67
diff changeset
226 below:
kono
parents: 67
diff changeset
227
kono
parents: 67
diff changeset
228 11111111112
kono
parents: 67
diff changeset
229 12345678901234567890
kono
parents: 67
diff changeset
230 522
kono
parents: 67
diff changeset
231 523 return foo + bar;
kono
parents: 67
diff changeset
232 ~~~~^~~~~
kono
parents: 67
diff changeset
233 524
kono
parents: 67
diff changeset
234
kono
parents: 67
diff changeset
235 The location's caret is at the "+", line 523 column 15, but starts
kono
parents: 67
diff changeset
236 earlier, at the "f" of "foo" at column 11. The finish is at the "r"
kono
parents: 67
diff changeset
237 of "bar" at column 19.
kono
parents: 67
diff changeset
238
kono
parents: 67
diff changeset
239 This can't be stored as a packed range since start != caret.
kono
parents: 67
diff changeset
240 Hence it is stored as an ad-hoc location e.g. 0x80000003.
kono
parents: 67
diff changeset
241
kono
parents: 67
diff changeset
242 Stripping off the top bit gives us an index into the ad-hoc
kono
parents: 67
diff changeset
243 lookaside table:
kono
parents: 67
diff changeset
244
kono
parents: 67
diff changeset
245 line_table->location_adhoc_data_map.data[0x3]
kono
parents: 67
diff changeset
246
kono
parents: 67
diff changeset
247 from which the caret, start and finish can be looked up,
kono
parents: 67
diff changeset
248 encoded as "pure" locations:
kono
parents: 67
diff changeset
249
kono
parents: 67
diff changeset
250 start == ordmap->start + (23 << 12) + (11 << 5)
kono
parents: 67
diff changeset
251 == ordmap->start + 0x17160 (as above; the "f" of "foo")
kono
parents: 67
diff changeset
252
kono
parents: 67
diff changeset
253 caret == ordmap->start + (23 << 12) + (15 << 5)
kono
parents: 67
diff changeset
254 == ordmap->start + 0x171e0
kono
parents: 67
diff changeset
255
kono
parents: 67
diff changeset
256 finish == ordmap->start + (23 << 12) + (19 << 5)
kono
parents: 67
diff changeset
257 == ordmap->start + 0x17260
kono
parents: 67
diff changeset
258
kono
parents: 67
diff changeset
259 To further see how source_location works in practice, see the
kono
parents: 67
diff changeset
260 worked example in libcpp/location-example.txt. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 typedef unsigned int source_location;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
262
111
kono
parents: 67
diff changeset
263 /* Do not pack ranges if locations get higher than this.
kono
parents: 67
diff changeset
264 If you change this, update:
kono
parents: 67
diff changeset
265 gcc.dg/plugin/location-overflow-test-*.c. */
kono
parents: 67
diff changeset
266 const source_location LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES = 0x50000000;
kono
parents: 67
diff changeset
267
kono
parents: 67
diff changeset
268 /* Do not track column numbers if locations get higher than this.
kono
parents: 67
diff changeset
269 If you change this, update:
kono
parents: 67
diff changeset
270 gcc.dg/plugin/location-overflow-test-*.c. */
kono
parents: 67
diff changeset
271 const source_location LINE_MAP_MAX_LOCATION_WITH_COLS = 0x60000000;
kono
parents: 67
diff changeset
272
kono
parents: 67
diff changeset
273 /* A range of source locations.
kono
parents: 67
diff changeset
274
kono
parents: 67
diff changeset
275 Ranges are closed:
kono
parents: 67
diff changeset
276 m_start is the first location within the range,
kono
parents: 67
diff changeset
277 m_finish is the last location within the range.
kono
parents: 67
diff changeset
278
kono
parents: 67
diff changeset
279 We may need a more compact way to store these, but for now,
kono
parents: 67
diff changeset
280 let's do it the simple way, as a pair. */
kono
parents: 67
diff changeset
281 struct GTY(()) source_range
kono
parents: 67
diff changeset
282 {
kono
parents: 67
diff changeset
283 source_location m_start;
kono
parents: 67
diff changeset
284 source_location m_finish;
kono
parents: 67
diff changeset
285
kono
parents: 67
diff changeset
286 /* We avoid using constructors, since various structs that
kono
parents: 67
diff changeset
287 don't yet have constructors will embed instances of
kono
parents: 67
diff changeset
288 source_range. */
kono
parents: 67
diff changeset
289
kono
parents: 67
diff changeset
290 /* Make a source_range from a source_location. */
kono
parents: 67
diff changeset
291 static source_range from_location (source_location loc)
kono
parents: 67
diff changeset
292 {
kono
parents: 67
diff changeset
293 source_range result;
kono
parents: 67
diff changeset
294 result.m_start = loc;
kono
parents: 67
diff changeset
295 result.m_finish = loc;
kono
parents: 67
diff changeset
296 return result;
kono
parents: 67
diff changeset
297 }
kono
parents: 67
diff changeset
298
kono
parents: 67
diff changeset
299 /* Make a source_range from a pair of source_location. */
kono
parents: 67
diff changeset
300 static source_range from_locations (source_location start,
kono
parents: 67
diff changeset
301 source_location finish)
kono
parents: 67
diff changeset
302 {
kono
parents: 67
diff changeset
303 source_range result;
kono
parents: 67
diff changeset
304 result.m_start = start;
kono
parents: 67
diff changeset
305 result.m_finish = finish;
kono
parents: 67
diff changeset
306 return result;
kono
parents: 67
diff changeset
307 }
kono
parents: 67
diff changeset
308 };
kono
parents: 67
diff changeset
309
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 /* Memory allocation function typedef. Works like xrealloc. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 typedef void *(*line_map_realloc) (void *, size_t);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
312
111
kono
parents: 67
diff changeset
313 /* Memory allocator function that returns the actual allocated size,
kono
parents: 67
diff changeset
314 for a given requested allocation. */
kono
parents: 67
diff changeset
315 typedef size_t (*line_map_round_alloc_size_func) (size_t);
kono
parents: 67
diff changeset
316
kono
parents: 67
diff changeset
317 /* A line_map encodes a sequence of locations.
kono
parents: 67
diff changeset
318 There are two kinds of maps. Ordinary maps and macro expansion
kono
parents: 67
diff changeset
319 maps, a.k.a macro maps.
kono
parents: 67
diff changeset
320
kono
parents: 67
diff changeset
321 A macro map encodes source locations of tokens that are part of a
kono
parents: 67
diff changeset
322 macro replacement-list, at a macro expansion point. E.g, in:
kono
parents: 67
diff changeset
323
kono
parents: 67
diff changeset
324 #define PLUS(A,B) A + B
kono
parents: 67
diff changeset
325
kono
parents: 67
diff changeset
326 No macro map is going to be created there, because we are not at a
kono
parents: 67
diff changeset
327 macro expansion point. We are at a macro /definition/ point. So the
kono
parents: 67
diff changeset
328 locations of the tokens of the macro replacement-list (i.e, A + B)
kono
parents: 67
diff changeset
329 will be locations in an ordinary map, not a macro map.
kono
parents: 67
diff changeset
330
kono
parents: 67
diff changeset
331 On the other hand, if we later do:
kono
parents: 67
diff changeset
332
kono
parents: 67
diff changeset
333 int a = PLUS (1,2);
kono
parents: 67
diff changeset
334
kono
parents: 67
diff changeset
335 The invocation of PLUS here is a macro expansion. So we are at a
kono
parents: 67
diff changeset
336 macro expansion point. The preprocessor expands PLUS (1,2) and
kono
parents: 67
diff changeset
337 replaces it with the tokens of its replacement-list: 1 + 2. A macro
kono
parents: 67
diff changeset
338 map is going to be created to hold (or rather to map, haha ...) the
kono
parents: 67
diff changeset
339 locations of the tokens 1, + and 2. The macro map also records the
kono
parents: 67
diff changeset
340 location of the expansion point of PLUS. That location is mapped in
kono
parents: 67
diff changeset
341 the map that is active right before the location of the invocation
kono
parents: 67
diff changeset
342 of PLUS. */
kono
parents: 67
diff changeset
343 struct GTY((tag ("0"), desc ("%h.reason == LC_ENTER_MACRO ? 2 : 1"))) line_map {
kono
parents: 67
diff changeset
344 source_location start_location;
kono
parents: 67
diff changeset
345
kono
parents: 67
diff changeset
346 /* The reason for creation of this line map. */
kono
parents: 67
diff changeset
347 ENUM_BITFIELD (lc_reason) reason : CHAR_BIT;
kono
parents: 67
diff changeset
348 };
kono
parents: 67
diff changeset
349
kono
parents: 67
diff changeset
350 /* An ordinary line map encodes physical source locations. Those
kono
parents: 67
diff changeset
351 physical source locations are called "spelling locations".
kono
parents: 67
diff changeset
352
kono
parents: 67
diff changeset
353 Physical source file TO_FILE at line TO_LINE at column 0 is represented
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 by the logical START_LOCATION. TO_LINE+L at column C is represented by
111
kono
parents: 67
diff changeset
355 START_LOCATION+(L*(1<<m_column_and_range_bits))+(C*1<<m_range_bits), as
kono
parents: 67
diff changeset
356 long as C<(1<<effective range bits), and the result_location is less than
kono
parents: 67
diff changeset
357 the next line_map's start_location.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 (The top line is line 1 and the leftmost column is column 1; line/column 0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 means "entire file/line" or "unknown line/column" or "not applicable".)
111
kono
parents: 67
diff changeset
360
kono
parents: 67
diff changeset
361 The highest possible source location is MAX_SOURCE_LOCATION. */
kono
parents: 67
diff changeset
362 struct GTY((tag ("1"))) line_map_ordinary : public line_map {
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 const char *to_file;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 linenum_type to_line;
111
kono
parents: 67
diff changeset
365
kono
parents: 67
diff changeset
366 /* An index into the set that gives the line mapping at whose end
kono
parents: 67
diff changeset
367 the current one was included. File(s) at the bottom of the
kono
parents: 67
diff changeset
368 include stack have this set to -1. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
369 int included_from;
111
kono
parents: 67
diff changeset
370
kono
parents: 67
diff changeset
371 /* SYSP is one for a system header, two for a C system header file
kono
parents: 67
diff changeset
372 that therefore needs to be extern "C" protected in C++, and zero
kono
parents: 67
diff changeset
373 otherwise. This field isn't really needed now that it's in
kono
parents: 67
diff changeset
374 cpp_buffer. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 unsigned char sysp;
111
kono
parents: 67
diff changeset
376
kono
parents: 67
diff changeset
377 /* Number of the low-order source_location bits used for column numbers
kono
parents: 67
diff changeset
378 and ranges. */
kono
parents: 67
diff changeset
379 unsigned int m_column_and_range_bits : 8;
kono
parents: 67
diff changeset
380
kono
parents: 67
diff changeset
381 /* Number of the low-order "column" bits used for storing short ranges
kono
parents: 67
diff changeset
382 inline, rather than in the ad-hoc table.
kono
parents: 67
diff changeset
383 MSB LSB
kono
parents: 67
diff changeset
384 31 0
kono
parents: 67
diff changeset
385 +-------------------------+-------------------------------------------+
kono
parents: 67
diff changeset
386 | |<---map->column_and_range_bits (e.g. 12)-->|
kono
parents: 67
diff changeset
387 +-------------------------+-----------------------+-------------------+
kono
parents: 67
diff changeset
388 | | column_and_range_bits | map->range_bits |
kono
parents: 67
diff changeset
389 | | - range_bits | |
kono
parents: 67
diff changeset
390 +-------------------------+-----------------------+-------------------+
kono
parents: 67
diff changeset
391 | row bits | effective column bits | short range bits |
kono
parents: 67
diff changeset
392 | | (e.g. 7) | (e.g. 5) |
kono
parents: 67
diff changeset
393 +-------------------------+-----------------------+-------------------+ */
kono
parents: 67
diff changeset
394 unsigned int m_range_bits : 8;
kono
parents: 67
diff changeset
395 };
kono
parents: 67
diff changeset
396
kono
parents: 67
diff changeset
397 /* This is the highest possible source location encoded within an
kono
parents: 67
diff changeset
398 ordinary or macro map. */
kono
parents: 67
diff changeset
399 const source_location MAX_SOURCE_LOCATION = 0x7FFFFFFF;
kono
parents: 67
diff changeset
400
kono
parents: 67
diff changeset
401 struct cpp_hashnode;
kono
parents: 67
diff changeset
402
kono
parents: 67
diff changeset
403 /* A macro line map encodes location of tokens coming from a macro
kono
parents: 67
diff changeset
404 expansion.
kono
parents: 67
diff changeset
405
kono
parents: 67
diff changeset
406 The offset from START_LOCATION is used to index into
kono
parents: 67
diff changeset
407 MACRO_LOCATIONS; this holds the original location of the token. */
kono
parents: 67
diff changeset
408 struct GTY((tag ("2"))) line_map_macro : public line_map {
kono
parents: 67
diff changeset
409 /* The cpp macro which expansion gave birth to this macro map. */
kono
parents: 67
diff changeset
410 struct cpp_hashnode * GTY ((nested_ptr (union tree_node,
kono
parents: 67
diff changeset
411 "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
kono
parents: 67
diff changeset
412 "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL")))
kono
parents: 67
diff changeset
413 macro;
kono
parents: 67
diff changeset
414
kono
parents: 67
diff changeset
415 /* The number of tokens inside the replacement-list of MACRO. */
kono
parents: 67
diff changeset
416 unsigned int n_tokens;
kono
parents: 67
diff changeset
417
kono
parents: 67
diff changeset
418 /* This array of location is actually an array of pairs of
kono
parents: 67
diff changeset
419 locations. The elements inside it thus look like:
kono
parents: 67
diff changeset
420
kono
parents: 67
diff changeset
421 x0,y0, x1,y1, x2,y2, ...., xn,yn.
kono
parents: 67
diff changeset
422
kono
parents: 67
diff changeset
423 where n == n_tokens;
kono
parents: 67
diff changeset
424
kono
parents: 67
diff changeset
425 Remember that these xI,yI are collected when libcpp is about to
kono
parents: 67
diff changeset
426 expand a given macro.
kono
parents: 67
diff changeset
427
kono
parents: 67
diff changeset
428 yI is the location in the macro definition, either of the token
kono
parents: 67
diff changeset
429 itself or of a macro parameter that it replaces.
kono
parents: 67
diff changeset
430
kono
parents: 67
diff changeset
431 Imagine this:
kono
parents: 67
diff changeset
432
kono
parents: 67
diff changeset
433 #define PLUS(A, B) A + B <--- #1
kono
parents: 67
diff changeset
434
kono
parents: 67
diff changeset
435 int a = PLUS (1,2); <--- #2
kono
parents: 67
diff changeset
436
kono
parents: 67
diff changeset
437 There is a macro map for the expansion of PLUS in #2. PLUS is
kono
parents: 67
diff changeset
438 expanded into its expansion-list. The expansion-list is the
kono
parents: 67
diff changeset
439 replacement-list of PLUS where the macro parameters are replaced
kono
parents: 67
diff changeset
440 with their arguments. So the replacement-list of PLUS is made of
kono
parents: 67
diff changeset
441 the tokens:
kono
parents: 67
diff changeset
442
kono
parents: 67
diff changeset
443 A, +, B
kono
parents: 67
diff changeset
444
kono
parents: 67
diff changeset
445 and the expansion-list is made of the tokens:
kono
parents: 67
diff changeset
446
kono
parents: 67
diff changeset
447 1, +, 2
kono
parents: 67
diff changeset
448
kono
parents: 67
diff changeset
449 Let's consider the case of token "+". Its y1 [yI for I == 1] is
kono
parents: 67
diff changeset
450 its spelling location in #1.
kono
parents: 67
diff changeset
451
kono
parents: 67
diff changeset
452 y0 (thus for token "1") is the spelling location of A in #1.
kono
parents: 67
diff changeset
453
kono
parents: 67
diff changeset
454 And y2 (of token "2") is the spelling location of B in #1.
kono
parents: 67
diff changeset
455
kono
parents: 67
diff changeset
456 When the token is /not/ an argument for a macro, xI is the same
kono
parents: 67
diff changeset
457 location as yI. Otherwise, xI is the location of the token
kono
parents: 67
diff changeset
458 outside this macro expansion. If this macro was expanded from
kono
parents: 67
diff changeset
459 another macro expansion, xI is a virtual location representing
kono
parents: 67
diff changeset
460 the token in that macro expansion; otherwise, it is the spelling
kono
parents: 67
diff changeset
461 location of the token.
kono
parents: 67
diff changeset
462
kono
parents: 67
diff changeset
463 Note that a virtual location is a location returned by
kono
parents: 67
diff changeset
464 linemap_add_macro_token. It encodes the relevant locations (x,y
kono
parents: 67
diff changeset
465 pairs) of that token across the macro expansions from which it
kono
parents: 67
diff changeset
466 (the token) might come from.
kono
parents: 67
diff changeset
467
kono
parents: 67
diff changeset
468 In the example above x1 (for token "+") is going to be the same
kono
parents: 67
diff changeset
469 as y1. x0 is the spelling location for the argument token "1",
kono
parents: 67
diff changeset
470 and x2 is the spelling location for the argument token "2". */
kono
parents: 67
diff changeset
471 source_location * GTY((atomic)) macro_locations;
kono
parents: 67
diff changeset
472
kono
parents: 67
diff changeset
473 /* This is the location of the expansion point of the current macro
kono
parents: 67
diff changeset
474 map. It's the location of the macro name. That location is held
kono
parents: 67
diff changeset
475 by the map that was current right before the current one. It
kono
parents: 67
diff changeset
476 could have been either a macro or an ordinary map, depending on
kono
parents: 67
diff changeset
477 if we are in a nested expansion context not. */
kono
parents: 67
diff changeset
478 source_location expansion;
kono
parents: 67
diff changeset
479 };
kono
parents: 67
diff changeset
480
kono
parents: 67
diff changeset
481 #if CHECKING_P && (GCC_VERSION >= 2007)
kono
parents: 67
diff changeset
482
kono
parents: 67
diff changeset
483 /* Assertion macro to be used in line-map code. */
kono
parents: 67
diff changeset
484 #define linemap_assert(EXPR) \
kono
parents: 67
diff changeset
485 do { \
kono
parents: 67
diff changeset
486 if (! (EXPR)) \
kono
parents: 67
diff changeset
487 abort (); \
kono
parents: 67
diff changeset
488 } while (0)
kono
parents: 67
diff changeset
489
kono
parents: 67
diff changeset
490 /* Assert that becomes a conditional expression when checking is disabled at
kono
parents: 67
diff changeset
491 compilation time. Use this for conditions that should not happen but if
kono
parents: 67
diff changeset
492 they happen, it is better to handle them gracefully rather than crash
kono
parents: 67
diff changeset
493 randomly later.
kono
parents: 67
diff changeset
494 Usage:
kono
parents: 67
diff changeset
495
kono
parents: 67
diff changeset
496 if (linemap_assert_fails(EXPR)) handle_error(); */
kono
parents: 67
diff changeset
497 #define linemap_assert_fails(EXPR) __extension__ \
kono
parents: 67
diff changeset
498 ({linemap_assert (EXPR); false;})
kono
parents: 67
diff changeset
499
kono
parents: 67
diff changeset
500 #else
kono
parents: 67
diff changeset
501 /* Include EXPR, so that unused variable warnings do not occur. */
kono
parents: 67
diff changeset
502 #define linemap_assert(EXPR) ((void)(0 && (EXPR)))
kono
parents: 67
diff changeset
503 #define linemap_assert_fails(EXPR) (! (EXPR))
kono
parents: 67
diff changeset
504 #endif
kono
parents: 67
diff changeset
505
kono
parents: 67
diff changeset
506 /* Return TRUE if MAP encodes locations coming from a macro
kono
parents: 67
diff changeset
507 replacement-list at macro expansion point. */
kono
parents: 67
diff changeset
508 bool
kono
parents: 67
diff changeset
509 linemap_macro_expansion_map_p (const struct line_map *);
kono
parents: 67
diff changeset
510
kono
parents: 67
diff changeset
511 /* Assert that MAP encodes locations of tokens that are not part of
kono
parents: 67
diff changeset
512 the replacement-list of a macro expansion, downcasting from
kono
parents: 67
diff changeset
513 line_map * to line_map_ordinary *. */
kono
parents: 67
diff changeset
514
kono
parents: 67
diff changeset
515 inline line_map_ordinary *
kono
parents: 67
diff changeset
516 linemap_check_ordinary (struct line_map *map)
kono
parents: 67
diff changeset
517 {
kono
parents: 67
diff changeset
518 linemap_assert (!linemap_macro_expansion_map_p (map));
kono
parents: 67
diff changeset
519 return (line_map_ordinary *)map;
kono
parents: 67
diff changeset
520 }
kono
parents: 67
diff changeset
521
kono
parents: 67
diff changeset
522 /* Assert that MAP encodes locations of tokens that are not part of
kono
parents: 67
diff changeset
523 the replacement-list of a macro expansion, downcasting from
kono
parents: 67
diff changeset
524 const line_map * to const line_map_ordinary *. */
kono
parents: 67
diff changeset
525
kono
parents: 67
diff changeset
526 inline const line_map_ordinary *
kono
parents: 67
diff changeset
527 linemap_check_ordinary (const struct line_map *map)
kono
parents: 67
diff changeset
528 {
kono
parents: 67
diff changeset
529 linemap_assert (!linemap_macro_expansion_map_p (map));
kono
parents: 67
diff changeset
530 return (const line_map_ordinary *)map;
kono
parents: 67
diff changeset
531 }
kono
parents: 67
diff changeset
532
kono
parents: 67
diff changeset
533 /* Assert that MAP is a macro expansion and downcast to the appropriate
kono
parents: 67
diff changeset
534 subclass. */
kono
parents: 67
diff changeset
535
kono
parents: 67
diff changeset
536 inline line_map_macro *linemap_check_macro (line_map *map)
kono
parents: 67
diff changeset
537 {
kono
parents: 67
diff changeset
538 linemap_assert (linemap_macro_expansion_map_p (map));
kono
parents: 67
diff changeset
539 return (line_map_macro *)map;
kono
parents: 67
diff changeset
540 }
kono
parents: 67
diff changeset
541
kono
parents: 67
diff changeset
542 /* Assert that MAP is a macro expansion and downcast to the appropriate
kono
parents: 67
diff changeset
543 subclass. */
kono
parents: 67
diff changeset
544
kono
parents: 67
diff changeset
545 inline const line_map_macro *
kono
parents: 67
diff changeset
546 linemap_check_macro (const line_map *map)
kono
parents: 67
diff changeset
547 {
kono
parents: 67
diff changeset
548 linemap_assert (linemap_macro_expansion_map_p (map));
kono
parents: 67
diff changeset
549 return (const line_map_macro *)map;
kono
parents: 67
diff changeset
550 }
kono
parents: 67
diff changeset
551
kono
parents: 67
diff changeset
552 /* Read the start location of MAP. */
kono
parents: 67
diff changeset
553
kono
parents: 67
diff changeset
554 inline source_location
kono
parents: 67
diff changeset
555 MAP_START_LOCATION (const line_map *map)
kono
parents: 67
diff changeset
556 {
kono
parents: 67
diff changeset
557 return map->start_location;
kono
parents: 67
diff changeset
558 }
kono
parents: 67
diff changeset
559
kono
parents: 67
diff changeset
560 /* Get the starting line number of ordinary map MAP. */
kono
parents: 67
diff changeset
561
kono
parents: 67
diff changeset
562 inline linenum_type
kono
parents: 67
diff changeset
563 ORDINARY_MAP_STARTING_LINE_NUMBER (const line_map_ordinary *ord_map)
kono
parents: 67
diff changeset
564 {
kono
parents: 67
diff changeset
565 return ord_map->to_line;
kono
parents: 67
diff changeset
566 }
kono
parents: 67
diff changeset
567
kono
parents: 67
diff changeset
568 /* Get the index of the ordinary map at whose end
kono
parents: 67
diff changeset
569 ordinary map MAP was included.
kono
parents: 67
diff changeset
570
kono
parents: 67
diff changeset
571 File(s) at the bottom of the include stack have this set. */
kono
parents: 67
diff changeset
572
kono
parents: 67
diff changeset
573 inline int
kono
parents: 67
diff changeset
574 ORDINARY_MAP_INCLUDER_FILE_INDEX (const line_map_ordinary *ord_map)
kono
parents: 67
diff changeset
575 {
kono
parents: 67
diff changeset
576 return ord_map->included_from;
kono
parents: 67
diff changeset
577 }
kono
parents: 67
diff changeset
578
kono
parents: 67
diff changeset
579 /* Return a positive value if map encodes locations from a system
kono
parents: 67
diff changeset
580 header, 0 otherwise. Returns 1 if ordinary map MAP encodes locations
kono
parents: 67
diff changeset
581 in a system header and 2 if it encodes locations in a C system header
kono
parents: 67
diff changeset
582 that therefore needs to be extern "C" protected in C++. */
kono
parents: 67
diff changeset
583
kono
parents: 67
diff changeset
584 inline unsigned char
kono
parents: 67
diff changeset
585 ORDINARY_MAP_IN_SYSTEM_HEADER_P (const line_map_ordinary *ord_map)
kono
parents: 67
diff changeset
586 {
kono
parents: 67
diff changeset
587 return ord_map->sysp;
kono
parents: 67
diff changeset
588 }
kono
parents: 67
diff changeset
589
kono
parents: 67
diff changeset
590 /* Get the filename of ordinary map MAP. */
kono
parents: 67
diff changeset
591
kono
parents: 67
diff changeset
592 inline const char *
kono
parents: 67
diff changeset
593 ORDINARY_MAP_FILE_NAME (const line_map_ordinary *ord_map)
kono
parents: 67
diff changeset
594 {
kono
parents: 67
diff changeset
595 return ord_map->to_file;
kono
parents: 67
diff changeset
596 }
kono
parents: 67
diff changeset
597
kono
parents: 67
diff changeset
598 /* Get the cpp macro whose expansion gave birth to macro map MAP. */
kono
parents: 67
diff changeset
599
kono
parents: 67
diff changeset
600 inline cpp_hashnode *
kono
parents: 67
diff changeset
601 MACRO_MAP_MACRO (const line_map_macro *macro_map)
kono
parents: 67
diff changeset
602 {
kono
parents: 67
diff changeset
603 return macro_map->macro;
kono
parents: 67
diff changeset
604 }
kono
parents: 67
diff changeset
605
kono
parents: 67
diff changeset
606 /* Get the number of tokens inside the replacement-list of the macro
kono
parents: 67
diff changeset
607 that led to macro map MAP. */
kono
parents: 67
diff changeset
608
kono
parents: 67
diff changeset
609 inline unsigned int
kono
parents: 67
diff changeset
610 MACRO_MAP_NUM_MACRO_TOKENS (const line_map_macro *macro_map)
kono
parents: 67
diff changeset
611 {
kono
parents: 67
diff changeset
612 return macro_map->n_tokens;
kono
parents: 67
diff changeset
613 }
kono
parents: 67
diff changeset
614
kono
parents: 67
diff changeset
615 /* Get the array of pairs of locations within macro map MAP.
kono
parents: 67
diff changeset
616 See the declaration of line_map_macro for more information. */
kono
parents: 67
diff changeset
617
kono
parents: 67
diff changeset
618 inline source_location *
kono
parents: 67
diff changeset
619 MACRO_MAP_LOCATIONS (const line_map_macro *macro_map)
kono
parents: 67
diff changeset
620 {
kono
parents: 67
diff changeset
621 return macro_map->macro_locations;
kono
parents: 67
diff changeset
622 }
kono
parents: 67
diff changeset
623
kono
parents: 67
diff changeset
624 /* Get the location of the expansion point of the macro map MAP. */
kono
parents: 67
diff changeset
625
kono
parents: 67
diff changeset
626 inline source_location
kono
parents: 67
diff changeset
627 MACRO_MAP_EXPANSION_POINT_LOCATION (const line_map_macro *macro_map)
kono
parents: 67
diff changeset
628 {
kono
parents: 67
diff changeset
629 return macro_map->expansion;
kono
parents: 67
diff changeset
630 }
kono
parents: 67
diff changeset
631
kono
parents: 67
diff changeset
632 /* The abstraction of a set of location maps. There can be several
kono
parents: 67
diff changeset
633 types of location maps. This abstraction contains the attributes
kono
parents: 67
diff changeset
634 that are independent from the type of the map.
kono
parents: 67
diff changeset
635
kono
parents: 67
diff changeset
636 Essentially this is just a vector of T_linemap_subclass,
kono
parents: 67
diff changeset
637 which can only ever grow in size. */
kono
parents: 67
diff changeset
638
kono
parents: 67
diff changeset
639 struct GTY(()) maps_info_ordinary {
kono
parents: 67
diff changeset
640 /* This array contains the "ordinary" line maps, for all
kono
parents: 67
diff changeset
641 events other than macro expansion
kono
parents: 67
diff changeset
642 (e.g. when a new preprocessing unit starts or ends). */
kono
parents: 67
diff changeset
643 line_map_ordinary * GTY ((length ("%h.used"))) maps;
kono
parents: 67
diff changeset
644
kono
parents: 67
diff changeset
645 /* The total number of allocated maps. */
kono
parents: 67
diff changeset
646 unsigned int allocated;
kono
parents: 67
diff changeset
647
kono
parents: 67
diff changeset
648 /* The number of elements used in maps. This number is smaller
kono
parents: 67
diff changeset
649 or equal to ALLOCATED. */
kono
parents: 67
diff changeset
650 unsigned int used;
kono
parents: 67
diff changeset
651
kono
parents: 67
diff changeset
652 unsigned int cache;
kono
parents: 67
diff changeset
653 };
kono
parents: 67
diff changeset
654
kono
parents: 67
diff changeset
655 struct GTY(()) maps_info_macro {
kono
parents: 67
diff changeset
656 /* This array contains the macro line maps.
kono
parents: 67
diff changeset
657 A macro line map is created whenever a macro expansion occurs. */
kono
parents: 67
diff changeset
658 line_map_macro * GTY ((length ("%h.used"))) maps;
kono
parents: 67
diff changeset
659
kono
parents: 67
diff changeset
660 /* The total number of allocated maps. */
kono
parents: 67
diff changeset
661 unsigned int allocated;
kono
parents: 67
diff changeset
662
kono
parents: 67
diff changeset
663 /* The number of elements used in maps. This number is smaller
kono
parents: 67
diff changeset
664 or equal to ALLOCATED. */
kono
parents: 67
diff changeset
665 unsigned int used;
kono
parents: 67
diff changeset
666
kono
parents: 67
diff changeset
667 unsigned int cache;
kono
parents: 67
diff changeset
668 };
kono
parents: 67
diff changeset
669
kono
parents: 67
diff changeset
670 /* Data structure to associate a source_range together with an arbitrary
kono
parents: 67
diff changeset
671 data pointer with a source location. */
kono
parents: 67
diff changeset
672 struct GTY(()) location_adhoc_data {
kono
parents: 67
diff changeset
673 source_location locus;
kono
parents: 67
diff changeset
674 source_range src_range;
kono
parents: 67
diff changeset
675 void * GTY((skip)) data;
kono
parents: 67
diff changeset
676 };
kono
parents: 67
diff changeset
677
kono
parents: 67
diff changeset
678 struct htab;
kono
parents: 67
diff changeset
679
kono
parents: 67
diff changeset
680 /* The following data structure encodes a location with some adhoc data
kono
parents: 67
diff changeset
681 and maps it to a new unsigned integer (called an adhoc location)
kono
parents: 67
diff changeset
682 that replaces the original location to represent the mapping.
kono
parents: 67
diff changeset
683
kono
parents: 67
diff changeset
684 The new adhoc_loc uses the highest bit as the enabling bit, i.e. if the
kono
parents: 67
diff changeset
685 highest bit is 1, then the number is adhoc_loc. Otherwise, it serves as
kono
parents: 67
diff changeset
686 the original location. Once identified as the adhoc_loc, the lower 31
kono
parents: 67
diff changeset
687 bits of the integer is used to index the location_adhoc_data array,
kono
parents: 67
diff changeset
688 in which the locus and associated data is stored. */
kono
parents: 67
diff changeset
689
kono
parents: 67
diff changeset
690 struct GTY(()) location_adhoc_data_map {
kono
parents: 67
diff changeset
691 struct htab * GTY((skip)) htab;
kono
parents: 67
diff changeset
692 source_location curr_loc;
kono
parents: 67
diff changeset
693 unsigned int allocated;
kono
parents: 67
diff changeset
694 struct location_adhoc_data GTY((length ("%h.allocated"))) *data;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
695 };
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
696
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
697 /* A set of chronological line_map structures. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
698 struct GTY(()) line_maps {
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
699
111
kono
parents: 67
diff changeset
700 ~line_maps ();
kono
parents: 67
diff changeset
701
kono
parents: 67
diff changeset
702 maps_info_ordinary info_ordinary;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
703
111
kono
parents: 67
diff changeset
704 maps_info_macro info_macro;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
705
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
706 /* Depth of the include stack, including the current file. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
707 unsigned int depth;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
708
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
709 /* If true, prints an include trace a la -H. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
710 bool trace_includes;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
711
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
712 /* Highest source_location "given out". */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
713 source_location highest_location;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
714
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
715 /* Start of line of highest source_location "given out". */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
716 source_location highest_line;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
717
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
718 /* The maximum column number we can quickly allocate. Higher numbers
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
719 may require allocating a new line_map. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
720 unsigned int max_column_hint;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
721
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
722 /* If non-null, the allocator to use when resizing 'maps'. If null,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
723 xrealloc is used. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
724 line_map_realloc reallocator;
111
kono
parents: 67
diff changeset
725
kono
parents: 67
diff changeset
726 /* The allocators' function used to know the actual size it
kono
parents: 67
diff changeset
727 allocated, for a certain allocation size requested. */
kono
parents: 67
diff changeset
728 line_map_round_alloc_size_func round_alloc_size;
kono
parents: 67
diff changeset
729
kono
parents: 67
diff changeset
730 struct location_adhoc_data_map location_adhoc_data_map;
kono
parents: 67
diff changeset
731
kono
parents: 67
diff changeset
732 /* The special location value that is used as spelling location for
kono
parents: 67
diff changeset
733 built-in tokens. */
kono
parents: 67
diff changeset
734 source_location builtin_location;
kono
parents: 67
diff changeset
735
kono
parents: 67
diff changeset
736 /* True if we've seen a #line or # 44 "file" directive. */
kono
parents: 67
diff changeset
737 bool seen_line_directive;
kono
parents: 67
diff changeset
738
kono
parents: 67
diff changeset
739 /* The default value of range_bits in ordinary line maps. */
kono
parents: 67
diff changeset
740 unsigned int default_range_bits;
kono
parents: 67
diff changeset
741
kono
parents: 67
diff changeset
742 unsigned int num_optimized_ranges;
kono
parents: 67
diff changeset
743 unsigned int num_unoptimized_ranges;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
744 };
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
745
111
kono
parents: 67
diff changeset
746 /* Returns the number of allocated maps so far. MAP_KIND shall be TRUE
kono
parents: 67
diff changeset
747 if we are interested in macro maps, FALSE otherwise. */
kono
parents: 67
diff changeset
748 inline unsigned int
kono
parents: 67
diff changeset
749 LINEMAPS_ALLOCATED (const line_maps *set, bool map_kind)
kono
parents: 67
diff changeset
750 {
kono
parents: 67
diff changeset
751 if (map_kind)
kono
parents: 67
diff changeset
752 return set->info_macro.allocated;
kono
parents: 67
diff changeset
753 else
kono
parents: 67
diff changeset
754 return set->info_ordinary.allocated;
kono
parents: 67
diff changeset
755 }
kono
parents: 67
diff changeset
756
kono
parents: 67
diff changeset
757 /* As above, but by reference (e.g. as an lvalue). */
kono
parents: 67
diff changeset
758
kono
parents: 67
diff changeset
759 inline unsigned int &
kono
parents: 67
diff changeset
760 LINEMAPS_ALLOCATED (line_maps *set, bool map_kind)
kono
parents: 67
diff changeset
761 {
kono
parents: 67
diff changeset
762 if (map_kind)
kono
parents: 67
diff changeset
763 return set->info_macro.allocated;
kono
parents: 67
diff changeset
764 else
kono
parents: 67
diff changeset
765 return set->info_ordinary.allocated;
kono
parents: 67
diff changeset
766 }
kono
parents: 67
diff changeset
767
kono
parents: 67
diff changeset
768 /* Returns the number of used maps so far. MAP_KIND shall be TRUE if
kono
parents: 67
diff changeset
769 we are interested in macro maps, FALSE otherwise.*/
kono
parents: 67
diff changeset
770 inline unsigned int
kono
parents: 67
diff changeset
771 LINEMAPS_USED (const line_maps *set, bool map_kind)
kono
parents: 67
diff changeset
772 {
kono
parents: 67
diff changeset
773 if (map_kind)
kono
parents: 67
diff changeset
774 return set->info_macro.used;
kono
parents: 67
diff changeset
775 else
kono
parents: 67
diff changeset
776 return set->info_ordinary.used;
kono
parents: 67
diff changeset
777 }
kono
parents: 67
diff changeset
778
kono
parents: 67
diff changeset
779 /* As above, but by reference (e.g. as an lvalue). */
kono
parents: 67
diff changeset
780
kono
parents: 67
diff changeset
781 inline unsigned int &
kono
parents: 67
diff changeset
782 LINEMAPS_USED (line_maps *set, bool map_kind)
kono
parents: 67
diff changeset
783 {
kono
parents: 67
diff changeset
784 if (map_kind)
kono
parents: 67
diff changeset
785 return set->info_macro.used;
kono
parents: 67
diff changeset
786 else
kono
parents: 67
diff changeset
787 return set->info_ordinary.used;
kono
parents: 67
diff changeset
788 }
kono
parents: 67
diff changeset
789
kono
parents: 67
diff changeset
790 /* Returns the index of the last map that was looked up with
kono
parents: 67
diff changeset
791 linemap_lookup. MAP_KIND shall be TRUE if we are interested in
kono
parents: 67
diff changeset
792 macro maps, FALSE otherwise. */
kono
parents: 67
diff changeset
793 inline unsigned int
kono
parents: 67
diff changeset
794 LINEMAPS_CACHE (const line_maps *set, bool map_kind)
kono
parents: 67
diff changeset
795 {
kono
parents: 67
diff changeset
796 if (map_kind)
kono
parents: 67
diff changeset
797 return set->info_macro.cache;
kono
parents: 67
diff changeset
798 else
kono
parents: 67
diff changeset
799 return set->info_ordinary.cache;
kono
parents: 67
diff changeset
800 }
kono
parents: 67
diff changeset
801
kono
parents: 67
diff changeset
802 /* As above, but by reference (e.g. as an lvalue). */
kono
parents: 67
diff changeset
803
kono
parents: 67
diff changeset
804 inline unsigned int &
kono
parents: 67
diff changeset
805 LINEMAPS_CACHE (line_maps *set, bool map_kind)
kono
parents: 67
diff changeset
806 {
kono
parents: 67
diff changeset
807 if (map_kind)
kono
parents: 67
diff changeset
808 return set->info_macro.cache;
kono
parents: 67
diff changeset
809 else
kono
parents: 67
diff changeset
810 return set->info_ordinary.cache;
kono
parents: 67
diff changeset
811 }
kono
parents: 67
diff changeset
812
kono
parents: 67
diff changeset
813 /* Return the map at a given index. */
kono
parents: 67
diff changeset
814 inline line_map *
kono
parents: 67
diff changeset
815 LINEMAPS_MAP_AT (const line_maps *set, bool map_kind, int index)
kono
parents: 67
diff changeset
816 {
kono
parents: 67
diff changeset
817 if (map_kind)
kono
parents: 67
diff changeset
818 return &set->info_macro.maps[index];
kono
parents: 67
diff changeset
819 else
kono
parents: 67
diff changeset
820 return &set->info_ordinary.maps[index];
kono
parents: 67
diff changeset
821 }
kono
parents: 67
diff changeset
822
kono
parents: 67
diff changeset
823 /* Returns the last map used in the line table SET. MAP_KIND
kono
parents: 67
diff changeset
824 shall be TRUE if we are interested in macro maps, FALSE
kono
parents: 67
diff changeset
825 otherwise.*/
kono
parents: 67
diff changeset
826 inline line_map *
kono
parents: 67
diff changeset
827 LINEMAPS_LAST_MAP (const line_maps *set, bool map_kind)
kono
parents: 67
diff changeset
828 {
kono
parents: 67
diff changeset
829 return LINEMAPS_MAP_AT (set, map_kind,
kono
parents: 67
diff changeset
830 LINEMAPS_USED (set, map_kind) - 1);
kono
parents: 67
diff changeset
831 }
kono
parents: 67
diff changeset
832
kono
parents: 67
diff changeset
833 /* Returns the last map that was allocated in the line table SET.
kono
parents: 67
diff changeset
834 MAP_KIND shall be TRUE if we are interested in macro maps, FALSE
kono
parents: 67
diff changeset
835 otherwise.*/
kono
parents: 67
diff changeset
836 inline line_map *
kono
parents: 67
diff changeset
837 LINEMAPS_LAST_ALLOCATED_MAP (const line_maps *set, bool map_kind)
kono
parents: 67
diff changeset
838 {
kono
parents: 67
diff changeset
839 return LINEMAPS_MAP_AT (set, map_kind,
kono
parents: 67
diff changeset
840 LINEMAPS_ALLOCATED (set, map_kind) - 1);
kono
parents: 67
diff changeset
841 }
kono
parents: 67
diff changeset
842
kono
parents: 67
diff changeset
843 /* Returns a pointer to the memory region where ordinary maps are
kono
parents: 67
diff changeset
844 allocated in the line table SET. */
kono
parents: 67
diff changeset
845 inline line_map_ordinary *
kono
parents: 67
diff changeset
846 LINEMAPS_ORDINARY_MAPS (const line_maps *set)
kono
parents: 67
diff changeset
847 {
kono
parents: 67
diff changeset
848 return set->info_ordinary.maps;
kono
parents: 67
diff changeset
849 }
kono
parents: 67
diff changeset
850
kono
parents: 67
diff changeset
851 /* Returns the INDEXth ordinary map. */
kono
parents: 67
diff changeset
852 inline line_map_ordinary *
kono
parents: 67
diff changeset
853 LINEMAPS_ORDINARY_MAP_AT (const line_maps *set, int index)
kono
parents: 67
diff changeset
854 {
kono
parents: 67
diff changeset
855 linemap_assert (index >= 0);
kono
parents: 67
diff changeset
856 linemap_assert ((unsigned int)index < set->info_ordinary.used);
kono
parents: 67
diff changeset
857 return &set->info_ordinary.maps[index];
kono
parents: 67
diff changeset
858 }
kono
parents: 67
diff changeset
859
kono
parents: 67
diff changeset
860 /* Return the number of ordinary maps allocated in the line table
kono
parents: 67
diff changeset
861 SET. */
kono
parents: 67
diff changeset
862 inline unsigned int
kono
parents: 67
diff changeset
863 LINEMAPS_ORDINARY_ALLOCATED (const line_maps *set)
kono
parents: 67
diff changeset
864 {
kono
parents: 67
diff changeset
865 return LINEMAPS_ALLOCATED (set, false);
kono
parents: 67
diff changeset
866 }
kono
parents: 67
diff changeset
867
kono
parents: 67
diff changeset
868 /* Return the number of ordinary maps used in the line table SET. */
kono
parents: 67
diff changeset
869 inline unsigned int
kono
parents: 67
diff changeset
870 LINEMAPS_ORDINARY_USED (const line_maps *set)
kono
parents: 67
diff changeset
871 {
kono
parents: 67
diff changeset
872 return LINEMAPS_USED (set, false);
kono
parents: 67
diff changeset
873 }
kono
parents: 67
diff changeset
874
kono
parents: 67
diff changeset
875 /* Return the index of the last ordinary map that was looked up with
kono
parents: 67
diff changeset
876 linemap_lookup. */
kono
parents: 67
diff changeset
877 inline unsigned int
kono
parents: 67
diff changeset
878 LINEMAPS_ORDINARY_CACHE (const line_maps *set)
kono
parents: 67
diff changeset
879 {
kono
parents: 67
diff changeset
880 return LINEMAPS_CACHE (set, false);
kono
parents: 67
diff changeset
881 }
kono
parents: 67
diff changeset
882
kono
parents: 67
diff changeset
883 /* As above, but by reference (e.g. as an lvalue). */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
884
111
kono
parents: 67
diff changeset
885 inline unsigned int &
kono
parents: 67
diff changeset
886 LINEMAPS_ORDINARY_CACHE (line_maps *set)
kono
parents: 67
diff changeset
887 {
kono
parents: 67
diff changeset
888 return LINEMAPS_CACHE (set, false);
kono
parents: 67
diff changeset
889 }
kono
parents: 67
diff changeset
890
kono
parents: 67
diff changeset
891 /* Returns a pointer to the last ordinary map used in the line table
kono
parents: 67
diff changeset
892 SET. */
kono
parents: 67
diff changeset
893 inline line_map_ordinary *
kono
parents: 67
diff changeset
894 LINEMAPS_LAST_ORDINARY_MAP (const line_maps *set)
kono
parents: 67
diff changeset
895 {
kono
parents: 67
diff changeset
896 return (line_map_ordinary *)LINEMAPS_LAST_MAP (set, false);
kono
parents: 67
diff changeset
897 }
kono
parents: 67
diff changeset
898
kono
parents: 67
diff changeset
899 /* Returns a pointer to the last ordinary map allocated the line table
kono
parents: 67
diff changeset
900 SET. */
kono
parents: 67
diff changeset
901 inline line_map_ordinary *
kono
parents: 67
diff changeset
902 LINEMAPS_LAST_ALLOCATED_ORDINARY_MAP (const line_maps *set)
kono
parents: 67
diff changeset
903 {
kono
parents: 67
diff changeset
904 return (line_map_ordinary *)LINEMAPS_LAST_ALLOCATED_MAP (set, false);
kono
parents: 67
diff changeset
905 }
kono
parents: 67
diff changeset
906
kono
parents: 67
diff changeset
907 /* Returns a pointer to the beginning of the region where macro maps
kono
parents: 67
diff changeset
908 are allocated. */
kono
parents: 67
diff changeset
909 inline line_map_macro *
kono
parents: 67
diff changeset
910 LINEMAPS_MACRO_MAPS (const line_maps *set)
kono
parents: 67
diff changeset
911 {
kono
parents: 67
diff changeset
912 return set->info_macro.maps;
kono
parents: 67
diff changeset
913 }
kono
parents: 67
diff changeset
914
kono
parents: 67
diff changeset
915 /* Returns the INDEXth macro map. */
kono
parents: 67
diff changeset
916 inline line_map_macro *
kono
parents: 67
diff changeset
917 LINEMAPS_MACRO_MAP_AT (const line_maps *set, int index)
kono
parents: 67
diff changeset
918 {
kono
parents: 67
diff changeset
919 linemap_assert (index >= 0);
kono
parents: 67
diff changeset
920 linemap_assert ((unsigned int)index < set->info_macro.used);
kono
parents: 67
diff changeset
921 return &set->info_macro.maps[index];
kono
parents: 67
diff changeset
922 }
kono
parents: 67
diff changeset
923
kono
parents: 67
diff changeset
924 /* Returns the number of macro maps that were allocated in the line
kono
parents: 67
diff changeset
925 table SET. */
kono
parents: 67
diff changeset
926 inline unsigned int
kono
parents: 67
diff changeset
927 LINEMAPS_MACRO_ALLOCATED (const line_maps *set)
kono
parents: 67
diff changeset
928 {
kono
parents: 67
diff changeset
929 return LINEMAPS_ALLOCATED (set, true);
kono
parents: 67
diff changeset
930 }
kono
parents: 67
diff changeset
931
kono
parents: 67
diff changeset
932 /* Returns the number of macro maps used in the line table SET. */
kono
parents: 67
diff changeset
933 inline unsigned int
kono
parents: 67
diff changeset
934 LINEMAPS_MACRO_USED (const line_maps *set)
kono
parents: 67
diff changeset
935 {
kono
parents: 67
diff changeset
936 return LINEMAPS_USED (set, true);
kono
parents: 67
diff changeset
937 }
kono
parents: 67
diff changeset
938
kono
parents: 67
diff changeset
939 /* Returns the index of the last macro map looked up with
kono
parents: 67
diff changeset
940 linemap_lookup. */
kono
parents: 67
diff changeset
941 inline unsigned int
kono
parents: 67
diff changeset
942 LINEMAPS_MACRO_CACHE (const line_maps *set)
kono
parents: 67
diff changeset
943 {
kono
parents: 67
diff changeset
944 return LINEMAPS_CACHE (set, true);
kono
parents: 67
diff changeset
945 }
kono
parents: 67
diff changeset
946
kono
parents: 67
diff changeset
947 /* As above, but by reference (e.g. as an lvalue). */
kono
parents: 67
diff changeset
948
kono
parents: 67
diff changeset
949 inline unsigned int &
kono
parents: 67
diff changeset
950 LINEMAPS_MACRO_CACHE (line_maps *set)
kono
parents: 67
diff changeset
951 {
kono
parents: 67
diff changeset
952 return LINEMAPS_CACHE (set, true);
kono
parents: 67
diff changeset
953 }
kono
parents: 67
diff changeset
954
kono
parents: 67
diff changeset
955 /* Returns the last macro map used in the line table SET. */
kono
parents: 67
diff changeset
956 inline line_map_macro *
kono
parents: 67
diff changeset
957 LINEMAPS_LAST_MACRO_MAP (const line_maps *set)
kono
parents: 67
diff changeset
958 {
kono
parents: 67
diff changeset
959 return (line_map_macro *)LINEMAPS_LAST_MAP (set, true);
kono
parents: 67
diff changeset
960 }
kono
parents: 67
diff changeset
961
kono
parents: 67
diff changeset
962 /* Returns the lowest location [of a token resulting from macro
kono
parents: 67
diff changeset
963 expansion] encoded in this line table. */
kono
parents: 67
diff changeset
964 inline source_location
kono
parents: 67
diff changeset
965 LINEMAPS_MACRO_LOWEST_LOCATION (const line_maps *set)
kono
parents: 67
diff changeset
966 {
kono
parents: 67
diff changeset
967 return LINEMAPS_MACRO_USED (set)
kono
parents: 67
diff changeset
968 ? MAP_START_LOCATION (LINEMAPS_LAST_MACRO_MAP (set))
kono
parents: 67
diff changeset
969 : MAX_SOURCE_LOCATION;
kono
parents: 67
diff changeset
970 }
kono
parents: 67
diff changeset
971
kono
parents: 67
diff changeset
972 /* Returns the last macro map allocated in the line table SET. */
kono
parents: 67
diff changeset
973 inline line_map_macro *
kono
parents: 67
diff changeset
974 LINEMAPS_LAST_ALLOCATED_MACRO_MAP (const line_maps *set)
kono
parents: 67
diff changeset
975 {
kono
parents: 67
diff changeset
976 return (line_map_macro *)LINEMAPS_LAST_ALLOCATED_MAP (set, true);
kono
parents: 67
diff changeset
977 }
kono
parents: 67
diff changeset
978
kono
parents: 67
diff changeset
979 extern source_location get_combined_adhoc_loc (struct line_maps *,
kono
parents: 67
diff changeset
980 source_location,
kono
parents: 67
diff changeset
981 source_range,
kono
parents: 67
diff changeset
982 void *);
kono
parents: 67
diff changeset
983 extern void *get_data_from_adhoc_loc (struct line_maps *, source_location);
kono
parents: 67
diff changeset
984 extern source_location get_location_from_adhoc_loc (struct line_maps *,
kono
parents: 67
diff changeset
985 source_location);
kono
parents: 67
diff changeset
986
kono
parents: 67
diff changeset
987 extern source_range get_range_from_loc (line_maps *set, source_location loc);
kono
parents: 67
diff changeset
988
kono
parents: 67
diff changeset
989 /* Get whether location LOC is an ad-hoc location. */
kono
parents: 67
diff changeset
990
kono
parents: 67
diff changeset
991 inline bool
kono
parents: 67
diff changeset
992 IS_ADHOC_LOC (source_location loc)
kono
parents: 67
diff changeset
993 {
kono
parents: 67
diff changeset
994 return (loc & MAX_SOURCE_LOCATION) != loc;
kono
parents: 67
diff changeset
995 }
kono
parents: 67
diff changeset
996
kono
parents: 67
diff changeset
997 /* Get whether location LOC is a "pure" location, or
kono
parents: 67
diff changeset
998 whether it is an ad-hoc location, or embeds range information. */
kono
parents: 67
diff changeset
999
kono
parents: 67
diff changeset
1000 bool
kono
parents: 67
diff changeset
1001 pure_location_p (line_maps *set, source_location loc);
kono
parents: 67
diff changeset
1002
kono
parents: 67
diff changeset
1003 /* Given location LOC within SET, strip away any packed range information
kono
parents: 67
diff changeset
1004 or ad-hoc information. */
kono
parents: 67
diff changeset
1005
kono
parents: 67
diff changeset
1006 extern source_location get_pure_location (line_maps *set,
kono
parents: 67
diff changeset
1007 source_location loc);
kono
parents: 67
diff changeset
1008
kono
parents: 67
diff changeset
1009 /* Combine LOC and BLOCK, giving a combined adhoc location. */
kono
parents: 67
diff changeset
1010
kono
parents: 67
diff changeset
1011 inline source_location
kono
parents: 67
diff changeset
1012 COMBINE_LOCATION_DATA (struct line_maps *set,
kono
parents: 67
diff changeset
1013 source_location loc,
kono
parents: 67
diff changeset
1014 source_range src_range,
kono
parents: 67
diff changeset
1015 void *block)
kono
parents: 67
diff changeset
1016 {
kono
parents: 67
diff changeset
1017 return get_combined_adhoc_loc (set, loc, src_range, block);
kono
parents: 67
diff changeset
1018 }
kono
parents: 67
diff changeset
1019
kono
parents: 67
diff changeset
1020 extern void rebuild_location_adhoc_htab (struct line_maps *);
kono
parents: 67
diff changeset
1021
kono
parents: 67
diff changeset
1022 /* Initialize a line map set. SET is the line map set to initialize
kono
parents: 67
diff changeset
1023 and BUILTIN_LOCATION is the special location value to be used as
kono
parents: 67
diff changeset
1024 spelling location for built-in tokens. This BUILTIN_LOCATION has
kono
parents: 67
diff changeset
1025 to be strictly less than RESERVED_LOCATION_COUNT. */
kono
parents: 67
diff changeset
1026 extern void linemap_init (struct line_maps *set,
kono
parents: 67
diff changeset
1027 source_location builtin_location);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1028
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1029 /* Check for and warn about line_maps entered but not exited. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1030
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1031 extern void linemap_check_files_exited (struct line_maps *);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1032
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1033 /* Return a source_location for the start (i.e. column==0) of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1034 (physical) line TO_LINE in the current source file (as in the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1035 most recent linemap_add). MAX_COLUMN_HINT is the highest column
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1036 number we expect to use in this line (but it does not change
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1037 the highest_location). */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1038
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1039 extern source_location linemap_line_start
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1040 (struct line_maps *set, linenum_type to_line, unsigned int max_column_hint);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1041
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1042 /* Add a mapping of logical source line to physical source file and
111
kono
parents: 67
diff changeset
1043 line number. This function creates an "ordinary map", which is a
kono
parents: 67
diff changeset
1044 map that records locations of tokens that are not part of macro
kono
parents: 67
diff changeset
1045 replacement-lists present at a macro expansion point.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1046
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1047 The text pointed to by TO_FILE must have a lifetime
111
kono
parents: 67
diff changeset
1048 at least as long as the lifetime of SET. An empty
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1049 TO_FILE means standard input. If reason is LC_LEAVE, and
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1050 TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1051 natural values considering the file we are returning to.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1052
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1053 A call to this function can relocate the previous set of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1054 maps, so any stored line_map pointers should not be used. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1055 extern const struct line_map *linemap_add
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1056 (struct line_maps *, enum lc_reason, unsigned int sysp,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1057 const char *to_file, linenum_type to_line);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1058
111
kono
parents: 67
diff changeset
1059 /* Given a logical source location, returns the map which the
kono
parents: 67
diff changeset
1060 corresponding (source file, line, column) triplet can be deduced
kono
parents: 67
diff changeset
1061 from. Since the set is built chronologically, the logical lines are
kono
parents: 67
diff changeset
1062 monotonic increasing, and so the list is sorted and we can use a
kono
parents: 67
diff changeset
1063 binary search. If no line map have been allocated yet, this
kono
parents: 67
diff changeset
1064 function returns NULL. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1065 extern const struct line_map *linemap_lookup
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1066 (struct line_maps *, source_location);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1067
111
kono
parents: 67
diff changeset
1068 /* Returns TRUE if the line table set tracks token locations across
kono
parents: 67
diff changeset
1069 macro expansion, FALSE otherwise. */
kono
parents: 67
diff changeset
1070 bool linemap_tracks_macro_expansion_locs_p (struct line_maps *);
kono
parents: 67
diff changeset
1071
kono
parents: 67
diff changeset
1072 /* Return the name of the macro associated to MACRO_MAP. */
kono
parents: 67
diff changeset
1073 const char* linemap_map_get_macro_name (const line_map_macro *);
kono
parents: 67
diff changeset
1074
kono
parents: 67
diff changeset
1075 /* Return a positive value if LOCATION is the locus of a token that is
kono
parents: 67
diff changeset
1076 located in a system header, O otherwise. It returns 1 if LOCATION
kono
parents: 67
diff changeset
1077 is the locus of a token that is located in a system header, and 2
kono
parents: 67
diff changeset
1078 if LOCATION is the locus of a token located in a C system header
kono
parents: 67
diff changeset
1079 that therefore needs to be extern "C" protected in C++.
kono
parents: 67
diff changeset
1080
kono
parents: 67
diff changeset
1081 Note that this function returns 1 if LOCATION belongs to a token
kono
parents: 67
diff changeset
1082 that is part of a macro replacement-list defined in a system
kono
parents: 67
diff changeset
1083 header, but expanded in a non-system file. */
kono
parents: 67
diff changeset
1084 int linemap_location_in_system_header_p (struct line_maps *,
kono
parents: 67
diff changeset
1085 source_location);
kono
parents: 67
diff changeset
1086
kono
parents: 67
diff changeset
1087 /* Return TRUE if LOCATION is a source code location of a token that is part of
kono
parents: 67
diff changeset
1088 a macro expansion, FALSE otherwise. */
kono
parents: 67
diff changeset
1089 bool linemap_location_from_macro_expansion_p (const struct line_maps *,
kono
parents: 67
diff changeset
1090 source_location);
kono
parents: 67
diff changeset
1091
kono
parents: 67
diff changeset
1092 /* TRUE if LOCATION is a source code location of a token that is part of the
kono
parents: 67
diff changeset
1093 definition of a macro, FALSE otherwise. */
kono
parents: 67
diff changeset
1094 bool linemap_location_from_macro_definition_p (struct line_maps *,
kono
parents: 67
diff changeset
1095 source_location);
kono
parents: 67
diff changeset
1096
kono
parents: 67
diff changeset
1097 /* With the precondition that LOCATION is the locus of a token that is
kono
parents: 67
diff changeset
1098 an argument of a function-like macro MACRO_MAP and appears in the
kono
parents: 67
diff changeset
1099 expansion of MACRO_MAP, return the locus of that argument in the
kono
parents: 67
diff changeset
1100 context of the caller of MACRO_MAP. */
kono
parents: 67
diff changeset
1101
kono
parents: 67
diff changeset
1102 extern source_location linemap_macro_map_loc_unwind_toward_spelling
kono
parents: 67
diff changeset
1103 (line_maps *set, const line_map_macro *macro_map, source_location location);
kono
parents: 67
diff changeset
1104
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1105 /* source_location values from 0 to RESERVED_LOCATION_COUNT-1 will
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1106 be reserved for libcpp user as special values, no token from libcpp
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1107 will contain any of those locations. */
111
kono
parents: 67
diff changeset
1108 const source_location RESERVED_LOCATION_COUNT = 2;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1109
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1110 /* Converts a map and a source_location to source line. */
111
kono
parents: 67
diff changeset
1111 inline linenum_type
kono
parents: 67
diff changeset
1112 SOURCE_LINE (const line_map_ordinary *ord_map, source_location loc)
kono
parents: 67
diff changeset
1113 {
kono
parents: 67
diff changeset
1114 return ((loc - ord_map->start_location)
kono
parents: 67
diff changeset
1115 >> ord_map->m_column_and_range_bits) + ord_map->to_line;
kono
parents: 67
diff changeset
1116 }
kono
parents: 67
diff changeset
1117
kono
parents: 67
diff changeset
1118 /* Convert a map and source_location to source column number. */
kono
parents: 67
diff changeset
1119 inline linenum_type
kono
parents: 67
diff changeset
1120 SOURCE_COLUMN (const line_map_ordinary *ord_map, source_location loc)
kono
parents: 67
diff changeset
1121 {
kono
parents: 67
diff changeset
1122 return ((loc - ord_map->start_location)
kono
parents: 67
diff changeset
1123 & ((1 << ord_map->m_column_and_range_bits) - 1)) >> ord_map->m_range_bits;
kono
parents: 67
diff changeset
1124 }
kono
parents: 67
diff changeset
1125
kono
parents: 67
diff changeset
1126 /* Return the location of the last source line within an ordinary
kono
parents: 67
diff changeset
1127 map. */
kono
parents: 67
diff changeset
1128 inline source_location
kono
parents: 67
diff changeset
1129 LAST_SOURCE_LINE_LOCATION (const line_map_ordinary *map)
kono
parents: 67
diff changeset
1130 {
kono
parents: 67
diff changeset
1131 return (((map[1].start_location - 1
kono
parents: 67
diff changeset
1132 - map->start_location)
kono
parents: 67
diff changeset
1133 & ~((1 << map->m_column_and_range_bits) - 1))
kono
parents: 67
diff changeset
1134 + map->start_location);
kono
parents: 67
diff changeset
1135 }
kono
parents: 67
diff changeset
1136
kono
parents: 67
diff changeset
1137 /* Returns the last source line number within an ordinary map. This
kono
parents: 67
diff changeset
1138 is the (last) line of the #include, or other directive, that caused
kono
parents: 67
diff changeset
1139 a map change. */
kono
parents: 67
diff changeset
1140 inline linenum_type
kono
parents: 67
diff changeset
1141 LAST_SOURCE_LINE (const line_map_ordinary *map)
kono
parents: 67
diff changeset
1142 {
kono
parents: 67
diff changeset
1143 return SOURCE_LINE (map, LAST_SOURCE_LINE_LOCATION (map));
kono
parents: 67
diff changeset
1144 }
kono
parents: 67
diff changeset
1145
kono
parents: 67
diff changeset
1146 /* Return the last column number within an ordinary map. */
kono
parents: 67
diff changeset
1147
kono
parents: 67
diff changeset
1148 inline linenum_type
kono
parents: 67
diff changeset
1149 LAST_SOURCE_COLUMN (const line_map_ordinary *map)
kono
parents: 67
diff changeset
1150 {
kono
parents: 67
diff changeset
1151 return SOURCE_COLUMN (map, LAST_SOURCE_LINE_LOCATION (map));
kono
parents: 67
diff changeset
1152 }
kono
parents: 67
diff changeset
1153
kono
parents: 67
diff changeset
1154 /* Returns the map a given map was included from, or NULL if the map
kono
parents: 67
diff changeset
1155 belongs to the main file, i.e, a file that wasn't included by
kono
parents: 67
diff changeset
1156 another one. */
kono
parents: 67
diff changeset
1157 inline line_map_ordinary *
kono
parents: 67
diff changeset
1158 INCLUDED_FROM (struct line_maps *set, const line_map_ordinary *ord_map)
kono
parents: 67
diff changeset
1159 {
kono
parents: 67
diff changeset
1160 return ((ord_map->included_from == -1)
kono
parents: 67
diff changeset
1161 ? NULL
kono
parents: 67
diff changeset
1162 : LINEMAPS_ORDINARY_MAP_AT (set, ord_map->included_from));
kono
parents: 67
diff changeset
1163 }
kono
parents: 67
diff changeset
1164
kono
parents: 67
diff changeset
1165 /* True if the map is at the bottom of the include stack. */
kono
parents: 67
diff changeset
1166
kono
parents: 67
diff changeset
1167 inline bool
kono
parents: 67
diff changeset
1168 MAIN_FILE_P (const line_map_ordinary *ord_map)
kono
parents: 67
diff changeset
1169 {
kono
parents: 67
diff changeset
1170 return ord_map->included_from < 0;
kono
parents: 67
diff changeset
1171 }
kono
parents: 67
diff changeset
1172
kono
parents: 67
diff changeset
1173 /* Encode and return a source_location from a column number. The
kono
parents: 67
diff changeset
1174 source line considered is the last source line used to call
kono
parents: 67
diff changeset
1175 linemap_line_start, i.e, the last source line which a location was
kono
parents: 67
diff changeset
1176 encoded from. */
kono
parents: 67
diff changeset
1177 extern source_location
kono
parents: 67
diff changeset
1178 linemap_position_for_column (struct line_maps *, unsigned int);
kono
parents: 67
diff changeset
1179
kono
parents: 67
diff changeset
1180 /* Encode and return a source location from a given line and
kono
parents: 67
diff changeset
1181 column. */
kono
parents: 67
diff changeset
1182 source_location
kono
parents: 67
diff changeset
1183 linemap_position_for_line_and_column (line_maps *set,
kono
parents: 67
diff changeset
1184 const line_map_ordinary *,
kono
parents: 67
diff changeset
1185 linenum_type, unsigned int);
kono
parents: 67
diff changeset
1186
kono
parents: 67
diff changeset
1187 /* Encode and return a source_location starting from location LOC and
kono
parents: 67
diff changeset
1188 shifting it by OFFSET columns. This function does not support
kono
parents: 67
diff changeset
1189 virtual locations. */
kono
parents: 67
diff changeset
1190 source_location
kono
parents: 67
diff changeset
1191 linemap_position_for_loc_and_offset (struct line_maps *set,
kono
parents: 67
diff changeset
1192 source_location loc,
kono
parents: 67
diff changeset
1193 unsigned int offset);
kono
parents: 67
diff changeset
1194
kono
parents: 67
diff changeset
1195 /* Return the file this map is for. */
kono
parents: 67
diff changeset
1196 inline const char *
kono
parents: 67
diff changeset
1197 LINEMAP_FILE (const line_map_ordinary *ord_map)
kono
parents: 67
diff changeset
1198 {
kono
parents: 67
diff changeset
1199 return ord_map->to_file;
kono
parents: 67
diff changeset
1200 }
kono
parents: 67
diff changeset
1201
kono
parents: 67
diff changeset
1202 /* Return the line number this map started encoding location from. */
kono
parents: 67
diff changeset
1203 inline linenum_type
kono
parents: 67
diff changeset
1204 LINEMAP_LINE (const line_map_ordinary *ord_map)
kono
parents: 67
diff changeset
1205 {
kono
parents: 67
diff changeset
1206 return ord_map->to_line;
kono
parents: 67
diff changeset
1207 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1208
111
kono
parents: 67
diff changeset
1209 /* Return a positive value if map encodes locations from a system
kono
parents: 67
diff changeset
1210 header, 0 otherwise. Returns 1 if MAP encodes locations in a
kono
parents: 67
diff changeset
1211 system header and 2 if it encodes locations in a C system header
kono
parents: 67
diff changeset
1212 that therefore needs to be extern "C" protected in C++. */
kono
parents: 67
diff changeset
1213 inline unsigned char
kono
parents: 67
diff changeset
1214 LINEMAP_SYSP (const line_map_ordinary *ord_map)
kono
parents: 67
diff changeset
1215 {
kono
parents: 67
diff changeset
1216 return ord_map->sysp;
kono
parents: 67
diff changeset
1217 }
kono
parents: 67
diff changeset
1218
kono
parents: 67
diff changeset
1219 /* Return a positive value if PRE denotes the location of a token that
kono
parents: 67
diff changeset
1220 comes before the token of POST, 0 if PRE denotes the location of
kono
parents: 67
diff changeset
1221 the same token as the token for POST, and a negative value
kono
parents: 67
diff changeset
1222 otherwise. */
kono
parents: 67
diff changeset
1223 int linemap_compare_locations (struct line_maps *set,
kono
parents: 67
diff changeset
1224 source_location pre,
kono
parents: 67
diff changeset
1225 source_location post);
kono
parents: 67
diff changeset
1226
kono
parents: 67
diff changeset
1227 /* Return TRUE if LOC_A denotes the location a token that comes
kono
parents: 67
diff changeset
1228 topogically before the token denoted by location LOC_B, or if they
kono
parents: 67
diff changeset
1229 are equal. */
kono
parents: 67
diff changeset
1230 inline bool
kono
parents: 67
diff changeset
1231 linemap_location_before_p (struct line_maps *set,
kono
parents: 67
diff changeset
1232 source_location loc_a,
kono
parents: 67
diff changeset
1233 source_location loc_b)
kono
parents: 67
diff changeset
1234 {
kono
parents: 67
diff changeset
1235 return linemap_compare_locations (set, loc_a, loc_b) >= 0;
kono
parents: 67
diff changeset
1236 }
kono
parents: 67
diff changeset
1237
kono
parents: 67
diff changeset
1238 typedef struct
kono
parents: 67
diff changeset
1239 {
kono
parents: 67
diff changeset
1240 /* The name of the source file involved. */
kono
parents: 67
diff changeset
1241 const char *file;
kono
parents: 67
diff changeset
1242
kono
parents: 67
diff changeset
1243 /* The line-location in the source file. */
kono
parents: 67
diff changeset
1244 int line;
kono
parents: 67
diff changeset
1245
kono
parents: 67
diff changeset
1246 int column;
kono
parents: 67
diff changeset
1247
kono
parents: 67
diff changeset
1248 void *data;
kono
parents: 67
diff changeset
1249
kono
parents: 67
diff changeset
1250 /* In a system header?. */
kono
parents: 67
diff changeset
1251 bool sysp;
kono
parents: 67
diff changeset
1252 } expanded_location;
kono
parents: 67
diff changeset
1253
kono
parents: 67
diff changeset
1254 /* Both gcc and emacs number source *lines* starting at 1, but
kono
parents: 67
diff changeset
1255 they have differing conventions for *columns*.
kono
parents: 67
diff changeset
1256
kono
parents: 67
diff changeset
1257 GCC uses a 1-based convention for source columns,
kono
parents: 67
diff changeset
1258 whereas Emacs's M-x column-number-mode uses a 0-based convention.
kono
parents: 67
diff changeset
1259
kono
parents: 67
diff changeset
1260 For example, an error in the initial, left-hand
kono
parents: 67
diff changeset
1261 column of source line 3 is reported by GCC as:
kono
parents: 67
diff changeset
1262
kono
parents: 67
diff changeset
1263 some-file.c:3:1: error: ...etc...
kono
parents: 67
diff changeset
1264
kono
parents: 67
diff changeset
1265 On navigating to the location of that error in Emacs
kono
parents: 67
diff changeset
1266 (e.g. via "next-error"),
kono
parents: 67
diff changeset
1267 the locus is reported in the Mode Line
kono
parents: 67
diff changeset
1268 (assuming M-x column-number-mode) as:
kono
parents: 67
diff changeset
1269
kono
parents: 67
diff changeset
1270 some-file.c 10% (3, 0)
kono
parents: 67
diff changeset
1271
kono
parents: 67
diff changeset
1272 i.e. "3:1:" in GCC corresponds to "(3, 0)" in Emacs. */
kono
parents: 67
diff changeset
1273
kono
parents: 67
diff changeset
1274 /* A location within a rich_location: a caret&range, with
kono
parents: 67
diff changeset
1275 the caret potentially flagged for display. */
kono
parents: 67
diff changeset
1276
kono
parents: 67
diff changeset
1277 struct location_range
kono
parents: 67
diff changeset
1278 {
kono
parents: 67
diff changeset
1279 source_location m_loc;
kono
parents: 67
diff changeset
1280
kono
parents: 67
diff changeset
1281 /* Should a caret be drawn for this range? Typically this is
kono
parents: 67
diff changeset
1282 true for the 0th range, and false for subsequent ranges,
kono
parents: 67
diff changeset
1283 but the Fortran frontend overrides this for rendering things like:
kono
parents: 67
diff changeset
1284
kono
parents: 67
diff changeset
1285 x = x + y
kono
parents: 67
diff changeset
1286 1 2
kono
parents: 67
diff changeset
1287 Error: Shapes for operands at (1) and (2) are not conformable
kono
parents: 67
diff changeset
1288
kono
parents: 67
diff changeset
1289 where "1" and "2" are notionally carets. */
kono
parents: 67
diff changeset
1290 bool m_show_caret_p;
kono
parents: 67
diff changeset
1291 };
kono
parents: 67
diff changeset
1292
kono
parents: 67
diff changeset
1293 /* A partially-embedded vec for use within rich_location for storing
kono
parents: 67
diff changeset
1294 ranges and fix-it hints.
kono
parents: 67
diff changeset
1295
kono
parents: 67
diff changeset
1296 Elements [0..NUM_EMBEDDED) are allocated within m_embed, after
kono
parents: 67
diff changeset
1297 that they are within the dynamically-allocated m_extra.
kono
parents: 67
diff changeset
1298
kono
parents: 67
diff changeset
1299 This allows for static allocation in the common case, whilst
kono
parents: 67
diff changeset
1300 supporting the rarer case of an arbitrary number of elements.
kono
parents: 67
diff changeset
1301
kono
parents: 67
diff changeset
1302 Dynamic allocation is not performed unless it's needed. */
kono
parents: 67
diff changeset
1303
kono
parents: 67
diff changeset
1304 template <typename T, int NUM_EMBEDDED>
kono
parents: 67
diff changeset
1305 class semi_embedded_vec
kono
parents: 67
diff changeset
1306 {
kono
parents: 67
diff changeset
1307 public:
kono
parents: 67
diff changeset
1308 semi_embedded_vec ();
kono
parents: 67
diff changeset
1309 ~semi_embedded_vec ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1310
111
kono
parents: 67
diff changeset
1311 unsigned int count () const { return m_num; }
kono
parents: 67
diff changeset
1312 T& operator[] (int idx);
kono
parents: 67
diff changeset
1313 const T& operator[] (int idx) const;
kono
parents: 67
diff changeset
1314
kono
parents: 67
diff changeset
1315 void push (const T&);
kono
parents: 67
diff changeset
1316 void truncate (int len);
kono
parents: 67
diff changeset
1317
kono
parents: 67
diff changeset
1318 private:
kono
parents: 67
diff changeset
1319 int m_num;
kono
parents: 67
diff changeset
1320 T m_embedded[NUM_EMBEDDED];
kono
parents: 67
diff changeset
1321 int m_alloc;
kono
parents: 67
diff changeset
1322 T *m_extra;
kono
parents: 67
diff changeset
1323 };
kono
parents: 67
diff changeset
1324
kono
parents: 67
diff changeset
1325 /* Constructor for semi_embedded_vec. In particular, no dynamic allocation
kono
parents: 67
diff changeset
1326 is done. */
kono
parents: 67
diff changeset
1327
kono
parents: 67
diff changeset
1328 template <typename T, int NUM_EMBEDDED>
kono
parents: 67
diff changeset
1329 semi_embedded_vec<T, NUM_EMBEDDED>::semi_embedded_vec ()
kono
parents: 67
diff changeset
1330 : m_num (0), m_alloc (0), m_extra (NULL)
kono
parents: 67
diff changeset
1331 {
kono
parents: 67
diff changeset
1332 }
kono
parents: 67
diff changeset
1333
kono
parents: 67
diff changeset
1334 /* semi_embedded_vec's dtor. Release any dynamically-allocated memory. */
kono
parents: 67
diff changeset
1335
kono
parents: 67
diff changeset
1336 template <typename T, int NUM_EMBEDDED>
kono
parents: 67
diff changeset
1337 semi_embedded_vec<T, NUM_EMBEDDED>::~semi_embedded_vec ()
kono
parents: 67
diff changeset
1338 {
kono
parents: 67
diff changeset
1339 XDELETEVEC (m_extra);
kono
parents: 67
diff changeset
1340 }
kono
parents: 67
diff changeset
1341
kono
parents: 67
diff changeset
1342 /* Look up element IDX, mutably. */
kono
parents: 67
diff changeset
1343
kono
parents: 67
diff changeset
1344 template <typename T, int NUM_EMBEDDED>
kono
parents: 67
diff changeset
1345 T&
kono
parents: 67
diff changeset
1346 semi_embedded_vec<T, NUM_EMBEDDED>::operator[] (int idx)
kono
parents: 67
diff changeset
1347 {
kono
parents: 67
diff changeset
1348 linemap_assert (idx < m_num);
kono
parents: 67
diff changeset
1349 if (idx < NUM_EMBEDDED)
kono
parents: 67
diff changeset
1350 return m_embedded[idx];
kono
parents: 67
diff changeset
1351 else
kono
parents: 67
diff changeset
1352 {
kono
parents: 67
diff changeset
1353 linemap_assert (m_extra != NULL);
kono
parents: 67
diff changeset
1354 return m_extra[idx - NUM_EMBEDDED];
kono
parents: 67
diff changeset
1355 }
kono
parents: 67
diff changeset
1356 }
kono
parents: 67
diff changeset
1357
kono
parents: 67
diff changeset
1358 /* Look up element IDX (const). */
kono
parents: 67
diff changeset
1359
kono
parents: 67
diff changeset
1360 template <typename T, int NUM_EMBEDDED>
kono
parents: 67
diff changeset
1361 const T&
kono
parents: 67
diff changeset
1362 semi_embedded_vec<T, NUM_EMBEDDED>::operator[] (int idx) const
kono
parents: 67
diff changeset
1363 {
kono
parents: 67
diff changeset
1364 linemap_assert (idx < m_num);
kono
parents: 67
diff changeset
1365 if (idx < NUM_EMBEDDED)
kono
parents: 67
diff changeset
1366 return m_embedded[idx];
kono
parents: 67
diff changeset
1367 else
kono
parents: 67
diff changeset
1368 {
kono
parents: 67
diff changeset
1369 linemap_assert (m_extra != NULL);
kono
parents: 67
diff changeset
1370 return m_extra[idx - NUM_EMBEDDED];
kono
parents: 67
diff changeset
1371 }
kono
parents: 67
diff changeset
1372 }
kono
parents: 67
diff changeset
1373
kono
parents: 67
diff changeset
1374 /* Append VALUE to the end of the semi_embedded_vec. */
kono
parents: 67
diff changeset
1375
kono
parents: 67
diff changeset
1376 template <typename T, int NUM_EMBEDDED>
kono
parents: 67
diff changeset
1377 void
kono
parents: 67
diff changeset
1378 semi_embedded_vec<T, NUM_EMBEDDED>::push (const T& value)
kono
parents: 67
diff changeset
1379 {
kono
parents: 67
diff changeset
1380 int idx = m_num++;
kono
parents: 67
diff changeset
1381 if (idx < NUM_EMBEDDED)
kono
parents: 67
diff changeset
1382 m_embedded[idx] = value;
kono
parents: 67
diff changeset
1383 else
kono
parents: 67
diff changeset
1384 {
kono
parents: 67
diff changeset
1385 /* Offset "idx" to be an index within m_extra. */
kono
parents: 67
diff changeset
1386 idx -= NUM_EMBEDDED;
kono
parents: 67
diff changeset
1387 if (NULL == m_extra)
kono
parents: 67
diff changeset
1388 {
kono
parents: 67
diff changeset
1389 linemap_assert (m_alloc == 0);
kono
parents: 67
diff changeset
1390 m_alloc = 16;
kono
parents: 67
diff changeset
1391 m_extra = XNEWVEC (T, m_alloc);
kono
parents: 67
diff changeset
1392 }
kono
parents: 67
diff changeset
1393 else if (idx >= m_alloc)
kono
parents: 67
diff changeset
1394 {
kono
parents: 67
diff changeset
1395 linemap_assert (m_alloc > 0);
kono
parents: 67
diff changeset
1396 m_alloc *= 2;
kono
parents: 67
diff changeset
1397 m_extra = XRESIZEVEC (T, m_extra, m_alloc);
kono
parents: 67
diff changeset
1398 }
kono
parents: 67
diff changeset
1399 linemap_assert (m_extra);
kono
parents: 67
diff changeset
1400 linemap_assert (idx < m_alloc);
kono
parents: 67
diff changeset
1401 m_extra[idx] = value;
kono
parents: 67
diff changeset
1402 }
kono
parents: 67
diff changeset
1403 }
kono
parents: 67
diff changeset
1404
kono
parents: 67
diff changeset
1405 /* Truncate to length LEN. No deallocation is performed. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1406
111
kono
parents: 67
diff changeset
1407 template <typename T, int NUM_EMBEDDED>
kono
parents: 67
diff changeset
1408 void
kono
parents: 67
diff changeset
1409 semi_embedded_vec<T, NUM_EMBEDDED>::truncate (int len)
kono
parents: 67
diff changeset
1410 {
kono
parents: 67
diff changeset
1411 linemap_assert (len <= m_num);
kono
parents: 67
diff changeset
1412 m_num = len;
kono
parents: 67
diff changeset
1413 }
kono
parents: 67
diff changeset
1414
kono
parents: 67
diff changeset
1415 class fixit_hint;
kono
parents: 67
diff changeset
1416
kono
parents: 67
diff changeset
1417 /* A "rich" source code location, for use when printing diagnostics.
kono
parents: 67
diff changeset
1418 A rich_location has one or more carets&ranges, where the carets
kono
parents: 67
diff changeset
1419 are optional. These are referred to as "ranges" from here.
kono
parents: 67
diff changeset
1420 Typically the zeroth range has a caret; other ranges sometimes
kono
parents: 67
diff changeset
1421 have carets.
kono
parents: 67
diff changeset
1422
kono
parents: 67
diff changeset
1423 The "primary" location of a rich_location is the caret of range 0,
kono
parents: 67
diff changeset
1424 used for determining the line/column when printing diagnostic
kono
parents: 67
diff changeset
1425 text, such as:
kono
parents: 67
diff changeset
1426
kono
parents: 67
diff changeset
1427 some-file.c:3:1: error: ...etc...
kono
parents: 67
diff changeset
1428
kono
parents: 67
diff changeset
1429 Additional ranges may be added to help the user identify other
kono
parents: 67
diff changeset
1430 pertinent clauses in a diagnostic.
kono
parents: 67
diff changeset
1431
kono
parents: 67
diff changeset
1432 rich_location instances are intended to be allocated on the stack
kono
parents: 67
diff changeset
1433 when generating diagnostics, and to be short-lived.
kono
parents: 67
diff changeset
1434
kono
parents: 67
diff changeset
1435 Examples of rich locations
kono
parents: 67
diff changeset
1436 --------------------------
kono
parents: 67
diff changeset
1437
kono
parents: 67
diff changeset
1438 Example A
kono
parents: 67
diff changeset
1439 *********
kono
parents: 67
diff changeset
1440 int i = "foo";
kono
parents: 67
diff changeset
1441 ^
kono
parents: 67
diff changeset
1442 This "rich" location is simply a single range (range 0), with
kono
parents: 67
diff changeset
1443 caret = start = finish at the given point.
kono
parents: 67
diff changeset
1444
kono
parents: 67
diff changeset
1445 Example B
kono
parents: 67
diff changeset
1446 *********
kono
parents: 67
diff changeset
1447 a = (foo && bar)
kono
parents: 67
diff changeset
1448 ~~~~~^~~~~~~
kono
parents: 67
diff changeset
1449 This rich location has a single range (range 0), with the caret
kono
parents: 67
diff changeset
1450 at the first "&", and the start/finish at the parentheses.
kono
parents: 67
diff changeset
1451 Compare with example C below.
kono
parents: 67
diff changeset
1452
kono
parents: 67
diff changeset
1453 Example C
kono
parents: 67
diff changeset
1454 *********
kono
parents: 67
diff changeset
1455 a = (foo && bar)
kono
parents: 67
diff changeset
1456 ~~~ ^~ ~~~
kono
parents: 67
diff changeset
1457 This rich location has three ranges:
kono
parents: 67
diff changeset
1458 - Range 0 has its caret and start location at the first "&" and
kono
parents: 67
diff changeset
1459 end at the second "&.
kono
parents: 67
diff changeset
1460 - Range 1 has its start and finish at the "f" and "o" of "foo";
kono
parents: 67
diff changeset
1461 the caret is not flagged for display, but is perhaps at the "f"
kono
parents: 67
diff changeset
1462 of "foo".
kono
parents: 67
diff changeset
1463 - Similarly, range 2 has its start and finish at the "b" and "r" of
kono
parents: 67
diff changeset
1464 "bar"; the caret is not flagged for display, but is perhaps at the
kono
parents: 67
diff changeset
1465 "b" of "bar".
kono
parents: 67
diff changeset
1466 Compare with example B above.
kono
parents: 67
diff changeset
1467
kono
parents: 67
diff changeset
1468 Example D (Fortran frontend)
kono
parents: 67
diff changeset
1469 ****************************
kono
parents: 67
diff changeset
1470 x = x + y
kono
parents: 67
diff changeset
1471 1 2
kono
parents: 67
diff changeset
1472 This rich location has range 0 at "1", and range 1 at "2".
kono
parents: 67
diff changeset
1473 Both are flagged for caret display. Both ranges have start/finish
kono
parents: 67
diff changeset
1474 equal to their caret point. The frontend overrides the diagnostic
kono
parents: 67
diff changeset
1475 context's default caret character for these ranges.
kono
parents: 67
diff changeset
1476
kono
parents: 67
diff changeset
1477 Example E
kono
parents: 67
diff changeset
1478 *********
kono
parents: 67
diff changeset
1479 printf ("arg0: %i arg1: %s arg2: %i",
kono
parents: 67
diff changeset
1480 ^~
kono
parents: 67
diff changeset
1481 100, 101, 102);
kono
parents: 67
diff changeset
1482 ~~~
kono
parents: 67
diff changeset
1483 This rich location has two ranges:
kono
parents: 67
diff changeset
1484 - range 0 is at the "%s" with start = caret = "%" and finish at
kono
parents: 67
diff changeset
1485 the "s".
kono
parents: 67
diff changeset
1486 - range 1 has start/finish covering the "101" and is not flagged for
kono
parents: 67
diff changeset
1487 caret printing; it is perhaps at the start of "101".
kono
parents: 67
diff changeset
1488
kono
parents: 67
diff changeset
1489
kono
parents: 67
diff changeset
1490 Fix-it hints
kono
parents: 67
diff changeset
1491 ------------
kono
parents: 67
diff changeset
1492
kono
parents: 67
diff changeset
1493 Rich locations can also contain "fix-it hints", giving suggestions
kono
parents: 67
diff changeset
1494 for the user on how to edit their code to fix a problem. These
kono
parents: 67
diff changeset
1495 can be expressed as insertions, replacements, and removals of text.
kono
parents: 67
diff changeset
1496 The edits by default are relative to the zeroth range within the
kono
parents: 67
diff changeset
1497 rich_location, but optionally they can be expressed relative to
kono
parents: 67
diff changeset
1498 other locations (using various overloaded methods of the form
kono
parents: 67
diff changeset
1499 rich_location::add_fixit_*).
kono
parents: 67
diff changeset
1500
kono
parents: 67
diff changeset
1501 For example:
kono
parents: 67
diff changeset
1502
kono
parents: 67
diff changeset
1503 Example F: fix-it hint: insert_before
kono
parents: 67
diff changeset
1504 *************************************
kono
parents: 67
diff changeset
1505 ptr = arr[0];
kono
parents: 67
diff changeset
1506 ^~~~~~
kono
parents: 67
diff changeset
1507 &
kono
parents: 67
diff changeset
1508 This rich location has a single range (range 0) covering "arr[0]",
kono
parents: 67
diff changeset
1509 with the caret at the start. The rich location has a single
kono
parents: 67
diff changeset
1510 insertion fix-it hint, inserted before range 0, added via
kono
parents: 67
diff changeset
1511 richloc.add_fixit_insert_before ("&");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1512
111
kono
parents: 67
diff changeset
1513 Example G: multiple fix-it hints: insert_before and insert_after
kono
parents: 67
diff changeset
1514 ****************************************************************
kono
parents: 67
diff changeset
1515 #define FN(ARG0, ARG1, ARG2) fn(ARG0, ARG1, ARG2)
kono
parents: 67
diff changeset
1516 ^~~~ ^~~~ ^~~~
kono
parents: 67
diff changeset
1517 ( ) ( ) ( )
kono
parents: 67
diff changeset
1518 This rich location has three ranges, covering "arg0", "arg1",
kono
parents: 67
diff changeset
1519 and "arg2", all with caret-printing enabled.
kono
parents: 67
diff changeset
1520 The rich location has 6 insertion fix-it hints: each arg
kono
parents: 67
diff changeset
1521 has a pair of insertion fix-it hints, suggesting wrapping
kono
parents: 67
diff changeset
1522 them with parentheses: one a '(' inserted before,
kono
parents: 67
diff changeset
1523 the other a ')' inserted after, added via
kono
parents: 67
diff changeset
1524 richloc.add_fixit_insert_before (LOC, "(");
kono
parents: 67
diff changeset
1525 and
kono
parents: 67
diff changeset
1526 richloc.add_fixit_insert_after (LOC, ")");
kono
parents: 67
diff changeset
1527
kono
parents: 67
diff changeset
1528 Example H: fix-it hint: removal
kono
parents: 67
diff changeset
1529 *******************************
kono
parents: 67
diff changeset
1530 struct s {int i};;
kono
parents: 67
diff changeset
1531 ^
kono
parents: 67
diff changeset
1532 -
kono
parents: 67
diff changeset
1533 This rich location has a single range at the stray trailing
kono
parents: 67
diff changeset
1534 semicolon, along with a single removal fix-it hint, covering
kono
parents: 67
diff changeset
1535 the same range, added via:
kono
parents: 67
diff changeset
1536 richloc.add_fixit_remove ();
kono
parents: 67
diff changeset
1537
kono
parents: 67
diff changeset
1538 Example I: fix-it hint: replace
kono
parents: 67
diff changeset
1539 *******************************
kono
parents: 67
diff changeset
1540 c = s.colour;
kono
parents: 67
diff changeset
1541 ^~~~~~
kono
parents: 67
diff changeset
1542 color
kono
parents: 67
diff changeset
1543 This rich location has a single range (range 0) covering "colour",
kono
parents: 67
diff changeset
1544 and a single "replace" fix-it hint, covering the same range,
kono
parents: 67
diff changeset
1545 added via
kono
parents: 67
diff changeset
1546 richloc.add_fixit_replace ("color");
kono
parents: 67
diff changeset
1547
kono
parents: 67
diff changeset
1548 Adding a fix-it hint can fail: for example, attempts to insert content
kono
parents: 67
diff changeset
1549 at the transition between two line maps may fail due to there being no
kono
parents: 67
diff changeset
1550 source_location (aka location_t) value to express the new location.
kono
parents: 67
diff changeset
1551
kono
parents: 67
diff changeset
1552 Attempts to add a fix-it hint within a macro expansion will fail.
kono
parents: 67
diff changeset
1553
kono
parents: 67
diff changeset
1554 There is only limited support for newline characters in fix-it hints:
kono
parents: 67
diff changeset
1555 only hints with newlines which insert an entire new line are permitted,
kono
parents: 67
diff changeset
1556 inserting at the start of a line, and finishing with a newline
kono
parents: 67
diff changeset
1557 (with no interior newline characters). Other attempts to add
kono
parents: 67
diff changeset
1558 fix-it hints containing newline characters will fail.
kono
parents: 67
diff changeset
1559 Similarly, attempts to delete or replace a range *affecting* multiple
kono
parents: 67
diff changeset
1560 lines will fail.
kono
parents: 67
diff changeset
1561
kono
parents: 67
diff changeset
1562 The rich_location API handles these failures gracefully, so that
kono
parents: 67
diff changeset
1563 diagnostics can attempt to add fix-it hints without each needing
kono
parents: 67
diff changeset
1564 extensive checking.
kono
parents: 67
diff changeset
1565
kono
parents: 67
diff changeset
1566 Fix-it hints within a rich_location are "atomic": if any hints can't
kono
parents: 67
diff changeset
1567 be applied, none of them will be (tracked by the m_seen_impossible_fixit
kono
parents: 67
diff changeset
1568 flag), and no fix-its hints will be displayed for that rich_location.
kono
parents: 67
diff changeset
1569 This implies that diagnostic messages need to be worded in such a way
kono
parents: 67
diff changeset
1570 that they make sense whether or not the fix-it hints are displayed,
kono
parents: 67
diff changeset
1571 or that richloc.seen_impossible_fixit_p () should be checked before
kono
parents: 67
diff changeset
1572 issuing the diagnostics. */
kono
parents: 67
diff changeset
1573
kono
parents: 67
diff changeset
1574 class rich_location
kono
parents: 67
diff changeset
1575 {
kono
parents: 67
diff changeset
1576 public:
kono
parents: 67
diff changeset
1577 /* Constructors. */
kono
parents: 67
diff changeset
1578
kono
parents: 67
diff changeset
1579 /* Constructing from a location. */
kono
parents: 67
diff changeset
1580 rich_location (line_maps *set, source_location loc);
kono
parents: 67
diff changeset
1581
kono
parents: 67
diff changeset
1582 /* Destructor. */
kono
parents: 67
diff changeset
1583 ~rich_location ();
kono
parents: 67
diff changeset
1584
kono
parents: 67
diff changeset
1585 /* Accessors. */
kono
parents: 67
diff changeset
1586 source_location get_loc () const { return get_loc (0); }
kono
parents: 67
diff changeset
1587 source_location get_loc (unsigned int idx) const;
kono
parents: 67
diff changeset
1588
kono
parents: 67
diff changeset
1589 void
kono
parents: 67
diff changeset
1590 add_range (source_location loc, bool show_caret_p);
kono
parents: 67
diff changeset
1591
kono
parents: 67
diff changeset
1592 void
kono
parents: 67
diff changeset
1593 set_range (line_maps *set, unsigned int idx, source_location loc,
kono
parents: 67
diff changeset
1594 bool show_caret_p);
kono
parents: 67
diff changeset
1595
kono
parents: 67
diff changeset
1596 unsigned int get_num_locations () const { return m_ranges.count (); }
kono
parents: 67
diff changeset
1597
kono
parents: 67
diff changeset
1598 const location_range *get_range (unsigned int idx) const;
kono
parents: 67
diff changeset
1599 location_range *get_range (unsigned int idx);
kono
parents: 67
diff changeset
1600
kono
parents: 67
diff changeset
1601 expanded_location get_expanded_location (unsigned int idx);
kono
parents: 67
diff changeset
1602
kono
parents: 67
diff changeset
1603 void
kono
parents: 67
diff changeset
1604 override_column (int column);
kono
parents: 67
diff changeset
1605
kono
parents: 67
diff changeset
1606 /* Fix-it hints. */
kono
parents: 67
diff changeset
1607
kono
parents: 67
diff changeset
1608 /* Methods for adding insertion fix-it hints. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1609
111
kono
parents: 67
diff changeset
1610 /* Suggest inserting NEW_CONTENT immediately before the primary
kono
parents: 67
diff changeset
1611 range's start. */
kono
parents: 67
diff changeset
1612 void
kono
parents: 67
diff changeset
1613 add_fixit_insert_before (const char *new_content);
kono
parents: 67
diff changeset
1614
kono
parents: 67
diff changeset
1615 /* Suggest inserting NEW_CONTENT immediately before the start of WHERE. */
kono
parents: 67
diff changeset
1616 void
kono
parents: 67
diff changeset
1617 add_fixit_insert_before (source_location where,
kono
parents: 67
diff changeset
1618 const char *new_content);
kono
parents: 67
diff changeset
1619
kono
parents: 67
diff changeset
1620 /* Suggest inserting NEW_CONTENT immediately after the end of the primary
kono
parents: 67
diff changeset
1621 range. */
kono
parents: 67
diff changeset
1622 void
kono
parents: 67
diff changeset
1623 add_fixit_insert_after (const char *new_content);
kono
parents: 67
diff changeset
1624
kono
parents: 67
diff changeset
1625 /* Suggest inserting NEW_CONTENT immediately after the end of WHERE. */
kono
parents: 67
diff changeset
1626 void
kono
parents: 67
diff changeset
1627 add_fixit_insert_after (source_location where,
kono
parents: 67
diff changeset
1628 const char *new_content);
kono
parents: 67
diff changeset
1629
kono
parents: 67
diff changeset
1630 /* Methods for adding removal fix-it hints. */
kono
parents: 67
diff changeset
1631
kono
parents: 67
diff changeset
1632 /* Suggest removing the content covered by range 0. */
kono
parents: 67
diff changeset
1633 void
kono
parents: 67
diff changeset
1634 add_fixit_remove ();
kono
parents: 67
diff changeset
1635
kono
parents: 67
diff changeset
1636 /* Suggest removing the content covered between the start and finish
kono
parents: 67
diff changeset
1637 of WHERE. */
kono
parents: 67
diff changeset
1638 void
kono
parents: 67
diff changeset
1639 add_fixit_remove (source_location where);
kono
parents: 67
diff changeset
1640
kono
parents: 67
diff changeset
1641 /* Suggest removing the content covered by SRC_RANGE. */
kono
parents: 67
diff changeset
1642 void
kono
parents: 67
diff changeset
1643 add_fixit_remove (source_range src_range);
kono
parents: 67
diff changeset
1644
kono
parents: 67
diff changeset
1645 /* Methods for adding "replace" fix-it hints. */
kono
parents: 67
diff changeset
1646
kono
parents: 67
diff changeset
1647 /* Suggest replacing the content covered by range 0 with NEW_CONTENT. */
kono
parents: 67
diff changeset
1648 void
kono
parents: 67
diff changeset
1649 add_fixit_replace (const char *new_content);
kono
parents: 67
diff changeset
1650
kono
parents: 67
diff changeset
1651 /* Suggest replacing the content between the start and finish of
kono
parents: 67
diff changeset
1652 WHERE with NEW_CONTENT. */
kono
parents: 67
diff changeset
1653 void
kono
parents: 67
diff changeset
1654 add_fixit_replace (source_location where,
kono
parents: 67
diff changeset
1655 const char *new_content);
kono
parents: 67
diff changeset
1656
kono
parents: 67
diff changeset
1657 /* Suggest replacing the content covered by SRC_RANGE with
kono
parents: 67
diff changeset
1658 NEW_CONTENT. */
kono
parents: 67
diff changeset
1659 void
kono
parents: 67
diff changeset
1660 add_fixit_replace (source_range src_range,
kono
parents: 67
diff changeset
1661 const char *new_content);
kono
parents: 67
diff changeset
1662
kono
parents: 67
diff changeset
1663 unsigned int get_num_fixit_hints () const { return m_fixit_hints.count (); }
kono
parents: 67
diff changeset
1664 fixit_hint *get_fixit_hint (int idx) const { return m_fixit_hints[idx]; }
kono
parents: 67
diff changeset
1665 fixit_hint *get_last_fixit_hint () const;
kono
parents: 67
diff changeset
1666 bool seen_impossible_fixit_p () const { return m_seen_impossible_fixit; }
kono
parents: 67
diff changeset
1667
kono
parents: 67
diff changeset
1668 /* Set this if the fix-it hints are not suitable to be
kono
parents: 67
diff changeset
1669 automatically applied.
kono
parents: 67
diff changeset
1670
kono
parents: 67
diff changeset
1671 For example, if you are suggesting more than one
kono
parents: 67
diff changeset
1672 mutually exclusive solution to a problem, then
kono
parents: 67
diff changeset
1673 it doesn't make sense to apply all of the solutions;
kono
parents: 67
diff changeset
1674 manual intervention is required.
kono
parents: 67
diff changeset
1675
kono
parents: 67
diff changeset
1676 If set, then the fix-it hints in the rich_location will
kono
parents: 67
diff changeset
1677 be printed, but will not be added to generated patches,
kono
parents: 67
diff changeset
1678 or affect the modified version of the file. */
kono
parents: 67
diff changeset
1679 void fixits_cannot_be_auto_applied ()
kono
parents: 67
diff changeset
1680 {
kono
parents: 67
diff changeset
1681 m_fixits_cannot_be_auto_applied = true;
kono
parents: 67
diff changeset
1682 }
kono
parents: 67
diff changeset
1683
kono
parents: 67
diff changeset
1684 bool fixits_can_be_auto_applied_p () const
kono
parents: 67
diff changeset
1685 {
kono
parents: 67
diff changeset
1686 return !m_fixits_cannot_be_auto_applied;
kono
parents: 67
diff changeset
1687 }
kono
parents: 67
diff changeset
1688
kono
parents: 67
diff changeset
1689 private:
kono
parents: 67
diff changeset
1690 bool reject_impossible_fixit (source_location where);
kono
parents: 67
diff changeset
1691 void stop_supporting_fixits ();
kono
parents: 67
diff changeset
1692 void maybe_add_fixit (source_location start,
kono
parents: 67
diff changeset
1693 source_location next_loc,
kono
parents: 67
diff changeset
1694 const char *new_content);
kono
parents: 67
diff changeset
1695
kono
parents: 67
diff changeset
1696 public:
kono
parents: 67
diff changeset
1697 static const int STATICALLY_ALLOCATED_RANGES = 3;
kono
parents: 67
diff changeset
1698
kono
parents: 67
diff changeset
1699 protected:
kono
parents: 67
diff changeset
1700 line_maps *m_line_table;
kono
parents: 67
diff changeset
1701 semi_embedded_vec <location_range, STATICALLY_ALLOCATED_RANGES> m_ranges;
kono
parents: 67
diff changeset
1702
kono
parents: 67
diff changeset
1703 int m_column_override;
kono
parents: 67
diff changeset
1704
kono
parents: 67
diff changeset
1705 bool m_have_expanded_location;
kono
parents: 67
diff changeset
1706 expanded_location m_expanded_location;
kono
parents: 67
diff changeset
1707
kono
parents: 67
diff changeset
1708 static const int MAX_STATIC_FIXIT_HINTS = 2;
kono
parents: 67
diff changeset
1709 semi_embedded_vec <fixit_hint *, MAX_STATIC_FIXIT_HINTS> m_fixit_hints;
kono
parents: 67
diff changeset
1710
kono
parents: 67
diff changeset
1711 bool m_seen_impossible_fixit;
kono
parents: 67
diff changeset
1712 bool m_fixits_cannot_be_auto_applied;
kono
parents: 67
diff changeset
1713 };
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1714
111
kono
parents: 67
diff changeset
1715 /* A fix-it hint: a suggested insertion, replacement, or deletion of text.
kono
parents: 67
diff changeset
1716 We handle these three types of edit with one class, by representing
kono
parents: 67
diff changeset
1717 them as replacement of a half-open range:
kono
parents: 67
diff changeset
1718 [start, next_loc)
kono
parents: 67
diff changeset
1719 Insertions have start == next_loc: "replace" the empty string at the
kono
parents: 67
diff changeset
1720 start location with the new string.
kono
parents: 67
diff changeset
1721 Deletions are replacement with the empty string.
kono
parents: 67
diff changeset
1722
kono
parents: 67
diff changeset
1723 There is only limited support for newline characters in fix-it hints
kono
parents: 67
diff changeset
1724 as noted above in the comment for class rich_location.
kono
parents: 67
diff changeset
1725 A fixit_hint instance can have at most one newline character; if
kono
parents: 67
diff changeset
1726 present, the newline character must be the final character of
kono
parents: 67
diff changeset
1727 the content (preventing e.g. fix-its that split a pre-existing line). */
kono
parents: 67
diff changeset
1728
kono
parents: 67
diff changeset
1729 class fixit_hint
kono
parents: 67
diff changeset
1730 {
kono
parents: 67
diff changeset
1731 public:
kono
parents: 67
diff changeset
1732 fixit_hint (source_location start,
kono
parents: 67
diff changeset
1733 source_location next_loc,
kono
parents: 67
diff changeset
1734 const char *new_content);
kono
parents: 67
diff changeset
1735 ~fixit_hint () { free (m_bytes); }
kono
parents: 67
diff changeset
1736
kono
parents: 67
diff changeset
1737 bool affects_line_p (const char *file, int line) const;
kono
parents: 67
diff changeset
1738 source_location get_start_loc () const { return m_start; }
kono
parents: 67
diff changeset
1739 source_location get_next_loc () const { return m_next_loc; }
kono
parents: 67
diff changeset
1740 bool maybe_append (source_location start,
kono
parents: 67
diff changeset
1741 source_location next_loc,
kono
parents: 67
diff changeset
1742 const char *new_content);
kono
parents: 67
diff changeset
1743
kono
parents: 67
diff changeset
1744 const char *get_string () const { return m_bytes; }
kono
parents: 67
diff changeset
1745 size_t get_length () const { return m_len; }
kono
parents: 67
diff changeset
1746
kono
parents: 67
diff changeset
1747 bool insertion_p () const { return m_start == m_next_loc; }
kono
parents: 67
diff changeset
1748
kono
parents: 67
diff changeset
1749 bool ends_with_newline_p () const;
kono
parents: 67
diff changeset
1750
kono
parents: 67
diff changeset
1751 private:
kono
parents: 67
diff changeset
1752 /* We don't use source_range here since, unlike most places,
kono
parents: 67
diff changeset
1753 this is a half-open/half-closed range:
kono
parents: 67
diff changeset
1754 [start, next_loc)
kono
parents: 67
diff changeset
1755 so that we can support insertion via start == next_loc. */
kono
parents: 67
diff changeset
1756 source_location m_start;
kono
parents: 67
diff changeset
1757 source_location m_next_loc;
kono
parents: 67
diff changeset
1758 char *m_bytes;
kono
parents: 67
diff changeset
1759 size_t m_len;
kono
parents: 67
diff changeset
1760 };
kono
parents: 67
diff changeset
1761
kono
parents: 67
diff changeset
1762
kono
parents: 67
diff changeset
1763 /* This is enum is used by the function linemap_resolve_location
kono
parents: 67
diff changeset
1764 below. The meaning of the values is explained in the comment of
kono
parents: 67
diff changeset
1765 that function. */
kono
parents: 67
diff changeset
1766 enum location_resolution_kind
kono
parents: 67
diff changeset
1767 {
kono
parents: 67
diff changeset
1768 LRK_MACRO_EXPANSION_POINT,
kono
parents: 67
diff changeset
1769 LRK_SPELLING_LOCATION,
kono
parents: 67
diff changeset
1770 LRK_MACRO_DEFINITION_LOCATION
kono
parents: 67
diff changeset
1771 };
kono
parents: 67
diff changeset
1772
kono
parents: 67
diff changeset
1773 /* Resolve a virtual location into either a spelling location, an
kono
parents: 67
diff changeset
1774 expansion point location or a token argument replacement point
kono
parents: 67
diff changeset
1775 location. Return the map that encodes the virtual location as well
kono
parents: 67
diff changeset
1776 as the resolved location.
kono
parents: 67
diff changeset
1777
kono
parents: 67
diff changeset
1778 If LOC is *NOT* the location of a token resulting from the
kono
parents: 67
diff changeset
1779 expansion of a macro, then the parameter LRK (which stands for
kono
parents: 67
diff changeset
1780 Location Resolution Kind) is ignored and the resulting location
kono
parents: 67
diff changeset
1781 just equals the one given in argument.
kono
parents: 67
diff changeset
1782
kono
parents: 67
diff changeset
1783 Now if LOC *IS* the location of a token resulting from the
kono
parents: 67
diff changeset
1784 expansion of a macro, this is what happens.
kono
parents: 67
diff changeset
1785
kono
parents: 67
diff changeset
1786 * If LRK is set to LRK_MACRO_EXPANSION_POINT
kono
parents: 67
diff changeset
1787 -------------------------------
kono
parents: 67
diff changeset
1788
kono
parents: 67
diff changeset
1789 The virtual location is resolved to the first macro expansion point
kono
parents: 67
diff changeset
1790 that led to this macro expansion.
kono
parents: 67
diff changeset
1791
kono
parents: 67
diff changeset
1792 * If LRK is set to LRK_SPELLING_LOCATION
kono
parents: 67
diff changeset
1793 -------------------------------------
kono
parents: 67
diff changeset
1794
kono
parents: 67
diff changeset
1795 The virtual location is resolved to the locus where the token has
kono
parents: 67
diff changeset
1796 been spelled in the source. This can follow through all the macro
kono
parents: 67
diff changeset
1797 expansions that led to the token.
kono
parents: 67
diff changeset
1798
kono
parents: 67
diff changeset
1799 * If LRK is set to LRK_MACRO_DEFINITION_LOCATION
kono
parents: 67
diff changeset
1800 --------------------------------------
kono
parents: 67
diff changeset
1801
kono
parents: 67
diff changeset
1802 The virtual location is resolved to the locus of the token in the
kono
parents: 67
diff changeset
1803 context of the macro definition.
kono
parents: 67
diff changeset
1804
kono
parents: 67
diff changeset
1805 If LOC is the locus of a token that is an argument of a
kono
parents: 67
diff changeset
1806 function-like macro [replacing a parameter in the replacement list
kono
parents: 67
diff changeset
1807 of the macro] the virtual location is resolved to the locus of the
kono
parents: 67
diff changeset
1808 parameter that is replaced, in the context of the definition of the
kono
parents: 67
diff changeset
1809 macro.
kono
parents: 67
diff changeset
1810
kono
parents: 67
diff changeset
1811 If LOC is the locus of a token that is not an argument of a
kono
parents: 67
diff changeset
1812 function-like macro, then the function behaves as if LRK was set to
kono
parents: 67
diff changeset
1813 LRK_SPELLING_LOCATION.
kono
parents: 67
diff changeset
1814
kono
parents: 67
diff changeset
1815 If LOC_MAP is not NULL, *LOC_MAP is set to the map encoding the
kono
parents: 67
diff changeset
1816 returned location. Note that if the returned location wasn't originally
kono
parents: 67
diff changeset
1817 encoded by a map, the *MAP is set to NULL. This can happen if LOC
kono
parents: 67
diff changeset
1818 resolves to a location reserved for the client code, like
kono
parents: 67
diff changeset
1819 UNKNOWN_LOCATION or BUILTINS_LOCATION in GCC. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1820
111
kono
parents: 67
diff changeset
1821 source_location linemap_resolve_location (struct line_maps *,
kono
parents: 67
diff changeset
1822 source_location loc,
kono
parents: 67
diff changeset
1823 enum location_resolution_kind lrk,
kono
parents: 67
diff changeset
1824 const line_map_ordinary **loc_map);
kono
parents: 67
diff changeset
1825
kono
parents: 67
diff changeset
1826 /* Suppose that LOC is the virtual location of a token coming from the
kono
parents: 67
diff changeset
1827 expansion of a macro M. This function then steps up to get the
kono
parents: 67
diff changeset
1828 location L of the point where M got expanded. If L is a spelling
kono
parents: 67
diff changeset
1829 location inside a macro expansion M', then this function returns
kono
parents: 67
diff changeset
1830 the point where M' was expanded. LOC_MAP is an output parameter.
kono
parents: 67
diff changeset
1831 When non-NULL, *LOC_MAP is set to the map of the returned
kono
parents: 67
diff changeset
1832 location. */
kono
parents: 67
diff changeset
1833 source_location linemap_unwind_toward_expansion (struct line_maps *,
kono
parents: 67
diff changeset
1834 source_location loc,
kono
parents: 67
diff changeset
1835 const struct line_map **loc_map);
kono
parents: 67
diff changeset
1836
kono
parents: 67
diff changeset
1837 /* If LOC is the virtual location of a token coming from the expansion
kono
parents: 67
diff changeset
1838 of a macro M and if its spelling location is reserved (e.g, a
kono
parents: 67
diff changeset
1839 location for a built-in token), then this function unwinds (using
kono
parents: 67
diff changeset
1840 linemap_unwind_toward_expansion) the location until a location that
kono
parents: 67
diff changeset
1841 is not reserved and is not in a system header is reached. In other
kono
parents: 67
diff changeset
1842 words, this unwinds the reserved location until a location that is
kono
parents: 67
diff changeset
1843 in real source code is reached.
kono
parents: 67
diff changeset
1844
kono
parents: 67
diff changeset
1845 Otherwise, if the spelling location for LOC is not reserved or if
kono
parents: 67
diff changeset
1846 LOC doesn't come from the expansion of a macro, the function
kono
parents: 67
diff changeset
1847 returns LOC as is and *MAP is not touched.
kono
parents: 67
diff changeset
1848
kono
parents: 67
diff changeset
1849 *MAP is set to the map of the returned location if the later is
kono
parents: 67
diff changeset
1850 different from LOC. */
kono
parents: 67
diff changeset
1851 source_location linemap_unwind_to_first_non_reserved_loc (struct line_maps *,
kono
parents: 67
diff changeset
1852 source_location loc,
kono
parents: 67
diff changeset
1853 const struct line_map **map);
kono
parents: 67
diff changeset
1854
kono
parents: 67
diff changeset
1855 /* Expand source code location LOC and return a user readable source
kono
parents: 67
diff changeset
1856 code location. LOC must be a spelling (non-virtual) location. If
kono
parents: 67
diff changeset
1857 it's a location < RESERVED_LOCATION_COUNT a zeroed expanded source
kono
parents: 67
diff changeset
1858 location is returned. */
kono
parents: 67
diff changeset
1859 expanded_location linemap_expand_location (struct line_maps *,
kono
parents: 67
diff changeset
1860 const struct line_map *,
kono
parents: 67
diff changeset
1861 source_location loc);
kono
parents: 67
diff changeset
1862
kono
parents: 67
diff changeset
1863 /* Statistics about maps allocation and usage as returned by
kono
parents: 67
diff changeset
1864 linemap_get_statistics. */
kono
parents: 67
diff changeset
1865 struct linemap_stats
kono
parents: 67
diff changeset
1866 {
kono
parents: 67
diff changeset
1867 long num_ordinary_maps_allocated;
kono
parents: 67
diff changeset
1868 long num_ordinary_maps_used;
kono
parents: 67
diff changeset
1869 long ordinary_maps_allocated_size;
kono
parents: 67
diff changeset
1870 long ordinary_maps_used_size;
kono
parents: 67
diff changeset
1871 long num_expanded_macros;
kono
parents: 67
diff changeset
1872 long num_macro_tokens;
kono
parents: 67
diff changeset
1873 long num_macro_maps_used;
kono
parents: 67
diff changeset
1874 long macro_maps_allocated_size;
kono
parents: 67
diff changeset
1875 long macro_maps_used_size;
kono
parents: 67
diff changeset
1876 long macro_maps_locations_size;
kono
parents: 67
diff changeset
1877 long duplicated_macro_maps_locations_size;
kono
parents: 67
diff changeset
1878 long adhoc_table_size;
kono
parents: 67
diff changeset
1879 long adhoc_table_entries_used;
kono
parents: 67
diff changeset
1880 };
kono
parents: 67
diff changeset
1881
kono
parents: 67
diff changeset
1882 /* Return the highest location emitted for a given file for which
kono
parents: 67
diff changeset
1883 there is a line map in SET. FILE_NAME is the file name to
kono
parents: 67
diff changeset
1884 consider. If the function returns TRUE, *LOC is set to the highest
kono
parents: 67
diff changeset
1885 location emitted for that file. */
kono
parents: 67
diff changeset
1886 bool linemap_get_file_highest_location (struct line_maps * set,
kono
parents: 67
diff changeset
1887 const char *file_name,
kono
parents: 67
diff changeset
1888 source_location *loc);
kono
parents: 67
diff changeset
1889
kono
parents: 67
diff changeset
1890 /* Compute and return statistics about the memory consumption of some
kono
parents: 67
diff changeset
1891 parts of the line table SET. */
kono
parents: 67
diff changeset
1892 void linemap_get_statistics (struct line_maps *, struct linemap_stats *);
kono
parents: 67
diff changeset
1893
kono
parents: 67
diff changeset
1894 /* Dump debugging information about source location LOC into the file
kono
parents: 67
diff changeset
1895 stream STREAM. SET is the line map set LOC comes from. */
kono
parents: 67
diff changeset
1896 void linemap_dump_location (struct line_maps *, source_location, FILE *);
kono
parents: 67
diff changeset
1897
kono
parents: 67
diff changeset
1898 /* Dump line map at index IX in line table SET to STREAM. If STREAM
kono
parents: 67
diff changeset
1899 is NULL, use stderr. IS_MACRO is true if the caller wants to
kono
parents: 67
diff changeset
1900 dump a macro map, false otherwise. */
kono
parents: 67
diff changeset
1901 void linemap_dump (FILE *, struct line_maps *, unsigned, bool);
kono
parents: 67
diff changeset
1902
kono
parents: 67
diff changeset
1903 /* Dump line table SET to STREAM. If STREAM is NULL, stderr is used.
kono
parents: 67
diff changeset
1904 NUM_ORDINARY specifies how many ordinary maps to dump. NUM_MACRO
kono
parents: 67
diff changeset
1905 specifies how many macro maps to dump. */
kono
parents: 67
diff changeset
1906 void line_table_dump (FILE *, struct line_maps *, unsigned int, unsigned int);
kono
parents: 67
diff changeset
1907
kono
parents: 67
diff changeset
1908 /* An enum for distinguishing the various parts within a source_location. */
kono
parents: 67
diff changeset
1909
kono
parents: 67
diff changeset
1910 enum location_aspect
kono
parents: 67
diff changeset
1911 {
kono
parents: 67
diff changeset
1912 LOCATION_ASPECT_CARET,
kono
parents: 67
diff changeset
1913 LOCATION_ASPECT_START,
kono
parents: 67
diff changeset
1914 LOCATION_ASPECT_FINISH
kono
parents: 67
diff changeset
1915 };
kono
parents: 67
diff changeset
1916
kono
parents: 67
diff changeset
1917 /* The rich_location class requires a way to expand source_location instances.
kono
parents: 67
diff changeset
1918 We would directly use expand_location_to_spelling_point, which is
kono
parents: 67
diff changeset
1919 implemented in gcc/input.c, but we also need to use it for rich_location
kono
parents: 67
diff changeset
1920 within genmatch.c.
kono
parents: 67
diff changeset
1921 Hence we require client code of libcpp to implement the following
kono
parents: 67
diff changeset
1922 symbol. */
kono
parents: 67
diff changeset
1923 extern expanded_location
kono
parents: 67
diff changeset
1924 linemap_client_expand_location_to_spelling_point (source_location,
kono
parents: 67
diff changeset
1925 enum location_aspect);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1926
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1927 #endif /* !LIBCPP_LINE_MAP_H */