pyEDAA.Reports.CodeCoverage.QuestaSim

pyEDAA/Reports/CodeCoverage/QuestaSim.py
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
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
# ==================================================================================================================== #
#              _____ ____    _        _      ____                       _                                              #
#  _ __  _   _| ____|  _ \  / \      / \    |  _ \ ___ _ __   ___  _ __| |_ ___                                        #
# | '_ \| | | |  _| | | | |/ _ \    / _ \   | |_) / _ \ '_ \ / _ \| '__| __/ __|                                       #
# | |_) | |_| | |___| |_| / ___ \  / ___ \ _|  _ <  __/ |_) | (_) | |  | |_\__ \                                       #
# | .__/ \__, |_____|____/_/   \_\/_/   \_(_)_| \_\___| .__/ \___/|_|   \__|___/                                       #
# |_|    |___/                                        |_|                                                              #
# ==================================================================================================================== #
# Authors:                                                                                                             #
#   Patrick Lehmann                                                                                                    #
#                                                                                                                      #
# License:                                                                                                             #
# ==================================================================================================================== #
# Copyright 2026-2026 Electronic Design Automation Abstraction (EDA²)                                                  #
#                                                                                                                      #
# Licensed under the Apache License, Version 2.0 (the "License");                                                      #
# you may not use this file except in compliance with the License.                                                     #
# You may obtain a copy of the License at                                                                              #
#                                                                                                                      #
#   http://www.apache.org/licenses/LICENSE-2.0                                                                         #
#                                                                                                                      #
# Unless required by applicable law or agreed to in writing, software                                                  #
# distributed under the License is distributed on an "AS IS" BASIS,                                                    #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.                                             #
# See the License for the specific language governing permissions and                                                  #
# limitations under the License.                                                                                       #
#                                                                                                                      #
# SPDX-License-Identifier: Apache-2.0                                                                                  #
# ==================================================================================================================== #
#
"""
QuestaSim's coverage report XML: a model of the format, read from a report and converted to the common model.

Questa SIM keeps coverage in a coverage database (UCDB), whose format is proprietary. The command
``vcover report -xml -details`` - or ``coverage report -xml -details`` in a simulation - writes a report of it as XML,
with the coverage items of each instance:

.. code-block:: bash

   vcover report -xml -details -output CoverageReport.xml Testsuite.ucdb

The XML's root is ``<coverage_report>``, without namespace and without format version; it isn't the XML interchange
format of the UCIS standard. Questa states its version - e.g. ``2026.2`` - and the command, which wrote the report. A
report is validated against :file:`QuestaSim-Coverage.xsd` (:data:`SCHEMA`).

The format's model keeps what the report states: a :class:`Document` holds the report's mode (:class:`ReportMode`) and
its scopes - instances, design units or source files (:class:`Scope`) -, each with its coverage statistics
(:class:`Statistics`), its source files and its coverage items: the statements, the ``if`` and ``case`` statements with
their branches, and the states and transitions of finite state machines. Each element's constructor takes typed values,
so the model can be built by hand: an element below the report names its parent with the keyword parameter ``parent``
and is added to it. Its class method ``Parse`` reads the element's XML element.

* A coverage statistics element states how many coverage items of a kind - e.g. statements or branches - a scope or a
  summary record (:class:`Totals`) has, and how many of them were hit.
* Which kind of scope a report lists, its mode decides: :class:`InstanceData`, :class:`DesignUnitData` or
  :class:`FileData`. With details (``vcover report -details``), a scope names its source files in a source table and
  lists its coverage items.
* ``-code`` chooses the kinds of coverage items, e.g. ``-code bcesf`` for branches, conditions, expressions, statements
  and finite state machines. A coverage item - :class:`Statement`, :class:`IfBranch`, :class:`CaseBranch` - names its
  source file by the number the scope's source table gives it, its line, and its index among the items of its kind in
  that line.
* Unlike the other coverage items, a state (:class:`FSMState`) and a transition (:class:`FSMTransition`) of a finite
  state machine name no file number: their file is the scope's, if the scope has a single file.

:meth:`Document.ToCoverageSummary` converts the statements and branches to the common model of
:mod:`pyEDAA.Reports.CodeCoverage`:

* Coverage items are identified by their file, their line and their index in the line. The items of all scopes are
  merged: an item of a design unit with several instances counts as often as in all instances together.
* A line ran as often as its least often run statement or branching statement. An ``if`` or ``case`` statement adds
  its branches to the line of its first branch - the ``if``, or the first case item -, each taken as often as Questa
  counted.
* A line, which ran, is covered, if all its branches were taken, otherwise partially covered.

The coverage statistics, the states and transitions of finite state machines, conditions, expressions and toggles
aren't converted.

.. rubric:: Example

.. code-block:: Python

   from pathlib import Path
   from pyEDAA.Reports.CodeCoverage.QuestaSim import Document

   report = Document(Path("CoverageReport.xml"), analyzeAndConvert=True)
   summary = report.ToCoverageSummary()
   print(f"Lines:    {summary.CoveredLines} of {summary.TotalLines}")
   print(f"Branches: {summary.CoveredBranches} of {summary.TotalBranches}")
"""
from __future__                  import annotations

from io                          import BytesIO
from pathlib                     import Path
from typing                      import Generator, Mapping, Optional as Nullable, Self

from lxml.etree                  import XMLParser, XMLSchema, XMLSchemaParseError, XMLSyntaxError
from lxml.etree                  import _Element, _ElementTree, parse
from pyTooling.Common            import getFullyQualifiedName, getResourceFile, StringEnum
from pyTooling.Decorators        import export, readonly
from pyTooling.Exceptions        import ToolingException
from pyTooling.MetaClasses       import ExtendedType
from pyTooling.Stopwatch         import Stopwatch

from pyEDAA.Reports              import Resources
from pyEDAA.Reports.CodeCoverage import CodeCoverageError, CoverageSummary, Document as cc_Document
from pyEDAA.Reports.CodeCoverage import Branch as cc_Branch, Line as cc_Line, LineCoverageStatus


__all__ = ["SCHEMA"]

SCHEMA = "QuestaSim-Coverage.xsd"  #: The XML schema a report is validated against.

# A class with a property named like a class - ``Path``, ``Totals`` - can't name that class in the annotation of a
# field: the class body's namespace, where annotations are evaluated, binds the name to the property.
_Path = Path


@export
class ReportMode(StringEnum):
	"""
	How a report groups its coverage data, as the attribute of ``<code_coverage_report>`` set to ``1`` states.
	"""

	ByInstance =   "byInstance"  #: Per instance (``<instanceData>``), ``vcover report -setdefault byinstance``.
	ByDesignUnit = "byDU"        #: Per design unit (``<DuData>``), ``vcover report -setdefault bydu``.
	ByFile =       "byFile"      #: Per source file (``<fileData>``), ``vcover report -setdefault byfile``.


@export
class CoverageKind(StringEnum):
	"""
	Kind of coverage items a coverage statistics element counts, as its element name states.
	"""

	Statements =  "statements"     #: Statements.
	Branches =    "branches"       #: Branches of ``if`` and ``case`` statements.
	Conditions =  "conditions"     #: Conditions.
	Expressions = "expressions"    #: Expressions.
	States =      "states"         #: States of finite state machines.
	Transitions = "transitions"    #: Transitions of finite state machines.
	Toggles =     "toggleSummary"  #: Signal toggles.


@export
class Statistics(metaclass=ExtendedType, slots=True):
	"""
	A coverage statistics element of a scope or a summary record: how many coverage items of a kind it has, and how many
	of them were hit.

	The element is named after the kind of coverage items, e.g. ``<statements>`` or ``<branches>``.
	"""

	_parent:  Nullable[StatisticsMixin]  #: The scope or summary record the coverage statistics belong to.
	_kind:    CoverageKind               #: Kind of the coverage items.
	_active:  int                        #: Number of coverage items.
	_hits:    int                        #: Number of coverage items, which were hit.
	_percent: float                      #: Percentage of coverage items, which were hit, as the report states it.

	def __init__(
		self,
		kind: CoverageKind,
		active: int,
		hits: int,
		percent: float,
		*,
		parent: Nullable[StatisticsMixin] = None
	) -> None:
		"""
		Initialize the coverage statistics, and add them to the coverage statistics of their element.

		:param kind:               Kind of the coverage items.
		:param active:             Number of coverage items.
		:param hits:               Number of coverage items, which were hit.
		:param percent:            Percentage of coverage items, which were hit, as the report states it.
		:param parent:             Optional, the scope or summary record the coverage statistics belong to; they are added
		                           to its coverage statistics by :attr:`Kind`. Default: ``None``.
		:raises ValueError:        If parameter ``kind`` is ``None``.
		:raises TypeError:         If parameter ``kind`` isn't of type :class:`CoverageKind`.
		:raises ValueError:        If parameter ``active`` is ``None``.
		:raises TypeError:         If parameter ``active`` isn't of type :class:`int`.
		:raises ValueError:        If parameter ``active`` is negative.
		:raises ValueError:        If parameter ``hits`` is ``None``.
		:raises TypeError:         If parameter ``hits`` isn't of type :class:`int`.
		:raises ValueError:        If parameter ``hits`` is negative or greater than parameter ``active``.
		:raises ValueError:        If parameter ``percent`` is ``None``.
		:raises TypeError:         If parameter ``percent`` isn't of type :class:`float` or :class:`int`.
		:raises ValueError:        If parameter ``percent`` is out of range 0..100.
		:raises TypeError:         If parameter ``parent`` isn't of type :class:`StatisticsMixin`.
		:raises CodeCoverageError: If the parent already has coverage statistics of this kind.
		"""
		if kind is None:
			raise ValueError("Parameter 'kind' is None.")
		elif not isinstance(kind, CoverageKind):
			ex = TypeError("Parameter 'kind' is not of type 'CoverageKind'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(kind)}'.")
			raise ex

		if active is None:
			raise ValueError("Parameter 'active' is None.")
		elif not isinstance(active, int):
			ex = TypeError("Parameter 'active' is not of type 'int'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(active)}'.")
			raise ex
		elif active < 0:
			ex = ValueError("Parameter 'active' is negative.")
			ex.add_note(f"Got value '{active}'.")
			raise ex

		if hits is None:
			raise ValueError("Parameter 'hits' is None.")
		elif not isinstance(hits, int):
			ex = TypeError("Parameter 'hits' is not of type 'int'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(hits)}'.")
			raise ex
		elif not (0 <= hits <= active):
			ex = ValueError(f"Parameter 'hits' is out of range 0..{active}.")
			ex.add_note(f"Got value '{hits}'.")
			raise ex

		if percent is None:
			raise ValueError("Parameter 'percent' is None.")
		elif not isinstance(percent, (float, int)):
			ex = TypeError("Parameter 'percent' is not of type 'float' or 'int'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(percent)}'.")
			raise ex
		elif not (0.0 <= percent <= 100.0):
			ex = ValueError("Parameter 'percent' is out of range 0..100.")
			ex.add_note(f"Got value '{percent}'.")
			raise ex

		if parent is not None:
			if not isinstance(parent, StatisticsMixin):
				ex = TypeError("Parameter 'parent' is not of type 'StatisticsMixin'.")
				ex.add_note(f"Got type '{getFullyQualifiedName(parent)}'.")
				raise ex
			elif kind in parent._statistics:
				raise CodeCoverageError(f"Coverage statistics '{kind}' are stated twice.")

		self._parent =  parent
		self._kind =    kind
		self._active =  active
		self._hits =    hits
		self._percent = float(percent)

		if parent is not None:
			parent._statistics[kind] = self

	@classmethod
	def Parse(cls, element: _Element, *, parent: Nullable[StatisticsMixin] = None) -> Self:
		"""
		Parse coverage statistics from their element.

		:param element:            The coverage statistics element.
		:param parent:             Optional, the scope or summary record the coverage statistics belong to. Default:
		                           ``None``.
		:returns:                  The coverage statistics.
		:raises CodeCoverageError: If the element states more hit items than items.
		:raises CodeCoverageError: If the parent already has coverage statistics of this kind.
		"""
		active = int(element.attrib["active"])
		hits =   int(element.attrib["hits"])
		if hits > active:
			ex = CodeCoverageError(f"Coverage statistics '<{element.tag}>' state more hit items than items.")
			ex.add_note(f"Got '{hits}' hit items of '{active}' items in line {element.sourceline}.")
			raise ex

		return cls(CoverageKind(element.tag), active, hits, float(element.attrib["percent"]), parent=parent)

	@readonly
	def Parent(self) -> Nullable[StatisticsMixin]:
		"""
		Read-only property to access the scope or summary record the coverage statistics belong to (:attr:`_parent`).

		:returns: The scope or summary record; ``None`` if the coverage statistics belong to none.
		"""
		return self._parent

	@readonly
	def Kind(self) -> CoverageKind:
		"""
		Read-only property to access the kind of the coverage items (:attr:`_kind`).

		:returns: The kind of the coverage items.
		"""
		return self._kind

	@readonly
	def Active(self) -> int:
		"""
		Read-only property to access the number of coverage items (:attr:`_active`).

		:returns: The number of coverage items.
		"""
		return self._active

	@readonly
	def Hits(self) -> int:
		"""
		Read-only property to access the number of coverage items, which were hit (:attr:`_hits`).

		:returns: The number of hit coverage items.
		"""
		return self._hits

	@readonly
	def Percent(self) -> float:
		"""
		Read-only property to access the percentage of coverage items, which were hit, as the report states it
		(:attr:`_percent`).

		Questa truncates the percentage to two decimals: 66 of 74 items are ``89.18`` percent.

		:returns: The percentage, from 0 to 100.
		"""
		return self._percent


