GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 94.5% 394 / 0 / 417
Functions: 100.0% 14 / 0 / 14
Branches: 56.2% 568 / 0 / 1010

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 <SourceFile.h>
6 #include <ast/Attributes.h>
7 #include <global/GlobalResourceManager.h>
8 #include <global/TypeRegistry.h>
9 #include <model/GenericType.h>
10 #include <model/Interface.h>
11 #include <symboltablebuilder/Scope.h>
12 #include <symboltablebuilder/SymbolTableBuilder.h>
13 #include <typechecker/FunctionManager.h>
14 #include <typechecker/InterfaceManager.h>
15 #include <typechecker/MacroDefs.h>
16 #include <typechecker/StructManager.h>
17
18 namespace spice::compiler {
19
20 502 std::any TypeChecker::visitMainFctDefPrepare(MainFctDefNode *node) {
21 // Mark unreachable statements
22 502 bool returnsOnAllControlPaths = true;
23
1/2
✓ Branch 2 → 3 taken 502 times.
✗ Branch 2 → 77 not taken.
502 node->returnsOnAllControlPaths(&returnsOnAllControlPaths, manIdx);
24
25 // Retrieve return type
26
1/2
✓ Branch 3 → 4 taken 502 times.
✗ Branch 3 → 77 not taken.
502 const QualType returnType(TY_INT);
27
28 // Change to function body scope
29 502 currentScope = node->bodyScope;
30
31 // Set type of 'result' variable to int
32
1/2
✓ Branch 6 → 7 taken 502 times.
✗ Branch 6 → 56 not taken.
1506 SymbolTableEntry *resultEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME);
33
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 502 times.
502 assert(resultEntry != nullptr);
34
1/2
✓ Branch 14 → 15 taken 502 times.
✗ Branch 14 → 77 not taken.
502 resultEntry->updateType(returnType, false);
35 502 resultEntry->used = true;
36
37 // Retrieve param types
38 502 QualTypeList paramTypes;
39
2/2
✓ Branch 15 → 16 taken 7 times.
✓ Branch 15 → 36 taken 495 times.
502 if (node->takesArgs) {
40
2/4
✓ Branch 16 → 17 taken 7 times.
✗ Branch 16 → 62 not taken.
✓ Branch 17 → 18 taken 7 times.
✗ Branch 17 → 60 not taken.
7 auto namedParamList = std::any_cast<NamedParamList>(visit(node->paramLst));
41
2/2
✓ Branch 33 → 21 taken 14 times.
✓ Branch 33 → 34 taken 7 times.
28 for (const auto &[name, qualType, isOptional] : namedParamList)
42
1/2
✓ Branch 23 → 24 taken 14 times.
✗ Branch 23 → 63 not taken.
14 paramTypes.push_back(qualType);
43 7 }
44
45 // Prepare type of function
46
2/4
✓ Branch 36 → 37 taken 502 times.
✗ Branch 36 → 67 not taken.
✓ Branch 37 → 38 taken 502 times.
✗ Branch 37 → 67 not taken.
502 const QualType functionType = QualType(TY_FUNCTION).getWithFunctionParamAndReturnTypes(returnType, paramTypes);
47
48 // Update main function symbol type
49
1/2
✓ Branch 40 → 41 taken 502 times.
✗ Branch 40 → 70 not taken.
1506 SymbolTableEntry *functionEntry = rootScope->lookupStrict(MAIN_FUNCTION_NAME);
50
1/2
✗ Branch 46 → 47 not taken.
✓ Branch 46 → 48 taken 502 times.
502 assert(functionEntry != nullptr);
51
1/2
✓ Branch 48 → 49 taken 502 times.
✗ Branch 48 → 75 not taken.
502 functionEntry->updateType(functionType, false);
52 502 functionEntry->used = true;
53
54 // Leave main function body scope
55 502 currentScope = rootScope;
56
57
1/2
✓ Branch 49 → 50 taken 502 times.
✗ Branch 49 → 74 not taken.
1004 return nullptr;
58 502 }
59
60 19948 std::any TypeChecker::visitFctDefPrepare(FctDefNode *node) {
61 // Check if name is dtor
62
3/4
✓ Branch 2 → 3 taken 19948 times.
✗ Branch 2 → 424 not taken.
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 13 taken 19947 times.
19948 if (node->name->name == DTOR_FUNCTION_NAME)
63
3/6
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 281 not taken.
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 279 not taken.
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 285 not taken.
4 SOFT_ERROR_BOOL(node, DTOR_MUST_BE_PROCEDURE, "Destructors are not allowed to be of type function")
64
65 // Check if all control paths in the function return
66 19947 bool doSetPredecessorsUnreachable = true;
67
3/4
✓ Branch 13 → 14 taken 19947 times.
✗ Branch 13 → 424 not taken.
✓ Branch 14 → 15 taken 1 time.
✓ Branch 14 → 24 taken 19946 times.
19947 if (!node->returnsOnAllControlPaths(&doSetPredecessorsUnreachable, manIdx))
68
3/6
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 288 not taken.
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 286 not taken.
✓ Branch 21 → 22 taken 1 time.
✗ Branch 21 → 292 not taken.
4 SOFT_ERROR_BOOL(node, MISSING_RETURN_STMT, "Not all control paths of this function have a return statement")
69
70 // Change to function scope
71 19946 currentScope = node->scope;
72
1/2
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 26 taken 19946 times.
19946 assert(currentScope->type == ScopeType::FUNC_PROC_BODY);
73
74 // Retrieve function template types
75 19946 std::vector<GenericType> usedGenericTypes;
76
2/2
✓ Branch 26 → 27 taken 2084 times.
✓ Branch 26 → 65 taken 17862 times.
19946 if (node->hasTemplateTypes) {
77
2/2
✓ Branch 63 → 29 taken 2520 times.
✓ Branch 63 → 64 taken 2083 times.
6687 for (DataTypeNode *dataType : node->templateTypeLst->dataTypes) {
78 // Visit template type
79
2/4
✓ Branch 31 → 32 taken 2520 times.
✗ Branch 31 → 295 not taken.
✓ Branch 32 → 33 taken 2520 times.
✗ Branch 32 → 293 not taken.
2520 auto templateType = std::any_cast<QualType>(visit(dataType));
80
2/4
✓ Branch 34 → 35 taken 2520 times.
✗ Branch 34 → 305 not taken.
✗ Branch 35 → 36 not taken.
✓ Branch 35 → 37 taken 2520 times.
2520 if (templateType.is(TY_UNRESOLVED))
81 continue;
82 // Check if it is a generic type
83
3/4
✓ Branch 37 → 38 taken 2520 times.
✗ Branch 37 → 305 not taken.
✓ Branch 38 → 39 taken 1 time.
✓ Branch 38 → 47 taken 2519 times.
2520 if (!templateType.is(TY_GENERIC))
84
2/4
✓ Branch 42 → 43 taken 1 time.
✗ Branch 42 → 299 not taken.
✓ Branch 43 → 44 taken 1 time.
✗ Branch 43 → 296 not taken.
3 throw SemanticError(dataType, EXPECTED_GENERIC_TYPE, "A template list can only contain generic types");
85 // Convert generic symbol type to generic type
86
2/4
✓ Branch 47 → 48 taken 2519 times.
✗ Branch 47 → 305 not taken.
✓ Branch 48 → 49 taken 2519 times.
✗ Branch 48 → 305 not taken.
2519 GenericType *genericType = rootScope->lookupGenericTypeStrict(templateType.getSubType());
87
1/2
✗ Branch 49 → 50 not taken.
✓ Branch 49 → 51 taken 2519 times.
2519 assert(genericType != nullptr);
88
1/2
✓ Branch 51 → 52 taken 2519 times.
✗ Branch 51 → 305 not taken.
2519 usedGenericTypes.push_back(*genericType);
89 }
90 }
91
92 // Retrieve 'this' type
93
1/2
✓ Branch 65 → 66 taken 19945 times.
✗ Branch 65 → 422 not taken.
19945 QualType thisType(TY_DYN); // If the function is not a method, the default this type is TY_DYN
94
2/2
✓ Branch 66 → 67 taken 9931 times.
✓ Branch 66 → 105 taken 10014 times.
19945 if (node->isMethod) {
95 9931 Scope *structParentScope = node->structScope->parent;
96
1/2
✓ Branch 67 → 68 taken 9931 times.
✗ Branch 67 → 315 not taken.
9931 SymbolTableEntry *structEntry = structParentScope->lookupStrict(node->name->structName);
97
1/2
✗ Branch 70 → 71 not taken.
✓ Branch 70 → 72 taken 9931 times.
9931 assert(structEntry != nullptr);
98 // Set struct to used
99 9931 structEntry->used = true;
100 // Get type and ptr type
101
1/2
✓ Branch 72 → 73 taken 9931 times.
✗ Branch 72 → 315 not taken.
9931 thisType = structEntry->getQualType();
102
1/2
✓ Branch 73 → 74 taken 9931 times.
✗ Branch 73 → 315 not taken.
9931 const QualType thisPtrType = thisType.toPtr(node);
103 // Collect template types of 'this' type
104
3/4
✓ Branch 74 → 75 taken 9931 times.
✗ Branch 74 → 308 not taken.
✓ Branch 92 → 77 taken 3367 times.
✓ Branch 92 → 93 taken 9931 times.
23229 for (const QualType &templateType : thisType.getTemplateTypes()) {
105 801 const auto lambda = [&](const GenericType &genericType) { return genericType == templateType; };
106
3/4
✓ Branch 79 → 80 taken 3367 times.
✗ Branch 79 → 307 not taken.
✓ Branch 80 → 81 taken 3359 times.
✓ Branch 80 → 82 taken 8 times.
3367 if (std::ranges::none_of(usedGenericTypes, lambda))
107
1/2
✓ Branch 81 → 82 taken 3359 times.
✗ Branch 81 → 307 not taken.
3359 usedGenericTypes.emplace_back(templateType);
108 3367 usedGenericTypes.back().used = true;
109 }
110
111 // Set type of 'this' variable
112
1/2
✓ Branch 95 → 96 taken 9931 times.
✗ Branch 95 → 311 not taken.
29793 SymbolTableEntry *thisEntry = currentScope->lookupStrict(THIS_VARIABLE_NAME);
113
1/2
✗ Branch 101 → 102 not taken.
✓ Branch 101 → 103 taken 9931 times.
9931 assert(thisEntry != nullptr);
114
1/2
✓ Branch 103 → 104 taken 9931 times.
✗ Branch 103 → 315 not taken.
9931 thisEntry->updateType(thisPtrType, false);
115 }
116
117 // Visit parameters
118 19945 QualTypeList paramTypes;
119 19945 ParamList paramList;
120
2/2
✓ Branch 105 → 106 taken 14756 times.
✓ Branch 105 → 152 taken 5189 times.
19945 if (node->hasParams) {
121 14756 std::vector<const char *> paramNames;
122 // Visit param list to retrieve the param names
123
2/4
✓ Branch 106 → 107 taken 14756 times.
✗ Branch 106 → 318 not taken.
✓ Branch 107 → 108 taken 14756 times.
✗ Branch 107 → 316 not taken.
14756 auto namedParamList = std::any_cast<NamedParamList>(visit(node->paramLst));
124
2/2
✓ Branch 140 → 111 taken 22374 times.
✓ Branch 140 → 141 taken 14754 times.
51884 for (const auto &[name, qualType, isOptional] : namedParamList) {
125
1/2
✓ Branch 113 → 114 taken 22374 times.
✗ Branch 113 → 330 not taken.
22374 paramNames.push_back(name);
126
2/6
✓ Branch 114 → 115 taken 22374 times.
✗ Branch 114 → 330 not taken.
✗ Branch 115 → 116 not taken.
✓ Branch 115 → 119 taken 22374 times.
✗ Branch 116 → 117 not taken.
✗ Branch 116 → 319 not taken.
22374 HANDLE_UNRESOLVED_TYPE_PTR(qualType);
127
1/2
✓ Branch 119 → 120 taken 22374 times.
✗ Branch 119 → 330 not taken.
22374 paramTypes.push_back(qualType);
128
1/2
✓ Branch 120 → 121 taken 22374 times.
✗ Branch 120 → 320 not taken.
22374 paramList.push_back({qualType, isOptional});
129 // Check if the type is present in the template for generic types
130
3/4
✓ Branch 121 → 122 taken 22374 times.
✗ Branch 121 → 330 not taken.
✓ Branch 122 → 123 taken 2 times.
✓ Branch 122 → 131 taken 22372 times.
22374 if (!qualType.isCoveredByGenericTypeList(usedGenericTypes))
131 throw SemanticError(node->paramLst, GENERIC_TYPE_NOT_IN_TEMPLATE,
132
2/4
✓ Branch 126 → 127 taken 2 times.
✗ Branch 126 → 324 not taken.
✓ Branch 127 → 128 taken 2 times.
✗ Branch 127 → 321 not taken.
6 "Generic param type not included in the template type list of the function");
133 }
134
2/4
✓ Branch 143 → 144 taken 14754 times.
✗ Branch 143 → 145 not taken.
✓ Branch 148 → 149 taken 14754 times.
✗ Branch 148 → 151 not taken.
29512 }
135
136 // Retrieve return type
137
2/4
✓ Branch 152 → 153 taken 19943 times.
✗ Branch 152 → 338 not taken.
✓ Branch 153 → 154 taken 19943 times.
✗ Branch 153 → 336 not taken.
19943 auto returnType = std::any_cast<QualType>(visit(node->returnType));
138
2/6
✓ Branch 155 → 156 taken 19943 times.
✗ Branch 155 → 418 not taken.
✗ Branch 156 → 157 not taken.
✓ Branch 156 → 160 taken 19943 times.
✗ Branch 157 → 158 not taken.
✗ Branch 157 → 339 not taken.
19943 HANDLE_UNRESOLVED_TYPE_PTR(returnType)
139
3/4
✓ Branch 160 → 161 taken 19943 times.
✗ Branch 160 → 418 not taken.
✓ Branch 161 → 162 taken 1 time.
✓ Branch 161 → 171 taken 19942 times.
19943 if (returnType.is(TY_DYN))
140
3/6
✓ Branch 164 → 165 taken 1 time.
✗ Branch 164 → 342 not taken.
✓ Branch 165 → 166 taken 1 time.
✗ Branch 165 → 340 not taken.
✓ Branch 168 → 169 taken 1 time.
✗ Branch 168 → 346 not taken.
4 SOFT_ERROR_BOOL(node, UNEXPECTED_DYN_TYPE, "Dyn return types are not allowed")
141
3/4
✓ Branch 171 → 172 taken 19942 times.
✗ Branch 171 → 418 not taken.
✓ Branch 172 → 173 taken 1 time.
✓ Branch 172 → 182 taken 19941 times.
19942 if (!returnType.isCoveredByGenericTypeList(usedGenericTypes))
142
3/6
✓ Branch 175 → 176 taken 1 time.
✗ Branch 175 → 349 not taken.
✓ Branch 176 → 177 taken 1 time.
✗ Branch 176 → 347 not taken.
✓ Branch 179 → 180 taken 1 time.
✗ Branch 179 → 353 not taken.
4 SOFT_ERROR_BOOL(node->returnType, GENERIC_TYPE_NOT_IN_TEMPLATE,
143 "Generic return type not included in the template type list of the function")
144
145 // Leave function body scope
146 19941 currentScope = node->scope->parent;
147
3/4
✓ Branch 182 → 183 taken 9931 times.
✓ Branch 182 → 185 taken 10010 times.
✗ Branch 183 → 184 not taken.
✓ Branch 183 → 185 taken 9931 times.
19941 assert(currentScope->type == ScopeType::GLOBAL || currentScope->type == ScopeType::STRUCT);
148
149 // Prepare type of function
150
2/4
✓ Branch 185 → 186 taken 19941 times.
✗ Branch 185 → 354 not taken.
✓ Branch 186 → 187 taken 19941 times.
✗ Branch 186 → 354 not taken.
19941 QualType functionType = QualType(TY_FUNCTION).getWithFunctionParamAndReturnTypes(returnType, paramTypes);
151 19941 functionType.setQualifiers(node->qualifiers);
152
153 // Update type of function entry
154
1/2
✓ Branch 188 → 189 taken 19941 times.
✗ Branch 188 → 357 not taken.
39882 SymbolTableEntry *functionEntry = currentScope->lookupStrict(node->getSymbolTableEntryName());
155
1/2
✗ Branch 193 → 194 not taken.
✓ Branch 193 → 195 taken 19941 times.
19941 assert(functionEntry != nullptr);
156
1/2
✓ Branch 195 → 196 taken 19941 times.
✗ Branch 195 → 418 not taken.
19941 functionEntry->updateType(functionType, false);
157
158 // Build function object
159
4/8
✓ Branch 196 → 197 taken 19941 times.
✗ Branch 196 → 366 not taken.
✓ Branch 197 → 198 taken 19941 times.
✗ Branch 197 → 363 not taken.
✓ Branch 198 → 199 taken 19941 times.
✗ Branch 198 → 360 not taken.
✓ Branch 199 → 200 taken 19941 times.
✗ Branch 199 → 358 not taken.
19941 Function spiceFunc(node->name->name, functionEntry, thisType, returnType, paramList, usedGenericTypes, node);
160 19941 spiceFunc.bodyScope = node->scope;
161
2/2
✓ Branch 203 → 204 taken 19940 times.
✓ Branch 203 → 416 taken 1 time.
19941 FunctionManager::insert(currentScope, spiceFunc, &node->manifestations);
162
163 // Check function attributes
164
2/2
✓ Branch 204 → 205 taken 692 times.
✓ Branch 204 → 252 taken 19248 times.
19940 if (node->attrs) {
165 692 const AttrLstNode *attrLst = node->attrs->attrLst;
166 692 Function *firstManifestation = node->manifestations.front();
167
4/6
✓ Branch 208 → 209 taken 692 times.
✗ Branch 208 → 369 not taken.
✓ Branch 209 → 210 taken 692 times.
✗ Branch 209 → 367 not taken.
✓ Branch 212 → 213 taken 1 time.
✓ Branch 212 → 214 taken 691 times.
2076 if (const CompileTimeValue *value = attrLst->getAttrValueByName(ATTR_CORE_COMPILER_MANGLE))
168 1 firstManifestation->mangleFunctionName = value->boolValue;
169
3/6
✓ Branch 216 → 217 taken 692 times.
✗ Branch 216 → 375 not taken.
✓ Branch 217 → 218 taken 692 times.
✗ Branch 217 → 373 not taken.
✗ Branch 220 → 221 not taken.
✓ Branch 220 → 223 taken 692 times.
2076 if (const CompileTimeValue *value = attrLst->getAttrValueByName(ATTR_CORE_COMPILER_MANGLED_NAME)) {
170 const std::string &stringValue = resourceManager.compileTimeStringValues.at(value->stringValueOffset);
171 firstManifestation->predefinedMangledName = stringValue;
172 }
173
6/8
✓ Branch 225 → 226 taken 692 times.
✗ Branch 225 → 381 not taken.
✓ Branch 226 → 227 taken 692 times.
✗ Branch 226 → 379 not taken.
✓ Branch 229 → 230 taken 109 times.
✓ Branch 229 → 252 taken 583 times.
✓ Branch 230 → 231 taken 108 times.
✓ Branch 230 → 252 taken 1 time.
2076 if (const CompileTimeValue *value = attrLst->getAttrValueByName(ATTR_TEST); value && value->boolValue) {
174 // Make sure that the function has the correct signature
175
2/2
✓ Branch 231 → 232 taken 1 time.
✓ Branch 231 → 240 taken 107 times.
108 if (node->hasParams)
176
2/4
✓ Branch 235 → 236 taken 1 time.
✗ Branch 235 → 388 not taken.
✓ Branch 236 → 237 taken 1 time.
✗ Branch 236 → 385 not taken.
3 throw SemanticError(node->paramLst, TEST_FUNCTION_WITH_PARAMS, "Test function may not have parameters");
177
3/4
✓ Branch 240 → 241 taken 107 times.
✗ Branch 240 → 416 not taken.
✓ Branch 241 → 242 taken 1 time.
✓ Branch 241 → 250 taken 106 times.
107 if (!returnType.is(TY_BOOL))
178
2/4
✓ Branch 245 → 246 taken 1 time.
✗ Branch 245 → 397 not taken.
✓ Branch 246 → 247 taken 1 time.
✗ Branch 246 → 394 not taken.
3 throw SemanticError(node->returnType, TEST_FUNCTION_WRONG_RETURN_TYPE, "Test function must return a bool");
179 // Add to test function list
180 106 firstManifestation->entry->used = true; // Avoid printing unused warnings
181 106 firstManifestation->used = true; // Always keep test functions, because they are called implicitly by the test main
182
1/2
✓ Branch 251 → 252 taken 106 times.
✗ Branch 251 → 416 not taken.
106 sourceFile->testFunctions.push_back(node->manifestations.front());
183 }
184 }
185
186 // Duplicate / rename the original child scope to reflect the substantiated versions of the function
187
2/2
✓ Branch 262 → 253 taken 1707 times.
✓ Branch 262 → 263 taken 19938 times.
21645 for (size_t i = 1; i < node->manifestations.size(); i++) {
188
4/8
✓ Branch 253 → 254 taken 1707 times.
✗ Branch 253 → 408 not taken.
✓ Branch 254 → 255 taken 1707 times.
✗ Branch 254 → 408 not taken.
✓ Branch 255 → 256 taken 1707 times.
✗ Branch 255 → 405 not taken.
✓ Branch 256 → 257 taken 1707 times.
✗ Branch 256 → 403 not taken.
1707 Scope *scope = currentScope->copyChildScope(node->getScopeId(), node->manifestations.at(i)->getScopeName());
189
1/2
✓ Branch 259 → 260 taken 1707 times.
✗ Branch 259 → 416 not taken.
1707 node->manifestations.at(i)->bodyScope = scope;
190 }
191
3/6
✓ Branch 264 → 265 taken 19938 times.
✗ Branch 264 → 414 not taken.
✓ Branch 265 → 266 taken 19938 times.
✗ Branch 265 → 411 not taken.
✓ Branch 266 → 267 taken 19938 times.
✗ Branch 266 → 409 not taken.
19938 currentScope->renameChildScope(node->getScopeId(), node->manifestations.front()->getScopeName());
192
193 // Change to the root scope
194 19938 currentScope = rootScope;
195
1/2
✗ Branch 269 → 270 not taken.
✓ Branch 269 → 271 taken 19938 times.
19938 assert(currentScope->type == ScopeType::GLOBAL);
196
197
1/2
✓ Branch 271 → 272 taken 19938 times.
✗ Branch 271 → 415 not taken.
19938 return nullptr;
198 19959 }
199
200 10594 std::any TypeChecker::visitProcDefPrepare(ProcDefNode *node) {
201 // Mark unreachable statements
202 10594 bool doSetPredecessorsUnreachable = true;
203
1/2
✓ Branch 2 → 3 taken 10594 times.
✗ Branch 2 → 316 not taken.
10594 node->returnsOnAllControlPaths(&doSetPredecessorsUnreachable, manIdx);
204
205 // Check if dtor and has params
206
7/8
✓ Branch 3 → 4 taken 8179 times.
✓ Branch 3 → 7 taken 2415 times.
✓ Branch 4 → 5 taken 8179 times.
✗ Branch 4 → 316 not taken.
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 7 taken 8178 times.
✓ Branch 8 → 9 taken 1 time.
✓ Branch 8 → 17 taken 10593 times.
10594 if (node->hasParams && node->name->name == DTOR_FUNCTION_NAME)
207
2/4
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 219 not taken.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 216 not taken.
3 throw SemanticError(node, DTOR_WITH_PARAMS, "It is not allowed to specify parameters for destructors");
208
209 // Change to procedure scope
210 10593 currentScope = node->scope;
211
1/2
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 10593 times.
10593 assert(currentScope->type == ScopeType::FUNC_PROC_BODY);
212
213 // Retrieve procedure template types
214 10593 std::vector<GenericType> usedGenericTypes;
215
2/2
✓ Branch 19 → 20 taken 2257 times.
✓ Branch 19 → 58 taken 8336 times.
10593 if (node->hasTemplateTypes) {
216
2/2
✓ Branch 56 → 22 taken 2570 times.
✓ Branch 56 → 57 taken 2256 times.
7083 for (DataTypeNode *dataType : node->templateTypeLst->dataTypes) {
217 // Visit template type
218
2/4
✓ Branch 24 → 25 taken 2570 times.
✗ Branch 24 → 227 not taken.
✓ Branch 25 → 26 taken 2570 times.
✗ Branch 25 → 225 not taken.
2570 auto templateType = std::any_cast<QualType>(visit(dataType));
219
2/4
✓ Branch 27 → 28 taken 2570 times.
✗ Branch 27 → 237 not taken.
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 2570 times.
2570 if (templateType.is(TY_UNRESOLVED))
220 continue;
221 // Check if it is a generic type
222
3/4
✓ Branch 30 → 31 taken 2570 times.
✗ Branch 30 → 237 not taken.
✓ Branch 31 → 32 taken 1 time.
✓ Branch 31 → 40 taken 2569 times.
2570 if (!templateType.is(TY_GENERIC))
223
2/4
✓ Branch 35 → 36 taken 1 time.
✗ Branch 35 → 231 not taken.
✓ Branch 36 → 37 taken 1 time.
✗ Branch 36 → 228 not taken.
3 throw SemanticError(dataType, EXPECTED_GENERIC_TYPE, "A template list can only contain generic types");
224 // Convert generic symbol type to generic type
225
2/4
✓ Branch 40 → 41 taken 2569 times.
✗ Branch 40 → 237 not taken.
✓ Branch 41 → 42 taken 2569 times.
✗ Branch 41 → 237 not taken.
2569 const GenericType *genericType = rootScope->lookupGenericTypeStrict(templateType.getSubType());
226
1/2
✗ Branch 42 → 43 not taken.
✓ Branch 42 → 44 taken 2569 times.
2569 assert(genericType != nullptr);
227
1/2
✓ Branch 44 → 45 taken 2569 times.
✗ Branch 44 → 237 not taken.
2569 usedGenericTypes.push_back(*genericType);
228 }
229 }
230
231 // Retrieve 'this' type
232
1/2
✓ Branch 58 → 59 taken 10592 times.
✗ Branch 58 → 314 not taken.
10592 QualType thisType(TY_DYN); // If the procedure is not a method, the default this type is TY_DYN
233
2/2
✓ Branch 59 → 60 taken 8822 times.
✓ Branch 59 → 98 taken 1770 times.
10592 if (node->isMethod) {
234 8822 Scope *structParentScope = node->structScope->parent;
235
1/2
✓ Branch 60 → 61 taken 8822 times.
✗ Branch 60 → 247 not taken.
8822 SymbolTableEntry *structEntry = structParentScope->lookupStrict(node->name->structName);
236
1/2
✗ Branch 63 → 64 not taken.
✓ Branch 63 → 65 taken 8822 times.
8822 assert(structEntry != nullptr);
237 // Set struct to used
238 8822 structEntry->used = true;
239 // Get type and ptr type
240
1/2
✓ Branch 65 → 66 taken 8822 times.
✗ Branch 65 → 247 not taken.
8822 thisType = structEntry->getQualType();
241
1/2
✓ Branch 66 → 67 taken 8822 times.
✗ Branch 66 → 247 not taken.
8822 const QualType thisPtrType = thisType.toPtr(node);
242 // Collect template types of 'this' type
243
3/4
✓ Branch 67 → 68 taken 8822 times.
✗ Branch 67 → 240 not taken.
✓ Branch 85 → 70 taken 3174 times.
✓ Branch 85 → 86 taken 8822 times.
20818 for (const QualType &templateType : thisType.getTemplateTypes()) {
244 953 const auto lambda = [&](const GenericType &genericType) { return genericType == templateType; };
245
3/4
✓ Branch 72 → 73 taken 3174 times.
✗ Branch 72 → 239 not taken.
✓ Branch 73 → 74 taken 2911 times.
✓ Branch 73 → 75 taken 263 times.
3174 if (std::ranges::none_of(usedGenericTypes, lambda))
246
1/2
✓ Branch 74 → 75 taken 2911 times.
✗ Branch 74 → 239 not taken.
2911 usedGenericTypes.emplace_back(templateType);
247 3174 usedGenericTypes.back().used = true;
248 }
249
250 // Set type of 'this' variable
251
1/2
✓ Branch 88 → 89 taken 8822 times.
✗ Branch 88 → 243 not taken.
26466 SymbolTableEntry *thisEntry = currentScope->lookupStrict(THIS_VARIABLE_NAME);
252
1/2
✗ Branch 94 → 95 not taken.
✓ Branch 94 → 96 taken 8822 times.
8822 assert(thisEntry != nullptr);
253
1/2
✓ Branch 96 → 97 taken 8822 times.
✗ Branch 96 → 247 not taken.
8822 thisEntry->updateType(thisPtrType, false);
254 }
255
256 // Visit parameters
257 10592 QualTypeList paramTypes;
258 10592 ParamList paramList;
259
2/2
✓ Branch 98 → 99 taken 8178 times.
✓ Branch 98 → 145 taken 2414 times.
10592 if (node->hasParams) {
260 8178 std::vector<const char *> paramNames;
261 // Visit param list to retrieve the param names
262
2/4
✓ Branch 99 → 100 taken 8178 times.
✗ Branch 99 → 250 not taken.
✓ Branch 100 → 101 taken 8178 times.
✗ Branch 100 → 248 not taken.
8178 auto namedParamList = std::any_cast<NamedParamList>(visit(node->paramLst));
263
2/2
✓ Branch 133 → 104 taken 11219 times.
✓ Branch 133 → 134 taken 8176 times.
27573 for (const auto &[name, qualType, isOptional] : namedParamList) {
264
1/2
✓ Branch 106 → 107 taken 11219 times.
✗ Branch 106 → 262 not taken.
11219 paramNames.push_back(name);
265
1/2
✓ Branch 107 → 108 taken 11219 times.
✗ Branch 107 → 262 not taken.
11219 paramTypes.push_back(qualType);
266
4/6
✓ Branch 108 → 109 taken 11219 times.
✗ Branch 108 → 262 not taken.
✓ Branch 109 → 110 taken 1 time.
✓ Branch 109 → 113 taken 11218 times.
✓ Branch 110 → 111 taken 1 time.
✗ Branch 110 → 251 not taken.
11220 HANDLE_UNRESOLVED_TYPE_PTR(qualType);
267
1/2
✓ Branch 113 → 114 taken 11218 times.
✗ Branch 113 → 252 not taken.
11218 paramList.push_back({qualType, isOptional});
268 // Check if the type is present in the template for generic types
269
3/4
✓ Branch 114 → 115 taken 11218 times.
✗ Branch 114 → 262 not taken.
✓ Branch 115 → 116 taken 1 time.
✓ Branch 115 → 124 taken 11217 times.
11218 if (!qualType.isCoveredByGenericTypeList(usedGenericTypes))
270 throw SemanticError(node->paramLst, GENERIC_TYPE_NOT_IN_TEMPLATE,
271
2/4
✓ Branch 119 → 120 taken 1 time.
✗ Branch 119 → 256 not taken.
✓ Branch 120 → 121 taken 1 time.
✗ Branch 120 → 253 not taken.
3 "Generic param type not included in the template type list of the procedure");
272 }
273
4/4
✓ Branch 136 → 137 taken 8176 times.
✓ Branch 136 → 138 taken 1 time.
✓ Branch 141 → 142 taken 8176 times.
✓ Branch 141 → 144 taken 1 time.
16356 }
274
275 // Leave procedure body scope
276 10590 currentScope = node->scope->parent;
277
3/4
✓ Branch 145 → 146 taken 8822 times.
✓ Branch 145 → 148 taken 1768 times.
✗ Branch 146 → 147 not taken.
✓ Branch 146 → 148 taken 8822 times.
10590 assert(currentScope->type == ScopeType::GLOBAL || currentScope->type == ScopeType::STRUCT);
278
279 // Prepare type of procedure
280
3/6
✓ Branch 148 → 149 taken 10590 times.
✗ Branch 148 → 269 not taken.
✓ Branch 149 → 150 taken 10590 times.
✗ Branch 149 → 268 not taken.
✓ Branch 150 → 151 taken 10590 times.
✗ Branch 150 → 268 not taken.
10590 QualType procedureType = QualType(TY_PROCEDURE).getWithFunctionParamAndReturnTypes(QualType(TY_DYN), paramTypes);
281 10590 procedureType.setQualifiers(node->qualifiers);
282
283 // Update type of procedure entry
284
1/2
✓ Branch 152 → 153 taken 10590 times.
✗ Branch 152 → 272 not taken.
21180 SymbolTableEntry *procedureEntry = currentScope->lookupStrict(node->getSymbolTableEntryName());
285
1/2
✗ Branch 157 → 158 not taken.
✓ Branch 157 → 159 taken 10590 times.
10590 assert(procedureEntry != nullptr);
286
1/2
✓ Branch 159 → 160 taken 10590 times.
✗ Branch 159 → 310 not taken.
10590 procedureEntry->updateType(procedureType, false);
287
288 // Build procedure object
289
5/10
✓ Branch 160 → 161 taken 10590 times.
✗ Branch 160 → 282 not taken.
✓ Branch 161 → 162 taken 10590 times.
✗ Branch 161 → 279 not taken.
✓ Branch 162 → 163 taken 10590 times.
✗ Branch 162 → 276 not taken.
✓ Branch 163 → 164 taken 10590 times.
✗ Branch 163 → 275 not taken.
✓ Branch 164 → 165 taken 10590 times.
✗ Branch 164 → 273 not taken.
10590 Function spiceProc(node->name->name, procedureEntry, thisType, QualType(TY_DYN), paramList, usedGenericTypes, node);
290 10590 spiceProc.bodyScope = node->scope;
291
2/2
✓ Branch 168 → 169 taken 10589 times.
✓ Branch 168 → 308 taken 1 time.
10590 FunctionManager::insert(currentScope, spiceProc, &node->manifestations);
292
293 // Check procedure attributes
294
1/2
✗ Branch 169 → 170 not taken.
✓ Branch 169 → 189 taken 10589 times.
10589 if (node->attrs) {
295 const AttrLstNode *attrLst = node->attrs->attrLst;
296 if (const CompileTimeValue *value = attrLst->getAttrValueByName(ATTR_CORE_COMPILER_MANGLE))
297 node->manifestations.front()->mangleFunctionName = value->boolValue;
298 if (const CompileTimeValue *value = attrLst->getAttrValueByName(ATTR_CORE_COMPILER_MANGLED_NAME)) {
299 const std::string &stringValue = resourceManager.compileTimeStringValues.at(value->stringValueOffset);
300 node->manifestations.front()->predefinedMangledName = stringValue;
301 }
302 }
303
304 // Duplicate / rename the original child scope to reflect the substantiated versions of the procedure
305
2/2
✓ Branch 199 → 190 taken 541 times.
✓ Branch 199 → 200 taken 10589 times.
11130 for (size_t i = 1; i < node->manifestations.size(); i++) {
306
4/8
✓ Branch 190 → 191 taken 541 times.
✗ Branch 190 → 300 not taken.
✓ Branch 191 → 192 taken 541 times.
✗ Branch 191 → 300 not taken.
✓ Branch 192 → 193 taken 541 times.
✗ Branch 192 → 297 not taken.
✓ Branch 193 → 194 taken 541 times.
✗ Branch 193 → 295 not taken.
541 Scope *scope = currentScope->copyChildScope(node->getScopeId(), node->manifestations.at(i)->getScopeName());
307
1/2
✓ Branch 196 → 197 taken 541 times.
✗ Branch 196 → 308 not taken.
541 node->manifestations.at(i)->bodyScope = scope;
308 }
309
3/6
✓ Branch 201 → 202 taken 10589 times.
✗ Branch 201 → 306 not taken.
✓ Branch 202 → 203 taken 10589 times.
✗ Branch 202 → 303 not taken.
✓ Branch 203 → 204 taken 10589 times.
✗ Branch 203 → 301 not taken.
10589 currentScope->renameChildScope(node->getScopeId(), node->manifestations.front()->getScopeName());
310
311 // Change to the root scope
312 10589 currentScope = rootScope;
313
1/2
✗ Branch 206 → 207 not taken.
✓ Branch 206 → 208 taken 10589 times.
10589 assert(currentScope->type == ScopeType::GLOBAL);
314
315
1/2
✓ Branch 208 → 209 taken 10589 times.
✗ Branch 208 → 307 not taken.
10589 return nullptr;
316 10598 }
317
318 2808 std::any TypeChecker::visitStructDefPrepare(StructDefNode *node) {
319 2808 QualTypeList usedTemplateTypes;
320 2808 std::vector<GenericType> templateTypesGeneric;
321
322 // Retrieve struct template types
323
2/2
✓ Branch 2 → 3 taken 632 times.
✓ Branch 2 → 46 taken 2176 times.
2808 if (node->hasTemplateTypes) {
324
1/2
✓ Branch 4 → 5 taken 632 times.
✗ Branch 4 → 317 not taken.
632 usedTemplateTypes.reserve(node->templateTypeLst->dataTypes.size());
325
1/2
✓ Branch 6 → 7 taken 632 times.
✗ Branch 6 → 317 not taken.
632 templateTypesGeneric.reserve(node->templateTypeLst->dataTypes.size());
326
2/2
✓ Branch 44 → 9 taken 856 times.
✓ Branch 44 → 45 taken 632 times.
2120 for (DataTypeNode *dataType : node->templateTypeLst->dataTypes) {
327 // Visit template type
328
2/4
✓ Branch 11 → 12 taken 856 times.
✗ Branch 11 → 221 not taken.
✓ Branch 12 → 13 taken 856 times.
✗ Branch 12 → 219 not taken.
856 auto templateType = std::any_cast<QualType>(visit(dataType));
329
2/4
✓ Branch 14 → 15 taken 856 times.
✗ Branch 14 → 231 not taken.
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 856 times.
856 if (templateType.is(TY_UNRESOLVED))
330 continue;
331 // Check if it is a generic type
332
2/4
✓ Branch 17 → 18 taken 856 times.
✗ Branch 17 → 231 not taken.
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 27 taken 856 times.
856 if (!templateType.is(TY_GENERIC))
333 throw SemanticError(dataType, EXPECTED_GENERIC_TYPE, "A template list can only contain generic types");
334 // Convert generic symbol type to generic type
335
2/4
✓ Branch 27 → 28 taken 856 times.
✗ Branch 27 → 231 not taken.
✓ Branch 28 → 29 taken 856 times.
✗ Branch 28 → 231 not taken.
856 GenericType *genericType = rootScope->lookupGenericTypeStrict(templateType.getSubType());
336
1/2
✗ Branch 29 → 30 not taken.
✓ Branch 29 → 31 taken 856 times.
856 assert(genericType != nullptr);
337
1/2
✓ Branch 31 → 32 taken 856 times.
✗ Branch 31 → 231 not taken.
856 usedTemplateTypes.push_back(*genericType);
338
1/2
✓ Branch 32 → 33 taken 856 times.
✗ Branch 32 → 231 not taken.
856 templateTypesGeneric.push_back(*genericType);
339 }
340 }
341
342 // Retrieve implemented interfaces
343 2808 QualTypeList interfaceTypes;
344
2/2
✓ Branch 46 → 47 taken 374 times.
✓ Branch 46 → 107 taken 2434 times.
2808 if (node->hasInterfaces) {
345
1/2
✓ Branch 48 → 49 taken 374 times.
✗ Branch 48 → 315 not taken.
374 interfaceTypes.reserve(node->interfaceTypeLst->dataTypes.size());
346
2/2
✓ Branch 105 → 51 taken 374 times.
✓ Branch 105 → 106 taken 373 times.
1121 for (DataTypeNode *interfaceNode : node->interfaceTypeLst->dataTypes) {
347 // Visit interface type
348
2/4
✓ Branch 53 → 54 taken 374 times.
✗ Branch 53 → 235 not taken.
✓ Branch 54 → 55 taken 374 times.
✗ Branch 54 → 233 not taken.
374 auto interfaceType = std::any_cast<QualType>(visit(interfaceNode));
349
2/4
✓ Branch 56 → 57 taken 374 times.
✗ Branch 56 → 257 not taken.
✗ Branch 57 → 58 not taken.
✓ Branch 57 → 59 taken 374 times.
374 if (interfaceType.is(TY_UNRESOLVED))
350 continue;
351 // Check if it is an interface type
352
2/4
✓ Branch 59 → 60 taken 374 times.
✗ Branch 59 → 257 not taken.
✗ Branch 60 → 61 not taken.
✓ Branch 60 → 68 taken 374 times.
374 if (!interfaceType.is(TY_INTERFACE))
353 throw SemanticError(interfaceNode, EXPECTED_INTERFACE_TYPE,
354 "Expected interface type, got " + interfaceType.getName(false));
355 // Check for visibility
356
9/12
✓ Branch 68 → 69 taken 374 times.
✗ Branch 68 → 257 not taken.
✓ Branch 69 → 70 taken 374 times.
✗ Branch 69 → 257 not taken.
✓ Branch 70 → 71 taken 336 times.
✓ Branch 70 → 74 taken 38 times.
✓ Branch 71 → 72 taken 336 times.
✗ Branch 71 → 257 not taken.
✓ Branch 72 → 73 taken 1 time.
✓ Branch 72 → 74 taken 335 times.
✓ Branch 75 → 76 taken 1 time.
✓ Branch 75 → 84 taken 373 times.
374 if (interfaceType.getBodyScope()->isImportedBy(rootScope) && !interfaceType.isPublic())
357 throw SemanticError(node, INSUFFICIENT_VISIBILITY,
358
4/8
✓ Branch 77 → 78 taken 1 time.
✗ Branch 77 → 250 not taken.
✓ Branch 78 → 79 taken 1 time.
✗ Branch 78 → 250 not taken.
✓ Branch 79 → 80 taken 1 time.
✗ Branch 79 → 248 not taken.
✓ Branch 80 → 81 taken 1 time.
✗ Branch 80 → 245 not taken.
1 "Cannot access interface '" + interfaceType.getSubType() + "' due to its private visibility");
359 // Add to interface types
360
1/2
✓ Branch 84 → 85 taken 373 times.
✗ Branch 84 → 257 not taken.
373 interfaceTypes.push_back(interfaceType);
361 // Update the type of the entry for that interface field
362 373 const std::string &interfaceName = interfaceNode->baseDataType->customDataType->typeNameFragments.back();
363
1/2
✓ Branch 86 → 87 taken 373 times.
✗ Branch 86 → 256 not taken.
746 SymbolTableEntry *interfaceEntry = node->structScope->lookupStrict("this." + interfaceName);
364
1/2
✗ Branch 91 → 92 not taken.
✓ Branch 91 → 93 taken 373 times.
373 assert(interfaceEntry != nullptr);
365
1/2
✓ Branch 93 → 94 taken 373 times.
✗ Branch 93 → 257 not taken.
373 interfaceEntry->updateType(interfaceType, false);
366 }
367 }
368
369 // Update type of struct entry
370
1/2
✗ Branch 107 → 108 not taken.
✓ Branch 107 → 109 taken 2807 times.
2807 assert(node->entry != nullptr);
371 2807 const TypeChainElementData data = {.bodyScope = node->structScope};
372
1/2
✓ Branch 109 → 110 taken 2807 times.
✗ Branch 109 → 315 not taken.
2807 const Type *type = TypeRegistry::getOrInsert(TY_STRUCT, node->structName, node->typeId, data, usedTemplateTypes);
373 // If the entry was upgraded from a forward declaration, the existing type was already set to the opaque
374 // forward-decl type. Overwriting is expected here.
375 2807 const bool overwrite = node->entry->forwardDeclCodeLoc != nullptr;
376
2/4
✓ Branch 110 → 111 taken 2807 times.
✗ Branch 110 → 259 not taken.
✓ Branch 111 → 112 taken 2807 times.
✗ Branch 111 → 259 not taken.
2807 node->entry->updateType(QualType(type, node->qualifiers), overwrite);
377
378 // Change to struct scope
379 2807 currentScope = node->structScope;
380
1/2
✗ Branch 112 → 113 not taken.
✓ Branch 112 → 114 taken 2807 times.
2807 assert(currentScope->type == ScopeType::STRUCT);
381
382 // Retrieve field types
383 2807 QualTypeList fieldTypes;
384
1/2
✓ Branch 115 → 116 taken 2807 times.
✗ Branch 115 → 313 not taken.
2807 fieldTypes.reserve(node->fields.size());
385
2/2
✓ Branch 167 → 118 taken 5304 times.
✓ Branch 167 → 168 taken 2804 times.
10915 for (FieldNode *field : node->fields) {
386 // Visit field type
387
2/4
✓ Branch 120 → 121 taken 5304 times.
✗ Branch 120 → 262 not taken.
✓ Branch 121 → 122 taken 5304 times.
✗ Branch 121 → 260 not taken.
5304 auto fieldType = std::any_cast<QualType>(visit(field));
388
3/4
✓ Branch 123 → 124 taken 5304 times.
✗ Branch 123 → 281 not taken.
✓ Branch 124 → 125 taken 2 times.
✓ Branch 124 → 126 taken 5302 times.
5304 if (fieldType.is(TY_UNRESOLVED))
389
1/2
✗ Branch 125 → 126 not taken.
✓ Branch 125 → 281 taken 2 times.
2 sourceFile->checkForSoftErrors(); // We get into trouble if we continue without the field type -> abort
390
391 // Check for struct with infinite size.
392 // This can happen if the struct A has a field with type A
393
6/10
✓ Branch 126 → 127 taken 5302 times.
✗ Branch 126 → 281 not taken.
✓ Branch 127 → 128 taken 1841 times.
✓ Branch 127 → 131 taken 3461 times.
✓ Branch 128 → 129 taken 1841 times.
✗ Branch 128 → 281 not taken.
✗ Branch 129 → 130 not taken.
✓ Branch 129 → 131 taken 1841 times.
✗ Branch 132 → 133 not taken.
✓ Branch 132 → 141 taken 5302 times.
5302 if (fieldType.is(TY_STRUCT) && fieldType.getBodyScope() == node->structScope)
394 throw SemanticError(field, STRUCT_INFINITE_SIZE, "Struct with infinite size detected");
395
396 // Add to field types
397
1/2
✓ Branch 141 → 142 taken 5302 times.
✗ Branch 141 → 281 not taken.
5302 fieldTypes.push_back(fieldType);
398
399 // Update type of field entry
400
1/2
✓ Branch 142 → 143 taken 5302 times.
✗ Branch 142 → 281 not taken.
5302 SymbolTableEntry *fieldEntry = currentScope->lookupStrict(field->fieldName);
401
1/2
✗ Branch 145 → 146 not taken.
✓ Branch 145 → 147 taken 5302 times.
5302 assert(fieldEntry != nullptr);
402
1/2
✓ Branch 147 → 148 taken 5302 times.
✗ Branch 147 → 281 not taken.
5302 fieldEntry->updateType(fieldType, false);
403
404 // Check if the template type list contains this type
405
3/4
✓ Branch 148 → 149 taken 5302 times.
✗ Branch 148 → 281 not taken.
✓ Branch 149 → 150 taken 1 time.
✓ Branch 149 → 158 taken 5301 times.
5302 if (!fieldType.isCoveredByGenericTypeList(templateTypesGeneric))
406
2/4
✓ Branch 153 → 154 taken 1 time.
✗ Branch 153 → 275 not taken.
✓ Branch 154 → 155 taken 1 time.
✗ Branch 154 → 272 not taken.
3 throw SemanticError(field->dataType, GENERIC_TYPE_NOT_IN_TEMPLATE, "Generic field type not included in struct template");
407 }
408
409 // Change to the root scope
410 2804 currentScope = rootScope;
411
1/2
✗ Branch 168 → 169 not taken.
✓ Branch 168 → 170 taken 2804 times.
2804 assert(currentScope->type == ScopeType::GLOBAL);
412
413 // Build struct object
414
5/10
✓ Branch 170 → 171 taken 2804 times.
✗ Branch 170 → 294 not taken.
✓ Branch 171 → 172 taken 2804 times.
✗ Branch 171 → 291 not taken.
✓ Branch 172 → 173 taken 2804 times.
✗ Branch 172 → 288 not taken.
✓ Branch 173 → 174 taken 2804 times.
✗ Branch 173 → 285 not taken.
✓ Branch 174 → 175 taken 2804 times.
✗ Branch 174 → 283 not taken.
2804 Struct spiceStruct(node->structName, node->entry, node->structScope, fieldTypes, templateTypesGeneric, interfaceTypes, node);
415
1/2
✓ Branch 179 → 180 taken 2804 times.
✗ Branch 179 → 311 not taken.
2804 StructManager::insert(currentScope, spiceStruct, &node->structManifestations);
416 2804 spiceStruct.scope = node->structScope;
417
418 // Request RTTI runtime if the struct is polymorphic
419 2804 node->emitVTable |= node->hasInterfaces;
420
12/18
✓ Branch 180 → 181 taken 105 times.
✓ Branch 180 → 187 taken 2699 times.
✓ Branch 183 → 184 taken 105 times.
✗ Branch 183 → 295 not taken.
✓ Branch 184 → 185 taken 105 times.
✗ Branch 184 → 295 not taken.
✓ Branch 185 → 186 taken 104 times.
✓ Branch 185 → 187 taken 1 time.
✓ Branch 188 → 189 taken 105 times.
✓ Branch 188 → 190 taken 2699 times.
✓ Branch 190 → 191 taken 105 times.
✓ Branch 190 → 193 taken 2699 times.
✓ Branch 193 → 194 taken 104 times.
✓ Branch 193 → 201 taken 2700 times.
✗ Branch 295 → 296 not taken.
✗ Branch 295 → 297 not taken.
✗ Branch 299 → 300 not taken.
✗ Branch 299 → 302 not taken.
3014 if (node->attrs && node->attrs->attrLst->hasAttr(ATTR_CORE_COMPILER_EMIT_VTABLE))
421
2/4
✓ Branch 196 → 197 taken 104 times.
✗ Branch 196 → 306 not taken.
✓ Branch 197 → 198 taken 104 times.
✗ Branch 197 → 304 not taken.
312 node->emitVTable |= node->attrs->attrLst->getAttrValueByName(ATTR_CORE_COMPILER_EMIT_VTABLE)->boolValue;
422
7/8
✓ Branch 201 → 202 taken 477 times.
✓ Branch 201 → 207 taken 2327 times.
✓ Branch 202 → 203 taken 477 times.
✗ Branch 202 → 311 not taken.
✓ Branch 205 → 206 taken 374 times.
✓ Branch 205 → 207 taken 103 times.
✓ Branch 208 → 209 taken 374 times.
✓ Branch 208 → 210 taken 2430 times.
3281 if (node->emitVTable && !sourceFile->isRttiRT())
423
1/2
✓ Branch 209 → 210 taken 374 times.
✗ Branch 209 → 311 not taken.
374 sourceFile->requestRuntimeModule(RTTI_RT);
424
425
1/2
✓ Branch 210 → 211 taken 2804 times.
✗ Branch 210 → 310 not taken.
5608 return nullptr;
426 2819 }
427
428 363 std::any TypeChecker::visitInterfaceDefPrepare(InterfaceDefNode *node) {
429 363 QualTypeList usedTemplateTypes;
430 363 std::vector<GenericType> templateTypesGeneric;
431
432 // Retrieve interface template types
433
2/2
✓ Branch 2 → 3 taken 156 times.
✓ Branch 2 → 47 taken 207 times.
363 if (node->hasTemplateTypes) {
434
1/2
✓ Branch 4 → 5 taken 156 times.
✗ Branch 4 → 154 not taken.
156 usedTemplateTypes.reserve(node->templateTypeLst->dataTypes.size());
435
1/2
✓ Branch 6 → 7 taken 156 times.
✗ Branch 6 → 154 not taken.
156 templateTypesGeneric.reserve(node->templateTypeLst->dataTypes.size());
436
2/2
✓ Branch 45 → 9 taken 156 times.
✓ Branch 45 → 46 taken 156 times.
468 for (DataTypeNode *dataType : node->templateTypeLst->dataTypes) {
437 // Visit template type
438
2/4
✓ Branch 11 → 12 taken 156 times.
✗ Branch 11 → 123 not taken.
✓ Branch 12 → 13 taken 156 times.
✗ Branch 12 → 121 not taken.
156 auto templateType = std::any_cast<QualType>(visit(dataType));
439
2/6
✓ Branch 14 → 15 taken 156 times.
✗ Branch 14 → 131 not taken.
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 19 taken 156 times.
✗ Branch 16 → 17 not taken.
✗ Branch 16 → 124 not taken.
156 HANDLE_UNRESOLVED_TYPE_PTR(templateType)
440 // Check if it is a generic type
441
2/4
✓ Branch 19 → 20 taken 156 times.
✗ Branch 19 → 131 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 28 taken 156 times.
156 if (!templateType.is(TY_GENERIC)) {
442 softError(dataType, EXPECTED_GENERIC_TYPE, "A template list can only contain generic types");
443 continue;
444 }
445 // Convert generic symbol type to generic type
446
2/4
✓ Branch 28 → 29 taken 156 times.
✗ Branch 28 → 131 not taken.
✓ Branch 29 → 30 taken 156 times.
✗ Branch 29 → 131 not taken.
156 const GenericType *genericType = rootScope->lookupGenericTypeStrict(templateType.getSubType());
447
1/2
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 32 taken 156 times.
156 assert(genericType != nullptr);
448
1/2
✓ Branch 32 → 33 taken 156 times.
✗ Branch 32 → 131 not taken.
156 usedTemplateTypes.push_back(*genericType);
449
1/2
✓ Branch 33 → 34 taken 156 times.
✗ Branch 33 → 131 not taken.
156 templateTypesGeneric.push_back(*genericType);
450 }
451 }
452
453 // Update type of interface entry
454 363 const TypeChainElementData data = {.bodyScope = node->interfaceScope};
455
1/2
✓ Branch 47 → 48 taken 363 times.
✗ Branch 47 → 154 not taken.
363 const Type *type = TypeRegistry::getOrInsert(TY_INTERFACE, node->interfaceName, node->typeId, data, usedTemplateTypes);
456
1/2
✓ Branch 48 → 49 taken 363 times.
✗ Branch 48 → 154 not taken.
363 const QualType interfaceType(type, node->qualifiers);
457
1/2
✗ Branch 49 → 50 not taken.
✓ Branch 49 → 51 taken 363 times.
363 assert(node->entry != nullptr);
458 // If the entry was upgraded from a forward declaration, the existing type was already set to the opaque
459 // forward-decl type. Overwriting is expected here.
460 363 const bool overwrite = node->entry->forwardDeclCodeLoc != nullptr;
461
1/2
✓ Branch 51 → 52 taken 363 times.
✗ Branch 51 → 154 not taken.
363 node->entry->updateType(interfaceType, overwrite);
462
463 // Change to interface scope
464 363 currentScope = node->interfaceScope;
465
1/2
✗ Branch 52 → 53 not taken.
✓ Branch 52 → 54 taken 363 times.
363 assert(currentScope->type == ScopeType::INTERFACE);
466
467 // Visit methods
468 363 size_t vtableIndex = 0;
469 363 std::vector<Function *> methods;
470
1/2
✓ Branch 55 → 56 taken 363 times.
✗ Branch 55 → 152 not taken.
363 methods.reserve(node->signatures.size());
471
2/2
✓ Branch 97 → 58 taken 1330 times.
✓ Branch 97 → 98 taken 362 times.
2055 for (SignatureNode *signature : node->signatures) {
472
2/4
✓ Branch 60 → 61 taken 1330 times.
✗ Branch 60 → 135 not taken.
✓ Branch 61 → 62 taken 1330 times.
✗ Branch 61 → 133 not taken.
1330 const auto method = std::any_cast<std::vector<Function *> *>(visit(signature));
473
2/2
✓ Branch 63 → 64 taken 1 time.
✓ Branch 63 → 67 taken 1329 times.
1330 if (!method)
474
1/2
✓ Branch 64 → 65 taken 1 time.
✗ Branch 64 → 136 not taken.
2 return nullptr;
475
476 // Set 'this' type
477
2/2
✓ Branch 80 → 69 taken 1329 times.
✓ Branch 80 → 81 taken 1329 times.
3987 for (Function *m : *method) {
478 1329 m->isVirtual = true; // Interface methods are always virtual
479 1329 m->vtableIndex = vtableIndex;
480 1329 m->thisType = interfaceType;
481 }
482
483
1/2
✓ Branch 87 → 88 taken 1329 times.
✗ Branch 87 → 137 not taken.
2658 methods.insert(methods.end(), method->begin(), method->end());
484 1329 vtableIndex++;
485 }
486
487 // Change to root scope
488 362 currentScope = rootScope;
489
1/2
✗ Branch 98 → 99 not taken.
✓ Branch 98 → 100 taken 362 times.
362 assert(currentScope->type == ScopeType::GLOBAL);
490
491 // Build interface object
492
4/8
✓ Branch 100 → 101 taken 362 times.
✗ Branch 100 → 148 not taken.
✓ Branch 101 → 102 taken 362 times.
✗ Branch 101 → 145 not taken.
✓ Branch 102 → 103 taken 362 times.
✗ Branch 102 → 142 not taken.
✓ Branch 103 → 104 taken 362 times.
✗ Branch 103 → 140 not taken.
362 Interface spiceInterface(node->interfaceName, node->entry, node->interfaceScope, methods, templateTypesGeneric, node);
493
1/2
✓ Branch 107 → 108 taken 362 times.
✗ Branch 107 → 150 not taken.
362 InterfaceManager::insert(currentScope, spiceInterface, &node->interfaceManifestations);
494 362 spiceInterface.scope = node->interfaceScope;
495
496 // Request RTTI runtime, that is always required when dealing with interfaces due to polymorphism
497
2/4
✓ Branch 108 → 109 taken 362 times.
✗ Branch 108 → 150 not taken.
✓ Branch 111 → 112 taken 362 times.
✗ Branch 111 → 113 not taken.
724 if (!sourceFile->isRttiRT())
498
1/2
✓ Branch 112 → 113 taken 362 times.
✗ Branch 112 → 150 not taken.
362 sourceFile->requestRuntimeModule(RTTI_RT);
499
500
1/2
✓ Branch 113 → 114 taken 362 times.
✗ Branch 113 → 149 not taken.
362 return nullptr;
501 363 }
502
503 366 std::any TypeChecker::visitEnumDefPrepare(EnumDefNode *node) {
504 // Update type of enum entry
505 366 const TypeChainElementData data = {.bodyScope = node->enumScope};
506
1/2
✓ Branch 3 → 4 taken 366 times.
✗ Branch 3 → 86 not taken.
366 const Type *type = TypeRegistry::getOrInsert(TY_ENUM, node->enumName, node->typeId, data, {});
507
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 366 times.
366 assert(node->entry != nullptr);
508
2/4
✓ Branch 7 → 8 taken 366 times.
✗ Branch 7 → 89 not taken.
✓ Branch 8 → 9 taken 366 times.
✗ Branch 8 → 89 not taken.
366 node->entry->updateType(QualType(type, node->qualifiers), false);
509
510 // Change to enum scope
511 366 currentScope = node->enumScope;
512
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 366 times.
366 assert(currentScope->type == ScopeType::ENUM);
513
514 // Loop through all items with values
515 366 std::vector<std::string> names;
516 366 std::vector<uint32_t> values;
517
2/2
✓ Branch 43 → 13 taken 4901 times.
✓ Branch 43 → 44 taken 366 times.
5633 for (const EnumItemNode *enumItem : node->itemLst->items) {
518 // Save name
519
1/2
✓ Branch 15 → 16 taken 4901 times.
✗ Branch 15 → 98 not taken.
4901 names.push_back(enumItem->itemName);
520 // Check for duplicate value
521
2/2
✓ Branch 16 → 17 taken 2642 times.
✓ Branch 16 → 34 taken 2259 times.
4901 if (enumItem->hasValue) {
522
3/4
✓ Branch 18 → 19 taken 2642 times.
✗ Branch 18 → 90 not taken.
✓ Branch 25 → 26 taken 1 time.
✓ Branch 25 → 33 taken 2641 times.
5284 if (std::ranges::find(values, enumItem->itemValue) != values.end()) {
523
2/4
✓ Branch 28 → 29 taken 1 time.
✗ Branch 28 → 94 not taken.
✓ Branch 29 → 30 taken 1 time.
✗ Branch 29 → 92 not taken.
1 softError(enumItem, DUPLICATE_ENUM_ITEM_VALUE, "Duplicate enum item value, please use another");
524 1 continue;
525 }
526
1/2
✓ Branch 33 → 34 taken 2641 times.
✗ Branch 33 → 98 not taken.
2641 values.push_back(enumItem->itemValue);
527 }
528 }
529
530 // Loop through all items without values
531 366 uint32_t nextValue = 0;
532
1/2
✓ Branch 44 → 45 taken 366 times.
✗ Branch 44 → 103 not taken.
366 const QualType intSymbolType(TY_INT);
533
2/2
✓ Branch 77 → 47 taken 4901 times.
✓ Branch 77 → 78 taken 366 times.
5633 for (EnumItemNode *enumItem : node->itemLst->items) {
534 // Update type of enum item entry
535
1/2
✓ Branch 49 → 50 taken 4901 times.
✗ Branch 49 → 101 not taken.
4901 SymbolTableEntry *itemEntry = currentScope->lookupStrict(enumItem->itemName);
536
1/2
✗ Branch 52 → 53 not taken.
✓ Branch 52 → 54 taken 4901 times.
4901 assert(itemEntry != nullptr);
537
1/2
✓ Branch 54 → 55 taken 4901 times.
✗ Branch 54 → 101 not taken.
4901 itemEntry->updateType(intSymbolType, false);
538 // Fill in value if not filled yet
539
2/2
✓ Branch 55 → 56 taken 2259 times.
✓ Branch 55 → 68 taken 2642 times.
4901 if (!enumItem->hasValue) {
540
3/4
✓ Branch 59 → 60 taken 4298 times.
✗ Branch 59 → 99 not taken.
✓ Branch 66 → 57 taken 2039 times.
✓ Branch 66 → 67 taken 2259 times.
8596 while (std::ranges::find(values, nextValue) != values.end())
541 2039 nextValue++;
542 2259 enumItem->itemValue = nextValue;
543
1/2
✓ Branch 67 → 68 taken 2259 times.
✗ Branch 67 → 101 not taken.
2259 values.push_back(nextValue);
544 }
545 }
546
547 // Change to root scope
548 366 currentScope = rootScope;
549
1/2
✗ Branch 78 → 79 not taken.
✓ Branch 78 → 80 taken 366 times.
366 assert(currentScope->type == ScopeType::GLOBAL);
550
551
1/2
✓ Branch 80 → 81 taken 366 times.
✗ Branch 80 → 102 not taken.
732 return nullptr;
552 366 }
553
554 1927 std::any TypeChecker::visitGenericTypeDefPrepare(GenericTypeDefNode *node) {
555 // Retrieve type conditions
556 1927 QualTypeList typeConditions;
557
1/2
✓ Branch 3 → 4 taken 1927 times.
✗ Branch 3 → 70 not taken.
1927 typeConditions.reserve(node->typeAltsLst->dataTypes.size());
558
2/2
✓ Branch 26 → 6 taken 3460 times.
✓ Branch 26 → 27 taken 1927 times.
7314 for (const auto &typeAlt : node->typeAltsLst->dataTypes) {
559
2/4
✓ Branch 8 → 9 taken 3460 times.
✗ Branch 8 → 58 not taken.
✓ Branch 9 → 10 taken 3460 times.
✗ Branch 9 → 56 not taken.
3460 auto typeCondition = std::any_cast<QualType>(visit(typeAlt));
560
2/6
✓ Branch 11 → 12 taken 3460 times.
✗ Branch 11 → 60 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 16 taken 3460 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 59 not taken.
3460 HANDLE_UNRESOLVED_TYPE_PTR(typeCondition)
561
1/2
✓ Branch 16 → 17 taken 3460 times.
✗ Branch 16 → 60 not taken.
3460 typeConditions.push_back(typeCondition);
562 }
563
564 // Add generic type to the scope
565
2/4
✓ Branch 27 → 28 taken 1927 times.
✗ Branch 27 → 64 not taken.
✓ Branch 28 → 29 taken 1927 times.
✗ Branch 28 → 62 not taken.
1927 const GenericType genericType(node->typeName, typeConditions);
566
1/2
✓ Branch 30 → 31 taken 1927 times.
✗ Branch 30 → 68 not taken.
1927 rootScope->insertGenericType(node->typeName, genericType);
567
568 // Check if only one type condition is set
569
7/8
✓ Branch 32 → 33 taken 875 times.
✓ Branch 32 → 37 taken 1052 times.
✓ Branch 34 → 35 taken 875 times.
✗ Branch 34 → 68 not taken.
✓ Branch 35 → 36 taken 1 time.
✓ Branch 35 → 37 taken 874 times.
✓ Branch 38 → 39 taken 1 time.
✓ Branch 38 → 41 taken 1926 times.
1927 if (typeConditions.size() == 1 && !typeConditions.front().is(TY_DYN))
570
1/2
✓ Branch 39 → 40 taken 1 time.
✗ Branch 39 → 65 not taken.
1 sourceFile->compilerOutput.warnings.emplace_back(node->typeAltsLst->codeLoc, SINGLE_GENERIC_TYPE_CONDITION,
571 "Generic type is locked to one type");
572
573 // Check if the list contains the dyn type, along with other types
574
1/2
✓ Branch 41 → 42 taken 1927 times.
✗ Branch 41 → 68 not taken.
5385 const bool containsDynType = std::ranges::any_of(typeConditions, [&](const QualType &type) { return type.is(TY_DYN); });
575
6/6
✓ Branch 42 → 43 taken 876 times.
✓ Branch 42 → 46 taken 1051 times.
✓ Branch 44 → 45 taken 2 times.
✓ Branch 44 → 46 taken 874 times.
✓ Branch 47 → 48 taken 2 times.
✓ Branch 47 → 50 taken 1925 times.
1927 if (containsDynType && typeConditions.size() > 1)
576 2 sourceFile->compilerOutput.warnings.emplace_back(
577
1/2
✓ Branch 48 → 49 taken 2 times.
✗ Branch 48 → 66 not taken.
2 node->typeAltsLst->codeLoc, INEFFECTIVE_GENERIC_TYPE_CONDITION,
578 "One or several type conditions are superfluous, because the dyn type condition is given");
579
580
1/2
✓ Branch 50 → 51 taken 1927 times.
✗ Branch 50 → 67 not taken.
1927 return nullptr;
581 1927 }
582
583 340 std::any TypeChecker::visitAliasDefPrepare(AliasDefNode *node) {
584
2/4
✓ Branch 2 → 3 taken 340 times.
✗ Branch 2 → 5 not taken.
✓ Branch 3 → 4 taken 340 times.
✗ Branch 3 → 5 not taken.
340 assert(node->entry != nullptr && node->aliasedTypeContainerEntry != nullptr);
585
586 // Update type of alias entry
587
1/2
✓ Branch 7 → 8 taken 340 times.
✗ Branch 7 → 25 not taken.
340 const Type *type = TypeRegistry::getOrInsert(TY_ALIAS, node->aliasName, node->typeId, {}, {});
588
2/4
✓ Branch 9 → 10 taken 340 times.
✗ Branch 9 → 29 not taken.
✓ Branch 10 → 11 taken 340 times.
✗ Branch 10 → 29 not taken.
340 node->entry->updateType(QualType(type, node->qualifiers), false);
589
590 // Update type of the aliased type container entry
591
2/4
✓ Branch 11 → 12 taken 340 times.
✗ Branch 11 → 32 not taken.
✓ Branch 12 → 13 taken 340 times.
✗ Branch 12 → 30 not taken.
340 const auto aliasedType = std::any_cast<QualType>(visit(node->dataType));
592
4/6
✓ Branch 14 → 15 taken 340 times.
✗ Branch 14 → 35 not taken.
✓ Branch 15 → 16 taken 1 time.
✓ Branch 15 → 19 taken 339 times.
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 33 not taken.
341 HANDLE_UNRESOLVED_TYPE_PTR(aliasedType)
593
1/2
✓ Branch 19 → 20 taken 339 times.
✗ Branch 19 → 35 not taken.
339 node->aliasedTypeContainerEntry->updateType(aliasedType, false);
594 339 node->aliasedTypeContainerEntry->used = true; // The container type is always used per default
595
596
1/2
✓ Branch 20 → 21 taken 339 times.
✗ Branch 20 → 34 not taken.
678 return nullptr;
597 }
598
599 2375 std::any TypeChecker::visitGlobalVarDefPrepare(GlobalVarDefNode *node) {
600 // Insert variable name to symbol table
601
2/4
✓ Branch 2 → 3 taken 2375 times.
✗ Branch 2 → 87 not taken.
✓ Branch 3 → 4 taken 2375 times.
✗ Branch 3 → 85 not taken.
2375 auto globalVarType = std::any_cast<QualType>(visit(node->dataType));
602
2/6
✓ Branch 5 → 6 taken 2375 times.
✗ Branch 5 → 133 not taken.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 10 taken 2375 times.
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 88 not taken.
2375 HANDLE_UNRESOLVED_TYPE_PTR(globalVarType)
603
604
2/2
✓ Branch 10 → 11 taken 2373 times.
✓ Branch 10 → 40 taken 2 times.
2375 if (node->constant) { // Variable is initialized here
605
2/4
✓ Branch 11 → 12 taken 2373 times.
✗ Branch 11 → 91 not taken.
✓ Branch 12 → 13 taken 2373 times.
✗ Branch 12 → 89 not taken.
2373 const QualType rhsType = std::any_cast<ExprResult>(visit(node->constant)).type;
606
2/6
✓ Branch 14 → 15 taken 2373 times.
✗ Branch 14 → 110 not taken.
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 19 taken 2373 times.
✗ Branch 16 → 17 not taken.
✗ Branch 16 → 93 not taken.
2373 HANDLE_UNRESOLVED_TYPE_PTR(rhsType)
607
3/4
✓ Branch 19 → 20 taken 2373 times.
✗ Branch 19 → 110 not taken.
✓ Branch 20 → 21 taken 1 time.
✓ Branch 20 → 22 taken 2372 times.
2373 if (globalVarType.is(TY_DYN)) { // Perform type inference
608 1 globalVarType = rhsType;
609
3/4
✓ Branch 22 → 23 taken 2372 times.
✗ Branch 22 → 110 not taken.
✓ Branch 23 → 24 taken 2 times.
✓ Branch 23 → 38 taken 2370 times.
2372 } else if (!globalVarType.matches(rhsType, false, true, true)) { // Check if types are matching
610
7/14
✓ Branch 24 → 25 taken 2 times.
✗ Branch 24 → 107 not taken.
✓ Branch 25 → 26 taken 2 times.
✗ Branch 25 → 102 not taken.
✓ Branch 26 → 27 taken 2 times.
✗ Branch 26 → 100 not taken.
✓ Branch 27 → 28 taken 2 times.
✗ Branch 27 → 98 not taken.
✓ Branch 28 → 29 taken 2 times.
✗ Branch 28 → 96 not taken.
✓ Branch 29 → 30 taken 2 times.
✗ Branch 29 → 94 not taken.
✓ Branch 35 → 36 taken 2 times.
✗ Branch 35 → 109 not taken.
4 SOFT_ERROR_BOOL(node->constant, OPERATOR_WRONG_DATA_TYPE,
611 "Expected " + globalVarType.getName(false) + ", but got " + rhsType.getName(false))
612 }
613 }
614
615 // Check if the type is still missing
616
3/4
✓ Branch 40 → 41 taken 2373 times.
✗ Branch 40 → 133 not taken.
✓ Branch 41 → 42 taken 1 time.
✓ Branch 41 → 51 taken 2372 times.
2373 if (globalVarType.is(TY_DYN))
617
3/6
✓ Branch 44 → 45 taken 1 time.
✗ Branch 44 → 113 not taken.
✓ Branch 45 → 46 taken 1 time.
✗ Branch 45 → 111 not taken.
✓ Branch 48 → 49 taken 1 time.
✗ Branch 48 → 117 not taken.
4 SOFT_ERROR_BOOL(node->dataType, GLOBAL_OF_TYPE_DYN, "Global variables must have an explicit data type")
618
619 // Check if we would need to insert instructions in the global scope to initialize the variable
620
2/4
✓ Branch 51 → 52 taken 2372 times.
✗ Branch 51 → 133 not taken.
✗ Branch 52 → 53 not taken.
✓ Branch 52 → 62 taken 2372 times.
2372 if (!globalVarType.isPrimitive())
621 SOFT_ERROR_BOOL(node->dataType, GLOBAL_OF_INVALID_TYPE, "Spice does only support global variables of primitive type")
622
623 // Update type of global var entry
624
1/2
✗ Branch 62 → 63 not taken.
✓ Branch 62 → 64 taken 2372 times.
2372 assert(node->entry != nullptr);
625
1/2
✓ Branch 64 → 65 taken 2372 times.
✗ Branch 64 → 133 not taken.
2372 node->entry->updateType(globalVarType, false);
626
627 // Check if a value is attached
628
6/8
✓ Branch 65 → 66 taken 1 time.
✓ Branch 65 → 69 taken 2371 times.
✓ Branch 66 → 67 taken 1 time.
✗ Branch 66 → 133 not taken.
✓ Branch 67 → 68 taken 1 time.
✗ Branch 67 → 69 not taken.
✓ Branch 70 → 71 taken 1 time.
✓ Branch 70 → 80 taken 2371 times.
2372 if (!node->constant && globalVarType.isConst())
629
3/6
✓ Branch 73 → 74 taken 1 time.
✗ Branch 73 → 127 not taken.
✓ Branch 74 → 75 taken 1 time.
✗ Branch 74 → 125 not taken.
✓ Branch 77 → 78 taken 1 time.
✗ Branch 77 → 131 not taken.
4 SOFT_ERROR_BOOL(node, GLOBAL_CONST_WITHOUT_VALUE, "You must specify a value for constant global variables")
630
631
1/2
✓ Branch 80 → 81 taken 2371 times.
✗ Branch 80 → 132 not taken.
4742 return nullptr;
632 }
633
634 2961 std::any TypeChecker::visitExtDeclPrepare(ExtDeclNode *node) {
635 // Collect argument types
636 2961 QualTypeList argTypes;
637 2961 ParamList argList;
638
2/2
✓ Branch 2 → 3 taken 2754 times.
✓ Branch 2 → 41 taken 207 times.
2961 if (node->hasArgs) {
639
1/2
✓ Branch 4 → 5 taken 2754 times.
✗ Branch 4 → 168 not taken.
2754 argList.reserve(node->argTypeLst->typeLst->dataTypes.size());
640
2/2
✓ Branch 39 → 7 taken 6108 times.
✓ Branch 39 → 40 taken 2754 times.
11616 for (DataTypeNode *arg : node->argTypeLst->typeLst->dataTypes) {
641 // Visit argument
642
2/4
✓ Branch 9 → 10 taken 6108 times.
✗ Branch 9 → 113 not taken.
✓ Branch 10 → 11 taken 6108 times.
✗ Branch 10 → 111 not taken.
6108 auto argType = std::any_cast<QualType>(visit(arg));
643
2/6
✓ Branch 12 → 13 taken 6108 times.
✗ Branch 12 → 122 not taken.
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 17 taken 6108 times.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 114 not taken.
6108 HANDLE_UNRESOLVED_TYPE_PTR(argType)
644 // Check if the argument type is 'dyn'
645
3/4
✓ Branch 17 → 18 taken 6108 times.
✗ Branch 17 → 122 not taken.
✓ Branch 18 → 19 taken 1 time.
✓ Branch 18 → 26 taken 6107 times.
6108 if (argType.is(TY_DYN)) {
646
2/4
✓ Branch 21 → 22 taken 1 time.
✗ Branch 21 → 117 not taken.
✓ Branch 22 → 23 taken 1 time.
✗ Branch 22 → 115 not taken.
1 softError(arg, UNEXPECTED_DYN_TYPE, "Dyn data type is not allowed as arg type for external functions");
647 1 continue;
648 }
649 // Save argument
650
1/2
✓ Branch 26 → 27 taken 6107 times.
✗ Branch 26 → 122 not taken.
6107 argTypes.push_back(argType);
651
1/2
✓ Branch 27 → 28 taken 6107 times.
✗ Branch 27 → 121 not taken.
6107 argList.push_back({argType, false});
652 }
653 }
654
655 // Retrieve return type
656
1/2
✓ Branch 41 → 42 taken 2961 times.
✗ Branch 41 → 168 not taken.
2961 QualType returnType(TY_DYN);
657 2961 const bool isFunction = node->returnType;
658
2/2
✓ Branch 42 → 43 taken 1965 times.
✓ Branch 42 → 62 taken 996 times.
2961 if (isFunction) { // External function
659
2/4
✓ Branch 43 → 44 taken 1965 times.
✗ Branch 43 → 126 not taken.
✓ Branch 44 → 45 taken 1965 times.
✗ Branch 44 → 124 not taken.
1965 returnType = std::any_cast<QualType>(visit(node->returnType));
660
2/6
✓ Branch 46 → 47 taken 1965 times.
✗ Branch 46 → 168 not taken.
✗ Branch 47 → 48 not taken.
✓ Branch 47 → 51 taken 1965 times.
✗ Branch 48 → 49 not taken.
✗ Branch 48 → 128 not taken.
1965 HANDLE_UNRESOLVED_TYPE_PTR(returnType)
661 // Check if return type is dyn
662
3/4
✓ Branch 51 → 52 taken 1965 times.
✗ Branch 51 → 168 not taken.
✓ Branch 52 → 53 taken 1 time.
✓ Branch 52 → 62 taken 1964 times.
1965 if (returnType.is(TY_DYN))
663
3/6
✓ Branch 55 → 56 taken 1 time.
✗ Branch 55 → 131 not taken.
✓ Branch 56 → 57 taken 1 time.
✗ Branch 56 → 129 not taken.
✓ Branch 59 → 60 taken 1 time.
✗ Branch 59 → 135 not taken.
4 SOFT_ERROR_BOOL(node->returnType, UNEXPECTED_DYN_TYPE, "dyn is not allowed as return type for external functions")
664 }
665
666 // Add function to current scope
667
4/8
✓ Branch 63 → 64 taken 2960 times.
✗ Branch 63 → 142 not taken.
✓ Branch 64 → 65 taken 2960 times.
✗ Branch 64 → 139 not taken.
✓ Branch 65 → 66 taken 2960 times.
✗ Branch 65 → 138 not taken.
✓ Branch 66 → 67 taken 2960 times.
✗ Branch 66 → 136 not taken.
2960 const Function spiceFunc(node->extFunctionName, node->entry, QualType(TY_DYN), returnType, argList, {}, node);
668
1/2
✓ Branch 70 → 71 taken 2960 times.
✗ Branch 70 → 166 not taken.
2960 node->extFunction = FunctionManager::insert(currentScope, spiceFunc, &node->extFunctionManifestations);
669 2960 node->extFunction->mangleFunctionName = false;
670 2960 node->extFunction->alreadyTypeChecked = true;
671
4/4
✓ Branch 71 → 72 taken 2754 times.
✓ Branch 71 → 74 taken 206 times.
✓ Branch 72 → 73 taken 58 times.
✓ Branch 72 → 74 taken 2696 times.
2960 node->extFunction->isVararg = node->argTypeLst && node->argTypeLst->hasEllipsis;
672
673 // Check procedure attributes
674
2/2
✓ Branch 75 → 76 taken 1 time.
✓ Branch 75 → 93 taken 2959 times.
2960 if (node->attrs) {
675 1 const AttrLstNode *attrLst = node->attrs->attrLst;
676
3/6
✓ Branch 78 → 79 taken 1 time.
✗ Branch 78 → 148 not taken.
✓ Branch 79 → 80 taken 1 time.
✗ Branch 79 → 146 not taken.
✗ Branch 82 → 83 not taken.
✓ Branch 82 → 84 taken 1 time.
3 if (const CompileTimeValue *value = attrLst->getAttrValueByName(ATTR_CORE_COMPILER_MANGLE))
677 node->extFunction->mangleFunctionName = value->boolValue;
678
3/6
✓ Branch 86 → 87 taken 1 time.
✗ Branch 86 → 154 not taken.
✓ Branch 87 → 88 taken 1 time.
✗ Branch 87 → 152 not taken.
✓ Branch 90 → 91 taken 1 time.
✗ Branch 90 → 93 not taken.
3 if (const CompileTimeValue *value = attrLst->getAttrValueByName(ATTR_CORE_COMPILER_MANGLED_NAME)) {
679
1/2
✓ Branch 91 → 92 taken 1 time.
✗ Branch 91 → 166 not taken.
1 const std::string &stringValue = resourceManager.compileTimeStringValues.at(value->stringValueOffset);
680
1/2
✓ Branch 92 → 93 taken 1 time.
✗ Branch 92 → 166 not taken.
1 node->extFunction->predefinedMangledName = stringValue;
681 }
682 }
683
684 // Prepare ext function type
685
2/2
✓ Branch 93 → 94 taken 1964 times.
✓ Branch 93 → 95 taken 996 times.
2960 const SuperType superType = isFunction ? TY_FUNCTION : TY_PROCEDURE;
686
2/4
✓ Branch 96 → 97 taken 2960 times.
✗ Branch 96 → 158 not taken.
✓ Branch 97 → 98 taken 2960 times.
✗ Branch 97 → 158 not taken.
2960 const QualType extFunctionType = QualType(superType).getWithFunctionParamAndReturnTypes(returnType, argTypes);
687
688 // Set type of external function
689
1/2
✓ Branch 98 → 99 taken 2960 times.
✗ Branch 98 → 166 not taken.
2960 node->entry->updateType(extFunctionType, false);
690
691 // Rename the original child scope to reflect the substantiated versions of the external function
692
3/6
✓ Branch 99 → 100 taken 2960 times.
✗ Branch 99 → 164 not taken.
✓ Branch 100 → 101 taken 2960 times.
✗ Branch 100 → 161 not taken.
✓ Branch 101 → 102 taken 2960 times.
✗ Branch 101 → 159 not taken.
2960 currentScope->renameChildScope(node->getScopeId(), spiceFunc.getScopeName());
693
694
1/2
✓ Branch 104 → 105 taken 2960 times.
✗ Branch 104 → 165 not taken.
2960 return nullptr;
695 2961 }
696
697 2532 std::any TypeChecker::visitImportDefPrepare(ImportDefNode *node) {
698 // Set entry to import type
699
1/2
✓ Branch 2 → 3 taken 2532 times.
✗ Branch 2 → 11 not taken.
2532 const QualType importType(TY_IMPORT, node->importName);
700
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 2532 times.
2532 assert(node->entry != nullptr);
701
1/2
✓ Branch 5 → 6 taken 2532 times.
✗ Branch 5 → 11 not taken.
2532 node->entry->updateType(importType, false);
702
703
1/2
✓ Branch 6 → 7 taken 2532 times.
✗ Branch 6 → 10 not taken.
5064 return nullptr;
704 }
705
706 } // namespace spice::compiler
707