This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix .opt file parsing to allow nested parentheses in option property arguments.
- From: Dave Korn <dave dot korn dot cygwin at googlemail dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 09 Jul 2009 14:12:07 +0100
- Subject: [PATCH] Fix .opt file parsing to allow nested parentheses in option property arguments.
Hi all,
I ran into difficulty when I wanted to use the preprocessor "defined (X)"
operator in a Condition(...) option property. The simple parsing in the awk
script got fooled by the closing parenthesis of the defined operator, taking
it for the end of the option property argument itself, and I ended up with a
line in $objdir/gcc/options.c looking like
#if defined (X
... which of course didn't work. Rather than attempting to count the depth of
nested parentheses using a regex language I figured the simple approach would
just be to invent a way of quoting the argument string, and picked on curly
braces, which aren't currently used anywhere in .opt files (at least according
to "find gcc/ -name '*.opt' | xargs grep '{'", anyway).
gcc/ChangeLog:
* opt-functions.awk (opt_args): Allow argument to be enclosed in
curly braces.
* doc/options.texi (Option properties): Mention new quoting syntax.
Tested by running the scripts manually and visually inspecting options.c,
then completing a bootstrap, and docs tested by "make doc info dvi html pdf".
OK for head?
cheers,
DaveK
Index: gcc/opt-functions.awk
===================================================================
--- gcc/opt-functions.awk (revision 149338)
+++ gcc/opt-functions.awk (working copy)
@@ -41,7 +41,13 @@ function opt_args(name, flags)
if (flags !~ " " name "\\(")
return ""
sub(".* " name "\\(", "", flags)
- sub("\\).*", "", flags)
+ if (flags ~ "^{")
+ {
+ sub ("^{", "", flags)
+ sub("}\\).*", "", flags)
+ }
+ else
+ sub("\\).*", "", flags)
return flags
}
Index: gcc/doc/options.texi
===================================================================
--- gcc/doc/options.texi (revision 149338)
+++ gcc/doc/options.texi (working copy)
@@ -84,8 +84,17 @@ configurations and yet the masks always need to be
@node Option properties
@section Option properties
-The second field of an option record can specify the following properties:
+The second field of an option record can specify any of the following
+properties. When an option takes an argument, it is enlosed in parentheses
+following the option property name. The parser that handles option files
+is quite simplistic, and will be tricked by any nested parentheses within
+the argument text itself; in this case, the entire option argument can
+be wrapped in curly braces within the parentheses to demarcate it, e.g.:
+@smallexample
+Condition(@{defined (USE_CYGWIN_LIBSTDCXX_WRAPPERS)@})
+@end smallexample
+
@table @code
@item Common
The option is available for all languages and targets.