1/* Map logical line numbers to (source file, line number) pairs. 2 Copyright (C) 2001 3 Free Software Foundation, Inc. 4 5This program is free software; you can redistribute it and/or modify it 6under the terms of the GNU General Public License as published by the 7Free Software Foundation; either version 2, or (at your option) any 8later version. 9 10This program is distributed in the hope that it will be useful, 11but WITHOUT ANY WARRANTY; without even the implied warranty of 12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13GNU General Public License for more details. 14 15You should have received a copy of the GNU General Public License 16along with this program; if not, write to the Free Software 17Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 19 In other words, you are welcome to use, share and improve this program. 20 You are forbidden to forbid anyone else to use, share and improve 21 what you give them. Help stamp out software-hoarding! */ 22 23#ifndef GCC_LINE_MAP_H 24#define GCC_LINE_MAP_H 25 26/* Reason for adding a line change with add_line_map (). LC_ENTER is 27 when including a new file, e.g. a #include directive in C. 28 LC_LEAVE is when reaching a file's end. LC_RENAME is when a file 29 name or line number changes for neither of the above reasons 30 (e.g. a #line directive in C). */ 31enum lc_reason {LC_ENTER = 0, LC_LEAVE, LC_RENAME}; 32 33/* The logical line FROM_LINE maps to physical source file TO_FILE at 34 line TO_LINE, and subsequently one-to-one until the next line_map 35 structure in the set. INCLUDED_FROM is an index into the set that 36 gives the line mapping at whose end the current one was included. 37 File(s) at the bottom of the include stack have this set to -1. 38 REASON is the reason for creation of this line map, SYSP is one for 39 a system header, two for a C system header file that therefore 40 needs to be extern "C" protected in C++, and zero otherwise. */ 41struct line_map 42{ 43 const char *to_file; 44 unsigned int to_line; 45 unsigned int from_line; 46 int included_from; 47 ENUM_BITFIELD (lc_reason) reason : CHAR_BIT; 48 unsigned char sysp; 49}; 50 51/* A set of chronological line_map structures. */ 52struct line_maps 53{ 54 struct line_map *maps; 55 unsigned int allocated; 56 unsigned int used; 57 58 /* The most recently listed include stack, if any, starts with 59 LAST_LISTED as the topmost including file. -1 indicates nothing 60 has been listed yet. */ 61 int last_listed; 62 63 /* Depth of the include stack, including the current file. */ 64 unsigned int depth; 65 66 /* If true, prints an include trace a la -H. */ 67 bool trace_includes; 68}; 69 70/* Initialize a line map set. */ 71extern void init_line_maps 72 PARAMS ((struct line_maps *)); 73 74/* Free a line map set. */ 75extern void free_line_maps 76 PARAMS ((struct line_maps *)); 77 78/* Add a mapping of logical source line to physical source file and 79 line number. The text pointed to by TO_FILE must have a lifetime 80 at least as long as the line maps. If reason is LC_LEAVE, and 81 TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their 82 natural values considering the file we are returning to. 83 84 FROM_LINE should be monotonic increasing across calls to this 85 function. A call to this function can relocate the previous set of 86 maps, so any stored line_map pointers should not be used. */ 87extern const struct line_map *add_line_map 88 PARAMS ((struct line_maps *, enum lc_reason, unsigned int sysp, 89 unsigned int from_line, const char *to_file, unsigned int to_line)); 90 91/* Given a logical line, returns the map from which the corresponding 92 (source file, line) pair can be deduced. */ 93extern const struct line_map *lookup_line 94 PARAMS ((struct line_maps *, unsigned int)); 95 96/* Print the file names and line numbers of the #include commands 97 which led to the map MAP, if any, to stderr. Nothing is output if 98 the most recently listed stack is the same as the current one. */ 99extern void print_containing_files 100 PARAMS ((struct line_maps *, const struct line_map *)); 101 102/* Converts a map and logical line to source line. */ 103#define SOURCE_LINE(MAP, LINE) ((LINE) + (MAP)->to_line - (MAP)->from_line) 104 105/* Returns the last source line within a map. This is the (last) line 106 of the #include, or other directive, that caused a map change. */ 107#define LAST_SOURCE_LINE(MAP) SOURCE_LINE ((MAP), (MAP)[1].from_line - 1) 108 109/* Returns the map a given map was included from. */ 110#define INCLUDED_FROM(SET, MAP) (&(SET)->maps[(MAP)->included_from]) 111 112/* Nonzero if the map is at the bottom of the include stack. */ 113#define MAIN_FILE_P(MAP) ((MAP)->included_from < 0) 114 115/* The current line map. Saves a call to lookup_line if the caller is 116 sure he is in the scope of the current map. */ 117#define CURRENT_LINE_MAP(MAPS) ((MAPS)->maps + (MAPS)->used - 1) 118 119#endif /* !GCC_LINE_MAP_H */ 120