OpenCores
URL https://opencores.org/ocsvn/altor32/altor32/trunk

Subversion Repositories altor32

[/] [altor32/] [trunk/] [gcc-x64/] [or1knd-elf/] [lib/] [gcc/] [or1knd-elf/] [4.8.0/] [plugin/] [include/] [line-map.h] - Blame information for rev 35

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 35 ultra_embe
/* 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
/* Memory allocator function that returns the actual allocated size,
57
   for a given requested allocation.  */
58
typedef size_t (*line_map_round_alloc_size_func) (size_t);
59
 
60
/* An ordinary line map encodes physical source locations. Those
61
   physical source locations are called "spelling locations".
62
 
63
   Physical source file TO_FILE at line TO_LINE at column 0 is represented
64
   by the logical START_LOCATION.  TO_LINE+L at column C is represented by
65
   START_LOCATION+(L*(1<<column_bits))+C, as long as C<(1<<column_bits),
66
   and the result_location is less than the next line_map's start_location.
67
   (The top line is line 1 and the leftmost column is column 1; line/column 0
68
   means "entire file/line" or "unknown line/column" or "not applicable".)
69
 
70
   The highest possible source location is MAX_SOURCE_LOCATION.  */
71
struct GTY(()) line_map_ordinary {
72
  const char *to_file;
73
  linenum_type to_line;
74
 
75
  /* An index into the set that gives the line mapping at whose end
76
     the current one was included.  File(s) at the bottom of the
77
     include stack have this set to -1.  */
78
  int included_from;
79
 
80
  /* SYSP is one for a system header, two for a C system header file
81
     that therefore needs to be extern "C" protected in C++, and zero
82
     otherwise.  This field isn't really needed now that it's in
83
     cpp_buffer.  */
84
  unsigned char sysp;
85
 
86
  /* Number of the low-order source_location bits used for a column number.  */
87
  unsigned int column_bits : 8;
88
};
89
 
90
/* This is the highest possible source location encoded within an
91
   ordinary or macro map.  */
92
#define MAX_SOURCE_LOCATION 0x7FFFFFFF
93
 
94
struct cpp_hashnode;
95
 
96
/* A macro line map encodes location of tokens coming from a macro
97
   expansion.
98
 
99
   Please note that this struct line_map_macro is a field of struct
100
   line_map below, go read the comments of struct line_map below and
101
   then come back here.
102
 
103
   The offset from START_LOCATION is used to index into
104
   MACRO_LOCATIONS; this holds the original location of the token.  */
105
struct GTY(()) line_map_macro {
106
  /* The cpp macro which expansion gave birth to this macro map.  */
107
  struct cpp_hashnode * GTY ((nested_ptr (union tree_node,
108
                                   "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
109
                                   "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL")))
110
    macro;
111
 
112
  /* The number of tokens inside the replacement-list of MACRO.  */
113
  unsigned int n_tokens;
114
 
115
  /* This array of location is actually an array of pairs of
116
     locations. The elements inside it thus look like:
117
 
118
           x0,y0, x1,y1, x2,y2, ...., xn,yn.
119
 
120
     where n == n_tokens;
121
 
122
     Remember that these xI,yI are collected when libcpp is about to
123
     expand a given macro.
124
 
125
     yI is the location in the macro definition, either of the token
126
     itself or of a macro parameter that it replaces.
127
 
128
     Imagine this:
129
 
130
        #define PLUS(A, B) A + B  <--- #1
131
 
132
        int a = PLUS (1,2); <--- #2
133
 
134
     There is a macro map for the expansion of PLUS in #2.  PLUS is
135
     expanded into its expansion-list.  The expansion-list is the
136
     replacement-list of PLUS where the macro parameters are replaced
137
     with their arguments.  So the replacement-list of PLUS is made of
138
     the tokens:
139
 
140
        A, +, B
141
 
142
     and the expansion-list is made of the tokens:
143
 
144
        1, +, 2
145
 
146
     Let's consider the case of token "+".  Its y1 [yI for I == 1] is
147
     its spelling location in #1.
148
 
149
     y0 (thus for token "1") is the spelling location of A in #1.
150
 
151
     And y2 (of token "2") is the spelling location of B in #1.
152
 
153
     When the token is /not/ an argument for a macro, xI is the same
154
     location as yI.  Otherwise, xI is the location of the token
155
     outside this macro expansion.  If this macro was expanded from
156
     another macro expansion, xI is a virtual location representing
157
     the token in that macro expansion; otherwise, it is the spelling
158
     location of the token.
159
 
160
     Note that a virtual location is a location returned by
161
     linemap_add_macro_token.  It encodes the relevant locations (x,y
162
     pairs) of that token across the macro expansions from which it
163
     (the token) might come from.
164
 
165
     In the example above x1 (for token "+") is going to be the same
166
     as y1.  x0 is the spelling location for the argument token "1",
167
     and x2 is the spelling location for the argument token "2".  */
168
  source_location * GTY((atomic)) macro_locations;
169
 
170
  /* This is the location of the expansion point of the current macro
171
     map.  It's the location of the macro name.  That location is held
172
     by the map that was current right before the current one. It
173
     could have been either a macro or an ordinary map, depending on
174
     if we are in a nested expansion context not.  */
175
  source_location expansion;
176
};
177
 
