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 1329 std::any TypeChecker::visitMainFctDefCheck(MainFctDefNode *node) {
18 // Skip if already type-checked
19
2/2
✓ Branch 2 → 3 taken 161 times.
✓ Branch 2 → 6 taken 1168 times.
1329 if (typeCheckedMainFct)
20
1/2
✓ Branch 3 → 4 taken 161 times.
✗ Branch 3 → 13 not taken.
322 return nullptr;
21
22 1168 node->resizeToNumberOfManifestations(1);
23
24 // Change to function body scope
25 1168 currentScope = node->bodyScope;
26 // Visit statements in new scope
27
2/2
✓ Branch 7 → 8 taken 1108 times.
✓ Branch 7 → 14 taken 60 times.
1168 visit(node->body);
28 // Leave main function body scope
29 1108 currentScope = rootScope;
30
31 // Set to type-checked
32 1108 typeCheckedMainFct = true;
33
1/2
✓ Branch 9 → 10 taken 1108 times.
✗ Branch 9 → 15 not taken.
2216 return nullptr;
34 }
35
36 105748 std::any TypeChecker::visitFctDefCheck(FctDefNode *node) {
37 105748 node->resizeToNumberOfManifestations(node->manifestations.size());
38 105748 manIdx = 0; // Reset the manifestation index
39
40 // Get all manifestations for this function definition
41
2/2
✓ Branch 79 → 6 taken 140129 times.
✓ Branch 79 → 80 taken 105744 times.
351621 for (Function *manifestation : node->manifestations) {
42 // Skip non-substantiated or already checked functions
43
7/8
✓ Branch 8 → 9 taken 140129 times.
✗ Branch 8 → 101 not taken.
✓ Branch 9 → 10 taken 112421 times.
✓ Branch 9 → 11 taken 27708 times.
✓ Branch 10 → 11 taken 59898 times.
✓ Branch 10 → 12 taken 52523 times.
✓ Branch 13 → 14 taken 87606 times.
✓ Branch 13 → 15 taken 52523 times.
140129 if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) {
44 87606 manIdx++; // Increase the manifestation index
45 87606 continue;
46 }
47
48 // Change scope to concrete struct specialization scope
49
2/2
✓ Branch 15 → 16 taken 30212 times.
✓ Branch 15 → 21 taken 22311 times.
52523 if (node->isMethod) {
50
2/4
✓ Branch 16 → 17 taken 30212 times.
✗ Branch 16 → 86 not taken.
✓ Branch 17 → 18 taken 30212 times.
✗ Branch 17 → 86 not taken.
30212 const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes());
51
1/2
✓ Branch 18 → 19 taken 30212 times.
✗ Branch 18 → 84 not taken.
30212 changeToScope(scopeName, ScopeType::STRUCT);
52 30212 }
53
54 // Change to function scope
55
1/2
✓ Branch 21 → 22 taken 52523 times.
✗ Branch 21 → 101 not taken.
52523 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 52523 times.
52523 assert(typeMapping.empty());
59
1/2
✓ Branch 25 → 26 taken 52523 times.
✗ Branch 25 → 101 not taken.
52523 typeMapping = manifestation->typeMapping;
60
61 // Set return type to the result variable
62
1/2
✓ Branch 28 → 29 taken 52523 times.
✗ Branch 28 → 89 not taken.
157569 SymbolTableEntry *resultVarEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME);
63
1/2
✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 52523 times.
52523 assert(resultVarEntry != nullptr);
64
1/2
✓ Branch 36 → 37 taken 52523 times.
✗ Branch 36 → 101 not taken.
52523 resultVarEntry->updateType(manifestation->returnType, false);
65 52523 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 36906 times.
✓ Branch 37 → 64 taken 15617 times.
52523 if (node->hasParams) {
70
1/2
✓ Branch 38 → 39 taken 36906 times.
✗ Branch 38 → 93 not taken.
36906 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 53687 times.
✓ Branch 63 → 64 taken 36906 times.
90593 for (size_t i = 0; i < manifestation->paramList.size(); i++) {
74
1/2
✓ Branch 41 → 42 taken 53687 times.
✗ Branch 41 → 99 not taken.
53687 const DeclStmtNode *param = node->paramLst->params.at(i);
75
2/4
✓ Branch 42 → 43 taken 53687 times.
✗ Branch 42 → 96 not taken.
✓ Branch 43 → 44 taken 53687 times.
✗ Branch 43 → 94 not taken.
53687 const QualType paramType = manifestation->getParamTypes().at(i);
76
8/10
✓ Branch 45 → 46 taken 53687 times.
✗ Branch 45 → 97 not taken.
✓ Branch 46 → 47 taken 38 times.
✓ Branch 46 → 50 taken 53649 times.
✓ Branch 47 → 48 taken 38 times.
✗ Branch 47 → 97 not taken.
✓ Branch 48 → 49 taken 6 times.
✓ Branch 48 → 50 taken 32 times.
✓ Branch 51 → 52 taken 6 times.
✓ Branch 51 → 61 taken 53681 times.
53687 if (paramType.isOneOf({TY_FUNCTION, TY_PROCEDURE}) && paramType.hasLambdaCaptures()) {
77
1/2
✓ Branch 52 → 53 taken 6 times.
✗ Branch 52 → 99 not taken.
6 SymbolTableEntry *paramSymbol = currentScope->lookupStrict(param->varName);
78
1/2
✗ Branch 55 → 56 not taken.
✓ Branch 55 → 57 taken 6 times.
6 assert(paramSymbol != nullptr);
79
3/6
✓ Branch 57 → 58 taken 6 times.
✗ Branch 57 → 98 not taken.
✓ Branch 58 → 59 taken 6 times.
✗ Branch 58 → 98 not taken.
✓ Branch 59 → 60 taken 6 times.
✗ Branch 59 → 98 not taken.
6 paramSymbol->updateType(paramSymbol->getQualType().getWithLambdaCaptures(), true);
80 }
81 }
82 }
83
84 // Visit statements in new scope
85
2/2
✓ Branch 64 → 65 taken 52519 times.
✓ Branch 64 → 100 taken 4 times.
52523 visit(node->body);
86
87 // Clear type mapping
88 52519 typeMapping.clear();
89
90 // Change to root scope
91 52519 currentScope = rootScope;
92
1/2
✗ Branch 67 → 68 not taken.
✓ Branch 67 → 69 taken 52519 times.
52519 assert(currentScope->type == ScopeType::GLOBAL);
93
94 // Do not type-check this manifestation again
95 52519 manifestation->alreadyTypeChecked = true;
96
97 52519 manIdx++; // Increase the manifestation index
98 }
99 105744 manIdx = 0; // Reset the manifestation index
100
101
1/2
✓ Branch 80 → 81 taken 105744 times.
✗ Branch 80 → 102 not taken.
211488 return nullptr;
102 }
103
104 65651 std::any TypeChecker::visitProcDefCheck(ProcDefNode *node) {
105 65651 node->resizeToNumberOfManifestations(node->manifestations.size());
106 65651 manIdx = 0; // Reset the manifestation index
107
108 // Get all manifestations for this procedure definition
109
2/2
✓ Branch 72 → 6 taken 93391 times.
✓ Branch 72 → 73 taken 65651 times.
224693 for (Function *manifestation : node->manifestations) {
110 // Skip non-substantiated or already checked procedures
111
7/8
✓ Branch 8 → 9 taken 93391 times.
✗ Branch 8 → 88 not taken.
✓ Branch 9 → 10 taken 66176 times.
✓ Branch 9 → 11 taken 27215 times.
✓ Branch 10 → 11 taken 34030 times.
✓ Branch 10 → 12 taken 32146 times.
✓ Branch 13 → 14 taken 61245 times.
✓ Branch 13 → 15 taken 32146 times.
93391 if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) {
112 61245 manIdx++; // Increase the manifestation index
113 61245 continue;
114 }
115
116 // Change scope to concrete struct specialization scope
117
2/2
✓ Branch 15 → 16 taken 26550 times.
✓ Branch 15 → 21 taken 5596 times.
32146 if (node->isMethod) {
118
2/4
✓ Branch 16 → 17 taken 26550 times.
✗ Branch 16 → 79 not taken.
✓ Branch 17 → 18 taken 26550 times.
✗ Branch 17 → 79 not taken.
26550 const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes());
119
1/2
✓ Branch 18 → 19 taken 26550 times.
✗ Branch 18 → 77 not taken.
26550 changeToScope(scopeName, ScopeType::STRUCT);
120 26550 }
121
122 // Change to procedure scope
123
1/2
✓ Branch 21 → 22 taken 32146 times.
✗ Branch 21 → 88 not taken.
32146 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 32146 times.
32146 assert(typeMapping.empty());
127
1/2
✓ Branch 25 → 26 taken 32146 times.
✗ Branch 25 → 88 not taken.
32146 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 23550 times.
✓ Branch 26 → 53 taken 8596 times.
32146 if (node->hasParams) {
132
1/2
✓ Branch 27 → 28 taken 23550 times.
✗ Branch 27 → 80 not taken.
23550 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 37326 times.
✓ Branch 52 → 53 taken 23550 times.
60876 for (size_t i = 0; i < manifestation->paramList.size(); i++) {
136
1/2
✓ Branch 30 → 31 taken 37326 times.
✗ Branch 30 → 86 not taken.
37326 const DeclStmtNode *param = node->paramLst->params.at(i);
137
2/4
✓ Branch 31 → 32 taken 37326 times.
✗ Branch 31 → 83 not taken.
✓ Branch 32 → 33 taken 37326 times.
✗ Branch 32 → 81 not taken.
37326 const QualType paramType = manifestation->getParamTypes().at(i);
138
8/10
✓ Branch 34 → 35 taken 37326 times.
✗ Branch 34 → 84 not taken.
✓ Branch 35 → 36 taken 128 times.
✓ Branch 35 → 39 taken 37198 times.
✓ Branch 36 → 37 taken 128 times.
✗ Branch 36 → 84 not taken.
✓ Branch 37 → 38 taken 32 times.
✓ Branch 37 → 39 taken 96 times.
✓ Branch 40 → 41 taken 32 times.
✓ Branch 40 → 50 taken 37294 times.
37326 if (paramType.isOneOf({TY_FUNCTION, TY_PROCEDURE}) && paramType.hasLambdaCaptures()) {
139
1/2
✓ Branch 41 → 42 taken 32 times.
✗ Branch 41 → 86 not taken.
32 SymbolTableEntry *paramSymbol = currentScope->lookupStrict(param->varName);
140
1/2
✗ Branch 44 → 45 not taken.
✓ Branch 44 → 46 taken 32 times.
32 assert(paramSymbol != nullptr);
141
3/6
✓ Branch 46 → 47 taken 32 times.
✗ Branch 46 → 85 not taken.
✓ Branch 47 → 48 taken 32 times.
✗ Branch 47 → 85 not taken.
✓ Branch 48 → 49 taken 32 times.
✗ Branch 48 → 85 not taken.
32 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 12862 times.
✓ Branch 53 → 55 taken 19284 times.
32146 if (node->isCtor)
148
1/2
✓ Branch 54 → 55 taken 12862 times.
✗ Branch 54 → 88 not taken.
12862 createCtorBodyPreamble(manifestation->bodyScope);
149
150 // Visit statements in new scope
151
1/2
✓ Branch 55 → 56 taken 32146 times.
✗ Branch 55 → 87 not taken.
32146 visit(node->body);
152
153 // Clear type mapping
154 32146 typeMapping.clear();
155
156 // Change to root scope
157 32146 currentScope = rootScope;
158
2/4
✓ Branch 58 → 59 taken 32146 times.
✗ Branch 58 → 61 not taken.
✓ Branch 59 → 60 taken 32146 times.
✗ Branch 59 → 61 not taken.
32146 assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL);
159
160 // Do not type-check this manifestation again
161 32146 manifestation->alreadyTypeChecked = true;
162
163 32146 manIdx++; // Increase the manifestation index
164 }
165 65651 manIdx = 0; // Reset the manifestation index
166
167
1/2
✓ Branch 73 → 74 taken 65651 times.
✗ Branch 73 → 89 not taken.
131302 return nullptr;
168 }
169
170 14774 std::any TypeChecker::visitStructDefCheck(StructDefNode *node) {
171 14774 node->resizeToNumberOfManifestations(node->structManifestations.size());
172 14774 manIdx = 0; // Reset the manifestation index
173
174 // Get all manifestations for this procedure definition
175
2/2
✓ Branch 215 → 6 taken 24144 times.
✓ Branch 215 → 216 taken 14774 times.
53692 for (Struct *manifestation : node->structManifestations) {
176 // Skip non-substantiated or already checked procedures
177
3/4
✓ Branch 8 → 9 taken 24144 times.
✗ Branch 8 → 299 not taken.
✓ Branch 9 → 10 taken 3828 times.
✓ Branch 9 → 11 taken 20316 times.
24144 if (!manifestation->isFullySubstantiated()) {
178 3828 manIdx++; // Increase the manifestation index
179 3828 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 20316 times.
✗ Branch 11 → 299 not taken.
20316 createImplicitDefaultMembers(*manifestation, node, /*withMoveCtor=*/false);
186
187 // Change to struct scope
188
1/2
✓ Branch 12 → 13 taken 20316 times.
✗ Branch 12 → 299 not taken.
20316 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 20316 times.
20316 assert(typeMapping.empty());
194
1/2
✓ Branch 16 → 17 taken 20316 times.
✗ Branch 16 → 299 not taken.
20316 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 44342 times.
✓ Branch 40 → 41 taken 20316 times.
84974 for (const FieldNode *field : node->fields) {
198
2/2
✓ Branch 21 → 22 taken 15005 times.
✓ Branch 21 → 31 taken 29337 times.
44342 if (field->defaultValue != nullptr) {
199
1/2
✓ Branch 22 → 23 taken 15005 times.
✗ Branch 22 → 220 not taken.
15005 visit(field->defaultValue);
200
1/2
✓ Branch 24 → 25 taken 15005 times.
✗ Branch 24 → 222 not taken.
15005 SymbolTableEntry *fieldEntry = manifestation->scope->lookupStrict(field->fieldName);
201
1/2
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 15005 times.
15005 assert(fieldEntry != nullptr);
202
1/2
✓ Branch 29 → 30 taken 15005 times.
✗ Branch 29 → 221 not taken.
15005 fieldEntry->updateState(INITIALIZED, field);
203 }
204 }
205
206 // Build struct type
207
1/2
✓ Branch 41 → 42 taken 20316 times.
✗ Branch 41 → 299 not taken.
20316 const QualType structType = manifestation->entry->getQualType();
208
209 // Check if the struct implements all methods of all attached interfaces
210 20316 size_t vtableIndex = 0;
211
2/2
✓ Branch 146 → 44 taken 4816 times.
✓ Branch 146 → 147 taken 20316 times.
45448 for (const QualType &interfaceType : manifestation->interfaceTypes) {
212
1/2
✓ Branch 46 → 47 taken 4816 times.
✗ Branch 46 → 266 not taken.
4816 const Interface *interface = interfaceType.getInterface(node);
213
1/2
✗ Branch 47 → 48 not taken.
✓ Branch 47 → 49 taken 4816 times.
4816 assert(interface != nullptr);
214
215 // Check for all methods, that it is implemented by the struct
216
2/2
✓ Branch 136 → 51 taken 14120 times.
✓ Branch 136 → 137 taken 4816 times.
23752 for (const Function *expMethod : interface->methods) {
217
1/2
✓ Branch 53 → 54 taken 14120 times.
✗ Branch 53 → 264 not taken.
14120 const std::string methodName = expMethod->name;
218
1/2
✓ Branch 54 → 55 taken 14120 times.
✗ Branch 54 → 262 not taken.
14120 QualTypeList params = expMethod->getParamTypes();
219 14120 QualType returnType = expMethod->returnType;
220
221 // Substantiate param and return types
222
1/2
✓ Branch 55 → 56 taken 14120 times.
✗ Branch 55 → 260 not taken.
14120 TypeMatcher::substantiateTypesWithTypeMapping(params, interface->typeMapping, node);
223
3/4
✓ Branch 56 → 57 taken 14120 times.
✗ Branch 56 → 260 not taken.
✓ Branch 57 → 58 taken 6848 times.
✓ Branch 57 → 59 taken 7272 times.
14120 if (returnType.hasAnyGenericParts())
224
1/2
✓ Branch 58 → 59 taken 6848 times.
✗ Branch 58 → 260 not taken.
6848 TypeMatcher::substantiateTypeWithTypeMapping(returnType, interface->typeMapping, node);
225
226 // Build args list
227 14120 ArgList args;
228
1/2
✓ Branch 60 → 61 taken 14120 times.
✗ Branch 60 → 258 not taken.
14120 args.reserve(params.size());
229
2/2
✓ Branch 75 → 63 taken 2160 times.
✓ Branch 75 → 76 taken 14120 times.
30400 for (const QualType &param : params)
230
1/2
✓ Branch 65 → 66 taken 2160 times.
✗ Branch 65 → 223 not taken.
2160 args.emplace_back(param, nullptr);
231
232 // Search for method that has the required signature
233
1/2
✓ Branch 77 → 78 taken 14120 times.
✗ Branch 77 → 225 not taken.
14120 Function *spiceFunction = FunctionManager::match(currentScope, methodName, structType, args, {}, true, node);
234
2/2
✓ Branch 79 → 80 taken 8 times.
✓ Branch 79 → 92 taken 14112 times.
14120 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 14112 times.
✗ Branch 92 → 258 not taken.
✓ Branch 93 → 94 taken 2244 times.
✓ Branch 93 → 97 taken 11868 times.
✓ Branch 98 → 99 taken 4 times.
✓ Branch 98 → 111 taken 14108 times.
16356 if (spiceFunction->returnType != returnType &&
242
3/4
✓ Branch 94 → 95 taken 2244 times.
✗ Branch 94 → 258 not taken.
✓ Branch 95 → 96 taken 4 times.
✓ Branch 95 → 97 taken 2240 times.
2244 !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 14108 spiceFunction->isVirtual = true;
250 14108 spiceFunction->vtableIndex = vtableIndex++;
251
6/6
✓ Branch 113 → 114 taken 14108 times.
✓ Branch 113 → 115 taken 12 times.
✓ Branch 118 → 119 taken 14108 times.
✓ Branch 118 → 120 taken 12 times.
✓ Branch 123 → 124 taken 14108 times.
✓ Branch 123 → 126 taken 12 times.
42360 }
252 }
253
254 // Check default ctor body if required
255
2/4
✓ Branch 150 → 151 taken 20316 times.
✗ Branch 150 → 269 not taken.
✓ Branch 151 → 152 taken 20316 times.
✗ Branch 151 → 267 not taken.
60948 const Function *ctorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, {}, true);
256
4/4
✓ Branch 155 → 156 taken 5049 times.
✓ Branch 155 → 161 taken 15267 times.
✓ Branch 156 → 157 taken 586 times.
✓ Branch 156 → 161 taken 4463 times.
20316 if (ctorFunc != nullptr && ctorFunc->implicitDefault) {
257
1/2
✓ Branch 157 → 158 taken 586 times.
✗ Branch 157 → 299 not taken.
586 createCtorBodyPreamble(ctorFunc->bodyScope);
258
2/4
✓ Branch 158 → 159 taken 586 times.
✗ Branch 158 → 299 not taken.
✗ Branch 159 → 160 not taken.
✓ Branch 159 → 161 taken 586 times.
586 assert(manifestation->areAllFieldsInitialized() == nullptr);
259 }
260
261 // Check default copy ctor body if required
262
2/4
✓ Branch 161 → 162 taken 20316 times.
✗ Branch 161 → 280 not taken.
✓ Branch 165 → 166 taken 20316 times.
✗ Branch 165 → 276 not taken.
60948 const ArgList args = {{structType.toConstRef(node), false /* always non-temporary */}};
263
2/4
✓ Branch 169 → 170 taken 20316 times.
✗ Branch 169 → 284 not taken.
✓ Branch 170 → 171 taken 20316 times.
✗ Branch 170 → 282 not taken.
20316 const Function *copyCtorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, args, true);
264
4/4
✓ Branch 173 → 174 taken 9730 times.
✓ Branch 173 → 179 taken 10586 times.
✓ Branch 174 → 175 taken 7390 times.
✓ Branch 174 → 179 taken 2340 times.
20316 if (copyCtorFunc != nullptr && copyCtorFunc->implicitDefault) {
265
1/2
✓ Branch 175 → 176 taken 7390 times.
✗ Branch 175 → 297 not taken.
7390 createCopyCtorBodyPreamble(copyCtorFunc->bodyScope);
266
2/4
✓ Branch 176 → 177 taken 7390 times.
✗ Branch 176 → 297 not taken.
✗ Branch 177 → 178 not taken.
✓ Branch 177 → 179 taken 7390 times.
7390 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 20316 times.
✗ Branch 179 → 297 not taken.
✓ Branch 180 → 181 taken 231 times.
✓ Branch 180 → 186 taken 20085 times.
20316 if (const Function *moveCtorFunc = FunctionManager::findMoveCtor(currentScope);
272
2/2
✓ Branch 181 → 182 taken 34 times.
✓ Branch 181 → 186 taken 197 times.
231 moveCtorFunc && moveCtorFunc->implicitDefault) {
273
1/2
✓ Branch 182 → 183 taken 34 times.
✗ Branch 182 → 297 not taken.
34 createMoveCtorBodyPreamble(moveCtorFunc->bodyScope);
274
2/4
✓ Branch 183 → 184 taken 34 times.
✗ Branch 183 → 297 not taken.
✗ Branch 184 → 185 not taken.
✓ Branch 184 → 186 taken 34 times.
34 assert(manifestation->areAllFieldsInitialized() == nullptr);
275 }
276
277 // Check default dtor body if required
278
2/4
✓ Branch 189 → 190 taken 20316 times.
✗ Branch 189 → 290 not taken.
✓ Branch 190 → 191 taken 20316 times.
✗ Branch 190 → 288 not taken.
60948 const Function *dtorFunc = FunctionManager::lookup(currentScope, DTOR_FUNCTION_NAME, structType, {}, true);
279
4/4
✓ Branch 194 → 195 taken 10482 times.
✓ Branch 194 → 197 taken 9834 times.
✓ Branch 195 → 196 taken 7247 times.
✓ Branch 195 → 197 taken 3235 times.
20316 if (dtorFunc != nullptr && dtorFunc->implicitDefault)
280
1/2
✓ Branch 196 → 197 taken 7247 times.
✗ Branch 196 → 297 not taken.
7247 createDtorBodyPreamble(dtorFunc->bodyScope, node);
281
282 // Reset field symbols to declared state for the next manifestation
283
1/2
✓ Branch 197 → 198 taken 20316 times.
✗ Branch 197 → 297 not taken.
20316 manifestation->resetFieldSymbolsToDeclared(node);
284
285 // Clear type mapping
286 20316 typeMapping.clear();
287
288 // Return to the root scope
289 20316 currentScope = rootScope;
290
2/4
✓ Branch 199 → 200 taken 20316 times.
✗ Branch 199 → 202 not taken.
✓ Branch 200 → 201 taken 20316 times.
✗ Branch 200 → 202 not taken.
20316 assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL);
291
292 20316 manIdx++; // Increase the manifestation index
293 20316 }
294 14774 manIdx = 0; // Reset the manifestation index
295
296
1/2
✓ Branch 216 → 217 taken 14774 times.
✗ Branch 216 → 301 not taken.
29548 return nullptr;
297 }
298
299 90 std::any TypeChecker::visitUnionDefCheck(UnionDefNode *node) {
300 90 node->resizeToNumberOfManifestations(node->unionManifestations.size());
301 90 manIdx = 0; // Reset the manifestation index
302
303 // Get all manifestations for this union definition
304
2/2
✓ Branch 55 → 6 taken 90 times.
✓ Branch 55 → 56 taken 90 times.
270 for (Union *manifestation : node->unionManifestations) {
305 // Skip non-substantiated manifestations
306
3/4
✓ Branch 8 → 9 taken 90 times.
✗ Branch 8 → 63 not taken.
✓ Branch 9 → 10 taken 4 times.
✓ Branch 9 → 11 taken 86 times.
90 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 86 times.
✗ Branch 11 → 63 not taken.
86 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 86 times.
86 assert(typeMapping.empty());
316
1/2
✓ Branch 15 → 16 taken 86 times.
✗ Branch 15 → 63 not taken.
86 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 532 times.
✓ Branch 39 → 40 taken 86 times.
704 for (const FieldNode *field : node->fields) {
321
2/2
✓ Branch 20 → 21 taken 8 times.
✓ Branch 20 → 30 taken 524 times.
532 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 86 typeMapping.clear();
331
332 // Return to the root scope
333 86 currentScope = rootScope;
334
2/4
✓ Branch 41 → 42 taken 86 times.
✗ Branch 41 → 44 not taken.
✓ Branch 42 → 43 taken 86 times.
✗ Branch 42 → 44 not taken.
86 assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL);
335
336 86 manIdx++; // Increase the manifestation index
337 }
338 90 manIdx = 0; // Reset the manifestation index
339
340
1/2
✓ Branch 56 → 57 taken 90 times.
✗ Branch 56 → 64 not taken.
180 return nullptr;
341 }
342
343 } // namespace spice::compiler
344