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 | 522 | std::any TypeChecker::visitMainFctDefCheck(MainFctDefNode *node) { | |
| 17 | // Skip if already type-checked | ||
| 18 |
2/2✓ Branch 2 → 3 taken 61 times.
✓ Branch 2 → 6 taken 461 times.
|
522 | if (typeCheckedMainFct) |
| 19 |
1/2✓ Branch 3 → 4 taken 61 times.
✗ Branch 3 → 13 not taken.
|
122 | return nullptr; |
| 20 | |||
| 21 | 461 | node->resizeToNumberOfManifestations(1); | |
| 22 | |||
| 23 | // Change to function body scope | ||
| 24 | 461 | currentScope = node->bodyScope; | |
| 25 | // Visit statements in new scope | ||
| 26 |
2/2✓ Branch 7 → 8 taken 431 times.
✓ Branch 7 → 14 taken 30 times.
|
461 | visit(node->body); |
| 27 | // Leave main function body scope | ||
| 28 | 431 | currentScope = rootScope; | |
| 29 | |||
| 30 | // Set to type-checked | ||
| 31 | 431 | typeCheckedMainFct = true; | |
| 32 |
1/2✓ Branch 9 → 10 taken 431 times.
✗ Branch 9 → 15 not taken.
|
862 | return nullptr; |
| 33 | } | ||
| 34 | |||
| 35 | 27996 | std::any TypeChecker::visitFctDefCheck(FctDefNode *node) { | |
| 36 | 27996 | node->resizeToNumberOfManifestations(node->manifestations.size()); | |
| 37 | 27996 | manIdx = 0; // Reset the manifestation index | |
| 38 | |||
| 39 | // Get all manifestations for this function definition | ||
| 40 |
2/2✓ Branch 56 → 6 taken 36472 times.
✓ Branch 56 → 57 taken 27994 times.
|
92462 | for (Function *manifestation : node->manifestations) { |
| 41 | // Skip non-substantiated or already checked functions | ||
| 42 |
7/8✓ Branch 8 → 9 taken 36472 times.
✗ Branch 8 → 72 not taken.
✓ Branch 9 → 10 taken 28448 times.
✓ Branch 9 → 11 taken 8024 times.
✓ Branch 10 → 11 taken 15195 times.
✓ Branch 10 → 12 taken 13253 times.
✓ Branch 13 → 14 taken 23219 times.
✓ Branch 13 → 15 taken 13253 times.
|
36472 | if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) { |
| 43 | 23219 | manIdx++; // Increase the manifestation index | |
| 44 | 23219 | continue; | |
| 45 | } | ||
| 46 | |||
| 47 | // Change scope to concrete struct specialization scope | ||
| 48 |
2/2✓ Branch 15 → 16 taken 6366 times.
✓ Branch 15 → 21 taken 6887 times.
|
13253 | if (node->isMethod) { |
| 49 |
2/4✓ Branch 16 → 17 taken 6366 times.
✗ Branch 16 → 63 not taken.
✓ Branch 17 → 18 taken 6366 times.
✗ Branch 17 → 63 not taken.
|
6366 | const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes()); |
| 50 |
1/2✓ Branch 18 → 19 taken 6366 times.
✗ Branch 18 → 61 not taken.
|
6366 | changeToScope(scopeName, ScopeType::STRUCT); |
| 51 | 6366 | } | |
| 52 | |||
| 53 | // Change to function scope | ||
| 54 |
1/2✓ Branch 21 → 22 taken 13253 times.
✗ Branch 21 → 72 not taken.
|
13253 | 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 13253 times.
|
13253 | assert(typeMapping.empty()); |
| 58 |
1/2✓ Branch 25 → 26 taken 13253 times.
✗ Branch 25 → 72 not taken.
|
13253 | typeMapping = manifestation->typeMapping; |
| 59 | |||
| 60 | // Set return type to the result variable | ||
| 61 |
1/2✓ Branch 28 → 29 taken 13253 times.
✗ Branch 28 → 66 not taken.
|
39759 | SymbolTableEntry *resultVarEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME); |
| 62 |
1/2✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 13253 times.
|
13253 | assert(resultVarEntry != nullptr); |
| 63 |
1/2✓ Branch 36 → 37 taken 13253 times.
✗ Branch 36 → 72 not taken.
|
13253 | resultVarEntry->updateType(manifestation->returnType, false); |
| 64 | 13253 | 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 9856 times.
✓ Branch 37 → 41 taken 3397 times.
|
13253 | if (node->hasParams) |
| 69 |
1/2✓ Branch 38 → 39 taken 9856 times.
✗ Branch 38 → 70 not taken.
|
9856 | visit(node->paramLst); |
| 70 | |||
| 71 | // Visit statements in new scope | ||
| 72 |
2/2✓ Branch 41 → 42 taken 13251 times.
✓ Branch 41 → 71 taken 2 times.
|
13253 | visit(node->body); |
| 73 | |||
| 74 | // Clear type mapping | ||
| 75 | 13251 | typeMapping.clear(); | |
| 76 | |||
| 77 | // Change to root scope | ||
| 78 | 13251 | currentScope = rootScope; | |
| 79 |
1/2✗ Branch 44 → 45 not taken.
✓ Branch 44 → 46 taken 13251 times.
|
13251 | assert(currentScope->type == ScopeType::GLOBAL); |
| 80 | |||
| 81 | // Do not type-check this manifestation again | ||
| 82 | 13251 | manifestation->alreadyTypeChecked = true; | |
| 83 | |||
| 84 | 13251 | manIdx++; // Increase the manifestation index | |
| 85 | } | ||
| 86 | 27994 | manIdx = 0; // Reset the manifestation index | |
| 87 | |||
| 88 |
1/2✓ Branch 57 → 58 taken 27994 times.
✗ Branch 57 → 73 not taken.
|
55988 | return nullptr; |
| 89 | } | ||
| 90 | |||
| 91 | 15232 | std::any TypeChecker::visitProcDefCheck(ProcDefNode *node) { | |
| 92 | 15232 | node->resizeToNumberOfManifestations(node->manifestations.size()); | |
| 93 | 15232 | manIdx = 0; // Reset the manifestation index | |
| 94 | |||
| 95 | // Get all manifestations for this procedure definition | ||
| 96 |
2/2✓ Branch 49 → 6 taken 20839 times.
✓ Branch 49 → 50 taken 15232 times.
|
51303 | for (Function *manifestation : node->manifestations) { |
| 97 | // Skip non-substantiated or already checked procedures | ||
| 98 |
7/8✓ Branch 8 → 9 taken 20839 times.
✗ Branch 8 → 59 not taken.
✓ Branch 9 → 10 taken 12570 times.
✓ Branch 9 → 11 taken 8269 times.
✓ Branch 10 → 11 taken 6016 times.
✓ Branch 10 → 12 taken 6554 times.
✓ Branch 13 → 14 taken 14285 times.
✓ Branch 13 → 15 taken 6554 times.
|
20839 | if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) { |
| 99 | 14285 | manIdx++; // Increase the manifestation index | |
| 100 | 14285 | continue; | |
| 101 | } | ||
| 102 | |||
| 103 | // Change scope to concrete struct specialization scope | ||
| 104 |
2/2✓ Branch 15 → 16 taken 5233 times.
✓ Branch 15 → 21 taken 1321 times.
|
6554 | if (node->isMethod) { |
| 105 |
2/4✓ Branch 16 → 17 taken 5233 times.
✗ Branch 16 → 56 not taken.
✓ Branch 17 → 18 taken 5233 times.
✗ Branch 17 → 56 not taken.
|
5233 | const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes()); |
| 106 |
1/2✓ Branch 18 → 19 taken 5233 times.
✗ Branch 18 → 54 not taken.
|
5233 | changeToScope(scopeName, ScopeType::STRUCT); |
| 107 | 5233 | } | |
| 108 | |||
| 109 | // Change to procedure scope | ||
| 110 |
1/2✓ Branch 21 → 22 taken 6554 times.
✗ Branch 21 → 59 not taken.
|
6554 | 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 6554 times.
|
6554 | assert(typeMapping.empty()); |
| 114 |
1/2✓ Branch 25 → 26 taken 6554 times.
✗ Branch 25 → 59 not taken.
|
6554 | 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 4969 times.
✓ Branch 26 → 30 taken 1585 times.
|
6554 | if (node->hasParams) |
| 119 |
1/2✓ Branch 27 → 28 taken 4969 times.
✗ Branch 27 → 57 not taken.
|
4969 | 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 2708 times.
✓ Branch 30 → 32 taken 3846 times.
|
6554 | if (node->isCtor) |
| 123 |
1/2✓ Branch 31 → 32 taken 2708 times.
✗ Branch 31 → 59 not taken.
|
2708 | createCtorBodyPreamble(node->scope); |
| 124 | |||
| 125 | // Visit statements in new scope | ||
| 126 |
1/2✓ Branch 32 → 33 taken 6554 times.
✗ Branch 32 → 58 not taken.
|
6554 | visit(node->body); |
| 127 | |||
| 128 | // Clear type mapping | ||
| 129 | 6554 | typeMapping.clear(); | |
| 130 | |||
| 131 | // Change to root scope | ||
| 132 | 6554 | currentScope = rootScope; | |
| 133 |
2/4✓ Branch 35 → 36 taken 6554 times.
✗ Branch 35 → 38 not taken.
✓ Branch 36 → 37 taken 6554 times.
✗ Branch 36 → 38 not taken.
|
6554 | assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL); |
| 134 | |||
| 135 | // Do not type-check this manifestation again | ||
| 136 | 6554 | manifestation->alreadyTypeChecked = true; | |
| 137 | |||
| 138 | 6554 | manIdx++; // Increase the manifestation index | |
| 139 | } | ||
| 140 | 15232 | manIdx = 0; // Reset the manifestation index | |
| 141 | |||
| 142 |
1/2✓ Branch 50 → 51 taken 15232 times.
✗ Branch 50 → 60 not taken.
|
30464 | return nullptr; |
| 143 | } | ||
| 144 | |||
| 145 | 2661 | std::any TypeChecker::visitStructDefCheck(StructDefNode *node) { | |
| 146 | 2661 | node->resizeToNumberOfManifestations(node->structManifestations.size()); | |
| 147 | 2661 | manIdx = 0; // Reset the manifestation index | |
| 148 | |||
| 149 | // Get all manifestations for this procedure definition | ||
| 150 |
2/2✓ Branch 214 → 6 taken 4547 times.
✓ Branch 214 → 215 taken 2661 times.
|
9869 | for (const Struct *manifestation : node->structManifestations) { |
| 151 | // Skip non-substantiated or already checked procedures | ||
| 152 |
3/4✓ Branch 8 → 9 taken 4547 times.
✗ Branch 8 → 298 not taken.
✓ Branch 9 → 10 taken 1134 times.
✓ Branch 9 → 11 taken 3413 times.
|
4547 | if (!manifestation->isFullySubstantiated()) { |
| 153 | 1134 | manIdx++; // Increase the manifestation index | |
| 154 | 1134 | continue; | |
| 155 | } | ||
| 156 | |||
| 157 | // Change to struct scope | ||
| 158 |
1/2✓ Branch 11 → 12 taken 3413 times.
✗ Branch 11 → 298 not taken.
|
3413 | 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 3413 times.
|
3413 | assert(typeMapping.empty()); |
| 164 |
1/2✓ Branch 15 → 16 taken 3413 times.
✗ Branch 15 → 298 not taken.
|
3413 | 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 7323 times.
✓ Branch 39 → 40 taken 3413 times.
|
14149 | for (const FieldNode *field : node->fields) { |
| 168 |
2/2✓ Branch 20 → 21 taken 1474 times.
✓ Branch 20 → 30 taken 5849 times.
|
7323 | if (field->defaultValue != nullptr) { |
| 169 |
1/2✓ Branch 21 → 22 taken 1474 times.
✗ Branch 21 → 219 not taken.
|
1474 | visit(field->defaultValue); |
| 170 |
1/2✓ Branch 23 → 24 taken 1474 times.
✗ Branch 23 → 221 not taken.
|
1474 | SymbolTableEntry *fieldEntry = manifestation->scope->lookupStrict(field->fieldName); |
| 171 |
1/2✗ Branch 26 → 27 not taken.
✓ Branch 26 → 28 taken 1474 times.
|
1474 | assert(fieldEntry != nullptr); |
| 172 |
1/2✓ Branch 28 → 29 taken 1474 times.
✗ Branch 28 → 220 not taken.
|
1474 | fieldEntry->updateState(INITIALIZED, field); |
| 173 | } | ||
| 174 | } | ||
| 175 | |||
| 176 | // Build struct type | ||
| 177 |
1/2✓ Branch 40 → 41 taken 3413 times.
✗ Branch 40 → 298 not taken.
|
3413 | const QualType structType = manifestation->entry->getQualType(); |
| 178 | |||
| 179 | // Check if the struct implements all methods of all attached interfaces | ||
| 180 | 3413 | size_t vtableIndex = 0; | |
| 181 |
2/2✓ Branch 145 → 43 taken 1002 times.
✓ Branch 145 → 146 taken 3413 times.
|
7828 | for (const QualType &interfaceType : manifestation->interfaceTypes) { |
| 182 |
1/2✓ Branch 45 → 46 taken 1002 times.
✗ Branch 45 → 265 not taken.
|
1002 | const Interface *interface = interfaceType.getInterface(node); |
| 183 |
1/2✗ Branch 46 → 47 not taken.
✓ Branch 46 → 48 taken 1002 times.
|
1002 | assert(interface != nullptr); |
| 184 | |||
| 185 | // Check for all methods, that it is implemented by the struct | ||
| 186 |
2/2✓ Branch 135 → 50 taken 2502 times.
✓ Branch 135 → 136 taken 1002 times.
|
4506 | for (const Function *expMethod : interface->methods) { |
| 187 |
1/2✓ Branch 52 → 53 taken 2502 times.
✗ Branch 52 → 263 not taken.
|
2502 | const std::string methodName = expMethod->name; |
| 188 |
1/2✓ Branch 53 → 54 taken 2502 times.
✗ Branch 53 → 261 not taken.
|
2502 | QualTypeList params = expMethod->getParamTypes(); |
| 189 | 2502 | QualType returnType = expMethod->returnType; | |
| 190 | |||
| 191 | // Substantiate param and return types | ||
| 192 |
1/2✓ Branch 54 → 55 taken 2502 times.
✗ Branch 54 → 259 not taken.
|
2502 | TypeMatcher::substantiateTypesWithTypeMapping(params, interface->typeMapping, node); |
| 193 |
3/4✓ Branch 55 → 56 taken 2502 times.
✗ Branch 55 → 259 not taken.
✓ Branch 56 → 57 taken 1458 times.
✓ Branch 56 → 58 taken 1044 times.
|
2502 | if (returnType.hasAnyGenericParts()) |
| 194 |
1/2✓ Branch 57 → 58 taken 1458 times.
✗ Branch 57 → 259 not taken.
|
1458 | TypeMatcher::substantiateTypeWithTypeMapping(returnType, interface->typeMapping, node); |
| 195 | |||
| 196 | // Build args list | ||
| 197 | 2502 | ArgList args; | |
| 198 |
1/2✓ Branch 59 → 60 taken 2502 times.
✗ Branch 59 → 257 not taken.
|
2502 | args.reserve(params.size()); |
| 199 |
2/2✓ Branch 74 → 62 taken 22 times.
✓ Branch 74 → 75 taken 2502 times.
|
5026 | for (const QualType ¶m : params) |
| 200 |
1/2✓ Branch 64 → 65 taken 22 times.
✗ Branch 64 → 222 not taken.
|
22 | args.emplace_back(param, nullptr); |
| 201 | |||
| 202 | // Search for method that has the required signature | ||
| 203 |
1/2✓ Branch 76 → 77 taken 2502 times.
✗ Branch 76 → 224 not taken.
|
2502 | Function *spiceFunction = FunctionManager::match(currentScope, methodName, structType, args, {}, true, node); |
| 204 |
2/2✓ Branch 78 → 79 taken 4 times.
✓ Branch 78 → 91 taken 2498 times.
|
2502 | 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 2498 times.
✗ Branch 91 → 257 not taken.
✓ Branch 92 → 93 taken 468 times.
✓ Branch 92 → 96 taken 2030 times.
✓ Branch 97 → 98 taken 2 times.
✓ Branch 97 → 110 taken 2496 times.
|
2966 | if (spiceFunction->returnType != returnType && |
| 212 |
3/4✓ Branch 93 → 94 taken 468 times.
✗ Branch 93 → 257 not taken.
✓ Branch 94 → 95 taken 2 times.
✓ Branch 94 → 96 taken 466 times.
|
468 | !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 | 2496 | spiceFunction->isVirtual = true; | |
| 220 | 2496 | spiceFunction->vtableIndex = vtableIndex++; | |
| 221 |
6/6✓ Branch 112 → 113 taken 2496 times.
✓ Branch 112 → 114 taken 6 times.
✓ Branch 117 → 118 taken 2496 times.
✓ Branch 117 → 119 taken 6 times.
✓ Branch 122 → 123 taken 2496 times.
✓ Branch 122 → 125 taken 6 times.
|
7506 | } |
| 222 | } | ||
| 223 | |||
| 224 | // Check default ctor body if required | ||
| 225 |
2/4✓ Branch 149 → 150 taken 3413 times.
✗ Branch 149 → 268 not taken.
✓ Branch 150 → 151 taken 3413 times.
✗ Branch 150 → 266 not taken.
|
10239 | const Function *ctorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, {}, true); |
| 226 |
4/4✓ Branch 154 → 155 taken 1082 times.
✓ Branch 154 → 160 taken 2331 times.
✓ Branch 155 → 156 taken 174 times.
✓ Branch 155 → 160 taken 908 times.
|
3413 | if (ctorFunc != nullptr && ctorFunc->implicitDefault) { |
| 227 |
1/2✓ Branch 156 → 157 taken 174 times.
✗ Branch 156 → 298 not taken.
|
174 | createCtorBodyPreamble(ctorFunc->bodyScope); |
| 228 |
2/4✓ Branch 157 → 158 taken 174 times.
✗ Branch 157 → 298 not taken.
✗ Branch 158 → 159 not taken.
✓ Branch 158 → 160 taken 174 times.
|
174 | assert(manifestation->areAllFieldsInitialized() == nullptr); |
| 229 | } | ||
| 230 | |||
| 231 | // Check default copy ctor body if required | ||
| 232 |
2/4✓ Branch 160 → 161 taken 3413 times.
✗ Branch 160 → 279 not taken.
✓ Branch 164 → 165 taken 3413 times.
✗ Branch 164 → 275 not taken.
|
10239 | const ArgList args = {{structType.toConstRef(node), false /* always non-temporary */}}; |
| 233 |
2/4✓ Branch 168 → 169 taken 3413 times.
✗ Branch 168 → 283 not taken.
✓ Branch 169 → 170 taken 3413 times.
✗ Branch 169 → 281 not taken.
|
3413 | const Function *copyCtorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, args, true); |
| 234 |
4/4✓ Branch 172 → 173 taken 766 times.
✓ Branch 172 → 178 taken 2647 times.
✓ Branch 173 → 174 taken 246 times.
✓ Branch 173 → 178 taken 520 times.
|
3413 | if (copyCtorFunc != nullptr && copyCtorFunc->implicitDefault) { |
| 235 |
1/2✓ Branch 174 → 175 taken 246 times.
✗ Branch 174 → 296 not taken.
|
246 | createCopyCtorBodyPreamble(copyCtorFunc->bodyScope); |
| 236 |
2/4✓ Branch 175 → 176 taken 246 times.
✗ Branch 175 → 296 not taken.
✗ Branch 176 → 177 not taken.
✓ Branch 176 → 178 taken 246 times.
|
246 | 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 3413 times.
✗ Branch 178 → 296 not taken.
✓ Branch 179 → 180 taken 22 times.
✓ Branch 179 → 185 taken 3391 times.
✓ Branch 180 → 181 taken 17 times.
✓ Branch 180 → 185 taken 5 times.
|
3413 | 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 3413 times.
✗ Branch 188 → 289 not taken.
✓ Branch 189 → 190 taken 3413 times.
✗ Branch 189 → 287 not taken.
|
10239 | const Function *dtorFunc = FunctionManager::lookup(currentScope, DTOR_FUNCTION_NAME, structType, {}, true); |
| 248 |
4/4✓ Branch 193 → 194 taken 1673 times.
✓ Branch 193 → 196 taken 1740 times.
✓ Branch 194 → 195 taken 1248 times.
✓ Branch 194 → 196 taken 425 times.
|
3413 | if (dtorFunc != nullptr && dtorFunc->implicitDefault) |
| 249 |
1/2✓ Branch 195 → 196 taken 1248 times.
✗ Branch 195 → 296 not taken.
|
1248 | createDtorBodyPreamble(dtorFunc->bodyScope); |
| 250 | |||
| 251 | // Reset field symbols to declared state for the next manifestation | ||
| 252 |
1/2✓ Branch 196 → 197 taken 3413 times.
✗ Branch 196 → 296 not taken.
|
3413 | manifestation->resetFieldSymbolsToDeclared(node); |
| 253 | |||
| 254 | // Clear type mapping | ||
| 255 | 3413 | typeMapping.clear(); | |
| 256 | |||
| 257 | // Return to the root scope | ||
| 258 | 3413 | currentScope = rootScope; | |
| 259 |
2/4✓ Branch 198 → 199 taken 3413 times.
✗ Branch 198 → 201 not taken.
✓ Branch 199 → 200 taken 3413 times.
✗ Branch 199 → 201 not taken.
|
3413 | assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL); |
| 260 | |||
| 261 | 3413 | manIdx++; // Increase the manifestation index | |
| 262 | 3413 | } | |
| 263 | 2661 | manIdx = 0; // Reset the manifestation index | |
| 264 | |||
| 265 |
1/2✓ Branch 215 → 216 taken 2661 times.
✗ Branch 215 → 300 not taken.
|
5322 | return nullptr; |
| 266 | } | ||
| 267 | |||
| 268 | } // namespace spice::compiler | ||
| 269 |