178
/* A line_map encodes a sequence of locations.
179
   There are two kinds of maps. Ordinary maps and macro expansion
180
   maps, a.k.a macro maps.
181
 
182
   A macro map encodes source locations of tokens that are part of a
183
   macro replacement-list, at a macro expansion point. E.g, in:
184
 
185
            #define PLUS(A,B) A + B
186
 
187
   No macro map is going to be created there, because we are not at a
188
   macro expansion point. We are at a macro /definition/ point. So the
189
   locations of the tokens of the macro replacement-list (i.e, A + B)
190
   will be locations in an ordinary map, not a macro map.
191
 
192
   On the other hand, if we later do:
193
 
194
        int a = PLUS (1,2);
195
 
196
   The invocation of PLUS here is a macro expansion. So we are at a
197
   macro expansion point. The preprocessor expands PLUS (1,2) and
198
   replaces it with the tokens of its replacement-list: 1 + 2. A macro
199
   map is going to be created to hold (or rather to map, haha ...) the
200
   locations of the tokens 1, + and 2. The macro map also records the
201
   location of the expansion point of PLUS. That location is mapped in
202
   the map that is active right before the location of the invocation
203
   of PLUS.  */
204
struct GTY(()) line_map {
205
  source_location start_location;
206
 
207
  /* The reason for creation of this line map.  */
208
  ENUM_BITFIELD (lc_reason) reason : CHAR_BIT;
209
 
210
  union map_u {
211
    struct line_map_ordinary GTY((tag ("0"))) ordinary;
212
    struct line_map_macro GTY((tag ("1"))) macro;
213
  } GTY((desc ("%1.reason == LC_ENTER_MACRO"))) d;
214
};
215
 
216
#define MAP_START_LOCATION(MAP) (MAP)->start_location
217
 
218
#define ORDINARY_MAP_FILE_NAME(MAP) \
219
  linemap_check_ordinary (MAP)->d.ordinary.to_file
220
 
221
#define ORDINARY_MAP_STARTING_LINE_NUMBER(MAP) \
222
  linemap_check_ordinary (MAP)->d.ordinary.to_line
223
 
224
#define ORDINARY_MAP_INCLUDER_FILE_INDEX(MAP) \
225
  linemap_check_ordinary (MAP)->d.ordinary.included_from
226
 
227
#define ORDINARY_MAP_IN_SYSTEM_HEADER_P(MAP) \
228
  linemap_check_ordinary (MAP)->d.ordinary.sysp
229
 
230
#define ORDINARY_MAP_NUMBER_OF_COLUMN_BITS(MAP) \
231
  linemap_check_ordinary (MAP)->d.ordinary.column_bits
232
 
233
#define MACRO_MAP_MACRO(MAP) (MAP)->d.macro.macro
234
 
235
#define MACRO_MAP_NUM_MACRO_TOKENS(MAP) (MAP)->d.macro.n_tokens
236
 
237
#define MACRO_MAP_LOCATIONS(MAP) (MAP)->d.macro.macro_locations
238
 
239
#define MACRO_MAP_EXPANSION_POINT_LOCATION(MAP) (MAP)->d.macro.expansion
240
 
