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 | 606 | 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 530 times.
|
606 | if (typeCheckedMainFct) |
| 19 |
1/2✓ Branch 3 → 4 taken 76 times.
✗ Branch 3 → 13 not taken.
|
152 | return nullptr; |
| 20 | |||
| 21 | 530 | node->resizeToNumberOfManifestations(1); | |
| 22 | |||
| 23 | // Change to function body scope | ||
| 24 | 530 | currentScope = node->bodyScope; | |
| 25 | // Visit statements in new scope | ||
| 26 |
2/2✓ Branch 7 → 8 taken 500 times.
✓ Branch 7 → 14 taken 30 times.
|
530 | visit(node->body); |
| 27 | // Leave main function body scope | ||
| 28 | 500 | currentScope = rootScope; | |
| 29 | |||
| 30 | // Set to type-checked | ||
| 31 | 500 | typeCheckedMainFct = true; | |
| 32 |
1/2✓ Branch 9 → 10 taken 500 times.
✗ Branch 9 → 15 not taken.
|
1000 | return nullptr; |
| 33 | } | ||
| 34 | |||
| 35 | 45298 | std::any TypeChecker::visitFctDefCheck(FctDefNode *node) { | |
| 36 | 45298 | node->resizeToNumberOfManifestations(node->manifestations.size()); | |
| 37 | 45298 | manIdx = 0; // Reset the manifestation index | |
| 38 | |||
| 39 | // Get all manifestations for this function definition | ||
| 40 |
2/2✓ Branch 79 → 6 taken 60378 times.
✓ Branch 79 → 80 taken 45296 times.
|
150972 | for (Function *manifestation : node->manifestations) { |
| 41 | // Skip non-substantiated or already checked functions | ||
| 42 |
7/8✓ Branch 8 → 9 taken 60378 times.
✗ Branch 8 → 101 not taken.
✓ Branch 9 → 10 taken 49302 times.
✓ Branch 9 → 11 taken 11076 times.
✓ Branch 10 → 11 taken 26177 times.
✓ Branch 10 → 12 taken 23125 times.
✓ Branch 13 → 14 taken 37253 times.
✓ Branch 13 → 15 taken 23125 times.
|
60378 | if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) { |
| 43 | 37253 | manIdx++; // Increase the manifestation index | |
| 44 | 37253 | continue; | |
| 45 | } | ||
| 46 | |||
| 47 | // Change scope to concrete struct specialization scope | ||
| 48 |
2/2✓ Branch 15 → 16 taken 13105 times.
✓ Branch 15 → 21 taken 10020 times.
|
23125 | if (node->isMethod) { |
| 49 |
2/4✓ Branch 16 → 17 taken 13105 times.
✗ Branch 16 → 86 not taken.
✓ Branch 17 → 18 taken 13105 times.
✗ Branch 17 → 86 not taken.
|
13105 | const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes()); |
| 50 |
1/2✓ Branch 18 → 19 taken 13105 times.
✗ Branch 18 → 84 not taken.
|
13105 | changeToScope(scopeName, ScopeType::STRUCT); |
| 51 | 13105 | } | |
| 52 | |||
| 53 | // Change to function scope | ||
| 54 |
1/2✓ Branch 21 → 22 taken 23125 times.
✗ Branch 21 → 101 not taken.
|
23125 | 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 23125 times.
|
23125 | assert(typeMapping.empty()); |
| 58 |
1/2✓ Branch 25 → 26 taken 23125 times.
✗ Branch 25 → 101 not taken.
|
23125 | typeMapping = manifestation->typeMapping; |
| 59 | |||
| 60 | // Set return type to the result variable | ||
| 61 |
1/2✓ Branch 28 → 29 taken 23125 times.
✗ Branch 28 → 89 not taken.
|
69375 | SymbolTableEntry *resultVarEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME); |
| 62 |
1/2✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 23125 times.
|
23125 | assert(resultVarEntry != nullptr); |
| 63 |
1/2✓ Branch 36 → 37 taken 23125 times.
✗ Branch 36 → 101 not taken.
|
23125 | resultVarEntry->updateType(manifestation->returnType, false); |
| 64 | 23125 | 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 16854 times.
✓ Branch 37 → 64 taken 6271 times.
|
23125 | if (node->hasParams) { |
| 69 |
1/2✓ Branch 38 → 39 taken 16854 times.
✗ Branch 38 → 93 not taken.
|
16854 | 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 24559 times.
✓ Branch 63 → 64 taken 16854 times.
|
41413 | for (size_t i = 0; i < manifestation->paramList.size(); i++) { |
| 73 |
1/2✓ Branch 41 → 42 taken 24559 times.
✗ Branch 41 → 99 not taken.
|
24559 | const DeclStmtNode *param = node->paramLst->params.at(i); |
| 74 |
2/4✓ Branch 42 → 43 taken 24559 times.
✗ Branch 42 → 96 not taken.
✓ Branch 43 → 44 taken 24559 times.
✗ Branch 43 → 94 not taken.
|
24559 | const QualType paramType = manifestation->getParamTypes().at(i); |
| 75 |
8/10✓ Branch 45 → 46 taken 24559 times.
✗ Branch 45 → 97 not taken.
✓ Branch 46 → 47 taken 6 times.
✓ Branch 46 → 50 taken 24553 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 24557 times.
|
24559 | 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 23123 times.
✓ Branch 64 → 100 taken 2 times.
|
23125 | visit(node->body); |
| 85 | |||
| 86 | // Clear type mapping | ||
| 87 | 23123 | typeMapping.clear(); | |
| 88 | |||
| 89 | // Change to root scope | ||
| 90 | 23123 | currentScope = rootScope; | |
| 91 |
1/2✗ Branch 67 → 68 not taken.
✓ Branch 67 → 69 taken 23123 times.
|
23123 | assert(currentScope->type == ScopeType::GLOBAL); |
| 92 | |||
| 93 | // Do not type-check this manifestation again | ||
| 94 | 23123 | manifestation->alreadyTypeChecked = true; | |
| 95 | |||
| 96 | 23123 | manIdx++; // Increase the manifestation index | |
| 97 | } | ||
| 98 | 45296 | manIdx = 0; // Reset the manifestation index | |
| 99 | |||
| 100 |
1/2✓ Branch 80 → 81 taken 45296 times.
✗ Branch 80 → 102 not taken.
|
90592 | return nullptr; |
| 101 | } | ||
| 102 | |||
| 103 | 24934 | std::any TypeChecker::visitProcDefCheck(ProcDefNode *node) { | |
| 104 | 24934 | node->resizeToNumberOfManifestations(node->manifestations.size()); | |
| 105 | 24934 | manIdx = 0; // Reset the manifestation index | |
| 106 | |||
| 107 | // Get all manifestations for this procedure definition | ||
| 108 |
2/2✓ Branch 72 → 6 taken 36653 times.
✓ Branch 72 → 73 taken 24934 times.
|
86521 | for (Function *manifestation : node->manifestations) { |
| 109 | // Skip non-substantiated or already checked procedures | ||
| 110 |
7/8✓ Branch 8 → 9 taken 36653 times.
✗ Branch 8 → 88 not taken.
✓ Branch 9 → 10 taken 25003 times.
✓ Branch 9 → 11 taken 11650 times.
✓ Branch 10 → 11 taken 12231 times.
✓ Branch 10 → 12 taken 12772 times.
✓ Branch 13 → 14 taken 23881 times.
✓ Branch 13 → 15 taken 12772 times.
|
36653 | if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) { |
| 111 | 23881 | manIdx++; // Increase the manifestation index | |
| 112 | 23881 | continue; | |
| 113 | } | ||
| 114 | |||
| 115 | // Change scope to concrete struct specialization scope | ||
| 116 |
2/2✓ Branch 15 → 16 taken 10825 times.
✓ Branch 15 → 21 taken 1947 times.
|
12772 | if (node->isMethod) { |
| 117 |
2/4✓ Branch 16 → 17 taken 10825 times.
✗ Branch 16 → 79 not taken.
✓ Branch 17 → 18 taken 10825 times.
✗ Branch 17 → 79 not taken.
|
10825 | const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes()); |
| 118 |
1/2✓ Branch 18 → 19 taken 10825 times.
✗ Branch 18 → 77 not taken.
|
10825 | changeToScope(scopeName, ScopeType::STRUCT); |
| 119 | 10825 | } | |
| 120 | |||
| 121 | // Change to procedure scope | ||
| 122 |
1/2✓ Branch 21 → 22 taken 12772 times.
✗ Branch 21 → 88 not taken.
|
12772 | 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 12772 times.
|
12772 | assert(typeMapping.empty()); |
| 126 |
1/2✓ Branch 25 → 26 taken 12772 times.
✗ Branch 25 → 88 not taken.
|
12772 | 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 9587 times.
✓ Branch 26 → 53 taken 3185 times.
|
12772 | if (node->hasParams) { |
| 131 |
1/2✓ Branch 27 → 28 taken 9587 times.
✗ Branch 27 → 80 not taken.
|
9587 | 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 13358 times.
✓ Branch 52 → 53 taken 9587 times.
|
22945 | for (size_t i = 0; i < manifestation->paramList.size(); i++) { |
| 135 |
1/2✓ Branch 30 → 31 taken 13358 times.
✗ Branch 30 → 86 not taken.
|
13358 | const DeclStmtNode *param = node->paramLst->params.at(i); |
| 136 |
2/4✓ Branch 31 → 32 taken 13358 times.
✗ Branch 31 → 83 not taken.
✓ Branch 32 → 33 taken 13358 times.
✗ Branch 32 → 81 not taken.
|
13358 | const QualType paramType = manifestation->getParamTypes().at(i); |
| 137 |
8/10✓ Branch 34 → 35 taken 13358 times.
✗ Branch 34 → 84 not taken.
✓ Branch 35 → 36 taken 59 times.
✓ Branch 35 → 39 taken 13299 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 13345 times.
|
13358 | 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 5749 times.
✓ Branch 53 → 55 taken 7023 times.
|
12772 | if (node->isCtor) |
| 147 |
1/2✓ Branch 54 → 55 taken 5749 times.
✗ Branch 54 → 88 not taken.
|
5749 | createCtorBodyPreamble(node->scope); |
| 148 | |||
| 149 | // Visit statements in new scope | ||
| 150 |
1/2✓ Branch 55 → 56 taken 12772 times.
✗ Branch 55 → 87 not taken.
|
12772 | visit(node->body); |
| 151 | |||
| 152 | // Clear type mapping | ||
| 153 | 12772 | typeMapping.clear(); | |
| 154 | |||
| 155 | // Change to root scope | ||
| 156 | 12772 | currentScope = rootScope; | |
| 157 |
2/4✓ Branch 58 → 59 taken 12772 times.
✗ Branch 58 → 61 not taken.
✓ Branch 59 → 60 taken 12772 times.
✗ Branch 59 → 61 not taken.
|
12772 | assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL); |
| 158 | |||
| 159 | // Do not type-check this manifestation again | ||
| 160 | 12772 | manifestation->alreadyTypeChecked = true; | |
| 161 | |||
| 162 | 12772 | manIdx++; // Increase the manifestation index | |
| 163 | } | ||
| 164 | 24934 | manIdx = 0; // Reset the manifestation index | |
| 165 | |||
| 166 |
1/2✓ Branch 73 → 74 taken 24934 times.
✗ Branch 73 → 89 not taken.
|
49868 | return nullptr; |
| 167 | } | ||
| 168 | |||
| 169 | 5833 | std::any TypeChecker::visitStructDefCheck(StructDefNode *node) { | |
| 170 | 5833 | node->resizeToNumberOfManifestations(node->structManifestations.size()); | |
| 171 | 5833 | manIdx = 0; // Reset the manifestation index | |
| 172 | |||
| 173 | // Get all manifestations for this procedure definition | ||
| 174 |
2/2✓ Branch 215 → 6 taken 9841 times.
✓ Branch 215 → 216 taken 5833 times.
|
21507 | for (Struct *manifestation : node->structManifestations) { |
| 175 | // Skip non-substantiated or already checked procedures | ||
| 176 |
3/4✓ Branch 8 → 9 taken 9841 times.
✗ Branch 8 → 299 not taken.
✓ Branch 9 → 10 taken 1653 times.
✓ Branch 9 → 11 taken 8188 times.
|
9841 | if (!manifestation->isFullySubstantiated()) { |
| 177 | 1653 | manIdx++; // Increase the manifestation index | |
| 178 | 1653 | 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 8188 times.
✗ Branch 11 → 299 not taken.
|
8188 | createImplicitDefaultMembers(*manifestation, node, /*withMoveCtor=*/false); |
| 185 | |||
| 186 | // Change to struct scope | ||
| 187 |
1/2✓ Branch 12 → 13 taken 8188 times.
✗ Branch 12 → 299 not taken.
|
8188 | 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 8188 times.
|
8188 | assert(typeMapping.empty()); |
| 193 |
1/2✓ Branch 16 → 17 taken 8188 times.
✗ Branch 16 → 299 not taken.
|
8188 | 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 17015 times.
✓ Branch 40 → 41 taken 8188 times.
|
33391 | for (const FieldNode *field : node->fields) { |
| 197 |
2/2✓ Branch 21 → 22 taken 6832 times.
✓ Branch 21 → 31 taken 10183 times.
|
17015 | if (field->defaultValue != nullptr) { |
| 198 |
1/2✓ Branch 22 → 23 taken 6832 times.
✗ Branch 22 → 220 not taken.
|
6832 | visit(field->defaultValue); |
| 199 |
1/2✓ Branch 24 → 25 taken 6832 times.
✗ Branch 24 → 222 not taken.
|
6832 | SymbolTableEntry *fieldEntry = manifestation->scope->lookupStrict(field->fieldName); |
| 200 |
1/2✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 6832 times.
|
6832 | assert(fieldEntry != nullptr); |
| 201 |
1/2✓ Branch 29 → 30 taken 6832 times.
✗ Branch 29 → 221 not taken.
|
6832 | fieldEntry->updateState(INITIALIZED, field); |
| 202 | } | ||
| 203 | } | ||
| 204 | |||
| 205 | // Build struct type | ||
| 206 |
1/2✓ Branch 41 → 42 taken 8188 times.
✗ Branch 41 → 299 not taken.
|
8188 | const QualType structType = manifestation->entry->getQualType(); |
| 207 | |||
| 208 | // Check if the struct implements all methods of all attached interfaces | ||
| 209 | 8188 | size_t vtableIndex = 0; | |
| 210 |
2/2✓ Branch 146 → 44 taken 2118 times.
✓ Branch 146 → 147 taken 8188 times.
|
18494 | for (const QualType &interfaceType : manifestation->interfaceTypes) { |
| 211 |
1/2✓ Branch 46 → 47 taken 2118 times.
✗ Branch 46 → 266 not taken.
|
2118 | const Interface *interface = interfaceType.getInterface(node); |
| 212 |
1/2✗ Branch 47 → 48 not taken.
✓ Branch 47 → 49 taken 2118 times.
|
2118 | assert(interface != nullptr); |
| 213 | |||
| 214 | // Check for all methods, that it is implemented by the struct | ||
| 215 |
2/2✓ Branch 136 → 51 taken 6343 times.
✓ Branch 136 → 137 taken 2118 times.
|
10579 | for (const Function *expMethod : interface->methods) { |
| 216 |
1/2✓ Branch 53 → 54 taken 6343 times.
✗ Branch 53 → 264 not taken.
|
6343 | const std::string methodName = expMethod->name; |
| 217 |
1/2✓ Branch 54 → 55 taken 6343 times.
✗ Branch 54 → 262 not taken.
|
6343 | QualTypeList params = expMethod->getParamTypes(); |
| 218 | 6343 | QualType returnType = expMethod->returnType; | |
| 219 | |||
| 220 | // Substantiate param and return types | ||
| 221 |
1/2✓ Branch 55 → 56 taken 6343 times.
✗ Branch 55 → 260 not taken.
|
6343 | TypeMatcher::substantiateTypesWithTypeMapping(params, interface->typeMapping, node); |
| 222 |
3/4✓ Branch 56 → 57 taken 6343 times.
✗ Branch 56 → 260 not taken.
✓ Branch 57 → 58 taken 3001 times.
✓ Branch 57 → 59 taken 3342 times.
|
6343 | if (returnType.hasAnyGenericParts()) |
| 223 |
1/2✓ Branch 58 → 59 taken 3001 times.
✗ Branch 58 → 260 not taken.
|
3001 | TypeMatcher::substantiateTypeWithTypeMapping(returnType, interface->typeMapping, node); |
| 224 | |||
| 225 | // Build args list | ||
| 226 | 6343 | ArgList args; | |
| 227 |
1/2✓ Branch 60 → 61 taken 6343 times.
✗ Branch 60 → 258 not taken.
|
6343 | args.reserve(params.size()); |
| 228 |
2/2✓ Branch 75 → 63 taken 1080 times.
✓ Branch 75 → 76 taken 6343 times.
|
13766 | 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 6343 times.
✗ Branch 77 → 225 not taken.
|
6343 | Function *spiceFunction = FunctionManager::match(currentScope, methodName, structType, args, {}, true, node); |
| 233 |
2/2✓ Branch 79 → 80 taken 4 times.
✓ Branch 79 → 92 taken 6339 times.
|
6343 | 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 6339 times.
✗ Branch 92 → 258 not taken.
✓ Branch 93 → 94 taken 981 times.
✓ Branch 93 → 97 taken 5358 times.
✓ Branch 98 → 99 taken 2 times.
✓ Branch 98 → 111 taken 6337 times.
|
7320 | if (spiceFunction->returnType != returnType && |
| 241 |
3/4✓ Branch 94 → 95 taken 981 times.
✗ Branch 94 → 258 not taken.
✓ Branch 95 → 96 taken 2 times.
✓ Branch 95 → 97 taken 979 times.
|
981 | !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 | 6337 | spiceFunction->isVirtual = true; | |
| 249 | 6337 | spiceFunction->vtableIndex = vtableIndex++; | |
| 250 |
6/6✓ Branch 113 → 114 taken 6337 times.
✓ Branch 113 → 115 taken 6 times.
✓ Branch 118 → 119 taken 6337 times.
✓ Branch 118 → 120 taken 6 times.
✓ Branch 123 → 124 taken 6337 times.
✓ Branch 123 → 126 taken 6 times.
|
19029 | } |
| 251 | } | ||
| 252 | |||
| 253 | // Check default ctor body if required | ||
| 254 |
2/4✓ Branch 150 → 151 taken 8188 times.
✗ Branch 150 → 269 not taken.
✓ Branch 151 → 152 taken 8188 times.
✗ Branch 151 → 267 not taken.
|
24564 | const Function *ctorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, {}, true); |
| 255 |
4/4✓ Branch 155 → 156 taken 1970 times.
✓ Branch 155 → 161 taken 6218 times.
✓ Branch 156 → 157 taken 285 times.
✓ Branch 156 → 161 taken 1685 times.
|
8188 | if (ctorFunc != nullptr && ctorFunc->implicitDefault) { |
| 256 |
1/2✓ Branch 157 → 158 taken 285 times.
✗ Branch 157 → 299 not taken.
|
285 | createCtorBodyPreamble(ctorFunc->bodyScope); |
| 257 |
2/4✓ Branch 158 → 159 taken 285 times.
✗ Branch 158 → 299 not taken.
✗ Branch 159 → 160 not taken.
✓ Branch 159 → 161 taken 285 times.
|
285 | assert(manifestation->areAllFieldsInitialized() == nullptr); |
| 258 | } | ||
| 259 | |||
| 260 | // Check default copy ctor body if required | ||
| 261 |
2/4✓ Branch 161 → 162 taken 8188 times.
✗ Branch 161 → 280 not taken.
✓ Branch 165 → 166 taken 8188 times.
✗ Branch 165 → 276 not taken.
|
24564 | const ArgList args = {{structType.toConstRef(node), false /* always non-temporary */}}; |
| 262 |
2/4✓ Branch 169 → 170 taken 8188 times.
✗ Branch 169 → 284 not taken.
✓ Branch 170 → 171 taken 8188 times.
✗ Branch 170 → 282 not taken.
|
8188 | const Function *copyCtorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, args, true); |
| 263 |
4/4✓ Branch 173 → 174 taken 4550 times.
✓ Branch 173 → 179 taken 3638 times.
✓ Branch 174 → 175 taken 3492 times.
✓ Branch 174 → 179 taken 1058 times.
|
8188 | if (copyCtorFunc != nullptr && copyCtorFunc->implicitDefault) { |
| 264 |
1/2✓ Branch 175 → 176 taken 3492 times.
✗ Branch 175 → 297 not taken.
|
3492 | createCopyCtorBodyPreamble(copyCtorFunc->bodyScope); |
| 265 |
2/4✓ Branch 176 → 177 taken 3492 times.
✗ Branch 176 → 297 not taken.
✗ Branch 177 → 178 not taken.
✓ Branch 177 → 179 taken 3492 times.
|
3492 | 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 8188 times.
✗ Branch 179 → 297 not taken.
✓ Branch 180 → 181 taken 103 times.
✓ Branch 180 → 186 taken 8085 times.
|
8188 | if (const Function *moveCtorFunc = FunctionManager::findMoveCtor(currentScope); |
| 271 |
2/2✓ Branch 181 → 182 taken 17 times.
✓ Branch 181 → 186 taken 86 times.
|
103 | 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 8188 times.
✗ Branch 189 → 290 not taken.
✓ Branch 190 → 191 taken 8188 times.
✗ Branch 190 → 288 not taken.
|
24564 | const Function *dtorFunc = FunctionManager::lookup(currentScope, DTOR_FUNCTION_NAME, structType, {}, true); |
| 278 |
4/4✓ Branch 194 → 195 taken 4862 times.
✓ Branch 194 → 197 taken 3326 times.
✓ Branch 195 → 196 taken 3413 times.
✓ Branch 195 → 197 taken 1449 times.
|
8188 | if (dtorFunc != nullptr && dtorFunc->implicitDefault) |
| 279 |
1/2✓ Branch 196 → 197 taken 3413 times.
✗ Branch 196 → 297 not taken.
|
3413 | createDtorBodyPreamble(dtorFunc->bodyScope, node); |
| 280 | |||
| 281 | // Reset field symbols to declared state for the next manifestation | ||
| 282 |
1/2✓ Branch 197 → 198 taken 8188 times.
✗ Branch 197 → 297 not taken.
|
8188 | manifestation->resetFieldSymbolsToDeclared(node); |
| 283 | |||
| 284 | // Clear type mapping | ||
| 285 | 8188 | typeMapping.clear(); | |
| 286 | |||
| 287 | // Return to the root scope | ||
| 288 | 8188 | currentScope = rootScope; | |
| 289 |
2/4✓ Branch 199 → 200 taken 8188 times.
✗ Branch 199 → 202 not taken.
✓ Branch 200 → 201 taken 8188 times.
✗ Branch 200 → 202 not taken.
|
8188 | assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL); |
| 290 | |||
| 291 | 8188 | manIdx++; // Increase the manifestation index | |
| 292 | 8188 | } | |
| 293 | 5833 | manIdx = 0; // Reset the manifestation index | |
| 294 | |||
| 295 |
1/2✓ Branch 216 → 217 taken 5833 times.
✗ Branch 216 → 301 not taken.
|
11666 | return nullptr; |
| 296 | } | ||
| 297 | |||
| 298 | } // namespace spice::compiler | ||
| 299 |