diff options
author | David Malcolm <dmalcolm@redhat.com> | 2024-06-21 18:20:38 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2024-06-21 18:20:38 -0400 |
commit | ccbcde5ec0e481e1ea775649d59691b6f5fcc5a1 (patch) | |
tree | c85d19c0ee9c144b542d73de8e02894e155950f2 /gcc | |
parent | 4819dc7d4b84afa98881ffb8471cf19bc362221b (diff) | |
download | gcc-ccbcde5ec0e481e1ea775649d59691b6f5fcc5a1.zip gcc-ccbcde5ec0e481e1ea775649d59691b6f5fcc5a1.tar.gz gcc-ccbcde5ec0e481e1ea775649d59691b6f5fcc5a1.tar.bz2 |
diagnostics: remove duplicate copies of diagnostic_kind_text
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>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/diagnostic-format-json.cc | 8 | ||||
-rw-r--r-- | gcc/diagnostic-format-sarif.cc | 8 | ||||
-rw-r--r-- | gcc/diagnostic.cc | 8 | ||||
-rw-r--r-- | gcc/diagnostic.h | 2 |
4 files changed, 12 insertions, 14 deletions
diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc index ec03ac1..8f2ff6c 100644 --- a/gcc/diagnostic-format-json.cc +++ b/gcc/diagnostic-format-json.cc @@ -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] == ':'); diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc index 5581aa1..2745c72 100644 --- a/gcc/diagnostic-format-sarif.cc +++ b/gcc/diagnostic-format-sarif.cc @@ -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] == ':'); diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index c66aa5a..8fc2246 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -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. */ diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index c684652..4969f078 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -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 */ |