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


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

[options] Langhooks for missing argument and filenames


With this patch, the C front ends' overriding of the missing
argument diagnostic is restored, and filenames are passed
down to front ends with a langhook.  The option handlers
in each front end are now just a big switch statement.

Bootstrapped all except C++ and Java, which I can't do
because of the VERSION binutils issue.

Neil.

	* c-common.h (c_comon_handle_filename,
	c_common_missing_arguement): New.
	* c-lang.c (LANG_HOOKS_HANDLE_FILENAME,
	LANG_HOOKS_MISSING_ARGUMENT): New.
	* c-opts.c (missing_arg): Rename c_common_missing_argument,
	update to be an appropriate langhook.
	(c_common_handle_option): Don't handle filenames.
	(c_common_handle_filename): New.
	* hooks.c (hook_void_constcharptr,
	hook_bool_constcharptr_size_t_false): New.
	* hooks.h (hook_void_constcharptr,
	hook_bool_constcharptr_size_t_false): New.
	* langhooks-def.h (LANG_HOOKS_HANDLE_FILENAME,
	LANG_HOOKS_MISSING_ARGUMENT): New.
	(LANG_HOOKS_INITIALIZER): Update.
	* langhooks.h (struct lang_hooks): Add handle_filename and
	missing_argument.
	* opts.c (handle_option): Don't handle filenames here, but ...
	(handle_options): ... here.
	(common_handle_option): Don't handle missing arguments here.
	* objc/objc-lang.c (LANG_HOOKS_HANDLE_FILENAME,
	LANG_HOOKS_MISSING_ARGUMENT): New.
ada:
	* misc.c (gnat_handle_option): Don't handle filenames.
cp:
	* cp-lang.c (LANG_HOOKS_HANDLE_FILENAME,
	LANG_HOOKS_MISSING_ARGUMENT): Override.
f:
	* top.c (ffe_handle_option): Don't handle filenames.
java:
	* lang.c (java_handle_option): Don't handle filenames.

Index: c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.187
diff -u -p -b -r1.187 c-common.h
--- c-common.h	5 Jul 2003 00:23:47 -0000	1.187
+++ c-common.h	6 Jul 2003 18:53:40 -0000
@@ -896,6 +896,8 @@ extern tree handle_format_attribute (tre
 extern tree handle_format_arg_attribute (tree *, tree, tree, int, bool *);
 extern void c_common_insert_default_attributes (tree);
 extern int c_common_handle_option (size_t code, const char *arg, int value);
+extern void c_common_handle_filename (const char *filename);
+extern bool c_common_missing_argument (const char *opt, size_t code);
 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_unsigned_type (tree);
Index: c-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lang.c,v
retrieving revision 1.106
diff -u -p -b -r1.106 c-lang.c
--- c-lang.c	30 Jun 2003 19:36:20 -0000	1.106
+++ c-lang.c	6 Jul 2003 18:53:40 -0000
@@ -45,6 +45,10 @@ enum c_language_kind c_language = clk_c;
 #define LANG_HOOKS_INIT_OPTIONS c_common_init_options
 #undef LANG_HOOKS_HANDLE_OPTION
 #define LANG_HOOKS_HANDLE_OPTION c_common_handle_option
+#undef LANG_HOOKS_HANDLE_FILENAME
+#define LANG_HOOKS_HANDLE_FILENAME c_common_handle_filename
+#undef LANG_HOOKS_MISSING_ARGUMENT
+#define LANG_HOOKS_MISSING_ARGUMENT c_common_missing_argument
 #undef LANG_HOOKS_POST_OPTIONS
 #define LANG_HOOKS_POST_OPTIONS c_common_post_options
 #undef LANG_HOOKS_GET_ALIAS_SET
Index: c-opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-opts.c,v
retrieving revision 1.69
diff -u -p -b -r1.69 c-opts.c
--- c-opts.c	5 Jul 2003 07:20:32 -0000	1.69
+++ c-opts.c	6 Jul 2003 18:53:41 -0000
@@ -97,7 +97,6 @@ static size_t include_cursor;
 /* Permit Fotran front-end options.  */
 static bool permit_fortran_options;
 
-void missing_arg (enum opt_code);
 static void set_Wimplicit (int);
 static void print_help (void);
 static void handle_OPT_d (const char *);
@@ -125,51 +124,37 @@ static struct deferred_opt
   const char *arg;
 } *deferred_opts;
 
