GCC Code Coverage Report


src/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
29 / 31
93.5%
Branches:
11 / 12
91.7%
Functions:
6 / 9
66.7%

model/generic-type.spice
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 // Std imports
4 import "std/data/unordered-map";
5
6 // Own imports
7 import "@/symboltablebuilder/super-type";
8 import "@/symboltablebuilder/qual-type";
9
10 // Type aliases
11 public type TypeMapping alias UnorderedMap</*typeName=*/String, /*concreteType=*/QualType>;
12
13 525700 public type GenericType struct {
14 public compose QualType qualType
15 QualTypeList typeConditions
16 28751 public bool used = false
17 }
18
19 ✗ public p GenericType.ctor() {}
20
21 25689 public p GenericType.ctor(const QualType& qualType) {
22 25689 this.qualType = qualType;
23 25689 this.typeConditions.pushBack(QualType(SuperType::TY_DYN));
24 25689 }
25
26 3062 public p GenericType.ctor(const String& name, const QualTypeList& typeConditions) {
27 3062 this.qualType = QualType(SuperType::TY_GENERIC, name);
28 3062 this.typeConditions = typeConditions;
29 3062 }
30
31 /**
32 * Checks if the given symbol qualType matches all conditions to get a manifestation of the current generic qualType
33 *
34 * @param requestedType Qualified qualType to be checked
35 * @param substantiation Concrete substantiation of the generic type
36 * @param ignoreArraySize Ignore the array size for qualType comparison
37 * @param ignoreQualifiers Ignore the type qualifiers for qualType comparison
38 * @return True or false
39 */
40 27259 public f<bool> GenericType.checkConditionsOf(const QualType& requestedType, QualType& substantiation, bool ignoreArraySize = false, bool ignoreQualifiers = false) {
41 27259 return this.checkTypeConditionOf(requestedType, substantiation, ignoreArraySize, ignoreQualifiers);
42 }
43
44 /**
45 * Checks if the given qualType matches all qualType conditions to get a manifestation of the current generic qualType
46 *
47 * @param requestedType Qualified type to be checked
48 * @param substantiation Concrete substantiation of the generic type
49 * @param ignoreArraySize Ignore the array size for qualType comparison
50 * @param ignoreQualifiers Ignore the type qualifiers for qualType comparison
51 * @return True or false
52 */
53 27259 f<bool> GenericType.checkTypeConditionOf(const QualType& requestedType, QualType& substantiation, bool ignoreArraySize, bool ignoreQualifiers) {
54 27259 substantiation = requestedType;
55 // Succeed if there are no type conditions
56
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27259 times.
27259 if this.typeConditions.isEmpty() {
57 ✗ return true;
58 }
59 // Succeed if the given qual type is generic and matches the current one
60
4/4
✓ Branch 0 taken 25277 times.
✓ Branch 1 taken 1982 times.
✓ Branch 2 taken 1419 times.
✓ Branch 3 taken 25840 times.
27259 if requestedType.hasAnyGenericParts() && requestedType == this.qualType {
61 1419 return true;
62 }
63 // Check type conditions
64
2/2
✓ Branch 0 taken 32451 times.
✓ Branch 1 taken 4329 times.
36780 foreach const QualType& typeCondition : this.typeConditions {
65 // If we have a dyn type condition, the conditions are fulfilled immediately
66
2/2
✓ Branch 0 taken 19038 times.
✓ Branch 1 taken 13413 times.
32451 if typeCondition.is(SuperType::TY_DYN) {
67 19038 return true;
68 }
69 // In situations like this we need to unwrap: requestedType = const int&, typeCondition = int
70 13413 QualType typeConditionCopy = typeCondition;
71 13413 QualType requestedTypeCopy = requestedType;
72 13413 unwrapBothWithRefWrappers(typeConditionCopy, requestedTypeCopy);
73
2/2
✓ Branch 0 taken 2473 times.
✓ Branch 1 taken 10940 times.
13413 if typeConditionCopy.matches(requestedTypeCopy, ignoreArraySize, ignoreQualifiers, ignoreQualifiers) {
74 // Field-wise copy instead of assigning the const reference through the reference
75 2473 substantiation.rawType = typeCondition.rawType;
76 2473 substantiation.qualifiers = typeCondition.qualifiers;
77 2473 return true;
78 }
79 10940 }
80 4329 return false;
81 }
82