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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libcpp/] [include/] [line-map.h] - Blame information for rev 800

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 730 jeremybenn
/* 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 0xFFFFFFFF
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 accross 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((length ("2 * %h.n_tokens"))) 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
/* A set of chronological line_map structures.  */
263
struct GTY(()) line_maps {
264
 
265
  struct maps_info info_ordinary;
266
 
267
  struct maps_info info_macro;
268
 
269
  /* Depth of the include stack, including the current file.  */
270
  unsigned int depth;
271
 
272
  /* If true, prints an include trace a la -H.  */
273
  bool trace_includes;
274
 
275
  /* Highest source_location "given out".  */
276
  source_location highest_location;
277
 
278
  /* Start of line of highest source_location "given out".  */
279
  source_location highest_line;
280
 
281
  /* The maximum column number we can quickly allocate.  Higher numbers
282
     may require allocating a new line_map.  */
283
  unsigned int max_column_hint;
284
 
285
  /* If non-null, the allocator to use when resizing 'maps'.  If null,
286
     xrealloc is used.  */
287
  line_map_realloc reallocator;
288
 
289
  /* The allocators' function used to know the actual size it
290
     allocated, for a certain allocation size requested.  */
291
  line_map_round_alloc_size_func round_alloc_size;
292
};
293
 
294
/* Returns the pointer to the memory region where information about
295
   maps are stored in the line table SET. MACRO_MAP_P is a flag
296
   telling if we want macro or ordinary maps.  */
297
#define LINEMAPS_MAP_INFO(SET, MACRO_MAP_P)                             \
298
  ((MACRO_MAP_P)                                                        \
299
   ? &((SET)->info_macro)                                               \
300
   : &((SET)->info_ordinary))
301
 
302
/* Returns the pointer to the memory region where maps are stored in
303
   the line table SET. MAP_KIND shall be TRUE if we are interested in
304
   macro maps false otherwise.  */
305
#define LINEMAPS_MAPS(SET, MAP_KIND) \
306
  (LINEMAPS_MAP_INFO (SET, MAP_KIND))->maps
307
 
308
/* Returns the number of allocated maps so far. MAP_KIND shall be TRUE
309
   if we are interested in macro maps, FALSE otherwise.  */
310
#define LINEMAPS_ALLOCATED(SET, MAP_KIND) \
311
  (LINEMAPS_MAP_INFO (SET, MAP_KIND))->allocated
312
 
313
/* Returns the number of used maps so far. MAP_KIND shall be TRUE if
314
   we are interested in macro maps, FALSE otherwise.*/
315
#define LINEMAPS_USED(SET, MAP_KIND) \
316
  (LINEMAPS_MAP_INFO (SET, MAP_KIND))->used
317
 
318
/* Returns the index of the last map that was looked up with
319
   linemap_lookup. MAP_KIND shall be TRUE if we are interested in
320
   macro maps, FALSE otherwise.  */
321
#define LINEMAPS_CACHE(SET, MAP_KIND) \
322
  (LINEMAPS_MAP_INFO (SET, MAP_KIND))->cache
323
 
324
/* Return the map at a given index.  */
325
#define LINEMAPS_MAP_AT(SET, MAP_KIND, INDEX)   \
326
  (&((LINEMAPS_MAPS (SET, MAP_KIND))[(INDEX)]))
327
 
328
/* Returns the last map used in the line table SET. MAP_KIND
329
   shall be TRUE if we are interested in macro maps, FALSE
330
   otherwise.*/
331
#define LINEMAPS_LAST_MAP(SET, MAP_KIND) \
332
  LINEMAPS_MAP_AT (SET, MAP_KIND, (LINEMAPS_USED (SET, MAP_KIND) - 1))
333
 
334
/* Returns the last map that was allocated in the line table SET.
335
   MAP_KIND shall be TRUE if we are interested in macro maps, FALSE
336
   otherwise.*/
337
#define LINEMAPS_LAST_ALLOCATED_MAP(SET, MAP_KIND) \
338
  LINEMAPS_MAP_AT (SET, MAP_KIND, LINEMAPS_ALLOCATED (SET, MAP_KIND) - 1)
339
 
340
/* Returns a pointer to the memory region where ordinary maps are
341
   allocated in the line table SET.  */
342
#define LINEMAPS_ORDINARY_MAPS(SET) \
343
  LINEMAPS_MAPS (SET, false)
