GCC Code Coverage Report


Directory: ../
File: src/typechecker/OpRuleManager.cpp
Date: 2025-11-11 23:26:16
Coverage Exec Excl Total
Lines: 94.1% 430 0 457
Functions: 100.0% 51 0 51
Branches: 60.0% 707 0 1178

Line Branch Exec Source
1 // Copyright (c) 2021-2025 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 3510 OpRuleManager::OpRuleManager(TypeChecker *typeChecker)
15 3510 : typeChecker(typeChecker), resourceManager(typeChecker->resourceManager) {}
16
17 25573 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 25573 const QualType lhsType = lhs.type;
22 25573 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 25572 times.
25573 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 25572 times.
✗ Branch 12 → 125 not taken.
✓ Branch 13 → 14 taken 69 times.
✓ Branch 13 → 16 taken 25503 times.
25572 if (lhsType.is(TY_DYN))
30 69 return {rhsType, nullptr};
31
32 // Check if we try to assign a constant value
33
1/2
✓ Branch 16 → 17 taken 25503 times.
✗ Branch 16 → 125 not taken.
25503 ensureNoConstAssign(node, lhsType, isDecl, isReturn);
34
35 // Allow pointers and references of the same type straight away
36
8/10
✓ Branch 17 → 18 taken 25503 times.
✗ Branch 17 → 117 not taken.
✓ Branch 18 → 19 taken 3512 times.
✓ Branch 18 → 22 taken 21991 times.
✓ Branch 19 → 20 taken 3512 times.
✗ Branch 19 → 117 not taken.
✓ Branch 20 → 21 taken 2885 times.
✓ Branch 20 → 22 taken 627 times.
✓ Branch 23 → 24 taken 2885 times.
✓ Branch 23 → 41 taken 22618 times.
25503 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 961 times.
✓ Branch 24 → 35 taken 1924 times.
✓ Branch 25 → 26 taken 961 times.
✗ Branch 25 → 118 not taken.
✓ Branch 26 → 27 taken 651 times.
✓ Branch 26 → 35 taken 310 times.
✓ Branch 27 → 28 taken 651 times.
✗ Branch 27 → 118 not taken.
✓ Branch 28 → 29 taken 537 times.
✓ Branch 28 → 35 taken 114 times.
✓ Branch 29 → 30 taken 537 times.
✗ Branch 29 → 118 not taken.
✓ Branch 30 → 31 taken 537 times.
✗ Branch 30 → 118 not taken.
✓ Branch 31 → 32 taken 537 times.
✗ Branch 31 → 35 not taken.
✓ Branch 32 → 33 taken 537 times.
✗ Branch 32 → 118 not taken.
✓ Branch 33 → 34 taken 537 times.
✗ Branch 33 → 35 not taken.
✓ Branch 36 → 37 taken 537 times.
✓ Branch 36 → 39 taken 2348 times.
2885 if (rhs.entry && lhsType.isPtr() && lhsType.isHeap() && rhsType.removeReferenceWrapper().isPtr() && rhsType.isHeap())
39
1/2
✓ Branch 37 → 38 taken 537 times.
✗ Branch 37 → 119 not taken.
537 rhs.entry->updateState(MOVED, node);
40 2885 return {rhsType, nullptr};
41 }
42 // Allow ref type to type of the same contained type straight away
43
3/4
✓ Branch 41 → 42 taken 22618 times.
✗ Branch 41 → 125 not taken.
✓ Branch 42 → 43 taken 368 times.
✓ Branch 42 → 63 taken 22250 times.
22618 if (rhsType.isRef()) {
44 // If this is const ref, remove both: the reference and the constness
45
2/4
✓ Branch 43 → 44 taken 368 times.
✗ Branch 43 → 120 not taken.
✓ Branch 44 → 45 taken 368 times.
✗ Branch 44 → 120 not taken.
368 const QualType rhsModified = rhsType.getContained().toNonConst();
46
3/4
✓ Branch 45 → 46 taken 368 times.
✗ Branch 45 → 122 not taken.
✓ Branch 46 → 47 taken 366 times.
✓ Branch 46 → 62 taken 2 times.
368 if (lhsType.matches(rhsModified, false, false, true)) {
47 // Check if we support nrvo. If yes, skip the implicit copy ctor call
48
4/4
✓ Branch 47 → 48 taken 13 times.
✓ Branch 47 → 51 taken 353 times.
✓ Branch 49 → 50 taken 2 times.
✓ Branch 49 → 51 taken 11 times.
366 const bool supportsNRVO = isReturn && !rhs.isTemporary();
49 366 Function *copyCtor = nullptr;
50
7/8
✓ Branch 52 → 53 taken 366 times.
✗ Branch 52 → 121 not taken.
✓ Branch 53 → 54 taken 242 times.
✓ Branch 53 → 56 taken 124 times.
✓ Branch 54 → 55 taken 240 times.
✓ Branch 54 → 56 taken 2 times.
✓ Branch 57 → 58 taken 240 times.
✓ Branch 57 → 60 taken 126 times.
366 if (rhsModified.is(TY_STRUCT) && !supportsNRVO)
51
1/2
✓ Branch 58 → 59 taken 240 times.
✗ Branch 58 → 121 not taken.
240 copyCtor = typeChecker->implicitlyCallStructCopyCtor(rhsModified, node);
52 366 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 22252 times.
✗ Branch 63 → 123 not taken.
✓ Branch 64 → 65 taken 80 times.
✓ Branch 64 → 68 taken 22172 times.
✓ Branch 65 → 66 taken 80 times.
✗ Branch 65 → 123 not taken.
✓ Branch 66 → 67 taken 75 times.
✓ Branch 66 → 68 taken 5 times.
✓ Branch 69 → 70 taken 75 times.
✓ Branch 69 → 72 taken 22177 times.
22252 if (lhsType.isOneOf({TY_ARRAY, TY_INTERFACE, TY_FUNCTION, TY_PROCEDURE}) && lhsType.matches(rhsType, false, true, true))
57 75 return {rhsType, nullptr};
58 // Allow struct of the same type straight away
59
8/10
✓ Branch 72 → 73 taken 22177 times.
✗ Branch 72 → 125 not taken.
✓ Branch 73 → 74 taken 2675 times.
✓ Branch 73 → 77 taken 19502 times.
✓ Branch 74 → 75 taken 2675 times.
✗ Branch 74 → 125 not taken.
✓ Branch 75 → 76 taken 2674 times.
✓ Branch 75 → 77 taken 1 time.
✓ Branch 78 → 79 taken 2674 times.
✓ Branch 78 → 96 taken 19503 times.
22177 if (lhsType.is(TY_STRUCT) && lhsType.matches(rhsType, false, true, true)) {
60 // Check if we support nrvo. If yes, skip the implicit copy ctor call
61
4/4
✓ Branch 79 → 80 taken 1476 times.
✓ Branch 79 → 83 taken 1198 times.
✓ Branch 81 → 82 taken 110 times.
✓ Branch 81 → 83 taken 1366 times.
2674 const bool supportsNRVO = isReturn && !rhs.isTemporary();
62 2674 Function *copyCtor = nullptr;
63
10/10
✓ Branch 84 → 85 taken 1988 times.
✓ Branch 84 → 90 taken 686 times.
✓ Branch 85 → 86 taken 1878 times.
✓ Branch 85 → 90 taken 110 times.
✓ Branch 86 → 87 taken 1030 times.
✓ Branch 86 → 90 taken 848 times.
✓ Branch 88 → 89 taken 11 times.
✓ Branch 88 → 90 taken 1019 times.
✓ Branch 91 → 92 taken 11 times.
✓ Branch 91 → 94 taken 2663 times.
2674 if (rhs.entry != nullptr && !supportsNRVO && !isReturn && !rhs.isTemporary())
64
1/2
✓ Branch 92 → 93 taken 11 times.
✗ Branch 92 → 124 not taken.
11 copyCtor = typeChecker->implicitlyCallStructCopyCtor(rhsType, rhs.entry->declNode);
65 2674 return {rhsType, copyCtor};
66 }
67
68 // Check common type combinations
69
2/2
✓ Branch 96 → 97 taken 19501 times.
✓ Branch 96 → 125 taken 2 times.
19503 const QualType resultType = getAssignResultTypeCommon(node, lhs, rhs, isDecl, isReturn);
70
3/4
✓ Branch 97 → 98 taken 19501 times.
✗ Branch 97 → 125 not taken.
✓ Branch 98 → 99 taken 575 times.
✓ Branch 98 → 101 taken 18926 times.
19501 if (!resultType.is(TY_INVALID))
71 575 return {resultType, nullptr};
72
73 // Check primitive type combinations
74 const QualType binOpType =
75
2/2
✓ Branch 103 → 104 taken 18914 times.
✓ Branch 103 → 125 taken 12 times.
18926 validateBinaryOperation(node, ASSIGN_OP_RULES, std::size(ASSIGN_OP_RULES), "=", lhsType, rhsType, true, errMsgPrefix);
76 18914 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 19645 QualType OpRuleManager::getAssignResultTypeCommon(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, bool isDecl,
127 bool isReturn) {
128 // Retrieve types
129 19645 const QualType lhsType = lhs.type;
130 19645 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 19645 times.
✗ Branch 2 → 113 not taken.
✓ Branch 3 → 4 taken 421 times.
✓ Branch 3 → 8 taken 19224 times.
✓ Branch 4 → 5 taken 421 times.
✗ Branch 4 → 113 not taken.
✓ Branch 5 → 6 taken 421 times.
✗ Branch 5 → 113 not taken.
✓ Branch 6 → 7 taken 418 times.
✓ Branch 6 → 8 taken 3 times.
✓ Branch 9 → 10 taken 418 times.
✓ Branch 9 → 44 taken 19227 times.
19645 if (lhsType.isRef() && lhsType.getContained().matches(rhsType, false, false, true)) {
134
4/4
✓ Branch 10 → 11 taken 356 times.
✓ Branch 10 → 12 taken 62 times.
✓ Branch 11 → 12 taken 294 times.
✓ Branch 11 → 13 taken 62 times.
418 const bool isDeclOrReturn = isDecl || isReturn;
135
7/8
✓ Branch 14 → 15 taken 356 times.
✓ Branch 14 → 19 taken 62 times.
✓ Branch 16 → 17 taken 356 times.
✗ Branch 16 → 137 not taken.
✓ Branch 17 → 18 taken 1 time.
✓ Branch 17 → 19 taken 355 times.
✓ Branch 20 → 21 taken 1 time.
✓ Branch 20 → 29 taken 417 times.
418 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 294 times.
✓ Branch 29 → 33 taken 123 times.
✓ Branch 31 → 32 taken 1 time.
✓ Branch 31 → 33 taken 293 times.
✓ Branch 34 → 35 taken 1 time.
✓ Branch 34 → 43 taken 416 times.
417 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 416 return lhsType;
140 }
141 // Allow char* = string
142
9/14
✓ Branch 44 → 45 taken 19227 times.
✗ Branch 44 → 137 not taken.
✓ Branch 45 → 46 taken 1 time.
✓ Branch 45 → 53 taken 19226 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 19226 times.
19227 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 19226 times.
✗ Branch 56 → 132 not taken.
✓ Branch 57 → 58 taken 162 times.
✓ Branch 57 → 65 taken 19064 times.
✓ Branch 58 → 59 taken 162 times.
✗ Branch 58 → 132 not taken.
✓ Branch 59 → 60 taken 5 times.
✓ Branch 59 → 65 taken 157 times.
✓ Branch 60 → 61 taken 5 times.
✗ Branch 60 → 132 not taken.
✓ Branch 61 → 62 taken 5 times.
✗ Branch 61 → 132 not taken.
✓ Branch 62 → 63 taken 5 times.
✗ Branch 62 → 132 not taken.
✓ Branch 63 → 64 taken 5 times.
✗ Branch 63 → 65 not taken.
✓ Branch 66 → 67 taken 5 times.
✓ Branch 66 → 68 taken 19221 times.
19226 if (lhsType.isPtr() && rhsType.isArray() && lhsType.getContained().matches(rhsType.getContained(), false, false, true))
146 5 return lhsType;
147 // Allow interface* = struct* or interface& = struct that implements this interface
148
1/2
✓ Branch 70 → 71 taken 19221 times.
✗ Branch 70 → 137 not taken.
19221 const bool sameChainDepth = Type::hasSameTypeChainDepth(lhsType.getType(), rhsType.getType());
149
10/14
✓ Branch 71 → 72 taken 19221 times.
✗ Branch 71 → 137 not taken.
✓ Branch 72 → 73 taken 157 times.
✓ Branch 72 → 76 taken 19064 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 19065 times.
✗ Branch 76 → 137 not taken.
✓ Branch 77 → 78 taken 3 times.
✓ Branch 77 → 79 taken 19062 times.
19221 const bool typesCompatible = (lhsType.isPtr() && rhsType.isPtr() && sameChainDepth) || lhsType.isRef();
150
9/12
✓ Branch 80 → 81 taken 159 times.
✓ Branch 80 → 86 taken 19062 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 19216 times.
19221 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::unwrapBoth(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 19216 times.
✗ Branch 93 → 137 not taken.
✓ Branch 94 → 95 taken 153 times.
✓ Branch 94 → 100 taken 19063 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 19064 times.
19216 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 19064 times.
✗ Branch 108 → 136 not taken.
19064 return QualType(TY_INVALID);
167 }
168
169 256 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 256 times.
✗ Branch 2 → 24 not taken.
256 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_PLUS_EQUAL, {lhs, rhs}, opIdx);
172
3/4
✓ Branch 3 → 4 taken 256 times.
✗ Branch 3 → 26 not taken.
✓ Branch 4 → 5 taken 97 times.
✓ Branch 4 → 6 taken 159 times.
256 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 159 times.
✗ Branch 6 → 26 not taken.
159 ensureNoConstAssign(node, lhs.type);
177
178 // Remove reference wrappers
179
1/2
✓ Branch 7 → 8 taken 159 times.
✗ Branch 7 → 26 not taken.
159 const QualType lhsType = lhs.type.removeReferenceWrapper();
180
1/2
✓ Branch 8 → 9 taken 159 times.
✗ Branch 8 → 26 not taken.
159 const QualType rhsType = rhs.type.removeReferenceWrapper();
181
182 // Check if this is an unsafe operation
183
7/10
✓ Branch 9 → 10 taken 159 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 1 time.
✓ Branch 10 → 14 taken 158 times.
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 25 not taken.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 14 not taken.
✓ Branch 15 → 16 taken 1 time.
✓ Branch 15 → 18 taken 158 times.
159 if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) {
184
1/2
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 26 not taken.
1 ensureUnsafeAllowed(node, "+=", lhsType, rhsType);
185 1 return {lhs};
186 }
187
188
1/2
✓ Branch 20 → 21 taken 158 times.
✗ Branch 20 → 26 not taken.
158 return {validateBinaryOperation(node, PLUS_EQUAL_OP_RULES, std::size(PLUS_EQUAL_OP_RULES), "+=", lhsType, rhsType)};
189 }
190
191 33 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 33 times.
✗ Branch 2 → 24 not taken.
33 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MINUS_EQUAL, {lhs, rhs}, opIdx);
194
3/4
✓ Branch 3 → 4 taken 33 times.
✗ Branch 3 → 26 not taken.
✓ Branch 4 → 5 taken 7 times.
✓ Branch 4 → 6 taken 26 times.
33 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 26 times.
✗ Branch 6 → 26 not taken.
26 ensureNoConstAssign(node, lhs.type);
199
200 // Remove reference wrappers
201
1/2
✓ Branch 7 → 8 taken 26 times.
✗ Branch 7 → 26 not taken.
26 const QualType lhsType = lhs.type.removeReferenceWrapper();
202
1/2
✓ Branch 8 → 9 taken 26 times.
✗ Branch 8 → 26 not taken.
26 const QualType rhsType = rhs.type.removeReferenceWrapper();
203
204 // Check if this is an unsafe operation
205
7/10
✓ Branch 9 → 10 taken 26 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 1 time.
✓ Branch 10 → 14 taken 25 times.
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 25 not taken.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 14 not taken.
✓ Branch 15 → 16 taken 1 time.
✓ Branch 15 → 18 taken 25 times.
26 if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) {
206
1/2
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 26 not taken.
1 ensureUnsafeAllowed(node, "-=", lhsType, rhsType);
207 1 return {lhs};
208 }
209
210
1/2
✓ Branch 20 → 21 taken 25 times.
✗ Branch 20 → 26 not taken.
25 return {validateBinaryOperation(node, MINUS_EQUAL_OP_RULES, std::size(MINUS_EQUAL_OP_RULES), "-=", lhsType, rhsType)};
211 }
212
213 40 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 40 times.
✗ Branch 2 → 15 not taken.
40 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MUL_EQUAL, {lhs, rhs}, opIdx);
216
3/4
✓ Branch 3 → 4 taken 40 times.
✗ Branch 3 → 16 not taken.
✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 6 taken 38 times.
40 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 38 times.
✗ Branch 6 → 16 not taken.
38 ensureNoConstAssign(node, lhs.type);
221
222 // Remove reference wrappers
223
1/2
✓ Branch 7 → 8 taken 38 times.
✗ Branch 7 → 16 not taken.
38 const QualType lhsType = lhs.type.removeReferenceWrapper();
224
1/2
✓ Branch 8 → 9 taken 38 times.
✗ Branch 8 → 16 not taken.
38 const QualType rhsType = rhs.type.removeReferenceWrapper();
225
226
1/2
✓ Branch 11 → 12 taken 38 times.
✗ Branch 11 → 16 not taken.
38 return {validateBinaryOperation(node, MUL_EQUAL_OP_RULES, std::size(MUL_EQUAL_OP_RULES), "*=", lhsType, rhsType)};
227 }
228
229 45 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 45 times.
✗ Branch 2 → 15 not taken.
45 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_DIV_EQUAL, {lhs, rhs}, opIdx);
232
3/4
✓ Branch 3 → 4 taken 45 times.
✗ Branch 3 → 16 not taken.
✓ Branch 4 → 5 taken 37 times.
✓ Branch 4 → 6 taken 8 times.
45 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 8 times.
✗ Branch 6 → 16 not taken.
8 ensureNoConstAssign(node, lhs.type);
237
238 // Remove reference wrappers
239
1/2
✓ Branch 7 → 8 taken 8 times.
✗ Branch 7 → 16 not taken.
8 const QualType lhsType = lhs.type.removeReferenceWrapper();
240
1/2
✓ Branch 8 → 9 taken 8 times.
✗ Branch 8 → 16 not taken.
8 const QualType rhsType = rhs.type.removeReferenceWrapper();
241
242
1/2
✓ Branch 11 → 12 taken 8 times.
✗ Branch 11 → 16 not taken.
8 return {validateBinaryOperation(node, DIV_EQUAL_OP_RULES, std::size(DIV_EQUAL_OP_RULES), "/=", lhsType, rhsType)};
243 }
244
245 6 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 6 times.
✗ Branch 2 → 11 not taken.
6 ensureNoConstAssign(node, lhs.type);
248
249 // Remove reference wrappers
250
1/2
✓ Branch 3 → 4 taken 6 times.
✗ Branch 3 → 11 not taken.
6 const QualType lhsType = lhs.type.removeReferenceWrapper();
251
1/2
✓ Branch 4 → 5 taken 6 times.
✗ Branch 4 → 11 not taken.
6 const QualType rhsType = rhs.type.removeReferenceWrapper();
252
253
1/2
✓ Branch 7 → 8 taken 6 times.
✗ Branch 7 → 11 not taken.
12 return validateBinaryOperation(node, REM_EQUAL_OP_RULES, std::size(REM_EQUAL_OP_RULES), "%=", lhsType, rhsType);
254 }
255
256 2 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 2 times.
✗ Branch 2 → 11 not taken.
2 ensureNoConstAssign(node, lhs.type);
259
260 // Remove reference wrappers
261
1/2
✓ Branch 3 → 4 taken 2 times.
✗ Branch 3 → 11 not taken.
2 const QualType lhsType = lhs.type.removeReferenceWrapper();
262
1/2
✓ Branch 4 → 5 taken 2 times.
✗ Branch 4 → 11 not taken.
2 const QualType rhsType = rhs.type.removeReferenceWrapper();
263
264
1/2
✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 11 not taken.
4 return validateBinaryOperation(node, SHL_EQUAL_OP_RULES, std::size(SHL_EQUAL_OP_RULES), "<<=", lhsType, rhsType);
265 }
266
267 3 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 3 times.
✗ Branch 2 → 11 not taken.
3 ensureNoConstAssign(node, lhs.type);
270
271 // Remove reference wrappers
272
1/2
✓ Branch 3 → 4 taken 3 times.
✗ Branch 3 → 11 not taken.
3 const QualType lhsType = lhs.type.removeReferenceWrapper();
273
1/2
✓ Branch 4 → 5 taken 3 times.
✗ Branch 4 → 11 not taken.
3 const QualType rhsType = rhs.type.removeReferenceWrapper();
274
275
1/2
✓ Branch 7 → 8 taken 3 times.
✗ Branch 7 → 11 not taken.
6 return validateBinaryOperation(node, SHR_EQUAL_OP_RULES, std::size(SHR_EQUAL_OP_RULES), ">>=", lhsType, rhsType);
276 }
277
278 1 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 1 time.
✗ Branch 2 → 11 not taken.
1 ensureNoConstAssign(node, lhs.type);
281
282 // Remove reference wrappers
283
1/2
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 11 not taken.
1 const QualType lhsType = lhs.type.removeReferenceWrapper();
284
1/2
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 11 not taken.
1 const QualType rhsType = rhs.type.removeReferenceWrapper();
285
286
1/2
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 11 not taken.
2 return validateBinaryOperation(node, AND_EQUAL_OP_RULES, std::size(AND_EQUAL_OP_RULES), "&=", lhsType, rhsType);
287 }
288
289 1 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 1 time.
✗ Branch 2 → 11 not taken.
1 ensureNoConstAssign(node, lhs.type);
292
293 // Remove reference wrappers
294
1/2
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 11 not taken.
1 const QualType lhsType = lhs.type.removeReferenceWrapper();
295
1/2
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 11 not taken.
1 const QualType rhsType = rhs.type.removeReferenceWrapper();
296
297
1/2
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 11 not taken.
2 return validateBinaryOperation(node, OR_EQUAL_OP_RULES, std::size(OR_EQUAL_OP_RULES), "|=", lhsType, rhsType);
298 }
299
300 337 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 337 times.
✗ Branch 2 → 11 not taken.
337 ensureNoConstAssign(node, lhs.type);
303
304 // Remove reference wrappers
305
1/2
✓ Branch 3 → 4 taken 337 times.
✗ Branch 3 → 11 not taken.
337 const QualType lhsType = lhs.type.removeReferenceWrapper();
306
1/2
✓ Branch 4 → 5 taken 337 times.
✗ Branch 4 → 11 not taken.
337 const QualType rhsType = rhs.type.removeReferenceWrapper();
307
308
1/2
✓ Branch 7 → 8 taken 337 times.
✗ Branch 7 → 11 not taken.
674 return validateBinaryOperation(node, XOR_EQUAL_OP_RULES, std::size(XOR_EQUAL_OP_RULES), "^=", lhsType, rhsType);
309 }
310
311 1202 QualType OpRuleManager::getLogicalOrResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
312 // Remove reference wrappers
313
1/2
✓ Branch 2 → 3 taken 1202 times.
✗ Branch 2 → 10 not taken.
1202 const QualType lhsType = lhs.type.removeReferenceWrapper();
314
1/2
✓ Branch 3 → 4 taken 1202 times.
✗ Branch 3 → 10 not taken.
1202 const QualType rhsType = rhs.type.removeReferenceWrapper();
315
316
2/2
✓ Branch 6 → 7 taken 1201 times.
✓ Branch 6 → 10 taken 1 time.
2403 return validateBinaryOperation(node, LOGICAL_OR_OP_RULES, std::size(LOGICAL_OR_OP_RULES), "||", lhsType, rhsType);
317 }
318
319 218 QualType OpRuleManager::getLogicalAndResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
320 // Remove reference wrappers
321
1/2
✓ Branch 2 → 3 taken 218 times.
✗ Branch 2 → 10 not taken.
218 const QualType lhsType = lhs.type.removeReferenceWrapper();
322
1/2
✓ Branch 3 → 4 taken 218 times.
✗ Branch 3 → 10 not taken.
218 const QualType rhsType = rhs.type.removeReferenceWrapper();
323
324
1/2
✓ Branch 6 → 7 taken 218 times.
✗ Branch 6 → 10 not taken.
436 return validateBinaryOperation(node, LOGICAL_AND_OP_RULES, std::size(LOGICAL_AND_OP_RULES), "&&", lhsType, rhsType);
325 }
326
327 92 QualType OpRuleManager::getBitwiseOrResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
328 // Remove reference wrappers
329
1/2
✓ Branch 2 → 3 taken 92 times.
✗ Branch 2 → 10 not taken.
92 const QualType lhsType = lhs.type.removeReferenceWrapper();
330
1/2
✓ Branch 3 → 4 taken 92 times.
✗ Branch 3 → 10 not taken.
92 const QualType rhsType = rhs.type.removeReferenceWrapper();
331
332
2/2
✓ Branch 6 → 7 taken 91 times.
✓ Branch 6 → 10 taken 1 time.
183 return validateBinaryOperation(node, BITWISE_OR_OP_RULES, std::size(BITWISE_OR_OP_RULES), "|", lhsType, rhsType);
333 }
334
335 14 QualType OpRuleManager::getBitwiseXorResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
336 // Remove reference wrappers
337
1/2
✓ Branch 2 → 3 taken 14 times.
✗ Branch 2 → 10 not taken.
14 const QualType lhsType = lhs.type.removeReferenceWrapper();
338
1/2
✓ Branch 3 → 4 taken 14 times.
✗ Branch 3 → 10 not taken.
14 const QualType rhsType = rhs.type.removeReferenceWrapper();
339
340
1/2
✓ Branch 6 → 7 taken 14 times.
✗ Branch 6 → 10 not taken.
28 return validateBinaryOperation(node, BITWISE_XOR_OP_RULES, std::size(BITWISE_XOR_OP_RULES), "^", lhsType, rhsType);
341 }
342
343 46 QualType OpRuleManager::getBitwiseAndResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
344 // Remove reference wrappers
345
1/2
✓ Branch 2 → 3 taken 46 times.
✗ Branch 2 → 10 not taken.
46 const QualType lhsType = lhs.type.removeReferenceWrapper();
346
1/2
✓ Branch 3 → 4 taken 46 times.
✗ Branch 3 → 10 not taken.
46 const QualType rhsType = rhs.type.removeReferenceWrapper();
347
348
1/2
✓ Branch 6 → 7 taken 46 times.
✗ Branch 6 → 10 not taken.
92 return validateBinaryOperation(node, BITWISE_AND_OP_RULES, std::size(BITWISE_AND_OP_RULES), "&", lhsType, rhsType);
349 }
350
351 3802 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 3802 times.
✗ Branch 2 → 45 not taken.
3802 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_EQUAL, {lhs, rhs}, opIdx);
354
3/4
✓ Branch 3 → 4 taken 3802 times.
✗ Branch 3 → 46 not taken.
✓ Branch 4 → 5 taken 432 times.
✓ Branch 4 → 6 taken 3370 times.
3802 if (!resultType.type.is(TY_INVALID))
355 432 return resultType;
356
357 // Remove reference wrappers
358
1/2
✓ Branch 6 → 7 taken 3370 times.
✗ Branch 6 → 46 not taken.
3370 const QualType lhsType = lhs.type.removeReferenceWrapper();
359
1/2
✓ Branch 7 → 8 taken 3370 times.
✗ Branch 7 → 46 not taken.
3370 const QualType rhsType = rhs.type.removeReferenceWrapper();
360
361 // Allow 'pointer == pointer' straight away
362
7/10
✓ Branch 8 → 9 taken 3370 times.
✗ Branch 8 → 46 not taken.
✓ Branch 9 → 10 taken 949 times.
✓ Branch 9 → 13 taken 2421 times.
✓ Branch 10 → 11 taken 949 times.
✗ Branch 10 → 46 not taken.
✓ Branch 11 → 12 taken 949 times.
✗ Branch 11 → 13 not taken.
✓ Branch 14 → 15 taken 949 times.
✓ Branch 14 → 17 taken 2421 times.
3370 if (lhsType.isPtr() && rhsType.isPtr())
363
1/2
✓ Branch 15 → 16 taken 949 times.
✗ Branch 15 → 46 not taken.
949 return ExprResult(QualType(TY_BOOL));
364
365 // Allow 'pointer == int' straight away
366
3/10
✓ Branch 17 → 18 taken 2421 times.
✗ Branch 17 → 46 not taken.
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 22 taken 2421 times.
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 46 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 22 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 26 taken 2421 times.
2421 if (lhsType.isPtr() && rhsType.is(TY_INT))
367 return ExprResult(QualType(TY_BOOL));
368
369 // Allow 'string == char*' and vice versa straight away
370
8/18
✓ Branch 26 → 27 taken 2421 times.
✗ Branch 26 → 46 not taken.
✓ Branch 27 → 28 taken 152 times.
✓ Branch 27 → 30 taken 2269 times.
✓ Branch 28 → 29 taken 152 times.
✗ Branch 28 → 46 not taken.
✓ Branch 29 → 30 taken 152 times.
✗ Branch 29 → 34 not taken.
✓ Branch 30 → 31 taken 2421 times.
✗ Branch 30 → 46 not taken.
✗ Branch 31 → 32 not taken.
✓ Branch 31 → 35 taken 2421 times.
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 46 not taken.
✗ Branch 33 → 34 not taken.
✗ Branch 33 → 35 not taken.
✗ Branch 36 → 37 not taken.
✓ Branch 36 → 39 taken 2421 times.
2421 if ((lhsType.is(TY_STRING) && rhsType.isPtrTo(TY_CHAR)) || (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING)))
371 return ExprResult(QualType(TY_BOOL));
372
373 // Check primitive type combinations
374
2/2
✓ Branch 41 → 42 taken 2420 times.
✓ Branch 41 → 46 taken 1 time.
2421 return ExprResult(validateBinaryOperation(node, EQUAL_OP_RULES, std::size(EQUAL_OP_RULES), "==", lhsType, rhsType));
375 }
376
377 1557 ExprResult OpRuleManager::getNotEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) {
378 // Check is there is an overloaded operator function available
379
1/2
✓ Branch 2 → 3 taken 1557 times.
✗ Branch 2 → 45 not taken.
1557 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_NOT_EQUAL, {lhs, rhs}, opIdx);
380
3/4
✓ Branch 3 → 4 taken 1557 times.
✗ Branch 3 → 46 not taken.
✓ Branch 4 → 5 taken 11 times.
✓ Branch 4 → 6 taken 1546 times.
1557 if (!resultType.type.is(TY_INVALID))
381 11 return resultType;
382
383 // Remove reference wrappers
384
1/2
✓ Branch 6 → 7 taken 1546 times.
✗ Branch 6 → 46 not taken.
1546 const QualType lhsType = lhs.type.removeReferenceWrapper();
385
1/2
✓ Branch 7 → 8 taken 1546 times.
✗ Branch 7 → 46 not taken.
1546 const QualType rhsType = rhs.type.removeReferenceWrapper();
386
387 // Allow 'pointer != pointer' straight away
388
8/10
✓ Branch 8 → 9 taken 1546 times.
✗ Branch 8 → 46 not taken.
✓ Branch 9 → 10 taken 229 times.
✓ Branch 9 → 13 taken 1317 times.
✓ Branch 10 → 11 taken 229 times.
✗ Branch 10 → 46 not taken.
✓ Branch 11 → 12 taken 222 times.
✓ Branch 11 → 13 taken 7 times.
✓ Branch 14 → 15 taken 222 times.
✓ Branch 14 → 17 taken 1324 times.
1546 if (lhsType.isPtr() && rhsType.isPtr())
389
1/2
✓ Branch 15 → 16 taken 222 times.
✗ Branch 15 → 46 not taken.
222 return ExprResult(QualType(TY_BOOL));
390
391 // Allow 'pointer != int' straight away
392
6/10
✓ Branch 17 → 18 taken 1324 times.
✗ Branch 17 → 46 not taken.
✓ Branch 18 → 19 taken 7 times.
✓ Branch 18 → 22 taken 1317 times.
✓ Branch 19 → 20 taken 7 times.
✗ Branch 19 → 46 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 7 times.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 26 taken 1324 times.
1324 if (lhsType.isPtr() && rhsType.is(TY_INT))
393 return ExprResult(QualType(TY_BOOL));
394
395 // Allow 'string != char*' and vice versa straight away
396
12/18
✓ Branch 26 → 27 taken 1324 times.
✗ Branch 26 → 46 not taken.
✓ Branch 27 → 28 taken 9 times.
✓ Branch 27 → 30 taken 1315 times.
✓ Branch 28 → 29 taken 9 times.
✗ Branch 28 → 46 not taken.
✓ Branch 29 → 30 taken 9 times.
✗ Branch 29 → 34 not taken.
✓ Branch 30 → 31 taken 1324 times.
✗ Branch 30 → 46 not taken.
✓ Branch 31 → 32 taken 7 times.
✓ Branch 31 → 35 taken 1317 times.
✓ Branch 32 → 33 taken 7 times.
✗ Branch 32 → 46 not taken.
✓ Branch 33 → 34 taken 7 times.
✗ Branch 33 → 35 not taken.
✓ Branch 36 → 37 taken 7 times.
✓ Branch 36 → 39 taken 1317 times.
1324 if ((lhsType.is(TY_STRING) && rhsType.isPtrTo(TY_CHAR)) || (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING)))
397
1/2
✓ Branch 37 → 38 taken 7 times.
✗ Branch 37 → 46 not taken.
7 return ExprResult(QualType(TY_BOOL));
398
399 // Check primitive type combinations
400
1/2
✓ Branch 41 → 42 taken 1317 times.
✗ Branch 41 → 46 not taken.
1317 return ExprResult(validateBinaryOperation(node, NOT_EQUAL_OP_RULES, std::size(NOT_EQUAL_OP_RULES), "!=", lhsType, rhsType));
401 }
402
403 1905 QualType OpRuleManager::getLessResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
404 // Remove reference wrappers
405
1/2
✓ Branch 2 → 3 taken 1905 times.
✗ Branch 2 → 10 not taken.
1905 const QualType lhsType = lhs.type.removeReferenceWrapper();
406
1/2
✓ Branch 3 → 4 taken 1905 times.
✗ Branch 3 → 10 not taken.
1905 const QualType rhsType = rhs.type.removeReferenceWrapper();
407
408
1/2
✓ Branch 6 → 7 taken 1905 times.
✗ Branch 6 → 10 not taken.
3810 return validateBinaryOperation(node, LESS_OP_RULES, std::size(LESS_OP_RULES), "<", lhsType, rhsType);
409 }
410
411 530 QualType OpRuleManager::getGreaterResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
412 // Remove reference wrappers
413
1/2
✓ Branch 2 → 3 taken 530 times.
✗ Branch 2 → 10 not taken.
530 const QualType lhsType = lhs.type.removeReferenceWrapper();
414
1/2
✓ Branch 3 → 4 taken 530 times.
✗ Branch 3 → 10 not taken.
530 const QualType rhsType = rhs.type.removeReferenceWrapper();
415
416
2/2
✓ Branch 6 → 7 taken 529 times.
✓ Branch 6 → 10 taken 1 time.
1059 return validateBinaryOperation(node, GREATER_OP_RULES, std::size(GREATER_OP_RULES), ">", lhsType, rhsType);
417 }
418
419 389 QualType OpRuleManager::getLessEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
420 // Remove reference wrappers
421
1/2
✓ Branch 2 → 3 taken 389 times.
✗ Branch 2 → 10 not taken.
389 const QualType lhsType = lhs.type.removeReferenceWrapper();
422
1/2
✓ Branch 3 → 4 taken 389 times.
✗ Branch 3 → 10 not taken.
389 const QualType rhsType = rhs.type.removeReferenceWrapper();
423
424
1/2
✓ Branch 6 → 7 taken 389 times.
✗ Branch 6 → 10 not taken.
778 return validateBinaryOperation(node, LESS_EQUAL_OP_RULES, std::size(LESS_EQUAL_OP_RULES), "<=", lhsType, rhsType);
425 }
426
427 1007 QualType OpRuleManager::getGreaterEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
428 // Remove reference wrappers
429
1/2
✓ Branch 2 → 3 taken 1007 times.
✗ Branch 2 → 10 not taken.
1007 const QualType lhsType = lhs.type.removeReferenceWrapper();
430
1/2
✓ Branch 3 → 4 taken 1007 times.
✗ Branch 3 → 10 not taken.
1007 const QualType rhsType = rhs.type.removeReferenceWrapper();
431
432
1/2
✓ Branch 6 → 7 taken 1007 times.
✗ Branch 6 → 10 not taken.
2014 return validateBinaryOperation(node, GREATER_EQUAL_OP_RULES, std::size(GREATER_EQUAL_OP_RULES), ">=", lhsType, rhsType);
433 }
434
435 97 ExprResult OpRuleManager::getShiftLeftResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) {
436 // Check is there is an overloaded operator function available
437
1/2
✓ Branch 2 → 3 taken 97 times.
✗ Branch 2 → 14 not taken.
97 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_SHL, {lhs, rhs}, opIdx);
438
3/4
✓ Branch 3 → 4 taken 97 times.
✗ Branch 3 → 15 not taken.
✓ Branch 4 → 5 taken 85 times.
✓ Branch 4 → 6 taken 12 times.
97 if (!resultType.type.is(TY_INVALID))
439 85 return resultType;
440
441 // Remove reference wrappers
442
1/2
✓ Branch 6 → 7 taken 12 times.
✗ Branch 6 → 15 not taken.
12 const QualType lhsType = lhs.type.removeReferenceWrapper();
443
1/2
✓ Branch 7 → 8 taken 12 times.
✗ Branch 7 → 15 not taken.
12 const QualType rhsType = rhs.type.removeReferenceWrapper();
444
445
1/2
✓ Branch 10 → 11 taken 12 times.
✗ Branch 10 → 15 not taken.
12 return {validateBinaryOperation(node, SHIFT_LEFT_OP_RULES, std::size(SHIFT_LEFT_OP_RULES), "<<", lhsType, rhsType)};
446 }
447
448 56 ExprResult OpRuleManager::getShiftRightResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) {
449 // Check is there is an overloaded operator function available
450
1/2
✓ Branch 2 → 3 taken 56 times.
✗ Branch 2 → 14 not taken.
56 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_SHR, {lhs, rhs}, opIdx);
451
3/4
✓ Branch 3 → 4 taken 56 times.
✗ Branch 3 → 15 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 55 times.
56 if (!resultType.type.is(TY_INVALID))
452 1 return resultType;
453
454 // Remove reference wrappers
455
1/2
✓ Branch 6 → 7 taken 55 times.
✗ Branch 6 → 15 not taken.
55 const QualType lhsType = lhs.type.removeReferenceWrapper();
456
1/2
✓ Branch 7 → 8 taken 55 times.
✗ Branch 7 → 15 not taken.
55 const QualType rhsType = rhs.type.removeReferenceWrapper();
457
458
1/2
✓ Branch 10 → 11 taken 55 times.
✗ Branch 10 → 15 not taken.
55 return {validateBinaryOperation(node, SHIFT_RIGHT_OP_RULES, std::size(SHIFT_RIGHT_OP_RULES), ">>", lhsType, rhsType)};
459 }
460
461 2996 ExprResult OpRuleManager::getPlusResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) {
462 // Check is there is an overloaded operator function available
463
1/2
✓ Branch 2 → 3 taken 2996 times.
✗ Branch 2 → 32 not taken.
2996 const ExprResult result = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_PLUS, {lhs, rhs}, opIdx);
464
3/4
✓ Branch 3 → 4 taken 2996 times.
✗ Branch 3 → 35 not taken.
✓ Branch 4 → 5 taken 70 times.
✓ Branch 4 → 6 taken 2926 times.
2996 if (!result.type.is(TY_INVALID))
465 70 return result;
466
467 // Remove reference wrappers
468
1/2
✓ Branch 6 → 7 taken 2926 times.
✗ Branch 6 → 35 not taken.
2926 const QualType lhsType = lhs.type.removeReferenceWrapper();
469
1/2
✓ Branch 7 → 8 taken 2926 times.
✗ Branch 7 → 35 not taken.
2926 const QualType rhsType = rhs.type.removeReferenceWrapper();
470
471 // Allow any* + <int/long/short>
472
7/10
✓ Branch 8 → 9 taken 2926 times.
✗ Branch 8 → 33 not taken.
✓ Branch 9 → 10 taken 546 times.
✓ Branch 9 → 13 taken 2380 times.
✓ Branch 10 → 11 taken 546 times.
✗ Branch 10 → 33 not taken.
✓ Branch 11 → 12 taken 546 times.
✗ Branch 11 → 13 not taken.
✓ Branch 14 → 15 taken 546 times.
✓ Branch 14 → 17 taken 2380 times.
2926 if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) {
473
1/2
✓ Branch 15 → 16 taken 546 times.
✗ Branch 15 → 35 not taken.
546 ensureUnsafeAllowed(node, "+", lhsType, rhsType);
474 546 return {lhsType};
475 }
476 // Allow <int/long/short> + any*
477
6/10
✓ Branch 17 → 18 taken 2380 times.
✗ Branch 17 → 34 not taken.
✓ Branch 18 → 19 taken 2273 times.
✓ Branch 18 → 22 taken 107 times.
✓ Branch 19 → 20 taken 2273 times.
✗ Branch 19 → 34 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 2273 times.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 26 taken 2380 times.
2380 if (lhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT}) && rhsType.isPtr()) {
478 ensureUnsafeAllowed(node, "+", lhsType, rhsType);
479 return {rhsType};
480 }
481
482
2/2
✓ Branch 28 → 29 taken 2379 times.
✓ Branch 28 → 35 taken 1 time.
2380 return {validateBinaryOperation(node, PLUS_OP_RULES, std::size(PLUS_OP_RULES), "+", lhsType, rhsType)};
483 }
484
485 1893 ExprResult OpRuleManager::getMinusResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) {
486 // Check is there is an overloaded operator function available
487
1/2
✓ Branch 2 → 3 taken 1893 times.
✗ Branch 2 → 32 not taken.
1893 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MINUS, {lhs, rhs}, opIdx);
488
3/4
✓ Branch 3 → 4 taken 1893 times.
✗ Branch 3 → 35 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 1892 times.
1893 if (!resultType.type.is(TY_INVALID))
489 1 return resultType;
490
491 // Remove reference wrappers
492
1/2
✓ Branch 6 → 7 taken 1892 times.
✗ Branch 6 → 35 not taken.
1892 const QualType lhsType = lhs.type.removeReferenceWrapper();
493
1/2
✓ Branch 7 → 8 taken 1892 times.
✗ Branch 7 → 35 not taken.
1892 const QualType rhsType = rhs.type.removeReferenceWrapper();
494
495 // Allow any* - <int/long/short>
496
3/10
✓ Branch 8 → 9 taken 1892 times.
✗ Branch 8 → 33 not taken.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 13 taken 1892 times.
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 33 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 13 not taken.
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 17 taken 1892 times.
1892 if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) {
497 ensureUnsafeAllowed(node, "-", lhsType, rhsType);
498 return {lhs};
499 }
500 // Allow <int/long/short> - any*
501
6/10
✓ Branch 17 → 18 taken 1892 times.
✗ Branch 17 → 34 not taken.
✓ Branch 18 → 19 taken 1884 times.
✓ Branch 18 → 22 taken 8 times.
✓ Branch 19 → 20 taken 1884 times.
✗ Branch 19 → 34 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 1884 times.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 26 taken 1892 times.
1892 if (lhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT}) && rhsType.isPtr()) {
502 ensureUnsafeAllowed(node, "-", lhsType, rhsType);
503 return {rhs};
504 }
505
506
1/2
✓ Branch 28 → 29 taken 1892 times.
✗ Branch 28 → 35 not taken.
1892 return {validateBinaryOperation(node, MINUS_OP_RULES, std::size(MINUS_OP_RULES), "-", lhsType, rhsType)};
507 }
508
509 777 ExprResult OpRuleManager::getMulResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) {
510 // Check is there is an overloaded operator function available
511
1/2
✓ Branch 2 → 3 taken 777 times.
✗ Branch 2 → 14 not taken.
777 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MUL, {lhs, rhs}, opIdx);
512
3/4
✓ Branch 3 → 4 taken 777 times.
✗ Branch 3 → 15 not taken.
✓ Branch 4 → 5 taken 9 times.
✓ Branch 4 → 6 taken 768 times.
777 if (!resultType.type.is(TY_INVALID))
513 9 return resultType;
514
515 // Remove reference wrappers
516
1/2
✓ Branch 6 → 7 taken 768 times.
✗ Branch 6 → 15 not taken.
768 const QualType lhsType = lhs.type.removeReferenceWrapper();
517
1/2
✓ Branch 7 → 8 taken 768 times.
✗ Branch 7 → 15 not taken.
768 const QualType rhsType = rhs.type.removeReferenceWrapper();
518
519
2/2
✓ Branch 10 → 11 taken 767 times.
✓ Branch 10 → 15 taken 1 time.
768 return {validateBinaryOperation(node, MUL_OP_RULES, std::size(MUL_OP_RULES), "*", lhsType, rhsType)};
520 }
521
522 142 ExprResult OpRuleManager::getDivResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) {
523 // Check is there is an overloaded operator function available
524
1/2
✓ Branch 2 → 3 taken 142 times.
✗ Branch 2 → 14 not taken.
142 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_DIV, {lhs, rhs}, opIdx);
525
3/4
✓ Branch 3 → 4 taken 142 times.
✗ Branch 3 → 15 not taken.
✓ Branch 4 → 5 taken 3 times.
✓ Branch 4 → 6 taken 139 times.
142 if (!resultType.type.is(TY_INVALID))
526 3 return resultType;
527
528 // Remove reference wrappers
529
1/2
✓ Branch 6 → 7 taken 139 times.
✗ Branch 6 → 15 not taken.
139 const QualType lhsType = lhs.type.removeReferenceWrapper();
530
1/2
✓ Branch 7 → 8 taken 139 times.
✗ Branch 7 → 15 not taken.
139 const QualType rhsType = rhs.type.removeReferenceWrapper();
531
532
1/2
✓ Branch 10 → 11 taken 139 times.
✗ Branch 10 → 15 not taken.
139 return {validateBinaryOperation(node, DIV_OP_RULES, std::size(DIV_OP_RULES), "/", lhsType, rhsType)};
533 }
534
535 12 ExprResult OpRuleManager::getRemResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
536 // Remove reference wrappers
537
1/2
✓ Branch 2 → 3 taken 12 times.
✗ Branch 2 → 10 not taken.
12 const QualType lhsType = lhs.type.removeReferenceWrapper();
538
1/2
✓ Branch 3 → 4 taken 12 times.
✗ Branch 3 → 10 not taken.
12 const QualType rhsType = rhs.type.removeReferenceWrapper();
539
540
1/2
✓ Branch 6 → 7 taken 12 times.
✗ Branch 6 → 10 not taken.
24 return {validateBinaryOperation(node, REM_OP_RULES, std::size(REM_OP_RULES), "%", lhsType, rhsType)};
541 }
542
543 16 QualType OpRuleManager::getPrefixMinusResultType(const ASTNode *node, const ExprResult &lhs) {
544 // Remove reference wrappers
545
1/2
✓ Branch 2 → 3 taken 16 times.
✗ Branch 2 → 9 not taken.
16 const QualType lhsType = lhs.type.removeReferenceWrapper();
546
547
1/2
✓ Branch 5 → 6 taken 16 times.
✗ Branch 5 → 9 not taken.
32 return validateUnaryOperation(node, PREFIX_MINUS_OP_RULES, std::size(PREFIX_MINUS_OP_RULES), "-", lhsType);
548 }
549
550 23 QualType OpRuleManager::getPrefixPlusPlusResultType(const ASTNode *node, const ExprResult &lhs) const {
551 // Check if we try to assign a constant value
552
1/2
✓ Branch 2 → 3 taken 23 times.
✗ Branch 2 → 14 not taken.
23 ensureNoConstAssign(node, lhs.type);
553
554 // Remove reference wrappers
555
1/2
✓ Branch 3 → 4 taken 23 times.
✗ Branch 3 → 14 not taken.
23 const QualType lhsType = lhs.type.removeReferenceWrapper();
556
557 // Check if this is an unsafe operation
558
2/4
✓ Branch 4 → 5 taken 23 times.
✗ Branch 4 → 14 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 23 times.
23 if (lhsType.isPtr()) {
559 ensureUnsafeAllowed(node, "++", lhsType);
560 return lhsType;
561 }
562
563
1/2
✓ Branch 10 → 11 taken 23 times.
✗ Branch 10 → 14 not taken.
23 return validateUnaryOperation(node, PREFIX_PLUS_PLUS_OP_RULES, std::size(PREFIX_PLUS_PLUS_OP_RULES), "++", lhsType);
564 }
565
566 8 QualType OpRuleManager::getPrefixMinusMinusResultType(const ASTNode *node, const ExprResult &lhs) const {
567 // Check if we try to assign a constant value
568
1/2
✓ Branch 2 → 3 taken 8 times.
✗ Branch 2 → 14 not taken.
8 ensureNoConstAssign(node, lhs.type);
569
570 // Remove reference wrappers
571
1/2
✓ Branch 3 → 4 taken 8 times.
✗ Branch 3 → 14 not taken.
8 const QualType lhsType = lhs.type.removeReferenceWrapper();
572
573 // Check if this is an unsafe operation
574
2/4
✓ Branch 4 → 5 taken 8 times.
✗ Branch 4 → 14 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 8 times.
8 if (lhsType.isPtr()) {
575 ensureUnsafeAllowed(node, "--", lhsType);
576 return lhsType;
577 }
578
579
2/2
✓ Branch 10 → 11 taken 7 times.
✓ Branch 10 → 14 taken 1 time.
8 return validateUnaryOperation(node, PREFIX_MINUS_MINUS_OP_RULES, std::size(PREFIX_MINUS_MINUS_OP_RULES), "--", lhsType);
580 }
581
582 763 QualType OpRuleManager::getPrefixNotResultType(const ASTNode *node, const ExprResult &lhs) {
583 // Remove reference wrappers
584
1/2
✓ Branch 2 → 3 taken 763 times.
✗ Branch 2 → 9 not taken.
763 const QualType lhsType = lhs.type.removeReferenceWrapper();
585
586
1/2
✓ Branch 5 → 6 taken 763 times.
✗ Branch 5 → 9 not taken.
1526 return validateUnaryOperation(node, PREFIX_NOT_OP_RULES, std::size(PREFIX_NOT_OP_RULES), "!", lhsType);
587 }
588
589 1 QualType OpRuleManager::getPrefixBitwiseNotResultType(const ASTNode *node, const ExprResult &lhs) {
590 // Remove reference wrappers
591
1/2
✓ Branch 2 → 3 taken 1 time.
✗ Branch 2 → 9 not taken.
1 const QualType lhsType = lhs.type.removeReferenceWrapper();
592
593
1/2
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 9 not taken.
2 return validateUnaryOperation(node, PREFIX_BITWISE_NOT_OP_RULES, std::size(PREFIX_BITWISE_NOT_OP_RULES), "~", lhsType);
594 }
595
596 223 QualType OpRuleManager::getPrefixMulResultType(const ASTNode *node, const ExprResult &lhs) {
597 // Remove reference wrappers
598
1/2
✓ Branch 2 → 3 taken 223 times.
✗ Branch 2 → 25 not taken.
223 const QualType lhsType = lhs.type.removeReferenceWrapper();
599
600
2/4
✓ Branch 3 → 4 taken 223 times.
✗ Branch 3 → 25 not taken.
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 12 taken 223 times.
223 if (!lhsType.isPtr())
601 throw SemanticError(node, OPERATOR_WRONG_DATA_TYPE, "Cannot apply de-referencing operator on type " + lhsType.getName(true));
602
1/2
✓ Branch 12 → 13 taken 223 times.
✗ Branch 12 → 25 not taken.
446 return lhsType.getContained();
603 }
604
605 94 QualType OpRuleManager::getPrefixBitwiseAndResultType(const ASTNode *node, const ExprResult &lhs) {
606 // Remove reference wrappers
607
1/2
✓ Branch 2 → 3 taken 94 times.
✗ Branch 2 → 7 not taken.
94 const QualType lhsType = lhs.type.removeReferenceWrapper();
608
609
1/2
✓ Branch 3 → 4 taken 94 times.
✗ Branch 3 → 7 not taken.
188 return lhsType.toPtr(node);
610 }
611
612 1837 ExprResult OpRuleManager::getPostfixPlusPlusResultType(ASTNode *node, const ExprResult &lhs, size_t opIdx) {
613 // Check is there is an overloaded operator function available
614
1/2
✓ Branch 2 → 3 taken 1837 times.
✗ Branch 2 → 18 not taken.
1837 const ExprResult resultType = isOperatorOverloadingFctAvailable<1>(node, OP_FCT_POSTFIX_PLUS_PLUS, {lhs}, opIdx);
615
3/4
✓ Branch 3 → 4 taken 1837 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 9 times.
✓ Branch 4 → 6 taken 1828 times.
1837 if (!resultType.type.is(TY_INVALID))
616 9 return resultType;
617
618 // Check if we try to assign a constant value
619
1/2
✓ Branch 6 → 7 taken 1828 times.
✗ Branch 6 → 19 not taken.
1828 ensureNoConstAssign(node, lhs.type);
620
621 // Remove reference wrappers
622
1/2
✓ Branch 7 → 8 taken 1828 times.
✗ Branch 7 → 19 not taken.
1828 const QualType lhsType = lhs.type.removeReferenceWrapper();
623
624 // Check if this is an unsafe operation
625
3/4
✓ Branch 8 → 9 taken 1828 times.
✗ Branch 8 → 19 not taken.
✓ Branch 9 → 10 taken 8 times.
✓ Branch 9 → 12 taken 1820 times.
1828 if (lhsType.isPtr()) {
626
1/2
✓ Branch 10 → 11 taken 8 times.
✗ Branch 10 → 19 not taken.
8 ensureUnsafeAllowed(node, "++", lhsType);
627 8 return {lhs};
628 }
629
630
2/2
✓ Branch 14 → 15 taken 1819 times.
✓ Branch 14 → 19 taken 1 time.
1820 return {validateUnaryOperation(node, POSTFIX_PLUS_PLUS_OP_RULES, std::size(POSTFIX_PLUS_PLUS_OP_RULES), "++", lhsType)};
631 }
632
633 419 ExprResult OpRuleManager::getPostfixMinusMinusResultType(ASTNode *node, const ExprResult &lhs, size_t opIdx) {
634 // Check is there is an overloaded operator function available
635
1/2
✓ Branch 2 → 3 taken 419 times.
✗ Branch 2 → 18 not taken.
419 const ExprResult resultType = isOperatorOverloadingFctAvailable<1>(node, OP_FCT_POSTFIX_MINUS_MINUS, {lhs}, opIdx);
636
3/4
✓ Branch 3 → 4 taken 419 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 7 times.
✓ Branch 4 → 6 taken 412 times.
419 if (!resultType.type.is(TY_INVALID))
637 7 return resultType;
638
639 // Check if we try to assign a constant value
640
1/2
✓ Branch 6 → 7 taken 412 times.
✗ Branch 6 → 19 not taken.
412 ensureNoConstAssign(node, lhs.type);
641
642 // Remove reference wrappers
643
1/2
✓ Branch 7 → 8 taken 412 times.
✗ Branch 7 → 19 not taken.
412 const QualType lhsType = lhs.type.removeReferenceWrapper();
644
645 // Check if this is an unsafe operation
646
3/4
✓ Branch 8 → 9 taken 412 times.
✗ Branch 8 → 19 not taken.
✓ Branch 9 → 10 taken 1 time.
✓ Branch 9 → 12 taken 411 times.
412 if (lhsType.isPtr()) {
647
1/2
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 19 not taken.
1 ensureUnsafeAllowed(node, "--", lhsType);
648 1 return {lhs};
649 }
650
651
1/2
✓ Branch 14 → 15 taken 411 times.
✗ Branch 14 → 19 not taken.
411 return {validateUnaryOperation(node, POSTFIX_MINUS_MINUS_OP_RULES, std::size(POSTFIX_MINUS_MINUS_OP_RULES), "--", lhsType)};
652 }
653
654 2543 QualType OpRuleManager::getCastResultType(const ASTNode *node, QualType lhsType, const ExprResult &rhs) const {
655 // Remove reference wrappers
656
1/2
✓ Branch 2 → 3 taken 2543 times.
✗ Branch 2 → 50 not taken.
2543 lhsType = lhsType.removeReferenceWrapper();
657
1/2
✓ Branch 3 → 4 taken 2543 times.
✗ Branch 3 → 57 not taken.
2543 QualType rhsType = rhs.type.removeReferenceWrapper();
658
659 // Only allow to cast the 'heap' qualifier away, if we are in unsafe mode
660
2/2
✓ Branch 6 → 7 taken 104 times.
✓ Branch 6 → 8 taken 2439 times.
2543 if (lhsType.getQualifiers().isHeap != rhsType.getQualifiers().isHeap)
661
1/2
✓ Branch 7 → 8 taken 104 times.
✗ Branch 7 → 57 not taken.
104 ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType);
662
663 // Allow identity casts
664
3/4
✓ Branch 8 → 9 taken 2543 times.
✗ Branch 8 → 57 not taken.
✓ Branch 9 → 10 taken 256 times.
✓ Branch 9 → 11 taken 2287 times.
2543 if (lhsType.matches(rhsType, false, true, true))
665 256 return lhsType;
666 // Allow casts string -> char* and string -> char[]
667
12/16
✓ Branch 11 → 12 taken 2287 times.
✗ Branch 11 → 51 not taken.
✓ Branch 12 → 13 taken 1158 times.
✓ Branch 12 → 19 taken 1129 times.
✓ Branch 13 → 14 taken 1158 times.
✗ Branch 13 → 51 not taken.
✓ Branch 14 → 15 taken 1158 times.
✗ Branch 14 → 51 not taken.
✓ Branch 15 → 16 taken 907 times.
✓ Branch 15 → 19 taken 251 times.
✓ Branch 16 → 17 taken 907 times.
✗ Branch 16 → 51 not taken.
✓ Branch 17 → 18 taken 903 times.
✓ Branch 17 → 19 taken 4 times.
✓ Branch 20 → 21 taken 903 times.
✓ Branch 20 → 22 taken 1384 times.
2287 if (lhsType.isOneOf({TY_PTR, TY_ARRAY}) && lhsType.getContained().is(TY_CHAR) && rhsType.is(TY_STRING))
668 903 return lhsType;
669 // Allow casts char* -> string and char[] -> string
670
10/16
✓ Branch 22 → 23 taken 1384 times.
✗ Branch 22 → 53 not taken.
✓ Branch 23 → 24 taken 91 times.
✓ Branch 23 → 30 taken 1293 times.
✓ Branch 24 → 25 taken 91 times.
✗ Branch 24 → 53 not taken.
✓ Branch 25 → 26 taken 91 times.
✗ Branch 25 → 30 not taken.
✓ Branch 26 → 27 taken 91 times.
✗ Branch 26 → 53 not taken.
✓ Branch 27 → 28 taken 91 times.
✗ Branch 27 → 53 not taken.
✓ Branch 28 → 29 taken 91 times.
✗ Branch 28 → 30 not taken.
✓ Branch 31 → 32 taken 91 times.
✓ Branch 31 → 33 taken 1293 times.
1384 if (lhsType.is(TY_STRING) && rhsType.isOneOf({TY_PTR, TY_ARRAY}) && rhsType.getContained().is(TY_CHAR))
671 91 return lhsType;
672 // Allow casts any* -> any*
673
7/10
✓ Branch 33 → 34 taken 1293 times.
✗ Branch 33 → 55 not taken.
✓ Branch 34 → 35 taken 255 times.
✓ Branch 34 → 38 taken 1038 times.
✓ Branch 35 → 36 taken 255 times.
✗ Branch 35 → 55 not taken.
✓ Branch 36 → 37 taken 255 times.
✗ Branch 36 → 38 not taken.
✓ Branch 39 → 40 taken 255 times.
✓ Branch 39 → 44 taken 1038 times.
1293 if (lhsType.isOneOf({TY_PTR, TY_STRING}) && rhsType.isOneOf({TY_PTR, TY_STRING})) {
674
2/4
✓ Branch 40 → 41 taken 255 times.
✗ Branch 40 → 57 not taken.
✓ Branch 41 → 42 taken 255 times.
✗ Branch 41 → 43 not taken.
255 if (lhsType != rhsType)
675
1/2
✓ Branch 42 → 43 taken 255 times.
✗ Branch 42 → 57 not taken.
255 ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType);
676 255 return lhsType;
677 }
678 // Check primitive type combinations
679
1/2
✓ Branch 46 → 47 taken 1038 times.
✗ Branch 46 → 57 not taken.
1038 return validateBinaryOperation(node, CAST_OP_RULES, std::size(CAST_OP_RULES), "(cast)", lhsType, rhsType, true);
680 }
681
682 template <size_t N>
683 17340 ExprResult OpRuleManager::isOperatorOverloadingFctAvailable(ASTNode *node, const char *const fctName,
684 const std::array<ExprResult, N> &op, size_t opIdx) {
685 static_assert(N == 1 || N == 2, "Only unary and binary operators are overloadable");
686 17340 Scope *calleeParentScope = nullptr;
687 17340 const Function *callee = nullptr;
688
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 2256 times.
✗ Branch 2 → 123 not taken.
✓ Branch 3 → 4 taken 2256 times.
✗ Branch 3 → 123 not taken.
✓ Branch 4 → 5 taken 2256 times.
✗ Branch 4 → 123 not taken.
✓ Branch 42 → 43 taken 2592 times.
✓ Branch 42 → 45 taken 16 times.
✓ Branch 48 → 6 taken 19955 times.
✓ Branch 48 → 49 taken 2240 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 15084 times.
✗ Branch 2 → 132 not taken.
✓ Branch 3 → 4 taken 15084 times.
✗ Branch 3 → 132 not taken.
✓ Branch 4 → 5 taken 15084 times.
✗ Branch 4 → 132 not taken.
✓ Branch 49 → 50 taken 52455 times.
✓ Branch 49 → 52 taken 873 times.
✓ Branch 55 → 6 taken 129809 times.
✓ Branch 55 → 56 taken 14211 times.
222151 for (const auto &sourceFile : typeChecker->resourceManager.sourceFiles | std::views::values) {
689 // Check if there is a registered operator function
690
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 19955 times.
✗ Branch 10 → 102 not taken.
✓ Branch 11 → 12 taken 19955 times.
✗ Branch 11 → 100 not taken.
✓ Branch 14 → 15 taken 17347 times.
✓ Branch 14 → 16 taken 2608 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 129809 times.
✗ Branch 10 → 109 not taken.
✓ Branch 11 → 12 taken 129809 times.
✗ Branch 11 → 107 not taken.
✓ Branch 14 → 15 taken 76481 times.
✓ Branch 14 → 16 taken 53328 times.
449292 if (!sourceFile->getNameRegistryEntry(fctName))
691 93828 continue;
692
693 // Match callees in the global scope of this source file
694 55936 calleeParentScope = sourceFile->globalScope.get();
695
2/4
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long):
✓ Branch 18 → 19 taken 2608 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 53328 times.
✗ Branch 18 → 131 not taken.
55936 const QualType thisType(TY_DYN);
696
2/4
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long):
✓ Branch 21 → 22 taken 2608 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 53328 times.
✗ Branch 21 → 113 not taken.
55936 ArgList args(N);
697
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 2608 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 53328 times.
✗ Branch 24 → 116 not taken.
55936 args[0] = {typeChecker->mapLocalTypeToImportedScopeType(calleeParentScope, op[0].type), op[0].isTemporary()};
698 if constexpr (N == 2)
699
1/2
✓ Branch 31 → 32 taken 53328 times.
✗ Branch 31 → 118 not taken.
53328 args[1] = {typeChecker->mapLocalTypeToImportedScopeType(calleeParentScope, op[1].type), op[1].isTemporary()};
700
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 2608 times.
✗ Branch 33 → 113 not taken.
✓ Branch 34 → 35 taken 2608 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 53328 times.
✗ Branch 40 → 122 not taken.
✓ Branch 41 → 42 taken 53328 times.
✗ Branch 41 → 120 not taken.
167808 callee = FunctionManager::match(calleeParentScope, fctName, thisType, args, {}, false, node);
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 38 → 39 taken 16 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 873 times.
✓ Branch 45 → 47 taken 52455 times.
55936 if (callee)
702 889 break;
703 }
704
705 // Return invalid type if the callee was not found
706
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 2240 times.
✓ Branch 49 → 52 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 56 → 57 taken 14211 times.
✓ Branch 56 → 59 taken 873 times.
17340 if (!callee)
707 16451 return ExprResult(QualType(TY_INVALID));
708
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 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 59 → 60 not taken.
✓ Branch 59 → 61 taken 873 times.
889 assert(calleeParentScope != nullptr);
709
710 // Save the pointer to the operator function in the AST node
711 889 std::vector<const Function *> &opFctPointers = typeChecker->getOpFctPointers(node);
712
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 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 63 → 64 taken 74 times.
✓ Branch 63 → 66 taken 799 times.
889 if (opFctPointers.size() <= opIdx)
713
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);
714 889 opFctPointers.at(opIdx) = callee;
715
716 // Check if we need to request a re-visit, because the function body was not type-checked yet
717 889 typeChecker->requestRevisitIfRequired(callee);
718
719 // Check if the called function has sufficient visibility
720
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 16 times.
✗ Branch 61 → 65 not taken.
✓ Branch 63 → 64 taken 14 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 873 times.
✗ Branch 68 → 72 not taken.
✓ Branch 70 → 71 taken 394 times.
✓ Branch 70 → 72 taken 479 times.
889 const bool isImported = calleeParentScope != nullptr && calleeParentScope->isImportedBy(typeChecker->rootScope);
721 889 const SymbolTableEntry *calleeEntry = callee->entry;
722
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 66 → 67 taken 14 times.
✓ Branch 66 → 71 taken 2 times.
✗ Branch 69 → 70 not taken.
✓ Branch 69 → 71 taken 14 times.
✗ Branch 72 → 73 not taken.
✓ 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 479 times.
✗ Branch 76 → 77 not taken.
✓ Branch 76 → 78 taken 394 times.
✗ Branch 79 → 80 not taken.
✓ Branch 79 → 89 taken 873 times.
889 if (isImported && !calleeEntry->getQualType().isPublic())
723 throw SemanticError(node, INSUFFICIENT_VISIBILITY,
724 "Overloaded operator '" + callee->getSignature() + "' has insufficient visibility");
725
726 // Procedures always have the return type 'bool'
727
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 730 times.
889 if (callee->isProcedure())
728 157 return ExprResult(QualType(TY_BOOL));
729 732 const QualType &returnType = callee->returnType;
730
731 // Add anonymous symbol to keep track of dtor call, if non-trivially destructible
732 732 SymbolTableEntry *anonymousSymbol = nullptr;
733
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 645 times.
✓ Branch 98 → 99 taken 79 times.
✓ Branch 98 → 100 taken 6 times.
✓ Branch 101 → 102 taken 79 times.
✓ Branch 101 → 104 taken 651 times.
732 if (returnType.is(TY_STRUCT) && !returnType.isTriviallyDestructible(node))
734 79 anonymousSymbol = typeChecker->currentScope->symbolTable.insertAnonymous(returnType, node, opIdx);
735
736 732 return {typeChecker->mapImportedScopeTypeToLocalType(calleeParentScope, returnType), anonymousSymbol};
737 }
738
739 3042 QualType OpRuleManager::validateUnaryOperation(const ASTNode *node, const UnaryOpRule opRules[], size_t opRulesSize,
740 const char *name, const QualType &lhs) {
741
2/2
✓ Branch 11 → 3 taken 7289 times.
✓ Branch 11 → 12 taken 2 times.
7291 for (size_t i = 0; i < opRulesSize; i++) {
742 7289 const UnaryOpRule &rule = opRules[i];
743
2/2
✓ Branch 5 → 6 taken 3040 times.
✓ Branch 5 → 10 taken 4249 times.
7289 if (std::get<0>(rule) == lhs.getSuperType())
744
1/2
✓ Branch 7 → 8 taken 3040 times.
✗ Branch 7 → 16 not taken.
3040 return QualType(std::get<1>(rule));
745 }
746
1/2
✓ Branch 13 → 14 taken 2 times.
✗ Branch 13 → 17 not taken.
2 throw getExceptionUnary(node, name, lhs);
747 }
748
749 35080 QualType OpRuleManager::validateBinaryOperation(const ASTNode *node, const BinaryOpRule opRules[], size_t opRulesSize,
750 const char *name, const QualType &lhs, const QualType &rhs,
751 bool preserveQualifiersFromLhs, const char *customMessagePrefix) {
752
2/2
✓ Branch 19 → 3 taken 323542 times.
✓ Branch 19 → 20 taken 19 times.
323561 for (size_t i = 0; i < opRulesSize; i++) {
753 323542 const BinaryOpRule &rule = opRules[i];
754
6/6
✓ Branch 5 → 6 taken 69606 times.
✓ Branch 5 → 10 taken 253936 times.
✓ Branch 8 → 9 taken 35061 times.
✓ Branch 8 → 10 taken 34545 times.
✓ Branch 11 → 12 taken 35061 times.
✓ Branch 11 → 18 taken 288481 times.
323542 if (std::get<0>(rule) == lhs.getSuperType() && std::get<1>(rule) == rhs.getSuperType()) {
755
1/2
✓ Branch 13 → 14 taken 35061 times.
✗ Branch 13 → 24 not taken.
35061 QualType resultType((std::get<2>(rule)));
756
2/2
✓ Branch 14 → 15 taken 20089 times.
✓ Branch 14 → 17 taken 14972 times.
35061 if (preserveQualifiersFromLhs)
757 20089 resultType.setQualifiers(lhs.getQualifiers());
758 35061 return resultType;
759 }
760 }
761
1/2
✓ Branch 21 → 22 taken 19 times.
✗ Branch 21 → 25 not taken.
19 throw getExceptionBinary(node, name, lhs, rhs, customMessagePrefix);
762 }
763
764 2 SemanticError OpRuleManager::getExceptionUnary(const ASTNode *node, const char *name, const QualType &lhs) {
765
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)};
766 }
767
768 19 SemanticError OpRuleManager::getExceptionBinary(const ASTNode *node, const char *name, const QualType &lhs, const QualType &rhs,
769 const char *messagePrefix) {
770 // Build error message
771
1/2
✓ Branch 2 → 3 taken 19 times.
✗ Branch 2 → 50 not taken.
19 std::stringstream errorMsg;
772
2/2
✓ Branch 3 → 4 taken 4 times.
✓ Branch 3 → 14 taken 15 times.
19 if (strlen(messagePrefix) != 0)
773
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);
774 else
775
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);
776
777 // Return the exception
778
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()};
779 19 }
780
781 9 void OpRuleManager::ensureUnsafeAllowed(const ASTNode *node, const char *name, const QualType &lhs) const {
782
2/4
✓ Branch 2 → 3 taken 9 times.
✗ Branch 2 → 43 not taken.
✓ Branch 3 → 4 taken 9 times.
✗ Branch 3 → 5 not taken.
9 if (typeChecker->currentScope->doesAllowUnsafeOperations())
783 9 return;
784 // Print error message
785 const std::string lhsName = lhs.getName(true);
786 const std::string errorMsg = "Cannot apply '" + std::string(name) + "' operator on type " + lhsName +
787 " as this is an unsafe operation. Please use unsafe blocks if you know what you are doing.";
788 SOFT_ERROR_VOID(node, UNSAFE_OPERATION_IN_SAFE_CONTEXT, errorMsg)
789 }
790
791 907 void OpRuleManager::ensureUnsafeAllowed(const ASTNode *node, const char *name, const QualType &lhs, const QualType &rhs) const {
792
3/4
✓ Branch 2 → 3 taken 907 times.
✗ Branch 2 → 57 not taken.
✓ Branch 3 → 4 taken 906 times.
✓ Branch 3 → 5 taken 1 time.
907 if (typeChecker->currentScope->doesAllowUnsafeOperations())
793 906 return;
794 // Print error message
795
1/2
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 57 not taken.
1 const std::string lhsName = lhs.getName(true);
796
1/2
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 55 not taken.
1 const std::string rhsName = rhs.getName(true);
797
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 +
798
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.";
799
1/2
✓ Branch 23 → 24 taken 1 time.
✗ Branch 23 → 51 not taken.
1 SOFT_ERROR_VOID(node, UNSAFE_OPERATION_IN_SAFE_CONTEXT, errorMsg)
800 1 }
801
802 28768 void OpRuleManager::ensureNoConstAssign(const ASTNode *node, const QualType &lhs, bool isDecl, bool isReturn) const {
803 // Check if we try to assign a constant value
804
10/12
✓ Branch 2 → 3 taken 28768 times.
✗ Branch 2 → 18 not taken.
✓ Branch 3 → 4 taken 28768 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 2971 times.
✓ Branch 4 → 8 taken 25797 times.
✓ Branch 5 → 6 taken 56 times.
✓ Branch 5 → 8 taken 2915 times.
✓ Branch 6 → 7 taken 14 times.
✓ Branch 6 → 8 taken 42 times.
✓ Branch 9 → 10 taken 14 times.
✓ Branch 9 → 17 taken 28754 times.
28768 if (lhs.removeReferenceWrapper().isConst() && !isDecl && !isReturn) {
805
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);
806
1/2
✓ Branch 13 → 14 taken 14 times.
✗ Branch 13 → 22 not taken.
14 SOFT_ERROR_VOID(node, REASSIGN_CONST_VARIABLE, errorMessage);
807 14 }
808 }
809
810 } // namespace spice::compiler
811