gcc/gcc/cppfiles.c

1210 lines
34 KiB
C
Raw Normal View History

[multiple changes] 1998-10-28 16:10 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * c-lang.c: Declare extern char *yy_cur if USE_CPPLIB. (lang_init): Call check_newline always. * c-lex.c (init_parse) [USE_CPPLIB=1]: After calling cpp_start_read, set yy_cur and yy_lim to read from parse_in.token_buffer, so that we'll see the first #line directive. * cpplib.c (cpp_start_read): finclude the main input file before processing -include/-imacros. Process -imacros and -include separately, and handle -include by stacking a buffer for the file in question as if it'd been #included. * toplev.c (documented_lang_options) Recognize -H when USE_CPPLIB is on. 1998-10-28 16:09 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.c: Merge do_once into do_pragma. Break file handling code out of do_include. Move append_include_chain, deps_output, file_cleanup, redundant_include_p, import_hash, lookup_import, add_import, read_filename_string, read_name_map, open_include_file, finclude, safe_read to cppfiles.c. Move prototypes for deps_output, append_include_chain, finclude to cpplib.h. Move definition of struct file_name_list there also. * cppfiles.c: New file. Contains all the above functions broken out of cpplib.c; also hack_vms_include_specification from cccp.c and find_include_file, a new function broken out of do_include. * Makefile.in (cppmain): Depend on cppfiles.o. (fix-header): Likewise. (cppfiles.o): New target. * configure.in (--enable-c-cpplib): Add cppfiles.o to extra_c_objs. Add ../cppfiles.o to extra_cxx_objs. From-SVN: r23424
1998-10-29 12:54:13 +01:00
/* Part of CPP library. (include file handling)
Makefile.in (C_AND_OBJC_OBJS, [...]): Update. * Makefile.in (C_AND_OBJC_OBJS, c-incpath.o, c-lex.o, LIBCPP_OBJS, cppinit.o, cppdefault.o, fix-header): Update. * c-incpath.c: New file. * c-incpath.h: New file. * c-lex.c: Include c-incpath.h. (init_c_lex): Register path simplifier. * c-opts.c: Include cppdefault.h and c-incpath.h. (TARGET_SYSTEM_ROOT, verbose, iprefix, sysroot, std_inc, std_cxx_inc, quote_chain_split, add_prefixed_path): New. (COMMAND_LINE_OPTIONS): Add more options from cpplib. (missing_arg, c_common_decode_option): Handle them. (c_common_post_options): Register include chains. (print_help): Update. * cppdefault.h (struct default include): Update. Move some macros to ... * cppdefault.c: ... here. (cpp_include_defaults): Add extra field add_sysroot. * cppfiles.c (include_file, search_from, find_or_create_entry, cpp_included, find_include_file, remap_filename): Update for renaming of search_path to cpp_path, and of the chain headers. (remove_component_p, _cpp_simplify_pathname): Move to c-incpath.c. * cpphash.h (struct search_path): Move to cpplib.h. (struct cpp_buffer, struct cpp_reader): Update. (_cpp_simplify_pathname): Remove. * cppinit.c: Don't include prefix.h and cppdefault.h. (INO_T_EQ, INO_T_COPY, path_include, append_include_chain, remove_dup_dir, remove_dup_nonsys_dirs, remove_dup_dirs, init_standard_includes, BRACKET, SYSTEM, AFTER, no_dir, no_pth, cpp_handle_options): Remove. (struct pending_option): Remove chain members. (cpp_destroy, cpp_read_main_file, COMMAND_LINE_OPTIONS, cpp_handle_option): Update. * cpplib.h (struct cpp_path, cpp_set_include_chains): New. (struct cpp_options): Remove quote_include, bracket_include, include_prefix, include_prefix_len, verbose, ignore_srcdir, no_standard_includes, no_standard_cplusplus_includes. (struct cpp_callbacks): Add simplify_path. (cpp_handle_options): Remove. * fix-header.c: Include c-incpath.h. (read_scan_file): Update to use c-incpath functionality. * doc/passes.texi: Update. cp: * Make-lang.in (CXX_C_OBJS): Update. From-SVN: r63612
2003-03-01 15:31:21 +01:00
Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1998,
1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
[multiple changes] 1998-10-28 16:10 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * c-lang.c: Declare extern char *yy_cur if USE_CPPLIB. (lang_init): Call check_newline always. * c-lex.c (init_parse) [USE_CPPLIB=1]: After calling cpp_start_read, set yy_cur and yy_lim to read from parse_in.token_buffer, so that we'll see the first #line directive. * cpplib.c (cpp_start_read): finclude the main input file before processing -include/-imacros. Process -imacros and -include separately, and handle -include by stacking a buffer for the file in question as if it'd been #included. * toplev.c (documented_lang_options) Recognize -H when USE_CPPLIB is on. 1998-10-28 16:09 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.c: Merge do_once into do_pragma. Break file handling code out of do_include. Move append_include_chain, deps_output, file_cleanup, redundant_include_p, import_hash, lookup_import, add_import, read_filename_string, read_name_map, open_include_file, finclude, safe_read to cppfiles.c. Move prototypes for deps_output, append_include_chain, finclude to cpplib.h. Move definition of struct file_name_list there also. * cppfiles.c: New file. Contains all the above functions broken out of cpplib.c; also hack_vms_include_specification from cccp.c and find_include_file, a new function broken out of do_include. * Makefile.in (cppmain): Depend on cppfiles.o. (fix-header): Likewise. (cppfiles.o): New target. * configure.in (--enable-c-cpplib): Add cppfiles.o to extra_c_objs. Add ../cppfiles.o to extra_cxx_objs. From-SVN: r23424
1998-10-29 12:54:13 +01:00
Written by Per Bothner, 1994.
Based on CCCP program by Paul Rubin, June 1986
Adapted to ANSI C, Richard Stallman, Jan 1987
Split out of cpplib.c, Zack Weinberg, Oct 1998
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
[multiple changes] 1998-10-28 16:10 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * c-lang.c: Declare extern char *yy_cur if USE_CPPLIB. (lang_init): Call check_newline always. * c-lex.c (init_parse) [USE_CPPLIB=1]: After calling cpp_start_read, set yy_cur and yy_lim to read from parse_in.token_buffer, so that we'll see the first #line directive. * cpplib.c (cpp_start_read): finclude the main input file before processing -include/-imacros. Process -imacros and -include separately, and handle -include by stacking a buffer for the file in question as if it'd been #included. * toplev.c (documented_lang_options) Recognize -H when USE_CPPLIB is on. 1998-10-28 16:09 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.c: Merge do_once into do_pragma. Break file handling code out of do_include. Move append_include_chain, deps_output, file_cleanup, redundant_include_p, import_hash, lookup_import, add_import, read_filename_string, read_name_map, open_include_file, finclude, safe_read to cppfiles.c. Move prototypes for deps_output, append_include_chain, finclude to cpplib.h. Move definition of struct file_name_list there also. * cppfiles.c: New file. Contains all the above functions broken out of cpplib.c; also hack_vms_include_specification from cccp.c and find_include_file, a new function broken out of do_include. * Makefile.in (cppmain): Depend on cppfiles.o. (fix-header): Likewise. (cppfiles.o): New target. * configure.in (--enable-c-cpplib): Add cppfiles.o to extra_c_objs. Add ../cppfiles.o to extra_cxx_objs. From-SVN: r23424
1998-10-29 12:54:13 +01:00
#include "config.h"
#include "system.h"
#include <dirent.h>
[multiple changes] 1998-10-28 16:10 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * c-lang.c: Declare extern char *yy_cur if USE_CPPLIB. (lang_init): Call check_newline always. * c-lex.c (init_parse) [USE_CPPLIB=1]: After calling cpp_start_read, set yy_cur and yy_lim to read from parse_in.token_buffer, so that we'll see the first #line directive. * cpplib.c (cpp_start_read): finclude the main input file before processing -include/-imacros. Process -imacros and -include separately, and handle -include by stacking a buffer for the file in question as if it'd been #included. * toplev.c (documented_lang_options) Recognize -H when USE_CPPLIB is on. 1998-10-28 16:09 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.c: Merge do_once into do_pragma. Break file handling code out of do_include. Move append_include_chain, deps_output, file_cleanup, redundant_include_p, import_hash, lookup_import, add_import, read_filename_string, read_name_map, open_include_file, finclude, safe_read to cppfiles.c. Move prototypes for deps_output, append_include_chain, finclude to cpplib.h. Move definition of struct file_name_list there also. * cppfiles.c: New file. Contains all the above functions broken out of cpplib.c; also hack_vms_include_specification from cccp.c and find_include_file, a new function broken out of do_include. * Makefile.in (cppmain): Depend on cppfiles.o. (fix-header): Likewise. (cppfiles.o): New target. * configure.in (--enable-c-cpplib): Add cppfiles.o to extra_c_objs. Add ../cppfiles.o to extra_cxx_objs. From-SVN: r23424
1998-10-29 12:54:13 +01:00
#include "cpplib.h"
#include "cpphash.h"
cpplib.c (my_strerror, [...]): Move to cpperror.c. * cpplib.c (my_strerror, cpp_error, cpp_error_with_line, cpp_error_from_errno, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Move to cpperror.c. (cpp_print_file_and_line, v_cpp_error, v_cpp_warning, v_cpp_error_with_line, v_cpp_warning_with_line, cpp_message_from_errno, cpp_perror_with_name): Delete. * cpperror.c (cpp_print_containing_files): Take starting buffer as argument. (cpp_file_line_for_message): Rename to cpp_print_file_and_line. (v_cpp_message): Now called directly by all entry points. Remove -1 case. (cpp_pfatal_with_name, cpp_message): Delete. (cpp_notice_from_errno, cpp_ice): New functions. (cpp_notice): Is now for reporting error conditions, just without an associated file. (cpp_error, cpp_error_with_line): Don't do anything if opts->inhibit_errors is on. (cpp_pedwarn_with_file_and_line): Take column argument also. * cpplib.h: Update prototypes of exported functions. (struct cpp_options): Add inhibit_errors. * cppalloc.c, cppfiles.c: Use fprintf not cpp_notice for non-error messages. Include intl.h. * cppinit.c, cppmain.c: Likewise. Also, use cpp_notice_from_errno instead of cpp_perror_with_name or cpp_pfatal_with_name, and cpp_notice instead of cpp_message. * cppexp.c, cpphash.c, cppinit.c, cpplib.c: Use cpp_ice to report internal errors. * cpplib.c (do_define): Switch bcopy to memcpy. Give cpp_pedwarn_with_file_and_line a dummy column argument. From-SVN: r31829
2000-02-07 00:46:18 +01:00
#include "intl.h"
cppfiles.c: Include mkdeps.h. * cppfiles.c: Include mkdeps.h. (find_include_file, read_include_file): Remove _cpp_ prefix from name, make static. (_cpp_execute_include): New function, broken out of do_include. * cpplib.c: Don't include mkdeps.h. (struct directive): Remove type field. Reorder entries. The function takes only one argument. (struct if_stack): Make type field an int. (directive_table): Rename to dtable. Generate it, the prototypes of the directive handlers, and the enum for the directive numbers, from a template macro. (do_ifndef, do_include_next, do_import): New functions. (do_define, do_include, do_endif, do_ifdef, do_if, do_else, do_undef, do_line, do_elif, do_error, do_pragma, do_warning, do_ident, do_assert, do_unassert, do_sccs): Take only one argument. (do_sccs): Define always, but alter behavior based on SCCS_DIRECTIVE. (_cpp_handle_directive, consider_directive_while_skipping): Restructure for new directive table layout. (pass_thru_directive): Take a directive number, not a pointer to a struct directive. (parse_include): New function, broken out of do_include. (do_include, do_import, do_include_next): Use parse_include and _cpp_execute_include. (do_elif, do_else): Test for T_ELSE specifically when checking for #elif/#else after #else. (parse_ifdef): New function, broken out of do_ifdef. (validate_else): Expect a name arg without a leading #. (if_directive_name): Delete. (cpp_define, cpp_assert, cpp_undef, cpp_unassert): Call directive handlers with only one argument. * cpphash.h: Update prototypes. (enum node_type): Remove entries for directives. * Makefile.in: Update dependencies. From-SVN: r32519
2000-03-14 07:34:11 +01:00
#include "mkdeps.h"
#include "splay-tree.h"
#ifndef O_BINARY
# define O_BINARY 0
#endif
/* If errno is inspected immediately after a system call fails, it will be
nonzero, and no error number will ever be zero. */
#ifndef ENOENT
# define ENOENT 0
#endif
#ifndef ENOTDIR
# define ENOTDIR 0
#endif
/* This structure is used for the table of all includes. */
struct include_file {
const char *name; /* actual path name of file */
const char *header_name; /* the original header found */
const cpp_hashnode *cmacro; /* macro, if any, preventing reinclusion. */
Makefile.in (C_AND_OBJC_OBJS, [...]): Update. * Makefile.in (C_AND_OBJC_OBJS, c-incpath.o, c-lex.o, LIBCPP_OBJS, cppinit.o, cppdefault.o, fix-header): Update. * c-incpath.c: New file. * c-incpath.h: New file. * c-lex.c: Include c-incpath.h. (init_c_lex): Register path simplifier. * c-opts.c: Include cppdefault.h and c-incpath.h. (TARGET_SYSTEM_ROOT, verbose, iprefix, sysroot, std_inc, std_cxx_inc, quote_chain_split, add_prefixed_path): New. (COMMAND_LINE_OPTIONS): Add more options from cpplib. (missing_arg, c_common_decode_option): Handle them. (c_common_post_options): Register include chains. (print_help): Update. * cppdefault.h (struct default include): Update. Move some macros to ... * cppdefault.c: ... here. (cpp_include_defaults): Add extra field add_sysroot. * cppfiles.c (include_file, search_from, find_or_create_entry, cpp_included, find_include_file, remap_filename): Update for renaming of search_path to cpp_path, and of the chain headers. (remove_component_p, _cpp_simplify_pathname): Move to c-incpath.c. * cpphash.h (struct search_path): Move to cpplib.h. (struct cpp_buffer, struct cpp_reader): Update. (_cpp_simplify_pathname): Remove. * cppinit.c: Don't include prefix.h and cppdefault.h. (INO_T_EQ, INO_T_COPY, path_include, append_include_chain, remove_dup_dir, remove_dup_nonsys_dirs, remove_dup_dirs, init_standard_includes, BRACKET, SYSTEM, AFTER, no_dir, no_pth, cpp_handle_options): Remove. (struct pending_option): Remove chain members. (cpp_destroy, cpp_read_main_file, COMMAND_LINE_OPTIONS, cpp_handle_option): Update. * cpplib.h (struct cpp_path, cpp_set_include_chains): New. (struct cpp_options): Remove quote_include, bracket_include, include_prefix, include_prefix_len, verbose, ignore_srcdir, no_standard_includes, no_standard_cplusplus_includes. (struct cpp_callbacks): Add simplify_path. (cpp_handle_options): Remove. * fix-header.c: Include c-incpath.h. (read_scan_file): Update to use c-incpath functionality. * doc/passes.texi: Update. cp: * Make-lang.in (CXX_C_OBJS): Update. From-SVN: r63612
2003-03-01 15:31:21 +01:00
const struct cpp_path *foundhere;
/* location in search path where file was
found, for #include_next and sysp. */
const unsigned char *buffer; /* pointer to cached file contents */
struct stat st; /* copy of stat(2) data for file */
int fd; /* fd open on file (short term storage only) */
int err_no; /* errno obtained if opening a file failed */
unsigned short include_count; /* number of times file has been read */
unsigned char pch; /* 0: file not known to be a PCH.
1: file is a PCH
(on return from find_include_file).
2: file is not and never will be a valid
precompiled header.
3: file is always a valid precompiled
header. */
};
/* Variable length record files on VMS will have a stat size that includes
record control characters that won't be included in the read size. */
#ifdef VMS
# define FAB_C_VAR 2 /* variable length records (see Starlet fabdef.h) */
# define STAT_SIZE_TOO_BIG(ST) ((ST).st_fab_rfm == FAB_C_VAR)
#else
# define STAT_SIZE_TOO_BIG(ST) 0
#endif
/* The cmacro works like this: If it's NULL, the file is to be
included again. If it's NEVER_REREAD, the file is never to be
included again. Otherwise it is a macro hashnode, and the file is
to be included again if the macro is defined. */
#define NEVER_REREAD ((const cpp_hashnode *) -1)
#define DO_NOT_REREAD(inc) \
((inc)->cmacro && ((inc)->cmacro == NEVER_REREAD \
|| (inc)->cmacro->type == NT_MACRO))
#define NO_INCLUDE_PATH ((struct include_file *) -1)
#define INCLUDE_PCH_P(F) (((F)->pch & 1) != 0)
static struct file_name_map *read_name_map (cpp_reader *, const char *);
static char *read_filename_string (int, FILE *);
static char *remap_filename (cpp_reader *, char *, struct cpp_path *);
static struct cpp_path *search_from (cpp_reader *, enum include_type);
static struct include_file *find_include_file (cpp_reader *, const char *,
int, enum include_type);
static struct include_file *open_file (cpp_reader *, const char *);
static struct include_file *validate_pch (cpp_reader *, const char *,
const char *);
static struct include_file *open_file_pch (cpp_reader *, const char *);
static int read_include_file (cpp_reader *, struct include_file *);
static bool stack_include_file (cpp_reader *, struct include_file *);
static void purge_cache (struct include_file *);
static void destroy_node (splay_tree_value);
static int report_missing_guard (splay_tree_node, void *);
static splay_tree_node find_or_create_entry (cpp_reader *, const char *);
static void handle_missing_header (cpp_reader *, const char *, int);
static int remove_component_p (const char *);
/* Set up the splay tree we use to store information about all the
file names seen in this compilation. We also have entries for each
file we tried to open but failed; this saves system calls since we
don't try to open it again in future.
The key of each node is the file name, after processing by
cpp_simplify_path. The path name may or may not be absolute.
The path string has been malloced, as is automatically freed by
registering free () as the splay tree key deletion function.
A node's value is a pointer to a struct include_file, and is never
NULL. */
Convert cpplib to use libiberty/hashtab.c. * cpplib.h (struct cpp_reader): Make hashtab and all_include_files of type 'struct htab *'. Delete HASHSIZE and ALL_INCLUDE_HASHSIZE macros. * cpphash.h: Update prototypes. (struct hashnode): Remove next, prev, and bucket_hdr members. Make length a size_t. Add hash member. (struct ihash): Remove next member. Add hash member. Make name a flexible array member. * cppfiles.c: Include hashtab.h. (include_hash): Delete. (IHASHSIZE): New macro. (hash_IHASH, eq_IHASH, _cpp_init_include_hash): New functions. (cpp_included): Do the hash lookup here. (_cpp_find_include_file): Rewrite. (cpp_read_file): Put the "fake" hash entry into the hash table. Honor the control_macro, if it turns out we've seen the file before. Don't push the buffer here. (_cpp_read_include_file): Push the buffer here. (OMODES): New macro. Use it whenever we call open(2). * cpphash.c: Include hashtab.h. (hash_HASHNODE, eq_HASHNODE, del_HASHNODE, dump_hash_helper, _cpp_init_macro_hash, _cpp_dump_macro_hash, _cpp_make_hashnode, _cpp_lookup_slot): New functions. (HASHSIZE): new macro. (hashf, _cpp_install, _cpp_delete_macro): Delete. (_cpp_lookup): Use hashtab.h routines. * cppinit.c: Include hashtab.h. (cpp_reader_init): Call _cpp_init_macro_hash and _cpp_init_include_hash. Don't allocate hashtab directly. (cpp_cleanup): Just call htab_delete on pfile->hashtab and pfile->all_include_files. (initialize_builtins): Use _cpp_make_hashnode and htab_find_slot to add hash entries. (cpp_finish): Just call _cpp_dump_macro_hash. * cpplib.c: Include hashtab.h. (do_define): Use _cpp_lookup_slot and _cpp_make_hashnode to create hash entries. (do_pragma_poison, do_assert): Likewise. (do_include): Don't push the buffer here. Don't increment system_include_depth unless _cpp_read_include_file succeeds. (do_undef, do_unassert): Use _cpp_lookup_slot and htab_clear_slot or htab_remove_elt. (do_pragma_implementation): Use alloca to create copy. * Makefile.in: Update dependencies. From-SVN: r32497
2000-03-13 00:46:05 +01:00
void
_cpp_init_includes (cpp_reader *pfile)
Convert cpplib to use libiberty/hashtab.c. * cpplib.h (struct cpp_reader): Make hashtab and all_include_files of type 'struct htab *'. Delete HASHSIZE and ALL_INCLUDE_HASHSIZE macros. * cpphash.h: Update prototypes. (struct hashnode): Remove next, prev, and bucket_hdr members. Make length a size_t. Add hash member. (struct ihash): Remove next member. Add hash member. Make name a flexible array member. * cppfiles.c: Include hashtab.h. (include_hash): Delete. (IHASHSIZE): New macro. (hash_IHASH, eq_IHASH, _cpp_init_include_hash): New functions. (cpp_included): Do the hash lookup here. (_cpp_find_include_file): Rewrite. (cpp_read_file): Put the "fake" hash entry into the hash table. Honor the control_macro, if it turns out we've seen the file before. Don't push the buffer here. (_cpp_read_include_file): Push the buffer here. (OMODES): New macro. Use it whenever we call open(2). * cpphash.c: Include hashtab.h. (hash_HASHNODE, eq_HASHNODE, del_HASHNODE, dump_hash_helper, _cpp_init_macro_hash, _cpp_dump_macro_hash, _cpp_make_hashnode, _cpp_lookup_slot): New functions. (HASHSIZE): new macro. (hashf, _cpp_install, _cpp_delete_macro): Delete. (_cpp_lookup): Use hashtab.h routines. * cppinit.c: Include hashtab.h. (cpp_reader_init): Call _cpp_init_macro_hash and _cpp_init_include_hash. Don't allocate hashtab directly. (cpp_cleanup): Just call htab_delete on pfile->hashtab and pfile->all_include_files. (initialize_builtins): Use _cpp_make_hashnode and htab_find_slot to add hash entries. (cpp_finish): Just call _cpp_dump_macro_hash. * cpplib.c: Include hashtab.h. (do_define): Use _cpp_lookup_slot and _cpp_make_hashnode to create hash entries. (do_pragma_poison, do_assert): Likewise. (do_include): Don't push the buffer here. Don't increment system_include_depth unless _cpp_read_include_file succeeds. (do_undef, do_unassert): Use _cpp_lookup_slot and htab_clear_slot or htab_remove_elt. (do_pragma_implementation): Use alloca to create copy. * Makefile.in: Update dependencies. From-SVN: r32497
2000-03-13 00:46:05 +01:00
{
pfile->all_include_files
= splay_tree_new ((splay_tree_compare_fn) strcmp,
(splay_tree_delete_key_fn) free,
destroy_node);
cpplib.h: Delete struct import_file. Wed Nov 25 14:54:46 1998 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.h: Delete struct import_file. Add ihash element to struct cpp_buffer. Delete dont_repeat_files and import_hash_table elements from cpp_reader; change all_include_files to a hash table. Delete all foobar_include / last_foobar_include elements from struct cpp_options; put back four such: quote_include, bracket_include, system_include, after_include. Redo struct file_name_list completely. Add new structure type include_hash. Add prototypes for merge_include_chains and include_hash. Change prototypes for finclude, find_include_file, and append_include_chain to match changes below. * cppfiles.c (simplify_pathname, include_hash, remap_filename, merge_include_chains): New functions. (add_import, lookup_import, open_include_file): Removed. (INO_T_EQ): Define this (copied from cccp.c). (hack_vms_include_specification): Remove all calls and #if 0 out the definition. It was being called incorrectly and at the wrong times. Until a VMSie can look at this, it's better to not pretend to support it. (append_include_chain): Change calling convention; now takes only one directory at a time, and sets up the data structure itself. (redundant_include_p): Rewritten - this is now used for all include redundancy, whether by #ifndef, #import, or #pragma once. Looks up things in the include hash table. (file_cleanup): Decrement pfile->system_include_depth here if it's >0. (find_include_file): Calling convention changed; now passes around a struct include_hash instead of 3 separate parameters. Guts ripped out and replaced with new include_hash mechanism. (finclude): Calling convention changed as for find_include_file. Error exits pulled out-of-line. Reformat. (safe_read): Return a long, not an int. (deps_output): Don't recurse. * cpplib.c (is_system_include): Deleted. (path_include): Fix up call to append_include_chain. (do_include): Fix up calls to find_include_file and finclude. Clean up dependency output a bit. Shorten obnoxiously lengthy #import warning message. Don't decrement pfile->system_include_depth here. (do_pragma): Understand the include_hash structure. Reformat. (do_endif): Correct handling of control macros. Understand the include_hash. (cpp_start_read): Fix up calls to finclude. Call merge_include_chains. (cpp_handle_option): Fix up calls to append_include_chain. Understand the four partial include chains. (cpp_finish): Add debugging code (#if 0-ed out) for the include_hash. (cpp_cleanup): Free the include_hash, not the import hash and the all_include and dont_repeat lists which no longer exist. From-SVN: r23857
1998-11-25 12:56:54 +01:00
}
[multiple changes] 1998-10-28 16:10 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * c-lang.c: Declare extern char *yy_cur if USE_CPPLIB. (lang_init): Call check_newline always. * c-lex.c (init_parse) [USE_CPPLIB=1]: After calling cpp_start_read, set yy_cur and yy_lim to read from parse_in.token_buffer, so that we'll see the first #line directive. * cpplib.c (cpp_start_read): finclude the main input file before processing -include/-imacros. Process -imacros and -include separately, and handle -include by stacking a buffer for the file in question as if it'd been #included. * toplev.c (documented_lang_options) Recognize -H when USE_CPPLIB is on. 1998-10-28 16:09 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.c: Merge do_once into do_pragma. Break file handling code out of do_include. Move append_include_chain, deps_output, file_cleanup, redundant_include_p, import_hash, lookup_import, add_import, read_filename_string, read_name_map, open_include_file, finclude, safe_read to cppfiles.c. Move prototypes for deps_output, append_include_chain, finclude to cpplib.h. Move definition of struct file_name_list there also. * cppfiles.c: New file. Contains all the above functions broken out of cpplib.c; also hack_vms_include_specification from cccp.c and find_include_file, a new function broken out of do_include. * Makefile.in (cppmain): Depend on cppfiles.o. (fix-header): Likewise. (cppfiles.o): New target. * configure.in (--enable-c-cpplib): Add cppfiles.o to extra_c_objs. Add ../cppfiles.o to extra_cxx_objs. From-SVN: r23424
1998-10-29 12:54:13 +01:00
/* Tear down the splay tree. */
cpplex.c: Don't include sys/mman.h. toplevel: * cpplex.c: Don't include sys/mman.h. (cpp_push_buffer, cpp_pop_buffer): Moved to cpplib.c. * cpplib.c: Include sys/mman.h and obstack.h. (cpp_push_buffer): Moved from cpplex.c; allocate buffers on an obstack. (cpp_pop_buffer): Moved from cpplex.c; free buffers from an obstack. (_cpp_unwind_if_stack): Now static, unwind_if_stack. Don't bother freeing if stack entries (they will be freed with their buffer). (do_endif): Free if stack entries from the buffer obstack. (push_conditional): Allocate if stack entries from the buffer obstack. (find_answer): Rename to _cpp_find_answer. (do_assert, do_unassert): Update. * cpphash.h: Update prototypes. (xobnew): New convenience macro. * cpplib.h (struct cpp_reader): Add hash_ob and buffer_ob fields. Update comments. (struct cpp_hashnode): Remove disabled field. * cppinit.c: Don't include hashtab.h or splay-tree.h. (report_missing_guard): Moved to cppfiles.c. (cpp_reader_init): Call cpp_init_stacks, cpp_init_macros, cpp_init_includes. (cpp_cleanup): Call cpp_cleanup_stacks, cpp_cleanup_macros, cpp_cleanup_includes. Don't destroy hashtab or all_include_files here. (cpp_finish): Use _cpp_report_missing_guards. * cppfiles.c (report_missing_guard): Moved from cppinit.c. (_cpp_init_include_table): Rename _cpp_init_includes. (_cpp_cleanup_includes, _cpp_report_missing_guards): New. * cppexp.c (parse_assertion): Update for new name of find_answer. * Makefile.in (cpplib.o, cpphash.o, cppinit.o): Update deps. * cpplib.c (do_ident): s/VSPACE/EOF/ testsuite: * gcc.dg/cpp/ident.c: New test. From-SVN: r34870
2000-07-05 07:33:57 +02:00
void
_cpp_cleanup_includes (cpp_reader *pfile)
cpplex.c: Don't include sys/mman.h. toplevel: * cpplex.c: Don't include sys/mman.h. (cpp_push_buffer, cpp_pop_buffer): Moved to cpplib.c. * cpplib.c: Include sys/mman.h and obstack.h. (cpp_push_buffer): Moved from cpplex.c; allocate buffers on an obstack. (cpp_pop_buffer): Moved from cpplex.c; free buffers from an obstack. (_cpp_unwind_if_stack): Now static, unwind_if_stack. Don't bother freeing if stack entries (they will be freed with their buffer). (do_endif): Free if stack entries from the buffer obstack. (push_conditional): Allocate if stack entries from the buffer obstack. (find_answer): Rename to _cpp_find_answer. (do_assert, do_unassert): Update. * cpphash.h: Update prototypes. (xobnew): New convenience macro. * cpplib.h (struct cpp_reader): Add hash_ob and buffer_ob fields. Update comments. (struct cpp_hashnode): Remove disabled field. * cppinit.c: Don't include hashtab.h or splay-tree.h. (report_missing_guard): Moved to cppfiles.c. (cpp_reader_init): Call cpp_init_stacks, cpp_init_macros, cpp_init_includes. (cpp_cleanup): Call cpp_cleanup_stacks, cpp_cleanup_macros, cpp_cleanup_includes. Don't destroy hashtab or all_include_files here. (cpp_finish): Use _cpp_report_missing_guards. * cppfiles.c (report_missing_guard): Moved from cppinit.c. (_cpp_init_include_table): Rename _cpp_init_includes. (_cpp_cleanup_includes, _cpp_report_missing_guards): New. * cppexp.c (parse_assertion): Update for new name of find_answer. * Makefile.in (cpplib.o, cpphash.o, cppinit.o): Update deps. * cpplib.c (do_ident): s/VSPACE/EOF/ testsuite: * gcc.dg/cpp/ident.c: New test. From-SVN: r34870
2000-07-05 07:33:57 +02:00
{
splay_tree_delete (pfile->all_include_files);
}
/* Free a node. The path string is automatically freed. */
static void
destroy_node (splay_tree_value v)
{
struct include_file *f = (struct include_file *) v;
if (f)
{
purge_cache (f);
free (f);
}
}
/* Mark a file to not be reread (e.g. #import, read failure). */
void
_cpp_never_reread (struct include_file *file)
{
file->cmacro = NEVER_REREAD;
}
/* Lookup a filename, which is simplified after making a copy, and
Makefile.in (C_AND_OBJC_OBJS, [...]): Update. * Makefile.in (C_AND_OBJC_OBJS, c-incpath.o, c-lex.o, LIBCPP_OBJS, cppinit.o, cppdefault.o, fix-header): Update. * c-incpath.c: New file. * c-incpath.h: New file. * c-lex.c: Include c-incpath.h. (init_c_lex): Register path simplifier. * c-opts.c: Include cppdefault.h and c-incpath.h. (TARGET_SYSTEM_ROOT, verbose, iprefix, sysroot, std_inc, std_cxx_inc, quote_chain_split, add_prefixed_path): New. (COMMAND_LINE_OPTIONS): Add more options from cpplib. (missing_arg, c_common_decode_option): Handle them. (c_common_post_options): Register include chains. (print_help): Update. * cppdefault.h (struct default include): Update. Move some macros to ... * cppdefault.c: ... here. (cpp_include_defaults): Add extra field add_sysroot. * cppfiles.c (include_file, search_from, find_or_create_entry, cpp_included, find_include_file, remap_filename): Update for renaming of search_path to cpp_path, and of the chain headers. (remove_component_p, _cpp_simplify_pathname): Move to c-incpath.c. * cpphash.h (struct search_path): Move to cpplib.h. (struct cpp_buffer, struct cpp_reader): Update. (_cpp_simplify_pathname): Remove. * cppinit.c: Don't include prefix.h and cppdefault.h. (INO_T_EQ, INO_T_COPY, path_include, append_include_chain, remove_dup_dir, remove_dup_nonsys_dirs, remove_dup_dirs, init_standard_includes, BRACKET, SYSTEM, AFTER, no_dir, no_pth, cpp_handle_options): Remove. (struct pending_option): Remove chain members. (cpp_destroy, cpp_read_main_file, COMMAND_LINE_OPTIONS, cpp_handle_option): Update. * cpplib.h (struct cpp_path, cpp_set_include_chains): New. (struct cpp_options): Remove quote_include, bracket_include, include_prefix, include_prefix_len, verbose, ignore_srcdir, no_standard_includes, no_standard_cplusplus_includes. (struct cpp_callbacks): Add simplify_path. (cpp_handle_options): Remove. * fix-header.c: Include c-incpath.h. (read_scan_file): Update to use c-incpath functionality. * doc/passes.texi: Update. cp: * Make-lang.in (CXX_C_OBJS): Update. From-SVN: r63612
2003-03-01 15:31:21 +01:00
create an entry if none exists. */
static splay_tree_node
find_or_create_entry (cpp_reader *pfile, const char *fname)
{
splay_tree_node node;
struct include_file *file;
char *name = xstrdup (fname);
int saved_errno;
cpp_simplify_path (name);
saved_errno = errno;
node = splay_tree_lookup (pfile->all_include_files, (splay_tree_key) name);
if (node)
free (name);
else
{
file = xcnew (struct include_file);
file->name = name;
file->header_name = name;
file->err_no = saved_errno;
node = splay_tree_insert (pfile->all_include_files,
(splay_tree_key) file->name,
(splay_tree_value) file);
}
return node;
}
/* Enter a file name in the splay tree, for the sake of cpp_included. */
void
_cpp_fake_include (cpp_reader *pfile, const char *fname)
{
find_or_create_entry (pfile, fname);
}
/* Given a file name, look it up in the cache; if there is no entry,
create one with a non-NULL value (regardless of success in opening
the file). If the file doesn't exist or is inaccessible, this
entry is flagged so we don't attempt to open it again in the
future. If the file isn't open, open it. The empty string is
interpreted as stdin.
Returns an include_file structure with an open file descriptor on
success, or NULL on failure. */
static struct include_file *
open_file (cpp_reader *pfile, const char *filename)
{
splay_tree_node nd = find_or_create_entry (pfile, filename);
struct include_file *file = (struct include_file *) nd->value;
[multiple changes] 1998-10-28 16:10 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * c-lang.c: Declare extern char *yy_cur if USE_CPPLIB. (lang_init): Call check_newline always. * c-lex.c (init_parse) [USE_CPPLIB=1]: After calling cpp_start_read, set yy_cur and yy_lim to read from parse_in.token_buffer, so that we'll see the first #line directive. * cpplib.c (cpp_start_read): finclude the main input file before processing -include/-imacros. Process -imacros and -include separately, and handle -include by stacking a buffer for the file in question as if it'd been #included. * toplev.c (documented_lang_options) Recognize -H when USE_CPPLIB is on. 1998-10-28 16:09 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.c: Merge do_once into do_pragma. Break file handling code out of do_include. Move append_include_chain, deps_output, file_cleanup, redundant_include_p, import_hash, lookup_import, add_import, read_filename_string, read_name_map, open_include_file, finclude, safe_read to cppfiles.c. Move prototypes for deps_output, append_include_chain, finclude to cpplib.h. Move definition of struct file_name_list there also. * cppfiles.c: New file. Contains all the above functions broken out of cpplib.c; also hack_vms_include_specification from cccp.c and find_include_file, a new function broken out of do_include. * Makefile.in (cppmain): Depend on cppfiles.o. (fix-header): Likewise. (cppfiles.o): New target. * configure.in (--enable-c-cpplib): Add cppfiles.o to extra_c_objs. Add ../cppfiles.o to extra_cxx_objs. From-SVN: r23424
1998-10-29 12:54:13 +01:00
if (file->err_no)
{
/* Ugh. handle_missing_header () needs errno to be set. */
errno = file->err_no;
return 0;
}
/* Don't reopen an idempotent file. */
if (DO_NOT_REREAD (file))
return file;
/* Don't reopen one which is already loaded. */
cppfiles.c (ENABLE_VALGRIND_CHECKING, [...]): Remove. * cppfiles.c (ENABLE_VALGRIND_CHECKING, VALGRIND_DISCARD, MMAP_THRESHOLD, TEST_THRESHOLD, SHOULD_MMAP): Remove. (struct include_file): Remove fefcnt, mapped members. (open_file, stack_include_file, _cpp_pop_file_buffer): Disable caching. (read_include_file): Don't use mmap, terminate buffers in '\r'. (purge_cache): Don't use munmap. * cpphash.h (CPP_BUF_COLUMN): Update. (lexer_state): Remove lexing_comment. (struct _cpp_line_note): New. (struct cpp_buffer): New members cur_note, notes_used, notes_cap, next_line and need_line. Remove col_adjust and saved_flags. (_cpp_process_line_notes, _cpp_clean_line, _cpp_get_fresh_line, _cpp_skip_block_comment, scan_out_logical_line): New. (_cpp_init_mbchar): Remove. * cppinit.c (init_library): Remove call to _cpp_init_mbchar. (cpp_read_main_file): Set line to 1 earlier. (post_options): -traditional-cpp doesn't want trigraphs. * cpplex.c (MULTIBYTE_CHARS): Remove code predicated on this. (add_line_note, _cpp_clean_line, _cpp_process_line_notes, _cpp_get_fresh_line): New. (handle_newline, skip_escaped_newlines, trigraph_p, continue_after_nul, _cpp_init_mbchar): Remove. (get_effective_char): Update. (_cpp_skip_block_comment): Rename from skip_block_comment, simplify. (skip_line_comment): Simplify. (skip_whitespace, parse_identifier, parse_slow, parse_number, parse_string): Update. (cpp_lex_direct): Use clean lines and process line notes. Update. (cpp_interpret_charconst): No MULTIBYTE_CHARS. * cpplib.c (prepare_directive_trad): Call scan_out_logical_line directly. (_cpp_handle_directive): Don't set saved_flags. (run_directive, destringize_and_run, cpp_define, cpp_define_builtin, cpp_undef, handle_assertion, cpp_push_buffer): Update. (_cpp_pop_buffer): Free notes. * cppmacro.c (builtin_macro, paste_tokens): \n terminate buffer. * cpppch.c (cpp_read_state): \n terminate buffer. * cpptrad.c (skip_escaped_newlines, handle_newline): Remove. (copy_comment): Use _cpp_skip_block_comment. (skip_whitespace, lex_identifier, _cpp_read_logical_line_trad): Simplify. (_cpp_overlay_buffer, _cpp_remove_overlay, push_replacement_text, save_replacement_text): Update. (scan_out_logical_line): Update to use clean lines and process line notes. * fix-header.c (read_scan_file): Update. testsuite: * gcc.dg/cpp/_Pragma4.c: Remove stray space. * gcc.dg/cpp/trad/escaped-eof.c: Correct line number. From-SVN: r65808
2003-04-19 02:22:51 +02:00
if (0 && file->buffer != NULL)
return file;
[multiple changes] 1998-10-28 16:10 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * c-lang.c: Declare extern char *yy_cur if USE_CPPLIB. (lang_init): Call check_newline always. * c-lex.c (init_parse) [USE_CPPLIB=1]: After calling cpp_start_read, set yy_cur and yy_lim to read from parse_in.token_buffer, so that we'll see the first #line directive. * cpplib.c (cpp_start_read): finclude the main input file before processing -include/-imacros. Process -imacros and -include separately, and handle -include by stacking a buffer for the file in question as if it'd been #included. * toplev.c (documented_lang_options) Recognize -H when USE_CPPLIB is on. 1998-10-28 16:09 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.c: Merge do_once into do_pragma. Break file handling code out of do_include. Move append_include_chain, deps_output, file_cleanup, redundant_include_p, import_hash, lookup_import, add_import, read_filename_string, read_name_map, open_include_file, finclude, safe_read to cppfiles.c. Move prototypes for deps_output, append_include_chain, finclude to cpplib.h. Move definition of struct file_name_list there also. * cppfiles.c: New file. Contains all the above functions broken out of cpplib.c; also hack_vms_include_specification from cccp.c and find_include_file, a new function broken out of do_include. * Makefile.in (cppmain): Depend on cppfiles.o. (fix-header): Likewise. (cppfiles.o): New target. * configure.in (--enable-c-cpplib): Add cppfiles.o to extra_c_objs. Add ../cppfiles.o to extra_cxx_objs. From-SVN: r23424
1998-10-29 12:54:13 +01:00
/* We used to open files in nonblocking mode, but that caused more
problems than it solved. Do take care not to acquire a
controlling terminal by mistake (this can't happen on sane
systems, but paranoia is a virtue).
[multiple changes] 1998-10-28 16:10 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * c-lang.c: Declare extern char *yy_cur if USE_CPPLIB. (lang_init): Call check_newline always. * c-lex.c (init_parse) [USE_CPPLIB=1]: After calling cpp_start_read, set yy_cur and yy_lim to read from parse_in.token_buffer, so that we'll see the first #line directive. * cpplib.c (cpp_start_read): finclude the main input file before processing -include/-imacros. Process -imacros and -include separately, and handle -include by stacking a buffer for the file in question as if it'd been #included. * toplev.c (documented_lang_options) Recognize -H when USE_CPPLIB is on. 1998-10-28 16:09 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.c: Merge do_once into do_pragma. Break file handling code out of do_include. Move append_include_chain, deps_output, file_cleanup, redundant_include_p, import_hash, lookup_import, add_import, read_filename_string, read_name_map, open_include_file, finclude, safe_read to cppfiles.c. Move prototypes for deps_output, append_include_chain, finclude to cpplib.h. Move definition of struct file_name_list there also. * cppfiles.c: New file. Contains all the above functions broken out of cpplib.c; also hack_vms_include_specification from cccp.c and find_include_file, a new function broken out of do_include. * Makefile.in (cppmain): Depend on cppfiles.o. (fix-header): Likewise. (cppfiles.o): New target. * configure.in (--enable-c-cpplib): Add cppfiles.o to extra_c_objs. Add ../cppfiles.o to extra_cxx_objs. From-SVN: r23424
1998-10-29 12:54:13 +01:00
Use the three-argument form of open even though we aren't
specifying O_CREAT, to defend against broken system headers.
[multiple changes] 1998-10-28 16:10 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * c-lang.c: Declare extern char *yy_cur if USE_CPPLIB. (lang_init): Call check_newline always. * c-lex.c (init_parse) [USE_CPPLIB=1]: After calling cpp_start_read, set yy_cur and yy_lim to read from parse_in.token_buffer, so that we'll see the first #line directive. * cpplib.c (cpp_start_read): finclude the main input file before processing -include/-imacros. Process -imacros and -include separately, and handle -include by stacking a buffer for the file in question as if it'd been #included. * toplev.c (documented_lang_options) Recognize -H when USE_CPPLIB is on. 1998-10-28 16:09 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.c: Merge do_once into do_pragma. Break file handling code out of do_include. Move append_include_chain, deps_output, file_cleanup, redundant_include_p, import_hash, lookup_import, add_import, read_filename_string, read_name_map, open_include_file, finclude, safe_read to cppfiles.c. Move prototypes for deps_output, append_include_chain, finclude to cpplib.h. Move definition of struct file_name_list there also. * cppfiles.c: New file. Contains all the above functions broken out of cpplib.c; also hack_vms_include_specification from cccp.c and find_include_file, a new function broken out of do_include. * Makefile.in (cppmain): Depend on cppfiles.o. (fix-header): Likewise. (cppfiles.o): New target. * configure.in (--enable-c-cpplib): Add cppfiles.o to extra_c_objs. Add ../cppfiles.o to extra_cxx_objs. From-SVN: r23424
1998-10-29 12:54:13 +01:00
O_BINARY tells some runtime libraries (notably DJGPP) not to do
newline translation; we can handle DOS line breaks just fine
ourselves.
Special case: the empty string is translated to stdin. */
if (filename[0] == '\0')
{
file->fd = 0;
#ifdef __DJGPP__
/* For DJGPP redirected input is opened in text mode. Change it
to binary mode. */
if (! isatty (file->fd))
setmode (file->fd, O_BINARY);
#endif
}
cpplex.c (cpp_output_tokens, [...]): New public interfaces. * cpplex.c (cpp_output_tokens, cpp_scan_buffer_nooutput): New public interfaces. (safe_fwrite, output_line_command): New static functions. (cpp_expand_to_buffer): Now private to cpplib. (cpp_scan_buffer): Take a printer. * cpphash.h: Update prototypes. * cpplib.h: Update prototypes. (cpp_printer): New. (cpp_buffer): Remove last_nominal_fname. (cpp_reader): Remove lineno. * cppmain.c: Use a cpp_printer. * fix-header.c: No need to inhibit line commands. Call cpp_start_read with no printer. * cpperror.c (cpp_notice_from_errno): Provide default name. * cppfiles.c (make_IHASH, _cpp_fake_ihash): New functions. (find_include_file, cpp_read_file): Use make_IHASH. (file_cleanup): Set control_macro and clear input_stack_listing_current here. (_cpp_execute_include): Don't output entering-file marker. * cpphash.c (special_symbol): Look for the line number in the buffer, not the reader. (_cpp_macroexpand): No need to disable line commands. (_cpp_dump_definition): No need to generate line commands. (dump_hash_helper): Remove excess newline from output. * cppinit.c (dump_special_to_buffer): No need to generate line commands. (cpp_printer_init): New. (cpp_start_read): Take a printer, and start it up if it's not NULL. No need to generate line commands. (cpp_finish): Expect no buffers stacked at all. Take a printer argument, and flush the output buffer if it's not NULL. * cpplex.c (_cpp_lex_token): Return EOF if there's no buffer. Don't put two hashes at the beginning of an assertion. (cpp_get_token): Don't increment pfile->lineno or emit line commands here. Return EOF if there's no buffer when we get EOF. * cpplib.c (do_define, skip_if_group): No need to disable line commands. (_cpp_output_line_command): Delete function. (do_line): Don't emit line commands here, but set things up so they will be emitted if necessary. Use _cpp_fake_ihash to make unique nominal_fnames if necessary. (do_elif, do_else, _cpp_handle_eof): Call cpp_error_with_line with 0 for column, not -1. (_cpp_handle_eof): Don't set the control macro here. Don't clear input_stack_listing_current here. Don't emit line commands. From-SVN: r33159
2000-04-15 01:29:45 +02:00
else
file->fd = open (file->name, O_RDONLY | O_NOCTTY | O_BINARY, 0666);
if (file->fd != -1 && fstat (file->fd, &file->st) == 0)
{
if (!S_ISDIR (file->st.st_mode))
return file;
/* If it's a directory, we return null and continue the search
as the file we're looking for may appear elsewhere in the
search path. */
errno = ENOENT;
close (file->fd);
file->fd = -1;
}
file->err_no = errno;
return 0;
}
static struct include_file *
validate_pch (cpp_reader *pfile, const char *filename, const char *pchname)
{
struct include_file * file;
file = open_file (pfile, pchname);
if (file == NULL)
return NULL;
if ((file->pch & 2) == 0)
file->pch = pfile->cb.valid_pch (pfile, pchname, file->fd);
if (CPP_OPTION (pfile, print_include_names))
{
unsigned int i;
for (i = 1; i < pfile->line_maps.depth; i++)
putc ('.', stderr);
fprintf (stderr, "%c %s\n", INCLUDE_PCH_P (file) ? '!' : 'x', pchname);
}
if (INCLUDE_PCH_P (file))
{
Makefile.in (C_AND_OBJC_OBJS, [...]): Update. * Makefile.in (C_AND_OBJC_OBJS, c-incpath.o, c-lex.o, LIBCPP_OBJS, cppinit.o, cppdefault.o, fix-header): Update. * c-incpath.c: New file. * c-incpath.h: New file. * c-lex.c: Include c-incpath.h. (init_c_lex): Register path simplifier. * c-opts.c: Include cppdefault.h and c-incpath.h. (TARGET_SYSTEM_ROOT, verbose, iprefix, sysroot, std_inc, std_cxx_inc, quote_chain_split, add_prefixed_path): New. (COMMAND_LINE_OPTIONS): Add more options from cpplib. (missing_arg, c_common_decode_option): Handle them. (c_common_post_options): Register include chains. (print_help): Update. * cppdefault.h (struct default include): Update. Move some macros to ... * cppdefault.c: ... here. (cpp_include_defaults): Add extra field add_sysroot. * cppfiles.c (include_file, search_from, find_or_create_entry, cpp_included, find_include_file, remap_filename): Update for renaming of search_path to cpp_path, and of the chain headers. (remove_component_p, _cpp_simplify_pathname): Move to c-incpath.c. * cpphash.h (struct search_path): Move to cpplib.h. (struct cpp_buffer, struct cpp_reader): Update. (_cpp_simplify_pathname): Remove. * cppinit.c: Don't include prefix.h and cppdefault.h. (INO_T_EQ, INO_T_COPY, path_include, append_include_chain, remove_dup_dir, remove_dup_nonsys_dirs, remove_dup_dirs, init_standard_includes, BRACKET, SYSTEM, AFTER, no_dir, no_pth, cpp_handle_options): Remove. (struct pending_option): Remove chain members. (cpp_destroy, cpp_read_main_file, COMMAND_LINE_OPTIONS, cpp_handle_option): Update. * cpplib.h (struct cpp_path, cpp_set_include_chains): New. (struct cpp_options): Remove quote_include, bracket_include, include_prefix, include_prefix_len, verbose, ignore_srcdir, no_standard_includes, no_standard_cplusplus_includes. (struct cpp_callbacks): Add simplify_path. (cpp_handle_options): Remove. * fix-header.c: Include c-incpath.h. (read_scan_file): Update to use c-incpath functionality. * doc/passes.texi: Update. cp: * Make-lang.in (CXX_C_OBJS): Update. From-SVN: r63612
2003-03-01 15:31:21 +01:00
char *f = xstrdup (filename);
cpp_simplify_path (f);
Makefile.in (C_AND_OBJC_OBJS, [...]): Update. * Makefile.in (C_AND_OBJC_OBJS, c-incpath.o, c-lex.o, LIBCPP_OBJS, cppinit.o, cppdefault.o, fix-header): Update. * c-incpath.c: New file. * c-incpath.h: New file. * c-lex.c: Include c-incpath.h. (init_c_lex): Register path simplifier. * c-opts.c: Include cppdefault.h and c-incpath.h. (TARGET_SYSTEM_ROOT, verbose, iprefix, sysroot, std_inc, std_cxx_inc, quote_chain_split, add_prefixed_path): New. (COMMAND_LINE_OPTIONS): Add more options from cpplib. (missing_arg, c_common_decode_option): Handle them. (c_common_post_options): Register include chains. (print_help): Update. * cppdefault.h (struct default include): Update. Move some macros to ... * cppdefault.c: ... here. (cpp_include_defaults): Add extra field add_sysroot. * cppfiles.c (include_file, search_from, find_or_create_entry, cpp_included, find_include_file, remap_filename): Update for renaming of search_path to cpp_path, and of the chain headers. (remove_component_p, _cpp_simplify_pathname): Move to c-incpath.c. * cpphash.h (struct search_path): Move to cpplib.h. (struct cpp_buffer, struct cpp_reader): Update. (_cpp_simplify_pathname): Remove. * cppinit.c: Don't include prefix.h and cppdefault.h. (INO_T_EQ, INO_T_COPY, path_include, append_include_chain, remove_dup_dir, remove_dup_nonsys_dirs, remove_dup_dirs, init_standard_includes, BRACKET, SYSTEM, AFTER, no_dir, no_pth, cpp_handle_options): Remove. (struct pending_option): Remove chain members. (cpp_destroy, cpp_read_main_file, COMMAND_LINE_OPTIONS, cpp_handle_option): Update. * cpplib.h (struct cpp_path, cpp_set_include_chains): New. (struct cpp_options): Remove quote_include, bracket_include, include_prefix, include_prefix_len, verbose, ignore_srcdir, no_standard_includes, no_standard_cplusplus_includes. (struct cpp_callbacks): Add simplify_path. (cpp_handle_options): Remove. * fix-header.c: Include c-incpath.h. (read_scan_file): Update to use c-incpath functionality. * doc/passes.texi: Update. cp: * Make-lang.in (CXX_C_OBJS): Update. From-SVN: r63612
2003-03-01 15:31:21 +01:00
file->header_name = f;
return file;
}
close (file->fd);
file->fd = -1;
return NULL;
}
/* Like open_file, but also look for a precompiled header if (a) one exists
and (b) it is valid. */
static struct include_file *
open_file_pch (cpp_reader *pfile, const char *filename)
{
if (filename[0] != '\0'
&& pfile->cb.valid_pch != NULL)
{
size_t namelen = strlen (filename);
char *pchname = alloca (namelen + 5);
struct include_file *file = NULL;
struct stat st;
memcpy (pchname, filename, namelen);
memcpy (pchname + namelen, ".gch", 5);
cpp_simplify_path (pchname);
if (stat (pchname, &st) == 0 && S_ISDIR (st.st_mode))
{
DIR * thedir;
struct dirent *d;
size_t subname_len = namelen + 64;
char *subname = xmalloc (subname_len);
thedir = opendir (pchname);
if (thedir == NULL)
return NULL;
memcpy (subname, pchname, namelen + 4);
subname[namelen+4] = '/';
while ((d = readdir (thedir)) != NULL)
{
if (strlen (d->d_name) + namelen + 7 > subname_len)
{
subname_len = strlen (d->d_name) + namelen + 64;
subname = xrealloc (subname, subname_len);
}
strcpy (subname + namelen + 5, d->d_name);
file = validate_pch (pfile, filename, subname);
if (file)
break;
}
closedir (thedir);
free (subname);
}
else
file = validate_pch (pfile, filename, pchname);
if (file)
return file;
}
return open_file (pfile, filename);
}
/* Place the file referenced by INC into a new buffer on the buffer
stack, unless there are errors, or the file is not re-included
because of e.g. multiple-include guards. Returns true if a buffer
is stacked. */
static bool
stack_include_file (cpp_reader *pfile, struct include_file *inc)
{
cpp_buffer *fp;
int sysp;
const char *filename;
if (DO_NOT_REREAD (inc))
return false;
c-lex.c (map): Make const. * c-lex.c (map): Make const. (cb_file_change): Update for callback passing a line map. Don't assume we have a previous map. Remove sanity check about popping too many files. * cpperror.c (print_location): Make map const. * cppfiles.c (stack_include_file): Update; line maps now hold sysp. (cpp_make_system_header): Similarly. (search_from): Similarly. (_cpp_execute_include): Don't remember where we came from. * cpphash.h (struct cpp_buffer): Remove return_to_line, sysp. (struct cpp_reader): Make map const. (CPP_IN_SYSTEM_HEADER, _cpp_do_file_change): Update. * cpplib.c (do_line): Update; line maps now hold sysp. (cpp_push_buffer): Similarly. (_cpp_do_file_change): Similarly; callback with map instead. (cpp_get_line_maps): Constify return value. (_cpp_pop_buffer): Update. * cpplib.h (struct cpp_file_change): Remove. (struct cpp_callbacks): Update. (cpp_get_line_maps): Constify return value. * cppmacro.c (_cpp_create_definition): Update. * cppmain.c (struct printer): Constify map. (maybe_print_line): Similarly. (print_line): Similarly. Deduce flags 1 and 2 here. (cb_file_change): Update. * line-map.c (free_line_maps): Warn regardless. (add_line_map): Return pointer to const. When passed NULL to_file with LC_LEAVE, use the obvious values for the return point so the caller doesn't have to figure them out. (lookup_line): Return pointer to const. (print_containing_files): Take pointer to const. * line-map.h (struct line_map): New members reason, sysp. (add_line_map): Return pointer to const. (lookup_line): Similarly. (print_containing_files): Take pointer to const. From-SVN: r44789
2001-08-11 09:33:39 +02:00
sysp = MAX ((pfile->map ? pfile->map->sysp : 0),
(inc->foundhere ? inc->foundhere->sysp : 0));
/* Add the file to the dependencies on its first inclusion. */
if (CPP_OPTION (pfile, deps.style) > !!sysp && !inc->include_count)
{
if (pfile->buffer || CPP_OPTION (pfile, deps.ignore_main_file) == 0)
deps_add_dep (pfile->deps, inc->name);
}
/* PCH files get dealt with immediately. */
if (INCLUDE_PCH_P (inc))
{
pfile->cb.read_pch (pfile, inc->name, inc->fd, inc->header_name);
close (inc->fd);
inc->fd = -1;
return false;
}
/* Not in cache? */
cppfiles.c (ENABLE_VALGRIND_CHECKING, [...]): Remove. * cppfiles.c (ENABLE_VALGRIND_CHECKING, VALGRIND_DISCARD, MMAP_THRESHOLD, TEST_THRESHOLD, SHOULD_MMAP): Remove. (struct include_file): Remove fefcnt, mapped members. (open_file, stack_include_file, _cpp_pop_file_buffer): Disable caching. (read_include_file): Don't use mmap, terminate buffers in '\r'. (purge_cache): Don't use munmap. * cpphash.h (CPP_BUF_COLUMN): Update. (lexer_state): Remove lexing_comment. (struct _cpp_line_note): New. (struct cpp_buffer): New members cur_note, notes_used, notes_cap, next_line and need_line. Remove col_adjust and saved_flags. (_cpp_process_line_notes, _cpp_clean_line, _cpp_get_fresh_line, _cpp_skip_block_comment, scan_out_logical_line): New. (_cpp_init_mbchar): Remove. * cppinit.c (init_library): Remove call to _cpp_init_mbchar. (cpp_read_main_file): Set line to 1 earlier. (post_options): -traditional-cpp doesn't want trigraphs. * cpplex.c (MULTIBYTE_CHARS): Remove code predicated on this. (add_line_note, _cpp_clean_line, _cpp_process_line_notes, _cpp_get_fresh_line): New. (handle_newline, skip_escaped_newlines, trigraph_p, continue_after_nul, _cpp_init_mbchar): Remove. (get_effective_char): Update. (_cpp_skip_block_comment): Rename from skip_block_comment, simplify. (skip_line_comment): Simplify. (skip_whitespace, parse_identifier, parse_slow, parse_number, parse_string): Update. (cpp_lex_direct): Use clean lines and process line notes. Update. (cpp_interpret_charconst): No MULTIBYTE_CHARS. * cpplib.c (prepare_directive_trad): Call scan_out_logical_line directly. (_cpp_handle_directive): Don't set saved_flags. (run_directive, destringize_and_run, cpp_define, cpp_define_builtin, cpp_undef, handle_assertion, cpp_push_buffer): Update. (_cpp_pop_buffer): Free notes. * cppmacro.c (builtin_macro, paste_tokens): \n terminate buffer. * cpppch.c (cpp_read_state): \n terminate buffer. * cpptrad.c (skip_escaped_newlines, handle_newline): Remove. (copy_comment): Use _cpp_skip_block_comment. (skip_whitespace, lex_identifier, _cpp_read_logical_line_trad): Simplify. (_cpp_overlay_buffer, _cpp_remove_overlay, push_replacement_text, save_replacement_text): Update. (scan_out_logical_line): Update to use clean lines and process line notes. * fix-header.c (read_scan_file): Update. testsuite: * gcc.dg/cpp/_Pragma4.c: Remove stray space. * gcc.dg/cpp/trad/escaped-eof.c: Correct line number. From-SVN: r65808
2003-04-19 02:22:51 +02:00
if (1 || ! inc->buffer)
{
cppfiles.c (stack_include_file): Don't optimize zero-length files. * cppfiles.c (stack_include_file): Don't optimize zero-length files. (read_include_file): NUL-terminate read files. * cpplex.c (handle_newline, skip_escaped_newlines, get_effective_char, skip_whitespace, parse_identifier, parse_identifier_slow, parse_number, parse_string, _cpp_lex_direct): Optimize for the fact that buffers are guaranteed NUL-terminated. * cpplib.c (destringize_and_run, cpp_define, handle_assertion): Be sure buffers are NUL terminated. * cppmacro.c (warn_of_redefinition): Kill compile warning. * c-common.c: Include tree-inline.h. (c_language): Move separate definitions here. (c_common_init_options, c_common_post_options): New. (c_common_lang_init): Rename c_common_init. * c-common.h (c_common_lang_init): Similarly. (c_common_init_options, c_common_post_options): New. * c-lang.c (c_post_options): Move body to c_common_post_options. (c_init_options): Use c_common_init_options. (c_init): Update. * langhooks.def: Rearrange. * langhooks.h: Rearrange, and improve comments. * toplev.c (do_compile): New function. (toplev_main): Use it. (lang_independent_f_options, parse_options_and_default_flags, process_options): Remove trailing periods. * Makefile.in: Update. cp: * decl2.c (c_language): Move to c-common.c. * lex.c (cxx_post_options, cxx_init_options): Use c-common.c functions. (cxx_init): Update. objc: * objc-act.c (objc_post_options, objc_init_options): Use c-common.c functions. (ojbc_init): Update. From-SVN: r47362
2001-11-27 00:44:54 +01:00
if (read_include_file (pfile, inc))
{
/* If an error occurs, do not try to read this file again. */
_cpp_never_reread (inc);
return false;
}
cppfiles.c (stack_include_file): Don't optimize zero-length files. * cppfiles.c (stack_include_file): Don't optimize zero-length files. (read_include_file): NUL-terminate read files. * cpplex.c (handle_newline, skip_escaped_newlines, get_effective_char, skip_whitespace, parse_identifier, parse_identifier_slow, parse_number, parse_string, _cpp_lex_direct): Optimize for the fact that buffers are guaranteed NUL-terminated. * cpplib.c (destringize_and_run, cpp_define, handle_assertion): Be sure buffers are NUL terminated. * cppmacro.c (warn_of_redefinition): Kill compile warning. * c-common.c: Include tree-inline.h. (c_language): Move separate definitions here. (c_common_init_options, c_common_post_options): New. (c_common_lang_init): Rename c_common_init. * c-common.h (c_common_lang_init): Similarly. (c_common_init_options, c_common_post_options): New. * c-lang.c (c_post_options): Move body to c_common_post_options. (c_init_options): Use c_common_init_options. (c_init): Update. * langhooks.def: Rearrange. * langhooks.h: Rearrange, and improve comments. * toplev.c (do_compile): New function. (toplev_main): Use it. (lang_independent_f_options, parse_options_and_default_flags, process_options): Remove trailing periods. * Makefile.in: Update. cp: * decl2.c (c_language): Move to c-common.c. * lex.c (cxx_post_options, cxx_init_options): Use c-common.c functions. (cxx_init): Update. objc: * objc-act.c (objc_post_options, objc_init_options): Use c-common.c functions. (ojbc_init): Update. From-SVN: r47362
2001-11-27 00:44:54 +01:00
/* Mark a regular, zero-length file never-reread. We read it,
NUL-terminate it, and stack it once, so preprocessing a main
file of zero length does not raise an error. */
if (S_ISREG (inc->st.st_mode) && inc->st.st_size == 0)
_cpp_never_reread (inc);
close (inc->fd);
inc->fd = -1;
}
if (pfile->buffer)
/* We don't want MI guard advice for the main file. */
inc->include_count++;
/* Push a buffer. */
fp = cpp_push_buffer (pfile, inc->buffer, inc->st.st_size,
/* from_stage3 */ CPP_OPTION (pfile, preprocessed), 0);
fp->inc = inc;
/* Initialize controlling macro state. */
pfile->mi_valid = true;
pfile->mi_cmacro = 0;
/* Generate the call back. */
filename = inc->name;
if (*filename == '\0')
filename = "<stdin>";
_cpp_do_file_change (pfile, LC_ENTER, filename, 1, sysp);
return true;
}
/* Read the file referenced by INC into the file cache.
If fd points to a plain file, we might be able to mmap it; we can
definitely allocate the buffer all at once. If fd is a pipe or
terminal, we can't do either. If fd is something weird, like a
block device, we don't want to read it at all.
Unfortunately, different systems use different st.st_mode values
for pipes: some have S_ISFIFO, some S_ISSOCK, some are buggy and
zero the entire struct stat except a couple fields. Hence we don't
even try to figure out what something is, except for plain files
and block devices.
FIXME: Flush file cache and try again if we run out of memory. */
static int
read_include_file (cpp_reader *pfile, struct include_file *inc)
{
ssize_t size, offset, count;
uchar *buf;
if (S_ISREG (inc->st.st_mode))
cpplex.c (cpp_output_tokens, [...]): New public interfaces. * cpplex.c (cpp_output_tokens, cpp_scan_buffer_nooutput): New public interfaces. (safe_fwrite, output_line_command): New static functions. (cpp_expand_to_buffer): Now private to cpplib. (cpp_scan_buffer): Take a printer. * cpphash.h: Update prototypes. * cpplib.h: Update prototypes. (cpp_printer): New. (cpp_buffer): Remove last_nominal_fname. (cpp_reader): Remove lineno. * cppmain.c: Use a cpp_printer. * fix-header.c: No need to inhibit line commands. Call cpp_start_read with no printer. * cpperror.c (cpp_notice_from_errno): Provide default name. * cppfiles.c (make_IHASH, _cpp_fake_ihash): New functions. (find_include_file, cpp_read_file): Use make_IHASH. (file_cleanup): Set control_macro and clear input_stack_listing_current here. (_cpp_execute_include): Don't output entering-file marker. * cpphash.c (special_symbol): Look for the line number in the buffer, not the reader. (_cpp_macroexpand): No need to disable line commands. (_cpp_dump_definition): No need to generate line commands. (dump_hash_helper): Remove excess newline from output. * cppinit.c (dump_special_to_buffer): No need to generate line commands. (cpp_printer_init): New. (cpp_start_read): Take a printer, and start it up if it's not NULL. No need to generate line commands. (cpp_finish): Expect no buffers stacked at all. Take a printer argument, and flush the output buffer if it's not NULL. * cpplex.c (_cpp_lex_token): Return EOF if there's no buffer. Don't put two hashes at the beginning of an assertion. (cpp_get_token): Don't increment pfile->lineno or emit line commands here. Return EOF if there's no buffer when we get EOF. * cpplib.c (do_define, skip_if_group): No need to disable line commands. (_cpp_output_line_command): Delete function. (do_line): Don't emit line commands here, but set things up so they will be emitted if necessary. Use _cpp_fake_ihash to make unique nominal_fnames if necessary. (do_elif, do_else, _cpp_handle_eof): Call cpp_error_with_line with 0 for column, not -1. (_cpp_handle_eof): Don't set the control macro here. Don't clear input_stack_listing_current here. Don't emit line commands. From-SVN: r33159
2000-04-15 01:29:45 +02:00
{
/* off_t might have a wider range than ssize_t - in other words,
the max size of a file might be bigger than the address
space. We can't handle a file that large. (Anyone with
a single source file bigger than 2GB needs to rethink
their coding style.) Some systems (e.g. AIX 4.1) define
SSIZE_MAX to be much smaller than the actual range of the
type. Use INTTYPE_MAXIMUM unconditionally to ensure this
does not bite us. */
if (inc->st.st_size > INTTYPE_MAXIMUM (ssize_t))
cpplex.c (cpp_output_tokens, [...]): New public interfaces. * cpplex.c (cpp_output_tokens, cpp_scan_buffer_nooutput): New public interfaces. (safe_fwrite, output_line_command): New static functions. (cpp_expand_to_buffer): Now private to cpplib. (cpp_scan_buffer): Take a printer. * cpphash.h: Update prototypes. * cpplib.h: Update prototypes. (cpp_printer): New. (cpp_buffer): Remove last_nominal_fname. (cpp_reader): Remove lineno. * cppmain.c: Use a cpp_printer. * fix-header.c: No need to inhibit line commands. Call cpp_start_read with no printer. * cpperror.c (cpp_notice_from_errno): Provide default name. * cppfiles.c (make_IHASH, _cpp_fake_ihash): New functions. (find_include_file, cpp_read_file): Use make_IHASH. (file_cleanup): Set control_macro and clear input_stack_listing_current here. (_cpp_execute_include): Don't output entering-file marker. * cpphash.c (special_symbol): Look for the line number in the buffer, not the reader. (_cpp_macroexpand): No need to disable line commands. (_cpp_dump_definition): No need to generate line commands. (dump_hash_helper): Remove excess newline from output. * cppinit.c (dump_special_to_buffer): No need to generate line commands. (cpp_printer_init): New. (cpp_start_read): Take a printer, and start it up if it's not NULL. No need to generate line commands. (cpp_finish): Expect no buffers stacked at all. Take a printer argument, and flush the output buffer if it's not NULL. * cpplex.c (_cpp_lex_token): Return EOF if there's no buffer. Don't put two hashes at the beginning of an assertion. (cpp_get_token): Don't increment pfile->lineno or emit line commands here. Return EOF if there's no buffer when we get EOF. * cpplib.c (do_define, skip_if_group): No need to disable line commands. (_cpp_output_line_command): Delete function. (do_line): Don't emit line commands here, but set things up so they will be emitted if necessary. Use _cpp_fake_ihash to make unique nominal_fnames if necessary. (do_elif, do_else, _cpp_handle_eof): Call cpp_error_with_line with 0 for column, not -1. (_cpp_handle_eof): Don't set the control macro here. Don't clear input_stack_listing_current here. Don't emit line commands. From-SVN: r33159
2000-04-15 01:29:45 +02:00
{
cpperror.c (print_location): Don't print include chain if line == 0. * cpperror.c (print_location): Don't print include chain if line == 0. (cpp_begin_message): Update to use DL_ macros. (cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_notice, cpp_notice_from_errno): Remove. (cpp_error, cpp_error_with_line): Update to take a diagnostic level. (cpp_errno): New. * cppexp.c (CPP_ICE): Remove. (SYNTAX_ERROR, SYNTAX_ERROR2, parse_number, parse_defined, lex, integer_overflow, _cpp_parse_expr): Update. * cppfiles.c (read_include_file, find_include_file, handle_missing_header, _cpp_read_file, remap_filename): Update. * cpphash.h (enum error_type): Remove. (_cpp_begin_message): Update. * cppinit.c (append_include_chain, remove_dup_dirs, output_deps, cpp_handle_option, cpp_post_options): Update. * cpplex.c (trigraph_p, skip_escaped_newlines, skip_block_comment, skip_whitespace, parse_identifier, parse_slow, parse_string, _cpp_lex_direct, cpp_spell_token, maybe_read_ucs, cpp_parse_escape, cpp_interpret_charconst): Update. * cpplib.c (check_eol, directive_diagnostics, _cpp_handle_directive, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, read_flag, do_line, do_linemarker, do_ident, cpp_register_pragma, do_pragma_once, do_pragma_system_header, do_pragma_poison, do_pragma_dependency, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, parse_assertion, do_assert, _cpp_pop_buffer, do_diagnostic): Update. * cpplib.h (DL_WARNING, DL_WARNING_SYSHDR, DL_PEDWARN, DL_ERROR, DL_FATAL, DL_ICE, DL_EXTRACT, DL_WARNING_P): New. (cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_notice, cpp_notice_from_errno): Remove. (cpp_error, cpp_error_with_line): Update to take a diagnostic level. (cpp_errno): New. * cppmacro.c (builtin_macro, stringify_arg, paste_all_tokens, collect_args, enter_macro_context, save_parameter, parse_params, _cpp_create_definition, check_trad_stringification, cpp_macro_definition): Update. * cppmain.c (cpp_preprocess_file): Update. * fix-header.c (read_scan_file): Update. From-SVN: r52302
2002-04-14 20:42:47 +02:00
cpp_error (pfile, DL_ERROR, "%s is too large", inc->name);
goto fail;
cpplex.c (cpp_output_tokens, [...]): New public interfaces. * cpplex.c (cpp_output_tokens, cpp_scan_buffer_nooutput): New public interfaces. (safe_fwrite, output_line_command): New static functions. (cpp_expand_to_buffer): Now private to cpplib. (cpp_scan_buffer): Take a printer. * cpphash.h: Update prototypes. * cpplib.h: Update prototypes. (cpp_printer): New. (cpp_buffer): Remove last_nominal_fname. (cpp_reader): Remove lineno. * cppmain.c: Use a cpp_printer. * fix-header.c: No need to inhibit line commands. Call cpp_start_read with no printer. * cpperror.c (cpp_notice_from_errno): Provide default name. * cppfiles.c (make_IHASH, _cpp_fake_ihash): New functions. (find_include_file, cpp_read_file): Use make_IHASH. (file_cleanup): Set control_macro and clear input_stack_listing_current here. (_cpp_execute_include): Don't output entering-file marker. * cpphash.c (special_symbol): Look for the line number in the buffer, not the reader. (_cpp_macroexpand): No need to disable line commands. (_cpp_dump_definition): No need to generate line commands. (dump_hash_helper): Remove excess newline from output. * cppinit.c (dump_special_to_buffer): No need to generate line commands. (cpp_printer_init): New. (cpp_start_read): Take a printer, and start it up if it's not NULL. No need to generate line commands. (cpp_finish): Expect no buffers stacked at all. Take a printer argument, and flush the output buffer if it's not NULL. * cpplex.c (_cpp_lex_token): Return EOF if there's no buffer. Don't put two hashes at the beginning of an assertion. (cpp_get_token): Don't increment pfile->lineno or emit line commands here. Return EOF if there's no buffer when we get EOF. * cpplib.c (do_define, skip_if_group): No need to disable line commands. (_cpp_output_line_command): Delete function. (do_line): Don't emit line commands here, but set things up so they will be emitted if necessary. Use _cpp_fake_ihash to make unique nominal_fnames if necessary. (do_elif, do_else, _cpp_handle_eof): Call cpp_error_with_line with 0 for column, not -1. (_cpp_handle_eof): Don't set the control macro here. Don't clear input_stack_listing_current here. Don't emit line commands. From-SVN: r33159
2000-04-15 01:29:45 +02:00
}
size = inc->st.st_size;
{
buf = xmalloc (size + 1);
offset = 0;
while (offset < size)
{
count = read (inc->fd, buf + offset, size - offset);
if (count < 0)
goto perror_fail;
if (count == 0)
{
if (!STAT_SIZE_TOO_BIG (inc->st))
cpperror.c (print_location): Don't print include chain if line == 0. * cpperror.c (print_location): Don't print include chain if line == 0. (cpp_begin_message): Update to use DL_ macros. (cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_notice, cpp_notice_from_errno): Remove. (cpp_error, cpp_error_with_line): Update to take a diagnostic level. (cpp_errno): New. * cppexp.c (CPP_ICE): Remove. (SYNTAX_ERROR, SYNTAX_ERROR2, parse_number, parse_defined, lex, integer_overflow, _cpp_parse_expr): Update. * cppfiles.c (read_include_file, find_include_file, handle_missing_header, _cpp_read_file, remap_filename): Update. * cpphash.h (enum error_type): Remove. (_cpp_begin_message): Update. * cppinit.c (append_include_chain, remove_dup_dirs, output_deps, cpp_handle_option, cpp_post_options): Update. * cpplex.c (trigraph_p, skip_escaped_newlines, skip_block_comment, skip_whitespace, parse_identifier, parse_slow, parse_string, _cpp_lex_direct, cpp_spell_token, maybe_read_ucs, cpp_parse_escape, cpp_interpret_charconst): Update. * cpplib.c (check_eol, directive_diagnostics, _cpp_handle_directive, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, read_flag, do_line, do_linemarker, do_ident, cpp_register_pragma, do_pragma_once, do_pragma_system_header, do_pragma_poison, do_pragma_dependency, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, parse_assertion, do_assert, _cpp_pop_buffer, do_diagnostic): Update. * cpplib.h (DL_WARNING, DL_WARNING_SYSHDR, DL_PEDWARN, DL_ERROR, DL_FATAL, DL_ICE, DL_EXTRACT, DL_WARNING_P): New. (cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_notice, cpp_notice_from_errno): Remove. (cpp_error, cpp_error_with_line): Update to take a diagnostic level. (cpp_errno): New. * cppmacro.c (builtin_macro, stringify_arg, paste_all_tokens, collect_args, enter_macro_context, save_parameter, parse_params, _cpp_create_definition, check_trad_stringification, cpp_macro_definition): Update. * cppmain.c (cpp_preprocess_file): Update. * fix-header.c (read_scan_file): Update. From-SVN: r52302
2002-04-14 20:42:47 +02:00
cpp_error (pfile, DL_WARNING,
"%s is shorter than expected", inc->name);
size = offset;
buf = xrealloc (buf, size + 1);
inc->st.st_size = size;
break;
}
offset += count;
}
cppfiles.c (ENABLE_VALGRIND_CHECKING, [...]): Remove. * cppfiles.c (ENABLE_VALGRIND_CHECKING, VALGRIND_DISCARD, MMAP_THRESHOLD, TEST_THRESHOLD, SHOULD_MMAP): Remove. (struct include_file): Remove fefcnt, mapped members. (open_file, stack_include_file, _cpp_pop_file_buffer): Disable caching. (read_include_file): Don't use mmap, terminate buffers in '\r'. (purge_cache): Don't use munmap. * cpphash.h (CPP_BUF_COLUMN): Update. (lexer_state): Remove lexing_comment. (struct _cpp_line_note): New. (struct cpp_buffer): New members cur_note, notes_used, notes_cap, next_line and need_line. Remove col_adjust and saved_flags. (_cpp_process_line_notes, _cpp_clean_line, _cpp_get_fresh_line, _cpp_skip_block_comment, scan_out_logical_line): New. (_cpp_init_mbchar): Remove. * cppinit.c (init_library): Remove call to _cpp_init_mbchar. (cpp_read_main_file): Set line to 1 earlier. (post_options): -traditional-cpp doesn't want trigraphs. * cpplex.c (MULTIBYTE_CHARS): Remove code predicated on this. (add_line_note, _cpp_clean_line, _cpp_process_line_notes, _cpp_get_fresh_line): New. (handle_newline, skip_escaped_newlines, trigraph_p, continue_after_nul, _cpp_init_mbchar): Remove. (get_effective_char): Update. (_cpp_skip_block_comment): Rename from skip_block_comment, simplify. (skip_line_comment): Simplify. (skip_whitespace, parse_identifier, parse_slow, parse_number, parse_string): Update. (cpp_lex_direct): Use clean lines and process line notes. Update. (cpp_interpret_charconst): No MULTIBYTE_CHARS. * cpplib.c (prepare_directive_trad): Call scan_out_logical_line directly. (_cpp_handle_directive): Don't set saved_flags. (run_directive, destringize_and_run, cpp_define, cpp_define_builtin, cpp_undef, handle_assertion, cpp_push_buffer): Update. (_cpp_pop_buffer): Free notes. * cppmacro.c (builtin_macro, paste_tokens): \n terminate buffer. * cpppch.c (cpp_read_state): \n terminate buffer. * cpptrad.c (skip_escaped_newlines, handle_newline): Remove. (copy_comment): Use _cpp_skip_block_comment. (skip_whitespace, lex_identifier, _cpp_read_logical_line_trad): Simplify. (_cpp_overlay_buffer, _cpp_remove_overlay, push_replacement_text, save_replacement_text): Update. (scan_out_logical_line): Update to use clean lines and process line notes. * fix-header.c (read_scan_file): Update. testsuite: * gcc.dg/cpp/_Pragma4.c: Remove stray space. * gcc.dg/cpp/trad/escaped-eof.c: Correct line number. From-SVN: r65808
2003-04-19 02:22:51 +02:00
/* The lexer requires that the buffer be \n-terminated. */
buf[size] = '\n';
}
}
else if (S_ISBLK (inc->st.st_mode))
{
cpperror.c (print_location): Don't print include chain if line == 0. * cpperror.c (print_location): Don't print include chain if line == 0. (cpp_begin_message): Update to use DL_ macros. (cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_notice, cpp_notice_from_errno): Remove. (cpp_error, cpp_error_with_line): Update to take a diagnostic level. (cpp_errno): New. * cppexp.c (CPP_ICE): Remove. (SYNTAX_ERROR, SYNTAX_ERROR2, parse_number, parse_defined, lex, integer_overflow, _cpp_parse_expr): Update. * cppfiles.c (read_include_file, find_include_file, handle_missing_header, _cpp_read_file, remap_filename): Update. * cpphash.h (enum error_type): Remove. (_cpp_begin_message): Update. * cppinit.c (append_include_chain, remove_dup_dirs, output_deps, cpp_handle_option, cpp_post_options): Update. * cpplex.c (trigraph_p, skip_escaped_newlines, skip_block_comment, skip_whitespace, parse_identifier, parse_slow, parse_string, _cpp_lex_direct, cpp_spell_token, maybe_read_ucs, cpp_parse_escape, cpp_interpret_charconst): Update. * cpplib.c (check_eol, directive_diagnostics, _cpp_handle_directive, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, read_flag, do_line, do_linemarker, do_ident, cpp_register_pragma, do_pragma_once, do_pragma_system_header, do_pragma_poison, do_pragma_dependency, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, parse_assertion, do_assert, _cpp_pop_buffer, do_diagnostic): Update. * cpplib.h (DL_WARNING, DL_WARNING_SYSHDR, DL_PEDWARN, DL_ERROR, DL_FATAL, DL_ICE, DL_EXTRACT, DL_WARNING_P): New. (cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_notice, cpp_notice_from_errno): Remove. (cpp_error, cpp_error_with_line): Update to take a diagnostic level. (cpp_errno): New. * cppmacro.c (builtin_macro, stringify_arg, paste_all_tokens, collect_args, enter_macro_context, save_parameter, parse_params, _cpp_create_definition, check_trad_stringification, cpp_macro_definition): Update. * cppmain.c (cpp_preprocess_file): Update. * fix-header.c (read_scan_file): Update. From-SVN: r52302
2002-04-14 20:42:47 +02:00
cpp_error (pfile, DL_ERROR, "%s is a block device", inc->name);
goto fail;
}
else
{
/* 8 kilobytes is a sensible starting size. It ought to be
bigger than the kernel pipe buffer, and it's definitely
bigger than the majority of C source files. */
size = 8 * 1024;
buf = xmalloc (size + 1);
offset = 0;
while ((count = read (inc->fd, buf + offset, size - offset)) > 0)
cpplex.c (cpp_output_tokens, [...]): New public interfaces. * cpplex.c (cpp_output_tokens, cpp_scan_buffer_nooutput): New public interfaces. (safe_fwrite, output_line_command): New static functions. (cpp_expand_to_buffer): Now private to cpplib. (cpp_scan_buffer): Take a printer. * cpphash.h: Update prototypes. * cpplib.h: Update prototypes. (cpp_printer): New. (cpp_buffer): Remove last_nominal_fname. (cpp_reader): Remove lineno. * cppmain.c: Use a cpp_printer. * fix-header.c: No need to inhibit line commands. Call cpp_start_read with no printer. * cpperror.c (cpp_notice_from_errno): Provide default name. * cppfiles.c (make_IHASH, _cpp_fake_ihash): New functions. (find_include_file, cpp_read_file): Use make_IHASH. (file_cleanup): Set control_macro and clear input_stack_listing_current here. (_cpp_execute_include): Don't output entering-file marker. * cpphash.c (special_symbol): Look for the line number in the buffer, not the reader. (_cpp_macroexpand): No need to disable line commands. (_cpp_dump_definition): No need to generate line commands. (dump_hash_helper): Remove excess newline from output. * cppinit.c (dump_special_to_buffer): No need to generate line commands. (cpp_printer_init): New. (cpp_start_read): Take a printer, and start it up if it's not NULL. No need to generate line commands. (cpp_finish): Expect no buffers stacked at all. Take a printer argument, and flush the output buffer if it's not NULL. * cpplex.c (_cpp_lex_token): Return EOF if there's no buffer. Don't put two hashes at the beginning of an assertion. (cpp_get_token): Don't increment pfile->lineno or emit line commands here. Return EOF if there's no buffer when we get EOF. * cpplib.c (do_define, skip_if_group): No need to disable line commands. (_cpp_output_line_command): Delete function. (do_line): Don't emit line commands here, but set things up so they will be emitted if necessary. Use _cpp_fake_ihash to make unique nominal_fnames if necessary. (do_elif, do_else, _cpp_handle_eof): Call cpp_error_with_line with 0 for column, not -1. (_cpp_handle_eof): Don't set the control macro here. Don't clear input_stack_listing_current here. Don't emit line commands. From-SVN: r33159
2000-04-15 01:29:45 +02:00
{
offset += count;
if (offset == size)
cppfiles.c (stack_include_file): Don't optimize zero-length files. * cppfiles.c (stack_include_file): Don't optimize zero-length files. (read_include_file): NUL-terminate read files. * cpplex.c (handle_newline, skip_escaped_newlines, get_effective_char, skip_whitespace, parse_identifier, parse_identifier_slow, parse_number, parse_string, _cpp_lex_direct): Optimize for the fact that buffers are guaranteed NUL-terminated. * cpplib.c (destringize_and_run, cpp_define, handle_assertion): Be sure buffers are NUL terminated. * cppmacro.c (warn_of_redefinition): Kill compile warning. * c-common.c: Include tree-inline.h. (c_language): Move separate definitions here. (c_common_init_options, c_common_post_options): New. (c_common_lang_init): Rename c_common_init. * c-common.h (c_common_lang_init): Similarly. (c_common_init_options, c_common_post_options): New. * c-lang.c (c_post_options): Move body to c_common_post_options. (c_init_options): Use c_common_init_options. (c_init): Update. * langhooks.def: Rearrange. * langhooks.h: Rearrange, and improve comments. * toplev.c (do_compile): New function. (toplev_main): Use it. (lang_independent_f_options, parse_options_and_default_flags, process_options): Remove trailing periods. * Makefile.in: Update. cp: * decl2.c (c_language): Move to c-common.c. * lex.c (cxx_post_options, cxx_init_options): Use c-common.c functions. (cxx_init): Update. objc: * objc-act.c (objc_post_options, objc_init_options): Use c-common.c functions. (ojbc_init): Update. From-SVN: r47362
2001-11-27 00:44:54 +01:00
{
size *= 2;
buf = xrealloc (buf, size + 1);
}
cpplex.c (cpp_output_tokens, [...]): New public interfaces. * cpplex.c (cpp_output_tokens, cpp_scan_buffer_nooutput): New public interfaces. (safe_fwrite, output_line_command): New static functions. (cpp_expand_to_buffer): Now private to cpplib. (cpp_scan_buffer): Take a printer. * cpphash.h: Update prototypes. * cpplib.h: Update prototypes. (cpp_printer): New. (cpp_buffer): Remove last_nominal_fname. (cpp_reader): Remove lineno. * cppmain.c: Use a cpp_printer. * fix-header.c: No need to inhibit line commands. Call cpp_start_read with no printer. * cpperror.c (cpp_notice_from_errno): Provide default name. * cppfiles.c (make_IHASH, _cpp_fake_ihash): New functions. (find_include_file, cpp_read_file): Use make_IHASH. (file_cleanup): Set control_macro and clear input_stack_listing_current here. (_cpp_execute_include): Don't output entering-file marker. * cpphash.c (special_symbol): Look for the line number in the buffer, not the reader. (_cpp_macroexpand): No need to disable line commands. (_cpp_dump_definition): No need to generate line commands. (dump_hash_helper): Remove excess newline from output. * cppinit.c (dump_special_to_buffer): No need to generate line commands. (cpp_printer_init): New. (cpp_start_read): Take a printer, and start it up if it's not NULL. No need to generate line commands. (cpp_finish): Expect no buffers stacked at all. Take a printer argument, and flush the output buffer if it's not NULL. * cpplex.c (_cpp_lex_token): Return EOF if there's no buffer. Don't put two hashes at the beginning of an assertion. (cpp_get_token): Don't increment pfile->lineno or emit line commands here. Return EOF if there's no buffer when we get EOF. * cpplib.c (do_define, skip_if_group): No need to disable line commands. (_cpp_output_line_command): Delete function. (do_line): Don't emit line commands here, but set things up so they will be emitted if necessary. Use _cpp_fake_ihash to make unique nominal_fnames if necessary. (do_elif, do_else, _cpp_handle_eof): Call cpp_error_with_line with 0 for column, not -1. (_cpp_handle_eof): Don't set the control macro here. Don't clear input_stack_listing_current here. Don't emit line commands. From-SVN: r33159
2000-04-15 01:29:45 +02:00
}
if (count < 0)
goto perror_fail;
cppfiles.c (stack_include_file): Don't optimize zero-length files. * cppfiles.c (stack_include_file): Don't optimize zero-length files. (read_include_file): NUL-terminate read files. * cpplex.c (handle_newline, skip_escaped_newlines, get_effective_char, skip_whitespace, parse_identifier, parse_identifier_slow, parse_number, parse_string, _cpp_lex_direct): Optimize for the fact that buffers are guaranteed NUL-terminated. * cpplib.c (destringize_and_run, cpp_define, handle_assertion): Be sure buffers are NUL terminated. * cppmacro.c (warn_of_redefinition): Kill compile warning. * c-common.c: Include tree-inline.h. (c_language): Move separate definitions here. (c_common_init_options, c_common_post_options): New. (c_common_lang_init): Rename c_common_init. * c-common.h (c_common_lang_init): Similarly. (c_common_init_options, c_common_post_options): New. * c-lang.c (c_post_options): Move body to c_common_post_options. (c_init_options): Use c_common_init_options. (c_init): Update. * langhooks.def: Rearrange. * langhooks.h: Rearrange, and improve comments. * toplev.c (do_compile): New function. (toplev_main): Use it. (lang_independent_f_options, parse_options_and_default_flags, process_options): Remove trailing periods. * Makefile.in: Update. cp: * decl2.c (c_language): Move to c-common.c. * lex.c (cxx_post_options, cxx_init_options): Use c-common.c functions. (cxx_init): Update. objc: * objc-act.c (objc_post_options, objc_init_options): Use c-common.c functions. (ojbc_init): Update. From-SVN: r47362
2001-11-27 00:44:54 +01:00
if (offset + 1 < size)
buf = xrealloc (buf, offset + 1);
cppfiles.c (ENABLE_VALGRIND_CHECKING, [...]): Remove. * cppfiles.c (ENABLE_VALGRIND_CHECKING, VALGRIND_DISCARD, MMAP_THRESHOLD, TEST_THRESHOLD, SHOULD_MMAP): Remove. (struct include_file): Remove fefcnt, mapped members. (open_file, stack_include_file, _cpp_pop_file_buffer): Disable caching. (read_include_file): Don't use mmap, terminate buffers in '\r'. (purge_cache): Don't use munmap. * cpphash.h (CPP_BUF_COLUMN): Update. (lexer_state): Remove lexing_comment. (struct _cpp_line_note): New. (struct cpp_buffer): New members cur_note, notes_used, notes_cap, next_line and need_line. Remove col_adjust and saved_flags. (_cpp_process_line_notes, _cpp_clean_line, _cpp_get_fresh_line, _cpp_skip_block_comment, scan_out_logical_line): New. (_cpp_init_mbchar): Remove. * cppinit.c (init_library): Remove call to _cpp_init_mbchar. (cpp_read_main_file): Set line to 1 earlier. (post_options): -traditional-cpp doesn't want trigraphs. * cpplex.c (MULTIBYTE_CHARS): Remove code predicated on this. (add_line_note, _cpp_clean_line, _cpp_process_line_notes, _cpp_get_fresh_line): New. (handle_newline, skip_escaped_newlines, trigraph_p, continue_after_nul, _cpp_init_mbchar): Remove. (get_effective_char): Update. (_cpp_skip_block_comment): Rename from skip_block_comment, simplify. (skip_line_comment): Simplify. (skip_whitespace, parse_identifier, parse_slow, parse_number, parse_string): Update. (cpp_lex_direct): Use clean lines and process line notes. Update. (cpp_interpret_charconst): No MULTIBYTE_CHARS. * cpplib.c (prepare_directive_trad): Call scan_out_logical_line directly. (_cpp_handle_directive): Don't set saved_flags. (run_directive, destringize_and_run, cpp_define, cpp_define_builtin, cpp_undef, handle_assertion, cpp_push_buffer): Update. (_cpp_pop_buffer): Free notes. * cppmacro.c (builtin_macro, paste_tokens): \n terminate buffer. * cpppch.c (cpp_read_state): \n terminate buffer. * cpptrad.c (skip_escaped_newlines, handle_newline): Remove. (copy_comment): Use _cpp_skip_block_comment. (skip_whitespace, lex_identifier, _cpp_read_logical_line_trad): Simplify. (_cpp_overlay_buffer, _cpp_remove_overlay, push_replacement_text, save_replacement_text): Update. (scan_out_logical_line): Update to use clean lines and process line notes. * fix-header.c (read_scan_file): Update. testsuite: * gcc.dg/cpp/_Pragma4.c: Remove stray space. * gcc.dg/cpp/trad/escaped-eof.c: Correct line number. From-SVN: r65808
2003-04-19 02:22:51 +02:00
/* The lexer requires that the buffer be \n-terminated. */
buf[offset] = '\n';
inc->st.st_size = offset;
cpplex.c (cpp_output_tokens, [...]): New public interfaces. * cpplex.c (cpp_output_tokens, cpp_scan_buffer_nooutput): New public interfaces. (safe_fwrite, output_line_command): New static functions. (cpp_expand_to_buffer): Now private to cpplib. (cpp_scan_buffer): Take a printer. * cpphash.h: Update prototypes. * cpplib.h: Update prototypes. (cpp_printer): New. (cpp_buffer): Remove last_nominal_fname. (cpp_reader): Remove lineno. * cppmain.c: Use a cpp_printer. * fix-header.c: No need to inhibit line commands. Call cpp_start_read with no printer. * cpperror.c (cpp_notice_from_errno): Provide default name. * cppfiles.c (make_IHASH, _cpp_fake_ihash): New functions. (find_include_file, cpp_read_file): Use make_IHASH. (file_cleanup): Set control_macro and clear input_stack_listing_current here. (_cpp_execute_include): Don't output entering-file marker. * cpphash.c (special_symbol): Look for the line number in the buffer, not the reader. (_cpp_macroexpand): No need to disable line commands. (_cpp_dump_definition): No need to generate line commands. (dump_hash_helper): Remove excess newline from output. * cppinit.c (dump_special_to_buffer): No need to generate line commands. (cpp_printer_init): New. (cpp_start_read): Take a printer, and start it up if it's not NULL. No need to generate line commands. (cpp_finish): Expect no buffers stacked at all. Take a printer argument, and flush the output buffer if it's not NULL. * cpplex.c (_cpp_lex_token): Return EOF if there's no buffer. Don't put two hashes at the beginning of an assertion. (cpp_get_token): Don't increment pfile->lineno or emit line commands here. Return EOF if there's no buffer when we get EOF. * cpplib.c (do_define, skip_if_group): No need to disable line commands. (_cpp_output_line_command): Delete function. (do_line): Don't emit line commands here, but set things up so they will be emitted if necessary. Use _cpp_fake_ihash to make unique nominal_fnames if necessary. (do_elif, do_else, _cpp_handle_eof): Call cpp_error_with_line with 0 for column, not -1. (_cpp_handle_eof): Don't set the control macro here. Don't clear input_stack_listing_current here. Don't emit line commands. From-SVN: r33159
2000-04-15 01:29:45 +02:00
}
inc->buffer = buf;
return 0;
perror_fail:
cpperror.c (print_location): Don't print include chain if line == 0. * cpperror.c (print_location): Don't print include chain if line == 0. (cpp_begin_message): Update to use DL_ macros. (cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_notice, cpp_notice_from_errno): Remove. (cpp_error, cpp_error_with_line): Update to take a diagnostic level. (cpp_errno): New. * cppexp.c (CPP_ICE): Remove. (SYNTAX_ERROR, SYNTAX_ERROR2, parse_number, parse_defined, lex, integer_overflow, _cpp_parse_expr): Update. * cppfiles.c (read_include_file, find_include_file, handle_missing_header, _cpp_read_file, remap_filename): Update. * cpphash.h (enum error_type): Remove. (_cpp_begin_message): Update. * cppinit.c (append_include_chain, remove_dup_dirs, output_deps, cpp_handle_option, cpp_post_options): Update. * cpplex.c (trigraph_p, skip_escaped_newlines, skip_block_comment, skip_whitespace, parse_identifier, parse_slow, parse_string, _cpp_lex_direct, cpp_spell_token, maybe_read_ucs, cpp_parse_escape, cpp_interpret_charconst): Update. * cpplib.c (check_eol, directive_diagnostics, _cpp_handle_directive, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, read_flag, do_line, do_linemarker, do_ident, cpp_register_pragma, do_pragma_once, do_pragma_system_header, do_pragma_poison, do_pragma_dependency, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, parse_assertion, do_assert, _cpp_pop_buffer, do_diagnostic): Update. * cpplib.h (DL_WARNING, DL_WARNING_SYSHDR, DL_PEDWARN, DL_ERROR, DL_FATAL, DL_ICE, DL_EXTRACT, DL_WARNING_P): New. (cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_notice, cpp_notice_from_errno): Remove. (cpp_error, cpp_error_with_line): Update to take a diagnostic level. (cpp_errno): New. * cppmacro.c (builtin_macro, stringify_arg, paste_all_tokens, collect_args, enter_macro_context, save_parameter, parse_params, _cpp_create_definition, check_trad_stringification, cpp_macro_definition): Update. * cppmain.c (cpp_preprocess_file): Update. * fix-header.c (read_scan_file): Update. From-SVN: r52302
2002-04-14 20:42:47 +02:00
cpp_errno (pfile, DL_ERROR, inc->name);
fail:
return 1;
}
cppfiles.c (ENABLE_VALGRIND_CHECKING, [...]): Remove. * cppfiles.c (ENABLE_VALGRIND_CHECKING, VALGRIND_DISCARD, MMAP_THRESHOLD, TEST_THRESHOLD, SHOULD_MMAP): Remove. (struct include_file): Remove fefcnt, mapped members. (open_file, stack_include_file, _cpp_pop_file_buffer): Disable caching. (read_include_file): Don't use mmap, terminate buffers in '\r'. (purge_cache): Don't use munmap. * cpphash.h (CPP_BUF_COLUMN): Update. (lexer_state): Remove lexing_comment. (struct _cpp_line_note): New. (struct cpp_buffer): New members cur_note, notes_used, notes_cap, next_line and need_line. Remove col_adjust and saved_flags. (_cpp_process_line_notes, _cpp_clean_line, _cpp_get_fresh_line, _cpp_skip_block_comment, scan_out_logical_line): New. (_cpp_init_mbchar): Remove. * cppinit.c (init_library): Remove call to _cpp_init_mbchar. (cpp_read_main_file): Set line to 1 earlier. (post_options): -traditional-cpp doesn't want trigraphs. * cpplex.c (MULTIBYTE_CHARS): Remove code predicated on this. (add_line_note, _cpp_clean_line, _cpp_process_line_notes, _cpp_get_fresh_line): New. (handle_newline, skip_escaped_newlines, trigraph_p, continue_after_nul, _cpp_init_mbchar): Remove. (get_effective_char): Update. (_cpp_skip_block_comment): Rename from skip_block_comment, simplify. (skip_line_comment): Simplify. (skip_whitespace, parse_identifier, parse_slow, parse_number, parse_string): Update. (cpp_lex_direct): Use clean lines and process line notes. Update. (cpp_interpret_charconst): No MULTIBYTE_CHARS. * cpplib.c (prepare_directive_trad): Call scan_out_logical_line directly. (_cpp_handle_directive): Don't set saved_flags. (run_directive, destringize_and_run, cpp_define, cpp_define_builtin, cpp_undef, handle_assertion, cpp_push_buffer): Update. (_cpp_pop_buffer): Free notes. * cppmacro.c (builtin_macro, paste_tokens): \n terminate buffer. * cpppch.c (cpp_read_state): \n terminate buffer. * cpptrad.c (skip_escaped_newlines, handle_newline): Remove. (copy_comment): Use _cpp_skip_block_comment. (skip_whitespace, lex_identifier, _cpp_read_logical_line_trad): Simplify. (_cpp_overlay_buffer, _cpp_remove_overlay, push_replacement_text, save_replacement_text): Update. (scan_out_logical_line): Update to use clean lines and process line notes. * fix-header.c (read_scan_file): Update. testsuite: * gcc.dg/cpp/_Pragma4.c: Remove stray space. * gcc.dg/cpp/trad/escaped-eof.c: Correct line number. From-SVN: r65808
2003-04-19 02:22:51 +02:00
/* Drop INC's buffer from memory. */
static void
purge_cache (struct include_file *inc)
{
if (inc->buffer)
{
free ((void *) inc->buffer);
inc->buffer = NULL;
}
}
/* Return 1 if the file named by FNAME has been included before in
any context, 0 otherwise. */
int
cpp_included (cpp_reader *pfile, const char *fname)
[multiple changes] 1998-10-28 16:10 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * c-lang.c: Declare extern char *yy_cur if USE_CPPLIB. (lang_init): Call check_newline always. * c-lex.c (init_parse) [USE_CPPLIB=1]: After calling cpp_start_read, set yy_cur and yy_lim to read from parse_in.token_buffer, so that we'll see the first #line directive. * cpplib.c (cpp_start_read): finclude the main input file before processing -include/-imacros. Process -imacros and -include separately, and handle -include by stacking a buffer for the file in question as if it'd been #included. * toplev.c (documented_lang_options) Recognize -H when USE_CPPLIB is on. 1998-10-28 16:09 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.c: Merge do_once into do_pragma. Break file handling code out of do_include. Move append_include_chain, deps_output, file_cleanup, redundant_include_p, import_hash, lookup_import, add_import, read_filename_string, read_name_map, open_include_file, finclude, safe_read to cppfiles.c. Move prototypes for deps_output, append_include_chain, finclude to cpplib.h. Move definition of struct file_name_list there also. * cppfiles.c: New file. Contains all the above functions broken out of cpplib.c; also hack_vms_include_specification from cccp.c and find_include_file, a new function broken out of do_include. * Makefile.in (cppmain): Depend on cppfiles.o. (fix-header): Likewise. (cppfiles.o): New target. * configure.in (--enable-c-cpplib): Add cppfiles.o to extra_c_objs. Add ../cppfiles.o to extra_cxx_objs. From-SVN: r23424
1998-10-29 12:54:13 +01:00
{
Makefile.in (C_AND_OBJC_OBJS, [...]): Update. * Makefile.in (C_AND_OBJC_OBJS, c-incpath.o, c-lex.o, LIBCPP_OBJS, cppinit.o, cppdefault.o, fix-header): Update. * c-incpath.c: New file. * c-incpath.h: New file. * c-lex.c: Include c-incpath.h. (init_c_lex): Register path simplifier. * c-opts.c: Include cppdefault.h and c-incpath.h. (TARGET_SYSTEM_ROOT, verbose, iprefix, sysroot, std_inc, std_cxx_inc, quote_chain_split, add_prefixed_path): New. (COMMAND_LINE_OPTIONS): Add more options from cpplib. (missing_arg, c_common_decode_option): Handle them. (c_common_post_options): Register include chains. (print_help): Update. * cppdefault.h (struct default include): Update. Move some macros to ... * cppdefault.c: ... here. (cpp_include_defaults): Add extra field add_sysroot. * cppfiles.c (include_file, search_from, find_or_create_entry, cpp_included, find_include_file, remap_filename): Update for renaming of search_path to cpp_path, and of the chain headers. (remove_component_p, _cpp_simplify_pathname): Move to c-incpath.c. * cpphash.h (struct search_path): Move to cpplib.h. (struct cpp_buffer, struct cpp_reader): Update. (_cpp_simplify_pathname): Remove. * cppinit.c: Don't include prefix.h and cppdefault.h. (INO_T_EQ, INO_T_COPY, path_include, append_include_chain, remove_dup_dir, remove_dup_nonsys_dirs, remove_dup_dirs, init_standard_includes, BRACKET, SYSTEM, AFTER, no_dir, no_pth, cpp_handle_options): Remove. (struct pending_option): Remove chain members. (cpp_destroy, cpp_read_main_file, COMMAND_LINE_OPTIONS, cpp_handle_option): Update. * cpplib.h (struct cpp_path, cpp_set_include_chains): New. (struct cpp_options): Remove quote_include, bracket_include, include_prefix, include_prefix_len, verbose, ignore_srcdir, no_standard_includes, no_standard_cplusplus_includes. (struct cpp_callbacks): Add simplify_path. (cpp_handle_options): Remove. * fix-header.c: Include c-incpath.h. (read_scan_file): Update to use c-incpath functionality. * doc/passes.texi: Update. cp: * Make-lang.in (CXX_C_OBJS): Update. From-SVN: r63612
2003-03-01 15:31:21 +01:00
struct cpp_path *path;
char *name, *n;
splay_tree_node nd;
cpplib.h: Delete struct import_file. Wed Nov 25 14:54:46 1998 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.h: Delete struct import_file. Add ihash element to struct cpp_buffer. Delete dont_repeat_files and import_hash_table elements from cpp_reader; change all_include_files to a hash table. Delete all foobar_include / last_foobar_include elements from struct cpp_options; put back four such: quote_include, bracket_include, system_include, after_include. Redo struct file_name_list completely. Add new structure type include_hash. Add prototypes for merge_include_chains and include_hash. Change prototypes for finclude, find_include_file, and append_include_chain to match changes below. * cppfiles.c (simplify_pathname, include_hash, remap_filename, merge_include_chains): New functions. (add_import, lookup_import, open_include_file): Removed. (INO_T_EQ): Define this (copied from cccp.c). (hack_vms_include_specification): Remove all calls and #if 0 out the definition. It was being called incorrectly and at the wrong times. Until a VMSie can look at this, it's better to not pretend to support it. (append_include_chain): Change calling convention; now takes only one directory at a time, and sets up the data structure itself. (redundant_include_p): Rewritten - this is now used for all include redundancy, whether by #ifndef, #import, or #pragma once. Looks up things in the include hash table. (file_cleanup): Decrement pfile->system_include_depth here if it's >0. (find_include_file): Calling convention changed; now passes around a struct include_hash instead of 3 separate parameters. Guts ripped out and replaced with new include_hash mechanism. (finclude): Calling convention changed as for find_include_file. Error exits pulled out-of-line. Reformat. (safe_read): Return a long, not an int. (deps_output): Don't recurse. * cpplib.c (is_system_include): Deleted. (path_include): Fix up call to append_include_chain. (do_include): Fix up calls to find_include_file and finclude. Clean up dependency output a bit. Shorten obnoxiously lengthy #import warning message. Don't decrement pfile->system_include_depth here. (do_pragma): Understand the include_hash structure. Reformat. (do_endif): Correct handling of control macros. Understand the include_hash. (cpp_start_read): Fix up calls to finclude. Call merge_include_chains. (cpp_handle_option): Fix up calls to append_include_chain. Understand the four partial include chains. (cpp_finish): Add debugging code (#if 0-ed out) for the include_hash. (cpp_cleanup): Free the include_hash, not the import hash and the all_include and dont_repeat lists which no longer exist. From-SVN: r23857
1998-11-25 12:56:54 +01:00
if (IS_ABSOLUTE_PATH (fname))
cpplib.h: Delete struct import_file. Wed Nov 25 14:54:46 1998 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.h: Delete struct import_file. Add ihash element to struct cpp_buffer. Delete dont_repeat_files and import_hash_table elements from cpp_reader; change all_include_files to a hash table. Delete all foobar_include / last_foobar_include elements from struct cpp_options; put back four such: quote_include, bracket_include, system_include, after_include. Redo struct file_name_list completely. Add new structure type include_hash. Add prototypes for merge_include_chains and include_hash. Change prototypes for finclude, find_include_file, and append_include_chain to match changes below. * cppfiles.c (simplify_pathname, include_hash, remap_filename, merge_include_chains): New functions. (add_import, lookup_import, open_include_file): Removed. (INO_T_EQ): Define this (copied from cccp.c). (hack_vms_include_specification): Remove all calls and #if 0 out the definition. It was being called incorrectly and at the wrong times. Until a VMSie can look at this, it's better to not pretend to support it. (append_include_chain): Change calling convention; now takes only one directory at a time, and sets up the data structure itself. (redundant_include_p): Rewritten - this is now used for all include redundancy, whether by #ifndef, #import, or #pragma once. Looks up things in the include hash table. (file_cleanup): Decrement pfile->system_include_depth here if it's >0. (find_include_file): Calling convention changed; now passes around a struct include_hash instead of 3 separate parameters. Guts ripped out and replaced with new include_hash mechanism. (finclude): Calling convention changed as for find_include_file. Error exits pulled out-of-line. Reformat. (safe_read): Return a long, not an int. (deps_output): Don't recurse. * cpplib.c (is_system_include): Deleted. (path_include): Fix up call to append_include_chain. (do_include): Fix up calls to find_include_file and finclude. Clean up dependency output a bit. Shorten obnoxiously lengthy #import warning message. Don't decrement pfile->system_include_depth here. (do_pragma): Understand the include_hash structure. Reformat. (do_endif): Correct handling of control macros. Understand the include_hash. (cpp_start_read): Fix up calls to finclude. Call merge_include_chains. (cpp_handle_option): Fix up calls to append_include_chain. Understand the four partial include chains. (cpp_finish): Add debugging code (#if 0-ed out) for the include_hash. (cpp_cleanup): Free the include_hash, not the import hash and the all_include and dont_repeat lists which no longer exist. From-SVN: r23857
1998-11-25 12:56:54 +01:00
{
/* Just look it up. */
nd = splay_tree_lookup (pfile->all_include_files, (splay_tree_key) fname);
return (nd && nd->value);
cpplib.h: Delete struct import_file. Wed Nov 25 14:54:46 1998 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.h: Delete struct import_file. Add ihash element to struct cpp_buffer. Delete dont_repeat_files and import_hash_table elements from cpp_reader; change all_include_files to a hash table. Delete all foobar_include / last_foobar_include elements from struct cpp_options; put back four such: quote_include, bracket_include, system_include, after_include. Redo struct file_name_list completely. Add new structure type include_hash. Add prototypes for merge_include_chains and include_hash. Change prototypes for finclude, find_include_file, and append_include_chain to match changes below. * cppfiles.c (simplify_pathname, include_hash, remap_filename, merge_include_chains): New functions. (add_import, lookup_import, open_include_file): Removed. (INO_T_EQ): Define this (copied from cccp.c). (hack_vms_include_specification): Remove all calls and #if 0 out the definition. It was being called incorrectly and at the wrong times. Until a VMSie can look at this, it's better to not pretend to support it. (append_include_chain): Change calling convention; now takes only one directory at a time, and sets up the data structure itself. (redundant_include_p): Rewritten - this is now used for all include redundancy, whether by #ifndef, #import, or #pragma once. Looks up things in the include hash table. (file_cleanup): Decrement pfile->system_include_depth here if it's >0. (find_include_file): Calling convention changed; now passes around a struct include_hash instead of 3 separate parameters. Guts ripped out and replaced with new include_hash mechanism. (finclude): Calling convention changed as for find_include_file. Error exits pulled out-of-line. Reformat. (safe_read): Return a long, not an int. (deps_output): Don't recurse. * cpplib.c (is_system_include): Deleted. (path_include): Fix up call to append_include_chain. (do_include): Fix up calls to find_include_file and finclude. Clean up dependency output a bit. Shorten obnoxiously lengthy #import warning message. Don't decrement pfile->system_include_depth here. (do_pragma): Understand the include_hash structure. Reformat. (do_endif): Correct handling of control macros. Understand the include_hash. (cpp_start_read): Fix up calls to finclude. Call merge_include_chains. (cpp_handle_option): Fix up calls to append_include_chain. Understand the four partial include chains. (cpp_finish): Add debugging code (#if 0-ed out) for the include_hash. (cpp_cleanup): Free the include_hash, not the import hash and the all_include and dont_repeat lists which no longer exist. From-SVN: r23857
1998-11-25 12:56:54 +01:00
}
/* Search directory path for the file. */
name = alloca (strlen (fname) + pfile->max_include_len + 2);
Makefile.in (C_AND_OBJC_OBJS, [...]): Update. * Makefile.in (C_AND_OBJC_OBJS, c-incpath.o, c-lex.o, LIBCPP_OBJS, cppinit.o, cppdefault.o, fix-header): Update. * c-incpath.c: New file. * c-incpath.h: New file. * c-lex.c: Include c-incpath.h. (init_c_lex): Register path simplifier. * c-opts.c: Include cppdefault.h and c-incpath.h. (TARGET_SYSTEM_ROOT, verbose, iprefix, sysroot, std_inc, std_cxx_inc, quote_chain_split, add_prefixed_path): New. (COMMAND_LINE_OPTIONS): Add more options from cpplib. (missing_arg, c_common_decode_option): Handle them. (c_common_post_options): Register include chains. (print_help): Update. * cppdefault.h (struct default include): Update. Move some macros to ... * cppdefault.c: ... here. (cpp_include_defaults): Add extra field add_sysroot. * cppfiles.c (include_file, search_from, find_or_create_entry, cpp_included, find_include_file, remap_filename): Update for renaming of search_path to cpp_path, and of the chain headers. (remove_component_p, _cpp_simplify_pathname): Move to c-incpath.c. * cpphash.h (struct search_path): Move to cpplib.h. (struct cpp_buffer, struct cpp_reader): Update. (_cpp_simplify_pathname): Remove. * cppinit.c: Don't include prefix.h and cppdefault.h. (INO_T_EQ, INO_T_COPY, path_include, append_include_chain, remove_dup_dir, remove_dup_nonsys_dirs, remove_dup_dirs, init_standard_includes, BRACKET, SYSTEM, AFTER, no_dir, no_pth, cpp_handle_options): Remove. (struct pending_option): Remove chain members. (cpp_destroy, cpp_read_main_file, COMMAND_LINE_OPTIONS, cpp_handle_option): Update. * cpplib.h (struct cpp_path, cpp_set_include_chains): New. (struct cpp_options): Remove quote_include, bracket_include, include_prefix, include_prefix_len, verbose, ignore_srcdir, no_standard_includes, no_standard_cplusplus_includes. (struct cpp_callbacks): Add simplify_path. (cpp_handle_options): Remove. * fix-header.c: Include c-incpath.h. (read_scan_file): Update to use c-incpath functionality. * doc/passes.texi: Update. cp: * Make-lang.in (CXX_C_OBJS): Update. From-SVN: r63612
2003-03-01 15:31:21 +01:00
for (path = pfile->quote_include; path; path = path->next)
cpplib.h: Delete struct import_file. Wed Nov 25 14:54:46 1998 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.h: Delete struct import_file. Add ihash element to struct cpp_buffer. Delete dont_repeat_files and import_hash_table elements from cpp_reader; change all_include_files to a hash table. Delete all foobar_include / last_foobar_include elements from struct cpp_options; put back four such: quote_include, bracket_include, system_include, after_include. Redo struct file_name_list completely. Add new structure type include_hash. Add prototypes for merge_include_chains and include_hash. Change prototypes for finclude, find_include_file, and append_include_chain to match changes below. * cppfiles.c (simplify_pathname, include_hash, remap_filename, merge_include_chains): New functions. (add_import, lookup_import, open_include_file): Removed. (INO_T_EQ): Define this (copied from cccp.c). (hack_vms_include_specification): Remove all calls and #if 0 out the definition. It was being called incorrectly and at the wrong times. Until a VMSie can look at this, it's better to not pretend to support it. (append_include_chain): Change calling convention; now takes only one directory at a time, and sets up the data structure itself. (redundant_include_p): Rewritten - this is now used for all include redundancy, whether by #ifndef, #import, or #pragma once. Looks up things in the include hash table. (file_cleanup): Decrement pfile->system_include_depth here if it's >0. (find_include_file): Calling convention changed; now passes around a struct include_hash instead of 3 separate parameters. Guts ripped out and replaced with new include_hash mechanism. (finclude): Calling convention changed as for find_include_file. Error exits pulled out-of-line. Reformat. (safe_read): Return a long, not an int. (deps_output): Don't recurse. * cpplib.c (is_system_include): Deleted. (path_include): Fix up call to append_include_chain. (do_include): Fix up calls to find_include_file and finclude. Clean up dependency output a bit. Shorten obnoxiously lengthy #import warning message. Don't decrement pfile->system_include_depth here. (do_pragma): Understand the include_hash structure. Reformat. (do_endif): Correct handling of control macros. Understand the include_hash. (cpp_start_read): Fix up calls to finclude. Call merge_include_chains. (cpp_handle_option): Fix up calls to append_include_chain. Understand the four partial include chains. (cpp_finish): Add debugging code (#if 0-ed out) for the include_hash. (cpp_cleanup): Free the include_hash, not the import hash and the all_include and dont_repeat lists which no longer exist. From-SVN: r23857
1998-11-25 12:56:54 +01:00
{
memcpy (name, path->name, path->len);
name[path->len] = '/';
strcpy (&name[path->len + 1], fname);
if (CPP_OPTION (pfile, remap))
n = remap_filename (pfile, name, path);
else
n = name;
nd = splay_tree_lookup (pfile->all_include_files, (splay_tree_key) n);
if (nd && nd->value)
return 1;
cpplib.h: Delete struct import_file. Wed Nov 25 14:54:46 1998 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.h: Delete struct import_file. Add ihash element to struct cpp_buffer. Delete dont_repeat_files and import_hash_table elements from cpp_reader; change all_include_files to a hash table. Delete all foobar_include / last_foobar_include elements from struct cpp_options; put back four such: quote_include, bracket_include, system_include, after_include. Redo struct file_name_list completely. Add new structure type include_hash. Add prototypes for merge_include_chains and include_hash. Change prototypes for finclude, find_include_file, and append_include_chain to match changes below. * cppfiles.c (simplify_pathname, include_hash, remap_filename, merge_include_chains): New functions. (add_import, lookup_import, open_include_file): Removed. (INO_T_EQ): Define this (copied from cccp.c). (hack_vms_include_specification): Remove all calls and #if 0 out the definition. It was being called incorrectly and at the wrong times. Until a VMSie can look at this, it's better to not pretend to support it. (append_include_chain): Change calling convention; now takes only one directory at a time, and sets up the data structure itself. (redundant_include_p): Rewritten - this is now used for all include redundancy, whether by #ifndef, #import, or #pragma once. Looks up things in the include hash table. (file_cleanup): Decrement pfile->system_include_depth here if it's >0. (find_include_file): Calling convention changed; now passes around a struct include_hash instead of 3 separate parameters. Guts ripped out and replaced with new include_hash mechanism. (finclude): Calling convention changed as for find_include_file. Error exits pulled out-of-line. Reformat. (safe_read): Return a long, not an int. (deps_output): Don't recurse. * cpplib.c (is_system_include): Deleted. (path_include): Fix up call to append_include_chain. (do_include): Fix up calls to find_include_file and finclude. Clean up dependency output a bit. Shorten obnoxiously lengthy #import warning message. Don't decrement pfile->system_include_depth here. (do_pragma): Understand the include_hash structure. Reformat. (do_endif): Correct handling of control macros. Understand the include_hash. (cpp_start_read): Fix up calls to finclude. Call merge_include_chains. (cpp_handle_option): Fix up calls to append_include_chain. Understand the four partial include chains. (cpp_finish): Add debugging code (#if 0-ed out) for the include_hash. (cpp_cleanup): Free the include_hash, not the import hash and the all_include and dont_repeat lists which no longer exist. From-SVN: r23857
1998-11-25 12:56:54 +01:00
}
return 0;
[multiple changes] 1998-10-28 16:10 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * c-lang.c: Declare extern char *yy_cur if USE_CPPLIB. (lang_init): Call check_newline always. * c-lex.c (init_parse) [USE_CPPLIB=1]: After calling cpp_start_read, set yy_cur and yy_lim to read from parse_in.token_buffer, so that we'll see the first #line directive. * cpplib.c (cpp_start_read): finclude the main input file before processing -include/-imacros. Process -imacros and -include separately, and handle -include by stacking a buffer for the file in question as if it'd been #included. * toplev.c (documented_lang_options) Recognize -H when USE_CPPLIB is on. 1998-10-28 16:09 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.c: Merge do_once into do_pragma. Break file handling code out of do_include. Move append_include_chain, deps_output, file_cleanup, redundant_include_p, import_hash, lookup_import, add_import, read_filename_string, read_name_map, open_include_file, finclude, safe_read to cppfiles.c. Move prototypes for deps_output, append_include_chain, finclude to cpplib.h. Move definition of struct file_name_list there also. * cppfiles.c: New file. Contains all the above functions broken out of cpplib.c; also hack_vms_include_specification from cccp.c and find_include_file, a new function broken out of do_include. * Makefile.in (cppmain): Depend on cppfiles.o. (fix-header): Likewise. (cppfiles.o): New target. * configure.in (--enable-c-cpplib): Add cppfiles.o to extra_c_objs. Add ../cppfiles.o to extra_cxx_objs. From-SVN: r23424
1998-10-29 12:54:13 +01:00
}
/* Search for FNAME. Return 0 if there is no such file (or it's
un-openable), in which case an error code will be in errno. If
there is no include path to use it returns NO_INCLUDE_PATH,
otherwise an include_file structure. If this request originates
from a directive of TYPE #include_next, set INCLUDE_NEXT to true. */
static struct include_file *
find_include_file (cpp_reader *pfile, const char *fname, int angle_brackets,
enum include_type type)
cpplex.c (cpp_output_tokens, [...]): New public interfaces. * cpplex.c (cpp_output_tokens, cpp_scan_buffer_nooutput): New public interfaces. (safe_fwrite, output_line_command): New static functions. (cpp_expand_to_buffer): Now private to cpplib. (cpp_scan_buffer): Take a printer. * cpphash.h: Update prototypes. * cpplib.h: Update prototypes. (cpp_printer): New. (cpp_buffer): Remove last_nominal_fname. (cpp_reader): Remove lineno. * cppmain.c: Use a cpp_printer. * fix-header.c: No need to inhibit line commands. Call cpp_start_read with no printer. * cpperror.c (cpp_notice_from_errno): Provide default name. * cppfiles.c (make_IHASH, _cpp_fake_ihash): New functions. (find_include_file, cpp_read_file): Use make_IHASH. (file_cleanup): Set control_macro and clear input_stack_listing_current here. (_cpp_execute_include): Don't output entering-file marker. * cpphash.c (special_symbol): Look for the line number in the buffer, not the reader. (_cpp_macroexpand): No need to disable line commands. (_cpp_dump_definition): No need to generate line commands. (dump_hash_helper): Remove excess newline from output. * cppinit.c (dump_special_to_buffer): No need to generate line commands. (cpp_printer_init): New. (cpp_start_read): Take a printer, and start it up if it's not NULL. No need to generate line commands. (cpp_finish): Expect no buffers stacked at all. Take a printer argument, and flush the output buffer if it's not NULL. * cpplex.c (_cpp_lex_token): Return EOF if there's no buffer. Don't put two hashes at the beginning of an assertion. (cpp_get_token): Don't increment pfile->lineno or emit line commands here. Return EOF if there's no buffer when we get EOF. * cpplib.c (do_define, skip_if_group): No need to disable line commands. (_cpp_output_line_command): Delete function. (do_line): Don't emit line commands here, but set things up so they will be emitted if necessary. Use _cpp_fake_ihash to make unique nominal_fnames if necessary. (do_elif, do_else, _cpp_handle_eof): Call cpp_error_with_line with 0 for column, not -1. (_cpp_handle_eof): Don't set the control macro here. Don't clear input_stack_listing_current here. Don't emit line commands. From-SVN: r33159
2000-04-15 01:29:45 +02:00
{
Makefile.in (C_AND_OBJC_OBJS, [...]): Update. * Makefile.in (C_AND_OBJC_OBJS, c-incpath.o, c-lex.o, LIBCPP_OBJS, cppinit.o, cppdefault.o, fix-header): Update. * c-incpath.c: New file. * c-incpath.h: New file. * c-lex.c: Include c-incpath.h. (init_c_lex): Register path simplifier. * c-opts.c: Include cppdefault.h and c-incpath.h. (TARGET_SYSTEM_ROOT, verbose, iprefix, sysroot, std_inc, std_cxx_inc, quote_chain_split, add_prefixed_path): New. (COMMAND_LINE_OPTIONS): Add more options from cpplib. (missing_arg, c_common_decode_option): Handle them. (c_common_post_options): Register include chains. (print_help): Update. * cppdefault.h (struct default include): Update. Move some macros to ... * cppdefault.c: ... here. (cpp_include_defaults): Add extra field add_sysroot. * cppfiles.c (include_file, search_from, find_or_create_entry, cpp_included, find_include_file, remap_filename): Update for renaming of search_path to cpp_path, and of the chain headers. (remove_component_p, _cpp_simplify_pathname): Move to c-incpath.c. * cpphash.h (struct search_path): Move to cpplib.h. (struct cpp_buffer, struct cpp_reader): Update. (_cpp_simplify_pathname): Remove. * cppinit.c: Don't include prefix.h and cppdefault.h. (INO_T_EQ, INO_T_COPY, path_include, append_include_chain, remove_dup_dir, remove_dup_nonsys_dirs, remove_dup_dirs, init_standard_includes, BRACKET, SYSTEM, AFTER, no_dir, no_pth, cpp_handle_options): Remove. (struct pending_option): Remove chain members. (cpp_destroy, cpp_read_main_file, COMMAND_LINE_OPTIONS, cpp_handle_option): Update. * cpplib.h (struct cpp_path, cpp_set_include_chains): New. (struct cpp_options): Remove quote_include, bracket_include, include_prefix, include_prefix_len, verbose, ignore_srcdir, no_standard_includes, no_standard_cplusplus_includes. (struct cpp_callbacks): Add simplify_path. (cpp_handle_options): Remove. * fix-header.c: Include c-incpath.h. (read_scan_file): Update to use c-incpath functionality. * doc/passes.texi: Update. cp: * Make-lang.in (CXX_C_OBJS): Update. From-SVN: r63612
2003-03-01 15:31:21 +01:00
struct cpp_path *path;
struct include_file *file;
char *name, *n;
[multiple changes] 1998-10-28 16:10 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * c-lang.c: Declare extern char *yy_cur if USE_CPPLIB. (lang_init): Call check_newline always. * c-lex.c (init_parse) [USE_CPPLIB=1]: After calling cpp_start_read, set yy_cur and yy_lim to read from parse_in.token_buffer, so that we'll see the first #line directive. * cpplib.c (cpp_start_read): finclude the main input file before processing -include/-imacros. Process -imacros and -include separately, and handle -include by stacking a buffer for the file in question as if it'd been #included. * toplev.c (documented_lang_options) Recognize -H when USE_CPPLIB is on. 1998-10-28 16:09 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.c: Merge do_once into do_pragma. Break file handling code out of do_include. Move append_include_chain, deps_output, file_cleanup, redundant_include_p, import_hash, lookup_import, add_import, read_filename_string, read_name_map, open_include_file, finclude, safe_read to cppfiles.c. Move prototypes for deps_output, append_include_chain, finclude to cpplib.h. Move definition of struct file_name_list there also. * cppfiles.c: New file. Contains all the above functions broken out of cpplib.c; also hack_vms_include_specification from cccp.c and find_include_file, a new function broken out of do_include. * Makefile.in (cppmain): Depend on cppfiles.o. (fix-header): Likewise. (cppfiles.o): New target. * configure.in (--enable-c-cpplib): Add cppfiles.o to extra_c_objs. Add ../cppfiles.o to extra_cxx_objs. From-SVN: r23424
1998-10-29 12:54:13 +01:00
if (*fname == '\0')
{
cpp_error (pfile, DL_ERROR, "empty file name");
return NO_INCLUDE_PATH;
}
if (IS_ABSOLUTE_PATH (fname))
return open_file_pch (pfile, fname);
/* For #include_next, skip in the search path past the dir in which
the current file was found, but if it was found via an absolute
path use the normal search logic. */
if (type == IT_INCLUDE_NEXT && pfile->buffer->inc->foundhere)
path = pfile->buffer->inc->foundhere->next;
else if (angle_brackets)
Makefile.in (C_AND_OBJC_OBJS, [...]): Update. * Makefile.in (C_AND_OBJC_OBJS, c-incpath.o, c-lex.o, LIBCPP_OBJS, cppinit.o, cppdefault.o, fix-header): Update. * c-incpath.c: New file. * c-incpath.h: New file. * c-lex.c: Include c-incpath.h. (init_c_lex): Register path simplifier. * c-opts.c: Include cppdefault.h and c-incpath.h. (TARGET_SYSTEM_ROOT, verbose, iprefix, sysroot, std_inc, std_cxx_inc, quote_chain_split, add_prefixed_path): New. (COMMAND_LINE_OPTIONS): Add more options from cpplib. (missing_arg, c_common_decode_option): Handle them. (c_common_post_options): Register include chains. (print_help): Update. * cppdefault.h (struct default include): Update. Move some macros to ... * cppdefault.c: ... here. (cpp_include_defaults): Add extra field add_sysroot. * cppfiles.c (include_file, search_from, find_or_create_entry, cpp_included, find_include_file, remap_filename): Update for renaming of search_path to cpp_path, and of the chain headers. (remove_component_p, _cpp_simplify_pathname): Move to c-incpath.c. * cpphash.h (struct search_path): Move to cpplib.h. (struct cpp_buffer, struct cpp_reader): Update. (_cpp_simplify_pathname): Remove. * cppinit.c: Don't include prefix.h and cppdefault.h. (INO_T_EQ, INO_T_COPY, path_include, append_include_chain, remove_dup_dir, remove_dup_nonsys_dirs, remove_dup_dirs, init_standard_includes, BRACKET, SYSTEM, AFTER, no_dir, no_pth, cpp_handle_options): Remove. (struct pending_option): Remove chain members. (cpp_destroy, cpp_read_main_file, COMMAND_LINE_OPTIONS, cpp_handle_option): Update. * cpplib.h (struct cpp_path, cpp_set_include_chains): New. (struct cpp_options): Remove quote_include, bracket_include, include_prefix, include_prefix_len, verbose, ignore_srcdir, no_standard_includes, no_standard_cplusplus_includes. (struct cpp_callbacks): Add simplify_path. (cpp_handle_options): Remove. * fix-header.c: Include c-incpath.h. (read_scan_file): Update to use c-incpath functionality. * doc/passes.texi: Update. cp: * Make-lang.in (CXX_C_OBJS): Update. From-SVN: r63612
2003-03-01 15:31:21 +01:00
path = pfile->bracket_include;
else
path = search_from (pfile, type);
if (path == NULL)
{
cpperror.c (print_location): Don't print include chain if line == 0. * cpperror.c (print_location): Don't print include chain if line == 0. (cpp_begin_message): Update to use DL_ macros. (cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_notice, cpp_notice_from_errno): Remove. (cpp_error, cpp_error_with_line): Update to take a diagnostic level. (cpp_errno): New. * cppexp.c (CPP_ICE): Remove. (SYNTAX_ERROR, SYNTAX_ERROR2, parse_number, parse_defined, lex, integer_overflow, _cpp_parse_expr): Update. * cppfiles.c (read_include_file, find_include_file, handle_missing_header, _cpp_read_file, remap_filename): Update. * cpphash.h (enum error_type): Remove. (_cpp_begin_message): Update. * cppinit.c (append_include_chain, remove_dup_dirs, output_deps, cpp_handle_option, cpp_post_options): Update. * cpplex.c (trigraph_p, skip_escaped_newlines, skip_block_comment, skip_whitespace, parse_identifier, parse_slow, parse_string, _cpp_lex_direct, cpp_spell_token, maybe_read_ucs, cpp_parse_escape, cpp_interpret_charconst): Update. * cpplib.c (check_eol, directive_diagnostics, _cpp_handle_directive, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, read_flag, do_line, do_linemarker, do_ident, cpp_register_pragma, do_pragma_once, do_pragma_system_header, do_pragma_poison, do_pragma_dependency, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, parse_assertion, do_assert, _cpp_pop_buffer, do_diagnostic): Update. * cpplib.h (DL_WARNING, DL_WARNING_SYSHDR, DL_PEDWARN, DL_ERROR, DL_FATAL, DL_ICE, DL_EXTRACT, DL_WARNING_P): New. (cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_notice, cpp_notice_from_errno): Remove. (cpp_error, cpp_error_with_line): Update to take a diagnostic level. (cpp_errno): New. * cppmacro.c (builtin_macro, stringify_arg, paste_all_tokens, collect_args, enter_macro_context, save_parameter, parse_params, _cpp_create_definition, check_trad_stringification, cpp_macro_definition): Update. * cppmain.c (cpp_preprocess_file): Update. * fix-header.c (read_scan_file): Update. From-SVN: r52302
2002-04-14 20:42:47 +02:00
cpp_error (pfile, DL_ERROR, "no include path in which to find %s",
fname);
return NO_INCLUDE_PATH;
}
/* Search directory path for the file. */
name = alloca (strlen (fname) + pfile->max_include_len + 2);
for (; path; path = path->next)
[multiple changes] 1998-10-28 16:10 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * c-lang.c: Declare extern char *yy_cur if USE_CPPLIB. (lang_init): Call check_newline always. * c-lex.c (init_parse) [USE_CPPLIB=1]: After calling cpp_start_read, set yy_cur and yy_lim to read from parse_in.token_buffer, so that we'll see the first #line directive. * cpplib.c (cpp_start_read): finclude the main input file before processing -include/-imacros. Process -imacros and -include separately, and handle -include by stacking a buffer for the file in question as if it'd been #included. * toplev.c (documented_lang_options) Recognize -H when USE_CPPLIB is on. 1998-10-28 16:09 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.c: Merge do_once into do_pragma. Break file handling code out of do_include. Move append_include_chain, deps_output, file_cleanup, redundant_include_p, import_hash, lookup_import, add_import, read_filename_string, read_name_map, open_include_file, finclude, safe_read to cppfiles.c. Move prototypes for deps_output, append_include_chain, finclude to cpplib.h. Move definition of struct file_name_list there also. * cppfiles.c: New file. Contains all the above functions broken out of cpplib.c; also hack_vms_include_specification from cccp.c and find_include_file, a new function broken out of do_include. * Makefile.in (cppmain): Depend on cppfiles.o. (fix-header): Likewise. (cppfiles.o): New target. * configure.in (--enable-c-cpplib): Add cppfiles.o to extra_c_objs. Add ../cppfiles.o to extra_cxx_objs. From-SVN: r23424
1998-10-29 12:54:13 +01:00
{
int len = path->len;
memcpy (name, path->name, len);
/* Don't turn / into // or // into ///; // may be a namespace
escape. */
if (name[len-1] == '/')
len--;
name[len] = '/';
strcpy (&name[len + 1], fname);
if (CPP_OPTION (pfile, remap))
n = remap_filename (pfile, name, path);
else
n = name;
file = open_file_pch (pfile, n);
if (file)
[multiple changes] 1998-10-28 16:10 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * c-lang.c: Declare extern char *yy_cur if USE_CPPLIB. (lang_init): Call check_newline always. * c-lex.c (init_parse) [USE_CPPLIB=1]: After calling cpp_start_read, set yy_cur and yy_lim to read from parse_in.token_buffer, so that we'll see the first #line directive. * cpplib.c (cpp_start_read): finclude the main input file before processing -include/-imacros. Process -imacros and -include separately, and handle -include by stacking a buffer for the file in question as if it'd been #included. * toplev.c (documented_lang_options) Recognize -H when USE_CPPLIB is on. 1998-10-28 16:09 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.c: Merge do_once into do_pragma. Break file handling code out of do_include. Move append_include_chain, deps_output, file_cleanup, redundant_include_p, import_hash, lookup_import, add_import, read_filename_string, read_name_map, open_include_file, finclude, safe_read to cppfiles.c. Move prototypes for deps_output, append_include_chain, finclude to cpplib.h. Move definition of struct file_name_list there also. * cppfiles.c: New file. Contains all the above functions broken out of cpplib.c; also hack_vms_include_specification from cccp.c and find_include_file, a new function broken out of do_include. * Makefile.in (cppmain): Depend on cppfiles.o. (fix-header): Likewise. (cppfiles.o): New target. * configure.in (--enable-c-cpplib): Add cppfiles.o to extra_c_objs. Add ../cppfiles.o to extra_cxx_objs. From-SVN: r23424
1998-10-29 12:54:13 +01:00
{
file->foundhere = path;
return file;
[multiple changes] 1998-10-28 16:10 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * c-lang.c: Declare extern char *yy_cur if USE_CPPLIB. (lang_init): Call check_newline always. * c-lex.c (init_parse) [USE_CPPLIB=1]: After calling cpp_start_read, set yy_cur and yy_lim to read from parse_in.token_buffer, so that we'll see the first #line directive. * cpplib.c (cpp_start_read): finclude the main input file before processing -include/-imacros. Process -imacros and -include separately, and handle -include by stacking a buffer for the file in question as if it'd been #included. * toplev.c (documented_lang_options) Recognize -H when USE_CPPLIB is on. 1998-10-28 16:09 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.c: Merge do_once into do_pragma. Break file handling code out of do_include. Move append_include_chain, deps_output, file_cleanup, redundant_include_p, import_hash, lookup_import, add_import, read_filename_string, read_name_map, open_include_file, finclude, safe_read to cppfiles.c. Move prototypes for deps_output, append_include_chain, finclude to cpplib.h. Move definition of struct file_name_list there also. * cppfiles.c: New file. Contains all the above functions broken out of cpplib.c; also hack_vms_include_specification from cccp.c and find_include_file, a new function broken out of do_include. * Makefile.in (cppmain): Depend on cppfiles.o. (fix-header): Likewise. (cppfiles.o): New target. * configure.in (--enable-c-cpplib): Add cppfiles.o to extra_c_objs. Add ../cppfiles.o to extra_cxx_objs. From-SVN: r23424
1998-10-29 12:54:13 +01:00
}
}
return 0;
[multiple changes] 1998-10-28 16:10 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * c-lang.c: Declare extern char *yy_cur if USE_CPPLIB. (lang_init): Call check_newline always. * c-lex.c (init_parse) [USE_CPPLIB=1]: After calling cpp_start_read, set yy_cur and yy_lim to read from parse_in.token_buffer, so that we'll see the first #line directive. * cpplib.c (cpp_start_read): finclude the main input file before processing -include/-imacros. Process -imacros and -include separately, and handle -include by stacking a buffer for the file in question as if it'd been #included. * toplev.c (documented_lang_options) Recognize -H when USE_CPPLIB is on. 1998-10-28 16:09 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.c: Merge do_once into do_pragma. Break file handling code out of do_include. Move append_include_chain, deps_output, file_cleanup, redundant_include_p, import_hash, lookup_import, add_import, read_filename_string, read_name_map, open_include_file, finclude, safe_read to cppfiles.c. Move prototypes for deps_output, append_include_chain, finclude to cpplib.h. Move definition of struct file_name_list there also. * cppfiles.c: New file. Contains all the above functions broken out of cpplib.c; also hack_vms_include_specification from cccp.c and find_include_file, a new function broken out of do_include. * Makefile.in (cppmain): Depend on cppfiles.o. (fix-header): Likewise. (cppfiles.o): New target. * configure.in (--enable-c-cpplib): Add cppfiles.o to extra_c_objs. Add ../cppfiles.o to extra_cxx_objs. From-SVN: r23424
1998-10-29 12:54:13 +01:00
}
/* Not everyone who wants to set system-header-ness on a buffer can
see the details of a buffer. This is an exported interface because
fix-header needs it. */
void
cpp_make_system_header (cpp_reader *pfile, int syshdr, int externc)
{
int flags = 0;
/* 1 = system header, 2 = system header to be treated as C. */
if (syshdr)
flags = 1 + (externc != 0);
c-lex.c (map): Make const. * c-lex.c (map): Make const. (cb_file_change): Update for callback passing a line map. Don't assume we have a previous map. Remove sanity check about popping too many files. * cpperror.c (print_location): Make map const. * cppfiles.c (stack_include_file): Update; line maps now hold sysp. (cpp_make_system_header): Similarly. (search_from): Similarly. (_cpp_execute_include): Don't remember where we came from. * cpphash.h (struct cpp_buffer): Remove return_to_line, sysp. (struct cpp_reader): Make map const. (CPP_IN_SYSTEM_HEADER, _cpp_do_file_change): Update. * cpplib.c (do_line): Update; line maps now hold sysp. (cpp_push_buffer): Similarly. (_cpp_do_file_change): Similarly; callback with map instead. (cpp_get_line_maps): Constify return value. (_cpp_pop_buffer): Update. * cpplib.h (struct cpp_file_change): Remove. (struct cpp_callbacks): Update. (cpp_get_line_maps): Constify return value. * cppmacro.c (_cpp_create_definition): Update. * cppmain.c (struct printer): Constify map. (maybe_print_line): Similarly. (print_line): Similarly. Deduce flags 1 and 2 here. (cb_file_change): Update. * line-map.c (free_line_maps): Warn regardless. (add_line_map): Return pointer to const. When passed NULL to_file with LC_LEAVE, use the obvious values for the return point so the caller doesn't have to figure them out. (lookup_line): Return pointer to const. (print_containing_files): Take pointer to const. * line-map.h (struct line_map): New members reason, sysp. (add_line_map): Return pointer to const. (lookup_line): Similarly. (print_containing_files): Take pointer to const. From-SVN: r44789
2001-08-11 09:33:39 +02:00
_cpp_do_file_change (pfile, LC_RENAME, pfile->map->to_file,
SOURCE_LINE (pfile->map, pfile->line), flags);
}
/* Allow the client to change the current file. Used by the front end
to achieve pseudo-file names like <built-in>.
If REASON is LC_LEAVE, then NEW_NAME must be NULL. */
void
cpp_change_file (cpp_reader *pfile, enum lc_reason reason,
const char *new_name)
{
_cpp_do_file_change (pfile, reason, new_name, 1, 0);
}
cpplex.c: Don't include sys/mman.h. toplevel: * cpplex.c: Don't include sys/mman.h. (cpp_push_buffer, cpp_pop_buffer): Moved to cpplib.c. * cpplib.c: Include sys/mman.h and obstack.h. (cpp_push_buffer): Moved from cpplex.c; allocate buffers on an obstack. (cpp_pop_buffer): Moved from cpplex.c; free buffers from an obstack. (_cpp_unwind_if_stack): Now static, unwind_if_stack. Don't bother freeing if stack entries (they will be freed with their buffer). (do_endif): Free if stack entries from the buffer obstack. (push_conditional): Allocate if stack entries from the buffer obstack. (find_answer): Rename to _cpp_find_answer. (do_assert, do_unassert): Update. * cpphash.h: Update prototypes. (xobnew): New convenience macro. * cpplib.h (struct cpp_reader): Add hash_ob and buffer_ob fields. Update comments. (struct cpp_hashnode): Remove disabled field. * cppinit.c: Don't include hashtab.h or splay-tree.h. (report_missing_guard): Moved to cppfiles.c. (cpp_reader_init): Call cpp_init_stacks, cpp_init_macros, cpp_init_includes. (cpp_cleanup): Call cpp_cleanup_stacks, cpp_cleanup_macros, cpp_cleanup_includes. Don't destroy hashtab or all_include_files here. (cpp_finish): Use _cpp_report_missing_guards. * cppfiles.c (report_missing_guard): Moved from cppinit.c. (_cpp_init_include_table): Rename _cpp_init_includes. (_cpp_cleanup_includes, _cpp_report_missing_guards): New. * cppexp.c (parse_assertion): Update for new name of find_answer. * Makefile.in (cpplib.o, cpphash.o, cppinit.o): Update deps. * cpplib.c (do_ident): s/VSPACE/EOF/ testsuite: * gcc.dg/cpp/ident.c: New test. From-SVN: r34870
2000-07-05 07:33:57 +02:00
/* Report on all files that might benefit from a multiple include guard.
Triggered by -H. */
void
_cpp_report_missing_guards (cpp_reader *pfile)
cpplex.c: Don't include sys/mman.h. toplevel: * cpplex.c: Don't include sys/mman.h. (cpp_push_buffer, cpp_pop_buffer): Moved to cpplib.c. * cpplib.c: Include sys/mman.h and obstack.h. (cpp_push_buffer): Moved from cpplex.c; allocate buffers on an obstack. (cpp_pop_buffer): Moved from cpplex.c; free buffers from an obstack. (_cpp_unwind_if_stack): Now static, unwind_if_stack. Don't bother freeing if stack entries (they will be freed with their buffer). (do_endif): Free if stack entries from the buffer obstack. (push_conditional): Allocate if stack entries from the buffer obstack. (find_answer): Rename to _cpp_find_answer. (do_assert, do_unassert): Update. * cpphash.h: Update prototypes. (xobnew): New convenience macro. * cpplib.h (struct cpp_reader): Add hash_ob and buffer_ob fields. Update comments. (struct cpp_hashnode): Remove disabled field. * cppinit.c: Don't include hashtab.h or splay-tree.h. (report_missing_guard): Moved to cppfiles.c. (cpp_reader_init): Call cpp_init_stacks, cpp_init_macros, cpp_init_includes. (cpp_cleanup): Call cpp_cleanup_stacks, cpp_cleanup_macros, cpp_cleanup_includes. Don't destroy hashtab or all_include_files here. (cpp_finish): Use _cpp_report_missing_guards. * cppfiles.c (report_missing_guard): Moved from cppinit.c. (_cpp_init_include_table): Rename _cpp_init_includes. (_cpp_cleanup_includes, _cpp_report_missing_guards): New. * cppexp.c (parse_assertion): Update for new name of find_answer. * Makefile.in (cpplib.o, cpphash.o, cppinit.o): Update deps. * cpplib.c (do_ident): s/VSPACE/EOF/ testsuite: * gcc.dg/cpp/ident.c: New test. From-SVN: r34870
2000-07-05 07:33:57 +02:00
{
int banner = 0;
splay_tree_foreach (pfile->all_include_files, report_missing_guard, &banner);
cpplex.c: Don't include sys/mman.h. toplevel: * cpplex.c: Don't include sys/mman.h. (cpp_push_buffer, cpp_pop_buffer): Moved to cpplib.c. * cpplib.c: Include sys/mman.h and obstack.h. (cpp_push_buffer): Moved from cpplex.c; allocate buffers on an obstack. (cpp_pop_buffer): Moved from cpplex.c; free buffers from an obstack. (_cpp_unwind_if_stack): Now static, unwind_if_stack. Don't bother freeing if stack entries (they will be freed with their buffer). (do_endif): Free if stack entries from the buffer obstack. (push_conditional): Allocate if stack entries from the buffer obstack. (find_answer): Rename to _cpp_find_answer. (do_assert, do_unassert): Update. * cpphash.h: Update prototypes. (xobnew): New convenience macro. * cpplib.h (struct cpp_reader): Add hash_ob and buffer_ob fields. Update comments. (struct cpp_hashnode): Remove disabled field. * cppinit.c: Don't include hashtab.h or splay-tree.h. (report_missing_guard): Moved to cppfiles.c. (cpp_reader_init): Call cpp_init_stacks, cpp_init_macros, cpp_init_includes. (cpp_cleanup): Call cpp_cleanup_stacks, cpp_cleanup_macros, cpp_cleanup_includes. Don't destroy hashtab or all_include_files here. (cpp_finish): Use _cpp_report_missing_guards. * cppfiles.c (report_missing_guard): Moved from cppinit.c. (_cpp_init_include_table): Rename _cpp_init_includes. (_cpp_cleanup_includes, _cpp_report_missing_guards): New. * cppexp.c (parse_assertion): Update for new name of find_answer. * Makefile.in (cpplib.o, cpphash.o, cppinit.o): Update deps. * cpplib.c (do_ident): s/VSPACE/EOF/ testsuite: * gcc.dg/cpp/ident.c: New test. From-SVN: r34870
2000-07-05 07:33:57 +02:00
}
/* Callback function for splay_tree_foreach(). */
cpplex.c: Don't include sys/mman.h. toplevel: * cpplex.c: Don't include sys/mman.h. (cpp_push_buffer, cpp_pop_buffer): Moved to cpplib.c. * cpplib.c: Include sys/mman.h and obstack.h. (cpp_push_buffer): Moved from cpplex.c; allocate buffers on an obstack. (cpp_pop_buffer): Moved from cpplex.c; free buffers from an obstack. (_cpp_unwind_if_stack): Now static, unwind_if_stack. Don't bother freeing if stack entries (they will be freed with their buffer). (do_endif): Free if stack entries from the buffer obstack. (push_conditional): Allocate if stack entries from the buffer obstack. (find_answer): Rename to _cpp_find_answer. (do_assert, do_unassert): Update. * cpphash.h: Update prototypes. (xobnew): New convenience macro. * cpplib.h (struct cpp_reader): Add hash_ob and buffer_ob fields. Update comments. (struct cpp_hashnode): Remove disabled field. * cppinit.c: Don't include hashtab.h or splay-tree.h. (report_missing_guard): Moved to cppfiles.c. (cpp_reader_init): Call cpp_init_stacks, cpp_init_macros, cpp_init_includes. (cpp_cleanup): Call cpp_cleanup_stacks, cpp_cleanup_macros, cpp_cleanup_includes. Don't destroy hashtab or all_include_files here. (cpp_finish): Use _cpp_report_missing_guards. * cppfiles.c (report_missing_guard): Moved from cppinit.c. (_cpp_init_include_table): Rename _cpp_init_includes. (_cpp_cleanup_includes, _cpp_report_missing_guards): New. * cppexp.c (parse_assertion): Update for new name of find_answer. * Makefile.in (cpplib.o, cpphash.o, cppinit.o): Update deps. * cpplib.c (do_ident): s/VSPACE/EOF/ testsuite: * gcc.dg/cpp/ident.c: New test. From-SVN: r34870
2000-07-05 07:33:57 +02:00
static int
report_missing_guard (splay_tree_node n, void *b)
cpplex.c: Don't include sys/mman.h. toplevel: * cpplex.c: Don't include sys/mman.h. (cpp_push_buffer, cpp_pop_buffer): Moved to cpplib.c. * cpplib.c: Include sys/mman.h and obstack.h. (cpp_push_buffer): Moved from cpplex.c; allocate buffers on an obstack. (cpp_pop_buffer): Moved from cpplex.c; free buffers from an obstack. (_cpp_unwind_if_stack): Now static, unwind_if_stack. Don't bother freeing if stack entries (they will be freed with their buffer). (do_endif): Free if stack entries from the buffer obstack. (push_conditional): Allocate if stack entries from the buffer obstack. (find_answer): Rename to _cpp_find_answer. (do_assert, do_unassert): Update. * cpphash.h: Update prototypes. (xobnew): New convenience macro. * cpplib.h (struct cpp_reader): Add hash_ob and buffer_ob fields. Update comments. (struct cpp_hashnode): Remove disabled field. * cppinit.c: Don't include hashtab.h or splay-tree.h. (report_missing_guard): Moved to cppfiles.c. (cpp_reader_init): Call cpp_init_stacks, cpp_init_macros, cpp_init_includes. (cpp_cleanup): Call cpp_cleanup_stacks, cpp_cleanup_macros, cpp_cleanup_includes. Don't destroy hashtab or all_include_files here. (cpp_finish): Use _cpp_report_missing_guards. * cppfiles.c (report_missing_guard): Moved from cppinit.c. (_cpp_init_include_table): Rename _cpp_init_includes. (_cpp_cleanup_includes, _cpp_report_missing_guards): New. * cppexp.c (parse_assertion): Update for new name of find_answer. * Makefile.in (cpplib.o, cpphash.o, cppinit.o): Update deps. * cpplib.c (do_ident): s/VSPACE/EOF/ testsuite: * gcc.dg/cpp/ident.c: New test. From-SVN: r34870
2000-07-05 07:33:57 +02:00
{
struct include_file *f = (struct include_file *) n->value;
int *bannerp = (int *) b;
cpplex.c: Don't include sys/mman.h. toplevel: * cpplex.c: Don't include sys/mman.h. (cpp_push_buffer, cpp_pop_buffer): Moved to cpplib.c. * cpplib.c: Include sys/mman.h and obstack.h. (cpp_push_buffer): Moved from cpplex.c; allocate buffers on an obstack. (cpp_pop_buffer): Moved from cpplex.c; free buffers from an obstack. (_cpp_unwind_if_stack): Now static, unwind_if_stack. Don't bother freeing if stack entries (they will be freed with their buffer). (do_endif): Free if stack entries from the buffer obstack. (push_conditional): Allocate if stack entries from the buffer obstack. (find_answer): Rename to _cpp_find_answer. (do_assert, do_unassert): Update. * cpphash.h: Update prototypes. (xobnew): New convenience macro. * cpplib.h (struct cpp_reader): Add hash_ob and buffer_ob fields. Update comments. (struct cpp_hashnode): Remove disabled field. * cppinit.c: Don't include hashtab.h or splay-tree.h. (report_missing_guard): Moved to cppfiles.c. (cpp_reader_init): Call cpp_init_stacks, cpp_init_macros, cpp_init_includes. (cpp_cleanup): Call cpp_cleanup_stacks, cpp_cleanup_macros, cpp_cleanup_includes. Don't destroy hashtab or all_include_files here. (cpp_finish): Use _cpp_report_missing_guards. * cppfiles.c (report_missing_guard): Moved from cppinit.c. (_cpp_init_include_table): Rename _cpp_init_includes. (_cpp_cleanup_includes, _cpp_report_missing_guards): New. * cppexp.c (parse_assertion): Update for new name of find_answer. * Makefile.in (cpplib.o, cpphash.o, cppinit.o): Update deps. * cpplib.c (do_ident): s/VSPACE/EOF/ testsuite: * gcc.dg/cpp/ident.c: New test. From-SVN: r34870
2000-07-05 07:33:57 +02:00
if (f && f->cmacro == 0 && f->include_count == 1)
{
if (*bannerp == 0)
{
fputs (_("Multiple include guards may be useful for:\n"), stderr);
*bannerp = 1;
}
fputs (f->name, stderr);
putc ('\n', stderr);
}
return 0;
}
/* Create a dependency for file FNAME, or issue an error message as
appropriate. ANGLE_BRACKETS is nonzero if the file was bracketed
like <..>. */
static void
handle_missing_header (cpp_reader *pfile, const char *fname,
int angle_brackets)
{
bool print_dep
= CPP_OPTION (pfile, deps.style) > (angle_brackets || pfile->map->sysp);
if (CPP_OPTION (pfile, deps.missing_files) && print_dep)
deps_add_dep (pfile->deps, fname);
/* If -M was specified, then don't count this as an error, because
we can still produce correct output. Otherwise, we can't produce
correct output, because there may be dependencies we need inside
the missing file, and we don't know what directory this missing
cpperror.c (print_location): Don't print include chain if line == 0. * cpperror.c (print_location): Don't print include chain if line == 0. (cpp_begin_message): Update to use DL_ macros. (cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_notice, cpp_notice_from_errno): Remove. (cpp_error, cpp_error_with_line): Update to take a diagnostic level. (cpp_errno): New. * cppexp.c (CPP_ICE): Remove. (SYNTAX_ERROR, SYNTAX_ERROR2, parse_number, parse_defined, lex, integer_overflow, _cpp_parse_expr): Update. * cppfiles.c (read_include_file, find_include_file, handle_missing_header, _cpp_read_file, remap_filename): Update. * cpphash.h (enum error_type): Remove. (_cpp_begin_message): Update. * cppinit.c (append_include_chain, remove_dup_dirs, output_deps, cpp_handle_option, cpp_post_options): Update. * cpplex.c (trigraph_p, skip_escaped_newlines, skip_block_comment, skip_whitespace, parse_identifier, parse_slow, parse_string, _cpp_lex_direct, cpp_spell_token, maybe_read_ucs, cpp_parse_escape, cpp_interpret_charconst): Update. * cpplib.c (check_eol, directive_diagnostics, _cpp_handle_directive, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, read_flag, do_line, do_linemarker, do_ident, cpp_register_pragma, do_pragma_once, do_pragma_system_header, do_pragma_poison, do_pragma_dependency, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, parse_assertion, do_assert, _cpp_pop_buffer, do_diagnostic): Update. * cpplib.h (DL_WARNING, DL_WARNING_SYSHDR, DL_PEDWARN, DL_ERROR, DL_FATAL, DL_ICE, DL_EXTRACT, DL_WARNING_P): New. (cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_notice, cpp_notice_from_errno): Remove. (cpp_error, cpp_error_with_line): Update to take a diagnostic level. (cpp_errno): New. * cppmacro.c (builtin_macro, stringify_arg, paste_all_tokens, collect_args, enter_macro_context, save_parameter, parse_params, _cpp_create_definition, check_trad_stringification, cpp_macro_definition): Update. * cppmain.c (cpp_preprocess_file): Update. * fix-header.c (read_scan_file): Update. From-SVN: r52302
2002-04-14 20:42:47 +02:00
file exists in. */
else
cpp_errno (pfile, CPP_OPTION (pfile, deps.style) && ! print_dep
cpperror.c (print_location): Don't print include chain if line == 0. * cpperror.c (print_location): Don't print include chain if line == 0. (cpp_begin_message): Update to use DL_ macros. (cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_notice, cpp_notice_from_errno): Remove. (cpp_error, cpp_error_with_line): Update to take a diagnostic level. (cpp_errno): New. * cppexp.c (CPP_ICE): Remove. (SYNTAX_ERROR, SYNTAX_ERROR2, parse_number, parse_defined, lex, integer_overflow, _cpp_parse_expr): Update. * cppfiles.c (read_include_file, find_include_file, handle_missing_header, _cpp_read_file, remap_filename): Update. * cpphash.h (enum error_type): Remove. (_cpp_begin_message): Update. * cppinit.c (append_include_chain, remove_dup_dirs, output_deps, cpp_handle_option, cpp_post_options): Update. * cpplex.c (trigraph_p, skip_escaped_newlines, skip_block_comment, skip_whitespace, parse_identifier, parse_slow, parse_string, _cpp_lex_direct, cpp_spell_token, maybe_read_ucs, cpp_parse_escape, cpp_interpret_charconst): Update. * cpplib.c (check_eol, directive_diagnostics, _cpp_handle_directive, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, read_flag, do_line, do_linemarker, do_ident, cpp_register_pragma, do_pragma_once, do_pragma_system_header, do_pragma_poison, do_pragma_dependency, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, parse_assertion, do_assert, _cpp_pop_buffer, do_diagnostic): Update. * cpplib.h (DL_WARNING, DL_WARNING_SYSHDR, DL_PEDWARN, DL_ERROR, DL_FATAL, DL_ICE, DL_EXTRACT, DL_WARNING_P): New. (cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_notice, cpp_notice_from_errno): Remove. (cpp_error, cpp_error_with_line): Update to take a diagnostic level. (cpp_errno): New. * cppmacro.c (builtin_macro, stringify_arg, paste_all_tokens, collect_args, enter_macro_context, save_parameter, parse_params, _cpp_create_definition, check_trad_stringification, cpp_macro_definition): Update. * cppmain.c (cpp_preprocess_file): Update. * fix-header.c (read_scan_file): Update. From-SVN: r52302
2002-04-14 20:42:47 +02:00
? DL_WARNING: DL_ERROR, fname);
}
/* Handles #include-family directives (distinguished by TYPE),
including HEADER, and the command line -imacros and -include.
Returns true if a buffer was stacked. */
bool
_cpp_execute_include (cpp_reader *pfile, const char *fname, int angle_brackets,
enum include_type type)
cppfiles.c: Include mkdeps.h. * cppfiles.c: Include mkdeps.h. (find_include_file, read_include_file): Remove _cpp_ prefix from name, make static. (_cpp_execute_include): New function, broken out of do_include. * cpplib.c: Don't include mkdeps.h. (struct directive): Remove type field. Reorder entries. The function takes only one argument. (struct if_stack): Make type field an int. (directive_table): Rename to dtable. Generate it, the prototypes of the directive handlers, and the enum for the directive numbers, from a template macro. (do_ifndef, do_include_next, do_import): New functions. (do_define, do_include, do_endif, do_ifdef, do_if, do_else, do_undef, do_line, do_elif, do_error, do_pragma, do_warning, do_ident, do_assert, do_unassert, do_sccs): Take only one argument. (do_sccs): Define always, but alter behavior based on SCCS_DIRECTIVE. (_cpp_handle_directive, consider_directive_while_skipping): Restructure for new directive table layout. (pass_thru_directive): Take a directive number, not a pointer to a struct directive. (parse_include): New function, broken out of do_include. (do_include, do_import, do_include_next): Use parse_include and _cpp_execute_include. (do_elif, do_else): Test for T_ELSE specifically when checking for #elif/#else after #else. (parse_ifdef): New function, broken out of do_ifdef. (validate_else): Expect a name arg without a leading #. (if_directive_name): Delete. (cpp_define, cpp_assert, cpp_undef, cpp_unassert): Call directive handlers with only one argument. * cpphash.h: Update prototypes. (enum node_type): Remove entries for directives. * Makefile.in: Update dependencies. From-SVN: r32519
2000-03-14 07:34:11 +01:00
{
bool stacked = false;
struct include_file *inc;
inc = find_include_file (pfile, fname, angle_brackets, type);
if (inc == 0)
handle_missing_header (pfile, fname, angle_brackets);
else if (inc != NO_INCLUDE_PATH)
cppfiles.c: Include mkdeps.h. * cppfiles.c: Include mkdeps.h. (find_include_file, read_include_file): Remove _cpp_ prefix from name, make static. (_cpp_execute_include): New function, broken out of do_include. * cpplib.c: Don't include mkdeps.h. (struct directive): Remove type field. Reorder entries. The function takes only one argument. (struct if_stack): Make type field an int. (directive_table): Rename to dtable. Generate it, the prototypes of the directive handlers, and the enum for the directive numbers, from a template macro. (do_ifndef, do_include_next, do_import): New functions. (do_define, do_include, do_endif, do_ifdef, do_if, do_else, do_undef, do_line, do_elif, do_error, do_pragma, do_warning, do_ident, do_assert, do_unassert, do_sccs): Take only one argument. (do_sccs): Define always, but alter behavior based on SCCS_DIRECTIVE. (_cpp_handle_directive, consider_directive_while_skipping): Restructure for new directive table layout. (pass_thru_directive): Take a directive number, not a pointer to a struct directive. (parse_include): New function, broken out of do_include. (do_include, do_import, do_include_next): Use parse_include and _cpp_execute_include. (do_elif, do_else): Test for T_ELSE specifically when checking for #elif/#else after #else. (parse_ifdef): New function, broken out of do_ifdef. (validate_else): Expect a name arg without a leading #. (if_directive_name): Delete. (cpp_define, cpp_assert, cpp_undef, cpp_unassert): Call directive handlers with only one argument. * cpphash.h: Update prototypes. (enum node_type): Remove entries for directives. * Makefile.in: Update dependencies. From-SVN: r32519
2000-03-14 07:34:11 +01:00
{
stacked = stack_include_file (pfile, inc);
if (type == IT_IMPORT)
_cpp_never_reread (inc);
cppfiles.c: Include mkdeps.h. * cppfiles.c: Include mkdeps.h. (find_include_file, read_include_file): Remove _cpp_ prefix from name, make static. (_cpp_execute_include): New function, broken out of do_include. * cpplib.c: Don't include mkdeps.h. (struct directive): Remove type field. Reorder entries. The function takes only one argument. (struct if_stack): Make type field an int. (directive_table): Rename to dtable. Generate it, the prototypes of the directive handlers, and the enum for the directive numbers, from a template macro. (do_ifndef, do_include_next, do_import): New functions. (do_define, do_include, do_endif, do_ifdef, do_if, do_else, do_undef, do_line, do_elif, do_error, do_pragma, do_warning, do_ident, do_assert, do_unassert, do_sccs): Take only one argument. (do_sccs): Define always, but alter behavior based on SCCS_DIRECTIVE. (_cpp_handle_directive, consider_directive_while_skipping): Restructure for new directive table layout. (pass_thru_directive): Take a directive number, not a pointer to a struct directive. (parse_include): New function, broken out of do_include. (do_include, do_import, do_include_next): Use parse_include and _cpp_execute_include. (do_elif, do_else): Test for T_ELSE specifically when checking for #elif/#else after #else. (parse_ifdef): New function, broken out of do_ifdef. (validate_else): Expect a name arg without a leading #. (if_directive_name): Delete. (cpp_define, cpp_assert, cpp_undef, cpp_unassert): Call directive handlers with only one argument. * cpphash.h: Update prototypes. (enum node_type): Remove entries for directives. * Makefile.in: Update dependencies. From-SVN: r32519
2000-03-14 07:34:11 +01:00
}
return stacked;
cppfiles.c: Include mkdeps.h. * cppfiles.c: Include mkdeps.h. (find_include_file, read_include_file): Remove _cpp_ prefix from name, make static. (_cpp_execute_include): New function, broken out of do_include. * cpplib.c: Don't include mkdeps.h. (struct directive): Remove type field. Reorder entries. The function takes only one argument. (struct if_stack): Make type field an int. (directive_table): Rename to dtable. Generate it, the prototypes of the directive handlers, and the enum for the directive numbers, from a template macro. (do_ifndef, do_include_next, do_import): New functions. (do_define, do_include, do_endif, do_ifdef, do_if, do_else, do_undef, do_line, do_elif, do_error, do_pragma, do_warning, do_ident, do_assert, do_unassert, do_sccs): Take only one argument. (do_sccs): Define always, but alter behavior based on SCCS_DIRECTIVE. (_cpp_handle_directive, consider_directive_while_skipping): Restructure for new directive table layout. (pass_thru_directive): Take a directive number, not a pointer to a struct directive. (parse_include): New function, broken out of do_include. (do_include, do_import, do_include_next): Use parse_include and _cpp_execute_include. (do_elif, do_else): Test for T_ELSE specifically when checking for #elif/#else after #else. (parse_ifdef): New function, broken out of do_ifdef. (validate_else): Expect a name arg without a leading #. (if_directive_name): Delete. (cpp_define, cpp_assert, cpp_undef, cpp_unassert): Call directive handlers with only one argument. * cpphash.h: Update prototypes. (enum node_type): Remove entries for directives. * Makefile.in: Update dependencies. From-SVN: r32519
2000-03-14 07:34:11 +01:00
}
/* Locate HEADER, and determine whether it is newer than the current
file. If it cannot be located or dated, return -1, if it is
newer, return 1, otherwise 0. */
int
_cpp_compare_file_date (cpp_reader *pfile, const char *fname,
int angle_brackets)
{
struct include_file *inc;
inc = find_include_file (pfile, fname, angle_brackets, IT_INCLUDE);
if (inc == NULL || inc == NO_INCLUDE_PATH)
return -1;
if (inc->fd > 0)
{
close (inc->fd);
inc->fd = -1;
}
return inc->st.st_mtime > pfile->buffer->inc->st.st_mtime;
}
/* Push an input buffer and load it up with the contents of FNAME. If
FNAME is "", read standard input. Return true if a buffer was
stacked. */
bool
_cpp_read_file (cpp_reader *pfile, const char *fname)
{
/* This uses open_file, because we don't allow a PCH to be used as
the toplevel compilation (that would prevent re-compiling an
existing PCH without deleting it first). */
struct include_file *f = open_file (pfile, fname);
top level: 2000-07-03 Zack Weinberg <zack@wolery.cumb.org> * fix-header.c (struct partial_proto): Remove unnecessary fields. (recognized_extern, recognized_function, read_scan_file): Update for new scheme. (check_protection): It's still a multiple include guard even if it doesn't always trigger. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new scheme. * scan.h: Declare struct cpp_token. Update prototypes. 2000-07-03 Neil Booth <neilb@earthling.net> Zack Weinberg <zack@wolery.cumb.org> Complete overhaul of the lexer and macro expander. * cpphash.c (object_defn, funct_defn, push_macro_expansion, arg, arglist, argdata, reflist, collect_objlike_expansion, collect_funlike_expansion, collect_params, warn_trad_stringify, trad_stringify, duplicate_arg_p, add_pat, unsafe_chars, macarg, compare_defs, special_symbol, scan_arguments, stringify, funlike_macroexpand, _cpp_quote_string, monthnames): Delete. (cpp_lookup, _cpp_free_definition, dump_funlike_macro, _cpp_create_definition, _cpp_dump_definition, dump_hash_helper): Adjust. (find_param, count_params, parse_define, var_args_str, check_macro_redefinition, save_expansion): New. * cpplex.c (skip_block_comment, skip_line_comment, parse_name, parse_string, output_line_command, trigraph_replace, lex_line, cpp_push_buffer, cpp_pop_buffer, cpp_output_tokens, cpp_scan_buffer_nooutput, cpp_scan_buffer, cpp_free_toklist, cpp_idcmp, _cpp_get_directive_token, _cpp_init_input_buffer, _cpp_skip_rest_of_line): Modify. (maybe_macroexpand, skip_comment, copy_comment, skip_string, find_position, null_warning, bump_column, expand_name_space, pedantic_whitespace, _cpp_output_list, _cpp_slice_toklist, _cpp_squeeze_toklist, _cpp_scan_until, _cpp_skip_hspace, _cpp_parse_name, _cpp_lex_token, cpp_get_non_space_token, _cpp_prescan): Delete. (dump_param_spelling, process_directive, lex_next, is_macro_disabled, stringify_arg, expand_context_stack, output_token, make_string_token, alloc_number_token, special_symbol, duplicate_token, maybe_paste_with_next, can_paste, prevent_macro_expansion, restore_macro_expansion, get_temp_token, release_temp_tokens, quote_string, token_names, token_spellings, _cpp_expand_name_space, _cpp_glue_header_name, _cpp_reserve_name_space, digraph_spellings, trigraph_ok, skip_whitespace, save_comment, placemarker_token, eof_token, cpp_context, macro_args, get_raw_token, parse_arg, parse_args, save_token, push_arg_context, push_macro_context, pop_context, do_pop_context, free_macro_args, _cpp_get_line, _cpp_run_directive): New. * cpplib.c (validate_else, parse_include, push_conditional, pass_thru_directive, read_line_number, parse_ifdef, detect_if_not_defined, _cpp_check_directive, do_define, do_undef, do_include, do_import, do_include_next, do_error, do_warning, do_ident, do_pragma, pragma_dispatch, gcc_pragmas, top_pragmas, do_pragma_gcc, do_pragma_implementation, do_pragma_poison, do_pragma_system_header, do_pragma_dependency, do_sccs, do_ifdef, do_ifndef, do_else, dl_elif, do_endif, _cpp_unwind_if_stack, do_assert, do_unassert, cpp_define, cpp_undef, cpp_assert, cpp_unassert, cpp_defined): Update for new scheme. (strtoul_for_line, get_define_node, dump_macro_name, _cpp_check_linemarker, _cpp_parse_assertion): New. (_cpp_handle_directive, do_pragma_default): Delete. * cpphash.h (struct predicate): Now struct answer. (enum spell_type, struct token_spelling, struct directive, directive_handler): New. Update prototypes. Remove unused macros. * cpplib.h: Update prototypes. Remove unused macros, structure definitions, and fields. * cpperror.c (print_containing_files, v_message): Adjust. * cppexp.c (parse_assertion, lex, parse_escape, _cpp_parse_expr): Adjust. * cppfiles.c (open_include_file, _cpp_execute_include, _cpp_compare_file_date, cpp_read_file, read_include_file): Adjust. * cppinit.c (dump_special_to_buffer): Delete. (append_include_chain, merge_include_chains, cpp_reader_init, cpp_cleanup, initialize_builtins, builtin_array, cpp_start_read, cpp_finish, handle_option, print_help): Adjust. * cppmain.c (main): Adjust. testsuite: 2000-07-03 Zack Weinberg <zack@wolery.cumb.org> * testsuite/gcc.dg/cpp/19951025-1.c: Adjust regexps. * testsuite/gcc.dg/cpp/19990703-1.c: Likewise. * testsuite/gcc.dg/cpp/20000625-1.c: Likewise. * testsuite/gcc.dg/cpp/20000625-2.c: Likewise. * testsuite/gcc.dg/cpp/macro1.c, testsuite/gcc.dg/cpp/paste1.c, testsuite/gcc.dg/cpp/paste2.c, testsuite/gcc.dg/cpp/paste3.c, testsuite/gcc.dg/cpp/paste4.c, testsuite/gcc.dg/cpp/strify1.c, testsuite/gcc.dg/cpp/strify2.c: New tests. From-SVN: r34859
2000-07-04 03:58:21 +02:00
if (f == NULL)
{
cpperror.c (print_location): Don't print include chain if line == 0. * cpperror.c (print_location): Don't print include chain if line == 0. (cpp_begin_message): Update to use DL_ macros. (cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_notice, cpp_notice_from_errno): Remove. (cpp_error, cpp_error_with_line): Update to take a diagnostic level. (cpp_errno): New. * cppexp.c (CPP_ICE): Remove. (SYNTAX_ERROR, SYNTAX_ERROR2, parse_number, parse_defined, lex, integer_overflow, _cpp_parse_expr): Update. * cppfiles.c (read_include_file, find_include_file, handle_missing_header, _cpp_read_file, remap_filename): Update. * cpphash.h (enum error_type): Remove. (_cpp_begin_message): Update. * cppinit.c (append_include_chain, remove_dup_dirs, output_deps, cpp_handle_option, cpp_post_options): Update. * cpplex.c (trigraph_p, skip_escaped_newlines, skip_block_comment, skip_whitespace, parse_identifier, parse_slow, parse_string, _cpp_lex_direct, cpp_spell_token, maybe_read_ucs, cpp_parse_escape, cpp_interpret_charconst): Update. * cpplib.c (check_eol, directive_diagnostics, _cpp_handle_directive, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, read_flag, do_line, do_linemarker, do_ident, cpp_register_pragma, do_pragma_once, do_pragma_system_header, do_pragma_poison, do_pragma_dependency, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, parse_assertion, do_assert, _cpp_pop_buffer, do_diagnostic): Update. * cpplib.h (DL_WARNING, DL_WARNING_SYSHDR, DL_PEDWARN, DL_ERROR, DL_FATAL, DL_ICE, DL_EXTRACT, DL_WARNING_P): New. (cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_notice, cpp_notice_from_errno): Remove. (cpp_error, cpp_error_with_line): Update to take a diagnostic level. (cpp_errno): New. * cppmacro.c (builtin_macro, stringify_arg, paste_all_tokens, collect_args, enter_macro_context, save_parameter, parse_params, _cpp_create_definition, check_trad_stringification, cpp_macro_definition): Update. * cppmain.c (cpp_preprocess_file): Update. * fix-header.c (read_scan_file): Update. From-SVN: r52302
2002-04-14 20:42:47 +02:00
cpp_errno (pfile, DL_ERROR, fname);
return false;
}
top level: 2000-07-03 Zack Weinberg <zack@wolery.cumb.org> * fix-header.c (struct partial_proto): Remove unnecessary fields. (recognized_extern, recognized_function, read_scan_file): Update for new scheme. (check_protection): It's still a multiple include guard even if it doesn't always trigger. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new scheme. * scan.h: Declare struct cpp_token. Update prototypes. 2000-07-03 Neil Booth <neilb@earthling.net> Zack Weinberg <zack@wolery.cumb.org> Complete overhaul of the lexer and macro expander. * cpphash.c (object_defn, funct_defn, push_macro_expansion, arg, arglist, argdata, reflist, collect_objlike_expansion, collect_funlike_expansion, collect_params, warn_trad_stringify, trad_stringify, duplicate_arg_p, add_pat, unsafe_chars, macarg, compare_defs, special_symbol, scan_arguments, stringify, funlike_macroexpand, _cpp_quote_string, monthnames): Delete. (cpp_lookup, _cpp_free_definition, dump_funlike_macro, _cpp_create_definition, _cpp_dump_definition, dump_hash_helper): Adjust. (find_param, count_params, parse_define, var_args_str, check_macro_redefinition, save_expansion): New. * cpplex.c (skip_block_comment, skip_line_comment, parse_name, parse_string, output_line_command, trigraph_replace, lex_line, cpp_push_buffer, cpp_pop_buffer, cpp_output_tokens, cpp_scan_buffer_nooutput, cpp_scan_buffer, cpp_free_toklist, cpp_idcmp, _cpp_get_directive_token, _cpp_init_input_buffer, _cpp_skip_rest_of_line): Modify. (maybe_macroexpand, skip_comment, copy_comment, skip_string, find_position, null_warning, bump_column, expand_name_space, pedantic_whitespace, _cpp_output_list, _cpp_slice_toklist, _cpp_squeeze_toklist, _cpp_scan_until, _cpp_skip_hspace, _cpp_parse_name, _cpp_lex_token, cpp_get_non_space_token, _cpp_prescan): Delete. (dump_param_spelling, process_directive, lex_next, is_macro_disabled, stringify_arg, expand_context_stack, output_token, make_string_token, alloc_number_token, special_symbol, duplicate_token, maybe_paste_with_next, can_paste, prevent_macro_expansion, restore_macro_expansion, get_temp_token, release_temp_tokens, quote_string, token_names, token_spellings, _cpp_expand_name_space, _cpp_glue_header_name, _cpp_reserve_name_space, digraph_spellings, trigraph_ok, skip_whitespace, save_comment, placemarker_token, eof_token, cpp_context, macro_args, get_raw_token, parse_arg, parse_args, save_token, push_arg_context, push_macro_context, pop_context, do_pop_context, free_macro_args, _cpp_get_line, _cpp_run_directive): New. * cpplib.c (validate_else, parse_include, push_conditional, pass_thru_directive, read_line_number, parse_ifdef, detect_if_not_defined, _cpp_check_directive, do_define, do_undef, do_include, do_import, do_include_next, do_error, do_warning, do_ident, do_pragma, pragma_dispatch, gcc_pragmas, top_pragmas, do_pragma_gcc, do_pragma_implementation, do_pragma_poison, do_pragma_system_header, do_pragma_dependency, do_sccs, do_ifdef, do_ifndef, do_else, dl_elif, do_endif, _cpp_unwind_if_stack, do_assert, do_unassert, cpp_define, cpp_undef, cpp_assert, cpp_unassert, cpp_defined): Update for new scheme. (strtoul_for_line, get_define_node, dump_macro_name, _cpp_check_linemarker, _cpp_parse_assertion): New. (_cpp_handle_directive, do_pragma_default): Delete. * cpphash.h (struct predicate): Now struct answer. (enum spell_type, struct token_spelling, struct directive, directive_handler): New. Update prototypes. Remove unused macros. * cpplib.h: Update prototypes. Remove unused macros, structure definitions, and fields. * cpperror.c (print_containing_files, v_message): Adjust. * cppexp.c (parse_assertion, lex, parse_escape, _cpp_parse_expr): Adjust. * cppfiles.c (open_include_file, _cpp_execute_include, _cpp_compare_file_date, cpp_read_file, read_include_file): Adjust. * cppinit.c (dump_special_to_buffer): Delete. (append_include_chain, merge_include_chains, cpp_reader_init, cpp_cleanup, initialize_builtins, builtin_array, cpp_start_read, cpp_finish, handle_option, print_help): Adjust. * cppmain.c (main): Adjust. testsuite: 2000-07-03 Zack Weinberg <zack@wolery.cumb.org> * testsuite/gcc.dg/cpp/19951025-1.c: Adjust regexps. * testsuite/gcc.dg/cpp/19990703-1.c: Likewise. * testsuite/gcc.dg/cpp/20000625-1.c: Likewise. * testsuite/gcc.dg/cpp/20000625-2.c: Likewise. * testsuite/gcc.dg/cpp/macro1.c, testsuite/gcc.dg/cpp/paste1.c, testsuite/gcc.dg/cpp/paste2.c, testsuite/gcc.dg/cpp/paste3.c, testsuite/gcc.dg/cpp/paste4.c, testsuite/gcc.dg/cpp/strify1.c, testsuite/gcc.dg/cpp/strify2.c: New tests. From-SVN: r34859
2000-07-04 03:58:21 +02:00
return stack_include_file (pfile, f);
}
/* Pushes the given file onto the buffer stack. Returns nonzero if
successful. */
bool
cpp_push_include (cpp_reader *pfile, const char *filename)
{
/* Make the command line directive take up a line. */
pfile->line++;
return _cpp_execute_include (pfile, filename, false, IT_CMDLINE);
}
/* Do appropriate cleanup when a file INC's buffer is popped off the
input stack. */
void
_cpp_pop_file_buffer (cpp_reader *pfile, struct include_file *inc)
{
/* Record the inclusion-preventing macro, which could be NULL
meaning no controlling macro. */
if (pfile->mi_valid && inc->cmacro == NULL)
inc->cmacro = pfile->mi_cmacro;
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
/* Invalidate control macros in the #including file. */
pfile->mi_valid = false;
cppfiles.c (ENABLE_VALGRIND_CHECKING, [...]): Remove. * cppfiles.c (ENABLE_VALGRIND_CHECKING, VALGRIND_DISCARD, MMAP_THRESHOLD, TEST_THRESHOLD, SHOULD_MMAP): Remove. (struct include_file): Remove fefcnt, mapped members. (open_file, stack_include_file, _cpp_pop_file_buffer): Disable caching. (read_include_file): Don't use mmap, terminate buffers in '\r'. (purge_cache): Don't use munmap. * cpphash.h (CPP_BUF_COLUMN): Update. (lexer_state): Remove lexing_comment. (struct _cpp_line_note): New. (struct cpp_buffer): New members cur_note, notes_used, notes_cap, next_line and need_line. Remove col_adjust and saved_flags. (_cpp_process_line_notes, _cpp_clean_line, _cpp_get_fresh_line, _cpp_skip_block_comment, scan_out_logical_line): New. (_cpp_init_mbchar): Remove. * cppinit.c (init_library): Remove call to _cpp_init_mbchar. (cpp_read_main_file): Set line to 1 earlier. (post_options): -traditional-cpp doesn't want trigraphs. * cpplex.c (MULTIBYTE_CHARS): Remove code predicated on this. (add_line_note, _cpp_clean_line, _cpp_process_line_notes, _cpp_get_fresh_line): New. (handle_newline, skip_escaped_newlines, trigraph_p, continue_after_nul, _cpp_init_mbchar): Remove. (get_effective_char): Update. (_cpp_skip_block_comment): Rename from skip_block_comment, simplify. (skip_line_comment): Simplify. (skip_whitespace, parse_identifier, parse_slow, parse_number, parse_string): Update. (cpp_lex_direct): Use clean lines and process line notes. Update. (cpp_interpret_charconst): No MULTIBYTE_CHARS. * cpplib.c (prepare_directive_trad): Call scan_out_logical_line directly. (_cpp_handle_directive): Don't set saved_flags. (run_directive, destringize_and_run, cpp_define, cpp_define_builtin, cpp_undef, handle_assertion, cpp_push_buffer): Update. (_cpp_pop_buffer): Free notes. * cppmacro.c (builtin_macro, paste_tokens): \n terminate buffer. * cpppch.c (cpp_read_state): \n terminate buffer. * cpptrad.c (skip_escaped_newlines, handle_newline): Remove. (copy_comment): Use _cpp_skip_block_comment. (skip_whitespace, lex_identifier, _cpp_read_logical_line_trad): Simplify. (_cpp_overlay_buffer, _cpp_remove_overlay, push_replacement_text, save_replacement_text): Update. (scan_out_logical_line): Update to use clean lines and process line notes. * fix-header.c (read_scan_file): Update. testsuite: * gcc.dg/cpp/_Pragma4.c: Remove stray space. * gcc.dg/cpp/trad/escaped-eof.c: Correct line number. From-SVN: r65808
2003-04-19 02:22:51 +02:00
purge_cache (inc);
}
/* Returns the first place in the include chain to start searching for
"" includes. This involves stripping away the basename of the
current file, unless -I- was specified.
If we're handling -include or -imacros, use the "" chain, but with
the preprocessor's cwd prepended. */
Makefile.in (C_AND_OBJC_OBJS, [...]): Update. * Makefile.in (C_AND_OBJC_OBJS, c-incpath.o, c-lex.o, LIBCPP_OBJS, cppinit.o, cppdefault.o, fix-header): Update. * c-incpath.c: New file. * c-incpath.h: New file. * c-lex.c: Include c-incpath.h. (init_c_lex): Register path simplifier. * c-opts.c: Include cppdefault.h and c-incpath.h. (TARGET_SYSTEM_ROOT, verbose, iprefix, sysroot, std_inc, std_cxx_inc, quote_chain_split, add_prefixed_path): New. (COMMAND_LINE_OPTIONS): Add more options from cpplib. (missing_arg, c_common_decode_option): Handle them. (c_common_post_options): Register include chains. (print_help): Update. * cppdefault.h (struct default include): Update. Move some macros to ... * cppdefault.c: ... here. (cpp_include_defaults): Add extra field add_sysroot. * cppfiles.c (include_file, search_from, find_or_create_entry, cpp_included, find_include_file, remap_filename): Update for renaming of search_path to cpp_path, and of the chain headers. (remove_component_p, _cpp_simplify_pathname): Move to c-incpath.c. * cpphash.h (struct search_path): Move to cpplib.h. (struct cpp_buffer, struct cpp_reader): Update. (_cpp_simplify_pathname): Remove. * cppinit.c: Don't include prefix.h and cppdefault.h. (INO_T_EQ, INO_T_COPY, path_include, append_include_chain, remove_dup_dir, remove_dup_nonsys_dirs, remove_dup_dirs, init_standard_includes, BRACKET, SYSTEM, AFTER, no_dir, no_pth, cpp_handle_options): Remove. (struct pending_option): Remove chain members. (cpp_destroy, cpp_read_main_file, COMMAND_LINE_OPTIONS, cpp_handle_option): Update. * cpplib.h (struct cpp_path, cpp_set_include_chains): New. (struct cpp_options): Remove quote_include, bracket_include, include_prefix, include_prefix_len, verbose, ignore_srcdir, no_standard_includes, no_standard_cplusplus_includes. (struct cpp_callbacks): Add simplify_path. (cpp_handle_options): Remove. * fix-header.c: Include c-incpath.h. (read_scan_file): Update to use c-incpath functionality. * doc/passes.texi: Update. cp: * Make-lang.in (CXX_C_OBJS): Update. From-SVN: r63612
2003-03-01 15:31:21 +01:00
static struct cpp_path *
search_from (cpp_reader *pfile, enum include_type type)
{
cpp_buffer *buffer = pfile->buffer;
unsigned int dlen;
/* Command line uses the cwd, and does not cache the result. */
if (type == IT_CMDLINE)
goto use_cwd;
Makefile.in (C_AND_OBJC_OBJS, [...]): Update. * Makefile.in (C_AND_OBJC_OBJS, c-incpath.o, c-lex.o, LIBCPP_OBJS, cppinit.o, cppdefault.o, fix-header): Update. * c-incpath.c: New file. * c-incpath.h: New file. * c-lex.c: Include c-incpath.h. (init_c_lex): Register path simplifier. * c-opts.c: Include cppdefault.h and c-incpath.h. (TARGET_SYSTEM_ROOT, verbose, iprefix, sysroot, std_inc, std_cxx_inc, quote_chain_split, add_prefixed_path): New. (COMMAND_LINE_OPTIONS): Add more options from cpplib. (missing_arg, c_common_decode_option): Handle them. (c_common_post_options): Register include chains. (print_help): Update. * cppdefault.h (struct default include): Update. Move some macros to ... * cppdefault.c: ... here. (cpp_include_defaults): Add extra field add_sysroot. * cppfiles.c (include_file, search_from, find_or_create_entry, cpp_included, find_include_file, remap_filename): Update for renaming of search_path to cpp_path, and of the chain headers. (remove_component_p, _cpp_simplify_pathname): Move to c-incpath.c. * cpphash.h (struct search_path): Move to cpplib.h. (struct cpp_buffer, struct cpp_reader): Update. (_cpp_simplify_pathname): Remove. * cppinit.c: Don't include prefix.h and cppdefault.h. (INO_T_EQ, INO_T_COPY, path_include, append_include_chain, remove_dup_dir, remove_dup_nonsys_dirs, remove_dup_dirs, init_standard_includes, BRACKET, SYSTEM, AFTER, no_dir, no_pth, cpp_handle_options): Remove. (struct pending_option): Remove chain members. (cpp_destroy, cpp_read_main_file, COMMAND_LINE_OPTIONS, cpp_handle_option): Update. * cpplib.h (struct cpp_path, cpp_set_include_chains): New. (struct cpp_options): Remove quote_include, bracket_include, include_prefix, include_prefix_len, verbose, ignore_srcdir, no_standard_includes, no_standard_cplusplus_includes. (struct cpp_callbacks): Add simplify_path. (cpp_handle_options): Remove. * fix-header.c: Include c-incpath.h. (read_scan_file): Update to use c-incpath functionality. * doc/passes.texi: Update. cp: * Make-lang.in (CXX_C_OBJS): Update. From-SVN: r63612
2003-03-01 15:31:21 +01:00
/* Ignore the current file's directory? */
if (pfile->quote_ignores_source_dir)
return pfile->quote_include;
if (! buffer->search_cached)
{
buffer->search_cached = 1;
dlen = lbasename (buffer->inc->name) - buffer->inc->name;
if (dlen)
{
/* We don't guarantee NAME is null-terminated. This saves
allocating and freeing memory. Drop a trailing '/'. */
Makefile.in (C_AND_OBJC_OBJS, [...]): Update. * Makefile.in (C_AND_OBJC_OBJS, c-incpath.o, c-lex.o, LIBCPP_OBJS, cppinit.o, cppdefault.o, fix-header): Update. * c-incpath.c: New file. * c-incpath.h: New file. * c-lex.c: Include c-incpath.h. (init_c_lex): Register path simplifier. * c-opts.c: Include cppdefault.h and c-incpath.h. (TARGET_SYSTEM_ROOT, verbose, iprefix, sysroot, std_inc, std_cxx_inc, quote_chain_split, add_prefixed_path): New. (COMMAND_LINE_OPTIONS): Add more options from cpplib. (missing_arg, c_common_decode_option): Handle them. (c_common_post_options): Register include chains. (print_help): Update. * cppdefault.h (struct default include): Update. Move some macros to ... * cppdefault.c: ... here. (cpp_include_defaults): Add extra field add_sysroot. * cppfiles.c (include_file, search_from, find_or_create_entry, cpp_included, find_include_file, remap_filename): Update for renaming of search_path to cpp_path, and of the chain headers. (remove_component_p, _cpp_simplify_pathname): Move to c-incpath.c. * cpphash.h (struct search_path): Move to cpplib.h. (struct cpp_buffer, struct cpp_reader): Update. (_cpp_simplify_pathname): Remove. * cppinit.c: Don't include prefix.h and cppdefault.h. (INO_T_EQ, INO_T_COPY, path_include, append_include_chain, remove_dup_dir, remove_dup_nonsys_dirs, remove_dup_dirs, init_standard_includes, BRACKET, SYSTEM, AFTER, no_dir, no_pth, cpp_handle_options): Remove. (struct pending_option): Remove chain members. (cpp_destroy, cpp_read_main_file, COMMAND_LINE_OPTIONS, cpp_handle_option): Update. * cpplib.h (struct cpp_path, cpp_set_include_chains): New. (struct cpp_options): Remove quote_include, bracket_include, include_prefix, include_prefix_len, verbose, ignore_srcdir, no_standard_includes, no_standard_cplusplus_includes. (struct cpp_callbacks): Add simplify_path. (cpp_handle_options): Remove. * fix-header.c: Include c-incpath.h. (read_scan_file): Update to use c-incpath functionality. * doc/passes.texi: Update. cp: * Make-lang.in (CXX_C_OBJS): Update. From-SVN: r63612
2003-03-01 15:31:21 +01:00
buffer->dir.name = (char *) buffer->inc->name;
if (dlen > 1)
dlen--;
}
else
{
use_cwd:
Makefile.in (C_AND_OBJC_OBJS, [...]): Update. * Makefile.in (C_AND_OBJC_OBJS, c-incpath.o, c-lex.o, LIBCPP_OBJS, cppinit.o, cppdefault.o, fix-header): Update. * c-incpath.c: New file. * c-incpath.h: New file. * c-lex.c: Include c-incpath.h. (init_c_lex): Register path simplifier. * c-opts.c: Include cppdefault.h and c-incpath.h. (TARGET_SYSTEM_ROOT, verbose, iprefix, sysroot, std_inc, std_cxx_inc, quote_chain_split, add_prefixed_path): New. (COMMAND_LINE_OPTIONS): Add more options from cpplib. (missing_arg, c_common_decode_option): Handle them. (c_common_post_options): Register include chains. (print_help): Update. * cppdefault.h (struct default include): Update. Move some macros to ... * cppdefault.c: ... here. (cpp_include_defaults): Add extra field add_sysroot. * cppfiles.c (include_file, search_from, find_or_create_entry, cpp_included, find_include_file, remap_filename): Update for renaming of search_path to cpp_path, and of the chain headers. (remove_component_p, _cpp_simplify_pathname): Move to c-incpath.c. * cpphash.h (struct search_path): Move to cpplib.h. (struct cpp_buffer, struct cpp_reader): Update. (_cpp_simplify_pathname): Remove. * cppinit.c: Don't include prefix.h and cppdefault.h. (INO_T_EQ, INO_T_COPY, path_include, append_include_chain, remove_dup_dir, remove_dup_nonsys_dirs, remove_dup_dirs, init_standard_includes, BRACKET, SYSTEM, AFTER, no_dir, no_pth, cpp_handle_options): Remove. (struct pending_option): Remove chain members. (cpp_destroy, cpp_read_main_file, COMMAND_LINE_OPTIONS, cpp_handle_option): Update. * cpplib.h (struct cpp_path, cpp_set_include_chains): New. (struct cpp_options): Remove quote_include, bracket_include, include_prefix, include_prefix_len, verbose, ignore_srcdir, no_standard_includes, no_standard_cplusplus_includes. (struct cpp_callbacks): Add simplify_path. (cpp_handle_options): Remove. * fix-header.c: Include c-incpath.h. (read_scan_file): Update to use c-incpath functionality. * doc/passes.texi: Update. cp: * Make-lang.in (CXX_C_OBJS): Update. From-SVN: r63612
2003-03-01 15:31:21 +01:00
buffer->dir.name = (char *) ".";
dlen = 1;
}
if (dlen > pfile->max_include_len)
pfile->max_include_len = dlen;
buffer->dir.len = dlen;
Makefile.in (C_AND_OBJC_OBJS, [...]): Update. * Makefile.in (C_AND_OBJC_OBJS, c-incpath.o, c-lex.o, LIBCPP_OBJS, cppinit.o, cppdefault.o, fix-header): Update. * c-incpath.c: New file. * c-incpath.h: New file. * c-lex.c: Include c-incpath.h. (init_c_lex): Register path simplifier. * c-opts.c: Include cppdefault.h and c-incpath.h. (TARGET_SYSTEM_ROOT, verbose, iprefix, sysroot, std_inc, std_cxx_inc, quote_chain_split, add_prefixed_path): New. (COMMAND_LINE_OPTIONS): Add more options from cpplib. (missing_arg, c_common_decode_option): Handle them. (c_common_post_options): Register include chains. (print_help): Update. * cppdefault.h (struct default include): Update. Move some macros to ... * cppdefault.c: ... here. (cpp_include_defaults): Add extra field add_sysroot. * cppfiles.c (include_file, search_from, find_or_create_entry, cpp_included, find_include_file, remap_filename): Update for renaming of search_path to cpp_path, and of the chain headers. (remove_component_p, _cpp_simplify_pathname): Move to c-incpath.c. * cpphash.h (struct search_path): Move to cpplib.h. (struct cpp_buffer, struct cpp_reader): Update. (_cpp_simplify_pathname): Remove. * cppinit.c: Don't include prefix.h and cppdefault.h. (INO_T_EQ, INO_T_COPY, path_include, append_include_chain, remove_dup_dir, remove_dup_nonsys_dirs, remove_dup_dirs, init_standard_includes, BRACKET, SYSTEM, AFTER, no_dir, no_pth, cpp_handle_options): Remove. (struct pending_option): Remove chain members. (cpp_destroy, cpp_read_main_file, COMMAND_LINE_OPTIONS, cpp_handle_option): Update. * cpplib.h (struct cpp_path, cpp_set_include_chains): New. (struct cpp_options): Remove quote_include, bracket_include, include_prefix, include_prefix_len, verbose, ignore_srcdir, no_standard_includes, no_standard_cplusplus_includes. (struct cpp_callbacks): Add simplify_path. (cpp_handle_options): Remove. * fix-header.c: Include c-incpath.h. (read_scan_file): Update to use c-incpath functionality. * doc/passes.texi: Update. cp: * Make-lang.in (CXX_C_OBJS): Update. From-SVN: r63612
2003-03-01 15:31:21 +01:00
buffer->dir.next = pfile->quote_include;
c-lex.c (map): Make const. * c-lex.c (map): Make const. (cb_file_change): Update for callback passing a line map. Don't assume we have a previous map. Remove sanity check about popping too many files. * cpperror.c (print_location): Make map const. * cppfiles.c (stack_include_file): Update; line maps now hold sysp. (cpp_make_system_header): Similarly. (search_from): Similarly. (_cpp_execute_include): Don't remember where we came from. * cpphash.h (struct cpp_buffer): Remove return_to_line, sysp. (struct cpp_reader): Make map const. (CPP_IN_SYSTEM_HEADER, _cpp_do_file_change): Update. * cpplib.c (do_line): Update; line maps now hold sysp. (cpp_push_buffer): Similarly. (_cpp_do_file_change): Similarly; callback with map instead. (cpp_get_line_maps): Constify return value. (_cpp_pop_buffer): Update. * cpplib.h (struct cpp_file_change): Remove. (struct cpp_callbacks): Update. (cpp_get_line_maps): Constify return value. * cppmacro.c (_cpp_create_definition): Update. * cppmain.c (struct printer): Constify map. (maybe_print_line): Similarly. (print_line): Similarly. Deduce flags 1 and 2 here. (cb_file_change): Update. * line-map.c (free_line_maps): Warn regardless. (add_line_map): Return pointer to const. When passed NULL to_file with LC_LEAVE, use the obvious values for the return point so the caller doesn't have to figure them out. (lookup_line): Return pointer to const. (print_containing_files): Take pointer to const. * line-map.h (struct line_map): New members reason, sysp. (add_line_map): Return pointer to const. (lookup_line): Similarly. (print_containing_files): Take pointer to const. From-SVN: r44789
2001-08-11 09:33:39 +02:00
buffer->dir.sysp = pfile->map->sysp;
}
return &buffer->dir;
}
/* The file_name_map structure holds a mapping of file names for a
particular directory. This mapping is read from the file named
FILE_NAME_MAP_FILE in that directory. Such a file can be used to
map filenames on a file system with severe filename restrictions,
such as DOS. The format of the file name map file is just a series
of lines with two tokens on each line. The first token is the name
to map, and the second token is the actual name to use. */
struct file_name_map {
struct file_name_map *map_next;
char *map_from;
char *map_to;
};
#define FILE_NAME_MAP_FILE "header.gcc"
/* Read a space delimited string of unlimited length from a stdio
file F. */
static char *
read_filename_string (int ch, FILE *f)
{
char *alloc, *set;
int len;
len = 20;
set = alloc = xmalloc (len + 1);
if (! is_space (ch))
{
*set++ = ch;
while ((ch = getc (f)) != EOF && ! is_space (ch))
{
if (set - alloc == len)
{
len *= 2;
alloc = xrealloc (alloc, len + 1);
set = alloc + len / 2;
}
*set++ = ch;
}
}
*set = '\0';
ungetc (ch, f);
return alloc;
}
/* This structure holds a linked list of file name maps, one per directory. */
struct file_name_map_list {
struct file_name_map_list *map_list_next;
char *map_list_name;
struct file_name_map *map_list_map;
};
/* Read the file name map file for DIRNAME. */
static struct file_name_map *
read_name_map (cpp_reader *pfile, const char *dirname)
{
alias.c: Remove uses of "register" specifier in declarations of arguments and local... 2001-10-10 Stan Shebs <shebs@apple.com> * alias.c: Remove uses of "register" specifier in declarations of arguments and local variables. * c-common.c: Ditto. * c-convert.c: Ditto. * c-decl.c: Ditto. * c-format.c: Ditto. * c-semantics.c: Ditto. * c-typeck.c: Ditto. * caller-save.c: Ditto. * calls.c: Ditto. * cfg.c: Ditto. * cfgbuild.c: Ditto. * cfgrtl.c: Ditto. * collect2.c: Ditto. * combine.c: Ditto. * convert.c: Ditto. * cppexp.c: Ditto. * cppfiles.c: Ditto. * cse.c: Ditto. * dbxout.c: Ditto. * defaults.h: Ditto. * df.c: Ditto. * dwarf2out.c: Ditto. * dwarfout.c: Ditto. * emit-rtl.c: Ditto. * explow.c: Ditto. * expmed.c: Ditto. * expr.c: Ditto. * final.c: Ditto. * fix-header.c: Ditto. * floatlib.c: Ditto. * flow.c: Ditto. * fold-const.c: Ditto. * function.c: Ditto. * gcc.c: Ditto. * gcse.c: Ditto. * gen-protos.c: Ditto. * genattrtab.c: Ditto. * gencheck.c: Ditto. * genconfig.c: Ditto. * genemit.c: Ditto. * genextract.c: Ditto. * genflags.c: Ditto. * gengenrtl.c: Ditto. * genoutput.c: Ditto. * genpeep.c: Ditto. * genrecog.c: Ditto. * gensupport.c: Ditto. * global.c: Ditto. * gmon.c: Ditto. * graph.c: Ditto. * haifa-sched.c: Ditto. * hard-reg-set.h: Ditto. * hash.c: Ditto. * integrate.c: Ditto. * jump.c: Ditto. * lists.c: Ditto. * local-alloc.c: Ditto. * loop.c: Ditto. * mips-tdump.c: Ditto. * mips-tfile.c: Ditto. * optabs.c: Ditto. * prefix.c: Ditto. * print-rtl.c: Ditto. * read-rtl.c: Ditto. * real.c: Ditto. * recog.c: Ditto. * reg-stack.c: Ditto. * regclass.c: Ditto. * regmove.c: Ditto. * reload.c: Ditto. * reload1.c: Ditto. * reorg.c: Ditto. * resource.c: Ditto. * rtl.c: Ditto. * rtlanal.c: Ditto. * scan.c: Ditto. * sched-deps.c: Ditto. * sched-rgn.c: Ditto. * sdbout.c: Ditto. * simplify-rtx.c: Ditto. * stmt.c: Ditto. * stor-layout.c: Ditto. * toplev.c: Ditto. * tradcif.y: Ditto. * tradcpp.c: Ditto. * tree.c: Ditto. * unroll.c: Ditto. * varasm.c: Ditto. * xcoffout.c: Ditto. From-SVN: r46173
2001-10-11 05:16:15 +02:00
struct file_name_map_list *map_list_ptr;
char *name;
FILE *f;
/* Check the cache of directories, and mappings in their remap file. */
for (map_list_ptr = CPP_OPTION (pfile, map_list); map_list_ptr;
map_list_ptr = map_list_ptr->map_list_next)
if (! strcmp (map_list_ptr->map_list_name, dirname))
return map_list_ptr->map_list_map;
map_list_ptr = xmalloc (sizeof (struct file_name_map_list));
map_list_ptr->map_list_name = xstrdup (dirname);
/* The end of the list ends in NULL. */
map_list_ptr->map_list_map = NULL;
name = alloca (strlen (dirname) + strlen (FILE_NAME_MAP_FILE) + 2);
strcpy (name, dirname);
if (*dirname)
strcat (name, "/");
strcat (name, FILE_NAME_MAP_FILE);
f = fopen (name, "r");
/* Silently return NULL if we cannot open. */
if (f)
{
int ch;
while ((ch = getc (f)) != EOF)
{
char *from, *to;
struct file_name_map *ptr;
if (is_space (ch))
continue;
from = read_filename_string (ch, f);
while ((ch = getc (f)) != EOF && is_hspace (ch))
;
to = read_filename_string (ch, f);
ptr = xmalloc (sizeof (struct file_name_map));
ptr->map_from = from;
/* Make the real filename absolute. */
if (IS_ABSOLUTE_PATH (to))
ptr->map_to = to;
else
{
ptr->map_to = concat (dirname, "/", to, NULL);
free (to);
}
ptr->map_next = map_list_ptr->map_list_map;
map_list_ptr->map_list_map = ptr;
while ((ch = getc (f)) != '\n')
if (ch == EOF)
break;
}
fclose (f);
}
/* Add this information to the cache. */
map_list_ptr->map_list_next = CPP_OPTION (pfile, map_list);
CPP_OPTION (pfile, map_list) = map_list_ptr;
return map_list_ptr->map_list_map;
}
/* Remap an unsimplified path NAME based on the file_name_map (if any)
for LOC. */
static char *
remap_filename (cpp_reader *pfile, char *name, struct cpp_path *loc)
{
struct file_name_map *map;
const char *from, *p;
char *dir;
if (! loc->name_map)
{
/* Get a null-terminated path. */
char *dname = alloca (loc->len + 1);
memcpy (dname, loc->name, loc->len);
dname[loc->len] = '\0';
loc->name_map = read_name_map (pfile, dname);
if (! loc->name_map)
return name;
}
/* This works since NAME has not been simplified yet. */
from = name + loc->len + 1;
for (map = loc->name_map; map; map = map->map_next)
if (!strcmp (map->map_from, from))
return map->map_to;
/* Try to find a mapping file for the particular directory we are
looking in. Thus #include <sys/types.h> will look up sys/types.h
in /usr/include/header.gcc and look up types.h in
/usr/include/sys/header.gcc. */
p = strrchr (name, '/');
if (!p)
return name;
/* We know p != name as absolute paths don't call remap_filename. */
if (p == name)
cpperror.c (print_location): Don't print include chain if line == 0. * cpperror.c (print_location): Don't print include chain if line == 0. (cpp_begin_message): Update to use DL_ macros. (cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_notice, cpp_notice_from_errno): Remove. (cpp_error, cpp_error_with_line): Update to take a diagnostic level. (cpp_errno): New. * cppexp.c (CPP_ICE): Remove. (SYNTAX_ERROR, SYNTAX_ERROR2, parse_number, parse_defined, lex, integer_overflow, _cpp_parse_expr): Update. * cppfiles.c (read_include_file, find_include_file, handle_missing_header, _cpp_read_file, remap_filename): Update. * cpphash.h (enum error_type): Remove. (_cpp_begin_message): Update. * cppinit.c (append_include_chain, remove_dup_dirs, output_deps, cpp_handle_option, cpp_post_options): Update. * cpplex.c (trigraph_p, skip_escaped_newlines, skip_block_comment, skip_whitespace, parse_identifier, parse_slow, parse_string, _cpp_lex_direct, cpp_spell_token, maybe_read_ucs, cpp_parse_escape, cpp_interpret_charconst): Update. * cpplib.c (check_eol, directive_diagnostics, _cpp_handle_directive, lex_macro_node, do_undef, glue_header_name, parse_include, do_include_common, read_flag, do_line, do_linemarker, do_ident, cpp_register_pragma, do_pragma_once, do_pragma_system_header, do_pragma_poison, do_pragma_dependency, _cpp_do__Pragma, do_else, do_elif, do_endif, parse_answer, parse_assertion, do_assert, _cpp_pop_buffer, do_diagnostic): Update. * cpplib.h (DL_WARNING, DL_WARNING_SYSHDR, DL_PEDWARN, DL_ERROR, DL_FATAL, DL_ICE, DL_EXTRACT, DL_WARNING_P): New. (cpp_ice, cpp_fatal, cpp_error_from_errno, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_notice, cpp_notice_from_errno): Remove. (cpp_error, cpp_error_with_line): Update to take a diagnostic level. (cpp_errno): New. * cppmacro.c (builtin_macro, stringify_arg, paste_all_tokens, collect_args, enter_macro_context, save_parameter, parse_params, _cpp_create_definition, check_trad_stringification, cpp_macro_definition): Update. * cppmain.c (cpp_preprocess_file): Update. * fix-header.c (read_scan_file): Update. From-SVN: r52302
2002-04-14 20:42:47 +02:00
cpp_error (pfile, DL_ICE, "absolute file name in remap_filename");
dir = alloca (p - name + 1);
memcpy (dir, name, p - name);
dir[p - name] = '\0';
from = p + 1;
for (map = read_name_map (pfile, dir); map; map = map->map_next)
if (! strcmp (map->map_from, from))
return map->map_to;
return name;
}
Makefile.in (C_AND_OBJC_OBJS, [...]): Update. * Makefile.in (C_AND_OBJC_OBJS, c-incpath.o, c-lex.o, LIBCPP_OBJS, cppinit.o, cppdefault.o, fix-header): Update. * c-incpath.c: New file. * c-incpath.h: New file. * c-lex.c: Include c-incpath.h. (init_c_lex): Register path simplifier. * c-opts.c: Include cppdefault.h and c-incpath.h. (TARGET_SYSTEM_ROOT, verbose, iprefix, sysroot, std_inc, std_cxx_inc, quote_chain_split, add_prefixed_path): New. (COMMAND_LINE_OPTIONS): Add more options from cpplib. (missing_arg, c_common_decode_option): Handle them. (c_common_post_options): Register include chains. (print_help): Update. * cppdefault.h (struct default include): Update. Move some macros to ... * cppdefault.c: ... here. (cpp_include_defaults): Add extra field add_sysroot. * cppfiles.c (include_file, search_from, find_or_create_entry, cpp_included, find_include_file, remap_filename): Update for renaming of search_path to cpp_path, and of the chain headers. (remove_component_p, _cpp_simplify_pathname): Move to c-incpath.c. * cpphash.h (struct search_path): Move to cpplib.h. (struct cpp_buffer, struct cpp_reader): Update. (_cpp_simplify_pathname): Remove. * cppinit.c: Don't include prefix.h and cppdefault.h. (INO_T_EQ, INO_T_COPY, path_include, append_include_chain, remove_dup_dir, remove_dup_nonsys_dirs, remove_dup_dirs, init_standard_includes, BRACKET, SYSTEM, AFTER, no_dir, no_pth, cpp_handle_options): Remove. (struct pending_option): Remove chain members. (cpp_destroy, cpp_read_main_file, COMMAND_LINE_OPTIONS, cpp_handle_option): Update. * cpplib.h (struct cpp_path, cpp_set_include_chains): New. (struct cpp_options): Remove quote_include, bracket_include, include_prefix, include_prefix_len, verbose, ignore_srcdir, no_standard_includes, no_standard_cplusplus_includes. (struct cpp_callbacks): Add simplify_path. (cpp_handle_options): Remove. * fix-header.c: Include c-incpath.h. (read_scan_file): Update to use c-incpath functionality. * doc/passes.texi: Update. cp: * Make-lang.in (CXX_C_OBJS): Update. From-SVN: r63612
2003-03-01 15:31:21 +01:00
/* Set the include chain for "" to QUOTE, for <> to BRACKET. If
QUOTE_IGNORES_SOURCE_DIR, then "" includes do not look in the
directory of the including file.
Makefile.in (C_AND_OBJC_OBJS, [...]): Update. * Makefile.in (C_AND_OBJC_OBJS, c-incpath.o, c-lex.o, LIBCPP_OBJS, cppinit.o, cppdefault.o, fix-header): Update. * c-incpath.c: New file. * c-incpath.h: New file. * c-lex.c: Include c-incpath.h. (init_c_lex): Register path simplifier. * c-opts.c: Include cppdefault.h and c-incpath.h. (TARGET_SYSTEM_ROOT, verbose, iprefix, sysroot, std_inc, std_cxx_inc, quote_chain_split, add_prefixed_path): New. (COMMAND_LINE_OPTIONS): Add more options from cpplib. (missing_arg, c_common_decode_option): Handle them. (c_common_post_options): Register include chains. (print_help): Update. * cppdefault.h (struct default include): Update. Move some macros to ... * cppdefault.c: ... here. (cpp_include_defaults): Add extra field add_sysroot. * cppfiles.c (include_file, search_from, find_or_create_entry, cpp_included, find_include_file, remap_filename): Update for renaming of search_path to cpp_path, and of the chain headers. (remove_component_p, _cpp_simplify_pathname): Move to c-incpath.c. * cpphash.h (struct search_path): Move to cpplib.h. (struct cpp_buffer, struct cpp_reader): Update. (_cpp_simplify_pathname): Remove. * cppinit.c: Don't include prefix.h and cppdefault.h. (INO_T_EQ, INO_T_COPY, path_include, append_include_chain, remove_dup_dir, remove_dup_nonsys_dirs, remove_dup_dirs, init_standard_includes, BRACKET, SYSTEM, AFTER, no_dir, no_pth, cpp_handle_options): Remove. (struct pending_option): Remove chain members. (cpp_destroy, cpp_read_main_file, COMMAND_LINE_OPTIONS, cpp_handle_option): Update. * cpplib.h (struct cpp_path, cpp_set_include_chains): New. (struct cpp_options): Remove quote_include, bracket_include, include_prefix, include_prefix_len, verbose, ignore_srcdir, no_standard_includes, no_standard_cplusplus_includes. (struct cpp_callbacks): Add simplify_path. (cpp_handle_options): Remove. * fix-header.c: Include c-incpath.h. (read_scan_file): Update to use c-incpath functionality. * doc/passes.texi: Update. cp: * Make-lang.in (CXX_C_OBJS): Update. From-SVN: r63612
2003-03-01 15:31:21 +01:00
If BRACKET does not lie in the QUOTE chain, it is set to QUOTE. */
void
cpp_set_include_chains (cpp_reader *pfile, cpp_path *quote, cpp_path *bracket,
int quote_ignores_source_dir)
cpplib.h: Delete struct import_file. Wed Nov 25 14:54:46 1998 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.h: Delete struct import_file. Add ihash element to struct cpp_buffer. Delete dont_repeat_files and import_hash_table elements from cpp_reader; change all_include_files to a hash table. Delete all foobar_include / last_foobar_include elements from struct cpp_options; put back four such: quote_include, bracket_include, system_include, after_include. Redo struct file_name_list completely. Add new structure type include_hash. Add prototypes for merge_include_chains and include_hash. Change prototypes for finclude, find_include_file, and append_include_chain to match changes below. * cppfiles.c (simplify_pathname, include_hash, remap_filename, merge_include_chains): New functions. (add_import, lookup_import, open_include_file): Removed. (INO_T_EQ): Define this (copied from cccp.c). (hack_vms_include_specification): Remove all calls and #if 0 out the definition. It was being called incorrectly and at the wrong times. Until a VMSie can look at this, it's better to not pretend to support it. (append_include_chain): Change calling convention; now takes only one directory at a time, and sets up the data structure itself. (redundant_include_p): Rewritten - this is now used for all include redundancy, whether by #ifndef, #import, or #pragma once. Looks up things in the include hash table. (file_cleanup): Decrement pfile->system_include_depth here if it's >0. (find_include_file): Calling convention changed; now passes around a struct include_hash instead of 3 separate parameters. Guts ripped out and replaced with new include_hash mechanism. (finclude): Calling convention changed as for find_include_file. Error exits pulled out-of-line. Reformat. (safe_read): Return a long, not an int. (deps_output): Don't recurse. * cpplib.c (is_system_include): Deleted. (path_include): Fix up call to append_include_chain. (do_include): Fix up calls to find_include_file and finclude. Clean up dependency output a bit. Shorten obnoxiously lengthy #import warning message. Don't decrement pfile->system_include_depth here. (do_pragma): Understand the include_hash structure. Reformat. (do_endif): Correct handling of control macros. Understand the include_hash. (cpp_start_read): Fix up calls to finclude. Call merge_include_chains. (cpp_handle_option): Fix up calls to append_include_chain. Understand the four partial include chains. (cpp_finish): Add debugging code (#if 0-ed out) for the include_hash. (cpp_cleanup): Free the include_hash, not the import hash and the all_include and dont_repeat lists which no longer exist. From-SVN: r23857
1998-11-25 12:56:54 +01:00
{
Makefile.in (C_AND_OBJC_OBJS, [...]): Update. * Makefile.in (C_AND_OBJC_OBJS, c-incpath.o, c-lex.o, LIBCPP_OBJS, cppinit.o, cppdefault.o, fix-header): Update. * c-incpath.c: New file. * c-incpath.h: New file. * c-lex.c: Include c-incpath.h. (init_c_lex): Register path simplifier. * c-opts.c: Include cppdefault.h and c-incpath.h. (TARGET_SYSTEM_ROOT, verbose, iprefix, sysroot, std_inc, std_cxx_inc, quote_chain_split, add_prefixed_path): New. (COMMAND_LINE_OPTIONS): Add more options from cpplib. (missing_arg, c_common_decode_option): Handle them. (c_common_post_options): Register include chains. (print_help): Update. * cppdefault.h (struct default include): Update. Move some macros to ... * cppdefault.c: ... here. (cpp_include_defaults): Add extra field add_sysroot. * cppfiles.c (include_file, search_from, find_or_create_entry, cpp_included, find_include_file, remap_filename): Update for renaming of search_path to cpp_path, and of the chain headers. (remove_component_p, _cpp_simplify_pathname): Move to c-incpath.c. * cpphash.h (struct search_path): Move to cpplib.h. (struct cpp_buffer, struct cpp_reader): Update. (_cpp_simplify_pathname): Remove. * cppinit.c: Don't include prefix.h and cppdefault.h. (INO_T_EQ, INO_T_COPY, path_include, append_include_chain, remove_dup_dir, remove_dup_nonsys_dirs, remove_dup_dirs, init_standard_includes, BRACKET, SYSTEM, AFTER, no_dir, no_pth, cpp_handle_options): Remove. (struct pending_option): Remove chain members. (cpp_destroy, cpp_read_main_file, COMMAND_LINE_OPTIONS, cpp_handle_option): Update. * cpplib.h (struct cpp_path, cpp_set_include_chains): New. (struct cpp_options): Remove quote_include, bracket_include, include_prefix, include_prefix_len, verbose, ignore_srcdir, no_standard_includes, no_standard_cplusplus_includes. (struct cpp_callbacks): Add simplify_path. (cpp_handle_options): Remove. * fix-header.c: Include c-incpath.h. (read_scan_file): Update to use c-incpath functionality. * doc/passes.texi: Update. cp: * Make-lang.in (CXX_C_OBJS): Update. From-SVN: r63612
2003-03-01 15:31:21 +01:00
pfile->quote_include = quote;
pfile->bracket_include = quote;
pfile->quote_ignores_source_dir = quote_ignores_source_dir;
pfile->max_include_len = 0;
Makefile.in (C_AND_OBJC_OBJS, [...]): Update. * Makefile.in (C_AND_OBJC_OBJS, c-incpath.o, c-lex.o, LIBCPP_OBJS, cppinit.o, cppdefault.o, fix-header): Update. * c-incpath.c: New file. * c-incpath.h: New file. * c-lex.c: Include c-incpath.h. (init_c_lex): Register path simplifier. * c-opts.c: Include cppdefault.h and c-incpath.h. (TARGET_SYSTEM_ROOT, verbose, iprefix, sysroot, std_inc, std_cxx_inc, quote_chain_split, add_prefixed_path): New. (COMMAND_LINE_OPTIONS): Add more options from cpplib. (missing_arg, c_common_decode_option): Handle them. (c_common_post_options): Register include chains. (print_help): Update. * cppdefault.h (struct default include): Update. Move some macros to ... * cppdefault.c: ... here. (cpp_include_defaults): Add extra field add_sysroot. * cppfiles.c (include_file, search_from, find_or_create_entry, cpp_included, find_include_file, remap_filename): Update for renaming of search_path to cpp_path, and of the chain headers. (remove_component_p, _cpp_simplify_pathname): Move to c-incpath.c. * cpphash.h (struct search_path): Move to cpplib.h. (struct cpp_buffer, struct cpp_reader): Update. (_cpp_simplify_pathname): Remove. * cppinit.c: Don't include prefix.h and cppdefault.h. (INO_T_EQ, INO_T_COPY, path_include, append_include_chain, remove_dup_dir, remove_dup_nonsys_dirs, remove_dup_dirs, init_standard_includes, BRACKET, SYSTEM, AFTER, no_dir, no_pth, cpp_handle_options): Remove. (struct pending_option): Remove chain members. (cpp_destroy, cpp_read_main_file, COMMAND_LINE_OPTIONS, cpp_handle_option): Update. * cpplib.h (struct cpp_path, cpp_set_include_chains): New. (struct cpp_options): Remove quote_include, bracket_include, include_prefix, include_prefix_len, verbose, ignore_srcdir, no_standard_includes, no_standard_cplusplus_includes. (struct cpp_callbacks): Add simplify_path. (cpp_handle_options): Remove. * fix-header.c: Include c-incpath.h. (read_scan_file): Update to use c-incpath functionality. * doc/passes.texi: Update. cp: * Make-lang.in (CXX_C_OBJS): Update. From-SVN: r63612
2003-03-01 15:31:21 +01:00
for (; quote; quote = quote->next)
cpplib.h: Delete struct import_file. Wed Nov 25 14:54:46 1998 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.h: Delete struct import_file. Add ihash element to struct cpp_buffer. Delete dont_repeat_files and import_hash_table elements from cpp_reader; change all_include_files to a hash table. Delete all foobar_include / last_foobar_include elements from struct cpp_options; put back four such: quote_include, bracket_include, system_include, after_include. Redo struct file_name_list completely. Add new structure type include_hash. Add prototypes for merge_include_chains and include_hash. Change prototypes for finclude, find_include_file, and append_include_chain to match changes below. * cppfiles.c (simplify_pathname, include_hash, remap_filename, merge_include_chains): New functions. (add_import, lookup_import, open_include_file): Removed. (INO_T_EQ): Define this (copied from cccp.c). (hack_vms_include_specification): Remove all calls and #if 0 out the definition. It was being called incorrectly and at the wrong times. Until a VMSie can look at this, it's better to not pretend to support it. (append_include_chain): Change calling convention; now takes only one directory at a time, and sets up the data structure itself. (redundant_include_p): Rewritten - this is now used for all include redundancy, whether by #ifndef, #import, or #pragma once. Looks up things in the include hash table. (file_cleanup): Decrement pfile->system_include_depth here if it's >0. (find_include_file): Calling convention changed; now passes around a struct include_hash instead of 3 separate parameters. Guts ripped out and replaced with new include_hash mechanism. (finclude): Calling convention changed as for find_include_file. Error exits pulled out-of-line. Reformat. (safe_read): Return a long, not an int. (deps_output): Don't recurse. * cpplib.c (is_system_include): Deleted. (path_include): Fix up call to append_include_chain. (do_include): Fix up calls to find_include_file and finclude. Clean up dependency output a bit. Shorten obnoxiously lengthy #import warning message. Don't decrement pfile->system_include_depth here. (do_pragma): Understand the include_hash structure. Reformat. (do_endif): Correct handling of control macros. Understand the include_hash. (cpp_start_read): Fix up calls to finclude. Call merge_include_chains. (cpp_handle_option): Fix up calls to append_include_chain. Understand the four partial include chains. (cpp_finish): Add debugging code (#if 0-ed out) for the include_hash. (cpp_cleanup): Free the include_hash, not the import hash and the all_include and dont_repeat lists which no longer exist. From-SVN: r23857
1998-11-25 12:56:54 +01:00
{
Makefile.in (C_AND_OBJC_OBJS, [...]): Update. * Makefile.in (C_AND_OBJC_OBJS, c-incpath.o, c-lex.o, LIBCPP_OBJS, cppinit.o, cppdefault.o, fix-header): Update. * c-incpath.c: New file. * c-incpath.h: New file. * c-lex.c: Include c-incpath.h. (init_c_lex): Register path simplifier. * c-opts.c: Include cppdefault.h and c-incpath.h. (TARGET_SYSTEM_ROOT, verbose, iprefix, sysroot, std_inc, std_cxx_inc, quote_chain_split, add_prefixed_path): New. (COMMAND_LINE_OPTIONS): Add more options from cpplib. (missing_arg, c_common_decode_option): Handle them. (c_common_post_options): Register include chains. (print_help): Update. * cppdefault.h (struct default include): Update. Move some macros to ... * cppdefault.c: ... here. (cpp_include_defaults): Add extra field add_sysroot. * cppfiles.c (include_file, search_from, find_or_create_entry, cpp_included, find_include_file, remap_filename): Update for renaming of search_path to cpp_path, and of the chain headers. (remove_component_p, _cpp_simplify_pathname): Move to c-incpath.c. * cpphash.h (struct search_path): Move to cpplib.h. (struct cpp_buffer, struct cpp_reader): Update. (_cpp_simplify_pathname): Remove. * cppinit.c: Don't include prefix.h and cppdefault.h. (INO_T_EQ, INO_T_COPY, path_include, append_include_chain, remove_dup_dir, remove_dup_nonsys_dirs, remove_dup_dirs, init_standard_includes, BRACKET, SYSTEM, AFTER, no_dir, no_pth, cpp_handle_options): Remove. (struct pending_option): Remove chain members. (cpp_destroy, cpp_read_main_file, COMMAND_LINE_OPTIONS, cpp_handle_option): Update. * cpplib.h (struct cpp_path, cpp_set_include_chains): New. (struct cpp_options): Remove quote_include, bracket_include, include_prefix, include_prefix_len, verbose, ignore_srcdir, no_standard_includes, no_standard_cplusplus_includes. (struct cpp_callbacks): Add simplify_path. (cpp_handle_options): Remove. * fix-header.c: Include c-incpath.h. (read_scan_file): Update to use c-incpath functionality. * doc/passes.texi: Update. cp: * Make-lang.in (CXX_C_OBJS): Update. From-SVN: r63612
2003-03-01 15:31:21 +01:00
quote->name_map = NULL;
quote->len = strlen (quote->name);
if (quote->len > pfile->max_include_len)
pfile->max_include_len = quote->len;
if (quote == bracket)
pfile->bracket_include = bracket;
cpplib.h: Delete struct import_file. Wed Nov 25 14:54:46 1998 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.h: Delete struct import_file. Add ihash element to struct cpp_buffer. Delete dont_repeat_files and import_hash_table elements from cpp_reader; change all_include_files to a hash table. Delete all foobar_include / last_foobar_include elements from struct cpp_options; put back four such: quote_include, bracket_include, system_include, after_include. Redo struct file_name_list completely. Add new structure type include_hash. Add prototypes for merge_include_chains and include_hash. Change prototypes for finclude, find_include_file, and append_include_chain to match changes below. * cppfiles.c (simplify_pathname, include_hash, remap_filename, merge_include_chains): New functions. (add_import, lookup_import, open_include_file): Removed. (INO_T_EQ): Define this (copied from cccp.c). (hack_vms_include_specification): Remove all calls and #if 0 out the definition. It was being called incorrectly and at the wrong times. Until a VMSie can look at this, it's better to not pretend to support it. (append_include_chain): Change calling convention; now takes only one directory at a time, and sets up the data structure itself. (redundant_include_p): Rewritten - this is now used for all include redundancy, whether by #ifndef, #import, or #pragma once. Looks up things in the include hash table. (file_cleanup): Decrement pfile->system_include_depth here if it's >0. (find_include_file): Calling convention changed; now passes around a struct include_hash instead of 3 separate parameters. Guts ripped out and replaced with new include_hash mechanism. (finclude): Calling convention changed as for find_include_file. Error exits pulled out-of-line. Reformat. (safe_read): Return a long, not an int. (deps_output): Don't recurse. * cpplib.c (is_system_include): Deleted. (path_include): Fix up call to append_include_chain. (do_include): Fix up calls to find_include_file and finclude. Clean up dependency output a bit. Shorten obnoxiously lengthy #import warning message. Don't decrement pfile->system_include_depth here. (do_pragma): Understand the include_hash structure. Reformat. (do_endif): Correct handling of control macros. Understand the include_hash. (cpp_start_read): Fix up calls to finclude. Call merge_include_chains. (cpp_handle_option): Fix up calls to append_include_chain. Understand the four partial include chains. (cpp_finish): Add debugging code (#if 0-ed out) for the include_hash. (cpp_cleanup): Free the include_hash, not the import hash and the all_include and dont_repeat lists which no longer exist. From-SVN: r23857
1998-11-25 12:56:54 +01:00
}
}
/* Returns true if it is safe to remove the final component of path,
when it is followed by a ".." component. We use lstat to avoid
symlinks if we have it. If not, we can still catch errors with
stat (). */
static int
remove_component_p (const char *path)
{
struct stat s;
int result;
#ifdef HAVE_LSTAT
result = lstat (path, &s);
#else
result = stat (path, &s);
#endif
/* There's no guarantee that errno will be unchanged, even on
success. Cygwin's lstat(), for example, will often set errno to
ENOSYS. In case of success, reset errno to zero. */
if (result == 0)
errno = 0;
return result == 0 && S_ISDIR (s.st_mode);
}
/* Simplify a path name in place, deleting redundant components. This
reduces OS overhead and guarantees that equivalent paths compare
the same (modulo symlinks).
Transforms made:
foo/bar/../quux foo/quux
foo/./bar foo/bar
foo//bar foo/bar
/../quux /quux
//quux //quux (POSIX allows leading // as a namespace escape)
Guarantees no trailing slashes. All transforms reduce the length
of the string. Returns PATH. errno is 0 if no error occurred;
nonzero if an error occurred when using stat () or lstat (). */
void
cpp_simplify_path (char *path ATTRIBUTE_UNUSED)
{
#ifndef VMS
char *from, *to;
char *base, *orig_base;
int absolute = 0;
errno = 0;
/* Don't overflow the empty path by putting a '.' in it below. */
if (*path == '\0')
return;
#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
/* Convert all backslashes to slashes. */
for (from = path; *from; from++)
if (*from == '\\') *from = '/';
/* Skip over leading drive letter if present. */
if (ISALPHA (path[0]) && path[1] == ':')
from = to = &path[2];
else
from = to = path;
#else
from = to = path;
#endif
/* Remove redundant leading /s. */
if (*from == '/')
{
absolute = 1;
to++;
from++;
if (*from == '/')
{
if (*++from == '/')
/* 3 or more initial /s are equivalent to 1 /. */
while (*++from == '/');
else
/* On some hosts // differs from /; Posix allows this. */
to++;
}
}
base = orig_base = to;
for (;;)
{
int move_base = 0;
while (*from == '/')
from++;
if (*from == '\0')
break;
if (*from == '.')
{
if (from[1] == '\0')
break;
if (from[1] == '/')
{
from += 2;
continue;
}
else if (from[1] == '.' && (from[2] == '/' || from[2] == '\0'))
{
/* Don't simplify if there was no previous component. */
if (absolute && orig_base == to)
{
from += 2;
continue;
}
/* Don't simplify if the previous component was "../",
or if an error has already occurred with (l)stat. */
if (base != to && errno == 0)
{
/* We don't back up if it's a symlink. */
*to = '\0';
if (remove_component_p (path))
{
while (to > base && *to != '/')
to--;
from += 2;
continue;
}
}
move_base = 1;
}
}
/* Add the component separator. */
if (to > orig_base)
*to++ = '/';
/* Copy this component until the trailing null or '/'. */
while (*from != '\0' && *from != '/')
*to++ = *from++;
if (move_base)
base = to;
}
/* Change the empty string to "." so that it is not treated as stdin.
Null terminate. */
if (to == path)
*to++ = '.';
*to = '\0';
#else /* VMS */
errno = 0;
#endif /* !VMS */
}