Mercurial > hg > CbC > CbC_gcc
annotate libcpp/pch.c @ 111:04ced10e8804
gcc 7
author | kono |
---|---|
date | Fri, 27 Oct 2017 22:46:09 +0900 |
parents | f6334be47118 |
children | 84e7813d76e9 |
rev | line source |
---|---|
0 | 1 /* Part of CPP library. (Precompiled header reading/writing.) |
111 | 2 Copyright (C) 2000-2017 Free Software Foundation, Inc. |
0 | 3 |
4 This program is free software; you can redistribute it and/or modify it | |
5 under the terms of the GNU General Public License as published by the | |
6 Free Software Foundation; either version 3, or (at your option) any | |
7 later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program; see the file COPYING3. If not see | |
16 <http://www.gnu.org/licenses/>. */ | |
17 | |
18 #include "config.h" | |
19 #include "system.h" | |
20 #include "cpplib.h" | |
21 #include "internal.h" | |
22 #include "hashtab.h" | |
23 #include "mkdeps.h" | |
24 | |
25 static int write_macdef (cpp_reader *, cpp_hashnode *, void *); | |
26 static int save_idents (cpp_reader *, cpp_hashnode *, void *); | |
27 static hashval_t hashmem (const void *, size_t); | |
28 static hashval_t cpp_string_hash (const void *); | |
29 static int cpp_string_eq (const void *, const void *); | |
30 static int count_defs (cpp_reader *, cpp_hashnode *, void *); | |
31 static int comp_hashnodes (const void *, const void *); | |
32 static int collect_ht_nodes (cpp_reader *, cpp_hashnode *, void *); | |
33 static int write_defs (cpp_reader *, cpp_hashnode *, void *); | |
34 static int save_macros (cpp_reader *, cpp_hashnode *, void *); | |
47
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
35 static int _cpp_save_pushed_macros (cpp_reader *, FILE *); |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
36 static int _cpp_restore_pushed_macros (cpp_reader *, FILE *); |
0 | 37 |
38 /* This structure represents a macro definition on disk. */ | |
39 struct macrodef_struct | |
40 { | |
41 unsigned int definition_length; | |
42 unsigned short name_length; | |
43 unsigned short flags; | |
44 }; | |
45 | |
46 /* This is how we write out a macro definition. | |
47 Suitable for being called by cpp_forall_identifiers. */ | |
48 | |
49 static int | |
50 write_macdef (cpp_reader *pfile, cpp_hashnode *hn, void *file_p) | |
51 { | |
52 FILE *f = (FILE *) file_p; | |
53 switch (hn->type) | |
54 { | |
55 case NT_VOID: | |
56 if (! (hn->flags & NODE_POISONED)) | |
57 return 1; | |
111 | 58 /* XXX Really fallthru? */ |
59 /* FALLTHRU */ | |
0 | 60 |
61 case NT_MACRO: | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
62 if ((hn->flags & NODE_BUILTIN) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
63 && (!pfile->cb.user_builtin_macro |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
64 || !pfile->cb.user_builtin_macro (pfile, hn))) |
0 | 65 return 1; |
66 | |
67 { | |
68 struct macrodef_struct s; | |
69 const unsigned char *defn; | |
70 | |
71 s.name_length = NODE_LEN (hn); | |
72 s.flags = hn->flags & NODE_POISONED; | |
73 | |
74 if (hn->type == NT_MACRO) | |
75 { | |
76 defn = cpp_macro_definition (pfile, hn); | |
77 s.definition_length = ustrlen (defn); | |
78 } | |
79 else | |
80 { | |
81 defn = NODE_NAME (hn); | |
82 s.definition_length = s.name_length; | |
83 } | |
84 | |
85 if (fwrite (&s, sizeof (s), 1, f) != 1 | |
86 || fwrite (defn, 1, s.definition_length, f) != s.definition_length) | |
87 { | |
88 cpp_errno (pfile, CPP_DL_ERROR, | |
89 "while writing precompiled header"); | |
90 return 0; | |
91 } | |
92 } | |
93 return 1; | |
94 | |
95 case NT_ASSERTION: | |
96 /* Not currently implemented. */ | |
97 return 1; | |
98 | |
99 default: | |
100 abort (); | |
101 } | |
102 } | |
103 | |
104 /* This structure records the names of the defined macros. | |
105 It's also used as a callback structure for size_initial_idents | |
106 and save_idents. */ | |
107 | |
108 struct cpp_savedstate | |
109 { | |
110 /* A hash table of the defined identifiers. */ | |
111 htab_t definedhash; | |
112 /* The size of the definitions of those identifiers (the size of | |
113 'definedstrs'). */ | |
114 size_t hashsize; | |
115 /* Number of definitions */ | |
116 size_t n_defs; | |
117 /* Array of definitions. In cpp_write_pch_deps it is used for sorting. */ | |
118 cpp_hashnode **defs; | |
119 /* Space for the next definition. Definitions are null-terminated | |
120 strings. */ | |
121 unsigned char *definedstrs; | |
122 }; | |
123 | |
124 /* Save this identifier into the state: put it in the hash table, | |
125 put the definition in 'definedstrs'. */ | |
126 | |
127 static int | |
128 save_idents (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p) | |
129 { | |
130 struct cpp_savedstate *const ss = (struct cpp_savedstate *)ss_p; | |
131 | |
132 if (hn->type != NT_VOID) | |
133 { | |
134 struct cpp_string news; | |
135 void **slot; | |
136 | |
137 news.len = NODE_LEN (hn); | |
138 news.text= NODE_NAME (hn); | |
139 slot = htab_find_slot (ss->definedhash, &news, INSERT); | |
140 if (*slot == NULL) | |
141 { | |
142 struct cpp_string *sp; | |
143 unsigned char *text; | |
144 | |
145 sp = XNEW (struct cpp_string); | |
146 *slot = sp; | |
147 | |
148 sp->len = NODE_LEN (hn); | |
149 sp->text = text = XNEWVEC (unsigned char, NODE_LEN (hn)); | |
150 memcpy (text, NODE_NAME (hn), NODE_LEN (hn)); | |
151 } | |
152 } | |
153 | |
154 return 1; | |
155 } | |
156 | |
157 /* Hash some memory in a generic way. */ | |
158 | |
159 static hashval_t | |
160 hashmem (const void *p_p, size_t sz) | |
161 { | |
162 const unsigned char *p = (const unsigned char *)p_p; | |
163 size_t i; | |
164 hashval_t h; | |
165 | |
166 h = 0; | |
167 for (i = 0; i < sz; i++) | |
168 h = h * 67 - (*p++ - 113); | |
169 return h; | |
170 } | |
171 | |
172 /* Hash a cpp string for the hashtable machinery. */ | |
173 | |
174 static hashval_t | |
175 cpp_string_hash (const void *a_p) | |
176 { | |
177 const struct cpp_string *a = (const struct cpp_string *) a_p; | |
178 return hashmem (a->text, a->len); | |
179 } | |
180 | |
181 /* Compare two cpp strings for the hashtable machinery. */ | |
182 | |
183 static int | |
184 cpp_string_eq (const void *a_p, const void *b_p) | |
185 { | |
186 const struct cpp_string *a = (const struct cpp_string *) a_p; | |
187 const struct cpp_string *b = (const struct cpp_string *) b_p; | |
188 return (a->len == b->len | |
189 && memcmp (a->text, b->text, a->len) == 0); | |
190 } | |
191 | |
111 | 192 /* Free memory associated with cpp_string. */ |
193 | |
194 static void | |
195 cpp_string_free (void *a_p) | |
196 { | |
197 struct cpp_string *a = (struct cpp_string *) a_p; | |
198 free ((void *) a->text); | |
199 free (a); | |
200 } | |
201 | |
0 | 202 /* Save the current definitions of the cpp_reader for dependency |
203 checking purposes. When writing a precompiled header, this should | |
204 be called at the same point in the compilation as cpp_valid_state | |
205 would be called when reading the precompiled header back in. */ | |
206 | |
207 int | |
208 cpp_save_state (cpp_reader *r, FILE *f) | |
209 { | |
210 /* Save the list of non-void identifiers for the dependency checking. */ | |
211 r->savedstate = XNEW (struct cpp_savedstate); | |
212 r->savedstate->definedhash = htab_create (100, cpp_string_hash, | |
111 | 213 cpp_string_eq, cpp_string_free); |
0 | 214 cpp_forall_identifiers (r, save_idents, r->savedstate); |
215 | |
216 /* Write out the list of defined identifiers. */ | |
217 cpp_forall_identifiers (r, write_macdef, f); | |
218 | |
219 return 0; | |
220 } | |
221 | |
222 /* Calculate the 'hashsize' field of the saved state. */ | |
223 | |
224 static int | |
225 count_defs (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p) | |
226 { | |
227 struct cpp_savedstate *const ss = (struct cpp_savedstate *)ss_p; | |
228 | |
229 switch (hn->type) | |
230 { | |
231 case NT_MACRO: | |
232 if (hn->flags & NODE_BUILTIN) | |
233 return 1; | |
234 | |
111 | 235 /* fall through. */ |
0 | 236 |
237 case NT_VOID: | |
238 { | |
239 struct cpp_string news; | |
240 void **slot; | |
241 | |
242 news.len = NODE_LEN (hn); | |
243 news.text = NODE_NAME (hn); | |
244 slot = (void **) htab_find (ss->definedhash, &news); | |
245 if (slot == NULL) | |
246 { | |
247 ss->hashsize += NODE_LEN (hn) + 1; | |
248 ss->n_defs += 1; | |
249 } | |
250 } | |
251 return 1; | |
252 | |
253 case NT_ASSERTION: | |
254 /* Not currently implemented. */ | |
255 return 1; | |
256 | |
257 default: | |
258 abort (); | |
259 } | |
260 } | |
261 | |
262 /* Collect the identifiers into the state's string table. */ | |
263 static int | |
264 write_defs (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p) | |
265 { | |
266 struct cpp_savedstate *const ss = (struct cpp_savedstate *)ss_p; | |
267 | |
268 switch (hn->type) | |
269 { | |
270 case NT_MACRO: | |
271 if (hn->flags & NODE_BUILTIN) | |
272 return 1; | |
273 | |
111 | 274 /* fall through. */ |
0 | 275 |
276 case NT_VOID: | |
277 { | |
278 struct cpp_string news; | |
279 void **slot; | |
280 | |
281 news.len = NODE_LEN (hn); | |
282 news.text = NODE_NAME (hn); | |
283 slot = (void **) htab_find (ss->definedhash, &news); | |
284 if (slot == NULL) | |
285 { | |
286 ss->defs[ss->n_defs] = hn; | |
287 ss->n_defs += 1; | |
288 } | |
289 } | |
290 return 1; | |
291 | |
292 case NT_ASSERTION: | |
293 /* Not currently implemented. */ | |
294 return 1; | |
295 | |
296 default: | |
297 abort (); | |
298 } | |
299 } | |
300 | |
301 /* Comparison function for qsort. The arguments point to pointers of | |
302 type ht_hashnode *. */ | |
303 static int | |
304 comp_hashnodes (const void *px, const void *py) | |
305 { | |
306 cpp_hashnode *x = *(cpp_hashnode **) px; | |
307 cpp_hashnode *y = *(cpp_hashnode **) py; | |
308 return ustrcmp (NODE_NAME (x), NODE_NAME (y)); | |
309 } | |
310 | |
311 /* Write out the remainder of the dependency information. This should be | |
312 called after the PCH is ready to be saved. */ | |
313 | |
314 int | |
315 cpp_write_pch_deps (cpp_reader *r, FILE *f) | |
316 { | |
317 struct macrodef_struct z; | |
318 struct cpp_savedstate *const ss = r->savedstate; | |
319 unsigned char *definedstrs; | |
320 size_t i; | |
321 | |
322 /* Collect the list of identifiers which have been seen and | |
323 weren't defined to anything previously. */ | |
324 ss->hashsize = 0; | |
325 ss->n_defs = 0; | |
326 cpp_forall_identifiers (r, count_defs, ss); | |
327 | |
328 ss->defs = XNEWVEC (cpp_hashnode *, ss->n_defs); | |
329 ss->n_defs = 0; | |
330 cpp_forall_identifiers (r, write_defs, ss); | |
331 | |
332 /* Sort the list, copy it into a buffer, and write it out. */ | |
333 qsort (ss->defs, ss->n_defs, sizeof (cpp_hashnode *), &comp_hashnodes); | |
334 definedstrs = ss->definedstrs = XNEWVEC (unsigned char, ss->hashsize); | |
335 for (i = 0; i < ss->n_defs; ++i) | |
336 { | |
337 size_t len = NODE_LEN (ss->defs[i]); | |
338 memcpy (definedstrs, NODE_NAME (ss->defs[i]), len + 1); | |
339 definedstrs += len + 1; | |
340 } | |
341 | |
342 memset (&z, 0, sizeof (z)); | |
343 z.definition_length = ss->hashsize; | |
344 if (fwrite (&z, sizeof (z), 1, f) != 1 | |
345 || fwrite (ss->definedstrs, ss->hashsize, 1, f) != 1) | |
346 { | |
347 cpp_errno (r, CPP_DL_ERROR, "while writing precompiled header"); | |
348 return -1; | |
349 } | |
350 free (ss->definedstrs); | |
111 | 351 free (ss->defs); |
352 htab_delete (ss->definedhash); | |
0 | 353 |
354 /* Free the saved state. */ | |
355 free (ss); | |
356 r->savedstate = NULL; | |
357 | |
358 /* Save the next value of __COUNTER__. */ | |
359 if (fwrite (&r->counter, sizeof (r->counter), 1, f) != 1) | |
360 { | |
361 cpp_errno (r, CPP_DL_ERROR, "while writing precompiled header"); | |
362 return -1; | |
363 } | |
364 | |
365 return 0; | |
366 } | |
367 | |
368 /* Write out the definitions of the preprocessor, in a form suitable for | |
369 cpp_read_state. */ | |
370 | |
371 int | |
372 cpp_write_pch_state (cpp_reader *r, FILE *f) | |
373 { | |
374 if (!r->deps) | |
375 r->deps = deps_init (); | |
376 | |
377 if (deps_save (r->deps, f) != 0) | |
378 { | |
379 cpp_errno (r, CPP_DL_ERROR, "while writing precompiled header"); | |
380 return -1; | |
381 } | |
382 | |
383 if (! _cpp_save_file_entries (r, f)) | |
384 { | |
385 cpp_errno (r, CPP_DL_ERROR, "while writing precompiled header"); | |
386 return -1; | |
387 } | |
388 | |
389 /* Save the next __COUNTER__ value. When we include a precompiled header, | |
390 we need to start at the offset we would have if the header had been | |
391 included normally. */ | |
392 if (fwrite (&r->counter, sizeof (r->counter), 1, f) != 1) | |
393 { | |
394 cpp_errno (r, CPP_DL_ERROR, "while writing precompiled header"); | |
395 return -1; | |
396 } | |
397 | |
47
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
398 /* Write saved macros. */ |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
399 if (! _cpp_save_pushed_macros (r, f)) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
400 { |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
401 cpp_errno (r, CPP_DL_ERROR, "while writing precompiled header"); |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
402 return -1; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
403 } |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
404 |
0 | 405 return 0; |
406 } | |
407 | |
47
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
408 static int |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
409 _cpp_restore_pushed_macros (cpp_reader *r, FILE *f) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
410 { |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
411 size_t count_saved = 0; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
412 size_t i; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
413 struct def_pragma_macro *p; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
414 size_t nlen; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
415 uchar *defn; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
416 size_t defnlen; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
417 |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
418 if (fread (&count_saved, sizeof (count_saved), 1, f) != 1) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
419 return 0; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
420 if (! count_saved) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
421 return 1; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
422 for (i = 0; i < count_saved; i++) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
423 { |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
424 if (fread (&nlen, sizeof (nlen), 1, f) != 1) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
425 return 0; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
426 p = XNEW (struct def_pragma_macro); |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
427 memset (p, 0, sizeof (struct def_pragma_macro)); |
47
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
428 p->name = XNEWVAR (char, nlen + 1); |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
429 p->name[nlen] = 0; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
430 if (fread (p->name, nlen, 1, f) != 1) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
431 return 0; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
432 if (fread (&defnlen, sizeof (defnlen), 1, f) != 1) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
433 return 0; |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
434 if (defnlen == 0) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
435 p->is_undef = 1; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
436 else |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
437 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
438 defn = XNEWVEC (uchar, defnlen + 1); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
439 defn[defnlen] = 0; |
47
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
440 |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
441 if (fread (defn, defnlen, 1, f) != 1) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
442 return 0; |
47
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
443 |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
444 p->definition = defn; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
445 if (fread (&(p->line), sizeof (source_location), 1, f) != 1) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
446 return 0; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
447 defnlen = 0; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
448 if (fread (&defnlen, sizeof (defnlen), 1, f) != 1) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
449 return 0; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
450 p->syshdr = ((defnlen & 1) != 0 ? 1 : 0); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
451 p->used = ((defnlen & 2) != 0 ? 1 : 0); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
452 } |
47
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
453 |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
454 p->next = r->pushed_macros; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
455 r->pushed_macros = p; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
456 } |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
457 return 1; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
458 } |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
459 |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
460 static int |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
461 _cpp_save_pushed_macros (cpp_reader *r, FILE *f) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
462 { |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
463 size_t count_saved = 0; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
464 size_t i; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
465 struct def_pragma_macro *p,**pp; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
466 size_t defnlen; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
467 |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
468 /* Get count. */ |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
469 p = r->pushed_macros; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
470 while (p != NULL) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
471 { |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
472 count_saved++; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
473 p = p->next; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
474 } |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
475 if (fwrite (&count_saved, sizeof (count_saved), 1, f) != 1) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
476 return 0; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
477 if (!count_saved) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
478 return 1; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
479 |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
480 pp = (struct def_pragma_macro **) alloca (sizeof (struct def_pragma_macro *) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
481 * count_saved); |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
482 /* Store them in reverse order. */ |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
483 p = r->pushed_macros; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
484 i = count_saved; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
485 while (p != NULL) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
486 { |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
487 --i; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
488 pp[i] = p; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
489 p = p->next; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
490 } |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
491 for (i = 0; i < count_saved; i++) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
492 { |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
493 defnlen = strlen (pp[i]->name); |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
494 if (fwrite (&defnlen, sizeof (size_t), 1, f) != 1 |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
495 || fwrite (pp[i]->name, defnlen, 1, f) != 1) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
496 return 0; |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
497 if (pp[i]->is_undef) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
498 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
499 defnlen = 0; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
500 if (fwrite (&defnlen, sizeof (size_t), 1, f) != 1) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
501 return 0; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
502 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
503 else |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
504 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
505 defnlen = ustrlen (pp[i]->definition); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
506 if (fwrite (&defnlen, sizeof (size_t), 1, f) != 1 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
507 || fwrite (pp[i]->definition, defnlen, 1, f) != 1) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
508 return 0; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
509 if (fwrite (&(pp[i]->line), sizeof (source_location), 1, f) != 1) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
510 return 0; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
511 defnlen = 0; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
512 defnlen |= (pp[i]->syshdr != 0 ? 1 : 0); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
513 defnlen |= (pp[i]->used != 0 ? 2 : 0); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
514 if (fwrite (&defnlen, sizeof (defnlen), 1, f) != 1) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
515 return 0; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
516 } |
47
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
517 } |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
518 return 1; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
519 } |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
520 |
0 | 521 |
522 /* Data structure to transform hash table nodes into a sorted list */ | |
523 | |
524 struct ht_node_list | |
525 { | |
526 /* Array of nodes */ | |
527 cpp_hashnode **defs; | |
528 /* Number of nodes in the array */ | |
529 size_t n_defs; | |
530 /* Size of the allocated array */ | |
531 size_t asize; | |
532 }; | |
533 | |
534 /* Callback for collecting identifiers from hash table */ | |
535 | |
536 static int | |
537 collect_ht_nodes (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, | |
538 void *nl_p) | |
539 { | |
540 struct ht_node_list *const nl = (struct ht_node_list *)nl_p; | |
541 | |
542 if (hn->type != NT_VOID || hn->flags & NODE_POISONED) | |
543 { | |
544 if (nl->n_defs == nl->asize) | |
545 { | |
546 nl->asize *= 2; | |
547 nl->defs = XRESIZEVEC (cpp_hashnode *, nl->defs, nl->asize); | |
548 } | |
549 | |
550 nl->defs[nl->n_defs] = hn; | |
551 ++nl->n_defs; | |
552 } | |
553 return 1; | |
554 } | |
555 | |
556 | |
557 /* Return nonzero if FD is a precompiled header which is consistent | |
558 with the preprocessor's current definitions. It will be consistent | |
559 when: | |
560 | |
561 - anything that was defined just before the PCH was generated | |
562 is defined the same way now; and | |
563 - anything that was not defined then, but is defined now, was not | |
564 used by the PCH. | |
565 | |
566 NAME is used to print warnings if `warn_invalid_pch' is set in the | |
567 reader's flags. | |
568 */ | |
569 | |
570 int | |
571 cpp_valid_state (cpp_reader *r, const char *name, int fd) | |
572 { | |
573 struct macrodef_struct m; | |
574 size_t namebufsz = 256; | |
575 unsigned char *namebuf = XNEWVEC (unsigned char, namebufsz); | |
576 unsigned char *undeftab = NULL; | |
577 struct ht_node_list nl = { 0, 0, 0 }; | |
578 unsigned char *first, *last; | |
579 unsigned int i; | |
580 unsigned int counter; | |
581 | |
582 /* Read in the list of identifiers that must be defined | |
583 Check that they are defined in the same way. */ | |
584 for (;;) | |
585 { | |
586 cpp_hashnode *h; | |
587 const unsigned char *newdefn; | |
588 | |
589 if (read (fd, &m, sizeof (m)) != sizeof (m)) | |
590 goto error; | |
591 | |
592 if (m.name_length == 0) | |
593 break; | |
594 | |
595 /* If this file is already preprocessed, there won't be any | |
596 macros defined, and that's OK. */ | |
597 if (CPP_OPTION (r, preprocessed)) | |
598 { | |
599 if (lseek (fd, m.definition_length, SEEK_CUR) == -1) | |
600 goto error; | |
601 continue; | |
602 } | |
603 | |
604 if (m.definition_length > namebufsz) | |
605 { | |
606 free (namebuf); | |
607 namebufsz = m.definition_length + 256; | |
608 namebuf = XNEWVEC (unsigned char, namebufsz); | |
609 } | |
610 | |
611 if ((size_t)read (fd, namebuf, m.definition_length) | |
612 != m.definition_length) | |
613 goto error; | |
614 | |
615 h = cpp_lookup (r, namebuf, m.name_length); | |
616 if (m.flags & NODE_POISONED | |
617 || h->flags & NODE_POISONED) | |
618 { | |
619 if (CPP_OPTION (r, warn_invalid_pch)) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
620 cpp_warning_syshdr (r, CPP_W_INVALID_PCH, |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
621 "%s: not used because `%.*s' is poisoned", |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
622 name, m.name_length, namebuf); |
0 | 623 goto fail; |
624 } | |
625 | |
626 if (h->type != NT_MACRO) | |
627 { | |
628 /* It's ok if __GCC_HAVE_DWARF2_CFI_ASM becomes undefined, | |
629 as in, when the PCH file is created with -g and we're | |
630 attempting to use it without -g. Restoring the PCH file | |
631 is supposed to bring in this definition *and* enable the | |
632 generation of call frame information, so that precompiled | |
111 | 633 definitions that take this macro into account, to decide |
0 | 634 what asm to emit, won't issue .cfi directives when the |
635 compiler doesn't. */ | |
636 if (!(h->flags & NODE_USED) | |
637 && m.name_length == sizeof ("__GCC_HAVE_DWARF2_CFI_ASM") - 1 | |
638 && !memcmp (namebuf, "__GCC_HAVE_DWARF2_CFI_ASM", m.name_length)) | |
639 continue; | |
640 | |
641 if (CPP_OPTION (r, warn_invalid_pch)) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
642 cpp_warning_syshdr (r, CPP_W_INVALID_PCH, |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
643 "%s: not used because `%.*s' not defined", |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
644 name, m.name_length, namebuf); |
0 | 645 goto fail; |
646 } | |
647 | |
648 newdefn = cpp_macro_definition (r, h); | |
649 | |
650 if (m.definition_length != ustrlen (newdefn) | |
651 || memcmp (namebuf, newdefn, m.definition_length) != 0) | |
652 { | |
653 if (CPP_OPTION (r, warn_invalid_pch)) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
654 cpp_warning_syshdr (r, CPP_W_INVALID_PCH, |
0 | 655 "%s: not used because `%.*s' defined as `%s' not `%.*s'", |
656 name, m.name_length, namebuf, newdefn + m.name_length, | |
657 m.definition_length - m.name_length, | |
658 namebuf + m.name_length); | |
659 goto fail; | |
660 } | |
661 } | |
662 free (namebuf); | |
663 namebuf = NULL; | |
664 | |
665 /* Read in the list of identifiers that must not be defined. | |
666 Check that they really aren't. */ | |
667 undeftab = XNEWVEC (unsigned char, m.definition_length); | |
668 if ((size_t) read (fd, undeftab, m.definition_length) != m.definition_length) | |
669 goto error; | |
670 | |
671 /* Collect identifiers from the current hash table. */ | |
672 nl.n_defs = 0; | |
673 nl.asize = 10; | |
674 nl.defs = XNEWVEC (cpp_hashnode *, nl.asize); | |
675 cpp_forall_identifiers (r, &collect_ht_nodes, &nl); | |
676 qsort (nl.defs, nl.n_defs, sizeof (cpp_hashnode *), &comp_hashnodes); | |
677 | |
678 /* Loop through nl.defs and undeftab, both of which are sorted lists. | |
679 There should be no matches. */ | |
680 first = undeftab; | |
681 last = undeftab + m.definition_length; | |
682 i = 0; | |
683 | |
684 while (first < last && i < nl.n_defs) | |
685 { | |
686 int cmp = ustrcmp (first, NODE_NAME (nl.defs[i])); | |
687 | |
688 if (cmp < 0) | |
689 first += ustrlen (first) + 1; | |
690 else if (cmp > 0) | |
691 ++i; | |
692 else | |
693 { | |
694 if (CPP_OPTION (r, warn_invalid_pch)) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
695 cpp_warning_syshdr (r, CPP_W_INVALID_PCH, |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
696 "%s: not used because `%s' is defined", |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
697 name, first); |
0 | 698 goto fail; |
699 } | |
700 } | |
701 | |
702 free(nl.defs); | |
703 nl.defs = NULL; | |
704 free (undeftab); | |
705 undeftab = NULL; | |
706 | |
707 /* Read in the next value of __COUNTER__. | |
708 Check that (a) __COUNTER__ was not used in the pch or (b) __COUNTER__ | |
709 has not been used in this translation unit. */ | |
710 if (read (fd, &counter, sizeof (counter)) != sizeof (counter)) | |
711 goto error; | |
712 if (counter && r->counter) | |
713 { | |
714 if (CPP_OPTION (r, warn_invalid_pch)) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
715 cpp_warning_syshdr (r, CPP_W_INVALID_PCH, |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
716 "%s: not used because `__COUNTER__' is invalid", |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
717 name); |
111 | 718 goto fail; |
0 | 719 } |
720 | |
721 /* We win! */ | |
722 return 0; | |
723 | |
724 error: | |
725 cpp_errno (r, CPP_DL_ERROR, "while reading precompiled header"); | |
726 | |
727 fail: | |
111 | 728 free (namebuf); |
729 free (undeftab); | |
730 free (nl.defs); | |
0 | 731 return 1; |
732 } | |
733 | |
734 /* Save all the existing macros. */ | |
735 | |
736 struct save_macro_data | |
737 { | |
738 uchar **defns; | |
739 size_t count; | |
740 size_t array_size; | |
741 char **saved_pragmas; | |
742 }; | |
743 | |
744 /* Save the definition of a single macro, so that it will persist | |
745 across a PCH restore. Because macro data is in GCed memory, which | |
746 will be blown away by PCH, it must be temporarily copied to | |
747 malloced memory. (The macros will refer to identifier nodes which | |
748 are also GCed and so on, so the copying is done by turning them | |
749 into self-contained strings.) The assumption is that most macro | |
750 definitions will come from the PCH file, not from the compilation | |
751 before the PCH file is loaded, so it doesn't matter that this is | |
752 a little expensive. | |
753 | |
754 It would reduce the cost even further if macros defined in the PCH | |
755 file were not saved in this way, but this is not done (yet), except | |
756 for builtins, and for #assert by default. */ | |
757 | |
758 static int | |
759 save_macros (cpp_reader *r, cpp_hashnode *h, void *data_p) | |
760 { | |
761 struct save_macro_data *data = (struct save_macro_data *)data_p; | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
762 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
763 if ((h->flags & NODE_BUILTIN) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
764 && h->type == NT_MACRO |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
765 && r->cb.user_builtin_macro) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
766 r->cb.user_builtin_macro (r, h); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
767 |
0 | 768 if (h->type != NT_VOID |
769 && (h->flags & NODE_BUILTIN) == 0) | |
770 { | |
771 if (data->count == data->array_size) | |
772 { | |
773 data->array_size *= 2; | |
774 data->defns = XRESIZEVEC (uchar *, data->defns, (data->array_size)); | |
775 } | |
776 | |
777 switch (h->type) | |
778 { | |
779 case NT_ASSERTION: | |
780 /* Not currently implemented. */ | |
781 return 1; | |
782 | |
783 case NT_MACRO: | |
784 { | |
785 const uchar * defn = cpp_macro_definition (r, h); | |
786 size_t defnlen = ustrlen (defn); | |
787 | |
788 data->defns[data->count] = (uchar *) xmemdup (defn, defnlen, | |
789 defnlen + 2); | |
790 data->defns[data->count][defnlen] = '\n'; | |
791 } | |
792 break; | |
793 | |
794 default: | |
795 abort (); | |
796 } | |
797 data->count++; | |
798 } | |
799 return 1; | |
800 } | |
801 | |
802 /* Prepare to restore the state, by saving the currently-defined | |
803 macros in 'data'. */ | |
804 | |
805 void | |
806 cpp_prepare_state (cpp_reader *r, struct save_macro_data **data) | |
807 { | |
808 struct save_macro_data *d = XNEW (struct save_macro_data); | |
809 | |
810 d->array_size = 512; | |
811 d->defns = XNEWVEC (uchar *, d->array_size); | |
812 d->count = 0; | |
813 cpp_forall_identifiers (r, save_macros, d); | |
814 d->saved_pragmas = _cpp_save_pragma_names (r); | |
815 *data = d; | |
816 } | |
817 | |
818 /* Given a precompiled header that was previously determined to be valid, | |
819 apply all its definitions (and undefinitions) to the current state. | |
820 DEPNAME is passed to deps_restore. */ | |
821 | |
822 int | |
823 cpp_read_state (cpp_reader *r, const char *name, FILE *f, | |
824 struct save_macro_data *data) | |
825 { | |
826 size_t i; | |
827 struct lexer_state old_state; | |
828 unsigned int counter; | |
829 | |
830 /* Restore spec_nodes, which will be full of references to the old | |
831 hashtable entries and so will now be invalid. */ | |
832 { | |
833 struct spec_nodes *s = &r->spec_nodes; | |
834 s->n_defined = cpp_lookup (r, DSC("defined")); | |
835 s->n_true = cpp_lookup (r, DSC("true")); | |
836 s->n_false = cpp_lookup (r, DSC("false")); | |
837 s->n__VA_ARGS__ = cpp_lookup (r, DSC("__VA_ARGS__")); | |
111 | 838 s->n__has_include__ = cpp_lookup (r, DSC("__has_include__")); |
839 s->n__has_include_next__ = cpp_lookup (r, DSC("__has_include_next__")); | |
0 | 840 } |
841 | |
842 old_state = r->state; | |
843 r->state.in_directive = 1; | |
844 r->state.prevent_expansion = 1; | |
845 r->state.angled_headers = 0; | |
846 | |
847 /* Run through the carefully-saved macros, insert them. */ | |
848 for (i = 0; i < data->count; i++) | |
849 { | |
850 cpp_hashnode *h; | |
851 size_t namelen; | |
852 uchar *defn; | |
853 | |
854 namelen = ustrcspn (data->defns[i], "( \n"); | |
855 h = cpp_lookup (r, data->defns[i], namelen); | |
856 defn = data->defns[i] + namelen; | |
857 | |
858 /* The PCH file is valid, so we know that if there is a definition | |
859 from the PCH file it must be the same as the one we had | |
860 originally, and so do not need to restore it. */ | |
861 if (h->type == NT_VOID) | |
862 { | |
863 if (cpp_push_buffer (r, defn, ustrchr (defn, '\n') - defn, true) | |
864 != NULL) | |
865 { | |
866 _cpp_clean_line (r); | |
867 if (!_cpp_create_definition (r, h)) | |
868 abort (); | |
869 _cpp_pop_buffer (r); | |
870 } | |
871 else | |
872 abort (); | |
873 } | |
874 | |
875 free (data->defns[i]); | |
876 } | |
877 r->state = old_state; | |
878 | |
879 _cpp_restore_pragma_names (r, data->saved_pragmas); | |
880 | |
881 free (data); | |
882 | |
883 if (deps_restore (r->deps, f, CPP_OPTION (r, restore_pch_deps) ? name : NULL) | |
884 != 0) | |
885 goto error; | |
886 | |
887 if (! _cpp_read_file_entries (r, f)) | |
888 goto error; | |
889 | |
890 if (fread (&counter, sizeof (counter), 1, f) != 1) | |
891 goto error; | |
892 | |
893 if (!r->counter) | |
894 r->counter = counter; | |
895 | |
47
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
896 /* Read pushed macros. */ |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
897 if (! _cpp_restore_pushed_macros (r, f)) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
898 goto error; |
0 | 899 return 0; |
900 | |
901 error: | |
902 cpp_errno (r, CPP_DL_ERROR, "while reading precompiled header"); | |
903 return -1; | |
904 } |