public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada,C++,etc.] Options patches pending review
@ 2010-06-24 17:28 Joseph S. Myers
  2010-06-24 19:44 ` Mike Stump
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Joseph S. Myers @ 2010-06-24 17:28 UTC (permalink / raw)
  To: gcc-patches; +Cc: bosch, dewar, charlet, jason, Mark Mitchell, Nathan Sidwell

Various recent option handling patches of mine have got bogged down in 
piecemeal review of bits of the patches.  In particular, several currently 
needs review of C++ and Ada pieces.

<http://gcc.gnu.org/ml/gcc-patches/2010-06/msg01968.html> needs C++ and 
Ada review.

<http://gcc.gnu.org/ml/gcc-patches/2010-06/msg02150.html> needs C++ 
review.

<http://gcc.gnu.org/ml/gcc-patches/2010-06/msg02260.html> needs review for 
Ada and LTO pieces and the main language-independent part of the patch.

<http://gcc.gnu.org/ml/gcc-patches/2010-06/msg02377.html> needs review for 
the whole patch (including Ada and Fortran pieces).

<http://gcc.gnu.org/ml/gcc-patches/2010-06/msg02407.html> is a C++ patch 
(including C++-specific gcc.c pieces and Obj-C++ specs).

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Ada,C++,etc.] Options patches pending review
  2010-06-24 17:28 [Ada,C++,etc.] Options patches pending review Joseph S. Myers
@ 2010-06-24 19:44 ` Mike Stump
  2010-06-25 16:57 ` Joseph S. Myers
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Mike Stump @ 2010-06-24 19:44 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: GCC Patches, Jason Merrill, Mark Mitchell, Nathan Sidwell

On Jun 24, 2010, at 9:00 AM, Joseph S. Myers wrote:
> <http://gcc.gnu.org/ml/gcc-patches/2010-06/msg02407.html> is a C++ patch 
> (including C++-specific gcc.c pieces and Obj-C++ specs).

Since this has a bit of objc in it, I thought I should Ok that bit, just to ensure you don't block on my approval.  In general, all objc changes like this that mirror C or C++ changes are always ok as the C or C++ maintainers approve them.

Anyway, I reviewed the whole patch, and it looks fine to me.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Ada,C++,etc.] Options patches pending review
  2010-06-24 17:28 [Ada,C++,etc.] Options patches pending review Joseph S. Myers
  2010-06-24 19:44 ` Mike Stump
