GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 93.3% 378 / 10 / 415
Functions: 100.0% 16 / 0 / 16
Branches: 51.8% 631 / 32 / 1251

src/typechecker/TypeCheckerExpressions.cpp
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 #include "TypeChecker.h"
4
5 #include <SourceFile.h>
6 #include <global/GlobalResourceManager.h>
7 #include <symboltablebuilder/Scope.h>
8 #include <symboltablebuilder/SymbolTableBuilder.h>
9 #include <typechecker/MacroDefs.h>
10
11 namespace spice::compiler {
12
13 7745 std::any TypeChecker::visitAssignExpr(AssignExprNode *node) {
14 // Check if ternary
15
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 10 taken 7745 times.
7745 if (node->ternaryExpr) {
16 auto result = std::any_cast<ExprResult>(visit(node->ternaryExpr));
17 node->setEvaluatedSymbolType(result.type, manIdx);
18 return result;
19 }
20
21 // Check if assignment
22
1/2
✓ Branch 10 → 11 taken 7745 times.
✗ Branch 10 → 84 not taken.
7745 if (node->op != AssignExprNode::AssignOp::OP_NONE) {
23 // Visit the right side first
24
2/4
✓ Branch 11 → 12 taken 7745 times.
✗ Branch 11 → 99 not taken.
✓ Branch 12 → 13 taken 7745 times.
✗ Branch 12 → 97 not taken.
7745 auto rhs = std::any_cast<ExprResult>(visit(node->rhs));
25 7745 auto [rhsType, rhsEntry] = rhs;
26
5/8
✓ Branch 14 → 15 taken 7745 times.
✗ Branch 14 → 118 not taken.
✓ Branch 15 → 16 taken 1 time.
✓ Branch 15 → 20 taken 7744 times.
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 100 not taken.
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 100 not taken.
7745 HANDLE_UNRESOLVED_TYPE_ER(rhsType)
27 // Then visit the left side
28
2/4
✓ Branch 20 → 21 taken 7744 times.
✗ Branch 20 → 103 not taken.
✓ Branch 21 → 22 taken 7744 times.
✗ Branch 21 → 101 not taken.
7744 auto lhs = std::any_cast<ExprResult>(visit(node->lhs));
29 7744 auto [lhsType, lhsVar] = lhs;
30
5/8
✓ Branch 23 → 24 taken 7744 times.
✗ Branch 23 → 118 not taken.
✓ Branch 24 → 25 taken 1 time.
✓ Branch 24 → 29 taken 7743 times.
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 104 not taken.
✓ Branch 26 → 27 taken 1 time.
✗ Branch 26 → 104 not taken.
7744 HANDLE_UNRESOLVED_TYPE_ER(lhsType)
31
32 // Take a look at the operator
33
2/2
✓ Branch 29 → 30 taken 6834 times.
✓ Branch 29 → 40 taken 909 times.
7743 if (node->op == AssignExprNode::AssignOp::OP_ASSIGN) {
34
8/10
✓ Branch 30 → 31 taken 6833 times.
✓ Branch 30 → 37 taken 1 time.
✓ Branch 31 → 32 taken 6833 times.
✗ Branch 31 → 118 not taken.
✓ Branch 32 → 33 taken 5485 times.
✓ Branch 32 → 37 taken 1348 times.
✓ Branch 34 → 35 taken 5485 times.
✗ Branch 34 → 118 not taken.
✓ Branch 35 → 36 taken 1212 times.
✓ Branch 35 → 37 taken 4273 times.
6834 const bool isDecl = lhs.entry != nullptr && lhs.entry->isField() && !lhs.entry->getLifecycle().isInitialized();
35
2/2
✓ Branch 38 → 39 taken 6833 times.
✓ Branch 38 → 105 taken 1 time.
6834 rhsType = opRuleManager.getAssignResultType(node, lhs, rhs, isDecl).first;
36
2/2
✓ Branch 40 → 41 taken 298 times.
✓ Branch 40 → 43 taken 611 times.
909 } else if (node->op == AssignExprNode::AssignOp::OP_PLUS_EQUAL) {
37
1/2
✓ Branch 41 → 42 taken 298 times.
✗ Branch 41 → 106 not taken.
298 rhsType = opRuleManager.getPlusEqualResultType(node, lhs, rhs).type;
38
2/2
✓ Branch 43 → 44 taken 49 times.
✓ Branch 43 → 46 taken 562 times.
611 } else if (node->op == AssignExprNode::AssignOp::OP_MINUS_EQUAL) {
39
1/2
✓ Branch 44 → 45 taken 49 times.
✗ Branch 44 → 107 not taken.
49 rhsType = opRuleManager.getMinusEqualResultType(node, lhs, rhs).type;
40
2/2
✓ Branch 46 → 47 taken 54 times.
✓ Branch 46 → 49 taken 508 times.
562 } else if (node->op == AssignExprNode::AssignOp::OP_MUL_EQUAL) {
41
1/2
✓ Branch 47 → 48 taken 54 times.
✗ Branch 47 → 108 not taken.
54 rhsType = opRuleManager.getMulEqualResultType(node, lhs, rhs).type;
42
2/2
✓ Branch 49 → 50 taken 55 times.
✓ Branch 49 → 52 taken 453 times.
508 } else if (node->op == AssignExprNode::AssignOp::OP_DIV_EQUAL) {
43
1/2
✓ Branch 50 → 51 taken 55 times.
✗ Branch 50 → 109 not taken.
55 rhsType = opRuleManager.getDivEqualResultType(node, lhs, rhs).type;
44
2/2
✓ Branch 52 → 53 taken 17 times.
✓ Branch 52 → 55 taken 436 times.
453 } else if (node->op == AssignExprNode::AssignOp::OP_REM_EQUAL) {
45
1/2
✓ Branch 53 → 54 taken 17 times.
✗ Branch 53 → 110 not taken.
17 rhsType = opRuleManager.getRemEqualResultType(node, lhs, rhs);
46
2/2
✓ Branch 55 → 56 taken 12 times.
✓ Branch 55 → 58 taken 424 times.
436 } else if (node->op == AssignExprNode::AssignOp::OP_SHL_EQUAL) {
47
1/2
✓ Branch 56 → 57 taken 12 times.
✗ Branch 56 → 111 not taken.
12 rhsType = opRuleManager.getSHLEqualResultType(node, lhs, rhs);
48
2/2
✓ Branch 58 → 59 taken 13 times.
✓ Branch 58 → 61 taken 411 times.
424 } else if (node->op == AssignExprNode::AssignOp::OP_SHR_EQUAL) {
49
1/2
✓ Branch 59 → 60 taken 13 times.
✗ Branch 59 → 112 not taken.
13 rhsType = opRuleManager.getSHREqualResultType(node, lhs, rhs);
50
2/2
✓ Branch 61 → 62 taken 11 times.
✓ Branch 61 → 64 taken 400 times.
411 } else if (node->op == AssignExprNode::AssignOp::OP_AND_EQUAL) {
51
1/2
✓ Branch 62 → 63 taken 11 times.
✗ Branch 62 → 113 not taken.
11 rhsType = opRuleManager.getAndEqualResultType(node, lhs, rhs);
52
2/2
✓ Branch 64 → 65 taken 11 times.
✓ Branch 64 → 67 taken 389 times.
400 } else if (node->op == AssignExprNode::AssignOp::OP_OR_EQUAL) {
53
1/2
✓ Branch 65 → 66 taken 11 times.
✗ Branch 65 → 114 not taken.
11 rhsType = opRuleManager.getOrEqualResultType(node, lhs, rhs);
54
1/2
✓ Branch 67 → 68 taken 389 times.
✗ Branch 67 → 70 not taken.
389 } else if (node->op == AssignExprNode::AssignOp::OP_XOR_EQUAL) {
55
1/2
✓ Branch 68 → 69 taken 389 times.
✗ Branch 68 → 115 not taken.
389 rhsType = opRuleManager.getXorEqualResultType(node, lhs, rhs);
56 }
57
58
1/2
✓ Branch 70 → 71 taken 7742 times.
✗ Branch 70 → 79 not taken.
7742 if (lhsVar) { // Variable is involved on the left side
59 // Perform type inference
60
3/4
✓ Branch 71 → 72 taken 7742 times.
✗ Branch 71 → 118 not taken.
✓ Branch 72 → 73 taken 1 time.
✓ Branch 72 → 74 taken 7741 times.
7742 if (lhsType.is(TY_DYN))
61
1/2
✓ Branch 73 → 74 taken 1 time.
✗ Branch 73 → 118 not taken.
1 lhsVar->updateType(rhsType, false);
62
63 // In case the lhs variable is captured, notify the capture about the write access
64
3/4
✓ Branch 74 → 75 taken 7742 times.
✗ Branch 74 → 118 not taken.
✓ Branch 75 → 76 taken 3 times.
✓ Branch 75 → 77 taken 7739 times.
7742 if (Capture *lhsCapture = currentScope->symbolTable.lookupCapture(lhsVar->name); lhsCapture)
65
1/2
✓ Branch 76 → 77 taken 3 times.
✗ Branch 76 → 118 not taken.
3 lhsCapture->setAccessType(READ_WRITE);
66
67 // Update the state of the variable
68
1/2
✓ Branch 77 → 78 taken 7742 times.
✗ Branch 77 → 116 not taken.
7742 lhsVar->updateState(INITIALIZED, node);
69 }
70
71
2/4
✓ Branch 79 → 80 taken 7742 times.
✗ Branch 79 → 117 not taken.
✓ Branch 80 → 81 taken 7742 times.
✗ Branch 80 → 117 not taken.
7742 return ExprResult{node->setEvaluatedSymbolType(rhsType, manIdx)};
72 }
73
74 throw CompilerError(UNHANDLED_BRANCH, "AssignExpr fall-through"); // GCOV_EXCL_LINE
75 }
76
77 568 std::any TypeChecker::visitTernaryExpr(TernaryExprNode *node) {
78 // Check if there is a ternary operator applied
79
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 568 times.
568 if (!node->falseExpr)
80 return visit(node->condition);
81
82 // Visit condition
83
2/4
✓ Branch 5 → 6 taken 568 times.
✗ Branch 5 → 126 not taken.
✓ Branch 6 → 7 taken 568 times.
✗ Branch 6 → 124 not taken.
568 const auto condition = std::any_cast<ExprResult>(visit(node->condition));
84
2/8
✓ Branch 8 → 9 taken 568 times.
✗ Branch 8 → 161 not taken.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 14 taken 568 times.
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 127 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 127 not taken.
568 HANDLE_UNRESOLVED_TYPE_ER(condition.type)
85
6/10
✓ Branch 14 → 15 taken 1 time.
✓ Branch 14 → 16 taken 567 times.
✓ Branch 16 → 17 taken 567 times.
✗ Branch 16 → 128 not taken.
✓ Branch 17 → 18 taken 567 times.
✗ Branch 17 → 128 not taken.
✓ Branch 18 → 19 taken 567 times.
✓ Branch 18 → 20 taken 1 time.
✗ Branch 128 → 129 not taken.
✗ Branch 128 → 130 not taken.
568 const auto trueExpr = node->isShortened ? condition : std::any_cast<ExprResult>(visit(node->trueExpr));
86 568 const auto [trueType, trueEntry] = trueExpr;
87
2/8
✓ Branch 20 → 21 taken 568 times.
✗ Branch 20 → 161 not taken.
✗ Branch 21 → 22 not taken.
✓ Branch 21 → 26 taken 568 times.
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 132 not taken.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 132 not taken.
568 HANDLE_UNRESOLVED_TYPE_ER(trueType)
88
2/4
✓ Branch 26 → 27 taken 568 times.
✗ Branch 26 → 135 not taken.
✓ Branch 27 → 28 taken 568 times.
✗ Branch 27 → 133 not taken.
568 const auto falseExpr = std::any_cast<ExprResult>(visit(node->falseExpr));
89 568 const auto [falseType, falseEntry] = falseExpr;
90
2/8
✓ Branch 29 → 30 taken 568 times.
✗ Branch 29 → 161 not taken.
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 35 taken 568 times.
✗ Branch 31 → 32 not taken.
✗ Branch 31 → 136 not taken.
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 136 not taken.
568 HANDLE_UNRESOLVED_TYPE_ER(falseType)
91
92 // Check if the condition evaluates to bool
93
3/4
✓ Branch 35 → 36 taken 568 times.
✗ Branch 35 → 161 not taken.
✓ Branch 36 → 37 taken 1 time.
✓ Branch 36 → 47 taken 567 times.
568 if (!condition.type.is(TY_BOOL))
94
4/8
✓ Branch 39 → 40 taken 1 time.
✗ Branch 39 → 139 not taken.
✓ Branch 40 → 41 taken 1 time.
✗ Branch 40 → 137 not taken.
✓ Branch 43 → 44 taken 1 time.
✗ Branch 43 → 143 not taken.
✓ Branch 44 → 45 taken 1 time.
✗ Branch 44 → 143 not taken.
3 SOFT_ERROR_ER(node->condition, OPERATOR_WRONG_DATA_TYPE, "Condition operand in ternary must be a bool")
95
96 // Check if trueType and falseType are matching
97
1/2
✓ Branch 47 → 48 taken 567 times.
✗ Branch 47 → 161 not taken.
567 const QualType trueTypeModified = trueType.removeReferenceWrapper();
98
1/2
✓ Branch 48 → 49 taken 567 times.
✗ Branch 48 → 161 not taken.
567 const QualType falseTypeModified = falseType.removeReferenceWrapper();
99
3/4
✓ Branch 49 → 50 taken 567 times.
✗ Branch 49 → 161 not taken.
✓ Branch 50 → 51 taken 1 time.
✓ Branch 50 → 66 taken 566 times.
567 if (!trueTypeModified.matches(falseTypeModified, false, true, false))
100
8/16
✓ Branch 51 → 52 taken 1 time.
✗ Branch 51 → 157 not taken.
✓ Branch 52 → 53 taken 1 time.
✗ Branch 52 → 152 not taken.
✓ Branch 53 → 54 taken 1 time.
✗ Branch 53 → 150 not taken.
✓ Branch 54 → 55 taken 1 time.
✗ Branch 54 → 148 not taken.
✓ Branch 55 → 56 taken 1 time.
✗ Branch 55 → 146 not taken.
✓ Branch 56 → 57 taken 1 time.
✗ Branch 56 → 144 not taken.
✓ Branch 62 → 63 taken 1 time.
✗ Branch 62 → 159 not taken.
✓ Branch 63 → 64 taken 1 time.
✗ Branch 63 → 159 not taken.
1 SOFT_ERROR_ER(node, OPERATOR_WRONG_DATA_TYPE,
101 "True and false operands in ternary must be of same data type. Got " + trueType.getName(true) + " and " +
102 falseType.getName(true))
103
104 // The result type must be a reference if one of true/false branch is of reference type. Otherwise,
105 // the copy ctor is not called correctly
106
3/4
✓ Branch 66 → 67 taken 566 times.
✗ Branch 66 → 161 not taken.
✓ Branch 67 → 68 taken 9 times.
✓ Branch 67 → 69 taken 557 times.
566 QualType resultType = trueType.isRef() ? trueType : falseType;
107 // Infer the const-ness from the more restrictive operand
108
7/10
✓ Branch 70 → 71 taken 566 times.
✗ Branch 70 → 161 not taken.
✓ Branch 71 → 72 taken 557 times.
✓ Branch 71 → 74 taken 9 times.
✓ Branch 72 → 73 taken 557 times.
✗ Branch 72 → 161 not taken.
✓ Branch 73 → 74 taken 223 times.
✓ Branch 73 → 75 taken 334 times.
✓ Branch 76 → 77 taken 566 times.
✗ Branch 76 → 161 not taken.
566 resultType.makeConst(trueType.isConst() || falseType.isConst());
109
110 // If there is an anonymous symbol attached to left or right, remove it,
111 // since the result takes over the ownership of any destructible object.
112 566 bool removedAnonymousSymbols = false;
113
2/2
✓ Branch 77 → 78 taken 149 times.
✓ Branch 77 → 89 taken 417 times.
566 if (trueEntry) {
114
2/2
✓ Branch 78 → 79 taken 102 times.
✓ Branch 78 → 81 taken 47 times.
149 if (trueEntry->anonymous) {
115
1/2
✓ Branch 79 → 80 taken 102 times.
✗ Branch 79 → 161 not taken.
102 currentScope->symbolTable.deleteAnonymous(trueEntry->name);
116 102 removedAnonymousSymbols = true;
117
8/10
✓ Branch 81 → 82 taken 47 times.
✗ Branch 81 → 161 not taken.
✓ Branch 82 → 83 taken 39 times.
✓ Branch 82 → 86 taken 8 times.
✓ Branch 83 → 84 taken 39 times.
✗ Branch 83 → 161 not taken.
✓ Branch 84 → 85 taken 9 times.
✓ Branch 84 → 86 taken 30 times.
✓ Branch 87 → 88 taken 9 times.
✓ Branch 87 → 89 taken 38 times.
47 } else if (!trueType.isRef() && !trueType.isTriviallyCopyable(node)) {
118 9 node->trueSideCallsCopyCtor = true;
119 }
120 }
121
2/2
✓ Branch 89 → 90 taken 378 times.
✓ Branch 89 → 101 taken 188 times.
566 if (falseEntry) {
122
2/2
✓ Branch 90 → 91 taken 101 times.
✓ Branch 90 → 93 taken 277 times.
378 if (falseEntry->anonymous) {
123
1/2
✓ Branch 91 → 92 taken 101 times.
✗ Branch 91 → 161 not taken.
101 currentScope->symbolTable.deleteAnonymous(falseEntry->name);
124 101 removedAnonymousSymbols = true;
125
8/10
✓ Branch 93 → 94 taken 277 times.
✗ Branch 93 → 161 not taken.
✓ Branch 94 → 95 taken 267 times.
✓ Branch 94 → 98 taken 10 times.
✓ Branch 95 → 96 taken 267 times.
✗ Branch 95 → 161 not taken.
✓ Branch 96 → 97 taken 8 times.
✓ Branch 96 → 98 taken 259 times.
✓ Branch 99 → 100 taken 8 times.
✓ Branch 99 → 101 taken 269 times.
277 } else if (!falseType.isRef() && !falseType.isTriviallyCopyable(node)) {
126 8 node->falseSideCallsCopyCtor = true;
127 }
128 }
129
130 // Create a new anonymous symbol for the result if required
131 566 SymbolTableEntry *anonymousSymbol = nullptr;
132
4/4
✓ Branch 101 → 102 taken 557 times.
✓ Branch 101 → 103 taken 9 times.
✓ Branch 102 → 103 taken 2 times.
✓ Branch 102 → 104 taken 555 times.
566 const bool calledCopyCtor = node->trueSideCallsCopyCtor || node->falseSideCallsCopyCtor;
133
9/10
✓ Branch 105 → 106 taken 462 times.
✓ Branch 105 → 109 taken 104 times.
✓ Branch 106 → 107 taken 455 times.
✓ Branch 106 → 109 taken 7 times.
✓ Branch 107 → 108 taken 455 times.
✗ Branch 107 → 161 not taken.
✓ Branch 108 → 109 taken 9 times.
✓ Branch 108 → 110 taken 446 times.
✓ Branch 111 → 112 taken 120 times.
✓ Branch 111 → 114 taken 446 times.
566 if (removedAnonymousSymbols || calledCopyCtor || resultType.isRef())
134
1/2
✓ Branch 112 → 113 taken 120 times.
✗ Branch 112 → 161 not taken.
120 anonymousSymbol = currentScope->symbolTable.insertAnonymous(resultType, node);
135
136 // Look up the copy ctor if at least one side needs it
137
4/4
✓ Branch 114 → 115 taken 557 times.
✓ Branch 114 → 116 taken 9 times.
✓ Branch 115 → 116 taken 2 times.
✓ Branch 115 → 118 taken 555 times.
566 if (node->trueSideCallsCopyCtor || node->falseSideCallsCopyCtor)
138
1/2
✓ Branch 116 → 117 taken 11 times.
✗ Branch 116 → 161 not taken.
11 node->calledCopyCtor = matchCopyCtor(trueTypeModified, node);
139
140
2/4
✓ Branch 118 → 119 taken 566 times.
✗ Branch 118 → 160 not taken.
✓ Branch 119 → 120 taken 566 times.
✗ Branch 119 → 160 not taken.
566 return ExprResult{node->setEvaluatedSymbolType(resultType, manIdx), anonymousSymbol};
141 }
142
143 1041 std::any TypeChecker::visitLogicalOrExpr(LogicalOrExprNode *node) {
144 // Check if a logical or operator is applied
145
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 1041 times.
1041 if (node->operands.size() == 1)
146 return visit(node->operands.front());
147
148 // Visit leftmost operand
149
2/4
✓ Branch 8 → 9 taken 1041 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 1041 times.
✗ Branch 9 → 37 not taken.
1041 auto currentOperand = std::any_cast<ExprResult>(visit(node->operands[0]));
150
2/8
✓ Branch 11 → 12 taken 1041 times.
✗ Branch 11 → 46 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 1041 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 40 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 40 not taken.
1041 HANDLE_UNRESOLVED_TYPE_ER(currentOperand.type)
151
152 // Loop through all remaining operands
153
2/2
✓ Branch 31 → 18 taken 1338 times.
✓ Branch 31 → 32 taken 1040 times.
2378 for (size_t i = 1; i < node->operands.size(); i++) {
154
2/4
✓ Branch 19 → 20 taken 1338 times.
✗ Branch 19 → 43 not taken.
✓ Branch 20 → 21 taken 1338 times.
✗ Branch 20 → 41 not taken.
1338 auto rhsOperand = std::any_cast<ExprResult>(visit(node->operands[i]));
155
2/8
✓ Branch 22 → 23 taken 1338 times.
✗ Branch 22 → 45 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 1338 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 44 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 44 not taken.
1338 HANDLE_UNRESOLVED_TYPE_ER(rhsOperand.type)
156
2/2
✓ Branch 28 → 29 taken 1337 times.
✓ Branch 28 → 45 taken 1 time.
1338 currentOperand = {OpRuleManager::getLogicalOrResultType(node, currentOperand, rhsOperand)};
157 }
158
159
1/2
✓ Branch 32 → 33 taken 1040 times.
✗ Branch 32 → 46 not taken.
1040 node->setEvaluatedSymbolType(currentOperand.type, manIdx);
160
1/2
✓ Branch 33 → 34 taken 1040 times.
✗ Branch 33 → 46 not taken.
1040 return currentOperand;
161 }
162
163 201 std::any TypeChecker::visitLogicalAndExpr(LogicalAndExprNode *node) {
164 // Check if a logical and operator is applied
165
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 201 times.
201 if (node->operands.size() == 1)
166 return visit(node->operands.front());
167
168 // Visit leftmost operand
169
2/4
✓ Branch 8 → 9 taken 201 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 201 times.
✗ Branch 9 → 37 not taken.
201 auto currentOperand = std::any_cast<ExprResult>(visit(node->operands[0]));
170
2/8
✓ Branch 11 → 12 taken 201 times.
✗ Branch 11 → 46 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 201 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 40 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 40 not taken.
201 HANDLE_UNRESOLVED_TYPE_ER(currentOperand.type)
171
172 // Loop through all remaining operands
173
2/2
✓ Branch 31 → 18 taken 236 times.
✓ Branch 31 → 32 taken 201 times.
437 for (size_t i = 1; i < node->operands.size(); i++) {
174
2/4
✓ Branch 19 → 20 taken 236 times.
✗ Branch 19 → 43 not taken.
✓ Branch 20 → 21 taken 236 times.
✗ Branch 20 → 41 not taken.
236 auto rhsOperand = std::any_cast<ExprResult>(visit(node->operands[i]));
175
2/8
✓ Branch 22 → 23 taken 236 times.
✗ Branch 22 → 45 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 236 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 44 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 44 not taken.
236 HANDLE_UNRESOLVED_TYPE_ER(rhsOperand.type)
176
1/2
✓ Branch 28 → 29 taken 236 times.
✗ Branch 28 → 45 not taken.
236 currentOperand = {OpRuleManager::getLogicalAndResultType(node, currentOperand, rhsOperand)};
177 }
178
179
1/2
✓ Branch 32 → 33 taken 201 times.
✗ Branch 32 → 46 not taken.
201 node->setEvaluatedSymbolType(currentOperand.type, manIdx);
180
1/2
✓ Branch 33 → 34 taken 201 times.
✗ Branch 33 → 46 not taken.
201 return currentOperand;
181 }
182
183 106 std::any TypeChecker::visitBitwiseOrExpr(BitwiseOrExprNode *node) {
184 // Check if a bitwise or operator is applied
185
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 106 times.
106 if (node->operands.size() == 1)
186 return visit(node->operands.front());
187
188 // Visit leftmost operand
189
2/4
✓ Branch 8 → 9 taken 106 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 106 times.
✗ Branch 9 → 37 not taken.
106 auto currentOperand = std::any_cast<ExprResult>(visit(node->operands[0]));
190
2/8
✓ Branch 11 → 12 taken 106 times.
✗ Branch 11 → 46 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 106 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 40 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 40 not taken.
106 HANDLE_UNRESOLVED_TYPE_ER(currentOperand.type)
191
192 // Loop through all remaining operands
193
2/2
✓ Branch 31 → 18 taken 109 times.
✓ Branch 31 → 32 taken 105 times.
214 for (size_t i = 1; i < node->operands.size(); i++) {
194
2/4
✓ Branch 19 → 20 taken 109 times.
✗ Branch 19 → 43 not taken.
✓ Branch 20 → 21 taken 109 times.
✗ Branch 20 → 41 not taken.
109 auto rhsOperand = std::any_cast<ExprResult>(visit(node->operands[i]));
195
2/8
✓ Branch 22 → 23 taken 109 times.
✗ Branch 22 → 45 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 109 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 44 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 44 not taken.
109 HANDLE_UNRESOLVED_TYPE_ER(rhsOperand.type)
196
2/2
✓ Branch 28 → 29 taken 108 times.
✓ Branch 28 → 45 taken 1 time.
109 currentOperand = {OpRuleManager::getBitwiseOrResultType(node, currentOperand, rhsOperand)};
197 }
198
199
1/2
✓ Branch 32 → 33 taken 105 times.
✗ Branch 32 → 46 not taken.
105 node->setEvaluatedSymbolType(currentOperand.type, manIdx);
200
1/2
✓ Branch 33 → 34 taken 105 times.
✗ Branch 33 → 46 not taken.
105 return currentOperand;
201 }
202
203 17 std::any TypeChecker::visitBitwiseXorExpr(BitwiseXorExprNode *node) {
204 // Check if a bitwise xor operator is applied
205
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 17 times.
17 if (node->operands.size() == 1)
206 return visit(node->operands.front());
207
208 // Visit leftmost operand
209
2/4
✓ Branch 8 → 9 taken 17 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 17 times.
✗ Branch 9 → 37 not taken.
17 auto currentOperand = std::any_cast<ExprResult>(visit(node->operands[0]));
210
2/8
✓ Branch 11 → 12 taken 17 times.
✗ Branch 11 → 46 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 17 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 40 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 40 not taken.
17 HANDLE_UNRESOLVED_TYPE_ER(currentOperand.type)
211
212 // Loop through all remaining operands
213
2/2
✓ Branch 31 → 18 taken 20 times.
✓ Branch 31 → 32 taken 17 times.
37 for (size_t i = 1; i < node->operands.size(); i++) {
214
2/4
✓ Branch 19 → 20 taken 20 times.
✗ Branch 19 → 43 not taken.
✓ Branch 20 → 21 taken 20 times.
✗ Branch 20 → 41 not taken.
20 auto rhsOperand = std::any_cast<ExprResult>(visit(node->operands[i]));
215
2/8
✓ Branch 22 → 23 taken 20 times.
✗ Branch 22 → 45 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 20 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 44 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 44 not taken.
20 HANDLE_UNRESOLVED_TYPE_ER(rhsOperand.type)
216
1/2
✓ Branch 28 → 29 taken 20 times.
✗ Branch 28 → 45 not taken.
20 currentOperand = {OpRuleManager::getBitwiseXorResultType(node, currentOperand, rhsOperand)};
217 }
218
219
1/2
✓ Branch 32 → 33 taken 17 times.
✗ Branch 32 → 46 not taken.
17 node->setEvaluatedSymbolType(currentOperand.type, manIdx);
220
1/2
✓ Branch 33 → 34 taken 17 times.
✗ Branch 33 → 46 not taken.
17 return currentOperand;
221 }
222
223 46 std::any TypeChecker::visitBitwiseAndExpr(BitwiseAndExprNode *node) {
224 // Check if a bitwise and operator is applied
225
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 46 times.
46 if (node->operands.size() == 1)
226 return visit(node->operands.front());
227
228 // Visit leftmost operand
229
2/4
✓ Branch 8 → 9 taken 46 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 46 times.
✗ Branch 9 → 37 not taken.
46 auto currentOperand = std::any_cast<ExprResult>(visit(node->operands[0]));
230
2/8
✓ Branch 11 → 12 taken 46 times.
✗ Branch 11 → 46 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 46 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 40 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 40 not taken.
46 HANDLE_UNRESOLVED_TYPE_ER(currentOperand.type)
231
232 // Loop through all remaining operands
233
2/2
✓ Branch 31 → 18 taken 49 times.
✓ Branch 31 → 32 taken 46 times.
95 for (size_t i = 1; i < node->operands.size(); i++) {
234
2/4
✓ Branch 19 → 20 taken 49 times.
✗ Branch 19 → 43 not taken.
✓ Branch 20 → 21 taken 49 times.
✗ Branch 20 → 41 not taken.
49 auto rhsOperand = std::any_cast<ExprResult>(visit(node->operands[i]));
235
2/8
✓ Branch 22 → 23 taken 49 times.
✗ Branch 22 → 45 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 49 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 44 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 44 not taken.
49 HANDLE_UNRESOLVED_TYPE_ER(rhsOperand.type)
236
1/2
✓ Branch 28 → 29 taken 49 times.
✗ Branch 28 → 45 not taken.
49 currentOperand = {OpRuleManager::getBitwiseAndResultType(node, currentOperand, rhsOperand)};
237 }
238
239
1/2
✓ Branch 32 → 33 taken 46 times.
✗ Branch 32 → 46 not taken.
46 node->setEvaluatedSymbolType(currentOperand.type, manIdx);
240
1/2
✓ Branch 33 → 34 taken 46 times.
✗ Branch 33 → 46 not taken.
46 return currentOperand;
241 }
242
243 6376 std::any TypeChecker::visitEqualityExpr(EqualityExprNode *node) {
244 // Check if at least one equality operator is applied
245
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 6376 times.
6376 if (node->operands.size() == 1)
246 return visit(node->operands.front());
247
248 // Visit right side first, then left side
249
2/4
✓ Branch 8 → 9 taken 6376 times.
✗ Branch 8 → 58 not taken.
✓ Branch 9 → 10 taken 6376 times.
✗ Branch 9 → 56 not taken.
6376 const auto rhs = std::any_cast<ExprResult>(visit(node->operands[1]));
250
2/8
✓ Branch 11 → 12 taken 6376 times.
✗ Branch 11 → 73 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 6376 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 59 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 59 not taken.
6376 HANDLE_UNRESOLVED_TYPE_ER(rhs.type)
251
2/4
✓ Branch 18 → 19 taken 6376 times.
✗ Branch 18 → 62 not taken.
✓ Branch 19 → 20 taken 6376 times.
✗ Branch 19 → 60 not taken.
6376 const auto lhs = std::any_cast<ExprResult>(visit(node->operands[0]));
252
2/8
✓ Branch 21 → 22 taken 6376 times.
✗ Branch 21 → 73 not taken.
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 27 taken 6376 times.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 63 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 63 not taken.
6376 HANDLE_UNRESOLVED_TYPE_ER(lhs.type)
253
254 // Check if we need the string runtime to perform a string comparison
255
10/14
✓ Branch 27 → 28 taken 6376 times.
✗ Branch 27 → 73 not taken.
✓ Branch 28 → 29 taken 159 times.
✓ Branch 28 → 36 taken 6217 times.
✓ Branch 29 → 30 taken 159 times.
✗ Branch 29 → 73 not taken.
✓ Branch 30 → 31 taken 158 times.
✓ Branch 30 → 36 taken 1 time.
✓ Branch 31 → 32 taken 158 times.
✗ Branch 31 → 73 not taken.
✓ Branch 34 → 35 taken 158 times.
✗ Branch 34 → 36 not taken.
✓ Branch 37 → 38 taken 158 times.
✓ Branch 37 → 39 taken 6218 times.
6534 if (lhs.type.is(TY_STRING) && rhs.type.is(TY_STRING) && !sourceFile->isStringRT())
256
1/2
✓ Branch 38 → 39 taken 158 times.
✗ Branch 38 → 73 not taken.
158 sourceFile->requestRuntimeModule(STRING_RT);
257
258 // Check operator
259 6376 ExprResult result;
260
2/2
✓ Branch 39 → 40 taken 4660 times.
✓ Branch 39 → 41 taken 1716 times.
6376 if (node->op == EqualityExprNode::EqualityOp::OP_EQUAL) // Operator was equal
261
2/2
✓ Branch 40 → 51 taken 4659 times.
✓ Branch 40 → 73 taken 1 time.
4660 result = opRuleManager.getEqualResultType(node, lhs, rhs);
262
1/2
✓ Branch 41 → 42 taken 1716 times.
✗ Branch 41 → 43 not taken.
1716 else if (node->op == EqualityExprNode::EqualityOp::OP_NOT_EQUAL) // Operator was not equal
263
1/2
✓ Branch 42 → 51 taken 1716 times.
✗ Branch 42 → 73 not taken.
1716 result = opRuleManager.getNotEqualResultType(node, lhs, rhs);
264 else
265 throw CompilerError(UNHANDLED_BRANCH, "EqualityExpr fall-through"); // GCOV_EXCL_LINE
266
267
1/2
✓ Branch 51 → 52 taken 6375 times.
✗ Branch 51 → 73 not taken.
6375 node->setEvaluatedSymbolType(result.type, manIdx);
268
1/2
✓ Branch 52 → 53 taken 6375 times.
✗ Branch 52 → 73 not taken.
6375 return result;
269 }
270
271 4343 std::any TypeChecker::visitRelationalExpr(RelationalExprNode *node) {
272 // Check if a relational operator is applied
273
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 4343 times.
4343 if (node->operands.size() == 1)
274 return visit(node->operands.front());
275
276 // Visit right side first, then left side
277
2/4
✓ Branch 8 → 9 taken 4343 times.
✗ Branch 8 → 55 not taken.
✓ Branch 9 → 10 taken 4343 times.
✗ Branch 9 → 53 not taken.
4343 const auto rhs = std::any_cast<ExprResult>(visit(node->operands[1]));
278
5/8
✓ Branch 11 → 12 taken 4343 times.
✗ Branch 11 → 75 not taken.
✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 17 taken 4342 times.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 56 not taken.
✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 56 not taken.
4343 HANDLE_UNRESOLVED_TYPE_ER(rhs.type)
279
2/4
✓ Branch 18 → 19 taken 4342 times.
✗ Branch 18 → 59 not taken.
✓ Branch 19 → 20 taken 4342 times.
✗ Branch 19 → 57 not taken.
4342 const auto lhs = std::any_cast<ExprResult>(visit(node->operands[0]));
280
2/8
✓ Branch 21 → 22 taken 4342 times.
✗ Branch 21 → 75 not taken.
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 27 taken 4342 times.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 60 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 60 not taken.
4342 HANDLE_UNRESOLVED_TYPE_ER(lhs.type)
281
282 // Check operator
283 4342 QualType resultType;
284
2/2
✓ Branch 27 → 28 taken 2130 times.
✓ Branch 27 → 30 taken 2212 times.
4342 if (node->op == RelationalExprNode::RelationalOp::OP_LESS) // Operator was less
285
1/2
✓ Branch 28 → 29 taken 2130 times.
✗ Branch 28 → 61 not taken.
2130 resultType = OpRuleManager::getLessResultType(node, lhs, rhs);
286
2/2
✓ Branch 30 → 31 taken 607 times.
✓ Branch 30 → 33 taken 1605 times.
2212 else if (node->op == RelationalExprNode::RelationalOp::OP_GREATER) // Operator was greater
287
2/2
✓ Branch 31 → 32 taken 606 times.
✓ Branch 31 → 62 taken 1 time.
607 resultType = OpRuleManager::getGreaterResultType(node, lhs, rhs);
288
2/2
✓ Branch 33 → 34 taken 457 times.
✓ Branch 33 → 36 taken 1148 times.
1605 else if (node->op == RelationalExprNode::RelationalOp::OP_LESS_EQUAL) // Operator was less equal
289
1/2
✓ Branch 34 → 35 taken 457 times.
✗ Branch 34 → 63 not taken.
457 resultType = OpRuleManager::getLessEqualResultType(node, lhs, rhs);
290
1/2
✓ Branch 36 → 37 taken 1148 times.
✗ Branch 36 → 39 not taken.
1148 else if (node->op == RelationalExprNode::RelationalOp::OP_GREATER_EQUAL) // Operator was greater equal
291
1/2
✓ Branch 37 → 38 taken 1148 times.
✗ Branch 37 → 64 not taken.
1148 resultType = OpRuleManager::getGreaterEqualResultType(node, lhs, rhs);
292 else
293 throw CompilerError(UNHANDLED_BRANCH, "RelationalExpr fall-through"); // GCOV_EXCL_LINE
294
295
2/4
✓ Branch 47 → 48 taken 4341 times.
✗ Branch 47 → 74 not taken.
✓ Branch 48 → 49 taken 4341 times.
✗ Branch 48 → 74 not taken.
4341 return ExprResult{node->setEvaluatedSymbolType(resultType, manIdx)};
296 }
297
298 149 std::any TypeChecker::visitShiftExpr(ShiftExprNode *node) {
299 // Check if at least one shift operator is applied
300
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 149 times.
149 if (node->operands.size() == 1)
301 return visit(node->operands.front());
302
303 // Visit leftmost operand
304
2/4
✓ Branch 8 → 9 taken 149 times.
✗ Branch 8 → 53 not taken.
✓ Branch 9 → 10 taken 149 times.
✗ Branch 9 → 51 not taken.
149 auto currentResult = std::any_cast<ExprResult>(visit(node->operands[0]));
305
2/8
✓ Branch 11 → 12 taken 149 times.
✗ Branch 11 → 69 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 149 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 54 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 54 not taken.
149 HANDLE_UNRESOLVED_TYPE_ER(currentResult.type)
306
307 // Loop through remaining operands
308
2/2
✓ Branch 45 → 18 taken 198 times.
✓ Branch 45 → 46 taken 149 times.
347 for (size_t i = 0; i < node->opQueue.size(); i++) {
309
2/4
✓ Branch 19 → 20 taken 198 times.
✗ Branch 19 → 57 not taken.
✓ Branch 20 → 21 taken 198 times.
✗ Branch 20 → 55 not taken.
198 auto operandResult = std::any_cast<ExprResult>(visit(node->operands[i + 1]));
310
2/8
✓ Branch 22 → 23 taken 198 times.
✗ Branch 22 → 68 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 198 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 58 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 58 not taken.
198 HANDLE_UNRESOLVED_TYPE_ER(operandResult.type)
311
312 // Check operator
313 198 const ShiftExprNode::ShiftOp &op = node->opQueue.front().first;
314
2/2
✓ Branch 29 → 30 taken 122 times.
✓ Branch 29 → 31 taken 76 times.
198 if (op == ShiftExprNode::ShiftOp::OP_SHIFT_LEFT)
315
1/2
✓ Branch 30 → 41 taken 122 times.
✗ Branch 30 → 68 not taken.
122 currentResult = opRuleManager.getShiftLeftResultType(node, currentResult, operandResult, i);
316
1/2
✓ Branch 31 → 32 taken 76 times.
✗ Branch 31 → 33 not taken.
76 else if (op == ShiftExprNode::ShiftOp::OP_SHIFT_RIGHT)
317
1/2
✓ Branch 32 → 41 taken 76 times.
✗ Branch 32 → 68 not taken.
76 currentResult = opRuleManager.getShiftRightResultType(node, currentResult, operandResult, i);
318 else
319 throw CompilerError(UNHANDLED_BRANCH, "ShiftExpr fall-through"); // GCOV_EXCL_LINE
320
321 // Push the new item and pop the old one on the other side of the queue
322
1/2
✓ Branch 41 → 42 taken 198 times.
✗ Branch 41 → 68 not taken.
198 node->opQueue.emplace(op, currentResult.type);
323 198 node->opQueue.pop();
324 }
325
326
1/2
✓ Branch 46 → 47 taken 149 times.
✗ Branch 46 → 69 not taken.
149 node->setEvaluatedSymbolType(currentResult.type, manIdx);
327
1/2
✓ Branch 47 → 48 taken 149 times.
✗ Branch 47 → 69 not taken.
149 return currentResult;
328 }
329
330 5021 std::any TypeChecker::visitAdditiveExpr(AdditiveExprNode *node) {
331 // Check if at least one additive operator is applied
332
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 5021 times.
5021 if (node->operands.size() == 1)
333 return visit(node->operands.front());
334
335 // Visit leftmost operand
336
2/4
✓ Branch 8 → 9 taken 5021 times.
✗ Branch 8 → 53 not taken.
✓ Branch 9 → 10 taken 5021 times.
✗ Branch 9 → 51 not taken.
5021 auto currentResult = std::any_cast<ExprResult>(visit(node->operands[0]));
337
2/8
✓ Branch 11 → 12 taken 5021 times.
✗ Branch 11 → 69 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 5021 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 54 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 54 not taken.
5021 HANDLE_UNRESOLVED_TYPE_ER(currentResult.type)
338
339 // Loop through remaining operands
340
2/2
✓ Branch 45 → 18 taken 5698 times.
✓ Branch 45 → 46 taken 5020 times.
10718 for (size_t i = 0; i < node->opQueue.size(); i++) {
341
2/4
✓ Branch 19 → 20 taken 5698 times.
✗ Branch 19 → 57 not taken.
✓ Branch 20 → 21 taken 5698 times.
✗ Branch 20 → 55 not taken.
5698 auto operandResult = std::any_cast<ExprResult>(visit(node->operands[i + 1]));
342
2/8
✓ Branch 22 → 23 taken 5698 times.
✗ Branch 22 → 68 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 5698 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 58 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 58 not taken.
5698 HANDLE_UNRESOLVED_TYPE_ER(operandResult.type)
343
344 // Check operator
345 5698 const AdditiveExprNode::AdditiveOp &op = node->opQueue.front().first;
346
2/2
✓ Branch 29 → 30 taken 3567 times.
✓ Branch 29 → 31 taken 2131 times.
5698 if (op == AdditiveExprNode::AdditiveOp::OP_PLUS)
347
2/2
✓ Branch 30 → 41 taken 3566 times.
✓ Branch 30 → 68 taken 1 time.
3567 currentResult = opRuleManager.getPlusResultType(node, currentResult, operandResult, i);
348
1/2
✓ Branch 31 → 32 taken 2131 times.
✗ Branch 31 → 33 not taken.
2131 else if (op == AdditiveExprNode::AdditiveOp::OP_MINUS)
349
1/2
✓ Branch 32 → 41 taken 2131 times.
✗ Branch 32 → 68 not taken.
2131 currentResult = opRuleManager.getMinusResultType(node, currentResult, operandResult, i);
350 else
351 throw CompilerError(UNHANDLED_BRANCH, "AdditiveExpr fall-through"); // GCOV_EXCL_LINE
352
353 // Push the new item and pop the old one on the other side of the queue
354
1/2
✓ Branch 41 → 42 taken 5697 times.
✗ Branch 41 → 68 not taken.
5697 node->opQueue.emplace(op, currentResult.type);
355 5697 node->opQueue.pop();
356 }
357
358
1/2
✓ Branch 46 → 47 taken 5020 times.
✗ Branch 46 → 69 not taken.
5020 node->setEvaluatedSymbolType(currentResult.type, manIdx);
359
1/2
✓ Branch 47 → 48 taken 5020 times.
✗ Branch 47 → 69 not taken.
5020 return currentResult;
360 }
361
362 1070 std::any TypeChecker::visitMultiplicativeExpr(MultiplicativeExprNode *node) {
363 // Check if at least one multiplicative operator is applied
364
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 1070 times.
1070 if (node->operands.size() == 1)
365 return visit(node->operands.front());
366
367 // Visit leftmost operand
368
2/4
✓ Branch 8 → 9 taken 1070 times.
✗ Branch 8 → 55 not taken.
✓ Branch 9 → 10 taken 1070 times.
✗ Branch 9 → 53 not taken.
1070 auto currentResult = std::any_cast<ExprResult>(visit(node->operands[0]));
369
2/8
✓ Branch 11 → 12 taken 1070 times.
✗ Branch 11 → 71 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 1070 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 56 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 56 not taken.
1070 HANDLE_UNRESOLVED_TYPE_ER(currentResult.type)
370 // Loop through remaining operands
371
2/2
✓ Branch 47 → 18 taken 1094 times.
✓ Branch 47 → 48 taken 1069 times.
2163 for (size_t i = 0; i < node->opQueue.size(); i++) {
372
2/4
✓ Branch 19 → 20 taken 1094 times.
✗ Branch 19 → 59 not taken.
✓ Branch 20 → 21 taken 1094 times.
✗ Branch 20 → 57 not taken.
1094 auto operandResult = std::any_cast<ExprResult>(visit(node->operands[i + 1]));
373
2/8
✓ Branch 22 → 23 taken 1094 times.
✗ Branch 22 → 70 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 1094 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 60 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 60 not taken.
1094 HANDLE_UNRESOLVED_TYPE_ER(operandResult.type)
374
375 // Check operator
376 1094 const MultiplicativeExprNode::MultiplicativeOp &op = node->opQueue.front().first;
377
2/2
✓ Branch 29 → 30 taken 893 times.
✓ Branch 29 → 31 taken 201 times.
1094 if (op == MultiplicativeExprNode::MultiplicativeOp::OP_MUL)
378
2/2
✓ Branch 30 → 43 taken 892 times.
✓ Branch 30 → 70 taken 1 time.
893 currentResult = opRuleManager.getMulResultType(node, currentResult, operandResult, i);
379
2/2
✓ Branch 31 → 32 taken 174 times.
✓ Branch 31 → 33 taken 27 times.
201 else if (op == MultiplicativeExprNode::MultiplicativeOp::OP_DIV)
380
1/2
✓ Branch 32 → 43 taken 174 times.
✗ Branch 32 → 70 not taken.
174 currentResult = opRuleManager.getDivResultType(node, currentResult, operandResult, i);
381
1/2
✓ Branch 33 → 34 taken 27 times.
✗ Branch 33 → 35 not taken.
27 else if (op == MultiplicativeExprNode::MultiplicativeOp::OP_REM)
382
1/2
✓ Branch 34 → 43 taken 27 times.
✗ Branch 34 → 70 not taken.
27 currentResult = OpRuleManager::getRemResultType(node, currentResult, operandResult);
383 else
384 throw CompilerError(UNHANDLED_BRANCH, "Multiplicative fall-through"); // GCOV_EXCL_LINE
385
386 // Push the new item and pop the old one on the other side of the queue
387
1/2
✓ Branch 43 → 44 taken 1093 times.
✗ Branch 43 → 70 not taken.
1093 node->opQueue.emplace(op, currentResult.type);
388 1093 node->opQueue.pop();
389 }
390
391
1/2
✓ Branch 48 → 49 taken 1069 times.
✗ Branch 48 → 71 not taken.
1069 node->setEvaluatedSymbolType(currentResult.type, manIdx);
392
1/2
✓ Branch 49 → 50 taken 1069 times.
✗ Branch 49 → 71 not taken.
1069 return currentResult;
393 }
394
395 2975 std::any TypeChecker::visitCastExpr(CastExprNode *node) {
396 // Check if cast is applied
397
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 2975 times.
2975 if (!node->isCast)
398 return visit(node->prefixUnaryExpr);
399
400 // Visit destination type
401
2/4
✓ Branch 5 → 6 taken 2975 times.
✗ Branch 5 → 49 not taken.
✓ Branch 6 → 7 taken 2975 times.
✗ Branch 6 → 47 not taken.
2975 const auto dstType = std::any_cast<QualType>(visit(node->dataType));
402
2/8
✓ Branch 8 → 9 taken 2975 times.
✗ Branch 8 → 65 not taken.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 14 taken 2975 times.
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 50 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 50 not taken.
2975 HANDLE_UNRESOLVED_TYPE_ER(dstType)
403 // Visit source type
404
2/4
✓ Branch 14 → 15 taken 2975 times.
✗ Branch 14 → 53 not taken.
✓ Branch 15 → 16 taken 2975 times.
✗ Branch 15 → 51 not taken.
2975 const auto src = std::any_cast<ExprResult>(visit(node->assignExpr));
405
2/8
✓ Branch 17 → 18 taken 2975 times.
✗ Branch 17 → 65 not taken.
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 23 taken 2975 times.
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 54 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 54 not taken.
2975 HANDLE_UNRESOLVED_TYPE_ER(src.type)
406
407 // Check for identity cast
408
3/4
✓ Branch 23 → 24 taken 2975 times.
✗ Branch 23 → 65 not taken.
✓ Branch 24 → 25 taken 311 times.
✓ Branch 24 → 34 taken 2664 times.
2975 if (src.type == dstType) {
409
2/4
✓ Branch 27 → 28 taken 311 times.
✗ Branch 27 → 57 not taken.
✓ Branch 28 → 29 taken 311 times.
✗ Branch 28 → 55 not taken.
311 const CompilerWarning warning(node->codeLoc, IDENTITY_CAST, "You cast from a type to itself. Thus, this can be simplified.");
410
1/2
✓ Branch 31 → 32 taken 311 times.
✗ Branch 31 → 61 not taken.
311 sourceFile->compilerOutput.warnings.push_back(warning);
411 311 }
412
413 // Get result type
414
1/2
✓ Branch 34 → 35 taken 2975 times.
✗ Branch 34 → 65 not taken.
2975 const QualType resultType = opRuleManager.getCastResultType(node, dstType, src);
415
416
1/2
✓ Branch 35 → 36 taken 2975 times.
✗ Branch 35 → 65 not taken.
2975 const bool typesMatch = dstType.matches(src.type, false, true, true);
417
1/2
✓ Branch 36 → 37 taken 2975 times.
✗ Branch 36 → 65 not taken.
2975 const bool sameContainerType = src.type.isSameContainerTypeAs(dstType);
418
4/4
✓ Branch 37 → 38 taken 2664 times.
✓ Branch 37 → 39 taken 311 times.
✓ Branch 38 → 39 taken 148 times.
✓ Branch 38 → 40 taken 2516 times.
2975 SymbolTableEntry *entry = typesMatch || sameContainerType ? src.entry : nullptr;
419
2/4
✓ Branch 41 → 42 taken 2975 times.
✗ Branch 41 → 64 not taken.
✓ Branch 42 → 43 taken 2975 times.
✗ Branch 42 → 64 not taken.
2975 return ExprResult{node->setEvaluatedSymbolType(resultType, manIdx), entry};
420 }
421
422 2294 std::any TypeChecker::visitPrefixUnaryExpr(PrefixUnaryExprNode *node) {
423 // If no operator is applied, simply visit the postfix unary expression
424
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 2294 times.
2294 if (node->op == PrefixUnaryExprNode::PrefixUnaryOp::OP_NONE)
425 return visit(node->postfixUnaryExpr);
426
427 // Visit the right side
428 2294 ExprNode *rhsNode = node->prefixUnaryExpr;
429
2/4
✓ Branch 5 → 6 taken 2294 times.
✗ Branch 5 → 57 not taken.
✓ Branch 6 → 7 taken 2294 times.
✗ Branch 6 → 55 not taken.
2294 auto operand = std::any_cast<ExprResult>(visit(rhsNode));
430 2294 auto [operandType, operandEntry] = operand;
431
5/8
✓ Branch 8 → 9 taken 2294 times.
✗ Branch 8 → 78 not taken.
✓ Branch 9 → 10 taken 1 time.
✓ Branch 9 → 14 taken 2293 times.
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 58 not taken.
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 58 not taken.
2294 HANDLE_UNRESOLVED_TYPE_ER(operandType)
432 // Determine action, based on the given operator
433
7/8
✓ Branch 14 → 15 taken 893 times.
✓ Branch 14 → 17 taken 30 times.
✓ Branch 14 → 25 taken 12 times.
✓ Branch 14 → 33 taken 854 times.
✓ Branch 14 → 35 taken 5 times.
✓ Branch 14 → 37 taken 277 times.
✓ Branch 14 → 39 taken 222 times.
✗ Branch 14 → 41 not taken.
2293 switch (node->op) {
434 893 case PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS:
435
1/2
✓ Branch 15 → 16 taken 893 times.
✗ Branch 15 → 59 not taken.
893 operandType = OpRuleManager::getPrefixMinusResultType(node, operand);
436 893 break;
437 30 case PrefixUnaryExprNode::PrefixUnaryOp::OP_PLUS_PLUS:
438
1/2
✓ Branch 17 → 18 taken 30 times.
✗ Branch 17 → 60 not taken.
30 operandType = opRuleManager.getPrefixPlusPlusResultType(node, operand);
439
440
2/2
✓ Branch 18 → 19 taken 27 times.
✓ Branch 18 → 24 taken 3 times.
30 if (operandEntry) {
441 // In case the lhs is captured, notify the capture about the write access
442
2/4
✓ Branch 19 → 20 taken 27 times.
✗ Branch 19 → 78 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 27 times.
27 if (Capture *lhsCapture = currentScope->symbolTable.lookupCapture(operandEntry->name); lhsCapture)
443 lhsCapture->setAccessType(READ_WRITE);
444
445 // Update the state of the variable
446
1/2
✓ Branch 22 → 23 taken 27 times.
✗ Branch 22 → 61 not taken.
27 operandEntry->updateState(INITIALIZED, node);
447 }
448
449 30 break;
450 12 case PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS_MINUS:
451
2/2
✓ Branch 25 → 26 taken 11 times.
✓ Branch 25 → 62 taken 1 time.
12 operandType = opRuleManager.getPrefixMinusMinusResultType(node, operand);
452
453
2/2
✓ Branch 26 → 27 taken 8 times.
✓ Branch 26 → 32 taken 3 times.
11 if (operandEntry) {
454 // In case the lhs is captured, notify the capture about the write access
455
2/4
✓ Branch 27 → 28 taken 8 times.
✗ Branch 27 → 78 not taken.
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 8 times.
8 if (Capture *lhsCapture = currentScope->symbolTable.lookupCapture(operandEntry->name); lhsCapture)
456 lhsCapture->setAccessType(READ_WRITE);
457
458 // Update the state of the variable
459
1/2
✓ Branch 30 → 31 taken 8 times.
✗ Branch 30 → 63 not taken.
8 operandEntry->updateState(INITIALIZED, node);
460 }
461
462 11 break;
463 854 case PrefixUnaryExprNode::PrefixUnaryOp::OP_NOT:
464
1/2
✓ Branch 33 → 34 taken 854 times.
✗ Branch 33 → 64 not taken.
854 operandType = OpRuleManager::getPrefixNotResultType(node, operand);
465 854 break;
466 5 case PrefixUnaryExprNode::PrefixUnaryOp::OP_BITWISE_NOT:
467
1/2
✓ Branch 35 → 36 taken 5 times.
✗ Branch 35 → 65 not taken.
5 operandType = OpRuleManager::getPrefixBitwiseNotResultType(node, operand);
468 5 break;
469 277 case PrefixUnaryExprNode::PrefixUnaryOp::OP_DEREFERENCE:
470
2/2
✓ Branch 37 → 38 taken 276 times.
✓ Branch 37 → 66 taken 1 time.
277 operandType = OpRuleManager::getPrefixMulResultType(node, operand);
471 276 break;
472 222 case PrefixUnaryExprNode::PrefixUnaryOp::OP_ADDRESS_OF:
473
1/2
✓ Branch 39 → 40 taken 222 times.
✗ Branch 39 → 67 not taken.
222 operandType = OpRuleManager::getPrefixBitwiseAndResultType(node, operand);
474 222 break;
475 default: // GCOV_EXCL_LINE
476 throw CompilerError(UNHANDLED_BRANCH, "PrefixUnaryExpr fall-through"); // GCOV_EXCL_LINE
477 }
478
479
2/4
✓ Branch 49 → 50 taken 2291 times.
✗ Branch 49 → 77 not taken.
✓ Branch 50 → 51 taken 2291 times.
✗ Branch 50 → 77 not taken.
2291 return ExprResult{node->setEvaluatedSymbolType(operandType, manIdx), operandEntry};
480 }
481
482 25832 std::any TypeChecker::visitPostfixUnaryExpr(PostfixUnaryExprNode *node) {
483 // If no operator is applied, simply visit the atomic expression
484
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 25832 times.
25832 if (node->op == PostfixUnaryExprNode::PostfixUnaryOp::OP_NONE)
485 return visit(node->atomicExpr);
486
487 // Visit left side
488 25832 ExprNode *lhsNode = node->postfixUnaryExpr;
489
2/4
✓ Branch 5 → 6 taken 25832 times.
✗ Branch 5 → 211 not taken.
✓ Branch 6 → 7 taken 25832 times.
✗ Branch 6 → 209 not taken.
25832 auto operand = std::any_cast<ExprResult>(visit(lhsNode));
490 25832 auto [operandType, operandEntry] = operand;
491
5/8
✓ Branch 8 → 9 taken 25832 times.
✗ Branch 8 → 316 not taken.
✓ Branch 9 → 10 taken 6 times.
✓ Branch 9 → 14 taken 25826 times.
✓ Branch 10 → 11 taken 6 times.
✗ Branch 10 → 212 not taken.
✓ Branch 11 → 12 taken 6 times.
✗ Branch 11 → 212 not taken.
25832 HANDLE_UNRESOLVED_TYPE_ER(operandType)
492
493
4/5
✓ Branch 14 → 15 taken 3831 times.
✓ Branch 14 → 101 taken 19471 times.
✓ Branch 14 → 159 taken 2056 times.
✓ Branch 14 → 167 taken 468 times.
✗ Branch 14 → 175 not taken.
25826 switch (node->op) {
494 3831 case PostfixUnaryExprNode::PostfixUnaryOp::OP_SUBSCRIPT: {
495 // Visit index assignment
496 3831 ExprNode *indexAssignExpr = node->subscriptIndexExpr;
497
2/4
✓ Branch 15 → 16 taken 3831 times.
✗ Branch 15 → 215 not taken.
✓ Branch 16 → 17 taken 3831 times.
✗ Branch 16 → 213 not taken.
3831 const auto index = std::any_cast<ExprResult>(visit(indexAssignExpr));
498
2/8
✓ Branch 18 → 19 taken 3831 times.
✗ Branch 18 → 258 not taken.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 24 taken 3831 times.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 216 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 216 not taken.
3831 HANDLE_UNRESOLVED_TYPE_ER(index.type)
499
500 // Check is there is an overloaded operator function available, if yes accept it
501
1/2
✓ Branch 24 → 25 taken 3831 times.
✗ Branch 24 → 217 not taken.
3831 const auto [type, _] = opRuleManager.isOperatorOverloadingFctAvailable<2>(node, OP_FCT_SUBSCRIPT, {operand, index}, 0);
502
3/4
✓ Branch 25 → 26 taken 3831 times.
✗ Branch 25 → 258 not taken.
✓ Branch 26 → 27 taken 133 times.
✓ Branch 26 → 28 taken 3698 times.
3831 if (!type.is(TY_INVALID)) {
503 133 operandType = type;
504 3829 break;
505 }
506
507
1/2
✓ Branch 28 → 29 taken 3698 times.
✗ Branch 28 → 218 not taken.
3698 operandType = operandType.removeReferenceWrapper();
508
509 // Check if the index is of the right type
510
3/4
✓ Branch 29 → 30 taken 3698 times.
✗ Branch 29 → 219 not taken.
✓ Branch 30 → 31 taken 1 time.
✓ Branch 30 → 41 taken 3697 times.
3698 if (!index.type.isOneOf({TY_INT, TY_LONG}))
511
4/8
✓ Branch 33 → 34 taken 1 time.
✗ Branch 33 → 222 not taken.
✓ Branch 34 → 35 taken 1 time.
✗ Branch 34 → 220 not taken.
✓ Branch 37 → 38 taken 1 time.
✗ Branch 37 → 226 not taken.
✓ Branch 38 → 39 taken 1 time.
✗ Branch 38 → 226 not taken.
3 SOFT_ERROR_ER(node, ARRAY_INDEX_NOT_INT_OR_LONG, "Array index must be of type int or long")
512
513 // Check if we can apply the subscript operator on the lhs type
514
2/4
✓ Branch 41 → 42 taken 3697 times.
✗ Branch 41 → 227 not taken.
✗ Branch 42 → 43 not taken.
✓ Branch 42 → 52 taken 3697 times.
3697 if (!operandType.isOneOf({TY_ARRAY, TY_PTR, TY_STRING}))
515 SOFT_ERROR_ER(node, OPERATOR_WRONG_DATA_TYPE,
516 "Can only apply subscript operator on array type, got " + operandType.getName(true))
517
518 // Check if we have an unsafe operation
519
6/10
✓ Branch 52 → 53 taken 3697 times.
✗ Branch 52 → 258 not taken.
✓ Branch 53 → 54 taken 2621 times.
✓ Branch 53 → 57 taken 1076 times.
✓ Branch 54 → 55 taken 2621 times.
✗ Branch 54 → 258 not taken.
✗ Branch 55 → 56 not taken.
✓ Branch 55 → 57 taken 2621 times.
✗ Branch 58 → 59 not taken.
✓ Branch 58 → 69 taken 3697 times.
3697 if (operandType.isPtr() && !currentScope->doesAllowUnsafeOperations())
520 SOFT_ERROR_ER(
521 node, UNSAFE_OPERATION_IN_SAFE_CONTEXT,
522 "The subscript operator on pointers is an unsafe operation. Use unsafe blocks if you know what you are doing.")
523
524 // In case of compile time index value and known array size, perform a compile time out-of-bounds check
525
8/10
✓ Branch 69 → 70 taken 3697 times.
✗ Branch 69 → 258 not taken.
✓ Branch 70 → 71 taken 199 times.
✓ Branch 70 → 76 taken 3498 times.
✓ Branch 71 → 72 taken 199 times.
✗ Branch 71 → 258 not taken.
✓ Branch 72 → 73 taken 158 times.
✓ Branch 72 → 76 taken 41 times.
✓ Branch 77 → 78 taken 91 times.
✓ Branch 77 → 96 taken 3606 times.
3855 if (operandType.isArray() && operandType.getArraySize() != ARRAY_SIZE_UNKNOWN &&
526
3/4
✓ Branch 73 → 74 taken 158 times.
✗ Branch 73 → 258 not taken.
✓ Branch 74 → 75 taken 91 times.
✓ Branch 74 → 76 taken 67 times.
158 indexAssignExpr->hasCompileTimeValue(manIdx)) {
527
1/2
✓ Branch 78 → 79 taken 91 times.
✗ Branch 78 → 258 not taken.
91 const int32_t constIndex = indexAssignExpr->getCompileTimeValue(manIdx).intValue;
528
1/2
✓ Branch 79 → 80 taken 91 times.
✗ Branch 79 → 258 not taken.
91 const unsigned int constSize = operandType.getArraySize();
529 // Check if we are accessing out-of-bounds memory
530
2/2
✓ Branch 80 → 81 taken 1 time.
✓ Branch 80 → 96 taken 90 times.
91 if (constIndex >= static_cast<int32_t>(constSize)) {
531 1 const std::string idxStr = std::to_string(constIndex);
532 1 const std::string sizeStr = std::to_string(constSize);
533
6/12
✓ Branch 83 → 84 taken 1 time.
✗ Branch 83 → 248 not taken.
✓ Branch 84 → 85 taken 1 time.
✗ Branch 84 → 246 not taken.
✓ Branch 85 → 86 taken 1 time.
✗ Branch 85 → 244 not taken.
✓ Branch 86 → 87 taken 1 time.
✗ Branch 86 → 242 not taken.
✓ Branch 90 → 91 taken 1 time.
✗ Branch 90 → 251 not taken.
✓ Branch 91 → 92 taken 1 time.
✗ Branch 91 → 251 not taken.
1 SOFT_ERROR_ER(node, ARRAY_INDEX_OUT_OF_BOUNDS,
534 "You are trying to access element with index " + idxStr + " of an array with size " + sizeStr)
535 1 }
536 }
537
538 // Get item type
539
1/2
✓ Branch 96 → 97 taken 3696 times.
✗ Branch 96 → 257 not taken.
3696 operandType = operandType.getContained();
540
541 // Remove heap qualifier
542 3696 operandType.getQualifiers().isHeap = false;
543
544 3696 break;
545 }
546 19471 case PostfixUnaryExprNode::PostfixUnaryOp::OP_MEMBER_ACCESS: {
547 19471 const std::string &fieldName = node->identifier;
548
549 // Check if lhs is enum or strobj
550
1/2
✓ Branch 101 → 102 taken 19471 times.
✗ Branch 101 → 286 not taken.
19471 const QualType lhsBaseTy = operandType.autoDeReference();
551
3/4
✓ Branch 102 → 103 taken 19471 times.
✗ Branch 102 → 286 not taken.
✓ Branch 103 → 104 taken 1 time.
✓ Branch 103 → 113 taken 19470 times.
19471 if (!lhsBaseTy.is(TY_STRUCT))
552
5/10
✓ Branch 104 → 105 taken 1 time.
✗ Branch 104 → 263 not taken.
✓ Branch 105 → 106 taken 1 time.
✗ Branch 105 → 261 not taken.
✓ Branch 106 → 107 taken 1 time.
✗ Branch 106 → 259 not taken.
✓ Branch 109 → 110 taken 1 time.
✗ Branch 109 → 265 not taken.
✓ Branch 110 → 111 taken 1 time.
✗ Branch 110 → 265 not taken.
1 SOFT_ERROR_ER(node, INVALID_MEMBER_ACCESS, "Cannot apply member access operator on " + operandType.getName(false))
553
554 // Retrieve registry entry
555
1/2
✓ Branch 113 → 114 taken 19470 times.
✗ Branch 113 → 286 not taken.
19470 const std::string &structName = lhsBaseTy.getSubType();
556
1/2
✓ Branch 114 → 115 taken 19470 times.
✗ Branch 114 → 286 not taken.
19470 Scope *structScope = lhsBaseTy.getBodyScope();
557
558 // If we only have the generic struct scope, lookup the concrete manifestation scope
559
2/2
✓ Branch 115 → 116 taken 123 times.
✓ Branch 115 → 120 taken 19347 times.
19470 if (structScope->isGenericScope) {
560
1/2
✓ Branch 116 → 117 taken 123 times.
✗ Branch 116 → 286 not taken.
123 const Struct *spiceStruct = lhsBaseTy.getStruct(node);
561
1/2
✗ Branch 117 → 118 not taken.
✓ Branch 117 → 119 taken 123 times.
123 assert(spiceStruct != nullptr);
562 123 structScope = spiceStruct->scope;
563 }
564
1/2
✗ Branch 120 → 121 not taken.
✓ Branch 120 → 122 taken 19470 times.
19470 assert(!structScope->isGenericScope); // At this point we always expect a substantiation scope
565
566 // Get accessed field
567 19470 std::vector<size_t> indexPath;
568
1/2
✓ Branch 122 → 123 taken 19470 times.
✗ Branch 122 → 284 not taken.
19470 SymbolTableEntry *memberEntry = structScope->symbolTable.lookupInComposedFields(fieldName, indexPath);
569
2/2
✓ Branch 123 → 124 taken 2 times.
✓ Branch 123 → 135 taken 19468 times.
19470 if (!memberEntry)
570
6/12
✓ Branch 124 → 125 taken 2 times.
✗ Branch 124 → 272 not taken.
✓ Branch 125 → 126 taken 2 times.
✗ Branch 125 → 270 not taken.
✓ Branch 126 → 127 taken 2 times.
✗ Branch 126 → 268 not taken.
✓ Branch 127 → 128 taken 2 times.
✗ Branch 127 → 266 not taken.
✓ Branch 131 → 132 taken 2 times.
✗ Branch 131 → 275 not taken.
✓ Branch 132 → 133 taken 2 times.
✗ Branch 132 → 275 not taken.
2 SOFT_ERROR_ER(node, REFERENCED_UNDEFINED_VARIABLE, "Field '" + node->identifier + "' not found in struct " + structName)
571
1/2
✓ Branch 135 → 136 taken 19468 times.
✗ Branch 135 → 284 not taken.
19468 const QualType memberType = memberEntry->getQualType();
572
573 // Check for insufficient visibility
574
8/14
✓ Branch 136 → 137 taken 19468 times.
✗ Branch 136 → 276 not taken.
✓ Branch 137 → 138 taken 90 times.
✓ Branch 137 → 143 taken 19378 times.
✓ Branch 138 → 139 taken 90 times.
✗ Branch 138 → 276 not taken.
✓ Branch 139 → 140 taken 90 times.
✗ Branch 139 → 276 not taken.
✓ Branch 140 → 141 taken 90 times.
✗ Branch 140 → 276 not taken.
✗ Branch 141 → 142 not taken.
✓ Branch 141 → 143 taken 90 times.
✗ Branch 144 → 145 not taken.
✓ Branch 144 → 154 taken 19468 times.
19468 if (structScope->isImportedBy(rootScope) && !memberEntry->getQualType().getBase().isPublic())
575 SOFT_ERROR_ER(node, INSUFFICIENT_VISIBILITY, "Cannot access field '" + fieldName + "' due to its private visibility")
576
577 // Set field to used
578 19468 memberEntry->used = true;
579
580 // Overwrite type and entry of left side with member type and entry
581 19468 operandType = memberType;
582 19468 operandEntry = memberEntry;
583 19468 break;
584
2/2
✓ Branch 156 → 157 taken 2 times.
✓ Branch 156 → 158 taken 19468 times.
19470 }
585 2056 case PostfixUnaryExprNode::PostfixUnaryOp::OP_PLUS_PLUS: {
586
2/2
✓ Branch 159 → 160 taken 2054 times.
✓ Branch 159 → 287 taken 2 times.
2056 operandType = opRuleManager.getPostfixPlusPlusResultType(node, operand).type;
587
588
2/2
✓ Branch 160 → 161 taken 2050 times.
✓ Branch 160 → 166 taken 4 times.
2054 if (operandEntry) {
589 // In case the lhs is captured, notify the capture about the write access
590
3/4
✓ Branch 161 → 162 taken 2050 times.
✗ Branch 161 → 316 not taken.
✓ Branch 162 → 163 taken 4 times.
✓ Branch 162 → 164 taken 2046 times.
2050 if (Capture *lhsCapture = currentScope->symbolTable.lookupCapture(operandEntry->name); lhsCapture)
591
1/2
✓ Branch 163 → 164 taken 4 times.
✗ Branch 163 → 316 not taken.
4 lhsCapture->setAccessType(READ_WRITE);
592
593 // Update the state of the variable
594
1/2
✓ Branch 164 → 165 taken 2050 times.
✗ Branch 164 → 288 not taken.
2050 operandEntry->updateState(INITIALIZED, node);
595 }
596
597 2054 break;
598 }
599 468 case PostfixUnaryExprNode::PostfixUnaryOp::OP_MINUS_MINUS: {
600
1/2
✓ Branch 167 → 168 taken 468 times.
✗ Branch 167 → 289 not taken.
468 operandType = opRuleManager.getPostfixMinusMinusResultType(node, operand).type;
601
602
2/2
✓ Branch 168 → 169 taken 464 times.
✓ Branch 168 → 174 taken 4 times.
468 if (operandEntry) {
603 // In case the lhs is captured, notify the capture about the write access
604
2/4
✓ Branch 169 → 170 taken 464 times.
✗ Branch 169 → 316 not taken.
✗ Branch 170 → 171 not taken.
✓ Branch 170 → 172 taken 464 times.
464 if (Capture *lhsCapture = currentScope->symbolTable.lookupCapture(operandEntry->name); lhsCapture)
605 lhsCapture->setAccessType(READ_WRITE);
606
607 // Update the state of the variable
608
1/2
✓ Branch 172 → 173 taken 464 times.
✗ Branch 172 → 290 not taken.
464 operandEntry->updateState(INITIALIZED, node);
609 }
610
611 468 break;
612 }
613 default: // GCOV_EXCL_LINE
614 throw CompilerError(UNHANDLED_BRANCH, "PostfixUnaryExpr fall-through"); // GCOV_EXCL_LINE
615 }
616
617
2/4
✓ Branch 183 → 184 taken 25819 times.
✗ Branch 183 → 316 not taken.
✗ Branch 184 → 185 not taken.
✓ Branch 184 → 203 taken 25819 times.
25819 if (operandType.is(TY_INVALID)) {
618 const std::string &varName = operandEntry ? operandEntry->name : "";
619 SOFT_ERROR_ER(node, REFERENCED_UNDEFINED_VARIABLE, "Variable '" + varName + "' was referenced before declared")
620 }
621
622
2/4
✓ Branch 203 → 204 taken 25819 times.
✗ Branch 203 → 315 not taken.
✓ Branch 204 → 205 taken 25819 times.
✗ Branch 204 → 315 not taken.
25819 return ExprResult{node->setEvaluatedSymbolType(operandType, manIdx), operandEntry};
623 }
624
625 111841 std::any TypeChecker::visitAtomicExpr(AtomicExprNode *node) {
626 // Check if constant
627
2/2
✓ Branch 2 → 3 taken 22756 times.
✓ Branch 2 → 5 taken 89085 times.
111841 if (node->constant)
628
1/2
✓ Branch 3 → 4 taken 22756 times.
✗ Branch 3 → 216 not taken.
22756 return visit(node->constant);
629
630 // Check if value
631
2/2
✓ Branch 5 → 6 taken 23595 times.
✓ Branch 5 → 8 taken 65490 times.
89085 if (node->value)
632
2/2
✓ Branch 6 → 7 taken 23590 times.
✓ Branch 6 → 216 taken 5 times.
23595 return visit(node->value);
633
634 // Check for assign expression within parentheses
635
2/2
✓ Branch 8 → 9 taken 585 times.
✓ Branch 8 → 11 taken 64905 times.
65490 if (node->assignExpr)
636
2/2
✓ Branch 9 → 10 taken 582 times.
✓ Branch 9 → 216 taken 3 times.
585 return visit(node->assignExpr);
637
638 // Identifier (local or global variable access)
639
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 64905 times.
64905 assert(!node->fqIdentifier.empty());
640
641
1/2
✓ Branch 14 → 15 taken 64905 times.
✗ Branch 14 → 216 not taken.
64905 auto &[entry, accessScope, capture] = node->data.at(manIdx);
642 64905 accessScope = currentScope;
643
644 // Check if a local or global variable can be found by searching for the name
645
2/2
✓ Branch 16 → 17 taken 64596 times.
✓ Branch 16 → 22 taken 309 times.
64905 if (node->identifierFragments.size() == 1)
646 129192 entry = accessScope->lookup(node->identifierFragments.back());
647
648 // If no local or global was found, search in the name registry
649
2/2
✓ Branch 22 → 23 taken 398 times.
✓ Branch 22 → 35 taken 64507 times.
64905 if (!entry) {
650
1/2
✓ Branch 23 → 24 taken 398 times.
✗ Branch 23 → 216 not taken.
398 const NameRegistryEntry *registryEntry = sourceFile->getNameRegistryEntry(node->fqIdentifier);
651
2/2
✓ Branch 24 → 25 taken 1 time.
✓ Branch 24 → 34 taken 397 times.
398 if (!registryEntry)
652
5/10
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 164 not taken.
✓ Branch 26 → 27 taken 1 time.
✗ Branch 26 → 162 not taken.
✓ Branch 27 → 28 taken 1 time.
✗ Branch 27 → 160 not taken.
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 166 not taken.
✓ Branch 31 → 32 taken 1 time.
✗ Branch 31 → 166 not taken.
1 SOFT_ERROR_ER(node, REFERENCED_UNDEFINED_VARIABLE, "The variable '" + node->fqIdentifier + "' could not be found")
653 397 entry = registryEntry->targetEntry;
654 397 accessScope = registryEntry->targetScope;
655 }
656
1/2
✗ Branch 35 → 36 not taken.
✓ Branch 35 → 37 taken 64904 times.
64904 assert(entry != nullptr);
657 64904 entry->used = true;
658
1/2
✓ Branch 37 → 38 taken 64904 times.
✗ Branch 37 → 216 not taken.
64904 capture = accessScope->symbolTable.lookupCapture(entry->name);
659
660
1/2
✓ Branch 38 → 39 taken 64904 times.
✗ Branch 38 → 216 not taken.
64904 const QualType varType = entry->getQualType();
661
5/8
✓ Branch 39 → 40 taken 64904 times.
✗ Branch 39 → 216 not taken.
✓ Branch 40 → 41 taken 9 times.
✓ Branch 40 → 45 taken 64895 times.
✓ Branch 41 → 42 taken 9 times.
✗ Branch 41 → 167 not taken.
✓ Branch 42 → 43 taken 9 times.
✗ Branch 42 → 167 not taken.
64904 HANDLE_UNRESOLVED_TYPE_ER(varType)
662
3/4
✓ Branch 45 → 46 taken 64895 times.
✗ Branch 45 → 216 not taken.
✓ Branch 46 → 47 taken 2 times.
✓ Branch 46 → 56 taken 64893 times.
64895 if (varType.is(TY_INVALID))
663
5/10
✓ Branch 47 → 48 taken 2 times.
✗ Branch 47 → 172 not taken.
✓ Branch 48 → 49 taken 2 times.
✗ Branch 48 → 170 not taken.
✓ Branch 49 → 50 taken 2 times.
✗ Branch 49 → 168 not taken.
✓ Branch 52 → 53 taken 2 times.
✗ Branch 52 → 174 not taken.
✓ Branch 53 → 54 taken 2 times.
✗ Branch 53 → 174 not taken.
2 SOFT_ERROR_ER(node, USED_BEFORE_DECLARED, "Symbol '" + entry->name + "' was used before declared.")
664
665
7/8
✓ Branch 56 → 57 taken 64893 times.
✗ Branch 56 → 175 not taken.
✓ Branch 57 → 58 taken 67 times.
✓ Branch 57 → 60 taken 64826 times.
✓ Branch 58 → 59 taken 20 times.
✓ Branch 58 → 60 taken 47 times.
✓ Branch 61 → 62 taken 20 times.
✓ Branch 61 → 90 taken 64873 times.
64893 if (varType.isOneOf({TY_FUNCTION, TY_PROCEDURE}) && entry->global) {
666 // Check if overloaded function was referenced
667
1/2
✓ Branch 62 → 63 taken 20 times.
✗ Branch 62 → 216 not taken.
20 const std::vector<Function *> *manifestations = entry->declNode->getFctManifestations(entry->name);
668
2/2
✓ Branch 64 → 65 taken 1 time.
✓ Branch 64 → 75 taken 19 times.
20 if (manifestations->size() > 1)
669
4/8
✓ Branch 67 → 68 taken 1 time.
✗ Branch 67 → 178 not taken.
✓ Branch 68 → 69 taken 1 time.
✗ Branch 68 → 176 not taken.
✓ Branch 71 → 72 taken 1 time.
✗ Branch 71 → 182 not taken.
✓ Branch 72 → 73 taken 1 time.
✗ Branch 72 → 182 not taken.
3 SOFT_ERROR_ER(node, REFERENCED_OVERLOADED_FCT, "Overloaded functions / functions with optional params cannot be referenced")
670
2/2
✓ Branch 77 → 78 taken 1 time.
✓ Branch 77 → 88 taken 18 times.
19 if (!manifestations->front()->templateTypes.empty())
671
4/8
✓ Branch 80 → 81 taken 1 time.
✗ Branch 80 → 185 not taken.
✓ Branch 81 → 82 taken 1 time.
✗ Branch 81 → 183 not taken.
✓ Branch 84 → 85 taken 1 time.
✗ Branch 84 → 189 not taken.
✓ Branch 85 → 86 taken 1 time.
✗ Branch 85 → 189 not taken.
3 SOFT_ERROR_ER(node, REFERENCED_OVERLOADED_FCT, "Generic functions cannot be referenced")
672 // Set referenced function to used
673 18 Function *referencedFunction = manifestations->front();
674 18 referencedFunction->used = true;
675 18 referencedFunction->entry->used = true;
676 }
677
678 // The base type should be an extended primitive
679
1/2
✓ Branch 90 → 91 taken 64891 times.
✗ Branch 90 → 216 not taken.
64891 const QualType baseType = varType.getBase();
680
6/10
✓ Branch 91 → 92 taken 64891 times.
✗ Branch 91 → 216 not taken.
✓ Branch 92 → 93 taken 4 times.
✓ Branch 92 → 96 taken 64887 times.
✓ Branch 93 → 94 taken 4 times.
✗ Branch 93 → 216 not taken.
✗ Branch 94 → 95 not taken.
✓ Branch 94 → 96 taken 4 times.
✗ Branch 97 → 98 not taken.
✓ Branch 97 → 109 taken 64891 times.
64891 if (!baseType.isExtendedPrimitive() && !baseType.is(TY_DYN))
681 SOFT_ERROR_ER(node, INVALID_SYMBOL_ACCESS, "A symbol of type " + varType.getName(false) + " cannot be accessed here")
682
683 // Check if we have seen a 'this.' prefix, because the generator needs that
684
6/8
✓ Branch 109 → 110 taken 1 time.
✓ Branch 109 → 114 taken 64890 times.
✓ Branch 111 → 112 taken 1 time.
✗ Branch 111 → 216 not taken.
✓ Branch 112 → 113 taken 1 time.
✗ Branch 112 → 114 not taken.
✓ Branch 115 → 116 taken 1 time.
✓ Branch 115 → 125 taken 64890 times.
64891 if (entry->scope->type == ScopeType::STRUCT && node->identifierFragments.front() != THIS_VARIABLE_NAME)
685
5/10
✓ Branch 116 → 117 taken 1 time.
✗ Branch 116 → 204 not taken.
✓ Branch 117 → 118 taken 1 time.
✗ Branch 117 → 202 not taken.
✓ Branch 118 → 119 taken 1 time.
✗ Branch 118 → 200 not taken.
✓ Branch 121 → 122 taken 1 time.
✗ Branch 121 → 206 not taken.
✓ Branch 122 → 123 taken 1 time.
✗ Branch 122 → 206 not taken.
1 SOFT_ERROR_ER(node, REFERENCED_UNDEFINED_VARIABLE,
686 "The symbol '" + node->fqIdentifier + "' could not be found. Missing 'this.' prefix?")
687
688 // Ensure that the entry is public, if the symbol is imported.
689 // An exception are enum items. There it is sufficient, that the enum itself is public.
690
7/8
✓ Branch 125 → 126 taken 64890 times.
✗ Branch 125 → 216 not taken.
✓ Branch 126 → 127 taken 209 times.
✓ Branch 126 → 129 taken 64681 times.
✓ Branch 127 → 128 taken 82 times.
✓ Branch 127 → 129 taken 127 times.
✓ Branch 130 → 131 taken 82 times.
✓ Branch 130 → 144 taken 64808 times.
64890 if (accessScope->isImportedBy(rootScope) && accessScope->type != ScopeType::ENUM)
691
5/8
✓ Branch 131 → 132 taken 82 times.
✗ Branch 131 → 207 not taken.
✓ Branch 132 → 133 taken 82 times.
✗ Branch 132 → 207 not taken.
✓ Branch 133 → 134 taken 82 times.
✗ Branch 133 → 207 not taken.
✓ Branch 134 → 135 taken 1 time.
✓ Branch 134 → 144 taken 81 times.
82 if (!entry->getQualType().getBase().isPublic())
692
5/10
✓ Branch 135 → 136 taken 1 time.
✗ Branch 135 → 212 not taken.
✓ Branch 136 → 137 taken 1 time.
✗ Branch 136 → 210 not taken.
✓ Branch 137 → 138 taken 1 time.
✗ Branch 137 → 208 not taken.
✓ Branch 140 → 141 taken 1 time.
✗ Branch 140 → 214 not taken.
✓ Branch 141 → 142 taken 1 time.
✗ Branch 141 → 214 not taken.
1 SOFT_ERROR_ER(node, INSUFFICIENT_VISIBILITY, "Cannot access '" + entry->name + "' due to its private visibility")
693
694 // For enum item access, use access scope of the enum
695
2/2
✓ Branch 144 → 145 taken 304 times.
✓ Branch 144 → 146 taken 64585 times.
64889 if (entry->scope->type == ScopeType::ENUM)
696 304 accessScope = entry->scope;
697
698 // For struct access, use access scope of the struct
699
3/4
✓ Branch 146 → 147 taken 64889 times.
✗ Branch 146 → 216 not taken.
✓ Branch 147 → 148 taken 22017 times.
✓ Branch 147 → 154 taken 42872 times.
64889 if (baseType.is(TY_STRUCT)) {
700
1/2
✓ Branch 148 → 149 taken 22017 times.
✗ Branch 148 → 216 not taken.
22017 const std::string &structName = baseType.getSubType();
701
1/2
✓ Branch 149 → 150 taken 22017 times.
✗ Branch 149 → 216 not taken.
22017 const NameRegistryEntry *nameRegistryEntry = sourceFile->getNameRegistryEntry(structName);
702
1/2
✗ Branch 150 → 151 not taken.
✓ Branch 150 → 152 taken 22017 times.
22017 assert(nameRegistryEntry != nullptr);
703 22017 accessScope = nameRegistryEntry->targetScope;
704
1/2
✗ Branch 152 → 153 not taken.
✓ Branch 152 → 154 taken 22017 times.
22017 assert(accessScope != nullptr);
705 }
706
707
2/4
✓ Branch 154 → 155 taken 64889 times.
✗ Branch 154 → 215 not taken.
✓ Branch 155 → 156 taken 64889 times.
✗ Branch 155 → 215 not taken.
64889 return ExprResult{node->setEvaluatedSymbolType(varType, manIdx), entry};
708 }
709
710 } // namespace spice::compiler
711