GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 96.3% 469 / 0 / 487
Functions: 100.0% 52 / 0 / 52
Branches: 63.1% 801 / 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 8621 OpRuleManager::OpRuleManager(TypeChecker *typeChecker)
16 8621 : typeChecker(typeChecker), resourceManager(typeChecker->resourceManager) {}
17
18 75315 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 75315 const QualType lhsType = lhs.type;
22 75315 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 75314 times.
75315 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 75314 times.
✗ Branch 12 → 123 not taken.
✓ Branch 13 → 14 taken 580 times.
✓ Branch 13 → 16 taken 74734 times.
75314 if (lhsType.is(TY_DYN))
30 580 return {rhsType, nullptr};
31
32 // Check if we try to assign a constant value
33
1/2
✓ Branch 16 → 17 taken 74734 times.
✗ Branch 16 → 123 not taken.
74734 ensureNoConstAssign(node, lhsType, isDecl, isReturn);
34
35 // Allow pointers and references of the same type straight away
36
8/10
✓ Branch 17 → 18 taken 74734 times.
✗ Branch 17 → 113 not taken.
✓ Branch 18 → 19 taken 14725 times.
✓ Branch 18 → 22 taken 60009 times.
✓ Branch 19 → 20 taken 14725 times.
✗ Branch 19 → 113 not taken.
✓ Branch 20 → 21 taken 11920 times.
✓ Branch 20 → 22 taken 2805 times.
✓ Branch 23 → 24 taken 11920 times.
✓ Branch 23 → 41 taken 62814 times.
74734 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 4090 times.
✓ Branch 24 → 35 taken 7830 times.
✓ Branch 25 → 26 taken 4090 times.
✗ Branch 25 → 114 not taken.
✓ Branch 26 → 27 taken 2770 times.
✓ Branch 26 → 35 taken 1320 times.
✓ Branch 27 → 28 taken 2770 times.
✗ Branch 27 → 114 not taken.
✓ Branch 28 → 29 taken 1095 times.
✓ Branch 28 → 35 taken 1675 times.
✓ Branch 29 → 30 taken 1095 times.
✗ Branch 29 → 114 not taken.
✓ Branch 30 → 31 taken 1095 times.
✗ Branch 30 → 114 not taken.
✓ Branch 31 → 32 taken 1095 times.
✗ Branch 31 → 35 not taken.
✓ Branch 32 → 33 taken 1095 times.
✗ Branch 32 → 114 not taken.
✓ Branch 33 → 34 taken 1095 times.
✗ Branch 33 → 35 not taken.
✓ Branch 36 → 37 taken 1095 times.
✓ Branch 36 → 39 taken 10825 times.
11920 if (rhs.entry && lhsType.isPtr() && lhsType.isHeap() && rhsType.removeReferenceWrapper().isPtr() && rhsType.isHeap())
39
1/2
✓ Branch 37 → 38 taken 1095 times.
✗ Branch 37 → 115 not taken.
1095 rhs.entry->updateState(MOVED, node);
40 11920 return {rhsType, nullptr};
41 }
42 // Allow ref type to type of the same contained type straight away
43
3/4
✓ Branch 41 → 42 taken 62814 times.
✗ Branch 41 → 123 not taken.
✓ Branch 42 → 43 taken 1599 times.
✓ Branch 42 → 55 taken 61215 times.
62814 if (rhsType.isRef()) {
44 // If this is const ref, remove both: the reference and the constness
45
2/4
✓ Branch 43 → 44 taken 1599 times.
✗ Branch 43 → 116 not taken.
✓ Branch 44 → 45 taken 1599 times.
✗ Branch 44 → 116 not taken.
1599 const QualType rhsNonRef = rhsType.getContained().toNonConst();
46
3/4
✓ Branch 45 → 46 taken 1599 times.
✗ Branch 45 → 117 not taken.
✓ Branch 46 → 47 taken 1597 times.
✓ Branch 46 → 53 taken 2 times.
1599 if (lhsType.matches(rhsNonRef, false, false, true)) {
47
3/4
✓ Branch 47 → 48 taken 1597 times.
✗ Branch 47 → 117 not taken.
✓ Branch 48 → 49 taken 798 times.
✓ Branch 48 → 51 taken 799 times.
1597 if (rhsNonRef.is(TY_STRUCT))
48
1/2
✓ Branch 49 → 50 taken 798 times.
✗ Branch 49 → 117 not taken.
1597 return performStructAssign(node, lhs, rhs, rhsNonRef, isDecl, isReturn);
49 799 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 61217 times.
✗ Branch 55 → 118 not taken.
✓ Branch 56 → 57 taken 344 times.
✓ Branch 56 → 60 taken 60873 times.
✓ Branch 57 → 58 taken 344 times.
✗ Branch 57 → 118 not taken.
✓ Branch 58 → 59 taken 339 times.
✓ Branch 58 → 60 taken 5 times.
✓ Branch 61 → 62 taken 339 times.
✓ Branch 61 → 64 taken 60878 times.
61217 if (lhsType.isOneOf({TY_ARRAY, TY_INTERFACE, TY_FUNCTION, TY_PROCEDURE}) && lhsType.matches(rhsType, false, true, true))
54 339 return {rhsType, nullptr};
55 // Allow struct of the same type straight away
56
8/10
✓ Branch 64 → 65 taken 60878 times.
✗ Branch 64 → 123 not taken.
✓ Branch 65 → 66 taken 12206 times.
✓ Branch 65 → 69 taken 48672 times.
✓ Branch 66 → 67 taken 12206 times.
✗ Branch 66 → 123 not taken.
✓ Branch 67 → 68 taken 12205 times.
✓ Branch 67 → 69 taken 1 time.
✓ Branch 70 → 71 taken 12205 times.
✓ Branch 70 → 73 taken 48673 times.
60878 if (lhsType.is(TY_STRUCT) && lhsType.matches(rhsType, false, true, true))
57
1/2
✓ Branch 71 → 72 taken 12205 times.
✗ Branch 71 → 123 not taken.
12205 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 8501 times.
✓ Branch 74 → 88 taken 18625 times.
✓ Branch 75 → 76 taken 8501 times.
✗ Branch 75 → 119 not taken.
✓ Branch 76 → 77 taken 197 times.
✓ Branch 76 → 88 taken 8304 times.
✓ Branch 77 → 78 taken 197 times.
✗ Branch 77 → 119 not taken.
✓ Branch 78 → 79 taken 197 times.
✗ Branch 78 → 119 not taken.
✓ Branch 79 → 80 taken 7 times.
✓ Branch 79 → 88 taken 190 times.
✓ Branch 80 → 81 taken 7 times.
✗ Branch 80 → 88 not taken.
27126 if (!isDecl && !isReturn && lhsType.isRef() && lhsType.getContained().is(TY_STRUCT) && lhs.entry != nullptr &&
63
10/16
✓ Branch 73 → 74 taken 27126 times.
✓ Branch 73 → 88 taken 21547 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 48666 times.
75799 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 48664 times.
✓ Branch 94 → 123 taken 2 times.
48666 const QualType resultType = getAssignResultTypeCommon(node, lhs, rhs, isDecl, isReturn);
68
3/4
✓ Branch 95 → 96 taken 48664 times.
✗ Branch 95 → 123 not taken.
✓ Branch 96 → 97 taken 2231 times.
✓ Branch 96 → 99 taken 46433 times.
48664 if (!resultType.is(TY_INVALID))
69 2231 return {resultType, nullptr};
70
71 // Check primitive type combinations
72 46433 const QualType binOpType =
73
2/2
✓ Branch 99 → 100 taken 46420 times.
✓ Branch 99 → 123 taken 13 times.
46433 validateBinaryOperation(node, ASSIGN_OP_RULES, std::size(ASSIGN_OP_RULES), "=", lhsType, rhsType, true, errMsgPrefix);
74 46420 return {binOpType, nullptr};
75 }
76
77 1739 QualType OpRuleManager::getFieldAssignResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, bool imm,
78 bool isDecl) const {
79 // Retrieve types
80 1739 const QualType lhsType = lhs.type;
81 1739 const QualType rhsType = rhs.type;
82
2/4
✓ Branch 2 → 3 taken 1739 times.
✗ Branch 2 → 96 not taken.
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 1739 times.
1739 assert(!lhsType.is(TY_DYN));
83
84 // Check if we try to assign a constant value
85
1/2
✓ Branch 5 → 6 taken 1739 times.
✗ Branch 5 → 96 not taken.
1739 ensureNoConstAssign(node, lhsType, isDecl);
86
87 // Allow pointers, arrays and structs of the same type straight away
88
8/10
✓ Branch 6 → 7 taken 1739 times.
✗ Branch 6 → 85 not taken.
✓ Branch 7 → 8 taken 1115 times.
✓ Branch 7 → 11 taken 624 times.
✓ Branch 8 → 9 taken 1115 times.
✗ Branch 8 → 85 not taken.
✓ Branch 9 → 10 taken 1112 times.
✓ Branch 9 → 11 taken 3 times.
✓ Branch 12 → 13 taken 1112 times.
✓ Branch 12 → 29 taken 627 times.
1739 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 → 86 not taken.
✓ Branch 15 → 16 taken 262 times.
✓ Branch 15 → 24 taken 2 times.
✓ Branch 16 → 17 taken 262 times.
✗ Branch 16 → 86 not taken.
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 24 taken 262 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 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;
93 }
94 // Allow struct of the same type straight away
95
8/10
✓ Branch 29 → 30 taken 627 times.
✗ Branch 29 → 96 not taken.
✓ Branch 30 → 31 taken 58 times.
✓ Branch 30 → 34 taken 569 times.
✓ Branch 31 → 32 taken 58 times.
✗ Branch 31 → 96 not taken.
✓ Branch 32 → 33 taken 39 times.
✓ Branch 32 → 34 taken 19 times.
✓ Branch 35 → 36 taken 39 times.
✓ Branch 35 → 38 taken 588 times.
627 if (lhsType.is(TY_STRUCT) && lhsType.matches(rhsType, false, true, true))
96
1/2
✓ Branch 36 → 37 taken 39 times.
✗ Branch 36 → 88 not taken.
39 return performStructAssign(node, lhs, rhs, rhsType, isDecl, false).first;
97 // Allow ref type to type of the same contained type straight away
98
9/12
✓ Branch 38 → 39 taken 588 times.
✗ Branch 38 → 89 not taken.
✓ Branch 39 → 40 taken 63 times.
✓ Branch 39 → 44 taken 525 times.
✓ Branch 40 → 41 taken 63 times.
✗ Branch 40 → 89 not taken.
✓ Branch 41 → 42 taken 63 times.
✗ Branch 41 → 89 not taken.
✓ Branch 42 → 43 taken 1 time.
✓ Branch 42 → 44 taken 62 times.
✓ Branch 45 → 46 taken 1 time.
✓ Branch 45 → 61 taken 587 times.
588 if (rhsType.isRef() && lhsType.matches(rhsType.getContained(), false, false, true)) {
99 // Check is there is an overloaded operator function available
100
1/2
✓ Branch 46 → 47 taken 1 time.
✗ Branch 46 → 90 not taken.
1 const auto [type, _] = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_ASSIGN, {lhs, rhs}, 0);
101
2/4
✓ Branch 47 → 48 taken 1 time.
✗ Branch 47 → 92 not taken.
✗ Branch 48 → 49 not taken.
✓ Branch 48 → 50 taken 1 time.
1 if (!type.is(TY_INVALID))
102 return type;
103
104 // In case of a return expression, we perform temp stealing
105
4/10
✓ Branch 50 → 51 taken 1 time.
✗ Branch 50 → 91 not taken.
✓ Branch 51 → 52 taken 1 time.
✗ Branch 51 → 91 not taken.
✗ Branch 52 → 53 not taken.
✓ Branch 52 → 56 taken 1 time.
✗ Branch 54 → 55 not taken.
✗ Branch 54 → 56 not taken.
✗ Branch 57 → 58 not taken.
✓ Branch 57 → 59 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 ref type to type of the same contained type straight away
110
3/4
✓ Branch 61 → 62 taken 587 times.
✗ Branch 61 → 96 not taken.
✓ Branch 62 → 63 taken 62 times.
✓ Branch 62 → 70 taken 525 times.
587 if (rhsType.isRef()) {
111 // If this is const ref, remove both: the reference and the constness
112
2/4
✓ Branch 63 → 64 taken 62 times.
✗ Branch 63 → 93 not taken.
✓ Branch 64 → 65 taken 62 times.
✗ Branch 64 → 93 not taken.
62 const QualType rhsNonRef = rhsType.getContained().toNonConst();
113
2/4
✓ Branch 65 → 66 taken 62 times.
✗ Branch 65 → 95 not taken.
✓ Branch 66 → 67 taken 62 times.
✗ Branch 66 → 69 not taken.
62 if (lhsType.matches(rhsNonRef, false, false, true))
114
1/2
✓ Branch 67 → 68 taken 62 times.
✗ Branch 67 → 94 not taken.
62 return performStructAssign(node, lhs, rhs, rhsNonRef, isDecl, false).first;
115 }
116 // Allow immediate value to const ref of the same contained type straight away
117
6/8
✓ Branch 70 → 71 taken 525 times.
✗ Branch 70 → 96 not taken.
✓ Branch 71 → 72 taken 1 time.
✓ Branch 71 → 74 taken 524 times.
✓ Branch 72 → 73 taken 1 time.
✗ Branch 72 → 74 not taken.
✓ Branch 75 → 76 taken 1 time.
✓ Branch 75 → 77 taken 524 times.
525 if (lhsType.isConstRef() && imm)
118 1 return rhsType;
119
120 // Check common type combinations
121
1/2
✓ Branch 77 → 78 taken 524 times.
✗ Branch 77 → 96 not taken.
524 const QualType resultType = getAssignResultTypeCommon(node, lhs, rhs, isDecl, false);
122
3/4
✓ Branch 78 → 79 taken 524 times.
✗ Branch 78 → 96 not taken.
✓ Branch 79 → 80 taken 4 times.
✓ Branch 79 → 81 taken 520 times.
524 if (!resultType.is(TY_INVALID))
123 4 return resultType;
124
125 // Check primitive type combinations
126
2/2
✓ Branch 81 → 82 taken 519 times.
✓ Branch 81 → 96 taken 1 time.
520 return validateBinaryOperation(node, ASSIGN_OP_RULES, std::size(ASSIGN_OP_RULES), "=", lhsType, rhsType, true,
127 519 ERROR_FIELD_ASSIGN);
128 }
129
130 49190 QualType OpRuleManager::getAssignResultTypeCommon(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, bool isDecl,
131 bool isReturn) {
132 // Retrieve types
133 49190 const QualType lhsType = lhs.type;
134 49190 const QualType rhsType = rhs.type;
135
136 // Allow type to ref type of the same contained type straight away
137
9/12
✓ Branch 2 → 3 taken 49190 times.
✗ Branch 2 → 112 not taken.
✓ Branch 3 → 4 taken 1761 times.
✓ Branch 3 → 8 taken 47429 times.
✓ Branch 4 → 5 taken 1761 times.
✗ Branch 4 → 112 not taken.
✓ Branch 5 → 6 taken 1761 times.
✗ Branch 5 → 112 not taken.
✓ Branch 6 → 7 taken 1758 times.
✓ Branch 6 → 8 taken 3 times.
✓ Branch 9 → 10 taken 1758 times.
✓ Branch 9 → 44 taken 47432 times.
49190 if (lhsType.isRef() && lhsType.getContained().matches(rhsType, false, false, true)) {
138
4/4
✓ Branch 10 → 11 taken 1261 times.
✓ Branch 10 → 12 taken 497 times.
✓ Branch 11 → 12 taken 1071 times.
✓ Branch 11 → 13 taken 190 times.
1758 const bool isDeclOrReturn = isDecl || isReturn;
139
7/8
✓ Branch 14 → 15 taken 1568 times.
✓ Branch 14 → 19 taken 190 times.
✓ Branch 16 → 17 taken 1568 times.
✗ Branch 16 → 136 not taken.
✓ Branch 17 → 18 taken 1 time.
✓ Branch 17 → 19 taken 1567 times.
✓ Branch 20 → 21 taken 1 time.
✓ Branch 20 → 29 taken 1757 times.
1758 if (isDeclOrReturn && !lhsType.canBind(rhsType, rhs.isTemporary()))
140
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");
141
6/6
✓ Branch 29 → 30 taken 1071 times.
✓ Branch 29 → 33 taken 686 times.
✓ Branch 31 → 32 taken 1 time.
✓ Branch 31 → 33 taken 1070 times.
✓ Branch 34 → 35 taken 1 time.
✓ Branch 34 → 43 taken 1756 times.
1757 if (isReturn && rhs.isTemporary())
142
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");
143 1756 return lhsType;
144 }
145 // Allow char* = string
146
9/14
✓ Branch 44 → 45 taken 47432 times.
✗ Branch 44 → 136 not taken.
✓ Branch 45 → 46 taken 1 time.
✓ Branch 45 → 53 taken 47431 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 47431 times.
47432 if (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING) && lhsType.getQualifiers() == rhsType.getQualifiers())
147 1 return lhsType;
148 // Allow array to pointer
149
12/18
✓ Branch 56 → 57 taken 47431 times.
✗ Branch 56 → 131 not taken.
✓ Branch 57 → 58 taken 479 times.
✓ Branch 57 → 65 taken 46952 times.
✓ Branch 58 → 59 taken 479 times.
✗ Branch 58 → 131 not taken.
✓ Branch 59 → 60 taken 7 times.
✓ Branch 59 → 65 taken 472 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 47424 times.
47431 if (lhsType.isPtr() && rhsType.isArray() && lhsType.getContained().matches(rhsType.getContained(), false, false, true))
150 7 return lhsType;
151 // Allow interface* = struct* or interface& = struct that implements this interface
152
1/2
✓ Branch 70 → 71 taken 47424 times.
✗ Branch 70 → 136 not taken.
47424 const bool sameChainDepth = Type::hasSameTypeChainDepth(lhsType.getType(), rhsType.getType());
153
10/14
✓ Branch 71 → 72 taken 47424 times.
✗ Branch 71 → 136 not taken.
✓ Branch 72 → 73 taken 472 times.
✓ Branch 72 → 76 taken 46952 times.
✓ Branch 73 → 74 taken 472 times.
✗ Branch 73 → 136 not taken.
✓ Branch 74 → 75 taken 471 times.
✓ Branch 74 → 76 taken 1 time.
✗ Branch 75 → 76 not taken.
✓ Branch 75 → 78 taken 471 times.
✓ Branch 76 → 77 taken 46953 times.
✗ Branch 76 → 136 not taken.
✓ Branch 77 → 78 taken 3 times.
✓ Branch 77 → 79 taken 46950 times.
47424 const bool typesCompatible = (lhsType.isPtr() && rhsType.isPtr() && sameChainDepth) || lhsType.isRef();
154
9/12
✓ Branch 80 → 81 taken 474 times.
✓ Branch 80 → 86 taken 46950 times.
✓ Branch 81 → 82 taken 474 times.
✗ Branch 81 → 136 not taken.
✓ Branch 82 → 83 taken 56 times.
✓ Branch 82 → 86 taken 418 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 47368 times.
47424 if (typesCompatible && lhsType.isBase(TY_INTERFACE) && rhsType.isBase(TY_STRUCT)) {
155 56 QualType lhsTypeCopy = lhsType;
156 56 QualType rhsTypeCopy = rhsType;
157
1/2
✓ Branch 88 → 89 taken 56 times.
✗ Branch 88 → 133 not taken.
56 QualType::unwrapBothWithRefWrappers(lhsTypeCopy, rhsTypeCopy);
158
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))
159 56 return lhsType;
160 }
161 // Allow type* = heap type* straight away. This is used for initializing non-owning pointers to heap allocations
162
10/14
✓ Branch 93 → 94 taken 47368 times.
✗ Branch 93 → 136 not taken.
✓ Branch 94 → 95 taken 417 times.
✓ Branch 94 → 100 taken 46951 times.
✓ Branch 95 → 96 taken 417 times.
✗ Branch 95 → 136 not taken.
✓ Branch 96 → 97 taken 415 times.
✓ Branch 96 → 100 taken 2 times.
✓ Branch 97 → 98 taken 415 times.
✗ Branch 97 → 136 not taken.
✓ Branch 98 → 99 taken 415 times.
✗ Branch 98 → 100 not taken.
✓ Branch 101 → 102 taken 415 times.
✓ Branch 101 → 108 taken 46953 times.
47368 if (lhsType.isPtr() && rhsType.isHeap() && lhsType.matches(rhsType, false, true, true)) {
163 415 TypeQualifiers rhsQualifiers = rhsType.getQualifiers();
164 415 rhsQualifiers.isHeap = false;
165
2/4
✓ Branch 104 → 105 taken 415 times.
✗ Branch 104 → 134 not taken.
✓ Branch 105 → 106 taken 415 times.
✗ Branch 105 → 107 not taken.
415 if (lhsType.getQualifiers() == rhsQualifiers)
166 415 return lhsType;
167 }
168
169 // Nothing matched
170
1/2
✓ Branch 108 → 109 taken 46953 times.
✗ Branch 108 → 135 not taken.
46953 return QualType(TY_INVALID);
171 }
172
173 13111 std::pair<QualType, Function *> OpRuleManager::performStructAssign(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs,
174 const QualType &rhsType, bool isDecl, bool isReturn) const {
175 13111 const bool rhsIsRef = rhs.type.isRef();
176
177 // Check is there is an overloaded operator function available
178
8/8
✓ Branch 3 → 4 taken 7612 times.
✓ Branch 3 → 8 taken 5499 times.
✓ Branch 4 → 5 taken 1034 times.
✓ Branch 4 → 8 taken 6578 times.
✓ Branch 6 → 7 taken 539 times.
✓ Branch 6 → 8 taken 495 times.
✓ Branch 9 → 10 taken 539 times.
✓ Branch 9 → 16 taken 12572 times.
13111 if (!isDecl && !isReturn && lhs.entry->isInitialized()) {
179
1/2
✓ Branch 10 → 11 taken 539 times.
✗ Branch 10 → 44 not taken.
539 const auto [type, _] = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_ASSIGN, {lhs, rhs}, 0);
180
3/4
✓ Branch 11 → 12 taken 539 times.
✗ Branch 11 → 45 not taken.
✓ Branch 12 → 13 taken 400 times.
✓ Branch 12 → 15 taken 139 times.
539 if (!type.is(TY_INVALID))
181 400 return {type, nullptr};
182 }
183
184 // If temp stealing is possible, delete any rhs anonymous entry
185
6/6
✓ Branch 16 → 17 taken 12024 times.
✓ Branch 16 → 20 taken 687 times.
✓ Branch 18 → 19 taken 11272 times.
✓ Branch 18 → 20 taken 752 times.
✓ Branch 21 → 22 taken 11272 times.
✓ Branch 21 → 27 taken 1439 times.
12711 if (!rhsIsRef && rhs.isTemporary()) {
186
3/4
✓ Branch 22 → 23 taken 7975 times.
✓ Branch 22 → 25 taken 3297 times.
✓ Branch 23 → 24 taken 7975 times.
✗ Branch 23 → 25 not taken.
11272 if (rhs.entry != nullptr && rhs.entry->anonymous)
187 7975 typeChecker->currentScope->symbolTable.deleteAnonymous(rhs.entry->name);
188 11272 return {rhsType, nullptr};
189 }
190
191 // If RVO is possible, cancel here
192
7/8
✓ Branch 27 → 28 taken 752 times.
✓ Branch 27 → 32 taken 687 times.
✓ Branch 28 → 29 taken 426 times.
✓ Branch 28 → 32 taken 326 times.
✓ Branch 30 → 31 taken 426 times.
✗ Branch 30 → 32 not taken.
✓ Branch 33 → 34 taken 426 times.
✓ Branch 33 → 36 taken 1013 times.
1439 if (!rhsIsRef && isReturn && !rhs.isTemporary())
193 426 return {rhsType, nullptr};
194
195 // => We have to copy
196 // If struct, try to call copy ctor
197
2/2
✓ Branch 37 → 38 taken 970 times.
✓ Branch 37 → 41 taken 43 times.
1013 if (rhsType.is(TY_STRUCT))
198
1/2
✓ Branch 38 → 39 taken 970 times.
✗ Branch 38 → 46 not taken.
970 return {rhsType, typeChecker->implicitlyCallStructCopyCtor(rhsType, node)};
199
200 // Perform shallow copy
201 43 return {rhsType, nullptr};
202 }
203
204 1170 ExprResult OpRuleManager::getPlusEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
205 // Check is there is an overloaded operator function available
206
1/2
✓ Branch 2 → 3 taken 1170 times.
✗ Branch 2 → 22 not taken.
1170 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_PLUS_EQUAL, {lhs, rhs}, 0);
207
3/4
✓ Branch 3 → 4 taken 1170 times.
✗ Branch 3 → 24 not taken.
✓ Branch 4 → 5 taken 416 times.
✓ Branch 4 → 6 taken 754 times.
1170 if (!resultType.type.is(TY_INVALID))
208 416 return resultType;
209
210 // Check if we try to assign a constant value
211
1/2
✓ Branch 6 → 7 taken 754 times.
✗ Branch 6 → 24 not taken.
754 ensureNoConstAssign(node, lhs.type);
212
213 // Remove reference wrappers
214
1/2
✓ Branch 7 → 8 taken 754 times.
✗ Branch 7 → 24 not taken.
754 const QualType lhsType = lhs.type.removeReferenceWrapper();
215
1/2
✓ Branch 8 → 9 taken 754 times.
✗ Branch 8 → 24 not taken.
754 const QualType rhsType = rhs.type.removeReferenceWrapper();
216
217 // Check if this is an unsafe operation
218
7/10
✓ Branch 9 → 10 taken 754 times.
✗ Branch 9 → 23 not taken.
✓ Branch 10 → 11 taken 166 times.
✓ Branch 10 → 14 taken 588 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 588 times.
754 if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) {
219
1/2
✓ Branch 16 → 17 taken 166 times.
✗ Branch 16 → 24 not taken.
166 ensureUnsafeAllowed(node, "+=", lhsType, rhsType);
220 166 return lhs;
221 }
222
223
1/2
✓ Branch 18 → 19 taken 588 times.
✗ Branch 18 → 24 not taken.
588 return {validateBinaryOperation(node, PLUS_EQUAL_OP_RULES, std::size(PLUS_EQUAL_OP_RULES), "+=", lhsType, rhsType)};
224 }
225
226 81 ExprResult OpRuleManager::getMinusEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
227 // Check is there is an overloaded operator function available
228
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);
229
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))
230 7 return resultType;
231
232 // Check if we try to assign a constant value
233
1/2
✓ Branch 6 → 7 taken 74 times.
✗ Branch 6 → 24 not taken.
74 ensureNoConstAssign(node, lhs.type);
234
235 // Remove reference wrappers
236
1/2
✓ Branch 7 → 8 taken 74 times.
✗ Branch 7 → 24 not taken.
74 const QualType lhsType = lhs.type.removeReferenceWrapper();
237
1/2
✓ Branch 8 → 9 taken 74 times.
✗ Branch 8 → 24 not taken.
74 const QualType rhsType = rhs.type.removeReferenceWrapper();
238
239 // Check if this is an unsafe operation
240
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})) {
241
1/2
✓ Branch 16 → 17 taken 5 times.
✗ Branch 16 → 24 not taken.
5 ensureUnsafeAllowed(node, "-=", lhsType, rhsType);
242 5 return lhs;
243 }
244
245
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)};
246 }
247
248 170 ExprResult OpRuleManager::getMulEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
249 // Check is there is an overloaded operator function available
250
1/2
✓ Branch 2 → 3 taken 170 times.
✗ Branch 2 → 13 not taken.
170 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MUL_EQUAL, {lhs, rhs}, 0);
251
3/4
✓ Branch 3 → 4 taken 170 times.
✗ Branch 3 → 14 not taken.
✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 6 taken 168 times.
170 if (!resultType.type.is(TY_INVALID))
252 2 return resultType;
253
254 // Check if we try to assign a constant value
255
1/2
✓ Branch 6 → 7 taken 168 times.
✗ Branch 6 → 14 not taken.
168 ensureNoConstAssign(node, lhs.type);
256
257 // Remove reference wrappers
258
1/2
✓ Branch 7 → 8 taken 168 times.
✗ Branch 7 → 14 not taken.
168 const QualType lhsType = lhs.type.removeReferenceWrapper();
259
1/2
✓ Branch 8 → 9 taken 168 times.
✗ Branch 8 → 14 not taken.
168 const QualType rhsType = rhs.type.removeReferenceWrapper();
260
261
1/2
✓ Branch 9 → 10 taken 168 times.
✗ Branch 9 → 14 not taken.
168 return {validateBinaryOperation(node, MUL_EQUAL_OP_RULES, std::size(MUL_EQUAL_OP_RULES), "*=", lhsType, rhsType)};
262 }
263
264 104 ExprResult OpRuleManager::getDivEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
265 // Check is there is an overloaded operator function available
266
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);
267
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))
268 62 return resultType;
269
270 // Check if we try to assign a constant value
271
1/2
✓ Branch 6 → 7 taken 42 times.
✗ Branch 6 → 14 not taken.
42 ensureNoConstAssign(node, lhs.type);
272
273 // Remove reference wrappers
274
1/2
✓ Branch 7 → 8 taken 42 times.
✗ Branch 7 → 14 not taken.
42 const QualType lhsType = lhs.type.removeReferenceWrapper();
275
1/2
✓ Branch 8 → 9 taken 42 times.
✗ Branch 8 → 14 not taken.
42 const QualType rhsType = rhs.type.removeReferenceWrapper();
276
277
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)};
278 }
279
280 41 QualType OpRuleManager::getRemEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
281 // Check if we try to assign a constant value
282
1/2
✓ Branch 2 → 3 taken 41 times.
✗ Branch 2 → 9 not taken.
41 ensureNoConstAssign(node, lhs.type);
283
284 // Remove reference wrappers
285
1/2
✓ Branch 3 → 4 taken 41 times.
✗ Branch 3 → 9 not taken.
41 const QualType lhsType = lhs.type.removeReferenceWrapper();
286
1/2
✓ Branch 4 → 5 taken 41 times.
✗ Branch 4 → 9 not taken.
41 const QualType rhsType = rhs.type.removeReferenceWrapper();
287
288
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);
289 }
290
291 12 QualType OpRuleManager::getSHLEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
292 // Check if we try to assign a constant value
293
1/2
✓ Branch 2 → 3 taken 12 times.
✗ Branch 2 → 9 not taken.
12 ensureNoConstAssign(node, lhs.type);
294
295 // Remove reference wrappers
296
1/2
✓ Branch 3 → 4 taken 12 times.
✗ Branch 3 → 9 not taken.
12 const QualType lhsType = lhs.type.removeReferenceWrapper();
297
1/2
✓ Branch 4 → 5 taken 12 times.
✗ Branch 4 → 9 not taken.
12 const QualType rhsType = rhs.type.removeReferenceWrapper();
298
299
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);
300 }
301
302 13 QualType OpRuleManager::getSHREqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
303 // Check if we try to assign a constant value
304
1/2
✓ Branch 2 → 3 taken 13 times.
✗ Branch 2 → 9 not taken.
13 ensureNoConstAssign(node, lhs.type);
305
306 // Remove reference wrappers
307
1/2
✓ Branch 3 → 4 taken 13 times.
✗ Branch 3 → 9 not taken.
13 const QualType lhsType = lhs.type.removeReferenceWrapper();
308
1/2
✓ Branch 4 → 5 taken 13 times.
✗ Branch 4 → 9 not taken.
13 const QualType rhsType = rhs.type.removeReferenceWrapper();
309
310
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);
311 }
312
313 17 QualType OpRuleManager::getAndEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
314 // Check if we try to assign a constant value
315
1/2
✓ Branch 2 → 3 taken 17 times.
✗ Branch 2 → 9 not taken.
17 ensureNoConstAssign(node, lhs.type);
316
317 // Remove reference wrappers
318
1/2
✓ Branch 3 → 4 taken 17 times.
✗ Branch 3 → 9 not taken.
17 const QualType lhsType = lhs.type.removeReferenceWrapper();
319
1/2
✓ Branch 4 → 5 taken 17 times.
✗ Branch 4 → 9 not taken.
17 const QualType rhsType = rhs.type.removeReferenceWrapper();
320
321
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);
322 }
323
324 13 QualType OpRuleManager::getOrEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
325 // Check if we try to assign a constant value
326
1/2
✓ Branch 2 → 3 taken 13 times.
✗ Branch 2 → 9 not taken.
13 ensureNoConstAssign(node, lhs.type);
327
328 // Remove reference wrappers
329
1/2
✓ Branch 3 → 4 taken 13 times.
✗ Branch 3 → 9 not taken.
13 const QualType lhsType = lhs.type.removeReferenceWrapper();
330
1/2
✓ Branch 4 → 5 taken 13 times.
✗ Branch 4 → 9 not taken.
13 const QualType rhsType = rhs.type.removeReferenceWrapper();
331
332
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);
333 }
334
335 687 QualType OpRuleManager::getXorEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
336 // Check if we try to assign a constant value
337
1/2
✓ Branch 2 → 3 taken 687 times.
✗ Branch 2 → 9 not taken.
687 ensureNoConstAssign(node, lhs.type);
338
339 // Remove reference wrappers
340
1/2
✓ Branch 3 → 4 taken 687 times.
✗ Branch 3 → 9 not taken.
687 const QualType lhsType = lhs.type.removeReferenceWrapper();
341
1/2
✓ Branch 4 → 5 taken 687 times.
✗ Branch 4 → 9 not taken.
687 const QualType rhsType = rhs.type.removeReferenceWrapper();
342
343
1/2
✓ Branch 5 → 6 taken 687 times.
✗ Branch 5 → 9 not taken.
1374 return validateBinaryOperation(node, XOR_EQUAL_OP_RULES, std::size(XOR_EQUAL_OP_RULES), "^=", lhsType, rhsType);
344 }
345
346 2447 QualType OpRuleManager::getLogicalOrResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
347 // Remove reference wrappers
348
1/2
✓ Branch 2 → 3 taken 2447 times.
✗ Branch 2 → 8 not taken.
2447 const QualType lhsType = lhs.type.removeReferenceWrapper();
349
1/2
✓ Branch 3 → 4 taken 2447 times.
✗ Branch 3 → 8 not taken.
2447 const QualType rhsType = rhs.type.removeReferenceWrapper();
350
351
2/2
✓ Branch 4 → 5 taken 2446 times.
✓ Branch 4 → 8 taken 1 time.
4893 return validateBinaryOperation(node, LOGICAL_OR_OP_RULES, std::size(LOGICAL_OR_OP_RULES), "||", lhsType, rhsType);
352 }
353
354 1523 QualType OpRuleManager::getLogicalAndResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
355 // Remove reference wrappers
356
1/2
✓ Branch 2 → 3 taken 1523 times.
✗ Branch 2 → 8 not taken.
1523 const QualType lhsType = lhs.type.removeReferenceWrapper();
357
1/2
✓ Branch 3 → 4 taken 1523 times.
✗ Branch 3 → 8 not taken.
1523 const QualType rhsType = rhs.type.removeReferenceWrapper();
358
359
1/2
✓ Branch 4 → 5 taken 1523 times.
✗ Branch 4 → 8 not taken.
3046 return validateBinaryOperation(node, LOGICAL_AND_OP_RULES, std::size(LOGICAL_AND_OP_RULES), "&&", lhsType, rhsType);
360 }
361
362 282 ExprResult OpRuleManager::getBitwiseOrResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs,
363 size_t opIdx) const {
364 // Check if there is an overloaded operator function available
365
1/2
✓ Branch 2 → 3 taken 282 times.
✗ Branch 2 → 12 not taken.
282 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_BITWISE_OR, {lhs, rhs}, opIdx);
366
3/4
✓ Branch 3 → 4 taken 282 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 4 times.
✓ Branch 4 → 6 taken 278 times.
282 if (!resultType.type.is(TY_INVALID))
367 4 return resultType;
368
369 // Remove reference wrappers
370
1/2
✓ Branch 6 → 7 taken 278 times.
✗ Branch 6 → 13 not taken.
278 const QualType lhsType = lhs.type.removeReferenceWrapper();
371
1/2
✓ Branch 7 → 8 taken 278 times.
✗ Branch 7 → 13 not taken.
278 const QualType rhsType = rhs.type.removeReferenceWrapper();
372
373
2/2
✓ Branch 8 → 9 taken 277 times.
✓ Branch 8 → 13 taken 1 time.
278 return {validateBinaryOperation(node, BITWISE_OR_OP_RULES, std::size(BITWISE_OR_OP_RULES), "|", lhsType, rhsType)};
374 }
375
376 41 ExprResult OpRuleManager::getBitwiseXorResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs,
377 size_t opIdx) const {
378 // Check if there is an overloaded operator function available
379
1/2
✓ Branch 2 → 3 taken 41 times.
✗ Branch 2 → 12 not taken.
41 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_BITWISE_XOR, {lhs, rhs}, opIdx);
380
3/4
✓ Branch 3 → 4 taken 41 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 3 times.
✓ Branch 4 → 6 taken 38 times.
41 if (!resultType.type.is(TY_INVALID))
381 3 return resultType;
382
383 // Remove reference wrappers
384
1/2
✓ Branch 6 → 7 taken 38 times.
✗ Branch 6 → 13 not taken.
38 const QualType lhsType = lhs.type.removeReferenceWrapper();
385
1/2
✓ Branch 7 → 8 taken 38 times.
✗ Branch 7 → 13 not taken.
38 const QualType rhsType = rhs.type.removeReferenceWrapper();
386
387
1/2
✓ Branch 8 → 9 taken 38 times.
✗ Branch 8 → 13 not taken.
38 return {validateBinaryOperation(node, BITWISE_XOR_OP_RULES, std::size(BITWISE_XOR_OP_RULES), "^", lhsType, rhsType)};
388 }
389
390 73 ExprResult OpRuleManager::getBitwiseAndResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs,
391 size_t opIdx) const {
392 // Check if there is an overloaded operator function available
393
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);
394
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))
395 4 return resultType;
396
397 // Remove reference wrappers
398
1/2
✓ Branch 6 → 7 taken 69 times.
✗ Branch 6 → 13 not taken.
69 const QualType lhsType = lhs.type.removeReferenceWrapper();
399
1/2
✓ Branch 7 → 8 taken 69 times.
✗ Branch 7 → 13 not taken.
69 const QualType rhsType = rhs.type.removeReferenceWrapper();
400
401
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)};
402 }
403
404 13537 ExprResult OpRuleManager::getEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
405 // Check is there is an overloaded operator function available
406
1/2
✓ Branch 2 → 3 taken 13537 times.
✗ Branch 2 → 36 not taken.
13537 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_EQUAL, {lhs, rhs}, 0);
407
3/4
✓ Branch 3 → 4 taken 13537 times.
✗ Branch 3 → 37 not taken.
✓ Branch 4 → 5 taken 1294 times.
✓ Branch 4 → 6 taken 12243 times.
13537 if (!resultType.type.is(TY_INVALID))
408 1294 return resultType;
409
410 // Remove reference wrappers
411
1/2
✓ Branch 6 → 7 taken 12243 times.
✗ Branch 6 → 37 not taken.
12243 const QualType lhsType = lhs.type.removeReferenceWrapper();
412
1/2
✓ Branch 7 → 8 taken 12243 times.
✗ Branch 7 → 37 not taken.
12243 const QualType rhsType = rhs.type.removeReferenceWrapper();
413
414 // Allow 'pointer == unsigned long' straight away
415
10/14
✓ Branch 8 → 9 taken 12243 times.
✗ Branch 8 → 37 not taken.
✓ Branch 9 → 10 taken 2561 times.
✓ Branch 9 → 15 taken 9682 times.
✓ Branch 10 → 11 taken 2561 times.
✗ Branch 10 → 37 not taken.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 15 taken 2560 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 12242 times.
12243 if (lhsType.isPtr() && rhsType.is(TY_LONG) && rhsType.isUnsigned())
416
1/2
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 37 not taken.
1 return ExprResult(QualType(TY_BOOL));
417
418 // Allow 'string == char*' and vice versa straight away
419
11/18
✓ Branch 19 → 20 taken 12242 times.
✗ Branch 19 → 37 not taken.
✓ Branch 20 → 21 taken 348 times.
✓ Branch 20 → 23 taken 11894 times.
✓ Branch 21 → 22 taken 348 times.
✗ Branch 21 → 37 not taken.
✓ Branch 22 → 23 taken 348 times.
✗ Branch 22 → 27 not taken.
✓ Branch 23 → 24 taken 12242 times.
✗ Branch 23 → 37 not taken.
✓ Branch 24 → 25 taken 1386 times.
✓ Branch 24 → 28 taken 10856 times.
✓ Branch 25 → 26 taken 1386 times.
✗ Branch 25 → 37 not taken.
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 28 taken 1386 times.
✗ Branch 29 → 30 not taken.
✓ Branch 29 → 32 taken 12242 times.
12242 if ((lhsType.is(TY_STRING) && rhsType.isPtrTo(TY_CHAR)) || (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING)))
420 return ExprResult(QualType(TY_BOOL));
421
422 // Check primitive type combinations
423
2/2
✓ Branch 32 → 33 taken 12241 times.
✓ Branch 32 → 37 taken 1 time.
12242 return ExprResult(validateBinaryOperation(node, EQUAL_OP_RULES, std::size(EQUAL_OP_RULES), "==", lhsType, rhsType));
424 }
425
426 3566 ExprResult OpRuleManager::getNotEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const {
427 // Check is there is an overloaded operator function available
428
1/2
✓ Branch 2 → 3 taken 3566 times.
✗ Branch 2 → 36 not taken.
3566 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_NOT_EQUAL, {lhs, rhs}, 0);
429
3/4
✓ Branch 3 → 4 taken 3566 times.
✗ Branch 3 → 37 not taken.
✓ Branch 4 → 5 taken 71 times.
✓ Branch 4 → 6 taken 3495 times.
3566 if (!resultType.type.is(TY_INVALID))
430 71 return resultType;
431
432 // Remove reference wrappers
433
1/2
✓ Branch 6 → 7 taken 3495 times.
✗ Branch 6 → 37 not taken.
3495 const QualType lhsType = lhs.type.removeReferenceWrapper();
434
1/2
✓ Branch 7 → 8 taken 3495 times.
✗ Branch 7 → 37 not taken.
3495 const QualType rhsType = rhs.type.removeReferenceWrapper();
435
436 // Allow 'pointer != unsigned long' straight away
437
10/14
✓ Branch 8 → 9 taken 3495 times.
✗ Branch 8 → 37 not taken.
✓ Branch 9 → 10 taken 743 times.
✓ Branch 9 → 15 taken 2752 times.
✓ Branch 10 → 11 taken 743 times.
✗ Branch 10 → 37 not taken.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 15 taken 742 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 3494 times.
3495 if (lhsType.isPtr() && rhsType.is(TY_LONG) && rhsType.isUnsigned())
438
1/2
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 37 not taken.
1 return ExprResult(QualType(TY_BOOL));
439
440 // Allow 'string != char*' and vice versa straight away
441
13/18
✓ Branch 19 → 20 taken 3494 times.
✗ Branch 19 → 37 not taken.
✓ Branch 20 → 21 taken 16 times.
✓ Branch 20 → 23 taken 3478 times.
✓ Branch 21 → 22 taken 16 times.
✗ Branch 21 → 37 not taken.
✓ Branch 22 → 23 taken 16 times.
✗ Branch 22 → 27 not taken.
✓ Branch 23 → 24 taken 3494 times.
✗ Branch 23 → 37 not taken.
✓ Branch 24 → 25 taken 177 times.
✓ Branch 24 → 28 taken 3317 times.
✓ Branch 25 → 26 taken 177 times.
✗ Branch 25 → 37 not taken.
✓ Branch 26 → 27 taken 23 times.
✓ Branch 26 → 28 taken 154 times.
✓ Branch 29 → 30 taken 23 times.
✓ Branch 29 → 32 taken 3471 times.
3494 if ((lhsType.is(TY_STRING) && rhsType.isPtrTo(TY_CHAR)) || (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING)))
442
1/2
✓ Branch 30 → 31 taken 23 times.
✗ Branch 30 → 37 not taken.
23 return ExprResult(QualType(TY_BOOL));
443
444 // Check primitive type combinations
445
1/2
✓ Branch 32 → 33 taken 3471 times.
✗ Branch 32 → 37 not taken.
3471 return ExprResult(validateBinaryOperation(node, NOT_EQUAL_OP_RULES, std::size(NOT_EQUAL_OP_RULES), "!=", lhsType, rhsType));
446 }
447
448 4282 QualType OpRuleManager::getLessResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
449 // Remove reference wrappers
450
1/2
✓ Branch 2 → 3 taken 4282 times.
✗ Branch 2 → 8 not taken.
4282 const QualType lhsType = lhs.type.removeReferenceWrapper();
451
1/2
✓ Branch 3 → 4 taken 4282 times.
✗ Branch 3 → 8 not taken.
4282 const QualType rhsType = rhs.type.removeReferenceWrapper();
452
453
1/2
✓ Branch 4 → 5 taken 4282 times.
✗ Branch 4 → 8 not taken.
8564 return validateBinaryOperation(node, LESS_OP_RULES, std::size(LESS_OP_RULES), "<", lhsType, rhsType);
454 }
455
456 1715 QualType OpRuleManager::getGreaterResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
457 // Remove reference wrappers
458
1/2
✓ Branch 2 → 3 taken 1715 times.
✗ Branch 2 → 8 not taken.
1715 const QualType lhsType = lhs.type.removeReferenceWrapper();
459
1/2
✓ Branch 3 → 4 taken 1715 times.
✗ Branch 3 → 8 not taken.
1715 const QualType rhsType = rhs.type.removeReferenceWrapper();
460
461
2/2
✓ Branch 4 → 5 taken 1714 times.
✓ Branch 4 → 8 taken 1 time.
3429 return validateBinaryOperation(node, GREATER_OP_RULES, std::size(GREATER_OP_RULES), ">", lhsType, rhsType);
462 }
463
464 1222 QualType OpRuleManager::getLessEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
465 // Remove reference wrappers
466
1/2
✓ Branch 2 → 3 taken 1222 times.
✗ Branch 2 → 8 not taken.
1222 const QualType lhsType = lhs.type.removeReferenceWrapper();
467
1/2
✓ Branch 3 → 4 taken 1222 times.
✗ Branch 3 → 8 not taken.
1222 const QualType rhsType = rhs.type.removeReferenceWrapper();
468
469
1/2
✓ Branch 4 → 5 taken 1222 times.
✗ Branch 4 → 8 not taken.
2444 return validateBinaryOperation(node, LESS_EQUAL_OP_RULES, std::size(LESS_EQUAL_OP_RULES), "<=", lhsType, rhsType);
470 }
471
472 2016 QualType OpRuleManager::getGreaterEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
473 // Remove reference wrappers
474
1/2
✓ Branch 2 → 3 taken 2016 times.
✗ Branch 2 → 18 not taken.
2016 const QualType lhsType = lhs.type.removeReferenceWrapper();
475
1/2
✓ Branch 3 → 4 taken 2016 times.
✗ Branch 3 → 18 not taken.
2016 const QualType rhsType = rhs.type.removeReferenceWrapper();
476
477 // Allow 'pointer == pointer' straight away
478
7/10
✓ Branch 4 → 5 taken 2016 times.
✗ Branch 4 → 18 not taken.
✓ Branch 5 → 6 taken 4 times.
✓ Branch 5 → 9 taken 2012 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 2012 times.
2016 if (lhsType.isPtr() && rhsType.isPtr())
479
1/2
✓ Branch 11 → 12 taken 4 times.
✗ Branch 11 → 17 not taken.
4 return QualType(TY_BOOL);
480
481
1/2
✓ Branch 13 → 14 taken 2012 times.
✗ Branch 13 → 18 not taken.
2012 return validateBinaryOperation(node, GREATER_EQUAL_OP_RULES, std::size(GREATER_EQUAL_OP_RULES), ">=", lhsType, rhsType);
482 }
483
484 2098 ExprResult OpRuleManager::getShiftLeftResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs,
485 size_t opIdx) const {
486 // Check is there is an overloaded operator function available
487
1/2
✓ Branch 2 → 3 taken 2098 times.
✗ Branch 2 → 12 not taken.
2098 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_SHL, {lhs, rhs}, opIdx);
488
3/4
✓ Branch 3 → 4 taken 2098 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 2048 times.
✓ Branch 4 → 6 taken 50 times.
2098 if (!resultType.type.is(TY_INVALID))
489 2048 return resultType;
490
491 // Remove reference wrappers
492
1/2
✓ Branch 6 → 7 taken 50 times.
✗ Branch 6 → 13 not taken.
50 const QualType lhsType = lhs.type.removeReferenceWrapper();
493
1/2
✓ Branch 7 → 8 taken 50 times.
✗ Branch 7 → 13 not taken.
50 const QualType rhsType = rhs.type.removeReferenceWrapper();
494
495
1/2
✓ Branch 8 → 9 taken 50 times.
✗ Branch 8 → 13 not taken.
50 return {validateBinaryOperation(node, SHIFT_LEFT_OP_RULES, std::size(SHIFT_LEFT_OP_RULES), "<<", lhsType, rhsType)};
496 }
497
498 189 ExprResult OpRuleManager::getShiftRightResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs,
499 size_t opIdx) const {
500 // Check is there is an overloaded operator function available
501
1/2
✓ Branch 2 → 3 taken 189 times.
✗ Branch 2 → 12 not taken.
189 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_SHR, {lhs, rhs}, opIdx);
502
3/4
✓ Branch 3 → 4 taken 189 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 188 times.
189 if (!resultType.type.is(TY_INVALID))
503 1 return resultType;
504
505 // Remove reference wrappers
506
1/2
✓ Branch 6 → 7 taken 188 times.
✗ Branch 6 → 13 not taken.
188 const QualType lhsType = lhs.type.removeReferenceWrapper();
507
1/2
✓ Branch 7 → 8 taken 188 times.
✗ Branch 7 → 13 not taken.
188 const QualType rhsType = rhs.type.removeReferenceWrapper();
508
509
1/2
✓ Branch 8 → 9 taken 188 times.
✗ Branch 8 → 13 not taken.
188 return {validateBinaryOperation(node, SHIFT_RIGHT_OP_RULES, std::size(SHIFT_RIGHT_OP_RULES), ">>", lhsType, rhsType)};
510 }
511
512 6782 ExprResult OpRuleManager::getPlusResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const {
513 // Check is there is an overloaded operator function available
514
1/2
✓ Branch 2 → 3 taken 6782 times.
✗ Branch 2 → 30 not taken.
6782 const ExprResult result = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_PLUS, {lhs, rhs}, opIdx);
515
3/4
✓ Branch 3 → 4 taken 6782 times.
✗ Branch 3 → 33 not taken.
✓ Branch 4 → 5 taken 593 times.
✓ Branch 4 → 6 taken 6189 times.
6782 if (!result.type.is(TY_INVALID))
516 593 return result;
517
518 // Remove reference wrappers
519
1/2
✓ Branch 6 → 7 taken 6189 times.
✗ Branch 6 → 33 not taken.
6189 const QualType lhsType = lhs.type.removeReferenceWrapper();
520
1/2
✓ Branch 7 → 8 taken 6189 times.
✗ Branch 7 → 33 not taken.
6189 const QualType rhsType = rhs.type.removeReferenceWrapper();
521
522 // Allow any* + <int/long/short>
523
7/10
✓ Branch 8 → 9 taken 6189 times.
✗ Branch 8 → 31 not taken.
✓ Branch 9 → 10 taken 927 times.
✓ Branch 9 → 13 taken 5262 times.
✓ Branch 10 → 11 taken 927 times.
✗ Branch 10 → 31 not taken.
✓ Branch 11 → 12 taken 927 times.
✗ Branch 11 → 13 not taken.
✓ Branch 14 → 15 taken 927 times.
✓ Branch 14 → 17 taken 5262 times.
6189 if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) {
524
1/2
✓ Branch 15 → 16 taken 927 times.
✗ Branch 15 → 33 not taken.
927 ensureUnsafeAllowed(node, "+", lhsType, rhsType);
525 927 return {lhsType};
526 }
527 // Allow <int/long/short> + any*
528
6/10
✓ Branch 17 → 18 taken 5262 times.
✗ Branch 17 → 32 not taken.
✓ Branch 18 → 19 taken 4862 times.
✓ Branch 18 → 22 taken 400 times.
✓ Branch 19 → 20 taken 4862 times.
✗ Branch 19 → 32 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 4862 times.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 26 taken 5262 times.
5262 if (lhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT}) && rhsType.isPtr()) {
529 ensureUnsafeAllowed(node, "+", lhsType, rhsType);
530 return {rhsType};
531 }
532
533
2/2
✓ Branch 26 → 27 taken 5261 times.
✓ Branch 26 → 33 taken 1 time.
5262 return {validateBinaryOperation(node, PLUS_OP_RULES, std::size(PLUS_OP_RULES), "+", lhsType, rhsType)};
534 }
535
536 3828 ExprResult OpRuleManager::getMinusResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const {
537 // Check is there is an overloaded operator function available
538
1/2
✓ Branch 2 → 3 taken 3828 times.
✗ Branch 2 → 21 not taken.
3828 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MINUS, {lhs, rhs}, opIdx);
539
3/4
✓ Branch 3 → 4 taken 3828 times.
✗ Branch 3 → 23 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 3827 times.
3828 if (!resultType.type.is(TY_INVALID))
540 1 return resultType;
541
542 // Remove reference wrappers
543
1/2
✓ Branch 6 → 7 taken 3827 times.
✗ Branch 6 → 23 not taken.
3827 const QualType lhsType = lhs.type.removeReferenceWrapper();
544
1/2
✓ Branch 7 → 8 taken 3827 times.
✗ Branch 7 → 23 not taken.
3827 const QualType rhsType = rhs.type.removeReferenceWrapper();
545
546 // Allow any* - <int/long/short>
547
7/10
✓ Branch 8 → 9 taken 3827 times.
✗ Branch 8 → 22 not taken.
✓ Branch 9 → 10 taken 3 times.
✓ Branch 9 → 13 taken 3824 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 3824 times.
3827 if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) {
548
1/2
✓ Branch 15 → 16 taken 3 times.
✗ Branch 15 → 23 not taken.
3 ensureUnsafeAllowed(node, "-", lhsType, rhsType);
549 3 return lhs;
550 }
551
552
1/2
✓ Branch 17 → 18 taken 3824 times.
✗ Branch 17 → 23 not taken.
3824 return {validateBinaryOperation(node, MINUS_OP_RULES, std::size(MINUS_OP_RULES), "-", lhsType, rhsType)};
553 }
554
555 2343 ExprResult OpRuleManager::getMulResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const {
556 // Check is there is an overloaded operator function available
557
1/2
✓ Branch 2 → 3 taken 2343 times.
✗ Branch 2 → 12 not taken.
2343 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MUL, {lhs, rhs}, opIdx);
558
3/4
✓ Branch 3 → 4 taken 2343 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 9 times.
✓ Branch 4 → 6 taken 2334 times.
2343 if (!resultType.type.is(TY_INVALID))
559 9 return resultType;
560
561 // Remove reference wrappers
562
1/2
✓ Branch 6 → 7 taken 2334 times.
✗ Branch 6 → 13 not taken.
2334 const QualType lhsType = lhs.type.removeReferenceWrapper();
563
1/2
✓ Branch 7 → 8 taken 2334 times.
✗ Branch 7 → 13 not taken.
2334 const QualType rhsType = rhs.type.removeReferenceWrapper();
564
565
2/2
✓ Branch 8 → 9 taken 2333 times.
✓ Branch 8 → 13 taken 1 time.
2334 return {validateBinaryOperation(node, MUL_OP_RULES, std::size(MUL_OP_RULES), "*", lhsType, rhsType)};
566 }
567
568 518 ExprResult OpRuleManager::getDivResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) const {
569 // Check is there is an overloaded operator function available
570
1/2
✓ Branch 2 → 3 taken 518 times.
✗ Branch 2 → 12 not taken.
518 const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_DIV, {lhs, rhs}, opIdx);
571
3/4
✓ Branch 3 → 4 taken 518 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 5 times.
✓ Branch 4 → 6 taken 513 times.
518 if (!resultType.type.is(TY_INVALID))
572 5 return resultType;
573
574 // Remove reference wrappers
575
1/2
✓ Branch 6 → 7 taken 513 times.
✗ Branch 6 → 13 not taken.
513 const QualType lhsType = lhs.type.removeReferenceWrapper();
576
1/2
✓ Branch 7 → 8 taken 513 times.
✗ Branch 7 → 13 not taken.
513 const QualType rhsType = rhs.type.removeReferenceWrapper();
577
578
1/2
✓ Branch 8 → 9 taken 513 times.
✗ Branch 8 → 13 not taken.
513 return {validateBinaryOperation(node, DIV_OP_RULES, std::size(DIV_OP_RULES), "/", lhsType, rhsType)};
579 }
580
581 128 ExprResult OpRuleManager::getRemResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) {
582 // Remove reference wrappers
583
1/2
✓ Branch 2 → 3 taken 128 times.
✗ Branch 2 → 7 not taken.
128 const QualType lhsType = lhs.type.removeReferenceWrapper();
584
1/2
✓ Branch 3 → 4 taken 128 times.
✗ Branch 3 → 7 not taken.
128 const QualType rhsType = rhs.type.removeReferenceWrapper();
585
586
1/2
✓ Branch 4 → 5 taken 128 times.
✗ Branch 4 → 7 not taken.
128 return {validateBinaryOperation(node, REM_OP_RULES, std::size(REM_OP_RULES), "%", lhsType, rhsType)};
587 }
588
589 1004 QualType OpRuleManager::getPrefixMinusResultType(const ASTNode *node, const ExprResult &lhs) {
590 // Remove reference wrappers
591
1/2
✓ Branch 2 → 3 taken 1004 times.
✗ Branch 2 → 7 not taken.
1004 const QualType lhsType = lhs.type.removeReferenceWrapper();
592
593
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);
594 }
595
596 88 QualType OpRuleManager::getPrefixPlusPlusResultType(const ASTNode *node, const ExprResult &lhs) const {
597 // Check if we try to assign a constant value
598
1/2
✓ Branch 2 → 3 taken 88 times.
✗ Branch 2 → 12 not taken.
88 ensureNoConstAssign(node, lhs.type);
599
600 // Remove reference wrappers
601
1/2
✓ Branch 3 → 4 taken 88 times.
✗ Branch 3 → 12 not taken.
88 const QualType lhsType = lhs.type.removeReferenceWrapper();
602
603 // Check if this is an unsafe operation
604
2/4
✓ Branch 4 → 5 taken 88 times.
✗ Branch 4 → 12 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 88 times.
88 if (lhsType.isPtr()) {
605 ensureUnsafeAllowed(node, "++", lhsType);
606 return lhsType;
607 }
608
609
1/2
✓ Branch 8 → 9 taken 88 times.
✗ Branch 8 → 12 not taken.
88 return validateUnaryOperation(node, PREFIX_PLUS_PLUS_OP_RULES, std::size(PREFIX_PLUS_PLUS_OP_RULES), "++", lhsType);
610 }
611
612 16 QualType OpRuleManager::getPrefixMinusMinusResultType(const ASTNode *node, const ExprResult &lhs) const {
613 // Check if we try to assign a constant value
614
1/2
✓ Branch 2 → 3 taken 16 times.
✗ Branch 2 → 12 not taken.
16 ensureNoConstAssign(node, lhs.type);
615
616 // Remove reference wrappers
617
1/2
✓ Branch 3 → 4 taken 16 times.
✗ Branch 3 → 12 not taken.
16 const QualType lhsType = lhs.type.removeReferenceWrapper();
618
619 // Check if this is an unsafe operation
620
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()) {
621 ensureUnsafeAllowed(node, "--", lhsType);
622 return lhsType;
623 }
624
625
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);
626 }
627
628 3552 QualType OpRuleManager::getPrefixNotResultType(const ASTNode *node, const ExprResult &lhs) {
629 // Remove reference wrappers
630
1/2
✓ Branch 2 → 3 taken 3552 times.
✗ Branch 2 → 7 not taken.
3552 const QualType lhsType = lhs.type.removeReferenceWrapper();
631
632
1/2
✓ Branch 3 → 4 taken 3552 times.
✗ Branch 3 → 7 not taken.
7104 return validateUnaryOperation(node, PREFIX_NOT_OP_RULES, std::size(PREFIX_NOT_OP_RULES), "!", lhsType);
633 }
634
635 12 ExprResult OpRuleManager::getPrefixBitwiseNotResultType(ASTNode *node, const ExprResult &lhs) const {
636 // Check if there is an overloaded operator function available
637
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);
638
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))
639 2 return resultType;
640
641 // Remove reference wrappers
642
1/2
✓ Branch 6 → 7 taken 10 times.
✗ Branch 6 → 12 not taken.
10 const QualType lhsType = lhs.type.removeReferenceWrapper();
643
644
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)};
645 }
646
647 920 QualType OpRuleManager::getPrefixMulResultType(const ASTNode *node, const ExprResult &lhs) {
648 // Remove reference wrappers
649
1/2
✓ Branch 2 → 3 taken 920 times.
✗ Branch 2 → 25 not taken.
920 const QualType lhsType = lhs.type.removeReferenceWrapper();
650
651
3/4
✓ Branch 3 → 4 taken 920 times.
✗ Branch 3 → 25 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 12 taken 919 times.
920 if (!lhsType.isPtr())
652
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));
653
1/2
✓ Branch 12 → 13 taken 919 times.
✗ Branch 12 → 25 not taken.
1838 return lhsType.getContained();
654 }
655
656 770 QualType OpRuleManager::getPrefixBitwiseAndResultType(const ASTNode *node, const ExprResult &lhs) {
657 // Remove reference wrappers
658
1/2
✓ Branch 2 → 3 taken 770 times.
✗ Branch 2 → 7 not taken.
770 const QualType lhsType = lhs.type.removeReferenceWrapper();
659
660
1/2
✓ Branch 3 → 4 taken 770 times.
✗ Branch 3 → 7 not taken.
1540 return lhsType.toPtr(node);
661 }
662
663 4628 ExprResult OpRuleManager::getPostfixPlusPlusResultType(ASTNode *node, const ExprResult &lhs) const {
664 // Check is there is an overloaded operator function available
665
2/2
✓ Branch 2 → 3 taken 4627 times.
✓ Branch 2 → 16 taken 1 time.
4628 const ExprResult resultType = isOperatorOverloadingFctAvailable<1>(node, OP_FCT_POSTFIX_PLUS_PLUS, {lhs}, 0);
666
3/4
✓ Branch 3 → 4 taken 4627 times.
✗ Branch 3 → 17 not taken.
✓ Branch 4 → 5 taken 9 times.
✓ Branch 4 → 6 taken 4618 times.
4627 if (!resultType.type.is(TY_INVALID))
667 9 return resultType;
668
669 // Check if we try to assign a constant value
670
1/2
✓ Branch 6 → 7 taken 4618 times.
✗ Branch 6 → 17 not taken.
4618 ensureNoConstAssign(node, lhs.type);
671
672 // Remove reference wrappers
673
1/2
✓ Branch 7 → 8 taken 4618 times.
✗ Branch 7 → 17 not taken.
4618 const QualType lhsType = lhs.type.removeReferenceWrapper();
674
675 // Check if this is an unsafe operation
676
3/4
✓ Branch 8 → 9 taken 4618 times.
✗ Branch 8 → 17 not taken.
✓ Branch 9 → 10 taken 25 times.
✓ Branch 9 → 12 taken 4593 times.
4618 if (lhsType.isPtr()) {
677
1/2
✓ Branch 10 → 11 taken 25 times.
✗ Branch 10 → 17 not taken.
25 ensureUnsafeAllowed(node, "++", lhsType);
678 25 return lhs;
679 }
680
681
2/2
✓ Branch 12 → 13 taken 4592 times.
✓ Branch 12 → 17 taken 1 time.
4593 return {validateUnaryOperation(node, POSTFIX_PLUS_PLUS_OP_RULES, std::size(POSTFIX_PLUS_PLUS_OP_RULES), "++", lhsType)};
682 }
683
684 451 ExprResult OpRuleManager::getPostfixMinusMinusResultType(ASTNode *node, const ExprResult &lhs) const {
685 // Check is there is an overloaded operator function available
686
1/2
✓ Branch 2 → 3 taken 451 times.
✗ Branch 2 → 16 not taken.
451 const ExprResult resultType = isOperatorOverloadingFctAvailable<1>(node, OP_FCT_POSTFIX_MINUS_MINUS, {lhs}, 0);
687
3/4
✓ Branch 3 → 4 taken 451 times.
✗ Branch 3 → 17 not taken.
✓ Branch 4 → 5 taken 7 times.
✓ Branch 4 → 6 taken 444 times.
451 if (!resultType.type.is(TY_INVALID))
688 7 return resultType;
689
690 // Check if we try to assign a constant value
691
1/2
✓ Branch 6 → 7 taken 444 times.
✗ Branch 6 → 17 not taken.
444 ensureNoConstAssign(node, lhs.type);
692
693 // Remove reference wrappers
694
1/2
✓ Branch 7 → 8 taken 444 times.
✗ Branch 7 → 17 not taken.
444 const QualType lhsType = lhs.type.removeReferenceWrapper();
695
696 // Check if this is an unsafe operation
697
3/4
✓ Branch 8 → 9 taken 444 times.
✗ Branch 8 → 17 not taken.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 12 taken 442 times.
444 if (lhsType.isPtr()) {
698
1/2
✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 17 not taken.
2 ensureUnsafeAllowed(node, "--", lhsType);
699 2 return lhs;
700 }
701
702
1/2
✓ Branch 12 → 13 taken 442 times.
✗ Branch 12 → 17 not taken.
442 return {validateUnaryOperation(node, POSTFIX_MINUS_MINUS_OP_RULES, std::size(POSTFIX_MINUS_MINUS_OP_RULES), "--", lhsType)};
703 }
704
705 8158 QualType OpRuleManager::getCastResultType(const ASTNode *node, QualType lhsType, const ExprResult &rhs) const {
706 // Remove reference wrappers
707
1/2
✓ Branch 2 → 3 taken 8158 times.
✗ Branch 2 → 73 not taken.
8158 lhsType = lhsType.removeReferenceWrapper();
708
1/2
✓ Branch 3 → 4 taken 8158 times.
✗ Branch 3 → 82 not taken.
8158 QualType rhsType = rhs.type.removeReferenceWrapper();
709
710 // Only allow to cast the 'heap' qualifier away, if we are in unsafe mode
711
2/2
✓ Branch 6 → 7 taken 348 times.
✓ Branch 6 → 8 taken 7810 times.
8158 if (lhsType.getQualifiers().isHeap != rhsType.getQualifiers().isHeap)
712
1/2
✓ Branch 7 → 8 taken 348 times.
✗ Branch 7 → 82 not taken.
348 ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType);
713
714 // Allow identity casts
715
3/4
✓ Branch 8 → 9 taken 8158 times.
✗ Branch 8 → 82 not taken.
✓ Branch 9 → 10 taken 882 times.
✓ Branch 9 → 11 taken 7276 times.
8158 if (lhsType.matches(rhsType, false, true, true))
716 882 return lhsType;
717 // Allow casts string -> char* and string -> char[]
718
12/16
✓ Branch 11 → 12 taken 7276 times.
✗ Branch 11 → 74 not taken.
✓ Branch 12 → 13 taken 4149 times.
✓ Branch 12 → 19 taken 3127 times.
✓ Branch 13 → 14 taken 4149 times.
✗ Branch 13 → 74 not taken.
✓ Branch 14 → 15 taken 4149 times.
✗ Branch 14 → 74 not taken.
✓ Branch 15 → 16 taken 1661 times.
✓ Branch 15 → 19 taken 2488 times.
✓ Branch 16 → 17 taken 1661 times.
✗ Branch 16 → 74 not taken.
✓ Branch 17 → 18 taken 1654 times.
✓ Branch 17 → 19 taken 7 times.
✓ Branch 20 → 21 taken 1654 times.
✓ Branch 20 → 22 taken 5622 times.
7276 if (lhsType.isOneOf({TY_PTR, TY_ARRAY}) && lhsType.getContained().is(TY_CHAR) && rhsType.is(TY_STRING))
719 1654 return lhsType;
720 // Allow casts char* -> string and char[] -> string
721
10/16
✓ Branch 22 → 23 taken 5622 times.
✗ Branch 22 → 76 not taken.
✓ Branch 23 → 24 taken 156 times.
✓ Branch 23 → 30 taken 5466 times.
✓ Branch 24 → 25 taken 156 times.
✗ Branch 24 → 76 not taken.
✓ Branch 25 → 26 taken 156 times.
✗ Branch 25 → 30 not taken.
✓ Branch 26 → 27 taken 156 times.
✗ Branch 26 → 76 not taken.
✓ Branch 27 → 28 taken 156 times.
✗ Branch 27 → 76 not taken.
✓ Branch 28 → 29 taken 156 times.
✗ Branch 28 → 30 not taken.
✓ Branch 31 → 32 taken 156 times.
✓ Branch 31 → 33 taken 5466 times.
5622 if (lhsType.is(TY_STRING) && rhsType.isOneOf({TY_PTR, TY_ARRAY}) && rhsType.getContained().is(TY_CHAR))
722 156 return lhsType;
723 // Allow safe upcasts baseStruct* <- derivedStruct* and interface* <- struct* without requiring an unsafe
724 // block. These are the only struct-pointer casts where the target subobject is guaranteed to be present;
725 // the IR generator advances the pointer to that subobject (past any vtable prefix). The reverse direction
726 // (down/sibling casts) is not covered here and still falls through to the unsafe any* -> any* rule below.
727
8/10
✓ Branch 33 → 34 taken 5466 times.
✗ Branch 33 → 82 not taken.
✓ Branch 34 → 35 taken 2495 times.
✓ Branch 34 → 38 taken 2971 times.
✓ Branch 35 → 36 taken 2495 times.
✗ Branch 35 → 82 not taken.
✓ Branch 36 → 37 taken 2487 times.
✓ Branch 36 → 38 taken 8 times.
✓ Branch 39 → 40 taken 2487 times.
✓ Branch 39 → 51 taken 2979 times.
5466 if (lhsType.isPtr() && rhsType.isPtr()) {
728
1/2
✓ Branch 40 → 41 taken 2487 times.
✗ Branch 40 → 78 not taken.
2487 const QualType lhsContained = lhsType.getContained();
729
1/2
✓ Branch 41 → 42 taken 2487 times.
✗ Branch 41 → 78 not taken.
2487 const QualType rhsContained = rhsType.getContained();
730
8/10
✓ Branch 42 → 43 taken 2487 times.
✗ Branch 42 → 78 not taken.
✓ Branch 43 → 44 taken 2480 times.
✓ Branch 43 → 46 taken 7 times.
✓ Branch 44 → 45 taken 2480 times.
✗ Branch 44 → 78 not taken.
✓ Branch 45 → 46 taken 462 times.
✓ Branch 45 → 47 taken 2018 times.
✓ Branch 48 → 49 taken 469 times.
✓ Branch 48 → 50 taken 2018 times.
2487 if (lhsContained.matchesInterfaceImplementedByStruct(rhsContained) || lhsContained.matchesComposedBaseOfStruct(rhsContained))
731 469 return lhsType;
732 }
733 // Allow casts any* -> any*
734
8/10
✓ Branch 51 → 52 taken 4997 times.
✗ Branch 51 → 79 not taken.
✓ Branch 52 → 53 taken 2026 times.
✓ Branch 52 → 56 taken 2971 times.
✓ Branch 53 → 54 taken 2026 times.
✗ Branch 53 → 79 not taken.
✓ Branch 54 → 55 taken 2018 times.
✓ Branch 54 → 56 taken 8 times.
✓ Branch 57 → 58 taken 2018 times.
✓ Branch 57 → 60 taken 2979 times.
4997 if (lhsType.isOneOf({TY_PTR, TY_STRING}) && rhsType.isOneOf({TY_PTR, TY_STRING})) {
735
1/2
✓ Branch 58 → 59 taken 2018 times.
✗ Branch 58 → 82 not taken.
2018 ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType);
736 2018 return lhsType;
737 }
738 // Allow casts p()/f<>() -> byte*
739
7/10
✓ Branch 60 → 61 taken 2979 times.
✗ Branch 60 → 81 not taken.
✓ Branch 61 → 62 taken 8 times.
✓ Branch 61 → 65 taken 2971 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 2971 times.
2979 if (lhsType.isPtrTo(TY_BYTE) && rhsType.isOneOf({TY_FUNCTION, TY_PROCEDURE})) {
740
1/2
✓ Branch 67 → 68 taken 8 times.
✗ Branch 67 → 82 not taken.
8 ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType);
741 8 return lhsType;
742 }
743 // Check primitive type combinations
744
1/2
✓ Branch 69 → 70 taken 2971 times.
✗ Branch 69 → 82 not taken.
2971 return validateBinaryOperation(node, CAST_OP_RULES, std::size(CAST_OP_RULES), "(cast)", lhsType, rhsType, true);
745 }
746
747 template <size_t N>
748 47242 ExprResult OpRuleManager::isOperatorOverloadingFctAvailable(ASTNode *node, const char *const fctName,
749 const std::array<ExprResult, N> &op, size_t opIdx) const {
750 static_assert(N == 1 || N == 2, "Only unary and binary operators are overloadable");
751 47242 Scope *calleeParentScope = nullptr;
752 47242 const Function *callee = nullptr;
753
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 5091 times.
✗ Branch 2 → 124 not taken.
✓ Branch 3 → 4 taken 5091 times.
✗ Branch 3 → 124 not taken.
✓ Branch 4 → 5 taken 5091 times.
✗ Branch 4 → 124 not taken.
✓ Branch 42 → 43 taken 17871 times.
✓ Branch 42 → 46 taken 19 times.
✓ Branch 49 → 6 taken 86533 times.
✓ Branch 49 → 50 taken 5072 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 42151 times.
✗ Branch 2 → 133 not taken.
✓ Branch 3 → 4 taken 42151 times.
✗ Branch 3 → 133 not taken.
✓ Branch 4 → 5 taken 42151 times.
✗ Branch 4 → 133 not taken.
✓ Branch 49 → 50 taken 317447 times.
✓ Branch 49 → 53 taken 5342 times.
✓ Branch 56 → 6 taken 673553 times.
✓ Branch 56 → 57 taken 36809 times.
1189888 for (const auto &sourceFile : typeChecker->resourceManager.sourceFiles | std::views::values) {
754 // Check if there is a registered operator function
755
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 86533 times.
✗ Branch 10 → 103 not taken.
✓ Branch 11 → 12 taken 86533 times.
✗ Branch 11 → 101 not taken.
✓ Branch 14 → 15 taken 68643 times.
✓ Branch 14 → 16 taken 17890 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 673553 times.
✗ Branch 10 → 110 not taken.
✓ Branch 11 → 12 taken 673553 times.
✗ Branch 11 → 108 not taken.
✓ Branch 14 → 15 taken 350764 times.
✓ Branch 14 → 16 taken 322789 times.
2280258 if (!sourceFile->getNameRegistryEntry(fctName))
756 419407 continue;
757
758 // Match callees in the global scope of this source file
759 340679 calleeParentScope = sourceFile->globalScope.get();
760
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 17890 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 322789 times.
✗ Branch 18 → 132 not taken.
340679 const QualType thisType(TY_DYN);
761
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 17890 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 322789 times.
✗ Branch 21 → 114 not taken.
681358 ArgList args(N);
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 24 → 25 taken 17890 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 322789 times.
✗ Branch 24 → 117 not taken.
340679 args[0] = {typeChecker->mapLocalTypeToImportedScopeType(calleeParentScope, op[0].type), op[0].isTemporary()};
763 if constexpr (N == 2)
764
1/2
✓ Branch 31 → 32 taken 322789 times.
✗ Branch 31 → 119 not taken.
322789 args[1] = {typeChecker->mapLocalTypeToImportedScopeType(calleeParentScope, op[1].type), op[1].isTemporary()};
765
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 17890 times.
✗ Branch 33 → 114 not taken.
✓ Branch 34 → 35 taken 17890 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 322789 times.
✗ Branch 40 → 123 not taken.
✓ Branch 41 → 42 taken 322789 times.
✗ Branch 41 → 121 not taken.
1022037 callee = FunctionManager::match(calleeParentScope, fctName, thisType, args, {}, false, node);
766
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 17871 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 5342 times.
✓ Branch 45 → 47 taken 317447 times.
340679 if (callee)
767 5361 break;
768 }
769
770 // Return invalid type if the callee was not found
771
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 5072 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 36809 times.
✓ Branch 57 → 60 taken 5342 times.
47242 if (!callee)
772 41881 return ExprResult(QualType(TY_INVALID));
773
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 5342 times.
5361 assert(calleeParentScope != nullptr);
774
775 // Save the pointer to the operator function in the AST node
776 5361 std::vector<const Function *> &opFctPointers = typeChecker->getOpFctPointers(node);
777
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 4195 times.
5361 if (opFctPointers.size() <= opIdx)
778
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);
779 5361 opFctPointers.at(opIdx) = callee;
780
781 // Check if we need to request a re-visit, because the function body was not type-checked yet
782 5361 TypeChecker::requestRevisitIfRequired(callee);
783
784 // Check if the called function has sufficient visibility
785
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 5342 times.
✗ Branch 69 → 73 not taken.
✓ Branch 71 → 72 taken 4413 times.
✓ Branch 71 → 73 taken 929 times.
5361 const bool isImported = calleeParentScope != nullptr && calleeParentScope->isImportedBy(typeChecker->rootScope);
786 5361 const SymbolTableEntry *calleeEntry = callee->entry;
787
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 4413 times.
✓ Branch 74 → 79 taken 929 times.
✗ Branch 77 → 78 not taken.
✓ Branch 77 → 79 taken 4413 times.
✗ Branch 80 → 81 not taken.
✓ Branch 80 → 90 taken 5342 times.
5361 if (isImported && !calleeEntry->getQualType().isPublic())
788
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,
789
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");
790
791 // Procedures always have the return type 'bool'
792
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 887 times.
✓ Branch 93 → 96 taken 4455 times.
5360 if (callee->isProcedure())
793 901 return ExprResult(QualType(TY_BOOL));
794 4459 const QualType &returnType = callee->returnType;
795
796 // Add anonymous symbol to keep track of dtor call, if non-trivially destructible
797 4459 SymbolTableEntry *anonymousSymbol = nullptr;
798
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 3834 times.
✓ Branch 99 → 100 taken 610 times.
✓ Branch 99 → 101 taken 11 times.
✓ Branch 102 → 103 taken 610 times.
✓ Branch 102 → 105 taken 3845 times.
4459 if (returnType.is(TY_STRUCT) && !returnType.isTriviallyDestructible(node))
799 611 anonymousSymbol = typeChecker->currentScope->symbolTable.insertAnonymous(returnType, node, opIdx);
800
801 4459 return {typeChecker->mapImportedScopeTypeToLocalType(calleeParentScope, returnType), anonymousSymbol};
802 }
803
804 9705 QualType OpRuleManager::validateUnaryOperation(const ASTNode *node, const UnaryOpRule opRules[], size_t opRulesSize,
805 const char *name, const QualType &lhs) {
806
2/2
✓ Branch 10 → 3 taken 20628 times.
✓ Branch 10 → 11 taken 2 times.
20630 for (size_t i = 0; i < opRulesSize; i++) {
807 20628 const UnaryOpRule &rule = opRules[i];
808
2/2
✓ Branch 5 → 6 taken 9703 times.
✓ Branch 5 → 9 taken 10925 times.
20628 if (std::get<0>(rule) == lhs.getSuperType())
809
1/2
✓ Branch 7 → 8 taken 9703 times.
✗ Branch 7 → 15 not taken.
9703 return QualType(std::get<1>(rule));
810 }
811
1/2
✓ Branch 12 → 13 taken 2 times.
✗ Branch 12 → 16 not taken.
2 throw getExceptionUnary(node, name, lhs);
812 }
813
814 93172 QualType OpRuleManager::validateBinaryOperation(const ASTNode *node, const BinaryOpRule opRules[], size_t opRulesSize,
815 const char *name, const QualType &lhs, const QualType &rhs,
816 bool preserveQualifiersFromLhs, const char *customMessagePrefix) {
817
2/2
✓ Branch 19 → 3 taken 917788 times.
✓ Branch 19 → 20 taken 20 times.
917808 for (size_t i = 0; i < opRulesSize; i++) {
818 917788 const BinaryOpRule &rule = opRules[i];
819
6/6
✓ Branch 5 → 6 taken 183178 times.
✓ Branch 5 → 10 taken 734610 times.
✓ Branch 8 → 9 taken 93152 times.
✓ Branch 8 → 10 taken 90026 times.
✓ Branch 11 → 12 taken 93152 times.
✓ Branch 11 → 18 taken 824636 times.
917788 if (std::get<0>(rule) == lhs.getSuperType() && std::get<1>(rule) == rhs.getSuperType()) {
820
1/2
✓ Branch 13 → 14 taken 93152 times.
✗ Branch 13 → 24 not taken.
93152 QualType resultType((std::get<2>(rule)));
821
2/2
✓ Branch 14 → 15 taken 49910 times.
✓ Branch 14 → 17 taken 43242 times.
93152 if (preserveQualifiersFromLhs)
822 49910 resultType.setQualifiers(lhs.getQualifiers());
823 93152 return resultType;
824 }
825 }
826
1/2
✓ Branch 21 → 22 taken 20 times.
✗ Branch 21 → 25 not taken.
20 throw getExceptionBinary(node, name, lhs, rhs, customMessagePrefix);
827 }
828
829 2 SemanticError OpRuleManager::getExceptionUnary(const ASTNode *node, const char *name, const QualType &lhs) {
830
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)};
831 }
832
833 20 SemanticError OpRuleManager::getExceptionBinary(const ASTNode *node, const char *name, const QualType &lhs, const QualType &rhs,
834 const char *messagePrefix) {
835 // Build error message
836
1/2
✓ Branch 2 → 3 taken 20 times.
✗ Branch 2 → 50 not taken.
20 std::stringstream errorMsg;
837
2/2
✓ Branch 3 → 4 taken 4 times.
✓ Branch 3 → 14 taken 16 times.
20 if (strlen(messagePrefix) != 0)
838
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);
839 else
840
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);
841
842 // Return the exception
843
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()};
844 20 }
845
846 27 void OpRuleManager::ensureUnsafeAllowed(const ASTNode *node, const char *name, const QualType &lhs) const {
847
2/4
✓ Branch 2 → 3 taken 27 times.
✗ Branch 2 → 43 not taken.
✓ Branch 3 → 4 taken 27 times.
✗ Branch 3 → 5 not taken.
27 if (typeChecker->currentScope->doesAllowUnsafeOperations())
848 27 return;
849 // Print error message
850 const std::string lhsName = lhs.getName(true);
851 const std::string errorMsg = "Cannot apply '" + std::string(name) + "' operator on type " + lhsName +
852 " as this is an unsafe operation. Please use unsafe blocks if you know what you are doing.";
853 SOFT_ERROR_VOID(node, UNSAFE_OPERATION_IN_SAFE_CONTEXT, errorMsg)
854 }
855
856 3475 void OpRuleManager::ensureUnsafeAllowed(const ASTNode *node, const char *name, const QualType &lhs, const QualType &rhs) const {
857
3/4
✓ Branch 2 → 3 taken 3475 times.
✗ Branch 2 → 57 not taken.
✓ Branch 3 → 4 taken 3474 times.
✓ Branch 3 → 5 taken 1 time.
3475 if (typeChecker->currentScope->doesAllowUnsafeOperations())
858 3474 return;
859 // Print error message
860
1/2
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 57 not taken.
1 const std::string lhsName = lhs.getName(true);
861
1/2
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 55 not taken.
1 const std::string rhsName = rhs.getName(true);
862
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 +
863
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.";
864
1/2
✓ Branch 23 → 24 taken 1 time.
✗ Branch 23 → 51 not taken.
1 SOFT_ERROR_VOID(node, UNSAFE_OPERATION_IN_SAFE_CONTEXT, errorMsg)
865 1 }
866
867 83460 void OpRuleManager::ensureNoConstAssign(const ASTNode *node, const QualType &lhs, bool isDecl, bool isReturn) const {
868 // Check if we try to assign a constant value
869
10/12
✓ Branch 2 → 3 taken 83460 times.
✗ Branch 2 → 17 not taken.
✓ Branch 3 → 4 taken 83460 times.
✗ Branch 3 → 17 not taken.
✓ Branch 4 → 5 taken 9307 times.
✓ Branch 4 → 8 taken 74153 times.
✓ Branch 5 → 6 taken 194 times.
✓ Branch 5 → 8 taken 9113 times.
✓ Branch 6 → 7 taken 14 times.
✓ Branch 6 → 8 taken 180 times.
✓ Branch 9 → 10 taken 14 times.
✓ Branch 9 → 16 taken 83446 times.
83460 if (lhs.removeReferenceWrapper().isConst() && !isDecl && !isReturn) {
870
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);
871
1/2
✓ Branch 13 → 14 taken 14 times.
✗ Branch 13 → 21 not taken.
14 SOFT_ERROR_VOID(node, REASSIGN_CONST_VARIABLE, errorMessage);
872 14 }
873 }
874
875 } // namespace spice::compiler
876