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 | 8499 | OpRuleManager::OpRuleManager(TypeChecker *typeChecker) | |
| 16 | 8499 | : typeChecker(typeChecker), resourceManager(typeChecker->resourceManager) {} | |
| 17 | |||
| 18 | 72814 | 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 | 72814 | const QualType lhsType = lhs.type; | |
| 22 | 72814 | 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 72813 times.
|
72814 | if (lhs.isTemporary()) |
| 26 |
2/4✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 86 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 83 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 72813 times.
✗ Branch 12 → 98 not taken.
✓ Branch 13 → 14 taken 578 times.
✓ Branch 13 → 16 taken 72235 times.
|
72813 | if (lhsType.is(TY_DYN)) |
| 30 | 578 | return {rhsType, nullptr}; | |
| 31 | |||
| 32 | // Check if we try to assign a constant value | ||
| 33 |
1/2✓ Branch 16 → 17 taken 72235 times.
✗ Branch 16 → 98 not taken.
|
72235 | ensureNoConstAssign(node, lhsType, isDecl, isReturn); |
| 34 | |||
| 35 | // Allow pointers and references of the same type straight away | ||
| 36 |
8/10✓ Branch 17 → 18 taken 72235 times.
✗ Branch 17 → 92 not taken.
✓ Branch 18 → 19 taken 14134 times.
✓ Branch 18 → 22 taken 58101 times.
✓ Branch 19 → 20 taken 14134 times.
✗ Branch 19 → 92 not taken.
✓ Branch 20 → 21 taken 11473 times.
✓ Branch 20 → 22 taken 2661 times.
✓ Branch 23 → 24 taken 11473 times.
✓ Branch 23 → 41 taken 60762 times.
|
72235 | 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 4051 times.
✓ Branch 24 → 35 taken 7422 times.
✓ Branch 25 → 26 taken 4051 times.
✗ Branch 25 → 93 not taken.
✓ Branch 26 → 27 taken 2739 times.
✓ Branch 26 → 35 taken 1312 times.
✓ Branch 27 → 28 taken 2739 times.
✗ Branch 27 → 93 not taken.
✓ Branch 28 → 29 taken 1074 times.
✓ Branch 28 → 35 taken 1665 times.
✓ Branch 29 → 30 taken 1074 times.
✗ Branch 29 → 93 not taken.
✓ Branch 30 → 31 taken 1074 times.
✗ Branch 30 → 93 not taken.
✓ Branch 31 → 32 taken 1074 times.
✗ Branch 31 → 35 not taken.
✓ Branch 32 → 33 taken 1074 times.
✗ Branch 32 → 93 not taken.
✓ Branch 33 → 34 taken 1074 times.
✗ Branch 33 → 35 not taken.
✓ Branch 36 → 37 taken 1074 times.
✓ Branch 36 → 39 taken 10399 times.
|
11473 | if (rhs.entry && lhsType.isPtr() && lhsType.isHeap() && rhsType.removeReferenceWrapper().isPtr() && rhsType.isHeap()) |
| 39 |
1/2✓ Branch 37 → 38 taken 1074 times.
✗ Branch 37 → 94 not taken.
|
1074 | rhs.entry->updateState(MOVED, node); |
| 40 | 11473 | return {rhsType, nullptr}; | |
| 41 | } | ||
| 42 | // Allow ref type to type of the same contained type straight away | ||
| 43 |
3/4✓ Branch 41 → 42 taken 60762 times.
✗ Branch 41 → 98 not taken.
✓ Branch 42 → 43 taken 1662 times.
✓ Branch 42 → 55 taken 59100 times.
|
60762 | if (rhsType.isRef()) { |
| 44 | // If this is const ref, remove both: the reference and the constness | ||
| 45 |
2/4✓ Branch 43 → 44 taken 1662 times.
✗ Branch 43 → 95 not taken.
✓ Branch 44 → 45 taken 1662 times.
✗ Branch 44 → 95 not taken.
|
1662 | const QualType rhsNonRef = rhsType.getContained().toNonConst(); |
| 46 |
3/4✓ Branch 45 → 46 taken 1662 times.
✗ Branch 45 → 96 not taken.
✓ Branch 46 → 47 taken 1660 times.
✓ Branch 46 → 53 taken 2 times.
|
1662 | if (lhsType.matches(rhsNonRef, false, false, true)) { |
| 47 |
3/4✓ Branch 47 → 48 taken 1660 times.
✗ Branch 47 → 96 not taken.
✓ Branch 48 → 49 taken 786 times.
✓ Branch 48 → 51 taken 874 times.
|
1660 | if (rhsNonRef.is(TY_STRUCT)) |
| 48 |
1/2✓ Branch 49 → 50 taken 786 times.
✗ Branch 49 → 96 not taken.
|
1660 | return performStructAssign(node, lhs, rhs, rhsNonRef, isDecl, isReturn); |
| 49 | 874 | 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 59102 times.
✗ Branch 55 → 97 not taken.
✓ Branch 56 → 57 taken 340 times.
✓ Branch 56 → 60 taken 58762 times.
✓ Branch 57 → 58 taken 340 times.
✗ Branch 57 → 97 not taken.
✓ Branch 58 → 59 taken 335 times.
✓ Branch 58 → 60 taken 5 times.
✓ Branch 61 → 62 taken 335 times.
✓ Branch 61 → 64 taken 58767 times.
|
59102 | if (lhsType.isOneOf({TY_ARRAY, TY_INTERFACE, TY_FUNCTION, TY_PROCEDURE}) && lhsType.matches(rhsType, false, true, true)) |
| 54 | 335 | return {rhsType, nullptr}; | |
| 55 | // Allow struct of the same type straight away | ||
| 56 |
8/10✓ Branch 64 → 65 taken 58767 times.
✗ Branch 64 → 98 not taken.
✓ Branch 65 → 66 taken 11834 times.
✓ Branch 65 → 69 taken 46933 times.
✓ Branch 66 → 67 taken 11834 times.
✗ Branch 66 → 98 not taken.
✓ Branch 67 → 68 taken 11833 times.
✓ Branch 67 → 69 taken 1 time.
✓ Branch 70 → 71 taken 11833 times.
✓ Branch 70 → 73 taken 46934 times.
|
58767 | if (lhsType.is(TY_STRUCT) && lhsType.matches(rhsType, false, true, true)) |
| 57 |
1/2✓ Branch 71 → 72 taken 11833 times.
✗ Branch 71 → 98 not taken.
|
11833 | return performStructAssign(node, lhs, rhs, rhsType, isDecl, isReturn); |
| 58 | |||
| 59 | // Check common type combinations | ||
| 60 |
2/2✓ Branch 73 → 74 taken 46932 times.
✓ Branch 73 → 98 taken 2 times.
|
46934 | const QualType resultType = getAssignResultTypeCommon(node, lhs, rhs, isDecl, isReturn); |
| 61 |
3/4✓ Branch 74 → 75 taken 46932 times.
✗ Branch 74 → 98 not taken.
✓ Branch 75 → 76 taken 2017 times.
✓ Branch 75 → 78 taken 44915 times.
|
46932 | if (!resultType.is(TY_INVALID)) |
| 62 | 2017 | return {resultType, nullptr}; | |
| 63 | |||
| 64 | // Check primitive type combinations | ||
| 65 | 44915 | const QualType binOpType = | |
| 66 |
2/2✓ Branch 78 → 79 taken 44902 times.
✓ Branch 78 → 98 taken 13 times.
|
44915 | validateBinaryOperation(node, ASSIGN_OP_RULES, std::size(ASSIGN_OP_RULES), "=", lhsType, rhsType, true, errMsgPrefix); |
| 67 | 44902 | return {binOpType, nullptr}; | |
| 68 | } | ||
| 69 | |||
| 70 | 1736 | QualType OpRuleManager::getFieldAssignResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, bool imm, | |
| 71 | bool isDecl) const { | ||
| 72 | // Retrieve types | ||
| 73 | 1736 | const QualType lhsType = lhs.type; | |
| 74 | 1736 | const QualType rhsType = rhs.type; | |
| 75 |
2/4✓ Branch 2 → 3 taken 1736 times.
✗ Branch 2 → 96 not taken.
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 1736 times.
|
1736 | assert(!lhsType.is(TY_DYN)); |
| 76 | |||
| 77 | // Check if we try to assign a constant value | ||
| 78 |
1/2✓ Branch 5 → 6 taken 1736 times.
✗ Branch 5 → 96 not taken.
|
1736 | ensureNoConstAssign(node, lhsType, isDecl); |
| 79 | |||
| 80 | // Allow pointers, arrays and structs of the same type straight away | ||
| 81 |
8/10✓ Branch 6 → 7 taken 1736 times.
✗ Branch 6 → 85 not taken.
✓ Branch 7 → 8 taken 1115 times.
✓ Branch 7 → 11 taken 621 times.
✓ Branch 8 → 9 taken 1115 times.
✗ Branch 8 → 85 not taken.
✓ Branch 9 → 10 taken 1112 times.
✓ Branch 9 → 11 taken 3 times.
✓ Branch 12 → 13 taken 1112 times.
✓ Branch 12 → 29 taken 624 times.
|
1736 | 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 264 times.
✓ Branch 13 → 24 taken 848 times.
✓ Branch 14 → 15 taken 264 times.
✗ Branch 14 → 86 not taken.
✓ Branch 15 → 16 taken 262 times.
✓ Branch 15 → 24 taken 2 times.
✓ Branch 16 → 17 taken 262 times.
✗ Branch 16 → 86 not taken.
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 24 taken 262 times.
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 86 not taken.
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 86 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 24 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 86 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 24 not taken.
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 28 taken 1112 times.
|
1112 | if (rhs.entry && lhsType.isPtr() && lhsType.isHeap() && rhsType.removeReferenceWrapper().isPtr() && rhsType.isHeap()) |
| 84 | ✗ | rhs.entry->updateState(MOVED, node); | |
| 85 | 1112 | return rhsType; | |
| 86 | } | ||
| 87 | // Allow struct of the same type straight away | ||
| 88 |
8/10✓ Branch 29 → 30 taken 624 times.
✗ Branch 29 → 96 not taken.
✓ Branch 30 → 31 taken 58 times.
✓ Branch 30 → 34 taken 566 times.
✓ Branch 31 → 32 taken 58 times.
✗ Branch 31 → 96 not taken.
✓ Branch 32 → 33 taken 39 times.
✓ Branch 32 → 34 taken 19 times.
✓ Branch 35 → 36 taken 39 times.
✓ Branch 35 → 38 taken 585 times.
|
624 | if (lhsType.is(TY_STRUCT) && lhsType.matches(rhsType, false, true, true)) |
| 89 |
1/2✓ Branch 36 → 37 taken 39 times.
✗ Branch 36 → 88 not taken.
|
39 | 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 38 → 39 taken 585 times.
✗ Branch 38 → 89 not taken.
✓ Branch 39 → 40 taken 63 times.
✓ Branch 39 → 44 taken 522 times.
✓ Branch 40 → 41 taken 63 times.
✗ Branch 40 → 89 not taken.
✓ Branch 41 → 42 taken 63 times.
✗ Branch 41 → 89 not taken.
✓ Branch 42 → 43 taken 1 time.
✓ Branch 42 → 44 taken 62 times.
✓ Branch 45 → 46 taken 1 time.
✓ Branch 45 → 61 taken 584 times.
|
585 | if (rhsType.isRef() && lhsType.matches(rhsType.getContained(), false, false, true)) { |
| 92 | // Check is there is an overloaded operator function available | ||
| 93 |
1/2✓ Branch 46 → 47 taken 1 time.
✗ Branch 46 → 90 not taken.
|
1 | const auto [type, _] = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_ASSIGN, {lhs, rhs}, 0); |
| 94 |
2/4✓ Branch 47 → 48 taken 1 time.
✗ Branch 47 → 92 not taken.
✗ Branch 48 → 49 not taken.
✓ Branch 48 → 50 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 50 → 51 taken 1 time.
✗ Branch 50 → 91 not taken.
✓ Branch 51 → 52 taken 1 time.
✗ Branch 51 → 91 not taken.
✗ Branch 52 → 53 not taken.
✓ Branch 52 → 56 taken 1 time.
✗ Branch 54 → 55 not taken.
✗ Branch 54 → 56 not taken.
✗ Branch 57 → 58 not taken.
✓ Branch 57 → 59 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 61 → 62 taken 584 times.
✗ Branch 61 → 96 not taken.
✓ Branch 62 → 63 taken 62 times.
✓ Branch 62 → 70 taken 522 times.
|
584 | if (rhsType.isRef()) { |
| 104 | // If this is const ref, remove both: the reference and the constness | ||
| 105 |
2/4✓ Branch 63 → 64 taken 62 times.
✗ Branch 63 → 93 not taken.
✓ Branch 64 → 65 taken 62 times.
✗ Branch 64 → 93 not taken.
|
62 | const QualType rhsNonRef = rhsType.getContained().toNonConst(); |
| 106 |
2/4✓ Branch 65 → 66 taken 62 times.
✗ Branch 65 → 95 not taken.
✓ Branch 66 → 67 taken 62 times.
✗ Branch 66 → 69 not taken.
|
62 | if (lhsType.matches(rhsNonRef, false, false, true)) |
| 107 |
1/2✓ Branch 67 → 68 taken 62 times.
✗ Branch 67 → 94 not taken.
|
62 | 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 70 → 71 taken 522 times.
✗ Branch 70 → 96 not taken.
✓ Branch 71 → 72 taken 1 time.
✓ Branch 71 → 74 taken 521 times.
✓ Branch 72 → 73 taken 1 time.
✗ Branch 72 → 74 not taken.
✓ Branch 75 → 76 taken 1 time.
✓ Branch 75 → 77 taken 521 times.
|
522 | if (lhsType.isConstRef() && imm) |
| 111 | 1 | return rhsType; | |
| 112 | |||
| 113 | // Check common type combinations | ||
| 114 |
1/2✓ Branch 77 → 78 taken 521 times.
✗ Branch 77 → 96 not taken.
|
521 | const QualType resultType = getAssignResultTypeCommon(node, lhs, rhs, isDecl, false); |
| 115 |
3/4✓ Branch 78 → 79 taken 521 times.
✗ Branch 78 → 96 not taken.
✓ Branch 79 → 80 taken 4 times.
✓ Branch 79 → 81 taken 517 times.
|
521 | if (!resultType.is(TY_INVALID)) |
| 116 | 4 | return resultType; | |
| 117 | |||
| 118 | // Check primitive type combinations | ||
| 119 |
2/2✓ Branch 81 → 82 taken 516 times.
✓ Branch 81 → 96 taken 1 time.
|
517 | return validateBinaryOperation(node, ASSIGN_OP_RULES, std::size(ASSIGN_OP_RULES), "=", lhsType, rhsType, true, |
| 120 | 516 | ERROR_FIELD_ASSIGN); | |
| 121 | } | ||
| 122 | |||
| 123 | 47455 | QualType OpRuleManager::getAssignResultTypeCommon(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, bool isDecl, | |
| 124 | bool isReturn) { | ||
| 125 | // Retrieve types | ||
| 126 | 47455 | const QualType lhsType = lhs.type; | |
| 127 | 47455 | 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 47455 times.
✗ Branch 2 → 112 not taken.
✓ Branch 3 → 4 taken 1548 times.
✓ Branch 3 → 8 taken 45907 times.
✓ Branch 4 → 5 taken 1548 times.
✗ Branch 4 → 112 not taken.
✓ Branch 5 → 6 taken 1548 times.
✗ Branch 5 → 112 not taken.
✓ Branch 6 → 7 taken 1545 times.
✓ Branch 6 → 8 taken 3 times.
✓ Branch 9 → 10 taken 1545 times.
✓ Branch 9 → 44 taken 45910 times.
|
47455 | if (lhsType.isRef() && lhsType.getContained().matches(rhsType, false, false, true)) { |
| 131 |
4/4✓ Branch 10 → 11 taken 1277 times.
✓ Branch 10 → 12 taken 268 times.
✓ Branch 11 → 12 taken 1088 times.
✓ Branch 11 → 13 taken 189 times.
|
1545 | const bool isDeclOrReturn = isDecl || isReturn; |
| 132 |
7/8✓ Branch 14 → 15 taken 1356 times.
✓ Branch 14 → 19 taken 189 times.
✓ Branch 16 → 17 taken 1356 times.
✗ Branch 16 → 136 not taken.
✓ Branch 17 → 18 taken 1 time.
✓ Branch 17 → 19 taken 1355 times.
✓ Branch 20 → 21 taken 1 time.
✓ Branch 20 → 29 taken 1544 times.
|
1545 | if (isDeclOrReturn && !lhsType.canBind(rhsType, rhs.isTemporary())) |
| 133 |
2/4✓ Branch 24 → 25 taken 1 time.
✗ Branch 24 → 116 not taken.
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 113 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 1088 times.
✓ Branch 29 → 33 taken 456 times.
✓ Branch 31 → 32 taken 1 time.
✓ Branch 31 → 33 taken 1087 times.
✓ Branch 34 → 35 taken 1 time.
✓ Branch 34 → 43 taken 1543 times.
|
1544 | if (isReturn && rhs.isTemporary()) |
| 135 |
2/4✓ Branch 38 → 39 taken 1 time.
✗ Branch 38 → 125 not taken.
✓ Branch 39 → 40 taken 1 time.
✗ Branch 39 → 122 not taken.
|
3 | throw SemanticError(node, RETURN_OF_TEMPORARY_VALUE, "Cannot return reference to temporary value"); |
| 136 | 1543 | return lhsType; | |
| 137 | } | ||
| 138 | // Allow char* = string | ||
| 139 |
9/14✓ Branch 44 → 45 taken 45910 times.
✗ Branch 44 → 136 not taken.
✓ Branch 45 → 46 taken 1 time.
✓ Branch 45 → 53 taken 45909 times.
✓ Branch 46 → 47 taken 1 time.
✗ Branch 46 → 136 not taken.
✓ Branch 47 → 48 taken 1 time.
✗ Branch 47 → 53 not taken.
✓ Branch 50 → 51 taken 1 time.
✗ Branch 50 → 136 not taken.
✓ Branch 51 → 52 taken 1 time.
✗ Branch 51 → 53 not taken.
✓ Branch 54 → 55 taken 1 time.
✓ Branch 54 → 56 taken 45909 times.
|
45910 | 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 45909 times.
✗ Branch 56 → 131 not taken.
✓ Branch 57 → 58 taken 478 times.
✓ Branch 57 → 65 taken 45431 times.
✓ Branch 58 → 59 taken 478 times.
✗ Branch 58 → 131 not taken.
✓ Branch 59 → 60 taken 7 times.
✓ Branch 59 → 65 taken 471 times.
✓ Branch 60 → 61 taken 7 times.
✗ Branch 60 → 131 not taken.
✓ Branch 61 → 62 taken 7 times.
✗ Branch 61 → 131 not taken.
✓ Branch 62 → 63 taken 7 times.
✗ Branch 62 → 131 not taken.
✓ Branch 63 → 64 taken 7 times.
✗ Branch 63 → 65 not taken.
✓ Branch 66 → 67 taken 7 times.
✓ Branch 66 → 68 taken 45902 times.
|
45909 | if (lhsType.isPtr() && rhsType.isArray() && lhsType.getContained().matches(rhsType.getContained(), false, false, true)) |
| 143 | 7 | return lhsType; | |
| 144 | // Allow interface* = struct* or interface& = struct that implements this interface | ||
| 145 |
1/2✓ Branch 70 → 71 taken 45902 times.
✗ Branch 70 → 136 not taken.
|
45902 | const bool sameChainDepth = Type::hasSameTypeChainDepth(lhsType.getType(), rhsType.getType()); |
| 146 |
10/14✓ Branch 71 → 72 taken 45902 times.
✗ Branch 71 → 136 not taken.
✓ Branch 72 → 73 taken 471 times.
✓ Branch 72 → 76 taken 45431 times.
✓ Branch 73 → 74 taken 471 times.
✗ Branch 73 → 136 not taken.
✓ Branch 74 → 75 taken 470 times.
✓ Branch 74 → 76 taken 1 time.
✗ Branch 75 → 76 not taken.
✓ Branch 75 → 78 taken 470 times.
✓ Branch 76 → 77 taken 45432 times.
✗ Branch 76 → 136 not taken.
✓ Branch 77 → 78 taken 3 times.
✓ Branch 77 → 79 taken 45429 times.
|
45902 | const bool typesCompatible = (lhsType.isPtr() && rhsType.isPtr() && sameChainDepth) || lhsType.isRef(); |
| 147 |
9/12✓ Branch 80 → 81 taken 473 times.
✓ Branch 80 → 86 taken 45429 times.
✓ Branch 81 → 82 taken 473 times.
✗ Branch 81 → 136 not taken.
✓ Branch 82 → 83 taken 55 times.
✓ Branch 82 → 86 taken 418 times.
✓ Branch 83 → 84 taken 55 times.
✗ Branch 83 → 136 not taken.
✓ Branch 84 → 85 taken 55 times.
✗ Branch 84 → 86 not taken.
✓ Branch 87 → 88 taken 55 times.
✓ Branch 87 → 93 taken 45847 times.
|
45902 | if (typesCompatible && lhsType.isBase(TY_INTERFACE) && rhsType.isBase(TY_STRUCT)) { |
| 148 | 55 | QualType lhsTypeCopy = lhsType; | |
| 149 | 55 | QualType rhsTypeCopy = rhsType; | |
| 150 |
1/2✓ Branch 88 → 89 taken 55 times.
✗ Branch 88 → 133 not taken.
|
55 | QualType::unwrapBothWithRefWrappers(lhsTypeCopy, rhsTypeCopy); |
| 151 |
2/4✓ Branch 89 → 90 taken 55 times.
✗ Branch 89 → 133 not taken.
✓ Branch 90 → 91 taken 55 times.
✗ Branch 90 → 92 not taken.
|
55 | if (lhsTypeCopy.matchesInterfaceImplementedByStruct(rhsTypeCopy)) |
| 152 | 55 | 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 45847 times.
✗ Branch 93 → 136 not taken.
✓ Branch 94 → 95 taken 417 times.
✓ Branch 94 → 100 taken 45430 times.
✓ Branch 95 → 96 taken 417 times.
✗ Branch 95 → 136 not taken.
✓ Branch 96 → 97 taken 415 times.
✓ Branch 96 → 100 taken 2 times.
✓ Branch 97 → 98 taken 415 times.
✗ Branch 97 → 136 not taken.
✓ Branch 98 → 99 taken 415 times.
✗ Branch 98 → 100 not taken.
✓ Branch 101 → 102 taken 415 times.
✓ Branch 101 → 108 taken 45432 times.
|
45847 | if (lhsType.isPtr() && rhsType.isHeap() && lhsType.matches(rhsType, false, true, true)) { |
| 156 | 415 | TypeQualifiers rhsQualifiers = rhsType.getQualifiers(); | |
| 157 | 415 | rhsQualifiers.isHeap = false; | |
| 158 |
2/4✓ Branch 104 → 105 taken 415 times.
✗ Branch 104 → 134 not taken.
✓ Branch 105 → 106 taken 415 times.
✗ Branch 105 → 107 not taken.
|
415 | if (lhsType.getQualifiers() == rhsQualifiers) |
| 159 | 415 | return lhsType; | |
| 160 | } | ||
| 161 | |||
| 162 | // Nothing matched | ||
| 163 |
1/2✓ Branch 108 → 109 taken 45432 times.
✗ Branch 108 → 135 not taken.
|
45432 | return QualType(TY_INVALID); |
| 164 | } | ||
| 165 | |||
| 166 | 12720 | std::pair<QualType, Function *> OpRuleManager::performStructAssign(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, | |
| 167 | const QualType &rhsType, bool isDecl, bool isReturn) const { | ||
| 168 | 12720 | const bool rhsIsRef = rhs.type.isRef(); | |
| 169 | |||
| 170 | // Check is there is an overloaded operator function available | ||
| 171 |
8/8✓ Branch 3 → 4 taken 7444 times.
✓ Branch 3 → 8 taken 5276 times.
✓ Branch 4 → 5 taken 1044 times.
✓ Branch 4 → 8 taken 6400 times.
✓ Branch 6 → 7 taken 549 times.
✓ Branch 6 → 8 taken 495 times.
✓ Branch 9 → 10 taken 549 times.
✓ Branch 9 → 16 taken 12171 times.
|
12720 | if (!isDecl && !isReturn && lhs.entry->isInitialized()) { |
| 172 |
1/2✓ Branch 10 → 11 taken 549 times.
✗ Branch 10 → 44 not taken.
|
549 | const auto [type, _] = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_ASSIGN, {lhs, rhs}, 0); |
| 173 |
3/4✓ Branch 11 → 12 taken 549 times.
✗ Branch 11 → 45 not taken.
✓ Branch 12 → 13 taken 409 times.
✓ Branch 12 → 15 taken 140 times.
|
549 | if (!type.is(TY_INVALID)) |
| 174 | 409 | return {type, nullptr}; | |
| 175 | } | ||
| 176 | |||
| 177 | // If temp stealing is possible, delete any rhs anonymous entry | ||
| 178 |
6/6✓ Branch 16 → 17 taken 11635 times.
✓ Branch 16 → 20 taken 676 times.
✓ Branch 18 → 19 taken 10888 times.
✓ Branch 18 → 20 taken 747 times.
✓ Branch 21 → 22 taken 10888 times.
✓ Branch 21 → 27 taken 1423 times.
|
12311 | if (!rhsIsRef && rhs.isTemporary()) { |
| 179 |
3/4✓ Branch 22 → 23 taken 7614 times.
✓ Branch 22 → 25 taken 3274 times.
✓ Branch 23 → 24 taken 7614 times.
✗ Branch 23 → 25 not taken.
|
10888 | if (rhs.entry != nullptr && rhs.entry->anonymous) |
| 180 | 7614 | typeChecker->currentScope->symbolTable.deleteAnonymous(rhs.entry->name); | |
| 181 | 10888 | return {rhsType, nullptr}; | |
| 182 | } | ||
| 183 | |||
| 184 | // If RVO is possible, cancel here | ||
| 185 |
7/8✓ Branch 27 → 28 taken 747 times.
✓ Branch 27 → 32 taken 676 times.
✓ Branch 28 → 29 taken 423 times.
✓ Branch 28 → 32 taken 324 times.
✓ Branch 30 → 31 taken 423 times.
✗ Branch 30 → 32 not taken.
✓ Branch 33 → 34 taken 423 times.
✓ Branch 33 → 36 taken 1000 times.
|
1423 | if (!rhsIsRef && isReturn && !rhs.isTemporary()) |
| 186 | 423 | return {rhsType, nullptr}; | |
| 187 | |||
| 188 | // => We have to copy | ||
| 189 | // If struct, try to call copy ctor | ||
| 190 |
2/2✓ Branch 37 → 38 taken 957 times.
✓ Branch 37 → 41 taken 43 times.
|
1000 | if (rhsType.is(TY_STRUCT)) |
| 191 |
1/2✓ Branch 38 → 39 taken 957 times.
✗ Branch 38 → 46 not taken.
|
957 | return {rhsType, typeChecker->implicitlyCallStructCopyCtor(rhsType, node)}; |
| 192 | |||
| 193 | // Perform shallow copy | ||
| 194 | 43 | return {rhsType, nullptr}; | |
| 195 | } | ||
| 196 | |||
| 197 | 1163 | 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 1163 times.
✗ Branch 2 → 22 not taken.
|
1163 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_PLUS_EQUAL, {lhs, rhs}, 0); |
| 200 |
3/4✓ Branch 3 → 4 taken 1163 times.
✗ Branch 3 → 24 not taken.
✓ Branch 4 → 5 taken 416 times.
✓ Branch 4 → 6 taken 747 times.
|
1163 | if (!resultType.type.is(TY_INVALID)) |
| 201 | 416 | return resultType; | |
| 202 | |||
| 203 | // Check if we try to assign a constant value | ||
| 204 |
1/2✓ Branch 6 → 7 taken 747 times.
✗ Branch 6 → 24 not taken.
|
747 | ensureNoConstAssign(node, lhs.type); |
| 205 | |||
| 206 | // Remove reference wrappers | ||
| 207 |
1/2✓ Branch 7 → 8 taken 747 times.
✗ Branch 7 → 24 not taken.
|
747 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 208 |
1/2✓ Branch 8 → 9 taken 747 times.
✗ Branch 8 → 24 not taken.
|
747 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 209 | |||
| 210 | // Check if this is an unsafe operation | ||
| 211 |
7/10✓ Branch 9 → 10 taken 747 times.
✗ Branch 9 → 23 not taken.
✓ Branch 10 → 11 taken 166 times.
✓ Branch 10 → 14 taken 581 times.
✓ Branch 11 → 12 taken 166 times.
✗ Branch 11 → 23 not taken.
✓ Branch 12 → 13 taken 166 times.
✗ Branch 12 → 14 not taken.
✓ Branch 15 → 16 taken 166 times.
✓ Branch 15 → 18 taken 581 times.
|
747 | if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) { |
| 212 |
1/2✓ Branch 16 → 17 taken 166 times.
✗ Branch 16 → 24 not taken.
|
166 | ensureUnsafeAllowed(node, "+=", lhsType, rhsType); |
| 213 | 166 | return lhs; | |
| 214 | } | ||
| 215 | |||
| 216 |
1/2✓ Branch 18 → 19 taken 581 times.
✗ Branch 18 → 24 not taken.
|
581 | return {validateBinaryOperation(node, PLUS_EQUAL_OP_RULES, std::size(PLUS_EQUAL_OP_RULES), "+=", lhsType, rhsType)}; |
| 217 | } | ||
| 218 | |||
| 219 | 80 | 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 80 times.
✗ Branch 2 → 22 not taken.
|
80 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MINUS_EQUAL, {lhs, rhs}, 0); |
| 222 |
3/4✓ Branch 3 → 4 taken 80 times.
✗ Branch 3 → 24 not taken.
✓ Branch 4 → 5 taken 7 times.
✓ Branch 4 → 6 taken 73 times.
|
80 | 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 73 times.
✗ Branch 6 → 24 not taken.
|
73 | ensureNoConstAssign(node, lhs.type); |
| 227 | |||
| 228 | // Remove reference wrappers | ||
| 229 |
1/2✓ Branch 7 → 8 taken 73 times.
✗ Branch 7 → 24 not taken.
|
73 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 230 |
1/2✓ Branch 8 → 9 taken 73 times.
✗ Branch 8 → 24 not taken.
|
73 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 231 | |||
| 232 | // Check if this is an unsafe operation | ||
| 233 |
7/10✓ Branch 9 → 10 taken 73 times.
✗ Branch 9 → 23 not taken.
✓ Branch 10 → 11 taken 5 times.
✓ Branch 10 → 14 taken 68 times.
✓ Branch 11 → 12 taken 5 times.
✗ Branch 11 → 23 not taken.
✓ Branch 12 → 13 taken 5 times.
✗ Branch 12 → 14 not taken.
✓ Branch 15 → 16 taken 5 times.
✓ Branch 15 → 18 taken 68 times.
|
73 | if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) { |
| 234 |
1/2✓ Branch 16 → 17 taken 5 times.
✗ Branch 16 → 24 not taken.
|
5 | ensureUnsafeAllowed(node, "-=", lhsType, rhsType); |
| 235 | 5 | return lhs; | |
| 236 | } | ||
| 237 | |||
| 238 |
1/2✓ Branch 18 → 19 taken 68 times.
✗ Branch 18 → 24 not taken.
|
68 | return {validateBinaryOperation(node, MINUS_EQUAL_OP_RULES, std::size(MINUS_EQUAL_OP_RULES), "-=", lhsType, rhsType)}; |
| 239 | } | ||
| 240 | |||
| 241 | 170 | 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 170 times.
✗ Branch 2 → 13 not taken.
|
170 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MUL_EQUAL, {lhs, rhs}, 0); |
| 244 |
3/4✓ Branch 3 → 4 taken 170 times.
✗ Branch 3 → 14 not taken.
✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 6 taken 168 times.
|
170 | 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 168 times.
✗ Branch 6 → 14 not taken.
|
168 | ensureNoConstAssign(node, lhs.type); |
| 249 | |||
| 250 | // Remove reference wrappers | ||
| 251 |
1/2✓ Branch 7 → 8 taken 168 times.
✗ Branch 7 → 14 not taken.
|
168 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 252 |
1/2✓ Branch 8 → 9 taken 168 times.
✗ Branch 8 → 14 not taken.
|
168 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 253 | |||
| 254 |
1/2✓ Branch 9 → 10 taken 168 times.
✗ Branch 9 → 14 not taken.
|
168 | return {validateBinaryOperation(node, MUL_EQUAL_OP_RULES, std::size(MUL_EQUAL_OP_RULES), "*=", lhsType, rhsType)}; |
| 255 | } | ||
| 256 | |||
| 257 | 104 | 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 104 times.
✗ Branch 2 → 13 not taken.
|
104 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_DIV_EQUAL, {lhs, rhs}, 0); |
| 260 |
3/4✓ Branch 3 → 4 taken 104 times.
✗ Branch 3 → 14 not taken.
✓ Branch 4 → 5 taken 62 times.
✓ Branch 4 → 6 taken 42 times.
|
104 | if (!resultType.type.is(TY_INVALID)) |
| 261 | 62 | return resultType; | |
| 262 | |||
| 263 | // Check if we try to assign a constant value | ||
| 264 |
1/2✓ Branch 6 → 7 taken 42 times.
✗ Branch 6 → 14 not taken.
|
42 | ensureNoConstAssign(node, lhs.type); |
| 265 | |||
| 266 | // Remove reference wrappers | ||
| 267 |
1/2✓ Branch 7 → 8 taken 42 times.
✗ Branch 7 → 14 not taken.
|
42 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 268 |
1/2✓ Branch 8 → 9 taken 42 times.
✗ Branch 8 → 14 not taken.
|
42 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 269 | |||
| 270 |
1/2✓ Branch 9 → 10 taken 42 times.
✗ Branch 9 → 14 not taken.
|
42 | return {validateBinaryOperation(node, DIV_EQUAL_OP_RULES, std::size(DIV_EQUAL_OP_RULES), "/=", lhsType, rhsType)}; |
| 271 | } | ||
| 272 | |||
| 273 | 41 | 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 41 times.
✗ Branch 2 → 9 not taken.
|
41 | ensureNoConstAssign(node, lhs.type); |
| 276 | |||
| 277 | // Remove reference wrappers | ||
| 278 |
1/2✓ Branch 3 → 4 taken 41 times.
✗ Branch 3 → 9 not taken.
|
41 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 279 |
1/2✓ Branch 4 → 5 taken 41 times.
✗ Branch 4 → 9 not taken.
|
41 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 280 | |||
| 281 |
1/2✓ Branch 5 → 6 taken 41 times.
✗ Branch 5 → 9 not taken.
|
82 | 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 → 9 not taken.
|
12 | ensureNoConstAssign(node, lhs.type); |
| 287 | |||
| 288 | // Remove reference wrappers | ||
| 289 |
1/2✓ Branch 3 → 4 taken 12 times.
✗ Branch 3 → 9 not taken.
|
12 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 290 |
1/2✓ Branch 4 → 5 taken 12 times.
✗ Branch 4 → 9 not taken.
|
12 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 291 | |||
| 292 |
1/2✓ Branch 5 → 6 taken 12 times.
✗ Branch 5 → 9 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 → 9 not taken.
|
13 | ensureNoConstAssign(node, lhs.type); |
| 298 | |||
| 299 | // Remove reference wrappers | ||
| 300 |
1/2✓ Branch 3 → 4 taken 13 times.
✗ Branch 3 → 9 not taken.
|
13 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 301 |
1/2✓ Branch 4 → 5 taken 13 times.
✗ Branch 4 → 9 not taken.
|
13 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 302 | |||
| 303 |
1/2✓ Branch 5 → 6 taken 13 times.
✗ Branch 5 → 9 not taken.
|
26 | return validateBinaryOperation(node, SHR_EQUAL_OP_RULES, std::size(SHR_EQUAL_OP_RULES), ">>=", lhsType, rhsType); |
| 304 | } | ||
| 305 | |||
| 306 | 17 | 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 17 times.
✗ Branch 2 → 9 not taken.
|
17 | ensureNoConstAssign(node, lhs.type); |
| 309 | |||
| 310 | // Remove reference wrappers | ||
| 311 |
1/2✓ Branch 3 → 4 taken 17 times.
✗ Branch 3 → 9 not taken.
|
17 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 312 |
1/2✓ Branch 4 → 5 taken 17 times.
✗ Branch 4 → 9 not taken.
|
17 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 313 | |||
| 314 |
1/2✓ Branch 5 → 6 taken 17 times.
✗ Branch 5 → 9 not taken.
|
34 | return validateBinaryOperation(node, AND_EQUAL_OP_RULES, std::size(AND_EQUAL_OP_RULES), "&=", lhsType, rhsType); |
| 315 | } | ||
| 316 | |||
| 317 | 13 | 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 13 times.
✗ Branch 2 → 9 not taken.
|
13 | ensureNoConstAssign(node, lhs.type); |
| 320 | |||
| 321 | // Remove reference wrappers | ||
| 322 |
1/2✓ Branch 3 → 4 taken 13 times.
✗ Branch 3 → 9 not taken.
|
13 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 323 |
1/2✓ Branch 4 → 5 taken 13 times.
✗ Branch 4 → 9 not taken.
|
13 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 324 | |||
| 325 |
1/2✓ Branch 5 → 6 taken 13 times.
✗ Branch 5 → 9 not taken.
|
26 | return validateBinaryOperation(node, OR_EQUAL_OP_RULES, std::size(OR_EQUAL_OP_RULES), "|=", lhsType, rhsType); |
| 326 | } | ||
| 327 | |||
| 328 | 678 | 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 678 times.
✗ Branch 2 → 9 not taken.
|
678 | ensureNoConstAssign(node, lhs.type); |
| 331 | |||
| 332 | // Remove reference wrappers | ||
| 333 |
1/2✓ Branch 3 → 4 taken 678 times.
✗ Branch 3 → 9 not taken.
|
678 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 334 |
1/2✓ Branch 4 → 5 taken 678 times.
✗ Branch 4 → 9 not taken.
|
678 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 335 | |||
| 336 |
1/2✓ Branch 5 → 6 taken 678 times.
✗ Branch 5 → 9 not taken.
|
1356 | return validateBinaryOperation(node, XOR_EQUAL_OP_RULES, std::size(XOR_EQUAL_OP_RULES), "^=", lhsType, rhsType); |
| 337 | } | ||
| 338 | |||
| 339 | 2414 | QualType OpRuleManager::getLogicalOrResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
| 340 | // Remove reference wrappers | ||
| 341 |
1/2✓ Branch 2 → 3 taken 2414 times.
✗ Branch 2 → 8 not taken.
|
2414 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 342 |
1/2✓ Branch 3 → 4 taken 2414 times.
✗ Branch 3 → 8 not taken.
|
2414 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 343 | |||
| 344 |
2/2✓ Branch 4 → 5 taken 2413 times.
✓ Branch 4 → 8 taken 1 time.
|
4827 | return validateBinaryOperation(node, LOGICAL_OR_OP_RULES, std::size(LOGICAL_OR_OP_RULES), "||", lhsType, rhsType); |
| 345 | } | ||
| 346 | |||
| 347 | 1512 | QualType OpRuleManager::getLogicalAndResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
| 348 | // Remove reference wrappers | ||
| 349 |
1/2✓ Branch 2 → 3 taken 1512 times.
✗ Branch 2 → 8 not taken.
|
1512 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 350 |
1/2✓ Branch 3 → 4 taken 1512 times.
✗ Branch 3 → 8 not taken.
|
1512 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 351 | |||
| 352 |
1/2✓ Branch 4 → 5 taken 1512 times.
✗ Branch 4 → 8 not taken.
|
3024 | return validateBinaryOperation(node, LOGICAL_AND_OP_RULES, std::size(LOGICAL_AND_OP_RULES), "&&", lhsType, rhsType); |
| 353 | } | ||
| 354 | |||
| 355 | 278 | ExprResult OpRuleManager::getBitwiseOrResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const { | |
| 356 | // Check if there is an overloaded operator function available | ||
| 357 |
1/2✓ Branch 2 → 3 taken 278 times.
✗ Branch 2 → 12 not taken.
|
278 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_BITWISE_OR, {lhs, rhs}, opIdx); |
| 358 |
3/4✓ Branch 3 → 4 taken 278 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 4 times.
✓ Branch 4 → 6 taken 274 times.
|
278 | if (!resultType.type.is(TY_INVALID)) |
| 359 | 4 | return resultType; | |
| 360 | |||
| 361 | // Remove reference wrappers | ||
| 362 |
1/2✓ Branch 6 → 7 taken 274 times.
✗ Branch 6 → 13 not taken.
|
274 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 363 |
1/2✓ Branch 7 → 8 taken 274 times.
✗ Branch 7 → 13 not taken.
|
274 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 364 | |||
| 365 |
2/2✓ Branch 8 → 9 taken 273 times.
✓ Branch 8 → 13 taken 1 time.
|
274 | return {validateBinaryOperation(node, BITWISE_OR_OP_RULES, std::size(BITWISE_OR_OP_RULES), "|", lhsType, rhsType)}; |
| 366 | } | ||
| 367 | |||
| 368 | 41 | ExprResult OpRuleManager::getBitwiseXorResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, | |
| 369 | size_t opIdx) const { | ||
| 370 | // Check if there is an overloaded operator function available | ||
| 371 |
1/2✓ Branch 2 → 3 taken 41 times.
✗ Branch 2 → 12 not taken.
|
41 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_BITWISE_XOR, {lhs, rhs}, opIdx); |
| 372 |
3/4✓ Branch 3 → 4 taken 41 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 3 times.
✓ Branch 4 → 6 taken 38 times.
|
41 | if (!resultType.type.is(TY_INVALID)) |
| 373 | 3 | return resultType; | |
| 374 | |||
| 375 | // Remove reference wrappers | ||
| 376 |
1/2✓ Branch 6 → 7 taken 38 times.
✗ Branch 6 → 13 not taken.
|
38 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 377 |
1/2✓ Branch 7 → 8 taken 38 times.
✗ Branch 7 → 13 not taken.
|
38 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 378 | |||
| 379 |
1/2✓ Branch 8 → 9 taken 38 times.
✗ Branch 8 → 13 not taken.
|
38 | return {validateBinaryOperation(node, BITWISE_XOR_OP_RULES, std::size(BITWISE_XOR_OP_RULES), "^", lhsType, rhsType)}; |
| 380 | } | ||
| 381 | |||
| 382 | 73 | ExprResult OpRuleManager::getBitwiseAndResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, | |
| 383 | size_t opIdx) const { | ||
| 384 | // Check if there is an overloaded operator function available | ||
| 385 |
1/2✓ Branch 2 → 3 taken 73 times.
✗ Branch 2 → 12 not taken.
|
73 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_BITWISE_AND, {lhs, rhs}, opIdx); |
| 386 |
3/4✓ Branch 3 → 4 taken 73 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 4 times.
✓ Branch 4 → 6 taken 69 times.
|
73 | if (!resultType.type.is(TY_INVALID)) |
| 387 | 4 | return resultType; | |
| 388 | |||
| 389 | // Remove reference wrappers | ||
| 390 |
1/2✓ Branch 6 → 7 taken 69 times.
✗ Branch 6 → 13 not taken.
|
69 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 391 |
1/2✓ Branch 7 → 8 taken 69 times.
✗ Branch 7 → 13 not taken.
|
69 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 392 | |||
| 393 |
1/2✓ Branch 8 → 9 taken 69 times.
✗ Branch 8 → 13 not taken.
|
69 | return {validateBinaryOperation(node, BITWISE_AND_OP_RULES, std::size(BITWISE_AND_OP_RULES), "&", lhsType, rhsType)}; |
| 394 | } | ||
| 395 | |||
| 396 | 10495 | ExprResult OpRuleManager::getEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const { | |
| 397 | // Check is there is an overloaded operator function available | ||
| 398 |
1/2✓ Branch 2 → 3 taken 10495 times.
✗ Branch 2 → 36 not taken.
|
10495 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_EQUAL, {lhs, rhs}, 0); |
| 399 |
3/4✓ Branch 3 → 4 taken 10495 times.
✗ Branch 3 → 37 not taken.
✓ Branch 4 → 5 taken 1283 times.
✓ Branch 4 → 6 taken 9212 times.
|
10495 | if (!resultType.type.is(TY_INVALID)) |
| 400 | 1283 | return resultType; | |
| 401 | |||
| 402 | // Remove reference wrappers | ||
| 403 |
1/2✓ Branch 6 → 7 taken 9212 times.
✗ Branch 6 → 37 not taken.
|
9212 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 404 |
1/2✓ Branch 7 → 8 taken 9212 times.
✗ Branch 7 → 37 not taken.
|
9212 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 405 | |||
| 406 | // Allow 'pointer == unsigned long' straight away | ||
| 407 |
10/14✓ Branch 8 → 9 taken 9212 times.
✗ Branch 8 → 37 not taken.
✓ Branch 9 → 10 taken 2063 times.
✓ Branch 9 → 15 taken 7149 times.
✓ Branch 10 → 11 taken 2063 times.
✗ Branch 10 → 37 not taken.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 15 taken 2062 times.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 37 not taken.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 15 not taken.
✓ Branch 16 → 17 taken 1 time.
✓ Branch 16 → 19 taken 9211 times.
|
9212 | if (lhsType.isPtr() && rhsType.is(TY_LONG) && rhsType.isUnsigned()) |
| 408 |
1/2✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 37 not taken.
|
1 | return ExprResult(QualType(TY_BOOL)); |
| 409 | |||
| 410 | // Allow 'string == char*' and vice versa straight away | ||
| 411 |
11/18✓ Branch 19 → 20 taken 9211 times.
✗ Branch 19 → 37 not taken.
✓ Branch 20 → 21 taken 347 times.
✓ Branch 20 → 23 taken 8864 times.
✓ Branch 21 → 22 taken 347 times.
✗ Branch 21 → 37 not taken.
✓ Branch 22 → 23 taken 347 times.
✗ Branch 22 → 27 not taken.
✓ Branch 23 → 24 taken 9211 times.
✗ Branch 23 → 37 not taken.
✓ Branch 24 → 25 taken 906 times.
✓ Branch 24 → 28 taken 8305 times.
✓ Branch 25 → 26 taken 906 times.
✗ Branch 25 → 37 not taken.
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 28 taken 906 times.
✗ Branch 29 → 30 not taken.
✓ Branch 29 → 32 taken 9211 times.
|
9211 | if ((lhsType.is(TY_STRING) && rhsType.isPtrTo(TY_CHAR)) || (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING))) |
| 412 | ✗ | return ExprResult(QualType(TY_BOOL)); | |
| 413 | |||
| 414 | // Check primitive type combinations | ||
| 415 |
2/2✓ Branch 32 → 33 taken 9210 times.
✓ Branch 32 → 37 taken 1 time.
|
9211 | return ExprResult(validateBinaryOperation(node, EQUAL_OP_RULES, std::size(EQUAL_OP_RULES), "==", lhsType, rhsType)); |
| 416 | } | ||
| 417 | |||
| 418 | 3472 | ExprResult OpRuleManager::getNotEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const { | |
| 419 | // Check is there is an overloaded operator function available | ||
| 420 |
1/2✓ Branch 2 → 3 taken 3472 times.
✗ Branch 2 → 36 not taken.
|
3472 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_NOT_EQUAL, {lhs, rhs}, 0); |
| 421 |
3/4✓ Branch 3 → 4 taken 3472 times.
✗ Branch 3 → 37 not taken.
✓ Branch 4 → 5 taken 71 times.
✓ Branch 4 → 6 taken 3401 times.
|
3472 | if (!resultType.type.is(TY_INVALID)) |
| 422 | 71 | return resultType; | |
| 423 | |||
| 424 | // Remove reference wrappers | ||
| 425 |
1/2✓ Branch 6 → 7 taken 3401 times.
✗ Branch 6 → 37 not taken.
|
3401 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 426 |
1/2✓ Branch 7 → 8 taken 3401 times.
✗ Branch 7 → 37 not taken.
|
3401 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 427 | |||
| 428 | // Allow 'pointer != unsigned long' straight away | ||
| 429 |
10/14✓ Branch 8 → 9 taken 3401 times.
✗ Branch 8 → 37 not taken.
✓ Branch 9 → 10 taken 671 times.
✓ Branch 9 → 15 taken 2730 times.
✓ Branch 10 → 11 taken 671 times.
✗ Branch 10 → 37 not taken.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 15 taken 670 times.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 37 not taken.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 15 not taken.
✓ Branch 16 → 17 taken 1 time.
✓ Branch 16 → 19 taken 3400 times.
|
3401 | if (lhsType.isPtr() && rhsType.is(TY_LONG) && rhsType.isUnsigned()) |
| 430 |
1/2✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 37 not taken.
|
1 | return ExprResult(QualType(TY_BOOL)); |
| 431 | |||
| 432 | // Allow 'string != char*' and vice versa straight away | ||
| 433 |
12/18✓ Branch 19 → 20 taken 3400 times.
✗ Branch 19 → 37 not taken.
✓ Branch 20 → 21 taken 16 times.
✓ Branch 20 → 23 taken 3384 times.
✓ Branch 21 → 22 taken 16 times.
✗ Branch 21 → 37 not taken.
✓ Branch 22 → 23 taken 16 times.
✗ Branch 22 → 27 not taken.
✓ Branch 23 → 24 taken 3400 times.
✗ Branch 23 → 37 not taken.
✓ Branch 24 → 25 taken 23 times.
✓ Branch 24 → 28 taken 3377 times.
✓ Branch 25 → 26 taken 23 times.
✗ Branch 25 → 37 not taken.
✓ Branch 26 → 27 taken 23 times.
✗ Branch 26 → 28 not taken.
✓ Branch 29 → 30 taken 23 times.
✓ Branch 29 → 32 taken 3377 times.
|
3400 | if ((lhsType.is(TY_STRING) && rhsType.isPtrTo(TY_CHAR)) || (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING))) |
| 434 |
1/2✓ Branch 30 → 31 taken 23 times.
✗ Branch 30 → 37 not taken.
|
23 | return ExprResult(QualType(TY_BOOL)); |
| 435 | |||
| 436 | // Check primitive type combinations | ||
| 437 |
1/2✓ Branch 32 → 33 taken 3377 times.
✗ Branch 32 → 37 not taken.
|
3377 | return ExprResult(validateBinaryOperation(node, NOT_EQUAL_OP_RULES, std::size(NOT_EQUAL_OP_RULES), "!=", lhsType, rhsType)); |
| 438 | } | ||
| 439 | |||
| 440 | 4202 | QualType OpRuleManager::getLessResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
| 441 | // Remove reference wrappers | ||
| 442 |
1/2✓ Branch 2 → 3 taken 4202 times.
✗ Branch 2 → 8 not taken.
|
4202 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 443 |
1/2✓ Branch 3 → 4 taken 4202 times.
✗ Branch 3 → 8 not taken.
|
4202 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 444 | |||
| 445 |
1/2✓ Branch 4 → 5 taken 4202 times.
✗ Branch 4 → 8 not taken.
|
8404 | return validateBinaryOperation(node, LESS_OP_RULES, std::size(LESS_OP_RULES), "<", lhsType, rhsType); |
| 446 | } | ||
| 447 | |||
| 448 | 1686 | QualType OpRuleManager::getGreaterResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
| 449 | // Remove reference wrappers | ||
| 450 |
1/2✓ Branch 2 → 3 taken 1686 times.
✗ Branch 2 → 8 not taken.
|
1686 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 451 |
1/2✓ Branch 3 → 4 taken 1686 times.
✗ Branch 3 → 8 not taken.
|
1686 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 452 | |||
| 453 |
2/2✓ Branch 4 → 5 taken 1685 times.
✓ Branch 4 → 8 taken 1 time.
|
3371 | return validateBinaryOperation(node, GREATER_OP_RULES, std::size(GREATER_OP_RULES), ">", lhsType, rhsType); |
| 454 | } | ||
| 455 | |||
| 456 | 1202 | QualType OpRuleManager::getLessEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
| 457 | // Remove reference wrappers | ||
| 458 |
1/2✓ Branch 2 → 3 taken 1202 times.
✗ Branch 2 → 8 not taken.
|
1202 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 459 |
1/2✓ Branch 3 → 4 taken 1202 times.
✗ Branch 3 → 8 not taken.
|
1202 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 460 | |||
| 461 |
1/2✓ Branch 4 → 5 taken 1202 times.
✗ Branch 4 → 8 not taken.
|
2404 | return validateBinaryOperation(node, LESS_EQUAL_OP_RULES, std::size(LESS_EQUAL_OP_RULES), "<=", lhsType, rhsType); |
| 462 | } | ||
| 463 | |||
| 464 | 1993 | QualType OpRuleManager::getGreaterEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
| 465 | // Remove reference wrappers | ||
| 466 |
1/2✓ Branch 2 → 3 taken 1993 times.
✗ Branch 2 → 18 not taken.
|
1993 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 467 |
1/2✓ Branch 3 → 4 taken 1993 times.
✗ Branch 3 → 18 not taken.
|
1993 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 468 | |||
| 469 | // Allow 'pointer == pointer' straight away | ||
| 470 |
7/10✓ Branch 4 → 5 taken 1993 times.
✗ Branch 4 → 18 not taken.
✓ Branch 5 → 6 taken 4 times.
✓ Branch 5 → 9 taken 1989 times.
✓ Branch 6 → 7 taken 4 times.
✗ Branch 6 → 18 not taken.
✓ Branch 7 → 8 taken 4 times.
✗ Branch 7 → 9 not taken.
✓ Branch 10 → 11 taken 4 times.
✓ Branch 10 → 13 taken 1989 times.
|
1993 | if (lhsType.isPtr() && rhsType.isPtr()) |
| 471 |
1/2✓ Branch 11 → 12 taken 4 times.
✗ Branch 11 → 17 not taken.
|
4 | return QualType(TY_BOOL); |
| 472 | |||
| 473 |
1/2✓ Branch 13 → 14 taken 1989 times.
✗ Branch 13 → 18 not taken.
|
1989 | return validateBinaryOperation(node, GREATER_EQUAL_OP_RULES, std::size(GREATER_EQUAL_OP_RULES), ">=", lhsType, rhsType); |
| 474 | } | ||
| 475 | |||
| 476 | 2252 | ExprResult OpRuleManager::getShiftLeftResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, | |
| 477 | size_t opIdx) const { | ||
| 478 | // Check is there is an overloaded operator function available | ||
| 479 |
1/2✓ Branch 2 → 3 taken 2252 times.
✗ Branch 2 → 12 not taken.
|
2252 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_SHL, {lhs, rhs}, opIdx); |
| 480 |
3/4✓ Branch 3 → 4 taken 2252 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 2202 times.
✓ Branch 4 → 6 taken 50 times.
|
2252 | if (!resultType.type.is(TY_INVALID)) |
| 481 | 2202 | return resultType; | |
| 482 | |||
| 483 | // Remove reference wrappers | ||
| 484 |
1/2✓ Branch 6 → 7 taken 50 times.
✗ Branch 6 → 13 not taken.
|
50 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 485 |
1/2✓ Branch 7 → 8 taken 50 times.
✗ Branch 7 → 13 not taken.
|
50 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 486 | |||
| 487 |
1/2✓ Branch 8 → 9 taken 50 times.
✗ Branch 8 → 13 not taken.
|
50 | return {validateBinaryOperation(node, SHIFT_LEFT_OP_RULES, std::size(SHIFT_LEFT_OP_RULES), "<<", lhsType, rhsType)}; |
| 488 | } | ||
| 489 | |||
| 490 | 189 | ExprResult OpRuleManager::getShiftRightResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, | |
| 491 | size_t opIdx) const { | ||
| 492 | // Check is there is an overloaded operator function available | ||
| 493 |
1/2✓ Branch 2 → 3 taken 189 times.
✗ Branch 2 → 12 not taken.
|
189 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_SHR, {lhs, rhs}, opIdx); |
| 494 |
3/4✓ Branch 3 → 4 taken 189 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 188 times.
|
189 | if (!resultType.type.is(TY_INVALID)) |
| 495 | 1 | return resultType; | |
| 496 | |||
| 497 | // Remove reference wrappers | ||
| 498 |
1/2✓ Branch 6 → 7 taken 188 times.
✗ Branch 6 → 13 not taken.
|
188 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 499 |
1/2✓ Branch 7 → 8 taken 188 times.
✗ Branch 7 → 13 not taken.
|
188 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 500 | |||
| 501 |
1/2✓ Branch 8 → 9 taken 188 times.
✗ Branch 8 → 13 not taken.
|
188 | return {validateBinaryOperation(node, SHIFT_RIGHT_OP_RULES, std::size(SHIFT_RIGHT_OP_RULES), ">>", lhsType, rhsType)}; |
| 502 | } | ||
| 503 | |||
| 504 | 6682 | ExprResult OpRuleManager::getPlusResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const { | |
| 505 | // Check is there is an overloaded operator function available | ||
| 506 |
1/2✓ Branch 2 → 3 taken 6682 times.
✗ Branch 2 → 30 not taken.
|
6682 | const ExprResult result = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_PLUS, {lhs, rhs}, opIdx); |
| 507 |
3/4✓ Branch 3 → 4 taken 6682 times.
✗ Branch 3 → 33 not taken.
✓ Branch 4 → 5 taken 593 times.
✓ Branch 4 → 6 taken 6089 times.
|
6682 | if (!result.type.is(TY_INVALID)) |
| 508 | 593 | return result; | |
| 509 | |||
| 510 | // Remove reference wrappers | ||
| 511 |
1/2✓ Branch 6 → 7 taken 6089 times.
✗ Branch 6 → 33 not taken.
|
6089 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 512 |
1/2✓ Branch 7 → 8 taken 6089 times.
✗ Branch 7 → 33 not taken.
|
6089 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 513 | |||
| 514 | // Allow any* + <int/long/short> | ||
| 515 |
7/10✓ Branch 8 → 9 taken 6089 times.
✗ Branch 8 → 31 not taken.
✓ Branch 9 → 10 taken 909 times.
✓ Branch 9 → 13 taken 5180 times.
✓ Branch 10 → 11 taken 909 times.
✗ Branch 10 → 31 not taken.
✓ Branch 11 → 12 taken 909 times.
✗ Branch 11 → 13 not taken.
✓ Branch 14 → 15 taken 909 times.
✓ Branch 14 → 17 taken 5180 times.
|
6089 | if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) { |
| 516 |
1/2✓ Branch 15 → 16 taken 909 times.
✗ Branch 15 → 33 not taken.
|
909 | ensureUnsafeAllowed(node, "+", lhsType, rhsType); |
| 517 | 909 | return {lhsType}; | |
| 518 | } | ||
| 519 | // Allow <int/long/short> + any* | ||
| 520 |
6/10✓ Branch 17 → 18 taken 5180 times.
✗ Branch 17 → 32 not taken.
✓ Branch 18 → 19 taken 4780 times.
✓ Branch 18 → 22 taken 400 times.
✓ Branch 19 → 20 taken 4780 times.
✗ Branch 19 → 32 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 4780 times.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 26 taken 5180 times.
|
5180 | if (lhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT}) && rhsType.isPtr()) { |
| 521 | ✗ | ensureUnsafeAllowed(node, "+", lhsType, rhsType); | |
| 522 | ✗ | return {rhsType}; | |
| 523 | } | ||
| 524 | |||
| 525 |
2/2✓ Branch 26 → 27 taken 5179 times.
✓ Branch 26 → 33 taken 1 time.
|
5180 | return {validateBinaryOperation(node, PLUS_OP_RULES, std::size(PLUS_OP_RULES), "+", lhsType, rhsType)}; |
| 526 | } | ||
| 527 | |||
| 528 | 3771 | ExprResult OpRuleManager::getMinusResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const { | |
| 529 | // Check is there is an overloaded operator function available | ||
| 530 |
1/2✓ Branch 2 → 3 taken 3771 times.
✗ Branch 2 → 21 not taken.
|
3771 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MINUS, {lhs, rhs}, opIdx); |
| 531 |
3/4✓ Branch 3 → 4 taken 3771 times.
✗ Branch 3 → 23 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 3770 times.
|
3771 | if (!resultType.type.is(TY_INVALID)) |
| 532 | 1 | return resultType; | |
| 533 | |||
| 534 | // Remove reference wrappers | ||
| 535 |
1/2✓ Branch 6 → 7 taken 3770 times.
✗ Branch 6 → 23 not taken.
|
3770 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 536 |
1/2✓ Branch 7 → 8 taken 3770 times.
✗ Branch 7 → 23 not taken.
|
3770 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 537 | |||
| 538 | // Allow any* - <int/long/short> | ||
| 539 |
7/10✓ Branch 8 → 9 taken 3770 times.
✗ Branch 8 → 22 not taken.
✓ Branch 9 → 10 taken 3 times.
✓ Branch 9 → 13 taken 3767 times.
✓ Branch 10 → 11 taken 3 times.
✗ Branch 10 → 22 not taken.
✓ Branch 11 → 12 taken 3 times.
✗ Branch 11 → 13 not taken.
✓ Branch 14 → 15 taken 3 times.
✓ Branch 14 → 17 taken 3767 times.
|
3770 | if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) { |
| 540 |
1/2✓ Branch 15 → 16 taken 3 times.
✗ Branch 15 → 23 not taken.
|
3 | ensureUnsafeAllowed(node, "-", lhsType, rhsType); |
| 541 | 3 | return lhs; | |
| 542 | } | ||
| 543 | |||
| 544 |
1/2✓ Branch 17 → 18 taken 3767 times.
✗ Branch 17 → 23 not taken.
|
3767 | return {validateBinaryOperation(node, MINUS_OP_RULES, std::size(MINUS_OP_RULES), "-", lhsType, rhsType)}; |
| 545 | } | ||
| 546 | |||
| 547 | 2385 | ExprResult OpRuleManager::getMulResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const { | |
| 548 | // Check is there is an overloaded operator function available | ||
| 549 |
1/2✓ Branch 2 → 3 taken 2385 times.
✗ Branch 2 → 12 not taken.
|
2385 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MUL, {lhs, rhs}, opIdx); |
| 550 |
3/4✓ Branch 3 → 4 taken 2385 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 9 times.
✓ Branch 4 → 6 taken 2376 times.
|
2385 | if (!resultType.type.is(TY_INVALID)) |
| 551 | 9 | return resultType; | |
| 552 | |||
| 553 | // Remove reference wrappers | ||
| 554 |
1/2✓ Branch 6 → 7 taken 2376 times.
✗ Branch 6 → 13 not taken.
|
2376 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 555 |
1/2✓ Branch 7 → 8 taken 2376 times.
✗ Branch 7 → 13 not taken.
|
2376 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 556 | |||
| 557 |
2/2✓ Branch 8 → 9 taken 2375 times.
✓ Branch 8 → 13 taken 1 time.
|
2376 | return {validateBinaryOperation(node, MUL_OP_RULES, std::size(MUL_OP_RULES), "*", lhsType, rhsType)}; |
| 558 | } | ||
| 559 | |||
| 560 | 515 | ExprResult OpRuleManager::getDivResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const { | |
| 561 | // Check is there is an overloaded operator function available | ||
| 562 |
1/2✓ Branch 2 → 3 taken 515 times.
✗ Branch 2 → 12 not taken.
|
515 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_DIV, {lhs, rhs}, opIdx); |
| 563 |
3/4✓ Branch 3 → 4 taken 515 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 5 times.
✓ Branch 4 → 6 taken 510 times.
|
515 | if (!resultType.type.is(TY_INVALID)) |
| 564 | 5 | return resultType; | |
| 565 | |||
| 566 | // Remove reference wrappers | ||
| 567 |
1/2✓ Branch 6 → 7 taken 510 times.
✗ Branch 6 → 13 not taken.
|
510 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 568 |
1/2✓ Branch 7 → 8 taken 510 times.
✗ Branch 7 → 13 not taken.
|
510 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 569 | |||
| 570 |
1/2✓ Branch 8 → 9 taken 510 times.
✗ Branch 8 → 13 not taken.
|
510 | return {validateBinaryOperation(node, DIV_OP_RULES, std::size(DIV_OP_RULES), "/", lhsType, rhsType)}; |
| 571 | } | ||
| 572 | |||
| 573 | 126 | ExprResult OpRuleManager::getRemResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
| 574 | // Remove reference wrappers | ||
| 575 |
1/2✓ Branch 2 → 3 taken 126 times.
✗ Branch 2 → 7 not taken.
|
126 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 576 |
1/2✓ Branch 3 → 4 taken 126 times.
✗ Branch 3 → 7 not taken.
|
126 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 577 | |||
| 578 |
1/2✓ Branch 4 → 5 taken 126 times.
✗ Branch 4 → 7 not taken.
|
126 | return {validateBinaryOperation(node, REM_OP_RULES, std::size(REM_OP_RULES), "%", lhsType, rhsType)}; |
| 579 | } | ||
| 580 | |||
| 581 | 1003 | QualType OpRuleManager::getPrefixMinusResultType(const ASTNode *node, const ExprResult &lhs) { | |
| 582 | // Remove reference wrappers | ||
| 583 |
1/2✓ Branch 2 → 3 taken 1003 times.
✗ Branch 2 → 7 not taken.
|
1003 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 584 | |||
| 585 |
1/2✓ Branch 3 → 4 taken 1003 times.
✗ Branch 3 → 7 not taken.
|
2006 | return validateUnaryOperation(node, PREFIX_MINUS_OP_RULES, std::size(PREFIX_MINUS_OP_RULES), "-", lhsType); |
| 586 | } | ||
| 587 | |||
| 588 | 88 | QualType OpRuleManager::getPrefixPlusPlusResultType(const ASTNode *node, const ExprResult &lhs) const { | |
| 589 | // Check if we try to assign a constant value | ||
| 590 |
1/2✓ Branch 2 → 3 taken 88 times.
✗ Branch 2 → 12 not taken.
|
88 | ensureNoConstAssign(node, lhs.type); |
| 591 | |||
| 592 | // Remove reference wrappers | ||
| 593 |
1/2✓ Branch 3 → 4 taken 88 times.
✗ Branch 3 → 12 not taken.
|
88 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 594 | |||
| 595 | // Check if this is an unsafe operation | ||
| 596 |
2/4✓ Branch 4 → 5 taken 88 times.
✗ Branch 4 → 12 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 88 times.
|
88 | if (lhsType.isPtr()) { |
| 597 | ✗ | ensureUnsafeAllowed(node, "++", lhsType); | |
| 598 | ✗ | return lhsType; | |
| 599 | } | ||
| 600 | |||
| 601 |
1/2✓ Branch 8 → 9 taken 88 times.
✗ Branch 8 → 12 not taken.
|
88 | return validateUnaryOperation(node, PREFIX_PLUS_PLUS_OP_RULES, std::size(PREFIX_PLUS_PLUS_OP_RULES), "++", lhsType); |
| 602 | } | ||
| 603 | |||
| 604 | 22 | QualType OpRuleManager::getPrefixMinusMinusResultType(const ASTNode *node, const ExprResult &lhs) const { | |
| 605 | // Check if we try to assign a constant value | ||
| 606 |
1/2✓ Branch 2 → 3 taken 22 times.
✗ Branch 2 → 12 not taken.
|
22 | ensureNoConstAssign(node, lhs.type); |
| 607 | |||
| 608 | // Remove reference wrappers | ||
| 609 |
1/2✓ Branch 3 → 4 taken 22 times.
✗ Branch 3 → 12 not taken.
|
22 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 610 | |||
| 611 | // Check if this is an unsafe operation | ||
| 612 |
2/4✓ Branch 4 → 5 taken 22 times.
✗ Branch 4 → 12 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 22 times.
|
22 | if (lhsType.isPtr()) { |
| 613 | ✗ | ensureUnsafeAllowed(node, "--", lhsType); | |
| 614 | ✗ | return lhsType; | |
| 615 | } | ||
| 616 | |||
| 617 |
2/2✓ Branch 8 → 9 taken 21 times.
✓ Branch 8 → 12 taken 1 time.
|
22 | return validateUnaryOperation(node, PREFIX_MINUS_MINUS_OP_RULES, std::size(PREFIX_MINUS_MINUS_OP_RULES), "--", lhsType); |
| 618 | } | ||
| 619 | |||
| 620 | 3536 | QualType OpRuleManager::getPrefixNotResultType(const ASTNode *node, const ExprResult &lhs) { | |
| 621 | // Remove reference wrappers | ||
| 622 |
1/2✓ Branch 2 → 3 taken 3536 times.
✗ Branch 2 → 7 not taken.
|
3536 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 623 | |||
| 624 |
1/2✓ Branch 3 → 4 taken 3536 times.
✗ Branch 3 → 7 not taken.
|
7072 | return validateUnaryOperation(node, PREFIX_NOT_OP_RULES, std::size(PREFIX_NOT_OP_RULES), "!", lhsType); |
| 625 | } | ||
| 626 | |||
| 627 | 12 | ExprResult OpRuleManager::getPrefixBitwiseNotResultType(ASTNode *node, const ExprResult &lhs) const { | |
| 628 | // Check if there is an overloaded operator function available | ||
| 629 |
1/2✓ Branch 2 → 3 taken 12 times.
✗ Branch 2 → 11 not taken.
|
12 | const ExprResult resultType = isOperatorOverloadingFctAvailable<1>(node, OP_FCT_BITWISE_NOT, {lhs}, 0); |
| 630 |
3/4✓ Branch 3 → 4 taken 12 times.
✗ Branch 3 → 12 not taken.
✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 6 taken 10 times.
|
12 | if (!resultType.type.is(TY_INVALID)) |
| 631 | 2 | return resultType; | |
| 632 | |||
| 633 | // Remove reference wrappers | ||
| 634 |
1/2✓ Branch 6 → 7 taken 10 times.
✗ Branch 6 → 12 not taken.
|
10 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 635 | |||
| 636 |
1/2✓ Branch 7 → 8 taken 10 times.
✗ Branch 7 → 12 not taken.
|
10 | return {validateUnaryOperation(node, PREFIX_BITWISE_NOT_OP_RULES, std::size(PREFIX_BITWISE_NOT_OP_RULES), "~", lhsType)}; |
| 637 | } | ||
| 638 | |||
| 639 | 904 | QualType OpRuleManager::getPrefixMulResultType(const ASTNode *node, const ExprResult &lhs) { | |
| 640 | // Remove reference wrappers | ||
| 641 |
1/2✓ Branch 2 → 3 taken 904 times.
✗ Branch 2 → 25 not taken.
|
904 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 642 | |||
| 643 |
3/4✓ Branch 3 → 4 taken 904 times.
✗ Branch 3 → 25 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 12 taken 903 times.
|
904 | if (!lhsType.isPtr()) |
| 644 |
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)); |
| 645 |
1/2✓ Branch 12 → 13 taken 903 times.
✗ Branch 12 → 25 not taken.
|
1806 | return lhsType.getContained(); |
| 646 | } | ||
| 647 | |||
| 648 | 748 | QualType OpRuleManager::getPrefixBitwiseAndResultType(const ASTNode *node, const ExprResult &lhs) { | |
| 649 | // Remove reference wrappers | ||
| 650 |
1/2✓ Branch 2 → 3 taken 748 times.
✗ Branch 2 → 7 not taken.
|
748 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 651 | |||
| 652 |
1/2✓ Branch 3 → 4 taken 748 times.
✗ Branch 3 → 7 not taken.
|
1496 | return lhsType.toPtr(node); |
| 653 | } | ||
| 654 | |||
| 655 | 4549 | ExprResult OpRuleManager::getPostfixPlusPlusResultType(ASTNode *node, const ExprResult &lhs) const { | |
| 656 | // Check is there is an overloaded operator function available | ||
| 657 |
2/2✓ Branch 2 → 3 taken 4548 times.
✓ Branch 2 → 16 taken 1 time.
|
4549 | const ExprResult resultType = isOperatorOverloadingFctAvailable<1>(node, OP_FCT_POSTFIX_PLUS_PLUS, {lhs}, 0); |
| 658 |
3/4✓ Branch 3 → 4 taken 4548 times.
✗ Branch 3 → 17 not taken.
✓ Branch 4 → 5 taken 9 times.
✓ Branch 4 → 6 taken 4539 times.
|
4548 | if (!resultType.type.is(TY_INVALID)) |
| 659 | 9 | return resultType; | |
| 660 | |||
| 661 | // Check if we try to assign a constant value | ||
| 662 |
1/2✓ Branch 6 → 7 taken 4539 times.
✗ Branch 6 → 17 not taken.
|
4539 | ensureNoConstAssign(node, lhs.type); |
| 663 | |||
| 664 | // Remove reference wrappers | ||
| 665 |
1/2✓ Branch 7 → 8 taken 4539 times.
✗ Branch 7 → 17 not taken.
|
4539 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 666 | |||
| 667 | // Check if this is an unsafe operation | ||
| 668 |
3/4✓ Branch 8 → 9 taken 4539 times.
✗ Branch 8 → 17 not taken.
✓ Branch 9 → 10 taken 25 times.
✓ Branch 9 → 12 taken 4514 times.
|
4539 | if (lhsType.isPtr()) { |
| 669 |
1/2✓ Branch 10 → 11 taken 25 times.
✗ Branch 10 → 17 not taken.
|
25 | ensureUnsafeAllowed(node, "++", lhsType); |
| 670 | 25 | return lhs; | |
| 671 | } | ||
| 672 | |||
| 673 |
2/2✓ Branch 12 → 13 taken 4513 times.
✓ Branch 12 → 17 taken 1 time.
|
4514 | return {validateUnaryOperation(node, POSTFIX_PLUS_PLUS_OP_RULES, std::size(POSTFIX_PLUS_PLUS_OP_RULES), "++", lhsType)}; |
| 674 | } | ||
| 675 | |||
| 676 | 445 | ExprResult OpRuleManager::getPostfixMinusMinusResultType(ASTNode *node, const ExprResult &lhs) const { | |
| 677 | // Check is there is an overloaded operator function available | ||
| 678 |
1/2✓ Branch 2 → 3 taken 445 times.
✗ Branch 2 → 16 not taken.
|
445 | const ExprResult resultType = isOperatorOverloadingFctAvailable<1>(node, OP_FCT_POSTFIX_MINUS_MINUS, {lhs}, 0); |
| 679 |
3/4✓ Branch 3 → 4 taken 445 times.
✗ Branch 3 → 17 not taken.
✓ Branch 4 → 5 taken 7 times.
✓ Branch 4 → 6 taken 438 times.
|
445 | if (!resultType.type.is(TY_INVALID)) |
| 680 | 7 | return resultType; | |
| 681 | |||
| 682 | // Check if we try to assign a constant value | ||
| 683 |
1/2✓ Branch 6 → 7 taken 438 times.
✗ Branch 6 → 17 not taken.
|
438 | ensureNoConstAssign(node, lhs.type); |
| 684 | |||
| 685 | // Remove reference wrappers | ||
| 686 |
1/2✓ Branch 7 → 8 taken 438 times.
✗ Branch 7 → 17 not taken.
|
438 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
| 687 | |||
| 688 | // Check if this is an unsafe operation | ||
| 689 |
3/4✓ Branch 8 → 9 taken 438 times.
✗ Branch 8 → 17 not taken.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 12 taken 436 times.
|
438 | if (lhsType.isPtr()) { |
| 690 |
1/2✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 17 not taken.
|
2 | ensureUnsafeAllowed(node, "--", lhsType); |
| 691 | 2 | return lhs; | |
| 692 | } | ||
| 693 | |||
| 694 |
1/2✓ Branch 12 → 13 taken 436 times.
✗ Branch 12 → 17 not taken.
|
436 | return {validateUnaryOperation(node, POSTFIX_MINUS_MINUS_OP_RULES, std::size(POSTFIX_MINUS_MINUS_OP_RULES), "--", lhsType)}; |
| 695 | } | ||
| 696 | |||
| 697 | 7950 | QualType OpRuleManager::getCastResultType(const ASTNode *node, QualType lhsType, const ExprResult &rhs) const { | |
| 698 | // Remove reference wrappers | ||
| 699 |
1/2✓ Branch 2 → 3 taken 7950 times.
✗ Branch 2 → 73 not taken.
|
7950 | lhsType = lhsType.removeReferenceWrapper(); |
| 700 |
1/2✓ Branch 3 → 4 taken 7950 times.
✗ Branch 3 → 82 not taken.
|
7950 | QualType rhsType = rhs.type.removeReferenceWrapper(); |
| 701 | |||
| 702 | // Only allow to cast the 'heap' qualifier away, if we are in unsafe mode | ||
| 703 |
2/2✓ Branch 6 → 7 taken 337 times.
✓ Branch 6 → 8 taken 7613 times.
|
7950 | if (lhsType.getQualifiers().isHeap != rhsType.getQualifiers().isHeap) |
| 704 |
1/2✓ Branch 7 → 8 taken 337 times.
✗ Branch 7 → 82 not taken.
|
337 | ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType); |
| 705 | |||
| 706 | // Allow identity casts | ||
| 707 |
3/4✓ Branch 8 → 9 taken 7950 times.
✗ Branch 8 → 82 not taken.
✓ Branch 9 → 10 taken 876 times.
✓ Branch 9 → 11 taken 7074 times.
|
7950 | if (lhsType.matches(rhsType, false, true, true)) |
| 708 | 876 | return lhsType; | |
| 709 | // Allow casts string -> char* and string -> char[] | ||
| 710 |
12/16✓ Branch 11 → 12 taken 7074 times.
✗ Branch 11 → 74 not taken.
✓ Branch 12 → 13 taken 3974 times.
✓ Branch 12 → 19 taken 3100 times.
✓ Branch 13 → 14 taken 3974 times.
✗ Branch 13 → 74 not taken.
✓ Branch 14 → 15 taken 3974 times.
✗ Branch 14 → 74 not taken.
✓ Branch 15 → 16 taken 1634 times.
✓ Branch 15 → 19 taken 2340 times.
✓ Branch 16 → 17 taken 1634 times.
✗ Branch 16 → 74 not taken.
✓ Branch 17 → 18 taken 1627 times.
✓ Branch 17 → 19 taken 7 times.
✓ Branch 20 → 21 taken 1627 times.
✓ Branch 20 → 22 taken 5447 times.
|
7074 | if (lhsType.isOneOf({TY_PTR, TY_ARRAY}) && lhsType.getContained().is(TY_CHAR) && rhsType.is(TY_STRING)) |
| 711 | 1627 | return lhsType; | |
| 712 | // Allow casts char* -> string and char[] -> string | ||
| 713 |
10/16✓ Branch 22 → 23 taken 5447 times.
✗ Branch 22 → 76 not taken.
✓ Branch 23 → 24 taken 153 times.
✓ Branch 23 → 30 taken 5294 times.
✓ Branch 24 → 25 taken 153 times.
✗ Branch 24 → 76 not taken.
✓ Branch 25 → 26 taken 153 times.
✗ Branch 25 → 30 not taken.
✓ Branch 26 → 27 taken 153 times.
✗ Branch 26 → 76 not taken.
✓ Branch 27 → 28 taken 153 times.
✗ Branch 27 → 76 not taken.
✓ Branch 28 → 29 taken 153 times.
✗ Branch 28 → 30 not taken.
✓ Branch 31 → 32 taken 153 times.
✓ Branch 31 → 33 taken 5294 times.
|
5447 | if (lhsType.is(TY_STRING) && rhsType.isOneOf({TY_PTR, TY_ARRAY}) && rhsType.getContained().is(TY_CHAR)) |
| 714 | 153 | return lhsType; | |
| 715 | // Allow safe upcasts baseStruct* <- derivedStruct* and interface* <- struct* without requiring an unsafe | ||
| 716 | // block. These are the only struct-pointer casts where the target subobject is guaranteed to be present; | ||
| 717 | // the IR generator advances the pointer to that subobject (past any vtable prefix). The reverse direction | ||
| 718 | // (down/sibling casts) is not covered here and still falls through to the unsafe any* -> any* rule below. | ||
| 719 |
8/10✓ Branch 33 → 34 taken 5294 times.
✗ Branch 33 → 82 not taken.
✓ Branch 34 → 35 taken 2347 times.
✓ Branch 34 → 38 taken 2947 times.
✓ Branch 35 → 36 taken 2347 times.
✗ Branch 35 → 82 not taken.
✓ Branch 36 → 37 taken 2339 times.
✓ Branch 36 → 38 taken 8 times.
✓ Branch 39 → 40 taken 2339 times.
✓ Branch 39 → 51 taken 2955 times.
|
5294 | if (lhsType.isPtr() && rhsType.isPtr()) { |
| 720 |
1/2✓ Branch 40 → 41 taken 2339 times.
✗ Branch 40 → 78 not taken.
|
2339 | const QualType lhsContained = lhsType.getContained(); |
| 721 |
1/2✓ Branch 41 → 42 taken 2339 times.
✗ Branch 41 → 78 not taken.
|
2339 | const QualType rhsContained = rhsType.getContained(); |
| 722 |
5/6✓ Branch 42 → 43 taken 2339 times.
✗ Branch 42 → 78 not taken.
✓ Branch 43 → 44 taken 2334 times.
✓ Branch 43 → 46 taken 5 times.
✓ Branch 48 → 49 taken 467 times.
✓ Branch 48 → 50 taken 1872 times.
|
4673 | if (lhsContained.matchesInterfaceImplementedByStruct(rhsContained) || |
| 723 |
3/4✓ Branch 44 → 45 taken 2334 times.
✗ Branch 44 → 78 not taken.
✓ Branch 45 → 46 taken 462 times.
✓ Branch 45 → 47 taken 1872 times.
|
2334 | lhsContained.matchesComposedBaseOfStruct(rhsContained)) |
| 724 | 467 | return lhsType; | |
| 725 | } | ||
| 726 | // Allow casts any* -> any* | ||
| 727 |
8/10✓ Branch 51 → 52 taken 4827 times.
✗ Branch 51 → 79 not taken.
✓ Branch 52 → 53 taken 1880 times.
✓ Branch 52 → 56 taken 2947 times.
✓ Branch 53 → 54 taken 1880 times.
✗ Branch 53 → 79 not taken.
✓ Branch 54 → 55 taken 1872 times.
✓ Branch 54 → 56 taken 8 times.
✓ Branch 57 → 58 taken 1872 times.
✓ Branch 57 → 60 taken 2955 times.
|
4827 | if (lhsType.isOneOf({TY_PTR, TY_STRING}) && rhsType.isOneOf({TY_PTR, TY_STRING})) { |
| 728 |
1/2✓ Branch 58 → 59 taken 1872 times.
✗ Branch 58 → 82 not taken.
|
1872 | ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType); |
| 729 | 1872 | return lhsType; | |
| 730 | } | ||
| 731 | // Allow casts p()/f<>() -> byte* | ||
| 732 |
7/10✓ Branch 60 → 61 taken 2955 times.
✗ Branch 60 → 81 not taken.
✓ Branch 61 → 62 taken 8 times.
✓ Branch 61 → 65 taken 2947 times.
✓ Branch 62 → 63 taken 8 times.
✗ Branch 62 → 81 not taken.
✓ Branch 63 → 64 taken 8 times.
✗ Branch 63 → 65 not taken.
✓ Branch 66 → 67 taken 8 times.
✓ Branch 66 → 69 taken 2947 times.
|
2955 | if (lhsType.isPtrTo(TY_BYTE) && rhsType.isOneOf({TY_FUNCTION, TY_PROCEDURE})) { |
| 733 |
1/2✓ Branch 67 → 68 taken 8 times.
✗ Branch 67 → 82 not taken.
|
8 | ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType); |
| 734 | 8 | return lhsType; | |
| 735 | } | ||
| 736 | // Check primitive type combinations | ||
| 737 |
1/2✓ Branch 69 → 70 taken 2947 times.
✗ Branch 69 → 82 not taken.
|
2947 | return validateBinaryOperation(node, CAST_OP_RULES, std::size(CAST_OP_RULES), "(cast)", lhsType, rhsType, true); |
| 738 | } | ||
| 739 | |||
| 740 | template <size_t N> | ||
| 741 | 43962 | ExprResult OpRuleManager::isOperatorOverloadingFctAvailable(ASTNode *node, const char *const fctName, | |
| 742 | const std::array<ExprResult, N> &op, size_t opIdx) const { | ||
| 743 | static_assert(N == 1 || N == 2, "Only unary and binary operators are overloadable"); | ||
| 744 | 43962 | Scope *calleeParentScope = nullptr; | |
| 745 | 43962 | const Function *callee = nullptr; | |
| 746 |
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 5006 times.
✗ Branch 2 → 124 not taken.
✓ Branch 3 → 4 taken 5006 times.
✗ Branch 3 → 124 not taken.
✓ Branch 4 → 5 taken 5006 times.
✗ Branch 4 → 124 not taken.
✓ Branch 42 → 43 taken 18607 times.
✓ Branch 42 → 46 taken 19 times.
✓ Branch 49 → 6 taken 87146 times.
✓ Branch 49 → 50 taken 4987 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 38956 times.
✗ Branch 2 → 133 not taken.
✓ Branch 3 → 4 taken 38956 times.
✗ Branch 3 → 133 not taken.
✓ Branch 4 → 5 taken 38956 times.
✗ Branch 4 → 133 not taken.
✓ Branch 49 → 50 taken 284708 times.
✓ Branch 49 → 53 taken 5491 times.
✓ Branch 56 → 6 taken 630802 times.
✓ Branch 56 → 57 taken 33465 times.
|
1109187 | for (const auto &sourceFile : typeChecker->resourceManager.sourceFiles | std::views::values) { |
| 747 | // Check if there is a registered operator function | ||
| 748 |
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 87146 times.
✗ Branch 10 → 103 not taken.
✓ Branch 11 → 12 taken 87146 times.
✗ Branch 11 → 101 not taken.
✓ Branch 14 → 15 taken 68520 times.
✓ Branch 14 → 16 taken 18626 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 630802 times.
✗ Branch 10 → 110 not taken.
✓ Branch 11 → 12 taken 630802 times.
✗ Branch 11 → 108 not taken.
✓ Branch 14 → 15 taken 340603 times.
✓ Branch 14 → 16 taken 290199 times.
|
2153844 | if (!sourceFile->getNameRegistryEntry(fctName)) |
| 749 | 409123 | continue; | |
| 750 | |||
| 751 | // Match callees in the global scope of this source file | ||
| 752 | 308825 | calleeParentScope = sourceFile->globalScope.get(); | |
| 753 |
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 18626 times.
✗ Branch 18 → 123 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 290199 times.
✗ Branch 18 → 132 not taken.
|
308825 | const QualType thisType(TY_DYN); |
| 754 |
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 18626 times.
✗ Branch 21 → 107 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 290199 times.
✗ Branch 21 → 114 not taken.
|
617650 | ArgList args(N); |
| 755 |
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 18626 times.
✗ Branch 24 → 110 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 290199 times.
✗ Branch 24 → 117 not taken.
|
308825 | args[0] = {typeChecker->mapLocalTypeToImportedScopeType(calleeParentScope, op[0].type), op[0].isTemporary()}; |
| 756 | if constexpr (N == 2) | ||
| 757 |
1/2✓ Branch 31 → 32 taken 290199 times.
✗ Branch 31 → 119 not taken.
|
290199 | args[1] = {typeChecker->mapLocalTypeToImportedScopeType(calleeParentScope, op[1].type), op[1].isTemporary()}; |
| 758 |
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 18626 times.
✗ Branch 33 → 114 not taken.
✓ Branch 34 → 35 taken 18626 times.
✗ Branch 34 → 112 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 290199 times.
✗ Branch 40 → 123 not taken.
✓ Branch 41 → 42 taken 290199 times.
✗ Branch 41 → 121 not taken.
|
926475 | callee = FunctionManager::match(calleeParentScope, fctName, thisType, args, {}, false, node); |
| 759 |
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 19 times.
✓ Branch 38 → 40 taken 18607 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 5491 times.
✓ Branch 45 → 47 taken 284708 times.
|
308825 | if (callee) |
| 760 | 5510 | break; | |
| 761 | } | ||
| 762 | |||
| 763 | // Return invalid type if the callee was not found | ||
| 764 |
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 50 → 51 taken 4987 times.
✓ Branch 50 → 53 taken 19 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 57 → 58 taken 33465 times.
✓ Branch 57 → 60 taken 5491 times.
|
43962 | if (!callee) |
| 765 | 38452 | return ExprResult(QualType(TY_INVALID)); | |
| 766 |
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 53 → 54 not taken.
✓ Branch 53 → 55 taken 19 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 60 → 61 not taken.
✓ Branch 60 → 62 taken 5491 times.
|
5510 | assert(calleeParentScope != nullptr); |
| 767 | |||
| 768 | // Save the pointer to the operator function in the AST node | ||
| 769 | 5510 | std::vector<const Function *> &opFctPointers = typeChecker->getOpFctPointers(node); | |
| 770 |
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 57 → 58 not taken.
✓ Branch 57 → 60 taken 19 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 64 → 65 taken 1224 times.
✓ Branch 64 → 67 taken 4267 times.
|
5510 | if (opFctPointers.size() <= opIdx) |
| 771 |
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 58 → 59 not taken.
✗ Branch 58 → 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 65 → 66 taken 1224 times.
✗ Branch 65 → 134 not taken.
|
1224 | opFctPointers.resize(opIdx + 1, nullptr); |
| 772 | 5510 | opFctPointers.at(opIdx) = callee; | |
| 773 | |||
| 774 | // Check if we need to request a re-visit, because the function body was not type-checked yet | ||
| 775 | 5510 | TypeChecker::requestRevisitIfRequired(callee); | |
| 776 | |||
| 777 | // Check if the called function has sufficient visibility | ||
| 778 |
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 62 → 63 taken 19 times.
✗ Branch 62 → 66 not taken.
✓ Branch 64 → 65 taken 16 times.
✓ Branch 64 → 66 taken 3 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 69 → 70 taken 5491 times.
✗ Branch 69 → 73 not taken.
✓ Branch 71 → 72 taken 4575 times.
✓ Branch 71 → 73 taken 916 times.
|
5510 | const bool isImported = calleeParentScope != nullptr && calleeParentScope->isImportedBy(typeChecker->rootScope); |
| 779 | 5510 | const SymbolTableEntry *calleeEntry = callee->entry; | |
| 780 |
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 67 → 68 taken 16 times.
✓ Branch 67 → 72 taken 3 times.
✓ Branch 70 → 71 taken 1 time.
✓ Branch 70 → 72 taken 15 times.
✓ Branch 73 → 74 taken 1 time.
✓ Branch 73 → 83 taken 18 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 74 → 75 taken 4575 times.
✓ Branch 74 → 79 taken 916 times.
✗ Branch 77 → 78 not taken.
✓ Branch 77 → 79 taken 4575 times.
✗ Branch 80 → 81 not taken.
✓ Branch 80 → 90 taken 5491 times.
|
5510 | if (isImported && !calleeEntry->getQualType().isPublic()) |
| 781 |
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 78 → 79 taken 1 time.
✗ Branch 78 → 126 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 85 → 86 not taken.
✗ Branch 85 → 135 not taken.
|
2 | throw SemanticError(node, INSUFFICIENT_VISIBILITY, |
| 782 |
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 75 → 76 taken 1 time.
✗ Branch 75 → 133 not taken.
✓ Branch 76 → 77 taken 1 time.
✗ Branch 76 → 131 not taken.
✓ Branch 77 → 78 taken 1 time.
✗ Branch 77 → 129 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 82 → 83 not taken.
✗ Branch 82 → 142 not taken.
✗ Branch 83 → 84 not taken.
✗ Branch 83 → 140 not taken.
✗ Branch 84 → 85 not taken.
✗ Branch 84 → 138 not taken.
|
2 | "Overloaded operator '" + callee->getSignature() + "' has insufficient visibility"); |
| 783 | |||
| 784 | // Procedures always have the return type 'bool' | ||
| 785 |
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 86 → 87 taken 14 times.
✓ Branch 86 → 89 taken 4 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 93 → 94 taken 896 times.
✓ Branch 93 → 96 taken 4595 times.
|
5509 | if (callee->isProcedure()) |
| 786 | 910 | return ExprResult(QualType(TY_BOOL)); | |
| 787 | 4599 | const QualType &returnType = callee->returnType; | |
| 788 | |||
| 789 | // Add anonymous symbol to keep track of dtor call, if non-trivially destructible | ||
| 790 | 4599 | SymbolTableEntry *anonymousSymbol = nullptr; | |
| 791 |
12/12spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 90 → 91 taken 2 times.
✓ Branch 90 → 94 taken 2 times.
✓ Branch 92 → 93 taken 1 time.
✓ Branch 92 → 94 taken 1 time.
✓ Branch 95 → 96 taken 1 time.
✓ Branch 95 → 98 taken 3 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 97 → 98 taken 621 times.
✓ Branch 97 → 101 taken 3974 times.
✓ Branch 99 → 100 taken 610 times.
✓ Branch 99 → 101 taken 11 times.
✓ Branch 102 → 103 taken 610 times.
✓ Branch 102 → 105 taken 3985 times.
|
4599 | if (returnType.is(TY_STRUCT) && !returnType.isTriviallyDestructible(node)) |
| 792 | 611 | anonymousSymbol = typeChecker->currentScope->symbolTable.insertAnonymous(returnType, node, opIdx); | |
| 793 | |||
| 794 | 4599 | return {typeChecker->mapImportedScopeTypeToLocalType(calleeParentScope, returnType), anonymousSymbol}; | |
| 795 | } | ||
| 796 | |||
| 797 | 9609 | QualType OpRuleManager::validateUnaryOperation(const ASTNode *node, const UnaryOpRule opRules[], size_t opRulesSize, | |
| 798 | const char *name, const QualType &lhs) { | ||
| 799 |
2/2✓ Branch 10 → 3 taken 20377 times.
✓ Branch 10 → 11 taken 2 times.
|
20379 | for (size_t i = 0; i < opRulesSize; i++) { |
| 800 | 20377 | const UnaryOpRule &rule = opRules[i]; | |
| 801 |
2/2✓ Branch 5 → 6 taken 9607 times.
✓ Branch 5 → 9 taken 10770 times.
|
20377 | if (std::get<0>(rule) == lhs.getSuperType()) |
| 802 |
1/2✓ Branch 7 → 8 taken 9607 times.
✗ Branch 7 → 15 not taken.
|
9607 | return QualType(std::get<1>(rule)); |
| 803 | } | ||
| 804 |
1/2✓ Branch 12 → 13 taken 2 times.
✗ Branch 12 → 16 not taken.
|
2 | throw getExceptionUnary(node, name, lhs); |
| 805 | } | ||
| 806 | |||
| 807 | 88183 | QualType OpRuleManager::validateBinaryOperation(const ASTNode *node, const BinaryOpRule opRules[], size_t opRulesSize, | |
| 808 | const char *name, const QualType &lhs, const QualType &rhs, | ||
| 809 | bool preserveQualifiersFromLhs, const char *customMessagePrefix) { | ||
| 810 |
2/2✓ Branch 19 → 3 taken 844785 times.
✓ Branch 19 → 20 taken 20 times.
|
844805 | for (size_t i = 0; i < opRulesSize; i++) { |
| 811 | 844785 | const BinaryOpRule &rule = opRules[i]; | |
| 812 |
6/6✓ Branch 5 → 6 taken 169926 times.
✓ Branch 5 → 10 taken 674859 times.
✓ Branch 8 → 9 taken 88163 times.
✓ Branch 8 → 10 taken 81763 times.
✓ Branch 11 → 12 taken 88163 times.
✓ Branch 11 → 18 taken 756622 times.
|
844785 | if (std::get<0>(rule) == lhs.getSuperType() && std::get<1>(rule) == rhs.getSuperType()) { |
| 813 |
1/2✓ Branch 13 → 14 taken 88163 times.
✗ Branch 13 → 24 not taken.
|
88163 | QualType resultType((std::get<2>(rule))); |
| 814 |
2/2✓ Branch 14 → 15 taken 48365 times.
✓ Branch 14 → 17 taken 39798 times.
|
88163 | if (preserveQualifiersFromLhs) |
| 815 | 48365 | resultType.setQualifiers(lhs.getQualifiers()); | |
| 816 | 88163 | return resultType; | |
| 817 | } | ||
| 818 | } | ||
| 819 |
1/2✓ Branch 21 → 22 taken 20 times.
✗ Branch 21 → 25 not taken.
|
20 | throw getExceptionBinary(node, name, lhs, rhs, customMessagePrefix); |
| 820 | } | ||
| 821 | |||
| 822 | 2 | SemanticError OpRuleManager::getExceptionUnary(const ASTNode *node, const char *name, const QualType &lhs) { | |
| 823 |
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)}; |
| 824 | } | ||
| 825 | |||
| 826 | 20 | SemanticError OpRuleManager::getExceptionBinary(const ASTNode *node, const char *name, const QualType &lhs, const QualType &rhs, | |
| 827 | const char *messagePrefix) { | ||
| 828 | // Build error message | ||
| 829 |
1/2✓ Branch 2 → 3 taken 20 times.
✗ Branch 2 → 50 not taken.
|
20 | std::stringstream errorMsg; |
| 830 |
2/2✓ Branch 3 → 4 taken 4 times.
✓ Branch 3 → 14 taken 16 times.
|
20 | if (strlen(messagePrefix) != 0) |
| 831 |
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); |
| 832 | else | ||
| 833 |
8/16✓ Branch 14 → 15 taken 16 times.
✗ Branch 14 → 48 not taken.
✓ Branch 15 → 16 taken 16 times.
✗ Branch 15 → 48 not taken.
✓ Branch 16 → 17 taken 16 times.
✗ Branch 16 → 48 not taken.
✓ Branch 17 → 18 taken 16 times.
✗ Branch 17 → 43 not taken.
✓ Branch 18 → 19 taken 16 times.
✗ Branch 18 → 41 not taken.
✓ Branch 19 → 20 taken 16 times.
✗ Branch 19 → 41 not taken.
✓ Branch 20 → 21 taken 16 times.
✗ Branch 20 → 40 not taken.
✓ Branch 21 → 22 taken 16 times.
✗ Branch 21 → 38 not taken.
|
16 | errorMsg << "Cannot apply '" << name << "' operator on types " << lhs.getName(true) << " and " << rhs.getName(true); |
| 834 | |||
| 835 | // Return the exception | ||
| 836 |
2/4✓ Branch 25 → 26 taken 20 times.
✗ Branch 25 → 46 not taken.
✓ Branch 26 → 27 taken 20 times.
✗ Branch 26 → 44 not taken.
|
60 | return {node, OPERATOR_WRONG_DATA_TYPE, errorMsg.str()}; |
| 837 | 20 | } | |
| 838 | |||
| 839 | 27 | void OpRuleManager::ensureUnsafeAllowed(const ASTNode *node, const char *name, const QualType &lhs) const { | |
| 840 |
2/4✓ Branch 2 → 3 taken 27 times.
✗ Branch 2 → 43 not taken.
✓ Branch 3 → 4 taken 27 times.
✗ Branch 3 → 5 not taken.
|
27 | if (typeChecker->currentScope->doesAllowUnsafeOperations()) |
| 841 | 27 | return; | |
| 842 | // Print error message | ||
| 843 | ✗ | const std::string lhsName = lhs.getName(true); | |
| 844 | ✗ | const std::string errorMsg = "Cannot apply '" + std::string(name) + "' operator on type " + lhsName + | |
| 845 | ✗ | " as this is an unsafe operation. Please use unsafe blocks if you know what you are doing."; | |
| 846 | ✗ | SOFT_ERROR_VOID(node, UNSAFE_OPERATION_IN_SAFE_CONTEXT, errorMsg) | |
| 847 | ✗ | } | |
| 848 | |||
| 849 | 3300 | void OpRuleManager::ensureUnsafeAllowed(const ASTNode *node, const char *name, const QualType &lhs, const QualType &rhs) const { | |
| 850 |
3/4✓ Branch 2 → 3 taken 3300 times.
✗ Branch 2 → 57 not taken.
✓ Branch 3 → 4 taken 3299 times.
✓ Branch 3 → 5 taken 1 time.
|
3300 | if (typeChecker->currentScope->doesAllowUnsafeOperations()) |
| 851 | 3299 | return; | |
| 852 | // Print error message | ||
| 853 |
1/2✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 57 not taken.
|
1 | const std::string lhsName = lhs.getName(true); |
| 854 |
1/2✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 55 not taken.
|
1 | const std::string rhsName = rhs.getName(true); |
| 855 |
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.
|
3 | const std::string errorMsg = "Cannot apply '" + std::string(name) + "' operator on types " + lhsName + " and " + rhsName + |
| 856 |
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."; |
| 857 |
1/2✓ Branch 23 → 24 taken 1 time.
✗ Branch 23 → 51 not taken.
|
1 | SOFT_ERROR_VOID(node, UNSAFE_OPERATION_IN_SAFE_CONTEXT, errorMsg) |
| 858 | 1 | } | |
| 859 | |||
| 860 | 80862 | void OpRuleManager::ensureNoConstAssign(const ASTNode *node, const QualType &lhs, bool isDecl, bool isReturn) const { | |
| 861 | // Check if we try to assign a constant value | ||
| 862 |
10/12✓ Branch 2 → 3 taken 80862 times.
✗ Branch 2 → 17 not taken.
✓ Branch 3 → 4 taken 80862 times.
✗ Branch 3 → 17 not taken.
✓ Branch 4 → 5 taken 8453 times.
✓ Branch 4 → 8 taken 72409 times.
✓ Branch 5 → 6 taken 205 times.
✓ Branch 5 → 8 taken 8248 times.
✓ Branch 6 → 7 taken 14 times.
✓ Branch 6 → 8 taken 191 times.
✓ Branch 9 → 10 taken 14 times.
✓ Branch 9 → 16 taken 80848 times.
|
80862 | if (lhs.removeReferenceWrapper().isConst() && !isDecl && !isReturn) { |
| 863 |
2/4✓ Branch 10 → 11 taken 14 times.
✗ Branch 10 → 20 not taken.
✓ Branch 11 → 12 taken 14 times.
✗ Branch 11 → 18 not taken.
|
14 | const std::string errorMessage = "Trying to assign value to an immutable variable of type " + lhs.getName(true); |
| 864 |
1/2✓ Branch 13 → 14 taken 14 times.
✗ Branch 13 → 21 not taken.
|
14 | SOFT_ERROR_VOID(node, REASSIGN_CONST_VARIABLE, errorMessage); |
| 865 | 14 | } | |
| 866 | } | ||
| 867 | |||
| 868 | } // namespace spice::compiler | ||
| 869 |