344
 
345
/* Returns the INDEXth ordinary map.  */
346
#define LINEMAPS_ORDINARY_MAP_AT(SET, INDEX)    \
347
  LINEMAPS_MAP_AT (SET, false, INDEX)
348
 
349
/* Return the number of ordinary maps allocated in the line table
350
   SET.  */
351
#define LINEMAPS_ORDINARY_ALLOCATED(SET) \
352
  LINEMAPS_ALLOCATED(SET, false)
353
 
354
/* Return the number of ordinary maps used in the line table SET.  */
355
#define LINEMAPS_ORDINARY_USED(SET) \
356
  LINEMAPS_USED(SET, false)
357
 
358
/* Return the index of the last ordinary map that was looked up with
359
   linemap_lookup.  */
360
#define LINEMAPS_ORDINARY_CACHE(SET) \
361
  LINEMAPS_CACHE(SET, false)
362
 
363
/* Returns a pointer to the last ordinary map used in the line table
364
   SET.  */
365
#define LINEMAPS_LAST_ORDINARY_MAP(SET) \
366
  LINEMAPS_LAST_MAP(SET, false)
367
 
368
/* Returns a pointer to the last ordinary map allocated the line table
369
   SET.  */
370
#define LINEMAPS_LAST_ALLOCATED_ORDINARY_MAP(SET) \
371
  LINEMAPS_LAST_ALLOCATED_MAP(SET, false)
372
 
373
/* Returns a pointer to the begining of the region where macro maps
374
   are allcoated.  */
375
#define LINEMAPS_MACRO_MAPS(SET) \
376
  LINEMAPS_MAPS(SET, true)
377
 
378
/* Returns the INDEXth macro map.  */
379
#define LINEMAPS_MACRO_MAP_AT(SET, INDEX)       \
380
  LINEMAPS_MAP_AT (SET, true, INDEX)
381
 
382
/* Returns the number of macro maps that were allocated in the line
383
   table SET.  */
384
#define LINEMAPS_MACRO_ALLOCATED(SET) \
385
  LINEMAPS_ALLOCATED(SET, true)
386
 
387
/* Returns the number of macro maps used in the line table SET.  */
388
#define LINEMAPS_MACRO_USED(SET) \
389
  LINEMAPS_USED(SET, true)
390
 
391
/* Returns the index of the last macro map looked up with
392
   linemap_lookup.  */
393
#define LINEMAPS_MACRO_CACHE(SET) \
394
  LINEMAPS_CACHE(SET, true)
395
 
396
/* Returns the lowest location [of a token resulting from macro
397
   expansion] encoded in this line table.  */
398
#define LINEMAPS_MACRO_LOWEST_LOCATION(SET)                     \
399
  (LINEMAPS_MACRO_USED (set)                                    \
400
   ? MAP_START_LOCATION (LINEMAPS_LAST_MACRO_MAP (set))         \
401
   : MAX_SOURCE_LOCATION)
402
 
403
/* Returns the last macro map used in the line table SET.  */
404
#define LINEMAPS_LAST_MACRO_MAP(SET) \
405
  LINEMAPS_LAST_MAP (SET, true)
406
 
407
/* Returns the last macro map allocated in the line table SET.  */
408
#define LINEMAPS_LAST_ALLOCATED_MACRO_MAP(SET) \
409
  LINEMAPS_LAST_ALLOCATED_MAP (SET, true)
410
 
411
/* Initialize a line map set.  */
412
extern void linemap_init (struct line_maps *);
413
 
414
/* Check for and warn about line_maps entered but not exited.  */
415
 
416
extern void linemap_check_files_exited (struct line_maps *);
417
 
418
/* Return a source_location for the start (i.e. column==0) of
419
   (physical) line TO_LINE in the current source file (as in the
420
   most recent linemap_add).   MAX_COLUMN_HINT is the highest column
421
   number we expect to use in this line (but it does not change
422
   the highest_location).  */
423
 
424
extern source_location linemap_line_start
425
(struct line_maps *set, linenum_type to_line,  unsigned int max_column_hint);
426
 
