]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
* coretypes.h (struct cl_option_handlers): Declare.
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 27 Jul 2010 21:23:53 +0000 (21:23 +0000)
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 27 Jul 2010 21:23:53 +0000 (21:23 +0000)
* 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:
* gcc-interface/misc.c (gnat_handle_option): Update prototype and
return value type.  Don't check for missing arguments here.

c-family:
* 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:
* gfortran.h (gfc_handle_option): Update prototype and return
value type.
* options.c (gfc_handle_option): Update prototype and return value
type.

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

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

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@162601 138bc75d-0d04-0410-961f-82ee72b054a4

24 files changed:
gcc/ChangeLog
gcc/Makefile.in
gcc/ada/ChangeLog
gcc/ada/gcc-interface/misc.c
gcc/c-family/ChangeLog
gcc/c-family/c-common.h
gcc/c-family/c-opts.c
gcc/coretypes.h
gcc/fortran/ChangeLog
gcc/fortran/gfortran.h
gcc/fortran/options.c
gcc/hooks.c
gcc/hooks.h
gcc/java/ChangeLog
gcc/java/lang.c
gcc/langhooks-def.h
gcc/langhooks.c
gcc/langhooks.h
gcc/lto/ChangeLog
gcc/lto/lto-lang.c
gcc/optc-gen.awk
gcc/opts-common.c
gcc/opts.c
gcc/opts.h

index b4c30411e9e515f4194ef51cf64d3677ddf30ed8..eb5bad8211a0c3812635e824694b1084e1cfc859 100644 (file)
@@ -1,3 +1,38 @@
+2010-07-27  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.
+
 2010-07-27  Maxim Kuvyrkov  <maxim@codesourcery.com>
 
        * config/arm/arm.c (params.h): Include.
index 3ce39140e9e92a9f452dbb088434b7fb5967bd50..6a99e23fceef50838b2b4388737dae3f7ce58aa8 100644 (file)
@@ -2806,7 +2806,7 @@ opts.o : opts.c opts.h options.h $(TOPLEV_H) $(DIAGNOSTIC_CORE_H) $(CONFIG_H) $(
    $(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 options.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) $(DIAGNOSTIC_CORE_H) \
    $(MACHMODE_H) $(TARGET_DEF_H) $(TARGET_H) $(GGC_H) gt-targhooks.h \
index a8506db93ed515a2048da7354893b01ce0a1b4a8..7324c3a9256d739917490fdff8c0924dc804bfda 100644 (file)
@@ -1,3 +1,8 @@
+2010-07-27  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.
+
 2010-07-27  Joseph Myers  <joseph@codesourcery.com>
 
        * gcc-interface/misc.c (gnat_option_lang_mask): New.
index 43ed1571f4abc2c51871d8333b700f0a18f3ea70..01b33a3f9c4341cd3a76b305a3685e4543289705 100644 (file)
@@ -64,7 +64,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);
@@ -186,22 +187,15 @@ gnat_parse_file (int set_yydebug ATTRIBUTE_UNUSED)
 
 /* 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
-gnat_handle_option (size_t scode, const char *arg, int value,
-                   int kind ATTRIBUTE_UNUSED)
+static bool
+gnat_handle_option (size_t scode, const char *arg ATTRIBUTE_UNUSED, int value,
+                   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;
 
-  if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
-    {
-      error ("missing argument to \"-%s\"", option->opt_text);
-      return 1;
-    }
-
   switch (code)
     {
     case OPT_Wall:
@@ -250,7 +244,7 @@ gnat_handle_option (size_t scode, const char *arg, int value,
       gcc_unreachable ();
     }
 
-  return 1;
+  return true;
 }
 
 /* Return language mask for option processing.  */
index d5f3e6eabb3e78fa034d47f05b1bcc05ed3ea479..c7c3a1f8b739c30bae2a352c2bf86e13c8ea39da 100644 (file)
@@ -1,3 +1,11 @@
+2010-07-27  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.
+
 2010-07-27  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/45079
