src/typechecker/TypeCheckerTopLevelDefinitionsPrepare.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2026 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #include "TypeChecker.h" | ||
| 4 | |||
| 5 | #include <unordered_set> | ||
| 6 | |||
| 7 | #include <SourceFile.h> | ||
| 8 | #include <ast/Attributes.h> | ||
| 9 | #include <global/GlobalResourceManager.h> | ||
| 10 | #include <global/TypeRegistry.h> | ||
| 11 | #include <model/GenericType.h> | ||
| 12 | #include <model/Interface.h> | ||
| 13 | #include <symboltablebuilder/Scope.h> | ||
| 14 | #include <symboltablebuilder/SymbolTableBuilder.h> | ||
| 15 | #include <typechecker/FunctionManager.h> | ||
| 16 | #include <typechecker/InterfaceManager.h> | ||
| 17 | #include <typechecker/MacroDefs.h> | ||
| 18 | #include <typechecker/StructManager.h> | ||
| 19 | |||
| 20 | namespace spice::compiler { | ||
| 21 | |||
| 22 | 511 | std::any TypeChecker::visitMainFctDefPrepare(MainFctDefNode *node) { | |
| 23 | // Mark unreachable statements | ||
| 24 | 511 | bool returnsOnAllControlPaths = true; | |
| 25 |
1/2✓ Branch 2 → 3 taken 511 times.
✗ Branch 2 → 77 not taken.
|
511 | node->returnsOnAllControlPaths(&returnsOnAllControlPaths, manIdx); |
| 26 | |||
| 27 | // Retrieve return type | ||
| 28 |
1/2✓ Branch 3 → 4 taken 511 times.
✗ Branch 3 → 77 not taken.
|
511 | const QualType returnType(TY_INT); |
| 29 | |||
| 30 | // Change to function body scope | ||
| 31 | 511 | currentScope = node->bodyScope; | |
| 32 | |||
| 33 | // Set type of 'result' variable to int | ||
| 34 |
1/2✓ Branch 6 → 7 taken 511 times.
✗ Branch 6 → 56 not taken.
|
1533 | SymbolTableEntry *resultEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME); |
| 35 |
1/2✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 511 times.
|
511 | assert(resultEntry != nullptr); |
| 36 |
1/2✓ Branch 14 → 15 taken 511 times.
✗ Branch 14 → 77 not taken.
|
511 | resultEntry->updateType(returnType, false); |
| 37 | 511 | resultEntry->used = true; | |
| 38 | |||
| 39 | // Retrieve param types | ||
| 40 | 511 | QualTypeList paramTypes; | |
| 41 |
2/2✓ Branch 15 → 16 taken 7 times.
✓ Branch 15 → 36 taken 504 times.
|
511 | if (node->takesArgs) { |
| 42 |
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)); |
| 43 |
2/2✓ Branch 33 → 21 taken 14 times.
✓ Branch 33 → 34 taken 7 times.
|
28 | for (const auto &[name, qualType, isOptional] : namedParamList) |
| 44 |
1/2✓ Branch 23 → 24 taken 14 times.
✗ Branch 23 → 63 not taken.
|
14 | paramTypes.push_back(qualType); |
| 45 | 7 | } | |
| 46 | |||
| 47 | // Prepare type of function | ||
| 48 |
2/4✓ Branch 36 → 37 taken 511 times.
✗ Branch 36 → 67 not taken.
✓ Branch 37 → 38 taken 511 times.
✗ Branch 37 → 67 not taken.
|
511 | const QualType functionType = QualType(TY_FUNCTION).getWithFunctionParamAndReturnTypes(returnType, paramTypes); |
| 49 | |||
| 50 | // Update main function symbol type | ||
| 51 |
1/2✓ Branch 40 → 41 taken 511 times.
✗ Branch 40 → 70 not taken.
|
1533 | SymbolTableEntry *functionEntry = rootScope->lookupStrict(MAIN_FUNCTION_NAME); |
| 52 |
1/2✗ Branch 46 → 47 not taken.
✓ Branch 46 → 48 taken 511 times.
|
511 | assert(functionEntry != nullptr); |
| 53 |
1/2✓ Branch 48 → 49 taken 511 times.
✗ Branch 48 → 75 not taken.
|
511 | functionEntry->updateType(functionType, false); |
| 54 | 511 | functionEntry->used = true; | |
| 55 | |||
| 56 | // Leave main function body scope | ||
| 57 | 511 | currentScope = rootScope; | |
| 58 | |||
| 59 |
1/2✓ Branch 49 → 50 taken 511 times.
✗ Branch 49 → 74 not taken.
|
1022 | return nullptr; |
| 60 | 511 | } | |
| 61 | |||
| 62 | 20210 | std::any TypeChecker::visitFctDefPrepare(FctDefNode *node) { | |
| 63 | // Check if name is dtor | ||
| 64 |
3/4✓ Branch 2 → 3 taken 20210 times.
✗ Branch 2 → 424 not taken.
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 13 taken 20209 times.
|
20210 | if (node->name->name == DTOR_FUNCTION_NAME) |
| 65 |
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") |
| 66 | |||
| 67 | // Check if all control paths in the function return | ||
| 68 | 20209 | bool doSetPredecessorsUnreachable = true; | |
| 69 |
3/4✓ Branch 13 → 14 taken 20209 times.
✗ Branch 13 → 424 not taken.
✓ Branch 14 → 15 taken 1 time.
✓ Branch 14 → 24 taken 20208 times.
|
20209 | if (!node->returnsOnAllControlPaths(&doSetPredecessorsUnreachable, manIdx)) |
| 70 |
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") |
| 71 | |||
| 72 | // Change to function scope | ||
| 73 | 20208 | currentScope = node->scope; | |
| 74 |
1/2✗ Branch 24 → 25 not taken.
✓ Branch 24 → 26 taken 20208 times.
|
20208 | assert(currentScope->type == ScopeType::FUNC_PROC_BODY); |
| 75 | |||
| 76 | // Retrieve function template types | ||
| 77 | 20208 | std::vector<GenericType> usedGenericTypes; | |
| 78 |
2/2✓ Branch 26 → 27 taken 2092 times.
✓ Branch 26 → 65 taken 18116 times.
|
20208 | if (node->hasTemplateTypes) { |
| 79 |
2/2✓ Branch 63 → 29 taken 2531 times.
✓ Branch 63 → 64 taken 2091 times.
|
6714 | for (DataTypeNode *dataType : node->templateTypeLst->dataTypes) { |
| 80 | // Visit template type | ||
| 81 |
2/4✓ Branch 31 → 32 taken 2531 times.
✗ Branch 31 → 295 not taken.
✓ Branch 32 → 33 taken 2531 times.
✗ Branch 32 → 293 not taken.
|
2531 | auto templateType = std::any_cast<QualType>(visit(dataType)); |
| 82 |
2/4✓ Branch 34 → 35 taken 2531 times.
✗ Branch 34 → 305 not taken.
✗ Branch 35 → 36 not taken.
✓ Branch 35 → 37 taken 2531 times.
|
2531 | if (templateType.is(TY_UNRESOLVED)) |
| 83 | ✗ | continue; | |
| 84 | // Check if it is a generic type | ||
| 85 |
3/4✓ Branch 37 → 38 taken 2531 times.
✗ Branch 37 → 305 not taken.
✓ Branch 38 → 39 taken 1 time.
✓ Branch 38 → 47 taken 2530 times.
|
2531 | if (!templateType.is(TY_GENERIC)) |
| 86 |
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"); |
| 87 | // Convert generic symbol type to generic type | ||
| 88 |
2/4✓ Branch 47 → 48 taken 2530 times.
✗ Branch 47 → 305 not taken.
✓ Branch 48 → 49 taken 2530 times.
✗ Branch 48 → 305 not taken.
|
2530 | GenericType *genericType = rootScope->lookupGenericTypeStrict(templateType.getSubType()); |
| 89 |
1/2✗ Branch 49 → 50 not taken.
✓ Branch 49 → 51 taken 2530 times.
|
2530 | assert(genericType != nullptr); |
| 90 |
1/2✓ Branch 51 → 52 taken 2530 times.
✗ Branch 51 → 305 not taken.
|
2530 | usedGenericTypes.push_back(*genericType); |
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | // Retrieve 'this' type | ||
| 95 |
1/2✓ Branch 65 → 66 taken 20207 times.
✗ Branch 65 → 422 not taken.
|
20207 | QualType thisType(TY_DYN); // If the function is not a method, the default this type is TY_DYN |
| 96 |
2/2✓ Branch 66 → 67 taken 10093 times.
✓ Branch 66 → 105 taken 10114 times.
|
20207 | if (node->isMethod) { |
| 97 | 10093 | Scope *structParentScope = node->structScope->parent; | |
| 98 |
1/2✓ Branch 67 → 68 taken 10093 times.
✗ Branch 67 → 315 not taken.
|
10093 | SymbolTableEntry *structEntry = structParentScope->lookupStrict(node->name->structName); |
| 99 |
1/2✗ Branch 70 → 71 not taken.
✓ Branch 70 → 72 taken 10093 times.
|
10093 | assert(structEntry != nullptr); |
| 100 | // Set struct to used | ||
| 101 | 10093 | structEntry->used = true; | |
| 102 | // Get type and ptr type | ||
| 103 |
1/2✓ Branch 72 → 73 taken 10093 times.
✗ Branch 72 → 315 not taken.
|
10093 | thisType = structEntry->getQualType(); |
| 104 |
1/2✓ Branch 73 → 74 taken 10093 times.
✗ Branch 73 → 315 not taken.
|
10093 | const QualType thisPtrType = thisType.toPtr(node); |
| 105 | // Collect template types of 'this' type | ||
| 106 |
3/4✓ Branch 74 → 75 taken 10093 times.
✗ Branch 74 → 308 not taken.
✓ Branch 92 → 77 taken 3338 times.
✓ Branch 92 → 93 taken 10093 times.
|
23524 | for (const QualType &templateType : thisType.getTemplateTypes()) { |
| 107 | 801 | const auto lambda = [&](const GenericType &genericType) { return genericType == templateType; }; | |
| 108 |
3/4✓ Branch 79 → 80 taken 3338 times.
✗ Branch 79 → 307 not taken.
✓ Branch 80 → 81 taken 3330 times.
✓ Branch 80 → 82 taken 8 times.
|
3338 | if (std::ranges::none_of(usedGenericTypes, lambda)) |
| 109 |
1/2✓ Branch 81 → 82 taken 3330 times.
✗ Branch 81 → 307 not taken.
|
3330 | usedGenericTypes.emplace_back(templateType); |
| 110 | 3338 | usedGenericTypes.back().used = true; | |
| 111 | } | ||
| 112 | |||
| 113 | // Set type of 'this' variable | ||
| 114 |
1/2✓ Branch 95 → 96 taken 10093 times.
✗ Branch 95 → 311 not taken.
|
30279 | SymbolTableEntry *thisEntry = currentScope->lookupStrict(THIS_VARIABLE_NAME); |
| 115 |
1/2✗ Branch 101 → 102 not taken.
✓ Branch 101 → 103 taken 10093 times.
|
10093 | assert(thisEntry != nullptr); |
| 116 |
1/2✓ Branch 103 → 104 taken 10093 times.
✗ Branch 103 → 315 not taken.
|
10093 | thisEntry->updateType(thisPtrType, false); |
| 117 | } | ||
| 118 | |||
| 119 | // Visit parameters | ||
| 120 | 20207 | QualTypeList paramTypes; | |
| 121 | 20207 | ParamList paramList; | |
| 122 |
2/2✓ Branch 105 → 106 taken 15049 times.
✓ Branch 105 → 152 taken 5158 times.
|
20207 | if (node->hasParams) { |
| 123 | 15049 | std::vector<const char *> paramNames; | |
| 124 | // Visit param list to retrieve the param names | ||
| 125 |
2/4✓ Branch 106 → 107 taken 15049 times.
✗ Branch 106 → 318 not taken.
✓ Branch 107 → 108 taken 15049 times.
✗ Branch 107 → 316 not taken.
|
15049 | auto namedParamList = std::any_cast<NamedParamList>(visit(node->paramLst)); |
| 126 |
2/2✓ Branch 140 → 111 taken 22747 times.
✓ Branch 140 → 141 taken 15047 times.
|
52843 | for (const auto &[name, qualType, isOptional] : namedParamList) { |
| 127 |
1/2✓ Branch 113 → 114 taken 22747 times.
✗ Branch 113 → 330 not taken.
|
22747 | paramNames.push_back(name); |
| 128 |
2/6✓ Branch 114 → 115 taken 22747 times.
✗ Branch 114 → 330 not taken.
✗ Branch 115 → 116 not taken.
✓ Branch 115 → 119 taken 22747 times.
✗ Branch 116 → 117 not taken.
✗ Branch 116 → 319 not taken.
|
22747 | HANDLE_UNRESOLVED_TYPE_PTR(qualType); |
| 129 |
1/2✓ Branch 119 → 120 taken 22747 times.
✗ Branch 119 → 330 not taken.
|
22747 | paramTypes.push_back(qualType); |
| 130 |
1/2✓ Branch 120 → 121 taken 22747 times.
✗ Branch 120 → 320 not taken.
|
22747 | paramList.push_back({qualType, isOptional}); |
| 131 | // Check if the type is present in the template for generic types | ||
| 132 |
3/4✓ Branch 121 → 122 taken 22747 times.
✗ Branch 121 → 330 not taken.
✓ Branch 122 → 123 taken 2 times.
✓ Branch 122 → 131 taken 22745 times.
|
22747 | if (!qualType.isCoveredByGenericTypeList(usedGenericTypes)) |
| 133 | ✗ | throw SemanticError(node->paramLst, GENERIC_TYPE_NOT_IN_TEMPLATE, | |
| 134 |
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"); |
| 135 | } | ||
| 136 |
2/4✓ Branch 143 → 144 taken 15047 times.
✗ Branch 143 → 145 not taken.
✓ Branch 148 → 149 taken 15047 times.
✗ Branch 148 → 151 not taken.
|
30098 | } |
| 137 | |||
| 138 | // Retrieve return type | ||
| 139 |
2/4✓ Branch 152 → 153 taken 20205 times.
✗ Branch 152 → 338 not taken.
✓ Branch 153 → 154 taken 20205 times.
✗ Branch 153 → 336 not taken.
|
20205 | auto returnType = std::any_cast<QualType>(visit(node->returnType)); |
| 140 |
2/6✓ Branch 155 → 156 taken 20205 times.
✗ Branch 155 → 418 not taken.
✗ Branch 156 → 157 not taken.
✓ Branch 156 → 160 taken 20205 times.
✗ Branch 157 → 158 not taken.
✗ Branch 157 → 339 not taken.
|
20205 | HANDLE_UNRESOLVED_TYPE_PTR(returnType) |
| 141 |
3/4✓ Branch 160 → 161 taken 20205 times.
✗ Branch 160 → 418 not taken.
✓ Branch 161 → 162 taken 1 time.
✓ Branch 161 → 171 taken 20204 times.
|
20205 | if (returnType.is(TY_DYN)) |
| 142 |
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") |
| 143 |
3/4✓ Branch 171 → 172 taken 20204 times.
✗ Branch 171 → 418 not taken.
✓ Branch 172 → 173 taken 1 time.
✓ Branch 172 → 182 taken 20203 times.
|
20204 | if (!returnType.isCoveredByGenericTypeList(usedGenericTypes)) |
| 144 |
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, |
| 145 | "Generic return type not included in the template type list of the function") | ||
| 146 | |||
| 147 | // Leave function body scope | ||
| 148 | 20203 | currentScope = node->scope->parent; | |
| 149 |
3/4✓ Branch 182 → 183 taken 10093 times.
✓ Branch 182 → 185 taken 10110 times.
✗ Branch 183 → 184 not taken.
✓ Branch 183 → 185 taken 10093 times.
|
20203 | assert(currentScope->type == ScopeType::GLOBAL || currentScope->type == ScopeType::STRUCT); |
| 150 | |||
| 151 | // Prepare type of function | ||
| 152 |
2/4✓ Branch 185 → 186 taken 20203 times.
✗ Branch 185 → 354 not taken.
✓ Branch 186 → 187 taken 20203 times.
✗ Branch 186 → 354 not taken.
|
20203 | QualType functionType = QualType(TY_FUNCTION).getWithFunctionParamAndReturnTypes(returnType, paramTypes); |
| 153 | 20203 | functionType.setQualifiers(node->qualifiers); | |
| 154 | |||
| 155 | // Update type of function entry | ||
| 156 |
1/2✓ Branch 188 → 189 taken 20203 times.
✗ Branch 188 → 357 not taken.
|
40406 | SymbolTableEntry *functionEntry = currentScope->lookupStrict(node->getSymbolTableEntryName()); |
| 157 |
1/2✗ Branch 193 → 194 not taken.
✓ Branch 193 → 195 taken 20203 times.
|
20203 | assert(functionEntry != nullptr); |
| 158 |
1/2✓ Branch 195 → 196 taken 20203 times.
✗ Branch 195 → 418 not taken.
|
20203 | functionEntry->updateType(functionType, false); |
| 159 | |||
| 160 | // Build function object | ||
| 161 |
4/8✓ Branch 196 → 197 taken 20203 times.
✗ Branch 196 → 366 not taken.
✓ Branch 197 → 198 taken 20203 times.
✗ Branch 197 → 363 not taken.
✓ Branch 198 → 199 taken 20203 times.
✗ Branch 198 → 360 not taken.
✓ Branch 199 → 200 taken 20203 times.
✗ Branch 199 → 358 not taken.
|
20203 | Function spiceFunc(node->name->name, functionEntry, thisType, returnType, paramList, usedGenericTypes, node); |
| 162 | 20203 | spiceFunc.bodyScope = node->scope; | |
| 163 |
2/2✓ Branch 203 → 204 taken 20202 times.
✓ Branch 203 → 416 taken 1 time.
|
20203 | FunctionManager::insert(currentScope, spiceFunc, &node->manifestations); |
| 164 | |||
| 165 | // Check function attributes | ||
| 166 |
2/2✓ Branch 204 → 205 taken 697 times.
✓ Branch 204 → 252 taken 19505 times.
|
20202 | if (node->attrs) { |
| 167 | 697 | const AttrLstNode *attrLst = node->attrs->attrLst; | |
| 168 | 697 | Function *firstManifestation = node->manifestations.front(); | |
| 169 |
4/6✓ Branch 208 → 209 taken 697 times.
✗ Branch 208 → 369 not taken.
✓ Branch 209 → 210 taken 697 times.
✗ Branch 209 → 367 not taken.
✓ Branch 212 → 213 taken 1 time.
✓ Branch 212 → 214 taken 696 times.
|
2091 | if (const CompileTimeValue *value = attrLst->getAttrValueByName(ATTR_CORE_COMPILER_MANGLE)) |
| 170 | 1 | firstManifestation->mangleFunctionName = value->boolValue; | |
| 171 |
3/6✓ Branch 216 → 217 taken 697 times.
✗ Branch 216 → 375 not taken.
✓ Branch 217 → 218 taken 697 times.
✗ Branch 217 → 373 not taken.
✗ Branch 220 → 221 not taken.
✓ Branch 220 → 223 taken 697 times.
|
2091 | if (const CompileTimeValue *value = attrLst->getAttrValueByName(ATTR_CORE_COMPILER_MANGLED_NAME)) { |
| 172 | ✗ | const std::string &stringValue = resourceManager.compileTimeStringValues.at(value->stringValueOffset); | |
| 173 | ✗ | firstManifestation->predefinedMangledName = stringValue; | |
| 174 | } | ||
| 175 |
6/8✓ Branch 225 → 226 taken 697 times.
✗ Branch 225 → 381 not taken.
✓ Branch 226 → 227 taken 697 times.
✗ Branch 226 → 379 not taken.
✓ Branch 229 → 230 taken 111 times.
✓ Branch 229 → 252 taken 586 times.
✓ Branch 230 → 231 taken 110 times.
✓ Branch 230 → 252 taken 1 time.
|
2091 | if (const CompileTimeValue *value = attrLst->getAttrValueByName(ATTR_TEST); value && value->boolValue) { |
| 176 | // Make sure that the function has the correct signature | ||
| 177 |
2/2✓ Branch 231 → 232 taken 1 time.
✓ Branch 231 → 240 taken 109 times.
|
110 | if (node->hasParams) |
| 178 |
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"); |
| 179 |
3/4✓ Branch 240 → 241 taken 109 times.
✗ Branch 240 → 416 not taken.
✓ Branch 241 → 242 taken 1 time.
✓ Branch 241 → 250 taken 108 times.
|
109 | if (!returnType.is(TY_BOOL)) |
| 180 |
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"); |
| 181 | // Add to test function list | ||
| 182 | 108 | firstManifestation->entry->used = true; // Avoid printing unused warnings | |
| 183 | 108 | firstManifestation->used = true; // Always keep test functions, because they are called implicitly by the test main | |
| 184 |
1/2✓ Branch 251 → 252 taken 108 times.
✗ Branch 251 → 416 not taken.
|
108 | sourceFile->testFunctions.push_back(node->manifestations.front()); |
| 185 | } | ||
| 186 | } | ||
| 187 | |||
| 188 | // Duplicate / rename the original child scope to reflect the substantiated versions of the function | ||
| 189 |
2/2✓ Branch 262 → 253 taken 1725 times.
✓ Branch 262 → 263 taken 20200 times.
|
21925 | for (size_t i = 1; i < node->manifestations.size(); i++) { |
| 190 |
4/8✓ Branch 253 → 254 taken 1725 times.
✗ Branch 253 → 408 not taken.
✓ Branch 254 → 255 taken 1725 times.
✗ Branch 254 → 408 not taken.
✓ Branch 255 → 256 taken 1725 times.
✗ Branch 255 → 405 not taken.
✓ Branch 256 → 257 taken 1725 times.
✗ Branch 256 → 403 not taken.
|
1725 | Scope *scope = currentScope->copyChildScope(node->getScopeId(), node->manifestations.at(i)->getScopeName()); |
| 191 |
1/2✓ Branch 259 → 260 taken 1725 times.
✗ Branch 259 → 416 not taken.
|
1725 | node->manifestations.at(i)->bodyScope = scope; |
| 192 | } | ||
| 193 |
3/6✓ Branch 264 → 265 taken 20200 times.
✗ Branch 264 → 414 not taken.
✓ Branch 265 → 266 taken 20200 times.
✗ Branch 265 → 411 not taken.
✓ Branch 266 → 267 taken 20200 times.
✗ Branch 266 → 409 not taken.
|
20200 | currentScope->renameChildScope(node->getScopeId(), node->manifestations.front()->getScopeName()); |
| 194 | |||
| 195 | // Change to the root scope | ||
| 196 | 20200 | currentScope = rootScope; | |
| 197 |
1/2✗ Branch 269 → 270 not taken.
✓ Branch 269 → 271 taken 20200 times.
|
20200 | assert(currentScope->type == ScopeType::GLOBAL); |
| 198 | |||
| 199 |
1/2✓ Branch 271 → 272 taken 20200 times.
✗ Branch 271 → 415 not taken.
|
20200 | return nullptr; |
| 200 | 20221 | } | |
| 201 | |||
| 202 | 10796 | std::any TypeChecker::visitProcDefPrepare(ProcDefNode *node) { | |
| 203 | // Mark unreachable statements | ||
| 204 | 10796 | bool doSetPredecessorsUnreachable = true; | |
| 205 |
1/2✓ Branch 2 → 3 taken 10796 times.
✗ Branch 2 → 316 not taken.
|
10796 | node->returnsOnAllControlPaths(&doSetPredecessorsUnreachable, manIdx); |
| 206 | |||
| 207 | // Check if dtor and has params | ||
| 208 |
7/8✓ Branch 3 → 4 taken 8365 times.
✓ Branch 3 → 7 taken 2431 times.
✓ Branch 4 → 5 taken 8365 times.
✗ Branch 4 → 316 not taken.
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 7 taken 8364 times.
✓ Branch 8 → 9 taken 1 time.
✓ Branch 8 → 17 taken 10795 times.
|
10796 | if (node->hasParams && node->name->name == DTOR_FUNCTION_NAME) |
| 209 |
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"); |
| 210 | |||
| 211 | // Change to procedure scope | ||
| 212 | 10795 | currentScope = node->scope; | |
| 213 |
1/2✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 10795 times.
|
10795 | assert(currentScope->type == ScopeType::FUNC_PROC_BODY); |
| 214 | |||
| 215 | // Retrieve procedure template types | ||
| 216 | 10795 | std::vector<GenericType> usedGenericTypes; | |
| 217 |
2/2✓ Branch 19 → 20 taken 2277 times.
✓ Branch 19 → 58 taken 8518 times.
|
10795 | if (node->hasTemplateTypes) { |
| 218 |
2/2✓ Branch 56 → 22 taken 2590 times.
✓ Branch 56 → 57 taken 2276 times.
|
7143 | for (DataTypeNode *dataType : node->templateTypeLst->dataTypes) { |
| 219 | // Visit template type | ||
| 220 |
2/4✓ Branch 24 → 25 taken 2590 times.
✗ Branch 24 → 227 not taken.
✓ Branch 25 → 26 taken 2590 times.
✗ Branch 25 → 225 not taken.
|
2590 | auto templateType = std::any_cast<QualType>(visit(dataType)); |
| 221 |
2/4✓ Branch 27 → 28 taken 2590 times.
✗ Branch 27 → 237 not taken.
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 2590 times.
|
2590 | if (templateType.is(TY_UNRESOLVED)) |
| 222 | ✗ | continue; | |
| 223 | // Check if it is a generic type | ||
| 224 |
3/4✓ Branch 30 → 31 taken 2590 times.
✗ Branch 30 → 237 not taken.
✓ Branch 31 → 32 taken 1 time.
✓ Branch 31 → 40 taken 2589 times.
|
2590 | if (!templateType.is(TY_GENERIC)) |
| 225 |
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"); |
| 226 | // Convert generic symbol type to generic type | ||
| 227 |
2/4✓ Branch 40 → 41 taken 2589 times.
✗ Branch 40 → 237 not taken.
✓ Branch 41 → 42 taken 2589 times.
✗ Branch 41 → 237 not taken.
|
2589 | const GenericType *genericType = rootScope->lookupGenericTypeStrict(templateType.getSubType()); |
| 228 |
1/2✗ Branch 42 → 43 not taken.
✓ Branch 42 → 44 taken 2589 times.
|
2589 | assert(genericType != nullptr); |
| 229 |
1/2✓ Branch 44 → 45 taken 2589 times.
✗ Branch 44 → 237 not taken.
|
2589 | usedGenericTypes.push_back(*genericType); |
| 230 | } | ||
| 231 | } | ||
| 232 | |||
| 233 | // Retrieve 'this' type | ||
| 234 |
1/2✓ Branch 58 → 59 taken 10794 times.
✗ Branch 58 → 314 not taken.
|
10794 | QualType thisType(TY_DYN); // If the procedure is not a method, the default this type is TY_DYN |
| 235 |
2/2✓ Branch 59 → 60 taken 9015 times.
✓ Branch 59 → 98 taken 1779 times.
|
10794 | if (node->isMethod) { |
| 236 | 9015 | Scope *structParentScope = node->structScope->parent; | |
| 237 |
1/2✓ Branch 60 → 61 taken 9015 times.
✗ Branch 60 → 247 not taken.
|
9015 | SymbolTableEntry *structEntry = structParentScope->lookupStrict(node->name->structName); |
| 238 |
1/2✗ Branch 63 → 64 not taken.
✓ Branch 63 → 65 taken 9015 times.
|
9015 | assert(structEntry != nullptr); |
| 239 | // Set struct to used | ||
| 240 | 9015 | structEntry->used = true; | |
| 241 | // Get type and ptr type | ||
| 242 |
1/2✓ Branch 65 → 66 taken 9015 times.
✗ Branch 65 → 247 not taken.
|
9015 | thisType = structEntry->getQualType(); |
| 243 |
1/2✓ Branch 66 → 67 taken 9015 times.
✗ Branch 66 → 247 not taken.
|
9015 | const QualType thisPtrType = thisType.toPtr(node); |
| 244 | // Collect template types of 'this' type | ||
| 245 |
3/4✓ Branch 67 → 68 taken 9015 times.
✗ Branch 67 → 240 not taken.
✓ Branch 85 → 70 taken 3139 times.
✓ Branch 85 → 86 taken 9015 times.
|
21169 | for (const QualType &templateType : thisType.getTemplateTypes()) { |
| 246 | 953 | const auto lambda = [&](const GenericType &genericType) { return genericType == templateType; }; | |
| 247 |
3/4✓ Branch 72 → 73 taken 3139 times.
✗ Branch 72 → 239 not taken.
✓ Branch 73 → 74 taken 2876 times.
✓ Branch 73 → 75 taken 263 times.
|
3139 | if (std::ranges::none_of(usedGenericTypes, lambda)) |
| 248 |
1/2✓ Branch 74 → 75 taken 2876 times.
✗ Branch 74 → 239 not taken.
|
2876 | usedGenericTypes.emplace_back(templateType); |
| 249 | 3139 | usedGenericTypes.back().used = true; | |
| 250 | } | ||
| 251 | |||
| 252 | // Set type of 'this' variable | ||
| 253 |
1/2✓ Branch 88 → 89 taken 9015 times.
✗ Branch 88 → 243 not taken.
|
27045 | SymbolTableEntry *thisEntry = currentScope->lookupStrict(THIS_VARIABLE_NAME); |
| 254 |
1/2✗ Branch 94 → 95 not taken.
✓ Branch 94 → 96 taken 9015 times.
|
9015 | assert(thisEntry != nullptr); |
| 255 |
1/2✓ Branch 96 → 97 taken 9015 times.
✗ Branch 96 → 247 not taken.
|
9015 | thisEntry->updateType(thisPtrType, false); |
| 256 | } | ||
| 257 | |||
| 258 | // Visit parameters | ||
| 259 | 10794 | QualTypeList paramTypes; | |
| 260 | 10794 | ParamList paramList; | |
| 261 |
2/2✓ Branch 98 → 99 taken 8364 times.
✓ Branch 98 → 145 taken 2430 times.
|
10794 | if (node->hasParams) { |
| 262 | 8364 | std::vector<const char *> paramNames; | |
| 263 | // Visit param list to retrieve the param names | ||
| 264 |
2/4✓ Branch 99 → 100 taken 8364 times.
✗ Branch 99 → 250 not taken.
✓ Branch 100 → 101 taken 8364 times.
✗ Branch 100 → 248 not taken.
|
8364 | auto namedParamList = std::any_cast<NamedParamList>(visit(node->paramLst)); |
| 265 |
2/2✓ Branch 133 → 104 taken 11421 times.
✓ Branch 133 → 134 taken 8362 times.
|
28147 | for (const auto &[name, qualType, isOptional] : namedParamList) { |
| 266 |
1/2✓ Branch 106 → 107 taken 11421 times.
✗ Branch 106 → 262 not taken.
|
11421 | paramNames.push_back(name); |
| 267 |
1/2✓ Branch 107 → 108 taken 11421 times.
✗ Branch 107 → 262 not taken.
|
11421 | paramTypes.push_back(qualType); |
| 268 |
4/6✓ Branch 108 → 109 taken 11421 times.
✗ Branch 108 → 262 not taken.
✓ Branch 109 → 110 taken 1 time.
✓ Branch 109 → 113 taken 11420 times.
✓ Branch 110 → 111 taken 1 time.
✗ Branch 110 → 251 not taken.
|
11422 | HANDLE_UNRESOLVED_TYPE_PTR(qualType); |
| 269 |
1/2✓ Branch 113 → 114 taken 11420 times.
✗ Branch 113 → 252 not taken.
|
11420 | paramList.push_back({qualType, isOptional}); |
| 270 | // Check if the type is present in the template for generic types | ||
| 271 |
3/4✓ Branch 114 → 115 taken 11420 times.
✗ Branch 114 → 262 not taken.
✓ Branch 115 → 116 taken 1 time.
✓ Branch 115 → 124 taken 11419 times.
|
11420 | if (!qualType.isCoveredByGenericTypeList(usedGenericTypes)) |
| 272 | ✗ | throw SemanticError(node->paramLst, GENERIC_TYPE_NOT_IN_TEMPLATE, | |
| 273 |
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"); |
| 274 | } | ||
| 275 |
4/4✓ Branch 136 → 137 taken 8362 times.
✓ Branch 136 → 138 taken 1 time.
✓ Branch 141 → 142 taken 8362 times.
✓ Branch 141 → 144 taken 1 time.
|
16728 | } |
| 276 | |||
| 277 | // Leave procedure body scope | ||
| 278 | 10792 | currentScope = node->scope->parent; | |
| 279 |
3/4✓ Branch 145 → 146 taken 9015 times.
✓ Branch 145 → 148 taken 1777 times.
✗ Branch 146 → 147 not taken.
✓ Branch 146 → 148 taken 9015 times.
|
10792 | assert(currentScope->type == ScopeType::GLOBAL || currentScope->type == ScopeType::STRUCT); |
| 280 | |||
| 281 | // Prepare type of procedure | ||
| 282 |
3/6✓ Branch 148 → 149 taken 10792 times.
✗ Branch 148 → 269 not taken.
✓ Branch 149 → 150 taken 10792 times.
✗ Branch 149 → 268 not taken.
✓ Branch 150 → 151 taken 10792 times.
✗ Branch 150 → 268 not taken.
|
10792 | QualType procedureType = QualType(TY_PROCEDURE).getWithFunctionParamAndReturnTypes(QualType(TY_DYN), paramTypes); |
| 283 | 10792 | procedureType.setQualifiers(node->qualifiers); | |
| 284 | |||
| 285 | // Update type of procedure entry | ||
| 286 |
1/2✓ Branch 152 → 153 taken 10792 times.
✗ Branch 152 → 272 not taken.
|
21584 | SymbolTableEntry *procedureEntry = currentScope->lookupStrict(node->getSymbolTableEntryName()); |
| 287 |
1/2✗ Branch 157 → 158 not taken.
✓ Branch 157 → 159 taken 10792 times.
|
10792 | assert(procedureEntry != nullptr); |
| 288 |
1/2✓ Branch 159 → 160 taken 10792 times.
✗ Branch 159 → 310 not taken.
|
10792 | procedureEntry->updateType(procedureType, false); |
| 289 | |||
| 290 | // Build procedure object | ||
| 291 |
5/10✓ Branch 160 → 161 taken 10792 times.
✗ Branch 160 → 282 not taken.
✓ Branch 161 → 162 taken 10792 times.
✗ Branch 161 → 279 not taken.
✓ Branch 162 → 163 taken 10792 times.
✗ Branch 162 → 276 not taken.
✓ Branch 163 → 164 taken 10792 times.
✗ Branch 163 → 275 not taken.
✓ Branch 164 → 165 taken 10792 times.
✗ Branch 164 → 273 not taken.
|
10792 | Function spiceProc(node->name->name, procedureEntry, thisType, QualType(TY_DYN), paramList, usedGenericTypes, node); |
| 292 | 10792 | spiceProc.bodyScope = node->scope; | |
| 293 |
2/2✓ Branch 168 → 169 taken 10791 times.
✓ Branch 168 → 308 taken 1 time.
|
10792 | FunctionManager::insert(currentScope, spiceProc, &node->manifestations); |
| 294 | |||
| 295 | // Check procedure attributes | ||
| 296 |
1/2✗ Branch 169 → 170 not taken.
✓ Branch 169 → 189 taken 10791 times.
|
10791 | if (node->attrs) { |
| 297 | ✗ | const AttrLstNode *attrLst = node->attrs->attrLst; | |
| 298 | ✗ | if (const CompileTimeValue *value = attrLst->getAttrValueByName(ATTR_CORE_COMPILER_MANGLE)) | |
| 299 | ✗ | node->manifestations.front()->mangleFunctionName = value->boolValue; | |
| 300 | ✗ | if (const CompileTimeValue *value = attrLst->getAttrValueByName(ATTR_CORE_COMPILER_MANGLED_NAME)) { | |
| 301 | ✗ | const std::string &stringValue = resourceManager.compileTimeStringValues.at(value->stringValueOffset); | |
| 302 | ✗ | node->manifestations.front()->predefinedMangledName = stringValue; | |
| 303 | } | ||
| 304 | } | ||
| 305 | |||
| 306 | // Duplicate / rename the original child scope to reflect the substantiated versions of the procedure | ||
| 307 |
2/2✓ Branch 199 → 190 taken 538 times.
✓ Branch 199 → 200 taken 10791 times.
|
11329 | for (size_t i = 1; i < node->manifestations.size(); i++) { |
| 308 |
4/8✓ Branch 190 → 191 taken 538 times.
✗ Branch 190 → 300 not taken.
✓ Branch 191 → 192 taken 538 times.
✗ Branch 191 → 300 not taken.
✓ Branch 192 → 193 taken 538 times.
✗ Branch 192 → 297 not taken.
✓ Branch 193 → 194 taken 538 times.
✗ Branch 193 → 295 not taken.
|
538 | Scope *scope = currentScope->copyChildScope(node->getScopeId(), node->manifestations.at(i)->getScopeName()); |
| 309 |
1/2✓ Branch 196 → 197 taken 538 times.
✗ Branch 196 → 308 not taken.
|
538 | node->manifestations.at(i)->bodyScope = scope; |
| 310 | } | ||
| 311 |
3/6✓ Branch 201 → 202 taken 10791 times.
✗ Branch 201 → 306 not taken.
✓ Branch 202 → 203 taken 10791 times.
✗ Branch 202 → 303 not taken.
✓ Branch 203 → 204 taken 10791 times.
✗ Branch 203 → 301 not taken.
|
10791 | currentScope->renameChildScope(node->getScopeId(), node->manifestations.front()->getScopeName()); |
| 312 | |||
| 313 | // Change to the root scope | ||
| 314 | 10791 | currentScope = rootScope; | |
| 315 |
1/2✗ Branch 206 → 207 not taken.
✓ Branch 206 → 208 taken 10791 times.
|
10791 | assert(currentScope->type == ScopeType::GLOBAL); |
| 316 | |||
| 317 |
1/2✓ Branch 208 → 209 taken 10791 times.
✗ Branch 208 → 307 not taken.
|
10791 | return nullptr; |
| 318 | 10800 | } | |
| 319 | |||
| 320 | /** | ||
| 321 | * Determine whether a field type (transitively) contains a struct with the given origin body scope by value, which would | ||
| 322 | * give the origin struct an infinite size. Only by-value struct fields are followed; pointers and references break the | ||
| 323 | * cycle and have a fixed size. Struct types that are not manifested yet (e.g. still being prepared as part of a circular | ||
| 324 | * import) end a branch - such a cycle is still detected once the last struct in it is prepared, when all the others are | ||
| 325 | * manifested. | ||
| 326 | * | ||
| 327 | * @param fieldType Type of the field to inspect | ||
| 328 | * @param originScope Body scope of the struct whose infinite size we are checking for | ||
| 329 | * @param node Accessing AST node (for struct lookup diagnostics) | ||
| 330 | * @param visited Set of already-visited struct scopes, to keep the walk finite | ||
| 331 | * @return true if the origin struct is reachable by value, i.e. it has infinite size | ||
| 332 | */ | ||
| 333 | 20565 | static bool fieldContainsStructByValue(const QualType &fieldType, const Scope *originScope, const ASTNode *node, | |
| 334 | std::unordered_set<const Scope *> &visited) { | ||
| 335 |
3/4✓ Branch 2 → 3 taken 20565 times.
✗ Branch 2 → 22 not taken.
✓ Branch 3 → 4 taken 14848 times.
✓ Branch 3 → 5 taken 5717 times.
|
20565 | if (!fieldType.is(TY_STRUCT)) |
| 336 | 14848 | return false; | |
| 337 |
1/2✓ Branch 5 → 6 taken 5717 times.
✗ Branch 5 → 22 not taken.
|
5717 | const Scope *fieldScope = fieldType.getBodyScope(); |
| 338 |
2/2✓ Branch 6 → 7 taken 1 time.
✓ Branch 6 → 8 taken 5716 times.
|
5717 | if (fieldScope == originScope) |
| 339 | 1 | return true; | |
| 340 |
6/8✓ Branch 8 → 9 taken 5716 times.
✗ Branch 8 → 11 not taken.
✓ Branch 9 → 10 taken 5716 times.
✗ Branch 9 → 22 not taken.
✓ Branch 10 → 11 taken 94 times.
✓ Branch 10 → 12 taken 5622 times.
✓ Branch 13 → 14 taken 94 times.
✓ Branch 13 → 15 taken 5622 times.
|
5716 | if (fieldScope == nullptr || !visited.insert(fieldScope).second) |
| 341 | 94 | return false; | |
| 342 |
1/2✓ Branch 15 → 16 taken 5622 times.
✗ Branch 15 → 22 not taken.
|
5622 | const Struct *spiceStruct = fieldType.getStruct(node); |
| 343 |
2/2✓ Branch 16 → 17 taken 1 time.
✓ Branch 16 → 18 taken 5621 times.
|
5622 | if (spiceStruct == nullptr) |
| 344 | 1 | return false; // Not manifested yet; the cycle is caught once the last struct in it is prepared | |
| 345 |
1/2✓ Branch 18 → 19 taken 5621 times.
✗ Branch 18 → 22 not taken.
|
5621 | return std::ranges::any_of(spiceStruct->fieldTypes, [&](const QualType &memberType) { |
| 346 | 15084 | return fieldContainsStructByValue(memberType, originScope, node, visited); | |
| 347 | 5621 | }); | |
| 348 | } | ||
| 349 | |||
| 350 | 2989 | std::any TypeChecker::visitStructDefPrepare(StructDefNode *node) { | |
| 351 | 2989 | QualTypeList usedTemplateTypes; | |
| 352 | 2989 | std::vector<GenericType> templateTypesGeneric; | |
| 353 | |||
| 354 | // Retrieve struct template types | ||
| 355 |
2/2✓ Branch 2 → 3 taken 630 times.
✓ Branch 2 → 46 taken 2359 times.
|
2989 | if (node->hasTemplateTypes) { |
| 356 |
1/2✓ Branch 4 → 5 taken 630 times.
✗ Branch 4 → 318 not taken.
|
630 | usedTemplateTypes.reserve(node->templateTypeLst->dataTypes.size()); |
| 357 |
1/2✓ Branch 6 → 7 taken 630 times.
✗ Branch 6 → 318 not taken.
|
630 | templateTypesGeneric.reserve(node->templateTypeLst->dataTypes.size()); |
| 358 |
2/2✓ Branch 44 → 9 taken 854 times.
✓ Branch 44 → 45 taken 630 times.
|
2114 | for (DataTypeNode *dataType : node->templateTypeLst->dataTypes) { |
| 359 | // Visit template type | ||
| 360 |
2/4✓ Branch 11 → 12 taken 854 times.
✗ Branch 11 → 220 not taken.
✓ Branch 12 → 13 taken 854 times.
✗ Branch 12 → 218 not taken.
|
854 | auto templateType = std::any_cast<QualType>(visit(dataType)); |
| 361 |
2/4✓ Branch 14 → 15 taken 854 times.
✗ Branch 14 → 230 not taken.
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 854 times.
|
854 | if (templateType.is(TY_UNRESOLVED)) |
| 362 | ✗ | continue; | |
| 363 | // Check if it is a generic type | ||
| 364 |
2/4✓ Branch 17 → 18 taken 854 times.
✗ Branch 17 → 230 not taken.
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 27 taken 854 times.
|
854 | if (!templateType.is(TY_GENERIC)) |
| 365 | ✗ | throw SemanticError(dataType, EXPECTED_GENERIC_TYPE, "A template list can only contain generic types"); | |
| 366 | // Convert generic symbol type to generic type | ||
| 367 |
2/4✓ Branch 27 → 28 taken 854 times.
✗ Branch 27 → 230 not taken.
✓ Branch 28 → 29 taken 854 times.
✗ Branch 28 → 230 not taken.
|
854 | GenericType *genericType = rootScope->lookupGenericTypeStrict(templateType.getSubType()); |
| 368 |
1/2✗ Branch 29 → 30 not taken.
✓ Branch 29 → 31 taken 854 times.
|
854 | assert(genericType != nullptr); |
| 369 |
1/2✓ Branch 31 → 32 taken 854 times.
✗ Branch 31 → 230 not taken.
|
854 | usedTemplateTypes.push_back(*genericType); |
| 370 |
1/2✓ Branch 32 → 33 taken 854 times.
✗ Branch 32 → 230 not taken.
|
854 | templateTypesGeneric.push_back(*genericType); |
| 371 | } | ||
| 372 | } | ||
| 373 | |||
| 374 | // Retrieve implemented interfaces | ||
| 375 | 2989 | QualTypeList interfaceTypes; | |
| 376 |
2/2✓ Branch 46 → 47 taken 375 times.
✓ Branch 46 → 107 taken 2614 times.
|
2989 | if (node->hasInterfaces) { |
| 377 |
1/2✓ Branch 48 → 49 taken 375 times.
✗ Branch 48 → 316 not taken.
|
375 | interfaceTypes.reserve(node->interfaceTypeLst->dataTypes.size()); |
| 378 |
2/2✓ Branch 105 → 51 taken 375 times.
✓ Branch 105 → 106 taken 374 times.
|
1124 | for (DataTypeNode *interfaceNode : node->interfaceTypeLst->dataTypes) { |
| 379 | // Visit interface type | ||
| 380 |
2/4✓ Branch 53 → 54 taken 375 times.
✗ Branch 53 → 234 not taken.
✓ Branch 54 → 55 taken 375 times.
✗ Branch 54 → 232 not taken.
|
375 | auto interfaceType = std::any_cast<QualType>(visit(interfaceNode)); |
| 381 |
2/4✓ Branch 56 → 57 taken 375 times.
✗ Branch 56 → 256 not taken.
✗ Branch 57 → 58 not taken.
✓ Branch 57 → 59 taken 375 times.
|
375 | if (interfaceType.is(TY_UNRESOLVED)) |
| 382 | ✗ | continue; | |
| 383 | // Check if it is an interface type | ||
| 384 |
2/4✓ Branch 59 → 60 taken 375 times.
✗ Branch 59 → 256 not taken.
✗ Branch 60 → 61 not taken.
✓ Branch 60 → 68 taken 375 times.
|
375 | if (!interfaceType.is(TY_INTERFACE)) |
| 385 | ✗ | throw SemanticError(interfaceNode, EXPECTED_INTERFACE_TYPE, | |
| 386 | ✗ | "Expected interface type, got " + interfaceType.getName(false)); | |
| 387 | // Check for visibility | ||
| 388 |
9/12✓ Branch 68 → 69 taken 375 times.
✗ Branch 68 → 256 not taken.
✓ Branch 69 → 70 taken 375 times.
✗ Branch 69 → 256 not taken.
✓ Branch 70 → 71 taken 337 times.
✓ Branch 70 → 74 taken 38 times.
✓ Branch 71 → 72 taken 337 times.
✗ Branch 71 → 256 not taken.
✓ Branch 72 → 73 taken 1 time.
✓ Branch 72 → 74 taken 336 times.
✓ Branch 75 → 76 taken 1 time.
✓ Branch 75 → 84 taken 374 times.
|
375 | if (interfaceType.getBodyScope()->isImportedBy(rootScope) && !interfaceType.isPublic()) |
| 389 | ✗ | throw SemanticError(node, INSUFFICIENT_VISIBILITY, | |
| 390 |
4/8✓ Branch 77 → 78 taken 1 time.
✗ Branch 77 → 249 not taken.
✓ Branch 78 → 79 taken 1 time.
✗ Branch 78 → 249 not taken.
✓ Branch 79 → 80 taken 1 time.
✗ Branch 79 → 247 not taken.
✓ Branch 80 → 81 taken 1 time.
✗ Branch 80 → 244 not taken.
|
1 | "Cannot access interface '" + interfaceType.getSubType() + "' due to its private visibility"); |
| 391 | // Add to interface types | ||
| 392 |
1/2✓ Branch 84 → 85 taken 374 times.
✗ Branch 84 → 256 not taken.
|
374 | interfaceTypes.push_back(interfaceType); |
| 393 | // Update the type of the entry for that interface field | ||
| 394 | 374 | const std::string &interfaceName = interfaceNode->baseDataType->customDataType->typeNameFragments.back(); | |
| 395 |
1/2✓ Branch 86 → 87 taken 374 times.
✗ Branch 86 → 255 not taken.
|
748 | SymbolTableEntry *interfaceEntry = node->structScope->lookupStrict("this." + interfaceName); |
| 396 |
1/2✗ Branch 91 → 92 not taken.
✓ Branch 91 → 93 taken 374 times.
|
374 | assert(interfaceEntry != nullptr); |
| 397 |
1/2✓ Branch 93 → 94 taken 374 times.
✗ Branch 93 → 256 not taken.
|
374 | interfaceEntry->updateType(interfaceType, false); |
| 398 | } | ||
| 399 | } | ||
| 400 | |||
| 401 | // Update type of struct entry | ||
| 402 |
1/2✗ Branch 107 → 108 not taken.
✓ Branch 107 → 109 taken 2988 times.
|
2988 | assert(node->entry != nullptr); |
| 403 | 2988 | const TypeChainElementData data = {.bodyScope = node->structScope}; | |
| 404 |
1/2✓ Branch 109 → 110 taken 2988 times.
✗ Branch 109 → 316 not taken.
|
2988 | const Type *type = TypeRegistry::getOrInsert(TY_STRUCT, node->structName, node->typeId, data, usedTemplateTypes); |
| 405 | // If the entry was implicitly forward-declared because it is referenced across a circular import | ||
| 406 | // (assignDeferredOpaqueType), the existing type was already set to the opaque struct type. Overwriting it with the | ||
| 407 | // identical interned type is expected here. | ||
| 408 |
2/4✓ Branch 110 → 111 taken 2988 times.
✗ Branch 110 → 316 not taken.
✓ Branch 111 → 112 taken 2988 times.
✗ Branch 111 → 316 not taken.
|
2988 | const bool overwrite = node->entry->getQualType().is(TY_STRUCT); |
| 409 |
2/4✓ Branch 112 → 113 taken 2988 times.
✗ Branch 112 → 258 not taken.
✓ Branch 113 → 114 taken 2988 times.
✗ Branch 113 → 258 not taken.
|
2988 | node->entry->updateType(QualType(type, node->qualifiers), overwrite); |
| 410 | |||
| 411 | // Change to struct scope | ||
| 412 | 2988 | currentScope = node->structScope; | |
| 413 |
1/2✗ Branch 114 → 115 not taken.
✓ Branch 114 → 116 taken 2988 times.
|
2988 | assert(currentScope->type == ScopeType::STRUCT); |
| 414 | |||
| 415 | // Retrieve field types | ||
| 416 | 2988 | QualTypeList fieldTypes; | |
| 417 |
1/2✓ Branch 117 → 118 taken 2988 times.
✗ Branch 117 → 314 not taken.
|
2988 | fieldTypes.reserve(node->fields.size()); |
| 418 | // Shared across all fields: the origin (node->structScope) is constant, so a struct already proven not to reach it | ||
| 419 | // via one field need not be re-walked for another. | ||
| 420 | 2988 | std::unordered_set<const Scope *> visitedScopes; | |
| 421 |
2/2✓ Branch 165 → 121 taken 5483 times.
✓ Branch 165 → 166 taken 2984 times.
|
11455 | for (FieldNode *field : node->fields) { |
| 422 | // Visit field type | ||
| 423 |
2/4✓ Branch 123 → 124 taken 5483 times.
✗ Branch 123 → 261 not taken.
✓ Branch 124 → 125 taken 5483 times.
✗ Branch 124 → 259 not taken.
|
5483 | auto fieldType = std::any_cast<QualType>(visit(field)); |
| 424 |
3/4✓ Branch 126 → 127 taken 5483 times.
✗ Branch 126 → 280 not taken.
✓ Branch 127 → 128 taken 2 times.
✓ Branch 127 → 129 taken 5481 times.
|
5483 | if (fieldType.is(TY_UNRESOLVED)) |
| 425 |
1/2✗ Branch 128 → 129 not taken.
✓ Branch 128 → 280 taken 2 times.
|
2 | sourceFile->checkForSoftErrors(); // We get into trouble if we continue without the field type -> abort |
| 426 | |||
| 427 | // Check for struct with infinite size. This happens if a struct (transitively, through by-value struct fields) | ||
| 428 | // contains itself - either directly (struct A has a field of type A) or through a cycle of structs in mutually | ||
| 429 | // importing files (A has a field of type B and B has a field of type A). | ||
| 430 |
3/4✓ Branch 129 → 130 taken 5481 times.
✗ Branch 129 → 280 not taken.
✓ Branch 130 → 131 taken 1 time.
✓ Branch 130 → 139 taken 5480 times.
|
5481 | if (fieldContainsStructByValue(fieldType, node->structScope, field, visitedScopes)) |
| 431 |
2/4✓ Branch 134 → 135 taken 1 time.
✗ Branch 134 → 265 not taken.
✓ Branch 135 → 136 taken 1 time.
✗ Branch 135 → 262 not taken.
|
3 | throw SemanticError(field, STRUCT_INFINITE_SIZE, "Struct with infinite size detected"); |
| 432 | |||
| 433 | // Add to field types | ||
| 434 |
1/2✓ Branch 139 → 140 taken 5480 times.
✗ Branch 139 → 280 not taken.
|
5480 | fieldTypes.push_back(fieldType); |
| 435 | |||
| 436 | // Update type of field entry | ||
| 437 |
1/2✓ Branch 140 → 141 taken 5480 times.
✗ Branch 140 → 280 not taken.
|
5480 | SymbolTableEntry *fieldEntry = currentScope->lookupStrict(field->fieldName); |
| 438 |
1/2✗ Branch 143 → 144 not taken.
✓ Branch 143 → 145 taken 5480 times.
|
5480 | assert(fieldEntry != nullptr); |
| 439 |
1/2✓ Branch 145 → 146 taken 5480 times.
✗ Branch 145 → 280 not taken.
|
5480 | fieldEntry->updateType(fieldType, false); |
| 440 | |||
| 441 | // Check if the template type list contains this type | ||
| 442 |
3/4✓ Branch 146 → 147 taken 5480 times.
✗ Branch 146 → 280 not taken.
✓ Branch 147 → 148 taken 1 time.
✓ Branch 147 → 156 taken 5479 times.
|
5480 | if (!fieldType.isCoveredByGenericTypeList(templateTypesGeneric)) |
| 443 |
2/4✓ Branch 151 → 152 taken 1 time.
✗ Branch 151 → 274 not taken.
✓ Branch 152 → 153 taken 1 time.
✗ Branch 152 → 271 not taken.
|
3 | throw SemanticError(field->dataType, GENERIC_TYPE_NOT_IN_TEMPLATE, "Generic field type not included in struct template"); |
| 444 | } | ||
| 445 | |||
| 446 | // Change to the root scope | ||
| 447 | 2984 | currentScope = rootScope; | |
| 448 |
1/2✗ Branch 166 → 167 not taken.
✓ Branch 166 → 168 taken 2984 times.
|
2984 | assert(currentScope->type == ScopeType::GLOBAL); |
| 449 | |||
| 450 | // Build struct object | ||
| 451 |
5/10✓ Branch 168 → 169 taken 2984 times.
✗ Branch 168 → 293 not taken.
✓ Branch 169 → 170 taken 2984 times.
✗ Branch 169 → 290 not taken.
✓ Branch 170 → 171 taken 2984 times.
✗ Branch 170 → 287 not taken.
✓ Branch 171 → 172 taken 2984 times.
✗ Branch 171 → 284 not taken.
✓ Branch 172 → 173 taken 2984 times.
✗ Branch 172 → 282 not taken.
|
2984 | Struct spiceStruct(node->structName, node->entry, node->structScope, fieldTypes, templateTypesGeneric, interfaceTypes, node); |
| 452 |
1/2✓ Branch 177 → 178 taken 2984 times.
✗ Branch 177 → 310 not taken.
|
2984 | StructManager::insert(currentScope, spiceStruct, &node->structManifestations); |
| 453 | 2984 | spiceStruct.scope = node->structScope; | |
| 454 | |||
| 455 | // Request RTTI runtime if the struct is polymorphic | ||
| 456 | 2984 | node->emitVTable |= node->hasInterfaces; | |
| 457 |
12/18✓ Branch 178 → 179 taken 106 times.
✓ Branch 178 → 185 taken 2878 times.
✓ Branch 181 → 182 taken 106 times.
✗ Branch 181 → 294 not taken.
✓ Branch 182 → 183 taken 106 times.
✗ Branch 182 → 294 not taken.
✓ Branch 183 → 184 taken 105 times.
✓ Branch 183 → 185 taken 1 time.
✓ Branch 186 → 187 taken 106 times.
✓ Branch 186 → 188 taken 2878 times.
✓ Branch 188 → 189 taken 106 times.
✓ Branch 188 → 191 taken 2878 times.
✓ Branch 191 → 192 taken 105 times.
✓ Branch 191 → 199 taken 2879 times.
✗ Branch 294 → 295 not taken.
✗ Branch 294 → 296 not taken.
✗ Branch 298 → 299 not taken.
✗ Branch 298 → 301 not taken.
|
3196 | if (node->attrs && node->attrs->attrLst->hasAttr(ATTR_CORE_COMPILER_EMIT_VTABLE)) |
| 458 |
2/4✓ Branch 194 → 195 taken 105 times.
✗ Branch 194 → 305 not taken.
✓ Branch 195 → 196 taken 105 times.
✗ Branch 195 → 303 not taken.
|
315 | node->emitVTable |= node->attrs->attrLst->getAttrValueByName(ATTR_CORE_COMPILER_EMIT_VTABLE)->boolValue; |
| 459 |
7/8✓ Branch 199 → 200 taken 479 times.
✓ Branch 199 → 205 taken 2505 times.
✓ Branch 200 → 201 taken 479 times.
✗ Branch 200 → 310 not taken.
✓ Branch 203 → 204 taken 375 times.
✓ Branch 203 → 205 taken 104 times.
✓ Branch 206 → 207 taken 375 times.
✓ Branch 206 → 208 taken 2609 times.
|
3463 | if (node->emitVTable && !sourceFile->isRttiRT()) |
| 460 |
1/2✓ Branch 207 → 208 taken 375 times.
✗ Branch 207 → 310 not taken.
|
375 | sourceFile->requestRuntimeModule(RTTI_RT); |
| 461 | |||
| 462 |
1/2✓ Branch 208 → 209 taken 2984 times.
✗ Branch 208 → 309 not taken.
|
5968 | return nullptr; |
| 463 | 3007 | } | |
| 464 | |||
| 465 | 364 | std::any TypeChecker::visitInterfaceDefPrepare(InterfaceDefNode *node) { | |
| 466 | 364 | QualTypeList usedTemplateTypes; | |
| 467 | 364 | std::vector<GenericType> templateTypesGeneric; | |
| 468 | |||
| 469 | // Retrieve interface template types | ||
| 470 |
2/2✓ Branch 2 → 3 taken 156 times.
✓ Branch 2 → 47 taken 208 times.
|
364 | if (node->hasTemplateTypes) { |
| 471 |
1/2✓ Branch 4 → 5 taken 156 times.
✗ Branch 4 → 156 not taken.
|
156 | usedTemplateTypes.reserve(node->templateTypeLst->dataTypes.size()); |
| 472 |
1/2✓ Branch 6 → 7 taken 156 times.
✗ Branch 6 → 156 not taken.
|
156 | templateTypesGeneric.reserve(node->templateTypeLst->dataTypes.size()); |
| 473 |
2/2✓ Branch 45 → 9 taken 156 times.
✓ Branch 45 → 46 taken 156 times.
|
468 | for (DataTypeNode *dataType : node->templateTypeLst->dataTypes) { |
| 474 | // Visit template type | ||
| 475 |
2/4✓ Branch 11 → 12 taken 156 times.
✗ Branch 11 → 125 not taken.
✓ Branch 12 → 13 taken 156 times.
✗ Branch 12 → 123 not taken.
|
156 | auto templateType = std::any_cast<QualType>(visit(dataType)); |
| 476 |
2/6✓ Branch 14 → 15 taken 156 times.
✗ Branch 14 → 133 not taken.
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 19 taken 156 times.
✗ Branch 16 → 17 not taken.
✗ Branch 16 → 126 not taken.
|
156 | HANDLE_UNRESOLVED_TYPE_PTR(templateType) |
| 477 | // Check if it is a generic type | ||
| 478 |
2/4✓ Branch 19 → 20 taken 156 times.
✗ Branch 19 → 133 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 28 taken 156 times.
|
156 | if (!templateType.is(TY_GENERIC)) { |
| 479 | ✗ | softError(dataType, EXPECTED_GENERIC_TYPE, "A template list can only contain generic types"); | |
| 480 | ✗ | continue; | |
| 481 | } | ||
| 482 | // Convert generic symbol type to generic type | ||
| 483 |
2/4✓ Branch 28 → 29 taken 156 times.
✗ Branch 28 → 133 not taken.
✓ Branch 29 → 30 taken 156 times.
✗ Branch 29 → 133 not taken.
|
156 | const GenericType *genericType = rootScope->lookupGenericTypeStrict(templateType.getSubType()); |
| 484 |
1/2✗ Branch 30 → 31 not taken.
✓ Branch 30 → 32 taken 156 times.
|
156 | assert(genericType != nullptr); |
| 485 |
1/2✓ Branch 32 → 33 taken 156 times.
✗ Branch 32 → 133 not taken.
|
156 | usedTemplateTypes.push_back(*genericType); |
| 486 |
1/2✓ Branch 33 → 34 taken 156 times.
✗ Branch 33 → 133 not taken.
|
156 | templateTypesGeneric.push_back(*genericType); |
| 487 | } | ||
| 488 | } | ||
| 489 | |||
| 490 | // Update type of interface entry | ||
| 491 | 364 | const TypeChainElementData data = {.bodyScope = node->interfaceScope}; | |
| 492 |
1/2✓ Branch 47 → 48 taken 364 times.
✗ Branch 47 → 156 not taken.
|
364 | const Type *type = TypeRegistry::getOrInsert(TY_INTERFACE, node->interfaceName, node->typeId, data, usedTemplateTypes); |
| 493 |
1/2✓ Branch 48 → 49 taken 364 times.
✗ Branch 48 → 156 not taken.
|
364 | const QualType interfaceType(type, node->qualifiers); |
| 494 |
1/2✗ Branch 49 → 50 not taken.
✓ Branch 49 → 51 taken 364 times.
|
364 | assert(node->entry != nullptr); |
| 495 | // If the entry was implicitly forward-declared because it is referenced across a circular import | ||
| 496 | // (assignDeferredOpaqueType), the existing type was already set to the opaque interface type. Overwriting it with the | ||
| 497 | // identical interned type is expected here. | ||
| 498 |
2/4✓ Branch 51 → 52 taken 364 times.
✗ Branch 51 → 156 not taken.
✓ Branch 52 → 53 taken 364 times.
✗ Branch 52 → 156 not taken.
|
364 | const bool overwrite = node->entry->getQualType().is(TY_INTERFACE); |
| 499 |
1/2✓ Branch 53 → 54 taken 364 times.
✗ Branch 53 → 156 not taken.
|
364 | node->entry->updateType(interfaceType, overwrite); |
| 500 | |||
| 501 | // Change to interface scope | ||
| 502 | 364 | currentScope = node->interfaceScope; | |
| 503 |
1/2✗ Branch 54 → 55 not taken.
✓ Branch 54 → 56 taken 364 times.
|
364 | assert(currentScope->type == ScopeType::INTERFACE); |
| 504 | |||
| 505 | // Visit methods | ||
| 506 | 364 | size_t vtableIndex = 0; | |
| 507 | 364 | std::vector<Function *> methods; | |
| 508 |
1/2✓ Branch 57 → 58 taken 364 times.
✗ Branch 57 → 154 not taken.
|
364 | methods.reserve(node->signatures.size()); |
| 509 |
2/2✓ Branch 99 → 60 taken 2347 times.
✓ Branch 99 → 100 taken 363 times.
|
3074 | for (SignatureNode *signature : node->signatures) { |
| 510 |
2/4✓ Branch 62 → 63 taken 2347 times.
✗ Branch 62 → 137 not taken.
✓ Branch 63 → 64 taken 2347 times.
✗ Branch 63 → 135 not taken.
|
2347 | const auto method = std::any_cast<std::vector<Function *> *>(visit(signature)); |
| 511 |
2/2✓ Branch 65 → 66 taken 1 time.
✓ Branch 65 → 69 taken 2346 times.
|
2347 | if (!method) |
| 512 |
1/2✓ Branch 66 → 67 taken 1 time.
✗ Branch 66 → 138 not taken.
|
2 | return nullptr; |
| 513 | |||
| 514 | // Set 'this' type | ||
| 515 |
2/2✓ Branch 82 → 71 taken 2346 times.
✓ Branch 82 → 83 taken 2346 times.
|
7038 | for (Function *m : *method) { |
| 516 | 2346 | m->isVirtual = true; // Interface methods are always virtual | |
| 517 | 2346 | m->vtableIndex = vtableIndex; | |
| 518 | 2346 | m->thisType = interfaceType; | |
| 519 | } | ||
| 520 | |||
| 521 |
1/2✓ Branch 89 → 90 taken 2346 times.
✗ Branch 89 → 139 not taken.
|
4692 | methods.insert(methods.end(), method->begin(), method->end()); |
| 522 | 2346 | vtableIndex++; | |
| 523 | } | ||
| 524 | |||
| 525 | // Change to root scope | ||
| 526 | 363 | currentScope = rootScope; | |
| 527 |
1/2✗ Branch 100 → 101 not taken.
✓ Branch 100 → 102 taken 363 times.
|
363 | assert(currentScope->type == ScopeType::GLOBAL); |
| 528 | |||
| 529 | // Build interface object | ||
| 530 |
4/8✓ Branch 102 → 103 taken 363 times.
✗ Branch 102 → 150 not taken.
✓ Branch 103 → 104 taken 363 times.
✗ Branch 103 → 147 not taken.
✓ Branch 104 → 105 taken 363 times.
✗ Branch 104 → 144 not taken.
✓ Branch 105 → 106 taken 363 times.
✗ Branch 105 → 142 not taken.
|
363 | Interface spiceInterface(node->interfaceName, node->entry, node->interfaceScope, methods, templateTypesGeneric, node); |
| 531 |
1/2✓ Branch 109 → 110 taken 363 times.
✗ Branch 109 → 152 not taken.
|
363 | InterfaceManager::insert(currentScope, spiceInterface, &node->interfaceManifestations); |
| 532 | 363 | spiceInterface.scope = node->interfaceScope; | |
| 533 | |||
| 534 | // Request RTTI runtime, that is always required when dealing with interfaces due to polymorphism | ||
| 535 |
2/4✓ Branch 110 → 111 taken 363 times.
✗ Branch 110 → 152 not taken.
✓ Branch 113 → 114 taken 363 times.
✗ Branch 113 → 115 not taken.
|
726 | if (!sourceFile->isRttiRT()) |
| 536 |
1/2✓ Branch 114 → 115 taken 363 times.
✗ Branch 114 → 152 not taken.
|
363 | sourceFile->requestRuntimeModule(RTTI_RT); |
| 537 | |||
| 538 |
1/2✓ Branch 115 → 116 taken 363 times.
✗ Branch 115 → 151 not taken.
|
363 | return nullptr; |
| 539 | 364 | } | |
| 540 | |||
| 541 | 369 | std::any TypeChecker::visitEnumDefPrepare(EnumDefNode *node) { | |
| 542 | // Update type of enum entry | ||
| 543 | 369 | const TypeChainElementData data = {.bodyScope = node->enumScope}; | |
| 544 |
1/2✓ Branch 3 → 4 taken 369 times.
✗ Branch 3 → 88 not taken.
|
369 | const Type *type = TypeRegistry::getOrInsert(TY_ENUM, node->enumName, node->typeId, data, {}); |
| 545 |
1/2✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 369 times.
|
369 | assert(node->entry != nullptr); |
| 546 | // The enum may already carry its opaque type if it was referenced across a circular import before being prepared | ||
| 547 | // (assignDeferredOpaqueType). Overwriting it with the identical interned type is expected here. | ||
| 548 |
2/4✓ Branch 7 → 8 taken 369 times.
✗ Branch 7 → 109 not taken.
✓ Branch 8 → 9 taken 369 times.
✗ Branch 8 → 109 not taken.
|
369 | const bool overwrite = node->entry->getQualType().is(TY_ENUM); |
| 549 |
2/4✓ Branch 9 → 10 taken 369 times.
✗ Branch 9 → 91 not taken.
✓ Branch 10 → 11 taken 369 times.
✗ Branch 10 → 91 not taken.
|
369 | node->entry->updateType(QualType(type, node->qualifiers), overwrite); |
| 550 | |||
| 551 | // Change to enum scope | ||
| 552 | 369 | currentScope = node->enumScope; | |
| 553 |
1/2✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 369 times.
|
369 | assert(currentScope->type == ScopeType::ENUM); |
| 554 | |||
| 555 | // Loop through all items with values | ||
| 556 | 369 | std::vector<std::string> names; | |
| 557 | 369 | std::vector<uint32_t> values; | |
| 558 |
2/2✓ Branch 45 → 15 taken 4920 times.
✓ Branch 45 → 46 taken 369 times.
|
5658 | for (const EnumItemNode *enumItem : node->itemLst->items) { |
| 559 | // Save name | ||
| 560 |
1/2✓ Branch 17 → 18 taken 4920 times.
✗ Branch 17 → 100 not taken.
|
4920 | names.push_back(enumItem->itemName); |
| 561 | // Check for duplicate value | ||
| 562 |
2/2✓ Branch 18 → 19 taken 2642 times.
✓ Branch 18 → 36 taken 2278 times.
|
4920 | if (enumItem->hasValue) { |
| 563 |
3/4✓ Branch 20 → 21 taken 2642 times.
✗ Branch 20 → 92 not taken.
✓ Branch 27 → 28 taken 1 time.
✓ Branch 27 → 35 taken 2641 times.
|
5284 | if (std::ranges::find(values, enumItem->itemValue) != values.end()) { |
| 564 |
2/4✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 96 not taken.
✓ Branch 31 → 32 taken 1 time.
✗ Branch 31 → 94 not taken.
|
1 | softError(enumItem, DUPLICATE_ENUM_ITEM_VALUE, "Duplicate enum item value, please use another"); |
| 565 | 1 | continue; | |
| 566 | } | ||
| 567 |
1/2✓ Branch 35 → 36 taken 2641 times.
✗ Branch 35 → 100 not taken.
|
2641 | values.push_back(enumItem->itemValue); |
| 568 | } | ||
| 569 | } | ||
| 570 | |||
| 571 | // Loop through all items without values | ||
| 572 | 369 | uint32_t nextValue = 0; | |
| 573 |
1/2✓ Branch 46 → 47 taken 369 times.
✗ Branch 46 → 105 not taken.
|
369 | const QualType intSymbolType(TY_INT); |
| 574 |
2/2✓ Branch 79 → 49 taken 4920 times.
✓ Branch 79 → 80 taken 369 times.
|
5658 | for (EnumItemNode *enumItem : node->itemLst->items) { |
| 575 | // Update type of enum item entry | ||
| 576 |
1/2✓ Branch 51 → 52 taken 4920 times.
✗ Branch 51 → 103 not taken.
|
4920 | SymbolTableEntry *itemEntry = currentScope->lookupStrict(enumItem->itemName); |
| 577 |
1/2✗ Branch 54 → 55 not taken.
✓ Branch 54 → 56 taken 4920 times.
|
4920 | assert(itemEntry != nullptr); |
| 578 |
1/2✓ Branch 56 → 57 taken 4920 times.
✗ Branch 56 → 103 not taken.
|
4920 | itemEntry->updateType(intSymbolType, false); |
| 579 | // Fill in value if not filled yet | ||
| 580 |
2/2✓ Branch 57 → 58 taken 2278 times.
✓ Branch 57 → 70 taken 2642 times.
|
4920 | if (!enumItem->hasValue) { |
| 581 |
3/4✓ Branch 61 → 62 taken 4333 times.
✗ Branch 61 → 101 not taken.
✓ Branch 68 → 59 taken 2055 times.
✓ Branch 68 → 69 taken 2278 times.
|
8666 | while (std::ranges::find(values, nextValue) != values.end()) |
| 582 | 2055 | nextValue++; | |
| 583 | 2278 | enumItem->itemValue = nextValue; | |
| 584 |
1/2✓ Branch 69 → 70 taken 2278 times.
✗ Branch 69 → 103 not taken.
|
2278 | values.push_back(nextValue); |
| 585 | } | ||
| 586 | } | ||
| 587 | |||
| 588 | // Change to root scope | ||
| 589 | 369 | currentScope = rootScope; | |
| 590 |
1/2✗ Branch 80 → 81 not taken.
✓ Branch 80 → 82 taken 369 times.
|
369 | assert(currentScope->type == ScopeType::GLOBAL); |
| 591 | |||
| 592 |
1/2✓ Branch 82 → 83 taken 369 times.
✗ Branch 82 → 104 not taken.
|
738 | return nullptr; |
| 593 | 369 | } | |
| 594 | |||
| 595 | 1941 | std::any TypeChecker::visitGenericTypeDefPrepare(GenericTypeDefNode *node) { | |
| 596 | // Retrieve type conditions | ||
| 597 | 1941 | QualTypeList typeConditions; | |
| 598 |
1/2✓ Branch 3 → 4 taken 1941 times.
✗ Branch 3 → 70 not taken.
|
1941 | typeConditions.reserve(node->typeAltsLst->dataTypes.size()); |
| 599 |
2/2✓ Branch 26 → 6 taken 3495 times.
✓ Branch 26 → 27 taken 1941 times.
|
7377 | for (const auto &typeAlt : node->typeAltsLst->dataTypes) { |
| 600 |
2/4✓ Branch 8 → 9 taken 3495 times.
✗ Branch 8 → 58 not taken.
✓ Branch 9 → 10 taken 3495 times.
✗ Branch 9 → 56 not taken.
|
3495 | auto typeCondition = std::any_cast<QualType>(visit(typeAlt)); |
| 601 |
2/6✓ Branch 11 → 12 taken 3495 times.
✗ Branch 11 → 60 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 16 taken 3495 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 59 not taken.
|
3495 | HANDLE_UNRESOLVED_TYPE_PTR(typeCondition) |
| 602 |
1/2✓ Branch 16 → 17 taken 3495 times.
✗ Branch 16 → 60 not taken.
|
3495 | typeConditions.push_back(typeCondition); |
| 603 | } | ||
| 604 | |||
| 605 | // Add generic type to the scope | ||
| 606 |
2/4✓ Branch 27 → 28 taken 1941 times.
✗ Branch 27 → 64 not taken.
✓ Branch 28 → 29 taken 1941 times.
✗ Branch 28 → 62 not taken.
|
1941 | const GenericType genericType(node->typeName, typeConditions); |
| 607 |
1/2✓ Branch 30 → 31 taken 1941 times.
✗ Branch 30 → 68 not taken.
|
1941 | rootScope->insertGenericType(node->typeName, genericType); |
| 608 | |||
| 609 | // Check if only one type condition is set | ||
| 610 |
7/8✓ Branch 32 → 33 taken 874 times.
✓ Branch 32 → 37 taken 1067 times.
✓ Branch 34 → 35 taken 874 times.
✗ Branch 34 → 68 not taken.
✓ Branch 35 → 36 taken 1 time.
✓ Branch 35 → 37 taken 873 times.
✓ Branch 38 → 39 taken 1 time.
✓ Branch 38 → 41 taken 1940 times.
|
1941 | if (typeConditions.size() == 1 && !typeConditions.front().is(TY_DYN)) |
| 611 |
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, |
| 612 | "Generic type is locked to one type"); | ||
| 613 | |||
| 614 | // Check if the list contains the dyn type, along with other types | ||
| 615 |
1/2✓ Branch 41 → 42 taken 1941 times.
✗ Branch 41 → 68 not taken.
|
5434 | const bool containsDynType = std::ranges::any_of(typeConditions, [&](const QualType &type) { return type.is(TY_DYN); }); |
| 616 |
6/6✓ Branch 42 → 43 taken 875 times.
✓ Branch 42 → 46 taken 1066 times.
✓ Branch 44 → 45 taken 2 times.
✓ Branch 44 → 46 taken 873 times.
✓ Branch 47 → 48 taken 2 times.
✓ Branch 47 → 50 taken 1939 times.
|
1941 | if (containsDynType && typeConditions.size() > 1) |
| 617 | 2 | sourceFile->compilerOutput.warnings.emplace_back( | |
| 618 |
1/2✓ Branch 48 → 49 taken 2 times.
✗ Branch 48 → 66 not taken.
|
2 | node->typeAltsLst->codeLoc, INEFFECTIVE_GENERIC_TYPE_CONDITION, |
| 619 | "One or several type conditions are superfluous, because the dyn type condition is given"); | ||
| 620 | |||
| 621 |
1/2✓ Branch 50 → 51 taken 1941 times.
✗ Branch 50 → 67 not taken.
|
1941 | return nullptr; |
| 622 | 1941 | } | |
| 623 | |||
| 624 | 342 | std::any TypeChecker::visitAliasDefPrepare(AliasDefNode *node) { | |
| 625 |
2/4✓ Branch 2 → 3 taken 342 times.
✗ Branch 2 → 5 not taken.
✓ Branch 3 → 4 taken 342 times.
✗ Branch 3 → 5 not taken.
|
342 | assert(node->entry != nullptr && node->aliasedTypeContainerEntry != nullptr); |
| 626 | |||
| 627 | // The alias may already have been prepared on demand because it was referenced across a circular import | ||
| 628 | // (assignDeferredOpaqueType). In that case there is nothing left to do. | ||
| 629 |
4/6✓ Branch 6 → 7 taken 342 times.
✗ Branch 6 → 43 not taken.
✓ Branch 7 → 8 taken 342 times.
✗ Branch 7 → 43 not taken.
✓ Branch 8 → 9 taken 1 time.
✓ Branch 8 → 12 taken 341 times.
|
342 | if (node->entry->getQualType().is(TY_ALIAS)) |
| 630 |
1/2✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 32 not taken.
|
2 | return nullptr; |
| 631 | |||
| 632 | // Ensure the aliased-type subtree is sized for manifestations before it is visited below. On the normal path | ||
| 633 | // visitEntry already sized the whole file to 1, so this is a no-op; on the on-demand path (a cross-import reference | ||
| 634 | // reaching this alias before its own file's visitEntry ran) it establishes the precondition setEvaluatedSymbolType | ||
| 635 | // requires. | ||
| 636 |
1/2✓ Branch 12 → 13 taken 341 times.
✗ Branch 12 → 43 not taken.
|
341 | node->dataType->resizeToNumberOfManifestations(1); |
| 637 | |||
| 638 | // Update type of alias entry | ||
| 639 |
1/2✓ Branch 14 → 15 taken 341 times.
✗ Branch 14 → 33 not taken.
|
341 | const Type *type = TypeRegistry::getOrInsert(TY_ALIAS, node->aliasName, node->typeId, {}, {}); |
| 640 |
2/4✓ Branch 16 → 17 taken 341 times.
✗ Branch 16 → 37 not taken.
✓ Branch 17 → 18 taken 341 times.
✗ Branch 17 → 37 not taken.
|
341 | node->entry->updateType(QualType(type, node->qualifiers), false); |
| 641 | |||
| 642 | // Update type of the aliased type container entry | ||
| 643 |
2/4✓ Branch 18 → 19 taken 341 times.
✗ Branch 18 → 40 not taken.
✓ Branch 19 → 20 taken 341 times.
✗ Branch 19 → 38 not taken.
|
341 | const auto aliasedType = std::any_cast<QualType>(visit(node->dataType)); |
| 644 |
4/6✓ Branch 21 → 22 taken 341 times.
✗ Branch 21 → 43 not taken.
✓ Branch 22 → 23 taken 1 time.
✓ Branch 22 → 26 taken 340 times.
✓ Branch 23 → 24 taken 1 time.
✗ Branch 23 → 41 not taken.
|
342 | HANDLE_UNRESOLVED_TYPE_PTR(aliasedType) |
| 645 |
1/2✓ Branch 26 → 27 taken 340 times.
✗ Branch 26 → 43 not taken.
|
340 | node->aliasedTypeContainerEntry->updateType(aliasedType, false); |
| 646 | 340 | node->aliasedTypeContainerEntry->used = true; // The container type is always used per default | |
| 647 | |||
| 648 |
1/2✓ Branch 27 → 28 taken 340 times.
✗ Branch 27 → 42 not taken.
|
680 | return nullptr; |
| 649 | } | ||
| 650 | |||
| 651 | 2373 | std::any TypeChecker::visitGlobalVarDefPrepare(GlobalVarDefNode *node) { | |
| 652 | // Insert variable name to symbol table | ||
| 653 |
2/4✓ Branch 2 → 3 taken 2373 times.
✗ Branch 2 → 87 not taken.
✓ Branch 3 → 4 taken 2373 times.
✗ Branch 3 → 85 not taken.
|
2373 | auto globalVarType = std::any_cast<QualType>(visit(node->dataType)); |
| 654 |
2/6✓ Branch 5 → 6 taken 2373 times.
✗ Branch 5 → 133 not taken.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 10 taken 2373 times.
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 88 not taken.
|
2373 | HANDLE_UNRESOLVED_TYPE_PTR(globalVarType) |
| 655 | |||
| 656 |
2/2✓ Branch 10 → 11 taken 2371 times.
✓ Branch 10 → 40 taken 2 times.
|
2373 | if (node->constant) { // Variable is initialized here |
| 657 |
2/4✓ Branch 11 → 12 taken 2371 times.
✗ Branch 11 → 91 not taken.
✓ Branch 12 → 13 taken 2371 times.
✗ Branch 12 → 89 not taken.
|
2371 | const QualType rhsType = std::any_cast<ExprResult>(visit(node->constant)).type; |
| 658 |
2/6✓ Branch 14 → 15 taken 2371 times.
✗ Branch 14 → 110 not taken.
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 19 taken 2371 times.
✗ Branch 16 → 17 not taken.
✗ Branch 16 → 93 not taken.
|
2371 | HANDLE_UNRESOLVED_TYPE_PTR(rhsType) |
| 659 |
3/4✓ Branch 19 → 20 taken 2371 times.
✗ Branch 19 → 110 not taken.
✓ Branch 20 → 21 taken 1 time.
✓ Branch 20 → 22 taken 2370 times.
|
2371 | if (globalVarType.is(TY_DYN)) { // Perform type inference |
| 660 | 1 | globalVarType = rhsType; | |
| 661 |
3/4✓ Branch 22 → 23 taken 2370 times.
✗ Branch 22 → 110 not taken.
✓ Branch 23 → 24 taken 2 times.
✓ Branch 23 → 38 taken 2368 times.
|
2370 | } else if (!globalVarType.matches(rhsType, false, true, true)) { // Check if types are matching |
| 662 |
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, |
| 663 | "Expected " + globalVarType.getName(false) + ", but got " + rhsType.getName(false)) | ||
| 664 | } | ||
| 665 | } | ||
| 666 | |||
| 667 | // Check if the type is still missing | ||
| 668 |
3/4✓ Branch 40 → 41 taken 2371 times.
✗ Branch 40 → 133 not taken.
✓ Branch 41 → 42 taken 1 time.
✓ Branch 41 → 51 taken 2370 times.
|
2371 | if (globalVarType.is(TY_DYN)) |
| 669 |
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") |
| 670 | |||
| 671 | // Check if we would need to insert instructions in the global scope to initialize the variable | ||
| 672 |
2/4✓ Branch 51 → 52 taken 2370 times.
✗ Branch 51 → 133 not taken.
✗ Branch 52 → 53 not taken.
✓ Branch 52 → 62 taken 2370 times.
|
2370 | if (!globalVarType.isPrimitive()) |
| 673 | ✗ | SOFT_ERROR_BOOL(node->dataType, GLOBAL_OF_INVALID_TYPE, "Spice does only support global variables of primitive type") | |
| 674 | |||
| 675 | // Update type of global var entry | ||
| 676 |
1/2✗ Branch 62 → 63 not taken.
✓ Branch 62 → 64 taken 2370 times.
|
2370 | assert(node->entry != nullptr); |
| 677 |
1/2✓ Branch 64 → 65 taken 2370 times.
✗ Branch 64 → 133 not taken.
|
2370 | node->entry->updateType(globalVarType, false); |
| 678 | |||
| 679 | // Check if a value is attached | ||
| 680 |
6/8✓ Branch 65 → 66 taken 1 time.
✓ Branch 65 → 69 taken 2369 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 2369 times.
|
2370 | if (!node->constant && globalVarType.isConst()) |
| 681 |
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") |
| 682 | |||
| 683 |
1/2✓ Branch 80 → 81 taken 2369 times.
✗ Branch 80 → 132 not taken.
|
4738 | return nullptr; |
| 684 | } | ||
| 685 | |||
| 686 | 2978 | std::any TypeChecker::visitExtDeclPrepare(ExtDeclNode *node) { | |
| 687 | // Collect argument types | ||
| 688 | 2978 | QualTypeList argTypes; | |
| 689 | 2978 | ParamList argList; | |
| 690 |
2/2✓ Branch 2 → 3 taken 2771 times.
✓ Branch 2 → 41 taken 207 times.
|
2978 | if (node->hasArgs) { |
| 691 |
1/2✓ Branch 4 → 5 taken 2771 times.
✗ Branch 4 → 168 not taken.
|
2771 | argList.reserve(node->argTypeLst->typeLst->dataTypes.size()); |
| 692 |
2/2✓ Branch 39 → 7 taken 6139 times.
✓ Branch 39 → 40 taken 2771 times.
|
11681 | for (DataTypeNode *arg : node->argTypeLst->typeLst->dataTypes) { |
| 693 | // Visit argument | ||
| 694 |
2/4✓ Branch 9 → 10 taken 6139 times.
✗ Branch 9 → 113 not taken.
✓ Branch 10 → 11 taken 6139 times.
✗ Branch 10 → 111 not taken.
|
6139 | auto argType = std::any_cast<QualType>(visit(arg)); |
| 695 |
2/6✓ Branch 12 → 13 taken 6139 times.
✗ Branch 12 → 122 not taken.
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 17 taken 6139 times.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 114 not taken.
|
6139 | HANDLE_UNRESOLVED_TYPE_PTR(argType) |
| 696 | // Check if the argument type is 'dyn' | ||
| 697 |
3/4✓ Branch 17 → 18 taken 6139 times.
✗ Branch 17 → 122 not taken.
✓ Branch 18 → 19 taken 1 time.
✓ Branch 18 → 26 taken 6138 times.
|
6139 | if (argType.is(TY_DYN)) { |
| 698 |
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"); |
| 699 | 1 | continue; | |
| 700 | } | ||
| 701 | // Save argument | ||
| 702 |
1/2✓ Branch 26 → 27 taken 6138 times.
✗ Branch 26 → 122 not taken.
|
6138 | argTypes.push_back(argType); |
| 703 |
1/2✓ Branch 27 → 28 taken 6138 times.
✗ Branch 27 → 121 not taken.
|
6138 | argList.push_back({argType, false}); |
| 704 | } | ||
| 705 | } | ||
| 706 | |||
| 707 | // Retrieve return type | ||
| 708 |
1/2✓ Branch 41 → 42 taken 2978 times.
✗ Branch 41 → 168 not taken.
|
2978 | QualType returnType(TY_DYN); |
| 709 | 2978 | const bool isFunction = node->returnType; | |
| 710 |
2/2✓ Branch 42 → 43 taken 1974 times.
✓ Branch 42 → 62 taken 1004 times.
|
2978 | if (isFunction) { // External function |
| 711 |
2/4✓ Branch 43 → 44 taken 1974 times.
✗ Branch 43 → 126 not taken.
✓ Branch 44 → 45 taken 1974 times.
✗ Branch 44 → 124 not taken.
|
1974 | returnType = std::any_cast<QualType>(visit(node->returnType)); |
| 712 |
2/6✓ Branch 46 → 47 taken 1974 times.
✗ Branch 46 → 168 not taken.
✗ Branch 47 → 48 not taken.
✓ Branch 47 → 51 taken 1974 times.
✗ Branch 48 → 49 not taken.
✗ Branch 48 → 128 not taken.
|
1974 | HANDLE_UNRESOLVED_TYPE_PTR(returnType) |
| 713 | // Check if return type is dyn | ||
| 714 |
3/4✓ Branch 51 → 52 taken 1974 times.
✗ Branch 51 → 168 not taken.
✓ Branch 52 → 53 taken 1 time.
✓ Branch 52 → 62 taken 1973 times.
|
1974 | if (returnType.is(TY_DYN)) |
| 715 |
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") |
| 716 | } | ||
| 717 | |||
| 718 | // Add function to current scope | ||
| 719 |
4/8✓ Branch 63 → 64 taken 2977 times.
✗ Branch 63 → 142 not taken.
✓ Branch 64 → 65 taken 2977 times.
✗ Branch 64 → 139 not taken.
✓ Branch 65 → 66 taken 2977 times.
✗ Branch 65 → 138 not taken.
✓ Branch 66 → 67 taken 2977 times.
✗ Branch 66 → 136 not taken.
|
2977 | const Function spiceFunc(node->extFunctionName, node->entry, QualType(TY_DYN), returnType, argList, {}, node); |
| 720 |
1/2✓ Branch 70 → 71 taken 2977 times.
✗ Branch 70 → 166 not taken.
|
2977 | node->extFunction = FunctionManager::insert(currentScope, spiceFunc, &node->extFunctionManifestations); |
| 721 | 2977 | node->extFunction->mangleFunctionName = false; | |
| 722 | 2977 | node->extFunction->alreadyTypeChecked = true; | |
| 723 |
4/4✓ Branch 71 → 72 taken 2771 times.
✓ Branch 71 → 74 taken 206 times.
✓ Branch 72 → 73 taken 58 times.
✓ Branch 72 → 74 taken 2713 times.
|
2977 | node->extFunction->isVararg = node->argTypeLst && node->argTypeLst->hasEllipsis; |
| 724 | |||
| 725 | // Check procedure attributes | ||
| 726 |
2/2✓ Branch 75 → 76 taken 1 time.
✓ Branch 75 → 93 taken 2976 times.
|
2977 | if (node->attrs) { |
| 727 | 1 | const AttrLstNode *attrLst = node->attrs->attrLst; | |
| 728 |
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)) |
| 729 | ✗ | node->extFunction->mangleFunctionName = value->boolValue; | |
| 730 |
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)) { |
| 731 |
1/2✓ Branch 91 → 92 taken 1 time.
✗ Branch 91 → 166 not taken.
|
1 | const std::string &stringValue = resourceManager.compileTimeStringValues.at(value->stringValueOffset); |
| 732 |
1/2✓ Branch 92 → 93 taken 1 time.
✗ Branch 92 → 166 not taken.
|
1 | node->extFunction->predefinedMangledName = stringValue; |
| 733 | } | ||
| 734 | } | ||
| 735 | |||
| 736 | // Prepare ext function type | ||
| 737 |
2/2✓ Branch 93 → 94 taken 1973 times.
✓ Branch 93 → 95 taken 1004 times.
|
2977 | const SuperType superType = isFunction ? TY_FUNCTION : TY_PROCEDURE; |
| 738 |
2/4✓ Branch 96 → 97 taken 2977 times.
✗ Branch 96 → 158 not taken.
✓ Branch 97 → 98 taken 2977 times.
✗ Branch 97 → 158 not taken.
|
2977 | const QualType extFunctionType = QualType(superType).getWithFunctionParamAndReturnTypes(returnType, argTypes); |
| 739 | |||
| 740 | // Set type of external function | ||
| 741 |
1/2✓ Branch 98 → 99 taken 2977 times.
✗ Branch 98 → 166 not taken.
|
2977 | node->entry->updateType(extFunctionType, false); |
| 742 | |||
| 743 | // Rename the original child scope to reflect the substantiated versions of the external function | ||
| 744 |
3/6✓ Branch 99 → 100 taken 2977 times.
✗ Branch 99 → 164 not taken.
✓ Branch 100 → 101 taken 2977 times.
✗ Branch 100 → 161 not taken.
✓ Branch 101 → 102 taken 2977 times.
✗ Branch 101 → 159 not taken.
|
2977 | currentScope->renameChildScope(node->getScopeId(), spiceFunc.getScopeName()); |
| 745 | |||
| 746 |
1/2✓ Branch 104 → 105 taken 2977 times.
✗ Branch 104 → 165 not taken.
|
2977 | return nullptr; |
| 747 | 2978 | } | |
| 748 | |||
| 749 | 2488 | std::any TypeChecker::visitImportDefPrepare(ImportDefNode *node) { | |
| 750 | // Set entry to import type | ||
| 751 |
1/2✓ Branch 2 → 3 taken 2488 times.
✗ Branch 2 → 11 not taken.
|
2488 | const QualType importType(TY_IMPORT, node->importName); |
| 752 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 2488 times.
|
2488 | assert(node->entry != nullptr); |
| 753 |
1/2✓ Branch 5 → 6 taken 2488 times.
✗ Branch 5 → 11 not taken.
|
2488 | node->entry->updateType(importType, false); |
| 754 | |||
| 755 |
1/2✓ Branch 6 → 7 taken 2488 times.
✗ Branch 6 → 10 not taken.
|
4976 | return nullptr; |
| 756 | } | ||
| 757 | |||
| 758 | } // namespace spice::compiler | ||
| 759 |