mirror of
https://forge.sourceware.org/marek/gcc.git
synced 2026-02-22 03:47:02 -05:00
diagnostics: add class sink::extension
This patch provides a way for plugins to add extra information to a diagnostic sink, potentially capturing more information via a "finalizer" hook. gcc/c-family/ChangeLog: * c-opts.cc: Define INCLUDE_VECTOR. gcc/cp/ChangeLog: * error.cc: Define INCLUDE_VECTOR. gcc/ChangeLog: * diagnostic-global-context.cc: Define INCLUDE_VECTOR. * diagnostics/buffering.cc: Likewise. * diagnostics/context.cc (context::finish): Call finalize_extensions on each sink. (sink::dump): Dump any extensions. (sink::finalize_extensions): New. * diagnostics/macro-unwinding.cc: Define INCLUDE_VECTOR. * diagnostics/selftest-context.cc: Likewise. * diagnostics/sink.h (class sink::extension): New. (sink::add_extension): New. (sink::finalize_extensions): New decl. (sink::m_extensions): New member. * gcc.cc: Define INCLUDE_VECTOR. * langhooks.cc: Likewise. * opts.cc: Likewise. * tree-diagnostic-client-data-hooks.cc: Likewise. * tree-diagnostic.cc: Likewise. gcc/fortran/ChangeLog: * error.cc: Define INCLUDE_VECTOR. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_group_plugin.cc: Define INCLUDE_VECTOR. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc: Likewise. * gcc.dg/plugin/location_overflow_plugin.cc: Likewise. libcc1/ChangeLog: * context.cc: Define INCLUDE_VECTOR. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
This commit is contained in:
@@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with GCC; see the file COPYING3. If not see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#define INCLUDE_VECTOR
|
||||
#include "config.h"
|
||||
#include "system.h"
|
||||
#include "coretypes.h"
|
||||
|
||||
@@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with GCC; see the file COPYING3. If not see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#define INCLUDE_VECTOR
|
||||
#include "config.h"
|
||||
/* For use with name_hint. */
|
||||
#include "system.h"
|
||||
|
||||
@@ -22,6 +22,7 @@ along with GCC; see the file COPYING3. If not see
|
||||
/* This file implements the parts of the language independent aspect
|
||||
of diagnostic messages that implicitly use global_dc. */
|
||||
|
||||
#define INCLUDE_VECTOR
|
||||
#include "config.h"
|
||||
#include "system.h"
|
||||
#include "coretypes.h"
|
||||
|
||||
@@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with GCC; see the file COPYING3. If not see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#define INCLUDE_VECTOR
|
||||
#include "config.h"
|
||||
#include "system.h"
|
||||
#include "coretypes.h"
|
||||
|
||||
@@ -361,6 +361,9 @@ context::finish ()
|
||||
dump (m_logger->get_stream (), m_logger->get_indent ());
|
||||
}
|
||||
|
||||
for (auto iter : m_sinks)
|
||||
iter->finalize_extensions ();
|
||||
|
||||
/* We might be handling a fatal error.
|
||||
Close any active diagnostic groups, which may trigger flushing
|
||||
sinks. */
|
||||
@@ -1860,6 +1863,20 @@ sink::dump (FILE *out, int indent) const
|
||||
{
|
||||
dumping::emit_heading (out, indent, "printer");
|
||||
m_printer->dump (out, indent + 2);
|
||||
|
||||
dumping::emit_heading (out, indent, "extensions");
|
||||
if (m_extensions.empty ())
|
||||
dumping::emit_none (out, indent + 2);
|
||||
else
|
||||
for (auto &ext : m_extensions)
|
||||
ext->dump (out, indent + 2);
|
||||
}
|
||||
|
||||
void
|
||||
sink::finalize_extensions ()
|
||||
{
|
||||
for (auto &ext : m_extensions)
|
||||
ext->finalize ();
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with GCC; see the file COPYING3. If not see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#define INCLUDE_VECTOR
|
||||
#include "config.h"
|
||||
#include "system.h"
|
||||
#include "coretypes.h"
|
||||
|
||||
@@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with GCC; see the file COPYING3. If not see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#define INCLUDE_VECTOR
|
||||
#include "config.h"
|
||||
#include "system.h"
|
||||
#include "coretypes.h"
|
||||
|
||||
@@ -34,6 +34,27 @@ class per_sink_buffer;
|
||||
class sink
|
||||
{
|
||||
public:
|
||||
/* Abstract base class for adding additional functionality to a sink
|
||||
(e.g. via a plugin). */
|
||||
class extension
|
||||
{
|
||||
public:
|
||||
virtual ~extension () {}
|
||||
virtual void dump (FILE *out, int indent) const = 0;
|
||||
virtual void finalize () {}
|
||||
|
||||
sink &get_sink () const { return m_sink; }
|
||||
|
||||
protected:
|
||||
extension (sink &sink_)
|
||||
: m_sink (sink_)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
sink &m_sink;
|
||||
};
|
||||
|
||||
virtual ~sink () {}
|
||||
|
||||
virtual text_sink *dyn_cast_text_sink () { return nullptr; }
|
||||
@@ -92,6 +113,15 @@ public:
|
||||
|
||||
logging::logger *get_logger () { return m_context.get_logger (); }
|
||||
|
||||
void
|
||||
add_extension (std::unique_ptr<extension> sink_ext)
|
||||
{
|
||||
m_extensions.push_back (std::move (sink_ext));
|
||||
}
|
||||
|
||||
void
|
||||
finalize_extensions ();
|
||||
|
||||
protected:
|
||||
sink (context &dc)
|
||||
: m_context (dc),
|
||||
@@ -101,6 +131,9 @@ protected:
|
||||
protected:
|
||||
context &m_context;
|
||||
std::unique_ptr<pretty_printer> m_printer;
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<extension>> m_extensions;
|
||||
};
|
||||
|
||||
extern void
|
||||
|
||||
@@ -24,6 +24,7 @@ along with GCC; see the file COPYING3. If not see
|
||||
for possible use later. If a line does not match a legal
|
||||
construction, then the saved error message is reported. */
|
||||
|
||||
#define INCLUDE_VECTOR
|
||||
#include "config.h"
|
||||
#include "system.h"
|
||||
#include "coretypes.h"
|
||||
|
||||
@@ -28,6 +28,7 @@ Once it knows which kind of compilation to perform, the procedure for
|
||||
compilation is specified by a string called a "spec". */
|
||||
|
||||
#define INCLUDE_STRING
|
||||
#define INCLUDE_VECTOR
|
||||
#include "config.h"
|
||||
#include "system.h"
|
||||
#ifdef HOST_HAS_PERSONALITY_ADDR_NO_RANDOMIZE
|
||||
|
||||
@@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with GCC; see the file COPYING3. If not see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#define INCLUDE_VECTOR
|
||||
#include "config.h"
|
||||
#include "system.h"
|
||||
#include "coretypes.h"
|
||||
|
||||
@@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with GCC; see the file COPYING3. If not see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#define INCLUDE_VECTOR
|
||||
#include "config.h"
|
||||
#include "system.h"
|
||||
#include "intl.h"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* { dg-options "-O" } */
|
||||
|
||||
#define INCLUDE_VECTOR
|
||||
#include "gcc-plugin.h"
|
||||
#include "config.h"
|
||||
#include "system.h"
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
to ensure that further very long lines don't start a new linemap.
|
||||
This also means that we can't use macros in the test files. */
|
||||
|
||||
#define INCLUDE_VECTOR
|
||||
#include "gcc-plugin.h"
|
||||
#include "config.h"
|
||||
#include "system.h"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* Plugin for testing how gracefully we degrade in the face of very
|
||||
large source files. */
|
||||
|
||||
#define INCLUDE_VECTOR
|
||||
#include "config.h"
|
||||
#include "gcc-plugin.h"
|
||||
#include "system.h"
|
||||
|
||||
@@ -19,6 +19,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with GCC; see the file COPYING3. If not see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#define INCLUDE_VECTOR
|
||||
#include "config.h"
|
||||
#include "system.h"
|
||||
#include "coretypes.h"
|
||||
|
||||
@@ -19,6 +19,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with GCC; see the file COPYING3. If not see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#define INCLUDE_VECTOR
|
||||
#include "config.h"
|
||||
#include "system.h"
|
||||
#include "coretypes.h"
|
||||
|
||||
@@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. If not see
|
||||
#undef PACKAGE_TARNAME
|
||||
#undef PACKAGE_VERSION
|
||||
|
||||
#define INCLUDE_VECTOR
|
||||
#include "gcc-plugin.h"
|
||||
#include "system.h"
|
||||
#include "coretypes.h"
|
||||
|
||||
Reference in New Issue
Block a user