@export
class StatisticsMixin(metaclass=ExtendedType, mixin=True):
	"""
	A mixin-class adding the coverage statistics an element states: per kind of coverage items, how many it has and how
	many were hit.
	"""

	_statistics: dict[CoverageKind, Statistics]  #: The coverage statistics, by kind.

	def __init__(self) -> None:
		"""
		Initialize the coverage statistics to none.

		Coverage statistics are added by creating them with the element as their parent.
		"""
		self._statistics = {}

	def _ParseStatistics(self, element: _Element) -> None:
		"""
		Parse the coverage statistics elements below an element, with this element as their parent.

		:param element:            The element holding the coverage statistics elements.
		:raises CodeCoverageError: If a coverage statistics element states more hit items than items.
		:raises CodeCoverageError: If the element states a kind of coverage statistics twice.
		"""
		kinds = [kind.value for kind in CoverageKind]
		for child in element:
			if child.tag in kinds:
				Statistics.Parse(child, parent=self)

	@readonly
	def Statistics(self) -> dict[CoverageKind, Statistics]:
		"""
		Read-only property to access the coverage statistics (:attr:`_statistics`).

		:returns: The coverage statistics, by kind; a kind the element doesn't state has none.
		"""
		return self._statistics


@export
class SourceItem(metaclass=ExtendedType, slots=True):
	"""
	Base-class of the coverage items, which name where they are in the sources: a file, a line and an index in the line.
	"""

	_file:       Path  #: Path of the source file, as the report states it.
	_lineNumber: int   #: Line number, counted from 1.
	_index:      int   #: Index of the item among the items of its kind in its line, counted from 1.

	def __init__(self, file: Path, lineNumber: int, index: int) -> None:
		"""
		Initialize where the coverage item is in the sources.

		:param file:        Path of the source file, as the report states it.
		:param lineNumber:  Line number, counted from 1.
		:param index:       Index of the item among the items of its kind in its line, counted from 1.
		:raises ValueError: If parameter ``file`` is ``None``.
		:raises TypeError:  If parameter ``file`` isn't of type :class:`~pathlib.Path`.
		:raises ValueError: If parameter ``lineNumber`` is ``None``.
		:raises TypeError:  If parameter ``lineNumber`` isn't of type :class:`int`.
		:raises ValueError: If parameter ``lineNumber`` is less than 1.
		:raises ValueError: If parameter ``index`` is ``None``.
		:raises TypeError:  If parameter ``index`` isn't of type :class:`int`.
		:raises ValueError: If parameter ``index`` is less than 1.
		"""
		if file is None:
			raise ValueError("Parameter 'file' is None.")
		elif not isinstance(file, Path):
			ex = TypeError("Parameter 'file' is not of type 'Path'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(file)}'.")
			raise ex

		if lineNumber is None:
			raise ValueError("Parameter 'lineNumber' is None.")
		elif not isinstance(lineNumber, int):
			ex = TypeError("Parameter 'lineNumber' is not of type 'int'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(lineNumber)}'.")
			raise ex
		elif lineNumber < 1:
			ex = ValueError("Parameter 'lineNumber' is less than 1.")
			ex.add_note(f"Got value '{lineNumber}'.")
			raise ex

		if index is None:
			raise ValueError("Parameter 'index' is None.")
		elif not isinstance(index, int):
			ex = TypeError("Parameter 'index' is not of type 'int'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(index)}'.")
			raise ex
		elif index < 1:
			ex = ValueError("Parameter 'index' is less than 1.")
			ex.add_note(f"Got value '{index}'.")
			raise ex

		self._file =       file
		self._lineNumber = lineNumber
		self._index =      index

	@readonly
	def File(self) -> Path:
		"""
		Read-only property to access the path of the source file (:attr:`_file`).

		:returns: The path, as the report states it.
		"""
		return self._file

	@readonly
	def LineNumber(self) -> int:
		"""
		Read-only property to access the line number (:attr:`_lineNumber`).

		:returns: The line number, counted from 1.
		"""
		return self._lineNumber

	@readonly
	def Index(self) -> int:
		"""
		Read-only property to access the index of the item among the items of its kind in its line (:attr:`_index`).

		:returns: The index, counted from 1.
		"""
		return self._index


@export
class Statement(SourceItem):
	"""
	A ``<stmt>`` of a scope: a statement, where it is in the sources, and how often it ran.
	"""

	_parent: Nullable[Scope]  #: The scope the statement belongs to.
	_hits:   int              #: How often the statement ran.

	def __init__(self, file: Path, lineNumber: int, index: int, hits: int, *, parent: Nullable[Scope] = None) -> None:
		"""
		Initialize the statement, and append it to the statements of its scope.

		:param file:        Path of the source file, as the report states it.
		:param lineNumber:  Line number, counted from 1.
		:param index:       Index of the statement in its line, counted from 1.
		:param hits:        How often the statement ran.
		:param parent:      Optional, the scope the statement belongs to; the statement is appended to its statements.
		                    Default: ``None``.
		:raises ValueError: If parameter ``file`` is ``None``.
		:raises TypeError:  If parameter ``file`` isn't of type :class:`~pathlib.Path`.
		:raises ValueError: If parameter ``lineNumber`` is ``None``.
		:raises TypeError:  If parameter ``lineNumber`` isn't of type :class:`int`.
		:raises ValueError: If parameter ``lineNumber`` is less than 1.
		:raises ValueError: If parameter ``index`` is ``None``.
		:raises TypeError:  If parameter ``index`` isn't of type :class:`int`.
		:raises ValueError: If parameter ``index`` is less than 1.
		:raises ValueError: If parameter ``hits`` is ``None``.
		:raises TypeError:  If parameter ``hits`` isn't of type :class:`int`.
		:raises ValueError: If parameter ``hits`` is negative.
		:raises TypeError:  If parameter ``parent`` isn't of type
		                    :class:`Scope`.
		"""
		super().__init__(file, lineNumber, index)

		if hits is None:
			raise ValueError("Parameter 'hits' is None.")
		elif not isinstance(hits, int):
			ex = TypeError("Parameter 'hits' is not of type 'int'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(hits)}'.")
			raise ex
		elif hits < 0:
			ex = ValueError("Parameter 'hits' is negative.")
			ex.add_note(f"Got value '{hits}'.")
			raise ex

		if parent is not None and not isinstance(parent, Scope):
			ex = TypeError("Parameter 'parent' is not of type 'Scope'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(parent)}'.")
			raise ex

		self._parent = parent
		self._hits =   hits

		if parent is not None:
			parent._statements.append(self)

	@classmethod
	def Parse(cls, element: _Element, *, parent: Scope) -> Self:
		"""
		Parse a statement from its ``<stmt>`` element; its file is the one its file number names in the scope's source
		table.

		:param element:            The ``<stmt>`` element.
		:param parent:             The scope the statement belongs to.
		:returns:                  The statement.
		:raises CodeCoverageError: If the statement's file number isn't in the scope's source table.
		:raises CodeCoverageError: If the statement states no file number and its scope has no single file.
		"""
		return cls(
			parent._ResolveFile(element),
			int(element.attrib["ln"]),
			int(element.attrib["st"]),
			int(element.attrib["hits"]),
			parent=parent
		)

	@readonly
	def Parent(self) -> Nullable[Scope]:
		"""
		Read-only property to access the scope the statement belongs to (:attr:`_parent`).

		:returns: The scope; ``None`` if the statement belongs to no scope.
		"""
		return self._parent

	@readonly
	def Hits(self) -> int:
		"""
		Read-only property to access how often the statement ran (:attr:`_hits`).

		:returns: The count.
		"""
		return self._hits