@ 2010-06-25 16:57 ` Joseph S. Myers
  2010-06-25 18:26   ` Arnaud Charlet
  2010-07-02 11:29   ` Geert Bosch
  2010-06-30 21:36 ` Jason Merrill
  2010-06-30 21:53 ` Diego Novillo
  3 siblings, 2 replies; 8+ messages in thread
From: Joseph S. Myers @ 2010-06-25 16:57 UTC (permalink / raw)
  To: gcc-patches; +Cc: bosch, dewar, charlet

On Thu, 24 Jun 2010, Joseph S. Myers wrote:

> Various recent option handling patches of mine have got bogged down in 
> piecemeal review of bits of the patches.  In particular, several currently 
> needs review of C++ and Ada pieces.

An update to the status of this series (four presently uncommitted 
patches, but one of those is now completely approved):

> <http://gcc.gnu.org/ml/gcc-patches/2010-06/msg01968.html> needs C++ and 
> Ada review.

Ada review still needed.

> <http://gcc.gnu.org/ml/gcc-patches/2010-06/msg02260.html> needs review for 
> Ada and LTO pieces and the main language-independent part of the patch.
> 
> <http://gcc.gnu.org/ml/gcc-patches/2010-06/msg02377.html> needs review for 
> the whole patch (including Ada and Fortran pieces).

If you wish to consider the Ada pieces as less mechanical than the purely 
mechanical changes to other front ends, then these also still need Ada 
review.

The second of these patches no longer applies cleanly to trunk because of 
changes to set_option since I created that patch, so here's an updated 
version (the updates are purely to reflect the changes to set_option in 
the parts of the patch that move that function).

2010-06-25  Joseph Myers  <joseph@codesourcery.com>

	* coretypes.h (struct cl_option_handlers): Declare.
	* hooks.c (hook_int_size_t_constcharptr_int_0): Remove.
	* hooks.h (hook_int_size_t_constcharptr_int_0): Remove.
	* langhooks-def.h (lhd_handle_option): Declare.
	(LANG_HOOKS_HANDLE_OPTION): Use lhd_handle_option.
	* langhooks.c (lhd_handle_option): New.
	* langhooks.h (struct lang_hooks): Update prototype and return
	value type of handle_option hook.
	* optc-gen.awk: Generate target_flags_explicit definition for the
	driver.
	* opts-common.c: Include diagnostic.h.
	(handle_option): Move from opts.c.  Update prototype and return
	value type.  Use handlers structure.
	(read_cmdline_option): Move from opts.c.  Update prototype.  Use
	handlers structure.
	(set_option): Move from opts.c.
	* opts.c (common_handle_option): Update prototype and return value
	type.  Update calls to handle_option and enable_warning_as_error.
	(unknown_option_callback, post_handling_callback,
	lang_handle_option, target_handle_option): New.
	(handle_option, read_cmdline_option): Move to opts-common.c.
	(read_cmdline_options): Update prototype.  Update call to
	read_cmdline_option.
	(decode_options): Initialize and use handlers structure.
	(set_option): Move to opts-common.c.
	(enable_warning_as_error): Update prototype.  Update call to
	handle_option.
	* opts.h (struct cl_option_handler_func, struct
	cl_option_handlers): New.
	(handle_option, enable_warning_as_error): Update prototypes.
	(read_cmdline_option): Declare.
	* Makefile.in (opts-common.o): Update dependencies.

ada:
2010-06-25  Joseph Myers  <joseph@codesourcery.com>

	* gcc-interface/misc.c (gnat_handle_option): Update prototype and
	return value type.  Don't check for missing arguments here.

c-family:
2010-06-25  Joseph Myers  <joseph@codesourcery.com>

	* c-common.h (c_common_handle_option): Update prototype and return
	value type.
	* c-opts.c (c_common_handle_option): Update prototype and return
	value type.  Update calls to handle_option and
	enable_warning_as_error.

fortran:
2010-06-25  Joseph Myers  <joseph@codesourcery.com>

	* gfortran.h (gfc_handle_option): Update prototype and return
	value type.
	* options.c (gfc_handle_option): Update prototype and return value
	type.

java:
2010-06-25  Joseph Myers  <joseph@codesourcery.com>

	* lang.c (java_handle_option): Update prototype and return value
	type.

lto:
2010-06-25  Joseph Myers  <joseph@codesourcery.com>

	* lto-lang.c (lto_handle_option): Update prototype and return
	value type.  Remove duplicate assignment to result.

diff -rupN --exclude=.svn gcc-mainline-opt2-missing-arg/gcc/Makefile.in gcc-mainline/gcc/Makefile.in
--- gcc-mainline-opt2-missing-arg/gcc/Makefile.in	2010-06-25 04:15:31.000000000 -0700
+++ gcc-mainline/gcc/Makefile.in	2010-06-25 06:21:00.000000000 -0700
@@ -2796,7 +2796,7 @@ opts.o : opts.c opts.h options.h $(TOPLE
    $(FLAGS_H) $(PARAMS_H) $(TREE_PASS_H) $(DBGCNT_H) debug.h \
    $(PLUGIN_H) $(EXCEPT_H) $(LTO_STREAMER_H) opts-diagnostic.h
 opts-common.o : opts-common.c opts.h $(CONFIG_H) $(SYSTEM_H) \
-   coretypes.h intl.h
+   coretypes.h intl.h $(DIAGNOSTIC_H)
 targhooks.o : targhooks.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TREE_H) \
    $(EXPR_H) $(TM_H) $(RTL_H) $(TM_P_H) $(FUNCTION_H) output.h $(TOPLEV_H) \
    $(MACHMODE_H) $(TARGET_DEF_H) $(TARGET_H) $(GGC_H) gt-targhooks.h \
diff -rupN --exclude=.svn gcc-mainline-opt2-missing-arg/gcc/ada/gcc-interface/misc.c gcc-mainline/gcc/ada/gcc-interface/misc.c
--- gcc-mainline-opt2-missing-arg/gcc/ada/gcc-interface/misc.c	2010-06-25 04:18:56.000000000 -0700
+++ gcc-mainline/gcc/ada/gcc-interface/misc.c	2010-06-25 06:21:00.000000000 -0700
@@ -65,7 +65,8 @@ static bool gnat_init			(void);
 static unsigned int gnat_option_lang_mask (void);
 static void gnat_init_options		(unsigned int,
 					 struct cl_decoded_option *);
-static int gnat_handle_option		(size_t, const char *, int, int);
+static bool gnat_handle_option		(size_t, const char *, int, int,
+					 const struct cl_option_handlers *);
 static bool gnat_post_options		(const char **);
 static alias_set_type gnat_get_alias_set (tree);
 static void gnat_print_decl		(FILE *, tree, int);
@@ -187,23 +188,16 @@ gnat_parse_file (int set_yydebug ATTRIBU
 
 /* Decode all the language specific options that cannot be decoded by GCC.
    The option decoding phase of GCC calls this routine on the flags that
-   it cannot decode.  Return the number of consecutive arguments from ARGV
-   that have been successfully decoded or 0 on failure.  */
+   are marked as Ada-specific.  Return true on success or false on failure.  */
 
-static int
+static bool
 gnat_handle_option (size_t scode, const char *arg, int value,
-		    int kind ATTRIBUTE_UNUSED)
+		    int kind ATTRIBUTE_UNUSED,
+		    const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
 {
-  const struct cl_option *option = &cl_options[scode];
   enum opt_code code = (enum opt_code) scode;
   char *q;
 
-  if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
-    {
-      error ("missing argument to \"-%s\"", option->opt_text);
-      return 1;
-    }
-
   switch (code)
     {
     case OPT_I:
@@ -280,7 +274,7 @@ gnat_handle_option (size_t scode, const 
       gcc_unreachable ();
     }
 
-  return 1;
+  return true;
 }
 
 /* Return language mask for option processing.  */
diff -rupN --exclude=.svn gcc-mainline-opt2-missing-arg/gcc/c-family/c-common.h gcc-mainline/gcc/c-family/c-common.h
--- gcc-mainline-opt2-missing-arg/gcc/c-family/c-common.h	2010-06-25 06:15:53.000000000 -0700
+++ gcc-mainline/gcc/c-family/c-common.h	2010-06-25 06:21:00.000000000 -0700
@@ -652,7 +652,8 @@ extern void set_Wformat (int);
 extern tree handle_format_attribute (tree *, tree, tree, int, bool *);
 extern tree handle_format_arg_attribute (tree *, tree, tree, int, bool *);
 extern bool attribute_takes_identifier_p (const_tree);
-extern int c_common_handle_option (size_t code, const char *arg, int value, int kind);
+extern bool c_common_handle_option (size_t, const char *, int, int,
+				    const struct cl_option_handlers *);
 extern tree c_common_type_for_mode (enum machine_mode, int);
 extern tree c_common_type_for_size (unsigned int, int);
 extern tree c_common_fixed_point_type_for_size (unsigned int, unsigned int,
diff -rupN --exclude=.svn gcc-mainline-opt2-missing-arg/gcc/c-family/c-opts.c gcc-mainline/gcc/c-family/c-opts.c
--- gcc-mainline-opt2-missing-arg/gcc/c-family/c-opts.c	2010-06-25 06:15:53.000000000 -0700
+++ gcc-mainline/gcc/c-family/c-opts.c	2010-06-25 06:21:00.000000000 -0700
@@ -319,16 +319,15 @@ c_common_init_options (unsigned int deco
 }
 
 /* Handle switch SCODE with argument ARG.  VALUE is true, unless no-
-   form of an -f or -W option was given.  Returns 0 if the switch was
-   invalid, a negative number to prevent language-independent
-   processing in toplev.c (a hack necessary for the short-term).  */
-int
+   form of an -f or -W option was given.  Returns false if the switch was
+   invalid, true if valid.  Use HANDLERS in recursive handle_option calls.  */
+bool
 c_common_handle_option (size_t scode, const char *arg, int value,
-			int kind)
+			int kind, const struct cl_option_handlers *handlers)
 {
   const struct cl_option *option = &cl_options[scode];
   enum opt_code code = (enum opt_code) scode;
-  int result = 1;
+  bool result = true;
 
   /* Prevent resetting the language standard to a C dialect when the driver
      has already determined that we're looking at assembler input.  */
@@ -341,10 +340,10 @@ c_common_handle_option (size_t scode, co
 	{
 	  if ((option->flags & CL_TARGET)
 	      && ! targetcm.handle_c_option (scode, arg, value))
-	    result = 0;
+	    result = false;
 	  break;
 	}
-      result = 0;
+      result = false;
       break;
 
     case OPT__output_pch_:
@@ -438,7 +437,8 @@ c_common_handle_option (size_t scode, co
     case OPT_Wall:
       warn_unused = value;
       set_Wformat (value);
-      handle_option (OPT_Wimplicit, value, NULL, c_family_lang_mask, kind);
+      handle_option (OPT_Wimplicit, NULL, value, c_family_lang_mask, kind,
+		     handlers);
       warn_char_subscripts = value;
       warn_missing_braces = value;
       warn_parentheses = value;
@@ -524,7 +524,8 @@ c_common_handle_option (size_t scode, co
     case OPT_Werror_implicit_function_declaration:
       /* For backward compatibility, this is the same as
 	 -Werror=implicit-function-declaration.  */
-      enable_warning_as_error ("implicit-function-declaration", value, CL_C | CL_ObjC);
+      enable_warning_as_error ("implicit-function-declaration", value,
+			       CL_C | CL_ObjC, handlers);
       break;
 
     case OPT_Wformat:
@@ -538,11 +539,11 @@ c_common_handle_option (size_t scode, co
     case OPT_Wimplicit:
       gcc_assert (value == 0 || value == 1);
       if (warn_implicit_int == -1)
-	handle_option (OPT_Wimplicit_int, value, NULL,
-		       c_family_lang_mask, kind);
+	handle_option (OPT_Wimplicit_int, NULL, value,
+		       c_family_lang_mask, kind, handlers);
       if (warn_implicit_function_declaration == -1)
-	handle_option (OPT_Wimplicit_function_declaration, value, NULL,
-		       c_family_lang_mask, kind);
+	handle_option (OPT_Wimplicit_function_declaration, NULL, value,
+		       c_family_lang_mask, kind, handlers);
       break;
 
     case OPT_Wimport:
@@ -655,7 +656,7 @@ c_common_handle_option (size_t scode, co
 
     case OPT_fbuiltin_:
       if (value)
-	result = 0;
+	result = false;
       else
 	disable_builtin_function (arg);
       break;
diff -rupN --exclude=.svn gcc-mainline-opt2-missing-arg/gcc/coretypes.h gcc-mainline/gcc/coretypes.h
--- gcc-mainline-opt2-missing-arg/gcc/coretypes.h	2010-06-25 04:18:56.000000000 -0700
+++ gcc-mainline/gcc/coretypes.h	2010-06-25 06:21:00.000000000 -0700
@@ -68,6 +68,7 @@ struct cl_target_option;
 struct cl_optimization;
 struct cl_option;
 struct cl_decoded_option;
+struct cl_option_handlers;
 struct gimple_seq_d;
 typedef struct gimple_seq_d *gimple_seq;
 typedef const struct gimple_seq_d *const_gimple_seq;
diff -rupN --exclude=.svn gcc-mainline-opt2-missing-arg/gcc/fortran/gfortran.h gcc-mainline/gcc/fortran/gfortran.h
--- gcc-mainline-opt2-missing-arg/gcc/fortran/gfortran.h	2010-06-25 04:18:56.000000000 -0700
+++ gcc-mainline/gcc/fortran/gfortran.h	2010-06-25 06:21:00.000000000 -0700
@@ -2346,7 +2346,8 @@ int get_c_kind (const char *, CInteropKi
 unsigned int gfc_option_lang_mask (void);
 void gfc_init_options (unsigned int,
 		       struct cl_decoded_option *);
-int gfc_handle_option (size_t, const char *, int, int);
+bool gfc_handle_option (size_t, const char *, int, int,
+			const struct cl_option_handlers *);
 bool gfc_post_options (const char **);
 
 /* f95-lang.c */
diff -rupN --exclude=.svn gcc-mainline-opt2-missing-arg/gcc/fortran/options.c gcc-mainline/gcc/fortran/options.c
--- gcc-mainline-opt2-missing-arg/gcc/fortran/options.c	2010-06-25 04:18:56.000000000 -0700
+++ gcc-mainline/gcc/fortran/options.c	2010-06-25 06:21:00.000000000 -0700
@@ -542,20 +542,21 @@ gfc_handle_runtime_check_option (const c
 /* Handle command-line options.  Returns 0 if unrecognized, 1 if
    recognized and handled.  */
 
-int
+bool
 gfc_handle_option (size_t scode, const char *arg, int value,
-		   int kind ATTRIBUTE_UNUSED)
+		   int kind ATTRIBUTE_UNUSED,
+		   const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
 {
-  int result = 1;
+  bool result = true;
   enum opt_code code = (enum opt_code) scode;
 
   if (gfc_cpp_handle_option (scode, arg, value) == 1)
-    return 1;
+    return true;
 
   switch (code)
     {
     default:
-      result = 0;
+      result = false;
       break;
 
     case OPT_Wall:
diff -rupN --exclude=.svn gcc-mainline-opt2-missing-arg/gcc/hooks.c gcc-mainline/gcc/hooks.c
--- gcc-mainline-opt2-missing-arg/gcc/hooks.c	2010-06-25 06:15:53.000000000 -0700
+++ gcc-mainline/gcc/hooks.c	2010-06-25 06:21:00.000000000 -0700
@@ -160,14 +160,6 @@ hook_int_rtx_bool_0 (rtx a ATTRIBUTE_UNU
   return 0;
 }
 
-int
-hook_int_size_t_constcharptr_int_0 (size_t a ATTRIBUTE_UNUSED,
-				    const char *b ATTRIBUTE_UNUSED,
-				    int c ATTRIBUTE_UNUSED)
-{
-  return 0;
-}
-
 unsigned int
 hook_uint_void_0 (void)
 {
diff -rupN --exclude=.svn gcc-mainline-opt2-missing-arg/gcc/hooks.h gcc-mainline/gcc/hooks.h
--- gcc-mainline-opt2-missing-arg/gcc/hooks.h	2010-06-25 06:15:53.000000000 -0700
+++ gcc-mainline/gcc/hooks.h	2010-06-25 06:21:00.000000000 -0700
@@ -63,7 +63,6 @@ extern int hook_int_const_tree_0 (const_
 extern int hook_int_const_tree_const_tree_1 (const_tree, const_tree);
 extern int hook_int_rtx_0 (rtx);
 extern int hook_int_rtx_bool_0 (rtx, bool);
-extern int hook_int_size_t_constcharptr_int_0 (size_t, const char *, int);
 
 extern tree hook_tree_const_tree_null (const_tree);
 
diff -rupN --exclude=.svn gcc-mainline-opt2-missing-arg/gcc/java/lang.c gcc-mainline/gcc/java/lang.c
--- gcc-mainline-opt2-missing-arg/gcc/java/lang.c	2010-06-25 04:18:56.000000000 -0700
+++ gcc-mainline/gcc/java/lang.c	2010-06-25 06:21:00.000000000 -0700
@@ -51,7 +51,8 @@ static unsigned int java_option_lang_mas
 static void java_init_options (unsigned int, struct cl_decoded_option *);
 static bool java_post_options (const char **);
 
-static int java_handle_option (size_t scode, const char *arg, int value, int kind);
+static bool java_handle_option (size_t, const char *, int, int,
+				const struct cl_option_handlers *);
 static void put_decl_string (const char *, int);
 static void put_decl_node (tree, int);
 static void java_print_error_function (diagnostic_context *, const char *,
@@ -175,11 +176,12 @@ struct lang_hooks lang_hooks = LANG_HOOK
 
 /*
  * process java-specific compiler command-line options
- * return 0, but do not complain if the option is not recognized.
+ * return false, but do not complain if the option is not recognized.
  */
-static int
+static bool
 java_handle_option (size_t scode, const char *arg, int value,
-		    int kind ATTRIBUTE_UNUSED)
+		    int kind ATTRIBUTE_UNUSED,
+		    const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
 {
   enum opt_code code = (enum opt_code) scode;
 
@@ -270,7 +272,7 @@ java_handle_option (size_t scode, const 
 
     case OPT_fdump_:
       if (!dump_switch_p (arg))
-	return 0;
+	return false;
       break;
 
     case OPT_fencoding_:
@@ -299,7 +301,7 @@ java_handle_option (size_t scode, const 
       gcc_unreachable ();
     }
 
-  return 1;
+  return true;
 }
 
 /* Global open file.  */
diff -rupN --exclude=.svn gcc-mainline-opt2-missing-arg/gcc/langhooks-def.h gcc-mainline/gcc/langhooks-def.h
--- gcc-mainline-opt2-missing-arg/gcc/langhooks-def.h	2010-06-25 06:15:53.000000000 -0700
+++ gcc-mainline/gcc/langhooks-def.h	2010-06-25 06:21:00.000000000 -0700
@@ -69,6 +69,8 @@ extern void lhd_initialize_diagnostics (
 extern void lhd_init_options (unsigned int,
 			      struct cl_decoded_option *);
 extern bool lhd_complain_wrong_lang_p (const struct cl_option *);
+extern bool lhd_handle_option (size_t, const char *, int, int,
+			       const struct cl_option_handlers *);
 extern tree lhd_callgraph_analyze_expr (tree *, int *);
 
 
@@ -89,7 +91,7 @@ extern void lhd_omp_firstprivatize_type_
 #define LANG_HOOKS_INIT_OPTIONS		lhd_init_options
 #define LANG_HOOKS_INITIALIZE_DIAGNOSTICS lhd_initialize_diagnostics
 #define LANG_HOOKS_COMPLAIN_WRONG_LANG_P lhd_complain_wrong_lang_p
-#define LANG_HOOKS_HANDLE_OPTION	hook_int_size_t_constcharptr_int_0
+#define LANG_HOOKS_HANDLE_OPTION	lhd_handle_option
 #define LANG_HOOKS_POST_OPTIONS		lhd_post_options
 #define LANG_HOOKS_MISSING_NORETURN_OK_P hook_bool_tree_true
 #define LANG_HOOKS_GET_ALIAS_SET	lhd_get_alias_set
diff -rupN --exclude=.svn gcc-mainline-opt2-missing-arg/gcc/langhooks.c gcc-mainline/gcc/langhooks.c
--- gcc-mainline-opt2-missing-arg/gcc/langhooks.c	2010-06-25 04:18:56.000000000 -0700
+++ gcc-mainline/gcc/langhooks.c	2010-06-25 06:21:00.000000000 -0700
@@ -351,6 +351,16 @@ lhd_complain_wrong_lang_p (const struct 
   return true;
 }
 
+/* By default, no language-specific options are valid.  */
+bool
+lhd_handle_option (size_t code ATTRIBUTE_UNUSED,
+		   const char *arg ATTRIBUTE_UNUSED,
+		   int value ATTRIBUTE_UNUSED, int kind ATTRIBUTE_UNUSED,
+		   const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
+{
+  return false;
+}
+
 /* The default function to print out name of current function that caused
    an error.  */
 void
diff -rupN --exclude=.svn gcc-mainline-opt2-missing-arg/gcc/langhooks.h gcc-mainline/gcc/langhooks.h
--- gcc-mainline-opt2-missing-arg/gcc/langhooks.h	2010-06-25 06:15:53.000000000 -0700
+++ gcc-mainline/gcc/langhooks.h	2010-06-25 06:21:00.000000000 -0700
@@ -292,11 +292,12 @@ struct lang_hooks
      which points to permanent storage.  The handler is responsible for
      checking whether ARG is NULL, which indicates that no argument
      was in fact supplied.  For -f and -W switches, VALUE is 1 or 0
-     for the positive and negative forms respectively.
+     for the positive and negative forms respectively.  HANDLERS should
+     be passed to any recursive handle_option calls.
 
-     Return 1 if the switch is valid, 0 if invalid, and -1 if it's
-     valid and should not be treated as language-independent too.  */
-  int (*handle_option) (size_t code, const char *arg, int value, int kind);
+     Return true if the switch is valid, false if invalid.  */
+  bool (*handle_option) (size_t code, const char *arg, int value, int kind,
+			 const struct cl_option_handlers *handlers);
 
   /* Called when all command line options have been parsed to allow
      further processing and initialization
diff -rupN --exclude=.svn gcc-mainline-opt2-missing-arg/gcc/lto/lto-lang.c gcc-mainline/gcc/lto/lto-lang.c
--- gcc-mainline-opt2-missing-arg/gcc/lto/lto-lang.c	2010-06-25 04:18:56.000000000 -0700
+++ gcc-mainline/gcc/lto/lto-lang.c	2010-06-25 06:21:00.000000000 -0700
@@ -630,18 +630,18 @@ lto_init_options (unsigned int decoded_o
    of the option was supplied.  */
 
 const char *resolution_file_name;
-static int
+static bool
 lto_handle_option (size_t scode, const char *arg,
-		   int value ATTRIBUTE_UNUSED, int kind ATTRIBUTE_UNUSED)
+		   int value ATTRIBUTE_UNUSED, int kind ATTRIBUTE_UNUSED,
+		   const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
 {
   enum opt_code code = (enum opt_code) scode;
-  int result = 1;
+  bool result = true;
 
   switch (code)
     {
     case OPT_fresolution_:
       resolution_file_name = arg;
-      result = 1;
       break;
 
     case OPT_Wabi:
diff -rupN --exclude=.svn gcc-mainline-opt2-missing-arg/gcc/optc-gen.awk gcc-mainline/gcc/optc-gen.awk
--- gcc-mainline-opt2-missing-arg/gcc/optc-gen.awk	2010-06-25 06:15:53.000000000 -0700
+++ gcc-mainline/gcc/optc-gen.awk	2010-06-25 06:21:00.000000000 -0700
@@ -73,6 +73,7 @@ print "#include " quote "intl.h" quote
 print ""
 print "#ifdef GCC_DRIVER"
 print "int target_flags;"
+print "int target_flags_explicit;"
 print "#else"
 print "#include " quote "flags.h" quote
 print "#include " quote "target.h" quote
diff -rupN --exclude=.svn gcc-mainline-opt2-missing-arg/gcc/opts-common.c gcc-mainline/gcc/opts-common.c
--- gcc-mainline-opt2-missing-arg/gcc/opts-common.c	2010-06-25 04:18:56.000000000 -0700
+++ gcc-mainline/gcc/opts-common.c	2010-06-25 06:23:06.000000000 -0700
@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3.  
 #include "coretypes.h"
 #include "opts.h"
 #include "options.h"
+#include "diagnostic.h"
 
 /* Perform a binary search to find which option the command-line INPUT
    matches.  Returns its index in the option array, and
@@ -453,3 +454,136 @@ done:
 
   free (options);
 }
+
+/* Handle option OPT_INDEX, and argument ARG, for the language
+   indicated by LANG_MASK, using the handlers in HANDLERS.  VALUE is
+   the option value as for the value field of cl_decoded_option.  KIND
+   is the diagnostic_t if this is a diagnostics option, DK_UNSPECIFIED
+   otherwise.  Returns false if the switch was invalid.  */
+
+bool
+handle_option (size_t opt_index, const char *arg, int value,
+	       unsigned int lang_mask, int kind,
+	       const struct cl_option_handlers *handlers)
+{
+  const struct cl_option *option = &cl_options[opt_index];
+  size_t i;
+
+  if (option->flag_var)
+    set_option (opt_index, value, arg, kind);
+
+  for (i = 0; i < handlers->num_handlers; i++)
+    if (option->flags & handlers->handlers[i].mask)
+      {
+	if (!handlers->handlers[i].handler (opt_index, arg, value,
+					    lang_mask, kind, handlers))
+	  return false;
+	else
+	  handlers->post_handling_callback (opt_index, arg, value,
+					    handlers->handlers[i].mask);
+      }
+  
+  return true;
+}
+
+/* Handle the switch DECODED for the language indicated by LANG_MASK,
+   using the handlers in *HANDLERS.  */
+
+void
+read_cmdline_option (struct cl_decoded_option *decoded,
+		     unsigned int lang_mask,
+		     const struct cl_option_handlers *handlers)
+{
+  const struct cl_option *option;
+  const char *opt;
+
+  if (decoded->opt_index == OPT_SPECIAL_unknown)
+    {
+      opt = decoded->arg;
+
+      if (handlers->unknown_option_callback (opt))
+	error ("unrecognized command line option %qs", opt);
+      return;
+    }
+
+  option = &cl_options[decoded->opt_index];
+  opt = decoded->orig_option_with_args_text;
+
+  if (decoded->errors & CL_ERR_DISABLED)
+    {
+      error ("command line option %qs"
+	     " is not supported by this configuration", opt);
+      return;
+    }
+
+  if (decoded->errors & CL_ERR_WRONG_LANG)
+    {
+      handlers->wrong_lang_callback (opt, option, lang_mask);
+      return;
+    }
+
+  if (decoded->errors & CL_ERR_MISSING_ARG)
+    {
+      if (option->missing_argument_error)
+	error (option->missing_argument_error, opt);
+      else
+	error ("missing argument to %qs", opt);
+      return;
+    }
+
+  if (decoded->errors & CL_ERR_UINT_ARG)
+    {
+      error ("argument to %qs should be a non-negative integer",
+	     option->opt_text);
+      return;
+    }
+
+  gcc_assert (!decoded->errors);
+
+  if (!handle_option (decoded->opt_index, decoded->arg, decoded->value,
+		      lang_mask, DK_UNSPECIFIED, handlers))
+    error ("unrecognized command line option %qs", opt);
+}
+
+/* Set any variable for option OPT_INDEX according to VALUE and ARG,
+   diagnostic kind KIND.  */
+
+void
+set_option (int opt_index, int value, const char *arg, int kind)
+{
+  const struct cl_option *option = &cl_options[opt_index];
+
+  if (!option->flag_var)
+    return;
+
+  switch (option->var_type)
+    {
+    case CLVC_BOOLEAN:
+	*(int *) option->flag_var = value;
+	break;
+
+    case CLVC_EQUAL:
+	*(int *) option->flag_var = (value
+				     ? option->var_value
+				     : !option->var_value);
+	break;
+
+    case CLVC_BIT_CLEAR:
+    case CLVC_BIT_SET:
+	if ((value != 0) == (option->var_type == CLVC_BIT_SET))
+	  *(int *) option->flag_var |= option->var_value;
+	else
+	  *(int *) option->flag_var &= ~option->var_value;
+	if (option->flag_var == &target_flags)
+	  target_flags_explicit |= option->var_value;
+	break;
+
+    case CLVC_STRING:
+	*(const char **) option->flag_var = arg;
+	break;
+    }
+
+  if ((diagnostic_t) kind != DK_UNSPECIFIED)
+    diagnostic_classify_diagnostic (global_dc, opt_index, (diagnostic_t) kind,
+				    UNKNOWN_LOCATION);
+}
diff -rupN --exclude=.svn gcc-mainline-opt2-missing-arg/gcc/opts.c gcc-mainline/gcc/opts.c
--- gcc-mainline-opt2-missing-arg/gcc/opts.c	2010-06-25 06:15:53.000000000 -0700
+++ gcc-mainline/gcc/opts.c	2010-06-25 06:22:04.000000000 -0700
@@ -372,8 +372,9 @@ bool flag_warn_unused_result = false;
 const char **in_fnames;
 unsigned num_in_fnames;
 
-static int common_handle_option (size_t scode, const char *arg, int value,
-				 unsigned int lang_mask, int kind);
+static bool common_handle_option (size_t scode, const char *arg, int value,
+				  unsigned int lang_mask, int kind,
+				  const struct cl_option_handlers *handlers);
 static void handle_param (const char *);
 static char *write_langs (unsigned int lang_mask);
 static void complain_wrong_lang (const char *, const struct cl_option *,
@@ -460,112 +461,58 @@ void print_ignored_options (void)
   input_location = saved_loc;
 }
 
+/* Handle an unknown option ARG, returning true if an error should be
+   given.  */
 
-/* Handle option OPT_INDEX, and argument ARG, for the language
-   indicated by LANG_MASK.  VALUE is true, unless no- form of an -f or
-   -W option was given.  KIND is the diagnostic_t if this is a
-   diagnostics option, DK_UNSPECIFIED otherwise.  Returns false if the
-   switch was invalid.  */
-bool
-handle_option (int opt_index, int value, const char *arg,
-		unsigned int lang_mask, int kind)
+static bool
+unknown_option_callback (const char *opt)
 {
-  const struct cl_option *option = &cl_options[opt_index];
-
-  if (option->flag_var)
-    set_option (opt_index, value, arg, kind);
-  
-  if (option->flags & lang_mask)
+  if (opt[1] == 'W' && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
     {
-      if (lang_hooks.handle_option (opt_index, arg, value, kind) == 0)
-	return false;
-#ifdef ENABLE_LTO
-      else
-	lto_register_user_option (opt_index, arg, value, lang_mask);
- #endif
+      /* We don't generate warnings for unknown -Wno-* options unless
+	 we issue diagnostics.  */
+      postpone_unknown_option_warning (opt);
+      return false;
     }
+  else
+    return true;
+}
 
-  if (option->flags & CL_COMMON)
-    {
-      if (common_handle_option (opt_index, arg, value, lang_mask, kind) == 0)
-	return false;
-#ifdef ENABLE_LTO
-      else
-	lto_register_user_option (opt_index, arg, value, CL_COMMON);
-#endif
-    }
+/* Note that an option (index OPT_INDEX, argument ARG, value VALUE)
+   has been successfully handled with a handler for mask MASK.  */
 
-  if (option->flags & CL_TARGET)
-    {
-      if (!targetm.handle_option (opt_index, arg, value))
-	return false;
+static void
+post_handling_callback (size_t opt_index ATTRIBUTE_UNUSED,
+			const char *arg ATTRIBUTE_UNUSED,
+			int value ATTRIBUTE_UNUSED,
+			unsigned int mask ATTRIBUTE_UNUSED)
+{
 #ifdef ENABLE_LTO
-      else
-	lto_register_user_option (opt_index, arg, value, CL_TARGET);
+  lto_register_user_option (opt_index, arg, value, mask);
 #endif
-    }
-  return true;
 }
 
-/* Handle the switch DECODED for the language indicated by
-   LANG_MASK.  */
-static void
-read_cmdline_option (struct cl_decoded_option *decoded,
-		     unsigned int lang_mask)
-{
-  const struct cl_option *option;
-  const char *opt;
-
-  if (decoded->opt_index == OPT_SPECIAL_unknown)
-    {
-      opt = decoded->arg;
-
-      if (opt[1] == 'W' && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
-	/* We don't generate warnings for unknown -Wno-* options
-	   unless we issue diagnostics.  */
-	  postpone_unknown_option_warning (opt);
-      else
-	error ("unrecognized command line option %qs", opt);
-      return;
-    }
-
-  option = &cl_options[decoded->opt_index];
-  opt = decoded->orig_option_with_args_text;
+/* Handle a front-end option; arguments and return value as for
+   handle_option.  */
 
-  if (decoded->errors & CL_ERR_DISABLED)
-    {
-      error ("command line option %qs"
-	     " is not supported by this configuration", opt);
-      return;
-    }
-
-  if (decoded->errors & CL_ERR_WRONG_LANG)
-    {
-      complain_wrong_lang (opt, option, lang_mask);
-      return;
-    }
-
-  if (decoded->errors & CL_ERR_MISSING_ARG)
-    {
-      if (option->missing_argument_error)
-	error (option->missing_argument_error, opt);
-      else
-	error ("missing argument to %qs", opt);
-      return;
-    }
-
-  if (decoded->errors & CL_ERR_UINT_ARG)
-    {
-      error ("argument to %qs should be a non-negative integer",
-	     option->opt_text);
-      return;
-    }
+static bool
+lang_handle_option (size_t opt_index, const char *arg, int value,
+		    unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
+		    const struct cl_option_handlers *handlers)
+{
+  return lang_hooks.handle_option (opt_index, arg, value, kind, handlers);
+}
 
-  gcc_assert (!decoded->errors);
+/* Handle a back-end option; arguments and return value as for
+   handle_option.  */
 
-  if (!handle_option (decoded->opt_index, decoded->value, decoded->arg,
-		      lang_mask, DK_UNSPECIFIED))
-    error ("unrecognized command line option %qs", opt);
+static bool
+target_handle_option (size_t opt_index, const char *arg, int value,
+		    unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
+		    const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
+{
+  gcc_assert (kind == DK_UNSPECIFIED);
+  return targetm.handle_option (opt_index, arg, value);
 }
 
 /* Handle FILENAME from the command line.  */
@@ -659,11 +606,12 @@ flag_instrument_functions_exclude_p (tre
 
 /* Handle the vector of command line options.  LANG_MASK
    contains has a single bit set representing the current
-   language.  */
+   language.  HANDLERS describes what functions to call for the options.  */
 static void
 read_cmdline_options (struct cl_decoded_option *decoded_options,
 		      unsigned int decoded_options_count,
-		      unsigned int lang_mask)
+		      unsigned int lang_mask,
+		      const struct cl_option_handlers *handlers)
 {
   unsigned int i;
 
@@ -681,7 +629,7 @@ read_cmdline_options (struct cl_decoded_
 	  continue;
 	}
 
-      read_cmdline_option (decoded_options + i, lang_mask);
+      read_cmdline_option (decoded_options + i, lang_mask, handlers);
     }
 }
 
@@ -698,6 +646,7 @@ decode_options (unsigned int argc, const
   static int initial_max_fields_for_field_sensitive;
   static int initial_loop_invariant_max_bbs_in_loop;
   static unsigned int initial_lang_mask;
+  struct cl_option_handlers handlers;
 
   unsigned int i, lang_mask;
   int opt1;
@@ -730,6 +679,17 @@ decode_options (unsigned int argc, const
     /* Perform language-specific options initialization.  */
     lang_hooks.init_options (*decoded_options_count, *decoded_options);
 
+  handlers.unknown_option_callback = unknown_option_callback;
+  handlers.wrong_lang_callback = complain_wrong_lang;
+  handlers.post_handling_callback = post_handling_callback;
+  handlers.num_handlers = 3;
+  handlers.handlers[0].handler = lang_handle_option;
+  handlers.handlers[0].mask = lang_mask;
+  handlers.handlers[1].handler = common_handle_option;
+  handlers.handlers[1].mask = CL_COMMON;
+  handlers.handlers[2].handler = target_handle_option;
+  handlers.handlers[2].mask = CL_TARGET;
+
   /* Scan to see what optimization level has been specified.  That will
      determine the default value of many flags.  */
   for (i = 1; i < *decoded_options_count; i++)
@@ -903,7 +863,7 @@ decode_options (unsigned int argc, const
     }
 
   /* Enable -Werror=coverage-mismatch by default */
-  enable_warning_as_error("coverage-mismatch", 1, lang_mask);
+  enable_warning_as_error ("coverage-mismatch", 1, lang_mask, &handlers);
 
   if (first_time_p)
     {
@@ -931,7 +891,8 @@ decode_options (unsigned int argc, const
   OPTIMIZATION_OPTIONS (optimize, optimize_size);
 #endif
 
-  read_cmdline_options (*decoded_options, *decoded_options_count, lang_mask);
+  read_cmdline_options (*decoded_options, *decoded_options_count, lang_mask,
+			&handlers);
 
   if (dump_base_name && ! IS_ABSOLUTE_PATH (dump_base_name))
     {
@@ -1425,9 +1386,10 @@ print_specific_help (unsigned int includ
    extra handling need to be listed here; if you simply want
    VALUE assigned to a variable, it happens automatically.  */
 
-static int
+static bool
 common_handle_option (size_t scode, const char *arg, int value,
-		      unsigned int lang_mask, int kind ATTRIBUTE_UNUSED)
+		      unsigned int lang_mask, int kind ATTRIBUTE_UNUSED,
+		      const struct cl_option_handlers *handlers)
 {
   static bool verbose = false;
   enum opt_code code = (enum opt_code) scode;
@@ -1609,7 +1571,7 @@ common_handle_option (size_t scode, cons
       break;
 
     case OPT_Werror_:
-      enable_warning_as_error (arg, value, lang_mask);
+      enable_warning_as_error (arg, value, lang_mask, handlers);
       break;
 
     case OPT_Wlarger_than_:
@@ -1735,7 +1697,7 @@ common_handle_option (size_t scode, cons
 	diagnostic_prefixing_rule (global_dc)
 	  = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
       else
-	return 0;
+	return false;
       break;
 
     case OPT_fdiagnostics_show_option:
@@ -1744,7 +1706,7 @@ common_handle_option (size_t scode, cons
 
     case OPT_fdump_:
       if (!dump_switch_p (arg))
-	return 0;
+	return false;
       break;
 
     case OPT_fexcess_precision_:
@@ -1908,7 +1870,7 @@ common_handle_option (size_t scode, cons
     case OPT_frandom_seed:
       /* The real switch is -fno-random-seed.  */
       if (value)
-	return 0;
+	return false;
       set_random_seed (NULL);
       break;
 
@@ -1926,7 +1888,7 @@ common_handle_option (size_t scode, cons
       fix_sched_param ("verbose", arg);
       break;
 #else
-      return 0;
+      return false;
 #endif
 
     case OPT_fsched_stalled_insns_:
@@ -1973,7 +1935,7 @@ common_handle_option (size_t scode, cons
     case OPT_fstack_limit:
       /* The real switch is -fno-stack-limit.  */
       if (value)
-	return 0;
+	return false;
       stack_limit_rtx = NULL_RTX;
       break;
 
@@ -2140,7 +2102,7 @@ common_handle_option (size_t scode, cons
       break;
     }
 
-  return 1;
+  return true;
 }
 
 /* Handle --param NAME=VALUE.  */
@@ -2355,49 +2317,6 @@ get_option_state (int option, struct cl_
   return true;
 }
 
-/* Set *OPTION according to VALUE and ARG.  */
-
-void
-set_option (int opt_index, int value, const char *arg, int kind)
-{
-  const struct cl_option *option = &cl_options[opt_index];
-
-  if (!option->flag_var)
-    return;
-
-  switch (option->var_type)
-    {
-    case CLVC_BOOLEAN:
-	*(int *) option->flag_var = value;
-	break;
-
-    case CLVC_EQUAL:
-	*(int *) option->flag_var = (value
-				     ? option->var_value
-				     : !option->var_value);
-	break;
-
-    case CLVC_BIT_CLEAR:
-    case CLVC_BIT_SET:
-	if ((value != 0) == (option->var_type == CLVC_BIT_SET))
-	  *(int *) option->flag_var |= option->var_value;
-	else
-	  *(int *) option->flag_var &= ~option->var_value;
-	if (option->flag_var == &target_flags)
-	  target_flags_explicit |= option->var_value;
-	break;
-
-    case CLVC_STRING:
-	*(const char **) option->flag_var = arg;
-	break;
-    }
-
-  if ((diagnostic_t)kind != DK_UNSPECIFIED)
-    diagnostic_classify_diagnostic (global_dc, opt_index, (diagnostic_t)kind,
-				    UNKNOWN_LOCATION);
-}
-
-
 /* Callback function, called when -Werror= enables a warning.  */
 
 static void (*warning_as_error_callback) (int) = NULL;
@@ -2415,7 +2334,8 @@ register_warning_as_error_callback (void
    also by legacy Werror-implicit-function-declaration.  */
 
 void
-enable_warning_as_error (const char *arg, int value, unsigned int lang_mask)
+enable_warning_as_error (const char *arg, int value, unsigned int lang_mask,
+			 const struct cl_option_handlers *handlers)
 {
   char *new_option;
   int option_index;
@@ -2440,7 +2360,8 @@ enable_warning_as_error (const char *arg
 
 	  /* -Werror=foo implies -Wfoo.  */
 	  if (option->var_type == CLVC_BOOLEAN)
-	    handle_option (option_index, value, arg, lang_mask, (int)kind);
+	    handle_option (option_index, arg, value, lang_mask, (int)kind,
+			   handlers);
 
 	  if (warning_as_error_callback)
 	    warning_as_error_callback (option_index);
diff -rupN --exclude=.svn gcc-mainline-opt2-missing-arg/gcc/opts.h gcc-mainline/gcc/opts.h
--- gcc-mainline-opt2-missing-arg/gcc/opts.h	2010-06-25 06:15:53.000000000 -0700
+++ gcc-mainline/gcc/opts.h	2010-06-25 06:21:00.000000000 -0700
@@ -135,6 +135,47 @@ struct cl_decoded_option
   int errors;
 };
 
+/* Structure describing a single option-handling callback.  */
+
+struct cl_option_handler_func
+{
+  /* The function called to handle the option.  */
+  bool (*handler) (size_t opt_index, const char *arg, int value,
+		   unsigned int lang_mask, int kind,
+		   const struct cl_option_handlers *handlers);
+
+  /* The mask that must have some bit in common with the flags for the
+     option for this particular handler to be used.  */
+  unsigned int mask;
+};
+
+/* Structure describing the callbacks used in handling options.  */
+
+struct cl_option_handlers
+{
+  /* Callback for an unknown option to determine whether to give an
+     error for it, and possibly store information to diagnose the
+     option at a later point.  Return true if an error should be
+     given, false otherwise.  */
+  bool (*unknown_option_callback) (const char *opt);
+
+  /* Callback to handle, and possibly diagnose, an option for another
+     language.  */
+  void (*wrong_lang_callback) (const char *text,
+			       const struct cl_option *option,
+			       unsigned int lang_mask);
+
+  /* Callback to call after the successful handling of any option.  */
+  void (*post_handling_callback) (size_t opt_index, const char *arg,
+				  int value, unsigned int mask);
+
+  /* The number of individual handlers.  */
+  size_t num_handlers;
+
+  /* The handlers themselves.  */
+  struct cl_option_handler_func handlers[3];
+};
+
 /* Input file names.  */
 
 extern const char **in_fnames;
@@ -157,10 +198,15 @@ extern void decode_options (unsigned int
 extern int option_enabled (int opt_idx);
 extern bool get_option_state (int, struct cl_option_state *);
 extern void set_option (int opt_index, int value, const char *arg, int);
-bool handle_option (int opt_index, int value, const char *arg,
-		    unsigned int lang_mask, int kind);
+bool handle_option (size_t opt_index, const char *arg, int value,
+		    unsigned int lang_mask, int kind,
+		    const struct cl_option_handlers *handlers);
+extern void read_cmdline_option (struct cl_decoded_option *decoded,
+				 unsigned int lang_mask,
+				 const struct cl_option_handlers *handlers);
 extern void register_warning_as_error_callback (void (*callback) (int));
 extern void enable_warning_as_error (const char *arg, int value,
-				     unsigned int lang_mask);
+				     unsigned int lang_mask,
+				     const struct cl_option_handlers *handlers);
 extern void print_ignored_options (void);
 #endif

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Ada,C++,etc.] Options patches pending review
  2010-06-25 16:57 ` Joseph S. Myers
@ 2010-06-25 18:26   ` Arnaud Charlet
  2010-07-02 11:29   ` Geert Bosch
  1 sibling, 0 replies; 8+ messages in thread
From: Arnaud Charlet @ 2010-06-25 18:26 UTC (permalink / raw)
  To: Joseph S. Myers, Eric Botcazou; +Cc: gcc-patches, bosch, dewar, Arnaud Charlet

> Ada review still needed.

Right, the tricky part is changing the handling of gnat_argv, so that's why
it's taking some time to review, plus the fact that we're quite busy with
our own internal transition to GCC 4.5, but Eric is looking at these
patches.

Arno

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Ada,C++,etc.] Options patches pending review
  2010-06-24 17:28 [Ada,C++,etc.] Options patches pending review Joseph S. Myers
  2010-06-24 19:44 ` Mike Stump
  2010-06-25 16:57 ` Joseph S. Myers
@ 2010-06-30 21:36 ` Jason Merrill
  2010-06-30 21:53 ` Diego Novillo
  3 siblings, 0 replies; 8+ messages in thread
From: Jason Merrill @ 2010-06-30 21:36 UTC (permalink / raw)
  To: Joseph S. Myers
  Cc: gcc-patches, bosch, dewar, charlet, Mark Mitchell, Nathan Sidwell

