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 | 21885 | std::any TypeChecker::visitAssignExpr(AssignExprNode *node) { | |
| 14 | // Check if ternary | ||
| 15 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 10 taken 21885 times.
|
21885 | 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 21885 times.
✗ Branch 10 → 142 not taken.
|
21885 | if (node->op != AssignExprNode::AssignOp::OP_NONE) { |
| 23 | // Visit the right side first | ||
| 24 |
2/4✓ Branch 11 → 12 taken 21885 times.
✗ Branch 11 → 157 not taken.
✓ Branch 12 → 13 taken 21885 times.
✗ Branch 12 → 155 not taken.
|
21885 | auto rhs = std::any_cast<ExprResult>(visit(node->rhs)); |
| 25 | 21885 | auto [rhsType, rhsEntry] = rhs; | |
| 26 |
5/8✓ Branch 14 → 15 taken 21885 times.
✗ Branch 14 → 201 not taken.
✓ Branch 15 → 16 taken 1 time.
✓ Branch 15 → 20 taken 21884 times.
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 158 not taken.
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 158 not taken.
|
21886 | HANDLE_UNRESOLVED_TYPE_ER(rhsType) |
| 27 | // Then visit the left side | ||
| 28 |
2/4✓ Branch 20 → 21 taken 21884 times.
✗ Branch 20 → 161 not taken.
✓ Branch 21 → 22 taken 21884 times.
✗ Branch 21 → 159 not taken.
|
21884 | auto lhs = std::any_cast<ExprResult>(visit(node->lhs)); |
| 29 | 21884 | auto [lhsType, lhsVar] = lhs; | |
| 30 |
5/8✓ Branch 23 → 24 taken 21884 times.
✗ Branch 23 → 201 not taken.
✓ Branch 24 → 25 taken 1 time.
✓ Branch 24 → 29 taken 21883 times.
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 162 not taken.
✓ Branch 26 → 27 taken 1 time.
✗ Branch 26 → 162 not taken.
|
21885 | 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 19540 times.
✓ Branch 30 → 40 taken 1 time.
✓ Branch 31 → 32 taken 19540 times.
✗ Branch 31 → 163 not taken.
✓ Branch 32 → 33 taken 15951 times.
✓ Branch 32 → 40 taken 3589 times.
|
19541 | if (node->op == AssignExprNode::AssignOp::OP_ASSIGN && lhs.entry != nullptr && lhs.entry->isField() && |
| 38 |
13/16✓ Branch 29 → 30 taken 19541 times.
✓ Branch 29 → 40 taken 2342 times.
✓ Branch 33 → 34 taken 15951 times.
✗ Branch 33 → 163 not taken.
✓ Branch 34 → 35 taken 15951 times.
✗ Branch 34 → 163 not taken.
✓ Branch 35 → 36 taken 153 times.
✓ Branch 35 → 40 taken 15798 times.
✓ Branch 36 → 37 taken 153 times.
✗ Branch 36 → 163 not taken.
✓ Branch 37 → 38 taken 7 times.
✓ Branch 37 → 40 taken 146 times.
✓ Branch 38 → 39 taken 1 time.
✓ Branch 38 → 40 taken 6 times.
✓ Branch 41 → 42 taken 1 time.
✓ Branch 41 → 55 taken 21882 times.
|
41424 | 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 19540 times.
✓ Branch 55 → 98 taken 2342 times.
|
21882 | if (node->op == AssignExprNode::AssignOp::OP_ASSIGN) { |
| 46 |
8/10✓ Branch 56 → 57 taken 19539 times.
✓ Branch 56 → 63 taken 1 time.
✓ Branch 57 → 58 taken 19539 times.
✗ Branch 57 → 188 not taken.
✓ Branch 58 → 59 taken 15950 times.
✓ Branch 58 → 63 taken 3589 times.
✓ Branch 60 → 61 taken 15950 times.
✗ Branch 60 → 188 not taken.
✓ Branch 61 → 62 taken 5931 times.
✓ Branch 61 → 63 taken 10019 times.
|
19540 | const bool isDecl = lhs.entry != nullptr && lhs.entry->isField() && !lhs.entry->getLifecycle().isInitialized(); |
| 47 |
2/2✓ Branch 64 → 65 taken 19539 times.
✓ Branch 64 → 188 taken 1 time.
|
19540 | const auto [assignType, copyCtor] = opRuleManager.getAssignResultType(node, lhs, rhs, isDecl); |
| 48 | 19539 | 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 188 times.
✓ Branch 67 → 75 taken 19351 times.
✓ Branch 68 → 69 taken 34 times.
✓ Branch 68 → 75 taken 154 times.
✓ Branch 69 → 70 taken 34 times.
✗ Branch 69 → 75 not taken.
✓ Branch 70 → 71 taken 34 times.
✗ Branch 70 → 188 not taken.
✓ Branch 71 → 72 taken 19 times.
✓ Branch 71 → 75 taken 15 times.
✓ Branch 76 → 77 taken 11 times.
✓ Branch 76 → 97 taken 19528 times.
|
19558 | if (copyCtor != nullptr && !isDecl && lhs.entry != nullptr && lhs.entry->isInitialized() && |
| 56 |
3/4✓ Branch 72 → 73 taken 19 times.
✗ Branch 72 → 188 not taken.
✓ Branch 73 → 74 taken 11 times.
✓ Branch 73 → 75 taken 8 times.
|
19 | !currentScope->doesAllowUnsafeOperations()) { |
| 57 |
2/4✓ Branch 77 → 78 taken 11 times.
✗ Branch 77 → 177 not taken.
✓ Branch 78 → 79 taken 11 times.
✗ Branch 78 → 177 not taken.
|
11 | const QualType lhsSType = lhs.type.removeReferenceWrapper().toNonConst(); |
| 58 |
5/10✓ Branch 79 → 80 taken 11 times.
✗ Branch 79 → 187 not taken.
✓ Branch 80 → 81 taken 11 times.
✗ Branch 80 → 84 not taken.
✓ Branch 81 → 82 taken 11 times.
✗ Branch 81 → 187 not taken.
✓ Branch 82 → 83 taken 11 times.
✗ Branch 82 → 84 not taken.
✓ Branch 85 → 86 taken 11 times.
✗ Branch 85 → 96 not taken.
|
11 | if (lhsSType.is(TY_STRUCT) && !lhsSType.isTriviallyDestructible(node)) |
| 59 |
2/4✓ Branch 89 → 90 taken 11 times.
✗ Branch 89 → 180 not taken.
✓ Branch 90 → 91 taken 11 times.
✗ Branch 90 → 178 not taken.
|
33 | node->lhsDtorFct[manIdx] = implicitlyCallStructMethod(lhsSType, DTOR_FUNCTION_NAME, {}, node); |
| 60 | } | ||
| 61 |
2/2✓ Branch 98 → 99 taken 1171 times.
✓ Branch 98 → 101 taken 1171 times.
|
2342 | } else if (node->op == AssignExprNode::AssignOp::OP_PLUS_EQUAL) { |
| 62 |
1/2✓ Branch 99 → 100 taken 1171 times.
✗ Branch 99 → 189 not taken.
|
1171 | rhsType = opRuleManager.getPlusEqualResultType(node, lhs, rhs).type; |
| 63 |
2/2✓ Branch 101 → 102 taken 81 times.
✓ Branch 101 → 104 taken 1090 times.
|
1171 | } else if (node->op == AssignExprNode::AssignOp::OP_MINUS_EQUAL) { |
| 64 |
1/2✓ Branch 102 → 103 taken 81 times.
✗ Branch 102 → 190 not taken.
|
81 | rhsType = opRuleManager.getMinusEqualResultType(node, lhs, rhs).type; |
| 65 |
2/2✓ Branch 104 → 105 taken 176 times.
✓ Branch 104 → 107 taken 914 times.
|
1090 | } else if (node->op == AssignExprNode::AssignOp::OP_MUL_EQUAL) { |
| 66 |
1/2✓ Branch 105 → 106 taken 176 times.
✗ Branch 105 → 191 not taken.
|
176 | rhsType = opRuleManager.getMulEqualResultType(node, lhs, rhs).type; |
| 67 |
2/2✓ Branch 107 → 108 taken 104 times.
✓ Branch 107 → 110 taken 810 times.
|
914 | } else if (node->op == AssignExprNode::AssignOp::OP_DIV_EQUAL) { |
| 68 |
1/2✓ Branch 108 → 109 taken 104 times.
✗ Branch 108 → 192 not taken.
|
104 | rhsType = opRuleManager.getDivEqualResultType(node, lhs, rhs).type; |
| 69 |
2/2✓ Branch 110 → 111 taken 41 times.
✓ Branch 110 → 113 taken 769 times.
|
810 | } 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 757 times.
|
769 | } 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 744 times.
|
757 | } 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 727 times.
|
744 | } 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 714 times.
|
727 | } 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 714 times.
✗ Branch 125 → 128 not taken.
|
714 | } else if (node->op == AssignExprNode::AssignOp::OP_XOR_EQUAL) { |
| 80 |
1/2✓ Branch 126 → 127 taken 714 times.
✗ Branch 126 → 198 not taken.
|
714 | rhsType = opRuleManager.getXorEqualResultType(node, lhs, rhs); |
| 81 | } | ||
| 82 | |||
| 83 |
1/2✓ Branch 128 → 129 taken 21881 times.
✗ Branch 128 → 137 not taken.
|
21881 | if (lhsVar) { // Variable is involved on the left side |
| 84 | // Perform type inference | ||
| 85 |
3/4✓ Branch 129 → 130 taken 21881 times.
✗ Branch 129 → 201 not taken.
✓ Branch 130 → 131 taken 1 time.
✓ Branch 130 → 132 taken 21880 times.
|
21881 | 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 21881 times.
✗ Branch 132 → 201 not taken.
✓ Branch 133 → 134 taken 3 times.
✓ Branch 133 → 135 taken 21878 times.
|
21881 | 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 21881 times.
✗ Branch 135 → 199 not taken.
|
21881 | lhsVar->updateState(INITIALIZED, node); |
| 94 | } | ||
| 95 | |||
| 96 |
2/4✓ Branch 137 → 138 taken 21881 times.
✗ Branch 137 → 200 not taken.
✓ Branch 138 → 139 taken 21881 times.
✗ Branch 138 → 200 not taken.
|
43762 | return ExprResult{node->setEvaluatedSymbolType(rhsType, manIdx)}; |
| 97 | } | ||
| 98 | |||
| 99 | − | throw CompilerError(UNHANDLED_BRANCH, "AssignExpr fall-through"); // GCOV_EXCL_LINE | |
| 100 | } | ||
| 101 | |||
| 102 | 2085 | 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 2085 times.
|
2085 | if (!node->falseExpr) |
| 105 | ✗ | return visit(node->condition); | |
| 106 | |||
| 107 | // Visit condition | ||
| 108 |
2/4✓ Branch 5 → 6 taken 2085 times.
✗ Branch 5 → 126 not taken.
✓ Branch 6 → 7 taken 2085 times.
✗ Branch 6 → 124 not taken.
|
2085 | const auto condition = std::any_cast<ExprResult>(visit(node->condition)); |
| 109 |
2/8✓ Branch 8 → 9 taken 2085 times.
✗ Branch 8 → 161 not taken.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 14 taken 2085 times.
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 127 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 127 not taken.
|
2085 | HANDLE_UNRESOLVED_TYPE_ER(condition.type) |
| 110 |
6/10✓ Branch 14 → 15 taken 1 time.
✓ Branch 14 → 16 taken 2084 times.
✓ Branch 16 → 17 taken 2084 times.
✗ Branch 16 → 128 not taken.
✓ Branch 17 → 18 taken 2084 times.
✗ Branch 17 → 128 not taken.
✓ Branch 18 → 19 taken 2084 times.
✓ Branch 18 → 20 taken 1 time.
✗ Branch 128 → 129 not taken.
✗ Branch 128 → 130 not taken.
|
2085 | const auto trueExpr = node->isShortened ? condition : std::any_cast<ExprResult>(visit(node->trueExpr)); |
| 111 | 2085 | const auto [trueType, trueEntry] = trueExpr; | |
| 112 |
2/8✓ Branch 20 → 21 taken 2085 times.
✗ Branch 20 → 161 not taken.
✗ Branch 21 → 22 not taken.
✓ Branch 21 → 26 taken 2085 times.
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 132 not taken.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 132 not taken.
|
2085 | HANDLE_UNRESOLVED_TYPE_ER(trueType) |
| 113 |
2/4✓ Branch 26 → 27 taken 2085 times.
✗ Branch 26 → 135 not taken.
✓ Branch 27 → 28 taken 2085 times.
✗ Branch 27 → 133 not taken.
|
2085 | const auto falseExpr = std::any_cast<ExprResult>(visit(node->falseExpr)); |
| 114 | 2085 | const auto [falseType, falseEntry] = falseExpr; | |
| 115 |
2/8✓ Branch 29 → 30 taken 2085 times.
✗ Branch 29 → 161 not taken.
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 35 taken 2085 times.
✗ Branch 31 → 32 not taken.
✗ Branch 31 → 136 not taken.
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 136 not taken.
|
2085 | HANDLE_UNRESOLVED_TYPE_ER(falseType) |
| 116 | |||
| 117 | // Check if the condition evaluates to bool | ||
| 118 |
3/4✓ Branch 35 → 36 taken 2085 times.
✗ Branch 35 → 161 not taken.
✓ Branch 36 → 37 taken 1 time.
✓ Branch 36 → 47 taken 2084 times.
|
2085 | 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 2084 times.
✗ Branch 47 → 161 not taken.
|
2084 | const QualType trueTypeModified = trueType.removeReferenceWrapper(); |
| 123 |
1/2✓ Branch 48 → 49 taken 2084 times.
✗ Branch 48 → 161 not taken.
|
2084 | const QualType falseTypeModified = falseType.removeReferenceWrapper(); |
| 124 |
3/4✓ Branch 49 → 50 taken 2084 times.
✗ Branch 49 → 161 not taken.
✓ Branch 50 → 51 taken 1 time.
✓ Branch 50 → 66 taken 2083 times.
|
2084 | 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 2083 times.
✗ Branch 66 → 161 not taken.
✓ Branch 67 → 68 taken 9 times.
✓ Branch 67 → 69 taken 2074 times.
|
2083 | QualType resultType = trueType.isRef() ? trueType : falseType; |
| 132 | // Infer the const-ness from the more restrictive operand | ||
| 133 |
7/10✓ Branch 70 → 71 taken 2083 times.
✗ Branch 70 → 161 not taken.
✓ Branch 71 → 72 taken 1212 times.
✓ Branch 71 → 74 taken 871 times.
✓ Branch 72 → 73 taken 1212 times.
✗ Branch 72 → 161 not taken.
✓ Branch 73 → 74 taken 361 times.
✓ Branch 73 → 75 taken 851 times.
✓ Branch 76 → 77 taken 2083 times.
✗ Branch 76 → 161 not taken.
|
2083 | 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 | 2083 | bool removedAnonymousSymbols = false; | |
| 138 |
2/2✓ Branch 77 → 78 taken 1261 times.
✓ Branch 77 → 89 taken 822 times.
|
2083 | if (trueEntry) { |
| 139 |
2/2✓ Branch 78 → 79 taken 286 times.
✓ Branch 78 → 81 taken 975 times.
|
1261 | if (trueEntry->anonymous) { |
| 140 |
1/2✓ Branch 79 → 80 taken 286 times.
✗ Branch 79 → 161 not taken.
|
286 | currentScope->symbolTable.deleteAnonymous(trueEntry->name); |
| 141 | 286 | removedAnonymousSymbols = true; | |
| 142 |
8/10✓ Branch 81 → 82 taken 975 times.
✗ Branch 81 → 161 not taken.
✓ Branch 82 → 83 taken 967 times.
✓ Branch 82 → 86 taken 8 times.
✓ Branch 83 → 84 taken 967 times.
✗ Branch 83 → 161 not taken.
✓ Branch 84 → 85 taken 9 times.
✓ Branch 84 → 86 taken 958 times.
✓ Branch 87 → 88 taken 9 times.
✓ Branch 87 → 89 taken 966 times.
|
975 | } else if (!trueType.isRef() && !trueType.isTriviallyCopyable(node)) { |
| 143 | 9 | node->trueSideCallsCopyCtor = true; | |
| 144 | } | ||
| 145 | } | ||
| 146 |
2/2✓ Branch 89 → 90 taken 796 times.
✓ Branch 89 → 101 taken 1287 times.
|
2083 | if (falseEntry) { |
| 147 |
2/2✓ Branch 90 → 91 taken 276 times.
✓ Branch 90 → 93 taken 520 times.
|
796 | if (falseEntry->anonymous) { |
| 148 |
1/2✓ Branch 91 → 92 taken 276 times.
✗ Branch 91 → 161 not taken.
|
276 | currentScope->symbolTable.deleteAnonymous(falseEntry->name); |
| 149 | 276 | removedAnonymousSymbols = true; | |
| 150 |
8/10✓ Branch 93 → 94 taken 520 times.
✗ Branch 93 → 161 not taken.
✓ Branch 94 → 95 taken 504 times.
✓ Branch 94 → 98 taken 16 times.
✓ Branch 95 → 96 taken 504 times.
✗ Branch 95 → 161 not taken.
✓ Branch 96 → 97 taken 20 times.
✓ Branch 96 → 98 taken 484 times.
✓ Branch 99 → 100 taken 20 times.
✓ Branch 99 → 101 taken 500 times.
|
520 | } 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 | 2083 | SymbolTableEntry *anonymousSymbol = nullptr; | |
| 157 |
4/4✓ Branch 101 → 102 taken 2074 times.
✓ Branch 101 → 103 taken 9 times.
✓ Branch 102 → 103 taken 14 times.
✓ Branch 102 → 104 taken 2060 times.
|
2083 | const bool calledCopyCtor = node->trueSideCallsCopyCtor || node->falseSideCallsCopyCtor; |
| 158 |
9/10✓ Branch 105 → 106 taken 1795 times.
✓ Branch 105 → 109 taken 288 times.
✓ Branch 106 → 107 taken 1780 times.
✓ Branch 106 → 109 taken 15 times.
✓ Branch 107 → 108 taken 1780 times.
✗ Branch 107 → 161 not taken.
✓ Branch 108 → 109 taken 10 times.
✓ Branch 108 → 110 taken 1770 times.
✓ Branch 111 → 112 taken 313 times.
✓ Branch 111 → 114 taken 1770 times.
|
2083 | if (removedAnonymousSymbols || calledCopyCtor || resultType.isRef()) |
| 159 |
1/2✓ Branch 112 → 113 taken 313 times.
✗ Branch 112 → 161 not taken.
|
313 | 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 2074 times.
✓ Branch 114 → 116 taken 9 times.
✓ Branch 115 → 116 taken 14 times.
✓ Branch 115 → 118 taken 2060 times.
|
2083 | 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 2083 times.
✗ Branch 118 → 160 not taken.
✓ Branch 119 → 120 taken 2083 times.
✗ Branch 119 → 160 not taken.
|
4166 | return ExprResult{node->setEvaluatedSymbolType(resultType, manIdx), anonymousSymbol}; |
| 166 | } | ||
| 167 | |||
| 168 | 2144 | 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 2144 times.
|
2144 | if (node->operands.size() == 1) |
| 171 | ✗ | return visit(node->operands.front()); | |
| 172 | |||
| 173 | // Visit leftmost operand | ||
| 174 |
2/4✓ Branch 8 → 9 taken 2144 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 2144 times.
✗ Branch 9 → 37 not taken.
|
2144 | auto currentOperand = std::any_cast<ExprResult>(visit(node->operands[0])); |
| 175 |
2/8✓ Branch 11 → 12 taken 2144 times.
✗ Branch 11 → 46 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 2144 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 40 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 40 not taken.
|
2144 | HANDLE_UNRESOLVED_TYPE_ER(currentOperand.type) |
| 176 | |||
| 177 | // Loop through all remaining operands | ||
| 178 |
2/2✓ Branch 31 → 18 taken 2756 times.
✓ Branch 31 → 32 taken 2143 times.
|
4899 | for (size_t i = 1; i < node->operands.size(); i++) { |
| 179 |
2/4✓ Branch 19 → 20 taken 2756 times.
✗ Branch 19 → 43 not taken.
✓ Branch 20 → 21 taken 2756 times.
✗ Branch 20 → 41 not taken.
|
2756 | auto rhsOperand = std::any_cast<ExprResult>(visit(node->operands[i])); |
| 180 |
2/8✓ Branch 22 → 23 taken 2756 times.
✗ Branch 22 → 45 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 2756 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 44 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 44 not taken.
|
2756 | HANDLE_UNRESOLVED_TYPE_ER(rhsOperand.type) |
| 181 |
2/2✓ Branch 28 → 29 taken 2755 times.
✓ Branch 28 → 45 taken 1 time.
|
2756 | currentOperand = {OpRuleManager::getLogicalOrResultType(node, currentOperand, rhsOperand)}; |
| 182 | } | ||
| 183 | |||
| 184 |
1/2✓ Branch 32 → 33 taken 2143 times.
✗ Branch 32 → 46 not taken.
|
2143 | node->setEvaluatedSymbolType(currentOperand.type, manIdx); |
| 185 |
1/2✓ Branch 33 → 34 taken 2143 times.
✗ Branch 33 → 46 not taken.
|
2143 | return currentOperand; |
| 186 | } | ||
| 187 | |||
| 188 | 1201 | 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 1201 times.
|
1201 | if (node->operands.size() == 1) |
| 191 | ✗ | return visit(node->operands.front()); | |
| 192 | |||
| 193 | // Visit leftmost operand | ||
| 194 |
2/4✓ Branch 8 → 9 taken 1201 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 1201 times.
✗ Branch 9 → 37 not taken.
|
1201 | auto currentOperand = std::any_cast<ExprResult>(visit(node->operands[0])); |
| 195 |
2/8✓ Branch 11 → 12 taken 1201 times.
✗ Branch 11 → 46 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 1201 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 40 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 40 not taken.
|
1201 | HANDLE_UNRESOLVED_TYPE_ER(currentOperand.type) |
| 196 | |||
| 197 | // Loop through all remaining operands | ||
| 198 |
2/2✓ Branch 31 → 18 taken 1622 times.
✓ Branch 31 → 32 taken 1201 times.
|
2823 | for (size_t i = 1; i < node->operands.size(); i++) { |
| 199 |
2/4✓ Branch 19 → 20 taken 1622 times.
✗ Branch 19 → 43 not taken.
✓ Branch 20 → 21 taken 1622 times.
✗ Branch 20 → 41 not taken.
|
1622 | auto rhsOperand = std::any_cast<ExprResult>(visit(node->operands[i])); |
| 200 |
2/8✓ Branch 22 → 23 taken 1622 times.
✗ Branch 22 → 45 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 1622 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 44 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 44 not taken.
|
1622 | HANDLE_UNRESOLVED_TYPE_ER(rhsOperand.type) |
| 201 |
1/2✓ Branch 28 → 29 taken 1622 times.
✗ Branch 28 → 45 not taken.
|
1622 | currentOperand = {OpRuleManager::getLogicalAndResultType(node, currentOperand, rhsOperand)}; |
| 202 | } | ||
| 203 | |||
| 204 |
1/2✓ Branch 32 → 33 taken 1201 times.
✗ Branch 32 → 46 not taken.
|
1201 | node->setEvaluatedSymbolType(currentOperand.type, manIdx); |
| 205 |
1/2✓ Branch 33 → 34 taken 1201 times.
✗ Branch 33 → 46 not taken.
|
1201 | return currentOperand; |
| 206 | } | ||
| 207 | |||
| 208 | 305 | 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 305 times.
|
305 | if (node->operands.size() == 1) |
| 211 | ✗ | return visit(node->operands.front()); | |
| 212 | |||
| 213 | // Visit leftmost operand | ||
| 214 |
2/4✓ Branch 8 → 9 taken 305 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 305 times.
✗ Branch 9 → 37 not taken.
|
305 | auto currentOperand = std::any_cast<ExprResult>(visit(node->operands[0])); |
| 215 |
2/8✓ Branch 11 → 12 taken 305 times.
✗ Branch 11 → 46 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 305 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 40 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 40 not taken.
|
305 | HANDLE_UNRESOLVED_TYPE_ER(currentOperand.type) |
| 216 | |||
| 217 | // Loop through all remaining operands | ||
| 218 |
2/2✓ Branch 31 → 18 taken 308 times.
✓ Branch 31 → 32 taken 304 times.
|
612 | for (size_t i = 1; i < node->operands.size(); i++) { |
| 219 |
2/4✓ Branch 19 → 20 taken 308 times.
✗ Branch 19 → 43 not taken.
✓ Branch 20 → 21 taken 308 times.
✗ Branch 20 → 41 not taken.
|
308 | auto rhsOperand = std::any_cast<ExprResult>(visit(node->operands[i])); |
| 220 |
2/8✓ Branch 22 → 23 taken 308 times.
✗ Branch 22 → 45 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 308 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 44 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 44 not taken.
|
308 | HANDLE_UNRESOLVED_TYPE_ER(rhsOperand.type) |
| 221 |
2/2✓ Branch 28 → 29 taken 307 times.
✓ Branch 28 → 45 taken 1 time.
|
308 | currentOperand = opRuleManager.getBitwiseOrResultType(node, currentOperand, rhsOperand, i - 1); |
| 222 | } | ||
| 223 | |||
| 224 |
1/2✓ Branch 32 → 33 taken 304 times.
✗ Branch 32 → 46 not taken.
|
304 | node->setEvaluatedSymbolType(currentOperand.type, manIdx); |
| 225 |
1/2✓ Branch 33 → 34 taken 304 times.
✗ Branch 33 → 46 not taken.
|
304 | return currentOperand; |
| 226 | } | ||
| 227 | |||
| 228 | 40 | 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 40 times.
|
40 | if (node->operands.size() == 1) |
| 231 | ✗ | return visit(node->operands.front()); | |
| 232 | |||
| 233 | // Visit leftmost operand | ||
| 234 |
2/4✓ Branch 8 → 9 taken 40 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 40 times.
✗ Branch 9 → 37 not taken.
|
40 | auto currentOperand = std::any_cast<ExprResult>(visit(node->operands[0])); |
| 235 |
2/8✓ Branch 11 → 12 taken 40 times.
✗ Branch 11 → 46 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 40 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 40 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 40 not taken.
|
40 | HANDLE_UNRESOLVED_TYPE_ER(currentOperand.type) |
| 236 | |||
| 237 | // Loop through all remaining operands | ||
| 238 |
2/2✓ Branch 31 → 18 taken 43 times.
✓ Branch 31 → 32 taken 40 times.
|
83 | for (size_t i = 1; i < node->operands.size(); i++) { |
| 239 |
2/4✓ Branch 19 → 20 taken 43 times.
✗ Branch 19 → 43 not taken.
✓ Branch 20 → 21 taken 43 times.
✗ Branch 20 → 41 not taken.
|
43 | auto rhsOperand = std::any_cast<ExprResult>(visit(node->operands[i])); |
| 240 |
2/8✓ Branch 22 → 23 taken 43 times.
✗ Branch 22 → 45 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 43 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 44 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 44 not taken.
|
43 | HANDLE_UNRESOLVED_TYPE_ER(rhsOperand.type) |
| 241 |
1/2✓ Branch 28 → 29 taken 43 times.
✗ Branch 28 → 45 not taken.
|
43 | currentOperand = opRuleManager.getBitwiseXorResultType(node, currentOperand, rhsOperand, i - 1); |
| 242 | } | ||
| 243 | |||
| 244 |
1/2✓ Branch 32 → 33 taken 40 times.
✗ Branch 32 → 46 not taken.
|
40 | node->setEvaluatedSymbolType(currentOperand.type, manIdx); |
| 245 |
1/2✓ Branch 33 → 34 taken 40 times.
✗ Branch 33 → 46 not taken.
|
40 | return currentOperand; |
| 246 | } | ||
| 247 | |||
| 248 | 70 | 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 70 times.
|
70 | if (node->operands.size() == 1) |
| 251 | ✗ | return visit(node->operands.front()); | |
| 252 | |||
| 253 | // Visit leftmost operand | ||
| 254 |
2/4✓ Branch 8 → 9 taken 70 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 70 times.
✗ Branch 9 → 37 not taken.
|
70 | auto currentOperand = std::any_cast<ExprResult>(visit(node->operands[0])); |
| 255 |
2/8✓ Branch 11 → 12 taken 70 times.
✗ Branch 11 → 46 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 70 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 40 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 40 not taken.
|
70 | HANDLE_UNRESOLVED_TYPE_ER(currentOperand.type) |
| 256 | |||
| 257 | // Loop through all remaining operands | ||
| 258 |
2/2✓ Branch 31 → 18 taken 73 times.
✓ Branch 31 → 32 taken 70 times.
|
143 | for (size_t i = 1; i < node->operands.size(); i++) { |
| 259 |
2/4✓ Branch 19 → 20 taken 73 times.
✗ Branch 19 → 43 not taken.
✓ Branch 20 → 21 taken 73 times.
✗ Branch 20 → 41 not taken.
|
73 | auto rhsOperand = std::any_cast<ExprResult>(visit(node->operands[i])); |
| 260 |
2/8✓ Branch 22 → 23 taken 73 times.
✗ Branch 22 → 45 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 73 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 44 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 44 not taken.
|
73 | HANDLE_UNRESOLVED_TYPE_ER(rhsOperand.type) |
| 261 |
1/2✓ Branch 28 → 29 taken 73 times.
✗ Branch 28 → 45 not taken.
|
73 | currentOperand = opRuleManager.getBitwiseAndResultType(node, currentOperand, rhsOperand, i - 1); |
| 262 | } | ||
| 263 | |||
| 264 |
1/2✓ Branch 32 → 33 taken 70 times.
✗ Branch 32 → 46 not taken.
|
70 | node->setEvaluatedSymbolType(currentOperand.type, manIdx); |
| 265 |
1/2✓ Branch 33 → 34 taken 70 times.
✗ Branch 33 → 46 not taken.
|
70 | return currentOperand; |
| 266 | } | ||
| 267 | |||
| 268 | 18041 | 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 18041 times.
|
18041 | 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 18041 times.
✗ Branch 8 → 58 not taken.
✓ Branch 9 → 10 taken 18041 times.
✗ Branch 9 → 56 not taken.
|
18041 | const auto rhs = std::any_cast<ExprResult>(visit(node->operands[1])); |
| 275 |
2/8✓ Branch 11 → 12 taken 18041 times.
✗ Branch 11 → 73 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 18041 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 59 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 59 not taken.
|
18041 | HANDLE_UNRESOLVED_TYPE_ER(rhs.type) |
| 276 |
2/4✓ Branch 18 → 19 taken 18041 times.
✗ Branch 18 → 62 not taken.
✓ Branch 19 → 20 taken 18041 times.
✗ Branch 19 → 60 not taken.
|
18041 | const auto lhs = std::any_cast<ExprResult>(visit(node->operands[0])); |
| 277 |
2/8✓ Branch 21 → 22 taken 18041 times.
✗ Branch 21 → 73 not taken.
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 27 taken 18041 times.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 63 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 63 not taken.
|
18041 | 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 18041 times.
✗ Branch 27 → 73 not taken.
✓ Branch 28 → 29 taken 368 times.
✓ Branch 28 → 36 taken 17673 times.
✓ Branch 29 → 30 taken 368 times.
✗ Branch 29 → 73 not taken.
✓ Branch 30 → 31 taken 367 times.
✓ Branch 30 → 36 taken 1 time.
✓ Branch 31 → 32 taken 367 times.
✗ Branch 31 → 73 not taken.
✓ Branch 34 → 35 taken 367 times.
✗ Branch 34 → 36 not taken.
✓ Branch 37 → 38 taken 367 times.
✓ Branch 37 → 39 taken 17674 times.
|
18408 | if (lhs.type.is(TY_STRING) && rhs.type.is(TY_STRING) && !sourceFile->isStringRT()) |
| 281 |
1/2✓ Branch 38 → 39 taken 367 times.
✗ Branch 38 → 73 not taken.
|
367 | sourceFile->requestRuntimeModule(STRING_RT); |
| 282 | |||
| 283 | // Check operator | ||
| 284 | 18041 | ExprResult result; | |
| 285 |
2/2✓ Branch 39 → 40 taken 14248 times.
✓ Branch 39 → 41 taken 3793 times.
|
18041 | if (node->op == EqualityExprNode::EqualityOp::OP_EQUAL) // Operator was equal |
| 286 |
2/2✓ Branch 40 → 51 taken 14247 times.
✓ Branch 40 → 73 taken 1 time.
|
14248 | result = opRuleManager.getEqualResultType(node, lhs, rhs); |
| 287 |
1/2✓ Branch 41 → 42 taken 3793 times.
✗ Branch 41 → 43 not taken.
|
3793 | else if (node->op == EqualityExprNode::EqualityOp::OP_NOT_EQUAL) // Operator was not equal |
| 288 |
1/2✓ Branch 42 → 51 taken 3793 times.
✗ Branch 42 → 73 not taken.
|
3793 | 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 18040 times.
✗ Branch 51 → 73 not taken.
|
18040 | node->setEvaluatedSymbolType(result.type, manIdx); |
| 293 |
1/2✓ Branch 52 → 53 taken 18040 times.
✗ Branch 52 → 73 not taken.
|
18040 | return result; |
| 294 | } | ||
| 295 | |||
| 296 | 9928 | 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 9928 times.
|
9928 | 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 9928 times.
✗ Branch 8 → 55 not taken.
✓ Branch 9 → 10 taken 9928 times.
✗ Branch 9 → 53 not taken.
|
9928 | const auto rhs = std::any_cast<ExprResult>(visit(node->operands[1])); |
| 303 |
5/8✓ Branch 11 → 12 taken 9928 times.
✗ Branch 11 → 75 not taken.
✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 17 taken 9927 times.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 56 not taken.
✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 56 not taken.
|
9929 | HANDLE_UNRESOLVED_TYPE_ER(rhs.type) |
| 304 |
2/4✓ Branch 18 → 19 taken 9927 times.
✗ Branch 18 → 59 not taken.
✓ Branch 19 → 20 taken 9927 times.
✗ Branch 19 → 57 not taken.
|
9927 | const auto lhs = std::any_cast<ExprResult>(visit(node->operands[0])); |
| 305 |
2/8✓ Branch 21 → 22 taken 9927 times.
✗ Branch 21 → 75 not taken.
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 27 taken 9927 times.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 60 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 60 not taken.
|
9927 | HANDLE_UNRESOLVED_TYPE_ER(lhs.type) |
| 306 | |||
| 307 | // Check operator | ||
| 308 | 9927 | QualType resultType; | |
| 309 |
2/2✓ Branch 27 → 28 taken 4791 times.
✓ Branch 27 → 30 taken 5136 times.
|
9927 | if (node->op == RelationalExprNode::RelationalOp::OP_LESS) // Operator was less |
| 310 |
1/2✓ Branch 28 → 29 taken 4791 times.
✗ Branch 28 → 61 not taken.
|
4791 | resultType = OpRuleManager::getLessResultType(node, lhs, rhs); |
| 311 |
2/2✓ Branch 30 → 31 taken 1739 times.
✓ Branch 30 → 33 taken 3397 times.
|
5136 | else if (node->op == RelationalExprNode::RelationalOp::OP_GREATER) // Operator was greater |
| 312 |
2/2✓ Branch 31 → 32 taken 1738 times.
✓ Branch 31 → 62 taken 1 time.
|
1739 | resultType = OpRuleManager::getGreaterResultType(node, lhs, rhs); |
| 313 |
2/2✓ Branch 33 → 34 taken 1240 times.
✓ Branch 33 → 36 taken 2157 times.
|
3397 | else if (node->op == RelationalExprNode::RelationalOp::OP_LESS_EQUAL) // Operator was less equal |
| 314 |
1/2✓ Branch 34 → 35 taken 1240 times.
✗ Branch 34 → 63 not taken.
|
1240 | resultType = OpRuleManager::getLessEqualResultType(node, lhs, rhs); |
| 315 |
1/2✓ Branch 36 → 37 taken 2157 times.
✗ Branch 36 → 39 not taken.
|
2157 | else if (node->op == RelationalExprNode::RelationalOp::OP_GREATER_EQUAL) // Operator was greater equal |
| 316 |
1/2✓ Branch 37 → 38 taken 2157 times.
✗ Branch 37 → 64 not taken.
|
2157 | 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 9926 times.
✗ Branch 47 → 74 not taken.
✓ Branch 48 → 49 taken 9926 times.
✗ Branch 48 → 74 not taken.
|
19852 | return ExprResult{node->setEvaluatedSymbolType(resultType, manIdx)}; |
| 321 | } | ||
| 322 | |||
| 323 | 1475 | 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 1475 times.
|
1475 | if (node->operands.size() == 1) |
| 326 | ✗ | return visit(node->operands.front()); | |
| 327 | |||
| 328 | // Visit leftmost operand | ||
| 329 |
2/4✓ Branch 8 → 9 taken 1475 times.
✗ Branch 8 → 53 not taken.
✓ Branch 9 → 10 taken 1475 times.
✗ Branch 9 → 51 not taken.
|
1475 | auto currentResult = std::any_cast<ExprResult>(visit(node->operands[0])); |
| 330 |
2/8✓ Branch 11 → 12 taken 1475 times.
✗ Branch 11 → 69 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 1475 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 54 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 54 not taken.
|
1475 | HANDLE_UNRESOLVED_TYPE_ER(currentResult.type) |
| 331 | |||
| 332 | // Loop through remaining operands | ||
| 333 |
2/2✓ Branch 45 → 18 taken 2303 times.
✓ Branch 45 → 46 taken 1475 times.
|
3778 | for (size_t i = 0; i < node->opQueue.size(); i++) { |
| 334 |
2/4✓ Branch 19 → 20 taken 2303 times.
✗ Branch 19 → 57 not taken.
✓ Branch 20 → 21 taken 2303 times.
✗ Branch 20 → 55 not taken.
|
2303 | auto operandResult = std::any_cast<ExprResult>(visit(node->operands[i + 1])); |
| 335 |
2/8✓ Branch 22 → 23 taken 2303 times.
✗ Branch 22 → 68 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 2303 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 58 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 58 not taken.
|
2303 | HANDLE_UNRESOLVED_TYPE_ER(operandResult.type) |
| 336 | |||
| 337 | // Check operator | ||
| 338 |
1/2✓ Branch 28 → 29 taken 2303 times.
✗ Branch 28 → 68 not taken.
|
2303 | const ShiftExprNode::ShiftOp &op = node->opQueue.front().first; |
| 339 |
2/2✓ Branch 29 → 30 taken 2100 times.
✓ Branch 29 → 31 taken 203 times.
|
2303 | if (op == ShiftExprNode::ShiftOp::OP_SHIFT_LEFT) |
| 340 |
1/2✓ Branch 30 → 41 taken 2100 times.
✗ Branch 30 → 68 not taken.
|
2100 | currentResult = opRuleManager.getShiftLeftResultType(node, currentResult, operandResult, i); |
| 341 |
1/2✓ Branch 31 → 32 taken 203 times.
✗ Branch 31 → 33 not taken.
|
203 | else if (op == ShiftExprNode::ShiftOp::OP_SHIFT_RIGHT) |
| 342 |
1/2✓ Branch 32 → 41 taken 203 times.
✗ Branch 32 → 68 not taken.
|
203 | 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 2303 times.
✗ Branch 41 → 68 not taken.
|
2303 | node->opQueue.emplace(op, currentResult.type); |
| 348 |
1/2✓ Branch 42 → 43 taken 2303 times.
✗ Branch 42 → 68 not taken.
|
2303 | node->opQueue.pop(); |
| 349 | } | ||
| 350 | |||
| 351 |
1/2✓ Branch 46 → 47 taken 1475 times.
✗ Branch 46 → 69 not taken.
|
1475 | node->setEvaluatedSymbolType(currentResult.type, manIdx); |
| 352 |
1/2✓ Branch 47 → 48 taken 1475 times.
✗ Branch 47 → 69 not taken.
|
1475 | return currentResult; |
| 353 | } | ||
| 354 | |||
| 355 | 9469 | 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 9469 times.
|
9469 | if (node->operands.size() == 1) |
| 358 | ✗ | return visit(node->operands.front()); | |
| 359 | |||
| 360 | // Visit leftmost operand | ||
| 361 |
2/4✓ Branch 8 → 9 taken 9469 times.
✗ Branch 8 → 53 not taken.
✓ Branch 9 → 10 taken 9469 times.
✗ Branch 9 → 51 not taken.
|
9469 | auto currentResult = std::any_cast<ExprResult>(visit(node->operands[0])); |
| 362 |
2/8✓ Branch 11 → 12 taken 9469 times.
✗ Branch 11 → 69 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 9469 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 54 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 54 not taken.
|
9469 | HANDLE_UNRESOLVED_TYPE_ER(currentResult.type) |
| 363 | |||
| 364 | // Loop through remaining operands | ||
| 365 |
2/2✓ Branch 45 → 18 taken 10831 times.
✓ Branch 45 → 46 taken 9468 times.
|
20299 | for (size_t i = 0; i < node->opQueue.size(); i++) { |
| 366 |
2/4✓ Branch 19 → 20 taken 10831 times.
✗ Branch 19 → 57 not taken.
✓ Branch 20 → 21 taken 10831 times.
✗ Branch 20 → 55 not taken.
|
10831 | auto operandResult = std::any_cast<ExprResult>(visit(node->operands[i + 1])); |
| 367 |
2/8✓ Branch 22 → 23 taken 10831 times.
✗ Branch 22 → 68 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 10831 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 58 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 58 not taken.
|
10831 | HANDLE_UNRESOLVED_TYPE_ER(operandResult.type) |
| 368 | |||
| 369 | // Check operator | ||
| 370 |
1/2✓ Branch 28 → 29 taken 10831 times.
✗ Branch 28 → 68 not taken.
|
10831 | const AdditiveExprNode::AdditiveOp &op = node->opQueue.front().first; |
| 371 |
2/2✓ Branch 29 → 30 taken 6872 times.
✓ Branch 29 → 31 taken 3959 times.
|
10831 | if (op == AdditiveExprNode::AdditiveOp::OP_PLUS) |
| 372 |
2/2✓ Branch 30 → 41 taken 6871 times.
✓ Branch 30 → 68 taken 1 time.
|
6872 | currentResult = opRuleManager.getPlusResultType(node, currentResult, operandResult, i); |
| 373 |
1/2✓ Branch 31 → 32 taken 3959 times.
✗ Branch 31 → 33 not taken.
|
3959 | else if (op == AdditiveExprNode::AdditiveOp::OP_MINUS) |
| 374 |
1/2✓ Branch 32 → 41 taken 3959 times.
✗ Branch 32 → 68 not taken.
|
3959 | 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 10830 times.
✗ Branch 41 → 68 not taken.
|
10830 | node->opQueue.emplace(op, currentResult.type); |
| 380 |
1/2✓ Branch 42 → 43 taken 10830 times.
✗ Branch 42 → 68 not taken.
|
10830 | node->opQueue.pop(); |
| 381 | } | ||
| 382 | |||
| 383 |
1/2✓ Branch 46 → 47 taken 9468 times.
✗ Branch 46 → 69 not taken.
|
9468 | node->setEvaluatedSymbolType(currentResult.type, manIdx); |
| 384 |
1/2✓ Branch 47 → 48 taken 9468 times.
✗ Branch 47 → 69 not taken.
|
9468 | return currentResult; |
| 385 | } | ||
| 386 | |||
| 387 | 2793 | 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 2793 times.
|
2793 | if (node->operands.size() == 1) |
| 390 | ✗ | return visit(node->operands.front()); | |
| 391 | |||
| 392 | // Visit leftmost operand | ||
| 393 |
2/4✓ Branch 8 → 9 taken 2793 times.
✗ Branch 8 → 55 not taken.
✓ Branch 9 → 10 taken 2793 times.
✗ Branch 9 → 53 not taken.
|
2793 | auto currentResult = std::any_cast<ExprResult>(visit(node->operands[0])); |
| 394 |
2/8✓ Branch 11 → 12 taken 2793 times.
✗ Branch 11 → 71 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 2793 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 56 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 56 not taken.
|
2793 | HANDLE_UNRESOLVED_TYPE_ER(currentResult.type) |
| 395 | // Loop through remaining operands | ||
| 396 |
2/2✓ Branch 47 → 18 taken 2847 times.
✓ Branch 47 → 48 taken 2792 times.
|
5639 | for (size_t i = 0; i < node->opQueue.size(); i++) { |
| 397 |
2/4✓ Branch 19 → 20 taken 2847 times.
✗ Branch 19 → 59 not taken.
✓ Branch 20 → 21 taken 2847 times.
✗ Branch 20 → 57 not taken.
|
2847 | auto operandResult = std::any_cast<ExprResult>(visit(node->operands[i + 1])); |
| 398 |
2/8✓ Branch 22 → 23 taken 2847 times.
✗ Branch 22 → 70 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 2847 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 60 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 60 not taken.
|
2847 | HANDLE_UNRESOLVED_TYPE_ER(operandResult.type) |
| 399 | |||
| 400 | // Check operator | ||
| 401 |
1/2✓ Branch 28 → 29 taken 2847 times.
✗ Branch 28 → 70 not taken.
|
2847 | const MultiplicativeExprNode::MultiplicativeOp &op = node->opQueue.front().first; |
| 402 |
2/2✓ Branch 29 → 30 taken 2196 times.
✓ Branch 29 → 31 taken 651 times.
|
2847 | if (op == MultiplicativeExprNode::MultiplicativeOp::OP_MUL) |
| 403 |
2/2✓ Branch 30 → 43 taken 2195 times.
✓ Branch 30 → 70 taken 1 time.
|
2196 | currentResult = opRuleManager.getMulResultType(node, currentResult, operandResult, i); |
| 404 |
2/2✓ Branch 31 → 32 taken 521 times.
✓ Branch 31 → 33 taken 130 times.
|
651 | else if (op == MultiplicativeExprNode::MultiplicativeOp::OP_DIV) |
| 405 |
1/2✓ Branch 32 → 43 taken 521 times.
✗ Branch 32 → 70 not taken.
|
521 | currentResult = opRuleManager.getDivResultType(node, currentResult, operandResult, i); |
| 406 |
1/2✓ Branch 33 → 34 taken 130 times.
✗ Branch 33 → 35 not taken.
|
130 | else if (op == MultiplicativeExprNode::MultiplicativeOp::OP_REM) |
| 407 |
1/2✓ Branch 34 → 43 taken 130 times.
✗ Branch 34 → 70 not taken.
|
130 | 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 2846 times.
✗ Branch 43 → 70 not taken.
|
2846 | node->opQueue.emplace(op, currentResult.type); |
| 413 |
1/2✓ Branch 44 → 45 taken 2846 times.
✗ Branch 44 → 70 not taken.
|
2846 | node->opQueue.pop(); |
| 414 | } | ||
| 415 | |||
| 416 |
1/2✓ Branch 48 → 49 taken 2792 times.
✗ Branch 48 → 71 not taken.
|
2792 | node->setEvaluatedSymbolType(currentResult.type, manIdx); |
| 417 |
1/2✓ Branch 49 → 50 taken 2792 times.
✗ Branch 49 → 71 not taken.
|
2792 | return currentResult; |
| 418 | } | ||
| 419 | |||
| 420 | 8644 | std::any TypeChecker::visitCastExpr(CastExprNode *node) { | |
| 421 | // Check if cast is applied | ||
| 422 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 8644 times.
|
8644 | if (!node->isCast) |
| 423 | ✗ | return visit(node->prefixUnaryExpr); | |
| 424 | |||
| 425 | // Visit destination type | ||
| 426 |
2/4✓ Branch 5 → 6 taken 8644 times.
✗ Branch 5 → 49 not taken.
✓ Branch 6 → 7 taken 8644 times.
✗ Branch 6 → 47 not taken.
|
8644 | const auto dstType = std::any_cast<QualType>(visit(node->dataType)); |
| 427 |
2/8✓ Branch 8 → 9 taken 8644 times.
✗ Branch 8 → 65 not taken.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 14 taken 8644 times.
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 50 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 50 not taken.
|
8644 | HANDLE_UNRESOLVED_TYPE_ER(dstType) |
| 428 | // Visit source type | ||
| 429 |
2/4✓ Branch 14 → 15 taken 8644 times.
✗ Branch 14 → 53 not taken.
✓ Branch 15 → 16 taken 8644 times.
✗ Branch 15 → 51 not taken.
|
8644 | const auto src = std::any_cast<ExprResult>(visit(node->assignExpr)); |
| 430 |
2/8✓ Branch 17 → 18 taken 8644 times.
✗ Branch 17 → 65 not taken.
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 23 taken 8644 times.
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 54 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 54 not taken.
|
8644 | HANDLE_UNRESOLVED_TYPE_ER(src.type) |
| 431 | |||
| 432 | // Check for identity cast | ||
| 433 |
3/4✓ Branch 23 → 24 taken 8644 times.
✗ Branch 23 → 65 not taken.
✓ Branch 24 → 25 taken 904 times.
✓ Branch 24 → 34 taken 7740 times.
|
8644 | if (src.type == dstType) { |
| 434 |
2/4✓ Branch 27 → 28 taken 904 times.
✗ Branch 27 → 57 not taken.
✓ Branch 28 → 29 taken 904 times.
✗ Branch 28 → 55 not taken.
|
1808 | 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 904 times.
✗ Branch 31 → 61 not taken.
|
904 | sourceFile->compilerOutput.warnings.push_back(warning); |
| 436 | 904 | } | |
| 437 | |||
| 438 | // Get result type | ||
| 439 |
1/2✓ Branch 34 → 35 taken 8644 times.
✗ Branch 34 → 65 not taken.
|
8644 | const QualType resultType = opRuleManager.getCastResultType(node, dstType, src); |
| 440 | |||
| 441 |
1/2✓ Branch 35 → 36 taken 8644 times.
✗ Branch 35 → 65 not taken.
|
8644 | const bool typesMatch = dstType.matches(src.type, false, true, true); |
| 442 |
1/2✓ Branch 36 → 37 taken 8644 times.
✗ Branch 36 → 65 not taken.
|
8644 | const bool sameContainerType = src.type.isSameContainerTypeAs(dstType); |
| 443 |
4/4✓ Branch 37 → 38 taken 7740 times.
✓ Branch 37 → 39 taken 904 times.
✓ Branch 38 → 39 taken 1727 times.
✓ Branch 38 → 40 taken 6013 times.
|
8644 | SymbolTableEntry *entry = typesMatch || sameContainerType ? src.entry : nullptr; |
| 444 |
2/4✓ Branch 41 → 42 taken 8644 times.
✗ Branch 41 → 64 not taken.
✓ Branch 42 → 43 taken 8644 times.
✗ Branch 42 → 64 not taken.
|
17288 | return ExprResult{node->setEvaluatedSymbolType(resultType, manIdx), entry}; |
| 445 | } | ||
| 446 | |||
| 447 | 7207 | 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 7207 times.
|
7207 | if (node->op == PrefixUnaryExprNode::PrefixUnaryOp::OP_NONE) |
| 450 | ✗ | return visit(node->postfixUnaryExpr); | |
| 451 | |||
| 452 | // Visit the right side | ||
| 453 | 7207 | ExprNode *rhsNode = node->prefixUnaryExpr; | |
| 454 |
2/4✓ Branch 5 → 6 taken 7207 times.
✗ Branch 5 → 58 not taken.
✓ Branch 6 → 7 taken 7207 times.
✗ Branch 6 → 56 not taken.
|
7207 | auto operand = std::any_cast<ExprResult>(visit(rhsNode)); |
| 455 | 7207 | auto [operandType, operandEntry] = operand; | |
| 456 |
5/8✓ Branch 8 → 9 taken 7207 times.
✗ Branch 8 → 79 not taken.
✓ Branch 9 → 10 taken 1 time.
✓ Branch 9 → 14 taken 7206 times.
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 59 not taken.
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 59 not taken.
|
7208 | HANDLE_UNRESOLVED_TYPE_ER(operandType) |
| 457 | // Determine action, based on the given operator | ||
| 458 |
7/8✓ Branch 14 → 15 taken 1004 times.
✓ Branch 14 → 17 taken 14 times.
✓ Branch 14 → 25 taken 16 times.
✓ Branch 14 → 33 taken 4149 times.
✓ Branch 14 → 35 taken 12 times.
✓ Branch 14 → 38 taken 1009 times.
✓ Branch 14 → 40 taken 1002 times.
✗ Branch 14 → 42 not taken.
|
7206 | switch (node->op) { |
| 459 | 1004 | case PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS: | |
| 460 |
1/2✓ Branch 15 → 16 taken 1004 times.
✗ Branch 15 → 60 not taken.
|
1004 | operandType = OpRuleManager::getPrefixMinusResultType(node, operand); |
| 461 | 1004 | break; | |
| 462 | 14 | case PrefixUnaryExprNode::PrefixUnaryOp::OP_PLUS_PLUS: | |
| 463 |
1/2✓ Branch 17 → 18 taken 14 times.
✗ Branch 17 → 61 not taken.
|
14 | operandType = opRuleManager.getPrefixPlusPlusResultType(node, operand); |
| 464 | |||
| 465 |
2/2✓ Branch 18 → 19 taken 11 times.
✓ Branch 18 → 24 taken 3 times.
|
14 | if (operandEntry) { |
| 466 | // In case the lhs is captured, notify the capture about the write access | ||
| 467 |
2/4✓ Branch 19 → 20 taken 11 times.
✗ Branch 19 → 79 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 11 times.
|
11 | 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 11 times.
✗ Branch 22 → 62 not taken.
|
11 | operandEntry->updateState(INITIALIZED, node); |
| 472 | } | ||
| 473 | |||
| 474 | 14 | break; | |
| 475 | 16 | case PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS_MINUS: | |
| 476 |
2/2✓ Branch 25 → 26 taken 15 times.
✓ Branch 25 → 63 taken 1 time.
|
16 | operandType = opRuleManager.getPrefixMinusMinusResultType(node, operand); |
| 477 | |||
| 478 |
2/2✓ Branch 26 → 27 taken 12 times.
✓ Branch 26 → 32 taken 3 times.
|
15 | if (operandEntry) { |
| 479 | // In case the lhs is captured, notify the capture about the write access | ||
| 480 |
2/4✓ Branch 27 → 28 taken 12 times.
✗ Branch 27 → 79 not taken.
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 12 times.
|
12 | 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 12 times.
✗ Branch 30 → 64 not taken.
|
12 | operandEntry->updateState(INITIALIZED, node); |
| 485 | } | ||
| 486 | |||
| 487 | 15 | break; | |
| 488 | 4149 | case PrefixUnaryExprNode::PrefixUnaryOp::OP_NOT: | |
| 489 |
1/2✓ Branch 33 → 34 taken 4149 times.
✗ Branch 33 → 65 not taken.
|
4149 | operandType = OpRuleManager::getPrefixNotResultType(node, operand); |
| 490 | 4149 | 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 | 1009 | case PrefixUnaryExprNode::PrefixUnaryOp::OP_DEREFERENCE: | |
| 498 |
2/2✓ Branch 38 → 39 taken 1008 times.
✓ Branch 38 → 67 taken 1 time.
|
1009 | operandType = OpRuleManager::getPrefixMulResultType(node, operand); |
| 499 | 1008 | break; | |
| 500 | 1002 | case PrefixUnaryExprNode::PrefixUnaryOp::OP_ADDRESS_OF: | |
| 501 |
1/2✓ Branch 40 → 41 taken 1002 times.
✗ Branch 40 → 68 not taken.
|
1002 | operandType = OpRuleManager::getPrefixBitwiseAndResultType(node, operand); |
| 502 | 1002 | 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 7204 times.
✗ Branch 50 → 78 not taken.
✓ Branch 51 → 52 taken 7204 times.
✗ Branch 51 → 78 not taken.
|
14408 | return ExprResult{node->setEvaluatedSymbolType(operandType, manIdx), operandEntry}; |
| 508 | } | ||
| 509 | |||
| 510 | 71224 | 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 71224 times.
|
71224 | if (node->op == PostfixUnaryExprNode::PostfixUnaryOp::OP_NONE) |
| 513 | ✗ | return visit(node->atomicExpr); | |
| 514 | |||
| 515 | // Visit left side | ||
| 516 | 71224 | ExprNode *lhsNode = node->postfixUnaryExpr; | |
| 517 |
2/4✓ Branch 5 → 6 taken 71224 times.
✗ Branch 5 → 211 not taken.
✓ Branch 6 → 7 taken 71224 times.
✗ Branch 6 → 209 not taken.
|
71224 | auto operand = std::any_cast<ExprResult>(visit(lhsNode)); |
| 518 | 71224 | auto [operandType, operandEntry] = operand; | |
| 519 |
5/8✓ Branch 8 → 9 taken 71224 times.
✗ Branch 8 → 316 not taken.
✓ Branch 9 → 10 taken 6 times.
✓ Branch 9 → 14 taken 71218 times.
✓ Branch 10 → 11 taken 6 times.
✗ Branch 10 → 212 not taken.
✓ Branch 11 → 12 taken 6 times.
✗ Branch 11 → 212 not taken.
|
71230 | HANDLE_UNRESOLVED_TYPE_ER(operandType) |
| 520 | |||
| 521 |
4/5✓ Branch 14 → 15 taken 7566 times.
✓ Branch 14 → 101 taken 57842 times.
✓ Branch 14 → 159 taken 5284 times.
✓ Branch 14 → 167 taken 526 times.
✗ Branch 14 → 175 not taken.
|
71218 | switch (node->op) { |
| 522 | 7566 | case PostfixUnaryExprNode::PostfixUnaryOp::OP_SUBSCRIPT: { | |
| 523 | // Visit index assignment | ||
| 524 | 7566 | ExprNode *indexAssignExpr = node->subscriptIndexExpr; | |
| 525 |
2/4✓ Branch 15 → 16 taken 7566 times.
✗ Branch 15 → 215 not taken.
✓ Branch 16 → 17 taken 7566 times.
✗ Branch 16 → 213 not taken.
|
7566 | const auto index = std::any_cast<ExprResult>(visit(indexAssignExpr)); |
| 526 |
2/8✓ Branch 18 → 19 taken 7566 times.
✗ Branch 18 → 258 not taken.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 24 taken 7566 times.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 216 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 216 not taken.
|
7566 | 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 7566 times.
✗ Branch 24 → 217 not taken.
|
7566 | const auto [type, _] = opRuleManager.isOperatorOverloadingFctAvailable<2>(node, OP_FCT_SUBSCRIPT, {operand, index}, 0); |
| 530 |
3/4✓ Branch 25 → 26 taken 7566 times.
✗ Branch 25 → 258 not taken.
✓ Branch 26 → 27 taken 415 times.
✓ Branch 26 → 28 taken 7151 times.
|
7566 | if (!type.is(TY_INVALID)) { |
| 531 | 415 | operandType = type; | |
| 532 | 7564 | break; | |
| 533 | } | ||
| 534 | |||
| 535 |
1/2✓ Branch 28 → 29 taken 7151 times.
✗ Branch 28 → 218 not taken.
|
7151 | operandType = operandType.removeReferenceWrapper(); |
| 536 | |||
| 537 | // Check if the index is of the right type | ||
| 538 |
3/4✓ Branch 29 → 30 taken 7151 times.
✗ Branch 29 → 219 not taken.
✓ Branch 30 → 31 taken 1 time.
✓ Branch 30 → 41 taken 7150 times.
|
7151 | 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 7150 times.
✗ Branch 41 → 227 not taken.
✗ Branch 42 → 43 not taken.
✓ Branch 42 → 52 taken 7150 times.
|
7150 | 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 7150 times.
✗ Branch 52 → 258 not taken.
✓ Branch 53 → 54 taken 5511 times.
✓ Branch 53 → 57 taken 1639 times.
✓ Branch 54 → 55 taken 5511 times.
✗ Branch 54 → 258 not taken.
✗ Branch 55 → 56 not taken.
✓ Branch 55 → 57 taken 5511 times.
✗ Branch 58 → 59 not taken.
✓ Branch 58 → 69 taken 7150 times.
|
7150 | 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 7150 times.
✗ Branch 69 → 258 not taken.
✓ Branch 70 → 71 taken 265 times.
✓ Branch 70 → 76 taken 6885 times.
✓ Branch 71 → 72 taken 265 times.
✗ Branch 71 → 258 not taken.
✓ Branch 72 → 73 taken 190 times.
✓ Branch 72 → 76 taken 75 times.
✓ Branch 77 → 78 taken 102 times.
✓ Branch 77 → 96 taken 7048 times.
|
7340 | if (operandType.isArray() && operandType.getArraySize() != ARRAY_SIZE_UNKNOWN && |
| 554 |
3/4✓ Branch 73 → 74 taken 190 times.
✗ Branch 73 → 258 not taken.
✓ Branch 74 → 75 taken 102 times.
✓ Branch 74 → 76 taken 88 times.
|
190 | indexAssignExpr->hasCompileTimeValue(manIdx)) { |
| 555 |
1/2✓ Branch 78 → 79 taken 102 times.
✗ Branch 78 → 258 not taken.
|
102 | const int32_t constIndex = indexAssignExpr->getCompileTimeValue(manIdx).intValue; |
| 556 |
1/2✓ Branch 79 → 80 taken 102 times.
✗ Branch 79 → 258 not taken.
|
102 | 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 101 times.
|
102 | 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 7149 times.
✗ Branch 96 → 257 not taken.
|
7149 | operandType = operandType.getContained(); |
| 568 | |||
| 569 | // Remove heap qualifier | ||
| 570 | 7149 | operandType.getQualifiers().isHeap = false; | |
| 571 | |||
| 572 | 7149 | break; | |
| 573 | } | ||
| 574 | 57842 | case PostfixUnaryExprNode::PostfixUnaryOp::OP_MEMBER_ACCESS: { | |
| 575 | 57842 | const std::string &fieldName = node->identifier; | |
| 576 | |||
| 577 | // Check if lhs is enum or strobj | ||
| 578 |
1/2✓ Branch 101 → 102 taken 57842 times.
✗ Branch 101 → 286 not taken.
|
57842 | const QualType lhsBaseTy = operandType.autoDeReference(); |
| 579 |
3/4✓ Branch 102 → 103 taken 57842 times.
✗ Branch 102 → 286 not taken.
✓ Branch 103 → 104 taken 1 time.
✓ Branch 103 → 113 taken 57841 times.
|
57842 | 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 57841 times.
✗ Branch 113 → 286 not taken.
|
57841 | const std::string &structName = lhsBaseTy.getSubType(); |
| 584 |
1/2✓ Branch 114 → 115 taken 57841 times.
✗ Branch 114 → 286 not taken.
|
57841 | 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 364 times.
✓ Branch 115 → 120 taken 57477 times.
|
57841 | if (structScope->isGenericScope) { |
| 588 |
1/2✓ Branch 116 → 117 taken 364 times.
✗ Branch 116 → 286 not taken.
|
364 | const Struct *spiceStruct = lhsBaseTy.getStruct(node); |
| 589 |
1/2✗ Branch 117 → 118 not taken.
✓ Branch 117 → 119 taken 364 times.
|
364 | assert(spiceStruct != nullptr); |
| 590 | 364 | structScope = spiceStruct->scope; | |
| 591 | } | ||
| 592 |
1/2✗ Branch 120 → 121 not taken.
✓ Branch 120 → 122 taken 57841 times.
|
57841 | assert(!structScope->isGenericScope); // At this point we always expect a substantiation scope |
| 593 | |||
| 594 | // Get accessed field | ||
| 595 | 57841 | std::vector<size_t> indexPath; | |
| 596 |
1/2✓ Branch 122 → 123 taken 57841 times.
✗ Branch 122 → 284 not taken.
|
57841 | SymbolTableEntry *memberEntry = structScope->symbolTable.lookupInComposedFields(fieldName, indexPath); |
| 597 |
2/2✓ Branch 123 → 124 taken 2 times.
✓ Branch 123 → 135 taken 57839 times.
|
57841 | 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 57839 times.
✗ Branch 135 → 284 not taken.
|
57839 | const QualType memberType = memberEntry->getQualType(); |
| 600 | |||
| 601 | // Check for insufficient visibility | ||
| 602 |
8/14✓ Branch 136 → 137 taken 57839 times.
✗ Branch 136 → 276 not taken.
✓ Branch 137 → 138 taken 1696 times.
✓ Branch 137 → 143 taken 56143 times.
✓ Branch 138 → 139 taken 1696 times.
✗ Branch 138 → 276 not taken.
✓ Branch 139 → 140 taken 1696 times.
✗ Branch 139 → 276 not taken.
✓ Branch 140 → 141 taken 1696 times.
✗ Branch 140 → 276 not taken.
✗ Branch 141 → 142 not taken.
✓ Branch 141 → 143 taken 1696 times.
✗ Branch 144 → 145 not taken.
✓ Branch 144 → 154 taken 57839 times.
|
57839 | 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 | 57839 | memberEntry->used = true; | |
| 607 | |||
| 608 | // Overwrite type and entry of left side with member type and entry | ||
| 609 | 57839 | operandType = memberType; | |
| 610 | 57839 | operandEntry = memberEntry; | |
| 611 | 57839 | break; | |
| 612 |
2/2✓ Branch 156 → 157 taken 2 times.
✓ Branch 156 → 158 taken 57839 times.
|
57841 | } |
| 613 | 5284 | case PostfixUnaryExprNode::PostfixUnaryOp::OP_PLUS_PLUS: { | |
| 614 |
2/2✓ Branch 159 → 160 taken 5282 times.
✓ Branch 159 → 287 taken 2 times.
|
5284 | operandType = opRuleManager.getPostfixPlusPlusResultType(node, operand).type; |
| 615 | |||
| 616 |
2/2✓ Branch 160 → 161 taken 5278 times.
✓ Branch 160 → 166 taken 4 times.
|
5282 | if (operandEntry) { |
| 617 | // In case the lhs is captured, notify the capture about the write access | ||
| 618 |
3/4✓ Branch 161 → 162 taken 5278 times.
✗ Branch 161 → 316 not taken.
✓ Branch 162 → 163 taken 4 times.
✓ Branch 162 → 164 taken 5274 times.
|
5278 | 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 5278 times.
✗ Branch 164 → 288 not taken.
|
5278 | operandEntry->updateState(INITIALIZED, node); |
| 623 | } | ||
| 624 | |||
| 625 | 5282 | break; | |
| 626 | } | ||
| 627 | 526 | case PostfixUnaryExprNode::PostfixUnaryOp::OP_MINUS_MINUS: { | |
| 628 |
1/2✓ Branch 167 → 168 taken 526 times.
✗ Branch 167 → 289 not taken.
|
526 | operandType = opRuleManager.getPostfixMinusMinusResultType(node, operand).type; |
| 629 | |||
| 630 |
2/2✓ Branch 168 → 169 taken 522 times.
✓ Branch 168 → 174 taken 4 times.
|
526 | if (operandEntry) { |
| 631 | // In case the lhs is captured, notify the capture about the write access | ||
| 632 |
2/4✓ Branch 169 → 170 taken 522 times.
✗ Branch 169 → 316 not taken.
✗ Branch 170 → 171 not taken.
✓ Branch 170 → 172 taken 522 times.
|
522 | 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 522 times.
✗ Branch 172 → 290 not taken.
|
522 | operandEntry->updateState(INITIALIZED, node); |
| 637 | } | ||
| 638 | |||
| 639 | 526 | 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 71211 times.
✗ Branch 183 → 316 not taken.
✗ Branch 184 → 185 not taken.
✓ Branch 184 → 203 taken 71211 times.
|
71211 | 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 71211 times.
✗ Branch 203 → 315 not taken.
✓ Branch 204 → 205 taken 71211 times.
✗ Branch 204 → 315 not taken.
|
142422 | return ExprResult{node->setEvaluatedSymbolType(operandType, manIdx), operandEntry}; |
| 651 | } | ||
| 652 | |||
| 653 | 301647 | std::any TypeChecker::visitAtomicExpr(AtomicExprNode *node) { | |
| 654 | // Check if constant | ||
| 655 |
2/2✓ Branch 2 → 3 taken 59289 times.
✓ Branch 2 → 5 taken 242358 times.
|
301647 | if (node->constant) |
| 656 |
1/2✓ Branch 3 → 4 taken 59289 times.
✗ Branch 3 → 218 not taken.
|
59289 | return visit(node->constant); |
| 657 | |||
| 658 | // Check if value | ||
| 659 |
2/2✓ Branch 5 → 6 taken 74815 times.
✓ Branch 5 → 8 taken 167543 times.
|
242358 | if (node->value) |
| 660 |
2/2✓ Branch 6 → 7 taken 74811 times.
✓ Branch 6 → 218 taken 4 times.
|
74815 | return visit(node->value); |
| 661 | |||
| 662 | // Check for assign expression within parentheses | ||
| 663 |
2/2✓ Branch 8 → 9 taken 1202 times.
✓ Branch 8 → 11 taken 166341 times.
|
167543 | if (node->assignExpr) |
| 664 |
2/2✓ Branch 9 → 10 taken 1199 times.
✓ Branch 9 → 218 taken 3 times.
|
1202 | return visit(node->assignExpr); |
| 665 | |||
| 666 | // Identifier (local or global variable access) | ||
| 667 |
1/2✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 166341 times.
|
166341 | assert(!node->fqIdentifier.empty()); |
| 668 | |||
| 669 |
1/2✓ Branch 14 → 15 taken 166341 times.
✗ Branch 14 → 218 not taken.
|
166341 | auto &[entry, accessScope, capture] = node->data.at(manIdx); |
| 670 | 166341 | 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 162440 times.
✓ Branch 16 → 22 taken 3901 times.
|
166341 | if (node->identifierFragments.size() == 1) |
| 674 | 324880 | 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 4040 times.
✓ Branch 22 → 35 taken 162301 times.
|
166341 | if (!entry) { |
| 678 |
1/2✓ Branch 23 → 24 taken 4040 times.
✗ Branch 23 → 218 not taken.
|
4040 | const NameRegistryEntry *registryEntry = sourceFile->getNameRegistryEntry(node->fqIdentifier); |
| 679 |
2/2✓ Branch 24 → 25 taken 1 time.
✓ Branch 24 → 34 taken 4039 times.
|
4040 | 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 | 4039 | entry = registryEntry->targetEntry; | |
| 682 | 4039 | accessScope = registryEntry->targetScope; | |
| 683 | } | ||
| 684 |
1/2✗ Branch 35 → 36 not taken.
✓ Branch 35 → 37 taken 166340 times.
|
166340 | assert(entry != nullptr); |
| 685 | 166340 | entry->used = true; | |
| 686 |
1/2✓ Branch 37 → 38 taken 166340 times.
✗ Branch 37 → 218 not taken.
|
166340 | capture = accessScope->symbolTable.lookupCapture(entry->name); |
| 687 | |||
| 688 |
1/2✓ Branch 38 → 39 taken 166340 times.
✗ Branch 38 → 218 not taken.
|
166340 | const QualType varType = entry->getQualType(); |
| 689 |
5/8✓ Branch 39 → 40 taken 166340 times.
✗ Branch 39 → 218 not taken.
✓ Branch 40 → 41 taken 9 times.
✓ Branch 40 → 45 taken 166331 times.
✓ Branch 41 → 42 taken 9 times.
✗ Branch 41 → 169 not taken.
✓ Branch 42 → 43 taken 9 times.
✗ Branch 42 → 169 not taken.
|
166349 | HANDLE_UNRESOLVED_TYPE_ER(varType) |
| 690 |
3/4✓ Branch 45 → 46 taken 166331 times.
✗ Branch 45 → 218 not taken.
✓ Branch 46 → 47 taken 2 times.
✓ Branch 46 → 56 taken 166329 times.
|
166331 | 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 166329 times.
✗ Branch 56 → 177 not taken.
✓ Branch 57 → 58 taken 127 times.
✓ Branch 57 → 60 taken 166202 times.
✓ Branch 58 → 59 taken 21 times.
✓ Branch 58 → 60 taken 106 times.
✓ Branch 61 → 62 taken 21 times.
✓ Branch 61 → 90 taken 166308 times.
|
166329 | 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 166327 times.
✗ Branch 90 → 218 not taken.
|
166327 | const QualType baseType = varType.getBase(); |
| 708 |
6/10✓ Branch 91 → 92 taken 166327 times.
✗ Branch 91 → 218 not taken.
✓ Branch 92 → 93 taken 4 times.
✓ Branch 92 → 96 taken 166323 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 166327 times.
|
166327 | 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 166326 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 166326 times.
|
166327 | 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 166326 times.
✗ Branch 125 → 218 not taken.
✓ Branch 126 → 127 taken 3350 times.
✓ Branch 126 → 129 taken 162976 times.
✓ Branch 127 → 128 taken 257 times.
✓ Branch 127 → 129 taken 3093 times.
✓ Branch 130 → 131 taken 257 times.
✓ Branch 130 → 144 taken 166069 times.
|
166326 | if (accessScope->isImportedBy(rootScope) && accessScope->type != ScopeType::ENUM) |
| 719 |
5/8✓ Branch 131 → 132 taken 257 times.
✗ Branch 131 → 209 not taken.
✓ Branch 132 → 133 taken 257 times.
✗ Branch 132 → 209 not taken.
✓ Branch 133 → 134 taken 257 times.
✗ Branch 133 → 209 not taken.
✓ Branch 134 → 135 taken 1 time.
✓ Branch 134 → 144 taken 256 times.
|
257 | 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 3896 times.
✓ Branch 144 → 146 taken 162429 times.
|
166325 | if (entry->scope->type == ScopeType::ENUM) |
| 724 | 3896 | accessScope = entry->scope; | |
| 725 | |||
| 726 | // For struct access, use access scope of the struct | ||
| 727 |
3/4✓ Branch 146 → 147 taken 166325 times.
✗ Branch 146 → 218 not taken.
✓ Branch 147 → 148 taken 73020 times.
✓ Branch 147 → 156 taken 93305 times.
|
166325 | if (baseType.is(TY_STRUCT)) { |
| 728 |
1/2✓ Branch 148 → 149 taken 73020 times.
✗ Branch 148 → 218 not taken.
|
73020 | const std::string &structName = baseType.getSubType(); |
| 729 |
1/2✓ Branch 149 → 150 taken 73020 times.
✗ Branch 149 → 218 not taken.
|
73020 | 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 73000 times.
✓ Branch 150 → 152 taken 20 times.
✓ Branch 152 → 153 taken 20 times.
✗ Branch 152 → 218 not taken.
|
73020 | accessScope = nameRegistryEntry != nullptr ? nameRegistryEntry->targetScope : baseType.getBodyScope(); |
| 735 |
1/2✗ Branch 154 → 155 not taken.
✓ Branch 154 → 156 taken 73020 times.
|
73020 | assert(accessScope != nullptr); |
| 736 | } | ||
| 737 | |||
| 738 |
2/4✓ Branch 156 → 157 taken 166325 times.
✗ Branch 156 → 217 not taken.
✓ Branch 157 → 158 taken 166325 times.
✗ Branch 157 → 217 not taken.
|
332650 | return ExprResult{node->setEvaluatedSymbolType(varType, manIdx), entry}; |
| 739 | } | ||
| 740 | |||
| 741 | } // namespace spice::compiler | ||
| 742 |