aboutsummaryrefslogtreecommitdiff
path: root/gcc/line-map.h
blob: 1f9a47da42a5cc60e4cdc2e84937200f25e6e43e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* Map logical line numbers to (source file, line number) pairs.
   Copyright (C) 2001
   Free Software Foundation, Inc.

This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

 In other words, you are welcome to use, share and improve this program.
 You are forbidden to forbid anyone else to use, share and improve
 what you give them.   Help stamp out software-hoarding!  */

#ifndef GCC_LINE_MAP_H
#define GCC_LINE_MAP_H

/* The logical line FROM_LINE maps to physical source file TO_FILE at
   line TO_LINE, and subsequently one-to-one until the next line_map
   structure in the set.  INCLUDED_FROM is an index into the set that
   gives the line mapping at whose end the current one was included.
   File(s) at the bottom of the include stack have this set to -1.  */
struct line_map
{
  const char *to_file;
  unsigned int to_line;
  unsigned int from_line;
  int included_from;
};

/* A set of chronological line_map structures.  */
struct line_maps
{
  struct line_map *maps;
  unsigned int allocated;
  unsigned int used;
};

/* Reason for adding a line change with add_line_map ().  */
enum lc_reason {LC_ENTER = 0, LC_LEAVE, LC_RENAME};

/* Initialize a line map set.  */
extern void init_line_maps
  PARAMS ((struct line_maps *));

/* Free a line map set.  */
extern void free_line_maps
  PARAMS ((struct line_maps *));

/* Add a mapping of logical source line to physical source file and
   line number.  Ther text pointed to by TO_FILE must have a lifetime
   at least as long as the final call to lookup_line ().

   FROM_LINE should be monotonic increasing across calls to this
   function.  */
extern struct line_map *add_line_map
  PARAMS ((struct line_maps *, enum lc_reason,
	   unsigned int from_line, const char *to_file, unsigned int to_line));

/* Given a logical line, returns the map from which the corresponding
   (source file, line) pair can be deduced.  */
extern struct line_map *lookup_line
  PARAMS ((struct line_maps *, unsigned int));

/* Converts a map and logical line to source line.  */
#define SOURCE_LINE(MAP, LINE) ((LINE) + (MAP)->to_line - (MAP)->from_line)

/* Returns the last source line within a map.  This is the (last) line
   of the #include, or other directive, that caused a map change.  */
#define LAST_SOURCE_LINE(MAP) SOURCE_LINE (MAP, (MAP)[1].from_line - 1)

/* Non-zero if the map is at the bottom of the include stack.  */
#define MAIN_FILE_P(MAP) ((MAP)->included_from < 0)

#endif /* !GCC_LINE_MAP_H  */