@export
class IfBranch(SourceItem):
	"""
	An ``<ielem>`` of an ``if`` statement: a branch - ``if``, ``elsif``, ``else`` or the implicit *AllFalse* branch -, how
	often it was taken, and how often its condition was false.
	"""

	_parent:     Nullable[IfStatement]  #: The ``if`` statement the branch belongs to.
	_trueCount:  int                    #: How often the branch was taken.
	_falseCount: int                    #: How often the branch's condition was false: the evaluation went on.

	def __init__(
		self,
		file: Path,
		lineNumber: int,
		index: int,
		trueCount: int,
		falseCount: int,
		*,
		parent: Nullable[IfStatement] = None
	) -> None:
		"""
		Initialize the branch, and append it to the branches of its ``if`` statement.

		:param file:        Path of the source file, as the report states it.
		:param lineNumber:  Line number of the branch's condition, counted from 1.
		:param index:       Index of the ``if`` statement in its line, counted from 1.
		:param trueCount:   How often the branch was taken.
		:param falseCount:  How often the branch's condition was false; ``0`` for an ``else`` or *AllFalse* branch.
		:param parent:      Optional, the ``if`` statement the branch belongs to. Default: ``None``.
		:raises ValueError: If parameter ``file`` is ``None``.
		:raises TypeError:  If parameter ``file`` isn't of type :class:`~pathlib.Path`.
		:raises ValueError: If parameter ``lineNumber`` is ``None``.
		:raises TypeError:  If parameter ``lineNumber`` isn't of type :class:`int`.
		:raises ValueError: If parameter ``lineNumber`` is less than 1.
		:raises ValueError: If parameter ``index`` is ``None``.
		:raises TypeError:  If parameter ``index`` isn't of type :class:`int`.
		:raises ValueError: If parameter ``index`` is less than 1.
		:raises ValueError: If parameter ``trueCount`` is ``None``.
		:raises TypeError:  If parameter ``trueCount`` isn't of type :class:`int`.
		:raises ValueError: If parameter ``trueCount`` is negative.
		:raises ValueError: If parameter ``falseCount`` is ``None``.
		:raises TypeError:  If parameter ``falseCount`` isn't of type :class:`int`.
		:raises ValueError: If parameter ``falseCount`` is negative.
		:raises TypeError:  If parameter ``parent`` isn't of type :class:`IfStatement`.
		"""
		super().__init__(file, lineNumber, index)

		if trueCount is None:
			raise ValueError("Parameter 'trueCount' is None.")
		elif not isinstance(trueCount, int):
			ex = TypeError("Parameter 'trueCount' is not of type 'int'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(trueCount)}'.")
			raise ex
		elif trueCount < 0:
			ex = ValueError("Parameter 'trueCount' is negative.")
			ex.add_note(f"Got value '{trueCount}'.")
			raise ex

		if falseCount is None:
			raise ValueError("Parameter 'falseCount' is None.")
		elif not isinstance(falseCount, int):
			ex = TypeError("Parameter 'falseCount' is not of type 'int'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(falseCount)}'.")
			raise ex
		elif falseCount < 0:
			ex = ValueError("Parameter 'falseCount' is negative.")
			ex.add_note(f"Got value '{falseCount}'.")
			raise ex

		if parent is not None and not isinstance(parent, IfStatement):
			ex = TypeError("Parameter 'parent' is not of type 'IfStatement'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(parent)}'.")
			raise ex

		self._parent =     parent
		self._trueCount =  trueCount
		self._falseCount = falseCount

		if parent is not None:
			parent._branches.append(self)

	@classmethod
	def Parse(cls, element: _Element, *, parent: IfStatement) -> Self:
		"""
		Parse a branch from its ``<ielem>`` element.

		:param element:            The ``<ielem>`` element.
		:param parent:             The ``if`` statement the branch belongs to; it belongs to a scope.
		:returns:                  The branch.
		:raises CodeCoverageError: If the branch's file number isn't in the scope's source table, or it states none and
		                           the scope has no single file.
		"""
		return cls(
			parent._parent._ResolveFile(element),
			int(element.attrib["ln"]),
			int(element.attrib["st"]),
			int(element.attrib["true"]),
			int(element.attrib["false"]),
			parent=parent
		)

	@readonly
	def Parent(self) -> Nullable[IfStatement]:
		"""
		Read-only property to access the ``if`` statement the branch belongs to (:attr:`_parent`).

		:returns: The ``if`` statement; ``None`` if the branch belongs to none.
		"""
		return self._parent

	@readonly
	def TrueCount(self) -> int:
		"""
		Read-only property to access how often the branch was taken (:attr:`_trueCount`).

		:returns: The count.
		"""
		return self._trueCount

	@readonly
	def FalseCount(self) -> int:
		"""
		Read-only property to access how often the branch's condition was false (:attr:`_falseCount`).

		Then the evaluation went on to the next branch: the count is the sum of the next branches' true counts.

		:returns: The count; ``0`` for an ``else`` or *AllFalse* branch.
		"""
		return self._falseCount


@export
class IfStatement(metaclass=ExtendedType, slots=True):
	"""
	An ``<if>`` of a scope: an ``if`` statement - with its ``elsif`` and ``else`` branches - and how often each branch was
	taken.

	Each branch is an ``<ielem>`` (:class:`IfBranch`). An ``if`` statement without ``else`` has an implicit branch, the
	*AllFalse* branch, taken whenever no condition was true; Questa lists it as the last ``<ielem>``, in the line of the
	``if``.
	"""

	_parent:   Nullable[Scope]  #: The scope the ``if`` statement belongs to.
	_hasElse:  bool             #: Whether the ``if`` statement has an ``else`` branch.
	_branches: list[IfBranch]   #: The branches, in the order of their conditions.

	def __init__(self, hasElse: bool, *, parent: Nullable[Scope] = None) -> None:
		"""
		Initialize the ``if`` statement, and append it to the ``if`` statements of its scope.

		Its branches are added by creating them with this ``if`` statement as their parent.

		:param hasElse:     Whether the ``if`` statement has an ``else`` branch; otherwise its last branch is the implicit
		                    *AllFalse* branch.
		:param parent:      Optional, the scope the ``if`` statement belongs to. Default: ``None``.
		:raises ValueError: If parameter ``hasElse`` is ``None``.
		:raises TypeError:  If parameter ``hasElse`` isn't of type :class:`bool`.
		:raises TypeError:  If parameter ``parent`` isn't of type
		                    :class:`Scope`.
		"""
		if hasElse is None:
			raise ValueError("Parameter 'hasElse' is None.")
		elif not isinstance(hasElse, bool):
			ex = TypeError("Parameter 'hasElse' is not of type 'bool'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(hasElse)}'.")
			raise ex

		if parent is not None and not isinstance(parent, Scope):
			ex = TypeError("Parameter 'parent' is not of type 'Scope'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(parent)}'.")
			raise ex

		self._parent =   parent
		self._hasElse =  hasElse
		self._branches = []

		if parent is not None:
			parent._ifStatements.append(self)

	@classmethod
	def Parse(cls, element: _Element, *, parent: Scope) -> Self:
		"""
		Parse an ``if`` statement and its branches from its ``<if>`` element.

		:param element:            The ``<if>`` element.
		:param parent:             The scope the ``if`` statement belongs to.
		:returns:                  The ``if`` statement.
		:raises CodeCoverageError: If a branch's file number isn't in the scope's source table, or it states none and the
		                           scope has no single file.
		:raises CodeCoverageError: If the ``if`` statement states other numbers of branches and taken branches than its
		                           branches have.
		"""
		ifStatement = cls(element.attrib["hasElse"] == "1", parent=parent)
		for branchElement in element.iterfind("ielem"):
			IfBranch.Parse(branchElement, parent=ifStatement)

		active = int(element.attrib["active"])
		hits =   int(element.attrib["hits"])
		if active != len(ifStatement._branches) or hits != ifStatement.TakenBranches:
			ex = CodeCoverageError(f"'<if>' in line {element.sourceline} states other figures than its branches have.")
			ex.add_note(f"Got '{hits}' of '{active}' branches taken, its branches have {ifStatement.TakenBranches} of "
			            f"{len(ifStatement._branches)}.")
			raise ex

		return ifStatement

	@readonly
	def Parent(self) -> Nullable[Scope]:
		"""
		Read-only property to access the scope the ``if`` statement belongs to (:attr:`_parent`).

		:returns: The scope; ``None`` if the ``if`` statement belongs to no scope.
		"""
		return self._parent

	@readonly
	def HasElse(self) -> bool:
		"""
		Read-only property to access whether the ``if`` statement has an ``else`` branch (:attr:`_hasElse`).

		:returns: ``True``, if it has an ``else`` branch; otherwise its last branch is the implicit *AllFalse* branch.
		"""
		return self._hasElse

	@readonly
	def Branches(self) -> list[IfBranch]:
		"""
		Read-only property to access the branches (:attr:`_branches`).

		:returns: The branches, in the order of their conditions; the ``else`` or *AllFalse* branch last.
		"""
		return self._branches

	@readonly
	def TakenBranches(self) -> int:
		"""
		Read-only property to return the number of branches, which were taken.

		:returns: The number of branches with a positive :attr:`IfBranch.TrueCount`.
		"""
		return sum(1 for branch in self._branches if branch._trueCount > 0)

	@readonly
	def EvaluationCount(self) -> int:
		"""
		Read-only property to return how often the ``if`` statement was evaluated.

		Each evaluation takes exactly one branch, so it is the sum of the branches' :attr:`IfBranch.TrueCount`.

		:returns: The number of evaluations.
		"""
		return sum(branch._trueCount for branch in self._branches)


