OSDN Git Service

Generate virtual locations for tokens
[pf3gnuchains/gcc-fork.git] / libcpp / include / line-map.h
1 /* Map logical line numbers to (source file, line number) pairs.
2    Copyright (C) 2001, 2003, 2004, 2007, 2008, 2009, 2010, 2011
3    Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 3, or (at your option) any
8 later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING3.  If not see
17 <http://www.gnu.org/licenses/>.
18
19  In other words, you are welcome to use, share and improve this program.
20  You are forbidden to forbid anyone else to use, share and improve
21  what you give them.   Help stamp out software-hoarding!  */
22
23 #ifndef LIBCPP_LINE_MAP_H
24 #define LIBCPP_LINE_MAP_H
25
26 #ifndef GTY
27 #define GTY(x) /* nothing */
28 #endif
29
30 /* Reason for creating a new line map with linemap_add.  LC_ENTER is
31    when including a new file, e.g. a #include directive in C.
32    LC_LEAVE is when reaching a file's end.  LC_RENAME is when a file
33    name or line number changes for neither of the above reasons
34    (e.g. a #line directive in C); LC_RENAME_VERBATIM is like LC_RENAME
35    but a filename of "" is not specially interpreted as standard
36    input. LC_ENTER_MACRO is when a macro expansion is about to start.  */
37 enum lc_reason
38 {
39   LC_ENTER = 0,
40   LC_LEAVE,
41   LC_RENAME,
42   LC_RENAME_VERBATIM,
43   LC_ENTER_MACRO
44   /* FIXME: add support for stringize and paste.  */
45 };
46
47 /* The type of line numbers.  */
48 typedef unsigned int linenum_type;
49
50 /* A logical line/column number, i.e. an "index" into a line_map.  */
51 typedef unsigned int source_location;
52
53 /* Memory allocation function typedef.  Works like xrealloc.  */
54 typedef void *(*line_map_realloc) (void *, size_t);
55
56 /* An ordinary line map encodes physical source locations. Those
57    physical source locations are called "spelling locations".
58    
59    Physical source file TO_FILE at line TO_LINE at column 0 is represented
60    by the logical START_LOCATION.  TO_LINE+L at column C is represented by
61    START_LOCATION+(L*(1<<column_bits))+C, as long as C<(1<<column_bits),
62    and the result_location is less than the next line_map's start_location.
63    (The top line is line 1 and the leftmost column is column 1; line/column 0
64    means "entire file/line" or "unknown line/column" or "not applicable".)
65
66    The highest possible source location is MAX_SOURCE_LOCATION.  */
67 struct GTY(()) line_map_ordinary {
68   const char *to_file;
69   linenum_type to_line;
70
71   /* An index into the set that gives the line mapping at whose end
72      the current one was included.  File(s) at the bottom of the
73      include stack have this set to -1.  */
74   int included_from;
75
76   /* SYSP is one for a system header, two for a C system header file
77      that therefore needs to be extern "C" protected in C++, and zero
78      otherwise.  This field isn't really needed now that it's in
79      cpp_buffer.  */
80   unsigned char sysp;
81
82   /* Number of the low-order source_location bits used for a column number.  */
83   unsigned int column_bits : 8;
84 };
85
86 /* This is the highest possible source location encoded within an
87    ordinary or macro map.  */
88 #define MAX_SOURCE_LOCATION 0xFFFFFFFF
89
90 struct cpp_hashnode;
91
92 /* A macro line map encodes location of tokens coming from a macro
93    expansion.
94    
95    Please note that this struct line_map_macro is a field of struct
96    line_map below, go read the comments of struct line_map below and
97    then come back here.
98    
99    The offset from START_LOCATION is used to index into
100    MACRO_LOCATIONS; this holds the original location of the token.  */
101 struct GTY(()) line_map_macro {
102   /* The cpp macro which expansion gave birth to this macro map.  */
103   struct cpp_hashnode * GTY ((nested_ptr (union tree_node,
104                                    "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
105                                    "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL")))
106     macro;
107
108   /* The number of tokens inside the replacement-list of MACRO.  */
109   unsigned int n_tokens;
110
111   /* This array of location is actually an array of pairs of
112      locations. The elements inside it thus look like:
113
114            x0,y0, x1,y1, x2,y2, ...., xn,yn.
115
116      where n == n_tokens;
117
118      Remember that these xI,yI are collected when libcpp is about to
119      expand a given macro.
120
121      yI is the location in the macro definition, either of the token
122      itself or of a macro parameter that it replaces.
123
124      Imagine this:
125
126         #define PLUS(A, B) A + B  <--- #1
127
128         int a = PLUS (1,2); <--- #2
129
130      There is a macro map for the expansion of PLUS in #2.  PLUS is
131      expanded into its expansion-list.  The expansion-list is the
132      replacement-list of PLUS where the macro parameters are replaced
133      with their arguments.  So the replacement-list of PLUS is made of
134      the tokens:
135
136         A, +, B
137
138      and the expansion-list is made of the tokens:
139
140         1, +, 2
141
142      Let's consider the case of token "+".  Its y1 [yI for I == 1] is
143      its spelling location in #1.
144
145      y0 (thus for token "1") is the spelling location of A in #1.
146
147      And y2 (of token "2") is the spelling location of B in #1.
148
149      When the token is /not/ an argument for a macro, xI is the same
150      location as yI.  Otherwise, xI is the location of the token
151      outside this macro expansion.  If this macro was expanded from
152      another macro expansion, xI is a virtual location representing
153      the token in that macro expansion; otherwise, it is the spelling
154      location of the token.
155
156      Note that a virtual location is a location returned by
157      linemap_add_macro_token.  It encodes the relevant locations (x,y
158      pairs) of that token accross the macro expansions from which it
159      (the token) might come from.
160
161      In the example above x1 (for token "+") is going to be the same
162      as y1.  x0 is the spelling location for the argument token "1",
163      and x2 is the spelling location for the argument token "2".  */
164   source_location * GTY((length ("2 * %h.n_tokens"))) macro_locations;
165
166   /* This is the location of the expansion point of the current macro
167      map.  It's the location of the macro name.  That location is held
168      by the map that was current right before the current one. It
169      could have been either a macro or an ordinary map, depending on
170      if we are in a nested expansion context not.  */
171   source_location expansion;
172 };
173
174 /* A line_map encodes a sequence of locations.
175    There are two kinds of maps. Ordinary maps and macro expansion
176    maps, a.k.a macro maps.
177
178    A macro map encodes source locations of tokens that are part of a
179    macro replacement-list, at a macro expansion point. E.g, in:
180
181             #define PLUS(A,B) A + B
182
183    No macro map is going to be created there, because we are not at a
184    macro expansion point. We are at a macro /definition/ point. So the
185    locations of the tokens of the macro replacement-list (i.e, A + B)
186    will be locations in an ordinary map, not a macro map.
187
188    On the other hand, if we later do:
189
190         int a = PLUS (1,2);
191
192    The invocation of PLUS here is a macro expansion. So we are at a
193    macro expansion point. The preprocessor expands PLUS (1,2) and
194    replaces it with the tokens of its replacement-list: 1 + 2. A macro
195    map is going to be created to hold (or rather to map, haha ...) the
196    locations of the tokens 1, + and 2. The macro map also records the
197    location of the expansion point of PLUS. That location is mapped in
198    the map that is active right before the location of the invocation
199    of PLUS.  */
200 struct GTY(()) line_map {
201   source_location start_location;
202
203   /* The reason for creation of this line map.  */
204   ENUM_BITFIELD (lc_reason) reason : CHAR_BIT;
205
206   union map_u {
207     struct line_map_ordinary GTY((tag ("0"))) ordinary;
208     struct line_map_macro GTY((tag ("1"))) macro;
209   } GTY((desc ("%1.reason == LC_ENTER_MACRO"))) d;
210 };
211
212 #define MAP_START_LOCATION(MAP) (MAP)->start_location
213
214 #define ORDINARY_MAP_FILE_NAME(MAP) \
215   linemap_check_ordinary (MAP)->d.ordinary.to_file
216
217 #define ORDINARY_MAP_STARTING_LINE_NUMBER(MAP) \
218   linemap_check_ordinary (MAP)->d.ordinary.to_line
219
220 #define ORDINARY_MAP_INCLUDER_FILE_INDEX(MAP) \
221   linemap_check_ordinary (MAP)->d.ordinary.included_from
222
223 #define ORDINARY_MAP_IN_SYSTEM_HEADER_P(MAP) \
224   linemap_check_ordinary (MAP)->d.ordinary.sysp
225
226 #define ORDINARY_MAP_NUMBER_OF_COLUMN_BITS(MAP) \
227   linemap_check_ordinary (MAP)->d.ordinary.column_bits
228
229 #define MACRO_MAP_MACRO(MAP) (MAP)->d.macro.macro
230
231 #define MACRO_MAP_NUM_MACRO_TOKENS(MAP) (MAP)->d.macro.n_tokens
232
233 #define MACRO_MAP_LOCATIONS(MAP) (MAP)->d.macro.macro_locations
234
235 #define MACRO_MAP_EXPANSION_POINT_LOCATION(MAP) (MAP)->d.macro.expansion
236
237 /* The abstraction of a set of location maps. There can be several
238    types of location maps. This abstraction contains the attributes
239    that are independent from the type of the map.  */
240 struct GTY(()) maps_info {
241   /* This array contains the different line maps.
242      A line map is created for the following events:
243        - when a new preprocessing unit start. 
244        - when a preprocessing unit ends.
245        - when a macro expansion occurs.  */
246   struct line_map * GTY ((length ("%h.used"))) maps;
247
248   /* The total number of allocated maps.  */
249   unsigned int allocated;
250
251   /* The number of elements used in maps. This number is smaller
252      or equal to ALLOCATED.  */
253   unsigned int used;
254
255   unsigned int cache;
256 };
257
258 /* A set of chronological line_map structures.  */
259 struct GTY(()) line_maps {
260   
261   struct maps_info info_ordinary;
262
263   struct maps_info info_macro;
264
265   /* Depth of the include stack, including the current file.  */
266   unsigned int depth;
267
268   /* If true, prints an include trace a la -H.  */
269   bool trace_includes;
270
271   /* Highest source_location "given out".  */
272   source_location highest_location;
273
274   /* Start of line of highest source_location "given out".  */
275   source_location highest_line;
276
277   /* The maximum column number we can quickly allocate.  Higher numbers
278      may require allocating a new line_map.  */
279   unsigned int max_column_hint;
280
281   /* If non-null, the allocator to use when resizing 'maps'.  If null,
282      xrealloc is used.  */
283   line_map_realloc reallocator;
284 };
285
286 /* Returns the pointer to the memory region where information about
287    maps are stored in the line table SET. MACRO_MAP_P is a flag
288    telling if we want macro or ordinary maps.  */
289 #define LINEMAPS_MAP_INFO(SET, MACRO_MAP_P)                             \
290   ((MACRO_MAP_P)                                                        \
291    ? &((SET)->info_macro)                                               \
292    : &((SET)->info_ordinary))
293
294 /* Returns the pointer to the memory region where maps are stored in
295    the line table SET. MAP_KIND shall be TRUE if we are interested in
296    macro maps false otherwise.  */
297 #define LINEMAPS_MAPS(SET, MAP_KIND) \
298   (LINEMAPS_MAP_INFO (SET, MAP_KIND))->maps
299
300 /* Returns the number of allocated maps so far. MAP_KIND shall be TRUE
301    if we are interested in macro maps, FALSE otherwise.  */
302 #define LINEMAPS_ALLOCATED(SET, MAP_KIND) \
303   (LINEMAPS_MAP_INFO (SET, MAP_KIND))->allocated
304
305 /* Returns the number of used maps so far. MAP_KIND shall be TRUE if
306    we are interested in macro maps, FALSE otherwise.*/
307 #define LINEMAPS_USED(SET, MAP_KIND) \
308   (LINEMAPS_MAP_INFO (SET, MAP_KIND))->used
309
310 /* Returns the index of the last map that was looked up with
311    linemap_lookup. MAP_KIND shall be TRUE if we are interested in
312    macro maps, FALSE otherwise.  */
313 #define LINEMAPS_CACHE(SET, MAP_KIND) \
314   (LINEMAPS_MAP_INFO (SET, MAP_KIND))->cache
315
316 /* Return the map at a given index.  */
317 #define LINEMAPS_MAP_AT(SET, MAP_KIND, INDEX)   \
318   (&((LINEMAPS_MAPS (SET, MAP_KIND))[(INDEX)]))
319
320 /* Returns the last map used in the line table SET. MAP_KIND
321    shall be TRUE if we are interested in macro maps, FALSE
322    otherwise.*/
323 #define LINEMAPS_LAST_MAP(SET, MAP_KIND) \
324   LINEMAPS_MAP_AT (SET, MAP_KIND, (LINEMAPS_USED (SET, MAP_KIND) - 1))
325
326 /* Returns the last map that was allocated in the line table SET.
327    MAP_KIND shall be TRUE if we are interested in macro maps, FALSE
328    otherwise.*/
329 #define LINEMAPS_LAST_ALLOCATED_MAP(SET, MAP_KIND) \
330   LINEMAPS_MAP_AT (SET, MAP_KIND, LINEMAPS_ALLOCATED (SET, MAP_KIND) - 1)
331
332 /* Returns a pointer to the memory region where ordinary maps are
333    allocated in the line table SET.  */
334 #define LINEMAPS_ORDINARY_MAPS(SET) \
335   LINEMAPS_MAPS (SET, false)
336
337 /* Returns the INDEXth ordinary map.  */
338 #define LINEMAPS_ORDINARY_MAP_AT(SET, INDEX)    \
339   LINEMAPS_MAP_AT (SET, false, INDEX)
340
341 /* Return the number of ordinary maps allocated in the line table
342    SET.  */
343 #define LINEMAPS_ORDINARY_ALLOCATED(SET) \
344   LINEMAPS_ALLOCATED(SET, false)
345
346 /* Return the number of ordinary maps used in the line table SET.  */
347 #define LINEMAPS_ORDINARY_USED(SET) \
348   LINEMAPS_USED(SET, false)
349
350 /* Return the index of the last ordinary map that was looked up with
351    linemap_lookup.  */
352 #define LINEMAPS_ORDINARY_CACHE(SET) \
353   LINEMAPS_CACHE(SET, false)
354
355 /* Returns a pointer to the last ordinary map used in the line table
356    SET.  */
357 #define LINEMAPS_LAST_ORDINARY_MAP(SET) \
358   LINEMAPS_LAST_MAP(SET, false)
359
360 /* Returns a pointer to the last ordinary map allocated the line table
361    SET.  */
362 #define LINEMAPS_LAST_ALLOCATED_ORDINARY_MAP(SET) \
363   LINEMAPS_LAST_ALLOCATED_MAP(SET, false)
364
365 /* Returns a pointer to the begining of the region where macro maps
366    are allcoated.  */
367 #define LINEMAPS_MACRO_MAPS(SET) \
368   LINEMAPS_MAPS(SET, true)
369
370 /* Returns the INDEXth macro map.  */
371 #define LINEMAPS_MACRO_MAP_AT(SET, INDEX)       \
372   LINEMAPS_MAP_AT (SET, true, INDEX)
373
374 /* Returns the number of macro maps that were allocated in the line
375    table SET.  */
376 #define LINEMAPS_MACRO_ALLOCATED(SET) \
377   LINEMAPS_ALLOCATED(SET, true)
378
379 /* Returns the number of macro maps used in the line table SET.  */
380 #define LINEMAPS_MACRO_USED(SET) \
381   LINEMAPS_USED(SET, true)
382
383 /* Returns the index of the last macro map looked up with
384    linemap_lookup.  */
385 #define LINEMAPS_MACRO_CACHE(SET) \
386   LINEMAPS_CACHE(SET, true)
387
388 /* Returns the lowest location [of a token resulting from macro
389    expansion] encoded in this line table.  */
390 #define LINEMAPS_MACRO_LOWEST_LOCATION(SET)                     \
391   (LINEMAPS_MACRO_USED (set)                                    \
392    ? MAP_START_LOCATION (LINEMAPS_LAST_MACRO_MAP (set))         \
393    : MAX_SOURCE_LOCATION)
394
395 /* Returns the last macro map used in the line table SET.  */
396 #define LINEMAPS_LAST_MACRO_MAP(SET) \
397   LINEMAPS_LAST_MAP (SET, true)
398
399 /* Returns the last macro map allocated in the line table SET.  */
400 #define LINEMAPS_LAST_ALLOCATED_MACRO_MAP(SET) \
401   LINEMAPS_LAST_ALLOCATED_MAP (SET, true)
402
403 /* Initialize a line map set.  */
404 extern void linemap_init (struct line_maps *);
405
406 /* Check for and warn about line_maps entered but not exited.  */
407
408 extern void linemap_check_files_exited (struct line_maps *);
409
410 /* Return a source_location for the start (i.e. column==0) of
411    (physical) line TO_LINE in the current source file (as in the
412    most recent linemap_add).   MAX_COLUMN_HINT is the highest column
413    number we expect to use in this line (but it does not change
414    the highest_location).  */
415
416 extern source_location linemap_line_start
417 (struct line_maps *set, linenum_type to_line,  unsigned int max_column_hint);
418
419 /* Add a mapping of logical source line to physical source file and
420    line number. This function creates an "ordinary map", which is a
421    map that records locations of tokens that are not part of macro
422    replacement-lists present at a macro expansion point.
423
424    The text pointed to by TO_FILE must have a lifetime
425    at least as long as the lifetime of SET.  An empty
426    TO_FILE means standard input.  If reason is LC_LEAVE, and
427    TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their
428    natural values considering the file we are returning to.
429
430    A call to this function can relocate the previous set of
431    maps, so any stored line_map pointers should not be used.  */
432 extern const struct line_map *linemap_add
433   (struct line_maps *, enum lc_reason, unsigned int sysp,
434    const char *to_file, linenum_type to_line);
435
436 /* Given a logical source location, returns the map which the
437    corresponding (source file, line, column) triplet can be deduced
438    from. Since the set is built chronologically, the logical lines are
439    monotonic increasing, and so the list is sorted and we can use a
440    binary search. If no line map have been allocated yet, this
441    function returns NULL.  */
442 extern const struct line_map *linemap_lookup
443   (struct line_maps *, source_location);
444
445 /* Returns TRUE if the line table set tracks token locations accross
446    macro expansion, FALSE otherwise.  */
447 bool linemap_tracks_macro_expansion_locs_p (struct line_maps *);
448
449 /* Return TRUE if MAP encodes locations coming from a macro
450    replacement-list at macro expansion point.  */
451 bool linemap_macro_expansion_map_p (const struct line_map *);
452
453 /* Return the name of the macro associated to MACRO_MAP.  */
454 const char* linemap_map_get_macro_name (const struct line_map*);
455
456 /* Return a positive value if LOCATION is the locus of a token that is
457    located in a system header, O otherwise. It returns 1 if LOCATION
458    is the locus of a token that is located in a system header, and 2
459    if LOCATION is the locus of a token located in a C system header
460    that therefore needs to be extern "C" protected in C++.
461
462    Note that this function returns 1 if LOCATION belongs to a token
463    that is part of a macro replacement-list defined in a system
464    header, but expanded in a non-system file.  */
465 int linemap_location_in_system_header_p (struct line_maps *,
466                                          source_location);
467
468 /* Return TRUE if LOCATION is a source code location of a token coming
469    from a macro replacement-list at a macro expansion point, FALSE
470    otherwise.  */
471 bool linemap_location_from_macro_expansion_p (struct line_maps *,
472                                               source_location);
473
474 /* source_location values from 0 to RESERVED_LOCATION_COUNT-1 will
475    be reserved for libcpp user as special values, no token from libcpp
476    will contain any of those locations.  */
477 #define RESERVED_LOCATION_COUNT 2
478
479 /* Converts a map and a source_location to source line.  */
480 #define SOURCE_LINE(MAP, LOC)                                           \
481   (((((LOC) - linemap_check_ordinary (MAP)->start_location)             \
482      >> (MAP)->d.ordinary.column_bits) + (MAP)->d.ordinary.to_line))
483
484 /* Convert a map and source_location to source column number.  */
485 #define SOURCE_COLUMN(MAP, LOC)                                         \
486   ((((LOC) - linemap_check_ordinary (MAP)->start_location)              \
487     & ((1 << (MAP)->d.ordinary.column_bits) - 1)))
488
489 /* Returns the last source line number within an ordinary map.  This
490    is the (last) line of the #include, or other directive, that caused
491    a map change.  */
492 #define LAST_SOURCE_LINE(MAP) \
493   SOURCE_LINE (MAP, LAST_SOURCE_LINE_LOCATION (MAP))
494
495 /* Return the last column number within an ordinary map.  */
496 #define LAST_SOURCE_COLUMN(MAP) \
497   SOURCE_COLUMN (MAP, LAST_SOURCE_LINE_LOCATION (MAP))
498
499 /* Return the location of the last source line within an ordinary
500    map.  */
501 #define LAST_SOURCE_LINE_LOCATION(MAP)                                  \
502   ((((linemap_check_ordinary (MAP)[1].start_location - 1                \
503       - (MAP)->start_location)                                          \
504      & ~((1 << (MAP)->d.ordinary.column_bits) - 1))                     \
505     + (MAP)->start_location))
506
507 /* Returns the map a given map was included from, or NULL if the map
508    belongs to the main file, i.e, a file that wasn't included by
509    another one.  */
510 #define INCLUDED_FROM(SET, MAP)                                         \
511   ((linemap_check_ordinary (MAP)->d.ordinary.included_from == -1)       \
512    ? NULL                                                               \
513    : (&LINEMAPS_ORDINARY_MAPS (SET)[(MAP)->d.ordinary.included_from]))
514
515 /* Nonzero if the map is at the bottom of the include stack.  */
516 #define MAIN_FILE_P(MAP)                                                \
517   ((linemap_check_ordinary (MAP)->d.ordinary.included_from < 0))
518
519 #if defined ENABLE_CHECKING && (GCC_VERSION >= 2007)
520
521 /* Assertion macro to be used in line-map code.  */
522 #define linemap_assert(EXPR)                    \
523   do {                                          \
524     if (! (EXPR))                               \
525       abort ();                                 \
526   } while (0)
527
528 /* Assert that MAP encodes locations of tokens that are not part of
529    the replacement-list of a macro expansion.  */
530 #define linemap_check_ordinary(LINE_MAP) __extension__          \
531   ({linemap_assert (!linemap_macro_expansion_map_p (LINE_MAP)); \
532     (LINE_MAP);})
533 #else
534 #define linemap_assert(EXPR)
535 #define linemap_check_ordinary(LINE_MAP) (LINE_MAP)
536 #endif
537
538 /* Encode and return a source_location from a column number. The
539    source line considered is the last source line used to call
540    linemap_line_start, i.e, the last source line which a location was
541    encoded from.  */
542 extern source_location
543 linemap_position_for_column (struct line_maps *, unsigned int);
544
545 /* Encode and return a source location from a given line and
546    column.  */
547 source_location linemap_position_for_line_and_column (struct line_map *,
548                                                       linenum_type,
549                                                       unsigned int);
550 /* Return the file this map is for.  */
551 #define LINEMAP_FILE(MAP)                                       \
552   (linemap_check_ordinary (MAP)->d.ordinary.to_file)
553
554 /* Return the line number this map started encoding location from.  */
555 #define LINEMAP_LINE(MAP)                                       \
556   (linemap_check_ordinary (MAP)->d.ordinary.to_line)
557
558 /* Return a positive value if map encodes locations from a system
559    header, 0 otherwise. Returns 1 if MAP encodes locations in a
560    system header and 2 if it encodes locations in a C system header
561    that therefore needs to be extern "C" protected in C++.  */
562 #define LINEMAP_SYSP(MAP)                                       \
563   (linemap_check_ordinary (MAP)->d.ordinary.sysp)
564
565 /* Return a positive value if PRE denotes the location of a token that
566    comes before the token of POST, 0 if PRE denotes the location of
567    the same token as the token for POST, and a negative value
568    otherwise.  */
569 int linemap_compare_locations (struct line_maps *set,
570                                source_location   pre,
571                                source_location   post);
572
573 /* Return TRUE if LOC_A denotes the location a token that comes
574    topogically before the token denoted by location LOC_B, or if they
575    are equal.  */
576 #define linemap_location_before_p(SET, LOC_A, LOC_B)    \
577   (linemap_compare_locations ((SET), (LOC_A), (LOC_B)) >= 0)
578
579 typedef struct
580 {
581   /* The name of the source file involved.  */
582   const char *file;
583
584   /* The line-location in the source file.  */
585   int line;
586
587   int column;
588
589   /* In a system header?. */
590   bool sysp;
591 } expanded_location;
592
593 /* This is enum is used by the function linemap_resolve_location
594    below.  The meaning of the values is explained in the comment of
595    that function.  */
596 enum location_resolution_kind
597 {
598   LRK_MACRO_EXPANSION_POINT,
599   LRK_SPELLING_LOCATION,
600   LRK_MACRO_DEFINITION_LOCATION
601 };
602
603 /* Resolve a virtual location into either a spelling location, an
604    expansion point location or a token argument replacement point
605    location.  Return the map that encodes the virtual location as well
606    as the resolved location.
607
608    If LOC is *NOT* the location of a token resulting from the
609    expansion of a macro, then the parameter LRK (which stands for
610    Location Resolution Kind) is ignored and the resulting location
611    just equals the one given in argument.
612
613    Now if LOC *IS* the location of a token resulting from the
614    expansion of a macro, this is what happens.
615
616    * If LRK is set to LRK_MACRO_EXPANSION_POINT
617    -------------------------------
618
619    The virtual location is resolved to the first macro expansion point
620    that led to this macro expansion.
621
622    * If LRK is set to LRK_SPELLING_LOCATION
623    -------------------------------------
624
625    The virtual location is resolved to the locus where the token has
626    been spelled in the source.   This can follow through all the macro
627    expansions that led to the token.
628
629    * If LRK is set to LRK_MACRO_DEFINITION_LOCATION
630    --------------------------------------
631
632    The virtual location is resolved to the locus of the token in the
633    context of the macro definition.
634
635    If LOC is the locus of a token that is an argument of a
636    function-like macro [replacing a parameter in the replacement list
637    of the macro] the virtual location is resolved to the locus of the
638    parameter that is replaced, in the context of the definition of the
639    macro.
640
641    If LOC is the locus of a token that is not an argument of a
642    function-like macro, then the function behaves as if LRK was set to
643    LRK_SPELLING_LOCATION.
644
645    If LOC_MAP is not NULL, *LOC_MAP is set to the map encoding the
646    returned location.  */
647
648 source_location linemap_resolve_location (struct line_maps *,
649                                           source_location loc,
650                                           enum location_resolution_kind lrk,
651                                           const struct line_map **loc_map);
652
653 /* Suppose that LOC is the virtual location of a token coming from the
654    expansion of a macro M.  This function then steps up to get the
655    location L of the point where M got expanded.  If L is a spelling
656    location inside a macro expansion M', then this function returns
657    the point where M' was expanded.  LOC_MAP is an output parameter.
658    When non-NULL, *LOC_MAP is set the the map of the returned
659    location.  */
660 source_location linemap_unwind_toward_expansion (struct line_maps *,
661                                                  source_location loc,
662                                                  const struct line_map **loc_map);
663
664 /* Expand source code location LOC and return a user readable source
665    code location.  LOC must be a spelling (non-virtual) location.  */
666
667 expanded_location linemap_expand_location (const struct line_map *,
668                                            source_location loc);
669
670 /* Expand source code location LOC and return a user readable source
671    code location.  LOC can be a virtual location.  The LRK parameter
672    is the same as for linemap_resolve_location.  */
673
674 expanded_location linemap_expand_location_full (struct line_maps *,
675                                                 source_location loc,
676                                                 enum location_resolution_kind lrk);
677
678 #endif /* !LIBCPP_LINE_MAP_H  */