GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 148 / 0 / 148
Functions: 100.0% 4 / 0 / 4
Branches: 65.5% 199 / 0 / 304

src/typechecker/TypeCheckerTopLevelDefinitionsCheck.cpp
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 #include "TypeChecker.h"
4
5 #include <SourceFile.h>
6 #include <ast/ASTNodes.h>
7 #include <exception/SemanticError.h>
8 #include <model/Interface.h>
9 #include <symboltablebuilder/Scope.h>
10 #include <symboltablebuilder/SymbolTableBuilder.h>
11 #include <typechecker/FunctionManager.h>
12 #include <typechecker/TypeMatcher.h>
13
14 namespace spice::compiler {
15
16 617 std::any TypeChecker::visitMainFctDefCheck(MainFctDefNode *node) {
17 // Skip if already type-checked
18
2/2
✓ Branch 2 → 3 taken 79 times.
✓ Branch 2 → 6 taken 538 times.
617 if (typeCheckedMainFct)
19
1/2
✓ Branch 3 → 4 taken 79 times.
✗ Branch 3 → 13 not taken.
158 return nullptr;
20
21 538 node->resizeToNumberOfManifestations(1);
22
23 // Change to function body scope
24 538 currentScope = node->bodyScope;
25 // Visit statements in new scope
26
2/2
✓ Branch 7 → 8 taken 508 times.
✓ Branch 7 → 14 taken 30 times.
538 visit(node->body);
27 // Leave main function body scope
28 508 currentScope = rootScope;
29
30 // Set to type-checked
31 508 typeCheckedMainFct = true;
32
1/2
✓ Branch 9 → 10 taken 508 times.
✗ Branch 9 → 15 not taken.
1016 return nullptr;
33 }
34
35 47245 std::any TypeChecker::visitFctDefCheck(FctDefNode *node) {
36 47245 node->resizeToNumberOfManifestations(node->manifestations.size());
37 47245 manIdx = 0; // Reset the manifestation index
38
39 // Get all manifestations for this function definition
40
2/2
✓ Branch 79 → 6 taken 63266 times.
✓ Branch 79 → 80 taken 47243 times.
157754 for (Function *manifestation : node->manifestations) {
41 // Skip non-substantiated or already checked functions
42
7/8
✓ Branch 8 → 9 taken 63266 times.
✗ Branch 8 → 101 not taken.
✓ Branch 9 → 10 taken 51536 times.
✓ Branch 9 → 11 taken 11730 times.
✓ Branch 10 → 11 taken 27331 times.
✓ Branch 10 → 12 taken 24205 times.
✓ Branch 13 → 14 taken 39061 times.
✓ Branch 13 → 15 taken 24205 times.
63266 if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) {
43 39061 manIdx++; // Increase the manifestation index
44 39061 continue;
45 }
46
47 // Change scope to concrete struct specialization scope
48
2/2
✓ Branch 15 → 16 taken 13688 times.
✓ Branch 15 → 21 taken 10517 times.
24205 if (node->isMethod) {
49
2/4
✓ Branch 16 → 17 taken 13688 times.
✗ Branch 16 → 86 not taken.
✓ Branch 17 → 18 taken 13688 times.
✗ Branch 17 → 86 not taken.
13688 const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes());
50
1/2
✓ Branch 18 → 19 taken 13688 times.
✗ Branch 18 → 84 not taken.
13688 changeToScope(scopeName, ScopeType::STRUCT);
51 13688 }
52
53 // Change to function scope
54
1/2
✓ Branch 21 → 22 taken 24205 times.
✗ Branch 21 → 101 not taken.
24205 changeToScope(manifestation->bodyScope, ScopeType::FUNC_PROC_BODY);
55
56 // Mount type mapping for this manifestation
57
1/2
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 24205 times.
24205 assert(typeMapping.empty());
58
1/2
✓ Branch 25 → 26 taken 24205 times.
✗ Branch 25 → 101 not taken.
24205 typeMapping = manifestation->typeMapping;
59
60 // Set return type to the result variable
61
1/2
✓ Branch 28 → 29 taken 24205 times.
✗ Branch 28 → 89 not taken.
72615 SymbolTableEntry *resultVarEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME);
62
1/2
✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 24205 times.
24205 assert(resultVarEntry != nullptr);
63
1/2
✓ Branch 36 → 37 taken 24205 times.
✗ Branch 36 → 101 not taken.
24205 resultVarEntry->updateType(manifestation->returnType, false);
64 24205 resultVarEntry->used = true;
65
66 // Visit parameters
67 // This happens once in the type checker prepare stage. This second time is only required if we have a generic function
68
2/2
✓ Branch 37 → 38 taken 17580 times.
✓ Branch 37 → 64 taken 6625 times.
24205 if (node->hasParams) {
69
1/2
✓ Branch 38 → 39 taken 17580 times.
✗ Branch 38 → 93 not taken.
17580 visit(node->paramLst);
70 // Annotate function/procedure-typed params with lambda-capture info from the resolved manifestation type.
71 // This must happen in the TypeChecker so that the IRGenerator can treat SymbolTableEntry as immutable.
72
2/2
✓ Branch 63 → 41 taken 25622 times.
✓ Branch 63 → 64 taken 17580 times.
43202 for (size_t i = 0; i < manifestation->paramList.size(); i++) {
73
1/2
✓ Branch 41 → 42 taken 25622 times.
✗ Branch 41 → 99 not taken.
25622 const DeclStmtNode *param = node->paramLst->params.at(i);
74
2/4
✓ Branch 42 → 43 taken 25622 times.
✗ Branch 42 → 96 not taken.
✓ Branch 43 → 44 taken 25622 times.
✗ Branch 43 → 94 not taken.
25622 const QualType paramType = manifestation->getParamTypes().at(i);
75
8/10
✓ Branch 45 → 46 taken 25622 times.
✗ Branch 45 → 97 not taken.
✓ Branch 46 → 47 taken 18 times.
✓ Branch 46 → 50 taken 25604 times.
✓ Branch 47 → 48 taken 18 times.
✗ Branch 47 → 97 not taken.
✓ Branch 48 → 49 taken 2 times.
✓ Branch 48 → 50 taken 16 times.
✓ Branch 51 → 52 taken 2 times.
✓ Branch 51 → 61 taken 25620 times.
25622 if (paramType.isOneOf({TY_FUNCTION, TY_PROCEDURE}) && paramType.hasLambdaCaptures()) {
76
1/2
✓ Branch 52 → 53 taken 2 times.
✗ Branch 52 → 99 not taken.
2 SymbolTableEntry *paramSymbol = currentScope->lookupStrict(param->varName);
77
1/2
✗ Branch 55 → 56 not taken.
✓ Branch 55 → 57 taken 2 times.
2 assert(paramSymbol != nullptr);
78
3/6
✓ Branch 57 → 58 taken 2 times.
✗ Branch 57 → 98 not taken.
✓ Branch 58 → 59 taken 2 times.
✗ Branch 58 → 98 not taken.
✓ Branch 59 → 60 taken 2 times.
✗ Branch 59 → 98 not taken.
2 paramSymbol->updateType(paramSymbol->getQualType().getWithLambdaCaptures(), true);
79 }
80 }
81 }
82
83 // Visit statements in new scope
84
2/2
✓ Branch 64 → 65 taken 24203 times.
✓ Branch 64 → 100 taken 2 times.
24205 visit(node->body);
85
86 // Clear type mapping
87 24203 typeMapping.clear();
88
89 // Change to root scope
90 24203 currentScope = rootScope;
91
1/2
✗ Branch 67 → 68 not taken.
✓ Branch 67 → 69 taken 24203 times.
24203 assert(currentScope->type == ScopeType::GLOBAL);
92
93 // Do not type-check this manifestation again
94 24203 manifestation->alreadyTypeChecked = true;
95
96 24203 manIdx++; // Increase the manifestation index
97 }
98 47243 manIdx = 0; // Reset the manifestation index
99
100
1/2
✓ Branch 80 → 81 taken 47243 times.
✗ Branch 80 → 102 not taken.
94486 return nullptr;
101 }
102
103 26383 std::any TypeChecker::visitProcDefCheck(ProcDefNode *node) {
104 26383 node->resizeToNumberOfManifestations(node->manifestations.size());
105 26383 manIdx = 0; // Reset the manifestation index
106
107 // Get all manifestations for this procedure definition
108
2/2
✓ Branch 72 → 6 taken 38902 times.
✓ Branch 72 → 73 taken 26383 times.
91668 for (Function *manifestation : node->manifestations) {
109 // Skip non-substantiated or already checked procedures
110
7/8
✓ Branch 8 → 9 taken 38902 times.
✗ Branch 8 → 88 not taken.
✓ Branch 9 → 10 taken 26720 times.
✓ Branch 9 → 11 taken 12182 times.
✓ Branch 10 → 11 taken 13080 times.
✓ Branch 10 → 12 taken 13640 times.
✓ Branch 13 → 14 taken 25262 times.
✓ Branch 13 → 15 taken 13640 times.
38902 if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) {
111 25262 manIdx++; // Increase the manifestation index
112 25262 continue;
113 }
114
115 // Change scope to concrete struct specialization scope
116
2/2
✓ Branch 15 → 16 taken 11609 times.
✓ Branch 15 → 21 taken 2031 times.
13640 if (node->isMethod) {
117
2/4
✓ Branch 16 → 17 taken 11609 times.
✗ Branch 16 → 79 not taken.
✓ Branch 17 → 18 taken 11609 times.
✗ Branch 17 → 79 not taken.
11609 const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes());
118
1/2
✓ Branch 18 → 19 taken 11609 times.
✗ Branch 18 → 77 not taken.
11609 changeToScope(scopeName, ScopeType::STRUCT);
119 11609 }
120
121 // Change to procedure scope
122
1/2
✓ Branch 21 → 22 taken 13640 times.
✗ Branch 21 → 88 not taken.
13640 changeToScope(manifestation->bodyScope, ScopeType::FUNC_PROC_BODY);
123
124 // Mount type mapping for this manifestation
125
1/2
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 13640 times.
13640 assert(typeMapping.empty());
126
1/2
✓ Branch 25 → 26 taken 13640 times.
✗ Branch 25 → 88 not taken.
13640 typeMapping = manifestation->typeMapping;
127
128 // Visit parameters
129 // This happens once in the type checker prepare stage. This second time is only required if we have a generic procedure
130
2/2
✓ Branch 26 → 27 taken 10283 times.
✓ Branch 26 → 53 taken 3357 times.
13640 if (node->hasParams) {
131
1/2
✓ Branch 27 → 28 taken 10283 times.
✗ Branch 27 → 80 not taken.
10283 visit(node->paramLst);
132 // Annotate function/procedure-typed params with lambda-capture info from the resolved manifestation type.
133 // This must happen in the TypeChecker so that the IRGenerator can treat SymbolTableEntry as immutable.
134
2/2
✓ Branch 52 → 30 taken 14314 times.
✓ Branch 52 → 53 taken 10283 times.
24597 for (size_t i = 0; i < manifestation->paramList.size(); i++) {
135
1/2
✓ Branch 30 → 31 taken 14314 times.
✗ Branch 30 → 86 not taken.
14314 const DeclStmtNode *param = node->paramLst->params.at(i);
136
2/4
✓ Branch 31 → 32 taken 14314 times.
✗ Branch 31 → 83 not taken.
✓ Branch 32 → 33 taken 14314 times.
✗ Branch 32 → 81 not taken.
14314 const QualType paramType = manifestation->getParamTypes().at(i);
137
8/10
✓ Branch 34 → 35 taken 14314 times.
✗ Branch 34 → 84 not taken.
✓ Branch 35 → 36 taken 60 times.
✓ Branch 35 → 39 taken 14254 times.
✓ Branch 36 → 37 taken 60 times.
✗ Branch 36 → 84 not taken.
✓ Branch 37 → 38 taken 14 times.
✓ Branch 37 → 39 taken 46 times.
✓ Branch 40 → 41 taken 14 times.
✓ Branch 40 → 50 taken 14300 times.
14314 if (paramType.isOneOf({TY_FUNCTION, TY_PROCEDURE}) && paramType.hasLambdaCaptures()) {
138
1/2
✓ Branch 41 → 42 taken 14 times.
✗ Branch 41 → 86 not taken.
14 SymbolTableEntry *paramSymbol = currentScope->lookupStrict(param->varName);
139
1/2
✗ Branch 44 → 45 not taken.
✓ Branch 44 → 46 taken 14 times.
14 assert(paramSymbol != nullptr);
140
3/6
✓ Branch 46 → 47 taken 14 times.
✗ Branch 46 → 85 not taken.
✓ Branch 47 → 48 taken 14 times.
✗ Branch 47 → 85 not taken.
✓ Branch 48 → 49 taken 14 times.
✗ Branch 48 → 85 not taken.
14 paramSymbol->updateType(paramSymbol->getQualType().getWithLambdaCaptures(), true);
141 }
142 }
143 }
144
145 // Prepare generation of special ctor preamble to store VTable, default field values, etc. if required
146
2/2
✓ Branch 53 → 54 taken 6077 times.
✓ Branch 53 → 55 taken 7563 times.
13640 if (node->isCtor)
147
1/2
✓ Branch 54 → 55 taken 6077 times.
✗ Branch 54 → 88 not taken.
6077 createCtorBodyPreamble(node->scope);
148
149 // Visit statements in new scope
150
1/2
✓ Branch 55 → 56 taken 13640 times.
✗ Branch 55 → 87 not taken.
13640 visit(node->body);
151
152 // Clear type mapping
153 13640 typeMapping.clear();
154
155 // Change to root scope
156 13640 currentScope = rootScope;
157
2/4
✓ Branch 58 → 59 taken 13640 times.
✗ Branch 58 → 61 not taken.
✓ Branch 59 → 60 taken 13640 times.
✗ Branch 59 → 61 not taken.
13640 assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL);
158
159 // Do not type-check this manifestation again
160 13640 manifestation->alreadyTypeChecked = true;
161
162 13640 manIdx++; // Increase the manifestation index
163 }
164 26383 manIdx = 0; // Reset the manifestation index
165
166
1/2
✓ Branch 73 → 74 taken 26383 times.
✗ Branch 73 → 89 not taken.
52766 return nullptr;
167 }
168
169 6004 std::any TypeChecker::visitStructDefCheck(StructDefNode *node) {
170 6004 node->resizeToNumberOfManifestations(node->structManifestations.size());
171 6004 manIdx = 0; // Reset the manifestation index
172
173 // Get all manifestations for this procedure definition
174
2/2
✓ Branch 215 → 6 taken 10302 times.
✓ Branch 215 → 216 taken 6004 times.
22310 for (Struct *manifestation : node->structManifestations) {
175 // Skip non-substantiated or already checked procedures
176
3/4
✓ Branch 8 → 9 taken 10302 times.
✗ Branch 8 → 299 not taken.
✓ Branch 9 → 10 taken 1724 times.
✓ Branch 9 → 11 taken 8578 times.
10302 if (!manifestation->isFullySubstantiated()) {
177 1724 manIdx++; // Increase the manifestation index
178 1724 continue;
179 }
180
181 // Fallback for manifestations that could not be decided on when they were created, because a by-value struct field
182 // was not manifested yet at that point (circular import). By now the whole import graph is prepared, so the
183 // decision can be taken - late, but still before the struct's own default member bodies are prepared below.
184
1/2
✓ Branch 11 → 12 taken 8578 times.
✗ Branch 11 → 299 not taken.
8578 createImplicitDefaultMembers(*manifestation, node, /*withMoveCtor=*/false);
185
186 // Change to struct scope
187
1/2
✓ Branch 12 → 13 taken 8578 times.
✗ Branch 12 → 299 not taken.
8578 changeToScope(manifestation->scope, ScopeType::STRUCT);
188
189 // Mount type mapping for this manifestation, so that the body preamble helpers below can substantiate
190 // generic field types (e.g. `heap T*` on `Vector<T>`). Without this, an auto-generated body preamble that
191 // touches a still-generic field would assert in TypeMatcher::substantiateTypeWithTypeMapping.
192
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 8578 times.
8578 assert(typeMapping.empty());
193
1/2
✓ Branch 16 → 17 taken 8578 times.
✗ Branch 16 → 299 not taken.
8578 typeMapping = manifestation->typeMapping;
194
195 // Re-visit all default values. This is required, since the type of the default value might vary for different manifestations
196
2/2
✓ Branch 40 → 19 taken 17996 times.
✓ Branch 40 → 41 taken 8578 times.
35152 for (const FieldNode *field : node->fields) {
197
2/2
✓ Branch 21 → 22 taken 7216 times.
✓ Branch 21 → 31 taken 10780 times.
17996 if (field->defaultValue != nullptr) {
198
1/2
✓ Branch 22 → 23 taken 7216 times.
✗ Branch 22 → 220 not taken.
7216 visit(field->defaultValue);
199
1/2
✓ Branch 24 → 25 taken 7216 times.
✗ Branch 24 → 222 not taken.
7216 SymbolTableEntry *fieldEntry = manifestation->scope->lookupStrict(field->fieldName);
200
1/2
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 7216 times.
7216 assert(fieldEntry != nullptr);
201
1/2
✓ Branch 29 → 30 taken 7216 times.
✗ Branch 29 → 221 not taken.
7216 fieldEntry->updateState(INITIALIZED, field);
202 }
203 }
204
205 // Build struct type
206
1/2
✓ Branch 41 → 42 taken 8578 times.
✗ Branch 41 → 299 not taken.
8578 const QualType structType = manifestation->entry->getQualType();
207
208 // Check if the struct implements all methods of all attached interfaces
209 8578 size_t vtableIndex = 0;
210
2/2
✓ Branch 146 → 44 taken 2258 times.
✓ Branch 146 → 147 taken 8578 times.
19414 for (const QualType &interfaceType : manifestation->interfaceTypes) {
211
1/2
✓ Branch 46 → 47 taken 2258 times.
✗ Branch 46 → 266 not taken.
2258 const Interface *interface = interfaceType.getInterface(node);
212
1/2
✗ Branch 47 → 48 not taken.
✓ Branch 47 → 49 taken 2258 times.
2258 assert(interface != nullptr);
213
214 // Check for all methods, that it is implemented by the struct
215
2/2
✓ Branch 136 → 51 taken 6691 times.
✓ Branch 136 → 137 taken 2258 times.
11207 for (const Function *expMethod : interface->methods) {
216
1/2
✓ Branch 53 → 54 taken 6691 times.
✗ Branch 53 → 264 not taken.
6691 const std::string methodName = expMethod->name;
217
1/2
✓ Branch 54 → 55 taken 6691 times.
✗ Branch 54 → 262 not taken.
6691 QualTypeList params = expMethod->getParamTypes();
218 6691 QualType returnType = expMethod->returnType;
219
220 // Substantiate param and return types
221
1/2
✓ Branch 55 → 56 taken 6691 times.
✗ Branch 55 → 260 not taken.
6691 TypeMatcher::substantiateTypesWithTypeMapping(params, interface->typeMapping, node);
222
3/4
✓ Branch 56 → 57 taken 6691 times.
✗ Branch 56 → 260 not taken.
✓ Branch 57 → 58 taken 3205 times.
✓ Branch 57 → 59 taken 3486 times.
6691 if (returnType.hasAnyGenericParts())
223
1/2
✓ Branch 58 → 59 taken 3205 times.
✗ Branch 58 → 260 not taken.
3205 TypeMatcher::substantiateTypeWithTypeMapping(returnType, interface->typeMapping, node);
224
225 // Build args list
226 6691 ArgList args;
227
1/2
✓ Branch 60 → 61 taken 6691 times.
✗ Branch 60 → 258 not taken.
6691 args.reserve(params.size());
228
2/2
✓ Branch 75 → 63 taken 1080 times.
✓ Branch 75 → 76 taken 6691 times.
14462 for (const QualType &param : params)
229
1/2
✓ Branch 65 → 66 taken 1080 times.
✗ Branch 65 → 223 not taken.
1080 args.emplace_back(param, nullptr);
230
231 // Search for method that has the required signature
232
1/2
✓ Branch 77 → 78 taken 6691 times.
✗ Branch 77 → 225 not taken.
6691 Function *spiceFunction = FunctionManager::match(currentScope, methodName, structType, args, {}, true, node);
233
2/2
✓ Branch 79 → 80 taken 4 times.
✓ Branch 79 → 92 taken 6687 times.
6691 if (spiceFunction == nullptr) {
234
1/2
✓ Branch 85 → 86 taken 4 times.
✗ Branch 85 → 228 not taken.
4 softError(node, INTERFACE_METHOD_NOT_IMPLEMENTED,
235
5/10
✓ Branch 80 → 81 taken 4 times.
✗ Branch 80 → 240 not taken.
✓ Branch 81 → 82 taken 4 times.
✗ Branch 81 → 236 not taken.
✓ Branch 82 → 83 taken 4 times.
✗ Branch 82 → 234 not taken.
✓ Branch 83 → 84 taken 4 times.
✗ Branch 83 → 232 not taken.
✓ Branch 84 → 85 taken 4 times.
✗ Branch 84 → 230 not taken.
8 "The struct '" + node->structName + "' does not implement method '" + expMethod->getSignature() + "'.");
236 4 continue;
237 }
238
239 // Check return type
240
5/6
✓ Branch 92 → 93 taken 6687 times.
✗ Branch 92 → 258 not taken.
✓ Branch 93 → 94 taken 1049 times.
✓ Branch 93 → 97 taken 5638 times.
✓ Branch 98 → 99 taken 2 times.
✓ Branch 98 → 111 taken 6685 times.
7736 if (spiceFunction->returnType != returnType &&
241
3/4
✓ Branch 94 → 95 taken 1049 times.
✗ Branch 94 → 258 not taken.
✓ Branch 95 → 96 taken 2 times.
✓ Branch 95 → 97 taken 1047 times.
1049 !returnType.matchesInterfaceImplementedByStruct(spiceFunction->returnType)) {
242
1/2
✓ Branch 104 → 105 taken 2 times.
✗ Branch 104 → 243 not taken.
2 softError(node, INTERFACE_METHOD_NOT_IMPLEMENTED,
243
4/8
✓ Branch 99 → 100 taken 2 times.
✗ Branch 99 → 255 not taken.
✓ Branch 100 → 101 taken 2 times.
✗ Branch 100 → 251 not taken.
✓ Branch 101 → 102 taken 2 times.
✗ Branch 101 → 249 not taken.
✓ Branch 102 → 103 taken 2 times.
✗ Branch 102 → 247 not taken.
4 "The struct '" + node->structName + "' does not implement method '" + expMethod->getSignature() +
244
1/2
✓ Branch 103 → 104 taken 2 times.
✗ Branch 103 → 245 not taken.
2 "'. The return type does not match.");
245 2 continue;
246 }
247 // Set to virtual, since it overrides the interface method
248 6685 spiceFunction->isVirtual = true;
249 6685 spiceFunction->vtableIndex = vtableIndex++;
250
6/6
✓ Branch 113 → 114 taken 6685 times.
✓ Branch 113 → 115 taken 6 times.
✓ Branch 118 → 119 taken 6685 times.
✓ Branch 118 → 120 taken 6 times.
✓ Branch 123 → 124 taken 6685 times.
✓ Branch 123 → 126 taken 6 times.
20073 }
251 }
252
253 // Check default ctor body if required
254
2/4
✓ Branch 150 → 151 taken 8578 times.
✗ Branch 150 → 269 not taken.
✓ Branch 151 → 152 taken 8578 times.
✗ Branch 151 → 267 not taken.
25734 const Function *ctorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, {}, true);
255
4/4
✓ Branch 155 → 156 taken 2120 times.
✓ Branch 155 → 161 taken 6458 times.
✓ Branch 156 → 157 taken 305 times.
✓ Branch 156 → 161 taken 1815 times.
8578 if (ctorFunc != nullptr && ctorFunc->implicitDefault) {
256
1/2
✓ Branch 157 → 158 taken 305 times.
✗ Branch 157 → 299 not taken.
305 createCtorBodyPreamble(ctorFunc->bodyScope);
257
2/4
✓ Branch 158 → 159 taken 305 times.
✗ Branch 158 → 299 not taken.
✗ Branch 159 → 160 not taken.
✓ Branch 159 → 161 taken 305 times.
305 assert(manifestation->areAllFieldsInitialized() == nullptr);
258 }
259
260 // Check default copy ctor body if required
261
2/4
✓ Branch 161 → 162 taken 8578 times.
✗ Branch 161 → 280 not taken.
✓ Branch 165 → 166 taken 8578 times.
✗ Branch 165 → 276 not taken.
25734 const ArgList args = {{structType.toConstRef(node), false /* always non-temporary */}};
262
2/4
✓ Branch 169 → 170 taken 8578 times.
✗ Branch 169 → 284 not taken.
✓ Branch 170 → 171 taken 8578 times.
✗ Branch 170 → 282 not taken.
8578 const Function *copyCtorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, args, true);
263
4/4
✓ Branch 173 → 174 taken 4710 times.
✓ Branch 173 → 179 taken 3868 times.
✓ Branch 174 → 175 taken 3580 times.
✓ Branch 174 → 179 taken 1130 times.
8578 if (copyCtorFunc != nullptr && copyCtorFunc->implicitDefault) {
264
1/2
✓ Branch 175 → 176 taken 3580 times.
✗ Branch 175 → 297 not taken.
3580 createCopyCtorBodyPreamble(copyCtorFunc->bodyScope);
265
2/4
✓ Branch 176 → 177 taken 3580 times.
✗ Branch 176 → 297 not taken.
✗ Branch 177 → 178 not taken.
✓ Branch 177 → 179 taken 3580 times.
3580 assert(manifestation->areAllFieldsInitialized() == nullptr);
266 }
267
268 // Check default move ctor body if required. findMoveCtor scans the manifestations directly to avoid the
269 // constify-based false-positive that FunctionManager::lookup with a non-const ref arg can produce.
270
3/4
✓ Branch 179 → 180 taken 8578 times.
✗ Branch 179 → 297 not taken.
✓ Branch 180 → 181 taken 103 times.
✓ Branch 180 → 186 taken 8475 times.
8578 if (const Function *moveCtorFunc = FunctionManager::findMoveCtor(currentScope);
271
2/2
✓ Branch 181 → 182 taken 17 times.
✓ Branch 181 → 186 taken 86 times.
103 moveCtorFunc && moveCtorFunc->implicitDefault) {
272
1/2
✓ Branch 182 → 183 taken 17 times.
✗ Branch 182 → 297 not taken.
17 createMoveCtorBodyPreamble(moveCtorFunc->bodyScope);
273
2/4
✓ Branch 183 → 184 taken 17 times.
✗ Branch 183 → 297 not taken.
✗ Branch 184 → 185 not taken.
✓ Branch 184 → 186 taken 17 times.
17 assert(manifestation->areAllFieldsInitialized() == nullptr);
274 }
275
276 // Check default dtor body if required
277
2/4
✓ Branch 189 → 190 taken 8578 times.
✗ Branch 189 → 290 not taken.
✓ Branch 190 → 191 taken 8578 times.
✗ Branch 190 → 288 not taken.
25734 const Function *dtorFunc = FunctionManager::lookup(currentScope, DTOR_FUNCTION_NAME, structType, {}, true);
278
4/4
✓ Branch 194 → 195 taken 5029 times.
✓ Branch 194 → 197 taken 3549 times.
✓ Branch 195 → 196 taken 3490 times.
✓ Branch 195 → 197 taken 1539 times.
8578 if (dtorFunc != nullptr && dtorFunc->implicitDefault)
279
1/2
✓ Branch 196 → 197 taken 3490 times.
✗ Branch 196 → 297 not taken.
3490 createDtorBodyPreamble(dtorFunc->bodyScope, node);
280
281 // Reset field symbols to declared state for the next manifestation
282
1/2
✓ Branch 197 → 198 taken 8578 times.
✗ Branch 197 → 297 not taken.
8578 manifestation->resetFieldSymbolsToDeclared(node);
283
284 // Clear type mapping
285 8578 typeMapping.clear();
286
287 // Return to the root scope
288 8578 currentScope = rootScope;
289
2/4
✓ Branch 199 → 200 taken 8578 times.
✗ Branch 199 → 202 not taken.
✓ Branch 200 → 201 taken 8578 times.
✗ Branch 200 → 202 not taken.
8578 assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL);
290
291 8578 manIdx++; // Increase the manifestation index
292 8578 }
293 6004 manIdx = 0; // Reset the manifestation index
294
295
1/2
✓ Branch 216 → 217 taken 6004 times.
✗ Branch 216 → 301 not taken.
12008 return nullptr;
296 }
297
298 } // namespace spice::compiler
299