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>
* 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
unnecessary extern declaration.
......
......@@ -32,7 +32,11 @@
; compiler recognize the switch, as declared by "Language" entries.
; If the switch takes an argument, then you should also specify
; "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
; by a semicolon. Whitespace is permitted before the semicolon.
......@@ -311,7 +315,7 @@ d
C ObjC C++ ObjC++ Joined
fabi-version=
C++ ObjC++ Joined
C++ ObjC++ Joined UInteger
faccess-control
C++ ObjC++
......@@ -479,10 +483,10 @@ fstrict-prototype
C++ ObjC++
ftabstop=
C ObjC C++ ObjC++ Joined RejectNegative
C ObjC C++ ObjC++ Joined RejectNegative UInteger
ftemplate-depth-
C++ ObjC++ Joined
C++ ObjC++ Joined RejectNegative UInteger
fthis-is-variable
C++ ObjC++
......
......@@ -18,26 +18,7 @@
; Software Foundation, 59 Temple Place - Suite 330, Boston, MA
; 02111-1307, USA.
; 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.
; See c.opt for a description of this file's format.
; Please try to keep this file in ASCII collating order.
......@@ -51,7 +32,7 @@ Common
Common
G
Common Joined Separate
Common Joined Separate UInteger
aux-info
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>
* lang.opt: Declare Java.
......
......@@ -274,17 +274,8 @@ java_handle_option (size_t scode, const char *arg, int value)
if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
{
/* These can take an empty argument. */
if (code == OPT_fassume_compiled_
|| code == OPT_fclasspath_
|| code == OPT_fCLASSPATH_
|| code == OPT_fbootclasspath_)
arg = "";
else
{
error ("missing argument to \"-%s\"", option->opt_text);
return 1;
}
error ("missing argument to \"-%s\"", option->opt_text);
return 1;
}
switch (code)
......
......@@ -65,7 +65,7 @@ Wredundant-modifiers
Java
fCLASSPATH=
Java Joined RejectNegative
Java JoinedOrMissing RejectNegative
fassert
Java
......@@ -74,16 +74,16 @@ fassume-compiled
Java
fassume-compiled=
Java Joined
Java JoinedOrMissing
fbootclasspath=
Java Joined RejectNegative
Java JoinedOrMissing RejectNegative
fcheck-references
Java
fclasspath=
Java Joined RejectNegative
Java JoinedOrMissing RejectNegative
fcompile-resource=
Java Joined RejectNegative
......
......@@ -130,6 +130,22 @@ find_opt (const char *input, int lang_mask)
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. */
int
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;
const char *opt, *arg = 0;
char *dup = 0;
bool on = true;
int value = 1;
int result = 0, temp;
const struct cl_option *option;
......@@ -149,7 +165,7 @@ handle_option (int argc ATTRIBUTE_UNUSED, char **argv, int lang_mask)
opt_index = cl_options_count;
arg = opt;
main_input_filename = opt;
result = (*lang_hooks.handle_option) (opt_index, arg, on);
result = (*lang_hooks.handle_option) (opt_index, arg, value);
}
else
{
......@@ -164,7 +180,7 @@ handle_option (int argc ATTRIBUTE_UNUSED, char **argv, int lang_mask)
dup[1] = opt[1];
memcpy (dup + 2, opt + 5, len - 2 + 1);
opt = dup;
on = false;
value = 0;
}
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)
option = &cl_options[opt_index];
/* 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;
/* We've recognized this switch. */
result = 1;
/* 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
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 (!on)
arg += strlen ("no-");
if (option->flags & CL_SEPARATE)
{
arg = argv[1];
result = 2;
}
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
argument in the vector. */
if (!arg || (*arg == '\0' && option->flags & CL_SEPARATE))
/* If the switch takes an integer, convert it. */
if (arg && (option->flags & CL_UINTEGER))
{
value = integral_argument (arg);
if (value == -1)
{
arg = argv[1];
result = 2;
error ("argument to \"-%s\" should be a non-negative integer",
option->opt_text);
goto done;
}
/* Canonicalize missing arguments as NULL for the handler. */
if (*arg == '\0')
arg = NULL;
}
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)
result = temp;
}
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;
}
}
......@@ -262,9 +292,7 @@ common_handle_option (size_t scode, const char *arg,
break;
case OPT_G:
g_switch_value = read_integral_parameter (arg, 0, -1);
if (g_switch_value == (unsigned HOST_WIDE_INT) -1)
return 0;
g_switch_value = value;
g_switch_set = true;
break;
......
......@@ -36,6 +36,8 @@ extern const unsigned int cl_options_count;
#define CL_JOINED (1 << 24) /* If takes joined argument. */
#define CL_SEPARATE (1 << 25) /* If takes a separate argument. */
#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
......@@ -55,8 +55,11 @@ ${AWK} '
}
if (flags ~ " Common ") result = result " | CL_COMMON"
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 ~ " RejectNegative ") result = result " | CL_REJECT_NEGATIVE"
if (flags ~ " UInteger ") result = result " | CL_UINTEGER"
sub( "^0 \\| ", "", 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