[option,handling] optc-gen.awk - support || in EnabledBy()
diff mbox

Message ID CAESRpQBROkSXMMc1KmmRFQ7TBx1e9+DpPeDfHRP2fHzwf2NJ5g@mail.gmail.com
State New
Headers show

Commit Message

Manuel López-Ibáñez Nov. 22, 2014, 10:37 p.m. UTC
For what is worth, the patch looks good to me, except that the form
EnabledBy(@var{opt} || @var{opt2} needs documentation in
doc/options.texi.

Perhaps it could be more condensed as (untested!):

         for (j = 1; j <= n_enabledby_names; j++) {
@@ -49,7 +57,7 @@
                 print "#error Enabledby: " enabledby_name
             } else {
                 condition = "";
-                if (n_enabledby_names == 2) {
+                if (logical_and != 0) {
                     opt_var_name_1 =
search_var_name(enabledby_names[1], opt_numbers, opts, flags, n_opts);
                     opt_var_name_2 =
search_var_name(enabledby_names[2], opt_numbers, opts, flags, n_opts);
                     if (opt_var_name_1 == "") {

If I recall correctly, there are several -W* flags in common.opt and
c-family/c.opt that benefit from this cleanup (Wpointer-sign being
one). It would be nice to convert them to the new format together with
the patch.

A version handling LangEnabledBy(Lang, Wx || Wy) should be fairly
similar and probably even more useful, if you wish to fix also that.

Cheers,

Manuel.

Patch
diff mbox

Index: optc-gen.awk
===================================================================
--- optc-gen.awk    (revision 217510)
+++ optc-gen.awk    (working copy)
@@ -38,8 +38,16 @@ 
 for (i = 0; i < n_opts; i++) {
     enabledby_arg = opt_args("EnabledBy", flags[i]);
     if (enabledby_arg != "") {
-        n_enabledby_names = split(enabledby_arg, enabledby_names, " && ");
-        if (n_enabledby_names > 2) {
+        logical_and = index(enabledby_arg, " && ");
+        if (logical_and != 0) {
+            # EnabledBy(arg1 && arg2)
+            split_sep = " && ";
+        } else {
+            # EnabledBy(arg) or EnabledBy(arg1 || arg2 || arg3)
+            split_sep = " \\|\\| ";
+        }
+        n_enabledby_names = split(enabledby_arg, enabledby_names, split_sep);
+        if (logical_and != 0 && n_enabledby_names > 2) {
             print "#error EnabledBy (Wfoo && Wbar && Wbaz) not
currently supported"
         }