View | Details | Raw Unified | Return to bug 7263 | Differences between
and this patch

Collapse All | Expand All

(-)a/gcc/ChangeLog (+22 lines)
Lines 1-3 Link Here
1
2010-05-18  Dodji Seketeli  <dodji@redhat.com>
2
3
	* c-decl.c (declspecs_add_type): Use in_system_header_at instead
4
	of in_system_header.
5
	* c.opt: Add -fdebug_cpp command line option.
6
	* c-opts.c (c_common_handle_option): Handle OPT_fdebug_cpp.
7
	* c-ppoutput.c (print_line_1): Factor out of print_line.
8
	(maybe_print_line_1): Factor out of maybe_print_line.
9
	(scan_translation_unit): Use linemap_get_source_line instead of
10
	SOURCE_LINE. If -E and -fdebug_cpp is active, dump locations debugging
11
	info for each token emitted.
12
	(cb_define): Use linemap_macro_exp_loc_to_exp_point.
13
	* diagnostic.c (diagnostic_report_current_module): Avoid a
14
	compiler warning. Use linemap_macro_expansion_map_p,
15
	linemap_macro_map_loc_to_def_point instead of libcpp internals
16
	directly.
17
	* input.h (LOCATION_FILE, LOCATION_LINE): Use
18
	linemap_get_file_path and linemap_get_source_line.
19
	(in_system_header_at, in_system_header): Use
20
	linemap_location_in_system_header_p.
21
22
1
2010-04-12  Eric Botcazou  <ebotcazou@adacore.com>
23
2010-04-12  Eric Botcazou  <ebotcazou@adacore.com>
2
24
3
	* expr.c (categorize_ctor_elements_1): Properly count sub-elements of
25
	* expr.c (categorize_ctor_elements_1): Properly count sub-elements of
