GCC Code Coverage Report


Directory: ../
File: src/model/GenericType.cpp
Date: 2025-03-05 01:50:32
Exec Total Coverage
Lines: 17 18 94.4%
Functions: 2 2 100.0%
Branches: 16 20 80.0%

Line Branch Exec Source
1 // Copyright (c) 2021-2025 ChilliBits. All rights reserved.
2
3 #include "GenericType.h"
4
5 namespace spice::compiler {
6
7 /**
8 * Checks if the given symbol qualType matches all conditions to get a manifestation of the current generic qualType
9 *
10 * @param requestedType Qualified qualType to be checked
11 * @param substantiation Concrete substantiation of the generic type
12 * @param ignoreArraySize Ignore the array size for qualType comparison
13 * @param ignoreQualifiers Ignore the type qualifiers for qualType comparison
14 * @return True or false
15 */
16 7110 bool GenericType::checkConditionsOf(const QualType &requestedType, QualType &substantiation, bool ignoreArraySize,
17 bool ignoreQualifiers) const {
18 7110 return checkTypeConditionOf(requestedType, substantiation, ignoreArraySize, ignoreQualifiers);
19 }
20
21 /**
22 * Checks if the given qualType matches all qualType conditions to get a manifestation of the current generic qualType
23 *
24 * @param requestedType Qualified type to be checked
25 * @param substantiation Concrete substantiation of the generic type
26 * @param ignoreArraySize Ignore the array size for qualType comparison
27 * @param ignoreQualifiers Ignore the type qualifiers for qualType comparison
28 * @return True or false
29 */
30 7110 bool GenericType::checkTypeConditionOf(const QualType &requestedType, QualType &substantiation, bool ignoreArraySize,
31 bool ignoreQualifiers) const {
32 7110 substantiation = requestedType;
33 // Succeed if there are no type conditions
34
1/2
✗ Branch 0 (3→4) not taken.
✓ Branch 1 (3→5) taken 7110 times.
7110 if (typeConditions.empty())
35 return true;
36 // Succeed if the given qual type is generic and matches the current one
37
6/6
✓ Branch 0 (6→7) taken 907 times.
✓ Branch 1 (6→10) taken 6203 times.
✓ Branch 2 (8→9) taken 752 times.
✓ Branch 3 (8→10) taken 155 times.
✓ Branch 4 (11→12) taken 752 times.
✓ Branch 5 (11→13) taken 6358 times.
7110 if (requestedType.hasAnyGenericParts() && requestedType == *this)
38 752 return true;
39 // Check type conditions
40
2/2
✓ Branch 0 (26→15) taken 10093 times.
✓ Branch 1 (26→27) taken 2723 times.
12816 for (const QualType &typeCondition : typeConditions) {
41 // If we have a dyn type condition, the conditions are fulfilled immediately
42
3/4
✓ Branch 0 (16→17) taken 10093 times.
✗ Branch 1 (16→29) not taken.
✓ Branch 2 (17→18) taken 2590 times.
✓ Branch 3 (17→19) taken 7503 times.
10093 if (typeCondition.is(TY_DYN))
43 3635 return true;
44 // In situations like this we need to unwrap: requestedType = const int&, typeCondition = int
45 7503 QualType typeConditionCopy = typeCondition;
46 7503 QualType requestedTypeCopy = requestedType;
47
1/2
✓ Branch 0 (19→20) taken 7503 times.
✗ Branch 1 (19→29) not taken.
7503 unwrapBoth(typeConditionCopy, requestedTypeCopy);
48
3/4
✓ Branch 0 (20→21) taken 7503 times.
✗ Branch 1 (20→29) not taken.
✓ Branch 2 (21→22) taken 1045 times.
✓ Branch 3 (21→23) taken 6458 times.
7503 if (typeConditionCopy.matches(requestedTypeCopy, ignoreArraySize, ignoreQualifiers, ignoreQualifiers)) {
49 1045 substantiation = typeCondition;
50 1045 return true;
51 }
52 }
53 2723 return false;
54 }
55
56 } // namespace spice::compiler
57