This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

cpplib: Start moving switch handling to front ends


This does all the -W and -f options that cpplib understands.  I don't
believe any are used by fix-header, so this is safe.  When I move
-D, -U etc. fix-header will need to be updated to handle them itself.

Bootstrapping x86 Linux, I'll apply it if successful.

Neil.

	* c-opts.c (cpp_opts): New.
	(COMMAND_LINE_OPTIONS): Add switches from cppinit.c.
	(c_common_decode_options): Handle cpplib switches.
	(c_common_init_options): Set cpp_opts.
	* cppinit.c (COMMAND_LINE_OPTIONS): Move some switches to c-opts.c.
	(cpp_handle_option): Similarly.

Index: c-opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-opts.c,v
retrieving revision 1.1
diff -u -p -r1.1 c-opts.c
--- c-opts.c	7 Aug 2002 18:32:07 -0000	1.1
+++ c-opts.c	7 Aug 2002 21:13:11 -0000
@@ -30,6 +30,8 @@ Software Foundation, 59 Temple Place - S
 #include "tree-inline.h"
 #include "diagnostic.h"
 
+static cpp_options *cpp_opts;
+
 static void missing_arg PARAMS ((size_t));
 static size_t parse_option PARAMS ((const char *, int));
 static void set_Wimplicit PARAMS ((int));
