このページを編集する際は,編集に関する方針に従ってください.[]
概要[]
引数[]
- struct line_maps *set
- enum lc_reason reason
- unsigned int sysp
- const char *to_file
- unsigned int to_line
実装[]
73 /* Add a mapping of logical source line to physical source file and
74 line number.
75
76 The text pointed to by TO_FILE must have a lifetime
77 at least as long as the final call to lookup_line (). An empty
78 TO_FILE means standard input. If reason is LC_LEAVE, and
79 TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their
80 natural values considering the file we are returning to.
81
82 FROM_LINE should be monotonic increasing across calls to this
83 function. A call to this function can relocate the previous set of
84 A call to this function can relocate the previous set of
85 maps, so any stored line_map pointers should not be used. */
86
87 const struct line_map *
88 linemap_add (struct line_maps *set, enum lc_reason reason,
89 unsigned int sysp, const char *to_file, unsigned int to_line)
90 {
91 struct line_map *map;
92 source_location start_location = set->highest_location + 1;
93
94 if (set->used && start_location < set->maps[set->used - 1].start_location)
95 abort ();
96
97 if (set->used == set->allocated)
98 {
99 set->allocated = 2 * set->allocated + 256;
100 set->maps = XRESIZEVEC (struct line_map, set->maps, set->allocated);
101 }
102
103 map = &set->maps[set->used];
104
105 if (to_file && *to_file == '\0')
106 to_file = "<stdin>";
107
108 /* If we don't keep our line maps consistent, we can easily
109 segfault. Don't rely on the client to do it for us. */
110 if (set->depth == 0)
111 reason = LC_ENTER;
112 else if (reason == LC_LEAVE)
113 {
114 struct line_map *from;
115 bool error;
116
117 if (MAIN_FILE_P (map - 1))
118 {
119 if (to_file == NULL)
120 {
121 set->depth--;
122 return NULL;
123 }
124 error = true;
125 reason = LC_RENAME;
126 from = map - 1;
127 }
128 else
129 {
130 from = INCLUDED_FROM (set, map - 1);
131 error = to_file && strcmp (from->to_file, to_file);
132 }
133
134 /* Depending upon whether we are handling preprocessed input or
135 not, this can be a user error or an ICE. */
136 if (error)
137 fprintf (stderr, "line-map.c: file \"%s\" left but not entered\n",
138 to_file);
139
140 /* A TO_FILE of NULL is special - we use the natural values. */
141 if (error || to_file == NULL)
142 {
143 to_file = from->to_file;
144 to_line = SOURCE_LINE (from, from[1].start_location);
145 sysp = from->sysp;
146 }
147 }
148
149 map->reason = reason;
150 map->sysp = sysp;
151 map->start_location = start_location;
152 map->to_file = to_file;
153 map->to_line = to_line;
154 set->cache = set->used++;
155 map->column_bits = 0;
156 set->highest_location = start_location;
157 set->highest_line = start_location;
158 set->max_column_hint = 0;
159
160 if (reason == LC_ENTER)
161 {
162 map->included_from = set->depth == 0 ? -1 : (int) (set->used - 2);
163 set->depth++;
164 if (set->trace_includes)
165 trace_include (set, map);
166 }
167 else if (reason == LC_RENAME)
168 map->included_from = map[-1].included_from;
169 else if (reason == LC_LEAVE)
170 {
171 set->depth--;
172 map->included_from = INCLUDED_FROM (set, map - 1)->included_from;
173 }
174
175 return map;
176 }