Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: gcc/libcpp/files.c

Issue 3050029: [gcc] GCC 4.5.0=>4.5.1 (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/nacl-toolchain.git
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gcc/libcpp/expr.c ('k') | gcc/libcpp/internal.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Part of CPP library. File handling. 1 /* Part of CPP library. File handling.
2 Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1998, 2 Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 Free Software Foundation, Inc. 4 Free Software Foundation, Inc.
5 Written by Per Bothner, 1994. 5 Written by Per Bothner, 1994.
6 Based on CCCP program by Paul Rubin, June 1986 6 Based on CCCP program by Paul Rubin, June 1986
7 Adapted to ANSI C, Richard Stallman, Jan 1987 7 Adapted to ANSI C, Richard Stallman, Jan 1987
8 Split out of cpplib.c, Zack Weinberg, Oct 1998 8 Split out of cpplib.c, Zack Weinberg, Oct 1998
9 Reimplemented, Neil Booth, Jul 2003 9 Reimplemented, Neil Booth, Jul 2003
10 10
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 const char *path = file->path; 281 const char *path = file->path;
282 size_t len, flen; 282 size_t len, flen;
283 char *pchname; 283 char *pchname;
284 struct stat st; 284 struct stat st;
285 bool valid = false; 285 bool valid = false;
286 286
287 /* No PCH on <stdin> or if not requested. */ 287 /* No PCH on <stdin> or if not requested. */
288 if (file->name[0] == '\0' || !pfile->cb.valid_pch) 288 if (file->name[0] == '\0' || !pfile->cb.valid_pch)
289 return false; 289 return false;
290 290
291 /* If the file is not included as first include from either the toplevel
292 file or the command-line it is not a valid use of PCH. */
293 if (pfile->all_files
294 && pfile->all_files->next_file)
295 return false;
296
291 flen = strlen (path); 297 flen = strlen (path);
292 len = flen + sizeof (extension); 298 len = flen + sizeof (extension);
293 pchname = XNEWVEC (char, len); 299 pchname = XNEWVEC (char, len);
294 memcpy (pchname, path, flen); 300 memcpy (pchname, path, flen);
295 memcpy (pchname + flen, extension, sizeof (extension)); 301 memcpy (pchname + flen, extension, sizeof (extension));
296 302
297 if (stat (pchname, &st) == 0) 303 if (stat (pchname, &st) == 0)
298 { 304 {
299 DIR *pchdir; 305 DIR *pchdir;
300 struct dirent *d; 306 struct dirent *d;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 380
375 if (file->err_no != ENOENT) 381 if (file->err_no != ENOENT)
376 { 382 {
377 open_file_failed (pfile, file, 0); 383 open_file_failed (pfile, file, 0);
378 return true; 384 return true;
379 } 385 }
380 386
381 /* We copy the path name onto an obstack partly so that we don't 387 /* We copy the path name onto an obstack partly so that we don't
382 leak the memory, but mostly so that we don't fragment the 388 leak the memory, but mostly so that we don't fragment the
383 heap. */ 389 heap. */
384 copy = obstack_copy0 (&pfile->nonexistent_file_ob, path, 390 copy = (char *) obstack_copy0 (&pfile->nonexistent_file_ob, path,
385 » » » strlen (path)); 391 » » » » strlen (path));
386 free (path); 392 free (path);
387 pp = htab_find_slot_with_hash (pfile->nonexistent_file_hash, 393 pp = htab_find_slot_with_hash (pfile->nonexistent_file_hash,
388 copy, hv, INSERT); 394 copy, hv, INSERT);
389 *pp = copy; 395 *pp = copy;
390 396
391 file->path = file->name; 397 file->path = file->name;
392 } 398 }
393 else 399 else
394 { 400 {
395 file->err_no = ENOENT; 401 file->err_no = ENOENT;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 { 487 {
482 /* Although this file must not go in the cache, because 488 /* Although this file must not go in the cache, because
483 the file found might depend on things (like the current file) 489 the file found might depend on things (like the current file)
484 that aren't represented in the cache, it still has to go in 490 that aren't represented in the cache, it still has to go in
485 the list of all files so that #import works. */ 491 the list of all files so that #import works. */
486 file->next_file = pfile->all_files; 492 file->next_file = pfile->all_files;
487 pfile->all_files = file; 493 pfile->all_files = file;
488 return file; 494 return file;
489 } 495 }
490 496
491 open_file_failed (pfile, file, angle_brackets);
492 if (invalid_pch) 497 if (invalid_pch)
493 { 498 {
494 cpp_error (pfile, CPP_DL_ERROR, 499 cpp_error (pfile, CPP_DL_ERROR,
495 "one or more PCH files were found, but they were invalid"); 500 "one or more PCH files were found, but they were invalid");
496 if (!cpp_get_options (pfile)->warn_invalid_pch) 501 if (!cpp_get_options (pfile)->warn_invalid_pch)
497 cpp_error (pfile, CPP_DL_ERROR, 502 cpp_error (pfile, CPP_DL_ERROR,
498 "use -Winvalid-pch for more information"); 503 "use -Winvalid-pch for more information");
499 } 504 }
505 open_file_failed (pfile, file, angle_brackets);
500 break; 506 break;
501 } 507 }
502 508
503 /* Only check the cache for the starting location (done above) 509 /* Only check the cache for the starting location (done above)
504 and the quote and bracket chain heads because there are no 510 and the quote and bracket chain heads because there are no
505 other possible starting points for searches. */ 511 other possible starting points for searches. */
506 if (file->dir == pfile->bracket_include) 512 if (file->dir == pfile->bracket_include)
507 saw_bracket_include = true; 513 saw_bracket_include = true;
508 else if (file->dir == pfile->quote_include) 514 else if (file->dir == pfile->quote_include)
509 saw_quote_include = true; 515 saw_quote_include = true;
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 { 911 {
906 struct cpp_dir *dir; 912 struct cpp_dir *dir;
907 _cpp_file *file; 913 _cpp_file *file;
908 914
909 dir = search_path_head (pfile, fname, angle_brackets, type); 915 dir = search_path_head (pfile, fname, angle_brackets, type);
910 if (!dir) 916 if (!dir)
911 return false; 917 return false;
912 918
913 file = _cpp_find_file (pfile, fname, dir, false, angle_brackets); 919 file = _cpp_find_file (pfile, fname, dir, false, angle_brackets);
914 920
915 /* Compensate for the increment in linemap_add. In the case of a 921 /* Compensate for the increment in linemap_add that occurs in
916 normal #include, we're currently at the start of the line 922 _cpp_stack_file. In the case of a normal #include, we're
917 *following* the #include. A separate source_location for this 923 currently at the start of the line *following* the #include. A
918 location makes no sense (until we do the LC_LEAVE), and 924 separate source_location for this location makes no sense (until
919 complicates LAST_SOURCE_LINE_LOCATION. This does not apply if we 925 we do the LC_LEAVE), and complicates LAST_SOURCE_LINE_LOCATION.
920 found a PCH file (in which case linemap_add is not called) or we 926 This does not apply if we found a PCH file (in which case
921 were included from the command-line. */ 927 linemap_add is not called) or we were included from the
928 command-line. */
922 if (file->pchname == NULL && file->err_no == 0 && type != IT_CMDLINE) 929 if (file->pchname == NULL && file->err_no == 0 && type != IT_CMDLINE)
923 pfile->line_table->highest_location--; 930 pfile->line_table->highest_location--;
924 931
925 return _cpp_stack_file (pfile, file, type == IT_IMPORT); 932 return _cpp_stack_file (pfile, file, type == IT_IMPORT);
926 } 933 }
927 934
928 /* Could not open FILE. The complication is dependency output. */ 935 /* Could not open FILE. The complication is dependency output. */
929 static void 936 static void
930 open_file_failed (cpp_reader *pfile, _cpp_file *file, int angle_brackets) 937 open_file_failed (cpp_reader *pfile, _cpp_file *file, int angle_brackets)
931 { 938 {
932 int sysp = pfile->line_table->highest_line > 1 && pfile->buffer ? pfile->buffe r->sysp : 0; 939 int sysp = pfile->line_table->highest_line > 1 && pfile->buffer ? pfile->buffe r->sysp : 0;
933 bool print_dep = CPP_OPTION (pfile, deps.style) > (angle_brackets || !!sysp); 940 bool print_dep = CPP_OPTION (pfile, deps.style) > (angle_brackets || !!sysp);
934 941
935 errno = file->err_no; 942 errno = file->err_no;
936 if (print_dep && CPP_OPTION (pfile, deps.missing_files) && errno == ENOENT) 943 if (print_dep && CPP_OPTION (pfile, deps.missing_files) && errno == ENOENT)
937 deps_add_dep (pfile->deps, file->name); 944 {
945 deps_add_dep (pfile->deps, file->name);
946 /* If the preprocessor output (other than dependency information) is
947 being used, we must also flag an error. */
948 if (CPP_OPTION (pfile, deps.need_preprocessor_output))
949 » cpp_errno (pfile, CPP_DL_FATAL, file->path);
950 }
938 else 951 else
939 { 952 {
940 /* If we are outputting dependencies but not for this file then 953 /* If we are not outputting dependencies, or if we are and dependencies
941 » don't error because we can still produce correct output. */ 954 were requested for this file, or if preprocessor output is needed
942 if (CPP_OPTION (pfile, deps.style) && ! print_dep) 955 in addition to dependency information, this is an error.
956
957 Otherwise (outputting dependencies but not for this file, and not
958 using the preprocessor output), we can still produce correct output
959 so it's only a warning. */
960 if (CPP_OPTION (pfile, deps.style) == DEPS_NONE
961 || print_dep
962 || CPP_OPTION (pfile, deps.need_preprocessor_output))
963 » cpp_errno (pfile, CPP_DL_FATAL, file->path);
964 else
943 cpp_errno (pfile, CPP_DL_WARNING, file->path); 965 cpp_errno (pfile, CPP_DL_WARNING, file->path);
944 else
945 cpp_errno (pfile, CPP_DL_ERROR, file->path);
946 } 966 }
947 } 967 }
948 968
949 /* Search in the chain beginning at HEAD for a file whose search path 969 /* Search in the chain beginning at HEAD for a file whose search path
950 started at START_DIR != NULL. */ 970 started at START_DIR != NULL. */
951 static struct file_hash_entry * 971 static struct file_hash_entry *
952 search_cache (struct file_hash_entry *head, const cpp_dir *start_dir) 972 search_cache (struct file_hash_entry *head, const cpp_dir *start_dir)
953 { 973 {
954 while (head && head->start_dir != start_dir) 974 while (head && head->start_dir != start_dir)
955 head = head->next; 975 head = head->next;
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 hname = entry->u.dir->name; 1156 hname = entry->u.dir->name;
1137 1157
1138 return strcmp (hname, fname) == 0; 1158 return strcmp (hname, fname) == 0;
1139 } 1159 }
1140 1160
1141 /* Compare entries in the nonexistent file hash table. These are just 1161 /* Compare entries in the nonexistent file hash table. These are just
1142 strings. */ 1162 strings. */
1143 static int 1163 static int
1144 nonexistent_file_hash_eq (const void *p, const void *q) 1164 nonexistent_file_hash_eq (const void *p, const void *q)
1145 { 1165 {
1146 return strcmp (p, q) == 0; 1166 return strcmp ((const char *) p, (const char *) q) == 0;
1147 } 1167 }
1148 1168
1149 /* Initialize everything in this source file. */ 1169 /* Initialize everything in this source file. */
1150 void 1170 void
1151 _cpp_init_files (cpp_reader *pfile) 1171 _cpp_init_files (cpp_reader *pfile)
1152 { 1172 {
1153 pfile->file_hash = htab_create_alloc (127, file_hash_hash, file_hash_eq, 1173 pfile->file_hash = htab_create_alloc (127, file_hash_hash, file_hash_eq,
1154 NULL, xcalloc, free); 1174 NULL, xcalloc, free);
1155 pfile->dir_hash = htab_create_alloc (127, file_hash_hash, file_hash_eq, 1175 pfile->dir_hash = htab_create_alloc (127, file_hash_hash, file_hash_eq,
1156 NULL, xcalloc, free); 1176 NULL, xcalloc, free);
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
1798 || (! check_included && ! pchf->have_once_only)) 1818 || (! check_included && ! pchf->have_once_only))
1799 return false; 1819 return false;
1800 1820
1801 d.size = f->st.st_size; 1821 d.size = f->st.st_size;
1802 d.sum_computed = false; 1822 d.sum_computed = false;
1803 d.f = f; 1823 d.f = f;
1804 d.check_included = check_included; 1824 d.check_included = check_included;
1805 return bsearch (&d, pchf->entries, pchf->count, sizeof (struct pchf_entry), 1825 return bsearch (&d, pchf->entries, pchf->count, sizeof (struct pchf_entry),
1806 pchf_compare) != NULL; 1826 pchf_compare) != NULL;
1807 } 1827 }
OLDNEW
« no previous file with comments | « gcc/libcpp/expr.c ('k') | gcc/libcpp/internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698