GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 93.5% 388 / 10 / 425
Functions: 100.0% 16 / 0 / 16
Branches: 52.6% 686 / 32 / 1337

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 19028 std::any TypeChecker::visitAssignExpr(AssignExprNode *node) {
14 // Check if ternary
15
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 10 taken 19028 times.
19028 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 19028 times.
✗ Branch 10 → 142 not taken.
19028 if (node->op != AssignExprNode::AssignOp::OP_NONE) {
23 // Visit the right side first
24
2/4
✓ Branch 11 → 12 taken 19028 times.
✗ Branch 11 → 157 not taken.
✓ Branch 12 → 13 taken 19028 times.
✗ Branch 12 → 155 not taken.
19028 auto rhs = std::any_cast<ExprResult>(visit(node->rhs));
25 19028 auto [rhsType, rhsEntry] = rhs;
26
5/8
✓ Branch 14 → 15 taken 19028 times.
✗ Branch 14 → 201 not taken.
✓ Branch 15 → 16 taken 1 time.
✓ Branch 15 → 20 taken 19027 times.
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 158 not taken.
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 158 not taken.
19029 HANDLE_UNRESOLVED_TYPE_ER(rhsType)
27 // Then visit the left side
28
2/4
✓ Branch 20 → 21 taken 19027 times.
✗ Branch 20 → 161 not taken.
✓ Branch 21 → 22 taken 19027 times.
✗ Branch 21 → 159 not taken.
19027 auto lhs = std::any_cast<ExprResult>(visit(node->lhs));
29 19027 auto [lhsType, lhsVar] = lhs;
30
5/8
✓ Branch 23 → 24 taken 19027 times.
✗ Branch 23 → 201 not taken.
✓ Branch 24 → 25 taken 1 time.
✓ Branch 24 → 29 taken 19026 times.
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 162 not taken.
✓ Branch 26 → 27 taken 1 time.
✗ Branch 26 → 162 not taken.
19028 HANDLE_UNRESOLVED_TYPE_ER(lhsType)
31
32 // A native lambda stores its captures in the stack frame that created it. Storing a capturing lambda in a
33 // struct field lets it outlive those captures, so the captures would dangle. Reject this and direct the user
34 // to the owning std Lambda wrapper. Non-capturing lambdas (plain function pointers) are safe to store and are
35 // not affected. The std Lambda wrapper itself stores the captures-flagged lambda in its own field, so std
36 // files are exempt.
37
5/6
✓ Branch 30 → 31 taken 16775 times.
✓ Branch 30 → 40 taken 1 time.
✓ Branch 31 → 32 taken 16775 times.
✗ Branch 31 → 163 not taken.
✓ Branch 32 → 33 taken 13502 times.
✓ Branch 32 → 40 taken 3273 times.
16776 if (node->op == AssignExprNode::AssignOp::OP_ASSIGN && lhs.entry != nullptr && lhs.entry->isField() &&
38
12/16
✓ Branch 29 → 30 taken 16776 times.
✓ Branch 29 → 40 taken 2250 times.
✓ Branch 33 → 34 taken 13502 times.
✗ Branch 33 → 163 not taken.
✓ Branch 34 → 35 taken 13502 times.
✗ Branch 34 → 163 not taken.
✓ Branch 35 → 36 taken 85 times.
✓ Branch 35 → 40 taken 13417 times.
✓ Branch 36 → 37 taken 85 times.
✗ Branch 36 → 163 not taken.
✓ Branch 37 → 38 taken 1 time.
✓ Branch 37 → 40 taken 84 times.
✓ Branch 38 → 39 taken 1 time.
✗ Branch 38 → 40 not taken.
✓ Branch 41 → 42 taken 1 time.
✓ Branch 41 → 55 taken 19025 times.
35802 rhsType.getBase().isOneOf({TY_FUNCTION, TY_PROCEDURE}) && rhsType.hasLambdaCaptures() && !sourceFile->isStdFile)
39
8/16
✓ Branch 42 → 43 taken 1 time.
✗ Branch 42 → 171 not taken.
✓ Branch 43 → 44 taken 1 time.
✗ Branch 43 → 171 not taken.
✓ Branch 44 → 45 taken 1 time.
✗ Branch 44 → 171 not taken.
✓ Branch 45 → 46 taken 1 time.
✗ Branch 45 → 169 not taken.
✓ Branch 46 → 47 taken 1 time.
✗ Branch 46 → 167 not taken.
✓ Branch 47 → 48 taken 1 time.
✗ Branch 47 → 165 not taken.
✓ Branch 51 → 52 taken 1 time.
✗ Branch 51 → 176 not taken.
✓ Branch 52 → 53 taken 1 time.
✗ Branch 52 → 176 not taken.
2 SOFT_ERROR_ER(node->rhs, LAMBDA_CAPTURE_ESCAPE,
40 "A capturing lambda cannot be stored in a field, because its captures live in the frame that "
41 "created it and would dangle. Wrap it in 'Lambda<" +
42 rhsType.getBase().getWithLambdaCaptures(false).getName(false) + ">' from std/type/lambda instead.")
43
44 // Take a look at the operator
45
2/2
✓ Branch 55 → 56 taken 16775 times.
✓ Branch 55 → 98 taken 2250 times.
19025 if (node->op == AssignExprNode::AssignOp::OP_ASSIGN) {
46
8/10
✓ Branch 56 → 57 taken 16774 times.
✓ Branch 56 → 63 taken 1 time.
✓ Branch 57 → 58 taken 16774 times.
✗ Branch 57 → 188 not taken.
✓ Branch 58 → 59 taken 13501 times.
✓ Branch 58 → 63 taken 3273 times.
✓ Branch 60 → 61 taken 13501 times.
✗ Branch 60 → 188 not taken.
✓ Branch 61 → 62 taken 5164 times.
✓ Branch 61 → 63 taken 8337 times.
16775 const bool isDecl = lhs.entry != nullptr && lhs.entry->isField() && !lhs.entry->getLifecycle().isInitialized();
47
2/2
✓ Branch 64 → 65 taken 16774 times.
✓ Branch 64 → 188 taken 1 time.
16775 const auto [assignType, copyCtor] = opRuleManager.getAssignResultType(node, lhs, rhs, isDecl);
48 16774 rhsType = assignType;
49 // If the assignment overwrites an already initialized struct by copying a new value into it, the old value
50 // of the lhs must be destructed first. Otherwise its owning members (heap pointers, strings, ...) would leak.
51 // A non-null copy ctor signals that a real copy (not a move/temporary steal or ref assignment) takes place.
52 // 'isInitialized()' is false for declarations, uninitialized fields and moved-from values, so those are skipped.
53 // Unsafe blocks are excluded on purpose: code that manually manages object lifetimes there (e.g. the raw
54 // element shifts in container implementations) relies on assignments not implicitly destructing the lhs.
55
10/12
✓ Branch 67 → 68 taken 139 times.
✓ Branch 67 → 75 taken 16635 times.
✓ Branch 68 → 69 taken 33 times.
✓ Branch 68 → 75 taken 106 times.
✓ Branch 69 → 70 taken 33 times.
✗ Branch 69 → 75 not taken.
✓ Branch 70 → 71 taken 33 times.
✗ Branch 70 → 188 not taken.
✓ Branch 71 → 72 taken 18 times.
✓ Branch 71 → 75 taken 15 times.
✓ Branch 76 → 77 taken 10 times.
✓ Branch 76 → 97 taken 16764 times.
16792 if (copyCtor != nullptr && !isDecl && lhs.entry != nullptr && lhs.entry->isInitialized() &&
56
3/4
✓ Branch 72 → 73 taken 18 times.
✗ Branch 72 → 188 not taken.
✓ Branch 73 → 74 taken 10 times.
✓ Branch 73 → 75 taken 8 times.
18 !currentScope->doesAllowUnsafeOperations()) {
57
2/4
✓ Branch 77 → 78 taken 10 times.
✗ Branch 77 → 177 not taken.
✓ Branch 78 → 79 taken 10 times.
✗ Branch 78 → 177 not taken.
10 const QualType lhsSType = lhs.type.removeReferenceWrapper().toNonConst();
58
5/10
✓ Branch 79 → 80 taken 10 times.
✗ Branch 79 → 187 not taken.
✓ Branch 80 → 81 taken 10 times.
✗ Branch 80 → 84 not taken.
✓ Branch 81 → 82 taken 10 times.
✗ Branch 81 → 187 not taken.
✓ Branch 82 → 83 taken 10 times.
✗ Branch 82 → 84 not taken.
✓ Branch 85 → 86 taken 10 times.
✗ Branch 85 → 96 not taken.
10 if (lhsSType.is(TY_STRUCT) && !lhsSType.isTriviallyDestructible(node))
59
2/4
✓ Branch 89 → 90 taken 10 times.
✗ Branch 89 → 180 not taken.
✓ Branch 90 → 91 taken 10 times.
✗ Branch 90 → 178 not taken.
30 node->lhsDtorFct[manIdx] = implicitlyCallStructMethod(lhsSType, DTOR_FUNCTION_NAME, {}, node);
60 }
61
2/2
✓ Branch 98 → 99 taken 1147 times.
✓ Branch 98 → 101 taken 1103 times.
2250 } else if (node->op == AssignExprNode::AssignOp::OP_PLUS_EQUAL) {
62
1/2
✓ Branch 99 → 100 taken 1147 times.
✗ Branch 99 → 189 not taken.
1147 rhsType = opRuleManager.getPlusEqualResultType(node, lhs, rhs).type;
63
2/2
✓ Branch 101 → 102 taken 78 times.
✓ Branch 101 → 104 taken 1025 times.
1103 } else if (node->op == AssignExprNode::AssignOp::OP_MINUS_EQUAL) {
64
1/2
✓ Branch 102 → 103 taken 78 times.
✗ Branch 102 → 190 not taken.
78 rhsType = opRuleManager.getMinusEqualResultType(node, lhs, rhs).type;
65
2/2
✓ Branch 104 → 105 taken 161 times.
✓ Branch 104 → 107 taken 864 times.
1025 } else if (node->op == AssignExprNode::AssignOp::OP_MUL_EQUAL) {
66
1/2
✓ Branch 105 → 106 taken 161 times.
✗ Branch 105 → 191 not taken.
161 rhsType = opRuleManager.getMulEqualResultType(node, lhs, rhs).type;
67
2/2
✓ Branch 107 → 108 taken 102 times.
✓ Branch 107 → 110 taken 762 times.
864 } else if (node->op == AssignExprNode::AssignOp::OP_DIV_EQUAL) {
68
1/2
✓ Branch 108 → 109 taken 102 times.
✗ Branch 108 → 192 not taken.
102 rhsType = opRuleManager.getDivEqualResultType(node, lhs, rhs).type;
69
2/2
✓ Branch 110 → 111 taken 41 times.
✓ Branch 110 → 113 taken 721 times.
762 } else if (node->op == AssignExprNode::AssignOp::OP_REM_EQUAL) {
70
1/2
✓ Branch 111 → 112 taken 41 times.
✗ Branch 111 → 193 not taken.
41 rhsType = opRuleManager.getRemEqualResultType(node, lhs, rhs);
71
2/2
✓ Branch 113 → 114 taken 12 times.
✓ Branch 113 → 116 taken 709 times.
721 } else if (node->op == AssignExprNode::AssignOp::OP_SHL_EQUAL) {
72
1/2
✓ Branch 114 → 115 taken 12 times.
✗ Branch 114 → 194 not taken.
12 rhsType = opRuleManager.getSHLEqualResultType(node, lhs, rhs);
73
2/2
✓ Branch 116 → 117 taken 13 times.
✓ Branch 116 → 119 taken 696 times.
709 } else if (node->op == AssignExprNode::AssignOp::OP_SHR_EQUAL) {
74
1/2
✓ Branch 117 → 118 taken 13 times.
✗ Branch 117 → 195 not taken.
13 rhsType = opRuleManager.getSHREqualResultType(node, lhs, rhs);
75
2/2
✓ Branch 119 → 120 taken 17 times.
✓ Branch 119 → 122 taken 679 times.
696 } else if (node->op == AssignExprNode::AssignOp::OP_AND_EQUAL) {
76
1/2
✓ Branch 120 → 121 taken 17 times.
✗ Branch 120 → 196 not taken.
17 rhsType = opRuleManager.getAndEqualResultType(node, lhs, rhs);
77
2/2
✓ Branch 122 → 123 taken 13 times.
✓ Branch 122 → 125 taken 666 times.
679 } else if (node->op == AssignExprNode::AssignOp::OP_OR_EQUAL) {
78
1/2
✓ Branch 123 → 124 taken 13 times.
✗ Branch 123 → 197 not taken.
13 rhsType = opRuleManager.getOrEqualResultType(node, lhs, rhs);
79
1/2
✓ Branch 125 → 126 taken 666 times.
✗ Branch 125 → 128 not taken.
666 } else if (node->op == AssignExprNode::AssignOp::OP_XOR_EQUAL) {
80
1/2
✓ Branch 126 → 127 taken 666 times.
✗ Branch 126 → 198 not taken.
666 rhsType = opRuleManager.getXorEqualResultType(node, lhs, rhs);
81 }
82
83
1/2
✓ Branch 128 → 129 taken 19024 times.
✗ Branch 128 → 137 not taken.
19024 if (lhsVar) { // Variable is involved on the left side
84 // Perform type inference
85
3/4
✓ Branch 129 → 130 taken 19024 times.
✗ Branch 129 → 201 not taken.
✓ Branch 130 → 131 taken 1 time.
✓ Branch 130 → 132 taken 19023 times.
19024 if (lhsType.is(TY_DYN))
86
1/2
✓ Branch 131 → 132 taken 1 time.
✗ Branch 131 → 201 not taken.
1 lhsVar->updateType(rhsType, false);
87
88 // In case the lhs variable is captured, notify the capture about the write access
89
3/4
✓ Branch 132 → 133 taken 19024 times.
✗ Branch 132 → 201 not taken.
✓ Branch 133 → 134 taken 3 times.
✓ Branch 133 → 135 taken 19021 times.
19024 if (Capture *lhsCapture = currentScope->symbolTable.lookupCapture(lhsVar->name); lhsCapture)
90
1/2
✓ Branch 134 → 135 taken 3 times.
✗ Branch 134 → 201 not taken.
3 lhsCapture->setAccessType(READ_WRITE);
91
92 // Update the state of the variable
93
1/2
✓ Branch 135 → 136 taken 19024 times.
✗ Branch 135 → 199 not taken.
19024 lhsVar->updateState(INITIALIZED, node);
94 }
95
96
2/4
✓ Branch 137 → 138 taken 19024 times.
✗ Branch 137 → 200 not taken.
✓ Branch 138 → 139 taken 19024 times.
✗ Branch 138 → 200 not taken.
38048 return ExprResult{node->setEvaluatedSymbolType(rhsType, manIdx)};
97 }
98
99 throw CompilerError(UNHANDLED_BRANCH, "AssignExpr fall-through"); // GCOV_EXCL_LINE
100 }
101
102 1167 std::any TypeChecker::visitTernaryExpr(TernaryExprNode *node) {
103 // Check if there is a ternary operator applied
104
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 1167 times.
1167 if (!node->falseExpr)
105 return visit(node->condition);
106
107 // Visit condition
108
2/4
✓ Branch 5 → 6 taken 1167 times.
✗ Branch 5 → 126 not taken.
✓ Branch 6 → 7 taken 1167 times.
✗ Branch 6 → 124 not taken.
1167 const auto condition = std::any_cast<ExprResult>(visit(node->condition));
109
2/8
✓ Branch 8 → 9 taken 1167 times.
✗ Branch 8 → 161 not taken.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 14 taken 1167 times.
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 127 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 127 not taken.
1167 HANDLE_UNRESOLVED_TYPE_ER(condition.type)
110
6/10
✓ Branch 14 → 15 taken 1 time.
✓ Branch 14 → 16 taken 1166 times.
✓ Branch 16 → 17 taken 1166 times.
✗ Branch 16 → 128 not taken.
✓ Branch 17 → 18 taken 1166 times.
✗ Branch 17 → 128 not taken.
✓ Branch 18 → 19 taken 1166 times.
✓ Branch 18 → 20 taken 1 time.
✗ Branch 128 → 129 not taken.
✗ Branch 128 → 130 not taken.
1167 const auto trueExpr = node->isShortened ? condition : std::any_cast<ExprResult>(visit(node->trueExpr));
111 1167 const auto [trueType, trueEntry] = trueExpr;
112
2/8
✓ Branch 20 → 21 taken 1167 times.
✗ Branch 20 → 161 not taken.
✗ Branch 21 → 22 not taken.
✓ Branch 21 → 26 taken 1167 times.
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 132 not taken.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 132 not taken.
1167 HANDLE_UNRESOLVED_TYPE_ER(trueType)
113
2/4
✓ Branch 26 → 27 taken 1167 times.
✗ Branch 26 → 135 not taken.
✓ Branch 27 → 28 taken 1167 times.
✗ Branch 27 → 133 not taken.
1167 const auto falseExpr = std::any_cast<ExprResult>(visit(node->falseExpr));
114 1167 const auto [falseType, falseEntry] = falseExpr;
115
2/8
✓ Branch 29 → 30 taken 1167 times.
✗ Branch 29 → 161 not taken.
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 35 taken 1167 times.
✗ Branch 31 → 32 not taken.
✗ Branch 31 → 136 not taken.
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 136 not taken.
1167 HANDLE_UNRESOLVED_TYPE_ER(falseType)
116
117 // Check if the condition evaluates to bool
118
3/4
✓ Branch 35 → 36 taken 1167 times.
✗ Branch 35 → 161 not taken.
✓ Branch 36 → 37 taken 1 time.
✓ Branch 36 → 47 taken 1166 times.
1167 if (!condition.type.is(TY_BOOL))
119
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.
4 SOFT_ERROR_ER(node->condition, OPERATOR_WRONG_DATA_TYPE, "Condition operand in ternary must be a bool")
120
121 // Check if trueType and falseType are matching
122
1/2
✓ Branch 47 → 48 taken 1166 times.
✗ Branch 47 → 161 not taken.
1166 const QualType trueTypeModified = trueType.removeReferenceWrapper();
123
1/2
✓ Branch 48 → 49 taken 1166 times.
✗ Branch 48 → 161 not taken.
1166 const QualType falseTypeModified = falseType.removeReferenceWrapper();
124
3/4
✓ Branch 49 → 50 taken 1166 times.
✗ Branch 49 → 161 not taken.
✓ Branch 50 → 51 taken 1 time.
✓ Branch 50 → 66 taken 1165 times.
1166 if (!trueTypeModified.matches(falseTypeModified, false, true, false))
125
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.
2 SOFT_ERROR_ER(node, OPERATOR_WRONG_DATA_TYPE,
126 "True and false operands in ternary must be of same data type. Got " + trueType.getName(true) + " and " +
127 falseType.getName(true))
128
129 // The result type must be a reference if one of true/false branch is of reference type. Otherwise,
130 // the copy ctor is not called correctly
131
3/4
✓ Branch 66 → 67 taken 1165 times.
✗ Branch 66 → 161 not taken.
✓ Branch 67 → 68 taken 9 times.
✓ Branch 67 → 69 taken 1156 times.
1165 QualType resultType = trueType.isRef() ? trueType : falseType;
132 // Infer the const-ness from the more restrictive operand
133
7/10
✓ Branch 70 → 71 taken 1165 times.
✗ Branch 70 → 161 not taken.
✓ Branch 71 → 72 taken 1137 times.
✓ Branch 71 → 74 taken 28 times.
✓ Branch 72 → 73 taken 1137 times.
✗ Branch 72 → 161 not taken.
✓ Branch 73 → 74 taken 341 times.
✓ Branch 73 → 75 taken 796 times.
✓ Branch 76 → 77 taken 1165 times.
✗ Branch 76 → 161 not taken.
1165 resultType.makeConst(trueType.isConst() || falseType.isConst());
134
135 // If there is an anonymous symbol attached to left or right, remove it,
136 // since the result takes over the ownership of any destructible object.
137 1165 bool removedAnonymousSymbols = false;
138
2/2
✓ Branch 77 → 78 taken 332 times.
✓ Branch 77 → 89 taken 833 times.
1165 if (trueEntry) {
139
2/2
✓ Branch 78 → 79 taken 217 times.
✓ Branch 78 → 81 taken 115 times.
332 if (trueEntry->anonymous) {
140
1/2
✓ Branch 79 → 80 taken 217 times.
✗ Branch 79 → 161 not taken.
217 currentScope->symbolTable.deleteAnonymous(trueEntry->name);
141 217 removedAnonymousSymbols = true;
142
8/10
✓ Branch 81 → 82 taken 115 times.
✗ Branch 81 → 161 not taken.
✓ Branch 82 → 83 taken 107 times.
✓ Branch 82 → 86 taken 8 times.
✓ Branch 83 → 84 taken 107 times.
✗ Branch 83 → 161 not taken.
✓ Branch 84 → 85 taken 9 times.
✓ Branch 84 → 86 taken 98 times.
✓ Branch 87 → 88 taken 9 times.
✓ Branch 87 → 89 taken 106 times.
115 } else if (!trueType.isRef() && !trueType.isTriviallyCopyable(node)) {
143 9 node->trueSideCallsCopyCtor = true;
144 }
145 }
146
2/2
✓ Branch 89 → 90 taken 695 times.
✓ Branch 89 → 101 taken 470 times.
1165 if (falseEntry) {
147
2/2
✓ Branch 90 → 91 taken 207 times.
✓ Branch 90 → 93 taken 488 times.
695 if (falseEntry->anonymous) {
148
1/2
✓ Branch 91 → 92 taken 207 times.
✗ Branch 91 → 161 not taken.
207 currentScope->symbolTable.deleteAnonymous(falseEntry->name);
149 207 removedAnonymousSymbols = true;
150
8/10
✓ Branch 93 → 94 taken 488 times.
✗ Branch 93 → 161 not taken.
✓ Branch 94 → 95 taken 472 times.
✓ Branch 94 → 98 taken 16 times.
✓ Branch 95 → 96 taken 472 times.
✗ Branch 95 → 161 not taken.
✓ Branch 96 → 97 taken 20 times.
✓ Branch 96 → 98 taken 452 times.
✓ Branch 99 → 100 taken 20 times.
✓ Branch 99 → 101 taken 468 times.
488 } else if (!falseType.isRef() && !falseType.isTriviallyCopyable(node)) {
151 20 node->falseSideCallsCopyCtor = true;
152 }
153 }
154
155 // Create a new anonymous symbol for the result if required
156 1165 SymbolTableEntry *anonymousSymbol = nullptr;
157
4/4
✓ Branch 101 → 102 taken 1156 times.
✓ Branch 101 → 103 taken 9 times.
✓ Branch 102 → 103 taken 14 times.
✓ Branch 102 → 104 taken 1142 times.
1165 const bool calledCopyCtor = node->trueSideCallsCopyCtor || node->falseSideCallsCopyCtor;
158
9/10
✓ Branch 105 → 106 taken 946 times.
✓ Branch 105 → 109 taken 219 times.
✓ Branch 106 → 107 taken 931 times.
✓ Branch 106 → 109 taken 15 times.
✓ Branch 107 → 108 taken 931 times.
✗ Branch 107 → 161 not taken.
✓ Branch 108 → 109 taken 16 times.
✓ Branch 108 → 110 taken 915 times.
✓ Branch 111 → 112 taken 250 times.
✓ Branch 111 → 114 taken 915 times.
1165 if (removedAnonymousSymbols || calledCopyCtor || resultType.isRef())
159
1/2
✓ Branch 112 → 113 taken 250 times.
✗ Branch 112 → 161 not taken.
250 anonymousSymbol = currentScope->symbolTable.insertAnonymous(resultType, node);
160
161 // Look up the copy ctor if at least one side needs it
162
4/4
✓ Branch 114 → 115 taken 1156 times.
✓ Branch 114 → 116 taken 9 times.
✓ Branch 115 → 116 taken 14 times.
✓ Branch 115 → 118 taken 1142 times.
1165 if (node->trueSideCallsCopyCtor || node->falseSideCallsCopyCtor)
163
1/2
✓ Branch 116 → 117 taken 23 times.
✗ Branch 116 → 161 not taken.
23 node->calledCopyCtor = matchCopyCtor(trueTypeModified, node);
164
165
2/4
✓ Branch 118 → 119 taken 1165 times.
✗ Branch 118 → 160 not taken.
✓ Branch 119 → 120 taken 1165 times.
✗ Branch 119 → 160 not taken.
2330 return ExprResult{node->setEvaluatedSymbolType(resultType, manIdx), anonymousSymbol};
166 }
167
168 1788 std::any TypeChecker::visitLogicalOrExpr(LogicalOrExprNode *node) {
169 // Check if a logical or operator is applied
170
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 1788 times.
1788 if (node->operands.size() == 1)
171 return visit(node->operands.front());
172
173 // Visit leftmost operand
174
2/4
✓ Branch 8 → 9 taken 1788 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 1788 times.
✗ Branch 9 → 37 not taken.
1788 auto currentOperand = std::any_cast<ExprResult>(visit(node->operands[0]));
175
2/8
✓ Branch 11 → 12 taken 1788 times.
✗ Branch 11 → 46 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 1788 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 40 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 40 not taken.
1788 HANDLE_UNRESOLVED_TYPE_ER(currentOperand.type)
176
177 // Loop through all remaining operands
178
2/2
✓ Branch 31 → 18 taken 2372 times.
✓ Branch 31 → 32 taken 1787 times.
4159 for (size_t i = 1; i < node->operands.size(); i++) {
179
2/4
✓ Branch 19 → 20 taken 2372 times.
✗ Branch 19 → 43 not taken.
✓ Branch 20 → 21 taken 2372 times.
✗ Branch 20 → 41 not taken.
2372 auto rhsOperand = std::any_cast<ExprResult>(visit(node->operands[i]));
180
2/8
✓ Branch 22 → 23 taken 2372 times.
✗ Branch 22 → 45 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 2372 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 44 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 44 not taken.
2372 HANDLE_UNRESOLVED_TYPE_ER(rhsOperand.type)
181
2/2
✓ Branch 28 → 29 taken 2371 times.
✓ Branch 28 → 45 taken 1 time.
2372 currentOperand = {OpRuleManager::getLogicalOrResultType(node, currentOperand, rhsOperand)};
182 }
183
184
1/2
✓ Branch 32 → 33 taken 1787 times.
✗ Branch 32 → 46 not taken.
1787 node->setEvaluatedSymbolType(currentOperand.type, manIdx);
185
1/2
✓ Branch 33 → 34 taken 1787 times.
✗ Branch 33 → 46 not taken.
1787 return currentOperand;
186 }
187
188 1083 std::any TypeChecker::visitLogicalAndExpr(LogicalAndExprNode *node) {
189 // Check if a logical and operator is applied
190
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 1083 times.
1083 if (node->operands.size() == 1)
191 return visit(node->operands.front());
192
193 // Visit leftmost operand
194
2/4
✓ Branch 8 → 9 taken 1083 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 1083 times.
✗ Branch 9 → 37 not taken.
1083 auto currentOperand = std::any_cast<ExprResult>(visit(node->operands[0]));
195
2/8
✓ Branch 11 → 12 taken 1083 times.
✗ Branch 11 → 46 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 1083 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 40 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 40 not taken.
1083 HANDLE_UNRESOLVED_TYPE_ER(currentOperand.type)
196
197 // Loop through all remaining operands
198
2/2
✓ Branch 31 → 18 taken 1499 times.
✓ Branch 31 → 32 taken 1083 times.
2582 for (size_t i = 1; i < node->operands.size(); i++) {
199
2/4
✓ Branch 19 → 20 taken 1499 times.
✗ Branch 19 → 43 not taken.
✓ Branch 20 → 21 taken 1499 times.
✗ Branch 20 → 41 not taken.
1499 auto rhsOperand = std::any_cast<ExprResult>(visit(node->operands[i]));
200
2/8
✓ Branch 22 → 23 taken 1499 times.
✗ Branch 22 → 45 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 1499 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 44 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 44 not taken.
1499 HANDLE_UNRESOLVED_TYPE_ER(rhsOperand.type)
201
1/2
✓ Branch 28 → 29 taken 1499 times.
✗ Branch 28 → 45 not taken.
1499 currentOperand = {OpRuleManager::getLogicalAndResultType(node, currentOperand, rhsOperand)};
202 }
203
204
1/2
✓ Branch 32 → 33 taken 1083 times.
✗ Branch 32 → 46 not taken.
1083 node->setEvaluatedSymbolType(currentOperand.type, manIdx);
205
1/2
✓ Branch 33 → 34 taken 1083 times.
✗ Branch 33 → 46 not taken.
1083 return currentOperand;
206 }
207
208 275 std::any TypeChecker::visitBitwiseOrExpr(BitwiseOrExprNode *node) {
209 // Check if a bitwise or operator is applied
210
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 275 times.
275 if (node->operands.size() == 1)
211 return visit(node->operands.front());
212
213 // Visit leftmost operand
214
2/4
✓ Branch 8 → 9 taken 275 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 275 times.
✗ Branch 9 → 37 not taken.
275 auto currentOperand = std::any_cast<ExprResult>(visit(node->operands[0]));
215
2/8
✓ Branch 11 → 12 taken 275 times.
✗ Branch 11 → 46 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 275 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 40 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 40 not taken.
275 HANDLE_UNRESOLVED_TYPE_ER(currentOperand.type)
216
217 // Loop through all remaining operands
218
2/2
✓ Branch 31 → 18 taken 278 times.
✓ Branch 31 → 32 taken 274 times.
552 for (size_t i = 1; i < node->operands.size(); i++) {
219
2/4
✓ Branch 19 → 20 taken 278 times.
✗ Branch 19 → 43 not taken.
✓ Branch 20 → 21 taken 278 times.
✗ Branch 20 → 41 not taken.
278 auto rhsOperand = std::any_cast<ExprResult>(visit(node->operands[i]));
220
2/8
✓ Branch 22 → 23 taken 278 times.
✗ Branch 22 → 45 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 278 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 44 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 44 not taken.
278 HANDLE_UNRESOLVED_TYPE_ER(rhsOperand.type)
221
2/2
✓ Branch 28 → 29 taken 277 times.
✓ Branch 28 → 45 taken 1 time.
278 currentOperand = opRuleManager.getBitwiseOrResultType(node, currentOperand, rhsOperand, i - 1);
222 }
223
224
1/2
✓ Branch 32 → 33 taken 274 times.
✗ Branch 32 → 46 not taken.
274 node->setEvaluatedSymbolType(currentOperand.type, manIdx);
225
1/2
✓ Branch 33 → 34 taken 274 times.
✗ Branch 33 → 46 not taken.
274 return currentOperand;
226 }
227
228 38 std::any TypeChecker::visitBitwiseXorExpr(BitwiseXorExprNode *node) {
229 // Check if a bitwise xor operator is applied
230
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 38 times.
38 if (node->operands.size() == 1)
231 return visit(node->operands.front());
232
233 // Visit leftmost operand
234
2/4
✓ Branch 8 → 9 taken 38 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 38 times.
✗ Branch 9 → 37 not taken.
38 auto currentOperand = std::any_cast<ExprResult>(visit(node->operands[0]));
235
2/8
✓ Branch 11 → 12 taken 38 times.
✗ Branch 11 → 46 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 38 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 40 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 40 not taken.
38 HANDLE_UNRESOLVED_TYPE_ER(currentOperand.type)
236
237 // Loop through all remaining operands
238
2/2
✓ Branch 31 → 18 taken 41 times.
✓ Branch 31 → 32 taken 38 times.
79 for (size_t i = 1; i < node->operands.size(); i++) {
239
2/4
✓ Branch 19 → 20 taken 41 times.
✗ Branch 19 → 43 not taken.
✓ Branch 20 → 21 taken 41 times.
✗ Branch 20 → 41 not taken.
41 auto rhsOperand = std::any_cast<ExprResult>(visit(node->operands[i]));
240
2/8
✓ Branch 22 → 23 taken 41 times.
✗ Branch 22 → 45 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 41 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 44 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 44 not taken.
41 HANDLE_UNRESOLVED_TYPE_ER(rhsOperand.type)
241
1/2
✓ Branch 28 → 29 taken 41 times.
✗ Branch 28 → 45 not taken.
41 currentOperand = opRuleManager.getBitwiseXorResultType(node, currentOperand, rhsOperand, i - 1);
242 }
243
244
1/2
✓ Branch 32 → 33 taken 38 times.
✗ Branch 32 → 46 not taken.
38 node->setEvaluatedSymbolType(currentOperand.type, manIdx);
245
1/2
✓ Branch 33 → 34 taken 38 times.
✗ Branch 33 → 46 not taken.
38 return currentOperand;
246 }
247
248 69 std::any TypeChecker::visitBitwiseAndExpr(BitwiseAndExprNode *node) {
249 // Check if a bitwise and operator is applied
250
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 69 times.
69 if (node->operands.size() == 1)
251 return visit(node->operands.front());
252
253 // Visit leftmost operand
254
2/4
✓ Branch 8 → 9 taken 69 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 69 times.
✗ Branch 9 → 37 not taken.
69 auto currentOperand = std::any_cast<ExprResult>(visit(node->operands[0]));
255
2/8
✓ Branch 11 → 12 taken 69 times.
✗ Branch 11 → 46 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 69 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 40 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 40 not taken.
69 HANDLE_UNRESOLVED_TYPE_ER(currentOperand.type)
256
257 // Loop through all remaining operands
258
2/2
✓ Branch 31 → 18 taken 72 times.
✓ Branch 31 → 32 taken 69 times.
141 for (size_t i = 1; i < node->operands.size(); i++) {
259
2/4
✓ Branch 19 → 20 taken 72 times.
✗ Branch 19 → 43 not taken.
✓ Branch 20 → 21 taken 72 times.
✗ Branch 20 → 41 not taken.
72 auto rhsOperand = std::any_cast<ExprResult>(visit(node->operands[i]));
260
2/8
✓ Branch 22 → 23 taken 72 times.
✗ Branch 22 → 45 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 72 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 44 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 44 not taken.
72 HANDLE_UNRESOLVED_TYPE_ER(rhsOperand.type)
261
1/2
✓ Branch 28 → 29 taken 72 times.
✗ Branch 28 → 45 not taken.
72 currentOperand = opRuleManager.getBitwiseAndResultType(node, currentOperand, rhsOperand, i - 1);
262 }
263
264
1/2
✓ Branch 32 → 33 taken 69 times.
✗ Branch 32 → 46 not taken.
69 node->setEvaluatedSymbolType(currentOperand.type, manIdx);
265
1/2
✓ Branch 33 → 34 taken 69 times.
✗ Branch 33 → 46 not taken.
69 return currentOperand;
266 }
267
268 13566 std::any TypeChecker::visitEqualityExpr(EqualityExprNode *node) {
269 // Check if at least one equality operator is applied
270
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 13566 times.
13566 if (node->operands.size() == 1)
271 return visit(node->operands.front());
272
273 // Visit right side first, then left side
274
2/4
✓ Branch 8 → 9 taken 13566 times.
✗ Branch 8 → 58 not taken.
✓ Branch 9 → 10 taken 13566 times.
✗ Branch 9 → 56 not taken.
13566 const auto rhs = std::any_cast<ExprResult>(visit(node->operands[1]));
275
2/8
✓ Branch 11 → 12 taken 13566 times.
✗ Branch 11 → 73 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 13566 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 59 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 59 not taken.
13566 HANDLE_UNRESOLVED_TYPE_ER(rhs.type)
276
2/4
✓ Branch 18 → 19 taken 13566 times.
✗ Branch 18 → 62 not taken.
✓ Branch 19 → 20 taken 13566 times.
✗ Branch 19 → 60 not taken.
13566 const auto lhs = std::any_cast<ExprResult>(visit(node->operands[0]));
277
2/8
✓ Branch 21 → 22 taken 13566 times.
✗ Branch 21 → 73 not taken.
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 27 taken 13566 times.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 63 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 63 not taken.
13566 HANDLE_UNRESOLVED_TYPE_ER(lhs.type)
278
279 // Check if we need the string runtime to perform a string comparison
280
10/14
✓ Branch 27 → 28 taken 13566 times.
✗ Branch 27 → 73 not taken.
✓ Branch 28 → 29 taken 334 times.
✓ Branch 28 → 36 taken 13232 times.
✓ Branch 29 → 30 taken 334 times.
✗ Branch 29 → 73 not taken.
✓ Branch 30 → 31 taken 333 times.
✓ Branch 30 → 36 taken 1 time.
✓ Branch 31 → 32 taken 333 times.
✗ Branch 31 → 73 not taken.
✓ Branch 34 → 35 taken 333 times.
✗ Branch 34 → 36 not taken.
✓ Branch 37 → 38 taken 333 times.
✓ Branch 37 → 39 taken 13233 times.
13899 if (lhs.type.is(TY_STRING) && rhs.type.is(TY_STRING) && !sourceFile->isStringRT())
281
1/2
✓ Branch 38 → 39 taken 333 times.
✗ Branch 38 → 73 not taken.
333 sourceFile->requestRuntimeModule(STRING_RT);
282
283 // Check operator
284 13566 ExprResult result;
285
2/2
✓ Branch 39 → 40 taken 10274 times.
✓ Branch 39 → 41 taken 3292 times.
13566 if (node->op == EqualityExprNode::EqualityOp::OP_EQUAL) // Operator was equal
286
2/2
✓ Branch 40 → 51 taken 10273 times.
✓ Branch 40 → 73 taken 1 time.
10274 result = opRuleManager.getEqualResultType(node, lhs, rhs);
287
1/2
✓ Branch 41 → 42 taken 3292 times.
✗ Branch 41 → 43 not taken.
3292 else if (node->op == EqualityExprNode::EqualityOp::OP_NOT_EQUAL) // Operator was not equal
288
1/2
✓ Branch 42 → 51 taken 3292 times.
✗ Branch 42 → 73 not taken.
3292 result = opRuleManager.getNotEqualResultType(node, lhs, rhs);
289 else
290 throw CompilerError(UNHANDLED_BRANCH, "EqualityExpr fall-through"); // GCOV_EXCL_LINE
291
292
1/2
✓ Branch 51 → 52 taken 13565 times.
✗ Branch 51 → 73 not taken.
13565 node->setEvaluatedSymbolType(result.type, manIdx);
293
1/2
✓ Branch 52 → 53 taken 13565 times.
✗ Branch 52 → 73 not taken.
13565 return result;
294 }
295
296 8913 std::any TypeChecker::visitRelationalExpr(RelationalExprNode *node) {
297 // Check if a relational operator is applied
298
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 8913 times.
8913 if (node->operands.size() == 1)
299 return visit(node->operands.front());
300
301 // Visit right side first, then left side
302
2/4
✓ Branch 8 → 9 taken 8913 times.
✗ Branch 8 → 55 not taken.
✓ Branch 9 → 10 taken 8913 times.
✗ Branch 9 → 53 not taken.
8913 const auto rhs = std::any_cast<ExprResult>(visit(node->operands[1]));
303
5/8
✓ Branch 11 → 12 taken 8913 times.
✗ Branch 11 → 75 not taken.
✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 17 taken 8912 times.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 56 not taken.
✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 56 not taken.
8914 HANDLE_UNRESOLVED_TYPE_ER(rhs.type)
304
2/4
✓ Branch 18 → 19 taken 8912 times.
✗ Branch 18 → 59 not taken.
✓ Branch 19 → 20 taken 8912 times.
✗ Branch 19 → 57 not taken.
8912 const auto lhs = std::any_cast<ExprResult>(visit(node->operands[0]));
305
2/8
✓ Branch 21 → 22 taken 8912 times.
✗ Branch 21 → 75 not taken.
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 27 taken 8912 times.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 60 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 60 not taken.
8912 HANDLE_UNRESOLVED_TYPE_ER(lhs.type)
306
307 // Check operator
308 8912 QualType resultType;
309
2/2
✓ Branch 27 → 28 taken 4128 times.
✓ Branch 27 → 30 taken 4784 times.
8912 if (node->op == RelationalExprNode::RelationalOp::OP_LESS) // Operator was less
310
1/2
✓ Branch 28 → 29 taken 4128 times.
✗ Branch 28 → 61 not taken.
4128 resultType = OpRuleManager::getLessResultType(node, lhs, rhs);
311
2/2
✓ Branch 30 → 31 taken 1658 times.
✓ Branch 30 → 33 taken 3126 times.
4784 else if (node->op == RelationalExprNode::RelationalOp::OP_GREATER) // Operator was greater
312
2/2
✓ Branch 31 → 32 taken 1657 times.
✓ Branch 31 → 62 taken 1 time.
1658 resultType = OpRuleManager::getGreaterResultType(node, lhs, rhs);
313
2/2
✓ Branch 33 → 34 taken 1178 times.
✓ Branch 33 → 36 taken 1948 times.
3126 else if (node->op == RelationalExprNode::RelationalOp::OP_LESS_EQUAL) // Operator was less equal
314
1/2
✓ Branch 34 → 35 taken 1178 times.
✗ Branch 34 → 63 not taken.
1178 resultType = OpRuleManager::getLessEqualResultType(node, lhs, rhs);
315
1/2
✓ Branch 36 → 37 taken 1948 times.
✗ Branch 36 → 39 not taken.
1948 else if (node->op == RelationalExprNode::RelationalOp::OP_GREATER_EQUAL) // Operator was greater equal
316
1/2
✓ Branch 37 → 38 taken 1948 times.
✗ Branch 37 → 64 not taken.
1948 resultType = OpRuleManager::getGreaterEqualResultType(node, lhs, rhs);
317 else
318 throw CompilerError(UNHANDLED_BRANCH, "RelationalExpr fall-through"); // GCOV_EXCL_LINE
319
320
2/4
✓ Branch 47 → 48 taken 8911 times.
✗ Branch 47 → 74 not taken.
✓ Branch 48 → 49 taken 8911 times.
✗ Branch 48 → 74 not taken.
17822 return ExprResult{node->setEvaluatedSymbolType(resultType, manIdx)};
321 }
322
323 1301 std::any TypeChecker::visitShiftExpr(ShiftExprNode *node) {
324 // Check if at least one shift operator is applied
325
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 1301 times.
1301 if (node->operands.size() == 1)
326 return visit(node->operands.front());
327
328 // Visit leftmost operand
329
2/4
✓ Branch 8 → 9 taken 1301 times.
✗ Branch 8 → 53 not taken.
✓ Branch 9 → 10 taken 1301 times.
✗ Branch 9 → 51 not taken.
1301 auto currentResult = std::any_cast<ExprResult>(visit(node->operands[0]));
330
2/8
✓ Branch 11 → 12 taken 1301 times.
✗ Branch 11 → 69 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 1301 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 54 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 54 not taken.
1301 HANDLE_UNRESOLVED_TYPE_ER(currentResult.type)
331
332 // Loop through remaining operands
333
2/2
✓ Branch 45 → 18 taken 1590 times.
✓ Branch 45 → 46 taken 1301 times.
2891 for (size_t i = 0; i < node->opQueue.size(); i++) {
334
2/4
✓ Branch 19 → 20 taken 1590 times.
✗ Branch 19 → 57 not taken.
✓ Branch 20 → 21 taken 1590 times.
✗ Branch 20 → 55 not taken.
1590 auto operandResult = std::any_cast<ExprResult>(visit(node->operands[i + 1]));
335
2/8
✓ Branch 22 → 23 taken 1590 times.
✗ Branch 22 → 68 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 1590 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 58 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 58 not taken.
1590 HANDLE_UNRESOLVED_TYPE_ER(operandResult.type)
336
337 // Check operator
338
1/2
✓ Branch 28 → 29 taken 1590 times.
✗ Branch 28 → 68 not taken.
1590 const ShiftExprNode::ShiftOp &op = node->opQueue.front().first;
339
2/2
✓ Branch 29 → 30 taken 1404 times.
✓ Branch 29 → 31 taken 186 times.
1590 if (op == ShiftExprNode::ShiftOp::OP_SHIFT_LEFT)
340
1/2
✓ Branch 30 → 41 taken 1404 times.
✗ Branch 30 → 68 not taken.
1404 currentResult = opRuleManager.getShiftLeftResultType(node, currentResult, operandResult, i);
341
1/2
✓ Branch 31 → 32 taken 186 times.
✗ Branch 31 → 33 not taken.
186 else if (op == ShiftExprNode::ShiftOp::OP_SHIFT_RIGHT)
342
1/2
✓ Branch 32 → 41 taken 186 times.
✗ Branch 32 → 68 not taken.
186 currentResult = opRuleManager.getShiftRightResultType(node, currentResult, operandResult, i);
343 else
344 throw CompilerError(UNHANDLED_BRANCH, "ShiftExpr fall-through"); // GCOV_EXCL_LINE
345
346 // Push the new item and pop the old one on the other side of the queue
347
1/2
✓ Branch 41 → 42 taken 1590 times.
✗ Branch 41 → 68 not taken.
1590 node->opQueue.emplace(op, currentResult.type);
348
1/2
✓ Branch 42 → 43 taken 1590 times.
✗ Branch 42 → 68 not taken.
1590 node->opQueue.pop();
349 }
350
351
1/2
✓ Branch 46 → 47 taken 1301 times.
✗ Branch 46 → 69 not taken.
1301 node->setEvaluatedSymbolType(currentResult.type, manIdx);
352
1/2
✓ Branch 47 → 48 taken 1301 times.
✗ Branch 47 → 69 not taken.
1301 return currentResult;
353 }
354
355 8772 std::any TypeChecker::visitAdditiveExpr(AdditiveExprNode *node) {
356 // Check if at least one additive operator is applied
357
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 8772 times.
8772 if (node->operands.size() == 1)
358 return visit(node->operands.front());
359
360 // Visit leftmost operand
361
2/4
✓ Branch 8 → 9 taken 8772 times.
✗ Branch 8 → 53 not taken.
✓ Branch 9 → 10 taken 8772 times.
✗ Branch 9 → 51 not taken.
8772 auto currentResult = std::any_cast<ExprResult>(visit(node->operands[0]));
362
2/8
✓ Branch 11 → 12 taken 8772 times.
✗ Branch 11 → 69 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 8772 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 54 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 54 not taken.
8772 HANDLE_UNRESOLVED_TYPE_ER(currentResult.type)
363
364 // Loop through remaining operands
365
2/2
✓ Branch 45 → 18 taken 9980 times.
✓ Branch 45 → 46 taken 8771 times.
18751 for (size_t i = 0; i < node->opQueue.size(); i++) {
366
2/4
✓ Branch 19 → 20 taken 9980 times.
✗ Branch 19 → 57 not taken.
✓ Branch 20 → 21 taken 9980 times.
✗ Branch 20 → 55 not taken.
9980 auto operandResult = std::any_cast<ExprResult>(visit(node->operands[i + 1]));
367
2/8
✓ Branch 22 → 23 taken 9980 times.
✗ Branch 22 → 68 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 9980 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 58 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 58 not taken.
9980 HANDLE_UNRESOLVED_TYPE_ER(operandResult.type)
368
369 // Check operator
370
1/2
✓ Branch 28 → 29 taken 9980 times.
✗ Branch 28 → 68 not taken.
9980 const AdditiveExprNode::AdditiveOp &op = node->opQueue.front().first;
371
2/2
✓ Branch 29 → 30 taken 6286 times.
✓ Branch 29 → 31 taken 3694 times.
9980 if (op == AdditiveExprNode::AdditiveOp::OP_PLUS)
372
2/2
✓ Branch 30 → 41 taken 6285 times.
✓ Branch 30 → 68 taken 1 time.
6286 currentResult = opRuleManager.getPlusResultType(node, currentResult, operandResult, i);
373
1/2
✓ Branch 31 → 32 taken 3694 times.
✗ Branch 31 → 33 not taken.
3694 else if (op == AdditiveExprNode::AdditiveOp::OP_MINUS)
374
1/2
✓ Branch 32 → 41 taken 3694 times.
✗ Branch 32 → 68 not taken.
3694 currentResult = opRuleManager.getMinusResultType(node, currentResult, operandResult, i);
375 else
376 throw CompilerError(UNHANDLED_BRANCH, "AdditiveExpr fall-through"); // GCOV_EXCL_LINE
377
378 // Push the new item and pop the old one on the other side of the queue
379
1/2
✓ Branch 41 → 42 taken 9979 times.
✗ Branch 41 → 68 not taken.
9979 node->opQueue.emplace(op, currentResult.type);
380
1/2
✓ Branch 42 → 43 taken 9979 times.
✗ Branch 42 → 68 not taken.
9979 node->opQueue.pop();
381 }
382
383
1/2
✓ Branch 46 → 47 taken 8771 times.
✗ Branch 46 → 69 not taken.
8771 node->setEvaluatedSymbolType(currentResult.type, manIdx);
384
1/2
✓ Branch 47 → 48 taken 8771 times.
✗ Branch 47 → 69 not taken.
8771 return currentResult;
385 }
386
387 2891 std::any TypeChecker::visitMultiplicativeExpr(MultiplicativeExprNode *node) {
388 // Check if at least one multiplicative operator is applied
389
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 2891 times.
2891 if (node->operands.size() == 1)
390 return visit(node->operands.front());
391
392 // Visit leftmost operand
393
2/4
✓ Branch 8 → 9 taken 2891 times.
✗ Branch 8 → 55 not taken.
✓ Branch 9 → 10 taken 2891 times.
✗ Branch 9 → 53 not taken.
2891 auto currentResult = std::any_cast<ExprResult>(visit(node->operands[0]));
394
2/8
✓ Branch 11 → 12 taken 2891 times.
✗ Branch 11 → 71 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 2891 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 56 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 56 not taken.
2891 HANDLE_UNRESOLVED_TYPE_ER(currentResult.type)
395 // Loop through remaining operands
396
2/2
✓ Branch 47 → 18 taken 2941 times.
✓ Branch 47 → 48 taken 2890 times.
5831 for (size_t i = 0; i < node->opQueue.size(); i++) {
397
2/4
✓ Branch 19 → 20 taken 2941 times.
✗ Branch 19 → 59 not taken.
✓ Branch 20 → 21 taken 2941 times.
✗ Branch 20 → 57 not taken.
2941 auto operandResult = std::any_cast<ExprResult>(visit(node->operands[i + 1]));
398
2/8
✓ Branch 22 → 23 taken 2941 times.
✗ Branch 22 → 70 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 2941 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 60 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 60 not taken.
2941 HANDLE_UNRESOLVED_TYPE_ER(operandResult.type)
399
400 // Check operator
401
1/2
✓ Branch 28 → 29 taken 2941 times.
✗ Branch 28 → 70 not taken.
2941 const MultiplicativeExprNode::MultiplicativeOp &op = node->opQueue.front().first;
402
2/2
✓ Branch 29 → 30 taken 2335 times.
✓ Branch 29 → 31 taken 606 times.
2941 if (op == MultiplicativeExprNode::MultiplicativeOp::OP_MUL)
403
2/2
✓ Branch 30 → 43 taken 2334 times.
✓ Branch 30 → 70 taken 1 time.
2335 currentResult = opRuleManager.getMulResultType(node, currentResult, operandResult, i);
404
2/2
✓ Branch 31 → 32 taken 482 times.
✓ Branch 31 → 33 taken 124 times.
606 else if (op == MultiplicativeExprNode::MultiplicativeOp::OP_DIV)
405
1/2
✓ Branch 32 → 43 taken 482 times.
✗ Branch 32 → 70 not taken.
482 currentResult = opRuleManager.getDivResultType(node, currentResult, operandResult, i);
406
1/2
✓ Branch 33 → 34 taken 124 times.
✗ Branch 33 → 35 not taken.
124 else if (op == MultiplicativeExprNode::MultiplicativeOp::OP_REM)
407
1/2
✓ Branch 34 → 43 taken 124 times.
✗ Branch 34 → 70 not taken.
124 currentResult = OpRuleManager::getRemResultType(node, currentResult, operandResult);
408 else
409 throw CompilerError(UNHANDLED_BRANCH, "Multiplicative fall-through"); // GCOV_EXCL_LINE
410
411 // Push the new item and pop the old one on the other side of the queue
412
1/2
✓ Branch 43 → 44 taken 2940 times.
✗ Branch 43 → 70 not taken.
2940 node->opQueue.emplace(op, currentResult.type);
413
1/2
✓ Branch 44 → 45 taken 2940 times.
✗ Branch 44 → 70 not taken.
2940 node->opQueue.pop();
414 }
415
416
1/2
✓ Branch 48 → 49 taken 2890 times.
✗ Branch 48 → 71 not taken.
2890 node->setEvaluatedSymbolType(currentResult.type, manIdx);
417
1/2
✓ Branch 49 → 50 taken 2890 times.
✗ Branch 49 → 71 not taken.
2890 return currentResult;
418 }
419
420 7255 std::any TypeChecker::visitCastExpr(CastExprNode *node) {
421 // Check if cast is applied
422
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 7255 times.
7255 if (!node->isCast)
423 return visit(node->prefixUnaryExpr);
424
425 // Visit destination type
426
2/4
✓ Branch 5 → 6 taken 7255 times.
✗ Branch 5 → 49 not taken.
✓ Branch 6 → 7 taken 7255 times.
✗ Branch 6 → 47 not taken.
7255 const auto dstType = std::any_cast<QualType>(visit(node->dataType));
427
2/8
✓ Branch 8 → 9 taken 7255 times.
✗ Branch 8 → 65 not taken.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 14 taken 7255 times.
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 50 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 50 not taken.
7255 HANDLE_UNRESOLVED_TYPE_ER(dstType)
428 // Visit source type
429
2/4
✓ Branch 14 → 15 taken 7255 times.
✗ Branch 14 → 53 not taken.
✓ Branch 15 → 16 taken 7255 times.
✗ Branch 15 → 51 not taken.
7255 const auto src = std::any_cast<ExprResult>(visit(node->assignExpr));
430
2/8
✓ Branch 17 → 18 taken 7255 times.
✗ Branch 17 → 65 not taken.
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 23 taken 7255 times.
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 54 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 54 not taken.
7255 HANDLE_UNRESOLVED_TYPE_ER(src.type)
431
432 // Check for identity cast
433
3/4
✓ Branch 23 → 24 taken 7255 times.
✗ Branch 23 → 65 not taken.
✓ Branch 24 → 25 taken 803 times.
✓ Branch 24 → 34 taken 6452 times.
7255 if (src.type == dstType) {
434
2/4
✓ Branch 27 → 28 taken 803 times.
✗ Branch 27 → 57 not taken.
✓ Branch 28 → 29 taken 803 times.
✗ Branch 28 → 55 not taken.
1606 const CompilerWarning warning(node->codeLoc, IDENTITY_CAST, "You cast from a type to itself. Thus, this can be simplified.");
435
1/2
✓ Branch 31 → 32 taken 803 times.
✗ Branch 31 → 61 not taken.
803 sourceFile->compilerOutput.warnings.push_back(warning);
436 803 }
437
438 // Get result type
439
1/2
✓ Branch 34 → 35 taken 7255 times.
✗ Branch 34 → 65 not taken.
7255 const QualType resultType = opRuleManager.getCastResultType(node, dstType, src);
440
441
1/2
✓ Branch 35 → 36 taken 7255 times.
✗ Branch 35 → 65 not taken.
7255 const bool typesMatch = dstType.matches(src.type, false, true, true);
442
1/2
✓ Branch 36 → 37 taken 7255 times.
✗ Branch 36 → 65 not taken.
7255 const bool sameContainerType = src.type.isSameContainerTypeAs(dstType);
443
4/4
✓ Branch 37 → 38 taken 6452 times.
✓ Branch 37 → 39 taken 803 times.
✓ Branch 38 → 39 taken 1172 times.
✓ Branch 38 → 40 taken 5280 times.
7255 SymbolTableEntry *entry = typesMatch || sameContainerType ? src.entry : nullptr;
444
2/4
✓ Branch 41 → 42 taken 7255 times.
✗ Branch 41 → 64 not taken.
✓ Branch 42 → 43 taken 7255 times.
✗ Branch 42 → 64 not taken.
14510 return ExprResult{node->setEvaluatedSymbolType(resultType, manIdx), entry};
445 }
446
447 6176 std::any TypeChecker::visitPrefixUnaryExpr(PrefixUnaryExprNode *node) {
448 // If no operator is applied, simply visit the postfix unary expression
449
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 6176 times.
6176 if (node->op == PrefixUnaryExprNode::PrefixUnaryOp::OP_NONE)
450 return visit(node->postfixUnaryExpr);
451
452 // Visit the right side
453 6176 ExprNode *rhsNode = node->prefixUnaryExpr;
454
2/4
✓ Branch 5 → 6 taken 6176 times.
✗ Branch 5 → 58 not taken.
✓ Branch 6 → 7 taken 6176 times.
✗ Branch 6 → 56 not taken.
6176 auto operand = std::any_cast<ExprResult>(visit(rhsNode));
455 6176 auto [operandType, operandEntry] = operand;
456
5/8
✓ Branch 8 → 9 taken 6176 times.
✗ Branch 8 → 79 not taken.
✓ Branch 9 → 10 taken 1 time.
✓ Branch 9 → 14 taken 6175 times.
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 59 not taken.
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 59 not taken.
6177 HANDLE_UNRESOLVED_TYPE_ER(operandType)
457 // Determine action, based on the given operator
458
7/8
✓ Branch 14 → 15 taken 991 times.
✓ Branch 14 → 17 taken 88 times.
✓ Branch 14 → 25 taken 22 times.
✓ Branch 14 → 33 taken 3430 times.
✓ Branch 14 → 35 taken 12 times.
✓ Branch 14 → 38 taken 900 times.
✓ Branch 14 → 40 taken 732 times.
✗ Branch 14 → 42 not taken.
6175 switch (node->op) {
459 991 case PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS:
460
1/2
✓ Branch 15 → 16 taken 991 times.
✗ Branch 15 → 60 not taken.
991 operandType = OpRuleManager::getPrefixMinusResultType(node, operand);
461 991 break;
462 88 case PrefixUnaryExprNode::PrefixUnaryOp::OP_PLUS_PLUS:
463
1/2
✓ Branch 17 → 18 taken 88 times.
✗ Branch 17 → 61 not taken.
88 operandType = opRuleManager.getPrefixPlusPlusResultType(node, operand);
464
465
2/2
✓ Branch 18 → 19 taken 85 times.
✓ Branch 18 → 24 taken 3 times.
88 if (operandEntry) {
466 // In case the lhs is captured, notify the capture about the write access
467
2/4
✓ Branch 19 → 20 taken 85 times.
✗ Branch 19 → 79 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 85 times.
85 if (Capture *lhsCapture = currentScope->symbolTable.lookupCapture(operandEntry->name); lhsCapture)
468 lhsCapture->setAccessType(READ_WRITE);
469
470 // Update the state of the variable
471
1/2
✓ Branch 22 → 23 taken 85 times.
✗ Branch 22 → 62 not taken.
85 operandEntry->updateState(INITIALIZED, node);
472 }
473
474 88 break;
475 22 case PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS_MINUS:
476
2/2
✓ Branch 25 → 26 taken 21 times.
✓ Branch 25 → 63 taken 1 time.
22 operandType = opRuleManager.getPrefixMinusMinusResultType(node, operand);
477
478
2/2
✓ Branch 26 → 27 taken 18 times.
✓ Branch 26 → 32 taken 3 times.
21 if (operandEntry) {
479 // In case the lhs is captured, notify the capture about the write access
480
2/4
✓ Branch 27 → 28 taken 18 times.
✗ Branch 27 → 79 not taken.
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 18 times.
18 if (Capture *lhsCapture = currentScope->symbolTable.lookupCapture(operandEntry->name); lhsCapture)
481 lhsCapture->setAccessType(READ_WRITE);
482
483 // Update the state of the variable
484
1/2
✓ Branch 30 → 31 taken 18 times.
✗ Branch 30 → 64 not taken.
18 operandEntry->updateState(INITIALIZED, node);
485 }
486
487 21 break;
488 3430 case PrefixUnaryExprNode::PrefixUnaryOp::OP_NOT:
489
1/2
✓ Branch 33 → 34 taken 3430 times.
✗ Branch 33 → 65 not taken.
3430 operandType = OpRuleManager::getPrefixNotResultType(node, operand);
490 3430 break;
491 12 case PrefixUnaryExprNode::PrefixUnaryOp::OP_BITWISE_NOT: {
492
1/2
✓ Branch 35 → 36 taken 12 times.
✗ Branch 35 → 66 not taken.
12 const ExprResult result = opRuleManager.getPrefixBitwiseNotResultType(node, operand);
493 12 operandType = result.type;
494 12 operandEntry = result.entry;
495 12 break;
496 }
497 900 case PrefixUnaryExprNode::PrefixUnaryOp::OP_DEREFERENCE:
498
2/2
✓ Branch 38 → 39 taken 899 times.
✓ Branch 38 → 67 taken 1 time.
900 operandType = OpRuleManager::getPrefixMulResultType(node, operand);
499 899 break;
500 732 case PrefixUnaryExprNode::PrefixUnaryOp::OP_ADDRESS_OF:
501
1/2
✓ Branch 40 → 41 taken 732 times.
✗ Branch 40 → 68 not taken.
732 operandType = OpRuleManager::getPrefixBitwiseAndResultType(node, operand);
502 732 break;
503 default: // GCOV_EXCL_LINE
504 throw CompilerError(UNHANDLED_BRANCH, "PrefixUnaryExpr fall-through"); // GCOV_EXCL_LINE
505 }
506
507
2/4
✓ Branch 50 → 51 taken 6173 times.
✗ Branch 50 → 78 not taken.
✓ Branch 51 → 52 taken 6173 times.
✗ Branch 51 → 78 not taken.
12346 return ExprResult{node->setEvaluatedSymbolType(operandType, manIdx), operandEntry};
508 }
509
510 60657 std::any TypeChecker::visitPostfixUnaryExpr(PostfixUnaryExprNode *node) {
511 // If no operator is applied, simply visit the atomic expression
512
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 60657 times.
60657 if (node->op == PostfixUnaryExprNode::PostfixUnaryOp::OP_NONE)
513 return visit(node->atomicExpr);
514
515 // Visit left side
516 60657 ExprNode *lhsNode = node->postfixUnaryExpr;
517
2/4
✓ Branch 5 → 6 taken 60657 times.
✗ Branch 5 → 211 not taken.
✓ Branch 6 → 7 taken 60657 times.
✗ Branch 6 → 209 not taken.
60657 auto operand = std::any_cast<ExprResult>(visit(lhsNode));
518 60657 auto [operandType, operandEntry] = operand;
519
5/8
✓ Branch 8 → 9 taken 60657 times.
✗ Branch 8 → 316 not taken.
✓ Branch 9 → 10 taken 6 times.
✓ Branch 9 → 14 taken 60651 times.
✓ Branch 10 → 11 taken 6 times.
✗ Branch 10 → 212 not taken.
✓ Branch 11 → 12 taken 6 times.
✗ Branch 11 → 212 not taken.
60663 HANDLE_UNRESOLVED_TYPE_ER(operandType)
520
521
4/5
✓ Branch 14 → 15 taken 6628 times.
✓ Branch 14 → 101 taken 49102 times.
✓ Branch 14 → 159 taken 4482 times.
✓ Branch 14 → 167 taken 439 times.
✗ Branch 14 → 175 not taken.
60651 switch (node->op) {
522 6628 case PostfixUnaryExprNode::PostfixUnaryOp::OP_SUBSCRIPT: {
523 // Visit index assignment
524 6628 ExprNode *indexAssignExpr = node->subscriptIndexExpr;
525
2/4
✓ Branch 15 → 16 taken 6628 times.
✗ Branch 15 → 215 not taken.
✓ Branch 16 → 17 taken 6628 times.
✗ Branch 16 → 213 not taken.
6628 const auto index = std::any_cast<ExprResult>(visit(indexAssignExpr));
526
2/8
✓ Branch 18 → 19 taken 6628 times.
✗ Branch 18 → 258 not taken.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 24 taken 6628 times.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 216 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 216 not taken.
6628 HANDLE_UNRESOLVED_TYPE_ER(index.type)
527
528 // Check is there is an overloaded operator function available, if yes accept it
529
1/2
✓ Branch 24 → 25 taken 6628 times.
✗ Branch 24 → 217 not taken.
6628 const auto [type, _] = opRuleManager.isOperatorOverloadingFctAvailable<2>(node, OP_FCT_SUBSCRIPT, {operand, index}, 0);
530
3/4
✓ Branch 25 → 26 taken 6628 times.
✗ Branch 25 → 258 not taken.
✓ Branch 26 → 27 taken 416 times.
✓ Branch 26 → 28 taken 6212 times.
6628 if (!type.is(TY_INVALID)) {
531 416 operandType = type;
532 6626 break;
533 }
534
535
1/2
✓ Branch 28 → 29 taken 6212 times.
✗ Branch 28 → 218 not taken.
6212 operandType = operandType.removeReferenceWrapper();
536
537 // Check if the index is of the right type
538
3/4
✓ Branch 29 → 30 taken 6212 times.
✗ Branch 29 → 219 not taken.
✓ Branch 30 → 31 taken 1 time.
✓ Branch 30 → 41 taken 6211 times.
6212 if (!index.type.isOneOf({TY_INT, TY_LONG}))
539
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.
4 SOFT_ERROR_ER(node, ARRAY_INDEX_NOT_INT_OR_LONG, "Array index must be of type int or long")
540
541 // Check if we can apply the subscript operator on the lhs type
542
2/4
✓ Branch 41 → 42 taken 6211 times.
✗ Branch 41 → 227 not taken.
✗ Branch 42 → 43 not taken.
✓ Branch 42 → 52 taken 6211 times.
6211 if (!operandType.isOneOf({TY_ARRAY, TY_PTR, TY_STRING}))
543 SOFT_ERROR_ER(node, OPERATOR_WRONG_DATA_TYPE,
544 "Can only apply subscript operator on array type, got " + operandType.getName(true))
545
546 // Check if we have an unsafe operation
547
6/10
✓ Branch 52 → 53 taken 6211 times.
✗ Branch 52 → 258 not taken.
✓ Branch 53 → 54 taken 4657 times.
✓ Branch 53 → 57 taken 1554 times.
✓ Branch 54 → 55 taken 4657 times.
✗ Branch 54 → 258 not taken.
✗ Branch 55 → 56 not taken.
✓ Branch 55 → 57 taken 4657 times.
✗ Branch 58 → 59 not taken.
✓ Branch 58 → 69 taken 6211 times.
6211 if (operandType.isPtr() && !currentScope->doesAllowUnsafeOperations())
548 SOFT_ERROR_ER(
549 node, UNSAFE_OPERATION_IN_SAFE_CONTEXT,
550 "The subscript operator on pointers is an unsafe operation. Use unsafe blocks if you know what you are doing.")
551
552 // In case of compile time index value and known array size, perform a compile time out-of-bounds check
553
8/10
✓ Branch 69 → 70 taken 6211 times.
✗ Branch 69 → 258 not taken.
✓ Branch 70 → 71 taken 254 times.
✓ Branch 70 → 76 taken 5957 times.
✓ Branch 71 → 72 taken 254 times.
✗ Branch 71 → 258 not taken.
✓ Branch 72 → 73 taken 179 times.
✓ Branch 72 → 76 taken 75 times.
✓ Branch 77 → 78 taken 91 times.
✓ Branch 77 → 96 taken 6120 times.
6390 if (operandType.isArray() && operandType.getArraySize() != ARRAY_SIZE_UNKNOWN &&
554
3/4
✓ Branch 73 → 74 taken 179 times.
✗ Branch 73 → 258 not taken.
✓ Branch 74 → 75 taken 91 times.
✓ Branch 74 → 76 taken 88 times.
179 indexAssignExpr->hasCompileTimeValue(manIdx)) {
555
1/2
✓ Branch 78 → 79 taken 91 times.
✗ Branch 78 → 258 not taken.
91 const int32_t constIndex = indexAssignExpr->getCompileTimeValue(manIdx).intValue;
556
1/2
✓ Branch 79 → 80 taken 91 times.
✗ Branch 79 → 258 not taken.
91 const unsigned int constSize = operandType.getArraySize();
557 // Check if we are accessing out-of-bounds memory
558
2/2
✓ Branch 80 → 81 taken 1 time.
✓ Branch 80 → 96 taken 90 times.
91 if (constIndex >= static_cast<int32_t>(constSize)) {
559 1 const std::string idxStr = std::to_string(constIndex);
560 1 const std::string sizeStr = std::to_string(constSize);
561
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,
562 "You are trying to access element with index " + idxStr + " of an array with size " + sizeStr)
563 1 }
564 }
565
566 // Get item type
567
1/2
✓ Branch 96 → 97 taken 6210 times.
✗ Branch 96 → 257 not taken.
6210 operandType = operandType.getContained();
568
569 // Remove heap qualifier
570 6210 operandType.getQualifiers().isHeap = false;
571
572 6210 break;
573 }
574 49102 case PostfixUnaryExprNode::PostfixUnaryOp::OP_MEMBER_ACCESS: {
575 49102 const std::string &fieldName = node->identifier;
576
577 // Check if lhs is enum or strobj
578
1/2
✓ Branch 101 → 102 taken 49102 times.
✗ Branch 101 → 286 not taken.
49102 const QualType lhsBaseTy = operandType.autoDeReference();
579
3/4
✓ Branch 102 → 103 taken 49102 times.
✗ Branch 102 → 286 not taken.
✓ Branch 103 → 104 taken 1 time.
✓ Branch 103 → 113 taken 49101 times.
49102 if (!lhsBaseTy.is(TY_STRUCT))
580
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.
2 SOFT_ERROR_ER(node, INVALID_MEMBER_ACCESS, "Cannot apply member access operator on " + operandType.getName(false))
581
582 // Retrieve registry entry
583
1/2
✓ Branch 113 → 114 taken 49101 times.
✗ Branch 113 → 286 not taken.
49101 const std::string &structName = lhsBaseTy.getSubType();
584
1/2
✓ Branch 114 → 115 taken 49101 times.
✗ Branch 114 → 286 not taken.
49101 Scope *structScope = lhsBaseTy.getBodyScope();
585
586 // If we only have the generic struct scope, lookup the concrete manifestation scope
587
2/2
✓ Branch 115 → 116 taken 280 times.
✓ Branch 115 → 120 taken 48821 times.
49101 if (structScope->isGenericScope) {
588
1/2
✓ Branch 116 → 117 taken 280 times.
✗ Branch 116 → 286 not taken.
280 const Struct *spiceStruct = lhsBaseTy.getStruct(node);
589
1/2
✗ Branch 117 → 118 not taken.
✓ Branch 117 → 119 taken 280 times.
280 assert(spiceStruct != nullptr);
590 280 structScope = spiceStruct->scope;
591 }
592
1/2
✗ Branch 120 → 121 not taken.
✓ Branch 120 → 122 taken 49101 times.
49101 assert(!structScope->isGenericScope); // At this point we always expect a substantiation scope
593
594 // Get accessed field
595 49101 std::vector<size_t> indexPath;
596
1/2
✓ Branch 122 → 123 taken 49101 times.
✗ Branch 122 → 284 not taken.
49101 SymbolTableEntry *memberEntry = structScope->symbolTable.lookupInComposedFields(fieldName, indexPath);
597
2/2
✓ Branch 123 → 124 taken 2 times.
✓ Branch 123 → 135 taken 49099 times.
49101 if (!memberEntry)
598
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.
4 SOFT_ERROR_ER(node, REFERENCED_UNDEFINED_VARIABLE, "Field '" + node->identifier + "' not found in struct " + structName)
599
1/2
✓ Branch 135 → 136 taken 49099 times.
✗ Branch 135 → 284 not taken.
49099 const QualType memberType = memberEntry->getQualType();
600
601 // Check for insufficient visibility
602
8/14
✓ Branch 136 → 137 taken 49099 times.
✗ Branch 136 → 276 not taken.
✓ Branch 137 → 138 taken 1640 times.
✓ Branch 137 → 143 taken 47459 times.
✓ Branch 138 → 139 taken 1640 times.
✗ Branch 138 → 276 not taken.
✓ Branch 139 → 140 taken 1640 times.
✗ Branch 139 → 276 not taken.
✓ Branch 140 → 141 taken 1640 times.
✗ Branch 140 → 276 not taken.
✗ Branch 141 → 142 not taken.
✓ Branch 141 → 143 taken 1640 times.
✗ Branch 144 → 145 not taken.
✓ Branch 144 → 154 taken 49099 times.
49099 if (structScope->isImportedBy(rootScope) && !memberEntry->getQualType().getBase().isPublic())
603 SOFT_ERROR_ER(node, INSUFFICIENT_VISIBILITY, "Cannot access field '" + fieldName + "' due to its private visibility")
604
605 // Set field to used
606 49099 memberEntry->used = true;
607
608 // Overwrite type and entry of left side with member type and entry
609 49099 operandType = memberType;
610 49099 operandEntry = memberEntry;
611 49099 break;
612
2/2
✓ Branch 156 → 157 taken 2 times.
✓ Branch 156 → 158 taken 49099 times.
49101 }
613 4482 case PostfixUnaryExprNode::PostfixUnaryOp::OP_PLUS_PLUS: {
614
2/2
✓ Branch 159 → 160 taken 4480 times.
✓ Branch 159 → 287 taken 2 times.
4482 operandType = opRuleManager.getPostfixPlusPlusResultType(node, operand).type;
615
616
2/2
✓ Branch 160 → 161 taken 4476 times.
✓ Branch 160 → 166 taken 4 times.
4480 if (operandEntry) {
617 // In case the lhs is captured, notify the capture about the write access
618
3/4
✓ Branch 161 → 162 taken 4476 times.
✗ Branch 161 → 316 not taken.
✓ Branch 162 → 163 taken 4 times.
✓ Branch 162 → 164 taken 4472 times.
4476 if (Capture *lhsCapture = currentScope->symbolTable.lookupCapture(operandEntry->name); lhsCapture)
619
1/2
✓ Branch 163 → 164 taken 4 times.
✗ Branch 163 → 316 not taken.
4 lhsCapture->setAccessType(READ_WRITE);
620
621 // Update the state of the variable
622
1/2
✓ Branch 164 → 165 taken 4476 times.
✗ Branch 164 → 288 not taken.
4476 operandEntry->updateState(INITIALIZED, node);
623 }
624
625 4480 break;
626 }
627 439 case PostfixUnaryExprNode::PostfixUnaryOp::OP_MINUS_MINUS: {
628
1/2
✓ Branch 167 → 168 taken 439 times.
✗ Branch 167 → 289 not taken.
439 operandType = opRuleManager.getPostfixMinusMinusResultType(node, operand).type;
629
630
2/2
✓ Branch 168 → 169 taken 435 times.
✓ Branch 168 → 174 taken 4 times.
439 if (operandEntry) {
631 // In case the lhs is captured, notify the capture about the write access
632
2/4
✓ Branch 169 → 170 taken 435 times.
✗ Branch 169 → 316 not taken.
✗ Branch 170 → 171 not taken.
✓ Branch 170 → 172 taken 435 times.
435 if (Capture *lhsCapture = currentScope->symbolTable.lookupCapture(operandEntry->name); lhsCapture)
633 lhsCapture->setAccessType(READ_WRITE);
634
635 // Update the state of the variable
636
1/2
✓ Branch 172 → 173 taken 435 times.
✗ Branch 172 → 290 not taken.
435 operandEntry->updateState(INITIALIZED, node);
637 }
638
639 439 break;
640 }
641 default: // GCOV_EXCL_LINE
642 throw CompilerError(UNHANDLED_BRANCH, "PostfixUnaryExpr fall-through"); // GCOV_EXCL_LINE
643 }
644
645
2/4
✓ Branch 183 → 184 taken 60644 times.
✗ Branch 183 → 316 not taken.
✗ Branch 184 → 185 not taken.
✓ Branch 184 → 203 taken 60644 times.
60644 if (operandType.is(TY_INVALID)) {
646 const std::string &varName = operandEntry ? operandEntry->name : "";
647 SOFT_ERROR_ER(node, REFERENCED_UNDEFINED_VARIABLE, "Variable '" + varName + "' was referenced before declared")
648 }
649
650
2/4
✓ Branch 203 → 204 taken 60644 times.
✗ Branch 203 → 315 not taken.
✓ Branch 204 → 205 taken 60644 times.
✗ Branch 204 → 315 not taken.
121288 return ExprResult{node->setEvaluatedSymbolType(operandType, manIdx), operandEntry};
651 }
652
653 258888 std::any TypeChecker::visitAtomicExpr(AtomicExprNode *node) {
654 // Check if constant
655
2/2
✓ Branch 2 → 3 taken 48529 times.
✓ Branch 2 → 5 taken 210359 times.
258888 if (node->constant)
656
1/2
✓ Branch 3 → 4 taken 48529 times.
✗ Branch 3 → 218 not taken.
48529 return visit(node->constant);
657
658 // Check if value
659
2/2
✓ Branch 5 → 6 taken 63728 times.
✓ Branch 5 → 8 taken 146631 times.
210359 if (node->value)
660
2/2
✓ Branch 6 → 7 taken 63723 times.
✓ Branch 6 → 218 taken 5 times.
63728 return visit(node->value);
661
662 // Check for assign expression within parentheses
663
2/2
✓ Branch 8 → 9 taken 1143 times.
✓ Branch 8 → 11 taken 145488 times.
146631 if (node->assignExpr)
664
2/2
✓ Branch 9 → 10 taken 1140 times.
✓ Branch 9 → 218 taken 3 times.
1143 return visit(node->assignExpr);
665
666 // Identifier (local or global variable access)
667
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 145488 times.
145488 assert(!node->fqIdentifier.empty());
668
669
1/2
✓ Branch 14 → 15 taken 145488 times.
✗ Branch 14 → 218 not taken.
145488 auto &[entry, accessScope, capture] = node->data.at(manIdx);
670 145488 accessScope = currentScope;
671
672 // Check if a local or global variable can be found by searching for the name
673
2/2
✓ Branch 16 → 17 taken 141610 times.
✓ Branch 16 → 22 taken 3878 times.
145488 if (node->identifierFragments.size() == 1)
674 283220 entry = accessScope->lookup(node->identifierFragments.back());
675
676 // If no local or global was found, search in the name registry
677
2/2
✓ Branch 22 → 23 taken 4030 times.
✓ Branch 22 → 35 taken 141458 times.
145488 if (!entry) {
678
1/2
✓ Branch 23 → 24 taken 4030 times.
✗ Branch 23 → 218 not taken.
4030 const NameRegistryEntry *registryEntry = sourceFile->getNameRegistryEntry(node->fqIdentifier);
679
2/2
✓ Branch 24 → 25 taken 1 time.
✓ Branch 24 → 34 taken 4029 times.
4030 if (!registryEntry)
680
5/10
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 166 not taken.
✓ Branch 26 → 27 taken 1 time.
✗ Branch 26 → 164 not taken.
✓ Branch 27 → 28 taken 1 time.
✗ Branch 27 → 162 not taken.
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 168 not taken.
✓ Branch 31 → 32 taken 1 time.
✗ Branch 31 → 168 not taken.
2 SOFT_ERROR_ER(node, REFERENCED_UNDEFINED_VARIABLE, "The variable '" + node->fqIdentifier + "' could not be found")
681 4029 entry = registryEntry->targetEntry;
682 4029 accessScope = registryEntry->targetScope;
683 }
684
1/2
✗ Branch 35 → 36 not taken.
✓ Branch 35 → 37 taken 145487 times.
145487 assert(entry != nullptr);
685 145487 entry->used = true;
686
1/2
✓ Branch 37 → 38 taken 145487 times.
✗ Branch 37 → 218 not taken.
145487 capture = accessScope->symbolTable.lookupCapture(entry->name);
687
688
1/2
✓ Branch 38 → 39 taken 145487 times.
✗ Branch 38 → 218 not taken.
145487 const QualType varType = entry->getQualType();
689
5/8
✓ Branch 39 → 40 taken 145487 times.
✗ Branch 39 → 218 not taken.
✓ Branch 40 → 41 taken 9 times.
✓ Branch 40 → 45 taken 145478 times.
✓ Branch 41 → 42 taken 9 times.
✗ Branch 41 → 169 not taken.
✓ Branch 42 → 43 taken 9 times.
✗ Branch 42 → 169 not taken.
145496 HANDLE_UNRESOLVED_TYPE_ER(varType)
690
3/4
✓ Branch 45 → 46 taken 145478 times.
✗ Branch 45 → 218 not taken.
✓ Branch 46 → 47 taken 2 times.
✓ Branch 46 → 56 taken 145476 times.
145478 if (varType.is(TY_INVALID))
691
5/10
✓ Branch 47 → 48 taken 2 times.
✗ Branch 47 → 174 not taken.
✓ Branch 48 → 49 taken 2 times.
✗ Branch 48 → 172 not taken.
✓ Branch 49 → 50 taken 2 times.
✗ Branch 49 → 170 not taken.
✓ Branch 52 → 53 taken 2 times.
✗ Branch 52 → 176 not taken.
✓ Branch 53 → 54 taken 2 times.
✗ Branch 53 → 176 not taken.
4 SOFT_ERROR_ER(node, USED_BEFORE_DECLARED, "Symbol '" + entry->name + "' was used before declared.")
692
693
7/8
✓ Branch 56 → 57 taken 145476 times.
✗ Branch 56 → 177 not taken.
✓ Branch 57 → 58 taken 121 times.
✓ Branch 57 → 60 taken 145355 times.
✓ Branch 58 → 59 taken 21 times.
✓ Branch 58 → 60 taken 100 times.
✓ Branch 61 → 62 taken 21 times.
✓ Branch 61 → 90 taken 145455 times.
145476 if (varType.isOneOf({TY_FUNCTION, TY_PROCEDURE}) && entry->global) {
694 // Check if overloaded function was referenced
695
1/2
✓ Branch 62 → 63 taken 21 times.
✗ Branch 62 → 218 not taken.
21 const std::vector<Function *> *manifestations = entry->declNode->getFctManifestations(entry->name);
696
2/2
✓ Branch 64 → 65 taken 1 time.
✓ Branch 64 → 75 taken 20 times.
21 if (manifestations->size() > 1)
697
4/8
✓ Branch 67 → 68 taken 1 time.
✗ Branch 67 → 180 not taken.
✓ Branch 68 → 69 taken 1 time.
✗ Branch 68 → 178 not taken.
✓ Branch 71 → 72 taken 1 time.
✗ Branch 71 → 184 not taken.
✓ Branch 72 → 73 taken 1 time.
✗ Branch 72 → 184 not taken.
4 SOFT_ERROR_ER(node, REFERENCED_OVERLOADED_FCT, "Overloaded functions / functions with optional params cannot be referenced")
698
2/2
✓ Branch 77 → 78 taken 1 time.
✓ Branch 77 → 88 taken 19 times.
20 if (!manifestations->front()->templateTypes.empty())
699
4/8
✓ Branch 80 → 81 taken 1 time.
✗ Branch 80 → 187 not taken.
✓ Branch 81 → 82 taken 1 time.
✗ Branch 81 → 185 not taken.
✓ Branch 84 → 85 taken 1 time.
✗ Branch 84 → 191 not taken.
✓ Branch 85 → 86 taken 1 time.
✗ Branch 85 → 191 not taken.
4 SOFT_ERROR_ER(node, REFERENCED_OVERLOADED_FCT, "Generic functions cannot be referenced")
700 // Set referenced function to used
701 19 Function *referencedFunction = manifestations->front();
702 19 referencedFunction->used = true;
703 19 referencedFunction->entry->used = true;
704 }
705
706 // The base type should be an extended primitive
707
1/2
✓ Branch 90 → 91 taken 145474 times.
✗ Branch 90 → 218 not taken.
145474 const QualType baseType = varType.getBase();
708
6/10
✓ Branch 91 → 92 taken 145474 times.
✗ Branch 91 → 218 not taken.
✓ Branch 92 → 93 taken 4 times.
✓ Branch 92 → 96 taken 145470 times.
✓ Branch 93 → 94 taken 4 times.
✗ Branch 93 → 218 not taken.
✗ Branch 94 → 95 not taken.
✓ Branch 94 → 96 taken 4 times.
✗ Branch 97 → 98 not taken.
✓ Branch 97 → 109 taken 145474 times.
145474 if (!baseType.isExtendedPrimitive() && !baseType.is(TY_DYN))
709 SOFT_ERROR_ER(node, INVALID_SYMBOL_ACCESS, "A symbol of type " + varType.getName(false) + " cannot be accessed here")
710
711 // Check if we have seen a 'this.' prefix, because the generator needs that
712
6/8
✓ Branch 109 → 110 taken 1 time.
✓ Branch 109 → 114 taken 145473 times.
✓ Branch 111 → 112 taken 1 time.
✗ Branch 111 → 218 not taken.
✓ Branch 112 → 113 taken 1 time.
✗ Branch 112 → 114 not taken.
✓ Branch 115 → 116 taken 1 time.
✓ Branch 115 → 125 taken 145473 times.
145474 if (entry->scope->type == ScopeType::STRUCT && node->identifierFragments.front() != THIS_VARIABLE_NAME)
713
5/10
✓ Branch 116 → 117 taken 1 time.
✗ Branch 116 → 206 not taken.
✓ Branch 117 → 118 taken 1 time.
✗ Branch 117 → 204 not taken.
✓ Branch 118 → 119 taken 1 time.
✗ Branch 118 → 202 not taken.
✓ Branch 121 → 122 taken 1 time.
✗ Branch 121 → 208 not taken.
✓ Branch 122 → 123 taken 1 time.
✗ Branch 122 → 208 not taken.
2 SOFT_ERROR_ER(node, REFERENCED_UNDEFINED_VARIABLE,
714 "The symbol '" + node->fqIdentifier + "' could not be found. Missing 'this.' prefix?")
715
716 // Ensure that the entry is public, if the symbol is imported.
717 // An exception are enum items. There it is sufficient, that the enum itself is public.
718
7/8
✓ Branch 125 → 126 taken 145473 times.
✗ Branch 125 → 218 not taken.
✓ Branch 126 → 127 taken 3367 times.
✓ Branch 126 → 129 taken 142106 times.
✓ Branch 127 → 128 taken 250 times.
✓ Branch 127 → 129 taken 3117 times.
✓ Branch 130 → 131 taken 250 times.
✓ Branch 130 → 144 taken 145223 times.
145473 if (accessScope->isImportedBy(rootScope) && accessScope->type != ScopeType::ENUM)
719
5/8
✓ Branch 131 → 132 taken 250 times.
✗ Branch 131 → 209 not taken.
✓ Branch 132 → 133 taken 250 times.
✗ Branch 132 → 209 not taken.
✓ Branch 133 → 134 taken 250 times.
✗ Branch 133 → 209 not taken.
✓ Branch 134 → 135 taken 1 time.
✓ Branch 134 → 144 taken 249 times.
250 if (!entry->getQualType().getBase().isPublic())
720
5/10
✓ Branch 135 → 136 taken 1 time.
✗ Branch 135 → 214 not taken.
✓ Branch 136 → 137 taken 1 time.
✗ Branch 136 → 212 not taken.
✓ Branch 137 → 138 taken 1 time.
✗ Branch 137 → 210 not taken.
✓ Branch 140 → 141 taken 1 time.
✗ Branch 140 → 216 not taken.
✓ Branch 141 → 142 taken 1 time.
✗ Branch 141 → 216 not taken.
2 SOFT_ERROR_ER(node, INSUFFICIENT_VISIBILITY, "Cannot access '" + entry->name + "' due to its private visibility")
721
722 // For enum item access, use access scope of the enum
723
2/2
✓ Branch 144 → 145 taken 3873 times.
✓ Branch 144 → 146 taken 141599 times.
145472 if (entry->scope->type == ScopeType::ENUM)
724 3873 accessScope = entry->scope;
725
726 // For struct access, use access scope of the struct
727
3/4
✓ Branch 146 → 147 taken 145472 times.
✗ Branch 146 → 218 not taken.
✓ Branch 147 → 148 taken 61505 times.
✓ Branch 147 → 156 taken 83967 times.
145472 if (baseType.is(TY_STRUCT)) {
728
1/2
✓ Branch 148 → 149 taken 61505 times.
✗ Branch 148 → 218 not taken.
61505 const std::string &structName = baseType.getSubType();
729
1/2
✓ Branch 149 → 150 taken 61505 times.
✗ Branch 149 → 218 not taken.
61505 const NameRegistryEntry *nameRegistryEntry = sourceFile->getNameRegistryEntry(structName);
730 // The struct may only be reachable transitively (i.e. it is not present in this file's name registry under
731 // its unqualified name). In that case, fall back to the struct's body scope, which is exactly what the
732 // registry entry's targetScope would point to (see SymbolTableBuilder struct registration). This keeps
733 // member access working across deep transitive imports instead of crashing.
734
3/4
✓ Branch 150 → 151 taken 61488 times.
✓ Branch 150 → 152 taken 17 times.
✓ Branch 152 → 153 taken 17 times.
✗ Branch 152 → 218 not taken.
61505 accessScope = nameRegistryEntry != nullptr ? nameRegistryEntry->targetScope : baseType.getBodyScope();
735
1/2
✗ Branch 154 → 155 not taken.
✓ Branch 154 → 156 taken 61505 times.
61505 assert(accessScope != nullptr);
736 }
737
738
2/4
✓ Branch 156 → 157 taken 145472 times.
✗ Branch 156 → 217 not taken.
✓ Branch 157 → 158 taken 145472 times.
✗ Branch 157 → 217 not taken.
290944 return ExprResult{node->setEvaluatedSymbolType(varType, manIdx), entry};
739 }
740
741 } // namespace spice::compiler
742