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 1422 std::any TypeChecker::visitMainFctDefCheck(MainFctDefNode *node) {
18 // Skip if already type-checked
19
2/2
✓ Branch 2 → 3 taken 173 times.
✓ Branch 2 → 6 taken 1249 times.
1422 if (typeCheckedMainFct)
20
1/2
✓ Branch 3 → 4 taken 173 times.
✗ Branch 3 → 13 not taken.
346 return nullptr;
21
22 1249 node->resizeToNumberOfManifestations(1);
23
24 // Change to function body scope
25 1249 currentScope = node->bodyScope;
26 // Visit statements in new scope
27
2/2
✓ Branch 7 → 8 taken 1183 times.
✓ Branch 7 → 14 taken 66 times.
1249 visit(node->body);
28 // Leave main function body scope
29 1183 currentScope = rootScope;
30
31 // Set to type-checked
32 1183 typeCheckedMainFct = true;
33
1/2
✓ Branch 9 → 10 taken 1183 times.
✗ Branch 9 → 15 not taken.
2366 return nullptr;
34 }
35
36 278926 std::any TypeChecker::visitFctDefCheck(FctDefNode *node) {
37 278926 node->resizeToNumberOfManifestations(node->manifestations.size());
38 278926 manIdx = 0; // Reset the manifestation index
39
40 // Get all manifestations for this function definition
41
2/2
✓ Branch 79 → 6 taken 447607 times.
✓ Branch 79 → 80 taken 278922 times.
1005455 for (Function *manifestation : node->manifestations) {
42 // Skip non-substantiated or already checked functions
43
7/8
✓ Branch 8 → 9 taken 447607 times.
✗ Branch 8 → 101 not taken.
✓ Branch 9 → 10 taken 398976 times.
✓ Branch 9 → 11 taken 48631 times.
✓ Branch 10 → 11 taken 213307 times.
✓ Branch 10 → 12 taken 185669 times.
✓ Branch 13 → 14 taken 261938 times.
✓ Branch 13 → 15 taken 185669 times.
447607 if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) {
44 261938 manIdx++; // Increase the manifestation index
45 261938 continue;
46 }
47
48 // Change scope to concrete struct specialization scope
49
2/2
✓ Branch 15 → 16 taken 141846 times.
✓ Branch 15 → 21 taken 43823 times.
185669 if (node->isMethod) {
50
2/4
✓ Branch 16 → 17 taken 141846 times.
✗ Branch 16 → 86 not taken.
✓ Branch 17 → 18 taken 141846 times.
✗ Branch 17 → 86 not taken.
141846 const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes());
51
1/2
✓ Branch 18 → 19 taken 141846 times.
✗ Branch 18 → 84 not taken.
141846 changeToScope(scopeName, ScopeType::STRUCT);
52 141846 }
53
54 // Change to function scope
55
1/2
✓ Branch 21 → 22 taken 185669 times.
✗ Branch 21 → 101 not taken.
185669 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 185669 times.
185669 assert(typeMapping.empty());
59
1/2
✓ Branch 25 → 26 taken 185669 times.
✗ Branch 25 → 101 not taken.
185669 typeMapping = manifestation->typeMapping;
60
61 // Set return type to the result variable
62
1/2
✓ Branch 28 → 29 taken 185669 times.
✗ Branch 28 → 89 not taken.
557007 SymbolTableEntry *resultVarEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME);
63
1/2
✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 185669 times.
185669 assert(resultVarEntry != nullptr);
64
1/2
✓ Branch 36 → 37 taken 185669 times.
✗ Branch 36 → 101 not taken.
185669 resultVarEntry->updateType(manifestation->returnType, false);
65 185669 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 108174 times.
✓ Branch 37 → 64 taken 77495 times.
185669 if (node->hasParams) {
70
1/2
✓ Branch 38 → 39 taken 108174 times.
✗ Branch 38 → 93 not taken.
108174 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 155699 times.
✓ Branch 63 → 64 taken 108174 times.
263873 for (size_t i = 0; i < manifestation->paramList.size(); i++) {
74
1/2
✓ Branch 41 → 42 taken 155699 times.
✗ Branch 41 → 99 not taken.
155699 const DeclStmtNode *param = node->paramLst->params.at(i);
75
2/4
✓ Branch 42 → 43 taken 155699 times.
✗ Branch 42 → 96 not taken.
✓ Branch 43 → 44 taken 155699 times.
✗ Branch 43 → 94 not taken.
155699 const QualType paramType = manifestation->getParamTypes().at(i);
76
8/10
✓ Branch 45 → 46 taken 155699 times.
✗ Branch 45 → 97 not taken.
✓ Branch 46 → 47 taken 140 times.
✓ Branch 46 → 50 taken 155559 times.
✓ Branch 47 → 48 taken 140 times.
✗ Branch 47 → 97 not taken.
✓ Branch 48 → 49 taken 110 times.
✓ Branch 48 → 50 taken 30 times.
✓ Branch 51 → 52 taken 110 times.
✓ Branch 51 → 61 taken 155589 times.
155699 if (paramType.isOneOf({TY_FUNCTION, TY_PROCEDURE}) && paramType.hasLambdaCaptures()) {
77
1/2
✓ Branch 52 → 53 taken 110 times.
✗ Branch 52 → 99 not taken.
110 SymbolTableEntry *paramSymbol = currentScope->lookupStrict(param->varName);
78
1/2
✗ Branch 55 → 56 not taken.
✓ Branch 55 → 57 taken 110 times.
110 assert(paramSymbol != nullptr);
79
3/6
✓ Branch 57 → 58 taken 110 times.
✗ Branch 57 → 98 not taken.
✓ Branch 58 → 59 taken 110 times.
✗ Branch 58 → 98 not taken.
✓ Branch 59 → 60 taken 110 times.
✗ Branch 59 → 98 not taken.
110 paramSymbol->updateType(paramSymbol->getQualType().getWithLambdaCaptures(), true);
80 }
81 }
82 }
83
84 // Visit statements in new scope
85
2/2
✓ Branch 64 → 65 taken 185665 times.
✓ Branch 64 → 100 taken 4 times.
185669 visit(node->body);
86
87 // Clear type mapping
88 185665 typeMapping.clear();
89
90 // Change to root scope
91 185665 currentScope = rootScope;
92
1/2
✗ Branch 67 → 68 not taken.
✓ Branch 67 → 69 taken 185665 times.
185665 assert(currentScope->type == ScopeType::GLOBAL);
93
94 // Do not type-check this manifestation again
95 185665 manifestation->alreadyTypeChecked = true;
96
97 185665 manIdx++; // Increase the manifestation index
98 }
99 278922 manIdx = 0; // Reset the manifestation index
100
101
1/2
✓ Branch 80 → 81 taken 278922 times.
✗ Branch 80 → 102 not taken.
557844 return nullptr;
102 }
103
104 126878 std::any TypeChecker::visitProcDefCheck(ProcDefNode *node) {
105 126878 node->resizeToNumberOfManifestations(node->manifestations.size());
106 126878 manIdx = 0; // Reset the manifestation index
107
108 // Get all manifestations for this procedure definition
109
2/2
✓ Branch 72 → 6 taken 302688 times.
✓ Branch 72 → 73 taken 126878 times.
556444 for (Function *manifestation : node->manifestations) {
110 // Skip non-substantiated or already checked procedures
111
7/8
✓ Branch 8 → 9 taken 302688 times.
✗ Branch 8 → 88 not taken.
✓ Branch 9 → 10 taken 255975 times.
✓ Branch 9 → 11 taken 46713 times.
✓ Branch 10 → 11 taken 140342 times.
✓ Branch 10 → 12 taken 115633 times.
✓ Branch 13 → 14 taken 187055 times.
✓ Branch 13 → 15 taken 115633 times.
302688 if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) {
112 187055 manIdx++; // Increase the manifestation index
113 187055 continue;
114 }
115
116 // Change scope to concrete struct specialization scope
117
2/2
✓ Branch 15 → 16 taken 94573 times.
✓ Branch 15 → 21 taken 21060 times.
115633 if (node->isMethod) {
118
2/4
✓ Branch 16 → 17 taken 94573 times.
✗ Branch 16 → 79 not taken.
✓ Branch 17 → 18 taken 94573 times.
✗ Branch 17 → 79 not taken.
94573 const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes());
119
1/2
✓ Branch 18 → 19 taken 94573 times.
✗ Branch 18 → 77 not taken.
94573 changeToScope(scopeName, ScopeType::STRUCT);
120 94573 }
121
122 // Change to procedure scope
123
1/2
✓ Branch 21 → 22 taken 115633 times.
✗ Branch 21 → 88 not taken.
115633 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 115633 times.
115633 assert(typeMapping.empty());
127
1/2
✓ Branch 25 → 26 taken 115633 times.
✗ Branch 25 → 88 not taken.
115633 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 86946 times.
✓ Branch 26 → 53 taken 28687 times.
115633 if (node->hasParams) {
132
1/2
✓ Branch 27 → 28 taken 86946 times.
✗ Branch 27 → 80 not taken.
86946 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 119283 times.
✓ Branch 52 → 53 taken 86946 times.
206229 for (size_t i = 0; i < manifestation->paramList.size(); i++) {
136
1/2
✓ Branch 30 → 31 taken 119283 times.
✗ Branch 30 → 86 not taken.
119283 const DeclStmtNode *param = node->paramLst->params.at(i);
137
2/4
✓ Branch 31 → 32 taken 119283 times.
✗ Branch 31 → 83 not taken.
✓ Branch 32 → 33 taken 119283 times.
✗ Branch 32 → 81 not taken.
119283 const QualType paramType = manifestation->getParamTypes().at(i);
138
8/10
✓ Branch 34 → 35 taken 119283 times.
✗ Branch 34 → 84 not taken.
✓ Branch 35 → 36 taken 608 times.
✓ Branch 35 → 39 taken 118675 times.
✓ Branch 36 → 37 taken 608 times.
✗ Branch 36 → 84 not taken.
✓ Branch 37 → 38 taken 350 times.
✓ Branch 37 → 39 taken 258 times.
✓ Branch 40 → 41 taken 350 times.
✓ Branch 40 → 50 taken 118933 times.
119283 if (paramType.isOneOf({TY_FUNCTION, TY_PROCEDURE}) && paramType.hasLambdaCaptures()) {
139
1/2
✓ Branch 41 → 42 taken 350 times.
✗ Branch 41 → 86 not taken.
350 SymbolTableEntry *paramSymbol = currentScope->lookupStrict(param->varName);
140
1/2
✗ Branch 44 → 45 not taken.
✓ Branch 44 → 46 taken 350 times.
350 assert(paramSymbol != nullptr);
141
3/6
✓ Branch 46 → 47 taken 350 times.
✗ Branch 46 → 85 not taken.
✓ Branch 47 → 48 taken 350 times.
✗ Branch 47 → 85 not taken.
✓ Branch 48 → 49 taken 350 times.
✗ Branch 48 → 85 not taken.
350 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 43033 times.
✓ Branch 53 → 55 taken 72600 times.
115633 if (node->isCtor)
148
1/2
✓ Branch 54 → 55 taken 43033 times.
✗ Branch 54 → 88 not taken.
43033 createCtorBodyPreamble(manifestation->bodyScope);
149
150 // Visit statements in new scope
151
1/2
✓ Branch 55 → 56 taken 115633 times.
✗ Branch 55 → 87 not taken.
115633 visit(node->body);
152
153 // Clear type mapping
154 115633 typeMapping.clear();
155
156 // Change to root scope
157 115633 currentScope = rootScope;
158
2/4
✓ Branch 58 → 59 taken 115633 times.
✗ Branch 58 → 61 not taken.
✓ Branch 59 → 60 taken 115633 times.
✗ Branch 59 → 61 not taken.
115633 assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL);
159
160 // Do not type-check this manifestation again
161 115633 manifestation->alreadyTypeChecked = true;
162
163 115633 manIdx++; // Increase the manifestation index
164 }
165 126878 manIdx = 0; // Reset the manifestation index
166
167
1/2
✓ Branch 73 → 74 taken 126878 times.
✗ Branch 73 → 89 not taken.
253756 return nullptr;
168 }
169
170 33524 std::any TypeChecker::visitStructDefCheck(StructDefNode *node) {
171 33524 node->resizeToNumberOfManifestations(node->structManifestations.size());
172 33524 manIdx = 0; // Reset the manifestation index
173
174 // Get all manifestations for this procedure definition
175
2/2
✓ Branch 215 → 6 taken 78876 times.
✓ Branch 215 → 216 taken 33524 times.
145924 for (Struct *manifestation : node->structManifestations) {
176 // Skip non-substantiated or already checked procedures
177
3/4
✓ Branch 8 → 9 taken 78876 times.
✗ Branch 8 → 299 not taken.
✓ Branch 9 → 10 taken 7440 times.
✓ Branch 9 → 11 taken 71436 times.
78876 if (!manifestation->isFullySubstantiated()) {
178 7440 manIdx++; // Increase the manifestation index
179 7440 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 71436 times.
✗ Branch 11 → 299 not taken.
71436 createImplicitDefaultMembers(*manifestation, node, /*withMoveCtor=*/false);
186
187 // Change to struct scope
188
1/2
✓ Branch 12 → 13 taken 71436 times.
✗ Branch 12 → 299 not taken.
71436 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 71436 times.
71436 assert(typeMapping.empty());
194
1/2
✓ Branch 16 → 17 taken 71436 times.
✗ Branch 16 → 299 not taken.
71436 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 233469 times.
✓ Branch 40 → 41 taken 71436 times.
376341 for (const FieldNode *field : node->fields) {
198
2/2
✓ Branch 21 → 22 taken 101497 times.
✓ Branch 21 → 31 taken 131972 times.
233469 if (field->defaultValue != nullptr) {
199
1/2
✓ Branch 22 → 23 taken 101497 times.
✗ Branch 22 → 220 not taken.
101497 visit(field->defaultValue);
200
1/2
✓ Branch 24 → 25 taken 101497 times.
✗ Branch 24 → 222 not taken.
101497 SymbolTableEntry *fieldEntry = manifestation->scope->lookupStrict(field->fieldName);
201
1/2
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 101497 times.
101497 assert(fieldEntry != nullptr);
202
1/2
✓ Branch 29 → 30 taken 101497 times.
✗ Branch 29 → 221 not taken.
101497 fieldEntry->updateState(INITIALIZED, field);
203 }
204 }
205
206 // Build struct type
207
1/2
✓ Branch 41 → 42 taken 71436 times.
✗ Branch 41 → 299 not taken.
71436 const QualType structType = manifestation->entry->getQualType();
208
209 // Check if the struct implements all methods of all attached interfaces
210 71436 size_t vtableIndex = 0;
211
2/2
✓ Branch 146 → 44 taken 37548 times.
✓ Branch 146 → 147 taken 71436 times.
180420 for (const QualType &interfaceType : manifestation->interfaceTypes) {
212
1/2
✓ Branch 46 → 47 taken 37548 times.
✗ Branch 46 → 266 not taken.
37548 const Interface *interface = interfaceType.getInterface(node);
213
1/2
✗ Branch 47 → 48 not taken.
✓ Branch 47 → 49 taken 37548 times.
37548 assert(interface != nullptr);
214
215 // Check for all methods, that it is implemented by the struct
216
2/2
✓ Branch 136 → 51 taken 129074 times.
✓ Branch 136 → 137 taken 37548 times.
204170 for (const Function *expMethod : interface->methods) {
217
1/2
✓ Branch 53 → 54 taken 129074 times.
✗ Branch 53 → 264 not taken.
129074 const std::string methodName = expMethod->name;
218
1/2
✓ Branch 54 → 55 taken 129074 times.
✗ Branch 54 → 262 not taken.
129074 QualTypeList params = expMethod->getParamTypes();
219 129074 QualType returnType = expMethod->returnType;
220
221 // Substantiate param and return types
222
1/2
✓ Branch 55 → 56 taken 129074 times.
✗ Branch 55 → 260 not taken.
129074 TypeMatcher::substantiateTypesWithTypeMapping(params, interface->typeMapping, node);
223
3/4
✓ Branch 56 → 57 taken 129074 times.
✗ Branch 56 → 260 not taken.
✓ Branch 57 → 58 taken 38514 times.
✓ Branch 57 → 59 taken 90560 times.
129074 if (returnType.hasAnyGenericParts())
224
1/2
✓ Branch 58 → 59 taken 38514 times.
✗ Branch 58 → 260 not taken.
38514 TypeMatcher::substantiateTypeWithTypeMapping(returnType, interface->typeMapping, node);
225
226 // Build args list
227 129074 ArgList args;
228
1/2
✓ Branch 60 → 61 taken 129074 times.
✗ Branch 60 → 258 not taken.
129074 args.reserve(params.size());
229
2/2
✓ Branch 75 → 63 taken 42108 times.
✓ Branch 75 → 76 taken 129074 times.
300256 for (const QualType &param : params)
230
1/2
✓ Branch 65 → 66 taken 42108 times.
✗ Branch 65 → 223 not taken.
42108 args.emplace_back(param, nullptr);
231
232 // Search for method that has the required signature
233
1/2
✓ Branch 77 → 78 taken 129074 times.
✗ Branch 77 → 225 not taken.
129074 Function *spiceFunction = FunctionManager::match(currentScope, methodName, structType, args, {}, true, node);
234
2/2
✓ Branch 79 → 80 taken 8 times.
✓ Branch 79 → 92 taken 129066 times.
129074 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 129066 times.
✗ Branch 92 → 258 not taken.
✓ Branch 93 → 94 taken 12730 times.
✓ Branch 93 → 97 taken 116336 times.
✓ Branch 98 → 99 taken 4 times.
✓ Branch 98 → 111 taken 129062 times.
141796 if (spiceFunction->returnType != returnType &&
242
3/4
✓ Branch 94 → 95 taken 12730 times.
✗ Branch 94 → 258 not taken.
✓ Branch 95 → 96 taken 4 times.
✓ Branch 95 → 97 taken 12726 times.
12730 !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 129062 spiceFunction->isVirtual = true;
250 129062 spiceFunction->vtableIndex = vtableIndex++;
251
6/6
✓ Branch 113 → 114 taken 129062 times.
✓ Branch 113 → 115 taken 12 times.
✓ Branch 118 → 119 taken 129062 times.
✓ Branch 118 → 120 taken 12 times.
✓ Branch 123 → 124 taken 129062 times.
✓ Branch 123 → 126 taken 12 times.
387222 }
252 }
253
254 // Check default ctor body if required
255
2/4
✓ Branch 150 → 151 taken 71436 times.
✗ Branch 150 → 269 not taken.
✓ Branch 151 → 152 taken 71436 times.
✗ Branch 151 → 267 not taken.
214308 const Function *ctorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, {}, true);
256
4/4
✓ Branch 155 → 156 taken 21709 times.
✓ Branch 155 → 161 taken 49727 times.
✓ Branch 156 → 157 taken 3756 times.
✓ Branch 156 → 161 taken 17953 times.
71436 if (ctorFunc != nullptr && ctorFunc->implicitDefault) {
257
1/2
✓ Branch 157 → 158 taken 3756 times.
✗ Branch 157 → 299 not taken.
3756 createCtorBodyPreamble(ctorFunc->bodyScope);
258
2/4
✓ Branch 158 → 159 taken 3756 times.
✗ Branch 158 → 299 not taken.
✗ Branch 159 → 160 not taken.
✓ Branch 159 → 161 taken 3756 times.
3756 assert(manifestation->areAllFieldsInitialized() == nullptr);
259 }
260
261 // Check default copy ctor body if required
262
2/4
✓ Branch 161 → 162 taken 71436 times.
✗ Branch 161 → 280 not taken.
✓ Branch 165 → 166 taken 71436 times.
✗ Branch 165 → 276 not taken.
214308 const ArgList args = {{structType.toConstRef(node), false /* always non-temporary */}};
263
2/4
✓ Branch 169 → 170 taken 71436 times.
✗ Branch 169 → 284 not taken.
✓ Branch 170 → 171 taken 71436 times.
✗ Branch 170 → 282 not taken.
71436 const Function *copyCtorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, args, true);
264
4/4
✓ Branch 173 → 174 taken 37114 times.
✓ Branch 173 → 179 taken 34322 times.
✓ Branch 174 → 175 taken 25522 times.
✓ Branch 174 → 179 taken 11592 times.
71436 if (copyCtorFunc != nullptr && copyCtorFunc->implicitDefault) {
265
1/2
✓ Branch 175 → 176 taken 25522 times.
✗ Branch 175 → 297 not taken.
25522 createCopyCtorBodyPreamble(copyCtorFunc->bodyScope);
266
2/4
✓ Branch 176 → 177 taken 25522 times.
✗ Branch 176 → 297 not taken.
✗ Branch 177 → 178 not taken.
✓ Branch 177 → 179 taken 25522 times.
25522 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 71436 times.
✗ Branch 179 → 297 not taken.
✓ Branch 180 → 181 taken 1359 times.
✓ Branch 180 → 186 taken 70077 times.
71436 if (const Function *moveCtorFunc = FunctionManager::findMoveCtor(currentScope);
272
2/2
✓ Branch 181 → 182 taken 134 times.
✓ Branch 181 → 186 taken 1225 times.
1359 moveCtorFunc && moveCtorFunc->implicitDefault) {
273
1/2
✓ Branch 182 → 183 taken 134 times.
✗ Branch 182 → 297 not taken.
134 createMoveCtorBodyPreamble(moveCtorFunc->bodyScope);
274
2/4
✓ Branch 183 → 184 taken 134 times.
✗ Branch 183 → 297 not taken.
✗ Branch 184 → 185 not taken.
✓ Branch 184 → 186 taken 134 times.
134 assert(manifestation->areAllFieldsInitialized() == nullptr);
275 }
276
277 // Check default dtor body if required
278
2/4
✓ Branch 189 → 190 taken 71436 times.
✗ Branch 189 → 290 not taken.
✓ Branch 190 → 191 taken 71436 times.
✗ Branch 190 → 288 not taken.
214308 const Function *dtorFunc = FunctionManager::lookup(currentScope, DTOR_FUNCTION_NAME, structType, {}, true);
279
4/4
✓ Branch 194 → 195 taken 40023 times.
✓ Branch 194 → 197 taken 31413 times.
✓ Branch 195 → 196 taken 25787 times.
✓ Branch 195 → 197 taken 14236 times.
71436 if (dtorFunc != nullptr && dtorFunc->implicitDefault)
280
1/2
✓ Branch 196 → 197 taken 25787 times.
✗ Branch 196 → 297 not taken.
25787 createDtorBodyPreamble(dtorFunc->bodyScope, node);
281
282 // Reset field symbols to declared state for the next manifestation
283
1/2
✓ Branch 197 → 198 taken 71436 times.
✗ Branch 197 → 297 not taken.
71436 manifestation->resetFieldSymbolsToDeclared(node);
284
285 // Clear type mapping
286 71436 typeMapping.clear();
287
288 // Return to the root scope
289 71436 currentScope = rootScope;
290
2/4
✓ Branch 199 → 200 taken 71436 times.
✗ Branch 199 → 202 not taken.
✓ Branch 200 → 201 taken 71436 times.
✗ Branch 200 → 202 not taken.
71436 assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL);
291
292 71436 manIdx++; // Increase the manifestation index
293 71436 }
294 33524 manIdx = 0; // Reset the manifestation index
295
296
1/2
✓ Branch 216 → 217 taken 33524 times.
✗ Branch 216 → 301 not taken.
67048 return nullptr;
297 }
298
299 174 std::any TypeChecker::visitUnionDefCheck(UnionDefNode *node) {
300 174 node->resizeToNumberOfManifestations(node->unionManifestations.size());
301 174 manIdx = 0; // Reset the manifestation index
302
303 // Get all manifestations for this union definition
304
2/2
✓ Branch 55 → 6 taken 174 times.
✓ Branch 55 → 56 taken 174 times.
522 for (Union *manifestation : node->unionManifestations) {
305 // Skip non-substantiated manifestations
306
3/4
✓ Branch 8 → 9 taken 174 times.
✗ Branch 8 → 63 not taken.
✓ Branch 9 → 10 taken 4 times.
✓ Branch 9 → 11 taken 170 times.
174 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 170 times.
✗ Branch 11 → 63 not taken.
170 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 170 times.
170 assert(typeMapping.empty());
316
1/2
✓ Branch 15 → 16 taken 170 times.
✗ Branch 15 → 63 not taken.
170 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 1204 times.
✓ Branch 39 → 40 taken 170 times.
1544 for (const FieldNode *field : node->fields) {
321
2/2
✓ Branch 20 → 21 taken 8 times.
✓ Branch 20 → 30 taken 1196 times.
1204 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 170 typeMapping.clear();
331
332 // Return to the root scope
333 170 currentScope = rootScope;
334
2/4
✓ Branch 41 → 42 taken 170 times.
✗ Branch 41 → 44 not taken.
✓ Branch 42 → 43 taken 170 times.
✗ Branch 42 → 44 not taken.
170 assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL);
335
336 170 manIdx++; // Increase the manifestation index
337 }
338 174 manIdx = 0; // Reset the manifestation index
339
340
1/2
✓ Branch 56 → 57 taken 174 times.
✗ Branch 56 → 64 not taken.
348 return nullptr;
341 }
342
343 } // namespace spice::compiler
344