forked from AdaCore/gnatcoverage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
annotations-report.adb
883 lines (705 loc) · 27.2 KB
/
annotations-report.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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
------------------------------------------------------------------------------
-- --
-- GNATcoverage --
-- --
-- Copyright (C) 2008-2021, 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.Calendar.Formatting;
with Ada.Characters.Handling; use Ada.Characters.Handling;
with Ada.Containers.Vectors;
with Ada.Strings.Unbounded;
with Ada.Text_IO; use Ada.Text_IO;
with ALI_Files;
with Coverage; use Coverage;
with Coverage.Source; use Coverage.Source;
with Coverage.Tags; use Coverage.Tags;
with Files_Table;
with Switches;
with Traces_Files; use Traces_Files;
with Strings; use Strings;
package body Annotations.Report is
type Final_Report_Type is limited record
-- Final report information
Name : String_Access := null;
-- Final report's file name
File : aliased File_Type;
-- Handle to the final report
end record;
Final_Report : aliased Final_Report_Type;
procedure Open_Report_File (Final_Report_Name : String);
-- Open Final_Report_Name and use it as the report file
function Get_Output return File_Access;
-- Return a handle to the current report file
procedure Close_Report_File;
-- Close the handle to the final report
-- Pretty printer type for the final report
type Report_Section is
range Coverage_Level'Pos (Coverage_Level'First)
.. Coverage_Level'Pos (Coverage_Level'Last) + 2;
-- There is one report section for each coverage level, plus the following
-- two special sections:
subtype Coverage_Violations is Report_Section
range Coverage_Level'Pos (Coverage_Level'First)
.. Coverage_Level'Pos (Coverage_Level'Last);
Coverage_Exclusions : constant Report_Section := Report_Section'Last - 1;
Other_Errors : constant Report_Section := Report_Section'Last;
function Section_Of_SCO (SCO : SCO_Id) return Report_Section;
function Section_Of_Message (M : Message) return Report_Section;
-- Indicate the coverage criterion a given SCO/message pertains to (by its
-- 'Pos), or Other_Errors if SCO has no related section/M is not a
-- violation message.
function Underline (S : String; C : Character := '-') return String;
-- Return, as a string with line-feeds, S underlined with a sequence
-- of C, for example
--
-- input-string-in-S
-- -----------------
function Frame (S : String; C : Character := '=') return String;
-- Similar to Underline, but framing S as in
--
-- =======================
-- == input string in S ==
-- =======================
function Highlight (S : String; C : Character := '*') return String;
-- Return S with a couple of C on both sides, as in
--
-- ** input string in S **
type Messages_Array is array (Report_Section) of Message_Vectors.Vector;
type SCO_Tally is record
Total : Natural := 0;
Covered : Natural := 0;
end record;
type SCO_Tallies_Array is array (Coverage_Level) of SCO_Tally;
package String_Vectors is
new Ada.Containers.Vectors
(Natural,
Ada.Strings.Unbounded.Unbounded_String,
Ada.Strings.Unbounded."=");
type Report_Pretty_Printer is new Pretty_Printer with record
Current_File_Index : Source_File_Index;
-- When going through the lines of a source file, this is set to the
-- current source file index.
Current_Chapter : Natural := 0;
-- Current chapter in final report
Current_Section : Natural := 0;
-- Current section in final report
Exempted_Messages : Message_Vectors.Vector;
-- Messages that have been covered by an exemption
Exemption : Slocs.Source_Location := Slocs.No_Location;
-- Exemption sloc applying to current line, if any
Nonexempted_Messages : Messages_Array;
-- All output messages, classified by section according to relevant
-- coverage level.
SCO_Tallies : SCO_Tallies_Array;
-- Tally of SCOs for each report section
Summary : String_Vectors.Vector;
-- Lines for SUMMARY chapter
Dump_Units : Boolean;
-- Whether to add a section for the list of names for units of interest
end record;
procedure Chapter
(Pp : in out Report_Pretty_Printer'Class;
Title : String);
-- Open a new chapter in final report
procedure Section
(Pp : in out Report_Pretty_Printer'Class;
Title : String);
-- Open a new section in final report
function Pluralize (Count : Natural; Item : String) return String;
-- Return:
-- "No <item>" (if Count = 0)
-- "1 <item>" (if Count = 1)
-- "<Count> <item>s" (if Count > 1)
--------------------------------------------------
-- Report_Pretty_Printer's primitive operations --
-- (inherited from Pretty_Printer) --
--------------------------------------------------
procedure Pretty_Print_Start (Pp : in out Report_Pretty_Printer);
procedure Pretty_Print_End (Pp : in out Report_Pretty_Printer);
procedure Pretty_Print_Start_File
(Pp : in out Report_Pretty_Printer;
File : Source_File_Index;
Skip : out Boolean);
procedure Pretty_Print_Start_Line
(Pp : in out Report_Pretty_Printer;
Line_Num : Natural;
Info : Line_Info_Access;
Line : String);
procedure Pretty_Print_End_File
(Pp : in out Report_Pretty_Printer);
procedure Pretty_Print_Message
(Pp : in out Report_Pretty_Printer;
M : Message);
-------------
-- Chapter --
-------------
procedure Chapter
(Pp : in out Report_Pretty_Printer'Class;
Title : String)
is
Output : constant File_Access := Get_Output;
begin
Pp.Current_Chapter := Pp.Current_Chapter + 1;
New_Line (Output.all);
Put_Line (Output.all, Frame (Img (Pp.Current_Chapter) & ". " & Title));
end Chapter;
-----------------------
-- Close_Report_File --
-----------------------
procedure Close_Report_File is
begin
if Final_Report.Name /= null then
Close (Final_Report.File);
Free (Final_Report.Name);
end if;
end Close_Report_File;
------------
-- Frame --
------------
function Frame (S : String; C : Character := '=') return String is
HS : constant String := Highlight (S, C);
Line : constant String (1 .. HS'Length) := (others => C);
begin
return Line & ASCII.LF & HS & ASCII.LF & Line;
end Frame;
---------------------
-- Generate_Report --
---------------------
procedure Generate_Report
(Context : Coverage.Context_Access;
Final_Report_Name : String_Access;
Dump_Units : Boolean)
is
Pp : Report_Pretty_Printer :=
(Need_Sources => False,
Context => Context,
Dump_Units => Dump_Units,
others => <>);
begin
if Final_Report_Name /= null then
Open_Report_File (Final_Report_Name.all);
end if;
Annotations.Generate_Report (Pp, True);
Close_Report_File;
end Generate_Report;
----------------
-- Get_Output --
----------------
function Get_Output return File_Access is
begin
if Final_Report.Name /= null then
return Final_Report.File'Access;
else
return Standard_Output;
end if;
end Get_Output;
---------------
-- Highlight --
---------------
function Highlight (S : String; C : Character := '*') return String is
Side : constant String (1 .. 2) := (others => C);
begin
return Side & " " & S & " " & Side;
end Highlight;
----------------------
-- Open_Report_File --
----------------------
procedure Open_Report_File (Final_Report_Name : String) is
begin
Final_Report.Name := new String'(Final_Report_Name);
Create (Final_Report.File, Out_File, Final_Report_Name);
end Open_Report_File;
---------------
-- Pluralize --
---------------
function Pluralize (Count : Natural; Item : String) return String is
begin
if Count = 0 then
return "No " & Item;
elsif Count = 1 then
return "1 " & Item;
else
return Img (Count) & " " & Item & "s";
end if;
end Pluralize;
----------------------
-- Pretty_Print_End --
----------------------
procedure Pretty_Print_End (Pp : in out Report_Pretty_Printer) is
use ALI_Files, ALI_Files.ALI_Annotation_Maps;
use Ada.Strings.Unbounded;
Output : constant File_Access := Get_Output;
Total_Messages : Natural;
-- Total count of output non-exempted messages (both violations and
-- other messages).
Total_Exempted_Regions : Natural;
function Has_Exempted_Region return Boolean;
-- True iff there's at least one exempted region
procedure Messages_For_Section
(MC : Report_Section;
Title : String;
Item : String);
-- Output all buffered messages of the given class in a section with the
-- given title (section omitted if Title is empty). Item is the noun for
-- the summary line counting messages in the section.
procedure Output_Exemption (C : Cursor);
-- Show summary information for exemption denoted by C
procedure Count_SCO (SCO : SCO_Id);
-- Account for SCO in the coverage tally
---------------
-- Count_SCO --
---------------
procedure Count_SCO (SCO : SCO_Id) is
Section : constant Report_Section := Section_Of_SCO (SCO);
L : Coverage_Level;
State : SCO_State;
begin
if Section /= Other_Errors then
L := Coverage_Level'Val (Section);
State := Get_Line_State (SCO, L);
if State /= No_Code then
Pp.SCO_Tallies (L).Total := Pp.SCO_Tallies (L).Total + 1;
if State = Covered then
Pp.SCO_Tallies (L).Covered := Pp.SCO_Tallies (L).Covered + 1;
end if;
end if;
end if;
end Count_SCO;
-------------------------
-- Has_Exempted_Region --
-------------------------
function Has_Exempted_Region return Boolean is
C : Cursor := ALI_Annotations.First;
begin
while Has_Element (C) loop
if Element (C).Kind = Exempt_On then
return True;
end if;
Next (C);
end loop;
return False;
end Has_Exempted_Region;
Non_Exempted_Str : constant String := "non-exempted ";
Non_Exempted : String renames Non_Exempted_Str
(Non_Exempted_Str'First ..
Boolean'Pos (Has_Exempted_Region)
* Non_Exempted_Str'Last);
-- If Has_Exempted_Region is True, Non_Exempted = Non_Exempted_Str,
-- else Non_Exempted = "". Used to omit the mention "non-exempted" when
-- there's no exemption in sight anyway.
----------------------
-- Output_Exemption --
----------------------
procedure Output_Exemption (C : Cursor) is
E : constant ALI_Annotation := Element (C);
Next_C : constant Cursor := Next (C);
Sloc : constant Source_Location := Key (C);
End_Sloc : Source_Location := Slocs.No_Location;
begin
if E.Kind /= Exempt_On then
return;
end if;
-- Determine end sloc of exempted region
if Next_C /= No_Element then
declare
Next_Sloc : constant Source_Location := Key (Next_C);
Next_E : constant ALI_Annotation := Element (Next_C);
begin
if Next_E.Kind = Exempt_Off
and then Sloc.Source_File = Next_Sloc.Source_File
then
End_Sloc := Next_Sloc;
end if;
end;
end if;
-- Output summary for this region: sloc range, exempted message count
-- and justification.
New_Line (Output.all);
Put (Output.all, Image (To_Range (Sloc, End_Sloc)));
if End_Sloc = Slocs.No_Location then
Put (Output.all, "-<eof>");
end if;
Put (Output.all, ":" & E.Count'Img & " exempted violation");
if E.Count > 1 then
Put (Output.all, "s");
end if;
Put_Line (Output.all, ", justification:");
Put_Line (Output.all, E.Message.all);
Total_Exempted_Regions := Total_Exempted_Regions + 1;
end Output_Exemption;
--------------------------
-- Messages_For_Section --
--------------------------
procedure Messages_For_Section
(MC : Report_Section;
Title : String;
Item : String)
is
procedure Output_Message (C : Message_Vectors.Cursor);
-- Print M in the final report and update item count. The difference
-- with Pretty_Print_Message is that Put_Message does not tries to
-- know if the message should be exempted or not.
Item_Count : Natural := 0;
--------------------
-- Output_Message --
--------------------
procedure Output_Message (C : Message_Vectors.Cursor) is
M : Message renames Message_Vectors.Element (C);
Msg : constant String := To_String (M.Msg);
First : Natural := Msg'First;
begin
if M.SCO /= No_SCO_Id then
Put
(Output.all, Image (First_Sloc (M.SCO), Unique_Name => True));
Put (Output.all, ": ");
if Msg (First) = '^' then
First := First + 1;
else
Put
(Output.all,
To_Lower (SCO_Kind'Image (Kind (M.SCO)))
& (if Switches.Show_MCDC_Vectors
and then Kind (M.SCO) = Condition
then Index (M.SCO)'Image
& " (""" & SCO_Text (M.SCO) & """) "
else " "));
end if;
else
Put (Output.all, Image (M.Sloc, Unique_Name => True));
Put (Output.all, ": ");
end if;
Output_Multiline_Msg
(Output => Output.all,
Text => Msg (First .. Msg'Last));
if M.SCO /= No_SCO_Id and then M.Tag /= No_SC_Tag then
Put (Output.all,
" (from " & Tag_Provider.Tag_Name (M.Tag) & ")");
end if;
Total_Messages := Total_Messages + 1;
Item_Count := Item_Count + 1;
New_Line (Output.all);
end Output_Message;
-- Start of processing for Messages_For_Section
begin
if Title /= "" then
Pp.Section (Title);
end if;
Pp.Nonexempted_Messages (MC).Iterate (Output_Message'Access);
if Item_Count > 0 then
New_Line (Output.all);
end if;
-- Output summary line at end of section
Put_Line (Output.all, Pluralize (Item_Count, Item) & ".");
-- Append summary line for general summary chapter
Pp.Summary.Append
(To_Unbounded_String
(Pluralize
(Item_Count,
(case MC is
when Coverage_Violations =>
Non_Exempted
& Coverage_Level'Val (MC)'Img & " " & Item,
when Other_Errors =>
"other message",
when Coverage_Exclusions =>
"coverage exclusion")) & "."));
-- Count of total (coverable) and covered SCOs is displayed only
-- if --all-messages is specified.
if Switches.All_Messages and then MC in Coverage_Violations then
declare
T : SCO_Tally renames Pp.SCO_Tallies (Coverage_Level'Val (MC));
begin
Put_Line (Output.all,
Pluralize (T.Covered, "coverage obligation")
& " covered out of" & T.Total'Img & ".");
end;
end if;
end Messages_For_Section;
-- Start of processing for Pretty_Print_End
begin
if Source_Coverage_Enabled then
SC_Obligations.Iterate (Count_SCO'Access);
end if;
Pp.Chapter (To_Upper (Non_Exempted) & "COVERAGE VIOLATIONS");
Total_Messages := 0;
for L in Coverage_Level loop
if Enabled (L)
or else (L = Decision and then MCDC_Coverage_Enabled)
then
Messages_For_Section
(Coverage_Level'Pos (L),
Title => L'Img & " COVERAGE",
Item => "violation");
else
pragma Assert
(Pp.Nonexempted_Messages (Coverage_Level'Pos (L)).Is_Empty);
null;
end if;
end loop;
if Source_Coverage_Enabled and then Switches.All_Messages then
Messages_For_Section
(Other_Errors,
Title => "OTHER ERRORS",
Item => "message");
end if;
if Switches.Excluded_SCOs then
Pp.Chapter ("NON COVERABLE ITEMS");
New_Line (Output.all);
Messages_For_Section
(Coverage_Exclusions,
Title => "",
Item => "exclusion");
end if;
if Has_Exempted_Region then
Pp.Chapter ("EXEMPTED REGIONS");
Total_Exempted_Regions := 0;
ALI_Annotations.Iterate (Output_Exemption'Access);
New_Line (Output.all);
Put_Line
(Output.all,
Pluralize (Total_Exempted_Regions, "exempted region") & ".");
end if;
Pp.Chapter ("ANALYSIS SUMMARY");
New_Line (Output.all);
for L of Pp.Summary loop
Put_Line (Output.all, To_String (L));
end loop;
if Has_Exempted_Region then
Put_Line
(Output.all,
Pluralize (Total_Exempted_Regions, "exempted region") & ".");
end if;
if Pp.Dump_Units then
Pp.Chapter ("UNITS OF INTEREST");
New_Line (Output.all);
declare
procedure Print_Ignored_File
(FI : Files_Table.File_Info);
-- Print the name of the file and its ignore status on the report
procedure Print_Unit_Name (Name : String);
-- Print Name on the report
------------------------
-- Print_Ignored_File --
------------------------
procedure Print_Ignored_File
(FI : Files_Table.File_Info) is
begin
if FI.Ignore_Status = Files_Table.Sometimes then
Put_Line (Output.all,
" " & FI.Unique_Name.all & " sometimes ignored");
elsif FI.Ignore_Status = Files_Table.Always then
Put_Line (Output.all,
" " & FI.Unique_Name.all & " always ignored");
end if;
end Print_Ignored_File;
---------------------
-- Print_Unit_Name --
---------------------
procedure Print_Unit_Name (Name : String) is
begin
Put_Line (Output.all, Name);
end Print_Unit_Name;
begin
Iterate_On_Unit_List
(Print_Unit_Name'Access, Print_Ignored_File'Access);
end;
end if;
New_Line (Output.all);
Put_Line (Output.all, Highlight ("END OF REPORT"));
end Pretty_Print_End;
---------------------------
-- Pretty_Print_End_File --
---------------------------
procedure Pretty_Print_End_File (Pp : in out Report_Pretty_Printer) is
begin
null;
end Pretty_Print_End_File;
-----------------------------
-- Pretty_Print_Start_Line --
-----------------------------
procedure Pretty_Print_Start_Line
(Pp : in out Report_Pretty_Printer;
Line_Num : Natural;
Info : Line_Info_Access;
Line : String)
is
pragma Unreferenced (Line_Num, Line);
begin
Pp.Exemption := Info.Exemption;
end Pretty_Print_Start_Line;
--------------------------
-- Pretty_Print_Message --
--------------------------
procedure Pretty_Print_Message
(Pp : in out Report_Pretty_Printer;
M : Message)
is
MC : constant Report_Section := Section_Of_Message (M);
begin
-- Messages with Kind = Notice need not be included in the report
if M.Kind > Notice then
-- If M is a violation, check if an exemption is currently active
if M.Kind = Violation and then Pp.Exemption /= Slocs.No_Location then
Pp.Exempted_Messages.Append (M);
Inc_Exemption_Count (Pp.Exemption);
else
Pp.Nonexempted_Messages (MC).Append (M);
end if;
end if;
end Pretty_Print_Message;
------------------------
-- Pretty_Print_Start --
------------------------
procedure Pretty_Print_Start (Pp : in out Report_Pretty_Printer) is
use Ada.Calendar.Formatting;
use Ada.Strings.Unbounded;
Output : constant File_Access := Get_Output;
procedure Process_One_Trace (TF : Trace_File_Element);
-- Print info from the TF trace file
-----------------------
-- Process_One_Trace --
-----------------------
procedure Process_One_Trace (TF : Trace_File_Element) is
Orig_Context : constant String := Original_Processing_Context (TF);
begin
New_Line (Output.all);
Put_Line (Output.all, To_String (TF.Filename));
Put_Line (Output.all, " kind : " & Image (TF.Kind));
Put_Line (Output.all, " program : " & To_String (TF.Program_Name));
Put_Line (Output.all, " date : " & To_String (TF.Time));
Put_Line (Output.all, " tag : " & To_String (TF.User_Data));
-- For a trace that has been processed in an earlier run, provide
-- information on original coverage assessment context.
if Orig_Context /= "" then
Put_Line (Output.all, " processed: " & Orig_Context);
end if;
end Process_One_Trace;
-- Start of processing for Pretty_Print_Start
begin
Put_Line (Output.all, Highlight ("COVERAGE REPORT"));
Pp.Chapter ("ASSESSMENT CONTEXT");
New_Line (Output.all);
Put_Line (Output.all, "Date and time of execution: "
& Image (Pp.Context.Timestamp, Include_Time_Fraction => True));
Put_Line (Output.all, "Tool version: XCOV "
& To_String (Pp.Context.Version));
New_Line (Output.all);
Put_Line (Output.all, "Command line:");
Put_Line (Output.all, To_String (Pp.Context.Command));
New_Line (Output.all);
Put_Line (Output.all, "Coverage level: "
& To_String (Pp.Context.Levels));
New_Line (Output.all);
Put_Line (Output.all, "Trace files:");
Iterate_On_Traces_Files (Process_One_Trace'Access);
end Pretty_Print_Start;
-----------------------------
-- Pretty_Print_Start_File --
-----------------------------
procedure Pretty_Print_Start_File
(Pp : in out Report_Pretty_Printer;
File : Source_File_Index;
Skip : out Boolean)
is
Info : constant File_Info_Access := Get_File (File);
begin
if Info.Stats (Covered) /= Get_Total (Info.Stats) then
-- Some uncovered or partially covered lines are present
Pp.Current_File_Index := File;
Skip := False;
else
-- Everything covered: nothing to report for this file
Skip := True;
end if;
end Pretty_Print_Start_File;
-------------
-- Section --
-------------
procedure Section
(Pp : in out Report_Pretty_Printer'Class;
Title : String)
is
Output : constant File_Access := Get_Output;
begin
Pp.Current_Section := Pp.Current_Section + 1;
New_Line (Output.all);
Put_Line (Output.all,
Underline (Img (Pp.Current_Chapter) & "."
& Img (Pp.Current_Section) & ". "
& Title));
New_Line (Output.all);
end Section;
------------------------
-- Section_Of_Message --
------------------------
function Section_Of_Message (M : Message) return Report_Section is
begin
if M.SCO /= No_SCO_Id and then M.Kind in Coverage_Kind then
if M.Kind = Exclusion then
return Coverage_Exclusions;
else
pragma Assert (M.Kind = Violation);
declare
S : constant Report_Section := Section_Of_SCO (M.SCO);
begin
if S = Other_Errors then
-- A violation message is expected to always be relevant to
-- some report section.
raise Program_Error with "unexpected SCO kind in violation";
end if;
return S;
end;
end if;
else
pragma Assert (M.Kind not in Coverage_Kind);
return Other_Errors;
end if;
end Section_Of_Message;
--------------------
-- Section_Of_SCO --
--------------------
function Section_Of_SCO (SCO : SCO_Id) return Report_Section is
MCDC_Section : Report_Section;
begin
-- Need to initialize MCDC_Section specially because it is erroneous
-- to evaluate MCDC_Level if MCDC coverage is not enabled.
if MCDC_Coverage_Enabled then
MCDC_Section := Coverage_Level'Pos (MCDC_Level);
else
MCDC_Section := Other_Errors;
end if;
case Kind (SCO) is
when Statement =>
return Coverage_Level'Pos (Stmt);
when Decision =>
if Is_Expression (SCO) then
return MCDC_Section;
else
return Coverage_Level'Pos (Decision);
end if;
when Condition =>
return MCDC_Section;
when others =>
return Other_Errors;
end case;
end Section_Of_SCO;
-----------------
-- Underline --
-----------------
function Underline (S : String; C : Character := '-') return String is
Line : constant String (1 .. S'Length) := (others => C);
begin
return S & ASCII.LF & Line;
end Underline;
end Annotations.Report;