241
/* The abstraction of a set of location maps. There can be several
242
   types of location maps. This abstraction contains the attributes
243
   that are independent from the type of the map.  */
244
struct GTY(()) maps_info {
245
  /* This array contains the different line maps.
246
     A line map is created for the following events:
247
       - when a new preprocessing unit start.
248
       - when a preprocessing unit ends.
249
       - when a macro expansion occurs.  */
250
  struct line_map * GTY ((length ("%h.used"))) maps;
251
 
252
  /* The total number of allocated maps.  */
253
  unsigned int allocated;
254
 
255
  /* The number of elements used in maps. This number is smaller
256
     or equal to ALLOCATED.  */
257
  unsigned int used;
258
 
259
  unsigned int cache;
260
};
261
 
262
/* Data structure to associate an arbitrary data to a source location.  */
263
struct GTY(()) location_adhoc_data {
264
  source_location locus;
265
  void * GTY((skip)) data;
266
};
267
 
268
struct htab;
269
 
270
/* The following data structure encodes a location with some adhoc data
271
   and maps it to a new unsigned integer (called an adhoc location)
272
   that replaces the original location to represent the mapping.
273
 
274
   The new adhoc_loc uses the highest bit as the enabling bit, i.e. if the
275
   highest bit is 1, then the number is adhoc_loc. Otherwise, it serves as
276
   the original location. Once identified as the adhoc_loc, the lower 31
277
   bits of the integer is used to index the location_adhoc_data array,
278
   in which the locus and associated data is stored.  */
279
 
280
struct GTY(()) location_adhoc_data_map {
281
  struct htab * GTY((skip)) htab;
282
  source_location curr_loc;
283
  unsigned int allocated;
284
  struct location_adhoc_data GTY((length ("%h.allocated"))) *data;
285
};
286
 
287
/* A set of chronological line_map structures.  */
288
struct GTY(()) line_maps {
289
 
290
  struct maps_info info_ordinary;
291
 
292
  struct maps_info info_macro;
293
 
294
  /* Depth of the include stack, including the current file.  */
295
  unsigned int depth;
296
 
297
  /* If true, prints an include trace a la -H.  */
298
  bool trace_includes;
299
 
300
  /* Highest source_location "given out".  */
301
  source_location highest_location;
302
 
303
  /* Start of line of highest source_location "given out".  */
304
  source_location highest_line;
305
 
306
  /* The maximum column number we can quickly allocate.  Higher numbers
307
     may require allocating a new line_map.  */
308
  unsigned int max_column_hint;
309
 
310
  /* If non-null, the allocator to use when resizing 'maps'.  If null,
311
     xrealloc is used.  */
312
  line_map_realloc reallocator;
313
 
314
  /* The allocators' function used to know the actual size it
315
     allocated, for a certain allocation size requested.  */
316
  line_map_round_alloc_size_func round_alloc_size;
317
 
318
  struct location_adhoc_data_map location_adhoc_data_map;
319
};
320
 
321
/* Returns the pointer to the memory region where information about
322
   maps are stored in the line table SET. MACRO_MAP_P is a flag
323
   telling if we want macro or ordinary maps.  */
324
#define LINEMAPS_MAP_INFO(SET, MACRO_MAP_P)                             \
325
  ((MACRO_MAP_P)                                                        \
326
   ? &((SET)->info_macro)                                               \
327
   : &((SET)->info_ordinary))
328
 
329
/* Returns the pointer to the memory region where maps are stored in
330
   the line table SET. MAP_KIND shall be TRUE if we are interested in
331
   macro maps false otherwise.  */
332
#define LINEMAPS_MAPS(SET, MAP_KIND) \
333
  (LINEMAPS_MAP_INFO (SET, MAP_KIND))->maps
334
 
335
/* Returns the number of allocated maps so far. MAP_KIND shall be TRUE
336
   if we are interested in macro maps, FALSE otherwise.  */
337
#define LINEMAPS_ALLOCATED(SET, MAP_KIND) \
338
  (LINEMAPS_MAP_INFO (SET, MAP_KIND))->allocated
339
 
340
/* Returns the number of used maps so far. MAP_KIND shall be TRUE if
341
   we are interested in macro maps, FALSE otherwise.*/
