src/typechecker/TypeCheckerValues.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 <ast/Attributes.h> | ||
| 8 | #include <global/GlobalResourceManager.h> | ||
| 9 | #include <model/GenericType.h> | ||
| 10 | #include <symboltablebuilder/Scope.h> | ||
| 11 | #include <symboltablebuilder/ScopeHandle.h> | ||
| 12 | #include <symboltablebuilder/SymbolTableBuilder.h> | ||
| 13 | #include <typechecker/BuiltinFunctions.h> | ||
| 14 | #include <typechecker/FunctionManager.h> | ||
| 15 | #include <typechecker/MacroDefs.h> | ||
| 16 | #include <typechecker/TypeMatcher.h> | ||
| 17 | |||
| 18 | namespace spice::compiler { | ||
| 19 | |||
| 20 | 83486 | std::any TypeChecker::visitValue(ValueNode *node) { | |
| 21 | // Function call | ||
| 22 |
2/2✓ Branch 2 → 3 taken 72266 times.
✓ Branch 2 → 4 taken 11220 times.
|
83486 | if (node->fctCall) |
| 23 | 72266 | return visit(node->fctCall); | |
| 24 | |||
| 25 | // Array initialization | ||
| 26 |
2/2✓ Branch 4 → 5 taken 335 times.
✓ Branch 4 → 6 taken 10885 times.
|
11220 | if (node->arrayInitialization) |
| 27 | 335 | return visit(node->arrayInitialization); | |
| 28 | |||
| 29 | // Struct instantiation | ||
| 30 |
2/2✓ Branch 6 → 7 taken 1313 times.
✓ Branch 6 → 8 taken 9572 times.
|
10885 | if (node->structInstantiation) |
| 31 | 1313 | return visit(node->structInstantiation); | |
| 32 | |||
| 33 | // Lambda function | ||
| 34 |
2/2✓ Branch 8 → 9 taken 55 times.
✓ Branch 8 → 10 taken 9517 times.
|
9572 | if (node->lambdaFunc) |
| 35 | 55 | return visit(node->lambdaFunc); | |
| 36 | |||
| 37 | // Lambda procedure | ||
| 38 |
2/2✓ Branch 10 → 11 taken 46 times.
✓ Branch 10 → 12 taken 9471 times.
|
9517 | if (node->lambdaProc) |
| 39 | 46 | return visit(node->lambdaProc); | |
| 40 | |||
| 41 | // Lambda expression | ||
| 42 |
2/2✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 14 taken 9470 times.
|
9471 | if (node->lambdaExpr) |
| 43 | 1 | return visit(node->lambdaExpr); | |
| 44 | |||
| 45 | // Typed nil | ||
| 46 |
1/2✓ Branch 14 → 15 taken 9470 times.
✗ Branch 14 → 41 not taken.
|
9470 | if (node->isNil) { |
| 47 |
2/4✓ Branch 15 → 16 taken 9470 times.
✗ Branch 15 → 52 not taken.
✓ Branch 16 → 17 taken 9470 times.
✗ Branch 16 → 50 not taken.
|
9470 | const auto nilType = std::any_cast<QualType>(visit(node->nilType)); |
| 48 |
2/8✓ Branch 18 → 19 taken 9470 times.
✗ Branch 18 → 62 not taken.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 24 taken 9470 times.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 53 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 53 not taken.
|
9470 | HANDLE_UNRESOLVED_TYPE_ER(nilType) |
| 49 |
2/4✓ Branch 24 → 25 taken 9470 times.
✗ Branch 24 → 62 not taken.
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 36 taken 9470 times.
|
9470 | if (nilType.is(TY_DYN)) |
| 50 | ✗ | SOFT_ERROR_ER(node->nilType, UNEXPECTED_DYN_TYPE, "Nil must have an explicit type") | |
| 51 |
2/4✓ Branch 36 → 37 taken 9470 times.
✗ Branch 36 → 61 not taken.
✓ Branch 37 → 38 taken 9470 times.
✗ Branch 37 → 61 not taken.
|
18940 | return ExprResult{node->setEvaluatedSymbolType(nilType, manIdx)}; |
| 52 | } | ||
| 53 | |||
| 54 | − | throw CompilerError(UNHANDLED_BRANCH, "Value fall-through"); // GCOV_EXCL_LINE | |
| 55 | } | ||
| 56 | |||
| 57 | 79664 | std::any TypeChecker::visitConstant(ConstantNode *node) { | |
| 58 | SuperType superType; | ||
| 59 |
7/8✓ Branch 2 → 3 taken 2001 times.
✓ Branch 2 → 4 taken 9952 times.
✓ Branch 2 → 5 taken 1308 times.
✓ Branch 2 → 6 taken 33807 times.
✓ Branch 2 → 7 taken 6616 times.
✓ Branch 2 → 8 taken 17058 times.
✓ Branch 2 → 9 taken 8922 times.
✗ Branch 2 → 10 not taken.
|
79664 | switch (node->type) { |
| 60 | 2001 | case ConstantNode::PrimitiveValueType::TYPE_DOUBLE: | |
| 61 | 2001 | superType = TY_DOUBLE; | |
| 62 | 2001 | break; | |
| 63 | 9952 | case ConstantNode::PrimitiveValueType::TYPE_INT: | |
| 64 | 9952 | superType = TY_INT; | |
| 65 | 9952 | break; | |
| 66 | 1308 | case ConstantNode::PrimitiveValueType::TYPE_SHORT: | |
| 67 | 1308 | superType = TY_SHORT; | |
| 68 | 1308 | break; | |
| 69 | 33807 | case ConstantNode::PrimitiveValueType::TYPE_LONG: | |
| 70 | 33807 | superType = TY_LONG; | |
| 71 | 33807 | break; | |
| 72 | 6616 | case ConstantNode::PrimitiveValueType::TYPE_CHAR: | |
| 73 | 6616 | superType = TY_CHAR; | |
| 74 | 6616 | break; | |
| 75 | 17058 | case ConstantNode::PrimitiveValueType::TYPE_STRING: | |
| 76 | 17058 | superType = TY_STRING; | |
| 77 | 17058 | break; | |
| 78 | 8922 | case ConstantNode::PrimitiveValueType::TYPE_BOOL: | |
| 79 | 8922 | superType = TY_BOOL; | |
| 80 | 8922 | break; | |
| 81 | − | default: // GCOV_EXCL_LINE | |
| 82 | − | throw CompilerError(UNHANDLED_BRANCH, "Constant fall-through"); // GCOV_EXCL_LINE | |
| 83 | } | ||
| 84 |
3/6✓ Branch 18 → 19 taken 79664 times.
✗ Branch 18 → 33 not taken.
✓ Branch 19 → 20 taken 79664 times.
✗ Branch 19 → 33 not taken.
✓ Branch 20 → 21 taken 79664 times.
✗ Branch 20 → 33 not taken.
|
159328 | return ExprResult{node->setEvaluatedSymbolType(QualType(superType), manIdx)}; |
| 85 | } | ||
| 86 | |||
| 87 | 72266 | std::any TypeChecker::visitFctCall(FctCallNode *node) { | |
| 88 |
1/2✓ Branch 2 → 3 taken 72266 times.
✗ Branch 2 → 549 not taken.
|
72266 | FctCallNode::FctCallData &data = node->data.at(manIdx); |
| 89 | 72266 | auto &[callType, isImported, templateTypes, thisType, args, callee, calleeParentScope, compTimeVal, hasCompTimeVal] = data; | |
| 90 | |||
| 91 | // Retrieve arg types | ||
| 92 | 72266 | args.clear(); | |
| 93 |
2/2✓ Branch 4 → 5 taken 53591 times.
✓ Branch 4 → 36 taken 18675 times.
|
72266 | if (node->hasArgs) { |
| 94 |
1/2✓ Branch 6 → 7 taken 53591 times.
✗ Branch 6 → 549 not taken.
|
53591 | args.reserve(node->argLst->args.size()); |
| 95 |
2/2✓ Branch 34 → 9 taken 83642 times.
✓ Branch 34 → 35 taken 53574 times.
|
190807 | for (ExprNode *arg : node->argLst->args) { |
| 96 | // Visit argument | ||
| 97 |
3/4✓ Branch 11 → 12 taken 83641 times.
✓ Branch 11 → 428 taken 1 time.
✓ Branch 12 → 13 taken 83641 times.
✗ Branch 12 → 426 not taken.
|
83642 | const auto argResult = std::any_cast<ExprResult>(visit(arg)); |
| 98 |
5/8✓ Branch 14 → 15 taken 83641 times.
✗ Branch 14 → 431 not taken.
✓ Branch 15 → 16 taken 16 times.
✓ Branch 15 → 20 taken 83625 times.
✓ Branch 16 → 17 taken 16 times.
✗ Branch 16 → 429 not taken.
✓ Branch 17 → 18 taken 16 times.
✗ Branch 17 → 429 not taken.
|
83657 | HANDLE_UNRESOLVED_TYPE_ER(argResult.type) |
| 99 |
2/4✓ Branch 20 → 21 taken 83625 times.
✗ Branch 20 → 431 not taken.
✗ Branch 21 → 22 not taken.
✓ Branch 21 → 23 taken 83625 times.
|
83625 | assert(!argResult.type.hasAnyGenericParts()); |
| 100 | // Save arg type to arg types list | ||
| 101 |
1/2✓ Branch 24 → 25 taken 83625 times.
✗ Branch 24 → 430 not taken.
|
83625 | args.emplace_back(argResult.type, argResult.isTemporary()); |
| 102 | } | ||
| 103 | } | ||
| 104 | |||
| 105 | // Retrieve template types | ||
| 106 | 72249 | templateTypes.clear(); | |
| 107 |
2/2✓ Branch 37 → 38 taken 6264 times.
✓ Branch 37 → 81 taken 65985 times.
|
72249 | if (node->hasTemplateTypes) { |
| 108 |
2/2✓ Branch 79 → 40 taken 7518 times.
✓ Branch 79 → 80 taken 6264 times.
|
20046 | for (DataTypeNode *templateTypeNode : node->templateTypeLst->dataTypes) { |
| 109 |
2/4✓ Branch 42 → 43 taken 7518 times.
✗ Branch 42 → 435 not taken.
✓ Branch 43 → 44 taken 7518 times.
✗ Branch 43 → 433 not taken.
|
7518 | auto templateType = std::any_cast<QualType>(visit(templateTypeNode)); |
| 110 |
2/4✓ Branch 45 → 46 taken 7518 times.
✗ Branch 45 → 444 not taken.
✗ Branch 46 → 47 not taken.
✓ Branch 46 → 48 taken 7518 times.
|
7518 | assert(!templateType.is(TY_INVALID)); |
| 111 | |||
| 112 | // Abort if the type is unresolved | ||
| 113 |
2/4✓ Branch 48 → 49 taken 7518 times.
✗ Branch 48 → 444 not taken.
✗ Branch 49 → 50 not taken.
✓ Branch 49 → 56 taken 7518 times.
|
7518 | if (templateType.is(TY_UNRESOLVED)) |
| 114 | ✗ | HANDLE_UNRESOLVED_TYPE_ER(templateType) | |
| 115 | |||
| 116 | // Check if the given type is generic | ||
| 117 |
2/4✓ Branch 56 → 57 taken 7518 times.
✗ Branch 56 → 444 not taken.
✗ Branch 57 → 58 not taken.
✓ Branch 57 → 68 taken 7518 times.
|
7518 | if (templateType.is(TY_GENERIC)) |
| 118 | ✗ | SOFT_ERROR_ER(templateTypeNode, EXPECTED_NON_GENERIC_TYPE, "You must specify a concrete type here") | |
| 119 | |||
| 120 |
1/2✓ Branch 68 → 69 taken 7518 times.
✗ Branch 68 → 444 not taken.
|
7518 | templateTypes.push_back(templateType); |
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 124 | // Check if this is a builtin call | ||
| 125 |
2/2✓ Branch 88 → 82 taken 1491860 times.
✓ Branch 88 → 89 taken 65328 times.
|
1557188 | for (const auto &[builtinFctName, _] : BUILTIN_FUNCTIONS) |
| 126 |
2/2✓ Branch 84 → 85 taken 6921 times.
✓ Branch 84 → 87 taken 1484939 times.
|
1491860 | if (node->fqFunctionName == builtinFctName) |
| 127 |
1/2✓ Branch 85 → 86 taken 6921 times.
✗ Branch 85 → 549 not taken.
|
6921 | return visitBuiltinCall(node); |
| 128 | |||
| 129 | // Retrieve entry of the first fragment | ||
| 130 | 65328 | const std::string &firstFrag = node->functionNameFragments.front(); | |
| 131 |
1/2✓ Branch 90 → 91 taken 65328 times.
✗ Branch 90 → 549 not taken.
|
65328 | SymbolTableEntry *firstFragEntry = currentScope->lookup(firstFrag); |
| 132 |
2/2✓ Branch 93 → 94 taken 43589 times.
✓ Branch 93 → 131 taken 21739 times.
|
65328 | if (firstFragEntry) { |
| 133 | // Check if we have seen a 'this.' prefix, because the generator needs that | ||
| 134 |
6/8✓ Branch 94 → 95 taken 1 time.
✓ Branch 94 → 98 taken 43588 times.
✓ Branch 95 → 96 taken 1 time.
✗ Branch 95 → 456 not taken.
✓ Branch 96 → 97 taken 1 time.
✗ Branch 96 → 98 not taken.
✓ Branch 99 → 100 taken 1 time.
✓ Branch 99 → 109 taken 43588 times.
|
43589 | if (firstFragEntry->scope->type == ScopeType::STRUCT && firstFrag != THIS_VARIABLE_NAME) |
| 135 |
5/10✓ Branch 100 → 101 taken 1 time.
✗ Branch 100 → 450 not taken.
✓ Branch 101 → 102 taken 1 time.
✗ Branch 101 → 448 not taken.
✓ Branch 102 → 103 taken 1 time.
✗ Branch 102 → 446 not taken.
✓ Branch 105 → 106 taken 1 time.
✗ Branch 105 → 452 not taken.
✓ Branch 106 → 107 taken 1 time.
✗ Branch 106 → 452 not taken.
|
2 | SOFT_ERROR_ER(node, REFERENCED_UNDEFINED_VARIABLE, |
| 136 | "The symbol '" + firstFrag + "' could not be found. Missing 'this.' prefix?") | ||
| 137 | |||
| 138 | 43588 | firstFragEntry->used = true; | |
| 139 | // Decide of which type the function call is | ||
| 140 |
2/4✓ Branch 109 → 110 taken 43588 times.
✗ Branch 109 → 456 not taken.
✓ Branch 110 → 111 taken 43588 times.
✗ Branch 110 → 456 not taken.
|
43588 | const QualType &baseType = firstFragEntry->getQualType().getBase(); |
| 141 |
5/8✓ Branch 111 → 112 taken 43588 times.
✗ Branch 111 → 456 not taken.
✓ Branch 112 → 113 taken 4 times.
✓ Branch 112 → 117 taken 43584 times.
✓ Branch 113 → 114 taken 4 times.
✗ Branch 113 → 453 not taken.
✓ Branch 114 → 115 taken 4 times.
✗ Branch 114 → 453 not taken.
|
43592 | HANDLE_UNRESOLVED_TYPE_ER(baseType) |
| 142 |
3/4✓ Branch 117 → 118 taken 43584 times.
✗ Branch 117 → 454 not taken.
✓ Branch 118 → 119 taken 34289 times.
✓ Branch 118 → 122 taken 9295 times.
|
43584 | if (baseType.isOneOf({TY_STRUCT, TY_INTERFACE})) { |
| 143 |
2/2✓ Branch 119 → 120 taken 3817 times.
✓ Branch 119 → 121 taken 30472 times.
|
34289 | if (firstFragEntry->scope->type == ScopeType::GLOBAL) |
| 144 | 3817 | callType = FctCallNode::FctCallType::TYPE_CTOR; | |
| 145 | else | ||
| 146 | 30472 | callType = FctCallNode::FctCallType::TYPE_METHOD; | |
| 147 |
7/8✓ Branch 122 → 123 taken 9295 times.
✗ Branch 122 → 455 not taken.
✓ Branch 123 → 124 taken 9127 times.
✓ Branch 123 → 126 taken 168 times.
✓ Branch 124 → 125 taken 118 times.
✓ Branch 124 → 126 taken 9009 times.
✓ Branch 127 → 128 taken 118 times.
✓ Branch 127 → 129 taken 9177 times.
|
9295 | } else if (baseType.isOneOf({TY_FUNCTION, TY_PROCEDURE}) && firstFragEntry->scope->type != ScopeType::GLOBAL) { |
| 148 | 118 | callType = FctCallNode::FctCallType::TYPE_FCT_PTR; | |
| 149 | } | ||
| 150 | } | ||
| 151 | |||
| 152 | // Get struct name. Retrieve it from alias if required | ||
| 153 |
1/2✓ Branch 131 → 132 taken 65323 times.
✗ Branch 131 → 549 not taken.
|
65323 | const auto &[structEntry, isAlias] = rootScope->symbolTable.lookupWithAliasResolution(node->fqFunctionName); |
| 154 |
4/6✓ Branch 134 → 135 taken 1 time.
✓ Branch 134 → 138 taken 65322 times.
✓ Branch 135 → 136 taken 1 time.
✗ Branch 135 → 549 not taken.
✓ Branch 136 → 137 taken 1 time.
✗ Branch 136 → 549 not taken.
|
65323 | const std::string &fqFunctionName = isAlias ? structEntry->getQualType().getSubType() : node->fqFunctionName; |
| 155 | |||
| 156 | // Get the concrete template types | ||
| 157 |
2/2✓ Branch 139 → 140 taken 1 time.
✓ Branch 139 → 159 taken 65322 times.
|
65323 | if (isAlias) { |
| 158 | // Retrieve concrete template types from type alias | ||
| 159 |
3/6✓ Branch 140 → 141 taken 1 time.
✗ Branch 140 → 549 not taken.
✓ Branch 141 → 142 taken 1 time.
✗ Branch 141 → 549 not taken.
✓ Branch 142 → 143 taken 1 time.
✗ Branch 142 → 549 not taken.
|
1 | templateTypes = structEntry->getQualType().getTemplateTypes(); |
| 160 | // Check if the aliased type specified template types and the struct instantiation does | ||
| 161 |
3/6✓ Branch 144 → 145 taken 1 time.
✗ Branch 144 → 147 not taken.
✗ Branch 145 → 146 not taken.
✓ Branch 145 → 147 taken 1 time.
✗ Branch 148 → 149 not taken.
✓ Branch 148 → 159 taken 1 time.
|
1 | if (!templateTypes.empty() && node->hasTemplateTypes) |
| 162 | ✗ | SOFT_ERROR_ER(node->templateTypeLst, ALIAS_WITH_TEMPLATE_LIST, "The aliased type already has a template list") | |
| 163 | } | ||
| 164 | |||
| 165 | // Check if this is a method call or a normal function call | ||
| 166 |
2/2✓ Branch 160 → 161 taken 30472 times.
✓ Branch 160 → 175 taken 34851 times.
|
65323 | if (data.isMethodCall()) { |
| 167 | // This is a method call | ||
| 168 |
1/2✓ Branch 161 → 162 taken 30472 times.
✗ Branch 161 → 549 not taken.
|
30472 | thisType = firstFragEntry->getQualType(); |
| 169 |
2/4✓ Branch 162 → 163 taken 30472 times.
✗ Branch 162 → 464 not taken.
✓ Branch 163 → 164 taken 30472 times.
✗ Branch 163 → 464 not taken.
|
30472 | Scope *structBodyScope = thisType.getBase().getBodyScope(); |
| 170 |
1/2✗ Branch 164 → 165 not taken.
✓ Branch 164 → 166 taken 30472 times.
|
30472 | assert(structBodyScope != nullptr); |
| 171 |
3/4✓ Branch 166 → 167 taken 30472 times.
✗ Branch 166 → 549 not taken.
✓ Branch 167 → 168 taken 2 times.
✓ Branch 167 → 173 taken 30470 times.
|
30472 | if (!visitMethodCall(node, structBodyScope)) // Check if soft errors occurred |
| 172 |
3/6✓ Branch 168 → 169 taken 2 times.
✗ Branch 168 → 465 not taken.
✓ Branch 169 → 170 taken 2 times.
✗ Branch 169 → 465 not taken.
✓ Branch 170 → 171 taken 2 times.
✗ Branch 170 → 465 not taken.
|
4 | return ExprResult{node->setEvaluatedSymbolType(QualType(TY_UNRESOLVED), manIdx)}; |
| 173 |
1/2✗ Branch 173 → 174 not taken.
✓ Branch 173 → 211 taken 30470 times.
|
30470 | assert(calleeParentScope != nullptr); |
| 174 |
2/2✓ Branch 176 → 177 taken 118 times.
✓ Branch 176 → 190 taken 34733 times.
|
34851 | } else if (data.isFctPtrCall()) { |
| 175 | // This is a function pointer call | ||
| 176 |
2/4✓ Branch 177 → 178 taken 118 times.
✗ Branch 177 → 470 not taken.
✓ Branch 178 → 179 taken 118 times.
✗ Branch 178 → 470 not taken.
|
118 | const QualType &functionType = firstFragEntry->getQualType().getBase(); |
| 177 |
2/4✓ Branch 179 → 180 taken 118 times.
✗ Branch 179 → 467 not taken.
✗ Branch 180 → 181 not taken.
✓ Branch 180 → 182 taken 118 times.
|
118 | assert(functionType.isOneOf({TY_FUNCTION, TY_PROCEDURE})); |
| 178 |
2/4✓ Branch 182 → 183 taken 118 times.
✗ Branch 182 → 470 not taken.
✗ Branch 183 → 184 not taken.
✓ Branch 183 → 189 taken 118 times.
|
118 | if (!visitFctPtrCall(node, functionType)) // Check if soft errors occurred |
| 179 | ✗ | return ExprResult{node->setEvaluatedSymbolType(QualType(TY_UNRESOLVED), manIdx)}; | |
| 180 | } else { | ||
| 181 | // This is an ordinary function call | ||
| 182 |
3/4✓ Branch 191 → 192 taken 3854 times.
✓ Branch 191 → 195 taken 30879 times.
✗ Branch 193 → 194 not taken.
✓ Branch 193 → 195 taken 3854 times.
|
34733 | assert(data.isOrdinaryCall() || data.isCtorCall()); |
| 183 |
5/6✓ Branch 195 → 196 taken 34733 times.
✗ Branch 195 → 473 not taken.
✓ Branch 196 → 197 taken 34732 times.
✓ Branch 196 → 471 taken 1 time.
✓ Branch 198 → 199 taken 4 times.
✓ Branch 198 → 204 taken 34728 times.
|
34734 | if (!visitOrdinaryFctCall(node, fqFunctionName)) // Check if soft errors occurred |
| 184 |
3/6✓ Branch 199 → 200 taken 4 times.
✗ Branch 199 → 474 not taken.
✓ Branch 200 → 201 taken 4 times.
✗ Branch 200 → 474 not taken.
✓ Branch 201 → 202 taken 4 times.
✗ Branch 201 → 474 not taken.
|
8 | return ExprResult{node->setEvaluatedSymbolType(QualType(TY_UNRESOLVED), manIdx)}; |
| 185 |
1/2✗ Branch 204 → 205 not taken.
✓ Branch 204 → 206 taken 34728 times.
|
34728 | assert(calleeParentScope != nullptr); |
| 186 | |||
| 187 | // If the call is no ordinary call, it must be a constructor, which takes a struct as this type. | ||
| 188 |
4/6✓ Branch 207 → 208 taken 9900 times.
✓ Branch 207 → 211 taken 24828 times.
✓ Branch 208 → 209 taken 9900 times.
✗ Branch 208 → 549 not taken.
✗ Branch 209 → 210 not taken.
✓ Branch 209 → 211 taken 9900 times.
|
34728 | assert(data.isOrdinaryCall() || data.thisType.is(TY_STRUCT)); |
| 189 | } | ||
| 190 | |||
| 191 |
2/2✓ Branch 212 → 213 taken 65198 times.
✓ Branch 212 → 284 taken 118 times.
|
65316 | if (!data.isFctPtrCall()) { |
| 192 | // Check if we were able to find a function | ||
| 193 |
2/2✓ Branch 213 → 214 taken 12 times.
✓ Branch 213 → 251 taken 65186 times.
|
65198 | if (!callee) { |
| 194 | // Build error message | ||
| 195 |
6/10✓ Branch 215 → 216 taken 2 times.
✓ Branch 215 → 219 taken 10 times.
✓ Branch 218 → 221 taken 2 times.
✗ Branch 218 → 476 not taken.
✓ Branch 220 → 221 taken 10 times.
✗ Branch 220 → 476 not taken.
✓ Branch 221 → 222 taken 2 times.
✓ Branch 221 → 224 taken 10 times.
✗ Branch 476 → 477 not taken.
✗ Branch 476 → 479 not taken.
|
14 | const std::string functionName = data.isCtorCall() ? CTOR_FUNCTION_NAME : node->functionNameFragments.back(); |
| 196 | 12 | ParamList errArgTypes; | |
| 197 |
1/2✓ Branch 225 → 226 taken 12 times.
✗ Branch 225 → 496 not taken.
|
12 | errArgTypes.reserve(args.size()); |
| 198 |
5/8✓ Branch 226 → 227 taken 12 times.
✗ Branch 226 → 482 not taken.
✓ Branch 227 → 228 taken 12 times.
✗ Branch 227 → 482 not taken.
✓ Branch 228 → 229 taken 12 times.
✗ Branch 228 → 482 not taken.
✓ Branch 234 → 230 taken 7 times.
✓ Branch 234 → 235 taken 12 times.
|
19 | for (const auto &type : args | std::views::keys) |
| 199 |
1/2✓ Branch 231 → 232 taken 7 times.
✗ Branch 231 → 481 not taken.
|
7 | errArgTypes.push_back({type, false}); |
| 200 |
2/4✓ Branch 236 → 237 taken 12 times.
✗ Branch 236 → 483 not taken.
✓ Branch 237 → 238 taken 12 times.
✗ Branch 237 → 483 not taken.
|
12 | const std::string signature = Function::getSignature(functionName, thisType, QualType(TY_DYN), errArgTypes, {}, false); |
| 201 | // Throw error | ||
| 202 |
5/10✓ Branch 239 → 240 taken 12 times.
✗ Branch 239 → 491 not taken.
✓ Branch 240 → 241 taken 12 times.
✗ Branch 240 → 489 not taken.
✓ Branch 241 → 242 taken 12 times.
✗ Branch 241 → 487 not taken.
✓ Branch 244 → 245 taken 12 times.
✗ Branch 244 → 493 not taken.
✓ Branch 245 → 246 taken 12 times.
✗ Branch 245 → 493 not taken.
|
12 | SOFT_ERROR_ER(node, REFERENCED_UNDEFINED_FUNCTION, "Function/procedure '" + signature + "' could not be found") |
| 203 | 12 | } | |
| 204 | |||
| 205 | // Check if we need to request a re-visit, because the function body was not type-checked yet | ||
| 206 |
1/2✓ Branch 251 → 252 taken 65186 times.
✗ Branch 251 → 549 not taken.
|
65186 | requestRevisitIfRequired(callee); |
| 207 | |||
| 208 | // Get function entry from function object | ||
| 209 | 65186 | SymbolTableEntry *functionEntry = callee->entry; | |
| 210 | |||
| 211 | // Check if the called function has sufficient visibility | ||
| 212 |
1/2✓ Branch 252 → 253 taken 65186 times.
✗ Branch 252 → 549 not taken.
|
65186 | isImported = calleeParentScope->isImportedBy(rootScope); |
| 213 |
8/10✓ Branch 253 → 254 taken 27594 times.
✓ Branch 253 → 258 taken 37592 times.
✓ Branch 254 → 255 taken 27594 times.
✗ Branch 254 → 549 not taken.
✓ Branch 255 → 256 taken 27594 times.
✗ Branch 255 → 549 not taken.
✓ Branch 256 → 257 taken 2 times.
✓ Branch 256 → 258 taken 27592 times.
✓ Branch 259 → 260 taken 2 times.
✓ Branch 259 → 284 taken 65184 times.
|
65186 | if (isImported && !functionEntry->getQualType().isPublic()) { |
| 214 |
1/2✓ Branch 260 → 261 taken 2 times.
✗ Branch 260 → 517 not taken.
|
2 | const QualType functionEntryType = functionEntry->getQualType(); |
| 215 |
1/2✓ Branch 261 → 262 taken 2 times.
✗ Branch 261 → 517 not taken.
|
2 | const std::string signature = callee->getSignature(); |
| 216 |
2/4✓ Branch 262 → 263 taken 2 times.
✗ Branch 262 → 515 not taken.
✓ Branch 263 → 264 taken 2 times.
✗ Branch 263 → 273 not taken.
|
2 | if (functionEntryType.is(TY_FUNCTION)) |
| 217 |
5/10✓ Branch 264 → 265 taken 2 times.
✗ Branch 264 → 505 not taken.
✓ Branch 265 → 266 taken 2 times.
✗ Branch 265 → 503 not taken.
✓ Branch 266 → 267 taken 2 times.
✗ Branch 266 → 501 not taken.
✓ Branch 269 → 270 taken 2 times.
✗ Branch 269 → 507 not taken.
✓ Branch 270 → 271 taken 2 times.
✗ Branch 270 → 507 not taken.
|
4 | SOFT_ERROR_ER(node, INSUFFICIENT_VISIBILITY, "Function '" + signature + "' has insufficient visibility") |
| 218 | else | ||
| 219 | ✗ | SOFT_ERROR_ER(node, INSUFFICIENT_VISIBILITY, "Procedure '" + signature + "' has insufficient visibility") | |
| 220 | 2 | } | |
| 221 | } | ||
| 222 | |||
| 223 | // Generate arg infos | ||
| 224 |
2/2✓ Branch 284 → 285 taken 48402 times.
✓ Branch 284 → 327 taken 16900 times.
|
65302 | if (node->hasArgs) { |
| 225 | 48402 | QualTypeList paramTypes; | |
| 226 |
2/2✓ Branch 286 → 287 taken 92 times.
✓ Branch 286 → 293 taken 48310 times.
|
48402 | if (data.isFctPtrCall()) { |
| 227 |
2/4✓ Branch 287 → 288 taken 92 times.
✗ Branch 287 → 519 not taken.
✓ Branch 288 → 289 taken 92 times.
✗ Branch 288 → 519 not taken.
|
92 | const QualType &functionType = firstFragEntry->getQualType().getBase(); |
| 228 |
1/2✓ Branch 289 → 290 taken 92 times.
✗ Branch 289 → 518 not taken.
|
92 | paramTypes = functionType.getFunctionParamTypes(); |
| 229 | } else { | ||
| 230 |
1/2✗ Branch 293 → 294 not taken.
✓ Branch 293 → 295 taken 48310 times.
|
48310 | assert(callee != nullptr); |
| 231 |
1/2✓ Branch 295 → 296 taken 48310 times.
✗ Branch 295 → 520 not taken.
|
48310 | paramTypes = callee->getParamTypes(); |
| 232 | } | ||
| 233 | |||
| 234 | 48402 | node->argLst->argInfos.clear(); | |
| 235 |
2/2✓ Branch 320 → 301 taken 76656 times.
✓ Branch 320 → 321 taken 48402 times.
|
125058 | for (size_t argIdx = 0; argIdx < args.size(); argIdx++) { |
| 236 |
1/2✓ Branch 301 → 302 taken 76656 times.
✗ Branch 301 → 522 not taken.
|
76656 | const QualType &expectedType = paramTypes.at(argIdx); |
| 237 |
1/2✓ Branch 302 → 303 taken 76656 times.
✗ Branch 302 → 522 not taken.
|
76656 | const auto &[actualType, _] = args.at(argIdx); |
| 238 | |||
| 239 | 76656 | Function *copyCtor = nullptr; | |
| 240 |
11/14✓ Branch 305 → 306 taken 76656 times.
✗ Branch 305 → 522 not taken.
✓ Branch 306 → 307 taken 1251 times.
✓ Branch 306 → 312 taken 75405 times.
✓ Branch 307 → 308 taken 1251 times.
✗ Branch 307 → 522 not taken.
✓ Branch 308 → 309 taken 1247 times.
✓ Branch 308 → 312 taken 4 times.
✓ Branch 309 → 310 taken 1247 times.
✗ Branch 309 → 522 not taken.
✓ Branch 310 → 311 taken 16 times.
✓ Branch 310 → 312 taken 1231 times.
✓ Branch 313 → 314 taken 16 times.
✓ Branch 313 → 317 taken 76640 times.
|
76656 | if (expectedType.is(TY_STRUCT) && actualType.is(TY_STRUCT) && !actualType.isTriviallyCopyable(node)) { |
| 241 |
1/2✓ Branch 314 → 315 taken 16 times.
✗ Branch 314 → 522 not taken.
|
16 | copyCtor = matchCopyCtor(actualType, node); |
| 242 | // Insert anonymous symbol to track the dtor call of the copy | ||
| 243 |
1/2✓ Branch 315 → 316 taken 16 times.
✗ Branch 315 → 522 not taken.
|
16 | ExprNode *argNode = node->argLst->args.at(argIdx); |
| 244 |
1/2✓ Branch 316 → 317 taken 16 times.
✗ Branch 316 → 522 not taken.
|
16 | currentScope->symbolTable.insertAnonymous(actualType, argNode, SIZE_MAX); |
| 245 | } | ||
| 246 | |||
| 247 |
1/2✓ Branch 317 → 318 taken 76656 times.
✗ Branch 317 → 521 not taken.
|
76656 | node->argLst->argInfos.push_back(ArgLstNode::ArgInfo{copyCtor}); |
| 248 | } | ||
| 249 |
1/2✗ Branch 323 → 324 not taken.
✓ Branch 323 → 325 taken 48402 times.
|
48402 | assert(node->argLst->argInfos.size() == node->argLst->args.size()); |
| 250 | 48402 | } | |
| 251 | |||
| 252 | // Retrieve return type | ||
| 253 |
6/10✓ Branch 328 → 329 taken 118 times.
✓ Branch 328 → 333 taken 65184 times.
✓ Branch 329 → 330 taken 118 times.
✗ Branch 329 → 525 not taken.
✓ Branch 330 → 331 taken 118 times.
✗ Branch 330 → 525 not taken.
✓ Branch 331 → 332 taken 118 times.
✗ Branch 331 → 525 not taken.
✓ Branch 333 → 334 taken 65184 times.
✗ Branch 333 → 525 not taken.
|
130486 | const bool isFct = data.isFctPtrCall() ? firstFragEntry->getQualType().getBase().is(TY_FUNCTION) : callee->isFunction(); |
| 254 | 65302 | QualType returnType; | |
| 255 |
2/2✓ Branch 338 → 339 taken 118 times.
✓ Branch 338 → 346 taken 65184 times.
|
65302 | if (data.isFctPtrCall()) { |
| 256 |
6/10✓ Branch 339 → 340 taken 40 times.
✓ Branch 339 → 344 taken 78 times.
✓ Branch 340 → 341 taken 40 times.
✗ Branch 340 → 526 not taken.
✓ Branch 341 → 342 taken 40 times.
✗ Branch 341 → 526 not taken.
✓ Branch 342 → 343 taken 40 times.
✗ Branch 342 → 526 not taken.
✓ Branch 344 → 345 taken 78 times.
✗ Branch 344 → 526 not taken.
|
118 | returnType = isFct ? firstFragEntry->getQualType().getBase().getFunctionReturnType() : QualType(TY_BOOL); |
| 257 |
2/2✓ Branch 347 → 348 taken 9898 times.
✓ Branch 347 → 349 taken 55286 times.
|
65184 | } else if (data.isCtorCall()) { |
| 258 | 9898 | returnType = thisType; | |
| 259 |
3/4✓ Branch 349 → 350 taken 55286 times.
✗ Branch 349 → 549 not taken.
✓ Branch 352 → 353 taken 14260 times.
✓ Branch 352 → 355 taken 41026 times.
|
110572 | } else if (callee->isProcedure()) { |
| 260 |
1/2✓ Branch 353 → 354 taken 14260 times.
✗ Branch 353 → 528 not taken.
|
14260 | returnType = QualType(TY_DYN); |
| 261 | } else { | ||
| 262 | 41026 | returnType = callee->returnType; | |
| 263 | } | ||
| 264 | |||
| 265 |
1/2✓ Branch 356 → 357 taken 65302 times.
✗ Branch 356 → 549 not taken.
|
65302 | const QualType returnBaseType = returnType.getBase(); |
| 266 | |||
| 267 | // Make sure this source file knows about the return type | ||
| 268 |
3/4✓ Branch 357 → 358 taken 65302 times.
✗ Branch 357 → 549 not taken.
✓ Branch 358 → 359 taken 20227 times.
✓ Branch 358 → 362 taken 45075 times.
|
65302 | if (returnBaseType.is(TY_STRUCT)) |
| 269 |
2/4✓ Branch 359 → 360 taken 20227 times.
✗ Branch 359 → 529 not taken.
✓ Branch 360 → 361 taken 20227 times.
✗ Branch 360 → 529 not taken.
|
20227 | returnType = mapImportedScopeTypeToLocalType(returnBaseType.getBodyScope(), returnType); |
| 270 | |||
| 271 | // Add anonymous symbol to keep track of dtor call, if non-trivially destructible | ||
| 272 | 65302 | SymbolTableEntry *anonymousSymbol = nullptr; | |
| 273 |
8/10✓ Branch 362 → 363 taken 65302 times.
✗ Branch 362 → 549 not taken.
✓ Branch 363 → 364 taken 15889 times.
✓ Branch 363 → 367 taken 49413 times.
✓ Branch 364 → 365 taken 15889 times.
✗ Branch 364 → 549 not taken.
✓ Branch 365 → 366 taken 9964 times.
✓ Branch 365 → 367 taken 5925 times.
✓ Branch 368 → 369 taken 9964 times.
✓ Branch 368 → 371 taken 55338 times.
|
65302 | if (returnType.is(TY_STRUCT) && !returnType.isTriviallyDestructible(node)) |
| 274 |
1/2✓ Branch 369 → 370 taken 9964 times.
✗ Branch 369 → 549 not taken.
|
9964 | anonymousSymbol = currentScope->symbolTable.insertAnonymous(returnType, node); |
| 275 | |||
| 276 | // Remove public qualifier to not have public local variables | ||
| 277 | 65302 | returnType.getQualifiers().isPublic = false; | |
| 278 | |||
| 279 | // Check if the return value gets discarded | ||
| 280 |
7/8✓ Branch 372 → 373 taken 41066 times.
✓ Branch 372 → 376 taken 24236 times.
✓ Branch 373 → 374 taken 41066 times.
✗ Branch 373 → 549 not taken.
✓ Branch 374 → 375 taken 4111 times.
✓ Branch 374 → 376 taken 36955 times.
✓ Branch 377 → 378 taken 4111 times.
✓ Branch 377 → 420 taken 61191 times.
|
65302 | if (isFct && !node->hasReturnValueReceiver()) { |
| 281 | // Discarding a Result<T> is always a hard error when explicit error handling is enabled for this module, | ||
| 282 | // regardless of ignoreUnusedReturnValue (which only ever weakens the generic warning below). | ||
| 283 |
8/10✓ Branch 378 → 379 taken 3 times.
✓ Branch 378 → 383 taken 4108 times.
✓ Branch 379 → 380 taken 3 times.
✗ Branch 379 → 530 not taken.
✓ Branch 380 → 381 taken 3 times.
✗ Branch 380 → 530 not taken.
✓ Branch 381 → 382 taken 2 times.
✓ Branch 381 → 383 taken 1 time.
✓ Branch 384 → 385 taken 2 times.
✓ Branch 384 → 395 taken 4109 times.
|
4111 | if (sourceFile->explicitErrorHandling && returnType.removeReferenceWrapper().isResultObj()) |
| 284 |
4/8✓ Branch 387 → 388 taken 2 times.
✗ Branch 387 → 533 not taken.
✓ Branch 388 → 389 taken 2 times.
✗ Branch 388 → 531 not taken.
✓ Branch 391 → 392 taken 2 times.
✗ Branch 391 → 537 not taken.
✓ Branch 392 → 393 taken 2 times.
✗ Branch 392 → 537 not taken.
|
8 | SOFT_ERROR_ER(node, DISCARDED_RESULT_VALUE, |
| 285 | "A Result<T> returned from a call must be handled: bind it to a variable, propagate it with the " | ||
| 286 | "'!' operator, handle it with '.unwrapOr(...)'/'.unwrapOrElse(...)', or explicitly discard it by " | ||
| 287 | "binding it to a variable with a name starting with '_'") | ||
| 288 | |||
| 289 | // Check if we want to ignore the discarded return value | ||
| 290 | 4109 | bool ignoreUnusedReturnValue = false; | |
| 291 |
2/2✓ Branch 396 → 397 taken 4105 times.
✓ Branch 396 → 417 taken 4 times.
|
4109 | if (!data.isFctPtrCall()) { |
| 292 |
1/2✗ Branch 397 → 398 not taken.
✓ Branch 397 → 399 taken 4105 times.
|
4105 | assert(callee != nullptr); |
| 293 |
1/2✓ Branch 399 → 400 taken 4105 times.
✗ Branch 399 → 401 not taken.
|
4105 | auto fctDef = dynamic_cast<const FctDefNode *>(callee->declNode); |
| 294 |
12/18✓ Branch 402 → 403 taken 1257 times.
✓ Branch 402 → 410 taken 2848 times.
✓ Branch 403 → 404 taken 277 times.
✓ Branch 403 → 410 taken 980 times.
✓ Branch 406 → 407 taken 277 times.
✗ Branch 406 → 538 not taken.
✓ Branch 407 → 408 taken 277 times.
✗ Branch 407 → 538 not taken.
✓ Branch 408 → 409 taken 258 times.
✓ Branch 408 → 410 taken 19 times.
✓ Branch 411 → 412 taken 277 times.
✓ Branch 411 → 413 taken 3828 times.
✓ Branch 413 → 414 taken 277 times.
✓ Branch 413 → 416 taken 3828 times.
✗ Branch 538 → 539 not taken.
✗ Branch 538 → 540 not taken.
✗ Branch 542 → 543 not taken.
✗ Branch 542 → 545 not taken.
|
4659 | ignoreUnusedReturnValue = fctDef && fctDef->attrs && fctDef->attrs->attrLst->hasAttr(ATTR_IGNORE_UNUSED_RETURN_VALUE); |
| 295 | } | ||
| 296 | |||
| 297 |
2/2✓ Branch 417 → 418 taken 3851 times.
✓ Branch 417 → 420 taken 258 times.
|
4109 | if (!ignoreUnusedReturnValue) |
| 298 |
1/2✓ Branch 418 → 419 taken 3851 times.
✗ Branch 418 → 547 not taken.
|
3851 | warnings.emplace_back(node->codeLoc, UNUSED_RETURN_VALUE, "The return value of the function call is unused"); |
| 299 | } | ||
| 300 | |||
| 301 |
2/4✓ Branch 420 → 421 taken 65300 times.
✗ Branch 420 → 548 not taken.
✓ Branch 421 → 422 taken 65300 times.
✗ Branch 421 → 548 not taken.
|
130600 | return ExprResult{node->setEvaluatedSymbolType(returnType, manIdx), anonymousSymbol}; |
| 302 | } | ||
| 303 | |||
| 304 | 34733 | bool TypeChecker::visitOrdinaryFctCall(FctCallNode *node, std::string fqFunctionName) const { | |
| 305 |
1/2✓ Branch 2 → 3 taken 34733 times.
✗ Branch 2 → 112 not taken.
|
34733 | FctCallNode::FctCallData &data = node->data.at(manIdx); |
| 306 | 34733 | auto &[callType, isImported, templateTypes, thisType, args, callee, calleeParentScope, compTimeVal, hasCompTimeVal] = data; | |
| 307 | |||
| 308 | // Check if this is a well-known ctor/fct call | ||
| 309 |
2/2✓ Branch 4 → 5 taken 34571 times.
✓ Branch 4 → 7 taken 162 times.
|
34733 | if (node->functionNameFragments.size() == 1) { |
| 310 |
1/2✓ Branch 5 → 6 taken 34571 times.
✗ Branch 5 → 112 not taken.
|
34571 | ensureLoadedRuntimeForTypeName(fqFunctionName); |
| 311 |
1/2✓ Branch 6 → 7 taken 34571 times.
✗ Branch 6 → 112 not taken.
|
34571 | ensureLoadedRuntimeForFunctionName(fqFunctionName); |
| 312 | } | ||
| 313 | |||
| 314 | // Check if the type is generic (possible in case of ctor call) | ||
| 315 |
1/2✓ Branch 7 → 8 taken 34733 times.
✗ Branch 7 → 112 not taken.
|
34733 | const QualType *genericType = rootScope->lookupGenericTypeStrict(fqFunctionName); |
| 316 |
6/8✓ Branch 8 → 9 taken 1 time.
✓ Branch 8 → 12 taken 34732 times.
✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 112 not taken.
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 12 not taken.
✓ Branch 13 → 14 taken 1 time.
✓ Branch 13 → 19 taken 34732 times.
|
34733 | if (genericType && typeMapping.contains(fqFunctionName)) { |
| 317 |
1/2✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 112 not taken.
|
1 | const QualType &replacementType = typeMapping.at(fqFunctionName); |
| 318 |
2/4✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 112 not taken.
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 19 not taken.
|
1 | if (replacementType.is(TY_STRUCT)) |
| 319 |
2/4✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 112 not taken.
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 112 not taken.
|
1 | fqFunctionName = replacementType.getSubType(); |
| 320 | } | ||
| 321 | |||
| 322 | // Check if the exported name registry contains that function name | ||
| 323 |
1/2✓ Branch 19 → 20 taken 34733 times.
✗ Branch 19 → 112 not taken.
|
34733 | const NameRegistryEntry *functionRegistryEntry = sourceFile->getNameRegistryEntry(fqFunctionName); |
| 324 |
2/2✓ Branch 20 → 21 taken 3 times.
✓ Branch 20 → 28 taken 34730 times.
|
34733 | if (!functionRegistryEntry) { |
| 325 |
2/4✓ Branch 22 → 23 taken 3 times.
✗ Branch 22 → 92 not taken.
✓ Branch 23 → 24 taken 3 times.
✗ Branch 23 → 90 not taken.
|
3 | const std::string msg = "Function/procedure/struct '" + node->functionNameFragments.back() + "' could not be found"; |
| 326 |
1/2✓ Branch 25 → 26 taken 3 times.
✗ Branch 25 → 93 not taken.
|
3 | SOFT_ERROR_BOOL(node, REFERENCED_UNDEFINED_FUNCTION, msg) |
| 327 | 3 | } | |
| 328 | 34730 | const SymbolTableEntry *functionEntry = functionRegistryEntry->targetEntry; | |
| 329 | 34730 | calleeParentScope = functionRegistryEntry->targetScope; | |
| 330 | |||
| 331 | // Check if the target symbol is a struct -> this must be a constructor call | ||
| 332 |
1/2✓ Branch 29 → 30 taken 34730 times.
✗ Branch 29 → 112 not taken.
|
34730 | std::string functionName = node->functionNameFragments.back(); |
| 333 |
7/10✓ Branch 30 → 31 taken 34730 times.
✗ Branch 30 → 35 not taken.
✓ Branch 31 → 32 taken 34730 times.
✗ Branch 31 → 110 not taken.
✓ Branch 32 → 33 taken 34730 times.
✗ Branch 32 → 110 not taken.
✓ Branch 33 → 34 taken 9901 times.
✓ Branch 33 → 35 taken 24829 times.
✓ Branch 36 → 37 taken 9901 times.
✓ Branch 36 → 52 taken 24829 times.
|
34730 | if (functionEntry != nullptr && functionEntry->getQualType().is(TY_STRUCT)) { |
| 334 | 9901 | callType = FctCallNode::FctCallType::TYPE_CTOR; | |
| 335 |
1/2✓ Branch 37 → 38 taken 9901 times.
✗ Branch 37 → 110 not taken.
|
9901 | functionName = CTOR_FUNCTION_NAME; |
| 336 | |||
| 337 | 9901 | const NameRegistryEntry *structRegistryEntry = functionRegistryEntry; | |
| 338 | 9901 | const SymbolTableEntry *structEntry = functionEntry; | |
| 339 | |||
| 340 | // Substantiate potentially generic this struct | ||
| 341 |
2/4✓ Branch 38 → 39 taken 9901 times.
✗ Branch 38 → 110 not taken.
✓ Branch 39 → 40 taken 9901 times.
✗ Branch 39 → 110 not taken.
|
9901 | const Struct *thisStruct = structEntry->getQualType().getStruct(node, templateTypes); |
| 342 |
2/2✓ Branch 40 → 41 taken 1 time.
✓ Branch 40 → 49 taken 9900 times.
|
9901 | if (!thisStruct) { |
| 343 |
1/2✓ Branch 41 → 42 taken 1 time.
✗ Branch 41 → 103 not taken.
|
1 | const std::string signature = Struct::getSignature(structRegistryEntry->targetEntry->name, templateTypes); |
| 344 |
2/4✓ Branch 42 → 43 taken 1 time.
✗ Branch 42 → 98 not taken.
✓ Branch 43 → 44 taken 1 time.
✗ Branch 43 → 96 not taken.
|
1 | const std::string errorMsg = "Could not find struct candidate for struct '" + signature + "'. Do the template types match?"; |
| 345 |
1/2✓ Branch 45 → 46 taken 1 time.
✗ Branch 45 → 99 not taken.
|
1 | SOFT_ERROR_BOOL(node, UNKNOWN_DATATYPE, errorMsg) |
| 346 | 1 | } | |
| 347 | |||
| 348 | // Set the 'this' type of the function to the struct type | ||
| 349 |
2/4✓ Branch 49 → 50 taken 9900 times.
✗ Branch 49 → 104 not taken.
✓ Branch 50 → 51 taken 9900 times.
✗ Branch 50 → 104 not taken.
|
9900 | thisType = structEntry->getQualType().getWithBodyScope(thisStruct->scope); |
| 350 | 9900 | calleeParentScope = thisStruct->scope; | |
| 351 | } | ||
| 352 | |||
| 353 | // Attach the concrete template types to the 'this' type | ||
| 354 |
7/8✓ Branch 52 → 53 taken 34729 times.
✗ Branch 52 → 110 not taken.
✓ Branch 53 → 54 taken 9900 times.
✓ Branch 53 → 57 taken 24829 times.
✓ Branch 55 → 56 taken 2109 times.
✓ Branch 55 → 57 taken 7791 times.
✓ Branch 58 → 59 taken 2109 times.
✓ Branch 58 → 61 taken 32620 times.
|
34729 | if (!thisType.is(TY_DYN) && !templateTypes.empty()) |
| 355 |
1/2✓ Branch 59 → 60 taken 2109 times.
✗ Branch 59 → 105 not taken.
|
2109 | thisType = thisType.getWithTemplateTypes(templateTypes); |
| 356 | |||
| 357 | // Map local arg types to imported types | ||
| 358 |
5/8✓ Branch 61 → 62 taken 34729 times.
✗ Branch 61 → 107 not taken.
✓ Branch 62 → 63 taken 34729 times.
✗ Branch 62 → 107 not taken.
✓ Branch 63 → 64 taken 34729 times.
✗ Branch 63 → 107 not taken.
✓ Branch 69 → 65 taken 57453 times.
✓ Branch 69 → 70 taken 34729 times.
|
92182 | for (QualType &argType : args | std::views::keys) |
| 359 |
1/2✓ Branch 66 → 67 taken 57453 times.
✗ Branch 66 → 106 not taken.
|
57453 | argType = mapLocalTypeToImportedScopeType(calleeParentScope, argType); |
| 360 | |||
| 361 | // Map local template types to imported types | ||
| 362 |
2/2✓ Branch 84 → 72 taken 4640 times.
✓ Branch 84 → 85 taken 34729 times.
|
74098 | for (QualType &templateType : templateTypes) |
| 363 |
1/2✓ Branch 74 → 75 taken 4640 times.
✗ Branch 74 → 108 not taken.
|
4640 | templateType = mapLocalTypeToImportedScopeType(calleeParentScope, templateType); |
| 364 | |||
| 365 | // Retrieve function object | ||
| 366 | 34729 | Scope *matchScope = calleeParentScope; | |
| 367 |
2/2✓ Branch 85 → 86 taken 34728 times.
✓ Branch 85 → 110 taken 1 time.
|
34729 | callee = FunctionManager::match(matchScope, functionName, data.thisType, data.args, templateTypes, false, node); |
| 368 | |||
| 369 | 34728 | return true; | |
| 370 | 34730 | } | |
| 371 | |||
| 372 | 118 | bool TypeChecker::visitFctPtrCall(const FctCallNode *node, const QualType &functionType) const { | |
| 373 |
1/2✓ Branch 2 → 3 taken 118 times.
✗ Branch 2 → 75 not taken.
|
118 | const FctCallNode::FctCallData &data = node->data.at(manIdx); |
| 374 | 118 | const auto &[callType, isImported, templateTypes, thisType, args, callee, calleeParentScope, compTimeVal, hasCompTimeVal] = | |
| 375 | data; | ||
| 376 | |||
| 377 | // Check if the given argument types match the type | ||
| 378 |
1/2✓ Branch 3 → 4 taken 118 times.
✗ Branch 3 → 75 not taken.
|
118 | const QualTypeList expectedArgTypes = functionType.getFunctionParamTypes(); |
| 379 |
1/2✗ Branch 6 → 7 not taken.
✓ Branch 6 → 14 taken 118 times.
|
118 | if (args.size() != expectedArgTypes.size()) |
| 380 | ✗ | SOFT_ERROR_BOOL(node, REFERENCED_UNDEFINED_FUNCTION, "Expected and actual number of arguments do not match") | |
| 381 | |||
| 382 | // Create resolver function, that always returns a nullptr | ||
| 383 | 118 | TypeMatcher::ResolverFct resolverFct = [](const std::string &) { return nullptr; }; | |
| 384 | |||
| 385 |
2/2✓ Branch 41 → 16 taken 119 times.
✓ Branch 41 → 42 taken 118 times.
|
237 | for (size_t i = 0; i < args.size(); i++) { |
| 386 |
1/2✓ Branch 16 → 17 taken 119 times.
✗ Branch 16 → 71 not taken.
|
119 | const QualType &actualType = args.at(i).first; |
| 387 |
1/2✓ Branch 17 → 18 taken 119 times.
✗ Branch 17 → 71 not taken.
|
119 | const QualType &expectedType = expectedArgTypes.at(i); |
| 388 |
2/4✓ Branch 19 → 20 taken 119 times.
✗ Branch 19 → 68 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 34 taken 119 times.
|
119 | if (TypeMapping tm; !TypeMatcher::matchRequestedToCandidateType(expectedType, actualType, tm, resolverFct, false)) |
| 389 |
1/16✗ Branch 21 → 22 not taken.
✗ Branch 21 → 66 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 61 not taken.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 59 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 57 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 55 not taken.
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 53 not taken.
✗ Branch 27 → 28 not taken.
✗ Branch 27 → 53 not taken.
✓ Branch 36 → 37 taken 119 times.
✗ Branch 36 → 39 not taken.
|
119 | SOFT_ERROR_BOOL(node->argLst->args.at(i), REFERENCED_UNDEFINED_FUNCTION, |
| 390 | "Expected " + expectedType.getName(false) + " but got " + actualType.getName(false)) | ||
| 391 | } | ||
| 392 | 118 | return true; | |
| 393 | 118 | } | |
| 394 | |||
| 395 | 30472 | bool TypeChecker::visitMethodCall(FctCallNode *node, Scope *structScope) const { | |
| 396 | 30472 | FctCallNode::FctCallData &data = node->data.at(manIdx); | |
| 397 | 30472 | auto &[callType, isImported, templateTypes, thisType, args, callee, calleeParentScope, compTimeVal, hasCompTimeVal] = data; | |
| 398 | |||
| 399 | // Traverse through structs - the first fragment is already looked up and the last one is the method name | ||
| 400 |
2/2✓ Branch 43 → 4 taken 7056 times.
✓ Branch 43 → 44 taken 30470 times.
|
37526 | for (size_t i = 1; i < node->functionNameFragments.size() - 1; i++) { |
| 401 |
1/2✓ Branch 4 → 5 taken 7056 times.
✗ Branch 4 → 104 not taken.
|
7056 | const std::string &identifier = node->functionNameFragments.at(i); |
| 402 | |||
| 403 | // Retrieve field entry, also looking through composed fields | ||
| 404 | 7056 | std::vector<size_t> indexPath; | |
| 405 |
1/2✓ Branch 5 → 6 taken 7056 times.
✗ Branch 5 → 102 not taken.
|
7056 | SymbolTableEntry *fieldEntry = structScope->symbolTable.lookupInComposedFields(identifier, indexPath); |
| 406 |
2/2✓ Branch 6 → 7 taken 1 time.
✓ Branch 6 → 21 taken 7055 times.
|
7056 | if (!fieldEntry) { |
| 407 |
1/2✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 92 not taken.
|
1 | std::stringstream errorMsg; |
| 408 |
1/2✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 90 not taken.
|
1 | errorMsg << "The type '"; |
| 409 |
3/6✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 85 not taken.
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 85 not taken.
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 83 not taken.
|
1 | errorMsg << thisType.getBase().getName(false, true); |
| 410 |
3/6✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 90 not taken.
✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 90 not taken.
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 90 not taken.
|
1 | errorMsg << "' does not have a member with the name '" << identifier << "'"; |
| 411 |
2/4✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 89 not taken.
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 87 not taken.
|
1 | SOFT_ERROR_BOOL(node, ACCESS_TO_NON_EXISTING_MEMBER, errorMsg.str()) |
| 412 | 1 | } | |
| 413 |
5/8✓ Branch 21 → 22 taken 7055 times.
✗ Branch 21 → 94 not taken.
✓ Branch 22 → 23 taken 7055 times.
✗ Branch 22 → 94 not taken.
✓ Branch 23 → 24 taken 7055 times.
✗ Branch 23 → 93 not taken.
✓ Branch 24 → 25 taken 1 time.
✓ Branch 24 → 31 taken 7054 times.
|
7055 | if (!fieldEntry->getQualType().getBase().isOneOf({TY_STRUCT, TY_INTERFACE})) |
| 414 |
3/6✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 99 not taken.
✓ Branch 26 → 27 taken 1 time.
✗ Branch 26 → 97 not taken.
✓ Branch 27 → 28 taken 1 time.
✗ Branch 27 → 95 not taken.
|
1 | SOFT_ERROR_BOOL(node, INVALID_MEMBER_ACCESS, |
| 415 | "Cannot call a method on '" + identifier + "', since it is no struct or interface") | ||
| 416 | 7054 | fieldEntry->used = true; | |
| 417 | |||
| 418 | // Get struct type and scope | ||
| 419 |
1/2✓ Branch 31 → 32 taken 7054 times.
✗ Branch 31 → 102 not taken.
|
7054 | thisType = fieldEntry->getQualType(); |
| 420 |
2/4✓ Branch 32 → 33 taken 7054 times.
✗ Branch 32 → 101 not taken.
✓ Branch 33 → 34 taken 7054 times.
✗ Branch 33 → 101 not taken.
|
7054 | structScope = thisType.getBase().getBodyScope(); |
| 421 |
1/2✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 7054 times.
|
7054 | assert(structScope != nullptr); |
| 422 |
2/2✓ Branch 38 → 39 taken 7054 times.
✓ Branch 38 → 41 taken 2 times.
|
7056 | } |
| 423 | |||
| 424 |
1/2✗ Branch 45 → 46 not taken.
✓ Branch 45 → 53 taken 30470 times.
|
30470 | if (thisType.is(TY_INTERFACE)) |
| 425 | ✗ | SOFT_ERROR_BOOL(node, INVALID_MEMBER_ACCESS, "Cannot call a method on an interface") | |
| 426 | |||
| 427 | // Map local arg types to imported types | ||
| 428 | 30470 | Scope *matchScope = calleeParentScope = structScope; | |
| 429 |
5/8✓ Branch 53 → 54 taken 30470 times.
✗ Branch 53 → 112 not taken.
✓ Branch 54 → 55 taken 30470 times.
✗ Branch 54 → 112 not taken.
✓ Branch 55 → 56 taken 30470 times.
✗ Branch 55 → 112 not taken.
✓ Branch 61 → 57 taken 19092 times.
✓ Branch 61 → 62 taken 30470 times.
|
49562 | for (QualType &argType : args | std::views::keys) |
| 430 |
1/2✓ Branch 58 → 59 taken 19092 times.
✗ Branch 58 → 111 not taken.
|
19092 | argType = mapLocalTypeToImportedScopeType(calleeParentScope, argType); |
| 431 | |||
| 432 | // Map local template types to imported types | ||
| 433 |
2/2✓ Branch 76 → 64 taken 350 times.
✓ Branch 76 → 77 taken 30470 times.
|
61290 | for (QualType &templateType : templateTypes) |
| 434 |
1/2✓ Branch 66 → 67 taken 350 times.
✗ Branch 66 → 113 not taken.
|
350 | templateType = mapLocalTypeToImportedScopeType(calleeParentScope, templateType); |
| 435 | |||
| 436 | // 'this' type | ||
| 437 |
1/2✓ Branch 77 → 78 taken 30470 times.
✗ Branch 77 → 115 not taken.
|
30470 | thisType = thisType.autoDeReference(); |
| 438 |
1/2✓ Branch 78 → 79 taken 30470 times.
✗ Branch 78 → 116 not taken.
|
30470 | thisType = mapLocalTypeToImportedScopeType(calleeParentScope, thisType); |
| 439 | |||
| 440 | // Retrieve function object | ||
| 441 | 30470 | const std::string &functionName = node->functionNameFragments.back(); | |
| 442 | 30470 | callee = FunctionManager::match(matchScope, functionName, thisType, args, templateTypes, false, node); | |
| 443 | |||
| 444 | 30470 | return true; | |
| 445 | } | ||
| 446 | |||
| 447 | 335 | std::any TypeChecker::visitArrayInitialization(ArrayInitializationNode *node) { | |
| 448 |
5/6✓ Branch 2 → 3 taken 334 times.
✓ Branch 2 → 5 taken 1 time.
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 334 times.
✓ Branch 7 → 8 taken 1 time.
✓ Branch 7 → 18 taken 334 times.
|
335 | if (!node->itemLst || node->itemLst->args.empty()) |
| 449 |
4/8✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 76 not taken.
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 74 not taken.
✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 80 not taken.
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 80 not taken.
|
4 | SOFT_ERROR_ER(node, ARRAY_SIZE_INVALID, "Array initializers must at least contain one value"); |
| 450 | 334 | node->actualSize = node->itemLst->args.size(); | |
| 451 | |||
| 452 |
1/2✓ Branch 19 → 20 taken 334 times.
✗ Branch 19 → 105 not taken.
|
334 | QualType actualItemType(TY_DYN); |
| 453 | // Check if all values have the same type | ||
| 454 |
2/2✓ Branch 63 → 22 taken 1815 times.
✓ Branch 63 → 64 taken 333 times.
|
2482 | for (ExprNode *arg : node->itemLst->args) { |
| 455 |
2/4✓ Branch 24 → 25 taken 1815 times.
✗ Branch 24 → 83 not taken.
✓ Branch 25 → 26 taken 1815 times.
✗ Branch 25 → 81 not taken.
|
1815 | const QualType itemType = std::any_cast<ExprResult>(visit(arg)).type; |
| 456 |
2/8✓ Branch 27 → 28 taken 1815 times.
✗ Branch 27 → 102 not taken.
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 33 taken 1815 times.
✗ Branch 29 → 30 not taken.
✗ Branch 29 → 85 not taken.
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 85 not taken.
|
1815 | HANDLE_UNRESOLVED_TYPE_ER(itemType) |
| 457 |
3/4✓ Branch 33 → 34 taken 1815 times.
✗ Branch 33 → 102 not taken.
✓ Branch 34 → 35 taken 334 times.
✓ Branch 34 → 36 taken 1481 times.
|
1815 | if (actualItemType.is(TY_DYN)) // Perform type inference |
| 458 | 334 | actualItemType = itemType; | |
| 459 |
3/4✓ Branch 36 → 37 taken 1481 times.
✗ Branch 36 → 102 not taken.
✓ Branch 37 → 38 taken 1 time.
✓ Branch 37 → 53 taken 1480 times.
|
1481 | else if (itemType != actualItemType) // Check if types are matching |
| 460 |
8/16✓ Branch 38 → 39 taken 1 time.
✗ Branch 38 → 99 not taken.
✓ Branch 39 → 40 taken 1 time.
✗ Branch 39 → 94 not taken.
✓ Branch 40 → 41 taken 1 time.
✗ Branch 40 → 92 not taken.
✓ Branch 41 → 42 taken 1 time.
✗ Branch 41 → 90 not taken.
✓ Branch 42 → 43 taken 1 time.
✗ Branch 42 → 88 not taken.
✓ Branch 43 → 44 taken 1 time.
✗ Branch 43 → 86 not taken.
✓ Branch 49 → 50 taken 1 time.
✗ Branch 49 → 101 not taken.
✓ Branch 50 → 51 taken 1 time.
✗ Branch 50 → 101 not taken.
|
2 | SOFT_ERROR_ER(arg, ARRAY_ITEM_TYPE_NOT_MATCHING, |
| 461 | "All provided values have to be of the same data type. You provided " + actualItemType.getName(false) + | ||
| 462 | " and " + itemType.getName(false)) | ||
| 463 | } | ||
| 464 |
2/4✓ Branch 64 → 65 taken 333 times.
✗ Branch 64 → 105 not taken.
✗ Branch 65 → 66 not taken.
✓ Branch 65 → 67 taken 333 times.
|
333 | assert(!actualItemType.is(TY_DYN)); |
| 465 | |||
| 466 |
1/2✓ Branch 67 → 68 taken 333 times.
✗ Branch 67 → 105 not taken.
|
333 | const QualType arrayType = actualItemType.toArr(node, node->actualSize, true); |
| 467 |
2/4✓ Branch 68 → 69 taken 333 times.
✗ Branch 68 → 104 not taken.
✓ Branch 69 → 70 taken 333 times.
✗ Branch 69 → 104 not taken.
|
666 | return ExprResult{node->setEvaluatedSymbolType(arrayType, manIdx)}; |
| 468 | } | ||
| 469 | |||
| 470 | 1313 | std::any TypeChecker::visitStructInstantiation(StructInstantiationNode *node) { | |
| 471 | // Retrieve struct name | ||
| 472 |
1/2✓ Branch 2 → 3 taken 1313 times.
✗ Branch 2 → 306 not taken.
|
1313 | const auto [aliasedEntry, isAlias] = rootScope->symbolTable.lookupWithAliasResolution(node->fqStructName); |
| 473 |
5/8✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 9 taken 1312 times.
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 306 not taken.
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 306 not taken.
✓ Branch 10 → 11 taken 1313 times.
✗ Branch 10 → 306 not taken.
|
1313 | std::string structName = isAlias ? aliasedEntry->getQualType().getSubType() : node->fqStructName; |
| 474 | |||
| 475 | // Check if the struct type is generic | ||
| 476 |
1/2✓ Branch 11 → 12 taken 1313 times.
✗ Branch 11 → 304 not taken.
|
1313 | const QualType *genericType = rootScope->lookupGenericTypeStrict(structName); |
| 477 |
6/8✓ Branch 12 → 13 taken 2 times.
✓ Branch 12 → 16 taken 1311 times.
✓ Branch 13 → 14 taken 2 times.
✗ Branch 13 → 304 not taken.
✓ Branch 14 → 15 taken 2 times.
✗ Branch 14 → 16 not taken.
✓ Branch 17 → 18 taken 2 times.
✓ Branch 17 → 23 taken 1311 times.
|
1313 | if (genericType && typeMapping.contains(structName)) { |
| 478 |
1/2✓ Branch 18 → 19 taken 2 times.
✗ Branch 18 → 304 not taken.
|
2 | const QualType &replacementType = typeMapping.at(structName); |
| 479 |
2/4✓ Branch 19 → 20 taken 2 times.
✗ Branch 19 → 304 not taken.
✓ Branch 20 → 21 taken 2 times.
✗ Branch 20 → 23 not taken.
|
2 | if (replacementType.is(TY_STRUCT)) |
| 480 |
2/4✓ Branch 21 → 22 taken 2 times.
✗ Branch 21 → 304 not taken.
✓ Branch 22 → 23 taken 2 times.
✗ Branch 22 → 304 not taken.
|
2 | structName = replacementType.getSubType(); |
| 481 | } | ||
| 482 | |||
| 483 | // Retrieve struct | ||
| 484 |
1/2✓ Branch 23 → 24 taken 1313 times.
✗ Branch 23 → 304 not taken.
|
1313 | const NameRegistryEntry *registryEntry = sourceFile->getNameRegistryEntry(structName); |
| 485 |
2/2✓ Branch 24 → 25 taken 1 time.
✓ Branch 24 → 34 taken 1312 times.
|
1313 | if (!registryEntry) |
| 486 |
5/10✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 233 not taken.
✓ Branch 26 → 27 taken 1 time.
✗ Branch 26 → 231 not taken.
✓ Branch 27 → 28 taken 1 time.
✗ Branch 27 → 229 not taken.
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 235 not taken.
✓ Branch 31 → 32 taken 1 time.
✗ Branch 31 → 235 not taken.
|
2 | SOFT_ERROR_ER(node, REFERENCED_UNDEFINED_STRUCT, "Cannot find struct '" + structName + "'") |
| 487 |
2/4✓ Branch 34 → 35 taken 1312 times.
✗ Branch 34 → 37 not taken.
✓ Branch 35 → 36 taken 1312 times.
✗ Branch 35 → 37 not taken.
|
1312 | assert(registryEntry->targetEntry != nullptr && registryEntry->targetScope != nullptr); |
| 488 | 1312 | SymbolTableEntry *structEntry = registryEntry->targetEntry; | |
| 489 | |||
| 490 | // Check visibility | ||
| 491 |
9/12✓ Branch 38 → 39 taken 1312 times.
✗ Branch 38 → 304 not taken.
✓ Branch 39 → 40 taken 1312 times.
✗ Branch 39 → 304 not taken.
✓ Branch 40 → 41 taken 81 times.
✓ Branch 40 → 44 taken 1231 times.
✓ Branch 41 → 42 taken 81 times.
✗ Branch 41 → 304 not taken.
✓ Branch 42 → 43 taken 1 time.
✓ Branch 42 → 44 taken 80 times.
✓ Branch 45 → 46 taken 1 time.
✓ Branch 45 → 55 taken 1311 times.
|
1312 | if (!structEntry->getQualType().isPublic() && structEntry->scope->isImportedBy(currentScope)) |
| 492 |
5/10✓ Branch 46 → 47 taken 1 time.
✗ Branch 46 → 240 not taken.
✓ Branch 47 → 48 taken 1 time.
✗ Branch 47 → 238 not taken.
✓ Branch 48 → 49 taken 1 time.
✗ Branch 48 → 236 not taken.
✓ Branch 51 → 52 taken 1 time.
✗ Branch 51 → 242 not taken.
✓ Branch 52 → 53 taken 1 time.
✗ Branch 52 → 242 not taken.
|
2 | SOFT_ERROR_ER(node, INSUFFICIENT_VISIBILITY, "Struct '" + structName + "' has insufficient visibility") |
| 493 | |||
| 494 | // Get struct type | ||
| 495 |
1/2✓ Branch 55 → 56 taken 1311 times.
✗ Branch 55 → 304 not taken.
|
1311 | QualType structType = structEntry->getQualType(); |
| 496 | |||
| 497 | // Get the concrete template types | ||
| 498 | 1311 | QualTypeList concreteTemplateTypes; | |
| 499 |
2/2✓ Branch 56 → 57 taken 1 time.
✓ Branch 56 → 76 taken 1310 times.
|
1311 | if (isAlias) { |
| 500 | // Retrieve concrete template types from type alias | ||
| 501 |
3/6✓ Branch 57 → 58 taken 1 time.
✗ Branch 57 → 302 not taken.
✓ Branch 58 → 59 taken 1 time.
✗ Branch 58 → 302 not taken.
✓ Branch 59 → 60 taken 1 time.
✗ Branch 59 → 302 not taken.
|
1 | concreteTemplateTypes = aliasedEntry->getQualType().getTemplateTypes(); |
| 502 | // Check if the aliased type specified template types and the struct instantiation does | ||
| 503 |
3/6✓ Branch 61 → 62 taken 1 time.
✗ Branch 61 → 64 not taken.
✗ Branch 62 → 63 not taken.
✓ Branch 62 → 64 taken 1 time.
✗ Branch 65 → 66 not taken.
✓ Branch 65 → 76 taken 1 time.
|
1 | if (!concreteTemplateTypes.empty() && node->templateTypeLst) |
| 504 | ✗ | SOFT_ERROR_ER(node->templateTypeLst, ALIAS_WITH_TEMPLATE_LIST, "The aliased type already has a template list") | |
| 505 | } | ||
| 506 | |||
| 507 |
2/2✓ Branch 76 → 77 taken 14 times.
✓ Branch 76 → 117 taken 1297 times.
|
1311 | if (node->templateTypeLst) { |
| 508 |
1/2✓ Branch 78 → 79 taken 14 times.
✗ Branch 78 → 302 not taken.
|
14 | concreteTemplateTypes.reserve(node->templateTypeLst->dataTypes.size()); |
| 509 |
2/2✓ Branch 115 → 81 taken 18 times.
✓ Branch 115 → 116 taken 14 times.
|
46 | for (DataTypeNode *dataType : node->templateTypeLst->dataTypes) { |
| 510 |
2/4✓ Branch 83 → 84 taken 18 times.
✗ Branch 83 → 252 not taken.
✓ Branch 84 → 85 taken 18 times.
✗ Branch 84 → 250 not taken.
|
18 | auto concreteType = std::any_cast<QualType>(visit(dataType)); |
| 511 |
2/8✓ Branch 86 → 87 taken 18 times.
✗ Branch 86 → 261 not taken.
✗ Branch 87 → 88 not taken.
✓ Branch 87 → 92 taken 18 times.
✗ Branch 88 → 89 not taken.
✗ Branch 88 → 253 not taken.
✗ Branch 89 → 90 not taken.
✗ Branch 89 → 253 not taken.
|
18 | HANDLE_UNRESOLVED_TYPE_ER(concreteType) |
| 512 | // Check if generic type | ||
| 513 |
2/4✓ Branch 92 → 93 taken 18 times.
✗ Branch 92 → 261 not taken.
✗ Branch 93 → 94 not taken.
✓ Branch 93 → 104 taken 18 times.
|
18 | if (concreteType.is(TY_GENERIC)) |
| 514 | ✗ | SOFT_ERROR_ER(dataType, EXPECTED_NON_GENERIC_TYPE, "Struct instantiations may only take concrete template types") | |
| 515 |
1/2✓ Branch 104 → 105 taken 18 times.
✗ Branch 104 → 261 not taken.
|
18 | concreteTemplateTypes.push_back(concreteType); |
| 516 | } | ||
| 517 | } | ||
| 518 | |||
| 519 | // Get the struct instance | ||
| 520 |
2/4✓ Branch 117 → 118 taken 1311 times.
✗ Branch 117 → 302 not taken.
✓ Branch 118 → 119 taken 1311 times.
✗ Branch 118 → 302 not taken.
|
1311 | Struct *spiceStruct = node->instantiatedStructs.at(manIdx) = structType.getStructAndAdjustType(node, concreteTemplateTypes); |
| 521 |
2/2✓ Branch 119 → 120 taken 1 time.
✓ Branch 119 → 131 taken 1310 times.
|
1311 | if (!spiceStruct) |
| 522 |
6/12✓ Branch 120 → 121 taken 1 time.
✗ Branch 120 → 269 not taken.
✓ Branch 121 → 122 taken 1 time.
✗ Branch 121 → 267 not taken.
✓ Branch 122 → 123 taken 1 time.
✗ Branch 122 → 265 not taken.
✓ Branch 123 → 124 taken 1 time.
✗ Branch 123 → 263 not taken.
✓ Branch 127 → 128 taken 1 time.
✗ Branch 127 → 272 not taken.
✓ Branch 128 → 129 taken 1 time.
✗ Branch 128 → 272 not taken.
|
2 | SOFT_ERROR_ER(node, REFERENCED_UNDEFINED_STRUCT, |
| 523 | "Struct '" + Struct::getSignature(structName, concreteTemplateTypes) + "' could not be found") | ||
| 524 | |||
| 525 | // Struct instantiation for an inheriting struct is forbidden, because the vtable needs to be initialized and this is done in | ||
| 526 | // the ctor of the struct, which is never called in case of struct instantiation | ||
| 527 |
2/2✓ Branch 132 → 133 taken 1 time.
✓ Branch 132 → 143 taken 1309 times.
|
1310 | if (!spiceStruct->interfaceTypes.empty()) |
| 528 |
4/8✓ Branch 135 → 136 taken 1 time.
✗ Branch 135 → 275 not taken.
✓ Branch 136 → 137 taken 1 time.
✗ Branch 136 → 273 not taken.
✓ Branch 139 → 140 taken 1 time.
✗ Branch 139 → 279 not taken.
✓ Branch 140 → 141 taken 1 time.
✗ Branch 140 → 279 not taken.
|
4 | SOFT_ERROR_ER(node, INVALID_STRUCT_INSTANTIATION, "Struct instantiations for inheriting structs are forbidden") |
| 529 | |||
| 530 | // Check if the number of fields matches | ||
| 531 |
2/2✓ Branch 143 → 144 taken 1283 times.
✓ Branch 143 → 203 taken 26 times.
|
1309 | if (node->fieldLst) { // Check if any fields are passed. Empty braces are also allowed |
| 532 |
2/2✓ Branch 146 → 147 taken 1 time.
✓ Branch 146 → 157 taken 1282 times.
|
1283 | if (spiceStruct->fieldTypes.size() != node->fieldLst->args.size()) |
| 533 |
4/8✓ Branch 149 → 150 taken 1 time.
✗ Branch 149 → 282 not taken.
✓ Branch 150 → 151 taken 1 time.
✗ Branch 150 → 280 not taken.
✓ Branch 153 → 154 taken 1 time.
✗ Branch 153 → 286 not taken.
✓ Branch 154 → 155 taken 1 time.
✗ Branch 154 → 286 not taken.
|
4 | SOFT_ERROR_ER(node->fieldLst, NUMBER_OF_FIELDS_NOT_MATCHING, |
| 534 | "You've passed too less/many field values. Pass either none or all of them") | ||
| 535 | |||
| 536 | // Check if the field types are matching | ||
| 537 | 1282 | const size_t fieldCount = spiceStruct->fieldTypes.size(); | |
| 538 |
1/2✓ Branch 158 → 159 taken 1282 times.
✗ Branch 158 → 302 not taken.
|
1282 | const size_t explicitFieldsStartIdx = spiceStruct->scope->getFieldCount() - fieldCount; |
| 539 | // Per-manifestation: a struct literal inside a generic function is re-type-checked once per manifestation of | ||
| 540 | // that function, and the struct itself may resolve to a different concrete type each time (e.g. HashEntry<K, | ||
| 541 | // V> inside HashTable<K, V>.upsert()), so the copy-ctor set from one manifestation must not leak into another. | ||
| 542 |
1/2✓ Branch 159 → 160 taken 1282 times.
✗ Branch 159 → 302 not taken.
|
1282 | std::vector<Function *> &fieldCopyCtors = node->fieldCopyCtors.at(manIdx); |
| 543 | 1282 | fieldCopyCtors.clear(); | |
| 544 |
2/2✓ Branch 198 → 162 taken 1729 times.
✓ Branch 198 → 199 taken 1281 times.
|
3010 | for (size_t i = 0; i < node->fieldLst->args.size(); i++) { |
| 545 | // Get actual type | ||
| 546 |
1/2✓ Branch 162 → 163 taken 1729 times.
✗ Branch 162 → 293 not taken.
|
1729 | ExprNode *assignExpr = node->fieldLst->args.at(i); |
| 547 |
2/4✓ Branch 163 → 164 taken 1729 times.
✗ Branch 163 → 289 not taken.
✓ Branch 164 → 165 taken 1729 times.
✗ Branch 164 → 287 not taken.
|
1729 | auto fieldResult = std::any_cast<ExprResult>(visit(assignExpr)); |
| 548 |
2/8✓ Branch 166 → 167 taken 1729 times.
✗ Branch 166 → 293 not taken.
✗ Branch 167 → 168 not taken.
✓ Branch 167 → 172 taken 1729 times.
✗ Branch 168 → 169 not taken.
✗ Branch 168 → 290 not taken.
✗ Branch 169 → 170 not taken.
✗ Branch 169 → 290 not taken.
|
1729 | HANDLE_UNRESOLVED_TYPE_ER(fieldResult.type) |
| 549 | // Get expected type | ||
| 550 |
1/2✗ Branch 172 → 173 not taken.
✓ Branch 172 → 174 taken 1729 times.
|
1729 | SymbolTableEntry *expectedField = spiceStruct->scope->lookupField(explicitFieldsStartIdx + i); |
| 551 |
1/2✗ Branch 177 → 178 not taken.
✓ Branch 177 → 179 taken 1729 times.
|
1729 | assert(expectedField != nullptr); |
| 552 |
1/2✓ Branch 179 → 180 taken 1729 times.
✗ Branch 179 → 293 not taken.
|
1729 | const ExprResult expected = {expectedField->getQualType(), expectedField}; |
| 553 |
1/2✓ Branch 180 → 181 taken 1729 times.
✗ Branch 180 → 293 not taken.
|
1729 | const bool rhsIsImmediate = assignExpr->hasCompileTimeValue(manIdx); |
| 554 | |||
| 555 | // Capture anonymous info up front: getFieldAssignResultType may delete the anonymous entry (temp stealing | ||
| 556 | // in performStructAssign), turning fieldResult.entry into a dangling pointer. | ||
| 557 |
4/4✓ Branch 181 → 182 taken 361 times.
✓ Branch 181 → 184 taken 1368 times.
✓ Branch 182 → 183 taken 7 times.
✓ Branch 182 → 184 taken 354 times.
|
1729 | const bool rhsIsAnonymous = fieldResult.entry != nullptr && fieldResult.entry->anonymous; |
| 558 |
3/4✓ Branch 185 → 186 taken 7 times.
✓ Branch 185 → 187 taken 1722 times.
✓ Branch 186 → 188 taken 7 times.
✗ Branch 186 → 293 not taken.
|
1729 | const std::string rhsEntryName = rhsIsAnonymous ? fieldResult.entry->name : std::string(); |
| 559 | |||
| 560 | // Check if actual type matches expected type. A non-anonymous, non-trivially-copyable rhs (e.g. a plain | ||
| 561 | // local variable) needs its value deep-copied into the field: the struct instantiation does not | ||
| 562 | // consume/move it, so the caller keeps its own copy alive and destructs it independently. | ||
| 563 |
2/2✓ Branch 188 → 189 taken 1728 times.
✓ Branch 188 → 291 taken 1 time.
|
1729 | const auto [_, copyCtor] = opRuleManager.getFieldAssignResultType(assignExpr, expected, fieldResult, rhsIsImmediate, true); |
| 564 |
1/2✓ Branch 191 → 192 taken 1728 times.
✗ Branch 191 → 291 not taken.
|
1728 | fieldCopyCtors.push_back(copyCtor); |
| 565 | |||
| 566 | // If there is an anonymous entry attached (e.g. for struct instantiation), delete it. | ||
| 567 | // Safe to call even if performStructAssign already deleted it: map::erase by key is a no-op when absent. | ||
| 568 |
2/2✓ Branch 192 → 193 taken 7 times.
✓ Branch 192 → 195 taken 1721 times.
|
1728 | if (rhsIsAnonymous) { |
| 569 |
1/2✓ Branch 193 → 194 taken 7 times.
✗ Branch 193 → 291 not taken.
|
7 | currentScope->symbolTable.deleteAnonymous(rhsEntryName); |
| 570 | 7 | fieldResult.entry = nullptr; | |
| 571 | } | ||
| 572 | 1729 | } | |
| 573 |
1/2✗ Branch 201 → 202 not taken.
✓ Branch 201 → 215 taken 1281 times.
|
1281 | assert(fieldCopyCtors.size() == node->fieldLst->args.size()); |
| 574 | } else { | ||
| 575 |
2/4✓ Branch 203 → 204 taken 26 times.
✗ Branch 203 → 302 not taken.
✗ Branch 204 → 205 not taken.
✓ Branch 204 → 215 taken 26 times.
|
102 | if (std::ranges::any_of(spiceStruct->fieldTypes, [](const QualType &fieldType) { return fieldType.isRef(); })) |
| 576 | ✗ | SOFT_ERROR_ER(node, REFERENCE_WITHOUT_INITIALIZER, | |
| 577 | "The struct takes at least one reference field. You need to instantiate it with all fields.") | ||
| 578 | } | ||
| 579 | |||
| 580 | // Update type of struct entry | ||
| 581 |
1/2✓ Branch 215 → 216 taken 1307 times.
✗ Branch 215 → 302 not taken.
|
1307 | structEntry->updateType(structType, true); |
| 582 | |||
| 583 | // Add anonymous symbol to keep track of dtor call, if non-trivially destructible | ||
| 584 | 1307 | SymbolTableEntry *anonymousEntry = nullptr; | |
| 585 |
3/4✓ Branch 216 → 217 taken 1307 times.
✗ Branch 216 → 302 not taken.
✓ Branch 217 → 218 taken 90 times.
✓ Branch 217 → 220 taken 1217 times.
|
1307 | if (!structType.isTriviallyDestructible(node)) |
| 586 |
1/2✓ Branch 218 → 219 taken 90 times.
✗ Branch 218 → 302 not taken.
|
90 | anonymousEntry = currentScope->symbolTable.insertAnonymous(structType, node); |
| 587 | |||
| 588 | // Remove public qualifier to not have public local variables | ||
| 589 | 1307 | structType.getQualifiers().isPublic = false; | |
| 590 | |||
| 591 |
2/4✓ Branch 221 → 222 taken 1307 times.
✗ Branch 221 → 301 not taken.
✓ Branch 222 → 223 taken 1307 times.
✗ Branch 222 → 301 not taken.
|
2614 | return ExprResult{node->setEvaluatedSymbolType(structType, manIdx), anonymousEntry}; |
| 592 | 1314 | } | |
| 593 | |||
| 594 | 55 | std::any TypeChecker::visitLambdaFunc(LambdaFuncNode *node) { | |
| 595 | // Check if all control paths in the lambda body return | ||
| 596 | 55 | bool returnsOnAllControlPaths = true; | |
| 597 |
3/4✓ Branch 2 → 3 taken 55 times.
✗ Branch 2 → 194 not taken.
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 14 taken 54 times.
|
55 | if (!node->returnsOnAllControlPaths(&returnsOnAllControlPaths, manIdx)) |
| 598 |
4/8✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 120 not taken.
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 118 not taken.
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 124 not taken.
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 124 not taken.
|
4 | SOFT_ERROR_ER(node, MISSING_RETURN_STMT, "Not all control paths of this lambda function have a return statement") |
| 599 | |||
| 600 | // Change to function scope | ||
| 601 |
2/4✓ Branch 14 → 15 taken 54 times.
✗ Branch 14 → 127 not taken.
✓ Branch 15 → 16 taken 54 times.
✗ Branch 15 → 125 not taken.
|
54 | Scope *bodyScope = currentScope->getChildScope(node->getScopeId()); |
| 602 |
1/2✓ Branch 17 → 18 taken 54 times.
✗ Branch 17 → 128 not taken.
|
54 | ScopeHandle scopeHandle(this, bodyScope, ScopeType::LAMBDA_BODY); |
| 603 | |||
| 604 | // Visit return type | ||
| 605 |
2/4✓ Branch 18 → 19 taken 54 times.
✗ Branch 18 → 131 not taken.
✓ Branch 19 → 20 taken 54 times.
✗ Branch 19 → 129 not taken.
|
54 | const auto returnType = std::any_cast<QualType>(visit(node->returnType)); |
| 606 |
2/8✓ Branch 21 → 22 taken 54 times.
✗ Branch 21 → 192 not taken.
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 27 taken 54 times.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 132 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 132 not taken.
|
54 | HANDLE_UNRESOLVED_TYPE_ER(returnType) |
| 607 |
3/4✓ Branch 27 → 28 taken 54 times.
✗ Branch 27 → 192 not taken.
✓ Branch 28 → 29 taken 1 time.
✓ Branch 28 → 39 taken 53 times.
|
54 | if (returnType.is(TY_DYN)) |
| 608 |
4/8✓ Branch 31 → 32 taken 1 time.
✗ Branch 31 → 135 not taken.
✓ Branch 32 → 33 taken 1 time.
✗ Branch 32 → 133 not taken.
✓ Branch 35 → 36 taken 1 time.
✗ Branch 35 → 139 not taken.
✓ Branch 36 → 37 taken 1 time.
✗ Branch 36 → 139 not taken.
|
4 | SOFT_ERROR_ER(node, UNEXPECTED_DYN_TYPE, "Dyn return types are not allowed") |
| 609 | |||
| 610 | // Set the type of the result variable | ||
| 611 |
1/2✓ Branch 41 → 42 taken 53 times.
✗ Branch 41 → 142 not taken.
|
159 | SymbolTableEntry *resultVarEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME); |
| 612 |
1/2✗ Branch 47 → 48 not taken.
✓ Branch 47 → 49 taken 53 times.
|
53 | assert(resultVarEntry != nullptr); |
| 613 |
1/2✓ Branch 49 → 50 taken 53 times.
✗ Branch 49 → 192 not taken.
|
53 | resultVarEntry->updateType(returnType, true); |
| 614 | 53 | resultVarEntry->used = true; | |
| 615 | |||
| 616 | // Visit parameters | ||
| 617 | 53 | QualTypeList paramTypes; | |
| 618 | 53 | ParamList paramList; | |
| 619 |
2/2✓ Branch 50 → 51 taken 48 times.
✓ Branch 50 → 80 taken 5 times.
|
53 | if (node->hasParams) { |
| 620 | // Visit param list to retrieve the param names | ||
| 621 |
2/4✓ Branch 51 → 52 taken 48 times.
✗ Branch 51 → 148 not taken.
✓ Branch 52 → 53 taken 48 times.
✗ Branch 52 → 146 not taken.
|
48 | auto namedParamList = std::any_cast<NamedParamList>(visit(node->paramLst)); |
| 622 |
2/2✓ Branch 77 → 56 taken 63 times.
✓ Branch 77 → 78 taken 48 times.
|
159 | for (const auto &[name, qualType, isOptional] : namedParamList) { |
| 623 |
1/2✗ Branch 58 → 59 not taken.
✓ Branch 58 → 66 taken 63 times.
|
63 | if (isOptional) |
| 624 | ✗ | softError(node, LAMBDA_WITH_OPTIONAL_PARAMS, "Lambdas cannot have optional parameters"); | |
| 625 | |||
| 626 |
1/2✓ Branch 66 → 67 taken 63 times.
✗ Branch 66 → 156 not taken.
|
63 | paramTypes.push_back(qualType); |
| 627 |
1/2✓ Branch 67 → 68 taken 63 times.
✗ Branch 67 → 155 not taken.
|
63 | paramList.push_back({qualType, isOptional}); |
| 628 | } | ||
| 629 | 48 | } | |
| 630 | |||
| 631 | // Visit lambda body | ||
| 632 |
2/2✓ Branch 80 → 81 taken 52 times.
✓ Branch 80 → 160 taken 1 time.
|
53 | visit(node->body); |
| 633 | |||
| 634 | // Leave function body scope | ||
| 635 |
1/2✓ Branch 82 → 83 taken 52 times.
✗ Branch 82 → 188 not taken.
|
52 | scopeHandle.leaveScopeEarly(); |
| 636 | |||
| 637 | // Prepare type of function | ||
| 638 |
1/2✓ Branch 83 → 84 taken 52 times.
✗ Branch 83 → 161 not taken.
|
52 | const QualType functionType = QualType(TY_FUNCTION) |
| 639 |
1/2✓ Branch 84 → 85 taken 52 times.
✗ Branch 84 → 161 not taken.
|
52 | .getWithFunctionParamAndReturnTypes(returnType, paramTypes) |
| 640 |
1/2✓ Branch 86 → 87 taken 52 times.
✗ Branch 86 → 161 not taken.
|
52 | .getWithLambdaCaptures(!bodyScope->symbolTable.captures.empty()); |
| 641 | |||
| 642 | // Create function object | ||
| 643 |
2/4✓ Branch 87 → 88 taken 52 times.
✗ Branch 87 → 165 not taken.
✓ Branch 88 → 89 taken 52 times.
✗ Branch 88 → 163 not taken.
|
52 | const std::string fctName = "lambda." + node->codeLoc.toPrettyLineAndColumn(); |
| 644 |
5/10✓ Branch 91 → 92 taken 52 times.
✗ Branch 91 → 174 not taken.
✓ Branch 92 → 93 taken 52 times.
✗ Branch 92 → 171 not taken.
✓ Branch 93 → 94 taken 52 times.
✗ Branch 93 → 170 not taken.
✓ Branch 94 → 95 taken 52 times.
✗ Branch 94 → 168 not taken.
✓ Branch 95 → 96 taken 52 times.
✗ Branch 95 → 166 not taken.
|
52 | node->manifestations.at(manIdx) = Function(fctName, nullptr, QualType(TY_DYN), returnType, paramList, {}, node); |
| 645 |
1/2✓ Branch 101 → 102 taken 52 times.
✗ Branch 101 → 186 not taken.
|
52 | node->manifestations.at(manIdx).bodyScope = bodyScope; |
| 646 |
3/6✓ Branch 102 → 103 taken 52 times.
✗ Branch 102 → 183 not taken.
✓ Branch 103 → 104 taken 52 times.
✗ Branch 103 → 181 not taken.
✓ Branch 104 → 105 taken 52 times.
✗ Branch 104 → 179 not taken.
|
52 | node->manifestations.at(manIdx).mangleSuffix = "." + std::to_string(manIdx); |
| 647 | |||
| 648 | // Check special requirements if this is an async lambda | ||
| 649 |
1/2✓ Branch 108 → 109 taken 52 times.
✗ Branch 108 → 186 not taken.
|
52 | (void)checkAsyncLambdaCaptureRules(node, node->lambdaAttr); |
| 650 | |||
| 651 |
2/4✓ Branch 109 → 110 taken 52 times.
✗ Branch 109 → 185 not taken.
✓ Branch 110 → 111 taken 52 times.
✗ Branch 110 → 185 not taken.
|
52 | return ExprResult{node->setEvaluatedSymbolType(functionType, manIdx)}; |
| 652 | 56 | } | |
| 653 | |||
| 654 | 46 | std::any TypeChecker::visitLambdaProc(LambdaProcNode *node) { | |
| 655 | // Mark unreachable statements | ||
| 656 | 46 | bool doSetPredecessorsUnreachable = true; | |
| 657 |
1/2✓ Branch 2 → 3 taken 46 times.
✗ Branch 2 → 131 not taken.
|
46 | node->returnsOnAllControlPaths(&doSetPredecessorsUnreachable, manIdx); |
| 658 | |||
| 659 | // Change to function scope | ||
| 660 |
2/4✓ Branch 3 → 4 taken 46 times.
✗ Branch 3 → 79 not taken.
✓ Branch 4 → 5 taken 46 times.
✗ Branch 4 → 77 not taken.
|
46 | Scope *bodyScope = currentScope->getChildScope(node->getScopeId()); |
| 661 |
1/2✓ Branch 6 → 7 taken 46 times.
✗ Branch 6 → 80 not taken.
|
46 | ScopeHandle scopeHandle(this, bodyScope, ScopeType::LAMBDA_BODY); |
| 662 | |||
| 663 | // Visit parameters | ||
| 664 | 46 | QualTypeList paramTypes; | |
| 665 | 46 | ParamList paramList; | |
| 666 |
2/2✓ Branch 7 → 8 taken 29 times.
✓ Branch 7 → 37 taken 17 times.
|
46 | if (node->hasParams) { |
| 667 | // Visit param list to retrieve the param names | ||
| 668 |
2/4✓ Branch 8 → 9 taken 29 times.
✗ Branch 8 → 83 not taken.
✓ Branch 9 → 10 taken 29 times.
✗ Branch 9 → 81 not taken.
|
29 | auto namedParamList = std::any_cast<NamedParamList>(visit(node->paramLst)); |
| 669 |
2/2✓ Branch 34 → 13 taken 39 times.
✓ Branch 34 → 35 taken 29 times.
|
97 | for (const auto &[_, qualType, isOptional] : namedParamList) { |
| 670 |
2/2✓ Branch 15 → 16 taken 1 time.
✓ Branch 15 → 23 taken 38 times.
|
39 | if (isOptional) |
| 671 |
2/4✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 86 not taken.
✓ Branch 19 → 20 taken 1 time.
✗ Branch 19 → 84 not taken.
|
2 | softError(node, LAMBDA_WITH_OPTIONAL_PARAMS, "Lambdas cannot have optional parameters"); |
| 672 | |||
| 673 |
1/2✓ Branch 23 → 24 taken 39 times.
✗ Branch 23 → 91 not taken.
|
39 | paramTypes.push_back(qualType); |
| 674 |
1/2✓ Branch 24 → 25 taken 39 times.
✗ Branch 24 → 90 not taken.
|
39 | paramList.push_back({qualType, isOptional}); |
| 675 | } | ||
| 676 | 29 | } | |
| 677 | |||
| 678 | // Visit lambda body | ||
| 679 |
1/2✓ Branch 37 → 38 taken 46 times.
✗ Branch 37 → 95 not taken.
|
46 | visit(node->body); |
| 680 | |||
| 681 | // Leave function body scope | ||
| 682 |
1/2✓ Branch 39 → 40 taken 46 times.
✗ Branch 39 → 125 not taken.
|
46 | scopeHandle.leaveScopeEarly(); |
| 683 | |||
| 684 | // Prepare type of function | ||
| 685 |
1/2✓ Branch 40 → 41 taken 46 times.
✗ Branch 40 → 97 not taken.
|
46 | const QualType functionType = QualType(TY_PROCEDURE) |
| 686 |
2/4✓ Branch 41 → 42 taken 46 times.
✗ Branch 41 → 96 not taken.
✓ Branch 42 → 43 taken 46 times.
✗ Branch 42 → 96 not taken.
|
46 | .getWithFunctionParamAndReturnTypes(QualType(TY_DYN), paramTypes) |
| 687 |
1/2✓ Branch 44 → 45 taken 46 times.
✗ Branch 44 → 96 not taken.
|
46 | .getWithLambdaCaptures(!bodyScope->symbolTable.captures.empty()); |
| 688 | |||
| 689 | // Create function object | ||
| 690 |
2/4✓ Branch 45 → 46 taken 46 times.
✗ Branch 45 → 101 not taken.
✓ Branch 46 → 47 taken 46 times.
✗ Branch 46 → 99 not taken.
|
46 | const std::string fctName = "lambda." + node->codeLoc.toPrettyLineAndColumn(); |
| 691 |
6/12✓ Branch 49 → 50 taken 46 times.
✗ Branch 49 → 111 not taken.
✓ Branch 50 → 51 taken 46 times.
✗ Branch 50 → 108 not taken.
✓ Branch 51 → 52 taken 46 times.
✗ Branch 51 → 107 not taken.
✓ Branch 52 → 53 taken 46 times.
✗ Branch 52 → 106 not taken.
✓ Branch 53 → 54 taken 46 times.
✗ Branch 53 → 104 not taken.
✓ Branch 54 → 55 taken 46 times.
✗ Branch 54 → 102 not taken.
|
46 | node->manifestations.at(manIdx) = Function(fctName, nullptr, QualType(TY_DYN), QualType(TY_DYN), paramList, {}, node); |
| 692 |
1/2✓ Branch 60 → 61 taken 46 times.
✗ Branch 60 → 123 not taken.
|
46 | node->manifestations.at(manIdx).bodyScope = bodyScope; |
| 693 |
3/6✓ Branch 61 → 62 taken 46 times.
✗ Branch 61 → 120 not taken.
✓ Branch 62 → 63 taken 46 times.
✗ Branch 62 → 118 not taken.
✓ Branch 63 → 64 taken 46 times.
✗ Branch 63 → 116 not taken.
|
46 | node->manifestations.at(manIdx).mangleSuffix = "." + std::to_string(manIdx); |
| 694 | |||
| 695 | // Check special requirements if this is an async lambda | ||
| 696 |
1/2✓ Branch 67 → 68 taken 46 times.
✗ Branch 67 → 123 not taken.
|
46 | (void)checkAsyncLambdaCaptureRules(node, node->lambdaAttr); |
| 697 | |||
| 698 |
2/4✓ Branch 68 → 69 taken 46 times.
✗ Branch 68 → 122 not taken.
✓ Branch 69 → 70 taken 46 times.
✗ Branch 69 → 122 not taken.
|
92 | return ExprResult{node->setEvaluatedSymbolType(functionType, manIdx)}; |
| 699 | 46 | } | |
| 700 | |||
| 701 | 1 | std::any TypeChecker::visitLambdaExpr(LambdaExprNode *node) { | |
| 702 | // Change to function scope | ||
| 703 |
2/4✓ Branch 2 → 3 taken 1 time.
✗ Branch 2 → 98 not taken.
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 96 not taken.
|
1 | Scope *bodyScope = currentScope->getChildScope(node->getScopeId()); |
| 704 |
1/2✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 99 not taken.
|
1 | ScopeHandle scopeHandle(this, bodyScope, ScopeType::LAMBDA_BODY); |
| 705 | |||
| 706 | // Visit parameters | ||
| 707 | 1 | QualTypeList paramTypes; | |
| 708 | 1 | ParamList paramList; | |
| 709 |
1/2✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 36 not taken.
|
1 | if (node->hasParams) { |
| 710 | // Visit param list to retrieve the param names | ||
| 711 |
2/4✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 102 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 100 not taken.
|
1 | auto namedParamList = std::any_cast<NamedParamList>(visit(node->paramLst)); |
| 712 |
2/2✓ Branch 33 → 12 taken 2 times.
✓ Branch 33 → 34 taken 1 time.
|
4 | for (const NamedParam ¶m : namedParamList) { |
| 713 |
1/2✗ Branch 14 → 15 not taken.
✓ Branch 14 → 22 taken 2 times.
|
2 | if (param.isOptional) |
| 714 | ✗ | softError(node, LAMBDA_WITH_OPTIONAL_PARAMS, "Lambdas cannot have optional parameters"); | |
| 715 | |||
| 716 |
1/2✓ Branch 22 → 23 taken 2 times.
✗ Branch 22 → 110 not taken.
|
2 | paramTypes.push_back(param.qualType); |
| 717 |
1/2✓ Branch 23 → 24 taken 2 times.
✗ Branch 23 → 109 not taken.
|
2 | paramList.push_back({param.qualType, param.isOptional}); |
| 718 | } | ||
| 719 | 1 | } | |
| 720 | |||
| 721 | // Visit lambda expression | ||
| 722 |
2/4✓ Branch 36 → 37 taken 1 time.
✗ Branch 36 → 116 not taken.
✓ Branch 37 → 38 taken 1 time.
✗ Branch 37 → 114 not taken.
|
1 | const QualType returnType = std::any_cast<ExprResult>(visit(node->lambdaExpr)).type; |
| 723 |
2/8✓ Branch 39 → 40 taken 1 time.
✗ Branch 39 → 153 not taken.
✗ Branch 40 → 41 not taken.
✓ Branch 40 → 45 taken 1 time.
✗ Branch 41 → 42 not taken.
✗ Branch 41 → 118 not taken.
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 118 not taken.
|
1 | HANDLE_UNRESOLVED_TYPE_ER(returnType) |
| 724 |
2/4✓ Branch 45 → 46 taken 1 time.
✗ Branch 45 → 153 not taken.
✗ Branch 46 → 47 not taken.
✓ Branch 46 → 57 taken 1 time.
|
1 | if (returnType.is(TY_DYN)) |
| 725 | ✗ | SOFT_ERROR_ER(node, UNEXPECTED_DYN_TYPE, "Dyn return types are not allowed") | |
| 726 | |||
| 727 | // Leave function body scope | ||
| 728 |
1/2✓ Branch 57 → 58 taken 1 time.
✗ Branch 57 → 153 not taken.
|
1 | scopeHandle.leaveScopeEarly(); |
| 729 | |||
| 730 | // Prepare type of function | ||
| 731 |
2/4✓ Branch 58 → 59 taken 1 time.
✗ Branch 58 → 153 not taken.
✗ Branch 59 → 60 not taken.
✓ Branch 59 → 61 taken 1 time.
|
1 | const SuperType superType = returnType.is(TY_DYN) ? TY_PROCEDURE : TY_FUNCTION; |
| 732 |
1/2✓ Branch 62 → 63 taken 1 time.
✗ Branch 62 → 126 not taken.
|
1 | const QualType functionType = QualType(superType) |
| 733 |
1/2✓ Branch 63 → 64 taken 1 time.
✗ Branch 63 → 126 not taken.
|
1 | .getWithFunctionParamAndReturnTypes(returnType, paramTypes) |
| 734 |
1/2✓ Branch 65 → 66 taken 1 time.
✗ Branch 65 → 126 not taken.
|
1 | .getWithLambdaCaptures(!bodyScope->symbolTable.captures.empty()); |
| 735 | |||
| 736 | // Create function object | ||
| 737 |
2/4✓ Branch 66 → 67 taken 1 time.
✗ Branch 66 → 130 not taken.
✓ Branch 67 → 68 taken 1 time.
✗ Branch 67 → 128 not taken.
|
1 | const std::string fctName = "lambda." + node->codeLoc.toPrettyLineAndColumn(); |
| 738 |
5/10✓ Branch 70 → 71 taken 1 time.
✗ Branch 70 → 139 not taken.
✓ Branch 71 → 72 taken 1 time.
✗ Branch 71 → 136 not taken.
✓ Branch 72 → 73 taken 1 time.
✗ Branch 72 → 135 not taken.
✓ Branch 73 → 74 taken 1 time.
✗ Branch 73 → 133 not taken.
✓ Branch 74 → 75 taken 1 time.
✗ Branch 74 → 131 not taken.
|
1 | node->manifestations.at(manIdx) = Function(fctName, nullptr, QualType(TY_DYN), returnType, paramList, {}, node); |
| 739 |
1/2✓ Branch 80 → 81 taken 1 time.
✗ Branch 80 → 151 not taken.
|
1 | node->manifestations.at(manIdx).bodyScope = bodyScope; |
| 740 |
3/6✓ Branch 81 → 82 taken 1 time.
✗ Branch 81 → 148 not taken.
✓ Branch 82 → 83 taken 1 time.
✗ Branch 82 → 146 not taken.
✓ Branch 83 → 84 taken 1 time.
✗ Branch 83 → 144 not taken.
|
1 | node->manifestations.at(manIdx).mangleSuffix = "." + std::to_string(manIdx); |
| 741 | |||
| 742 |
2/4✓ Branch 87 → 88 taken 1 time.
✗ Branch 87 → 150 not taken.
✓ Branch 88 → 89 taken 1 time.
✗ Branch 88 → 150 not taken.
|
1 | return ExprResult{node->setEvaluatedSymbolType(functionType, manIdx)}; |
| 743 | 1 | } | |
| 744 | |||
| 745 | } // namespace spice::compiler | ||
| 746 |