GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 95.6% 434 / 0 / 454
Functions: 100.0% 51 / 0 / 51
Branches: 62.2% 728 / 0 / 1170

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 <global/RuntimeModuleManager.h>
9 #include <typechecker/MacroDefs.h>
10 #include <typechecker/TypeChecker.h>
11
12 namespace spice::compiler {
13
14 3620 OpRuleManager::OpRuleManager(TypeChecker *typeChecker)
15 3620 : typeChecker(typeChecker), resourceManager(typeChecker->resourceManager) {}
16
17 26950 std::pair<QualType, Function *> OpRuleManager::getAssignResultType(const ASTNode *node, const ExprResult &lhs,
18 const ExprResult &rhs, bool isDecl, bool isReturn,
19 const char *errMsgPrefix) const {
20 // Retrieve types
21 26950 const QualType lhsType = lhs.type;
22 26950 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 26949 times.
26950 if (lhs.isTemporary())
26
2/4
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 111 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 108 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 26949 times.
✗ Branch 12 → 125 not taken.
✓ Branch 13 → 14 taken 77 times.
✓ Branch 13 → 16 taken 26872 times.
26949 if (lhsType.is(TY_DYN))
30 77 return {rhsType, nullptr};
31
32 // Check if we try to assign a constant value
33
1/2
✓ Branch 16 → 17 taken 26872 times.
✗ Branch 16 → 125 not taken.
26872 ensureNoConstAssign(node, lhsType, isDecl, isReturn);
34
35 // Allow pointers and references of the same type straight away
36
8/10
✓ Branch 17 → 18 taken 26872 times.
✗ Branch 17 → 117 not taken.
✓ Branch 18 → 19 taken 3619 times.
✓ Branch 18 → 22 taken 23253 times.
✓ Branch 19 → 20 taken 3619 times.
✗ Branch 19 → 117 not taken.
✓ Branch 20 → 21 taken 2983 times.
✓ Branch 20 → 22 taken 636 times.
✓ Branch 23 → 24 taken 2983 times.
✓ Branch 23 → 41 taken 23889 times.
26872 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 992 times.
✓ Branch 24 → 35 taken 1991 times.
✓ Branch 25 → 26 taken 992 times.
✗ Branch 25 → 118 not taken.
✓ Branch 26 → 27 taken 675 times.
✓ Branch 26 → 35 taken 317 times.
✓ Branch 27 → 28 taken 675 times.
✗ Branch 27 → 118 not taken.
✓ Branch 28 → 29 taken 552 times.
✓ Branch 28 → 35 taken 123 times.
✓ Branch 29 → 30 taken 552 times.
✗ Branch 29 → 118 not taken.
✓ Branch 30 → 31 taken 552 times.
✗ Branch 30 → 118 not taken.
✓ Branch 31 → 32 taken 552 times.
✗ Branch 31 → 35 not taken.
✓ Branch 32 → 33 taken 552 times.
✗ Branch 32 → 118 not taken.
✓ Branch 33 → 34 taken 552 times.
✗ Branch 33 → 35 not taken.
✓ Branch 36 → 37 taken 552 times.
✓ Branch 36 → 39 taken 2431 times.
2983 if (rhs.entry && lhsType.isPtr() && lhsType.isHeap() && rhsType.removeReferenceWrapper().isPtr() && rhsType.isHeap())
39
1/2
✓ Branch 37 → 38 taken 552 times.
✗ Branch 37 → 119 not taken.
552 rhs.entry->updateState(MOVED, node);
40 2983 return {rhsType, nullptr};
41 }
42 // Allow ref type to type of the same contained type straight away
43
3/4
✓ Branch 41 → 42 taken 23889 times.
✗ Branch 41 → 125 not taken.
✓ Branch 42 → 43 taken 369 times.
✓ Branch 42 → 63 taken 23520 times.
23889 if (rhsType.isRef()) {
44 // If this is const ref, remove both: the reference and the constness
45
2/4
✓ Branch 43 → 44 taken 369 times.
✗ Branch 43 → 120 not taken.
✓ Branch 44 → 45 taken 369 times.
✗ Branch 44 → 120 not taken.
369 const QualType rhsModified = rhsType.getContained().toNonConst();
46
3/4
✓ Branch 45 → 46 taken 369 times.
✗ Branch 45 → 122 not taken.
✓ Branch 46 → 47 taken 367 times.
✓ Branch 46 → 62 taken 2 times.
369 if (lhsType.matches(rhsModified, false, false, true)) {
47 // Check if we support rvo. If yes, skip the implicit copy ctor call
48
4/4
✓ Branch 47 → 48 taken 13 times.
✓ Branch 47 → 51 taken 354 times.
✓ Branch 49 → 50 taken 2 times.
✓ Branch 49 → 51 taken 11 times.
367 const bool supportsRVO = isReturn && !rhs.isTemporary();
49 367 Function *copyCtor = nullptr;
50
7/8
✓ Branch 52 → 53 taken 367 times.
✗ Branch 52 → 121 not taken.
✓ Branch 53 → 54 taken 243 times.
✓ Branch 53 → 56 taken 124 times.
✓ Branch 54 → 55 taken 241 times.
✓ Branch 54 → 56 taken 2 times.
✓ Branch 57 → 58 taken 241 times.
✓ Branch 57 → 60 taken 126 times.
367 if (rhsModified.is(TY_STRUCT) && !supportsRVO)
51
1/2
✓ Branch 58 → 59 taken 241 times.
✗ Branch 58 → 121 not taken.
241 copyCtor = typeChecker->implicitlyCallStructCopyCtor(rhsModified, node);
52 367 return {lhsType, copyCtor};
53 }
54 }
55 // Allow arrays, structs, interfaces, functions, procedures of the same type straight away
56
8/10
✓ Branch 63 → 64 taken 23522 times.
✗ Branch 63 → 123 not taken.
✓ Branch 64 → 65 taken 85 times.
✓ Branch 64 → 68 taken 23437 times.
✓ Branch 65 → 66 taken 85 times.
✗ Branch 65 → 123 not taken.
✓ Branch 66 → 67 taken 80 times.
✓ Branch 66 → 68 taken 5 times.
✓ Branch 69 → 70 taken 80 times.
✓ Branch 69 → 72 taken 23442 times.
23522 if (lhsType.isOneOf({TY_ARRAY, TY_INTERFACE, TY_FUNCTION, TY_PROCEDURE}) && lhsType.matches(rhsType, false, true, true))
57 80 return {rhsType, nullptr};
58 // Allow struct of the same type straight away
59
8/10
✓ Branch 72 → 73 taken 23442 times.
✗ Branch 72 → 125 not taken.
✓ Branch 73 → 74 taken 2735 times.
✓ Branch 73 → 77 taken 20707 times.
✓ Branch 74 → 75 taken 2735 times.
✗ Branch 74 → 125 not taken.
✓ Branch 75 → 76 taken 2734 times.
✓ Branch 75 → 77 taken 1 time.
✓ Branch 78 → 79 taken 2734 times.
✓ Branch 78 → 96 taken 20708 times.
23442 if (lhsType.is(TY_STRUCT) && lhsType.matches(rhsType, false, true, true)) {
60 // Check if we support rvo. If yes, skip the implicit copy ctor call
61
4/4
✓ Branch 79 → 80 taken 1500 times.
✓ Branch 79 → 83 taken 1234 times.
✓ Branch 81 → 82 taken 115 times.
✓ Branch 81 → 83 taken 1385 times.
2734 const bool supportsRVO = isReturn && !rhs.isTemporary();
62 2734 Function *copyCtor = nullptr;
63
10/10
✓ Branch 84 → 85 taken 2043 times.
✓ Branch 84 → 90 taken 691 times.
✓ Branch 85 → 86 taken 1928 times.
✓ Branch 85 → 90 taken 115 times.
✓ Branch 86 → 87 taken 1065 times.
✓ Branch 86 → 90 taken 863 times.
✓ Branch 88 → 89 taken 12 times.
✓ Branch 88 → 90 taken 1053 times.
✓ Branch 91 → 92 taken 12 times.
✓ Branch 91 → 94 taken 2722 times.
2734 if (rhs.entry != nullptr && !supportsRVO && !isReturn && !rhs.isTemporary())
64
1/2
✓ Branch 92 → 93 taken 12 times.
✗ Branch 92 → 124 not taken.
12 copyCtor = typeChecker->implicitlyCallStructCopyCtor(rhsType, rhs.entry->declNode);
65 2734 return {rhsType, copyCtor};
66 }
67
68 // Check common type combinations
69
2/2
✓ Branch 96 → 97 taken 20706 times.
✓ Branch 96 → 125 taken 2 times.
20708 const QualType resultType = getAssignResultTypeCommon(node, lhs, rhs, isDecl, isReturn);
70
3/4
✓ Branch 97 → 98 taken 20706 times.
✗ Branch 97 → 125 not taken.
✓ Branch 98 → 99 taken 584 times.
✓ Branch 98 → 101 taken 20122 times.
20706 if (!resultType.is(TY_INVALID))
71 584 return {resultType, nullptr};
72
73 // Check primitive type combinations
74 const QualType binOpType =
75
2/2
✓ Branch 103 → 104 taken 20110 times.
✓ Branch 103 → 125 taken 12 times.
20122 validateBinaryOperation(node, ASSIGN_OP_RULES, std::size(ASSIGN_OP_RULES), "=", lhsType, rhsType, true, errMsgPrefix);
76 20110 return {binOpType, nullptr};
77 }
78
79 413 QualType OpRuleManager::getFieldAssignResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, bool imm,
80 bool isDecl) const {
81 // Retrieve types
82 413 const QualType lhsType = lhs.type;
83 413 const QualType rhsType = rhs.type;
84
2/4
✓ Branch 2 → 3 taken 413 times.
✗ Branch 2 → 92 not taken.
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 413 times.
413 assert(!lhsType.is(TY_DYN));
85
86 // Check if we try to assign a constant value
87
1/2
✓ Branch 5 → 6 taken 413 times.
✗ Branch 5 → 92 not taken.
413 ensureNoConstAssign(node, lhsType, isDecl);
88
89 // Allow pointers, arrays and structs of the same type straight away
90
8/10
✓ Branch 6 → 7 taken 413 times.
✗ Branch 6 → 85 not taken.
✓ Branch 7 → 8 taken 239 times.
✓ Branch 7 → 11 taken 174 times.
✓ Branch 8 → 9 taken 239 times.
✗ Branch 8 → 85 not taken.
✓ Branch 9 → 10 taken 237 times.
✓ Branch 9 → 11 taken 2 times.
✓ Branch 12 → 13 taken 237 times.
✓ Branch 12 → 29 taken 176 times.
413 if (lhsType.isOneOf({TY_PTR, TY_ARRAY}) && lhsType == rhsType) {
91 // If we perform a heap x* = heap x* assignment, we need set the right hand side to MOVED
92
8/22
✓ Branch 13 → 14 taken 66 times.
✓ Branch 13 → 24 taken 171 times.
✓ Branch 14 → 15 taken 66 times.
✗ Branch 14 → 86 not taken.
✓ Branch 15 → 16 taken 64 times.
✓ Branch 15 → 24 taken 2 times.
✓ Branch 16 → 17 taken 64 times.
✗ Branch 16 → 86 not taken.
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 24 taken 64 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 237 times.
237 if (rhs.entry && lhsType.isPtr() && lhsType.isHeap() && rhsType.removeReferenceWrapper().isPtr() && rhsType.isHeap())
93 rhs.entry->updateState(MOVED, node);
94 237 return rhsType;
95 }
96 // Allow struct of the same type straight away
97
8/10
✓ Branch 29 → 30 taken 176 times.
✗ Branch 29 → 92 not taken.
✓ Branch 30 → 31 taken 11 times.
✓ Branch 30 → 34 taken 165 times.
✓ Branch 31 → 32 taken 11 times.
✗ Branch 31 → 92 not taken.
✓ Branch 32 → 33 taken 9 times.
✓ Branch 32 → 34 taken 2 times.
✓ Branch 35 → 36 taken 9 times.
✓ Branch 35 → 40 taken 167 times.
176 if (lhsType.is(TY_STRUCT) && lhsType.matches(rhsType, false, true, true)) {
98
2/2
✓ Branch 37 → 38 taken 5 times.
✓ Branch 37 → 39 taken 4 times.
9 if (!rhs.isTemporary())
99
1/2
✓ Branch 38 → 39 taken 5 times.
✗ Branch 38 → 92 not taken.
5 typeChecker->implicitlyCallStructCopyCtor(rhs.entry, rhs.entry->declNode);
100 9 return rhsType;
101 }
102 // Allow ref type to type of the same contained type straight away
103
9/12
✓ Branch 40 → 41 taken 167 times.
✗ Branch 40 → 88 not taken.
✓ Branch 41 → 42 taken 24 times.
✓ Branch 41 → 46 taken 143 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 166 times.
167 if (rhsType.isRef() && lhsType.matches(rhsType.getContained(), false, false, true)) {
104 // In case of a return expression, we perform temp stealing
105
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())
106 typeChecker->implicitlyCallStructCopyCtor(rhs.entry, rhs.entry->declNode);
107 1 return lhsType;
108 }
109 // Allow const ref type to type of the same contained type straight away
110
9/14
✓ Branch 58 → 59 taken 166 times.
✗ Branch 58 → 90 not taken.
✓ Branch 59 → 60 taken 23 times.
✓ Branch 59 → 65 taken 143 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 143 times.
166 if (rhsType.isConstRef() && lhsType.matches(rhsType.getContained().toNonConst(), false, false, true))
111 23 return lhsType;
112 // Allow immediate value to const ref of the same contained type straight away
113
6/8
✓ Branch 68 → 69 taken 143 times.
✗ Branch 68 → 92 not taken.
✓ Branch 69 → 70 taken 1 time.
✓ Branch 69 → 72 taken 142 times.
✓ Branch 70 → 71 taken 1 time.
✗ Branch 70 → 72 not taken.
✓ Branch 73 → 74 taken 1 time.
✓ Branch 73 → 75 taken 142 times.
143 if (lhsType.isConstRef() && imm)
114 1 return rhsType;
115
116 // Check common type combinations
117
1/2
✓ Branch 75 → 76 taken 142 times.
✗ Branch 75 → 92 not taken.
142 const QualType resultType = getAssignResultTypeCommon(node, lhs, rhs, isDecl, false);
118
3/4
✓ Branch 76 → 77 taken 142 times.
✗ Branch 76 → 92 not taken.
✓ Branch 77 → 78 taken 4 times.
✓ Branch 77 → 79 taken 138 times.
142 if (!resultType.is(TY_INVALID))
119 4 return resultType;
120
121 // Check primitive type combinations
122
2/2
✓ Branch 81 → 82 taken 137 times.
✓ Branch 81 → 92 taken 1 time.
138 return validateBinaryOperation(node, ASSIGN_OP_RULES, std::size(ASSIGN_OP_RULES), "=", lhsType, rhsType, true,
123 137 ERROR_FIELD_ASSIGN);
124 }
125
126 20850 QualType OpRuleManager::getAssignResultTypeCommon(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, bool isDecl,
127 bool isReturn) {
128 // Retrieve types
129 20850 const QualType lhsType = lhs.type;
130 20850 const QualType rhsType = rhs.type;
131
132 // Allow type to ref type of the same contained type straight away
133
9/12
✓ Branch 2 → 3 taken 20850 times.
✗ Branch 2 → 113 not taken.
✓ Branch 3 → 4 taken 429 times.
✓ Branch 3 → 8 taken 20421 times.
✓ Branch 4 → 5 taken 429 times.
✗ Branch 4 → 113 not taken.
✓ Branch 5 → 6 taken 429 times.
✗ Branch 5 → 113 not taken.
✓ Branch 6 → 7 taken 426 times.
✓ Branch 6 → 8 taken 3 times.
✓ Branch 9 → 10 taken 426 times.
✓ Branch 9 → 44 taken 20424 times.
20850 if (lhsType.isRef() && lhsType.getContained().matches(rhsType, false, false, true)) {
134
4/4
✓ Branch 10 → 11 taken 363 times.
✓ Branch 10 → 12 taken 63 times.
✓ Branch 11 → 12 taken 301 times.
✓ Branch 11 → 13 taken 62 times.
426 const bool isDeclOrReturn = isDecl || isReturn;
135
7/8
✓ Branch 14 → 15 taken 364 times.
✓ Branch 14 → 19 taken 62 times.
✓ Branch 16 → 17 taken 364 times.
✗ Branch 16 → 137 not taken.
✓ Branch 17 → 18 taken 1 time.
✓ Branch 17 → 19 taken 363 times.
✓ Branch 20 → 21 taken 1 time.
✓ Branch 20 → 29 taken 425 times.
426 if (isDeclOrReturn && !lhsType.canBind(rhsType, rhs.isTemporary()))
136
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");
137
6/6
✓ Branch 29 → 30 taken 301 times.
✓ Branch 29 → 33 taken 124 times.
✓ Branch 31 → 32 taken 1 time.
✓ Branch 31 → 33 taken 300 times.
✓ Branch 34 → 35 taken 1 time.
✓ Branch 34 → 43 taken 424 times.
425 if (isReturn && rhs.isTemporary())
138
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");
139 424 return lhsType;
140 }
141 // Allow char* = string
142
9/14
✓ Branch 44 → 45 taken 20424 times.
✗ Branch 44 → 137 not taken.
✓ Branch 45 → 46 taken 1 time.
✓ Branch 45 → 53 taken 20423 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 20423 times.
20424 if (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING) && lhsType.getQualifiers() == rhsType.getQualifiers())
143 1 return lhsType;
144 // Allow array to pointer
145
12/18
✓ Branch 56 → 57 taken 20423 times.
✗ Branch 56 → 132 not taken.
✓ Branch 57 → 58 taken 163 times.
✓ Branch 57 → 65 taken 20260 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 20417 times.
20423 if (lhsType.isPtr() && rhsType.isArray() && lhsType.getContained().matches(rhsType.getContained(), false, false, true))
146 6 return lhsType;
147 // Allow interface* = struct* or interface& = struct that implements this interface
148
1/2
✓ Branch 70 → 71 taken 20417 times.
✗ Branch 70 → 137 not taken.
20417 const bool sameChainDepth = Type::hasSameTypeChainDepth(lhsType.getType(), rhsType.getType());
149
10/14
✓ Branch 71 → 72 taken 20417 times.
✗ Branch 71 → 137 not taken.
✓ Branch 72 → 73 taken 157 times.
✓ Branch 72 → 76 taken 20260 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 20261 times.
✗ Branch 76 → 137 not taken.
✓ Branch 77 → 78 taken 3 times.
✓ Branch 77 → 79 taken 20258 times.
20417 const bool typesCompatible = (lhsType.isPtr() && rhsType.isPtr() && sameChainDepth) || lhsType.isRef();
150
9/12
✓ Branch 80 → 81 taken 159 times.
✓ Branch 80 → 86 taken 20258 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 20412 times.
20417 if (typesCompatible && lhsType.isBase(TY_INTERFACE) && rhsType.isBase(TY_STRUCT)) {
151 5 QualType lhsTypeCopy = lhsType;
152 5 QualType rhsTypeCopy = rhsType;
153
1/2
✓ Branch 88 → 89 taken 5 times.
✗ Branch 88 → 134 not taken.
5 QualType::unwrapBothWithRefWrappers(lhsTypeCopy, rhsTypeCopy);
154
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))
155 5 return lhsType;
156 }
157 // Allow type* = heap type* straight away. This is used for initializing non-owning pointers to heap allocations
158
10/14
✓ Branch 93 → 94 taken 20412 times.
✗ Branch 93 → 137 not taken.
✓ Branch 94 → 95 taken 153 times.
✓ Branch 94 → 100 taken 20259 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 20260 times.
20412 if (lhsType.isPtr() && rhsType.isHeap() && lhsType.matches(rhsType, false, true, true)) {
159 152 TypeQualifiers rhsQualifiers = rhsType.getQualifiers();
160 152 rhsQualifiers.isHeap = false;
161
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)
162 152 return lhsType;
163 }
164
165 // Nothing matched
166
1/2
✓ Branch 108 → 109 taken 20260 times.
✗ Branch 108 → 136 not taken.
20260 return QualType(TY_INVALID);
167 }
168
169 278 ExprResult OpRuleManager::getPlusEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) {
170 // Check is there is an overloaded operator function available
171
1/2
✓ Branch 2 → 3 taken 278 times.
✗ Branch 2 → 24 not taken.
278 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_PLUS_EQUAL, {lhs, rhs}, opIdx);
172
3/4
✓ Branch 3 → 4 taken 278 times.
✗ Branch 3 → 26 not taken.
✓ Branch 4 → 5 taken 97 times.
✓ Branch 4 → 6 taken 181 times.
278 if (!resultType.type.is(TY_INVALID))
173 97 return resultType;
174
175 // Check if we try to assign a constant value
176
1/2
✓ Branch 6 → 7 taken 181 times.
✗ Branch 6 → 26 not taken.
181 ensureNoConstAssign(node, lhs.type);
177
178 // Remove reference wrappers
179
1/2
✓ Branch 7 → 8 taken 181 times.
✗ Branch 7 → 26 not taken.
181 const QualType lhsType = lhs.type.removeReferenceWrapper();
180
1/2
✓ Branch 8 → 9 taken 181 times.
✗ Branch 8 → 26 not taken.
181 const QualType rhsType = rhs.type.removeReferenceWrapper();
181
182 // Check if this is an unsafe operation
183
7/10
✓ Branch 9 → 10 taken 181 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 5 times.
✓ Branch 10 → 14 taken 176 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 176 times.
181 if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) {
184
1/2
✓ Branch 16 → 17 taken 5 times.
✗ Branch 16 → 26 not taken.
5 ensureUnsafeAllowed(node, "+=", lhsType, rhsType);
185 5 return {lhs};
186 }
187
188
1/2
✓ Branch 20 → 21 taken 176 times.
✗ Branch 20 → 26 not taken.
176 return {validateBinaryOperation(node, PLUS_EQUAL_OP_RULES, std::size(PLUS_EQUAL_OP_RULES), "+=", lhsType, rhsType)};
189 }
190
191 49 ExprResult OpRuleManager::getMinusEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) {
192 // Check is there is an overloaded operator function available
193
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}, opIdx);
194
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))
195 7 return resultType;
196
197 // Check if we try to assign a constant value
198
1/2
✓ Branch 6 → 7 taken 42 times.
✗ Branch 6 → 26 not taken.
42 ensureNoConstAssign(node, lhs.type);
199
200 // Remove reference wrappers
201
1/2
✓ Branch 7 → 8 taken 42 times.
✗ Branch 7 → 26 not taken.
42 const QualType lhsType = lhs.type.removeReferenceWrapper();
202
1/2
✓ Branch 8 → 9 taken 42 times.
✗ Branch 8 → 26 not taken.
42 const QualType rhsType = rhs.type.removeReferenceWrapper();
203
204 // Check if this is an unsafe operation
205
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})) {
206
1/2
✓ Branch 16 → 17 taken 5 times.
✗ Branch 16 → 26 not taken.
5 ensureUnsafeAllowed(node, "-=", lhsType, rhsType);
207 5 return {lhs};
208 }
209
210
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)};
211 }
212
213 50 ExprResult OpRuleManager::getMulEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) {
214 // Check is there is an overloaded operator function available
215
1/2
✓ Branch 2 → 3 taken 50 times.
✗ Branch 2 → 15 not taken.
50 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MUL_EQUAL, {lhs, rhs}, opIdx);
216
3/4
✓ Branch 3 → 4 taken 50 times.
✗ Branch 3 → 16 not taken.
✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 6 taken 48 times.
50 if (!resultType.type.is(TY_INVALID))
217 2 return resultType;
218
219 // Check if we try to assign a constant value
220
1/2
✓ Branch 6 → 7 taken 48 times.
✗ Branch 6 → 16 not taken.
48 ensureNoConstAssign(node, lhs.type);
221
222 // Remove reference wrappers
223
1/2
✓ Branch 7 → 8 taken 48 times.
✗ Branch 7 → 16 not taken.
48 const QualType lhsType = lhs.type.removeReferenceWrapper();
224
1/2
✓ Branch 8 → 9 taken 48 times.
✗ Branch 8 → 16 not taken.
48 const QualType rhsType = rhs.type.removeReferenceWrapper();
225
226
1/2
✓ Branch 11 → 12 taken 48 times.
✗ Branch 11 → 16 not taken.
48 return {validateBinaryOperation(node, MUL_EQUAL_OP_RULES, std::size(MUL_EQUAL_OP_RULES), "*=", lhsType, rhsType)};
227 }
228
229 55 ExprResult OpRuleManager::getDivEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) {
230 // Check is there is an overloaded operator function available
231
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}, opIdx);
232
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))
233 37 return resultType;
234
235 // Check if we try to assign a constant value
236
1/2
✓ Branch 6 → 7 taken 18 times.
✗ Branch 6 → 16 not taken.
18 ensureNoConstAssign(node, lhs.type);
237
238 // Remove reference wrappers
239
1/2
✓ Branch 7 → 8 taken 18 times.
✗ Branch 7 → 16 not taken.
18 const QualType lhsType = lhs.type.removeReferenceWrapper();
240
1/2
✓ Branch 8 → 9 taken 18 times.
✗ Branch 8 → 16 not taken.
18 const QualType rhsType = rhs.type.removeReferenceWrapper();
241
242
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)};
243 }
244
245 17 QualType OpRuleManager::getRemEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
246 // Check if we try to assign a constant value
247
1/2
✓ Branch 2 → 3 taken 17 times.
✗ Branch 2 → 11 not taken.
17 ensureNoConstAssign(node, lhs.type);
248
249 // Remove reference wrappers
250
1/2
✓ Branch 3 → 4 taken 17 times.
✗ Branch 3 → 11 not taken.
17 const QualType lhsType = lhs.type.removeReferenceWrapper();
251
1/2
✓ Branch 4 → 5 taken 17 times.
✗ Branch 4 → 11 not taken.
17 const QualType rhsType = rhs.type.removeReferenceWrapper();
252
253
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);
254 }
255
256 12 QualType OpRuleManager::getSHLEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
257 // Check if we try to assign a constant value
258
1/2
✓ Branch 2 → 3 taken 12 times.
✗ Branch 2 → 11 not taken.
12 ensureNoConstAssign(node, lhs.type);
259
260 // Remove reference wrappers
261
1/2
✓ Branch 3 → 4 taken 12 times.
✗ Branch 3 → 11 not taken.
12 const QualType lhsType = lhs.type.removeReferenceWrapper();
262
1/2
✓ Branch 4 → 5 taken 12 times.
✗ Branch 4 → 11 not taken.
12 const QualType rhsType = rhs.type.removeReferenceWrapper();
263
264
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);
265 }
266
267 13 QualType OpRuleManager::getSHREqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
268 // Check if we try to assign a constant value
269
1/2
✓ Branch 2 → 3 taken 13 times.
✗ Branch 2 → 11 not taken.
13 ensureNoConstAssign(node, lhs.type);
270
271 // Remove reference wrappers
272
1/2
✓ Branch 3 → 4 taken 13 times.
✗ Branch 3 → 11 not taken.
13 const QualType lhsType = lhs.type.removeReferenceWrapper();
273
1/2
✓ Branch 4 → 5 taken 13 times.
✗ Branch 4 → 11 not taken.
13 const QualType rhsType = rhs.type.removeReferenceWrapper();
274
275
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);
276 }
277
278 11 QualType OpRuleManager::getAndEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
279 // Check if we try to assign a constant value
280
1/2
✓ Branch 2 → 3 taken 11 times.
✗ Branch 2 → 11 not taken.
11 ensureNoConstAssign(node, lhs.type);
281
282 // Remove reference wrappers
283
1/2
✓ Branch 3 → 4 taken 11 times.
✗ Branch 3 → 11 not taken.
11 const QualType lhsType = lhs.type.removeReferenceWrapper();
284
1/2
✓ Branch 4 → 5 taken 11 times.
✗ Branch 4 → 11 not taken.
11 const QualType rhsType = rhs.type.removeReferenceWrapper();
285
286
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);
287 }
288
289 11 QualType OpRuleManager::getOrEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
290 // Check if we try to assign a constant value
291
1/2
✓ Branch 2 → 3 taken 11 times.
✗ Branch 2 → 11 not taken.
11 ensureNoConstAssign(node, lhs.type);
292
293 // Remove reference wrappers
294
1/2
✓ Branch 3 → 4 taken 11 times.
✗ Branch 3 → 11 not taken.
11 const QualType lhsType = lhs.type.removeReferenceWrapper();
295
1/2
✓ Branch 4 → 5 taken 11 times.
✗ Branch 4 → 11 not taken.
11 const QualType rhsType = rhs.type.removeReferenceWrapper();
296
297
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);
298 }
299
300 362 QualType OpRuleManager::getXorEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
301 // Check if we try to assign a constant value
302
1/2
✓ Branch 2 → 3 taken 362 times.
✗ Branch 2 → 11 not taken.
362 ensureNoConstAssign(node, lhs.type);
303
304 // Remove reference wrappers
305
1/2
✓ Branch 3 → 4 taken 362 times.
✗ Branch 3 → 11 not taken.
362 const QualType lhsType = lhs.type.removeReferenceWrapper();
306
1/2
✓ Branch 4 → 5 taken 362 times.
✗ Branch 4 → 11 not taken.
362 const QualType rhsType = rhs.type.removeReferenceWrapper();
307
308
1/2
✓ Branch 7 → 8 taken 362 times.
✗ Branch 7 → 11 not taken.
724 return validateBinaryOperation(node, XOR_EQUAL_OP_RULES, std::size(XOR_EQUAL_OP_RULES), "^=", lhsType, rhsType);
309 }
310
311 1267 QualType OpRuleManager::getLogicalOrResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
312 // Remove reference wrappers
313
1/2
✓ Branch 2 → 3 taken 1267 times.
✗ Branch 2 → 10 not taken.
1267 const QualType lhsType = lhs.type.removeReferenceWrapper();
314
1/2
✓ Branch 3 → 4 taken 1267 times.
✗ Branch 3 → 10 not taken.
1267 const QualType rhsType = rhs.type.removeReferenceWrapper();
315
316
2/2
✓ Branch 6 → 7 taken 1266 times.
✓ Branch 6 → 10 taken 1 time.
2533 return validateBinaryOperation(node, LOGICAL_OR_OP_RULES, std::size(LOGICAL_OR_OP_RULES), "||", lhsType, rhsType);
317 }
318
319 223 QualType OpRuleManager::getLogicalAndResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
320 // Remove reference wrappers
321
1/2
✓ Branch 2 → 3 taken 223 times.
✗ Branch 2 → 10 not taken.
223 const QualType lhsType = lhs.type.removeReferenceWrapper();
322
1/2
✓ Branch 3 → 4 taken 223 times.
✗ Branch 3 → 10 not taken.
223 const QualType rhsType = rhs.type.removeReferenceWrapper();
323
324
1/2
✓ Branch 6 → 7 taken 223 times.
✗ Branch 6 → 10 not taken.
446 return validateBinaryOperation(node, LOGICAL_AND_OP_RULES, std::size(LOGICAL_AND_OP_RULES), "&&", lhsType, rhsType);
325 }
326
327 97 QualType OpRuleManager::getBitwiseOrResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
328 // Remove reference wrappers
329
1/2
✓ Branch 2 → 3 taken 97 times.
✗ Branch 2 → 10 not taken.
97 const QualType lhsType = lhs.type.removeReferenceWrapper();
330
1/2
✓ Branch 3 → 4 taken 97 times.
✗ Branch 3 → 10 not taken.
97 const QualType rhsType = rhs.type.removeReferenceWrapper();
331
332
2/2
✓ Branch 6 → 7 taken 96 times.
✓ Branch 6 → 10 taken 1 time.
193 return validateBinaryOperation(node, BITWISE_OR_OP_RULES, std::size(BITWISE_OR_OP_RULES), "|", lhsType, rhsType);
333 }
334
335 19 QualType OpRuleManager::getBitwiseXorResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
336 // Remove reference wrappers
337
1/2
✓ Branch 2 → 3 taken 19 times.
✗ Branch 2 → 10 not taken.
19 const QualType lhsType = lhs.type.removeReferenceWrapper();
338
1/2
✓ Branch 3 → 4 taken 19 times.
✗ Branch 3 → 10 not taken.
19 const QualType rhsType = rhs.type.removeReferenceWrapper();
339
340
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);
341 }
342
343 51 QualType OpRuleManager::getBitwiseAndResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
344 // Remove reference wrappers
345
1/2
✓ Branch 2 → 3 taken 51 times.
✗ Branch 2 → 10 not taken.
51 const QualType lhsType = lhs.type.removeReferenceWrapper();
346
1/2
✓ Branch 3 → 4 taken 51 times.
✗ Branch 3 → 10 not taken.
51 const QualType rhsType = rhs.type.removeReferenceWrapper();
347
348
1/2
✓ Branch 6 → 7 taken 51 times.
✗ Branch 6 → 10 not taken.
102 return validateBinaryOperation(node, BITWISE_AND_OP_RULES, std::size(BITWISE_AND_OP_RULES), "&", lhsType, rhsType);
349 }
350
351 4416 ExprResult OpRuleManager::getEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) {
352 // Check is there is an overloaded operator function available
353
1/2
✓ Branch 2 → 3 taken 4416 times.
✗ Branch 2 → 38 not taken.
4416 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_EQUAL, {lhs, rhs}, opIdx);
354
3/4
✓ Branch 3 → 4 taken 4416 times.
✗ Branch 3 → 39 not taken.
✓ Branch 4 → 5 taken 450 times.
✓ Branch 4 → 6 taken 3966 times.
4416 if (!resultType.type.is(TY_INVALID))
355 450 return resultType;
356
357 // Remove reference wrappers
358
1/2
✓ Branch 6 → 7 taken 3966 times.
✗ Branch 6 → 39 not taken.
3966 const QualType lhsType = lhs.type.removeReferenceWrapper();
359
1/2
✓ Branch 7 → 8 taken 3966 times.
✗ Branch 7 → 39 not taken.
3966 const QualType rhsType = rhs.type.removeReferenceWrapper();
360
361 // Allow 'pointer == unsigned long' straight away
362
10/14
✓ Branch 8 → 9 taken 3966 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 995 times.
✓ Branch 9 → 15 taken 2971 times.
✓ Branch 10 → 11 taken 995 times.
✗ Branch 10 → 39 not taken.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 15 taken 994 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 3965 times.
3966 if (lhsType.isPtr() && rhsType.is(TY_LONG) && rhsType.isUnsigned())
363
1/2
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 39 not taken.
1 return ExprResult(QualType(TY_BOOL));
364
365 // Allow 'string == char*' and vice versa straight away
366
11/18
✓ Branch 19 → 20 taken 3965 times.
✗ Branch 19 → 39 not taken.
✓ Branch 20 → 21 taken 157 times.
✓ Branch 20 → 23 taken 3808 times.
✓ Branch 21 → 22 taken 157 times.
✗ Branch 21 → 39 not taken.
✓ Branch 22 → 23 taken 157 times.
✗ Branch 22 → 27 not taken.
✓ Branch 23 → 24 taken 3965 times.
✗ Branch 23 → 39 not taken.
✓ Branch 24 → 25 taken 576 times.
✓ Branch 24 → 28 taken 3389 times.
✓ Branch 25 → 26 taken 576 times.
✗ Branch 25 → 39 not taken.
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 28 taken 576 times.
✗ Branch 29 → 30 not taken.
✓ Branch 29 → 32 taken 3965 times.
3965 if ((lhsType.is(TY_STRING) && rhsType.isPtrTo(TY_CHAR)) || (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING)))
367 return ExprResult(QualType(TY_BOOL));
368
369 // Check primitive type combinations
370
2/2
✓ Branch 34 → 35 taken 3964 times.
✓ Branch 34 → 39 taken 1 time.
3965 return ExprResult(validateBinaryOperation(node, EQUAL_OP_RULES, std::size(EQUAL_OP_RULES), "==", lhsType, rhsType));
371 }
372
373 1646 ExprResult OpRuleManager::getNotEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) {
374 // Check is there is an overloaded operator function available
375
1/2
✓ Branch 2 → 3 taken 1646 times.
✗ Branch 2 → 38 not taken.
1646 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_NOT_EQUAL, {lhs, rhs}, opIdx);
376
3/4
✓ Branch 3 → 4 taken 1646 times.
✗ Branch 3 → 39 not taken.
✓ Branch 4 → 5 taken 11 times.
✓ Branch 4 → 6 taken 1635 times.
1646 if (!resultType.type.is(TY_INVALID))
377 11 return resultType;
378
379 // Remove reference wrappers
380
1/2
✓ Branch 6 → 7 taken 1635 times.
✗ Branch 6 → 39 not taken.
1635 const QualType lhsType = lhs.type.removeReferenceWrapper();
381
1/2
✓ Branch 7 → 8 taken 1635 times.
✗ Branch 7 → 39 not taken.
1635 const QualType rhsType = rhs.type.removeReferenceWrapper();
382
383 // Allow 'pointer != unsigned long' straight away
384
10/14
✓ Branch 8 → 9 taken 1635 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 231 times.
✓ Branch 9 → 15 taken 1404 times.
✓ Branch 10 → 11 taken 231 times.
✗ Branch 10 → 39 not taken.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 15 taken 230 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 1634 times.
1635 if (lhsType.isPtr() && rhsType.is(TY_LONG) && rhsType.isUnsigned())
385
1/2
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 39 not taken.
1 return ExprResult(QualType(TY_BOOL));
386
387 // Allow 'string != char*' and vice versa straight away
388
12/18
✓ Branch 19 → 20 taken 1634 times.
✗ Branch 19 → 39 not taken.
✓ Branch 20 → 21 taken 10 times.
✓ Branch 20 → 23 taken 1624 times.
✓ Branch 21 → 22 taken 10 times.
✗ Branch 21 → 39 not taken.
✓ Branch 22 → 23 taken 10 times.
✗ Branch 22 → 27 not taken.
✓ Branch 23 → 24 taken 1634 times.
✗ Branch 23 → 39 not taken.
✓ Branch 24 → 25 taken 7 times.
✓ Branch 24 → 28 taken 1627 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 1627 times.
1634 if ((lhsType.is(TY_STRING) && rhsType.isPtrTo(TY_CHAR)) || (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING)))
389
1/2
✓ Branch 30 → 31 taken 7 times.
✗ Branch 30 → 39 not taken.
7 return ExprResult(QualType(TY_BOOL));
390
391 // Check primitive type combinations
392
1/2
✓ Branch 34 → 35 taken 1627 times.
✗ Branch 34 → 39 not taken.
1627 return ExprResult(validateBinaryOperation(node, NOT_EQUAL_OP_RULES, std::size(NOT_EQUAL_OP_RULES), "!=", lhsType, rhsType));
393 }
394
395 2013 QualType OpRuleManager::getLessResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
396 // Remove reference wrappers
397
1/2
✓ Branch 2 → 3 taken 2013 times.
✗ Branch 2 → 10 not taken.
2013 const QualType lhsType = lhs.type.removeReferenceWrapper();
398
1/2
✓ Branch 3 → 4 taken 2013 times.
✗ Branch 3 → 10 not taken.
2013 const QualType rhsType = rhs.type.removeReferenceWrapper();
399
400
1/2
✓ Branch 6 → 7 taken 2013 times.
✗ Branch 6 → 10 not taken.
4026 return validateBinaryOperation(node, LESS_OP_RULES, std::size(LESS_OP_RULES), "<", lhsType, rhsType);
401 }
402
403 572 QualType OpRuleManager::getGreaterResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
404 // Remove reference wrappers
405
1/2
✓ Branch 2 → 3 taken 572 times.
✗ Branch 2 → 10 not taken.
572 const QualType lhsType = lhs.type.removeReferenceWrapper();
406
1/2
✓ Branch 3 → 4 taken 572 times.
✗ Branch 3 → 10 not taken.
572 const QualType rhsType = rhs.type.removeReferenceWrapper();
407
408
2/2
✓ Branch 6 → 7 taken 571 times.
✓ Branch 6 → 10 taken 1 time.
1143 return validateBinaryOperation(node, GREATER_OP_RULES, std::size(GREATER_OP_RULES), ">", lhsType, rhsType);
409 }
410
411 432 QualType OpRuleManager::getLessEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
412 // Remove reference wrappers
413
1/2
✓ Branch 2 → 3 taken 432 times.
✗ Branch 2 → 10 not taken.
432 const QualType lhsType = lhs.type.removeReferenceWrapper();
414
1/2
✓ Branch 3 → 4 taken 432 times.
✗ Branch 3 → 10 not taken.
432 const QualType rhsType = rhs.type.removeReferenceWrapper();
415
416
1/2
✓ Branch 6 → 7 taken 432 times.
✗ Branch 6 → 10 not taken.
864 return validateBinaryOperation(node, LESS_EQUAL_OP_RULES, std::size(LESS_EQUAL_OP_RULES), "<=", lhsType, rhsType);
417 }
418
419 1074 QualType OpRuleManager::getGreaterEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
420 // Remove reference wrappers
421
1/2
✓ Branch 2 → 3 taken 1074 times.
✗ Branch 2 → 21 not taken.
1074 const QualType lhsType = lhs.type.removeReferenceWrapper();
422
1/2
✓ Branch 3 → 4 taken 1074 times.
✗ Branch 3 → 21 not taken.
1074 const QualType rhsType = rhs.type.removeReferenceWrapper();
423
424 // Allow 'pointer == pointer' straight away
425
7/10
✓ Branch 4 → 5 taken 1074 times.
✗ Branch 4 → 21 not taken.
✓ Branch 5 → 6 taken 4 times.
✓ Branch 5 → 9 taken 1070 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 1070 times.
1074 if (lhsType.isPtr() && rhsType.isPtr())
426
1/2
✓ Branch 11 → 12 taken 4 times.
✗ Branch 11 → 20 not taken.
4 return QualType(TY_BOOL);
427
428
1/2
✓ Branch 16 → 17 taken 1070 times.
✗ Branch 16 → 21 not taken.
1070 return validateBinaryOperation(node, GREATER_EQUAL_OP_RULES, std::size(GREATER_EQUAL_OP_RULES), ">=", lhsType, rhsType);
429 }
430
431 110 ExprResult OpRuleManager::getShiftLeftResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) {
432 // Check is there is an overloaded operator function available
433
1/2
✓ Branch 2 → 3 taken 110 times.
✗ Branch 2 → 14 not taken.
110 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_SHL, {lhs, rhs}, opIdx);
434
3/4
✓ Branch 3 → 4 taken 110 times.
✗ Branch 3 → 15 not taken.
✓ Branch 4 → 5 taken 85 times.
✓ Branch 4 → 6 taken 25 times.
110 if (!resultType.type.is(TY_INVALID))
435 85 return resultType;
436
437 // Remove reference wrappers
438
1/2
✓ Branch 6 → 7 taken 25 times.
✗ Branch 6 → 15 not taken.
25 const QualType lhsType = lhs.type.removeReferenceWrapper();
439
1/2
✓ Branch 7 → 8 taken 25 times.
✗ Branch 7 → 15 not taken.
25 const QualType rhsType = rhs.type.removeReferenceWrapper();
440
441
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)};
442 }
443
444 69 ExprResult OpRuleManager::getShiftRightResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) {
445 // Check is there is an overloaded operator function available
446
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);
447
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))
448 1 return resultType;
449
450 // Remove reference wrappers
451
1/2
✓ Branch 6 → 7 taken 68 times.
✗ Branch 6 → 15 not taken.
68 const QualType lhsType = lhs.type.removeReferenceWrapper();
452
1/2
✓ Branch 7 → 8 taken 68 times.
✗ Branch 7 → 15 not taken.
68 const QualType rhsType = rhs.type.removeReferenceWrapper();
453
454
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)};
455 }
456
457 3158 ExprResult OpRuleManager::getPlusResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) {
458 // Check is there is an overloaded operator function available
459
1/2
✓ Branch 2 → 3 taken 3158 times.
✗ Branch 2 → 32 not taken.
3158 const ExprResult result = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_PLUS, {lhs, rhs}, opIdx);
460
3/4
✓ Branch 3 → 4 taken 3158 times.
✗ Branch 3 → 35 not taken.
✓ Branch 4 → 5 taken 70 times.
✓ Branch 4 → 6 taken 3088 times.
3158 if (!result.type.is(TY_INVALID))
461 70 return result;
462
463 // Remove reference wrappers
464
1/2
✓ Branch 6 → 7 taken 3088 times.
✗ Branch 6 → 35 not taken.
3088 const QualType lhsType = lhs.type.removeReferenceWrapper();
465
1/2
✓ Branch 7 → 8 taken 3088 times.
✗ Branch 7 → 35 not taken.
3088 const QualType rhsType = rhs.type.removeReferenceWrapper();
466
467 // Allow any* + <int/long/short>
468
7/10
✓ Branch 8 → 9 taken 3088 times.
✗ Branch 8 → 33 not taken.
✓ Branch 9 → 10 taken 579 times.
✓ Branch 9 → 13 taken 2509 times.
✓ Branch 10 → 11 taken 579 times.
✗ Branch 10 → 33 not taken.
✓ Branch 11 → 12 taken 579 times.
✗ Branch 11 → 13 not taken.
✓ Branch 14 → 15 taken 579 times.
✓ Branch 14 → 17 taken 2509 times.
3088 if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) {
469
1/2
✓ Branch 15 → 16 taken 579 times.
✗ Branch 15 → 35 not taken.
579 ensureUnsafeAllowed(node, "+", lhsType, rhsType);
470 579 return {lhsType};
471 }
472 // Allow <int/long/short> + any*
473
6/10
✓ Branch 17 → 18 taken 2509 times.
✗ Branch 17 → 34 not taken.
✓ Branch 18 → 19 taken 2397 times.
✓ Branch 18 → 22 taken 112 times.
✓ Branch 19 → 20 taken 2397 times.
✗ Branch 19 → 34 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 2397 times.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 26 taken 2509 times.
2509 if (lhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT}) && rhsType.isPtr()) {
474 ensureUnsafeAllowed(node, "+", lhsType, rhsType);
475 return {rhsType};
476 }
477
478
2/2
✓ Branch 28 → 29 taken 2508 times.
✓ Branch 28 → 35 taken 1 time.
2509 return {validateBinaryOperation(node, PLUS_OP_RULES, std::size(PLUS_OP_RULES), "+", lhsType, rhsType)};
479 }
480
481 2014 ExprResult OpRuleManager::getMinusResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) {
482 // Check is there is an overloaded operator function available
483
1/2
✓ Branch 2 → 3 taken 2014 times.
✗ Branch 2 → 32 not taken.
2014 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MINUS, {lhs, rhs}, opIdx);
484
3/4
✓ Branch 3 → 4 taken 2014 times.
✗ Branch 3 → 35 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 2013 times.
2014 if (!resultType.type.is(TY_INVALID))
485 1 return resultType;
486
487 // Remove reference wrappers
488
1/2
✓ Branch 6 → 7 taken 2013 times.
✗ Branch 6 → 35 not taken.
2013 const QualType lhsType = lhs.type.removeReferenceWrapper();
489
1/2
✓ Branch 7 → 8 taken 2013 times.
✗ Branch 7 → 35 not taken.
2013 const QualType rhsType = rhs.type.removeReferenceWrapper();
490
491 // Allow any* - <int/long/short>
492
7/10
✓ Branch 8 → 9 taken 2013 times.
✗ Branch 8 → 33 not taken.
✓ Branch 9 → 10 taken 3 times.
✓ Branch 9 → 13 taken 2010 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 2010 times.
2013 if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) {
493
1/2
✓ Branch 15 → 16 taken 3 times.
✗ Branch 15 → 35 not taken.
3 ensureUnsafeAllowed(node, "-", lhsType, rhsType);
494 3 return {lhs};
495 }
496 // Allow <int/long/short> - any*
497
6/10
✓ Branch 17 → 18 taken 2010 times.
✗ Branch 17 → 34 not taken.
✓ Branch 18 → 19 taken 1997 times.
✓ Branch 18 → 22 taken 13 times.
✓ Branch 19 → 20 taken 1997 times.
✗ Branch 19 → 34 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 1997 times.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 26 taken 2010 times.
2010 if (lhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT}) && rhsType.isPtr()) {
498 ensureUnsafeAllowed(node, "-", lhsType, rhsType);
499 return {rhs};
500 }
501
502
1/2
✓ Branch 28 → 29 taken 2010 times.
✗ Branch 28 → 35 not taken.
2010 return {validateBinaryOperation(node, MINUS_OP_RULES, std::size(MINUS_OP_RULES), "-", lhsType, rhsType)};
503 }
504
505 828 ExprResult OpRuleManager::getMulResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) {
506 // Check is there is an overloaded operator function available
507
1/2
✓ Branch 2 → 3 taken 828 times.
✗ Branch 2 → 14 not taken.
828 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MUL, {lhs, rhs}, opIdx);
508
3/4
✓ Branch 3 → 4 taken 828 times.
✗ Branch 3 → 15 not taken.
✓ Branch 4 → 5 taken 9 times.
✓ Branch 4 → 6 taken 819 times.
828 if (!resultType.type.is(TY_INVALID))
509 9 return resultType;
510
511 // Remove reference wrappers
512
1/2
✓ Branch 6 → 7 taken 819 times.
✗ Branch 6 → 15 not taken.
819 const QualType lhsType = lhs.type.removeReferenceWrapper();
513
1/2
✓ Branch 7 → 8 taken 819 times.
✗ Branch 7 → 15 not taken.
819 const QualType rhsType = rhs.type.removeReferenceWrapper();
514
515
2/2
✓ Branch 10 → 11 taken 818 times.
✓ Branch 10 → 15 taken 1 time.
819 return {validateBinaryOperation(node, MUL_OP_RULES, std::size(MUL_OP_RULES), "*", lhsType, rhsType)};
516 }
517
518 165 ExprResult OpRuleManager::getDivResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) {
519 // Check is there is an overloaded operator function available
520
1/2
✓ Branch 2 → 3 taken 165 times.
✗ Branch 2 → 14 not taken.
165 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_DIV, {lhs, rhs}, opIdx);
521
3/4
✓ Branch 3 → 4 taken 165 times.
✗ Branch 3 → 15 not taken.
✓ Branch 4 → 5 taken 3 times.
✓ Branch 4 → 6 taken 162 times.
165 if (!resultType.type.is(TY_INVALID))
522 3 return resultType;
523
524 // Remove reference wrappers
525
1/2
✓ Branch 6 → 7 taken 162 times.
✗ Branch 6 → 15 not taken.
162 const QualType lhsType = lhs.type.removeReferenceWrapper();
526
1/2
✓ Branch 7 → 8 taken 162 times.
✗ Branch 7 → 15 not taken.
162 const QualType rhsType = rhs.type.removeReferenceWrapper();
527
528
1/2
✓ Branch 10 → 11 taken 162 times.
✗ Branch 10 → 15 not taken.
162 return {validateBinaryOperation(node, DIV_OP_RULES, std::size(DIV_OP_RULES), "/", lhsType, rhsType)};
529 }
530
531 25 ExprResult OpRuleManager::getRemResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
532 // Remove reference wrappers
533
1/2
✓ Branch 2 → 3 taken 25 times.
✗ Branch 2 → 10 not taken.
25 const QualType lhsType = lhs.type.removeReferenceWrapper();
534
1/2
✓ Branch 3 → 4 taken 25 times.
✗ Branch 3 → 10 not taken.
25 const QualType rhsType = rhs.type.removeReferenceWrapper();
535
536
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)};
537 }
538
539 893 QualType OpRuleManager::getPrefixMinusResultType(const ASTNode *node, const ExprResult &lhs) {
540 // Remove reference wrappers
541
1/2
✓ Branch 2 → 3 taken 893 times.
✗ Branch 2 → 9 not taken.
893 const QualType lhsType = lhs.type.removeReferenceWrapper();
542
543
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);
544 }
545
546 26 QualType OpRuleManager::getPrefixPlusPlusResultType(const ASTNode *node, const ExprResult &lhs) const {
547 // Check if we try to assign a constant value
548
1/2
✓ Branch 2 → 3 taken 26 times.
✗ Branch 2 → 14 not taken.
26 ensureNoConstAssign(node, lhs.type);
549
550 // Remove reference wrappers
551
1/2
✓ Branch 3 → 4 taken 26 times.
✗ Branch 3 → 14 not taken.
26 const QualType lhsType = lhs.type.removeReferenceWrapper();
552
553 // Check if this is an unsafe operation
554
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()) {
555 ensureUnsafeAllowed(node, "++", lhsType);
556 return lhsType;
557 }
558
559
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);
560 }
561
562 11 QualType OpRuleManager::getPrefixMinusMinusResultType(const ASTNode *node, const ExprResult &lhs) const {
563 // Check if we try to assign a constant value
564
1/2
✓ Branch 2 → 3 taken 11 times.
✗ Branch 2 → 14 not taken.
11 ensureNoConstAssign(node, lhs.type);
565
566 // Remove reference wrappers
567
1/2
✓ Branch 3 → 4 taken 11 times.
✗ Branch 3 → 14 not taken.
11 const QualType lhsType = lhs.type.removeReferenceWrapper();
568
569 // Check if this is an unsafe operation
570
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()) {
571 ensureUnsafeAllowed(node, "--", lhsType);
572 return lhsType;
573 }
574
575
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);
576 }
577
578 787 QualType OpRuleManager::getPrefixNotResultType(const ASTNode *node, const ExprResult &lhs) {
579 // Remove reference wrappers
580
1/2
✓ Branch 2 → 3 taken 787 times.
✗ Branch 2 → 9 not taken.
787 const QualType lhsType = lhs.type.removeReferenceWrapper();
581
582
1/2
✓ Branch 5 → 6 taken 787 times.
✗ Branch 5 → 9 not taken.
1574 return validateUnaryOperation(node, PREFIX_NOT_OP_RULES, std::size(PREFIX_NOT_OP_RULES), "!", lhsType);
583 }
584
585 5 QualType OpRuleManager::getPrefixBitwiseNotResultType(const ASTNode *node, const ExprResult &lhs) {
586 // Remove reference wrappers
587
1/2
✓ Branch 2 → 3 taken 5 times.
✗ Branch 2 → 9 not taken.
5 const QualType lhsType = lhs.type.removeReferenceWrapper();
588
589
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);
590 }
591
592 236 QualType OpRuleManager::getPrefixMulResultType(const ASTNode *node, const ExprResult &lhs) {
593 // Remove reference wrappers
594
1/2
✓ Branch 2 → 3 taken 236 times.
✗ Branch 2 → 25 not taken.
236 const QualType lhsType = lhs.type.removeReferenceWrapper();
595
596
3/4
✓ Branch 3 → 4 taken 236 times.
✗ Branch 3 → 25 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 12 taken 235 times.
236 if (!lhsType.isPtr())
597
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));
598
1/2
✓ Branch 12 → 13 taken 235 times.
✗ Branch 12 → 25 not taken.
470 return lhsType.getContained();
599 }
600
601 182 QualType OpRuleManager::getPrefixBitwiseAndResultType(const ASTNode *node, const ExprResult &lhs) {
602 // Remove reference wrappers
603
1/2
✓ Branch 2 → 3 taken 182 times.
✗ Branch 2 → 7 not taken.
182 const QualType lhsType = lhs.type.removeReferenceWrapper();
604
605
1/2
✓ Branch 3 → 4 taken 182 times.
✗ Branch 3 → 7 not taken.
364 return lhsType.toPtr(node);
606 }
607
608 1924 ExprResult OpRuleManager::getPostfixPlusPlusResultType(ASTNode *node, const ExprResult &lhs, size_t opIdx) {
609 // Check is there is an overloaded operator function available
610
2/2
✓ Branch 2 → 3 taken 1923 times.
✓ Branch 2 → 18 taken 1 time.
1924 const ExprResult resultType = isOperatorOverloadingFctAvailable<1>(node, OP_FCT_POSTFIX_PLUS_PLUS, {lhs}, opIdx);
611
3/4
✓ Branch 3 → 4 taken 1923 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 9 times.
✓ Branch 4 → 6 taken 1914 times.
1923 if (!resultType.type.is(TY_INVALID))
612 9 return resultType;
613
614 // Check if we try to assign a constant value
615
1/2
✓ Branch 6 → 7 taken 1914 times.
✗ Branch 6 → 19 not taken.
1914 ensureNoConstAssign(node, lhs.type);
616
617 // Remove reference wrappers
618
1/2
✓ Branch 7 → 8 taken 1914 times.
✗ Branch 7 → 19 not taken.
1914 const QualType lhsType = lhs.type.removeReferenceWrapper();
619
620 // Check if this is an unsafe operation
621
3/4
✓ Branch 8 → 9 taken 1914 times.
✗ Branch 8 → 19 not taken.
✓ Branch 9 → 10 taken 9 times.
✓ Branch 9 → 12 taken 1905 times.
1914 if (lhsType.isPtr()) {
622
1/2
✓ Branch 10 → 11 taken 9 times.
✗ Branch 10 → 19 not taken.
9 ensureUnsafeAllowed(node, "++", lhsType);
623 9 return {lhs};
624 }
625
626
2/2
✓ Branch 14 → 15 taken 1904 times.
✓ Branch 14 → 19 taken 1 time.
1905 return {validateUnaryOperation(node, POSTFIX_PLUS_PLUS_OP_RULES, std::size(POSTFIX_PLUS_PLUS_OP_RULES), "++", lhsType)};
627 }
628
629 443 ExprResult OpRuleManager::getPostfixMinusMinusResultType(ASTNode *node, const ExprResult &lhs, size_t opIdx) {
630 // Check is there is an overloaded operator function available
631
1/2
✓ Branch 2 → 3 taken 443 times.
✗ Branch 2 → 18 not taken.
443 const ExprResult resultType = isOperatorOverloadingFctAvailable<1>(node, OP_FCT_POSTFIX_MINUS_MINUS, {lhs}, opIdx);
632
3/4
✓ Branch 3 → 4 taken 443 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 7 times.
✓ Branch 4 → 6 taken 436 times.
443 if (!resultType.type.is(TY_INVALID))
633 7 return resultType;
634
635 // Check if we try to assign a constant value
636
1/2
✓ Branch 6 → 7 taken 436 times.
✗ Branch 6 → 19 not taken.
436 ensureNoConstAssign(node, lhs.type);
637
638 // Remove reference wrappers
639
1/2
✓ Branch 7 → 8 taken 436 times.
✗ Branch 7 → 19 not taken.
436 const QualType lhsType = lhs.type.removeReferenceWrapper();
640
641 // Check if this is an unsafe operation
642
3/4
✓ Branch 8 → 9 taken 436 times.
✗ Branch 8 → 19 not taken.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 12 taken 434 times.
436 if (lhsType.isPtr()) {
643
1/2
✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 19 not taken.
2 ensureUnsafeAllowed(node, "--", lhsType);
644 2 return {lhs};
645 }
646
647
1/2
✓ Branch 14 → 15 taken 434 times.
✗ Branch 14 → 19 not taken.
434 return {validateUnaryOperation(node, POSTFIX_MINUS_MINUS_OP_RULES, std::size(POSTFIX_MINUS_MINUS_OP_RULES), "--", lhsType)};
648 }
649
650 2731 QualType OpRuleManager::getCastResultType(const ASTNode *node, QualType lhsType, const ExprResult &rhs) const {
651 // Remove reference wrappers
652
1/2
✓ Branch 2 → 3 taken 2731 times.
✗ Branch 2 → 48 not taken.
2731 lhsType = lhsType.removeReferenceWrapper();
653
1/2
✓ Branch 3 → 4 taken 2731 times.
✗ Branch 3 → 55 not taken.
2731 QualType rhsType = rhs.type.removeReferenceWrapper();
654
655 // Only allow to cast the 'heap' qualifier away, if we are in unsafe mode
656
2/2
✓ Branch 6 → 7 taken 109 times.
✓ Branch 6 → 8 taken 2622 times.
2731 if (lhsType.getQualifiers().isHeap != rhsType.getQualifiers().isHeap)
657
1/2
✓ Branch 7 → 8 taken 109 times.
✗ Branch 7 → 55 not taken.
109 ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType);
658
659 // Allow identity casts
660
3/4
✓ Branch 8 → 9 taken 2731 times.
✗ Branch 8 → 55 not taken.
✓ Branch 9 → 10 taken 275 times.
✓ Branch 9 → 11 taken 2456 times.
2731 if (lhsType.matches(rhsType, false, true, true))
661 275 return lhsType;
662 // Allow casts string -> char* and string -> char[]
663
12/16
✓ Branch 11 → 12 taken 2456 times.
✗ Branch 11 → 49 not taken.
✓ Branch 12 → 13 taken 1206 times.
✓ Branch 12 → 19 taken 1250 times.
✓ Branch 13 → 14 taken 1206 times.
✗ Branch 13 → 49 not taken.
✓ Branch 14 → 15 taken 1206 times.
✗ Branch 14 → 49 not taken.
✓ Branch 15 → 16 taken 952 times.
✓ Branch 15 → 19 taken 254 times.
✓ Branch 16 → 17 taken 952 times.
✗ Branch 16 → 49 not taken.
✓ Branch 17 → 18 taken 948 times.
✓ Branch 17 → 19 taken 4 times.
✓ Branch 20 → 21 taken 948 times.
✓ Branch 20 → 22 taken 1508 times.
2456 if (lhsType.isOneOf({TY_PTR, TY_ARRAY}) && lhsType.getContained().is(TY_CHAR) && rhsType.is(TY_STRING))
664 948 return lhsType;
665 // Allow casts char* -> string and char[] -> string
666
10/16
✓ Branch 22 → 23 taken 1508 times.
✗ Branch 22 → 51 not taken.
✓ Branch 23 → 24 taken 96 times.
✓ Branch 23 → 30 taken 1412 times.
✓ Branch 24 → 25 taken 96 times.
✗ Branch 24 → 51 not taken.
✓ Branch 25 → 26 taken 96 times.
✗ Branch 25 → 30 not taken.
✓ Branch 26 → 27 taken 96 times.
✗ Branch 26 → 51 not taken.
✓ Branch 27 → 28 taken 96 times.
✗ Branch 27 → 51 not taken.
✓ Branch 28 → 29 taken 96 times.
✗ Branch 28 → 30 not taken.
✓ Branch 31 → 32 taken 96 times.
✓ Branch 31 → 33 taken 1412 times.
1508 if (lhsType.is(TY_STRING) && rhsType.isOneOf({TY_PTR, TY_ARRAY}) && rhsType.getContained().is(TY_CHAR))
667 96 return lhsType;
668 // Allow casts any* -> any*
669
7/10
✓ Branch 33 → 34 taken 1412 times.
✗ Branch 33 → 53 not taken.
✓ Branch 34 → 35 taken 258 times.
✓ Branch 34 → 38 taken 1154 times.
✓ Branch 35 → 36 taken 258 times.
✗ Branch 35 → 53 not taken.
✓ Branch 36 → 37 taken 258 times.
✗ Branch 36 → 38 not taken.
✓ Branch 39 → 40 taken 258 times.
✓ Branch 39 → 42 taken 1154 times.
1412 if (lhsType.isOneOf({TY_PTR, TY_STRING}) && rhsType.isOneOf({TY_PTR, TY_STRING})) {
670
1/2
✓ Branch 40 → 41 taken 258 times.
✗ Branch 40 → 55 not taken.
258 ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType);
671 258 return lhsType;
672 }
673 // Check primitive type combinations
674
1/2
✓ Branch 44 → 45 taken 1154 times.
✗ Branch 44 → 55 not taken.
1154 return validateBinaryOperation(node, CAST_OP_RULES, std::size(CAST_OP_RULES), "(cast)", lhsType, rhsType, true);
675 }
676
677 template <size_t N>
678 18807 ExprResult OpRuleManager::isOperatorOverloadingFctAvailable(ASTNode *node, const char *const fctName,
679 const std::array<ExprResult, N> &op, size_t opIdx) {
680 static_assert(N == 1 || N == 2, "Only unary and binary operators are overloadable");
681 18807 Scope *calleeParentScope = nullptr;
682 18807 const Function *callee = nullptr;
683
14/20
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long):
✓ Branch 2 → 3 taken 2367 times.
✗ Branch 2 → 123 not taken.
✓ Branch 3 → 4 taken 2367 times.
✗ Branch 3 → 123 not taken.
✓ Branch 4 → 5 taken 2367 times.
✗ Branch 4 → 123 not taken.
✓ Branch 42 → 43 taken 2592 times.
✓ Branch 42 → 45 taken 17 times.
✓ Branch 48 → 6 taken 20528 times.
✓ Branch 48 → 49 taken 2350 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long):
✓ Branch 2 → 3 taken 16440 times.
✗ Branch 2 → 132 not taken.
✓ Branch 3 → 4 taken 16440 times.
✗ Branch 3 → 132 not taken.
✓ Branch 4 → 5 taken 16440 times.
✗ Branch 4 → 132 not taken.
✓ Branch 49 → 50 taken 54888 times.
✓ Branch 49 → 52 taken 896 times.
✓ Branch 55 → 6 taken 135808 times.
✓ Branch 55 → 56 taken 15544 times.
232623 for (const auto &sourceFile : typeChecker->resourceManager.sourceFiles | std::views::values) {
684 // Check if there is a registered operator function
685
8/12
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long):
✓ Branch 10 → 11 taken 20528 times.
✗ Branch 10 → 102 not taken.
✓ Branch 11 → 12 taken 20528 times.
✗ Branch 11 → 100 not taken.
✓ Branch 14 → 15 taken 17919 times.
✓ Branch 14 → 16 taken 2609 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long):
✓ Branch 10 → 11 taken 135808 times.
✗ Branch 10 → 109 not taken.
✓ Branch 11 → 12 taken 135808 times.
✗ Branch 11 → 107 not taken.
✓ Branch 14 → 15 taken 80024 times.
✓ Branch 14 → 16 taken 55784 times.
469008 if (!sourceFile->getNameRegistryEntry(fctName))
686 97943 continue;
687
688 // Match callees in the global scope of this source file
689 58393 calleeParentScope = sourceFile->globalScope.get();
690
2/4
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long):
✓ Branch 18 → 19 taken 2609 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):
✓ Branch 18 → 19 taken 55784 times.
✗ Branch 18 → 131 not taken.
58393 const QualType thisType(TY_DYN);
691
2/4
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long):
✓ Branch 21 → 22 taken 2609 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):
✓ Branch 21 → 22 taken 55784 times.
✗ Branch 21 → 113 not taken.
58393 ArgList args(N);
692
2/4
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long):
✓ Branch 24 → 25 taken 2609 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):
✓ Branch 24 → 25 taken 55784 times.
✗ Branch 24 → 116 not taken.
58393 args[0] = {typeChecker->mapLocalTypeToImportedScopeType(calleeParentScope, op[0].type), op[0].isTemporary()};
693 if constexpr (N == 2)
694
1/2
✓ Branch 31 → 32 taken 55784 times.
✗ Branch 31 → 118 not taken.
55784 args[1] = {typeChecker->mapLocalTypeToImportedScopeType(calleeParentScope, op[1].type), op[1].isTemporary()};
695
4/8
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long):
✓ Branch 33 → 34 taken 2609 times.
✗ Branch 33 → 113 not taken.
✓ Branch 34 → 35 taken 2609 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):
✓ Branch 40 → 41 taken 55784 times.
✗ Branch 40 → 122 not taken.
✓ Branch 41 → 42 taken 55784 times.
✗ Branch 41 → 120 not taken.
175179 callee = FunctionManager::match(calleeParentScope, fctName, thisType, args, {}, false, node);
696
4/4
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long):
✓ Branch 38 → 39 taken 17 times.
✓ Branch 38 → 40 taken 2592 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long):
✓ Branch 45 → 46 taken 896 times.
✓ Branch 45 → 47 taken 54888 times.
58393 if (callee)
697 913 break;
698 }
699
700 // Return invalid type if the callee was not found
701
4/4
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long):
✓ Branch 49 → 50 taken 2350 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):
✓ Branch 56 → 57 taken 15544 times.
✓ Branch 56 → 59 taken 896 times.
18807 if (!callee)
702 17894 return ExprResult(QualType(TY_INVALID));
703
2/4
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long):
✗ 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):
✗ Branch 59 → 60 not taken.
✓ Branch 59 → 61 taken 896 times.
913 assert(calleeParentScope != nullptr);
704
705 // Save the pointer to the operator function in the AST node
706 913 std::vector<const Function *> &opFctPointers = typeChecker->getOpFctPointers(node);
707
3/4
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long):
✗ 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):
✓ Branch 63 → 64 taken 74 times.
✓ Branch 63 → 66 taken 822 times.
913 if (opFctPointers.size() <= opIdx)
708
1/4
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long):
✗ 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):
✓ Branch 64 → 65 taken 74 times.
✗ Branch 64 → 133 not taken.
74 opFctPointers.resize(opIdx + 1, nullptr);
709 913 opFctPointers.at(opIdx) = callee;
710
711 // Check if we need to request a re-visit, because the function body was not type-checked yet
712 913 typeChecker->requestRevisitIfRequired(callee);
713
714 // Check if the called function has sufficient visibility
715
6/8
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long):
✓ 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):
✓ Branch 68 → 69 taken 896 times.
✗ Branch 68 → 72 not taken.
✓ Branch 70 → 71 taken 394 times.
✓ Branch 70 → 72 taken 502 times.
913 const bool isImported = calleeParentScope != nullptr && calleeParentScope->isImportedBy(typeChecker->rootScope);
716 913 const SymbolTableEntry *calleeEntry = callee->entry;
717
10/12
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long):
✓ 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):
✓ Branch 73 → 74 taken 394 times.
✓ Branch 73 → 78 taken 502 times.
✗ Branch 76 → 77 not taken.
✓ Branch 76 → 78 taken 394 times.
✗ Branch 79 → 80 not taken.
✓ Branch 79 → 89 taken 896 times.
913 if (isImported && !calleeEntry->getQualType().isPublic())
718
1/4
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long):
✓ 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):
✗ Branch 84 → 85 not taken.
✗ Branch 84 → 134 not taken.
2 throw SemanticError(node, INSUFFICIENT_VISIBILITY,
719
3/12
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long):
✓ 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):
✗ 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");
720
721 // Procedures always have the return type 'bool'
722
4/4
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long):
✓ 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):
✓ Branch 92 → 93 taken 143 times.
✓ Branch 92 → 95 taken 753 times.
912 if (callee->isProcedure())
723 157 return ExprResult(QualType(TY_BOOL));
724 755 const QualType &returnType = callee->returnType;
725
726 // Add anonymous symbol to keep track of dtor call, if non-trivially destructible
727 755 SymbolTableEntry *anonymousSymbol = nullptr;
728
8/12
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long):
✗ 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):
✓ Branch 96 → 97 taken 85 times.
✓ Branch 96 → 100 taken 668 times.
✓ Branch 98 → 99 taken 79 times.
✓ Branch 98 → 100 taken 6 times.
✓ Branch 101 → 102 taken 79 times.
✓ Branch 101 → 104 taken 674 times.
755 if (returnType.is(TY_STRUCT) && !returnType.isTriviallyDestructible(node))
729 79 anonymousSymbol = typeChecker->currentScope->symbolTable.insertAnonymous(returnType, node, opIdx);
730
731 755 return {typeChecker->mapImportedScopeTypeToLocalType(calleeParentScope, returnType), anonymousSymbol};
732 }
733
734 4061 QualType OpRuleManager::validateUnaryOperation(const ASTNode *node, const UnaryOpRule opRules[], size_t opRulesSize,
735 const char *name, const QualType &lhs) {
736
2/2
✓ Branch 11 → 3 taken 9914 times.
✓ Branch 11 → 12 taken 2 times.
9916 for (size_t i = 0; i < opRulesSize; i++) {
737 9914 const UnaryOpRule &rule = opRules[i];
738
2/2
✓ Branch 5 → 6 taken 4059 times.
✓ Branch 5 → 10 taken 5855 times.
9914 if (std::get<0>(rule) == lhs.getSuperType())
739
1/2
✓ Branch 7 → 8 taken 4059 times.
✗ Branch 7 → 16 not taken.
4059 return QualType(std::get<1>(rule));
740 }
741
1/2
✓ Branch 13 → 14 taken 2 times.
✗ Branch 13 → 17 not taken.
2 throw getExceptionUnary(node, name, lhs);
742 }
743
744 39073 QualType OpRuleManager::validateBinaryOperation(const ASTNode *node, const BinaryOpRule opRules[], size_t opRulesSize,
745 const char *name, const QualType &lhs, const QualType &rhs,
746 bool preserveQualifiersFromLhs, const char *customMessagePrefix) {
747
2/2
✓ Branch 19 → 3 taken 387333 times.
✓ Branch 19 → 20 taken 19 times.
387352 for (size_t i = 0; i < opRulesSize; i++) {
748 387333 const BinaryOpRule &rule = opRules[i];
749
6/6
✓ Branch 5 → 6 taken 76087 times.
✓ Branch 5 → 10 taken 311246 times.
✓ Branch 8 → 9 taken 39054 times.
✓ Branch 8 → 10 taken 37033 times.
✓ Branch 11 → 12 taken 39054 times.
✓ Branch 11 → 18 taken 348279 times.
387333 if (std::get<0>(rule) == lhs.getSuperType() && std::get<1>(rule) == rhs.getSuperType()) {
750
1/2
✓ Branch 13 → 14 taken 39054 times.
✗ Branch 13 → 24 not taken.
39054 QualType resultType((std::get<2>(rule)));
751
2/2
✓ Branch 14 → 15 taken 21401 times.
✓ Branch 14 → 17 taken 17653 times.
39054 if (preserveQualifiersFromLhs)
752 21401 resultType.setQualifiers(lhs.getQualifiers());
753 39054 return resultType;
754 }
755 }
756
1/2
✓ Branch 21 → 22 taken 19 times.
✗ Branch 21 → 25 not taken.
19 throw getExceptionBinary(node, name, lhs, rhs, customMessagePrefix);
757 }
758
759 2 SemanticError OpRuleManager::getExceptionUnary(const ASTNode *node, const char *name, const QualType &lhs) {
760
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)};
761 }
762
763 19 SemanticError OpRuleManager::getExceptionBinary(const ASTNode *node, const char *name, const QualType &lhs, const QualType &rhs,
764 const char *messagePrefix) {
765 // Build error message
766
1/2
✓ Branch 2 → 3 taken 19 times.
✗ Branch 2 → 50 not taken.
19 std::stringstream errorMsg;
767
2/2
✓ Branch 3 → 4 taken 4 times.
✓ Branch 3 → 14 taken 15 times.
19 if (strlen(messagePrefix) != 0)
768
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);
769 else
770
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);
771
772 // Return the exception
773
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()};
774 19 }
775
776 11 void OpRuleManager::ensureUnsafeAllowed(const ASTNode *node, const char *name, const QualType &lhs) const {
777
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())
778 11 return;
779 // Print error message
780 const std::string lhsName = lhs.getName(true);
781 const std::string errorMsg = "Cannot apply '" + std::string(name) + "' operator on type " + lhsName +
782 " as this is an unsafe operation. Please use unsafe blocks if you know what you are doing.";
783 SOFT_ERROR_VOID(node, UNSAFE_OPERATION_IN_SAFE_CONTEXT, errorMsg)
784 }
785
786 959 void OpRuleManager::ensureUnsafeAllowed(const ASTNode *node, const char *name, const QualType &lhs, const QualType &rhs) const {
787
3/4
✓ Branch 2 → 3 taken 959 times.
✗ Branch 2 → 57 not taken.
✓ Branch 3 → 4 taken 958 times.
✓ Branch 3 → 5 taken 1 time.
959 if (typeChecker->currentScope->doesAllowUnsafeOperations())
788 958 return;
789 // Print error message
790
1/2
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 57 not taken.
1 const std::string lhsName = lhs.getName(true);
791
1/2
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 55 not taken.
1 const std::string rhsName = rhs.getName(true);
792
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 +
793
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.";
794
1/2
✓ Branch 23 → 24 taken 1 time.
✗ Branch 23 → 51 not taken.
1 SOFT_ERROR_VOID(node, UNSAFE_OPERATION_IN_SAFE_CONTEXT, errorMsg)
795 1 }
796
797 30387 void OpRuleManager::ensureNoConstAssign(const ASTNode *node, const QualType &lhs, bool isDecl, bool isReturn) const {
798 // Check if we try to assign a constant value
799
10/12
✓ Branch 2 → 3 taken 30387 times.
✗ Branch 2 → 18 not taken.
✓ Branch 3 → 4 taken 30387 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 3433 times.
✓ Branch 4 → 8 taken 26954 times.
✓ Branch 5 → 6 taken 56 times.
✓ Branch 5 → 8 taken 3377 times.
✓ Branch 6 → 7 taken 14 times.
✓ Branch 6 → 8 taken 42 times.
✓ Branch 9 → 10 taken 14 times.
✓ Branch 9 → 17 taken 30373 times.
30387 if (lhs.removeReferenceWrapper().isConst() && !isDecl && !isReturn) {
800
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);
801
1/2
✓ Branch 13 → 14 taken 14 times.
✗ Branch 13 → 22 not taken.
14 SOFT_ERROR_VOID(node, REASSIGN_CONST_VARIABLE, errorMessage);
802 14 }
803 }
804
805 } // namespace spice::compiler
806