Commit 7b086b11 by Neil Booth Committed by Neil Booth

c-opts.c (c_common_handle_option): s/on/value/.

	* c-opts.c (c_common_handle_option): s/on/value/.
	(OPT_fabi_version_, OPT_ftabstop_, OPT_ftemplate_depth_): Use value
	directly rather than converting the argument.
	* c.opt: Update docs.  Use UInteger where appropriate.
	* common.opt: Use UInteger where appropriate.
	* opts.c (integral_argument): New.
	(handle_argument): Handle integral arguments, and optional
	joined arguments.
	(common_handle_option): Update.
	* opts.h (CL_MISSING_OK, CL_UINTEGER): New.
	* opts.sh: Handle JoinedOrMissing and UInteger flags.
java:
	* lang.c (java_handle_option): Special-casing of optional
	joined arguments no longer needed.
	* lang.opt: Update switches that take optional argument.

From-SVN: r67999
parent 89aa997a
2003-06-16 Neil Booth <neil@daikokuya.co.uk> 2003-06-16 Neil Booth <neil@daikokuya.co.uk>
* c-opts.c (c_common_handle_option): s/on/value/.
(OPT_fabi_version_, OPT_ftabstop_, OPT_ftemplate_depth_): Use value
directly rather than converting the argument.
* c.opt: Update docs. Use UInteger where appropriate.
* common.opt: Use UInteger where appropriate.
* opts.c (integral_argument): New.
(handle_argument): Handle integral arguments, and optional
joined arguments.
(common_handle_option): Update.
* opts.h (CL_MISSING_OK, CL_UINTEGER): New.
* opts.sh: Handle JoinedOrMissing and UInteger flags.
2003-06-16 Neil Booth <neil@daikokuya.co.uk>
* config/rs6000/sysv4.h (ASM_OUTPUT_ALIGNED_LOCAL): Remove * config/rs6000/sysv4.h (ASM_OUTPUT_ALIGNED_LOCAL): Remove
unnecessary extern declaration. unnecessary extern declaration.
......
...@@ -32,7 +32,11 @@ ...@@ -32,7 +32,11 @@
; compiler recognize the switch, as declared by "Language" entries. ; compiler recognize the switch, as declared by "Language" entries.
; If the switch takes an argument, then you should also specify ; If the switch takes an argument, then you should also specify
; "Joined" and/or "Separate" to indicate where the argument can ; "Joined" and/or "Separate" to indicate where the argument can
; appear. ; appear. If a Joined argument can legitimately be omitted, specify
; "JoinedOrMissing" instead of "Joined". If the argument to a switch
; is a non-negative integer, you can specify "UInteger" and the switch
; decoder will convert the argument for you, or complain to the user
; if the argument is invalid.
; Comments can appear on their own line anwhere in the file, preceded ; Comments can appear on their own line anwhere in the file, preceded
; by a semicolon. Whitespace is permitted before the semicolon. ; by a semicolon. Whitespace is permitted before the semicolon.
...@@ -311,7 +315,7 @@ d ...@@ -311,7 +315,7 @@ d
C ObjC C++ ObjC++ Joined C ObjC C++ ObjC++ Joined
fabi-version= fabi-version=
C++ ObjC++ Joined C++ ObjC++ Joined UInteger
faccess-control faccess-control
C++ ObjC++ C++ ObjC++
...@@ -479,10 +483,10 @@ fstrict-prototype ...@@ -479,10 +483,10 @@ fstrict-prototype
C++ ObjC++ C++ ObjC++
ftabstop= ftabstop=
C ObjC C++ ObjC++ Joined RejectNegative C ObjC C++ ObjC++ Joined RejectNegative UInteger
ftemplate-depth- ftemplate-depth-
C++ ObjC++ Joined C++ ObjC++ Joined RejectNegative UInteger
fthis-is-variable fthis-is-variable
C++ ObjC++ C++ ObjC++
......
...@@ -18,26 +18,7 @@ ...@@ -18,26 +18,7 @@
; Software Foundation, 59 Temple Place - Suite 330, Boston, MA ; Software Foundation, 59 Temple Place - Suite 330, Boston, MA
; 02111-1307, USA. ; 02111-1307, USA.
; See c.opt for a description of this file's format.
; This file is processed by the script opts.sh. It is a database of
; command line options, with each record separated by a blank line,
; and each field appearing on its own line. The first field is the
; command-line switch with the leading "-" removed. All options
; beginning with "f" or "W" are implicitly assumed to take a "no-"
; form; this form should not be listed. If you do not want this
; negative form and you want it to be automatically rejected, add
; RejectNegative to the second field.
; The second field should contain "Common". If the switch takes an
; argument, then you should also specify "Joined" and/or "Separate" to
; indicate where the argument can appear.
; Comments can appear on their own line anwhere in the file, preceded
; by a semicolon. Whitespace is permitted before the semicolon.
; For each switch XXX below, an enumeration constant is created by the
; script opts.sh spelt OPT_XXX, but with all non-alphanumeric
; characters replaced with an underscore.
; Please try to keep this file in ASCII collating order. ; Please try to keep this file in ASCII collating order.
...@@ -51,7 +32,7 @@ Common ...@@ -51,7 +32,7 @@ Common
Common Common
G G
Common Joined Separate Common Joined Separate UInteger
aux-info aux-info
Common Separate Common Separate
......
2003-06-16 Neil Booth <neil@daikokuya.co.uk>
* lang.c (java_handle_option): Special-casing of optional
joined arguments no longer needed.
* lang.opt: Update switches that take optional argument.
2003-06-15 Neil Booth <neil@daikokuya.co.uk> 2003-06-15 Neil Booth <neil@daikokuya.co.uk>
* lang.opt: Declare Java. * lang.opt: Declare Java.
......
...@@ -274,17 +274,8 @@ java_handle_option (size_t scode, const char *arg, int value) ...@@ -274,17 +274,8 @@ java_handle_option (size_t scode, const char *arg, int value)
if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE))) if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
{ {
/* These can take an empty argument. */ error ("missing argument to \"-%s\"", option->opt_text);
if (code == OPT_fassume_compiled_ return 1;
|| code == OPT_fclasspath_
|| code == OPT_fCLASSPATH_
|| code == OPT_fbootclasspath_)
arg = "";
else
{
error ("missing argument to \"-%s\"", option->opt_text);
return 1;
}
} }
switch (code) switch (code)
......
...@@ -65,7 +65,7 @@ Wredundant-modifiers ...@@ -65,7 +65,7 @@ Wredundant-modifiers
Java Java
fCLASSPATH= fCLASSPATH=
Java Joined RejectNegative Java JoinedOrMissing RejectNegative
fassert fassert
Java Java
...@@ -74,16 +74,16 @@ fassume-compiled ...@@ -74,16 +74,16 @@ fassume-compiled
Java Java
fassume-compiled= fassume-compiled=
Java Joined Java JoinedOrMissing
fbootclasspath= fbootclasspath=
Java Joined RejectNegative Java JoinedOrMissing RejectNegative
fcheck-references fcheck-references
Java Java
fclasspath= fclasspath=
Java Joined RejectNegative Java JoinedOrMissing RejectNegative
fcompile-resource= fcompile-resource=
Java Joined RejectNegative Java Joined RejectNegative
......
...@@ -130,6 +130,22 @@ find_opt (const char *input, int lang_mask) ...@@ -130,6 +130,22 @@ find_opt (const char *input, int lang_mask)
return result; return result;
} }
/* If ARG is a postive integer made up solely of digits, return its
value, otherwise return -1. */
static int
integral_argument (const char *arg)
{
const char *p = arg;
while (*p && ISDIGIT (*p))
p++;
if (*p == '\0')
return atoi (arg);
return -1;
}
/* Handle the switch beginning at ARGV, with ARGC remaining. */ /* Handle the switch beginning at ARGV, with ARGC remaining. */
int int
handle_option (int argc ATTRIBUTE_UNUSED, char **argv, int lang_mask) handle_option (int argc ATTRIBUTE_UNUSED, char **argv, int lang_mask)
...@@ -137,7 +153,7 @@ handle_option (int argc ATTRIBUTE_UNUSED, char **argv, int lang_mask) ...@@ -137,7 +153,7 @@ handle_option (int argc ATTRIBUTE_UNUSED, char **argv, int lang_mask)
size_t opt_index; size_t opt_index;
const char *opt, *arg = 0; const char *opt, *arg = 0;
char *dup = 0; char *dup = 0;
bool on = true; int value = 1;
int result = 0, temp; int result = 0, temp;
const struct cl_option *option; const struct cl_option *option;
...@@ -149,7 +165,7 @@ handle_option (int argc ATTRIBUTE_UNUSED, char **argv, int lang_mask) ...@@ -149,7 +165,7 @@ handle_option (int argc ATTRIBUTE_UNUSED, char **argv, int lang_mask)
opt_index = cl_options_count; opt_index = cl_options_count;
arg = opt; arg = opt;
main_input_filename = opt; main_input_filename = opt;
result = (*lang_hooks.handle_option) (opt_index, arg, on); result = (*lang_hooks.handle_option) (opt_index, arg, value);
} }
else else
{ {
...@@ -164,7 +180,7 @@ handle_option (int argc ATTRIBUTE_UNUSED, char **argv, int lang_mask) ...@@ -164,7 +180,7 @@ handle_option (int argc ATTRIBUTE_UNUSED, char **argv, int lang_mask)
dup[1] = opt[1]; dup[1] = opt[1];
memcpy (dup + 2, opt + 5, len - 2 + 1); memcpy (dup + 2, opt + 5, len - 2 + 1);
opt = dup; opt = dup;
on = false; value = 0;
} }
opt_index = find_opt (opt + 1, lang_mask | CL_COMMON); opt_index = find_opt (opt + 1, lang_mask | CL_COMMON);
...@@ -174,48 +190,62 @@ handle_option (int argc ATTRIBUTE_UNUSED, char **argv, int lang_mask) ...@@ -174,48 +190,62 @@ handle_option (int argc ATTRIBUTE_UNUSED, char **argv, int lang_mask)
option = &cl_options[opt_index]; option = &cl_options[opt_index];
/* Reject negative form of switches that don't take negatives. */ /* Reject negative form of switches that don't take negatives. */
if (!on && (option->flags & CL_REJECT_NEGATIVE)) if (!value && (option->flags & CL_REJECT_NEGATIVE))
goto done; goto done;
/* We've recognized this switch. */ /* We've recognized this switch. */
result = 1; result = 1;
/* Sort out any argument the switch takes. */ /* Sort out any argument the switch takes. */
if (option->flags & (CL_JOINED | CL_SEPARATE)) if (option->flags & CL_JOINED)
{ {
if (option->flags & CL_JOINED) /* Have arg point to the original switch. This is because
some code, such as disable_builtin_function, expects its
argument to be persistent until the program exits. */
arg = argv[0] + cl_options[opt_index].opt_len + 1;
if (!value)
arg += strlen ("no-");
if (*arg == '\0' && !(option->flags & CL_MISSING_OK))
{ {
/* Have arg point to the original switch. This is because if (option->flags & CL_SEPARATE)
some code, such as disable_builtin_function, expects its {
argument to be persistent until the program exits. */ arg = argv[1];
arg = argv[0] + cl_options[opt_index].opt_len + 1; result = 2;
if (!on) }
arg += strlen ("no-"); else
/* Missing argument. */
arg = NULL;
} }
}
else if (option->flags & CL_SEPARATE)
{
arg = argv[1];
result = 2;
}
/* If we don't have an argument, and CL_SEPARATE, try the next /* If the switch takes an integer, convert it. */
argument in the vector. */ if (arg && (option->flags & CL_UINTEGER))
if (!arg || (*arg == '\0' && option->flags & CL_SEPARATE)) {
value = integral_argument (arg);
if (value == -1)
{ {
arg = argv[1]; error ("argument to \"-%s\" should be a non-negative integer",
result = 2; option->opt_text);
goto done;
} }
/* Canonicalize missing arguments as NULL for the handler. */
if (*arg == '\0')
arg = NULL;
} }
if (option->flags & lang_mask) if (option->flags & lang_mask)
{ {
temp = (*lang_hooks.handle_option) (opt_index, arg, on); temp = (*lang_hooks.handle_option) (opt_index, arg, value);
if (temp <= 0) if (temp <= 0)
result = temp; result = temp;
} }
if (result > 0 && (option->flags & CL_COMMON)) if (result > 0 && (option->flags & CL_COMMON))
{ {
if (common_handle_option (opt_index, arg, on) == 0) if (common_handle_option (opt_index, arg, value) == 0)
result = 0; result = 0;
} }
} }
...@@ -262,9 +292,7 @@ common_handle_option (size_t scode, const char *arg, ...@@ -262,9 +292,7 @@ common_handle_option (size_t scode, const char *arg,
break; break;
case OPT_G: case OPT_G:
g_switch_value = read_integral_parameter (arg, 0, -1); g_switch_value = value;
if (g_switch_value == (unsigned HOST_WIDE_INT) -1)
return 0;
g_switch_set = true; g_switch_set = true;
break; break;
......
...@@ -36,6 +36,8 @@ extern const unsigned int cl_options_count; ...@@ -36,6 +36,8 @@ extern const unsigned int cl_options_count;
#define CL_JOINED (1 << 24) /* If takes joined argument. */ #define CL_JOINED (1 << 24) /* If takes joined argument. */
#define CL_SEPARATE (1 << 25) /* If takes a separate argument. */ #define CL_SEPARATE (1 << 25) /* If takes a separate argument. */
#define CL_REJECT_NEGATIVE (1 << 26) /* Reject no- form. */ #define CL_REJECT_NEGATIVE (1 << 26) /* Reject no- form. */
#define CL_COMMON (1 << 27) /* Language-independent. */ #define CL_MISSING_OK (1 << 27) /* Missing argument OK (joined). */
#define CL_UINTEGER (1 << 28) /* Argument is an integer >=0. */
#define CL_COMMON (1 << 29) /* Language-independent. */
#endif #endif
...@@ -55,8 +55,11 @@ ${AWK} ' ...@@ -55,8 +55,11 @@ ${AWK} '
} }
if (flags ~ " Common ") result = result " | CL_COMMON" if (flags ~ " Common ") result = result " | CL_COMMON"
if (flags ~ " Joined ") result = result " | CL_JOINED" if (flags ~ " Joined ") result = result " | CL_JOINED"
if (flags ~ " JoinedOrMissing ") \
result = result " | CL_JOINED | CL_MISSING_OK"
if (flags ~ " Separate ") result = result " | CL_SEPARATE" if (flags ~ " Separate ") result = result " | CL_SEPARATE"
if (flags ~ " RejectNegative ") result = result " | CL_REJECT_NEGATIVE" if (flags ~ " RejectNegative ") result = result " | CL_REJECT_NEGATIVE"
if (flags ~ " UInteger ") result = result " | CL_UINTEGER"
sub( "^0 \\| ", "", result ) sub( "^0 \\| ", "", result )
return result return result
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment