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

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

(-)gcc/c-lex.c (-8 / +8 lines)
 Lines 1-8    Link Here 
1
   1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008
1
   1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
2
	  (*debug_hooks->start_source_file) (line, new_map->to_file);
2
	  (*debug_hooks->start_source_file) (line, LINEMAP_FILE (new_map));
3
      (*debug_hooks->end_source_file) (new_map->to_line);
3
      (*debug_hooks->end_source_file) (LINEMAP_LINE (new_map));
4
  update_header_times (new_map->to_file);
4
  update_header_times (LINEMAP_FILE (new_map));
5
  tok = cpp_get_token_with_location (parse_in, loc);
5
  tok = cpp_get_token (parse_in);
6
  *loc = tok->src_loc;
6
	  location_t newloc;
7
	  tok = cpp_get_token (parse_in);
7
	  tok = cpp_get_token_with_location (parse_in, &newloc);
8
	      *loc = newloc;
8
	      *loc = tok->src_loc;
(-)gcc/tree.c (-22 lines)
 Lines 1-22    Link Here 
1
expanded_location
2
expand_location (source_location loc)
3
{
4
  expanded_location xloc;
5
  if (loc == 0)
6
    {
7
      xloc.file = NULL;
8
      xloc.line = 0;
9
      xloc.column = 0;
10
      xloc.sysp = 0;
11
    }
12
  else
13
    {
14
      const struct line_map *map = linemap_lookup (line_table, loc);
15
      xloc.file = map->to_file;
16
      xloc.line = SOURCE_LINE (map, loc);
17
      xloc.column = SOURCE_COLUMN (map, loc);
18
      xloc.sysp = map->sysp != 0;
19
    };
20
  return xloc;
21
}
22
(-)gcc/diagnostic.c (-7 / +27 lines)
 Lines 1-7    Link Here 
1
  diagnostic_report_current_module (context);
1
#include "cpp-id-data.h"
2
diagnostic_report_current_module (diagnostic_context *context)
2
  diagnostic_report_current_module (context, diagnostic->location);
3
  if (input_location <= BUILTINS_LOCATION)
3
diagnostic_report_current_module (diagnostic_context *context, location_t where)
4
  map = linemap_lookup (line_table, input_location);
4
  if (where <= BUILTINS_LOCATION)
5
			 map->to_file,
5
  map = linemap_lookup (line_table, where);
6
      struct line_map *macro_map;
7
8
      for (macro_map = map; macro_map->reason == LC_ENTER_MACRO; )
9
 	{
10
 	  expanded_location loc;
11
 	  source_location l2 = where - macro_map->start_location;
12
 	  where = macro_map->d.macro.macro_locations[2 * l2 + 1];
13
 	  loc = expand_location (where);
14
 	  pp_verbatim (context->printer,
15
 		       "While expanding macro %s at %s:%d:%d",
16
 		       LINEMAP_MACRO_NAME (macro_map),
17
		       loc.file, loc.line, loc.column);
18
	  pp_newline (context->printer);
19
 	  macro_map = linemap_lookup (line_table, where);
20
 	}
21
22
      while (map->reason == LC_ENTER_MACRO)
23
 	map = linemap_lookup (line_table, map->d.macro.expansion);
24
6
			 map->to_file, LAST_SOURCE_LINE (map));
25
			 LINEMAP_FILE (map),
7
			   map->to_file, LAST_SOURCE_LINE (map));
26
			 LINEMAP_FILE (map), LAST_SOURCE_LINE (map));
27
			   LINEMAP_FILE (map), LAST_SOURCE_LINE (map));
(-)gcc/diagnostic.h (-1 / +2 lines)
Line 1    Link Here 
1
extern void diagnostic_report_current_module (diagnostic_context *);
1
extern void diagnostic_report_current_module (diagnostic_context *,
2
					      location_t);
(-)gcc/input.h (-17 / +3 lines)
 Lines 1-17    Link Here 
1
   Copyright (C) 1993, 1997, 1998, 2000, 2003, 2004, 2007, 2008
1
   Copyright (C) 1993, 1997, 1998, 2000, 2003, 2004, 2007, 2008, 2009
2
typedef struct GTY (())
2
#define expand_location(LOC) linemap_expand_location (line_table, LOC)
3
{
3
4
  /* The name of the source file involved.  */
5
  const char *file;
6
7
  /* The line-location in the source file.  */
8
  int line;
9
10
  int column;
11
12
  /* In a system header?. */
13
  bool sysp;
14
} expanded_location;
15
16
extern expanded_location expand_location (source_location);
17
(-)gcc/cp/error.c (-1 / +1 lines)
Line 1    Link Here 
1
  diagnostic_report_current_module (context);
1
  diagnostic_report_current_module (context, diagnostic->location);
(-)gcc/fortran/cpp.c (-7 / +11 lines)
 Lines 1-7    Link Here 
1
      size_t to_file_len = strlen (map->to_file);
1
      struct expanded_location loc;
2
      unsigned char *to_file_quoted =
3
         (unsigned char *) alloca (to_file_len * 4 + 1);
4
      print.src_line = SOURCE_LINE (map, src_loc);
2
      size_t to_file_len;
3
      unsigned char *to_file_quoted;
5
			    (const unsigned char *) map->to_file, to_file_len);
4
      loc = expand_location (src_loc);
5
      to_file_len = strlen (loc.file);
6
      to_file_quoted = (unsigned char *) alloca (to_file_len * 4 + 1);
7
      print.src_line = loc.line;
8
6
      if (map->sysp == 2)
9
			    (const unsigned char *) loc.file, to_file_len);
7
      else if (map->sysp == 1)
10
      if (loc.sysp == 2)
11
      else if (loc.sysp == 1)
(-)gcc/c-ppoutput.c (-5 / +13 lines)
 Lines 1-5    Link Here 
1
      size_t to_file_len = strlen (map->to_file);
1
      size_t to_file_len = strlen (LINEMAP_FILE (map));
2
			    (const unsigned char *) map->to_file, to_file_len);
2
			    (const unsigned char *) LINEMAP_FILE (map),
3
			    to_file_len);
3
      if (map->sysp == 2)
4
      if (LINEMAP_SYSP (map) == 2)
4
      else if (map->sysp == 1)
5
      else if (LINEMAP_SYSP (map) == 1)
6
  const struct line_map *map;
7
8
  if (line <= BUILTINS_LOCATION)
9
    return;
5
  if (linemap_lookup (line_table, line)->to_line != 0)
10
  map = linemap_lookup (line_table, line);
11
  if (LINEMAP_LINE (map) != 0)
12
  if (line <= BUILTINS_LOCATION)
13
    return;
(-)libcpp/macro.c (-57 / +79 lines)
 Lines 1-57    Link Here 
1
				_cpp_buff **);
1
				_cpp_buff **, source_location *);
2
			  macro_arg *);
2
			  macro_arg *, source_location, source_location);
3
					_cpp_buff **);
3
					_cpp_buff **, source_location *);
4
	name = map->to_file;
4
	linemap_check_ordinary (map);
5
	name = map->d.ordinary.to_file;
5
	      _cpp_buff **pragma_buff)
6
	      _cpp_buff **pragma_buff, source_location *paren_loc)
7
      *paren_loc = token->src_loc;
6
		      _cpp_buff **pragma_buff)
8
		      _cpp_buff **pragma_buff, source_location *paren_loc)
7
      return collect_args (pfile, node, pragma_buff);
9
      return collect_args (pfile, node, pragma_buff, paren_loc);
10
      source_location paren_loc = result->src_loc;
8
	  buff = funlike_invocation_p (pfile, node, &pragma_buff);
11
	  buff = funlike_invocation_p (pfile, node, &pragma_buff,
12
				       &paren_loc);
9
	    replace_args (pfile, node, macro, (macro_arg *) buff->base);
13
	    replace_args (pfile, node, macro, (macro_arg *) buff->base,
14
			  result->src_loc, paren_loc);
