src/typechecker/TypeCheckerTopLevelDefinitionsCheck.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2026 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #include "TypeChecker.h" | ||
| 4 | |||
| 5 | #include <SourceFile.h> | ||
| 6 | #include <ast/ASTNodes.h> | ||
| 7 | #include <exception/SemanticError.h> | ||
| 8 | #include <model/Interface.h> | ||
| 9 | #include <symboltablebuilder/Scope.h> | ||
| 10 | #include <symboltablebuilder/SymbolTableBuilder.h> | ||
| 11 | #include <typechecker/FunctionManager.h> | ||
| 12 | #include <typechecker/TypeMatcher.h> | ||
| 13 | |||
| 14 | namespace spice::compiler { | ||
| 15 | |||
| 16 | 603 | std::any TypeChecker::visitMainFctDefCheck(MainFctDefNode *node) { | |
| 17 | // Skip if already type-checked | ||
| 18 |
2/2✓ Branch 2 → 3 taken 76 times.
✓ Branch 2 → 6 taken 527 times.
|
603 | if (typeCheckedMainFct) |
| 19 |
1/2✓ Branch 3 → 4 taken 76 times.
✗ Branch 3 → 13 not taken.
|
152 | return nullptr; |
| 20 | |||
| 21 | 527 | node->resizeToNumberOfManifestations(1); | |
| 22 | |||
| 23 | // Change to function body scope | ||
| 24 | 527 | currentScope = node->bodyScope; | |
| 25 | // Visit statements in new scope | ||
| 26 |
2/2✓ Branch 7 → 8 taken 497 times.
✓ Branch 7 → 14 taken 30 times.
|
527 | visit(node->body); |
| 27 | // Leave main function body scope | ||
| 28 | 497 | currentScope = rootScope; | |
| 29 | |||
| 30 | // Set to type-checked | ||
| 31 | 497 | typeCheckedMainFct = true; | |
| 32 |
1/2✓ Branch 9 → 10 taken 497 times.
✗ Branch 9 → 15 not taken.
|
994 | return nullptr; |
| 33 | } | ||
| 34 | |||
| 35 | 46522 | std::any TypeChecker::visitFctDefCheck(FctDefNode *node) { | |
| 36 | 46522 | node->resizeToNumberOfManifestations(node->manifestations.size()); | |
| 37 | 46522 | manIdx = 0; // Reset the manifestation index | |
| 38 | |||
| 39 | // Get all manifestations for this function definition | ||
| 40 |
2/2✓ Branch 79 → 6 taken 65348 times.
✓ Branch 79 → 80 taken 46520 times.
|
158390 | for (Function *manifestation : node->manifestations) { |
| 41 | // Skip non-substantiated or already checked functions | ||
| 42 |
7/8✓ Branch 8 → 9 taken 65348 times.
✗ Branch 8 → 101 not taken.
✓ Branch 9 → 10 taken 52427 times.
✓ Branch 9 → 11 taken 12921 times.
✓ Branch 10 → 11 taken 29229 times.
✓ Branch 10 → 12 taken 23198 times.
✓ Branch 13 → 14 taken 42150 times.
✓ Branch 13 → 15 taken 23198 times.
|
65348 | if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) { |
| 43 | 42150 | manIdx++; // Increase the manifestation index | |
| 44 | 42150 | continue; | |
| 45 | } | ||
| 46 | |||
| 47 | // Change scope to concrete struct specialization scope | ||
| 48 |
2/2✓ Branch 15 → 16 taken 13465 times.
✓ Branch 15 → 21 taken 9733 times.
|
23198 | if (node->isMethod) { |
| 49 |
2/4✓ Branch 16 → 17 taken 13465 times.
✗ Branch 16 → 86 not taken.
✓ Branch 17 → 18 taken 13465 times.
✗ Branch 17 → 86 not taken.
|
13465 | const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes()); |
| 50 |
1/2✓ Branch 18 → 19 taken 13465 times.
✗ Branch 18 → 84 not taken.
|
13465 | changeToScope(scopeName, ScopeType::STRUCT); |
| 51 | 13465 | } | |
| 52 | |||
| 53 | // Change to function scope | ||
| 54 |
1/2✓ Branch 21 → 22 taken 23198 times.
✗ Branch 21 → 101 not taken.
|
23198 | changeToScope(manifestation->bodyScope, ScopeType::FUNC_PROC_BODY); |
| 55 | |||
| 56 | // Mount type mapping for this manifestation | ||
| 57 |
1/2✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 23198 times.
|
23198 | assert(typeMapping.empty()); |
| 58 |
1/2✓ Branch 25 → 26 taken 23198 times.
✗ Branch 25 → 101 not taken.
|
23198 | typeMapping = manifestation->typeMapping; |
| 59 | |||
| 60 | // Set return type to the result variable | ||
| 61 |
1/2✓ Branch 28 → 29 taken 23198 times.
✗ Branch 28 → 89 not taken.
|
69594 | SymbolTableEntry *resultVarEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME); |
| 62 |
1/2✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 23198 times.
|
23198 | assert(resultVarEntry != nullptr); |
| 63 |
1/2✓ Branch 36 → 37 taken 23198 times.
✗ Branch 36 → 101 not taken.
|
23198 | resultVarEntry->updateType(manifestation->returnType, false); |
| 64 | 23198 | resultVarEntry->used = true; | |
| 65 | |||
| 66 | // Visit parameters | ||
| 67 | // This happens once in the type checker prepare stage. This second time is only required if we have a generic function | ||
| 68 |
2/2✓ Branch 37 → 38 taken 16498 times.
✓ Branch 37 → 64 taken 6700 times.
|
23198 | if (node->hasParams) { |
| 69 |
1/2✓ Branch 38 → 39 taken 16498 times.
✗ Branch 38 → 93 not taken.
|
16498 | visit(node->paramLst); |
| 70 | // Annotate function/procedure-typed params with lambda-capture info from the resolved manifestation type. | ||
| 71 | // This must happen in the TypeChecker so that the IRGenerator can treat SymbolTableEntry as immutable. | ||
| 72 |
2/2✓ Branch 63 → 41 taken 24010 times.
✓ Branch 63 → 64 taken 16498 times.
|
40508 | for (size_t i = 0; i < manifestation->paramList.size(); i++) { |
| 73 |
1/2✓ Branch 41 → 42 taken 24010 times.
✗ Branch 41 → 99 not taken.
|
24010 | const DeclStmtNode *param = node->paramLst->params.at(i); |
| 74 |
2/4✓ Branch 42 → 43 taken 24010 times.
✗ Branch 42 → 96 not taken.
✓ Branch 43 → 44 taken 24010 times.
✗ Branch 43 → 94 not taken.
|
24010 | const QualType paramType = manifestation->getParamTypes().at(i); |
| 75 |
8/10✓ Branch 45 → 46 taken 24010 times.
✗ Branch 45 → 97 not taken.
✓ Branch 46 → 47 taken 6 times.
✓ Branch 46 → 50 taken 24004 times.
✓ Branch 47 → 48 taken 6 times.
✗ Branch 47 → 97 not taken.
✓ Branch 48 → 49 taken 2 times.
✓ Branch 48 → 50 taken 4 times.
✓ Branch 51 → 52 taken 2 times.
✓ Branch 51 → 61 taken 24008 times.
|
24010 | if (paramType.isOneOf({TY_FUNCTION, TY_PROCEDURE}) && paramType.hasLambdaCaptures()) { |
| 76 |
1/2✓ Branch 52 → 53 taken 2 times.
✗ Branch 52 → 99 not taken.
|
2 | SymbolTableEntry *paramSymbol = currentScope->lookupStrict(param->varName); |
| 77 |
1/2✗ Branch 55 → 56 not taken.
✓ Branch 55 → 57 taken 2 times.
|
2 | assert(paramSymbol != nullptr); |
| 78 |
3/6✓ Branch 57 → 58 taken 2 times.
✗ Branch 57 → 98 not taken.
✓ Branch 58 → 59 taken 2 times.
✗ Branch 58 → 98 not taken.
✓ Branch 59 → 60 taken 2 times.
✗ Branch 59 → 98 not taken.
|
2 | paramSymbol->updateType(paramSymbol->getQualType().getWithLambdaCaptures(), true); |
| 79 | } | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | // Visit statements in new scope | ||
| 84 |
2/2✓ Branch 64 → 65 taken 23196 times.
✓ Branch 64 → 100 taken 2 times.
|
23198 | visit(node->body); |
| 85 | |||
| 86 | // Clear type mapping | ||
| 87 | 23196 | typeMapping.clear(); | |
| 88 | |||
| 89 | // Change to root scope | ||
| 90 | 23196 | currentScope = rootScope; | |
| 91 |
1/2✗ Branch 67 → 68 not taken.
✓ Branch 67 → 69 taken 23196 times.
|
23196 | assert(currentScope->type == ScopeType::GLOBAL); |
| 92 | |||
| 93 | // Do not type-check this manifestation again | ||
| 94 | 23196 | manifestation->alreadyTypeChecked = true; | |
| 95 | |||
| 96 | 23196 | manIdx++; // Increase the manifestation index | |
| 97 | } | ||
| 98 | 46520 | manIdx = 0; // Reset the manifestation index | |
| 99 | |||
| 100 |
1/2✓ Branch 80 → 81 taken 46520 times.
✗ Branch 80 → 102 not taken.
|
93040 | return nullptr; |
| 101 | } | ||
| 102 | |||
| 103 | 27099 | std::any TypeChecker::visitProcDefCheck(ProcDefNode *node) { | |
| 104 | 27099 | node->resizeToNumberOfManifestations(node->manifestations.size()); | |
| 105 | 27099 | manIdx = 0; // Reset the manifestation index | |
| 106 | |||
| 107 | // Get all manifestations for this procedure definition | ||
| 108 |
2/2✓ Branch 72 → 6 taken 42006 times.
✓ Branch 72 → 73 taken 27099 times.
|
96204 | for (Function *manifestation : node->manifestations) { |
| 109 | // Skip non-substantiated or already checked procedures | ||
| 110 |
7/8✓ Branch 8 → 9 taken 42006 times.
✗ Branch 8 → 88 not taken.
✓ Branch 9 → 10 taken 27519 times.
✓ Branch 9 → 11 taken 14487 times.
✓ Branch 10 → 11 taken 14443 times.
✓ Branch 10 → 12 taken 13076 times.
✓ Branch 13 → 14 taken 28930 times.
✓ Branch 13 → 15 taken 13076 times.
|
42006 | if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) { |
| 111 | 28930 | manIdx++; // Increase the manifestation index | |
| 112 | 28930 | continue; | |
| 113 | } | ||
| 114 | |||
| 115 | // Change scope to concrete struct specialization scope | ||
| 116 |
2/2✓ Branch 15 → 16 taken 11083 times.
✓ Branch 15 → 21 taken 1993 times.
|
13076 | if (node->isMethod) { |
| 117 |
2/4✓ Branch 16 → 17 taken 11083 times.
✗ Branch 16 → 79 not taken.
✓ Branch 17 → 18 taken 11083 times.
✗ Branch 17 → 79 not taken.
|
11083 | const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes()); |
| 118 |
1/2✓ Branch 18 → 19 taken 11083 times.
✗ Branch 18 → 77 not taken.
|
11083 | changeToScope(scopeName, ScopeType::STRUCT); |
| 119 | 11083 | } | |
| 120 | |||
| 121 | // Change to procedure scope | ||
| 122 |
1/2✓ Branch 21 → 22 taken 13076 times.
✗ Branch 21 → 88 not taken.
|
13076 | changeToScope(manifestation->bodyScope, ScopeType::FUNC_PROC_BODY); |
| 123 | |||
| 124 | // Mount type mapping for this manifestation | ||
| 125 |
1/2✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 13076 times.
|
13076 | assert(typeMapping.empty()); |
| 126 |
1/2✓ Branch 25 → 26 taken 13076 times.
✗ Branch 25 → 88 not taken.
|
13076 | typeMapping = manifestation->typeMapping; |
| 127 | |||
| 128 | // Visit parameters | ||
| 129 | // This happens once in the type checker prepare stage. This second time is only required if we have a generic procedure | ||
| 130 |
2/2✓ Branch 26 → 27 taken 9761 times.
✓ Branch 26 → 53 taken 3315 times.
|
13076 | if (node->hasParams) { |
| 131 |
1/2✓ Branch 27 → 28 taken 9761 times.
✗ Branch 27 → 80 not taken.
|
9761 | visit(node->paramLst); |
| 132 | // Annotate function/procedure-typed params with lambda-capture info from the resolved manifestation type. | ||
| 133 | // This must happen in the TypeChecker so that the IRGenerator can treat SymbolTableEntry as immutable. | ||
| 134 |
2/2✓ Branch 52 → 30 taken 13539 times.
✓ Branch 52 → 53 taken 9761 times.
|
23300 | for (size_t i = 0; i < manifestation->paramList.size(); i++) { |
| 135 |
1/2✓ Branch 30 → 31 taken 13539 times.
✗ Branch 30 → 86 not taken.
|
13539 | const DeclStmtNode *param = node->paramLst->params.at(i); |
| 136 |
2/4✓ Branch 31 → 32 taken 13539 times.
✗ Branch 31 → 83 not taken.
✓ Branch 32 → 33 taken 13539 times.
✗ Branch 32 → 81 not taken.
|
13539 | const QualType paramType = manifestation->getParamTypes().at(i); |
| 137 |
8/10✓ Branch 34 → 35 taken 13539 times.
✗ Branch 34 → 84 not taken.
✓ Branch 35 → 36 taken 59 times.
✓ Branch 35 → 39 taken 13480 times.
✓ Branch 36 → 37 taken 59 times.
✗ Branch 36 → 84 not taken.
✓ Branch 37 → 38 taken 13 times.
✓ Branch 37 → 39 taken 46 times.
✓ Branch 40 → 41 taken 13 times.
✓ Branch 40 → 50 taken 13526 times.
|
13539 | if (paramType.isOneOf({TY_FUNCTION, TY_PROCEDURE}) && paramType.hasLambdaCaptures()) { |
| 138 |
1/2✓ Branch 41 → 42 taken 13 times.
✗ Branch 41 → 86 not taken.
|
13 | SymbolTableEntry *paramSymbol = currentScope->lookupStrict(param->varName); |
| 139 |
1/2✗ Branch 44 → 45 not taken.
✓ Branch 44 → 46 taken 13 times.
|
13 | assert(paramSymbol != nullptr); |
| 140 |
3/6✓ Branch 46 → 47 taken 13 times.
✗ Branch 46 → 85 not taken.
✓ Branch 47 → 48 taken 13 times.
✗ Branch 47 → 85 not taken.
✓ Branch 48 → 49 taken 13 times.
✗ Branch 48 → 85 not taken.
|
13 | paramSymbol->updateType(paramSymbol->getQualType().getWithLambdaCaptures(), true); |
| 141 | } | ||
| 142 | } | ||
| 143 | } | ||
| 144 | |||
| 145 | // Prepare generation of special ctor preamble to store VTable, default field values, etc. if required | ||
| 146 |
2/2✓ Branch 53 → 54 taken 6024 times.
✓ Branch 53 → 55 taken 7052 times.
|
13076 | if (node->isCtor) |
| 147 |
1/2✓ Branch 54 → 55 taken 6024 times.
✗ Branch 54 → 88 not taken.
|
6024 | createCtorBodyPreamble(node->scope); |
| 148 | |||
| 149 | // Visit statements in new scope | ||
| 150 |
1/2✓ Branch 55 → 56 taken 13076 times.
✗ Branch 55 → 87 not taken.
|
13076 | visit(node->body); |
| 151 | |||
| 152 | // Clear type mapping | ||
| 153 | 13076 | typeMapping.clear(); | |
| 154 | |||
| 155 | // Change to root scope | ||
| 156 | 13076 | currentScope = rootScope; | |
| 157 |
2/4✓ Branch 58 → 59 taken 13076 times.
✗ Branch 58 → 61 not taken.
✓ Branch 59 → 60 taken 13076 times.
✗ Branch 59 → 61 not taken.
|
13076 | assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL); |
| 158 | |||
| 159 | // Do not type-check this manifestation again | ||
| 160 | 13076 | manifestation->alreadyTypeChecked = true; | |
| 161 | |||
| 162 | 13076 | manIdx++; // Increase the manifestation index | |
| 163 | } | ||
| 164 | 27099 | manIdx = 0; // Reset the manifestation index | |
| 165 | |||
| 166 |
1/2✓ Branch 73 → 74 taken 27099 times.
✗ Branch 73 → 89 not taken.
|
54198 | return nullptr; |
| 167 | } | ||
| 168 | |||
| 169 | 6168 | std::any TypeChecker::visitStructDefCheck(StructDefNode *node) { | |
| 170 | 6168 | node->resizeToNumberOfManifestations(node->structManifestations.size()); | |
| 171 | 6168 | manIdx = 0; // Reset the manifestation index | |
| 172 | |||
| 173 | // Get all manifestations for this procedure definition | ||
| 174 |
2/2✓ Branch 215 → 6 taken 11406 times.
✓ Branch 215 → 216 taken 6168 times.
|
23742 | for (Struct *manifestation : node->structManifestations) { |
| 175 | // Skip non-substantiated or already checked procedures | ||
| 176 |
3/4✓ Branch 8 → 9 taken 11406 times.
✗ Branch 8 → 299 not taken.
✓ Branch 9 → 10 taken 1982 times.
✓ Branch 9 → 11 taken 9424 times.
|
11406 | if (!manifestation->isFullySubstantiated()) { |
| 177 | 1982 | manIdx++; // Increase the manifestation index | |
| 178 | 1982 | continue; | |
| 179 | } | ||
| 180 | |||
| 181 | // Fallback for manifestations that could not be decided on when they were created, because a by-value struct field | ||
| 182 | // was not manifested yet at that point (circular import). By now the whole import graph is prepared, so the | ||
| 183 | // decision can be taken - late, but still before the struct's own default member bodies are prepared below. | ||
| 184 |
1/2✓ Branch 11 → 12 taken 9424 times.
✗ Branch 11 → 299 not taken.
|
9424 | createImplicitDefaultMembers(*manifestation, node, /*withMoveCtor=*/false); |
| 185 | |||
| 186 | // Change to struct scope | ||
| 187 |
1/2✓ Branch 12 → 13 taken 9424 times.
✗ Branch 12 → 299 not taken.
|
9424 | changeToScope(manifestation->scope, ScopeType::STRUCT); |
| 188 | |||
| 189 | // Mount type mapping for this manifestation, so that the body preamble helpers below can substantiate | ||
| 190 | // generic field types (e.g. `heap T*` on `Vector<T>`). Without this, an auto-generated body preamble that | ||
| 191 | // touches a still-generic field would assert in TypeMatcher::substantiateTypeWithTypeMapping. | ||
| 192 |
1/2✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 9424 times.
|
9424 | assert(typeMapping.empty()); |
| 193 |
1/2✓ Branch 16 → 17 taken 9424 times.
✗ Branch 16 → 299 not taken.
|
9424 | typeMapping = manifestation->typeMapping; |
| 194 | |||
| 195 | // Re-visit all default values. This is required, since the type of the default value might vary for different manifestations | ||
| 196 |
2/2✓ Branch 40 → 19 taken 19679 times.
✓ Branch 40 → 41 taken 9424 times.
|
38527 | for (const FieldNode *field : node->fields) { |
| 197 |
2/2✓ Branch 21 → 22 taken 8724 times.
✓ Branch 21 → 31 taken 10955 times.
|
19679 | if (field->defaultValue != nullptr) { |
| 198 |
1/2✓ Branch 22 → 23 taken 8724 times.
✗ Branch 22 → 220 not taken.
|
8724 | visit(field->defaultValue); |
| 199 |
1/2✓ Branch 24 → 25 taken 8724 times.
✗ Branch 24 → 222 not taken.
|
8724 | SymbolTableEntry *fieldEntry = manifestation->scope->lookupStrict(field->fieldName); |
| 200 |
1/2✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 8724 times.
|
8724 | assert(fieldEntry != nullptr); |
| 201 |
1/2✓ Branch 29 → 30 taken 8724 times.
✗ Branch 29 → 221 not taken.
|
8724 | fieldEntry->updateState(INITIALIZED, field); |
| 202 | } | ||
| 203 | } | ||
| 204 | |||
| 205 | // Build struct type | ||
| 206 |
1/2✓ Branch 41 → 42 taken 9424 times.
✗ Branch 41 → 299 not taken.
|
9424 | const QualType structType = manifestation->entry->getQualType(); |
| 207 | |||
| 208 | // Check if the struct implements all methods of all attached interfaces | ||
| 209 | 9424 | size_t vtableIndex = 0; | |
| 210 |
2/2✓ Branch 146 → 44 taken 3148 times.
✓ Branch 146 → 147 taken 9424 times.
|
21996 | for (const QualType &interfaceType : manifestation->interfaceTypes) { |
| 211 |
1/2✓ Branch 46 → 47 taken 3148 times.
✗ Branch 46 → 266 not taken.
|
3148 | const Interface *interface = interfaceType.getInterface(node); |
| 212 |
1/2✗ Branch 47 → 48 not taken.
✓ Branch 47 → 49 taken 3148 times.
|
3148 | assert(interface != nullptr); |
| 213 | |||
| 214 | // Check for all methods, that it is implemented by the struct | ||
| 215 |
2/2✓ Branch 136 → 51 taken 8918 times.
✓ Branch 136 → 137 taken 3148 times.
|
15214 | for (const Function *expMethod : interface->methods) { |
| 216 |
1/2✓ Branch 53 → 54 taken 8918 times.
✗ Branch 53 → 264 not taken.
|
8918 | const std::string methodName = expMethod->name; |
| 217 |
1/2✓ Branch 54 → 55 taken 8918 times.
✗ Branch 54 → 262 not taken.
|
8918 | QualTypeList params = expMethod->getParamTypes(); |
| 218 | 8918 | QualType returnType = expMethod->returnType; | |
| 219 | |||
| 220 | // Substantiate param and return types | ||
| 221 |
1/2✓ Branch 55 → 56 taken 8918 times.
✗ Branch 55 → 260 not taken.
|
8918 | TypeMatcher::substantiateTypesWithTypeMapping(params, interface->typeMapping, node); |
| 222 |
3/4✓ Branch 56 → 57 taken 8918 times.
✗ Branch 56 → 260 not taken.
✓ Branch 57 → 58 taken 4546 times.
✓ Branch 57 → 59 taken 4372 times.
|
8918 | if (returnType.hasAnyGenericParts()) |
| 223 |
1/2✓ Branch 58 → 59 taken 4546 times.
✗ Branch 58 → 260 not taken.
|
4546 | TypeMatcher::substantiateTypeWithTypeMapping(returnType, interface->typeMapping, node); |
| 224 | |||
| 225 | // Build args list | ||
| 226 | 8918 | ArgList args; | |
| 227 |
1/2✓ Branch 60 → 61 taken 8918 times.
✗ Branch 60 → 258 not taken.
|
8918 | args.reserve(params.size()); |
| 228 |
2/2✓ Branch 75 → 63 taken 1080 times.
✓ Branch 75 → 76 taken 8918 times.
|
18916 | for (const QualType ¶m : params) |
| 229 |
1/2✓ Branch 65 → 66 taken 1080 times.
✗ Branch 65 → 223 not taken.
|
1080 | args.emplace_back(param, nullptr); |
| 230 | |||
| 231 | // Search for method that has the required signature | ||
| 232 |
1/2✓ Branch 77 → 78 taken 8918 times.
✗ Branch 77 → 225 not taken.
|
8918 | Function *spiceFunction = FunctionManager::match(currentScope, methodName, structType, args, {}, true, node); |
| 233 |
2/2✓ Branch 79 → 80 taken 4 times.
✓ Branch 79 → 92 taken 8914 times.
|
8918 | if (spiceFunction == nullptr) { |
| 234 |
1/2✓ Branch 85 → 86 taken 4 times.
✗ Branch 85 → 228 not taken.
|
4 | softError(node, INTERFACE_METHOD_NOT_IMPLEMENTED, |
| 235 |
5/10✓ Branch 80 → 81 taken 4 times.
✗ Branch 80 → 240 not taken.
✓ Branch 81 → 82 taken 4 times.
✗ Branch 81 → 236 not taken.
✓ Branch 82 → 83 taken 4 times.
✗ Branch 82 → 234 not taken.
✓ Branch 83 → 84 taken 4 times.
✗ Branch 83 → 232 not taken.
✓ Branch 84 → 85 taken 4 times.
✗ Branch 84 → 230 not taken.
|
8 | "The struct '" + node->structName + "' does not implement method '" + expMethod->getSignature() + "'."); |
| 236 | 4 | continue; | |
| 237 | } | ||
| 238 | |||
| 239 | // Check return type | ||
| 240 |
5/6✓ Branch 92 → 93 taken 8914 times.
✗ Branch 92 → 258 not taken.
✓ Branch 93 → 94 taken 1496 times.
✓ Branch 93 → 97 taken 7418 times.
✓ Branch 98 → 99 taken 2 times.
✓ Branch 98 → 111 taken 8912 times.
|
10410 | if (spiceFunction->returnType != returnType && |
| 241 |
3/4✓ Branch 94 → 95 taken 1496 times.
✗ Branch 94 → 258 not taken.
✓ Branch 95 → 96 taken 2 times.
✓ Branch 95 → 97 taken 1494 times.
|
1496 | !returnType.matchesInterfaceImplementedByStruct(spiceFunction->returnType)) { |
| 242 |
1/2✓ Branch 104 → 105 taken 2 times.
✗ Branch 104 → 243 not taken.
|
2 | softError(node, INTERFACE_METHOD_NOT_IMPLEMENTED, |
| 243 |
4/8✓ Branch 99 → 100 taken 2 times.
✗ Branch 99 → 255 not taken.
✓ Branch 100 → 101 taken 2 times.
✗ Branch 100 → 251 not taken.
✓ Branch 101 → 102 taken 2 times.
✗ Branch 101 → 249 not taken.
✓ Branch 102 → 103 taken 2 times.
✗ Branch 102 → 247 not taken.
|
4 | "The struct '" + node->structName + "' does not implement method '" + expMethod->getSignature() + |
| 244 |
1/2✓ Branch 103 → 104 taken 2 times.
✗ Branch 103 → 245 not taken.
|
2 | "'. The return type does not match."); |
| 245 | 2 | continue; | |
| 246 | } | ||
| 247 | // Set to virtual, since it overrides the interface method | ||
| 248 | 8912 | spiceFunction->isVirtual = true; | |
| 249 | 8912 | spiceFunction->vtableIndex = vtableIndex++; | |
| 250 |
6/6✓ Branch 113 → 114 taken 8912 times.
✓ Branch 113 → 115 taken 6 times.
✓ Branch 118 → 119 taken 8912 times.
✓ Branch 118 → 120 taken 6 times.
✓ Branch 123 → 124 taken 8912 times.
✓ Branch 123 → 126 taken 6 times.
|
26754 | } |
| 251 | } | ||
| 252 | |||
| 253 | // Check default ctor body if required | ||
| 254 |
2/4✓ Branch 150 → 151 taken 9424 times.
✗ Branch 150 → 269 not taken.
✓ Branch 151 → 152 taken 9424 times.
✗ Branch 151 → 267 not taken.
|
28272 | const Function *ctorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, {}, true); |
| 255 |
4/4✓ Branch 155 → 156 taken 2290 times.
✓ Branch 155 → 161 taken 7134 times.
✓ Branch 156 → 157 taken 243 times.
✓ Branch 156 → 161 taken 2047 times.
|
9424 | if (ctorFunc != nullptr && ctorFunc->implicitDefault) { |
| 256 |
1/2✓ Branch 157 → 158 taken 243 times.
✗ Branch 157 → 299 not taken.
|
243 | createCtorBodyPreamble(ctorFunc->bodyScope); |
| 257 |
2/4✓ Branch 158 → 159 taken 243 times.
✗ Branch 158 → 299 not taken.
✗ Branch 159 → 160 not taken.
✓ Branch 159 → 161 taken 243 times.
|
243 | assert(manifestation->areAllFieldsInitialized() == nullptr); |
| 258 | } | ||
| 259 | |||
| 260 | // Check default copy ctor body if required | ||
| 261 |
2/4✓ Branch 161 → 162 taken 9424 times.
✗ Branch 161 → 280 not taken.
✓ Branch 165 → 166 taken 9424 times.
✗ Branch 165 → 276 not taken.
|
28272 | const ArgList args = {{structType.toConstRef(node), false /* always non-temporary */}}; |
| 262 |
2/4✓ Branch 169 → 170 taken 9424 times.
✗ Branch 169 → 284 not taken.
✓ Branch 170 → 171 taken 9424 times.
✗ Branch 170 → 282 not taken.
|
9424 | const Function *copyCtorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, args, true); |
| 263 |
4/4✓ Branch 173 → 174 taken 4713 times.
✓ Branch 173 → 179 taken 4711 times.
✓ Branch 174 → 175 taken 3465 times.
✓ Branch 174 → 179 taken 1248 times.
|
9424 | if (copyCtorFunc != nullptr && copyCtorFunc->implicitDefault) { |
| 264 |
1/2✓ Branch 175 → 176 taken 3465 times.
✗ Branch 175 → 297 not taken.
|
3465 | createCopyCtorBodyPreamble(copyCtorFunc->bodyScope); |
| 265 |
2/4✓ Branch 176 → 177 taken 3465 times.
✗ Branch 176 → 297 not taken.
✗ Branch 177 → 178 not taken.
✓ Branch 177 → 179 taken 3465 times.
|
3465 | assert(manifestation->areAllFieldsInitialized() == nullptr); |
| 266 | } | ||
| 267 | |||
| 268 | // Check default move ctor body if required. findMoveCtor scans the manifestations directly to avoid the | ||
| 269 | // constify-based false-positive that FunctionManager::lookup with a non-const ref arg can produce. | ||
| 270 |
3/4✓ Branch 179 → 180 taken 9424 times.
✗ Branch 179 → 297 not taken.
✓ Branch 180 → 181 taken 392 times.
✓ Branch 180 → 186 taken 9032 times.
|
9424 | if (const Function *moveCtorFunc = FunctionManager::findMoveCtor(currentScope); |
| 271 |
2/2✓ Branch 181 → 182 taken 17 times.
✓ Branch 181 → 186 taken 375 times.
|
392 | moveCtorFunc && moveCtorFunc->implicitDefault) { |
| 272 |
1/2✓ Branch 182 → 183 taken 17 times.
✗ Branch 182 → 297 not taken.
|
17 | createMoveCtorBodyPreamble(moveCtorFunc->bodyScope); |
| 273 |
2/4✓ Branch 183 → 184 taken 17 times.
✗ Branch 183 → 297 not taken.
✗ Branch 184 → 185 not taken.
✓ Branch 184 → 186 taken 17 times.
|
17 | assert(manifestation->areAllFieldsInitialized() == nullptr); |
| 274 | } | ||
| 275 | |||
| 276 | // Check default dtor body if required | ||
| 277 |
2/4✓ Branch 189 → 190 taken 9424 times.
✗ Branch 189 → 290 not taken.
✓ Branch 190 → 191 taken 9424 times.
✗ Branch 190 → 288 not taken.
|
28272 | const Function *dtorFunc = FunctionManager::lookup(currentScope, DTOR_FUNCTION_NAME, structType, {}, true); |
| 278 |
4/4✓ Branch 194 → 195 taken 5431 times.
✓ Branch 194 → 197 taken 3993 times.
✓ Branch 195 → 196 taken 3708 times.
✓ Branch 195 → 197 taken 1723 times.
|
9424 | if (dtorFunc != nullptr && dtorFunc->implicitDefault) |
| 279 |
1/2✓ Branch 196 → 197 taken 3708 times.
✗ Branch 196 → 297 not taken.
|
3708 | createDtorBodyPreamble(dtorFunc->bodyScope, node); |
| 280 | |||
| 281 | // Reset field symbols to declared state for the next manifestation | ||
| 282 |
1/2✓ Branch 197 → 198 taken 9424 times.
✗ Branch 197 → 297 not taken.
|
9424 | manifestation->resetFieldSymbolsToDeclared(node); |
| 283 | |||
| 284 | // Clear type mapping | ||
| 285 | 9424 | typeMapping.clear(); | |
| 286 | |||
| 287 | // Return to the root scope | ||
| 288 | 9424 | currentScope = rootScope; | |
| 289 |
2/4✓ Branch 199 → 200 taken 9424 times.
✗ Branch 199 → 202 not taken.
✓ Branch 200 → 201 taken 9424 times.
✗ Branch 200 → 202 not taken.
|
9424 | assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL); |
| 290 | |||
| 291 | 9424 | manIdx++; // Increase the manifestation index | |
| 292 | 9424 | } | |
| 293 | 6168 | manIdx = 0; // Reset the manifestation index | |
| 294 | |||
| 295 |
1/2✓ Branch 216 → 217 taken 6168 times.
✗ Branch 216 → 301 not taken.
|
12336 | return nullptr; |
| 296 | } | ||
| 297 | |||
| 298 | } // namespace spice::compiler | ||
| 299 |