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 630 std::any TypeChecker::visitMainFctDefCheck(MainFctDefNode *node) {
17 // Skip if already type-checked
18
2/2
✓ Branch 2 → 3 taken 80 times.
✓ Branch 2 → 6 taken 550 times.
630 if (typeCheckedMainFct)
19
1/2
✓ Branch 3 → 4 taken 80 times.
✗ Branch 3 → 13 not taken.
160 return nullptr;
20
21 550 node->resizeToNumberOfManifestations(1);
22
23 // Change to function body scope
24 550 currentScope = node->bodyScope;
25 // Visit statements in new scope
26
2/2
✓ Branch 7 → 8 taken 520 times.
✓ Branch 7 → 14 taken 30 times.
550 visit(node->body);
27 // Leave main function body scope
28 520 currentScope = rootScope;
29
30 // Set to type-checked
31 520 typeCheckedMainFct = true;
32
1/2
✓ Branch 9 → 10 taken 520 times.
✗ Branch 9 → 15 not taken.
1040 return nullptr;
33 }
34
35 49796 std::any TypeChecker::visitFctDefCheck(FctDefNode *node) {
36 49796 node->resizeToNumberOfManifestations(node->manifestations.size());
37 49796 manIdx = 0; // Reset the manifestation index
38
39 // Get all manifestations for this function definition
40
2/2
✓ Branch 79 → 6 taken 66607 times.
✓ Branch 79 → 80 taken 49794 times.
166197 for (Function *manifestation : node->manifestations) {
41 // Skip non-substantiated or already checked functions
42
7/8
✓ Branch 8 → 9 taken 66607 times.
✗ Branch 8 → 101 not taken.
✓ Branch 9 → 10 taken 53981 times.
✓ Branch 9 → 11 taken 12626 times.
✓ Branch 10 → 11 taken 28671 times.
✓ Branch 10 → 12 taken 25310 times.
✓ Branch 13 → 14 taken 41297 times.
✓ Branch 13 → 15 taken 25310 times.
66607 if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) {
43 41297 manIdx++; // Increase the manifestation index
44 41297 continue;
45 }
46
47 // Change scope to concrete struct specialization scope
48
2/2
✓ Branch 15 → 16 taken 14241 times.
✓ Branch 15 → 21 taken 11069 times.
25310 if (node->isMethod) {
49
2/4
✓ Branch 16 → 17 taken 14241 times.
✗ Branch 16 → 86 not taken.
✓ Branch 17 → 18 taken 14241 times.
✗ Branch 17 → 86 not taken.
14241 const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes());
50
1/2
✓ Branch 18 → 19 taken 14241 times.
✗ Branch 18 → 84 not taken.
14241 changeToScope(scopeName, ScopeType::STRUCT);
51 14241 }
52
53 // Change to function scope
54
1/2
✓ Branch 21 → 22 taken 25310 times.
✗ Branch 21 → 101 not taken.
25310 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 25310 times.
25310 assert(typeMapping.empty());
58
1/2
✓ Branch 25 → 26 taken 25310 times.
✗ Branch 25 → 101 not taken.
25310 typeMapping = manifestation->typeMapping;
59
60 // Set return type to the result variable
61
1/2
✓ Branch 28 → 29 taken 25310 times.
✗ Branch 28 → 89 not taken.
75930 SymbolTableEntry *resultVarEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME);
62
1/2
✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 25310 times.
25310 assert(resultVarEntry != nullptr);
63
1/2
✓ Branch 36 → 37 taken 25310 times.
✗ Branch 36 → 101 not taken.
25310 resultVarEntry->updateType(manifestation->returnType, false);
64 25310 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 18384 times.
✓ Branch 37 → 64 taken 6926 times.
25310 if (node->hasParams) {
69
1/2
✓ Branch 38 → 39 taken 18384 times.
✗ Branch 38 → 93 not taken.
18384 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 26742 times.
✓ Branch 63 → 64 taken 18384 times.
45126 for (size_t i = 0; i < manifestation->paramList.size(); i++) {
73
1/2
✓ Branch 41 → 42 taken 26742 times.
✗ Branch 41 → 99 not taken.
26742 const DeclStmtNode *param = node->paramLst->params.at(i);
74
2/4
✓ Branch 42 → 43 taken 26742 times.
✗ Branch 42 → 96 not taken.
✓ Branch 43 → 44 taken 26742 times.
✗ Branch 43 → 94 not taken.
26742 const QualType paramType = manifestation->getParamTypes().at(i);
75
8/10
✓ Branch 45 → 46 taken 26742 times.
✗ Branch 45 → 97 not taken.
✓ Branch 46 → 47 taken 18 times.
✓ Branch 46 → 50 taken 26724 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 26740 times.
26742 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 25308 times.
✓ Branch 64 → 100 taken 2 times.
25310 visit(node->body);
85
86 // Clear type mapping
87 25308 typeMapping.clear();
88
89 // Change to root scope
90 25308 currentScope = rootScope;
91
1/2
✗ Branch 67 → 68 not taken.
✓ Branch 67 → 69 taken 25308 times.
25308 assert(currentScope->type == ScopeType::GLOBAL);
92
93 // Do not type-check this manifestation again
94 25308 manifestation->alreadyTypeChecked = true;
95
96 25308 manIdx++; // Increase the manifestation index
97 }
98 49794 manIdx = 0; // Reset the manifestation index
99
100
1/2
✓ Branch 80 → 81 taken 49794 times.
✗ Branch 80 → 102 not taken.
99588 return nullptr;
101 }
102
103 27897 std::any TypeChecker::visitProcDefCheck(ProcDefNode *node) {
104 27897 node->resizeToNumberOfManifestations(node->manifestations.size());
105 27897 manIdx = 0; // Reset the manifestation index
106
107 // Get all manifestations for this procedure definition
108
2/2
✓ Branch 72 → 6 taken 41319 times.
✓ Branch 72 → 73 taken 27897 times.
97113 for (Function *manifestation : node->manifestations) {
109 // Skip non-substantiated or already checked procedures
110
7/8
✓ Branch 8 → 9 taken 41319 times.
✗ Branch 8 → 88 not taken.
✓ Branch 9 → 10 taken 28162 times.
✓ Branch 9 → 11 taken 13157 times.
✓ Branch 10 → 11 taken 13869 times.
✓ Branch 10 → 12 taken 14293 times.
✓ Branch 13 → 14 taken 27026 times.
✓ Branch 13 → 15 taken 14293 times.
41319 if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) {
111 27026 manIdx++; // Increase the manifestation index
112 27026 continue;
113 }
114
115 // Change scope to concrete struct specialization scope
116
2/2
✓ Branch 15 → 16 taken 12200 times.
✓ Branch 15 → 21 taken 2093 times.
14293 if (node->isMethod) {
117
2/4
✓ Branch 16 → 17 taken 12200 times.
✗ Branch 16 → 79 not taken.
✓ Branch 17 → 18 taken 12200 times.
✗ Branch 17 → 79 not taken.
12200 const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes());
118
1/2
✓ Branch 18 → 19 taken 12200 times.
✗ Branch 18 → 77 not taken.
12200 changeToScope(scopeName, ScopeType::STRUCT);
119 12200 }
120
121 // Change to procedure scope
122
1/2
✓ Branch 21 → 22 taken 14293 times.
✗ Branch 21 → 88 not taken.
14293 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 14293 times.
14293 assert(typeMapping.empty());
126
1/2
✓ Branch 25 → 26 taken 14293 times.
✗ Branch 25 → 88 not taken.
14293 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 10747 times.
✓ Branch 26 → 53 taken 3546 times.
14293 if (node->hasParams) {
131
1/2
✓ Branch 27 → 28 taken 10747 times.
✗ Branch 27 → 80 not taken.
10747 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 14866 times.
✓ Branch 52 → 53 taken 10747 times.
25613 for (size_t i = 0; i < manifestation->paramList.size(); i++) {
135
1/2
✓ Branch 30 → 31 taken 14866 times.
✗ Branch 30 → 86 not taken.
14866 const DeclStmtNode *param = node->paramLst->params.at(i);
136
2/4
✓ Branch 31 → 32 taken 14866 times.
✗ Branch 31 → 83 not taken.
✓ Branch 32 → 33 taken 14866 times.
✗ Branch 32 → 81 not taken.
14866 const QualType paramType = manifestation->getParamTypes().at(i);
137
8/10
✓ Branch 34 → 35 taken 14866 times.
✗ Branch 34 → 84 not taken.
✓ Branch 35 → 36 taken 60 times.
✓ Branch 35 → 39 taken 14806 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 14852 times.
14866 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 6313 times.
✓ Branch 53 → 55 taken 7980 times.
14293 if (node->isCtor)
147
1/2
✓ Branch 54 → 55 taken 6313 times.
✗ Branch 54 → 88 not taken.
6313 createCtorBodyPreamble(node->scope);
148
149 // Visit statements in new scope
150
1/2
✓ Branch 55 → 56 taken 14293 times.
✗ Branch 55 → 87 not taken.
14293 visit(node->body);
151
152 // Clear type mapping
153 14293 typeMapping.clear();
154
155 // Change to root scope
156 14293 currentScope = rootScope;
157
2/4
✓ Branch 58 → 59 taken 14293 times.
✗ Branch 58 → 61 not taken.
✓ Branch 59 → 60 taken 14293 times.
✗ Branch 59 → 61 not taken.
14293 assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL);
158
159 // Do not type-check this manifestation again
160 14293 manifestation->alreadyTypeChecked = true;
161
162 14293 manIdx++; // Increase the manifestation index
163 }
164 27897 manIdx = 0; // Reset the manifestation index
165
166
1/2
✓ Branch 73 → 74 taken 27897 times.
✗ Branch 73 → 89 not taken.
55794 return nullptr;
167 }
168
169 6221 std::any TypeChecker::visitStructDefCheck(StructDefNode *node) {
170 6221 node->resizeToNumberOfManifestations(node->structManifestations.size());
171 6221 manIdx = 0; // Reset the manifestation index
172
173 // Get all manifestations for this procedure definition
174
2/2
✓ Branch 215 → 6 taken 10836 times.
✓ Branch 215 → 216 taken 6221 times.
23278 for (Struct *manifestation : node->structManifestations) {
175 // Skip non-substantiated or already checked procedures
176
3/4
✓ Branch 8 → 9 taken 10836 times.
✗ Branch 8 → 299 not taken.
✓ Branch 9 → 10 taken 1894 times.
✓ Branch 9 → 11 taken 8942 times.
10836 if (!manifestation->isFullySubstantiated()) {
177 1894 manIdx++; // Increase the manifestation index
178 1894 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 8942 times.
✗ Branch 11 → 299 not taken.
8942 createImplicitDefaultMembers(*manifestation, node, /*withMoveCtor=*/false);
185
186 // Change to struct scope
187
1/2
✓ Branch 12 → 13 taken 8942 times.
✗ Branch 12 → 299 not taken.
8942 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 8942 times.
8942 assert(typeMapping.empty());
193
1/2
✓ Branch 16 → 17 taken 8942 times.
✗ Branch 16 → 299 not taken.
8942 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 18990 times.
✓ Branch 40 → 41 taken 8942 times.
36874 for (const FieldNode *field : node->fields) {
197
2/2
✓ Branch 21 → 22 taken 7672 times.
✓ Branch 21 → 31 taken 11318 times.
18990 if (field->defaultValue != nullptr) {
198
1/2
✓ Branch 22 → 23 taken 7672 times.
✗ Branch 22 → 220 not taken.
7672 visit(field->defaultValue);
199
1/2
✓ Branch 24 → 25 taken 7672 times.
✗ Branch 24 → 222 not taken.
7672 SymbolTableEntry *fieldEntry = manifestation->scope->lookupStrict(field->fieldName);
200
1/2
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 7672 times.
7672 assert(fieldEntry != nullptr);
201
1/2
✓ Branch 29 → 30 taken 7672 times.
✗ Branch 29 → 221 not taken.
7672 fieldEntry->updateState(INITIALIZED, field);
202 }
203 }
204
205 // Build struct type
206
1/2
✓ Branch 41 → 42 taken 8942 times.
✗ Branch 41 → 299 not taken.
8942 const QualType structType = manifestation->entry->getQualType();
207
208 // Check if the struct implements all methods of all attached interfaces
209 8942 size_t vtableIndex = 0;
210
2/2
✓ Branch 146 → 44 taken 2408 times.
✓ Branch 146 → 147 taken 8942 times.
20292 for (const QualType &interfaceType : manifestation->interfaceTypes) {
211
1/2
✓ Branch 46 → 47 taken 2408 times.
✗ Branch 46 → 266 not taken.
2408 const Interface *interface = interfaceType.getInterface(node);
212
1/2
✗ Branch 47 → 48 not taken.
✓ Branch 47 → 49 taken 2408 times.
2408 assert(interface != nullptr);
213
214 // Check for all methods, that it is implemented by the struct
215
2/2
✓ Branch 136 → 51 taken 7060 times.
✓ Branch 136 → 137 taken 2408 times.
11876 for (const Function *expMethod : interface->methods) {
216
1/2
✓ Branch 53 → 54 taken 7060 times.
✗ Branch 53 → 264 not taken.
7060 const std::string methodName = expMethod->name;
217
1/2
✓ Branch 54 → 55 taken 7060 times.
✗ Branch 54 → 262 not taken.
7060 QualTypeList params = expMethod->getParamTypes();
218 7060 QualType returnType = expMethod->returnType;
219
220 // Substantiate param and return types
221
1/2
✓ Branch 55 → 56 taken 7060 times.
✗ Branch 55 → 260 not taken.
7060 TypeMatcher::substantiateTypesWithTypeMapping(params, interface->typeMapping, node);
222
3/4
✓ Branch 56 → 57 taken 7060 times.
✗ Branch 56 → 260 not taken.
✓ Branch 57 → 58 taken 3424 times.
✓ Branch 57 → 59 taken 3636 times.
7060 if (returnType.hasAnyGenericParts())
223
1/2
✓ Branch 58 → 59 taken 3424 times.
✗ Branch 58 → 260 not taken.
3424 TypeMatcher::substantiateTypeWithTypeMapping(returnType, interface->typeMapping, node);
224
225 // Build args list
226 7060 ArgList args;
227
1/2
✓ Branch 60 → 61 taken 7060 times.
✗ Branch 60 → 258 not taken.
7060 args.reserve(params.size());
228
2/2
✓ Branch 75 → 63 taken 1080 times.
✓ Branch 75 → 76 taken 7060 times.
15200 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 7060 times.
✗ Branch 77 → 225 not taken.
7060 Function *spiceFunction = FunctionManager::match(currentScope, methodName, structType, args, {}, true, node);
233
2/2
✓ Branch 79 → 80 taken 4 times.
✓ Branch 79 → 92 taken 7056 times.
7060 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 7056 times.
✗ Branch 92 → 258 not taken.
✓ Branch 93 → 94 taken 1122 times.
✓ Branch 93 → 97 taken 5934 times.
✓ Branch 98 → 99 taken 2 times.
✓ Branch 98 → 111 taken 7054 times.
8178 if (spiceFunction->returnType != returnType &&
241
3/4
✓ Branch 94 → 95 taken 1122 times.
✗ Branch 94 → 258 not taken.
✓ Branch 95 → 96 taken 2 times.
✓ Branch 95 → 97 taken 1120 times.
1122 !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 7054 spiceFunction->isVirtual = true;
249 7054 spiceFunction->vtableIndex = vtableIndex++;
250
6/6
✓ Branch 113 → 114 taken 7054 times.
✓ Branch 113 → 115 taken 6 times.
✓ Branch 118 → 119 taken 7054 times.
✓ Branch 118 → 120 taken 6 times.
✓ Branch 123 → 124 taken 7054 times.
✓ Branch 123 → 126 taken 6 times.
21180 }
251 }
252
253 // Check default ctor body if required
254
2/4
✓ Branch 150 → 151 taken 8942 times.
✗ Branch 150 → 269 not taken.
✓ Branch 151 → 152 taken 8942 times.
✗ Branch 151 → 267 not taken.
26826 const Function *ctorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, {}, true);
255
4/4
✓ Branch 155 → 156 taken 2268 times.
✓ Branch 155 → 161 taken 6674 times.
✓ Branch 156 → 157 taken 324 times.
✓ Branch 156 → 161 taken 1944 times.
8942 if (ctorFunc != nullptr && ctorFunc->implicitDefault) {
256
1/2
✓ Branch 157 → 158 taken 324 times.
✗ Branch 157 → 299 not taken.
324 createCtorBodyPreamble(ctorFunc->bodyScope);
257
2/4
✓ Branch 158 → 159 taken 324 times.
✗ Branch 158 → 299 not taken.
✗ Branch 159 → 160 not taken.
✓ Branch 159 → 161 taken 324 times.
324 assert(manifestation->areAllFieldsInitialized() == nullptr);
258 }
259
260 // Check default copy ctor body if required
261
2/4
✓ Branch 161 → 162 taken 8942 times.
✗ Branch 161 → 280 not taken.
✓ Branch 165 → 166 taken 8942 times.
✗ Branch 165 → 276 not taken.
26826 const ArgList args = {{structType.toConstRef(node), false /* always non-temporary */}};
262
2/4
✓ Branch 169 → 170 taken 8942 times.
✗ Branch 169 → 284 not taken.
✓ Branch 170 → 171 taken 8942 times.
✗ Branch 170 → 282 not taken.
8942 const Function *copyCtorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, args, true);
263
4/4
✓ Branch 173 → 174 taken 4793 times.
✓ Branch 173 → 179 taken 4149 times.
✓ Branch 174 → 175 taken 3623 times.
✓ Branch 174 → 179 taken 1170 times.
8942 if (copyCtorFunc != nullptr && copyCtorFunc->implicitDefault) {
264
1/2
✓ Branch 175 → 176 taken 3623 times.
✗ Branch 175 → 297 not taken.
3623 createCopyCtorBodyPreamble(copyCtorFunc->bodyScope);
265
2/4
✓ Branch 176 → 177 taken 3623 times.
✗ Branch 176 → 297 not taken.
✗ Branch 177 → 178 not taken.
✓ Branch 177 → 179 taken 3623 times.
3623 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 8942 times.
✗ Branch 179 → 297 not taken.
✓ Branch 180 → 181 taken 123 times.
✓ Branch 180 → 186 taken 8819 times.
8942 if (const Function *moveCtorFunc = FunctionManager::findMoveCtor(currentScope);
271
2/2
✓ Branch 181 → 182 taken 17 times.
✓ Branch 181 → 186 taken 106 times.
123 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 8942 times.
✗ Branch 189 → 290 not taken.
✓ Branch 190 → 191 taken 8942 times.
✗ Branch 190 → 288 not taken.
26826 const Function *dtorFunc = FunctionManager::lookup(currentScope, DTOR_FUNCTION_NAME, structType, {}, true);
278
4/4
✓ Branch 194 → 195 taken 5179 times.
✓ Branch 194 → 197 taken 3763 times.
✓ Branch 195 → 196 taken 3553 times.
✓ Branch 195 → 197 taken 1626 times.
8942 if (dtorFunc != nullptr && dtorFunc->implicitDefault)
279
1/2
✓ Branch 196 → 197 taken 3553 times.
✗ Branch 196 → 297 not taken.
3553 createDtorBodyPreamble(dtorFunc->bodyScope, node);
280
281 // Reset field symbols to declared state for the next manifestation
282
1/2
✓ Branch 197 → 198 taken 8942 times.
✗ Branch 197 → 297 not taken.
8942 manifestation->resetFieldSymbolsToDeclared(node);
283
284 // Clear type mapping
285 8942 typeMapping.clear();
286
287 // Return to the root scope
288 8942 currentScope = rootScope;
289
2/4
✓ Branch 199 → 200 taken 8942 times.
✗ Branch 199 → 202 not taken.
✓ Branch 200 → 201 taken 8942 times.
✗ Branch 200 → 202 not taken.
8942 assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL);
290
291 8942 manIdx++; // Increase the manifestation index
292 8942 }
293 6221 manIdx = 0; // Reset the manifestation index
294
295
1/2
✓ Branch 216 → 217 taken 6221 times.
✗ Branch 216 → 301 not taken.
12442 return nullptr;
296 }
297
298 } // namespace spice::compiler
299