10
	_cpp_push_token_context (pfile, node, macro->exp.tokens,
15
	{
11
				 macro_real_token_count (macro));
16
	  unsigned int i, count = macro_real_token_count (macro);
17
	  _cpp_buff *buff = _cpp_get_buff (pfile,
18
					   count * sizeof (cpp_token));
19
	  const cpp_token *src = macro->exp.tokens;
20
	  cpp_token *first = (cpp_token *) buff->base;
21
	  cpp_token *dest = first;
22
	  const struct line_map *map
23
	    = linemap_enter_macro (pfile->line_table, macro,
24
				   result->src_loc, count);
25
	  for (i = 0; i < count; ++i)
26
	    {
27
	      *dest = *src;
28
	      dest->src_loc = linemap_add_macro_token (map, i,
29
						       dest->src_loc,
30
						       dest->src_loc);
31
	      ++dest;
32
	      ++src;
33
	    }
34
	  linemap_leave_macro (pfile->line_table, paren_loc);
35
	  /* FIXME freeing  */
36
	  _cpp_push_token_context (pfile, node, first, count);
37
	}
12
replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro, macro_arg *args)
38
replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro,
39
	      macro_arg *args, source_location macro_loc,
40
	      source_location paren_loc)
13
  const cpp_token **dest, **first;
41
  cpp_token *dest, *first;
42
  const struct line_map *map;
14
  buff = _cpp_get_buff (pfile, total * sizeof (cpp_token *));
43
  buff = _cpp_get_buff (pfile, total * sizeof (cpp_token));
15
  first = (const cpp_token **) buff->base;
44
  first = (cpp_token *) buff->base;
16
  for (src = macro->exp.tokens; src < limit; src++)
45
  map = linemap_enter_macro (pfile->line_table, macro, macro_loc, total);
46
  i = 0;
47
  for (src = macro->exp.tokens; src < limit; src++, i++)
17
      const cpp_token **from, **paste_flag;
48
      const cpp_token **from;
49
      cpp_token *paste_flag;
18
	  *dest++ = src;
50
	  *dest = *src;
51
	  dest->src_loc = linemap_add_macro_token (map, i, dest->src_loc,
52
						   dest->src_loc);
53
	  ++dest;
