Mercurial > hg > CbC > CbC_gcc
comparison libcpp/pch.c @ 47:3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
author | kent <kent@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 07 Feb 2010 17:44:34 +0900 |
parents | a06113de4d67 |
children | b7f97abdc517 |
comparison
equal
deleted
inserted
replaced
46:b85a337e5837 | 47:3bfb6c00c1e0 |
---|---|
31 static int count_defs (cpp_reader *, cpp_hashnode *, void *); | 31 static int count_defs (cpp_reader *, cpp_hashnode *, void *); |
32 static int comp_hashnodes (const void *, const void *); | 32 static int comp_hashnodes (const void *, const void *); |
33 static int collect_ht_nodes (cpp_reader *, cpp_hashnode *, void *); | 33 static int collect_ht_nodes (cpp_reader *, cpp_hashnode *, void *); |
34 static int write_defs (cpp_reader *, cpp_hashnode *, void *); | 34 static int write_defs (cpp_reader *, cpp_hashnode *, void *); |
35 static int save_macros (cpp_reader *, cpp_hashnode *, void *); | 35 static int save_macros (cpp_reader *, cpp_hashnode *, void *); |
36 static int _cpp_save_pushed_macros (cpp_reader *, FILE *); | |
37 static int _cpp_restore_pushed_macros (cpp_reader *, FILE *); | |
36 | 38 |
37 /* This structure represents a macro definition on disk. */ | 39 /* This structure represents a macro definition on disk. */ |
38 struct macrodef_struct | 40 struct macrodef_struct |
39 { | 41 { |
40 unsigned int definition_length; | 42 unsigned int definition_length; |
376 { | 378 { |
377 cpp_errno (r, CPP_DL_ERROR, "while writing precompiled header"); | 379 cpp_errno (r, CPP_DL_ERROR, "while writing precompiled header"); |
378 return -1; | 380 return -1; |
379 } | 381 } |
380 | 382 |
383 /* Write saved macros. */ | |
384 if (! _cpp_save_pushed_macros (r, f)) | |
385 { | |
386 cpp_errno (r, CPP_DL_ERROR, "while writing precompiled header"); | |
387 return -1; | |
388 } | |
389 | |
381 return 0; | 390 return 0; |
391 } | |
392 | |
393 static int | |
394 _cpp_restore_pushed_macros (cpp_reader *r, FILE *f) | |
395 { | |
396 size_t count_saved = 0; | |
397 size_t i; | |
398 struct def_pragma_macro *p; | |
399 size_t nlen; | |
400 cpp_hashnode *h = NULL; | |
401 cpp_macro *m; | |
402 uchar *defn; | |
403 size_t defnlen; | |
404 | |
405 if (fread (&count_saved, sizeof (count_saved), 1, f) != 1) | |
406 return 0; | |
407 if (! count_saved) | |
408 return 1; | |
409 for (i = 0; i < count_saved; i++) | |
410 { | |
411 if (fread (&nlen, sizeof (nlen), 1, f) != 1) | |
412 return 0; | |
413 p = XNEW (struct def_pragma_macro); | |
414 p->name = XNEWVAR (char, nlen + 1); | |
415 p->name[nlen] = 0; | |
416 if (fread (p->name, nlen, 1, f) != 1) | |
417 return 0; | |
418 /* Save old state. */ | |
419 m = cpp_push_definition (r, p->name); | |
420 if (fread (&defnlen, sizeof (defnlen), 1, f) != 1) | |
421 return 0; | |
422 defn = XNEWVAR (uchar, defnlen + 2); | |
423 defn[defnlen] = '\n'; | |
424 defn[defnlen + 1] = 0; | |
425 | |
426 if (fread (defn, defnlen, 1, f) != 1) | |
427 return 0; | |
428 cpp_pop_definition (r, p->name, NULL); | |
429 { | |
430 size_t namelen; | |
431 uchar *dn; | |
432 | |
433 namelen = ustrcspn (defn, "( \n"); | |
434 h = cpp_lookup (r, defn, namelen); | |
435 dn = defn + namelen; | |
436 | |
437 h->type = NT_VOID; | |
438 h->flags &= ~(NODE_POISONED|NODE_BUILTIN|NODE_DISABLED|NODE_USED); | |
439 if (cpp_push_buffer (r, dn, ustrchr (dn, '\n') - dn, true) | |
440 != NULL) | |
441 { | |
442 _cpp_clean_line (r); | |
443 if (!_cpp_create_definition (r, h)) | |
444 abort (); | |
445 _cpp_pop_buffer (r); | |
446 } | |
447 else | |
448 abort (); | |
449 } | |
450 p->value = cpp_push_definition (r, p->name); | |
451 | |
452 free (defn); | |
453 p->next = r->pushed_macros; | |
454 r->pushed_macros = p; | |
455 /* Restore current state. */ | |
456 cpp_pop_definition (r, p->name, m); | |
457 } | |
458 return 1; | |
459 } | |
460 | |
461 static int | |
462 _cpp_save_pushed_macros (cpp_reader *r, FILE *f) | |
463 { | |
464 size_t count_saved = 0; | |
465 size_t i; | |
466 struct def_pragma_macro *p,**pp; | |
467 cpp_hashnode *node; | |
468 cpp_macro *m; | |
469 size_t defnlen; | |
470 const uchar *defn; | |
471 | |
472 /* Get count. */ | |
473 p = r->pushed_macros; | |
474 while (p != NULL) | |
475 { | |
476 count_saved++; | |
477 p = p->next; | |
478 } | |
479 if (fwrite (&count_saved, sizeof (count_saved), 1, f) != 1) | |
480 return 0; | |
481 if (!count_saved) | |
482 return 1; | |
483 | |
484 pp = (struct def_pragma_macro **) alloca (sizeof (struct def_pragma_macro *) | |
485 * count_saved); | |
486 /* Store them in reverse order. */ | |
487 p = r->pushed_macros; | |
488 i = count_saved; | |
489 while (p != NULL) | |
490 { | |
491 --i; | |
492 pp[i] = p; | |
493 p = p->next; | |
494 } | |
495 for (i = 0; i < count_saved; i++) | |
496 { | |
497 /* Save old state. */ | |
498 m = cpp_push_definition (r, pp[i]->name); | |
499 /* Set temporary macro name to saved state. */ | |
500 cpp_pop_definition (r, pp[i]->name, pp[i]->value); | |
501 node = _cpp_lex_identifier (r, pp[i]->name); | |
502 defnlen = strlen (pp[i]->name); | |
503 if (fwrite (&defnlen, sizeof (size_t), 1, f) != 1 | |
504 || fwrite (pp[i]->name, defnlen, 1, f) != 1) | |
505 return 0; | |
506 defn = cpp_macro_definition (r, node); | |
507 defnlen = ustrlen (defn); | |
508 if (fwrite (&defnlen, sizeof (size_t), 1, f) != 1 | |
509 || fwrite (defn, defnlen, 1, f) != 1) | |
510 return 0; | |
511 /* Restore current state. */ | |
512 cpp_pop_definition (r, pp[i]->name, m); | |
513 } | |
514 return 1; | |
382 } | 515 } |
383 | 516 |
384 | 517 |
385 /* Data structure to transform hash table nodes into a sorted list */ | 518 /* Data structure to transform hash table nodes into a sorted list */ |
386 | 519 |
750 goto error; | 883 goto error; |
751 | 884 |
752 if (!r->counter) | 885 if (!r->counter) |
753 r->counter = counter; | 886 r->counter = counter; |
754 | 887 |
888 /* Read pushed macros. */ | |
889 if (! _cpp_restore_pushed_macros (r, f)) | |
890 goto error; | |
755 return 0; | 891 return 0; |
756 | 892 |
757 error: | 893 error: |
758 cpp_errno (r, CPP_DL_ERROR, "while reading precompiled header"); | 894 cpp_errno (r, CPP_DL_ERROR, "while reading precompiled header"); |
759 return -1; | 895 return -1; |