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>
/* 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] == ':');
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] == ':');
"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. */
extern char *get_cwe_url (int cwe);
+extern const char *get_diagnostic_kind_text (diagnostic_t kind);
+
#endif /* ! GCC_DIAGNOSTIC_H */