-/* Complain that switch OPT_INDEX expects an argument but none was
-   provided.  */
-void
-missing_arg (enum opt_code code)
+/* Complain that switch CODE expects an argument but none was
+   provided.  OPT was the command-line option.  Return FALSE to get
+   the default message in opts.c, TRUE if we provide a specialized
+   one.  */
+bool
+c_common_missing_argument (const char *opt, size_t code)
 {
-  const char *opt_text = cl_options[code].opt_text;
-
   switch (code)
     {
-    case OPT__output_pch_:
-    case OPT_Wformat_:
-    case OPT_d:
-    case OPT_fabi_version_:
-    case OPT_fbuiltin_:
-    case OPT_fdump_:
-    case OPT_fname_mangling_version_:
-    case OPT_ftabstop_:
-    case OPT_fexec_charset_:
-    case OPT_fwide_exec_charset_:
-    case OPT_ftemplate_depth_:
-    case OPT_iprefix:
-    case OPT_iwithprefix:
-    case OPT_iwithprefixbefore:
     default:
-      error ("missing argument to \"-%s\"", opt_text);
-      break;
+      /* Pick up the default message.  */
+      return false;
 
     case OPT_fconstant_string_class_:
-      error ("no class name specified with \"-%s\"", opt_text);
+      error ("no class name specified with \"%s\"", opt);
       break;
 
     case OPT_A:
-      error ("assertion missing after \"-%s\"", opt_text);
+      error ("assertion missing after \"%s\"", opt);
       break;
 
     case OPT_D:
     case OPT_U:
-      error ("macro name missing after \"-%s\"", opt_text);
+      error ("macro name missing after \"%s\"", opt);
       break;
 
     case OPT_I:
     case OPT_idirafter:
     case OPT_isysroot:
     case OPT_isystem:
-      error ("missing path after \"-%s\"", opt_text);
+      error ("missing path after \"%s\"", opt);
       break;
 
     case OPT_MF:
@@ -178,14 +163,16 @@ missing_arg (enum opt_code code)
     case OPT_include:
     case OPT_imacros:
     case OPT_o:
-      error ("missing filename after \"-%s\"", opt_text);
+      error ("missing filename after \"%s\"", opt);
       break;
 
     case OPT_MQ:
     case OPT_MT:
-      error ("missing target after \"-%s\"", opt_text);
+      error ("missing makefile target after \"%s\"", opt);
       break;
     }
+
+  return true;
 }
 
 /* Defer option CODE with argument ARG.  */