342
#define LINEMAPS_USED(SET, MAP_KIND) \
343
  (LINEMAPS_MAP_INFO (SET, MAP_KIND))->used
344
 
345
/* Returns the index of the last map that was looked up with
346
   linemap_lookup. MAP_KIND shall be TRUE if we are interested in
347
   macro maps, FALSE otherwise.  */
348
#define LINEMAPS_CACHE(SET, MAP_KIND) \
349
  (LINEMAPS_MAP_INFO (SET, MAP_KIND))->cache
350
 
351
/* Return the map at a given index.  */
352
#define LINEMAPS_MAP_AT(SET, MAP_KIND, INDEX)   \
353
  (&((LINEMAPS_MAPS (SET, MAP_KIND))[(INDEX)]))
354
 
355
/* Returns the last map used in the line table SET. MAP_KIND
356
   shall be TRUE if we are interested in macro maps, FALSE
357
   otherwise.*/
358
#define LINEMAPS_LAST_MAP(SET, MAP_KIND) \
359
  LINEMAPS_MAP_AT (SET, MAP_KIND, (LINEMAPS_USED (SET, MAP_KIND) - 1))
360
 
361
/* Returns the last map that was allocated in the line table SET.
362
   MAP_KIND shall be TRUE if we are interested in macro maps, FALSE
363
   otherwise.*/
364
#define LINEMAPS_LAST_ALLOCATED_MAP(SET, MAP_KIND) \
365
  LINEMAPS_MAP_AT (SET, MAP_KIND, LINEMAPS_ALLOCATED (SET, MAP_KIND) - 1)
366
 
367
/* Returns a pointer to the memory region where ordinary maps are
368
   allocated in the line table SET.  */
369
#define LINEMAPS_ORDINARY_MAPS(SET) \
370
  LINEMAPS_MAPS (SET, false)
371
 
372
/* Returns the INDEXth ordinary map.  */
373
#define LINEMAPS_ORDINARY_MAP_AT(SET, INDEX)    \
374
  LINEMAPS_MAP_AT (SET, false, INDEX)
375
 
376
/* Return the number of ordinary maps allocated in the line table
377
   SET.  */
378
#define LINEMAPS_ORDINARY_ALLOCATED(SET) \
379
  LINEMAPS_ALLOCATED(SET, false)
380
 
381
/* Return the number of ordinary maps used in the line table SET.  */
382
#define LINEMAPS_ORDINARY_USED(SET) \
383
  LINEMAPS_USED(SET, false)
384
 
385
/* Return the index of the last ordinary map that was looked up with
386
   linemap_lookup.  */
387
#define LINEMAPS_ORDINARY_CACHE(SET) \
388
  LINEMAPS_CACHE(SET, false)
389
 
390
/* Returns a pointer to the last ordinary map used in the line table
391
   SET.  */
392
#define LINEMAPS_LAST_ORDINARY_MAP(SET) \
393
  LINEMAPS_LAST_MAP(SET, false)
394
 
395
/* Returns a pointer to the last ordinary map allocated the line table
396
   SET.  */
397
#define LINEMAPS_LAST_ALLOCATED_ORDINARY_MAP(SET) \
398
  LINEMAPS_LAST_ALLOCATED_MAP(SET, false)
399
 
400
/* Returns a pointer to the beginning of the region where macro maps
401
   are allcoated.  */
402
#define LINEMAPS_MACRO_MAPS(SET) \
403
  LINEMAPS_MAPS(SET, true)
404
 
405
/* Returns the INDEXth macro map.  */
406
#define LINEMAPS_MACRO_MAP_AT(SET, INDEX)       \
407
  LINEMAPS_MAP_AT (SET, true, INDEX)
408
 
409
/* Returns the number of macro maps that were allocated in the line
410
   table SET.  */
411
#define LINEMAPS_MACRO_ALLOCATED(SET) \
412
  LINEMAPS_ALLOCATED(SET, true)
413
 
414
/* Returns the number of macro maps used in the line table SET.  */
415
#define LINEMAPS_MACRO_USED(SET) \
416
  LINEMAPS_USED(SET, true)
417
 
