bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 3/6] warnings: organize variadic complaints call


From: Akim Demaille
Subject: Re: [PATCH 3/6] warnings: organize variadic complaints call
Date: Mon, 1 Oct 2012 16:51:23 +0200

Le 1 oct. 2012 à 15:44, Akim Demaille a écrit :

> Please, try to factor at the M4 level too: there are
> too many @commands to issue warnings, we don't need
> that many.  For a start, use empty location instead
> of foo_at vs. foo.

I did that bit as follows.  Now let's treat the "warning" kind
argument equally.  We ought to reuse the xargmatch
stuff.

commit c4e3a1622d668c02caab0bebae60f95f4b1225c6
Author: Akim Demaille <address@hidden>
Date:   Mon Oct 1 16:47:50 2012 +0200

    warnings: simplify the m4 interface
    
    * data/bison.m4 (error_at): Replace...
    (error): this.
    (b4_warn, b4_complain, b4_fatal): Bounce to their _at equivalent,
    with empty location.
    * src/scan-skel.l (at_directive_perform): Simplify accordingly.

diff --git a/data/bison.m4 b/data/bison.m4
index 42a548d..7a05473 100644
--- a/data/bison.m4
+++ b/data/bison.m4
@@ -82,30 +82,16 @@ _m4eof
 ])dnl
 m4_if(m4_sysval, [0], [], [m4_fatal([$0: cannot write to stdout])])])
 
-# b4_error(KIND, FORMAT, [ARG1], [ARG2], ...)
-# -------------------------------------------
-# Write @KIND(FORMAT@,ARG1@,ARG2@,...@) to stdout.
+# b4_error(KIND, START, END, FORMAT, [ARG1], [ARG2], ...)
+# -------------------------------------------------------
+# Write @KIND(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout.
 #
 # For example:
 #
