GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 96.5% 472 / 0 / 489
Functions: 100.0% 52 / 0 / 52
Branches: 63.4% 805 / 0 / 1270

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 10066 OpRuleManager::OpRuleManager(TypeChecker *typeChecker)
16 10066 : typeChecker(typeChecker), resourceManager(typeChecker->resourceManager) {}
17
18 92117 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 92117 const QualType lhsType = lhs.type;
22 92117 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 92116 times.
92117 if (lhs.isTemporary())
26
2/4
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 107 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 104 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 92116 times.
✗ Branch 12 → 123 not taken.
✓ Branch 13 → 14 taken 592 times.
✓ Branch 13 → 16 taken 91524 times.
92116 if (lhsType.is(TY_DYN))
30 592 return {rhsType, nullptr};
31
32 // Check if we try to assign a constant value
33
1/2
✓ Branch 16 → 17 taken 91524 times.
✗ Branch 16 → 123 not taken.
91524 ensureNoConstAssign(node, lhsType, isDecl, isReturn);
34
35 // Allow pointers and references of the same type straight away
36
8/10
✓ Branch 17 → 18 taken 91524 times.
✗ Branch 17 → 113 not taken.
✓ Branch 18 → 19 taken 17638 times.
✓ Branch 18 → 22 taken 73886 times.
✓ Branch 19 → 20 taken 17638 times.
✗ Branch 19 → 113 not taken.
✓ Branch 20 → 21 taken 13623 times.
✓ Branch 20 → 22 taken 4015 times.
✓ Branch 23 → 24 taken 13623 times.
✓ Branch 23 → 41 taken 77901 times.
91524 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 4759 times.
✓ Branch 24 → 35 taken 8864 times.
✓ Branch 25 → 26 taken 4759 times.
✗ Branch 25 → 114 not taken.
✓ Branch 26 → 27 taken 3406 times.
✓ Branch 26 → 35 taken 1353 times.
✓ Branch 27 → 28 taken 3406 times.
✗ Branch 27 → 114 not taken.
✓ Branch 28 → 29 taken 1340 times.
✓ Branch 28 → 35 taken 2066 times.
✓ Branch 29 → 30 taken 1340 times.
✗ Branch 29 → 114 not taken.
✓ Branch 30 → 31 taken 1340 times.
✗ Branch 30 → 114 not taken.
✓ Branch 31 → 32 taken 1340 times.
✗ Branch 31 → 35 not taken.
✓ Branch 32 → 33 taken 1340 times.
✗ Branch 32 → 114 not taken.
✓ Branch 33 → 34 taken 1340 times.
✗ Branch 33 → 35 not taken.
✓ Branch 36 → 37 taken 1340 times.
✓ Branch 36 → 39 taken 12283 times.
13623 if (rhs.entry && lhsType.isPtr() && lhsType.isHeap() && rhsType.removeReferenceWrapper().isPtr() && rhsType.isHeap())
39
1/2
✓ Branch 37 → 38 taken 1340 times.
✗ Branch 37 → 115 not taken.
1340 rhs.entry->updateState(MOVED, node);
40 13623 return {rhsType, nullptr};
41 }
42 // Allow ref type to type of the same contained type straight away
43
3/4
✓ Branch 41 → 42 taken 77901 times.
✗ Branch 41 → 123 not taken.
✓ Branch 42 → 43 taken 2262 times.
✓ Branch 42 → 55 taken 75639 times.
77901 if (rhsType.isRef()) {
44 // If this is const ref, remove both: the reference and the constness
45
2/4
✓ Branch 43 → 44 taken 2262 times.
✗ Branch 43 → 116 not taken.
✓ Branch 44 → 45 taken 2262 times.
✗ Branch 44 → 116 not taken.
2262 const QualType rhsNonRef = rhsType.getContained().toNonConst();
46
3/4
✓ Branch 45 → 46 taken 2262 times.
✗ Branch 45 → 117 not taken.
✓ Branch 46 → 47 taken 2260 times.
✓ Branch 46 → 53 taken 2 times.
2262 if (lhsType.matches(rhsNonRef, false, false, true)) {
47
3/4
✓ Branch 47 → 48 taken 2260 times.
✗ Branch 47 → 117 not taken.
✓ Branch 48 → 49 taken 1042 times.
✓ Branch 48 → 51 taken 1218 times.
2260 if (rhsNonRef.is(TY_STRUCT))
48
1/2
✓ Branch 49 → 50 taken 1042 times.
✗ Branch 49 → 117 not taken.
2260 return performStructAssign(node, lhs, rhs, rhsNonRef, isDecl, isReturn);
49 1218 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 75641 times.
✗ Branch 55 → 118 not taken.
✓ Branch 56 → 57 taken 369 times.
✓ Branch 56 → 60 taken 75272 times.
✓ Branch 57 → 58 taken 369 times.
✗ Branch 57 → 118 not taken.
✓ Branch 58 → 59 taken 364 times.
✓ Branch 58 → 60 taken 5 times.
✓ Branch 61 → 62 taken 364 times.
✓ Branch 61 → 64 taken 75277 times.
75641 if (lhsType.isOneOf({TY_ARRAY, TY_INTERFACE, TY_FUNCTION, TY_PROCEDURE}) && lhsType.matches(rhsType, false, true, true))
54 364 return {rhsType, nullptr};
55 // Allow struct of the same type straight away
56
8/10
✓ Branch 64 → 65 taken 75277 times.
✗ Branch 64 → 123 not taken.
✓ Branch 65 → 66 taken 13140 times.
✓ Branch 65 → 69 taken 62137 times.
✓ Branch 66 → 67 taken 13140 times.
✗ Branch 66 → 123 not taken.
✓ Branch 67 → 68 taken 13139 times.
✓ Branch 67 → 69 taken 1 time.
✓ Branch 70 → 71 taken 13139 times.
✓ Branch 70 → 73 taken 62138 times.
75277 if (lhsType.is(TY_STRUCT) && lhsType.matches(rhsType, false, true, true))
57
1/2
✓ Branch 71 → 72 taken 13139 times.
✗ Branch 71 → 123 not taken.
13139 return performStructAssign(node, lhs, rhs, rhsType, isDecl, isReturn);
58 // Allow assignment through an already-bound reference to a struct. Unlike binding a reference (declaration/return,
59 // which pass isDecl/isReturn and fall through to the common rules below), an assign-through must run the struct's
60 // copy-assignment operator / copy ctor on the referenced value instead of rebinding or shallow-copying it. Otherwise
61 // the referent would alias the rhs' owned members (heap buffers) and double-free once one of them is destructed.
62
10/14
✓ Branch 74 → 75 taken 11983 times.
✓ Branch 74 → 88 taken 23333 times.
✓ Branch 75 → 76 taken 11983 times.
✗ Branch 75 → 119 not taken.
✓ Branch 76 → 77 taken 375 times.
✓ Branch 76 → 88 taken 11608 times.
✓ Branch 77 → 78 taken 375 times.
✗ Branch 77 → 119 not taken.
✓ Branch 78 → 79 taken 375 times.
✗ Branch 78 → 119 not taken.
✓ Branch 79 → 80 taken 8 times.
✓ Branch 79 → 88 taken 367 times.
✓ Branch 80 → 81 taken 8 times.
✗ Branch 80 → 88 not taken.
35316 if (!isDecl && !isReturn && lhsType.isRef() && lhsType.getContained().is(TY_STRUCT) && lhs.entry != nullptr &&
63
10/16
✓ Branch 73 → 74 taken 35316 times.
✓ Branch 73 → 88 taken 26822 times.
✓ Branch 81 → 82 taken 8 times.
✗ Branch 81 → 119 not taken.
✓ Branch 82 → 83 taken 8 times.
✗ Branch 82 → 88 not taken.
✓ Branch 83 → 84 taken 8 times.
✗ Branch 83 → 119 not taken.
✓ Branch 84 → 85 taken 8 times.
✗ Branch 84 → 119 not taken.
✓ Branch 85 → 86 taken 8 times.
✗ Branch 85 → 119 not taken.
✓ Branch 86 → 87 taken 8 times.
✗ Branch 86 → 88 not taken.
✓ Branch 89 → 90 taken 8 times.
✓ Branch 89 → 94 taken 62130 times.
97454 lhs.entry->isInitialized() && lhsType.getContained().matches(rhsType.removeReferenceWrapper(), false, true, true))
64
2/4
✓ Branch 90 → 91 taken 8 times.
✗ Branch 90 → 122 not taken.
✓ Branch 91 → 92 taken 8 times.
✗ Branch 91 → 122 not taken.
8 return performStructAssign(node, lhs, rhs, lhsType.getContained(), isDecl, isReturn);
65
66 // Check common type combinations
67
2/2
✓ Branch 94 → 95 taken 62128 times.
✓ Branch 94 → 123 taken 2 times.
62130 const QualType resultType = getAssignResultTypeCommon(node, lhs, rhs, isDecl, isReturn);
68
3/4
✓ Branch 95 → 96 taken 62128 times.
✗ Branch 95 → 123 not taken.
✓ Branch 96 → 97 taken 3110 times.
✓ Branch 96 → 99 taken 59018 times.
62128 if (!resultType.is(TY_INVALID))
69 3110 return {resultType, nullptr};
70
71 // Check primitive type combinations
72 59018 const QualType binOpType =
73
2/2
✓ Branch 99 → 100 taken 59005 times.
✓ Branch 99 → 123 taken 13 times.
59018 validateBinaryOperation(node, ASSIGN_OP_RULES, std::size(ASSIGN_OP_RULES), "=", lhsType, rhsType, true, errMsgPrefix);
74 59005 return {binOpType, nullptr};
75 }
76
77 1729 std::pair<QualType, Function *> OpRuleManager::getFieldAssignResultType(ASTNode *node, const ExprResult &lhs,
78 const ExprResult &rhs, bool imm, bool isDecl) const {
79 // Retrieve types
80 1729 const QualType lhsType = lhs.type;
81 1729 const QualType rhsType = rhs.type;
82
2/4
✓ Branch 2 → 3 taken 1729 times.
✗ Branch 2 → 101 not taken.
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 1729 times.
1729 assert(!lhsType.is(TY_DYN));
83
84 // Check if we try to assign a constant value
85
1/2
✓ Branch 5 → 6 taken 1729 times.
✗ Branch 5 → 101 not taken.
1729 ensureNoConstAssign(node, lhsType, isDecl);
86
87 // Allow pointers, arrays and structs of the same type straight away
88
8/10
✓ Branch 6 → 7 taken 1729 times.
✗ Branch 6 → 92 not taken.
✓ Branch 7 → 8 taken 1114 times.
✓ Branch 7 → 11 taken 615 times.
✓ Branch 8 → 9 taken 1114 times.
✗ Branch 8 → 92 not taken.
✓ Branch 9 → 10 taken 1112 times.
✓ Branch 9 → 11 taken 2 times.
✓ Branch 12 → 13 taken 1112 times.
✓ Branch 12 → 30 taken 617 times.
1729 if (lhsType.isOneOf({TY_PTR, TY_ARRAY}) && lhsType == rhsType) {
89 // If we perform a heap x* = heap x* assignment, we need set the right hand side to MOVED
90
8/22
✓ Branch 13 → 14 taken 264 times.
✓ Branch 13 → 24 taken 848 times.
✓ Branch 14 → 15 taken 264 times.
✗ Branch 14 → 93 not taken.
✓ Branch 15 → 16 taken 262 times.
✓ Branch 15 → 24 taken 2 times.
✓ Branch 16 → 17 taken 262 times.
✗ Branch 16 → 93 not taken.
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 24 taken 262 times.
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 93 not taken.
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 93 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 24 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 93 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())
91 rhs.entry->updateState(MOVED, node);
92 1112 return {rhsType, nullptr};
93 }
94 // Allow struct of the same type straight away
95
8/10
✓ Branch 30 → 31 taken 617 times.
✗ Branch 30 → 101 not taken.
✓ Branch 31 → 32 taken 50 times.
✓ Branch 31 → 35 taken 567 times.
✓ Branch 32 → 33 taken 50 times.
✗ Branch 32 → 101 not taken.
✓ Branch 33 → 34 taken 46 times.
✓ Branch 33 → 35 taken 4 times.
✓ Branch 36 → 37 taken 46 times.
✓ Branch 36 → 39 taken 571 times.
617 if (lhsType.is(TY_STRUCT) && lhsType.matches(rhsType, false, true, true))
96
1/2
✓ Branch 37 → 38 taken 46 times.
✗ Branch 37 → 101 not taken.
46 return performStructAssign(node, lhs, rhs, rhsType, isDecl, false);
97 // Allow ref type to type of the same contained type straight away
98
9/12
✓ Branch 39 → 40 taken 571 times.
✗ Branch 39 → 95 not taken.
✓ Branch 40 → 41 taken 21 times.
✓ Branch 40 → 45 taken 550 times.
✓ Branch 41 → 42 taken 21 times.
✗ Branch 41 → 95 not taken.
✓ Branch 42 → 43 taken 21 times.
✗ Branch 42 → 95 not taken.
✓ Branch 43 → 44 taken 1 time.
✓ Branch 43 → 45 taken 20 times.
✓ Branch 46 → 47 taken 1 time.
✓ Branch 46 → 64 taken 570 times.
571 if (rhsType.isRef() && lhsType.matches(rhsType.getContained(), false, false, true)) {
99 // Check is there is an overloaded operator function available
100
1/2
✓ Branch 47 → 48 taken 1 time.
✗ Branch 47 → 96 not taken.
1 const auto [type, _] = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_ASSIGN, {lhs, rhs}, 0);
101
2/4
✓ Branch 48 → 49 taken 1 time.
✗ Branch 48 → 98 not taken.
✗ Branch 49 → 50 not taken.
✓ Branch 49 → 52 taken 1 time.
1 if (!type.is(TY_INVALID))
102 return {type, nullptr};
103
104 // In case of a return expression, we perform temp stealing
105 1 Function *copyCtor = nullptr;
106
4/10
✓ Branch 52 → 53 taken 1 time.
✗ Branch 52 → 97 not taken.
✓ Branch 53 → 54 taken 1 time.
✗ Branch 53 → 97 not taken.
✗ Branch 54 → 55 not taken.
✓ Branch 54 → 58 taken 1 time.
✗ Branch 56 → 57 not taken.
✗ Branch 56 → 58 not taken.
✗ Branch 59 → 60 not taken.
✓ Branch 59 → 62 taken 1 time.
1 if (rhsType.getContained().is(TY_STRUCT) && !rhs.isTemporary())
107 copyCtor = typeChecker->implicitlyCallStructCopyCtor(rhs.entry, rhs.entry->declNode);
108 1 return {lhsType, copyCtor};
109 }
110 // Allow ref type to type of the same contained type straight away
111
3/4
✓ Branch 64 → 65 taken 570 times.
✗ Branch 64 → 101 not taken.
✓ Branch 65 → 66 taken 20 times.
✓ Branch 65 → 74 taken 550 times.
570 if (rhsType.isRef()) {
112 // If this is const ref, remove both: the reference and the constness
113
2/4
✓ Branch 66 → 67 taken 20 times.
✗ Branch 66 → 99 not taken.
✓ Branch 67 → 68 taken 20 times.
✗ Branch 67 → 99 not taken.
20 const QualType rhsNonRef = rhsType.getContained().toNonConst();
114
2/4
✓ Branch 68 → 69 taken 20 times.
✗ Branch 68 → 100 not taken.
✓ Branch 69 → 70 taken 20 times.
✗ Branch 69 → 72 not taken.
20 if (lhsType.matches(rhsNonRef, false, false, true))
115
1/2
✓ Branch 70 → 71 taken 20 times.
✗ Branch 70 → 100 not taken.
20 return performStructAssign(node, lhs, rhs, rhsNonRef, isDecl, false);
116 }
117 // Allow immediate value to const ref of the same contained type straight away
118
6/8
✓ Branch 74 → 75 taken 550 times.
✗ Branch 74 → 101 not taken.
✓ Branch 75 → 76 taken 1 time.
✓ Branch 75 → 78 taken 549 times.
✓ Branch 76 → 77 taken 1 time.
✗ Branch 76 → 78 not taken.
✓ Branch 79 → 80 taken 1 time.
✓ Branch 79 → 82 taken 549 times.
550 if (lhsType.isConstRef() && imm)
119 1 return {rhsType, nullptr};
120
121 // Check common type combinations
122
1/2
✓ Branch 82 → 83 taken 549 times.
✗ Branch 82 → 101 not taken.
549 const QualType resultType = getAssignResultTypeCommon(node, lhs, rhs, isDecl, false);
123
3/4
✓ Branch 83 → 84 taken 549 times.
✗ Branch 83 → 101 not taken.
✓ Branch 84 → 85 taken 4 times.
✓ Branch 84 → 87 taken 545 times.
549 if (!resultType.is(TY_INVALID))
124 4 return {resultType, nullptr};
125
126 // Check primitive type combinations
127 545 const QualType binOpType =
128
2/2
✓ Branch 87 → 88 taken 544 times.
✓ Branch 87 → 101 taken 1 time.
545 validateBinaryOperation(node, ASSIGN_OP_RULES, std::size(ASSIGN_OP_RULES), "=", lhsType, rhsType, true, ERROR_FIELD_ASSIGN);
129 544 return {binOpType, nullptr};
130 }
131
132 62679 QualType OpRuleManager::getAssignResultTypeCommon(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, bool isDecl,
133 bool isReturn) {
134 // Retrieve types
135 62679 const QualType lhsType = lhs.type;
136 62679 const QualType rhsType = rhs.type;
137
138 // Allow type to ref type of the same contained type straight away
139
9/12
✓ Branch 2 → 3 taken 62679 times.
✗ Branch 2 → 112 not taken.
✓ Branch 3 → 4 taken 2575 times.
✓ Branch 3 → 8 taken 60104 times.
✓ Branch 4 → 5 taken 2575 times.
✗ Branch 4 → 112 not taken.
✓ Branch 5 → 6 taken 2575 times.
✗ Branch 5 → 112 not taken.
✓ Branch 6 → 7 taken 2567 times.
✓ Branch 6 → 8 taken 8 times.
✓ Branch 9 → 10 taken 2567 times.
✓ Branch 9 → 44 taken 60112 times.
62679 if (lhsType.isRef() && lhsType.getContained().matches(rhsType, false, false, true)) {
140
4/4
✓ Branch 10 → 11 taken 1558 times.
✓ Branch 10 → 12 taken 1009 times.
✓ Branch 11 → 12 taken 1191 times.
✓ Branch 11 → 13 taken 367 times.
2567 const bool isDeclOrReturn = isDecl || isReturn;
141
7/8
✓ Branch 14 → 15 taken 2200 times.
✓ Branch 14 → 19 taken 367 times.
✓ Branch 16 → 17 taken 2200 times.
✗ Branch 16 → 136 not taken.
✓ Branch 17 → 18 taken 1 time.
✓ Branch 17 → 19 taken 2199 times.
✓ Branch 20 → 21 taken 1 time.
✓ Branch 20 → 29 taken 2566 times.
2567 if (isDeclOrReturn && !lhsType.canBind(rhsType, rhs.isTemporary()))
142
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");
143
6/6
✓ Branch 29 → 30 taken 1191 times.
✓ Branch 29 → 33 taken 1375 times.
✓ Branch 31 → 32 taken 1 time.
✓ Branch 31 → 33 taken 1190 times.
✓ Branch 34 → 35 taken 1 time.
✓ Branch 34 → 43 taken 2565 times.
2566 if (isReturn && rhs.isTemporary())
144
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");
145 2565 return lhsType;
146 }
147 // Allow char* = string
148
9/14
✓ Branch 44 → 45 taken 60112 times.
✗ Branch 44 → 136 not taken.
✓ Branch 45 → 46 taken 1 time.
✓ Branch 45 → 53 taken 60111 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 60111 times.
60112 if (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING) && lhsType.getQualifiers() == rhsType.getQualifiers())
149 1 return lhsType;
150 // Allow array to pointer
151
12/18
✓ Branch 56 → 57 taken 60111 times.
✗ Branch 56 → 131 not taken.
✓ Branch 57 → 58 taken 544 times.
✓ Branch 57 → 65 taken 59567 times.
✓ Branch 58 → 59 taken 544 times.
✗ Branch 58 → 131 not taken.
✓ Branch 59 → 60 taken 7 times.
✓ Branch 59 → 65 taken 537 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 60104 times.
60111 if (lhsType.isPtr() && rhsType.isArray() && lhsType.getContained().matches(rhsType.getContained(), false, false, true))
152 7 return lhsType;
153 // Allow interface* = struct* or interface& = struct that implements this interface
154
1/2
✓ Branch 70 → 71 taken 60104 times.
✗ Branch 70 → 136 not taken.
60104 const bool sameChainDepth = Type::hasSameTypeChainDepth(lhsType.getType(), rhsType.getType());
155
10/14
✓ Branch 71 → 72 taken 60104 times.
✗ Branch 71 → 136 not taken.
✓ Branch 72 → 73 taken 537 times.
✓ Branch 72 → 76 taken 59567 times.
✓ Branch 73 → 74 taken 537 times.
✗ Branch 73 → 136 not taken.
✓ Branch 74 → 75 taken 536 times.
✓ Branch 74 → 76 taken 1 time.
✗ Branch 75 → 76 not taken.
✓ Branch 75 → 78 taken 536 times.
✓ Branch 76 → 77 taken 59568 times.
✗ Branch 76 → 136 not taken.
✓ Branch 77 → 78 taken 8 times.
✓ Branch 77 → 79 taken 59560 times.
60104 const bool typesCompatible = (lhsType.isPtr() && rhsType.isPtr() && sameChainDepth) || lhsType.isRef();
156
9/12
✓ Branch 80 → 81 taken 544 times.
✓ Branch 80 → 86 taken 59560 times.
✓ Branch 81 → 82 taken 544 times.
✗ Branch 81 → 136 not taken.
✓ Branch 82 → 83 taken 61 times.
✓ Branch 82 → 86 taken 483 times.
✓ Branch 83 → 84 taken 61 times.
✗ Branch 83 → 136 not taken.
✓ Branch 84 → 85 taken 61 times.
✗ Branch 84 → 86 not taken.
✓ Branch 87 → 88 taken 61 times.
✓ Branch 87 → 93 taken 60043 times.
60104 if (typesCompatible && lhsType.isBase(TY_INTERFACE) && rhsType.isBase(TY_STRUCT)) {
157 61 QualType lhsTypeCopy = lhsType;
158 61 QualType rhsTypeCopy = rhsType;
159
1/2
✓ Branch 88 → 89 taken 61 times.
✗ Branch 88 → 133 not taken.
61 QualType::unwrapBothWithRefWrappers(lhsTypeCopy, rhsTypeCopy);
160
2/4
✓ Branch 89 → 90 taken 61 times.
✗ Branch 89 → 133 not taken.
✓ Branch 90 → 91 taken 61 times.
✗ Branch 90 → 92 not taken.
61 if (lhsTypeCopy.matchesInterfaceImplementedByStruct(rhsTypeCopy))
161 61 return lhsType;
162 }
163 // Allow type* = heap type* straight away. This is used for initializing non-owning pointers to heap allocations
164
10/14
✓ Branch 93 → 94 taken 60043 times.
✗ Branch 93 → 136 not taken.
✓ Branch 94 → 95 taken 482 times.
✓ Branch 94 → 100 taken 59561 times.
✓ Branch 95 → 96 taken 482 times.
✗ Branch 95 → 136 not taken.
✓ Branch 96 → 97 taken 480 times.
✓ Branch 96 → 100 taken 2 times.
✓ Branch 97 → 98 taken 480 times.
✗ Branch 97 → 136 not taken.
✓ Branch 98 → 99 taken 480 times.
✗ Branch 98 → 100 not taken.
✓ Branch 101 → 102 taken 480 times.
✓ Branch 101 → 108 taken 59563 times.
60043 if (lhsType.isPtr() && rhsType.isHeap() && lhsType.matches(rhsType, false, true, true)) {
165 480 TypeQualifiers rhsQualifiers = rhsType.getQualifiers();
166 480 rhsQualifiers.isHeap = false;
167
2/4
✓ Branch 104 → 105 taken 480 times.
✗ Branch 104 → 134 not taken.
✓ Branch 105 → 106 taken 480 times.
✗ Branch 105 → 107 not taken.
480 if (lhsType.getQualifiers() == rhsQualifiers)
168 480 return lhsType;
169 }
170
171 // Nothing matched
172
1/2
✓ Branch 108 → 109 taken 59563 times.
✗ Branch 108 → 135 not taken.
59563 return QualType(TY_INVALID);
173 }
174
175 14255 std::pair<QualType, Function *> OpRuleManager::performStructAssign(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs,
176 const QualType &rhsType, bool isDecl, bool isReturn) const {
177 14255 const bool rhsIsRef = rhs.type.isRef();
178
179 // Check is there is an overloaded operator function available
180
8/8
✓ Branch 3 → 4 taken 8757 times.
✓ Branch 3 → 8 taken 5498 times.
✓ Branch 4 → 5 taken 1235 times.
✓ Branch 4 → 8 taken 7522 times.
✓ Branch 6 → 7 taken 658 times.
✓ Branch 6 → 8 taken 577 times.
✓ Branch 9 → 10 taken 658 times.
✓ Branch 9 → 16 taken 13597 times.
14255 if (!isDecl && !isReturn && lhs.entry->isInitialized()) {
181
1/2
✓ Branch 10 → 11 taken 658 times.
✗ Branch 10 → 44 not taken.
658 const auto [type, _] = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_ASSIGN, {lhs, rhs}, 0);
182
3/4
✓ Branch 11 → 12 taken 658 times.
✗ Branch 11 → 45 not taken.
✓ Branch 12 → 13 taken 503 times.
✓ Branch 12 → 15 taken 155 times.
658 if (!type.is(TY_INVALID))
183 503 return {type, nullptr};
184 }
185
186 // If temp stealing is possible, delete any rhs anonymous entry
187
6/6
✓ Branch 16 → 17 taken 12899 times.
✓ Branch 16 → 20 taken 853 times.
✓ Branch 18 → 19 taken 12052 times.
✓ Branch 18 → 20 taken 847 times.
✓ Branch 21 → 22 taken 12052 times.
✓ Branch 21 → 27 taken 1700 times.
13752 if (!rhsIsRef && rhs.isTemporary()) {
188
3/4
✓ Branch 22 → 23 taken 7917 times.
✓ Branch 22 → 25 taken 4135 times.
✓ Branch 23 → 24 taken 7917 times.
✗ Branch 23 → 25 not taken.
12052 if (rhs.entry != nullptr && rhs.entry->anonymous)
189 7917 typeChecker->currentScope->symbolTable.deleteAnonymous(rhs.entry->name);
190 12052 return {rhsType, nullptr};
191 }
192
193 // If RVO is possible, cancel here
194
7/8
✓ Branch 27 → 28 taken 847 times.
✓ Branch 27 → 32 taken 853 times.
✓ Branch 28 → 29 taken 521 times.
✓ Branch 28 → 32 taken 326 times.
✓ Branch 30 → 31 taken 521 times.
✗ Branch 30 → 32 not taken.
✓ Branch 33 → 34 taken 521 times.
✓ Branch 33 → 36 taken 1179 times.
1700 if (!rhsIsRef && isReturn && !rhs.isTemporary())
195 521 return {rhsType, nullptr};
196
197 // => We have to copy
198 // If struct, try to call copy ctor
199
2/2
✓ Branch 37 → 38 taken 1163 times.
✓ Branch 37 → 41 taken 16 times.
1179 if (rhsType.is(TY_STRUCT))
200
1/2
✓ Branch 38 → 39 taken 1163 times.
✗ Branch 38 → 46 not taken.
1163 return {rhsType, typeChecker->implicitlyCallStructCopyCtor(rhsType, node)};
201
202 // Perform shallow copy
203 16 return {rhsType, nullptr};
204 }
205
206 1983 ExprResult OpRuleManager::getPlusEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
207 // Check is there is an overloaded operator function available
208
1/2
✓ Branch 2 → 3 taken 1983 times.
✗ Branch 2 → 22 not taken.
1983 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_PLUS_EQUAL, {lhs, rhs}, 0);
209
3/4
✓ Branch 3 → 4 taken 1983 times.
✗ Branch 3 → 24 not taken.
✓ Branch 4 → 5 taken 716 times.
✓ Branch 4 → 6 taken 1267 times.
1983 if (!resultType.type.is(TY_INVALID))
210 716 return resultType;
211
212 // Check if we try to assign a constant value
213
1/2
✓ Branch 6 → 7 taken 1267 times.
✗ Branch 6 → 24 not taken.
1267 ensureNoConstAssign(node, lhs.type);
214
215 // Remove reference wrappers
216
1/2
✓ Branch 7 → 8 taken 1267 times.
✗ Branch 7 → 24 not taken.
1267 const QualType lhsType = lhs.type.removeReferenceWrapper();
217
1/2
✓ Branch 8 → 9 taken 1267 times.
✗ Branch 8 → 24 not taken.
1267 const QualType rhsType = rhs.type.removeReferenceWrapper();
218
219 // Check if this is an unsafe operation
220
7/10
✓ Branch 9 → 10 taken 1267 times.
✗ Branch 9 → 23 not taken.
✓ Branch 10 → 11 taken 166 times.
✓ Branch 10 → 14 taken 1101 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 1101 times.
1267 if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) {
221
1/2
✓ Branch 16 → 17 taken 166 times.
✗ Branch 16 → 24 not taken.
166 ensureUnsafeAllowed(node, "+=", lhsType, rhsType);
222 166 return lhs;
223 }
224
225
1/2
✓ Branch 18 → 19 taken 1101 times.
✗ Branch 18 → 24 not taken.
1101 return {validateBinaryOperation(node, PLUS_EQUAL_OP_RULES, std::size(PLUS_EQUAL_OP_RULES), "+=", lhsType, rhsType)};
226 }
227
228 90 ExprResult OpRuleManager::getMinusEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
229 // Check is there is an overloaded operator function available
230
1/2
✓ Branch 2 → 3 taken 90 times.
✗ Branch 2 → 22 not taken.
90 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MINUS_EQUAL, {lhs, rhs}, 0);
231
3/4
✓ Branch 3 → 4 taken 90 times.
✗ Branch 3 → 24 not taken.
✓ Branch 4 → 5 taken 7 times.
✓ Branch 4 → 6 taken 83 times.
90 if (!resultType.type.is(TY_INVALID))
232 7 return resultType;
233
234 // Check if we try to assign a constant value
235
1/2
✓ Branch 6 → 7 taken 83 times.
✗ Branch 6 → 24 not taken.
83 ensureNoConstAssign(node, lhs.type);
236
237 // Remove reference wrappers
238
1/2
✓ Branch 7 → 8 taken 83 times.
✗ Branch 7 → 24 not taken.
83 const QualType lhsType = lhs.type.removeReferenceWrapper();
239
1/2
✓ Branch 8 → 9 taken 83 times.
✗ Branch 8 → 24 not taken.
83 const QualType rhsType = rhs.type.removeReferenceWrapper();
240
241 // Check if this is an unsafe operation
242
7/10
✓ Branch 9 → 10 taken 83 times.
✗ Branch 9 → 23 not taken.
✓ Branch 10 → 11 taken 5 times.
✓ Branch 10 → 14 taken 78 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 78 times.
83 if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) {
243
1/2
✓ Branch 16 → 17 taken 5 times.
✗ Branch 16 → 24 not taken.
5 ensureUnsafeAllowed(node, "-=", lhsType, rhsType);
244 5 return lhs;
245 }
246
247
1/2
✓ Branch 18 → 19 taken 78 times.
✗ Branch 18 → 24 not taken.
78 return {validateBinaryOperation(node, MINUS_EQUAL_OP_RULES, std::size(MINUS_EQUAL_OP_RULES), "-=", lhsType, rhsType)};
248 }
249
250 258 ExprResult OpRuleManager::getMulEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
251 // Check is there is an overloaded operator function available
252
1/2
✓ Branch 2 → 3 taken 258 times.
✗ Branch 2 → 13 not taken.
258 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MUL_EQUAL, {lhs, rhs}, 0);
253
3/4
✓ Branch 3 → 4 taken 258 times.
✗ Branch 3 → 14 not taken.
✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 6 taken 256 times.
258 if (!resultType.type.is(TY_INVALID))
254 2 return resultType;
255
256 // Check if we try to assign a constant value
257
1/2
✓ Branch 6 → 7 taken 256 times.
✗ Branch 6 → 14 not taken.
256 ensureNoConstAssign(node, lhs.type);
258
259 // Remove reference wrappers
260
1/2
✓ Branch 7 → 8 taken 256 times.
✗ Branch 7 → 14 not taken.
256 const QualType lhsType = lhs.type.removeReferenceWrapper();
261
1/2
✓ Branch 8 → 9 taken 256 times.
✗ Branch 8 → 14 not taken.
256 const QualType rhsType = rhs.type.removeReferenceWrapper();
262
263
1/2
✓ Branch 9 → 10 taken 256 times.
✗ Branch 9 → 14 not taken.
256 return {validateBinaryOperation(node, MUL_EQUAL_OP_RULES, std::size(MUL_EQUAL_OP_RULES), "*=", lhsType, rhsType)};
264 }
265
266 108 ExprResult OpRuleManager::getDivEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
267 // Check is there is an overloaded operator function available
268
1/2
✓ Branch 2 → 3 taken 108 times.
✗ Branch 2 → 13 not taken.
108 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_DIV_EQUAL, {lhs, rhs}, 0);
269
3/4
✓ Branch 3 → 4 taken 108 times.
✗ Branch 3 → 14 not taken.
✓ Branch 4 → 5 taken 62 times.
✓ Branch 4 → 6 taken 46 times.
108 if (!resultType.type.is(TY_INVALID))
270 62 return resultType;
271
272 // Check if we try to assign a constant value
273
1/2
✓ Branch 6 → 7 taken 46 times.
✗ Branch 6 → 14 not taken.
46 ensureNoConstAssign(node, lhs.type);
274
275 // Remove reference wrappers
276
1/2
✓ Branch 7 → 8 taken 46 times.
✗ Branch 7 → 14 not taken.
46 const QualType lhsType = lhs.type.removeReferenceWrapper();
277
1/2
✓ Branch 8 → 9 taken 46 times.
✗ Branch 8 → 14 not taken.
46 const QualType rhsType = rhs.type.removeReferenceWrapper();
278
279
1/2
✓ Branch 9 → 10 taken 46 times.
✗ Branch 9 → 14 not taken.
46 return {validateBinaryOperation(node, DIV_EQUAL_OP_RULES, std::size(DIV_EQUAL_OP_RULES), "/=", lhsType, rhsType)};
280 }
281
282 46 QualType OpRuleManager::getRemEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
283 // Check if we try to assign a constant value
284
1/2
✓ Branch 2 → 3 taken 46 times.
✗ Branch 2 → 9 not taken.
46 ensureNoConstAssign(node, lhs.type);
285
286 // Remove reference wrappers
287
1/2
✓ Branch 3 → 4 taken 46 times.
✗ Branch 3 → 9 not taken.
46 const QualType lhsType = lhs.type.removeReferenceWrapper();
288
1/2
✓ Branch 4 → 5 taken 46 times.
✗ Branch 4 → 9 not taken.
46 const QualType rhsType = rhs.type.removeReferenceWrapper();
289
290
1/2
✓ Branch 5 → 6 taken 46 times.
✗ Branch 5 → 9 not taken.
92 return validateBinaryOperation(node, REM_EQUAL_OP_RULES, std::size(REM_EQUAL_OP_RULES), "%=", lhsType, rhsType);
291 }
292
293 12 QualType OpRuleManager::getSHLEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
294 // Check if we try to assign a constant value
295
1/2
✓ Branch 2 → 3 taken 12 times.
✗ Branch 2 → 9 not taken.
12 ensureNoConstAssign(node, lhs.type);
296
297 // Remove reference wrappers
298
1/2
✓ Branch 3 → 4 taken 12 times.
✗ Branch 3 → 9 not taken.
12 const QualType lhsType = lhs.type.removeReferenceWrapper();
299
1/2
✓ Branch 4 → 5 taken 12 times.
✗ Branch 4 → 9 not taken.
12 const QualType rhsType = rhs.type.removeReferenceWrapper();
300
301
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);
302 }
303
304 17 QualType OpRuleManager::getSHREqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
305 // Check if we try to assign a constant value
306
1/2
✓ Branch 2 → 3 taken 17 times.
✗ Branch 2 → 9 not taken.
17 ensureNoConstAssign(node, lhs.type);
307
308 // Remove reference wrappers
309
1/2
✓ Branch 3 → 4 taken 17 times.
✗ Branch 3 → 9 not taken.
17 const QualType lhsType = lhs.type.removeReferenceWrapper();
310
1/2
✓ Branch 4 → 5 taken 17 times.
✗ Branch 4 → 9 not taken.
17 const QualType rhsType = rhs.type.removeReferenceWrapper();
311
312
1/2
✓ Branch 5 → 6 taken 17 times.
✗ Branch 5 → 9 not taken.
34 return validateBinaryOperation(node, SHR_EQUAL_OP_RULES, std::size(SHR_EQUAL_OP_RULES), ">>=", lhsType, rhsType);
313 }
314
315 28 QualType OpRuleManager::getAndEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
316 // Check if we try to assign a constant value
317
1/2
✓ Branch 2 → 3 taken 28 times.
✗ Branch 2 → 9 not taken.
28 ensureNoConstAssign(node, lhs.type);
318
319 // Remove reference wrappers
320
1/2
✓ Branch 3 → 4 taken 28 times.
✗ Branch 3 → 9 not taken.
28 const QualType lhsType = lhs.type.removeReferenceWrapper();
321
1/2
✓ Branch 4 → 5 taken 28 times.
✗ Branch 4 → 9 not taken.
28 const QualType rhsType = rhs.type.removeReferenceWrapper();
322
323
1/2
✓ Branch 5 → 6 taken 28 times.
✗ Branch 5 → 9 not taken.
56 return validateBinaryOperation(node, AND_EQUAL_OP_RULES, std::size(AND_EQUAL_OP_RULES), "&=", lhsType, rhsType);
324 }
325
326 28 QualType OpRuleManager::getOrEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
327 // Check if we try to assign a constant value
328
1/2
✓ Branch 2 → 3 taken 28 times.
✗ Branch 2 → 9 not taken.
28 ensureNoConstAssign(node, lhs.type);
329
330 // Remove reference wrappers
331
1/2
✓ Branch 3 → 4 taken 28 times.
✗ Branch 3 → 9 not taken.
28 const QualType lhsType = lhs.type.removeReferenceWrapper();
332
1/2
✓ Branch 4 → 5 taken 28 times.
✗ Branch 4 → 9 not taken.
28 const QualType rhsType = rhs.type.removeReferenceWrapper();
333
334
1/2
✓ Branch 5 → 6 taken 28 times.
✗ Branch 5 → 9 not taken.
56 return validateBinaryOperation(node, OR_EQUAL_OP_RULES, std::size(OR_EQUAL_OP_RULES), "|=", lhsType, rhsType);
335 }
336
337 349 QualType OpRuleManager::getXorEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
338 // Check if we try to assign a constant value
339
1/2
✓ Branch 2 → 3 taken 349 times.
✗ Branch 2 → 9 not taken.
349 ensureNoConstAssign(node, lhs.type);
340
341 // Remove reference wrappers
342
1/2
✓ Branch 3 → 4 taken 349 times.
✗ Branch 3 → 9 not taken.
349 const QualType lhsType = lhs.type.removeReferenceWrapper();
343
1/2
✓ Branch 4 → 5 taken 349 times.
✗ Branch 4 → 9 not taken.
349 const QualType rhsType = rhs.type.removeReferenceWrapper();
344
345
1/2
✓ Branch 5 → 6 taken 349 times.
✗ Branch 5 → 9 not taken.
698 return validateBinaryOperation(node, XOR_EQUAL_OP_RULES, std::size(XOR_EQUAL_OP_RULES), "^=", lhsType, rhsType);
346 }
347
348 3325 QualType OpRuleManager::getLogicalOrResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
349 // Remove reference wrappers
350
1/2
✓ Branch 2 → 3 taken 3325 times.
✗ Branch 2 → 8 not taken.
3325 const QualType lhsType = lhs.type.removeReferenceWrapper();
351
1/2
✓ Branch 3 → 4 taken 3325 times.
✗ Branch 3 → 8 not taken.
3325 const QualType rhsType = rhs.type.removeReferenceWrapper();
352
353
2/2
✓ Branch 4 → 5 taken 3324 times.
✓ Branch 4 → 8 taken 1 time.
6649 return validateBinaryOperation(node, LOGICAL_OR_OP_RULES, std::size(LOGICAL_OR_OP_RULES), "||", lhsType, rhsType);
354 }
355
356 2033 QualType OpRuleManager::getLogicalAndResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
357 // Remove reference wrappers
358
1/2
✓ Branch 2 → 3 taken 2033 times.
✗ Branch 2 → 8 not taken.
2033 const QualType lhsType = lhs.type.removeReferenceWrapper();
359
1/2
✓ Branch 3 → 4 taken 2033 times.
✗ Branch 3 → 8 not taken.
2033 const QualType rhsType = rhs.type.removeReferenceWrapper();
360
361
1/2
✓ Branch 4 → 5 taken 2033 times.
✗ Branch 4 → 8 not taken.
4066 return validateBinaryOperation(node, LOGICAL_AND_OP_RULES, std::size(LOGICAL_AND_OP_RULES), "&&", lhsType, rhsType);
362 }
363
364 388 ExprResult OpRuleManager::getBitwiseOrResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs,
365 size_t opIdx) const {
366 // Check if there is an overloaded operator function available
367
1/2
✓ Branch 2 → 3 taken 388 times.
✗ Branch 2 → 12 not taken.
388 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_BITWISE_OR, {lhs, rhs}, opIdx);
368
3/4
✓ Branch 3 → 4 taken 388 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 4 times.
✓ Branch 4 → 6 taken 384 times.
388 if (!resultType.type.is(TY_INVALID))
369 4 return resultType;
370
371 // Remove reference wrappers
372
1/2
✓ Branch 6 → 7 taken 384 times.
✗ Branch 6 → 13 not taken.
384 const QualType lhsType = lhs.type.removeReferenceWrapper();
373
1/2
✓ Branch 7 → 8 taken 384 times.
✗ Branch 7 → 13 not taken.
384 const QualType rhsType = rhs.type.removeReferenceWrapper();
374
375
2/2
✓ Branch 8 → 9 taken 383 times.
✓ Branch 8 → 13 taken 1 time.
384 return {validateBinaryOperation(node, BITWISE_OR_OP_RULES, std::size(BITWISE_OR_OP_RULES), "|", lhsType, rhsType)};
376 }
377
378 78 ExprResult OpRuleManager::getBitwiseXorResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs,
379 size_t opIdx) const {
380 // Check if there is an overloaded operator function available
381
1/2
✓ Branch 2 → 3 taken 78 times.
✗ Branch 2 → 12 not taken.
78 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_BITWISE_XOR, {lhs, rhs}, opIdx);
382
3/4
✓ Branch 3 → 4 taken 78 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 3 times.
✓ Branch 4 → 6 taken 75 times.
78 if (!resultType.type.is(TY_INVALID))
383 3 return resultType;
384
385 // Remove reference wrappers
386
1/2
✓ Branch 6 → 7 taken 75 times.
✗ Branch 6 → 13 not taken.
75 const QualType lhsType = lhs.type.removeReferenceWrapper();
387
1/2
✓ Branch 7 → 8 taken 75 times.
✗ Branch 7 → 13 not taken.
75 const QualType rhsType = rhs.type.removeReferenceWrapper();
388
389
1/2
✓ Branch 8 → 9 taken 75 times.
✗ Branch 8 → 13 not taken.
75 return {validateBinaryOperation(node, BITWISE_XOR_OP_RULES, std::size(BITWISE_XOR_OP_RULES), "^", lhsType, rhsType)};
390 }
391
392 339 ExprResult OpRuleManager::getBitwiseAndResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs,
393 size_t opIdx) const {
394 // Check if there is an overloaded operator function available
395
1/2
✓ Branch 2 → 3 taken 339 times.
✗ Branch 2 → 12 not taken.
339 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_BITWISE_AND, {lhs, rhs}, opIdx);
396
3/4
✓ Branch 3 → 4 taken 339 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 4 times.
✓ Branch 4 → 6 taken 335 times.
339 if (!resultType.type.is(TY_INVALID))
397 4 return resultType;
398
399 // Remove reference wrappers
400
1/2
✓ Branch 6 → 7 taken 335 times.
✗ Branch 6 → 13 not taken.
335 const QualType lhsType = lhs.type.removeReferenceWrapper();
401
1/2
✓ Branch 7 → 8 taken 335 times.
✗ Branch 7 → 13 not taken.
335 const QualType rhsType = rhs.type.removeReferenceWrapper();
402
403
1/2
✓ Branch 8 → 9 taken 335 times.
✗ Branch 8 → 13 not taken.
335 return {validateBinaryOperation(node, BITWISE_AND_OP_RULES, std::size(BITWISE_AND_OP_RULES), "&", lhsType, rhsType)};
404 }
405
406 18991 ExprResult OpRuleManager::getEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
407 // Check is there is an overloaded operator function available
408
1/2
✓ Branch 2 → 3 taken 18991 times.
✗ Branch 2 → 36 not taken.
18991 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_EQUAL, {lhs, rhs}, 0);
409
3/4
✓ Branch 3 → 4 taken 18991 times.
✗ Branch 3 → 37 not taken.
✓ Branch 4 → 5 taken 1595 times.
✓ Branch 4 → 6 taken 17396 times.
18991 if (!resultType.type.is(TY_INVALID))
410 1595 return resultType;
411
412 // Remove reference wrappers
413
1/2
✓ Branch 6 → 7 taken 17396 times.
✗ Branch 6 → 37 not taken.
17396 const QualType lhsType = lhs.type.removeReferenceWrapper();
414
1/2
✓ Branch 7 → 8 taken 17396 times.
✗ Branch 7 → 37 not taken.
17396 const QualType rhsType = rhs.type.removeReferenceWrapper();
415
416 // Allow 'pointer == unsigned long' straight away
417
10/14
✓ Branch 8 → 9 taken 17396 times.
✗ Branch 8 → 37 not taken.
✓ Branch 9 → 10 taken 3428 times.
✓ Branch 9 → 15 taken 13968 times.
✓ Branch 10 → 11 taken 3428 times.
✗ Branch 10 → 37 not taken.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 15 taken 3427 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 17395 times.
17396 if (lhsType.isPtr() && rhsType.is(TY_LONG) && rhsType.isUnsigned())
418
1/2
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 37 not taken.
1 return ExprResult(QualType(TY_BOOL));
419
420 // Allow 'string == char*' and vice versa straight away
421
13/18
✓ Branch 19 → 20 taken 17395 times.
✗ Branch 19 → 37 not taken.
✓ Branch 20 → 21 taken 398 times.
✓ Branch 20 → 23 taken 16997 times.
✓ Branch 21 → 22 taken 398 times.
✗ Branch 21 → 37 not taken.
✓ Branch 22 → 23 taken 398 times.
✗ Branch 22 → 27 not taken.
✓ Branch 23 → 24 taken 17395 times.
✗ Branch 23 → 37 not taken.
✓ Branch 24 → 25 taken 1973 times.
✓ Branch 24 → 28 taken 15422 times.
✓ Branch 25 → 26 taken 1973 times.
✗ Branch 25 → 37 not taken.
✓ Branch 26 → 27 taken 1 time.
✓ Branch 26 → 28 taken 1972 times.
✓ Branch 29 → 30 taken 1 time.
✓ Branch 29 → 32 taken 17394 times.
17395 if ((lhsType.is(TY_STRING) && rhsType.isPtrTo(TY_CHAR)) || (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING)))
422
1/2
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 37 not taken.
1 return ExprResult(QualType(TY_BOOL));
423
424 // Check primitive type combinations
425
2/2
✓ Branch 32 → 33 taken 17393 times.
✓ Branch 32 → 37 taken 1 time.
17394 return ExprResult(validateBinaryOperation(node, EQUAL_OP_RULES, std::size(EQUAL_OP_RULES), "==", lhsType, rhsType));
426 }
427
428 3694 ExprResult OpRuleManager::getNotEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
429 // Check is there is an overloaded operator function available
430
1/2
✓ Branch 2 → 3 taken 3694 times.
✗ Branch 2 → 36 not taken.
3694 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_NOT_EQUAL, {lhs, rhs}, 0);
431
3/4
✓ Branch 3 → 4 taken 3694 times.
✗ Branch 3 → 37 not taken.
✓ Branch 4 → 5 taken 73 times.
✓ Branch 4 → 6 taken 3621 times.
3694 if (!resultType.type.is(TY_INVALID))
432 73 return resultType;
433
434 // Remove reference wrappers
435
1/2
✓ Branch 6 → 7 taken 3621 times.
✗ Branch 6 → 37 not taken.
3621 const QualType lhsType = lhs.type.removeReferenceWrapper();
436
1/2
✓ Branch 7 → 8 taken 3621 times.
✗ Branch 7 → 37 not taken.
3621 const QualType rhsType = rhs.type.removeReferenceWrapper();
437
438 // Allow 'pointer != unsigned long' straight away
439
10/14
✓ Branch 8 → 9 taken 3621 times.
✗ Branch 8 → 37 not taken.
✓ Branch 9 → 10 taken 833 times.
✓ Branch 9 → 15 taken 2788 times.
✓ Branch 10 → 11 taken 833 times.
✗ Branch 10 → 37 not taken.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 15 taken 832 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 3620 times.
3621 if (lhsType.isPtr() && rhsType.is(TY_LONG) && rhsType.isUnsigned())
440
1/2
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 37 not taken.
1 return ExprResult(QualType(TY_BOOL));
441
442 // Allow 'string != char*' and vice versa straight away
443
13/18
✓ Branch 19 → 20 taken 3620 times.
✗ Branch 19 → 37 not taken.
✓ Branch 20 → 21 taken 31 times.
✓ Branch 20 → 23 taken 3589 times.
✓ Branch 21 → 22 taken 31 times.
✗ Branch 21 → 37 not taken.
✓ Branch 22 → 23 taken 31 times.
✗ Branch 22 → 27 not taken.
✓ Branch 23 → 24 taken 3620 times.
✗ Branch 23 → 37 not taken.
✓ Branch 24 → 25 taken 180 times.
✓ Branch 24 → 28 taken 3440 times.
✓ Branch 25 → 26 taken 180 times.
✗ Branch 25 → 37 not taken.
✓ Branch 26 → 27 taken 1 time.
✓ Branch 26 → 28 taken 179 times.
✓ Branch 29 → 30 taken 1 time.
✓ Branch 29 → 32 taken 3619 times.
3620 if ((lhsType.is(TY_STRING) && rhsType.isPtrTo(TY_CHAR)) || (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING)))
444
1/2
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 37 not taken.
1 return ExprResult(QualType(TY_BOOL));
445
446 // Check primitive type combinations
447
1/2
✓ Branch 32 → 33 taken 3619 times.
✗ Branch 32 → 37 not taken.
3619 return ExprResult(validateBinaryOperation(node, NOT_EQUAL_OP_RULES, std::size(NOT_EQUAL_OP_RULES), "!=", lhsType, rhsType));
448 }
449
450 5240 QualType OpRuleManager::getLessResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
451 // Remove reference wrappers
452
1/2
✓ Branch 2 → 3 taken 5240 times.
✗ Branch 2 → 8 not taken.
5240 const QualType lhsType = lhs.type.removeReferenceWrapper();
453
1/2
✓ Branch 3 → 4 taken 5240 times.
✗ Branch 3 → 8 not taken.
5240 const QualType rhsType = rhs.type.removeReferenceWrapper();
454
455
1/2
✓ Branch 4 → 5 taken 5240 times.
✗ Branch 4 → 8 not taken.
10480 return validateBinaryOperation(node, LESS_OP_RULES, std::size(LESS_OP_RULES), "<", lhsType, rhsType);
456 }
457
458 2755 QualType OpRuleManager::getGreaterResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
459 // Remove reference wrappers
460
1/2
✓ Branch 2 → 3 taken 2755 times.
✗ Branch 2 → 8 not taken.
2755 const QualType lhsType = lhs.type.removeReferenceWrapper();
461
1/2
✓ Branch 3 → 4 taken 2755 times.
✗ Branch 3 → 8 not taken.
2755 const QualType rhsType = rhs.type.removeReferenceWrapper();
462
463
2/2
✓ Branch 4 → 5 taken 2754 times.
✓ Branch 4 → 8 taken 1 time.
5509 return validateBinaryOperation(node, GREATER_OP_RULES, std::size(GREATER_OP_RULES), ">", lhsType, rhsType);
464 }
465
466 1818 QualType OpRuleManager::getLessEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
467 // Remove reference wrappers
468
1/2
✓ Branch 2 → 3 taken 1818 times.
✗ Branch 2 → 8 not taken.
1818 const QualType lhsType = lhs.type.removeReferenceWrapper();
469
1/2
✓ Branch 3 → 4 taken 1818 times.
✗ Branch 3 → 8 not taken.
1818 const QualType rhsType = rhs.type.removeReferenceWrapper();
470
471
1/2
✓ Branch 4 → 5 taken 1818 times.
✗ Branch 4 → 8 not taken.
3636 return validateBinaryOperation(node, LESS_EQUAL_OP_RULES, std::size(LESS_EQUAL_OP_RULES), "<=", lhsType, rhsType);
472 }
473
474 3248 QualType OpRuleManager::getGreaterEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
475 // Remove reference wrappers
476
1/2
✓ Branch 2 → 3 taken 3248 times.
✗ Branch 2 → 18 not taken.
3248 const QualType lhsType = lhs.type.removeReferenceWrapper();
477
1/2
✓ Branch 3 → 4 taken 3248 times.
✗ Branch 3 → 18 not taken.
3248 const QualType rhsType = rhs.type.removeReferenceWrapper();
478
479 // Allow 'pointer == pointer' straight away
480
7/10
✓ Branch 4 → 5 taken 3248 times.
✗ Branch 4 → 18 not taken.
✓ Branch 5 → 6 taken 4 times.
✓ Branch 5 → 9 taken 3244 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 3244 times.
3248 if (lhsType.isPtr() && rhsType.isPtr())
481
1/2
✓ Branch 11 → 12 taken 4 times.
✗ Branch 11 → 17 not taken.
4 return QualType(TY_BOOL);
482
483
1/2
✓ Branch 13 → 14 taken 3244 times.
✗ Branch 13 → 18 not taken.
3244 return validateBinaryOperation(node, GREATER_EQUAL_OP_RULES, std::size(GREATER_EQUAL_OP_RULES), ">=", lhsType, rhsType);
484 }
485
486 2161 ExprResult OpRuleManager::getShiftLeftResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs,
487 size_t opIdx) const {
488 // Check is there is an overloaded operator function available
489
1/2
✓ Branch 2 → 3 taken 2161 times.
✗ Branch 2 → 12 not taken.
2161 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_SHL, {lhs, rhs}, opIdx);
490
3/4
✓ Branch 3 → 4 taken 2161 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 2048 times.
✓ Branch 4 → 6 taken 113 times.
2161 if (!resultType.type.is(TY_INVALID))
491 2048 return resultType;
492
493 // Remove reference wrappers
494
1/2
✓ Branch 6 → 7 taken 113 times.
✗ Branch 6 → 13 not taken.
113 const QualType lhsType = lhs.type.removeReferenceWrapper();
495
1/2
✓ Branch 7 → 8 taken 113 times.
✗ Branch 7 → 13 not taken.
113 const QualType rhsType = rhs.type.removeReferenceWrapper();
496
497
1/2
✓ Branch 8 → 9 taken 113 times.
✗ Branch 8 → 13 not taken.
113 return {validateBinaryOperation(node, SHIFT_LEFT_OP_RULES, std::size(SHIFT_LEFT_OP_RULES), "<<", lhsType, rhsType)};
498 }
499
500 382 ExprResult OpRuleManager::getShiftRightResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs,
501 size_t opIdx) const {
502 // Check is there is an overloaded operator function available
503
1/2
✓ Branch 2 → 3 taken 382 times.
✗ Branch 2 → 12 not taken.
382 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_SHR, {lhs, rhs}, opIdx);
504
3/4
✓ Branch 3 → 4 taken 382 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 381 times.
382 if (!resultType.type.is(TY_INVALID))
505 1 return resultType;
506
507 // Remove reference wrappers
508
1/2
✓ Branch 6 → 7 taken 381 times.
✗ Branch 6 → 13 not taken.
381 const QualType lhsType = lhs.type.removeReferenceWrapper();
509
1/2
✓ Branch 7 → 8 taken 381 times.
✗ Branch 7 → 13 not taken.
381 const QualType rhsType = rhs.type.removeReferenceWrapper();
510
511
1/2
✓ Branch 8 → 9 taken 381 times.
✗ Branch 8 → 13 not taken.
381 return {validateBinaryOperation(node, SHIFT_RIGHT_OP_RULES, std::size(SHIFT_RIGHT_OP_RULES), ">>", lhsType, rhsType)};
512 }
513
514 8680 ExprResult OpRuleManager::getPlusResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const {
515 // Check is there is an overloaded operator function available
516
1/2
✓ Branch 2 → 3 taken 8680 times.
✗ Branch 2 → 30 not taken.
8680 const ExprResult result = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_PLUS, {lhs, rhs}, opIdx);
517
3/4
✓ Branch 3 → 4 taken 8680 times.
✗ Branch 3 → 33 not taken.
✓ Branch 4 → 5 taken 598 times.
✓ Branch 4 → 6 taken 8082 times.
8680 if (!result.type.is(TY_INVALID))
518 598 return result;
519
520 // Remove reference wrappers
521
1/2
✓ Branch 6 → 7 taken 8082 times.
✗ Branch 6 → 33 not taken.
8082 const QualType lhsType = lhs.type.removeReferenceWrapper();
522
1/2
✓ Branch 7 → 8 taken 8082 times.
✗ Branch 7 → 33 not taken.
8082 const QualType rhsType = rhs.type.removeReferenceWrapper();
523
524 // Allow any* + <int/long/short>
525
7/10
✓ Branch 8 → 9 taken 8082 times.
✗ Branch 8 → 31 not taken.
✓ Branch 9 → 10 taken 1851 times.
✓ Branch 9 → 13 taken 6231 times.
✓ Branch 10 → 11 taken 1851 times.
✗ Branch 10 → 31 not taken.
✓ Branch 11 → 12 taken 1851 times.
✗ Branch 11 → 13 not taken.
✓ Branch 14 → 15 taken 1851 times.
✓ Branch 14 → 17 taken 6231 times.
8082 if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) {
526
1/2
✓ Branch 15 → 16 taken 1851 times.
✗ Branch 15 → 33 not taken.
1851 ensureUnsafeAllowed(node, "+", lhsType, rhsType);
527 1851 return {lhsType};
528 }
529 // Allow <int/long/short> + any*
530
6/10
✓ Branch 17 → 18 taken 6231 times.
✗ Branch 17 → 32 not taken.
✓ Branch 18 → 19 taken 5786 times.
✓ Branch 18 → 22 taken 445 times.
✓ Branch 19 → 20 taken 5786 times.
✗ Branch 19 → 32 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 5786 times.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 26 taken 6231 times.
6231 if (lhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT}) && rhsType.isPtr()) {
531 ensureUnsafeAllowed(node, "+", lhsType, rhsType);
532 return {rhsType};
533 }
534
535
2/2
✓ Branch 26 → 27 taken 6230 times.
✓ Branch 26 → 33 taken 1 time.
6231 return {validateBinaryOperation(node, PLUS_OP_RULES, std::size(PLUS_OP_RULES), "+", lhsType, rhsType)};
536 }
537
538 4970 ExprResult OpRuleManager::getMinusResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const {
539 // Check is there is an overloaded operator function available
540
1/2
✓ Branch 2 → 3 taken 4970 times.
✗ Branch 2 → 21 not taken.
4970 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MINUS, {lhs, rhs}, opIdx);
541
3/4
✓ Branch 3 → 4 taken 4970 times.
✗ Branch 3 → 23 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 4969 times.
4970 if (!resultType.type.is(TY_INVALID))
542 1 return resultType;
543
544 // Remove reference wrappers
545
1/2
✓ Branch 6 → 7 taken 4969 times.
✗ Branch 6 → 23 not taken.
4969 const QualType lhsType = lhs.type.removeReferenceWrapper();
546
1/2
✓ Branch 7 → 8 taken 4969 times.
✗ Branch 7 → 23 not taken.
4969 const QualType rhsType = rhs.type.removeReferenceWrapper();
547
548 // Allow any* - <int/long/short>
549
7/10
✓ Branch 8 → 9 taken 4969 times.
✗ Branch 8 → 22 not taken.
✓ Branch 9 → 10 taken 182 times.
✓ Branch 9 → 13 taken 4787 times.
✓ Branch 10 → 11 taken 182 times.
✗ Branch 10 → 22 not taken.
✓ Branch 11 → 12 taken 182 times.
✗ Branch 11 → 13 not taken.
✓ Branch 14 → 15 taken 182 times.
✓ Branch 14 → 17 taken 4787 times.
4969 if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) {
550
1/2
✓ Branch 15 → 16 taken 182 times.
✗ Branch 15 → 23 not taken.
182 ensureUnsafeAllowed(node, "-", lhsType, rhsType);
551 182 return lhs;
552 }
553
554
1/2
✓ Branch 17 → 18 taken 4787 times.
✗ Branch 17 → 23 not taken.
4787 return {validateBinaryOperation(node, MINUS_OP_RULES, std::size(MINUS_OP_RULES), "-", lhsType, rhsType)};
555 }
556
557 2278 ExprResult OpRuleManager::getMulResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const {
558 // Check is there is an overloaded operator function available
559
1/2
✓ Branch 2 → 3 taken 2278 times.
✗ Branch 2 → 12 not taken.
2278 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MUL, {lhs, rhs}, opIdx);
560
3/4
✓ Branch 3 → 4 taken 2278 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 9 times.
✓ Branch 4 → 6 taken 2269 times.
2278 if (!resultType.type.is(TY_INVALID))
561 9 return resultType;
562
563 // Remove reference wrappers
564
1/2
✓ Branch 6 → 7 taken 2269 times.
✗ Branch 6 → 13 not taken.
2269 const QualType lhsType = lhs.type.removeReferenceWrapper();
565
1/2
✓ Branch 7 → 8 taken 2269 times.
✗ Branch 7 → 13 not taken.
2269 const QualType rhsType = rhs.type.removeReferenceWrapper();
566
567
2/2
✓ Branch 8 → 9 taken 2268 times.
✓ Branch 8 → 13 taken 1 time.
2269 return {validateBinaryOperation(node, MUL_OP_RULES, std::size(MUL_OP_RULES), "*", lhsType, rhsType)};
568 }
569
570 468 ExprResult OpRuleManager::getDivResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const {
571 // Check is there is an overloaded operator function available
572
1/2
✓ Branch 2 → 3 taken 468 times.
✗ Branch 2 → 12 not taken.
468 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_DIV, {lhs, rhs}, opIdx);
573
3/4
✓ Branch 3 → 4 taken 468 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 5 times.
✓ Branch 4 → 6 taken 463 times.
468 if (!resultType.type.is(TY_INVALID))
574 5 return resultType;
575
576 // Remove reference wrappers
577
1/2
✓ Branch 6 → 7 taken 463 times.
✗ Branch 6 → 13 not taken.
463 const QualType lhsType = lhs.type.removeReferenceWrapper();
578
1/2
✓ Branch 7 → 8 taken 463 times.
✗ Branch 7 → 13 not taken.
463 const QualType rhsType = rhs.type.removeReferenceWrapper();
579
580
1/2
✓ Branch 8 → 9 taken 463 times.
✗ Branch 8 → 13 not taken.
463 return {validateBinaryOperation(node, DIV_OP_RULES, std::size(DIV_OP_RULES), "/", lhsType, rhsType)};
581 }
582
583 112 ExprResult OpRuleManager::getRemResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
584 // Remove reference wrappers
585
1/2
✓ Branch 2 → 3 taken 112 times.
✗ Branch 2 → 7 not taken.
112 const QualType lhsType = lhs.type.removeReferenceWrapper();
586
1/2
✓ Branch 3 → 4 taken 112 times.
✗ Branch 3 → 7 not taken.
112 const QualType rhsType = rhs.type.removeReferenceWrapper();
587
588
1/2
✓ Branch 4 → 5 taken 112 times.
✗ Branch 4 → 7 not taken.
112 return {validateBinaryOperation(node, REM_OP_RULES, std::size(REM_OP_RULES), "%", lhsType, rhsType)};
589 }
590
591 1025 QualType OpRuleManager::getPrefixMinusResultType(const ASTNode *node, const ExprResult &lhs) {
592 // Remove reference wrappers
593
1/2
✓ Branch 2 → 3 taken 1025 times.
✗ Branch 2 → 7 not taken.
1025 const QualType lhsType = lhs.type.removeReferenceWrapper();
594
595
1/2
✓ Branch 3 → 4 taken 1025 times.
✗ Branch 3 → 7 not taken.
2050 return validateUnaryOperation(node, PREFIX_MINUS_OP_RULES, std::size(PREFIX_MINUS_OP_RULES), "-", lhsType);
596 }
597
598 18 QualType OpRuleManager::getPrefixPlusPlusResultType(const ASTNode *node, const ExprResult &lhs) const {
599 // Check if we try to assign a constant value
600
1/2
✓ Branch 2 → 3 taken 18 times.
✗ Branch 2 → 12 not taken.
18 ensureNoConstAssign(node, lhs.type);
601
602 // Remove reference wrappers
603
1/2
✓ Branch 3 → 4 taken 18 times.
✗ Branch 3 → 12 not taken.
18 const QualType lhsType = lhs.type.removeReferenceWrapper();
604
605 // Check if this is an unsafe operation
606
2/4
✓ Branch 4 → 5 taken 18 times.
✗ Branch 4 → 12 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 18 times.
18 if (lhsType.isPtr()) {
607 ensureUnsafeAllowed(node, "++", lhsType);
608 return lhsType;
609 }
610
611
1/2
✓ Branch 8 → 9 taken 18 times.
✗ Branch 8 → 12 not taken.
18 return validateUnaryOperation(node, PREFIX_PLUS_PLUS_OP_RULES, std::size(PREFIX_PLUS_PLUS_OP_RULES), "++", lhsType);
612 }
613
614 17 QualType OpRuleManager::getPrefixMinusMinusResultType(const ASTNode *node, const ExprResult &lhs) const {
615 // Check if we try to assign a constant value
616
1/2
✓ Branch 2 → 3 taken 17 times.
✗ Branch 2 → 12 not taken.
17 ensureNoConstAssign(node, lhs.type);
617
618 // Remove reference wrappers
619
1/2
✓ Branch 3 → 4 taken 17 times.
✗ Branch 3 → 12 not taken.
17 const QualType lhsType = lhs.type.removeReferenceWrapper();
620
621 // Check if this is an unsafe operation
622
2/4
✓ Branch 4 → 5 taken 17 times.
✗ Branch 4 → 12 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 17 times.
17 if (lhsType.isPtr()) {
623 ensureUnsafeAllowed(node, "--", lhsType);
624 return lhsType;
625 }
626
627
2/2
✓ Branch 8 → 9 taken 16 times.
✓ Branch 8 → 12 taken 1 time.
17 return validateUnaryOperation(node, PREFIX_MINUS_MINUS_OP_RULES, std::size(PREFIX_MINUS_MINUS_OP_RULES), "--", lhsType);
628 }
629
630 4460 QualType OpRuleManager::getPrefixNotResultType(const ASTNode *node, const ExprResult &lhs) {
631 // Remove reference wrappers
632
1/2
✓ Branch 2 → 3 taken 4460 times.
✗ Branch 2 → 7 not taken.
4460 const QualType lhsType = lhs.type.removeReferenceWrapper();
633
634
1/2
✓ Branch 3 → 4 taken 4460 times.
✗ Branch 3 → 7 not taken.
8920 return validateUnaryOperation(node, PREFIX_NOT_OP_RULES, std::size(PREFIX_NOT_OP_RULES), "!", lhsType);
635 }
636
637 30 ExprResult OpRuleManager::getPrefixBitwiseNotResultType(ASTNode *node, const ExprResult &lhs) const {
638 // Check if there is an overloaded operator function available
639
1/2
✓ Branch 2 → 3 taken 30 times.
✗ Branch 2 → 11 not taken.
30 const ExprResult resultType = isOperatorOverloadingFctAvailable<1>(node, OP_FCT_BITWISE_NOT, {lhs}, 0);
640
3/4
✓ Branch 3 → 4 taken 30 times.
✗ Branch 3 → 12 not taken.
✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 6 taken 28 times.
30 if (!resultType.type.is(TY_INVALID))
641 2 return resultType;
642
643 // Remove reference wrappers
644
1/2
✓ Branch 6 → 7 taken 28 times.
✗ Branch 6 → 12 not taken.
28 const QualType lhsType = lhs.type.removeReferenceWrapper();
645
646
1/2
✓ Branch 7 → 8 taken 28 times.
✗ Branch 7 → 12 not taken.
28 return {validateUnaryOperation(node, PREFIX_BITWISE_NOT_OP_RULES, std::size(PREFIX_BITWISE_NOT_OP_RULES), "~", lhsType)};
647 }
648
649 1009 QualType OpRuleManager::getPrefixMulResultType(const ASTNode *node, const ExprResult &lhs) {
650 // Remove reference wrappers
651
1/2
✓ Branch 2 → 3 taken 1009 times.
✗ Branch 2 → 25 not taken.
1009 const QualType lhsType = lhs.type.removeReferenceWrapper();
652
653
3/4
✓ Branch 3 → 4 taken 1009 times.
✗ Branch 3 → 25 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 12 taken 1008 times.
1009 if (!lhsType.isPtr())
654
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));
655
1/2
✓ Branch 12 → 13 taken 1008 times.
✗ Branch 12 → 25 not taken.
2016 return lhsType.getContained();
656 }
657
658 1168 QualType OpRuleManager::getPrefixBitwiseAndResultType(const ASTNode *node, const ExprResult &lhs) {
659 // Remove reference wrappers
660
1/2
✓ Branch 2 → 3 taken 1168 times.
✗ Branch 2 → 7 not taken.
1168 const QualType lhsType = lhs.type.removeReferenceWrapper();
661
662
1/2
✓ Branch 3 → 4 taken 1168 times.
✗ Branch 3 → 7 not taken.
2336 return lhsType.toPtr(node);
663 }
664
665 6198 ExprResult OpRuleManager::getPostfixPlusPlusResultType(ASTNode *node, const ExprResult &lhs) const {
666 // Check is there is an overloaded operator function available
667
2/2
✓ Branch 2 → 3 taken 6197 times.
✓ Branch 2 → 16 taken 1 time.
6198 const ExprResult resultType = isOperatorOverloadingFctAvailable<1>(node, OP_FCT_POSTFIX_PLUS_PLUS, {lhs}, 0);
668
3/4
✓ Branch 3 → 4 taken 6197 times.
✗ Branch 3 → 17 not taken.
✓ Branch 4 → 5 taken 9 times.
✓ Branch 4 → 6 taken 6188 times.
6197 if (!resultType.type.is(TY_INVALID))
669 9 return resultType;
670
671 // Check if we try to assign a constant value
672
1/2
✓ Branch 6 → 7 taken 6188 times.
✗ Branch 6 → 17 not taken.
6188 ensureNoConstAssign(node, lhs.type);
673
674 // Remove reference wrappers
675
1/2
✓ Branch 7 → 8 taken 6188 times.
✗ Branch 7 → 17 not taken.
6188 const QualType lhsType = lhs.type.removeReferenceWrapper();
676
677 // Check if this is an unsafe operation
678
3/4
✓ Branch 8 → 9 taken 6188 times.
✗ Branch 8 → 17 not taken.
✓ Branch 9 → 10 taken 33 times.
✓ Branch 9 → 12 taken 6155 times.
6188 if (lhsType.isPtr()) {
679
1/2
✓ Branch 10 → 11 taken 33 times.
✗ Branch 10 → 17 not taken.
33 ensureUnsafeAllowed(node, "++", lhsType);
680 33 return lhs;
681 }
682
683
2/2
✓ Branch 12 → 13 taken 6154 times.
✓ Branch 12 → 17 taken 1 time.
6155 return {validateUnaryOperation(node, POSTFIX_PLUS_PLUS_OP_RULES, std::size(POSTFIX_PLUS_PLUS_OP_RULES), "++", lhsType)};
684 }
685
686 567 ExprResult OpRuleManager::getPostfixMinusMinusResultType(ASTNode *node, const ExprResult &lhs) const {
687 // Check is there is an overloaded operator function available
688
1/2
✓ Branch 2 → 3 taken 567 times.
✗ Branch 2 → 16 not taken.
567 const ExprResult resultType = isOperatorOverloadingFctAvailable<1>(node, OP_FCT_POSTFIX_MINUS_MINUS, {lhs}, 0);
689
3/4
✓ Branch 3 → 4 taken 567 times.
✗ Branch 3 → 17 not taken.
✓ Branch 4 → 5 taken 7 times.
✓ Branch 4 → 6 taken 560 times.
567 if (!resultType.type.is(TY_INVALID))
690 7 return resultType;
691
692 // Check if we try to assign a constant value
693
1/2
✓ Branch 6 → 7 taken 560 times.
✗ Branch 6 → 17 not taken.
560 ensureNoConstAssign(node, lhs.type);
694
695 // Remove reference wrappers
696
1/2
✓ Branch 7 → 8 taken 560 times.
✗ Branch 7 → 17 not taken.
560 const QualType lhsType = lhs.type.removeReferenceWrapper();
697
698 // Check if this is an unsafe operation
699
3/4
✓ Branch 8 → 9 taken 560 times.
✗ Branch 8 → 17 not taken.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 12 taken 558 times.
560 if (lhsType.isPtr()) {
700
1/2
✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 17 not taken.
2 ensureUnsafeAllowed(node, "--", lhsType);
701 2 return lhs;
702 }
703
704
1/2
✓ Branch 12 → 13 taken 558 times.
✗ Branch 12 → 17 not taken.
558 return {validateUnaryOperation(node, POSTFIX_MINUS_MINUS_OP_RULES, std::size(POSTFIX_MINUS_MINUS_OP_RULES), "--", lhsType)};
705 }
706
707 10798 QualType OpRuleManager::getCastResultType(const ASTNode *node, QualType lhsType, const ExprResult &rhs) const {
708 // Remove reference wrappers
709
1/2
✓ Branch 2 → 3 taken 10798 times.
✗ Branch 2 → 73 not taken.
10798 lhsType = lhsType.removeReferenceWrapper();
710
1/2
✓ Branch 3 → 4 taken 10798 times.
✗ Branch 3 → 82 not taken.
10798 QualType rhsType = rhs.type.removeReferenceWrapper();
711
712 // Only allow to cast the 'heap' qualifier away, if we are in unsafe mode
713
2/2
✓ Branch 6 → 7 taken 748 times.
✓ Branch 6 → 8 taken 10050 times.
10798 if (lhsType.getQualifiers().isHeap != rhsType.getQualifiers().isHeap)
714
1/2
✓ Branch 7 → 8 taken 748 times.
✗ Branch 7 → 82 not taken.
748 ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType);
715
716 // Allow identity casts
717
3/4
✓ Branch 8 → 9 taken 10798 times.
✗ Branch 8 → 82 not taken.
✓ Branch 9 → 10 taken 1246 times.
✓ Branch 9 → 11 taken 9552 times.
10798 if (lhsType.matches(rhsType, false, true, true))
718 1246 return lhsType;
719 // Allow casts string -> char* and string -> char[]
720
12/16
✓ Branch 11 → 12 taken 9552 times.
✗ Branch 11 → 74 not taken.
✓ Branch 12 → 13 taken 5726 times.
✓ Branch 12 → 19 taken 3826 times.
✓ Branch 13 → 14 taken 5726 times.
✗ Branch 13 → 74 not taken.
✓ Branch 14 → 15 taken 5726 times.
✗ Branch 14 → 74 not taken.
✓ Branch 15 → 16 taken 3011 times.
✓ Branch 15 → 19 taken 2715 times.
✓ Branch 16 → 17 taken 3011 times.
✗ Branch 16 → 74 not taken.
✓ Branch 17 → 18 taken 3001 times.
✓ Branch 17 → 19 taken 10 times.
✓ Branch 20 → 21 taken 3001 times.
✓ Branch 20 → 22 taken 6551 times.
9552 if (lhsType.isOneOf({TY_PTR, TY_ARRAY}) && lhsType.getContained().is(TY_CHAR) && rhsType.is(TY_STRING))
721 3001 return lhsType;
722 // Allow casts char* -> string and char[] -> string
723
11/16
✓ Branch 22 → 23 taken 6551 times.
✗ Branch 22 → 76 not taken.
✓ Branch 23 → 24 taken 182 times.
✓ Branch 23 → 30 taken 6369 times.
✓ Branch 24 → 25 taken 182 times.
✗ Branch 24 → 76 not taken.
✓ Branch 25 → 26 taken 182 times.
✗ Branch 25 → 30 not taken.
✓ Branch 26 → 27 taken 182 times.
✗ Branch 26 → 76 not taken.
✓ Branch 27 → 28 taken 182 times.
✗ Branch 27 → 76 not taken.
✓ Branch 28 → 29 taken 181 times.
✓ Branch 28 → 30 taken 1 time.
✓ Branch 31 → 32 taken 181 times.
✓ Branch 31 → 33 taken 6370 times.
6551 if (lhsType.is(TY_STRING) && rhsType.isOneOf({TY_PTR, TY_ARRAY}) && rhsType.getContained().is(TY_CHAR))
724 181 return lhsType;
725 // Allow safe upcasts baseStruct* <- derivedStruct* and interface* <- struct* without requiring an unsafe
726 // block. These are the only struct-pointer casts where the target subobject is guaranteed to be present;
727 // the IR generator advances the pointer to that subobject (past any vtable prefix). The reverse direction
728 // (down/sibling casts) is not covered here and still falls through to the unsafe any* -> any* rule below.
729
8/10
✓ Branch 33 → 34 taken 6370 times.
✗ Branch 33 → 82 not taken.
✓ Branch 34 → 35 taken 2725 times.
✓ Branch 34 → 38 taken 3645 times.
✓ Branch 35 → 36 taken 2725 times.
✗ Branch 35 → 82 not taken.
✓ Branch 36 → 37 taken 2715 times.
✓ Branch 36 → 38 taken 10 times.
✓ Branch 39 → 40 taken 2715 times.
✓ Branch 39 → 51 taken 3655 times.
6370 if (lhsType.isPtr() && rhsType.isPtr()) {
730
1/2
✓ Branch 40 → 41 taken 2715 times.
✗ Branch 40 → 78 not taken.
2715 const QualType lhsContained = lhsType.getContained();
731
1/2
✓ Branch 41 → 42 taken 2715 times.
✗ Branch 41 → 78 not taken.
2715 const QualType rhsContained = rhsType.getContained();
732
8/10
✓ Branch 42 → 43 taken 2715 times.
✗ Branch 42 → 78 not taken.
✓ Branch 43 → 44 taken 2708 times.
✓ Branch 43 → 46 taken 7 times.
✓ Branch 44 → 45 taken 2708 times.
✗ Branch 44 → 78 not taken.
✓ Branch 45 → 46 taken 462 times.
✓ Branch 45 → 47 taken 2246 times.
✓ Branch 48 → 49 taken 469 times.
✓ Branch 48 → 50 taken 2246 times.
2715 if (lhsContained.matchesInterfaceImplementedByStruct(rhsContained) || lhsContained.matchesComposedBaseOfStruct(rhsContained))
733 469 return lhsType;
734 }
735 // Allow casts any* -> any*
736
8/10
✓ Branch 51 → 52 taken 5901 times.
✗ Branch 51 → 79 not taken.
✓ Branch 52 → 53 taken 2257 times.
✓ Branch 52 → 56 taken 3644 times.
✓ Branch 53 → 54 taken 2257 times.
✗ Branch 53 → 79 not taken.
✓ Branch 54 → 55 taken 2249 times.
✓ Branch 54 → 56 taken 8 times.
✓ Branch 57 → 58 taken 2249 times.
✓ Branch 57 → 60 taken 3652 times.
5901 if (lhsType.isOneOf({TY_PTR, TY_STRING}) && rhsType.isOneOf({TY_PTR, TY_STRING})) {
737
1/2
✓ Branch 58 → 59 taken 2249 times.
✗ Branch 58 → 82 not taken.
2249 ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType);
738 2249 return lhsType;
739 }
740 // Allow casts p()/f<>() -> byte*
741
7/10
✓ Branch 60 → 61 taken 3652 times.
✗ Branch 60 → 81 not taken.
✓ Branch 61 → 62 taken 8 times.
✓ Branch 61 → 65 taken 3644 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 3644 times.
3652 if (lhsType.isPtrTo(TY_BYTE) && rhsType.isOneOf({TY_FUNCTION, TY_PROCEDURE})) {
742
1/2
✓ Branch 67 → 68 taken 8 times.
✗ Branch 67 → 82 not taken.
8 ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType);
743 8 return lhsType;
744 }
745 // Check primitive type combinations
746
1/2
✓ Branch 69 → 70 taken 3644 times.
✗ Branch 69 → 82 not taken.
3644 return validateBinaryOperation(node, CAST_OP_RULES, std::size(CAST_OP_RULES), "(cast)", lhsType, rhsType, true);
747 }
748
749 template <size_t N>
750 60985 ExprResult OpRuleManager::isOperatorOverloadingFctAvailable(ASTNode *node, const char *const fctName,
751 const std::array<ExprResult, N> &op, size_t opIdx) const {
752 static_assert(N == 1 || N == 2, "Only unary and binary operators are overloadable");
753 60985 Scope *calleeParentScope = nullptr;
754 60985 const Function *callee = nullptr;
755
14/20
spice::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 6795 times.
✗ Branch 2 → 124 not taken.
✓ Branch 3 → 4 taken 6795 times.
✗ Branch 3 → 124 not taken.
✓ Branch 4 → 5 taken 6795 times.
✗ Branch 4 → 124 not taken.
✓ Branch 42 → 43 taken 23825 times.
✓ Branch 42 → 46 taken 19 times.
✓ Branch 49 → 6 taken 116811 times.
✓ Branch 49 → 50 taken 6776 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 54190 times.
✗ Branch 2 → 133 not taken.
✓ Branch 3 → 4 taken 54190 times.
✗ Branch 3 → 133 not taken.
✓ Branch 4 → 5 taken 54190 times.
✗ Branch 4 → 133 not taken.
✓ Branch 49 → 50 taken 408848 times.
✓ Branch 49 → 53 taken 6179 times.
✓ Branch 56 → 6 taken 844329 times.
✓ Branch 56 → 57 taken 48011 times.
1515783 for (const auto &sourceFile : typeChecker->resourceManager.sourceFiles | std::views::values) {
756 // Check if there is a registered operator function
757
8/12
spice::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 116811 times.
✗ Branch 10 → 103 not taken.
✓ Branch 11 → 12 taken 116811 times.
✗ Branch 11 → 101 not taken.
✓ Branch 14 → 15 taken 92967 times.
✓ Branch 14 → 16 taken 23844 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 844329 times.
✗ Branch 10 → 110 not taken.
✓ Branch 11 → 12 taken 844329 times.
✗ Branch 11 → 108 not taken.
✓ Branch 14 → 15 taken 429302 times.
✓ Branch 14 → 16 taken 415027 times.
2883420 if (!sourceFile->getNameRegistryEntry(fctName))
758 522269 continue;
759
760 // Match callees in the global scope of this source file
761 438871 calleeParentScope = sourceFile->globalScope.get();
762
2/4
spice::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 23844 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 415027 times.
✗ Branch 18 → 132 not taken.
438871 const QualType thisType(TY_DYN);
763
2/4
spice::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 23844 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 415027 times.
✗ Branch 21 → 114 not taken.
877742 ArgList args(N);
764
2/4
spice::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 23844 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 415027 times.
✗ Branch 24 → 117 not taken.
438871 args[0] = {typeChecker->mapLocalTypeToImportedScopeType(calleeParentScope, op[0].type), op[0].isTemporary()};
765 if constexpr (N == 2)
766
1/2
✓ Branch 31 → 32 taken 415027 times.
✗ Branch 31 → 119 not taken.
415027 args[1] = {typeChecker->mapLocalTypeToImportedScopeType(calleeParentScope, op[1].type), op[1].isTemporary()};
767
4/8
spice::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 23844 times.
✗ Branch 33 → 114 not taken.
✓ Branch 34 → 35 taken 23844 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 415027 times.
✗ Branch 40 → 123 not taken.
✓ Branch 41 → 42 taken 415027 times.
✗ Branch 41 → 121 not taken.
1316613 callee = FunctionManager::match(calleeParentScope, fctName, thisType, args, {}, false, node);
768
4/4
spice::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 23825 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 6179 times.
✓ Branch 45 → 47 taken 408848 times.
438871 if (callee)
769 6198 break;
770 }
771
772 // Return invalid type if the callee was not found
773
4/4
spice::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 6776 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 48011 times.
✓ Branch 57 → 60 taken 6179 times.
60985 if (!callee)
774 54787 return ExprResult(QualType(TY_INVALID));
775
2/4
spice::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 6179 times.
6198 assert(calleeParentScope != nullptr);
776
777 // Save the pointer to the operator function in the AST node
778 6198 std::vector<const Function *> &opFctPointers = typeChecker->getOpFctPointers(node);
779
3/4
spice::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 1149 times.
✓ Branch 64 → 67 taken 5030 times.
6198 if (opFctPointers.size() <= opIdx)
780
1/4
spice::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 1149 times.
✗ Branch 65 → 134 not taken.
1149 opFctPointers.resize(opIdx + 1, nullptr);
781 6198 opFctPointers.at(opIdx) = callee;
782
783 // Check if we need to request a re-visit, because the function body was not type-checked yet
784 6198 TypeChecker::requestRevisitIfRequired(callee);
785
786 // Check if the called function has sufficient visibility
787
6/8
spice::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 6179 times.
✗ Branch 69 → 73 not taken.
✓ Branch 71 → 72 taken 5132 times.
✓ Branch 71 → 73 taken 1047 times.
6198 const bool isImported = calleeParentScope != nullptr && calleeParentScope->isImportedBy(typeChecker->rootScope);
788 6198 const SymbolTableEntry *calleeEntry = callee->entry;
789
10/12
spice::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 5132 times.
✓ Branch 74 → 79 taken 1047 times.
✗ Branch 77 → 78 not taken.
✓ Branch 77 → 79 taken 5132 times.
✗ Branch 80 → 81 not taken.
✓ Branch 80 → 90 taken 6179 times.
6198 if (isImported && !calleeEntry->getQualType().isPublic())
790
1/4
spice::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,
791
3/12
spice::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");
792
793 // Procedures always have the return type 'bool'
794
4/4
spice::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 1290 times.
✓ Branch 93 → 96 taken 4889 times.
6197 if (callee->isProcedure())
795 1304 return ExprResult(QualType(TY_BOOL));
796 4893 const QualType &returnType = callee->returnType;
797
798 // Add anonymous symbol to keep track of dtor call, if non-trivially destructible
799 4893 SymbolTableEntry *anonymousSymbol = nullptr;
800
12/12
spice::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 625 times.
✓ Branch 97 → 101 taken 4264 times.
✓ Branch 99 → 100 taken 614 times.
✓ Branch 99 → 101 taken 11 times.
✓ Branch 102 → 103 taken 614 times.
✓ Branch 102 → 105 taken 4275 times.
4893 if (returnType.is(TY_STRUCT) && !returnType.isTriviallyDestructible(node))
801 615 anonymousSymbol = typeChecker->currentScope->symbolTable.insertAnonymous(returnType, node, opIdx);
802
803 4893 return {typeChecker->mapImportedScopeTypeToLocalType(calleeParentScope, returnType), anonymousSymbol};
804 }
805
806 12261 QualType OpRuleManager::validateUnaryOperation(const ASTNode *node, const UnaryOpRule opRules[], size_t opRulesSize,
807 const char *name, const QualType &lhs) {
808
2/2
✓ Branch 10 → 3 taken 26285 times.
✓ Branch 10 → 11 taken 2 times.
26287 for (size_t i = 0; i < opRulesSize; i++) {
809 26285 const UnaryOpRule &rule = opRules[i];
810
2/2
✓ Branch 5 → 6 taken 12259 times.
✓ Branch 5 → 9 taken 14026 times.
26285 if (std::get<0>(rule) == lhs.getSuperType())
811
1/2
✓ Branch 7 → 8 taken 12259 times.
✗ Branch 7 → 15 not taken.
12259 return QualType(std::get<1>(rule));
812 }
813
1/2
✓ Branch 12 → 13 taken 2 times.
✗ Branch 12 → 16 not taken.
2 throw getExceptionUnary(node, name, lhs);
814 }
815
816 119746 QualType OpRuleManager::validateBinaryOperation(const ASTNode *node, const BinaryOpRule opRules[], size_t opRulesSize,
817 const char *name, const QualType &lhs, const QualType &rhs,
818 bool preserveQualifiersFromLhs, const char *customMessagePrefix) {
819
2/2
✓ Branch 19 → 3 taken 1187289 times.
✓ Branch 19 → 20 taken 20 times.
1187309 for (size_t i = 0; i < opRulesSize; i++) {
820 1187289 const BinaryOpRule &rule = opRules[i];
821
6/6
✓ Branch 5 → 6 taken 240253 times.
✓ Branch 5 → 10 taken 947036 times.
✓ Branch 8 → 9 taken 119726 times.
✓ Branch 8 → 10 taken 120527 times.
✓ Branch 11 → 12 taken 119726 times.
✓ Branch 11 → 18 taken 1067563 times.
1187289 if (std::get<0>(rule) == lhs.getSuperType() && std::get<1>(rule) == rhs.getSuperType()) {
822
1/2
✓ Branch 13 → 14 taken 119726 times.
✗ Branch 13 → 24 not taken.
119726 QualType resultType((std::get<2>(rule)));
823
2/2
✓ Branch 14 → 15 taken 63193 times.
✓ Branch 14 → 17 taken 56533 times.
119726 if (preserveQualifiersFromLhs)
824 63193 resultType.setQualifiers(lhs.getQualifiers());
825 119726 return resultType;
826 }
827 }
828
1/2
✓ Branch 21 → 22 taken 20 times.
✗ Branch 21 → 25 not taken.
20 throw getExceptionBinary(node, name, lhs, rhs, customMessagePrefix);
829 }
830
831 2 SemanticError OpRuleManager::getExceptionUnary(const ASTNode *node, const char *name, const QualType &lhs) {
832
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)};
833 }
834
835 20 SemanticError OpRuleManager::getExceptionBinary(const ASTNode *node, const char *name, const QualType &lhs, const QualType &rhs,
836 const char *messagePrefix) {
837 // Build error message
838
1/2
✓ Branch 2 → 3 taken 20 times.
✗ Branch 2 → 50 not taken.
20 std::stringstream errorMsg;
839
2/2
✓ Branch 3 → 4 taken 4 times.
✓ Branch 3 → 14 taken 16 times.
20 if (strlen(messagePrefix) != 0)
840
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);
841 else
842
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);
843
844 // Return the exception
845
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()};
846 20 }
847
848 35 void OpRuleManager::ensureUnsafeAllowed(const ASTNode *node, const char *name, const QualType &lhs) const {
849
2/4
✓ Branch 2 → 3 taken 35 times.
✗ Branch 2 → 43 not taken.
✓ Branch 3 → 4 taken 35 times.
✗ Branch 3 → 5 not taken.
35 if (typeChecker->currentScope->doesAllowUnsafeOperations())
850 35 return;
851 // Print error message
852 const std::string lhsName = lhs.getName(true);
853 const std::string errorMsg = "Cannot apply '" + std::string(name) + "' operator on type " + lhsName +
854 " as this is an unsafe operation. Please use unsafe blocks if you know what you are doing.";
855 SOFT_ERROR_VOID(node, UNSAFE_OPERATION_IN_SAFE_CONTEXT, errorMsg)
856 }
857
858 5209 void OpRuleManager::ensureUnsafeAllowed(const ASTNode *node, const char *name, const QualType &lhs, const QualType &rhs) const {
859
3/4
✓ Branch 2 → 3 taken 5209 times.
✗ Branch 2 → 57 not taken.
✓ Branch 3 → 4 taken 5208 times.
✓ Branch 3 → 5 taken 1 time.
5209 if (typeChecker->currentScope->doesAllowUnsafeOperations())
860 5208 return;
861 // Print error message
862
1/2
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 57 not taken.
1 const std::string lhsName = lhs.getName(true);
863
1/2
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 55 not taken.
1 const std::string rhsName = rhs.getName(true);
864
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 +
865
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.";
866
1/2
✓ Branch 23 → 24 taken 1 time.
✗ Branch 23 → 51 not taken.
1 SOFT_ERROR_VOID(node, UNSAFE_OPERATION_IN_SAFE_CONTEXT, errorMsg)
867 1 }
868
869 102168 void OpRuleManager::ensureNoConstAssign(const ASTNode *node, const QualType &lhs, bool isDecl, bool isReturn) const {
870 // Check if we try to assign a constant value
871
10/12
✓ Branch 2 → 3 taken 102168 times.
✗ Branch 2 → 17 not taken.
✓ Branch 3 → 4 taken 102168 times.
✗ Branch 3 → 17 not taken.
✓ Branch 4 → 5 taken 10251 times.
✓ Branch 4 → 8 taken 91917 times.
✓ Branch 5 → 6 taken 216 times.
✓ Branch 5 → 8 taken 10035 times.
✓ Branch 6 → 7 taken 14 times.
✓ Branch 6 → 8 taken 202 times.
✓ Branch 9 → 10 taken 14 times.
✓ Branch 9 → 16 taken 102154 times.
102168 if (lhs.removeReferenceWrapper().isConst() && !isDecl && !isReturn) {
872
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);
873
1/2
✓ Branch 13 → 14 taken 14 times.
✗ Branch 13 → 21 not taken.
14 SOFT_ERROR_VOID(node, REASSIGN_CONST_VARIABLE, errorMessage);
874 14 }
875 }
876
877 } // namespace spice::compiler
878