@@ -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] == ':');
@@ -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] == ':');
@@ -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. */
@@ -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 */
No functional change intended. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Successful run of analyzer integration tests on x86_64-pc-linux-gnu. Pushed to trunk as r15-1556-gccbcde5ec0e481. 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 | 8 +------- gcc/diagnostic-format-sarif.cc | 8 +------- gcc/diagnostic.cc | 8 ++++++++ gcc/diagnostic.h | 2 ++ 4 files changed, 12 insertions(+), 14 deletions(-)