@export
class CaseBranch(SourceItem):
	"""
	A ``<celem>`` of a ``case`` statement: a case item, and how often it was taken.
	"""

	_parent: Nullable[CaseStatement]  #: The ``case`` statement the branch belongs to.
	_hits:   int                      #: How often the branch was taken.

	def __init__(
		self,
		file: Path,
		lineNumber: int,
		index: int,
		hits: int,
		*,
		parent: Nullable[CaseStatement] = None
	) -> None:
		"""
		Initialize the branch, and append it to the branches of its ``case`` statement.

		:param file:        Path of the source file, as the report states it.
		:param lineNumber:  Line number of the case item, counted from 1.
		:param index:       Index of the case item in its line, counted from 1.
		:param hits:        How often the branch was taken.
		:param parent:      Optional, the ``case`` statement the branch belongs to. Default: ``None``.
		:raises ValueError: If parameter ``file`` is ``None``.
		:raises TypeError:  If parameter ``file`` isn't of type :class:`~pathlib.Path`.
		:raises ValueError: If parameter ``lineNumber`` is ``None``.
		:raises TypeError:  If parameter ``lineNumber`` isn't of type :class:`int`.
		:raises ValueError: If parameter ``lineNumber`` is less than 1.
		:raises ValueError: If parameter ``index`` is ``None``.
		:raises TypeError:  If parameter ``index`` isn't of type :class:`int`.
		:raises ValueError: If parameter ``index`` is less than 1.
		:raises ValueError: If parameter ``hits`` is ``None``.
		:raises TypeError:  If parameter ``hits`` isn't of type :class:`int`.
		:raises ValueError: If parameter ``hits`` is negative.
		:raises TypeError:  If parameter ``parent`` isn't of type :class:`CaseStatement`.
		"""
		super().__init__(file, lineNumber, index)

		if hits is None:
			raise ValueError("Parameter 'hits' is None.")
		elif not isinstance(hits, int):
			ex = TypeError("Parameter 'hits' is not of type 'int'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(hits)}'.")
			raise ex
		elif hits < 0:
			ex = ValueError("Parameter 'hits' is negative.")
			ex.add_note(f"Got value '{hits}'.")
			raise ex

		if parent is not None and not isinstance(parent, CaseStatement):
			ex = TypeError("Parameter 'parent' is not of type 'CaseStatement'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(parent)}'.")
			raise ex

		self._parent = parent
		self._hits =   hits

		if parent is not None:
			parent._branches.append(self)

	@classmethod
	def Parse(cls, element: _Element, *, parent: CaseStatement) -> Self:
		"""
		Parse a branch from its ``<celem>`` element.

		:param element:            The ``<celem>`` element.
		:param parent:             The ``case`` statement the branch belongs to; it belongs to a scope.
		:returns:                  The branch.
		:raises CodeCoverageError: If the branch's file number isn't in the scope's source table, or it states none and
		                           the scope has no single file.
		"""
		return cls(
			parent._parent._ResolveFile(element),
			int(element.attrib["ln"]),
			int(element.attrib["st"]),
			int(element.attrib["hits"]),
			parent=parent
		)

	@readonly
	def Parent(self) -> Nullable[CaseStatement]:
		"""
		Read-only property to access the ``case`` statement the branch belongs to (:attr:`_parent`).

		:returns: The ``case`` statement; ``None`` if the branch belongs to none.
		"""
		return self._parent

	@readonly
	def Hits(self) -> int:
		"""
		Read-only property to access how often the branch was taken (:attr:`_hits`).

		:returns: The count.
		"""
		return self._hits


@export
class CaseStatement(metaclass=ExtendedType, slots=True):
	"""
	A ``<case>`` of a scope: a ``case`` statement, and how often each of its branches was taken.

	Each case item is a branch (``<celem>``, :class:`CaseBranch`); the ``case`` statement's line isn't stated.
	"""

	_parent:   Nullable[Scope]   #: The scope the ``case`` statement belongs to.
	_branches: list[CaseBranch]  #: The branches, in the order of the case items.

	def __init__(self, *, parent: Nullable[Scope] = None) -> None:
		"""
		Initialize the ``case`` statement, and append it to the ``case`` statements of its scope.

		Its branches are added by creating them with this ``case`` statement as their parent.

		:param parent:     Optional, the scope the ``case`` statement belongs to. Default: ``None``.
		:raises TypeError: If parameter ``parent`` isn't of type
		                   :class:`Scope`.
		"""
		if parent is not None and not isinstance(parent, Scope):
			ex = TypeError("Parameter 'parent' is not of type 'Scope'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(parent)}'.")
			raise ex

		self._parent =   parent
		self._branches = []

		if parent is not None:
			parent._caseStatements.append(self)

	@classmethod
	def Parse(cls, element: _Element, *, parent: Scope) -> Self:
		"""
		Parse a ``case`` statement and its branches from its ``<case>`` element.

		:param element:            The ``<case>`` element.
		:param parent:             The scope the ``case`` statement belongs to.
		:returns:                  The ``case`` statement.
		:raises CodeCoverageError: If a branch's file number isn't in the scope's source table, or it states none and the
		                           scope has no single file.
		:raises CodeCoverageError: If the ``case`` statement states other numbers of branches and taken branches than its
		                           branches have.
		"""
		caseStatement = cls(parent=parent)
		for branchElement in element.iterfind("celem"):
			CaseBranch.Parse(branchElement, parent=caseStatement)

		active = int(element.attrib["active"])
		hits =   int(element.attrib["hits"])
		if active != len(caseStatement._branches) or hits != caseStatement.TakenBranches:
			ex = CodeCoverageError(f"'<case>' in line {element.sourceline} states other figures than its branches have.")
			ex.add_note(f"Got '{hits}' of '{active}' branches taken, its branches have {caseStatement.TakenBranches} of "
			            f"{len(caseStatement._branches)}.")
			raise ex

		return caseStatement

	@readonly
	def Parent(self) -> Nullable[Scope]:
		"""
		Read-only property to access the scope the ``case`` statement belongs to (:attr:`_parent`).

		:returns: The scope; ``None`` if the ``case`` statement belongs to no scope.
		"""
		return self._parent

	@readonly
	def Branches(self) -> list[CaseBranch]:
		"""
		Read-only property to access the branches (:attr:`_branches`).

		:returns: The branches, in the order of the case items.
		"""
		return self._branches

	@readonly
	def TakenBranches(self) -> int:
		"""
		Read-only property to return the number of branches, which were taken.

		:returns: The number of branches with a positive :attr:`CaseBranch.Hits`.
		"""
		return sum(1 for branch in self._branches if branch._hits > 0)

	@readonly
	def EvaluationCount(self) -> int:
		"""
		Read-only property to return how often the ``case`` statement was evaluated.

		Each evaluation takes exactly one branch, so it is the sum of the branches' :attr:`CaseBranch.Hits`.

		:returns: The number of evaluations.
		"""
		return sum(branch._hits for branch in self._branches)


@export
class FSMState(metaclass=ExtendedType, slots=True):
	"""
	A ``<state>`` of a scope: a state of a finite state machine, and how often it was entered.
	"""

	_parent:     Nullable[Scope]  #: The scope the state belongs to.
	_name:       str              #: Name of the state.
	_file:       Nullable[Path]   #: Path of the source file, if known.
	_lineNumber: int              #: Line number of the state, counted from 1.
	_hits:       int              #: How often the state was entered.

	def __init__(
		self,
		name: str,
		file: Nullable[Path],
		lineNumber: int,
		hits: int,
		*,
		parent: Nullable[Scope] = None
	) -> None:
		"""
		Initialize the state, and append it to the states of its scope.

		:param name:        Name of the state.
		:param file:        Path of the source file, as the report states it; ``None``, if unknown.
		:param lineNumber:  Line number of the state, counted from 1.
		:param hits:        How often the state was entered.
		:param parent:      Optional, the scope the state belongs to. Default: ``None``.
		:raises ValueError: If parameter ``name`` is ``None``.
		:raises TypeError:  If parameter ``name`` isn't of type :class:`str`.
		:raises ValueError: If parameter ``name`` is empty.
		:raises TypeError:  If parameter ``file`` isn't of type :class:`~pathlib.Path`.
		:raises ValueError: If parameter ``lineNumber`` is ``None``.
		:raises TypeError:  If parameter ``lineNumber`` isn't of type :class:`int`.
		:raises ValueError: If parameter ``lineNumber`` is less than 1.
		:raises ValueError: If parameter ``hits`` is ``None``.
		:raises TypeError:  If parameter ``hits`` isn't of type :class:`int`.
		:raises ValueError: If parameter ``hits`` is negative.
		:raises TypeError:  If parameter ``parent`` isn't of type
		                    :class:`Scope`.
		"""
		if name is None:
			raise ValueError("Parameter 'name' is None.")
		elif not isinstance(name, str):
			ex = TypeError("Parameter 'name' is not of type 'str'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(name)}'.")
			raise ex
		elif name == "":
			raise ValueError("Parameter 'name' is empty.")

		if file is not None and not isinstance(file, Path):
			ex = TypeError("Parameter 'file' is not of type 'Path'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(file)}'.")
			raise ex

		if lineNumber is None:
			raise ValueError("Parameter 'lineNumber' is None.")
		elif not isinstance(lineNumber, int):
			ex = TypeError("Parameter 'lineNumber' is not of type 'int'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(lineNumber)}'.")
			raise ex
		elif lineNumber < 1:
			ex = ValueError("Parameter 'lineNumber' is less than 1.")
			ex.add_note(f"Got value '{lineNumber}'.")
			raise ex

		if hits is None:
			raise ValueError("Parameter 'hits' is None.")
		elif not isinstance(hits, int):
			ex = TypeError("Parameter 'hits' is not of type 'int'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(hits)}'.")
			raise ex
		elif hits < 0:
			ex = ValueError("Parameter 'hits' is negative.")
			ex.add_note(f"Got value '{hits}'.")
			raise ex

		if parent is not None and not isinstance(parent, Scope):
			ex = TypeError("Parameter 'parent' is not of type 'Scope'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(parent)}'.")
			raise ex

		self._parent =     parent
		self._name =       name
		self._file =       file
		self._lineNumber = lineNumber
		self._hits =       hits

		if parent is not None:
			parent._states.append(self)

	@classmethod
	def Parse(cls, element: _Element, *, parent: Scope) -> Self:
		"""
		Parse a state from its ``<state>`` element.

		A ``<state>`` names no file number: its file is the scope's, if the scope has a single file.

		:param element: The ``<state>`` element.
		:param parent:  The scope the state belongs to.
		:returns:       The state.
		"""
		file = next(iter(parent._files.values())) if len(parent._files) == 1 else None
		return cls(
			element.attrib["state"], file, int(element.attrib["ln"]), int(element.attrib["hits"]), parent=parent
		)

	@readonly
	def Parent(self) -> Nullable[Scope]:
		"""
		Read-only property to access the scope the state belongs to (:attr:`_parent`).

		:returns: The scope; ``None`` if the state belongs to no scope.
		"""
		return self._parent

	@readonly
	def Name(self) -> str:
		"""
		Read-only property to access the name of the state (:attr:`_name`).

		:returns: The state's name, as the enumeration of the state machine names it.
		"""
		return self._name

	@readonly
	def File(self) -> Nullable[Path]:
		"""
		Read-only property to access the path of the source file (:attr:`_file`).

		:returns: The path, as the report states it; ``None``, if the scope has several files.
		"""
		return self._file

	@readonly
	def LineNumber(self) -> int:
		"""
		Read-only property to access the line number of the state (:attr:`_lineNumber`).

		:returns: The line number, counted from 1.
		"""
		return self._lineNumber

	@readonly
	def Hits(self) -> int:
		"""
		Read-only property to access how often the state was entered (:attr:`_hits`).

		:returns: The count.
		"""
		return self._hits