427
/* Add a mapping of logical source line to physical source file and
428
   line number. This function creates an "ordinary map", which is a
429
   map that records locations of tokens that are not part of macro
430
   replacement-lists present at a macro expansion point.
431
 
432
   The text pointed to by TO_FILE must have a lifetime
433
   at least as long as the lifetime of SET.  An empty
434
   TO_FILE means standard input.  If reason is LC_LEAVE, and
435
   TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their
436
   natural values considering the file we are returning to.
437
 
438
   A call to this function can relocate the previous set of
439
   maps, so any stored line_map pointers should not be used.  */
440
extern const struct line_map *linemap_add
441
  (struct line_maps *, enum lc_reason, unsigned int sysp,
442
   const char *to_file, linenum_type to_line);
443
 
444
/* Given a logical source location, returns the map which the
445
   corresponding (source file, line, column) triplet can be deduced
446
   from. Since the set is built chronologically, the logical lines are
447
   monotonic increasing, and so the list is sorted and we can use a
448
   binary search. If no line map have been allocated yet, this
449
   function returns NULL.  */
450
extern const struct line_map *linemap_lookup
451
  (struct line_maps *, source_location);
452
 
453
/* Returns TRUE if the line table set tracks token locations accross
454
   macro expansion, FALSE otherwise.  */
455
bool linemap_tracks_macro_expansion_locs_p (struct line_maps *);
456
 
457
/* Return TRUE if MAP encodes locations coming from a macro
458
   replacement-list at macro expansion point.  */
459
bool linemap_macro_expansion_map_p (const struct line_map *);
460
 
461
/* Return the name of the macro associated to MACRO_MAP.  */
462
const char* linemap_map_get_macro_name (const struct line_map*);
463
 
464
/* Return a positive value if LOCATION is the locus of a token that is
465
   located in a system header, O otherwise. It returns 1 if LOCATION
466
   is the locus of a token that is located in a system header, and 2
467
   if LOCATION is the locus of a token located in a C system header
468
   that therefore needs to be extern "C" protected in C++.
469
 
470
   Note that this function returns 1 if LOCATION belongs to a token
471
   that is part of a macro replacement-list defined in a system
472
   header, but expanded in a non-system file.  */
473
int linemap_location_in_system_header_p (struct line_maps *,
474
                                         source_location);
475
 
476
/* Return TRUE if LOCATION is a source code location of a token coming
477
   from a macro replacement-list at a macro expansion point, FALSE
478
   otherwise.  */
479
bool linemap_location_from_macro_expansion_p (struct line_maps *,
480
                                              source_location);
481
 
482
/* source_location values from 0 to RESERVED_LOCATION_COUNT-1 will
483
   be reserved for libcpp user as special values, no token from libcpp
484
   will contain any of those locations.  */
485
#define RESERVED_LOCATION_COUNT 2
486
 
487
/* Converts a map and a source_location to source line.  */
488
#define SOURCE_LINE(MAP, LOC)                                           \
489
  (((((LOC) - linemap_check_ordinary (MAP)->start_location)             \
490
     >> (MAP)->d.ordinary.column_bits) + (MAP)->d.ordinary.to_line))
491
 
492
/* Convert a map and source_location to source column number.  */
493
#define SOURCE_COLUMN(MAP, LOC)                                         \
494
  ((((LOC) - linemap_check_ordinary (MAP)->start_location)              \
495
    & ((1 << (MAP)->d.ordinary.column_bits) - 1)))
496
 
497
/* Returns the last source line number within an ordinary map.  This
498
   is the (last) line of the #include, or other directive, that caused
499
   a map change.  */
500
#define LAST_SOURCE_LINE(MAP) \
501
  SOURCE_LINE (MAP, LAST_SOURCE_LINE_LOCATION (MAP))
502
 
503
/* Return the last column number within an ordinary map.  */
504
#define LAST_SOURCE_COLUMN(MAP) \
505
  SOURCE_COLUMN (MAP, LAST_SOURCE_LINE_LOCATION (MAP))
506
 
507
/* Return the location of the last source line within an ordinary
508
   map.  */
509
#define LAST_SOURCE_LINE_LOCATION(MAP)                                  \
510
  ((((linemap_check_ordinary (MAP)[1].start_location - 1                \
511
      - (MAP)->start_location)                                          \
512
     & ~((1 << (MAP)->d.ordinary.column_bits) - 1))                     \
513
    + (MAP)->start_location))
514
 
515
/* Returns the map a given map was included from, or NULL if the map
516
   belongs to the main file, i.e, a file that wasn't included by
517
   another one.  */