19
	      if (dest[-1]->type == CPP_COMMA
54
	      if (dest[-1].type == CPP_COMMA
20
	*dest++ = padding_token (pfile, src);
55
	{
56
	  *dest = *padding_token (pfile, src);
57
	  dest->src_loc = linemap_add_macro_token (map, i, dest->src_loc,
58
						   dest->src_loc);
59
	  ++dest;
60
	}
21
	  memcpy (dest, from, count * sizeof (cpp_token *));
61
	  unsigned int j;
22
	  dest += count;
62
	  for (j = 0; j < count; ++j)
63
	    {
64
	      *dest = *from[j];
65
	      dest->src_loc = linemap_add_macro_token (map, i, dest->src_loc,
66
						       src->src_loc);
67
	      ++dest;
68
	    }
23
	*dest++ = &pfile->avoid_paste;
69
	{
70
	  *dest = pfile->avoid_paste;
71
	  /* Don't bother changing the location here.  */
72
	  ++dest;
73
	}
24
	  cpp_token *token = _cpp_temp_token (pfile);
74
	    paste_flag->flags |= PASTE_LEFT;
25
	  token->type = (*paste_flag)->type;
26
	  token->val = (*paste_flag)->val;
27
	    token->flags = (*paste_flag)->flags | PASTE_LEFT;
28
	    token->flags = (*paste_flag)->flags & ~PASTE_LEFT;
75
	    paste_flag->flags &= ~PASTE_LEFT;
29
	  *paste_flag = token;
76
  linemap_leave_macro (pfile->line_table, paren_loc);
30
  push_ptoken_context (pfile, node, buff, first, dest - first);
77
  /* FIXME: doesn't handle BUFF */
78
  _cpp_push_token_context (pfile, node, first, dest - first);
31
  bool can_set = pfile->set_invocation_location;
79
  macro->name = node;
32
  pfile->set_invocation_location = false;
33
	  /* If not in a macro context, and we're going to start an
34
	     expansion, record the location.  */
35
	  if (can_set && !context->macro)
36
	    pfile->invocation_location = result->src_loc;
37
/* Like cpp_get_token, but also returns a location separate from the
38
   one provided by the returned token.  LOC is an out parameter; *LOC
39
   is set to the location "as expected by the user".  This matters
40
   when a token results from macro expansion -- the token's location
41
   will indicate where the macro is defined, but *LOC will be the
42
   location of the start of the expansion.  */
43
const cpp_token *
44
cpp_get_token_with_location (cpp_reader *pfile, source_location *loc)
45
{
46
  const cpp_token *result;
47
48
  pfile->set_invocation_location = true;
49
  result = cpp_get_token (pfile);
50
  if (pfile->context->macro)
51
    *loc = pfile->invocation_location;
52
  else
53
    *loc = result->src_loc;
54
55
  return result;
56
}
57
(-)libcpp/directives.c (-5 / +5 lines)
 Lines 1-5    Link Here 
1
  unsigned char map_sysp = map->sysp;
1
  unsigned char map_sysp = map->d.ordinary.sysp;
2
  const char *new_file = map->to_file;
2
  const char *new_file = map->d.ordinary.to_file;
3
  const char *new_file = map->to_file;
3
  const char *new_file = map->d.ordinary.to_file;
4
  unsigned int new_sysp = map->sysp;
4
  unsigned int new_sysp = map->d.ordinary.sysp;
5
    linemap_line_start (pfile->line_table, map->to_line, 127);
5
    linemap_line_start (pfile->line_table, map->d.ordinary.to_line, 127);
(-)libcpp/include/cpplib.h (-2 lines)
 Lines 1-2    Link Here 
1
extern const cpp_token *cpp_get_token_with_location (cpp_reader *,
2
						     source_location *);
(-)libcpp/include/line-map.h (-30 / +117 lines)
 Lines 1-30    Link Here 
1
enum lc_reason {LC_ENTER = 0, LC_LEAVE, LC_RENAME, LC_RENAME_VERBATIM};
1
enum lc_reason
2
{
3
  LC_ENTER = 0,
4
  LC_LEAVE,
5
  LC_RENAME,
6
  LC_RENAME_VERBATIM,
7
  LC_ENTER_MACRO
8
  /* stringize */
9
  /* paste */
10
};
2
/* Long-term, we want to use this to replace struct location_s (in input.h),
11
/* An ordinary line map encodes physical source locations.
3
   and effectively typedef source_location location_t.  */
12
   
4
/* Physical source file TO_FILE at line TO_LINE at column 0 is represented
13
   Physical source file TO_FILE at line TO_LINE at column 0 is represented
5
   INCLUDED_FROM is an index into the set that gives the line mapping
14
*/
6
   at whose end the current one was included.  File(s) at the bottom
15
struct GTY(()) line_map_ordinary
7
   of the include stack have this set to -1.  REASON is the reason for
16
{
8
   creation of this line map, SYSP is one for a system header, two for
9
   a C system header file that therefore needs to be extern "C"
10
   protected in C++, and zero otherwise.  */
11
struct GTY(()) line_map {
12
  source_location start_location;
17
18
  /* An index into the set that gives the line mapping at whose end
19
     the current one was included.  File(s) at the bottom of the
20
     include stack have this set to -1.  */
13
  ENUM_BITFIELD (lc_reason) reason : CHAR_BIT;
21
14
  /* The sysp field isn't really needed now that it's in cpp_buffer.  */
22
  /* SYSP is one for a system header, two for a C system header file
23
     that therefore needs to be extern "C" protected in C++, and zero
24
     otherwise.  This field isn't really needed now that it's in
25
     cpp_buffer.  */
15
  /* Number of the low-order source_location bits used for a column number.  */
26
27
  /* Number of the low-order source_location bits used for a column
28
     number.  */
29
struct cpp_macro;
30
31
/* A macro line map encodes locations coming from a macro expansion.
32
   
33
   Here, the offset from START_LOCATION is used to index into
34
   MACRO_LOCATIONS; this holds the original location of the token.  */
35
struct GTY(()) line_map_macro
36
{
37
  struct cpp_macro *macro;
38
  unsigned int n_tokens;
39
  source_location * GTY((length ("%h.n_tokens"))) macro_locations;
40
  source_location expansion;
41
};
42
43
/* A line_map encodes a sequence of locations.  */
44
struct GTY(()) line_map {
45
  source_location start_location;
46
47
  /* The reason for creation of this line map.  */
48
  ENUM_BITFIELD (lc_reason) reason : CHAR_BIT;
49
50
  union {
51
    struct line_map_ordinary GTY((tag ("0"))) ordinary;
52
    struct line_map_macro GTY((tag ("1"))) macro;
53
  } GTY((desc ("%1.reason == LC_ENTER_MACRO"))) d;
54
};
55
16
  /* The most recently listed include stack, if any, starts with
56
extern const struct line_map *linemap_enter_macro (struct line_maps *,
17
     LAST_LISTED as the topmost including file.  -1 indicates nothing
57
						   void *, source_location,
18
     has been listed yet.  */
58
						   unsigned int);
19
  int last_listed;
59
20
60
extern source_location linemap_add_macro_token (const struct line_map *,
61
						unsigned int,
62
						source_location,
63
						source_location);
64
65
extern void linemap_leave_macro (struct line_maps *, source_location);
66
67
extern int linemap_check_ordinary (const struct line_map *);
68
21
#define SOURCE_LINE(MAP, LOC) \
69
#define SOURCE_LINE(MAP, LOC)						\
22
  ((((LOC) - (MAP)->start_location) >> (MAP)->column_bits) + (MAP)->to_line)
70
  (linemap_check_ordinary (MAP),					\
71
   ((((LOC) - (MAP)->start_location)					\
72
     >> (MAP)->d.ordinary.column_bits) + (MAP)->d.ordinary.to_line))
23
#define SOURCE_COLUMN(MAP, LOC) \
73
#define SOURCE_COLUMN(MAP, LOC)				\
24
  (((LOC) - (MAP)->start_location) & ((1 << (MAP)->column_bits) - 1))
74
  (linemap_check_ordinary (MAP),			\
75
  (((LOC) - (MAP)->start_location)			\
76
   & ((1 << (MAP)->d.ordinary.column_bits) - 1)))
25
#define LAST_SOURCE_LINE_LOCATION(MAP) \
77
#define LAST_SOURCE_LINE_LOCATION(MAP)				\
26
  ((((MAP)[1].start_location - 1 - (MAP)->start_location) \
78
  (linemap_check_ordinary (MAP),				\
27
    & ~((1 << (MAP)->column_bits) - 1))			  \
79
   ((((MAP)[1].start_location - 1 - (MAP)->start_location)	\
28
   + (MAP)->start_location)
80
     & ~((1 << (MAP)->d.ordinary.column_bits) - 1))		\
81
    + (MAP)->start_location))
29
#define INCLUDED_FROM(SET, MAP) (&(SET)->maps[(MAP)->included_from])
82
#define INCLUDED_FROM(SET, MAP)				\
83
  (linemap_check_ordinary (MAP),			\
84
   (&(SET)->maps[(MAP)->d.ordinary.included_from]))
30
#define MAIN_FILE_P(MAP) ((MAP)->included_from < 0)
85
#define MAIN_FILE_P(MAP)			\
86
  (linemap_check_ordinary (MAP),		\
87
   ((MAP)->d.ordinary.included_from < 0))
88
89
#define LINEMAP_FILE(MAP)					\
90
  (linemap_check_ordinary (MAP), (MAP)->d.ordinary.to_file)
91
92
#define LINEMAP_LINE(MAP)					\
93
  (linemap_check_ordinary (MAP), (MAP)->d.ordinary.to_line)
94
95
#define LINEMAP_SYSP(MAP)					\
96
  (linemap_check_ordinary (MAP), (MAP)->d.ordinary.sysp)
97
98
/* FIXME: add assertion.  */
99
#define LINEMAP_MACRO_NAME(MAP) (NODE_NAME ((MAP)->d.macro.macro->name))
100
101
typedef struct GTY (())
102
{
103
  /* The name of the source file involved.  */
104
  const char *file;
105
106
  /* The line-location in the source file.  */
107
  int line;
108
109
  int column;
110
111
  /* In a system header?. */
112
  bool sysp;
113
} expanded_location;
114
115
extern expanded_location linemap_expand_location (struct line_maps *,
116
						  source_location);
117
(-)libcpp/include/cpp-id-data.h (+6 lines)
Line 1    Link Here 
1
  /* Name of this macro.  Used only for error reporting.  */
2
  cpp_hashnode * GTY ((nested_ptr (union tree_node,
3
		"%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
4
				   "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL")))
5
    name;
6
(-)libcpp/line-map.c (-46 / +205 lines)
 Lines 1-46    Link Here 
1
  set->last_listed = -1;
1
#define linemap_assert(EXPR)			\
2
	     map->to_file);
2
  do {						\
3
    if (! (EXPR))				\
4
      abort ();					\
5
  } while (0)
6
3
/* Add a mapping of logical source line to physical source file and
7
	     map->d.ordinary.to_file);
4
   line number.
5
6
   The text pointed to by TO_FILE must have a lifetime
7
   at least as long as the final call to lookup_line ().  An empty
8
   TO_FILE means standard input.  If reason is LC_LEAVE, and
9
   TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their
10
   natural values considering the file we are returning to.
11
12
   FROM_LINE should be monotonic increasing across calls to this
13
   function.  A call to this function can relocate the previous set of
14
   maps, so any stored line_map pointers should not be used.  */
15
16
const struct line_map *
17
linemap_add (struct line_maps *set, enum lc_reason reason,
18
	     unsigned int sysp, const char *to_file, linenum_type to_line)
19
  struct line_map *map;
8
static struct line_map *
20
  source_location start_location = set->highest_location + 1;
9
new_linemap (struct line_maps *set)
21
22
  if (set->used && start_location < set->maps[set->used - 1].start_location)
23
    abort ();
24
25
  map = &set->maps[set->used];
26
	  error = to_file && strcmp (from->to_file, to_file);
10
  return &set->maps[set->used++];
11
}
12
static const struct line_map *
13
do_add (struct line_maps *set, enum lc_reason reason,
14
	unsigned int sysp, const char *to_file, linenum_type to_line,
15
	const struct line_map *previous)
16
{
17
  struct line_map *map;
18
  source_location start_location = set->highest_location + 1;
19
20
  if (set->used && start_location < set->maps[set->used - 1].start_location)
21
    abort ();
22
23
  map = new_linemap (set);
24
25
	      set->used--;
27
	  to_file = from->to_file;
26
	  linemap_check_ordinary (from);
27
	  error = to_file && strcmp (from->d.ordinary.to_file, to_file);
28
	  sysp = from->sysp;
28
	  linemap_check_ordinary (from);
29
	  to_file = from->d.ordinary.to_file;
29
  map->sysp = sysp;
30
	  sysp = from->d.ordinary.sysp;
31
  linemap_assert (reason != LC_ENTER_MACRO);
30
  map->to_file = to_file;
32
  map->d.ordinary.sysp = sysp;
31
  map->to_line = to_line;
32
  set->cache = set->used++;
33
  map->column_bits = 0;
34
      map->included_from = set->depth == 0 ? -1 : (int) (set->used - 2);
33
  map->d.ordinary.to_file = to_file;
34
  map->d.ordinary.to_line = to_line;
35
  set->cache = set->used - 1;
36
  map->d.ordinary.column_bits = 0;
35
    map->included_from = map[-1].included_from;
37
      map->d.ordinary.included_from
38
	= set->depth == 0 ? -1 : (int) (set->used - 2);
36
      map->included_from = INCLUDED_FROM (set, map - 1)->included_from;
39
    {
40
      if (previous == NULL)
41
	previous = &map[-1];
42
      linemap_check_ordinary (previous);
43
      map->d.ordinary.included_from = previous->d.ordinary.included_from;
44
    }
37
      || (line_delta > 10 && line_delta * map->column_bits > 1000)
45
      map->d.ordinary.included_from
38
      || (max_column_hint >= (1U << map->column_bits))
46
	= INCLUDED_FROM (set, map - 1)->d.ordinary.included_from;
39
      || (max_column_hint <= 80 && map->column_bits >= 10))
47
/* Add a mapping of logical source line to physical source file and
48
   line number.
49
50
   The text pointed to by TO_FILE must have a lifetime
51
   at least as long as the final call to lookup_line ().  An empty
52
   TO_FILE means standard input.  If reason is LC_LEAVE, and
53
   TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their
54
   natural values considering the file we are returning to.
55
56
   FROM_LINE should be monotonic increasing across calls to this
57
   function.  A call to this function can relocate the previous set of
58
   maps, so any stored line_map pointers should not be used.  */
59
60
const struct line_map *
61
linemap_add (struct line_maps *set, enum lc_reason reason,
62
	     unsigned int sysp, const char *to_file, linenum_type to_line)
63
{
64
  return do_add (set, reason, sysp, to_file, to_line, NULL);
65
}
66
67
const struct line_map *
68
linemap_enter_macro (struct line_maps *set, void *macro,
69
		     source_location expansion, unsigned int num_tokens)
70
{
71
  struct line_map *map;
72
  source_location start_location = set->highest_location + 1;
73
  line_map_realloc reallocator
74
    = set->reallocator ? set->reallocator : xrealloc;
75
76
  map = new_linemap (set);
77
78
  map->start_location = start_location;
79
  map->reason = LC_ENTER_MACRO;
80
  map->d.macro.macro = macro;
81
  map->d.macro.n_tokens = num_tokens;
82
  map->d.macro.macro_locations
83
    = reallocator (NULL, 2 * num_tokens * sizeof (source_location));
84
  map->d.macro.expansion = expansion;
85
  memset (map->d.macro.macro_locations, 0,
86
	  num_tokens * sizeof (source_location));
87
88
  set->cache = set->used - 1;
89
  set->max_column_hint = 0;
90
  set->highest_location = start_location + num_tokens;
91
  set->highest_line = start_location + num_tokens;
92
93
  return map;
94
}
95
96
linemap_add_macro_token (const struct line_map *map,
97
			 unsigned int token_no,
98
			 source_location orig,
99
			 source_location other /* FIXME name */)
100
{
101
  linemap_assert (map->reason == LC_ENTER_MACRO);
102
  map->d.macro.macro_locations[2 * token_no] = orig;
103
  map->d.macro.macro_locations[2 * token_no + 1] = other;
104
  return map->start_location + token_no;
105
}
106
107
static const struct line_map *
108
find_macro_base (struct line_maps *set, source_location loc, int expansion)
109
{
110
  while (1)
111
    {
112
      const struct line_map *map;
113
      map = linemap_lookup (set, loc);
114
      if (map->reason != LC_ENTER_MACRO)
115
	return map;
116
      if (expansion)
117
	loc = map->d.macro.expansion;
118
      else
119
	loc = map->d.macro.macro_locations[2 * (loc - map->start_location)];
120
    }
121
}
122
123
void
124
linemap_leave_macro (struct line_maps *set, source_location paren_loc)
125
{
126
  const struct line_map *base, *paren;
127
128
  linemap_assert (set->maps[set->used - 1].reason == LC_ENTER_MACRO);
129
130
/*   base = find_macro_base (set, set->maps[set->used - 1].d.macro.expansion, 1); */
131
  base = &set->maps[set->used - 2];
132
  linemap_assert (base->reason != LC_ENTER_MACRO);
133
134
  linemap_assert (base->reason != LC_ENTER_MACRO);
135
  paren = find_macro_base (set, paren_loc, 0);
136
  do_add (set, LC_RENAME, base->d.ordinary.sysp,
137
	  base->d.ordinary.to_file, SOURCE_LINE (paren, paren_loc), base);
138
}
139
140
source_location
141
142
  linemap_check_ordinary (map);
143
40
	  || last_line != map->to_line
144
      || (line_delta > 10 && line_delta * map->d.ordinary.column_bits > 1000)
145
      || (max_column_hint >= (1U << map->d.ordinary.column_bits))
146
      || (max_column_hint <= 80 && map->d.ordinary.column_bits >= 10))