@export
class FSMTransition(metaclass=ExtendedType, slots=True):
	"""
	A ``<trans>`` of a scope: a transition of a finite state machine from one state to another, and how often it was
	taken.
	"""

	_parent:     Nullable[Scope]  #: The scope the transition belongs to.
	_identifier: int              #: Number of the transition in its state machine, counted from 0.
	_fromState:  str              #: Name of the state the transition leaves.
	_toState:    str              #: Name of the state the transition enters.
	_file:       Nullable[Path]   #: Path of the source file, if known.
	_lineNumber: int              #: Line number of the transition, counted from 1.
	_hits:       int              #: How often the transition was taken.

	def __init__(
		self,
		identifier: int,
		fromState: str,
		toState: str,
		file: Nullable[Path],
		lineNumber: int,
		hits: int,
		*,
		parent: Nullable[Scope] = None
	) -> None:
		"""
		Initialize the transition, and append it to the transitions of its scope.

		:param identifier:  Number of the transition in its state machine, counted from 0.
		:param fromState:   Name of the state the transition leaves.
		:param toState:     Name of the state the transition enters.
		:param file:        Path of the source file, as the report states it; ``None``, if unknown.
		:param lineNumber:  Line number of the transition, counted from 1.
		:param hits:        How often the transition was taken.
		:param parent:      Optional, the scope the transition belongs to. Default: ``None``.
		:raises ValueError: If parameter ``identifier`` is ``None``.
		:raises TypeError:  If parameter ``identifier`` isn't of type :class:`int`.
		:raises ValueError: If parameter ``identifier`` is negative.
		:raises ValueError: If parameter ``fromState`` is ``None``.
		:raises TypeError:  If parameter ``fromState`` isn't of type :class:`str`.
		:raises ValueError: If parameter ``fromState`` is empty.
		:raises ValueError: If parameter ``toState`` is ``None``.
		:raises TypeError:  If parameter ``toState`` isn't of type :class:`str`.
		:raises ValueError: If parameter ``toState`` is empty.
		:raises TypeError:  If parameter ``file`` isn't of type :class:`~pathlib.Path`.
		:raises ValueError: If parameter ``lineNumber`` is ``None``.
		:raises TypeError:  If parameter ``lineNumber`` isn't of type :class:`int`.
		:raises ValueError: If parameter ``lineNumber`` is less than 1.
		:raises ValueError: If parameter ``hits`` is ``None``.
		:raises TypeError:  If parameter ``hits`` isn't of type :class:`int`.
		:raises ValueError: If parameter ``hits`` is negative.
		:raises TypeError:  If parameter ``parent`` isn't of type
		                    :class:`Scope`.
		"""
		if identifier is None:
			raise ValueError("Parameter 'identifier' is None.")
		elif not isinstance(identifier, int):
			ex = TypeError("Parameter 'identifier' is not of type 'int'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(identifier)}'.")
			raise ex
		elif identifier < 0:
			ex = ValueError("Parameter 'identifier' is negative.")
			ex.add_note(f"Got value '{identifier}'.")
			raise ex

		if fromState is None:
			raise ValueError("Parameter 'fromState' is None.")
		elif not isinstance(fromState, str):
			ex = TypeError("Parameter 'fromState' is not of type 'str'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(fromState)}'.")
			raise ex
		elif fromState == "":
			raise ValueError("Parameter 'fromState' is empty.")

		if toState is None:
			raise ValueError("Parameter 'toState' is None.")
		elif not isinstance(toState, str):
			ex = TypeError("Parameter 'toState' is not of type 'str'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(toState)}'.")
			raise ex
		elif toState == "":
			raise ValueError("Parameter 'toState' is empty.")

		if file is not None and not isinstance(file, Path):
			ex = TypeError("Parameter 'file' is not of type 'Path'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(file)}'.")
			raise ex

		if lineNumber is None:
			raise ValueError("Parameter 'lineNumber' is None.")
		elif not isinstance(lineNumber, int):
			ex = TypeError("Parameter 'lineNumber' is not of type 'int'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(lineNumber)}'.")
			raise ex
		elif lineNumber < 1:
			ex = ValueError("Parameter 'lineNumber' is less than 1.")
			ex.add_note(f"Got value '{lineNumber}'.")
			raise ex

		if hits is None:
			raise ValueError("Parameter 'hits' is None.")
		elif not isinstance(hits, int):
			ex = TypeError("Parameter 'hits' is not of type 'int'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(hits)}'.")
			raise ex
		elif hits < 0:
			ex = ValueError("Parameter 'hits' is negative.")
			ex.add_note(f"Got value '{hits}'.")
			raise ex

		if parent is not None and not isinstance(parent, Scope):
			ex = TypeError("Parameter 'parent' is not of type 'Scope'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(parent)}'.")
			raise ex

		self._parent =     parent
		self._identifier = identifier
		self._fromState =  fromState
		self._toState =    toState
		self._file =       file
		self._lineNumber = lineNumber
		self._hits =       hits

		if parent is not None:
			parent._transitions.append(self)

	@classmethod
	def Parse(cls, element: _Element, *, parent: Scope) -> Self:
		"""
		Parse a transition from its ``<trans>`` element, whose attribute ``state`` names both states.

		A ``<trans>`` names no file number: its file is the scope's, if the scope has a single file.

		:param element:            The ``<trans>`` element.
		:param parent:             The scope the transition belongs to.
		:returns:                  The transition.
		:raises CodeCoverageError: If attribute ``state`` doesn't name two states separated by ``->``. |br|
		                           Questa writes it as ``<state> -> <state>``.
		"""
		fromState, separator, toState = element.attrib["state"].partition(" -> ")
		if separator == "" or fromState == "" or toState == "":
			ex = CodeCoverageError(f"'<trans>' in line {element.sourceline} doesn't name the states it connects.")
			ex.add_note(f"Got state='{element.attrib['state']}'.")
			ex.add_note("Questa writes it as '<state> -> <state>'.")
			raise ex

		file = next(iter(parent._files.values())) if len(parent._files) == 1 else None
		return cls(
			int(element.attrib["tid"]),
			fromState,
			toState,
			file,
			int(element.attrib["ln"]),
			int(element.attrib["hits"]),
			parent=parent
		)

	@readonly
	def Parent(self) -> Nullable[Scope]:
		"""
		Read-only property to access the scope the transition belongs to (:attr:`_parent`).

		:returns: The scope; ``None`` if the transition belongs to no scope.
		"""
		return self._parent

	@readonly
	def Identifier(self) -> int:
		"""
		Read-only property to access the number of the transition in its state machine (:attr:`_identifier`).

		:returns: The number, counted from 0.
		"""
		return self._identifier

	@readonly
	def FromState(self) -> str:
		"""
		Read-only property to access the name of the state the transition leaves (:attr:`_fromState`).

		:returns: The state's name.
		"""
		return self._fromState

	@readonly
	def ToState(self) -> str:
		"""
		Read-only property to access the name of the state the transition enters (:attr:`_toState`).

		:returns: The state's name.
		"""
		return self._toState

	@readonly
	def File(self) -> Nullable[Path]:
		"""
		Read-only property to access the path of the source file (:attr:`_file`).

		:returns: The path, as the report states it; ``None``, if the scope has several files.
		"""
		return self._file

	@readonly
	def LineNumber(self) -> int:
		"""
		Read-only property to access the line number of the transition (:attr:`_lineNumber`).

		:returns: The line number, counted from 1.
		"""
		return self._lineNumber

	@readonly
	def Hits(self) -> int:
		"""
		Read-only property to access how often the transition was taken (:attr:`_hits`).

		:returns: The count.
		"""
		return self._hits