518
#define INCLUDED_FROM(SET, MAP)                                         \
519
  ((linemap_check_ordinary (MAP)->d.ordinary.included_from == -1)       \
520
   ? NULL                                                               \
521
   : (&LINEMAPS_ORDINARY_MAPS (SET)[(MAP)->d.ordinary.included_from]))
522
 
523
/* Nonzero if the map is at the bottom of the include stack.  */
524
#define MAIN_FILE_P(MAP)                                                \
525
  ((linemap_check_ordinary (MAP)->d.ordinary.included_from < 0))
526
 
527
#if defined ENABLE_CHECKING && (GCC_VERSION >= 2007)
528
 
529
/* Assertion macro to be used in line-map code.  */
530
#define linemap_assert(EXPR)                    \
531
  do {                                          \
532
    if (! (EXPR))                               \
533
      abort ();                                 \
534
  } while (0)
535
 
536
/* Assert that MAP encodes locations of tokens that are not part of
537
   the replacement-list of a macro expansion.  */
538
#define linemap_check_ordinary(LINE_MAP) __extension__          \
539
  ({linemap_assert (!linemap_macro_expansion_map_p (LINE_MAP)); \
540
    (LINE_MAP);})
541
#else
542
#define linemap_assert(EXPR)
543
#define linemap_check_ordinary(LINE_MAP) (LINE_MAP)
544
#endif
545
 
546
/* Encode and return a source_location from a column number. The
547
   source line considered is the last source line used to call
548
   linemap_line_start, i.e, the last source line which a location was
549
   encoded from.  */
550
extern source_location
551
linemap_position_for_column (struct line_maps *, unsigned int);
552
 
553
/* Encode and return a source location from a given line and
554
   column.  */
555
source_location linemap_position_for_line_and_column (struct line_map *,
556
                                                      linenum_type,
557
                                                      unsigned int);
558
/* Return the file this map is for.  */
559
#define LINEMAP_FILE(MAP)                                       \
560
  (linemap_check_ordinary (MAP)->d.ordinary.to_file)
561
 
562
/* Return the line number this map started encoding location from.  */
563
#define LINEMAP_LINE(MAP)                                       \
564
  (linemap_check_ordinary (MAP)->d.ordinary.to_line)
565
 
566
/* Return a positive value if map encodes locations from a system
567
   header, 0 otherwise. Returns 1 if MAP encodes locations in a
568
   system header and 2 if it encodes locations in a C system header
569
   that therefore needs to be extern "C" protected in C++.  */
570
#define LINEMAP_SYSP(MAP)                                       \
571
  (linemap_check_ordinary (MAP)->d.ordinary.sysp)
572
 
573
/* Return a positive value if PRE denotes the location of a token that
574
   comes before the token of POST, 0 if PRE denotes the location of
575
   the same token as the token for POST, and a negative value
576
   otherwise.  */
577
int linemap_compare_locations (struct line_maps *set,
578
                               source_location   pre,
579
                               source_location   post);
580
 
581
/* Return TRUE if LOC_A denotes the location a token that comes
582
   topogically before the token denoted by location LOC_B, or if they
583
   are equal.  */
584
#define linemap_location_before_p(SET, LOC_A, LOC_B)    \
585
  (linemap_compare_locations ((SET), (LOC_A), (LOC_B)) >= 0)
586
 
587
typedef struct
588
{
589
  /* The name of the source file involved.  */
590
  const char *file;
591
 
592
  /* The line-location in the source file.  */
593
  int line;
594
 
595
  int column;
596
 
597
  /* In a system header?. */
598
  bool sysp;
599
} expanded_location;
600
 
601
/* This is enum is used by the function linemap_resolve_location
602
   below.  The meaning of the values is explained in the comment of
603
   that function.  */
604
enum location_resolution_kind
605
{
606
  LRK_MACRO_EXPANSION_POINT,
607
  LRK_SPELLING_LOCATION,
608
  LRK_MACRO_DEFINITION_LOCATION
609
};
610
 
