GCC Code Coverage Report


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

src/typechecker/OpRuleManager.cpp
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 #include "OpRuleManager.h"
4
5 #include <SourceFile.h>
6 #include <ast/ASTNodes.h>
7 #include <global/GlobalResourceManager.h>
8 #include <symboltablebuilder/Scope.h>
9 #include <typechecker/FunctionManager.h>
10 #include <typechecker/MacroDefs.h>
11 #include <typechecker/TypeChecker.h>
12
13 namespace spice::compiler {
14
15 10076 OpRuleManager::OpRuleManager(TypeChecker *typeChecker)
16 10076 : typeChecker(typeChecker), resourceManager(typeChecker->resourceManager) {}
17
18 80536 std::pair<QualType, Function *> OpRuleManager::getAssignResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs,
19 bool isDecl, bool isReturn, const char *errMsgPrefix) const {
20 // Retrieve types
21 80536 const QualType lhsType = lhs.type;
22 80536 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 80535 times.
80536 if (lhs.isTemporary())
26
2/4
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 107 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 104 not taken.
3 throw SemanticError(node, OPERATOR_WRONG_DATA_TYPE, "Cannot assign to a temporary value");
27
28 // Skip type compatibility check if the lhs is of type dyn -> perform type inference
29
3/4
✓ Branch 12 → 13 taken 80535 times.
✗ Branch 12 → 123 not taken.
✓ Branch 13 → 14 taken 590 times.
✓ Branch 13 → 16 taken 79945 times.
80535 if (lhsType.is(TY_DYN))
30 590 return {rhsType, nullptr};
31
32 // Check if we try to assign a constant value
33
1/2
✓ Branch 16 → 17 taken 79945 times.
✗ Branch 16 → 123 not taken.
79945 ensureNoConstAssign(node, lhsType, isDecl, isReturn);
34
35 // Allow pointers and references of the same type straight away
36
8/10
✓ Branch 17 → 18 taken 79945 times.
✗ Branch 17 → 113 not taken.
✓ Branch 18 → 19 taken 16300 times.
✓ Branch 18 → 22 taken 63645 times.
✓ Branch 19 → 20 taken 16300 times.
✗ Branch 19 → 113 not taken.
✓ Branch 20 → 21 taken 12646 times.
✓ Branch 20 → 22 taken 3654 times.
✓ Branch 23 → 24 taken 12646 times.
✓ Branch 23 → 41 taken 67299 times.
79945 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 4400 times.
✓ Branch 24 → 35 taken 8246 times.
✓ Branch 25 → 26 taken 4400 times.
✗ Branch 25 → 114 not taken.
✓ Branch 26 → 27 taken 3046 times.
✓ Branch 26 → 35 taken 1354 times.
✓ Branch 27 → 28 taken 3046 times.
✗ Branch 27 → 114 not taken.
✓ Branch 28 → 29 taken 1263 times.
✓ Branch 28 → 35 taken 1783 times.
✓ Branch 29 → 30 taken 1263 times.
✗ Branch 29 → 114 not taken.
✓ Branch 30 → 31 taken 1263 times.
✗ Branch 30 → 114 not taken.
✓ Branch 31 → 32 taken 1263 times.
✗ Branch 31 → 35 not taken.
✓ Branch 32 → 33 taken 1263 times.
✗ Branch 32 → 114 not taken.
✓ Branch 33 → 34 taken 1263 times.
✗ Branch 33 → 35 not taken.
✓ Branch 36 → 37 taken 1263 times.
✓ Branch 36 → 39 taken 11383 times.
12646 if (rhs.entry && lhsType.isPtr() && lhsType.isHeap() && rhsType.removeReferenceWrapper().isPtr() && rhsType.isHeap())
39
1/2
✓ Branch 37 → 38 taken 1263 times.
✗ Branch 37 → 115 not taken.
1263 rhs.entry->updateState(MOVED, node);
40 12646 return {rhsType, nullptr};
41 }
42 // Allow ref type to type of the same contained type straight away
43
3/4
✓ Branch 41 → 42 taken 67299 times.
✗ Branch 41 → 123 not taken.
✓ Branch 42 → 43 taken 1967 times.
✓ Branch 42 → 55 taken 65332 times.
67299 if (rhsType.isRef()) {
44 // If this is const ref, remove both: the reference and the constness
45
2/4
✓ Branch 43 → 44 taken 1967 times.
✗ Branch 43 → 116 not taken.
✓ Branch 44 → 45 taken 1967 times.
✗ Branch 44 → 116 not taken.
1967 const QualType rhsNonRef = rhsType.getContained().toNonConst();
46
3/4
✓ Branch 45 → 46 taken 1967 times.
✗ Branch 45 → 117 not taken.
✓ Branch 46 → 47 taken 1965 times.
✓ Branch 46 → 53 taken 2 times.
1967 if (lhsType.matches(rhsNonRef, false, false, true)) {
47
3/4
✓ Branch 47 → 48 taken 1965 times.
✗ Branch 47 → 117 not taken.
✓ Branch 48 → 49 taken 944 times.
✓ Branch 48 → 51 taken 1021 times.
1965 if (rhsNonRef.is(TY_STRUCT))
48
1/2
✓ Branch 49 → 50 taken 944 times.
✗ Branch 49 → 117 not taken.
1965 return performStructAssign(node, lhs, rhs, rhsNonRef, isDecl, isReturn);
49 1021 return {lhsType, nullptr};
50 }
51 }
52 // Allow arrays, structs, interfaces, functions, procedures of the same type straight away
53
8/10
✓ Branch 55 → 56 taken 65334 times.
✗ Branch 55 → 118 not taken.
✓ Branch 56 → 57 taken 357 times.
✓ Branch 56 → 60 taken 64977 times.
✓ Branch 57 → 58 taken 357 times.
✗ Branch 57 → 118 not taken.
✓ Branch 58 → 59 taken 352 times.
✓ Branch 58 → 60 taken 5 times.
✓ Branch 61 → 62 taken 352 times.
✓ Branch 61 → 64 taken 64982 times.
65334 if (lhsType.isOneOf({TY_ARRAY, TY_INTERFACE, TY_FUNCTION, TY_PROCEDURE}) && lhsType.matches(rhsType, false, true, true))
54 352 return {rhsType, nullptr};
55 // Allow struct of the same type straight away
56
8/10
✓ Branch 64 → 65 taken 64982 times.
✗ Branch 64 → 123 not taken.
✓ Branch 65 → 66 taken 12683 times.
✓ Branch 65 → 69 taken 52299 times.
✓ Branch 66 → 67 taken 12683 times.
✗ Branch 66 → 123 not taken.
✓ Branch 67 → 68 taken 12682 times.
✓ Branch 67 → 69 taken 1 time.
✓ Branch 70 → 71 taken 12682 times.
✓ Branch 70 → 73 taken 52300 times.
64982 if (lhsType.is(TY_STRUCT) && lhsType.matches(rhsType, false, true, true))
57
1/2
✓ Branch 71 → 72 taken 12682 times.
✗ Branch 71 → 123 not taken.
12682 return performStructAssign(node, lhs, rhs, rhsType, isDecl, isReturn);
58 // Allow assignment through an already-bound reference to a struct. Unlike binding a reference (declaration/return,
59 // which pass isDecl/isReturn and fall through to the common rules below), an assign-through must run the struct's
60 // copy-assignment operator / copy ctor on the referenced value instead of rebinding or shallow-copying it. Otherwise
61 // the referent would alias the rhs' owned members (heap buffers) and double-free once one of them is destructed.
62
10/14
✓ Branch 74 → 75 taken 9583 times.
✓ Branch 74 → 88 taken 19338 times.
✓ Branch 75 → 76 taken 9583 times.
✗ Branch 75 → 119 not taken.
✓ Branch 76 → 77 taken 323 times.
✓ Branch 76 → 88 taken 9260 times.
✓ Branch 77 → 78 taken 323 times.
✗ Branch 77 → 119 not taken.
✓ Branch 78 → 79 taken 323 times.
✗ Branch 78 → 119 not taken.
✓ Branch 79 → 80 taken 7 times.
✓ Branch 79 → 88 taken 316 times.
✓ Branch 80 → 81 taken 7 times.
✗ Branch 80 → 88 not taken.
28921 if (!isDecl && !isReturn && lhsType.isRef() && lhsType.getContained().is(TY_STRUCT) && lhs.entry != nullptr &&
63
10/16
✓ Branch 73 → 74 taken 28921 times.
✓ Branch 73 → 88 taken 23379 times.
✓ Branch 81 → 82 taken 7 times.
✗ Branch 81 → 119 not taken.
✓ Branch 82 → 83 taken 7 times.
✗ Branch 82 → 88 not taken.
✓ Branch 83 → 84 taken 7 times.
✗ Branch 83 → 119 not taken.
✓ Branch 84 → 85 taken 7 times.
✗ Branch 84 → 119 not taken.
✓ Branch 85 → 86 taken 7 times.
✗ Branch 85 → 119 not taken.
✓ Branch 86 → 87 taken 7 times.
✗ Branch 86 → 88 not taken.
✓ Branch 89 → 90 taken 7 times.
✓ Branch 89 → 94 taken 52293 times.
81221 lhs.entry->isInitialized() && lhsType.getContained().matches(rhsType.removeReferenceWrapper(), false, true, true))
64
2/4
✓ Branch 90 → 91 taken 7 times.
✗ Branch 90 → 122 not taken.
✓ Branch 91 → 92 taken 7 times.
✗ Branch 91 → 122 not taken.
7 return performStructAssign(node, lhs, rhs, lhsType.getContained(), isDecl, isReturn);
65
66 // Check common type combinations
67
2/2
✓ Branch 94 → 95 taken 52291 times.
✓ Branch 94 → 123 taken 2 times.
52293 const QualType resultType = getAssignResultTypeCommon(node, lhs, rhs, isDecl, isReturn);
68
3/4
✓ Branch 95 → 96 taken 52291 times.
✗ Branch 95 → 123 not taken.
✓ Branch 96 → 97 taken 2863 times.
✓ Branch 96 → 99 taken 49428 times.
52291 if (!resultType.is(TY_INVALID))
69 2863 return {resultType, nullptr};
70
71 // Check primitive type combinations
72 49428 const QualType binOpType =
73
2/2
✓ Branch 99 → 100 taken 49415 times.
✓ Branch 99 → 123 taken 13 times.
49428 validateBinaryOperation(node, ASSIGN_OP_RULES, std::size(ASSIGN_OP_RULES), "=", lhsType, rhsType, true, errMsgPrefix);
74 49415 return {binOpType, nullptr};
75 }
76
77 1756 std::pair<QualType, Function *> OpRuleManager::getFieldAssignResultType(ASTNode *node, const ExprResult &lhs,
78 const ExprResult &rhs, bool imm, bool isDecl) const {
79 // Retrieve types
80 1756 const QualType lhsType = lhs.type;
81 1756 const QualType rhsType = rhs.type;
82
2/4
✓ Branch 2 → 3 taken 1756 times.
✗ Branch 2 → 101 not taken.
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 1756 times.
1756 assert(!lhsType.is(TY_DYN));
83
84 // Check if we try to assign a constant value
85
1/2
✓ Branch 5 → 6 taken 1756 times.
✗ Branch 5 → 101 not taken.
1756 ensureNoConstAssign(node, lhsType, isDecl);
86
87 // Allow pointers, arrays and structs of the same type straight away
88
8/10
✓ Branch 6 → 7 taken 1756 times.
✗ Branch 6 → 92 not taken.
✓ Branch 7 → 8 taken 1115 times.
✓ Branch 7 → 11 taken 641 times.
✓ Branch 8 → 9 taken 1115 times.
✗ Branch 8 → 92 not taken.
✓ Branch 9 → 10 taken 1112 times.
✓ Branch 9 → 11 taken 3 times.
✓ Branch 12 → 13 taken 1112 times.
✓ Branch 12 → 30 taken 644 times.
1756 if (lhsType.isOneOf({TY_PTR, TY_ARRAY}) && lhsType == rhsType) {
89 // If we perform a heap x* = heap x* assignment, we need set the right hand side to MOVED
90
8/22
✓ Branch 13 → 14 taken 264 times.
✓ Branch 13 → 24 taken 848 times.
✓ Branch 14 → 15 taken 264 times.
✗ Branch 14 → 93 not taken.
✓ Branch 15 → 16 taken 262 times.
✓ Branch 15 → 24 taken 2 times.
✓ Branch 16 → 17 taken 262 times.
✗ Branch 16 → 93 not taken.
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 24 taken 262 times.
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 93 not taken.
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 93 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 24 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 93 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 24 not taken.
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 28 taken 1112 times.
1112 if (rhs.entry && lhsType.isPtr() && lhsType.isHeap() && rhsType.removeReferenceWrapper().isPtr() && rhsType.isHeap())
91 rhs.entry->updateState(MOVED, node);
92 1112 return {rhsType, nullptr};
93 }
94 // Allow struct of the same type straight away
95
8/10
✓ Branch 30 → 31 taken 644 times.
✗ Branch 30 → 101 not taken.
✓ Branch 31 → 32 taken 68 times.
✓ Branch 31 → 35 taken 576 times.
✓ Branch 32 → 33 taken 68 times.
✗ Branch 32 → 101 not taken.
✓ Branch 33 → 34 taken 43 times.
✓ Branch 33 → 35 taken 25 times.
✓ Branch 36 → 37 taken 43 times.
✓ Branch 36 → 39 taken 601 times.
644 if (lhsType.is(TY_STRUCT) && lhsType.matches(rhsType, false, true, true))
96
1/2
✓ Branch 37 → 38 taken 43 times.
✗ Branch 37 → 101 not taken.
43 return performStructAssign(node, lhs, rhs, rhsType, isDecl, false);
97 // Allow ref type to type of the same contained type straight away
98
9/12
✓ Branch 39 → 40 taken 601 times.
✗ Branch 39 → 95 not taken.
✓ Branch 40 → 41 taken 75 times.
✓ Branch 40 → 45 taken 526 times.
✓ Branch 41 → 42 taken 75 times.
✗ Branch 41 → 95 not taken.
✓ Branch 42 → 43 taken 75 times.
✗ Branch 42 → 95 not taken.
✓ Branch 43 → 44 taken 1 time.
✓ Branch 43 → 45 taken 74 times.
✓ Branch 46 → 47 taken 1 time.
✓ Branch 46 → 64 taken 600 times.
601 if (rhsType.isRef() && lhsType.matches(rhsType.getContained(), false, false, true)) {
99 // Check is there is an overloaded operator function available
100
1/2
✓ Branch 47 → 48 taken 1 time.
✗ Branch 47 → 96 not taken.
1 const auto [type, _] = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_ASSIGN, {lhs, rhs}, 0);
101
2/4
✓ Branch 48 → 49 taken 1 time.
✗ Branch 48 → 98 not taken.
✗ Branch 49 → 50 not taken.
✓ Branch 49 → 52 taken 1 time.
1 if (!type.is(TY_INVALID))
102 return {type, nullptr};
103
104 // In case of a return expression, we perform temp stealing
105 1 Function *copyCtor = nullptr;
106
4/10
✓ Branch 52 → 53 taken 1 time.
✗ Branch 52 → 97 not taken.
✓ Branch 53 → 54 taken 1 time.
✗ Branch 53 → 97 not taken.
✗ Branch 54 → 55 not taken.
✓ Branch 54 → 58 taken 1 time.
✗ Branch 56 → 57 not taken.
✗ Branch 56 → 58 not taken.
✗ Branch 59 → 60 not taken.
✓ Branch 59 → 62 taken 1 time.
1 if (rhsType.getContained().is(TY_STRUCT) && !rhs.isTemporary())
107 copyCtor = typeChecker->implicitlyCallStructCopyCtor(rhs.entry, rhs.entry->declNode);
108 1 return {lhsType, copyCtor};
109 }
110 // Allow ref type to type of the same contained type straight away
111
3/4
✓ Branch 64 → 65 taken 600 times.
✗ Branch 64 → 101 not taken.
✓ Branch 65 → 66 taken 74 times.
✓ Branch 65 → 74 taken 526 times.
600 if (rhsType.isRef()) {
112 // If this is const ref, remove both: the reference and the constness
113
2/4
✓ Branch 66 → 67 taken 74 times.
✗ Branch 66 → 99 not taken.
✓ Branch 67 → 68 taken 74 times.
✗ Branch 67 → 99 not taken.
74 const QualType rhsNonRef = rhsType.getContained().toNonConst();
114
2/4
✓ Branch 68 → 69 taken 74 times.
✗ Branch 68 → 100 not taken.
✓ Branch 69 → 70 taken 74 times.
✗ Branch 69 → 72 not taken.
74 if (lhsType.matches(rhsNonRef, false, false, true))
115
1/2
✓ Branch 70 → 71 taken 74 times.
✗ Branch 70 → 100 not taken.
74 return performStructAssign(node, lhs, rhs, rhsNonRef, isDecl, false);
116 }
117 // Allow immediate value to const ref of the same contained type straight away
118
6/8
✓ Branch 74 → 75 taken 526 times.
✗ Branch 74 → 101 not taken.
✓ Branch 75 → 76 taken 1 time.
✓ Branch 75 → 78 taken 525 times.
✓ Branch 76 → 77 taken 1 time.
✗ Branch 76 → 78 not taken.
✓ Branch 79 → 80 taken 1 time.
✓ Branch 79 → 82 taken 525 times.
526 if (lhsType.isConstRef() && imm)
119 1 return {rhsType, nullptr};
120
121 // Check common type combinations
122
1/2
✓ Branch 82 → 83 taken 525 times.
✗ Branch 82 → 101 not taken.
525 const QualType resultType = getAssignResultTypeCommon(node, lhs, rhs, isDecl, false);
123
3/4
✓ Branch 83 → 84 taken 525 times.
✗ Branch 83 → 101 not taken.
✓ Branch 84 → 85 taken 4 times.
✓ Branch 84 → 87 taken 521 times.
525 if (!resultType.is(TY_INVALID))
124 4 return {resultType, nullptr};
125
126 // Check primitive type combinations
127 521 const QualType binOpType =
128
2/2
✓ Branch 87 → 88 taken 520 times.
✓ Branch 87 → 101 taken 1 time.
521 validateBinaryOperation(node, ASSIGN_OP_RULES, std::size(ASSIGN_OP_RULES), "=", lhsType, rhsType, true, ERROR_FIELD_ASSIGN);
129 520 return {binOpType, nullptr};
130 }
131
132 52818 QualType OpRuleManager::getAssignResultTypeCommon(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, bool isDecl,
133 bool isReturn) {
134 // Retrieve types
135 52818 const QualType lhsType = lhs.type;
136 52818 const QualType rhsType = rhs.type;
137
138 // Allow type to ref type of the same contained type straight away
139
9/12
✓ Branch 2 → 3 taken 52818 times.
✗ Branch 2 → 112 not taken.
✓ Branch 3 → 4 taken 2130 times.
✓ Branch 3 → 8 taken 50688 times.
✓ Branch 4 → 5 taken 2130 times.
✗ Branch 4 → 112 not taken.
✓ Branch 5 → 6 taken 2130 times.
✗ Branch 5 → 112 not taken.
✓ Branch 6 → 7 taken 2127 times.
✓ Branch 6 → 8 taken 3 times.
✓ Branch 9 → 10 taken 2127 times.
✓ Branch 9 → 44 taken 50691 times.
52818 if (lhsType.isRef() && lhsType.getContained().matches(rhsType, false, false, true)) {
140
4/4
✓ Branch 10 → 11 taken 1420 times.
✓ Branch 10 → 12 taken 707 times.
✓ Branch 11 → 12 taken 1104 times.
✓ Branch 11 → 13 taken 316 times.
2127 const bool isDeclOrReturn = isDecl || isReturn;
141
7/8
✓ Branch 14 → 15 taken 1811 times.
✓ Branch 14 → 19 taken 316 times.
✓ Branch 16 → 17 taken 1811 times.
✗ Branch 16 → 136 not taken.
✓ Branch 17 → 18 taken 1 time.
✓ Branch 17 → 19 taken 1810 times.
✓ Branch 20 → 21 taken 1 time.
✓ Branch 20 → 29 taken 2126 times.
2127 if (isDeclOrReturn && !lhsType.canBind(rhsType, rhs.isTemporary()))
142
2/4
✓ Branch 24 → 25 taken 1 time.
✗ Branch 24 → 116 not taken.
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 113 not taken.
3 throw SemanticError(node, TEMP_TO_NON_CONST_REF, "Temporary values can only be bound to const reference variables/fields");
143
6/6
✓ Branch 29 → 30 taken 1104 times.
✓ Branch 29 → 33 taken 1022 times.
✓ Branch 31 → 32 taken 1 time.
✓ Branch 31 → 33 taken 1103 times.
✓ Branch 34 → 35 taken 1 time.
✓ Branch 34 → 43 taken 2125 times.
2126 if (isReturn && rhs.isTemporary())
144
2/4
✓ Branch 38 → 39 taken 1 time.
✗ Branch 38 → 125 not taken.
✓ Branch 39 → 40 taken 1 time.
✗ Branch 39 → 122 not taken.
3 throw SemanticError(node, RETURN_OF_TEMPORARY_VALUE, "Cannot return reference to temporary value");
145 2125 return lhsType;
146 }
147 // Allow char* = string
148
9/14
✓ Branch 44 → 45 taken 50691 times.
✗ Branch 44 → 136 not taken.
✓ Branch 45 → 46 taken 1 time.
✓ Branch 45 → 53 taken 50690 times.
✓ Branch 46 → 47 taken 1 time.
✗ Branch 46 → 136 not taken.
✓ Branch 47 → 48 taken 1 time.
✗ Branch 47 → 53 not taken.
✓ Branch 50 → 51 taken 1 time.
✗ Branch 50 → 136 not taken.
✓ Branch 51 → 52 taken 1 time.
✗ Branch 51 → 53 not taken.
✓ Branch 54 → 55 taken 1 time.
✓ Branch 54 → 56 taken 50690 times.
50691 if (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING) && lhsType.getQualifiers() == rhsType.getQualifiers())
149 1 return lhsType;
150 // Allow array to pointer
151
12/18
✓ Branch 56 → 57 taken 50690 times.
✗ Branch 56 → 131 not taken.
✓ Branch 57 → 58 taken 742 times.
✓ Branch 57 → 65 taken 49948 times.
✓ Branch 58 → 59 taken 742 times.
✗ Branch 58 → 131 not taken.
✓ Branch 59 → 60 taken 7 times.
✓ Branch 59 → 65 taken 735 times.
✓ Branch 60 → 61 taken 7 times.
✗ Branch 60 → 131 not taken.
✓ Branch 61 → 62 taken 7 times.
✗ Branch 61 → 131 not taken.
✓ Branch 62 → 63 taken 7 times.
✗ Branch 62 → 131 not taken.
✓ Branch 63 → 64 taken 7 times.
✗ Branch 63 → 65 not taken.
✓ Branch 66 → 67 taken 7 times.
✓ Branch 66 → 68 taken 50683 times.
50690 if (lhsType.isPtr() && rhsType.isArray() && lhsType.getContained().matches(rhsType.getContained(), false, false, true))
152 7 return lhsType;
153 // Allow interface* = struct* or interface& = struct that implements this interface
154
1/2
✓ Branch 70 → 71 taken 50683 times.
✗ Branch 70 → 136 not taken.
50683 const bool sameChainDepth = Type::hasSameTypeChainDepth(lhsType.getType(), rhsType.getType());
155
10/14
✓ Branch 71 → 72 taken 50683 times.
✗ Branch 71 → 136 not taken.
✓ Branch 72 → 73 taken 735 times.
✓ Branch 72 → 76 taken 49948 times.
✓ Branch 73 → 74 taken 735 times.
✗ Branch 73 → 136 not taken.
✓ Branch 74 → 75 taken 734 times.
✓ Branch 74 → 76 taken 1 time.
✗ Branch 75 → 76 not taken.
✓ Branch 75 → 78 taken 734 times.
✓ Branch 76 → 77 taken 49949 times.
✗ Branch 76 → 136 not taken.
✓ Branch 77 → 78 taken 3 times.
✓ Branch 77 → 79 taken 49946 times.
50683 const bool typesCompatible = (lhsType.isPtr() && rhsType.isPtr() && sameChainDepth) || lhsType.isRef();
156
9/12
✓ Branch 80 → 81 taken 737 times.
✓ Branch 80 → 86 taken 49946 times.
✓ Branch 81 → 82 taken 737 times.
✗ Branch 81 → 136 not taken.
✓ Branch 82 → 83 taken 56 times.
✓ Branch 82 → 86 taken 681 times.
✓ Branch 83 → 84 taken 56 times.
✗ Branch 83 → 136 not taken.
✓ Branch 84 → 85 taken 56 times.
✗ Branch 84 → 86 not taken.
✓ Branch 87 → 88 taken 56 times.
✓ Branch 87 → 93 taken 50627 times.
50683 if (typesCompatible && lhsType.isBase(TY_INTERFACE) && rhsType.isBase(TY_STRUCT)) {
157 56 QualType lhsTypeCopy = lhsType;
158 56 QualType rhsTypeCopy = rhsType;
159
1/2
✓ Branch 88 → 89 taken 56 times.
✗ Branch 88 → 133 not taken.
56 QualType::unwrapBothWithRefWrappers(lhsTypeCopy, rhsTypeCopy);
160
2/4
✓ Branch 89 → 90 taken 56 times.
✗ Branch 89 → 133 not taken.
✓ Branch 90 → 91 taken 56 times.
✗ Branch 90 → 92 not taken.
56 if (lhsTypeCopy.matchesInterfaceImplementedByStruct(rhsTypeCopy))
161 56 return lhsType;
162 }
163 // Allow type* = heap type* straight away. This is used for initializing non-owning pointers to heap allocations
164
10/14
✓ Branch 93 → 94 taken 50627 times.
✗ Branch 93 → 136 not taken.
✓ Branch 94 → 95 taken 680 times.
✓ Branch 94 → 100 taken 49947 times.
✓ Branch 95 → 96 taken 680 times.
✗ Branch 95 → 136 not taken.
✓ Branch 96 → 97 taken 678 times.
✓ Branch 96 → 100 taken 2 times.
✓ Branch 97 → 98 taken 678 times.
✗ Branch 97 → 136 not taken.
✓ Branch 98 → 99 taken 678 times.
✗ Branch 98 → 100 not taken.
✓ Branch 101 → 102 taken 678 times.
✓ Branch 101 → 108 taken 49949 times.
50627 if (lhsType.isPtr() && rhsType.isHeap() && lhsType.matches(rhsType, false, true, true)) {
165 678 TypeQualifiers rhsQualifiers = rhsType.getQualifiers();
166 678 rhsQualifiers.isHeap = false;
167
2/4
✓ Branch 104 → 105 taken 678 times.
✗ Branch 104 → 134 not taken.
✓ Branch 105 → 106 taken 678 times.
✗ Branch 105 → 107 not taken.
678 if (lhsType.getQualifiers() == rhsQualifiers)
168 678 return lhsType;
169 }
170
171 // Nothing matched
172
1/2
✓ Branch 108 → 109 taken 49949 times.
✗ Branch 108 → 135 not taken.
49949 return QualType(TY_INVALID);
173 }
174
175 13750 std::pair<QualType, Function *> OpRuleManager::performStructAssign(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs,
176 const QualType &rhsType, bool isDecl, bool isReturn) const {
177 13750 const bool rhsIsRef = rhs.type.isRef();
178
179 // Check is there is an overloaded operator function available
180
8/8
✓ Branch 3 → 4 taken 7937 times.
✓ Branch 3 → 8 taken 5813 times.
✓ Branch 4 → 5 taken 1033 times.
✓ Branch 4 → 8 taken 6904 times.
✓ Branch 6 → 7 taken 538 times.
✓ Branch 6 → 8 taken 495 times.
✓ Branch 9 → 10 taken 538 times.
✓ Branch 9 → 16 taken 13212 times.
13750 if (!isDecl && !isReturn && lhs.entry->isInitialized()) {
181
1/2
✓ Branch 10 → 11 taken 538 times.
✗ Branch 10 → 44 not taken.
538 const auto [type, _] = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_ASSIGN, {lhs, rhs}, 0);
182
3/4
✓ Branch 11 → 12 taken 538 times.
✗ Branch 11 → 45 not taken.
✓ Branch 12 → 13 taken 397 times.
✓ Branch 12 → 15 taken 141 times.
538 if (!type.is(TY_INVALID))
183 397 return {type, nullptr};
184 }
185
186 // If temp stealing is possible, delete any rhs anonymous entry
187
6/6
✓ Branch 16 → 17 taken 12513 times.
✓ Branch 16 → 20 taken 840 times.
✓ Branch 18 → 19 taken 11741 times.
✓ Branch 18 → 20 taken 772 times.
✓ Branch 21 → 22 taken 11741 times.
✓ Branch 21 → 27 taken 1612 times.
13353 if (!rhsIsRef && rhs.isTemporary()) {
188
3/4
✓ Branch 22 → 23 taken 7973 times.
✓ Branch 22 → 25 taken 3768 times.
✓ Branch 23 → 24 taken 7973 times.
✗ Branch 23 → 25 not taken.
11741 if (rhs.entry != nullptr && rhs.entry->anonymous)
189 7973 typeChecker->currentScope->symbolTable.deleteAnonymous(rhs.entry->name);
190 11741 return {rhsType, nullptr};
191 }
192
193 // If RVO is possible, cancel here
194
7/8
✓ Branch 27 → 28 taken 772 times.
✓ Branch 27 → 32 taken 840 times.
✓ Branch 28 → 29 taken 418 times.
✓ Branch 28 → 32 taken 354 times.
✓ Branch 30 → 31 taken 418 times.
✗ Branch 30 → 32 not taken.
✓ Branch 33 → 34 taken 418 times.
✓ Branch 33 → 36 taken 1194 times.
1612 if (!rhsIsRef && isReturn && !rhs.isTemporary())
195 418 return {rhsType, nullptr};
196
197 // => We have to copy
198 // If struct, try to call copy ctor
199
2/2
✓ Branch 37 → 38 taken 1145 times.
✓ Branch 37 → 41 taken 49 times.
1194 if (rhsType.is(TY_STRUCT))
200
1/2
✓ Branch 38 → 39 taken 1145 times.
✗ Branch 38 → 46 not taken.
1145 return {rhsType, typeChecker->implicitlyCallStructCopyCtor(rhsType, node)};
201
202 // Perform shallow copy
203 49 return {rhsType, nullptr};
204 }
205
206 1177 ExprResult OpRuleManager::getPlusEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
207 // Check is there is an overloaded operator function available
208
1/2
✓ Branch 2 → 3 taken 1177 times.
✗ Branch 2 → 22 not taken.
1177 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_PLUS_EQUAL, {lhs, rhs}, 0);
209
3/4
✓ Branch 3 → 4 taken 1177 times.
✗ Branch 3 → 24 not taken.
✓ Branch 4 → 5 taken 416 times.
✓ Branch 4 → 6 taken 761 times.
1177 if (!resultType.type.is(TY_INVALID))
210 416 return resultType;
211
212 // Check if we try to assign a constant value
213
1/2
✓ Branch 6 → 7 taken 761 times.
✗ Branch 6 → 24 not taken.
761 ensureNoConstAssign(node, lhs.type);
214
215 // Remove reference wrappers
216
1/2
✓ Branch 7 → 8 taken 761 times.
✗ Branch 7 → 24 not taken.
761 const QualType lhsType = lhs.type.removeReferenceWrapper();
217
1/2
✓ Branch 8 → 9 taken 761 times.
✗ Branch 8 → 24 not taken.
761 const QualType rhsType = rhs.type.removeReferenceWrapper();
218
219 // Check if this is an unsafe operation
220
7/10
✓ Branch 9 → 10 taken 761 times.
✗ Branch 9 → 23 not taken.
✓ Branch 10 → 11 taken 166 times.
✓ Branch 10 → 14 taken 595 times.
✓ Branch 11 → 12 taken 166 times.
✗ Branch 11 → 23 not taken.
✓ Branch 12 → 13 taken 166 times.
✗ Branch 12 → 14 not taken.
✓ Branch 15 → 16 taken 166 times.
✓ Branch 15 → 18 taken 595 times.
761 if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) {
221
1/2
✓ Branch 16 → 17 taken 166 times.
✗ Branch 16 → 24 not taken.
166 ensureUnsafeAllowed(node, "+=", lhsType, rhsType);
222 166 return lhs;
223 }
224
225
1/2
✓ Branch 18 → 19 taken 595 times.
✗ Branch 18 → 24 not taken.
595 return {validateBinaryOperation(node, PLUS_EQUAL_OP_RULES, std::size(PLUS_EQUAL_OP_RULES), "+=", lhsType, rhsType)};
226 }
227
228 81 ExprResult OpRuleManager::getMinusEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
229 // Check is there is an overloaded operator function available
230
1/2
✓ Branch 2 → 3 taken 81 times.
✗ Branch 2 → 22 not taken.
81 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MINUS_EQUAL, {lhs, rhs}, 0);
231
3/4
✓ Branch 3 → 4 taken 81 times.
✗ Branch 3 → 24 not taken.
✓ Branch 4 → 5 taken 7 times.
✓ Branch 4 → 6 taken 74 times.
81 if (!resultType.type.is(TY_INVALID))
232 7 return resultType;
233
234 // Check if we try to assign a constant value
235
1/2
✓ Branch 6 → 7 taken 74 times.
✗ Branch 6 → 24 not taken.
74 ensureNoConstAssign(node, lhs.type);
236
237 // Remove reference wrappers
238
1/2
✓ Branch 7 → 8 taken 74 times.
✗ Branch 7 → 24 not taken.
74 const QualType lhsType = lhs.type.removeReferenceWrapper();
239
1/2
✓ Branch 8 → 9 taken 74 times.
✗ Branch 8 → 24 not taken.
74 const QualType rhsType = rhs.type.removeReferenceWrapper();
240
241 // Check if this is an unsafe operation
242
7/10
✓ Branch 9 → 10 taken 74 times.
✗ Branch 9 → 23 not taken.
✓ Branch 10 → 11 taken 5 times.
✓ Branch 10 → 14 taken 69 times.
✓ Branch 11 → 12 taken 5 times.
✗ Branch 11 → 23 not taken.
✓ Branch 12 → 13 taken 5 times.
✗ Branch 12 → 14 not taken.
✓ Branch 15 → 16 taken 5 times.
✓ Branch 15 → 18 taken 69 times.
74 if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) {
243
1/2
✓ Branch 16 → 17 taken 5 times.
✗ Branch 16 → 24 not taken.
5 ensureUnsafeAllowed(node, "-=", lhsType, rhsType);
244 5 return lhs;
245 }
246
247
1/2
✓ Branch 18 → 19 taken 69 times.
✗ Branch 18 → 24 not taken.
69 return {validateBinaryOperation(node, MINUS_EQUAL_OP_RULES, std::size(MINUS_EQUAL_OP_RULES), "-=", lhsType, rhsType)};
248 }
249
250 176 ExprResult OpRuleManager::getMulEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
251 // Check is there is an overloaded operator function available
252
1/2
✓ Branch 2 → 3 taken 176 times.
✗ Branch 2 → 13 not taken.
176 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MUL_EQUAL, {lhs, rhs}, 0);
253
3/4
✓ Branch 3 → 4 taken 176 times.
✗ Branch 3 → 14 not taken.
✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 6 taken 174 times.
176 if (!resultType.type.is(TY_INVALID))
254 2 return resultType;
255
256 // Check if we try to assign a constant value
257
1/2
✓ Branch 6 → 7 taken 174 times.
✗ Branch 6 → 14 not taken.
174 ensureNoConstAssign(node, lhs.type);
258
259 // Remove reference wrappers
260
1/2
✓ Branch 7 → 8 taken 174 times.
✗ Branch 7 → 14 not taken.
174 const QualType lhsType = lhs.type.removeReferenceWrapper();
261
1/2
✓ Branch 8 → 9 taken 174 times.
✗ Branch 8 → 14 not taken.
174 const QualType rhsType = rhs.type.removeReferenceWrapper();
262
263
1/2
✓ Branch 9 → 10 taken 174 times.
✗ Branch 9 → 14 not taken.
174 return {validateBinaryOperation(node, MUL_EQUAL_OP_RULES, std::size(MUL_EQUAL_OP_RULES), "*=", lhsType, rhsType)};
264 }
265
266 104 ExprResult OpRuleManager::getDivEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
267 // Check is there is an overloaded operator function available
268
1/2
✓ Branch 2 → 3 taken 104 times.
✗ Branch 2 → 13 not taken.
104 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_DIV_EQUAL, {lhs, rhs}, 0);
269
3/4
✓ Branch 3 → 4 taken 104 times.
✗ Branch 3 → 14 not taken.
✓ Branch 4 → 5 taken 62 times.
✓ Branch 4 → 6 taken 42 times.
104 if (!resultType.type.is(TY_INVALID))
270 62 return resultType;
271
272 // Check if we try to assign a constant value
273
1/2
✓ Branch 6 → 7 taken 42 times.
✗ Branch 6 → 14 not taken.
42 ensureNoConstAssign(node, lhs.type);
274
275 // Remove reference wrappers
276
1/2
✓ Branch 7 → 8 taken 42 times.
✗ Branch 7 → 14 not taken.
42 const QualType lhsType = lhs.type.removeReferenceWrapper();
277
1/2
✓ Branch 8 → 9 taken 42 times.
✗ Branch 8 → 14 not taken.
42 const QualType rhsType = rhs.type.removeReferenceWrapper();
278
279
1/2
✓ Branch 9 → 10 taken 42 times.
✗ Branch 9 → 14 not taken.
42 return {validateBinaryOperation(node, DIV_EQUAL_OP_RULES, std::size(DIV_EQUAL_OP_RULES), "/=", lhsType, rhsType)};
280 }
281
282 41 QualType OpRuleManager::getRemEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
283 // Check if we try to assign a constant value
284
1/2
✓ Branch 2 → 3 taken 41 times.
✗ Branch 2 → 9 not taken.
41 ensureNoConstAssign(node, lhs.type);
285
286 // Remove reference wrappers
287
1/2
✓ Branch 3 → 4 taken 41 times.
✗ Branch 3 → 9 not taken.
41 const QualType lhsType = lhs.type.removeReferenceWrapper();
288
1/2
✓ Branch 4 → 5 taken 41 times.
✗ Branch 4 → 9 not taken.
41 const QualType rhsType = rhs.type.removeReferenceWrapper();
289
290
1/2
✓ Branch 5 → 6 taken 41 times.
✗ Branch 5 → 9 not taken.
82 return validateBinaryOperation(node, REM_EQUAL_OP_RULES, std::size(REM_EQUAL_OP_RULES), "%=", lhsType, rhsType);
291 }
292
293 12 QualType OpRuleManager::getSHLEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
294 // Check if we try to assign a constant value
295
1/2
✓ Branch 2 → 3 taken 12 times.
✗ Branch 2 → 9 not taken.
12 ensureNoConstAssign(node, lhs.type);
296
297 // Remove reference wrappers
298
1/2
✓ Branch 3 → 4 taken 12 times.
✗ Branch 3 → 9 not taken.
12 const QualType lhsType = lhs.type.removeReferenceWrapper();
299
1/2
✓ Branch 4 → 5 taken 12 times.
✗ Branch 4 → 9 not taken.
12 const QualType rhsType = rhs.type.removeReferenceWrapper();
300
301
1/2
✓ Branch 5 → 6 taken 12 times.
✗ Branch 5 → 9 not taken.
24 return validateBinaryOperation(node, SHL_EQUAL_OP_RULES, std::size(SHL_EQUAL_OP_RULES), "<<=", lhsType, rhsType);
302 }
303
304 13 QualType OpRuleManager::getSHREqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
305 // Check if we try to assign a constant value
306
1/2
✓ Branch 2 → 3 taken 13 times.
✗ Branch 2 → 9 not taken.
13 ensureNoConstAssign(node, lhs.type);
307
308 // Remove reference wrappers
309
1/2
✓ Branch 3 → 4 taken 13 times.
✗ Branch 3 → 9 not taken.
13 const QualType lhsType = lhs.type.removeReferenceWrapper();
310
1/2
✓ Branch 4 → 5 taken 13 times.
✗ Branch 4 → 9 not taken.
13 const QualType rhsType = rhs.type.removeReferenceWrapper();
311
312
1/2
✓ Branch 5 → 6 taken 13 times.
✗ Branch 5 → 9 not taken.
26 return validateBinaryOperation(node, SHR_EQUAL_OP_RULES, std::size(SHR_EQUAL_OP_RULES), ">>=", lhsType, rhsType);
313 }
314
315 17 QualType OpRuleManager::getAndEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
316 // Check if we try to assign a constant value
317
1/2
✓ Branch 2 → 3 taken 17 times.
✗ Branch 2 → 9 not taken.
17 ensureNoConstAssign(node, lhs.type);
318
319 // Remove reference wrappers
320
1/2
✓ Branch 3 → 4 taken 17 times.
✗ Branch 3 → 9 not taken.
17 const QualType lhsType = lhs.type.removeReferenceWrapper();
321
1/2
✓ Branch 4 → 5 taken 17 times.
✗ Branch 4 → 9 not taken.
17 const QualType rhsType = rhs.type.removeReferenceWrapper();
322
323
1/2
✓ Branch 5 → 6 taken 17 times.
✗ Branch 5 → 9 not taken.
34 return validateBinaryOperation(node, AND_EQUAL_OP_RULES, std::size(AND_EQUAL_OP_RULES), "&=", lhsType, rhsType);
324 }
325
326 13 QualType OpRuleManager::getOrEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
327 // Check if we try to assign a constant value
328
1/2
✓ Branch 2 → 3 taken 13 times.
✗ Branch 2 → 9 not taken.
13 ensureNoConstAssign(node, lhs.type);
329
330 // Remove reference wrappers
331
1/2
✓ Branch 3 → 4 taken 13 times.
✗ Branch 3 → 9 not taken.
13 const QualType lhsType = lhs.type.removeReferenceWrapper();
332
1/2
✓ Branch 4 → 5 taken 13 times.
✗ Branch 4 → 9 not taken.
13 const QualType rhsType = rhs.type.removeReferenceWrapper();
333
334
1/2
✓ Branch 5 → 6 taken 13 times.
✗ Branch 5 → 9 not taken.
26 return validateBinaryOperation(node, OR_EQUAL_OP_RULES, std::size(OR_EQUAL_OP_RULES), "|=", lhsType, rhsType);
335 }
336
337 726 QualType OpRuleManager::getXorEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
338 // Check if we try to assign a constant value
339
1/2
✓ Branch 2 → 3 taken 726 times.
✗ Branch 2 → 9 not taken.
726 ensureNoConstAssign(node, lhs.type);
340
341 // Remove reference wrappers
342
1/2
✓ Branch 3 → 4 taken 726 times.
✗ Branch 3 → 9 not taken.
726 const QualType lhsType = lhs.type.removeReferenceWrapper();
343
1/2
✓ Branch 4 → 5 taken 726 times.
✗ Branch 4 → 9 not taken.
726 const QualType rhsType = rhs.type.removeReferenceWrapper();
344
345
1/2
✓ Branch 5 → 6 taken 726 times.
✗ Branch 5 → 9 not taken.
1452 return validateBinaryOperation(node, XOR_EQUAL_OP_RULES, std::size(XOR_EQUAL_OP_RULES), "^=", lhsType, rhsType);
346 }
347
348 2812 QualType OpRuleManager::getLogicalOrResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
349 // Remove reference wrappers
350
1/2
✓ Branch 2 → 3 taken 2812 times.
✗ Branch 2 → 8 not taken.
2812 const QualType lhsType = lhs.type.removeReferenceWrapper();
351
1/2
✓ Branch 3 → 4 taken 2812 times.
✗ Branch 3 → 8 not taken.
2812 const QualType rhsType = rhs.type.removeReferenceWrapper();
352
353
2/2
✓ Branch 4 → 5 taken 2811 times.
✓ Branch 4 → 8 taken 1 time.
5623 return validateBinaryOperation(node, LOGICAL_OR_OP_RULES, std::size(LOGICAL_OR_OP_RULES), "||", lhsType, rhsType);
354 }
355
356 1631 QualType OpRuleManager::getLogicalAndResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
357 // Remove reference wrappers
358
1/2
✓ Branch 2 → 3 taken 1631 times.
✗ Branch 2 → 8 not taken.
1631 const QualType lhsType = lhs.type.removeReferenceWrapper();
359
1/2
✓ Branch 3 → 4 taken 1631 times.
✗ Branch 3 → 8 not taken.
1631 const QualType rhsType = rhs.type.removeReferenceWrapper();
360
361
1/2
✓ Branch 4 → 5 taken 1631 times.
✗ Branch 4 → 8 not taken.
3262 return validateBinaryOperation(node, LOGICAL_AND_OP_RULES, std::size(LOGICAL_AND_OP_RULES), "&&", lhsType, rhsType);
362 }
363
364 294 ExprResult OpRuleManager::getBitwiseOrResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs,
365 size_t opIdx) const {
366 // Check if there is an overloaded operator function available
367
1/2
✓ Branch 2 → 3 taken 294 times.
✗ Branch 2 → 12 not taken.
294 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_BITWISE_OR, {lhs, rhs}, opIdx);
368
3/4
✓ Branch 3 → 4 taken 294 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 4 times.
✓ Branch 4 → 6 taken 290 times.
294 if (!resultType.type.is(TY_INVALID))
369 4 return resultType;
370
371 // Remove reference wrappers
372
1/2
✓ Branch 6 → 7 taken 290 times.
✗ Branch 6 → 13 not taken.
290 const QualType lhsType = lhs.type.removeReferenceWrapper();
373
1/2
✓ Branch 7 → 8 taken 290 times.
✗ Branch 7 → 13 not taken.
290 const QualType rhsType = rhs.type.removeReferenceWrapper();
374
375
2/2
✓ Branch 8 → 9 taken 289 times.
✓ Branch 8 → 13 taken 1 time.
290 return {validateBinaryOperation(node, BITWISE_OR_OP_RULES, std::size(BITWISE_OR_OP_RULES), "|", lhsType, rhsType)};
376 }
377
378 43 ExprResult OpRuleManager::getBitwiseXorResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs,
379 size_t opIdx) const {
380 // Check if there is an overloaded operator function available
381
1/2
✓ Branch 2 → 3 taken 43 times.
✗ Branch 2 → 12 not taken.
43 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_BITWISE_XOR, {lhs, rhs}, opIdx);
382
3/4
✓ Branch 3 → 4 taken 43 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 3 times.
✓ Branch 4 → 6 taken 40 times.
43 if (!resultType.type.is(TY_INVALID))
383 3 return resultType;
384
385 // Remove reference wrappers
386
1/2
✓ Branch 6 → 7 taken 40 times.
✗ Branch 6 → 13 not taken.
40 const QualType lhsType = lhs.type.removeReferenceWrapper();
387
1/2
✓ Branch 7 → 8 taken 40 times.
✗ Branch 7 → 13 not taken.
40 const QualType rhsType = rhs.type.removeReferenceWrapper();
388
389
1/2
✓ Branch 8 → 9 taken 40 times.
✗ Branch 8 → 13 not taken.
40 return {validateBinaryOperation(node, BITWISE_XOR_OP_RULES, std::size(BITWISE_XOR_OP_RULES), "^", lhsType, rhsType)};
390 }
391
392 73 ExprResult OpRuleManager::getBitwiseAndResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs,
393 size_t opIdx) const {
394 // Check if there is an overloaded operator function available
395
1/2
✓ Branch 2 → 3 taken 73 times.
✗ Branch 2 → 12 not taken.
73 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_BITWISE_AND, {lhs, rhs}, opIdx);
396
3/4
✓ Branch 3 → 4 taken 73 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 4 times.
✓ Branch 4 → 6 taken 69 times.
73 if (!resultType.type.is(TY_INVALID))
397 4 return resultType;
398
399 // Remove reference wrappers
400
1/2
✓ Branch 6 → 7 taken 69 times.
✗ Branch 6 → 13 not taken.
69 const QualType lhsType = lhs.type.removeReferenceWrapper();
401
1/2
✓ Branch 7 → 8 taken 69 times.
✗ Branch 7 → 13 not taken.
69 const QualType rhsType = rhs.type.removeReferenceWrapper();
402
403
1/2
✓ Branch 8 → 9 taken 69 times.
✗ Branch 8 → 13 not taken.
69 return {validateBinaryOperation(node, BITWISE_AND_OP_RULES, std::size(BITWISE_AND_OP_RULES), "&", lhsType, rhsType)};
404 }
405
406 14360 ExprResult OpRuleManager::getEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
407 // Check is there is an overloaded operator function available
408
1/2
✓ Branch 2 → 3 taken 14360 times.
✗ Branch 2 → 36 not taken.
14360 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_EQUAL, {lhs, rhs}, 0);
409
3/4
✓ Branch 3 → 4 taken 14360 times.
✗ Branch 3 → 37 not taken.
✓ Branch 4 → 5 taken 1323 times.
✓ Branch 4 → 6 taken 13037 times.
14360 if (!resultType.type.is(TY_INVALID))
410 1323 return resultType;
411
412 // Remove reference wrappers
413
1/2
✓ Branch 6 → 7 taken 13037 times.
✗ Branch 6 → 37 not taken.
13037 const QualType lhsType = lhs.type.removeReferenceWrapper();
414
1/2
✓ Branch 7 → 8 taken 13037 times.
✗ Branch 7 → 37 not taken.
13037 const QualType rhsType = rhs.type.removeReferenceWrapper();
415
416 // Allow 'pointer == unsigned long' straight away
417
10/14
✓ Branch 8 → 9 taken 13037 times.
✗ Branch 8 → 37 not taken.
✓ Branch 9 → 10 taken 3028 times.
✓ Branch 9 → 15 taken 10009 times.
✓ Branch 10 → 11 taken 3028 times.
✗ Branch 10 → 37 not taken.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 15 taken 3027 times.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 37 not taken.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 15 not taken.
✓ Branch 16 → 17 taken 1 time.
✓ Branch 16 → 19 taken 13036 times.
13037 if (lhsType.isPtr() && rhsType.is(TY_LONG) && rhsType.isUnsigned())
418
1/2
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 37 not taken.
1 return ExprResult(QualType(TY_BOOL));
419
420 // Allow 'string == char*' and vice versa straight away
421
13/18
✓ Branch 19 → 20 taken 13036 times.
✗ Branch 19 → 37 not taken.
✓ Branch 20 → 21 taken 358 times.
✓ Branch 20 → 23 taken 12678 times.
✓ Branch 21 → 22 taken 358 times.
✗ Branch 21 → 37 not taken.
✓ Branch 22 → 23 taken 358 times.
✗ Branch 22 → 27 not taken.
✓ Branch 23 → 24 taken 13036 times.
✗ Branch 23 → 37 not taken.
✓ Branch 24 → 25 taken 1772 times.
✓ Branch 24 → 28 taken 11264 times.
✓ Branch 25 → 26 taken 1772 times.
✗ Branch 25 → 37 not taken.
✓ Branch 26 → 27 taken 1 time.
✓ Branch 26 → 28 taken 1771 times.
✓ Branch 29 → 30 taken 1 time.
✓ Branch 29 → 32 taken 13035 times.
13036 if ((lhsType.is(TY_STRING) && rhsType.isPtrTo(TY_CHAR)) || (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING)))
422
1/2
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 37 not taken.
1 return ExprResult(QualType(TY_BOOL));
423
424 // Check primitive type combinations
425
2/2
✓ Branch 32 → 33 taken 13034 times.
✓ Branch 32 → 37 taken 1 time.
13035 return ExprResult(validateBinaryOperation(node, EQUAL_OP_RULES, std::size(EQUAL_OP_RULES), "==", lhsType, rhsType));
426 }
427
428 3837 ExprResult OpRuleManager::getNotEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
429 // Check is there is an overloaded operator function available
430
1/2
✓ Branch 2 → 3 taken 3837 times.
✗ Branch 2 → 36 not taken.
3837 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_NOT_EQUAL, {lhs, rhs}, 0);
431
3/4
✓ Branch 3 → 4 taken 3837 times.
✗ Branch 3 → 37 not taken.
✓ Branch 4 → 5 taken 71 times.
✓ Branch 4 → 6 taken 3766 times.
3837 if (!resultType.type.is(TY_INVALID))
432 71 return resultType;
433
434 // Remove reference wrappers
435
1/2
✓ Branch 6 → 7 taken 3766 times.
✗ Branch 6 → 37 not taken.
3766 const QualType lhsType = lhs.type.removeReferenceWrapper();
436
1/2
✓ Branch 7 → 8 taken 3766 times.
✗ Branch 7 → 37 not taken.
3766 const QualType rhsType = rhs.type.removeReferenceWrapper();
437
438 // Allow 'pointer != unsigned long' straight away
439
10/14
✓ Branch 8 → 9 taken 3766 times.
✗ Branch 8 → 37 not taken.
✓ Branch 9 → 10 taken 802 times.
✓ Branch 9 → 15 taken 2964 times.
✓ Branch 10 → 11 taken 802 times.
✗ Branch 10 → 37 not taken.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 15 taken 801 times.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 37 not taken.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 15 not taken.
✓ Branch 16 → 17 taken 1 time.
✓ Branch 16 → 19 taken 3765 times.
3766 if (lhsType.isPtr() && rhsType.is(TY_LONG) && rhsType.isUnsigned())
440
1/2
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 37 not taken.
1 return ExprResult(QualType(TY_BOOL));
441
442 // Allow 'string != char*' and vice versa straight away
443
13/18
✓ Branch 19 → 20 taken 3765 times.
✗ Branch 19 → 37 not taken.
✓ Branch 20 → 21 taken 30 times.
✓ Branch 20 → 23 taken 3735 times.
✓ Branch 21 → 22 taken 30 times.
✗ Branch 21 → 37 not taken.
✓ Branch 22 → 23 taken 30 times.
✗ Branch 22 → 27 not taken.
✓ Branch 23 → 24 taken 3765 times.
✗ Branch 23 → 37 not taken.
✓ Branch 24 → 25 taken 162 times.
✓ Branch 24 → 28 taken 3603 times.
✓ Branch 25 → 26 taken 162 times.
✗ Branch 25 → 37 not taken.
✓ Branch 26 → 27 taken 1 time.
✓ Branch 26 → 28 taken 161 times.
✓ Branch 29 → 30 taken 1 time.
✓ Branch 29 → 32 taken 3764 times.
3765 if ((lhsType.is(TY_STRING) && rhsType.isPtrTo(TY_CHAR)) || (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING)))
444
1/2
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 37 not taken.
1 return ExprResult(QualType(TY_BOOL));
445
446 // Check primitive type combinations
447
1/2
✓ Branch 32 → 33 taken 3764 times.
✗ Branch 32 → 37 not taken.
3764 return ExprResult(validateBinaryOperation(node, NOT_EQUAL_OP_RULES, std::size(NOT_EQUAL_OP_RULES), "!=", lhsType, rhsType));
448 }
449
450 4867 QualType OpRuleManager::getLessResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
451 // Remove reference wrappers
452
1/2
✓ Branch 2 → 3 taken 4867 times.
✗ Branch 2 → 8 not taken.
4867 const QualType lhsType = lhs.type.removeReferenceWrapper();
453
1/2
✓ Branch 3 → 4 taken 4867 times.
✗ Branch 3 → 8 not taken.
4867 const QualType rhsType = rhs.type.removeReferenceWrapper();
454
455
1/2
✓ Branch 4 → 5 taken 4867 times.
✗ Branch 4 → 8 not taken.
9734 return validateBinaryOperation(node, LESS_OP_RULES, std::size(LESS_OP_RULES), "<", lhsType, rhsType);
456 }
457
458 1760 QualType OpRuleManager::getGreaterResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
459 // Remove reference wrappers
460
1/2
✓ Branch 2 → 3 taken 1760 times.
✗ Branch 2 → 8 not taken.
1760 const QualType lhsType = lhs.type.removeReferenceWrapper();
461
1/2
✓ Branch 3 → 4 taken 1760 times.
✗ Branch 3 → 8 not taken.
1760 const QualType rhsType = rhs.type.removeReferenceWrapper();
462
463
2/2
✓ Branch 4 → 5 taken 1759 times.
✓ Branch 4 → 8 taken 1 time.
3519 return validateBinaryOperation(node, GREATER_OP_RULES, std::size(GREATER_OP_RULES), ">", lhsType, rhsType);
464 }
465
466 1264 QualType OpRuleManager::getLessEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
467 // Remove reference wrappers
468
1/2
✓ Branch 2 → 3 taken 1264 times.
✗ Branch 2 → 8 not taken.
1264 const QualType lhsType = lhs.type.removeReferenceWrapper();
469
1/2
✓ Branch 3 → 4 taken 1264 times.
✗ Branch 3 → 8 not taken.
1264 const QualType rhsType = rhs.type.removeReferenceWrapper();
470
471
1/2
✓ Branch 4 → 5 taken 1264 times.
✗ Branch 4 → 8 not taken.
2528 return validateBinaryOperation(node, LESS_EQUAL_OP_RULES, std::size(LESS_EQUAL_OP_RULES), "<=", lhsType, rhsType);
472 }
473
474 2186 QualType OpRuleManager::getGreaterEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
475 // Remove reference wrappers
476
1/2
✓ Branch 2 → 3 taken 2186 times.
✗ Branch 2 → 18 not taken.
2186 const QualType lhsType = lhs.type.removeReferenceWrapper();
477
1/2
✓ Branch 3 → 4 taken 2186 times.
✗ Branch 3 → 18 not taken.
2186 const QualType rhsType = rhs.type.removeReferenceWrapper();
478
479 // Allow 'pointer == pointer' straight away
480
7/10
✓ Branch 4 → 5 taken 2186 times.
✗ Branch 4 → 18 not taken.
✓ Branch 5 → 6 taken 4 times.
✓ Branch 5 → 9 taken 2182 times.
✓ Branch 6 → 7 taken 4 times.
✗ Branch 6 → 18 not taken.
✓ Branch 7 → 8 taken 4 times.
✗ Branch 7 → 9 not taken.
✓ Branch 10 → 11 taken 4 times.
✓ Branch 10 → 13 taken 2182 times.
2186 if (lhsType.isPtr() && rhsType.isPtr())
481
1/2
✓ Branch 11 → 12 taken 4 times.
✗ Branch 11 → 17 not taken.
4 return QualType(TY_BOOL);
482
483
1/2
✓ Branch 13 → 14 taken 2182 times.
✗ Branch 13 → 18 not taken.
2182 return validateBinaryOperation(node, GREATER_EQUAL_OP_RULES, std::size(GREATER_EQUAL_OP_RULES), ">=", lhsType, rhsType);
484 }
485
486 2100 ExprResult OpRuleManager::getShiftLeftResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs,
487 size_t opIdx) const {
488 // Check is there is an overloaded operator function available
489
1/2
✓ Branch 2 → 3 taken 2100 times.
✗ Branch 2 → 12 not taken.
2100 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_SHL, {lhs, rhs}, opIdx);
490
3/4
✓ Branch 3 → 4 taken 2100 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 2048 times.
✓ Branch 4 → 6 taken 52 times.
2100 if (!resultType.type.is(TY_INVALID))
491 2048 return resultType;
492
493 // Remove reference wrappers
494
1/2
✓ Branch 6 → 7 taken 52 times.
✗ Branch 6 → 13 not taken.
52 const QualType lhsType = lhs.type.removeReferenceWrapper();
495
1/2
✓ Branch 7 → 8 taken 52 times.
✗ Branch 7 → 13 not taken.
52 const QualType rhsType = rhs.type.removeReferenceWrapper();
496
497
1/2
✓ Branch 8 → 9 taken 52 times.
✗ Branch 8 → 13 not taken.
52 return {validateBinaryOperation(node, SHIFT_LEFT_OP_RULES, std::size(SHIFT_LEFT_OP_RULES), "<<", lhsType, rhsType)};
498 }
499
500 203 ExprResult OpRuleManager::getShiftRightResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs,
501 size_t opIdx) const {
502 // Check is there is an overloaded operator function available
503
1/2
✓ Branch 2 → 3 taken 203 times.
✗ Branch 2 → 12 not taken.
203 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_SHR, {lhs, rhs}, opIdx);
504
3/4
✓ Branch 3 → 4 taken 203 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 202 times.
203 if (!resultType.type.is(TY_INVALID))
505 1 return resultType;
506
507 // Remove reference wrappers
508
1/2
✓ Branch 6 → 7 taken 202 times.
✗ Branch 6 → 13 not taken.
202 const QualType lhsType = lhs.type.removeReferenceWrapper();
509
1/2
✓ Branch 7 → 8 taken 202 times.
✗ Branch 7 → 13 not taken.
202 const QualType rhsType = rhs.type.removeReferenceWrapper();
510
511
1/2
✓ Branch 8 → 9 taken 202 times.
✗ Branch 8 → 13 not taken.
202 return {validateBinaryOperation(node, SHIFT_RIGHT_OP_RULES, std::size(SHIFT_RIGHT_OP_RULES), ">>", lhsType, rhsType)};
512 }
513
514 6993 ExprResult OpRuleManager::getPlusResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const {
515 // Check is there is an overloaded operator function available
516
1/2
✓ Branch 2 → 3 taken 6993 times.
✗ Branch 2 → 30 not taken.
6993 const ExprResult result = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_PLUS, {lhs, rhs}, opIdx);
517
3/4
✓ Branch 3 → 4 taken 6993 times.
✗ Branch 3 → 33 not taken.
✓ Branch 4 → 5 taken 594 times.
✓ Branch 4 → 6 taken 6399 times.
6993 if (!result.type.is(TY_INVALID))
518 594 return result;
519
520 // Remove reference wrappers
521
1/2
✓ Branch 6 → 7 taken 6399 times.
✗ Branch 6 → 33 not taken.
6399 const QualType lhsType = lhs.type.removeReferenceWrapper();
522
1/2
✓ Branch 7 → 8 taken 6399 times.
✗ Branch 7 → 33 not taken.
6399 const QualType rhsType = rhs.type.removeReferenceWrapper();
523
524 // Allow any* + <int/long/short>
525
7/10
✓ Branch 8 → 9 taken 6399 times.
✗ Branch 8 → 31 not taken.
✓ Branch 9 → 10 taken 969 times.
✓ Branch 9 → 13 taken 5430 times.
✓ Branch 10 → 11 taken 969 times.
✗ Branch 10 → 31 not taken.
✓ Branch 11 → 12 taken 969 times.
✗ Branch 11 → 13 not taken.
✓ Branch 14 → 15 taken 969 times.
✓ Branch 14 → 17 taken 5430 times.
6399 if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) {
526
1/2
✓ Branch 15 → 16 taken 969 times.
✗ Branch 15 → 33 not taken.
969 ensureUnsafeAllowed(node, "+", lhsType, rhsType);
527 969 return {lhsType};
528 }
529 // Allow <int/long/short> + any*
530
6/10
✓ Branch 17 → 18 taken 5430 times.
✗ Branch 17 → 32 not taken.
✓ Branch 18 → 19 taken 5030 times.
✓ Branch 18 → 22 taken 400 times.
✓ Branch 19 → 20 taken 5030 times.
✗ Branch 19 → 32 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 5030 times.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 26 taken 5430 times.
5430 if (lhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT}) && rhsType.isPtr()) {
531 ensureUnsafeAllowed(node, "+", lhsType, rhsType);
532 return {rhsType};
533 }
534
535
2/2
✓ Branch 26 → 27 taken 5429 times.
✓ Branch 26 → 33 taken 1 time.
5430 return {validateBinaryOperation(node, PLUS_OP_RULES, std::size(PLUS_OP_RULES), "+", lhsType, rhsType)};
536 }
537
538 4043 ExprResult OpRuleManager::getMinusResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const {
539 // Check is there is an overloaded operator function available
540
1/2
✓ Branch 2 → 3 taken 4043 times.
✗ Branch 2 → 21 not taken.
4043 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MINUS, {lhs, rhs}, opIdx);
541
3/4
✓ Branch 3 → 4 taken 4043 times.
✗ Branch 3 → 23 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 4042 times.
4043 if (!resultType.type.is(TY_INVALID))
542 1 return resultType;
543
544 // Remove reference wrappers
545
1/2
✓ Branch 6 → 7 taken 4042 times.
✗ Branch 6 → 23 not taken.
4042 const QualType lhsType = lhs.type.removeReferenceWrapper();
546
1/2
✓ Branch 7 → 8 taken 4042 times.
✗ Branch 7 → 23 not taken.
4042 const QualType rhsType = rhs.type.removeReferenceWrapper();
547
548 // Allow any* - <int/long/short>
549
7/10
✓ Branch 8 → 9 taken 4042 times.
✗ Branch 8 → 22 not taken.
✓ Branch 9 → 10 taken 3 times.
✓ Branch 9 → 13 taken 4039 times.
✓ Branch 10 → 11 taken 3 times.
✗ Branch 10 → 22 not taken.
✓ Branch 11 → 12 taken 3 times.
✗ Branch 11 → 13 not taken.
✓ Branch 14 → 15 taken 3 times.
✓ Branch 14 → 17 taken 4039 times.
4042 if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) {
550
1/2
✓ Branch 15 → 16 taken 3 times.
✗ Branch 15 → 23 not taken.
3 ensureUnsafeAllowed(node, "-", lhsType, rhsType);
551 3 return lhs;
552 }
553
554
1/2
✓ Branch 17 → 18 taken 4039 times.
✗ Branch 17 → 23 not taken.
4039 return {validateBinaryOperation(node, MINUS_OP_RULES, std::size(MINUS_OP_RULES), "-", lhsType, rhsType)};
555 }
556
557 2219 ExprResult OpRuleManager::getMulResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const {
558 // Check is there is an overloaded operator function available
559
1/2
✓ Branch 2 → 3 taken 2219 times.
✗ Branch 2 → 12 not taken.
2219 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MUL, {lhs, rhs}, opIdx);
560
3/4
✓ Branch 3 → 4 taken 2219 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 9 times.
✓ Branch 4 → 6 taken 2210 times.
2219 if (!resultType.type.is(TY_INVALID))
561 9 return resultType;
562
563 // Remove reference wrappers
564
1/2
✓ Branch 6 → 7 taken 2210 times.
✗ Branch 6 → 13 not taken.
2210 const QualType lhsType = lhs.type.removeReferenceWrapper();
565
1/2
✓ Branch 7 → 8 taken 2210 times.
✗ Branch 7 → 13 not taken.
2210 const QualType rhsType = rhs.type.removeReferenceWrapper();
566
567
2/2
✓ Branch 8 → 9 taken 2209 times.
✓ Branch 8 → 13 taken 1 time.
2210 return {validateBinaryOperation(node, MUL_OP_RULES, std::size(MUL_OP_RULES), "*", lhsType, rhsType)};
568 }
569
570 525 ExprResult OpRuleManager::getDivResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const {
571 // Check is there is an overloaded operator function available
572
1/2
✓ Branch 2 → 3 taken 525 times.
✗ Branch 2 → 12 not taken.
525 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_DIV, {lhs, rhs}, opIdx);
573
3/4
✓ Branch 3 → 4 taken 525 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 5 times.
✓ Branch 4 → 6 taken 520 times.
525 if (!resultType.type.is(TY_INVALID))
574 5 return resultType;
575
576 // Remove reference wrappers
577
1/2
✓ Branch 6 → 7 taken 520 times.
✗ Branch 6 → 13 not taken.
520 const QualType lhsType = lhs.type.removeReferenceWrapper();
578
1/2
✓ Branch 7 → 8 taken 520 times.
✗ Branch 7 → 13 not taken.
520 const QualType rhsType = rhs.type.removeReferenceWrapper();
579
580
1/2
✓ Branch 8 → 9 taken 520 times.
✗ Branch 8 → 13 not taken.
520 return {validateBinaryOperation(node, DIV_OP_RULES, std::size(DIV_OP_RULES), "/", lhsType, rhsType)};
581 }
582
583 132 ExprResult OpRuleManager::getRemResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
584 // Remove reference wrappers
585
1/2
✓ Branch 2 → 3 taken 132 times.
✗ Branch 2 → 7 not taken.
132 const QualType lhsType = lhs.type.removeReferenceWrapper();
586
1/2
✓ Branch 3 → 4 taken 132 times.
✗ Branch 3 → 7 not taken.
132 const QualType rhsType = rhs.type.removeReferenceWrapper();
587
588
1/2
✓ Branch 4 → 5 taken 132 times.
✗ Branch 4 → 7 not taken.
132 return {validateBinaryOperation(node, REM_OP_RULES, std::size(REM_OP_RULES), "%", lhsType, rhsType)};
589 }
590
591 1004 QualType OpRuleManager::getPrefixMinusResultType(const ASTNode *node, const ExprResult &lhs) {
592 // Remove reference wrappers
593
1/2
✓ Branch 2 → 3 taken 1004 times.
✗ Branch 2 → 7 not taken.
1004 const QualType lhsType = lhs.type.removeReferenceWrapper();
594
595
1/2
✓ Branch 3 → 4 taken 1004 times.
✗ Branch 3 → 7 not taken.
2008 return validateUnaryOperation(node, PREFIX_MINUS_OP_RULES, std::size(PREFIX_MINUS_OP_RULES), "-", lhsType);
596 }
597
598 18 QualType OpRuleManager::getPrefixPlusPlusResultType(const ASTNode *node, const ExprResult &lhs) const {
599 // Check if we try to assign a constant value
600
1/2
✓ Branch 2 → 3 taken 18 times.
✗ Branch 2 → 12 not taken.
18 ensureNoConstAssign(node, lhs.type);
601
602 // Remove reference wrappers
603
1/2
✓ Branch 3 → 4 taken 18 times.
✗ Branch 3 → 12 not taken.
18 const QualType lhsType = lhs.type.removeReferenceWrapper();
604
605 // Check if this is an unsafe operation
606
2/4
✓ Branch 4 → 5 taken 18 times.
✗ Branch 4 → 12 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 18 times.
18 if (lhsType.isPtr()) {
607 ensureUnsafeAllowed(node, "++", lhsType);
608 return lhsType;
609 }
610
611
1/2
✓ Branch 8 → 9 taken 18 times.
✗ Branch 8 → 12 not taken.
18 return validateUnaryOperation(node, PREFIX_PLUS_PLUS_OP_RULES, std::size(PREFIX_PLUS_PLUS_OP_RULES), "++", lhsType);
612 }
613
614 16 QualType OpRuleManager::getPrefixMinusMinusResultType(const ASTNode *node, const ExprResult &lhs) const {
615 // Check if we try to assign a constant value
616
1/2
✓ Branch 2 → 3 taken 16 times.
✗ Branch 2 → 12 not taken.
16 ensureNoConstAssign(node, lhs.type);
617
618 // Remove reference wrappers
619
1/2
✓ Branch 3 → 4 taken 16 times.
✗ Branch 3 → 12 not taken.
16 const QualType lhsType = lhs.type.removeReferenceWrapper();
620
621 // Check if this is an unsafe operation
622
2/4
✓ Branch 4 → 5 taken 16 times.
✗ Branch 4 → 12 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 16 times.
16 if (lhsType.isPtr()) {
623 ensureUnsafeAllowed(node, "--", lhsType);
624 return lhsType;
625 }
626
627
2/2
✓ Branch 8 → 9 taken 15 times.
✓ Branch 8 → 12 taken 1 time.
16 return validateUnaryOperation(node, PREFIX_MINUS_MINUS_OP_RULES, std::size(PREFIX_MINUS_MINUS_OP_RULES), "--", lhsType);
628 }
629
630 4058 QualType OpRuleManager::getPrefixNotResultType(const ASTNode *node, const ExprResult &lhs) {
631 // Remove reference wrappers
632
1/2
✓ Branch 2 → 3 taken 4058 times.
✗ Branch 2 → 7 not taken.
4058 const QualType lhsType = lhs.type.removeReferenceWrapper();
633
634
1/2
✓ Branch 3 → 4 taken 4058 times.
✗ Branch 3 → 7 not taken.
8116 return validateUnaryOperation(node, PREFIX_NOT_OP_RULES, std::size(PREFIX_NOT_OP_RULES), "!", lhsType);
635 }
636
637 12 ExprResult OpRuleManager::getPrefixBitwiseNotResultType(ASTNode *node, const ExprResult &lhs) const {
638 // Check if there is an overloaded operator function available
639
1/2
✓ Branch 2 → 3 taken 12 times.
✗ Branch 2 → 11 not taken.
12 const ExprResult resultType = isOperatorOverloadingFctAvailable<1>(node, OP_FCT_BITWISE_NOT, {lhs}, 0);
640
3/4
✓ Branch 3 → 4 taken 12 times.
✗ Branch 3 → 12 not taken.
✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 6 taken 10 times.
12 if (!resultType.type.is(TY_INVALID))
641 2 return resultType;
642
643 // Remove reference wrappers
644
1/2
✓ Branch 6 → 7 taken 10 times.
✗ Branch 6 → 12 not taken.
10 const QualType lhsType = lhs.type.removeReferenceWrapper();
645
646
1/2
✓ Branch 7 → 8 taken 10 times.
✗ Branch 7 → 12 not taken.
10 return {validateUnaryOperation(node, PREFIX_BITWISE_NOT_OP_RULES, std::size(PREFIX_BITWISE_NOT_OP_RULES), "~", lhsType)};
647 }
648
649 1015 QualType OpRuleManager::getPrefixMulResultType(const ASTNode *node, const ExprResult &lhs) {
650 // Remove reference wrappers
651
1/2
✓ Branch 2 → 3 taken 1015 times.
✗ Branch 2 → 25 not taken.
1015 const QualType lhsType = lhs.type.removeReferenceWrapper();
652
653
3/4
✓ Branch 3 → 4 taken 1015 times.
✗ Branch 3 → 25 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 12 taken 1014 times.
1015 if (!lhsType.isPtr())
654
3/6
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 21 not taken.
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 19 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 16 not taken.
1 throw SemanticError(node, OPERATOR_WRONG_DATA_TYPE, "Cannot apply de-referencing operator on type " + lhsType.getName(true));
655
1/2
✓ Branch 12 → 13 taken 1014 times.
✗ Branch 12 → 25 not taken.
2028 return lhsType.getContained();
656 }
657
658 1004 QualType OpRuleManager::getPrefixBitwiseAndResultType(const ASTNode *node, const ExprResult &lhs) {
659 // Remove reference wrappers
660
1/2
✓ Branch 2 → 3 taken 1004 times.
✗ Branch 2 → 7 not taken.
1004 const QualType lhsType = lhs.type.removeReferenceWrapper();
661
662
1/2
✓ Branch 3 → 4 taken 1004 times.
✗ Branch 3 → 7 not taken.
2008 return lhsType.toPtr(node);
663 }
664
665 5365 ExprResult OpRuleManager::getPostfixPlusPlusResultType(ASTNode *node, const ExprResult &lhs) const {
666 // Check is there is an overloaded operator function available
667
2/2
✓ Branch 2 → 3 taken 5364 times.
✓ Branch 2 → 16 taken 1 time.
5365 const ExprResult resultType = isOperatorOverloadingFctAvailable<1>(node, OP_FCT_POSTFIX_PLUS_PLUS, {lhs}, 0);
668
3/4
✓ Branch 3 → 4 taken 5364 times.
✗ Branch 3 → 17 not taken.
✓ Branch 4 → 5 taken 9 times.
✓ Branch 4 → 6 taken 5355 times.
5364 if (!resultType.type.is(TY_INVALID))
669 9 return resultType;
670
671 // Check if we try to assign a constant value
672
1/2
✓ Branch 6 → 7 taken 5355 times.
✗ Branch 6 → 17 not taken.
5355 ensureNoConstAssign(node, lhs.type);
673
674 // Remove reference wrappers
675
1/2
✓ Branch 7 → 8 taken 5355 times.
✗ Branch 7 → 17 not taken.
5355 const QualType lhsType = lhs.type.removeReferenceWrapper();
676
677 // Check if this is an unsafe operation
678
3/4
✓ Branch 8 → 9 taken 5355 times.
✗ Branch 8 → 17 not taken.
✓ Branch 9 → 10 taken 27 times.
✓ Branch 9 → 12 taken 5328 times.
5355 if (lhsType.isPtr()) {
679
1/2
✓ Branch 10 → 11 taken 27 times.
✗ Branch 10 → 17 not taken.
27 ensureUnsafeAllowed(node, "++", lhsType);
680 27 return lhs;
681 }
682
683
2/2
✓ Branch 12 → 13 taken 5327 times.
✓ Branch 12 → 17 taken 1 time.
5328 return {validateUnaryOperation(node, POSTFIX_PLUS_PLUS_OP_RULES, std::size(POSTFIX_PLUS_PLUS_OP_RULES), "++", lhsType)};
684 }
685
686 534 ExprResult OpRuleManager::getPostfixMinusMinusResultType(ASTNode *node, const ExprResult &lhs) const {
687 // Check is there is an overloaded operator function available
688
1/2
✓ Branch 2 → 3 taken 534 times.
✗ Branch 2 → 16 not taken.
534 const ExprResult resultType = isOperatorOverloadingFctAvailable<1>(node, OP_FCT_POSTFIX_MINUS_MINUS, {lhs}, 0);
689
3/4
✓ Branch 3 → 4 taken 534 times.
✗ Branch 3 → 17 not taken.
✓ Branch 4 → 5 taken 7 times.
✓ Branch 4 → 6 taken 527 times.
534 if (!resultType.type.is(TY_INVALID))
690 7 return resultType;
691
692 // Check if we try to assign a constant value
693
1/2
✓ Branch 6 → 7 taken 527 times.
✗ Branch 6 → 17 not taken.
527 ensureNoConstAssign(node, lhs.type);
694
695 // Remove reference wrappers
696
1/2
✓ Branch 7 → 8 taken 527 times.
✗ Branch 7 → 17 not taken.
527 const QualType lhsType = lhs.type.removeReferenceWrapper();
697
698 // Check if this is an unsafe operation
699
3/4
✓ Branch 8 → 9 taken 527 times.
✗ Branch 8 → 17 not taken.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 12 taken 525 times.
527 if (lhsType.isPtr()) {
700
1/2
✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 17 not taken.
2 ensureUnsafeAllowed(node, "--", lhsType);
701 2 return lhs;
702 }
703
704
1/2
✓ Branch 12 → 13 taken 525 times.
✗ Branch 12 → 17 not taken.
525 return {validateUnaryOperation(node, POSTFIX_MINUS_MINUS_OP_RULES, std::size(POSTFIX_MINUS_MINUS_OP_RULES), "--", lhsType)};
705 }
706
707 8828 QualType OpRuleManager::getCastResultType(const ASTNode *node, QualType lhsType, const ExprResult &rhs) const {
708 // Remove reference wrappers
709
1/2
✓ Branch 2 → 3 taken 8828 times.
✗ Branch 2 → 73 not taken.
8828 lhsType = lhsType.removeReferenceWrapper();
710
1/2
✓ Branch 3 → 4 taken 8828 times.
✗ Branch 3 → 82 not taken.
8828 QualType rhsType = rhs.type.removeReferenceWrapper();
711
712 // Only allow to cast the 'heap' qualifier away, if we are in unsafe mode
713
2/2
✓ Branch 6 → 7 taken 477 times.
✓ Branch 6 → 8 taken 8351 times.
8828 if (lhsType.getQualifiers().isHeap != rhsType.getQualifiers().isHeap)
714
1/2
✓ Branch 7 → 8 taken 477 times.
✗ Branch 7 → 82 not taken.
477 ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType);
715
716 // Allow identity casts
717
3/4
✓ Branch 8 → 9 taken 8828 times.
✗ Branch 8 → 82 not taken.
✓ Branch 9 → 10 taken 1021 times.
✓ Branch 9 → 11 taken 7807 times.
8828 if (lhsType.matches(rhsType, false, true, true))
718 1021 return lhsType;
719 // Allow casts string -> char* and string -> char[]
720
12/16
✓ Branch 11 → 12 taken 7807 times.
✗ Branch 11 → 74 not taken.
✓ Branch 12 → 13 taken 4468 times.
✓ Branch 12 → 19 taken 3339 times.
✓ Branch 13 → 14 taken 4468 times.
✗ Branch 13 → 74 not taken.
✓ Branch 14 → 15 taken 4468 times.
✗ Branch 14 → 74 not taken.
✓ Branch 15 → 16 taken 2049 times.
✓ Branch 15 → 19 taken 2419 times.
✓ Branch 16 → 17 taken 2049 times.
✗ Branch 16 → 74 not taken.
✓ Branch 17 → 18 taken 2042 times.
✓ Branch 17 → 19 taken 7 times.
✓ Branch 20 → 21 taken 2042 times.
✓ Branch 20 → 22 taken 5765 times.
7807 if (lhsType.isOneOf({TY_PTR, TY_ARRAY}) && lhsType.getContained().is(TY_CHAR) && rhsType.is(TY_STRING))
721 2042 return lhsType;
722 // Allow casts char* -> string and char[] -> string
723
10/16
✓ Branch 22 → 23 taken 5765 times.
✗ Branch 22 → 76 not taken.
✓ Branch 23 → 24 taken 163 times.
✓ Branch 23 → 30 taken 5602 times.
✓ Branch 24 → 25 taken 163 times.
✗ Branch 24 → 76 not taken.
✓ Branch 25 → 26 taken 163 times.
✗ Branch 25 → 30 not taken.
✓ Branch 26 → 27 taken 163 times.
✗ Branch 26 → 76 not taken.
✓ Branch 27 → 28 taken 163 times.
✗ Branch 27 → 76 not taken.
✓ Branch 28 → 29 taken 163 times.
✗ Branch 28 → 30 not taken.
✓ Branch 31 → 32 taken 163 times.
✓ Branch 31 → 33 taken 5602 times.
5765 if (lhsType.is(TY_STRING) && rhsType.isOneOf({TY_PTR, TY_ARRAY}) && rhsType.getContained().is(TY_CHAR))
724 163 return lhsType;
725 // Allow safe upcasts baseStruct* <- derivedStruct* and interface* <- struct* without requiring an unsafe
726 // block. These are the only struct-pointer casts where the target subobject is guaranteed to be present;
727 // the IR generator advances the pointer to that subobject (past any vtable prefix). The reverse direction
728 // (down/sibling casts) is not covered here and still falls through to the unsafe any* -> any* rule below.
729
8/10
✓ Branch 33 → 34 taken 5602 times.
✗ Branch 33 → 82 not taken.
✓ Branch 34 → 35 taken 2426 times.
✓ Branch 34 → 38 taken 3176 times.
✓ Branch 35 → 36 taken 2426 times.
✗ Branch 35 → 82 not taken.
✓ Branch 36 → 37 taken 2418 times.
✓ Branch 36 → 38 taken 8 times.
✓ Branch 39 → 40 taken 2418 times.
✓ Branch 39 → 51 taken 3184 times.
5602 if (lhsType.isPtr() && rhsType.isPtr()) {
730
1/2
✓ Branch 40 → 41 taken 2418 times.
✗ Branch 40 → 78 not taken.
2418 const QualType lhsContained = lhsType.getContained();
731
1/2
✓ Branch 41 → 42 taken 2418 times.
✗ Branch 41 → 78 not taken.
2418 const QualType rhsContained = rhsType.getContained();
732
8/10
✓ Branch 42 → 43 taken 2418 times.
✗ Branch 42 → 78 not taken.
✓ Branch 43 → 44 taken 2411 times.
✓ Branch 43 → 46 taken 7 times.
✓ Branch 44 → 45 taken 2411 times.
✗ Branch 44 → 78 not taken.
✓ Branch 45 → 46 taken 462 times.
✓ Branch 45 → 47 taken 1949 times.
✓ Branch 48 → 49 taken 469 times.
✓ Branch 48 → 50 taken 1949 times.
2418 if (lhsContained.matchesInterfaceImplementedByStruct(rhsContained) || lhsContained.matchesComposedBaseOfStruct(rhsContained))
733 469 return lhsType;
734 }
735 // Allow casts any* -> any*
736
8/10
✓ Branch 51 → 52 taken 5133 times.
✗ Branch 51 → 79 not taken.
✓ Branch 52 → 53 taken 1957 times.
✓ Branch 52 → 56 taken 3176 times.
✓ Branch 53 → 54 taken 1957 times.
✗ Branch 53 → 79 not taken.
✓ Branch 54 → 55 taken 1949 times.
✓ Branch 54 → 56 taken 8 times.
✓ Branch 57 → 58 taken 1949 times.
✓ Branch 57 → 60 taken 3184 times.
5133 if (lhsType.isOneOf({TY_PTR, TY_STRING}) && rhsType.isOneOf({TY_PTR, TY_STRING})) {
737
1/2
✓ Branch 58 → 59 taken 1949 times.
✗ Branch 58 → 82 not taken.
1949 ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType);
738 1949 return lhsType;
739 }
740 // Allow casts p()/f<>() -> byte*
741
7/10
✓ Branch 60 → 61 taken 3184 times.
✗ Branch 60 → 81 not taken.
✓ Branch 61 → 62 taken 8 times.
✓ Branch 61 → 65 taken 3176 times.
✓ Branch 62 → 63 taken 8 times.
✗ Branch 62 → 81 not taken.
✓ Branch 63 → 64 taken 8 times.
✗ Branch 63 → 65 not taken.
✓ Branch 66 → 67 taken 8 times.
✓ Branch 66 → 69 taken 3176 times.
3184 if (lhsType.isPtrTo(TY_BYTE) && rhsType.isOneOf({TY_FUNCTION, TY_PROCEDURE})) {
742
1/2
✓ Branch 67 → 68 taken 8 times.
✗ Branch 67 → 82 not taken.
8 ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType);
743 8 return lhsType;
744 }
745 // Check primitive type combinations
746
1/2
✓ Branch 69 → 70 taken 3176 times.
✗ Branch 69 → 82 not taken.
3176 return validateBinaryOperation(node, CAST_OP_RULES, std::size(CAST_OP_RULES), "(cast)", lhsType, rhsType, true);
747 }
748
749 template <size_t N>
750 50381 ExprResult OpRuleManager::isOperatorOverloadingFctAvailable(ASTNode *node, const char *const fctName,
751 const std::array<ExprResult, N> &op, size_t opIdx) const {
752 static_assert(N == 1 || N == 2, "Only unary and binary operators are overloadable");
753 50381 Scope *calleeParentScope = nullptr;
754 50381 const Function *callee = nullptr;
755
14/20
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 2 → 3 taken 5911 times.
✗ Branch 2 → 124 not taken.
✓ Branch 3 → 4 taken 5911 times.
✗ Branch 3 → 124 not taken.
✓ Branch 4 → 5 taken 5911 times.
✗ Branch 4 → 124 not taken.
✓ Branch 42 → 43 taken 24251 times.
✓ Branch 42 → 46 taken 19 times.
✓ Branch 49 → 6 taken 109750 times.
✓ Branch 49 → 50 taken 5892 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 44470 times.
✗ Branch 2 → 133 not taken.
✓ Branch 3 → 4 taken 44470 times.
✗ Branch 3 → 133 not taken.
✓ Branch 4 → 5 taken 44470 times.
✗ Branch 4 → 133 not taken.
✓ Branch 49 → 50 taken 345271 times.
✓ Branch 49 → 53 taken 5366 times.
✓ Branch 56 → 6 taken 710856 times.
✓ Branch 56 → 57 taken 39104 times.
1290890 for (const auto &sourceFile : typeChecker->resourceManager.sourceFiles | std::views::values) {
756 // Check if there is a registered operator function
757
8/12
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 10 → 11 taken 109750 times.
✗ Branch 10 → 103 not taken.
✓ Branch 11 → 12 taken 109750 times.
✗ Branch 11 → 101 not taken.
✓ Branch 14 → 15 taken 85480 times.
✓ Branch 14 → 16 taken 24270 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 710856 times.
✗ Branch 10 → 110 not taken.
✓ Branch 11 → 12 taken 710856 times.
✗ Branch 11 → 108 not taken.
✓ Branch 14 → 15 taken 360219 times.
✓ Branch 14 → 16 taken 350637 times.
2461818 if (!sourceFile->getNameRegistryEntry(fctName))
758 445699 continue;
759
760 // Match callees in the global scope of this source file
761 374907 calleeParentScope = sourceFile->globalScope.get();
762
2/4
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 18 → 19 taken 24270 times.
✗ Branch 18 → 123 not taken.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 18 → 19 taken 350637 times.
✗ Branch 18 → 132 not taken.
374907 const QualType thisType(TY_DYN);
763
2/4
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 21 → 22 taken 24270 times.
✗ Branch 21 → 107 not taken.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 21 → 22 taken 350637 times.
✗ Branch 21 → 114 not taken.
749814 ArgList args(N);
764
2/4
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 24 → 25 taken 24270 times.
✗ Branch 24 → 110 not taken.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 24 → 25 taken 350637 times.
✗ Branch 24 → 117 not taken.
374907 args[0] = {typeChecker->mapLocalTypeToImportedScopeType(calleeParentScope, op[0].type), op[0].isTemporary()};
765 if constexpr (N == 2)
766
1/2
✓ Branch 31 → 32 taken 350637 times.
✗ Branch 31 → 119 not taken.
350637 args[1] = {typeChecker->mapLocalTypeToImportedScopeType(calleeParentScope, op[1].type), op[1].isTemporary()};
767
4/8
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 33 → 34 taken 24270 times.
✗ Branch 33 → 114 not taken.
✓ Branch 34 → 35 taken 24270 times.
✗ Branch 34 → 112 not taken.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 40 → 41 taken 350637 times.
✗ Branch 40 → 123 not taken.
✓ Branch 41 → 42 taken 350637 times.
✗ Branch 41 → 121 not taken.
1124721 callee = FunctionManager::match(calleeParentScope, fctName, thisType, args, {}, false, node);
768
4/4
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 38 → 39 taken 19 times.
✓ Branch 38 → 40 taken 24251 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 5366 times.
✓ Branch 45 → 47 taken 345271 times.
374907 if (callee)
769 5385 break;
770 }
771
772 // Return invalid type if the callee was not found
773
4/4
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 50 → 51 taken 5892 times.
✓ Branch 50 → 53 taken 19 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 57 → 58 taken 39104 times.
✓ Branch 57 → 60 taken 5366 times.
50381 if (!callee)
774 44996 return ExprResult(QualType(TY_INVALID));
775
2/4
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✗ Branch 53 → 54 not taken.
✓ Branch 53 → 55 taken 19 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✗ Branch 60 → 61 not taken.
✓ Branch 60 → 62 taken 5366 times.
5385 assert(calleeParentScope != nullptr);
776
777 // Save the pointer to the operator function in the AST node
778 5385 std::vector<const Function *> &opFctPointers = typeChecker->getOpFctPointers(node);
779
3/4
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✗ Branch 57 → 58 not taken.
✓ Branch 57 → 60 taken 19 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 64 → 65 taken 1147 times.
✓ Branch 64 → 67 taken 4219 times.
5385 if (opFctPointers.size() <= opIdx)
780
1/4
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✗ Branch 58 → 59 not taken.
✗ Branch 58 → 125 not taken.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 65 → 66 taken 1147 times.
✗ Branch 65 → 134 not taken.
1147 opFctPointers.resize(opIdx + 1, nullptr);
781 5385 opFctPointers.at(opIdx) = callee;
782
783 // Check if we need to request a re-visit, because the function body was not type-checked yet
784 5385 TypeChecker::requestRevisitIfRequired(callee);
785
786 // Check if the called function has sufficient visibility
787
6/8
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 62 → 63 taken 19 times.
✗ Branch 62 → 66 not taken.
✓ Branch 64 → 65 taken 16 times.
✓ Branch 64 → 66 taken 3 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 69 → 70 taken 5366 times.
✗ Branch 69 → 73 not taken.
✓ Branch 71 → 72 taken 4404 times.
✓ Branch 71 → 73 taken 962 times.
5385 const bool isImported = calleeParentScope != nullptr && calleeParentScope->isImportedBy(typeChecker->rootScope);
788 5385 const SymbolTableEntry *calleeEntry = callee->entry;
789
10/12
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 67 → 68 taken 16 times.
✓ Branch 67 → 72 taken 3 times.
✓ Branch 70 → 71 taken 1 time.
✓ Branch 70 → 72 taken 15 times.
✓ Branch 73 → 74 taken 1 time.
✓ Branch 73 → 83 taken 18 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 74 → 75 taken 4404 times.
✓ Branch 74 → 79 taken 962 times.
✗ Branch 77 → 78 not taken.
✓ Branch 77 → 79 taken 4404 times.
✗ Branch 80 → 81 not taken.
✓ Branch 80 → 90 taken 5366 times.
5385 if (isImported && !calleeEntry->getQualType().isPublic())
790
1/4
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 78 → 79 taken 1 time.
✗ Branch 78 → 126 not taken.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✗ Branch 85 → 86 not taken.
✗ Branch 85 → 135 not taken.
2 throw SemanticError(node, INSUFFICIENT_VISIBILITY,
791
3/12
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 75 → 76 taken 1 time.
✗ Branch 75 → 133 not taken.
✓ Branch 76 → 77 taken 1 time.
✗ Branch 76 → 131 not taken.
✓ Branch 77 → 78 taken 1 time.
✗ Branch 77 → 129 not taken.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✗ Branch 82 → 83 not taken.
✗ Branch 82 → 142 not taken.
✗ Branch 83 → 84 not taken.
✗ Branch 83 → 140 not taken.
✗ Branch 84 → 85 not taken.
✗ Branch 84 → 138 not taken.
2 "Overloaded operator '" + callee->getSignature() + "' has insufficient visibility");
792
793 // Procedures always have the return type 'bool'
794
4/4
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 86 → 87 taken 14 times.
✓ Branch 86 → 89 taken 4 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 93 → 94 taken 884 times.
✓ Branch 93 → 96 taken 4482 times.
5384 if (callee->isProcedure())
795 898 return ExprResult(QualType(TY_BOOL));
796 4486 const QualType &returnType = callee->returnType;
797
798 // Add anonymous symbol to keep track of dtor call, if non-trivially destructible
799 4486 SymbolTableEntry *anonymousSymbol = nullptr;
800
12/12
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<1ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 1ul> const&, unsigned long) const:
✓ Branch 90 → 91 taken 2 times.
✓ Branch 90 → 94 taken 2 times.
✓ Branch 92 → 93 taken 1 time.
✓ Branch 92 → 94 taken 1 time.
✓ Branch 95 → 96 taken 1 time.
✓ Branch 95 → 98 taken 3 times.
spice::compiler::ExprResult spice::compiler::OpRuleManager::isOperatorOverloadingFctAvailable<2ul>(spice::compiler::ASTNode*, char const*, std::array<spice::compiler::ExprResult, 2ul> const&, unsigned long) const:
✓ Branch 97 → 98 taken 621 times.
✓ Branch 97 → 101 taken 3861 times.
✓ Branch 99 → 100 taken 610 times.
✓ Branch 99 → 101 taken 11 times.
✓ Branch 102 → 103 taken 610 times.
✓ Branch 102 → 105 taken 3872 times.
4486 if (returnType.is(TY_STRUCT) && !returnType.isTriviallyDestructible(node))
801 611 anonymousSymbol = typeChecker->currentScope->symbolTable.insertAnonymous(returnType, node, opIdx);
802
803 4486 return {typeChecker->mapImportedScopeTypeToLocalType(calleeParentScope, returnType), anonymousSymbol};
804 }
805
806 10959 QualType OpRuleManager::validateUnaryOperation(const ASTNode *node, const UnaryOpRule opRules[], size_t opRulesSize,
807 const char *name, const QualType &lhs) {
808
2/2
✓ Branch 10 → 3 taken 23362 times.
✓ Branch 10 → 11 taken 2 times.
23364 for (size_t i = 0; i < opRulesSize; i++) {
809 23362 const UnaryOpRule &rule = opRules[i];
810
2/2
✓ Branch 5 → 6 taken 10957 times.
✓ Branch 5 → 9 taken 12405 times.
23362 if (std::get<0>(rule) == lhs.getSuperType())
811
1/2
✓ Branch 7 → 8 taken 10957 times.
✗ Branch 7 → 15 not taken.
10957 return QualType(std::get<1>(rule));
812 }
813
1/2
✓ Branch 12 → 13 taken 2 times.
✗ Branch 12 → 16 not taken.
2 throw getExceptionUnary(node, name, lhs);
814 }
815
816 99126 QualType OpRuleManager::validateBinaryOperation(const ASTNode *node, const BinaryOpRule opRules[], size_t opRulesSize,
817 const char *name, const QualType &lhs, const QualType &rhs,
818 bool preserveQualifiersFromLhs, const char *customMessagePrefix) {
819
2/2
✓ Branch 19 → 3 taken 985130 times.
✓ Branch 19 → 20 taken 20 times.
985150 for (size_t i = 0; i < opRulesSize; i++) {
820 985130 const BinaryOpRule &rule = opRules[i];
821
6/6
✓ Branch 5 → 6 taken 194755 times.
✓ Branch 5 → 10 taken 790375 times.
✓ Branch 8 → 9 taken 99106 times.
✓ Branch 8 → 10 taken 95649 times.
✓ Branch 11 → 12 taken 99106 times.
✓ Branch 11 → 18 taken 886024 times.
985130 if (std::get<0>(rule) == lhs.getSuperType() && std::get<1>(rule) == rhs.getSuperType()) {
822
1/2
✓ Branch 13 → 14 taken 99106 times.
✗ Branch 13 → 24 not taken.
99106 QualType resultType((std::get<2>(rule)));
823
2/2
✓ Branch 14 → 15 taken 53111 times.
✓ Branch 14 → 17 taken 45995 times.
99106 if (preserveQualifiersFromLhs)
824 53111 resultType.setQualifiers(lhs.getQualifiers());
825 99106 return resultType;
826 }
827 }
828
1/2
✓ Branch 21 → 22 taken 20 times.
✗ Branch 21 → 25 not taken.
20 throw getExceptionBinary(node, name, lhs, rhs, customMessagePrefix);
829 }
830
831 2 SemanticError OpRuleManager::getExceptionUnary(const ASTNode *node, const char *name, const QualType &lhs) {
832
6/12
✓ Branch 2 → 3 taken 2 times.
✗ Branch 2 → 35 not taken.
✓ Branch 5 → 6 taken 2 times.
✗ Branch 5 → 27 not taken.
✓ Branch 6 → 7 taken 2 times.
✗ Branch 6 → 25 not taken.
✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 23 not taken.
✓ Branch 8 → 9 taken 2 times.
✗ Branch 8 → 21 not taken.
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 19 not taken.
8 return {node, OPERATOR_WRONG_DATA_TYPE, "Cannot apply '" + std::string(name) + "' operator on type " + lhs.getName(true)};
833 }
834
835 20 SemanticError OpRuleManager::getExceptionBinary(const ASTNode *node, const char *name, const QualType &lhs, const QualType &rhs,
836 const char *messagePrefix) {
837 // Build error message
838
1/2
✓ Branch 2 → 3 taken 20 times.
✗ Branch 2 → 50 not taken.
20 std::stringstream errorMsg;
839
2/2
✓ Branch 3 → 4 taken 4 times.
✓ Branch 3 → 14 taken 16 times.
20 if (strlen(messagePrefix) != 0)
840
7/14
✓ Branch 4 → 5 taken 4 times.
✗ Branch 4 → 48 not taken.
✓ Branch 5 → 6 taken 4 times.
✗ Branch 5 → 48 not taken.
✓ Branch 6 → 7 taken 4 times.
✗ Branch 6 → 37 not taken.
✓ Branch 7 → 8 taken 4 times.
✗ Branch 7 → 35 not taken.
✓ Branch 8 → 9 taken 4 times.
✗ Branch 8 → 35 not taken.
✓ Branch 9 → 10 taken 4 times.
✗ Branch 9 → 34 not taken.
✓ Branch 10 → 11 taken 4 times.
✗ Branch 10 → 32 not taken.
4 errorMsg << messagePrefix << ". Expected " << lhs.getName(true) << " but got " << rhs.getName(true);
841 else
842
8/16
✓ Branch 14 → 15 taken 16 times.
✗ Branch 14 → 48 not taken.
✓ Branch 15 → 16 taken 16 times.
✗ Branch 15 → 48 not taken.
✓ Branch 16 → 17 taken 16 times.
✗ Branch 16 → 48 not taken.
✓ Branch 17 → 18 taken 16 times.
✗ Branch 17 → 43 not taken.
✓ Branch 18 → 19 taken 16 times.
✗ Branch 18 → 41 not taken.
✓ Branch 19 → 20 taken 16 times.
✗ Branch 19 → 41 not taken.
✓ Branch 20 → 21 taken 16 times.
✗ Branch 20 → 40 not taken.
✓ Branch 21 → 22 taken 16 times.
✗ Branch 21 → 38 not taken.
16 errorMsg << "Cannot apply '" << name << "' operator on types " << lhs.getName(true) << " and " << rhs.getName(true);
843
844 // Return the exception
845
2/4
✓ Branch 25 → 26 taken 20 times.
✗ Branch 25 → 46 not taken.
✓ Branch 26 → 27 taken 20 times.
✗ Branch 26 → 44 not taken.
60 return {node, OPERATOR_WRONG_DATA_TYPE, errorMsg.str()};
846 20 }
847
848 29 void OpRuleManager::ensureUnsafeAllowed(const ASTNode *node, const char *name, const QualType &lhs) const {
849
2/4
✓ Branch 2 → 3 taken 29 times.
✗ Branch 2 → 43 not taken.
✓ Branch 3 → 4 taken 29 times.
✗ Branch 3 → 5 not taken.
29 if (typeChecker->currentScope->doesAllowUnsafeOperations())
850 29 return;
851 // Print error message
852 const std::string lhsName = lhs.getName(true);
853 const std::string errorMsg = "Cannot apply '" + std::string(name) + "' operator on type " + lhsName +
854 " as this is an unsafe operation. Please use unsafe blocks if you know what you are doing.";
855 SOFT_ERROR_VOID(node, UNSAFE_OPERATION_IN_SAFE_CONTEXT, errorMsg)
856 }
857
858 3577 void OpRuleManager::ensureUnsafeAllowed(const ASTNode *node, const char *name, const QualType &lhs, const QualType &rhs) const {
859
3/4
✓ Branch 2 → 3 taken 3577 times.
✗ Branch 2 → 57 not taken.
✓ Branch 3 → 4 taken 3576 times.
✓ Branch 3 → 5 taken 1 time.
3577 if (typeChecker->currentScope->doesAllowUnsafeOperations())
860 3576 return;
861 // Print error message
862
1/2
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 57 not taken.
1 const std::string lhsName = lhs.getName(true);
863
1/2
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 55 not taken.
1 const std::string rhsName = rhs.getName(true);
864
6/12
✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 42 not taken.
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 40 not taken.
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 38 not taken.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 36 not taken.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 34 not taken.
✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 32 not taken.
3 const std::string errorMsg = "Cannot apply '" + std::string(name) + "' operator on types " + lhsName + " and " + rhsName +
865
1/2
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 30 not taken.
1 " as this is an unsafe operation. Please use unsafe blocks if you know what you are doing.";
866
1/2
✓ Branch 23 → 24 taken 1 time.
✗ Branch 23 → 51 not taken.
1 SOFT_ERROR_VOID(node, UNSAFE_OPERATION_IN_SAFE_CONTEXT, errorMsg)
867 1 }
868
869 89490 void OpRuleManager::ensureNoConstAssign(const ASTNode *node, const QualType &lhs, bool isDecl, bool isReturn) const {
870 // Check if we try to assign a constant value
871
10/12
✓ Branch 2 → 3 taken 89490 times.
✗ Branch 2 → 17 not taken.
✓ Branch 3 → 4 taken 89490 times.
✗ Branch 3 → 17 not taken.
✓ Branch 4 → 5 taken 9805 times.
✓ Branch 4 → 8 taken 79685 times.
✓ Branch 5 → 6 taken 202 times.
✓ Branch 5 → 8 taken 9603 times.
✓ Branch 6 → 7 taken 14 times.
✓ Branch 6 → 8 taken 188 times.
✓ Branch 9 → 10 taken 14 times.
✓ Branch 9 → 16 taken 89476 times.
89490 if (lhs.removeReferenceWrapper().isConst() && !isDecl && !isReturn) {
872
2/4
✓ Branch 10 → 11 taken 14 times.
✗ Branch 10 → 20 not taken.
✓ Branch 11 → 12 taken 14 times.
✗ Branch 11 → 18 not taken.
14 const std::string errorMessage = "Trying to assign value to an immutable variable of type " + lhs.getName(true);
873
1/2
✓ Branch 13 → 14 taken 14 times.
✗ Branch 13 → 21 not taken.
14 SOFT_ERROR_VOID(node, REASSIGN_CONST_VARIABLE, errorMessage);
874 14 }
875 }
876
877 } // namespace spice::compiler
878