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

Collapse All | Expand All | Context: (Patch / File /
)

(-)a/gcc/c-lex.c (-8 / +9 lines)
 Lines 1-6    Link Here 
1
/* Mainly the interface between cpplib and the C front ends.
1
/* Mainly the interface between cpplib and the C front ends.
2
   Copyright (C) 1987, 1988, 1989, 1992, 1994, 1995, 1996, 1997
2
   Copyright (C) 1987, 1988, 1989, 1992, 1994, 1995, 1996, 1997
3
   1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008
3
   1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
4
   2010
4
   Free Software Foundation, Inc.
5
   Free Software Foundation, Inc.
5
6
6
This file is part of GCC.
7
This file is part of GCC.
 Lines 211-217   fe_file_change (const struct line_map *new_map) Link Here 
211
	    line = SOURCE_LINE (new_map - 1, included_at);
212
	    line = SOURCE_LINE (new_map - 1, included_at);
212
213
213
	  input_location = new_map->start_location;
214
	  input_location = new_map->start_location;
214
	  (*debug_hooks->start_source_file) (line, new_map->to_file);
215
	  (*debug_hooks->start_source_file) (line, LINEMAP_FILE (new_map));
215
#ifndef NO_IMPLICIT_EXTERN_C
216
#ifndef NO_IMPLICIT_EXTERN_C
216
	  if (c_header_level)
217
	  if (c_header_level)
217
	    ++c_header_level;
218
	    ++c_header_level;
 Lines 235-244   fe_file_change (const struct line_map *new_map) Link Here 
235
#endif
236
#endif
236
      input_location = new_map->start_location;
237
      input_location = new_map->start_location;
237
238
238
      (*debug_hooks->end_source_file) (new_map->to_line);
239
      (*debug_hooks->end_source_file) (LINEMAP_LINE (new_map));
239
    }
240
    }
240
241
241
  update_header_times (new_map->to_file);
242
  update_header_times (LINEMAP_FILE (new_map));
242
  input_location = new_map->start_location;
243
  input_location = new_map->start_location;
243
}
244
}
244
245
 Lines 303-309   c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags, Link Here 
303
304
304
  timevar_push (TV_CPP);
305
  timevar_push (TV_CPP);
305
 retry:
306
 retry:
306
  tok = cpp_get_token_with_location (parse_in, loc);
307
  tok = cpp_get_token (parse_in);
308
  *loc = tok->src_loc;
307
  type = tok->type;
309
  type = tok->type;
308
310
309
 retry_after_at:
311
 retry_after_at:
 Lines 351-360   c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags, Link Here 
351
      if (c_dialect_objc ())
353
      if (c_dialect_objc ())
352
	{
354
	{
353
	  location_t atloc = *loc;
355
	  location_t atloc = *loc;
354
	  location_t newloc;
355
356
356
	retry_at:
357
	retry_at:
357
	  tok = cpp_get_token_with_location (parse_in, &newloc);
358
	  tok = cpp_get_token (parse_in);
358
	  type = tok->type;
359
	  type = tok->type;
359
	  switch (type)
360
	  switch (type)
360
	    {
361
	    {
 Lines 381-387   c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags, Link Here 
381
	    default:
382
	    default:
382
	      /* ... or not.  */
383
	      /* ... or not.  */
383
	      error_at (atloc, "stray %<@%> in program");
384
	      error_at (atloc, "stray %<@%> in program");
384
	      *loc = newloc;
385
	      *loc = tok->src_loc;
385
	      goto retry_after_at;
386
	      goto retry_after_at;
386
	    }
387
	    }
387
	  break;
388
	  break;
(-)a/gcc/c-ppoutput.c (-6 / +15 lines)
 Lines 171-177   scan_translation_unit (cpp_reader *pfile) Link Here 
171
  for (;;)
171
  for (;;)