@export
class Scope(StatisticsMixin, slots=True):
	"""
	Base-class of the scopes: an instance, a design unit or a source file, with its coverage statistics, its source files
	and its statements.
	"""

	_parent:         Nullable[Report]     #: The report the scope belongs to.
	_files:          dict[int, Path]      #: The source files, by the number the report gives them.
	_statements:     list[Statement]      #: The statements.
	_ifStatements:   list[IfStatement]    #: The ``if`` statements.
	_caseStatements: list[CaseStatement]  #: The ``case`` statements.
	_states:         list[FSMState]       #: The states of finite state machines.
	_transitions:    list[FSMTransition]  #: The transitions of finite state machines.

	def __init__(self, files: Nullable[Mapping[int, Path]] = None, *, parent: Nullable[Report] = None) -> None:
		"""
		Initialize the scope, and append it to the scopes of its report.

		Its coverage statistics and coverage items are added by creating them with this scope as their parent.

		:param files:       Optional, the source files, by the number the report gives them. Default: ``None``.
		:param parent:      Optional, the report the scope belongs to; the scope is appended to its scopes. Default:
		                    ``None``.
		:raises TypeError:  If parameter ``files`` isn't a mapping.
		:raises TypeError:  If parameter ``files`` contains a key not of type :class:`int`.
		:raises ValueError: If parameter ``files`` contains a negative key.
		:raises TypeError:  If parameter ``files`` contains a value not of type :class:`~pathlib.Path`.
		:raises TypeError:  If parameter ``parent`` isn't of type
		                    :class:`Report`.
		"""
		super().__init__()

		self._files = {}
		if files is not None:
			if not isinstance(files, Mapping):
				ex = TypeError("Parameter 'files' is not a mapping.")
				ex.add_note(f"Got type '{getFullyQualifiedName(files)}'.")
				raise ex

			for fileNumber, path in files.items():
				if not isinstance(fileNumber, int):
					ex = TypeError("Parameter 'files' contains a key not of type 'int'.")
					ex.add_note(f"Got type '{getFullyQualifiedName(fileNumber)}'.")
					raise ex
				elif fileNumber < 0:
					ex = ValueError("Parameter 'files' contains a negative key.")
					ex.add_note(f"Got value '{fileNumber}'.")
					raise ex
				elif not isinstance(path, Path):
					ex = TypeError("Parameter 'files' contains a value not of type 'Path'.")
					ex.add_note(f"Got type '{getFullyQualifiedName(path)}'.")
					raise ex

				self._files[fileNumber] = path

		if parent is not None and not isinstance(parent, Report):
			ex = TypeError("Parameter 'parent' is not of type 'Report'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(parent)}'.")
			raise ex

		self._parent =         parent
		self._statements =     []
		self._ifStatements =   []
		self._caseStatements = []
		self._states =         []
		self._transitions =    []

		if parent is not None:
			parent._scopes.append(self)

	@staticmethod
	def _ParseSourceTable(element: _Element) -> dict[int, Path]:
		"""
		Parse the source files of a scope's ``<sourceTable>``.

		:param element: The scope's element.
		:returns:       The source files, by their number; none, if the scope has no source table.
		"""
		return {
			int(fileMap.attrib["fn"]): Path(fileMap.attrib["path"]) for fileMap in element.iterfind("sourceTable/fileMap")
		}

	def _ParseItems(self, element: _Element) -> None:
		"""
		Parse the coverage statistics and the coverage items of the scope from its element.

		:param element:            The scope's element.
		:raises CodeCoverageError: If a coverage statistics element states more hit items than items.
		:raises CodeCoverageError: If the scope states a kind of coverage statistics twice.
		:raises CodeCoverageError: If a coverage item names an unknown file number, or none in a scope of several files.
		:raises CodeCoverageError: If an ``if`` or ``case`` statement states other figures than its branches have.
		:raises CodeCoverageError: If a transition's name doesn't name its two states.
		"""
		self._ParseStatistics(element)
		for child in element:
			if child.tag == "stmt":
				Statement.Parse(child, parent=self)
			elif child.tag == "if":
				IfStatement.Parse(child, parent=self)
			elif child.tag == "case":
				CaseStatement.Parse(child, parent=self)
			elif child.tag == "state":
				FSMState.Parse(child, parent=self)
			elif child.tag == "trans":
				FSMTransition.Parse(child, parent=self)

	def _ResolveFile(self, element: _Element) -> Path:
		"""
		Return the source file a coverage item's element names by its file number.

		An element without file number is in the scope's file: the path of a ``<fileData>``, or the only file of the source
		table.

		:param element:            The coverage item's element, e.g. a ``<stmt>``.
		:returns:                  The source file's path, as the report states it.
		:raises CodeCoverageError: If the file number isn't in the scope's source table.
		:raises CodeCoverageError: If the element names no file number, and the scope has no single file.
		"""
		if (fileNumber := element.attrib.get("fn")) is not None:
			if (file := self._files.get(int(fileNumber))) is None:
				ex = CodeCoverageError(
					f"'<{element.tag}>' in line {element.sourceline} names file number '{fileNumber}', which is unknown."
				)
				ex.add_note(f"Known file numbers: {', '.join(str(number) for number in self._files) or 'none'}.")
				raise ex

			return file
		elif isinstance(self, FileData):
			return self._path
		elif len(self._files) == 1:
			return next(iter(self._files.values()))

		ex = CodeCoverageError(f"'<{element.tag}>' in line {element.sourceline} names no file number.")
		ex.add_note(f"Its scope names {len(self._files)} files.")
		raise ex

	@readonly
	def Parent(self) -> Nullable[Report]:
		"""
		Read-only property to access the report the scope belongs to (:attr:`_parent`).

		:returns: The report; ``None`` if the scope belongs to none.
		"""
		return self._parent

	@readonly
	def Files(self) -> dict[int, Path]:
		"""
		Read-only property to access the source files (:attr:`_files`).

		:returns: The source files, by the number the report gives them; none, if the report has no details.
		"""
		return self._files

	@readonly
	def Statements(self) -> list[Statement]:
		"""
		Read-only property to access the statements (:attr:`_statements`).

		:returns: The statements, in the order the report lists them; none, if the report has no details.
		"""
		return self._statements

	@readonly
	def IfStatements(self) -> list[IfStatement]:
		"""
		Read-only property to access the ``if`` statements (:attr:`_ifStatements`).

		:returns: The ``if`` statements, in the order the report lists them; none, if the report has no details.
		"""
		return self._ifStatements

	@readonly
	def CaseStatements(self) -> list[CaseStatement]:
		"""
		Read-only property to access the ``case`` statements (:attr:`_caseStatements`).

		:returns: The ``case`` statements, in the order the report lists them; none, if the report has no details.
		"""
		return self._caseStatements

	@readonly
	def States(self) -> list[FSMState]:
		"""
		Read-only property to access the states of finite state machines (:attr:`_states`).

		:returns: The states, in the order the report lists them; none, if the report has no details.
		"""
		return self._states

	@readonly
	def Transitions(self) -> list[FSMTransition]:
		"""
		Read-only property to access the transitions of finite state machines (:attr:`_transitions`).

		:returns: The transitions, in the order the report lists them; none, if the report has no details.
		"""
		return self._transitions


@export
class InstanceData(Scope):
	"""
	An ``<instanceData>``: an instance of a design unit, or a package.
	"""

	_path:          str            #: Hierarchical path of the instance.
	_designUnit:    str            #: Name of the design unit.
	_secondaryUnit: Nullable[str]  #: Name of the secondary unit (the architecture), if the design unit has one.

	def __init__(
		self,
		path: str,
		designUnit: str,
		secondaryUnit: Nullable[str] = None,
		files: Nullable[Mapping[int, Path]] = None,
		*,
		parent: Nullable[Report] = None
	) -> None:
		"""
		Initialize the instance, and append it to the scopes of its report.

		:param path:          Hierarchical path of the instance, separated by ``/``.
		:param designUnit:    Name of the design unit.
		:param secondaryUnit: Optional, name of the secondary unit (the architecture). Default: ``None``.
		:param files:         Optional, the source files, by the number the report gives them. Default: ``None``.
		:param parent:        Optional, the report the instance belongs to. Default: ``None``.
		:raises TypeError:    If parameter ``files`` isn't a mapping.
		:raises TypeError:    If parameter ``files`` contains a key not of type :class:`int`.
		:raises ValueError:   If parameter ``files`` contains a negative key.
		:raises TypeError:    If parameter ``files`` contains a value not of type :class:`~pathlib.Path`.
		:raises TypeError:    If parameter ``parent`` isn't of type
		                      :class:`Report`.
		:raises ValueError:   If parameter ``path`` is ``None``.
		:raises TypeError:    If parameter ``path`` isn't of type :class:`str`.
		:raises ValueError:   If parameter ``path`` is empty.
		:raises ValueError:   If parameter ``designUnit`` is ``None``.
		:raises TypeError:    If parameter ``designUnit`` isn't of type :class:`str`.
		:raises ValueError:   If parameter ``designUnit`` is empty.
		:raises TypeError:    If parameter ``secondaryUnit`` isn't of type :class:`str`.
		:raises ValueError:   If parameter ``secondaryUnit`` is empty.
		"""
		super().__init__(files, parent=parent)

		if path is None:
			raise ValueError("Parameter 'path' is None.")
		elif not isinstance(path, str):
			ex = TypeError("Parameter 'path' is not of type 'str'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(path)}'.")
			raise ex
		elif path == "":
			raise ValueError("Parameter 'path' is empty.")

		if designUnit is None:
			raise ValueError("Parameter 'designUnit' is None.")
		elif not isinstance(designUnit, str):
			ex = TypeError("Parameter 'designUnit' is not of type 'str'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(designUnit)}'.")
			raise ex
		elif designUnit == "":
			raise ValueError("Parameter 'designUnit' is empty.")

		if secondaryUnit is not None:
			if not isinstance(secondaryUnit, str):
				ex = TypeError("Parameter 'secondaryUnit' is not of type 'str'.")
				ex.add_note(f"Got type '{getFullyQualifiedName(secondaryUnit)}'.")
				raise ex
			elif secondaryUnit == "":
				raise ValueError("Parameter 'secondaryUnit' is empty.")

		self._path =          path
		self._designUnit =    designUnit
		self._secondaryUnit = secondaryUnit

	@classmethod
	def Parse(cls, element: _Element, *, parent: Nullable[Report] = None) -> Self:
		"""
		Parse an instance, its source files, coverage statistics and statements from its ``<instanceData>`` element.

		:param element:            The ``<instanceData>`` element.
		:param parent:             Optional, the report the instance belongs to. Default: ``None``.
		:returns:                  The instance.
		:raises CodeCoverageError: If a coverage statistics element states more hit items than items.
		:raises CodeCoverageError: If the instance states a kind of coverage statistics twice.
		:raises CodeCoverageError: If a coverage item names an unknown file number, or none in an instance of several
		                           files.
		"""
		instance = cls(
			element.attrib["path"],
			element.attrib["du"],
			element.attrib.get("sec"),
			cls._ParseSourceTable(element),
			parent=parent
		)
		instance._ParseItems(element)
		return instance

	@readonly
	def Path(self) -> str:
		"""
		Read-only property to access the hierarchical path of the instance (:attr:`_path`).

		:returns: The path, separated by ``/``.
		"""
		return self._path

	@readonly
	def DesignUnit(self) -> str:
		"""
		Read-only property to access the name of the design unit (:attr:`_designUnit`).

		:returns: The design unit's name, as Questa writes it: in lower case for VHDL.
		"""
		return self._designUnit

	@readonly
	def SecondaryUnit(self) -> Nullable[str]:
		"""
		Read-only property to access the name of the secondary unit (:attr:`_secondaryUnit`).

		:returns: The architecture's name, or ``None`` - e.g. for a package.
		"""
		return self._secondaryUnit


