User account creation filtered due to spam.

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

Collapse All | Expand All

(-)gcc/c-lex.c (-8 / +8 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
   Free Software Foundation, Inc.
4
   Free Software Foundation, Inc.
5
5
6
This file is part of GCC.
6
This file is part of GCC.
Lines 211-217 Link Here
211
	    line = SOURCE_LINE (new_map - 1, included_at);
211
	    line = SOURCE_LINE (new_map - 1, included_at);
212
212
213
	  input_location = new_map->start_location;
213
	  input_location = new_map->start_location;
214
	  (*debug_hooks->start_source_file) (line, new_map->to_file);
214
	  (*debug_hooks->start_source_file) (line, LINEMAP_FILE (new_map));
215
#ifndef NO_IMPLICIT_EXTERN_C
215
#ifndef NO_IMPLICIT_EXTERN_C
216
	  if (c_header_level)
216
	  if (c_header_level)
217
	    ++c_header_level;
217
	    ++c_header_level;
Lines 235-244 Link Here
235
#endif
235
#endif
236
      input_location = new_map->start_location;
236
      input_location = new_map->start_location;
237
237
238
      (*debug_hooks->end_source_file) (new_map->to_line);
238
      (*debug_hooks->end_source_file) (LINEMAP_LINE (new_map));
239
    }
239
    }
240
240
241
  update_header_times (new_map->to_file);
241
  update_header_times (LINEMAP_FILE (new_map));
242
  input_location = new_map->start_location;
242
  input_location = new_map->start_location;
243
}
243
}
244
244
Lines 303-309 Link Here
303
303
304
  timevar_push (TV_CPP);
304
  timevar_push (TV_CPP);
305
 retry:
305
 retry:
306
  tok = cpp_get_token_with_location (parse_in, loc);
306
  tok = cpp_get_token (parse_in);
307
  *loc = tok->src_loc;
307
  type = tok->type;
308
  type = tok->type;
308
309
309
 retry_after_at:
310
 retry_after_at:
Lines 351-360 Link Here
351
      if (c_dialect_objc ())
352
      if (c_dialect_objc ())
352
	{
353
	{
353
	  location_t atloc = *loc;
354
	  location_t atloc = *loc;
354
	  location_t newloc;
355
355
356
	retry_at:
356
	retry_at:
357
	  tok = cpp_get_token_with_location (parse_in, &newloc);
357
	  tok = cpp_get_token (parse_in);
358
	  type = tok->type;
358
	  type = tok->type;
359
	  switch (type)
359
	  switch (type)
360
	    {
360
	    {
Lines 380-386 Link Here
380
	    default:
380
	    default:
381
	      /* ... or not.  */
381
	      /* ... or not.  */
382
	      error ("%Hstray %<@%> in program", &atloc);
382
	      error ("%Hstray %<@%> in program", &atloc);
383
	      *loc = newloc;
383
	      *loc = tok->src_loc;
384
	      goto retry_after_at;
384
	      goto retry_after_at;
385
	    }
385
	    }
386
	  break;
386
	  break;
(-)gcc/tree.c (-22 lines)
Lines 3599-3626 Link Here
3599
  return block;
3599
  return block;
3600
}
3600
}
3601
3601
3602
expanded_location
3603
expand_location (source_location loc)
3604
{
3605
  expanded_location xloc;
3606
  if (loc == 0)
3607
    {
3608
      xloc.file = NULL;
3609
      xloc.line = 0;
3610
      xloc.column = 0;
3611
      xloc.sysp = 0;
3612
    }
3613
  else
3614
    {
3615
      const struct line_map *map = linemap_lookup (line_table, loc);
3616
      xloc.file = map->to_file;
3617
      xloc.line = SOURCE_LINE (map, loc);
3618
      xloc.column = SOURCE_COLUMN (map, loc);
3619
      xloc.sysp = map->sysp != 0;
3620
    };
3621
  return xloc;
3622
}
3623
3624
3602
3625
/* Source location accessor functions.  */
3603
/* Source location accessor functions.  */
3626
3604
(-)gcc/diagnostic.c (-7 / +27 lines)
Lines 41-46 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 219-230 Link Here
219
diagnostic_report_current_function (diagnostic_context *context,
220
diagnostic_report_current_function (diagnostic_context *context,
220
				    diagnostic_info *diagnostic)
221
				    diagnostic_info *diagnostic)
221
{
222
{
222
  diagnostic_report_current_module (context);
223
  diagnostic_report_current_module (context, diagnostic->location);
223
  lang_hooks.print_error_function (context, input_filename, diagnostic);
224
  lang_hooks.print_error_function (context, input_filename, diagnostic);
224
}
225
}
225
226
226
void
227
void
227
diagnostic_report_current_module (diagnostic_context *context)
228
diagnostic_report_current_module (diagnostic_context *context, location_t where)
228
{
229
{
229
  const struct line_map *map;
230
  const struct line_map *map;
230
231
Lines 234-264 Link Here
234
      pp_needs_newline (context->printer) = false;
235
      pp_needs_newline (context->printer) = false;
235
    }
236
    }
236
237
237
  if (input_location <= BUILTINS_LOCATION)
238
  if (where <= BUILTINS_LOCATION)
238
    return;
239
    return;
239
240
240
  map = linemap_lookup (line_table, input_location);
241
  map = linemap_lookup (line_table, where);
241
  if (map && diagnostic_last_module_changed (context, map))
242
  if (map && diagnostic_last_module_changed (context, map))
