[pushed] diagnostics: consolidate group-handling fields in diagnostic_context

Message ID 20231103180241.2338051-1-dmalcolm@redhat.com
State Unresolved
Headers
Series [pushed] diagnostics: consolidate group-handling fields in diagnostic_context |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

David Malcolm Nov. 3, 2023, 6:02 p.m. UTC
  No functional change intended.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r14-5112-gae8abcb81ed814.

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.
---
 gcc/diagnostic.cc | 42 ++++++++++++++++++++++++++++--------------
 gcc/diagnostic.h  | 19 ++++++++++++++-----
 2 files changed, 42 insertions(+), 19 deletions(-)
  

Patch

diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
index 0f392358aef..0759fae916e 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 a2c8740cbd0..ed1b6c0c7b1 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.  */