@export
class DesignUnitData(Scope):
	"""
	A ``<DuData>``: a design unit, its instances' coverage combined.
	"""

	_designUnit:    str            #: Name of the design unit.
	_secondaryUnit: Nullable[str]  #: Name of the secondary unit (the architecture), if the design unit has one.

	def __init__(
		self,
		designUnit: str,
		secondaryUnit: Nullable[str] = None,
		files: Nullable[Mapping[int, Path]] = None,
		*,
		parent: Nullable[Report] = None
	) -> None:
		"""
		Initialize the design unit, and append it to the scopes of its report.

		:param designUnit:    Name of the design unit.
		:param secondaryUnit: Optional, name of the secondary unit (the architecture). Default: ``None``.
		:param files:         Optional, the source files, by the number the report gives them. Default: ``None``.
		:param parent:        Optional, the report the design unit belongs to. Default: ``None``.
		:raises TypeError:    If parameter ``files`` isn't a mapping.
		:raises TypeError:    If parameter ``files`` contains a key not of type :class:`int`.
		:raises ValueError:   If parameter ``files`` contains a negative key.
		:raises TypeError:    If parameter ``files`` contains a value not of type :class:`~pathlib.Path`.
		:raises TypeError:    If parameter ``parent`` isn't of type
		                      :class:`Report`.
		:raises ValueError:   If parameter ``designUnit`` is ``None``.
		:raises TypeError:    If parameter ``designUnit`` isn't of type :class:`str`.
		:raises ValueError:   If parameter ``designUnit`` is empty.
		:raises TypeError:    If parameter ``secondaryUnit`` isn't of type :class:`str`.
		:raises ValueError:   If parameter ``secondaryUnit`` is empty.
		"""
		super().__init__(files, parent=parent)

		if designUnit is None:
			raise ValueError("Parameter 'designUnit' is None.")
		elif not isinstance(designUnit, str):
			ex = TypeError("Parameter 'designUnit' is not of type 'str'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(designUnit)}'.")
			raise ex
		elif designUnit == "":
			raise ValueError("Parameter 'designUnit' is empty.")

		if secondaryUnit is not None:
			if not isinstance(secondaryUnit, str):
				ex = TypeError("Parameter 'secondaryUnit' is not of type 'str'.")
				ex.add_note(f"Got type '{getFullyQualifiedName(secondaryUnit)}'.")
				raise ex
			elif secondaryUnit == "":
				raise ValueError("Parameter 'secondaryUnit' is empty.")

		self._designUnit =    designUnit
		self._secondaryUnit = secondaryUnit

	@classmethod
	def Parse(cls, element: _Element, *, parent: Nullable[Report] = None) -> Self:
		"""
		Parse a design unit, its source files, coverage statistics and statements from its ``<DuData>`` element.

		:param element:            The ``<DuData>`` element.
		:param parent:             Optional, the report the design unit belongs to. Default: ``None``.
		:returns:                  The design unit.
		:raises CodeCoverageError: If a coverage statistics element states more hit items than items.
		:raises CodeCoverageError: If the design unit states a kind of coverage statistics twice.
		:raises CodeCoverageError: If a coverage item names an unknown file number, or none in a design unit of several
		                           files.
		"""
		designUnit = cls(element.attrib["du"], element.attrib.get("sec"), cls._ParseSourceTable(element), parent=parent)
		designUnit._ParseItems(element)
		return designUnit

	@readonly
	def DesignUnit(self) -> str:
		"""
		Read-only property to access the name of the design unit (:attr:`_designUnit`).

		:returns: The design unit's name, as Questa writes it: in lower case for VHDL.
		"""
		return self._designUnit

	@readonly
	def SecondaryUnit(self) -> Nullable[str]:
		"""
		Read-only property to access the name of the secondary unit (:attr:`_secondaryUnit`).

		:returns: The architecture's name, or ``None`` - e.g. for a package.
		"""
		return self._secondaryUnit


@export
class FileData(Scope):
	"""
	A ``<fileData>``: a source file.
	"""

	_path: _Path  #: Path of the source file, as the report states it.

	def __init__(
		self,
		path: Path,
		files: Nullable[Mapping[int, Path]] = None,
		*,
		parent: Nullable[Report] = None
	) -> None:
		"""
		Initialize the source file, and append it to the scopes of its report.

		:param path:        Path of the source file, as the report states it.
		:param files:       Optional, the source files, by the number the report gives them. Default: ``None``.
		:param parent:      Optional, the report the source file belongs to. Default: ``None``.
		:raises TypeError:  If parameter ``files`` isn't a mapping.
		:raises TypeError:  If parameter ``files`` contains a key not of type :class:`int`.
		:raises ValueError: If parameter ``files`` contains a negative key.
		:raises TypeError:  If parameter ``files`` contains a value not of type :class:`~pathlib.Path`.
		:raises TypeError:  If parameter ``parent`` isn't of type
		                    :class:`Report`.
		:raises ValueError: If parameter ``path`` is ``None``.
		:raises TypeError:  If parameter ``path`` isn't of type :class:`~pathlib.Path`.
		"""
		super().__init__(files, parent=parent)

		if path is None:
			raise ValueError("Parameter 'path' is None.")
		elif not isinstance(path, Path):
			ex = TypeError("Parameter 'path' is not of type 'Path'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(path)}'.")
			raise ex

		self._path = path

	@classmethod
	def Parse(cls, element: _Element, *, parent: Nullable[Report] = None) -> Self:
		"""
		Parse a source file, its coverage statistics and statements from its ``<fileData>`` element.

		:param element:            The ``<fileData>`` element.
		:param parent:             Optional, the report the source file belongs to. Default: ``None``.
		:returns:                  The source file.
		:raises CodeCoverageError: If a coverage statistics element states more hit items than items.
		:raises CodeCoverageError: If the source file states a kind of coverage statistics twice.
		:raises CodeCoverageError: If a coverage item names an unknown file number.
		"""
		fileData = cls(Path(element.attrib["path"]), cls._ParseSourceTable(element), parent=parent)
		fileData._ParseItems(element)
		return fileData

	@readonly
	def Path(self) -> _Path:
		"""
		Read-only property to access the path of the source file (:attr:`_path`).

		:returns: The path, as the report states it.
		"""
		return self._path


@export
class Totals(StatisticsMixin):
	"""
	A summary record of a report - ``<summaryByFile>`` or ``<summaryByInstance>`` -: the coverage statistics of all its
	files or instances together.
	"""

	_parent: Nullable[Report]  #: The report the summary record belongs to.
	_mode:   ReportMode        #: What the summary record sums up: files or instances.
	_count:  int               #: Number of files or instances summed up.

	def __init__(self, mode: ReportMode, count: int, *, parent: Nullable[Report] = None) -> None:
		"""
		Initialize the summary record, and add it to the summary records of its report.

		Its coverage statistics are added by creating them with this summary record as their parent.

		:param mode:               What the summary record sums up: :attr:`ReportMode.ByFile` or
		                           :attr:`ReportMode.ByInstance`.
		:param count:              Number of files or instances summed up.
		:param parent:             Optional, the report the summary record belongs to; it is added to its summary records
		                           by :attr:`Mode`. Default: ``None``.
		:raises ValueError:        If parameter ``mode`` is ``None``.
		:raises TypeError:         If parameter ``mode`` isn't of type :class:`ReportMode`.
		:raises ValueError:        If parameter ``mode`` is :attr:`ReportMode.ByDesignUnit`.
		:raises ValueError:        If parameter ``count`` is ``None``.
		:raises TypeError:         If parameter ``count`` isn't of type :class:`int`.
		:raises ValueError:        If parameter ``count`` is negative.
		:raises TypeError:         If parameter ``parent`` isn't of type
		                           :class:`Report`.
		:raises CodeCoverageError: If the report already has a summary record of this mode.
		"""
		super().__init__()

		if mode is None:
			raise ValueError("Parameter 'mode' is None.")
		elif not isinstance(mode, ReportMode):
			ex = TypeError("Parameter 'mode' is not of type 'ReportMode'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(mode)}'.")
			raise ex
		elif mode is ReportMode.ByDesignUnit:
			ex = ValueError("Parameter 'mode' is not 'ByFile' or 'ByInstance'.")
			ex.add_note(f"Got value '{mode.name}'.")
			raise ex

		if count is None:
			raise ValueError("Parameter 'count' is None.")
		elif not isinstance(count, int):
			ex = TypeError("Parameter 'count' is not of type 'int'.")
			ex.add_note(f"Got type '{getFullyQualifiedName(count)}'.")
			raise ex
		elif count < 0:
			ex = ValueError("Parameter 'count' is negative.")
			ex.add_note(f"Got value '{count}'.")
			raise ex

		if parent is not None:
			if not isinstance(parent, Report):
				ex = TypeError("Parameter 'parent' is not of type 'Report'.")
				ex.add_note(f"Got type '{getFullyQualifiedName(parent)}'.")
				raise ex
			elif mode in parent._totals:
				raise CodeCoverageError(f"Summary record '{mode}' is stated twice.")

		self._parent = parent
		self._mode =   mode
		self._count =  count

		if parent is not None:
			parent._totals[mode] = self

	@classmethod
	def Parse(cls, element: _Element, *, parent: Nullable[Report] = None) -> Self:
		"""
		Parse a summary record and its coverage statistics from its ``<summaryByFile>`` or ``<summaryByInstance>``
		element.

		:param element:            The summary record's element.
		:param parent:             Optional, the report the summary record belongs to. Default: ``None``.
		:returns:                  The summary record.
		:raises CodeCoverageError: If a coverage statistics element states more hit items than items.
		"""
		if element.tag == "summaryByFile":
			totals = cls(ReportMode.ByFile, int(element.attrib["files"]), parent=parent)
		else:
			totals = cls(ReportMode.ByInstance, int(element.attrib["instances"]), parent=parent)

		totals._ParseStatistics(element)
		return totals

	@readonly
	def Parent(self) -> Nullable[Report]:
		"""
		Read-only property to access the report the summary record belongs to (:attr:`_parent`).

		:returns: The report; ``None`` if the summary record belongs to none.
		"""
		return self._parent

	@readonly
	def Mode(self) -> ReportMode:
		"""
		Read-only property to access what the summary record sums up (:attr:`_mode`).

		:returns: :attr:`ReportMode.ByFile` or :attr:`ReportMode.ByInstance`.
		"""
		return self._mode

	@readonly
	def Count(self) -> int:
		"""
		Read-only property to access the number of files or instances summed up (:attr:`_count`).

		:returns: The number of files or instances.
		"""
		return self._count


_Totals = Totals


@export
class Report(metaclass=ExtendedType, mixin=True):
	"""
	The root element ``<coverage_report>`` and its ``<code_coverage_report>``: the Questa version and the command, which
	wrote it, its mode, the summary records and the scopes.

	The root of the format's model: a summary record or a scope names it as its parent.
	"""

	_toolVersion:    Nullable[str]               #: Version of Questa, which wrote the report.
	_command:        Nullable[str]               #: The command, which wrote the report.
	_mode:           Nullable[ReportMode]        #: How the report groups its coverage data.
	_hasLineDetails: bool                        #: Whether the report has details: source files and coverage items.
	_totals:         dict[ReportMode, _Totals]   #: The summary records, by what they sum up.
	_scopes:         list[Scope]                 #: The scopes.

	def __init__(self) -> None:
		"""
		Initialize an empty report.
		"""
		self._toolVersion =    None
		self._command =        None
		self._mode =           None
		self._hasLineDetails = False
		self._totals =         {}
		self._scopes =         []

	@readonly
	def ToolVersion(self) -> Nullable[str]:
		"""
		Read-only property to access the version of Questa, which wrote the report (:attr:`_toolVersion`).

		Questa states its version since a release between 10.x and 2023.3, e.g. ``2026.2``.

		:returns: The version, as the report states it; ``None`` if the report doesn't state it, or before it was converted.
		"""
		return self._toolVersion

	@readonly
	def Command(self) -> Nullable[str]:
		"""
		Read-only property to access the command, which wrote the report (:attr:`_command`).

		:returns: The command, as the report states it; ``None`` if the report doesn't state it, or before it was converted.
		"""
		return self._command

	@readonly
	def Mode(self) -> Nullable[ReportMode]:
		"""
		Read-only property to access how the report groups its coverage data (:attr:`_mode`).

		:returns: The mode; ``None`` before the report was converted.
		"""
		return self._mode

	@readonly
	def HasLineDetails(self) -> bool:
		"""
		Read-only property to access whether the report has details (:attr:`_hasLineDetails`).

		A report written with ``-details`` names the source files of its scopes and lists their coverage items; it states
		``lines="1"``.

		:returns: ``True``, if the report states details.
		"""
		return self._hasLineDetails

	@readonly
	def Totals(self) -> dict[ReportMode, _Totals]:
		"""
		Read-only property to access the summary records (:attr:`_totals`).

		:returns: The summary records, by what they sum up; none, if the report has no summary records.
		"""
		return self._totals

	@readonly
	def Scopes(self) -> list[Scope]:
		"""
		Read-only property to access the scopes (:attr:`_scopes`).

		:returns: The scopes, in the order the report lists them.
		"""
		return self._scopes

	def IterateStatements(self) -> Generator[Statement, None, None]:
		"""
		Iterate the statements of all scopes.

		:returns: A generator of the statements, scope by scope, in the order the report lists them.
		"""
		for scope in self._scopes:
			yield from scope._statements