On 06/24/2010 12:00 PM, Joseph S. Myers wrote:
> Various recent option handling patches of mine have got bogged down in
> piecemeal review of bits of the patches.  In particular, several currently
> needs review of C++ and Ada pieces.
>
> <http://gcc.gnu.org/ml/gcc-patches/2010-06/msg01968.html>  needs C++ and
> Ada review.

C++ OK.

> <http://gcc.gnu.org/ml/gcc-patches/2010-06/msg02150.html>  needs C++
> review.

C++ OK.

Jason

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Ada,C++,etc.] Options patches pending review
  2010-06-24 17:28 [Ada,C++,etc.] Options patches pending review Joseph S. Myers
                   ` (2 preceding siblings ...)
  2010-06-30 21:36 ` Jason Merrill
@ 2010-06-30 21:53 ` Diego Novillo
  3 siblings, 0 replies; 8+ messages in thread
From: Diego Novillo @ 2010-06-30 21:53 UTC (permalink / raw)
  To: Joseph S. Myers
  Cc: gcc-patches, bosch, dewar, charlet, jason, Mark Mitchell, Nathan Sidwell

On Thu, Jun 24, 2010 at 12:00, Joseph S. Myers <joseph@codesourcery.com> wrote:

> <http://gcc.gnu.org/ml/gcc-patches/2010-06/msg02260.html> needs review for
> Ada and LTO pieces and the main language-independent part of the patch.

OK for the LTO and language-independent parts.


> <http://gcc.gnu.org/ml/gcc-patches/2010-06/msg02377.html> needs review for
> the whole patch (including Ada and Fortran pieces).

Likewise (though I see that Richi already approved the non FE parts).


Diego.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Ada,C++,etc.] Options patches pending review
  2010-06-25 16:57 ` Joseph S. Myers
  2010-06-25 18:26   ` Arnaud Charlet
@ 2010-07-02 11:29   ` Geert Bosch
  2010-07-27 10:07     ` Joseph S. Myers
  1 sibling, 1 reply; 8+ messages in thread
From: Geert Bosch @ 2010-07-02 11:29 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: gcc-patches, bosch, dewar, charlet



On Jun 25, 2010, at 11:10, "Joseph S. Myers" <joseph@codesourcery.com>  
wrote:

> On Thu, 24 Jun 2010, Joseph S. Myers wrote:
>
>> Various recent option handling patches of mine have got bogged down  
>> in
>> piecemeal review of bits of the patches.  In particular, several  
>> currently
>> needs review of C++ and Ada pieces.
>
> An update to the status of this series (four presently uncommitted
> patches, but one of those is now completely approved):
>
>> <http://gcc.gnu.org/ml/gcc-patches/2010-06/msg01968.html> needs C++  
>> and
>> Ada review.
>
> Ada review still needed.

Ada changes are OK.
>> <http://gcc.gnu.org/ml/gcc-patches/2010-06/msg02260.html> needs  
>> review for
>> Ada and LTO pieces and the main language-independent part of the  
>> patch.
>>
>> <http://gcc.gnu.org/ml/gcc-patches/2010-06/msg02377.html> needs  
>> review for
>> the whole patch (including Ada and Fortran pieces).
>
> If you wish to consider the Ada pieces as less mechanical than the  
> purely
> mechanical changes to other front ends, then these also still need Ada
> review.
Ada changes OK.

   -Geert
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Ada,C++,etc.] Options patches pending review
  2010-07-02 11:29   ` Geert Bosch
