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 | 567 | std::any TypeChecker::visitMainFctDefCheck(MainFctDefNode *node) { | |
| 17 | // Skip if already type-checked | ||
| 18 |
2/2✓ Branch 2 → 3 taken 65 times.
✓ Branch 2 → 6 taken 502 times.
|
567 | if (typeCheckedMainFct) |
| 19 |
1/2✓ Branch 3 → 4 taken 65 times.
✗ Branch 3 → 13 not taken.
|
130 | return nullptr; |
| 20 | |||
| 21 | 502 | node->resizeToNumberOfManifestations(1); | |
| 22 | |||
| 23 | // Change to function body scope | ||
| 24 | 502 | currentScope = node->bodyScope; | |
| 25 | // Visit statements in new scope | ||
| 26 |
2/2✓ Branch 7 → 8 taken 472 times.
✓ Branch 7 → 14 taken 30 times.
|
502 | visit(node->body); |
| 27 | // Leave main function body scope | ||
| 28 | 472 | currentScope = rootScope; | |
| 29 | |||
| 30 | // Set to type-checked | ||
| 31 | 472 | typeCheckedMainFct = true; | |
| 32 |
1/2✓ Branch 9 → 10 taken 472 times.
✗ Branch 9 → 15 not taken.
|
944 | return nullptr; |
| 33 | } | ||
| 34 | |||
| 35 | 41731 | std::any TypeChecker::visitFctDefCheck(FctDefNode *node) { | |
| 36 | 41731 | node->resizeToNumberOfManifestations(node->manifestations.size()); | |
| 37 | 41731 | manIdx = 0; // Reset the manifestation index | |
| 38 | |||
| 39 | // Get all manifestations for this function definition | ||
| 40 |
2/2✓ Branch 79 → 6 taken 57060 times.
✓ Branch 79 → 80 taken 41729 times.
|
140520 | for (Function *manifestation : node->manifestations) { |
| 41 | // Skip non-substantiated or already checked functions | ||
| 42 |
7/8✓ Branch 8 → 9 taken 57060 times.
✗ Branch 8 → 101 not taken.
✓ Branch 9 → 10 taken 46398 times.
✓ Branch 9 → 11 taken 10662 times.
✓ Branch 10 → 11 taken 24251 times.
✓ Branch 10 → 12 taken 22147 times.
✓ Branch 13 → 14 taken 34913 times.
✓ Branch 13 → 15 taken 22147 times.
|
57060 | if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) { |
| 43 | 34913 | manIdx++; // Increase the manifestation index | |
| 44 | 34913 | continue; | |
| 45 | } | ||
| 46 | |||
| 47 | // Change scope to concrete struct specialization scope | ||
| 48 |
2/2✓ Branch 15 → 16 taken 13100 times.
✓ Branch 15 → 21 taken 9047 times.
|
22147 | if (node->isMethod) { |
| 49 |
2/4✓ Branch 16 → 17 taken 13100 times.
✗ Branch 16 → 86 not taken.
✓ Branch 17 → 18 taken 13100 times.
✗ Branch 17 → 86 not taken.
|
13100 | const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes()); |
| 50 |
1/2✓ Branch 18 → 19 taken 13100 times.
✗ Branch 18 → 84 not taken.
|
13100 | changeToScope(scopeName, ScopeType::STRUCT); |
| 51 | 13100 | } | |
| 52 | |||
| 53 | // Change to function scope | ||
| 54 |
1/2✓ Branch 21 → 22 taken 22147 times.
✗ Branch 21 → 101 not taken.
|
22147 | 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 22147 times.
|
22147 | assert(typeMapping.empty()); |
| 58 |
1/2✓ Branch 25 → 26 taken 22147 times.
✗ Branch 25 → 101 not taken.
|
22147 | typeMapping = manifestation->typeMapping; |
| 59 | |||
| 60 | // Set return type to the result variable | ||
| 61 |
1/2✓ Branch 28 → 29 taken 22147 times.
✗ Branch 28 → 89 not taken.
|
66441 | SymbolTableEntry *resultVarEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME); |
| 62 |
1/2✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 22147 times.
|
22147 | assert(resultVarEntry != nullptr); |
| 63 |
1/2✓ Branch 36 → 37 taken 22147 times.
✗ Branch 36 → 101 not taken.
|
22147 | resultVarEntry->updateType(manifestation->returnType, false); |
| 64 | 22147 | 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 15439 times.
✓ Branch 37 → 64 taken 6708 times.
|
22147 | if (node->hasParams) { |
| 69 |
1/2✓ Branch 38 → 39 taken 15439 times.
✗ Branch 38 → 93 not taken.
|
15439 | 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 22641 times.
✓ Branch 63 → 64 taken 15439 times.
|
38080 | for (size_t i = 0; i < manifestation->paramList.size(); i++) { |
| 73 |
1/2✓ Branch 41 → 42 taken 22641 times.
✗ Branch 41 → 99 not taken.
|
22641 | const DeclStmtNode *param = node->paramLst->params.at(i); |
| 74 |
2/4✓ Branch 42 → 43 taken 22641 times.
✗ Branch 42 → 96 not taken.
✓ Branch 43 → 44 taken 22641 times.
✗ Branch 43 → 94 not taken.
|
22641 | const QualType paramType = manifestation->getParamTypes().at(i); |
| 75 |
8/10✓ Branch 45 → 46 taken 22641 times.
✗ Branch 45 → 97 not taken.
✓ Branch 46 → 47 taken 6 times.
✓ Branch 46 → 50 taken 22635 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 22639 times.
|
22641 | 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 22145 times.
✓ Branch 64 → 100 taken 2 times.
|
22147 | visit(node->body); |
| 85 | |||
| 86 | // Clear type mapping | ||
| 87 | 22145 | typeMapping.clear(); | |
| 88 | |||
| 89 | // Change to root scope | ||
| 90 | 22145 | currentScope = rootScope; | |
| 91 |
1/2✗ Branch 67 → 68 not taken.
✓ Branch 67 → 69 taken 22145 times.
|
22145 | assert(currentScope->type == ScopeType::GLOBAL); |
| 92 | |||
| 93 | // Do not type-check this manifestation again | ||
| 94 | 22145 | manifestation->alreadyTypeChecked = true; | |
| 95 | |||
| 96 | 22145 | manIdx++; // Increase the manifestation index | |
| 97 | } | ||
| 98 | 41729 | manIdx = 0; // Reset the manifestation index | |
| 99 | |||
| 100 |
1/2✓ Branch 80 → 81 taken 41729 times.
✗ Branch 80 → 102 not taken.
|
83458 | return nullptr; |
| 101 | } | ||
| 102 | |||
| 103 | 22544 | std::any TypeChecker::visitProcDefCheck(ProcDefNode *node) { | |
| 104 | 22544 | node->resizeToNumberOfManifestations(node->manifestations.size()); | |
| 105 | 22544 | manIdx = 0; // Reset the manifestation index | |
| 106 | |||
| 107 | // Get all manifestations for this procedure definition | ||
| 108 |
2/2✓ Branch 72 → 6 taken 32387 times.
✓ Branch 72 → 73 taken 22544 times.
|
77475 | for (Function *manifestation : node->manifestations) { |
| 109 | // Skip non-substantiated or already checked procedures | ||
| 110 |
7/8✓ Branch 8 → 9 taken 32387 times.
✗ Branch 8 → 88 not taken.
✓ Branch 9 → 10 taken 21313 times.
✓ Branch 9 → 11 taken 11074 times.
✓ Branch 10 → 11 taken 10166 times.
✓ Branch 10 → 12 taken 11147 times.
✓ Branch 13 → 14 taken 21240 times.
✓ Branch 13 → 15 taken 11147 times.
|
32387 | if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) { |
| 111 | 21240 | manIdx++; // Increase the manifestation index | |
| 112 | 21240 | continue; | |
| 113 | } | ||
| 114 | |||
| 115 | // Change scope to concrete struct specialization scope | ||
| 116 |
2/2✓ Branch 15 → 16 taken 9450 times.
✓ Branch 15 → 21 taken 1697 times.
|
11147 | if (node->isMethod) { |
| 117 |
2/4✓ Branch 16 → 17 taken 9450 times.
✗ Branch 16 → 79 not taken.
✓ Branch 17 → 18 taken 9450 times.
✗ Branch 17 → 79 not taken.
|
9450 | const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes()); |
| 118 |
1/2✓ Branch 18 → 19 taken 9450 times.
✗ Branch 18 → 77 not taken.
|
9450 | changeToScope(scopeName, ScopeType::STRUCT); |
| 119 | 9450 | } | |
| 120 | |||
| 121 | // Change to procedure scope | ||
| 122 |
1/2✓ Branch 21 → 22 taken 11147 times.
✗ Branch 21 → 88 not taken.
|
11147 | 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 11147 times.
|
11147 | assert(typeMapping.empty()); |
| 126 |
1/2✓ Branch 25 → 26 taken 11147 times.
✗ Branch 25 → 88 not taken.
|
11147 | 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 8541 times.
✓ Branch 26 → 53 taken 2606 times.
|
11147 | if (node->hasParams) { |
| 131 |
1/2✓ Branch 27 → 28 taken 8541 times.
✗ Branch 27 → 80 not taken.
|
8541 | 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 12297 times.
✓ Branch 52 → 53 taken 8541 times.
|
20838 | for (size_t i = 0; i < manifestation->paramList.size(); i++) { |
| 135 |
1/2✓ Branch 30 → 31 taken 12297 times.
✗ Branch 30 → 86 not taken.
|
12297 | const DeclStmtNode *param = node->paramLst->params.at(i); |
| 136 |
2/4✓ Branch 31 → 32 taken 12297 times.
✗ Branch 31 → 83 not taken.
✓ Branch 32 → 33 taken 12297 times.
✗ Branch 32 → 81 not taken.
|
12297 | const QualType paramType = manifestation->getParamTypes().at(i); |
| 137 |
8/10✓ Branch 34 → 35 taken 12297 times.
✗ Branch 34 → 84 not taken.
✓ Branch 35 → 36 taken 59 times.
✓ Branch 35 → 39 taken 12238 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 12284 times.
|
12297 | 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 5278 times.
✓ Branch 53 → 55 taken 5869 times.
|
11147 | if (node->isCtor) |
| 147 |
1/2✓ Branch 54 → 55 taken 5278 times.
✗ Branch 54 → 88 not taken.
|
5278 | createCtorBodyPreamble(node->scope); |
| 148 | |||
| 149 | // Visit statements in new scope | ||
| 150 |
1/2✓ Branch 55 → 56 taken 11147 times.
✗ Branch 55 → 87 not taken.
|
11147 | visit(node->body); |
| 151 | |||
| 152 | // Clear type mapping | ||
| 153 | 11147 | typeMapping.clear(); | |
| 154 | |||
| 155 | // Change to root scope | ||
| 156 | 11147 | currentScope = rootScope; | |
| 157 |
2/4✓ Branch 58 → 59 taken 11147 times.
✗ Branch 58 → 61 not taken.
✓ Branch 59 → 60 taken 11147 times.
✗ Branch 59 → 61 not taken.
|
11147 | assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL); |
| 158 | |||
| 159 | // Do not type-check this manifestation again | ||
| 160 | 11147 | manifestation->alreadyTypeChecked = true; | |
| 161 | |||
| 162 | 11147 | manIdx++; // Increase the manifestation index | |
| 163 | } | ||
| 164 | 22544 | manIdx = 0; // Reset the manifestation index | |
| 165 | |||
| 166 |
1/2✓ Branch 73 → 74 taken 22544 times.
✗ Branch 73 → 89 not taken.
|
45088 | return nullptr; |
| 167 | } | ||
| 168 | |||
| 169 | 5283 | std::any TypeChecker::visitStructDefCheck(StructDefNode *node) { | |
| 170 | 5283 | node->resizeToNumberOfManifestations(node->structManifestations.size()); | |
| 171 | 5283 | manIdx = 0; // Reset the manifestation index | |
| 172 | |||
| 173 | // Get all manifestations for this procedure definition | ||
| 174 |
2/2✓ Branch 214 → 6 taken 9231 times.
✓ Branch 214 → 215 taken 5283 times.
|
19797 | for (const Struct *manifestation : node->structManifestations) { |
| 175 | // Skip non-substantiated or already checked procedures | ||
| 176 |
3/4✓ Branch 8 → 9 taken 9231 times.
✗ Branch 8 → 298 not taken.
✓ Branch 9 → 10 taken 1543 times.
✓ Branch 9 → 11 taken 7688 times.
|
9231 | if (!manifestation->isFullySubstantiated()) { |
| 177 | 1543 | manIdx++; // Increase the manifestation index | |
| 178 | 1543 | continue; | |
| 179 | } | ||
| 180 | |||
| 181 | // Change to struct scope | ||
| 182 |
1/2✓ Branch 11 → 12 taken 7688 times.
✗ Branch 11 → 298 not taken.
|
7688 | changeToScope(manifestation->scope, ScopeType::STRUCT); |
| 183 | |||
| 184 | // Mount type mapping for this manifestation, so that the body preamble helpers below can substantiate | ||
| 185 | // generic field types (e.g. `heap T*` on `Vector<T>`). Without this, an auto-generated body preamble that | ||
| 186 | // touches a still-generic field would assert in TypeMatcher::substantiateTypeWithTypeMapping. | ||
| 187 |
1/2✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 7688 times.
|
7688 | assert(typeMapping.empty()); |
| 188 |
1/2✓ Branch 15 → 16 taken 7688 times.
✗ Branch 15 → 298 not taken.
|
7688 | typeMapping = manifestation->typeMapping; |
| 189 | |||
| 190 | // Re-visit all default values. This is required, since the type of the default value might vary for different manifestations | ||
| 191 |
2/2✓ Branch 39 → 18 taken 16031 times.
✓ Branch 39 → 40 taken 7688 times.
|
31407 | for (const FieldNode *field : node->fields) { |
| 192 |
2/2✓ Branch 20 → 21 taken 4020 times.
✓ Branch 20 → 30 taken 12011 times.
|
16031 | if (field->defaultValue != nullptr) { |
| 193 |
1/2✓ Branch 21 → 22 taken 4020 times.
✗ Branch 21 → 219 not taken.
|
4020 | visit(field->defaultValue); |
| 194 |
1/2✓ Branch 23 → 24 taken 4020 times.
✗ Branch 23 → 221 not taken.
|
4020 | SymbolTableEntry *fieldEntry = manifestation->scope->lookupStrict(field->fieldName); |
| 195 |
1/2✗ Branch 26 → 27 not taken.
✓ Branch 26 → 28 taken 4020 times.
|
4020 | assert(fieldEntry != nullptr); |
| 196 |
1/2✓ Branch 28 → 29 taken 4020 times.
✗ Branch 28 → 220 not taken.
|
4020 | fieldEntry->updateState(INITIALIZED, field); |
| 197 | } | ||
| 198 | } | ||
| 199 | |||
| 200 | // Build struct type | ||
| 201 |
1/2✓ Branch 40 → 41 taken 7688 times.
✗ Branch 40 → 298 not taken.
|
7688 | const QualType structType = manifestation->entry->getQualType(); |
| 202 | |||
| 203 | // Check if the struct implements all methods of all attached interfaces | ||
| 204 | 7688 | size_t vtableIndex = 0; | |
| 205 |
2/2✓ Branch 145 → 43 taken 2464 times.
✓ Branch 145 → 146 taken 7688 times.
|
17840 | for (const QualType &interfaceType : manifestation->interfaceTypes) { |
| 206 |
1/2✓ Branch 45 → 46 taken 2464 times.
✗ Branch 45 → 265 not taken.
|
2464 | const Interface *interface = interfaceType.getInterface(node); |
| 207 |
1/2✗ Branch 46 → 47 not taken.
✓ Branch 46 → 48 taken 2464 times.
|
2464 | assert(interface != nullptr); |
| 208 | |||
| 209 | // Check for all methods, that it is implemented by the struct | ||
| 210 |
2/2✓ Branch 135 → 50 taken 7016 times.
✓ Branch 135 → 136 taken 2464 times.
|
11944 | for (const Function *expMethod : interface->methods) { |
| 211 |
1/2✓ Branch 52 → 53 taken 7016 times.
✗ Branch 52 → 263 not taken.
|
7016 | const std::string methodName = expMethod->name; |
| 212 |
1/2✓ Branch 53 → 54 taken 7016 times.
✗ Branch 53 → 261 not taken.
|
7016 | QualTypeList params = expMethod->getParamTypes(); |
| 213 | 7016 | QualType returnType = expMethod->returnType; | |
| 214 | |||
| 215 | // Substantiate param and return types | ||
| 216 |
1/2✓ Branch 54 → 55 taken 7016 times.
✗ Branch 54 → 259 not taken.
|
7016 | TypeMatcher::substantiateTypesWithTypeMapping(params, interface->typeMapping, node); |
| 217 |
3/4✓ Branch 55 → 56 taken 7016 times.
✗ Branch 55 → 259 not taken.
✓ Branch 56 → 57 taken 3532 times.
✓ Branch 56 → 58 taken 3484 times.
|
7016 | if (returnType.hasAnyGenericParts()) |
| 218 |
1/2✓ Branch 57 → 58 taken 3532 times.
✗ Branch 57 → 259 not taken.
|
3532 | TypeMatcher::substantiateTypeWithTypeMapping(returnType, interface->typeMapping, node); |
| 219 | |||
| 220 | // Build args list | ||
| 221 | 7016 | ArgList args; | |
| 222 |
1/2✓ Branch 59 → 60 taken 7016 times.
✗ Branch 59 → 257 not taken.
|
7016 | args.reserve(params.size()); |
| 223 |
2/2✓ Branch 74 → 62 taken 916 times.
✓ Branch 74 → 75 taken 7016 times.
|
14948 | for (const QualType ¶m : params) |
| 224 |
1/2✓ Branch 64 → 65 taken 916 times.
✗ Branch 64 → 222 not taken.
|
916 | args.emplace_back(param, nullptr); |
| 225 | |||
| 226 | // Search for method that has the required signature | ||
| 227 |
1/2✓ Branch 76 → 77 taken 7016 times.
✗ Branch 76 → 224 not taken.
|
7016 | Function *spiceFunction = FunctionManager::match(currentScope, methodName, structType, args, {}, true, node); |
| 228 |
2/2✓ Branch 78 → 79 taken 4 times.
✓ Branch 78 → 91 taken 7012 times.
|
7016 | if (spiceFunction == nullptr) { |
| 229 |
1/2✓ Branch 84 → 85 taken 4 times.
✗ Branch 84 → 227 not taken.
|
4 | softError(node, INTERFACE_METHOD_NOT_IMPLEMENTED, |
| 230 |
5/10✓ Branch 79 → 80 taken 4 times.
✗ Branch 79 → 239 not taken.
✓ Branch 80 → 81 taken 4 times.
✗ Branch 80 → 235 not taken.
✓ Branch 81 → 82 taken 4 times.
✗ Branch 81 → 233 not taken.
✓ Branch 82 → 83 taken 4 times.
✗ Branch 82 → 231 not taken.
✓ Branch 83 → 84 taken 4 times.
✗ Branch 83 → 229 not taken.
|
8 | "The struct '" + node->structName + "' does not implement method '" + expMethod->getSignature() + "'."); |
| 231 | 4 | continue; | |
| 232 | } | ||
| 233 | |||
| 234 | // Check return type | ||
| 235 |
5/6✓ Branch 91 → 92 taken 7012 times.
✗ Branch 91 → 257 not taken.
✓ Branch 92 → 93 taken 1158 times.
✓ Branch 92 → 96 taken 5854 times.
✓ Branch 97 → 98 taken 2 times.
✓ Branch 97 → 110 taken 7010 times.
|
8170 | if (spiceFunction->returnType != returnType && |
| 236 |
3/4✓ Branch 93 → 94 taken 1158 times.
✗ Branch 93 → 257 not taken.
✓ Branch 94 → 95 taken 2 times.
✓ Branch 94 → 96 taken 1156 times.
|
1158 | !returnType.matchesInterfaceImplementedByStruct(spiceFunction->returnType)) { |
| 237 |
1/2✓ Branch 103 → 104 taken 2 times.
✗ Branch 103 → 242 not taken.
|
2 | softError(node, INTERFACE_METHOD_NOT_IMPLEMENTED, |
| 238 |
4/8✓ Branch 98 → 99 taken 2 times.
✗ Branch 98 → 254 not taken.
✓ Branch 99 → 100 taken 2 times.
✗ Branch 99 → 250 not taken.
✓ Branch 100 → 101 taken 2 times.
✗ Branch 100 → 248 not taken.
✓ Branch 101 → 102 taken 2 times.
✗ Branch 101 → 246 not taken.
|
4 | "The struct '" + node->structName + "' does not implement method '" + expMethod->getSignature() + |
| 239 |
1/2✓ Branch 102 → 103 taken 2 times.
✗ Branch 102 → 244 not taken.
|
2 | "'. The return type does not match."); |
| 240 | 2 | continue; | |
| 241 | } | ||
| 242 | // Set to virtual, since it overrides the interface method | ||
| 243 | 7010 | spiceFunction->isVirtual = true; | |
| 244 | 7010 | spiceFunction->vtableIndex = vtableIndex++; | |
| 245 |
6/6✓ Branch 112 → 113 taken 7010 times.
✓ Branch 112 → 114 taken 6 times.
✓ Branch 117 → 118 taken 7010 times.
✓ Branch 117 → 119 taken 6 times.
✓ Branch 122 → 123 taken 7010 times.
✓ Branch 122 → 125 taken 6 times.
|
21048 | } |
| 246 | } | ||
| 247 | |||
| 248 | // Check default ctor body if required | ||
| 249 |
2/4✓ Branch 149 → 150 taken 7688 times.
✗ Branch 149 → 268 not taken.
✓ Branch 150 → 151 taken 7688 times.
✗ Branch 150 → 266 not taken.
|
23064 | const Function *ctorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, {}, true); |
| 250 |
4/4✓ Branch 154 → 155 taken 1885 times.
✓ Branch 154 → 160 taken 5803 times.
✓ Branch 155 → 156 taken 325 times.
✓ Branch 155 → 160 taken 1560 times.
|
7688 | if (ctorFunc != nullptr && ctorFunc->implicitDefault) { |
| 251 |
1/2✓ Branch 156 → 157 taken 325 times.
✗ Branch 156 → 298 not taken.
|
325 | createCtorBodyPreamble(ctorFunc->bodyScope); |
| 252 |
2/4✓ Branch 157 → 158 taken 325 times.
✗ Branch 157 → 298 not taken.
✗ Branch 158 → 159 not taken.
✓ Branch 158 → 160 taken 325 times.
|
325 | assert(manifestation->areAllFieldsInitialized() == nullptr); |
| 253 | } | ||
| 254 | |||
| 255 | // Check default copy ctor body if required | ||
| 256 |
2/4✓ Branch 160 → 161 taken 7688 times.
✗ Branch 160 → 279 not taken.
✓ Branch 164 → 165 taken 7688 times.
✗ Branch 164 → 275 not taken.
|
23064 | const ArgList args = {{structType.toConstRef(node), false /* always non-temporary */}}; |
| 257 |
2/4✓ Branch 168 → 169 taken 7688 times.
✗ Branch 168 → 283 not taken.
✓ Branch 169 → 170 taken 7688 times.
✗ Branch 169 → 281 not taken.
|
7688 | const Function *copyCtorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, args, true); |
| 258 |
4/4✓ Branch 172 → 173 taken 3773 times.
✓ Branch 172 → 178 taken 3915 times.
✓ Branch 173 → 174 taken 2790 times.
✓ Branch 173 → 178 taken 983 times.
|
7688 | if (copyCtorFunc != nullptr && copyCtorFunc->implicitDefault) { |
| 259 |
1/2✓ Branch 174 → 175 taken 2790 times.
✗ Branch 174 → 296 not taken.
|
2790 | createCopyCtorBodyPreamble(copyCtorFunc->bodyScope); |
| 260 |
2/4✓ Branch 175 → 176 taken 2790 times.
✗ Branch 175 → 296 not taken.
✗ Branch 176 → 177 not taken.
✓ Branch 176 → 178 taken 2790 times.
|
2790 | assert(manifestation->areAllFieldsInitialized() == nullptr); |
| 261 | } | ||
| 262 | |||
| 263 | // Check default move ctor body if required. findMoveCtor scans the manifestations directly to avoid the | ||
| 264 | // constify-based false-positive that FunctionManager::lookup with a non-const ref arg can produce. | ||
| 265 |
5/6✓ Branch 178 → 179 taken 7688 times.
✗ Branch 178 → 296 not taken.
✓ Branch 179 → 180 taken 22 times.
✓ Branch 179 → 185 taken 7666 times.
✓ Branch 180 → 181 taken 17 times.
✓ Branch 180 → 185 taken 5 times.
|
7688 | if (const Function *moveCtorFunc = FunctionManager::findMoveCtor(currentScope); moveCtorFunc && moveCtorFunc->implicitDefault) { |
| 266 |
1/2✓ Branch 181 → 182 taken 17 times.
✗ Branch 181 → 296 not taken.
|
17 | createMoveCtorBodyPreamble(moveCtorFunc->bodyScope); |
| 267 |
2/4✓ Branch 182 → 183 taken 17 times.
✗ Branch 182 → 296 not taken.
✗ Branch 183 → 184 not taken.
✓ Branch 183 → 185 taken 17 times.
|
17 | assert(manifestation->areAllFieldsInitialized() == nullptr); |
| 268 | } | ||
| 269 | |||
| 270 | // Check default dtor body if required | ||
| 271 |
2/4✓ Branch 188 → 189 taken 7688 times.
✗ Branch 188 → 289 not taken.
✓ Branch 189 → 190 taken 7688 times.
✗ Branch 189 → 287 not taken.
|
23064 | const Function *dtorFunc = FunctionManager::lookup(currentScope, DTOR_FUNCTION_NAME, structType, {}, true); |
| 272 |
4/4✓ Branch 193 → 194 taken 4088 times.
✓ Branch 193 → 196 taken 3600 times.
✓ Branch 194 → 195 taken 3315 times.
✓ Branch 194 → 196 taken 773 times.
|
7688 | if (dtorFunc != nullptr && dtorFunc->implicitDefault) |
| 273 |
1/2✓ Branch 195 → 196 taken 3315 times.
✗ Branch 195 → 296 not taken.
|
3315 | createDtorBodyPreamble(dtorFunc->bodyScope); |
| 274 | |||
| 275 | // Reset field symbols to declared state for the next manifestation | ||
| 276 |
1/2✓ Branch 196 → 197 taken 7688 times.
✗ Branch 196 → 296 not taken.
|
7688 | manifestation->resetFieldSymbolsToDeclared(node); |
| 277 | |||
| 278 | // Clear type mapping | ||
| 279 | 7688 | typeMapping.clear(); | |
| 280 | |||
| 281 | // Return to the root scope | ||
| 282 | 7688 | currentScope = rootScope; | |
| 283 |
2/4✓ Branch 198 → 199 taken 7688 times.
✗ Branch 198 → 201 not taken.
✓ Branch 199 → 200 taken 7688 times.
✗ Branch 199 → 201 not taken.
|
7688 | assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL); |
| 284 | |||
| 285 | 7688 | manIdx++; // Increase the manifestation index | |
| 286 | 7688 | } | |
| 287 | 5283 | manIdx = 0; // Reset the manifestation index | |
| 288 | |||
| 289 |
1/2✓ Branch 215 → 216 taken 5283 times.
✗ Branch 215 → 300 not taken.
|
10566 | return nullptr; |
| 290 | } | ||
| 291 | |||
| 292 | } // namespace spice::compiler | ||
| 293 |