diff options
author | Neil Booth <neil@daikokuya.demon.co.uk> | 2001-11-15 10:01:10 +0000 |
---|---|---|
committer | Neil Booth <neil@gcc.gnu.org> | 2001-11-15 10:01:10 +0000 |
commit | f5e99456f19b80978984f781e1d847b90d09b30a (patch) | |
tree | cac90266aeb52525edc15fddc73e9428ce8a8556 /gcc/cppinit.c | |
parent | 87bc7fa6aab909eb842be0800e0284b0daa3de70 (diff) | |
download | gcc-f5e99456f19b80978984f781e1d847b90d09b30a.zip gcc-f5e99456f19b80978984f781e1d847b90d09b30a.tar.gz gcc-f5e99456f19b80978984f781e1d847b90d09b30a.tar.bz2 |
c-common.c: Include c-lex.h.
* c-common.c: Include c-lex.h.
(c_common_lang_init): Change prototype. Call init_c_lex and
init_pragma from here.
* c-common.h (c_common_lang_init): Change prototype.
* c-decl.c (init_decl_processing): Rename. Call c_parse_init.
* c-lang.c (c_init): Change prototype. Update.
(c_init_options): Update.
* c-lex.c (cpp_filename): Remove.
(init_c_lex): Update. Read the main file, and get the original
file name.
(yyparse): Finish the command line options.
* c-parse.in (c_parse_init): Call init_reswords here.
(init_parse): Remove.
* c-tree.h (c_init_decl_processing): New.
* cpphash.c (_cpp_init_hashtable): After initializing the hash
table, populate it.
* cppinit.c (read_original_filename, cpp_finish_options): New.
(cpp_create_reader): New prototype. Defer hash table initialization.
(cpp_start_read): Rename cpp_read_main_file. Initialize the
hash table. Get the original filename.
* cpplib.h (cpp_create_reader): Update.
(cpp_start_read): Remove.
(cpp_read_main_file, cpp_finish_options): New.
* cppmain.c (main, do_preprocessing): Update.
* langhooks.h (struct langhooks): Update init prototype.
* toplev.c (general_init, parse_options_and_default_flags,
process_options, lang_indpendent_init, lang_dependent_init,
init_asm_output): New; perform the bulk of initialization.
(compile_file): Move most of initialization to above functions.
(debug_hooks): Initialize statically.
(set_Wunused): Relocate.
(toplev_main): Move most of initialization to other init functions.
Have a clear logic flow.
* tree.h (init_parse, init_decl_processing): Remove.
ada:
* misc.c (gnat_init): Change prototype. Include the
functionality of the old init_parse and init_decl_processing.
(gnat_init_decl_processing): New prototype.
(init_parse): Remove.
* utils.c (init_decl_processing): Rename gnat_init_decl_processing.
cp: * cp-tree.h (init_reswords, cxx_init_decl_processing): New.
(cxx_init): Update prototype.
* decl.c (init_decl_processing): Rename. Move null node init
to its creation time.
* lex.c (cxx_init_options): Update.
(cxx_init): Combine with old init_parse; also call
cxx_init_decl_processing.
f: * com.c (ffecom_init_decl_processing): Renamed from
init_decl_processing.
(init_parse): Move contents to ffe_init.
(ffe_init): Update prototype.
java: * decl.c (init_decl_processing): Rename java_init_decl_processing.
* java-tree.h: New prototype.
* lang.c (java_init): Update prototype. Combine with old init_parse.
objc: * objc-act.c (objc_init): Update prototype, combine with old
init_parse.
(objc_init_options): Update.
From-SVN: r47046
Diffstat (limited to 'gcc/cppinit.c')
-rw-r--r-- | gcc/cppinit.c | 94 |
1 files changed, 63 insertions, 31 deletions
diff --git a/gcc/cppinit.c b/gcc/cppinit.c index d17dcac01..ba9f122 100644 --- a/gcc/cppinit.c +++ b/gcc/cppinit.c @@ -63,7 +63,7 @@ struct pending_option }; /* The `pending' structure accumulates all the options that are not - actually processed until we hit cpp_start_read. It consists of + actually processed until we hit cpp_read_main_file. It consists of several lists, one for each type of option. We keep both head and tail pointers for quick insertion. */ struct cpp_pending @@ -111,6 +111,7 @@ static void free_chain PARAMS ((struct pending_option *)); static void set_lang PARAMS ((cpp_reader *, enum c_lang)); static void init_dependency_output PARAMS ((cpp_reader *)); static void init_standard_includes PARAMS ((cpp_reader *)); +static void read_original_filename PARAMS ((cpp_reader *)); static void new_pending_directive PARAMS ((struct cpp_pending *, const char *, cl_directive_handler)); @@ -476,11 +477,9 @@ init_library () /* Initialize a cpp_reader structure. */ cpp_reader * -cpp_create_reader (table, lang) - hash_table *table; +cpp_create_reader (lang) enum c_lang lang; { - struct spec_nodes *s; cpp_reader *pfile; /* Initialise this instance of the library if it hasn't been already. */ @@ -534,23 +533,7 @@ cpp_create_reader (table, lang) /* Initialise the buffer obstack. */ gcc_obstack_init (&pfile->buffer_ob); - /* Initialise the hashtable. */ - _cpp_init_hashtable (pfile, table); - - _cpp_init_directives (pfile); _cpp_init_includes (pfile); - _cpp_init_internal_pragmas (pfile); - - /* Initialize the special nodes. */ - s = &pfile->spec_nodes; - s->n_L = cpp_lookup (pfile, DSC("L")); - s->n_defined = cpp_lookup (pfile, DSC("defined")); - s->n_true = cpp_lookup (pfile, DSC("true")); - s->n_false = cpp_lookup (pfile, DSC("false")); - s->n__STRICT_ANSI__ = cpp_lookup (pfile, DSC("__STRICT_ANSI__")); - s->n__CHAR_UNSIGNED__ = cpp_lookup (pfile, DSC("__CHAR_UNSIGNED__")); - s->n__VA_ARGS__ = cpp_lookup (pfile, DSC("__VA_ARGS__")); - s->n__VA_ARGS__->flags |= NODE_DIAGNOSTIC; return pfile; } @@ -704,7 +687,7 @@ static const struct builtin builtin_array[] = #define builtin_array_end \ builtin_array + sizeof(builtin_array)/sizeof(struct builtin) -/* Subroutine of cpp_start_read; reads the builtins table above and +/* Subroutine of cpp_read_main_file; reads the builtins table above and enters the macros into the hash table. */ static void init_builtins (pfile) @@ -916,14 +899,21 @@ free_chain (head) } } -/* This is called after options have been processed. Setup for - processing input from the file named FNAME, or stdin if it is the - empty string. Return 1 on success, 0 on failure. */ -int -cpp_start_read (pfile, fname) +/* This is called after options have been parsed, and partially + processed. Setup for processing input from the file named FNAME, + or stdin if it is the empty string. Return the original filename + on success (e.g. foo.i->foo.c), or NULL on failure. */ +const char * +cpp_read_main_file (pfile, fname, table) cpp_reader *pfile; const char *fname; + hash_table *table; { + /* The front ends don't set up the hash table until they have + finished processing the command line options, so initializing the + hashtable is deferred until now. */ + _cpp_init_hashtable (pfile, table); + /* Set up the include search path now. */ if (! CPP_OPTION (pfile, no_standard_includes)) init_standard_includes (pfile); @@ -948,16 +938,60 @@ cpp_start_read (pfile, fname) /* Set the default target (if there is none already). */ deps_add_default_target (pfile->deps, fname); - /* Open the main input file. This must be done early, so we have a - buffer to stand on. */ + /* Open the main input file. */ if (!_cpp_read_file (pfile, fname)) - return 0; + return NULL; /* Set this after cpp_post_options so the client can change the option if it wishes, and after stacking the main file so we don't trace the main file. */ pfile->line_maps.trace_includes = CPP_OPTION (pfile, print_include_names); + /* For foo.i, read the original filename foo.c now, for the benefit + of the front ends. */ + if (CPP_OPTION (pfile, preprocessed)) + read_original_filename (pfile); + + return pfile->map->to_file; +} + +/* For preprocessed files, if the first tokens are of the form # NUM. + handle the directive so we know the original file name. This will + generate file_change callbacks, which the front ends must handle + appropriately given their state of initialization. */ +static void +read_original_filename (pfile) + cpp_reader *pfile; +{ + const cpp_token *token, *token1; + + /* Lex ahead; if the first tokens are of the form # NUM, then + process the directive, otherwise back up. */ + token = _cpp_lex_direct (pfile); + if (token->type == CPP_HASH) + { + token1 = _cpp_lex_direct (pfile); + _cpp_backup_tokens (pfile, 1); + + /* If it's a #line directive, handle it. */ + if (token1->type == CPP_NUMBER) + { + _cpp_handle_directive (pfile, token->flags & PREV_WHITE); + return; + } + } + + /* Backup as if nothing happened. */ + _cpp_backup_tokens (pfile, 1); +} + +/* Handle pending command line options: -D, -U, -A, -imacros and + -include. This should be called after debugging has been properly + set up in the front ends. */ +void +cpp_finish_options (pfile) + cpp_reader *pfile; +{ /* Install builtins and process command line macros etc. in the order they appeared, but only if not already preprocessed. */ if (! CPP_OPTION (pfile, preprocessed)) @@ -986,8 +1020,6 @@ cpp_start_read (pfile, fname) free_chain (CPP_OPTION (pfile, pending)->directive_head); _cpp_push_next_buffer (pfile); - - return 1; } /* Called to push the next buffer on the stack given by -include. If |