| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- D I A G N O S T I C S . B R I E F _ E M I T T E R -- |
| 6 |
-- -- |
| 7 |
-- B o d y -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 1992-2025, Free Software Foundation, Inc. -- |
| 10 |
-- -- |
| 11 |
-- GNAT is free software; you can redistribute it and/or modify it under -- |
| 12 |
-- terms of the GNU General Public License as published by the Free Soft- -- |
| 13 |
-- ware Foundation; either version 3, or (at your option) any later ver- -- |
| 14 |
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
| 15 |
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- |
| 16 |
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- |
| 17 |
-- for more details. You should have received a copy of the GNU General -- |
| 18 |
-- Public License distributed with GNAT; see file COPYING3. If not, go to -- |
| 19 |
-- http://www.gnu.org/licenses for a complete copy of the license. -- |
| 20 |
-- -- |
| 21 |
-- GNAT was originally developed by the GNAT team at New York University. -- |
| 22 |
-- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| 23 |
-- -- |
| 24 |
------------------------------------------------------------------------------ |
| 25 |
|
| 26 |
with Diagnostics.Utils; use Diagnostics.Utils; |
| 27 |
with Erroutc; use Erroutc; |
| 28 |
with Opt; use Opt; |
| 29 |
with Output; use Output; |
| 30 |
|
| 31 |
package body Diagnostics.Brief_Emitter is |
| 32 |
|
| 33 |
procedure Print_Sub_Diagnostic |
| 34 |
(Sub_Diag : Sub_Diagnostic_Type; |
| 35 |
Diag : Diagnostic_Type); |
| 36 |
|
| 37 |
-------------------------- |
| 38 |
-- Print_Sub_Diagnostic -- |
| 39 |
-------------------------- |
| 40 |
|
| 41 |
procedure Print_Sub_Diagnostic |
| 42 |
(Sub_Diag : Sub_Diagnostic_Type; |
| 43 |
Diag : Diagnostic_Type) |
| 44 |
is |
| 45 |
-- In GNAT sub messages were grouped by the main messages by also having |
| 46 |
-- the same location. In the brief printer we use the primary location |
| 47 |
-- of the main diagnostic for all of the subdiagnostics. |
| 48 |
Prim_Loc : constant Labeled_Span_Type := Primary_Location (Diag); |
| 49 |
|
| 50 |
Sptr : constant Source_Ptr := Prim_Loc.Span.Ptr; |
| 51 |
|
| 52 |
Text : String_Ptr; |
| 53 |
|
| 54 |
Line_Length : constant Nat := (if Error_Msg_Line_Length = 0 then Nat'Last |
| 55 |
else Error_Msg_Line_Length); |
| 56 |
|
| 57 |
Switch_Str : constant String := Get_Doc_Switch (Diag); |
| 58 |
begin |
| 59 |
Text := new String'(To_String (Sptr) & ": " |
| 60 |
& Kind_To_String (Sub_Diag, Diag) & ": " |
| 61 |
& Sub_Diag.Message.all); |
| 62 |
|
| 63 |
if Switch_Str /= "" then |
| 64 |
Text := new String'(Text.all & " " & Switch_Str); |
| 65 |
end if; |
| 66 |
|
| 67 |
if Diag.Warn_Err then |
| 68 |
Text := new String'(Text.all & " [warning-as-error]"); |
| 69 |
end if; |
| 70 |
|
| 71 |
Output_Text_Within (Text, Line_Length); |
| 72 |
Write_Eol; |
| 73 |
end Print_Sub_Diagnostic; |
| 74 |
|
| 75 |
---------------------- |
| 76 |
-- Print_Diagnostic -- |
| 77 |
---------------------- |
| 78 |
|
| 79 |
procedure Print_Diagnostic (Diag : Diagnostic_Type) is |
| 80 |
use Sub_Diagnostic_Lists; |
| 81 |
|
| 82 |
Prim_Loc : constant Labeled_Span_Type := Primary_Location (Diag); |
| 83 |
|
| 84 |
Sptr : constant Source_Ptr := Prim_Loc.Span.Ptr; |
| 85 |
|
| 86 |
Text : String_Ptr; |
| 87 |
|
| 88 |
Line_Length : constant Nat := (if Error_Msg_Line_Length = 0 then Nat'Last |
| 89 |
else Error_Msg_Line_Length); |
| 90 |
|
| 91 |
Switch_Str : constant String := Get_Doc_Switch (Diag); |
| 92 |
begin |
| 93 |
Write_Str (To_String (Sptr) & ": "); |
| 94 |
|
| 95 |
-- Ignore the message prefix on Style messages. They will use |
| 96 |
-- the (style) prefix within the message. |
| 97 |
-- |
| 98 |
-- Also disable the "error:" prefix if Unique_Error_Tag is unset. |
| 99 |
|
| 100 |
if (Diag.Kind = Style and then not Diag.Warn_Err) |
| 101 |
or else (Diag.Kind = Error and then not Unique_Error_Tag) |
| 102 |
then |
| 103 |
Text := new String'(""); |
| 104 |
else |
| 105 |
Text := new String'(Kind_To_String (Diag) & ": "); |
| 106 |
end if; |
| 107 |
|
| 108 |
Text := new String'(Text.all & Diag.Message.all); |
| 109 |
|
| 110 |
if Switch_Str /= "" then |
| 111 |
Text := new String'(Text.all & " " & Switch_Str); |
| 112 |
end if; |
| 113 |
|
| 114 |
if Diag.Warn_Err then |
| 115 |
Text := new String'(Text.all & " [warning-as-error]"); |
| 116 |
end if; |
| 117 |
|
| 118 |
Output_Text_Within (Text, Line_Length); |
| 119 |
Write_Eol; |
| 120 |
|
| 121 |
if Present (Diag.Sub_Diagnostics) then |
| 122 |
declare |
| 123 |
|
| 124 |
Sub_Diag : Sub_Diagnostic_Type; |
| 125 |
|
| 126 |
It : Iterator := Iterate (Diag.Sub_Diagnostics); |
| 127 |
begin |
| 128 |
while Has_Next (It) loop |
| 129 |
Next (It, Sub_Diag); |
| 130 |
|
| 131 |
Print_Sub_Diagnostic (Sub_Diag, Diag); |
| 132 |
end loop; |
| 133 |
end; |
| 134 |
end if; |
| 135 |
|
| 136 |
end Print_Diagnostic; |
| 137 |
end Diagnostics.Brief_Emitter; |