@export
class Document(cc_Document, Report):
	"""
	A QuestaSim coverage report XML file: read into the format's model, and converted to the common model.
	"""

	_xmlDocument: Nullable[_ElementTree]  #: The parsed and validated XML document, after :meth:`Analyze`.

	def __init__(self, xmlReportFile: Path, analyzeAndConvert: bool = False) -> None:
		"""
		Initialize the report, and optionally read it.

		:param xmlReportFile:     Path to the coverage report XML file.
		:param analyzeAndConvert: Optional, if true, analyze the file and convert its content. Default: ``False``.
		"""
		super().__init__(xmlReportFile)
		Report.__init__(self)

		self._xmlDocument = None

		if analyzeAndConvert:
			self.Analyze()
			self.Convert()

	def Analyze(self) -> None:
		"""
		Parse the XML file, check its root element, and validate the file against the XML schema (:data:`SCHEMA`).

		:raises CodeCoverageError: If the file doesn't exist.
		:raises CodeCoverageError: If the file can't be read.
		:raises CodeCoverageError: If the file isn't well-formed XML.
		:raises CodeCoverageError: If the root element isn't ``<coverage_report>``.
		:raises CodeCoverageError: If the report is a functional coverage report. |br|
		                           Write the report without '-cvg', '-directive' and '-assert'.
		:raises CodeCoverageError: If the XML schema can't be located or parsed.
		:raises CodeCoverageError: If the file isn't valid according to the XML schema.
		"""
		if not self._path.exists():
			raise CodeCoverageError(f"QuestaSim coverage report '{self._path}' does not exist.") \
				from FileNotFoundError(f"File '{self._path}' not found.")

		with Stopwatch() as sw:
			try:
				content = self._path.read_bytes()
			except OSError as ex:
				raise CodeCoverageError(f"Couldn't read QuestaSim coverage report '{self._path}'.") from ex

			try:
				xmlDocument = parse(BytesIO(content), XMLParser(ns_clean=True), base_url=str(self._path))
			except XMLSyntaxError as ex:
				raise CodeCoverageError(f"XML syntax error in QuestaSim coverage report '{self._path}'.") from ex

			rootElement: _Element = xmlDocument.getroot()
			if rootElement.tag != "coverage_report":
				ex = CodeCoverageError(f"Root element of '{self._path}' is not '<coverage_report>'.")
				ex.add_note(f"Got root element '<{rootElement.tag}>'.")
				raise ex
			elif rootElement.find("functional_coverage_report") is not None:
				ex = CodeCoverageError(f"'{self._path}' is a functional coverage report, not a code coverage report.")
				ex.add_note("Write the report without '-cvg', '-directive' and '-assert'.")
				raise ex

			try:
				schemaResourceFile = getResourceFile(Resources, SCHEMA)
			except ToolingException as ex:
				raise CodeCoverageError(f"Couldn't locate XML Schema '{SCHEMA}' in package resources.") from ex

			try:
				xmlSchema = XMLSchema(parse(schemaResourceFile, XMLParser(ns_clean=True)))
			except (XMLSyntaxError, XMLSchemaParseError) as ex:
				raise CodeCoverageError(f"Error while parsing XML Schema '{SCHEMA}'.") from ex

			if not xmlSchema.validate(xmlDocument):
				ex = CodeCoverageError(f"Validation error for '{self._path}' using XSD schema '{SCHEMA}'.")
				for logEntry in xmlSchema.error_log:
					ex.add_note(str(logEntry))
				raise ex

			self._xmlDocument = xmlDocument

		self._analysisDuration = sw.Duration

	def Convert(self) -> None:
		"""
		Convert the parsed and validated XML document to the format's model.

		:raises CodeCoverageError: If the XML file was not analyzed before. |br|
		                           Call 'Document.Analyze()' or create the document using
		                           'Document(path, analyzeAndConvert=True)'.
		:raises CodeCoverageError: If the report doesn't state exactly one mode.
		:raises CodeCoverageError: If a coverage statistics element states more hit items than items.
		:raises CodeCoverageError: If a scope or summary record states a kind of coverage statistics twice.
		:raises CodeCoverageError: If a statement names an unknown file number, or none in a scope of several files.
		"""
		if self._xmlDocument is None:
			ex = CodeCoverageError(
				f"QuestaSim coverage report '{self._path}' needs to be read and analyzed by an XML parser."
			)
			ex.add_note("Call 'Document.Analyze()' or create the document using 'Document(path, analyzeAndConvert=True)'.")
			raise ex

		with Stopwatch() as sw:
			root: _Element = self._xmlDocument.getroot()
			codeCoverage: _Element = root.find("code_coverage_report")

			modes = [mode for mode in ReportMode if codeCoverage.attrib.get(mode.value) == "1"]
			if len(modes) != 1:
				ex = CodeCoverageError(f"QuestaSim coverage report '{self._path}' doesn't state exactly one mode.")
				ex.add_note(f"Got modes: {', '.join(mode.value for mode in modes) or 'none'}.")
				ex.add_note(f"One of the attributes {', '.join(mode.value for mode in ReportMode)} is '1'.")
				raise ex

			self._toolVersion =    root.attrib.get("questa_version")
			self._command =        root.attrib.get("command")
			self._mode =           modes[0]
			self._hasLineDetails = codeCoverage.attrib.get("lines") == "1"

			for element in codeCoverage:
				if element.tag in ("summaryByFile", "summaryByInstance"):
					Totals.Parse(element, parent=self)
				elif element.tag == "instanceData":
					InstanceData.Parse(element, parent=self)
				elif element.tag == "DuData":
					DesignUnitData.Parse(element, parent=self)
				else:
					FileData.Parse(element, parent=self)

		self._conversionDuration = sw.Duration

	def ToCoverageSummary(self) -> CoverageSummary:
		"""
		Convert the statements and branches of the format's model to the common model, and aggregate it.

		The statements of all scopes are merged by file, line and index, the ``if`` and ``case`` statements by the file,
		line and index of their first branch; merged items count as often as their items together. Each branch of an ``if``
		or ``case`` statement becomes a branch of the line of its first branch, taken as often as the branch's true count
		or hits. A line ran as often as its least often run statement or branching statement - the sum of its branches'
		counts. A line, which ran, is covered, if all its branches were taken, otherwise partially covered.

		:returns:                  The report's root of the common model, named after the report file.
		:raises CodeCoverageError: If the report has no statements: it was written without details. |br|
		                           Write the report with details: 'vcover report -xml -details ...'.
		:raises CodeCoverageError: If two scopes state the same ``if`` or ``case`` statement with different numbers of
		                           branches.
		:raises CodeCoverageError: If a file's path runs through another file.
		"""
		hitsPerStatement: dict[tuple[Path, int, int], int] = {}
		branchesPerDecision: dict[tuple[Path, int, int, str], list[int]] = {}
		for scope in self._scopes:
			for statement in scope._statements:
				key = (statement._file, statement._lineNumber, statement._index)
				hitsPerStatement[key] = hitsPerStatement.get(key, 0) + statement._hits

			decisions = [
				("if", [branch._trueCount for branch in ifStatement._branches], ifStatement._branches[0])
				for ifStatement in scope._ifStatements
			] + [
				("case", [branch._hits for branch in caseStatement._branches], caseStatement._branches[0])
				for caseStatement in scope._caseStatements
			]
			for kind, counts, first in decisions:
				key = (first._file, first._lineNumber, first._index, kind)
				if (merged := branchesPerDecision.get(key)) is None:
					branchesPerDecision[key] = counts
				elif len(merged) != len(counts):
					ex = CodeCoverageError(
						f"The '{kind}' statement at '{first._file.as_posix()}:{first._lineNumber}' has {len(counts)} branches in "
						f"one scope, but {len(merged)} in another."
					)
					ex.add_note("The scopes merge their branches by position.")
					raise ex
				else:
					branchesPerDecision[key] = [total + count for total, count in zip(merged, counts)]

		if len(hitsPerStatement) == 0:
			ex = CodeCoverageError(f"QuestaSim coverage report '{self._path}' has no statements to convert.")
			ex.add_note("Write the report with details: 'vcover report -xml -details ...'.")
			raise ex

		countsPerLine:   dict[Path, dict[int, list[int]]] = {}
		branchesPerLine: dict[Path, dict[int, list[int]]] = {}
		for (file, lineNumber, _), hits in hitsPerStatement.items():
			countsPerLine.setdefault(file, {}).setdefault(lineNumber, []).append(hits)

		for (file, lineNumber, _, _), counts in branchesPerDecision.items():
			countsPerLine.setdefault(file, {}).setdefault(lineNumber, []).append(sum(counts))
			branchesPerLine.setdefault(file, {}).setdefault(lineNumber, []).extend(counts)

		summary = CoverageSummary(self._path.stem)
		for path, counts in countsPerLine.items():
			file = summary.GetOrAddFile(path)
			branches = branchesPerLine.get(path, {})
			for lineNumber in sorted(counts):
				count = min(counts[lineNumber])
				branchCounts = branches.get(lineNumber, [])
				if count == 0:
					status = LineCoverageStatus.Uncovered
				elif any(branchCount == 0 for branchCount in branchCounts):
					status = LineCoverageStatus.PartiallyCovered
				else:
					status = LineCoverageStatus.Covered

				line = cc_Line(lineNumber, status, count, parent=file)
				for branchCount in branchCounts:
					branchStatus = LineCoverageStatus.Covered if branchCount > 0 else LineCoverageStatus.Uncovered
					cc_Branch(branchStatus, branchCount, parent=line)

		summary.Aggregate()
		return summary