Commit a56a0779 by Richard Sandiford Committed by Richard Sandiford

opt-functions.awk (flag_set_p, test_flag): New functions.

	* opt-functions.awk (flag_set_p, test_flag): New functions.
	(switch_flags): Use them.
	* opth-gen.awk: Use flag_set_p to check for flags.
	* optc-gen.awk: Likewise.  Use opt_args to check for Init(...) flags.

From-SVN: r97237
parent e5948c83
2005-03-20 Richard Sandiford <rsandifo@redhat.com>
* opt-functions.awk (flag_set_p, test_flag): New functions.
(switch_flags): Use them.
* opth-gen.awk: Use flag_set_p to check for flags.
* optc-gen.awk: Likewise. Use opt_args to check for Init(...) flags.
2005-03-30 Ian Lance Taylor <ian@airs.com> 2005-03-30 Ian Lance Taylor <ian@airs.com>
* config.host (i[34567]86-*-mingw32*): Don't set * config.host (i[34567]86-*-mingw32*): Don't set
......
...@@ -18,6 +18,21 @@ ...@@ -18,6 +18,21 @@
# Some common subroutines for use by opt[ch]-gen.awk. # Some common subroutines for use by opt[ch]-gen.awk.
# Return nonzero if FLAGS contains a flag matching REGEX.
function flag_set_p(regex, flags)
{
return (" " flags " ") ~ (" " regex " ")
}
# Return STRING if FLAGS contains a flag matching regexp REGEX,
# otherwise return the empty string.
function test_flag(regex, flags, string)
{
if (flag_set_p(regex, flags))
return string
return ""
}
# If FLAGS contains a "NAME(...argument...)" flag, return the value # If FLAGS contains a "NAME(...argument...)" flag, return the value
# of the argument. Return the empty string otherwise. # of the argument. Return the empty string otherwise.
function opt_args(name, flags) function opt_args(name, flags)
...@@ -47,24 +62,22 @@ function nth_arg(n, s) ...@@ -47,24 +62,22 @@ function nth_arg(n, s)
# Return a bitmask of CL_* values for option flags FLAGS. # Return a bitmask of CL_* values for option flags FLAGS.
function switch_flags (flags) function switch_flags (flags)
{ {
flags = " " flags " "
result = "0" result = "0"
for (j = 0; j < n_langs; j++) { for (j = 0; j < n_langs; j++) {
regex = " " langs[j] " " regex = langs[j]
gsub ( "\\+", "\\+", regex ) gsub ( "\\+", "\\+", regex )
if (flags ~ regex) result = result test_flag(regex, flags, " | " macros[j])
result = result " | " macros[j]
} }
if (flags ~ " Common ") result = result " | CL_COMMON" result = result \
if (flags ~ " Target ") result = result " | CL_TARGET" test_flag("Common", flags, " | CL_COMMON") \
if (flags ~ " Joined ") result = result " | CL_JOINED" test_flag("Target", flags, " | CL_TARGET") \
if (flags ~ " JoinedOrMissing ") \ test_flag("Joined", flags, " | CL_JOINED") \
result = result " | CL_JOINED | CL_MISSING_OK" test_flag("JoinedOrMissing", flags, " | CL_JOINED | CL_MISSING_OK") \
if (flags ~ " Separate ") result = result " | CL_SEPARATE" test_flag("Separate", flags, " | CL_SEPARATE") \
if (flags ~ " RejectNegative ") result = result " | CL_REJECT_NEGATIVE" test_flag("RejectNegative", flags, " | CL_REJECT_NEGATIVE") \
if (flags ~ " UInteger ") result = result " | CL_UINTEGER" test_flag("UInteger", flags, " | CL_UINTEGER") \
if (flags ~ " Undocumented ") result = result " | CL_UNDOCUMENTED" test_flag("Undocumented", flags, " | CL_UNDOCUMENTED") \
if (flags ~ " Report ") result = result " | CL_REPORT" test_flag("Report", flags, " | CL_REPORT")
sub( "^0 \\| ", "", result ) sub( "^0 \\| ", "", result )
return result return result
} }
......
...@@ -63,22 +63,16 @@ for (i = 0; i < n_opts; i++) { ...@@ -63,22 +63,16 @@ for (i = 0; i < n_opts; i++) {
if (name == "") if (name == "")
continue; continue;
if (flags[i] ~ "VarExists") if (flag_set_p("VarExists", flags[i]))
continue; continue;
if (flags[i] ~ "Init\\(") init = opt_args("Init", flags[i])
{ if (init != "")
init = flags[i]; init = " = " init;
sub(".*Init\\(","",init);
sub("\\).*","",init); printf ("/* Set by -%s.\n %s */\nint %s%s;\n\n",
init = " = " init;
}
else
init = "";
printf ("/* Set by -%s.\n %s */\nint %s%s;\n\n",
opts[i], help[i], name,init) opts[i], help[i], name,init)
} }
print "const char * const lang_names[] =\n{" print "const char * const lang_names[] =\n{"
...@@ -117,7 +111,7 @@ for (i = 0; i < n_opts; i++) ...@@ -117,7 +111,7 @@ for (i = 0; i < n_opts; i++)
# a later switch S is a longer prefix of a switch T, T # a later switch S is a longer prefix of a switch T, T
# will be back-chained to S in a later iteration of this # will be back-chained to S in a later iteration of this
# for() loop, which is what we want. # for() loop, which is what we want.
if (flags[i] ~ "Joined") { if (flag_set_p("Joined.*", flags[i])) {
for (j = i + 1; j < n_opts; j++) { for (j = i + 1; j < n_opts; j++) {
if (substr (opts[j], 1, len) != opts[i]) if (substr (opts[j], 1, len) != opts[i])
break; break;
......
...@@ -127,7 +127,7 @@ for (i = 0; i < n_opts; i++) ...@@ -127,7 +127,7 @@ for (i = 0; i < n_opts; i++)
# a later switch S is a longer prefix of a switch T, T # a later switch S is a longer prefix of a switch T, T
# will be back-chained to S in a later iteration of this # will be back-chained to S in a later iteration of this
# for() loop, which is what we want. # for() loop, which is what we want.
if (flags[i] ~ "Joined") { if (flag_set_p("Joined.*", flags[i])) {
for (j = i + 1; j < n_opts; j++) { for (j = i + 1; j < n_opts; j++) {
if (substr (opts[j], 1, len) != opts[i]) if (substr (opts[j], 1, len) != opts[i])
break; break;
......
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