@ 2010-07-27 10:07     ` Joseph S. Myers
  0 siblings, 0 replies; 8+ messages in thread
From: Joseph S. Myers @ 2010-07-27 10:07 UTC (permalink / raw)
  To: Geert Bosch; +Cc: gcc-patches, bosch, dewar, charlet

On Fri, 2 Jul 2010, Geert Bosch wrote:

> > > <http://gcc.gnu.org/ml/gcc-patches/2010-06/msg01968.html> needs C++ and
> > > Ada review.
> > 
> > Ada review still needed.
> 
> Ada changes are OK.

Thanks for the review.  I have now updated the patch to apply to current 
trunk, retested and committed in the following form.

2010-07-27  Joseph Myers  <joseph@codesourcery.com>

	* langhooks-def.h (lhd_init_options, LANG_HOOKS_OPTION_LANG_MASK,
	LANG_HOOKS_COMPLAIN_WRONG_LANG_P): New.
	(LANG_HOOKS_INIT_OPTIONS): Update default definition.
	(LANG_HOOKS_INITIALIZER): Add new hooks.
	* langhooks.c (lhd_init_options, lhd_complain_wrong_lang_p): New.
	* langhooks.h (struct lang_hooks): Add new hooks option_lang_mask
	and complain_wrong_lang_p.  Update init_options prototype.
	* c-objc-common.c (c_initialize_diagnostics): First call
	c_common_initialize_diagnostics.
	* c-objc-common.h (LANG_HOOKS_OPTION_LANG_MASK,
	LANG_HOOKS_COMPLAIN_WRONG_LANG_P): Define.
	* coretypes.h (struct cl_option, struct cl_decoded_option):
	Declare.
	* hooks.c (hook_uint_uint_constcharptrptr_0): Remove.
	(hook_uint_void_0): New.
	* hooks.h (hook_uint_uint_constcharptrptr_0): Remove.
	(hook_uint_void_0): New.
	* opts-common.c (decode_cmdline_option,
	decode_cmdline_options_to_array): Also fill in canonical_option
	field.
	* opts.c (complain_wrong_lang): Use langhook to determine whether
	to complain instead of special-casing LTO.
	(decode_options): Separate lang_mask determination with
	option_lang_mask hook from call of init_options hook.
	* opts.h (struct cl_decoded_option): Add canonical_option.

ada:
2010-07-27  Joseph Myers  <joseph@codesourcery.com>

	* gcc-interface/misc.c (gnat_option_lang_mask): New.
	(gnat_init_options): Update prototype.  Reconstruct argv array
	from decoded options.

c-family:
2010-07-27  Joseph Myers  <joseph@codesourcery.com>

	* c-common.h (c_common_option_lang_mask,
	c_common_initialize_diagnostics, c_common_complain_wrong_lang_p):
	New.
	(c_common_init_options): Update prototype.
	* c-opts.c (c_common_option_lang_mask): New.
	(c_common_initialize_diagnostics): Split out of
	c_common_init_options.
	(accept_all_c_family_options, c_common_complain_wrong_lang_p):
	New.
	(c_common_init_options): Update prototype.  Use decoded options in
	search for -lang-asm.

cp:
2010-07-27  Joseph Myers  <joseph@codesourcery.com>

	* cp-objcp-common.c (cxx_initialize_diagnostics): First call
	c_common_initialize_diagnostics.
	* cp-objcp-common.h (LANG_HOOKS_OPTION_LANG_MASK,
	LANG_HOOKS_COMPLAIN_WRONG_LANG_P): Define.

fortran:
2010-07-27  Joseph Myers  <joseph@codesourcery.com>

	* cpp.c (gfc_cpp_init_options): Update prototype.  Use number of
	decoded options in allocating deferred_opt.
	* cpp.h (gfc_cpp_init_options): Update prototype.
	* f95-lang.c (LANG_HOOKS_OPTION_LANG_MASK): Define.
	* gfortran.h (gfc_option_lang_mask): New.
	(gfc_init_options): Update prototype.
	* options.c (gfc_option_lang_mask): New.
	(gfc_init_options): Update prototype.  Pass new arguments to
	gfc_cpp_init_options.

java:
2010-07-27  Joseph Myers  <joseph@codesourcery.com>

	* lang.c (java_option_lang_mask): New.
	(java_init_options): Update prototype.
	(LANG_HOOKS_OPTION_LANG_MASK): Define.

lto:
2010-07-27  Joseph Myers  <joseph@codesourcery.com>

	* lto-lang.c (lto_option_lang_mask, lto_complain_wrong_lang_p):
	New.
	(lto_init_options): Update prototype.
	(LANG_HOOKS_OPTION_LANG_MASK, LANG_HOOKS_COMPLAIN_WRONG_LANG_P):
	Define.

Index: gcc/hooks.c
===================================================================
--- gcc/hooks.c	(revision 162559)
+++ gcc/hooks.c	(working copy)
@@ -1,5 +1,5 @@
 /* General-purpose hooks.
-   Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009
+   Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify it
@@ -176,8 +176,7 @@ hook_int_size_t_constcharptr_int_0 (size
 }
 
 unsigned int
-hook_uint_uint_constcharptrptr_0 (unsigned int a ATTRIBUTE_UNUSED,
-				  const char **b ATTRIBUTE_UNUSED)
+hook_uint_void_0 (void)
 {
   return 0;
 }
Index: gcc/hooks.h
===================================================================
--- gcc/hooks.h	(revision 162559)
+++ gcc/hooks.h	(working copy)
@@ -1,5 +1,5 @@
 /* General-purpose hooks.
-   Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009
+   Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify it
@@ -73,7 +73,7 @@ extern tree hook_tree_tree_tree_tree_nul
 extern tree hook_tree_tree_tree_tree_3rd_identity (tree, tree, tree);
 extern tree hook_tree_tree_int_treep_bool_null (tree, int, tree *, bool);
 
-extern unsigned hook_uint_uint_constcharptrptr_0 (unsigned, const char **);
+extern unsigned hook_uint_void_0 (void);
 
 extern bool default_can_output_mi_thunk_no_vcall (const_tree, HOST_WIDE_INT,
 						  HOST_WIDE_INT, const_tree);
Index: gcc/opts-common.c
===================================================================
--- gcc/opts-common.c	(revision 162559)
+++ gcc/opts-common.c	(working copy)
@@ -245,10 +245,14 @@ decode_cmdline_option (const char **argv
     {
     case 1:
       decoded->orig_option_with_args_text = argv[0];
+      decoded->canonical_option[0] = argv[0];
+      decoded->canonical_option[1] = NULL;
       break;
     case 2:
       decoded->orig_option_with_args_text = concat (argv[0], " ",
 						    argv[1], NULL);
+      decoded->canonical_option[0] = argv[0];
+      decoded->canonical_option[1] = argv[1];
       break;
     default:
       gcc_unreachable ();
@@ -279,6 +283,8 @@ decode_cmdline_options_to_array (unsigne
   opt_array[0].opt_index = OPT_SPECIAL_program_name;
   opt_array[0].arg = argv[0];
   opt_array[0].orig_option_with_args_text = argv[0];
+  opt_array[0].canonical_option[0] = argv[0];
+  opt_array[0].canonical_option[1] = NULL;
   opt_array[0].value = 1;
   opt_array[0].errors = 0;
   num_decoded_options = 1;
@@ -293,6 +299,8 @@ decode_cmdline_options_to_array (unsigne
 	  opt_array[num_decoded_options].opt_index = OPT_SPECIAL_input_file;
 	  opt_array[num_decoded_options].arg = opt;
 	  opt_array[num_decoded_options].orig_option_with_args_text = opt;
+	  opt_array[num_decoded_options].canonical_option[0] = opt;
+	  opt_array[num_decoded_options].canonical_option[1] = NULL;
 	  opt_array[num_decoded_options].value = 1;
 	  opt_array[num_decoded_options].errors = 0;
 	  num_decoded_options++;
Index: gcc/c-family/c-opts.c
===================================================================
--- gcc/c-family/c-opts.c	(revision 162559)
+++ gcc/c-family/c-opts.c	(working copy)
@@ -281,14 +281,19 @@ warning_as_error_callback (int option_in
     }
 }
 
-/* Common initialization before parsing options.  */
+/* Return language mask for option parsing.  */
 unsigned int
-c_common_init_options (unsigned int argc, const char **argv)
+c_common_option_lang_mask (void)
 {
   static const unsigned int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX};
-  unsigned int i, result;
-  struct cpp_callbacks *cb;
 
+  return lang_flags[c_language];
+}
+
+/* Common diagnostics initialization.  */
+void
+c_common_initialize_diagnostics (diagnostic_context *context)
+{
   /* Register callback for warnings enabled by -Werror=.  */
   register_warning_as_error_callback (warning_as_error_callback);
 
@@ -298,13 +303,37 @@ c_common_init_options (unsigned int argc
     {
       /* By default wrap lines at 80 characters.  Is getenv
 	 ("COLUMNS") preferable?  */
-      diagnostic_line_cutoff (global_dc) = 80;
+      diagnostic_line_cutoff (context) = 80;
       /* By default, emit location information once for every
 	 diagnostic message.  */
-      diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
+      diagnostic_prefixing_rule (context) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
     }
 
-  global_dc->opt_permissive = OPT_fpermissive;
+  context->opt_permissive = OPT_fpermissive;
+}
+
+/* Whether options from all C-family languages should be accepted
+   quietly.  */
+static bool accept_all_c_family_options = false;
+
+/* Return whether to complain about a wrong-language option.  */
+bool
+c_common_complain_wrong_lang_p (const struct cl_option *option)
+{
+  if (accept_all_c_family_options
+      && (option->flags & c_family_lang_mask))
+    return false;
+
+  return true;
+}
+
+/* Common initialization before calling option handlers.  */
+void
+c_common_init_options (unsigned int decoded_options_count,
+		       struct cl_decoded_option *decoded_options)
+{
+  unsigned int i;
+  struct cpp_callbacks *cb;
 
   parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX: CLK_GNUC89,
 				ident_hash, line_table);
@@ -327,23 +356,19 @@ c_common_init_options (unsigned int argc
   /* By default, C99-like requirements for complex multiply and divide.  */
   flag_complex_method = 2;
 
-  deferred_opts = XNEWVEC (struct deferred_opt, argc);
-
-  result = lang_flags[c_language];
+  deferred_opts = XNEWVEC (struct deferred_opt, decoded_options_count);
 
   if (c_language == clk_c)
     {
       /* If preprocessing assembly language, accept any of the C-family
 	 front end options since the driver may pass them through.  */
-      for (i = 1; i < argc; i++)
-	if (! strcmp (argv[i], "-lang-asm"))
+      for (i = 1; i < decoded_options_count; i++)
+	if (decoded_options[i].opt_index == OPT_lang_asm)
 	  {
-	    result |= CL_C | CL_ObjC | CL_CXX | CL_ObjCXX;
+	    accept_all_c_family_options = true;
 	    break;
 	  }
     }
-
-  return result;
 }
 
 /* Handle switch SCODE with argument ARG.  VALUE is true, unless no-
Index: gcc/c-family/c-common.h
===================================================================
--- gcc/c-family/c-common.h	(revision 162559)
+++ gcc/c-family/c-common.h	(working copy)
@@ -1,6 +1,6 @@
 /* Definitions for c-common.c.
    Copyright (C) 1987, 1993, 1994, 1995, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
+   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -724,7 +724,12 @@ extern void set_compound_literal_name (t
 
 extern tree build_va_arg (location_t, tree, tree);
 
-extern unsigned int c_common_init_options (unsigned int, const char **);
+struct diagnostic_context;
+
+extern unsigned int c_common_option_lang_mask (void);
+extern void c_common_initialize_diagnostics (struct diagnostic_context *);
+extern bool c_common_complain_wrong_lang_p (const struct cl_option *);
+extern void c_common_init_options (unsigned int, struct cl_decoded_option *);
 extern bool c_common_post_options (const char **);
 extern bool c_common_init (void);
 extern void c_common_finish (void);
Index: gcc/java/lang.c
===================================================================
--- gcc/java/lang.c	(revision 162559)
+++ gcc/java/lang.c	(working copy)
@@ -46,7 +46,8 @@ The Free Software Foundation is independ
 
 static bool java_init (void);
 static void java_finish (void);
-static unsigned int java_init_options (unsigned int, const char **);
+static unsigned int java_option_lang_mask (void);
+static void java_init_options (unsigned int, struct cl_decoded_option *);
 static bool java_post_options (const char **);
 
 static int java_handle_option (size_t scode, const char *arg, int value, int kind);
@@ -121,6 +122,8 @@ struct GTY(()) language_function {
 #define LANG_HOOKS_INIT java_init
 #undef LANG_HOOKS_FINISH
 #define LANG_HOOKS_FINISH java_finish
+#undef LANG_HOOKS_OPTION_LANG_MASK
+#define LANG_HOOKS_OPTION_LANG_MASK java_option_lang_mask
 #undef LANG_HOOKS_INIT_OPTIONS
 #define LANG_HOOKS_INIT_OPTIONS java_init_options
 #undef LANG_HOOKS_HANDLE_OPTION
@@ -525,8 +528,14 @@ lang_init_source (int level)
 }
 
 static unsigned int
-java_init_options (unsigned int argc ATTRIBUTE_UNUSED,
-		   const char **argv ATTRIBUTE_UNUSED)
+java_option_lang_mask (void)
+{
+  return CL_Java;
+}
+
+static void
+java_init_options (unsigned int decoded_options_count ATTRIBUTE_UNUSED,
+		   struct cl_decoded_option *decoded_options ATTRIBUTE_UNUSED)
 {
   flag_bounds_check = 1;
   flag_exceptions = 1;
@@ -542,8 +551,6 @@ java_init_options (unsigned int argc ATT
   flag_evaluation_order = 1;
 
   jcf_path_init ();
-
-  return CL_Java;
 }
 
 /* Post-switch processing.  */
Index: gcc/cp/cp-objcp-common.c
===================================================================
--- gcc/cp/cp-objcp-common.c	(revision 162559)
+++ gcc/cp/cp-objcp-common.c	(working copy)
@@ -129,8 +129,13 @@ cp_var_mod_type_p (tree type, tree fn)
 void
 cxx_initialize_diagnostics (diagnostic_context *context)
 {
-  pretty_printer *base = context->printer;
-  cxx_pretty_printer *pp = XNEW (cxx_pretty_printer);
+  pretty_printer *base;
+  cxx_pretty_printer *pp;
+
+  c_common_initialize_diagnostics (context);
+
+  base = context->printer;
+  pp = XNEW (cxx_pretty_printer);
   memcpy (pp_base (pp), base, sizeof (pretty_printer));
   pp_cxx_pretty_printer_init (pp);
   context->printer = (pretty_printer *) pp;
Index: gcc/cp/cp-objcp-common.h
===================================================================
--- gcc/cp/cp-objcp-common.h	(revision 162559)
+++ gcc/cp/cp-objcp-common.h	(working copy)
@@ -1,5 +1,6 @@
 /* Language hooks common to C++ and ObjC++ front ends.
-   Copyright (C) 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2005, 2007, 2008, 2009, 2010
+   Free Software Foundation, Inc.
    Contributed by Ziemowit Laski  <zlaski@apple.com>
 
 This file is part of GCC.
@@ -40,6 +41,10 @@ extern bool cp_function_decl_explicit_p 
 #define LANG_HOOKS_FINISH cxx_finish
 #undef LANG_HOOKS_CLEAR_BINDING_STACK
 #define LANG_HOOKS_CLEAR_BINDING_STACK pop_everything
+#undef LANG_HOOKS_OPTION_LANG_MASK
+#define LANG_HOOKS_OPTION_LANG_MASK c_common_option_lang_mask
+#undef LANG_HOOKS_COMPLAIN_WRONG_LANG_P
+#define LANG_HOOKS_COMPLAIN_WRONG_LANG_P c_common_complain_wrong_lang_p
 #undef LANG_HOOKS_INIT_OPTIONS
 #define LANG_HOOKS_INIT_OPTIONS c_common_init_options
 #undef LANG_HOOKS_INITIALIZE_DIAGNOSTICS
Index: gcc/c-objc-common.c
===================================================================
--- gcc/c-objc-common.c	(revision 162559)
+++ gcc/c-objc-common.c	(working copy)
@@ -184,8 +184,13 @@ has_c_linkage (const_tree decl ATTRIBUTE
 void
 c_initialize_diagnostics (diagnostic_context *context)
 {
-  pretty_printer *base = context->printer;
-  c_pretty_printer *pp = XNEW (c_pretty_printer);
+  pretty_printer *base;
+  c_pretty_printer *pp;
+
+  c_common_initialize_diagnostics (context);
+
+  base = context->printer;
+  pp = XNEW (c_pretty_printer);
   memcpy (pp_base (pp), base, sizeof (pretty_printer));
   pp_c_pretty_printer_init (pp);
   context->printer = (pretty_printer *) pp;
Index: gcc/c-objc-common.h
===================================================================
--- gcc/c-objc-common.h	(revision 162559)
+++ gcc/c-objc-common.h	(working copy)
@@ -1,5 +1,6 @@
 /* Language hooks common to C and ObjC front ends.
-   Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2005, 2007, 2008, 2009, 2010
+   Free Software Foundation, Inc.
    Contributed by Ziemowit Laski  <zlaski@apple.com>
 
 This file is part of GCC.
@@ -28,6 +29,10 @@ along with GCC; see the file COPYING3.  
 #define LANG_HOOKS_IDENTIFIER_SIZE C_SIZEOF_STRUCT_LANG_IDENTIFIER
 #undef LANG_HOOKS_FINISH
 #define LANG_HOOKS_FINISH c_common_finish
+#undef LANG_HOOKS_OPTION_LANG_MASK
+#define LANG_HOOKS_OPTION_LANG_MASK c_common_option_lang_mask
+#undef LANG_HOOKS_COMPLAIN_WRONG_LANG_P
+#define LANG_HOOKS_COMPLAIN_WRONG_LANG_P c_common_complain_wrong_lang_p
 #undef LANG_HOOKS_INIT_OPTIONS
 #define LANG_HOOKS_INIT_OPTIONS c_common_init_options
 #undef LANG_HOOKS_INITIALIZE_DIAGNOSTICS
Index: gcc/opts.c
===================================================================
--- gcc/opts.c	(revision 162559)
+++ gcc/opts.c	(working copy)
@@ -416,15 +416,7 @@ complain_wrong_lang (const char *text, c
 {
   char *ok_langs, *bad_lang;
 
-  /* The LTO front end inherits all the options from the first front
-     end that was used.  However, not all the original front end
-     options make sense in LTO.
-
-     A real solution would be to filter this in collect2, but collect2
-     does not have access to all the option attributes to know what to
-     filter.  So, in lto1 we silently accept inherited flags and do
-     nothing about it.  */
-  if (lang_mask & CL_LTO)
+  if (!lang_hooks.complain_wrong_lang_p (option))
     return;
 
   ok_langs = write_langs (option->flags);
@@ -715,7 +707,7 @@ decode_options (unsigned int argc, const
   if (first_time_p)
     {
       /* Perform language-specific options initialization.  */
-      initial_lang_mask = lang_mask = lang_hooks.init_options (argc, argv);
+      initial_lang_mask = lang_mask = lang_hooks.option_lang_mask ();
 
       lang_hooks.initialize_diagnostics (global_dc);
 
@@ -732,6 +724,9 @@ decode_options (unsigned int argc, const
 
   decode_cmdline_options_to_array (argc, argv, lang_mask,
 				   decoded_options, decoded_options_count);
+  if (first_time_p)
+    /* Perform language-specific options initialization.  */
+    lang_hooks.init_options (*decoded_options_count, *decoded_options);
 
   /* Scan to see what optimization level has been specified.  That will
      determine the default value of many flags.  */
Index: gcc/opts.h
===================================================================
--- gcc/opts.h	(revision 162559)
+++ gcc/opts.h	(working copy)
@@ -117,6 +117,14 @@ struct cl_decoded_option
      -frecord-gcc-switches.  */
   const char *orig_option_with_args_text;
 
+  /* The canonical form of the option and its argument, for when it is
+     necessary to reconstruct argv elements (in particular, for
+     processing specs and passing options to subprocesses from the
+     driver).  The first element of this array is non-NULL; the second
+     is NULL if the canonical form uses only one argv element,
+     non-NULL otherwise.  */
+  const char *canonical_option[2];
+
   /* For a boolean option, 1 for the true case and 0 for the "no-"
      case.  For an unsigned integer option, the value of the
      argument.  1 in all other cases.  */
Index: gcc/ada/gcc-interface/misc.c
===================================================================
--- gcc/ada/gcc-interface/misc.c	(revision 162559)
+++ gcc/ada/gcc-interface/misc.c	(working copy)
@@ -61,7 +61,9 @@
 #include "gigi.h"
 
 static bool gnat_init			(void);
-static unsigned int gnat_init_options	(unsigned int, const char **);
+static unsigned int gnat_option_lang_mask (void);
+static void gnat_init_options		(unsigned int,
+					 struct cl_decoded_option *);
 static int gnat_handle_option		(size_t, const char *, int, int);
 static bool gnat_post_options		(const char **);
 static alias_set_type gnat_get_alias_set (tree);
@@ -85,6 +87,8 @@ static tree gnat_eh_personality		(void);
 #define LANG_HOOKS_IDENTIFIER_SIZE	sizeof (struct tree_identifier)
 #undef  LANG_HOOKS_INIT
 #define LANG_HOOKS_INIT			gnat_init
+#undef  LANG_HOOKS_OPTION_LANG_MASK
+#define LANG_HOOKS_OPTION_LANG_MASK	gnat_option_lang_mask
 #undef  LANG_HOOKS_INIT_OPTIONS
 #define LANG_HOOKS_INIT_OPTIONS		gnat_init_options
 #undef  LANG_HOOKS_HANDLE_OPTION
@@ -249,22 +253,43 @@ gnat_handle_option (size_t scode, const 
   return 1;
 }
 
-/* Initialize for option processing.  */
+/* Return language mask for option processing.  */
 
 static unsigned int
-gnat_init_options (unsigned int argc, const char **argv)
+gnat_option_lang_mask (void)
 {
-  gnat_argv = (char **) xmalloc (sizeof (argv[0]));
-  gnat_argv[0] = xstrdup (argv[0]);     /* name of the command */
-  gnat_argc = 1;
+  return CL_Ada;
+}
 
-  save_argc = argc;
-  save_argv = argv;
+/* Initialize for option processing.  */
+
+static void
+gnat_init_options (unsigned int decoded_options_count,
+		   struct cl_decoded_option *decoded_options)
+{
+  /* Reconstruct an argv array for use of back_end.adb.
+
+     ??? back_end.adb should not rely on this; instead, it should work
+     with decoded options without such reparsing, to ensure
+     consistency in how options are decoded.  */
+  unsigned int i;
+
+  save_argv = XNEWVEC (const char *, 2 * decoded_options_count + 1);
+  save_argc = 0;
+  for (i = 0; i < decoded_options_count; i++)
+    {
+      save_argv[save_argc++] = decoded_options[i].canonical_option[0];
+      if (decoded_options[i].canonical_option[1] != NULL)
+	save_argv[save_argc++] = decoded_options[i].canonical_option[1];
+    }
+  save_argv[save_argc] = NULL;
+
+  gnat_argv = (char **) xmalloc (sizeof (save_argv[0]));
+  gnat_argv[0] = xstrdup (save_argv[0]);     /* name of the command */
+  gnat_argc = 1;
 
   /* Uninitialized really means uninitialized in Ada.  */
   flag_zero_initialized_in_bss = 0;
-
-  return CL_Ada;
 }
 
 /* Post-switch processing.  */
Index: gcc/fortran/cpp.c
===================================================================
--- gcc/fortran/cpp.c	(revision 162559)
+++ gcc/fortran/cpp.c	(working copy)
@@ -304,8 +304,8 @@ gfc_cpp_temporary_file (void)
 }
 
 void
-gfc_cpp_init_options (unsigned int argc,
-		      const char **argv ATTRIBUTE_UNUSED)
+gfc_cpp_init_options (unsigned int decoded_options_count,
+		      struct cl_decoded_option *decoded_options ATTRIBUTE_UNUSED)
 {
   /* Do not create any objects from libcpp here. If no
      preprocessing is requested, this would be wasted
@@ -337,7 +337,8 @@ gfc_cpp_init_options (unsigned int argc,
   gfc_cpp_option.prefix = NULL;
   gfc_cpp_option.sysroot = NULL;
 
-  gfc_cpp_option.deferred_opt = XNEWVEC (gfc_cpp_deferred_opt_t, argc);
+  gfc_cpp_option.deferred_opt = XNEWVEC (gfc_cpp_deferred_opt_t,
+					 decoded_options_count);
   gfc_cpp_option.deferred_opt_count = 0;
 }
 
Index: gcc/fortran/cpp.h
===================================================================
--- gcc/fortran/cpp.h	(revision 162559)
+++ gcc/fortran/cpp.h	(working copy)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2008 Free Software Foundation, Inc.
+/* Copyright (C) 2008, 2010 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -36,7 +36,8 @@ const char *gfc_cpp_temporary_file (void
 void gfc_cpp_init_0 (void);
 void gfc_cpp_init (void);
 
-void gfc_cpp_init_options (unsigned int argc, const char **argv);
+void gfc_cpp_init_options (unsigned int decoded_options_count,
+			   struct cl_decoded_option *decoded_options);
 
 int gfc_cpp_handle_option(size_t scode, const char *arg, int value);
 
Index: gcc/fortran/gfortran.h
===================================================================
--- gcc/fortran/gfortran.h	(revision 162559)
+++ gcc/fortran/gfortran.h	(working copy)
@@ -2355,7 +2355,9 @@ void gfc_done_2 (void);
 int get_c_kind (const char *, CInteropKind_t *);
 
 /* options.c */
-unsigned int gfc_init_options (unsigned int, const char **);
+unsigned int gfc_option_lang_mask (void);
+void gfc_init_options (unsigned int,
+		       struct cl_decoded_option *);
 int gfc_handle_option (size_t, const char *, int, int);
 bool gfc_post_options (const char **);
 
Index: gcc/fortran/f95-lang.c
===================================================================
--- gcc/fortran/f95-lang.c	(revision 162559)
+++ gcc/fortran/f95-lang.c	(working copy)
@@ -101,6 +101,7 @@ static void gfc_init_ts (void);
 #undef LANG_HOOKS_INIT
 #undef LANG_HOOKS_FINISH
 #undef LANG_HOOKS_WRITE_GLOBALS
+#undef LANG_HOOKS_OPTION_LANG_MASK
 #undef LANG_HOOKS_INIT_OPTIONS
 #undef LANG_HOOKS_HANDLE_OPTION
 #undef LANG_HOOKS_POST_OPTIONS
@@ -130,6 +131,7 @@ static void gfc_init_ts (void);
 #define LANG_HOOKS_INIT                 gfc_init
 #define LANG_HOOKS_FINISH               gfc_finish
 #define LANG_HOOKS_WRITE_GLOBALS	gfc_write_global_declarations
+#define LANG_HOOKS_OPTION_LANG_MASK	gfc_option_lang_mask
 #define LANG_HOOKS_INIT_OPTIONS         gfc_init_options
 #define LANG_HOOKS_HANDLE_OPTION        gfc_handle_option
 #define LANG_HOOKS_POST_OPTIONS		gfc_post_options
Index: gcc/fortran/options.c
===================================================================
--- gcc/fortran/options.c	(revision 162559)
+++ gcc/fortran/options.c	(working copy)
@@ -53,11 +53,21 @@ set_default_std_flags (void)
 }
 
 
+/* Return language mask for Fortran options.  */
+
+unsigned int
+gfc_option_lang_mask (void)
+{
+  return CL_Fortran;
+}
+
+
 /* Get ready for options handling. Keep in sync with
    libgfortran/runtime/compile_options.c (init_compile_options). */
 
-unsigned int
-gfc_init_options (unsigned int argc, const char **argv)
+void
+gfc_init_options (unsigned int decoded_options_count,
+		  struct cl_decoded_option *decoded_options)
 {
   gfc_source_file = NULL;
   gfc_option.module_dir = NULL;
@@ -143,9 +153,7 @@ gfc_init_options (unsigned int argc, con
   flag_short_enums = targetm.default_short_enums ();
 
   /* Initialize cpp-related options.  */
-  gfc_cpp_init_options(argc, argv);
-
-  return CL_Fortran;
+  gfc_cpp_init_options (decoded_options_count, decoded_options);
 }
 
 
Index: gcc/langhooks.c
===================================================================
--- gcc/langhooks.c	(revision 162559)
+++ gcc/langhooks.c	(working copy)
@@ -337,6 +337,20 @@ lhd_initialize_diagnostics (struct diagn
 {
 }
 
+/* Called to perform language-specific options initialization.  */
+void
+lhd_init_options (unsigned int decoded_options_count ATTRIBUTE_UNUSED,
+		  struct cl_decoded_option *decoded_options ATTRIBUTE_UNUSED)
+{
+}
+
+/* By default, always complain about options for the wrong language.  */
+bool
+lhd_complain_wrong_lang_p (const struct cl_option *option ATTRIBUTE_UNUSED)
+{
+  return true;
+}
+
 /* The default function to print out name of current function that caused
    an error.  */
 void
Index: gcc/langhooks.h
===================================================================
--- gcc/langhooks.h	(revision 162559)
+++ gcc/langhooks.h	(working copy)
@@ -1,5 +1,5 @@
 /* The lang_hooks data structure.
-   Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+   Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -269,15 +269,24 @@ struct lang_hooks
      on unrecognized codes.  */
   size_t (*tree_size) (enum tree_code);
 
-  /* The first callback made to the front end, for simple
-     initialization needed before any calls to handle_option.  Return
-     the language mask to filter the switch array with.  */
-  unsigned int (*init_options) (unsigned int argc, const char **argv);
+  /* Return the language mask used for converting argv into a sequence
+     of options.  */
+  unsigned int (*option_lang_mask) (void);
+
+  /* After the initialize_diagnostics hook is called, do any simple
+     initialization needed before any calls to handle_option.  */
+  void (*init_options) (unsigned int decoded_options_count,
+			struct cl_decoded_option *decoded_options);
 
   /* Callback used to perform language-specific initialization for the
      global diagnostic context structure.  */
   void (*initialize_diagnostics) (struct diagnostic_context *);
 
+  /* Return true if a warning should be given about option OPTION,
+     which is for the wrong language, false if it should be quietly
+     ignored.  */
+  bool (*complain_wrong_lang_p) (const struct cl_option *option);
+
   /* Handle the switch CODE, which has real type enum opt_code from
      options.h.  If the switch takes an argument, it is passed in ARG
      which points to permanent storage.  The handler is responsible for
Index: gcc/coretypes.h
===================================================================
--- gcc/coretypes.h	(revision 162559)
+++ gcc/coretypes.h	(working copy)
@@ -1,5 +1,6 @@
 /* GCC core type declarations.
-   Copyright (C) 2002, 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2004, 2007, 2008, 2009, 2010
+   Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -65,6 +66,8 @@ union section;
 typedef union section section;
 struct cl_target_option;
 struct cl_optimization;
+struct cl_option;
+struct cl_decoded_option;
 struct gimple_seq_d;
 typedef struct gimple_seq_d *gimple_seq;
 typedef const struct gimple_seq_d *const_gimple_seq;
Index: gcc/lto/lto-lang.c
===================================================================
--- gcc/lto/lto-lang.c	(revision 162559)
+++ gcc/lto/lto-lang.c	(working copy)
@@ -595,16 +595,34 @@ static GTY(()) tree registered_builtin_f
 /* Language hooks.  */
 
 static unsigned int
-lto_init_options (unsigned int argc ATTRIBUTE_UNUSED,
-		  const char **argv ATTRIBUTE_UNUSED)
+lto_option_lang_mask (void)
+{
+  return CL_LTO;
+}
+
+static bool
+lto_complain_wrong_lang_p (const struct cl_option *option ATTRIBUTE_UNUSED)
+{
+  /* The LTO front end inherits all the options from the first front
+     end that was used.  However, not all the original front end
+     options make sense in LTO.
+
+     A real solution would be to filter this in collect2, but collect2
+     does not have access to all the option attributes to know what to
+     filter.  So, in lto1 we silently accept inherited flags and do
+     nothing about it.  */
+  return false;
+}
+
+static void
+lto_init_options (unsigned int decoded_options_count ATTRIBUTE_UNUSED,
+		  struct cl_decoded_option *decoded_options ATTRIBUTE_UNUSED)
 {
   /* By default, C99-like requirements for complex multiply and divide.
      ???  Until the complex method is encoded in the IL this is the only
      safe choice.  This will pessimize Fortran code with LTO unless
      people specify a complex method manually or use -ffast-math.  */
   flag_complex_method = 2;
-
-  return CL_LTO;
 }
 
 /* Handle command-line option SCODE.  If the option takes an argument, it is
@@ -1116,6 +1134,10 @@ static void lto_init_ts (void)
 
 #undef LANG_HOOKS_NAME
 #define LANG_HOOKS_NAME "GNU GIMPLE"
+#undef LANG_HOOKS_OPTION_LANG_MASK
+#define LANG_HOOKS_OPTION_LANG_MASK lto_option_lang_mask
+#undef LANG_HOOKS_COMPLAIN_WRONG_LANG_P
+#define LANG_HOOKS_COMPLAIN_WRONG_LANG_P lto_complain_wrong_lang_p
 #undef LANG_HOOKS_INIT_OPTIONS
 #define LANG_HOOKS_INIT_OPTIONS lto_init_options
 #undef LANG_HOOKS_HANDLE_OPTION
Index: gcc/langhooks-def.h
===================================================================
--- gcc/langhooks-def.h	(revision 162559)
+++ gcc/langhooks-def.h	(working copy)
@@ -1,5 +1,5 @@
 /* Default macros to initialize the lang_hooks data structure.
-   Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+   Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
    Contributed by Alexandre Oliva  <aoliva@redhat.com>
 
@@ -66,6 +66,9 @@ extern tree lhd_builtin_function (tree);
 
 /* Declarations of default tree inlining hooks.  */
 extern void lhd_initialize_diagnostics (struct diagnostic_context *);
+extern void lhd_init_options (unsigned int,
+			      struct cl_decoded_option *);
+extern bool lhd_complain_wrong_lang_p (const struct cl_option *);
 extern tree lhd_callgraph_analyze_expr (tree *, int *);
 
 
@@ -82,8 +85,10 @@ extern void lhd_omp_firstprivatize_type_
 #define LANG_HOOKS_INIT			hook_bool_void_false
 #define LANG_HOOKS_FINISH		lhd_do_nothing
 #define LANG_HOOKS_PARSE_FILE		lhd_do_nothing_i
-#define LANG_HOOKS_INIT_OPTIONS		hook_uint_uint_constcharptrptr_0
+#define LANG_HOOKS_OPTION_LANG_MASK	hook_uint_void_0
+#define LANG_HOOKS_INIT_OPTIONS		lhd_init_options
 #define LANG_HOOKS_INITIALIZE_DIAGNOSTICS lhd_initialize_diagnostics
+#define LANG_HOOKS_COMPLAIN_WRONG_LANG_P lhd_complain_wrong_lang_p
 #define LANG_HOOKS_HANDLE_OPTION	hook_int_size_t_constcharptr_int_0
 #define LANG_HOOKS_MISSING_ARGUMENT	hook_bool_constcharptr_size_t_false
 #define LANG_HOOKS_POST_OPTIONS		lhd_post_options
@@ -258,8 +263,10 @@ extern void lhd_end_section (void);
   LANG_HOOKS_IDENTIFIER_SIZE, \
   LANG_HOOKS_FREE_LANG_DATA, \
   LANG_HOOKS_TREE_SIZE, \
+  LANG_HOOKS_OPTION_LANG_MASK, \
   LANG_HOOKS_INIT_OPTIONS, \
   LANG_HOOKS_INITIALIZE_DIAGNOSTICS, \
+  LANG_HOOKS_COMPLAIN_WRONG_LANG_P, \
   LANG_HOOKS_HANDLE_OPTION, \
   LANG_HOOKS_MISSING_ARGUMENT, \
   LANG_HOOKS_POST_OPTIONS, \

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-07-27 10:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-24 17:28 [Ada,C++,etc.] Options patches pending review Joseph S. Myers
2010-06-24 19:44 ` Mike Stump
2010-06-25 16:57 ` Joseph S. Myers
2010-06-25 18:26   ` Arnaud Charlet
2010-07-02 11:29   ` Geert Bosch
2010-07-27 10:07     ` Joseph S. Myers
2010-06-30 21:36 ` Jason Merrill
2010-06-30 21:53 ` Diego Novillo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).