index b92fef8f04d4e3a1ba2a933bf5a87be6c9678dbc..3f22485b6acbc23810edf3b2af46d3c9f8fbef4e 100644 (file)
@@ -658,7 +658,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,
index 38c996bfea034b59c7c9d9fc0a9509d6e3d3dea3..2c8245e2a5e8d8dc48074f7925b7d721f0883dd4 100644 (file)
@@ -319,16 +319,15 @@ c_common_init_options (unsigned int decoded_options_count,
 }
 
 /* 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, const char *arg, int value,
        {
          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, const char *arg, int value,
     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, const char *arg, int value,
     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, const char *arg, int value,
     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, const char *arg, int value,
 
     case OPT_fbuiltin_:
       if (value)
-       result = 0;
+       result = false;
       else
        disable_builtin_function (arg);
       break;
index 25539c3d543f538e6abe9081250ca0d2cd83bb6c..f23741ad762afa68ecfe804203718d9d565eafce 100644 (file)
@@ -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;
index dcff2b2f4e192b2edba141865e45d84f15cb57e6..fb49a8dc85bb8f63606532eff9b668c99763cd84 100644 (file)
@@ -1,3 +1,10 @@
+2010-07-27  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.
+
 2010-07-27  Joseph Myers  <joseph@codesourcery.com>
 
        * cpp.c (gfc_cpp_init_options): Update prototype.  Use number of
index f082d5e5974305df8c46bd5b773289c37892494b..15ae26f530c0c7af85eae105f3a3cc70c608e657 100644 (file)
@@ -2358,7 +2358,8 @@ int get_c_kind (const char *, CInteropKind_t *);
 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 */
index 337802e35a7805fca64e446d8b794da5856ca416..c49620a24f64169501e1bbdf86d141a2950dbe1c 100644 (file)
@@ -542,20 +542,21 @@ gfc_handle_runtime_check_option (const char *arg)
 /* 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:
index 94d045f037047bdb303a5b2ec8b64d8d7ac41ec8..52a40484054d6937aaeed76d8a9fbe3ff4e95e19 100644 (file)
@@ -160,14 +160,6 @@ hook_int_rtx_bool_0 (rtx a ATTRIBUTE_UNUSED, bool b ATTRIBUTE_UNUSED)
   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)
 {
index 52e4d84ce78a019b06441155dcc621e189dbaf30..a89a355f879da6a841417b2b91e6c0ca39ad190c 100644 (file)
@@ -63,7 +63,6 @@ extern int hook_int_const_tree_0 (const_tree);
 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);
 
index 47c5e0f133226604816a1ca2bd502116177bafc5..00e7ce754c63e028f1c8effe082e9754fb596e0a 100644 (file)
@@ -1,3 +1,8 @@
+2010-07-27  Joseph Myers  <joseph@codesourcery.com>
+
+       * lang.c (java_handle_option): Update prototype and return value
+       type.
+
 2010-07-27  Joseph Myers  <joseph@codesourcery.com>
 
        * lang.c (java_option_lang_mask): New.
index c084cb88a7cc46c8cdbec7eae1e0b352a5b46313..06edd5ee6f38ca159d1ef2454e6a4958e3b3ea98 100644 (file)
@@ -50,7 +50,8 @@ 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);
+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 *,
@@ -174,11 +175,12 @@ struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
 
 /*
  * 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;
 
@@ -269,7 +271,7 @@ java_handle_option (size_t scode, const char *arg, int value,
 
     case OPT_fdump_:
       if (!dump_switch_p (arg))
-       return 0;
+       return false;
       break;
 
     case OPT_fencoding_:
@@ -298,7 +300,7 @@ java_handle_option (size_t scode, const char *arg, int value,
       gcc_unreachable ();
     }
 
-  return 1;
+  return true;
 }
 
 /* Global open file.  */
