aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2023-11-03 13:55:52 -0400
committerDavid Malcolm <dmalcolm@redhat.com>2023-11-03 13:55:52 -0400
commitae8abcb81ed81456c0fe5ff8e0c060c9fb9c82d7 (patch)
tree0cd24bf361e018a67e0f19f2245f8e1ba9dacf6a /gcc
parent413ac2c8608cd0378955af27f69e45274b025b32 (diff)
downloadgcc-ae8abcb81ed81456c0fe5ff8e0c060c9fb9c82d7.zip
gcc-ae8abcb81ed81456c0fe5ff8e0c060c9fb9c82d7.tar.gz
gcc-ae8abcb81ed81456c0fe5ff8e0c060c9fb9c82d7.tar.bz2
diagnostics: consolidate group-handling fields in diagnostic_context
No functional change intended. gcc/ChangeLog: * diagnostic.cc (diagnostic_initialize): Update for consolidation of group-based fields. (diagnostic_report_diagnostic): Likewise. (diagnostic_context::begin_group): New, based on body of auto_diagnostic_group's ctor. (diagnostic_context::end_group): New, based on body of auto_diagnostic_group's dtor. (auto_diagnostic_group::auto_diagnostic_group): Convert to a call to begin_group. (auto_diagnostic_group::~auto_diagnostic_group): Convert to a call to end_group. * diagnostic.h (diagnostic_context::begin_group): New decl. (diagnostic_context::end_group): New decl. (diagnostic_context::diagnostic_group_nesting_depth): Rename to... (diagnostic_context::m_diagnostic_groups.m_nesting_depth): ...this. (diagnostic_context::diagnostic_group_emission_count): Rename to... (diagnostic_context::m_diagnostic_groups::m_emission_count): ...this. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/diagnostic.cc42
-rw-r--r--gcc/diagnostic.h19
2 files changed, 42 insertions, 19 deletions
diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
index 0f39235..0759fae 100644
--- a/gcc/diagnostic.cc
+++ b/gcc/diagnostic.cc
@@ -218,8 +218,8 @@ diagnostic_initialize (diagnostic_context *context, int n_opts)
context->tabstop = 8;
context->escape_format = DIAGNOSTICS_ESCAPE_FORMAT_UNICODE;
context->edit_context_ptr = NULL;
- context->diagnostic_group_nesting_depth = 0;
- context->diagnostic_group_emission_count = 0;
+ context->m_diagnostic_groups.m_nesting_depth = 0;
+ context->m_diagnostic_groups.m_emission_count = 0;
context->m_output_format = new diagnostic_text_output_format (*context);
context->set_locations_cb = nullptr;
context->ice_handler_cb = NULL;
@@ -1570,9 +1570,9 @@ diagnostic_report_diagnostic (diagnostic_context *context,
++diagnostic_kind_count (context, diagnostic->kind);
/* Is this the initial diagnostic within the stack of groups? */
- if (context->diagnostic_group_emission_count == 0)
+ if (context->m_diagnostic_groups.m_emission_count == 0)
context->m_output_format->on_begin_group ();
- context->diagnostic_group_emission_count++;
+ context->m_diagnostic_groups.m_emission_count++;
pp_format (context->printer, &diagnostic->message);
context->m_output_format->on_begin_diagnostic (diagnostic);
@@ -2296,28 +2296,42 @@ fancy_abort (const char *file, int line, const char *function)
internal_error ("in %s, at %s:%d", function, trim_filename (file), line);
}
+/* struct diagnostic_context. */
+
+void
+diagnostic_context::begin_group ()
+{
+ m_diagnostic_groups.m_nesting_depth++;
+}
+
+void
+diagnostic_context::end_group ()
+{
+ if (--m_diagnostic_groups.m_nesting_depth == 0)
+ {
+ /* Handle the case where we've popped the final diagnostic group.
+ If any diagnostics were emitted, give the context a chance
+ to do something. */
+ if (m_diagnostic_groups.m_emission_count > 0)
+ m_output_format->on_end_group ();
+ m_diagnostic_groups.m_emission_count = 0;
+ }
+}
+
/* class auto_diagnostic_group. */
/* Constructor: "push" this group into global_dc. */
auto_diagnostic_group::auto_diagnostic_group ()
{
- global_dc->diagnostic_group_nesting_depth++;
+ global_dc->begin_group ();
}
/* Destructor: "pop" this group from global_dc. */
auto_diagnostic_group::~auto_diagnostic_group ()
{
- if (--global_dc->diagnostic_group_nesting_depth == 0)
- {
- /* Handle the case where we've popped the final diagnostic group.
- If any diagnostics were emitted, give the context a chance
- to do something. */
- if (global_dc->diagnostic_group_emission_count > 0)
- global_dc->m_output_format->on_end_group ();
- global_dc->diagnostic_group_emission_count = 0;
- }
+ global_dc->end_group ();
}
/* class diagnostic_text_output_format : public diagnostic_output_format. */
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index a2c8740..ed1b6c0 100644
--- a/gcc/diagnostic.h
+++ b/gcc/diagnostic.h
@@ -226,6 +226,12 @@ public:
the context of a diagnostic message. */
struct diagnostic_context
{
+public:
+ void begin_group ();
+ void end_group ();
+
+public:
+
/* Where most of the diagnostic formatting work is done. */
pretty_printer *printer;
@@ -443,12 +449,15 @@ struct diagnostic_context
applied, for generating patches. */
edit_context *edit_context_ptr;
- /* How many diagnostic_group instances are currently alive. */
- int diagnostic_group_nesting_depth;
+ /* Fields relating to diagnostic groups. */
+ struct {
+ /* How many diagnostic_group instances are currently alive. */
+ int m_nesting_depth;
- /* How many diagnostics have been emitted since the bottommost
- diagnostic_group was pushed. */
- int diagnostic_group_emission_count;
+ /* How many diagnostics have been emitted since the bottommost
+ diagnostic_group was pushed. */
+ int m_emission_count;
+ } m_diagnostic_groups;
/* How to output diagnostics (text vs a structured format such as JSON).
Must be non-NULL; owned by context. */