418
/* Returns the index of the last macro map looked up with
419
   linemap_lookup.  */
420
#define LINEMAPS_MACRO_CACHE(SET) \
421
  LINEMAPS_CACHE(SET, true)
422
 
423
/* Returns the lowest location [of a token resulting from macro
424
   expansion] encoded in this line table.  */
425
#define LINEMAPS_MACRO_LOWEST_LOCATION(SET)                     \
426
  (LINEMAPS_MACRO_USED (set)                                    \
427
   ? MAP_START_LOCATION (LINEMAPS_LAST_MACRO_MAP (set))         \
428
   : MAX_SOURCE_LOCATION)
429
 
430
/* Returns the last macro map used in the line table SET.  */
431
#define LINEMAPS_LAST_MACRO_MAP(SET) \
432
  LINEMAPS_LAST_MAP (SET, true)
433
 
434
/* Returns the last macro map allocated in the line table SET.  */
435
#define LINEMAPS_LAST_ALLOCATED_MACRO_MAP(SET) \
436
  LINEMAPS_LAST_ALLOCATED_MAP (SET, true)
437
 
438
extern void location_adhoc_data_fini (struct line_maps *);
439
extern source_location get_combined_adhoc_loc (struct line_maps *,
440
                                               source_location, void *);
441
extern void *get_data_from_adhoc_loc (struct line_maps *, source_location);
442
extern source_location get_location_from_adhoc_loc (struct line_maps *,
443
                                                    source_location);
444
 
445
#define IS_ADHOC_LOC(LOC) (((LOC) & MAX_SOURCE_LOCATION) != (LOC))
446
#define COMBINE_LOCATION_DATA(SET, LOC, BLOCK) \
447
  get_combined_adhoc_loc ((SET), (LOC), (BLOCK))
448
 
449
extern void rebuild_location_adhoc_htab (struct line_maps *);
450
 
451
/* Initialize a line map set.  */
452
extern void linemap_init (struct line_maps *);
453
 
454
/* Check for and warn about line_maps entered but not exited.  */
455
 
456
extern void linemap_check_files_exited (struct line_maps *);
457
 
458
/* Return a source_location for the start (i.e. column==0) of
459
   (physical) line TO_LINE in the current source file (as in the
460
   most recent linemap_add).   MAX_COLUMN_HINT is the highest column
461
   number we expect to use in this line (but it does not change
462
   the highest_location).  */
463
 
464
extern source_location linemap_line_start
465
(struct line_maps *set, linenum_type to_line,  unsigned int max_column_hint);
466
 
467
/* Add a mapping of logical source line to physical source file and
468
   line number. This function creates an "ordinary map", which is a
469
   map that records locations of tokens that are not part of macro
470
   replacement-lists present at a macro expansion point.
471
 
472
   The text pointed to by TO_FILE must have a lifetime
473
   at least as long as the lifetime of SET.  An empty
474
   TO_FILE means standard input.  If reason is LC_LEAVE, and
475
   TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their
476
   natural values considering the file we are returning to.
477
 
478
   A call to this function can relocate the previous set of
479
   maps, so any stored line_map pointers should not be used.  */
480
extern const struct line_map *linemap_add
481
  (struct line_maps *, enum lc_reason, unsigned int sysp,
482
   const char *to_file, linenum_type to_line);
483
 
484
/* Given a logical source location, returns the map which the
485
   corresponding (source file, line, column) triplet can be deduced
486
   from. Since the set is built chronologically, the logical lines are
487
   monotonic increasing, and so the list is sorted and we can use a
488
   binary search. If no line map have been allocated yet, this
489
   function returns NULL.  */
490
extern const struct line_map *linemap_lookup
491
  (struct line_maps *, source_location);
492
 
493
/* Returns TRUE if the line table set tracks token locations across
494
   macro expansion, FALSE otherwise.  */
495
bool linemap_tracks_macro_expansion_locs_p (struct line_maps *);
496
 
497
/* Return TRUE if MAP encodes locations coming from a macro
498
   replacement-list at macro expansion point.  */
499
bool linemap_macro_expansion_map_p (const struct line_map *);
500
 
501
/* Return the name of the macro associated to MACRO_MAP.  */
502
const char* linemap_map_get_macro_name (const struct line_map*);
503
 
