GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 170 / 0 / 170
Functions: 100.0% 5 / 0 / 5
Branches: 65.3% 218 / 0 / 334

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 <model/Union.h>
10 #include <symboltablebuilder/Scope.h>
11 #include <symboltablebuilder/SymbolTableBuilder.h>
12 #include <typechecker/FunctionManager.h>
13 #include <typechecker/TypeMatcher.h>
14
15 namespace spice::compiler {
16
17 1416 std::any TypeChecker::visitMainFctDefCheck(MainFctDefNode *node) {
18 // Skip if already type-checked
19
2/2
✓ Branch 2 → 3 taken 171 times.
✓ Branch 2 → 6 taken 1245 times.
1416 if (typeCheckedMainFct)
20
1/2
✓ Branch 3 → 4 taken 171 times.
✗ Branch 3 → 13 not taken.
342 return nullptr;
21
22 1245 node->resizeToNumberOfManifestations(1);
23
24 // Change to function body scope
25 1245 currentScope = node->bodyScope;
26 // Visit statements in new scope
27
2/2
✓ Branch 7 → 8 taken 1179 times.
✓ Branch 7 → 14 taken 66 times.
1245 visit(node->body);
28 // Leave main function body scope
29 1179 currentScope = rootScope;
30
31 // Set to type-checked
32 1179 typeCheckedMainFct = true;
33
1/2
✓ Branch 9 → 10 taken 1179 times.
✗ Branch 9 → 15 not taken.
2358 return nullptr;
34 }
35
36 245472 std::any TypeChecker::visitFctDefCheck(FctDefNode *node) {
37 245472 node->resizeToNumberOfManifestations(node->manifestations.size());
38 245472 manIdx = 0; // Reset the manifestation index
39
40 // Get all manifestations for this function definition
41
2/2
✓ Branch 79 → 6 taken 396993 times.
✓ Branch 79 → 80 taken 245468 times.
887933 for (Function *manifestation : node->manifestations) {
42 // Skip non-substantiated or already checked functions
43
7/8
✓ Branch 8 → 9 taken 396993 times.
✗ Branch 8 → 101 not taken.
✓ Branch 9 → 10 taken 350640 times.
✓ Branch 9 → 11 taken 46353 times.
✓ Branch 10 → 11 taken 183023 times.
✓ Branch 10 → 12 taken 167617 times.
✓ Branch 13 → 14 taken 229376 times.
✓ Branch 13 → 15 taken 167617 times.
396993 if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) {
44 229376 manIdx++; // Increase the manifestation index
45 229376 continue;
46 }
47
48 // Change scope to concrete struct specialization scope
49
2/2
✓ Branch 15 → 16 taken 127814 times.
✓ Branch 15 → 21 taken 39803 times.
167617 if (node->isMethod) {
50
2/4
✓ Branch 16 → 17 taken 127814 times.
✗ Branch 16 → 86 not taken.
✓ Branch 17 → 18 taken 127814 times.
✗ Branch 17 → 86 not taken.
127814 const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes());
51
1/2
✓ Branch 18 → 19 taken 127814 times.
✗ Branch 18 → 84 not taken.
127814 changeToScope(scopeName, ScopeType::STRUCT);
52 127814 }
53
54 // Change to function scope
55
1/2
✓ Branch 21 → 22 taken 167617 times.
✗ Branch 21 → 101 not taken.
167617 changeToScope(manifestation->bodyScope, ScopeType::FUNC_PROC_BODY);
56
57 // Mount type mapping for this manifestation
58
1/2
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 167617 times.
167617 assert(typeMapping.empty());
59
1/2
✓ Branch 25 → 26 taken 167617 times.
✗ Branch 25 → 101 not taken.
167617 typeMapping = manifestation->typeMapping;
60
61 // Set return type to the result variable
62
1/2
✓ Branch 28 → 29 taken 167617 times.
✗ Branch 28 → 89 not taken.
502851 SymbolTableEntry *resultVarEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME);
63
1/2
✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 167617 times.
167617 assert(resultVarEntry != nullptr);
64
1/2
✓ Branch 36 → 37 taken 167617 times.
✗ Branch 36 → 101 not taken.
167617 resultVarEntry->updateType(manifestation->returnType, false);
65 167617 resultVarEntry->used = true;
66
67 // Visit parameters
68 // This happens once in the type checker prepare stage. This second time is only required if we have a generic function
69
2/2
✓ Branch 37 → 38 taken 95084 times.
✓ Branch 37 → 64 taken 72533 times.
167617 if (node->hasParams) {
70
1/2
✓ Branch 38 → 39 taken 95084 times.
✗ Branch 38 → 93 not taken.
95084 visit(node->paramLst);
71 // Annotate function/procedure-typed params with lambda-capture info from the resolved manifestation type.
72 // This must happen in the TypeChecker so that the IRGenerator can treat SymbolTableEntry as immutable.
73
2/2
✓ Branch 63 → 41 taken 134267 times.
✓ Branch 63 → 64 taken 95084 times.
229351 for (size_t i = 0; i < manifestation->paramList.size(); i++) {
74
1/2
✓ Branch 41 → 42 taken 134267 times.
✗ Branch 41 → 99 not taken.
134267 const DeclStmtNode *param = node->paramLst->params.at(i);
75
2/4
✓ Branch 42 → 43 taken 134267 times.
✗ Branch 42 → 96 not taken.
✓ Branch 43 → 44 taken 134267 times.
✗ Branch 43 → 94 not taken.
134267 const QualType paramType = manifestation->getParamTypes().at(i);
76
8/10
✓ Branch 45 → 46 taken 134267 times.
✗ Branch 45 → 97 not taken.
✓ Branch 46 → 47 taken 136 times.
✓ Branch 46 → 50 taken 134131 times.
✓ Branch 47 → 48 taken 136 times.
✗ Branch 47 → 97 not taken.
✓ Branch 48 → 49 taken 106 times.
✓ Branch 48 → 50 taken 30 times.
✓ Branch 51 → 52 taken 106 times.
✓ Branch 51 → 61 taken 134161 times.
134267 if (paramType.isOneOf({TY_FUNCTION, TY_PROCEDURE}) && paramType.hasLambdaCaptures()) {
77
1/2
✓ Branch 52 → 53 taken 106 times.
✗ Branch 52 → 99 not taken.
106 SymbolTableEntry *paramSymbol = currentScope->lookupStrict(param->varName);
78
1/2
✗ Branch 55 → 56 not taken.
✓ Branch 55 → 57 taken 106 times.
106 assert(paramSymbol != nullptr);
79
3/6
✓ Branch 57 → 58 taken 106 times.
✗ Branch 57 → 98 not taken.
✓ Branch 58 → 59 taken 106 times.
✗ Branch 58 → 98 not taken.
✓ Branch 59 → 60 taken 106 times.
✗ Branch 59 → 98 not taken.
106 paramSymbol->updateType(paramSymbol->getQualType().getWithLambdaCaptures(), true);
80 }
81 }
82 }
83
84 // Visit statements in new scope
85
2/2
✓ Branch 64 → 65 taken 167613 times.
✓ Branch 64 → 100 taken 4 times.
167617 visit(node->body);
86
87 // Clear type mapping
88 167613 typeMapping.clear();
89
90 // Change to root scope
91 167613 currentScope = rootScope;
92
1/2
✗ Branch 67 → 68 not taken.
✓ Branch 67 → 69 taken 167613 times.
167613 assert(currentScope->type == ScopeType::GLOBAL);
93
94 // Do not type-check this manifestation again
95 167613 manifestation->alreadyTypeChecked = true;
96
97 167613 manIdx++; // Increase the manifestation index
98 }
99 245468 manIdx = 0; // Reset the manifestation index
100
101
1/2
✓ Branch 80 → 81 taken 245468 times.
✗ Branch 80 → 102 not taken.
490936 return nullptr;
102 }
103
104 116666 std::any TypeChecker::visitProcDefCheck(ProcDefNode *node) {
105 116666 node->resizeToNumberOfManifestations(node->manifestations.size());
106 116666 manIdx = 0; // Reset the manifestation index
107
108 // Get all manifestations for this procedure definition
109
2/2
✓ Branch 72 → 6 taken 253212 times.
✓ Branch 72 → 73 taken 116666 times.
486544 for (Function *manifestation : node->manifestations) {
110 // Skip non-substantiated or already checked procedures
111
7/8
✓ Branch 8 → 9 taken 253212 times.
✗ Branch 8 → 88 not taken.
✓ Branch 9 → 10 taken 208749 times.
✓ Branch 9 → 11 taken 44463 times.
✓ Branch 10 → 11 taken 109194 times.
✓ Branch 10 → 12 taken 99555 times.
✓ Branch 13 → 14 taken 153657 times.
✓ Branch 13 → 15 taken 99555 times.
253212 if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) {
112 153657 manIdx++; // Increase the manifestation index
113 153657 continue;
114 }
115
116 // Change scope to concrete struct specialization scope
117
2/2
✓ Branch 15 → 16 taken 87287 times.
✓ Branch 15 → 21 taken 12268 times.
99555 if (node->isMethod) {
118
2/4
✓ Branch 16 → 17 taken 87287 times.
✗ Branch 16 → 79 not taken.
✓ Branch 17 → 18 taken 87287 times.
✗ Branch 17 → 79 not taken.
87287 const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes());
119
1/2
✓ Branch 18 → 19 taken 87287 times.
✗ Branch 18 → 77 not taken.
87287 changeToScope(scopeName, ScopeType::STRUCT);
120 87287 }
121
122 // Change to procedure scope
123
1/2
✓ Branch 21 → 22 taken 99555 times.
✗ Branch 21 → 88 not taken.
99555 changeToScope(manifestation->bodyScope, ScopeType::FUNC_PROC_BODY);
124
125 // Mount type mapping for this manifestation
126
1/2
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 99555 times.
99555 assert(typeMapping.empty());
127
1/2
✓ Branch 25 → 26 taken 99555 times.
✗ Branch 25 → 88 not taken.
99555 typeMapping = manifestation->typeMapping;
128
129 // Visit parameters
130 // This happens once in the type checker prepare stage. This second time is only required if we have a generic procedure
131
2/2
✓ Branch 26 → 27 taken 72698 times.
✓ Branch 26 → 53 taken 26857 times.
99555 if (node->hasParams) {
132
1/2
✓ Branch 27 → 28 taken 72698 times.
✗ Branch 27 → 80 not taken.
72698 visit(node->paramLst);
133 // Annotate function/procedure-typed params with lambda-capture info from the resolved manifestation type.
134 // This must happen in the TypeChecker so that the IRGenerator can treat SymbolTableEntry as immutable.
135
2/2
✓ Branch 52 → 30 taken 102263 times.
✓ Branch 52 → 53 taken 72698 times.
174961 for (size_t i = 0; i < manifestation->paramList.size(); i++) {
136
1/2
✓ Branch 30 → 31 taken 102263 times.
✗ Branch 30 → 86 not taken.
102263 const DeclStmtNode *param = node->paramLst->params.at(i);
137
2/4
✓ Branch 31 → 32 taken 102263 times.
✗ Branch 31 → 83 not taken.
✓ Branch 32 → 33 taken 102263 times.
✗ Branch 32 → 81 not taken.
102263 const QualType paramType = manifestation->getParamTypes().at(i);
138
8/10
✓ Branch 34 → 35 taken 102263 times.
✗ Branch 34 → 84 not taken.
✓ Branch 35 → 36 taken 590 times.
✓ Branch 35 → 39 taken 101673 times.
✓ Branch 36 → 37 taken 590 times.
✗ Branch 36 → 84 not taken.
✓ Branch 37 → 38 taken 338 times.
✓ Branch 37 → 39 taken 252 times.
✓ Branch 40 → 41 taken 338 times.
✓ Branch 40 → 50 taken 101925 times.
102263 if (paramType.isOneOf({TY_FUNCTION, TY_PROCEDURE}) && paramType.hasLambdaCaptures()) {
139
1/2
✓ Branch 41 → 42 taken 338 times.
✗ Branch 41 → 86 not taken.
338 SymbolTableEntry *paramSymbol = currentScope->lookupStrict(param->varName);
140
1/2
✗ Branch 44 → 45 not taken.
✓ Branch 44 → 46 taken 338 times.
338 assert(paramSymbol != nullptr);
141
3/6
✓ Branch 46 → 47 taken 338 times.
✗ Branch 46 → 85 not taken.
✓ Branch 47 → 48 taken 338 times.
✗ Branch 47 → 85 not taken.
✓ Branch 48 → 49 taken 338 times.
✗ Branch 48 → 85 not taken.
338 paramSymbol->updateType(paramSymbol->getQualType().getWithLambdaCaptures(), true);
142 }
143 }
144 }
145
146 // Prepare generation of special ctor preamble to store VTable, default field values, etc. if required
147
2/2
✓ Branch 53 → 54 taken 40049 times.
✓ Branch 53 → 55 taken 59506 times.
99555 if (node->isCtor)
148
1/2
✓ Branch 54 → 55 taken 40049 times.
✗ Branch 54 → 88 not taken.
40049 createCtorBodyPreamble(manifestation->bodyScope);
149
150 // Visit statements in new scope
151
1/2
✓ Branch 55 → 56 taken 99555 times.
✗ Branch 55 → 87 not taken.
99555 visit(node->body);
152
153 // Clear type mapping
154 99555 typeMapping.clear();
155
156 // Change to root scope
157 99555 currentScope = rootScope;
158
2/4
✓ Branch 58 → 59 taken 99555 times.
✗ Branch 58 → 61 not taken.
✓ Branch 59 → 60 taken 99555 times.
✗ Branch 59 → 61 not taken.
99555 assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL);
159
160 // Do not type-check this manifestation again
161 99555 manifestation->alreadyTypeChecked = true;
162
163 99555 manIdx++; // Increase the manifestation index
164 }
165 116666 manIdx = 0; // Reset the manifestation index
166
167
1/2
✓ Branch 73 → 74 taken 116666 times.
✗ Branch 73 → 89 not taken.
233332 return nullptr;
168 }
169
170 28774 std::any TypeChecker::visitStructDefCheck(StructDefNode *node) {
171 28774 node->resizeToNumberOfManifestations(node->structManifestations.size());
172 28774 manIdx = 0; // Reset the manifestation index
173
174 // Get all manifestations for this procedure definition
175
2/2
✓ Branch 215 → 6 taken 70696 times.
✓ Branch 215 → 216 taken 28774 times.
128244 for (Struct *manifestation : node->structManifestations) {
176 // Skip non-substantiated or already checked procedures
177
3/4
✓ Branch 8 → 9 taken 70696 times.
✗ Branch 8 → 299 not taken.
✓ Branch 9 → 10 taken 7154 times.
✓ Branch 9 → 11 taken 63542 times.
70696 if (!manifestation->isFullySubstantiated()) {
178 7154 manIdx++; // Increase the manifestation index
179 7154 continue;
180 }
181
182 // Fallback for manifestations that could not be decided on when they were created, because a by-value struct field
183 // was not manifested yet at that point (circular import). By now the whole import graph is prepared, so the
184 // decision can be taken - late, but still before the struct's own default member bodies are prepared below.
185
1/2
✓ Branch 11 → 12 taken 63542 times.
✗ Branch 11 → 299 not taken.
63542 createImplicitDefaultMembers(*manifestation, node, /*withMoveCtor=*/false);
186
187 // Change to struct scope
188
1/2
✓ Branch 12 → 13 taken 63542 times.
✗ Branch 12 → 299 not taken.
63542 changeToScope(manifestation->scope, ScopeType::STRUCT);
189
190 // Mount type mapping for this manifestation, so that the body preamble helpers below can substantiate
191 // generic field types (e.g. `heap T*` on `Vector<T>`). Without this, an auto-generated body preamble that
192 // touches a still-generic field would assert in TypeMatcher::substantiateTypeWithTypeMapping.
193
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 63542 times.
63542 assert(typeMapping.empty());
194
1/2
✓ Branch 16 → 17 taken 63542 times.
✗ Branch 16 → 299 not taken.
63542 typeMapping = manifestation->typeMapping;
195
196 // Re-visit all default values. This is required, since the type of the default value might vary for different manifestations
197
2/2
✓ Branch 40 → 19 taken 202295 times.
✓ Branch 40 → 41 taken 63542 times.
329379 for (const FieldNode *field : node->fields) {
198
2/2
✓ Branch 21 → 22 taken 86807 times.
✓ Branch 21 → 31 taken 115488 times.
202295 if (field->defaultValue != nullptr) {
199
1/2
✓ Branch 22 → 23 taken 86807 times.
✗ Branch 22 → 220 not taken.
86807 visit(field->defaultValue);
200
1/2
✓ Branch 24 → 25 taken 86807 times.
✗ Branch 24 → 222 not taken.
86807 SymbolTableEntry *fieldEntry = manifestation->scope->lookupStrict(field->fieldName);
201
1/2
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 86807 times.
86807 assert(fieldEntry != nullptr);
202
1/2
✓ Branch 29 → 30 taken 86807 times.
✗ Branch 29 → 221 not taken.
86807 fieldEntry->updateState(INITIALIZED, field);
203 }
204 }
205
206 // Build struct type
207
1/2
✓ Branch 41 → 42 taken 63542 times.
✗ Branch 41 → 299 not taken.
63542 const QualType structType = manifestation->entry->getQualType();
208
209 // Check if the struct implements all methods of all attached interfaces
210 63542 size_t vtableIndex = 0;
211
2/2
✓ Branch 146 → 44 taken 31924 times.
✓ Branch 146 → 147 taken 63542 times.
159008 for (const QualType &interfaceType : manifestation->interfaceTypes) {
212
1/2
✓ Branch 46 → 47 taken 31924 times.
✗ Branch 46 → 266 not taken.
31924 const Interface *interface = interfaceType.getInterface(node);
213
1/2
✗ Branch 47 → 48 not taken.
✓ Branch 47 → 49 taken 31924 times.
31924 assert(interface != nullptr);
214
215 // Check for all methods, that it is implemented by the struct
216
2/2
✓ Branch 136 → 51 taken 106640 times.
✓ Branch 136 → 137 taken 31924 times.
170488 for (const Function *expMethod : interface->methods) {
217
1/2
✓ Branch 53 → 54 taken 106640 times.
✗ Branch 53 → 264 not taken.
106640 const std::string methodName = expMethod->name;
218
1/2
✓ Branch 54 → 55 taken 106640 times.
✗ Branch 54 → 262 not taken.
106640 QualTypeList params = expMethod->getParamTypes();
219 106640 QualType returnType = expMethod->returnType;
220
221 // Substantiate param and return types
222
1/2
✓ Branch 55 → 56 taken 106640 times.
✗ Branch 55 → 260 not taken.
106640 TypeMatcher::substantiateTypesWithTypeMapping(params, interface->typeMapping, node);
223
3/4
✓ Branch 56 → 57 taken 106640 times.
✗ Branch 56 → 260 not taken.
✓ Branch 57 → 58 taken 35132 times.
✓ Branch 57 → 59 taken 71508 times.
106640 if (returnType.hasAnyGenericParts())
224
1/2
✓ Branch 58 → 59 taken 35132 times.
✗ Branch 58 → 260 not taken.
35132 TypeMatcher::substantiateTypeWithTypeMapping(returnType, interface->typeMapping, node);
225
226 // Build args list
227 106640 ArgList args;
228
1/2
✓ Branch 60 → 61 taken 106640 times.
✗ Branch 60 → 258 not taken.
106640 args.reserve(params.size());
229
2/2
✓ Branch 75 → 63 taken 31872 times.
✓ Branch 75 → 76 taken 106640 times.
245152 for (const QualType &param : params)
230
1/2
✓ Branch 65 → 66 taken 31872 times.
✗ Branch 65 → 223 not taken.
31872 args.emplace_back(param, nullptr);
231
232 // Search for method that has the required signature
233
1/2
✓ Branch 77 → 78 taken 106640 times.
✗ Branch 77 → 225 not taken.
106640 Function *spiceFunction = FunctionManager::match(currentScope, methodName, structType, args, {}, true, node);
234
2/2
✓ Branch 79 → 80 taken 8 times.
✓ Branch 79 → 92 taken 106632 times.
106640 if (spiceFunction == nullptr) {
235
1/2
✓ Branch 85 → 86 taken 8 times.
✗ Branch 85 → 228 not taken.
8 softError(node, INTERFACE_METHOD_NOT_IMPLEMENTED,
236
5/10
✓ Branch 80 → 81 taken 8 times.
✗ Branch 80 → 240 not taken.
✓ Branch 81 → 82 taken 8 times.
✗ Branch 81 → 236 not taken.
✓ Branch 82 → 83 taken 8 times.
✗ Branch 82 → 234 not taken.
✓ Branch 83 → 84 taken 8 times.
✗ Branch 83 → 232 not taken.
✓ Branch 84 → 85 taken 8 times.
✗ Branch 84 → 230 not taken.
16 "The struct '" + node->structName + "' does not implement method '" + expMethod->getSignature() + "'.");
237 8 continue;
238 }
239
240 // Check return type
241
5/6
✓ Branch 92 → 93 taken 106632 times.
✗ Branch 92 → 258 not taken.
✓ Branch 93 → 94 taken 11608 times.
✓ Branch 93 → 97 taken 95024 times.
✓ Branch 98 → 99 taken 4 times.
✓ Branch 98 → 111 taken 106628 times.
118240 if (spiceFunction->returnType != returnType &&
242
3/4
✓ Branch 94 → 95 taken 11608 times.
✗ Branch 94 → 258 not taken.
✓ Branch 95 → 96 taken 4 times.
✓ Branch 95 → 97 taken 11604 times.
11608 !returnType.matchesInterfaceImplementedByStruct(spiceFunction->returnType)) {
243
1/2
✓ Branch 104 → 105 taken 4 times.
✗ Branch 104 → 243 not taken.
4 softError(node, INTERFACE_METHOD_NOT_IMPLEMENTED,
244
4/8
✓ Branch 99 → 100 taken 4 times.
✗ Branch 99 → 255 not taken.
✓ Branch 100 → 101 taken 4 times.
✗ Branch 100 → 251 not taken.
✓ Branch 101 → 102 taken 4 times.
✗ Branch 101 → 249 not taken.
✓ Branch 102 → 103 taken 4 times.
✗ Branch 102 → 247 not taken.
8 "The struct '" + node->structName + "' does not implement method '" + expMethod->getSignature() +
245
1/2
✓ Branch 103 → 104 taken 4 times.
✗ Branch 103 → 245 not taken.
4 "'. The return type does not match.");
246 4 continue;
247 }
248 // Set to virtual, since it overrides the interface method
249 106628 spiceFunction->isVirtual = true;
250 106628 spiceFunction->vtableIndex = vtableIndex++;
251
6/6
✓ Branch 113 → 114 taken 106628 times.
✓ Branch 113 → 115 taken 12 times.
✓ Branch 118 → 119 taken 106628 times.
✓ Branch 118 → 120 taken 12 times.
✓ Branch 123 → 124 taken 106628 times.
✓ Branch 123 → 126 taken 12 times.
319920 }
252 }
253
254 // Check default ctor body if required
255
2/4
✓ Branch 150 → 151 taken 63542 times.
✗ Branch 150 → 269 not taken.
✓ Branch 151 → 152 taken 63542 times.
✗ Branch 151 → 267 not taken.
190626 const Function *ctorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, {}, true);
256
4/4
✓ Branch 155 → 156 taken 19885 times.
✓ Branch 155 → 161 taken 43657 times.
✓ Branch 156 → 157 taken 3580 times.
✓ Branch 156 → 161 taken 16305 times.
63542 if (ctorFunc != nullptr && ctorFunc->implicitDefault) {
257
1/2
✓ Branch 157 → 158 taken 3580 times.
✗ Branch 157 → 299 not taken.
3580 createCtorBodyPreamble(ctorFunc->bodyScope);
258
2/4
✓ Branch 158 → 159 taken 3580 times.
✗ Branch 158 → 299 not taken.
✗ Branch 159 → 160 not taken.
✓ Branch 159 → 161 taken 3580 times.
3580 assert(manifestation->areAllFieldsInitialized() == nullptr);
259 }
260
261 // Check default copy ctor body if required
262
2/4
✓ Branch 161 → 162 taken 63542 times.
✗ Branch 161 → 280 not taken.
✓ Branch 165 → 166 taken 63542 times.
✗ Branch 165 → 276 not taken.
190626 const ArgList args = {{structType.toConstRef(node), false /* always non-temporary */}};
263
2/4
✓ Branch 169 → 170 taken 63542 times.
✗ Branch 169 → 284 not taken.
✓ Branch 170 → 171 taken 63542 times.
✗ Branch 170 → 282 not taken.
63542 const Function *copyCtorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, args, true);
264
4/4
✓ Branch 173 → 174 taken 31656 times.
✓ Branch 173 → 179 taken 31886 times.
✓ Branch 174 → 175 taken 21032 times.
✓ Branch 174 → 179 taken 10624 times.
63542 if (copyCtorFunc != nullptr && copyCtorFunc->implicitDefault) {
265
1/2
✓ Branch 175 → 176 taken 21032 times.
✗ Branch 175 → 297 not taken.
21032 createCopyCtorBodyPreamble(copyCtorFunc->bodyScope);
266
2/4
✓ Branch 176 → 177 taken 21032 times.
✗ Branch 176 → 297 not taken.
✗ Branch 177 → 178 not taken.
✓ Branch 177 → 179 taken 21032 times.
21032 assert(manifestation->areAllFieldsInitialized() == nullptr);
267 }
268
269 // Check default move ctor body if required. findMoveCtor scans the manifestations directly to avoid the
270 // constify-based false-positive that FunctionManager::lookup with a non-const ref arg can produce.
271
3/4
✓ Branch 179 → 180 taken 63542 times.
✗ Branch 179 → 297 not taken.
✓ Branch 180 → 181 taken 1325 times.
✓ Branch 180 → 186 taken 62217 times.
63542 if (const Function *moveCtorFunc = FunctionManager::findMoveCtor(currentScope);
272
2/2
✓ Branch 181 → 182 taken 150 times.
✓ Branch 181 → 186 taken 1175 times.
1325 moveCtorFunc && moveCtorFunc->implicitDefault) {
273
1/2
✓ Branch 182 → 183 taken 150 times.
✗ Branch 182 → 297 not taken.
150 createMoveCtorBodyPreamble(moveCtorFunc->bodyScope);
274
2/4
✓ Branch 183 → 184 taken 150 times.
✗ Branch 183 → 297 not taken.
✗ Branch 184 → 185 not taken.
✓ Branch 184 → 186 taken 150 times.
150 assert(manifestation->areAllFieldsInitialized() == nullptr);
275 }
276
277 // Check default dtor body if required
278
2/4
✓ Branch 189 → 190 taken 63542 times.
✗ Branch 189 → 290 not taken.
✓ Branch 190 → 191 taken 63542 times.
✗ Branch 190 → 288 not taken.
190626 const Function *dtorFunc = FunctionManager::lookup(currentScope, DTOR_FUNCTION_NAME, structType, {}, true);
279
4/4
✓ Branch 194 → 195 taken 34275 times.
✓ Branch 194 → 197 taken 29267 times.
✓ Branch 195 → 196 taken 21331 times.
✓ Branch 195 → 197 taken 12944 times.
63542 if (dtorFunc != nullptr && dtorFunc->implicitDefault)
280
1/2
✓ Branch 196 → 197 taken 21331 times.
✗ Branch 196 → 297 not taken.
21331 createDtorBodyPreamble(dtorFunc->bodyScope, node);
281
282 // Reset field symbols to declared state for the next manifestation
283
1/2
✓ Branch 197 → 198 taken 63542 times.
✗ Branch 197 → 297 not taken.
63542 manifestation->resetFieldSymbolsToDeclared(node);
284
285 // Clear type mapping
286 63542 typeMapping.clear();
287
288 // Return to the root scope
289 63542 currentScope = rootScope;
290
2/4
✓ Branch 199 → 200 taken 63542 times.
✗ Branch 199 → 202 not taken.
✓ Branch 200 → 201 taken 63542 times.
✗ Branch 200 → 202 not taken.
63542 assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL);
291
292 63542 manIdx++; // Increase the manifestation index
293 63542 }
294 28774 manIdx = 0; // Reset the manifestation index
295
296
1/2
✓ Branch 216 → 217 taken 28774 times.
✗ Branch 216 → 301 not taken.
57548 return nullptr;
297 }
298
299 132 std::any TypeChecker::visitUnionDefCheck(UnionDefNode *node) {
300 132 node->resizeToNumberOfManifestations(node->unionManifestations.size());
301 132 manIdx = 0; // Reset the manifestation index
302
303 // Get all manifestations for this union definition
304
2/2
✓ Branch 55 → 6 taken 132 times.
✓ Branch 55 → 56 taken 132 times.
396 for (Union *manifestation : node->unionManifestations) {
305 // Skip non-substantiated manifestations
306
3/4
✓ Branch 8 → 9 taken 132 times.
✗ Branch 8 → 63 not taken.
✓ Branch 9 → 10 taken 4 times.
✓ Branch 9 → 11 taken 128 times.
132 if (!manifestation->isFullySubstantiated()) {
307 4 manIdx++; // Increase the manifestation index
308 4 continue;
309 }
310
311 // Change to union scope
312
1/2
✓ Branch 11 → 12 taken 128 times.
✗ Branch 11 → 63 not taken.
128 changeToScope(manifestation->scope, ScopeType::UNION);
313
314 // Mount type mapping for this manifestation, so that the default value below can substantiate generic field types
315
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 128 times.
128 assert(typeMapping.empty());
316
1/2
✓ Branch 15 → 16 taken 128 times.
✗ Branch 15 → 63 not taken.
128 typeMapping = manifestation->typeMapping;
317
318 // Re-visit the default value (at most one field may have one). This is required, since the type of the default
319 // value might vary for different manifestations
320
2/2
✓ Branch 39 → 18 taken 868 times.
✓ Branch 39 → 40 taken 128 times.
1124 for (const FieldNode *field : node->fields) {
321
2/2
✓ Branch 20 → 21 taken 8 times.
✓ Branch 20 → 30 taken 860 times.
868 if (field->defaultValue != nullptr) {
322
1/2
✓ Branch 21 → 22 taken 8 times.
✗ Branch 21 → 60 not taken.
8 visit(field->defaultValue);
323
1/2
✓ Branch 23 → 24 taken 8 times.
✗ Branch 23 → 62 not taken.
8 SymbolTableEntry *fieldEntry = manifestation->scope->lookupStrict(field->fieldName);
324
1/2
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 28 taken 8 times.
8 assert(fieldEntry != nullptr);
325
1/2
✓ Branch 28 → 29 taken 8 times.
✗ Branch 28 → 61 not taken.
8 fieldEntry->updateState(INITIALIZED, field);
326 }
327 }
328
329 // Clear type mapping
330 128 typeMapping.clear();
331
332 // Return to the root scope
333 128 currentScope = rootScope;
334
2/4
✓ Branch 41 → 42 taken 128 times.
✗ Branch 41 → 44 not taken.
✓ Branch 42 → 43 taken 128 times.
✗ Branch 42 → 44 not taken.
128 assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL);
335
336 128 manIdx++; // Increase the manifestation index
337 }
338 132 manIdx = 0; // Reset the manifestation index
339
340
1/2
✓ Branch 56 → 57 taken 132 times.
✗ Branch 56 → 64 not taken.
264 return nullptr;
341 }
342
343 } // namespace spice::compiler
344