diff options
author | brolley <brolley@138bc75d-0d04-0410-961f-82ee72b054a4> | 1998-06-10 10:12:36 +0000 |
---|---|---|
committer | brolley <brolley@138bc75d-0d04-0410-961f-82ee72b054a4> | 1998-06-10 10:12:36 +0000 |
commit | 11ce684d779b50cf49fa1a9216e55c2dca06b4fc (patch) | |
tree | 34e222e6636a47fccb9290f46b926d67612b47a9 | |
parent | 8af6f9d5e7604c51eb73a577fd40f5a9c441e454 (diff) | |
download | gcc-11ce684d779b50cf49fa1a9216e55c2dca06b4fc.tar.gz |
Integrate cpplib into the C and C++ front ends.
Wed Jun 10 13:07:02 1998 Dave Brolley <brolley@cygnus.com>
* objc/objc-act.c: Add cpplib declarations.
(lang_decode_option): Initialize cpplib if necessary.
(lang_decode_option): New argc/argv interface.
* tree.h (lang_decode_option): New argc/argv interface.
* toplev.c (lang_options): Add cpp options.
(main): New interface for lang_decode_option.
* gcc.c (default_compilers): Don't call cpp for a cpplib-enabled C compiler
unless -E, -M or -MM is specified.
* cpplib.h (cpp_handle_option): New function.
* cpplib.c (cpp_handle_option): New function.
(cpp_handle_options): Now calls cpp_handle_option.
* c-tree.h (c_decode_option): New argc/argv interface.
* c-lex.c (init_parse): cpplib now initialized in c_decode_option.
* c-lang.c (lang_decode_option): New argc/argv interface.
* c-decl.c: Add cpplib declarations.
(c_decode_option): New argc/argv interface.
(c_decode_option): Call cpp_handle_option.
(c_decode_option): Now returns number of strings processed.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@20407 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 21 | ||||
-rw-r--r-- | gcc/LANGUAGES | 7 | ||||
-rw-r--r-- | gcc/c-decl.c | 32 | ||||
-rw-r--r-- | gcc/c-lang.c | 7 | ||||
-rw-r--r-- | gcc/c-lex.c | 4 | ||||
-rw-r--r-- | gcc/c-tree.h | 2 | ||||
-rw-r--r-- | gcc/cpplib.c | 929 | ||||
-rw-r--r-- | gcc/cpplib.h | 1 | ||||
-rw-r--r-- | gcc/gcc.c | 47 | ||||
-rw-r--r-- | gcc/toplev.c | 23 | ||||
-rw-r--r-- | gcc/tree.h | 2 |
11 files changed, 600 insertions, 475 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index de58977765e..393f5b75a61 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,24 @@ +Wed Jun 10 13:07:02 1998 Dave Brolley <brolley@cygnus.com> + + * objc/objc-act.c: Add cpplib declarations. + (lang_decode_option): Initialize cpplib if necessary. + (lang_decode_option): New argc/argv interface. + * tree.h (lang_decode_option): New argc/argv interface. + * toplev.c (lang_options): Add cpp options. + (main): New interface for lang_decode_option. + * gcc.c (default_compilers): Don't call cpp for a cpplib-enabled C compiler + unless -E, -M or -MM is specified. + * cpplib.h (cpp_handle_option): New function. + * cpplib.c (cpp_handle_option): New function. + (cpp_handle_options): Now calls cpp_handle_option. + * c-tree.h (c_decode_option): New argc/argv interface. + * c-lex.c (init_parse): cpplib now initialized in c_decode_option. + * c-lang.c (lang_decode_option): New argc/argv interface. + * c-decl.c: Add cpplib declarations. + (c_decode_option): New argc/argv interface. + (c_decode_option): Call cpp_handle_option. + (c_decode_option): Now returns number of strings processed. + Wed Jun 10 09:47:13 1998 Richard Earnshaw (rearnsha@arm.com) * unroll.c (verify_addresses): Use validate_replace_rtx to undo the diff --git a/gcc/LANGUAGES b/gcc/LANGUAGES index a72b9e0c550..bce134ca9d9 100644 --- a/gcc/LANGUAGES +++ b/gcc/LANGUAGES @@ -6,6 +6,13 @@ time as we can formally start documenting the interface this file will serve as a repository for information on these interface and any incompatable changes we've made. +Jun 10, 1998: + The interface to lang_decode_option has changed. It now uses and argc/argv + interface to allow for options that use more than one input string. The new + declaration is: int lang_decode_option (int argc, char** argv). It now + returns the number of input strings processed, or 0 if the option is + unknown. + Jun 7, 1998: Front-ends must now define lang_init_options. It is safe for this function to do nothing. See c-lang.c. diff --git a/gcc/c-decl.c b/gcc/c-decl.c index bc8f61773f9..0f2a3f2ccac 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -35,6 +35,13 @@ Boston, MA 02111-1307, USA. */ #include "c-lex.h" #include "toplev.h" +#if USE_CPPLIB +#include "cpplib.h" +extern cpp_reader parse_in; +extern cpp_options parse_options; +static int cpp_initialized; +#endif + /* In grokdeclarator, distinguish syntactic contexts of declarators. */ enum decl_context { NORMAL, /* Ordinary declaration */ @@ -578,13 +585,28 @@ int warn_sign_compare = -1; int dollars_in_ident = DOLLARS_IN_IDENTIFIERS; /* Decode the string P as a language-specific option for C. - Return 1 if it is recognized (and handle it); - return 0 if not recognized. */ + Return the number of strings consumed. */ int -c_decode_option (p) - char *p; +c_decode_option (argc, argv) + int argc; + char **argv; { + int strings_processed; + char *p = argv[0]; +#if USE_CPPLIB + if (! cpp_initialized) + { + cpp_reader_init (&parse_in); + parse_in.data = &parse_options; + cpp_options_init (&parse_options); + cpp_initialized = 1; + } + strings_processed = cpp_handle_option (&parse_in, argc, argv); +#else + strings_processed = 0; +#endif /* ! USE_CPPLIB */ + if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional")) { flag_traditional = 1; @@ -799,7 +821,7 @@ c_decode_option (p) warn_unknown_pragmas = 1; } else - return 0; + return strings_processed; return 1; } diff --git a/gcc/c-lang.c b/gcc/c-lang.c index ebba1919680..4a21666cb17 100644 --- a/gcc/c-lang.c +++ b/gcc/c-lang.c @@ -31,10 +31,11 @@ Boston, MA 02111-1307, USA. */ is an alternative to a function in objc-actions.c. */ int -lang_decode_option (p) - char *p; +lang_decode_option (argc, argv) + int argc; + char **argv; { - return c_decode_option (p); + return c_decode_option (argc, argv); } void diff --git a/gcc/c-lex.c b/gcc/c-lex.c index 7612352fe02..840ad14b99b 100644 --- a/gcc/c-lex.c +++ b/gcc/c-lex.c @@ -200,10 +200,6 @@ init_parse (filename) yy_cur = "\n"; yy_lim = yy_cur+1; - cpp_reader_init (&parse_in); - parse_in.data = &parse_options; - cpp_options_init (&parse_options); - cpp_handle_options (&parse_in, 0, NULL); /* FIXME */ parse_in.show_column = 1; if (! cpp_start_read (&parse_in, filename)) abort (); diff --git a/gcc/c-tree.h b/gcc/c-tree.h index 6fa5c47742b..a2a76c032b8 100644 --- a/gcc/c-tree.h +++ b/gcc/c-tree.h @@ -263,7 +263,7 @@ extern tree build_enumerator PROTO((tree, tree)); extern tree builtin_function PROTO((char *, tree, enum built_in_function function_, char *)); /* Add qualifiers to a type, in the fashion for C. */ extern tree c_build_type_variant PROTO((tree, int, int)); -extern int c_decode_option PROTO((char *)); +extern int c_decode_option PROTO((int, char **)); extern void c_mark_varargs PROTO((void)); extern tree check_identifier PROTO((tree, tree)); extern void clear_parm_order PROTO((void)); diff --git a/gcc/cpplib.c b/gcc/cpplib.c index 6084d3f6cb2..e29de4a2ab5 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -6234,507 +6234,526 @@ push_pending (pfile, cmd, arg) CPP_OPTIONS (pfile)->pending = pend; } -/* Handle command-line options in (argc, argv). +/* Handle one command-line option in (argc, argv). Can be called multiple times, to handle multiple sets of options. - Returns if an unrecognized option is seen. - Returns number of handled arguments. */ - + Returns number of strings consumed. */ int -cpp_handle_options (pfile, argc, argv) +cpp_handle_option (pfile, argc, argv) cpp_reader *pfile; int argc; char **argv; { - int i; struct cpp_options *opts = CPP_OPTIONS (pfile); - for (i = 0; i < argc; i++) { - if (argv[i][0] != '-') { - if (opts->out_fname != NULL) - { - cpp_fatal (pfile, "Usage: %s [switches] input output", argv[0]); - return argc; - } - else if (opts->in_fname != NULL) - opts->out_fname = argv[i]; - else - opts->in_fname = argv[i]; - } else { - switch (argv[i][1]) { - - missing_filename: - cpp_fatal (pfile, "Filename missing after `%s' option", argv[i]); - return argc; - missing_dirname: - cpp_fatal (pfile, "Directory name missing after `%s' option", argv[i]); + int i = 0; + if (argv[i][0] != '-') { + if (opts->out_fname != NULL) + { + cpp_fatal (pfile, "Usage: %s [switches] input output", argv[0]); return argc; - - case 'i': - if (!strcmp (argv[i], "-include") - || !strcmp (argv[i], "-imacros")) { - if (i + 1 == argc) - goto missing_filename; - else - push_pending (pfile, argv[i], argv[i+1]), i++; - } - if (!strcmp (argv[i], "-iprefix")) { - if (i + 1 == argc) - goto missing_filename; - else - opts->include_prefix = argv[++i]; - } - if (!strcmp (argv[i], "-ifoutput")) { - opts->output_conditionals = 1; - } - if (!strcmp (argv[i], "-isystem")) { - struct file_name_list *dirtmp; - - if (i + 1 == argc) - goto missing_filename; - - dirtmp = (struct file_name_list *) - xmalloc (sizeof (struct file_name_list)); - dirtmp->next = 0; - dirtmp->control_macro = 0; - dirtmp->c_system_include_path = 1; - dirtmp->fname = (char *) xmalloc (strlen (argv[i+1]) + 1); - strcpy (dirtmp->fname, argv[++i]); - dirtmp->got_name_map = 0; - - if (opts->before_system == 0) - opts->before_system = dirtmp; - else - opts->last_before_system->next = dirtmp; - opts->last_before_system = dirtmp; /* Tail follows the last one */ - } - /* Add directory to end of path for includes, - with the default prefix at the front of its name. */ - if (!strcmp (argv[i], "-iwithprefix")) { - struct file_name_list *dirtmp; - char *prefix; - - if (opts->include_prefix != 0) - prefix = opts->include_prefix; - else { - prefix = savestring (GCC_INCLUDE_DIR); - /* Remove the `include' from /usr/local/lib/gcc.../include. */ - if (!strcmp (prefix + strlen (prefix) - 8, "/include")) - prefix[strlen (prefix) - 7] = 0; - } - - dirtmp = (struct file_name_list *) - xmalloc (sizeof (struct file_name_list)); - dirtmp->next = 0; /* New one goes on the end */ - dirtmp->control_macro = 0; - dirtmp->c_system_include_path = 0; - if (i + 1 == argc) - goto missing_dirname; - - dirtmp->fname = (char *) xmalloc (strlen (argv[i+1]) - + strlen (prefix) + 1); - strcpy (dirtmp->fname, prefix); - strcat (dirtmp->fname, argv[++i]); - dirtmp->got_name_map = 0; - - if (opts->after_include == 0) - opts->after_include = dirtmp; - else - opts->last_after_include->next = dirtmp; - opts->last_after_include = dirtmp; /* Tail follows the last one */ - } - /* Add directory to main path for includes, - with the default prefix at the front of its name. */ - if (!strcmp (argv[i], "-iwithprefixbefore")) { - struct file_name_list *dirtmp; - char *prefix; - - if (opts->include_prefix != 0) - prefix = opts->include_prefix; - else { - prefix = savestring (GCC_INCLUDE_DIR); - /* Remove the `include' from /usr/local/lib/gcc.../include. */ - if (!strcmp (prefix + strlen (prefix) - 8, "/include")) - prefix[strlen (prefix) - 7] = 0; - } - - dirtmp = (struct file_name_list *) - xmalloc (sizeof (struct file_name_list)); - dirtmp->next = 0; /* New one goes on the end */ - dirtmp->control_macro = 0; - dirtmp->c_system_include_path = 0; - if (i + 1 == argc) - goto missing_dirname; - - dirtmp->fname = (char *) xmalloc (strlen (argv[i+1]) - + strlen (prefix) + 1); - strcpy (dirtmp->fname, prefix); - strcat (dirtmp->fname, argv[++i]); - dirtmp->got_name_map = 0; - - append_include_chain (pfile, dirtmp, dirtmp); + } + else if (opts->in_fname != NULL) + opts->out_fname = argv[i]; + else + opts->in_fname = argv[i]; + } else { + switch (argv[i][1]) { + + missing_filename: + cpp_fatal (pfile, "Filename missing after `%s' option", argv[i]); + return argc; + missing_dirname: + cpp_fatal (pfile, "Directory name missing after `%s' option", argv[i]); + return argc; + + case 'i': + if (!strcmp (argv[i], "-include") + || !strcmp (argv[i], "-imacros")) { + if (i + 1 == argc) + goto missing_filename; + else + push_pending (pfile, argv[i], argv[i+1]), i++; + } + if (!strcmp (argv[i], "-iprefix")) { + if (i + 1 == argc) + goto missing_filename; + else + opts->include_prefix = argv[++i]; + } + if (!strcmp (argv[i], "-ifoutput")) { + opts->output_conditionals = 1; + } + if (!strcmp (argv[i], "-isystem")) { + struct file_name_list *dirtmp; + + if (i + 1 == argc) + goto missing_filename; + + dirtmp = (struct file_name_list *) + xmalloc (sizeof (struct file_name_list)); + dirtmp->next = 0; + dirtmp->control_macro = 0; + dirtmp->c_system_include_path = 1; + dirtmp->fname = (char *) xmalloc (strlen (argv[i+1]) + 1); + strcpy (dirtmp->fname, argv[++i]); + dirtmp->got_name_map = 0; + + if (opts->before_system == 0) + opts->before_system = dirtmp; + else + opts->last_before_system->next = dirtmp; + opts->last_before_system = dirtmp; /* Tail follows the last one */ + } + /* Add directory to end of path for includes, + with the default prefix at the front of its name. */ + if (!strcmp (argv[i], "-iwithprefix")) { + struct file_name_list *dirtmp; + char *prefix; + + if (opts->include_prefix != 0) + prefix = opts->include_prefix; + else { + prefix = savestring (GCC_INCLUDE_DIR); + /* Remove the `include' from /usr/local/lib/gcc.../include. */ + if (!strcmp (prefix + strlen (prefix) - 8, "/include")) + prefix[strlen (prefix) - 7] = 0; } - /* Add directory to end of path for includes. */ - if (!strcmp (argv[i], "-idirafter")) { - struct file_name_list *dirtmp; - - dirtmp = (struct file_name_list *) - xmalloc (sizeof (struct file_name_list)); - dirtmp->next = 0; /* New one goes on the end */ - dirtmp->control_macro = 0; - dirtmp->c_system_include_path = 0; - if (i + 1 == argc) - goto missing_dirname; - else - dirtmp->fname = argv[++i]; - dirtmp->got_name_map = 0; - - if (opts->after_include == 0) - opts->after_include = dirtmp; - else - opts->last_after_include->next = dirtmp; - opts->last_after_include = dirtmp; /* Tail follows the last one */ + + dirtmp = (struct file_name_list *) + xmalloc (sizeof (struct file_name_list)); + dirtmp->next = 0; /* New one goes on the end */ + dirtmp->control_macro = 0; + dirtmp->c_system_include_path = 0; + if (i + 1 == argc) + goto missing_dirname; + + dirtmp->fname = (char *) xmalloc (strlen (argv[i+1]) + + strlen (prefix) + 1); + strcpy (dirtmp->fname, prefix); + strcat (dirtmp->fname, argv[++i]); + dirtmp->got_name_map = 0; + + if (opts->after_include == 0) + opts->after_include = dirtmp; + else + opts->last_after_include->next = dirtmp; + opts->last_after_include = dirtmp; /* Tail follows the last one */ + } + /* Add directory to main path for includes, + with the default prefix at the front of its name. */ + if (!strcmp (argv[i], "-iwithprefixbefore")) { + struct file_name_list *dirtmp; + char *prefix; + + if (opts->include_prefix != 0) + prefix = opts->include_prefix; + else { + prefix = savestring (GCC_INCLUDE_DIR); + /* Remove the `include' from /usr/local/lib/gcc.../include. */ + if (!strcmp (prefix + strlen (prefix) - 8, "/include")) + prefix[strlen (prefix) - 7] = 0; } - break; - - case 'o': - if (opts->out_fname != NULL) - { - cpp_fatal (pfile, "Output filename specified twice"); - return argc; - } + + dirtmp = (struct file_name_list *) + xmalloc (sizeof (struct file_name_list)); + dirtmp->next = 0; /* New one goes on the end */ + dirtmp->control_macro = 0; + dirtmp->c_system_include_path = 0; if (i + 1 == argc) - goto missing_filename; - opts->out_fname = argv[++i]; - if (!strcmp (opts->out_fname, "-")) - opts->out_fname = ""; - break; - - case 'p': - if (!strcmp (argv[i], "-pedantic")) - CPP_PEDANTIC (pfile) = 1; - else if (!strcmp (argv[i], "-pedantic-errors")) { - CPP_PEDANTIC (pfile) = 1; - opts->pedantic_errors = 1; + goto missing_dirname; + + dirtmp->fname = (char *) xmalloc (strlen (argv[i+1]) + + strlen (prefix) + 1); + strcpy (dirtmp->fname, prefix); + strcat (dirtmp->fname, argv[++i]); + dirtmp->got_name_map = 0; + + append_include_chain (pfile, dirtmp, dirtmp); + } + /* Add directory to end of path for includes. */ + if (!strcmp (argv[i], "-idirafter")) { + struct file_name_list *dirtmp; + + dirtmp = (struct file_name_list *) + xmalloc (sizeof (struct file_name_list)); + dirtmp->next = 0; /* New one goes on the end */ + dirtmp->control_macro = 0; + dirtmp->c_system_include_path = 0; + if (i + 1 == argc) + goto missing_dirname; + else + dirtmp->fname = argv[++i]; + dirtmp->got_name_map = 0; + + if (opts->after_include == 0) + opts->after_include = dirtmp; + else + opts->last_after_include->next = dirtmp; + opts->last_after_include = dirtmp; /* Tail follows the last one */ + } + break; + + case 'o': + if (opts->out_fname != NULL) + { + cpp_fatal (pfile, "Output filename specified twice"); + return argc; } + if (i + 1 == argc) + goto missing_filename; + opts->out_fname = argv[++i]; + if (!strcmp (opts->out_fname, "-")) + opts->out_fname = ""; + break; + + case 'p': + if (!strcmp (argv[i], "-pedantic")) + CPP_PEDANTIC (pfile) = 1; + else if (!strcmp (argv[i], "-pedantic-errors")) { + CPP_PEDANTIC (pfile) = 1; + opts->pedantic_errors = 1; + } #if 0 - else if (!strcmp (argv[i], "-pcp")) { - char *pcp_fname = argv[++i]; - pcp_outfile = ((pcp_fname[0] != '-' || pcp_fname[1] != '\0') - ? fopen (pcp_fname, "w") - : fdopen (dup (fileno (stdout)), "w")); - if (pcp_outfile == 0) - cpp_pfatal_with_name (pfile, pcp_fname); - no_precomp = 1; - } + else if (!strcmp (argv[i], "-pcp")) { + char *pcp_fname = argv[++i]; + pcp_outfile = ((pcp_fname[0] != '-' || pcp_fname[1] != '\0') + ? fopen (pcp_fname, "w") + : fdopen (dup (fileno (stdout)), "w")); + if (pcp_outfile == 0) + cpp_pfatal_with_name (pfile, pcp_fname); + no_precomp = 1; + } #endif - break; - - case 't': - if (!strcmp (argv[i], "-traditional")) { - opts->traditional = 1; - } else if (!strcmp (argv[i], "-trigraphs")) { - if (!opts->chill) - opts->no_trigraphs = 0; - } - break; - - case 'l': - if (! strcmp (argv[i], "-lang-c")) - opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->c89 = 0, + break; + + case 't': + if (!strcmp (argv[i], "-traditional")) { + opts->traditional = 1; + } else if (!strcmp (argv[i], "-trigraphs")) { + if (!opts->chill) + opts->no_trigraphs = 0; + } + break; + + case 'l': + if (! strcmp (argv[i], "-lang-c")) + opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->c89 = 0, opts->objc = 0; - if (! strcmp (argv[i], "-lang-c89")) - opts->cplusplus = 0, opts->cplusplus_comments = 0, opts->c89 = 1, + if (! strcmp (argv[i], "-lang-c89")) + opts->cplusplus = 0, opts->cplusplus_comments = 0, opts->c89 = 1, opts->objc = 0; - if (! strcmp (argv[i], "-lang-c++")) - opts->cplusplus = 1, opts->cplusplus_comments = 1, opts->c89 = 0, + if (! strcmp (argv[i], "-lang-c++")) + opts->cplusplus = 1, opts->cplusplus_comments = 1, opts->c89 = 0, opts->objc = 0; - if (! strcmp (argv[i], "-lang-objc")) - opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->c89 = 0, + if (! strcmp (argv[i], "-lang-objc")) + opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->c89 = 0, opts->objc = 1; - if (! strcmp (argv[i], "-lang-objc++")) - opts->cplusplus = 1, opts->cplusplus_comments = 1, opts->c89 = 0, + if (! strcmp (argv[i], "-lang-objc++")) + opts->cplusplus = 1, opts->cplusplus_comments = 1, opts->c89 = 0, opts->objc = 1; - if (! strcmp (argv[i], "-lang-asm")) - opts->lang_asm = 1; - if (! strcmp (argv[i], "-lint")) - opts->for_lint = 1; - if (! strcmp (argv[i], "-lang-chill")) - opts->objc = 0, opts->cplusplus = 0, opts->chill = 1, + if (! strcmp (argv[i], "-lang-asm")) + opts->lang_asm = 1; + if (! strcmp (argv[i], "-lint")) + opts->for_lint = 1; + if (! strcmp (argv[i], "-lang-chill")) + opts->objc = 0, opts->cplusplus = 0, opts->chill = 1, opts->traditional = 1, opts->no_trigraphs = 1; - break; - - case '+': - opts->cplusplus = 1, opts->cplusplus_comments = 1; - break; - - case 'w': - opts->inhibit_warnings = 1; - break; - - case 'W': - if (!strcmp (argv[i], "-Wtrigraphs")) + break; + + case '+': + opts->cplusplus = 1, opts->cplusplus_comments = 1; + break; + + case 'w': + opts->inhibit_warnings = 1; + break; + + case 'W': + if (!strcmp (argv[i], "-Wtrigraphs")) + opts->warn_trigraphs = 1; + else if (!strcmp (argv[i], "-Wno-trigraphs")) + opts->warn_trigraphs = 0; + else if (!strcmp (argv[i], "-Wcomment")) + opts->warn_comments = 1; + else if (!strcmp (argv[i], "-Wno-comment")) + opts->warn_comments = 0; + else if (!strcmp (argv[i], "-Wcomments")) + opts->warn_comments = 1; + else if (!strcmp (argv[i], "-Wno-comments")) + opts->warn_comments = 0; + else if (!strcmp (argv[i], "-Wtraditional")) + opts->warn_stringify = 1; + else if (!strcmp (argv[i], "-Wno-traditional")) + opts->warn_stringify = 0; + else if (!strcmp (argv[i], "-Wundef")) + opts->warn_undef = 1; + else if (!strcmp (argv[i], "-Wno-undef")) + opts->warn_undef = 0; + else if (!strcmp (argv[i], "-Wimport")) + opts->warn_import = 1; + else if (!strcmp (argv[i], "-Wno-import")) + opts->warn_import = 0; + else if (!strcmp (argv[i], "-Werror")) + opts->warnings_are_errors = 1; + else if (!strcmp (argv[i], "-Wno-error")) + opts->warnings_are_errors = 0; + else if (!strcmp (argv[i], "-Wall")) + { opts->warn_trigraphs = 1; - else if (!strcmp (argv[i], "-Wno-trigraphs")) - opts->warn_trigraphs = 0; - else if (!strcmp (argv[i], "-Wcomment")) - opts->warn_comments = 1; - else if (!strcmp (argv[i], "-Wno-comment")) - opts->warn_comments = 0; - else if (!strcmp (argv[i], "-Wcomments")) opts->warn_comments = 1; - else if (!strcmp (argv[i], "-Wno-comments")) - opts->warn_comments = 0; - else if (!strcmp (argv[i], "-Wtraditional")) - opts->warn_stringify = 1; - else if (!strcmp (argv[i], "-Wno-traditional")) - opts->warn_stringify = 0; - else if (!strcmp (argv[i], "-Wundef")) - opts->warn_undef = 1; - else if (!strcmp (argv[i], "-Wno-undef")) - opts->warn_undef = 0; - else if (!strcmp (argv[i], "-Wimport")) - opts->warn_import = 1; - else if (!strcmp (argv[i], "-Wno-import")) - opts->warn_import = 0; - else if (!strcmp (argv[i], "-Werror")) - opts->warnings_are_errors = 1; - else if (!strcmp (argv[i], "-Wno-error")) - opts->warnings_are_errors = 0; - else if (!strcmp (argv[i], "-Wall")) - { - opts->warn_trigraphs = 1; - opts->warn_comments = 1; - } - break; - - case 'M': - /* The style of the choices here is a bit mixed. - The chosen scheme is a hybrid of keeping all options in one string - and specifying each option in a separate argument: - -M|-MM|-MD file|-MMD file [-MG]. An alternative is: - -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely: - -M[M][G][D file]. This is awkward to handle in specs, and is not - as extensible. */ - /* ??? -MG must be specified in addition to one of -M or -MM. - This can be relaxed in the future without breaking anything. - The converse isn't true. */ - - /* -MG isn't valid with -MD or -MMD. This is checked for later. */ - if (!strcmp (argv[i], "-MG")) - { - opts->print_deps_missing_files = 1; - break; - } - if (!strcmp (argv[i], "-M")) - opts->print_deps = 2; - else if (!strcmp (argv[i], "-MM")) - opts->print_deps = 1; - else if (!strcmp (argv[i], "-MD")) - opts->print_deps = 2; - else if (!strcmp (argv[i], "-MMD")) - opts->print_deps = 1; - /* For -MD and -MMD options, write deps on file named by next arg. */ - if (!strcmp (argv[i], "-MD") || !strcmp (argv[i], "-MMD")) - { - if (i+1 == argc) - goto missing_filename; - opts->deps_file = argv[++i]; - } - else - { - /* For -M and -MM, write deps on standard output - and suppress the usual output. */ - opts->no_output = 1; - } - break; - - case 'd': + } + break; + + case 'M': + /* The style of the choices here is a bit mixed. + The chosen scheme is a hybrid of keeping all options in one string + and specifying each option in a separate argument: + -M|-MM|-MD file|-MMD file [-MG]. An alternative is: + -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely: + -M[M][G][D file]. This is awkward to handle in specs, and is not + as extensible. */ + /* ??? -MG must be specified in addition to one of -M or -MM. + This can be relaxed in the future without breaking anything. + The converse isn't true. */ + + /* -MG isn't valid with -MD or -MMD. This is checked for later. */ + if (!strcmp (argv[i], "-MG")) { - char *p = argv[i] + 2; - char c; - while ((c = *p++) != 0) { - /* Arg to -d specifies what parts of macros to dump */ - switch (c) { - case 'M': - opts->dump_macros = dump_only; - opts->no_output = 1; - break; - case 'N': - opts->dump_macros = dump_names; - break; - case 'D': - opts->dump_macros = dump_definitions; - break; - case 'I': - opts->dump_includes = 1; - break; - } + opts->print_deps_missing_files = 1; + break; + } + if (!strcmp (argv[i], "-M")) + opts->print_deps = 2; + else if (!strcmp (argv[i], "-MM")) + opts->print_deps = 1; + else if (!strcmp (argv[i], "-MD")) + opts->print_deps = 2; + else if (!strcmp (argv[i], "-MMD")) + opts->print_deps = 1; + /* For -MD and -MMD options, write deps on file named by next arg. */ + if (!strcmp (argv[i], "-MD") || !strcmp (argv[i], "-MMD")) + { + if (i+1 == argc) + goto missing_filename; + opts->deps_file = argv[++i]; + } + else + { + /* For -M and -MM, write deps on standard output + and suppress the usual output. */ + opts->no_output = 1; + } + break; + + case 'd': + { + char *p = argv[i] + 2; + char c; + while ((c = *p++) != 0) { + /* Arg to -d specifies what parts of macros to dump */ + switch (c) { + case 'M': + opts->dump_macros = dump_only; + opts->no_output = 1; + break; + case 'N': + opts->dump_macros = dump_names; + break; + case 'D': + opts->dump_macros = dump_definitions; + break; + case 'I': + opts->dump_includes = 1; + break; } } - break; - - case 'g': - if (argv[i][2] == '3') - opts->debug_output = 1; - break; - - case 'v': - fprintf (stderr, "GNU CPP version %s", version_string); + } + break; + + case 'g': + if (argv[i][2] == '3') + opts->debug_output = 1; + break; + + case 'v': + fprintf (stderr, "GNU CPP version %s", version_string); #ifdef TARGET_VERSION - TARGET_VERSION; + TARGET_VERSION; #endif - fprintf (stderr, "\n"); - opts->verbose = 1; - break; - - case 'H': - opts->print_include_names = 1; - break; - - case 'D': + fprintf (stderr, "\n"); + opts->verbose = 1; + break; + + case 'H': + opts->print_include_names = 1; + break; + + case 'D': + if (argv[i][2] != 0) + push_pending (pfile, "-D", argv[i] + 2); + else if (i + 1 == argc) + { + cpp_fatal (pfile, "Macro name missing after -D option"); + return argc; + } + else + i++, push_pending (pfile, "-D", argv[i]); + break; + + case 'A': + { + char *p; + if (argv[i][2] != 0) - push_pending (pfile, "-D", argv[i] + 2); + p = argv[i] + 2; else if (i + 1 == argc) { - cpp_fatal (pfile, "Macro name missing after -D option"); + cpp_fatal (pfile, "Assertion missing after -A option"); return argc; } else - i++, push_pending (pfile, "-D", argv[i]); - break; - - case 'A': - { - char *p; - - if (argv[i][2] != 0) - p = argv[i] + 2; - else if (i + 1 == argc) + p = argv[++i]; + + if (!strcmp (p, "-")) { + struct cpp_pending **ptr; + /* -A- eliminates all predefined macros and assertions. + Let's include also any that were specified earlier + on the command line. That way we can get rid of any + that were passed automatically in from GCC. */ + opts->inhibit_predefs = 1; + for (ptr = &opts->pending; *ptr != NULL; ) { - cpp_fatal (pfile, "Assertion missing after -A option"); - return argc; + struct cpp_pending *pend = *ptr; + if (pend->cmd && pend->cmd[0] == '-' + && (pend->cmd[1] == 'D' || pend->cmd[1] == 'A')) + { + *ptr = pend->next; + free (pend); + } + else + ptr = &pend->next; } - else - p = argv[++i]; - - if (!strcmp (p, "-")) { - struct cpp_pending **ptr; - /* -A- eliminates all predefined macros and assertions. - Let's include also any that were specified earlier - on the command line. That way we can get rid of any - that were passed automatically in from GCC. */ - opts->inhibit_predefs = 1; - for (ptr = &opts->pending; *ptr != NULL; ) - { - struct cpp_pending *pend = *ptr; - if (pend->cmd && pend->cmd[0] == '-' - && (pend->cmd[1] == 'D' || pend->cmd[1] == 'A')) - { - *ptr = pend->next; - free (pend); - } - else - ptr = &pend->next; - } - } else { - push_pending (pfile, "-A", p); - } + } else { + push_pending (pfile, "-A", p); } - break; - - case 'U': /* JF #undef something */ - if (argv[i][2] != 0) - push_pending (pfile, "-U", argv[i] + 2); - else if (i + 1 == argc) - { - cpp_fatal (pfile, "Macro name missing after -U option"); - return argc; - } - else - push_pending (pfile, "-U", argv[i+1]), i++; - break; - - case 'C': - opts->put_out_comments = 1; - break; - - case 'E': /* -E comes from cc -E; ignore it. */ - break; - - case 'P': - opts->no_line_commands = 1; - break; - - case '$': /* Don't include $ in identifiers. */ - opts->dollars_in_ident = 0; - break; - - case 'I': /* Add directory to path for includes. */ + } + break; + + case 'U': /* JF #undef something */ + if (argv[i][2] != 0) + push_pending (pfile, "-U", argv[i] + 2); + else if (i + 1 == argc) { - struct file_name_list *dirtmp; - - if (! CPP_OPTIONS(pfile)->ignore_srcdir - && !strcmp (argv[i] + 2, "-")) { - CPP_OPTIONS (pfile)->ignore_srcdir = 1; - /* Don't use any preceding -I directories for #include <...>. */ - CPP_OPTIONS (pfile)->first_bracket_include = 0; - } - else { - dirtmp = (struct file_name_list *) - xmalloc (sizeof (struct file_name_list)); - dirtmp->next = 0; /* New one goes on the end */ - dirtmp->control_macro = 0; - dirtmp->c_system_include_path = 0; - if (argv[i][2] != 0) - dirtmp->fname = argv[i] + 2; - else if (i + 1 == argc) - goto missing_dirname; - else - dirtmp->fname = argv[++i]; - dirtmp->got_name_map = 0; - append_include_chain (pfile, dirtmp, dirtmp); - } + cpp_fatal (pfile, "Macro name missing after -U option", NULL); + return argc; } - break; - - case 'n': - if (!strcmp (argv[i], "-nostdinc")) - /* -nostdinc causes no default include directories. - You must specify all include-file directories with -I. */ - opts->no_standard_includes = 1; - else if (!strcmp (argv[i], "-nostdinc++")) - /* -nostdinc++ causes no default C++-specific include directories. */ - opts->no_standard_cplusplus_includes = 1; + else + push_pending (pfile, "-U", argv[i+1]), i++; + break; + + case 'C': + opts->put_out_comments = 1; + break; + + case 'E': /* -E comes from cc -E; ignore it. */ + break; + + case 'P': + opts->no_line_commands = 1; + break; + + case '$': /* Don't include $ in identifiers. */ + opts->dollars_in_ident = 0; + break; + + case 'I': /* Add directory to path for includes. */ + { + struct file_name_list *dirtmp; + + if (! CPP_OPTIONS(pfile)->ignore_srcdir + && !strcmp (argv[i] + 2, "-")) { + CPP_OPTIONS (pfile)->ignore_srcdir = 1; + /* Don't use any preceding -I directories for #include <...>. */ + CPP_OPTIONS (pfile)->first_bracket_include = 0; + } + else { + dirtmp = (struct file_name_list *) + xmalloc (sizeof (struct file_name_list)); + dirtmp->next = 0; /* New one goes on the end */ + dirtmp->control_macro = 0; + dirtmp->c_system_include_path = 0; + if (argv[i][2] != 0) + dirtmp->fname = argv[i] + 2; + else if (i + 1 == argc) + goto missing_dirname; + else + dirtmp->fname = argv[++i]; + dirtmp->got_name_map = 0; + append_include_chain (pfile, dirtmp, dirtmp); + } + } + break; + + case 'n': + if (!strcmp (argv[i], "-nostdinc")) + /* -nostdinc causes no default include directories. + You must specify all include-file directories with -I. */ + opts->no_standard_includes = 1; + else if (!strcmp (argv[i], "-nostdinc++")) + /* -nostdinc++ causes no default C++-specific include directories. */ + opts->no_standard_cplusplus_includes = 1; #if 0 - else if (!strcmp (argv[i], "-noprecomp")) - no_precomp = 1; + else if (!strcmp (argv[i], "-noprecomp")) + no_precomp = 1; #endif + break; + + case 'r': + if (!strcmp (argv[i], "-remap")) + opts->remap = 1; + break; + + case 'u': + /* Sun compiler passes undocumented switch "-undef". + Let's assume it means to inhibit the predefined symbols. */ + opts->inhibit_predefs = 1; + break; + + case '\0': /* JF handle '-' as file name meaning stdin or stdout */ + if (opts->in_fname == NULL) { + opts->in_fname = ""; break; - - case 'r': - if (!strcmp (argv[i], "-remap")) - opts->remap = 1; + } else if (opts->out_fname == NULL) { + opts->out_fname = ""; break; + } /* else fall through into error */ + + default: + return i; + } + } - case 'u': - /* Sun compiler passes undocumented switch "-undef". - Let's assume it means to inhibit the predefined symbols. */ - opts->inhibit_predefs = 1; - break; + return i + 1; +} - case '\0': /* JF handle '-' as file name meaning stdin or stdout */ - if (opts->in_fname == NULL) { - opts->in_fname = ""; - break; - } else if (opts->out_fname == NULL) { - opts->out_fname = ""; - break; - } /* else fall through into error */ +/* Handle command-line options in (argc, argv). + Can be called multiple times, to handle multiple sets of options. + Returns if an unrecognized option is seen. + Returns number of strings consumed. */ - default: - return i; - } +int +cpp_handle_options (pfile, argc, argv) + cpp_reader *pfile; + int argc; + char **argv; +{ + int i; + int strings_processed; + for (i = 0; i < argc; i += strings_processed) + { + strings_processed = cpp_handle_option (pfile, argc - i, argv + i); + if (strings_processed == 0) + break; } - } return i; } diff --git a/gcc/cpplib.h b/gcc/cpplib.h index 37468dd0a69..e6a32954124 100644 --- a/gcc/cpplib.h +++ b/gcc/cpplib.h @@ -94,6 +94,7 @@ extern void parse_clear_mark PARAMS ((struct parse_marker *)); extern void parse_goto_mark PARAMS((struct parse_marker *, cpp_reader *)); extern void parse_move_mark PARAMS((struct parse_marker *, cpp_reader *)); +extern int cpp_handle_option PARAMS ((cpp_reader *, int, char **)); extern int cpp_handle_options PARAMS ((cpp_reader *, int, char **)); extern enum cpp_token cpp_get_token PARAMS ((cpp_reader *)); extern void cpp_skip_hspace PARAMS((cpp_reader *)); diff --git a/gcc/gcc.c b/gcc/gcc.c index 9e2be41f142..606fb7d9001 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -597,7 +597,46 @@ static struct compiler default_compilers[] = /* Next come the entries for C. */ {".c", {"@c"}}, {"@c", - {"cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\ + { +#if USE_CPPLIB +#define CPP_FOR_C \ + "cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\ + %{C:%{!E:%eGNU C does not support -C without using -E}}\ + %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\ + -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\ + %{ansi:-trigraphs -D__STRICT_ANSI__}\ + %{!undef:%{!ansi:%p} %P} %{trigraphs} \ + %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\ + %{traditional} %{ftraditional:-traditional}\ + %{traditional-cpp:-traditional}\ + %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\ + %i %{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}}\n" + + "%{E:"CPP_FOR_C"}" + "%{!E:%{M:"CPP_FOR_C"}" + "%{!M:%{MM:"CPP_FOR_C"}" + "%{!MM:cc1 %i %1 \ + -lang-c%{ansi:89} %{nostdinc*} %{A*} %{I*} %I\ + %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\ + %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\ + -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\ + %{ansi:-trigraphs -D__STRICT_ANSI__}\ + %{!undef:%{!ansi:%p} %P} %{trigraphs} \ + %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\ + %{H} %C %{D*} %{U*} %{i*} %Z\ + %{ftraditional:-traditional}\ + %{traditional-cpp:-traditional}\ + %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\ + %{aux-info*}\ + %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \ + %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\ + %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\ + %{!S:as %a %Y\ + %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\ + %{!pipe:%g.s} %A\n }}}}" + }}, +#else /* ! USE_CPPLIB */ + "cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\ %{C:%{!E:%eGNU C does not support -C without using -E}}\ %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\ -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\ @@ -608,7 +647,7 @@ static struct compiler default_compilers[] = %{traditional-cpp:-traditional}\ %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\ %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n", - "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \ + "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \ %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\ %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \ %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\ @@ -617,7 +656,9 @@ static struct compiler default_compilers[] = %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\ %{!S:as %a %Y\ %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\ - %{!pipe:%g.s} %A\n }}}}"}}, + %{!pipe:%g.s} %A\n }}}}" + }}, +#endif /* ! USE_CPPLIB */ {"-", {"%{E:cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\ %{C:%{!E:%eGNU C does not support -C without using -E}}\ diff --git a/gcc/toplev.c b/gcc/toplev.c index f68c9add1ec..d4c57cb52d0 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -894,6 +894,19 @@ char *lang_options[] = "-Wno-protocol", "-print-objc-runtime-info", + /* These are for languages with USE_CPPLIB. */ + "-A", + "-D", + "-I", + "-iprefix", + "-isystem", + "-lang-c", + "-lang-c89", + "-lang-c++", + "-nostdinc++", + "-U", + "-undef", + #include "options.h" 0 }; @@ -3853,9 +3866,13 @@ main (argc, argv, envp) strlen (lang_options[j]))) break; if (lang_options[j] != 0) - /* If the option is valid for *some* language, - treat it as valid even if this language doesn't understand it. */ - lang_decode_option (argv[i]); + { + /* If the option is valid for *some* language, + treat it as valid even if this language doesn't understand it. */ + int strings_processed = lang_decode_option (argc - i, argv + i); + if (strings_processed != 0) + i += strings_processed - 1; + } else if (argv[i][0] == '-' && argv[i][1] != 0) { register char *str = argv[i] + 1; diff --git a/gcc/tree.h b/gcc/tree.h index c7779dd7bfd..3a89122eab6 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -1967,7 +1967,7 @@ extern int yyparse PROTO((void)); /* Function called with option as argument to decode options starting with -f or -W or +. It should return nonzero if it handles the option. */ -extern int lang_decode_option PROTO((char *)); +extern int lang_decode_option PROTO((int, char **)); /* Functions for processing symbol declarations. */ /* Function to enter a new lexical scope. |