611
/* Resolve a virtual location into either a spelling location, an
612
   expansion point location or a token argument replacement point
613
   location.  Return the map that encodes the virtual location as well
614
   as the resolved location.
615
 
616
   If LOC is *NOT* the location of a token resulting from the
617
   expansion of a macro, then the parameter LRK (which stands for
618
   Location Resolution Kind) is ignored and the resulting location
619
   just equals the one given in argument.
620
 
621
   Now if LOC *IS* the location of a token resulting from the
622
   expansion of a macro, this is what happens.
623
 
624
   * If LRK is set to LRK_MACRO_EXPANSION_POINT
625
   -------------------------------
626
 
627
   The virtual location is resolved to the first macro expansion point
628
   that led to this macro expansion.
629
 
630
   * If LRK is set to LRK_SPELLING_LOCATION
631
   -------------------------------------
632
 
633
   The virtual location is resolved to the locus where the token has
634
   been spelled in the source.   This can follow through all the macro
635
   expansions that led to the token.
636
 
637
   * If LRK is set to LRK_MACRO_DEFINITION_LOCATION
638
   --------------------------------------
639
 
640
   The virtual location is resolved to the locus of the token in the
641
   context of the macro definition.
642
 
643
   If LOC is the locus of a token that is an argument of a
644
   function-like macro [replacing a parameter in the replacement list
645
   of the macro] the virtual location is resolved to the locus of the
646
   parameter that is replaced, in the context of the definition of the
647
   macro.
648
 
649
   If LOC is the locus of a token that is not an argument of a
650
   function-like macro, then the function behaves as if LRK was set to
651
   LRK_SPELLING_LOCATION.
652
 
653
   If LOC_MAP is not NULL, *LOC_MAP is set to the map encoding the
654
   returned location.  Note that if the resturned location wasn't originally
655
   encoded by a map, the *MAP is set to NULL.  This can happen if LOC
656
   resolves to a location reserved for the client code, like
657
   UNKNOWN_LOCATION or BUILTINS_LOCATION in GCC.  */
658
 
659
source_location linemap_resolve_location (struct line_maps *,
660
                                          source_location loc,
661
                                          enum location_resolution_kind lrk,
662
                                          const struct line_map **loc_map);
663
 
664
/* Suppose that LOC is the virtual location of a token coming from the
665
   expansion of a macro M.  This function then steps up to get the
666
   location L of the point where M got expanded.  If L is a spelling
667
   location inside a macro expansion M', then this function returns
668
   the point where M' was expanded.  LOC_MAP is an output parameter.
669
   When non-NULL, *LOC_MAP is set the the map of the returned
670
   location.  */
671
source_location linemap_unwind_toward_expansion (struct line_maps *,
672
                                                 source_location loc,
673
                                                 const struct line_map **loc_map);
674
 
675
/* Expand source code location LOC and return a user readable source
676
   code location.  LOC must be a spelling (non-virtual) location.  If
677
   it's a location < RESERVED_LOCATION_COUNT a zeroed expanded source
678
   location is returned.  */
679
expanded_location linemap_expand_location (struct line_maps *,
680
                                           const struct line_map *,
681
                                           source_location loc);
682
 
683
/* Statistics about maps allocation and usage as returned by
684
   linemap_get_statistics.  */
685
struct linemap_stats
686
{
687
  long num_ordinary_maps_allocated;
688
  long num_ordinary_maps_used;
689
  long ordinary_maps_allocated_size;
690
  long ordinary_maps_used_size;
691
  long num_expanded_macros;
692
  long num_macro_tokens;
693
  long num_macro_maps_used;
694
  long macro_maps_allocated_size;
695
  long macro_maps_used_size;
696
  long macro_maps_locations_size;
697
  long duplicated_macro_maps_locations_size;
698
};
699
 
700
/* Compute and return statistics about the memory consumption of some
701
   parts of the line table SET.  */
702
void linemap_get_statistics (struct line_maps *, struct linemap_stats *);
703
 
704
/* Dump debugging information about source location LOC into the file
705
   stream STREAM. SET is the line map set LOC comes from.  */
706
void linemap_dump_location (struct line_maps *, source_location, FILE *);
707
 
708
/* Dump line map at index IX in line table SET to STREAM.  If STREAM
709
   is NULL, use stderr.  IS_MACRO is true if the caller wants to
710
   dump a macro map, false otherwise.  */
711
void linemap_dump (FILE *, struct line_maps *, unsigned, bool);
712
 
713
/* Dump line table SET to STREAM.  If STREAM is NULL, stderr is used.
714
   NUM_ORDINARY specifies how many ordinary maps to dump.  NUM_MACRO
715
   specifies how many macro maps to dump.  */
716
void line_table_dump (FILE *, struct line_maps *, unsigned int, unsigned int);
717
 
718
#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.