-#   b4_error([[warn]], [[invalid value for '%s': %s]], [[foo]], [[3]])
+#   b4_error([[complain]], [[input.y:2.3]], [[input.y:5.4]],
+#            [[invalid %s]], [[foo]])
 m4_define([b4_error],
-[b4_cat(address@hidden(]$2[]]dnl
-[m4_if([$#], [2], [],
-       [m4_foreach([b4_arg],
-                   m4_dquote(m4_shift(m4_shift($@))),
-                   [[@,]b4_arg])])[@)]])])
-
-# b4_error_at(KIND, START, END, FORMAT, [ARG1], [ARG2], ...)
-# ----------------------------------------------------------
-# Write @KIND_at(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout.
-#
-# For example:
-#
-#   b4_error_at([[complain]], [[input.y:2.3]], [[input.y:5.4]],
-#               [[invalid %s]], [[foo]])
-m4_define([b4_error_at],
-[b4_cat(address@hidden(]$2[@,]$3[@,]$4[]]dnl
+[b4_cat(address@hidden(]$2[@,]$3[@,]$4[]]dnl
 [m4_if([$#], [4], [],
        [m4_foreach([b4_arg],
                    m4_dquote(m4_shift(m4_shift(m4_shift(m4_shift($@))))),
@@ -125,21 +111,21 @@ m4_define([b4_error_at],
 #   m4_define([asdf], [ASDF])
 #   m4_define([fsa], [FSA])
 #   m4_define([fdsa], [FDSA])
-#   b4_warn([[[asdf), asdf]]], [[[fsa), fsa]]], [[[fdsa), fdsa]]])
-#   b4_warn([[asdf), asdf]], [[fsa), fsa]], [[fdsa), fdsa]])
-#   b4_warn()
-#   b4_warn(1)
-#   b4_warn(1, 2)
+#   b4_warn_at([[[asdf), asdf]]], [[[fsa), fsa]]], [[[fdsa), fdsa]]])
+#   b4_warn_at([[asdf), asdf]], [[fsa), fsa]], [[fdsa), fdsa]])
+#   b4_warn_at()
+#   b4_warn_at(1)
+#   b4_warn_at(1, 2)
 #
 # Should produce this without newlines:
 #
-#   @warn([asdf), asdf]@,[fsa), fsa]@,[fdsa), fdsa]@)
-#   @warn(asdf), asdf@,fsa), fsa@,fdsa), fdsa@)
+#   @warn_at([asdf), asdf]@,@,@,[fsa), fsa]@,[fdsa), fdsa]@)
+#   @warn(asdf), asdf@,@,@,fsa), fsa@,fdsa), fdsa@)
 #   @warn(@)
 #   @warn(1@)
 #   @warn(1@,2@)
 m4_define([b4_warn],
-[b4_error([[warn]], $@)])
+[b4_error([[warn]], [], [], $@)])
 
 # b4_warn_at(START, END, FORMAT, [ARG1], [ARG2], ...)
 # ---------------------------------------------------
@@ -149,15 +135,15 @@ m4_define([b4_warn],
 #
 #   b4_warn_at([[input.y:2.3]], [[input.y:5.4]], [[invalid %s]], [[foo]])
 m4_define([b4_warn_at],
-[b4_error_at([[warn]], $@)])
+[b4_error([[warn]], $@)])
 
 # b4_complain(FORMAT, [ARG1], [ARG2], ...)
 # ----------------------------------------
-# Write @complain(FORMAT@,ARG1@,ARG2@,...@) to stdout.
+# Bounce to b4_complain_at.
 #
 # See b4_warn example.
 m4_define([b4_complain],
-[b4_error([[complain]], $@)])
+[b4_error([[complain]], [], [], $@)])
 
 # b4_complain_at(START, END, FORMAT, [ARG1], [ARG2], ...)
 # -------------------------------------------------------
@@ -165,15 +151,15 @@ m4_define([b4_complain],
 #
 # See b4_warn_at example.
 m4_define([b4_complain_at],
-[b4_error_at([[complain]], $@)])
+[b4_error([[complain]], $@)])
 
 # b4_fatal(FORMAT, [ARG1], [ARG2], ...)
 # -------------------------------------
-# Write @fatal(FORMAT@,ARG1@,ARG2@,...@) to stdout and exit.
+# Bounce to b4_fatal_at.
 #
 # See b4_warn example.
 m4_define([b4_fatal],
-[b4_error([[fatal]], $@)dnl
+[b4_error([[fatal]], [], [], $@)dnl
 m4_exit(1)])
 
 # b4_fatal_at(START, END, FORMAT, [ARG1], [ARG2], ...)
@@ -182,7 +168,7 @@ m4_exit(1)])
 #
 # See b4_warn_at example.
 m4_define([b4_fatal_at],
-[b4_error_at([[fatal]], $@)dnl
+[b4_error([[fatal]], $@)dnl
 m4_exit(1)])
 
 
diff --git a/src/scan-skel.l b/src/scan-skel.l
index 68f528c..607dc3c 100644
--- a/src/scan-skel.l
+++ b/src/scan-skel.l
@@ -186,25 +186,23 @@ at_directive_perform (int argc, char *argv[], char 
**outnamep, int *out_linenop)
         fail_for_at_directive_too_many_args (argv[0]);
       fputs (last_component (argv[1]), yyout);
     }
-  else if (STREQ (argv[0], "@warn") || STREQ (argv[0], "@warn_at")
-           || STREQ (argv[0], "@complain") || STREQ (argv[0], "@complain_at")
-           || STREQ (argv[0], "@fatal") || STREQ (argv[0], "@fatal_at"))
+  else if (STREQ (argv[0], "@warn")
+           || STREQ (argv[0], "@complain")
+           || STREQ (argv[0], "@fatal"))
     {
       warnings w = flag (*argv);
       location loc;
       location *locp = NULL;
-      if (STREQ (*argv + strlen (*argv) - 3, "_at"))
+      if (argc < 4)
+        fail_for_at_directive_too_few_args (argv[0]);
+      if (argv[1] && argv[1][0])
         {
-          if (argc < 4)
-            fail_for_at_directive_too_few_args (argv[0]);
           boundary_set_from_string (&loc.start, argv[1]);
           boundary_set_from_string (&loc.end, argv[2]);
-          argc -= 2;
-          argv += 2;
           locp = &loc;
         }
-      else if (argc < 2)
-        fail_for_at_directive_too_few_args (argv[0]);
+      argc -= 2;
+      argv += 2;
       complain_args (locp, w, argc, argv);
     }
   else if (STREQ (argv[0], "@output"))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]