GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 94.5% 392 / 0 / 415
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 402 std::any TypeChecker::visitMainFctDefPrepare(MainFctDefNode *node) {
21 // Mark unreachable statements
22 402 bool returnsOnAllControlPaths = true;
23
1/2
✓ Branch 2 → 3 taken 402 times.
✗ Branch 2 → 68 not taken.
402 node->returnsOnAllControlPaths(&returnsOnAllControlPaths, manIdx);
24
25 // Retrieve return type
26
1/2
✓ Branch 3 → 4 taken 402 times.
✗ Branch 3 → 68 not taken.
402 const QualType returnType(TY_INT);
27
28 // Change to function body scope
29 402 currentScope = node->bodyScope;
30
31 // Set type of 'result' variable to int
32
1/2
✓ Branch 6 → 7 taken 402 times.
✗ Branch 6 → 47 not taken.
1206 SymbolTableEntry *resultEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME);
33
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 402 times.
402 assert(resultEntry != nullptr);
34
1/2
✓ Branch 14 → 15 taken 402 times.
✗ Branch 14 → 68 not taken.
402 resultEntry->updateType(returnType, false);
35 402 resultEntry->used = true;
36
37 // Retrieve param types
38 402 QualTypeList paramTypes;
39
2/2
✓ Branch 15 → 16 taken 4 times.
✓ Branch 15 → 28 taken 398 times.
402 if (node->takesArgs) {
40
2/4
✓ Branch 16 → 17 taken 4 times.
✗ Branch 16 → 53 not taken.
✓ Branch 17 → 18 taken 4 times.
✗ Branch 17 → 51 not taken.
4 auto namedParamList = std::any_cast<NamedParamList>(visit(node->paramLst));
41
2/2
✓ Branch 25 → 21 taken 8 times.
✓ Branch 25 → 26 taken 4 times.
12 for (const auto &[name, qualType, isOptional] : namedParamList)
42
1/2
✓ Branch 22 → 23 taken 8 times.
✗ Branch 22 → 54 not taken.
8 paramTypes.push_back(qualType);
43 4 }
44
45 // Prepare type of function
46
2/4
✓ Branch 28 → 29 taken 402 times.
✗ Branch 28 → 58 not taken.
✓ Branch 29 → 30 taken 402 times.
✗ Branch 29 → 58 not taken.
402 const QualType functionType = QualType(TY_FUNCTION).getWithFunctionParamAndReturnTypes(returnType, paramTypes);
47
48 // Update main function symbol type
49
1/2
✓ Branch 32 → 33 taken 402 times.
✗ Branch 32 → 61 not taken.
1206 SymbolTableEntry *functionEntry = rootScope->lookupStrict(MAIN_FUNCTION_NAME);
50
1/2
✗ Branch 38 → 39 not taken.
✓ Branch 38 → 40 taken 402 times.
402 assert(functionEntry != nullptr);
51
1/2
✓ Branch 40 → 41 taken 402 times.
✗ Branch 40 → 66 not taken.
402 functionEntry->updateType(functionType, false);
52 402 functionEntry->used = true;
53
54 // Leave main function body scope
55 402 currentScope = rootScope;
56
57
1/2
✓ Branch 41 → 42 taken 402 times.
✗ Branch 41 → 65 not taken.
804 return nullptr;
58 402 }
59
60 8181 std::any TypeChecker::visitFctDefPrepare(FctDefNode *node) {
61 // Check if name is dtor
62
3/4
✓ Branch 2 → 3 taken 8181 times.
✗ Branch 2 → 391 not taken.
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 12 taken 8180 times.
8181 if (node->name->name == DTOR_FUNCTION_NAME)
63
3/6
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 248 not taken.
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 246 not taken.
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 252 not taken.
3 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 8180 bool doSetPredecessorsUnreachable = true;
67
3/4
✓ Branch 12 → 13 taken 8180 times.
✗ Branch 12 → 391 not taken.
✓ Branch 13 → 14 taken 1 time.
✓ Branch 13 → 22 taken 8179 times.
8180 if (!node->returnsOnAllControlPaths(&doSetPredecessorsUnreachable, manIdx))
68
3/6
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 255 not taken.
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 253 not taken.
✓ Branch 20 → 21 taken 1 time.
✗ Branch 20 → 259 not taken.
3 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 8179 currentScope = node->scope;
72
1/2
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 8179 times.
8179 assert(currentScope->type == ScopeType::FUNC_PROC_BODY);
73
74 // Retrieve function template types
75 8179 std::vector<GenericType> usedGenericTypes;
76
2/2
✓ Branch 24 → 25 taken 1094 times.
✓ Branch 24 → 54 taken 7085 times.
8179 if (node->hasTemplateTypes) {
77
2/2
✓ Branch 52 → 27 taken 1306 times.
✓ Branch 52 → 53 taken 1093 times.
2399 for (DataTypeNode *dataType : node->templateTypeLst->dataTypes) {
78 // Visit template type
79
2/4
✓ Branch 28 → 29 taken 1306 times.
✗ Branch 28 → 262 not taken.
✓ Branch 29 → 30 taken 1306 times.
✗ Branch 29 → 260 not taken.
1306 auto templateType = std::any_cast<QualType>(visit(dataType));
80
2/4
✓ Branch 31 → 32 taken 1306 times.
✗ Branch 31 → 272 not taken.
✗ Branch 32 → 33 not taken.
✓ Branch 32 → 34 taken 1306 times.
1306 if (templateType.is(TY_UNRESOLVED))
81 continue;
82 // Check if it is a generic type
83
3/4
✓ Branch 34 → 35 taken 1306 times.
✗ Branch 34 → 272 not taken.
✓ Branch 35 → 36 taken 1 time.
✓ Branch 35 → 44 taken 1305 times.
1306 if (!templateType.is(TY_GENERIC))
84
2/4
✓ Branch 39 → 40 taken 1 time.
✗ Branch 39 → 266 not taken.
✓ Branch 40 → 41 taken 1 time.
✗ Branch 40 → 263 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 44 → 45 taken 1305 times.
✗ Branch 44 → 272 not taken.
✓ Branch 45 → 46 taken 1305 times.
✗ Branch 45 → 272 not taken.
1305 GenericType *genericType = rootScope->lookupGenericTypeStrict(templateType.getSubType());
87
1/2
✗ Branch 46 → 47 not taken.
✓ Branch 46 → 48 taken 1305 times.
1305 assert(genericType != nullptr);
88
1/2
✓ Branch 48 → 49 taken 1305 times.
✗ Branch 48 → 272 not taken.
1305 usedGenericTypes.push_back(*genericType);
89 }
90 }
91
92 // Retrieve 'this' type
93
1/2
✓ Branch 54 → 55 taken 8178 times.
✗ Branch 54 → 389 not taken.
8178 QualType thisType(TY_DYN); // If the function is not a method, the default this type is TY_DYN
94
2/2
✓ Branch 55 → 56 taken 3285 times.
✓ Branch 55 → 86 taken 4893 times.
8178 if (node->isMethod) {
95 3285 Scope *structParentScope = node->structScope->parent;
96
1/2
✓ Branch 56 → 57 taken 3285 times.
✗ Branch 56 → 282 not taken.
3285 SymbolTableEntry *structEntry = structParentScope->lookupStrict(node->name->structName);
97
1/2
✗ Branch 59 → 60 not taken.
✓ Branch 59 → 61 taken 3285 times.
3285 assert(structEntry != nullptr);
98 // Set struct to used
99 3285 structEntry->used = true;
100 // Get type and ptr type
101
1/2
✓ Branch 61 → 62 taken 3285 times.
✗ Branch 61 → 282 not taken.
3285 thisType = structEntry->getQualType();
102
1/2
✓ Branch 62 → 63 taken 3285 times.
✗ Branch 62 → 282 not taken.
3285 const QualType thisPtrType = thisType.toPtr(node);
103 // Collect template types of 'this' type
104
3/4
✓ Branch 63 → 64 taken 3285 times.
✗ Branch 63 → 275 not taken.
✓ Branch 73 → 66 taken 1292 times.
✓ Branch 73 → 74 taken 3285 times.
4577 for (const QualType &templateType : thisType.getTemplateTypes()) {
105 300 const auto lambda = [&](const GenericType &genericType) { return genericType == templateType; };
106
3/4
✓ Branch 67 → 68 taken 1292 times.
✗ Branch 67 → 274 not taken.
✓ Branch 68 → 69 taken 1288 times.
✓ Branch 68 → 70 taken 4 times.
1292 if (std::ranges::none_of(usedGenericTypes, lambda))
107
1/2
✓ Branch 69 → 70 taken 1288 times.
✗ Branch 69 → 274 not taken.
1288 usedGenericTypes.emplace_back(templateType);
108 1292 usedGenericTypes.back().used = true;
109 }
110
111 // Set type of 'this' variable
112
1/2
✓ Branch 76 → 77 taken 3285 times.
✗ Branch 76 → 278 not taken.
9855 SymbolTableEntry *thisEntry = currentScope->lookupStrict(THIS_VARIABLE_NAME);
113
1/2
✗ Branch 82 → 83 not taken.
✓ Branch 82 → 84 taken 3285 times.
3285 assert(thisEntry != nullptr);
114
1/2
✓ Branch 84 → 85 taken 3285 times.
✗ Branch 84 → 282 not taken.
3285 thisEntry->updateType(thisPtrType, false);
115 }
116
117 // Visit parameters
118 8178 QualTypeList paramTypes;
119 8178 ParamList paramList;
120
2/2
✓ Branch 86 → 87 taken 6320 times.
✓ Branch 86 → 123 taken 1858 times.
8178 if (node->hasParams) {
121 6320 std::vector<const char *> paramNames;
122 // Visit param list to retrieve the param names
123
2/4
✓ Branch 87 → 88 taken 6320 times.
✗ Branch 87 → 285 not taken.
✓ Branch 88 → 89 taken 6320 times.
✗ Branch 88 → 283 not taken.
6320 auto namedParamList = std::any_cast<NamedParamList>(visit(node->paramLst));
124
2/2
✓ Branch 112 → 92 taken 10023 times.
✓ Branch 112 → 113 taken 6318 times.
16341 for (const auto &[name, qualType, isOptional] : namedParamList) {
125
1/2
✓ Branch 93 → 94 taken 10023 times.
✗ Branch 93 → 297 not taken.
10023 paramNames.push_back(name);
126
2/6
✓ Branch 94 → 95 taken 10023 times.
✗ Branch 94 → 297 not taken.
✗ Branch 95 → 96 not taken.
✓ Branch 95 → 98 taken 10023 times.
✗ Branch 96 → 97 not taken.
✗ Branch 96 → 286 not taken.
10023 HANDLE_UNRESOLVED_TYPE_PTR(qualType);
127
1/2
✓ Branch 98 → 99 taken 10023 times.
✗ Branch 98 → 297 not taken.
10023 paramTypes.push_back(qualType);
128
1/2
✓ Branch 99 → 100 taken 10023 times.
✗ Branch 99 → 287 not taken.
10023 paramList.push_back({qualType, isOptional});
129 // Check if the type is present in the template for generic types
130
3/4
✓ Branch 100 → 101 taken 10023 times.
✗ Branch 100 → 297 not taken.
✓ Branch 101 → 102 taken 2 times.
✓ Branch 101 → 110 taken 10021 times.
10023 if (!qualType.isCoveredByGenericTypeList(usedGenericTypes))
131 throw SemanticError(node->paramLst, GENERIC_TYPE_NOT_IN_TEMPLATE,
132
2/4
✓ Branch 105 → 106 taken 2 times.
✗ Branch 105 → 291 not taken.
✓ Branch 106 → 107 taken 2 times.
✗ Branch 106 → 288 not taken.
6 "Generic param type not included in the template type list of the function");
133 }
134
2/4
✓ Branch 115 → 116 taken 6318 times.
✗ Branch 115 → 117 not taken.
✓ Branch 119 → 120 taken 6318 times.
✗ Branch 119 → 122 not taken.
6322 }
135
136 // Retrieve return type
137
2/4
✓ Branch 123 → 124 taken 8176 times.
✗ Branch 123 → 305 not taken.
✓ Branch 124 → 125 taken 8176 times.
✗ Branch 124 → 303 not taken.
8176 auto returnType = std::any_cast<QualType>(visit(node->returnType));
138
2/6
✓ Branch 126 → 127 taken 8176 times.
✗ Branch 126 → 385 not taken.
✗ Branch 127 → 128 not taken.
✓ Branch 127 → 130 taken 8176 times.
✗ Branch 128 → 129 not taken.
✗ Branch 128 → 306 not taken.
8176 HANDLE_UNRESOLVED_TYPE_PTR(returnType)
139
3/4
✓ Branch 130 → 131 taken 8176 times.
✗ Branch 130 → 385 not taken.
✓ Branch 131 → 132 taken 1 time.
✓ Branch 131 → 140 taken 8175 times.
8176 if (returnType.is(TY_DYN))
140
3/6
✓ Branch 134 → 135 taken 1 time.
✗ Branch 134 → 309 not taken.
✓ Branch 135 → 136 taken 1 time.
✗ Branch 135 → 307 not taken.
✓ Branch 138 → 139 taken 1 time.
✗ Branch 138 → 313 not taken.
3 SOFT_ERROR_BOOL(node, UNEXPECTED_DYN_TYPE, "Dyn return types are not allowed")
141
3/4
✓ Branch 140 → 141 taken 8175 times.
✗ Branch 140 → 385 not taken.
✓ Branch 141 → 142 taken 1 time.
✓ Branch 141 → 150 taken 8174 times.
8175 if (!returnType.isCoveredByGenericTypeList(usedGenericTypes))
142
3/6
✓ Branch 144 → 145 taken 1 time.
✗ Branch 144 → 316 not taken.
✓ Branch 145 → 146 taken 1 time.
✗ Branch 145 → 314 not taken.
✓ Branch 148 → 149 taken 1 time.
✗ Branch 148 → 320 not taken.
3 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 8174 currentScope = node->scope->parent;
147
3/4
✓ Branch 150 → 151 taken 3285 times.
✓ Branch 150 → 153 taken 4889 times.
✗ Branch 151 → 152 not taken.
✓ Branch 151 → 153 taken 3285 times.
8174 assert(currentScope->type == ScopeType::GLOBAL || currentScope->type == ScopeType::STRUCT);
148
149 // Prepare type of function
150
2/4
✓ Branch 153 → 154 taken 8174 times.
✗ Branch 153 → 321 not taken.
✓ Branch 154 → 155 taken 8174 times.
✗ Branch 154 → 321 not taken.
8174 QualType functionType = QualType(TY_FUNCTION).getWithFunctionParamAndReturnTypes(returnType, paramTypes);
151 8174 functionType.setQualifiers(node->qualifiers);
152
153 // Update type of function entry
154
1/2
✓ Branch 156 → 157 taken 8174 times.
✗ Branch 156 → 324 not taken.
16348 SymbolTableEntry *functionEntry = currentScope->lookupStrict(node->getSymbolTableEntryName());
155
1/2
✗ Branch 161 → 162 not taken.
✓ Branch 161 → 163 taken 8174 times.
8174 assert(functionEntry != nullptr);
156
1/2
✓ Branch 163 → 164 taken 8174 times.
✗ Branch 163 → 385 not taken.
8174 functionEntry->updateType(functionType, false);
157
158 // Build function object
159
4/8
✓ Branch 164 → 165 taken 8174 times.
✗ Branch 164 → 333 not taken.
✓ Branch 165 → 166 taken 8174 times.
✗ Branch 165 → 330 not taken.
✓ Branch 166 → 167 taken 8174 times.
✗ Branch 166 → 327 not taken.
✓ Branch 167 → 168 taken 8174 times.
✗ Branch 167 → 325 not taken.
8174 Function spiceFunc(node->name->name, functionEntry, thisType, returnType, paramList, usedGenericTypes, node);
160 8174 spiceFunc.bodyScope = node->scope;
161
2/2
✓ Branch 171 → 172 taken 8173 times.
✓ Branch 171 → 383 taken 1 time.
8174 FunctionManager::insert(currentScope, spiceFunc, &node->manifestations);
162
163 // Check function attributes
164
2/2
✓ Branch 172 → 173 taken 338 times.
✓ Branch 172 → 220 taken 7835 times.
8173 if (node->attrs) {
165 338 const AttrLstNode *attrLst = node->attrs->attrLst;
166 338 Function *firstManifestation = node->manifestations.front();
167
4/6
✓ Branch 176 → 177 taken 338 times.
✗ Branch 176 → 336 not taken.
✓ Branch 177 → 178 taken 338 times.
✗ Branch 177 → 334 not taken.
✓ Branch 180 → 181 taken 1 time.
✓ Branch 180 → 182 taken 337 times.
1014 if (const CompileTimeValue *value = attrLst->getAttrValueByName(ATTR_CORE_COMPILER_MANGLE))
168 1 firstManifestation->mangleFunctionName = value->boolValue;
169
3/6
✓ Branch 184 → 185 taken 338 times.
✗ Branch 184 → 342 not taken.
✓ Branch 185 → 186 taken 338 times.
✗ Branch 185 → 340 not taken.
✗ Branch 188 → 189 not taken.
✓ Branch 188 → 191 taken 338 times.
1014 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 193 → 194 taken 338 times.
✗ Branch 193 → 348 not taken.
✓ Branch 194 → 195 taken 338 times.
✗ Branch 194 → 346 not taken.
✓ Branch 197 → 198 taken 14 times.
✓ Branch 197 → 220 taken 324 times.
✓ Branch 198 → 199 taken 13 times.
✓ Branch 198 → 220 taken 1 time.
1014 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 199 → 200 taken 1 time.
✓ Branch 199 → 208 taken 12 times.
13 if (node->hasParams)
176
2/4
✓ Branch 203 → 204 taken 1 time.
✗ Branch 203 → 355 not taken.
✓ Branch 204 → 205 taken 1 time.
✗ Branch 204 → 352 not taken.
3 throw SemanticError(node->paramLst, TEST_FUNCTION_WITH_PARAMS, "Test function may not have parameters");
177
3/4
✓ Branch 208 → 209 taken 12 times.
✗ Branch 208 → 383 not taken.
✓ Branch 209 → 210 taken 1 time.
✓ Branch 209 → 218 taken 11 times.
12 if (!returnType.is(TY_BOOL))
178
2/4
✓ Branch 213 → 214 taken 1 time.
✗ Branch 213 → 364 not taken.
✓ Branch 214 → 215 taken 1 time.
✗ Branch 214 → 361 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 11 firstManifestation->entry->used = true; // Avoid printing unused warnings
181 11 firstManifestation->used = true; // Always keep test functions, because they are called implicitly by the test main
182
1/2
✓ Branch 219 → 220 taken 11 times.
✗ Branch 219 → 383 not taken.
11 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 230 → 221 taken 754 times.
✓ Branch 230 → 231 taken 8171 times.
8925 for (size_t i = 1; i < node->manifestations.size(); i++) {
188
4/8
✓ Branch 221 → 222 taken 754 times.
✗ Branch 221 → 375 not taken.
✓ Branch 222 → 223 taken 754 times.
✗ Branch 222 → 375 not taken.
✓ Branch 223 → 224 taken 754 times.
✗ Branch 223 → 372 not taken.
✓ Branch 224 → 225 taken 754 times.
✗ Branch 224 → 370 not taken.
754 Scope *scope = currentScope->copyChildScope(node->getScopeId(), node->manifestations.at(i)->getScopeName());
189
1/2
✓ Branch 227 → 228 taken 754 times.
✗ Branch 227 → 383 not taken.
754 node->manifestations.at(i)->bodyScope = scope;
190 }
191
3/6
✓ Branch 232 → 233 taken 8171 times.
✗ Branch 232 → 381 not taken.
✓ Branch 233 → 234 taken 8171 times.
✗ Branch 233 → 378 not taken.
✓ Branch 234 → 235 taken 8171 times.
✗ Branch 234 → 376 not taken.
8171 currentScope->renameChildScope(node->getScopeId(), node->manifestations.front()->getScopeName());
192
193 // Change to the root scope
194 8171 currentScope = rootScope;
195
1/2
✗ Branch 237 → 238 not taken.
✓ Branch 237 → 239 taken 8171 times.
8171 assert(currentScope->type == ScopeType::GLOBAL);
196
197
1/2
✓ Branch 239 → 240 taken 8171 times.
✗ Branch 239 → 382 not taken.
8171 return nullptr;
198 8192 }
199
200 4211 std::any TypeChecker::visitProcDefPrepare(ProcDefNode *node) {
201 // Mark unreachable statements
202 4211 bool doSetPredecessorsUnreachable = true;
203
1/2
✓ Branch 2 → 3 taken 4211 times.
✗ Branch 2 → 288 not taken.
4211 node->returnsOnAllControlPaths(&doSetPredecessorsUnreachable, manIdx);
204
205 // Check if dtor and has params
206
7/8
✓ Branch 3 → 4 taken 3120 times.
✓ Branch 3 → 7 taken 1091 times.
✓ Branch 4 → 5 taken 3120 times.
✗ Branch 4 → 288 not taken.
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 7 taken 3119 times.
✓ Branch 8 → 9 taken 1 time.
✓ Branch 8 → 17 taken 4210 times.
4211 if (node->hasParams && node->name->name == DTOR_FUNCTION_NAME)
207
2/4
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 191 not taken.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 188 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 4210 currentScope = node->scope;
211
1/2
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 4210 times.
4210 assert(currentScope->type == ScopeType::FUNC_PROC_BODY);
212
213 // Retrieve procedure template types
214 4210 std::vector<GenericType> usedGenericTypes;
215
2/2
✓ Branch 19 → 20 taken 1186 times.
✓ Branch 19 → 49 taken 3024 times.
4210 if (node->hasTemplateTypes) {
216
2/2
✓ Branch 47 → 22 taken 1339 times.
✓ Branch 47 → 48 taken 1185 times.
2524 for (DataTypeNode *dataType : node->templateTypeLst->dataTypes) {
217 // Visit template type
218
2/4
✓ Branch 23 → 24 taken 1339 times.
✗ Branch 23 → 199 not taken.
✓ Branch 24 → 25 taken 1339 times.
✗ Branch 24 → 197 not taken.
1339 auto templateType = std::any_cast<QualType>(visit(dataType));
219
2/4
✓ Branch 26 → 27 taken 1339 times.
✗ Branch 26 → 209 not taken.
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 1339 times.
1339 if (templateType.is(TY_UNRESOLVED))
220 continue;
221 // Check if it is a generic type
222
3/4
✓ Branch 29 → 30 taken 1339 times.
✗ Branch 29 → 209 not taken.
✓ Branch 30 → 31 taken 1 time.
✓ Branch 30 → 39 taken 1338 times.
1339 if (!templateType.is(TY_GENERIC))
223
2/4
✓ Branch 34 → 35 taken 1 time.
✗ Branch 34 → 203 not taken.
✓ Branch 35 → 36 taken 1 time.
✗ Branch 35 → 200 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 39 → 40 taken 1338 times.
✗ Branch 39 → 209 not taken.
✓ Branch 40 → 41 taken 1338 times.
✗ Branch 40 → 209 not taken.
1338 const GenericType *genericType = rootScope->lookupGenericTypeStrict(templateType.getSubType());
226
1/2
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 43 taken 1338 times.
1338 assert(genericType != nullptr);
227
1/2
✓ Branch 43 → 44 taken 1338 times.
✗ Branch 43 → 209 not taken.
1338 usedGenericTypes.push_back(*genericType);
228 }
229 }
230
231 // Retrieve 'this' type
232
1/2
✓ Branch 49 → 50 taken 4209 times.
✗ Branch 49 → 286 not taken.
4209 QualType thisType(TY_DYN); // If the procedure is not a method, the default this type is TY_DYN
233
2/2
✓ Branch 50 → 51 taken 3454 times.
✓ Branch 50 → 81 taken 755 times.
4209 if (node->isMethod) {
234 3454 Scope *structParentScope = node->structScope->parent;
235
1/2
✓ Branch 51 → 52 taken 3454 times.
✗ Branch 51 → 219 not taken.
3454 SymbolTableEntry *structEntry = structParentScope->lookupStrict(node->name->structName);
236
1/2
✗ Branch 54 → 55 not taken.
✓ Branch 54 → 56 taken 3454 times.
3454 assert(structEntry != nullptr);
237 // Set struct to used
238 3454 structEntry->used = true;
239 // Get type and ptr type
240
1/2
✓ Branch 56 → 57 taken 3454 times.
✗ Branch 56 → 219 not taken.
3454 thisType = structEntry->getQualType();
241
1/2
✓ Branch 57 → 58 taken 3454 times.
✗ Branch 57 → 219 not taken.
3454 const QualType thisPtrType = thisType.toPtr(node);
242 // Collect template types of 'this' type
243
3/4
✓ Branch 58 → 59 taken 3454 times.
✗ Branch 58 → 212 not taken.
✓ Branch 68 → 61 taken 1194 times.
✓ Branch 68 → 69 taken 3454 times.
4648 for (const QualType &templateType : thisType.getTemplateTypes()) {
244 377 const auto lambda = [&](const GenericType &genericType) { return genericType == templateType; };
245
3/4
✓ Branch 62 → 63 taken 1194 times.
✗ Branch 62 → 211 not taken.
✓ Branch 63 → 64 taken 1100 times.
✓ Branch 63 → 65 taken 94 times.
1194 if (std::ranges::none_of(usedGenericTypes, lambda))
246
1/2
✓ Branch 64 → 65 taken 1100 times.
✗ Branch 64 → 211 not taken.
1100 usedGenericTypes.emplace_back(templateType);
247 1194 usedGenericTypes.back().used = true;
248 }
249
250 // Set type of 'this' variable
251
1/2
✓ Branch 71 → 72 taken 3454 times.
✗ Branch 71 → 215 not taken.
10362 SymbolTableEntry *thisEntry = currentScope->lookupStrict(THIS_VARIABLE_NAME);
252
1/2
✗ Branch 77 → 78 not taken.
✓ Branch 77 → 79 taken 3454 times.
3454 assert(thisEntry != nullptr);
253
1/2
✓ Branch 79 → 80 taken 3454 times.
✗ Branch 79 → 219 not taken.
3454 thisEntry->updateType(thisPtrType, false);
254 }
255
256 // Visit parameters
257 4209 QualTypeList paramTypes;
258 4209 ParamList paramList;
259
2/2
✓ Branch 81 → 82 taken 3119 times.
✓ Branch 81 → 118 taken 1090 times.
4209 if (node->hasParams) {
260 3119 std::vector<const char *> paramNames;
261 // Visit param list to retrieve the param names
262
2/4
✓ Branch 82 → 83 taken 3119 times.
✗ Branch 82 → 222 not taken.
✓ Branch 83 → 84 taken 3119 times.
✗ Branch 83 → 220 not taken.
3119 auto namedParamList = std::any_cast<NamedParamList>(visit(node->paramLst));
263
2/2
✓ Branch 107 → 87 taken 4352 times.
✓ Branch 107 → 108 taken 3117 times.
7469 for (const auto &[name, qualType, isOptional] : namedParamList) {
264
1/2
✓ Branch 88 → 89 taken 4352 times.
✗ Branch 88 → 234 not taken.
4352 paramNames.push_back(name);
265
1/2
✓ Branch 89 → 90 taken 4352 times.
✗ Branch 89 → 234 not taken.
4352 paramTypes.push_back(qualType);
266
4/6
✓ Branch 90 → 91 taken 4352 times.
✗ Branch 90 → 234 not taken.
✓ Branch 91 → 92 taken 1 time.
✓ Branch 91 → 94 taken 4351 times.
✓ Branch 92 → 93 taken 1 time.
✗ Branch 92 → 223 not taken.
4352 HANDLE_UNRESOLVED_TYPE_PTR(qualType);
267
1/2
✓ Branch 94 → 95 taken 4351 times.
✗ Branch 94 → 224 not taken.
4351 paramList.push_back({qualType, isOptional});
268 // Check if the type is present in the template for generic types
269
3/4
✓ Branch 95 → 96 taken 4351 times.
✗ Branch 95 → 234 not taken.
✓ Branch 96 → 97 taken 1 time.
✓ Branch 96 → 105 taken 4350 times.
4351 if (!qualType.isCoveredByGenericTypeList(usedGenericTypes))
270 throw SemanticError(node->paramLst, GENERIC_TYPE_NOT_IN_TEMPLATE,
271
2/4
✓ Branch 100 → 101 taken 1 time.
✗ Branch 100 → 228 not taken.
✓ Branch 101 → 102 taken 1 time.
✗ Branch 101 → 225 not taken.
3 "Generic param type not included in the template type list of the procedure");
272 }
273
4/4
✓ Branch 110 → 111 taken 3117 times.
✓ Branch 110 → 112 taken 1 time.
✓ Branch 114 → 115 taken 3117 times.
✓ Branch 114 → 117 taken 1 time.
3121 }
274
275 // Leave procedure body scope
276 4207 currentScope = node->scope->parent;
277
3/4
✓ Branch 118 → 119 taken 3454 times.
✓ Branch 118 → 121 taken 753 times.
✗ Branch 119 → 120 not taken.
✓ Branch 119 → 121 taken 3454 times.
4207 assert(currentScope->type == ScopeType::GLOBAL || currentScope->type == ScopeType::STRUCT);
278
279 // Prepare type of procedure
280
3/6
✓ Branch 121 → 122 taken 4207 times.
✗ Branch 121 → 241 not taken.
✓ Branch 122 → 123 taken 4207 times.
✗ Branch 122 → 240 not taken.
✓ Branch 123 → 124 taken 4207 times.
✗ Branch 123 → 240 not taken.
4207 QualType procedureType = QualType(TY_PROCEDURE).getWithFunctionParamAndReturnTypes(QualType(TY_DYN), paramTypes);
281 4207 procedureType.setQualifiers(node->qualifiers);
282
283 // Update type of procedure entry
284
1/2
✓ Branch 125 → 126 taken 4207 times.
✗ Branch 125 → 244 not taken.
8414 SymbolTableEntry *procedureEntry = currentScope->lookupStrict(node->getSymbolTableEntryName());
285
1/2
✗ Branch 130 → 131 not taken.
✓ Branch 130 → 132 taken 4207 times.
4207 assert(procedureEntry != nullptr);
286
1/2
✓ Branch 132 → 133 taken 4207 times.
✗ Branch 132 → 282 not taken.
4207 procedureEntry->updateType(procedureType, false);
287
288 // Build procedure object
289
5/10
✓ Branch 133 → 134 taken 4207 times.
✗ Branch 133 → 254 not taken.
✓ Branch 134 → 135 taken 4207 times.
✗ Branch 134 → 251 not taken.
✓ Branch 135 → 136 taken 4207 times.
✗ Branch 135 → 248 not taken.
✓ Branch 136 → 137 taken 4207 times.
✗ Branch 136 → 247 not taken.
✓ Branch 137 → 138 taken 4207 times.
✗ Branch 137 → 245 not taken.
4207 Function spiceProc(node->name->name, procedureEntry, thisType, QualType(TY_DYN), paramList, usedGenericTypes, node);
290 4207 spiceProc.bodyScope = node->scope;
291
2/2
✓ Branch 141 → 142 taken 4206 times.
✓ Branch 141 → 280 taken 1 time.
4207 FunctionManager::insert(currentScope, spiceProc, &node->manifestations);
292
293 // Check procedure attributes
294
1/2
✗ Branch 142 → 143 not taken.
✓ Branch 142 → 162 taken 4206 times.
4206 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 172 → 163 taken 192 times.
✓ Branch 172 → 173 taken 4206 times.
4398 for (size_t i = 1; i < node->manifestations.size(); i++) {
306
4/8
✓ Branch 163 → 164 taken 192 times.
✗ Branch 163 → 272 not taken.
✓ Branch 164 → 165 taken 192 times.
✗ Branch 164 → 272 not taken.
✓ Branch 165 → 166 taken 192 times.
✗ Branch 165 → 269 not taken.
✓ Branch 166 → 167 taken 192 times.
✗ Branch 166 → 267 not taken.
192 Scope *scope = currentScope->copyChildScope(node->getScopeId(), node->manifestations.at(i)->getScopeName());
307
1/2
✓ Branch 169 → 170 taken 192 times.
✗ Branch 169 → 280 not taken.
192 node->manifestations.at(i)->bodyScope = scope;
308 }
309
3/6
✓ Branch 174 → 175 taken 4206 times.
✗ Branch 174 → 278 not taken.
✓ Branch 175 → 176 taken 4206 times.
✗ Branch 175 → 275 not taken.
✓ Branch 176 → 177 taken 4206 times.
✗ Branch 176 → 273 not taken.
4206 currentScope->renameChildScope(node->getScopeId(), node->manifestations.front()->getScopeName());
310
311 // Change to the root scope
312 4206 currentScope = rootScope;
313
1/2
✗ Branch 179 → 180 not taken.
✓ Branch 179 → 181 taken 4206 times.
4206 assert(currentScope->type == ScopeType::GLOBAL);
314
315
1/2
✓ Branch 181 → 182 taken 4206 times.
✗ Branch 181 → 279 not taken.
4206 return nullptr;
316 4215 }
317
318 727 std::any TypeChecker::visitStructDefPrepare(StructDefNode *node) {
319 727 QualTypeList usedTemplateTypes;
320 727 std::vector<GenericType> templateTypesGeneric;
321
322 // Retrieve struct template types
323
2/2
✓ Branch 2 → 3 taken 255 times.
✓ Branch 2 → 37 taken 472 times.
727 if (node->hasTemplateTypes) {
324
1/2
✓ Branch 4 → 5 taken 255 times.
✗ Branch 4 → 290 not taken.
255 usedTemplateTypes.reserve(node->templateTypeLst->dataTypes.size());
325
1/2
✓ Branch 6 → 7 taken 255 times.
✗ Branch 6 → 290 not taken.
255 templateTypesGeneric.reserve(node->templateTypeLst->dataTypes.size());
326
2/2
✓ Branch 35 → 9 taken 346 times.
✓ Branch 35 → 36 taken 255 times.
601 for (DataTypeNode *dataType : node->templateTypeLst->dataTypes) {
327 // Visit template type
328
2/4
✓ Branch 10 → 11 taken 346 times.
✗ Branch 10 → 194 not taken.
✓ Branch 11 → 12 taken 346 times.
✗ Branch 11 → 192 not taken.
346 auto templateType = std::any_cast<QualType>(visit(dataType));
329
2/4
✓ Branch 13 → 14 taken 346 times.
✗ Branch 13 → 204 not taken.
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 346 times.
346 if (templateType.is(TY_UNRESOLVED))
330 continue;
331 // Check if it is a generic type
332
2/4
✓ Branch 16 → 17 taken 346 times.
✗ Branch 16 → 204 not taken.
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 26 taken 346 times.
346 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 26 → 27 taken 346 times.
✗ Branch 26 → 204 not taken.
✓ Branch 27 → 28 taken 346 times.
✗ Branch 27 → 204 not taken.
346 GenericType *genericType = rootScope->lookupGenericTypeStrict(templateType.getSubType());
336
1/2
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 346 times.
346 assert(genericType != nullptr);
337
1/2
✓ Branch 30 → 31 taken 346 times.
✗ Branch 30 → 204 not taken.
346 usedTemplateTypes.push_back(*genericType);
338
1/2
✓ Branch 31 → 32 taken 346 times.
✗ Branch 31 → 204 not taken.
346 templateTypesGeneric.push_back(*genericType);
339 }
340 }
341
342 // Retrieve implemented interfaces
343 727 QualTypeList interfaceTypes;
344
2/2
✓ Branch 37 → 38 taken 142 times.
✓ Branch 37 → 89 taken 585 times.
727 if (node->hasInterfaces) {
345
1/2
✓ Branch 39 → 40 taken 142 times.
✗ Branch 39 → 288 not taken.
142 interfaceTypes.reserve(node->interfaceTypeLst->dataTypes.size());
346
2/2
✓ Branch 87 → 42 taken 142 times.
✓ Branch 87 → 88 taken 141 times.
283 for (DataTypeNode *interfaceNode : node->interfaceTypeLst->dataTypes) {
347 // Visit interface type
348
2/4
✓ Branch 43 → 44 taken 142 times.
✗ Branch 43 → 208 not taken.
✓ Branch 44 → 45 taken 142 times.
✗ Branch 44 → 206 not taken.
142 auto interfaceType = std::any_cast<QualType>(visit(interfaceNode));
349
2/4
✓ Branch 46 → 47 taken 142 times.
✗ Branch 46 → 230 not taken.
✗ Branch 47 → 48 not taken.
✓ Branch 47 → 49 taken 142 times.
142 if (interfaceType.is(TY_UNRESOLVED))
350 continue;
351 // Check if it is an interface type
352
2/4
✓ Branch 49 → 50 taken 142 times.
✗ Branch 49 → 230 not taken.
✗ Branch 50 → 51 not taken.
✓ Branch 50 → 58 taken 142 times.
142 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 58 → 59 taken 142 times.
✗ Branch 58 → 230 not taken.
✓ Branch 59 → 60 taken 142 times.
✗ Branch 59 → 230 not taken.
✓ Branch 60 → 61 taken 126 times.
✓ Branch 60 → 64 taken 16 times.
✓ Branch 61 → 62 taken 126 times.
✗ Branch 61 → 230 not taken.
✓ Branch 62 → 63 taken 1 time.
✓ Branch 62 → 64 taken 125 times.
✓ Branch 65 → 66 taken 1 time.
✓ Branch 65 → 74 taken 141 times.
142 if (interfaceType.getBodyScope()->isImportedBy(rootScope) && !interfaceType.isPublic())
357 throw SemanticError(node, INSUFFICIENT_VISIBILITY,
358
4/8
✓ Branch 67 → 68 taken 1 time.
✗ Branch 67 → 223 not taken.
✓ Branch 68 → 69 taken 1 time.
✗ Branch 68 → 223 not taken.
✓ Branch 69 → 70 taken 1 time.
✗ Branch 69 → 221 not taken.
✓ Branch 70 → 71 taken 1 time.
✗ Branch 70 → 218 not taken.
1 "Cannot access interface '" + interfaceType.getSubType() + "' due to its private visibility");
359 // Add to interface types
360
1/2
✓ Branch 74 → 75 taken 141 times.
✗ Branch 74 → 230 not taken.
141 interfaceTypes.push_back(interfaceType);
361 // Update the type of the entry for that interface field
362 141 const std::string &interfaceName = interfaceNode->baseDataType->customDataType->typeNameFragments.back();
363
1/2
✓ Branch 76 → 77 taken 141 times.
✗ Branch 76 → 229 not taken.
282 SymbolTableEntry *interfaceEntry = node->structScope->lookupStrict("this." + interfaceName);
364
1/2
✗ Branch 81 → 82 not taken.
✓ Branch 81 → 83 taken 141 times.
141 assert(interfaceEntry != nullptr);
365
1/2
✓ Branch 83 → 84 taken 141 times.
✗ Branch 83 → 230 not taken.
141 interfaceEntry->updateType(interfaceType, false);
366 }
367 }
368
369 // Update type of struct entry
370
1/2
✗ Branch 89 → 90 not taken.
✓ Branch 89 → 91 taken 726 times.
726 assert(node->entry != nullptr);
371 726 const TypeChainElementData data = {.bodyScope = node->structScope};
372
1/2
✓ Branch 91 → 92 taken 726 times.
✗ Branch 91 → 288 not taken.
726 const Type *type = TypeRegistry::getOrInsert(TY_STRUCT, node->structName, node->typeId, data, usedTemplateTypes);
373
2/4
✓ Branch 92 → 93 taken 726 times.
✗ Branch 92 → 232 not taken.
✓ Branch 93 → 94 taken 726 times.
✗ Branch 93 → 232 not taken.
726 node->entry->updateType(QualType(type, node->qualifiers), false);
374
375 // Change to struct scope
376 726 currentScope = node->structScope;
377
1/2
✗ Branch 94 → 95 not taken.
✓ Branch 94 → 96 taken 726 times.
726 assert(currentScope->type == ScopeType::STRUCT);
378
379 // Retrieve field types
380 726 QualTypeList fieldTypes;
381
1/2
✓ Branch 97 → 98 taken 726 times.
✗ Branch 97 → 286 not taken.
726 fieldTypes.reserve(node->fields.size());
382
2/2
✓ Branch 141 → 100 taken 1536 times.
✓ Branch 141 → 142 taken 723 times.
2259 for (FieldNode *field : node->fields) {
383 // Visit field type
384
2/4
✓ Branch 101 → 102 taken 1536 times.
✗ Branch 101 → 235 not taken.
✓ Branch 102 → 103 taken 1536 times.
✗ Branch 102 → 233 not taken.
1536 auto fieldType = std::any_cast<QualType>(visit(field));
385
3/4
✓ Branch 104 → 105 taken 1536 times.
✗ Branch 104 → 254 not taken.
✓ Branch 105 → 106 taken 2 times.
✓ Branch 105 → 107 taken 1534 times.
1536 if (fieldType.is(TY_UNRESOLVED))
386
1/2
✗ Branch 106 → 107 not taken.
✓ Branch 106 → 254 taken 2 times.
2 sourceFile->checkForSoftErrors(); // We get into trouble if we continue without the field type -> abort
387
388 // Check for struct with infinite size.
389 // This can happen if the struct A has a field with type A
390
6/10
✓ Branch 107 → 108 taken 1534 times.
✗ Branch 107 → 254 not taken.
✓ Branch 108 → 109 taken 164 times.
✓ Branch 108 → 112 taken 1370 times.
✓ Branch 109 → 110 taken 164 times.
✗ Branch 109 → 254 not taken.
✗ Branch 110 → 111 not taken.
✓ Branch 110 → 112 taken 164 times.
✗ Branch 113 → 114 not taken.
✓ Branch 113 → 122 taken 1534 times.
1534 if (fieldType.is(TY_STRUCT) && fieldType.getBodyScope() == node->structScope)
391 throw SemanticError(field, STRUCT_INFINITE_SIZE, "Struct with infinite size detected");
392
393 // Add to field types
394
1/2
✓ Branch 122 → 123 taken 1534 times.
✗ Branch 122 → 254 not taken.
1534 fieldTypes.push_back(fieldType);
395
396 // Update type of field entry
397
1/2
✓ Branch 123 → 124 taken 1534 times.
✗ Branch 123 → 254 not taken.
1534 SymbolTableEntry *fieldEntry = currentScope->lookupStrict(field->fieldName);
398
1/2
✗ Branch 126 → 127 not taken.
✓ Branch 126 → 128 taken 1534 times.
1534 assert(fieldEntry != nullptr);
399
1/2
✓ Branch 128 → 129 taken 1534 times.
✗ Branch 128 → 254 not taken.
1534 fieldEntry->updateType(fieldType, false);
400
401 // Check if the template type list contains this type
402
3/4
✓ Branch 129 → 130 taken 1534 times.
✗ Branch 129 → 254 not taken.
✓ Branch 130 → 131 taken 1 time.
✓ Branch 130 → 139 taken 1533 times.
1534 if (!fieldType.isCoveredByGenericTypeList(templateTypesGeneric))
403
2/4
✓ Branch 134 → 135 taken 1 time.
✗ Branch 134 → 248 not taken.
✓ Branch 135 → 136 taken 1 time.
✗ Branch 135 → 245 not taken.
3 throw SemanticError(field->dataType, GENERIC_TYPE_NOT_IN_TEMPLATE, "Generic field type not included in struct template");
404 }
405
406 // Change to the root scope
407 723 currentScope = rootScope;
408
1/2
✗ Branch 142 → 143 not taken.
✓ Branch 142 → 144 taken 723 times.
723 assert(currentScope->type == ScopeType::GLOBAL);
409
410 // Build struct object
411
5/10
✓ Branch 144 → 145 taken 723 times.
✗ Branch 144 → 267 not taken.
✓ Branch 145 → 146 taken 723 times.
✗ Branch 145 → 264 not taken.
✓ Branch 146 → 147 taken 723 times.
✗ Branch 146 → 261 not taken.
✓ Branch 147 → 148 taken 723 times.
✗ Branch 147 → 258 not taken.
✓ Branch 148 → 149 taken 723 times.
✗ Branch 148 → 256 not taken.
723 Struct spiceStruct(node->structName, node->entry, node->structScope, fieldTypes, templateTypesGeneric, interfaceTypes, node);
412
1/2
✓ Branch 153 → 154 taken 723 times.
✗ Branch 153 → 284 not taken.
723 StructManager::insert(currentScope, spiceStruct, &node->structManifestations);
413 723 spiceStruct.scope = node->structScope;
414
415 // Request RTTI runtime if the struct is polymorphic
416 723 node->emitVTable |= node->hasInterfaces;
417
12/18
✓ Branch 154 → 155 taken 65 times.
✓ Branch 154 → 161 taken 658 times.
✓ Branch 157 → 158 taken 65 times.
✗ Branch 157 → 268 not taken.
✓ Branch 158 → 159 taken 65 times.
✗ Branch 158 → 268 not taken.
✓ Branch 159 → 160 taken 64 times.
✓ Branch 159 → 161 taken 1 time.
✓ Branch 162 → 163 taken 65 times.
✓ Branch 162 → 164 taken 658 times.
✓ Branch 164 → 165 taken 65 times.
✓ Branch 164 → 167 taken 658 times.
✓ Branch 167 → 168 taken 64 times.
✓ Branch 167 → 175 taken 659 times.
✗ Branch 268 → 269 not taken.
✗ Branch 268 → 270 not taken.
✗ Branch 272 → 273 not taken.
✗ Branch 272 → 275 not taken.
853 if (node->attrs && node->attrs->attrLst->hasAttr(ATTR_CORE_COMPILER_EMIT_VTABLE))
418
2/4
✓ Branch 170 → 171 taken 64 times.
✗ Branch 170 → 279 not taken.
✓ Branch 171 → 172 taken 64 times.
✗ Branch 171 → 277 not taken.
192 node->emitVTable |= node->attrs->attrLst->getAttrValueByName(ATTR_CORE_COMPILER_EMIT_VTABLE)->boolValue;
419
7/8
✓ Branch 175 → 176 taken 205 times.
✓ Branch 175 → 181 taken 518 times.
✓ Branch 176 → 177 taken 205 times.
✗ Branch 176 → 284 not taken.
✓ Branch 179 → 180 taken 142 times.
✓ Branch 179 → 181 taken 63 times.
✓ Branch 182 → 183 taken 142 times.
✓ Branch 182 → 184 taken 581 times.
928 if (node->emitVTable && !sourceFile->isRttiRT())
420
1/2
✓ Branch 183 → 184 taken 142 times.
✗ Branch 183 → 284 not taken.
142 sourceFile->requestRuntimeModule(RTTI_RT);
421
422
1/2
✓ Branch 184 → 185 taken 723 times.
✗ Branch 184 → 283 not taken.
1446 return nullptr;
423 738 }
424
425 105 std::any TypeChecker::visitInterfaceDefPrepare(InterfaceDefNode *node) {
426 105 QualTypeList usedTemplateTypes;
427 105 std::vector<GenericType> templateTypesGeneric;
428
429 // Retrieve interface template types
430
2/2
✓ Branch 2 → 3 taken 80 times.
✓ Branch 2 → 37 taken 25 times.
105 if (node->hasTemplateTypes) {
431
1/2
✓ Branch 4 → 5 taken 80 times.
✗ Branch 4 → 124 not taken.
80 usedTemplateTypes.reserve(node->templateTypeLst->dataTypes.size());
432
1/2
✓ Branch 6 → 7 taken 80 times.
✗ Branch 6 → 124 not taken.
80 templateTypesGeneric.reserve(node->templateTypeLst->dataTypes.size());
433
2/2
✓ Branch 35 → 9 taken 80 times.
✓ Branch 35 → 36 taken 80 times.
160 for (DataTypeNode *dataType : node->templateTypeLst->dataTypes) {
434 // Visit template type
435
2/4
✓ Branch 10 → 11 taken 80 times.
✗ Branch 10 → 93 not taken.
✓ Branch 11 → 12 taken 80 times.
✗ Branch 11 → 91 not taken.
80 auto templateType = std::any_cast<QualType>(visit(dataType));
436
2/6
✓ Branch 13 → 14 taken 80 times.
✗ Branch 13 → 101 not taken.
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 17 taken 80 times.
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 94 not taken.
80 HANDLE_UNRESOLVED_TYPE_PTR(templateType)
437 // Check if it is a generic type
438
2/4
✓ Branch 17 → 18 taken 80 times.
✗ Branch 17 → 101 not taken.
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 26 taken 80 times.
80 if (!templateType.is(TY_GENERIC)) {
439 softError(dataType, EXPECTED_GENERIC_TYPE, "A template list can only contain generic types");
440 continue;
441 }
442 // Convert generic symbol type to generic type
443
2/4
✓ Branch 26 → 27 taken 80 times.
✗ Branch 26 → 101 not taken.
✓ Branch 27 → 28 taken 80 times.
✗ Branch 27 → 101 not taken.
80 const GenericType *genericType = rootScope->lookupGenericTypeStrict(templateType.getSubType());
444
1/2
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 80 times.
80 assert(genericType != nullptr);
445
1/2
✓ Branch 30 → 31 taken 80 times.
✗ Branch 30 → 101 not taken.
80 usedTemplateTypes.push_back(*genericType);
446
1/2
✓ Branch 31 → 32 taken 80 times.
✗ Branch 31 → 101 not taken.
80 templateTypesGeneric.push_back(*genericType);
447 }
448 }
449
450 // Update type of interface entry
451 105 const TypeChainElementData data = {.bodyScope = node->interfaceScope};
452
1/2
✓ Branch 37 → 38 taken 105 times.
✗ Branch 37 → 124 not taken.
105 const Type *type = TypeRegistry::getOrInsert(TY_INTERFACE, node->interfaceName, node->typeId, data, usedTemplateTypes);
453
1/2
✓ Branch 38 → 39 taken 105 times.
✗ Branch 38 → 124 not taken.
105 const QualType interfaceType(type, node->qualifiers);
454
1/2
✗ Branch 39 → 40 not taken.
✓ Branch 39 → 41 taken 105 times.
105 assert(node->entry != nullptr);
455
1/2
✓ Branch 41 → 42 taken 105 times.
✗ Branch 41 → 124 not taken.
105 node->entry->updateType(interfaceType, false);
456
457 // Change to interface scope
458 105 currentScope = node->interfaceScope;
459
1/2
✗ Branch 42 → 43 not taken.
✓ Branch 42 → 44 taken 105 times.
105 assert(currentScope->type == ScopeType::INTERFACE);
460
461 // Visit methods
462 105 size_t vtableIndex = 0;
463 105 std::vector<Function *> methods;
464
1/2
✓ Branch 45 → 46 taken 105 times.
✗ Branch 45 → 122 not taken.
105 methods.reserve(node->signatures.size());
465
2/2
✓ Branch 68 → 48 taken 241 times.
✓ Branch 68 → 69 taken 104 times.
345 for (SignatureNode *signature : node->signatures) {
466
2/4
✓ Branch 49 → 50 taken 241 times.
✗ Branch 49 → 105 not taken.
✓ Branch 50 → 51 taken 241 times.
✗ Branch 50 → 103 not taken.
241 const auto method = std::any_cast<std::vector<Function *> *>(visit(signature));
467
2/2
✓ Branch 52 → 53 taken 1 time.
✓ Branch 52 → 55 taken 240 times.
241 if (!method)
468
1/2
✓ Branch 53 → 54 taken 1 time.
✗ Branch 53 → 106 not taken.
1 return nullptr;
469
470 // Set 'this' type
471
2/2
✓ Branch 60 → 57 taken 240 times.
✓ Branch 60 → 61 taken 240 times.
480 for (Function *m : *method) {
472 240 m->isVirtual = true; // Interface methods are always virtual
473 240 m->vtableIndex = vtableIndex;
474 240 m->thisType = interfaceType;
475 }
476
477
1/2
✓ Branch 65 → 66 taken 240 times.
✗ Branch 65 → 107 not taken.
240 methods.insert(methods.end(), method->begin(), method->end());
478 240 vtableIndex++;
479 }
480
481 // Change to root scope
482 104 currentScope = rootScope;
483
1/2
✗ Branch 69 → 70 not taken.
✓ Branch 69 → 71 taken 104 times.
104 assert(currentScope->type == ScopeType::GLOBAL);
484
485 // Build interface object
486
4/8
✓ Branch 71 → 72 taken 104 times.
✗ Branch 71 → 118 not taken.
✓ Branch 72 → 73 taken 104 times.
✗ Branch 72 → 115 not taken.
✓ Branch 73 → 74 taken 104 times.
✗ Branch 73 → 112 not taken.
✓ Branch 74 → 75 taken 104 times.
✗ Branch 74 → 110 not taken.
104 Interface spiceInterface(node->interfaceName, node->entry, node->interfaceScope, methods, templateTypesGeneric, node);
487
1/2
✓ Branch 78 → 79 taken 104 times.
✗ Branch 78 → 120 not taken.
104 InterfaceManager::insert(currentScope, spiceInterface, &node->interfaceManifestations);
488 104 spiceInterface.scope = node->interfaceScope;
489
490 // Request RTTI runtime, that is always required when dealing with interfaces due to polymorphism
491
2/4
✓ Branch 79 → 80 taken 104 times.
✗ Branch 79 → 120 not taken.
✓ Branch 82 → 83 taken 104 times.
✗ Branch 82 → 84 not taken.
208 if (!sourceFile->isRttiRT())
492
1/2
✓ Branch 83 → 84 taken 104 times.
✗ Branch 83 → 120 not taken.
104 sourceFile->requestRuntimeModule(RTTI_RT);
493
494
1/2
✓ Branch 84 → 85 taken 104 times.
✗ Branch 84 → 119 not taken.
104 return nullptr;
495 105 }
496
497 65 std::any TypeChecker::visitEnumDefPrepare(EnumDefNode *node) {
498 // Update type of enum entry
499 65 const TypeChainElementData data = {.bodyScope = node->enumScope};
500
1/2
✓ Branch 3 → 4 taken 65 times.
✗ Branch 3 → 59 not taken.
65 const Type *type = TypeRegistry::getOrInsert(TY_ENUM, node->enumName, node->typeId, data, {});
501
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 65 times.
65 assert(node->entry != nullptr);
502
2/4
✓ Branch 7 → 8 taken 65 times.
✗ Branch 7 → 62 not taken.
✓ Branch 8 → 9 taken 65 times.
✗ Branch 8 → 62 not taken.
65 node->entry->updateType(QualType(type, node->qualifiers), false);
503
504 // Change to enum scope
505 65 currentScope = node->enumScope;
506
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 65 times.
65 assert(currentScope->type == ScopeType::ENUM);
507
508 // Loop through all items with values
509 65 std::vector<std::string> names;
510 65 std::vector<uint32_t> values;
511
2/2
✓ Branch 30 → 13 taken 730 times.
✓ Branch 30 → 31 taken 65 times.
795 for (const EnumItemNode *enumItem : node->itemLst->items) {
512 // Save name
513
1/2
✓ Branch 14 → 15 taken 730 times.
✗ Branch 14 → 71 not taken.
730 names.push_back(enumItem->itemName);
514 // Check for duplicate value
515
2/2
✓ Branch 15 → 16 taken 409 times.
✓ Branch 15 → 28 taken 321 times.
730 if (enumItem->hasValue) {
516
3/4
✓ Branch 17 → 18 taken 409 times.
✗ Branch 17 → 63 not taken.
✓ Branch 19 → 20 taken 1 time.
✓ Branch 19 → 27 taken 408 times.
409 if (std::ranges::find(values, enumItem->itemValue) != values.end()) {
517
2/4
✓ Branch 22 → 23 taken 1 time.
✗ Branch 22 → 67 not taken.
✓ Branch 23 → 24 taken 1 time.
✗ Branch 23 → 65 not taken.
1 softError(enumItem, DUPLICATE_ENUM_ITEM_VALUE, "Duplicate enum item value, please use another");
518 1 continue;
519 }
520
1/2
✓ Branch 27 → 28 taken 408 times.
✗ Branch 27 → 71 not taken.
408 values.push_back(enumItem->itemValue);
521 }
522 }
523
524 // Loop through all items without values
525 65 uint32_t nextValue = 0;
526
1/2
✓ Branch 31 → 32 taken 65 times.
✗ Branch 31 → 76 not taken.
65 const QualType intSymbolType(TY_INT);
527
2/2
✓ Branch 51 → 34 taken 730 times.
✓ Branch 51 → 52 taken 65 times.
795 for (EnumItemNode *enumItem : node->itemLst->items) {
528 // Update type of enum item entry
529
1/2
✓ Branch 35 → 36 taken 730 times.
✗ Branch 35 → 74 not taken.
730 SymbolTableEntry *itemEntry = currentScope->lookupStrict(enumItem->itemName);
530
1/2
✗ Branch 38 → 39 not taken.
✓ Branch 38 → 40 taken 730 times.
730 assert(itemEntry != nullptr);
531
1/2
✓ Branch 40 → 41 taken 730 times.
✗ Branch 40 → 74 not taken.
730 itemEntry->updateType(intSymbolType, false);
532 // Fill in value if not filled yet
533
2/2
✓ Branch 41 → 42 taken 321 times.
✓ Branch 41 → 49 taken 409 times.
730 if (!enumItem->hasValue) {
534
3/4
✓ Branch 45 → 46 taken 602 times.
✗ Branch 45 → 72 not taken.
✓ Branch 47 → 43 taken 281 times.
✓ Branch 47 → 48 taken 321 times.
602 while (std::ranges::find(values, nextValue) != values.end())
535 281 nextValue++;
536 321 enumItem->itemValue = nextValue;
537
1/2
✓ Branch 48 → 49 taken 321 times.
✗ Branch 48 → 74 not taken.
321 values.push_back(nextValue);
538 }
539 }
540
541 // Change to root scope
542 65 currentScope = rootScope;
543
1/2
✗ Branch 52 → 53 not taken.
✓ Branch 52 → 54 taken 65 times.
65 assert(currentScope->type == ScopeType::GLOBAL);
544
545
1/2
✓ Branch 54 → 55 taken 65 times.
✗ Branch 54 → 75 not taken.
130 return nullptr;
546 65 }
547
548 986 std::any TypeChecker::visitGenericTypeDefPrepare(GenericTypeDefNode *node) {
549 // Retrieve type conditions
550 986 QualTypeList typeConditions;
551
1/2
✓ Branch 3 → 4 taken 986 times.
✗ Branch 3 → 60 not taken.
986 typeConditions.reserve(node->typeAltsLst->dataTypes.size());
552
2/2
✓ Branch 17 → 6 taken 1866 times.
✓ Branch 17 → 18 taken 986 times.
2852 for (const auto &typeAlt : node->typeAltsLst->dataTypes) {
553
2/4
✓ Branch 7 → 8 taken 1866 times.
✗ Branch 7 → 48 not taken.
✓ Branch 8 → 9 taken 1866 times.
✗ Branch 8 → 46 not taken.
1866 auto typeCondition = std::any_cast<QualType>(visit(typeAlt));
554
2/6
✓ Branch 10 → 11 taken 1866 times.
✗ Branch 10 → 50 not taken.
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 14 taken 1866 times.
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 49 not taken.
1866 HANDLE_UNRESOLVED_TYPE_PTR(typeCondition)
555
1/2
✓ Branch 14 → 15 taken 1866 times.
✗ Branch 14 → 50 not taken.
1866 typeConditions.push_back(typeCondition);
556 }
557
558 // Add generic type to the scope
559
2/4
✓ Branch 18 → 19 taken 986 times.
✗ Branch 18 → 54 not taken.
✓ Branch 19 → 20 taken 986 times.
✗ Branch 19 → 52 not taken.
986 const GenericType genericType(node->typeName, typeConditions);
560
1/2
✓ Branch 21 → 22 taken 986 times.
✗ Branch 21 → 58 not taken.
986 rootScope->insertGenericType(node->typeName, genericType);
561
562 // Check if only one type condition is set
563
7/8
✓ Branch 23 → 24 taken 376 times.
✓ Branch 23 → 28 taken 610 times.
✓ Branch 25 → 26 taken 376 times.
✗ Branch 25 → 58 not taken.
✓ Branch 26 → 27 taken 1 time.
✓ Branch 26 → 28 taken 375 times.
✓ Branch 29 → 30 taken 1 time.
✓ Branch 29 → 32 taken 985 times.
986 if (typeConditions.size() == 1 && !typeConditions.front().is(TY_DYN))
564
1/2
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 55 not taken.
1 sourceFile->compilerOutput.warnings.emplace_back(node->typeAltsLst->codeLoc, SINGLE_GENERIC_TYPE_CONDITION,
565 "Generic type is locked to one type");
566
567 // Check if the list contains the dyn type, along with other types
568
1/2
✓ Branch 32 → 33 taken 986 times.
✗ Branch 32 → 58 not taken.
2850 const bool containsDynType = std::ranges::any_of(typeConditions, [&](const QualType &type) { return type.is(TY_DYN); });
569
6/6
✓ Branch 33 → 34 taken 377 times.
✓ Branch 33 → 37 taken 609 times.
✓ Branch 35 → 36 taken 2 times.
✓ Branch 35 → 37 taken 375 times.
✓ Branch 38 → 39 taken 2 times.
✓ Branch 38 → 41 taken 984 times.
986 if (containsDynType && typeConditions.size() > 1)
570 2 sourceFile->compilerOutput.warnings.emplace_back(
571
1/2
✓ Branch 39 → 40 taken 2 times.
✗ Branch 39 → 56 not taken.
2 node->typeAltsLst->codeLoc, INEFFECTIVE_GENERIC_TYPE_CONDITION,
572 "One or several type conditions are superfluous, because the dyn type condition is given");
573
574
1/2
✓ Branch 41 → 42 taken 986 times.
✗ Branch 41 → 57 not taken.
986 return nullptr;
575 986 }
576
577 68 std::any TypeChecker::visitAliasDefPrepare(AliasDefNode *node) {
578
2/4
✓ Branch 2 → 3 taken 68 times.
✗ Branch 2 → 5 not taken.
✓ Branch 3 → 4 taken 68 times.
✗ Branch 3 → 5 not taken.
68 assert(node->entry != nullptr && node->aliasedTypeContainerEntry != nullptr);
579
580 // Update type of alias entry
581
1/2
✓ Branch 7 → 8 taken 68 times.
✗ Branch 7 → 23 not taken.
68 const Type *type = TypeRegistry::getOrInsert(TY_ALIAS, node->aliasName, node->typeId, {}, {});
582
2/4
✓ Branch 9 → 10 taken 68 times.
✗ Branch 9 → 27 not taken.
✓ Branch 10 → 11 taken 68 times.
✗ Branch 10 → 27 not taken.
68 node->entry->updateType(QualType(type, node->qualifiers), false);
583
584 // Update type of the aliased type container entry
585
2/4
✓ Branch 11 → 12 taken 68 times.
✗ Branch 11 → 30 not taken.
✓ Branch 12 → 13 taken 68 times.
✗ Branch 12 → 28 not taken.
68 const auto aliasedType = std::any_cast<QualType>(visit(node->dataType));
586
4/6
✓ Branch 14 → 15 taken 68 times.
✗ Branch 14 → 33 not taken.
✓ Branch 15 → 16 taken 1 time.
✓ Branch 15 → 18 taken 67 times.
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 31 not taken.
68 HANDLE_UNRESOLVED_TYPE_PTR(aliasedType)
587
1/2
✓ Branch 18 → 19 taken 67 times.
✗ Branch 18 → 33 not taken.
67 node->aliasedTypeContainerEntry->updateType(aliasedType, false);
588 67 node->aliasedTypeContainerEntry->used = true; // The container type is always used per default
589
590
1/2
✓ Branch 19 → 20 taken 67 times.
✗ Branch 19 → 32 not taken.
67 return nullptr;
591 }
592
593 1187 std::any TypeChecker::visitGlobalVarDefPrepare(GlobalVarDefNode *node) {
594 // Insert variable name to symbol table
595
2/4
✓ Branch 2 → 3 taken 1187 times.
✗ Branch 2 → 80 not taken.
✓ Branch 3 → 4 taken 1187 times.
✗ Branch 3 → 78 not taken.
1187 auto globalVarType = std::any_cast<QualType>(visit(node->dataType));
596
2/6
✓ Branch 5 → 6 taken 1187 times.
✗ Branch 5 → 126 not taken.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 9 taken 1187 times.
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 81 not taken.
1187 HANDLE_UNRESOLVED_TYPE_PTR(globalVarType)
597
598
2/2
✓ Branch 9 → 10 taken 1185 times.
✓ Branch 9 → 37 taken 2 times.
1187 if (node->constant) { // Variable is initialized here
599
2/4
✓ Branch 10 → 11 taken 1185 times.
✗ Branch 10 → 84 not taken.
✓ Branch 11 → 12 taken 1185 times.
✗ Branch 11 → 82 not taken.
1185 const QualType rhsType = std::any_cast<ExprResult>(visit(node->constant)).type;
600
2/6
✓ Branch 13 → 14 taken 1185 times.
✗ Branch 13 → 103 not taken.
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 17 taken 1185 times.
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 86 not taken.
1185 HANDLE_UNRESOLVED_TYPE_PTR(rhsType)
601
3/4
✓ Branch 17 → 18 taken 1185 times.
✗ Branch 17 → 103 not taken.
✓ Branch 18 → 19 taken 1 time.
✓ Branch 18 → 20 taken 1184 times.
1185 if (globalVarType.is(TY_DYN)) { // Perform type inference
602 1 globalVarType = rhsType;
603
3/4
✓ Branch 20 → 21 taken 1184 times.
✗ Branch 20 → 103 not taken.
✓ Branch 21 → 22 taken 2 times.
✓ Branch 21 → 35 taken 1182 times.
1184 } else if (!globalVarType.matches(rhsType, false, true, true)) { // Check if types are matching
604
7/14
✓ Branch 22 → 23 taken 2 times.
✗ Branch 22 → 100 not taken.
✓ Branch 23 → 24 taken 2 times.
✗ Branch 23 → 95 not taken.
✓ Branch 24 → 25 taken 2 times.
✗ Branch 24 → 93 not taken.
✓ Branch 25 → 26 taken 2 times.
✗ Branch 25 → 91 not taken.
✓ Branch 26 → 27 taken 2 times.
✗ Branch 26 → 89 not taken.
✓ Branch 27 → 28 taken 2 times.
✗ Branch 27 → 87 not taken.
✓ Branch 33 → 34 taken 2 times.
✗ Branch 33 → 102 not taken.
2 SOFT_ERROR_BOOL(node->constant, OPERATOR_WRONG_DATA_TYPE,
605 "Expected " + globalVarType.getName(false) + ", but got " + rhsType.getName(false))
606 }
607 }
608
609 // Check if the type is still missing
610
3/4
✓ Branch 37 → 38 taken 1185 times.
✗ Branch 37 → 126 not taken.
✓ Branch 38 → 39 taken 1 time.
✓ Branch 38 → 47 taken 1184 times.
1185 if (globalVarType.is(TY_DYN))
611
3/6
✓ Branch 41 → 42 taken 1 time.
✗ Branch 41 → 106 not taken.
✓ Branch 42 → 43 taken 1 time.
✗ Branch 42 → 104 not taken.
✓ Branch 45 → 46 taken 1 time.
✗ Branch 45 → 110 not taken.
3 SOFT_ERROR_BOOL(node->dataType, GLOBAL_OF_TYPE_DYN, "Global variables must have an explicit data type")
612
613 // Check if we would need to insert instructions in the global scope to initialize the variable
614
2/4
✓ Branch 47 → 48 taken 1184 times.
✗ Branch 47 → 126 not taken.
✗ Branch 48 → 49 not taken.
✓ Branch 48 → 57 taken 1184 times.
1184 if (!globalVarType.isPrimitive())
615 SOFT_ERROR_BOOL(node->dataType, GLOBAL_OF_INVALID_TYPE, "Spice does only support global variables of primitive type")
616
617 // Update type of global var entry
618
1/2
✗ Branch 57 → 58 not taken.
✓ Branch 57 → 59 taken 1184 times.
1184 assert(node->entry != nullptr);
619
1/2
✓ Branch 59 → 60 taken 1184 times.
✗ Branch 59 → 126 not taken.
1184 node->entry->updateType(globalVarType, false);
620
621 // Check if a value is attached
622
6/8
✓ Branch 60 → 61 taken 1 time.
✓ Branch 60 → 64 taken 1183 times.
✓ Branch 61 → 62 taken 1 time.
✗ Branch 61 → 126 not taken.
✓ Branch 62 → 63 taken 1 time.
✗ Branch 62 → 64 not taken.
✓ Branch 65 → 66 taken 1 time.
✓ Branch 65 → 74 taken 1183 times.
1184 if (!node->constant && globalVarType.isConst())
623
3/6
✓ Branch 68 → 69 taken 1 time.
✗ Branch 68 → 120 not taken.
✓ Branch 69 → 70 taken 1 time.
✗ Branch 69 → 118 not taken.
✓ Branch 72 → 73 taken 1 time.
✗ Branch 72 → 124 not taken.
3 SOFT_ERROR_BOOL(node, GLOBAL_CONST_WITHOUT_VALUE, "You must specify a value for constant global variables")
624
625
1/2
✓ Branch 74 → 75 taken 1183 times.
✗ Branch 74 → 125 not taken.
1183 return nullptr;
626 }
627
628 1026 std::any TypeChecker::visitExtDeclPrepare(ExtDeclNode *node) {
629 // Collect argument types
630 1026 QualTypeList argTypes;
631 1026 ParamList argList;
632
2/2
✓ Branch 2 → 3 taken 988 times.
✓ Branch 2 → 31 taken 38 times.
1026 if (node->hasArgs) {
633
1/2
✓ Branch 4 → 5 taken 988 times.
✗ Branch 4 → 155 not taken.
988 argList.reserve(node->argTypeLst->typeLst->dataTypes.size());
634
2/2
✓ Branch 29 → 7 taken 2011 times.
✓ Branch 29 → 30 taken 988 times.
2999 for (DataTypeNode *arg : node->argTypeLst->typeLst->dataTypes) {
635 // Visit argument
636
2/4
✓ Branch 8 → 9 taken 2011 times.
✗ Branch 8 → 100 not taken.
✓ Branch 9 → 10 taken 2011 times.
✗ Branch 9 → 98 not taken.
2011 auto argType = std::any_cast<QualType>(visit(arg));
637
2/6
✓ Branch 11 → 12 taken 2011 times.
✗ Branch 11 → 109 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 15 taken 2011 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 101 not taken.
2011 HANDLE_UNRESOLVED_TYPE_PTR(argType)
638 // Check if the argument type is 'dyn'
639
3/4
✓ Branch 15 → 16 taken 2011 times.
✗ Branch 15 → 109 not taken.
✓ Branch 16 → 17 taken 1 time.
✓ Branch 16 → 24 taken 2010 times.
2011 if (argType.is(TY_DYN)) {
640
2/4
✓ Branch 19 → 20 taken 1 time.
✗ Branch 19 → 104 not taken.
✓ Branch 20 → 21 taken 1 time.
✗ Branch 20 → 102 not taken.
1 softError(arg, UNEXPECTED_DYN_TYPE, "Dyn data type is not allowed as arg type for external functions");
641 1 continue;
642 }
643 // Save argument
644
1/2
✓ Branch 24 → 25 taken 2010 times.
✗ Branch 24 → 109 not taken.
2010 argTypes.push_back(argType);
645
1/2
✓ Branch 25 → 26 taken 2010 times.
✗ Branch 25 → 108 not taken.
2010 argList.push_back({argType, false});
646 }
647 }
648
649 // Retrieve return type
650
1/2
✓ Branch 31 → 32 taken 1026 times.
✗ Branch 31 → 155 not taken.
1026 QualType returnType(TY_DYN);
651 1026 const bool isFunction = node->returnType;
652
2/2
✓ Branch 32 → 33 taken 668 times.
✓ Branch 32 → 50 taken 358 times.
1026 if (isFunction) { // External function
653
2/4
✓ Branch 33 → 34 taken 668 times.
✗ Branch 33 → 113 not taken.
✓ Branch 34 → 35 taken 668 times.
✗ Branch 34 → 111 not taken.
668 returnType = std::any_cast<QualType>(visit(node->returnType));
654
2/6
✓ Branch 36 → 37 taken 668 times.
✗ Branch 36 → 155 not taken.
✗ Branch 37 → 38 not taken.
✓ Branch 37 → 40 taken 668 times.
✗ Branch 38 → 39 not taken.
✗ Branch 38 → 115 not taken.
668 HANDLE_UNRESOLVED_TYPE_PTR(returnType)
655 // Check if return type is dyn
656
3/4
✓ Branch 40 → 41 taken 668 times.
✗ Branch 40 → 155 not taken.
✓ Branch 41 → 42 taken 1 time.
✓ Branch 41 → 50 taken 667 times.
668 if (returnType.is(TY_DYN))
657
3/6
✓ Branch 44 → 45 taken 1 time.
✗ Branch 44 → 118 not taken.
✓ Branch 45 → 46 taken 1 time.
✗ Branch 45 → 116 not taken.
✓ Branch 48 → 49 taken 1 time.
✗ Branch 48 → 122 not taken.
3 SOFT_ERROR_BOOL(node->returnType, UNEXPECTED_DYN_TYPE, "dyn is not allowed as return type for external functions")
658 }
659
660 // Add function to current scope
661
4/8
✓ Branch 51 → 52 taken 1025 times.
✗ Branch 51 → 129 not taken.
✓ Branch 52 → 53 taken 1025 times.
✗ Branch 52 → 126 not taken.
✓ Branch 53 → 54 taken 1025 times.
✗ Branch 53 → 125 not taken.
✓ Branch 54 → 55 taken 1025 times.
✗ Branch 54 → 123 not taken.
1025 const Function spiceFunc(node->extFunctionName, node->entry, QualType(TY_DYN), returnType, argList, {}, node);
662
1/2
✓ Branch 58 → 59 taken 1025 times.
✗ Branch 58 → 153 not taken.
1025 node->extFunction = FunctionManager::insert(currentScope, spiceFunc, &node->extFunctionManifestations);
663 1025 node->extFunction->mangleFunctionName = false;
664 1025 node->extFunction->alreadyTypeChecked = true;
665
4/4
✓ Branch 59 → 60 taken 988 times.
✓ Branch 59 → 62 taken 37 times.
✓ Branch 60 → 61 taken 17 times.
✓ Branch 60 → 62 taken 971 times.
1025 node->extFunction->isVararg = node->argTypeLst && node->argTypeLst->hasEllipsis;
666
667 // Check procedure attributes
668
2/2
✓ Branch 63 → 64 taken 1 time.
✓ Branch 63 → 81 taken 1024 times.
1025 if (node->attrs) {
669 1 const AttrLstNode *attrLst = node->attrs->attrLst;
670
3/6
✓ Branch 66 → 67 taken 1 time.
✗ Branch 66 → 135 not taken.
✓ Branch 67 → 68 taken 1 time.
✗ Branch 67 → 133 not taken.
✗ Branch 70 → 71 not taken.
✓ Branch 70 → 72 taken 1 time.
3 if (const CompileTimeValue *value = attrLst->getAttrValueByName(ATTR_CORE_COMPILER_MANGLE))
671 node->extFunction->mangleFunctionName = value->boolValue;
672
3/6
✓ Branch 74 → 75 taken 1 time.
✗ Branch 74 → 141 not taken.
✓ Branch 75 → 76 taken 1 time.
✗ Branch 75 → 139 not taken.
✓ Branch 78 → 79 taken 1 time.
✗ Branch 78 → 81 not taken.
3 if (const CompileTimeValue *value = attrLst->getAttrValueByName(ATTR_CORE_COMPILER_MANGLED_NAME)) {
673
1/2
✓ Branch 79 → 80 taken 1 time.
✗ Branch 79 → 153 not taken.
1 const std::string &stringValue = resourceManager.compileTimeStringValues.at(value->stringValueOffset);
674
1/2
✓ Branch 80 → 81 taken 1 time.
✗ Branch 80 → 153 not taken.
1 node->extFunction->predefinedMangledName = stringValue;
675 }
676 }
677
678 // Prepare ext function type
679
2/2
✓ Branch 81 → 82 taken 667 times.
✓ Branch 81 → 83 taken 358 times.
1025 const SuperType superType = isFunction ? TY_FUNCTION : TY_PROCEDURE;
680
2/4
✓ Branch 84 → 85 taken 1025 times.
✗ Branch 84 → 145 not taken.
✓ Branch 85 → 86 taken 1025 times.
✗ Branch 85 → 145 not taken.
1025 const QualType extFunctionType = QualType(superType).getWithFunctionParamAndReturnTypes(returnType, argTypes);
681
682 // Set type of external function
683
1/2
✓ Branch 86 → 87 taken 1025 times.
✗ Branch 86 → 153 not taken.
1025 node->entry->updateType(extFunctionType, false);
684
685 // Rename the original child scope to reflect the substantiated versions of the external function
686
3/6
✓ Branch 87 → 88 taken 1025 times.
✗ Branch 87 → 151 not taken.
✓ Branch 88 → 89 taken 1025 times.
✗ Branch 88 → 148 not taken.
✓ Branch 89 → 90 taken 1025 times.
✗ Branch 89 → 146 not taken.
1025 currentScope->renameChildScope(node->getScopeId(), spiceFunc.getScopeName());
687
688
1/2
✓ Branch 92 → 93 taken 1025 times.
✗ Branch 92 → 152 not taken.
1025 return nullptr;
689 1026 }
690
691 628 std::any TypeChecker::visitImportDefPrepare(ImportDefNode *node) {
692 // Set entry to import type
693
1/2
✓ Branch 2 → 3 taken 628 times.
✗ Branch 2 → 10 not taken.
628 const QualType importType(TY_IMPORT, node->importName);
694
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 628 times.
628 assert(node->entry != nullptr);
695
1/2
✓ Branch 5 → 6 taken 628 times.
✗ Branch 5 → 10 not taken.
628 node->entry->updateType(importType, false);
696
697
1/2
✓ Branch 6 → 7 taken 628 times.
✗ Branch 6 → 9 not taken.
628 return nullptr;
698 }
699
700 } // namespace spice::compiler
701