41
	map = (struct line_map *) linemap_add (set, LC_RENAME, map->sysp,
147
	  || last_line != map->d.ordinary.to_line
42
					       map->to_file, to_line);
43
      map->column_bits = column_bits;
44
      r = map->start_location + ((to_line - map->to_line) << column_bits);
45
      + (line_delta << map->column_bits);
148
	map = (struct line_map *) linemap_add (set, LC_RENAME,
149
					       map->d.ordinary.sysp,
150
					       map->d.ordinary.to_file,
151
					       to_line);
152
      map->d.ordinary.column_bits = column_bits;
153
      r = map->start_location + ((to_line - map->d.ordinary.to_line)
154
				 << column_bits);
46
  fprintf (stderr, " %s\n", map->to_file);
155
      + (line_delta << map->d.ordinary.column_bits);
156
157
  linemap_assert (set->maps[set->used - 1].reason != LC_ENTER_MACRO);
158
159
int
160
linemap_check_ordinary (const struct line_map *map)
161
{
162
  linemap_assert (map->reason != LC_ENTER_MACRO);
163
  /* Return any old value.  */
164
  return 0;
165
}
166
167
  linemap_check_ordinary (map);
168
  fprintf (stderr, " %s\n", map->d.ordinary.to_file);
169
170
expanded_location
171
linemap_expand_location (struct line_maps *set, source_location loc)
172
{
173
  expanded_location xloc;
174
  if (loc == 0)
175
    {
176
      xloc.file = NULL;
177
      xloc.line = 0;
178
      xloc.column = 0;
179
      xloc.sysp = 0;
180
    }
181
  else
182
    {
183
      const struct line_map *map;
184
      while (1)
185
	{
186
	  unsigned int token;
187
188
	  map = linemap_lookup (set, loc);
189
	  if (map->reason != LC_ENTER_MACRO)
190
	    break;
191
	  token = loc - map->start_location;
192
	  linemap_assert (token < map->d.macro.n_tokens);
193
	  /* FIXME?? when we have 2 locs */
194
	  if (map->d.macro.macro_locations[2 * token] > map->d.macro.expansion)
195
	    loc = map->d.macro.macro_locations[2 * token];
196
	  else
197
	    loc = map->d.macro.expansion;
198
	}
199
      xloc.file = LINEMAP_FILE (map);
200
      xloc.line = SOURCE_LINE (map, loc);
201
      xloc.column = SOURCE_COLUMN (map, loc);
202
      xloc.sysp = LINEMAP_SYSP (map) != 0;
203
    }
204
  return xloc;
205
}
(-)libcpp/files.c (-1 / +1 lines)
Line 1    Link Here 
1
  _cpp_do_file_change (pfile, LC_RENAME, map->to_file,
1
  _cpp_do_file_change (pfile, LC_RENAME, map->d.ordinary.to_file,
(-)libcpp/init.c (-1 / +1 lines)
Line 1    Link Here 
1
      fname = pfile->line_table->maps[pfile->line_table->used-1].to_file;
1
      fname = pfile->line_table->maps[pfile->line_table->used-1].d.ordinary.to_file;
(-)libcpp/internal.h (-8 lines)
 Lines 1-8    Link Here 
1
  /* When expanding a macro at top-level, this is the location of the
2
     macro invocation.  */
3
  source_location invocation_location;
4
5
  /* True if this call to cpp_get_token should consider setting
6
     invocation_location.  */
7
  bool set_invocation_location;
8