504
/* Return a positive value if LOCATION is the locus of a token that is
505
   located in a system header, O otherwise. It returns 1 if LOCATION
506
   is the locus of a token that is located in a system header, and 2
507
   if LOCATION is the locus of a token located in a C system header
508
   that therefore needs to be extern "C" protected in C++.
509
 
510
   Note that this function returns 1 if LOCATION belongs to a token
511
   that is part of a macro replacement-list defined in a system
512
   header, but expanded in a non-system file.  */
513
int linemap_location_in_system_header_p (struct line_maps *,
514
                                         source_location);
515
 
516
/* Return TRUE if LOCATION is a source code location of a token coming
517
   from a macro replacement-list at a macro expansion point, FALSE
518
   otherwise.  */
519
bool linemap_location_from_macro_expansion_p (struct line_maps *,
520
                                              source_location);
521
 
522
/* source_location values from 0 to RESERVED_LOCATION_COUNT-1 will
523
   be reserved for libcpp user as special values, no token from libcpp
524
   will contain any of those locations.  */
525
#define RESERVED_LOCATION_COUNT 2
526
 
527
/* Converts a map and a source_location to source line.  */
528
#define SOURCE_LINE(MAP, LOC)                                           \
529
  (((((LOC) - linemap_check_ordinary (MAP)->start_location)             \
530
     >> (MAP)->d.ordinary.column_bits) + (MAP)->d.ordinary.to_line))
531
 
532
/* Convert a map and source_location to source column number.  */
533
#define SOURCE_COLUMN(MAP, LOC)                                         \
534
  ((((LOC) - linemap_check_ordinary (MAP)->start_location)              \
535
    & ((1 << (MAP)->d.ordinary.column_bits) - 1)))
536
 
537
/* Returns the last source line number within an ordinary map.  This
538
   is the (last) line of the #include, or other directive, that caused
539
   a map change.  */
540
#define LAST_SOURCE_LINE(MAP) \
541
  SOURCE_LINE (MAP, LAST_SOURCE_LINE_LOCATION (MAP))
542
 
543
/* Return the last column number within an ordinary map.  */
544
#define LAST_SOURCE_COLUMN(MAP) \
545
  SOURCE_COLUMN (MAP, LAST_SOURCE_LINE_LOCATION (MAP))
546
 
547
/* Return the location of the last source line within an ordinary
548
   map.  */
549
#define LAST_SOURCE_LINE_LOCATION(MAP)                                  \
550
  ((((linemap_check_ordinary (MAP)[1].start_location - 1                \
551
      - (MAP)->start_location)                                          \
552
     & ~((1 << (MAP)->d.ordinary.column_bits) - 1))                     \
553
    + (MAP)->start_location))
554
 
555
/* Returns the map a given map was included from, or NULL if the map
556
   belongs to the main file, i.e, a file that wasn't included by
557
   another one.  */
558
#define INCLUDED_FROM(SET, MAP)                                         \
559
  ((linemap_check_ordinary (MAP)->d.ordinary.included_from == -1)       \
560
   ? NULL                                                               \
561
   : (&LINEMAPS_ORDINARY_MAPS (SET)[(MAP)->d.ordinary.included_from]))
562
 
563
/* Nonzero if the map is at the bottom of the include stack.  */
564
#define MAIN_FILE_P(MAP)                                                \
565
  ((linemap_check_ordinary (MAP)->d.ordinary.included_from < 0))
566
 
567
#if defined ENABLE_CHECKING && (GCC_VERSION >= 2007)
568
 
569
/* Assertion macro to be used in line-map code.  */
570
#define linemap_assert(EXPR)                    \
571
  do {                                          \
572
    if (! (EXPR))                               \
573
      abort ();                                 \
574
  } while (0)
575
 
576
/* Assert that MAP encodes locations of tokens that are not part of
577
   the replacement-list of a macro expansion.  */
578
#define linemap_check_ordinary(LINE_MAP) __extension__          \
579
  ({linemap_assert (!linemap_macro_expansion_map_p (LINE_MAP)); \
580
    (LINE_MAP);})
581
#else
582
#define linemap_assert(EXPR)
583
#define linemap_check_ordinary(LINE_MAP) (LINE_MAP)
584
#endif
585
 
