GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 94.7% 481 / 0 / 508
Functions: 100.0% 18 / 0 / 18
Branches: 56.7% 695 / 0 / 1226

src/typechecker/TypeCheckerTopLevelDefinitionsPrepare.cpp
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 #include "TypeChecker.h"
4
5 #include <unordered_set>
6
7 #include <SourceFile.h>
8 #include <ast/Attributes.h>
9 #include <global/GlobalResourceManager.h>
10 #include <global/TypeRegistry.h>
11 #include <model/GenericType.h>
12 #include <model/Interface.h>
13 #include <model/Union.h>
14 #include <symboltablebuilder/Scope.h>
15 #include <symboltablebuilder/SymbolTableBuilder.h>
16 #include <typechecker/FunctionManager.h>
17 #include <typechecker/InterfaceManager.h>
18 #include <typechecker/MacroDefs.h>
19 #include <typechecker/StructManager.h>
20 #include <typechecker/UnionManager.h>
21
22 namespace spice::compiler {
23
24 1172 std::any TypeChecker::visitMainFctDefPrepare(MainFctDefNode *node) {
25 // Mark unreachable statements
26 1172 bool returnsOnAllControlPaths = true;
27
1/2
✓ Branch 2 → 3 taken 1172 times.
✗ Branch 2 → 77 not taken.
1172 node->returnsOnAllControlPaths(&returnsOnAllControlPaths, manIdx);
28
29 // Retrieve return type
30
1/2
✓ Branch 3 → 4 taken 1172 times.
✗ Branch 3 → 77 not taken.
1172 const QualType returnType(TY_INT);
31
32 // Change to function body scope
33 1172 currentScope = node->bodyScope;
34
35 // Set type of 'result' variable to int
36
1/2
✓ Branch 6 → 7 taken 1172 times.
✗ Branch 6 → 56 not taken.
3516 SymbolTableEntry *resultEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME);
37
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 1172 times.
1172 assert(resultEntry != nullptr);
38
1/2
✓ Branch 14 → 15 taken 1172 times.
✗ Branch 14 → 77 not taken.
1172 resultEntry->updateType(returnType, false);
39 1172 resultEntry->used = true;
40
41 // Retrieve param types
42 1172 QualTypeList paramTypes;
43
2/2
✓ Branch 15 → 16 taken 14 times.
✓ Branch 15 → 36 taken 1158 times.
1172 if (node->takesArgs) {
44
2/4
✓ Branch 16 → 17 taken 14 times.
✗ Branch 16 → 62 not taken.
✓ Branch 17 → 18 taken 14 times.
✗ Branch 17 → 60 not taken.
14 auto namedParamList = std::any_cast<NamedParamList>(visit(node->paramLst));
45
2/2
✓ Branch 33 → 21 taken 28 times.
✓ Branch 33 → 34 taken 14 times.
56 for (const auto &[name, qualType, isOptional] : namedParamList)
46
1/2
✓ Branch 23 → 24 taken 28 times.
✗ Branch 23 → 63 not taken.
28 paramTypes.push_back(qualType);
47 14 }
48
49 // Prepare type of function
50
2/4
✓ Branch 36 → 37 taken 1172 times.
✗ Branch 36 → 67 not taken.
✓ Branch 37 → 38 taken 1172 times.
✗ Branch 37 → 67 not taken.
1172 const QualType functionType = QualType(TY_FUNCTION).getWithFunctionParamAndReturnTypes(returnType, paramTypes);
51
52 // Update main function symbol type
53
1/2
✓ Branch 40 → 41 taken 1172 times.
✗ Branch 40 → 70 not taken.
3516 SymbolTableEntry *functionEntry = rootScope->lookupStrict(MAIN_FUNCTION_NAME);
54
1/2
✗ Branch 46 → 47 not taken.
✓ Branch 46 → 48 taken 1172 times.
1172 assert(functionEntry != nullptr);
55
1/2
✓ Branch 48 → 49 taken 1172 times.
✗ Branch 48 → 75 not taken.
1172 functionEntry->updateType(functionType, false);
56 1172 functionEntry->used = true;
57
58 // Leave main function body scope
59 1172 currentScope = rootScope;
60
61
1/2
✓ Branch 49 → 50 taken 1172 times.
✗ Branch 49 → 74 not taken.
2344 return nullptr;
62 1172 }
63
64 48728 std::any TypeChecker::visitFctDefPrepare(FctDefNode *node) {
65 // Check if name is dtor
66
3/4
✓ Branch 2 → 3 taken 48728 times.
✗ Branch 2 → 424 not taken.
✓ Branch 3 → 4 taken 2 times.
✓ Branch 3 → 13 taken 48726 times.
48728 if (node->name->name == DTOR_FUNCTION_NAME)
67
3/6
✓ Branch 6 → 7 taken 2 times.
✗ Branch 6 → 281 not taken.
✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 279 not taken.
✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 285 not taken.
8 SOFT_ERROR_BOOL(node, DTOR_MUST_BE_PROCEDURE, "Destructors are not allowed to be of type function")
68
69 // Check if all control paths in the function return
70 48726 bool doSetPredecessorsUnreachable = true;
71
3/4
✓ Branch 13 → 14 taken 48726 times.
✗ Branch 13 → 424 not taken.
✓ Branch 14 → 15 taken 2 times.
✓ Branch 14 → 24 taken 48724 times.
48726 if (!node->returnsOnAllControlPaths(&doSetPredecessorsUnreachable, manIdx))
72
3/6
✓ Branch 17 → 18 taken 2 times.
✗ Branch 17 → 288 not taken.
✓ Branch 18 → 19 taken 2 times.
✗ Branch 18 → 286 not taken.
✓ Branch 21 → 22 taken 2 times.
✗ Branch 21 → 292 not taken.
8 SOFT_ERROR_BOOL(node, MISSING_RETURN_STMT, "Not all control paths of this function have a return statement")
73
74 // Change to function scope
75 48724 currentScope = node->scope;
76
1/2
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 26 taken 48724 times.
48724 assert(currentScope->type == ScopeType::FUNC_PROC_BODY);
77
78 // Retrieve function template types
79 48724 std::vector<GenericType> usedGenericTypes;
80
2/2
✓ Branch 26 → 27 taken 4950 times.
✓ Branch 26 → 65 taken 43774 times.
48724 if (node->hasTemplateTypes) {
81
2/2
✓ Branch 63 → 29 taken 6030 times.
✓ Branch 63 → 64 taken 4948 times.
15928 for (DataTypeNode *dataType : node->templateTypeLst->dataTypes) {
82 // Visit template type
83
2/4
✓ Branch 31 → 32 taken 6030 times.
✗ Branch 31 → 295 not taken.
✓ Branch 32 → 33 taken 6030 times.
✗ Branch 32 → 293 not taken.
6030 auto templateType = std::any_cast<QualType>(visit(dataType));
84
2/4
✓ Branch 34 → 35 taken 6030 times.
✗ Branch 34 → 305 not taken.
✗ Branch 35 → 36 not taken.
✓ Branch 35 → 37 taken 6030 times.
6030 if (templateType.is(TY_UNRESOLVED))
85 continue;
86 // Check if it is a generic type
87
3/4
✓ Branch 37 → 38 taken 6030 times.
✗ Branch 37 → 305 not taken.
✓ Branch 38 → 39 taken 2 times.
✓ Branch 38 → 47 taken 6028 times.
6030 if (!templateType.is(TY_GENERIC))
88
2/4
✓ Branch 42 → 43 taken 2 times.
✗ Branch 42 → 299 not taken.
✓ Branch 43 → 44 taken 2 times.
✗ Branch 43 → 296 not taken.
6 throw SemanticError(dataType, EXPECTED_GENERIC_TYPE, "A template list can only contain generic types");
89 // Convert generic symbol type to generic type
90
2/4
✓ Branch 47 → 48 taken 6028 times.
✗ Branch 47 → 305 not taken.
✓ Branch 48 → 49 taken 6028 times.
✗ Branch 48 → 305 not taken.
6028 GenericType *genericType = rootScope->lookupGenericTypeStrict(templateType.getSubType());
91
1/2
✗ Branch 49 → 50 not taken.
✓ Branch 49 → 51 taken 6028 times.
6028 assert(genericType != nullptr);
92
1/2
✓ Branch 51 → 52 taken 6028 times.
✗ Branch 51 → 305 not taken.
6028 usedGenericTypes.push_back(*genericType);
93 }
94 }
95
96 // Retrieve 'this' type
97
1/2
✓ Branch 65 → 66 taken 48722 times.
✗ Branch 65 → 422 not taken.
48722 QualType thisType(TY_DYN); // If the function is not a method, the default this type is TY_DYN
98
2/2
✓ Branch 66 → 67 taken 24905 times.
✓ Branch 66 → 105 taken 23817 times.
48722 if (node->isMethod) {
99 24905 Scope *structParentScope = node->structScope->parent;
100
1/2
✓ Branch 67 → 68 taken 24905 times.
✗ Branch 67 → 315 not taken.
24905 SymbolTableEntry *structEntry = structParentScope->lookupStrict(node->name->structName);
101
1/2
✗ Branch 70 → 71 not taken.
✓ Branch 70 → 72 taken 24905 times.
24905 assert(structEntry != nullptr);
102 // Set struct to used
103 24905 structEntry->used = true;
104 // Get type and ptr type
105
1/2
✓ Branch 72 → 73 taken 24905 times.
✗ Branch 72 → 315 not taken.
24905 thisType = structEntry->getQualType();
106
1/2
✓ Branch 73 → 74 taken 24905 times.
✗ Branch 73 → 315 not taken.
24905 const QualType thisPtrType = thisType.toPtr(node);
107 // Collect template types of 'this' type
108
3/4
✓ Branch 74 → 75 taken 24905 times.
✗ Branch 74 → 308 not taken.
✓ Branch 92 → 77 taken 8461 times.
✓ Branch 92 → 93 taken 24905 times.
58271 for (const QualType &templateType : thisType.getTemplateTypes()) {
109 1934 const auto lambda = [&](const GenericType &genericType) { return genericType == templateType; };
110
3/4
✓ Branch 79 → 80 taken 8461 times.
✗ Branch 79 → 307 not taken.
✓ Branch 80 → 81 taken 8422 times.
✓ Branch 80 → 82 taken 39 times.
8461 if (std::ranges::none_of(usedGenericTypes, lambda))
111
1/2
✓ Branch 81 → 82 taken 8422 times.
✗ Branch 81 → 307 not taken.
8422 usedGenericTypes.emplace_back(templateType);
112 8461 usedGenericTypes.back().used = true;
113 }
114
115 // Set type of 'this' variable
116
1/2
✓ Branch 95 → 96 taken 24905 times.
✗ Branch 95 → 311 not taken.
74715 SymbolTableEntry *thisEntry = currentScope->lookupStrict(THIS_VARIABLE_NAME);
117
1/2
✗ Branch 101 → 102 not taken.
✓ Branch 101 → 103 taken 24905 times.
24905 assert(thisEntry != nullptr);
118
1/2
✓ Branch 103 → 104 taken 24905 times.
✗ Branch 103 → 315 not taken.
24905 thisEntry->updateType(thisPtrType, false);
119 }
120
121 // Visit parameters
122 48722 QualTypeList paramTypes;
123 48722 ParamList paramList;
124
2/2
✓ Branch 105 → 106 taken 35396 times.
✓ Branch 105 → 152 taken 13326 times.
48722 if (node->hasParams) {
125 35396 std::vector<const char *> paramNames;
126 // Visit param list to retrieve the param names
127
2/4
✓ Branch 106 → 107 taken 35396 times.
✗ Branch 106 → 318 not taken.
✓ Branch 107 → 108 taken 35396 times.
✗ Branch 107 → 316 not taken.
35396 auto namedParamList = std::any_cast<NamedParamList>(visit(node->paramLst));
128
2/2
✓ Branch 140 → 111 taken 53418 times.
✓ Branch 140 → 141 taken 35392 times.
124206 for (const auto &[name, qualType, isOptional] : namedParamList) {
129
1/2
✓ Branch 113 → 114 taken 53418 times.
✗ Branch 113 → 330 not taken.
53418 paramNames.push_back(name);
130
2/6
✓ Branch 114 → 115 taken 53418 times.
✗ Branch 114 → 330 not taken.
✗ Branch 115 → 116 not taken.
✓ Branch 115 → 119 taken 53418 times.
✗ Branch 116 → 117 not taken.
✗ Branch 116 → 319 not taken.
53418 HANDLE_UNRESOLVED_TYPE_PTR(qualType);
131
1/2
✓ Branch 119 → 120 taken 53418 times.
✗ Branch 119 → 330 not taken.
53418 paramTypes.push_back(qualType);
132
1/2
✓ Branch 120 → 121 taken 53418 times.
✗ Branch 120 → 320 not taken.
53418 paramList.push_back({qualType, isOptional});
133 // Check if the type is present in the template for generic types
134
3/4
✓ Branch 121 → 122 taken 53418 times.
✗ Branch 121 → 330 not taken.
✓ Branch 122 → 123 taken 4 times.
✓ Branch 122 → 131 taken 53414 times.
53418 if (!qualType.isCoveredByGenericTypeList(usedGenericTypes))
135 throw SemanticError(node->paramLst, GENERIC_TYPE_NOT_IN_TEMPLATE,
136
2/4
✓ Branch 126 → 127 taken 4 times.
✗ Branch 126 → 324 not taken.
✓ Branch 127 → 128 taken 4 times.
✗ Branch 127 → 321 not taken.
12 "Generic param type not included in the template type list of the function");
137 }
138
2/4
✓ Branch 143 → 144 taken 35392 times.
✗ Branch 143 → 145 not taken.
✓ Branch 148 → 149 taken 35392 times.
✗ Branch 148 → 151 not taken.
70792 }
139
140 // Retrieve return type
141
2/4
✓ Branch 152 → 153 taken 48718 times.
✗ Branch 152 → 338 not taken.
✓ Branch 153 → 154 taken 48718 times.
✗ Branch 153 → 336 not taken.
48718 auto returnType = std::any_cast<QualType>(visit(node->returnType));
142
2/6
✓ Branch 155 → 156 taken 48718 times.
✗ Branch 155 → 418 not taken.
✗ Branch 156 → 157 not taken.
✓ Branch 156 → 160 taken 48718 times.
✗ Branch 157 → 158 not taken.
✗ Branch 157 → 339 not taken.
48718 HANDLE_UNRESOLVED_TYPE_PTR(returnType)
143
3/4
✓ Branch 160 → 161 taken 48718 times.
✗ Branch 160 → 418 not taken.
✓ Branch 161 → 162 taken 2 times.
✓ Branch 161 → 171 taken 48716 times.
48718 if (returnType.is(TY_DYN))
144
3/6
✓ Branch 164 → 165 taken 2 times.
✗ Branch 164 → 342 not taken.
✓ Branch 165 → 166 taken 2 times.
✗ Branch 165 → 340 not taken.
✓ Branch 168 → 169 taken 2 times.
✗ Branch 168 → 346 not taken.
8 SOFT_ERROR_BOOL(node, UNEXPECTED_DYN_TYPE, "Dyn return types are not allowed")
145
3/4
✓ Branch 171 → 172 taken 48716 times.
✗ Branch 171 → 418 not taken.
✓ Branch 172 → 173 taken 2 times.
✓ Branch 172 → 182 taken 48714 times.
48716 if (!returnType.isCoveredByGenericTypeList(usedGenericTypes))
146
3/6
✓ Branch 175 → 176 taken 2 times.
✗ Branch 175 → 349 not taken.
✓ Branch 176 → 177 taken 2 times.
✗ Branch 176 → 347 not taken.
✓ Branch 179 → 180 taken 2 times.
✗ Branch 179 → 353 not taken.
8 SOFT_ERROR_BOOL(node->returnType, GENERIC_TYPE_NOT_IN_TEMPLATE,
147 "Generic return type not included in the template type list of the function")
148
149 // Leave function body scope
150 48714 currentScope = node->scope->parent;
151
3/4
✓ Branch 182 → 183 taken 24905 times.
✓ Branch 182 → 185 taken 23809 times.
✗ Branch 183 → 184 not taken.
✓ Branch 183 → 185 taken 24905 times.
48714 assert(currentScope->type == ScopeType::GLOBAL || currentScope->type == ScopeType::STRUCT);
152
153 // Prepare type of function
154
2/4
✓ Branch 185 → 186 taken 48714 times.
✗ Branch 185 → 354 not taken.
✓ Branch 186 → 187 taken 48714 times.
✗ Branch 186 → 354 not taken.
48714 QualType functionType = QualType(TY_FUNCTION).getWithFunctionParamAndReturnTypes(returnType, paramTypes);
155 48714 functionType.setQualifiers(node->qualifiers);
156
157 // Update type of function entry
158
1/2
✓ Branch 188 → 189 taken 48714 times.
✗ Branch 188 → 357 not taken.
97428 SymbolTableEntry *functionEntry = currentScope->lookupStrict(node->getSymbolTableEntryName());
159
1/2
✗ Branch 193 → 194 not taken.
✓ Branch 193 → 195 taken 48714 times.
48714 assert(functionEntry != nullptr);
160
1/2
✓ Branch 195 → 196 taken 48714 times.
✗ Branch 195 → 418 not taken.
48714 functionEntry->updateType(functionType, false);
161
162 // Build function object
163
4/8
✓ Branch 196 → 197 taken 48714 times.
✗ Branch 196 → 366 not taken.
✓ Branch 197 → 198 taken 48714 times.
✗ Branch 197 → 363 not taken.
✓ Branch 198 → 199 taken 48714 times.
✗ Branch 198 → 360 not taken.
✓ Branch 199 → 200 taken 48714 times.
✗ Branch 199 → 358 not taken.
48714 Function spiceFunc(node->name->name, functionEntry, thisType, returnType, paramList, usedGenericTypes, node);
164 48714 spiceFunc.bodyScope = node->scope;
165
2/2
✓ Branch 203 → 204 taken 48712 times.
✓ Branch 203 → 416 taken 2 times.
48714 FunctionManager::insert(currentScope, spiceFunc, &node->manifestations);
166
167 // Check function attributes
168
2/2
✓ Branch 204 → 205 taken 1612 times.
✓ Branch 204 → 252 taken 47100 times.
48712 if (node->attrs) {
169 1612 const AttrLstNode *attrLst = node->attrs->attrLst;
170 1612 Function *firstManifestation = node->manifestations.front();
171
4/6
✓ Branch 208 → 209 taken 1612 times.
✗ Branch 208 → 369 not taken.
✓ Branch 209 → 210 taken 1612 times.
✗ Branch 209 → 367 not taken.
✓ Branch 212 → 213 taken 2 times.
✓ Branch 212 → 214 taken 1610 times.
4836 if (const CompileTimeValue *value = attrLst->getAttrValueByName(ATTR_CORE_COMPILER_MANGLE))
172 2 firstManifestation->mangleFunctionName = value->boolValue;
173
3/6
✓ Branch 216 → 217 taken 1612 times.
✗ Branch 216 → 375 not taken.
✓ Branch 217 → 218 taken 1612 times.
✗ Branch 217 → 373 not taken.
✗ Branch 220 → 221 not taken.
✓ Branch 220 → 223 taken 1612 times.
4836 if (const CompileTimeValue *value = attrLst->getAttrValueByName(ATTR_CORE_COMPILER_MANGLED_NAME)) {
174 const std::string &stringValue = resourceManager.compileTimeStringValues.at(value->stringValueOffset);
175 firstManifestation->predefinedMangledName = stringValue;
176 }
177
6/8
✓ Branch 225 → 226 taken 1612 times.
✗ Branch 225 → 381 not taken.
✓ Branch 226 → 227 taken 1612 times.
✗ Branch 226 → 379 not taken.
✓ Branch 229 → 230 taken 224 times.
✓ Branch 229 → 252 taken 1388 times.
✓ Branch 230 → 231 taken 222 times.
✓ Branch 230 → 252 taken 2 times.
4836 if (const CompileTimeValue *value = attrLst->getAttrValueByName(ATTR_TEST); value && value->boolValue) {
178 // Make sure that the function has the correct signature
179
2/2
✓ Branch 231 → 232 taken 2 times.
✓ Branch 231 → 240 taken 220 times.
222 if (node->hasParams)
180
2/4
✓ Branch 235 → 236 taken 2 times.
✗ Branch 235 → 388 not taken.
✓ Branch 236 → 237 taken 2 times.
✗ Branch 236 → 385 not taken.
6 throw SemanticError(node->paramLst, TEST_FUNCTION_WITH_PARAMS, "Test function may not have parameters");
181
3/4
✓ Branch 240 → 241 taken 220 times.
✗ Branch 240 → 416 not taken.
✓ Branch 241 → 242 taken 2 times.
✓ Branch 241 → 250 taken 218 times.
220 if (!returnType.is(TY_BOOL))
182
2/4
✓ Branch 245 → 246 taken 2 times.
✗ Branch 245 → 397 not taken.
✓ Branch 246 → 247 taken 2 times.
✗ Branch 246 → 394 not taken.
6 throw SemanticError(node->returnType, TEST_FUNCTION_WRONG_RETURN_TYPE, "Test function must return a bool");
183 // Add to test function list
184 218 firstManifestation->entry->used = true; // Avoid printing unused warnings
185 218 firstManifestation->used = true; // Always keep test functions, because they are called implicitly by the test main
186
1/2
✓ Branch 251 → 252 taken 218 times.
✗ Branch 251 → 416 not taken.
218 sourceFile->testFunctions.push_back(node->manifestations.front());
187 }
188 }
189
190 // Duplicate / rename the original child scope to reflect the substantiated versions of the function
191
2/2
✓ Branch 262 → 253 taken 3820 times.
✓ Branch 262 → 263 taken 48708 times.
52528 for (size_t i = 1; i < node->manifestations.size(); i++) {
192
4/8
✓ Branch 253 → 254 taken 3820 times.
✗ Branch 253 → 408 not taken.
✓ Branch 254 → 255 taken 3820 times.
✗ Branch 254 → 408 not taken.
✓ Branch 255 → 256 taken 3820 times.
✗ Branch 255 → 405 not taken.
✓ Branch 256 → 257 taken 3820 times.
✗ Branch 256 → 403 not taken.
3820 Scope *scope = currentScope->copyChildScope(node->getScopeId(), node->manifestations.at(i)->getScopeName());
193
1/2
✓ Branch 259 → 260 taken 3820 times.
✗ Branch 259 → 416 not taken.
3820 node->manifestations.at(i)->bodyScope = scope;
194 }
195
3/6
✓ Branch 264 → 265 taken 48708 times.
✗ Branch 264 → 414 not taken.
✓ Branch 265 → 266 taken 48708 times.
✗ Branch 265 → 411 not taken.
✓ Branch 266 → 267 taken 48708 times.
✗ Branch 266 → 409 not taken.
48708 currentScope->renameChildScope(node->getScopeId(), node->manifestations.front()->getScopeName());
196
197 // Change to the root scope
198 48708 currentScope = rootScope;
199
1/2
✗ Branch 269 → 270 not taken.
✓ Branch 269 → 271 taken 48708 times.
48708 assert(currentScope->type == ScopeType::GLOBAL);
200
201
1/2
✓ Branch 271 → 272 taken 48708 times.
✗ Branch 271 → 415 not taken.
48708 return nullptr;
202 48750 }
203
204 29248 std::any TypeChecker::visitProcDefPrepare(ProcDefNode *node) {
205 // Mark unreachable statements
206 29248 bool doSetPredecessorsUnreachable = true;
207
1/2
✓ Branch 2 → 3 taken 29248 times.
✗ Branch 2 → 316 not taken.
29248 node->returnsOnAllControlPaths(&doSetPredecessorsUnreachable, manIdx);
208
209 // Check if dtor and has params
210
7/8
✓ Branch 3 → 4 taken 21627 times.
✓ Branch 3 → 7 taken 7621 times.
✓ Branch 4 → 5 taken 21627 times.
✗ Branch 4 → 316 not taken.
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 7 taken 21625 times.
✓ Branch 8 → 9 taken 2 times.
✓ Branch 8 → 17 taken 29246 times.
29248 if (node->hasParams && node->name->name == DTOR_FUNCTION_NAME)
211
2/4
✓ Branch 12 → 13 taken 2 times.
✗ Branch 12 → 219 not taken.
✓ Branch 13 → 14 taken 2 times.
✗ Branch 13 → 216 not taken.
6 throw SemanticError(node, DTOR_WITH_PARAMS, "It is not allowed to specify parameters for destructors");
212
213 // Change to procedure scope
214 29246 currentScope = node->scope;
215
1/2
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 29246 times.
29246 assert(currentScope->type == ScopeType::FUNC_PROC_BODY);
216
217 // Retrieve procedure template types
218 29246 std::vector<GenericType> usedGenericTypes;
219
2/2
✓ Branch 19 → 20 taken 5042 times.
✓ Branch 19 → 58 taken 24204 times.
29246 if (node->hasTemplateTypes) {
220
2/2
✓ Branch 56 → 22 taken 5681 times.
✓ Branch 56 → 57 taken 5040 times.
15763 for (DataTypeNode *dataType : node->templateTypeLst->dataTypes) {
221 // Visit template type
222
2/4
✓ Branch 24 → 25 taken 5681 times.
✗ Branch 24 → 227 not taken.
✓ Branch 25 → 26 taken 5681 times.
✗ Branch 25 → 225 not taken.
5681 auto templateType = std::any_cast<QualType>(visit(dataType));
223
2/4
✓ Branch 27 → 28 taken 5681 times.
✗ Branch 27 → 237 not taken.
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 5681 times.
5681 if (templateType.is(TY_UNRESOLVED))
224 continue;
225 // Check if it is a generic type
226
3/4
✓ Branch 30 → 31 taken 5681 times.
✗ Branch 30 → 237 not taken.
✓ Branch 31 → 32 taken 2 times.
✓ Branch 31 → 40 taken 5679 times.
5681 if (!templateType.is(TY_GENERIC))
227
2/4
✓ Branch 35 → 36 taken 2 times.
✗ Branch 35 → 231 not taken.
✓ Branch 36 → 37 taken 2 times.
✗ Branch 36 → 228 not taken.
6 throw SemanticError(dataType, EXPECTED_GENERIC_TYPE, "A template list can only contain generic types");
228 // Convert generic symbol type to generic type
229
2/4
✓ Branch 40 → 41 taken 5679 times.
✗ Branch 40 → 237 not taken.
✓ Branch 41 → 42 taken 5679 times.
✗ Branch 41 → 237 not taken.
5679 const GenericType *genericType = rootScope->lookupGenericTypeStrict(templateType.getSubType());
230
1/2
✗ Branch 42 → 43 not taken.
✓ Branch 42 → 44 taken 5679 times.
5679 assert(genericType != nullptr);
231
1/2
✓ Branch 44 → 45 taken 5679 times.
✗ Branch 44 → 237 not taken.
5679 usedGenericTypes.push_back(*genericType);
232 }
233 }
234
235 // Retrieve 'this' type
236
1/2
✓ Branch 58 → 59 taken 29244 times.
✗ Branch 58 → 314 not taken.
29244 QualType thisType(TY_DYN); // If the procedure is not a method, the default this type is TY_DYN
237
2/2
✓ Branch 59 → 60 taken 23932 times.
✓ Branch 59 → 98 taken 5312 times.
29244 if (node->isMethod) {
238 23932 Scope *structParentScope = node->structScope->parent;
239
1/2
✓ Branch 60 → 61 taken 23932 times.
✗ Branch 60 → 247 not taken.
23932 SymbolTableEntry *structEntry = structParentScope->lookupStrict(node->name->structName);
240
1/2
✗ Branch 63 → 64 not taken.
✓ Branch 63 → 65 taken 23932 times.
23932 assert(structEntry != nullptr);
241 // Set struct to used
242 23932 structEntry->used = true;
243 // Get type and ptr type
244
1/2
✓ Branch 65 → 66 taken 23932 times.
✗ Branch 65 → 247 not taken.
23932 thisType = structEntry->getQualType();
245
1/2
✓ Branch 66 → 67 taken 23932 times.
✗ Branch 66 → 247 not taken.
23932 const QualType thisPtrType = thisType.toPtr(node);
246 // Collect template types of 'this' type
247
3/4
✓ Branch 67 → 68 taken 23932 times.
✗ Branch 67 → 240 not taken.
✓ Branch 85 → 70 taken 8190 times.
✓ Branch 85 → 86 taken 23932 times.
56054 for (const QualType &templateType : thisType.getTemplateTypes()) {
248 2533 const auto lambda = [&](const GenericType &genericType) { return genericType == templateType; };
249
3/4
✓ Branch 72 → 73 taken 8190 times.
✗ Branch 72 → 239 not taken.
✓ Branch 73 → 74 taken 7628 times.
✓ Branch 73 → 75 taken 562 times.
8190 if (std::ranges::none_of(usedGenericTypes, lambda))
250
1/2
✓ Branch 74 → 75 taken 7628 times.
✗ Branch 74 → 239 not taken.
7628 usedGenericTypes.emplace_back(templateType);
251 8190 usedGenericTypes.back().used = true;
252 }
253
254 // Set type of 'this' variable
255
1/2
✓ Branch 88 → 89 taken 23932 times.
✗ Branch 88 → 243 not taken.
71796 SymbolTableEntry *thisEntry = currentScope->lookupStrict(THIS_VARIABLE_NAME);
256
1/2
✗ Branch 94 → 95 not taken.
✓ Branch 94 → 96 taken 23932 times.
23932 assert(thisEntry != nullptr);
257
1/2
✓ Branch 96 → 97 taken 23932 times.
✗ Branch 96 → 247 not taken.
23932 thisEntry->updateType(thisPtrType, false);
258 }
259
260 // Visit parameters
261 29244 QualTypeList paramTypes;
262 29244 ParamList paramList;
263
2/2
✓ Branch 98 → 99 taken 21625 times.
✓ Branch 98 → 145 taken 7619 times.
29244 if (node->hasParams) {
264 21625 std::vector<const char *> paramNames;
265 // Visit param list to retrieve the param names
266
2/4
✓ Branch 99 → 100 taken 21625 times.
✗ Branch 99 → 250 not taken.
✓ Branch 100 → 101 taken 21625 times.
✗ Branch 100 → 248 not taken.
21625 auto namedParamList = std::any_cast<NamedParamList>(visit(node->paramLst));
267
2/2
✓ Branch 133 → 104 taken 34383 times.
✓ Branch 133 → 134 taken 21621 times.
77629 for (const auto &[name, qualType, isOptional] : namedParamList) {
268
1/2
✓ Branch 106 → 107 taken 34383 times.
✗ Branch 106 → 262 not taken.
34383 paramNames.push_back(name);
269
1/2
✓ Branch 107 → 108 taken 34383 times.
✗ Branch 107 → 262 not taken.
34383 paramTypes.push_back(qualType);
270
4/6
✓ Branch 108 → 109 taken 34383 times.
✗ Branch 108 → 262 not taken.
✓ Branch 109 → 110 taken 2 times.
✓ Branch 109 → 113 taken 34381 times.
✓ Branch 110 → 111 taken 2 times.
✗ Branch 110 → 251 not taken.
34385 HANDLE_UNRESOLVED_TYPE_PTR(qualType);
271
1/2
✓ Branch 113 → 114 taken 34381 times.
✗ Branch 113 → 252 not taken.
34381 paramList.push_back({qualType, isOptional});
272 // Check if the type is present in the template for generic types
273
3/4
✓ Branch 114 → 115 taken 34381 times.
✗ Branch 114 → 262 not taken.
✓ Branch 115 → 116 taken 2 times.
✓ Branch 115 → 124 taken 34379 times.
34381 if (!qualType.isCoveredByGenericTypeList(usedGenericTypes))
274 throw SemanticError(node->paramLst, GENERIC_TYPE_NOT_IN_TEMPLATE,
275
2/4
✓ Branch 119 → 120 taken 2 times.
✗ Branch 119 → 256 not taken.
✓ Branch 120 → 121 taken 2 times.
✗ Branch 120 → 253 not taken.
6 "Generic param type not included in the template type list of the procedure");
276 }
277
4/4
✓ Branch 136 → 137 taken 21621 times.
✓ Branch 136 → 138 taken 2 times.
✓ Branch 141 → 142 taken 21621 times.
✓ Branch 141 → 144 taken 2 times.
43250 }
278
279 // Leave procedure body scope
280 29240 currentScope = node->scope->parent;
281
3/4
✓ Branch 145 → 146 taken 23932 times.
✓ Branch 145 → 148 taken 5308 times.
✗ Branch 146 → 147 not taken.
✓ Branch 146 → 148 taken 23932 times.
29240 assert(currentScope->type == ScopeType::GLOBAL || currentScope->type == ScopeType::STRUCT);
282
283 // Prepare type of procedure
284
3/6
✓ Branch 148 → 149 taken 29240 times.
✗ Branch 148 → 269 not taken.
✓ Branch 149 → 150 taken 29240 times.
✗ Branch 149 → 268 not taken.
✓ Branch 150 → 151 taken 29240 times.
✗ Branch 150 → 268 not taken.
29240 QualType procedureType = QualType(TY_PROCEDURE).getWithFunctionParamAndReturnTypes(QualType(TY_DYN), paramTypes);
285 29240 procedureType.setQualifiers(node->qualifiers);
286
287 // Update type of procedure entry
288
1/2
✓ Branch 152 → 153 taken 29240 times.
✗ Branch 152 → 272 not taken.
58480 SymbolTableEntry *procedureEntry = currentScope->lookupStrict(node->getSymbolTableEntryName());
289
1/2
✗ Branch 157 → 158 not taken.
✓ Branch 157 → 159 taken 29240 times.
29240 assert(procedureEntry != nullptr);
290
1/2
✓ Branch 159 → 160 taken 29240 times.
✗ Branch 159 → 310 not taken.
29240 procedureEntry->updateType(procedureType, false);
291
292 // Build procedure object
293
5/10
✓ Branch 160 → 161 taken 29240 times.
✗ Branch 160 → 282 not taken.
✓ Branch 161 → 162 taken 29240 times.
✗ Branch 161 → 279 not taken.
✓ Branch 162 → 163 taken 29240 times.
✗ Branch 162 → 276 not taken.
✓ Branch 163 → 164 taken 29240 times.
✗ Branch 163 → 275 not taken.
✓ Branch 164 → 165 taken 29240 times.
✗ Branch 164 → 273 not taken.
29240 Function spiceProc(node->name->name, procedureEntry, thisType, QualType(TY_DYN), paramList, usedGenericTypes, node);
294 29240 spiceProc.bodyScope = node->scope;
295
2/2
✓ Branch 168 → 169 taken 29238 times.
✓ Branch 168 → 308 taken 2 times.
29240 FunctionManager::insert(currentScope, spiceProc, &node->manifestations);
296
297 // Check procedure attributes
298
1/2
✗ Branch 169 → 170 not taken.
✓ Branch 169 → 189 taken 29238 times.
29238 if (node->attrs) {
299 const AttrLstNode *attrLst = node->attrs->attrLst;
300 if (const CompileTimeValue *value = attrLst->getAttrValueByName(ATTR_CORE_COMPILER_MANGLE))
301 node->manifestations.front()->mangleFunctionName = value->boolValue;
302 if (const CompileTimeValue *value = attrLst->getAttrValueByName(ATTR_CORE_COMPILER_MANGLED_NAME)) {
303 const std::string &stringValue = resourceManager.compileTimeStringValues.at(value->stringValueOffset);
304 node->manifestations.front()->predefinedMangledName = stringValue;
305 }
306 }
307
308 // Duplicate / rename the original child scope to reflect the substantiated versions of the procedure
309
2/2
✓ Branch 199 → 190 taken 1234 times.
✓ Branch 199 → 200 taken 29238 times.
30472 for (size_t i = 1; i < node->manifestations.size(); i++) {
310
4/8
✓ Branch 190 → 191 taken 1234 times.
✗ Branch 190 → 300 not taken.
✓ Branch 191 → 192 taken 1234 times.
✗ Branch 191 → 300 not taken.
✓ Branch 192 → 193 taken 1234 times.
✗ Branch 192 → 297 not taken.
✓ Branch 193 → 194 taken 1234 times.
✗ Branch 193 → 295 not taken.
1234 Scope *scope = currentScope->copyChildScope(node->getScopeId(), node->manifestations.at(i)->getScopeName());
311
1/2
✓ Branch 196 → 197 taken 1234 times.
✗ Branch 196 → 308 not taken.
1234 node->manifestations.at(i)->bodyScope = scope;
312 }
313
3/6
✓ Branch 201 → 202 taken 29238 times.
✗ Branch 201 → 306 not taken.
✓ Branch 202 → 203 taken 29238 times.
✗ Branch 202 → 303 not taken.
✓ Branch 203 → 204 taken 29238 times.
✗ Branch 203 → 301 not taken.
29238 currentScope->renameChildScope(node->getScopeId(), node->manifestations.front()->getScopeName());
314
315 // Change to the root scope
316 29238 currentScope = rootScope;
317
1/2
✗ Branch 206 → 207 not taken.
✓ Branch 206 → 208 taken 29238 times.
29238 assert(currentScope->type == ScopeType::GLOBAL);
318
319
1/2
✓ Branch 208 → 209 taken 29238 times.
✗ Branch 208 → 307 not taken.
29238 return nullptr;
320 29256 }
321
322 /**
323 * Determine whether a field type (transitively) contains a struct or union with the given origin body scope by value,
324 * which would give the origin struct/union an infinite size. Only by-value struct/union fields are followed, including
325 * through fixed-size arrays thereof (e.g. `T[3]`), since those embed their element by value as well. Dynamic arrays,
326 * pointers and references break the cycle and have a fixed size. Struct/union types that are not manifested yet (e.g.
327 * still being prepared as part of a circular import) end a branch - such a cycle is still detected once the last one
328 * in it is prepared, when all the others are manifested.
329 *
330 * @param fieldType Type of the field to inspect
331 * @param originScope Body scope of the struct/union whose infinite size we are checking for
332 * @param node Accessing AST node (for struct/union lookup diagnostics)
333 * @param visited Set of already-visited struct/union scopes, to keep the walk finite
334 * @return true if the origin struct/union is reachable by value, i.e. it has infinite size
335 */
336 48588 static bool fieldContainsAggregateByValue(const QualType &fieldType, const Scope *originScope, const ASTNode *node,
337 std::unordered_set<const Scope *> &visited) {
338 // Unwrap fixed-size arrays, so that e.g. a `T[3]` field is treated like a `T` field for cycle detection. Dynamic
339 // arrays, pointers and references keep breaking the cycle, since they do not embed the element by value.
340
8/10
✓ Branch 2 → 3 taken 48588 times.
✗ Branch 2 → 45 not taken.
✓ Branch 3 → 4 taken 537 times.
✓ Branch 3 → 7 taken 48051 times.
✓ Branch 4 → 5 taken 537 times.
✗ Branch 4 → 45 not taken.
✓ Branch 5 → 6 taken 533 times.
✓ Branch 5 → 7 taken 4 times.
✓ Branch 8 → 9 taken 533 times.
✓ Branch 8 → 13 taken 48055 times.
48588 if (fieldType.isArray() && fieldType.getArraySize() > 0)
341
2/4
✓ Branch 9 → 10 taken 533 times.
✗ Branch 9 → 41 not taken.
✓ Branch 10 → 11 taken 533 times.
✗ Branch 10 → 41 not taken.
533 return fieldContainsAggregateByValue(fieldType.getContained(), originScope, node, visited);
342
3/4
✓ Branch 13 → 14 taken 48055 times.
✗ Branch 13 → 42 not taken.
✓ Branch 14 → 15 taken 35948 times.
✓ Branch 14 → 16 taken 12107 times.
48055 if (!fieldType.isOneOf({TY_STRUCT, TY_UNION}))
343 35948 return false;
344
1/2
✓ Branch 16 → 17 taken 12107 times.
✗ Branch 16 → 45 not taken.
12107 const Scope *fieldScope = fieldType.getBodyScope();
345
2/2
✓ Branch 17 → 18 taken 8 times.
✓ Branch 17 → 19 taken 12099 times.
12107 if (fieldScope == originScope)
346 8 return true;
347
6/8
✓ Branch 19 → 20 taken 12099 times.
✗ Branch 19 → 22 not taken.
✓ Branch 20 → 21 taken 12099 times.
✗ Branch 20 → 45 not taken.
✓ Branch 21 → 22 taken 209 times.
✓ Branch 21 → 23 taken 11890 times.
✓ Branch 24 → 25 taken 209 times.
✓ Branch 24 → 26 taken 11890 times.
12099 if (fieldScope == nullptr || !visited.insert(fieldScope).second)
348 209 return false;
349
350 11890 QualTypeList memberTypes;
351
3/4
✓ Branch 26 → 27 taken 11890 times.
✗ Branch 26 → 43 not taken.
✓ Branch 27 → 28 taken 11860 times.
✓ Branch 27 → 32 taken 30 times.
11890 if (fieldType.is(TY_STRUCT)) {
352
1/2
✓ Branch 28 → 29 taken 11860 times.
✗ Branch 28 → 43 not taken.
11860 const Struct *spiceStruct = fieldType.getStruct(node);
353
2/2
✓ Branch 29 → 30 taken 2 times.
✓ Branch 29 → 31 taken 11858 times.
11860 if (spiceStruct == nullptr)
354 2 return false; // Not manifested yet; the cycle is caught once the last aggregate in it is prepared
355
1/2
✓ Branch 31 → 36 taken 11858 times.
✗ Branch 31 → 43 not taken.
11858 memberTypes = spiceStruct->fieldTypes;
356 } else {
357
1/2
✓ Branch 32 → 33 taken 30 times.
✗ Branch 32 → 43 not taken.
30 const Union *spiceUnion = fieldType.getUnion(node);
358
1/2
✗ Branch 33 → 34 not taken.
✓ Branch 33 → 35 taken 30 times.
30 if (spiceUnion == nullptr)
359 return false; // Not manifested yet; the cycle is caught once the last aggregate in it is prepared
360
1/2
✓ Branch 35 → 36 taken 30 times.
✗ Branch 35 → 43 not taken.
30 memberTypes = spiceUnion->fieldTypes;
361 }
362
363
1/2
✓ Branch 36 → 37 taken 11888 times.
✗ Branch 36 → 43 not taken.
11888 return std::ranges::any_of(memberTypes, [&](const QualType &memberType) {
364 32726 return fieldContainsAggregateByValue(memberType, originScope, node, visited);
365 11888 });
366 11890 }
367
368 7457 std::any TypeChecker::visitStructDefPrepare(StructDefNode *node) {
369 7457 QualTypeList usedTemplateTypes;
370 7457 std::vector<GenericType> templateTypesGeneric;
371
372 // Retrieve struct template types
373
2/2
✓ Branch 2 → 3 taken 1462 times.
✓ Branch 2 → 46 taken 5995 times.
7457 if (node->hasTemplateTypes) {
374
1/2
✓ Branch 4 → 5 taken 1462 times.
✗ Branch 4 → 318 not taken.
1462 usedTemplateTypes.reserve(node->templateTypeLst->dataTypes.size());
375
1/2
✓ Branch 6 → 7 taken 1462 times.
✗ Branch 6 → 318 not taken.
1462 templateTypesGeneric.reserve(node->templateTypeLst->dataTypes.size());
376
2/2
✓ Branch 44 → 9 taken 2041 times.
✓ Branch 44 → 45 taken 1462 times.
4965 for (DataTypeNode *dataType : node->templateTypeLst->dataTypes) {
377 // Visit template type
378
2/4
✓ Branch 11 → 12 taken 2041 times.
✗ Branch 11 → 220 not taken.
✓ Branch 12 → 13 taken 2041 times.
✗ Branch 12 → 218 not taken.
2041 auto templateType = std::any_cast<QualType>(visit(dataType));
379
2/4
✓ Branch 14 → 15 taken 2041 times.
✗ Branch 14 → 230 not taken.
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 2041 times.
2041 if (templateType.is(TY_UNRESOLVED))
380 continue;
381 // Check if it is a generic type
382
2/4
✓ Branch 17 → 18 taken 2041 times.
✗ Branch 17 → 230 not taken.
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 27 taken 2041 times.
2041 if (!templateType.is(TY_GENERIC))
383 throw SemanticError(dataType, EXPECTED_GENERIC_TYPE, "A template list can only contain generic types");
384 // Convert generic symbol type to generic type
385
2/4
✓ Branch 27 → 28 taken 2041 times.
✗ Branch 27 → 230 not taken.
✓ Branch 28 → 29 taken 2041 times.
✗ Branch 28 → 230 not taken.
2041 GenericType *genericType = rootScope->lookupGenericTypeStrict(templateType.getSubType());
386
1/2
✗ Branch 29 → 30 not taken.
✓ Branch 29 → 31 taken 2041 times.
2041 assert(genericType != nullptr);
387
1/2
✓ Branch 31 → 32 taken 2041 times.
✗ Branch 31 → 230 not taken.
2041 usedTemplateTypes.push_back(*genericType);
388
1/2
✓ Branch 32 → 33 taken 2041 times.
✗ Branch 32 → 230 not taken.
2041 templateTypesGeneric.push_back(*genericType);
389 }
390 }
391
392 // Retrieve implemented interfaces
393 7457 QualTypeList interfaceTypes;
394
2/2
✓ Branch 46 → 47 taken 742 times.
✓ Branch 46 → 107 taken 6715 times.
7457 if (node->hasInterfaces) {
395
1/2
✓ Branch 48 → 49 taken 742 times.
✗ Branch 48 → 316 not taken.
742 interfaceTypes.reserve(node->interfaceTypeLst->dataTypes.size());
396
2/2
✓ Branch 105 → 51 taken 742 times.
✓ Branch 105 → 106 taken 740 times.
2224 for (DataTypeNode *interfaceNode : node->interfaceTypeLst->dataTypes) {
397 // Visit interface type
398
2/4
✓ Branch 53 → 54 taken 742 times.
✗ Branch 53 → 234 not taken.
✓ Branch 54 → 55 taken 742 times.
✗ Branch 54 → 232 not taken.
742 auto interfaceType = std::any_cast<QualType>(visit(interfaceNode));
399
2/4
✓ Branch 56 → 57 taken 742 times.
✗ Branch 56 → 256 not taken.
✗ Branch 57 → 58 not taken.
✓ Branch 57 → 59 taken 742 times.
742 if (interfaceType.is(TY_UNRESOLVED))
400 continue;
401 // Check if it is an interface type
402
2/4
✓ Branch 59 → 60 taken 742 times.
✗ Branch 59 → 256 not taken.
✗ Branch 60 → 61 not taken.
✓ Branch 60 → 68 taken 742 times.
742 if (!interfaceType.is(TY_INTERFACE))
403 throw SemanticError(interfaceNode, EXPECTED_INTERFACE_TYPE,
404 "Expected interface type, got " + interfaceType.getName(false));
405 // Check for visibility
406
9/12
✓ Branch 68 → 69 taken 742 times.
✗ Branch 68 → 256 not taken.
✓ Branch 69 → 70 taken 742 times.
✗ Branch 69 → 256 not taken.
✓ Branch 70 → 71 taken 664 times.
✓ Branch 70 → 74 taken 78 times.
✓ Branch 71 → 72 taken 664 times.
✗ Branch 71 → 256 not taken.
✓ Branch 72 → 73 taken 2 times.
✓ Branch 72 → 74 taken 662 times.
✓ Branch 75 → 76 taken 2 times.
✓ Branch 75 → 84 taken 740 times.
742 if (interfaceType.getBodyScope()->isImportedBy(rootScope) && !interfaceType.isPublic())
407 throw SemanticError(node, INSUFFICIENT_VISIBILITY,
408
4/8
✓ Branch 77 → 78 taken 2 times.
✗ Branch 77 → 249 not taken.
✓ Branch 78 → 79 taken 2 times.
✗ Branch 78 → 249 not taken.
✓ Branch 79 → 80 taken 2 times.
✗ Branch 79 → 247 not taken.
✓ Branch 80 → 81 taken 2 times.
✗ Branch 80 → 244 not taken.
2 "Cannot access interface '" + interfaceType.getSubType() + "' due to its private visibility");
409 // Add to interface types
410
1/2
✓ Branch 84 → 85 taken 740 times.
✗ Branch 84 → 256 not taken.
740 interfaceTypes.push_back(interfaceType);
411 // Update the type of the entry for that interface field
412 740 const std::string &interfaceName = interfaceNode->baseDataType->customDataType->typeNameFragments.back();
413
1/2
✓ Branch 86 → 87 taken 740 times.
✗ Branch 86 → 255 not taken.
1480 SymbolTableEntry *interfaceEntry = node->structScope->lookupStrict("this." + interfaceName);
414
1/2
✗ Branch 91 → 92 not taken.
✓ Branch 91 → 93 taken 740 times.
740 assert(interfaceEntry != nullptr);
415
1/2
✓ Branch 93 → 94 taken 740 times.
✗ Branch 93 → 256 not taken.
740 interfaceEntry->updateType(interfaceType, false);
416 }
417 }
418
419 // Update type of struct entry
420
1/2
✗ Branch 107 → 108 not taken.
✓ Branch 107 → 109 taken 7455 times.
7455 assert(node->entry != nullptr);
421 7455 const TypeChainElementData data = {.bodyScope = node->structScope};
422
1/2
✓ Branch 109 → 110 taken 7455 times.
✗ Branch 109 → 316 not taken.
7455 const Type *type = TypeRegistry::getOrInsert(TY_STRUCT, node->structName, node->typeId, data, usedTemplateTypes);
423 // If the entry was implicitly forward-declared because it is referenced across a circular import
424 // (assignDeferredOpaqueType), the existing type was already set to the opaque struct type. Overwriting it with the
425 // identical interned type is expected here.
426
2/4
✓ Branch 110 → 111 taken 7455 times.
✗ Branch 110 → 316 not taken.
✓ Branch 111 → 112 taken 7455 times.
✗ Branch 111 → 316 not taken.
7455 const bool overwrite = node->entry->getQualType().is(TY_STRUCT);
427
2/4
✓ Branch 112 → 113 taken 7455 times.
✗ Branch 112 → 258 not taken.
✓ Branch 113 → 114 taken 7455 times.
✗ Branch 113 → 258 not taken.
7455 node->entry->updateType(QualType(type, node->qualifiers), overwrite);
428
429 // Change to struct scope
430 7455 currentScope = node->structScope;
431
1/2
✗ Branch 114 → 115 not taken.
✓ Branch 114 → 116 taken 7455 times.
7455 assert(currentScope->type == ScopeType::STRUCT);
432
433 // Retrieve field types
434 7455 QualTypeList fieldTypes;
435
1/2
✓ Branch 117 → 118 taken 7455 times.
✗ Branch 117 → 314 not taken.
7455 fieldTypes.reserve(node->fields.size());
436 // Shared across all fields: the origin (node->structScope) is constant, so a struct already proven not to reach it
437 // via one field need not be re-walked for another.
438 7455 std::unordered_set<const Scope *> visitedScopes;
439
2/2
✓ Branch 165 → 121 taken 15025 times.
✓ Branch 165 → 166 taken 7445 times.
29925 for (FieldNode *field : node->fields) {
440 // Visit field type
441
2/4
✓ Branch 123 → 124 taken 15025 times.
✗ Branch 123 → 261 not taken.
✓ Branch 124 → 125 taken 15025 times.
✗ Branch 124 → 259 not taken.
15025 auto fieldType = std::any_cast<QualType>(visit(field));
442
3/4
✓ Branch 126 → 127 taken 15025 times.
✗ Branch 126 → 280 not taken.
✓ Branch 127 → 128 taken 4 times.
✓ Branch 127 → 129 taken 15021 times.
15025 if (fieldType.is(TY_UNRESOLVED))
443
1/2
✗ Branch 128 → 129 not taken.
✓ Branch 128 → 280 taken 4 times.
4 sourceFile->checkForSoftErrors(); // We get into trouble if we continue without the field type -> abort
444
445 // Check for struct with infinite size. This happens if a struct (transitively, through by-value struct fields)
446 // contains itself - either directly (struct A has a field of type A) or through a cycle of structs in mutually
447 // importing files (A has a field of type B and B has a field of type A).
448
3/4
✓ Branch 129 → 130 taken 15021 times.
✗ Branch 129 → 280 not taken.
✓ Branch 130 → 131 taken 4 times.
✓ Branch 130 → 139 taken 15017 times.
15021 if (fieldContainsAggregateByValue(fieldType, node->structScope, field, visitedScopes))
449
2/4
✓ Branch 134 → 135 taken 4 times.
✗ Branch 134 → 265 not taken.
✓ Branch 135 → 136 taken 4 times.
✗ Branch 135 → 262 not taken.
12 throw SemanticError(field, STRUCT_INFINITE_SIZE, "Struct with infinite size detected");
450
451 // Add to field types
452
1/2
✓ Branch 139 → 140 taken 15017 times.
✗ Branch 139 → 280 not taken.
15017 fieldTypes.push_back(fieldType);
453
454 // Update type of field entry
455
1/2
✓ Branch 140 → 141 taken 15017 times.
✗ Branch 140 → 280 not taken.
15017 SymbolTableEntry *fieldEntry = currentScope->lookupStrict(field->fieldName);
456
1/2
✗ Branch 143 → 144 not taken.
✓ Branch 143 → 145 taken 15017 times.
15017 assert(fieldEntry != nullptr);
457
1/2
✓ Branch 145 → 146 taken 15017 times.
✗ Branch 145 → 280 not taken.
15017 fieldEntry->updateType(fieldType, false);
458
459 // Check if the template type list contains this type
460
3/4
✓ Branch 146 → 147 taken 15017 times.
✗ Branch 146 → 280 not taken.
✓ Branch 147 → 148 taken 2 times.
✓ Branch 147 → 156 taken 15015 times.
15017 if (!fieldType.isCoveredByGenericTypeList(templateTypesGeneric))
461
2/4
✓ Branch 151 → 152 taken 2 times.
✗ Branch 151 → 274 not taken.
✓ Branch 152 → 153 taken 2 times.
✗ Branch 152 → 271 not taken.
6 throw SemanticError(field->dataType, GENERIC_TYPE_NOT_IN_TEMPLATE, "Generic field type not included in struct template");
462 }
463
464 // Change to the root scope
465 7445 currentScope = rootScope;
466
1/2
✗ Branch 166 → 167 not taken.
✓ Branch 166 → 168 taken 7445 times.
7445 assert(currentScope->type == ScopeType::GLOBAL);
467
468 // Build struct object
469
5/10
✓ Branch 168 → 169 taken 7445 times.
✗ Branch 168 → 293 not taken.
✓ Branch 169 → 170 taken 7445 times.
✗ Branch 169 → 290 not taken.
✓ Branch 170 → 171 taken 7445 times.
✗ Branch 170 → 287 not taken.
✓ Branch 171 → 172 taken 7445 times.
✗ Branch 171 → 284 not taken.
✓ Branch 172 → 173 taken 7445 times.
✗ Branch 172 → 282 not taken.
7445 Struct spiceStruct(node->structName, node->entry, node->structScope, fieldTypes, templateTypesGeneric, interfaceTypes, node);
470
1/2
✓ Branch 177 → 178 taken 7445 times.
✗ Branch 177 → 310 not taken.
7445 StructManager::insert(currentScope, spiceStruct, &node->structManifestations);
471 7445 spiceStruct.scope = node->structScope;
472
473 // Request RTTI runtime if the struct is polymorphic
474 7445 node->emitVTable |= node->hasInterfaces;
475
12/18
✓ Branch 178 → 179 taken 248 times.
✓ Branch 178 → 185 taken 7197 times.
✓ Branch 181 → 182 taken 248 times.
✗ Branch 181 → 294 not taken.
✓ Branch 182 → 183 taken 248 times.
✗ Branch 182 → 294 not taken.
✓ Branch 183 → 184 taken 246 times.
✓ Branch 183 → 185 taken 2 times.
✓ Branch 186 → 187 taken 248 times.
✓ Branch 186 → 188 taken 7197 times.
✓ Branch 188 → 189 taken 248 times.
✓ Branch 188 → 191 taken 7197 times.
✓ Branch 191 → 192 taken 246 times.
✓ Branch 191 → 199 taken 7199 times.
✗ Branch 294 → 295 not taken.
✗ Branch 294 → 296 not taken.
✗ Branch 298 → 299 not taken.
✗ Branch 298 → 301 not taken.
7941 if (node->attrs && node->attrs->attrLst->hasAttr(ATTR_CORE_COMPILER_EMIT_VTABLE))
476
2/4
✓ Branch 194 → 195 taken 246 times.
✗ Branch 194 → 305 not taken.
✓ Branch 195 → 196 taken 246 times.
✗ Branch 195 → 303 not taken.
738 node->emitVTable |= node->attrs->attrLst->getAttrValueByName(ATTR_CORE_COMPILER_EMIT_VTABLE)->boolValue;
477
7/8
✓ Branch 199 → 200 taken 986 times.
✓ Branch 199 → 205 taken 6459 times.
✓ Branch 200 → 201 taken 986 times.
✗ Branch 200 → 310 not taken.
✓ Branch 203 → 204 taken 742 times.
✓ Branch 203 → 205 taken 244 times.
✓ Branch 206 → 207 taken 742 times.
✓ Branch 206 → 208 taken 6703 times.
8431 if (node->emitVTable && !sourceFile->isRttiRT())
478
1/2
✓ Branch 207 → 208 taken 742 times.
✗ Branch 207 → 310 not taken.
742 sourceFile->requestRuntimeModule(RTTI_RT);
479
480
1/2
✓ Branch 208 → 209 taken 7445 times.
✗ Branch 208 → 309 not taken.
14890 return nullptr;
481 7501 }
482
483 801 std::any TypeChecker::visitInterfaceDefPrepare(InterfaceDefNode *node) {
484 801 QualTypeList usedTemplateTypes;
485 801 std::vector<GenericType> templateTypesGeneric;
486
487 // Retrieve interface template types
488
2/2
✓ Branch 2 → 3 taken 378 times.
✓ Branch 2 → 47 taken 423 times.
801 if (node->hasTemplateTypes) {
489
1/2
✓ Branch 4 → 5 taken 378 times.
✗ Branch 4 → 178 not taken.
378 usedTemplateTypes.reserve(node->templateTypeLst->dataTypes.size());
490
1/2
✓ Branch 6 → 7 taken 378 times.
✗ Branch 6 → 178 not taken.
378 templateTypesGeneric.reserve(node->templateTypeLst->dataTypes.size());
491
2/2
✓ Branch 45 → 9 taken 378 times.
✓ Branch 45 → 46 taken 378 times.
1134 for (DataTypeNode *dataType : node->templateTypeLst->dataTypes) {
492 // Visit template type
493
2/4
✓ Branch 11 → 12 taken 378 times.
✗ Branch 11 → 144 not taken.
✓ Branch 12 → 13 taken 378 times.
✗ Branch 12 → 142 not taken.
378 auto templateType = std::any_cast<QualType>(visit(dataType));
494
2/6
✓ Branch 14 → 15 taken 378 times.
✗ Branch 14 → 152 not taken.
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 19 taken 378 times.
✗ Branch 16 → 17 not taken.
✗ Branch 16 → 145 not taken.
378 HANDLE_UNRESOLVED_TYPE_PTR(templateType)
495 // Check if it is a generic type
496
2/4
✓ Branch 19 → 20 taken 378 times.
✗ Branch 19 → 152 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 28 taken 378 times.
378 if (!templateType.is(TY_GENERIC)) {
497 softError(dataType, EXPECTED_GENERIC_TYPE, "A template list can only contain generic types");
498 continue;
499 }
500 // Convert generic symbol type to generic type
501
2/4
✓ Branch 28 → 29 taken 378 times.
✗ Branch 28 → 152 not taken.
✓ Branch 29 → 30 taken 378 times.
✗ Branch 29 → 152 not taken.
378 const GenericType *genericType = rootScope->lookupGenericTypeStrict(templateType.getSubType());
502
1/2
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 32 taken 378 times.
378 assert(genericType != nullptr);
503
1/2
✓ Branch 32 → 33 taken 378 times.
✗ Branch 32 → 152 not taken.
378 usedTemplateTypes.push_back(*genericType);
504
1/2
✓ Branch 33 → 34 taken 378 times.
✗ Branch 33 → 152 not taken.
378 templateTypesGeneric.push_back(*genericType);
505 }
506 }
507
508 // Update type of interface entry
509 801 const TypeChainElementData data = {.bodyScope = node->interfaceScope};
510
1/2
✓ Branch 47 → 48 taken 801 times.
✗ Branch 47 → 178 not taken.
801 const Type *type = TypeRegistry::getOrInsert(TY_INTERFACE, node->interfaceName, node->typeId, data, usedTemplateTypes);
511
1/2
✓ Branch 48 → 49 taken 801 times.
✗ Branch 48 → 178 not taken.
801 const QualType interfaceType(type, node->qualifiers);
512
1/2
✗ Branch 49 → 50 not taken.
✓ Branch 49 → 51 taken 801 times.
801 assert(node->entry != nullptr);
513 // If the entry was implicitly forward-declared because it is referenced across a circular import
514 // (assignDeferredOpaqueType), the existing type was already set to the opaque interface type. Overwriting it with the
515 // identical interned type is expected here.
516
2/4
✓ Branch 51 → 52 taken 801 times.
✗ Branch 51 → 178 not taken.
✓ Branch 52 → 53 taken 801 times.
✗ Branch 52 → 178 not taken.
801 const bool overwrite = node->entry->getQualType().is(TY_INTERFACE);
517
1/2
✓ Branch 53 → 54 taken 801 times.
✗ Branch 53 → 178 not taken.
801 node->entry->updateType(interfaceType, overwrite);
518
519 // Change to interface scope
520 801 currentScope = node->interfaceScope;
521
1/2
✗ Branch 54 → 55 not taken.
✓ Branch 54 → 56 taken 801 times.
801 assert(currentScope->type == ScopeType::INTERFACE);
522
523 // Visit methods
524 801 size_t vtableIndex = 0;
525 801 std::vector<Function *> methods;
526
1/2
✓ Branch 57 → 58 taken 801 times.
✗ Branch 57 → 176 not taken.
801 methods.reserve(node->signatures.size());
527
2/2
✓ Branch 118 → 60 taken 4865 times.
✓ Branch 118 → 119 taken 799 times.
6465 for (SignatureNode *signature : node->signatures) {
528
2/4
✓ Branch 62 → 63 taken 4865 times.
✗ Branch 62 → 156 not taken.
✓ Branch 63 → 64 taken 4865 times.
✗ Branch 63 → 154 not taken.
4865 const auto method = std::any_cast<std::vector<Function *> *>(visit(signature));
529
2/2
✓ Branch 65 → 66 taken 2 times.
✓ Branch 65 → 69 taken 4863 times.
4865 if (!method)
530
1/2
✓ Branch 66 → 67 taken 2 times.
✗ Branch 66 → 157 not taken.
4 return nullptr;
531
532 // Set 'this' type
533
2/2
✓ Branch 101 → 71 taken 4863 times.
✓ Branch 101 → 102 taken 4863 times.
14589 for (Function *m : *method) {
534 4863 m->isVirtual = true; // Interface methods are always virtual
535 4863 m->vtableIndex = vtableIndex;
536 4863 m->thisType = interfaceType;
537
538 // Merge the enclosing interface's own template types into the method's template types, mirroring how struct
539 // methods inherit the struct's generic params in visitFctDefPrepare. Without this, a method that does not
540 // redeclare its own template list (e.g. isValid() inside IIterator<T>) ends up with an empty templateTypes
541 // list, even though its thisType references the interface's generic type - so generic type resolution fails
542 // while matching the 'this' type of a call through an interface reference.
543
3/4
✓ Branch 73 → 74 taken 4863 times.
✗ Branch 73 → 159 not taken.
✓ Branch 91 → 76 taken 968 times.
✓ Branch 91 → 92 taken 4863 times.
10694 for (const QualType &templateType : interfaceType.getTemplateTypes()) {
544 570 const auto lambda = [&](const GenericType &genericType) { return genericType == templateType; };
545
3/4
✓ Branch 78 → 79 taken 968 times.
✗ Branch 78 → 158 not taken.
✓ Branch 79 → 80 taken 398 times.
✓ Branch 79 → 81 taken 570 times.
968 if (std::ranges::none_of(m->templateTypes, lambda))
546
1/2
✓ Branch 80 → 81 taken 398 times.
✗ Branch 80 → 158 not taken.
398 m->templateTypes.emplace_back(templateType);
547 968 m->templateTypes.back().used = true;
548 }
549 }
550
551
1/2
✓ Branch 108 → 109 taken 4863 times.
✗ Branch 108 → 161 not taken.
9726 methods.insert(methods.end(), method->begin(), method->end());
552 4863 vtableIndex++;
553 }
554
555 // Change to root scope
556 799 currentScope = rootScope;
557
1/2
✗ Branch 119 → 120 not taken.
✓ Branch 119 → 121 taken 799 times.
799 assert(currentScope->type == ScopeType::GLOBAL);
558
559 // Build interface object
560
4/8
✓ Branch 121 → 122 taken 799 times.
✗ Branch 121 → 172 not taken.
✓ Branch 122 → 123 taken 799 times.
✗ Branch 122 → 169 not taken.
✓ Branch 123 → 124 taken 799 times.
✗ Branch 123 → 166 not taken.
✓ Branch 124 → 125 taken 799 times.
✗ Branch 124 → 164 not taken.
799 Interface spiceInterface(node->interfaceName, node->entry, node->interfaceScope, methods, templateTypesGeneric, node);
561
1/2
✓ Branch 128 → 129 taken 799 times.
✗ Branch 128 → 174 not taken.
799 InterfaceManager::insert(currentScope, spiceInterface, &node->interfaceManifestations);
562 799 spiceInterface.scope = node->interfaceScope;
563
564 // Request RTTI runtime, that is always required when dealing with interfaces due to polymorphism
565
2/4
✓ Branch 129 → 130 taken 799 times.
✗ Branch 129 → 174 not taken.
✓ Branch 132 → 133 taken 799 times.
✗ Branch 132 → 134 not taken.
1598 if (!sourceFile->isRttiRT())
566
1/2
✓ Branch 133 → 134 taken 799 times.
✗ Branch 133 → 174 not taken.
799 sourceFile->requestRuntimeModule(RTTI_RT);
567
568
1/2
✓ Branch 134 → 135 taken 799 times.
✗ Branch 134 → 173 not taken.
799 return nullptr;
569 801 }
570
571 64 std::any TypeChecker::visitUnionDefPrepare(UnionDefNode *node) {
572 64 QualTypeList usedTemplateTypes;
573 64 std::vector<GenericType> templateTypesGeneric;
574
575 // Retrieve union template types
576
2/2
✓ Branch 2 → 3 taken 4 times.
✓ Branch 2 → 46 taken 60 times.
64 if (node->hasTemplateTypes) {
577
1/2
✓ Branch 4 → 5 taken 4 times.
✗ Branch 4 → 222 not taken.
4 usedTemplateTypes.reserve(node->templateTypeLst->dataTypes.size());
578
1/2
✓ Branch 6 → 7 taken 4 times.
✗ Branch 6 → 222 not taken.
4 templateTypesGeneric.reserve(node->templateTypeLst->dataTypes.size());
579
2/2
✓ Branch 44 → 9 taken 4 times.
✓ Branch 44 → 45 taken 4 times.
12 for (DataTypeNode *dataType : node->templateTypeLst->dataTypes) {
580 // Visit template type
581
2/4
✓ Branch 11 → 12 taken 4 times.
✗ Branch 11 → 153 not taken.
✓ Branch 12 → 13 taken 4 times.
✗ Branch 12 → 151 not taken.
4 auto templateType = std::any_cast<QualType>(visit(dataType));
582
2/4
✓ Branch 14 → 15 taken 4 times.
✗ Branch 14 → 163 not taken.
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 4 times.
4 if (templateType.is(TY_UNRESOLVED))
583 continue;
584 // Check if it is a generic type
585
2/4
✓ Branch 17 → 18 taken 4 times.
✗ Branch 17 → 163 not taken.
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 27 taken 4 times.
4 if (!templateType.is(TY_GENERIC))
586 throw SemanticError(dataType, EXPECTED_GENERIC_TYPE, "A template list can only contain generic types");
587 // Convert generic symbol type to generic type
588
2/4
✓ Branch 27 → 28 taken 4 times.
✗ Branch 27 → 163 not taken.
✓ Branch 28 → 29 taken 4 times.
✗ Branch 28 → 163 not taken.
4 GenericType *genericType = rootScope->lookupGenericTypeStrict(templateType.getSubType());
589
1/2
✗ Branch 29 → 30 not taken.
✓ Branch 29 → 31 taken 4 times.
4 assert(genericType != nullptr);
590
1/2
✓ Branch 31 → 32 taken 4 times.
✗ Branch 31 → 163 not taken.
4 usedTemplateTypes.push_back(*genericType);
591
1/2
✓ Branch 32 → 33 taken 4 times.
✗ Branch 32 → 163 not taken.
4 templateTypesGeneric.push_back(*genericType);
592 }
593 }
594
595 // Update type of union entry
596
1/2
✗ Branch 46 → 47 not taken.
✓ Branch 46 → 48 taken 64 times.
64 assert(node->entry != nullptr);
597 64 const TypeChainElementData data = {.bodyScope = node->unionScope};
598
1/2
✓ Branch 48 → 49 taken 64 times.
✗ Branch 48 → 222 not taken.
64 const Type *type = TypeRegistry::getOrInsert(TY_UNION, node->unionName, node->typeId, data, usedTemplateTypes);
599 // If the entry was implicitly forward-declared because it is referenced across a circular import
600 // (assignDeferredOpaqueType), the existing type was already set to the opaque union type. Overwriting it with the
601 // identical interned type is expected here.
602
2/4
✓ Branch 49 → 50 taken 64 times.
✗ Branch 49 → 222 not taken.
✓ Branch 50 → 51 taken 64 times.
✗ Branch 50 → 222 not taken.
64 const bool overwrite = node->entry->getQualType().is(TY_UNION);
603
2/4
✓ Branch 51 → 52 taken 64 times.
✗ Branch 51 → 165 not taken.
✓ Branch 52 → 53 taken 64 times.
✗ Branch 52 → 165 not taken.
64 node->entry->updateType(QualType(type, node->qualifiers), overwrite);
604
605 // Change to union scope
606 64 currentScope = node->unionScope;
607
1/2
✗ Branch 53 → 54 not taken.
✓ Branch 53 → 55 taken 64 times.
64 assert(currentScope->type == ScopeType::UNION);
608
609 // Retrieve field types
610 64 QualTypeList fieldTypes;
611
1/2
✓ Branch 56 → 57 taken 64 times.
✗ Branch 56 → 220 not taken.
64 fieldTypes.reserve(node->fields.size());
612 // Shared across all fields: the origin (node->unionScope) is constant, so an aggregate already proven not to reach
613 // it via one field need not be re-walked for another.
614 64 std::unordered_set<const Scope *> visitedScopes;
615 64 size_t defaultFieldIndex = SIZE_MAX;
616
2/2
✓ Branch 131 → 59 taken 308 times.
✓ Branch 131 → 132 taken 60 times.
368 for (size_t i = 0; i < node->fields.size(); i++) {
617
1/2
✓ Branch 59 → 60 taken 308 times.
✗ Branch 59 → 205 not taken.
308 FieldNode *field = node->fields.at(i);
618
619 // Visit field type
620
2/4
✓ Branch 60 → 61 taken 308 times.
✗ Branch 60 → 168 not taken.
✓ Branch 61 → 62 taken 308 times.
✗ Branch 61 → 166 not taken.
308 auto fieldType = std::any_cast<QualType>(visit(field));
621
2/4
✓ Branch 63 → 64 taken 308 times.
✗ Branch 63 → 205 not taken.
✗ Branch 64 → 65 not taken.
✓ Branch 64 → 66 taken 308 times.
308 if (fieldType.is(TY_UNRESOLVED))
622 sourceFile->checkForSoftErrors(); // We get into trouble if we continue without the field type -> abort
623
624 // Check for union/struct with infinite size. This happens if the union (transitively, through by-value
625 // struct/union fields) contains itself - either directly or through a cycle of aggregates in mutually
626 // importing files.
627
3/4
✓ Branch 66 → 67 taken 308 times.
✗ Branch 66 → 205 not taken.
✓ Branch 67 → 68 taken 4 times.
✓ Branch 67 → 76 taken 304 times.
308 if (fieldContainsAggregateByValue(fieldType, node->unionScope, field, visitedScopes))
628
2/4
✓ Branch 71 → 72 taken 4 times.
✗ Branch 71 → 172 not taken.
✓ Branch 72 → 73 taken 4 times.
✗ Branch 72 → 169 not taken.
12 throw SemanticError(field, UNION_INFINITE_SIZE, "Union with infinite size detected");
629
630 // Union fields must not be references
631
3/4
✓ Branch 76 → 77 taken 304 times.
✗ Branch 76 → 205 not taken.
✓ Branch 77 → 78 taken 2 times.
✓ Branch 77 → 85 taken 302 times.
304 if (fieldType.isRef())
632
2/4
✓ Branch 80 → 81 taken 2 times.
✗ Branch 80 → 180 not taken.
✓ Branch 81 → 82 taken 2 times.
✗ Branch 81 → 178 not taken.
4 softError(field, UNION_FIELD_MUST_NOT_BE_REFERENCE, "A union field must not be a reference");
633
634 // Union fields must be trivially constructible, copyable and destructible, since the union does not know which
635 // field is currently active and therefore cannot run any non-trivial special member on its own.
636
5/6
✓ Branch 85 → 86 taken 304 times.
✗ Branch 85 → 205 not taken.
✓ Branch 86 → 87 taken 302 times.
✓ Branch 86 → 94 taken 2 times.
✓ Branch 95 → 96 taken 2 times.
✓ Branch 95 → 102 taken 302 times.
606 if (!fieldType.isRef() &&
637
7/12
✓ Branch 87 → 88 taken 302 times.
✗ Branch 87 → 205 not taken.
✓ Branch 88 → 89 taken 300 times.
✓ Branch 88 → 93 taken 2 times.
✓ Branch 89 → 90 taken 300 times.
✗ Branch 89 → 205 not taken.
✓ Branch 90 → 91 taken 300 times.
✗ Branch 90 → 93 not taken.
✓ Branch 91 → 92 taken 300 times.
✗ Branch 91 → 205 not taken.
✗ Branch 92 → 93 not taken.
✓ Branch 92 → 94 taken 300 times.
302 (!fieldType.isTriviallyConstructible(field) || !fieldType.isTriviallyCopyable(field) || !fieldType.isTriviallyDestructible(field)))
638
1/2
✓ Branch 98 → 99 taken 2 times.
✗ Branch 98 → 184 not taken.
2 softError(field, UNION_FIELD_TYPE_NOT_TRIVIAL,
639
2/4
✓ Branch 96 → 97 taken 2 times.
✗ Branch 96 → 188 not taken.
✓ Branch 97 → 98 taken 2 times.
✗ Branch 97 → 186 not taken.
4 "The type of the union field '" + field->fieldName + "' is not trivial. Only trivial types are allowed as union fields");
640
641 // At most one field may carry a default value
642
2/2
✓ Branch 102 → 103 taken 8 times.
✓ Branch 102 → 112 taken 296 times.
304 if (field->defaultValue != nullptr) {
643
2/2
✓ Branch 103 → 104 taken 2 times.
✓ Branch 103 → 111 taken 6 times.
8 if (defaultFieldIndex != SIZE_MAX)
644
2/4
✓ Branch 106 → 107 taken 2 times.
✗ Branch 106 → 192 not taken.
✓ Branch 107 → 108 taken 2 times.
✗ Branch 107 → 190 not taken.
4 softError(field, DUPLICATE_UNION_DEFAULT_VALUE, "A union may only have one field with a default value");
645 else
646 6 defaultFieldIndex = i;
647 }
648
649 // Add to field types
650
1/2
✓ Branch 112 → 113 taken 304 times.
✗ Branch 112 → 205 not taken.
304 fieldTypes.push_back(fieldType);
651
652 // Update type of field entry
653
1/2
✓ Branch 113 → 114 taken 304 times.
✗ Branch 113 → 205 not taken.
304 SymbolTableEntry *fieldEntry = currentScope->lookupStrict(field->fieldName);
654
1/2
✗ Branch 116 → 117 not taken.
✓ Branch 116 → 118 taken 304 times.
304 assert(fieldEntry != nullptr);
655
1/2
✓ Branch 118 → 119 taken 304 times.
✗ Branch 118 → 205 not taken.
304 fieldEntry->updateType(fieldType, false);
656
657 // Check if the template type list contains this type
658
2/4
✓ Branch 119 → 120 taken 304 times.
✗ Branch 119 → 205 not taken.
✗ Branch 120 → 121 not taken.
✓ Branch 120 → 129 taken 304 times.
304 if (!fieldType.isCoveredByGenericTypeList(templateTypesGeneric))
659 throw SemanticError(field->dataType, GENERIC_TYPE_NOT_IN_TEMPLATE, "Generic field type not included in union template");
660 }
661
662 // Change to the root scope
663 60 currentScope = rootScope;
664
1/2
✗ Branch 132 → 133 not taken.
✓ Branch 132 → 134 taken 60 times.
60 assert(currentScope->type == ScopeType::GLOBAL);
665
666 // Build union object
667
4/8
✓ Branch 134 → 135 taken 60 times.
✗ Branch 134 → 214 not taken.
✓ Branch 135 → 136 taken 60 times.
✗ Branch 135 → 211 not taken.
✓ Branch 136 → 137 taken 60 times.
✗ Branch 136 → 208 not taken.
✓ Branch 137 → 138 taken 60 times.
✗ Branch 137 → 206 not taken.
60 Union spiceUnion(node->unionName, node->entry, node->unionScope, fieldTypes, templateTypesGeneric, node);
668 60 spiceUnion.defaultFieldIndex = defaultFieldIndex;
669
1/2
✓ Branch 141 → 142 taken 60 times.
✗ Branch 141 → 216 not taken.
60 UnionManager::insert(currentScope, spiceUnion, &node->unionManifestations);
670
671
1/2
✓ Branch 142 → 143 taken 60 times.
✗ Branch 142 → 215 not taken.
120 return nullptr;
672 76 }
673
674 1226 std::any TypeChecker::visitEnumDefPrepare(EnumDefNode *node) {
675 // Update type of enum entry
676 1226 const TypeChainElementData data = {.bodyScope = node->enumScope};
677
1/2
✓ Branch 3 → 4 taken 1226 times.
✗ Branch 3 → 88 not taken.
1226 const Type *type = TypeRegistry::getOrInsert(TY_ENUM, node->enumName, node->typeId, data, {});
678
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 1226 times.
1226 assert(node->entry != nullptr);
679 // The enum may already carry its opaque type if it was referenced across a circular import before being prepared
680 // (assignDeferredOpaqueType). Overwriting it with the identical interned type is expected here.
681
2/4
✓ Branch 7 → 8 taken 1226 times.
✗ Branch 7 → 109 not taken.
✓ Branch 8 → 9 taken 1226 times.
✗ Branch 8 → 109 not taken.
1226 const bool overwrite = node->entry->getQualType().is(TY_ENUM);
682
2/4
✓ Branch 9 → 10 taken 1226 times.
✗ Branch 9 → 91 not taken.
✓ Branch 10 → 11 taken 1226 times.
✗ Branch 10 → 91 not taken.
1226 node->entry->updateType(QualType(type, node->qualifiers), overwrite);
683
684 // Change to enum scope
685 1226 currentScope = node->enumScope;
686
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 1226 times.
1226 assert(currentScope->type == ScopeType::ENUM);
687
688 // Loop through all items with values
689 1226 std::vector<std::string> names;
690 1226 std::vector<uint32_t> values;
691
2/2
✓ Branch 45 → 15 taken 11036 times.
✓ Branch 45 → 46 taken 1226 times.
13488 for (const EnumItemNode *enumItem : node->itemLst->items) {
692 // Save name
693
1/2
✓ Branch 17 → 18 taken 11036 times.
✗ Branch 17 → 100 not taken.
11036 names.push_back(enumItem->itemName);
694 // Check for duplicate value
695
2/2
✓ Branch 18 → 19 taken 6274 times.
✓ Branch 18 → 36 taken 4762 times.
11036 if (enumItem->hasValue) {
696
3/4
✓ Branch 20 → 21 taken 6274 times.
✗ Branch 20 → 92 not taken.
✓ Branch 27 → 28 taken 2 times.
✓ Branch 27 → 35 taken 6272 times.
12548 if (std::ranges::find(values, enumItem->itemValue) != values.end()) {
697
2/4
✓ Branch 30 → 31 taken 2 times.
✗ Branch 30 → 96 not taken.
✓ Branch 31 → 32 taken 2 times.
✗ Branch 31 → 94 not taken.
2 softError(enumItem, DUPLICATE_ENUM_ITEM_VALUE, "Duplicate enum item value, please use another");
698 2 continue;
699 }
700
1/2
✓ Branch 35 → 36 taken 6272 times.
✗ Branch 35 → 100 not taken.
6272 values.push_back(enumItem->itemValue);
701 }
702 }
703
704 // Loop through all items without values
705 1226 uint32_t nextValue = 0;
706
1/2
✓ Branch 46 → 47 taken 1226 times.
✗ Branch 46 → 105 not taken.
1226 const QualType intSymbolType(TY_INT);
707
2/2
✓ Branch 79 → 49 taken 11036 times.
✓ Branch 79 → 80 taken 1226 times.
13488 for (EnumItemNode *enumItem : node->itemLst->items) {
708 // Update type of enum item entry
709
1/2
✓ Branch 51 → 52 taken 11036 times.
✗ Branch 51 → 103 not taken.
11036 SymbolTableEntry *itemEntry = currentScope->lookupStrict(enumItem->itemName);
710
1/2
✗ Branch 54 → 55 not taken.
✓ Branch 54 → 56 taken 11036 times.
11036 assert(itemEntry != nullptr);
711
1/2
✓ Branch 56 → 57 taken 11036 times.
✗ Branch 56 → 103 not taken.
11036 itemEntry->updateType(intSymbolType, false);
712 // Fill in value if not filled yet
713
2/2
✓ Branch 57 → 58 taken 4762 times.
✓ Branch 57 → 70 taken 6274 times.
11036 if (!enumItem->hasValue) {
714
3/4
✓ Branch 61 → 62 taken 9053 times.
✗ Branch 61 → 101 not taken.
✓ Branch 68 → 59 taken 4291 times.
✓ Branch 68 → 69 taken 4762 times.
18106 while (std::ranges::find(values, nextValue) != values.end())
715 4291 nextValue++;
716 4762 enumItem->itemValue = nextValue;
717
1/2
✓ Branch 69 → 70 taken 4762 times.
✗ Branch 69 → 103 not taken.
4762 values.push_back(nextValue);
718 }
719 }
720
721 // Change to root scope
722 1226 currentScope = rootScope;
723
1/2
✗ Branch 80 → 81 not taken.
✓ Branch 80 → 82 taken 1226 times.
1226 assert(currentScope->type == ScopeType::GLOBAL);
724
725
1/2
✓ Branch 82 → 83 taken 1226 times.
✗ Branch 82 → 104 not taken.
2452 return nullptr;
726 1226 }
727
728 4497 std::any TypeChecker::visitGenericTypeDefPrepare(GenericTypeDefNode *node) {
729 // Retrieve type conditions
730 4497 QualTypeList typeConditions;
731
1/2
✓ Branch 3 → 4 taken 4497 times.
✗ Branch 3 → 70 not taken.
4497 typeConditions.reserve(node->typeAltsLst->dataTypes.size());
732
2/2
✓ Branch 26 → 6 taken 7935 times.
✓ Branch 26 → 27 taken 4497 times.
16929 for (const auto &typeAlt : node->typeAltsLst->dataTypes) {
733
2/4
✓ Branch 8 → 9 taken 7935 times.
✗ Branch 8 → 58 not taken.
✓ Branch 9 → 10 taken 7935 times.
✗ Branch 9 → 56 not taken.
7935 auto typeCondition = std::any_cast<QualType>(visit(typeAlt));
734
2/6
✓ Branch 11 → 12 taken 7935 times.
✗ Branch 11 → 60 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 16 taken 7935 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 59 not taken.
7935 HANDLE_UNRESOLVED_TYPE_PTR(typeCondition)
735
1/2
✓ Branch 16 → 17 taken 7935 times.
✗ Branch 16 → 60 not taken.
7935 typeConditions.push_back(typeCondition);
736 }
737
738 // Add generic type to the scope
739
2/4
✓ Branch 27 → 28 taken 4497 times.
✗ Branch 27 → 64 not taken.
✓ Branch 28 → 29 taken 4497 times.
✗ Branch 28 → 62 not taken.
4497 const GenericType genericType(node->typeName, typeConditions);
740
1/2
✓ Branch 30 → 31 taken 4497 times.
✗ Branch 30 → 68 not taken.
4497 rootScope->insertGenericType(node->typeName, genericType);
741
742 // Check if only one type condition is set
743
7/8
✓ Branch 32 → 33 taken 2114 times.
✓ Branch 32 → 37 taken 2383 times.
✓ Branch 34 → 35 taken 2114 times.
✗ Branch 34 → 68 not taken.
✓ Branch 35 → 36 taken 2 times.
✓ Branch 35 → 37 taken 2112 times.
✓ Branch 38 → 39 taken 2 times.
✓ Branch 38 → 41 taken 4495 times.
4497 if (typeConditions.size() == 1 && !typeConditions.front().is(TY_DYN))
744
1/2
✓ Branch 39 → 40 taken 2 times.
✗ Branch 39 → 65 not taken.
2 sourceFile->compilerOutput.warnings.emplace_back(node->typeAltsLst->codeLoc, SINGLE_GENERIC_TYPE_CONDITION,
745 "Generic type is locked to one type");
746
747 // Check if the list contains the dyn type, along with other types
748
1/2
✓ Branch 41 → 42 taken 4497 times.
✗ Branch 41 → 68 not taken.
12428 const bool containsDynType = std::ranges::any_of(typeConditions, [&](const QualType &type) { return type.is(TY_DYN); });
749
6/6
✓ Branch 42 → 43 taken 2116 times.
✓ Branch 42 → 46 taken 2381 times.
✓ Branch 44 → 45 taken 4 times.
✓ Branch 44 → 46 taken 2112 times.
✓ Branch 47 → 48 taken 4 times.
✓ Branch 47 → 50 taken 4493 times.
4497 if (containsDynType && typeConditions.size() > 1)
750 4 sourceFile->compilerOutput.warnings.emplace_back(
751
1/2
✓ Branch 48 → 49 taken 4 times.
✗ Branch 48 → 66 not taken.
4 node->typeAltsLst->codeLoc, INEFFECTIVE_GENERIC_TYPE_CONDITION,
752 "One or several type conditions are superfluous, because the dyn type condition is given");
753
754
1/2
✓ Branch 50 → 51 taken 4497 times.
✗ Branch 50 → 67 not taken.
4497 return nullptr;
755 4497 }
756
757 705 std::any TypeChecker::visitAliasDefPrepare(AliasDefNode *node) {
758
2/4
✓ Branch 2 → 3 taken 705 times.
✗ Branch 2 → 5 not taken.
✓ Branch 3 → 4 taken 705 times.
✗ Branch 3 → 5 not taken.
705 assert(node->entry != nullptr && node->aliasedTypeContainerEntry != nullptr);
759
760 // The alias may already have been prepared on demand because it was referenced across a circular import
761 // (assignDeferredOpaqueType). In that case there is nothing left to do.
762
4/6
✓ Branch 6 → 7 taken 705 times.
✗ Branch 6 → 43 not taken.
✓ Branch 7 → 8 taken 705 times.
✗ Branch 7 → 43 not taken.
✓ Branch 8 → 9 taken 2 times.
✓ Branch 8 → 12 taken 703 times.
705 if (node->entry->getQualType().is(TY_ALIAS))
763
1/2
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 32 not taken.
4 return nullptr;
764
765 // Ensure the aliased-type subtree is sized for manifestations before it is visited below. On the normal path
766 // visitEntry already sized the whole file to 1, so this is a no-op; on the on-demand path (a cross-import reference
767 // reaching this alias before its own file's visitEntry ran) it establishes the precondition setEvaluatedSymbolType
768 // requires.
769
1/2
✓ Branch 12 → 13 taken 703 times.
✗ Branch 12 → 43 not taken.
703 node->dataType->resizeToNumberOfManifestations(1);
770
771 // Update type of alias entry
772
1/2
✓ Branch 14 → 15 taken 703 times.
✗ Branch 14 → 33 not taken.
703 const Type *type = TypeRegistry::getOrInsert(TY_ALIAS, node->aliasName, node->typeId, {}, {});
773
2/4
✓ Branch 16 → 17 taken 703 times.
✗ Branch 16 → 37 not taken.
✓ Branch 17 → 18 taken 703 times.
✗ Branch 17 → 37 not taken.
703 node->entry->updateType(QualType(type, node->qualifiers), false);
774
775 // Update type of the aliased type container entry
776
2/4
✓ Branch 18 → 19 taken 703 times.
✗ Branch 18 → 40 not taken.
✓ Branch 19 → 20 taken 703 times.
✗ Branch 19 → 38 not taken.
703 const auto aliasedType = std::any_cast<QualType>(visit(node->dataType));
777
4/6
✓ Branch 21 → 22 taken 703 times.
✗ Branch 21 → 43 not taken.
✓ Branch 22 → 23 taken 2 times.
✓ Branch 22 → 26 taken 701 times.
✓ Branch 23 → 24 taken 2 times.
✗ Branch 23 → 41 not taken.
705 HANDLE_UNRESOLVED_TYPE_PTR(aliasedType)
778
1/2
✓ Branch 26 → 27 taken 701 times.
✗ Branch 26 → 43 not taken.
701 node->aliasedTypeContainerEntry->updateType(aliasedType, false);
779 701 node->aliasedTypeContainerEntry->used = true; // The container type is always used per default
780
781
1/2
✓ Branch 27 → 28 taken 701 times.
✗ Branch 27 → 42 not taken.
1402 return nullptr;
782 }
783
784 5937 std::any TypeChecker::visitGlobalVarDefPrepare(GlobalVarDefNode *node) {
785 // Insert variable name to symbol table
786
2/4
✓ Branch 2 → 3 taken 5937 times.
✗ Branch 2 → 87 not taken.
✓ Branch 3 → 4 taken 5937 times.
✗ Branch 3 → 85 not taken.
5937 auto globalVarType = std::any_cast<QualType>(visit(node->dataType));
787
2/6
✓ Branch 5 → 6 taken 5937 times.
✗ Branch 5 → 133 not taken.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 10 taken 5937 times.
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 88 not taken.
5937 HANDLE_UNRESOLVED_TYPE_PTR(globalVarType)
788
789
2/2
✓ Branch 10 → 11 taken 5933 times.
✓ Branch 10 → 40 taken 4 times.
5937 if (node->constant) { // Variable is initialized here
790
2/4
✓ Branch 11 → 12 taken 5933 times.
✗ Branch 11 → 91 not taken.
✓ Branch 12 → 13 taken 5933 times.
✗ Branch 12 → 89 not taken.
5933 const QualType rhsType = std::any_cast<ExprResult>(visit(node->constant)).type;
791
2/6
✓ Branch 14 → 15 taken 5933 times.
✗ Branch 14 → 110 not taken.
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 19 taken 5933 times.
✗ Branch 16 → 17 not taken.
✗ Branch 16 → 93 not taken.
5933 HANDLE_UNRESOLVED_TYPE_PTR(rhsType)
792
3/4
✓ Branch 19 → 20 taken 5933 times.
✗ Branch 19 → 110 not taken.
✓ Branch 20 → 21 taken 2 times.
✓ Branch 20 → 22 taken 5931 times.
5933 if (globalVarType.is(TY_DYN)) { // Perform type inference
793 2 globalVarType = rhsType;
794
3/4
✓ Branch 22 → 23 taken 5931 times.
✗ Branch 22 → 110 not taken.
✓ Branch 23 → 24 taken 4 times.
✓ Branch 23 → 38 taken 5927 times.
5931 } else if (!globalVarType.matches(rhsType, false, true, true)) { // Check if types are matching
795
7/14
✓ Branch 24 → 25 taken 4 times.
✗ Branch 24 → 107 not taken.
✓ Branch 25 → 26 taken 4 times.
✗ Branch 25 → 102 not taken.
✓ Branch 26 → 27 taken 4 times.
✗ Branch 26 → 100 not taken.
✓ Branch 27 → 28 taken 4 times.
✗ Branch 27 → 98 not taken.
✓ Branch 28 → 29 taken 4 times.
✗ Branch 28 → 96 not taken.
✓ Branch 29 → 30 taken 4 times.
✗ Branch 29 → 94 not taken.
✓ Branch 35 → 36 taken 4 times.
✗ Branch 35 → 109 not taken.
8 SOFT_ERROR_BOOL(node->constant, OPERATOR_WRONG_DATA_TYPE,
796 "Expected " + globalVarType.getName(false) + ", but got " + rhsType.getName(false))
797 }
798 }
799
800 // Check if the type is still missing
801
3/4
✓ Branch 40 → 41 taken 5933 times.
✗ Branch 40 → 133 not taken.
✓ Branch 41 → 42 taken 2 times.
✓ Branch 41 → 51 taken 5931 times.
5933 if (globalVarType.is(TY_DYN))
802
3/6
✓ Branch 44 → 45 taken 2 times.
✗ Branch 44 → 113 not taken.
✓ Branch 45 → 46 taken 2 times.
✗ Branch 45 → 111 not taken.
✓ Branch 48 → 49 taken 2 times.
✗ Branch 48 → 117 not taken.
8 SOFT_ERROR_BOOL(node->dataType, GLOBAL_OF_TYPE_DYN, "Global variables must have an explicit data type")
803
804 // Check if we would need to insert instructions in the global scope to initialize the variable
805
2/4
✓ Branch 51 → 52 taken 5931 times.
✗ Branch 51 → 133 not taken.
✗ Branch 52 → 53 not taken.
✓ Branch 52 → 62 taken 5931 times.
5931 if (!globalVarType.isPrimitive())
806 SOFT_ERROR_BOOL(node->dataType, GLOBAL_OF_INVALID_TYPE, "Spice does only support global variables of primitive type")
807
808 // Update type of global var entry
809
1/2
✗ Branch 62 → 63 not taken.
✓ Branch 62 → 64 taken 5931 times.
5931 assert(node->entry != nullptr);
810
1/2
✓ Branch 64 → 65 taken 5931 times.
✗ Branch 64 → 133 not taken.
5931 node->entry->updateType(globalVarType, false);
811
812 // Check if a value is attached
813
6/8
✓ Branch 65 → 66 taken 2 times.
✓ Branch 65 → 69 taken 5929 times.
✓ Branch 66 → 67 taken 2 times.
✗ Branch 66 → 133 not taken.
✓ Branch 67 → 68 taken 2 times.
✗ Branch 67 → 69 not taken.
✓ Branch 70 → 71 taken 2 times.
✓ Branch 70 → 80 taken 5929 times.
5931 if (!node->constant && globalVarType.isConst())
814
3/6
✓ Branch 73 → 74 taken 2 times.
✗ Branch 73 → 127 not taken.
✓ Branch 74 → 75 taken 2 times.
✗ Branch 74 → 125 not taken.
✓ Branch 77 → 78 taken 2 times.
✗ Branch 77 → 131 not taken.
8 SOFT_ERROR_BOOL(node, GLOBAL_CONST_WITHOUT_VALUE, "You must specify a value for constant global variables")
815
816
1/2
✓ Branch 80 → 81 taken 5929 times.
✗ Branch 80 → 132 not taken.
11858 return nullptr;
817 }
818
819 8883 std::any TypeChecker::visitExtDeclPrepare(ExtDeclNode *node) {
820 // Collect argument types
821 8883 QualTypeList argTypes;
822 8883 ParamList argList;
823
2/2
✓ Branch 2 → 3 taken 8463 times.
✓ Branch 2 → 41 taken 420 times.
8883 if (node->hasArgs) {
824
1/2
✓ Branch 4 → 5 taken 8463 times.
✗ Branch 4 → 168 not taken.
8463 argList.reserve(node->argTypeLst->typeLst->dataTypes.size());
825
2/2
✓ Branch 39 → 7 taken 18446 times.
✓ Branch 39 → 40 taken 8463 times.
35372 for (DataTypeNode *arg : node->argTypeLst->typeLst->dataTypes) {
826 // Visit argument
827
2/4
✓ Branch 9 → 10 taken 18446 times.
✗ Branch 9 → 113 not taken.
✓ Branch 10 → 11 taken 18446 times.
✗ Branch 10 → 111 not taken.
18446 auto argType = std::any_cast<QualType>(visit(arg));
828
2/6
✓ Branch 12 → 13 taken 18446 times.
✗ Branch 12 → 122 not taken.
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 17 taken 18446 times.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 114 not taken.
18446 HANDLE_UNRESOLVED_TYPE_PTR(argType)
829 // Check if the argument type is 'dyn'
830
3/4
✓ Branch 17 → 18 taken 18446 times.
✗ Branch 17 → 122 not taken.
✓ Branch 18 → 19 taken 2 times.
✓ Branch 18 → 26 taken 18444 times.
18446 if (argType.is(TY_DYN)) {
831
2/4
✓ Branch 21 → 22 taken 2 times.
✗ Branch 21 → 117 not taken.
✓ Branch 22 → 23 taken 2 times.
✗ Branch 22 → 115 not taken.
2 softError(arg, UNEXPECTED_DYN_TYPE, "Dyn data type is not allowed as arg type for external functions");
832 2 continue;
833 }
834 // Save argument
835
1/2
✓ Branch 26 → 27 taken 18444 times.
✗ Branch 26 → 122 not taken.
18444 argTypes.push_back(argType);
836
1/2
✓ Branch 27 → 28 taken 18444 times.
✗ Branch 27 → 121 not taken.
18444 argList.push_back({argType, false});
837 }
838 }
839
840 // Retrieve return type
841
1/2
✓ Branch 41 → 42 taken 8883 times.
✗ Branch 41 → 168 not taken.
8883 QualType returnType(TY_DYN);
842 8883 const bool isFunction = node->returnType;
843
2/2
✓ Branch 42 → 43 taken 7266 times.
✓ Branch 42 → 62 taken 1617 times.
8883 if (isFunction) { // External function
844
2/4
✓ Branch 43 → 44 taken 7266 times.
✗ Branch 43 → 126 not taken.
✓ Branch 44 → 45 taken 7266 times.
✗ Branch 44 → 124 not taken.
7266 returnType = std::any_cast<QualType>(visit(node->returnType));
845
2/6
✓ Branch 46 → 47 taken 7266 times.
✗ Branch 46 → 168 not taken.
✗ Branch 47 → 48 not taken.
✓ Branch 47 → 51 taken 7266 times.
✗ Branch 48 → 49 not taken.
✗ Branch 48 → 128 not taken.
7266 HANDLE_UNRESOLVED_TYPE_PTR(returnType)
846 // Check if return type is dyn
847
3/4
✓ Branch 51 → 52 taken 7266 times.
✗ Branch 51 → 168 not taken.
✓ Branch 52 → 53 taken 2 times.
✓ Branch 52 → 62 taken 7264 times.
7266 if (returnType.is(TY_DYN))
848
3/6
✓ Branch 55 → 56 taken 2 times.
✗ Branch 55 → 131 not taken.
✓ Branch 56 → 57 taken 2 times.
✗ Branch 56 → 129 not taken.
✓ Branch 59 → 60 taken 2 times.
✗ Branch 59 → 135 not taken.
8 SOFT_ERROR_BOOL(node->returnType, UNEXPECTED_DYN_TYPE, "dyn is not allowed as return type for external functions")
849 }
850
851 // Add function to current scope
852
4/8
✓ Branch 63 → 64 taken 8881 times.
✗ Branch 63 → 142 not taken.
✓ Branch 64 → 65 taken 8881 times.
✗ Branch 64 → 139 not taken.
✓ Branch 65 → 66 taken 8881 times.
✗ Branch 65 → 138 not taken.
✓ Branch 66 → 67 taken 8881 times.
✗ Branch 66 → 136 not taken.
8881 const Function spiceFunc(node->extFunctionName, node->entry, QualType(TY_DYN), returnType, argList, {}, node);
853
1/2
✓ Branch 70 → 71 taken 8881 times.
✗ Branch 70 → 166 not taken.
8881 node->extFunction = FunctionManager::insert(currentScope, spiceFunc, &node->extFunctionManifestations);
854 8881 node->extFunction->mangleFunctionName = false;
855 8881 node->extFunction->alreadyTypeChecked = true;
856
4/4
✓ Branch 71 → 72 taken 8463 times.
✓ Branch 71 → 74 taken 418 times.
✓ Branch 72 → 73 taken 1050 times.
✓ Branch 72 → 74 taken 7413 times.
8881 node->extFunction->isVararg = node->argTypeLst && node->argTypeLst->hasEllipsis;
857
858 // Check procedure attributes
859
2/2
✓ Branch 75 → 76 taken 2 times.
✓ Branch 75 → 93 taken 8879 times.
8881 if (node->attrs) {
860 2 const AttrLstNode *attrLst = node->attrs->attrLst;
861
3/6
✓ Branch 78 → 79 taken 2 times.
✗ Branch 78 → 148 not taken.
✓ Branch 79 → 80 taken 2 times.
✗ Branch 79 → 146 not taken.
✗ Branch 82 → 83 not taken.
✓ Branch 82 → 84 taken 2 times.
6 if (const CompileTimeValue *value = attrLst->getAttrValueByName(ATTR_CORE_COMPILER_MANGLE))
862 node->extFunction->mangleFunctionName = value->boolValue;
863
3/6
✓ Branch 86 → 87 taken 2 times.
✗ Branch 86 → 154 not taken.
✓ Branch 87 → 88 taken 2 times.
✗ Branch 87 → 152 not taken.
✓ Branch 90 → 91 taken 2 times.
✗ Branch 90 → 93 not taken.
6 if (const CompileTimeValue *value = attrLst->getAttrValueByName(ATTR_CORE_COMPILER_MANGLED_NAME)) {
864
1/2
✓ Branch 91 → 92 taken 2 times.
✗ Branch 91 → 166 not taken.
2 const std::string &stringValue = resourceManager.compileTimeStringValues.at(value->stringValueOffset);
865
1/2
✓ Branch 92 → 93 taken 2 times.
✗ Branch 92 → 166 not taken.
2 node->extFunction->predefinedMangledName = stringValue;
866 }
867 }
868
869 // Prepare ext function type
870
2/2
✓ Branch 93 → 94 taken 7264 times.
✓ Branch 93 → 95 taken 1617 times.
8881 const SuperType superType = isFunction ? TY_FUNCTION : TY_PROCEDURE;
871
2/4
✓ Branch 96 → 97 taken 8881 times.
✗ Branch 96 → 158 not taken.
✓ Branch 97 → 98 taken 8881 times.
✗ Branch 97 → 158 not taken.
8881 const QualType extFunctionType = QualType(superType).getWithFunctionParamAndReturnTypes(returnType, argTypes);
872
873 // Set type of external function
874
1/2
✓ Branch 98 → 99 taken 8881 times.
✗ Branch 98 → 166 not taken.
8881 node->entry->updateType(extFunctionType, false);
875
876 // Rename the original child scope to reflect the substantiated versions of the external function
877
3/6
✓ Branch 99 → 100 taken 8881 times.
✗ Branch 99 → 164 not taken.
✓ Branch 100 → 101 taken 8881 times.
✗ Branch 100 → 161 not taken.
✓ Branch 101 → 102 taken 8881 times.
✗ Branch 101 → 159 not taken.
8881 currentScope->renameChildScope(node->getScopeId(), spiceFunc.getScopeName());
878
879
1/2
✓ Branch 104 → 105 taken 8881 times.
✗ Branch 104 → 165 not taken.
8881 return nullptr;
880 8883 }
881
882 5892 std::any TypeChecker::visitImportDefPrepare(ImportDefNode *node) {
883 // Set entry to import type
884
1/2
✓ Branch 2 → 3 taken 5892 times.
✗ Branch 2 → 11 not taken.
5892 const QualType importType(TY_IMPORT, node->importName);
885
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 5892 times.
5892 assert(node->entry != nullptr);
886
1/2
✓ Branch 5 → 6 taken 5892 times.
✗ Branch 5 → 11 not taken.
5892 node->entry->updateType(importType, false);
887
888
1/2
✓ Branch 6 → 7 taken 5892 times.
✗ Branch 6 → 10 not taken.
11784 return nullptr;
889 }
890
891 } // namespace spice::compiler
892