options: Improve 'LangEnabledBy' option property diagnostics (was: r193303 - in /trunk/gcc: ChangeLog opt-function...)
Commit Message
Hi!
Once the three 'LangEnabledBy' option property patches that I've just
posted are accepted, we may proceed here:
On 2012-11-07T18:11:02+0000, manu@gcc.gnu.org wrote:
> Author: manu
> Date: Wed Nov 7 18:11:01 2012
> New Revision: 193303
>
> URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=193303
> Log:
> 2012-11-07 Manuel López-Ibáñez <manu@gcc.gnu.org>
>
> * optc-gen.awk: Factor code out to...
> * opt-functions.awk (lang_enabled_by): ... this new function.
>
> Modified:
> trunk/gcc/ChangeLog
> trunk/gcc/opt-functions.awk
> trunk/gcc/optc-gen.awk
I'm generally very much in favor of abstracting functionality into
separate functions. Here, however, there ever existed only one user of
'gcc/opt-functions.awk:lang_enabled_by', its interface is a bit clumsy,
leading to (slightly) confusing diagnostics, and all handling for other
related option properties remains in the original place, so I find that
in fact confusing to be split out, and scattered over two files. I thus
propose to merge 'gcc/opt-functions.awk:lang_enabled_by' back into its
original place, and then improve diagnostics. OK to push the attached
"options: Improve 'LangEnabledBy' option property diagnostics"? In
addition to standard testing, I've manually verified the error cases.
Grüße
Thomas
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
Comments
On Tue, 29 Mar 2022, Thomas Schwinge wrote:
> I'm generally very much in favor of abstracting functionality into
> separate functions. Here, however, there ever existed only one user of
> 'gcc/opt-functions.awk:lang_enabled_by', its interface is a bit clumsy,
> leading to (slightly) confusing diagnostics, and all handling for other
> related option properties remains in the original place, so I find that
> in fact confusing to be split out, and scattered over two files. I thus
> propose to merge 'gcc/opt-functions.awk:lang_enabled_by' back into its
> original place, and then improve diagnostics. OK to push the attached
> "options: Improve 'LangEnabledBy' option property diagnostics"? In
> addition to standard testing, I've manually verified the error cases.
OK.
From 08eb8eca7673d2ce13ad22fd7e8823f5864e740e Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Mon, 28 Mar 2022 10:55:49 +0200
Subject: [PATCH] options: Improve 'LangEnabledBy' option property diagnostics
No changes in generated files.
gcc/
* opt-functions.awk (n_args): New function.
(lang_enabled_by): Merge function into...
* optc-gen.awk <END>: ... sole user here.
Improve diagnostics.
---
gcc/opt-functions.awk | 47 +++++++++---------------------------
gcc/optc-gen.awk | 56 +++++++++++++++++++++++++++++++++++++++----
2 files changed, 62 insertions(+), 41 deletions(-)
@@ -82,6 +82,17 @@ function opt_args_non_empty(name, flags, description)
return args
}
+# Return the number of comma-separated element of S.
+function n_args(s)
+{
+ n = 1
+ while (s ~ ",") {
+ n++
+ sub("[^,]*, *", "", s)
+ }
+ return n
+}
+
# Return the Nth comma-separated element of S. Return the empty string
# if S does not contain N elements.
function nth_arg(n, s)
@@ -376,39 +387,3 @@ function integer_range_info(range_option, init, option, uinteger_used)
else
return "-1, -1"
}
-
-# Handle LangEnabledBy(ENABLED_BY_LANGS, ENABLEDBY_NAME, ENABLEDBY_POSARG,
-# ENABLEDBY_NEGARG). This function does not return anything.
-function lang_enabled_by(enabledby_langs, enabledby_name, enabledby_posarg, enabledby_negarg)
-{
- n_enabledby_arg_langs = split(enabledby_langs, enabledby_arg_langs, " ");
- if (enabledby_posarg != "" && enabledby_negarg != "") {
- with_args = "," enabledby_posarg "," enabledby_negarg
- } else if (enabledby_posarg == "" && enabledby_negarg == "") {
- with_args = ""
- } else {
- print "#error " opts[i] " LangEnabledBy("enabledby_langs","enabledby_name", " \
- enabledby_posarg", " enabledby_negarg \
- ") with three arguments, it should have either 2 or 4"
- }
-
- n_enabledby_array = split(enabledby_name, enabledby_array, " \\|\\| ");
- for (k = 1; k <= n_enabledby_array; k++) {
- enabledby_index = opt_numbers[enabledby_array[k]];
- if (enabledby_index == "") {
- print "#error " opts[i] " LangEnabledBy("enabledby_langs","enabledby_name", " \
- enabledby_posarg", " enabledby_negarg"), unknown option '" enabledby_name "'"
- } else {
- for (j = 1; j <= n_enabledby_arg_langs; j++) {
- lang_name = lang_sanitized_name(enabledby_arg_langs[j]);
- lang_index = lang_numbers[enabledby_arg_langs[j]];
- if (enables[lang_name,enabledby_array[k]] == "") {
- enabledby[lang_name,n_enabledby_lang[lang_index]] = enabledby_array[k];
- n_enabledby_lang[lang_index]++;
- }
- enables[lang_name,enabledby_array[k]] \
- = enables[lang_name,enabledby_array[k]] opts[i] with_args ";";
- }
- }
- }
-}
@@ -98,11 +98,57 @@ for (i = 0; i < n_opts; i++) {
enabledby_arg = opt_args("LangEnabledBy", flags[i]);
if (enabledby_arg != "") {
- enabledby_langs = nth_arg(0, enabledby_arg);
- enabledby_name = nth_arg(1, enabledby_arg);
- enabledby_posarg = nth_arg(2, enabledby_arg);
- enabledby_negarg = nth_arg(3, enabledby_arg);
- lang_enabled_by(enabledby_langs, enabledby_name, enabledby_posarg, enabledby_negarg);
+ enabledby_n_args = n_args(enabledby_arg)
+ if (enabledby_n_args != 2 \
+ && enabledby_n_args != 4) {
+ print "#error " opts[i] " LangEnabledBy(" enabledby_arg ") must specify two or four arguments"
+ }
+
+ enabledby_langs = nth_arg(0, enabledby_arg);
+ if (enabledby_langs == "")
+ print "#error " opts[i] " LangEnabledBy(" enabledby_arg ") must specify LANGUAGE"
+ enabledby_opt = nth_arg(1, enabledby_arg);
+ if (enabledby_opt == "")
+ print "#error " opts[i] " LangEnabledBy(" enabledby_arg ") must specify OPT"
+
+ enabledby_posarg_negarg = ""
+ if (enabledby_n_args == 4) {
+ enabledby_posarg = nth_arg(2, enabledby_arg);
+ enabledby_negarg = nth_arg(3, enabledby_arg);
+ if (enabledby_posarg == "" \
+ || enabledby_negarg == "")
+ print "#error " opts[i] " LangEnabledBy(" enabledby_arg ") with four arguments must specify POSARG and NEGARG"
+ else
+ enabledby_posarg_negarg = "," enabledby_posarg "," enabledby_negarg
+ }
+
+ n_enabledby_arg_langs = split(enabledby_langs, enabledby_arg_langs, " ");
+ n_enabledby_array = split(enabledby_opt, enabledby_array, " \\|\\| ");
+ for (k = 1; k <= n_enabledby_array; k++) {
+ enabledby_index = opt_numbers[enabledby_array[k]];
+ if (enabledby_index == "") {
+ print "#error " opts[i] " LangEnabledBy(" enabledby_arg "), unknown option '" enabledby_opt "'"
+ continue
+ }
+
+ for (j = 1; j <= n_enabledby_arg_langs; j++) {
+ lang_name = enabledby_arg_langs[j]
+ lang_index = lang_numbers[lang_name];
+ if (lang_index == "") {
+ print "#error " opts[i] " LangEnabledBy(" enabledby_arg "), unknown language '" lang_name "'"
+ continue
+ }
+
+ lang_name = lang_sanitized_name(lang_name);
+
+ if (enables[lang_name,enabledby_array[k]] == "") {
+ enabledby[lang_name,n_enabledby_lang[lang_index]] = enabledby_array[k];
+ n_enabledby_lang[lang_index]++;
+ }
+ enables[lang_name,enabledby_array[k]] \
+ = enables[lang_name,enabledby_array[k]] opts[i] enabledby_posarg_negarg ";";
+ }
+ }
}
if (flag_set_p("Param", flags[i]) && !(opts[i] ~ "^-param="))
--
2.25.1