bison-patches
[Top][All Lists]
Advanced

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

[PATCH 2/2] diagnostics: refactor error_message() not to use global vari


From: László Várady
Subject: [PATCH 2/2] diagnostics: refactor error_message() not to use global variables
Date: Fri, 9 Aug 2019 14:24:15 +0200

---
 src/complain.c | 31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/src/complain.c b/src/complain.c
index 7f3c8d1b..75c53192 100644
--- a/src/complain.c
+++ b/src/complain.c
@@ -63,8 +63,6 @@ typedef enum
 /** For each warning type, its severity.  */
 static severity warnings_flag[warnings_size];
 
-static unsigned *indent_ptr = NULL;
-
 styled_ostream_t errstream = NULL;
 
 void
@@ -405,6 +403,7 @@ warnings_print_categories (warnings warn_flags, FILE *out)
  *
  * \param loc     the location, defaulting to the current file,
  *                or the program name.
+ * \param indent  optional indentation for the error message.
  * \param flags   the category for this message.
  * \param sever   to decide the prefix to put before the message
  *                (e.g., "warning").
@@ -416,8 +415,8 @@ warnings_print_categories (warnings warn_flags, FILE *out)
  */
 static
 void
-error_message (const location *loc, warnings flags, severity sever,
-               const char *message, va_list args)
+error_message (const location *loc, unsigned *indent, warnings flags,
+               severity sever, const char *message, va_list args)
 {
   unsigned pos = 0;
 
@@ -427,14 +426,14 @@ error_message (const location *loc, warnings flags, 
severity sever,
     pos += fprintf (stderr, "%s", current_file ? current_file : program_name);
   pos += fprintf (stderr, ": ");
 
-  if (indent_ptr)
+  if (indent)
     {
-      if (*indent_ptr)
+      if (*indent)
         sever = severity_disabled;
-      if (!*indent_ptr)
-        *indent_ptr = pos;
-      else if (*indent_ptr > pos)
-        fprintf (stderr, "%*s", *indent_ptr - pos, "");
+      if (!*indent)
+        *indent = pos;
+      else if (*indent > pos)
+        fprintf (stderr, "%*s", *indent - pos, "");
     }
 
   const char* style = severity_style (sever);
@@ -469,8 +468,8 @@ error_message (const location *loc, warnings flags, 
severity sever,
 /** Raise a complaint (fatal error, error or just warning).  */
 
 static void
-complains (const location *loc, warnings flags, const char *message,
-           va_list args)
+complains (const location *loc, unsigned *indent, warnings flags,
+           const char *message, va_list args)
 {
   severity s = warning_severity (flags);
   if ((flags & complaint) && complaint_status < status_complaint)
@@ -480,7 +479,7 @@ complains (const location *loc, warnings flags, const char 
*message,
     {
       if (severity_error <= s && ! complaint_status)
         complaint_status = status_warning_as_error;
-      error_message (loc, flags, s, message, args);
+      error_message (loc, indent, flags, s, message, args);
     }
 
   if (flags & fatal)
@@ -492,7 +491,7 @@ complain (location const *loc, warnings flags, const char 
*message, ...)
 {
   va_list args;
   va_start (args, message);
-  complains (loc, flags, message, args);
+  complains (loc, NULL, flags, message, args);
   va_end (args);
 }
 
@@ -501,11 +500,9 @@ complain_indent (location const *loc, warnings flags, 
unsigned *indent,
                  const char *message, ...)
 {
   va_list args;
-  indent_ptr = indent;
   va_start (args, message);
-  complains (loc, flags, message, args);
+  complains (loc, indent, flags, message, args);
   va_end (args);
-  indent_ptr = NULL;
 }
 
 void
-- 
2.22.0




reply via email to

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