(-)a/gcc/c-decl.c (-1 / +1 lines)
Lines 8722-8728 declspecs_add_type (location_t loc, struct c_declspecs *specs, Link Here
8722
	      break;
8722
	      break;
8723
	    case RID_COMPLEX:
8723
	    case RID_COMPLEX:
8724
	      dupe = specs->complex_p;
8724
	      dupe = specs->complex_p;
8725
	      if (!flag_isoc99 && !in_system_header)
8725
	      if (!flag_isoc99 && !in_system_header_at (loc))
8726
		pedwarn (loc, OPT_pedantic,
8726
		pedwarn (loc, OPT_pedantic,
8727
			 "ISO C90 does not support complex types");
8727
			 "ISO C90 does not support complex types");
8728
	      if (specs->typespec_word == cts_void)
8728
	      if (specs->typespec_word == cts_void)
(-)a/gcc/c-opts.c (+4 lines)
Lines 847-852 c_common_handle_option (size_t scode, const char *arg, int value) Link Here
847
      cpp_opts->preprocessed = value;
847
      cpp_opts->preprocessed = value;
848
      break;
848
      break;
849
849
850
    case OPT_fdebug_cpp:
851
      cpp_opts->debug = 1;
852
      break;
853
850
    case OPT_freplace_objc_classes:
854
    case OPT_freplace_objc_classes:
851
      flag_replace_objc_classes = value;
855
      flag_replace_objc_classes = value;
852
      break;
856
      break;
(-)a/gcc/c-ppoutput.c (-30 / +60 lines)
Lines 59-65 static void account_for_newlines (const unsigned char *, size_t); Link Here
59
static int dump_macro (cpp_reader *, cpp_hashnode *, void *);
59
static int dump_macro (cpp_reader *, cpp_hashnode *, void *);
60
static void dump_queued_macros (cpp_reader *);
60
static void dump_queued_macros (cpp_reader *);
61
61
62
static void print_line_1 (source_location, const char*, FILE *);
62
static void print_line (source_location, const char *);
63
static void print_line (source_location, const char *);
64
static void maybe_print_line_1 (source_location, FILE *);
63
static void maybe_print_line (source_location);
65
static void maybe_print_line (source_location);
64
static void do_line_change (cpp_reader *, const cpp_token *,
66
static void do_line_change (cpp_reader *, const cpp_token *,
65
			    source_location, int);
67
			    source_location, int);
Lines 190-198 scan_translation_unit (cpp_reader *pfile) Link Here
190
      /* Subtle logic to output a space if and only if necessary.  */
192
      /* Subtle logic to output a space if and only if necessary.  */
191
      if (avoid_paste)
193
      if (avoid_paste)
192
	{
194
	{
193
	  const struct line_map *map
195
	  int src_line = linemap_get_source_line (line_table, loc);
194
	    = linemap_lookup (line_table, loc);
195
	  int src_line = SOURCE_LINE (map, loc);
196
196
197
	  if (print.source == NULL)
197
	  if (print.source == NULL)
198
	    print.source = token;
198
	    print.source = token;
Lines 212-220 scan_translation_unit (cpp_reader *pfile) Link Here
212
	}
212
	}
213
      else if (token->flags & PREV_WHITE)
213
      else if (token->flags & PREV_WHITE)
214
	{
214
	{
215
	  const struct line_map *map
215
	  int src_line = linemap_get_source_line (line_table, loc);
216
	    = linemap_lookup (line_table, loc);
217
	  int src_line = SOURCE_LINE (map, loc);
218
216
219
	  if (src_line != print.src_line
217
	  if (src_line != print.src_line
220
	      && do_line_adjustments
218
	      && do_line_adjustments
Lines 247-253 scan_translation_unit (cpp_reader *pfile) Link Here
247
	  in_pragma = false;
245
	  in_pragma = false;
248
	}
246
	}
249
      else
247
      else
250
	cpp_output_token (token, print.outf);
248
	{
249
	  if (cpp_get_options (parse_in)->debug)
250
	      linemap_dump_location (line_table, token->src_loc,
251
				     print.outf);
252
	  cpp_output_token (token, print.outf);
253
	}
251
254
252
      if (token->type == CPP_COMMENT)
255
      if (token->type == CPP_COMMENT)
253
	account_for_newlines (token->val.str.text, token->val.str.len);
256
	account_for_newlines (token->val.str.text, token->val.str.len);
Lines 301-315 scan_translation_unit_trad (cpp_reader *pfile) Link Here
301
/* If the token read on logical line LINE needs to be output on a
304
/* If the token read on logical line LINE needs to be output on a
302
   different line to the current one, output the required newlines or
305
   different line to the current one, output the required newlines or
303
   a line marker, and return 1.  Otherwise return 0.  */
306
   a line marker, and return 1.  Otherwise return 0.  */
307
304
static void
308
static void
305
maybe_print_line (source_location src_loc)
309
maybe_print_line_1 (source_location src_loc, FILE *stream)
306
{
310
{
307
  const struct line_map *map = linemap_lookup (line_table, src_loc);
311
  int src_line = linemap_get_source_line (line_table, src_loc);
308
  int src_line = SOURCE_LINE (map, src_loc);
309
  /* End the previous line of text.  */
312
  /* End the previous line of text.  */
310
  if (print.printed)
313
  if (print.printed)
311
    {
314
    {
312
      putc ('\n', print.outf);
315
      putc ('\n', stream);
313
      print.src_line++;
316
      print.src_line++;
314
      print.printed = 0;
317
      print.printed = 0;
315
    }
318
    }
Lines 318-371 maybe_print_line (source_location src_loc) Link Here
318
    {
321
    {
319
      while (src_line > print.src_line)
322
      while (src_line > print.src_line)
320
	{
323
	{
321
	  putc ('\n', print.outf);
324
	  putc ('\n', stream);
322
	  print.src_line++;
325
	  print.src_line++;
323
	}
326
	}
324
    }
327
    }
325
  else
328
  else
326
    print_line (src_loc, "");
329
    print_line_1 (src_loc, "", stream);
330
331
}
332
333
/* If the token read on logical line LINE needs to be output on a
334
   different line to the current one, output the required newlines or
335
   a line marker, and return 1.  Otherwise return 0.  */
336
337
static void
338
maybe_print_line (source_location src_loc)
339
{
340
  if (cpp_get_options (parse_in)->debug)
341
    linemap_dump_location (line_table, src_loc,
342
			   print.outf);
343
  maybe_print_line_1 (src_loc, print.outf);
327
}
344
}
328
345
329
/* Output a line marker for logical line LINE.  Special flags are "1"
346
/* Output a line marker for logical line LINE.  Special flags are "1"
330
   or "2" indicating entering or leaving a file.  */
347
   or "2" indicating entering or leaving a file.  */
348
331
static void
349
static void
332
print_line (source_location src_loc, const char *special_flags)
350
print_line_1 (source_location src_loc, const char *special_flags, FILE *stream)
333
{
351
{
334
  /* End any previous line of text.  */
352
  /* End any previous line of text.  */
335
  if (print.printed)
353
  if (print.printed)
336
    putc ('\n', print.outf);
354
    putc ('\n', stream);
337
  print.printed = 0;
355
  print.printed = 0;
338
356
339
  if (!flag_no_line_commands)
357
  if (!flag_no_line_commands)
340
    {
358
    {
341
      const struct line_map *map = linemap_lookup (line_table, src_loc);
359
      const char *file_path = linemap_get_file_path (line_table, src_loc);
342
360
      int sysp;
343
      size_t to_file_len = strlen (LINEMAP_FILE (map));
361
      size_t to_file_len = strlen (file_path);
344
      unsigned char *to_file_quoted =
362
      unsigned char *to_file_quoted =
345
         (unsigned char *) alloca (to_file_len * 4 + 1);
363
         (unsigned char *) alloca (to_file_len * 4 + 1);
346
      unsigned char *p;
364
      unsigned char *p;
347
365
348
      print.src_line = SOURCE_LINE (map, src_loc);
366
      print.src_line = linemap_get_source_line (line_table, src_loc);
349
367
350
      /* cpp_quote_string does not nul-terminate, so we have to do it
368
      /* cpp_quote_string does not nul-terminate, so we have to do it
351
	 ourselves.  */
369
	 ourselves.  */
352
      p = cpp_quote_string (to_file_quoted,
370
      p = cpp_quote_string (to_file_quoted,
353
			    (const unsigned char *) LINEMAP_FILE (map),
371
			    (const unsigned char *) file_path,
354
			    to_file_len);
372
			    to_file_len);
355
      *p = '\0';
373
      *p = '\0';
356
      fprintf (print.outf, "# %u \"%s\"%s",
374
      fprintf (stream, "# %u \"%s\"%s",
357
	       print.src_line == 0 ? 1 : print.src_line,
375
	       print.src_line == 0 ? 1 : print.src_line,
358
	       to_file_quoted, special_flags);
376
	       to_file_quoted, special_flags);
359
377
360
      if (LINEMAP_SYSP (map) == 2)
378
      sysp = linemap_location_in_system_header_p (line_table, src_loc);
361
	fputs (" 3 4", print.outf);
379
      if (sysp == 2)
362
      else if (LINEMAP_SYSP (map) == 1)
380
	fputs (" 3 4", stream);
363
	fputs (" 3", print.outf);
381
      else if (sysp == 1)
382
	fputs (" 3", stream);
364
383
365
      putc ('\n', print.outf);
384
      putc ('\n', stream);
366
    }
385
    }
367
}
386
}
368
387
388
/* Output a line marker for logical line LINE.  Special flags are "1"
389
   or "2" indicating entering or leaving a file.  */
390
391
static void
392
print_line (source_location src_loc, const char *special_flags)
393
{
394
    if (cpp_get_options (parse_in)->debug)
395
      linemap_dump_location (line_table, src_loc,
396
			     print.outf);
397
    print_line_1 (src_loc, special_flags, print.outf);
398
}
399
369
/* Helper function for cb_line_change and scan_translation_unit.  */
400
/* Helper function for cb_line_change and scan_translation_unit.  */
370
static void
401
static void
371
do_line_change (cpp_reader *pfile, const cpp_token *token,
402
do_line_change (cpp_reader *pfile, const cpp_token *token,
Lines 388-395 do_line_change (cpp_reader *pfile, const cpp_token *token, Link Here
388
     ought to care.  Some things do care; the fault lies with them.  */
419
     ought to care.  Some things do care; the fault lies with them.  */
389
  if (!CPP_OPTION (pfile, traditional))
420
  if (!CPP_OPTION (pfile, traditional))
390
    {
421
    {
391
      const struct line_map *map = linemap_lookup (line_table, src_loc);
422
      int spaces = linemap_get_source_column (line_table, src_loc) - 2;
392
      int spaces = SOURCE_COLUMN (map, src_loc) - 2;
393
      print.printed = 1;
423
      print.printed = 1;
394
424
395
      while (-- spaces >= 0)
425
      while (-- spaces >= 0)
Lines 418-424 cb_ident (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line, Link Here
418
static void
448
static void
419
cb_define (cpp_reader *pfile, source_location line, cpp_hashnode *node)
449
cb_define (cpp_reader *pfile, source_location line, cpp_hashnode *node)
420
{
450
{
421
  const struct line_map *map;
451
   struct line_map *map;
422
452
423
  if (line <= BUILTINS_LOCATION)
453
  if (line <= BUILTINS_LOCATION)
424
    return;
454
    return;
Lines 433-439 cb_define (cpp_reader *pfile, source_location line, cpp_hashnode *node) Link Here
433
    fputs ((const char *) NODE_NAME (node), print.outf);
463
    fputs ((const char *) NODE_NAME (node), print.outf);
434
464
435
  putc ('\n', print.outf);
465
  putc ('\n', print.outf);
436
  map = linemap_lookup (line_table, line);
466
  linemap_macro_exp_loc_to_exp_point (line_table, line, &map);
437
  if (LINEMAP_LINE (map) != 0)
467
  if (LINEMAP_LINE (map) != 0)
438
    print.src_line++;
468
    print.src_line++;
439
}
469
}
(-)a/gcc/c.opt (+4 lines)
Lines 740-745 fpreprocessed Link Here
740
C ObjC C++ ObjC++
740
C ObjC C++ ObjC++
741
Treat the input file as already preprocessed
741
Treat the input file as already preprocessed
742
742
743
fdebug-cpp
744
C ObjC C++ ObjC++
745
Emit debug annotations during preprocessing
746
743
fpretty-templates
747
fpretty-templates
744
C++ ObjC++
748
C++ ObjC++
745
-fno-pretty-templates Do not pretty-print template specializations as the template signature followed by the arguments
749
-fno-pretty-templates Do not pretty-print template specializations as the template signature followed by the arguments
(-)a/gcc/diagnostic.c (-5 / +4 lines)
Lines 260-273 diagnostic_report_current_module (diagnostic_context *context, location_t where) Link Here
260
  map = linemap_lookup (line_table, where);
260
  map = linemap_lookup (line_table, where);
261
  if (map && diagnostic_last_module_changed (context, map))
261
  if (map && diagnostic_last_module_changed (context, map))
262
    {
262
    {
263
      struct line_map *macro_map;
263
      const struct line_map *macro_map;
264
264
265
      diagnostic_set_last_module (context, map);
265
      diagnostic_set_last_module (context, map);
266
      for (macro_map = map; macro_map->reason == LC_ENTER_MACRO; )
266
      for (macro_map = map; linemap_macro_expansion_map_p (macro_map); )
267
 	{
267
 	{
268
 	  expanded_location loc;
268
 	  expanded_location loc;
269
 	  source_location l2 = where - macro_map->start_location;
269
	  where = linemap_macro_map_loc_to_def_point (macro_map, where);
270
 	  where = macro_map->d.macro.macro_locations[2 * l2 + 1];
271
 	  loc = expand_location (where);
270
 	  loc = expand_location (where);
272
 	  pp_verbatim (context->printer,
271
 	  pp_verbatim (context->printer,
273
 		       "While expanding macro %s at %s:%d:%d",
272
 		       "While expanding macro %s at %s:%d:%d",
Lines 277-283 diagnostic_report_current_module (diagnostic_context *context, location_t where) Link Here
277
 	  macro_map = linemap_lookup (line_table, where);
276
 	  macro_map = linemap_lookup (line_table, where);
278
 	}
277
 	}
279
278
280
      while (map->reason == LC_ENTER_MACRO)
279
      while (linemap_macro_expansion_map_p (map))
281
 	map = linemap_lookup (line_table, map->d.macro.expansion);
280
 	map = linemap_lookup (line_table, map->d.macro.expansion);
282
281
283
      if (! MAIN_FILE_P (map))
282
      if (! MAIN_FILE_P (map))
(-)a/gcc/input.h (-4 / +5 lines)
Lines 48-60 extern const char *main_input_filename; Link Here
48
48
49
extern location_t input_location;
49
extern location_t input_location;
50
50
51
#define LOCATION_FILE(LOC) ((expand_location (LOC)).file)
51
#define LOCATION_FILE(LOC) (linemap_get_file_path (line_table, LOC))
52
#define LOCATION_LINE(LOC) ((expand_location (LOC)).line)
52
#define LOCATION_LINE(LOC) (linemap_get_source_line (line_table, LOC))
53
53
54
#define input_line LOCATION_LINE (input_location)
54
#define input_line LOCATION_LINE (input_location)
55
#define input_filename LOCATION_FILE (input_location)
55
#define input_filename LOCATION_FILE (input_location)
56
#define in_system_header_at(LOC) ((expand_location (LOC)).sysp != 0)
56
#define in_system_header_at(LOC) \
57
#define in_system_header (in_system_header_at (input_location))
57
  ((linemap_location_in_system_header_p (line_table, LOC)))
58
#define in_system_header  (in_system_header_at (input_location))
58
#define expand_location(LOC) linemap_expand_location (line_table, LOC)
59
#define expand_location(LOC) linemap_expand_location (line_table, LOC)
59
60
60
#endif
61
#endif
(-)a/libcpp/ChangeLog (+51 lines)
Lines 1-3 Link Here
1
2010-05-17  Dodji Seketeli  <dodji@redhat.com>
2
3
	* include/cpplib.h (struct cpp_options) <debug>: Declare new debug
4
	flag.
5
	* include/line-map.h (struct line_map) <index>: New member.
6
	(linemap_enter_macro): The macro parm has type struct cpp_macro*,
7
	not void.
8
	(linemap_macro_exp_loc_to_exp_point): Declare new public fns.
9
	(linemap_macro_exp_loc_to_def_point): Likewise.
10
	(linemap_macro_map_loc_to_def_point): Likewise.
11
	(linemap_macro_map_loc_to_exp_point): Likewise.
12
	(linemap_get_source_line, linemap_get_source_column): Likewise.
13
	(linemap_macro_expansion_map_p, linemap_get_file_path): Likewise
14
	(linemap_location_from_macro_expansion_p): Likewise.
15
	(linemap_location_in_system_header_p, linemap_dump_location):
16
	Likewise.
17
	(linemap_location_in_system_header_p): Return bool rather than int.
18
	* line-map.c (linemap_init): Initialize the new members
19
	maps_stack, maps_stack_allocated and maps_stack_used of struct
20
	line_maps.
21
	(new_linemap): Add comments. Initialize the index member of struct
22
	line_map.
23
	(linemap_macro_exp_loc_to_exp_point): Define new public fns.
24
	(linemap_macro_exp_loc_to_def_point): Likewise.
25
	(linemap_macro_map_loc_to_def_point): Likewise.
26
	(linemap_macro_map_loc_to_exp_point): Likewise.
27
	(linemap_get_source_line, linemap_get_source_column): Likewise.
28
	(linemap_macro_expansion_map_p, linemap_get_file_path): Likewise
29
	(linemap_location_from_macro_expansion_p): Likewise.
30
	(linemap_location_in_system_header_p, linemap_dump_location):
31
	Likewise.
32
	(linemap_location_in_system_header_p): Return bool rather than int.
33
	(do_add): Added comments. Renamed variable FROM into
34
	PREV_MAP_SAME_FILE. Do not create a map when we are sure we must
35
	return NULL. Fix dangling pointer use around line map
36
	creation. When reason == LC_LEAVE, reuse PREV_MAP_SAME_FILE value
37
	instead of recomputing it.
38
	(linemap_add): Add comments.
39
	(linemap_add_macro_token): Use new linemap_macro_expansion_map_p,
40
	linemap_macro_exp_loc_to_exp_point.
41
	(linemap_position_for_column): Use new linemap_macro_expansion_map_p.
42
	(linemap_enter_macro): Kill a compilation warning. Add comments.
43
	(find_macro_base): Remove.
44
	(linemap_leave_macro): Add comments. Renamed variables base and
45
	paren into previous and expansion_point. Use
46
	linemap_macro_exp_loc_to_exp_point instead of find_macro_base.
47
	(linemap_expand_location): Use linemap_macro_exp_loc_to_exp_point.
48
	(linemap_check_ordinary): Use linemap_macro_expansion_map_p.
49
	* macro.c (_cpp_builtin_macro_text): Use linemap_get_source_line
50
	instead of SOURCE_LINE.
51
1
2010-04-09  Manuel López-Ibáñez <manu@gcc.gnu.org>
52
2010-04-09  Manuel López-Ibáñez <manu@gcc.gnu.org>
2
53
3
	PR cpp/43195
54
	PR cpp/43195
(-)a/libcpp/include/cpplib.h (+4 lines)
Lines 387-392 struct cpp_options Link Here
387
  /* Nonzero means we're looking at already preprocessed code, so don't
387
  /* Nonzero means we're looking at already preprocessed code, so don't
388
     bother trying to do macro expansion and whatnot.  */
388
     bother trying to do macro expansion and whatnot.  */
389
  unsigned char preprocessed;
389
  unsigned char preprocessed;
390
  
391
  /* Nonzero means we are going to emit debugging logs during
392
     preprocessing.  */
393
  unsigned char debug;
390
394
391
  /* Print column number in error messages.  */
395
  /* Print column number in error messages.  */
392
  unsigned char show_column;
396
  unsigned char show_column;
(-)a/libcpp/include/line-map.h (-1 / +50 lines)
Lines 101-106 struct GTY(()) line_map_macro Link Here
101
struct GTY(()) line_map {
101
struct GTY(()) line_map {
102
  source_location start_location;
102
  source_location start_location;
103
103
104
  /* The index of this map into its set.  */
105
  int index;
106
104
  /* The reason for creation of this line map.  */
107
  /* The reason for creation of this line map.  */
105
  ENUM_BITFIELD (lc_reason) reason : CHAR_BIT;
108
  ENUM_BITFIELD (lc_reason) reason : CHAR_BIT;
106
109
Lines 112-119 struct GTY(()) line_map { Link Here
112
115
113
/* A set of chronological line_map structures.  */
116
/* A set of chronological line_map structures.  */
114
struct GTY(()) line_maps {
117
struct GTY(()) line_maps {
118
  /* This array contains the different line maps.
119
     A line map is created for the following events:
120
       - when a new preprocessing unit start. 
121
       - when a preprocessing unit ends.
122
       - when a macro expansion occurs
123
  */
115
  struct line_map * GTY ((length ("%h.used"))) maps;
124
  struct line_map * GTY ((length ("%h.used"))) maps;
125
126
  /* The allocated size of maps.  */
116
  unsigned int allocated;
127
  unsigned int allocated;
128
129
  /* The number of elements used in maps. This number is smaller
130
     or equal to allocated.  */
117
  unsigned int used;
131
  unsigned int used;
118
132
119
  unsigned int cache;
133
  unsigned int cache;
Lines 174-180 extern const struct line_map *linemap_add Link Here
174
   const char *to_file, linenum_type to_line);
188
   const char *to_file, linenum_type to_line);
175
189
176
extern const struct line_map *linemap_enter_macro (struct line_maps *,
190
extern const struct line_map *linemap_enter_macro (struct line_maps *,
177
						   void *, source_location,
191
						   struct cpp_macro*,
192
						   source_location,
178
						   unsigned int);
193
						   unsigned int);
179
194
180
extern source_location linemap_add_macro_token (const struct line_map *,
195
extern source_location linemap_add_macro_token (const struct line_map *,
Lines 191-196 extern const struct line_map *linemap_lookup Link Here
191
206
192
extern int linemap_check_ordinary (const struct line_map *);
207
extern int linemap_check_ordinary (const struct line_map *);
193
208
209
extern bool linemap_macro_expansion_map_p (const struct line_map *);
210
211
extern source_location linemap_macro_exp_loc_to_exp_point (struct line_maps *,
212
							   source_location,
213
							   struct line_map **);
214
215
extern source_location linemap_macro_exp_loc_to_def_point (struct line_maps *,
216
							   source_location,
217
							   struct line_map **);
218
219
extern source_location linemap_macro_map_loc_to_def_point (const struct line_map*,
220
							   source_location);
221
222
extern source_location linemap_macro_map_loc_to_exp_point (const struct line_map*,
223
							   source_location);
224
225
extern int linemap_get_source_line (struct line_maps *,
226
				    source_location);
227
228
extern int linemap_get_source_column (struct line_maps *,
229
				      source_location);
230
231
extern const char* linemap_get_file_path (struct line_maps *,
232
					  source_location);
233
234
extern bool linemap_location_in_system_header_p (struct line_maps *,
235
						 source_location);
236
237
extern bool linemap_location_from_macro_expansion_p (struct line_maps *,
238
						     source_location);
239
194
/* source_location values from 0 to RESERVED_LOCATION_COUNT-1 will
240
/* source_location values from 0 to RESERVED_LOCATION_COUNT-1 will
195
   be reserved for libcpp user as special values, no token from libcpp
241
   be reserved for libcpp user as special values, no token from libcpp
196
   will contain any of those locations.  */
242
   will contain any of those locations.  */
Lines 278-282 typedef struct GTY (()) Link Here
278
324
279
extern expanded_location linemap_expand_location (struct line_maps *,
325
extern expanded_location linemap_expand_location (struct line_maps *,
280
						  source_location);
326
						  source_location);
327
extern void linemap_dump_location (struct line_maps *,
328
				   source_location,
329
				   FILE *stream);
281
330
282
#endif /* !LIBCPP_LINE_MAP_H  */
331
#endif /* !LIBCPP_LINE_MAP_H  */
(-)a/libcpp/line-map.c (-78 / +406 lines)
Lines 76-84 linemap_free (struct line_maps *set) Link Here
76
    }
76
    }
77
}
77
}
78
78
79
/* Create a new line map in the line map set SET, and return it.  */
80
79
static struct line_map *
81
static struct line_map *
80
new_linemap (struct line_maps *set)
82
new_linemap (struct line_maps *set)
81
{
83
{
84
  struct line_map *result;
85
82
  if (set->used == set->allocated)
86
  if (set->used == set->allocated)
83
    {
87
    {
84
      line_map_realloc reallocator
88
      line_map_realloc reallocator
Lines 92-112 new_linemap (struct line_maps *set) Link Here
92
					 * sizeof (struct line_map)));
96
					 * sizeof (struct line_map)));
93
    }
97
    }
94
98
95
  return &set->maps[set->used++];
99
  result = &set->maps[set->used];
100
  result->index = set->used;
101
  set->used++;
102
  return result;
96
}
103
}
97
104
105
/* Create a line map -- a mapping between a logical source location
106
   and physical source file and line number.
107
108
   SET is the set of line maps the new map will belong to.  The text
109
   pointed to by TO_FILE must have a lifetime at least as long as the
110
   lifetime of SET.  An empty TO_FILE means standard input.  If reason
111
   is LC_LEAVE, and TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP
112
   are given their natural values considering the file we are
113
   returning to.
114
115
   A call to this function can relocate the previous set of
116
   maps, so any stored line_map pointers should not be used.
117
118
   This function is a subroutine of linemap_add and
119
   linemap_enter_macro.  */
120
98
static const struct line_map *
121
static const struct line_map *
99
do_add (struct line_maps *set, enum lc_reason reason,
122
do_add (struct line_maps *set, enum lc_reason reason,
100
	unsigned int sysp, const char *to_file, linenum_type to_line,
123
	unsigned int sysp, const char *to_file, linenum_type to_line,
101
	const struct line_map *previous)
124
	const struct line_map *previous)
102
{
125
{
103
  struct line_map *map;
126
  struct line_map *map = NULL;
127
  /* When we are just leaving an "included" file, and jump to the next
128
     location inside the "includer" right after the #include
129
     "included", this variable points the map in use right before the
130
     #include "included", inside the same "includer" file.
131
  */
132
  struct line_map *prev_map_same_file = NULL;
104
  source_location start_location = set->highest_location + 1;
133
  source_location start_location = set->highest_location + 1;
105
134
  int previous_index = -1;
106
  if (set->used && start_location < set->maps[set->used - 1].start_location)
135
107
    abort ();
136
  linemap_assert (!(set->used
108
137
		    && start_location < set->maps[set->used - 1].start_location));
138
139
  /* If we are leaving the main file, return a NULL map.  */
140
  if (reason == LC_LEAVE
141
      && MAIN_FILE_P (&set->maps[set->used - 1])
142
      && to_file == NULL)
143
    return NULL;
144
145
  /*
146
     *Kludge* ahead. new_linemap uses ggc_realloc to enlarge
147
     line_maps::maps. ggc_realloc frees the previous storage of
148
     line_maps::maps. So struct line_map* pointers that where pointing
149
     into line_maps::maps prior to new_linemap can become dangling
150
     after new_linemap. previous is such a pointer that can become
151
     dangling after new_linemap. Let's make sure we make it point into
152
     the newly allocated line_maps::maps.
153
  */
154
  if (previous)
155
    previous_index = previous->index;
109
  map = new_linemap (set);
156
  map = new_linemap (set);
157
  if (previous_index > -1)
158
    previous = &set->maps[previous_index];
110
159
111
  if (to_file && *to_file == '\0' && reason != LC_RENAME_VERBATIM)
160
  if (to_file && *to_file == '\0' && reason != LC_RENAME_VERBATIM)
112
    to_file = "<stdin>";
161
    to_file = "<stdin>";
Lines 120-145 do_add (struct line_maps *set, enum lc_reason reason, Link Here
120
    reason = LC_ENTER;
169
    reason = LC_ENTER;
121
  else if (reason == LC_LEAVE)
170
  else if (reason == LC_LEAVE)
122
    {
171
    {
123
      struct line_map *from;
124
      bool error;
172
      bool error;
125
173
126
      if (MAIN_FILE_P (map - 1))
174
      if (MAIN_FILE_P (map - 1))
127
	{
175
	{
128
	  if (to_file == NULL)
176
	  /* So this _should_ means we are leaving the main file --
129
	    {
177
	     effectively ending the compilation unit. But to_file not
130
	      set->depth--;
178
	     being NULL means the caller thinks we are leaving to
131
	      set->used--;
179
	     another file. This is an erratic behaviour but we'll try
132
	      return NULL;
180
	     to recover from it. Let's pretend we are not leaving the
133
	    }
181
	     main file.  */
134
	  error = true;
182
	  error = true;
135
          reason = LC_RENAME;
183
	  reason = LC_RENAME;
136
          from = map - 1;
184
	  prev_map_same_file = map - 1;
137
	}
185
	}
138
      else
186
      else
139
	{
187
	{
140
	  from = INCLUDED_FROM (set, map - 1);
188
	  /* (MAP - 1) points to the map we are leaving. The
141
	  linemap_check_ordinary (from);
189
	     map from which (MAP - 1) got included should be the map
142
	  error = to_file && strcmp (from->d.ordinary.to_file, to_file);
190
	     that comes right before MAP in the same file.  */
191
	  prev_map_same_file = INCLUDED_FROM (set, map - 1);
192
	  linemap_check_ordinary (prev_map_same_file);
193
	  error = to_file && strcmp (prev_map_same_file->d.ordinary.to_file,
194
				     to_file);
143
	}
195
	}
144
196
145
      /* Depending upon whether we are handling preprocessed input or
197
      /* Depending upon whether we are handling preprocessed input or
Lines 151-160 do_add (struct line_maps *set, enum lc_reason reason, Link Here
151
      /* A TO_FILE of NULL is special - we use the natural values.  */
203
      /* A TO_FILE of NULL is special - we use the natural values.  */
152
      if (error || to_file == NULL)
204
      if (error || to_file == NULL)
153
	{
205
	{
154
	  linemap_check_ordinary (from);
206
	  linemap_check_ordinary (prev_map_same_file);
155
	  to_file = from->d.ordinary.to_file;
207
	  to_file = prev_map_same_file->d.ordinary.to_file;
156
	  to_line = SOURCE_LINE (from, from[1].start_location);
208
	  to_line = SOURCE_LINE (prev_map_same_file,
157
	  sysp = from->d.ordinary.sysp;
209
				 prev_map_same_file[1].start_location);
210
	  sysp = prev_map_same_file->d.ordinary.sysp;
158
	}
211
	}
159
    }
212
    }
160
213
Lines 187-211 do_add (struct line_maps *set, enum lc_reason reason, Link Here
187
    }
240
    }
188
  else if (reason == LC_LEAVE)
241
  else if (reason == LC_LEAVE)
189
    {
242
    {
243
      linemap_assert (prev_map_same_file != NULL);
190
      set->depth--;
244
      set->depth--;
191
      map->d.ordinary.included_from
245
      map->d.ordinary.included_from =
192
	= INCLUDED_FROM (set, map - 1)->d.ordinary.included_from;
246
		prev_map_same_file->d.ordinary.included_from;
193
    }
247
    }
194
248
195
  return map;
249
  return map;
196
}
250
}
197
251
198
/* Add a mapping of logical source line to physical source file and
252
/* Add a mapping of logical source line to physical source file and
199
   line number.
253
   line number. This function creates an "ordinary map", which is a
254
   map that records locations of tokens that are not part of macro
255
   replacement-lists present at a macro expansion point.
200
256
201
   The text pointed to by TO_FILE must have a lifetime
257
   The text pointed to by TO_FILE must have a lifetime
202
   at least as long as the final call to lookup_line ().  An empty
258
   at least as long as the lifetime of SET.  An empty
203
   TO_FILE means standard input.  If reason is LC_LEAVE, and
259
   TO_FILE means standard input.  If reason is LC_LEAVE, and
204
   TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their
260
   TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their
205
   natural values considering the file we are returning to.
261
   natural values considering the file we are returning to.
206
262
207
   FROM_LINE should be monotonic increasing across calls to this
263
   A call to this function can relocate the previous set of
208
   function.  A call to this function can relocate the previous set of
209
   maps, so any stored line_map pointers should not be used.  */
264
   maps, so any stored line_map pointers should not be used.  */
210
265
211
const struct line_map *
266
const struct line_map *
Lines 215-222 linemap_add (struct line_maps *set, enum lc_reason reason, Link Here
215
  return do_add (set, reason, sysp, to_file, to_line, NULL);
270
  return do_add (set, reason, sysp, to_file, to_line, NULL);
216
}
271
}
217
272
273
/*
274
   Create a macro map. A macro map is a map that encodes source
275
   locations of tokens that are part of a macro replacement-list. This
276
   map shall be created when the macro is expanded. The map encodes
277
   the source location of the expansion point of the macro as well as
278
   the "original" source location of each token that is part of the
279
   macro replacement-list. If a macro is defined by never expanded, it
280
   has no macro map.  SET is the set of maps the macro map should be
281
   part of.  MACRO is the macro which the new macro map should encode
282
   source locations for.  EXPANSION is the location of the expansion
283
   point of MACRO. NUM_TOKENS is the number of tokens that are part
284
   of the replacement-list of MACRO.  */
285
218
const struct line_map *
286
const struct line_map *
219
linemap_enter_macro (struct line_maps *set, void *macro,
287
linemap_enter_macro (struct line_maps *set, struct cpp_macro *macro,
220
		     source_location expansion, unsigned int num_tokens)
288
		     source_location expansion, unsigned int num_tokens)
221
{
289
{
222
  struct line_map *map;
290
  struct line_map *map;
Lines 231-237 linemap_enter_macro (struct line_maps *set, void *macro, Link Here
231
  map->d.macro.macro = macro;
299
  map->d.macro.macro = macro;
232
  map->d.macro.n_tokens = num_tokens;
300
  map->d.macro.n_tokens = num_tokens;
233
  map->d.macro.macro_locations
301
  map->d.macro.macro_locations
234
    = reallocator (NULL, 2 * num_tokens * sizeof (source_location));
302
    = (source_location*) reallocator (NULL,
303
				      2 * num_tokens
304
				      * sizeof (source_location));
235
  map->d.macro.expansion = expansion;
305
  map->d.macro.expansion = expansion;
236
  memset (map->d.macro.macro_locations, 0,
306
  memset (map->d.macro.macro_locations, 0,
237
	  num_tokens * sizeof (source_location));
307
	  num_tokens * sizeof (source_location));
Lines 244-292 linemap_enter_macro (struct line_maps *set, void *macro, Link Here
244
  return map;
314
  return map;
245
}
315
}
246
316
317
/* Create and return a source location for a token that is part of a
318
   macro replacement-list in a macro expansion.
319
320
   A call to this function must come after a call to
321
   linemap_enter_macro.
322
323
   MAP is the map into which the source location is created.  TOKEN_NO
324
   is the index of the token in the macro replacement-list, starting
325
   at number 0.  ORIG is the orginal location of the token at the
326
   definition point of the macro.  OTHER is ???  */
327
247
source_location
328
source_location
248
linemap_add_macro_token (const struct line_map *map,
329
linemap_add_macro_token (const struct line_map *map,
249
			 unsigned int token_no,
330
			 unsigned int token_no,
250
			 source_location orig,
331
			 source_location orig,
251
			 source_location other /* FIXME name */)
332
			 source_location other /* FIXME name */)
252
{
333
{
253
  linemap_assert (map->reason == LC_ENTER_MACRO);
334
  linemap_assert (linemap_macro_expansion_map_p (map));
254
  map->d.macro.macro_locations[2 * token_no] = orig;
335
  map->d.macro.macro_locations[2 * token_no] = orig;
255
  map->d.macro.macro_locations[2 * token_no + 1] = other;
336
  map->d.macro.macro_locations[2 * token_no + 1] = other;
256
  return map->start_location + token_no;
337
  return map->start_location + token_no;
257
}
338
}
258
339
259
static const struct line_map *
340
/* Create an ordinary map coming right after the macro map holding the
260
find_macro_base (struct line_maps *set, source_location loc, int expansion)
341
   locations of the tokens of the macro replacement-list at a macro
261
{
342
   expansion point. The current map must be a macro map.
262
  while (1)
343
   
263
    {
344
   This function must be called right after the series of calls to
264
      const struct line_map *map;
345
   linemap_add_macro_token. It thus ends the creation of locations for
265
      map = linemap_lookup (set, loc);
346
   macro replacement-list tokens at a macro expansion point.
266
      if (map->reason != LC_ENTER_MACRO)
347
267
	return map;
348
   SET is the set of line maps to consider.
268
      if (expansion)
349
   EXPANSION_POINT_LOC is the location of the expansion point.  */
269
	loc = map->d.macro.expansion;
270
      else
271
	loc = map->d.macro.macro_locations[2 * (loc - map->start_location)];
272
    }
273
}
274
350
275
void
351
void
276
linemap_leave_macro (struct line_maps *set, source_location paren_loc)
352
linemap_leave_macro (struct line_maps *set,
353
		     source_location expansion_point_loc)
277
{
354
{
278
  const struct line_map *base, *paren;
355
  /* The ordinary (non-macro) map that comes right before the current
279
356
     macro map.  */
280
  linemap_assert (set->maps[set->used - 1].reason == LC_ENTER_MACRO);
357
  const struct line_map *previous;
281
358
  /* Then map that encodes the expansion point of the current macro.  */
282
/*   base = find_macro_base (set, set->maps[set->used - 1].d.macro.expansion, 1); */
359
  struct line_map *expansion_point;
283
  base = &set->maps[set->used - 2];
360
284
  linemap_assert (base->reason != LC_ENTER_MACRO);
361
  /* The current macro must be a macro map.  */
285
362
  linemap_assert (linemap_macro_expansion_map_p (&set->maps[set->used - 1]));
286
  linemap_assert (base->reason != LC_ENTER_MACRO);
363
287
  paren = find_macro_base (set, paren_loc, 0);
364
  previous = &set->maps[set->used - 2];
288
  do_add (set, LC_RENAME, base->d.ordinary.sysp,
365
  /* The previous map cannot be a macro map.  */
289
	  base->d.ordinary.to_file, SOURCE_LINE (paren, paren_loc), base);
366
  linemap_assert (!linemap_macro_expansion_map_p (previous));
367
368
  expansion_point_loc =
369
    linemap_macro_exp_loc_to_exp_point (set, expansion_point_loc,
370
					&expansion_point);
371
  linemap_assert (!linemap_macro_expansion_map_p (expansion_point));
372
373
  do_add (set, LC_RENAME, previous->d.ordinary.sysp,
374
	  previous->d.ordinary.to_file,
375
	  SOURCE_LINE (expansion_point, expansion_point_loc),
376
	  previous);
290
}
377
}
291
378
292
source_location
379
source_location
Lines 358-364 linemap_position_for_column (struct line_maps *set, unsigned int to_column) Link Here
358
{
445
{
359
  source_location r = set->highest_line;
446
  source_location r = set->highest_line;
360
447
361
  linemap_assert (set->maps[set->used - 1].reason != LC_ENTER_MACRO);
448
  linemap_assert (!linemap_macro_expansion_map_p (&set->maps[set->used - 1]));
362
449
363
  if (to_column >= set->max_column_hint)
450
  if (to_column >= set->max_column_hint)
364
    {
451
    {
Lines 390-395 linemap_lookup (struct line_maps *set, source_location line) Link Here
390
  unsigned int md, mn, mx;
477
  unsigned int md, mn, mx;
391
  const struct line_map *cached;
478
  const struct line_map *cached;
392
479
480
  linemap_assert (set != NULL && set->maps != NULL && line != 0);
481
393
  mn = set->cache;
482
  mn = set->cache;
394
  mx = set->used;
483
  mx = set->used;
395
  
484
  
Lines 419-432 linemap_lookup (struct line_maps *set, source_location line) Link Here
419
  return &set->maps[mn];
508
  return &set->maps[mn];
420
}
509
}
421
510
511
/* Return TRUE if MAP encodes locations coming from a macro
512
   replacement-list at macro expansion point.  */
513
514
bool
515
linemap_macro_expansion_map_p (const struct line_map *map)
516
{
517
  if (!map)
518
    return false;
519
  return (map->reason == LC_ENTER_MACRO);
520
}
521
522
/* Assert that MAP encodes locations of tokens that are not part of the
523
   replacement-list of a macro expansion.  */
524
422
int
525
int
423
linemap_check_ordinary (const struct line_map *map)
526
linemap_check_ordinary (const struct line_map *map)
424
{
527
{
425
  linemap_assert (map->reason != LC_ENTER_MACRO);
528
  linemap_assert (!linemap_macro_expansion_map_p (map));
426
  /* Return any old value.  */
529
  /* Return any old value.  */
427
  return 0;
530
  return 0;
428
}
531
}
429
532
533
/* If LOCATION is the locus of a token in a replacement-list of a
534
   macro expansion return the location of the macro expansion point.  */
535
536
source_location
537
linemap_macro_map_loc_to_exp_point (const struct line_map *map,
538
				    source_location location)
539
{
540
  linemap_assert (linemap_macro_expansion_map_p (map) && location);
541
542
  location = location - map->start_location;
543
  linemap_assert (location < map->d.macro.n_tokens);
544
  return map->d.macro.expansion;
545
}
546
547
/* If LOCATION is the locus of a token in a replacement-list of a
548
   macro expansion return the location of said token in the
549
   definition of the macro.
550
551
   Note that if the token is a builtin the function returns the
552
   location of the expansion point of the macro.  */
553
554
source_location
555
linemap_macro_map_loc_to_def_point (const struct line_map *map,
556
				    source_location location)
557
{
558
  linemap_assert (linemap_macro_expansion_map_p (map) && location);
559
560
  location = location - map->start_location;
561
  linemap_assert (location < map->d.macro.n_tokens);
562
563
  location = map->d.macro.macro_locations[2 * location];
564
565
  if (location >= RESERVED_LOCATION_COUNT)
566
    return location;
567
  else
568
    return map->d.macro.expansion;
569
}
570
571
572
/* If LOCATION is the source location of a token that belongs to a
573
   macro replacement-list -- as part of a macro expansion -- then
574
   return the location of the expansion point of the macro.
575
   Otherwise, return LOCATION.  SET is the set of maps location come
576
   from.  ORIGINAL_MAP is an output parm. If non NULL, the function
577
   sets *ORIGINAL_MAP to the ordinary (non-macro) map LOCATION comes
578
   from.  For instance, if LOCATION comes from a macro map (which
579
   means it is the location of a token that is part of a macro
580
   replacement-list resulting from a macro expansion), *ORIGINAL_MAP
581
   will be set to the map containing the location of the macro
582
   expansion point.  */
583
584
source_location
585
linemap_macro_exp_loc_to_exp_point (struct line_maps *set,
586
				    source_location location,
587
				    struct line_map **original_map)
588
{
589
  struct line_map *map;
590
591
  linemap_assert (set && location);
592
593
  while (true)
594
    {
595
      map = (struct line_map*) linemap_lookup (set, location);
596
      if (!linemap_macro_expansion_map_p (map))
597
	break;
598
      location = linemap_macro_map_loc_to_exp_point (map, location);
599
    }
600
601
  if (original_map)
602
    *original_map = map;
603
  return location;
604
}
605
606
/* If LOCATION is the source location of a token that belongs to a
607
   macro replacement-list -- as part of a macro expansion -- then
608
   return the location of the token at the definition point of the
609
   macro. Otherwise, return LOCATION.  SET is the set of maps location
610
   come from.  ORIGINAL_MAP is an output parm. If non NULL, the
611
   function sets *ORIGINAL_MAP to the ordinary (non-macro) map
612
   LOCATION comes from.  For instance, if LOCATION comes from a macro
613
   map (which means it is the location of a token that is part of a
614
   macro replacement-list resulting from a macro expansion),
615
   *ORIGINAL_MAP will be set to the map containing the location of the
616
   macro definition.  */
617
618
source_location
619
linemap_macro_exp_loc_to_def_point (struct line_maps *set,
620
				    source_location location,
621
				    struct line_map **original_map)
622
{
623
  struct line_map *map;
624
625
  linemap_assert (set && location);
626
627
  while (true)
628
    {
629
      map = (struct line_map*) linemap_lookup (set, location);
630
      if (!linemap_macro_expansion_map_p (map))
631
	break;
632
      location = linemap_macro_map_loc_to_def_point (map, location);
633
    }
634
635
  if (original_map)
636
    *original_map = map;
637
  return location;
638
}
639
640
/* Return the source line number corresponding to source location
641
   LOCATION.  SET is the line map set LOCATION comes from.  */
642
643
int
644
linemap_get_source_line (struct line_maps *set,
645
			 source_location location)
646
{
647
  struct line_map *map = NULL;
648
649
  if (location == 0)
650
    return 0;
651
652
  location =
653
    linemap_macro_exp_loc_to_exp_point (set, location, &map);
654
  linemap_check_ordinary (map);
655
656
  return ((location - map->start_location)
657
	    >> map->d.ordinary.column_bits)
658
	 + map->d.ordinary.to_line;
659
}
660
661
/* Return the column number corresponding to location LOCATION.
662
   SET is the line map set LOCATION comes from.  */
663
664
int
665
linemap_get_source_column (struct line_maps *set,
666
			   source_location location)
667
{
668
  struct line_map *map = NULL;
669
670
  if (location == 0)
671
    return 0;
672
673
  location =
674
    linemap_macro_exp_loc_to_exp_point (set, location, &map);
675
  linemap_check_ordinary (map);
676
677
  return (location - map->start_location)
678
	  & ((1 << map->d.ordinary.column_bits) - 1);
679
}
680
681
/* Return the path of the file corresponding to source code location
682
   LOCATION. SET is the line map set LOCATION comes from.  */
683
684
const char*
685
linemap_get_file_path (struct line_maps *set,
686
		       source_location location)
687
{
688
  struct line_map *map = NULL;
689
690
  if (location == 0)
691
    return NULL;
692
693
  location =
694
    linemap_macro_exp_loc_to_exp_point (set, location, &map);
695
  linemap_check_ordinary (map);
696
  return LINEMAP_FILE (map);
697
}
698
699
/* Return TRUE if source code location LOCATION is located in a system
700
   header, FALSE otherwise.
701
   Note that this function returns TRUE if LOCATION belongs to a
702
   token that is part of a macro replacement-list defined in a system
703
   header, but expanded in an non-system file.  */
704
705
bool
706
linemap_location_in_system_header_p (struct line_maps *set,
707
				     source_location location)
708
{
709
  struct line_map *map = NULL;
710
711
  if (location == 0)
712
    return false;
713
714
  location =
715
    linemap_macro_exp_loc_to_def_point (set, location, &map);
716
  linemap_check_ordinary (map);
717
  return LINEMAP_SYSP (map);
718
}
719
720
/* Return TRUE if LOCATION is a source code location of a token
721
   coming from a macro replacement-list at a macro expansion point,
722
   FALSE otherwise.  */
723
724
bool
725
linemap_location_from_macro_expansion_p (struct line_maps *set,
726
					 source_location location)
727
{
728
  const struct line_map *map;
729
730
  if (location == 0)
731
    return false;
732
733
  map = linemap_lookup (set, location);
734
  return linemap_macro_expansion_map_p (map);
735
}
736
430
/* Print an include trace, for e.g. the -H option of the preprocessor.  */
737
/* Print an include trace, for e.g. the -H option of the preprocessor.  */
431
738
432
static void
739
static void
Lines 440-447 trace_include (const struct line_maps *set, const struct line_map *map) Link Here
440
  fprintf (stderr, " %s\n", map->d.ordinary.to_file);
747
  fprintf (stderr, " %s\n", map->d.ordinary.to_file);
441
}
748
}
442
749
750
/* Expand source code location LOC and return user readable
751
   source code location.  */
752
443
expanded_location
753
expanded_location
444
linemap_expand_location (struct line_maps *set, source_location loc)
754
linemap_expand_location (struct line_maps *set,
755
			 source_location loc)
445
{
756
{
446
  expanded_location xloc;
757
  expanded_location xloc;
447
  if (loc == 0)
758
  if (loc == 0)
Lines 453-474 linemap_expand_location (struct line_maps *set, source_location loc) Link Here
453
    }
764
    }
454
  else
765
  else
455
    {
766
    {
456
      const struct line_map *map;
767
      struct line_map *map;
457
      while (1)
768
      loc = linemap_macro_exp_loc_to_exp_point (set, loc, &map);
458
	{
459
	  unsigned int token;
460
461
	  map = linemap_lookup (set, loc);
462
	  if (map->reason != LC_ENTER_MACRO)
463
	    break;
464
	  token = loc - map->start_location;
465
	  linemap_assert (token < map->d.macro.n_tokens);
466
	  /* FIXME?? when we have 2 locs */
467
	  if (map->d.macro.macro_locations[2 * token] > map->d.macro.expansion)
468
	    loc = map->d.macro.macro_locations[2 * token];
469
	  else
470
	    loc = map->d.macro.expansion;
471
	}
472
      xloc.file = LINEMAP_FILE (map);
769
      xloc.file = LINEMAP_FILE (map);
473
      xloc.line = SOURCE_LINE (map, loc);
770
      xloc.line = SOURCE_LINE (map, loc);
474
      xloc.column = SOURCE_COLUMN (map, loc);
771
      xloc.column = SOURCE_COLUMN (map, loc);
Lines 476-478 linemap_expand_location (struct line_maps *set, source_location loc) Link Here
476
    }
773
    }
477
  return xloc;
774
  return xloc;
478
}
775
}
776
777
/* Dump debugging information about source location LOC into the file
778
   stream STREAM. SET is the line map set LOC comes from.  */
779
780
void
781
linemap_dump_location (struct line_maps *set,
782
		       source_location loc,
783
		       FILE *stream)
784
{
785
  struct line_map *map;
786
  source_location location;
787
  const char *p = LINEMAP_FILE (map);
788
  int l,c,s,e;
789
790
  if (loc == 0)
791
    return;
792
793
  location =
794
    linemap_macro_exp_loc_to_exp_point (set, loc, &map);
795
  p = LINEMAP_FILE (map);
796
797
  l = SOURCE_LINE (map, location);
798
  c = SOURCE_COLUMN (map, location);
799
  s = LINEMAP_SYSP (map) != 0;
800
  e = (location != loc);
801
  
802
  /* P: path, L: line, C: column, S: in-system-header, M: map address,
803
     E: macro expansion?.   */
804
  fprintf (stream, "{P:%s;L:%d;C:%d;S:%d;M:%p;E:%d,LOC:%d}",
805
	   p, l, c, s, (void*)map, e, loc);
806
}
(-)a/libcpp/macro.c (-2 / +6 lines)
Lines 201-210 _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node) Link Here
201
      /* If __LINE__ is embedded in a macro, it must expand to the
201
      /* If __LINE__ is embedded in a macro, it must expand to the
202
	 line of the macro's invocation, not its definition.
202
	 line of the macro's invocation, not its definition.
203
	 Otherwise things like assert() will not work properly.  */
203
	 Otherwise things like assert() will not work properly.  */
204
      number = SOURCE_LINE (map, 
204
      number = linemap_get_source_line (pfile->line_table,
205
					CPP_OPTION (pfile, traditional)
206
					? pfile->line_table->highest_line
207
					: pfile->cur_token[-1].src_loc);
208
      /*number = SOURCE_LINE (map, 
205
			    CPP_OPTION (pfile, traditional) 
209
			    CPP_OPTION (pfile, traditional) 
206
			    ? pfile->line_table->highest_line
210
			    ? pfile->line_table->highest_line
207
			    : pfile->cur_token[-1].src_loc);
211
			    : pfile->cur_token[-1].src_loc);*/
208
      break;
212
      break;
209
213
210
      /* __STDC__ has the value 1 under normal circumstances.
214
      /* __STDC__ has the value 1 under normal circumstances.

Return to bug 7263