GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 146 / 0 / 146
Functions: 100.0% 4 / 0 / 4
Branches: 65.6% 198 / 0 / 302

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 574 std::any TypeChecker::visitMainFctDefCheck(MainFctDefNode *node) {
17 // Skip if already type-checked
18
2/2
✓ Branch 2 → 3 taken 66 times.
✓ Branch 2 → 6 taken 508 times.
574 if (typeCheckedMainFct)
19
1/2
✓ Branch 3 → 4 taken 66 times.
✗ Branch 3 → 13 not taken.
132 return nullptr;
20
21 508 node->resizeToNumberOfManifestations(1);
22
23 // Change to function body scope
24 508 currentScope = node->bodyScope;
25 // Visit statements in new scope
26
2/2
✓ Branch 7 → 8 taken 478 times.
✓ Branch 7 → 14 taken 30 times.
508 visit(node->body);
27 // Leave main function body scope
28 478 currentScope = rootScope;
29
30 // Set to type-checked
31 478 typeCheckedMainFct = true;
32
1/2
✓ Branch 9 → 10 taken 478 times.
✗ Branch 9 → 15 not taken.
956 return nullptr;
33 }
34
35 41871 std::any TypeChecker::visitFctDefCheck(FctDefNode *node) {
36 41871 node->resizeToNumberOfManifestations(node->manifestations.size());
37 41871 manIdx = 0; // Reset the manifestation index
38
39 // Get all manifestations for this function definition
40
2/2
✓ Branch 79 → 6 taken 57220 times.
✓ Branch 79 → 80 taken 41869 times.
140960 for (Function *manifestation : node->manifestations) {
41 // Skip non-substantiated or already checked functions
42
7/8
✓ Branch 8 → 9 taken 57220 times.
✗ Branch 8 → 101 not taken.
✓ Branch 9 → 10 taken 46543 times.
✓ Branch 9 → 11 taken 10677 times.
✓ Branch 10 → 11 taken 24333 times.
✓ Branch 10 → 12 taken 22210 times.
✓ Branch 13 → 14 taken 35010 times.
✓ Branch 13 → 15 taken 22210 times.
57220 if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) {
43 35010 manIdx++; // Increase the manifestation index
44 35010 continue;
45 }
46
47 // Change scope to concrete struct specialization scope
48
2/2
✓ Branch 15 → 16 taken 13131 times.
✓ Branch 15 → 21 taken 9079 times.
22210 if (node->isMethod) {
49
2/4
✓ Branch 16 → 17 taken 13131 times.
✗ Branch 16 → 86 not taken.
✓ Branch 17 → 18 taken 13131 times.
✗ Branch 17 → 86 not taken.
13131 const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes());
50
1/2
✓ Branch 18 → 19 taken 13131 times.
✗ Branch 18 → 84 not taken.
13131 changeToScope(scopeName, ScopeType::STRUCT);
51 13131 }
52
53 // Change to function scope
54
1/2
✓ Branch 21 → 22 taken 22210 times.
✗ Branch 21 → 101 not taken.
22210 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 22210 times.
22210 assert(typeMapping.empty());
58
1/2
✓ Branch 25 → 26 taken 22210 times.
✗ Branch 25 → 101 not taken.
22210 typeMapping = manifestation->typeMapping;
59
60 // Set return type to the result variable
61
1/2
✓ Branch 28 → 29 taken 22210 times.
✗ Branch 28 → 89 not taken.
66630 SymbolTableEntry *resultVarEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME);
62
1/2
✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 22210 times.
22210 assert(resultVarEntry != nullptr);
63
1/2
✓ Branch 36 → 37 taken 22210 times.
✗ Branch 36 → 101 not taken.
22210 resultVarEntry->updateType(manifestation->returnType, false);
64 22210 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 15488 times.
✓ Branch 37 → 64 taken 6722 times.
22210 if (node->hasParams) {
69
1/2
✓ Branch 38 → 39 taken 15488 times.
✗ Branch 38 → 93 not taken.
15488 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 22716 times.
✓ Branch 63 → 64 taken 15488 times.
38204 for (size_t i = 0; i < manifestation->paramList.size(); i++) {
73
1/2
✓ Branch 41 → 42 taken 22716 times.
✗ Branch 41 → 99 not taken.
22716 const DeclStmtNode *param = node->paramLst->params.at(i);
74
2/4
✓ Branch 42 → 43 taken 22716 times.
✗ Branch 42 → 96 not taken.
✓ Branch 43 → 44 taken 22716 times.
✗ Branch 43 → 94 not taken.
22716 const QualType paramType = manifestation->getParamTypes().at(i);
75
8/10
✓ Branch 45 → 46 taken 22716 times.
✗ Branch 45 → 97 not taken.
✓ Branch 46 → 47 taken 6 times.
✓ Branch 46 → 50 taken 22710 times.
✓ Branch 47 → 48 taken 6 times.
✗ Branch 47 → 97 not taken.
✓ Branch 48 → 49 taken 2 times.
✓ Branch 48 → 50 taken 4 times.
✓ Branch 51 → 52 taken 2 times.
✓ Branch 51 → 61 taken 22714 times.
22716 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 22208 times.
✓ Branch 64 → 100 taken 2 times.
22210 visit(node->body);
85
86 // Clear type mapping
87 22208 typeMapping.clear();
88
89 // Change to root scope
90 22208 currentScope = rootScope;
91
1/2
✗ Branch 67 → 68 not taken.
✓ Branch 67 → 69 taken 22208 times.
22208 assert(currentScope->type == ScopeType::GLOBAL);
92
93 // Do not type-check this manifestation again
94 22208 manifestation->alreadyTypeChecked = true;
95
96 22208 manIdx++; // Increase the manifestation index
97 }
98 41869 manIdx = 0; // Reset the manifestation index
99
100
1/2
✓ Branch 80 → 81 taken 41869 times.
✗ Branch 80 → 102 not taken.
83738 return nullptr;
101 }
102
103 22612 std::any TypeChecker::visitProcDefCheck(ProcDefNode *node) {
104 22612 node->resizeToNumberOfManifestations(node->manifestations.size());
105 22612 manIdx = 0; // Reset the manifestation index
106
107 // Get all manifestations for this procedure definition
108
2/2
✓ Branch 72 → 6 taken 32460 times.
✓ Branch 72 → 73 taken 22612 times.
77684 for (Function *manifestation : node->manifestations) {
109 // Skip non-substantiated or already checked procedures
110
7/8
✓ Branch 8 → 9 taken 32460 times.
✗ Branch 8 → 88 not taken.
✓ Branch 9 → 10 taken 21362 times.
✓ Branch 9 → 11 taken 11098 times.
✓ Branch 10 → 11 taken 10193 times.
✓ Branch 10 → 12 taken 11169 times.
✓ Branch 13 → 14 taken 21291 times.
✓ Branch 13 → 15 taken 11169 times.
32460 if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) {
111 21291 manIdx++; // Increase the manifestation index
112 21291 continue;
113 }
114
115 // Change scope to concrete struct specialization scope
116
2/2
✓ Branch 15 → 16 taken 9469 times.
✓ Branch 15 → 21 taken 1700 times.
11169 if (node->isMethod) {
117
2/4
✓ Branch 16 → 17 taken 9469 times.
✗ Branch 16 → 79 not taken.
✓ Branch 17 → 18 taken 9469 times.
✗ Branch 17 → 79 not taken.
9469 const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes());
118
1/2
✓ Branch 18 → 19 taken 9469 times.
✗ Branch 18 → 77 not taken.
9469 changeToScope(scopeName, ScopeType::STRUCT);
119 9469 }
120
121 // Change to procedure scope
122
1/2
✓ Branch 21 → 22 taken 11169 times.
✗ Branch 21 → 88 not taken.
11169 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 11169 times.
11169 assert(typeMapping.empty());
126
1/2
✓ Branch 25 → 26 taken 11169 times.
✗ Branch 25 → 88 not taken.
11169 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 8554 times.
✓ Branch 26 → 53 taken 2615 times.
11169 if (node->hasParams) {
131
1/2
✓ Branch 27 → 28 taken 8554 times.
✗ Branch 27 → 80 not taken.
8554 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 12311 times.
✓ Branch 52 → 53 taken 8554 times.
20865 for (size_t i = 0; i < manifestation->paramList.size(); i++) {
135
1/2
✓ Branch 30 → 31 taken 12311 times.
✗ Branch 30 → 86 not taken.
12311 const DeclStmtNode *param = node->paramLst->params.at(i);
136
2/4
✓ Branch 31 → 32 taken 12311 times.
✗ Branch 31 → 83 not taken.
✓ Branch 32 → 33 taken 12311 times.
✗ Branch 32 → 81 not taken.
12311 const QualType paramType = manifestation->getParamTypes().at(i);
137
8/10
✓ Branch 34 → 35 taken 12311 times.
✗ Branch 34 → 84 not taken.
✓ Branch 35 → 36 taken 59 times.
✓ Branch 35 → 39 taken 12252 times.
✓ Branch 36 → 37 taken 59 times.
✗ Branch 36 → 84 not taken.
✓ Branch 37 → 38 taken 13 times.
✓ Branch 37 → 39 taken 46 times.
✓ Branch 40 → 41 taken 13 times.
✓ Branch 40 → 50 taken 12298 times.
12311 if (paramType.isOneOf({TY_FUNCTION, TY_PROCEDURE}) && paramType.hasLambdaCaptures()) {
138
1/2
✓ Branch 41 → 42 taken 13 times.
✗ Branch 41 → 86 not taken.
13 SymbolTableEntry *paramSymbol = currentScope->lookupStrict(param->varName);
139
1/2
✗ Branch 44 → 45 not taken.
✓ Branch 44 → 46 taken 13 times.
13 assert(paramSymbol != nullptr);
140
3/6
✓ Branch 46 → 47 taken 13 times.
✗ Branch 46 → 85 not taken.
✓ Branch 47 → 48 taken 13 times.
✗ Branch 47 → 85 not taken.
✓ Branch 48 → 49 taken 13 times.
✗ Branch 48 → 85 not taken.
13 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 5286 times.
✓ Branch 53 → 55 taken 5883 times.
11169 if (node->isCtor)
147
1/2
✓ Branch 54 → 55 taken 5286 times.
✗ Branch 54 → 88 not taken.
5286 createCtorBodyPreamble(node->scope);
148
149 // Visit statements in new scope
150
1/2
✓ Branch 55 → 56 taken 11169 times.
✗ Branch 55 → 87 not taken.
11169 visit(node->body);
151
152 // Clear type mapping
153 11169 typeMapping.clear();
154
155 // Change to root scope
156 11169 currentScope = rootScope;
157
2/4
✓ Branch 58 → 59 taken 11169 times.
✗ Branch 58 → 61 not taken.
✓ Branch 59 → 60 taken 11169 times.
✗ Branch 59 → 61 not taken.
11169 assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL);
158
159 // Do not type-check this manifestation again
160 11169 manifestation->alreadyTypeChecked = true;
161
162 11169 manIdx++; // Increase the manifestation index
163 }
164 22612 manIdx = 0; // Reset the manifestation index
165
166
1/2
✓ Branch 73 → 74 taken 22612 times.
✗ Branch 73 → 89 not taken.
45224 return nullptr;
167 }
168
169 5296 std::any TypeChecker::visitStructDefCheck(StructDefNode *node) {
170 5296 node->resizeToNumberOfManifestations(node->structManifestations.size());
171 5296 manIdx = 0; // Reset the manifestation index
172
173 // Get all manifestations for this procedure definition
174
2/2
✓ Branch 214 → 6 taken 9244 times.
✓ Branch 214 → 215 taken 5296 times.
19836 for (const Struct *manifestation : node->structManifestations) {
175 // Skip non-substantiated or already checked procedures
176
3/4
✓ Branch 8 → 9 taken 9244 times.
✗ Branch 8 → 298 not taken.
✓ Branch 9 → 10 taken 1543 times.
✓ Branch 9 → 11 taken 7701 times.
9244 if (!manifestation->isFullySubstantiated()) {
177 1543 manIdx++; // Increase the manifestation index
178 1543 continue;
179 }
180
181 // Change to struct scope
182
1/2
✓ Branch 11 → 12 taken 7701 times.
✗ Branch 11 → 298 not taken.
7701 changeToScope(manifestation->scope, ScopeType::STRUCT);
183
184 // Mount type mapping for this manifestation, so that the body preamble helpers below can substantiate
185 // generic field types (e.g. `heap T*` on `Vector<T>`). Without this, an auto-generated body preamble that
186 // touches a still-generic field would assert in TypeMatcher::substantiateTypeWithTypeMapping.
187
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 7701 times.
7701 assert(typeMapping.empty());
188
1/2
✓ Branch 15 → 16 taken 7701 times.
✗ Branch 15 → 298 not taken.
7701 typeMapping = manifestation->typeMapping;
189
190 // Re-visit all default values. This is required, since the type of the default value might vary for different manifestations
191
2/2
✓ Branch 39 → 18 taken 16049 times.
✓ Branch 39 → 40 taken 7701 times.
31451 for (const FieldNode *field : node->fields) {
192
2/2
✓ Branch 20 → 21 taken 4020 times.
✓ Branch 20 → 30 taken 12029 times.
16049 if (field->defaultValue != nullptr) {
193
1/2
✓ Branch 21 → 22 taken 4020 times.
✗ Branch 21 → 219 not taken.
4020 visit(field->defaultValue);
194
1/2
✓ Branch 23 → 24 taken 4020 times.
✗ Branch 23 → 221 not taken.
4020 SymbolTableEntry *fieldEntry = manifestation->scope->lookupStrict(field->fieldName);
195
1/2
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 28 taken 4020 times.
4020 assert(fieldEntry != nullptr);
196
1/2
✓ Branch 28 → 29 taken 4020 times.
✗ Branch 28 → 220 not taken.
4020 fieldEntry->updateState(INITIALIZED, field);
197 }
198 }
199
200 // Build struct type
201
1/2
✓ Branch 40 → 41 taken 7701 times.
✗ Branch 40 → 298 not taken.
7701 const QualType structType = manifestation->entry->getQualType();
202
203 // Check if the struct implements all methods of all attached interfaces
204 7701 size_t vtableIndex = 0;
205
2/2
✓ Branch 145 → 43 taken 2466 times.
✓ Branch 145 → 146 taken 7701 times.
17868 for (const QualType &interfaceType : manifestation->interfaceTypes) {
206
1/2
✓ Branch 45 → 46 taken 2466 times.
✗ Branch 45 → 265 not taken.
2466 const Interface *interface = interfaceType.getInterface(node);
207
1/2
✗ Branch 46 → 47 not taken.
✓ Branch 46 → 48 taken 2466 times.
2466 assert(interface != nullptr);
208
209 // Check for all methods, that it is implemented by the struct
210
2/2
✓ Branch 135 → 50 taken 7018 times.
✓ Branch 135 → 136 taken 2466 times.
11950 for (const Function *expMethod : interface->methods) {
211
1/2
✓ Branch 52 → 53 taken 7018 times.
✗ Branch 52 → 263 not taken.
7018 const std::string methodName = expMethod->name;
212
1/2
✓ Branch 53 → 54 taken 7018 times.
✗ Branch 53 → 261 not taken.
7018 QualTypeList params = expMethod->getParamTypes();
213 7018 QualType returnType = expMethod->returnType;
214
215 // Substantiate param and return types
216
1/2
✓ Branch 54 → 55 taken 7018 times.
✗ Branch 54 → 259 not taken.
7018 TypeMatcher::substantiateTypesWithTypeMapping(params, interface->typeMapping, node);
217
3/4
✓ Branch 55 → 56 taken 7018 times.
✗ Branch 55 → 259 not taken.
✓ Branch 56 → 57 taken 3532 times.
✓ Branch 56 → 58 taken 3486 times.
7018 if (returnType.hasAnyGenericParts())
218
1/2
✓ Branch 57 → 58 taken 3532 times.
✗ Branch 57 → 259 not taken.
3532 TypeMatcher::substantiateTypeWithTypeMapping(returnType, interface->typeMapping, node);
219
220 // Build args list
221 7018 ArgList args;
222
1/2
✓ Branch 59 → 60 taken 7018 times.
✗ Branch 59 → 257 not taken.
7018 args.reserve(params.size());
223
2/2
✓ Branch 74 → 62 taken 918 times.
✓ Branch 74 → 75 taken 7018 times.
14954 for (const QualType &param : params)
224
1/2
✓ Branch 64 → 65 taken 918 times.
✗ Branch 64 → 222 not taken.
918 args.emplace_back(param, nullptr);
225
226 // Search for method that has the required signature
227
1/2
✓ Branch 76 → 77 taken 7018 times.
✗ Branch 76 → 224 not taken.
7018 Function *spiceFunction = FunctionManager::match(currentScope, methodName, structType, args, {}, true, node);
228
2/2
✓ Branch 78 → 79 taken 4 times.
✓ Branch 78 → 91 taken 7014 times.
7018 if (spiceFunction == nullptr) {
229
1/2
✓ Branch 84 → 85 taken 4 times.
✗ Branch 84 → 227 not taken.
4 softError(node, INTERFACE_METHOD_NOT_IMPLEMENTED,
230
5/10
✓ Branch 79 → 80 taken 4 times.
✗ Branch 79 → 239 not taken.
✓ Branch 80 → 81 taken 4 times.
✗ Branch 80 → 235 not taken.
✓ Branch 81 → 82 taken 4 times.
✗ Branch 81 → 233 not taken.
✓ Branch 82 → 83 taken 4 times.
✗ Branch 82 → 231 not taken.
✓ Branch 83 → 84 taken 4 times.
✗ Branch 83 → 229 not taken.
8 "The struct '" + node->structName + "' does not implement method '" + expMethod->getSignature() + "'.");
231 4 continue;
232 }
233
234 // Check return type
235
5/6
✓ Branch 91 → 92 taken 7014 times.
✗ Branch 91 → 257 not taken.
✓ Branch 92 → 93 taken 1158 times.
✓ Branch 92 → 96 taken 5856 times.
✓ Branch 97 → 98 taken 2 times.
✓ Branch 97 → 110 taken 7012 times.
8172 if (spiceFunction->returnType != returnType &&
236
3/4
✓ Branch 93 → 94 taken 1158 times.
✗ Branch 93 → 257 not taken.
✓ Branch 94 → 95 taken 2 times.
✓ Branch 94 → 96 taken 1156 times.
1158 !returnType.matchesInterfaceImplementedByStruct(spiceFunction->returnType)) {
237
1/2
✓ Branch 103 → 104 taken 2 times.
✗ Branch 103 → 242 not taken.
2 softError(node, INTERFACE_METHOD_NOT_IMPLEMENTED,
238
4/8
✓ Branch 98 → 99 taken 2 times.
✗ Branch 98 → 254 not taken.
✓ Branch 99 → 100 taken 2 times.
✗ Branch 99 → 250 not taken.
✓ Branch 100 → 101 taken 2 times.
✗ Branch 100 → 248 not taken.
✓ Branch 101 → 102 taken 2 times.
✗ Branch 101 → 246 not taken.
4 "The struct '" + node->structName + "' does not implement method '" + expMethod->getSignature() +
239
1/2
✓ Branch 102 → 103 taken 2 times.
✗ Branch 102 → 244 not taken.
2 "'. The return type does not match.");
240 2 continue;
241 }
242 // Set to virtual, since it overrides the interface method
243 7012 spiceFunction->isVirtual = true;
244 7012 spiceFunction->vtableIndex = vtableIndex++;
245
6/6
✓ Branch 112 → 113 taken 7012 times.
✓ Branch 112 → 114 taken 6 times.
✓ Branch 117 → 118 taken 7012 times.
✓ Branch 117 → 119 taken 6 times.
✓ Branch 122 → 123 taken 7012 times.
✓ Branch 122 → 125 taken 6 times.
21054 }
246 }
247
248 // Check default ctor body if required
249
2/4
✓ Branch 149 → 150 taken 7701 times.
✗ Branch 149 → 268 not taken.
✓ Branch 150 → 151 taken 7701 times.
✗ Branch 150 → 266 not taken.
23103 const Function *ctorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, {}, true);
250
4/4
✓ Branch 154 → 155 taken 1891 times.
✓ Branch 154 → 160 taken 5810 times.
✓ Branch 155 → 156 taken 327 times.
✓ Branch 155 → 160 taken 1564 times.
7701 if (ctorFunc != nullptr && ctorFunc->implicitDefault) {
251
1/2
✓ Branch 156 → 157 taken 327 times.
✗ Branch 156 → 298 not taken.
327 createCtorBodyPreamble(ctorFunc->bodyScope);
252
2/4
✓ Branch 157 → 158 taken 327 times.
✗ Branch 157 → 298 not taken.
✗ Branch 158 → 159 not taken.
✓ Branch 158 → 160 taken 327 times.
327 assert(manifestation->areAllFieldsInitialized() == nullptr);
253 }
254
255 // Check default copy ctor body if required
256
2/4
✓ Branch 160 → 161 taken 7701 times.
✗ Branch 160 → 279 not taken.
✓ Branch 164 → 165 taken 7701 times.
✗ Branch 164 → 275 not taken.
23103 const ArgList args = {{structType.toConstRef(node), false /* always non-temporary */}};
257
2/4
✓ Branch 168 → 169 taken 7701 times.
✗ Branch 168 → 283 not taken.
✓ Branch 169 → 170 taken 7701 times.
✗ Branch 169 → 281 not taken.
7701 const Function *copyCtorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, args, true);
258
4/4
✓ Branch 172 → 173 taken 3779 times.
✓ Branch 172 → 178 taken 3922 times.
✓ Branch 173 → 174 taken 2793 times.
✓ Branch 173 → 178 taken 986 times.
7701 if (copyCtorFunc != nullptr && copyCtorFunc->implicitDefault) {
259
1/2
✓ Branch 174 → 175 taken 2793 times.
✗ Branch 174 → 296 not taken.
2793 createCopyCtorBodyPreamble(copyCtorFunc->bodyScope);
260
2/4
✓ Branch 175 → 176 taken 2793 times.
✗ Branch 175 → 296 not taken.
✗ Branch 176 → 177 not taken.
✓ Branch 176 → 178 taken 2793 times.
2793 assert(manifestation->areAllFieldsInitialized() == nullptr);
261 }
262
263 // Check default move ctor body if required. findMoveCtor scans the manifestations directly to avoid the
264 // constify-based false-positive that FunctionManager::lookup with a non-const ref arg can produce.
265
5/6
✓ Branch 178 → 179 taken 7701 times.
✗ Branch 178 → 296 not taken.
✓ Branch 179 → 180 taken 22 times.
✓ Branch 179 → 185 taken 7679 times.
✓ Branch 180 → 181 taken 17 times.
✓ Branch 180 → 185 taken 5 times.
7701 if (const Function *moveCtorFunc = FunctionManager::findMoveCtor(currentScope); moveCtorFunc && moveCtorFunc->implicitDefault) {
266
1/2
✓ Branch 181 → 182 taken 17 times.
✗ Branch 181 → 296 not taken.
17 createMoveCtorBodyPreamble(moveCtorFunc->bodyScope);
267
2/4
✓ Branch 182 → 183 taken 17 times.
✗ Branch 182 → 296 not taken.
✗ Branch 183 → 184 not taken.
✓ Branch 183 → 185 taken 17 times.
17 assert(manifestation->areAllFieldsInitialized() == nullptr);
268 }
269
270 // Check default dtor body if required
271
2/4
✓ Branch 188 → 189 taken 7701 times.
✗ Branch 188 → 289 not taken.
✓ Branch 189 → 190 taken 7701 times.
✗ Branch 189 → 287 not taken.
23103 const Function *dtorFunc = FunctionManager::lookup(currentScope, DTOR_FUNCTION_NAME, structType, {}, true);
272
4/4
✓ Branch 193 → 194 taken 4091 times.
✓ Branch 193 → 196 taken 3610 times.
✓ Branch 194 → 195 taken 3315 times.
✓ Branch 194 → 196 taken 776 times.
7701 if (dtorFunc != nullptr && dtorFunc->implicitDefault)
273
1/2
✓ Branch 195 → 196 taken 3315 times.
✗ Branch 195 → 296 not taken.
3315 createDtorBodyPreamble(dtorFunc->bodyScope);
274
275 // Reset field symbols to declared state for the next manifestation
276
1/2
✓ Branch 196 → 197 taken 7701 times.
✗ Branch 196 → 296 not taken.
7701 manifestation->resetFieldSymbolsToDeclared(node);
277
278 // Clear type mapping
279 7701 typeMapping.clear();
280
281 // Return to the root scope
282 7701 currentScope = rootScope;
283
2/4
✓ Branch 198 → 199 taken 7701 times.
✗ Branch 198 → 201 not taken.
✓ Branch 199 → 200 taken 7701 times.
✗ Branch 199 → 201 not taken.
7701 assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL);
284
285 7701 manIdx++; // Increase the manifestation index
286 7701 }
287 5296 manIdx = 0; // Reset the manifestation index
288
289
1/2
✓ Branch 215 → 216 taken 5296 times.
✗ Branch 215 → 300 not taken.
10592 return nullptr;
290 }
291
292 } // namespace spice::compiler
293