242
    {
243
    {
244
      struct line_map *macro_map;
245
243
      diagnostic_set_last_module (context, map);
246
      diagnostic_set_last_module (context, map);
247
      for (macro_map = map; macro_map->reason == LC_ENTER_MACRO; )
248
 	{
249
 	  expanded_location loc;
250
 	  source_location l2 = where - macro_map->start_location;
251
 	  where = macro_map->d.macro.macro_locations[2 * l2 + 1];
252
 	  loc = expand_location (where);
253
 	  pp_verbatim (context->printer,
254
 		       "While expanding macro %s at %s:%d:%d",
255
 		       LINEMAP_MACRO_NAME (macro_map),
256
		       loc.file, loc.line, loc.column);
257
	  pp_newline (context->printer);
258
 	  macro_map = linemap_lookup (line_table, where);
259
 	}
260
261
      while (map->reason == LC_ENTER_MACRO)
262
 	map = linemap_lookup (line_table, map->d.macro.expansion);
263
244
      if (! MAIN_FILE_P (map))
264
      if (! MAIN_FILE_P (map))
245
	{
265
	{
246
	  map = INCLUDED_FROM (line_table, map);
266
	  map = INCLUDED_FROM (line_table, map);
247
	  if (flag_show_column)
267
	  if (flag_show_column)
248
	    pp_verbatim (context->printer,
268
	    pp_verbatim (context->printer,
249
			 "In file included from %s:%d:%d",
269
			 "In file included from %s:%d:%d",
250
			 map->to_file,
270
			 LINEMAP_FILE (map),
251
			 LAST_SOURCE_LINE (map), LAST_SOURCE_COLUMN (map));
271
			 LAST_SOURCE_LINE (map), LAST_SOURCE_COLUMN (map));
252
	  else
272
	  else
253
	    pp_verbatim (context->printer,
273
	    pp_verbatim (context->printer,
254
			 "In file included from %s:%d",
274
			 "In file included from %s:%d",
255
			 map->to_file, LAST_SOURCE_LINE (map));
275
			 LINEMAP_FILE (map), LAST_SOURCE_LINE (map));
256
	  while (! MAIN_FILE_P (map))
276
	  while (! MAIN_FILE_P (map))
257
	    {
277
	    {
258
	      map = INCLUDED_FROM (line_table, map);
278
	      map = INCLUDED_FROM (line_table, map);
259
	      pp_verbatim (context->printer,
279
	      pp_verbatim (context->printer,
260
			   ",\n                 from %s:%d",
280
			   ",\n                 from %s:%d",
261
			   map->to_file, LAST_SOURCE_LINE (map));
281
			   LINEMAP_FILE (map), LAST_SOURCE_LINE (map));
262
	    }
282
	    }
263
	  pp_verbatim (context->printer, ":");
283
	  pp_verbatim (context->printer, ":");
264
	  pp_newline (context->printer);
284
	  pp_newline (context->printer);
(-)gcc/diagnostic.h (-1 / +2 lines)
Lines 192-198 Link Here
192
192
193
/* Diagnostic related functions.  */
193
/* Diagnostic related functions.  */
194
extern void diagnostic_initialize (diagnostic_context *);
194
extern void diagnostic_initialize (diagnostic_context *);
195
extern void diagnostic_report_current_module (diagnostic_context *);
195
extern void diagnostic_report_current_module (diagnostic_context *,
196
					      location_t);
196
extern void diagnostic_report_current_function (diagnostic_context *,
197
extern void diagnostic_report_current_function (diagnostic_context *,
197
						diagnostic_info *);
198
						diagnostic_info *);
198
199
(-)gcc/input.h (-17 / +3 lines)
Lines 1-6 Link Here
1
/* Declarations for variables relating to reading the source file.
1
/* Declarations for variables relating to reading the source file.
2
   Used by parsers, lexical analyzers, and error message routines.
2
   Used by parsers, lexical analyzers, and error message routines.
3
   Copyright (C) 1993, 1997, 1998, 2000, 2003, 2004, 2007, 2008
3
   Copyright (C) 1993, 1997, 1998, 2000, 2003, 2004, 2007, 2008, 2009
4
   Free Software Foundation, Inc.
4
   Free Software Foundation, Inc.
5
5
6
This file is part of GCC.
6
This file is part of GCC.
Lines 32-53 Link Here
32
/* The location for declarations in "<built-in>" */
32
/* The location for declarations in "<built-in>" */
33
#define BUILTINS_LOCATION ((source_location) 2)
33
#define BUILTINS_LOCATION ((source_location) 2)
34
34
35
typedef struct GTY (())
36
{
37
  /* The name of the source file involved.  */
38
  const char *file;
39
40
  /* The line-location in the source file.  */
41
  int line;
42
43
  int column;
44
45
  /* In a system header?. */
46
  bool sysp;
47
} expanded_location;
48
49
extern expanded_location expand_location (source_location);
50
51
/* Historically GCC used location_t, while cpp used source_location.
35
/* Historically GCC used location_t, while cpp used source_location.
52
   This could be removed but it hardly seems worth the effort.  */
36
   This could be removed but it hardly seems worth the effort.  */
53
typedef source_location location_t;
37
typedef source_location location_t;
Lines 65-68 Link Here
65
#define in_system_header_at(LOC) ((expand_location (LOC)).sysp != 0)
49
#define in_system_header_at(LOC) ((expand_location (LOC)).sysp != 0)
66
#define in_system_header (in_system_header_at (input_location))
50
#define in_system_header (in_system_header_at (input_location))
67
51
52
#define expand_location(LOC) linemap_expand_location (line_table, LOC)
53
68
#endif
54
#endif
(-)gcc/cp/error.c (-1 / +1 lines)
Lines 2518-2524 Link Here
2518
cp_diagnostic_starter (diagnostic_context *context,
2518
cp_diagnostic_starter (diagnostic_context *context,
2519
		       diagnostic_info *diagnostic)
2519
		       diagnostic_info *diagnostic)
2520
{
2520
{
2521
  diagnostic_report_current_module (context);
2521
  diagnostic_report_current_module (context, diagnostic->location);
2522
  cp_print_error_function (context, diagnostic);
2522
  cp_print_error_function (context, diagnostic);
2523
  maybe_print_instantiation_context (context);
2523
  maybe_print_instantiation_context (context);
2524
  pp_base_set_prefix (context->printer, diagnostic_build_prefix (diagnostic));
2524
  pp_base_set_prefix (context->printer, diagnostic_build_prefix (diagnostic));
(-)gcc/fortran/cpp.c (-7 / +11 lines)
Lines 779-804 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);
789
791
792
      print.src_line = loc.line;
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);
(-)gcc/c-ppoutput.c (-5 / +13 lines)
Lines 306-312 Link Here
306
    {
306
    {
307
      const struct line_map *map = linemap_lookup (line_table, src_loc);
307
      const struct line_map *map = linemap_lookup (line_table, src_loc);
308
308
309
      size_t to_file_len = strlen (map->to_file);
309
      size_t to_file_len = strlen (LINEMAP_FILE (map));
310
      unsigned char *to_file_quoted =
310
      unsigned char *to_file_quoted =
311
         (unsigned char *) alloca (to_file_len * 4 + 1);
311
         (unsigned char *) alloca (to_file_len * 4 + 1);
312
      unsigned char *p;
312
      unsigned char *p;
Lines 316-330 Link Here
316
      /* cpp_quote_string does not nul-terminate, so we have to do it
316
      /* cpp_quote_string does not nul-terminate, so we have to do it
317
	 ourselves.  */
317
	 ourselves.  */
318
      p = cpp_quote_string (to_file_quoted,
318
      p = cpp_quote_string (to_file_quoted,
319
			    (const unsigned char *) map->to_file, to_file_len);
319
			    (const unsigned char *) LINEMAP_FILE (map),
320
			    to_file_len);
320
      *p = '\0';
321
      *p = '\0';
321
      fprintf (print.outf, "# %u \"%s\"%s",
322
      fprintf (print.outf, "# %u \"%s\"%s",
322
	       print.src_line == 0 ? 1 : print.src_line,
323
	       print.src_line == 0 ? 1 : print.src_line,
323
	       to_file_quoted, special_flags);
324
	       to_file_quoted, special_flags);
324
325
325
      if (map->sysp == 2)
326
      if (LINEMAP_SYSP (map) == 2)
326
	fputs (" 3 4", print.outf);
327
	fputs (" 3 4", print.outf);
327
      else if (map->sysp == 1)
328
      else if (LINEMAP_SYSP (map) == 1)
328
	fputs (" 3", print.outf);
329
	fputs (" 3", print.outf);
329
330
330
      putc ('\n', print.outf);
331
      putc ('\n', print.outf);
Lines 377-382 Link Here
377
static void
378
static void
378
cb_define (cpp_reader *pfile, source_location line, cpp_hashnode *node)
379
cb_define (cpp_reader *pfile, source_location line, cpp_hashnode *node)
379
{
380
{
381
  const struct line_map *map;
382
383
  if (line <= BUILTINS_LOCATION)
384
    return;
380
  maybe_print_line (line);
385
  maybe_print_line (line);
381
  fputs ("#define ", print.outf);
386
  fputs ("#define ", print.outf);
382
387
Lines 388-394 Link Here
388
    fputs ((const char *) NODE_NAME (node), print.outf);
393
    fputs ((const char *) NODE_NAME (node), print.outf);
389
394
390
  putc ('\n', print.outf);
395
  putc ('\n', print.outf);
391
  if (linemap_lookup (line_table, line)->to_line != 0)
396
  map = linemap_lookup (line_table, line);
397
  if (LINEMAP_LINE (map) != 0)
392
    print.src_line++;
398
    print.src_line++;
393
}
399
}
394
400
Lines 396-401 Link Here
396
cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line,
402
cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line,
397
	  cpp_hashnode *node)
403
	  cpp_hashnode *node)
398
{
404
{
405
  if (line <= BUILTINS_LOCATION)
406
    return;
399
  maybe_print_line (line);
407
  maybe_print_line (line);
400
  fprintf (print.outf, "#undef %s\n", NODE_NAME (node));
408
  fprintf (print.outf, "#undef %s\n", NODE_NAME (node));
401
  print.src_line++;
409
  print.src_line++;
(-)libcpp/macro.c (-57 / +79 lines)
Lines 47-53 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 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 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 586-592 Link Here
586
   CPP_PRAGMA ... CPP_PRAGMA_EOL tokens into *PRAGMA_BUFF buffer.  */
587
   CPP_PRAGMA ... CPP_PRAGMA_EOL tokens into *PRAGMA_BUFF buffer.  */
587
static _cpp_buff *
588
static _cpp_buff *
588
collect_args (cpp_reader *pfile, const cpp_hashnode *node,
589
collect_args (cpp_reader *pfile, const cpp_hashnode *node,
589
	      _cpp_buff **pragma_buff)
590
	      _cpp_buff **pragma_buff, source_location *paren_loc)
590
{
591
{
591
  _cpp_buff *buff, *base_buff;
592
  _cpp_buff *buff, *base_buff;
592
  cpp_macro *macro;
593
  cpp_macro *macro;
Lines 735-740 Link Here
735
    }
736
    }
736
  else
737
  else
737
    {
738
    {
739
      *paren_loc = token->src_loc;
738
      /* A single empty argument is counted as no argument.  */
740
      /* A single empty argument is counted as no argument.  */
739
      if (argc == 1 && macro->paramc == 0 && args[0].count == 0)
741
      if (argc == 1 && macro->paramc == 0 && args[0].count == 0)
740
	argc = 0;
742
	argc = 0;
Lines 767-773 Link Here
767
   argument is the same as in collect_args.  */
769
   argument is the same as in collect_args.  */
768
static _cpp_buff *
770
static _cpp_buff *
769
funlike_invocation_p (cpp_reader *pfile, cpp_hashnode *node,
771
funlike_invocation_p (cpp_reader *pfile, cpp_hashnode *node,
770
		      _cpp_buff **pragma_buff)
772
		      _cpp_buff **pragma_buff, source_location *paren_loc)
771
{
773
{
772
  const cpp_token *token, *padding = NULL;
774
  const cpp_token *token, *padding = NULL;
773
775
Lines 784-790 Link Here
784
  if (token->type == CPP_OPEN_PAREN)
786
  if (token->type == CPP_OPEN_PAREN)
785
    {
787
    {
786
      pfile->state.parsing_args = 2;
788
      pfile->state.parsing_args = 2;
787
      return collect_args (pfile, node, pragma_buff);
789
      return collect_args (pfile, node, pragma_buff, paren_loc);
788
    }
790
    }
789
791
790
  /* CPP_EOF can be the end of macro arguments, or the end of the
792
  /* CPP_EOF can be the end of macro arguments, or the end of the
Lines 843-848 Link Here
843
    {
845
    {
844
      cpp_macro *macro = node->value.macro;
846
      cpp_macro *macro = node->value.macro;
845
      _cpp_buff *pragma_buff = NULL;
847
      _cpp_buff *pragma_buff = NULL;
848
      source_location paren_loc = result->src_loc;
846
849
847
      if (macro->fun_like)
850
      if (macro->fun_like)
848
	{
851
	{
Lines 851-857 Link Here
851
	  pfile->state.prevent_expansion++;
854
	  pfile->state.prevent_expansion++;
852
	  pfile->keep_tokens++;
855
	  pfile->keep_tokens++;
853
	  pfile->state.parsing_args = 1;
856
	  pfile->state.parsing_args = 1;
854
	  buff = funlike_invocation_p (pfile, node, &pragma_buff);
857
	  buff = funlike_invocation_p (pfile, node, &pragma_buff,
858
				       &paren_loc);
855
	  pfile->state.parsing_args = 0;
859
	  pfile->state.parsing_args = 0;
856
	  pfile->keep_tokens--;
860
	  pfile->keep_tokens--;
857
	  pfile->state.prevent_expansion--;
861
	  pfile->state.prevent_expansion--;
Lines 870-876 Link Here
870
	    }
874
	    }
871
875
872
	  if (macro->paramc > 0)
876
	  if (macro->paramc > 0)
873
	    replace_args (pfile, node, macro, (macro_arg *) buff->base);
877
	    replace_args (pfile, node, macro, (macro_arg *) buff->base,
878
			  result->src_loc, paren_loc);
874
	  _cpp_release_buff (pfile, buff);
879
	  _cpp_release_buff (pfile, buff);
875
	}
880
	}
876
881
Lines 887-894 Link Here
887
      macro->used = 1;
892
      macro->used = 1;
888
893
889
      if (macro->paramc == 0)
894
      if (macro->paramc == 0)
890
	_cpp_push_token_context (pfile, node, macro->exp.tokens,
895
	{
891
				 macro_real_token_count (macro));
896
	  unsigned int i, count = macro_real_token_count (macro);
897
	  _cpp_buff *buff = _cpp_get_buff (pfile,
898
					   count * sizeof (cpp_token));
899
	  const cpp_token *src = macro->exp.tokens;
900
	  cpp_token *first = (cpp_token *) buff->base;
901
	  cpp_token *dest = first;
902
	  const struct line_map *map
903
	    = linemap_enter_macro (pfile->line_table, macro,
904
				   result->src_loc, count);
905
	  for (i = 0; i < count; ++i)
906
	    {
907
	      *dest = *src;
908
	      dest->src_loc = linemap_add_macro_token (map, i,
909
						       dest->src_loc,
910
						       dest->src_loc);
911
	      ++dest;
912
	      ++src;
913
	    }
914
	  linemap_leave_macro (pfile->line_table, paren_loc);
915
	  /* FIXME freeing  */
916
	  _cpp_push_token_context (pfile, node, first, count);
917
	}
892
918
893
      if (pragma_buff)
919
      if (pragma_buff)
894
	{
920
	{
Lines 921-934 Link Here
921
   Expand each argument before replacing, unless it is operated upon
947
   Expand each argument before replacing, unless it is operated upon
922
   by the # or ## operators.  */
948
   by the # or ## operators.  */
923
static void
949
static void
924
replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro, macro_arg *args)
950
replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro,
951
	      macro_arg *args, source_location macro_loc,
952
	      source_location paren_loc)
925
{
953
{
926
  unsigned int i, total;
954
  unsigned int i, total;
927
  const cpp_token *src, *limit;
955
  const cpp_token *src, *limit;
928
  const cpp_token **dest, **first;
956
  cpp_token *dest, *first;
929
  macro_arg *arg;
957
  macro_arg *arg;
930
  _cpp_buff *buff;
958
  _cpp_buff *buff;
931
  unsigned int count;
959
  unsigned int count;
960
  const struct line_map *map;
932
961
933
  /* First, fully macro-expand arguments, calculating the number of
962
  /* First, fully macro-expand arguments, calculating the number of
934
     tokens in the final expansion as we go.  The ordering of the if
963
     tokens in the final expansion as we go.  The ordering of the if
Lines 966-983 Link Here
966
995
967
  /* Now allocate space for the expansion, copy the tokens and replace
996
  /* Now allocate space for the expansion, copy the tokens and replace
968
     the arguments.  */
997
     the arguments.  */
969
  buff = _cpp_get_buff (pfile, total * sizeof (cpp_token *));
998
  buff = _cpp_get_buff (pfile, total * sizeof (cpp_token));
970
  first = (const cpp_token **) buff->base;
999
  first = (cpp_token *) buff->base;
971
  dest = first;
1000
  dest = first;
972
1001
973
  for (src = macro->exp.tokens; src < limit; src++)
1002
  map = linemap_enter_macro (pfile->line_table, macro, macro_loc, total);
1003
  i = 0;
1004
  for (src = macro->exp.tokens; src < limit; src++, i++)
974
    {
1005
    {
975
      unsigned int count;
1006
      unsigned int count;
976
      const cpp_token **from, **paste_flag;
1007
      const cpp_token **from;
1008
      cpp_token *paste_flag;
977
1009
978
      if (src->type != CPP_MACRO_ARG)
1010
      if (src->type != CPP_MACRO_ARG)
979
	{
1011
	{
980
	  *dest++ = src;
1012
	  *dest = *src;
1013
	  dest->src_loc = linemap_add_macro_token (map, i, dest->src_loc,
1014
						   dest->src_loc);
1015
	  ++dest;
981
	  continue;
1016
	  continue;
982
	}
1017
	}
983
1018
Lines 992-998 Link Here
992
	  count = arg->count, from = arg->first;
1027
	  count = arg->count, from = arg->first;
993
	  if (dest != first)
1028
	  if (dest != first)
994
	    {
1029
	    {
995
	      if (dest[-1]->type == CPP_COMMA
1030
	      if (dest[-1].type == CPP_COMMA
996
		  && macro->variadic
1031
		  && macro->variadic
997
		  && src->val.macro_arg.arg_no == macro->paramc)
1032
		  && src->val.macro_arg.arg_no == macro->paramc)
998
		{
1033
		{
Lines 1014-1025 Link Here
1014
      /* Padding on the left of an argument (unless RHS of ##).  */
1049
      /* Padding on the left of an argument (unless RHS of ##).  */
1015
      if ((!pfile->state.in_directive || pfile->state.directive_wants_padding)
1050
      if ((!pfile->state.in_directive || pfile->state.directive_wants_padding)
1016
	  && src != macro->exp.tokens && !(src[-1].flags & PASTE_LEFT))
1051
	  && src != macro->exp.tokens && !(src[-1].flags & PASTE_LEFT))
1017
	*dest++ = padding_token (pfile, src);
1052
	{
1053
	  *dest = *padding_token (pfile, src);
1054
	  dest->src_loc = linemap_add_macro_token (map, i, dest->src_loc,
1055
						   dest->src_loc);
1056
	  ++dest;
1057
	}
1018
1058
1019
      if (count)
1059
      if (count)
1020
	{
1060
	{
1021
	  memcpy (dest, from, count * sizeof (cpp_token *));
1061
	  unsigned int j;
1022
	  dest += count;
1062
	  for (j = 0; j < count; ++j)
1063
	    {
1064
	      *dest = *from[j];
1065
	      dest->src_loc = linemap_add_macro_token (map, i, dest->src_loc,
1066
						       src->src_loc);
1067
	      ++dest;
1068
	    }
1023
1069
1024
	  /* With a non-empty argument on the LHS of ##, the last
1070
	  /* With a non-empty argument on the LHS of ##, the last
1025
	     token should be flagged PASTE_LEFT.  */
1071
	     token should be flagged PASTE_LEFT.  */
Lines 1040-1067 Link Here
1040
1086
1041
      /* Avoid paste on RHS (even case count == 0).  */
1087
      /* Avoid paste on RHS (even case count == 0).  */
1042
      if (!pfile->state.in_directive && !(src->flags & PASTE_LEFT))
1088
      if (!pfile->state.in_directive && !(src->flags & PASTE_LEFT))
1043
	*dest++ = &pfile->avoid_paste;
1089
	{
1090
	  *dest = pfile->avoid_paste;
1091
	  /* Don't bother changing the location here.  */
1092
	  ++dest;
1093
	}
1044
1094
1045
      /* Add a new paste flag, or remove an unwanted one.  */
1095
      /* Add a new paste flag, or remove an unwanted one.  */
1046
      if (paste_flag)
1096
      if (paste_flag)
1047
	{
1097
	{
1048
	  cpp_token *token = _cpp_temp_token (pfile);
1049
	  token->type = (*paste_flag)->type;
1050
	  token->val = (*paste_flag)->val;
1051
	  if (src->flags & PASTE_LEFT)
1098
	  if (src->flags & PASTE_LEFT)
1052
	    token->flags = (*paste_flag)->flags | PASTE_LEFT;
1099
	    paste_flag->flags |= PASTE_LEFT;
1053
	  else
1100
	  else
1054
	    token->flags = (*paste_flag)->flags & ~PASTE_LEFT;
1101
	    paste_flag->flags &= ~PASTE_LEFT;
1055
	  *paste_flag = token;
1056
	}
1102
	}
1057
    }
1103
    }
1104
  linemap_leave_macro (pfile->line_table, paren_loc);
1058
1105
1059
  /* Free the expanded arguments.  */
1106
  /* Free the expanded arguments.  */
1060
  for (i = 0; i < macro->paramc; i++)
1107
  for (i = 0; i < macro->paramc; i++)
1061
    if (args[i].expanded)
1108
    if (args[i].expanded)
1062
      free (args[i].expanded);
1109
      free (args[i].expanded);
1063
1110
1064
  push_ptoken_context (pfile, node, buff, first, dest - first);
1111
  /* FIXME: doesn't handle BUFF */
1112
  _cpp_push_token_context (pfile, node, first, dest - first);
1065
}
1113
}
1066
1114
1067
/* Return a special padding token, with padding inherited from SOURCE.  */
1115
/* Return a special padding token, with padding inherited from SOURCE.  */
Lines 1221-1228 Link Here
1221
cpp_get_token (cpp_reader *pfile)
1269
cpp_get_token (cpp_reader *pfile)
1222
{
1270
{
1223
  const cpp_token *result;
1271
  const cpp_token *result;
1224
  bool can_set = pfile->set_invocation_location;
1225
  pfile->set_invocation_location = false;
1226
1272
1227
  for (;;)
1273
  for (;;)
1228
    {
1274
    {
Lines 1269-1278 Link Here
1269
      if (!(node->flags & NODE_DISABLED))
1315
      if (!(node->flags & NODE_DISABLED))
1270
	{
1316
	{
1271
	  int ret = 0;
1317
	  int ret = 0;
1272
	  /* If not in a macro context, and we're going to start an
1273
	     expansion, record the location.  */
1274
	  if (can_set && !context->macro)
1275
	    pfile->invocation_location = result->src_loc;
1276
	  if (pfile->state.prevent_expansion)
1318
	  if (pfile->state.prevent_expansion)
1277
	    break;
1319
	    break;
1278
1320
Lines 1331-1357 Link Here
1331
  return result;
1373
  return result;
1332
}
1374
}
1333
1375
1334
/* Like cpp_get_token, but also returns a location separate from the
1335
   one provided by the returned token.  LOC is an out parameter; *LOC
1336
   is set to the location "as expected by the user".  This matters
1337
   when a token results from macro expansion -- the token's location
1338
   will indicate where the macro is defined, but *LOC will be the
1339
   location of the start of the expansion.  */
1340
const cpp_token *
1341
cpp_get_token_with_location (cpp_reader *pfile, source_location *loc)
1342
{
1343
  const cpp_token *result;
1344
1345
  pfile->set_invocation_location = true;
1346
  result = cpp_get_token (pfile);
1347
  if (pfile->context->macro)
1348
    *loc = pfile->invocation_location;
1349
  else
1350
    *loc = result->src_loc;
1351
1352
  return result;
1353
}
1354
1355
/* Returns true if we're expanding an object-like macro that was
1376
/* Returns true if we're expanding an object-like macro that was
1356
   defined in a system header.  Just checks the macro at the top of
1377
   defined in a system header.  Just checks the macro at the top of
1357
   the stack.  Used for diagnostic suppression.  */
1378
   the stack.  Used for diagnostic suppression.  */
Lines 1846-1851 Link Here
1846
      (sizeof (cpp_macro));
1867
      (sizeof (cpp_macro));
1847
  else
1868
  else
1848
    macro = (cpp_macro *) _cpp_aligned_alloc (pfile, sizeof (cpp_macro));
1869
    macro = (cpp_macro *) _cpp_aligned_alloc (pfile, sizeof (cpp_macro));
1870
  macro->name = node;
1849
  macro->line = pfile->directive_line;
1871
  macro->line = pfile->directive_line;
1850
  macro->params = 0;
1872
  macro->params = 0;
1851
  macro->paramc = 0;
1873
  macro->paramc = 0;
(-)libcpp/directives.c (-5 / +5 lines)
Lines 878-886 Link Here
878
  /* skip_rest_of_line() may cause line table to be realloc()ed so note down
878
  /* skip_rest_of_line() may cause line table to be realloc()ed so note down
879
     sysp right now.  */
879
     sysp right now.  */
880
880
881
  unsigned char map_sysp = map->sysp;
881
  unsigned char map_sysp = map->d.ordinary.sysp;
882
  const cpp_token *token;
882
  const cpp_token *token;
883
  const char *new_file = map->to_file;
883
  const char *new_file = map->d.ordinary.to_file;
884
  linenum_type new_lineno;
884
  linenum_type new_lineno;
885
885
886
  /* C99 raised the minimum limit on #line numbers.  */
886
  /* C99 raised the minimum limit on #line numbers.  */
Lines 937-945 Link Here
937
  const struct line_maps *line_table = pfile->line_table;
937
  const struct line_maps *line_table = pfile->line_table;
938
  const struct line_map *map = &line_table->maps[line_table->used - 1];
938
  const struct line_map *map = &line_table->maps[line_table->used - 1];
939
  const cpp_token *token;
939
  const cpp_token *token;
940
  const char *new_file = map->to_file;
940
  const char *new_file = map->d.ordinary.to_file;
941
  linenum_type new_lineno;
941
  linenum_type new_lineno;
942
  unsigned int new_sysp = map->sysp;
942
  unsigned int new_sysp = map->d.ordinary.sysp;
943
  enum lc_reason reason = LC_RENAME_VERBATIM;
943
  enum lc_reason reason = LC_RENAME_VERBATIM;
944
  int flag;
944
  int flag;
945
  bool wrapped;
945
  bool wrapped;
Lines 1027-1033 Link Here
1027
  const struct line_map *map = linemap_add (pfile->line_table, reason, sysp,
1027
  const struct line_map *map = linemap_add (pfile->line_table, reason, sysp,
1028
					    to_file, file_line);
1028
					    to_file, file_line);
1029
  if (map != NULL)
1029
  if (map != NULL)
1030
    linemap_line_start (pfile->line_table, map->to_line, 127);
1030
    linemap_line_start (pfile->line_table, map->d.ordinary.to_line, 127);
1031
1031
1032
  if (pfile->cb.file_change)
1032
  if (pfile->cb.file_change)
1033
    pfile->cb.file_change (pfile, map);
1033
    pfile->cb.file_change (pfile, map);
(-)libcpp/include/cpplib.h (-2 lines)
Lines 715-722 Link Here
715
extern int cpp_avoid_paste (cpp_reader *, const cpp_token *,
715
extern int cpp_avoid_paste (cpp_reader *, const cpp_token *,
716
			    const cpp_token *);
716
			    const cpp_token *);
717
extern const cpp_token *cpp_get_token (cpp_reader *);
717
extern const cpp_token *cpp_get_token (cpp_reader *);
718
extern const cpp_token *cpp_get_token_with_location (cpp_reader *,
719
						     source_location *);
720
extern const unsigned char *cpp_macro_definition (cpp_reader *,
718
extern const unsigned char *cpp_macro_definition (cpp_reader *,
721
						  const cpp_hashnode *);
719
						  const cpp_hashnode *);
722
extern void _cpp_backup_tokens (cpp_reader *, unsigned int);
720
extern void _cpp_backup_tokens (cpp_reader *, unsigned int);
(-)libcpp/include/line-map.h (-30 / +117 lines)
Lines 37-79 Link Here
37
   name or line number changes for neither of the above reasons
37
   name or line number changes for neither of the above reasons
38
   (e.g. a #line directive in C); LC_RENAME_VERBATIM is like LC_RENAME
38
   (e.g. a #line directive in C); LC_RENAME_VERBATIM is like LC_RENAME
39
   but a filename of "" is not specially interpreted as standard input.  */
39
   but a filename of "" is not specially interpreted as standard input.  */
40
enum lc_reason {LC_ENTER = 0, LC_LEAVE, LC_RENAME, LC_RENAME_VERBATIM};
40
enum lc_reason
41
{
42
  LC_ENTER = 0,
43
  LC_LEAVE,
44
  LC_RENAME,
45
  LC_RENAME_VERBATIM,
46
  LC_ENTER_MACRO
47
  /* stringize */
48
  /* paste */
49
};
41
50
42
/* The type of line numbers.  */
51
/* The type of line numbers.  */
43
typedef unsigned int linenum_type;
52
typedef unsigned int linenum_type;
44
53
45
/* A logical line/column number, i.e. an "index" into a line_map.  */
54
/* A logical line/column number, i.e. an "index" into a line_map.  */
46
/* Long-term, we want to use this to replace struct location_s (in input.h),
47
   and effectively typedef source_location location_t.  */
48
typedef unsigned int source_location;
55
typedef unsigned int source_location;
49
56
50
/* Memory allocation function typedef.  Works like xrealloc.  */
57
/* Memory allocation function typedef.  Works like xrealloc.  */
51
typedef void *(*line_map_realloc) (void *, size_t);
58
typedef void *(*line_map_realloc) (void *, size_t);
52
59
53
/* Physical source file TO_FILE at line TO_LINE at column 0 is represented
60
/* An ordinary line map encodes physical source locations.
61
   
62
   Physical source file TO_FILE at line TO_LINE at column 0 is represented
54
   by the logical START_LOCATION.  TO_LINE+L at column C is represented by
63
   by the logical START_LOCATION.  TO_LINE+L at column C is represented by
55
   START_LOCATION+(L*(1<<column_bits))+C, as long as C<(1<<column_bits),
64
   START_LOCATION+(L*(1<<column_bits))+C, as long as C<(1<<column_bits),
56
   and the result_location is less than the next line_map's start_location.
65
   and the result_location is less than the next line_map's start_location.
57
   (The top line is line 1 and the leftmost column is column 1; line/column 0
66
   (The top line is line 1 and the leftmost column is column 1; line/column 0
58
   means "entire file/line" or "unknown line/column" or "not applicable".)
67
   means "entire file/line" or "unknown line/column" or "not applicable".)
59
   INCLUDED_FROM is an index into the set that gives the line mapping
68
*/
60
   at whose end the current one was included.  File(s) at the bottom
69
struct GTY(()) line_map_ordinary
61
   of the include stack have this set to -1.  REASON is the reason for
70
{
62
   creation of this line map, SYSP is one for a system header, two for
63
   a C system header file that therefore needs to be extern "C"
64
   protected in C++, and zero otherwise.  */
65
struct GTY(()) line_map {
66
  const char *to_file;
71
  const char *to_file;
67
  linenum_type to_line;
72
  linenum_type to_line;
68
  source_location start_location;
73
74
  /* An index into the set that gives the line mapping at whose end
75
     the current one was included.  File(s) at the bottom of the
76
     include stack have this set to -1.  */
69
  int included_from;
77
  int included_from;
70
  ENUM_BITFIELD (lc_reason) reason : CHAR_BIT;
78
71
  /* The sysp field isn't really needed now that it's in cpp_buffer.  */
79
  /* SYSP is one for a system header, two for a C system header file
80
     that therefore needs to be extern "C" protected in C++, and zero
81
     otherwise.  This field isn't really needed now that it's in
82
     cpp_buffer.  */
72
  unsigned char sysp;
83
  unsigned char sysp;
73
  /* Number of the low-order source_location bits used for a column number.  */
84
85
  /* Number of the low-order source_location bits used for a column
86
     number.  */
74
  unsigned int column_bits : 8;
87
  unsigned int column_bits : 8;
75
};
88
};
76
89
90
struct cpp_macro;
91
92
/* A macro line map encodes locations coming from a macro expansion.
93
   
94
   Here, the offset from START_LOCATION is used to index into
95
   MACRO_LOCATIONS; this holds the original location of the token.  */
96
struct GTY(()) line_map_macro
97
{
98
  struct cpp_macro *macro;
99
  unsigned int n_tokens;
100
  source_location * GTY((length ("%h.n_tokens"))) macro_locations;
101
  source_location expansion;
102
};
103
104
/* A line_map encodes a sequence of locations.  */
105
struct GTY(()) line_map {
106
  source_location start_location;
107
108
  /* The reason for creation of this line map.  */
109
  ENUM_BITFIELD (lc_reason) reason : CHAR_BIT;
110
111
  union {
112
    struct line_map_ordinary GTY((tag ("0"))) ordinary;
113
    struct line_map_macro GTY((tag ("1"))) macro;
114
  } GTY((desc ("%1.reason == LC_ENTER_MACRO"))) d;
115
};
116
77
/* A set of chronological line_map structures.  */
117
/* A set of chronological line_map structures.  */
78
struct GTY(()) line_maps {
118
struct GTY(()) line_maps {
79
  struct line_map * GTY ((length ("%h.used"))) maps;
119
  struct line_map * GTY ((length ("%h.used"))) maps;
Lines 82-92 Link Here
82
122
83
  unsigned int cache;
123
  unsigned int cache;
84
124
85
  /* The most recently listed include stack, if any, starts with
86
     LAST_LISTED as the topmost including file.  -1 indicates nothing
87
     has been listed yet.  */
88
  int last_listed;
89
90
  /* Depth of the include stack, including the current file.  */
125
  /* Depth of the include stack, including the current file.  */
91
  unsigned int depth;
126
  unsigned int depth;
92
127
Lines 142-158 Link Here
142
  (struct line_maps *, enum lc_reason, unsigned int sysp,
177
  (struct line_maps *, enum lc_reason, unsigned int sysp,
143
   const char *to_file, linenum_type to_line);
178
   const char *to_file, linenum_type to_line);
144
179
180
extern const struct line_map *linemap_enter_macro (struct line_maps *,
181
						   void *, source_location,
182
						   unsigned int);
183
184
extern source_location linemap_add_macro_token (const struct line_map *,
185
						unsigned int,
186
						source_location,
187
						source_location);
188
189
extern void linemap_leave_macro (struct line_maps *, source_location);
190
145
/* Given a logical line, returns the map from which the corresponding
191
/* Given a logical line, returns the map from which the corresponding
146
   (source file, line) pair can be deduced.  */
192
   (source file, line) pair can be deduced.  */
147
extern const struct line_map *linemap_lookup
193
extern const struct line_map *linemap_lookup
148
  (struct line_maps *, source_location);
194
  (struct line_maps *, source_location);
149
195
196
extern int linemap_check_ordinary (const struct line_map *);
197
150
/* Converts a map and a source_location to source line.  */
198
/* Converts a map and a source_location to source line.  */
151
#define SOURCE_LINE(MAP, LOC) \
199
#define SOURCE_LINE(MAP, LOC)						\
152
  ((((LOC) - (MAP)->start_location) >> (MAP)->column_bits) + (MAP)->to_line)
200
  (linemap_check_ordinary (MAP),					\
201
   ((((LOC) - (MAP)->start_location)					\
202
     >> (MAP)->d.ordinary.column_bits) + (MAP)->d.ordinary.to_line))
153
203
154
#define SOURCE_COLUMN(MAP, LOC) \
204
#define SOURCE_COLUMN(MAP, LOC)				\
155
  (((LOC) - (MAP)->start_location) & ((1 << (MAP)->column_bits) - 1))
205
  (linemap_check_ordinary (MAP),			\
206
  (((LOC) - (MAP)->start_location)			\
207
   & ((1 << (MAP)->d.ordinary.column_bits) - 1)))
156
208
157
/* Returns the last source line within a map.  This is the (last) line
209
/* Returns the last source line within a map.  This is the (last) line
158
   of the #include, or other directive, that caused a map change.  */
210
   of the #include, or other directive, that caused a map change.  */
Lines 160-175 Link Here
160
  SOURCE_LINE (MAP, LAST_SOURCE_LINE_LOCATION (MAP))
212
  SOURCE_LINE (MAP, LAST_SOURCE_LINE_LOCATION (MAP))
161
#define LAST_SOURCE_COLUMN(MAP) \
213
#define LAST_SOURCE_COLUMN(MAP) \
162
  SOURCE_COLUMN (MAP, LAST_SOURCE_LINE_LOCATION (MAP))
214
  SOURCE_COLUMN (MAP, LAST_SOURCE_LINE_LOCATION (MAP))
163
#define LAST_SOURCE_LINE_LOCATION(MAP) \
215
#define LAST_SOURCE_LINE_LOCATION(MAP)				\
164
  ((((MAP)[1].start_location - 1 - (MAP)->start_location) \
216
  (linemap_check_ordinary (MAP),				\
165
    & ~((1 << (MAP)->column_bits) - 1))			  \
217
   ((((MAP)[1].start_location - 1 - (MAP)->start_location)	\
166
   + (MAP)->start_location)
218
     & ~((1 << (MAP)->d.ordinary.column_bits) - 1))		\
219
    + (MAP)->start_location))
167
220
168
/* Returns the map a given map was included from.  */
221
/* Returns the map a given map was included from.  */
169
#define INCLUDED_FROM(SET, MAP) (&(SET)->maps[(MAP)->included_from])
222
#define INCLUDED_FROM(SET, MAP)				\
223
  (linemap_check_ordinary (MAP),			\
224
   (&(SET)->maps[(MAP)->d.ordinary.included_from]))
170
225
171
/* Nonzero if the map is at the bottom of the include stack.  */
226
/* Nonzero if the map is at the bottom of the include stack.  */
172
#define MAIN_FILE_P(MAP) ((MAP)->included_from < 0)
227
#define MAIN_FILE_P(MAP)			\
228
  (linemap_check_ordinary (MAP),		\
229
   ((MAP)->d.ordinary.included_from < 0))
173
230
174
/* Set LOC to a source position that is the same line as the most recent
231
/* Set LOC to a source position that is the same line as the most recent
175
   linemap_line_start, but with the specified TO_COLUMN column number.  */
232
   linemap_line_start, but with the specified TO_COLUMN column number.  */
Lines 191-196 Link Here
191
extern source_location
248
extern source_location
192
linemap_position_for_column (struct line_maps *set, unsigned int to_column);
249
linemap_position_for_column (struct line_maps *set, unsigned int to_column);
193
250
251
252
#define LINEMAP_FILE(MAP)					\
253
  (linemap_check_ordinary (MAP), (MAP)->d.ordinary.to_file)
254
255
#define LINEMAP_LINE(MAP)					\
256
  (linemap_check_ordinary (MAP), (MAP)->d.ordinary.to_line)
257
258
#define LINEMAP_SYSP(MAP)					\
259
  (linemap_check_ordinary (MAP), (MAP)->d.ordinary.sysp)
260
261
/* FIXME: add assertion.  */
262
#define LINEMAP_MACRO_NAME(MAP) (NODE_NAME ((MAP)->d.macro.macro->name))
263
264
typedef struct GTY (())
265
{
266
  /* The name of the source file involved.  */
267
  const char *file;
268
269
  /* The line-location in the source file.  */
270
  int line;
271
272
  int column;
273
274
  /* In a system header?. */
275
  bool sysp;
276
} expanded_location;
277
278
extern expanded_location linemap_expand_location (struct line_maps *,
279
						  source_location);
280
194
#ifdef __cplusplus
281
#ifdef __cplusplus
195
}
282
}
196
#endif
283
#endif
(-)libcpp/include/cpp-id-data.h (+6 lines)
Lines 38-43 Link Here
38
/* Each macro definition is recorded in a cpp_macro structure.
38
/* Each macro definition is recorded in a cpp_macro structure.
39
   Variadic macros cannot occur with traditional cpp.  */
39
   Variadic macros cannot occur with traditional cpp.  */
40
struct GTY(()) cpp_macro {
40
struct GTY(()) cpp_macro {
41
  /* Name of this macro.  Used only for error reporting.  */
42
  cpp_hashnode * GTY ((nested_ptr (union tree_node,
43
		"%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
44
				   "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL")))
45
    name;
46
41
  /* Parameters, if any.  */
47
  /* Parameters, if any.  */
42
  cpp_hashnode ** GTY ((nested_ptr (union tree_node,
48
  cpp_hashnode ** GTY ((nested_ptr (union tree_node,
43
		"%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
49
		"%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
(-)libcpp/line-map.c (-46 / +205 lines)
Lines 24-29 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 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 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 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-114 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
}
111
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);
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>";
114
113
Lines 129-134 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 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-191 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
188
source_location
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
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)
191
{
295
{
Lines 195-204 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 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 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 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 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);
319
}
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;
478
}
(-)libcpp/files.c (-1 / +1 lines)
Lines 1208-1214 Link Here
1208
  if (syshdr)
1208
  if (syshdr)
1209
    flags = 1 + (externc != 0);
1209
    flags = 1 + (externc != 0);
1210
  pfile->buffer->sysp = flags;
1210
  pfile->buffer->sysp = flags;
1211
  _cpp_do_file_change (pfile, LC_RENAME, map->to_file,
1211
  _cpp_do_file_change (pfile, LC_RENAME, map->d.ordinary.to_file,
1212
		       SOURCE_LINE (map, pfile->line_table->highest_line), flags);
1212
		       SOURCE_LINE (map, pfile->line_table->highest_line), flags);
1213
}
1213
}
1214
1214
(-)libcpp/init.c (-1 / +1 lines)
Lines 555-561 Link Here
555
  if (CPP_OPTION (pfile, preprocessed))
555
  if (CPP_OPTION (pfile, preprocessed))
556
    {
556
    {
557
      read_original_filename (pfile);
557
      read_original_filename (pfile);
558
      fname = pfile->line_table->maps[pfile->line_table->used-1].to_file;
558
      fname = pfile->line_table->maps[pfile->line_table->used-1].d.ordinary.to_file;
559
    }
559
    }
560
  return fname;
560
  return fname;
561
}
561
}
(-)libcpp/internal.h (-8 lines)
Lines 340-353 Link Here
340
  /* Token generated while handling a directive, if any. */
340
  /* Token generated while handling a directive, if any. */
341
  cpp_token directive_result;
341
  cpp_token directive_result;
342
342
343
  /* When expanding a macro at top-level, this is the location of the
344
     macro invocation.  */
345
  source_location invocation_location;
346
347
  /* True if this call to cpp_get_token should consider setting
348
     invocation_location.  */
349
  bool set_invocation_location;
350
351
  /* Search paths for include files.  */
343
  /* Search paths for include files.  */
352
  struct cpp_dir *quote_include;	/* "" */
344
  struct cpp_dir *quote_include;	/* "" */
353
  struct cpp_dir *bracket_include;	/* <> */
345
  struct cpp_dir *bracket_include;	/* <> */

Return to bug 7263