annotate libcpp/include/line-map.h @ 145:1830386684a0

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