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 | 556 | 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 491 times.
|
556 | if (typeCheckedMainFct) |
| 19 |
1/2✓ Branch 3 → 4 taken 65 times.
✗ Branch 3 → 13 not taken.
|
130 | return nullptr; |
| 20 | |||
| 21 | 491 | node->resizeToNumberOfManifestations(1); | |
| 22 | |||
| 23 | // Change to function body scope | ||
| 24 | 491 | currentScope = node->bodyScope; | |
| 25 | // Visit statements in new scope | ||
| 26 |
2/2✓ Branch 7 → 8 taken 461 times.
✓ Branch 7 → 14 taken 30 times.
|
491 | visit(node->body); |
| 27 | // Leave main function body scope | ||
| 28 | 461 | currentScope = rootScope; | |
| 29 | |||
| 30 | // Set to type-checked | ||
| 31 | 461 | typeCheckedMainFct = true; | |
| 32 |
1/2✓ Branch 9 → 10 taken 461 times.
✗ Branch 9 → 15 not taken.
|
922 | return nullptr; |
| 33 | } | ||
| 34 | |||
| 35 | 38588 | std::any TypeChecker::visitFctDefCheck(FctDefNode *node) { | |
| 36 | 38588 | node->resizeToNumberOfManifestations(node->manifestations.size()); | |
| 37 | 38588 | manIdx = 0; // Reset the manifestation index | |
| 38 | |||
| 39 | // Get all manifestations for this function definition | ||
| 40 |
2/2✓ Branch 56 → 6 taken 53708 times.
✓ Branch 56 → 57 taken 38586 times.
|
130882 | for (Function *manifestation : node->manifestations) { |
| 41 | // Skip non-substantiated or already checked functions | ||
| 42 |
7/8✓ Branch 8 → 9 taken 53708 times.
✗ Branch 8 → 72 not taken.
✓ Branch 9 → 10 taken 43147 times.
✓ Branch 9 → 11 taken 10561 times.
✓ Branch 10 → 11 taken 22606 times.
✓ Branch 10 → 12 taken 20541 times.
✓ Branch 13 → 14 taken 33167 times.
✓ Branch 13 → 15 taken 20541 times.
|
53708 | if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) { |
| 43 | 33167 | manIdx++; // Increase the manifestation index | |
| 44 | 33167 | continue; | |
| 45 | } | ||
| 46 | |||
| 47 | // Change scope to concrete struct specialization scope | ||
| 48 |
2/2✓ Branch 15 → 16 taken 11743 times.
✓ Branch 15 → 21 taken 8798 times.
|
20541 | if (node->isMethod) { |
| 49 |
2/4✓ Branch 16 → 17 taken 11743 times.
✗ Branch 16 → 63 not taken.
✓ Branch 17 → 18 taken 11743 times.
✗ Branch 17 → 63 not taken.
|
11743 | const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes()); |
| 50 |
1/2✓ Branch 18 → 19 taken 11743 times.
✗ Branch 18 → 61 not taken.
|
11743 | changeToScope(scopeName, ScopeType::STRUCT); |
| 51 | 11743 | } | |
| 52 | |||
| 53 | // Change to function scope | ||
| 54 |
1/2✓ Branch 21 → 22 taken 20541 times.
✗ Branch 21 → 72 not taken.
|
20541 | 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 20541 times.
|
20541 | assert(typeMapping.empty()); |
| 58 |
1/2✓ Branch 25 → 26 taken 20541 times.
✗ Branch 25 → 72 not taken.
|
20541 | typeMapping = manifestation->typeMapping; |
| 59 | |||
| 60 | // Set return type to the result variable | ||
| 61 |
1/2✓ Branch 28 → 29 taken 20541 times.
✗ Branch 28 → 66 not taken.
|
61623 | SymbolTableEntry *resultVarEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME); |
| 62 |
1/2✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 20541 times.
|
20541 | assert(resultVarEntry != nullptr); |
| 63 |
1/2✓ Branch 36 → 37 taken 20541 times.
✗ Branch 36 → 72 not taken.
|
20541 | resultVarEntry->updateType(manifestation->returnType, false); |
| 64 | 20541 | 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 13973 times.
✓ Branch 37 → 41 taken 6568 times.
|
20541 | if (node->hasParams) |
| 69 |
1/2✓ Branch 38 → 39 taken 13973 times.
✗ Branch 38 → 70 not taken.
|
13973 | visit(node->paramLst); |
| 70 | |||
| 71 | // Visit statements in new scope | ||
| 72 |
2/2✓ Branch 41 → 42 taken 20539 times.
✓ Branch 41 → 71 taken 2 times.
|
20541 | visit(node->body); |
| 73 | |||
| 74 | // Clear type mapping | ||
| 75 | 20539 | typeMapping.clear(); | |
| 76 | |||
| 77 | // Change to root scope | ||
| 78 | 20539 | currentScope = rootScope; | |
| 79 |
1/2✗ Branch 44 → 45 not taken.
✓ Branch 44 → 46 taken 20539 times.
|
20539 | assert(currentScope->type == ScopeType::GLOBAL); |
| 80 | |||
| 81 | // Do not type-check this manifestation again | ||
| 82 | 20539 | manifestation->alreadyTypeChecked = true; | |
| 83 | |||
| 84 | 20539 | manIdx++; // Increase the manifestation index | |
| 85 | } | ||
| 86 | 38586 | manIdx = 0; // Reset the manifestation index | |
| 87 | |||
| 88 |
1/2✓ Branch 57 → 58 taken 38586 times.
✗ Branch 57 → 73 not taken.
|
77172 | return nullptr; |
| 89 | } | ||
| 90 | |||
| 91 | 21965 | std::any TypeChecker::visitProcDefCheck(ProcDefNode *node) { | |
| 92 | 21965 | node->resizeToNumberOfManifestations(node->manifestations.size()); | |
| 93 | 21965 | manIdx = 0; // Reset the manifestation index | |
| 94 | |||
| 95 | // Get all manifestations for this procedure definition | ||
| 96 |
2/2✓ Branch 49 → 6 taken 31772 times.
✓ Branch 49 → 50 taken 21965 times.
|
75702 | for (Function *manifestation : node->manifestations) { |
| 97 | // Skip non-substantiated or already checked procedures | ||
| 98 |
7/8✓ Branch 8 → 9 taken 31772 times.
✗ Branch 8 → 59 not taken.
✓ Branch 9 → 10 taken 20814 times.
✓ Branch 9 → 11 taken 10958 times.
✓ Branch 10 → 11 taken 9884 times.
✓ Branch 10 → 12 taken 10930 times.
✓ Branch 13 → 14 taken 20842 times.
✓ Branch 13 → 15 taken 10930 times.
|
31772 | if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) { |
| 99 | 20842 | manIdx++; // Increase the manifestation index | |
| 100 | 20842 | continue; | |
| 101 | } | ||
| 102 | |||
| 103 | // Change scope to concrete struct specialization scope | ||
| 104 |
2/2✓ Branch 15 → 16 taken 9242 times.
✓ Branch 15 → 21 taken 1688 times.
|
10930 | if (node->isMethod) { |
| 105 |
2/4✓ Branch 16 → 17 taken 9242 times.
✗ Branch 16 → 56 not taken.
✓ Branch 17 → 18 taken 9242 times.
✗ Branch 17 → 56 not taken.
|
9242 | const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes()); |
| 106 |
1/2✓ Branch 18 → 19 taken 9242 times.
✗ Branch 18 → 54 not taken.
|
9242 | changeToScope(scopeName, ScopeType::STRUCT); |
| 107 | 9242 | } | |
| 108 | |||
| 109 | // Change to procedure scope | ||
| 110 |
1/2✓ Branch 21 → 22 taken 10930 times.
✗ Branch 21 → 59 not taken.
|
10930 | changeToScope(manifestation->bodyScope, ScopeType::FUNC_PROC_BODY); |
| 111 | |||
| 112 | // Mount type mapping for this manifestation | ||
| 113 |
1/2✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 10930 times.
|
10930 | assert(typeMapping.empty()); |
| 114 |
1/2✓ Branch 25 → 26 taken 10930 times.
✗ Branch 25 → 59 not taken.
|
10930 | typeMapping = manifestation->typeMapping; |
| 115 | |||
| 116 | // Visit parameters | ||
| 117 | // This happens once in the type checker prepare stage. This second time is only required if we have a generic procedure | ||
| 118 |
2/2✓ Branch 26 → 27 taken 8386 times.
✓ Branch 26 → 30 taken 2544 times.
|
10930 | if (node->hasParams) |
| 119 |
1/2✓ Branch 27 → 28 taken 8386 times.
✗ Branch 27 → 57 not taken.
|
8386 | visit(node->paramLst); |
| 120 | |||
| 121 | // Prepare generation of special ctor preamble to store VTable, default field values, etc. if required | ||
| 122 |
2/2✓ Branch 30 → 31 taken 5128 times.
✓ Branch 30 → 32 taken 5802 times.
|
10930 | if (node->isCtor) |
| 123 |
1/2✓ Branch 31 → 32 taken 5128 times.
✗ Branch 31 → 59 not taken.
|
5128 | createCtorBodyPreamble(node->scope); |
| 124 | |||
| 125 | // Visit statements in new scope | ||
| 126 |
1/2✓ Branch 32 → 33 taken 10930 times.
✗ Branch 32 → 58 not taken.
|
10930 | visit(node->body); |
| 127 | |||
| 128 | // Clear type mapping | ||
| 129 | 10930 | typeMapping.clear(); | |
| 130 | |||
| 131 | // Change to root scope | ||
| 132 | 10930 | currentScope = rootScope; | |
| 133 |
2/4✓ Branch 35 → 36 taken 10930 times.
✗ Branch 35 → 38 not taken.
✓ Branch 36 → 37 taken 10930 times.
✗ Branch 36 → 38 not taken.
|
10930 | assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL); |
| 134 | |||
| 135 | // Do not type-check this manifestation again | ||
| 136 | 10930 | manifestation->alreadyTypeChecked = true; | |
| 137 | |||
| 138 | 10930 | manIdx++; // Increase the manifestation index | |
| 139 | } | ||
| 140 | 21965 | manIdx = 0; // Reset the manifestation index | |
| 141 | |||
| 142 |
1/2✓ Branch 50 → 51 taken 21965 times.
✗ Branch 50 → 60 not taken.
|
43930 | return nullptr; |
| 143 | } | ||
| 144 | |||
| 145 | 5058 | std::any TypeChecker::visitStructDefCheck(StructDefNode *node) { | |
| 146 | 5058 | node->resizeToNumberOfManifestations(node->structManifestations.size()); | |
| 147 | 5058 | manIdx = 0; // Reset the manifestation index | |
| 148 | |||
| 149 | // Get all manifestations for this procedure definition | ||
| 150 |
2/2✓ Branch 214 → 6 taken 8980 times.
✓ Branch 214 → 215 taken 5058 times.
|
19096 | for (const Struct *manifestation : node->structManifestations) { |
| 151 | // Skip non-substantiated or already checked procedures | ||
| 152 |
3/4✓ Branch 8 → 9 taken 8980 times.
✗ Branch 8 → 298 not taken.
✓ Branch 9 → 10 taken 1546 times.
✓ Branch 9 → 11 taken 7434 times.
|
8980 | if (!manifestation->isFullySubstantiated()) { |
| 153 | 1546 | manIdx++; // Increase the manifestation index | |
| 154 | 1546 | continue; | |
| 155 | } | ||
| 156 | |||
| 157 | // Change to struct scope | ||
| 158 |
1/2✓ Branch 11 → 12 taken 7434 times.
✗ Branch 11 → 298 not taken.
|
7434 | changeToScope(manifestation->scope, ScopeType::STRUCT); |
| 159 | |||
| 160 | // Mount type mapping for this manifestation, so that the body preamble helpers below can substantiate | ||
| 161 | // generic field types (e.g. `heap T*` on `Vector<T>`). Without this, an auto-generated body preamble that | ||
| 162 | // touches a still-generic field would assert in TypeMatcher::substantiateTypeWithTypeMapping. | ||
| 163 |
1/2✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 7434 times.
|
7434 | assert(typeMapping.empty()); |
| 164 |
1/2✓ Branch 15 → 16 taken 7434 times.
✗ Branch 15 → 298 not taken.
|
7434 | typeMapping = manifestation->typeMapping; |
| 165 | |||
| 166 | // Re-visit all default values. This is required, since the type of the default value might vary for different manifestations | ||
| 167 |
2/2✓ Branch 39 → 18 taken 15569 times.
✓ Branch 39 → 40 taken 7434 times.
|
30437 | for (const FieldNode *field : node->fields) { |
| 168 |
2/2✓ Branch 20 → 21 taken 3850 times.
✓ Branch 20 → 30 taken 11719 times.
|
15569 | if (field->defaultValue != nullptr) { |
| 169 |
1/2✓ Branch 21 → 22 taken 3850 times.
✗ Branch 21 → 219 not taken.
|
3850 | visit(field->defaultValue); |
| 170 |
1/2✓ Branch 23 → 24 taken 3850 times.
✗ Branch 23 → 221 not taken.
|
3850 | SymbolTableEntry *fieldEntry = manifestation->scope->lookupStrict(field->fieldName); |
| 171 |
1/2✗ Branch 26 → 27 not taken.
✓ Branch 26 → 28 taken 3850 times.
|
3850 | assert(fieldEntry != nullptr); |
| 172 |
1/2✓ Branch 28 → 29 taken 3850 times.
✗ Branch 28 → 220 not taken.
|
3850 | fieldEntry->updateState(INITIALIZED, field); |
| 173 | } | ||
| 174 | } | ||
| 175 | |||
| 176 | // Build struct type | ||
| 177 |
1/2✓ Branch 40 → 41 taken 7434 times.
✗ Branch 40 → 298 not taken.
|
7434 | const QualType structType = manifestation->entry->getQualType(); |
| 178 | |||
| 179 | // Check if the struct implements all methods of all attached interfaces | ||
| 180 | 7434 | size_t vtableIndex = 0; | |
| 181 |
2/2✓ Branch 145 → 43 taken 2430 times.
✓ Branch 145 → 146 taken 7434 times.
|
17298 | for (const QualType &interfaceType : manifestation->interfaceTypes) { |
| 182 |
1/2✓ Branch 45 → 46 taken 2430 times.
✗ Branch 45 → 265 not taken.
|
2430 | const Interface *interface = interfaceType.getInterface(node); |
| 183 |
1/2✗ Branch 46 → 47 not taken.
✓ Branch 46 → 48 taken 2430 times.
|
2430 | assert(interface != nullptr); |
| 184 | |||
| 185 | // Check for all methods, that it is implemented by the struct | ||
| 186 |
2/2✓ Branch 135 → 50 taken 6784 times.
✓ Branch 135 → 136 taken 2430 times.
|
11644 | for (const Function *expMethod : interface->methods) { |
| 187 |
1/2✓ Branch 52 → 53 taken 6784 times.
✗ Branch 52 → 263 not taken.
|
6784 | const std::string methodName = expMethod->name; |
| 188 |
1/2✓ Branch 53 → 54 taken 6784 times.
✗ Branch 53 → 261 not taken.
|
6784 | QualTypeList params = expMethod->getParamTypes(); |
| 189 | 6784 | QualType returnType = expMethod->returnType; | |
| 190 | |||
| 191 | // Substantiate param and return types | ||
| 192 |
1/2✓ Branch 54 → 55 taken 6784 times.
✗ Branch 54 → 259 not taken.
|
6784 | TypeMatcher::substantiateTypesWithTypeMapping(params, interface->typeMapping, node); |
| 193 |
3/4✓ Branch 55 → 56 taken 6784 times.
✗ Branch 55 → 259 not taken.
✓ Branch 56 → 57 taken 3490 times.
✓ Branch 56 → 58 taken 3294 times.
|
6784 | if (returnType.hasAnyGenericParts()) |
| 194 |
1/2✓ Branch 57 → 58 taken 3490 times.
✗ Branch 57 → 259 not taken.
|
3490 | TypeMatcher::substantiateTypeWithTypeMapping(returnType, interface->typeMapping, node); |
| 195 | |||
| 196 | // Build args list | ||
| 197 | 6784 | ArgList args; | |
| 198 |
1/2✓ Branch 59 → 60 taken 6784 times.
✗ Branch 59 → 257 not taken.
|
6784 | args.reserve(params.size()); |
| 199 |
2/2✓ Branch 74 → 62 taken 758 times.
✓ Branch 74 → 75 taken 6784 times.
|
14326 | for (const QualType ¶m : params) |
| 200 |
1/2✓ Branch 64 → 65 taken 758 times.
✗ Branch 64 → 222 not taken.
|
758 | args.emplace_back(param, nullptr); |
| 201 | |||
| 202 | // Search for method that has the required signature | ||
| 203 |
1/2✓ Branch 76 → 77 taken 6784 times.
✗ Branch 76 → 224 not taken.
|
6784 | Function *spiceFunction = FunctionManager::match(currentScope, methodName, structType, args, {}, true, node); |
| 204 |
2/2✓ Branch 78 → 79 taken 4 times.
✓ Branch 78 → 91 taken 6780 times.
|
6784 | if (spiceFunction == nullptr) { |
| 205 |
1/2✓ Branch 84 → 85 taken 4 times.
✗ Branch 84 → 227 not taken.
|
4 | softError(node, INTERFACE_METHOD_NOT_IMPLEMENTED, |
| 206 |
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() + "'."); |
| 207 | 4 | continue; | |
| 208 | } | ||
| 209 | |||
| 210 | // Check return type | ||
| 211 |
5/6✓ Branch 91 → 92 taken 6780 times.
✗ Branch 91 → 257 not taken.
✓ Branch 92 → 93 taken 1144 times.
✓ Branch 92 → 96 taken 5636 times.
✓ Branch 97 → 98 taken 2 times.
✓ Branch 97 → 110 taken 6778 times.
|
7924 | if (spiceFunction->returnType != returnType && |
| 212 |
3/4✓ Branch 93 → 94 taken 1144 times.
✗ Branch 93 → 257 not taken.
✓ Branch 94 → 95 taken 2 times.
✓ Branch 94 → 96 taken 1142 times.
|
1144 | !returnType.matchesInterfaceImplementedByStruct(spiceFunction->returnType)) { |
| 213 |
1/2✓ Branch 103 → 104 taken 2 times.
✗ Branch 103 → 242 not taken.
|
2 | softError(node, INTERFACE_METHOD_NOT_IMPLEMENTED, |
| 214 |
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() + |
| 215 |
1/2✓ Branch 102 → 103 taken 2 times.
✗ Branch 102 → 244 not taken.
|
2 | "'. The return type does not match."); |
| 216 | 2 | continue; | |
| 217 | } | ||
| 218 | // Set to virtual, since it overrides the interface method | ||
| 219 | 6778 | spiceFunction->isVirtual = true; | |
| 220 | 6778 | spiceFunction->vtableIndex = vtableIndex++; | |
| 221 |
6/6✓ Branch 112 → 113 taken 6778 times.
✓ Branch 112 → 114 taken 6 times.
✓ Branch 117 → 118 taken 6778 times.
✓ Branch 117 → 119 taken 6 times.
✓ Branch 122 → 123 taken 6778 times.
✓ Branch 122 → 125 taken 6 times.
|
20352 | } |
| 222 | } | ||
| 223 | |||
| 224 | // Check default ctor body if required | ||
| 225 |
2/4✓ Branch 149 → 150 taken 7434 times.
✗ Branch 149 → 268 not taken.
✓ Branch 150 → 151 taken 7434 times.
✗ Branch 150 → 266 not taken.
|
22302 | const Function *ctorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, {}, true); |
| 226 |
4/4✓ Branch 154 → 155 taken 1846 times.
✓ Branch 154 → 160 taken 5588 times.
✓ Branch 155 → 156 taken 318 times.
✓ Branch 155 → 160 taken 1528 times.
|
7434 | if (ctorFunc != nullptr && ctorFunc->implicitDefault) { |
| 227 |
1/2✓ Branch 156 → 157 taken 318 times.
✗ Branch 156 → 298 not taken.
|
318 | createCtorBodyPreamble(ctorFunc->bodyScope); |
| 228 |
2/4✓ Branch 157 → 158 taken 318 times.
✗ Branch 157 → 298 not taken.
✗ Branch 158 → 159 not taken.
✓ Branch 158 → 160 taken 318 times.
|
318 | assert(manifestation->areAllFieldsInitialized() == nullptr); |
| 229 | } | ||
| 230 | |||
| 231 | // Check default copy ctor body if required | ||
| 232 |
2/4✓ Branch 160 → 161 taken 7434 times.
✗ Branch 160 → 279 not taken.
✓ Branch 164 → 165 taken 7434 times.
✗ Branch 164 → 275 not taken.
|
22302 | const ArgList args = {{structType.toConstRef(node), false /* always non-temporary */}}; |
| 233 |
2/4✓ Branch 168 → 169 taken 7434 times.
✗ Branch 168 → 283 not taken.
✓ Branch 169 → 170 taken 7434 times.
✗ Branch 169 → 281 not taken.
|
7434 | const Function *copyCtorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, args, true); |
| 234 |
4/4✓ Branch 172 → 173 taken 3570 times.
✓ Branch 172 → 178 taken 3864 times.
✓ Branch 173 → 174 taken 2615 times.
✓ Branch 173 → 178 taken 955 times.
|
7434 | if (copyCtorFunc != nullptr && copyCtorFunc->implicitDefault) { |
| 235 |
1/2✓ Branch 174 → 175 taken 2615 times.
✗ Branch 174 → 296 not taken.
|
2615 | createCopyCtorBodyPreamble(copyCtorFunc->bodyScope); |
| 236 |
2/4✓ Branch 175 → 176 taken 2615 times.
✗ Branch 175 → 296 not taken.
✗ Branch 176 → 177 not taken.
✓ Branch 176 → 178 taken 2615 times.
|
2615 | assert(manifestation->areAllFieldsInitialized() == nullptr); |
| 237 | } | ||
| 238 | |||
| 239 | // Check default move ctor body if required. findMoveCtor scans the manifestations directly to avoid the | ||
| 240 | // constify-based false-positive that FunctionManager::lookup with a non-const ref arg can produce. | ||
| 241 |
5/6✓ Branch 178 → 179 taken 7434 times.
✗ Branch 178 → 296 not taken.
✓ Branch 179 → 180 taken 22 times.
✓ Branch 179 → 185 taken 7412 times.
✓ Branch 180 → 181 taken 17 times.
✓ Branch 180 → 185 taken 5 times.
|
7434 | if (const Function *moveCtorFunc = FunctionManager::findMoveCtor(currentScope); moveCtorFunc && moveCtorFunc->implicitDefault) { |
| 242 |
1/2✓ Branch 181 → 182 taken 17 times.
✗ Branch 181 → 296 not taken.
|
17 | createMoveCtorBodyPreamble(moveCtorFunc->bodyScope); |
| 243 |
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); |
| 244 | } | ||
| 245 | |||
| 246 | // Check default dtor body if required | ||
| 247 |
2/4✓ Branch 188 → 189 taken 7434 times.
✗ Branch 188 → 289 not taken.
✓ Branch 189 → 190 taken 7434 times.
✗ Branch 189 → 287 not taken.
|
22302 | const Function *dtorFunc = FunctionManager::lookup(currentScope, DTOR_FUNCTION_NAME, structType, {}, true); |
| 248 |
4/4✓ Branch 193 → 194 taken 3887 times.
✓ Branch 193 → 196 taken 3547 times.
✓ Branch 194 → 195 taken 3158 times.
✓ Branch 194 → 196 taken 729 times.
|
7434 | if (dtorFunc != nullptr && dtorFunc->implicitDefault) |
| 249 |
1/2✓ Branch 195 → 196 taken 3158 times.
✗ Branch 195 → 296 not taken.
|
3158 | createDtorBodyPreamble(dtorFunc->bodyScope); |
| 250 | |||
| 251 | // Reset field symbols to declared state for the next manifestation | ||
| 252 |
1/2✓ Branch 196 → 197 taken 7434 times.
✗ Branch 196 → 296 not taken.
|
7434 | manifestation->resetFieldSymbolsToDeclared(node); |
| 253 | |||
| 254 | // Clear type mapping | ||
| 255 | 7434 | typeMapping.clear(); | |
| 256 | |||
| 257 | // Return to the root scope | ||
| 258 | 7434 | currentScope = rootScope; | |
| 259 |
2/4✓ Branch 198 → 199 taken 7434 times.
✗ Branch 198 → 201 not taken.
✓ Branch 199 → 200 taken 7434 times.
✗ Branch 199 → 201 not taken.
|
7434 | assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL); |
| 260 | |||
| 261 | 7434 | manIdx++; // Increase the manifestation index | |
| 262 | 7434 | } | |
| 263 | 5058 | manIdx = 0; // Reset the manifestation index | |
| 264 | |||
| 265 |
1/2✓ Branch 215 → 216 taken 5058 times.
✗ Branch 215 → 300 not taken.
|
10116 | return nullptr; |
| 266 | } | ||
| 267 | |||
| 268 | } // namespace spice::compiler | ||
| 269 |