-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdiagnostics.adb
340 lines (290 loc) · 9.79 KB
/
diagnostics.adb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
------------------------------------------------------------------------------
-- --
-- GNATcoverage --
-- --
-- Copyright (C) 2009-2024, AdaCore --
-- --
-- GNATcoverage is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the Free --
-- Software Foundation; either version 3, or (at your option) any later --
-- version. This software is distributed in the hope that it will be useful --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
-- TABILITY 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 distributed with this software; see file --
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy --
-- of the license. --
------------------------------------------------------------------------------
with Ada.Characters.Handling; use Ada.Characters.Handling;
with Ada.Directories;
with Ada.Text_IO; use Ada.Text_IO;
with Command_Line; use Command_Line;
with Coverage.Tags; use Coverage.Tags;
with Files_Table; use Files_Table;
with Hex_Images; use Hex_Images;
with Outputs;
with Switches; use Switches;
package body Diagnostics is
function Suppress_Message (M : Message) return Boolean;
-- Return whether the given message must be removed from reports
procedure Output_Message (M : Message);
-- Display M
procedure Store_Message (M : Message);
-- Attach M to the relevant Line_Info structure, if any
-----------
-- Image --
-----------
function Image (M : Message) return String is
subtype Prefix_Str is String (1 .. 3);
Prefix : constant array (Report_Kind) of Prefix_Str :=
(Notice => "---",
Low_Warning => "***",
Warning => "***",
Error => "!!!",
Info => ".C.",
Violation => "!C!",
Undetermined_Cov => "?C?",
Exclusion => "-C-");
function Kind_Image return String;
-- Text prefix for Kind, empty for the value Error
function PC_Image return String;
-- Image of PC, null string for the value 0
function SCO_Image return String;
-- Image of SCO, null string for the value No_SCO_Id
function Sloc_Image return String;
-- Image of Sloc, null string for the value No_Location
function Tag_Image return String;
-- Tag indication, null string for the value No_SC_Tag
----------------
-- Kind_Image --
----------------
function Kind_Image return String is
begin
if M.Kind = Error then
return "";
else
return To_Lower (M.Kind'Img) & ": ";
end if;
end Kind_Image;
--------------
-- PC_Image --
--------------
function PC_Image return String is
use type Pc_Type;
begin
if M.PC /= 0 then
return Ada.Directories.Simple_Name (M.Exe.Get_Filename)
& "@" & Hex_Image (M.PC);
else
return "";
end if;
end PC_Image;
----------------
-- Sloc_Image --
----------------
function Sloc_Image return String is
begin
if M.Sloc /= No_Location then
-- Diagnostics can be emitted before the file table is complete,
-- so we cannot rely on unique filenames, here.
return " " & Image (M.Violation_Sloc, Unique_Name => False) & ":";
else
return "";
end if;
end Sloc_Image;
---------------
-- SCO_Image --
---------------
function SCO_Image return String is
begin
if M.SCO /= No_SCO_Id then
return Image (M.SCO, With_Sloc => First_Sloc (M.SCO) /= M.Sloc)
& ": ";
else
return "";
end if;
end SCO_Image;
---------------
-- Tag_Image --
---------------
function Tag_Image return String is
begin
if M.Tag /= No_SC_Tag then
return " (from " & Tag_Provider.Tag_Name (M.Tag) & ")";
else
return "";
end if;
end Tag_Image;
Msg : constant String := +M.Msg;
First : Natural := Msg'First;
-- Start of processing for Image
begin
if Msg (First) = '^' then
First := First + 1;
end if;
return
Prefix (M.Kind) &
PC_Image &
Sloc_Image &
" " &
Kind_Image &
SCO_Image & Msg (First .. Msg'Last) & Tag_Image;
end Image;
------------
-- Report --
------------
procedure Report
(Exe : Exe_File_Acc;
PC : Pc_Type;
Msg : String;
SCO : SCO_Id := No_SCO_Id;
Kind : Report_Kind := Error)
is
Subprg : constant Address_Info_Acc :=
Get_Address_Info (Exe.all, Subprogram_Addresses, PC);
Sloc : constant Source_Location :=
(if Subprg = null
then No_Location
else Get_Sloc (Subprg.Lines, PC));
begin
Report
(Msg,
Exe => Exe,
PC => PC,
Sloc => Sloc,
SCO => SCO,
Kind => Kind);
end Report;
procedure Report
(Sloc : Source_Location;
Msg : String;
Kind : Report_Kind := Error)
is
begin
Report (Msg, Sloc => Sloc, Kind => Kind);
end Report;
procedure Report
(Msg : String;
Exe : Exe_File_Acc := null;
PC : Pc_Type := No_PC;
Sloc : Source_Location := No_Location;
Violation_Sloc : Source_Location := No_Location;
SCO : SCO_Id := No_SCO_Id;
Tag : SC_Tag := No_SC_Tag;
Kind : Report_Kind := Error)
is
M : constant Message :=
(Kind => Kind,
Exe => Exe,
PC => PC,
Sloc => Sloc,
Violation_Sloc => (if Sloc /= No_Location
then Sloc
else Violation_Sloc),
SCO => SCO,
Tag => Tag,
Msg => +Msg);
begin
Output_Message (M);
Store_Message (M);
end Report;
---------------------
-- Report_Coverage --
---------------------
procedure Report_Coverage
(SCO : SCO_Id;
Tag : SC_Tag;
Msg : String;
Kind : Coverage_Kind)
is
Sloc : Source_Location;
-- Sloc of the message
Violation_Sloc : Source_Location;
-- Sloc of the violation the message expresses
begin
-- For an MC/DC violation, the message is attached to the decision for
-- the benefit of HTML output.
if SC_Obligations.Kind (SCO) = Condition then
Sloc := Last_Sloc (Enclosing_Decision (SCO));
Violation_Sloc := First_Sloc (Enclosing_Decision (SCO));
else
Sloc := Last_Sloc (SCO);
Violation_Sloc := First_Sloc (SCO);
end if;
Report (Msg,
Sloc => Sloc,
Violation_Sloc => Violation_Sloc,
SCO => SCO,
Tag => Tag,
Kind => Kind);
end Report_Coverage;
----------------------
-- Report_Exclusion --
----------------------
procedure Report_Exclusion
(SCO : SCO_Id;
Tag : SC_Tag;
Msg : String)
is
begin
Report_Coverage (SCO, Tag, Msg, Kind => Exclusion);
end Report_Exclusion;
----------------------
-- Report_Violation --
----------------------
procedure Report_Violation
(SCO : SCO_Id;
Tag : SC_Tag;
Msg : String)
is
begin
Report_Coverage (SCO, Tag, Msg, Kind => Violation);
end Report_Violation;
--------------------
-- Output_Message --
--------------------
procedure Output_Message (M : Message) is
begin
-- In Verbose mode, output all messages, else output only non-violation
-- messages of level higher than Notice. Note that violations are
-- always reported in the annotated sources or report output, so it's
-- fine to omit them here.
if Diagnostics_Trace.Is_Active
or else (M.Kind < Violation and then not Suppress_Message (M))
then
if M.Kind in Warning then
Outputs.Register_Warning;
end if;
Put_Line (Image (M));
end if;
end Output_Message;
-------------------
-- Store_Message --
-------------------
procedure Store_Message (M : Message) is
procedure Append_Message is new Append_To_Array
(Natural, Message,
Message_Array, Message_Array_Acc);
begin
if not Suppress_Message (M) then
declare
LI : constant Line_Info_Access := Get_Line (M.Sloc);
begin
if LI /= null then
Append_Message (LI.Messages, M);
end if;
end;
end if;
end Store_Message;
----------------------
-- Suppress_Message --
----------------------
function Suppress_Message (M : Message) return Boolean is
begin
if Args.Bool_Args (Opt_All_Warnings) then
return M.Kind <= Notice;
else
return M.Kind <= Low_Warning;
end if;
end Suppress_Message;
end Diagnostics;