586
/* Encode and return a source_location from a column number. The
587
   source line considered is the last source line used to call
588
   linemap_line_start, i.e, the last source line which a location was
589
   encoded from.  */
590
extern source_location
591
linemap_position_for_column (struct line_maps *, unsigned int);
592
 
593
/* Encode and return a source location from a given line and
594
   column.  */
595
source_location linemap_position_for_line_and_column (struct line_map *,
596
                                                      linenum_type,
597
                                                      unsigned int);
598
/* Return the file this map is for.  */
599
#define LINEMAP_FILE(MAP)                                       \
600
  (linemap_check_ordinary (MAP)->d.ordinary.to_file)
601
 
602
/* Return the line number this map started encoding location from.  */
603
#define LINEMAP_LINE(MAP)                                       \
604
  (linemap_check_ordinary (MAP)->d.ordinary.to_line)
605
 
606
/* Return a positive value if map encodes locations from a system
607
   header, 0 otherwise. Returns 1 if MAP encodes locations in a
608
   system header and 2 if it encodes locations in a C system header
609
   that therefore needs to be extern "C" protected in C++.  */
610
#define LINEMAP_SYSP(MAP)                                       \
611
  (linemap_check_ordinary (MAP)->d.ordinary.sysp)
612
 
613
/* Return a positive value if PRE denotes the location of a token that
614
   comes before the token of POST, 0 if PRE denotes the location of
615
   the same token as the token for POST, and a negative value
616
   otherwise.  */
617
int linemap_compare_locations (struct line_maps *set,
618
                               source_location   pre,
619
                               source_location   post);
620
 
621
/* Return TRUE if LOC_A denotes the location a token that comes
622
   topogically before the token denoted by location LOC_B, or if they
623
   are equal.  */
624
#define linemap_location_before_p(SET, LOC_A, LOC_B)    \
625
  (linemap_compare_locations ((SET), (LOC_A), (LOC_B)) >= 0)
626
 
627
typedef struct
628
{
629
  /* The name of the source file involved.  */
630
  const char *file;
631
 
632
  /* The line-location in the source file.  */
633
  int line;
634
 
635
  int column;
636
 
637
  void *data;
638
 
639
  /* In a system header?. */
640
  bool sysp;
641
} expanded_location;
642
 
643
/* This is enum is used by the function linemap_resolve_location
644
   below.  The meaning of the values is explained in the comment of
645
   that function.  */
646
enum location_resolution_kind
647
{
648
  LRK_MACRO_EXPANSION_POINT,
649
  LRK_SPELLING_LOCATION,
650
  LRK_MACRO_DEFINITION_LOCATION
651
};
652
 
653
/* Resolve a virtual location into either a spelling location, an
654
   expansion point location or a token argument replacement point
655
   location.  Return the map that encodes the virtual location as well
656
   as the resolved location.
657
 
658
   If LOC is *NOT* the location of a token resulting from the
659
   expansion of a macro, then the parameter LRK (which stands for
660
   Location Resolution Kind) is ignored and the resulting location
661
   just equals the one given in argument.
662
 
663
   Now if LOC *IS* the location of a token resulting from the
664
   expansion of a macro, this is what happens.
665
 
666
   * If LRK is set to LRK_MACRO_EXPANSION_POINT
667
   -------------------------------
668
 
669
   The virtual location is resolved to the first macro expansion point
670
   that led to this macro expansion.
671
 
672
   * If LRK is set to LRK_SPELLING_LOCATION
673
   -------------------------------------
674
 
675
   The virtual location is resolved to the locus where the token has
676
   been spelled in the source.   This can follow through all the macro
677
   expansions that led to the token.
678
 
679
   * If LRK is set to LRK_MACRO_DEFINITION_LOCATION
680
   --------------------------------------
681
 
682
   The virtual location is resolved to the locus of the token in the
683
   context of the macro definition.
684
 
685
   If LOC is the locus of a token that is an argument of a
686
   function-like macro [replacing a parameter in the replacement list
687
   of the macro] the virtual location is resolved to the locus of the
688
   parameter that is replaced, in the context of the definition of the
689
   macro.
690
 
691
   If LOC is the locus of a token that is not an argument of a
692
   function-like macro, then the function behaves as if LRK was set to
693
   LRK_SPELLING_LOCATION.
694
 
695
   If LOC_MAP is not NULL, *LOC_MAP is set to the map encoding the
696
   returned location.  Note that if the returned location wasn't originally
697
   encoded by a map, the *MAP is set to NULL.  This can happen if LOC
698
   resolves to a location reserved for the client code, like
699
   UNKNOWN_LOCATION or BUILTINS_LOCATION in GCC.  */
