src/typechecker/OpRuleManager.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2026 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #include "OpRuleManager.h" | ||
| 4 | |||
| 5 | #include <SourceFile.h> | ||
| 6 | #include <ast/ASTNodes.h> | ||
| 7 | #include <global/GlobalResourceManager.h> | ||
| 8 | #include <symboltablebuilder/Scope.h> | ||
| 9 | #include <typechecker/FunctionManager.h> | ||
| 10 | #include <typechecker/MacroDefs.h> | ||
| 11 | #include <typechecker/TypeChecker.h> | ||
| 12 | |||
| 13 | namespace spice::compiler { | ||
| 14 | |||
| 15 | 3950 | OpRuleManager::OpRuleManager(TypeChecker *typeChecker) | |
| 16 | 3950 | : typeChecker(typeChecker), resourceManager(typeChecker->resourceManager) {} | |
| 17 | |||
| 18 | 29359 | std::pair<QualType, Function *> OpRuleManager::getAssignResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, | |
| 19 | bool isDecl, bool isReturn, const char *errMsgPrefix) const { | ||
| 20 | // Retrieve types | ||
| 21 | 29359 | const QualType lhsType = lhs.type; | |
| 22 | 29359 | const QualType rhsType = rhs.type; | |
| 23 | |||
| 24 | // Check if lhs is a temporary | ||
| 25 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 12 taken 29358 times.
|
29359 | if (lhs.isTemporary()) |
| 26 |
2/4✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 88 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 85 not taken.
|
3 | throw SemanticError(node, OPERATOR_WRONG_DATA_TYPE, "Cannot assign to a temporary value"); |
| 27 | |||
| 28 | // Skip type compatibility check if the lhs is of type dyn -> perform type inference | ||
| 29 |
3/4✓ Branch 12 → 13 taken 29358 times.
✗ Branch 12 → 100 not taken.
✓ Branch 13 → 14 taken 86 times.
✓ Branch 13 → 16 taken 29272 times.
|
29358 | if (lhsType.is(TY_DYN)) |
| 30 | 86 | return {rhsType, nullptr}; | |
| 31 | |||
| 32 | // Check if we try to assign a constant value | ||
| 33 |
1/2✓ Branch 16 → 17 taken 29272 times.
✗ Branch 16 → 100 not taken.
|
29272 | ensureNoConstAssign(node, lhsType, isDecl, isReturn); |
| 34 | |||
| 35 | // Allow pointers and references of the same type straight away | ||
| 36 |
8/10✓ Branch 17 → 18 taken 29272 times.
✗ Branch 17 → 94 not taken.
✓ Branch 18 → 19 taken 4137 times.
✓ Branch 18 → 22 taken 25135 times.
✓ Branch 19 → 20 taken 4137 times.
✗ Branch 19 → 94 not taken.
✓ Branch 20 → 21 taken 3452 times.
✓ Branch 20 → 22 taken 685 times.
✓ Branch 23 → 24 taken 3452 times.
✓ Branch 23 → 41 taken 25820 times.
|
29272 | if (lhsType.isOneOf({TY_PTR, TY_REF}) && lhsType.matches(rhsType, false, false, true)) { |
| 37 | // If we perform a heap x* = heap x* assignment, we need set the right hand side to MOVED | ||
| 38 |
15/22✓ Branch 24 → 25 taken 1093 times.
✓ Branch 24 → 35 taken 2359 times.
✓ Branch 25 → 26 taken 1093 times.
✗ Branch 25 → 95 not taken.
✓ Branch 26 → 27 taken 742 times.
✓ Branch 26 → 35 taken 351 times.
✓ Branch 27 → 28 taken 742 times.
✗ Branch 27 → 95 not taken.
✓ Branch 28 → 29 taken 602 times.
✓ Branch 28 → 35 taken 140 times.
✓ Branch 29 → 30 taken 602 times.
✗ Branch 29 → 95 not taken.
✓ Branch 30 → 31 taken 602 times.
✗ Branch 30 → 95 not taken.
✓ Branch 31 → 32 taken 602 times.
✗ Branch 31 → 35 not taken.
✓ Branch 32 → 33 taken 602 times.
✗ Branch 32 → 95 not taken.
✓ Branch 33 → 34 taken 602 times.
✗ Branch 33 → 35 not taken.
✓ Branch 36 → 37 taken 602 times.
✓ Branch 36 → 39 taken 2850 times.
|
3452 | if (rhs.entry && lhsType.isPtr() && lhsType.isHeap() && rhsType.removeReferenceWrapper().isPtr() && rhsType.isHeap()) |
| 39 |
1/2✓ Branch 37 → 38 taken 602 times.
✗ Branch 37 → 96 not taken.
|
602 | rhs.entry->updateState(MOVED, node); |
| 40 | 3452 | return {rhsType, nullptr}; | |
| 41 | } | ||
| 42 | // Allow ref type to type of the same contained type straight away | ||
| 43 |
3/4✓ Branch 41 → 42 taken 25820 times.
✗ Branch 41 → 100 not taken.
✓ Branch 42 → 43 taken 396 times.
✓ Branch 42 → 55 taken 25424 times.
|
25820 | if (rhsType.isRef()) { |
| 44 | // If this is const ref, remove both: the reference and the constness | ||
| 45 |
2/4✓ Branch 43 → 44 taken 396 times.
✗ Branch 43 → 97 not taken.
✓ Branch 44 → 45 taken 396 times.
✗ Branch 44 → 97 not taken.
|
396 | const QualType rhsNonRef = rhsType.getContained().toNonConst(); |
| 46 |
3/4✓ Branch 45 → 46 taken 396 times.
✗ Branch 45 → 98 not taken.
✓ Branch 46 → 47 taken 394 times.
✓ Branch 46 → 53 taken 2 times.
|
396 | if (lhsType.matches(rhsNonRef, false, false, true)) { |
| 47 |
3/4✓ Branch 47 → 48 taken 394 times.
✗ Branch 47 → 98 not taken.
✓ Branch 48 → 49 taken 249 times.
✓ Branch 48 → 51 taken 145 times.
|
394 | if (rhsNonRef.is(TY_STRUCT)) |
| 48 |
1/2✓ Branch 49 → 50 taken 249 times.
✗ Branch 49 → 98 not taken.
|
394 | return performStructAssign(node, lhs, rhs, rhsNonRef, isDecl, isReturn); |
| 49 | 145 | return {lhsType, nullptr}; | |
| 50 | } | ||
| 51 | } | ||
| 52 | // Allow arrays, structs, interfaces, functions, procedures of the same type straight away | ||
| 53 |
8/10✓ Branch 55 → 56 taken 25426 times.
✗ Branch 55 → 99 not taken.
✓ Branch 56 → 57 taken 84 times.
✓ Branch 56 → 60 taken 25342 times.
✓ Branch 57 → 58 taken 84 times.
✗ Branch 57 → 99 not taken.
✓ Branch 58 → 59 taken 79 times.
✓ Branch 58 → 60 taken 5 times.
✓ Branch 61 → 62 taken 79 times.
✓ Branch 61 → 64 taken 25347 times.
|
25426 | if (lhsType.isOneOf({TY_ARRAY, TY_INTERFACE, TY_FUNCTION, TY_PROCEDURE}) && lhsType.matches(rhsType, false, true, true)) |
| 54 | 79 | return {rhsType, nullptr}; | |
| 55 | // Allow struct of the same type straight away | ||
| 56 |
8/10✓ Branch 64 → 65 taken 25347 times.
✗ Branch 64 → 100 not taken.
✓ Branch 65 → 66 taken 2913 times.
✓ Branch 65 → 69 taken 22434 times.
✓ Branch 66 → 67 taken 2913 times.
✗ Branch 66 → 100 not taken.
✓ Branch 67 → 68 taken 2912 times.
✓ Branch 67 → 69 taken 1 time.
✓ Branch 70 → 71 taken 2912 times.
✓ Branch 70 → 73 taken 22435 times.
|
25347 | if (lhsType.is(TY_STRUCT) && lhsType.matches(rhsType, false, true, true)) |
| 57 |
1/2✓ Branch 71 → 72 taken 2912 times.
✗ Branch 71 → 100 not taken.
|
2912 | return performStructAssign(node, lhs, rhs, rhsType, isDecl, isReturn); |
| 58 | |||
| 59 | // Check common type combinations | ||
| 60 |
2/2✓ Branch 73 → 74 taken 22433 times.
✓ Branch 73 → 100 taken 2 times.
|
22435 | const QualType resultType = getAssignResultTypeCommon(node, lhs, rhs, isDecl, isReturn); |
| 61 |
3/4✓ Branch 74 → 75 taken 22433 times.
✗ Branch 74 → 100 not taken.
✓ Branch 75 → 76 taken 623 times.
✓ Branch 75 → 78 taken 21810 times.
|
22433 | if (!resultType.is(TY_INVALID)) |
| 62 | 623 | return {resultType, nullptr}; | |
| 63 | |||
| 64 | // Check primitive type combinations | ||
| 65 | const QualType binOpType = | ||
| 66 |
2/2✓ Branch 80 → 81 taken 21798 times.
✓ Branch 80 → 100 taken 12 times.
|
21810 | validateBinaryOperation(node, ASSIGN_OP_RULES, std::size(ASSIGN_OP_RULES), "=", lhsType, rhsType, true, errMsgPrefix); |
| 67 | 21798 | return {binOpType, nullptr}; | |
| 68 | } | ||
| 69 | |||
| 70 | 396 | QualType OpRuleManager::getFieldAssignResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, bool imm, | |
| 71 | bool isDecl) const { | ||
| 72 | // Retrieve types | ||
| 73 | 396 | const QualType lhsType = lhs.type; | |
| 74 | 396 | const QualType rhsType = rhs.type; | |
| 75 |
2/4✓ Branch 2 → 3 taken 396 times.
✗ Branch 2 → 100 not taken.
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 396 times.
|
396 | assert(!lhsType.is(TY_DYN)); |
| 76 | |||
| 77 | // Check if we try to assign a constant value | ||
| 78 |
1/2✓ Branch 5 → 6 taken 396 times.
✗ Branch 5 → 100 not taken.
|
396 | ensureNoConstAssign(node, lhsType, isDecl); |
| 79 | |||
| 80 | // Allow pointers, arrays and structs of the same type straight away | ||
| 81 |
8/10✓ Branch 6 → 7 taken 396 times.
✗ Branch 6 → 89 not taken.
✓ Branch 7 → 8 taken 228 times.
✓ Branch 7 → 11 taken 168 times.
✓ Branch 8 → 9 taken 228 times.
✗ Branch 8 → 89 not taken.
✓ Branch 9 → 10 taken 226 times.
✓ Branch 9 → 11 taken 2 times.
✓ Branch 12 → 13 taken 226 times.
✓ Branch 12 → 29 taken 170 times.
|
396 | if (lhsType.isOneOf({TY_PTR, TY_ARRAY}) && lhsType == rhsType) { |
| 82 | // If we perform a heap x* = heap x* assignment, we need set the right hand side to MOVED | ||
| 83 |
8/22✓ Branch 13 → 14 taken 70 times.
✓ Branch 13 → 24 taken 156 times.
✓ Branch 14 → 15 taken 70 times.
✗ Branch 14 → 90 not taken.
✓ Branch 15 → 16 taken 68 times.
✓ Branch 15 → 24 taken 2 times.
✓ Branch 16 → 17 taken 68 times.
✗ Branch 16 → 90 not taken.
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 24 taken 68 times.
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 90 not taken.
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 90 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 24 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 90 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 24 not taken.
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 28 taken 226 times.
|
226 | if (rhs.entry && lhsType.isPtr() && lhsType.isHeap() && rhsType.removeReferenceWrapper().isPtr() && rhsType.isHeap()) |
| 84 | ✗ | rhs.entry->updateState(MOVED, node); | |
| 85 | 226 | return rhsType; | |
| 86 | } | ||
| 87 | // Allow struct of the same type straight away | ||
| 88 |
8/10✓ Branch 29 → 30 taken 170 times.
✗ Branch 29 → 100 not taken.
✓ Branch 30 → 31 taken 18 times.
✓ Branch 30 → 34 taken 152 times.
✓ Branch 31 → 32 taken 18 times.
✗ Branch 31 → 100 not taken.
✓ Branch 32 → 33 taken 13 times.
✓ Branch 32 → 34 taken 5 times.
✓ Branch 35 → 36 taken 13 times.
✓ Branch 35 → 39 taken 157 times.
|
170 | if (lhsType.is(TY_STRUCT) && lhsType.matches(rhsType, false, true, true)) |
| 89 |
1/2✓ Branch 36 → 37 taken 13 times.
✗ Branch 36 → 92 not taken.
|
13 | return performStructAssign(node, lhs, rhs, rhsType, isDecl, false).first; |
| 90 | // Allow ref type to type of the same contained type straight away | ||
| 91 |
9/12✓ Branch 39 → 40 taken 157 times.
✗ Branch 39 → 93 not taken.
✓ Branch 40 → 41 taken 17 times.
✓ Branch 40 → 45 taken 140 times.
✓ Branch 41 → 42 taken 17 times.
✗ Branch 41 → 93 not taken.
✓ Branch 42 → 43 taken 17 times.
✗ Branch 42 → 93 not taken.
✓ Branch 43 → 44 taken 1 time.
✓ Branch 43 → 45 taken 16 times.
✓ Branch 46 → 47 taken 1 time.
✓ Branch 46 → 62 taken 156 times.
|
157 | if (rhsType.isRef() && lhsType.matches(rhsType.getContained(), false, false, true)) { |
| 92 | // Check is there is an overloaded operator function available | ||
| 93 |
1/2✓ Branch 47 → 48 taken 1 time.
✗ Branch 47 → 94 not taken.
|
1 | const auto [type, _] = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_ASSIGN, {lhs, rhs}, 0); |
| 94 |
2/4✓ Branch 48 → 49 taken 1 time.
✗ Branch 48 → 96 not taken.
✗ Branch 49 → 50 not taken.
✓ Branch 49 → 51 taken 1 time.
|
1 | if (!type.is(TY_INVALID)) |
| 95 | ✗ | return type; | |
| 96 | |||
| 97 | // In case of a return expression, we perform temp stealing | ||
| 98 |
4/10✓ Branch 51 → 52 taken 1 time.
✗ Branch 51 → 95 not taken.
✓ Branch 52 → 53 taken 1 time.
✗ Branch 52 → 95 not taken.
✗ Branch 53 → 54 not taken.
✓ Branch 53 → 57 taken 1 time.
✗ Branch 55 → 56 not taken.
✗ Branch 55 → 57 not taken.
✗ Branch 58 → 59 not taken.
✓ Branch 58 → 60 taken 1 time.
|
1 | if (rhsType.getContained().is(TY_STRUCT) && !rhs.isTemporary()) |
| 99 | ✗ | typeChecker->implicitlyCallStructCopyCtor(rhs.entry, rhs.entry->declNode); | |
| 100 | 1 | return lhsType; | |
| 101 | } | ||
| 102 | // Allow ref type to type of the same contained type straight away | ||
| 103 |
3/4✓ Branch 62 → 63 taken 156 times.
✗ Branch 62 → 100 not taken.
✓ Branch 63 → 64 taken 16 times.
✓ Branch 63 → 72 taken 140 times.
|
156 | if (rhsType.isRef()) { |
| 104 | // If this is const ref, remove both: the reference and the constness | ||
| 105 |
2/4✓ Branch 64 → 65 taken 16 times.
✗ Branch 64 → 97 not taken.
✓ Branch 65 → 66 taken 16 times.
✗ Branch 65 → 97 not taken.
|
16 | const QualType rhsNonRef = rhsType.getContained().toNonConst(); |
| 106 |
2/4✓ Branch 66 → 67 taken 16 times.
✗ Branch 66 → 99 not taken.
✓ Branch 67 → 68 taken 16 times.
✗ Branch 67 → 71 not taken.
|
16 | if (lhsType.matches(rhsNonRef, false, false, true)) |
| 107 |
1/2✓ Branch 68 → 69 taken 16 times.
✗ Branch 68 → 98 not taken.
|
16 | return performStructAssign(node, lhs, rhs, rhsNonRef, isDecl, false).first; |
| 108 | } | ||
| 109 | // Allow immediate value to const ref of the same contained type straight away | ||
| 110 |
6/8✓ Branch 72 → 73 taken 140 times.
✗ Branch 72 → 100 not taken.
✓ Branch 73 → 74 taken 1 time.
✓ Branch 73 → 76 taken 139 times.
✓ Branch 74 → 75 taken 1 time.
✗ Branch 74 → 76 not taken.
✓ Branch 77 → 78 taken 1 time.
✓ Branch 77 → 79 taken 139 times.
|
140 | if (lhsType.isConstRef() && imm) |
| 111 | 1 | return rhsType; | |
| 112 | |||
| 113 | // Check common type combinations | ||
| 114 |
1/2✓ Branch 79 → 80 taken 139 times.
✗ Branch 79 → 100 not taken.
|
139 | const QualType resultType = getAssignResultTypeCommon(node, lhs, rhs, isDecl, false); |
| 115 |
3/4✓ Branch 80 → 81 taken 139 times.
✗ Branch 80 → 100 not taken.
✓ Branch 81 → 82 taken 4 times.
✓ Branch 81 → 83 taken 135 times.
|
139 | if (!resultType.is(TY_INVALID)) |
| 116 | 4 | return resultType; | |
| 117 | |||
| 118 | // Check primitive type combinations | ||
| 119 |
2/2✓ Branch 85 → 86 taken 134 times.
✓ Branch 85 → 100 taken 1 time.
|
135 | return validateBinaryOperation(node, ASSIGN_OP_RULES, std::size(ASSIGN_OP_RULES), "=", lhsType, rhsType, true, |
| 120 | 134 | ERROR_FIELD_ASSIGN); | |
| 121 | } | ||
| 122 | |||
| 123 | 22574 | QualType OpRuleManager::getAssignResultTypeCommon(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, bool isDecl, | |
| 124 | bool isReturn) { | ||
| 125 | // Retrieve types | ||
| 126 | 22574 | const QualType lhsType = lhs.type; | |
| 127 | 22574 | const QualType rhsType = rhs.type; | |
| 128 | |||
| 129 | // Allow type to ref type of the same contained type straight away | ||
| 130 |
9/12✓ Branch 2 → 3 taken 22574 times.
✗ Branch 2 → 113 not taken.
✓ Branch 3 → 4 taken 460 times.
✓ Branch 3 → 8 taken 22114 times.
✓ Branch 4 → 5 taken 460 times.
✗ Branch 4 → 113 not taken.
✓ Branch 5 → 6 taken 460 times.
✗ Branch 5 → 113 not taken.
✓ Branch 6 → 7 taken 457 times.
✓ Branch 6 → 8 taken 3 times.
✓ Branch 9 → 10 taken 457 times.
✓ Branch 9 → 44 taken 22117 times.
|
22574 | if (lhsType.isRef() && lhsType.getContained().matches(rhsType, false, false, true)) { |
| 131 |
4/4✓ Branch 10 → 11 taken 389 times.
✓ Branch 10 → 12 taken 68 times.
✓ Branch 11 → 12 taken 320 times.
✓ Branch 11 → 13 taken 69 times.
|
457 | const bool isDeclOrReturn = isDecl || isReturn; |
| 132 |
7/8✓ Branch 14 → 15 taken 388 times.
✓ Branch 14 → 19 taken 69 times.
✓ Branch 16 → 17 taken 388 times.
✗ Branch 16 → 137 not taken.
✓ Branch 17 → 18 taken 1 time.
✓ Branch 17 → 19 taken 387 times.
✓ Branch 20 → 21 taken 1 time.
✓ Branch 20 → 29 taken 456 times.
|
457 | if (isDeclOrReturn && !lhsType.canBind(rhsType, rhs.isTemporary())) |
| 133 |
2/4✓ Branch 24 → 25 taken 1 time.
✗ Branch 24 → 117 not taken.
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 114 not taken.
|
3 | throw SemanticError(node, TEMP_TO_NON_CONST_REF, "Temporary values can only be bound to const reference variables/fields"); |
| 134 |
6/6✓ Branch 29 → 30 taken 320 times.
✓ Branch 29 → 33 taken 136 times.
✓ Branch 31 → 32 taken 1 time.
✓ Branch 31 → 33 taken 319 times.
✓ Branch 34 → 35 taken 1 time.
✓ Branch 34 → 43 taken 455 times.
|
456 | if (isReturn && rhs.isTemporary()) |
| 135 |
2/4✓ Branch 38 → 39 taken 1 time.
✗ Branch 38 → 126 not taken.
✓ Branch 39 → 40 taken 1 time.
✗ Branch 39 → 123 not taken.
|
3 | throw SemanticError(node, RETURN_OF_TEMPORARY_VALUE, "Cannot return reference to temporary value"); |
| 136 | 455 | return lhsType; | |
| 137 | } | ||
| 138 | // Allow char* = string | ||
| 139 |
9/14✓ Branch 44 → 45 taken 22117 times.
✗ Branch 44 → 137 not taken.
✓ Branch 45 → 46 taken 1 time.
✓ Branch 45 → 53 taken 22116 times.
✓ Branch 46 → 47 taken 1 time.
✗ Branch 46 → 137 not taken.
✓ Branch 47 → 48 taken 1 time.
✗ Branch 47 → 53 not taken.
✓ Branch 50 → 51 taken 1 time.
✗ Branch 50 → 137 not taken.
✓ Branch 51 → 52 taken 1 time.
✗ Branch 51 → 53 not taken.
✓ Branch 54 → 55 taken 1 time.
✓ Branch 54 → 56 taken 22116 times.
|
22117 | if (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING) && lhsType.getQualifiers() == rhsType.getQualifiers()) |
| 140 | 1 | return lhsType; | |
| 141 | // Allow array to pointer | ||
| 142 |
12/18✓ Branch 56 → 57 taken 22116 times.
✗ Branch 56 → 132 not taken.
✓ Branch 57 → 58 taken 171 times.
✓ Branch 57 → 65 taken 21945 times.
✓ Branch 58 → 59 taken 171 times.
✗ Branch 58 → 132 not taken.
✓ Branch 59 → 60 taken 6 times.
✓ Branch 59 → 65 taken 165 times.
✓ Branch 60 → 61 taken 6 times.
✗ Branch 60 → 132 not taken.
✓ Branch 61 → 62 taken 6 times.
✗ Branch 61 → 132 not taken.
✓ Branch 62 → 63 taken 6 times.
✗ Branch 62 → 132 not taken.
✓ Branch 63 → 64 taken 6 times.
✗ Branch 63 → 65 not taken.
✓ Branch 66 → 67 taken 6 times.
✓ Branch 66 → 68 taken 22110 times.
|
22116 | if (lhsType.isPtr() && rhsType.isArray() && lhsType.getContained().matches(rhsType.getContained(), false, false, true)) |
| 143 | 6 | return lhsType; | |
| 144 | // Allow interface* = struct* or interface& = struct that implements this interface | ||
| 145 |
1/2✓ Branch 70 → 71 taken 22110 times.
✗ Branch 70 → 137 not taken.
|
22110 | const bool sameChainDepth = Type::hasSameTypeChainDepth(lhsType.getType(), rhsType.getType()); |
| 146 |
10/14✓ Branch 71 → 72 taken 22110 times.
✗ Branch 71 → 137 not taken.
✓ Branch 72 → 73 taken 165 times.
✓ Branch 72 → 76 taken 21945 times.
✓ Branch 73 → 74 taken 165 times.
✗ Branch 73 → 137 not taken.
✓ Branch 74 → 75 taken 164 times.
✓ Branch 74 → 76 taken 1 time.
✗ Branch 75 → 76 not taken.
✓ Branch 75 → 78 taken 164 times.
✓ Branch 76 → 77 taken 21946 times.
✗ Branch 76 → 137 not taken.
✓ Branch 77 → 78 taken 3 times.
✓ Branch 77 → 79 taken 21943 times.
|
22110 | const bool typesCompatible = (lhsType.isPtr() && rhsType.isPtr() && sameChainDepth) || lhsType.isRef(); |
| 147 |
9/12✓ Branch 80 → 81 taken 167 times.
✓ Branch 80 → 86 taken 21943 times.
✓ Branch 81 → 82 taken 167 times.
✗ Branch 81 → 137 not taken.
✓ Branch 82 → 83 taken 5 times.
✓ Branch 82 → 86 taken 162 times.
✓ Branch 83 → 84 taken 5 times.
✗ Branch 83 → 137 not taken.
✓ Branch 84 → 85 taken 5 times.
✗ Branch 84 → 86 not taken.
✓ Branch 87 → 88 taken 5 times.
✓ Branch 87 → 93 taken 22105 times.
|
22110 | if (typesCompatible && lhsType.isBase(TY_INTERFACE) && rhsType.isBase(TY_STRUCT)) { |
| 148 | 5 | QualType lhsTypeCopy = lhsType; | |
| 149 | 5 | QualType rhsTypeCopy = rhsType; | |
| 150 |
1/2✓ Branch 88 → 89 taken 5 times.
✗ Branch 88 → 134 not taken.
|
5 | QualType::unwrapBothWithRefWrappers(lhsTypeCopy, rhsTypeCopy); |
| 151 |
2/4✓ Branch 89 → 90 taken 5 times.
✗ Branch 89 → 134 not taken.
✓ Branch 90 → 91 taken 5 times.
✗ Branch 90 → 92 not taken.
|
5 | if (lhsTypeCopy.matchesInterfaceImplementedByStruct(rhsTypeCopy)) |
| 152 | 5 | return lhsType; | |
| 153 | } | ||
| 154 | // Allow type* = heap type* straight away. This is used for initializing non-owning pointers to heap allocations | ||
| 155 |
10/14✓ Branch 93 → 94 taken 22105 times.
✗ Branch 93 → 137 not taken.
✓ Branch 94 → 95 taken 161 times.
✓ Branch 94 → 100 taken 21944 times.
✓ Branch 95 → 96 taken 161 times.
✗ Branch 95 → 137 not taken.
✓ Branch 96 → 97 taken 160 times.
✓ Branch 96 → 100 taken 1 time.
✓ Branch 97 → 98 taken 160 times.
✗ Branch 97 → 137 not taken.
✓ Branch 98 → 99 taken 160 times.
✗ Branch 98 → 100 not taken.
✓ Branch 101 → 102 taken 160 times.
✓ Branch 101 → 108 taken 21945 times.
|
22105 | if (lhsType.isPtr() && rhsType.isHeap() && lhsType.matches(rhsType, false, true, true)) { |
| 156 | 160 | TypeQualifiers rhsQualifiers = rhsType.getQualifiers(); | |
| 157 | 160 | rhsQualifiers.isHeap = false; | |
| 158 |
2/4✓ Branch 104 → 105 taken 160 times.
✗ Branch 104 → 135 not taken.
✓ Branch 105 → 106 taken 160 times.
✗ Branch 105 → 107 not taken.
|
160 | if (lhsType.getQualifiers() == rhsQualifiers) |
| 159 | 160 | return lhsType; | |
| 160 | } | ||
| 161 | |||
| 162 | // Nothing matched | ||
| 163 |
1/2✓ Branch 108 → 109 taken 21945 times.
✗ Branch 108 → 136 not taken.
|
21945 | return QualType(TY_INVALID); |
| 164 | } | ||
| 165 | |||
| 166 | 3190 | std::pair<QualType, Function *> OpRuleManager::performStructAssign(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, | |
| 167 | const QualType &rhsType, bool isDecl, bool isReturn) const { | ||
| 168 | 3190 | const bool rhsIsRef = rhs.type.isRef(); | |
| 169 | |||
| 170 | // Check is there is an overloaded operator function available | ||
| 171 |
8/8✓ Branch 3 → 4 taken 1876 times.
✓ Branch 3 → 8 taken 1314 times.
✓ Branch 4 → 5 taken 264 times.
✓ Branch 4 → 8 taken 1612 times.
✓ Branch 6 → 7 taken 102 times.
✓ Branch 6 → 8 taken 162 times.
✓ Branch 9 → 10 taken 102 times.
✓ Branch 9 → 16 taken 3088 times.
|
3190 | if (!isDecl && !isReturn && lhs.entry->isInitialized()) { |
| 172 |
1/2✓ Branch 10 → 11 taken 102 times.
✗ Branch 10 → 44 not taken.
|
102 | const auto [type, _] = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_ASSIGN, {lhs, rhs}, 0); |
| 173 |
3/4✓ Branch 11 → 12 taken 102 times.
✗ Branch 11 → 45 not taken.
✓ Branch 12 → 13 taken 72 times.
✓ Branch 12 → 15 taken 30 times.
|
102 | if (!type.is(TY_INVALID)) |
| 174 | 72 | return {type, nullptr}; | |
| 175 | } | ||
| 176 | |||
| 177 | // If temp stealing is possible, delete any rhs anonymous entry | ||
| 178 |
6/6✓ Branch 16 → 17 taken 2881 times.
✓ Branch 16 → 20 taken 237 times.
✓ Branch 18 → 19 taken 2738 times.
✓ Branch 18 → 20 taken 143 times.
✓ Branch 21 → 22 taken 2738 times.
✓ Branch 21 → 27 taken 380 times.
|
3118 | if (!rhsIsRef && rhs.isTemporary()) { |
| 179 |
3/4✓ Branch 22 → 23 taken 1970 times.
✓ Branch 22 → 25 taken 768 times.
✓ Branch 23 → 24 taken 1970 times.
✗ Branch 23 → 25 not taken.
|
2738 | if (rhs.entry != nullptr && rhs.entry->anonymous) |
| 180 | 1970 | typeChecker->currentScope->symbolTable.deleteAnonymous(rhs.entry->name); | |
| 181 | 2738 | return {rhsType, nullptr}; | |
| 182 | } | ||
| 183 | |||
| 184 | // If RVO is possible, cancel here | ||
| 185 |
7/8✓ Branch 27 → 28 taken 143 times.
✓ Branch 27 → 32 taken 237 times.
✓ Branch 28 → 29 taken 122 times.
✓ Branch 28 → 32 taken 21 times.
✓ Branch 30 → 31 taken 122 times.
✗ Branch 30 → 32 not taken.
✓ Branch 33 → 34 taken 122 times.
✓ Branch 33 → 36 taken 258 times.
|
380 | if (!rhsIsRef && isReturn && !rhs.isTemporary()) |
| 186 | 122 | return {rhsType, nullptr}; | |
| 187 | |||
| 188 | // => We have to copy | ||
| 189 | // If struct, try to call copy ctor | ||
| 190 |
2/2✓ Branch 37 → 38 taken 247 times.
✓ Branch 37 → 41 taken 11 times.
|
258 | if (rhsType.is(TY_STRUCT)) |
| 191 |
1/2✓ Branch 38 → 39 taken 247 times.
✗ Branch 38 → 46 not taken.
|
247 | return {rhsType, typeChecker->implicitlyCallStructCopyCtor(rhsType, node)}; |
| 192 | |||
| 193 | // Perform shallow copy | ||
| 194 | 11 | return {rhsType, nullptr}; | |
| 195 | } | ||
| 196 | |||
| 197 | 298 | ExprResult OpRuleManager::getPlusEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const { | |
| 198 | // Check is there is an overloaded operator function available | ||
| 199 |
1/2✓ Branch 2 → 3 taken 298 times.
✗ Branch 2 → 24 not taken.
|
298 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_PLUS_EQUAL, {lhs, rhs}, 0); |
| 200 |
3/4✓ Branch 3 → 4 taken 298 times.
✗ Branch 3 → 26 not taken.
✓ Branch 4 → 5 taken 105 times.
✓ Branch 4 → 6 taken 193 times.
|
298 | if (!resultType.type.is(TY_INVALID)) |
| 201 | 105 | return resultType; | |
| 202 | |||
| 203 | // Check if we try to assign a constant value | ||
| 204 |
1/2✓ Branch 6 → 7 taken 193 times.
✗ Branch 6 → 26 not taken.
|
193 | ensureNoConstAssign(node, lhs.type); |
| 205 | |||
| 206 | // Remove reference wrappers | ||
| 207 |
1/2✓ Branch 7 → 8 taken 193 times.
✗ Branch 7 → 26 not taken.
|
193 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 208 |
1/2✓ Branch 8 → 9 taken 193 times.
✗ Branch 8 → 26 not taken.
|
193 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 209 | |||
| 210 | // Check if this is an unsafe operation | ||
| 211 |
7/10✓ Branch 9 → 10 taken 193 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 5 times.
✓ Branch 10 → 14 taken 188 times.
✓ Branch 11 → 12 taken 5 times.
✗ Branch 11 → 25 not taken.
✓ Branch 12 → 13 taken 5 times.
✗ Branch 12 → 14 not taken.
✓ Branch 15 → 16 taken 5 times.
✓ Branch 15 → 18 taken 188 times.
|
193 | if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) { |
| 212 |
1/2✓ Branch 16 → 17 taken 5 times.
✗ Branch 16 → 26 not taken.
|
5 | ensureUnsafeAllowed(node, "+=", lhsType, rhsType); |
| 213 | 5 | return lhs; | |
| 214 | } | ||
| 215 | |||
| 216 |
1/2✓ Branch 20 → 21 taken 188 times.
✗ Branch 20 → 26 not taken.
|
188 | return {validateBinaryOperation(node, PLUS_EQUAL_OP_RULES, std::size(PLUS_EQUAL_OP_RULES), "+=", lhsType, rhsType)}; |
| 217 | } | ||
| 218 | |||
| 219 | 49 | ExprResult OpRuleManager::getMinusEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const { | |
| 220 | // Check is there is an overloaded operator function available | ||
| 221 |
1/2✓ Branch 2 → 3 taken 49 times.
✗ Branch 2 → 24 not taken.
|
49 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MINUS_EQUAL, {lhs, rhs}, 0); |
| 222 |
3/4✓ Branch 3 → 4 taken 49 times.
✗ Branch 3 → 26 not taken.
✓ Branch 4 → 5 taken 7 times.
✓ Branch 4 → 6 taken 42 times.
|
49 | if (!resultType.type.is(TY_INVALID)) |
| 223 | 7 | return resultType; | |
| 224 | |||
| 225 | // Check if we try to assign a constant value | ||
| 226 |
1/2✓ Branch 6 → 7 taken 42 times.
✗ Branch 6 → 26 not taken.
|
42 | ensureNoConstAssign(node, lhs.type); |
| 227 | |||
| 228 | // Remove reference wrappers | ||
| 229 |
1/2✓ Branch 7 → 8 taken 42 times.
✗ Branch 7 → 26 not taken.
|
42 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 230 |
1/2✓ Branch 8 → 9 taken 42 times.
✗ Branch 8 → 26 not taken.
|
42 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 231 | |||
| 232 | // Check if this is an unsafe operation | ||
| 233 |
7/10✓ Branch 9 → 10 taken 42 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 5 times.
✓ Branch 10 → 14 taken 37 times.
✓ Branch 11 → 12 taken 5 times.
✗ Branch 11 → 25 not taken.
✓ Branch 12 → 13 taken 5 times.
✗ Branch 12 → 14 not taken.
✓ Branch 15 → 16 taken 5 times.
✓ Branch 15 → 18 taken 37 times.
|
42 | if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) { |
| 234 |
1/2✓ Branch 16 → 17 taken 5 times.
✗ Branch 16 → 26 not taken.
|
5 | ensureUnsafeAllowed(node, "-=", lhsType, rhsType); |
| 235 | 5 | return lhs; | |
| 236 | } | ||
| 237 | |||
| 238 |
1/2✓ Branch 20 → 21 taken 37 times.
✗ Branch 20 → 26 not taken.
|
37 | return {validateBinaryOperation(node, MINUS_EQUAL_OP_RULES, std::size(MINUS_EQUAL_OP_RULES), "-=", lhsType, rhsType)}; |
| 239 | } | ||
| 240 | |||
| 241 | 54 | ExprResult OpRuleManager::getMulEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const { | |
| 242 | // Check is there is an overloaded operator function available | ||
| 243 |
1/2✓ Branch 2 → 3 taken 54 times.
✗ Branch 2 → 15 not taken.
|
54 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MUL_EQUAL, {lhs, rhs}, 0); |
| 244 |
3/4✓ Branch 3 → 4 taken 54 times.
✗ Branch 3 → 16 not taken.
✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 6 taken 52 times.
|
54 | if (!resultType.type.is(TY_INVALID)) |
| 245 | 2 | return resultType; | |
| 246 | |||
| 247 | // Check if we try to assign a constant value | ||
| 248 |
1/2✓ Branch 6 → 7 taken 52 times.
✗ Branch 6 → 16 not taken.
|
52 | ensureNoConstAssign(node, lhs.type); |
| 249 | |||
| 250 | // Remove reference wrappers | ||
| 251 |
1/2✓ Branch 7 → 8 taken 52 times.
✗ Branch 7 → 16 not taken.
|
52 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 252 |
1/2✓ Branch 8 → 9 taken 52 times.
✗ Branch 8 → 16 not taken.
|
52 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 253 | |||
| 254 |
1/2✓ Branch 11 → 12 taken 52 times.
✗ Branch 11 → 16 not taken.
|
52 | return {validateBinaryOperation(node, MUL_EQUAL_OP_RULES, std::size(MUL_EQUAL_OP_RULES), "*=", lhsType, rhsType)}; |
| 255 | } | ||
| 256 | |||
| 257 | 55 | ExprResult OpRuleManager::getDivEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const { | |
| 258 | // Check is there is an overloaded operator function available | ||
| 259 |
1/2✓ Branch 2 → 3 taken 55 times.
✗ Branch 2 → 15 not taken.
|
55 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_DIV_EQUAL, {lhs, rhs}, 0); |
| 260 |
3/4✓ Branch 3 → 4 taken 55 times.
✗ Branch 3 → 16 not taken.
✓ Branch 4 → 5 taken 37 times.
✓ Branch 4 → 6 taken 18 times.
|
55 | if (!resultType.type.is(TY_INVALID)) |
| 261 | 37 | return resultType; | |
| 262 | |||
| 263 | // Check if we try to assign a constant value | ||
| 264 |
1/2✓ Branch 6 → 7 taken 18 times.
✗ Branch 6 → 16 not taken.
|
18 | ensureNoConstAssign(node, lhs.type); |
| 265 | |||
| 266 | // Remove reference wrappers | ||
| 267 |
1/2✓ Branch 7 → 8 taken 18 times.
✗ Branch 7 → 16 not taken.
|
18 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 268 |
1/2✓ Branch 8 → 9 taken 18 times.
✗ Branch 8 → 16 not taken.
|
18 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 269 | |||
| 270 |
1/2✓ Branch 11 → 12 taken 18 times.
✗ Branch 11 → 16 not taken.
|
18 | return {validateBinaryOperation(node, DIV_EQUAL_OP_RULES, std::size(DIV_EQUAL_OP_RULES), "/=", lhsType, rhsType)}; |
| 271 | } | ||
| 272 | |||
| 273 | 17 | QualType OpRuleManager::getRemEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const { | |
| 274 | // Check if we try to assign a constant value | ||
| 275 |
1/2✓ Branch 2 → 3 taken 17 times.
✗ Branch 2 → 11 not taken.
|
17 | ensureNoConstAssign(node, lhs.type); |
| 276 | |||
| 277 | // Remove reference wrappers | ||
| 278 |
1/2✓ Branch 3 → 4 taken 17 times.
✗ Branch 3 → 11 not taken.
|
17 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 279 |
1/2✓ Branch 4 → 5 taken 17 times.
✗ Branch 4 → 11 not taken.
|
17 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 280 | |||
| 281 |
1/2✓ Branch 7 → 8 taken 17 times.
✗ Branch 7 → 11 not taken.
|
34 | return validateBinaryOperation(node, REM_EQUAL_OP_RULES, std::size(REM_EQUAL_OP_RULES), "%=", lhsType, rhsType); |
| 282 | } | ||
| 283 | |||
| 284 | 12 | QualType OpRuleManager::getSHLEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const { | |
| 285 | // Check if we try to assign a constant value | ||
| 286 |
1/2✓ Branch 2 → 3 taken 12 times.
✗ Branch 2 → 11 not taken.
|
12 | ensureNoConstAssign(node, lhs.type); |
| 287 | |||
| 288 | // Remove reference wrappers | ||
| 289 |
1/2✓ Branch 3 → 4 taken 12 times.
✗ Branch 3 → 11 not taken.
|
12 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 290 |
1/2✓ Branch 4 → 5 taken 12 times.
✗ Branch 4 → 11 not taken.
|
12 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 291 | |||
| 292 |
1/2✓ Branch 7 → 8 taken 12 times.
✗ Branch 7 → 11 not taken.
|
24 | return validateBinaryOperation(node, SHL_EQUAL_OP_RULES, std::size(SHL_EQUAL_OP_RULES), "<<=", lhsType, rhsType); |
| 293 | } | ||
| 294 | |||
| 295 | 13 | QualType OpRuleManager::getSHREqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const { | |
| 296 | // Check if we try to assign a constant value | ||
| 297 |
1/2✓ Branch 2 → 3 taken 13 times.
✗ Branch 2 → 11 not taken.
|
13 | ensureNoConstAssign(node, lhs.type); |
| 298 | |||
| 299 | // Remove reference wrappers | ||
| 300 |
1/2✓ Branch 3 → 4 taken 13 times.
✗ Branch 3 → 11 not taken.
|
13 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 301 |
1/2✓ Branch 4 → 5 taken 13 times.
✗ Branch 4 → 11 not taken.
|
13 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 302 | |||
| 303 |
1/2✓ Branch 7 → 8 taken 13 times.
✗ Branch 7 → 11 not taken.
|
26 | return validateBinaryOperation(node, SHR_EQUAL_OP_RULES, std::size(SHR_EQUAL_OP_RULES), ">>=", lhsType, rhsType); |
| 304 | } | ||
| 305 | |||
| 306 | 11 | QualType OpRuleManager::getAndEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const { | |
| 307 | // Check if we try to assign a constant value | ||
| 308 |
1/2✓ Branch 2 → 3 taken 11 times.
✗ Branch 2 → 11 not taken.
|
11 | ensureNoConstAssign(node, lhs.type); |
| 309 | |||
| 310 | // Remove reference wrappers | ||
| 311 |
1/2✓ Branch 3 → 4 taken 11 times.
✗ Branch 3 → 11 not taken.
|
11 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 312 |
1/2✓ Branch 4 → 5 taken 11 times.
✗ Branch 4 → 11 not taken.
|
11 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 313 | |||
| 314 |
1/2✓ Branch 7 → 8 taken 11 times.
✗ Branch 7 → 11 not taken.
|
22 | return validateBinaryOperation(node, AND_EQUAL_OP_RULES, std::size(AND_EQUAL_OP_RULES), "&=", lhsType, rhsType); |
| 315 | } | ||
| 316 | |||
| 317 | 11 | QualType OpRuleManager::getOrEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const { | |
| 318 | // Check if we try to assign a constant value | ||
| 319 |
1/2✓ Branch 2 → 3 taken 11 times.
✗ Branch 2 → 11 not taken.
|
11 | ensureNoConstAssign(node, lhs.type); |
| 320 | |||
| 321 | // Remove reference wrappers | ||
| 322 |
1/2✓ Branch 3 → 4 taken 11 times.
✗ Branch 3 → 11 not taken.
|
11 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 323 |
1/2✓ Branch 4 → 5 taken 11 times.
✗ Branch 4 → 11 not taken.
|
11 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 324 | |||
| 325 |
1/2✓ Branch 7 → 8 taken 11 times.
✗ Branch 7 → 11 not taken.
|
22 | return validateBinaryOperation(node, OR_EQUAL_OP_RULES, std::size(OR_EQUAL_OP_RULES), "|=", lhsType, rhsType); |
| 326 | } | ||
| 327 | |||
| 328 | 389 | QualType OpRuleManager::getXorEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const { | |
| 329 | // Check if we try to assign a constant value | ||
| 330 |
1/2✓ Branch 2 → 3 taken 389 times.
✗ Branch 2 → 11 not taken.
|
389 | ensureNoConstAssign(node, lhs.type); |
| 331 | |||
| 332 | // Remove reference wrappers | ||
| 333 |
1/2✓ Branch 3 → 4 taken 389 times.
✗ Branch 3 → 11 not taken.
|
389 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 334 |
1/2✓ Branch 4 → 5 taken 389 times.
✗ Branch 4 → 11 not taken.
|
389 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 335 | |||
| 336 |
1/2✓ Branch 7 → 8 taken 389 times.
✗ Branch 7 → 11 not taken.
|
778 | return validateBinaryOperation(node, XOR_EQUAL_OP_RULES, std::size(XOR_EQUAL_OP_RULES), "^=", lhsType, rhsType); |
| 337 | } | ||
| 338 | |||
| 339 | 1338 | QualType OpRuleManager::getLogicalOrResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
| 340 | // Remove reference wrappers | ||
| 341 |
1/2✓ Branch 2 → 3 taken 1338 times.
✗ Branch 2 → 10 not taken.
|
1338 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 342 |
1/2✓ Branch 3 → 4 taken 1338 times.
✗ Branch 3 → 10 not taken.
|
1338 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 343 | |||
| 344 |
2/2✓ Branch 6 → 7 taken 1337 times.
✓ Branch 6 → 10 taken 1 time.
|
2675 | return validateBinaryOperation(node, LOGICAL_OR_OP_RULES, std::size(LOGICAL_OR_OP_RULES), "||", lhsType, rhsType); |
| 345 | } | ||
| 346 | |||
| 347 | 236 | QualType OpRuleManager::getLogicalAndResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
| 348 | // Remove reference wrappers | ||
| 349 |
1/2✓ Branch 2 → 3 taken 236 times.
✗ Branch 2 → 10 not taken.
|
236 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 350 |
1/2✓ Branch 3 → 4 taken 236 times.
✗ Branch 3 → 10 not taken.
|
236 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 351 | |||
| 352 |
1/2✓ Branch 6 → 7 taken 236 times.
✗ Branch 6 → 10 not taken.
|
472 | return validateBinaryOperation(node, LOGICAL_AND_OP_RULES, std::size(LOGICAL_AND_OP_RULES), "&&", lhsType, rhsType); |
| 353 | } | ||
| 354 | |||
| 355 | 109 | QualType OpRuleManager::getBitwiseOrResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
| 356 | // Remove reference wrappers | ||
| 357 |
1/2✓ Branch 2 → 3 taken 109 times.
✗ Branch 2 → 10 not taken.
|
109 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 358 |
1/2✓ Branch 3 → 4 taken 109 times.
✗ Branch 3 → 10 not taken.
|
109 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 359 | |||
| 360 |
2/2✓ Branch 6 → 7 taken 108 times.
✓ Branch 6 → 10 taken 1 time.
|
217 | return validateBinaryOperation(node, BITWISE_OR_OP_RULES, std::size(BITWISE_OR_OP_RULES), "|", lhsType, rhsType); |
| 361 | } | ||
| 362 | |||
| 363 | 20 | QualType OpRuleManager::getBitwiseXorResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
| 364 | // Remove reference wrappers | ||
| 365 |
1/2✓ Branch 2 → 3 taken 20 times.
✗ Branch 2 → 10 not taken.
|
20 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 366 |
1/2✓ Branch 3 → 4 taken 20 times.
✗ Branch 3 → 10 not taken.
|
20 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 367 | |||
| 368 |
1/2✓ Branch 6 → 7 taken 20 times.
✗ Branch 6 → 10 not taken.
|
40 | return validateBinaryOperation(node, BITWISE_XOR_OP_RULES, std::size(BITWISE_XOR_OP_RULES), "^", lhsType, rhsType); |
| 369 | } | ||
| 370 | |||
| 371 | 49 | QualType OpRuleManager::getBitwiseAndResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
| 372 | // Remove reference wrappers | ||
| 373 |
1/2✓ Branch 2 → 3 taken 49 times.
✗ Branch 2 → 10 not taken.
|
49 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 374 |
1/2✓ Branch 3 → 4 taken 49 times.
✗ Branch 3 → 10 not taken.
|
49 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 375 | |||
| 376 |
1/2✓ Branch 6 → 7 taken 49 times.
✗ Branch 6 → 10 not taken.
|
98 | return validateBinaryOperation(node, BITWISE_AND_OP_RULES, std::size(BITWISE_AND_OP_RULES), "&", lhsType, rhsType); |
| 377 | } | ||
| 378 | |||
| 379 | 4660 | ExprResult OpRuleManager::getEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const { | |
| 380 | // Check is there is an overloaded operator function available | ||
| 381 |
1/2✓ Branch 2 → 3 taken 4660 times.
✗ Branch 2 → 38 not taken.
|
4660 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_EQUAL, {lhs, rhs}, 0); |
| 382 |
3/4✓ Branch 3 → 4 taken 4660 times.
✗ Branch 3 → 39 not taken.
✓ Branch 4 → 5 taken 479 times.
✓ Branch 4 → 6 taken 4181 times.
|
4660 | if (!resultType.type.is(TY_INVALID)) |
| 383 | 479 | return resultType; | |
| 384 | |||
| 385 | // Remove reference wrappers | ||
| 386 |
1/2✓ Branch 6 → 7 taken 4181 times.
✗ Branch 6 → 39 not taken.
|
4181 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 387 |
1/2✓ Branch 7 → 8 taken 4181 times.
✗ Branch 7 → 39 not taken.
|
4181 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 388 | |||
| 389 | // Allow 'pointer == unsigned long' straight away | ||
| 390 |
10/14✓ Branch 8 → 9 taken 4181 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 1036 times.
✓ Branch 9 → 15 taken 3145 times.
✓ Branch 10 → 11 taken 1036 times.
✗ Branch 10 → 39 not taken.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 15 taken 1035 times.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 39 not taken.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 15 not taken.
✓ Branch 16 → 17 taken 1 time.
✓ Branch 16 → 19 taken 4180 times.
|
4181 | if (lhsType.isPtr() && rhsType.is(TY_LONG) && rhsType.isUnsigned()) |
| 391 |
1/2✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 39 not taken.
|
1 | return ExprResult(QualType(TY_BOOL)); |
| 392 | |||
| 393 | // Allow 'string == char*' and vice versa straight away | ||
| 394 |
11/18✓ Branch 19 → 20 taken 4180 times.
✗ Branch 19 → 39 not taken.
✓ Branch 20 → 21 taken 161 times.
✓ Branch 20 → 23 taken 4019 times.
✓ Branch 21 → 22 taken 161 times.
✗ Branch 21 → 39 not taken.
✓ Branch 22 → 23 taken 161 times.
✗ Branch 22 → 27 not taken.
✓ Branch 23 → 24 taken 4180 times.
✗ Branch 23 → 39 not taken.
✓ Branch 24 → 25 taken 612 times.
✓ Branch 24 → 28 taken 3568 times.
✓ Branch 25 → 26 taken 612 times.
✗ Branch 25 → 39 not taken.
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 28 taken 612 times.
✗ Branch 29 → 30 not taken.
✓ Branch 29 → 32 taken 4180 times.
|
4180 | if ((lhsType.is(TY_STRING) && rhsType.isPtrTo(TY_CHAR)) || (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING))) |
| 395 | ✗ | return ExprResult(QualType(TY_BOOL)); | |
| 396 | |||
| 397 | // Check primitive type combinations | ||
| 398 |
2/2✓ Branch 34 → 35 taken 4179 times.
✓ Branch 34 → 39 taken 1 time.
|
4180 | return ExprResult(validateBinaryOperation(node, EQUAL_OP_RULES, std::size(EQUAL_OP_RULES), "==", lhsType, rhsType)); |
| 399 | } | ||
| 400 | |||
| 401 | 1716 | ExprResult OpRuleManager::getNotEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const { | |
| 402 | // Check is there is an overloaded operator function available | ||
| 403 |
1/2✓ Branch 2 → 3 taken 1716 times.
✗ Branch 2 → 38 not taken.
|
1716 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_NOT_EQUAL, {lhs, rhs}, 0); |
| 404 |
3/4✓ Branch 3 → 4 taken 1716 times.
✗ Branch 3 → 39 not taken.
✓ Branch 4 → 5 taken 11 times.
✓ Branch 4 → 6 taken 1705 times.
|
1716 | if (!resultType.type.is(TY_INVALID)) |
| 405 | 11 | return resultType; | |
| 406 | |||
| 407 | // Remove reference wrappers | ||
| 408 |
1/2✓ Branch 6 → 7 taken 1705 times.
✗ Branch 6 → 39 not taken.
|
1705 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 409 |
1/2✓ Branch 7 → 8 taken 1705 times.
✗ Branch 7 → 39 not taken.
|
1705 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 410 | |||
| 411 | // Allow 'pointer != unsigned long' straight away | ||
| 412 |
10/14✓ Branch 8 → 9 taken 1705 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 211 times.
✓ Branch 9 → 15 taken 1494 times.
✓ Branch 10 → 11 taken 211 times.
✗ Branch 10 → 39 not taken.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 15 taken 210 times.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 39 not taken.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 15 not taken.
✓ Branch 16 → 17 taken 1 time.
✓ Branch 16 → 19 taken 1704 times.
|
1705 | if (lhsType.isPtr() && rhsType.is(TY_LONG) && rhsType.isUnsigned()) |
| 413 |
1/2✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 39 not taken.
|
1 | return ExprResult(QualType(TY_BOOL)); |
| 414 | |||
| 415 | // Allow 'string != char*' and vice versa straight away | ||
| 416 |
12/18✓ Branch 19 → 20 taken 1704 times.
✗ Branch 19 → 39 not taken.
✓ Branch 20 → 21 taken 11 times.
✓ Branch 20 → 23 taken 1693 times.
✓ Branch 21 → 22 taken 11 times.
✗ Branch 21 → 39 not taken.
✓ Branch 22 → 23 taken 11 times.
✗ Branch 22 → 27 not taken.
✓ Branch 23 → 24 taken 1704 times.
✗ Branch 23 → 39 not taken.
✓ Branch 24 → 25 taken 8 times.
✓ Branch 24 → 28 taken 1696 times.
✓ Branch 25 → 26 taken 8 times.
✗ Branch 25 → 39 not taken.
✓ Branch 26 → 27 taken 8 times.
✗ Branch 26 → 28 not taken.
✓ Branch 29 → 30 taken 8 times.
✓ Branch 29 → 32 taken 1696 times.
|
1704 | if ((lhsType.is(TY_STRING) && rhsType.isPtrTo(TY_CHAR)) || (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING))) |
| 417 |
1/2✓ Branch 30 → 31 taken 8 times.
✗ Branch 30 → 39 not taken.
|
8 | return ExprResult(QualType(TY_BOOL)); |
| 418 | |||
| 419 | // Check primitive type combinations | ||
| 420 |
1/2✓ Branch 34 → 35 taken 1696 times.
✗ Branch 34 → 39 not taken.
|
1696 | return ExprResult(validateBinaryOperation(node, NOT_EQUAL_OP_RULES, std::size(NOT_EQUAL_OP_RULES), "!=", lhsType, rhsType)); |
| 421 | } | ||
| 422 | |||
| 423 | 2130 | QualType OpRuleManager::getLessResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
| 424 | // Remove reference wrappers | ||
| 425 |
1/2✓ Branch 2 → 3 taken 2130 times.
✗ Branch 2 → 10 not taken.
|
2130 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 426 |
1/2✓ Branch 3 → 4 taken 2130 times.
✗ Branch 3 → 10 not taken.
|
2130 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 427 | |||
| 428 |
1/2✓ Branch 6 → 7 taken 2130 times.
✗ Branch 6 → 10 not taken.
|
4260 | return validateBinaryOperation(node, LESS_OP_RULES, std::size(LESS_OP_RULES), "<", lhsType, rhsType); |
| 429 | } | ||
| 430 | |||
| 431 | 607 | QualType OpRuleManager::getGreaterResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
| 432 | // Remove reference wrappers | ||
| 433 |
1/2✓ Branch 2 → 3 taken 607 times.
✗ Branch 2 → 10 not taken.
|
607 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 434 |
1/2✓ Branch 3 → 4 taken 607 times.
✗ Branch 3 → 10 not taken.
|
607 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 435 | |||
| 436 |
2/2✓ Branch 6 → 7 taken 606 times.
✓ Branch 6 → 10 taken 1 time.
|
1213 | return validateBinaryOperation(node, GREATER_OP_RULES, std::size(GREATER_OP_RULES), ">", lhsType, rhsType); |
| 437 | } | ||
| 438 | |||
| 439 | 457 | QualType OpRuleManager::getLessEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
| 440 | // Remove reference wrappers | ||
| 441 |
1/2✓ Branch 2 → 3 taken 457 times.
✗ Branch 2 → 10 not taken.
|
457 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 442 |
1/2✓ Branch 3 → 4 taken 457 times.
✗ Branch 3 → 10 not taken.
|
457 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 443 | |||
| 444 |
1/2✓ Branch 6 → 7 taken 457 times.
✗ Branch 6 → 10 not taken.
|
914 | return validateBinaryOperation(node, LESS_EQUAL_OP_RULES, std::size(LESS_EQUAL_OP_RULES), "<=", lhsType, rhsType); |
| 445 | } | ||
| 446 | |||
| 447 | 1148 | QualType OpRuleManager::getGreaterEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
| 448 | // Remove reference wrappers | ||
| 449 |
1/2✓ Branch 2 → 3 taken 1148 times.
✗ Branch 2 → 21 not taken.
|
1148 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 450 |
1/2✓ Branch 3 → 4 taken 1148 times.
✗ Branch 3 → 21 not taken.
|
1148 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 451 | |||
| 452 | // Allow 'pointer == pointer' straight away | ||
| 453 |
7/10✓ Branch 4 → 5 taken 1148 times.
✗ Branch 4 → 21 not taken.
✓ Branch 5 → 6 taken 4 times.
✓ Branch 5 → 9 taken 1144 times.
✓ Branch 6 → 7 taken 4 times.
✗ Branch 6 → 21 not taken.
✓ Branch 7 → 8 taken 4 times.
✗ Branch 7 → 9 not taken.
✓ Branch 10 → 11 taken 4 times.
✓ Branch 10 → 14 taken 1144 times.
|
1148 | if (lhsType.isPtr() && rhsType.isPtr()) |
| 454 |
1/2✓ Branch 11 → 12 taken 4 times.
✗ Branch 11 → 20 not taken.
|
4 | return QualType(TY_BOOL); |
| 455 | |||
| 456 |
1/2✓ Branch 16 → 17 taken 1144 times.
✗ Branch 16 → 21 not taken.
|
1144 | return validateBinaryOperation(node, GREATER_EQUAL_OP_RULES, std::size(GREATER_EQUAL_OP_RULES), ">=", lhsType, rhsType); |
| 457 | } | ||
| 458 | |||
| 459 | 122 | ExprResult OpRuleManager::getShiftLeftResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, | |
| 460 | size_t opIdx) const { | ||
| 461 | // Check is there is an overloaded operator function available | ||
| 462 |
1/2✓ Branch 2 → 3 taken 122 times.
✗ Branch 2 → 14 not taken.
|
122 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_SHL, {lhs, rhs}, opIdx); |
| 463 |
3/4✓ Branch 3 → 4 taken 122 times.
✗ Branch 3 → 15 not taken.
✓ Branch 4 → 5 taken 96 times.
✓ Branch 4 → 6 taken 26 times.
|
122 | if (!resultType.type.is(TY_INVALID)) |
| 464 | 96 | return resultType; | |
| 465 | |||
| 466 | // Remove reference wrappers | ||
| 467 |
1/2✓ Branch 6 → 7 taken 26 times.
✗ Branch 6 → 15 not taken.
|
26 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 468 |
1/2✓ Branch 7 → 8 taken 26 times.
✗ Branch 7 → 15 not taken.
|
26 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 469 | |||
| 470 |
1/2✓ Branch 10 → 11 taken 26 times.
✗ Branch 10 → 15 not taken.
|
26 | return {validateBinaryOperation(node, SHIFT_LEFT_OP_RULES, std::size(SHIFT_LEFT_OP_RULES), "<<", lhsType, rhsType)}; |
| 471 | } | ||
| 472 | |||
| 473 | 76 | ExprResult OpRuleManager::getShiftRightResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, | |
| 474 | size_t opIdx) const { | ||
| 475 | // Check is there is an overloaded operator function available | ||
| 476 |
1/2✓ Branch 2 → 3 taken 76 times.
✗ Branch 2 → 14 not taken.
|
76 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_SHR, {lhs, rhs}, opIdx); |
| 477 |
3/4✓ Branch 3 → 4 taken 76 times.
✗ Branch 3 → 15 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 75 times.
|
76 | if (!resultType.type.is(TY_INVALID)) |
| 478 | 1 | return resultType; | |
| 479 | |||
| 480 | // Remove reference wrappers | ||
| 481 |
1/2✓ Branch 6 → 7 taken 75 times.
✗ Branch 6 → 15 not taken.
|
75 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 482 |
1/2✓ Branch 7 → 8 taken 75 times.
✗ Branch 7 → 15 not taken.
|
75 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 483 | |||
| 484 |
1/2✓ Branch 10 → 11 taken 75 times.
✗ Branch 10 → 15 not taken.
|
75 | return {validateBinaryOperation(node, SHIFT_RIGHT_OP_RULES, std::size(SHIFT_RIGHT_OP_RULES), ">>", lhsType, rhsType)}; |
| 485 | } | ||
| 486 | |||
| 487 | 3567 | ExprResult OpRuleManager::getPlusResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const { | |
| 488 | // Check is there is an overloaded operator function available | ||
| 489 |
1/2✓ Branch 2 → 3 taken 3567 times.
✗ Branch 2 → 32 not taken.
|
3567 | const ExprResult result = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_PLUS, {lhs, rhs}, opIdx); |
| 490 |
3/4✓ Branch 3 → 4 taken 3567 times.
✗ Branch 3 → 35 not taken.
✓ Branch 4 → 5 taken 70 times.
✓ Branch 4 → 6 taken 3497 times.
|
3567 | if (!result.type.is(TY_INVALID)) |
| 491 | 70 | return result; | |
| 492 | |||
| 493 | // Remove reference wrappers | ||
| 494 |
1/2✓ Branch 6 → 7 taken 3497 times.
✗ Branch 6 → 35 not taken.
|
3497 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 495 |
1/2✓ Branch 7 → 8 taken 3497 times.
✗ Branch 7 → 35 not taken.
|
3497 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 496 | |||
| 497 | // Allow any* + <int/long/short> | ||
| 498 |
7/10✓ Branch 8 → 9 taken 3497 times.
✗ Branch 8 → 33 not taken.
✓ Branch 9 → 10 taken 615 times.
✓ Branch 9 → 13 taken 2882 times.
✓ Branch 10 → 11 taken 615 times.
✗ Branch 10 → 33 not taken.
✓ Branch 11 → 12 taken 615 times.
✗ Branch 11 → 13 not taken.
✓ Branch 14 → 15 taken 615 times.
✓ Branch 14 → 17 taken 2882 times.
|
3497 | if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) { |
| 499 |
1/2✓ Branch 15 → 16 taken 615 times.
✗ Branch 15 → 35 not taken.
|
615 | ensureUnsafeAllowed(node, "+", lhsType, rhsType); |
| 500 | 615 | return {lhsType}; | |
| 501 | } | ||
| 502 | // Allow <int/long/short> + any* | ||
| 503 |
6/10✓ Branch 17 → 18 taken 2882 times.
✗ Branch 17 → 34 not taken.
✓ Branch 18 → 19 taken 2758 times.
✓ Branch 18 → 22 taken 124 times.
✓ Branch 19 → 20 taken 2758 times.
✗ Branch 19 → 34 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 2758 times.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 26 taken 2882 times.
|
2882 | if (lhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT}) && rhsType.isPtr()) { |
| 504 | ✗ | ensureUnsafeAllowed(node, "+", lhsType, rhsType); | |
| 505 | ✗ | return {rhsType}; | |
| 506 | } | ||
| 507 | |||
| 508 |
2/2✓ Branch 28 → 29 taken 2881 times.
✓ Branch 28 → 35 taken 1 time.
|
2882 | return {validateBinaryOperation(node, PLUS_OP_RULES, std::size(PLUS_OP_RULES), "+", lhsType, rhsType)}; |
| 509 | } | ||
| 510 | |||
| 511 | 2131 | ExprResult OpRuleManager::getMinusResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const { | |
| 512 | // Check is there is an overloaded operator function available | ||
| 513 |
1/2✓ Branch 2 → 3 taken 2131 times.
✗ Branch 2 → 23 not taken.
|
2131 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MINUS, {lhs, rhs}, opIdx); |
| 514 |
3/4✓ Branch 3 → 4 taken 2131 times.
✗ Branch 3 → 25 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 2130 times.
|
2131 | if (!resultType.type.is(TY_INVALID)) |
| 515 | 1 | return resultType; | |
| 516 | |||
| 517 | // Remove reference wrappers | ||
| 518 |
1/2✓ Branch 6 → 7 taken 2130 times.
✗ Branch 6 → 25 not taken.
|
2130 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 519 |
1/2✓ Branch 7 → 8 taken 2130 times.
✗ Branch 7 → 25 not taken.
|
2130 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 520 | |||
| 521 | // Allow any* - <int/long/short> | ||
| 522 |
7/10✓ Branch 8 → 9 taken 2130 times.
✗ Branch 8 → 24 not taken.
✓ Branch 9 → 10 taken 3 times.
✓ Branch 9 → 13 taken 2127 times.
✓ Branch 10 → 11 taken 3 times.
✗ Branch 10 → 24 not taken.
✓ Branch 11 → 12 taken 3 times.
✗ Branch 11 → 13 not taken.
✓ Branch 14 → 15 taken 3 times.
✓ Branch 14 → 17 taken 2127 times.
|
2130 | if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) { |
| 523 |
1/2✓ Branch 15 → 16 taken 3 times.
✗ Branch 15 → 25 not taken.
|
3 | ensureUnsafeAllowed(node, "-", lhsType, rhsType); |
| 524 | 3 | return lhs; | |
| 525 | } | ||
| 526 | |||
| 527 |
1/2✓ Branch 19 → 20 taken 2127 times.
✗ Branch 19 → 25 not taken.
|
2127 | return {validateBinaryOperation(node, MINUS_OP_RULES, std::size(MINUS_OP_RULES), "-", lhsType, rhsType)}; |
| 528 | } | ||
| 529 | |||
| 530 | 893 | ExprResult OpRuleManager::getMulResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const { | |
| 531 | // Check is there is an overloaded operator function available | ||
| 532 |
1/2✓ Branch 2 → 3 taken 893 times.
✗ Branch 2 → 14 not taken.
|
893 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MUL, {lhs, rhs}, opIdx); |
| 533 |
3/4✓ Branch 3 → 4 taken 893 times.
✗ Branch 3 → 15 not taken.
✓ Branch 4 → 5 taken 9 times.
✓ Branch 4 → 6 taken 884 times.
|
893 | if (!resultType.type.is(TY_INVALID)) |
| 534 | 9 | return resultType; | |
| 535 | |||
| 536 | // Remove reference wrappers | ||
| 537 |
1/2✓ Branch 6 → 7 taken 884 times.
✗ Branch 6 → 15 not taken.
|
884 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 538 |
1/2✓ Branch 7 → 8 taken 884 times.
✗ Branch 7 → 15 not taken.
|
884 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 539 | |||
| 540 |
2/2✓ Branch 10 → 11 taken 883 times.
✓ Branch 10 → 15 taken 1 time.
|
884 | return {validateBinaryOperation(node, MUL_OP_RULES, std::size(MUL_OP_RULES), "*", lhsType, rhsType)}; |
| 541 | } | ||
| 542 | |||
| 543 | 174 | ExprResult OpRuleManager::getDivResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const { | |
| 544 | // Check is there is an overloaded operator function available | ||
| 545 |
1/2✓ Branch 2 → 3 taken 174 times.
✗ Branch 2 → 14 not taken.
|
174 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_DIV, {lhs, rhs}, opIdx); |
| 546 |
3/4✓ Branch 3 → 4 taken 174 times.
✗ Branch 3 → 15 not taken.
✓ Branch 4 → 5 taken 3 times.
✓ Branch 4 → 6 taken 171 times.
|
174 | if (!resultType.type.is(TY_INVALID)) |
| 547 | 3 | return resultType; | |
| 548 | |||
| 549 | // Remove reference wrappers | ||
| 550 |
1/2✓ Branch 6 → 7 taken 171 times.
✗ Branch 6 → 15 not taken.
|
171 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 551 |
1/2✓ Branch 7 → 8 taken 171 times.
✗ Branch 7 → 15 not taken.
|
171 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 552 | |||
| 553 |
1/2✓ Branch 10 → 11 taken 171 times.
✗ Branch 10 → 15 not taken.
|
171 | return {validateBinaryOperation(node, DIV_OP_RULES, std::size(DIV_OP_RULES), "/", lhsType, rhsType)}; |
| 554 | } | ||
| 555 | |||
| 556 | 27 | ExprResult OpRuleManager::getRemResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
| 557 | // Remove reference wrappers | ||
| 558 |
1/2✓ Branch 2 → 3 taken 27 times.
✗ Branch 2 → 10 not taken.
|
27 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 559 |
1/2✓ Branch 3 → 4 taken 27 times.
✗ Branch 3 → 10 not taken.
|
27 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 560 | |||
| 561 |
1/2✓ Branch 6 → 7 taken 27 times.
✗ Branch 6 → 10 not taken.
|
54 | return {validateBinaryOperation(node, REM_OP_RULES, std::size(REM_OP_RULES), "%", lhsType, rhsType)}; |
| 562 | } | ||
| 563 | |||
| 564 | 893 | QualType OpRuleManager::getPrefixMinusResultType(const ASTNode *node, const ExprResult &lhs) { | |
| 565 | // Remove reference wrappers | ||
| 566 |
1/2✓ Branch 2 → 3 taken 893 times.
✗ Branch 2 → 9 not taken.
|
893 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 567 | |||
| 568 |
1/2✓ Branch 5 → 6 taken 893 times.
✗ Branch 5 → 9 not taken.
|
1786 | return validateUnaryOperation(node, PREFIX_MINUS_OP_RULES, std::size(PREFIX_MINUS_OP_RULES), "-", lhsType); |
| 569 | } | ||
| 570 | |||
| 571 | 30 | QualType OpRuleManager::getPrefixPlusPlusResultType(const ASTNode *node, const ExprResult &lhs) const { | |
| 572 | // Check if we try to assign a constant value | ||
| 573 |
1/2✓ Branch 2 → 3 taken 30 times.
✗ Branch 2 → 14 not taken.
|
30 | ensureNoConstAssign(node, lhs.type); |
| 574 | |||
| 575 | // Remove reference wrappers | ||
| 576 |
1/2✓ Branch 3 → 4 taken 30 times.
✗ Branch 3 → 14 not taken.
|
30 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 577 | |||
| 578 | // Check if this is an unsafe operation | ||
| 579 |
2/4✓ Branch 4 → 5 taken 30 times.
✗ Branch 4 → 14 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 30 times.
|
30 | if (lhsType.isPtr()) { |
| 580 | ✗ | ensureUnsafeAllowed(node, "++", lhsType); | |
| 581 | ✗ | return lhsType; | |
| 582 | } | ||
| 583 | |||
| 584 |
1/2✓ Branch 10 → 11 taken 30 times.
✗ Branch 10 → 14 not taken.
|
30 | return validateUnaryOperation(node, PREFIX_PLUS_PLUS_OP_RULES, std::size(PREFIX_PLUS_PLUS_OP_RULES), "++", lhsType); |
| 585 | } | ||
| 586 | |||
| 587 | 12 | QualType OpRuleManager::getPrefixMinusMinusResultType(const ASTNode *node, const ExprResult &lhs) const { | |
| 588 | // Check if we try to assign a constant value | ||
| 589 |
1/2✓ Branch 2 → 3 taken 12 times.
✗ Branch 2 → 14 not taken.
|
12 | ensureNoConstAssign(node, lhs.type); |
| 590 | |||
| 591 | // Remove reference wrappers | ||
| 592 |
1/2✓ Branch 3 → 4 taken 12 times.
✗ Branch 3 → 14 not taken.
|
12 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 593 | |||
| 594 | // Check if this is an unsafe operation | ||
| 595 |
2/4✓ Branch 4 → 5 taken 12 times.
✗ Branch 4 → 14 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 12 times.
|
12 | if (lhsType.isPtr()) { |
| 596 | ✗ | ensureUnsafeAllowed(node, "--", lhsType); | |
| 597 | ✗ | return lhsType; | |
| 598 | } | ||
| 599 | |||
| 600 |
2/2✓ Branch 10 → 11 taken 11 times.
✓ Branch 10 → 14 taken 1 time.
|
12 | return validateUnaryOperation(node, PREFIX_MINUS_MINUS_OP_RULES, std::size(PREFIX_MINUS_MINUS_OP_RULES), "--", lhsType); |
| 601 | } | ||
| 602 | |||
| 603 | 854 | QualType OpRuleManager::getPrefixNotResultType(const ASTNode *node, const ExprResult &lhs) { | |
| 604 | // Remove reference wrappers | ||
| 605 |
1/2✓ Branch 2 → 3 taken 854 times.
✗ Branch 2 → 9 not taken.
|
854 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 606 | |||
| 607 |
1/2✓ Branch 5 → 6 taken 854 times.
✗ Branch 5 → 9 not taken.
|
1708 | return validateUnaryOperation(node, PREFIX_NOT_OP_RULES, std::size(PREFIX_NOT_OP_RULES), "!", lhsType); |
| 608 | } | ||
| 609 | |||
| 610 | 5 | QualType OpRuleManager::getPrefixBitwiseNotResultType(const ASTNode *node, const ExprResult &lhs) { | |
| 611 | // Remove reference wrappers | ||
| 612 |
1/2✓ Branch 2 → 3 taken 5 times.
✗ Branch 2 → 9 not taken.
|
5 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 613 | |||
| 614 |
1/2✓ Branch 5 → 6 taken 5 times.
✗ Branch 5 → 9 not taken.
|
10 | return validateUnaryOperation(node, PREFIX_BITWISE_NOT_OP_RULES, std::size(PREFIX_BITWISE_NOT_OP_RULES), "~", lhsType); |
| 615 | } | ||
| 616 | |||
| 617 | 277 | QualType OpRuleManager::getPrefixMulResultType(const ASTNode *node, const ExprResult &lhs) { | |
| 618 | // Remove reference wrappers | ||
| 619 |
1/2✓ Branch 2 → 3 taken 277 times.
✗ Branch 2 → 25 not taken.
|
277 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 620 | |||
| 621 |
3/4✓ Branch 3 → 4 taken 277 times.
✗ Branch 3 → 25 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 12 taken 276 times.
|
277 | if (!lhsType.isPtr()) |
| 622 |
3/6✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 21 not taken.
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 19 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 16 not taken.
|
1 | throw SemanticError(node, OPERATOR_WRONG_DATA_TYPE, "Cannot apply de-referencing operator on type " + lhsType.getName(true)); |
| 623 |
1/2✓ Branch 12 → 13 taken 276 times.
✗ Branch 12 → 25 not taken.
|
552 | return lhsType.getContained(); |
| 624 | } | ||
| 625 | |||
| 626 | 222 | QualType OpRuleManager::getPrefixBitwiseAndResultType(const ASTNode *node, const ExprResult &lhs) { | |
| 627 | // Remove reference wrappers | ||
| 628 |
1/2✓ Branch 2 → 3 taken 222 times.
✗ Branch 2 → 7 not taken.
|
222 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 629 | |||
| 630 |
1/2✓ Branch 3 → 4 taken 222 times.
✗ Branch 3 → 7 not taken.
|
444 | return lhsType.toPtr(node); |
| 631 | } | ||
| 632 | |||
| 633 | 2056 | ExprResult OpRuleManager::getPostfixPlusPlusResultType(ASTNode *node, const ExprResult &lhs) const { | |
| 634 | // Check is there is an overloaded operator function available | ||
| 635 |
2/2✓ Branch 2 → 3 taken 2055 times.
✓ Branch 2 → 18 taken 1 time.
|
2056 | const ExprResult resultType = isOperatorOverloadingFctAvailable<1>(node, OP_FCT_POSTFIX_PLUS_PLUS, {lhs}, 0); |
| 636 |
3/4✓ Branch 3 → 4 taken 2055 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 9 times.
✓ Branch 4 → 6 taken 2046 times.
|
2055 | if (!resultType.type.is(TY_INVALID)) |
| 637 | 9 | return resultType; | |
| 638 | |||
| 639 | // Check if we try to assign a constant value | ||
| 640 |
1/2✓ Branch 6 → 7 taken 2046 times.
✗ Branch 6 → 19 not taken.
|
2046 | ensureNoConstAssign(node, lhs.type); |
| 641 | |||
| 642 | // Remove reference wrappers | ||
| 643 |
1/2✓ Branch 7 → 8 taken 2046 times.
✗ Branch 7 → 19 not taken.
|
2046 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 644 | |||
| 645 | // Check if this is an unsafe operation | ||
| 646 |
3/4✓ Branch 8 → 9 taken 2046 times.
✗ Branch 8 → 19 not taken.
✓ Branch 9 → 10 taken 10 times.
✓ Branch 9 → 12 taken 2036 times.
|
2046 | if (lhsType.isPtr()) { |
| 647 |
1/2✓ Branch 10 → 11 taken 10 times.
✗ Branch 10 → 19 not taken.
|
10 | ensureUnsafeAllowed(node, "++", lhsType); |
| 648 | 10 | return lhs; | |
| 649 | } | ||
| 650 | |||
| 651 |
2/2✓ Branch 14 → 15 taken 2035 times.
✓ Branch 14 → 19 taken 1 time.
|
2036 | return {validateUnaryOperation(node, POSTFIX_PLUS_PLUS_OP_RULES, std::size(POSTFIX_PLUS_PLUS_OP_RULES), "++", lhsType)}; |
| 652 | } | ||
| 653 | |||
| 654 | 468 | ExprResult OpRuleManager::getPostfixMinusMinusResultType(ASTNode *node, const ExprResult &lhs) const { | |
| 655 | // Check is there is an overloaded operator function available | ||
| 656 |
1/2✓ Branch 2 → 3 taken 468 times.
✗ Branch 2 → 18 not taken.
|
468 | const ExprResult resultType = isOperatorOverloadingFctAvailable<1>(node, OP_FCT_POSTFIX_MINUS_MINUS, {lhs}, 0); |
| 657 |
3/4✓ Branch 3 → 4 taken 468 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 7 times.
✓ Branch 4 → 6 taken 461 times.
|
468 | if (!resultType.type.is(TY_INVALID)) |
| 658 | 7 | return resultType; | |
| 659 | |||
| 660 | // Check if we try to assign a constant value | ||
| 661 |
1/2✓ Branch 6 → 7 taken 461 times.
✗ Branch 6 → 19 not taken.
|
461 | ensureNoConstAssign(node, lhs.type); |
| 662 | |||
| 663 | // Remove reference wrappers | ||
| 664 |
1/2✓ Branch 7 → 8 taken 461 times.
✗ Branch 7 → 19 not taken.
|
461 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 665 | |||
| 666 | // Check if this is an unsafe operation | ||
| 667 |
3/4✓ Branch 8 → 9 taken 461 times.
✗ Branch 8 → 19 not taken.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 12 taken 459 times.
|
461 | if (lhsType.isPtr()) { |
| 668 |
1/2✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 19 not taken.
|
2 | ensureUnsafeAllowed(node, "--", lhsType); |
| 669 | 2 | return lhs; | |
| 670 | } | ||
| 671 | |||
| 672 |
1/2✓ Branch 14 → 15 taken 459 times.
✗ Branch 14 → 19 not taken.
|
459 | return {validateUnaryOperation(node, POSTFIX_MINUS_MINUS_OP_RULES, std::size(POSTFIX_MINUS_MINUS_OP_RULES), "--", lhsType)}; |
| 673 | } | ||
| 674 | |||
| 675 | 2975 | QualType OpRuleManager::getCastResultType(const ASTNode *node, QualType lhsType, const ExprResult &rhs) const { | |
| 676 | // Remove reference wrappers | ||
| 677 |
1/2✓ Branch 2 → 3 taken 2975 times.
✗ Branch 2 → 57 not taken.
|
2975 | lhsType = lhsType.removeReferenceWrapper(); |
| 678 |
1/2✓ Branch 3 → 4 taken 2975 times.
✗ Branch 3 → 65 not taken.
|
2975 | QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 679 | |||
| 680 | // Only allow to cast the 'heap' qualifier away, if we are in unsafe mode | ||
| 681 |
2/2✓ Branch 6 → 7 taken 108 times.
✓ Branch 6 → 8 taken 2867 times.
|
2975 | if (lhsType.getQualifiers().isHeap != rhsType.getQualifiers().isHeap) |
| 682 |
1/2✓ Branch 7 → 8 taken 108 times.
✗ Branch 7 → 65 not taken.
|
108 | ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType); |
| 683 | |||
| 684 | // Allow identity casts | ||
| 685 |
3/4✓ Branch 8 → 9 taken 2975 times.
✗ Branch 8 → 65 not taken.
✓ Branch 9 → 10 taken 311 times.
✓ Branch 9 → 11 taken 2664 times.
|
2975 | if (lhsType.matches(rhsType, false, true, true)) |
| 686 | 311 | return lhsType; | |
| 687 | // Allow casts string -> char* and string -> char[] | ||
| 688 |
12/16✓ Branch 11 → 12 taken 2664 times.
✗ Branch 11 → 58 not taken.
✓ Branch 12 → 13 taken 1304 times.
✓ Branch 12 → 19 taken 1360 times.
✓ Branch 13 → 14 taken 1304 times.
✗ Branch 13 → 58 not taken.
✓ Branch 14 → 15 taken 1304 times.
✗ Branch 14 → 58 not taken.
✓ Branch 15 → 16 taken 1025 times.
✓ Branch 15 → 19 taken 279 times.
✓ Branch 16 → 17 taken 1025 times.
✗ Branch 16 → 58 not taken.
✓ Branch 17 → 18 taken 1021 times.
✓ Branch 17 → 19 taken 4 times.
✓ Branch 20 → 21 taken 1021 times.
✓ Branch 20 → 22 taken 1643 times.
|
2664 | if (lhsType.isOneOf({TY_PTR, TY_ARRAY}) && lhsType.getContained().is(TY_CHAR) && rhsType.is(TY_STRING)) |
| 689 | 1021 | return lhsType; | |
| 690 | // Allow casts char* -> string and char[] -> string | ||
| 691 |
10/16✓ Branch 22 → 23 taken 1643 times.
✗ Branch 22 → 60 not taken.
✓ Branch 23 → 24 taken 104 times.
✓ Branch 23 → 30 taken 1539 times.
✓ Branch 24 → 25 taken 104 times.
✗ Branch 24 → 60 not taken.
✓ Branch 25 → 26 taken 104 times.
✗ Branch 25 → 30 not taken.
✓ Branch 26 → 27 taken 104 times.
✗ Branch 26 → 60 not taken.
✓ Branch 27 → 28 taken 104 times.
✗ Branch 27 → 60 not taken.
✓ Branch 28 → 29 taken 104 times.
✗ Branch 28 → 30 not taken.
✓ Branch 31 → 32 taken 104 times.
✓ Branch 31 → 33 taken 1539 times.
|
1643 | if (lhsType.is(TY_STRING) && rhsType.isOneOf({TY_PTR, TY_ARRAY}) && rhsType.getContained().is(TY_CHAR)) |
| 692 | 104 | return lhsType; | |
| 693 | // Allow casts any* -> any* | ||
| 694 |
8/10✓ Branch 33 → 34 taken 1539 times.
✗ Branch 33 → 62 not taken.
✓ Branch 34 → 35 taken 283 times.
✓ Branch 34 → 38 taken 1256 times.
✓ Branch 35 → 36 taken 283 times.
✗ Branch 35 → 62 not taken.
✓ Branch 36 → 37 taken 275 times.
✓ Branch 36 → 38 taken 8 times.
✓ Branch 39 → 40 taken 275 times.
✓ Branch 39 → 42 taken 1264 times.
|
1539 | if (lhsType.isOneOf({TY_PTR, TY_STRING}) && rhsType.isOneOf({TY_PTR, TY_STRING})) { |
| 695 |
1/2✓ Branch 40 → 41 taken 275 times.
✗ Branch 40 → 65 not taken.
|
275 | ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType); |
| 696 | 275 | return lhsType; | |
| 697 | } | ||
| 698 | // Allow casts p()/f<>() -> byte* | ||
| 699 |
7/10✓ Branch 42 → 43 taken 1264 times.
✗ Branch 42 → 64 not taken.
✓ Branch 43 → 44 taken 8 times.
✓ Branch 43 → 47 taken 1256 times.
✓ Branch 44 → 45 taken 8 times.
✗ Branch 44 → 64 not taken.
✓ Branch 45 → 46 taken 8 times.
✗ Branch 45 → 47 not taken.
✓ Branch 48 → 49 taken 8 times.
✓ Branch 48 → 51 taken 1256 times.
|
1264 | if (lhsType.isPtrTo(TY_BYTE) && rhsType.isOneOf({TY_FUNCTION, TY_PROCEDURE})) { |
| 700 |
1/2✓ Branch 49 → 50 taken 8 times.
✗ Branch 49 → 65 not taken.
|
8 | ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType); |
| 701 | 8 | return lhsType; | |
| 702 | } | ||
| 703 | // Check primitive type combinations | ||
| 704 |
1/2✓ Branch 53 → 54 taken 1256 times.
✗ Branch 53 → 65 not taken.
|
1256 | return validateBinaryOperation(node, CAST_OP_RULES, std::size(CAST_OP_RULES), "(cast)", lhsType, rhsType, true); |
| 705 | } | ||
| 706 | |||
| 707 | template <size_t N> | ||
| 708 | 20253 | ExprResult OpRuleManager::isOperatorOverloadingFctAvailable(ASTNode *node, const char *const fctName, | |
| 709 | const std::array<ExprResult, N> &op, size_t opIdx) const { | ||
| 710 | static_assert(N == 1 || N == 2, "Only unary and binary operators are overloadable"); | ||
| 711 | 20253 | Scope *calleeParentScope = nullptr; | |
| 712 | 20253 | const Function *callee = nullptr; | |
| 713 |
14/20spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 2 → 3 taken 2524 times.
✗ Branch 2 → 123 not taken.
✓ Branch 3 → 4 taken 2524 times.
✗ Branch 3 → 123 not taken.
✓ Branch 4 → 5 taken 2524 times.
✗ Branch 4 → 123 not taken.
✓ Branch 42 → 43 taken 2724 times.
✓ Branch 42 → 45 taken 17 times.
✓ Branch 48 → 6 taken 22075 times.
✓ Branch 48 → 49 taken 2507 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 2 → 3 taken 17729 times.
✗ Branch 2 → 132 not taken.
✓ Branch 3 → 4 taken 17729 times.
✗ Branch 3 → 132 not taken.
✓ Branch 4 → 5 taken 17729 times.
✗ Branch 4 → 132 not taken.
✓ Branch 49 → 50 taken 59304 times.
✓ Branch 49 → 52 taken 1026 times.
✓ Branch 55 → 6 taken 146419 times.
✓ Branch 55 → 56 taken 16703 times.
|
250775 | for (const auto &sourceFile : typeChecker->resourceManager.sourceFiles | std::views::values) { |
| 714 | // Check if there is a registered operator function | ||
| 715 |
8/12spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 10 → 11 taken 22075 times.
✗ Branch 10 → 102 not taken.
✓ Branch 11 → 12 taken 22075 times.
✗ Branch 11 → 100 not taken.
✓ Branch 14 → 15 taken 19334 times.
✓ Branch 14 → 16 taken 2741 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 10 → 11 taken 146419 times.
✗ Branch 10 → 109 not taken.
✓ Branch 11 → 12 taken 146419 times.
✗ Branch 11 → 107 not taken.
✓ Branch 14 → 15 taken 86089 times.
✓ Branch 14 → 16 taken 60330 times.
|
505482 | if (!sourceFile->getNameRegistryEntry(fctName)) |
| 716 | 105423 | continue; | |
| 717 | |||
| 718 | // Match callees in the global scope of this source file | ||
| 719 | 63071 | calleeParentScope = sourceFile->globalScope.get(); | |
| 720 |
2/4spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 18 → 19 taken 2741 times.
✗ Branch 18 → 122 not taken.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 18 → 19 taken 60330 times.
✗ Branch 18 → 131 not taken.
|
63071 | const QualType thisType(TY_DYN); |
| 721 |
2/4spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 21 → 22 taken 2741 times.
✗ Branch 21 → 106 not taken.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 21 → 22 taken 60330 times.
✗ Branch 21 → 113 not taken.
|
63071 | ArgList args(N); |
| 722 |
2/4spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 24 → 25 taken 2741 times.
✗ Branch 24 → 109 not taken.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 24 → 25 taken 60330 times.
✗ Branch 24 → 116 not taken.
|
63071 | args[0] = {typeChecker->mapLocalTypeToImportedScopeType(calleeParentScope, op[0].type), op[0].isTemporary()}; |
| 723 | if constexpr (N == 2) | ||
| 724 |
1/2✓ Branch 31 → 32 taken 60330 times.
✗ Branch 31 → 118 not taken.
|
60330 | args[1] = {typeChecker->mapLocalTypeToImportedScopeType(calleeParentScope, op[1].type), op[1].isTemporary()}; |
| 725 |
4/8spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 33 → 34 taken 2741 times.
✗ Branch 33 → 113 not taken.
✓ Branch 34 → 35 taken 2741 times.
✗ Branch 34 → 111 not taken.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 40 → 41 taken 60330 times.
✗ Branch 40 → 122 not taken.
✓ Branch 41 → 42 taken 60330 times.
✗ Branch 41 → 120 not taken.
|
189213 | callee = FunctionManager::match(calleeParentScope, fctName, thisType, args, {}, false, node); |
| 726 |
4/4spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 38 → 39 taken 17 times.
✓ Branch 38 → 40 taken 2724 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 45 → 46 taken 1026 times.
✓ Branch 45 → 47 taken 59304 times.
|
63071 | if (callee) |
| 727 | 1043 | break; | |
| 728 | } | ||
| 729 | |||
| 730 | // Return invalid type if the callee was not found | ||
| 731 |
4/4spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 49 → 50 taken 2507 times.
✓ Branch 49 → 52 taken 17 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 56 → 57 taken 16703 times.
✓ Branch 56 → 59 taken 1026 times.
|
20253 | if (!callee) |
| 732 | 19210 | return ExprResult(QualType(TY_INVALID)); | |
| 733 |
2/4spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✗ Branch 52 → 53 not taken.
✓ Branch 52 → 54 taken 17 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✗ Branch 59 → 60 not taken.
✓ Branch 59 → 61 taken 1026 times.
|
1043 | assert(calleeParentScope != nullptr); |
| 734 | |||
| 735 | // Save the pointer to the operator function in the AST node | ||
| 736 | 1043 | std::vector<const Function *> &opFctPointers = typeChecker->getOpFctPointers(node); | |
| 737 |
3/4spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✗ Branch 56 → 57 not taken.
✓ Branch 56 → 59 taken 17 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 63 → 64 taken 83 times.
✓ Branch 63 → 66 taken 943 times.
|
1043 | if (opFctPointers.size() <= opIdx) |
| 738 |
1/4spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✗ Branch 57 → 58 not taken.
✗ Branch 57 → 124 not taken.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 64 → 65 taken 83 times.
✗ Branch 64 → 133 not taken.
|
83 | opFctPointers.resize(opIdx + 1, nullptr); |
| 739 | 1043 | opFctPointers.at(opIdx) = callee; | |
| 740 | |||
| 741 | // Check if we need to request a re-visit, because the function body was not type-checked yet | ||
| 742 | 1043 | TypeChecker::requestRevisitIfRequired(callee); | |
| 743 | |||
| 744 | // Check if the called function has sufficient visibility | ||
| 745 |
6/8spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 61 → 62 taken 17 times.
✗ Branch 61 → 65 not taken.
✓ Branch 63 → 64 taken 15 times.
✓ Branch 63 → 65 taken 2 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 68 → 69 taken 1026 times.
✗ Branch 68 → 72 not taken.
✓ Branch 70 → 71 taken 491 times.
✓ Branch 70 → 72 taken 535 times.
|
1043 | const bool isImported = calleeParentScope != nullptr && calleeParentScope->isImportedBy(typeChecker->rootScope); |
| 746 | 1043 | const SymbolTableEntry *calleeEntry = callee->entry; | |
| 747 |
10/12spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 66 → 67 taken 15 times.
✓ Branch 66 → 71 taken 2 times.
✓ Branch 69 → 70 taken 1 time.
✓ Branch 69 → 71 taken 14 times.
✓ Branch 72 → 73 taken 1 time.
✓ Branch 72 → 82 taken 16 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 73 → 74 taken 491 times.
✓ Branch 73 → 78 taken 535 times.
✗ Branch 76 → 77 not taken.
✓ Branch 76 → 78 taken 491 times.
✗ Branch 79 → 80 not taken.
✓ Branch 79 → 89 taken 1026 times.
|
1043 | if (isImported && !calleeEntry->getQualType().isPublic()) |
| 748 |
1/4spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 77 → 78 taken 1 time.
✗ Branch 77 → 125 not taken.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✗ Branch 84 → 85 not taken.
✗ Branch 84 → 134 not taken.
|
2 | throw SemanticError(node, INSUFFICIENT_VISIBILITY, |
| 749 |
3/12spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 74 → 75 taken 1 time.
✗ Branch 74 → 132 not taken.
✓ Branch 75 → 76 taken 1 time.
✗ Branch 75 → 130 not taken.
✓ Branch 76 → 77 taken 1 time.
✗ Branch 76 → 128 not taken.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✗ Branch 81 → 82 not taken.
✗ Branch 81 → 141 not taken.
✗ Branch 82 → 83 not taken.
✗ Branch 82 → 139 not taken.
✗ Branch 83 → 84 not taken.
✗ Branch 83 → 137 not taken.
|
2 | "Overloaded operator '" + callee->getSignature() + "' has insufficient visibility"); |
| 750 | |||
| 751 | // Procedures always have the return type 'bool' | ||
| 752 |
4/4spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 85 → 86 taken 14 times.
✓ Branch 85 → 88 taken 2 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 92 → 93 taken 223 times.
✓ Branch 92 → 95 taken 803 times.
|
1042 | if (callee->isProcedure()) |
| 753 | 237 | return ExprResult(QualType(TY_BOOL)); | |
| 754 | 805 | const QualType &returnType = callee->returnType; | |
| 755 | |||
| 756 | // Add anonymous symbol to keep track of dtor call, if non-trivially destructible | ||
| 757 | 805 | SymbolTableEntry *anonymousSymbol = nullptr; | |
| 758 |
8/12spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✗ Branch 89 → 90 not taken.
✓ Branch 89 → 93 taken 2 times.
✗ Branch 91 → 92 not taken.
✗ Branch 91 → 93 not taken.
✗ Branch 94 → 95 not taken.
✓ Branch 94 → 97 taken 2 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 96 → 97 taken 85 times.
✓ Branch 96 → 100 taken 718 times.
✓ Branch 98 → 99 taken 79 times.
✓ Branch 98 → 100 taken 6 times.
✓ Branch 101 → 102 taken 79 times.
✓ Branch 101 → 104 taken 724 times.
|
805 | if (returnType.is(TY_STRUCT) && !returnType.isTriviallyDestructible(node)) |
| 759 | 79 | anonymousSymbol = typeChecker->currentScope->symbolTable.insertAnonymous(returnType, node, opIdx); | |
| 760 | |||
| 761 | 805 | return {typeChecker->mapImportedScopeTypeToLocalType(calleeParentScope, returnType), anonymousSymbol}; | |
| 762 | } | ||
| 763 | |||
| 764 | 4289 | QualType OpRuleManager::validateUnaryOperation(const ASTNode *node, const UnaryOpRule opRules[], size_t opRulesSize, | |
| 765 | const char *name, const QualType &lhs) { | ||
| 766 |
2/2✓ Branch 11 → 3 taken 10451 times.
✓ Branch 11 → 12 taken 2 times.
|
10453 | for (size_t i = 0; i < opRulesSize; i++) { |
| 767 | 10451 | const UnaryOpRule &rule = opRules[i]; | |
| 768 |
2/2✓ Branch 5 → 6 taken 4287 times.
✓ Branch 5 → 10 taken 6164 times.
|
10451 | if (std::get<0>(rule) == lhs.getSuperType()) |
| 769 |
1/2✓ Branch 7 → 8 taken 4287 times.
✗ Branch 7 → 16 not taken.
|
4287 | return QualType(std::get<1>(rule)); |
| 770 | } | ||
| 771 |
1/2✓ Branch 13 → 14 taken 2 times.
✗ Branch 13 → 17 not taken.
|
2 | throw getExceptionUnary(node, name, lhs); |
| 772 | } | ||
| 773 | |||
| 774 | 42107 | QualType OpRuleManager::validateBinaryOperation(const ASTNode *node, const BinaryOpRule opRules[], size_t opRulesSize, | |
| 775 | const char *name, const QualType &lhs, const QualType &rhs, | ||
| 776 | bool preserveQualifiersFromLhs, const char *customMessagePrefix) { | ||
| 777 |
2/2✓ Branch 19 → 3 taken 415142 times.
✓ Branch 19 → 20 taken 19 times.
|
415161 | for (size_t i = 0; i < opRulesSize; i++) { |
| 778 | 415142 | const BinaryOpRule &rule = opRules[i]; | |
| 779 |
6/6✓ Branch 5 → 6 taken 82205 times.
✓ Branch 5 → 10 taken 332937 times.
✓ Branch 8 → 9 taken 42088 times.
✓ Branch 8 → 10 taken 40117 times.
✓ Branch 11 → 12 taken 42088 times.
✓ Branch 11 → 18 taken 373054 times.
|
415142 | if (std::get<0>(rule) == lhs.getSuperType() && std::get<1>(rule) == rhs.getSuperType()) { |
| 780 |
1/2✓ Branch 13 → 14 taken 42088 times.
✗ Branch 13 → 24 not taken.
|
42088 | QualType resultType((std::get<2>(rule))); |
| 781 |
2/2✓ Branch 14 → 15 taken 23188 times.
✓ Branch 14 → 17 taken 18900 times.
|
42088 | if (preserveQualifiersFromLhs) |
| 782 | 23188 | resultType.setQualifiers(lhs.getQualifiers()); | |
| 783 | 42088 | return resultType; | |
| 784 | } | ||
| 785 | } | ||
| 786 |
1/2✓ Branch 21 → 22 taken 19 times.
✗ Branch 21 → 25 not taken.
|
19 | throw getExceptionBinary(node, name, lhs, rhs, customMessagePrefix); |
| 787 | } | ||
| 788 | |||
| 789 | 2 | SemanticError OpRuleManager::getExceptionUnary(const ASTNode *node, const char *name, const QualType &lhs) { | |
| 790 |
6/12✓ Branch 2 → 3 taken 2 times.
✗ Branch 2 → 35 not taken.
✓ Branch 5 → 6 taken 2 times.
✗ Branch 5 → 27 not taken.
✓ Branch 6 → 7 taken 2 times.
✗ Branch 6 → 25 not taken.
✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 23 not taken.
✓ Branch 8 → 9 taken 2 times.
✗ Branch 8 → 21 not taken.
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 19 not taken.
|
8 | return {node, OPERATOR_WRONG_DATA_TYPE, "Cannot apply '" + std::string(name) + "' operator on type " + lhs.getName(true)}; |
| 791 | } | ||
| 792 | |||
| 793 | 19 | SemanticError OpRuleManager::getExceptionBinary(const ASTNode *node, const char *name, const QualType &lhs, const QualType &rhs, | |
| 794 | const char *messagePrefix) { | ||
| 795 | // Build error message | ||
| 796 |
1/2✓ Branch 2 → 3 taken 19 times.
✗ Branch 2 → 50 not taken.
|
19 | std::stringstream errorMsg; |
| 797 |
2/2✓ Branch 3 → 4 taken 4 times.
✓ Branch 3 → 14 taken 15 times.
|
19 | if (strlen(messagePrefix) != 0) |
| 798 |
7/14✓ Branch 4 → 5 taken 4 times.
✗ Branch 4 → 48 not taken.
✓ Branch 5 → 6 taken 4 times.
✗ Branch 5 → 48 not taken.
✓ Branch 6 → 7 taken 4 times.
✗ Branch 6 → 37 not taken.
✓ Branch 7 → 8 taken 4 times.
✗ Branch 7 → 35 not taken.
✓ Branch 8 → 9 taken 4 times.
✗ Branch 8 → 35 not taken.
✓ Branch 9 → 10 taken 4 times.
✗ Branch 9 → 34 not taken.
✓ Branch 10 → 11 taken 4 times.
✗ Branch 10 → 32 not taken.
|
4 | errorMsg << messagePrefix << ". Expected " << lhs.getName(true) << " but got " << rhs.getName(true); |
| 799 | else | ||
| 800 |
8/16✓ Branch 14 → 15 taken 15 times.
✗ Branch 14 → 48 not taken.
✓ Branch 15 → 16 taken 15 times.
✗ Branch 15 → 48 not taken.
✓ Branch 16 → 17 taken 15 times.
✗ Branch 16 → 48 not taken.
✓ Branch 17 → 18 taken 15 times.
✗ Branch 17 → 43 not taken.
✓ Branch 18 → 19 taken 15 times.
✗ Branch 18 → 41 not taken.
✓ Branch 19 → 20 taken 15 times.
✗ Branch 19 → 41 not taken.
✓ Branch 20 → 21 taken 15 times.
✗ Branch 20 → 40 not taken.
✓ Branch 21 → 22 taken 15 times.
✗ Branch 21 → 38 not taken.
|
15 | errorMsg << "Cannot apply '" << name << "' operator on types " << lhs.getName(true) << " and " << rhs.getName(true); |
| 801 | |||
| 802 | // Return the exception | ||
| 803 |
2/4✓ Branch 25 → 26 taken 19 times.
✗ Branch 25 → 46 not taken.
✓ Branch 26 → 27 taken 19 times.
✗ Branch 26 → 44 not taken.
|
57 | return {node, OPERATOR_WRONG_DATA_TYPE, errorMsg.str()}; |
| 804 | 19 | } | |
| 805 | |||
| 806 | 12 | void OpRuleManager::ensureUnsafeAllowed(const ASTNode *node, const char *name, const QualType &lhs) const { | |
| 807 |
2/4✓ Branch 2 → 3 taken 12 times.
✗ Branch 2 → 43 not taken.
✓ Branch 3 → 4 taken 12 times.
✗ Branch 3 → 5 not taken.
|
12 | if (typeChecker->currentScope->doesAllowUnsafeOperations()) |
| 808 | 12 | return; | |
| 809 | // Print error message | ||
| 810 | ✗ | const std::string lhsName = lhs.getName(true); | |
| 811 | ✗ | const std::string errorMsg = "Cannot apply '" + std::string(name) + "' operator on type " + lhsName + | |
| 812 | ✗ | " as this is an unsafe operation. Please use unsafe blocks if you know what you are doing."; | |
| 813 | ✗ | SOFT_ERROR_VOID(node, UNSAFE_OPERATION_IN_SAFE_CONTEXT, errorMsg) | |
| 814 | ✗ | } | |
| 815 | |||
| 816 | 1019 | void OpRuleManager::ensureUnsafeAllowed(const ASTNode *node, const char *name, const QualType &lhs, const QualType &rhs) const { | |
| 817 |
3/4✓ Branch 2 → 3 taken 1019 times.
✗ Branch 2 → 57 not taken.
✓ Branch 3 → 4 taken 1018 times.
✓ Branch 3 → 5 taken 1 time.
|
1019 | if (typeChecker->currentScope->doesAllowUnsafeOperations()) |
| 818 | 1018 | return; | |
| 819 | // Print error message | ||
| 820 |
1/2✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 57 not taken.
|
1 | const std::string lhsName = lhs.getName(true); |
| 821 |
1/2✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 55 not taken.
|
1 | const std::string rhsName = rhs.getName(true); |
| 822 |
6/12✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 42 not taken.
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 40 not taken.
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 38 not taken.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 36 not taken.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 34 not taken.
✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 32 not taken.
|
2 | const std::string errorMsg = "Cannot apply '" + std::string(name) + "' operator on types " + lhsName + " and " + rhsName + |
| 823 |
1/2✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 30 not taken.
|
1 | " as this is an unsafe operation. Please use unsafe blocks if you know what you are doing."; |
| 824 |
1/2✓ Branch 23 → 24 taken 1 time.
✗ Branch 23 → 51 not taken.
|
1 | SOFT_ERROR_VOID(node, UNSAFE_OPERATION_IN_SAFE_CONTEXT, errorMsg) |
| 825 | 1 | } | |
| 826 | |||
| 827 | 32975 | void OpRuleManager::ensureNoConstAssign(const ASTNode *node, const QualType &lhs, bool isDecl, bool isReturn) const { | |
| 828 | // Check if we try to assign a constant value | ||
| 829 |
10/12✓ Branch 2 → 3 taken 32975 times.
✗ Branch 2 → 18 not taken.
✓ Branch 3 → 4 taken 32975 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 3663 times.
✓ Branch 4 → 8 taken 29312 times.
✓ Branch 5 → 6 taken 57 times.
✓ Branch 5 → 8 taken 3606 times.
✓ Branch 6 → 7 taken 14 times.
✓ Branch 6 → 8 taken 43 times.
✓ Branch 9 → 10 taken 14 times.
✓ Branch 9 → 17 taken 32961 times.
|
32975 | if (lhs.removeReferenceWrapper().isConst() && !isDecl && !isReturn) { |
| 830 |
2/4✓ Branch 10 → 11 taken 14 times.
✗ Branch 10 → 21 not taken.
✓ Branch 11 → 12 taken 14 times.
✗ Branch 11 → 19 not taken.
|
14 | const std::string errorMessage = "Trying to assign value to an immutable variable of type " + lhs.getName(true); |
| 831 |
1/2✓ Branch 13 → 14 taken 14 times.
✗ Branch 13 → 22 not taken.
|
14 | SOFT_ERROR_VOID(node, REASSIGN_CONST_VARIABLE, errorMessage); |
| 832 | 14 | } | |
| 833 | } | ||
| 834 | |||
| 835 | } // namespace spice::compiler | ||
| 836 |