172
    {
172
    {
173
      source_location loc;
173
      source_location loc;
174
      const cpp_token *token = cpp_get_token_with_location (pfile, &loc);
174
      const cpp_token *token = cpp_get_token (pfile);
175
      loc = token->src_loc;
175
176
176
      if (token->type == CPP_PADDING)
177
      if (token->type == CPP_PADDING)
177
	{
178
	{
 Lines 339-345   print_line (source_location src_loc, const char *special_flags) Link Here 
339
    {
340
    {
340
      const struct line_map *map = linemap_lookup (line_table, src_loc);
341
      const struct line_map *map = linemap_lookup (line_table, src_loc);
341
342
342
      size_t to_file_len = strlen (map->to_file);
343
      size_t to_file_len = strlen (LINEMAP_FILE (map));
343
      unsigned char *to_file_quoted =
344
      unsigned char *to_file_quoted =
344
         (unsigned char *) alloca (to_file_len * 4 + 1);
345
         (unsigned char *) alloca (to_file_len * 4 + 1);
345
      unsigned char *p;
346
      unsigned char *p;
 Lines 349-363   print_line (source_location src_loc, const char *special_flags) Link Here 
349
      /* cpp_quote_string does not nul-terminate, so we have to do it
350
      /* cpp_quote_string does not nul-terminate, so we have to do it
350
	 ourselves.  */
351
	 ourselves.  */
351
      p = cpp_quote_string (to_file_quoted,
352
      p = cpp_quote_string (to_file_quoted,
352
			    (const unsigned char *) map->to_file, to_file_len);
353
			    (const unsigned char *) LINEMAP_FILE (map),
354
			    to_file_len);
353
      *p = '\0';
355
      *p = '\0';
354
      fprintf (print.outf, "# %u \"%s\"%s",
356
      fprintf (print.outf, "# %u \"%s\"%s",
355
	       print.src_line == 0 ? 1 : print.src_line,
357
	       print.src_line == 0 ? 1 : print.src_line,
356
	       to_file_quoted, special_flags);
358
	       to_file_quoted, special_flags);
357
359
358
      if (map->sysp == 2)
360
      if (LINEMAP_SYSP (map) == 2)
359
	fputs (" 3 4", print.outf);
361
	fputs (" 3 4", print.outf);
360
      else if (map->sysp == 1)
362
      else if (LINEMAP_SYSP (map) == 1)
361
	fputs (" 3", print.outf);
363
	fputs (" 3", print.outf);
362
364
363
      putc ('\n', print.outf);
365
      putc ('\n', print.outf);
 Lines 416-421   cb_ident (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line, Link Here 
416
static void
418
static void
417
cb_define (cpp_reader *pfile, source_location line, cpp_hashnode *node)
419
cb_define (cpp_reader *pfile, source_location line, cpp_hashnode *node)
418
{
420
{
421
  const struct line_map *map;
422
423
  if (line <= BUILTINS_LOCATION)
424
    return;
419
  maybe_print_line (line);
425
  maybe_print_line (line);
420
  fputs ("#define ", print.outf);
426
  fputs ("#define ", print.outf);
421
427
 Lines 427-433   cb_define (cpp_reader *pfile, source_location line, cpp_hashnode *node) Link Here 
427
    fputs ((const char *) NODE_NAME (node), print.outf);
433
    fputs ((const char *) NODE_NAME (node), print.outf);
428
434
429
  putc ('\n', print.outf);
435
  putc ('\n', print.outf);
430
  if (linemap_lookup (line_table, line)->to_line != 0)
436
  map = linemap_lookup (line_table, line);
437
  if (LINEMAP_LINE (map) != 0)
431
    print.src_line++;
438
    print.src_line++;
432
}
439
}
433
440
 Lines 435-440   static void Link Here 
435
cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line,
442
cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line,
436
	  cpp_hashnode *node)
443
	  cpp_hashnode *node)
437
{
444
{
445
  if (line <= BUILTINS_LOCATION)
446
    return;
438
  maybe_print_line (line);
447
  maybe_print_line (line);
439
  fprintf (print.outf, "#undef %s\n", NODE_NAME (node));
448
  fprintf (print.outf, "#undef %s\n", NODE_NAME (node));
440
  print.src_line++;
449
  print.src_line++;
(-)a/gcc/cp/error.c (-1 / +1 lines)
 Lines 2541-2547   static void Link Here 
2541
cp_diagnostic_starter (diagnostic_context *context,
2541
cp_diagnostic_starter (diagnostic_context *context,
2542
		       diagnostic_info *diagnostic)
2542
		       diagnostic_info *diagnostic)
2543
{
2543
{
2544
  diagnostic_report_current_module (context);
2544
  diagnostic_report_current_module (context, diagnostic->location);
2545
  cp_print_error_function (context, diagnostic);
2545
  cp_print_error_function (context, diagnostic);
2546
  maybe_print_instantiation_context (context);
2546
  maybe_print_instantiation_context (context);
2547
  pp_base_set_prefix (context->printer, diagnostic_build_prefix (diagnostic));
2547
  pp_base_set_prefix (context->printer, diagnostic_build_prefix (diagnostic));
(-)a/gcc/diagnostic.c (-7 / +27 lines)
 Lines 41-46   along with GCC; see the file COPYING3. If not see Link Here 
41
#include "langhooks-def.h"
41
#include "langhooks-def.h"
42
#include "opts.h"
42
#include "opts.h"
43
#include "plugin.h"
43
#include "plugin.h"
44
#include "cpp-id-data.h"
44
45
45
#define pedantic_warning_kind() (flag_pedantic_errors ? DK_ERROR : DK_WARNING)
46
#define pedantic_warning_kind() (flag_pedantic_errors ? DK_ERROR : DK_WARNING)
46
#define permissive_error_kind() (flag_permissive ? DK_WARNING : DK_ERROR)
47
#define permissive_error_kind() (flag_permissive ? DK_WARNING : DK_ERROR)
 Lines 238-249   void Link Here 
238
diagnostic_report_current_function (diagnostic_context *context,
239
diagnostic_report_current_function (diagnostic_context *context,
239
				    diagnostic_info *diagnostic)
240
				    diagnostic_info *diagnostic)
240
{
241
{
241
  diagnostic_report_current_module (context);
242
  diagnostic_report_current_module (context, diagnostic->location);
242
  lang_hooks.print_error_function (context, input_filename, diagnostic);
243
  lang_hooks.print_error_function (context, input_filename, diagnostic);
243
}
244
}
244
245
245
void
246
void
246
diagnostic_report_current_module (diagnostic_context *context)
247
diagnostic_report_current_module (diagnostic_context *context, location_t where)
247
{
248
{
248
  const struct line_map *map;
249
  const struct line_map *map;
249
250
 Lines 253-283   diagnostic_report_current_module (diagnostic_context *context) Link Here 
253
      pp_needs_newline (context->printer) = false;
254
      pp_needs_newline (context->printer) = false;
254
    }
255
    }
255
256
256
  if (input_location <= BUILTINS_LOCATION)
257
  if (where <= BUILTINS_LOCATION)
257
    return;
258
    return;
258
259
259
  map = linemap_lookup (line_table, input_location);
260
  map = linemap_lookup (line_table, where);
260
  if (map && diagnostic_last_module_changed (context, map))
261
  if (map && diagnostic_last_module_changed (context, map))
261
    {
262
    {
263
      struct line_map *macro_map;
264
262
      diagnostic_set_last_module (context, map);
265
      diagnostic_set_last_module (context, map);
266
      for (macro_map = map; macro_map->reason == LC_ENTER_MACRO; )
267
 	{
268
 	  expanded_location loc;
269
 	  source_location l2 = where - macro_map->start_location;
270
 	  where = macro_map->d.macro.macro_locations[2 * l2 + 1];
271
 	  loc = expand_location (where);
272
 	  pp_verbatim (context->printer,
273
 		       "While expanding macro %s at %s:%d:%d",
274
 		       LINEMAP_MACRO_NAME (macro_map),
275
		       loc.file, loc.line, loc.column);
276
	  pp_newline (context->printer);
277
 	  macro_map = linemap_lookup (line_table, where);
278
 	}
279
280
      while (map->reason == LC_ENTER_MACRO)
281
 	map = linemap_lookup (line_table, map->d.macro.expansion);
282
263
      if (! MAIN_FILE_P (map))
283
      if (! MAIN_FILE_P (map))
264
	{
284
	{
265
	  map = INCLUDED_FROM (line_table, map);
285
	  map = INCLUDED_FROM (line_table, map);
266
	  if (flag_show_column)
286
	  if (flag_show_column)
267
	    pp_verbatim (context->printer,
287
	    pp_verbatim (context->printer,
268
			 "In file included from %s:%d:%d",
288
			 "In file included from %s:%d:%d",
269
			 map->to_file,
289
			 LINEMAP_FILE (map),
270
			 LAST_SOURCE_LINE (map), LAST_SOURCE_COLUMN (map));
290
			 LAST_SOURCE_LINE (map), LAST_SOURCE_COLUMN (map));
271
	  else
291
	  else
272
	    pp_verbatim (context->printer,
292
	    pp_verbatim (context->printer,
273
			 "In file included from %s:%d",
293
			 "In file included from %s:%d",
274
			 map->to_file, LAST_SOURCE_LINE (map));
294
			 LINEMAP_FILE (map), LAST_SOURCE_LINE (map));
275
	  while (! MAIN_FILE_P (map))
295
	  while (! MAIN_FILE_P (map))
276
	    {
296
	    {
277
	      map = INCLUDED_FROM (line_table, map);
297
	      map = INCLUDED_FROM (line_table, map);
278
	      pp_verbatim (context->printer,
298
	      pp_verbatim (context->printer,
279
			   ",\n                 from %s:%d",
299
			   ",\n                 from %s:%d",
280
			   map->to_file, LAST_SOURCE_LINE (map));
300
			   LINEMAP_FILE (map), LAST_SOURCE_LINE (map));
281
	    }
301
	    }
282
	  pp_verbatim (context->printer, ":");
302
	  pp_verbatim (context->printer, ":");
283
	  pp_newline (context->printer);
303
	  pp_newline (context->printer);
(-)a/gcc/diagnostic.h (-1 / +2 lines)
 Lines 207-213   extern diagnostic_context *global_dc; Link Here 
207
/* Diagnostic related functions.  */
207
/* Diagnostic related functions.  */
208
extern void diagnostic_initialize (diagnostic_context *);
208
extern void diagnostic_initialize (diagnostic_context *);
209
extern void diagnostic_finish (diagnostic_context *);
209
extern void diagnostic_finish (diagnostic_context *);
210
extern void diagnostic_report_current_module (diagnostic_context *);
210
extern void diagnostic_report_current_module (diagnostic_context *,
211
					      location_t);
211
extern void diagnostic_report_current_function (diagnostic_context *,
212
extern void diagnostic_report_current_function (diagnostic_context *,
212
						diagnostic_info *);
213
						diagnostic_info *);
213
214
(-)a/gcc/fortran/cpp.c (-7 / +11 lines)
 Lines 779-804   print_line (source_location src_loc, const char *special_flags) Link Here 
779
  if (!gfc_cpp_option.no_line_commands)
779
  if (!gfc_cpp_option.no_line_commands)
780
    {
780
    {
781
      const struct line_map *map = linemap_lookup (line_table, src_loc);
781
      const struct line_map *map = linemap_lookup (line_table, src_loc);
782
      struct expanded_location loc;
782
783
783
      size_t to_file_len = strlen (map->to_file);
784
      size_t to_file_len;
784
      unsigned char *to_file_quoted =
785
      unsigned char *to_file_quoted;
785
         (unsigned char *) alloca (to_file_len * 4 + 1);
786
      unsigned char *p;
786
      unsigned char *p;
787
787
788
      print.src_line = SOURCE_LINE (map, src_loc);
788
      loc = expand_location (src_loc);
789
      to_file_len = strlen (loc.file);
790
      to_file_quoted = (unsigned char *) alloca (to_file_len * 4 + 1);
791
792
      print.src_line = loc.line;
789
793
790
      /* cpp_quote_string does not nul-terminate, so we have to do it
794
      /* cpp_quote_string does not nul-terminate, so we have to do it
791
	 ourselves.  */
795
	 ourselves.  */
792
      p = cpp_quote_string (to_file_quoted,
796
      p = cpp_quote_string (to_file_quoted,
793
			    (const unsigned char *) map->to_file, to_file_len);
797
			    (const unsigned char *) loc.file, to_file_len);
794
      *p = '\0';
798
      *p = '\0';
795
      fprintf (print.outf, "# %u \"%s\"%s",
799
      fprintf (print.outf, "# %u \"%s\"%s",
796
	       print.src_line == 0 ? 1 : print.src_line,
800
	       print.src_line == 0 ? 1 : print.src_line,
797
	       to_file_quoted, special_flags);
801
	       to_file_quoted, special_flags);
798
802
799
      if (map->sysp == 2)
803
      if (loc.sysp == 2)
800
	fputs (" 3 4", print.outf);
804
	fputs (" 3 4", print.outf);
801
      else if (map->sysp == 1)
805
      else if (loc.sysp == 1)
802
	fputs (" 3", print.outf);
806
	fputs (" 3", print.outf);
803
807
804
      putc ('\n', print.outf);
808
      putc ('\n', print.outf);
(-)a/gcc/input.h (-14 / +1 lines)
 Lines 37-56   extern GTY(()) struct line_maps *line_table; Link Here 
37
extern char builtins_location_check[(BUILTINS_LOCATION
37
extern char builtins_location_check[(BUILTINS_LOCATION
38
				     < RESERVED_LOCATION_COUNT) ? 1 : -1];
38
				     < RESERVED_LOCATION_COUNT) ? 1 : -1];
39
39
40
typedef struct GTY (())
41
{
42
  /* The name of the source file involved.  */
43
  const char *file;
44
45
  /* The line-location in the source file.  */
46
  int line;
47
48
  int column;
49
50
  /* In a system header?. */
51
  bool sysp;
52
} expanded_location;
53
54
extern expanded_location expand_location (source_location);
40
extern expanded_location expand_location (source_location);
55
41
56
/* Historically GCC used location_t, while cpp used source_location.
42
/* Historically GCC used location_t, while cpp used source_location.
 Lines 69-73   extern location_t input_location; Link Here 
69
#define input_filename LOCATION_FILE (input_location)
55
#define input_filename LOCATION_FILE (input_location)
70
#define in_system_header_at(LOC) ((expand_location (LOC)).sysp != 0)
56
#define in_system_header_at(LOC) ((expand_location (LOC)).sysp != 0)
71
#define in_system_header (in_system_header_at (input_location))
57
#define in_system_header (in_system_header_at (input_location))
58
#define expand_location(LOC) linemap_expand_location (line_table, LOC)
72
59
73
#endif
60
#endif
(-)a/gcc/toplev.c (+1 lines)
 Lines 2477-2479   toplev_main (int argc, char **argv) Link Here 
2477
2477
2478
  return (SUCCESS_EXIT_CODE);
2478
  return (SUCCESS_EXIT_CODE);
2479
}
2479
}
2480
(-)a/gcc/tree.c (-23 lines)
 Lines 3961-3989   build_block (tree vars, tree subblocks, tree supercontext, tree chain) Link Here 
3961
  return block;
3961
  return block;
3962
}
3962
}
3963
3963
3964
expanded_location
3965
expand_location (source_location loc)
3966
{
3967
  expanded_location xloc;
3968
  if (loc <= BUILTINS_LOCATION)
3969
    {
3970
      xloc.file = loc == UNKNOWN_LOCATION ? NULL : _("<built-in>");
3971
      xloc.line = 0;
3972
      xloc.column = 0;
3973
      xloc.sysp = 0;
3974
    }
3975
  else
3976
    {
3977
      const struct line_map *map = linemap_lookup (line_table, loc);
3978
      xloc.file = map->to_file;
3979
      xloc.line = SOURCE_LINE (map, loc);
3980
      xloc.column = SOURCE_COLUMN (map, loc);
3981
      xloc.sysp = map->sysp != 0;
3982
    };
3983
  return xloc;
3984
}
3985
3986

3987
/* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
3964
/* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
3988
3965
3989
   LOC is the location to use in tree T.  */
3966
   LOC is the location to use in tree T.  */
(-)a/libcpp/directives.c (-5 / +5 lines)
 Lines 887-895   do_line (cpp_reader *pfile) Link Here 
887
  /* skip_rest_of_line() may cause line table to be realloc()ed so note down
887
  /* skip_rest_of_line() may cause line table to be realloc()ed so note down
888
     sysp right now.  */
888
     sysp right now.  */
889
889
890
  unsigned char map_sysp = map->sysp;
890
  unsigned char map_sysp = map->d.ordinary.sysp;
891
  const cpp_token *token;
891
  const cpp_token *token;
892
  const char *new_file = map->to_file;
892
  const char *new_file = map->d.ordinary.to_file;
893
  linenum_type new_lineno;
893
  linenum_type new_lineno;
894
894
895
  /* C99 raised the minimum limit on #line numbers.  */
895
  /* C99 raised the minimum limit on #line numbers.  */
 Lines 946-954   do_linemarker (cpp_reader *pfile) Link Here 
946
  const struct line_maps *line_table = pfile->line_table;
946
  const struct line_maps *line_table = pfile->line_table;
947
  const struct line_map *map = &line_table->maps[line_table->used - 1];
947
  const struct line_map *map = &line_table->maps[line_table->used - 1];
948
  const cpp_token *token;
948
  const cpp_token *token;
949
  const char *new_file = map->to_file;
949
  const char *new_file = map->d.ordinary.to_file;
950
  linenum_type new_lineno;
950
  linenum_type new_lineno;
951
  unsigned int new_sysp = map->sysp;
951
  unsigned int new_sysp = map->d.ordinary.sysp;
952
  enum lc_reason reason = LC_RENAME_VERBATIM;
952
  enum lc_reason reason = LC_RENAME_VERBATIM;
953
  int flag;
953
  int flag;
954
  bool wrapped;
954
  bool wrapped;
 Lines 1036-1042   _cpp_do_file_change (cpp_reader *pfile, enum lc_reason reason, Link Here 
1036
  const struct line_map *map = linemap_add (pfile->line_table, reason, sysp,
1036
  const struct line_map *map = linemap_add (pfile->line_table, reason, sysp,
1037
					    to_file, file_line);
1037
					    to_file, file_line);
1038
  if (map != NULL)
1038
  if (map != NULL)
1039
    linemap_line_start (pfile->line_table, map->to_line, 127);
1039
    linemap_line_start (pfile->line_table, map->d.ordinary.to_line, 127);
1040
1040
1041
  if (pfile->cb.file_change)
1041
  if (pfile->cb.file_change)
1042
    pfile->cb.file_change (pfile, map);
1042
    pfile->cb.file_change (pfile, map);
(-)a/libcpp/files.c (-1 / +1 lines)
 Lines 1227-1233   cpp_make_system_header (cpp_reader *pfile, int syshdr, int externc) Link Here 
1227
  if (syshdr)
1227
  if (syshdr)
1228
    flags = 1 + (externc != 0);
1228
    flags = 1 + (externc != 0);
1229
  pfile->buffer->sysp = flags;
1229
  pfile->buffer->sysp = flags;
1230
  _cpp_do_file_change (pfile, LC_RENAME, map->to_file,
1230
  _cpp_do_file_change (pfile, LC_RENAME, map->d.ordinary.to_file,
1231
		       SOURCE_LINE (map, pfile->line_table->highest_line), flags);
1231
		       SOURCE_LINE (map, pfile->line_table->highest_line), flags);
1232
}
1232
}
1233
1233
(-)a/libcpp/include/cpp-id-data.h (+6 lines)
 Lines 34-39   struct GTY(()) answer { Link Here 
34
/* Each macro definition is recorded in a cpp_macro structure.
34
/* Each macro definition is recorded in a cpp_macro structure.
35
   Variadic macros cannot occur with traditional cpp.  */
35
   Variadic macros cannot occur with traditional cpp.  */
36
struct GTY(()) cpp_macro {
36
struct GTY(()) cpp_macro {
37
  /* Name of this macro.  Used only for error reporting.  */
38
  cpp_hashnode * GTY ((nested_ptr (union tree_node,
39
		"%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
40
				   "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL")))
41
    name;
42
37
  /* Parameters, if any.  */
43
  /* Parameters, if any.  */
38
  cpp_hashnode ** GTY ((nested_ptr (union tree_node,
44
  cpp_hashnode ** GTY ((nested_ptr (union tree_node,
39
		"%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
45
		"%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
(-)a/libcpp/include/cpplib.h (-2 lines)
 Lines 725-732   extern void cpp_register_deferred_pragma (cpp_reader *, const char *, Link Here 
725
extern int cpp_avoid_paste (cpp_reader *, const cpp_token *,
725
extern int cpp_avoid_paste (cpp_reader *, const cpp_token *,
726
			    const cpp_token *);
726
			    const cpp_token *);
727
extern const cpp_token *cpp_get_token (cpp_reader *);
727
extern const cpp_token *cpp_get_token (cpp_reader *);
728
extern const cpp_token *cpp_get_token_with_location (cpp_reader *,
729
						     source_location *);
730
extern const unsigned char *cpp_macro_definition (cpp_reader *,
728
extern const unsigned char *cpp_macro_definition (cpp_reader *,
731
						  const cpp_hashnode *);
729
						  const cpp_hashnode *);
732
extern void _cpp_backup_tokens (cpp_reader *, unsigned int);
730
extern void _cpp_backup_tokens (cpp_reader *, unsigned int);
(-)a/libcpp/include/line-map.h (-30 / +117 lines)
 Lines 33-75   along with this program; see the file COPYING3. If not see Link Here 
33
   name or line number changes for neither of the above reasons
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
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 input.  */
35
   but a filename of "" is not specially interpreted as standard input.  */
36
enum lc_reason {LC_ENTER = 0, LC_LEAVE, LC_RENAME, LC_RENAME_VERBATIM};
36
enum lc_reason
37
{
38
  LC_ENTER = 0,
39
  LC_LEAVE,
40
  LC_RENAME,
41
  LC_RENAME_VERBATIM,
42
  LC_ENTER_MACRO
43
  /* stringize */
44
  /* paste */
45
};
37
46
38
/* The type of line numbers.  */
47
/* The type of line numbers.  */
39
typedef unsigned int linenum_type;
48
typedef unsigned int linenum_type;
40
49
41
/* A logical line/column number, i.e. an "index" into a line_map.  */
50
/* A logical line/column number, i.e. an "index" into a line_map.  */
42
/* Long-term, we want to use this to replace struct location_s (in input.h),
43
   and effectively typedef source_location location_t.  */
44
typedef unsigned int source_location;
51
typedef unsigned int source_location;
45
52
46
/* Memory allocation function typedef.  Works like xrealloc.  */
53
/* Memory allocation function typedef.  Works like xrealloc.  */
47
typedef void *(*line_map_realloc) (void *, size_t);
54
typedef void *(*line_map_realloc) (void *, size_t);
48
55
49
/* Physical source file TO_FILE at line TO_LINE at column 0 is represented
56
/* An ordinary line map encodes physical source locations.
57
   
58
   Physical source file TO_FILE at line TO_LINE at column 0 is represented
50
   by the logical START_LOCATION.  TO_LINE+L at column C is represented by
59
   by the logical START_LOCATION.  TO_LINE+L at column C is represented by
51
   START_LOCATION+(L*(1<<column_bits))+C, as long as C<(1<<column_bits),
60
   START_LOCATION+(L*(1<<column_bits))+C, as long as C<(1<<column_bits),
52
   and the result_location is less than the next line_map's start_location.
61
   and the result_location is less than the next line_map's start_location.
53
   (The top line is line 1 and the leftmost column is column 1; line/column 0
62
   (The top line is line 1 and the leftmost column is column 1; line/column 0
54
   means "entire file/line" or "unknown line/column" or "not applicable".)
63
   means "entire file/line" or "unknown line/column" or "not applicable".)
55
   INCLUDED_FROM is an index into the set that gives the line mapping
64
*/
56
   at whose end the current one was included.  File(s) at the bottom
65
struct GTY(()) line_map_ordinary
57
   of the include stack have this set to -1.  REASON is the reason for
66
{
58
   creation of this line map, SYSP is one for a system header, two for
59
   a C system header file that therefore needs to be extern "C"
60
   protected in C++, and zero otherwise.  */
61
struct GTY(()) line_map {
62
  const char *to_file;
67
  const char *to_file;
63
  linenum_type to_line;
68
  linenum_type to_line;
64
  source_location start_location;
69
70
  /* An index into the set that gives the line mapping at whose end
71
     the current one was included.  File(s) at the bottom of the
72
     include stack have this set to -1.  */
65
  int included_from;
73
  int included_from;
66
  ENUM_BITFIELD (lc_reason) reason : CHAR_BIT;
74
67
  /* The sysp field isn't really needed now that it's in cpp_buffer.  */
75
  /* SYSP is one for a system header, two for a C system header file
76
     that therefore needs to be extern "C" protected in C++, and zero
77
     otherwise.  This field isn't really needed now that it's in
78
     cpp_buffer.  */
68
  unsigned char sysp;
79
  unsigned char sysp;
69
  /* Number of the low-order source_location bits used for a column number.  */
80
81
  /* Number of the low-order source_location bits used for a column
82
     number.  */
70
  unsigned int column_bits : 8;
83
  unsigned int column_bits : 8;
71
};
84
};
72
85
86
struct GTY(()) cpp_macro;
87
88
/* A macro line map encodes locations coming from a macro expansion.
89
   
90
   Here, the offset from START_LOCATION is used to index into
91
   MACRO_LOCATIONS; this holds the original location of the token.  */
92
struct GTY(()) line_map_macro
93
{
94
  struct cpp_macro *macro;
95
  unsigned int n_tokens;
96
  source_location * GTY((length ("%h.n_tokens"))) macro_locations;
97
  source_location expansion;
98
};
99
100
/* A line_map encodes a sequence of locations.  */
101
struct GTY(()) line_map {
102
  source_location start_location;
103
104
  /* The reason for creation of this line map.  */
105
  ENUM_BITFIELD (lc_reason) reason : CHAR_BIT;
106
107
  union {
108
    struct line_map_ordinary GTY((tag ("0"))) ordinary;
109
    struct line_map_macro GTY((tag ("1"))) macro;
110
  } GTY((desc ("%1.reason == LC_ENTER_MACRO"))) d;
111
};
112
73
/* A set of chronological line_map structures.  */
113
/* A set of chronological line_map structures.  */
74
struct GTY(()) line_maps {
114
struct GTY(()) line_maps {
75
  struct line_map * GTY ((length ("%h.used"))) maps;
115
  struct line_map * GTY ((length ("%h.used"))) maps;
 Lines 78-88   struct GTY(()) line_maps { Link Here 
78
118
79
  unsigned int cache;
119
  unsigned int cache;
80
120
81
  /* The most recently listed include stack, if any, starts with
82
     LAST_LISTED as the topmost including file.  -1 indicates nothing
83
     has been listed yet.  */
84
  int last_listed;
85
86
  /* Depth of the include stack, including the current file.  */
121
  /* Depth of the include stack, including the current file.  */
87
  unsigned int depth;
122
  unsigned int depth;
88
123
 Lines 138-159   extern const struct line_map *linemap_add Link Here 
138
  (struct line_maps *, enum lc_reason, unsigned int sysp,
173
  (struct line_maps *, enum lc_reason, unsigned int sysp,
139
   const char *to_file, linenum_type to_line);
174
   const char *to_file, linenum_type to_line);
140
175
176
extern const struct line_map *linemap_enter_macro (struct line_maps *,
177
						   void *, source_location,
178
						   unsigned int);
179
180
extern source_location linemap_add_macro_token (const struct line_map *,
181
						unsigned int,
182
						source_location,
183
						source_location);
184
185
extern void linemap_leave_macro (struct line_maps *, source_location);
186
141
/* Given a logical line, returns the map from which the corresponding
187
/* Given a logical line, returns the map from which the corresponding
142
   (source file, line) pair can be deduced.  */
188
   (source file, line) pair can be deduced.  */
143
extern const struct line_map *linemap_lookup
189
extern const struct line_map *linemap_lookup
144
  (struct line_maps *, source_location);
190
  (struct line_maps *, source_location);
145
191
192
extern int linemap_check_ordinary (const struct line_map *);
193
146
/* source_location values from 0 to RESERVED_LOCATION_COUNT-1 will
194
/* source_location values from 0 to RESERVED_LOCATION_COUNT-1 will
147
   be reserved for libcpp user as special values, no token from libcpp
195
   be reserved for libcpp user as special values, no token from libcpp
148
   will contain any of those locations.  */
196
   will contain any of those locations.  */
149
#define RESERVED_LOCATION_COUNT	2
197
#define RESERVED_LOCATION_COUNT	2
150
198
151
/* Converts a map and a source_location to source line.  */
199
/* Converts a map and a source_location to source line.  */
152
#define SOURCE_LINE(MAP, LOC) \
200
#define SOURCE_LINE(MAP, LOC)						\
153
  ((((LOC) - (MAP)->start_location) >> (MAP)->column_bits) + (MAP)->to_line)
201
  (linemap_check_ordinary (MAP),					\
202
   ((((LOC) - (MAP)->start_location)					\
203
     >> (MAP)->d.ordinary.column_bits) + (MAP)->d.ordinary.to_line))
154
204
155
#define SOURCE_COLUMN(MAP, LOC) \
205
#define SOURCE_COLUMN(MAP, LOC)				\
156
  (((LOC) - (MAP)->start_location) & ((1 << (MAP)->column_bits) - 1))
206
  (linemap_check_ordinary (MAP),			\
207
  (((LOC) - (MAP)->start_location)			\
208
   & ((1 << (MAP)->d.ordinary.column_bits) - 1)))
157
209
158
/* Returns the last source line within a map.  This is the (last) line
210
/* Returns the last source line within a map.  This is the (last) line
159
   of the #include, or other directive, that caused a map change.  */
211
   of the #include, or other directive, that caused a map change.  */
 Lines 161-176   extern const struct line_map *linemap_lookup Link Here 
161
  SOURCE_LINE (MAP, LAST_SOURCE_LINE_LOCATION (MAP))
213
  SOURCE_LINE (MAP, LAST_SOURCE_LINE_LOCATION (MAP))
162
#define LAST_SOURCE_COLUMN(MAP) \
214
#define LAST_SOURCE_COLUMN(MAP) \
163
  SOURCE_COLUMN (MAP, LAST_SOURCE_LINE_LOCATION (MAP))
215
  SOURCE_COLUMN (MAP, LAST_SOURCE_LINE_LOCATION (MAP))
164
#define LAST_SOURCE_LINE_LOCATION(MAP) \
216
#define LAST_SOURCE_LINE_LOCATION(MAP)				\
165
  ((((MAP)[1].start_location - 1 - (MAP)->start_location) \
217
  (linemap_check_ordinary (MAP),				\
166
    & ~((1 << (MAP)->column_bits) - 1))			  \
218
   ((((MAP)[1].start_location - 1 - (MAP)->start_location)	\
167
   + (MAP)->start_location)
219
     & ~((1 << (MAP)->d.ordinary.column_bits) - 1))		\
220
    + (MAP)->start_location))
168
221
169
/* Returns the map a given map was included from.  */
222
/* Returns the map a given map was included from.  */
170
#define INCLUDED_FROM(SET, MAP) (&(SET)->maps[(MAP)->included_from])
223
#define INCLUDED_FROM(SET, MAP)				\
224
  (linemap_check_ordinary (MAP),			\
225
   (&(SET)->maps[(MAP)->d.ordinary.included_from]))
171
226
172
/* Nonzero if the map is at the bottom of the include stack.  */
227
/* Nonzero if the map is at the bottom of the include stack.  */
173
#define MAIN_FILE_P(MAP) ((MAP)->included_from < 0)
228
#define MAIN_FILE_P(MAP)			\
229
  (linemap_check_ordinary (MAP),		\
230
   ((MAP)->d.ordinary.included_from < 0))
174
231
175
/* Set LOC to a source position that is the same line as the most recent
232
/* Set LOC to a source position that is the same line as the most recent
176
   linemap_line_start, but with the specified TO_COLUMN column number.  */
233
   linemap_line_start, but with the specified TO_COLUMN column number.  */
 Lines 192-195   extern const struct line_map *linemap_lookup Link Here 
192
extern source_location
249
extern source_location
193
linemap_position_for_column (struct line_maps *set, unsigned int to_column);
250
linemap_position_for_column (struct line_maps *set, unsigned int to_column);
194
251
252
253
#define LINEMAP_FILE(MAP)					\
254
  (linemap_check_ordinary (MAP), (MAP)->d.ordinary.to_file)
255
256
#define LINEMAP_LINE(MAP)					\
257
  (linemap_check_ordinary (MAP), (MAP)->d.ordinary.to_line)
258
259
#define LINEMAP_SYSP(MAP)					\
260
  (linemap_check_ordinary (MAP), (MAP)->d.ordinary.sysp)
261
262
/* FIXME: add assertion.  */
263
#define LINEMAP_MACRO_NAME(MAP) (NODE_NAME ((MAP)->d.macro.macro->name))
264
265
typedef struct GTY (())
266
{
267
  /* The name of the source file involved.  */
268
  const char *file;
269
270
  /* The line-location in the source file.  */
271
  int line;
272
273
  int column;
274
275
  /* In a system header?. */
276
  bool sysp;
277
} expanded_location;
278
279
extern expanded_location linemap_expand_location (struct line_maps *,
280
						  source_location);
281
195
#endif /* !LIBCPP_LINE_MAP_H  */
282
#endif /* !LIBCPP_LINE_MAP_H  */
(-)a/libcpp/init.c (-1 / +1 lines)
 Lines 570-576   cpp_read_main_file (cpp_reader *pfile, const char *fname) Link Here 
570
  if (CPP_OPTION (pfile, preprocessed))
570
  if (CPP_OPTION (pfile, preprocessed))
571
    {
571
    {
572
      read_original_filename (pfile);
572
      read_original_filename (pfile);
573
      fname = pfile->line_table->maps[pfile->line_table->used-1].to_file;
573
      fname = pfile->line_table->maps[pfile->line_table->used-1].d.ordinary.to_file;
574
    }
574
    }
575
  return fname;
575
  return fname;
576
}
576
}
(-)a/libcpp/internal.h (-8 lines)
 Lines 351-364   struct cpp_reader Link Here 
351
  /* Token generated while handling a directive, if any. */
351
  /* Token generated while handling a directive, if any. */
352
  cpp_token directive_result;
352
  cpp_token directive_result;
353
353
354
  /* When expanding a macro at top-level, this is the location of the
355
     macro invocation.  */
356
  source_location invocation_location;
357
358
  /* True if this call to cpp_get_token should consider setting
359
     invocation_location.  */
360
  bool set_invocation_location;
361
362
  /* Search paths for include files.  */
354
  /* Search paths for include files.  */
363
  struct cpp_dir *quote_include;	/* "" */
355
  struct cpp_dir *quote_include;	/* "" */
364
  struct cpp_dir *bracket_include;	/* <> */
356
  struct cpp_dir *bracket_include;	/* <> */
(-)a/libcpp/line-map.c (-46 / +205 lines)
 Lines 24-29   along with this program; see the file COPYING3. If not see Link Here 
24
#include "system.h"
24
#include "system.h"
25
#include "line-map.h"
25
#include "line-map.h"
26
26
27
#define linemap_assert(EXPR)			\
28
  do {						\
29
    if (! (EXPR))				\
30
      abort ();					\
31
  } while (0)
32
27
static void trace_include (const struct line_maps *, const struct line_map *);
33
static void trace_include (const struct line_maps *, const struct line_map *);
28
34
29
/* Initialize a line map set.  */
35
/* Initialize a line map set.  */
 Lines 34-40   linemap_init (struct line_maps *set) Link Here 
34
  set->maps = NULL;
40
  set->maps = NULL;
35
  set->allocated = 0;
41
  set->allocated = 0;
36
  set->used = 0;
42
  set->used = 0;
37
  set->last_listed = -1;
38
  set->trace_includes = false;
43
  set->trace_includes = false;
39
  set->depth = 0;
44
  set->depth = 0;
40
  set->cache = 0;
45
  set->cache = 0;
 Lines 55-61   linemap_check_files_exited (struct line_maps *set) Link Here 
55
  for (map = &set->maps[set->used - 1]; ! MAIN_FILE_P (map);
60
  for (map = &set->maps[set->used - 1]; ! MAIN_FILE_P (map);
56
       map = INCLUDED_FROM (set, map))
61
       map = INCLUDED_FROM (set, map))
57
    fprintf (stderr, "line-map.c: file \"%s\" entered but not left\n",
62
    fprintf (stderr, "line-map.c: file \"%s\" entered but not left\n",
58
	     map->to_file);
63
	     map->d.ordinary.to_file);
59
}
64
}
60
 
65
 
61
/* Free a line map set.  */
66
/* Free a line map set.  */
 Lines 71-99   linemap_free (struct line_maps *set) Link Here 
71
    }
76
    }
72
}
77
}
73
78
74
/* Add a mapping of logical source line to physical source file and
79
static struct line_map *
75
   line number.
80
new_linemap (struct line_maps *set)
76
77
   The text pointed to by TO_FILE must have a lifetime
78
   at least as long as the final call to lookup_line ().  An empty
79
   TO_FILE means standard input.  If reason is LC_LEAVE, and
80
   TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their
81
   natural values considering the file we are returning to.
82
83
   FROM_LINE should be monotonic increasing across calls to this
84
   function.  A call to this function can relocate the previous set of
85
   maps, so any stored line_map pointers should not be used.  */
86
87
const struct line_map *
88
linemap_add (struct line_maps *set, enum lc_reason reason,
89
	     unsigned int sysp, const char *to_file, linenum_type to_line)
90
{
81
{
91
  struct line_map *map;
92
  source_location start_location = set->highest_location + 1;
93
94
  if (set->used && start_location < set->maps[set->used - 1].start_location)
95
    abort ();
96
97
  if (set->used == set->allocated)
82
  if (set->used == set->allocated)
98
    {
83
    {
99
      line_map_realloc reallocator
84
      line_map_realloc reallocator
 Lines 107-113   linemap_add (struct line_maps *set, enum lc_reason reason, Link Here 
107
					 * sizeof (struct line_map)));
92
					 * sizeof (struct line_map)));
108
    }
93
    }
109
94
110
  map = &set->maps[set->used];
95
  return &set->maps[set->used++];
96
}
97
98
static const struct line_map *
99
do_add (struct line_maps *set, enum lc_reason reason,
100
	unsigned int sysp, const char *to_file, linenum_type to_line,
101
	const struct line_map *previous)
102
{
103
  struct line_map *map;
104
  source_location start_location = set->highest_location + 1;
105
106
  if (set->used && start_location < set->maps[set->used - 1].start_location)
107
    abort ();
108
109
  map = new_linemap (set);
111
110
112
  if (to_file && *to_file == '\0' && reason != LC_RENAME_VERBATIM)
111
  if (to_file && *to_file == '\0' && reason != LC_RENAME_VERBATIM)
113
    to_file = "<stdin>";
112
    to_file = "<stdin>";
 Lines 129-134   linemap_add (struct line_maps *set, enum lc_reason reason, Link Here 
129
	  if (to_file == NULL)
128
	  if (to_file == NULL)
130
	    {
129
	    {
131
	      set->depth--;
130
	      set->depth--;
131
	      set->used--;
132
	      return NULL;
132
	      return NULL;
133
	    }
133
	    }
134
	  error = true;
134
	  error = true;
 Lines 138-144   linemap_add (struct line_maps *set, enum lc_reason reason, Link Here 
138
      else
138
      else
139
	{
139
	{
140
	  from = INCLUDED_FROM (set, map - 1);
140
	  from = INCLUDED_FROM (set, map - 1);
141
	  error = to_file && strcmp (from->to_file, to_file);
141
	  linemap_check_ordinary (from);
142
	  error = to_file && strcmp (from->d.ordinary.to_file, to_file);
142
	}
143
	}
143
144
144
      /* Depending upon whether we are handling preprocessed input or
145
      /* Depending upon whether we are handling preprocessed input or
 Lines 150-190   linemap_add (struct line_maps *set, enum lc_reason reason, Link Here 
150
      /* A TO_FILE of NULL is special - we use the natural values.  */
151
      /* A TO_FILE of NULL is special - we use the natural values.  */
151
      if (error || to_file == NULL)
152
      if (error || to_file == NULL)
152
	{
153
	{
153
	  to_file = from->to_file;
154
	  linemap_check_ordinary (from);
155
	  to_file = from->d.ordinary.to_file;
154
	  to_line = SOURCE_LINE (from, from[1].start_location);
156
	  to_line = SOURCE_LINE (from, from[1].start_location);
155
	  sysp = from->sysp;
157
	  sysp = from->d.ordinary.sysp;
156
	}
158
	}
157
    }
159
    }
158
160
161
  linemap_assert (reason != LC_ENTER_MACRO);
159
  map->reason = reason;
162
  map->reason = reason;
160
  map->sysp = sysp;
163
  map->d.ordinary.sysp = sysp;
161
  map->start_location = start_location;
164
  map->start_location = start_location;
162
  map->to_file = to_file;
165
  map->d.ordinary.to_file = to_file;
163
  map->to_line = to_line;
166
  map->d.ordinary.to_line = to_line;
164
  set->cache = set->used++;
167
  set->cache = set->used - 1;
165
  map->column_bits = 0;
168
  map->d.ordinary.column_bits = 0;
166
  set->highest_location = start_location;
169
  set->highest_location = start_location;
167
  set->highest_line = start_location;
170
  set->highest_line = start_location;
168
  set->max_column_hint = 0;
171
  set->max_column_hint = 0;
169
172
170
  if (reason == LC_ENTER)
173
  if (reason == LC_ENTER)
171
    {
174
    {
172
      map->included_from = set->depth == 0 ? -1 : (int) (set->used - 2);
175
      map->d.ordinary.included_from
176
	= set->depth == 0 ? -1 : (int) (set->used - 2);
173
      set->depth++;
177
      set->depth++;
174
      if (set->trace_includes)
178
      if (set->trace_includes)
175
	trace_include (set, map);
179
	trace_include (set, map);
176
    }
180
    }
177
  else if (reason == LC_RENAME)
181
  else if (reason == LC_RENAME)
178
    map->included_from = map[-1].included_from;
182
    {
183
      if (previous == NULL)
184
	previous = &map[-1];
185
      linemap_check_ordinary (previous);
186
      map->d.ordinary.included_from = previous->d.ordinary.included_from;
187
    }
179
  else if (reason == LC_LEAVE)
188
  else if (reason == LC_LEAVE)
180
    {
189
    {
181
      set->depth--;
190
      set->depth--;
182
      map->included_from = INCLUDED_FROM (set, map - 1)->included_from;
191
      map->d.ordinary.included_from
192
	= INCLUDED_FROM (set, map - 1)->d.ordinary.included_from;
183
    }
193
    }
184
194
185
  return map;
195
  return map;
186
}
196
}
187
197
198
/* Add a mapping of logical source line to physical source file and
199
   line number.
200
201
   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
203
   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
205
   natural values considering the file we are returning to.
206
207
   FROM_LINE should be monotonic increasing across calls to this
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.  */
210
211
const struct line_map *
212
linemap_add (struct line_maps *set, enum lc_reason reason,
213
	     unsigned int sysp, const char *to_file, linenum_type to_line)
214
{
215
  return do_add (set, reason, sysp, to_file, to_line, NULL);
216
}
217
218
const struct line_map *
219
linemap_enter_macro (struct line_maps *set, void *macro,
220
		     source_location expansion, unsigned int num_tokens)
221
{
222
  struct line_map *map;
223
  source_location start_location = set->highest_location + 1;
224
  line_map_realloc reallocator
225
    = set->reallocator ? set->reallocator : xrealloc;
226
227
  map = new_linemap (set);
228
229
  map->start_location = start_location;
230
  map->reason = LC_ENTER_MACRO;
231
  map->d.macro.macro = macro;
232
  map->d.macro.n_tokens = num_tokens;
233
  map->d.macro.macro_locations
234
    = reallocator (NULL, 2 * num_tokens * sizeof (source_location));
235
  map->d.macro.expansion = expansion;
236
  memset (map->d.macro.macro_locations, 0,
237
	  num_tokens * sizeof (source_location));
238
239
  set->cache = set->used - 1;
240
  set->max_column_hint = 0;
241
  set->highest_location = start_location + num_tokens;
242
  set->highest_line = start_location + num_tokens;
243
244
  return map;
245
}
246
247
source_location
248
linemap_add_macro_token (const struct line_map *map,
249
			 unsigned int token_no,
250
			 source_location orig,
251
			 source_location other /* FIXME name */)
252
{
253
  linemap_assert (map->reason == LC_ENTER_MACRO);
254
  map->d.macro.macro_locations[2 * token_no] = orig;
255
  map->d.macro.macro_locations[2 * token_no + 1] = other;
256
  return map->start_location + token_no;
257
}
258
259
static const struct line_map *
260
find_macro_base (struct line_maps *set, source_location loc, int expansion)
261
{
262
  while (1)
263
    {
264
      const struct line_map *map;
265
      map = linemap_lookup (set, loc);
266
      if (map->reason != LC_ENTER_MACRO)
267
	return map;
268
      if (expansion)
269
	loc = map->d.macro.expansion;
270
      else
271
	loc = map->d.macro.macro_locations[2 * (loc - map->start_location)];
272
    }
273
}
274
275
void
276
linemap_leave_macro (struct line_maps *set, source_location paren_loc)
277
{
278
  const struct line_map *base, *paren;
279
280
  linemap_assert (set->maps[set->used - 1].reason == LC_ENTER_MACRO);
281
282
/*   base = find_macro_base (set, set->maps[set->used - 1].d.macro.expansion, 1); */
283
  base = &set->maps[set->used - 2];
284
  linemap_assert (base->reason != LC_ENTER_MACRO);
285
286
  linemap_assert (base->reason != LC_ENTER_MACRO);
287
  paren = find_macro_base (set, paren_loc, 0);
288
  do_add (set, LC_RENAME, base->d.ordinary.sysp,
289
	  base->d.ordinary.to_file, SOURCE_LINE (paren, paren_loc), base);
290
}
291
188
source_location
292
source_location
189
linemap_line_start (struct line_maps *set, linenum_type to_line,
293
linemap_line_start (struct line_maps *set, linenum_type to_line,
190
		    unsigned int max_column_hint)
294
		    unsigned int max_column_hint)
 Lines 195-204   linemap_line_start (struct line_maps *set, linenum_type to_line, Link Here 
195
  linenum_type last_line = SOURCE_LINE (map, set->highest_line);
299
  linenum_type last_line = SOURCE_LINE (map, set->highest_line);
196
  int line_delta = to_line - last_line;
300
  int line_delta = to_line - last_line;
197
  bool add_map = false;
301
  bool add_map = false;
302
303
  linemap_check_ordinary (map);
304
198
  if (line_delta < 0
305
  if (line_delta < 0
199
      || (line_delta > 10 && line_delta * map->column_bits > 1000)
306
      || (line_delta > 10 && line_delta * map->d.ordinary.column_bits > 1000)
200
      || (max_column_hint >= (1U << map->column_bits))
307
      || (max_column_hint >= (1U << map->d.ordinary.column_bits))
201
      || (max_column_hint <= 80 && map->column_bits >= 10))
308
      || (max_column_hint <= 80 && map->d.ordinary.column_bits >= 10))
202
    {
309
    {
203
      add_map = true;
310
      add_map = true;
204
    }
311
    }
 Lines 226-241   linemap_line_start (struct line_maps *set, linenum_type to_line, Link Here 
226
      /* Allocate the new line_map.  However, if the current map only has a
333
      /* Allocate the new line_map.  However, if the current map only has a
227
	 single line we can sometimes just increase its column_bits instead. */
334
	 single line we can sometimes just increase its column_bits instead. */
228
      if (line_delta < 0
335
      if (line_delta < 0
229
	  || last_line != map->to_line
336
	  || last_line != map->d.ordinary.to_line
230
	  || SOURCE_COLUMN (map, highest) >= (1U << column_bits))
337
	  || SOURCE_COLUMN (map, highest) >= (1U << column_bits))
231
	map = (struct line_map *) linemap_add (set, LC_RENAME, map->sysp,
338
	map = (struct line_map *) linemap_add (set, LC_RENAME,
232
					       map->to_file, to_line);
339
					       map->d.ordinary.sysp,
233
      map->column_bits = column_bits;
340
					       map->d.ordinary.to_file,
234
      r = map->start_location + ((to_line - map->to_line) << column_bits);
341
					       to_line);
342
      map->d.ordinary.column_bits = column_bits;
343
      r = map->start_location + ((to_line - map->d.ordinary.to_line)
344
				 << column_bits);
235
    }
345
    }
236
  else
346
  else
237
    r = highest - SOURCE_COLUMN (map, highest)
347
    r = highest - SOURCE_COLUMN (map, highest)
238
      + (line_delta << map->column_bits);
348
      + (line_delta << map->d.ordinary.column_bits);
239
  set->highest_line = r;
349
  set->highest_line = r;
240
  if (r > set->highest_location)
350
  if (r > set->highest_location)
241
    set->highest_location = r;
351
    set->highest_location = r;
 Lines 247-252   source_location Link Here 
247
linemap_position_for_column (struct line_maps *set, unsigned int to_column)
357
linemap_position_for_column (struct line_maps *set, unsigned int to_column)
248
{
358
{
249
  source_location r = set->highest_line;
359
  source_location r = set->highest_line;
360
361
  linemap_assert (set->maps[set->used - 1].reason != LC_ENTER_MACRO);
362
250
  if (to_column >= set->max_column_hint)
363
  if (to_column >= set->max_column_hint)
251
    {
364
    {
252
      if (r >= 0xC000000 || to_column > 100000)
365
      if (r >= 0xC000000 || to_column > 100000)
 Lines 306-311   linemap_lookup (struct line_maps *set, source_location line) Link Here 
306
  return &set->maps[mn];
419
  return &set->maps[mn];
307
}
420
}
308
421
422
int
423
linemap_check_ordinary (const struct line_map *map)
424
{
425
  linemap_assert (map->reason != LC_ENTER_MACRO);
426
  /* Return any old value.  */
427
  return 0;
428
}
429
309
/* Print an include trace, for e.g. the -H option of the preprocessor.  */
430
/* Print an include trace, for e.g. the -H option of the preprocessor.  */
310
431
311
static void
432
static void
 Lines 315-319   trace_include (const struct line_maps *set, const struct line_map *map) Link Here 
315
436
316
  while (--i)
437
  while (--i)
317
    putc ('.', stderr);
438
    putc ('.', stderr);
318
  fprintf (stderr, " %s\n", map->to_file);
439
  linemap_check_ordinary (map);
440
  fprintf (stderr, " %s\n", map->d.ordinary.to_file);
441
}
442
443
expanded_location
444
linemap_expand_location (struct line_maps *set, source_location loc)
445
{
446
  expanded_location xloc;
447
  if (loc == 0)
448
    {
449
      xloc.file = NULL;
450
      xloc.line = 0;
451
      xloc.column = 0;
452
      xloc.sysp = 0;
453
    }
454
  else
455
    {
456
      const struct line_map *map;
457
      while (1)
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);
473
      xloc.line = SOURCE_LINE (map, loc);
474
      xloc.column = SOURCE_COLUMN (map, loc);
475
      xloc.sysp = LINEMAP_SYSP (map) != 0;
476
    }
477
  return xloc;
319
}
478
}
(-)a/libcpp/macro.c (-57 / +79 lines)
 Lines 47-53   static int builtin_macro (cpp_reader *, cpp_hashnode *); Link Here 
47
static void push_ptoken_context (cpp_reader *, cpp_hashnode *, _cpp_buff *,
47
static void push_ptoken_context (cpp_reader *, cpp_hashnode *, _cpp_buff *,
48
				 const cpp_token **, unsigned int);
48
				 const cpp_token **, unsigned int);
49
static _cpp_buff *collect_args (cpp_reader *, const cpp_hashnode *,
49
static _cpp_buff *collect_args (cpp_reader *, const cpp_hashnode *,
50
				_cpp_buff **);
50
				_cpp_buff **, source_location *);
51
static cpp_context *next_context (cpp_reader *);
51
static cpp_context *next_context (cpp_reader *);
52
static const cpp_token *padding_token (cpp_reader *, const cpp_token *);
52
static const cpp_token *padding_token (cpp_reader *, const cpp_token *);
53
static void expand_arg (cpp_reader *, macro_arg *);
53
static void expand_arg (cpp_reader *, macro_arg *);
 Lines 56-64   static const cpp_token *stringify_arg (cpp_reader *, macro_arg *); Link Here 
56
static void paste_all_tokens (cpp_reader *, const cpp_token *);
56
static void paste_all_tokens (cpp_reader *, const cpp_token *);
57
static bool paste_tokens (cpp_reader *, const cpp_token **, const cpp_token *);
57
static bool paste_tokens (cpp_reader *, const cpp_token **, const cpp_token *);
58
static void replace_args (cpp_reader *, cpp_hashnode *, cpp_macro *,
58
static void replace_args (cpp_reader *, cpp_hashnode *, cpp_macro *,
59
			  macro_arg *);
59
			  macro_arg *, source_location, source_location);
60
static _cpp_buff *funlike_invocation_p (cpp_reader *, cpp_hashnode *,
60
static _cpp_buff *funlike_invocation_p (cpp_reader *, cpp_hashnode *,
61
					_cpp_buff **);
61
					_cpp_buff **, source_location *);
62
static bool create_iso_definition (cpp_reader *, cpp_macro *);
62
static bool create_iso_definition (cpp_reader *, cpp_macro *);
63
63
64
/* #define directive parsing and handling.  */
64
/* #define directive parsing and handling.  */
 Lines 177-183   _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node) Link Here 
177
	  while (! MAIN_FILE_P (map))
177
	  while (! MAIN_FILE_P (map))
178
	    map = INCLUDED_FROM (pfile->line_table, map);
178
	    map = INCLUDED_FROM (pfile->line_table, map);
179
179
180
	name = map->to_file;
180
	linemap_check_ordinary (map);
181
	name = map->d.ordinary.to_file;
181
	len = strlen (name);
182
	len = strlen (name);
182
	buf = _cpp_unaligned_alloc (pfile, len * 2 + 3);
183
	buf = _cpp_unaligned_alloc (pfile, len * 2 + 3);
183
	result = buf;
184
	result = buf;
 Lines 587-593   _cpp_arguments_ok (cpp_reader *pfile, cpp_macro *macro, const cpp_hashnode *node Link Here 
587
   CPP_PRAGMA ... CPP_PRAGMA_EOL tokens into *PRAGMA_BUFF buffer.  */
588
   CPP_PRAGMA ... CPP_PRAGMA_EOL tokens into *PRAGMA_BUFF buffer.  */
588
static _cpp_buff *
589
static _cpp_buff *
589
collect_args (cpp_reader *pfile, const cpp_hashnode *node,
590
collect_args (cpp_reader *pfile, const cpp_hashnode *node,
590
	      _cpp_buff **pragma_buff)
591
	      _cpp_buff **pragma_buff, source_location *paren_loc)
591
{
592
{
592
  _cpp_buff *buff, *base_buff;
593
  _cpp_buff *buff, *base_buff;
593
  cpp_macro *macro;
594
  cpp_macro *macro;
 Lines 736-741   collect_args (cpp_reader *pfile, const cpp_hashnode *node, Link Here 
736
    }
737
    }
737
  else
738
  else
738
    {
739
    {
740
      *paren_loc = token->src_loc;
739
      /* A single empty argument is counted as no argument.  */
741
      /* A single empty argument is counted as no argument.  */
740
      if (argc == 1 && macro->paramc == 0 && args[0].count == 0)
742
      if (argc == 1 && macro->paramc == 0 && args[0].count == 0)
741
	argc = 0;
743
	argc = 0;
 Lines 768-774   collect_args (cpp_reader *pfile, const cpp_hashnode *node, Link Here 
768
   argument is the same as in collect_args.  */
770
   argument is the same as in collect_args.  */
769
static _cpp_buff *
771
static _cpp_buff *
770
funlike_invocation_p (cpp_reader *pfile, cpp_hashnode *node,
772
funlike_invocation_p (cpp_reader *pfile, cpp_hashnode *node,
771
		      _cpp_buff **pragma_buff)
773
		      _cpp_buff **pragma_buff, source_location *paren_loc)
772
{
774
{
773
  const cpp_token *token, *padding = NULL;
775
  const cpp_token *token, *padding = NULL;
774
776
 Lines 785-791   funlike_invocation_p (cpp_reader *pfile, cpp_hashnode *node, Link Here 
785
  if (token->type == CPP_OPEN_PAREN)
787
  if (token->type == CPP_OPEN_PAREN)
786
    {
788
    {
787
      pfile->state.parsing_args = 2;
789
      pfile->state.parsing_args = 2;
788
      return collect_args (pfile, node, pragma_buff);
790
      return collect_args (pfile, node, pragma_buff, paren_loc);
789
    }
791
    }
790
792
791
  /* CPP_EOF can be the end of macro arguments, or the end of the
793
  /* CPP_EOF can be the end of macro arguments, or the end of the
 Lines 844-849   enter_macro_context (cpp_reader *pfile, cpp_hashnode *node, Link Here 
844
    {
846
    {
845
      cpp_macro *macro = node->value.macro;
847
      cpp_macro *macro = node->value.macro;
846
      _cpp_buff *pragma_buff = NULL;
848
      _cpp_buff *pragma_buff = NULL;
849
      source_location paren_loc = result->src_loc;
847
850
848
      if (macro->fun_like)
851
      if (macro->fun_like)
849
	{
852
	{
 Lines 852-858   enter_macro_context (cpp_reader *pfile, cpp_hashnode *node, Link Here 
852
	  pfile->state.prevent_expansion++;
855
	  pfile->state.prevent_expansion++;
853
	  pfile->keep_tokens++;
856
	  pfile->keep_tokens++;
854
	  pfile->state.parsing_args = 1;
857
	  pfile->state.parsing_args = 1;
855
	  buff = funlike_invocation_p (pfile, node, &pragma_buff);
858
	  buff = funlike_invocation_p (pfile, node, &pragma_buff,
859
				       &paren_loc);
856
	  pfile->state.parsing_args = 0;
860
	  pfile->state.parsing_args = 0;
857
	  pfile->keep_tokens--;
861
	  pfile->keep_tokens--;
858
	  pfile->state.prevent_expansion--;
862
	  pfile->state.prevent_expansion--;
 Lines 871-877   enter_macro_context (cpp_reader *pfile, cpp_hashnode *node, Link Here 
871
	    }
875
	    }
872
876
873
	  if (macro->paramc > 0)
877
	  if (macro->paramc > 0)
874
	    replace_args (pfile, node, macro, (macro_arg *) buff->base);
878
	    replace_args (pfile, node, macro, (macro_arg *) buff->base,
879
			  result->src_loc, paren_loc);
875
	  _cpp_release_buff (pfile, buff);
880
	  _cpp_release_buff (pfile, buff);
876
	}
881
	}
877
882
 Lines 891-898   enter_macro_context (cpp_reader *pfile, cpp_hashnode *node, Link Here 
891
      macro->used = 1;
896
      macro->used = 1;
892
897
893
      if (macro->paramc == 0)
898
      if (macro->paramc == 0)
894
	_cpp_push_token_context (pfile, node, macro->exp.tokens,
899
	{
895
				 macro_real_token_count (macro));
900
	  unsigned int i, count = macro_real_token_count (macro);
901
	  _cpp_buff *buff = _cpp_get_buff (pfile,
902
					   count * sizeof (cpp_token));
903
	  const cpp_token *src = macro->exp.tokens;
904
	  cpp_token *first = (cpp_token *) buff->base;
905
	  cpp_token *dest = first;
906
	  const struct line_map *map
907
	    = linemap_enter_macro (pfile->line_table, macro,
908
				   result->src_loc, count);
909
	  for (i = 0; i < count; ++i)
910
	    {
911
	      *dest = *src;
912
	      dest->src_loc = linemap_add_macro_token (map, i,
913
						       dest->src_loc,
914
						       dest->src_loc);
915
	      ++dest;
916
	      ++src;
917
	    }
918
	  linemap_leave_macro (pfile->line_table, paren_loc);
919
	  /* FIXME freeing  */
920
	  _cpp_push_token_context (pfile, node, first, count);
921
	}
896
922
897
      if (pragma_buff)
923
      if (pragma_buff)
898
	{
924
	{
 Lines 925-938   enter_macro_context (cpp_reader *pfile, cpp_hashnode *node, Link Here 
925
   Expand each argument before replacing, unless it is operated upon
951
   Expand each argument before replacing, unless it is operated upon
926
   by the # or ## operators.  */
952
   by the # or ## operators.  */
927
static void
953
static void
928
replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro, macro_arg *args)
954
replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro,
955
	      macro_arg *args, source_location macro_loc,
956
	      source_location paren_loc)
929
{
957
{
930
  unsigned int i, total;
958
  unsigned int i, total;
931
  const cpp_token *src, *limit;
959
  const cpp_token *src, *limit;
932
  const cpp_token **dest, **first;
960
  cpp_token *dest, *first;
933
  macro_arg *arg;
961
  macro_arg *arg;
934
  _cpp_buff *buff;
962
  _cpp_buff *buff;
935
  unsigned int count;
963
  unsigned int count;
964
  const struct line_map *map;
936
965
937
  /* First, fully macro-expand arguments, calculating the number of
966
  /* First, fully macro-expand arguments, calculating the number of
938
     tokens in the final expansion as we go.  The ordering of the if
967
     tokens in the final expansion as we go.  The ordering of the if
 Lines 970-987   replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro, macro_arg Link Here 
970
999
971
  /* Now allocate space for the expansion, copy the tokens and replace
1000
  /* Now allocate space for the expansion, copy the tokens and replace
972
     the arguments.  */
1001
     the arguments.  */
973
  buff = _cpp_get_buff (pfile, total * sizeof (cpp_token *));
1002
  buff = _cpp_get_buff (pfile, total * sizeof (cpp_token));
974
  first = (const cpp_token **) buff->base;
1003
  first = (cpp_token *) buff->base;
975
  dest = first;
1004
  dest = first;
976
1005
977
  for (src = macro->exp.tokens; src < limit; src++)
1006
  map = linemap_enter_macro (pfile->line_table, macro, macro_loc, total);
1007
  i = 0;
1008
  for (src = macro->exp.tokens; src < limit; src++, i++)
978
    {
1009
    {
979
      unsigned int count;
1010
      unsigned int count;
980
      const cpp_token **from, **paste_flag;
1011
      const cpp_token **from;
1012
      cpp_token *paste_flag;
981
1013
982
      if (src->type != CPP_MACRO_ARG)
1014
      if (src->type != CPP_MACRO_ARG)
983
	{
1015
	{
984
	  *dest++ = src;
1016
	  *dest = *src;
1017
	  dest->src_loc = linemap_add_macro_token (map, i, dest->src_loc,
1018
						   dest->src_loc);
1019
	  ++dest;
985
	  continue;
1020
	  continue;
986
	}
1021
	}
987
1022
 Lines 996-1002   replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro, macro_arg Link Here 
996
	  count = arg->count, from = arg->first;
1031
	  count = arg->count, from = arg->first;
997
	  if (dest != first)
1032
	  if (dest != first)
998
	    {
1033
	    {
999
	      if (dest[-1]->type == CPP_COMMA
1034
	      if (dest[-1].type == CPP_COMMA
1000
		  && macro->variadic
1035
		  && macro->variadic
1001
		  && src->val.macro_arg.arg_no == macro->paramc)
1036
		  && src->val.macro_arg.arg_no == macro->paramc)
1002
		{
1037
		{
 Lines 1018-1029   replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro, macro_arg Link Here 
1018
      /* Padding on the left of an argument (unless RHS of ##).  */
1053
      /* Padding on the left of an argument (unless RHS of ##).  */
1019
      if ((!pfile->state.in_directive || pfile->state.directive_wants_padding)
1054
      if ((!pfile->state.in_directive || pfile->state.directive_wants_padding)
1020
	  && src != macro->exp.tokens && !(src[-1].flags & PASTE_LEFT))
1055
	  && src != macro->exp.tokens && !(src[-1].flags & PASTE_LEFT))
1021
	*dest++ = padding_token (pfile, src);
1056
	{
1057
	  *dest = *padding_token (pfile, src);
1058
	  dest->src_loc = linemap_add_macro_token (map, i, dest->src_loc,
1059
						   dest->src_loc);
1060
	  ++dest;
1061
	}
1022
1062
1023
      if (count)
1063
      if (count)
1024
	{
1064
	{
1025
	  memcpy (dest, from, count * sizeof (cpp_token *));
1065
	  unsigned int j;
1026
	  dest += count;
1066
	  for (j = 0; j < count; ++j)
1067
	    {
1068
	      *dest = *from[j];
1069
	      dest->src_loc = linemap_add_macro_token (map, i, dest->src_loc,
1070
						       src->src_loc);
1071
	      ++dest;
1072
	    }
1027
1073
1028
	  /* With a non-empty argument on the LHS of ##, the last
1074
	  /* With a non-empty argument on the LHS of ##, the last
1029
	     token should be flagged PASTE_LEFT.  */
1075
	     token should be flagged PASTE_LEFT.  */
 Lines 1044-1071   replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro, macro_arg Link Here 
1044
1090
1045
      /* Avoid paste on RHS (even case count == 0).  */
1091
      /* Avoid paste on RHS (even case count == 0).  */
1046
      if (!pfile->state.in_directive && !(src->flags & PASTE_LEFT))
1092
      if (!pfile->state.in_directive && !(src->flags & PASTE_LEFT))
1047
	*dest++ = &pfile->avoid_paste;
1093
	{
1094
	  *dest = pfile->avoid_paste;
1095
	  /* Don't bother changing the location here.  */
1096
	  ++dest;
1097
	}
1048
1098
1049
      /* Add a new paste flag, or remove an unwanted one.  */
1099
      /* Add a new paste flag, or remove an unwanted one.  */
1050
      if (paste_flag)
1100
      if (paste_flag)
1051
	{
1101
	{
1052
	  cpp_token *token = _cpp_temp_token (pfile);
1053
	  token->type = (*paste_flag)->type;
1054
	  token->val = (*paste_flag)->val;
1055
	  if (src->flags & PASTE_LEFT)
1102
	  if (src->flags & PASTE_LEFT)
1056
	    token->flags = (*paste_flag)->flags | PASTE_LEFT;
1103
	    paste_flag->flags |= PASTE_LEFT;
1057
	  else
1104
	  else
1058
	    token->flags = (*paste_flag)->flags & ~PASTE_LEFT;
1105
	    paste_flag->flags &= ~PASTE_LEFT;
1059
	  *paste_flag = token;
1060
	}
1106
	}
1061
    }
1107
    }
1108
  linemap_leave_macro (pfile->line_table, paren_loc);
1062
1109
1063
  /* Free the expanded arguments.  */
1110
  /* Free the expanded arguments.  */
1064
  for (i = 0; i < macro->paramc; i++)
1111
  for (i = 0; i < macro->paramc; i++)
1065
    if (args[i].expanded)
1112
    if (args[i].expanded)
1066
      free (args[i].expanded);
1113
      free (args[i].expanded);
1067
1114
1068
  push_ptoken_context (pfile, node, buff, first, dest - first);
1115
  /* FIXME: doesn't handle BUFF */
1116
  _cpp_push_token_context (pfile, node, first, dest - first);
1069
}
1117
}
1070
1118
1071
/* Return a special padding token, with padding inherited from SOURCE.  */
1119
/* Return a special padding token, with padding inherited from SOURCE.  */
 Lines 1225-1232   const cpp_token * Link Here 
1225
cpp_get_token (cpp_reader *pfile)
1273
cpp_get_token (cpp_reader *pfile)
1226
{
1274
{
1227
  const cpp_token *result;
1275
  const cpp_token *result;
1228
  bool can_set = pfile->set_invocation_location;
1229
  pfile->set_invocation_location = false;
1230
1276
1231
  for (;;)
1277
  for (;;)
1232
    {
1278
    {
 Lines 1273-1282   cpp_get_token (cpp_reader *pfile) Link Here 
1273
      if (!(node->flags & NODE_DISABLED))
1319
      if (!(node->flags & NODE_DISABLED))
1274
	{
1320
	{
1275
	  int ret = 0;
1321
	  int ret = 0;
1276
	  /* If not in a macro context, and we're going to start an
1277
	     expansion, record the location.  */
1278
	  if (can_set && !context->macro)
1279
	    pfile->invocation_location = result->src_loc;
1280
	  if (pfile->state.prevent_expansion)
1322
	  if (pfile->state.prevent_expansion)
1281
	    break;
1323
	    break;
1282
1324
 Lines 1335-1361   cpp_get_token (cpp_reader *pfile) Link Here 
1335
  return result;
1377
  return result;
1336
}
1378
}
1337
1379
1338
/* Like cpp_get_token, but also returns a location separate from the
1339
   one provided by the returned token.  LOC is an out parameter; *LOC
1340
   is set to the location "as expected by the user".  This matters
1341
   when a token results from macro expansion -- the token's location
1342
   will indicate where the macro is defined, but *LOC will be the
1343
   location of the start of the expansion.  */
1344
const cpp_token *
1345
cpp_get_token_with_location (cpp_reader *pfile, source_location *loc)
1346
{
1347
  const cpp_token *result;
1348
1349
  pfile->set_invocation_location = true;
1350
  result = cpp_get_token (pfile);
1351
  if (pfile->context->macro)
1352
    *loc = pfile->invocation_location;
1353
  else
1354
    *loc = result->src_loc;
1355
1356
  return result;
1357
}
1358
1359
/* Returns true if we're expanding an object-like macro that was
1380
/* Returns true if we're expanding an object-like macro that was
1360
   defined in a system header.  Just checks the macro at the top of
1381
   defined in a system header.  Just checks the macro at the top of
1361
   the stack.  Used for diagnostic suppression.  */
1382
   the stack.  Used for diagnostic suppression.  */
 Lines 1851-1856   _cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node) Link Here 
1851
      (sizeof (cpp_macro));
1872
      (sizeof (cpp_macro));
1852
  else
1873
  else
1853
    macro = (cpp_macro *) _cpp_aligned_alloc (pfile, sizeof (cpp_macro));
1874
    macro = (cpp_macro *) _cpp_aligned_alloc (pfile, sizeof (cpp_macro));
1875
  macro->name = node;
1854
  macro->line = pfile->directive_line;
1876
  macro->line = pfile->directive_line;
1855
  macro->params = 0;
1877
  macro->params = 0;
1856
  macro->paramc = 0;
1878
  macro->paramc = 0;

Return to bug 7263