700
 
701
source_location linemap_resolve_location (struct line_maps *,
702
                                          source_location loc,
703
                                          enum location_resolution_kind lrk,
704
                                          const struct line_map **loc_map);
705
 
706
/* Suppose that LOC is the virtual location of a token coming from the
707
   expansion of a macro M.  This function then steps up to get the
708
   location L of the point where M got expanded.  If L is a spelling
709
   location inside a macro expansion M', then this function returns
710
   the point where M' was expanded.  LOC_MAP is an output parameter.
711
   When non-NULL, *LOC_MAP is set to the map of the returned
712
   location.  */
713
source_location linemap_unwind_toward_expansion (struct line_maps *,
714
                                                 source_location loc,
715
                                                 const struct line_map **loc_map);
716
 
717
/* If LOC is the virtual location of a token coming from the expansion
718
   of a macro M and if its spelling location is reserved (e.g, a
719
   location for a built-in token), then this function unwinds (using
720
   linemap_unwind_toward_expansion) the location until a location that
721
   is not reserved and is not in a system header is reached.  In other
722
   words, this unwinds the reserved location until a location that is
723
   in real source code is reached.
724
 
725
   Otherwise, if the spelling location for LOC is not reserved or if
726
   LOC doesn't come from the expansion of a macro, the function
727
   returns LOC as is and *MAP is not touched.
728
 
729
   *MAP is set to the map of the returned location if the later is
730
   different from LOC.  */
731
source_location linemap_unwind_to_first_non_reserved_loc (struct line_maps *,
732
                                                          source_location loc,
733
                                                          const struct line_map **map);
734
 
735
/* Expand source code location LOC and return a user readable source
736
   code location.  LOC must be a spelling (non-virtual) location.  If
737
   it's a location < RESERVED_LOCATION_COUNT a zeroed expanded source
738
   location is returned.  */
739
expanded_location linemap_expand_location (struct line_maps *,
740
                                           const struct line_map *,
741
                                           source_location loc);
742
 
743
/* Statistics about maps allocation and usage as returned by
744
   linemap_get_statistics.  */
745
struct linemap_stats
746
{
747
  long num_ordinary_maps_allocated;
748
  long num_ordinary_maps_used;
749
  long ordinary_maps_allocated_size;
750
  long ordinary_maps_used_size;
751
  long num_expanded_macros;
752
  long num_macro_tokens;
753
  long num_macro_maps_used;
754
  long macro_maps_allocated_size;
755
  long macro_maps_used_size;
756
  long macro_maps_locations_size;
757
  long duplicated_macro_maps_locations_size;
758
};
759
 
760
/* Compute and return statistics about the memory consumption of some
761
   parts of the line table SET.  */
762
void linemap_get_statistics (struct line_maps *, struct linemap_stats *);
763
 
764
/* Dump debugging information about source location LOC into the file
765
   stream STREAM. SET is the line map set LOC comes from.  */
766
void linemap_dump_location (struct line_maps *, source_location, FILE *);
767
 
768
/* Dump line map at index IX in line table SET to STREAM.  If STREAM
769
   is NULL, use stderr.  IS_MACRO is true if the caller wants to
770
   dump a macro map, false otherwise.  */
771
void linemap_dump (FILE *, struct line_maps *, unsigned, bool);
772
 
773
/* Dump line table SET to STREAM.  If STREAM is NULL, stderr is used.
774
   NUM_ORDINARY specifies how many ordinary maps to dump.  NUM_MACRO
775
   specifies how many macro maps to dump.  */
776
void line_table_dump (FILE *, struct line_maps *, unsigned int, unsigned int);
777
 
778
#endif /* !LIBCPP_LINE_MAP_H  */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.