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 | 512 | std::any TypeChecker::visitMainFctDefCheck(MainFctDefNode *node) { | |
| 17 | // Skip if already type-checked | ||
| 18 |
2/2✓ Branch 2 → 3 taken 58 times.
✓ Branch 2 → 6 taken 454 times.
|
512 | if (typeCheckedMainFct) |
| 19 |
1/2✓ Branch 3 → 4 taken 58 times.
✗ Branch 3 → 13 not taken.
|
116 | return nullptr; |
| 20 | |||
| 21 | 454 | node->resizeToNumberOfManifestations(1); | |
| 22 | |||
| 23 | // Change to function body scope | ||
| 24 | 454 | currentScope = node->bodyScope; | |
| 25 | // Visit statements in new scope | ||
| 26 |
2/2✓ Branch 7 → 8 taken 424 times.
✓ Branch 7 → 14 taken 30 times.
|
454 | visit(node->body); |
| 27 | // Leave main function body scope | ||
| 28 | 424 | currentScope = rootScope; | |
| 29 | |||
| 30 | // Set to type-checked | ||
| 31 | 424 | typeCheckedMainFct = true; | |
| 32 |
1/2✓ Branch 9 → 10 taken 424 times.
✗ Branch 9 → 15 not taken.
|
848 | return nullptr; |
| 33 | } | ||
| 34 | |||
| 35 | 25467 | std::any TypeChecker::visitFctDefCheck(FctDefNode *node) { | |
| 36 | 25467 | node->resizeToNumberOfManifestations(node->manifestations.size()); | |
| 37 | 25467 | manIdx = 0; // Reset the manifestation index | |
| 38 | |||
| 39 | // Get all manifestations for this function definition | ||
| 40 |
2/2✓ Branch 56 → 6 taken 32768 times.
✓ Branch 56 → 57 taken 25465 times.
|
83700 | for (Function *manifestation : node->manifestations) { |
| 41 | // Skip non-substantiated or already checked functions | ||
| 42 |
7/8✓ Branch 8 → 9 taken 32768 times.
✗ Branch 8 → 72 not taken.
✓ Branch 9 → 10 taken 25223 times.
✓ Branch 9 → 11 taken 7545 times.
✓ Branch 10 → 11 taken 13811 times.
✓ Branch 10 → 12 taken 11412 times.
✓ Branch 13 → 14 taken 21356 times.
✓ Branch 13 → 15 taken 11412 times.
|
32768 | if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) { |
| 43 | 21356 | manIdx++; // Increase the manifestation index | |
| 44 | 21356 | continue; | |
| 45 | } | ||
| 46 | |||
| 47 | // Change scope to concrete struct specialization scope | ||
| 48 |
2/2✓ Branch 15 → 16 taken 5285 times.
✓ Branch 15 → 21 taken 6127 times.
|
11412 | if (node->isMethod) { |
| 49 |
2/4✓ Branch 16 → 17 taken 5285 times.
✗ Branch 16 → 63 not taken.
✓ Branch 17 → 18 taken 5285 times.
✗ Branch 17 → 63 not taken.
|
5285 | const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes()); |
| 50 |
1/2✓ Branch 18 → 19 taken 5285 times.
✗ Branch 18 → 61 not taken.
|
5285 | changeToScope(scopeName, ScopeType::STRUCT); |
| 51 | 5285 | } | |
| 52 | |||
| 53 | // Change to function scope | ||
| 54 |
1/2✓ Branch 21 → 22 taken 11412 times.
✗ Branch 21 → 72 not taken.
|
11412 | 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 11412 times.
|
11412 | assert(typeMapping.empty()); |
| 58 |
1/2✓ Branch 25 → 26 taken 11412 times.
✗ Branch 25 → 72 not taken.
|
11412 | typeMapping = manifestation->typeMapping; |
| 59 | |||
| 60 | // Set return type to the result variable | ||
| 61 |
1/2✓ Branch 28 → 29 taken 11412 times.
✗ Branch 28 → 66 not taken.
|
34236 | SymbolTableEntry *resultVarEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME); |
| 62 |
1/2✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 11412 times.
|
11412 | assert(resultVarEntry != nullptr); |
| 63 |
1/2✓ Branch 36 → 37 taken 11412 times.
✗ Branch 36 → 72 not taken.
|
11412 | resultVarEntry->updateType(manifestation->returnType, false); |
| 64 | 11412 | 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 8793 times.
✓ Branch 37 → 41 taken 2619 times.
|
11412 | if (node->hasParams) |
| 69 |
1/2✓ Branch 38 → 39 taken 8793 times.
✗ Branch 38 → 70 not taken.
|
8793 | visit(node->paramLst); |
| 70 | |||
| 71 | // Visit statements in new scope | ||
| 72 |
2/2✓ Branch 41 → 42 taken 11410 times.
✓ Branch 41 → 71 taken 2 times.
|
11412 | visit(node->body); |
| 73 | |||
| 74 | // Clear type mapping | ||
| 75 | 11410 | typeMapping.clear(); | |
| 76 | |||
| 77 | // Change to root scope | ||
| 78 | 11410 | currentScope = rootScope; | |
| 79 |
1/2✗ Branch 44 → 45 not taken.
✓ Branch 44 → 46 taken 11410 times.
|
11410 | assert(currentScope->type == ScopeType::GLOBAL); |
| 80 | |||
| 81 | // Do not type-check this manifestation again | ||
| 82 | 11410 | manifestation->alreadyTypeChecked = true; | |
| 83 | |||
| 84 | 11410 | manIdx++; // Increase the manifestation index | |
| 85 | } | ||
| 86 | 25465 | manIdx = 0; // Reset the manifestation index | |
| 87 | |||
| 88 |
1/2✓ Branch 57 → 58 taken 25465 times.
✗ Branch 57 → 73 not taken.
|
50930 | return nullptr; |
| 89 | } | ||
| 90 | |||
| 91 | 14146 | std::any TypeChecker::visitProcDefCheck(ProcDefNode *node) { | |
| 92 | 14146 | node->resizeToNumberOfManifestations(node->manifestations.size()); | |
| 93 | 14146 | manIdx = 0; // Reset the manifestation index | |
| 94 | |||
| 95 | // Get all manifestations for this procedure definition | ||
| 96 |
2/2✓ Branch 49 → 6 taken 19314 times.
✓ Branch 49 → 50 taken 14146 times.
|
47606 | for (Function *manifestation : node->manifestations) { |
| 97 | // Skip non-substantiated or already checked procedures | ||
| 98 |
7/8✓ Branch 8 → 9 taken 19314 times.
✗ Branch 8 → 59 not taken.
✓ Branch 9 → 10 taken 11424 times.
✓ Branch 9 → 11 taken 7890 times.
✓ Branch 10 → 11 taken 5455 times.
✓ Branch 10 → 12 taken 5969 times.
✓ Branch 13 → 14 taken 13345 times.
✓ Branch 13 → 15 taken 5969 times.
|
19314 | if (!manifestation->isFullySubstantiated() || manifestation->alreadyTypeChecked) { |
| 99 | 13345 | manIdx++; // Increase the manifestation index | |
| 100 | 13345 | continue; | |
| 101 | } | ||
| 102 | |||
| 103 | // Change scope to concrete struct specialization scope | ||
| 104 |
2/2✓ Branch 15 → 16 taken 4683 times.
✓ Branch 15 → 21 taken 1286 times.
|
5969 | if (node->isMethod) { |
| 105 |
2/4✓ Branch 16 → 17 taken 4683 times.
✗ Branch 16 → 56 not taken.
✓ Branch 17 → 18 taken 4683 times.
✗ Branch 17 → 56 not taken.
|
4683 | const std::string &scopeName = Struct::getScopeName(node->name->structName, manifestation->thisType.getTemplateTypes()); |
| 106 |
1/2✓ Branch 18 → 19 taken 4683 times.
✗ Branch 18 → 54 not taken.
|
4683 | changeToScope(scopeName, ScopeType::STRUCT); |
| 107 | 4683 | } | |
| 108 | |||
| 109 | // Change to procedure scope | ||
| 110 |
1/2✓ Branch 21 → 22 taken 5969 times.
✗ Branch 21 → 59 not taken.
|
5969 | 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 5969 times.
|
5969 | assert(typeMapping.empty()); |
| 114 |
1/2✓ Branch 25 → 26 taken 5969 times.
✗ Branch 25 → 59 not taken.
|
5969 | 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 4488 times.
✓ Branch 26 → 30 taken 1481 times.
|
5969 | if (node->hasParams) |
| 119 |
1/2✓ Branch 27 → 28 taken 4488 times.
✗ Branch 27 → 57 not taken.
|
4488 | 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 2348 times.
✓ Branch 30 → 32 taken 3621 times.
|
5969 | if (node->isCtor) |
| 123 |
1/2✓ Branch 31 → 32 taken 2348 times.
✗ Branch 31 → 59 not taken.
|
2348 | createCtorBodyPreamble(node->scope); |
| 124 | |||
| 125 | // Visit statements in new scope | ||
| 126 |
1/2✓ Branch 32 → 33 taken 5969 times.
✗ Branch 32 → 58 not taken.
|
5969 | visit(node->body); |
| 127 | |||
| 128 | // Clear type mapping | ||
| 129 | 5969 | typeMapping.clear(); | |
| 130 | |||
| 131 | // Change to root scope | ||
| 132 | 5969 | currentScope = rootScope; | |
| 133 |
2/4✓ Branch 35 → 36 taken 5969 times.
✗ Branch 35 → 38 not taken.
✓ Branch 36 → 37 taken 5969 times.
✗ Branch 36 → 38 not taken.
|
5969 | assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL); |
| 134 | |||
| 135 | // Do not type-check this manifestation again | ||
| 136 | 5969 | manifestation->alreadyTypeChecked = true; | |
| 137 | |||
| 138 | 5969 | manIdx++; // Increase the manifestation index | |
| 139 | } | ||
| 140 | 14146 | manIdx = 0; // Reset the manifestation index | |
| 141 | |||
| 142 |
1/2✓ Branch 50 → 51 taken 14146 times.
✗ Branch 50 → 60 not taken.
|
28292 | return nullptr; |
| 143 | } | ||
| 144 | |||
| 145 | 2224 | std::any TypeChecker::visitStructDefCheck(StructDefNode *node) { | |
| 146 | 2224 | node->resizeToNumberOfManifestations(node->structManifestations.size()); | |
| 147 | 2224 | manIdx = 0; // Reset the manifestation index | |
| 148 | |||
| 149 | // Get all manifestations for this procedure definition | ||
| 150 |
2/2✓ Branch 214 → 6 taken 3902 times.
✓ Branch 214 → 215 taken 2224 times.
|
8350 | for (const Struct *manifestation : node->structManifestations) { |
| 151 | // Skip non-substantiated or already checked procedures | ||
| 152 |
3/4✓ Branch 8 → 9 taken 3902 times.
✗ Branch 8 → 298 not taken.
✓ Branch 9 → 10 taken 1092 times.
✓ Branch 9 → 11 taken 2810 times.
|
3902 | if (!manifestation->isFullySubstantiated()) { |
| 153 | 1092 | manIdx++; // Increase the manifestation index | |
| 154 | 1092 | continue; | |
| 155 | } | ||
| 156 | |||
| 157 | // Change to struct scope | ||
| 158 |
1/2✓ Branch 11 → 12 taken 2810 times.
✗ Branch 11 → 298 not taken.
|
2810 | 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 2810 times.
|
2810 | assert(typeMapping.empty()); |
| 164 |
1/2✓ Branch 15 → 16 taken 2810 times.
✗ Branch 15 → 298 not taken.
|
2810 | 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 6282 times.
✓ Branch 39 → 40 taken 2810 times.
|
11902 | for (const FieldNode *field : node->fields) { |
| 168 |
2/2✓ Branch 20 → 21 taken 1290 times.
✓ Branch 20 → 30 taken 4992 times.
|
6282 | if (field->defaultValue != nullptr) { |
| 169 |
1/2✓ Branch 21 → 22 taken 1290 times.
✗ Branch 21 → 219 not taken.
|
1290 | visit(field->defaultValue); |
| 170 |
1/2✓ Branch 23 → 24 taken 1290 times.
✗ Branch 23 → 221 not taken.
|
1290 | SymbolTableEntry *fieldEntry = manifestation->scope->lookupStrict(field->fieldName); |
| 171 |
1/2✗ Branch 26 → 27 not taken.
✓ Branch 26 → 28 taken 1290 times.
|
1290 | assert(fieldEntry != nullptr); |
| 172 |
1/2✓ Branch 28 → 29 taken 1290 times.
✗ Branch 28 → 220 not taken.
|
1290 | fieldEntry->updateState(INITIALIZED, field); |
| 173 | } | ||
| 174 | } | ||
| 175 | |||
| 176 | // Build struct type | ||
| 177 |
1/2✓ Branch 40 → 41 taken 2810 times.
✗ Branch 40 → 298 not taken.
|
2810 | const QualType structType = manifestation->entry->getQualType(); |
| 178 | |||
| 179 | // Check if the struct implements all methods of all attached interfaces | ||
| 180 | 2810 | size_t vtableIndex = 0; | |
| 181 |
2/2✓ Branch 145 → 43 taken 866 times.
✓ Branch 145 → 146 taken 2810 times.
|
6486 | for (const QualType &interfaceType : manifestation->interfaceTypes) { |
| 182 |
1/2✓ Branch 45 → 46 taken 866 times.
✗ Branch 45 → 265 not taken.
|
866 | const Interface *interface = interfaceType.getInterface(node); |
| 183 |
1/2✗ Branch 46 → 47 not taken.
✓ Branch 46 → 48 taken 866 times.
|
866 | assert(interface != nullptr); |
| 184 | |||
| 185 | // Check for all methods, that it is implemented by the struct | ||
| 186 |
2/2✓ Branch 135 → 50 taken 2164 times.
✓ Branch 135 → 136 taken 866 times.
|
3896 | for (const Function *expMethod : interface->methods) { |
| 187 |
1/2✓ Branch 52 → 53 taken 2164 times.
✗ Branch 52 → 263 not taken.
|
2164 | const std::string methodName = expMethod->name; |
| 188 |
1/2✓ Branch 53 → 54 taken 2164 times.
✗ Branch 53 → 261 not taken.
|
2164 | QualTypeList params = expMethod->getParamTypes(); |
| 189 | 2164 | QualType returnType = expMethod->returnType; | |
| 190 | |||
| 191 | // Substantiate param and return types | ||
| 192 |
1/2✓ Branch 54 → 55 taken 2164 times.
✗ Branch 54 → 259 not taken.
|
2164 | TypeMatcher::substantiateTypesWithTypeMapping(params, interface->typeMapping, node); |
| 193 |
3/4✓ Branch 55 → 56 taken 2164 times.
✗ Branch 55 → 259 not taken.
✓ Branch 56 → 57 taken 1260 times.
✓ Branch 56 → 58 taken 904 times.
|
2164 | if (returnType.hasAnyGenericParts()) |
| 194 |
1/2✓ Branch 57 → 58 taken 1260 times.
✗ Branch 57 → 259 not taken.
|
1260 | TypeMatcher::substantiateTypeWithTypeMapping(returnType, interface->typeMapping, node); |
| 195 | |||
| 196 | // Build args list | ||
| 197 | 2164 | ArgList args; | |
| 198 |
1/2✓ Branch 59 → 60 taken 2164 times.
✗ Branch 59 → 257 not taken.
|
2164 | args.reserve(params.size()); |
| 199 |
2/2✓ Branch 74 → 62 taken 14 times.
✓ Branch 74 → 75 taken 2164 times.
|
4342 | for (const QualType ¶m : params) |
| 200 |
1/2✓ Branch 64 → 65 taken 14 times.
✗ Branch 64 → 222 not taken.
|
14 | args.emplace_back(param, nullptr); |
| 201 | |||
| 202 | // Search for method that has the required signature | ||
| 203 |
1/2✓ Branch 76 → 77 taken 2164 times.
✗ Branch 76 → 224 not taken.
|
2164 | Function *spiceFunction = FunctionManager::match(currentScope, methodName, structType, args, {}, true, node); |
| 204 |
2/2✓ Branch 78 → 79 taken 4 times.
✓ Branch 78 → 91 taken 2160 times.
|
2164 | 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 2160 times.
✗ Branch 91 → 257 not taken.
✓ Branch 92 → 93 taken 402 times.
✓ Branch 92 → 96 taken 1758 times.
✓ Branch 97 → 98 taken 2 times.
✓ Branch 97 → 110 taken 2158 times.
|
2562 | if (spiceFunction->returnType != returnType && |
| 212 |
3/4✓ Branch 93 → 94 taken 402 times.
✗ Branch 93 → 257 not taken.
✓ Branch 94 → 95 taken 2 times.
✓ Branch 94 → 96 taken 400 times.
|
402 | !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 | 2158 | spiceFunction->isVirtual = true; | |
| 220 | 2158 | spiceFunction->vtableIndex = vtableIndex++; | |
| 221 |
6/6✓ Branch 112 → 113 taken 2158 times.
✓ Branch 112 → 114 taken 6 times.
✓ Branch 117 → 118 taken 2158 times.
✓ Branch 117 → 119 taken 6 times.
✓ Branch 122 → 123 taken 2158 times.
✓ Branch 122 → 125 taken 6 times.
|
6492 | } |
| 222 | } | ||
| 223 | |||
| 224 | // Check default ctor body if required | ||
| 225 |
2/4✓ Branch 149 → 150 taken 2810 times.
✗ Branch 149 → 268 not taken.
✓ Branch 150 → 151 taken 2810 times.
✗ Branch 150 → 266 not taken.
|
8430 | const Function *ctorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, {}, true); |
| 226 |
4/4✓ Branch 154 → 155 taken 1019 times.
✓ Branch 154 → 160 taken 1791 times.
✓ Branch 155 → 156 taken 168 times.
✓ Branch 155 → 160 taken 851 times.
|
2810 | if (ctorFunc != nullptr && ctorFunc->implicitDefault) { |
| 227 |
1/2✓ Branch 156 → 157 taken 168 times.
✗ Branch 156 → 298 not taken.
|
168 | createCtorBodyPreamble(ctorFunc->bodyScope); |
| 228 |
2/4✓ Branch 157 → 158 taken 168 times.
✗ Branch 157 → 298 not taken.
✗ Branch 158 → 159 not taken.
✓ Branch 158 → 160 taken 168 times.
|
168 | assert(manifestation->areAllFieldsInitialized() == nullptr); |
| 229 | } | ||
| 230 | |||
| 231 | // Check default copy ctor body if required | ||
| 232 |
2/4✓ Branch 160 → 161 taken 2810 times.
✗ Branch 160 → 279 not taken.
✓ Branch 164 → 165 taken 2810 times.
✗ Branch 164 → 275 not taken.
|
8430 | const ArgList args = {{structType.toConstRef(node), false /* always non-temporary */}}; |
| 233 |
2/4✓ Branch 168 → 169 taken 2810 times.
✗ Branch 168 → 283 not taken.
✓ Branch 169 → 170 taken 2810 times.
✗ Branch 169 → 281 not taken.
|
2810 | const Function *copyCtorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, structType, args, true); |
| 234 |
4/4✓ Branch 172 → 173 taken 703 times.
✓ Branch 172 → 178 taken 2107 times.
✓ Branch 173 → 174 taken 231 times.
✓ Branch 173 → 178 taken 472 times.
|
2810 | if (copyCtorFunc != nullptr && copyCtorFunc->implicitDefault) { |
| 235 |
1/2✓ Branch 174 → 175 taken 231 times.
✗ Branch 174 → 296 not taken.
|
231 | createCopyCtorBodyPreamble(copyCtorFunc->bodyScope); |
| 236 |
2/4✓ Branch 175 → 176 taken 231 times.
✗ Branch 175 → 296 not taken.
✗ Branch 176 → 177 not taken.
✓ Branch 176 → 178 taken 231 times.
|
231 | 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 2810 times.
✗ Branch 178 → 296 not taken.
✓ Branch 179 → 180 taken 22 times.
✓ Branch 179 → 185 taken 2788 times.
✓ Branch 180 → 181 taken 17 times.
✓ Branch 180 → 185 taken 5 times.
|
2810 | 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 2810 times.
✗ Branch 188 → 289 not taken.
✓ Branch 189 → 190 taken 2810 times.
✗ Branch 189 → 287 not taken.
|
8430 | const Function *dtorFunc = FunctionManager::lookup(currentScope, DTOR_FUNCTION_NAME, structType, {}, true); |
| 248 |
4/4✓ Branch 193 → 194 taken 926 times.
✓ Branch 193 → 196 taken 1884 times.
✓ Branch 194 → 195 taken 529 times.
✓ Branch 194 → 196 taken 397 times.
|
2810 | if (dtorFunc != nullptr && dtorFunc->implicitDefault) |
| 249 |
1/2✓ Branch 195 → 196 taken 529 times.
✗ Branch 195 → 296 not taken.
|
529 | createDtorBodyPreamble(dtorFunc->bodyScope); |
| 250 | |||
| 251 | // Reset field symbols to declared state for the next manifestation | ||
| 252 |
1/2✓ Branch 196 → 197 taken 2810 times.
✗ Branch 196 → 296 not taken.
|
2810 | manifestation->resetFieldSymbolsToDeclared(node); |
| 253 | |||
| 254 | // Clear type mapping | ||
| 255 | 2810 | typeMapping.clear(); | |
| 256 | |||
| 257 | // Return to the root scope | ||
| 258 | 2810 | currentScope = rootScope; | |
| 259 |
2/4✓ Branch 198 → 199 taken 2810 times.
✗ Branch 198 → 201 not taken.
✓ Branch 199 → 200 taken 2810 times.
✗ Branch 199 → 201 not taken.
|
2810 | assert(currentScope != nullptr && currentScope->type == ScopeType::GLOBAL); |
| 260 | |||
| 261 | 2810 | manIdx++; // Increase the manifestation index | |
| 262 | 2810 | } | |
| 263 | 2224 | manIdx = 0; // Reset the manifestation index | |
| 264 | |||
| 265 |
1/2✓ Branch 215 → 216 taken 2224 times.
✗ Branch 215 → 300 not taken.
|
4448 | return nullptr; |
| 266 | } | ||
| 267 | |||
| 268 | } // namespace spice::compiler | ||
| 269 |