blob: 3dbaeaba7c92937dda1e013b9552c4120e3daaa4 [file] [log] [blame]
Neil Boothd82fc102001-08-02 23:03:31 +00001/* Map logical line numbers to (source file, line number) pairs.
Tom Tromey92582b72011-10-17 09:59:12 +00002 Copyright (C) 2001, 2003, 2004, 2007, 2008, 2009, 2010, 2011
Neil Boothd82fc102001-08-02 23:03:31 +00003 Free Software Foundation, Inc.
4
5This program is free software; you can redistribute it and/or modify it
6under the terms of the GNU General Public License as published by the
Jakub Jelinek748086b2009-04-09 17:00:19 +02007Free Software Foundation; either version 3, or (at your option) any
Neil Boothd82fc102001-08-02 23:03:31 +00008later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
Jakub Jelinek748086b2009-04-09 17:00:19 +020016along with this program; see the file COPYING3. If not see
17<http://www.gnu.org/licenses/>.
Neil Boothd82fc102001-08-02 23:03:31 +000018
19 In other words, you are welcome to use, share and improve this program.
20 You are forbidden to forbid anyone else to use, share and improve
21 what you give them. Help stamp out software-hoarding! */
22
23#include "config.h"
24#include "system.h"
25#include "line-map.h"
Tom Tromey46427372011-10-17 11:58:56 +020026#include "cpplib.h"
27#include "internal.h"
Neil Boothd82fc102001-08-02 23:03:31 +000028
Neil Boothe2b98532003-06-20 05:51:13 +000029static void trace_include (const struct line_maps *, const struct line_map *);
Tom Tromey46427372011-10-17 11:58:56 +020030static const struct line_map * linemap_ordinary_map_lookup (struct line_maps *,
31 source_location);
32static const struct line_map* linemap_macro_map_lookup (struct line_maps *,
33 source_location);
34static source_location linemap_macro_map_loc_to_def_point
35(const struct line_map*, source_location);
36static source_location linemap_macro_map_loc_unwind_toward_spelling
37(const struct line_map*, source_location);
38static source_location linemap_macro_map_loc_to_exp_point
39(const struct line_map*, source_location);
40static source_location linemap_macro_loc_to_spelling_point
41(struct line_maps *, source_location, const struct line_map **);
42static source_location linemap_macro_loc_to_def_point (struct line_maps *,
43 source_location,
44 const struct line_map **);
45static source_location linemap_macro_loc_to_exp_point (struct line_maps *,
46 source_location,
47 const struct line_map **);
Neil Booth59930192001-08-21 21:17:48 +000048
Neil Boothd82fc102001-08-02 23:03:31 +000049/* Initialize a line map set. */
50
51void
Zack Weinberga2f7be92003-07-22 16:24:53 +000052linemap_init (struct line_maps *set)
Neil Boothd82fc102001-08-02 23:03:31 +000053{
Tom Tromey46427372011-10-17 11:58:56 +020054 memset (set, 0, sizeof (struct line_maps));
Jakub Jelinek96c169e2009-10-14 12:04:22 +020055 set->highest_location = RESERVED_LOCATION_COUNT - 1;
56 set->highest_line = RESERVED_LOCATION_COUNT - 1;
Neil Boothd82fc102001-08-02 23:03:31 +000057}
58
Kazu Hirata9ac97462004-02-16 14:20:10 +000059/* Check for and warn about line_maps entered but not exited. */
Per Bothner12f9df42004-02-11 07:29:30 -080060
61void
62linemap_check_files_exited (struct line_maps *set)
63{
64 struct line_map *map;
65 /* Depending upon whether we are handling preprocessed input or
66 not, this can be a user error or an ICE. */
Tom Tromey46427372011-10-17 11:58:56 +020067 for (map = LINEMAPS_LAST_ORDINARY_MAP (set);
68 ! MAIN_FILE_P (map);
Per Bothner12f9df42004-02-11 07:29:30 -080069 map = INCLUDED_FROM (set, map))
70 fprintf (stderr, "line-map.c: file \"%s\" entered but not left\n",
Tom Tromey46427372011-10-17 11:58:56 +020071 ORDINARY_MAP_FILE_NAME (map));
Per Bothner12f9df42004-02-11 07:29:30 -080072}
Neil Boothd82fc102001-08-02 23:03:31 +000073
Tom Tromey46427372011-10-17 11:58:56 +020074/* Create a new line map in the line map set SET, and return it.
75 REASON is the reason of creating the map. It determines the type
76 of map created (ordinary or macro map). Note that ordinary maps and
77 macro maps are allocated in different memory location. */
78
79static struct line_map *
80new_linemap (struct line_maps *set,
81 enum lc_reason reason)
Neil Boothd82fc102001-08-02 23:03:31 +000082{
Tom Tromey46427372011-10-17 11:58:56 +020083 /* Depending on this variable, a macro map would be allocated in a
84 different memory location than an ordinary map. */
85 bool macro_map_p = (reason == LC_ENTER_MACRO);
86 struct line_map *result;
Neil Booth47d89cf2001-08-11 07:33:39 +000087
Tom Tromey46427372011-10-17 11:58:56 +020088 if (LINEMAPS_USED (set, macro_map_p) == LINEMAPS_ALLOCATED (set, macro_map_p))
89 {
90 /* We ran out of allocated line maps. Let's allocate more. */
91
92 line_map_realloc reallocator
93 = set->reallocator ? set->reallocator : xrealloc;
94 LINEMAPS_ALLOCATED (set, macro_map_p) =
95 2 * LINEMAPS_ALLOCATED (set, macro_map_p) + 256;
96 LINEMAPS_MAPS (set, macro_map_p)
97 = (struct line_map *) (*reallocator) (LINEMAPS_MAPS (set, macro_map_p),
98 LINEMAPS_ALLOCATED (set,
99 macro_map_p)
100 * sizeof (struct line_map));
101 result =
102 &LINEMAPS_MAPS (set, macro_map_p)[LINEMAPS_USED (set, macro_map_p)];
103 memset (result, 0,
104 ((LINEMAPS_ALLOCATED (set, macro_map_p)
105 - LINEMAPS_USED (set, macro_map_p))
106 * sizeof (struct line_map)));
Neil Boothfde84342001-08-06 21:07:41 +0000107 }
Tom Tromey46427372011-10-17 11:58:56 +0200108 else
109 result =
110 &LINEMAPS_MAPS (set, macro_map_p)[LINEMAPS_USED (set, macro_map_p)];
111
112 LINEMAPS_USED (set, macro_map_p)++;
113
114 result->reason = reason;
115 return result;
Neil Boothd82fc102001-08-02 23:03:31 +0000116}
117
118/* Add a mapping of logical source line to physical source file and
Geoffrey Keating90744642003-07-30 06:43:33 +0000119 line number.
120
121 The text pointed to by TO_FILE must have a lifetime
122 at least as long as the final call to lookup_line (). An empty
123 TO_FILE means standard input. If reason is LC_LEAVE, and
124 TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their
125 natural values considering the file we are returning to.
Neil Boothd82fc102001-08-02 23:03:31 +0000126
127 FROM_LINE should be monotonic increasing across calls to this
Geoffrey Keating90744642003-07-30 06:43:33 +0000128 function. A call to this function can relocate the previous set of
129 maps, so any stored line_map pointers should not be used. */
Neil Boothd82fc102001-08-02 23:03:31 +0000130
Neil Booth47d89cf2001-08-11 07:33:39 +0000131const struct line_map *
Zack Weinberga2f7be92003-07-22 16:24:53 +0000132linemap_add (struct line_maps *set, enum lc_reason reason,
Manuel López-Ibáñez1bb64662008-07-21 09:33:38 +0000133 unsigned int sysp, const char *to_file, linenum_type to_line)
Neil Boothd82fc102001-08-02 23:03:31 +0000134{
135 struct line_map *map;
Per Bothner12f9df42004-02-11 07:29:30 -0800136 source_location start_location = set->highest_location + 1;
Neil Boothd82fc102001-08-02 23:03:31 +0000137
Tom Tromey46427372011-10-17 11:58:56 +0200138 linemap_assert (!(LINEMAPS_ORDINARY_USED (set)
139 && (start_location
140 < MAP_START_LOCATION (LINEMAPS_LAST_ORDINARY_MAP (set)))));
Neil Boothd82fc102001-08-02 23:03:31 +0000141
Tom Tromey46427372011-10-17 11:58:56 +0200142 /* When we enter the file for the first time reason cannot be
143 LC_RENAME. */
144 linemap_assert (!(set->depth == 0 && reason == LC_RENAME));
145
146 /* If we are leaving the main file, return a NULL map. */
147 if (reason == LC_LEAVE
148 && MAIN_FILE_P (LINEMAPS_LAST_ORDINARY_MAP (set))
149 && to_file == NULL)
Neil Boothd82fc102001-08-02 23:03:31 +0000150 {
Tom Tromey46427372011-10-17 11:58:56 +0200151 set->depth--;
152 return NULL;
Neil Boothd82fc102001-08-02 23:03:31 +0000153 }
154
Tom Tromey46427372011-10-17 11:58:56 +0200155 map = new_linemap (set, reason);
Neil Boothd82fc102001-08-02 23:03:31 +0000156
Joseph Myersc7f9c0b2009-04-18 18:36:28 +0100157 if (to_file && *to_file == '\0' && reason != LC_RENAME_VERBATIM)
Geoffrey Keating90744642003-07-30 06:43:33 +0000158 to_file = "<stdin>";
159
Joseph Myersc7f9c0b2009-04-18 18:36:28 +0100160 if (reason == LC_RENAME_VERBATIM)
161 reason = LC_RENAME;
162
Dodji Seketeli892a3712011-08-28 20:14:46 +0000163 if (reason == LC_LEAVE)
Neil Boothfde84342001-08-06 21:07:41 +0000164 {
Tom Tromey46427372011-10-17 11:58:56 +0200165 /* When we are just leaving an "included" file, and jump to the next
166 location inside the "includer" right after the #include
167 "included", this variable points the map in use right before the
168 #include "included", inside the same "includer" file. */
Neil Booth47d89cf2001-08-11 07:33:39 +0000169 struct line_map *from;
170 bool error;
171
172 if (MAIN_FILE_P (map - 1))
Neil Boothfde84342001-08-06 21:07:41 +0000173 {
Tom Tromey46427372011-10-17 11:58:56 +0200174 /* So this _should_ means we are leaving the main file --
175 effectively ending the compilation unit. But to_file not
176 being NULL means the caller thinks we are leaving to
177 another file. This is an erroneous behaviour but we'll
178 try to recover from it. Let's pretend we are not leaving
179 the main file. */
Per Bothnerb3147022003-07-22 23:11:34 +0000180 error = true;
181 reason = LC_RENAME;
182 from = map - 1;
Neil Booth47d89cf2001-08-11 07:33:39 +0000183 }
184 else
185 {
Tom Tromey46427372011-10-17 11:58:56 +0200186 /* (MAP - 1) points to the map we are leaving. The
187 map from which (MAP - 1) got included should be the map
188 that comes right before MAP in the same file. */
Neil Booth47d89cf2001-08-11 07:33:39 +0000189 from = INCLUDED_FROM (set, map - 1);
Tom Tromey46427372011-10-17 11:58:56 +0200190 error = to_file && filename_cmp (ORDINARY_MAP_FILE_NAME (from),
191 to_file);
Neil Booth47d89cf2001-08-11 07:33:39 +0000192 }
193
194 /* Depending upon whether we are handling preprocessed input or
195 not, this can be a user error or an ICE. */
196 if (error)
197 fprintf (stderr, "line-map.c: file \"%s\" left but not entered\n",
198 to_file);
199
200 /* A TO_FILE of NULL is special - we use the natural values. */
201 if (error || to_file == NULL)
202 {
Tom Tromey46427372011-10-17 11:58:56 +0200203 to_file = ORDINARY_MAP_FILE_NAME (from);
Per Bothner12f9df42004-02-11 07:29:30 -0800204 to_line = SOURCE_LINE (from, from[1].start_location);
Tom Tromey46427372011-10-17 11:58:56 +0200205 sysp = ORDINARY_MAP_IN_SYSTEM_HEADER_P (from);
Neil Boothfde84342001-08-06 21:07:41 +0000206 }
207 }
208
Tom Tromey46427372011-10-17 11:58:56 +0200209 linemap_assert (reason != LC_ENTER_MACRO);
210 ORDINARY_MAP_IN_SYSTEM_HEADER_P (map) = sysp;
211 MAP_START_LOCATION (map) = start_location;
212 ORDINARY_MAP_FILE_NAME (map) = to_file;
213 ORDINARY_MAP_STARTING_LINE_NUMBER (map) = to_line;
214 LINEMAPS_ORDINARY_CACHE (set) = LINEMAPS_ORDINARY_USED (set) - 1;
215 ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (map) = 0;
Per Bothner12f9df42004-02-11 07:29:30 -0800216 set->highest_location = start_location;
Per Bothner500bee02004-04-22 19:22:27 -0700217 set->highest_line = start_location;
Per Bothner12f9df42004-02-11 07:29:30 -0800218 set->max_column_hint = 0;
Neil Booth47d89cf2001-08-11 07:33:39 +0000219
Neil Boothfde84342001-08-06 21:07:41 +0000220 if (reason == LC_ENTER)
Neil Boothd8693c62001-08-21 23:05:12 +0000221 {
Tom Tromey46427372011-10-17 11:58:56 +0200222 ORDINARY_MAP_INCLUDER_FILE_INDEX (map) =
223 set->depth == 0 ? -1 : (int) (LINEMAPS_ORDINARY_USED (set) - 2);
Neil Boothd8693c62001-08-21 23:05:12 +0000224 set->depth++;
Neil Boothd8693c62001-08-21 23:05:12 +0000225 if (set->trace_includes)
226 trace_include (set, map);
227 }
Neil Boothd82fc102001-08-02 23:03:31 +0000228 else if (reason == LC_RENAME)
Tom Tromey46427372011-10-17 11:58:56 +0200229 ORDINARY_MAP_INCLUDER_FILE_INDEX (map) =
230 ORDINARY_MAP_INCLUDER_FILE_INDEX (&map[-1]);
Neil Boothd82fc102001-08-02 23:03:31 +0000231 else if (reason == LC_LEAVE)
Neil Boothd8693c62001-08-21 23:05:12 +0000232 {
233 set->depth--;
Tom Tromey46427372011-10-17 11:58:56 +0200234 ORDINARY_MAP_INCLUDER_FILE_INDEX (map) =
235 ORDINARY_MAP_INCLUDER_FILE_INDEX (INCLUDED_FROM (set, map - 1));
Neil Boothd8693c62001-08-21 23:05:12 +0000236 }
Neil Booth59930192001-08-21 21:17:48 +0000237
Neil Boothd82fc102001-08-02 23:03:31 +0000238 return map;
239}
240
Tom Tromey46427372011-10-17 11:58:56 +0200241/* Returns TRUE if the line table set tracks token locations accross
242 macro expansion, FALSE otherwise. */
243
244bool
245linemap_tracks_macro_expansion_locs_p (struct line_maps *set)
246{
247 return LINEMAPS_MACRO_MAPS (set) != NULL;
248}
249
250/* Create a macro map. A macro map encodes source locations of tokens
251 that are part of a macro replacement-list, at a macro expansion
252 point. See the extensive comments of struct line_map and struct
253 line_map_macro, in line-map.h.
254
255 This map shall be created when the macro is expanded. The map
256 encodes the source location of the expansion point of the macro as
257 well as the "original" source location of each token that is part
258 of the macro replacement-list. If a macro is defined but never
259 expanded, it has no macro map. SET is the set of maps the macro
260 map should be part of. MACRO_NODE is the macro which the new macro
261 map should encode source locations for. EXPANSION is the location
262 of the expansion point of MACRO. For function-like macros
263 invocations, it's best to make it point to the closing parenthesis
264 of the macro, rather than the the location of the first character
265 of the macro. NUM_TOKENS is the number of tokens that are part of
266 the replacement-list of MACRO.
267
268 Note that when we run out of the integer space available for source
269 locations, this function returns NULL. In that case, callers of
270 this function cannot encode {line,column} pairs into locations of
271 macro tokens anymore. */
272
273const struct line_map *
274linemap_enter_macro (struct line_maps *set, struct cpp_hashnode *macro_node,
275 source_location expansion, unsigned int num_tokens)
276{
277 struct line_map *map;
278 source_location start_location;
279 line_map_realloc reallocator
280 = set->reallocator ? set->reallocator : xrealloc;
281
282 start_location = LINEMAPS_MACRO_LOWEST_LOCATION (set) - num_tokens;
283
284 if (start_location <= set->highest_line
285 || start_location > LINEMAPS_MACRO_LOWEST_LOCATION (set))
286 /* We ran out of macro map space. */
287 return NULL;
288
289 map = new_linemap (set, LC_ENTER_MACRO);
290
291 MAP_START_LOCATION (map) = start_location;
292 MACRO_MAP_MACRO (map) = macro_node;
293 MACRO_MAP_NUM_MACRO_TOKENS (map) = num_tokens;
294 MACRO_MAP_LOCATIONS (map)
295 = (source_location*) reallocator (NULL,
296 2 * num_tokens
297 * sizeof (source_location));
298 MACRO_MAP_EXPANSION_POINT_LOCATION (map) = expansion;
299 memset (MACRO_MAP_LOCATIONS (map), 0,
300 num_tokens * sizeof (source_location));
301
302 LINEMAPS_MACRO_CACHE (set) = LINEMAPS_MACRO_USED (set) - 1;
303 set->max_column_hint = 0;
304
305 return map;
306}
307
308/* Create and return a virtual location for a token that is part of a
309 macro expansion-list at a macro expansion point. See the comment
310 inside struct line_map_macro to see what an expansion-list exactly
311 is.
312
313 A call to this function must come after a call to
314 linemap_enter_macro.
315
316 MAP is the map into which the source location is created. TOKEN_NO
317 is the index of the token in the macro replacement-list, starting
318 at number 0.
319
320 ORIG_LOC is the location of the token outside of this macro
321 expansion. If the token comes originally from the macro
322 definition, it is the locus in the macro definition; otherwise it
323 is a location in the context of the caller of this macro expansion
324 (which is a virtual location or a source location if the caller is
325 itself a macro expansion or not).
326
327 MACRO_DEFINITION_LOC is the location in the macro definition,
328 either of the token itself or of a macro parameter that it
329 replaces. */
330
331source_location
332linemap_add_macro_token (const struct line_map *map,
333 unsigned int token_no,
334 source_location orig_loc,
335 source_location orig_parm_replacement_loc)
336{
337 source_location result;
338
339 linemap_assert (linemap_macro_expansion_map_p (map));
340 linemap_assert (token_no < MACRO_MAP_NUM_MACRO_TOKENS (map));
341
342 MACRO_MAP_LOCATIONS (map)[2 * token_no] = orig_loc;
343 MACRO_MAP_LOCATIONS (map)[2 * token_no + 1] = orig_parm_replacement_loc;
344
345 result = MAP_START_LOCATION (map) + token_no;
346 return result;
347}
348
349/* Return a source_location for the start (i.e. column==0) of
350 (physical) line TO_LINE in the current source file (as in the
351 most recent linemap_add). MAX_COLUMN_HINT is the highest column
352 number we expect to use in this line (but it does not change
353 the highest_location). */
354
Per Bothner12f9df42004-02-11 07:29:30 -0800355source_location
Manuel López-Ibáñez1bb64662008-07-21 09:33:38 +0000356linemap_line_start (struct line_maps *set, linenum_type to_line,
Per Bothner12f9df42004-02-11 07:29:30 -0800357 unsigned int max_column_hint)
358{
Tom Tromey46427372011-10-17 11:58:56 +0200359 struct line_map *map = LINEMAPS_LAST_ORDINARY_MAP (set);
Per Bothner12f9df42004-02-11 07:29:30 -0800360 source_location highest = set->highest_location;
361 source_location r;
Tom Tromey46427372011-10-17 11:58:56 +0200362 linenum_type last_line =
363 SOURCE_LINE (map, set->highest_line);
Per Bothner12f9df42004-02-11 07:29:30 -0800364 int line_delta = to_line - last_line;
365 bool add_map = false;
Tom Tromey46427372011-10-17 11:58:56 +0200366
Per Bothner12f9df42004-02-11 07:29:30 -0800367 if (line_delta < 0
Tom Tromey46427372011-10-17 11:58:56 +0200368 || (line_delta > 10
369 && line_delta * ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (map) > 1000)
370 || (max_column_hint >= (1U << ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (map)))
371 || (max_column_hint <= 80
372 && ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (map) >= 10))
Per Bothner12f9df42004-02-11 07:29:30 -0800373 {
374 add_map = true;
375 }
376 else
377 max_column_hint = set->max_column_hint;
378 if (add_map)
379 {
380 int column_bits;
Per Bothner500bee02004-04-22 19:22:27 -0700381 if (max_column_hint > 100000 || highest > 0xC0000000)
Per Bothner12f9df42004-02-11 07:29:30 -0800382 {
Per Bothnerc1fc5042005-04-21 10:08:27 -0700383 /* If the column number is ridiculous or we've allocated a huge
384 number of source_locations, give up on column numbers. */
Per Bothner12f9df42004-02-11 07:29:30 -0800385 max_column_hint = 0;
386 if (highest >0xF0000000)
387 return 0;
388 column_bits = 0;
389 }
390 else
391 {
392 column_bits = 7;
393 while (max_column_hint >= (1U << column_bits))
394 column_bits++;
395 max_column_hint = 1U << column_bits;
396 }
Per Bothnerc1fc5042005-04-21 10:08:27 -0700397 /* Allocate the new line_map. However, if the current map only has a
398 single line we can sometimes just increase its column_bits instead. */
Per Bothner12f9df42004-02-11 07:29:30 -0800399 if (line_delta < 0
Tom Tromey46427372011-10-17 11:58:56 +0200400 || last_line != ORDINARY_MAP_STARTING_LINE_NUMBER (map)
Per Bothner12f9df42004-02-11 07:29:30 -0800401 || SOURCE_COLUMN (map, highest) >= (1U << column_bits))
Tom Tromey46427372011-10-17 11:58:56 +0200402 map = (struct line_map *) linemap_add (set, LC_RENAME,
403 ORDINARY_MAP_IN_SYSTEM_HEADER_P
404 (map),
405 ORDINARY_MAP_FILE_NAME (map),
406 to_line);
407 ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (map) = column_bits;
408 r = (MAP_START_LOCATION (map)
409 + ((to_line - ORDINARY_MAP_STARTING_LINE_NUMBER (map))
410 << column_bits));
Per Bothner12f9df42004-02-11 07:29:30 -0800411 }
412 else
413 r = highest - SOURCE_COLUMN (map, highest)
Tom Tromey46427372011-10-17 11:58:56 +0200414 + (line_delta << ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (map));
415
416 /* Locations of ordinary tokens are always lower than locations of
417 macro tokens. */
418 if (r >= LINEMAPS_MACRO_LOWEST_LOCATION (set))
419 return 0;
420
Per Bothner500bee02004-04-22 19:22:27 -0700421 set->highest_line = r;
Per Bothner12f9df42004-02-11 07:29:30 -0800422 if (r > set->highest_location)
423 set->highest_location = r;
424 set->max_column_hint = max_column_hint;
425 return r;
426}
427
Tom Tromey46427372011-10-17 11:58:56 +0200428/* Encode and return a source_location from a column number. The
429 source line considered is the last source line used to call
430 linemap_line_start, i.e, the last source line which a location was
431 encoded from. */
432
Per Bothner500bee02004-04-22 19:22:27 -0700433source_location
434linemap_position_for_column (struct line_maps *set, unsigned int to_column)
435{
436 source_location r = set->highest_line;
Tom Tromey46427372011-10-17 11:58:56 +0200437
438 linemap_assert
439 (!linemap_macro_expansion_map_p (LINEMAPS_LAST_ORDINARY_MAP (set)));
440
Per Bothner500bee02004-04-22 19:22:27 -0700441 if (to_column >= set->max_column_hint)
442 {
443 if (r >= 0xC000000 || to_column > 100000)
444 {
445 /* Running low on source_locations - disable column numbers. */
446 return r;
447 }
448 else
449 {
Tom Tromey46427372011-10-17 11:58:56 +0200450 struct line_map *map = LINEMAPS_LAST_ORDINARY_MAP (set);
Per Bothner500bee02004-04-22 19:22:27 -0700451 r = linemap_line_start (set, SOURCE_LINE (map, r), to_column + 50);
452 }
453 }
454 r = r + to_column;
455 if (r >= set->highest_location)
456 set->highest_location = r;
457 return r;
458}
459
Tom Tromey46427372011-10-17 11:58:56 +0200460/* Encode and return a source location from a given line and
461 column. */
Neil Boothd82fc102001-08-02 23:03:31 +0000462
Tom Tromey46427372011-10-17 11:58:56 +0200463source_location
464linemap_position_for_line_and_column (struct line_map *map,
465 linenum_type line,
466 unsigned column)
467{
468 linemap_assert (ORDINARY_MAP_STARTING_LINE_NUMBER (map) <= line);
469
470 return (MAP_START_LOCATION (map)
471 + ((line - ORDINARY_MAP_STARTING_LINE_NUMBER (map))
472 << ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (map))
473 + (column & ((1 << ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (map)) - 1)));
474}
475
476/* Given a virtual source location yielded by a map (either an
477 ordinary or a macro map), returns that map. */
478
479const struct line_map*
Per Bothner7d40b452003-12-05 12:52:39 -0800480linemap_lookup (struct line_maps *set, source_location line)
Neil Boothd82fc102001-08-02 23:03:31 +0000481{
Tom Tromey46427372011-10-17 11:58:56 +0200482 if (linemap_location_from_macro_expansion_p (set, line))
483 return linemap_macro_map_lookup (set, line);
484 return linemap_ordinary_map_lookup (set, line);
485}
Neil Boothd82fc102001-08-02 23:03:31 +0000486
Tom Tromey46427372011-10-17 11:58:56 +0200487/* Given a source location yielded by an ordinary map, returns that
488 map. Since the set is built chronologically, the logical lines are
489 monotonic increasing, and so the list is sorted and we can use a
490 binary search. */
491
492static const struct line_map *
493linemap_ordinary_map_lookup (struct line_maps *set, source_location line)
494{
495 unsigned int md, mn, mx;
496 const struct line_map *cached, *result;
497
498 if (set == NULL || line < RESERVED_LOCATION_COUNT)
499 return NULL;
500
501 mn = LINEMAPS_ORDINARY_CACHE (set);
502 mx = LINEMAPS_ORDINARY_USED (set);
Per Bothner9132fbb2004-01-20 05:17:48 +0000503
Tom Tromey46427372011-10-17 11:58:56 +0200504 cached = LINEMAPS_ORDINARY_MAP_AT (set, mn);
Kazu Hirata9ac97462004-02-16 14:20:10 +0000505 /* We should get a segfault if no line_maps have been added yet. */
Tom Tromey46427372011-10-17 11:58:56 +0200506 if (line >= MAP_START_LOCATION (cached))
Per Bothner9132fbb2004-01-20 05:17:48 +0000507 {
Tom Tromey46427372011-10-17 11:58:56 +0200508 if (mn + 1 == mx || line < MAP_START_LOCATION (&cached[1]))
Per Bothner9132fbb2004-01-20 05:17:48 +0000509 return cached;
510 }
511 else
512 {
513 mx = mn;
514 mn = 0;
515 }
Neil Boothd82fc102001-08-02 23:03:31 +0000516
517 while (mx - mn > 1)
518 {
519 md = (mn + mx) / 2;
Tom Tromey46427372011-10-17 11:58:56 +0200520 if (MAP_START_LOCATION (LINEMAPS_ORDINARY_MAP_AT (set, md)) > line)
Neil Boothd82fc102001-08-02 23:03:31 +0000521 mx = md;
522 else
523 mn = md;
524 }
525
Tom Tromey46427372011-10-17 11:58:56 +0200526 LINEMAPS_ORDINARY_CACHE (set) = mn;
527 result = LINEMAPS_ORDINARY_MAP_AT (set, mn);
528 linemap_assert (line >= MAP_START_LOCATION (result));
529 return result;
530}
531
532/* Given a source location yielded by a macro map, returns that map.
533 Since the set is built chronologically, the logical lines are
534 monotonic decreasing, and so the list is sorted and we can use a
535 binary search. */
536
537static const struct line_map*
538linemap_macro_map_lookup (struct line_maps *set, source_location line)
539{
540 unsigned int md, mn, mx;
541 const struct line_map *cached, *result;
542
543 linemap_assert (line >= LINEMAPS_MACRO_LOWEST_LOCATION (set));
544
545 if (set == NULL)
546 return NULL;
547
548 mn = LINEMAPS_MACRO_CACHE (set);
549 mx = LINEMAPS_MACRO_USED (set);
550 cached = LINEMAPS_MACRO_MAP_AT (set, mn);
551
552 if (line >= MAP_START_LOCATION (cached))
553 {
554 if (mn == 0 || line < MAP_START_LOCATION (&cached[-1]))
555 return cached;
556 mx = mn - 1;
557 mn = 0;
558 }
559
560 do
561 {
562 md = (mx + mn) / 2;
563 if (MAP_START_LOCATION (LINEMAPS_MACRO_MAP_AT (set, md)) > line)
564 mn = md;
565 else
566 mx = md;
567 } while (mx - mn > 1);
568
569 LINEMAPS_MACRO_CACHE (set) = mx;
570 result = LINEMAPS_MACRO_MAP_AT (set, LINEMAPS_MACRO_CACHE (set));
571 linemap_assert (MAP_START_LOCATION (result) <= line);
572
573 return result;
574}
575
576/* Return TRUE if MAP encodes locations coming from a macro
577 replacement-list at macro expansion point. */
578
579bool
580linemap_macro_expansion_map_p (const struct line_map *map)
581{
582 if (!map)
583 return false;
584 return (map->reason == LC_ENTER_MACRO);
585}
586
587/* If LOCATION is the locus of a token in a replacement-list of a
588 macro expansion return the location of the macro expansion point.
589
590 Read the comments of struct line_map and struct line_map_macro in
591 line-map.h to understand what a macro expansion point is. */
592
593source_location
594linemap_macro_map_loc_to_exp_point (const struct line_map *map,
595 source_location location)
596{
597 unsigned token_no;
598
599 linemap_assert (linemap_macro_expansion_map_p (map)
600 && location >= MAP_START_LOCATION (map));
601
602 /* Make sure LOCATION is correct. */
603 token_no = location - MAP_START_LOCATION (map);
604 linemap_assert (token_no < MACRO_MAP_NUM_MACRO_TOKENS (map));
605
606 return MACRO_MAP_EXPANSION_POINT_LOCATION (map);
607}
608
609/* If LOCATION is the source location of a token that belongs to a
610 macro replacement-list -- as part of a macro expansion -- then
611 return the location of the token at the definition point of the
612 macro. Otherwise, return LOCATION. SET is the set of maps
613 location come from. ORIGINAL_MAP is an output parm. If non NULL,
614 the function sets *ORIGINAL_MAP to the ordinary (non-macro) map the
615 returned location comes from. */
616
617source_location
618linemap_macro_map_loc_to_def_point (const struct line_map *map,
619 source_location location)
620{
621 unsigned token_no;
622
623 linemap_assert (linemap_macro_expansion_map_p (map)
624 && location >= MAP_START_LOCATION (map));
625 linemap_assert (location >= RESERVED_LOCATION_COUNT);
626
627 token_no = location - MAP_START_LOCATION (map);
628 linemap_assert (token_no < MACRO_MAP_NUM_MACRO_TOKENS (map));
629
630 location = MACRO_MAP_LOCATIONS (map)[2 * token_no + 1];
631
632 return location;
633}
634
635/* If LOCATION is the locus of a token that is an argument of a
636 function-like macro M and appears in the expansion of M, return the
637 locus of that argument in the context of the caller of M.
638
639 In other words, this returns the xI location presented in the
640 comments of line_map_macro above. */
641source_location
642linemap_macro_map_loc_unwind_toward_spelling (const struct line_map* map,
643 source_location location)
644{
645 unsigned token_no;
646
647 linemap_assert (linemap_macro_expansion_map_p (map)
648 && location >= MAP_START_LOCATION (map));
649 linemap_assert (location >= RESERVED_LOCATION_COUNT);
650
651 token_no = location - MAP_START_LOCATION (map);
652 linemap_assert (token_no < MACRO_MAP_NUM_MACRO_TOKENS (map));
653
654 location = MACRO_MAP_LOCATIONS (map)[2 * token_no];
655
656 return location;
657}
658
659/* Return the source line number corresponding to source location
660 LOCATION. SET is the line map set LOCATION comes from. If
661 LOCATION is the source location of token that is part of the
662 replacement-list of a macro expansion return the line number of the
663 macro expansion point. */
664
665int
666linemap_get_expansion_line (struct line_maps *set,
667 source_location location)
668{
669 const struct line_map *map = NULL;
670
671 if (location < RESERVED_LOCATION_COUNT)
672 return 0;
673
674 location =
675 linemap_macro_loc_to_exp_point (set, location, &map);
676
677 return SOURCE_LINE (map, location);
678}
679
680/* Return the path of the file corresponding to source code location
681 LOCATION.
682
683 If LOCATION is the source location of token that is part of the
684 replacement-list of a macro expansion return the file path of the
685 macro expansion point.
686
687 SET is the line map set LOCATION comes from. */
688
689const char*
690linemap_get_expansion_filename (struct line_maps *set,
691 source_location location)
692{
693 const struct line_map *map = NULL;
694
695 if (location < RESERVED_LOCATION_COUNT)
696 return NULL;
697
698 location =
699 linemap_macro_loc_to_exp_point (set, location, &map);
700
701 return LINEMAP_FILE (map);
702}
703
704/* Return the name of the macro associated to MACRO_MAP. */
705
706const char*
707linemap_map_get_macro_name (const struct line_map* macro_map)
708{
709 linemap_assert (macro_map && linemap_macro_expansion_map_p (macro_map));
710 return (const char*) NODE_NAME (MACRO_MAP_MACRO (macro_map));
711}
712
713/* Return a positive value if LOCATION is the locus of a token that is
714 located in a system header, O otherwise. It returns 1 if LOCATION
715 is the locus of a token that is located in a system header, and 2
716 if LOCATION is the locus of a token located in a C system header
717 that therefore needs to be extern "C" protected in C++.
718
719 Note that this function returns 1 if LOCATION belongs to a token
720 that is part of a macro replacement-list defined in a system
721 header, but expanded in a non-system file. */
722
723int
724linemap_location_in_system_header_p (struct line_maps *set,
725 source_location location)
726{
727 const struct line_map *map = NULL;
728
729 if (location < RESERVED_LOCATION_COUNT)
730 return false;
731
732 location =
733 linemap_resolve_location (set, location, LRK_SPELLING_LOCATION, &map);
734
735 return LINEMAP_SYSP (map);
736}
737
738/* Return TRUE if LOCATION is a source code location of a token coming
739 from a macro replacement-list at a macro expansion point, FALSE
740 otherwise. */
741
742bool
743linemap_location_from_macro_expansion_p (struct line_maps *set,
744 source_location location)
745{
746 linemap_assert (location <= MAX_SOURCE_LOCATION
747 && (set->highest_location
748 < LINEMAPS_MACRO_LOWEST_LOCATION (set)));
749 if (set == NULL)
750 return false;
751 return (location > set->highest_location);
752}
753
754/* Given two virtual locations *LOC0 and *LOC1, return the first
755 common macro map in their macro expansion histories. Return NULL
756 if no common macro was found. *LOC0 (resp. *LOC1) is set to the
757 virtual location of the token inside the resulting macro. */
758
759static const struct line_map*
760first_map_in_common_1 (struct line_maps *set,
761 source_location *loc0,
762 source_location *loc1)
763{
764 source_location l0 = *loc0, l1 = *loc1;
765 const struct line_map *map0 = linemap_lookup (set, l0),
766 *map1 = linemap_lookup (set, l1);
767
768 while (linemap_macro_expansion_map_p (map0)
769 && linemap_macro_expansion_map_p (map1)
770 && (map0 != map1))
771 {
772 if (MAP_START_LOCATION (map0) < MAP_START_LOCATION (map1))
773 {
774 l0 = linemap_macro_map_loc_to_exp_point (map0, l0);
775 map0 = linemap_lookup (set, l0);
776 }
777 else
778 {
779 l1 = linemap_macro_map_loc_to_exp_point (map1, l1);
780 map1 = linemap_lookup (set, l1);
781 }
782 }
783
784 if (map0 == map1)
785 {
786 *loc0 = l0;
787 *loc1 = l1;
788 return map0;
789 }
790 return NULL;
791}
792
793/* Given two virtual locations LOC0 and LOC1, return the first common
794 macro map in their macro expansion histories. Return NULL if no
795 common macro was found. *RES_LOC0 (resp. *RES_LOC1) is set to the
796 virtual location of the token inside the resulting macro, upon
797 return of a non-NULL result. */
798
799static const struct line_map*
800first_map_in_common (struct line_maps *set,
801 source_location loc0,
802 source_location loc1,
803 source_location *res_loc0,
804 source_location *res_loc1)
805{
806 *res_loc0 = loc0;
807 *res_loc1 = loc1;
808
809 return first_map_in_common_1 (set, res_loc0, res_loc1);
810}
811
812/* Return a positive value if PRE denotes the location of a token that
813 comes before the token of POST, 0 if PRE denotes the location of
814 the same token as the token for POST, and a negative value
815 otherwise. */
816
817int
818linemap_compare_locations (struct line_maps *set,
819 source_location pre,
820 source_location post)
821{
822 bool pre_virtual_p, post_virtual_p;
823 source_location l0 = pre, l1 = post;
824
825 if (l0 == l1)
826 return 0;
827
828 if ((pre_virtual_p = linemap_location_from_macro_expansion_p (set, l0)))
829 l0 = linemap_resolve_location (set, l0,
830 LRK_MACRO_EXPANSION_POINT,
831 NULL);
832
833 if ((post_virtual_p = linemap_location_from_macro_expansion_p (set, l1)))
834 l1 = linemap_resolve_location (set, l1,
835 LRK_MACRO_EXPANSION_POINT,
836 NULL);
837
838 if (l0 == l1
839 && pre_virtual_p
840 && post_virtual_p)
841 {
842 /* So pre and post represent two tokens that are present in a
843 same macro expansion. Let's see if the token for pre was
844 before the token for post in that expansion. */
845 unsigned i0, i1;
846 const struct line_map *map =
847 first_map_in_common (set, pre, post, &l0, &l1);
848
849 if (map == NULL)
850 /* This should not be possible. */
851 abort ();
852
853 i0 = l0 - MAP_START_LOCATION (map);
854 i1 = l1 - MAP_START_LOCATION (map);
855 return i1 - i0;
856 }
857
858 return l1 - l0;
Neil Boothd82fc102001-08-02 23:03:31 +0000859}
Neil Boothfde84342001-08-06 21:07:41 +0000860
Neil Booth59930192001-08-21 21:17:48 +0000861/* Print an include trace, for e.g. the -H option of the preprocessor. */
862
863static void
Neil Boothe2b98532003-06-20 05:51:13 +0000864trace_include (const struct line_maps *set, const struct line_map *map)
Neil Booth59930192001-08-21 21:17:48 +0000865{
Neil Boothd8693c62001-08-21 23:05:12 +0000866 unsigned int i = set->depth;
Neil Booth59930192001-08-21 21:17:48 +0000867
Neil Boothd8693c62001-08-21 23:05:12 +0000868 while (--i)
Neil Booth59930192001-08-21 21:17:48 +0000869 putc ('.', stderr);
Tom Tromey46427372011-10-17 11:58:56 +0200870
871 fprintf (stderr, " %s\n", ORDINARY_MAP_FILE_NAME (map));
872}
873
874/* Return the spelling location of the token wherever it comes from,
875 whether part of a macro definition or not.
876
877 This is a subroutine for linemap_resolve_location. */
878
879static source_location
880linemap_macro_loc_to_spelling_point (struct line_maps *set,
881 source_location location,
882 const struct line_map **original_map)
883{
884 struct line_map *map;
885
886 linemap_assert (set && location >= RESERVED_LOCATION_COUNT);
887
888 while (true)
889 {
890 map = (struct line_map*) linemap_lookup (set, location);
891 if (!linemap_macro_expansion_map_p (map))
892 break;
893
894 location =
895 linemap_macro_map_loc_unwind_toward_spelling (map, location);
896 }
897
898 if (original_map)
899 *original_map = map;
900 return location;
901}
902
903/* If LOCATION is the source location of a token that belongs to a
904 macro replacement-list -- as part of a macro expansion -- then
905 return the location of the token at the definition point of the
906 macro. Otherwise, return LOCATION. SET is the set of maps
907 location come from. ORIGINAL_MAP is an output parm. If non NULL,
908 the function sets *ORIGINAL_MAP to the ordinary (non-macro) map the
909 returned location comes from.
910
911 This is a subroutine of linemap_resolve_location. */
912
913static source_location
914linemap_macro_loc_to_def_point (struct line_maps *set,
915 source_location location,
916 const struct line_map **original_map)
917{
918 struct line_map *map;
919
920 linemap_assert (set && location >= RESERVED_LOCATION_COUNT);
921
922 while (true)
923 {
924 map = (struct line_map*) linemap_lookup (set, location);
925 if (!linemap_macro_expansion_map_p (map))
926 break;
927
928 location =
929 linemap_macro_map_loc_to_def_point (map, location);
930 }
931
932 if (original_map)
933 *original_map = map;
934 return location;
935}
936
937/* If LOCATION is the source location of a token that belongs to a
938 macro replacement-list -- at a macro expansion point -- then return
939 the location of the topmost expansion point of the macro. We say
940 topmost because if we are in the context of a nested macro
941 expansion, the function returns the source location of the first
942 macro expansion that triggered the nested expansions.
943
944 Otherwise, return LOCATION. SET is the set of maps location come
945 from. ORIGINAL_MAP is an output parm. If non NULL, the function
946 sets *ORIGINAL_MAP to the ordinary (non-macro) map the returned
947 location comes from.
948
949 This is a subroutine of linemap_resolve_location. */
950
951static source_location
952linemap_macro_loc_to_exp_point (struct line_maps *set,
953 source_location location,
954 const struct line_map **original_map)
955{
956 struct line_map *map;
957
958 linemap_assert (set && location >= RESERVED_LOCATION_COUNT);
959
960 while (true)
961 {
962 map = (struct line_map*) linemap_lookup (set, location);
963 if (!linemap_macro_expansion_map_p (map))
964 break;
965 location = linemap_macro_map_loc_to_exp_point (map, location);
966 }
967
968 if (original_map)
969 *original_map = map;
970 return location;
971}
972
973/* Resolve a virtual location into either a spelling location, an
974 expansion point location or a token argument replacement point
975 location. Return the map that encodes the virtual location as well
976 as the resolved location.
977
978 If LOC is *NOT* the location of a token resulting from the
979 expansion of a macro, then the parameter LRK (which stands for
980 Location Resolution Kind) is ignored and the resulting location
981 just equals the one given in argument.
982
983 Now if LOC *IS* the location of a token resulting from the
984 expansion of a macro, this is what happens.
985
986 * If LRK is set to LRK_MACRO_EXPANSION_POINT
987 -------------------------------
988
989 The virtual location is resolved to the location to the locus of
990 the expansion point of the macro.
991
992 * If LRK is set to LRK_SPELLING_LOCATION
993 -------------------------------------
994
995 The virtual location is resolved to the location to the locus where
996 the token has been spelled in the source. This can follow through
997 all the macro expansions that led to the token.
998
999 * If LRK is set to LRK_MACRO_PARM_REPLACEMENT_POINT
1000 --------------------------------------
1001
1002 If LOC is the locus of a token that is an argument of a
1003 function-like macro [replacing a parameter in the replacement list
1004 of the macro] the virtual location is resolved to the locus of the
1005 parameter that is replaced, in the context of the definition of the
1006 macro.
1007
1008 If LOC is the locus of a token that is not an argument of a
1009 function-like macro, then the function behaves as if LRK was set to
1010 LRK_SPELLING_LOCATION.
1011
1012 If MAP is non-NULL, *MAP is set to the map of the resolved
1013 location. */
1014
1015source_location
1016linemap_resolve_location (struct line_maps *set,
1017 source_location loc,
1018 enum location_resolution_kind lrk,
1019 const struct line_map **map)
1020{
1021 linemap_assert (set && loc >= RESERVED_LOCATION_COUNT);
1022
1023 switch (lrk)
1024 {
1025 case LRK_MACRO_EXPANSION_POINT:
1026 loc = linemap_macro_loc_to_exp_point (set, loc, map);
1027 break;
1028 case LRK_SPELLING_LOCATION:
1029 loc = linemap_macro_loc_to_spelling_point (set, loc, map);
1030 break;
1031 case LRK_MACRO_DEFINITION_LOCATION:
1032 loc = linemap_macro_loc_to_def_point (set, loc, map);
1033 break;
1034 default:
1035 abort ();
1036 }
1037 return loc;
1038}
1039
1040/*
1041 Suppose that LOC is the virtual location of a token T coming from
1042 the expansion of a macro M. This function then steps up to get the
1043 location L of the point where M got expanded. If L is a spelling
1044 location inside a macro expansion M', then this function returns
1045 the locus of the point where M' was expanded. Said otherwise, this
1046 function returns the location of T in the context that triggered
1047 the expansion of M.
1048
1049 *LOC_MAP must be set to the map of LOC. This function then sets it
1050 to the map of the returned location. */
1051
1052source_location
1053linemap_unwind_toward_expansion (struct line_maps *set,
1054 source_location loc,
1055 const struct line_map **map)
1056{
1057 source_location resolved_location;
1058 const struct line_map *resolved_map;
1059
1060 resolved_location =
1061 linemap_macro_map_loc_unwind_toward_spelling (*map, loc);
1062 resolved_map = linemap_lookup (set, resolved_location);
1063
1064 if (!linemap_macro_expansion_map_p (resolved_map))
1065 {
1066 resolved_location = linemap_macro_map_loc_to_exp_point (*map, loc);
1067 resolved_map = linemap_lookup (set, resolved_location);
1068 }
1069
1070 *map = resolved_map;
1071 return resolved_location;
1072}
1073
1074/* Expand source code location LOC and return a user readable source
1075 code location. LOC must be a spelling (non-virtual) location. */
1076
1077expanded_location
1078linemap_expand_location (const struct line_map *map,
1079 source_location loc)
1080
1081{
1082 expanded_location xloc;
1083
1084 xloc.file = LINEMAP_FILE (map);
1085 xloc.line = SOURCE_LINE (map, loc);
1086 xloc.column = SOURCE_COLUMN (map, loc);
1087 xloc.sysp = LINEMAP_SYSP (map) != 0;
1088
1089 return xloc;
1090}
1091
1092/* Expand source code location LOC and return a user readable source
1093 code location. LOC can be a virtual location. The LRK parameter
1094 is the same as for linemap_resolve_location. */
1095
1096expanded_location
1097linemap_expand_location_full (struct line_maps *set,
1098 source_location loc,
1099 enum location_resolution_kind lrk)
1100{
1101 const struct line_map *map;
1102 expanded_location xloc;
1103
1104 loc = linemap_resolve_location (set, loc, lrk, &map);
1105 xloc = linemap_expand_location (map, loc);
1106 return xloc;
Neil Booth59930192001-08-21 21:17:48 +00001107}
Tom Tromey847e6972011-10-17 09:59:40 +00001108
1109/* Dump debugging information about source location LOC into the file
1110 stream STREAM. SET is the line map set LOC comes from. */
1111
1112void
1113linemap_dump_location (struct line_maps *set,
1114 source_location loc,
1115 FILE *stream)
1116{
1117 const struct line_map *map;
1118 source_location location;
1119 const char *path, *from;
1120 int l,c,s,e;
1121
1122 if (loc == 0)
1123 return;
1124
1125 location =
1126 linemap_resolve_location (set, loc, LRK_MACRO_DEFINITION_LOCATION, &map);
1127 path = LINEMAP_FILE (map);
1128
1129 l = SOURCE_LINE (map, location);
1130 c = SOURCE_COLUMN (map, location);
1131 s = LINEMAP_SYSP (map) != 0;
1132 e = location != loc;
1133
1134 if (e)
1135 from = "N/A";
1136 else
1137 from = (INCLUDED_FROM (set, map))
1138 ? LINEMAP_FILE (INCLUDED_FROM (set, map))
1139 : "<NULL>";
1140
1141 /* P: path, L: line, C: column, S: in-system-header, M: map address,
1142 E: macro expansion?. */
1143 fprintf (stream, "{P:%s;F:%s;L:%d;C:%d;S:%d;M:%p;E:%d,LOC:%d}",
1144 path, from, l, c, s, (void*)map, e, loc);
1145}