From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id CBE9C3814FD3 for ; Mon, 30 May 2022 08:33:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CBE9C3814FD3 Received: by mail-wm1-x334.google.com with SMTP id r9-20020a1c4409000000b00397345f2c6fso2363093wma.4 for ; Mon, 30 May 2022 01:33:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=fKGDzdffwqwKV7LmhoD/Fk4xEBSPKeHH9Gb5raTm8FI=; b=J8fUTMaC+glj0enZkV6sGM3cdxTgJooKIOtG8LbOhYS8Wf4/pvW1yuu9o7HcCVYG81 eNEworqxqbEGlvdDOeX3O70clxvxoVqkg+Z9bqKgfkvK9CbGWApbOTmFfopsD49lyR+J jUo8HnUE7dU5mSpIBFj4JKYARAeluq/upalKc4KpRwSY4R0OUbRH9MuULtfRZiu/4L51 7T+3fxdQgkXwkvJXQOHAblVTV/UF5VmCJZSOAylwx2ENe1IVUW6mwn8svCPiEuS8nerb EVMz0fflUCAuWGv5i7+BRwYVC0/KVa/f9j7C2btna1Ox+uj0IT99PqACnF52NUUNPmVy BObg== X-Gm-Message-State: AOAM531tphQPREHYDvU0e5swIKKNCQc9IdwExuCwKWAWHVU3DBiAKP0P WhE9tqppEelyLcELcLDn3eCLk4fmqUNURQ== X-Google-Smtp-Source: ABdhPJzBpMETZyglPFzwtqSagHJQmhpIMkJ4gck/hGTdalZzdUx+Y01E2/LMEmlHSPXfwY/XsUm+2A== X-Received: by 2002:a05:600c:4311:b0:397:4c1f:9f54 with SMTP id p17-20020a05600c431100b003974c1f9f54mr17948966wme.32.1653899582700; Mon, 30 May 2022 01:33:02 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id h20-20020a05600c415400b003958af7d0c8sm9865498wmm.45.2022.05.30.01.33.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 May 2022 01:33:02 -0700 (PDT) Date: Mon, 30 May 2022 08:33:01 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Ghjuvan Lacambre Subject: [Ada] Add "option" field to GNAT's -fdiagnostics-format=json output Message-ID: <20220530083301.GA211091@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="qDbXVdCdHGoSgWSk" Content-Disposition: inline X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, WEIRD_QUOTING 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 May 2022 08:33:05 -0000 --qDbXVdCdHGoSgWSk Content-Type: text/plain; charset=us-ascii Content-Disposition: inline This enables better integration with tools that handle GNAT's output. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * erroutc.ads (Get_Warning_Option): New function returning the option responsible for a warning if it exists. * erroutc.adb (Get_Warning_Option): Likewise. (Get_Warning_Tag): Rely on Get_Warning_Option when possible. * errout.adb (Output_JSON_Message): Emit option field. --qDbXVdCdHGoSgWSk Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb --- a/gcc/ada/errout.adb +++ b/gcc/ada/errout.adb @@ -2170,6 +2170,9 @@ package body Errout is -- Do not print continuations messages as children of the current -- message if the current message is a continuation message. + Option : constant String := Get_Warning_Option (E); + -- The option that triggered this message. + -- Start of processing for Output_JSON_Message begin @@ -2197,9 +2200,16 @@ package body Errout is Write_Str ("}"); end if; + Write_Str ("]"); + + -- Print message option, if there is one + if Option /= "" then + Write_Str (",""option"":""" & Option & """"); + end if; + -- Print message content - Write_Str ("],""message"":"""); + Write_Str (",""message"":"""); Write_JSON_Escaped_String (Errors.Table (E).Text); Write_Str (""""); diff --git a/gcc/ada/erroutc.adb b/gcc/ada/erroutc.adb --- a/gcc/ada/erroutc.adb +++ b/gcc/ada/erroutc.adb @@ -359,6 +359,26 @@ package body Erroutc is return Cur_Msg; end Get_Msg_Id; + ------------------------ + -- Get_Warning_Option -- + ------------------------ + + function Get_Warning_Option (Id : Error_Msg_Id) return String is + Warn : constant Boolean := Errors.Table (Id).Warn; + Warn_Chr : constant String (1 .. 2) := Errors.Table (Id).Warn_Chr; + begin + if Warn and then Warn_Chr /= " " then + if Warn_Chr = "$ " then + return "-gnatel"; + elsif Warn_Chr (2) = ' ' then + return "-gnatw" & Warn_Chr (1); + else + return "-gnatw" & Warn_Chr; + end if; + end if; + return ""; + end Get_Warning_Option; + --------------------- -- Get_Warning_Tag -- --------------------- @@ -366,22 +386,19 @@ package body Erroutc is function Get_Warning_Tag (Id : Error_Msg_Id) return String is Warn : constant Boolean := Errors.Table (Id).Warn; Warn_Chr : constant String (1 .. 2) := Errors.Table (Id).Warn_Chr; + Option : constant String := Get_Warning_Option (Id); begin - if Warn and then Warn_Chr /= " " then + if Warn then if Warn_Chr = "? " then return "[enabled by default]"; elsif Warn_Chr = "* " then return "[restriction warning]"; - elsif Warn_Chr = "$ " then - return "[-gnatel]"; - elsif Warn_Chr (2) = ' ' then - return "[-gnatw" & Warn_Chr (1) & ']'; - else - return "[-gnatw" & Warn_Chr & ']'; + elsif Option /= "" then + return "[" & Option & "]"; end if; - else - return ""; end if; + + return ""; end Get_Warning_Tag; ------------- diff --git a/gcc/ada/erroutc.ads b/gcc/ada/erroutc.ads --- a/gcc/ada/erroutc.ads +++ b/gcc/ada/erroutc.ads @@ -493,6 +493,10 @@ package Erroutc is -- Returns the number of warnings in the Errors table that were triggered -- by a Compile_Time_Warning pragma. + function Get_Warning_Option (Id : Error_Msg_Id) return String; + -- Returns the warning switch causing this warning message or an empty + -- string is there is none.. + function Get_Warning_Tag (Id : Error_Msg_Id) return String; -- Given an error message ID, return tag showing warning message class, or -- the null string if this option is not enabled or this is not a warning. --qDbXVdCdHGoSgWSk--