@@ -52,24 +54,42 @@ static void write_langs PARAMS ((char *,
 /* This is the list of all command line options, with the leading "-"
    removed.  It must be sorted in ASCII collating order.  All options
    beginning with "f" or "W" are implicitly assumed to take a "no-"
-   form; this form should not be listed.  If you don't want a "no-"
-   form, your handler should check and reject it.
+   form; this form should not be listed.  The variable "on" is true if
+   the positive form is given, otherwise it is false.  If you don't
+   want to allow a "no-" form, your handler should reject "on" being
+   false by returning zero.  See, for example, the handling of
+   -ftabstop=.
 
    If the user gives an option to a front end that doesn't support it,
    an error is output, mentioning which front ends the option is valid
    for.  If you don't want this, you must accept it for all front
-   ends, and test for the front end in the option handler.  */
+   ends, and test for the front end in the option handler.  See, for
+   example, the handling of -Wno-strict-prototypes for C++.
+
+   If you request an argument with CL_JOINED, CL_SEPARATE or their
+   combination CL_ARG, it is stored in the variable "arg", which is
+   guaranteed non-NULL.  It points to the argument either within the
+   argv[] vector or within one of its strings, and so the text is not
+   temporary and copies need not be made.
+
+   If you use the CL_SEPARATE flag (which is also in CL_ARG) be sure
+   to add an error message in missing_arg().  */
+
 #define COMMAND_LINE_OPTIONS						     \
   OPT("E",			CL_ALL,   OPT_E)			     \
   OPT("Wall",			CL_ALL,   OPT_Wall)			     \
   OPT("Wbad-function-cast",	CL_C,     OPT_Wbad_function_cast)	     \
   OPT("Wcast-qual",		CL_ALL,   OPT_Wcast_qual)		     \
   OPT("Wchar-subscripts",	CL_ALL,   OPT_Wchar_subscripts)		     \
+  OPT("Wcomment",		CL_ALL,   OPT_Wcomment)			     \
+  OPT("Wcomments",              CL_ALL,   OPT_Wcomments)		     \
   OPT("Wconversion",		CL_ALL,   OPT_Wconversion)		     \
   OPT("Wctor-dtor-privacy",	CL_CXX,   OPT_Wctor_dtor_privacy)	     \
   OPT("Wdeprecated",		CL_CXX,   OPT_Wdeprecated)		     \
   OPT("Wdiv-by-zero",		CL_C,     OPT_Wdiv_by_zero)		     \
   OPT("Weffc++",		CL_CXX,   OPT_Weffcxx)			     \
+  OPT("Wendif-labels",		CL_ALL,   OPT_Wendif_labels)		     \
+  OPT("Werror",                 CL_ALL,   OPT_Werror)			     \
   OPT("Werror-implicit-function-declaration",				     \
 	     			CL_C,     OPT_Werror_implicit_function_decl) \
   OPT("Wfloat-equal",		CL_ALL,   OPT_Wfloat_equal)		     \
@@ -83,6 +103,7 @@ static void write_langs PARAMS ((char *,
   OPT("Wimplicit",		CL_CXX,   OPT_Wimplicit)		     \
   OPT("Wimplicit-function-declaration",	CL_C, OPT_Wimplicit_function_decl)   \
   OPT("Wimplicit-int",		CL_C,	  OPT_Wimplicit_int)		     \
+  OPT("Wimport",                CL_ALL,   OPT_Wimport)			     \
   OPT("Wlong-long",		CL_ALL,   OPT_Wlong_long)		     \
   OPT("Wmain",			CL_C,     OPT_Wmain)			     \
   OPT("Wmissing-braces",	CL_ALL,   OPT_Wmissing_braces)		     \
@@ -109,8 +130,12 @@ static void write_langs PARAMS ((char *,
   OPT("Wsign-promo",		CL_CXX,   OPT_Wsign_promo)		     \
   OPT("Wstrict-prototypes",	CL_ALL,   OPT_Wstrict_prototypes)	     \
   OPT("Wsynth",			CL_CXX,   OPT_Wsynth)			     \
+  OPT("Wsystem-headers",	CL_ALL,   OPT_Wsystem_headers)		     \
   OPT("Wtraditional",		CL_C,     OPT_Wtraditional)		     \
+  OPT("Wtrigraphs",		CL_ALL,   OPT_Wtrigraphs)		     \
+  OPT("Wundef",			CL_ALL,   OPT_Wundef)			     \
   OPT("Wunknown-pragmas",	CL_ALL,   OPT_Wunknown_pragmas)		     \
+  OPT("Wunused-macros",		CL_ALL,   OPT_Wunused_macros)		     \
   OPT("Wwrite-strings",		CL_ALL,   OPT_Wwrite_strings)		     \
   OPT("ansi",			CL_ALL,   OPT_ansi)			     \
   OPT("faccess-control",	CL_CXX,   OPT_faccess_control)		     \
@@ -151,18 +176,22 @@ static void write_langs PARAMS ((char *,
   OPT("fnext-runtime",		CL_OBJC,  OPT_fnext_runtime)		     \
   OPT("fnonansi-builtins",	CL_CXX,   OPT_fnonansi_builtins)	     \
   OPT("fnonnull-objects",	CL_CXX,   OPT_fnonnull_objects)		     \
+  OPT("foperator-names",	CL_CXX,   OPT_foperator_names)		     \
   OPT("foptional-diags",	CL_CXX,   OPT_foptional_diags)		     \
   OPT("fpermissive",		CL_CXX,   OPT_fpermissive)		     \
+  OPT("fpreprocessed",		CL_ALL,   OPT_fpreprocessed)		     \
   OPT("frepo",			CL_CXX,   OPT_frepo)			     \
   OPT("frtti",			CL_CXX,   OPT_frtti)			     \
   OPT("fshort-double",		CL_ALL,   OPT_fshort_double)		     \
   OPT("fshort-enums",		CL_ALL,   OPT_fshort_enums)		     \
   OPT("fshort-wchar",		CL_ALL,   OPT_fshort_wchar)		     \
+  OPT("fshow-column",		CL_ALL,   OPT_fshow_column)		     \
   OPT("fsigned-bitfields",	CL_ALL,   OPT_fsigned_bitfields)	     \
   OPT("fsigned-char",		CL_ALL,   OPT_fsigned_char)		     \
   OPT("fsquangle",		CL_CXX,   OPT_fsquangle)		     \
   OPT("fstats",			CL_CXX,   OPT_fstats)			     \
   OPT("fstrict-prototype",	CL_CXX,   OPT_fstrict_prototype)	     \
+  OPT("ftabstop=",              CL_ALL | CL_JOINED,   OPT_ftabstop)	     \
   OPT("ftemplate-depth-",	CL_CXX | CL_JOINED, OPT_ftemplate_depth)     \
   OPT("fthis-is-variable",	CL_CXX,   OPT_fthis_is_variable)	     \
   OPT("funsigned-bitfields",	CL_ALL,   OPT_funsigned_bitfields)	     \
@@ -173,6 +202,8 @@ static void write_langs PARAMS ((char *,
   OPT("fweak",			CL_CXX,   OPT_fweak)			     \
   OPT("fxref",			CL_CXX,   OPT_fxref)			     \
   OPT("gen-decls",		CL_OBJC,  OPT_gen_decls)		     \
+  OPT("pedantic",		CL_ALL,   OPT_pedantic)			     \
+  OPT("pedantic-errors",	CL_ALL,   OPT_pedantic_errors)		     \
   OPT("print-objc-runtime-info", CL_OBJC, OPT_print_objc_runtime_info)	     \
   OPT("std=",			CL_ALL | CL_JOINED, OPT_std_bad)	     \
   OPT("std=c++98",		CL_CXX,	  OPT_std_cplusplus98)		     \
@@ -337,8 +368,10 @@ c_common_init_options (lang)
   c_language = lang;
   parse_in = cpp_create_reader (lang == clk_c || lang == clk_objective_c
 				? CLK_GNUC89 : CLK_GNUCXX);
+  cpp_opts = cpp_get_options (parse_in);
+
   if (lang == clk_objective_c)
-    cpp_get_options (parse_in)->objc = 1;
+    cpp_opts->objc = 1;
 
   flag_const_strings = (lang == clk_cplusplus);
   warn_pointer_arith = (lang == clk_cplusplus);
@@ -472,6 +505,10 @@ c_common_decode_option (argc, argv)
 	  warn_reorder = on;
 	  warn_nontemplate_friend = on;
 	}
+
+      cpp_opts->warn_trigraphs = on;
+      cpp_opts->warn_comments = on;
+      cpp_opts->warn_num_sign_change = on;
       break;
 
     case OPT_Wbad_function_cast:
@@ -486,6 +523,11 @@ c_common_decode_option (argc, argv)
       warn_char_subscripts = on;
       break;
 
+    case OPT_Wcomment:
+    case OPT_Wcomments:
+      cpp_opts->warn_comments = on;
+      break;
+
     case OPT_Wconversion:
       warn_conversion = on;
       break;
@@ -506,6 +548,14 @@ c_common_decode_option (argc, argv)
       warn_ecpp = on;
       break;
 
+    case OPT_Wendif_labels:
+      cpp_opts->warn_endif_labels = on;
+      break;
+
+    case OPT_Werror:
+      cpp_opts->warnings_are_errors = on;
+      break;
+
     case OPT_Werror_implicit_function_decl:
       if (!on)
 	{
@@ -559,6 +609,10 @@ c_common_decode_option (argc, argv)
       warn_implicit_int = on;
       break;
 
+    case OPT_Wimport:
+      cpp_opts->warn_import = on;
+      break;
+
     case OPT_Wlong_long:
       warn_long_long = on;
       break;
@@ -669,8 +723,21 @@ c_common_decode_option (argc, argv)
       warn_synth = on;
       break;
 
+    case OPT_Wsystem_headers:
+      cpp_opts->warn_system_headers = on;
+      break;
+
     case OPT_Wtraditional:
       warn_traditional = on;
+      cpp_opts->warn_traditional = on;
+      break;
+
+    case OPT_Wtrigraphs:
+      cpp_opts->warn_trigraphs = on;
+      break;
+
+    case OPT_Wundef:
+      cpp_opts->warn_undef = on;
       break;
 
     case OPT_Wunknown_pragmas:
@@ -679,6 +746,10 @@ c_common_decode_option (argc, argv)
       warn_unknown_pragmas = on * 2;
       break;
 
+    case OPT_Wunused_macros:
+      cpp_opts->warn_unused_macros = on;
+      break;
+
     case OPT_Wwrite_strings:
       if (c_language == clk_c || c_language == clk_objective_c)
 	flag_const_strings = on;
@@ -869,6 +940,10 @@ c_common_decode_option (argc, argv)
       flag_no_nonansi_builtin = !on;
       break;
 
+    case OPT_foperator_names:
+      cpp_opts->operator_names = on;
+      break;
+
     case OPT_foptional_diags:
       flag_optional_diags = on;
       break;
@@ -877,6 +952,10 @@ c_common_decode_option (argc, argv)
       flag_permissive = on;
       break;
 
+    case OPT_fpreprocessed:
+      cpp_opts->preprocessed = on;
+      break;
+
     case OPT_frepo:
       flag_use_repository = on;
       if (on)
@@ -887,10 +966,29 @@ c_common_decode_option (argc, argv)
       flag_rtti = on;
       break;
 
+    case OPT_fshow_column:
+      cpp_opts->show_column = on;
+      break;
+
     case OPT_fstats:
       flag_detailed_statistics = on;
       break;
 
+    case OPT_ftabstop:
+      /* Don't recognise -fno-tabstop=.  */
+      if (!on)
+	return 0;
+
+      /* It is documented that we silently ignore silly values.  */
+      if (*arg)
+	{
+	  char *endptr;
+	  long tabstop = strtol (arg, &endptr, 10);
+	  if (*endptr == '\0' && tabstop >= 1 && tabstop <= 100)
+	    cpp_opts->tabstop = tabstop;
+	}
+      break;
+
     case OPT_ftemplate_depth:
       max_tinst_depth = read_integral_parameter (arg, argv[0], 0);
       break;
@@ -909,6 +1007,17 @@ c_common_decode_option (argc, argv)
 
     case OPT_gen_decls:
       flag_gen_declaration = 1;
+      break;
+
+      /* We need to handle the -pedantic switches here, rather than in
+	 c_common_post_options, so that a subsequent -Wno-endif-labels
+	 is not overridden.  */
+    case OPT_pedantic_errors:
+      cpp_opts->pedantic_errors = 1;
+      /* fall through */
+    case OPT_pedantic:
+      cpp_opts->pedantic = 1;
+      cpp_opts->warn_endif_labels = 1;
       break;
 
     case OPT_print_objc_runtime_info:
Index: cppinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.249
diff -u -p -r1.249 cppinit.c
--- cppinit.c	6 Aug 2002 20:35:41 -0000	1.249
+++ cppinit.c	7 Aug 2002 21:13:11 -0000
@@ -1156,34 +1156,7 @@ new_pending_directive (pend, text, handl
   DEF_OPT("MT",                       no_tgt, OPT_MT)                         \
   DEF_OPT("P",                        0,      OPT_P)                          \
   DEF_OPT("U",                        no_mac, OPT_U)                          \
-  DEF_OPT("Wall",                     0,      OPT_Wall)                       \
-  DEF_OPT("Wcomment",                 0,      OPT_Wcomment)                   \
-  DEF_OPT("Wcomments",                0,      OPT_Wcomments)                  \
-  DEF_OPT("Wendif-labels",            0,      OPT_Wendif_labels)              \
-  DEF_OPT("Werror",                   0,      OPT_Werror)                     \
-  DEF_OPT("Wimport",                  0,      OPT_Wimport)                    \
-  DEF_OPT("Wno-comment",              0,      OPT_Wno_comment)                \
-  DEF_OPT("Wno-comments",             0,      OPT_Wno_comments)               \
-  DEF_OPT("Wno-endif-labels",         0,      OPT_Wno_endif_labels)           \
-  DEF_OPT("Wno-error",                0,      OPT_Wno_error)                  \
-  DEF_OPT("Wno-import",               0,      OPT_Wno_import)                 \
-  DEF_OPT("Wno-system-headers",       0,      OPT_Wno_system_headers)         \
-  DEF_OPT("Wno-traditional",          0,      OPT_Wno_traditional)            \
-  DEF_OPT("Wno-trigraphs",            0,      OPT_Wno_trigraphs)              \
-  DEF_OPT("Wno-undef",                0,      OPT_Wno_undef)                  \
-  DEF_OPT("Wno-unused-macros",        0,      OPT_Wno_unused_macros)          \
-  DEF_OPT("Wsystem-headers",          0,      OPT_Wsystem_headers)            \
-  DEF_OPT("Wtraditional",             0,      OPT_Wtraditional)               \
-  DEF_OPT("Wtrigraphs",               0,      OPT_Wtrigraphs)                 \
-  DEF_OPT("Wundef",                   0,      OPT_Wundef)                     \
-  DEF_OPT("Wunused-macros",           0,      OPT_Wunused_macros)             \
   DEF_OPT("d",                        no_arg, OPT_d)                          \
-  DEF_OPT("fno-operator-names",       0,      OPT_fno_operator_names)         \
-  DEF_OPT("fno-preprocessed",         0,      OPT_fno_preprocessed)           \
-  DEF_OPT("fno-show-column",          0,      OPT_fno_show_column)            \
-  DEF_OPT("fpreprocessed",            0,      OPT_fpreprocessed)              \
-  DEF_OPT("fshow-column",             0,      OPT_fshow_column)               \
-  DEF_OPT("ftabstop=",                no_num, OPT_ftabstop)                   \
   DEF_OPT("h",                        0,      OPT_h)                          \
   DEF_OPT("idirafter",                no_dir, OPT_idirafter)                  \
   DEF_OPT("imacros",                  no_fil, OPT_imacros)                    \
@@ -1200,8 +1173,6 @@ new_pending_directive (pend, text, handl
   DEF_OPT("nostdinc",                 0,      OPT_nostdinc)                   \
   DEF_OPT("nostdinc++",               0,      OPT_nostdincplusplus)           \
   DEF_OPT("o",                        no_fil, OPT_o)                          \
-  DEF_OPT("pedantic",                 0,      OPT_pedantic)                   \
-  DEF_OPT("pedantic-errors",          0,      OPT_pedantic_errors)            \
   DEF_OPT("remap",                    0,      OPT_remap)                      \
   DEF_OPT("std=c++98",                0,      OPT_std_cplusplus98)            \
   DEF_OPT("std=c89",                  0,      OPT_std_c89)                    \
@@ -1363,31 +1334,6 @@ cpp_handle_option (pfile, argc, argv)
 	{
 	case N_OPTS: /* Shut GCC up.  */
 	  break;
-	case OPT_fno_operator_names:
-	  CPP_OPTION (pfile, operator_names) = 0;
-	  break;
-	case OPT_fpreprocessed:
-	  CPP_OPTION (pfile, preprocessed) = 1;
-	  break;
-	case OPT_fno_preprocessed:
-	  CPP_OPTION (pfile, preprocessed) = 0;
-	  break;
-	case OPT_fshow_column:
-	  CPP_OPTION (pfile, show_column) = 1;
-	  break;
-	case OPT_fno_show_column:
-	  CPP_OPTION (pfile, show_column) = 0;
-	  break;
-	case OPT_ftabstop:
-	  /* Silently ignore empty string, non-longs and silly values.  */
-	  if (arg[0] != '\0')
-	    {
-	      char *endptr;
-	      long tabstop = strtol (arg, &endptr, 10);
-	      if (*endptr == '\0' && tabstop >= 1 && tabstop <= 100)
-		CPP_OPTION (pfile, tabstop) = tabstop;
-	    }
-	  break;
 	case OPT_w:
 	  CPP_OPTION (pfile, inhibit_warnings) = 1;
 	  break;
@@ -1421,13 +1367,6 @@ cpp_handle_option (pfile, argc, argv)
 	case OPT_D:
 	  new_pending_directive (pend, arg, cpp_define);
 	  break;
-	case OPT_pedantic_errors:
-	  CPP_OPTION (pfile, pedantic_errors) = 1;
-	  /* fall through */
-	case OPT_pedantic:
-	  CPP_OPTION (pfile, pedantic) = 1;
-	  CPP_OPTION (pfile, warn_endif_labels) = 1;
-	  break;
 	case OPT_trigraphs:
 	  CPP_OPTION (pfile, trigraphs) = 1;
 	  break;
@@ -1666,77 +1605,6 @@ cpp_handle_option (pfile, argc, argv)
 	case OPT_idirafter:
 	  /* Add directory to end of path for includes.  */
 	  append_include_chain (pfile, xstrdup (arg), AFTER, 0);
-	  break;
-
-	case OPT_Wall:
-	  CPP_OPTION (pfile, warn_trigraphs) = 1;
-	  CPP_OPTION (pfile, warn_comments) = 1;
-	  CPP_OPTION (pfile, warn_num_sign_change) = 1;
-	  break;
-
-	case OPT_Wtraditional:
-	  CPP_OPTION (pfile, warn_traditional) = 1;
-	  break;
-	case OPT_Wno_traditional:
-	  CPP_OPTION (pfile, warn_traditional) = 0;
-	  break;
-
-	case OPT_Wtrigraphs:
-	  CPP_OPTION (pfile, warn_trigraphs) = 1;
-	  break;
-	case OPT_Wno_trigraphs:
-	  CPP_OPTION (pfile, warn_trigraphs) = 0;
-	  break;
-
-	case OPT_Wcomment:
-	case OPT_Wcomments:
-	  CPP_OPTION (pfile, warn_comments) = 1;
-	  break;
-	case OPT_Wno_comment:
-	case OPT_Wno_comments:
-	  CPP_OPTION (pfile, warn_comments) = 0;
-	  break;
-
-	case OPT_Wunused_macros:
-	  CPP_OPTION (pfile, warn_unused_macros) = 1;
-	  break;
-	case OPT_Wno_unused_macros:
-	  CPP_OPTION (pfile, warn_unused_macros) = 0;
-	  break;
-
-	case OPT_Wundef:
-	  CPP_OPTION (pfile, warn_undef) = 1;
-	  break;
-	case OPT_Wno_undef:
-	  CPP_OPTION (pfile, warn_undef) = 0;
-	  break;
-
-	case OPT_Wimport:
-	  CPP_OPTION (pfile, warn_import) = 1;
-	  break;
-	case OPT_Wno_import:
-	  CPP_OPTION (pfile, warn_import) = 0;
-	  break;
-
-	case OPT_Wendif_labels:
-	  CPP_OPTION (pfile, warn_endif_labels) = 1;
-	  break;
-	case OPT_Wno_endif_labels:
-	  CPP_OPTION (pfile, warn_endif_labels) = 0;
-	  break;
-
-	case OPT_Werror:
-	  CPP_OPTION (pfile, warnings_are_errors) = 1;
-	  break;
-	case OPT_Wno_error:
-	  CPP_OPTION (pfile, warnings_are_errors) = 0;
-	  break;
-
-	case OPT_Wsystem_headers:
-	  CPP_OPTION (pfile, warn_system_headers) = 1;
-	  break;
-	case OPT_Wno_system_headers:
-	  CPP_OPTION (pfile, warn_system_headers) = 0;
 	  break;
 	}
     }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]