00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "config.h"
00024 #include "system.h"
00025 #include "line-map.h"
00026 #include "intl.h"
00027
00028 static void trace_include
00029 PARAMS ((const struct line_maps *, const struct line_map *));
00030
00031
00032
00033 void
00034 init_line_maps (set)
00035 struct line_maps *set;
00036 {
00037 set->maps = 0;
00038 set->allocated = 0;
00039 set->used = 0;
00040 set->last_listed = -1;
00041 set->trace_includes = false;
00042 set->depth = 0;
00043 }
00044
00045
00046
00047 void
00048 free_line_maps (set)
00049 struct line_maps *set;
00050 {
00051 if (set->maps)
00052 {
00053 struct line_map *map;
00054
00055
00056
00057 for (map = CURRENT_LINE_MAP (set); ! MAIN_FILE_P (map);
00058 map = INCLUDED_FROM (set, map))
00059 fprintf (stderr, "line-map.c: file \"%s\" entered but not left\n",
00060 map->to_file);
00061
00062 free (set->maps);
00063 }
00064 }
00065
00066
00067
00068
00069
00070
00071
00072
00073 const struct line_map *
00074 add_line_map (set, reason, sysp, from_line, to_file, to_line)
00075 struct line_maps *set;
00076 enum lc_reason reason;
00077 unsigned int sysp;
00078 unsigned int from_line;
00079 const char *to_file;
00080 unsigned int to_line;
00081 {
00082 struct line_map *map;
00083
00084 if (set->used && from_line < set->maps[set->used - 1].from_line)
00085 abort ();
00086
00087 if (set->used == set->allocated)
00088 {
00089 set->allocated = 2 * set->allocated + 256;
00090 set->maps = (struct line_map *)
00091 xrealloc (set->maps, set->allocated * sizeof (struct line_map));
00092 }
00093
00094 map = &set->maps[set->used++];
00095
00096
00097
00098 if (set->depth == 0)
00099 reason = LC_ENTER;
00100 else if (reason == LC_LEAVE)
00101 {
00102 struct line_map *from;
00103 bool error;
00104
00105 if (MAIN_FILE_P (map - 1))
00106 {
00107 error = true;
00108 reason = LC_RENAME;
00109 from = map - 1;
00110 }
00111 else
00112 {
00113 from = INCLUDED_FROM (set, map - 1);
00114 error = to_file && strcmp (from->to_file, to_file);
00115 }
00116
00117
00118
00119 if (error)
00120 fprintf (stderr, "line-map.c: file \"%s\" left but not entered\n",
00121 to_file);
00122
00123
00124 if (error || to_file == NULL)
00125 {
00126 to_file = from->to_file;
00127 to_line = LAST_SOURCE_LINE (from) + 1;
00128 sysp = from->sysp;
00129 }
00130 }
00131
00132 map->reason = reason;
00133 map->sysp = sysp;
00134 map->from_line = from_line;
00135 map->to_file = to_file;
00136 map->to_line = to_line;
00137
00138 if (reason == LC_ENTER)
00139 {
00140 set->depth++;
00141 map->included_from = set->used - 2;
00142 if (set->trace_includes)
00143 trace_include (set, map);
00144 }
00145 else if (reason == LC_RENAME)
00146 map->included_from = map[-1].included_from;
00147 else if (reason == LC_LEAVE)
00148 {
00149 set->depth--;
00150 map->included_from = INCLUDED_FROM (set, map - 1)->included_from;
00151 }
00152
00153 return map;
00154 }
00155
00156
00157
00158
00159
00160
00161 const struct line_map *
00162 lookup_line (set, line)
00163 struct line_maps *set;
00164 unsigned int line;
00165 {
00166 unsigned int md, mn = 0, mx = set->used;
00167
00168 if (mx == 0)
00169 abort ();
00170
00171 while (mx - mn > 1)
00172 {
00173 md = (mn + mx) / 2;
00174 if (set->maps[md].from_line > line)
00175 mx = md;
00176 else
00177 mn = md;
00178 }
00179
00180 return &set->maps[mn];
00181 }
00182
00183
00184
00185
00186
00187 void
00188 print_containing_files (set, map)
00189 struct line_maps *set;
00190 const struct line_map *map;
00191 {
00192 if (MAIN_FILE_P (map) || set->last_listed == map->included_from)
00193 return;
00194
00195 set->last_listed = map->included_from;
00196 map = INCLUDED_FROM (set, map);
00197
00198 fprintf (stderr, _("In file included from %s:%u"),
00199 map->to_file, LAST_SOURCE_LINE (map));
00200
00201 while (! MAIN_FILE_P (map))
00202 {
00203 map = INCLUDED_FROM (set, map);
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 fprintf (stderr, _(",\n from %s:%u"),
00217 map->to_file, LAST_SOURCE_LINE (map));
00218 }
00219
00220 fputs (":\n", stderr);
00221 }
00222
00223
00224
00225 static void
00226 trace_include (set, map)
00227 const struct line_maps *set;
00228 const struct line_map *map;
00229 {
00230 unsigned int i = set->depth;
00231
00232 while (--i)
00233 putc ('.', stderr);
00234 fprintf (stderr, " %s\n", map->to_file);
00235 }