]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
diagnostics: remove duplicate copies of diagnostic_kind_text
authorDavid Malcolm <dmalcolm@redhat.com>
Fri, 21 Jun 2024 22:20:38 +0000 (18:20 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Fri, 21 Jun 2024 22:20:38 +0000 (18:20 -0400)
No functional change intended.

gcc/ChangeLog:
* diagnostic-format-json.cc
(json_output_format::on_end_diagnostic): Use
get_diagnostic_kind_text rather than embedding a duplicate copy of
the table.
* diagnostic-format-sarif.cc
(make_rule_id_for_diagnostic_kind): Likewise.
* diagnostic.cc (get_diagnostic_kind_text): New.
* diagnostic.h (get_diagnostic_kind_text): New decl.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/diagnostic-format-json.cc
gcc/diagnostic-format-sarif.cc
gcc/diagnostic.cc
gcc/diagnostic.h

index ec03ac15aebabbf77a3178870c87d66be56ad1b5..8f2ff6cfde20d8e205dd38b45d34abcfdb6fc43d 100644 (file)
@@ -231,14 +231,8 @@ json_output_format::on_end_diagnostic (const diagnostic_info &diagnostic,
 
   /* Get "kind" of diagnostic.  */
   {
-    static const char *const diagnostic_kind_text[] = {
-#define DEFINE_DIAGNOSTIC_KIND(K, T, C) (T),
-#include "diagnostic.def"
-#undef DEFINE_DIAGNOSTIC_KIND
-      "must-not-happen"
-    };
     /* Lose the trailing ": ".  */
-    const char *kind_text = diagnostic_kind_text[diagnostic.kind];
+    const char *kind_text = get_diagnostic_kind_text (diagnostic.kind);
     size_t len = strlen (kind_text);
     gcc_assert (len > 2);
     gcc_assert (kind_text[len - 2] == ':');
index 5581aa1579e90b412189da229c3829482cbe938b..2745c72ea3e5568b972a063e63b0e8693fbf4e70 100644 (file)
@@ -662,14 +662,8 @@ maybe_get_sarif_level (diagnostic_t diag_kind)
 static char *
 make_rule_id_for_diagnostic_kind (diagnostic_t diag_kind)
 {
-  static const char *const diagnostic_kind_text[] = {
-#define DEFINE_DIAGNOSTIC_KIND(K, T, C) (T),
-#include "diagnostic.def"
-#undef DEFINE_DIAGNOSTIC_KIND
-    "must-not-happen"
-  };
   /* Lose the trailing ": ".  */
-  const char *kind_text = diagnostic_kind_text[diag_kind];
+  const char *kind_text = get_diagnostic_kind_text (diag_kind);
   size_t len = strlen (kind_text);
   gcc_assert (len > 2);
   gcc_assert (kind_text[len - 2] == ':');
index c66aa5af5ff5556b09d547ef48aaea19b9338d35..8fc22466b928aabb0f754ddfd3dd0c23c94da689 100644 (file)
@@ -590,6 +590,14 @@ static const char *const diagnostic_kind_text[] = {
   "must-not-happen"
 };
 
+/* Get unlocalized string describing KIND.  */
+
+const char *
+get_diagnostic_kind_text (diagnostic_t kind)
+{
+  return diagnostic_kind_text[kind];
+}
+
 /* Return a malloc'd string describing a location and the severity of the
    diagnostic, e.g. "foo.c:42:10: error: ".  The caller is responsible for
    freeing the memory.  */
index c6846525da3125d2c984b3604bc9892a08d81202..4969f07836ccb8a35e65d9358b83438e72c33786 100644 (file)
@@ -1121,4 +1121,6 @@ option_unspecified_p (int opt)
 
 extern char *get_cwe_url (int cwe);
 
+extern const char *get_diagnostic_kind_text (diagnostic_t kind);
+
 #endif /* ! GCC_DIAGNOSTIC_H */