00001 /* Map logical line numbers to (source file, line number) pairs. 00002 Copyright (C) 2001 00003 Free Software Foundation, Inc. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of the GNU General Public License as published by the 00007 Free Software Foundation; either version 2, or (at your option) any 00008 later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 00019 In other words, you are welcome to use, share and improve this program. 00020 You are forbidden to forbid anyone else to use, share and improve 00021 what you give them. Help stamp out software-hoarding! */ 00022 00023 #ifndef GCC_LINE_MAP_H 00024 #define GCC_LINE_MAP_H 00025 00026 /* Reason for adding a line change with add_line_map (). LC_ENTER is 00027 when including a new file, e.g. a #include directive in C. 00028 LC_LEAVE is when reaching a file's end. LC_RENAME is when a file 00029 name or line number changes for neither of the above reasons 00030 (e.g. a #line directive in C). */ 00031 enum lc_reason {LC_ENTER = 0, LC_LEAVE, LC_RENAME}; 00032 00033 /* The logical line FROM_LINE maps to physical source file TO_FILE at 00034 line TO_LINE, and subsequently one-to-one until the next line_map 00035 structure in the set. INCLUDED_FROM is an index into the set that 00036 gives the line mapping at whose end the current one was included. 00037 File(s) at the bottom of the include stack have this set to -1. 00038 REASON is the reason for creation of this line map, SYSP is one for 00039 a system header, two for a C system header file that therefore 00040 needs to be extern "C" protected in C++, and zero otherwise. */ 00041 struct line_map 00042 { 00043 const char *to_file; 00044 unsigned int to_line; 00045 unsigned int from_line; 00046 int included_from; 00047 ENUM_BITFIELD (lc_reason) reason : CHAR_BIT; 00048 unsigned char sysp; 00049 }; 00050 00051 /* A set of chronological line_map structures. */ 00052 struct line_maps 00053 { 00054 struct line_map *maps; 00055 unsigned int allocated; 00056 unsigned int used; 00057 00058 /* The most recently listed include stack, if any, starts with 00059 LAST_LISTED as the topmost including file. -1 indicates nothing 00060 has been listed yet. */ 00061 int last_listed; 00062 00063 /* Depth of the include stack, including the current file. */ 00064 unsigned int depth; 00065 00066 /* If true, prints an include trace a la -H. */ 00067 bool trace_includes; 00068 }; 00069 00070 /* Initialize a line map set. */ 00071 extern void init_line_maps 00072 PARAMS ((struct line_maps *)); 00073 00074 /* Free a line map set. */ 00075 extern void free_line_maps 00076 PARAMS ((struct line_maps *)); 00077 00078 /* Add a mapping of logical source line to physical source file and 00079 line number. The text pointed to by TO_FILE must have a lifetime 00080 at least as long as the line maps. If reason is LC_LEAVE, and 00081 TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their 00082 natural values considering the file we are returning to. 00083 00084 FROM_LINE should be monotonic increasing across calls to this 00085 function. A call to this function can relocate the previous set of 00086 maps, so any stored line_map pointers should not be used. */ 00087 extern const struct line_map *add_line_map 00088 PARAMS ((struct line_maps *, enum lc_reason, unsigned int sysp, 00089 unsigned int from_line, const char *to_file, unsigned int to_line)); 00090 00091 /* Given a logical line, returns the map from which the corresponding 00092 (source file, line) pair can be deduced. */ 00093 extern const struct line_map *lookup_line 00094 PARAMS ((struct line_maps *, unsigned int)); 00095 00096 /* Print the file names and line numbers of the #include commands 00097 which led to the map MAP, if any, to stderr. Nothing is output if 00098 the most recently listed stack is the same as the current one. */ 00099 extern void print_containing_files 00100 PARAMS ((struct line_maps *, const struct line_map *)); 00101 00102 /* Converts a map and logical line to source line. */ 00103 #define SOURCE_LINE(MAP, LINE) ((LINE) + (MAP)->to_line - (MAP)->from_line) 00104 00105 /* Returns the last source line within a map. This is the (last) line 00106 of the #include, or other directive, that caused a map change. */ 00107 #define LAST_SOURCE_LINE(MAP) SOURCE_LINE ((MAP), (MAP)[1].from_line - 1) 00108 00109 /* Returns the map a given map was included from. */ 00110 #define INCLUDED_FROM(SET, MAP) (&(SET)->maps[(MAP)->included_from]) 00111 00112 /* Nonzero if the map is at the bottom of the include stack. */ 00113 #define MAIN_FILE_P(MAP) ((MAP)->included_from < 0) 00114 00115 /* The current line map. Saves a call to lookup_line if the caller is 00116 sure he is in the scope of the current map. */ 00117 #define CURRENT_LINE_MAP(MAPS) ((MAPS)->maps + (MAPS)->used - 1) 00118 00119 #endif /* !GCC_LINE_MAP_H */
1.5.6