diff mbox

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

Message ID 547083AD.3010504@net-b.de
State New
Headers show

Commit Message

Tobias Burnus Nov. 22, 2014, 12:38 p.m. UTC
In fortran/*.opt, I'd like to use:

Fortran Var(warn_tabs) Warning EnabledBy(Wall || Wpedantic)

However, "||" is not supported by EnabledBy. This patch adds it. I 
checked that option.c remains the same after the patch.

I attached the patch twice: Once with "-w -U16" to show the modification 
(minus re-indenting) and once with re-indenting.

OK for the trunk?

Tobias

gcc/
2014-11-22  Tobias Burnus <net-b.de>

     * optc-gen.awk: Support || in EnabledBy.
diff mbox

Patch

diff --git a/gcc/optc-gen.awk b/gcc/optc-gen.awk
index ecb225c..0707db2 100644
--- a/gcc/optc-gen.awk
+++ b/gcc/optc-gen.awk
@@ -38,36 +38,57 @@  for (i = 0; i < n_langs; i++) {
 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) {
-            print "#error EnabledBy (Wfoo && Wbar && Wbaz) not currently supported"
-        }
-        for (j = 1; j <= n_enabledby_names; j++) {
-            enabledby_name = enabledby_names[j];
-            enabledby_index = opt_numbers[enabledby_name];
-            if (enabledby_index == "") {
-                print "#error Enabledby: " enabledby_name 
-            } else {
-                condition = "";
-                if (n_enabledby_names == 2) {
-                    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 == "") {
-                        print "#error " enabledby_names[1] " does not have a Var() flag"
+       if (index(enabledby_arg, " && ") == 0) {
+           # Enabledby(arg) or Enabledby(arg1 || arg2 || arg3)
+           n_enabledby_names = split(enabledby_arg, enabledby_names, " \\|\\| ");
+           for (j = 1; j <= n_enabledby_names; j++) {
+                enabledby_name = enabledby_names[j];
+                enabledby_index = opt_numbers[enabledby_name];
+                if (enabledby_index == "") {
+                    print "#error Enabledby: " enabledby_name
+                } else {
+                    condition = "";
+                    if (enables[enabledby_name] == "") {
+                        enabledby[n_enabledby] = enabledby_name;
+                        n_enabledby++;
                     }
-                    if (opt_var_name_2 == "") {
-                        print "#error " enabledby_names[2] " does not have a Var() flag"
-                    }
-                    condition = "opts->x_" opt_var_name_1 " && opts->x_" opt_var_name_2;
+                    enables[enabledby_name] = enables[enabledby_name] opts[i] ";";
+                    enablesif[enabledby_name] = enablesif[enabledby_name] condition ";";
                 }
-                if (enables[enabledby_name] == "") {
-                    enabledby[n_enabledby] = enabledby_name;
-                    n_enabledby++;
+           }
+       } else {
+            # Enabledby(arg1 && arg2)
+            n_enabledby_names = split(enabledby_arg, enabledby_names, " && ");
+            if (n_enabledby_names > 2) {
+                print "#error EnabledBy (Wfoo && Wbar && Wbaz) not currently supported"
+            }
+            for (j = 1; j <= n_enabledby_names; j++) {
+                enabledby_name = enabledby_names[j];
+                enabledby_index = opt_numbers[enabledby_name];
+                if (enabledby_index == "") {
+                    print "#error Enabledby: " enabledby_name
+                } else {
+                    condition = "";
+                    if (n_enabledby_names == 2) {
+                        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 == "") {
+                            print "#error " enabledby_names[1] " does not have a Var() flag"
+                        }
+                        if (opt_var_name_2 == "") {
+                            print "#error " enabledby_names[2] " does not have a Var() flag"
+                        }
+                        condition = "opts->x_" opt_var_name_1 " && opts->x_" opt_var_name_2;
+                    }
+                    if (enables[enabledby_name] == "") {
+                        enabledby[n_enabledby] = enabledby_name;
+                        n_enabledby++;
+                    }
+                    enables[enabledby_name] = enables[enabledby_name] opts[i] ";";
+                    enablesif[enabledby_name] = enablesif[enabledby_name] condition ";";
                 }
-                enables[enabledby_name] = enables[enabledby_name] opts[i] ";";
-                enablesif[enabledby_name] = enablesif[enabledby_name] condition ";";
             }
-        }
+      }
     }
 
     enabledby_arg = opt_args("LangEnabledBy", flags[i]);