From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id CA3D73882ACF for ; Tue, 18 Jun 2024 15:08:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CA3D73882ACF Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CA3D73882ACF Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718723310; cv=none; b=E0UePPSItASf5IvMAQRlaaLt6W21+yW3tXniAvRHnDXNZDjcqzi/MepBZ/ya8TE4aX+KUZVLipKQbFh+uehs8bWkeG92p8WHdOivIqrsg3Y882KPusbAn9QxejQTcsXSYnSY4Buj+NMyypPU5WDMx6PAzBUGncSwweIZ6sQvtqc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718723310; c=relaxed/simple; bh=oLbCV3rHXIwBNPHwEONj14N2oWiqNBIuGBZ+Y2yE8tU=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=ihZeSt7RLzbms2TTPJyHfP6GehVrhUF7xfP4twbgmDXIOfOQM5GNjSTWtSBlP67coSKVpPxnOIj+MqLjmr+prOEraEvJPXXTtQ5i1kvW0opXYSN8Mm9gkTe6ONPZEIfGLprGh8hl6TtyM0Gh1xGwddF/pxdpeOFeQBgG47VcRMI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718723306; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EBAi8yDQrI40MocMyN5YEVKOkLjw55DnfNdHjOim/8c=; b=Zw1mR84yz/G/rJ1YSi/3S/BaOtzSNn90jmET9HgbilVCpYkItVMdNvThyAFIoXTBy7XhAw L7DztPK86rtelUp/gPr6YvIkmGspvg2YZfz59h07EzRx4MC8JXDVG7X6gXJhCKzWuVclxb JPXtfOB23azp789Uy7rl2iyuPfxaLxI= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-64-8_w1GTgdO9ayPAVL8JwyLA-1; Tue, 18 Jun 2024 11:08:24 -0400 X-MC-Unique: 8_w1GTgdO9ayPAVL8JwyLA-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D64B71955F05 for ; Tue, 18 Jun 2024 15:08:23 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.10.107]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A0E2A1956048; Tue, 18 Jun 2024 15:08:22 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 1/7] diagnostics: move simple_diagnostic_{path,thread,event} to their own .h/cc Date: Tue, 18 Jun 2024 11:08:13 -0400 Message-Id: <20240618150819.946820-2-dmalcolm@redhat.com> In-Reply-To: <20240618150819.946820-1-dmalcolm@redhat.com> References: <20240618150819.946820-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: As work towards eliminating the dependency on "tree" from path-printing, move these classes to a new simple-diagnostic-path.h/cc. No functional change intended. gcc/analyzer/ChangeLog: * checker-path.h: Include "simple-diagnostic-path.h". gcc/ChangeLog: * Makefile.in (OBJS): Add simple-diagnostic-path.o. * diagnostic-path.h (class simple_diagnostic_event): Move to simple-diagnostic-path.h. (class simple_diagnostic_thread): Likewise. (class simple_diagnostic_path): Likewise. * diagnostic.cc (simple_diagnostic_path::simple_diagnostic_path): Move to simple-diagnostic-path.cc. (simple_diagnostic_path::num_events): Likewise. (simple_diagnostic_path::get_event): Likewise. (simple_diagnostic_path::num_threads): Likewise. (simple_diagnostic_path::get_thread): Likewise. (simple_diagnostic_path::add_thread): Likewise. (simple_diagnostic_path::add_event): Likewise. (simple_diagnostic_path::add_thread_event): Likewise. (simple_diagnostic_path::connect_to_next_event): Likewise. (simple_diagnostic_event::simple_diagnostic_event): Likewise. (simple_diagnostic_event::~simple_diagnostic_event): Likewise. * selftest-run-tests.cc (selftest::run_tests): Call selftest::simple_diagnostic_path_cc_tests. * selftest.h (selftest::simple_diagnostic_path_cc_tests): New decl. * simple-diagnostic-path.cc: New file, from the above material. * simple-diagnostic-path.h: New file, from the above material from diagnostic-path.h. * tree-diagnostic-path.cc: Include "simple-diagnostic-path.h". gcc/testsuite/ChangeLog * gcc.dg/plugin/diagnostic_plugin_test_paths.c: Include "simple-diagnostic-path.h". Signed-off-by: David Malcolm --- gcc/Makefile.in | 1 + gcc/analyzer/checker-path.h | 1 + gcc/diagnostic-path.h | 104 +------- gcc/diagnostic.cc | 149 ------------ gcc/selftest-run-tests.cc | 1 + gcc/selftest.h | 1 + gcc/simple-diagnostic-path.cc | 228 ++++++++++++++++++ gcc/simple-diagnostic-path.h | 130 ++++++++++ .../plugin/diagnostic_plugin_test_paths.c | 1 + gcc/tree-diagnostic-path.cc | 1 + 10 files changed, 366 insertions(+), 251 deletions(-) create mode 100644 gcc/simple-diagnostic-path.cc create mode 100644 gcc/simple-diagnostic-path.h diff --git a/gcc/Makefile.in b/gcc/Makefile.in index f5adb647d3f..35f259da858 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1700,6 +1700,7 @@ OBJS = \ ubsan.o \ sanopt.o \ sancov.o \ + simple-diagnostic-path.o \ tree-call-cdce.o \ tree-cfg.o \ tree-cfgcleanup.o \ diff --git a/gcc/analyzer/checker-path.h b/gcc/analyzer/checker-path.h index 6b3e8a34fe5..162ebb3f0d8 100644 --- a/gcc/analyzer/checker-path.h +++ b/gcc/analyzer/checker-path.h @@ -22,6 +22,7 @@ along with GCC; see the file COPYING3. If not see #define GCC_ANALYZER_CHECKER_PATH_H #include "analyzer/checker-event.h" +#include "simple-diagnostic-path.h" namespace ana { diff --git a/gcc/diagnostic-path.h b/gcc/diagnostic-path.h index 938bd583a3d..958eb725322 100644 --- a/gcc/diagnostic-path.h +++ b/gcc/diagnostic-path.h @@ -201,108 +201,8 @@ private: bool get_first_event_in_a_function (unsigned *out_idx) const; }; -/* Concrete subclasses. */ - -/* A simple implementation of diagnostic_event. */ - -class simple_diagnostic_event : public diagnostic_event -{ - public: - simple_diagnostic_event (location_t loc, tree fndecl, int depth, - const char *desc, - diagnostic_thread_id_t thread_id = 0); - ~simple_diagnostic_event (); - - location_t get_location () const final override { return m_loc; } - tree get_fndecl () const final override { return m_fndecl; } - int get_stack_depth () const final override { return m_depth; } - label_text get_desc (bool) const final override - { - return label_text::borrow (m_desc); - } - const logical_location *get_logical_location () const final override - { - return NULL; - } - meaning get_meaning () const final override - { - return meaning (); - } - bool connect_to_next_event_p () const final override - { - return m_connected_to_next_event; - } - diagnostic_thread_id_t get_thread_id () const final override - { - return m_thread_id; - } - - void connect_to_next_event () - { - m_connected_to_next_event = true; - } - - private: - location_t m_loc; - tree m_fndecl; - int m_depth; - char *m_desc; // has been i18n-ed and formatted - bool m_connected_to_next_event; - diagnostic_thread_id_t m_thread_id; -}; - -/* A simple implementation of diagnostic_thread. */ - -class simple_diagnostic_thread : public diagnostic_thread -{ -public: - simple_diagnostic_thread (const char *name) : m_name (name) {} - label_text get_name (bool) const final override - { - return label_text::borrow (m_name); - } - -private: - const char *m_name; // has been i18n-ed and formatted -}; - -/* A simple implementation of diagnostic_path, as a vector of - simple_diagnostic_event instances. */ - -class simple_diagnostic_path : public diagnostic_path -{ - public: - simple_diagnostic_path (pretty_printer *event_pp); - - unsigned num_events () const final override; - const diagnostic_event & get_event (int idx) const final override; - unsigned num_threads () const final override; - const diagnostic_thread & - get_thread (diagnostic_thread_id_t) const final override; - - diagnostic_thread_id_t add_thread (const char *name); - - diagnostic_event_id_t add_event (location_t loc, tree fndecl, int depth, - const char *fmt, ...) - ATTRIBUTE_GCC_DIAG(5,6); - diagnostic_event_id_t - add_thread_event (diagnostic_thread_id_t thread_id, - location_t loc, tree fndecl, int depth, - const char *fmt, ...) - ATTRIBUTE_GCC_DIAG(6,7); - - void connect_to_next_event (); - - void disable_event_localization () { m_localize_events = false; } - - private: - auto_delete_vec m_threads; - auto_delete_vec m_events; - - /* (for use by add_event). */ - pretty_printer *m_event_pp; - bool m_localize_events; -}; +/* Concrete subclasses of the above can be found in + simple-diagnostic-path.h. */ extern void debug (diagnostic_path *path); diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index 9d0cb8ea051..a7acde50ab8 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -2517,155 +2517,6 @@ set_text_art_charset (enum diagnostic_text_art_charset charset) } } -/* class simple_diagnostic_path : public diagnostic_path. */ - -simple_diagnostic_path::simple_diagnostic_path (pretty_printer *event_pp) -: m_event_pp (event_pp), - m_localize_events (true) -{ - add_thread ("main"); -} - -/* Implementation of diagnostic_path::num_events vfunc for - simple_diagnostic_path: simply get the number of events in the vec. */ - -unsigned -simple_diagnostic_path::num_events () const -{ - return m_events.length (); -} - -/* Implementation of diagnostic_path::get_event vfunc for - simple_diagnostic_path: simply return the event in the vec. */ - -const diagnostic_event & -simple_diagnostic_path::get_event (int idx) const -{ - return *m_events[idx]; -} - -unsigned -simple_diagnostic_path::num_threads () const -{ - return m_threads.length (); -} - -const diagnostic_thread & -simple_diagnostic_path::get_thread (diagnostic_thread_id_t idx) const -{ - return *m_threads[idx]; -} - -diagnostic_thread_id_t -simple_diagnostic_path::add_thread (const char *name) -{ - m_threads.safe_push (new simple_diagnostic_thread (name)); - return m_threads.length () - 1; -} - -/* Add an event to this path at LOC within function FNDECL at - stack depth DEPTH. - - Use m_context's printer to format FMT, as the text of the new - event. Localize FMT iff m_localize_events is set. - - Return the id of the new event. */ - -diagnostic_event_id_t -simple_diagnostic_path::add_event (location_t loc, tree fndecl, int depth, - const char *fmt, ...) -{ - pretty_printer *pp = m_event_pp; - pp_clear_output_area (pp); - - rich_location rich_loc (line_table, UNKNOWN_LOCATION); - - va_list ap; - - va_start (ap, fmt); - - text_info ti (m_localize_events ? _(fmt) : fmt, - &ap, 0, nullptr, &rich_loc); - pp_format (pp, &ti); - pp_output_formatted_text (pp); - - va_end (ap); - - simple_diagnostic_event *new_event - = new simple_diagnostic_event (loc, fndecl, depth, pp_formatted_text (pp)); - m_events.safe_push (new_event); - - pp_clear_output_area (pp); - - return diagnostic_event_id_t (m_events.length () - 1); -} - -diagnostic_event_id_t -simple_diagnostic_path::add_thread_event (diagnostic_thread_id_t thread_id, - location_t loc, - tree fndecl, - int depth, - const char *fmt, ...) -{ - pretty_printer *pp = m_event_pp; - pp_clear_output_area (pp); - - rich_location rich_loc (line_table, UNKNOWN_LOCATION); - - va_list ap; - - va_start (ap, fmt); - - text_info ti (_(fmt), &ap, 0, nullptr, &rich_loc); - - pp_format (pp, &ti); - pp_output_formatted_text (pp); - - va_end (ap); - - simple_diagnostic_event *new_event - = new simple_diagnostic_event (loc, fndecl, depth, pp_formatted_text (pp), - thread_id); - m_events.safe_push (new_event); - - pp_clear_output_area (pp); - - return diagnostic_event_id_t (m_events.length () - 1); -} - -/* Mark the most recent event on this path (which must exist) as being - connected to the next one to be added. */ - -void -simple_diagnostic_path::connect_to_next_event () -{ - gcc_assert (m_events.length () > 0); - m_events[m_events.length () - 1]->connect_to_next_event (); -} - -/* struct simple_diagnostic_event. */ - -/* simple_diagnostic_event's ctor. */ - -simple_diagnostic_event:: -simple_diagnostic_event (location_t loc, - tree fndecl, - int depth, - const char *desc, - diagnostic_thread_id_t thread_id) -: m_loc (loc), m_fndecl (fndecl), m_depth (depth), m_desc (xstrdup (desc)), - m_connected_to_next_event (false), - m_thread_id (thread_id) -{ -} - -/* simple_diagnostic_event's dtor. */ - -simple_diagnostic_event::~simple_diagnostic_event () -{ - free (m_desc); -} - /* Print PATH by emitting a dummy "note" associated with it. */ DEBUG_FUNCTION diff --git a/gcc/selftest-run-tests.cc b/gcc/selftest-run-tests.cc index d8f5e4b34c6..3275db38ba9 100644 --- a/gcc/selftest-run-tests.cc +++ b/gcc/selftest-run-tests.cc @@ -103,6 +103,7 @@ selftest::run_tests () spellcheck_tree_cc_tests (); tree_cfg_cc_tests (); tree_diagnostic_path_cc_tests (); + simple_diagnostic_path_cc_tests (); attribs_cc_tests (); /* This one relies on most of the above. */ diff --git a/gcc/selftest.h b/gcc/selftest.h index 9e294ad1e5f..2d1aa91607e 100644 --- a/gcc/selftest.h +++ b/gcc/selftest.h @@ -250,6 +250,7 @@ extern void read_rtl_function_cc_tests (); extern void rtl_tests_cc_tests (); extern void sbitmap_cc_tests (); extern void selftest_cc_tests (); +extern void simple_diagnostic_path_cc_tests (); extern void simplify_rtx_cc_tests (); extern void spellcheck_cc_tests (); extern void spellcheck_tree_cc_tests (); diff --git a/gcc/simple-diagnostic-path.cc b/gcc/simple-diagnostic-path.cc new file mode 100644 index 00000000000..3ec0e850985 --- /dev/null +++ b/gcc/simple-diagnostic-path.cc @@ -0,0 +1,228 @@ +/* Concrete classes for implementing diagnostic paths. + Copyright (C) 2019-2024 Free Software Foundation, Inc. + Contributed by David Malcolm + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + + +#include "config.h" +#define INCLUDE_MEMORY +#define INCLUDE_VECTOR +#include "system.h" +#include "coretypes.h" +#include "tree.h" +#include "version.h" +#include "demangle.h" +#include "intl.h" +#include "backtrace.h" +#include "diagnostic.h" +#include "simple-diagnostic-path.h" +#include "selftest.h" + +/* class simple_diagnostic_path : public diagnostic_path. */ + +simple_diagnostic_path::simple_diagnostic_path (pretty_printer *event_pp) +: m_event_pp (event_pp), + m_localize_events (true) +{ + add_thread ("main"); +} + +/* Implementation of diagnostic_path::num_events vfunc for + simple_diagnostic_path: simply get the number of events in the vec. */ + +unsigned +simple_diagnostic_path::num_events () const +{ + return m_events.length (); +} + +/* Implementation of diagnostic_path::get_event vfunc for + simple_diagnostic_path: simply return the event in the vec. */ + +const diagnostic_event & +simple_diagnostic_path::get_event (int idx) const +{ + return *m_events[idx]; +} + +unsigned +simple_diagnostic_path::num_threads () const +{ + return m_threads.length (); +} + +const diagnostic_thread & +simple_diagnostic_path::get_thread (diagnostic_thread_id_t idx) const +{ + return *m_threads[idx]; +} + +diagnostic_thread_id_t +simple_diagnostic_path::add_thread (const char *name) +{ + m_threads.safe_push (new simple_diagnostic_thread (name)); + return m_threads.length () - 1; +} + +/* Add an event to this path at LOC within function FNDECL at + stack depth DEPTH. + + Use m_context's printer to format FMT, as the text of the new + event. Localize FMT iff m_localize_events is set. + + Return the id of the new event. */ + +diagnostic_event_id_t +simple_diagnostic_path::add_event (location_t loc, tree fndecl, int depth, + const char *fmt, ...) +{ + pretty_printer *pp = m_event_pp; + pp_clear_output_area (pp); + + rich_location rich_loc (line_table, UNKNOWN_LOCATION); + + va_list ap; + + va_start (ap, fmt); + + text_info ti (m_localize_events ? _(fmt) : fmt, + &ap, 0, nullptr, &rich_loc); + pp_format (pp, &ti); + pp_output_formatted_text (pp); + + va_end (ap); + + simple_diagnostic_event *new_event + = new simple_diagnostic_event (loc, fndecl, depth, pp_formatted_text (pp)); + m_events.safe_push (new_event); + + pp_clear_output_area (pp); + + return diagnostic_event_id_t (m_events.length () - 1); +} + +diagnostic_event_id_t +simple_diagnostic_path::add_thread_event (diagnostic_thread_id_t thread_id, + location_t loc, + tree fndecl, + int depth, + const char *fmt, ...) +{ + pretty_printer *pp = m_event_pp; + pp_clear_output_area (pp); + + rich_location rich_loc (line_table, UNKNOWN_LOCATION); + + va_list ap; + + va_start (ap, fmt); + + text_info ti (_(fmt), &ap, 0, nullptr, &rich_loc); + + pp_format (pp, &ti); + pp_output_formatted_text (pp); + + va_end (ap); + + simple_diagnostic_event *new_event + = new simple_diagnostic_event (loc, fndecl, depth, pp_formatted_text (pp), + thread_id); + m_events.safe_push (new_event); + + pp_clear_output_area (pp); + + return diagnostic_event_id_t (m_events.length () - 1); +} + +/* Mark the most recent event on this path (which must exist) as being + connected to the next one to be added. */ + +void +simple_diagnostic_path::connect_to_next_event () +{ + gcc_assert (m_events.length () > 0); + m_events[m_events.length () - 1]->connect_to_next_event (); +} + +/* struct simple_diagnostic_event. */ + +/* simple_diagnostic_event's ctor. */ + +simple_diagnostic_event:: +simple_diagnostic_event (location_t loc, + tree fndecl, + int depth, + const char *desc, + diagnostic_thread_id_t thread_id) +: m_loc (loc), m_fndecl (fndecl), m_depth (depth), m_desc (xstrdup (desc)), + m_connected_to_next_event (false), + m_thread_id (thread_id) +{ +} + +/* simple_diagnostic_event's dtor. */ + +simple_diagnostic_event::~simple_diagnostic_event () +{ + free (m_desc); +} + +#if CHECKING_P + +namespace selftest { + +static void +test_intraprocedural_path (pretty_printer *event_pp) +{ + tree fntype_void_void + = build_function_type_array (void_type_node, 0, NULL); + tree fndecl_foo = build_fn_decl ("foo", fntype_void_void); + + simple_diagnostic_path path (event_pp); + path.add_event (UNKNOWN_LOCATION, fndecl_foo, 0, "first %qs", "free"); + path.add_event (UNKNOWN_LOCATION, fndecl_foo, 0, "double %qs", "free"); + + ASSERT_EQ (path.num_events (), 2); + ASSERT_EQ (path.num_threads (), 1); + ASSERT_FALSE (path.interprocedural_p ()); + ASSERT_STREQ (path.get_event (0).get_desc (false).get (), "first `free'"); + ASSERT_STREQ (path.get_event (1).get_desc (false).get (), "double `free'"); +} + +/* Run all of the selftests within this file. */ + +void +simple_diagnostic_path_cc_tests () +{ + /* In a few places we use the global dc's printer to determine + colorization so ensure this off during the tests. */ + const bool saved_show_color = pp_show_color (global_dc->printer); + pp_show_color (global_dc->printer) = false; + + auto_fix_quotes fix_quotes; + std::unique_ptr event_pp + = std::unique_ptr (global_dc->printer->clone ()); + + test_intraprocedural_path (event_pp.get ()); + + pp_show_color (global_dc->printer) = saved_show_color; +} + +} // namespace selftest + +#endif /* #if CHECKING_P */ diff --git a/gcc/simple-diagnostic-path.h b/gcc/simple-diagnostic-path.h new file mode 100644 index 00000000000..5fbed158f15 --- /dev/null +++ b/gcc/simple-diagnostic-path.h @@ -0,0 +1,130 @@ +/* Concrete classes for implementing diagnostic paths. + Copyright (C) 2019-2024 Free Software Foundation, Inc. + Contributed by David Malcolm + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#ifndef GCC_SIMPLE_DIAGNOSTIC_PATH_H +#define GCC_SIMPLE_DIAGNOSTIC_PATH_H + +#include "diagnostic-path.h" + +/* Concrete subclasses of the abstract base classes + declared in diagnostic-path.h. */ + +/* A simple implementation of diagnostic_event. */ + +class simple_diagnostic_event : public diagnostic_event +{ + public: + simple_diagnostic_event (location_t loc, tree fndecl, int depth, + const char *desc, + diagnostic_thread_id_t thread_id = 0); + ~simple_diagnostic_event (); + + location_t get_location () const final override { return m_loc; } + tree get_fndecl () const final override { return m_fndecl; } + int get_stack_depth () const final override { return m_depth; } + label_text get_desc (bool) const final override + { + return label_text::borrow (m_desc); + } + const logical_location *get_logical_location () const final override + { + return NULL; + } + meaning get_meaning () const final override + { + return meaning (); + } + bool connect_to_next_event_p () const final override + { + return m_connected_to_next_event; + } + diagnostic_thread_id_t get_thread_id () const final override + { + return m_thread_id; + } + + void connect_to_next_event () + { + m_connected_to_next_event = true; + } + + private: + location_t m_loc; + tree m_fndecl; + int m_depth; + char *m_desc; // has been i18n-ed and formatted + bool m_connected_to_next_event; + diagnostic_thread_id_t m_thread_id; +}; + +/* A simple implementation of diagnostic_thread. */ + +class simple_diagnostic_thread : public diagnostic_thread +{ +public: + simple_diagnostic_thread (const char *name) : m_name (name) {} + label_text get_name (bool) const final override + { + return label_text::borrow (m_name); + } + +private: + const char *m_name; // has been i18n-ed and formatted +}; + +/* A simple implementation of diagnostic_path, as a vector of + simple_diagnostic_event instances. */ + +class simple_diagnostic_path : public diagnostic_path +{ + public: + simple_diagnostic_path (pretty_printer *event_pp); + + unsigned num_events () const final override; + const diagnostic_event & get_event (int idx) const final override; + unsigned num_threads () const final override; + const diagnostic_thread & + get_thread (diagnostic_thread_id_t) const final override; + + diagnostic_thread_id_t add_thread (const char *name); + + diagnostic_event_id_t add_event (location_t loc, tree fndecl, int depth, + const char *fmt, ...) + ATTRIBUTE_GCC_DIAG(5,6); + diagnostic_event_id_t + add_thread_event (diagnostic_thread_id_t thread_id, + location_t loc, tree fndecl, int depth, + const char *fmt, ...) + ATTRIBUTE_GCC_DIAG(6,7); + + void connect_to_next_event (); + + void disable_event_localization () { m_localize_events = false; } + + private: + auto_delete_vec m_threads; + auto_delete_vec m_events; + + /* (for use by add_event). */ + pretty_printer *m_event_pp; + bool m_localize_events; +}; + +#endif /* ! GCC_SIMPLE_DIAGNOSTIC_PATH_H */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.c index bf665005c8b..efa4ec475ab 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.c @@ -38,6 +38,7 @@ #include "print-tree.h" #include "gcc-rich-location.h" #include "cgraph.h" +#include "simple-diagnostic-path.h" int plugin_is_GPL_compatible; diff --git a/gcc/tree-diagnostic-path.cc b/gcc/tree-diagnostic-path.cc index f82ef305c06..a9dd40cbd9d 100644 --- a/gcc/tree-diagnostic-path.cc +++ b/gcc/tree-diagnostic-path.cc @@ -33,6 +33,7 @@ along with GCC; see the file COPYING3. If not see #include "langhooks.h" #include "intl.h" #include "diagnostic-path.h" +#include "simple-diagnostic-path.h" #include "json.h" #include "gcc-rich-location.h" #include "diagnostic-color.h" -- 2.26.3