From patchwork Tue Jun 18 15:08:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1949227 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MoFdxiv7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W3VXB0cWGz20XR for ; Wed, 19 Jun 2024 01:09:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4EBE6388302E for ; Tue, 18 Jun 2024 15:09:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 24D453882AF3 for ; Tue, 18 Jun 2024 15:08:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 24D453882AF3 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 24D453882AF3 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=1718723314; cv=none; b=eat2I4cHRTp2xGg5+9V+C+6zt53P6PTmmw5zNjG9J0CarQokC0UlY+4/4t+YIixCfhcBjalx4GbgioWNgKFmFnUR3i/awB8MVKPV89lcdfRoAn5DDTEXYhrQR8sVQK5PYiIXxgj2krFWSe5J/5sNL+R3yeEv6yi4N2aqFpc0cVg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718723314; c=relaxed/simple; bh=mxfmMlXXmkixZLLsQO/rhh9s8QuSLufudCGcLz2stqE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=MAYL3KBBgI5bFtk9DN6ReSCukVAopsQ37pTj3u69UhIoFGiwelI15J+EiI0yCoJKsjI9fjPmeQgYQqLSaZfK+ziTYWDoHh1jIBaMYkbw63At5nWq3QoBxi71vbae8qSnJJHuhlYolAQLXqcrqXsuU6pmVDYm9vDdn91pDTeQc9k= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718723309; 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=yRt5O9nZHMKZobvDhvfSjJZKoJ5Oe+2Vjj+sQi7JYy8=; b=MoFdxiv7WIag5osE2g8mVlbehndKxnV7uNsPMsuPzTThLe76i/Hf1A/yWxwfDPEv4JTh19 80Scu8043jps7u9LqaiHQnI+yZ4fw3xmmAZMuP8izeajdSXMGrPwPBPkd0fibhwLf5iKjd 8zpsWQV/hwicnGpPkGL9LwCm6yqTUTI= Received: from mx-prod-mc-03.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-508-4TfVvqP6MnerNAT9aZCS1w-1; Tue, 18 Jun 2024 11:08:28 -0400 X-MC-Unique: 4TfVvqP6MnerNAT9aZCS1w-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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5AAB8195605F for ; Tue, 18 Jun 2024 15:08:27 +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 A7C771956052; Tue, 18 Jun 2024 15:08:26 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 4/7] diagnostics: eliminate diagnostic_context::m_make_json_for_path Date: Tue, 18 Jun 2024 11:08:16 -0400 Message-Id: <20240618150819.946820-5-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 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, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Now that the path-handling code for json_output_format no longer needs "tree", and thus can be in OBJS-libcommon we can move it from tree-diagnostic-path.cc to diagnostic-format-json.cc where it should have been all along. No functional change intended. gcc/ChangeLog: * diagnostic-format-json.cc: Include "diagnostic-path.h" and "logical-location.h". (make_json_for_path): Move tree-diagnostic-path.cc's default_tree_make_json_for_path here, renaming it and making it static. (json_output_format::on_end_diagnostic): Replace call of m_context's m_make_json_for_path callback with a direct call to make_json_for_path. * diagnostic.h (diagnostic_context::m_make_json_for_path): Drop field. * tree-diagnostic-path.cc: Drop include of "json.h". (default_tree_make_json_for_path): Rename to make_json_for_path and move to diagnostic-format-json.cc. * tree-diagnostic.cc (tree_diagnostics_defaults): Drop initialization of m_make_json_for_path. * tree-diagnostic.h (default_tree_make_json_for): Delete decl. Signed-off-by: David Malcolm --- gcc/diagnostic-format-json.cc | 37 ++++++++++++++++++++++++++++++++--- gcc/diagnostic.h | 2 -- gcc/tree-diagnostic-path.cc | 32 ------------------------------ gcc/tree-diagnostic.cc | 1 - gcc/tree-diagnostic.h | 2 -- 5 files changed, 34 insertions(+), 40 deletions(-) diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc index 0782ae831eb..2bdc2c13d37 100644 --- a/gcc/diagnostic-format-json.cc +++ b/gcc/diagnostic-format-json.cc @@ -25,8 +25,10 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic.h" #include "selftest-diagnostic.h" #include "diagnostic-metadata.h" +#include "diagnostic-path.h" #include "json.h" #include "selftest.h" +#include "logical-location.h" /* Subclass of diagnostic_output_format for JSON output. */ @@ -187,6 +189,36 @@ json_from_metadata (const diagnostic_metadata *metadata) return metadata_obj; } +/* Make a JSON value for PATH. */ + +static json::value * +make_json_for_path (diagnostic_context *context, + const diagnostic_path *path) +{ + json::array *path_array = new json::array (); + for (unsigned i = 0; i < path->num_events (); i++) + { + const diagnostic_event &event = path->get_event (i); + + json::object *event_obj = new json::object (); + if (event.get_location ()) + event_obj->set ("location", + json_from_expanded_location (context, + event.get_location ())); + label_text event_text (event.get_desc (false)); + event_obj->set_string ("description", event_text.get ()); + if (const logical_location *logical_loc = event.get_logical_location ()) + { + label_text name (logical_loc->get_name_for_path_output ()); + event_obj->set_string ("function", name.get ()); + } + event_obj->set_integer ("depth", event.get_stack_depth ()); + path_array->append (event_obj); + } + return path_array; +} + + /* Implementation of "on_end_diagnostic" vfunc for JSON output. Generate a JSON object for DIAGNOSTIC, and store for output within current diagnostic group. */ @@ -291,10 +323,9 @@ json_output_format::on_end_diagnostic (const diagnostic_info &diagnostic, } const diagnostic_path *path = richloc->get_path (); - if (path && m_context.m_make_json_for_path) + if (path) { - json::value *path_value - = m_context.m_make_json_for_path (&m_context, path); + json::value *path_value = make_json_for_path (&m_context, path); diag_obj->set ("path", path_value); } diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index 9a9571bb76d..ff2aa3dd9a3 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -713,8 +713,6 @@ private: public: void (*m_print_path) (diagnostic_context *, const diagnostic_path *); - json::value *(*m_make_json_for_path) (diagnostic_context *, - const diagnostic_path *); /* Auxiliary data for client. */ void *m_client_aux_data; diff --git a/gcc/tree-diagnostic-path.cc b/gcc/tree-diagnostic-path.cc index 39a85d33015..40b197d971c 100644 --- a/gcc/tree-diagnostic-path.cc +++ b/gcc/tree-diagnostic-path.cc @@ -30,7 +30,6 @@ along with GCC; see the file COPYING3. If not see #include "tree-diagnostic.h" #include "intl.h" #include "diagnostic-path.h" -#include "json.h" #include "gcc-rich-location.h" #include "diagnostic-color.h" #include "diagnostic-event-id.h" @@ -954,37 +953,6 @@ default_tree_diagnostic_path_printer (diagnostic_context *context, } } -/* This has to be here, rather than diagnostic-format-json.cc, - since diagnostic-format-json.o is within OBJS-libcommon and thus - doesn't have access to trees (for m_fndecl). */ - -json::value * -default_tree_make_json_for_path (diagnostic_context *context, - const diagnostic_path *path) -{ - json::array *path_array = new json::array (); - for (unsigned i = 0; i < path->num_events (); i++) - { - const diagnostic_event &event = path->get_event (i); - - json::object *event_obj = new json::object (); - if (event.get_location ()) - event_obj->set ("location", - json_from_expanded_location (context, - event.get_location ())); - label_text event_text (event.get_desc (false)); - event_obj->set_string ("description", event_text.get ()); - if (const logical_location *logical_loc = event.get_logical_location ()) - { - label_text name (logical_loc->get_name_for_path_output ()); - event_obj->set_string ("function", name.get ()); - } - event_obj->set_integer ("depth", event.get_stack_depth ()); - path_array->append (event_obj); - } - return path_array; -} - #if CHECKING_P namespace selftest { diff --git a/gcc/tree-diagnostic.cc b/gcc/tree-diagnostic.cc index a660c7d0785..f6e2a73497a 100644 --- a/gcc/tree-diagnostic.cc +++ b/gcc/tree-diagnostic.cc @@ -375,7 +375,6 @@ tree_diagnostics_defaults (diagnostic_context *context) diagnostic_finalizer (context) = default_diagnostic_finalizer; diagnostic_format_decoder (context) = default_tree_printer; context->m_print_path = default_tree_diagnostic_path_printer; - context->m_make_json_for_path = default_tree_make_json_for_path; context->set_set_locations_callback (set_inlining_locations); context->set_client_data_hooks (make_compiler_data_hooks ()); } diff --git a/gcc/tree-diagnostic.h b/gcc/tree-diagnostic.h index 1d13368537a..7959294f489 100644 --- a/gcc/tree-diagnostic.h +++ b/gcc/tree-diagnostic.h @@ -59,8 +59,6 @@ bool default_tree_printer (pretty_printer *, text_info *, const char *, extern void default_tree_diagnostic_path_printer (diagnostic_context *, const diagnostic_path *); -extern json::value *default_tree_make_json_for_path (diagnostic_context *, - const diagnostic_path *); extern void maybe_unwind_expanded_macro_loc (diagnostic_context *context, location_t where);