GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 95.6% 436 / 0 / 456
Functions: 100.0% 51 / 0 / 51
Branches: 62.1% 729 / 0 / 1174

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 3659 OpRuleManager::OpRuleManager(TypeChecker *typeChecker)
16 3659 : typeChecker(typeChecker), resourceManager(typeChecker->resourceManager) {}
17
18 27552 std::pair<QualType, Function *> OpRuleManager::getAssignResultType(const ASTNode *node, const ExprResult &lhs,
19 const ExprResult &rhs, bool isDecl, bool isReturn,
20 const char *errMsgPrefix) const {
21 // Retrieve types
22 27552 const QualType lhsType = lhs.type;
23 27552 const QualType rhsType = rhs.type;
24
25 // Check if lhs is a temporary
26
2/2
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 12 taken 27551 times.
27552 if (lhs.isTemporary())
27
2/4
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 102 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 99 not taken.
3 throw SemanticError(node, OPERATOR_WRONG_DATA_TYPE, "Cannot assign to a temporary value");
28
29 // Skip type compatibility check if the lhs is of type dyn -> perform type inference
30
3/4
✓ Branch 12 → 13 taken 27551 times.
✗ Branch 12 → 116 not taken.
✓ Branch 13 → 14 taken 86 times.
✓ Branch 13 → 16 taken 27465 times.
27551 if (lhsType.is(TY_DYN))
31 86 return {rhsType, nullptr};
32
33 // Check if we try to assign a constant value
34
1/2
✓ Branch 16 → 17 taken 27465 times.
✗ Branch 16 → 116 not taken.
27465 ensureNoConstAssign(node, lhsType, isDecl, isReturn);
35
36 // Allow pointers and references of the same type straight away
37
8/10
✓ Branch 17 → 18 taken 27465 times.
✗ Branch 17 → 108 not taken.
✓ Branch 18 → 19 taken 3673 times.
✓ Branch 18 → 22 taken 23792 times.
✓ Branch 19 → 20 taken 3673 times.
✗ Branch 19 → 108 not taken.
✓ Branch 20 → 21 taken 3036 times.
✓ Branch 20 → 22 taken 637 times.
✓ Branch 23 → 24 taken 3036 times.
✓ Branch 23 → 41 taken 24429 times.
27465 if (lhsType.isOneOf({TY_PTR, TY_REF}) && lhsType.matches(rhsType, false, false, true)) {
38 // If we perform a heap x* = heap x* assignment, we need set the right hand side to MOVED
39
15/22
✓ Branch 24 → 25 taken 1005 times.
✓ Branch 24 → 35 taken 2031 times.
✓ Branch 25 → 26 taken 1005 times.
✗ Branch 25 → 109 not taken.
✓ Branch 26 → 27 taken 688 times.
✓ Branch 26 → 35 taken 317 times.
✓ Branch 27 → 28 taken 688 times.
✗ Branch 27 → 109 not taken.
✓ Branch 28 → 29 taken 555 times.
✓ Branch 28 → 35 taken 133 times.
✓ Branch 29 → 30 taken 555 times.
✗ Branch 29 → 109 not taken.
✓ Branch 30 → 31 taken 555 times.
✗ Branch 30 → 109 not taken.
✓ Branch 31 → 32 taken 555 times.
✗ Branch 31 → 35 not taken.
✓ Branch 32 → 33 taken 555 times.
✗ Branch 32 → 109 not taken.
✓ Branch 33 → 34 taken 555 times.
✗ Branch 33 → 35 not taken.
✓ Branch 36 → 37 taken 555 times.
✓ Branch 36 → 39 taken 2481 times.
3036 if (rhs.entry && lhsType.isPtr() && lhsType.isHeap() && rhsType.removeReferenceWrapper().isPtr() && rhsType.isHeap())
40
1/2
✓ Branch 37 → 38 taken 555 times.
✗ Branch 37 → 110 not taken.
555 rhs.entry->updateState(MOVED, node);
41 3036 return {rhsType, nullptr};
42 }
43 // Allow ref type to type of the same contained type straight away
44
3/4
✓ Branch 41 → 42 taken 24429 times.
✗ Branch 41 → 116 not taken.
✓ Branch 42 → 43 taken 386 times.
✓ Branch 42 → 54 taken 24043 times.
24429 if (rhsType.isRef()) {
45 // If this is const ref, remove both: the reference and the constness
46
2/4
✓ Branch 43 → 44 taken 386 times.
✗ Branch 43 → 111 not taken.
✓ Branch 44 → 45 taken 386 times.
✗ Branch 44 → 111 not taken.
386 const QualType rhsModified = rhsType.getContained().toNonConst();
47
3/4
✓ Branch 45 → 46 taken 386 times.
✗ Branch 45 → 113 not taken.
✓ Branch 46 → 47 taken 384 times.
✓ Branch 46 → 53 taken 2 times.
386 if (lhsType.matches(rhsModified, false, false, true)) {
48 384 Function *copyCtor = nullptr;
49
3/4
✓ Branch 47 → 48 taken 384 times.
✗ Branch 47 → 112 not taken.
✓ Branch 48 → 49 taken 259 times.
✓ Branch 48 → 51 taken 125 times.
384 if (rhsModified.is(TY_STRUCT))
50
1/2
✓ Branch 49 → 50 taken 259 times.
✗ Branch 49 → 112 not taken.
259 copyCtor = typeChecker->implicitlyCallStructCopyCtor(rhsModified, node);
51 384 return {lhsType, copyCtor};
52 }
53 }
54 // Allow arrays, structs, interfaces, functions, procedures of the same type straight away
55
8/10
✓ Branch 54 → 55 taken 24045 times.
✗ Branch 54 → 114 not taken.
✓ Branch 55 → 56 taken 82 times.
✓ Branch 55 → 59 taken 23963 times.
✓ Branch 56 → 57 taken 82 times.
✗ Branch 56 → 114 not taken.
✓ Branch 57 → 58 taken 77 times.
✓ Branch 57 → 59 taken 5 times.
✓ Branch 60 → 61 taken 77 times.
✓ Branch 60 → 63 taken 23968 times.
24045 if (lhsType.isOneOf({TY_ARRAY, TY_INTERFACE, TY_FUNCTION, TY_PROCEDURE}) && lhsType.matches(rhsType, false, true, true))
56 77 return {rhsType, nullptr};
57 // Allow struct of the same type straight away
58
8/10
✓ Branch 63 → 64 taken 23968 times.
✗ Branch 63 → 116 not taken.
✓ Branch 64 → 65 taken 2803 times.
✓ Branch 64 → 68 taken 21165 times.
✓ Branch 65 → 66 taken 2803 times.
✗ Branch 65 → 116 not taken.
✓ Branch 66 → 67 taken 2802 times.
✓ Branch 66 → 68 taken 1 time.
✓ Branch 69 → 70 taken 2802 times.
✓ Branch 69 → 87 taken 21166 times.
23968 if (lhsType.is(TY_STRUCT) && lhsType.matches(rhsType, false, true, true)) {
59 // Check if we support rvo. If yes, skip the implicit copy ctor call
60
4/4
✓ Branch 70 → 71 taken 1545 times.
✓ Branch 70 → 74 taken 1257 times.
✓ Branch 72 → 73 taken 119 times.
✓ Branch 72 → 74 taken 1426 times.
2802 const bool supportsRVO = isReturn && !rhs.isTemporary();
61 2802 Function *copyCtor = nullptr;
62
10/10
✓ Branch 75 → 76 taken 2065 times.
✓ Branch 75 → 81 taken 737 times.
✓ Branch 76 → 77 taken 1946 times.
✓ Branch 76 → 81 taken 119 times.
✓ Branch 77 → 78 taken 1080 times.
✓ Branch 77 → 81 taken 866 times.
✓ Branch 79 → 80 taken 14 times.
✓ Branch 79 → 81 taken 1066 times.
✓ Branch 82 → 83 taken 14 times.
✓ Branch 82 → 85 taken 2788 times.
2802 if (rhs.entry != nullptr && !supportsRVO && !isReturn && !rhs.isTemporary())
63
1/2
✓ Branch 83 → 84 taken 14 times.
✗ Branch 83 → 115 not taken.
14 copyCtor = typeChecker->implicitlyCallStructCopyCtor(rhsType, rhs.entry->declNode);
64 2802 return {rhsType, copyCtor};
65 }
66
67 // Check common type combinations
68
2/2
✓ Branch 87 → 88 taken 21164 times.
✓ Branch 87 → 116 taken 2 times.
21166 const QualType resultType = getAssignResultTypeCommon(node, lhs, rhs, isDecl, isReturn);
69
3/4
✓ Branch 88 → 89 taken 21164 times.
✗ Branch 88 → 116 not taken.
✓ Branch 89 → 90 taken 586 times.
✓ Branch 89 → 92 taken 20578 times.
21164 if (!resultType.is(TY_INVALID))
70 586 return {resultType, nullptr};
71
72 // Check primitive type combinations
73 const QualType binOpType =
74
2/2
✓ Branch 94 → 95 taken 20566 times.
✓ Branch 94 → 116 taken 12 times.
20578 validateBinaryOperation(node, ASSIGN_OP_RULES, std::size(ASSIGN_OP_RULES), "=", lhsType, rhsType, true, errMsgPrefix);
75 20566 return {binOpType, nullptr};
76 }
77
78 425 QualType OpRuleManager::getFieldAssignResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, bool imm,
79 bool isDecl) const {
80 // Retrieve types
81 425 const QualType lhsType = lhs.type;
82 425 const QualType rhsType = rhs.type;
83
2/4
✓ Branch 2 → 3 taken 425 times.
✗ Branch 2 → 92 not taken.
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 425 times.
425 assert(!lhsType.is(TY_DYN));
84
85 // Check if we try to assign a constant value
86
1/2
✓ Branch 5 → 6 taken 425 times.
✗ Branch 5 → 92 not taken.
425 ensureNoConstAssign(node, lhsType, isDecl);
87
88 // Allow pointers, arrays and structs of the same type straight away
89
8/10
✓ Branch 6 → 7 taken 425 times.
✗ Branch 6 → 85 not taken.
✓ Branch 7 → 8 taken 245 times.
✓ Branch 7 → 11 taken 180 times.
✓ Branch 8 → 9 taken 245 times.
✗ Branch 8 → 85 not taken.
✓ Branch 9 → 10 taken 243 times.
✓ Branch 9 → 11 taken 2 times.
✓ Branch 12 → 13 taken 243 times.
✓ Branch 12 → 29 taken 182 times.
425 if (lhsType.isOneOf({TY_PTR, TY_ARRAY}) && lhsType == rhsType) {
90 // If we perform a heap x* = heap x* assignment, we need set the right hand side to MOVED
91
8/22
✓ Branch 13 → 14 taken 70 times.
✓ Branch 13 → 24 taken 173 times.
✓ Branch 14 → 15 taken 70 times.
✗ Branch 14 → 86 not taken.
✓ Branch 15 → 16 taken 68 times.
✓ Branch 15 → 24 taken 2 times.
✓ Branch 16 → 17 taken 68 times.
✗ Branch 16 → 86 not taken.
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 24 taken 68 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 243 times.
243 if (rhs.entry && lhsType.isPtr() && lhsType.isHeap() && rhsType.removeReferenceWrapper().isPtr() && rhsType.isHeap())
92 rhs.entry->updateState(MOVED, node);
93 243 return rhsType;
94 }
95 // Allow struct of the same type straight away
96
8/10
✓ Branch 29 → 30 taken 182 times.
✗ Branch 29 → 92 not taken.
✓ Branch 30 → 31 taken 15 times.
✓ Branch 30 → 34 taken 167 times.
✓ Branch 31 → 32 taken 15 times.
✗ Branch 31 → 92 not taken.
✓ Branch 32 → 33 taken 13 times.
✓ Branch 32 → 34 taken 2 times.
✓ Branch 35 → 36 taken 13 times.
✓ Branch 35 → 40 taken 169 times.
182 if (lhsType.is(TY_STRUCT) && lhsType.matches(rhsType, false, true, true)) {
97
2/2
✓ Branch 37 → 38 taken 5 times.
✓ Branch 37 → 39 taken 8 times.
13 if (!rhs.isTemporary())
98
1/2
✓ Branch 38 → 39 taken 5 times.
✗ Branch 38 → 92 not taken.
5 typeChecker->implicitlyCallStructCopyCtor(rhs.entry, rhs.entry->declNode);
99 13 return rhsType;
100 }
101 // Allow ref type to type of the same contained type straight away
102
9/12
✓ Branch 40 → 41 taken 169 times.
✗ Branch 40 → 88 not taken.
✓ Branch 41 → 42 taken 24 times.
✓ Branch 41 → 46 taken 145 times.
✓ Branch 42 → 43 taken 24 times.
✗ Branch 42 → 88 not taken.
✓ Branch 43 → 44 taken 24 times.
✗ Branch 43 → 88 not taken.
✓ Branch 44 → 45 taken 1 time.
✓ Branch 44 → 46 taken 23 times.
✓ Branch 47 → 48 taken 1 time.
✓ Branch 47 → 58 taken 168 times.
169 if (rhsType.isRef() && lhsType.matches(rhsType.getContained(), false, false, true)) {
103 // In case of a return expression, we perform temp stealing
104
4/10
✓ Branch 48 → 49 taken 1 time.
✗ Branch 48 → 89 not taken.
✓ Branch 49 → 50 taken 1 time.
✗ Branch 49 → 89 not taken.
✗ Branch 50 → 51 not taken.
✓ Branch 50 → 54 taken 1 time.
✗ Branch 52 → 53 not taken.
✗ Branch 52 → 54 not taken.
✗ Branch 55 → 56 not taken.
✓ Branch 55 → 57 taken 1 time.
1 if (rhsType.getContained().is(TY_STRUCT) && !rhs.isTemporary())
105 typeChecker->implicitlyCallStructCopyCtor(rhs.entry, rhs.entry->declNode);
106 1 return lhsType;
107 }
108 // Allow const ref type to type of the same contained type straight away
109
9/14
✓ Branch 58 → 59 taken 168 times.
✗ Branch 58 → 90 not taken.
✓ Branch 59 → 60 taken 23 times.
✓ Branch 59 → 65 taken 145 times.
✓ Branch 60 → 61 taken 23 times.
✗ Branch 60 → 90 not taken.
✓ Branch 61 → 62 taken 23 times.
✗ Branch 61 → 90 not taken.
✓ Branch 62 → 63 taken 23 times.
✗ Branch 62 → 90 not taken.
✓ Branch 63 → 64 taken 23 times.
✗ Branch 63 → 65 not taken.
✓ Branch 66 → 67 taken 23 times.
✓ Branch 66 → 68 taken 145 times.
168 if (rhsType.isConstRef() && lhsType.matches(rhsType.getContained().toNonConst(), false, false, true))
110 23 return lhsType;
111 // Allow immediate value to const ref of the same contained type straight away
112
6/8
✓ Branch 68 → 69 taken 145 times.
✗ Branch 68 → 92 not taken.
✓ Branch 69 → 70 taken 1 time.
✓ Branch 69 → 72 taken 144 times.
✓ Branch 70 → 71 taken 1 time.
✗ Branch 70 → 72 not taken.
✓ Branch 73 → 74 taken 1 time.
✓ Branch 73 → 75 taken 144 times.
145 if (lhsType.isConstRef() && imm)
113 1 return rhsType;
114
115 // Check common type combinations
116
1/2
✓ Branch 75 → 76 taken 144 times.
✗ Branch 75 → 92 not taken.
144 const QualType resultType = getAssignResultTypeCommon(node, lhs, rhs, isDecl, false);
117
3/4
✓ Branch 76 → 77 taken 144 times.
✗ Branch 76 → 92 not taken.
✓ Branch 77 → 78 taken 4 times.
✓ Branch 77 → 79 taken 140 times.
144 if (!resultType.is(TY_INVALID))
118 4 return resultType;
119
120 // Check primitive type combinations
121
2/2
✓ Branch 81 → 82 taken 139 times.
✓ Branch 81 → 92 taken 1 time.
140 return validateBinaryOperation(node, ASSIGN_OP_RULES, std::size(ASSIGN_OP_RULES), "=", lhsType, rhsType, true,
122 139 ERROR_FIELD_ASSIGN);
123 }
124
125 21310 QualType OpRuleManager::getAssignResultTypeCommon(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, bool isDecl,
126 bool isReturn) {
127 // Retrieve types
128 21310 const QualType lhsType = lhs.type;
129 21310 const QualType rhsType = rhs.type;
130
131 // Allow type to ref type of the same contained type straight away
132
9/12
✓ Branch 2 → 3 taken 21310 times.
✗ Branch 2 → 113 not taken.
✓ Branch 3 → 4 taken 431 times.
✓ Branch 3 → 8 taken 20879 times.
✓ Branch 4 → 5 taken 431 times.
✗ Branch 4 → 113 not taken.
✓ Branch 5 → 6 taken 431 times.
✗ Branch 5 → 113 not taken.
✓ Branch 6 → 7 taken 428 times.
✓ Branch 6 → 8 taken 3 times.
✓ Branch 9 → 10 taken 428 times.
✓ Branch 9 → 44 taken 20882 times.
21310 if (lhsType.isRef() && lhsType.getContained().matches(rhsType, false, false, true)) {
133
4/4
✓ Branch 10 → 11 taken 367 times.
✓ Branch 10 → 12 taken 61 times.
✓ Branch 11 → 12 taken 306 times.
✓ Branch 11 → 13 taken 61 times.
428 const bool isDeclOrReturn = isDecl || isReturn;
134
7/8
✓ Branch 14 → 15 taken 367 times.
✓ Branch 14 → 19 taken 61 times.
✓ Branch 16 → 17 taken 367 times.
✗ Branch 16 → 137 not taken.
✓ Branch 17 → 18 taken 1 time.
✓ Branch 17 → 19 taken 366 times.
✓ Branch 20 → 21 taken 1 time.
✓ Branch 20 → 29 taken 427 times.
428 if (isDeclOrReturn && !lhsType.canBind(rhsType, rhs.isTemporary()))
135
2/4
✓ Branch 24 → 25 taken 1 time.
✗ Branch 24 → 117 not taken.
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 114 not taken.
3 throw SemanticError(node, TEMP_TO_NON_CONST_REF, "Temporary values can only be bound to const reference variables/fields");
136
6/6
✓ Branch 29 → 30 taken 306 times.
✓ Branch 29 → 33 taken 121 times.
✓ Branch 31 → 32 taken 1 time.
✓ Branch 31 → 33 taken 305 times.
✓ Branch 34 → 35 taken 1 time.
✓ Branch 34 → 43 taken 426 times.
427 if (isReturn && rhs.isTemporary())
137
2/4
✓ Branch 38 → 39 taken 1 time.
✗ Branch 38 → 126 not taken.
✓ Branch 39 → 40 taken 1 time.
✗ Branch 39 → 123 not taken.
3 throw SemanticError(node, RETURN_OF_TEMPORARY_VALUE, "Cannot return reference to temporary value");
138 426 return lhsType;
139 }
140 // Allow char* = string
141
9/14
✓ Branch 44 → 45 taken 20882 times.
✗ Branch 44 → 137 not taken.
✓ Branch 45 → 46 taken 1 time.
✓ Branch 45 → 53 taken 20881 times.
✓ Branch 46 → 47 taken 1 time.
✗ Branch 46 → 137 not taken.
✓ Branch 47 → 48 taken 1 time.
✗ Branch 47 → 53 not taken.
✓ Branch 50 → 51 taken 1 time.
✗ Branch 50 → 137 not taken.
✓ Branch 51 → 52 taken 1 time.
✗ Branch 51 → 53 not taken.
✓ Branch 54 → 55 taken 1 time.
✓ Branch 54 → 56 taken 20881 times.
20882 if (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING) && lhsType.getQualifiers() == rhsType.getQualifiers())
142 1 return lhsType;
143 // Allow array to pointer
144
12/18
✓ Branch 56 → 57 taken 20881 times.
✗ Branch 56 → 132 not taken.
✓ Branch 57 → 58 taken 163 times.
✓ Branch 57 → 65 taken 20718 times.
✓ Branch 58 → 59 taken 163 times.
✗ Branch 58 → 132 not taken.
✓ Branch 59 → 60 taken 6 times.
✓ Branch 59 → 65 taken 157 times.
✓ Branch 60 → 61 taken 6 times.
✗ Branch 60 → 132 not taken.
✓ Branch 61 → 62 taken 6 times.
✗ Branch 61 → 132 not taken.
✓ Branch 62 → 63 taken 6 times.
✗ Branch 62 → 132 not taken.
✓ Branch 63 → 64 taken 6 times.
✗ Branch 63 → 65 not taken.
✓ Branch 66 → 67 taken 6 times.
✓ Branch 66 → 68 taken 20875 times.
20881 if (lhsType.isPtr() && rhsType.isArray() && lhsType.getContained().matches(rhsType.getContained(), false, false, true))
145 6 return lhsType;
146 // Allow interface* = struct* or interface& = struct that implements this interface
147
1/2
✓ Branch 70 → 71 taken 20875 times.
✗ Branch 70 → 137 not taken.
20875 const bool sameChainDepth = Type::hasSameTypeChainDepth(lhsType.getType(), rhsType.getType());
148
10/14
✓ Branch 71 → 72 taken 20875 times.
✗ Branch 71 → 137 not taken.
✓ Branch 72 → 73 taken 157 times.
✓ Branch 72 → 76 taken 20718 times.
✓ Branch 73 → 74 taken 157 times.
✗ Branch 73 → 137 not taken.
✓ Branch 74 → 75 taken 156 times.
✓ Branch 74 → 76 taken 1 time.
✗ Branch 75 → 76 not taken.
✓ Branch 75 → 78 taken 156 times.
✓ Branch 76 → 77 taken 20719 times.
✗ Branch 76 → 137 not taken.
✓ Branch 77 → 78 taken 3 times.
✓ Branch 77 → 79 taken 20716 times.
20875 const bool typesCompatible = (lhsType.isPtr() && rhsType.isPtr() && sameChainDepth) || lhsType.isRef();
149
9/12
✓ Branch 80 → 81 taken 159 times.
✓ Branch 80 → 86 taken 20716 times.
✓ Branch 81 → 82 taken 159 times.
✗ Branch 81 → 137 not taken.
✓ Branch 82 → 83 taken 5 times.
✓ Branch 82 → 86 taken 154 times.
✓ Branch 83 → 84 taken 5 times.
✗ Branch 83 → 137 not taken.
✓ Branch 84 → 85 taken 5 times.
✗ Branch 84 → 86 not taken.
✓ Branch 87 → 88 taken 5 times.
✓ Branch 87 → 93 taken 20870 times.
20875 if (typesCompatible && lhsType.isBase(TY_INTERFACE) && rhsType.isBase(TY_STRUCT)) {
150 5 QualType lhsTypeCopy = lhsType;
151 5 QualType rhsTypeCopy = rhsType;
152
1/2
✓ Branch 88 → 89 taken 5 times.
✗ Branch 88 → 134 not taken.
5 QualType::unwrapBothWithRefWrappers(lhsTypeCopy, rhsTypeCopy);
153
2/4
✓ Branch 89 → 90 taken 5 times.
✗ Branch 89 → 134 not taken.
✓ Branch 90 → 91 taken 5 times.
✗ Branch 90 → 92 not taken.
5 if (lhsTypeCopy.matchesInterfaceImplementedByStruct(rhsTypeCopy))
154 5 return lhsType;
155 }
156 // Allow type* = heap type* straight away. This is used for initializing non-owning pointers to heap allocations
157
10/14
✓ Branch 93 → 94 taken 20870 times.
✗ Branch 93 → 137 not taken.
✓ Branch 94 → 95 taken 153 times.
✓ Branch 94 → 100 taken 20717 times.
✓ Branch 95 → 96 taken 153 times.
✗ Branch 95 → 137 not taken.
✓ Branch 96 → 97 taken 152 times.
✓ Branch 96 → 100 taken 1 time.
✓ Branch 97 → 98 taken 152 times.
✗ Branch 97 → 137 not taken.
✓ Branch 98 → 99 taken 152 times.
✗ Branch 98 → 100 not taken.
✓ Branch 101 → 102 taken 152 times.
✓ Branch 101 → 108 taken 20718 times.
20870 if (lhsType.isPtr() && rhsType.isHeap() && lhsType.matches(rhsType, false, true, true)) {
158 152 TypeQualifiers rhsQualifiers = rhsType.getQualifiers();
159 152 rhsQualifiers.isHeap = false;
160
2/4
✓ Branch 104 → 105 taken 152 times.
✗ Branch 104 → 135 not taken.
✓ Branch 105 → 106 taken 152 times.
✗ Branch 105 → 107 not taken.
152 if (lhsType.getQualifiers() == rhsQualifiers)
161 152 return lhsType;
162 }
163
164 // Nothing matched
165
1/2
✓ Branch 108 → 109 taken 20718 times.
✗ Branch 108 → 136 not taken.
20718 return QualType(TY_INVALID);
166 }
167
168 285 ExprResult OpRuleManager::getPlusEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
169 // Check is there is an overloaded operator function available
170
1/2
✓ Branch 2 → 3 taken 285 times.
✗ Branch 2 → 24 not taken.
285 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_PLUS_EQUAL, {lhs, rhs}, 0);
171
3/4
✓ Branch 3 → 4 taken 285 times.
✗ Branch 3 → 26 not taken.
✓ Branch 4 → 5 taken 102 times.
✓ Branch 4 → 6 taken 183 times.
285 if (!resultType.type.is(TY_INVALID))
172 102 return resultType;
173
174 // Check if we try to assign a constant value
175
1/2
✓ Branch 6 → 7 taken 183 times.
✗ Branch 6 → 26 not taken.
183 ensureNoConstAssign(node, lhs.type);
176
177 // Remove reference wrappers
178
1/2
✓ Branch 7 → 8 taken 183 times.
✗ Branch 7 → 26 not taken.
183 const QualType lhsType = lhs.type.removeReferenceWrapper();
179
1/2
✓ Branch 8 → 9 taken 183 times.
✗ Branch 8 → 26 not taken.
183 const QualType rhsType = rhs.type.removeReferenceWrapper();
180
181 // Check if this is an unsafe operation
182
7/10
✓ Branch 9 → 10 taken 183 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 5 times.
✓ Branch 10 → 14 taken 178 times.
✓ Branch 11 → 12 taken 5 times.
✗ Branch 11 → 25 not taken.
✓ Branch 12 → 13 taken 5 times.
✗ Branch 12 → 14 not taken.
✓ Branch 15 → 16 taken 5 times.
✓ Branch 15 → 18 taken 178 times.
183 if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) {
183
1/2
✓ Branch 16 → 17 taken 5 times.
✗ Branch 16 → 26 not taken.
5 ensureUnsafeAllowed(node, "+=", lhsType, rhsType);
184 5 return {lhs};
185 }
186
187
1/2
✓ Branch 20 → 21 taken 178 times.
✗ Branch 20 → 26 not taken.
178 return {validateBinaryOperation(node, PLUS_EQUAL_OP_RULES, std::size(PLUS_EQUAL_OP_RULES), "+=", lhsType, rhsType)};
188 }
189
190 49 ExprResult OpRuleManager::getMinusEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
191 // Check is there is an overloaded operator function available
192
1/2
✓ Branch 2 → 3 taken 49 times.
✗ Branch 2 → 24 not taken.
49 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MINUS_EQUAL, {lhs, rhs}, 0);
193
3/4
✓ Branch 3 → 4 taken 49 times.
✗ Branch 3 → 26 not taken.
✓ Branch 4 → 5 taken 7 times.
✓ Branch 4 → 6 taken 42 times.
49 if (!resultType.type.is(TY_INVALID))
194 7 return resultType;
195
196 // Check if we try to assign a constant value
197
1/2
✓ Branch 6 → 7 taken 42 times.
✗ Branch 6 → 26 not taken.
42 ensureNoConstAssign(node, lhs.type);
198
199 // Remove reference wrappers
200
1/2
✓ Branch 7 → 8 taken 42 times.
✗ Branch 7 → 26 not taken.
42 const QualType lhsType = lhs.type.removeReferenceWrapper();
201
1/2
✓ Branch 8 → 9 taken 42 times.
✗ Branch 8 → 26 not taken.
42 const QualType rhsType = rhs.type.removeReferenceWrapper();
202
203 // Check if this is an unsafe operation
204
7/10
✓ Branch 9 → 10 taken 42 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 5 times.
✓ Branch 10 → 14 taken 37 times.
✓ Branch 11 → 12 taken 5 times.
✗ Branch 11 → 25 not taken.
✓ Branch 12 → 13 taken 5 times.
✗ Branch 12 → 14 not taken.
✓ Branch 15 → 16 taken 5 times.
✓ Branch 15 → 18 taken 37 times.
42 if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) {
205
1/2
✓ Branch 16 → 17 taken 5 times.
✗ Branch 16 → 26 not taken.
5 ensureUnsafeAllowed(node, "-=", lhsType, rhsType);
206 5 return {lhs};
207 }
208
209
1/2
✓ Branch 20 → 21 taken 37 times.
✗ Branch 20 → 26 not taken.
37 return {validateBinaryOperation(node, MINUS_EQUAL_OP_RULES, std::size(MINUS_EQUAL_OP_RULES), "-=", lhsType, rhsType)};
210 }
211
212 51 ExprResult OpRuleManager::getMulEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
213 // Check is there is an overloaded operator function available
214
1/2
✓ Branch 2 → 3 taken 51 times.
✗ Branch 2 → 15 not taken.
51 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MUL_EQUAL, {lhs, rhs}, 0);
215
3/4
✓ Branch 3 → 4 taken 51 times.
✗ Branch 3 → 16 not taken.
✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 6 taken 49 times.
51 if (!resultType.type.is(TY_INVALID))
216 2 return resultType;
217
218 // Check if we try to assign a constant value
219
1/2
✓ Branch 6 → 7 taken 49 times.
✗ Branch 6 → 16 not taken.
49 ensureNoConstAssign(node, lhs.type);
220
221 // Remove reference wrappers
222
1/2
✓ Branch 7 → 8 taken 49 times.
✗ Branch 7 → 16 not taken.
49 const QualType lhsType = lhs.type.removeReferenceWrapper();
223
1/2
✓ Branch 8 → 9 taken 49 times.
✗ Branch 8 → 16 not taken.
49 const QualType rhsType = rhs.type.removeReferenceWrapper();
224
225
1/2
✓ Branch 11 → 12 taken 49 times.
✗ Branch 11 → 16 not taken.
49 return {validateBinaryOperation(node, MUL_EQUAL_OP_RULES, std::size(MUL_EQUAL_OP_RULES), "*=", lhsType, rhsType)};
226 }
227
228 55 ExprResult OpRuleManager::getDivEqualResultType(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 55 times.
✗ Branch 2 → 15 not taken.
55 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_DIV_EQUAL, {lhs, rhs}, 0);
231
3/4
✓ Branch 3 → 4 taken 55 times.
✗ Branch 3 → 16 not taken.
✓ Branch 4 → 5 taken 37 times.
✓ Branch 4 → 6 taken 18 times.
55 if (!resultType.type.is(TY_INVALID))
232 37 return resultType;
233
234 // Check if we try to assign a constant value
235
1/2
✓ Branch 6 → 7 taken 18 times.
✗ Branch 6 → 16 not taken.
18 ensureNoConstAssign(node, lhs.type);
236
237 // Remove reference wrappers
238
1/2
✓ Branch 7 → 8 taken 18 times.
✗ Branch 7 → 16 not taken.
18 const QualType lhsType = lhs.type.removeReferenceWrapper();
239
1/2
✓ Branch 8 → 9 taken 18 times.
✗ Branch 8 → 16 not taken.
18 const QualType rhsType = rhs.type.removeReferenceWrapper();
240
241
1/2
✓ Branch 11 → 12 taken 18 times.
✗ Branch 11 → 16 not taken.
18 return {validateBinaryOperation(node, DIV_EQUAL_OP_RULES, std::size(DIV_EQUAL_OP_RULES), "/=", lhsType, rhsType)};
242 }
243
244 17 QualType OpRuleManager::getRemEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
245 // Check if we try to assign a constant value
246
1/2
✓ Branch 2 → 3 taken 17 times.
✗ Branch 2 → 11 not taken.
17 ensureNoConstAssign(node, lhs.type);
247
248 // Remove reference wrappers
249
1/2
✓ Branch 3 → 4 taken 17 times.
✗ Branch 3 → 11 not taken.
17 const QualType lhsType = lhs.type.removeReferenceWrapper();
250
1/2
✓ Branch 4 → 5 taken 17 times.
✗ Branch 4 → 11 not taken.
17 const QualType rhsType = rhs.type.removeReferenceWrapper();
251
252
1/2
✓ Branch 7 → 8 taken 17 times.
✗ Branch 7 → 11 not taken.
34 return validateBinaryOperation(node, REM_EQUAL_OP_RULES, std::size(REM_EQUAL_OP_RULES), "%=", lhsType, rhsType);
253 }
254
255 12 QualType OpRuleManager::getSHLEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
256 // Check if we try to assign a constant value
257
1/2
✓ Branch 2 → 3 taken 12 times.
✗ Branch 2 → 11 not taken.
12 ensureNoConstAssign(node, lhs.type);
258
259 // Remove reference wrappers
260
1/2
✓ Branch 3 → 4 taken 12 times.
✗ Branch 3 → 11 not taken.
12 const QualType lhsType = lhs.type.removeReferenceWrapper();
261
1/2
✓ Branch 4 → 5 taken 12 times.
✗ Branch 4 → 11 not taken.
12 const QualType rhsType = rhs.type.removeReferenceWrapper();
262
263
1/2
✓ Branch 7 → 8 taken 12 times.
✗ Branch 7 → 11 not taken.
24 return validateBinaryOperation(node, SHL_EQUAL_OP_RULES, std::size(SHL_EQUAL_OP_RULES), "<<=", lhsType, rhsType);
264 }
265
266 13 QualType OpRuleManager::getSHREqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
267 // Check if we try to assign a constant value
268
1/2
✓ Branch 2 → 3 taken 13 times.
✗ Branch 2 → 11 not taken.
13 ensureNoConstAssign(node, lhs.type);
269
270 // Remove reference wrappers
271
1/2
✓ Branch 3 → 4 taken 13 times.
✗ Branch 3 → 11 not taken.
13 const QualType lhsType = lhs.type.removeReferenceWrapper();
272
1/2
✓ Branch 4 → 5 taken 13 times.
✗ Branch 4 → 11 not taken.
13 const QualType rhsType = rhs.type.removeReferenceWrapper();
273
274
1/2
✓ Branch 7 → 8 taken 13 times.
✗ Branch 7 → 11 not taken.
26 return validateBinaryOperation(node, SHR_EQUAL_OP_RULES, std::size(SHR_EQUAL_OP_RULES), ">>=", lhsType, rhsType);
275 }
276
277 11 QualType OpRuleManager::getAndEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
278 // Check if we try to assign a constant value
279
1/2
✓ Branch 2 → 3 taken 11 times.
✗ Branch 2 → 11 not taken.
11 ensureNoConstAssign(node, lhs.type);
280
281 // Remove reference wrappers
282
1/2
✓ Branch 3 → 4 taken 11 times.
✗ Branch 3 → 11 not taken.
11 const QualType lhsType = lhs.type.removeReferenceWrapper();
283
1/2
✓ Branch 4 → 5 taken 11 times.
✗ Branch 4 → 11 not taken.
11 const QualType rhsType = rhs.type.removeReferenceWrapper();
284
285
1/2
✓ Branch 7 → 8 taken 11 times.
✗ Branch 7 → 11 not taken.
22 return validateBinaryOperation(node, AND_EQUAL_OP_RULES, std::size(AND_EQUAL_OP_RULES), "&=", lhsType, rhsType);
286 }
287
288 11 QualType OpRuleManager::getOrEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
289 // Check if we try to assign a constant value
290
1/2
✓ Branch 2 → 3 taken 11 times.
✗ Branch 2 → 11 not taken.
11 ensureNoConstAssign(node, lhs.type);
291
292 // Remove reference wrappers
293
1/2
✓ Branch 3 → 4 taken 11 times.
✗ Branch 3 → 11 not taken.
11 const QualType lhsType = lhs.type.removeReferenceWrapper();
294
1/2
✓ Branch 4 → 5 taken 11 times.
✗ Branch 4 → 11 not taken.
11 const QualType rhsType = rhs.type.removeReferenceWrapper();
295
296
1/2
✓ Branch 7 → 8 taken 11 times.
✗ Branch 7 → 11 not taken.
22 return validateBinaryOperation(node, OR_EQUAL_OP_RULES, std::size(OR_EQUAL_OP_RULES), "|=", lhsType, rhsType);
297 }
298
299 368 QualType OpRuleManager::getXorEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
300 // Check if we try to assign a constant value
301
1/2
✓ Branch 2 → 3 taken 368 times.
✗ Branch 2 → 11 not taken.
368 ensureNoConstAssign(node, lhs.type);
302
303 // Remove reference wrappers
304
1/2
✓ Branch 3 → 4 taken 368 times.
✗ Branch 3 → 11 not taken.
368 const QualType lhsType = lhs.type.removeReferenceWrapper();
305
1/2
✓ Branch 4 → 5 taken 368 times.
✗ Branch 4 → 11 not taken.
368 const QualType rhsType = rhs.type.removeReferenceWrapper();
306
307
1/2
✓ Branch 7 → 8 taken 368 times.
✗ Branch 7 → 11 not taken.
736 return validateBinaryOperation(node, XOR_EQUAL_OP_RULES, std::size(XOR_EQUAL_OP_RULES), "^=", lhsType, rhsType);
308 }
309
310 1293 QualType OpRuleManager::getLogicalOrResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
311 // Remove reference wrappers
312
1/2
✓ Branch 2 → 3 taken 1293 times.
✗ Branch 2 → 10 not taken.
1293 const QualType lhsType = lhs.type.removeReferenceWrapper();
313
1/2
✓ Branch 3 → 4 taken 1293 times.
✗ Branch 3 → 10 not taken.
1293 const QualType rhsType = rhs.type.removeReferenceWrapper();
314
315
2/2
✓ Branch 6 → 7 taken 1292 times.
✓ Branch 6 → 10 taken 1 time.
2585 return validateBinaryOperation(node, LOGICAL_OR_OP_RULES, std::size(LOGICAL_OR_OP_RULES), "||", lhsType, rhsType);
316 }
317
318 225 QualType OpRuleManager::getLogicalAndResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
319 // Remove reference wrappers
320
1/2
✓ Branch 2 → 3 taken 225 times.
✗ Branch 2 → 10 not taken.
225 const QualType lhsType = lhs.type.removeReferenceWrapper();
321
1/2
✓ Branch 3 → 4 taken 225 times.
✗ Branch 3 → 10 not taken.
225 const QualType rhsType = rhs.type.removeReferenceWrapper();
322
323
1/2
✓ Branch 6 → 7 taken 225 times.
✗ Branch 6 → 10 not taken.
450 return validateBinaryOperation(node, LOGICAL_AND_OP_RULES, std::size(LOGICAL_AND_OP_RULES), "&&", lhsType, rhsType);
324 }
325
326 95 QualType OpRuleManager::getBitwiseOrResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
327 // Remove reference wrappers
328
1/2
✓ Branch 2 → 3 taken 95 times.
✗ Branch 2 → 10 not taken.
95 const QualType lhsType = lhs.type.removeReferenceWrapper();
329
1/2
✓ Branch 3 → 4 taken 95 times.
✗ Branch 3 → 10 not taken.
95 const QualType rhsType = rhs.type.removeReferenceWrapper();
330
331
2/2
✓ Branch 6 → 7 taken 94 times.
✓ Branch 6 → 10 taken 1 time.
189 return validateBinaryOperation(node, BITWISE_OR_OP_RULES, std::size(BITWISE_OR_OP_RULES), "|", lhsType, rhsType);
332 }
333
334 19 QualType OpRuleManager::getBitwiseXorResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
335 // Remove reference wrappers
336
1/2
✓ Branch 2 → 3 taken 19 times.
✗ Branch 2 → 10 not taken.
19 const QualType lhsType = lhs.type.removeReferenceWrapper();
337
1/2
✓ Branch 3 → 4 taken 19 times.
✗ Branch 3 → 10 not taken.
19 const QualType rhsType = rhs.type.removeReferenceWrapper();
338
339
1/2
✓ Branch 6 → 7 taken 19 times.
✗ Branch 6 → 10 not taken.
38 return validateBinaryOperation(node, BITWISE_XOR_OP_RULES, std::size(BITWISE_XOR_OP_RULES), "^", lhsType, rhsType);
340 }
341
342 49 QualType OpRuleManager::getBitwiseAndResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
343 // Remove reference wrappers
344
1/2
✓ Branch 2 → 3 taken 49 times.
✗ Branch 2 → 10 not taken.
49 const QualType lhsType = lhs.type.removeReferenceWrapper();
345
1/2
✓ Branch 3 → 4 taken 49 times.
✗ Branch 3 → 10 not taken.
49 const QualType rhsType = rhs.type.removeReferenceWrapper();
346
347
1/2
✓ Branch 6 → 7 taken 49 times.
✗ Branch 6 → 10 not taken.
98 return validateBinaryOperation(node, BITWISE_AND_OP_RULES, std::size(BITWISE_AND_OP_RULES), "&", lhsType, rhsType);
348 }
349
350 4473 ExprResult OpRuleManager::getEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
351 // Check is there is an overloaded operator function available
352
1/2
✓ Branch 2 → 3 taken 4473 times.
✗ Branch 2 → 38 not taken.
4473 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_EQUAL, {lhs, rhs}, 0);
353
3/4
✓ Branch 3 → 4 taken 4473 times.
✗ Branch 3 → 39 not taken.
✓ Branch 4 → 5 taken 456 times.
✓ Branch 4 → 6 taken 4017 times.
4473 if (!resultType.type.is(TY_INVALID))
354 456 return resultType;
355
356 // Remove reference wrappers
357
1/2
✓ Branch 6 → 7 taken 4017 times.
✗ Branch 6 → 39 not taken.
4017 const QualType lhsType = lhs.type.removeReferenceWrapper();
358
1/2
✓ Branch 7 → 8 taken 4017 times.
✗ Branch 7 → 39 not taken.
4017 const QualType rhsType = rhs.type.removeReferenceWrapper();
359
360 // Allow 'pointer == unsigned long' straight away
361
10/14
✓ Branch 8 → 9 taken 4017 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 999 times.
✓ Branch 9 → 15 taken 3018 times.
✓ Branch 10 → 11 taken 999 times.
✗ Branch 10 → 39 not taken.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 15 taken 998 times.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 39 not taken.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 15 not taken.
✓ Branch 16 → 17 taken 1 time.
✓ Branch 16 → 19 taken 4016 times.
4017 if (lhsType.isPtr() && rhsType.is(TY_LONG) && rhsType.isUnsigned())
362
1/2
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 39 not taken.
1 return ExprResult(QualType(TY_BOOL));
363
364 // Allow 'string == char*' and vice versa straight away
365
11/18
✓ Branch 19 → 20 taken 4016 times.
✗ Branch 19 → 39 not taken.
✓ Branch 20 → 21 taken 158 times.
✓ Branch 20 → 23 taken 3858 times.
✓ Branch 21 → 22 taken 158 times.
✗ Branch 21 → 39 not taken.
✓ Branch 22 → 23 taken 158 times.
✗ Branch 22 → 27 not taken.
✓ Branch 23 → 24 taken 4016 times.
✗ Branch 23 → 39 not taken.
✓ Branch 24 → 25 taken 588 times.
✓ Branch 24 → 28 taken 3428 times.
✓ Branch 25 → 26 taken 588 times.
✗ Branch 25 → 39 not taken.
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 28 taken 588 times.
✗ Branch 29 → 30 not taken.
✓ Branch 29 → 32 taken 4016 times.
4016 if ((lhsType.is(TY_STRING) && rhsType.isPtrTo(TY_CHAR)) || (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING)))
366 return ExprResult(QualType(TY_BOOL));
367
368 // Check primitive type combinations
369
2/2
✓ Branch 34 → 35 taken 4015 times.
✓ Branch 34 → 39 taken 1 time.
4016 return ExprResult(validateBinaryOperation(node, EQUAL_OP_RULES, std::size(EQUAL_OP_RULES), "==", lhsType, rhsType));
370 }
371
372 1686 ExprResult OpRuleManager::getNotEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
373 // Check is there is an overloaded operator function available
374
1/2
✓ Branch 2 → 3 taken 1686 times.
✗ Branch 2 → 38 not taken.
1686 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_NOT_EQUAL, {lhs, rhs}, 0);
375
3/4
✓ Branch 3 → 4 taken 1686 times.
✗ Branch 3 → 39 not taken.
✓ Branch 4 → 5 taken 11 times.
✓ Branch 4 → 6 taken 1675 times.
1686 if (!resultType.type.is(TY_INVALID))
376 11 return resultType;
377
378 // Remove reference wrappers
379
1/2
✓ Branch 6 → 7 taken 1675 times.
✗ Branch 6 → 39 not taken.
1675 const QualType lhsType = lhs.type.removeReferenceWrapper();
380
1/2
✓ Branch 7 → 8 taken 1675 times.
✗ Branch 7 → 39 not taken.
1675 const QualType rhsType = rhs.type.removeReferenceWrapper();
381
382 // Allow 'pointer != unsigned long' straight away
383
10/14
✓ Branch 8 → 9 taken 1675 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 232 times.
✓ Branch 9 → 15 taken 1443 times.
✓ Branch 10 → 11 taken 232 times.
✗ Branch 10 → 39 not taken.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 15 taken 231 times.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 39 not taken.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 15 not taken.
✓ Branch 16 → 17 taken 1 time.
✓ Branch 16 → 19 taken 1674 times.
1675 if (lhsType.isPtr() && rhsType.is(TY_LONG) && rhsType.isUnsigned())
384
1/2
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 39 not taken.
1 return ExprResult(QualType(TY_BOOL));
385
386 // Allow 'string != char*' and vice versa straight away
387
12/18
✓ Branch 19 → 20 taken 1674 times.
✗ Branch 19 → 39 not taken.
✓ Branch 20 → 21 taken 11 times.
✓ Branch 20 → 23 taken 1663 times.
✓ Branch 21 → 22 taken 11 times.
✗ Branch 21 → 39 not taken.
✓ Branch 22 → 23 taken 11 times.
✗ Branch 22 → 27 not taken.
✓ Branch 23 → 24 taken 1674 times.
✗ Branch 23 → 39 not taken.
✓ Branch 24 → 25 taken 7 times.
✓ Branch 24 → 28 taken 1667 times.
✓ Branch 25 → 26 taken 7 times.
✗ Branch 25 → 39 not taken.
✓ Branch 26 → 27 taken 7 times.
✗ Branch 26 → 28 not taken.
✓ Branch 29 → 30 taken 7 times.
✓ Branch 29 → 32 taken 1667 times.
1674 if ((lhsType.is(TY_STRING) && rhsType.isPtrTo(TY_CHAR)) || (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING)))
388
1/2
✓ Branch 30 → 31 taken 7 times.
✗ Branch 30 → 39 not taken.
7 return ExprResult(QualType(TY_BOOL));
389
390 // Check primitive type combinations
391
1/2
✓ Branch 34 → 35 taken 1667 times.
✗ Branch 34 → 39 not taken.
1667 return ExprResult(validateBinaryOperation(node, NOT_EQUAL_OP_RULES, std::size(NOT_EQUAL_OP_RULES), "!=", lhsType, rhsType));
392 }
393
394 2046 QualType OpRuleManager::getLessResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
395 // Remove reference wrappers
396
1/2
✓ Branch 2 → 3 taken 2046 times.
✗ Branch 2 → 10 not taken.
2046 const QualType lhsType = lhs.type.removeReferenceWrapper();
397
1/2
✓ Branch 3 → 4 taken 2046 times.
✗ Branch 3 → 10 not taken.
2046 const QualType rhsType = rhs.type.removeReferenceWrapper();
398
399
1/2
✓ Branch 6 → 7 taken 2046 times.
✗ Branch 6 → 10 not taken.
4092 return validateBinaryOperation(node, LESS_OP_RULES, std::size(LESS_OP_RULES), "<", lhsType, rhsType);
400 }
401
402 577 QualType OpRuleManager::getGreaterResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
403 // Remove reference wrappers
404
1/2
✓ Branch 2 → 3 taken 577 times.
✗ Branch 2 → 10 not taken.
577 const QualType lhsType = lhs.type.removeReferenceWrapper();
405
1/2
✓ Branch 3 → 4 taken 577 times.
✗ Branch 3 → 10 not taken.
577 const QualType rhsType = rhs.type.removeReferenceWrapper();
406
407
2/2
✓ Branch 6 → 7 taken 576 times.
✓ Branch 6 → 10 taken 1 time.
1153 return validateBinaryOperation(node, GREATER_OP_RULES, std::size(GREATER_OP_RULES), ">", lhsType, rhsType);
408 }
409
410 441 QualType OpRuleManager::getLessEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
411 // Remove reference wrappers
412
1/2
✓ Branch 2 → 3 taken 441 times.
✗ Branch 2 → 10 not taken.
441 const QualType lhsType = lhs.type.removeReferenceWrapper();
413
1/2
✓ Branch 3 → 4 taken 441 times.
✗ Branch 3 → 10 not taken.
441 const QualType rhsType = rhs.type.removeReferenceWrapper();
414
415
1/2
✓ Branch 6 → 7 taken 441 times.
✗ Branch 6 → 10 not taken.
882 return validateBinaryOperation(node, LESS_EQUAL_OP_RULES, std::size(LESS_EQUAL_OP_RULES), "<=", lhsType, rhsType);
416 }
417
418 1098 QualType OpRuleManager::getGreaterEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
419 // Remove reference wrappers
420
1/2
✓ Branch 2 → 3 taken 1098 times.
✗ Branch 2 → 21 not taken.
1098 const QualType lhsType = lhs.type.removeReferenceWrapper();
421
1/2
✓ Branch 3 → 4 taken 1098 times.
✗ Branch 3 → 21 not taken.
1098 const QualType rhsType = rhs.type.removeReferenceWrapper();
422
423 // Allow 'pointer == pointer' straight away
424
7/10
✓ Branch 4 → 5 taken 1098 times.
✗ Branch 4 → 21 not taken.
✓ Branch 5 → 6 taken 4 times.
✓ Branch 5 → 9 taken 1094 times.
✓ Branch 6 → 7 taken 4 times.
✗ Branch 6 → 21 not taken.
✓ Branch 7 → 8 taken 4 times.
✗ Branch 7 → 9 not taken.
✓ Branch 10 → 11 taken 4 times.
✓ Branch 10 → 14 taken 1094 times.
1098 if (lhsType.isPtr() && rhsType.isPtr())
425
1/2
✓ Branch 11 → 12 taken 4 times.
✗ Branch 11 → 20 not taken.
4 return QualType(TY_BOOL);
426
427
1/2
✓ Branch 16 → 17 taken 1094 times.
✗ Branch 16 → 21 not taken.
1094 return validateBinaryOperation(node, GREATER_EQUAL_OP_RULES, std::size(GREATER_EQUAL_OP_RULES), ">=", lhsType, rhsType);
428 }
429
430 108 ExprResult OpRuleManager::getShiftLeftResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const {
431 // Check is there is an overloaded operator function available
432
1/2
✓ Branch 2 → 3 taken 108 times.
✗ Branch 2 → 14 not taken.
108 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_SHL, {lhs, rhs}, opIdx);
433
3/4
✓ Branch 3 → 4 taken 108 times.
✗ Branch 3 → 15 not taken.
✓ Branch 4 → 5 taken 83 times.
✓ Branch 4 → 6 taken 25 times.
108 if (!resultType.type.is(TY_INVALID))
434 83 return resultType;
435
436 // Remove reference wrappers
437
1/2
✓ Branch 6 → 7 taken 25 times.
✗ Branch 6 → 15 not taken.
25 const QualType lhsType = lhs.type.removeReferenceWrapper();
438
1/2
✓ Branch 7 → 8 taken 25 times.
✗ Branch 7 → 15 not taken.
25 const QualType rhsType = rhs.type.removeReferenceWrapper();
439
440
1/2
✓ Branch 10 → 11 taken 25 times.
✗ Branch 10 → 15 not taken.
25 return {validateBinaryOperation(node, SHIFT_LEFT_OP_RULES, std::size(SHIFT_LEFT_OP_RULES), "<<", lhsType, rhsType)};
441 }
442
443 69 ExprResult OpRuleManager::getShiftRightResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const {
444 // Check is there is an overloaded operator function available
445
1/2
✓ Branch 2 → 3 taken 69 times.
✗ Branch 2 → 14 not taken.
69 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_SHR, {lhs, rhs}, opIdx);
446
3/4
✓ Branch 3 → 4 taken 69 times.
✗ Branch 3 → 15 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 68 times.
69 if (!resultType.type.is(TY_INVALID))
447 1 return resultType;
448
449 // Remove reference wrappers
450
1/2
✓ Branch 6 → 7 taken 68 times.
✗ Branch 6 → 15 not taken.
68 const QualType lhsType = lhs.type.removeReferenceWrapper();
451
1/2
✓ Branch 7 → 8 taken 68 times.
✗ Branch 7 → 15 not taken.
68 const QualType rhsType = rhs.type.removeReferenceWrapper();
452
453
1/2
✓ Branch 10 → 11 taken 68 times.
✗ Branch 10 → 15 not taken.
68 return {validateBinaryOperation(node, SHIFT_RIGHT_OP_RULES, std::size(SHIFT_RIGHT_OP_RULES), ">>", lhsType, rhsType)};
454 }
455
456 3231 ExprResult OpRuleManager::getPlusResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const {
457 // Check is there is an overloaded operator function available
458
1/2
✓ Branch 2 → 3 taken 3231 times.
✗ Branch 2 → 32 not taken.
3231 const ExprResult result = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_PLUS, {lhs, rhs}, opIdx);
459
3/4
✓ Branch 3 → 4 taken 3231 times.
✗ Branch 3 → 35 not taken.
✓ Branch 4 → 5 taken 70 times.
✓ Branch 4 → 6 taken 3161 times.
3231 if (!result.type.is(TY_INVALID))
460 70 return result;
461
462 // Remove reference wrappers
463
1/2
✓ Branch 6 → 7 taken 3161 times.
✗ Branch 6 → 35 not taken.
3161 const QualType lhsType = lhs.type.removeReferenceWrapper();
464
1/2
✓ Branch 7 → 8 taken 3161 times.
✗ Branch 7 → 35 not taken.
3161 const QualType rhsType = rhs.type.removeReferenceWrapper();
465
466 // Allow any* + <int/long/short>
467
7/10
✓ Branch 8 → 9 taken 3161 times.
✗ Branch 8 → 33 not taken.
✓ Branch 9 → 10 taken 591 times.
✓ Branch 9 → 13 taken 2570 times.
✓ Branch 10 → 11 taken 591 times.
✗ Branch 10 → 33 not taken.
✓ Branch 11 → 12 taken 591 times.
✗ Branch 11 → 13 not taken.
✓ Branch 14 → 15 taken 591 times.
✓ Branch 14 → 17 taken 2570 times.
3161 if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) {
468
1/2
✓ Branch 15 → 16 taken 591 times.
✗ Branch 15 → 35 not taken.
591 ensureUnsafeAllowed(node, "+", lhsType, rhsType);
469 591 return {lhsType};
470 }
471 // Allow <int/long/short> + any*
472
6/10
✓ Branch 17 → 18 taken 2570 times.
✗ Branch 17 → 34 not taken.
✓ Branch 18 → 19 taken 2451 times.
✓ Branch 18 → 22 taken 119 times.
✓ Branch 19 → 20 taken 2451 times.
✗ Branch 19 → 34 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 2451 times.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 26 taken 2570 times.
2570 if (lhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT}) && rhsType.isPtr()) {
473 ensureUnsafeAllowed(node, "+", lhsType, rhsType);
474 return {rhsType};
475 }
476
477
2/2
✓ Branch 28 → 29 taken 2569 times.
✓ Branch 28 → 35 taken 1 time.
2570 return {validateBinaryOperation(node, PLUS_OP_RULES, std::size(PLUS_OP_RULES), "+", lhsType, rhsType)};
478 }
479
480 2052 ExprResult OpRuleManager::getMinusResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const {
481 // Check is there is an overloaded operator function available
482
1/2
✓ Branch 2 → 3 taken 2052 times.
✗ Branch 2 → 32 not taken.
2052 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MINUS, {lhs, rhs}, opIdx);
483
3/4
✓ Branch 3 → 4 taken 2052 times.
✗ Branch 3 → 35 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 2051 times.
2052 if (!resultType.type.is(TY_INVALID))
484 1 return resultType;
485
486 // Remove reference wrappers
487
1/2
✓ Branch 6 → 7 taken 2051 times.
✗ Branch 6 → 35 not taken.
2051 const QualType lhsType = lhs.type.removeReferenceWrapper();
488
1/2
✓ Branch 7 → 8 taken 2051 times.
✗ Branch 7 → 35 not taken.
2051 const QualType rhsType = rhs.type.removeReferenceWrapper();
489
490 // Allow any* - <int/long/short>
491
7/10
✓ Branch 8 → 9 taken 2051 times.
✗ Branch 8 → 33 not taken.
✓ Branch 9 → 10 taken 3 times.
✓ Branch 9 → 13 taken 2048 times.
✓ Branch 10 → 11 taken 3 times.
✗ Branch 10 → 33 not taken.
✓ Branch 11 → 12 taken 3 times.
✗ Branch 11 → 13 not taken.
✓ Branch 14 → 15 taken 3 times.
✓ Branch 14 → 17 taken 2048 times.
2051 if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) {
492
1/2
✓ Branch 15 → 16 taken 3 times.
✗ Branch 15 → 35 not taken.
3 ensureUnsafeAllowed(node, "-", lhsType, rhsType);
493 3 return {lhs};
494 }
495 // Allow <int/long/short> - any*
496
6/10
✓ Branch 17 → 18 taken 2048 times.
✗ Branch 17 → 34 not taken.
✓ Branch 18 → 19 taken 2035 times.
✓ Branch 18 → 22 taken 13 times.
✓ Branch 19 → 20 taken 2035 times.
✗ Branch 19 → 34 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 2035 times.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 26 taken 2048 times.
2048 if (lhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT}) && rhsType.isPtr()) {
497 ensureUnsafeAllowed(node, "-", lhsType, rhsType);
498 return {rhs};
499 }
500
501
1/2
✓ Branch 28 → 29 taken 2048 times.
✗ Branch 28 → 35 not taken.
2048 return {validateBinaryOperation(node, MINUS_OP_RULES, std::size(MINUS_OP_RULES), "-", lhsType, rhsType)};
502 }
503
504 835 ExprResult OpRuleManager::getMulResultType(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 835 times.
✗ Branch 2 → 14 not taken.
835 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MUL, {lhs, rhs}, opIdx);
507
3/4
✓ Branch 3 → 4 taken 835 times.
✗ Branch 3 → 15 not taken.
✓ Branch 4 → 5 taken 9 times.
✓ Branch 4 → 6 taken 826 times.
835 if (!resultType.type.is(TY_INVALID))
508 9 return resultType;
509
510 // Remove reference wrappers
511
1/2
✓ Branch 6 → 7 taken 826 times.
✗ Branch 6 → 15 not taken.
826 const QualType lhsType = lhs.type.removeReferenceWrapper();
512
1/2
✓ Branch 7 → 8 taken 826 times.
✗ Branch 7 → 15 not taken.
826 const QualType rhsType = rhs.type.removeReferenceWrapper();
513
514
2/2
✓ Branch 10 → 11 taken 825 times.
✓ Branch 10 → 15 taken 1 time.
826 return {validateBinaryOperation(node, MUL_OP_RULES, std::size(MUL_OP_RULES), "*", lhsType, rhsType)};
515 }
516
517 170 ExprResult OpRuleManager::getDivResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const {
518 // Check is there is an overloaded operator function available
519
1/2
✓ Branch 2 → 3 taken 170 times.
✗ Branch 2 → 14 not taken.
170 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_DIV, {lhs, rhs}, opIdx);
520
3/4
✓ Branch 3 → 4 taken 170 times.
✗ Branch 3 → 15 not taken.
✓ Branch 4 → 5 taken 3 times.
✓ Branch 4 → 6 taken 167 times.
170 if (!resultType.type.is(TY_INVALID))
521 3 return resultType;
522
523 // Remove reference wrappers
524
1/2
✓ Branch 6 → 7 taken 167 times.
✗ Branch 6 → 15 not taken.
167 const QualType lhsType = lhs.type.removeReferenceWrapper();
525
1/2
✓ Branch 7 → 8 taken 167 times.
✗ Branch 7 → 15 not taken.
167 const QualType rhsType = rhs.type.removeReferenceWrapper();
526
527
1/2
✓ Branch 10 → 11 taken 167 times.
✗ Branch 10 → 15 not taken.
167 return {validateBinaryOperation(node, DIV_OP_RULES, std::size(DIV_OP_RULES), "/", lhsType, rhsType)};
528 }
529
530 25 ExprResult OpRuleManager::getRemResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
531 // Remove reference wrappers
532
1/2
✓ Branch 2 → 3 taken 25 times.
✗ Branch 2 → 10 not taken.
25 const QualType lhsType = lhs.type.removeReferenceWrapper();
533
1/2
✓ Branch 3 → 4 taken 25 times.
✗ Branch 3 → 10 not taken.
25 const QualType rhsType = rhs.type.removeReferenceWrapper();
534
535
1/2
✓ Branch 6 → 7 taken 25 times.
✗ Branch 6 → 10 not taken.
50 return {validateBinaryOperation(node, REM_OP_RULES, std::size(REM_OP_RULES), "%", lhsType, rhsType)};
536 }
537
538 893 QualType OpRuleManager::getPrefixMinusResultType(const ASTNode *node, const ExprResult &lhs) {
539 // Remove reference wrappers
540
1/2
✓ Branch 2 → 3 taken 893 times.
✗ Branch 2 → 9 not taken.
893 const QualType lhsType = lhs.type.removeReferenceWrapper();
541
542
1/2
✓ Branch 5 → 6 taken 893 times.
✗ Branch 5 → 9 not taken.
1786 return validateUnaryOperation(node, PREFIX_MINUS_OP_RULES, std::size(PREFIX_MINUS_OP_RULES), "-", lhsType);
543 }
544
545 26 QualType OpRuleManager::getPrefixPlusPlusResultType(const ASTNode *node, const ExprResult &lhs) const {
546 // Check if we try to assign a constant value
547
1/2
✓ Branch 2 → 3 taken 26 times.
✗ Branch 2 → 14 not taken.
26 ensureNoConstAssign(node, lhs.type);
548
549 // Remove reference wrappers
550
1/2
✓ Branch 3 → 4 taken 26 times.
✗ Branch 3 → 14 not taken.
26 const QualType lhsType = lhs.type.removeReferenceWrapper();
551
552 // Check if this is an unsafe operation
553
2/4
✓ Branch 4 → 5 taken 26 times.
✗ Branch 4 → 14 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 26 times.
26 if (lhsType.isPtr()) {
554 ensureUnsafeAllowed(node, "++", lhsType);
555 return lhsType;
556 }
557
558
1/2
✓ Branch 10 → 11 taken 26 times.
✗ Branch 10 → 14 not taken.
26 return validateUnaryOperation(node, PREFIX_PLUS_PLUS_OP_RULES, std::size(PREFIX_PLUS_PLUS_OP_RULES), "++", lhsType);
559 }
560
561 11 QualType OpRuleManager::getPrefixMinusMinusResultType(const ASTNode *node, const ExprResult &lhs) const {
562 // Check if we try to assign a constant value
563
1/2
✓ Branch 2 → 3 taken 11 times.
✗ Branch 2 → 14 not taken.
11 ensureNoConstAssign(node, lhs.type);
564
565 // Remove reference wrappers
566
1/2
✓ Branch 3 → 4 taken 11 times.
✗ Branch 3 → 14 not taken.
11 const QualType lhsType = lhs.type.removeReferenceWrapper();
567
568 // Check if this is an unsafe operation
569
2/4
✓ Branch 4 → 5 taken 11 times.
✗ Branch 4 → 14 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 11 times.
11 if (lhsType.isPtr()) {
570 ensureUnsafeAllowed(node, "--", lhsType);
571 return lhsType;
572 }
573
574
2/2
✓ Branch 10 → 11 taken 10 times.
✓ Branch 10 → 14 taken 1 time.
11 return validateUnaryOperation(node, PREFIX_MINUS_MINUS_OP_RULES, std::size(PREFIX_MINUS_MINUS_OP_RULES), "--", lhsType);
575 }
576
577 803 QualType OpRuleManager::getPrefixNotResultType(const ASTNode *node, const ExprResult &lhs) {
578 // Remove reference wrappers
579
1/2
✓ Branch 2 → 3 taken 803 times.
✗ Branch 2 → 9 not taken.
803 const QualType lhsType = lhs.type.removeReferenceWrapper();
580
581
1/2
✓ Branch 5 → 6 taken 803 times.
✗ Branch 5 → 9 not taken.
1606 return validateUnaryOperation(node, PREFIX_NOT_OP_RULES, std::size(PREFIX_NOT_OP_RULES), "!", lhsType);
582 }
583
584 5 QualType OpRuleManager::getPrefixBitwiseNotResultType(const ASTNode *node, const ExprResult &lhs) {
585 // Remove reference wrappers
586
1/2
✓ Branch 2 → 3 taken 5 times.
✗ Branch 2 → 9 not taken.
5 const QualType lhsType = lhs.type.removeReferenceWrapper();
587
588
1/2
✓ Branch 5 → 6 taken 5 times.
✗ Branch 5 → 9 not taken.
10 return validateUnaryOperation(node, PREFIX_BITWISE_NOT_OP_RULES, std::size(PREFIX_BITWISE_NOT_OP_RULES), "~", lhsType);
589 }
590
591 238 QualType OpRuleManager::getPrefixMulResultType(const ASTNode *node, const ExprResult &lhs) {
592 // Remove reference wrappers
593
1/2
✓ Branch 2 → 3 taken 238 times.
✗ Branch 2 → 25 not taken.
238 const QualType lhsType = lhs.type.removeReferenceWrapper();
594
595
3/4
✓ Branch 3 → 4 taken 238 times.
✗ Branch 3 → 25 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 12 taken 237 times.
238 if (!lhsType.isPtr())
596
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));
597
1/2
✓ Branch 12 → 13 taken 237 times.
✗ Branch 12 → 25 not taken.
474 return lhsType.getContained();
598 }
599
600 182 QualType OpRuleManager::getPrefixBitwiseAndResultType(const ASTNode *node, const ExprResult &lhs) {
601 // Remove reference wrappers
602
1/2
✓ Branch 2 → 3 taken 182 times.
✗ Branch 2 → 7 not taken.
182 const QualType lhsType = lhs.type.removeReferenceWrapper();
603
604
1/2
✓ Branch 3 → 4 taken 182 times.
✗ Branch 3 → 7 not taken.
364 return lhsType.toPtr(node);
605 }
606
607 1952 ExprResult OpRuleManager::getPostfixPlusPlusResultType(ASTNode *node, const ExprResult &lhs) const {
608 // Check is there is an overloaded operator function available
609
2/2
✓ Branch 2 → 3 taken 1951 times.
✓ Branch 2 → 18 taken 1 time.
1952 const ExprResult resultType = isOperatorOverloadingFctAvailable<1>(node, OP_FCT_POSTFIX_PLUS_PLUS, {lhs}, 0);
610
3/4
✓ Branch 3 → 4 taken 1951 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 9 times.
✓ Branch 4 → 6 taken 1942 times.
1951 if (!resultType.type.is(TY_INVALID))
611 9 return resultType;
612
613 // Check if we try to assign a constant value
614
1/2
✓ Branch 6 → 7 taken 1942 times.
✗ Branch 6 → 19 not taken.
1942 ensureNoConstAssign(node, lhs.type);
615
616 // Remove reference wrappers
617
1/2
✓ Branch 7 → 8 taken 1942 times.
✗ Branch 7 → 19 not taken.
1942 const QualType lhsType = lhs.type.removeReferenceWrapper();
618
619 // Check if this is an unsafe operation
620
3/4
✓ Branch 8 → 9 taken 1942 times.
✗ Branch 8 → 19 not taken.
✓ Branch 9 → 10 taken 9 times.
✓ Branch 9 → 12 taken 1933 times.
1942 if (lhsType.isPtr()) {
621
1/2
✓ Branch 10 → 11 taken 9 times.
✗ Branch 10 → 19 not taken.
9 ensureUnsafeAllowed(node, "++", lhsType);
622 9 return {lhs};
623 }
624
625
2/2
✓ Branch 14 → 15 taken 1932 times.
✓ Branch 14 → 19 taken 1 time.
1933 return {validateUnaryOperation(node, POSTFIX_PLUS_PLUS_OP_RULES, std::size(POSTFIX_PLUS_PLUS_OP_RULES), "++", lhsType)};
626 }
627
628 450 ExprResult OpRuleManager::getPostfixMinusMinusResultType(ASTNode *node, const ExprResult &lhs) const {
629 // Check is there is an overloaded operator function available
630
1/2
✓ Branch 2 → 3 taken 450 times.
✗ Branch 2 → 18 not taken.
450 const ExprResult resultType = isOperatorOverloadingFctAvailable<1>(node, OP_FCT_POSTFIX_MINUS_MINUS, {lhs}, 0);
631
3/4
✓ Branch 3 → 4 taken 450 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 7 times.
✓ Branch 4 → 6 taken 443 times.
450 if (!resultType.type.is(TY_INVALID))
632 7 return resultType;
633
634 // Check if we try to assign a constant value
635
1/2
✓ Branch 6 → 7 taken 443 times.
✗ Branch 6 → 19 not taken.
443 ensureNoConstAssign(node, lhs.type);
636
637 // Remove reference wrappers
638
1/2
✓ Branch 7 → 8 taken 443 times.
✗ Branch 7 → 19 not taken.
443 const QualType lhsType = lhs.type.removeReferenceWrapper();
639
640 // Check if this is an unsafe operation
641
3/4
✓ Branch 8 → 9 taken 443 times.
✗ Branch 8 → 19 not taken.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 12 taken 441 times.
443 if (lhsType.isPtr()) {
642
1/2
✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 19 not taken.
2 ensureUnsafeAllowed(node, "--", lhsType);
643 2 return {lhs};
644 }
645
646
1/2
✓ Branch 14 → 15 taken 441 times.
✗ Branch 14 → 19 not taken.
441 return {validateUnaryOperation(node, POSTFIX_MINUS_MINUS_OP_RULES, std::size(POSTFIX_MINUS_MINUS_OP_RULES), "--", lhsType)};
647 }
648
649 2830 QualType OpRuleManager::getCastResultType(const ASTNode *node, QualType lhsType, const ExprResult &rhs) const {
650 // Remove reference wrappers
651
1/2
✓ Branch 2 → 3 taken 2830 times.
✗ Branch 2 → 57 not taken.
2830 lhsType = lhsType.removeReferenceWrapper();
652
1/2
✓ Branch 3 → 4 taken 2830 times.
✗ Branch 3 → 65 not taken.
2830 QualType rhsType = rhs.type.removeReferenceWrapper();
653
654 // Only allow to cast the 'heap' qualifier away, if we are in unsafe mode
655
2/2
✓ Branch 6 → 7 taken 111 times.
✓ Branch 6 → 8 taken 2719 times.
2830 if (lhsType.getQualifiers().isHeap != rhsType.getQualifiers().isHeap)
656
1/2
✓ Branch 7 → 8 taken 111 times.
✗ Branch 7 → 65 not taken.
111 ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType);
657
658 // Allow identity casts
659
3/4
✓ Branch 8 → 9 taken 2830 times.
✗ Branch 8 → 65 not taken.
✓ Branch 9 → 10 taken 297 times.
✓ Branch 9 → 11 taken 2533 times.
2830 if (lhsType.matches(rhsType, false, true, true))
660 297 return lhsType;
661 // Allow casts string -> char* and string -> char[]
662
12/16
✓ Branch 11 → 12 taken 2533 times.
✗ Branch 11 → 58 not taken.
✓ Branch 12 → 13 taken 1233 times.
✓ Branch 12 → 19 taken 1300 times.
✓ Branch 13 → 14 taken 1233 times.
✗ Branch 13 → 58 not taken.
✓ Branch 14 → 15 taken 1233 times.
✗ Branch 14 → 58 not taken.
✓ Branch 15 → 16 taken 983 times.
✓ Branch 15 → 19 taken 250 times.
✓ Branch 16 → 17 taken 983 times.
✗ Branch 16 → 58 not taken.
✓ Branch 17 → 18 taken 979 times.
✓ Branch 17 → 19 taken 4 times.
✓ Branch 20 → 21 taken 979 times.
✓ Branch 20 → 22 taken 1554 times.
2533 if (lhsType.isOneOf({TY_PTR, TY_ARRAY}) && lhsType.getContained().is(TY_CHAR) && rhsType.is(TY_STRING))
663 979 return lhsType;
664 // Allow casts char* -> string and char[] -> string
665
10/16
✓ Branch 22 → 23 taken 1554 times.
✗ Branch 22 → 60 not taken.
✓ Branch 23 → 24 taken 100 times.
✓ Branch 23 → 30 taken 1454 times.
✓ Branch 24 → 25 taken 100 times.
✗ Branch 24 → 60 not taken.
✓ Branch 25 → 26 taken 100 times.
✗ Branch 25 → 30 not taken.
✓ Branch 26 → 27 taken 100 times.
✗ Branch 26 → 60 not taken.
✓ Branch 27 → 28 taken 100 times.
✗ Branch 27 → 60 not taken.
✓ Branch 28 → 29 taken 100 times.
✗ Branch 28 → 30 not taken.
✓ Branch 31 → 32 taken 100 times.
✓ Branch 31 → 33 taken 1454 times.
1554 if (lhsType.is(TY_STRING) && rhsType.isOneOf({TY_PTR, TY_ARRAY}) && rhsType.getContained().is(TY_CHAR))
666 100 return lhsType;
667 // Allow casts any* -> any*
668
8/10
✓ Branch 33 → 34 taken 1454 times.
✗ Branch 33 → 62 not taken.
✓ Branch 34 → 35 taken 254 times.
✓ Branch 34 → 38 taken 1200 times.
✓ Branch 35 → 36 taken 254 times.
✗ Branch 35 → 62 not taken.
✓ Branch 36 → 37 taken 246 times.
✓ Branch 36 → 38 taken 8 times.
✓ Branch 39 → 40 taken 246 times.
✓ Branch 39 → 42 taken 1208 times.
1454 if (lhsType.isOneOf({TY_PTR, TY_STRING}) && rhsType.isOneOf({TY_PTR, TY_STRING})) {
669
1/2
✓ Branch 40 → 41 taken 246 times.
✗ Branch 40 → 65 not taken.
246 ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType);
670 246 return lhsType;
671 }
672 // Allow casts p()/f<>() -> byte*
673
7/10
✓ Branch 42 → 43 taken 1208 times.
✗ Branch 42 → 64 not taken.
✓ Branch 43 → 44 taken 8 times.
✓ Branch 43 → 47 taken 1200 times.
✓ Branch 44 → 45 taken 8 times.
✗ Branch 44 → 64 not taken.
✓ Branch 45 → 46 taken 8 times.
✗ Branch 45 → 47 not taken.
✓ Branch 48 → 49 taken 8 times.
✓ Branch 48 → 51 taken 1200 times.
1208 if (lhsType.isPtrTo(TY_BYTE) && rhsType.isOneOf({TY_FUNCTION, TY_PROCEDURE})) {
674
1/2
✓ Branch 49 → 50 taken 8 times.
✗ Branch 49 → 65 not taken.
8 ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType);
675 8 return lhsType;
676 }
677 // Check primitive type combinations
678
1/2
✓ Branch 53 → 54 taken 1200 times.
✗ Branch 53 → 65 not taken.
1200 return validateBinaryOperation(node, CAST_OP_RULES, std::size(CAST_OP_RULES), "(cast)", lhsType, rhsType, true);
679 }
680
681 template <size_t N>
682 19132 ExprResult OpRuleManager::isOperatorOverloadingFctAvailable(ASTNode *node, const char *const fctName,
683 const std::array<ExprResult, N> &op, size_t opIdx) const {
684 static_assert(N == 1 || N == 2, "Only unary and binary operators are overloadable");
685 19132 Scope *calleeParentScope = nullptr;
686 19132 const Function *callee = nullptr;
687
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 2402 times.
✗ Branch 2 → 123 not taken.
✓ Branch 3 → 4 taken 2402 times.
✗ Branch 3 → 123 not taken.
✓ Branch 4 → 5 taken 2402 times.
✗ Branch 4 → 123 not taken.
✓ Branch 42 → 43 taken 2538 times.
✓ Branch 42 → 45 taken 17 times.
✓ Branch 48 → 6 taken 20475 times.
✓ Branch 48 → 49 taken 2385 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 16730 times.
✗ Branch 2 → 132 not taken.
✓ Branch 3 → 4 taken 16730 times.
✗ Branch 3 → 132 not taken.
✓ Branch 4 → 5 taken 16730 times.
✗ Branch 4 → 132 not taken.
✓ Branch 49 → 50 taken 55519 times.
✓ Branch 49 → 52 taken 907 times.
✓ Branch 55 → 6 taken 136247 times.
✓ Branch 55 → 56 taken 15823 times.
233911 for (const auto &sourceFile : typeChecker->resourceManager.sourceFiles | std::views::values) {
688 // Check if there is a registered operator function
689
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 20475 times.
✗ Branch 10 → 102 not taken.
✓ Branch 11 → 12 taken 20475 times.
✗ Branch 11 → 100 not taken.
✓ Branch 14 → 15 taken 17920 times.
✓ Branch 14 → 16 taken 2555 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 136247 times.
✗ Branch 10 → 109 not taken.
✓ Branch 11 → 12 taken 136247 times.
✗ Branch 11 → 107 not taken.
✓ Branch 14 → 15 taken 79821 times.
✓ Branch 14 → 16 taken 56426 times.
470166 if (!sourceFile->getNameRegistryEntry(fctName))
690 97741 continue;
691
692 // Match callees in the global scope of this source file
693 58981 calleeParentScope = sourceFile->globalScope.get();
694
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 2555 times.
✗ Branch 18 → 122 not taken.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 18 → 19 taken 56426 times.
✗ Branch 18 → 131 not taken.
58981 const QualType thisType(TY_DYN);
695
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 2555 times.
✗ Branch 21 → 106 not taken.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 21 → 22 taken 56426 times.
✗ Branch 21 → 113 not taken.
58981 ArgList args(N);
696
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 2555 times.
✗ Branch 24 → 109 not taken.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 24 → 25 taken 56426 times.
✗ Branch 24 → 116 not taken.
58981 args[0] = {typeChecker->mapLocalTypeToImportedScopeType(calleeParentScope, op[0].type), op[0].isTemporary()};
697 if constexpr (N == 2)
698
1/2
✓ Branch 31 → 32 taken 56426 times.
✗ Branch 31 → 118 not taken.
56426 args[1] = {typeChecker->mapLocalTypeToImportedScopeType(calleeParentScope, op[1].type), op[1].isTemporary()};
699
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 2555 times.
✗ Branch 33 → 113 not taken.
✓ Branch 34 → 35 taken 2555 times.
✗ Branch 34 → 111 not taken.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 40 → 41 taken 56426 times.
✗ Branch 40 → 122 not taken.
✓ Branch 41 → 42 taken 56426 times.
✗ Branch 41 → 120 not taken.
176943 callee = FunctionManager::match(calleeParentScope, fctName, thisType, args, {}, false, node);
700
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 17 times.
✓ Branch 38 → 40 taken 2538 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 907 times.
✓ Branch 45 → 47 taken 55519 times.
58981 if (callee)
701 924 break;
702 }
703
704 // Return invalid type if the callee was not found
705
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 49 → 50 taken 2385 times.
✓ Branch 49 → 52 taken 17 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 56 → 57 taken 15823 times.
✓ Branch 56 → 59 taken 907 times.
19132 if (!callee)
706 18208 return ExprResult(QualType(TY_INVALID));
707
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 52 → 53 not taken.
✓ Branch 52 → 54 taken 17 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✗ Branch 59 → 60 not taken.
✓ Branch 59 → 61 taken 907 times.
924 assert(calleeParentScope != nullptr);
708
709 // Save the pointer to the operator function in the AST node
710 924 std::vector<const Function *> &opFctPointers = typeChecker->getOpFctPointers(node);
711
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 56 → 57 not taken.
✓ Branch 56 → 59 taken 17 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 63 → 64 taken 74 times.
✓ Branch 63 → 66 taken 833 times.
924 if (opFctPointers.size() <= opIdx)
712
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 57 → 58 not taken.
✗ Branch 57 → 124 not taken.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 64 → 65 taken 74 times.
✗ Branch 64 → 133 not taken.
74 opFctPointers.resize(opIdx + 1, nullptr);
713 924 opFctPointers.at(opIdx) = callee;
714
715 // Check if we need to request a re-visit, because the function body was not type-checked yet
716 924 TypeChecker::requestRevisitIfRequired(callee);
717
718 // Check if the called function has sufficient visibility
719
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 61 → 62 taken 17 times.
✗ Branch 61 → 65 not taken.
✓ Branch 63 → 64 taken 15 times.
✓ Branch 63 → 65 taken 2 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 68 → 69 taken 907 times.
✗ Branch 68 → 72 not taken.
✓ Branch 70 → 71 taken 397 times.
✓ Branch 70 → 72 taken 510 times.
924 const bool isImported = calleeParentScope != nullptr && calleeParentScope->isImportedBy(typeChecker->rootScope);
720 924 const SymbolTableEntry *calleeEntry = callee->entry;
721
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 66 → 67 taken 15 times.
✓ Branch 66 → 71 taken 2 times.
✓ Branch 69 → 70 taken 1 time.
✓ Branch 69 → 71 taken 14 times.
✓ Branch 72 → 73 taken 1 time.
✓ Branch 72 → 82 taken 16 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 73 → 74 taken 397 times.
✓ Branch 73 → 78 taken 510 times.
✗ Branch 76 → 77 not taken.
✓ Branch 76 → 78 taken 397 times.
✗ Branch 79 → 80 not taken.
✓ Branch 79 → 89 taken 907 times.
924 if (isImported && !calleeEntry->getQualType().isPublic())
722
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 77 → 78 taken 1 time.
✗ Branch 77 → 125 not taken.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✗ Branch 84 → 85 not taken.
✗ Branch 84 → 134 not taken.
2 throw SemanticError(node, INSUFFICIENT_VISIBILITY,
723
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 74 → 75 taken 1 time.
✗ Branch 74 → 132 not taken.
✓ Branch 75 → 76 taken 1 time.
✗ Branch 75 → 130 not taken.
✓ Branch 76 → 77 taken 1 time.
✗ Branch 76 → 128 not taken.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✗ Branch 81 → 82 not taken.
✗ Branch 81 → 141 not taken.
✗ Branch 82 → 83 not taken.
✗ Branch 82 → 139 not taken.
✗ Branch 83 → 84 not taken.
✗ Branch 83 → 137 not taken.
2 "Overloaded operator '" + callee->getSignature() + "' has insufficient visibility");
724
725 // Procedures always have the return type 'bool'
726
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 85 → 86 taken 14 times.
✓ Branch 85 → 88 taken 2 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 92 → 93 taken 148 times.
✓ Branch 92 → 95 taken 759 times.
923 if (callee->isProcedure())
727 162 return ExprResult(QualType(TY_BOOL));
728 761 const QualType &returnType = callee->returnType;
729
730 // Add anonymous symbol to keep track of dtor call, if non-trivially destructible
731 761 SymbolTableEntry *anonymousSymbol = nullptr;
732
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 89 → 90 not taken.
✓ Branch 89 → 93 taken 2 times.
✗ Branch 91 → 92 not taken.
✗ Branch 91 → 93 not taken.
✗ Branch 94 → 95 not taken.
✓ Branch 94 → 97 taken 2 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 96 → 97 taken 85 times.
✓ Branch 96 → 100 taken 674 times.
✓ Branch 98 → 99 taken 79 times.
✓ Branch 98 → 100 taken 6 times.
✓ Branch 101 → 102 taken 79 times.
✓ Branch 101 → 104 taken 680 times.
761 if (returnType.is(TY_STRUCT) && !returnType.isTriviallyDestructible(node))
733 79 anonymousSymbol = typeChecker->currentScope->symbolTable.insertAnonymous(returnType, node, opIdx);
734
735 761 return {typeChecker->mapImportedScopeTypeToLocalType(calleeParentScope, returnType), anonymousSymbol};
736 }
737
738 4112 QualType OpRuleManager::validateUnaryOperation(const ASTNode *node, const UnaryOpRule opRules[], size_t opRulesSize,
739 const char *name, const QualType &lhs) {
740
2/2
✓ Branch 11 → 3 taken 10032 times.
✓ Branch 11 → 12 taken 2 times.
10034 for (size_t i = 0; i < opRulesSize; i++) {
741 10032 const UnaryOpRule &rule = opRules[i];
742
2/2
✓ Branch 5 → 6 taken 4110 times.
✓ Branch 5 → 10 taken 5922 times.
10032 if (std::get<0>(rule) == lhs.getSuperType())
743
1/2
✓ Branch 7 → 8 taken 4110 times.
✗ Branch 7 → 16 not taken.
4110 return QualType(std::get<1>(rule));
744 }
745
1/2
✓ Branch 13 → 14 taken 2 times.
✗ Branch 13 → 17 not taken.
2 throw getExceptionUnary(node, name, lhs);
746 }
747
748 39883 QualType OpRuleManager::validateBinaryOperation(const ASTNode *node, const BinaryOpRule opRules[], size_t opRulesSize,
749 const char *name, const QualType &lhs, const QualType &rhs,
750 bool preserveQualifiersFromLhs, const char *customMessagePrefix) {
751
2/2
✓ Branch 19 → 3 taken 394414 times.
✓ Branch 19 → 20 taken 19 times.
394433 for (size_t i = 0; i < opRulesSize; i++) {
752 394414 const BinaryOpRule &rule = opRules[i];
753
6/6
✓ Branch 5 → 6 taken 77599 times.
✓ Branch 5 → 10 taken 316815 times.
✓ Branch 8 → 9 taken 39864 times.
✓ Branch 8 → 10 taken 37735 times.
✓ Branch 11 → 12 taken 39864 times.
✓ Branch 11 → 18 taken 354550 times.
394414 if (std::get<0>(rule) == lhs.getSuperType() && std::get<1>(rule) == rhs.getSuperType()) {
754
1/2
✓ Branch 13 → 14 taken 39864 times.
✗ Branch 13 → 24 not taken.
39864 QualType resultType((std::get<2>(rule)));
755
2/2
✓ Branch 14 → 15 taken 21905 times.
✓ Branch 14 → 17 taken 17959 times.
39864 if (preserveQualifiersFromLhs)
756 21905 resultType.setQualifiers(lhs.getQualifiers());
757 39864 return resultType;
758 }
759 }
760
1/2
✓ Branch 21 → 22 taken 19 times.
✗ Branch 21 → 25 not taken.
19 throw getExceptionBinary(node, name, lhs, rhs, customMessagePrefix);
761 }
762
763 2 SemanticError OpRuleManager::getExceptionUnary(const ASTNode *node, const char *name, const QualType &lhs) {
764
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)};
765 }
766
767 19 SemanticError OpRuleManager::getExceptionBinary(const ASTNode *node, const char *name, const QualType &lhs, const QualType &rhs,
768 const char *messagePrefix) {
769 // Build error message
770
1/2
✓ Branch 2 → 3 taken 19 times.
✗ Branch 2 → 50 not taken.
19 std::stringstream errorMsg;
771
2/2
✓ Branch 3 → 4 taken 4 times.
✓ Branch 3 → 14 taken 15 times.
19 if (strlen(messagePrefix) != 0)
772
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);
773 else
774
8/16
✓ Branch 14 → 15 taken 15 times.
✗ Branch 14 → 48 not taken.
✓ Branch 15 → 16 taken 15 times.
✗ Branch 15 → 48 not taken.
✓ Branch 16 → 17 taken 15 times.
✗ Branch 16 → 48 not taken.
✓ Branch 17 → 18 taken 15 times.
✗ Branch 17 → 43 not taken.
✓ Branch 18 → 19 taken 15 times.
✗ Branch 18 → 41 not taken.
✓ Branch 19 → 20 taken 15 times.
✗ Branch 19 → 41 not taken.
✓ Branch 20 → 21 taken 15 times.
✗ Branch 20 → 40 not taken.
✓ Branch 21 → 22 taken 15 times.
✗ Branch 21 → 38 not taken.
15 errorMsg << "Cannot apply '" << name << "' operator on types " << lhs.getName(true) << " and " << rhs.getName(true);
775
776 // Return the exception
777
2/4
✓ Branch 25 → 26 taken 19 times.
✗ Branch 25 → 46 not taken.
✓ Branch 26 → 27 taken 19 times.
✗ Branch 26 → 44 not taken.
57 return {node, OPERATOR_WRONG_DATA_TYPE, errorMsg.str()};
778 19 }
779
780 11 void OpRuleManager::ensureUnsafeAllowed(const ASTNode *node, const char *name, const QualType &lhs) const {
781
2/4
✓ Branch 2 → 3 taken 11 times.
✗ Branch 2 → 43 not taken.
✓ Branch 3 → 4 taken 11 times.
✗ Branch 3 → 5 not taken.
11 if (typeChecker->currentScope->doesAllowUnsafeOperations())
782 11 return;
783 // Print error message
784 const std::string lhsName = lhs.getName(true);
785 const std::string errorMsg = "Cannot apply '" + std::string(name) + "' operator on type " + lhsName +
786 " as this is an unsafe operation. Please use unsafe blocks if you know what you are doing.";
787 SOFT_ERROR_VOID(node, UNSAFE_OPERATION_IN_SAFE_CONTEXT, errorMsg)
788 }
789
790 969 void OpRuleManager::ensureUnsafeAllowed(const ASTNode *node, const char *name, const QualType &lhs, const QualType &rhs) const {
791
3/4
✓ Branch 2 → 3 taken 969 times.
✗ Branch 2 → 57 not taken.
✓ Branch 3 → 4 taken 968 times.
✓ Branch 3 → 5 taken 1 time.
969 if (typeChecker->currentScope->doesAllowUnsafeOperations())
792 968 return;
793 // Print error message
794
1/2
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 57 not taken.
1 const std::string lhsName = lhs.getName(true);
795
1/2
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 55 not taken.
1 const std::string rhsName = rhs.getName(true);
796
6/12
✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 42 not taken.
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 40 not taken.
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 38 not taken.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 36 not taken.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 34 not taken.
✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 32 not taken.
2 const std::string errorMsg = "Cannot apply '" + std::string(name) + "' operator on types " + lhsName + " and " + rhsName +
797
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.";
798
1/2
✓ Branch 23 → 24 taken 1 time.
✗ Branch 23 → 51 not taken.
1 SOFT_ERROR_VOID(node, UNSAFE_OPERATION_IN_SAFE_CONTEXT, errorMsg)
799 1 }
800
801 31036 void OpRuleManager::ensureNoConstAssign(const ASTNode *node, const QualType &lhs, bool isDecl, bool isReturn) const {
802 // Check if we try to assign a constant value
803
10/12
✓ Branch 2 → 3 taken 31036 times.
✗ Branch 2 → 18 not taken.
✓ Branch 3 → 4 taken 31036 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 3500 times.
✓ Branch 4 → 8 taken 27536 times.
✓ Branch 5 → 6 taken 55 times.
✓ Branch 5 → 8 taken 3445 times.
✓ Branch 6 → 7 taken 14 times.
✓ Branch 6 → 8 taken 41 times.
✓ Branch 9 → 10 taken 14 times.
✓ Branch 9 → 17 taken 31022 times.
31036 if (lhs.removeReferenceWrapper().isConst() && !isDecl && !isReturn) {
804
2/4
✓ Branch 10 → 11 taken 14 times.
✗ Branch 10 → 21 not taken.
✓ Branch 11 → 12 taken 14 times.
✗ Branch 11 → 19 not taken.
14 const std::string errorMessage = "Trying to assign value to an immutable variable of type " + lhs.getName(true);
805
1/2
✓ Branch 13 → 14 taken 14 times.
✗ Branch 13 → 22 not taken.
14 SOFT_ERROR_VOID(node, REASSIGN_CONST_VARIABLE, errorMessage);
806 14 }
807 }
808
809 } // namespace spice::compiler
810