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/Builtins.h> | ||
| 14 | #include <typechecker/FunctionManager.h> | ||
| 15 | #include <typechecker/MacroDefs.h> | ||
| 16 | #include <typechecker/TypeMatcher.h> | ||
| 17 | |||
| 18 | namespace spice::compiler { | ||
| 19 | |||
| 20 | 21672 | std::any TypeChecker::visitValue(ValueNode *node) { | |
| 21 | // Function call | ||
| 22 |
2/2✓ Branch 2 → 3 taken 19477 times.
✓ Branch 2 → 4 taken 2195 times.
|
21672 | if (node->fctCall) |
| 23 | 19477 | return visit(node->fctCall); | |
| 24 | |||
| 25 | // Array initialization | ||
| 26 |
2/2✓ Branch 4 → 5 taken 79 times.
✓ Branch 4 → 6 taken 2116 times.
|
2195 | if (node->arrayInitialization) |
| 27 | 79 | return visit(node->arrayInitialization); | |
| 28 | |||
| 29 | // Struct instantiation | ||
| 30 |
2/2✓ Branch 6 → 7 taken 297 times.
✓ Branch 6 → 8 taken 1819 times.
|
2116 | if (node->structInstantiation) |
| 31 | 297 | return visit(node->structInstantiation); | |
| 32 | |||
| 33 | // Lambda function | ||
| 34 |
2/2✓ Branch 8 → 9 taken 16 times.
✓ Branch 8 → 10 taken 1803 times.
|
1819 | if (node->lambdaFunc) |
| 35 | 16 | return visit(node->lambdaFunc); | |
| 36 | |||
| 37 | // Lambda procedure | ||
| 38 |
2/2✓ Branch 10 → 11 taken 21 times.
✓ Branch 10 → 12 taken 1782 times.
|
1803 | if (node->lambdaProc) |
| 39 | 21 | return visit(node->lambdaProc); | |
| 40 | |||
| 41 | // Lambda expression | ||
| 42 |
2/2✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 14 taken 1781 times.
|
1782 | if (node->lambdaExpr) |
| 43 | 1 | return visit(node->lambdaExpr); | |
| 44 | |||
| 45 | // Typed nil | ||
| 46 |
1/2✓ Branch 14 → 15 taken 1781 times.
✗ Branch 14 → 41 not taken.
|
1781 | if (node->isNil) { |
| 47 |
2/4✓ Branch 15 → 16 taken 1781 times.
✗ Branch 15 → 52 not taken.
✓ Branch 16 → 17 taken 1781 times.
✗ Branch 16 → 50 not taken.
|
1781 | const auto nilType = std::any_cast<QualType>(visit(node->nilType)); |
| 48 |
2/8✓ Branch 18 → 19 taken 1781 times.
✗ Branch 18 → 62 not taken.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 24 taken 1781 times.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 53 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 53 not taken.
|
1781 | HANDLE_UNRESOLVED_TYPE_ER(nilType) |
| 49 |
2/4✓ Branch 24 → 25 taken 1781 times.
✗ Branch 24 → 62 not taken.
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 36 taken 1781 times.
|
1781 | 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 1781 times.
✗ Branch 36 → 61 not taken.
✓ Branch 37 → 38 taken 1781 times.
✗ Branch 37 → 61 not taken.
|
1781 | return ExprResult{node->setEvaluatedSymbolType(nilType, manIdx)}; |
| 52 | } | ||
| 53 | |||
| 54 | − | throw CompilerError(UNHANDLED_BRANCH, "Value fall-through"); // GCOV_EXCL_LINE | |
| 55 | } | ||
| 56 | |||
| 57 | 23978 | std::any TypeChecker::visitConstant(ConstantNode *node) { | |
| 58 | SuperType superType; | ||
| 59 |
7/8✓ Branch 2 → 3 taken 659 times.
✓ Branch 2 → 4 taken 4228 times.
✓ Branch 2 → 5 taken 877 times.
✓ Branch 2 → 6 taken 8475 times.
✓ Branch 2 → 7 taken 2564 times.
✓ Branch 2 → 8 taken 4032 times.
✓ Branch 2 → 9 taken 3143 times.
✗ Branch 2 → 10 not taken.
|
23978 | switch (node->type) { |
| 60 | 659 | case ConstantNode::PrimitiveValueType::TYPE_DOUBLE: | |
| 61 | 659 | superType = TY_DOUBLE; | |
| 62 | 659 | break; | |
| 63 | 4228 | case ConstantNode::PrimitiveValueType::TYPE_INT: | |
| 64 | 4228 | superType = TY_INT; | |
| 65 | 4228 | break; | |
| 66 | 877 | case ConstantNode::PrimitiveValueType::TYPE_SHORT: | |
| 67 | 877 | superType = TY_SHORT; | |
| 68 | 877 | break; | |
| 69 | 8475 | case ConstantNode::PrimitiveValueType::TYPE_LONG: | |
| 70 | 8475 | superType = TY_LONG; | |
| 71 | 8475 | break; | |
| 72 | 2564 | case ConstantNode::PrimitiveValueType::TYPE_CHAR: | |
| 73 | 2564 | superType = TY_CHAR; | |
| 74 | 2564 | break; | |
| 75 | 4032 | case ConstantNode::PrimitiveValueType::TYPE_STRING: | |
| 76 | 4032 | superType = TY_STRING; | |
| 77 | 4032 | break; | |
| 78 | 3143 | case ConstantNode::PrimitiveValueType::TYPE_BOOL: | |
| 79 | 3143 | superType = TY_BOOL; | |
| 80 | 3143 | 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 23978 times.
✗ Branch 18 → 33 not taken.
✓ Branch 19 → 20 taken 23978 times.
✗ Branch 19 → 33 not taken.
✓ Branch 20 → 21 taken 23978 times.
✗ Branch 20 → 33 not taken.
|
23978 | return ExprResult{node->setEvaluatedSymbolType(QualType(superType), manIdx)}; |
| 85 | } | ||
| 86 | |||
| 87 | 19477 | std::any TypeChecker::visitFctCall(FctCallNode *node) { | |
| 88 |
1/2✓ Branch 2 → 3 taken 19477 times.
✗ Branch 2 → 508 not taken.
|
19477 | FctCallNode::FctCallData &data = node->data.at(manIdx); |
| 89 | 19477 | auto &[callType, isImported, templateTypes, thisType, args, callee, calleeParentScope, compTimeVal, hasCompTimeVal] = data; | |
| 90 | |||
| 91 | // Retrieve arg types | ||
| 92 | 19477 | args.clear(); | |
| 93 |
2/2✓ Branch 4 → 5 taken 15586 times.
✓ Branch 4 → 28 taken 3891 times.
|
19477 | if (node->hasArgs) { |
| 94 |
1/2✓ Branch 6 → 7 taken 15586 times.
✗ Branch 6 → 508 not taken.
|
15586 | args.reserve(node->argLst->args.size()); |
| 95 |
2/2✓ Branch 26 → 9 taken 26681 times.
✓ Branch 26 → 27 taken 15570 times.
|
42251 | for (ExprNode *arg : node->argLst->args) { |
| 96 | // Visit argument | ||
| 97 |
3/4✓ Branch 10 → 11 taken 26680 times.
✓ Branch 10 → 395 taken 1 time.
✓ Branch 11 → 12 taken 26680 times.
✗ Branch 11 → 393 not taken.
|
26681 | const auto argResult = std::any_cast<ExprResult>(visit(arg)); |
| 98 |
5/8✓ Branch 13 → 14 taken 26680 times.
✗ Branch 13 → 398 not taken.
✓ Branch 14 → 15 taken 15 times.
✓ Branch 14 → 19 taken 26665 times.
✓ Branch 15 → 16 taken 15 times.
✗ Branch 15 → 396 not taken.
✓ Branch 16 → 17 taken 15 times.
✗ Branch 16 → 396 not taken.
|
26680 | HANDLE_UNRESOLVED_TYPE_ER(argResult.type) |
| 99 |
2/4✓ Branch 19 → 20 taken 26665 times.
✗ Branch 19 → 398 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 26665 times.
|
26665 | assert(!argResult.type.hasAnyGenericParts()); |
| 100 | // Save arg type to arg types list | ||
| 101 |
1/2✓ Branch 23 → 24 taken 26665 times.
✗ Branch 23 → 397 not taken.
|
26665 | args.emplace_back(argResult.type, argResult.isTemporary()); |
| 102 | } | ||
| 103 | } | ||
| 104 | |||
| 105 | // Retrieve template types | ||
| 106 | 19461 | templateTypes.clear(); | |
| 107 |
2/2✓ Branch 29 → 30 taken 1281 times.
✓ Branch 29 → 65 taken 18180 times.
|
19461 | if (node->hasTemplateTypes) { |
| 108 |
2/2✓ Branch 63 → 32 taken 1923 times.
✓ Branch 63 → 64 taken 1281 times.
|
3204 | for (DataTypeNode *templateTypeNode : node->templateTypeLst->dataTypes) { |
| 109 |
2/4✓ Branch 33 → 34 taken 1923 times.
✗ Branch 33 → 402 not taken.
✓ Branch 34 → 35 taken 1923 times.
✗ Branch 34 → 400 not taken.
|
1923 | auto templateType = std::any_cast<QualType>(visit(templateTypeNode)); |
| 110 |
2/4✓ Branch 36 → 37 taken 1923 times.
✗ Branch 36 → 411 not taken.
✗ Branch 37 → 38 not taken.
✓ Branch 37 → 39 taken 1923 times.
|
1923 | assert(!templateType.is(TY_INVALID)); |
| 111 | |||
| 112 | // Abort if the type is unresolved | ||
| 113 |
2/4✓ Branch 39 → 40 taken 1923 times.
✗ Branch 39 → 411 not taken.
✗ Branch 40 → 41 not taken.
✓ Branch 40 → 47 taken 1923 times.
|
1923 | if (templateType.is(TY_UNRESOLVED)) |
| 114 | ✗ | HANDLE_UNRESOLVED_TYPE_ER(templateType) | |
| 115 | |||
| 116 | // Check if the given type is generic | ||
| 117 |
2/4✓ Branch 47 → 48 taken 1923 times.
✗ Branch 47 → 411 not taken.
✗ Branch 48 → 49 not taken.
✓ Branch 48 → 59 taken 1923 times.
|
1923 | 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 59 → 60 taken 1923 times.
✗ Branch 59 → 411 not taken.
|
1923 | templateTypes.push_back(templateType); |
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 124 | // Check if this is a builtin call | ||
| 125 |
2/2✓ Branch 72 → 66 taken 182132 times.
✓ Branch 72 → 73 taken 17572 times.
|
199704 | for (const auto &[builtinFctName, _] : BUILTIN_FUNCTIONS) |
| 126 |
2/2✓ Branch 68 → 69 taken 1889 times.
✓ Branch 68 → 71 taken 180243 times.
|
182132 | if (node->fqFunctionName == builtinFctName) |
| 127 |
1/2✓ Branch 69 → 70 taken 1889 times.
✗ Branch 69 → 508 not taken.
|
1889 | return visitBuiltinCall(node); |
| 128 | |||
| 129 | // Retrieve entry of the first fragment | ||
| 130 | 17572 | const std::string &firstFrag = node->functionNameFragments.front(); | |
| 131 |
1/2✓ Branch 74 → 75 taken 17572 times.
✗ Branch 74 → 508 not taken.
|
17572 | SymbolTableEntry *firstFragEntry = currentScope->lookup(firstFrag); |
| 132 |
2/2✓ Branch 77 → 78 taken 10055 times.
✓ Branch 77 → 115 taken 7517 times.
|
17572 | if (firstFragEntry) { |
| 133 | // Check if we have seen a 'this.' prefix, because the generator needs that | ||
| 134 |
6/8✓ Branch 78 → 79 taken 1 time.
✓ Branch 78 → 82 taken 10054 times.
✓ Branch 79 → 80 taken 1 time.
✗ Branch 79 → 423 not taken.
✓ Branch 80 → 81 taken 1 time.
✗ Branch 80 → 82 not taken.
✓ Branch 83 → 84 taken 1 time.
✓ Branch 83 → 93 taken 10054 times.
|
10055 | if (firstFragEntry->scope->type == ScopeType::STRUCT && firstFrag != THIS_VARIABLE_NAME) |
| 135 |
5/10✓ Branch 84 → 85 taken 1 time.
✗ Branch 84 → 417 not taken.
✓ Branch 85 → 86 taken 1 time.
✗ Branch 85 → 415 not taken.
✓ Branch 86 → 87 taken 1 time.
✗ Branch 86 → 413 not taken.
✓ Branch 89 → 90 taken 1 time.
✗ Branch 89 → 419 not taken.
✓ Branch 90 → 91 taken 1 time.
✗ Branch 90 → 419 not taken.
|
1 | SOFT_ERROR_ER(node, REFERENCED_UNDEFINED_VARIABLE, |
| 136 | "The symbol '" + firstFrag + "' could not be found. Missing 'this.' prefix?") | ||
| 137 | |||
| 138 | 10054 | firstFragEntry->used = true; | |
| 139 | // Decide of which type the function call is | ||
| 140 |
2/4✓ Branch 93 → 94 taken 10054 times.
✗ Branch 93 → 423 not taken.
✓ Branch 94 → 95 taken 10054 times.
✗ Branch 94 → 423 not taken.
|
10054 | const QualType &baseType = firstFragEntry->getQualType().getBase(); |
| 141 |
5/8✓ Branch 95 → 96 taken 10054 times.
✗ Branch 95 → 423 not taken.
✓ Branch 96 → 97 taken 4 times.
✓ Branch 96 → 101 taken 10050 times.
✓ Branch 97 → 98 taken 4 times.
✗ Branch 97 → 420 not taken.
✓ Branch 98 → 99 taken 4 times.
✗ Branch 98 → 420 not taken.
|
10054 | HANDLE_UNRESOLVED_TYPE_ER(baseType) |
| 142 |
3/4✓ Branch 101 → 102 taken 10050 times.
✗ Branch 101 → 421 not taken.
✓ Branch 102 → 103 taken 7542 times.
✓ Branch 102 → 106 taken 2508 times.
|
10050 | if (baseType.isOneOf({TY_STRUCT, TY_INTERFACE})) { |
| 143 |
2/2✓ Branch 103 → 104 taken 1120 times.
✓ Branch 103 → 105 taken 6422 times.
|
7542 | if (firstFragEntry->scope->type == ScopeType::GLOBAL) |
| 144 | 1120 | callType = FctCallNode::FctCallType::TYPE_CTOR; | |
| 145 | else | ||
| 146 | 6422 | callType = FctCallNode::FctCallType::TYPE_METHOD; | |
| 147 |
7/8✓ Branch 106 → 107 taken 2508 times.
✗ Branch 106 → 422 not taken.
✓ Branch 107 → 108 taken 2440 times.
✓ Branch 107 → 110 taken 68 times.
✓ Branch 108 → 109 taken 47 times.
✓ Branch 108 → 110 taken 2393 times.
✓ Branch 111 → 112 taken 47 times.
✓ Branch 111 → 113 taken 2461 times.
|
2508 | } else if (baseType.isOneOf({TY_FUNCTION, TY_PROCEDURE}) && firstFragEntry->scope->type != ScopeType::GLOBAL) { |
| 148 | 47 | callType = FctCallNode::FctCallType::TYPE_FCT_PTR; | |
| 149 | } | ||
| 150 | } | ||
| 151 | |||
| 152 | // Get struct name. Retrieve it from alias if required | ||
| 153 |
1/2✓ Branch 115 → 116 taken 17567 times.
✗ Branch 115 → 508 not taken.
|
17567 | const auto &[structEntry, isAlias] = rootScope->symbolTable.lookupWithAliasResolution(node->fqFunctionName); |
| 154 |
4/6✓ Branch 118 → 119 taken 1 time.
✓ Branch 118 → 122 taken 17566 times.
✓ Branch 119 → 120 taken 1 time.
✗ Branch 119 → 508 not taken.
✓ Branch 120 → 121 taken 1 time.
✗ Branch 120 → 508 not taken.
|
17567 | const std::string &fqFunctionName = isAlias ? structEntry->getQualType().getSubType() : node->fqFunctionName; |
| 155 | |||
| 156 | // Get the concrete template types | ||
| 157 |
2/2✓ Branch 123 → 124 taken 1 time.
✓ Branch 123 → 143 taken 17566 times.
|
17567 | if (isAlias) { |
| 158 | // Retrieve concrete template types from type alias | ||
| 159 |
3/6✓ Branch 124 → 125 taken 1 time.
✗ Branch 124 → 508 not taken.
✓ Branch 125 → 126 taken 1 time.
✗ Branch 125 → 508 not taken.
✓ Branch 126 → 127 taken 1 time.
✗ Branch 126 → 508 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 128 → 129 taken 1 time.
✗ Branch 128 → 131 not taken.
✗ Branch 129 → 130 not taken.
✓ Branch 129 → 131 taken 1 time.
✗ Branch 132 → 133 not taken.
✓ Branch 132 → 143 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 144 → 145 taken 6422 times.
✓ Branch 144 → 159 taken 11145 times.
|
17567 | if (data.isMethodCall()) { |
| 167 | // This is a method call | ||
| 168 |
1/2✓ Branch 145 → 146 taken 6422 times.
✗ Branch 145 → 508 not taken.
|
6422 | thisType = firstFragEntry->getQualType(); |
| 169 |
2/4✓ Branch 146 → 147 taken 6422 times.
✗ Branch 146 → 431 not taken.
✓ Branch 147 → 148 taken 6422 times.
✗ Branch 147 → 431 not taken.
|
6422 | Scope *structBodyScope = thisType.getBase().getBodyScope(); |
| 170 |
1/2✗ Branch 148 → 149 not taken.
✓ Branch 148 → 150 taken 6422 times.
|
6422 | assert(structBodyScope != nullptr); |
| 171 |
3/4✓ Branch 150 → 151 taken 6422 times.
✗ Branch 150 → 508 not taken.
✓ Branch 151 → 152 taken 2 times.
✓ Branch 151 → 157 taken 6420 times.
|
6422 | if (!visitMethodCall(node, structBodyScope)) // Check if soft errors occurred |
| 172 |
3/6✓ Branch 152 → 153 taken 2 times.
✗ Branch 152 → 432 not taken.
✓ Branch 153 → 154 taken 2 times.
✗ Branch 153 → 432 not taken.
✓ Branch 154 → 155 taken 2 times.
✗ Branch 154 → 432 not taken.
|
2 | return ExprResult{node->setEvaluatedSymbolType(QualType(TY_UNRESOLVED), manIdx)}; |
| 173 |
1/2✗ Branch 157 → 158 not taken.
✓ Branch 157 → 195 taken 6420 times.
|
6420 | assert(calleeParentScope != nullptr); |
| 174 |
2/2✓ Branch 160 → 161 taken 47 times.
✓ Branch 160 → 174 taken 11098 times.
|
11145 | } else if (data.isFctPtrCall()) { |
| 175 | // This is a function pointer call | ||
| 176 |
2/4✓ Branch 161 → 162 taken 47 times.
✗ Branch 161 → 437 not taken.
✓ Branch 162 → 163 taken 47 times.
✗ Branch 162 → 437 not taken.
|
47 | const QualType &functionType = firstFragEntry->getQualType().getBase(); |
| 177 |
2/4✓ Branch 163 → 164 taken 47 times.
✗ Branch 163 → 434 not taken.
✗ Branch 164 → 165 not taken.
✓ Branch 164 → 166 taken 47 times.
|
47 | assert(functionType.isOneOf({TY_FUNCTION, TY_PROCEDURE})); |
| 178 |
2/4✓ Branch 166 → 167 taken 47 times.
✗ Branch 166 → 437 not taken.
✗ Branch 167 → 168 not taken.
✓ Branch 167 → 173 taken 47 times.
|
47 | 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 175 → 176 taken 1125 times.
✓ Branch 175 → 179 taken 9973 times.
✗ Branch 177 → 178 not taken.
✓ Branch 177 → 179 taken 1125 times.
|
11098 | assert(data.isOrdinaryCall() || data.isCtorCall()); |
| 183 |
5/6✓ Branch 179 → 180 taken 11098 times.
✗ Branch 179 → 440 not taken.
✓ Branch 180 → 181 taken 11096 times.
✓ Branch 180 → 438 taken 2 times.
✓ Branch 182 → 183 taken 4 times.
✓ Branch 182 → 188 taken 11092 times.
|
11100 | if (!visitOrdinaryFctCall(node, fqFunctionName)) // Check if soft errors occurred |
| 184 |
3/6✓ Branch 183 → 184 taken 4 times.
✗ Branch 183 → 441 not taken.
✓ Branch 184 → 185 taken 4 times.
✗ Branch 184 → 441 not taken.
✓ Branch 185 → 186 taken 4 times.
✗ Branch 185 → 441 not taken.
|
4 | return ExprResult{node->setEvaluatedSymbolType(QualType(TY_UNRESOLVED), manIdx)}; |
| 185 |
1/2✗ Branch 188 → 189 not taken.
✓ Branch 188 → 190 taken 11092 times.
|
11092 | 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 191 → 192 taken 2440 times.
✓ Branch 191 → 195 taken 8652 times.
✓ Branch 192 → 193 taken 2440 times.
✗ Branch 192 → 508 not taken.
✗ Branch 193 → 194 not taken.
✓ Branch 193 → 195 taken 2440 times.
|
11092 | assert(data.isOrdinaryCall() || data.thisType.is(TY_STRUCT)); |
| 189 | } | ||
| 190 | |||
| 191 |
2/2✓ Branch 196 → 197 taken 17512 times.
✓ Branch 196 → 268 taken 47 times.
|
17559 | if (!data.isFctPtrCall()) { |
| 192 | // Check if we were able to find a function | ||
| 193 |
2/2✓ Branch 197 → 198 taken 12 times.
✓ Branch 197 → 235 taken 17500 times.
|
17512 | if (!callee) { |
| 194 | // Build error message | ||
| 195 |
6/10✓ Branch 199 → 200 taken 2 times.
✓ Branch 199 → 203 taken 10 times.
✓ Branch 202 → 205 taken 2 times.
✗ Branch 202 → 443 not taken.
✓ Branch 204 → 205 taken 10 times.
✗ Branch 204 → 443 not taken.
✓ Branch 205 → 206 taken 2 times.
✓ Branch 205 → 208 taken 10 times.
✗ Branch 443 → 444 not taken.
✗ Branch 443 → 446 not taken.
|
14 | const std::string functionName = data.isCtorCall() ? CTOR_FUNCTION_NAME : node->functionNameFragments.back(); |
| 196 | 12 | ParamList errArgTypes; | |
| 197 |
1/2✓ Branch 209 → 210 taken 12 times.
✗ Branch 209 → 463 not taken.
|
12 | errArgTypes.reserve(args.size()); |
| 198 |
5/8✓ Branch 210 → 211 taken 12 times.
✗ Branch 210 → 449 not taken.
✓ Branch 211 → 212 taken 12 times.
✗ Branch 211 → 449 not taken.
✓ Branch 212 → 213 taken 12 times.
✗ Branch 212 → 449 not taken.
✓ Branch 218 → 214 taken 7 times.
✓ Branch 218 → 219 taken 12 times.
|
19 | for (const auto &type : args | std::views::keys) |
| 199 |
1/2✓ Branch 215 → 216 taken 7 times.
✗ Branch 215 → 448 not taken.
|
7 | errArgTypes.push_back({type, false}); |
| 200 |
2/4✓ Branch 220 → 221 taken 12 times.
✗ Branch 220 → 450 not taken.
✓ Branch 221 → 222 taken 12 times.
✗ Branch 221 → 450 not taken.
|
12 | const std::string signature = Function::getSignature(functionName, thisType, QualType(TY_DYN), errArgTypes, {}, false); |
| 201 | // Throw error | ||
| 202 |
5/10✓ Branch 223 → 224 taken 12 times.
✗ Branch 223 → 458 not taken.
✓ Branch 224 → 225 taken 12 times.
✗ Branch 224 → 456 not taken.
✓ Branch 225 → 226 taken 12 times.
✗ Branch 225 → 454 not taken.
✓ Branch 228 → 229 taken 12 times.
✗ Branch 228 → 460 not taken.
✓ Branch 229 → 230 taken 12 times.
✗ Branch 229 → 460 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 235 → 236 taken 17500 times.
✗ Branch 235 → 508 not taken.
|
17500 | requestRevisitIfRequired(callee); |
| 207 | |||
| 208 | // Get function entry from function object | ||
| 209 | 17500 | SymbolTableEntry *functionEntry = callee->entry; | |
| 210 | |||
| 211 | // Check if the called function has sufficient visibility | ||
| 212 |
1/2✓ Branch 236 → 237 taken 17500 times.
✗ Branch 236 → 508 not taken.
|
17500 | isImported = calleeParentScope->isImportedBy(rootScope); |
| 213 |
8/10✓ Branch 237 → 238 taken 4547 times.
✓ Branch 237 → 242 taken 12953 times.
✓ Branch 238 → 239 taken 4547 times.
✗ Branch 238 → 508 not taken.
✓ Branch 239 → 240 taken 4547 times.
✗ Branch 239 → 508 not taken.
✓ Branch 240 → 241 taken 1 time.
✓ Branch 240 → 242 taken 4546 times.
✓ Branch 243 → 244 taken 1 time.
✓ Branch 243 → 268 taken 17499 times.
|
17500 | if (isImported && !functionEntry->getQualType().isPublic()) { |
| 214 |
1/2✓ Branch 244 → 245 taken 1 time.
✗ Branch 244 → 484 not taken.
|
1 | const QualType functionEntryType = functionEntry->getQualType(); |
| 215 |
1/2✓ Branch 245 → 246 taken 1 time.
✗ Branch 245 → 484 not taken.
|
1 | const std::string signature = callee->getSignature(); |
| 216 |
2/4✓ Branch 246 → 247 taken 1 time.
✗ Branch 246 → 482 not taken.
✓ Branch 247 → 248 taken 1 time.
✗ Branch 247 → 257 not taken.
|
1 | if (functionEntryType.is(TY_FUNCTION)) |
| 217 |
5/10✓ Branch 248 → 249 taken 1 time.
✗ Branch 248 → 472 not taken.
✓ Branch 249 → 250 taken 1 time.
✗ Branch 249 → 470 not taken.
✓ Branch 250 → 251 taken 1 time.
✗ Branch 250 → 468 not taken.
✓ Branch 253 → 254 taken 1 time.
✗ Branch 253 → 474 not taken.
✓ Branch 254 → 255 taken 1 time.
✗ Branch 254 → 474 not taken.
|
1 | 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 | 1 | } | |
| 221 | } | ||
| 222 | |||
| 223 | // Generate arg infos | ||
| 224 |
2/2✓ Branch 268 → 269 taken 13825 times.
✓ Branch 268 → 311 taken 3721 times.
|
17546 | if (node->hasArgs) { |
| 225 | 13825 | QualTypeList paramTypes; | |
| 226 |
2/2✓ Branch 270 → 271 taken 25 times.
✓ Branch 270 → 277 taken 13800 times.
|
13825 | if (data.isFctPtrCall()) { |
| 227 |
2/4✓ Branch 271 → 272 taken 25 times.
✗ Branch 271 → 486 not taken.
✓ Branch 272 → 273 taken 25 times.
✗ Branch 272 → 486 not taken.
|
25 | const QualType &functionType = firstFragEntry->getQualType().getBase(); |
| 228 |
1/2✓ Branch 273 → 274 taken 25 times.
✗ Branch 273 → 485 not taken.
|
25 | paramTypes = functionType.getFunctionParamTypes(); |
| 229 | } else { | ||
| 230 |
1/2✗ Branch 277 → 278 not taken.
✓ Branch 277 → 279 taken 13800 times.
|
13800 | assert(callee != nullptr); |
| 231 |
1/2✓ Branch 279 → 280 taken 13800 times.
✗ Branch 279 → 487 not taken.
|
13800 | paramTypes = callee->getParamTypes(); |
| 232 | } | ||
| 233 | |||
| 234 | 13825 | node->argLst->argInfos.clear(); | |
| 235 |
2/2✓ Branch 304 → 285 taken 24175 times.
✓ Branch 304 → 305 taken 13825 times.
|
38000 | for (size_t argIdx = 0; argIdx < args.size(); argIdx++) { |
| 236 |
1/2✓ Branch 285 → 286 taken 24175 times.
✗ Branch 285 → 489 not taken.
|
24175 | const QualType &expectedType = paramTypes.at(argIdx); |
| 237 |
1/2✓ Branch 286 → 287 taken 24175 times.
✗ Branch 286 → 489 not taken.
|
24175 | const auto &[actualType, _] = args.at(argIdx); |
| 238 | |||
| 239 | 24175 | Function *copyCtor = nullptr; | |
| 240 |
11/14✓ Branch 289 → 290 taken 24175 times.
✗ Branch 289 → 489 not taken.
✓ Branch 290 → 291 taken 40 times.
✓ Branch 290 → 296 taken 24135 times.
✓ Branch 291 → 292 taken 40 times.
✗ Branch 291 → 489 not taken.
✓ Branch 292 → 293 taken 36 times.
✓ Branch 292 → 296 taken 4 times.
✓ Branch 293 → 294 taken 36 times.
✗ Branch 293 → 489 not taken.
✓ Branch 294 → 295 taken 16 times.
✓ Branch 294 → 296 taken 20 times.
✓ Branch 297 → 298 taken 16 times.
✓ Branch 297 → 301 taken 24159 times.
|
24175 | if (expectedType.is(TY_STRUCT) && actualType.is(TY_STRUCT) && !actualType.isTriviallyCopyable(node)) { |
| 241 |
1/2✓ Branch 298 → 299 taken 16 times.
✗ Branch 298 → 489 not taken.
|
16 | copyCtor = matchCopyCtor(actualType, node); |
| 242 | // Insert anonymous symbol to track the dtor call of the copy | ||
| 243 |
1/2✓ Branch 299 → 300 taken 16 times.
✗ Branch 299 → 489 not taken.
|
16 | ExprNode *argNode = node->argLst->args.at(argIdx); |
| 244 |
1/2✓ Branch 300 → 301 taken 16 times.
✗ Branch 300 → 489 not taken.
|
16 | currentScope->symbolTable.insertAnonymous(actualType, argNode, SIZE_MAX); |
| 245 | } | ||
| 246 | |||
| 247 |
1/2✓ Branch 301 → 302 taken 24175 times.
✗ Branch 301 → 488 not taken.
|
24175 | node->argLst->argInfos.push_back(ArgLstNode::ArgInfo{copyCtor}); |
| 248 | } | ||
| 249 |
1/2✗ Branch 307 → 308 not taken.
✓ Branch 307 → 309 taken 13825 times.
|
13825 | assert(node->argLst->argInfos.size() == node->argLst->args.size()); |
| 250 | 13825 | } | |
| 251 | |||
| 252 | // Retrieve return type | ||
| 253 |
6/10✓ Branch 312 → 313 taken 47 times.
✓ Branch 312 → 317 taken 17499 times.
✓ Branch 313 → 314 taken 47 times.
✗ Branch 313 → 492 not taken.
✓ Branch 314 → 315 taken 47 times.
✗ Branch 314 → 492 not taken.
✓ Branch 315 → 316 taken 47 times.
✗ Branch 315 → 492 not taken.
✓ Branch 317 → 318 taken 17499 times.
✗ Branch 317 → 492 not taken.
|
35045 | const bool isFct = data.isFctPtrCall() ? firstFragEntry->getQualType().getBase().is(TY_FUNCTION) : callee->isFunction(); |
| 254 | 17546 | QualType returnType; | |
| 255 |
2/2✓ Branch 322 → 323 taken 47 times.
✓ Branch 322 → 330 taken 17499 times.
|
17546 | if (data.isFctPtrCall()) { |
| 256 |
6/10✓ Branch 323 → 324 taken 20 times.
✓ Branch 323 → 328 taken 27 times.
✓ Branch 324 → 325 taken 20 times.
✗ Branch 324 → 493 not taken.
✓ Branch 325 → 326 taken 20 times.
✗ Branch 325 → 493 not taken.
✓ Branch 326 → 327 taken 20 times.
✗ Branch 326 → 493 not taken.
✓ Branch 328 → 329 taken 27 times.
✗ Branch 328 → 493 not taken.
|
47 | returnType = isFct ? firstFragEntry->getQualType().getBase().getFunctionReturnType() : QualType(TY_BOOL); |
| 257 |
2/2✓ Branch 331 → 332 taken 2438 times.
✓ Branch 331 → 333 taken 15061 times.
|
17499 | } else if (data.isCtorCall()) { |
| 258 | 2438 | returnType = thisType; | |
| 259 |
3/4✓ Branch 333 → 334 taken 15061 times.
✗ Branch 333 → 508 not taken.
✓ Branch 336 → 337 taken 4542 times.
✓ Branch 336 → 339 taken 10519 times.
|
30122 | } else if (callee->isProcedure()) { |
| 260 |
1/2✓ Branch 337 → 338 taken 4542 times.
✗ Branch 337 → 495 not taken.
|
4542 | returnType = QualType(TY_DYN); |
| 261 | } else { | ||
| 262 | 10519 | returnType = callee->returnType; | |
| 263 | } | ||
| 264 |
1/2✓ Branch 340 → 341 taken 17546 times.
✗ Branch 340 → 508 not taken.
|
17546 | const QualType returnBaseType = returnType.getBase(); |
| 265 | |||
| 266 | // Make sure this source file knows about the return type | ||
| 267 |
3/4✓ Branch 341 → 342 taken 17546 times.
✗ Branch 341 → 508 not taken.
✓ Branch 342 → 343 taken 3845 times.
✓ Branch 342 → 346 taken 13701 times.
|
17546 | if (returnBaseType.is(TY_STRUCT)) |
| 268 |
2/4✓ Branch 343 → 344 taken 3845 times.
✗ Branch 343 → 496 not taken.
✓ Branch 344 → 345 taken 3845 times.
✗ Branch 344 → 496 not taken.
|
3845 | returnType = mapImportedScopeTypeToLocalType(returnBaseType.getBodyScope(), returnType); |
| 269 | |||
| 270 | // Add anonymous symbol to keep track of dtor call, if non-trivially destructible | ||
| 271 | 17546 | SymbolTableEntry *anonymousSymbol = nullptr; | |
| 272 |
8/10✓ Branch 346 → 347 taken 17546 times.
✗ Branch 346 → 508 not taken.
✓ Branch 347 → 348 taken 3382 times.
✓ Branch 347 → 351 taken 14164 times.
✓ Branch 348 → 349 taken 3382 times.
✗ Branch 348 → 508 not taken.
✓ Branch 349 → 350 taken 2220 times.
✓ Branch 349 → 351 taken 1162 times.
✓ Branch 352 → 353 taken 2220 times.
✓ Branch 352 → 355 taken 15326 times.
|
17546 | if (returnType.is(TY_STRUCT) && !returnType.isTriviallyDestructible(node)) |
| 273 |
1/2✓ Branch 353 → 354 taken 2220 times.
✗ Branch 353 → 508 not taken.
|
2220 | anonymousSymbol = currentScope->symbolTable.insertAnonymous(returnType, node); |
| 274 | |||
| 275 | // Remove public qualifier to not have public local variables | ||
| 276 | 17546 | returnType.getQualifiers().isPublic = false; | |
| 277 | |||
| 278 | // Check if the return value gets discarded | ||
| 279 |
7/8✓ Branch 356 → 357 taken 10539 times.
✓ Branch 356 → 360 taken 7007 times.
✓ Branch 357 → 358 taken 10539 times.
✗ Branch 357 → 508 not taken.
✓ Branch 358 → 359 taken 320 times.
✓ Branch 358 → 360 taken 10219 times.
✓ Branch 361 → 362 taken 320 times.
✓ Branch 361 → 387 taken 17226 times.
|
17546 | if (isFct && !node->hasReturnValueReceiver()) { |
| 280 | // Check if we want to ignore the discarded return value | ||
| 281 | 320 | bool ignoreUnusedReturnValue = false; | |
| 282 |
2/2✓ Branch 363 → 364 taken 317 times.
✓ Branch 363 → 384 taken 3 times.
|
320 | if (!data.isFctPtrCall()) { |
| 283 |
1/2✗ Branch 364 → 365 not taken.
✓ Branch 364 → 366 taken 317 times.
|
317 | assert(callee != nullptr); |
| 284 |
1/2✓ Branch 366 → 367 taken 317 times.
✗ Branch 366 → 368 not taken.
|
317 | auto fctDef = dynamic_cast<const FctDefNode *>(callee->declNode); |
| 285 |
12/18✓ Branch 369 → 370 taken 204 times.
✓ Branch 369 → 377 taken 113 times.
✓ Branch 370 → 371 taken 27 times.
✓ Branch 370 → 377 taken 177 times.
✓ Branch 373 → 374 taken 27 times.
✗ Branch 373 → 497 not taken.
✓ Branch 374 → 375 taken 27 times.
✗ Branch 374 → 497 not taken.
✓ Branch 375 → 376 taken 26 times.
✓ Branch 375 → 377 taken 1 time.
✓ Branch 378 → 379 taken 27 times.
✓ Branch 378 → 380 taken 290 times.
✓ Branch 380 → 381 taken 27 times.
✓ Branch 380 → 383 taken 290 times.
✗ Branch 497 → 498 not taken.
✗ Branch 497 → 499 not taken.
✗ Branch 501 → 502 not taken.
✗ Branch 501 → 504 not taken.
|
371 | ignoreUnusedReturnValue = fctDef && fctDef->attrs && fctDef->attrs->attrLst->hasAttr(ATTR_IGNORE_UNUSED_RETURN_VALUE); |
| 286 | } | ||
| 287 | |||
| 288 |
2/2✓ Branch 384 → 385 taken 294 times.
✓ Branch 384 → 387 taken 26 times.
|
320 | if (!ignoreUnusedReturnValue) |
| 289 |
1/2✓ Branch 385 → 386 taken 294 times.
✗ Branch 385 → 506 not taken.
|
294 | warnings.emplace_back(node->codeLoc, UNUSED_RETURN_VALUE, "The return value of the function call is unused"); |
| 290 | } | ||
| 291 | |||
| 292 |
2/4✓ Branch 387 → 388 taken 17546 times.
✗ Branch 387 → 507 not taken.
✓ Branch 388 → 389 taken 17546 times.
✗ Branch 388 → 507 not taken.
|
17546 | return ExprResult{node->setEvaluatedSymbolType(returnType, manIdx), anonymousSymbol}; |
| 293 | } | ||
| 294 | |||
| 295 | 11098 | bool TypeChecker::visitOrdinaryFctCall(FctCallNode *node, std::string fqFunctionName) const { | |
| 296 |
1/2✓ Branch 2 → 3 taken 11098 times.
✗ Branch 2 → 106 not taken.
|
11098 | FctCallNode::FctCallData &data = node->data.at(manIdx); |
| 297 | 11098 | auto &[callType, isImported, templateTypes, thisType, args, callee, calleeParentScope, compTimeVal, hasCompTimeVal] = data; | |
| 298 | |||
| 299 | // Check if this is a well-known ctor/fct call | ||
| 300 |
2/2✓ Branch 4 → 5 taken 11036 times.
✓ Branch 4 → 7 taken 62 times.
|
11098 | if (node->functionNameFragments.size() == 1) { |
| 301 |
1/2✓ Branch 5 → 6 taken 11036 times.
✗ Branch 5 → 106 not taken.
|
11036 | ensureLoadedRuntimeForTypeName(fqFunctionName); |
| 302 |
1/2✓ Branch 6 → 7 taken 11036 times.
✗ Branch 6 → 106 not taken.
|
11036 | ensureLoadedRuntimeForFunctionName(fqFunctionName); |
| 303 | } | ||
| 304 | |||
| 305 | // Check if the type is generic (possible in case of ctor call) | ||
| 306 |
1/2✓ Branch 7 → 8 taken 11098 times.
✗ Branch 7 → 106 not taken.
|
11098 | const QualType *genericType = rootScope->lookupGenericTypeStrict(fqFunctionName); |
| 307 |
6/8✓ Branch 8 → 9 taken 1 time.
✓ Branch 8 → 12 taken 11097 times.
✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 106 not taken.
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 12 not taken.
✓ Branch 13 → 14 taken 1 time.
✓ Branch 13 → 19 taken 11097 times.
|
11098 | if (genericType && typeMapping.contains(fqFunctionName)) { |
| 308 |
1/2✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 106 not taken.
|
1 | const QualType &replacementType = typeMapping.at(fqFunctionName); |
| 309 |
2/4✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 106 not taken.
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 19 not taken.
|
1 | if (replacementType.is(TY_STRUCT)) |
| 310 |
2/4✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 106 not taken.
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 106 not taken.
|
1 | fqFunctionName = replacementType.getSubType(); |
| 311 | } | ||
| 312 | |||
| 313 | // Check if the exported name registry contains that function name | ||
| 314 |
1/2✓ Branch 19 → 20 taken 11098 times.
✗ Branch 19 → 106 not taken.
|
11098 | const NameRegistryEntry *functionRegistryEntry = sourceFile->getNameRegistryEntry(fqFunctionName); |
| 315 |
2/2✓ Branch 20 → 21 taken 3 times.
✓ Branch 20 → 29 taken 11095 times.
|
11098 | if (!functionRegistryEntry) { |
| 316 |
2/4✓ Branch 22 → 23 taken 3 times.
✗ Branch 22 → 86 not taken.
✓ Branch 23 → 24 taken 3 times.
✗ Branch 23 → 84 not taken.
|
3 | const std::string msg = "Function/procedure/struct '" + node->functionNameFragments.back() + "' could not be found"; |
| 317 |
1/2✓ Branch 25 → 26 taken 3 times.
✗ Branch 25 → 87 not taken.
|
3 | SOFT_ERROR_BOOL(node, REFERENCED_UNDEFINED_FUNCTION, msg) |
| 318 | 3 | } | |
| 319 | 11095 | const SymbolTableEntry *functionEntry = functionRegistryEntry->targetEntry; | |
| 320 | 11095 | calleeParentScope = functionRegistryEntry->targetScope; | |
| 321 | |||
| 322 | // Check if the target symbol is a struct -> this must be a constructor call | ||
| 323 |
1/2✓ Branch 30 → 31 taken 11095 times.
✗ Branch 30 → 106 not taken.
|
11095 | std::string functionName = node->functionNameFragments.back(); |
| 324 |
7/10✓ Branch 31 → 32 taken 11095 times.
✗ Branch 31 → 36 not taken.
✓ Branch 32 → 33 taken 11095 times.
✗ Branch 32 → 104 not taken.
✓ Branch 33 → 34 taken 11095 times.
✗ Branch 33 → 104 not taken.
✓ Branch 34 → 35 taken 2441 times.
✓ Branch 34 → 36 taken 8654 times.
✓ Branch 37 → 38 taken 2441 times.
✓ Branch 37 → 54 taken 8654 times.
|
11095 | if (functionEntry != nullptr && functionEntry->getQualType().is(TY_STRUCT)) { |
| 325 | 2441 | callType = FctCallNode::FctCallType::TYPE_CTOR; | |
| 326 |
1/2✓ Branch 38 → 39 taken 2441 times.
✗ Branch 38 → 104 not taken.
|
2441 | functionName = CTOR_FUNCTION_NAME; |
| 327 | |||
| 328 | 2441 | const NameRegistryEntry *structRegistryEntry = functionRegistryEntry; | |
| 329 | 2441 | const SymbolTableEntry *structEntry = functionEntry; | |
| 330 | |||
| 331 | // Substantiate potentially generic this struct | ||
| 332 |
2/4✓ Branch 39 → 40 taken 2441 times.
✗ Branch 39 → 104 not taken.
✓ Branch 40 → 41 taken 2441 times.
✗ Branch 40 → 104 not taken.
|
2441 | const Struct *thisStruct = structEntry->getQualType().getStruct(node, templateTypes); |
| 333 |
2/2✓ Branch 41 → 42 taken 1 time.
✓ Branch 41 → 51 taken 2440 times.
|
2441 | if (!thisStruct) { |
| 334 |
1/2✓ Branch 42 → 43 taken 1 time.
✗ Branch 42 → 97 not taken.
|
1 | const std::string signature = Struct::getSignature(structRegistryEntry->targetEntry->name, templateTypes); |
| 335 |
2/4✓ Branch 43 → 44 taken 1 time.
✗ Branch 43 → 92 not taken.
✓ Branch 44 → 45 taken 1 time.
✗ Branch 44 → 90 not taken.
|
1 | const std::string errorMsg = "Could not find struct candidate for struct '" + signature + "'. Do the template types match?"; |
| 336 |
1/2✓ Branch 46 → 47 taken 1 time.
✗ Branch 46 → 93 not taken.
|
1 | SOFT_ERROR_BOOL(node, UNKNOWN_DATATYPE, errorMsg) |
| 337 | 1 | } | |
| 338 | |||
| 339 | // Set the 'this' type of the function to the struct type | ||
| 340 |
2/4✓ Branch 51 → 52 taken 2440 times.
✗ Branch 51 → 98 not taken.
✓ Branch 52 → 53 taken 2440 times.
✗ Branch 52 → 98 not taken.
|
2440 | thisType = structEntry->getQualType().getWithBodyScope(thisStruct->scope); |
| 341 | 2440 | calleeParentScope = thisStruct->scope; | |
| 342 | } | ||
| 343 | |||
| 344 | // Attach the concrete template types to the 'this' type | ||
| 345 |
7/8✓ Branch 54 → 55 taken 11094 times.
✗ Branch 54 → 104 not taken.
✓ Branch 55 → 56 taken 2440 times.
✓ Branch 55 → 59 taken 8654 times.
✓ Branch 57 → 58 taken 398 times.
✓ Branch 57 → 59 taken 2042 times.
✓ Branch 60 → 61 taken 398 times.
✓ Branch 60 → 63 taken 10696 times.
|
11094 | if (!thisType.is(TY_DYN) && !templateTypes.empty()) |
| 346 |
1/2✓ Branch 61 → 62 taken 398 times.
✗ Branch 61 → 99 not taken.
|
398 | thisType = thisType.getWithTemplateTypes(templateTypes); |
| 347 | |||
| 348 | // Map local arg types to imported types | ||
| 349 |
5/8✓ Branch 63 → 64 taken 11094 times.
✗ Branch 63 → 101 not taken.
✓ Branch 64 → 65 taken 11094 times.
✗ Branch 64 → 101 not taken.
✓ Branch 65 → 66 taken 11094 times.
✗ Branch 65 → 101 not taken.
✓ Branch 71 → 67 taken 19532 times.
✓ Branch 71 → 72 taken 11094 times.
|
30626 | for (QualType &argType : args | std::views::keys) |
| 350 |
1/2✓ Branch 68 → 69 taken 19532 times.
✗ Branch 68 → 100 not taken.
|
19532 | argType = mapLocalTypeToImportedScopeType(calleeParentScope, argType); |
| 351 | |||
| 352 | // Map local template types to imported types | ||
| 353 |
2/2✓ Branch 78 → 74 taken 1730 times.
✓ Branch 78 → 79 taken 11094 times.
|
12824 | for (QualType &templateType : templateTypes) |
| 354 |
1/2✓ Branch 75 → 76 taken 1730 times.
✗ Branch 75 → 102 not taken.
|
1730 | templateType = mapLocalTypeToImportedScopeType(calleeParentScope, templateType); |
| 355 | |||
| 356 | // Retrieve function object | ||
| 357 | 11094 | Scope *matchScope = calleeParentScope; | |
| 358 |
2/2✓ Branch 79 → 80 taken 11092 times.
✓ Branch 79 → 104 taken 2 times.
|
11094 | callee = FunctionManager::match(matchScope, functionName, data.thisType, data.args, templateTypes, false, node); |
| 359 | |||
| 360 | 11092 | return true; | |
| 361 | 11095 | } | |
| 362 | |||
| 363 | 47 | bool TypeChecker::visitFctPtrCall(const FctCallNode *node, const QualType &functionType) const { | |
| 364 |
1/2✓ Branch 2 → 3 taken 47 times.
✗ Branch 2 → 75 not taken.
|
47 | const FctCallNode::FctCallData &data = node->data.at(manIdx); |
| 365 | 47 | const auto &[callType, isImported, templateTypes, thisType, args, callee, calleeParentScope, compTimeVal, hasCompTimeVal] = | |
| 366 | data; | ||
| 367 | |||
| 368 | // Check if the given argument types match the type | ||
| 369 |
1/2✓ Branch 3 → 4 taken 47 times.
✗ Branch 3 → 75 not taken.
|
47 | const QualTypeList expectedArgTypes = functionType.getFunctionParamTypes(); |
| 370 |
1/2✗ Branch 6 → 7 not taken.
✓ Branch 6 → 14 taken 47 times.
|
47 | if (args.size() != expectedArgTypes.size()) |
| 371 | ✗ | SOFT_ERROR_BOOL(node, REFERENCED_UNDEFINED_FUNCTION, "Expected and actual number of arguments do not match") | |
| 372 | |||
| 373 | // Create resolver function, that always returns a nullptr | ||
| 374 | 47 | TypeMatcher::ResolverFct resolverFct = [](const std::string &) { return nullptr; }; | |
| 375 | |||
| 376 |
2/2✓ Branch 41 → 16 taken 31 times.
✓ Branch 41 → 42 taken 47 times.
|
78 | for (size_t i = 0; i < args.size(); i++) { |
| 377 |
1/2✓ Branch 16 → 17 taken 31 times.
✗ Branch 16 → 71 not taken.
|
31 | const QualType &actualType = args.at(i).first; |
| 378 |
1/2✓ Branch 17 → 18 taken 31 times.
✗ Branch 17 → 71 not taken.
|
31 | const QualType &expectedType = expectedArgTypes.at(i); |
| 379 |
2/4✓ Branch 19 → 20 taken 31 times.
✗ Branch 19 → 68 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 34 taken 31 times.
|
31 | if (TypeMapping tm; !TypeMatcher::matchRequestedToCandidateType(expectedType, actualType, tm, resolverFct, false)) |
| 380 |
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 31 times.
✗ Branch 36 → 39 not taken.
|
31 | SOFT_ERROR_BOOL(node->argLst->args.at(i), REFERENCED_UNDEFINED_FUNCTION, |
| 381 | "Expected " + expectedType.getName(false) + " but got " + actualType.getName(false)) | ||
| 382 | } | ||
| 383 | 47 | return true; | |
| 384 | 47 | } | |
| 385 | |||
| 386 | 6422 | bool TypeChecker::visitMethodCall(FctCallNode *node, Scope *structScope) const { | |
| 387 | 6422 | FctCallNode::FctCallData &data = node->data.at(manIdx); | |
| 388 | 6422 | auto &[callType, isImported, templateTypes, thisType, args, callee, calleeParentScope, compTimeVal, hasCompTimeVal] = data; | |
| 389 | |||
| 390 | // Traverse through structs - the first fragment is already looked up and the last one is the method name | ||
| 391 |
2/2✓ Branch 41 → 4 taken 838 times.
✓ Branch 41 → 42 taken 6420 times.
|
7258 | for (size_t i = 1; i < node->functionNameFragments.size() - 1; i++) { |
| 392 | 838 | const std::string &identifier = node->functionNameFragments.at(i); | |
| 393 | |||
| 394 | // Retrieve field entry | ||
| 395 | 838 | SymbolTableEntry *fieldEntry = structScope->lookupStrict(identifier); | |
| 396 |
2/2✓ Branch 8 → 9 taken 1 time.
✓ Branch 8 → 24 taken 837 times.
|
838 | if (!fieldEntry) { |
| 397 |
1/2✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 82 not taken.
|
1 | std::stringstream errorMsg; |
| 398 |
1/2✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 80 not taken.
|
1 | errorMsg << "The type '"; |
| 399 |
3/6✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 75 not taken.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 75 not taken.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 73 not taken.
|
1 | errorMsg << thisType.getBase().getName(false, true); |
| 400 |
3/6✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 80 not taken.
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 80 not taken.
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 80 not taken.
|
1 | errorMsg << "' does not have a member with the name '" << identifier << "'"; |
| 401 |
2/4✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 79 not taken.
✓ Branch 19 → 20 taken 1 time.
✗ Branch 19 → 77 not taken.
|
1 | SOFT_ERROR_BOOL(node, ACCESS_TO_NON_EXISTING_MEMBER, errorMsg.str()) |
| 402 | 1 | } | |
| 403 |
5/8✓ Branch 24 → 25 taken 837 times.
✗ Branch 24 → 84 not taken.
✓ Branch 25 → 26 taken 837 times.
✗ Branch 25 → 84 not taken.
✓ Branch 26 → 27 taken 837 times.
✗ Branch 26 → 83 not taken.
✓ Branch 27 → 28 taken 1 time.
✓ Branch 27 → 34 taken 836 times.
|
837 | if (!fieldEntry->getQualType().getBase().isOneOf({TY_STRUCT, TY_INTERFACE})) |
| 404 |
3/6✓ Branch 28 → 29 taken 1 time.
✗ Branch 28 → 89 not taken.
✓ Branch 29 → 30 taken 1 time.
✗ Branch 29 → 87 not taken.
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 85 not taken.
|
1 | SOFT_ERROR_BOOL(node, INVALID_MEMBER_ACCESS, |
| 405 | "Cannot call a method on '" + identifier + "', since it is no struct or interface") | ||
| 406 | 836 | fieldEntry->used = true; | |
| 407 | |||
| 408 | // Get struct type and scope | ||
| 409 | 836 | thisType = fieldEntry->getQualType(); | |
| 410 |
2/4✓ Branch 35 → 36 taken 836 times.
✗ Branch 35 → 91 not taken.
✓ Branch 36 → 37 taken 836 times.
✗ Branch 36 → 91 not taken.
|
836 | structScope = thisType.getBase().getBodyScope(); |
| 411 |
1/2✗ Branch 37 → 38 not taken.
✓ Branch 37 → 39 taken 836 times.
|
836 | assert(structScope != nullptr); |
| 412 | } | ||
| 413 | |||
| 414 |
1/2✗ Branch 43 → 44 not taken.
✓ Branch 43 → 51 taken 6420 times.
|
6420 | if (thisType.is(TY_INTERFACE)) |
| 415 | ✗ | SOFT_ERROR_BOOL(node, INVALID_MEMBER_ACCESS, "Cannot call a method on an interface") | |
| 416 | |||
| 417 | // Map local arg types to imported types | ||
| 418 | 6420 | Scope *matchScope = calleeParentScope = structScope; | |
| 419 |
5/8✓ Branch 51 → 52 taken 6420 times.
✗ Branch 51 → 99 not taken.
✓ Branch 52 → 53 taken 6420 times.
✗ Branch 52 → 99 not taken.
✓ Branch 53 → 54 taken 6420 times.
✗ Branch 53 → 99 not taken.
✓ Branch 59 → 55 taken 4621 times.
✓ Branch 59 → 60 taken 6420 times.
|
11041 | for (QualType &argType : args | std::views::keys) |
| 420 |
1/2✓ Branch 56 → 57 taken 4621 times.
✗ Branch 56 → 98 not taken.
|
4621 | argType = mapLocalTypeToImportedScopeType(calleeParentScope, argType); |
| 421 | |||
| 422 | // Map local template types to imported types | ||
| 423 |
1/2✗ Branch 66 → 62 not taken.
✓ Branch 66 → 67 taken 6420 times.
|
6420 | for (QualType &templateType : templateTypes) |
| 424 | ✗ | templateType = mapLocalTypeToImportedScopeType(calleeParentScope, templateType); | |
| 425 | |||
| 426 | // 'this' type | ||
| 427 |
1/2✓ Branch 67 → 68 taken 6420 times.
✗ Branch 67 → 102 not taken.
|
6420 | thisType = thisType.autoDeReference(); |
| 428 |
1/2✓ Branch 68 → 69 taken 6420 times.
✗ Branch 68 → 103 not taken.
|
6420 | thisType = mapLocalTypeToImportedScopeType(calleeParentScope, thisType); |
| 429 | |||
| 430 | // Retrieve function object | ||
| 431 | 6420 | const std::string &functionName = node->functionNameFragments.back(); | |
| 432 | 6420 | callee = FunctionManager::match(matchScope, functionName, thisType, args, templateTypes, false, node); | |
| 433 | |||
| 434 | 6420 | return true; | |
| 435 | } | ||
| 436 | |||
| 437 | 79 | std::any TypeChecker::visitArrayInitialization(ArrayInitializationNode *node) { | |
| 438 |
5/6✓ Branch 2 → 3 taken 78 times.
✓ Branch 2 → 5 taken 1 time.
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 78 times.
✓ Branch 7 → 8 taken 1 time.
✓ Branch 7 → 18 taken 78 times.
|
79 | if (!node->itemLst || node->itemLst->args.empty()) |
| 439 |
4/8✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 68 not taken.
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 66 not taken.
✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 72 not taken.
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 72 not taken.
|
3 | SOFT_ERROR_ER(node, ARRAY_SIZE_INVALID, "Array initializers must at least contain one value"); |
| 440 | 78 | node->actualSize = node->itemLst->args.size(); | |
| 441 | |||
| 442 |
1/2✓ Branch 19 → 20 taken 78 times.
✗ Branch 19 → 97 not taken.
|
78 | QualType actualItemType(TY_DYN); |
| 443 | // Check if all values have the same type | ||
| 444 |
2/2✓ Branch 55 → 22 taken 514 times.
✓ Branch 55 → 56 taken 77 times.
|
591 | for (ExprNode *arg : node->itemLst->args) { |
| 445 |
2/4✓ Branch 23 → 24 taken 514 times.
✗ Branch 23 → 75 not taken.
✓ Branch 24 → 25 taken 514 times.
✗ Branch 24 → 73 not taken.
|
514 | const QualType itemType = std::any_cast<ExprResult>(visit(arg)).type; |
| 446 |
2/8✓ Branch 26 → 27 taken 514 times.
✗ Branch 26 → 94 not taken.
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 32 taken 514 times.
✗ Branch 28 → 29 not taken.
✗ Branch 28 → 77 not taken.
✗ Branch 29 → 30 not taken.
✗ Branch 29 → 77 not taken.
|
514 | HANDLE_UNRESOLVED_TYPE_ER(itemType) |
| 447 |
3/4✓ Branch 32 → 33 taken 514 times.
✗ Branch 32 → 94 not taken.
✓ Branch 33 → 34 taken 78 times.
✓ Branch 33 → 35 taken 436 times.
|
514 | if (actualItemType.is(TY_DYN)) // Perform type inference |
| 448 | 78 | actualItemType = itemType; | |
| 449 |
3/4✓ Branch 35 → 36 taken 436 times.
✗ Branch 35 → 94 not taken.
✓ Branch 36 → 37 taken 1 time.
✓ Branch 36 → 52 taken 435 times.
|
436 | else if (itemType != actualItemType) // Check if types are matching |
| 450 |
8/16✓ Branch 37 → 38 taken 1 time.
✗ Branch 37 → 91 not taken.
✓ Branch 38 → 39 taken 1 time.
✗ Branch 38 → 86 not taken.
✓ Branch 39 → 40 taken 1 time.
✗ Branch 39 → 84 not taken.
✓ Branch 40 → 41 taken 1 time.
✗ Branch 40 → 82 not taken.
✓ Branch 41 → 42 taken 1 time.
✗ Branch 41 → 80 not taken.
✓ Branch 42 → 43 taken 1 time.
✗ Branch 42 → 78 not taken.
✓ Branch 48 → 49 taken 1 time.
✗ Branch 48 → 93 not taken.
✓ Branch 49 → 50 taken 1 time.
✗ Branch 49 → 93 not taken.
|
1 | SOFT_ERROR_ER(arg, ARRAY_ITEM_TYPE_NOT_MATCHING, |
| 451 | "All provided values have to be of the same data type. You provided " + actualItemType.getName(false) + | ||
| 452 | " and " + itemType.getName(false)) | ||
| 453 | } | ||
| 454 |
2/4✓ Branch 56 → 57 taken 77 times.
✗ Branch 56 → 97 not taken.
✗ Branch 57 → 58 not taken.
✓ Branch 57 → 59 taken 77 times.
|
77 | assert(!actualItemType.is(TY_DYN)); |
| 455 | |||
| 456 |
1/2✓ Branch 59 → 60 taken 77 times.
✗ Branch 59 → 97 not taken.
|
77 | const QualType arrayType = actualItemType.toArr(node, node->actualSize, true); |
| 457 |
2/4✓ Branch 60 → 61 taken 77 times.
✗ Branch 60 → 96 not taken.
✓ Branch 61 → 62 taken 77 times.
✗ Branch 61 → 96 not taken.
|
77 | return ExprResult{node->setEvaluatedSymbolType(arrayType, manIdx)}; |
| 458 | } | ||
| 459 | |||
| 460 | 297 | std::any TypeChecker::visitStructInstantiation(StructInstantiationNode *node) { | |
| 461 | // Retrieve struct name | ||
| 462 |
1/2✓ Branch 2 → 3 taken 297 times.
✗ Branch 2 → 264 not taken.
|
297 | const auto [aliasedEntry, isAlias] = rootScope->symbolTable.lookupWithAliasResolution(node->fqStructName); |
| 463 |
4/6✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 9 taken 296 times.
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 264 not taken.
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 264 not taken.
|
297 | const std::string &structName = isAlias ? aliasedEntry->getQualType().getSubType() : node->fqStructName; |
| 464 | |||
| 465 | // Retrieve struct | ||
| 466 |
1/2✓ Branch 10 → 11 taken 297 times.
✗ Branch 10 → 264 not taken.
|
297 | const NameRegistryEntry *registryEntry = sourceFile->getNameRegistryEntry(structName); |
| 467 |
2/2✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 21 taken 296 times.
|
297 | if (!registryEntry) |
| 468 |
5/10✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 195 not taken.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 193 not taken.
✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 191 not taken.
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 197 not taken.
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 197 not taken.
|
1 | SOFT_ERROR_ER(node, REFERENCED_UNDEFINED_STRUCT, "Cannot find struct '" + structName + "'") |
| 469 |
2/4✓ Branch 21 → 22 taken 296 times.
✗ Branch 21 → 24 not taken.
✓ Branch 22 → 23 taken 296 times.
✗ Branch 22 → 24 not taken.
|
296 | assert(registryEntry->targetEntry != nullptr && registryEntry->targetScope != nullptr); |
| 470 | 296 | SymbolTableEntry *structEntry = registryEntry->targetEntry; | |
| 471 | |||
| 472 | // Check visibility | ||
| 473 |
9/12✓ Branch 25 → 26 taken 296 times.
✗ Branch 25 → 264 not taken.
✓ Branch 26 → 27 taken 296 times.
✗ Branch 26 → 264 not taken.
✓ Branch 27 → 28 taken 63 times.
✓ Branch 27 → 31 taken 233 times.
✓ Branch 28 → 29 taken 63 times.
✗ Branch 28 → 264 not taken.
✓ Branch 29 → 30 taken 1 time.
✓ Branch 29 → 31 taken 62 times.
✓ Branch 32 → 33 taken 1 time.
✓ Branch 32 → 42 taken 295 times.
|
296 | if (!structEntry->getQualType().isPublic() && structEntry->scope->isImportedBy(currentScope)) |
| 474 |
5/10✓ Branch 33 → 34 taken 1 time.
✗ Branch 33 → 202 not taken.
✓ Branch 34 → 35 taken 1 time.
✗ Branch 34 → 200 not taken.
✓ Branch 35 → 36 taken 1 time.
✗ Branch 35 → 198 not taken.
✓ Branch 38 → 39 taken 1 time.
✗ Branch 38 → 204 not taken.
✓ Branch 39 → 40 taken 1 time.
✗ Branch 39 → 204 not taken.
|
1 | SOFT_ERROR_ER(node, INSUFFICIENT_VISIBILITY, "Struct '" + structName + "' has insufficient visibility") |
| 475 | |||
| 476 | // Get struct type | ||
| 477 |
1/2✓ Branch 42 → 43 taken 295 times.
✗ Branch 42 → 264 not taken.
|
295 | QualType structType = structEntry->getQualType(); |
| 478 | |||
| 479 | // Get the concrete template types | ||
| 480 | 295 | QualTypeList concreteTemplateTypes; | |
| 481 |
2/2✓ Branch 43 → 44 taken 1 time.
✓ Branch 43 → 63 taken 294 times.
|
295 | if (isAlias) { |
| 482 | // Retrieve concrete template types from type alias | ||
| 483 |
3/6✓ Branch 44 → 45 taken 1 time.
✗ Branch 44 → 262 not taken.
✓ Branch 45 → 46 taken 1 time.
✗ Branch 45 → 262 not taken.
✓ Branch 46 → 47 taken 1 time.
✗ Branch 46 → 262 not taken.
|
1 | concreteTemplateTypes = aliasedEntry->getQualType().getTemplateTypes(); |
| 484 | // Check if the aliased type specified template types and the struct instantiation does | ||
| 485 |
3/6✓ Branch 48 → 49 taken 1 time.
✗ Branch 48 → 51 not taken.
✗ Branch 49 → 50 not taken.
✓ Branch 49 → 51 taken 1 time.
✗ Branch 52 → 53 not taken.
✓ Branch 52 → 63 taken 1 time.
|
1 | if (!concreteTemplateTypes.empty() && node->templateTypeLst) |
| 486 | ✗ | SOFT_ERROR_ER(node->templateTypeLst, ALIAS_WITH_TEMPLATE_LIST, "The aliased type already has a template list") | |
| 487 | } | ||
| 488 | |||
| 489 |
2/2✓ Branch 63 → 64 taken 19 times.
✓ Branch 63 → 96 taken 276 times.
|
295 | if (node->templateTypeLst) { |
| 490 |
1/2✓ Branch 65 → 66 taken 19 times.
✗ Branch 65 → 262 not taken.
|
19 | concreteTemplateTypes.reserve(node->templateTypeLst->dataTypes.size()); |
| 491 |
2/2✓ Branch 94 → 68 taken 31 times.
✓ Branch 94 → 95 taken 19 times.
|
50 | for (DataTypeNode *dataType : node->templateTypeLst->dataTypes) { |
| 492 |
2/4✓ Branch 69 → 70 taken 31 times.
✗ Branch 69 → 214 not taken.
✓ Branch 70 → 71 taken 31 times.
✗ Branch 70 → 212 not taken.
|
31 | auto concreteType = std::any_cast<QualType>(visit(dataType)); |
| 493 |
2/8✓ Branch 72 → 73 taken 31 times.
✗ Branch 72 → 223 not taken.
✗ Branch 73 → 74 not taken.
✓ Branch 73 → 78 taken 31 times.
✗ Branch 74 → 75 not taken.
✗ Branch 74 → 215 not taken.
✗ Branch 75 → 76 not taken.
✗ Branch 75 → 215 not taken.
|
31 | HANDLE_UNRESOLVED_TYPE_ER(concreteType) |
| 494 | // Check if generic type | ||
| 495 |
2/4✓ Branch 78 → 79 taken 31 times.
✗ Branch 78 → 223 not taken.
✗ Branch 79 → 80 not taken.
✓ Branch 79 → 90 taken 31 times.
|
31 | if (concreteType.is(TY_GENERIC)) |
| 496 | ✗ | SOFT_ERROR_ER(dataType, EXPECTED_NON_GENERIC_TYPE, "Struct instantiations may only take concrete template types") | |
| 497 |
1/2✓ Branch 90 → 91 taken 31 times.
✗ Branch 90 → 223 not taken.
|
31 | concreteTemplateTypes.push_back(concreteType); |
| 498 | } | ||
| 499 | } | ||
| 500 | |||
| 501 | // Get the struct instance | ||
| 502 |
2/4✓ Branch 96 → 97 taken 295 times.
✗ Branch 96 → 262 not taken.
✓ Branch 97 → 98 taken 295 times.
✗ Branch 97 → 262 not taken.
|
295 | Struct *spiceStruct = node->instantiatedStructs.at(manIdx) = structType.getStructAndAdjustType(node, concreteTemplateTypes); |
| 503 |
1/2✗ Branch 98 → 99 not taken.
✓ Branch 98 → 110 taken 295 times.
|
295 | if (!spiceStruct) |
| 504 | ✗ | SOFT_ERROR_ER(node, REFERENCED_UNDEFINED_STRUCT, | |
| 505 | "Struct '" + Struct::getSignature(structName, concreteTemplateTypes) + "' could not be found") | ||
| 506 | |||
| 507 | // Struct instantiation for an inheriting struct is forbidden, because the vtable needs to be initialized and this is done in | ||
| 508 | // the ctor of the struct, which is never called in case of struct instantiation | ||
| 509 |
2/2✓ Branch 111 → 112 taken 1 time.
✓ Branch 111 → 122 taken 294 times.
|
295 | if (!spiceStruct->interfaceTypes.empty()) |
| 510 |
4/8✓ Branch 114 → 115 taken 1 time.
✗ Branch 114 → 237 not taken.
✓ Branch 115 → 116 taken 1 time.
✗ Branch 115 → 235 not taken.
✓ Branch 118 → 119 taken 1 time.
✗ Branch 118 → 241 not taken.
✓ Branch 119 → 120 taken 1 time.
✗ Branch 119 → 241 not taken.
|
3 | SOFT_ERROR_ER(node, INVALID_STRUCT_INSTANTIATION, "Struct instantiations for inheriting structs are forbidden") |
| 511 | |||
| 512 | // Check if the number of fields matches | ||
| 513 |
2/2✓ Branch 122 → 123 taken 279 times.
✓ Branch 122 → 166 taken 15 times.
|
294 | if (node->fieldLst) { // Check if any fields are passed. Empty braces are also allowed |
| 514 |
2/2✓ Branch 125 → 126 taken 1 time.
✓ Branch 125 → 136 taken 278 times.
|
279 | if (spiceStruct->fieldTypes.size() != node->fieldLst->args.size()) |
| 515 |
4/8✓ Branch 128 → 129 taken 1 time.
✗ Branch 128 → 244 not taken.
✓ Branch 129 → 130 taken 1 time.
✗ Branch 129 → 242 not taken.
✓ Branch 132 → 133 taken 1 time.
✗ Branch 132 → 248 not taken.
✓ Branch 133 → 134 taken 1 time.
✗ Branch 133 → 248 not taken.
|
3 | SOFT_ERROR_ER(node->fieldLst, NUMBER_OF_FIELDS_NOT_MATCHING, |
| 516 | "You've passed too less/many field values. Pass either none or all of them") | ||
| 517 | |||
| 518 | // Check if the field types are matching | ||
| 519 | 278 | const size_t fieldCount = spiceStruct->fieldTypes.size(); | |
| 520 |
1/2✓ Branch 137 → 138 taken 278 times.
✗ Branch 137 → 262 not taken.
|
278 | const size_t explicitFieldsStartIdx = spiceStruct->scope->getFieldCount() - fieldCount; |
| 521 |
2/2✓ Branch 165 → 139 taken 413 times.
✓ Branch 165 → 178 taken 277 times.
|
690 | for (size_t i = 0; i < node->fieldLst->args.size(); i++) { |
| 522 | // Get actual type | ||
| 523 |
1/2✓ Branch 139 → 140 taken 413 times.
✗ Branch 139 → 253 not taken.
|
413 | ExprNode *assignExpr = node->fieldLst->args.at(i); |
| 524 |
2/4✓ Branch 140 → 141 taken 413 times.
✗ Branch 140 → 251 not taken.
✓ Branch 141 → 142 taken 413 times.
✗ Branch 141 → 249 not taken.
|
413 | auto fieldResult = std::any_cast<ExprResult>(visit(assignExpr)); |
| 525 |
2/8✓ Branch 143 → 144 taken 413 times.
✗ Branch 143 → 253 not taken.
✗ Branch 144 → 145 not taken.
✓ Branch 144 → 149 taken 413 times.
✗ Branch 145 → 146 not taken.
✗ Branch 145 → 252 not taken.
✗ Branch 146 → 147 not taken.
✗ Branch 146 → 252 not taken.
|
413 | HANDLE_UNRESOLVED_TYPE_ER(fieldResult.type) |
| 526 | // Get expected type | ||
| 527 |
1/2✗ Branch 149 → 150 not taken.
✓ Branch 149 → 151 taken 413 times.
|
413 | SymbolTableEntry *expectedField = spiceStruct->scope->lookupField(explicitFieldsStartIdx + i); |
| 528 |
1/2✗ Branch 154 → 155 not taken.
✓ Branch 154 → 156 taken 413 times.
|
413 | assert(expectedField != nullptr); |
| 529 |
1/2✓ Branch 156 → 157 taken 413 times.
✗ Branch 156 → 253 not taken.
|
413 | const ExprResult expected = {expectedField->getQualType(), expectedField}; |
| 530 |
1/2✓ Branch 157 → 158 taken 413 times.
✗ Branch 157 → 253 not taken.
|
413 | const bool rhsIsImmediate = assignExpr->hasCompileTimeValue(manIdx); |
| 531 | |||
| 532 | // Check if actual type matches expected type | ||
| 533 |
2/2✓ Branch 158 → 159 taken 412 times.
✓ Branch 158 → 253 taken 1 time.
|
413 | (void)opRuleManager.getFieldAssignResultType(assignExpr, expected, fieldResult, rhsIsImmediate, true); |
| 534 | |||
| 535 | // If there is an anonymous entry attached (e.g. for struct instantiation), delete it | ||
| 536 |
4/4✓ Branch 159 → 160 taken 111 times.
✓ Branch 159 → 163 taken 301 times.
✓ Branch 160 → 161 taken 3 times.
✓ Branch 160 → 163 taken 108 times.
|
412 | if (fieldResult.entry != nullptr && fieldResult.entry->anonymous) { |
| 537 |
1/2✓ Branch 161 → 162 taken 3 times.
✗ Branch 161 → 253 not taken.
|
3 | currentScope->symbolTable.deleteAnonymous(fieldResult.entry->name); |
| 538 | 3 | fieldResult.entry = nullptr; | |
| 539 | } | ||
| 540 | } | ||
| 541 | } else { | ||
| 542 |
2/4✓ Branch 166 → 167 taken 15 times.
✗ Branch 166 → 262 not taken.
✗ Branch 167 → 168 not taken.
✓ Branch 167 → 178 taken 15 times.
|
60 | if (std::ranges::any_of(spiceStruct->fieldTypes, [](const QualType &fieldType) { return fieldType.isRef(); })) |
| 543 | ✗ | SOFT_ERROR_ER(node, REFERENCE_WITHOUT_INITIALIZER, | |
| 544 | "The struct takes at least one reference field. You need to instantiate it with all fields.") | ||
| 545 | } | ||
| 546 | |||
| 547 | // Update type of struct entry | ||
| 548 |
1/2✓ Branch 178 → 179 taken 292 times.
✗ Branch 178 → 262 not taken.
|
292 | structEntry->updateType(structType, true); |
| 549 | |||
| 550 | // Add anonymous symbol to keep track of dtor call, if non-trivially destructible | ||
| 551 | 292 | SymbolTableEntry *anonymousEntry = nullptr; | |
| 552 |
3/4✓ Branch 179 → 180 taken 292 times.
✗ Branch 179 → 262 not taken.
✓ Branch 180 → 181 taken 29 times.
✓ Branch 180 → 183 taken 263 times.
|
292 | if (!structType.isTriviallyDestructible(node)) |
| 553 |
1/2✓ Branch 181 → 182 taken 29 times.
✗ Branch 181 → 262 not taken.
|
29 | anonymousEntry = currentScope->symbolTable.insertAnonymous(structType, node); |
| 554 | |||
| 555 | // Remove public qualifier to not have public local variables | ||
| 556 | 292 | structType.getQualifiers().isPublic = false; | |
| 557 | |||
| 558 |
2/4✓ Branch 184 → 185 taken 292 times.
✗ Branch 184 → 261 not taken.
✓ Branch 185 → 186 taken 292 times.
✗ Branch 185 → 261 not taken.
|
292 | return ExprResult{node->setEvaluatedSymbolType(structType, manIdx), anonymousEntry}; |
| 559 | 295 | } | |
| 560 | |||
| 561 | 16 | std::any TypeChecker::visitLambdaFunc(LambdaFuncNode *node) { | |
| 562 | // Check if all control paths in the lambda body return | ||
| 563 | 16 | bool returnsOnAllControlPaths = true; | |
| 564 |
3/4✓ Branch 2 → 3 taken 16 times.
✗ Branch 2 → 186 not taken.
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 14 taken 15 times.
|
16 | if (!node->returnsOnAllControlPaths(&returnsOnAllControlPaths, manIdx)) |
| 565 |
4/8✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 112 not taken.
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 110 not taken.
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 116 not taken.
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 116 not taken.
|
3 | SOFT_ERROR_ER(node, MISSING_RETURN_STMT, "Not all control paths of this lambda function have a return statement") |
| 566 | |||
| 567 | // Change to function scope | ||
| 568 |
2/4✓ Branch 14 → 15 taken 15 times.
✗ Branch 14 → 119 not taken.
✓ Branch 15 → 16 taken 15 times.
✗ Branch 15 → 117 not taken.
|
15 | Scope *bodyScope = currentScope->getChildScope(node->getScopeId()); |
| 569 |
1/2✓ Branch 17 → 18 taken 15 times.
✗ Branch 17 → 120 not taken.
|
15 | ScopeHandle scopeHandle(this, bodyScope, ScopeType::LAMBDA_BODY); |
| 570 | |||
| 571 | // Visit return type | ||
| 572 |
2/4✓ Branch 18 → 19 taken 15 times.
✗ Branch 18 → 123 not taken.
✓ Branch 19 → 20 taken 15 times.
✗ Branch 19 → 121 not taken.
|
15 | const auto returnType = std::any_cast<QualType>(visit(node->returnType)); |
| 573 |
2/8✓ Branch 21 → 22 taken 15 times.
✗ Branch 21 → 184 not taken.
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 27 taken 15 times.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 124 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 124 not taken.
|
15 | HANDLE_UNRESOLVED_TYPE_ER(returnType) |
| 574 |
3/4✓ Branch 27 → 28 taken 15 times.
✗ Branch 27 → 184 not taken.
✓ Branch 28 → 29 taken 1 time.
✓ Branch 28 → 39 taken 14 times.
|
15 | if (returnType.is(TY_DYN)) |
| 575 |
4/8✓ Branch 31 → 32 taken 1 time.
✗ Branch 31 → 127 not taken.
✓ Branch 32 → 33 taken 1 time.
✗ Branch 32 → 125 not taken.
✓ Branch 35 → 36 taken 1 time.
✗ Branch 35 → 131 not taken.
✓ Branch 36 → 37 taken 1 time.
✗ Branch 36 → 131 not taken.
|
3 | SOFT_ERROR_ER(node, UNEXPECTED_DYN_TYPE, "Dyn return types are not allowed") |
| 576 | |||
| 577 | // Set the type of the result variable | ||
| 578 |
1/2✓ Branch 41 → 42 taken 14 times.
✗ Branch 41 → 134 not taken.
|
42 | SymbolTableEntry *resultVarEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME); |
| 579 |
1/2✗ Branch 47 → 48 not taken.
✓ Branch 47 → 49 taken 14 times.
|
14 | assert(resultVarEntry != nullptr); |
| 580 |
1/2✓ Branch 49 → 50 taken 14 times.
✗ Branch 49 → 184 not taken.
|
14 | resultVarEntry->updateType(returnType, true); |
| 581 | 14 | resultVarEntry->used = true; | |
| 582 | |||
| 583 | // Visit parameters | ||
| 584 | 14 | QualTypeList paramTypes; | |
| 585 | 14 | ParamList paramList; | |
| 586 |
2/2✓ Branch 50 → 51 taken 10 times.
✓ Branch 50 → 72 taken 4 times.
|
14 | if (node->hasParams) { |
| 587 | // Visit param list to retrieve the param names | ||
| 588 |
2/4✓ Branch 51 → 52 taken 10 times.
✗ Branch 51 → 140 not taken.
✓ Branch 52 → 53 taken 10 times.
✗ Branch 52 → 138 not taken.
|
10 | auto namedParamList = std::any_cast<NamedParamList>(visit(node->paramLst)); |
| 589 |
2/2✓ Branch 69 → 56 taken 18 times.
✓ Branch 69 → 70 taken 10 times.
|
28 | for (const auto &[name, qualType, isOptional] : namedParamList) { |
| 590 |
1/2✗ Branch 57 → 58 not taken.
✓ Branch 57 → 65 taken 18 times.
|
18 | if (isOptional) |
| 591 | ✗ | softError(node, LAMBDA_WITH_OPTIONAL_PARAMS, "Lambdas cannot have optional parameters"); | |
| 592 | |||
| 593 |
1/2✓ Branch 65 → 66 taken 18 times.
✗ Branch 65 → 148 not taken.
|
18 | paramTypes.push_back(qualType); |
| 594 |
1/2✓ Branch 66 → 67 taken 18 times.
✗ Branch 66 → 147 not taken.
|
18 | paramList.push_back({qualType, isOptional}); |
| 595 | } | ||
| 596 | 10 | } | |
| 597 | |||
| 598 | // Visit lambda body | ||
| 599 |
2/2✓ Branch 72 → 73 taken 13 times.
✓ Branch 72 → 152 taken 1 time.
|
14 | visit(node->body); |
| 600 | |||
| 601 | // Leave function body scope | ||
| 602 |
1/2✓ Branch 74 → 75 taken 13 times.
✗ Branch 74 → 180 not taken.
|
13 | scopeHandle.leaveScopeEarly(); |
| 603 | |||
| 604 | // Prepare type of function | ||
| 605 |
1/2✓ Branch 75 → 76 taken 13 times.
✗ Branch 75 → 153 not taken.
|
13 | const QualType functionType = QualType(TY_FUNCTION) |
| 606 |
1/2✓ Branch 76 → 77 taken 13 times.
✗ Branch 76 → 153 not taken.
|
13 | .getWithFunctionParamAndReturnTypes(returnType, paramTypes) |
| 607 |
1/2✓ Branch 78 → 79 taken 13 times.
✗ Branch 78 → 153 not taken.
|
13 | .getWithLambdaCaptures(!bodyScope->symbolTable.captures.empty()); |
| 608 | |||
| 609 | // Create function object | ||
| 610 |
2/4✓ Branch 79 → 80 taken 13 times.
✗ Branch 79 → 157 not taken.
✓ Branch 80 → 81 taken 13 times.
✗ Branch 80 → 155 not taken.
|
13 | const std::string fctName = "lambda." + node->codeLoc.toPrettyLineAndColumn(); |
| 611 |
5/10✓ Branch 83 → 84 taken 13 times.
✗ Branch 83 → 166 not taken.
✓ Branch 84 → 85 taken 13 times.
✗ Branch 84 → 163 not taken.
✓ Branch 85 → 86 taken 13 times.
✗ Branch 85 → 162 not taken.
✓ Branch 86 → 87 taken 13 times.
✗ Branch 86 → 160 not taken.
✓ Branch 87 → 88 taken 13 times.
✗ Branch 87 → 158 not taken.
|
13 | node->manifestations.at(manIdx) = Function(fctName, nullptr, QualType(TY_DYN), returnType, paramList, {}, node); |
| 612 |
1/2✓ Branch 93 → 94 taken 13 times.
✗ Branch 93 → 178 not taken.
|
13 | node->manifestations.at(manIdx).bodyScope = bodyScope; |
| 613 |
3/6✓ Branch 94 → 95 taken 13 times.
✗ Branch 94 → 175 not taken.
✓ Branch 95 → 96 taken 13 times.
✗ Branch 95 → 173 not taken.
✓ Branch 96 → 97 taken 13 times.
✗ Branch 96 → 171 not taken.
|
13 | node->manifestations.at(manIdx).mangleSuffix = "." + std::to_string(manIdx); |
| 614 | |||
| 615 | // Check special requirements if this is an async lambda | ||
| 616 |
1/2✓ Branch 100 → 101 taken 13 times.
✗ Branch 100 → 178 not taken.
|
13 | (void)checkAsyncLambdaCaptureRules(node, node->lambdaAttr); |
| 617 | |||
| 618 |
2/4✓ Branch 101 → 102 taken 13 times.
✗ Branch 101 → 177 not taken.
✓ Branch 102 → 103 taken 13 times.
✗ Branch 102 → 177 not taken.
|
13 | return ExprResult{node->setEvaluatedSymbolType(functionType, manIdx)}; |
| 619 | 17 | } | |
| 620 | |||
| 621 | 21 | std::any TypeChecker::visitLambdaProc(LambdaProcNode *node) { | |
| 622 | // Mark unreachable statements | ||
| 623 | 21 | bool doSetPredecessorsUnreachable = true; | |
| 624 |
1/2✓ Branch 2 → 3 taken 21 times.
✗ Branch 2 → 123 not taken.
|
21 | node->returnsOnAllControlPaths(&doSetPredecessorsUnreachable, manIdx); |
| 625 | |||
| 626 | // Change to function scope | ||
| 627 |
2/4✓ Branch 3 → 4 taken 21 times.
✗ Branch 3 → 71 not taken.
✓ Branch 4 → 5 taken 21 times.
✗ Branch 4 → 69 not taken.
|
21 | Scope *bodyScope = currentScope->getChildScope(node->getScopeId()); |
| 628 |
1/2✓ Branch 6 → 7 taken 21 times.
✗ Branch 6 → 72 not taken.
|
21 | ScopeHandle scopeHandle(this, bodyScope, ScopeType::LAMBDA_BODY); |
| 629 | |||
| 630 | // Visit parameters | ||
| 631 | 21 | QualTypeList paramTypes; | |
| 632 | 21 | ParamList paramList; | |
| 633 |
2/2✓ Branch 7 → 8 taken 11 times.
✓ Branch 7 → 29 taken 10 times.
|
21 | if (node->hasParams) { |
| 634 | // Visit param list to retrieve the param names | ||
| 635 |
2/4✓ Branch 8 → 9 taken 11 times.
✗ Branch 8 → 75 not taken.
✓ Branch 9 → 10 taken 11 times.
✗ Branch 9 → 73 not taken.
|
11 | auto namedParamList = std::any_cast<NamedParamList>(visit(node->paramLst)); |
| 636 |
2/2✓ Branch 26 → 13 taken 19 times.
✓ Branch 26 → 27 taken 11 times.
|
30 | for (const auto &[_, qualType, isOptional] : namedParamList) { |
| 637 |
2/2✓ Branch 14 → 15 taken 1 time.
✓ Branch 14 → 22 taken 18 times.
|
19 | if (isOptional) |
| 638 |
2/4✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 78 not taken.
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 76 not taken.
|
2 | softError(node, LAMBDA_WITH_OPTIONAL_PARAMS, "Lambdas cannot have optional parameters"); |
| 639 | |||
| 640 |
1/2✓ Branch 22 → 23 taken 19 times.
✗ Branch 22 → 83 not taken.
|
19 | paramTypes.push_back(qualType); |
| 641 |
1/2✓ Branch 23 → 24 taken 19 times.
✗ Branch 23 → 82 not taken.
|
19 | paramList.push_back({qualType, isOptional}); |
| 642 | } | ||
| 643 | 11 | } | |
| 644 | |||
| 645 | // Visit lambda body | ||
| 646 |
1/2✓ Branch 29 → 30 taken 21 times.
✗ Branch 29 → 87 not taken.
|
21 | visit(node->body); |
| 647 | |||
| 648 | // Leave function body scope | ||
| 649 |
1/2✓ Branch 31 → 32 taken 21 times.
✗ Branch 31 → 117 not taken.
|
21 | scopeHandle.leaveScopeEarly(); |
| 650 | |||
| 651 | // Prepare type of function | ||
| 652 |
1/2✓ Branch 32 → 33 taken 21 times.
✗ Branch 32 → 89 not taken.
|
21 | const QualType functionType = QualType(TY_PROCEDURE) |
| 653 |
2/4✓ Branch 33 → 34 taken 21 times.
✗ Branch 33 → 88 not taken.
✓ Branch 34 → 35 taken 21 times.
✗ Branch 34 → 88 not taken.
|
21 | .getWithFunctionParamAndReturnTypes(QualType(TY_DYN), paramTypes) |
| 654 |
1/2✓ Branch 36 → 37 taken 21 times.
✗ Branch 36 → 88 not taken.
|
21 | .getWithLambdaCaptures(!bodyScope->symbolTable.captures.empty()); |
| 655 | |||
| 656 | // Create function object | ||
| 657 |
2/4✓ Branch 37 → 38 taken 21 times.
✗ Branch 37 → 93 not taken.
✓ Branch 38 → 39 taken 21 times.
✗ Branch 38 → 91 not taken.
|
21 | const std::string fctName = "lambda." + node->codeLoc.toPrettyLineAndColumn(); |
| 658 |
6/12✓ Branch 41 → 42 taken 21 times.
✗ Branch 41 → 103 not taken.
✓ Branch 42 → 43 taken 21 times.
✗ Branch 42 → 100 not taken.
✓ Branch 43 → 44 taken 21 times.
✗ Branch 43 → 99 not taken.
✓ Branch 44 → 45 taken 21 times.
✗ Branch 44 → 98 not taken.
✓ Branch 45 → 46 taken 21 times.
✗ Branch 45 → 96 not taken.
✓ Branch 46 → 47 taken 21 times.
✗ Branch 46 → 94 not taken.
|
21 | node->manifestations.at(manIdx) = Function(fctName, nullptr, QualType(TY_DYN), QualType(TY_DYN), paramList, {}, node); |
| 659 |
1/2✓ Branch 52 → 53 taken 21 times.
✗ Branch 52 → 115 not taken.
|
21 | node->manifestations.at(manIdx).bodyScope = bodyScope; |
| 660 |
3/6✓ Branch 53 → 54 taken 21 times.
✗ Branch 53 → 112 not taken.
✓ Branch 54 → 55 taken 21 times.
✗ Branch 54 → 110 not taken.
✓ Branch 55 → 56 taken 21 times.
✗ Branch 55 → 108 not taken.
|
21 | node->manifestations.at(manIdx).mangleSuffix = "." + std::to_string(manIdx); |
| 661 | |||
| 662 | // Check special requirements if this is an async lambda | ||
| 663 |
1/2✓ Branch 59 → 60 taken 21 times.
✗ Branch 59 → 115 not taken.
|
21 | (void)checkAsyncLambdaCaptureRules(node, node->lambdaAttr); |
| 664 | |||
| 665 |
2/4✓ Branch 60 → 61 taken 21 times.
✗ Branch 60 → 114 not taken.
✓ Branch 61 → 62 taken 21 times.
✗ Branch 61 → 114 not taken.
|
42 | return ExprResult{node->setEvaluatedSymbolType(functionType, manIdx)}; |
| 666 | 21 | } | |
| 667 | |||
| 668 | 1 | std::any TypeChecker::visitLambdaExpr(LambdaExprNode *node) { | |
| 669 | // Change to function scope | ||
| 670 |
2/4✓ Branch 2 → 3 taken 1 time.
✗ Branch 2 → 90 not taken.
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 88 not taken.
|
1 | Scope *bodyScope = currentScope->getChildScope(node->getScopeId()); |
| 671 |
1/2✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 91 not taken.
|
1 | ScopeHandle scopeHandle(this, bodyScope, ScopeType::LAMBDA_BODY); |
| 672 | |||
| 673 | // Visit parameters | ||
| 674 | 1 | QualTypeList paramTypes; | |
| 675 | 1 | ParamList paramList; | |
| 676 |
1/2✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 28 not taken.
|
1 | if (node->hasParams) { |
| 677 | // Visit param list to retrieve the param names | ||
| 678 |
2/4✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 94 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 92 not taken.
|
1 | auto namedParamList = std::any_cast<NamedParamList>(visit(node->paramLst)); |
| 679 |
2/2✓ Branch 25 → 12 taken 2 times.
✓ Branch 25 → 26 taken 1 time.
|
3 | for (const NamedParam ¶m : namedParamList) { |
| 680 |
1/2✗ Branch 13 → 14 not taken.
✓ Branch 13 → 21 taken 2 times.
|
2 | if (param.isOptional) |
| 681 | ✗ | softError(node, LAMBDA_WITH_OPTIONAL_PARAMS, "Lambdas cannot have optional parameters"); | |
| 682 | |||
| 683 |
1/2✓ Branch 21 → 22 taken 2 times.
✗ Branch 21 → 102 not taken.
|
2 | paramTypes.push_back(param.qualType); |
| 684 |
1/2✓ Branch 22 → 23 taken 2 times.
✗ Branch 22 → 101 not taken.
|
2 | paramList.push_back({param.qualType, param.isOptional}); |
| 685 | } | ||
| 686 | 1 | } | |
| 687 | |||
| 688 | // Visit lambda expression | ||
| 689 |
2/4✓ Branch 28 → 29 taken 1 time.
✗ Branch 28 → 108 not taken.
✓ Branch 29 → 30 taken 1 time.
✗ Branch 29 → 106 not taken.
|
1 | const QualType returnType = std::any_cast<ExprResult>(visit(node->lambdaExpr)).type; |
| 690 |
2/8✓ Branch 31 → 32 taken 1 time.
✗ Branch 31 → 145 not taken.
✗ Branch 32 → 33 not taken.
✓ Branch 32 → 37 taken 1 time.
✗ Branch 33 → 34 not taken.
✗ Branch 33 → 110 not taken.
✗ Branch 34 → 35 not taken.
✗ Branch 34 → 110 not taken.
|
1 | HANDLE_UNRESOLVED_TYPE_ER(returnType) |
| 691 |
2/4✓ Branch 37 → 38 taken 1 time.
✗ Branch 37 → 145 not taken.
✗ Branch 38 → 39 not taken.
✓ Branch 38 → 49 taken 1 time.
|
1 | if (returnType.is(TY_DYN)) |
| 692 | ✗ | SOFT_ERROR_ER(node, UNEXPECTED_DYN_TYPE, "Dyn return types are not allowed") | |
| 693 | |||
| 694 | // Leave function body scope | ||
| 695 |
1/2✓ Branch 49 → 50 taken 1 time.
✗ Branch 49 → 145 not taken.
|
1 | scopeHandle.leaveScopeEarly(); |
| 696 | |||
| 697 | // Prepare type of function | ||
| 698 |
2/4✓ Branch 50 → 51 taken 1 time.
✗ Branch 50 → 145 not taken.
✗ Branch 51 → 52 not taken.
✓ Branch 51 → 53 taken 1 time.
|
1 | const SuperType superType = returnType.is(TY_DYN) ? TY_PROCEDURE : TY_FUNCTION; |
| 699 |
1/2✓ Branch 54 → 55 taken 1 time.
✗ Branch 54 → 118 not taken.
|
1 | const QualType functionType = QualType(superType) |
| 700 |
1/2✓ Branch 55 → 56 taken 1 time.
✗ Branch 55 → 118 not taken.
|
1 | .getWithFunctionParamAndReturnTypes(returnType, paramTypes) |
| 701 |
1/2✓ Branch 57 → 58 taken 1 time.
✗ Branch 57 → 118 not taken.
|
1 | .getWithLambdaCaptures(!bodyScope->symbolTable.captures.empty()); |
| 702 | |||
| 703 | // Create function object | ||
| 704 |
2/4✓ Branch 58 → 59 taken 1 time.
✗ Branch 58 → 122 not taken.
✓ Branch 59 → 60 taken 1 time.
✗ Branch 59 → 120 not taken.
|
1 | const std::string fctName = "lambda." + node->codeLoc.toPrettyLineAndColumn(); |
| 705 |
5/10✓ Branch 62 → 63 taken 1 time.
✗ Branch 62 → 131 not taken.
✓ Branch 63 → 64 taken 1 time.
✗ Branch 63 → 128 not taken.
✓ Branch 64 → 65 taken 1 time.
✗ Branch 64 → 127 not taken.
✓ Branch 65 → 66 taken 1 time.
✗ Branch 65 → 125 not taken.
✓ Branch 66 → 67 taken 1 time.
✗ Branch 66 → 123 not taken.
|
1 | node->manifestations.at(manIdx) = Function(fctName, nullptr, QualType(TY_DYN), returnType, paramList, {}, node); |
| 706 |
1/2✓ Branch 72 → 73 taken 1 time.
✗ Branch 72 → 143 not taken.
|
1 | node->manifestations.at(manIdx).bodyScope = bodyScope; |
| 707 |
3/6✓ Branch 73 → 74 taken 1 time.
✗ Branch 73 → 140 not taken.
✓ Branch 74 → 75 taken 1 time.
✗ Branch 74 → 138 not taken.
✓ Branch 75 → 76 taken 1 time.
✗ Branch 75 → 136 not taken.
|
1 | node->manifestations.at(manIdx).mangleSuffix = "." + std::to_string(manIdx); |
| 708 | |||
| 709 |
2/4✓ Branch 79 → 80 taken 1 time.
✗ Branch 79 → 142 not taken.
✓ Branch 80 → 81 taken 1 time.
✗ Branch 80 → 142 not taken.
|
1 | return ExprResult{node->setEvaluatedSymbolType(functionType, manIdx)}; |
| 710 | 1 | } | |
| 711 | |||
| 712 | } // namespace spice::compiler | ||
| 713 |