GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 95.6% 433 / 0 / 453
Functions: 100.0% 51 / 0 / 51
Branches: 62.0% 720 / 0 / 1162

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 3597 OpRuleManager::OpRuleManager(TypeChecker *typeChecker)
16 3597 : typeChecker(typeChecker), resourceManager(typeChecker->resourceManager) {}
17
18 26869 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 26869 const QualType lhsType = lhs.type;
23 26869 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 26868 times.
26869 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 26868 times.
✗ Branch 12 → 116 not taken.
✓ Branch 13 → 14 taken 76 times.
✓ Branch 13 → 16 taken 26792 times.
26868 if (lhsType.is(TY_DYN))
31 76 return {rhsType, nullptr};
32
33 // Check if we try to assign a constant value
34
1/2
✓ Branch 16 → 17 taken 26792 times.
✗ Branch 16 → 116 not taken.
26792 ensureNoConstAssign(node, lhsType, isDecl, isReturn);
35
36 // Allow pointers and references of the same type straight away
37
8/10
✓ Branch 17 → 18 taken 26792 times.
✗ Branch 17 → 108 not taken.
✓ Branch 18 → 19 taken 3591 times.
✓ Branch 18 → 22 taken 23201 times.
✓ Branch 19 → 20 taken 3591 times.
✗ Branch 19 → 108 not taken.
✓ Branch 20 → 21 taken 2963 times.
✓ Branch 20 → 22 taken 628 times.
✓ Branch 23 → 24 taken 2963 times.
✓ Branch 23 → 41 taken 23829 times.
26792 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 987 times.
✓ Branch 24 → 35 taken 1976 times.
✓ Branch 25 → 26 taken 987 times.
✗ Branch 25 → 109 not taken.
✓ Branch 26 → 27 taken 672 times.
✓ Branch 26 → 35 taken 315 times.
✓ Branch 27 → 28 taken 672 times.
✗ Branch 27 → 109 not taken.
✓ Branch 28 → 29 taken 549 times.
✓ Branch 28 → 35 taken 123 times.
✓ Branch 29 → 30 taken 549 times.
✗ Branch 29 → 109 not taken.
✓ Branch 30 → 31 taken 549 times.
✗ Branch 30 → 109 not taken.
✓ Branch 31 → 32 taken 549 times.
✗ Branch 31 → 35 not taken.
✓ Branch 32 → 33 taken 549 times.
✗ Branch 32 → 109 not taken.
✓ Branch 33 → 34 taken 549 times.
✗ Branch 33 → 35 not taken.
✓ Branch 36 → 37 taken 549 times.
✓ Branch 36 → 39 taken 2414 times.
2963 if (rhs.entry && lhsType.isPtr() && lhsType.isHeap() && rhsType.removeReferenceWrapper().isPtr() && rhsType.isHeap())
40
1/2
✓ Branch 37 → 38 taken 549 times.
✗ Branch 37 → 110 not taken.
549 rhs.entry->updateState(MOVED, node);
41 2963 return {rhsType, nullptr};
42 }
43 // Allow ref type to type of the same contained type straight away
44
3/4
✓ Branch 41 → 42 taken 23829 times.
✗ Branch 41 → 116 not taken.
✓ Branch 42 → 43 taken 364 times.
✓ Branch 42 → 54 taken 23465 times.
23829 if (rhsType.isRef()) {
45 // If this is const ref, remove both: the reference and the constness
46
2/4
✓ Branch 43 → 44 taken 364 times.
✗ Branch 43 → 111 not taken.
✓ Branch 44 → 45 taken 364 times.
✗ Branch 44 → 111 not taken.
364 const QualType rhsModified = rhsType.getContained().toNonConst();
47
3/4
✓ Branch 45 → 46 taken 364 times.
✗ Branch 45 → 113 not taken.
✓ Branch 46 → 47 taken 362 times.
✓ Branch 46 → 53 taken 2 times.
364 if (lhsType.matches(rhsModified, false, false, true)) {
48 362 Function *copyCtor = nullptr;
49
3/4
✓ Branch 47 → 48 taken 362 times.
✗ Branch 47 → 112 not taken.
✓ Branch 48 → 49 taken 243 times.
✓ Branch 48 → 51 taken 119 times.
362 if (rhsModified.is(TY_STRUCT))
50
1/2
✓ Branch 49 → 50 taken 243 times.
✗ Branch 49 → 112 not taken.
243 copyCtor = typeChecker->implicitlyCallStructCopyCtor(rhsModified, node);
51 362 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 23467 times.
✗ Branch 54 → 114 not taken.
✓ Branch 55 → 56 taken 82 times.
✓ Branch 55 → 59 taken 23385 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 23390 times.
23467 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 23390 times.
✗ Branch 63 → 116 not taken.
✓ Branch 64 → 65 taken 2718 times.
✓ Branch 64 → 68 taken 20672 times.
✓ Branch 65 → 66 taken 2718 times.
✗ Branch 65 → 116 not taken.
✓ Branch 66 → 67 taken 2717 times.
✓ Branch 66 → 68 taken 1 time.
✓ Branch 69 → 70 taken 2717 times.
✓ Branch 69 → 87 taken 20673 times.
23390 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 1492 times.
✓ Branch 70 → 74 taken 1225 times.
✓ Branch 72 → 73 taken 117 times.
✓ Branch 72 → 74 taken 1375 times.
2717 const bool supportsRVO = isReturn && !rhs.isTemporary();
61 2717 Function *copyCtor = nullptr;
62
10/10
✓ Branch 75 → 76 taken 2030 times.
✓ Branch 75 → 81 taken 687 times.
✓ Branch 76 → 77 taken 1913 times.
✓ Branch 76 → 81 taken 117 times.
✓ Branch 77 → 78 taken 1058 times.
✓ Branch 77 → 81 taken 855 times.
✓ Branch 79 → 80 taken 14 times.
✓ Branch 79 → 81 taken 1044 times.
✓ Branch 82 → 83 taken 14 times.
✓ Branch 82 → 85 taken 2703 times.
2717 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 2717 return {rhsType, copyCtor};
65 }
66
67 // Check common type combinations
68
2/2
✓ Branch 87 → 88 taken 20671 times.
✓ Branch 87 → 116 taken 2 times.
20673 const QualType resultType = getAssignResultTypeCommon(node, lhs, rhs, isDecl, isReturn);
69
3/4
✓ Branch 88 → 89 taken 20671 times.
✗ Branch 88 → 116 not taken.
✓ Branch 89 → 90 taken 577 times.
✓ Branch 89 → 92 taken 20094 times.
20671 if (!resultType.is(TY_INVALID))
70 577 return {resultType, nullptr};
71
72 // Check primitive type combinations
73 const QualType binOpType =
74
2/2
✓ Branch 94 → 95 taken 20082 times.
✓ Branch 94 → 116 taken 12 times.
20094 validateBinaryOperation(node, ASSIGN_OP_RULES, std::size(ASSIGN_OP_RULES), "=", lhsType, rhsType, true, errMsgPrefix);
75 20082 return {binOpType, nullptr};
76 }
77
78 413 QualType OpRuleManager::getFieldAssignResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, bool imm,
79 bool isDecl) const {
80 // Retrieve types
81 413 const QualType lhsType = lhs.type;
82 413 const QualType rhsType = rhs.type;
83
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));
84
85 // Check if we try to assign a constant value
86
1/2
✓ Branch 5 → 6 taken 413 times.
✗ Branch 5 → 92 not taken.
413 ensureNoConstAssign(node, lhsType, isDecl);
87
88 // Allow pointers, arrays and structs of the same type straight away
89
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) {
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 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())
92 rhs.entry->updateState(MOVED, node);
93 237 return rhsType;
94 }
95 // Allow struct of the same type straight away
96
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)) {
97
2/2
✓ Branch 37 → 38 taken 5 times.
✓ Branch 37 → 39 taken 4 times.
9 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 9 return rhsType;
100 }
101 // Allow ref type to type of the same contained type straight away
102
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)) {
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 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))
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 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)
113 1 return rhsType;
114
115 // Check common type combinations
116
1/2
✓ Branch 75 → 76 taken 142 times.
✗ Branch 75 → 92 not taken.
142 const QualType resultType = getAssignResultTypeCommon(node, lhs, rhs, isDecl, false);
117
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))
118 4 return resultType;
119
120 // Check primitive type combinations
121
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,
122 137 ERROR_FIELD_ASSIGN);
123 }
124
125 20815 QualType OpRuleManager::getAssignResultTypeCommon(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, bool isDecl,
126 bool isReturn) {
127 // Retrieve types
128 20815 const QualType lhsType = lhs.type;
129 20815 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 20815 times.
✗ Branch 2 → 113 not taken.
✓ Branch 3 → 4 taken 422 times.
✓ Branch 3 → 8 taken 20393 times.
✓ Branch 4 → 5 taken 422 times.
✗ Branch 4 → 113 not taken.
✓ Branch 5 → 6 taken 422 times.
✗ Branch 5 → 113 not taken.
✓ Branch 6 → 7 taken 419 times.
✓ Branch 6 → 8 taken 3 times.
✓ Branch 9 → 10 taken 419 times.
✓ Branch 9 → 44 taken 20396 times.
20815 if (lhsType.isRef() && lhsType.getContained().matches(rhsType, false, false, true)) {
133
4/4
✓ Branch 10 → 11 taken 358 times.
✓ Branch 10 → 12 taken 61 times.
✓ Branch 11 → 12 taken 297 times.
✓ Branch 11 → 13 taken 61 times.
419 const bool isDeclOrReturn = isDecl || isReturn;
134
7/8
✓ Branch 14 → 15 taken 358 times.
✓ Branch 14 → 19 taken 61 times.
✓ Branch 16 → 17 taken 358 times.
✗ Branch 16 → 137 not taken.
✓ Branch 17 → 18 taken 1 time.
✓ Branch 17 → 19 taken 357 times.
✓ Branch 20 → 21 taken 1 time.
✓ Branch 20 → 29 taken 418 times.
419 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 297 times.
✓ Branch 29 → 33 taken 121 times.
✓ Branch 31 → 32 taken 1 time.
✓ Branch 31 → 33 taken 296 times.
✓ Branch 34 → 35 taken 1 time.
✓ Branch 34 → 43 taken 417 times.
418 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 417 return lhsType;
139 }
140 // Allow char* = string
141
9/14
✓ Branch 44 → 45 taken 20396 times.
✗ Branch 44 → 137 not taken.
✓ Branch 45 → 46 taken 1 time.
✓ Branch 45 → 53 taken 20395 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 20395 times.
20396 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 20395 times.
✗ Branch 56 → 132 not taken.
✓ Branch 57 → 58 taken 163 times.
✓ Branch 57 → 65 taken 20232 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 20389 times.
20395 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 20389 times.
✗ Branch 70 → 137 not taken.
20389 const bool sameChainDepth = Type::hasSameTypeChainDepth(lhsType.getType(), rhsType.getType());
148
10/14
✓ Branch 71 → 72 taken 20389 times.
✗ Branch 71 → 137 not taken.
✓ Branch 72 → 73 taken 157 times.
✓ Branch 72 → 76 taken 20232 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 20233 times.
✗ Branch 76 → 137 not taken.
✓ Branch 77 → 78 taken 3 times.
✓ Branch 77 → 79 taken 20230 times.
20389 const bool typesCompatible = (lhsType.isPtr() && rhsType.isPtr() && sameChainDepth) || lhsType.isRef();
149
9/12
✓ Branch 80 → 81 taken 159 times.
✓ Branch 80 → 86 taken 20230 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 20384 times.
20389 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 20384 times.
✗ Branch 93 → 137 not taken.
✓ Branch 94 → 95 taken 153 times.
✓ Branch 94 → 100 taken 20231 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 20232 times.
20384 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 20232 times.
✗ Branch 108 → 136 not taken.
20232 return QualType(TY_INVALID);
166 }
167
168 278 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 278 times.
✗ Branch 2 → 24 not taken.
278 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_PLUS_EQUAL, {lhs, rhs}, 0);
171
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))
172 97 return resultType;
173
174 // Check if we try to assign a constant value
175
1/2
✓ Branch 6 → 7 taken 181 times.
✗ Branch 6 → 26 not taken.
181 ensureNoConstAssign(node, lhs.type);
176
177 // Remove reference wrappers
178
1/2
✓ Branch 7 → 8 taken 181 times.
✗ Branch 7 → 26 not taken.
181 const QualType lhsType = lhs.type.removeReferenceWrapper();
179
1/2
✓ Branch 8 → 9 taken 181 times.
✗ Branch 8 → 26 not taken.
181 const QualType rhsType = rhs.type.removeReferenceWrapper();
180
181 // Check if this is an unsafe operation
182
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})) {
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 176 times.
✗ Branch 20 → 26 not taken.
176 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 50 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 50 times.
✗ Branch 2 → 15 not taken.
50 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MUL_EQUAL, {lhs, rhs}, 0);
215
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))
216 2 return resultType;
217
218 // Check if we try to assign a constant value
219
1/2
✓ Branch 6 → 7 taken 48 times.
✗ Branch 6 → 16 not taken.
48 ensureNoConstAssign(node, lhs.type);
220
221 // Remove reference wrappers
222
1/2
✓ Branch 7 → 8 taken 48 times.
✗ Branch 7 → 16 not taken.
48 const QualType lhsType = lhs.type.removeReferenceWrapper();
223
1/2
✓ Branch 8 → 9 taken 48 times.
✗ Branch 8 → 16 not taken.
48 const QualType rhsType = rhs.type.removeReferenceWrapper();
224
225
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)};
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 362 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 362 times.
✗ Branch 2 → 11 not taken.
362 ensureNoConstAssign(node, lhs.type);
302
303 // Remove reference wrappers
304
1/2
✓ Branch 3 → 4 taken 362 times.
✗ Branch 3 → 11 not taken.
362 const QualType lhsType = lhs.type.removeReferenceWrapper();
305
1/2
✓ Branch 4 → 5 taken 362 times.
✗ Branch 4 → 11 not taken.
362 const QualType rhsType = rhs.type.removeReferenceWrapper();
306
307
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);
308 }
309
310 1267 QualType OpRuleManager::getLogicalOrResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
311 // Remove reference wrappers
312
1/2
✓ Branch 2 → 3 taken 1267 times.
✗ Branch 2 → 10 not taken.
1267 const QualType lhsType = lhs.type.removeReferenceWrapper();
313
1/2
✓ Branch 3 → 4 taken 1267 times.
✗ Branch 3 → 10 not taken.
1267 const QualType rhsType = rhs.type.removeReferenceWrapper();
314
315
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);
316 }
317
318 223 QualType OpRuleManager::getLogicalAndResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
319 // Remove reference wrappers
320
1/2
✓ Branch 2 → 3 taken 223 times.
✗ Branch 2 → 10 not taken.
223 const QualType lhsType = lhs.type.removeReferenceWrapper();
321
1/2
✓ Branch 3 → 4 taken 223 times.
✗ Branch 3 → 10 not taken.
223 const QualType rhsType = rhs.type.removeReferenceWrapper();
322
323
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);
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 4411 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 4411 times.
✗ Branch 2 → 38 not taken.
4411 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_EQUAL, {lhs, rhs}, 0);
353
3/4
✓ Branch 3 → 4 taken 4411 times.
✗ Branch 3 → 39 not taken.
✓ Branch 4 → 5 taken 450 times.
✓ Branch 4 → 6 taken 3961 times.
4411 if (!resultType.type.is(TY_INVALID))
354 450 return resultType;
355
356 // Remove reference wrappers
357
1/2
✓ Branch 6 → 7 taken 3961 times.
✗ Branch 6 → 39 not taken.
3961 const QualType lhsType = lhs.type.removeReferenceWrapper();
358
1/2
✓ Branch 7 → 8 taken 3961 times.
✗ Branch 7 → 39 not taken.
3961 const QualType rhsType = rhs.type.removeReferenceWrapper();
359
360 // Allow 'pointer == unsigned long' straight away
361
10/14
✓ Branch 8 → 9 taken 3961 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 987 times.
✓ Branch 9 → 15 taken 2974 times.
✓ Branch 10 → 11 taken 987 times.
✗ Branch 10 → 39 not taken.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 15 taken 986 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 3960 times.
3961 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 3960 times.
✗ Branch 19 → 39 not taken.
✓ Branch 20 → 21 taken 157 times.
✓ Branch 20 → 23 taken 3803 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 3960 times.
✗ Branch 23 → 39 not taken.
✓ Branch 24 → 25 taken 576 times.
✓ Branch 24 → 28 taken 3384 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 3960 times.
3960 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 3959 times.
✓ Branch 34 → 39 taken 1 time.
3960 return ExprResult(validateBinaryOperation(node, EQUAL_OP_RULES, std::size(EQUAL_OP_RULES), "==", lhsType, rhsType));
370 }
371
372 1639 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 1639 times.
✗ Branch 2 → 38 not taken.
1639 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_NOT_EQUAL, {lhs, rhs}, 0);
375
3/4
✓ Branch 3 → 4 taken 1639 times.
✗ Branch 3 → 39 not taken.
✓ Branch 4 → 5 taken 11 times.
✓ Branch 4 → 6 taken 1628 times.
1639 if (!resultType.type.is(TY_INVALID))
376 11 return resultType;
377
378 // Remove reference wrappers
379
1/2
✓ Branch 6 → 7 taken 1628 times.
✗ Branch 6 → 39 not taken.
1628 const QualType lhsType = lhs.type.removeReferenceWrapper();
380
1/2
✓ Branch 7 → 8 taken 1628 times.
✗ Branch 7 → 39 not taken.
1628 const QualType rhsType = rhs.type.removeReferenceWrapper();
381
382 // Allow 'pointer != unsigned long' straight away
383
10/14
✓ Branch 8 → 9 taken 1628 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 228 times.
✓ Branch 9 → 15 taken 1400 times.
✓ Branch 10 → 11 taken 228 times.
✗ Branch 10 → 39 not taken.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 15 taken 227 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 1627 times.
1628 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 1627 times.
✗ Branch 19 → 39 not taken.
✓ Branch 20 → 21 taken 10 times.
✓ Branch 20 → 23 taken 1617 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 1627 times.
✗ Branch 23 → 39 not taken.
✓ Branch 24 → 25 taken 7 times.
✓ Branch 24 → 28 taken 1620 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 1620 times.
1627 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 1620 times.
✗ Branch 34 → 39 not taken.
1620 return ExprResult(validateBinaryOperation(node, NOT_EQUAL_OP_RULES, std::size(NOT_EQUAL_OP_RULES), "!=", lhsType, rhsType));
392 }
393
394 2011 QualType OpRuleManager::getLessResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
395 // Remove reference wrappers
396
1/2
✓ Branch 2 → 3 taken 2011 times.
✗ Branch 2 → 10 not taken.
2011 const QualType lhsType = lhs.type.removeReferenceWrapper();
397
1/2
✓ Branch 3 → 4 taken 2011 times.
✗ Branch 3 → 10 not taken.
2011 const QualType rhsType = rhs.type.removeReferenceWrapper();
398
399
1/2
✓ Branch 6 → 7 taken 2011 times.
✗ Branch 6 → 10 not taken.
4022 return validateBinaryOperation(node, LESS_OP_RULES, std::size(LESS_OP_RULES), "<", lhsType, rhsType);
400 }
401
402 568 QualType OpRuleManager::getGreaterResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
403 // Remove reference wrappers
404
1/2
✓ Branch 2 → 3 taken 568 times.
✗ Branch 2 → 10 not taken.
568 const QualType lhsType = lhs.type.removeReferenceWrapper();
405
1/2
✓ Branch 3 → 4 taken 568 times.
✗ Branch 3 → 10 not taken.
568 const QualType rhsType = rhs.type.removeReferenceWrapper();
406
407
2/2
✓ Branch 6 → 7 taken 567 times.
✓ Branch 6 → 10 taken 1 time.
1135 return validateBinaryOperation(node, GREATER_OP_RULES, std::size(GREATER_OP_RULES), ">", lhsType, rhsType);
408 }
409
410 432 QualType OpRuleManager::getLessEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
411 // Remove reference wrappers
412
1/2
✓ Branch 2 → 3 taken 432 times.
✗ Branch 2 → 10 not taken.
432 const QualType lhsType = lhs.type.removeReferenceWrapper();
413
1/2
✓ Branch 3 → 4 taken 432 times.
✗ Branch 3 → 10 not taken.
432 const QualType rhsType = rhs.type.removeReferenceWrapper();
414
415
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);
416 }
417
418 1073 QualType OpRuleManager::getGreaterEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
419 // Remove reference wrappers
420
1/2
✓ Branch 2 → 3 taken 1073 times.
✗ Branch 2 → 21 not taken.
1073 const QualType lhsType = lhs.type.removeReferenceWrapper();
421
1/2
✓ Branch 3 → 4 taken 1073 times.
✗ Branch 3 → 21 not taken.
1073 const QualType rhsType = rhs.type.removeReferenceWrapper();
422
423 // Allow 'pointer == pointer' straight away
424
7/10
✓ Branch 4 → 5 taken 1073 times.
✗ Branch 4 → 21 not taken.
✓ Branch 5 → 6 taken 4 times.
✓ Branch 5 → 9 taken 1069 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 1069 times.
1073 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 1069 times.
✗ Branch 16 → 21 not taken.
1069 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 3161 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 3161 times.
✗ Branch 2 → 32 not taken.
3161 const ExprResult result = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_PLUS, {lhs, rhs}, opIdx);
459
3/4
✓ Branch 3 → 4 taken 3161 times.
✗ Branch 3 → 35 not taken.
✓ Branch 4 → 5 taken 70 times.
✓ Branch 4 → 6 taken 3091 times.
3161 if (!result.type.is(TY_INVALID))
460 70 return result;
461
462 // Remove reference wrappers
463
1/2
✓ Branch 6 → 7 taken 3091 times.
✗ Branch 6 → 35 not taken.
3091 const QualType lhsType = lhs.type.removeReferenceWrapper();
464
1/2
✓ Branch 7 → 8 taken 3091 times.
✗ Branch 7 → 35 not taken.
3091 const QualType rhsType = rhs.type.removeReferenceWrapper();
465
466 // Allow any* + <int/long/short>
467
7/10
✓ Branch 8 → 9 taken 3091 times.
✗ Branch 8 → 33 not taken.
✓ Branch 9 → 10 taken 579 times.
✓ Branch 9 → 13 taken 2512 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 2512 times.
3091 if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) {
468
1/2
✓ Branch 15 → 16 taken 579 times.
✗ Branch 15 → 35 not taken.
579 ensureUnsafeAllowed(node, "+", lhsType, rhsType);
469 579 return {lhsType};
470 }
471 // Allow <int/long/short> + any*
472
6/10
✓ Branch 17 → 18 taken 2512 times.
✗ Branch 17 → 34 not taken.
✓ Branch 18 → 19 taken 2400 times.
✓ Branch 18 → 22 taken 112 times.
✓ Branch 19 → 20 taken 2400 times.
✗ Branch 19 → 34 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 2400 times.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 26 taken 2512 times.
2512 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 2511 times.
✓ Branch 28 → 35 taken 1 time.
2512 return {validateBinaryOperation(node, PLUS_OP_RULES, std::size(PLUS_OP_RULES), "+", lhsType, rhsType)};
478 }
479
480 2013 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 2013 times.
✗ Branch 2 → 32 not taken.
2013 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MINUS, {lhs, rhs}, opIdx);
483
3/4
✓ Branch 3 → 4 taken 2013 times.
✗ Branch 3 → 35 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 2012 times.
2013 if (!resultType.type.is(TY_INVALID))
484 1 return resultType;
485
486 // Remove reference wrappers
487
1/2
✓ Branch 6 → 7 taken 2012 times.
✗ Branch 6 → 35 not taken.
2012 const QualType lhsType = lhs.type.removeReferenceWrapper();
488
1/2
✓ Branch 7 → 8 taken 2012 times.
✗ Branch 7 → 35 not taken.
2012 const QualType rhsType = rhs.type.removeReferenceWrapper();
489
490 // Allow any* - <int/long/short>
491
7/10
✓ Branch 8 → 9 taken 2012 times.
✗ Branch 8 → 33 not taken.
✓ Branch 9 → 10 taken 3 times.
✓ Branch 9 → 13 taken 2009 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 2009 times.
2012 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 2009 times.
✗ Branch 17 → 34 not taken.
✓ Branch 18 → 19 taken 1996 times.
✓ Branch 18 → 22 taken 13 times.
✓ Branch 19 → 20 taken 1996 times.
✗ Branch 19 → 34 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 1996 times.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 26 taken 2009 times.
2009 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 2009 times.
✗ Branch 28 → 35 not taken.
2009 return {validateBinaryOperation(node, MINUS_OP_RULES, std::size(MINUS_OP_RULES), "-", lhsType, rhsType)};
502 }
503
504 819 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 819 times.
✗ Branch 2 → 14 not taken.
819 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MUL, {lhs, rhs}, opIdx);
507
3/4
✓ Branch 3 → 4 taken 819 times.
✗ Branch 3 → 15 not taken.
✓ Branch 4 → 5 taken 9 times.
✓ Branch 4 → 6 taken 810 times.
819 if (!resultType.type.is(TY_INVALID))
508 9 return resultType;
509
510 // Remove reference wrappers
511
1/2
✓ Branch 6 → 7 taken 810 times.
✗ Branch 6 → 15 not taken.
810 const QualType lhsType = lhs.type.removeReferenceWrapper();
512
1/2
✓ Branch 7 → 8 taken 810 times.
✗ Branch 7 → 15 not taken.
810 const QualType rhsType = rhs.type.removeReferenceWrapper();
513
514
2/2
✓ Branch 10 → 11 taken 809 times.
✓ Branch 10 → 15 taken 1 time.
810 return {validateBinaryOperation(node, MUL_OP_RULES, std::size(MUL_OP_RULES), "*", lhsType, rhsType)};
515 }
516
517 165 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 165 times.
✗ Branch 2 → 14 not taken.
165 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_DIV, {lhs, rhs}, opIdx);
520
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))
521 3 return resultType;
522
523 // Remove reference wrappers
524
1/2
✓ Branch 6 → 7 taken 162 times.
✗ Branch 6 → 15 not taken.
162 const QualType lhsType = lhs.type.removeReferenceWrapper();
525
1/2
✓ Branch 7 → 8 taken 162 times.
✗ Branch 7 → 15 not taken.
162 const QualType rhsType = rhs.type.removeReferenceWrapper();
526
527
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)};
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 783 QualType OpRuleManager::getPrefixNotResultType(const ASTNode *node, const ExprResult &lhs) {
578 // Remove reference wrappers
579
1/2
✓ Branch 2 → 3 taken 783 times.
✗ Branch 2 → 9 not taken.
783 const QualType lhsType = lhs.type.removeReferenceWrapper();
580
581
1/2
✓ Branch 5 → 6 taken 783 times.
✗ Branch 5 → 9 not taken.
1566 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 235 QualType OpRuleManager::getPrefixMulResultType(const ASTNode *node, const ExprResult &lhs) {
592 // Remove reference wrappers
593
1/2
✓ Branch 2 → 3 taken 235 times.
✗ Branch 2 → 25 not taken.
235 const QualType lhsType = lhs.type.removeReferenceWrapper();
594
595
3/4
✓ Branch 3 → 4 taken 235 times.
✗ Branch 3 → 25 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 12 taken 234 times.
235 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 234 times.
✗ Branch 12 → 25 not taken.
468 return lhsType.getContained();
598 }
599
600 180 QualType OpRuleManager::getPrefixBitwiseAndResultType(const ASTNode *node, const ExprResult &lhs) {
601 // Remove reference wrappers
602
1/2
✓ Branch 2 → 3 taken 180 times.
✗ Branch 2 → 7 not taken.
180 const QualType lhsType = lhs.type.removeReferenceWrapper();
603
604
1/2
✓ Branch 3 → 4 taken 180 times.
✗ Branch 3 → 7 not taken.
360 return lhsType.toPtr(node);
605 }
606
607 1919 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 1918 times.
✓ Branch 2 → 18 taken 1 time.
1919 const ExprResult resultType = isOperatorOverloadingFctAvailable<1>(node, OP_FCT_POSTFIX_PLUS_PLUS, {lhs}, 0);
610
3/4
✓ Branch 3 → 4 taken 1918 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 9 times.
✓ Branch 4 → 6 taken 1909 times.
1918 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 1909 times.
✗ Branch 6 → 19 not taken.
1909 ensureNoConstAssign(node, lhs.type);
615
616 // Remove reference wrappers
617
1/2
✓ Branch 7 → 8 taken 1909 times.
✗ Branch 7 → 19 not taken.
1909 const QualType lhsType = lhs.type.removeReferenceWrapper();
618
619 // Check if this is an unsafe operation
620
3/4
✓ Branch 8 → 9 taken 1909 times.
✗ Branch 8 → 19 not taken.
✓ Branch 9 → 10 taken 9 times.
✓ Branch 9 → 12 taken 1900 times.
1909 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 1899 times.
✓ Branch 14 → 19 taken 1 time.
1900 return {validateUnaryOperation(node, POSTFIX_PLUS_PLUS_OP_RULES, std::size(POSTFIX_PLUS_PLUS_OP_RULES), "++", lhsType)};
626 }
627
628 442 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 442 times.
✗ Branch 2 → 18 not taken.
442 const ExprResult resultType = isOperatorOverloadingFctAvailable<1>(node, OP_FCT_POSTFIX_MINUS_MINUS, {lhs}, 0);
631
3/4
✓ Branch 3 → 4 taken 442 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 7 times.
✓ Branch 4 → 6 taken 435 times.
442 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 435 times.
✗ Branch 6 → 19 not taken.
435 ensureNoConstAssign(node, lhs.type);
636
637 // Remove reference wrappers
638
1/2
✓ Branch 7 → 8 taken 435 times.
✗ Branch 7 → 19 not taken.
435 const QualType lhsType = lhs.type.removeReferenceWrapper();
639
640 // Check if this is an unsafe operation
641
3/4
✓ Branch 8 → 9 taken 435 times.
✗ Branch 8 → 19 not taken.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 12 taken 433 times.
435 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 433 times.
✗ Branch 14 → 19 not taken.
433 return {validateUnaryOperation(node, POSTFIX_MINUS_MINUS_OP_RULES, std::size(POSTFIX_MINUS_MINUS_OP_RULES), "--", lhsType)};
647 }
648
649 2714 QualType OpRuleManager::getCastResultType(const ASTNode *node, QualType lhsType, const ExprResult &rhs) const {
650 // Remove reference wrappers
651
1/2
✓ Branch 2 → 3 taken 2714 times.
✗ Branch 2 → 48 not taken.
2714 lhsType = lhsType.removeReferenceWrapper();
652
1/2
✓ Branch 3 → 4 taken 2714 times.
✗ Branch 3 → 55 not taken.
2714 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 109 times.
✓ Branch 6 → 8 taken 2605 times.
2714 if (lhsType.getQualifiers().isHeap != rhsType.getQualifiers().isHeap)
656
1/2
✓ Branch 7 → 8 taken 109 times.
✗ Branch 7 → 55 not taken.
109 ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType);
657
658 // Allow identity casts
659
3/4
✓ Branch 8 → 9 taken 2714 times.
✗ Branch 8 → 55 not taken.
✓ Branch 9 → 10 taken 274 times.
✓ Branch 9 → 11 taken 2440 times.
2714 if (lhsType.matches(rhsType, false, true, true))
660 274 return lhsType;
661 // Allow casts string -> char* and string -> char[]
662
12/16
✓ Branch 11 → 12 taken 2440 times.
✗ Branch 11 → 49 not taken.
✓ Branch 12 → 13 taken 1194 times.
✓ Branch 12 → 19 taken 1246 times.
✓ Branch 13 → 14 taken 1194 times.
✗ Branch 13 → 49 not taken.
✓ Branch 14 → 15 taken 1194 times.
✗ Branch 14 → 49 not taken.
✓ Branch 15 → 16 taken 952 times.
✓ Branch 15 → 19 taken 242 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 1492 times.
2440 if (lhsType.isOneOf({TY_PTR, TY_ARRAY}) && lhsType.getContained().is(TY_CHAR) && rhsType.is(TY_STRING))
663 948 return lhsType;
664 // Allow casts char* -> string and char[] -> string
665
10/16
✓ Branch 22 → 23 taken 1492 times.
✗ Branch 22 → 51 not taken.
✓ Branch 23 → 24 taken 96 times.
✓ Branch 23 → 30 taken 1396 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 1396 times.
1492 if (lhsType.is(TY_STRING) && rhsType.isOneOf({TY_PTR, TY_ARRAY}) && rhsType.getContained().is(TY_CHAR))
666 96 return lhsType;
667 // Allow casts any* -> any*
668
7/10
✓ Branch 33 → 34 taken 1396 times.
✗ Branch 33 → 53 not taken.
✓ Branch 34 → 35 taken 246 times.
✓ Branch 34 → 38 taken 1150 times.
✓ Branch 35 → 36 taken 246 times.
✗ Branch 35 → 53 not taken.
✓ Branch 36 → 37 taken 246 times.
✗ Branch 36 → 38 not taken.
✓ Branch 39 → 40 taken 246 times.
✓ Branch 39 → 42 taken 1150 times.
1396 if (lhsType.isOneOf({TY_PTR, TY_STRING}) && rhsType.isOneOf({TY_PTR, TY_STRING})) {
669
1/2
✓ Branch 40 → 41 taken 246 times.
✗ Branch 40 → 55 not taken.
246 ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType);
670 246 return lhsType;
671 }
672 // Check primitive type combinations
673
1/2
✓ Branch 44 → 45 taken 1150 times.
✗ Branch 44 → 55 not taken.
1150 return validateBinaryOperation(node, CAST_OP_RULES, std::size(CAST_OP_RULES), "(cast)", lhsType, rhsType, true);
674 }
675
676 template <size_t N>
677 18776 ExprResult OpRuleManager::isOperatorOverloadingFctAvailable(ASTNode *node, const char *const fctName,
678 const std::array<ExprResult, N> &op, size_t opIdx) const {
679 static_assert(N == 1 || N == 2, "Only unary and binary operators are overloadable");
680 18776 Scope *calleeParentScope = nullptr;
681 18776 const Function *callee = nullptr;
682
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 2361 times.
✗ Branch 2 → 123 not taken.
✓ Branch 3 → 4 taken 2361 times.
✗ Branch 3 → 123 not taken.
✓ Branch 4 → 5 taken 2361 times.
✗ Branch 4 → 123 not taken.
✓ Branch 42 → 43 taken 2538 times.
✓ Branch 42 → 45 taken 17 times.
✓ Branch 48 → 6 taken 20125 times.
✓ Branch 48 → 49 taken 2344 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 16415 times.
✗ Branch 2 → 132 not taken.
✓ Branch 3 → 4 taken 16415 times.
✗ Branch 3 → 132 not taken.
✓ Branch 4 → 5 taken 16415 times.
✗ Branch 4 → 132 not taken.
✓ Branch 49 → 50 taken 54545 times.
✓ Branch 49 → 52 taken 894 times.
✓ Branch 55 → 6 taken 133449 times.
✓ Branch 55 → 56 taken 15521 times.
229433 for (const auto &sourceFile : typeChecker->resourceManager.sourceFiles | std::views::values) {
683 // Check if there is a registered operator function
684
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 20125 times.
✗ Branch 10 → 102 not taken.
✓ Branch 11 → 12 taken 20125 times.
✗ Branch 11 → 100 not taken.
✓ Branch 14 → 15 taken 17570 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 133449 times.
✗ Branch 10 → 109 not taken.
✓ Branch 11 → 12 taken 133449 times.
✗ Branch 11 → 107 not taken.
✓ Branch 14 → 15 taken 78010 times.
✓ Branch 14 → 16 taken 55439 times.
460722 if (!sourceFile->getNameRegistryEntry(fctName))
685 95580 continue;
686
687 // Match callees in the global scope of this source file
688 57994 calleeParentScope = sourceFile->globalScope.get();
689
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 55439 times.
✗ Branch 18 → 131 not taken.
57994 const QualType thisType(TY_DYN);
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) 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 55439 times.
✗ Branch 21 → 113 not taken.
57994 ArgList args(N);
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) 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 55439 times.
✗ Branch 24 → 116 not taken.
57994 args[0] = {typeChecker->mapLocalTypeToImportedScopeType(calleeParentScope, op[0].type), op[0].isTemporary()};
692 if constexpr (N == 2)
693
1/2
✓ Branch 31 → 32 taken 55439 times.
✗ Branch 31 → 118 not taken.
55439 args[1] = {typeChecker->mapLocalTypeToImportedScopeType(calleeParentScope, op[1].type), op[1].isTemporary()};
694
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 55439 times.
✗ Branch 40 → 122 not taken.
✓ Branch 41 → 42 taken 55439 times.
✗ Branch 41 → 120 not taken.
173982 callee = FunctionManager::match(calleeParentScope, fctName, thisType, args, {}, false, node);
695
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 894 times.
✓ Branch 45 → 47 taken 54545 times.
57994 if (callee)
696 911 break;
697 }
698
699 // Return invalid type if the callee was not found
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 49 → 50 taken 2344 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 15521 times.
✓ Branch 56 → 59 taken 894 times.
18776 if (!callee)
701 17865 return ExprResult(QualType(TY_INVALID));
702
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 894 times.
911 assert(calleeParentScope != nullptr);
703
704 // Save the pointer to the operator function in the AST node
705 911 std::vector<const Function *> &opFctPointers = typeChecker->getOpFctPointers(node);
706
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 820 times.
911 if (opFctPointers.size() <= opIdx)
707
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);
708 911 opFctPointers.at(opIdx) = callee;
709
710 // Check if we need to request a re-visit, because the function body was not type-checked yet
711 911 TypeChecker::requestRevisitIfRequired(callee);
712
713 // Check if the called function has sufficient visibility
714
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 894 times.
✗ Branch 68 → 72 not taken.
✓ Branch 70 → 71 taken 392 times.
✓ Branch 70 → 72 taken 502 times.
911 const bool isImported = calleeParentScope != nullptr && calleeParentScope->isImportedBy(typeChecker->rootScope);
715 911 const SymbolTableEntry *calleeEntry = callee->entry;
716
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 392 times.
✓ Branch 73 → 78 taken 502 times.
✗ Branch 76 → 77 not taken.
✓ Branch 76 → 78 taken 392 times.
✗ Branch 79 → 80 not taken.
✓ Branch 79 → 89 taken 894 times.
911 if (isImported && !calleeEntry->getQualType().isPublic())
717
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,
718
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");
719
720 // Procedures always have the return type 'bool'
721
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 143 times.
✓ Branch 92 → 95 taken 751 times.
910 if (callee->isProcedure())
722 157 return ExprResult(QualType(TY_BOOL));
723 753 const QualType &returnType = callee->returnType;
724
725 // Add anonymous symbol to keep track of dtor call, if non-trivially destructible
726 753 SymbolTableEntry *anonymousSymbol = nullptr;
727
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 666 times.
✓ Branch 98 → 99 taken 79 times.
✓ Branch 98 → 100 taken 6 times.
✓ Branch 101 → 102 taken 79 times.
✓ Branch 101 → 104 taken 672 times.
753 if (returnType.is(TY_STRUCT) && !returnType.isTriviallyDestructible(node))
728 79 anonymousSymbol = typeChecker->currentScope->symbolTable.insertAnonymous(returnType, node, opIdx);
729
730 753 return {typeChecker->mapImportedScopeTypeToLocalType(calleeParentScope, returnType), anonymousSymbol};
731 }
732
733 4051 QualType OpRuleManager::validateUnaryOperation(const ASTNode *node, const UnaryOpRule opRules[], size_t opRulesSize,
734 const char *name, const QualType &lhs) {
735
2/2
✓ Branch 11 → 3 taken 9891 times.
✓ Branch 11 → 12 taken 2 times.
9893 for (size_t i = 0; i < opRulesSize; i++) {
736 9891 const UnaryOpRule &rule = opRules[i];
737
2/2
✓ Branch 5 → 6 taken 4049 times.
✓ Branch 5 → 10 taken 5842 times.
9891 if (std::get<0>(rule) == lhs.getSuperType())
738
1/2
✓ Branch 7 → 8 taken 4049 times.
✗ Branch 7 → 16 not taken.
4049 return QualType(std::get<1>(rule));
739 }
740
1/2
✓ Branch 13 → 14 taken 2 times.
✗ Branch 13 → 17 not taken.
2 throw getExceptionUnary(node, name, lhs);
741 }
742
743 39011 QualType OpRuleManager::validateBinaryOperation(const ASTNode *node, const BinaryOpRule opRules[], size_t opRulesSize,
744 const char *name, const QualType &lhs, const QualType &rhs,
745 bool preserveQualifiersFromLhs, const char *customMessagePrefix) {
746
2/2
✓ Branch 19 → 3 taken 386537 times.
✓ Branch 19 → 20 taken 19 times.
386556 for (size_t i = 0; i < opRulesSize; i++) {
747 386537 const BinaryOpRule &rule = opRules[i];
748
6/6
✓ Branch 5 → 6 taken 75970 times.
✓ Branch 5 → 10 taken 310567 times.
✓ Branch 8 → 9 taken 38992 times.
✓ Branch 8 → 10 taken 36978 times.
✓ Branch 11 → 12 taken 38992 times.
✓ Branch 11 → 18 taken 347545 times.
386537 if (std::get<0>(rule) == lhs.getSuperType() && std::get<1>(rule) == rhs.getSuperType()) {
749
1/2
✓ Branch 13 → 14 taken 38992 times.
✗ Branch 13 → 24 not taken.
38992 QualType resultType((std::get<2>(rule)));
750
2/2
✓ Branch 14 → 15 taken 21369 times.
✓ Branch 14 → 17 taken 17623 times.
38992 if (preserveQualifiersFromLhs)
751 21369 resultType.setQualifiers(lhs.getQualifiers());
752 38992 return resultType;
753 }
754 }
755
1/2
✓ Branch 21 → 22 taken 19 times.
✗ Branch 21 → 25 not taken.
19 throw getExceptionBinary(node, name, lhs, rhs, customMessagePrefix);
756 }
757
758 2 SemanticError OpRuleManager::getExceptionUnary(const ASTNode *node, const char *name, const QualType &lhs) {
759
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)};
760 }
761
762 19 SemanticError OpRuleManager::getExceptionBinary(const ASTNode *node, const char *name, const QualType &lhs, const QualType &rhs,
763 const char *messagePrefix) {
764 // Build error message
765
1/2
✓ Branch 2 → 3 taken 19 times.
✗ Branch 2 → 50 not taken.
19 std::stringstream errorMsg;
766
2/2
✓ Branch 3 → 4 taken 4 times.
✓ Branch 3 → 14 taken 15 times.
19 if (strlen(messagePrefix) != 0)
767
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);
768 else
769
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);
770
771 // Return the exception
772
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()};
773 19 }
774
775 11 void OpRuleManager::ensureUnsafeAllowed(const ASTNode *node, const char *name, const QualType &lhs) const {
776
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())
777 11 return;
778 // Print error message
779 const std::string lhsName = lhs.getName(true);
780 const std::string errorMsg = "Cannot apply '" + std::string(name) + "' operator on type " + lhsName +
781 " as this is an unsafe operation. Please use unsafe blocks if you know what you are doing.";
782 SOFT_ERROR_VOID(node, UNSAFE_OPERATION_IN_SAFE_CONTEXT, errorMsg)
783 }
784
785 947 void OpRuleManager::ensureUnsafeAllowed(const ASTNode *node, const char *name, const QualType &lhs, const QualType &rhs) const {
786
3/4
✓ Branch 2 → 3 taken 947 times.
✗ Branch 2 → 57 not taken.
✓ Branch 3 → 4 taken 946 times.
✓ Branch 3 → 5 taken 1 time.
947 if (typeChecker->currentScope->doesAllowUnsafeOperations())
787 946 return;
788 // Print error message
789
1/2
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 57 not taken.
1 const std::string lhsName = lhs.getName(true);
790
1/2
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 55 not taken.
1 const std::string rhsName = rhs.getName(true);
791
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 +
792
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.";
793
1/2
✓ Branch 23 → 24 taken 1 time.
✗ Branch 23 → 51 not taken.
1 SOFT_ERROR_VOID(node, UNSAFE_OPERATION_IN_SAFE_CONTEXT, errorMsg)
794 1 }
795
796 30301 void OpRuleManager::ensureNoConstAssign(const ASTNode *node, const QualType &lhs, bool isDecl, bool isReturn) const {
797 // Check if we try to assign a constant value
798
10/12
✓ Branch 2 → 3 taken 30301 times.
✗ Branch 2 → 18 not taken.
✓ Branch 3 → 4 taken 30301 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 3430 times.
✓ Branch 4 → 8 taken 26871 times.
✓ Branch 5 → 6 taken 55 times.
✓ Branch 5 → 8 taken 3375 times.
✓ Branch 6 → 7 taken 14 times.
✓ Branch 6 → 8 taken 41 times.
✓ Branch 9 → 10 taken 14 times.
✓ Branch 9 → 17 taken 30287 times.
30301 if (lhs.removeReferenceWrapper().isConst() && !isDecl && !isReturn) {
799
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);
800
1/2
✓ Branch 13 → 14 taken 14 times.
✗ Branch 13 → 22 not taken.
14 SOFT_ERROR_VOID(node, REASSIGN_CONST_VARIABLE, errorMessage);
801 14 }
802 }
803
804 } // namespace spice::compiler
805