@@ -261,18 +248,6 @@ c_common_handle_option (size_t scode, co
   enum opt_code code = (enum opt_code) scode;
   int result = 1;
 
-  if (code == N_OPTS)
-    {
-      if (!in_fname)
-	in_fname = arg;
-      else if (!out_fname)
-	out_fname = arg;
-      else
-	  error ("too many filenames given.  Type %s --help for usage",
-		 progname);
-      return 1;
-    }
-
   switch (code)
     {
     default:
@@ -700,7 +675,7 @@ c_common_handle_option (size_t scode, co
     case OPT_fthis_is_variable:
     case OPT_fvtable_thunks:
     case OPT_fxref:
-      warning ("switch \"%s\" is no longer supported", option->opt_text);
+      warning ("switch \"-%s\" is no longer supported", option->opt_text);
       break;
 
     case OPT_fabi_version_:
@@ -716,7 +691,8 @@ c_common_handle_option (size_t scode, co
       if (value)
 	flag_external_templates = true;
     cp_deprecated:
-      warning ("switch \"%s\" is deprecated, please see documentation for details", option->opt_text);
+      warning ("switch \"-%s\" is deprecated, please see documentation "
+	       "for details", option->opt_text);
       break;
 
     case OPT_fasm:
@@ -1057,6 +1033,18 @@ c_common_handle_option (size_t scode, co
     }
 
   return result;
+}
+
+/* Handle FILENAME from the command line.  */
+void
+c_common_handle_filename (const char *filename)
+{
+  if (!in_fname)
+    in_fname = filename;
+  else if (!out_fname)
+    out_fname = filename;
+  else
+    error ("output filename specified twice");
 }
 
 /* Post-switch processing.  */
Index: hooks.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/hooks.c,v
retrieving revision 1.19
diff -u -p -b -r1.19 hooks.c
--- hooks.c	6 Jul 2003 06:15:35 -0000	1.19
+++ hooks.c	6 Jul 2003 18:53:41 -0000
@@ -68,6 +68,11 @@ hook_void_FILEptr_constcharptr (FILE *a 
 {
 }
 
+void
+hook_void_constcharptr (const char *a ATTRIBUTE_UNUSED)
+{
+}
+
 /* Used for the TARGET_ASM_CAN_OUTPUT_MI_THUNK hook.  */
 bool
 hook_bool_tree_hwi_hwi_tree_false (tree a ATTRIBUTE_UNUSED,
@@ -85,6 +90,13 @@ hook_bool_tree_hwi_hwi_tree_true (tree a
 				  tree d ATTRIBUTE_UNUSED)
 {
   return true;
+}
+
+bool
+hook_bool_constcharptr_size_t_false (const char *a ATTRIBUTE_UNUSED,
+				     size_t b ATTRIBUTE_UNUSED)
+{
+  return false;
 }
 
 bool
Index: hooks.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/hooks.h,v
retrieving revision 1.20
diff -u -p -b -r1.20 hooks.h
--- hooks.h	6 Jul 2003 06:15:35 -0000	1.20
+++ hooks.h	6 Jul 2003 18:53:41 -0000
@@ -31,12 +31,14 @@ bool hook_bool_tree_hwi_hwi_tree_true (t
 				       tree);
 bool hook_bool_rtx_false (rtx);
 bool hook_bool_rtx_int_int_intp_false (rtx, int, int, int *);
+bool hook_bool_constcharptr_size_t_false (const char *, size_t);
 
 void hook_void_tree_int (tree, int);
 void hook_void_void (void);
 void hook_void_FILEptr_constcharptr (FILE *, const char *);
 void hook_void_tree (tree);
 void hook_void_tree_treeptr (tree, tree *);
+void hook_void_constcharptr (const char *);
 
 int hook_int_tree_tree_1 (tree, tree);
 int hook_int_rtx_0 (rtx);
Index: langhooks-def.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks-def.h,v
retrieving revision 1.54
diff -u -p -b -r1.54 langhooks-def.h
--- langhooks-def.h	6 Jul 2003 09:56:04 -0000	1.54
+++ langhooks-def.h	6 Jul 2003 18:53:41 -0000
@@ -90,6 +90,8 @@ extern void write_global_declarations (v
 #define LANG_HOOKS_CLEAR_BINDING_STACK	lhd_clear_binding_stack
 #define LANG_HOOKS_INIT_OPTIONS		hook_uint_uint_constcharptrptr_0
 #define LANG_HOOKS_HANDLE_OPTION	hook_int_size_t_constcharptr_int_0
+#define LANG_HOOKS_HANDLE_FILENAME	hook_void_constcharptr
+#define LANG_HOOKS_MISSING_ARGUMENT	hook_bool_constcharptr_size_t_false
 #define LANG_HOOKS_POST_OPTIONS		lhd_post_options
 #define LANG_HOOKS_GET_ALIAS_SET	lhd_get_alias_set
 #define LANG_HOOKS_EXPAND_CONSTANT	lhd_return_tree
@@ -244,6 +246,8 @@ extern int lhd_tree_dump_type_quals (tre
   LANG_HOOKS_TREE_SIZE, \
   LANG_HOOKS_INIT_OPTIONS, \
   LANG_HOOKS_HANDLE_OPTION, \
+  LANG_HOOKS_HANDLE_FILENAME, \
+  LANG_HOOKS_MISSING_ARGUMENT, \
   LANG_HOOKS_POST_OPTIONS, \
   LANG_HOOKS_INIT, \
   LANG_HOOKS_FINISH, \
Index: langhooks.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks.h,v
retrieving revision 1.63
diff -u -p -b -r1.63 langhooks.h
--- langhooks.h	6 Jul 2003 09:56:04 -0000	1.63
+++ langhooks.h	6 Jul 2003 18:53:41 -0000
@@ -217,6 +217,13 @@ struct lang_hooks
      valid and should not be treated as language-independent too.  */
   int (*handle_option) (size_t code, const char *arg, int value);
 
+  /* Handle a filename on the command line.  */
+  void (*handle_filename) (const char *filename);
+
+  /* Return false to use the default complaint about a missing
+     argument, otherwise output a complaint and return true.  */
+  bool (*missing_argument) (const char *opt, size_t code);
+
   /* Called when all command line options have been parsed to allow
      further processing and initialization
 
Index: opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/opts.c,v
retrieving revision 1.22
diff -u -p -b -r1.22 opts.c
--- opts.c	4 Jul 2003 21:47:22 -0000	1.22
+++ opts.c	6 Jul 2003 18:53:41 -0000
@@ -297,16 +297,6 @@ handle_option (const char **argv, unsign
 
   opt = argv[0];
 
-  /* Interpret "-" or a non-switch as a file name.  */
-  if (opt[0] != '-' || opt[1] == '\0')
-    {
-      opt_index = cl_options_count;
-      arg = opt;
-      main_input_filename = opt;
-      result = (*lang_hooks.handle_option) (opt_index, arg, value);
-    }
-  else
-    {
       /* Drop the "no-" from negative switches.  */
       if ((opt[1] == 'W' || opt[1] == 'f')
 	  && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
@@ -373,7 +363,8 @@ handle_option (const char **argv, unsign
 
       if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
 	{
-	  error ("missing argument to \"-%s\"", argv[0]);
+      if (!(*lang_hooks.missing_argument) (opt, opt_index))
+	error ("missing argument to \"%s\"", opt);
 	  goto done;
 	}
 
@@ -396,7 +387,6 @@ handle_option (const char **argv, unsign
       if (result && (option->flags & CL_COMMON))
 	if (common_handle_option (opt_index, arg, value) == 0)
 	  result = 0;
-    }
 
  done:
   if (dup)
@@ -414,12 +404,23 @@ handle_options (unsigned int argc, const
 
   for (i = 1; i < argc; i += n)
     {
+      const char *opt = argv[i];
+
+      /* Interpret "-" or a non-switch as a file name.  */
+      if (opt[0] != '-' || opt[1] == '\0')
+	{
+	  main_input_filename = opt;
+	  (*lang_hooks.handle_filename) (opt);
+	  n = 1;
+	  continue;
+	}
+
       n = handle_option (argv + i, lang_mask);
 
       if (!n)
 	{
 	  n = 1;
-	  error ("unrecognized command line option \"%s\"", argv[i]);
+	  error ("unrecognized command line option \"%s\"", opt);
 	}
     }
 }
@@ -603,14 +604,7 @@ static int
 common_handle_option (size_t scode, const char *arg,
 		      int value 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)
     {
Index: ada/misc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ada/misc.c,v
retrieving revision 1.62
diff -u -p -b -r1.62 misc.c
--- ada/misc.c	3 Jul 2003 21:49:54 -0000	1.62
+++ ada/misc.c	6 Jul 2003 18:53:42 -0000
@@ -226,10 +226,6 @@ gnat_handle_option (size_t scode, const 
   char *q;
   unsigned int i;
 
-  /* Ignore file names.  */
-  if (code == N_OPTS)
-      return 1;
-
   switch (code)
     {
     default:
Index: cp/cp-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-lang.c,v
retrieving revision 1.53
diff -u -p -b -r1.53 cp-lang.c
--- cp/cp-lang.c	2 Jul 2003 00:12:09 -0000	1.53
+++ cp/cp-lang.c	6 Jul 2003 18:53:42 -0000
@@ -53,6 +53,10 @@ static bool cp_var_mod_type_p (tree);
 #define LANG_HOOKS_INIT_OPTIONS c_common_init_options
 #undef LANG_HOOKS_HANDLE_OPTION
 #define LANG_HOOKS_HANDLE_OPTION c_common_handle_option
+#undef LANG_HOOKS_HANDLE_FILENAME
+#define LANG_HOOKS_HANDLE_FILENAME c_common_handle_filename
+#undef LANG_HOOKS_MISSING_ARGUMENT
+#define LANG_HOOKS_MISSING_ARGUMENT c_common_missing_argument
 #undef LANG_HOOKS_POST_OPTIONS
 #define LANG_HOOKS_POST_OPTIONS c_common_post_options
 #undef LANG_HOOKS_GET_ALIAS_SET
Index: f/top.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/f/top.c,v
retrieving revision 1.37
diff -u -p -b -r1.37 top.c
--- f/top.c	2 Jul 2003 20:15:44 -0000	1.37
+++ f/top.c	6 Jul 2003 18:53:43 -0000
@@ -178,10 +178,6 @@ ffe_handle_option (size_t scode, const c
 {
   enum opt_code code = (enum opt_code) scode;
 
-  /* Ignore file names.  */
-  if (code == N_OPTS)
-    return 1;
-
   switch (code)
     {
     default:
Index: java/lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/lang.c,v
retrieving revision 1.138
diff -u -p -b -r1.138 lang.c
--- java/lang.c	2 Jul 2003 20:15:46 -0000	1.138
+++ java/lang.c	6 Jul 2003 18:53:43 -0000
@@ -267,10 +267,6 @@ java_handle_option (size_t scode, const 
 {
   enum opt_code code = (enum opt_code) scode;
 
-  /* Ignore file names.  */
-  if (code == N_OPTS)
-      return 1;
-
   switch (code)
     {
     default:
Index: objc/objc-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/objc/objc-lang.c,v
retrieving revision 1.32
diff -u -p -b -r1.32 objc-lang.c
--- objc/objc-lang.c	30 Jun 2003 19:36:25 -0000	1.32
+++ objc/objc-lang.c	6 Jul 2003 18:53:43 -0000
@@ -43,6 +43,10 @@ enum c_language_kind c_language = clk_ob
 #define LANG_HOOKS_INIT_OPTIONS c_common_init_options
 #undef LANG_HOOKS_HANDLE_OPTION
 #define LANG_HOOKS_HANDLE_OPTION c_common_handle_option
+#undef LANG_HOOKS_HANDLE_FILENAME
+#define LANG_HOOKS_HANDLE_FILENAME c_common_handle_filename
+#undef LANG_HOOKS_MISSING_ARGUMENT
+#define LANG_HOOKS_MISSING_ARGUMENT c_common_missing_argument
 #undef LANG_HOOKS_POST_OPTIONS
 #define LANG_HOOKS_POST_OPTIONS c_common_post_options
 #undef LANG_HOOKS_GET_ALIAS_SET


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