index 1b7cebfb10ea2268f57603188fad7e114aa86997..c89763bbee0319448c98c2e7864b31c817f644fd 100644 (file)
@@ -69,6 +69,8 @@ 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 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_sizes (struct gimplify_omp_ctx *,
 #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
index 1becd557c8a3efb6c54138d1c201bf25bff1dc7e..7a585085ef04c6653da099b32601db86a37c9f6d 100644 (file)
@@ -351,6 +351,16 @@ lhd_complain_wrong_lang_p (const struct cl_option *option ATTRIBUTE_UNUSED)
   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
index 6c9f80dec4b8d387b110a90dc20a5efca922d06d..87bac2826d034396cdce59e83686055aef304032 100644 (file)
@@ -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
index 28b594977e4adfd4a2cc8ed2d5b81abde042edc5..4a7260617a4f144d500d40a9eacd770937f5861d 100644 (file)
@@ -1,3 +1,8 @@
+2010-07-27  Joseph Myers  <joseph@codesourcery.com>
+
+       * lto-lang.c (lto_handle_option): Update prototype and return
+       value type.  Remove duplicate assignment to result.
+
 2010-07-27  Joseph Myers  <joseph@codesourcery.com>
 
        * lto-lang.c (lto_option_lang_mask, lto_complain_wrong_lang_p):
index 0915ac0ad409437257d3065e221ad30df59722c8..388a46c199cb9bb9967b6a5e53136986c93d51d7 100644 (file)
@@ -631,18 +631,18 @@ lto_init_options (unsigned int decoded_options_count ATTRIBUTE_UNUSED,
    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:
index 78741fc8743e8a29ed2e8e374a27ee2d355e849c..d0a07f8a5d3f3ea37bb296d2ca686fa5c601044d 100644 (file)
@@ -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
index 6b24b37ce5d19a906ceb2ab04869b076989feb93..d84938ac9a35dfa8c535b443f9a25069c8081557 100644 (file)
@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3.  If not see
 #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);
+}
index 12eb40a451a4855c2c19d1c2a0a40783f31b1b09..eaa31c5b572c6a243e179005cea04f10fe03ecb3 100644 (file)
@@ -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;
-
-  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;
-    }
+/* Handle a front-end option; arguments and return value as for
+   handle_option.  */
 
-  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 (tree fndecl)
 
 /* 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_option *decoded_options,
          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 char **argv,
   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 char **argv,
     /* 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++)
@@ -904,7 +864,7 @@ decode_options (unsigned int argc, const char **argv,
     }
 
   /* 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)
     {
@@ -932,7 +892,8 @@ decode_options (unsigned int argc, const char **argv,
   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))
     {
@@ -1426,9 +1387,10 @@ print_specific_help (unsigned int include_flags,
    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;
@@ -1610,7 +1572,7 @@ common_handle_option (size_t scode, const char *arg, int value,
       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_:
@@ -1736,7 +1698,7 @@ common_handle_option (size_t scode, const char *arg, int value,
        diagnostic_prefixing_rule (global_dc)
          = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
       else
-       return 0;
+       return false;
       break;
 
     case OPT_fdiagnostics_show_option:
@@ -1745,7 +1707,7 @@ common_handle_option (size_t scode, const char *arg, int value,
 
     case OPT_fdump_:
       if (!dump_switch_p (arg))
-       return 0;
+       return false;
       break;
 
     case OPT_fexcess_precision_:
@@ -1909,7 +1871,7 @@ common_handle_option (size_t scode, const char *arg, int value,
     case OPT_frandom_seed:
       /* The real switch is -fno-random-seed.  */
       if (value)
-       return 0;
+       return false;
       set_random_seed (NULL);
       break;
 
@@ -1927,7 +1889,7 @@ common_handle_option (size_t scode, const char *arg, int value,
       fix_sched_param ("verbose", arg);
       break;
 #else
-      return 0;
+      return false;
 #endif
 
     case OPT_fsched_stalled_insns_:
@@ -1974,7 +1936,7 @@ common_handle_option (size_t scode, const char *arg, int value,
     case OPT_fstack_limit:
       /* The real switch is -fno-stack-limit.  */
       if (value)
-       return 0;
+       return false;
       stack_limit_rtx = NULL_RTX;
       break;
 
@@ -2141,7 +2103,7 @@ common_handle_option (size_t scode, const char *arg, int value,
       break;
     }
 
-  return 1;
+  return true;
 }
 
 /* Handle --param NAME=VALUE.  */
@@ -2356,49 +2318,6 @@ get_option_state (int option, struct cl_option_state *state)
   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;
@@ -2416,7 +2335,8 @@ register_warning_as_error_callback (void (*callback) (int))
    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;
@@ -2441,7 +2361,8 @@ enable_warning_as_error (const char *arg, int value, unsigned int lang_mask)
 
          /* -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);
index 674843a9497be67a33defb994a272c419bcf777e..6613da0c3b05d9b19ca64b96f46b246019eed51c 100644 (file)
@@ -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 argc, const char **argv,
 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