Line | Branch | Exec | Source |
---|---|---|---|
1 | // Copyright (c) 2021-2025 ChilliBits. All rights reserved. | ||
2 | |||
3 | #include "OpRuleManager.h" | ||
4 | |||
5 | #include <SourceFile.h> | ||
6 | #include <ast/ASTNodes.h> | ||
7 | #include <global/GlobalResourceManager.h> | ||
8 | #include <global/RuntimeModuleManager.h> | ||
9 | #include <typechecker/MacroDefs.h> | ||
10 | #include <typechecker/TypeChecker.h> | ||
11 | |||
12 | namespace spice::compiler { | ||
13 | |||
14 | 2799 | OpRuleManager::OpRuleManager(TypeChecker *typeChecker) | |
15 | 2799 | : typeChecker(typeChecker), resourceManager(typeChecker->resourceManager) {} | |
16 | |||
17 | 21163 | std::pair<QualType, Function *> OpRuleManager::getAssignResultType(const ASTNode *node, const ExprResult &lhs, | |
18 | const ExprResult &rhs, bool isDecl, bool isReturn, | ||
19 | const char *errMsgPrefix) const { | ||
20 | // Retrieve types | ||
21 | 21163 | const QualType lhsType = lhs.type; | |
22 | 21163 | const QualType rhsType = rhs.type; | |
23 | |||
24 | // Check if lhs is a temporary | ||
25 |
2/2✓ Branch 0 (3→4) taken 1 times.
✓ Branch 1 (3→12) taken 21162 times.
|
21163 | if (lhs.isTemporary()) |
26 |
2/4✓ Branch 0 (7→8) taken 1 times.
✗ Branch 1 (7→111) not taken.
✓ Branch 2 (8→9) taken 1 times.
✗ Branch 3 (8→108) not taken.
|
3 | throw SemanticError(node, OPERATOR_WRONG_DATA_TYPE, "Cannot assign to a temporary value"); |
27 | |||
28 | // Skip type compatibility check if the lhs is of type dyn -> perform type inference | ||
29 |
3/4✓ Branch 0 (12→13) taken 21162 times.
✗ Branch 1 (12→125) not taken.
✓ Branch 2 (13→14) taken 66 times.
✓ Branch 3 (13→16) taken 21096 times.
|
21162 | if (lhsType.is(TY_DYN)) |
30 | 66 | return {rhsType, nullptr}; | |
31 | |||
32 | // Check if we try to assign a constant value | ||
33 |
1/2✓ Branch 0 (16→17) taken 21096 times.
✗ Branch 1 (16→125) not taken.
|
21096 | ensureNoConstAssign(node, lhsType, isDecl, isReturn); |
34 | |||
35 | // Allow pointers and references of the same type straight away | ||
36 |
8/10✓ Branch 0 (17→18) taken 21096 times.
✗ Branch 1 (17→117) not taken.
✓ Branch 2 (18→19) taken 2813 times.
✓ Branch 3 (18→22) taken 18283 times.
✓ Branch 4 (19→20) taken 2813 times.
✗ Branch 5 (19→117) not taken.
✓ Branch 6 (20→21) taken 2330 times.
✓ Branch 7 (20→22) taken 483 times.
✓ Branch 8 (23→24) taken 2330 times.
✓ Branch 9 (23→41) taken 18766 times.
|
21096 | 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 0 (24→25) taken 743 times.
✓ Branch 1 (24→35) taken 1587 times.
✓ Branch 2 (25→26) taken 743 times.
✗ Branch 3 (25→118) not taken.
✓ Branch 4 (26→27) taken 508 times.
✓ Branch 5 (26→35) taken 235 times.
✓ Branch 6 (27→28) taken 508 times.
✗ Branch 7 (27→118) not taken.
✓ Branch 8 (28→29) taken 424 times.
✓ Branch 9 (28→35) taken 84 times.
✓ Branch 10 (29→30) taken 424 times.
✗ Branch 11 (29→118) not taken.
✓ Branch 12 (30→31) taken 424 times.
✗ Branch 13 (30→118) not taken.
✓ Branch 14 (31→32) taken 424 times.
✗ Branch 15 (31→35) not taken.
✓ Branch 16 (32→33) taken 424 times.
✗ Branch 17 (32→118) not taken.
✓ Branch 18 (33→34) taken 424 times.
✗ Branch 19 (33→35) not taken.
✓ Branch 20 (36→37) taken 424 times.
✓ Branch 21 (36→39) taken 1906 times.
|
2330 | if (rhs.entry && lhsType.isPtr() && lhsType.isHeap() && rhsType.removeReferenceWrapper().isPtr() && rhsType.isHeap()) |
39 |
1/2✓ Branch 0 (37→38) taken 424 times.
✗ Branch 1 (37→119) not taken.
|
424 | rhs.entry->updateState(MOVED, node); |
40 | 2330 | return {rhsType, nullptr}; | |
41 | } | ||
42 | // Allow ref type to type of the same contained type straight away | ||
43 |
3/4✓ Branch 0 (41→42) taken 18766 times.
✗ Branch 1 (41→125) not taken.
✓ Branch 2 (42→43) taken 326 times.
✓ Branch 3 (42→63) taken 18440 times.
|
18766 | if (rhsType.isRef()) { |
44 | // If this is const ref, remove both: the reference and the constness | ||
45 |
2/4✓ Branch 0 (43→44) taken 326 times.
✗ Branch 1 (43→120) not taken.
✓ Branch 2 (44→45) taken 326 times.
✗ Branch 3 (44→120) not taken.
|
326 | const QualType rhsModified = rhsType.getContained().toNonConst(); |
46 |
3/4✓ Branch 0 (45→46) taken 326 times.
✗ Branch 1 (45→122) not taken.
✓ Branch 2 (46→47) taken 324 times.
✓ Branch 3 (46→62) taken 2 times.
|
326 | if (lhsType.matches(rhsModified, false, false, true)) { |
47 | // Check if we support nrvo. If yes, skip the implicit copy ctor call | ||
48 |
4/4✓ Branch 0 (47→48) taken 5 times.
✓ Branch 1 (47→51) taken 319 times.
✓ Branch 2 (49→50) taken 2 times.
✓ Branch 3 (49→51) taken 3 times.
|
324 | const bool supportsNRVO = isReturn && !rhs.isTemporary(); |
49 | 324 | Function *copyCtor = nullptr; | |
50 |
7/8✓ Branch 0 (52→53) taken 324 times.
✗ Branch 1 (52→121) not taken.
✓ Branch 2 (53→54) taken 232 times.
✓ Branch 3 (53→56) taken 92 times.
✓ Branch 4 (54→55) taken 230 times.
✓ Branch 5 (54→56) taken 2 times.
✓ Branch 6 (57→58) taken 230 times.
✓ Branch 7 (57→60) taken 94 times.
|
324 | if (rhsModified.is(TY_STRUCT) && !supportsNRVO) |
51 |
1/2✓ Branch 0 (58→59) taken 230 times.
✗ Branch 1 (58→121) not taken.
|
230 | copyCtor = typeChecker->implicitlyCallStructCopyCtor(rhsModified, node); |
52 | 324 | return {lhsType, copyCtor}; | |
53 | } | ||
54 | } | ||
55 | // Allow arrays, structs, interfaces, functions, procedures of the same type straight away | ||
56 |
8/10✓ Branch 0 (63→64) taken 18442 times.
✗ Branch 1 (63→123) not taken.
✓ Branch 2 (64→65) taken 79 times.
✓ Branch 3 (64→68) taken 18363 times.
✓ Branch 4 (65→66) taken 79 times.
✗ Branch 5 (65→123) not taken.
✓ Branch 6 (66→67) taken 74 times.
✓ Branch 7 (66→68) taken 5 times.
✓ Branch 8 (69→70) taken 74 times.
✓ Branch 9 (69→72) taken 18368 times.
|
18442 | if (lhsType.isOneOf({TY_ARRAY, TY_INTERFACE, TY_FUNCTION, TY_PROCEDURE}) && lhsType.matches(rhsType, false, true, true)) |
57 | 74 | return {rhsType, nullptr}; | |
58 | // Allow struct of the same type straight away | ||
59 |
8/10✓ Branch 0 (72→73) taken 18368 times.
✗ Branch 1 (72→125) not taken.
✓ Branch 2 (73→74) taken 2181 times.
✓ Branch 3 (73→77) taken 16187 times.
✓ Branch 4 (74→75) taken 2181 times.
✗ Branch 5 (74→125) not taken.
✓ Branch 6 (75→76) taken 2180 times.
✓ Branch 7 (75→77) taken 1 times.
✓ Branch 8 (78→79) taken 2180 times.
✓ Branch 9 (78→96) taken 16188 times.
|
18368 | if (lhsType.is(TY_STRUCT) && lhsType.matches(rhsType, false, true, true)) { |
60 | // Check if we support nrvo. If yes, skip the implicit copy ctor call | ||
61 |
4/4✓ Branch 0 (79→80) taken 1208 times.
✓ Branch 1 (79→83) taken 972 times.
✓ Branch 2 (81→82) taken 97 times.
✓ Branch 3 (81→83) taken 1111 times.
|
2180 | const bool supportsNRVO = isReturn && !rhs.isTemporary(); |
62 | 2180 | Function *copyCtor = nullptr; | |
63 |
10/10✓ Branch 0 (84→85) taken 2156 times.
✓ Branch 1 (84→90) taken 24 times.
✓ Branch 2 (85→86) taken 2059 times.
✓ Branch 3 (85→90) taken 97 times.
✓ Branch 4 (86→87) taken 954 times.
✓ Branch 5 (86→90) taken 1105 times.
✓ Branch 6 (88→89) taken 10 times.
✓ Branch 7 (88→90) taken 944 times.
✓ Branch 8 (91→92) taken 10 times.
✓ Branch 9 (91→94) taken 2170 times.
|
2180 | if (rhs.entry != nullptr && !supportsNRVO && !isReturn && !rhs.isTemporary()) |
64 |
1/2✓ Branch 0 (92→93) taken 10 times.
✗ Branch 1 (92→124) not taken.
|
10 | copyCtor = typeChecker->implicitlyCallStructCopyCtor(rhsType, rhs.entry->declNode); |
65 | 2180 | return {rhsType, copyCtor}; | |
66 | } | ||
67 | |||
68 | // Check common type combinations | ||
69 |
2/2✓ Branch 0 (96→97) taken 16186 times.
✓ Branch 1 (96→125) taken 2 times.
|
16188 | const QualType resultType = getAssignResultTypeCommon(node, lhs, rhs, isDecl, isReturn); |
70 |
3/4✓ Branch 0 (97→98) taken 16186 times.
✗ Branch 1 (97→125) not taken.
✓ Branch 2 (98→99) taken 448 times.
✓ Branch 3 (98→101) taken 15738 times.
|
16186 | if (!resultType.is(TY_INVALID)) |
71 | 448 | return {resultType, nullptr}; | |
72 | |||
73 | // Check primitive type combinations | ||
74 | const QualType binOpType = | ||
75 |
2/2✓ Branch 0 (103→104) taken 15726 times.
✓ Branch 1 (103→125) taken 12 times.
|
15738 | validateBinaryOperation(node, ASSIGN_OP_RULES, std::size(ASSIGN_OP_RULES), "=", lhsType, rhsType, true, errMsgPrefix); |
76 | 15726 | return {binOpType, nullptr}; | |
77 | } | ||
78 | |||
79 | 386 | QualType OpRuleManager::getFieldAssignResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, bool imm, | |
80 | bool isDecl) const { | ||
81 | // Retrieve types | ||
82 | 386 | const QualType lhsType = lhs.type; | |
83 | 386 | const QualType rhsType = rhs.type; | |
84 |
2/4✓ Branch 0 (2→3) taken 386 times.
✗ Branch 1 (2→92) not taken.
✗ Branch 2 (3→4) not taken.
✓ Branch 3 (3→5) taken 386 times.
|
386 | assert(!lhsType.is(TY_DYN)); |
85 | |||
86 | // Check if we try to assign a constant value | ||
87 |
1/2✓ Branch 0 (5→6) taken 386 times.
✗ Branch 1 (5→92) not taken.
|
386 | ensureNoConstAssign(node, lhsType, isDecl); |
88 | |||
89 | // Allow pointers, arrays and structs of the same type straight away | ||
90 |
8/10✓ Branch 0 (6→7) taken 386 times.
✗ Branch 1 (6→85) not taken.
✓ Branch 2 (7→8) taken 231 times.
✓ Branch 3 (7→11) taken 155 times.
✓ Branch 4 (8→9) taken 231 times.
✗ Branch 5 (8→85) not taken.
✓ Branch 6 (9→10) taken 229 times.
✓ Branch 7 (9→11) taken 2 times.
✓ Branch 8 (12→13) taken 229 times.
✓ Branch 9 (12→29) taken 157 times.
|
386 | if (lhsType.isOneOf({TY_PTR, TY_ARRAY}) && lhsType == rhsType) { |
91 | // If we perform a heap x* = heap x* assignment, we need set the right hand side to MOVED | ||
92 |
8/22✓ Branch 0 (13→14) taken 64 times.
✓ Branch 1 (13→24) taken 165 times.
✓ Branch 2 (14→15) taken 64 times.
✗ Branch 3 (14→86) not taken.
✓ Branch 4 (15→16) taken 62 times.
✓ Branch 5 (15→24) taken 2 times.
✓ Branch 6 (16→17) taken 62 times.
✗ Branch 7 (16→86) not taken.
✗ Branch 8 (17→18) not taken.
✓ Branch 9 (17→24) taken 62 times.
✗ Branch 10 (18→19) not taken.
✗ Branch 11 (18→86) not taken.
✗ Branch 12 (19→20) not taken.
✗ Branch 13 (19→86) not taken.
✗ Branch 14 (20→21) not taken.
✗ Branch 15 (20→24) not taken.
✗ Branch 16 (21→22) not taken.
✗ Branch 17 (21→86) not taken.
✗ Branch 18 (22→23) not taken.
✗ Branch 19 (22→24) not taken.
✗ Branch 20 (25→26) not taken.
✓ Branch 21 (25→28) taken 229 times.
|
229 | if (rhs.entry && lhsType.isPtr() && lhsType.isHeap() && rhsType.removeReferenceWrapper().isPtr() && rhsType.isHeap()) |
93 | ✗ | rhs.entry->updateState(MOVED, node); | |
94 | 229 | return rhsType; | |
95 | } | ||
96 | // Allow struct of the same type straight away | ||
97 |
8/10✓ Branch 0 (29→30) taken 157 times.
✗ Branch 1 (29→92) not taken.
✓ Branch 2 (30→31) taken 10 times.
✓ Branch 3 (30→34) taken 147 times.
✓ Branch 4 (31→32) taken 10 times.
✗ Branch 5 (31→92) not taken.
✓ Branch 6 (32→33) taken 9 times.
✓ Branch 7 (32→34) taken 1 times.
✓ Branch 8 (35→36) taken 9 times.
✓ Branch 9 (35→40) taken 148 times.
|
157 | if (lhsType.is(TY_STRUCT) && lhsType.matches(rhsType, false, true, true)) { |
98 |
2/2✓ Branch 0 (37→38) taken 5 times.
✓ Branch 1 (37→39) taken 4 times.
|
9 | if (!rhs.isTemporary()) |
99 |
1/2✓ Branch 0 (38→39) taken 5 times.
✗ Branch 1 (38→92) not taken.
|
5 | typeChecker->implicitlyCallStructCopyCtor(rhs.entry, rhs.entry->declNode); |
100 | 9 | return rhsType; | |
101 | } | ||
102 | // Allow ref type to type of the same contained type straight away | ||
103 |
9/12✓ Branch 0 (40→41) taken 148 times.
✗ Branch 1 (40→88) not taken.
✓ Branch 2 (41→42) taken 14 times.
✓ Branch 3 (41→46) taken 134 times.
✓ Branch 4 (42→43) taken 14 times.
✗ Branch 5 (42→88) not taken.
✓ Branch 6 (43→44) taken 14 times.
✗ Branch 7 (43→88) not taken.
✓ Branch 8 (44→45) taken 1 times.
✓ Branch 9 (44→46) taken 13 times.
✓ Branch 10 (47→48) taken 1 times.
✓ Branch 11 (47→58) taken 147 times.
|
148 | if (rhsType.isRef() && lhsType.matches(rhsType.getContained(), false, false, true)) { |
104 | // In case of a return expression, we perform temp stealing | ||
105 |
4/10✓ Branch 0 (48→49) taken 1 times.
✗ Branch 1 (48→89) not taken.
✓ Branch 2 (49→50) taken 1 times.
✗ Branch 3 (49→89) not taken.
✗ Branch 4 (50→51) not taken.
✓ Branch 5 (50→54) taken 1 times.
✗ Branch 6 (52→53) not taken.
✗ Branch 7 (52→54) not taken.
✗ Branch 8 (55→56) not taken.
✓ Branch 9 (55→57) taken 1 times.
|
1 | if (rhsType.getContained().is(TY_STRUCT) && !rhs.isTemporary()) |
106 | ✗ | typeChecker->implicitlyCallStructCopyCtor(rhs.entry, rhs.entry->declNode); | |
107 | 1 | return lhsType; | |
108 | } | ||
109 | // Allow const ref type to type of the same contained type straight away | ||
110 |
9/14✓ Branch 0 (58→59) taken 147 times.
✗ Branch 1 (58→90) not taken.
✓ Branch 2 (59→60) taken 13 times.
✓ Branch 3 (59→65) taken 134 times.
✓ Branch 4 (60→61) taken 13 times.
✗ Branch 5 (60→90) not taken.
✓ Branch 6 (61→62) taken 13 times.
✗ Branch 7 (61→90) not taken.
✓ Branch 8 (62→63) taken 13 times.
✗ Branch 9 (62→90) not taken.
✓ Branch 10 (63→64) taken 13 times.
✗ Branch 11 (63→65) not taken.
✓ Branch 12 (66→67) taken 13 times.
✓ Branch 13 (66→68) taken 134 times.
|
147 | if (rhsType.isConstRef() && lhsType.matches(rhsType.getContained().toNonConst(), false, false, true)) |
111 | 13 | return lhsType; | |
112 | // Allow immediate value to const ref of the same contained type straight away | ||
113 |
6/8✓ Branch 0 (68→69) taken 134 times.
✗ Branch 1 (68→92) not taken.
✓ Branch 2 (69→70) taken 1 times.
✓ Branch 3 (69→72) taken 133 times.
✓ Branch 4 (70→71) taken 1 times.
✗ Branch 5 (70→72) not taken.
✓ Branch 6 (73→74) taken 1 times.
✓ Branch 7 (73→75) taken 133 times.
|
134 | if (lhsType.isConstRef() && imm) |
114 | 1 | return rhsType; | |
115 | |||
116 | // Check common type combinations | ||
117 |
1/2✓ Branch 0 (75→76) taken 133 times.
✗ Branch 1 (75→92) not taken.
|
133 | const QualType resultType = getAssignResultTypeCommon(node, lhs, rhs, isDecl, false); |
118 |
3/4✓ Branch 0 (76→77) taken 133 times.
✗ Branch 1 (76→92) not taken.
✓ Branch 2 (77→78) taken 4 times.
✓ Branch 3 (77→79) taken 129 times.
|
133 | if (!resultType.is(TY_INVALID)) |
119 | 4 | return resultType; | |
120 | |||
121 | // Check primitive type combinations | ||
122 |
2/2✓ Branch 0 (81→82) taken 128 times.
✓ Branch 1 (81→92) taken 1 times.
|
129 | return validateBinaryOperation(node, ASSIGN_OP_RULES, std::size(ASSIGN_OP_RULES), "=", lhsType, rhsType, true, |
123 | 128 | ERROR_FIELD_ASSIGN); | |
124 | } | ||
125 | |||
126 | 16321 | QualType OpRuleManager::getAssignResultTypeCommon(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, bool isDecl, | |
127 | bool isReturn) { | ||
128 | // Retrieve types | ||
129 | 16321 | const QualType lhsType = lhs.type; | |
130 | 16321 | const QualType rhsType = rhs.type; | |
131 | |||
132 | // Allow type to ref type of the same contained type straight away | ||
133 |
9/12✓ Branch 0 (2→3) taken 16321 times.
✗ Branch 1 (2→113) not taken.
✓ Branch 2 (3→4) taken 358 times.
✓ Branch 3 (3→8) taken 15963 times.
✓ Branch 4 (4→5) taken 358 times.
✗ Branch 5 (4→113) not taken.
✓ Branch 6 (5→6) taken 358 times.
✗ Branch 7 (5→113) not taken.
✓ Branch 8 (6→7) taken 355 times.
✓ Branch 9 (6→8) taken 3 times.
✓ Branch 10 (9→10) taken 355 times.
✓ Branch 11 (9→44) taken 15966 times.
|
16321 | if (lhsType.isRef() && lhsType.getContained().matches(rhsType, false, false, true)) { |
134 |
4/4✓ Branch 0 (10→11) taken 296 times.
✓ Branch 1 (10→12) taken 59 times.
✓ Branch 2 (11→12) taken 247 times.
✓ Branch 3 (11→13) taken 49 times.
|
355 | const bool isDeclOrReturn = isDecl || isReturn; |
135 |
7/8✓ Branch 0 (14→15) taken 306 times.
✓ Branch 1 (14→19) taken 49 times.
✓ Branch 2 (16→17) taken 306 times.
✗ Branch 3 (16→137) not taken.
✓ Branch 4 (17→18) taken 1 times.
✓ Branch 5 (17→19) taken 305 times.
✓ Branch 6 (20→21) taken 1 times.
✓ Branch 7 (20→29) taken 354 times.
|
355 | if (isDeclOrReturn && !lhsType.canBind(rhsType, rhs.isTemporary())) |
136 |
2/4✓ Branch 0 (24→25) taken 1 times.
✗ Branch 1 (24→117) not taken.
✓ Branch 2 (25→26) taken 1 times.
✗ Branch 3 (25→114) not taken.
|
3 | throw SemanticError(node, TEMP_TO_NON_CONST_REF, "Temporary values can only be bound to const reference variables/fields"); |
137 |
6/6✓ Branch 0 (29→30) taken 247 times.
✓ Branch 1 (29→33) taken 107 times.
✓ Branch 2 (31→32) taken 1 times.
✓ Branch 3 (31→33) taken 246 times.
✓ Branch 4 (34→35) taken 1 times.
✓ Branch 5 (34→43) taken 353 times.
|
354 | if (isReturn && rhs.isTemporary()) |
138 |
2/4✓ Branch 0 (38→39) taken 1 times.
✗ Branch 1 (38→126) not taken.
✓ Branch 2 (39→40) taken 1 times.
✗ Branch 3 (39→123) not taken.
|
3 | throw SemanticError(node, RETURN_OF_TEMPORARY_VALUE, "Cannot return reference to temporary value"); |
139 | 353 | return lhsType; | |
140 | } | ||
141 | // Allow char* = string | ||
142 |
9/14✓ Branch 0 (44→45) taken 15966 times.
✗ Branch 1 (44→137) not taken.
✓ Branch 2 (45→46) taken 1 times.
✓ Branch 3 (45→53) taken 15965 times.
✓ Branch 4 (46→47) taken 1 times.
✗ Branch 5 (46→137) not taken.
✓ Branch 6 (47→48) taken 1 times.
✗ Branch 7 (47→53) not taken.
✓ Branch 8 (50→51) taken 1 times.
✗ Branch 9 (50→137) not taken.
✓ Branch 10 (51→52) taken 1 times.
✗ Branch 11 (51→53) not taken.
✓ Branch 12 (54→55) taken 1 times.
✓ Branch 13 (54→56) taken 15965 times.
|
15966 | if (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING) && lhsType.getQualifiers() == rhsType.getQualifiers()) |
143 | 1 | return lhsType; | |
144 | // Allow array to pointer | ||
145 |
12/18✓ Branch 0 (56→57) taken 15965 times.
✗ Branch 1 (56→132) not taken.
✓ Branch 2 (57→58) taken 98 times.
✓ Branch 3 (57→65) taken 15867 times.
✓ Branch 4 (58→59) taken 98 times.
✗ Branch 5 (58→132) not taken.
✓ Branch 6 (59→60) taken 5 times.
✓ Branch 7 (59→65) taken 93 times.
✓ Branch 8 (60→61) taken 5 times.
✗ Branch 9 (60→132) not taken.
✓ Branch 10 (61→62) taken 5 times.
✗ Branch 11 (61→132) not taken.
✓ Branch 12 (62→63) taken 5 times.
✗ Branch 13 (62→132) not taken.
✓ Branch 14 (63→64) taken 5 times.
✗ Branch 15 (63→65) not taken.
✓ Branch 16 (66→67) taken 5 times.
✓ Branch 17 (66→68) taken 15960 times.
|
15965 | if (lhsType.isPtr() && rhsType.isArray() && lhsType.getContained().matches(rhsType.getContained(), false, false, true)) |
146 | 5 | return lhsType; | |
147 | // Allow interface* = struct* or interface& = struct that implements this interface | ||
148 |
1/2✓ Branch 0 (70→71) taken 15960 times.
✗ Branch 1 (70→137) not taken.
|
15960 | const bool sameChainDepth = Type::hasSameTypeChainDepth(lhsType.getType(), rhsType.getType()); |
149 |
10/14✓ Branch 0 (71→72) taken 15960 times.
✗ Branch 1 (71→137) not taken.
✓ Branch 2 (72→73) taken 93 times.
✓ Branch 3 (72→76) taken 15867 times.
✓ Branch 4 (73→74) taken 93 times.
✗ Branch 5 (73→137) not taken.
✓ Branch 6 (74→75) taken 92 times.
✓ Branch 7 (74→76) taken 1 times.
✗ Branch 8 (75→76) not taken.
✓ Branch 9 (75→78) taken 92 times.
✓ Branch 10 (76→77) taken 15868 times.
✗ Branch 11 (76→137) not taken.
✓ Branch 12 (77→78) taken 3 times.
✓ Branch 13 (77→79) taken 15865 times.
|
15960 | const bool typesCompatible = (lhsType.isPtr() && rhsType.isPtr() && sameChainDepth) || lhsType.isRef(); |
150 |
9/12✓ Branch 0 (80→81) taken 95 times.
✓ Branch 1 (80→86) taken 15865 times.
✓ Branch 2 (81→82) taken 95 times.
✗ Branch 3 (81→137) not taken.
✓ Branch 4 (82→83) taken 5 times.
✓ Branch 5 (82→86) taken 90 times.
✓ Branch 6 (83→84) taken 5 times.
✗ Branch 7 (83→137) not taken.
✓ Branch 8 (84→85) taken 5 times.
✗ Branch 9 (84→86) not taken.
✓ Branch 10 (87→88) taken 5 times.
✓ Branch 11 (87→93) taken 15955 times.
|
15960 | if (typesCompatible && lhsType.isBase(TY_INTERFACE) && rhsType.isBase(TY_STRUCT)) { |
151 | 5 | QualType lhsTypeCopy = lhsType; | |
152 | 5 | QualType rhsTypeCopy = rhsType; | |
153 |
1/2✓ Branch 0 (88→89) taken 5 times.
✗ Branch 1 (88→134) not taken.
|
5 | QualType::unwrapBoth(lhsTypeCopy, rhsTypeCopy); |
154 |
2/4✓ Branch 0 (89→90) taken 5 times.
✗ Branch 1 (89→134) not taken.
✓ Branch 2 (90→91) taken 5 times.
✗ Branch 3 (90→92) not taken.
|
5 | if (lhsTypeCopy.matchesInterfaceImplementedByStruct(rhsTypeCopy)) |
155 | 5 | return lhsType; | |
156 | } | ||
157 | // Allow type* = heap type* straight away. This is used for initializing non-owning pointers to heap allocations | ||
158 |
10/14✓ Branch 0 (93→94) taken 15955 times.
✗ Branch 1 (93→137) not taken.
✓ Branch 2 (94→95) taken 89 times.
✓ Branch 3 (94→100) taken 15866 times.
✓ Branch 4 (95→96) taken 89 times.
✗ Branch 5 (95→137) not taken.
✓ Branch 6 (96→97) taken 88 times.
✓ Branch 7 (96→100) taken 1 times.
✓ Branch 8 (97→98) taken 88 times.
✗ Branch 9 (97→137) not taken.
✓ Branch 10 (98→99) taken 88 times.
✗ Branch 11 (98→100) not taken.
✓ Branch 12 (101→102) taken 88 times.
✓ Branch 13 (101→108) taken 15867 times.
|
15955 | if (lhsType.isPtr() && rhsType.isHeap() && lhsType.matches(rhsType, false, true, true)) { |
159 | 88 | TypeQualifiers rhsQualifiers = rhsType.getQualifiers(); | |
160 | 88 | rhsQualifiers.isHeap = false; | |
161 |
2/4✓ Branch 0 (104→105) taken 88 times.
✗ Branch 1 (104→135) not taken.
✓ Branch 2 (105→106) taken 88 times.
✗ Branch 3 (105→107) not taken.
|
88 | if (lhsType.getQualifiers() == rhsQualifiers) |
162 | 88 | return lhsType; | |
163 | } | ||
164 | |||
165 | // Nothing matched | ||
166 |
1/2✓ Branch 0 (108→109) taken 15867 times.
✗ Branch 1 (108→136) not taken.
|
15867 | return QualType(TY_INVALID); |
167 | } | ||
168 | |||
169 | 227 | ExprResult OpRuleManager::getPlusEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) { | |
170 | // Check is there is an overloaded operator function available | ||
171 |
1/2✓ Branch 0 (2→3) taken 227 times.
✗ Branch 1 (2→24) not taken.
|
227 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_PLUS_EQUAL, {lhs, rhs}, opIdx); |
172 |
3/4✓ Branch 0 (3→4) taken 227 times.
✗ Branch 1 (3→26) not taken.
✓ Branch 2 (4→5) taken 87 times.
✓ Branch 3 (4→6) taken 140 times.
|
227 | if (!resultType.type.is(TY_INVALID)) |
173 | 87 | return resultType; | |
174 | |||
175 | // Check if we try to assign a constant value | ||
176 |
1/2✓ Branch 0 (6→7) taken 140 times.
✗ Branch 1 (6→26) not taken.
|
140 | ensureNoConstAssign(node, lhs.type); |
177 | |||
178 | // Remove reference wrappers | ||
179 |
1/2✓ Branch 0 (7→8) taken 140 times.
✗ Branch 1 (7→26) not taken.
|
140 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
180 |
1/2✓ Branch 0 (8→9) taken 140 times.
✗ Branch 1 (8→26) not taken.
|
140 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
181 | |||
182 | // Check if this is an unsafe operation | ||
183 |
7/10✓ Branch 0 (9→10) taken 140 times.
✗ Branch 1 (9→25) not taken.
✓ Branch 2 (10→11) taken 1 times.
✓ Branch 3 (10→14) taken 139 times.
✓ Branch 4 (11→12) taken 1 times.
✗ Branch 5 (11→25) not taken.
✓ Branch 6 (12→13) taken 1 times.
✗ Branch 7 (12→14) not taken.
✓ Branch 8 (15→16) taken 1 times.
✓ Branch 9 (15→18) taken 139 times.
|
140 | if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) { |
184 |
1/2✓ Branch 0 (16→17) taken 1 times.
✗ Branch 1 (16→26) not taken.
|
1 | ensureUnsafeAllowed(node, "+=", lhsType, rhsType); |
185 | 1 | return {lhs}; | |
186 | } | ||
187 | |||
188 |
1/2✓ Branch 0 (20→21) taken 139 times.
✗ Branch 1 (20→26) not taken.
|
139 | return {validateBinaryOperation(node, PLUS_EQUAL_OP_RULES, std::size(PLUS_EQUAL_OP_RULES), "+=", lhsType, rhsType)}; |
189 | } | ||
190 | |||
191 | 28 | ExprResult OpRuleManager::getMinusEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) { | |
192 | // Check is there is an overloaded operator function available | ||
193 |
1/2✓ Branch 0 (2→3) taken 28 times.
✗ Branch 1 (2→24) not taken.
|
28 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MINUS_EQUAL, {lhs, rhs}, opIdx); |
194 |
3/4✓ Branch 0 (3→4) taken 28 times.
✗ Branch 1 (3→26) not taken.
✓ Branch 2 (4→5) taken 7 times.
✓ Branch 3 (4→6) taken 21 times.
|
28 | if (!resultType.type.is(TY_INVALID)) |
195 | 7 | return resultType; | |
196 | |||
197 | // Check if we try to assign a constant value | ||
198 |
1/2✓ Branch 0 (6→7) taken 21 times.
✗ Branch 1 (6→26) not taken.
|
21 | ensureNoConstAssign(node, lhs.type); |
199 | |||
200 | // Remove reference wrappers | ||
201 |
1/2✓ Branch 0 (7→8) taken 21 times.
✗ Branch 1 (7→26) not taken.
|
21 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
202 |
1/2✓ Branch 0 (8→9) taken 21 times.
✗ Branch 1 (8→26) not taken.
|
21 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
203 | |||
204 | // Check if this is an unsafe operation | ||
205 |
7/10✓ Branch 0 (9→10) taken 21 times.
✗ Branch 1 (9→25) not taken.
✓ Branch 2 (10→11) taken 1 times.
✓ Branch 3 (10→14) taken 20 times.
✓ Branch 4 (11→12) taken 1 times.
✗ Branch 5 (11→25) not taken.
✓ Branch 6 (12→13) taken 1 times.
✗ Branch 7 (12→14) not taken.
✓ Branch 8 (15→16) taken 1 times.
✓ Branch 9 (15→18) taken 20 times.
|
21 | if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) { |
206 |
1/2✓ Branch 0 (16→17) taken 1 times.
✗ Branch 1 (16→26) not taken.
|
1 | ensureUnsafeAllowed(node, "-=", lhsType, rhsType); |
207 | 1 | return {lhs}; | |
208 | } | ||
209 | |||
210 |
1/2✓ Branch 0 (20→21) taken 20 times.
✗ Branch 1 (20→26) not taken.
|
20 | return {validateBinaryOperation(node, MINUS_EQUAL_OP_RULES, std::size(MINUS_EQUAL_OP_RULES), "-=", lhsType, rhsType)}; |
211 | } | ||
212 | |||
213 | 16 | ExprResult OpRuleManager::getMulEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) { | |
214 | // Check is there is an overloaded operator function available | ||
215 |
1/2✓ Branch 0 (2→3) taken 16 times.
✗ Branch 1 (2→15) not taken.
|
16 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MUL_EQUAL, {lhs, rhs}, opIdx); |
216 |
3/4✓ Branch 0 (3→4) taken 16 times.
✗ Branch 1 (3→16) not taken.
✓ Branch 2 (4→5) taken 2 times.
✓ Branch 3 (4→6) taken 14 times.
|
16 | if (!resultType.type.is(TY_INVALID)) |
217 | 2 | return resultType; | |
218 | |||
219 | // Check if we try to assign a constant value | ||
220 |
1/2✓ Branch 0 (6→7) taken 14 times.
✗ Branch 1 (6→16) not taken.
|
14 | ensureNoConstAssign(node, lhs.type); |
221 | |||
222 | // Remove reference wrappers | ||
223 |
1/2✓ Branch 0 (7→8) taken 14 times.
✗ Branch 1 (7→16) not taken.
|
14 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
224 |
1/2✓ Branch 0 (8→9) taken 14 times.
✗ Branch 1 (8→16) not taken.
|
14 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
225 | |||
226 |
1/2✓ Branch 0 (11→12) taken 14 times.
✗ Branch 1 (11→16) not taken.
|
14 | return {validateBinaryOperation(node, MUL_EQUAL_OP_RULES, std::size(MUL_EQUAL_OP_RULES), "*=", lhsType, rhsType)}; |
227 | } | ||
228 | |||
229 | 36 | ExprResult OpRuleManager::getDivEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) { | |
230 | // Check is there is an overloaded operator function available | ||
231 |
1/2✓ Branch 0 (2→3) taken 36 times.
✗ Branch 1 (2→15) not taken.
|
36 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_DIV_EQUAL, {lhs, rhs}, opIdx); |
232 |
3/4✓ Branch 0 (3→4) taken 36 times.
✗ Branch 1 (3→16) not taken.
✓ Branch 2 (4→5) taken 32 times.
✓ Branch 3 (4→6) taken 4 times.
|
36 | if (!resultType.type.is(TY_INVALID)) |
233 | 32 | return resultType; | |
234 | |||
235 | // Check if we try to assign a constant value | ||
236 |
1/2✓ Branch 0 (6→7) taken 4 times.
✗ Branch 1 (6→16) not taken.
|
4 | ensureNoConstAssign(node, lhs.type); |
237 | |||
238 | // Remove reference wrappers | ||
239 |
1/2✓ Branch 0 (7→8) taken 4 times.
✗ Branch 1 (7→16) not taken.
|
4 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
240 |
1/2✓ Branch 0 (8→9) taken 4 times.
✗ Branch 1 (8→16) not taken.
|
4 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
241 | |||
242 |
1/2✓ Branch 0 (11→12) taken 4 times.
✗ Branch 1 (11→16) not taken.
|
4 | return {validateBinaryOperation(node, DIV_EQUAL_OP_RULES, std::size(DIV_EQUAL_OP_RULES), "/=", lhsType, rhsType)}; |
243 | } | ||
244 | |||
245 | 6 | QualType OpRuleManager::getRemEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const { | |
246 | // Check if we try to assign a constant value | ||
247 |
1/2✓ Branch 0 (2→3) taken 6 times.
✗ Branch 1 (2→11) not taken.
|
6 | ensureNoConstAssign(node, lhs.type); |
248 | |||
249 | // Remove reference wrappers | ||
250 |
1/2✓ Branch 0 (3→4) taken 6 times.
✗ Branch 1 (3→11) not taken.
|
6 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
251 |
1/2✓ Branch 0 (4→5) taken 6 times.
✗ Branch 1 (4→11) not taken.
|
6 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
252 | |||
253 |
1/2✓ Branch 0 (7→8) taken 6 times.
✗ Branch 1 (7→11) not taken.
|
12 | return validateBinaryOperation(node, REM_EQUAL_OP_RULES, std::size(REM_EQUAL_OP_RULES), "%=", lhsType, rhsType); |
254 | } | ||
255 | |||
256 | 2 | QualType OpRuleManager::getSHLEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const { | |
257 | // Check if we try to assign a constant value | ||
258 |
1/2✓ Branch 0 (2→3) taken 2 times.
✗ Branch 1 (2→11) not taken.
|
2 | ensureNoConstAssign(node, lhs.type); |
259 | |||
260 | // Remove reference wrappers | ||
261 |
1/2✓ Branch 0 (3→4) taken 2 times.
✗ Branch 1 (3→11) not taken.
|
2 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
262 |
1/2✓ Branch 0 (4→5) taken 2 times.
✗ Branch 1 (4→11) not taken.
|
2 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
263 | |||
264 |
1/2✓ Branch 0 (7→8) taken 2 times.
✗ Branch 1 (7→11) not taken.
|
4 | return validateBinaryOperation(node, SHL_EQUAL_OP_RULES, std::size(SHL_EQUAL_OP_RULES), "<<=", lhsType, rhsType); |
265 | } | ||
266 | |||
267 | 3 | QualType OpRuleManager::getSHREqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const { | |
268 | // Check if we try to assign a constant value | ||
269 |
1/2✓ Branch 0 (2→3) taken 3 times.
✗ Branch 1 (2→11) not taken.
|
3 | ensureNoConstAssign(node, lhs.type); |
270 | |||
271 | // Remove reference wrappers | ||
272 |
1/2✓ Branch 0 (3→4) taken 3 times.
✗ Branch 1 (3→11) not taken.
|
3 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
273 |
1/2✓ Branch 0 (4→5) taken 3 times.
✗ Branch 1 (4→11) not taken.
|
3 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
274 | |||
275 |
1/2✓ Branch 0 (7→8) taken 3 times.
✗ Branch 1 (7→11) not taken.
|
6 | return validateBinaryOperation(node, SHR_EQUAL_OP_RULES, std::size(SHR_EQUAL_OP_RULES), ">>=", lhsType, rhsType); |
276 | } | ||
277 | |||
278 | 1 | QualType OpRuleManager::getAndEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const { | |
279 | // Check if we try to assign a constant value | ||
280 |
1/2✓ Branch 0 (2→3) taken 1 times.
✗ Branch 1 (2→11) not taken.
|
1 | ensureNoConstAssign(node, lhs.type); |
281 | |||
282 | // Remove reference wrappers | ||
283 |
1/2✓ Branch 0 (3→4) taken 1 times.
✗ Branch 1 (3→11) not taken.
|
1 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
284 |
1/2✓ Branch 0 (4→5) taken 1 times.
✗ Branch 1 (4→11) not taken.
|
1 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
285 | |||
286 |
1/2✓ Branch 0 (7→8) taken 1 times.
✗ Branch 1 (7→11) not taken.
|
2 | return validateBinaryOperation(node, AND_EQUAL_OP_RULES, std::size(AND_EQUAL_OP_RULES), "&=", lhsType, rhsType); |
287 | } | ||
288 | |||
289 | 1 | QualType OpRuleManager::getOrEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const { | |
290 | // Check if we try to assign a constant value | ||
291 |
1/2✓ Branch 0 (2→3) taken 1 times.
✗ Branch 1 (2→11) not taken.
|
1 | ensureNoConstAssign(node, lhs.type); |
292 | |||
293 | // Remove reference wrappers | ||
294 |
1/2✓ Branch 0 (3→4) taken 1 times.
✗ Branch 1 (3→11) not taken.
|
1 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
295 |
1/2✓ Branch 0 (4→5) taken 1 times.
✗ Branch 1 (4→11) not taken.
|
1 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
296 | |||
297 |
1/2✓ Branch 0 (7→8) taken 1 times.
✗ Branch 1 (7→11) not taken.
|
2 | return validateBinaryOperation(node, OR_EQUAL_OP_RULES, std::size(OR_EQUAL_OP_RULES), "|=", lhsType, rhsType); |
298 | } | ||
299 | |||
300 | 244 | QualType OpRuleManager::getXorEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) const { | |
301 | // Check if we try to assign a constant value | ||
302 |
1/2✓ Branch 0 (2→3) taken 244 times.
✗ Branch 1 (2→11) not taken.
|
244 | ensureNoConstAssign(node, lhs.type); |
303 | |||
304 | // Remove reference wrappers | ||
305 |
1/2✓ Branch 0 (3→4) taken 244 times.
✗ Branch 1 (3→11) not taken.
|
244 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
306 |
1/2✓ Branch 0 (4→5) taken 244 times.
✗ Branch 1 (4→11) not taken.
|
244 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
307 | |||
308 |
1/2✓ Branch 0 (7→8) taken 244 times.
✗ Branch 1 (7→11) not taken.
|
488 | return validateBinaryOperation(node, XOR_EQUAL_OP_RULES, std::size(XOR_EQUAL_OP_RULES), "^=", lhsType, rhsType); |
309 | } | ||
310 | |||
311 | 1054 | QualType OpRuleManager::getLogicalOrResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
312 | // Remove reference wrappers | ||
313 |
1/2✓ Branch 0 (2→3) taken 1054 times.
✗ Branch 1 (2→10) not taken.
|
1054 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
314 |
1/2✓ Branch 0 (3→4) taken 1054 times.
✗ Branch 1 (3→10) not taken.
|
1054 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
315 | |||
316 |
2/2✓ Branch 0 (6→7) taken 1053 times.
✓ Branch 1 (6→10) taken 1 times.
|
2107 | return validateBinaryOperation(node, LOGICAL_OR_OP_RULES, std::size(LOGICAL_OR_OP_RULES), "||", lhsType, rhsType); |
317 | } | ||
318 | |||
319 | 170 | QualType OpRuleManager::getLogicalAndResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
320 | // Remove reference wrappers | ||
321 |
1/2✓ Branch 0 (2→3) taken 170 times.
✗ Branch 1 (2→10) not taken.
|
170 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
322 |
1/2✓ Branch 0 (3→4) taken 170 times.
✗ Branch 1 (3→10) not taken.
|
170 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
323 | |||
324 |
1/2✓ Branch 0 (6→7) taken 170 times.
✗ Branch 1 (6→10) not taken.
|
340 | return validateBinaryOperation(node, LOGICAL_AND_OP_RULES, std::size(LOGICAL_AND_OP_RULES), "&&", lhsType, rhsType); |
325 | } | ||
326 | |||
327 | 68 | QualType OpRuleManager::getBitwiseOrResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
328 | // Remove reference wrappers | ||
329 |
1/2✓ Branch 0 (2→3) taken 68 times.
✗ Branch 1 (2→10) not taken.
|
68 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
330 |
1/2✓ Branch 0 (3→4) taken 68 times.
✗ Branch 1 (3→10) not taken.
|
68 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
331 | |||
332 |
2/2✓ Branch 0 (6→7) taken 67 times.
✓ Branch 1 (6→10) taken 1 times.
|
135 | return validateBinaryOperation(node, BITWISE_OR_OP_RULES, std::size(BITWISE_OR_OP_RULES), "|", lhsType, rhsType); |
333 | } | ||
334 | |||
335 | 7 | QualType OpRuleManager::getBitwiseXorResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
336 | // Remove reference wrappers | ||
337 |
1/2✓ Branch 0 (2→3) taken 7 times.
✗ Branch 1 (2→10) not taken.
|
7 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
338 |
1/2✓ Branch 0 (3→4) taken 7 times.
✗ Branch 1 (3→10) not taken.
|
7 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
339 | |||
340 |
1/2✓ Branch 0 (6→7) taken 7 times.
✗ Branch 1 (6→10) not taken.
|
14 | return validateBinaryOperation(node, BITWISE_XOR_OP_RULES, std::size(BITWISE_XOR_OP_RULES), "^", lhsType, rhsType); |
341 | } | ||
342 | |||
343 | 33 | QualType OpRuleManager::getBitwiseAndResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
344 | // Remove reference wrappers | ||
345 |
1/2✓ Branch 0 (2→3) taken 33 times.
✗ Branch 1 (2→10) not taken.
|
33 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
346 |
1/2✓ Branch 0 (3→4) taken 33 times.
✗ Branch 1 (3→10) not taken.
|
33 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
347 | |||
348 |
1/2✓ Branch 0 (6→7) taken 33 times.
✗ Branch 1 (6→10) not taken.
|
66 | return validateBinaryOperation(node, BITWISE_AND_OP_RULES, std::size(BITWISE_AND_OP_RULES), "&", lhsType, rhsType); |
349 | } | ||
350 | |||
351 | 3249 | ExprResult OpRuleManager::getEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) { | |
352 | // Check is there is an overloaded operator function available | ||
353 |
1/2✓ Branch 0 (2→3) taken 3249 times.
✗ Branch 1 (2→45) not taken.
|
3249 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_EQUAL, {lhs, rhs}, opIdx); |
354 |
3/4✓ Branch 0 (3→4) taken 3249 times.
✗ Branch 1 (3→46) not taken.
✓ Branch 2 (4→5) taken 386 times.
✓ Branch 3 (4→6) taken 2863 times.
|
3249 | if (!resultType.type.is(TY_INVALID)) |
355 | 386 | return resultType; | |
356 | |||
357 | // Remove reference wrappers | ||
358 |
1/2✓ Branch 0 (6→7) taken 2863 times.
✗ Branch 1 (6→46) not taken.
|
2863 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
359 |
1/2✓ Branch 0 (7→8) taken 2863 times.
✗ Branch 1 (7→46) not taken.
|
2863 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
360 | |||
361 | // Allow 'pointer == pointer' straight away | ||
362 |
7/10✓ Branch 0 (8→9) taken 2863 times.
✗ Branch 1 (8→46) not taken.
✓ Branch 2 (9→10) taken 772 times.
✓ Branch 3 (9→13) taken 2091 times.
✓ Branch 4 (10→11) taken 772 times.
✗ Branch 5 (10→46) not taken.
✓ Branch 6 (11→12) taken 772 times.
✗ Branch 7 (11→13) not taken.
✓ Branch 8 (14→15) taken 772 times.
✓ Branch 9 (14→17) taken 2091 times.
|
2863 | if (lhsType.isPtr() && rhsType.isPtr()) |
363 |
1/2✓ Branch 0 (15→16) taken 772 times.
✗ Branch 1 (15→46) not taken.
|
772 | return ExprResult(QualType(TY_BOOL)); |
364 | |||
365 | // Allow 'pointer == int' straight away | ||
366 |
3/10✓ Branch 0 (17→18) taken 2091 times.
✗ Branch 1 (17→46) not taken.
✗ Branch 2 (18→19) not taken.
✓ Branch 3 (18→22) taken 2091 times.
✗ Branch 4 (19→20) not taken.
✗ Branch 5 (19→46) not taken.
✗ Branch 6 (20→21) not taken.
✗ Branch 7 (20→22) not taken.
✗ Branch 8 (23→24) not taken.
✓ Branch 9 (23→26) taken 2091 times.
|
2091 | if (lhsType.isPtr() && rhsType.is(TY_INT)) |
367 | ✗ | return ExprResult(QualType(TY_BOOL)); | |
368 | |||
369 | // Allow 'string == char*' and vice versa straight away | ||
370 |
8/18✓ Branch 0 (26→27) taken 2091 times.
✗ Branch 1 (26→46) not taken.
✓ Branch 2 (27→28) taken 117 times.
✓ Branch 3 (27→30) taken 1974 times.
✓ Branch 4 (28→29) taken 117 times.
✗ Branch 5 (28→46) not taken.
✓ Branch 6 (29→30) taken 117 times.
✗ Branch 7 (29→34) not taken.
✓ Branch 8 (30→31) taken 2091 times.
✗ Branch 9 (30→46) not taken.
✗ Branch 10 (31→32) not taken.
✓ Branch 11 (31→35) taken 2091 times.
✗ Branch 12 (32→33) not taken.
✗ Branch 13 (32→46) not taken.
✗ Branch 14 (33→34) not taken.
✗ Branch 15 (33→35) not taken.
✗ Branch 16 (36→37) not taken.
✓ Branch 17 (36→39) taken 2091 times.
|
2091 | if ((lhsType.is(TY_STRING) && rhsType.isPtrTo(TY_CHAR)) || (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING))) |
371 | ✗ | return ExprResult(QualType(TY_BOOL)); | |
372 | |||
373 | // Check primitive type combinations | ||
374 |
2/2✓ Branch 0 (41→42) taken 2090 times.
✓ Branch 1 (41→46) taken 1 times.
|
2091 | return ExprResult(validateBinaryOperation(node, EQUAL_OP_RULES, std::size(EQUAL_OP_RULES), "==", lhsType, rhsType)); |
375 | } | ||
376 | |||
377 | 1378 | ExprResult OpRuleManager::getNotEqualResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) { | |
378 | // Check is there is an overloaded operator function available | ||
379 |
1/2✓ Branch 0 (2→3) taken 1378 times.
✗ Branch 1 (2→45) not taken.
|
1378 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_NOT_EQUAL, {lhs, rhs}, opIdx); |
380 |
3/4✓ Branch 0 (3→4) taken 1378 times.
✗ Branch 1 (3→46) not taken.
✓ Branch 2 (4→5) taken 10 times.
✓ Branch 3 (4→6) taken 1368 times.
|
1378 | if (!resultType.type.is(TY_INVALID)) |
381 | 10 | return resultType; | |
382 | |||
383 | // Remove reference wrappers | ||
384 |
1/2✓ Branch 0 (6→7) taken 1368 times.
✗ Branch 1 (6→46) not taken.
|
1368 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
385 |
1/2✓ Branch 0 (7→8) taken 1368 times.
✗ Branch 1 (7→46) not taken.
|
1368 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
386 | |||
387 | // Allow 'pointer != pointer' straight away | ||
388 |
7/10✓ Branch 0 (8→9) taken 1368 times.
✗ Branch 1 (8→46) not taken.
✓ Branch 2 (9→10) taken 152 times.
✓ Branch 3 (9→13) taken 1216 times.
✓ Branch 4 (10→11) taken 152 times.
✗ Branch 5 (10→46) not taken.
✓ Branch 6 (11→12) taken 152 times.
✗ Branch 7 (11→13) not taken.
✓ Branch 8 (14→15) taken 152 times.
✓ Branch 9 (14→17) taken 1216 times.
|
1368 | if (lhsType.isPtr() && rhsType.isPtr()) |
389 |
1/2✓ Branch 0 (15→16) taken 152 times.
✗ Branch 1 (15→46) not taken.
|
152 | return ExprResult(QualType(TY_BOOL)); |
390 | |||
391 | // Allow 'pointer != int' straight away | ||
392 |
3/10✓ Branch 0 (17→18) taken 1216 times.
✗ Branch 1 (17→46) not taken.
✗ Branch 2 (18→19) not taken.
✓ Branch 3 (18→22) taken 1216 times.
✗ Branch 4 (19→20) not taken.
✗ Branch 5 (19→46) not taken.
✗ Branch 6 (20→21) not taken.
✗ Branch 7 (20→22) not taken.
✗ Branch 8 (23→24) not taken.
✓ Branch 9 (23→26) taken 1216 times.
|
1216 | if (lhsType.isPtr() && rhsType.is(TY_INT)) |
393 | ✗ | return ExprResult(QualType(TY_BOOL)); | |
394 | |||
395 | // Allow 'string != char*' and vice versa straight away | ||
396 |
8/18✓ Branch 0 (26→27) taken 1216 times.
✗ Branch 1 (26→46) not taken.
✓ Branch 2 (27→28) taken 9 times.
✓ Branch 3 (27→30) taken 1207 times.
✓ Branch 4 (28→29) taken 9 times.
✗ Branch 5 (28→46) not taken.
✓ Branch 6 (29→30) taken 9 times.
✗ Branch 7 (29→34) not taken.
✓ Branch 8 (30→31) taken 1216 times.
✗ Branch 9 (30→46) not taken.
✗ Branch 10 (31→32) not taken.
✓ Branch 11 (31→35) taken 1216 times.
✗ Branch 12 (32→33) not taken.
✗ Branch 13 (32→46) not taken.
✗ Branch 14 (33→34) not taken.
✗ Branch 15 (33→35) not taken.
✗ Branch 16 (36→37) not taken.
✓ Branch 17 (36→39) taken 1216 times.
|
1216 | if ((lhsType.is(TY_STRING) && rhsType.isPtrTo(TY_CHAR)) || (lhsType.isPtrTo(TY_CHAR) && rhsType.is(TY_STRING))) |
397 | ✗ | return ExprResult(QualType(TY_BOOL)); | |
398 | |||
399 | // Check primitive type combinations | ||
400 |
1/2✓ Branch 0 (41→42) taken 1216 times.
✗ Branch 1 (41→46) not taken.
|
1216 | return ExprResult(validateBinaryOperation(node, NOT_EQUAL_OP_RULES, std::size(NOT_EQUAL_OP_RULES), "!=", lhsType, rhsType)); |
401 | } | ||
402 | |||
403 | 1616 | QualType OpRuleManager::getLessResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
404 | // Remove reference wrappers | ||
405 |
1/2✓ Branch 0 (2→3) taken 1616 times.
✗ Branch 1 (2→10) not taken.
|
1616 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
406 |
1/2✓ Branch 0 (3→4) taken 1616 times.
✗ Branch 1 (3→10) not taken.
|
1616 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
407 | |||
408 |
1/2✓ Branch 0 (6→7) taken 1616 times.
✗ Branch 1 (6→10) not taken.
|
3232 | return validateBinaryOperation(node, LESS_OP_RULES, std::size(LESS_OP_RULES), "<", lhsType, rhsType); |
409 | } | ||
410 | |||
411 | 388 | QualType OpRuleManager::getGreaterResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
412 | // Remove reference wrappers | ||
413 |
1/2✓ Branch 0 (2→3) taken 388 times.
✗ Branch 1 (2→10) not taken.
|
388 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
414 |
1/2✓ Branch 0 (3→4) taken 388 times.
✗ Branch 1 (3→10) not taken.
|
388 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
415 | |||
416 |
2/2✓ Branch 0 (6→7) taken 387 times.
✓ Branch 1 (6→10) taken 1 times.
|
775 | return validateBinaryOperation(node, GREATER_OP_RULES, std::size(GREATER_OP_RULES), ">", lhsType, rhsType); |
417 | } | ||
418 | |||
419 | 344 | QualType OpRuleManager::getLessEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
420 | // Remove reference wrappers | ||
421 |
1/2✓ Branch 0 (2→3) taken 344 times.
✗ Branch 1 (2→10) not taken.
|
344 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
422 |
1/2✓ Branch 0 (3→4) taken 344 times.
✗ Branch 1 (3→10) not taken.
|
344 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
423 | |||
424 |
1/2✓ Branch 0 (6→7) taken 344 times.
✗ Branch 1 (6→10) not taken.
|
688 | return validateBinaryOperation(node, LESS_EQUAL_OP_RULES, std::size(LESS_EQUAL_OP_RULES), "<=", lhsType, rhsType); |
425 | } | ||
426 | |||
427 | 810 | QualType OpRuleManager::getGreaterEqualResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
428 | // Remove reference wrappers | ||
429 |
1/2✓ Branch 0 (2→3) taken 810 times.
✗ Branch 1 (2→10) not taken.
|
810 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
430 |
1/2✓ Branch 0 (3→4) taken 810 times.
✗ Branch 1 (3→10) not taken.
|
810 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
431 | |||
432 |
1/2✓ Branch 0 (6→7) taken 810 times.
✗ Branch 1 (6→10) not taken.
|
1620 | return validateBinaryOperation(node, GREATER_EQUAL_OP_RULES, std::size(GREATER_EQUAL_OP_RULES), ">=", lhsType, rhsType); |
433 | } | ||
434 | |||
435 | 56 | ExprResult OpRuleManager::getShiftLeftResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) { | |
436 | // Check is there is an overloaded operator function available | ||
437 |
1/2✓ Branch 0 (2→3) taken 56 times.
✗ Branch 1 (2→14) not taken.
|
56 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_SHL, {lhs, rhs}, opIdx); |
438 |
3/4✓ Branch 0 (3→4) taken 56 times.
✗ Branch 1 (3→15) not taken.
✓ Branch 2 (4→5) taken 47 times.
✓ Branch 3 (4→6) taken 9 times.
|
56 | if (!resultType.type.is(TY_INVALID)) |
439 | 47 | return resultType; | |
440 | |||
441 | // Remove reference wrappers | ||
442 |
1/2✓ Branch 0 (6→7) taken 9 times.
✗ Branch 1 (6→15) not taken.
|
9 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
443 |
1/2✓ Branch 0 (7→8) taken 9 times.
✗ Branch 1 (7→15) not taken.
|
9 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
444 | |||
445 |
1/2✓ Branch 0 (10→11) taken 9 times.
✗ Branch 1 (10→15) not taken.
|
9 | return {validateBinaryOperation(node, SHIFT_LEFT_OP_RULES, std::size(SHIFT_LEFT_OP_RULES), "<<", lhsType, rhsType)}; |
446 | } | ||
447 | |||
448 | 7 | ExprResult OpRuleManager::getShiftRightResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) { | |
449 | // Check is there is an overloaded operator function available | ||
450 |
1/2✓ Branch 0 (2→3) taken 7 times.
✗ Branch 1 (2→14) not taken.
|
7 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_SHR, {lhs, rhs}, opIdx); |
451 |
3/4✓ Branch 0 (3→4) taken 7 times.
✗ Branch 1 (3→15) not taken.
✓ Branch 2 (4→5) taken 1 times.
✓ Branch 3 (4→6) taken 6 times.
|
7 | if (!resultType.type.is(TY_INVALID)) |
452 | 1 | return resultType; | |
453 | |||
454 | // Remove reference wrappers | ||
455 |
1/2✓ Branch 0 (6→7) taken 6 times.
✗ Branch 1 (6→15) not taken.
|
6 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
456 |
1/2✓ Branch 0 (7→8) taken 6 times.
✗ Branch 1 (7→15) not taken.
|
6 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
457 | |||
458 |
1/2✓ Branch 0 (10→11) taken 6 times.
✗ Branch 1 (10→15) not taken.
|
6 | return {validateBinaryOperation(node, SHIFT_RIGHT_OP_RULES, std::size(SHIFT_RIGHT_OP_RULES), ">>", lhsType, rhsType)}; |
459 | } | ||
460 | |||
461 | 2500 | ExprResult OpRuleManager::getPlusResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) { | |
462 | // Check is there is an overloaded operator function available | ||
463 |
1/2✓ Branch 0 (2→3) taken 2500 times.
✗ Branch 1 (2→32) not taken.
|
2500 | const ExprResult result = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_PLUS, {lhs, rhs}, opIdx); |
464 |
3/4✓ Branch 0 (3→4) taken 2500 times.
✗ Branch 1 (3→35) not taken.
✓ Branch 2 (4→5) taken 48 times.
✓ Branch 3 (4→6) taken 2452 times.
|
2500 | if (!result.type.is(TY_INVALID)) |
465 | 48 | return result; | |
466 | |||
467 | // Remove reference wrappers | ||
468 |
1/2✓ Branch 0 (6→7) taken 2452 times.
✗ Branch 1 (6→35) not taken.
|
2452 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
469 |
1/2✓ Branch 0 (7→8) taken 2452 times.
✗ Branch 1 (7→35) not taken.
|
2452 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
470 | |||
471 | // Allow any* + <int/long/short> | ||
472 |
7/10✓ Branch 0 (8→9) taken 2452 times.
✗ Branch 1 (8→33) not taken.
✓ Branch 2 (9→10) taken 486 times.
✓ Branch 3 (9→13) taken 1966 times.
✓ Branch 4 (10→11) taken 486 times.
✗ Branch 5 (10→33) not taken.
✓ Branch 6 (11→12) taken 486 times.
✗ Branch 7 (11→13) not taken.
✓ Branch 8 (14→15) taken 486 times.
✓ Branch 9 (14→17) taken 1966 times.
|
2452 | if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) { |
473 |
1/2✓ Branch 0 (15→16) taken 486 times.
✗ Branch 1 (15→35) not taken.
|
486 | ensureUnsafeAllowed(node, "+", lhsType, rhsType); |
474 | 486 | return {lhsType}; | |
475 | } | ||
476 | // Allow <int/long/short> + any* | ||
477 |
6/10✓ Branch 0 (17→18) taken 1966 times.
✗ Branch 1 (17→34) not taken.
✓ Branch 2 (18→19) taken 1931 times.
✓ Branch 3 (18→22) taken 35 times.
✓ Branch 4 (19→20) taken 1931 times.
✗ Branch 5 (19→34) not taken.
✗ Branch 6 (20→21) not taken.
✓ Branch 7 (20→22) taken 1931 times.
✗ Branch 8 (23→24) not taken.
✓ Branch 9 (23→26) taken 1966 times.
|
1966 | if (lhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT}) && rhsType.isPtr()) { |
478 | ✗ | ensureUnsafeAllowed(node, "+", lhsType, rhsType); | |
479 | ✗ | return {rhsType}; | |
480 | } | ||
481 | |||
482 |
2/2✓ Branch 0 (28→29) taken 1965 times.
✓ Branch 1 (28→35) taken 1 times.
|
1966 | return {validateBinaryOperation(node, PLUS_OP_RULES, std::size(PLUS_OP_RULES), "+", lhsType, rhsType)}; |
483 | } | ||
484 | |||
485 | 1678 | ExprResult OpRuleManager::getMinusResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) { | |
486 | // Check is there is an overloaded operator function available | ||
487 |
1/2✓ Branch 0 (2→3) taken 1678 times.
✗ Branch 1 (2→32) not taken.
|
1678 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MINUS, {lhs, rhs}, opIdx); |
488 |
3/4✓ Branch 0 (3→4) taken 1678 times.
✗ Branch 1 (3→35) not taken.
✓ Branch 2 (4→5) taken 1 times.
✓ Branch 3 (4→6) taken 1677 times.
|
1678 | if (!resultType.type.is(TY_INVALID)) |
489 | 1 | return resultType; | |
490 | |||
491 | // Remove reference wrappers | ||
492 |
1/2✓ Branch 0 (6→7) taken 1677 times.
✗ Branch 1 (6→35) not taken.
|
1677 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
493 |
1/2✓ Branch 0 (7→8) taken 1677 times.
✗ Branch 1 (7→35) not taken.
|
1677 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
494 | |||
495 | // Allow any* - <int/long/short> | ||
496 |
3/10✓ Branch 0 (8→9) taken 1677 times.
✗ Branch 1 (8→33) not taken.
✗ Branch 2 (9→10) not taken.
✓ Branch 3 (9→13) taken 1677 times.
✗ Branch 4 (10→11) not taken.
✗ Branch 5 (10→33) not taken.
✗ Branch 6 (11→12) not taken.
✗ Branch 7 (11→13) not taken.
✗ Branch 8 (14→15) not taken.
✓ Branch 9 (14→17) taken 1677 times.
|
1677 | if (lhsType.isPtr() && rhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) { |
497 | ✗ | ensureUnsafeAllowed(node, "-", lhsType, rhsType); | |
498 | ✗ | return {lhs}; | |
499 | } | ||
500 | // Allow <int/long/short> - any* | ||
501 |
6/10✓ Branch 0 (17→18) taken 1677 times.
✗ Branch 1 (17→34) not taken.
✓ Branch 2 (18→19) taken 1669 times.
✓ Branch 3 (18→22) taken 8 times.
✓ Branch 4 (19→20) taken 1669 times.
✗ Branch 5 (19→34) not taken.
✗ Branch 6 (20→21) not taken.
✓ Branch 7 (20→22) taken 1669 times.
✗ Branch 8 (23→24) not taken.
✓ Branch 9 (23→26) taken 1677 times.
|
1677 | if (lhsType.isOneOf({TY_INT, TY_LONG, TY_SHORT}) && rhsType.isPtr()) { |
502 | ✗ | ensureUnsafeAllowed(node, "-", lhsType, rhsType); | |
503 | ✗ | return {rhs}; | |
504 | } | ||
505 | |||
506 |
1/2✓ Branch 0 (28→29) taken 1677 times.
✗ Branch 1 (28→35) not taken.
|
1677 | return {validateBinaryOperation(node, MINUS_OP_RULES, std::size(MINUS_OP_RULES), "-", lhsType, rhsType)}; |
507 | } | ||
508 | |||
509 | 691 | ExprResult OpRuleManager::getMulResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) { | |
510 | // Check is there is an overloaded operator function available | ||
511 |
1/2✓ Branch 0 (2→3) taken 691 times.
✗ Branch 1 (2→14) not taken.
|
691 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_MUL, {lhs, rhs}, opIdx); |
512 |
3/4✓ Branch 0 (3→4) taken 691 times.
✗ Branch 1 (3→15) not taken.
✓ Branch 2 (4→5) taken 9 times.
✓ Branch 3 (4→6) taken 682 times.
|
691 | if (!resultType.type.is(TY_INVALID)) |
513 | 9 | return resultType; | |
514 | |||
515 | // Remove reference wrappers | ||
516 |
1/2✓ Branch 0 (6→7) taken 682 times.
✗ Branch 1 (6→15) not taken.
|
682 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
517 |
1/2✓ Branch 0 (7→8) taken 682 times.
✗ Branch 1 (7→15) not taken.
|
682 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
518 | |||
519 |
2/2✓ Branch 0 (10→11) taken 681 times.
✓ Branch 1 (10→15) taken 1 times.
|
682 | return {validateBinaryOperation(node, MUL_OP_RULES, std::size(MUL_OP_RULES), "*", lhsType, rhsType)}; |
520 | } | ||
521 | |||
522 | 217 | ExprResult OpRuleManager::getDivResultType(ASTNode *node, const ExprResult &lhs, const ExprResult &rhs, size_t opIdx) { | |
523 | // Check is there is an overloaded operator function available | ||
524 |
1/2✓ Branch 0 (2→3) taken 217 times.
✗ Branch 1 (2→14) not taken.
|
217 | const ExprResult resultType = isOperatorOverloadingFctAvailable<2>(node, OP_FCT_DIV, {lhs, rhs}, opIdx); |
525 |
3/4✓ Branch 0 (3→4) taken 217 times.
✗ Branch 1 (3→15) not taken.
✓ Branch 2 (4→5) taken 3 times.
✓ Branch 3 (4→6) taken 214 times.
|
217 | if (!resultType.type.is(TY_INVALID)) |
526 | 3 | return resultType; | |
527 | |||
528 | // Remove reference wrappers | ||
529 |
1/2✓ Branch 0 (6→7) taken 214 times.
✗ Branch 1 (6→15) not taken.
|
214 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
530 |
1/2✓ Branch 0 (7→8) taken 214 times.
✗ Branch 1 (7→15) not taken.
|
214 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
531 | |||
532 |
1/2✓ Branch 0 (10→11) taken 214 times.
✗ Branch 1 (10→15) not taken.
|
214 | return {validateBinaryOperation(node, DIV_OP_RULES, std::size(DIV_OP_RULES), "/", lhsType, rhsType)}; |
533 | } | ||
534 | |||
535 | 9 | ExprResult OpRuleManager::getRemResultType(const ASTNode *node, const ExprResult &lhs, const ExprResult &rhs) { | |
536 | // Remove reference wrappers | ||
537 |
1/2✓ Branch 0 (2→3) taken 9 times.
✗ Branch 1 (2→10) not taken.
|
9 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
538 |
1/2✓ Branch 0 (3→4) taken 9 times.
✗ Branch 1 (3→10) not taken.
|
9 | const QualType rhsType = rhs.type.removeReferenceWrapper(); |
539 | |||
540 |
1/2✓ Branch 0 (6→7) taken 9 times.
✗ Branch 1 (6→10) not taken.
|
18 | return {validateBinaryOperation(node, REM_OP_RULES, std::size(REM_OP_RULES), "%", lhsType, rhsType)}; |
541 | } | ||
542 | |||
543 | 16 | QualType OpRuleManager::getPrefixMinusResultType(const ASTNode *node, const ExprResult &lhs) { | |
544 | // Remove reference wrappers | ||
545 |
1/2✓ Branch 0 (2→3) taken 16 times.
✗ Branch 1 (2→9) not taken.
|
16 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
546 | |||
547 |
1/2✓ Branch 0 (5→6) taken 16 times.
✗ Branch 1 (5→9) not taken.
|
32 | return validateUnaryOperation(node, PREFIX_MINUS_OP_RULES, std::size(PREFIX_MINUS_OP_RULES), "-", lhsType); |
548 | } | ||
549 | |||
550 | 33 | QualType OpRuleManager::getPrefixPlusPlusResultType(const ASTNode *node, const ExprResult &lhs) const { | |
551 | // Check if we try to assign a constant value | ||
552 |
1/2✓ Branch 0 (2→3) taken 33 times.
✗ Branch 1 (2→14) not taken.
|
33 | ensureNoConstAssign(node, lhs.type); |
553 | |||
554 | // Remove reference wrappers | ||
555 |
1/2✓ Branch 0 (3→4) taken 33 times.
✗ Branch 1 (3→14) not taken.
|
33 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
556 | |||
557 | // Check if this is an unsafe operation | ||
558 |
2/4✓ Branch 0 (4→5) taken 33 times.
✗ Branch 1 (4→14) not taken.
✗ Branch 2 (5→6) not taken.
✓ Branch 3 (5→8) taken 33 times.
|
33 | if (lhsType.isPtr()) { |
559 | ✗ | ensureUnsafeAllowed(node, "++", lhsType); | |
560 | ✗ | return lhsType; | |
561 | } | ||
562 | |||
563 |
1/2✓ Branch 0 (10→11) taken 33 times.
✗ Branch 1 (10→14) not taken.
|
33 | return validateUnaryOperation(node, PREFIX_PLUS_PLUS_OP_RULES, std::size(PREFIX_PLUS_PLUS_OP_RULES), "++", lhsType); |
564 | } | ||
565 | |||
566 | 8 | QualType OpRuleManager::getPrefixMinusMinusResultType(const ASTNode *node, const ExprResult &lhs) const { | |
567 | // Check if we try to assign a constant value | ||
568 |
1/2✓ Branch 0 (2→3) taken 8 times.
✗ Branch 1 (2→14) not taken.
|
8 | ensureNoConstAssign(node, lhs.type); |
569 | |||
570 | // Remove reference wrappers | ||
571 |
1/2✓ Branch 0 (3→4) taken 8 times.
✗ Branch 1 (3→14) not taken.
|
8 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
572 | |||
573 | // Check if this is an unsafe operation | ||
574 |
2/4✓ Branch 0 (4→5) taken 8 times.
✗ Branch 1 (4→14) not taken.
✗ Branch 2 (5→6) not taken.
✓ Branch 3 (5→8) taken 8 times.
|
8 | if (lhsType.isPtr()) { |
575 | ✗ | ensureUnsafeAllowed(node, "--", lhsType); | |
576 | ✗ | return lhsType; | |
577 | } | ||
578 | |||
579 |
2/2✓ Branch 0 (10→11) taken 7 times.
✓ Branch 1 (10→14) taken 1 times.
|
8 | return validateUnaryOperation(node, PREFIX_MINUS_MINUS_OP_RULES, std::size(PREFIX_MINUS_MINUS_OP_RULES), "--", lhsType); |
580 | } | ||
581 | |||
582 | 630 | QualType OpRuleManager::getPrefixNotResultType(const ASTNode *node, const ExprResult &lhs) { | |
583 | // Remove reference wrappers | ||
584 |
1/2✓ Branch 0 (2→3) taken 630 times.
✗ Branch 1 (2→9) not taken.
|
630 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
585 | |||
586 |
1/2✓ Branch 0 (5→6) taken 630 times.
✗ Branch 1 (5→9) not taken.
|
1260 | return validateUnaryOperation(node, PREFIX_NOT_OP_RULES, std::size(PREFIX_NOT_OP_RULES), "!", lhsType); |
587 | } | ||
588 | |||
589 | 1 | QualType OpRuleManager::getPrefixBitwiseNotResultType(const ASTNode *node, const ExprResult &lhs) { | |
590 | // Remove reference wrappers | ||
591 |
1/2✓ Branch 0 (2→3) taken 1 times.
✗ Branch 1 (2→9) not taken.
|
1 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
592 | |||
593 |
1/2✓ Branch 0 (5→6) taken 1 times.
✗ Branch 1 (5→9) not taken.
|
2 | return validateUnaryOperation(node, PREFIX_BITWISE_NOT_OP_RULES, std::size(PREFIX_BITWISE_NOT_OP_RULES), "~", lhsType); |
594 | } | ||
595 | |||
596 | 173 | QualType OpRuleManager::getPrefixMulResultType(const ASTNode *node, const ExprResult &lhs) { | |
597 | // Remove reference wrappers | ||
598 |
1/2✓ Branch 0 (2→3) taken 173 times.
✗ Branch 1 (2→25) not taken.
|
173 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
599 | |||
600 |
2/4✓ Branch 0 (3→4) taken 173 times.
✗ Branch 1 (3→25) not taken.
✗ Branch 2 (4→5) not taken.
✓ Branch 3 (4→12) taken 173 times.
|
173 | if (!lhsType.isPtr()) |
601 | ✗ | throw SemanticError(node, OPERATOR_WRONG_DATA_TYPE, "Cannot apply de-referencing operator on type " + lhsType.getName(true)); | |
602 |
1/2✓ Branch 0 (12→13) taken 173 times.
✗ Branch 1 (12→25) not taken.
|
346 | return lhsType.getContained(); |
603 | } | ||
604 | |||
605 | 79 | QualType OpRuleManager::getPrefixBitwiseAndResultType(const ASTNode *node, const ExprResult &lhs) { | |
606 | // Remove reference wrappers | ||
607 |
1/2✓ Branch 0 (2→3) taken 79 times.
✗ Branch 1 (2→7) not taken.
|
79 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
608 | |||
609 |
1/2✓ Branch 0 (3→4) taken 79 times.
✗ Branch 1 (3→7) not taken.
|
158 | return lhsType.toPtr(node); |
610 | } | ||
611 | |||
612 | 1570 | ExprResult OpRuleManager::getPostfixPlusPlusResultType(ASTNode *node, const ExprResult &lhs, size_t opIdx) { | |
613 | // Check is there is an overloaded operator function available | ||
614 |
1/2✓ Branch 0 (2→3) taken 1570 times.
✗ Branch 1 (2→18) not taken.
|
1570 | const ExprResult resultType = isOperatorOverloadingFctAvailable<1>(node, OP_FCT_POSTFIX_PLUS_PLUS, {lhs}, opIdx); |
615 |
3/4✓ Branch 0 (3→4) taken 1570 times.
✗ Branch 1 (3→19) not taken.
✓ Branch 2 (4→5) taken 9 times.
✓ Branch 3 (4→6) taken 1561 times.
|
1570 | if (!resultType.type.is(TY_INVALID)) |
616 | 9 | return resultType; | |
617 | |||
618 | // Check if we try to assign a constant value | ||
619 |
1/2✓ Branch 0 (6→7) taken 1561 times.
✗ Branch 1 (6→19) not taken.
|
1561 | ensureNoConstAssign(node, lhs.type); |
620 | |||
621 | // Remove reference wrappers | ||
622 |
1/2✓ Branch 0 (7→8) taken 1561 times.
✗ Branch 1 (7→19) not taken.
|
1561 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
623 | |||
624 | // Check if this is an unsafe operation | ||
625 |
3/4✓ Branch 0 (8→9) taken 1561 times.
✗ Branch 1 (8→19) not taken.
✓ Branch 2 (9→10) taken 1 times.
✓ Branch 3 (9→12) taken 1560 times.
|
1561 | if (lhsType.isPtr()) { |
626 |
1/2✓ Branch 0 (10→11) taken 1 times.
✗ Branch 1 (10→19) not taken.
|
1 | ensureUnsafeAllowed(node, "++", lhsType); |
627 | 1 | return {lhs}; | |
628 | } | ||
629 | |||
630 |
2/2✓ Branch 0 (14→15) taken 1559 times.
✓ Branch 1 (14→19) taken 1 times.
|
1560 | return {validateUnaryOperation(node, POSTFIX_PLUS_PLUS_OP_RULES, std::size(POSTFIX_PLUS_PLUS_OP_RULES), "++", lhsType)}; |
631 | } | ||
632 | |||
633 | 367 | ExprResult OpRuleManager::getPostfixMinusMinusResultType(ASTNode *node, const ExprResult &lhs, size_t opIdx) { | |
634 | // Check is there is an overloaded operator function available | ||
635 |
1/2✓ Branch 0 (2→3) taken 367 times.
✗ Branch 1 (2→18) not taken.
|
367 | const ExprResult resultType = isOperatorOverloadingFctAvailable<1>(node, OP_FCT_POSTFIX_MINUS_MINUS, {lhs}, opIdx); |
636 |
3/4✓ Branch 0 (3→4) taken 367 times.
✗ Branch 1 (3→19) not taken.
✓ Branch 2 (4→5) taken 7 times.
✓ Branch 3 (4→6) taken 360 times.
|
367 | if (!resultType.type.is(TY_INVALID)) |
637 | 7 | return resultType; | |
638 | |||
639 | // Check if we try to assign a constant value | ||
640 |
1/2✓ Branch 0 (6→7) taken 360 times.
✗ Branch 1 (6→19) not taken.
|
360 | ensureNoConstAssign(node, lhs.type); |
641 | |||
642 | // Remove reference wrappers | ||
643 |
1/2✓ Branch 0 (7→8) taken 360 times.
✗ Branch 1 (7→19) not taken.
|
360 | const QualType lhsType = lhs.type.removeReferenceWrapper(); |
644 | |||
645 | // Check if this is an unsafe operation | ||
646 |
3/4✓ Branch 0 (8→9) taken 360 times.
✗ Branch 1 (8→19) not taken.
✓ Branch 2 (9→10) taken 1 times.
✓ Branch 3 (9→12) taken 359 times.
|
360 | if (lhsType.isPtr()) { |
647 |
1/2✓ Branch 0 (10→11) taken 1 times.
✗ Branch 1 (10→19) not taken.
|
1 | ensureUnsafeAllowed(node, "--", lhsType); |
648 | 1 | return {lhs}; | |
649 | } | ||
650 | |||
651 |
1/2✓ Branch 0 (14→15) taken 359 times.
✗ Branch 1 (14→19) not taken.
|
359 | return {validateUnaryOperation(node, POSTFIX_MINUS_MINUS_OP_RULES, std::size(POSTFIX_MINUS_MINUS_OP_RULES), "--", lhsType)}; |
652 | } | ||
653 | |||
654 | 2721 | QualType OpRuleManager::getCastResultType(const ASTNode *node, QualType lhsType, const ExprResult &rhs) const { | |
655 | // Remove reference wrappers | ||
656 |
1/2✓ Branch 0 (2→3) taken 2721 times.
✗ Branch 1 (2→50) not taken.
|
2721 | lhsType = lhsType.removeReferenceWrapper(); |
657 |
1/2✓ Branch 0 (3→4) taken 2721 times.
✗ Branch 1 (3→57) not taken.
|
2721 | QualType rhsType = rhs.type.removeReferenceWrapper(); |
658 | |||
659 | // Only allow to cast the 'heap' qualifier away, if we are in unsafe mode | ||
660 |
2/2✓ Branch 0 (6→7) taken 97 times.
✓ Branch 1 (6→8) taken 2624 times.
|
2721 | if (lhsType.getQualifiers().isHeap != rhsType.getQualifiers().isHeap) |
661 |
1/2✓ Branch 0 (7→8) taken 97 times.
✗ Branch 1 (7→57) not taken.
|
97 | ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType); |
662 | |||
663 | // Allow identity casts | ||
664 |
3/4✓ Branch 0 (8→9) taken 2721 times.
✗ Branch 1 (8→57) not taken.
✓ Branch 2 (9→10) taken 1190 times.
✓ Branch 3 (9→11) taken 1531 times.
|
2721 | if (lhsType.matches(rhsType, false, true, true)) |
665 | 1190 | return lhsType; | |
666 | // Allow casts string -> char* and string -> char[] | ||
667 |
12/16✓ Branch 0 (11→12) taken 1531 times.
✗ Branch 1 (11→51) not taken.
✓ Branch 2 (12→13) taken 965 times.
✓ Branch 3 (12→19) taken 566 times.
✓ Branch 4 (13→14) taken 965 times.
✗ Branch 5 (13→51) not taken.
✓ Branch 6 (14→15) taken 965 times.
✗ Branch 7 (14→51) not taken.
✓ Branch 8 (15→16) taken 745 times.
✓ Branch 9 (15→19) taken 220 times.
✓ Branch 10 (16→17) taken 745 times.
✗ Branch 11 (16→51) not taken.
✓ Branch 12 (17→18) taken 741 times.
✓ Branch 13 (17→19) taken 4 times.
✓ Branch 14 (20→21) taken 741 times.
✓ Branch 15 (20→22) taken 790 times.
|
1531 | if (lhsType.isOneOf({TY_PTR, TY_ARRAY}) && lhsType.getContained().is(TY_CHAR) && rhsType.is(TY_STRING)) |
668 | 741 | return lhsType; | |
669 | // Allow casts char* -> string and char[] -> string | ||
670 |
10/16✓ Branch 0 (22→23) taken 790 times.
✗ Branch 1 (22→53) not taken.
✓ Branch 2 (23→24) taken 81 times.
✓ Branch 3 (23→30) taken 709 times.
✓ Branch 4 (24→25) taken 81 times.
✗ Branch 5 (24→53) not taken.
✓ Branch 6 (25→26) taken 81 times.
✗ Branch 7 (25→30) not taken.
✓ Branch 8 (26→27) taken 81 times.
✗ Branch 9 (26→53) not taken.
✓ Branch 10 (27→28) taken 81 times.
✗ Branch 11 (27→53) not taken.
✓ Branch 12 (28→29) taken 81 times.
✗ Branch 13 (28→30) not taken.
✓ Branch 14 (31→32) taken 81 times.
✓ Branch 15 (31→33) taken 709 times.
|
790 | if (lhsType.is(TY_STRING) && rhsType.isOneOf({TY_PTR, TY_ARRAY}) && rhsType.getContained().is(TY_CHAR)) |
671 | 81 | return lhsType; | |
672 | // Allow casts any* -> any* | ||
673 |
7/10✓ Branch 0 (33→34) taken 709 times.
✗ Branch 1 (33→55) not taken.
✓ Branch 2 (34→35) taken 224 times.
✓ Branch 3 (34→38) taken 485 times.
✓ Branch 4 (35→36) taken 224 times.
✗ Branch 5 (35→55) not taken.
✓ Branch 6 (36→37) taken 224 times.
✗ Branch 7 (36→38) not taken.
✓ Branch 8 (39→40) taken 224 times.
✓ Branch 9 (39→44) taken 485 times.
|
709 | if (lhsType.isOneOf({TY_PTR, TY_STRING}) && rhsType.isOneOf({TY_PTR, TY_STRING})) { |
674 |
2/4✓ Branch 0 (40→41) taken 224 times.
✗ Branch 1 (40→57) not taken.
✓ Branch 2 (41→42) taken 224 times.
✗ Branch 3 (41→43) not taken.
|
224 | if (lhsType != rhsType) |
675 |
1/2✓ Branch 0 (42→43) taken 224 times.
✗ Branch 1 (42→57) not taken.
|
224 | ensureUnsafeAllowed(node, "(cast)", lhsType, rhsType); |
676 | 224 | return lhsType; | |
677 | } | ||
678 | // Check primitive type combinations | ||
679 |
1/2✓ Branch 0 (46→47) taken 485 times.
✗ Branch 1 (46→57) not taken.
|
485 | return validateBinaryOperation(node, CAST_OP_RULES, std::size(CAST_OP_RULES), "(cast)", lhsType, rhsType, true); |
680 | } | ||
681 | |||
682 | template <size_t N> | ||
683 | 14999 | ExprResult OpRuleManager::isOperatorOverloadingFctAvailable(ASTNode *node, const char *const fctName, | |
684 | const std::array<ExprResult, N> &op, size_t opIdx) { | ||
685 | static_assert(N == 1 || N == 2, "Only unary and binary operators are overloadable"); | ||
686 | 14999 | Scope *calleeParentScope = nullptr; | |
687 | 14999 | const Function *callee = nullptr; | |
688 |
7/10✓ Branch 0 (2→3) taken 14999 times.
✗ Branch 1 (2→118) not taken.
✓ Branch 2 (3→4) taken 14999 times.
✗ Branch 3 (3→118) not taken.
✓ Branch 4 (4→5) taken 14999 times.
✗ Branch 5 (4→118) not taken.
✓ Branch 6 (42→43) taken 43016 times.
✓ Branch 7 (42→45) taken 743 times.
✓ Branch 8 (48→6) taken 119205 times.
✓ Branch 9 (48→49) taken 14256 times.
|
177220 | for (const auto &sourceFile : typeChecker->resourceManager.sourceFiles | std::views::values) { |
689 | // Check if there is a registered operator function | ||
690 |
4/6✓ Branch 0 (10→11) taken 119205 times.
✗ Branch 1 (10→97) not taken.
✓ Branch 2 (11→12) taken 119205 times.
✗ Branch 3 (11→95) not taken.
✓ Branch 4 (14→15) taken 75446 times.
✓ Branch 5 (14→16) taken 43759 times.
|
357615 | if (!sourceFile->getNameRegistryEntry(fctName)) |
691 | 75446 | continue; | |
692 | |||
693 | // Match callees in the global scope of this source file | ||
694 | 43759 | calleeParentScope = sourceFile->globalScope.get(); | |
695 |
1/2✓ Branch 0 (18→19) taken 43759 times.
✗ Branch 1 (18→117) not taken.
|
43759 | const QualType thisType(TY_DYN); |
696 |
1/2✓ Branch 0 (21→22) taken 43759 times.
✗ Branch 1 (21→101) not taken.
|
43759 | ArgList args(N); |
697 |
1/2✓ Branch 0 (24→25) taken 43759 times.
✗ Branch 1 (24→104) not taken.
|
43759 | args[0] = {typeChecker->mapLocalTypeToImportedScopeType(calleeParentScope, op[0].type), op[0].isTemporary()}; |
698 | if constexpr (N == 2) | ||
699 |
1/2✓ Branch 0 (31→32) taken 42008 times.
✗ Branch 1 (31→113) not taken.
|
42008 | args[1] = {typeChecker->mapLocalTypeToImportedScopeType(calleeParentScope, op[1].type), op[1].isTemporary()}; |
700 |
2/4✓ Branch 0 (33→34) taken 43759 times.
✗ Branch 1 (33→108) not taken.
✓ Branch 2 (34→35) taken 43759 times.
✗ Branch 3 (34→106) not taken.
|
131277 | callee = FunctionManager::match(typeChecker, calleeParentScope, fctName, thisType, args, {}, false, node); |
701 |
2/2✓ Branch 0 (38→39) taken 743 times.
✓ Branch 1 (38→40) taken 43016 times.
|
43759 | if (callee) |
702 | 743 | break; | |
703 | } | ||
704 | |||
705 | // Return invalid type if the callee was not found | ||
706 |
2/2✓ Branch 0 (49→50) taken 14256 times.
✓ Branch 1 (49→52) taken 743 times.
|
14999 | if (!callee) |
707 | 14256 | return ExprResult(QualType(TY_INVALID)); | |
708 |
1/2✗ Branch 0 (52→53) not taken.
✓ Branch 1 (52→54) taken 743 times.
|
743 | assert(calleeParentScope != nullptr); |
709 | |||
710 | // Save the pointer to the operator function in the AST node | ||
711 | 743 | std::vector<const Function *> &opFctPointers = typeChecker->getOpFctPointers(node); | |
712 |
2/2✓ Branch 0 (56→57) taken 44 times.
✓ Branch 1 (56→59) taken 699 times.
|
743 | if (opFctPointers.size() <= opIdx) |
713 |
1/2✓ Branch 0 (57→58) taken 44 times.
✗ Branch 1 (57→119) not taken.
|
44 | opFctPointers.resize(opIdx + 1, nullptr); |
714 | 743 | opFctPointers.at(opIdx) = callee; | |
715 | |||
716 | // Check if we need to request a re-visit, because the function body was not type-checked yet | ||
717 | 743 | typeChecker->requestRevisitIfRequired(callee); | |
718 | |||
719 | // Check if the called function has sufficient visibility | ||
720 |
3/4✓ Branch 0 (61→62) taken 743 times.
✗ Branch 1 (61→65) not taken.
✓ Branch 2 (63→64) taken 324 times.
✓ Branch 3 (63→65) taken 419 times.
|
743 | const bool isImported = calleeParentScope != nullptr && calleeParentScope->isImportedBy(typeChecker->rootScope); |
721 | 743 | const SymbolTableEntry *calleeEntry = callee->entry; | |
722 |
4/6✓ Branch 0 (66→67) taken 324 times.
✓ Branch 1 (66→71) taken 419 times.
✗ Branch 2 (69→70) not taken.
✓ Branch 3 (69→71) taken 324 times.
✗ Branch 4 (72→73) not taken.
✓ Branch 5 (72→82) taken 743 times.
|
743 | if (isImported && !calleeEntry->getQualType().isPublic()) |
723 | ✗ | throw SemanticError(node, INSUFFICIENT_VISIBILITY, | |
724 | ✗ | "Overloaded operator '" + callee->getSignature() + "' has insufficient visibility"); | |
725 | |||
726 | // Procedures always have the return type 'bool' | ||
727 |
2/2✓ Branch 0 (85→86) taken 142 times.
✓ Branch 1 (85→88) taken 601 times.
|
743 | if (callee->isProcedure()) |
728 | 142 | return ExprResult(QualType(TY_BOOL)); | |
729 | |||
730 | // Add anonymous symbol to keep track of de-allocation | ||
731 | 601 | SymbolTableEntry *anonymousSymbol = nullptr; | |
732 |
2/2✓ Branch 0 (89→90) taken 63 times.
✓ Branch 1 (89→92) taken 538 times.
|
601 | if (callee->returnType.is(TY_STRUCT)) |
733 | 63 | anonymousSymbol = typeChecker->currentScope->symbolTable.insertAnonymous(callee->returnType, node, opIdx); | |
734 | |||
735 | 601 | return {typeChecker->mapImportedScopeTypeToLocalType(calleeParentScope, callee->returnType), anonymousSymbol}; | |
736 | } | ||
737 | |||
738 | 2607 | QualType OpRuleManager::validateUnaryOperation(const ASTNode *node, const UnaryOpRule opRules[], size_t opRulesSize, | |
739 | const char *name, const QualType &lhs) { | ||
740 |
2/2✓ Branch 0 (11→3) taken 6290 times.
✓ Branch 1 (11→12) taken 2 times.
|
6292 | for (size_t i = 0; i < opRulesSize; i++) { |
741 | 6290 | const UnaryOpRule &rule = opRules[i]; | |
742 |
2/2✓ Branch 0 (5→6) taken 2605 times.
✓ Branch 1 (5→10) taken 3685 times.
|
6290 | if (std::get<0>(rule) == lhs.getSuperType()) |
743 |
1/2✓ Branch 0 (7→8) taken 2605 times.
✗ Branch 1 (7→16) not taken.
|
2605 | return QualType(std::get<1>(rule)); |
744 | } | ||
745 |
1/2✓ Branch 0 (13→14) taken 2 times.
✗ Branch 1 (13→17) not taken.
|
2 | throw getExceptionUnary(node, name, lhs); |
746 | } | ||
747 | |||
748 | 29146 | QualType OpRuleManager::validateBinaryOperation(const ASTNode *node, const BinaryOpRule opRules[], size_t opRulesSize, | |
749 | const char *name, const QualType &lhs, const QualType &rhs, | ||
750 | bool preserveQualifiersFromLhs, const char *customMessagePrefix) { | ||
751 |
2/2✓ Branch 0 (19→3) taken 271709 times.
✓ Branch 1 (19→20) taken 19 times.
|
271728 | for (size_t i = 0; i < opRulesSize; i++) { |
752 | 271709 | const BinaryOpRule &rule = opRules[i]; | |
753 |
6/6✓ Branch 0 (5→6) taken 58253 times.
✓ Branch 1 (5→10) taken 213456 times.
✓ Branch 2 (8→9) taken 29127 times.
✓ Branch 3 (8→10) taken 29126 times.
✓ Branch 4 (11→12) taken 29127 times.
✓ Branch 5 (11→18) taken 242582 times.
|
271709 | if (std::get<0>(rule) == lhs.getSuperType() && std::get<1>(rule) == rhs.getSuperType()) { |
754 |
1/2✓ Branch 0 (13→14) taken 29127 times.
✗ Branch 1 (13→24) not taken.
|
29127 | QualType resultType((std::get<2>(rule))); |
755 |
2/2✓ Branch 0 (14→15) taken 16339 times.
✓ Branch 1 (14→17) taken 12788 times.
|
29127 | if (preserveQualifiersFromLhs) |
756 | 16339 | resultType.setQualifiers(lhs.getQualifiers()); | |
757 | 29127 | return resultType; | |
758 | } | ||
759 | } | ||
760 |
1/2✓ Branch 0 (21→22) taken 19 times.
✗ Branch 1 (21→25) not taken.
|
19 | throw getExceptionBinary(node, name, lhs, rhs, customMessagePrefix); |
761 | } | ||
762 | |||
763 | 2 | SemanticError OpRuleManager::getExceptionUnary(const ASTNode *node, const char *name, const QualType &lhs) { | |
764 |
6/12✓ Branch 0 (2→3) taken 2 times.
✗ Branch 1 (2→35) not taken.
✓ Branch 2 (5→6) taken 2 times.
✗ Branch 3 (5→27) not taken.
✓ Branch 4 (6→7) taken 2 times.
✗ Branch 5 (6→25) not taken.
✓ Branch 6 (7→8) taken 2 times.
✗ Branch 7 (7→23) not taken.
✓ Branch 8 (8→9) taken 2 times.
✗ Branch 9 (8→21) not taken.
✓ Branch 10 (9→10) taken 2 times.
✗ Branch 11 (9→19) not taken.
|
8 | return {node, OPERATOR_WRONG_DATA_TYPE, "Cannot apply '" + std::string(name) + "' operator on type " + lhs.getName(true)}; |
765 | } | ||
766 | |||
767 | 19 | SemanticError OpRuleManager::getExceptionBinary(const ASTNode *node, const char *name, const QualType &lhs, const QualType &rhs, | |
768 | const char *messagePrefix) { | ||
769 | // Build error message | ||
770 |
1/2✓ Branch 0 (2→3) taken 19 times.
✗ Branch 1 (2→50) not taken.
|
19 | std::stringstream errorMsg; |
771 |
2/2✓ Branch 0 (3→4) taken 4 times.
✓ Branch 1 (3→14) taken 15 times.
|
19 | if (strlen(messagePrefix) != 0) |
772 |
7/14✓ Branch 0 (4→5) taken 4 times.
✗ Branch 1 (4→48) not taken.
✓ Branch 2 (5→6) taken 4 times.
✗ Branch 3 (5→48) not taken.
✓ Branch 4 (6→7) taken 4 times.
✗ Branch 5 (6→37) not taken.
✓ Branch 6 (7→8) taken 4 times.
✗ Branch 7 (7→35) not taken.
✓ Branch 8 (8→9) taken 4 times.
✗ Branch 9 (8→35) not taken.
✓ Branch 10 (9→10) taken 4 times.
✗ Branch 11 (9→34) not taken.
✓ Branch 12 (10→11) taken 4 times.
✗ Branch 13 (10→32) not taken.
|
4 | errorMsg << messagePrefix << ". Expected " << lhs.getName(true) << " but got " << rhs.getName(true); |
773 | else | ||
774 |
8/16✓ Branch 0 (14→15) taken 15 times.
✗ Branch 1 (14→48) not taken.
✓ Branch 2 (15→16) taken 15 times.
✗ Branch 3 (15→48) not taken.
✓ Branch 4 (16→17) taken 15 times.
✗ Branch 5 (16→48) not taken.
✓ Branch 6 (17→18) taken 15 times.
✗ Branch 7 (17→43) not taken.
✓ Branch 8 (18→19) taken 15 times.
✗ Branch 9 (18→41) not taken.
✓ Branch 10 (19→20) taken 15 times.
✗ Branch 11 (19→41) not taken.
✓ Branch 12 (20→21) taken 15 times.
✗ Branch 13 (20→40) not taken.
✓ Branch 14 (21→22) taken 15 times.
✗ Branch 15 (21→38) not taken.
|
15 | errorMsg << "Cannot apply '" << name << "' operator on types " << lhs.getName(true) << " and " << rhs.getName(true); |
775 | |||
776 | // Return the exception | ||
777 |
2/4✓ Branch 0 (25→26) taken 19 times.
✗ Branch 1 (25→46) not taken.
✓ Branch 2 (26→27) taken 19 times.
✗ Branch 3 (26→44) not taken.
|
57 | return {node, OPERATOR_WRONG_DATA_TYPE, errorMsg.str()}; |
778 | 19 | } | |
779 | |||
780 | 2 | void OpRuleManager::ensureUnsafeAllowed(const ASTNode *node, const char *name, const QualType &lhs) const { | |
781 |
2/4✓ Branch 0 (2→3) taken 2 times.
✗ Branch 1 (2→43) not taken.
✓ Branch 2 (3→4) taken 2 times.
✗ Branch 3 (3→5) not taken.
|
2 | if (typeChecker->currentScope->doesAllowUnsafeOperations()) |
782 | 2 | return; | |
783 | // Print error message | ||
784 | ✗ | const std::string lhsName = lhs.getName(true); | |
785 | ✗ | const std::string errorMsg = "Cannot apply '" + std::string(name) + "' operator on type " + lhsName + | |
786 | ✗ | " as this is an unsafe operation. Please use unsafe blocks if you know what you are doing."; | |
787 | ✗ | SOFT_ERROR_VOID(node, UNSAFE_OPERATION_IN_SAFE_CONTEXT, errorMsg) | |
788 | ✗ | } | |
789 | |||
790 | 809 | void OpRuleManager::ensureUnsafeAllowed(const ASTNode *node, const char *name, const QualType &lhs, const QualType &rhs) const { | |
791 |
3/4✓ Branch 0 (2→3) taken 809 times.
✗ Branch 1 (2→57) not taken.
✓ Branch 2 (3→4) taken 808 times.
✓ Branch 3 (3→5) taken 1 times.
|
809 | if (typeChecker->currentScope->doesAllowUnsafeOperations()) |
792 | 808 | return; | |
793 | // Print error message | ||
794 |
1/2✓ Branch 0 (5→6) taken 1 times.
✗ Branch 1 (5→57) not taken.
|
1 | const std::string lhsName = lhs.getName(true); |
795 |
1/2✓ Branch 0 (6→7) taken 1 times.
✗ Branch 1 (6→55) not taken.
|
1 | const std::string rhsName = rhs.getName(true); |
796 |
6/12✓ Branch 0 (9→10) taken 1 times.
✗ Branch 1 (9→42) not taken.
✓ Branch 2 (10→11) taken 1 times.
✗ Branch 3 (10→40) not taken.
✓ Branch 4 (11→12) taken 1 times.
✗ Branch 5 (11→38) not taken.
✓ Branch 6 (12→13) taken 1 times.
✗ Branch 7 (12→36) not taken.
✓ Branch 8 (13→14) taken 1 times.
✗ Branch 9 (13→34) not taken.
✓ Branch 10 (14→15) taken 1 times.
✗ Branch 11 (14→32) not taken.
|
2 | const std::string errorMsg = "Cannot apply '" + std::string(name) + "' operator on types " + lhsName + " and " + rhsName + |
797 |
1/2✓ Branch 0 (15→16) taken 1 times.
✗ Branch 1 (15→30) not taken.
|
1 | " as this is an unsafe operation. Please use unsafe blocks if you know what you are doing."; |
798 |
1/2✓ Branch 0 (23→24) taken 1 times.
✗ Branch 1 (23→51) not taken.
|
1 | SOFT_ERROR_VOID(node, UNSAFE_OPERATION_IN_SAFE_CONTEXT, errorMsg) |
799 | 1 | } | |
800 | |||
801 | 23880 | void OpRuleManager::ensureNoConstAssign(const ASTNode *node, const QualType &lhs, bool isDecl, bool isReturn) const { | |
802 | // Check if we try to assign a constant value | ||
803 |
10/12✓ Branch 0 (2→3) taken 23880 times.
✗ Branch 1 (2→18) not taken.
✓ Branch 2 (3→4) taken 23880 times.
✗ Branch 3 (3→18) not taken.
✓ Branch 4 (4→5) taken 2531 times.
✓ Branch 5 (4→8) taken 21349 times.
✓ Branch 6 (5→6) taken 51 times.
✓ Branch 7 (5→8) taken 2480 times.
✓ Branch 8 (6→7) taken 14 times.
✓ Branch 9 (6→8) taken 37 times.
✓ Branch 10 (9→10) taken 14 times.
✓ Branch 11 (9→17) taken 23866 times.
|
23880 | if (lhs.removeReferenceWrapper().isConst() && !isDecl && !isReturn) { |
804 |
2/4✓ Branch 0 (10→11) taken 14 times.
✗ Branch 1 (10→21) not taken.
✓ Branch 2 (11→12) taken 14 times.
✗ Branch 3 (11→19) not taken.
|
14 | const std::string errorMessage = "Trying to assign value to an immutable variable of type " + lhs.getName(true); |
805 |
1/2✓ Branch 0 (13→14) taken 14 times.
✗ Branch 1 (13→22) not taken.
|
14 | SOFT_ERROR_VOID(node, REASSIGN_CONST_VARIABLE, errorMessage); |
806 | 14 | } | |
807 | } | ||
808 | |||
809 | } // namespace spice::compiler | ||
810 |