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 | 13935 | std::any TypeChecker::visitAssignExpr(AssignExprNode *node) { | |
| 14 | // Check if ternary | ||
| 15 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 10 taken 13935 times.
|
13935 | 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 13935 times.
✗ Branch 10 → 116 not taken.
|
13935 | if (node->op != AssignExprNode::AssignOp::OP_NONE) { |
| 23 | // Visit the right side first | ||
| 24 |
2/4✓ Branch 11 → 12 taken 13935 times.
✗ Branch 11 → 131 not taken.
✓ Branch 12 → 13 taken 13935 times.
✗ Branch 12 → 129 not taken.
|
13935 | auto rhs = std::any_cast<ExprResult>(visit(node->rhs)); |
| 25 | 13935 | auto [rhsType, rhsEntry] = rhs; | |
| 26 |
5/8✓ Branch 14 → 15 taken 13935 times.
✗ Branch 14 → 161 not taken.
✓ Branch 15 → 16 taken 1 time.
✓ Branch 15 → 20 taken 13934 times.
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 132 not taken.
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 132 not taken.
|
13936 | HANDLE_UNRESOLVED_TYPE_ER(rhsType) |
| 27 | // Then visit the left side | ||
| 28 |
2/4✓ Branch 20 → 21 taken 13934 times.
✗ Branch 20 → 135 not taken.
✓ Branch 21 → 22 taken 13934 times.
✗ Branch 21 → 133 not taken.
|
13934 | auto lhs = std::any_cast<ExprResult>(visit(node->lhs)); |
| 29 | 13934 | auto [lhsType, lhsVar] = lhs; | |
| 30 |
5/8✓ Branch 23 → 24 taken 13934 times.
✗ Branch 23 → 161 not taken.
✓ Branch 24 → 25 taken 1 time.
✓ Branch 24 → 29 taken 13933 times.
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 136 not taken.
✓ Branch 26 → 27 taken 1 time.
✗ Branch 26 → 136 not taken.
|
13935 | HANDLE_UNRESOLVED_TYPE_ER(lhsType) |
| 31 | |||
| 32 | // Take a look at the operator | ||
| 33 |
2/2✓ Branch 29 → 30 taken 11945 times.
✓ Branch 29 → 72 taken 1988 times.
|
13933 | if (node->op == AssignExprNode::AssignOp::OP_ASSIGN) { |
| 34 |
8/10✓ Branch 30 → 31 taken 11944 times.
✓ Branch 30 → 37 taken 1 time.
✓ Branch 31 → 32 taken 11944 times.
✗ Branch 31 → 148 not taken.
✓ Branch 32 → 33 taken 9343 times.
✓ Branch 32 → 37 taken 2601 times.
✓ Branch 34 → 35 taken 9343 times.
✗ Branch 34 → 148 not taken.
✓ Branch 35 → 36 taken 2801 times.
✓ Branch 35 → 37 taken 6542 times.
|
11945 | const bool isDecl = lhs.entry != nullptr && lhs.entry->isField() && !lhs.entry->getLifecycle().isInitialized(); |
| 35 |
2/2✓ Branch 38 → 39 taken 11944 times.
✓ Branch 38 → 148 taken 1 time.
|
11945 | const auto [assignType, copyCtor] = opRuleManager.getAssignResultType(node, lhs, rhs, isDecl); |
| 36 | 11944 | rhsType = assignType; | |
| 37 | // If the assignment overwrites an already initialized struct by copying a new value into it, the old value | ||
| 38 | // of the lhs must be destructed first. Otherwise its owning members (heap pointers, strings, ...) would leak. | ||
| 39 | // A non-null copy ctor signals that a real copy (not a move/temporary steal or ref assignment) takes place. | ||
| 40 | // 'isInitialized()' is false for declarations, uninitialized fields and moved-from values, so those are skipped. | ||
| 41 | // Unsafe blocks are excluded on purpose: code that manually manages object lifetimes there (e.g. the raw | ||
| 42 | // element shifts in container implementations) relies on assignments not implicitly destructing the lhs. | ||
| 43 |
10/12✓ Branch 41 → 42 taken 69 times.
✓ Branch 41 → 49 taken 11875 times.
✓ Branch 42 → 43 taken 25 times.
✓ Branch 42 → 49 taken 44 times.
✓ Branch 43 → 44 taken 25 times.
✗ Branch 43 → 49 not taken.
✓ Branch 44 → 45 taken 25 times.
✗ Branch 44 → 148 not taken.
✓ Branch 45 → 46 taken 10 times.
✓ Branch 45 → 49 taken 15 times.
✓ Branch 50 → 51 taken 9 times.
✓ Branch 50 → 71 taken 11935 times.
|
11954 | if (copyCtor != nullptr && !isDecl && lhs.entry != nullptr && lhs.entry->isInitialized() && |
| 44 |
3/4✓ Branch 46 → 47 taken 10 times.
✗ Branch 46 → 148 not taken.
✓ Branch 47 → 48 taken 9 times.
✓ Branch 47 → 49 taken 1 time.
|
10 | !currentScope->doesAllowUnsafeOperations()) { |
| 45 |
2/4✓ Branch 51 → 52 taken 9 times.
✗ Branch 51 → 137 not taken.
✓ Branch 52 → 53 taken 9 times.
✗ Branch 52 → 137 not taken.
|
9 | const QualType lhsSType = lhs.type.removeReferenceWrapper().toNonConst(); |
| 46 |
5/10✓ Branch 53 → 54 taken 9 times.
✗ Branch 53 → 147 not taken.
✓ Branch 54 → 55 taken 9 times.
✗ Branch 54 → 58 not taken.
✓ Branch 55 → 56 taken 9 times.
✗ Branch 55 → 147 not taken.
✓ Branch 56 → 57 taken 9 times.
✗ Branch 56 → 58 not taken.
✓ Branch 59 → 60 taken 9 times.
✗ Branch 59 → 70 not taken.
|
9 | if (lhsSType.is(TY_STRUCT) && !lhsSType.isTriviallyDestructible(node)) |
| 47 |
2/4✓ Branch 63 → 64 taken 9 times.
✗ Branch 63 → 140 not taken.
✓ Branch 64 → 65 taken 9 times.
✗ Branch 64 → 138 not taken.
|
27 | node->lhsDtorFct[manIdx] = implicitlyCallStructMethod(lhsSType, DTOR_FUNCTION_NAME, {}, node); |
| 48 | } | ||
| 49 |
2/2✓ Branch 72 → 73 taken 1014 times.
✓ Branch 72 → 75 taken 974 times.
|
1988 | } else if (node->op == AssignExprNode::AssignOp::OP_PLUS_EQUAL) { |
| 50 |
1/2✓ Branch 73 → 74 taken 1014 times.
✗ Branch 73 → 149 not taken.
|
1014 | rhsType = opRuleManager.getPlusEqualResultType(node, lhs, rhs).type; |
| 51 |
2/2✓ Branch 75 → 76 taken 78 times.
✓ Branch 75 → 78 taken 896 times.
|
974 | } else if (node->op == AssignExprNode::AssignOp::OP_MINUS_EQUAL) { |
| 52 |
1/2✓ Branch 76 → 77 taken 78 times.
✗ Branch 76 → 150 not taken.
|
78 | rhsType = opRuleManager.getMinusEqualResultType(node, lhs, rhs).type; |
| 53 |
2/2✓ Branch 78 → 79 taken 140 times.
✓ Branch 78 → 81 taken 756 times.
|
896 | } else if (node->op == AssignExprNode::AssignOp::OP_MUL_EQUAL) { |
| 54 |
1/2✓ Branch 79 → 80 taken 140 times.
✗ Branch 79 → 151 not taken.
|
140 | rhsType = opRuleManager.getMulEqualResultType(node, lhs, rhs).type; |
| 55 |
2/2✓ Branch 81 → 82 taken 102 times.
✓ Branch 81 → 84 taken 654 times.
|
756 | } else if (node->op == AssignExprNode::AssignOp::OP_DIV_EQUAL) { |
| 56 |
1/2✓ Branch 82 → 83 taken 102 times.
✗ Branch 82 → 152 not taken.
|
102 | rhsType = opRuleManager.getDivEqualResultType(node, lhs, rhs).type; |
| 57 |
2/2✓ Branch 84 → 85 taken 41 times.
✓ Branch 84 → 87 taken 613 times.
|
654 | } else if (node->op == AssignExprNode::AssignOp::OP_REM_EQUAL) { |
| 58 |
1/2✓ Branch 85 → 86 taken 41 times.
✗ Branch 85 → 153 not taken.
|
41 | rhsType = opRuleManager.getRemEqualResultType(node, lhs, rhs); |
| 59 |
2/2✓ Branch 87 → 88 taken 12 times.
✓ Branch 87 → 90 taken 601 times.
|
613 | } else if (node->op == AssignExprNode::AssignOp::OP_SHL_EQUAL) { |
| 60 |
1/2✓ Branch 88 → 89 taken 12 times.
✗ Branch 88 → 154 not taken.
|
12 | rhsType = opRuleManager.getSHLEqualResultType(node, lhs, rhs); |
| 61 |
2/2✓ Branch 90 → 91 taken 13 times.
✓ Branch 90 → 93 taken 588 times.
|
601 | } else if (node->op == AssignExprNode::AssignOp::OP_SHR_EQUAL) { |
| 62 |
1/2✓ Branch 91 → 92 taken 13 times.
✗ Branch 91 → 155 not taken.
|
13 | rhsType = opRuleManager.getSHREqualResultType(node, lhs, rhs); |
| 63 |
2/2✓ Branch 93 → 94 taken 17 times.
✓ Branch 93 → 96 taken 571 times.
|
588 | } else if (node->op == AssignExprNode::AssignOp::OP_AND_EQUAL) { |
| 64 |
1/2✓ Branch 94 → 95 taken 17 times.
✗ Branch 94 → 156 not taken.
|
17 | rhsType = opRuleManager.getAndEqualResultType(node, lhs, rhs); |
| 65 |
2/2✓ Branch 96 → 97 taken 13 times.
✓ Branch 96 → 99 taken 558 times.
|
571 | } else if (node->op == AssignExprNode::AssignOp::OP_OR_EQUAL) { |
| 66 |
1/2✓ Branch 97 → 98 taken 13 times.
✗ Branch 97 → 157 not taken.
|
13 | rhsType = opRuleManager.getOrEqualResultType(node, lhs, rhs); |
| 67 |
1/2✓ Branch 99 → 100 taken 558 times.
✗ Branch 99 → 102 not taken.
|
558 | } else if (node->op == AssignExprNode::AssignOp::OP_XOR_EQUAL) { |
| 68 |
1/2✓ Branch 100 → 101 taken 558 times.
✗ Branch 100 → 158 not taken.
|
558 | rhsType = opRuleManager.getXorEqualResultType(node, lhs, rhs); |
| 69 | } | ||
| 70 | |||
| 71 |
1/2✓ Branch 102 → 103 taken 13932 times.
✗ Branch 102 → 111 not taken.
|
13932 | if (lhsVar) { // Variable is involved on the left side |
| 72 | // Perform type inference | ||
| 73 |
3/4✓ Branch 103 → 104 taken 13932 times.
✗ Branch 103 → 161 not taken.
✓ Branch 104 → 105 taken 1 time.
✓ Branch 104 → 106 taken 13931 times.
|
13932 | if (lhsType.is(TY_DYN)) |
| 74 |
1/2✓ Branch 105 → 106 taken 1 time.
✗ Branch 105 → 161 not taken.
|
1 | lhsVar->updateType(rhsType, false); |
| 75 | |||
| 76 | // In case the lhs variable is captured, notify the capture about the write access | ||
| 77 |
3/4✓ Branch 106 → 107 taken 13932 times.
✗ Branch 106 → 161 not taken.
✓ Branch 107 → 108 taken 3 times.
✓ Branch 107 → 109 taken 13929 times.
|
13932 | if (Capture *lhsCapture = currentScope->symbolTable.lookupCapture(lhsVar->name); lhsCapture) |
| 78 |
1/2✓ Branch 108 → 109 taken 3 times.
✗ Branch 108 → 161 not taken.
|
3 | lhsCapture->setAccessType(READ_WRITE); |
| 79 | |||
| 80 | // Update the state of the variable | ||
| 81 |
1/2✓ Branch 109 → 110 taken 13932 times.
✗ Branch 109 → 159 not taken.
|
13932 | lhsVar->updateState(INITIALIZED, node); |
| 82 | } | ||
| 83 | |||
| 84 |
2/4✓ Branch 111 → 112 taken 13932 times.
✗ Branch 111 → 160 not taken.
✓ Branch 112 → 113 taken 13932 times.
✗ Branch 112 → 160 not taken.
|
27864 | return ExprResult{node->setEvaluatedSymbolType(rhsType, manIdx)}; |
| 85 | } | ||
| 86 | |||
| 87 | − | throw CompilerError(UNHANDLED_BRANCH, "AssignExpr fall-through"); // GCOV_EXCL_LINE | |
| 88 | } | ||
| 89 | |||
| 90 | 969 | std::any TypeChecker::visitTernaryExpr(TernaryExprNode *node) { | |
| 91 | // Check if there is a ternary operator applied | ||
| 92 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 969 times.
|
969 | if (!node->falseExpr) |
| 93 | ✗ | return visit(node->condition); | |
| 94 | |||
| 95 | // Visit condition | ||
| 96 |
2/4✓ Branch 5 → 6 taken 969 times.
✗ Branch 5 → 126 not taken.
✓ Branch 6 → 7 taken 969 times.
✗ Branch 6 → 124 not taken.
|
969 | const auto condition = std::any_cast<ExprResult>(visit(node->condition)); |
| 97 |
2/8✓ Branch 8 → 9 taken 969 times.
✗ Branch 8 → 161 not taken.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 14 taken 969 times.
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 127 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 127 not taken.
|
969 | HANDLE_UNRESOLVED_TYPE_ER(condition.type) |
| 98 |
6/10✓ Branch 14 → 15 taken 1 time.
✓ Branch 14 → 16 taken 968 times.
✓ Branch 16 → 17 taken 968 times.
✗ Branch 16 → 128 not taken.
✓ Branch 17 → 18 taken 968 times.
✗ Branch 17 → 128 not taken.
✓ Branch 18 → 19 taken 968 times.
✓ Branch 18 → 20 taken 1 time.
✗ Branch 128 → 129 not taken.
✗ Branch 128 → 130 not taken.
|
969 | const auto trueExpr = node->isShortened ? condition : std::any_cast<ExprResult>(visit(node->trueExpr)); |
| 99 | 969 | const auto [trueType, trueEntry] = trueExpr; | |
| 100 |
2/8✓ Branch 20 → 21 taken 969 times.
✗ Branch 20 → 161 not taken.
✗ Branch 21 → 22 not taken.
✓ Branch 21 → 26 taken 969 times.
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 132 not taken.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 132 not taken.
|
969 | HANDLE_UNRESOLVED_TYPE_ER(trueType) |
| 101 |
2/4✓ Branch 26 → 27 taken 969 times.
✗ Branch 26 → 135 not taken.
✓ Branch 27 → 28 taken 969 times.
✗ Branch 27 → 133 not taken.
|
969 | const auto falseExpr = std::any_cast<ExprResult>(visit(node->falseExpr)); |
| 102 | 969 | const auto [falseType, falseEntry] = falseExpr; | |
| 103 |
2/8✓ Branch 29 → 30 taken 969 times.
✗ Branch 29 → 161 not taken.
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 35 taken 969 times.
✗ Branch 31 → 32 not taken.
✗ Branch 31 → 136 not taken.
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 136 not taken.
|
969 | HANDLE_UNRESOLVED_TYPE_ER(falseType) |
| 104 | |||
| 105 | // Check if the condition evaluates to bool | ||
| 106 |
3/4✓ Branch 35 → 36 taken 969 times.
✗ Branch 35 → 161 not taken.
✓ Branch 36 → 37 taken 1 time.
✓ Branch 36 → 47 taken 968 times.
|
969 | if (!condition.type.is(TY_BOOL)) |
| 107 |
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") |
| 108 | |||
| 109 | // Check if trueType and falseType are matching | ||
| 110 |
1/2✓ Branch 47 → 48 taken 968 times.
✗ Branch 47 → 161 not taken.
|
968 | const QualType trueTypeModified = trueType.removeReferenceWrapper(); |
| 111 |
1/2✓ Branch 48 → 49 taken 968 times.
✗ Branch 48 → 161 not taken.
|
968 | const QualType falseTypeModified = falseType.removeReferenceWrapper(); |
| 112 |
3/4✓ Branch 49 → 50 taken 968 times.
✗ Branch 49 → 161 not taken.
✓ Branch 50 → 51 taken 1 time.
✓ Branch 50 → 66 taken 967 times.
|
968 | if (!trueTypeModified.matches(falseTypeModified, false, true, false)) |
| 113 |
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, |
| 114 | "True and false operands in ternary must be of same data type. Got " + trueType.getName(true) + " and " + | ||
| 115 | falseType.getName(true)) | ||
| 116 | |||
| 117 | // The result type must be a reference if one of true/false branch is of reference type. Otherwise, | ||
| 118 | // the copy ctor is not called correctly | ||
| 119 |
3/4✓ Branch 66 → 67 taken 967 times.
✗ Branch 66 → 161 not taken.
✓ Branch 67 → 68 taken 9 times.
✓ Branch 67 → 69 taken 958 times.
|
967 | QualType resultType = trueType.isRef() ? trueType : falseType; |
| 120 | // Infer the const-ness from the more restrictive operand | ||
| 121 |
7/10✓ Branch 70 → 71 taken 967 times.
✗ Branch 70 → 161 not taken.
✓ Branch 71 → 72 taken 946 times.
✓ Branch 71 → 74 taken 21 times.
✓ Branch 72 → 73 taken 946 times.
✗ Branch 72 → 161 not taken.
✓ Branch 73 → 74 taken 302 times.
✓ Branch 73 → 75 taken 644 times.
✓ Branch 76 → 77 taken 967 times.
✗ Branch 76 → 161 not taken.
|
967 | resultType.makeConst(trueType.isConst() || falseType.isConst()); |
| 122 | |||
| 123 | // If there is an anonymous symbol attached to left or right, remove it, | ||
| 124 | // since the result takes over the ownership of any destructible object. | ||
| 125 | 967 | bool removedAnonymousSymbols = false; | |
| 126 |
2/2✓ Branch 77 → 78 taken 267 times.
✓ Branch 77 → 89 taken 700 times.
|
967 | if (trueEntry) { |
| 127 |
2/2✓ Branch 78 → 79 taken 169 times.
✓ Branch 78 → 81 taken 98 times.
|
267 | if (trueEntry->anonymous) { |
| 128 |
1/2✓ Branch 79 → 80 taken 169 times.
✗ Branch 79 → 161 not taken.
|
169 | currentScope->symbolTable.deleteAnonymous(trueEntry->name); |
| 129 | 169 | removedAnonymousSymbols = true; | |
| 130 |
8/10✓ Branch 81 → 82 taken 98 times.
✗ Branch 81 → 161 not taken.
✓ Branch 82 → 83 taken 90 times.
✓ Branch 82 → 86 taken 8 times.
✓ Branch 83 → 84 taken 90 times.
✗ Branch 83 → 161 not taken.
✓ Branch 84 → 85 taken 9 times.
✓ Branch 84 → 86 taken 81 times.
✓ Branch 87 → 88 taken 9 times.
✓ Branch 87 → 89 taken 89 times.
|
98 | } else if (!trueType.isRef() && !trueType.isTriviallyCopyable(node)) { |
| 131 | 9 | node->trueSideCallsCopyCtor = true; | |
| 132 | } | ||
| 133 | } | ||
| 134 |
2/2✓ Branch 89 → 90 taken 574 times.
✓ Branch 89 → 101 taken 393 times.
|
967 | if (falseEntry) { |
| 135 |
2/2✓ Branch 90 → 91 taken 167 times.
✓ Branch 90 → 93 taken 407 times.
|
574 | if (falseEntry->anonymous) { |
| 136 |
1/2✓ Branch 91 → 92 taken 167 times.
✗ Branch 91 → 161 not taken.
|
167 | currentScope->symbolTable.deleteAnonymous(falseEntry->name); |
| 137 | 167 | removedAnonymousSymbols = true; | |
| 138 |
8/10✓ Branch 93 → 94 taken 407 times.
✗ Branch 93 → 161 not taken.
✓ Branch 94 → 95 taken 395 times.
✓ Branch 94 → 98 taken 12 times.
✓ Branch 95 → 96 taken 395 times.
✗ Branch 95 → 161 not taken.
✓ Branch 96 → 97 taken 8 times.
✓ Branch 96 → 98 taken 387 times.
✓ Branch 99 → 100 taken 8 times.
✓ Branch 99 → 101 taken 399 times.
|
407 | } else if (!falseType.isRef() && !falseType.isTriviallyCopyable(node)) { |
| 139 | 8 | node->falseSideCallsCopyCtor = true; | |
| 140 | } | ||
| 141 | } | ||
| 142 | |||
| 143 | // Create a new anonymous symbol for the result if required | ||
| 144 | 967 | SymbolTableEntry *anonymousSymbol = nullptr; | |
| 145 |
4/4✓ Branch 101 → 102 taken 958 times.
✓ Branch 101 → 103 taken 9 times.
✓ Branch 102 → 103 taken 2 times.
✓ Branch 102 → 104 taken 956 times.
|
967 | const bool calledCopyCtor = node->trueSideCallsCopyCtor || node->falseSideCallsCopyCtor; |
| 146 |
9/10✓ Branch 105 → 106 taken 796 times.
✓ Branch 105 → 109 taken 171 times.
✓ Branch 106 → 107 taken 789 times.
✓ Branch 106 → 109 taken 7 times.
✓ Branch 107 → 108 taken 789 times.
✗ Branch 107 → 161 not taken.
✓ Branch 108 → 109 taken 10 times.
✓ Branch 108 → 110 taken 779 times.
✓ Branch 111 → 112 taken 188 times.
✓ Branch 111 → 114 taken 779 times.
|
967 | if (removedAnonymousSymbols || calledCopyCtor || resultType.isRef()) |
| 147 |
1/2✓ Branch 112 → 113 taken 188 times.
✗ Branch 112 → 161 not taken.
|
188 | anonymousSymbol = currentScope->symbolTable.insertAnonymous(resultType, node); |
| 148 | |||
| 149 | // Look up the copy ctor if at least one side needs it | ||
| 150 |
4/4✓ Branch 114 → 115 taken 958 times.
✓ Branch 114 → 116 taken 9 times.
✓ Branch 115 → 116 taken 2 times.
✓ Branch 115 → 118 taken 956 times.
|
967 | if (node->trueSideCallsCopyCtor || node->falseSideCallsCopyCtor) |
| 151 |
1/2✓ Branch 116 → 117 taken 11 times.
✗ Branch 116 → 161 not taken.
|
11 | node->calledCopyCtor = matchCopyCtor(trueTypeModified, node); |
| 152 | |||
| 153 |
2/4✓ Branch 118 → 119 taken 967 times.
✗ Branch 118 → 160 not taken.
✓ Branch 119 → 120 taken 967 times.
✗ Branch 119 → 160 not taken.
|
1934 | return ExprResult{node->setEvaluatedSymbolType(resultType, manIdx), anonymousSymbol}; |
| 154 | } | ||
| 155 | |||
| 156 | 1485 | std::any TypeChecker::visitLogicalOrExpr(LogicalOrExprNode *node) { | |
| 157 | // Check if a logical or operator is applied | ||
| 158 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 1485 times.
|
1485 | if (node->operands.size() == 1) |
| 159 | ✗ | return visit(node->operands.front()); | |
| 160 | |||
| 161 | // Visit leftmost operand | ||
| 162 |
2/4✓ Branch 8 → 9 taken 1485 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 1485 times.
✗ Branch 9 → 37 not taken.
|
1485 | auto currentOperand = std::any_cast<ExprResult>(visit(node->operands[0])); |
| 163 |
2/8✓ Branch 11 → 12 taken 1485 times.
✗ Branch 11 → 46 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 1485 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 40 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 40 not taken.
|
1485 | HANDLE_UNRESOLVED_TYPE_ER(currentOperand.type) |
| 164 | |||
| 165 | // Loop through all remaining operands | ||
| 166 |
2/2✓ Branch 31 → 18 taken 1993 times.
✓ Branch 31 → 32 taken 1484 times.
|
3477 | for (size_t i = 1; i < node->operands.size(); i++) { |
| 167 |
2/4✓ Branch 19 → 20 taken 1993 times.
✗ Branch 19 → 43 not taken.
✓ Branch 20 → 21 taken 1993 times.
✗ Branch 20 → 41 not taken.
|
1993 | auto rhsOperand = std::any_cast<ExprResult>(visit(node->operands[i])); |
| 168 |
2/8✓ Branch 22 → 23 taken 1993 times.
✗ Branch 22 → 45 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 1993 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 44 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 44 not taken.
|
1993 | HANDLE_UNRESOLVED_TYPE_ER(rhsOperand.type) |
| 169 |
2/2✓ Branch 28 → 29 taken 1992 times.
✓ Branch 28 → 45 taken 1 time.
|
1993 | currentOperand = {OpRuleManager::getLogicalOrResultType(node, currentOperand, rhsOperand)}; |
| 170 | } | ||
| 171 | |||
| 172 |
1/2✓ Branch 32 → 33 taken 1484 times.
✗ Branch 32 → 46 not taken.
|
1484 | node->setEvaluatedSymbolType(currentOperand.type, manIdx); |
| 173 |
1/2✓ Branch 33 → 34 taken 1484 times.
✗ Branch 33 → 46 not taken.
|
1484 | return currentOperand; |
| 174 | } | ||
| 175 | |||
| 176 | 426 | std::any TypeChecker::visitLogicalAndExpr(LogicalAndExprNode *node) { | |
| 177 | // Check if a logical and operator is applied | ||
| 178 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 426 times.
|
426 | if (node->operands.size() == 1) |
| 179 | ✗ | return visit(node->operands.front()); | |
| 180 | |||
| 181 | // Visit leftmost operand | ||
| 182 |
2/4✓ Branch 8 → 9 taken 426 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 426 times.
✗ Branch 9 → 37 not taken.
|
426 | auto currentOperand = std::any_cast<ExprResult>(visit(node->operands[0])); |
| 183 |
2/8✓ Branch 11 → 12 taken 426 times.
✗ Branch 11 → 46 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 426 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 40 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 40 not taken.
|
426 | HANDLE_UNRESOLVED_TYPE_ER(currentOperand.type) |
| 184 | |||
| 185 | // Loop through all remaining operands | ||
| 186 |
2/2✓ Branch 31 → 18 taken 521 times.
✓ Branch 31 → 32 taken 426 times.
|
947 | for (size_t i = 1; i < node->operands.size(); i++) { |
| 187 |
2/4✓ Branch 19 → 20 taken 521 times.
✗ Branch 19 → 43 not taken.
✓ Branch 20 → 21 taken 521 times.
✗ Branch 20 → 41 not taken.
|
521 | auto rhsOperand = std::any_cast<ExprResult>(visit(node->operands[i])); |
| 188 |
2/8✓ Branch 22 → 23 taken 521 times.
✗ Branch 22 → 45 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 521 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 44 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 44 not taken.
|
521 | HANDLE_UNRESOLVED_TYPE_ER(rhsOperand.type) |
| 189 |
1/2✓ Branch 28 → 29 taken 521 times.
✗ Branch 28 → 45 not taken.
|
521 | currentOperand = {OpRuleManager::getLogicalAndResultType(node, currentOperand, rhsOperand)}; |
| 190 | } | ||
| 191 | |||
| 192 |
1/2✓ Branch 32 → 33 taken 426 times.
✗ Branch 32 → 46 not taken.
|
426 | node->setEvaluatedSymbolType(currentOperand.type, manIdx); |
| 193 |
1/2✓ Branch 33 → 34 taken 426 times.
✗ Branch 33 → 46 not taken.
|
426 | return currentOperand; |
| 194 | } | ||
| 195 | |||
| 196 | 186 | std::any TypeChecker::visitBitwiseOrExpr(BitwiseOrExprNode *node) { | |
| 197 | // Check if a bitwise or operator is applied | ||
| 198 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 186 times.
|
186 | if (node->operands.size() == 1) |
| 199 | ✗ | return visit(node->operands.front()); | |
| 200 | |||
| 201 | // Visit leftmost operand | ||
| 202 |
2/4✓ Branch 8 → 9 taken 186 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 186 times.
✗ Branch 9 → 37 not taken.
|
186 | auto currentOperand = std::any_cast<ExprResult>(visit(node->operands[0])); |
| 203 |
2/8✓ Branch 11 → 12 taken 186 times.
✗ Branch 11 → 46 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 186 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 40 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 40 not taken.
|
186 | HANDLE_UNRESOLVED_TYPE_ER(currentOperand.type) |
| 204 | |||
| 205 | // Loop through all remaining operands | ||
| 206 |
2/2✓ Branch 31 → 18 taken 189 times.
✓ Branch 31 → 32 taken 185 times.
|
374 | for (size_t i = 1; i < node->operands.size(); i++) { |
| 207 |
2/4✓ Branch 19 → 20 taken 189 times.
✗ Branch 19 → 43 not taken.
✓ Branch 20 → 21 taken 189 times.
✗ Branch 20 → 41 not taken.
|
189 | auto rhsOperand = std::any_cast<ExprResult>(visit(node->operands[i])); |
| 208 |
2/8✓ Branch 22 → 23 taken 189 times.
✗ Branch 22 → 45 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 189 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 44 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 44 not taken.
|
189 | HANDLE_UNRESOLVED_TYPE_ER(rhsOperand.type) |
| 209 |
2/2✓ Branch 28 → 29 taken 188 times.
✓ Branch 28 → 45 taken 1 time.
|
189 | currentOperand = opRuleManager.getBitwiseOrResultType(node, currentOperand, rhsOperand, i - 1); |
| 210 | } | ||
| 211 | |||
| 212 |
1/2✓ Branch 32 → 33 taken 185 times.
✗ Branch 32 → 46 not taken.
|
185 | node->setEvaluatedSymbolType(currentOperand.type, manIdx); |
| 213 |
1/2✓ Branch 33 → 34 taken 185 times.
✗ Branch 33 → 46 not taken.
|
185 | return currentOperand; |
| 214 | } | ||
| 215 | |||
| 216 | 31 | std::any TypeChecker::visitBitwiseXorExpr(BitwiseXorExprNode *node) { | |
| 217 | // Check if a bitwise xor operator is applied | ||
| 218 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 31 times.
|
31 | if (node->operands.size() == 1) |
| 219 | ✗ | return visit(node->operands.front()); | |
| 220 | |||
| 221 | // Visit leftmost operand | ||
| 222 |
2/4✓ Branch 8 → 9 taken 31 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 31 times.
✗ Branch 9 → 37 not taken.
|
31 | auto currentOperand = std::any_cast<ExprResult>(visit(node->operands[0])); |
| 223 |
2/8✓ Branch 11 → 12 taken 31 times.
✗ Branch 11 → 46 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 31 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 40 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 40 not taken.
|
31 | HANDLE_UNRESOLVED_TYPE_ER(currentOperand.type) |
| 224 | |||
| 225 | // Loop through all remaining operands | ||
| 226 |
2/2✓ Branch 31 → 18 taken 34 times.
✓ Branch 31 → 32 taken 31 times.
|
65 | for (size_t i = 1; i < node->operands.size(); i++) { |
| 227 |
2/4✓ Branch 19 → 20 taken 34 times.
✗ Branch 19 → 43 not taken.
✓ Branch 20 → 21 taken 34 times.
✗ Branch 20 → 41 not taken.
|
34 | auto rhsOperand = std::any_cast<ExprResult>(visit(node->operands[i])); |
| 228 |
2/8✓ Branch 22 → 23 taken 34 times.
✗ Branch 22 → 45 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 34 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 44 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 44 not taken.
|
34 | HANDLE_UNRESOLVED_TYPE_ER(rhsOperand.type) |
| 229 |
1/2✓ Branch 28 → 29 taken 34 times.
✗ Branch 28 → 45 not taken.
|
34 | currentOperand = opRuleManager.getBitwiseXorResultType(node, currentOperand, rhsOperand, i - 1); |
| 230 | } | ||
| 231 | |||
| 232 |
1/2✓ Branch 32 → 33 taken 31 times.
✗ Branch 32 → 46 not taken.
|
31 | node->setEvaluatedSymbolType(currentOperand.type, manIdx); |
| 233 |
1/2✓ Branch 33 → 34 taken 31 times.
✗ Branch 33 → 46 not taken.
|
31 | return currentOperand; |
| 234 | } | ||
| 235 | |||
| 236 | 69 | std::any TypeChecker::visitBitwiseAndExpr(BitwiseAndExprNode *node) { | |
| 237 | // Check if a bitwise and operator is applied | ||
| 238 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 69 times.
|
69 | if (node->operands.size() == 1) |
| 239 | ✗ | return visit(node->operands.front()); | |
| 240 | |||
| 241 | // Visit leftmost operand | ||
| 242 |
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])); |
| 243 |
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) |
| 244 | |||
| 245 | // Loop through all remaining operands | ||
| 246 |
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++) { |
| 247 |
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])); |
| 248 |
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) |
| 249 |
1/2✓ Branch 28 → 29 taken 72 times.
✗ Branch 28 → 45 not taken.
|
72 | currentOperand = opRuleManager.getBitwiseAndResultType(node, currentOperand, rhsOperand, i - 1); |
| 250 | } | ||
| 251 | |||
| 252 |
1/2✓ Branch 32 → 33 taken 69 times.
✗ Branch 32 → 46 not taken.
|
69 | node->setEvaluatedSymbolType(currentOperand.type, manIdx); |
| 253 |
1/2✓ Branch 33 → 34 taken 69 times.
✗ Branch 33 → 46 not taken.
|
69 | return currentOperand; |
| 254 | } | ||
| 255 | |||
| 256 | 10974 | std::any TypeChecker::visitEqualityExpr(EqualityExprNode *node) { | |
| 257 | // Check if at least one equality operator is applied | ||
| 258 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 10974 times.
|
10974 | if (node->operands.size() == 1) |
| 259 | ✗ | return visit(node->operands.front()); | |
| 260 | |||
| 261 | // Visit right side first, then left side | ||
| 262 |
2/4✓ Branch 8 → 9 taken 10974 times.
✗ Branch 8 → 58 not taken.
✓ Branch 9 → 10 taken 10974 times.
✗ Branch 9 → 56 not taken.
|
10974 | const auto rhs = std::any_cast<ExprResult>(visit(node->operands[1])); |
| 263 |
2/8✓ Branch 11 → 12 taken 10974 times.
✗ Branch 11 → 73 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 10974 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 59 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 59 not taken.
|
10974 | HANDLE_UNRESOLVED_TYPE_ER(rhs.type) |
| 264 |
2/4✓ Branch 18 → 19 taken 10974 times.
✗ Branch 18 → 62 not taken.
✓ Branch 19 → 20 taken 10974 times.
✗ Branch 19 → 60 not taken.
|
10974 | const auto lhs = std::any_cast<ExprResult>(visit(node->operands[0])); |
| 265 |
2/8✓ Branch 21 → 22 taken 10974 times.
✗ Branch 21 → 73 not taken.
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 27 taken 10974 times.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 63 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 63 not taken.
|
10974 | HANDLE_UNRESOLVED_TYPE_ER(lhs.type) |
| 266 | |||
| 267 | // Check if we need the string runtime to perform a string comparison | ||
| 268 |
10/14✓ Branch 27 → 28 taken 10974 times.
✗ Branch 27 → 73 not taken.
✓ Branch 28 → 29 taken 268 times.
✓ Branch 28 → 36 taken 10706 times.
✓ Branch 29 → 30 taken 268 times.
✗ Branch 29 → 73 not taken.
✓ Branch 30 → 31 taken 267 times.
✓ Branch 30 → 36 taken 1 time.
✓ Branch 31 → 32 taken 267 times.
✗ Branch 31 → 73 not taken.
✓ Branch 34 → 35 taken 267 times.
✗ Branch 34 → 36 not taken.
✓ Branch 37 → 38 taken 267 times.
✓ Branch 37 → 39 taken 10707 times.
|
11241 | if (lhs.type.is(TY_STRING) && rhs.type.is(TY_STRING) && !sourceFile->isStringRT()) |
| 269 |
1/2✓ Branch 38 → 39 taken 267 times.
✗ Branch 38 → 73 not taken.
|
267 | sourceFile->requestRuntimeModule(STRING_RT); |
| 270 | |||
| 271 | // Check operator | ||
| 272 | 10974 | ExprResult result; | |
| 273 |
2/2✓ Branch 39 → 40 taken 8362 times.
✓ Branch 39 → 41 taken 2612 times.
|
10974 | if (node->op == EqualityExprNode::EqualityOp::OP_EQUAL) // Operator was equal |
| 274 |
2/2✓ Branch 40 → 51 taken 8361 times.
✓ Branch 40 → 73 taken 1 time.
|
8362 | result = opRuleManager.getEqualResultType(node, lhs, rhs); |
| 275 |
1/2✓ Branch 41 → 42 taken 2612 times.
✗ Branch 41 → 43 not taken.
|
2612 | else if (node->op == EqualityExprNode::EqualityOp::OP_NOT_EQUAL) // Operator was not equal |
| 276 |
1/2✓ Branch 42 → 51 taken 2612 times.
✗ Branch 42 → 73 not taken.
|
2612 | result = opRuleManager.getNotEqualResultType(node, lhs, rhs); |
| 277 | else | ||
| 278 | − | throw CompilerError(UNHANDLED_BRANCH, "EqualityExpr fall-through"); // GCOV_EXCL_LINE | |
| 279 | |||
| 280 |
1/2✓ Branch 51 → 52 taken 10973 times.
✗ Branch 51 → 73 not taken.
|
10973 | node->setEvaluatedSymbolType(result.type, manIdx); |
| 281 |
1/2✓ Branch 52 → 53 taken 10973 times.
✗ Branch 52 → 73 not taken.
|
10973 | return result; |
| 282 | } | ||
| 283 | |||
| 284 | 7097 | std::any TypeChecker::visitRelationalExpr(RelationalExprNode *node) { | |
| 285 | // Check if a relational operator is applied | ||
| 286 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 7097 times.
|
7097 | if (node->operands.size() == 1) |
| 287 | ✗ | return visit(node->operands.front()); | |
| 288 | |||
| 289 | // Visit right side first, then left side | ||
| 290 |
2/4✓ Branch 8 → 9 taken 7097 times.
✗ Branch 8 → 55 not taken.
✓ Branch 9 → 10 taken 7097 times.
✗ Branch 9 → 53 not taken.
|
7097 | const auto rhs = std::any_cast<ExprResult>(visit(node->operands[1])); |
| 291 |
5/8✓ Branch 11 → 12 taken 7097 times.
✗ Branch 11 → 75 not taken.
✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 17 taken 7096 times.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 56 not taken.
✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 56 not taken.
|
7098 | HANDLE_UNRESOLVED_TYPE_ER(rhs.type) |
| 292 |
2/4✓ Branch 18 → 19 taken 7096 times.
✗ Branch 18 → 59 not taken.
✓ Branch 19 → 20 taken 7096 times.
✗ Branch 19 → 57 not taken.
|
7096 | const auto lhs = std::any_cast<ExprResult>(visit(node->operands[0])); |
| 293 |
2/8✓ Branch 21 → 22 taken 7096 times.
✗ Branch 21 → 75 not taken.
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 27 taken 7096 times.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 60 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 60 not taken.
|
7096 | HANDLE_UNRESOLVED_TYPE_ER(lhs.type) |
| 294 | |||
| 295 | // Check operator | ||
| 296 | 7096 | QualType resultType; | |
| 297 |
2/2✓ Branch 27 → 28 taken 3336 times.
✓ Branch 27 → 30 taken 3760 times.
|
7096 | if (node->op == RelationalExprNode::RelationalOp::OP_LESS) // Operator was less |
| 298 |
1/2✓ Branch 28 → 29 taken 3336 times.
✗ Branch 28 → 61 not taken.
|
3336 | resultType = OpRuleManager::getLessResultType(node, lhs, rhs); |
| 299 |
2/2✓ Branch 30 → 31 taken 1178 times.
✓ Branch 30 → 33 taken 2582 times.
|
3760 | else if (node->op == RelationalExprNode::RelationalOp::OP_GREATER) // Operator was greater |
| 300 |
2/2✓ Branch 31 → 32 taken 1177 times.
✓ Branch 31 → 62 taken 1 time.
|
1178 | resultType = OpRuleManager::getGreaterResultType(node, lhs, rhs); |
| 301 |
2/2✓ Branch 33 → 34 taken 804 times.
✓ Branch 33 → 36 taken 1778 times.
|
2582 | else if (node->op == RelationalExprNode::RelationalOp::OP_LESS_EQUAL) // Operator was less equal |
| 302 |
1/2✓ Branch 34 → 35 taken 804 times.
✗ Branch 34 → 63 not taken.
|
804 | resultType = OpRuleManager::getLessEqualResultType(node, lhs, rhs); |
| 303 |
1/2✓ Branch 36 → 37 taken 1778 times.
✗ Branch 36 → 39 not taken.
|
1778 | else if (node->op == RelationalExprNode::RelationalOp::OP_GREATER_EQUAL) // Operator was greater equal |
| 304 |
1/2✓ Branch 37 → 38 taken 1778 times.
✗ Branch 37 → 64 not taken.
|
1778 | resultType = OpRuleManager::getGreaterEqualResultType(node, lhs, rhs); |
| 305 | else | ||
| 306 | − | throw CompilerError(UNHANDLED_BRANCH, "RelationalExpr fall-through"); // GCOV_EXCL_LINE | |
| 307 | |||
| 308 |
2/4✓ Branch 47 → 48 taken 7095 times.
✗ Branch 47 → 74 not taken.
✓ Branch 48 → 49 taken 7095 times.
✗ Branch 48 → 74 not taken.
|
14190 | return ExprResult{node->setEvaluatedSymbolType(resultType, manIdx)}; |
| 309 | } | ||
| 310 | |||
| 311 | 369 | std::any TypeChecker::visitShiftExpr(ShiftExprNode *node) { | |
| 312 | // Check if at least one shift operator is applied | ||
| 313 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 369 times.
|
369 | if (node->operands.size() == 1) |
| 314 | ✗ | return visit(node->operands.front()); | |
| 315 | |||
| 316 | // Visit leftmost operand | ||
| 317 |
2/4✓ Branch 8 → 9 taken 369 times.
✗ Branch 8 → 53 not taken.
✓ Branch 9 → 10 taken 369 times.
✗ Branch 9 → 51 not taken.
|
369 | auto currentResult = std::any_cast<ExprResult>(visit(node->operands[0])); |
| 318 |
2/8✓ Branch 11 → 12 taken 369 times.
✗ Branch 11 → 69 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 369 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 54 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 54 not taken.
|
369 | HANDLE_UNRESOLVED_TYPE_ER(currentResult.type) |
| 319 | |||
| 320 | // Loop through remaining operands | ||
| 321 |
2/2✓ Branch 45 → 18 taken 568 times.
✓ Branch 45 → 46 taken 369 times.
|
937 | for (size_t i = 0; i < node->opQueue.size(); i++) { |
| 322 |
2/4✓ Branch 19 → 20 taken 568 times.
✗ Branch 19 → 57 not taken.
✓ Branch 20 → 21 taken 568 times.
✗ Branch 20 → 55 not taken.
|
568 | auto operandResult = std::any_cast<ExprResult>(visit(node->operands[i + 1])); |
| 323 |
2/8✓ Branch 22 → 23 taken 568 times.
✗ Branch 22 → 68 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 568 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 58 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 58 not taken.
|
568 | HANDLE_UNRESOLVED_TYPE_ER(operandResult.type) |
| 324 | |||
| 325 | // Check operator | ||
| 326 |
1/2✓ Branch 28 → 29 taken 568 times.
✗ Branch 28 → 68 not taken.
|
568 | const ShiftExprNode::ShiftOp &op = node->opQueue.front().first; |
| 327 |
2/2✓ Branch 29 → 30 taken 431 times.
✓ Branch 29 → 31 taken 137 times.
|
568 | if (op == ShiftExprNode::ShiftOp::OP_SHIFT_LEFT) |
| 328 |
1/2✓ Branch 30 → 41 taken 431 times.
✗ Branch 30 → 68 not taken.
|
431 | currentResult = opRuleManager.getShiftLeftResultType(node, currentResult, operandResult, i); |
| 329 |
1/2✓ Branch 31 → 32 taken 137 times.
✗ Branch 31 → 33 not taken.
|
137 | else if (op == ShiftExprNode::ShiftOp::OP_SHIFT_RIGHT) |
| 330 |
1/2✓ Branch 32 → 41 taken 137 times.
✗ Branch 32 → 68 not taken.
|
137 | currentResult = opRuleManager.getShiftRightResultType(node, currentResult, operandResult, i); |
| 331 | else | ||
| 332 | − | throw CompilerError(UNHANDLED_BRANCH, "ShiftExpr fall-through"); // GCOV_EXCL_LINE | |
| 333 | |||
| 334 | // Push the new item and pop the old one on the other side of the queue | ||
| 335 |
1/2✓ Branch 41 → 42 taken 568 times.
✗ Branch 41 → 68 not taken.
|
568 | node->opQueue.emplace(op, currentResult.type); |
| 336 |
1/2✓ Branch 42 → 43 taken 568 times.
✗ Branch 42 → 68 not taken.
|
568 | node->opQueue.pop(); |
| 337 | } | ||
| 338 | |||
| 339 |
1/2✓ Branch 46 → 47 taken 369 times.
✗ Branch 46 → 69 not taken.
|
369 | node->setEvaluatedSymbolType(currentResult.type, manIdx); |
| 340 |
1/2✓ Branch 47 → 48 taken 369 times.
✗ Branch 47 → 69 not taken.
|
369 | return currentResult; |
| 341 | } | ||
| 342 | |||
| 343 | 7384 | std::any TypeChecker::visitAdditiveExpr(AdditiveExprNode *node) { | |
| 344 | // Check if at least one additive operator is applied | ||
| 345 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 7384 times.
|
7384 | if (node->operands.size() == 1) |
| 346 | ✗ | return visit(node->operands.front()); | |
| 347 | |||
| 348 | // Visit leftmost operand | ||
| 349 |
2/4✓ Branch 8 → 9 taken 7384 times.
✗ Branch 8 → 53 not taken.
✓ Branch 9 → 10 taken 7384 times.
✗ Branch 9 → 51 not taken.
|
7384 | auto currentResult = std::any_cast<ExprResult>(visit(node->operands[0])); |
| 350 |
2/8✓ Branch 11 → 12 taken 7384 times.
✗ Branch 11 → 69 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 7384 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 54 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 54 not taken.
|
7384 | HANDLE_UNRESOLVED_TYPE_ER(currentResult.type) |
| 351 | |||
| 352 | // Loop through remaining operands | ||
| 353 |
2/2✓ Branch 45 → 18 taken 8380 times.
✓ Branch 45 → 46 taken 7383 times.
|
15763 | for (size_t i = 0; i < node->opQueue.size(); i++) { |
| 354 |
2/4✓ Branch 19 → 20 taken 8380 times.
✗ Branch 19 → 57 not taken.
✓ Branch 20 → 21 taken 8380 times.
✗ Branch 20 → 55 not taken.
|
8380 | auto operandResult = std::any_cast<ExprResult>(visit(node->operands[i + 1])); |
| 355 |
2/8✓ Branch 22 → 23 taken 8380 times.
✗ Branch 22 → 68 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 8380 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 58 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 58 not taken.
|
8380 | HANDLE_UNRESOLVED_TYPE_ER(operandResult.type) |
| 356 | |||
| 357 | // Check operator | ||
| 358 |
1/2✓ Branch 28 → 29 taken 8380 times.
✗ Branch 28 → 68 not taken.
|
8380 | const AdditiveExprNode::AdditiveOp &op = node->opQueue.front().first; |
| 359 |
2/2✓ Branch 29 → 30 taken 5373 times.
✓ Branch 29 → 31 taken 3007 times.
|
8380 | if (op == AdditiveExprNode::AdditiveOp::OP_PLUS) |
| 360 |
2/2✓ Branch 30 → 41 taken 5372 times.
✓ Branch 30 → 68 taken 1 time.
|
5373 | currentResult = opRuleManager.getPlusResultType(node, currentResult, operandResult, i); |
| 361 |
1/2✓ Branch 31 → 32 taken 3007 times.
✗ Branch 31 → 33 not taken.
|
3007 | else if (op == AdditiveExprNode::AdditiveOp::OP_MINUS) |
| 362 |
1/2✓ Branch 32 → 41 taken 3007 times.
✗ Branch 32 → 68 not taken.
|
3007 | currentResult = opRuleManager.getMinusResultType(node, currentResult, operandResult, i); |
| 363 | else | ||
| 364 | − | throw CompilerError(UNHANDLED_BRANCH, "AdditiveExpr fall-through"); // GCOV_EXCL_LINE | |
| 365 | |||
| 366 | // Push the new item and pop the old one on the other side of the queue | ||
| 367 |
1/2✓ Branch 41 → 42 taken 8379 times.
✗ Branch 41 → 68 not taken.
|
8379 | node->opQueue.emplace(op, currentResult.type); |
| 368 |
1/2✓ Branch 42 → 43 taken 8379 times.
✗ Branch 42 → 68 not taken.
|
8379 | node->opQueue.pop(); |
| 369 | } | ||
| 370 | |||
| 371 |
1/2✓ Branch 46 → 47 taken 7383 times.
✗ Branch 46 → 69 not taken.
|
7383 | node->setEvaluatedSymbolType(currentResult.type, manIdx); |
| 372 |
1/2✓ Branch 47 → 48 taken 7383 times.
✗ Branch 47 → 69 not taken.
|
7383 | return currentResult; |
| 373 | } | ||
| 374 | |||
| 375 | 2174 | std::any TypeChecker::visitMultiplicativeExpr(MultiplicativeExprNode *node) { | |
| 376 | // Check if at least one multiplicative operator is applied | ||
| 377 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 2174 times.
|
2174 | if (node->operands.size() == 1) |
| 378 | ✗ | return visit(node->operands.front()); | |
| 379 | |||
| 380 | // Visit leftmost operand | ||
| 381 |
2/4✓ Branch 8 → 9 taken 2174 times.
✗ Branch 8 → 55 not taken.
✓ Branch 9 → 10 taken 2174 times.
✗ Branch 9 → 53 not taken.
|
2174 | auto currentResult = std::any_cast<ExprResult>(visit(node->operands[0])); |
| 382 |
2/8✓ Branch 11 → 12 taken 2174 times.
✗ Branch 11 → 71 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 17 taken 2174 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 56 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 56 not taken.
|
2174 | HANDLE_UNRESOLVED_TYPE_ER(currentResult.type) |
| 383 | // Loop through remaining operands | ||
| 384 |
2/2✓ Branch 47 → 18 taken 2224 times.
✓ Branch 47 → 48 taken 2173 times.
|
4397 | for (size_t i = 0; i < node->opQueue.size(); i++) { |
| 385 |
2/4✓ Branch 19 → 20 taken 2224 times.
✗ Branch 19 → 59 not taken.
✓ Branch 20 → 21 taken 2224 times.
✗ Branch 20 → 57 not taken.
|
2224 | auto operandResult = std::any_cast<ExprResult>(visit(node->operands[i + 1])); |
| 386 |
2/8✓ Branch 22 → 23 taken 2224 times.
✗ Branch 22 → 70 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 28 taken 2224 times.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 60 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 60 not taken.
|
2224 | HANDLE_UNRESOLVED_TYPE_ER(operandResult.type) |
| 387 | |||
| 388 | // Check operator | ||
| 389 |
1/2✓ Branch 28 → 29 taken 2224 times.
✗ Branch 28 → 70 not taken.
|
2224 | const MultiplicativeExprNode::MultiplicativeOp &op = node->opQueue.front().first; |
| 390 |
2/2✓ Branch 29 → 30 taken 1663 times.
✓ Branch 29 → 31 taken 561 times.
|
2224 | if (op == MultiplicativeExprNode::MultiplicativeOp::OP_MUL) |
| 391 |
2/2✓ Branch 30 → 43 taken 1662 times.
✓ Branch 30 → 70 taken 1 time.
|
1663 | currentResult = opRuleManager.getMulResultType(node, currentResult, operandResult, i); |
| 392 |
2/2✓ Branch 31 → 32 taken 454 times.
✓ Branch 31 → 33 taken 107 times.
|
561 | else if (op == MultiplicativeExprNode::MultiplicativeOp::OP_DIV) |
| 393 |
1/2✓ Branch 32 → 43 taken 454 times.
✗ Branch 32 → 70 not taken.
|
454 | currentResult = opRuleManager.getDivResultType(node, currentResult, operandResult, i); |
| 394 |
1/2✓ Branch 33 → 34 taken 107 times.
✗ Branch 33 → 35 not taken.
|
107 | else if (op == MultiplicativeExprNode::MultiplicativeOp::OP_REM) |
| 395 |
1/2✓ Branch 34 → 43 taken 107 times.
✗ Branch 34 → 70 not taken.
|
107 | currentResult = OpRuleManager::getRemResultType(node, currentResult, operandResult); |
| 396 | else | ||
| 397 | − | throw CompilerError(UNHANDLED_BRANCH, "Multiplicative fall-through"); // GCOV_EXCL_LINE | |
| 398 | |||
| 399 | // Push the new item and pop the old one on the other side of the queue | ||
| 400 |
1/2✓ Branch 43 → 44 taken 2223 times.
✗ Branch 43 → 70 not taken.
|
2223 | node->opQueue.emplace(op, currentResult.type); |
| 401 |
1/2✓ Branch 44 → 45 taken 2223 times.
✗ Branch 44 → 70 not taken.
|
2223 | node->opQueue.pop(); |
| 402 | } | ||
| 403 | |||
| 404 |
1/2✓ Branch 48 → 49 taken 2173 times.
✗ Branch 48 → 71 not taken.
|
2173 | node->setEvaluatedSymbolType(currentResult.type, manIdx); |
| 405 |
1/2✓ Branch 49 → 50 taken 2173 times.
✗ Branch 49 → 71 not taken.
|
2173 | return currentResult; |
| 406 | } | ||
| 407 | |||
| 408 | 5276 | std::any TypeChecker::visitCastExpr(CastExprNode *node) { | |
| 409 | // Check if cast is applied | ||
| 410 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 5276 times.
|
5276 | if (!node->isCast) |
| 411 | ✗ | return visit(node->prefixUnaryExpr); | |
| 412 | |||
| 413 | // Visit destination type | ||
| 414 |
2/4✓ Branch 5 → 6 taken 5276 times.
✗ Branch 5 → 49 not taken.
✓ Branch 6 → 7 taken 5276 times.
✗ Branch 6 → 47 not taken.
|
5276 | const auto dstType = std::any_cast<QualType>(visit(node->dataType)); |
| 415 |
2/8✓ Branch 8 → 9 taken 5276 times.
✗ Branch 8 → 65 not taken.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 14 taken 5276 times.
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 50 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 50 not taken.
|
5276 | HANDLE_UNRESOLVED_TYPE_ER(dstType) |
| 416 | // Visit source type | ||
| 417 |
2/4✓ Branch 14 → 15 taken 5276 times.
✗ Branch 14 → 53 not taken.
✓ Branch 15 → 16 taken 5276 times.
✗ Branch 15 → 51 not taken.
|
5276 | const auto src = std::any_cast<ExprResult>(visit(node->assignExpr)); |
| 418 |
2/8✓ Branch 17 → 18 taken 5276 times.
✗ Branch 17 → 65 not taken.
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 23 taken 5276 times.
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 54 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 54 not taken.
|
5276 | HANDLE_UNRESOLVED_TYPE_ER(src.type) |
| 419 | |||
| 420 | // Check for identity cast | ||
| 421 |
3/4✓ Branch 23 → 24 taken 5276 times.
✗ Branch 23 → 65 not taken.
✓ Branch 24 → 25 taken 577 times.
✓ Branch 24 → 34 taken 4699 times.
|
5276 | if (src.type == dstType) { |
| 422 |
2/4✓ Branch 27 → 28 taken 577 times.
✗ Branch 27 → 57 not taken.
✓ Branch 28 → 29 taken 577 times.
✗ Branch 28 → 55 not taken.
|
1154 | const CompilerWarning warning(node->codeLoc, IDENTITY_CAST, "You cast from a type to itself. Thus, this can be simplified."); |
| 423 |
1/2✓ Branch 31 → 32 taken 577 times.
✗ Branch 31 → 61 not taken.
|
577 | sourceFile->compilerOutput.warnings.push_back(warning); |
| 424 | 577 | } | |
| 425 | |||
| 426 | // Get result type | ||
| 427 |
1/2✓ Branch 34 → 35 taken 5276 times.
✗ Branch 34 → 65 not taken.
|
5276 | const QualType resultType = opRuleManager.getCastResultType(node, dstType, src); |
| 428 | |||
| 429 |
1/2✓ Branch 35 → 36 taken 5276 times.
✗ Branch 35 → 65 not taken.
|
5276 | const bool typesMatch = dstType.matches(src.type, false, true, true); |
| 430 |
1/2✓ Branch 36 → 37 taken 5276 times.
✗ Branch 36 → 65 not taken.
|
5276 | const bool sameContainerType = src.type.isSameContainerTypeAs(dstType); |
| 431 |
4/4✓ Branch 37 → 38 taken 4699 times.
✓ Branch 37 → 39 taken 577 times.
✓ Branch 38 → 39 taken 558 times.
✓ Branch 38 → 40 taken 4141 times.
|
5276 | SymbolTableEntry *entry = typesMatch || sameContainerType ? src.entry : nullptr; |
| 432 |
2/4✓ Branch 41 → 42 taken 5276 times.
✗ Branch 41 → 64 not taken.
✓ Branch 42 → 43 taken 5276 times.
✗ Branch 42 → 64 not taken.
|
10552 | return ExprResult{node->setEvaluatedSymbolType(resultType, manIdx), entry}; |
| 433 | } | ||
| 434 | |||
| 435 | 3914 | std::any TypeChecker::visitPrefixUnaryExpr(PrefixUnaryExprNode *node) { | |
| 436 | // If no operator is applied, simply visit the postfix unary expression | ||
| 437 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 3914 times.
|
3914 | if (node->op == PrefixUnaryExprNode::PrefixUnaryOp::OP_NONE) |
| 438 | ✗ | return visit(node->postfixUnaryExpr); | |
| 439 | |||
| 440 | // Visit the right side | ||
| 441 | 3914 | ExprNode *rhsNode = node->prefixUnaryExpr; | |
| 442 |
2/4✓ Branch 5 → 6 taken 3914 times.
✗ Branch 5 → 58 not taken.
✓ Branch 6 → 7 taken 3914 times.
✗ Branch 6 → 56 not taken.
|
3914 | auto operand = std::any_cast<ExprResult>(visit(rhsNode)); |
| 443 | 3914 | auto [operandType, operandEntry] = operand; | |
| 444 |
5/8✓ Branch 8 → 9 taken 3914 times.
✗ Branch 8 → 79 not taken.
✓ Branch 9 → 10 taken 1 time.
✓ Branch 9 → 14 taken 3913 times.
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 59 not taken.
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 59 not taken.
|
3915 | HANDLE_UNRESOLVED_TYPE_ER(operandType) |
| 445 | // Determine action, based on the given operator | ||
| 446 |
7/8✓ Branch 14 → 15 taken 991 times.
✓ Branch 14 → 17 taken 46 times.
✓ Branch 14 → 25 taken 16 times.
✓ Branch 14 → 33 taken 1983 times.
✓ Branch 14 → 35 taken 12 times.
✓ Branch 14 → 38 taken 507 times.
✓ Branch 14 → 40 taken 358 times.
✗ Branch 14 → 42 not taken.
|
3913 | switch (node->op) { |
| 447 | 991 | case PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS: | |
| 448 |
1/2✓ Branch 15 → 16 taken 991 times.
✗ Branch 15 → 60 not taken.
|
991 | operandType = OpRuleManager::getPrefixMinusResultType(node, operand); |
| 449 | 991 | break; | |
| 450 | 46 | case PrefixUnaryExprNode::PrefixUnaryOp::OP_PLUS_PLUS: | |
| 451 |
1/2✓ Branch 17 → 18 taken 46 times.
✗ Branch 17 → 61 not taken.
|
46 | operandType = opRuleManager.getPrefixPlusPlusResultType(node, operand); |
| 452 | |||
| 453 |
2/2✓ Branch 18 → 19 taken 43 times.
✓ Branch 18 → 24 taken 3 times.
|
46 | if (operandEntry) { |
| 454 | // In case the lhs is captured, notify the capture about the write access | ||
| 455 |
2/4✓ Branch 19 → 20 taken 43 times.
✗ Branch 19 → 79 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 43 times.
|
43 | if (Capture *lhsCapture = currentScope->symbolTable.lookupCapture(operandEntry->name); lhsCapture) |
| 456 | ✗ | lhsCapture->setAccessType(READ_WRITE); | |
| 457 | |||
| 458 | // Update the state of the variable | ||
| 459 |
1/2✓ Branch 22 → 23 taken 43 times.
✗ Branch 22 → 62 not taken.
|
43 | operandEntry->updateState(INITIALIZED, node); |
| 460 | } | ||
| 461 | |||
| 462 | 46 | break; | |
| 463 | 16 | case PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS_MINUS: | |
| 464 |
2/2✓ Branch 25 → 26 taken 15 times.
✓ Branch 25 → 63 taken 1 time.
|
16 | operandType = opRuleManager.getPrefixMinusMinusResultType(node, operand); |
| 465 | |||
| 466 |
2/2✓ Branch 26 → 27 taken 12 times.
✓ Branch 26 → 32 taken 3 times.
|
15 | if (operandEntry) { |
| 467 | // In case the lhs is captured, notify the capture about the write access | ||
| 468 |
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) |
| 469 | ✗ | lhsCapture->setAccessType(READ_WRITE); | |
| 470 | |||
| 471 | // Update the state of the variable | ||
| 472 |
1/2✓ Branch 30 → 31 taken 12 times.
✗ Branch 30 → 64 not taken.
|
12 | operandEntry->updateState(INITIALIZED, node); |
| 473 | } | ||
| 474 | |||
| 475 | 15 | break; | |
| 476 | 1983 | case PrefixUnaryExprNode::PrefixUnaryOp::OP_NOT: | |
| 477 |
1/2✓ Branch 33 → 34 taken 1983 times.
✗ Branch 33 → 65 not taken.
|
1983 | operandType = OpRuleManager::getPrefixNotResultType(node, operand); |
| 478 | 1983 | break; | |
| 479 | 12 | case PrefixUnaryExprNode::PrefixUnaryOp::OP_BITWISE_NOT: { | |
| 480 |
1/2✓ Branch 35 → 36 taken 12 times.
✗ Branch 35 → 66 not taken.
|
12 | const ExprResult result = opRuleManager.getPrefixBitwiseNotResultType(node, operand); |
| 481 | 12 | operandType = result.type; | |
| 482 | 12 | operandEntry = result.entry; | |
| 483 | 12 | break; | |
| 484 | } | ||
| 485 | 507 | case PrefixUnaryExprNode::PrefixUnaryOp::OP_DEREFERENCE: | |
| 486 |
2/2✓ Branch 38 → 39 taken 506 times.
✓ Branch 38 → 67 taken 1 time.
|
507 | operandType = OpRuleManager::getPrefixMulResultType(node, operand); |
| 487 | 506 | break; | |
| 488 | 358 | case PrefixUnaryExprNode::PrefixUnaryOp::OP_ADDRESS_OF: | |
| 489 |
1/2✓ Branch 40 → 41 taken 358 times.
✗ Branch 40 → 68 not taken.
|
358 | operandType = OpRuleManager::getPrefixBitwiseAndResultType(node, operand); |
| 490 | 358 | break; | |
| 491 | − | default: // GCOV_EXCL_LINE | |
| 492 | − | throw CompilerError(UNHANDLED_BRANCH, "PrefixUnaryExpr fall-through"); // GCOV_EXCL_LINE | |
| 493 | } | ||
| 494 | |||
| 495 |
2/4✓ Branch 50 → 51 taken 3911 times.
✗ Branch 50 → 78 not taken.
✓ Branch 51 → 52 taken 3911 times.
✗ Branch 51 → 78 not taken.
|
7822 | return ExprResult{node->setEvaluatedSymbolType(operandType, manIdx), operandEntry}; |
| 496 | } | ||
| 497 | |||
| 498 | 42612 | std::any TypeChecker::visitPostfixUnaryExpr(PostfixUnaryExprNode *node) { | |
| 499 | // If no operator is applied, simply visit the atomic expression | ||
| 500 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 42612 times.
|
42612 | if (node->op == PostfixUnaryExprNode::PostfixUnaryOp::OP_NONE) |
| 501 | ✗ | return visit(node->atomicExpr); | |
| 502 | |||
| 503 | // Visit left side | ||
| 504 | 42612 | ExprNode *lhsNode = node->postfixUnaryExpr; | |
| 505 |
2/4✓ Branch 5 → 6 taken 42612 times.
✗ Branch 5 → 211 not taken.
✓ Branch 6 → 7 taken 42612 times.
✗ Branch 6 → 209 not taken.
|
42612 | auto operand = std::any_cast<ExprResult>(visit(lhsNode)); |
| 506 | 42612 | auto [operandType, operandEntry] = operand; | |
| 507 |
5/8✓ Branch 8 → 9 taken 42612 times.
✗ Branch 8 → 316 not taken.
✓ Branch 9 → 10 taken 6 times.
✓ Branch 9 → 14 taken 42606 times.
✓ Branch 10 → 11 taken 6 times.
✗ Branch 10 → 212 not taken.
✓ Branch 11 → 12 taken 6 times.
✗ Branch 11 → 212 not taken.
|
42618 | HANDLE_UNRESOLVED_TYPE_ER(operandType) |
| 508 | |||
| 509 |
4/5✓ Branch 14 → 15 taken 5513 times.
✓ Branch 14 → 101 taken 33156 times.
✓ Branch 14 → 159 taken 3288 times.
✓ Branch 14 → 167 taken 649 times.
✗ Branch 14 → 175 not taken.
|
42606 | switch (node->op) { |
| 510 | 5513 | case PostfixUnaryExprNode::PostfixUnaryOp::OP_SUBSCRIPT: { | |
| 511 | // Visit index assignment | ||
| 512 | 5513 | ExprNode *indexAssignExpr = node->subscriptIndexExpr; | |
| 513 |
2/4✓ Branch 15 → 16 taken 5513 times.
✗ Branch 15 → 215 not taken.
✓ Branch 16 → 17 taken 5513 times.
✗ Branch 16 → 213 not taken.
|
5513 | const auto index = std::any_cast<ExprResult>(visit(indexAssignExpr)); |
| 514 |
2/8✓ Branch 18 → 19 taken 5513 times.
✗ Branch 18 → 258 not taken.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 24 taken 5513 times.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 216 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 216 not taken.
|
5513 | HANDLE_UNRESOLVED_TYPE_ER(index.type) |
| 515 | |||
| 516 | // Check is there is an overloaded operator function available, if yes accept it | ||
| 517 |
1/2✓ Branch 24 → 25 taken 5513 times.
✗ Branch 24 → 217 not taken.
|
5513 | const auto [type, _] = opRuleManager.isOperatorOverloadingFctAvailable<2>(node, OP_FCT_SUBSCRIPT, {operand, index}, 0); |
| 518 |
3/4✓ Branch 25 → 26 taken 5513 times.
✗ Branch 25 → 258 not taken.
✓ Branch 26 → 27 taken 296 times.
✓ Branch 26 → 28 taken 5217 times.
|
5513 | if (!type.is(TY_INVALID)) { |
| 519 | 296 | operandType = type; | |
| 520 | 5511 | break; | |
| 521 | } | ||
| 522 | |||
| 523 |
1/2✓ Branch 28 → 29 taken 5217 times.
✗ Branch 28 → 218 not taken.
|
5217 | operandType = operandType.removeReferenceWrapper(); |
| 524 | |||
| 525 | // Check if the index is of the right type | ||
| 526 |
3/4✓ Branch 29 → 30 taken 5217 times.
✗ Branch 29 → 219 not taken.
✓ Branch 30 → 31 taken 1 time.
✓ Branch 30 → 41 taken 5216 times.
|
5217 | if (!index.type.isOneOf({TY_INT, TY_LONG})) |
| 527 |
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") |
| 528 | |||
| 529 | // Check if we can apply the subscript operator on the lhs type | ||
| 530 |
2/4✓ Branch 41 → 42 taken 5216 times.
✗ Branch 41 → 227 not taken.
✗ Branch 42 → 43 not taken.
✓ Branch 42 → 52 taken 5216 times.
|
5216 | if (!operandType.isOneOf({TY_ARRAY, TY_PTR, TY_STRING})) |
| 531 | ✗ | SOFT_ERROR_ER(node, OPERATOR_WRONG_DATA_TYPE, | |
| 532 | "Can only apply subscript operator on array type, got " + operandType.getName(true)) | ||
| 533 | |||
| 534 | // Check if we have an unsafe operation | ||
| 535 |
6/10✓ Branch 52 → 53 taken 5216 times.
✗ Branch 52 → 258 not taken.
✓ Branch 53 → 54 taken 3812 times.
✓ Branch 53 → 57 taken 1404 times.
✓ Branch 54 → 55 taken 3812 times.
✗ Branch 54 → 258 not taken.
✗ Branch 55 → 56 not taken.
✓ Branch 55 → 57 taken 3812 times.
✗ Branch 58 → 59 not taken.
✓ Branch 58 → 69 taken 5216 times.
|
5216 | if (operandType.isPtr() && !currentScope->doesAllowUnsafeOperations()) |
| 536 | ✗ | SOFT_ERROR_ER( | |
| 537 | node, UNSAFE_OPERATION_IN_SAFE_CONTEXT, | ||
| 538 | "The subscript operator on pointers is an unsafe operation. Use unsafe blocks if you know what you are doing.") | ||
| 539 | |||
| 540 | // In case of compile time index value and known array size, perform a compile time out-of-bounds check | ||
| 541 |
8/10✓ Branch 69 → 70 taken 5216 times.
✗ Branch 69 → 258 not taken.
✓ Branch 70 → 71 taken 243 times.
✓ Branch 70 → 76 taken 4973 times.
✓ Branch 71 → 72 taken 243 times.
✗ Branch 71 → 258 not taken.
✓ Branch 72 → 73 taken 175 times.
✓ Branch 72 → 76 taken 68 times.
✓ Branch 77 → 78 taken 91 times.
✓ Branch 77 → 96 taken 5125 times.
|
5391 | if (operandType.isArray() && operandType.getArraySize() != ARRAY_SIZE_UNKNOWN && |
| 542 |
3/4✓ Branch 73 → 74 taken 175 times.
✗ Branch 73 → 258 not taken.
✓ Branch 74 → 75 taken 91 times.
✓ Branch 74 → 76 taken 84 times.
|
175 | indexAssignExpr->hasCompileTimeValue(manIdx)) { |
| 543 |
1/2✓ Branch 78 → 79 taken 91 times.
✗ Branch 78 → 258 not taken.
|
91 | const int32_t constIndex = indexAssignExpr->getCompileTimeValue(manIdx).intValue; |
| 544 |
1/2✓ Branch 79 → 80 taken 91 times.
✗ Branch 79 → 258 not taken.
|
91 | const unsigned int constSize = operandType.getArraySize(); |
| 545 | // Check if we are accessing out-of-bounds memory | ||
| 546 |
2/2✓ Branch 80 → 81 taken 1 time.
✓ Branch 80 → 96 taken 90 times.
|
91 | if (constIndex >= static_cast<int32_t>(constSize)) { |
| 547 | 1 | const std::string idxStr = std::to_string(constIndex); | |
| 548 | 1 | const std::string sizeStr = std::to_string(constSize); | |
| 549 |
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, |
| 550 | "You are trying to access element with index " + idxStr + " of an array with size " + sizeStr) | ||
| 551 | 1 | } | |
| 552 | } | ||
| 553 | |||
| 554 | // Get item type | ||
| 555 |
1/2✓ Branch 96 → 97 taken 5215 times.
✗ Branch 96 → 257 not taken.
|
5215 | operandType = operandType.getContained(); |
| 556 | |||
| 557 | // Remove heap qualifier | ||
| 558 | 5215 | operandType.getQualifiers().isHeap = false; | |
| 559 | |||
| 560 | 5215 | break; | |
| 561 | } | ||
| 562 | 33156 | case PostfixUnaryExprNode::PostfixUnaryOp::OP_MEMBER_ACCESS: { | |
| 563 | 33156 | const std::string &fieldName = node->identifier; | |
| 564 | |||
| 565 | // Check if lhs is enum or strobj | ||
| 566 |
1/2✓ Branch 101 → 102 taken 33156 times.
✗ Branch 101 → 286 not taken.
|
33156 | const QualType lhsBaseTy = operandType.autoDeReference(); |
| 567 |
3/4✓ Branch 102 → 103 taken 33156 times.
✗ Branch 102 → 286 not taken.
✓ Branch 103 → 104 taken 1 time.
✓ Branch 103 → 113 taken 33155 times.
|
33156 | if (!lhsBaseTy.is(TY_STRUCT)) |
| 568 |
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)) |
| 569 | |||
| 570 | // Retrieve registry entry | ||
| 571 |
1/2✓ Branch 113 → 114 taken 33155 times.
✗ Branch 113 → 286 not taken.
|
33155 | const std::string &structName = lhsBaseTy.getSubType(); |
| 572 |
1/2✓ Branch 114 → 115 taken 33155 times.
✗ Branch 114 → 286 not taken.
|
33155 | Scope *structScope = lhsBaseTy.getBodyScope(); |
| 573 | |||
| 574 | // If we only have the generic struct scope, lookup the concrete manifestation scope | ||
| 575 |
2/2✓ Branch 115 → 116 taken 237 times.
✓ Branch 115 → 120 taken 32918 times.
|
33155 | if (structScope->isGenericScope) { |
| 576 |
1/2✓ Branch 116 → 117 taken 237 times.
✗ Branch 116 → 286 not taken.
|
237 | const Struct *spiceStruct = lhsBaseTy.getStruct(node); |
| 577 |
1/2✗ Branch 117 → 118 not taken.
✓ Branch 117 → 119 taken 237 times.
|
237 | assert(spiceStruct != nullptr); |
| 578 | 237 | structScope = spiceStruct->scope; | |
| 579 | } | ||
| 580 |
1/2✗ Branch 120 → 121 not taken.
✓ Branch 120 → 122 taken 33155 times.
|
33155 | assert(!structScope->isGenericScope); // At this point we always expect a substantiation scope |
| 581 | |||
| 582 | // Get accessed field | ||
| 583 | 33155 | std::vector<size_t> indexPath; | |
| 584 |
1/2✓ Branch 122 → 123 taken 33155 times.
✗ Branch 122 → 284 not taken.
|
33155 | SymbolTableEntry *memberEntry = structScope->symbolTable.lookupInComposedFields(fieldName, indexPath); |
| 585 |
2/2✓ Branch 123 → 124 taken 2 times.
✓ Branch 123 → 135 taken 33153 times.
|
33155 | if (!memberEntry) |
| 586 |
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) |
| 587 |
1/2✓ Branch 135 → 136 taken 33153 times.
✗ Branch 135 → 284 not taken.
|
33153 | const QualType memberType = memberEntry->getQualType(); |
| 588 | |||
| 589 | // Check for insufficient visibility | ||
| 590 |
8/14✓ Branch 136 → 137 taken 33153 times.
✗ Branch 136 → 276 not taken.
✓ Branch 137 → 138 taken 421 times.
✓ Branch 137 → 143 taken 32732 times.
✓ Branch 138 → 139 taken 421 times.
✗ Branch 138 → 276 not taken.
✓ Branch 139 → 140 taken 421 times.
✗ Branch 139 → 276 not taken.
✓ Branch 140 → 141 taken 421 times.
✗ Branch 140 → 276 not taken.
✗ Branch 141 → 142 not taken.
✓ Branch 141 → 143 taken 421 times.
✗ Branch 144 → 145 not taken.
✓ Branch 144 → 154 taken 33153 times.
|
33153 | if (structScope->isImportedBy(rootScope) && !memberEntry->getQualType().getBase().isPublic()) |
| 591 | ✗ | SOFT_ERROR_ER(node, INSUFFICIENT_VISIBILITY, "Cannot access field '" + fieldName + "' due to its private visibility") | |
| 592 | |||
| 593 | // Set field to used | ||
| 594 | 33153 | memberEntry->used = true; | |
| 595 | |||
| 596 | // Overwrite type and entry of left side with member type and entry | ||
| 597 | 33153 | operandType = memberType; | |
| 598 | 33153 | operandEntry = memberEntry; | |
| 599 | 33153 | break; | |
| 600 |
2/2✓ Branch 156 → 157 taken 2 times.
✓ Branch 156 → 158 taken 33153 times.
|
33155 | } |
| 601 | 3288 | case PostfixUnaryExprNode::PostfixUnaryOp::OP_PLUS_PLUS: { | |
| 602 |
2/2✓ Branch 159 → 160 taken 3286 times.
✓ Branch 159 → 287 taken 2 times.
|
3288 | operandType = opRuleManager.getPostfixPlusPlusResultType(node, operand).type; |
| 603 | |||
| 604 |
2/2✓ Branch 160 → 161 taken 3282 times.
✓ Branch 160 → 166 taken 4 times.
|
3286 | if (operandEntry) { |
| 605 | // In case the lhs is captured, notify the capture about the write access | ||
| 606 |
3/4✓ Branch 161 → 162 taken 3282 times.
✗ Branch 161 → 316 not taken.
✓ Branch 162 → 163 taken 4 times.
✓ Branch 162 → 164 taken 3278 times.
|
3282 | if (Capture *lhsCapture = currentScope->symbolTable.lookupCapture(operandEntry->name); lhsCapture) |
| 607 |
1/2✓ Branch 163 → 164 taken 4 times.
✗ Branch 163 → 316 not taken.
|
4 | lhsCapture->setAccessType(READ_WRITE); |
| 608 | |||
| 609 | // Update the state of the variable | ||
| 610 |
1/2✓ Branch 164 → 165 taken 3282 times.
✗ Branch 164 → 288 not taken.
|
3282 | operandEntry->updateState(INITIALIZED, node); |
| 611 | } | ||
| 612 | |||
| 613 | 3286 | break; | |
| 614 | } | ||
| 615 | 649 | case PostfixUnaryExprNode::PostfixUnaryOp::OP_MINUS_MINUS: { | |
| 616 |
1/2✓ Branch 167 → 168 taken 649 times.
✗ Branch 167 → 289 not taken.
|
649 | operandType = opRuleManager.getPostfixMinusMinusResultType(node, operand).type; |
| 617 | |||
| 618 |
2/2✓ Branch 168 → 169 taken 645 times.
✓ Branch 168 → 174 taken 4 times.
|
649 | if (operandEntry) { |
| 619 | // In case the lhs is captured, notify the capture about the write access | ||
| 620 |
2/4✓ Branch 169 → 170 taken 645 times.
✗ Branch 169 → 316 not taken.
✗ Branch 170 → 171 not taken.
✓ Branch 170 → 172 taken 645 times.
|
645 | if (Capture *lhsCapture = currentScope->symbolTable.lookupCapture(operandEntry->name); lhsCapture) |
| 621 | ✗ | lhsCapture->setAccessType(READ_WRITE); | |
| 622 | |||
| 623 | // Update the state of the variable | ||
| 624 |
1/2✓ Branch 172 → 173 taken 645 times.
✗ Branch 172 → 290 not taken.
|
645 | operandEntry->updateState(INITIALIZED, node); |
| 625 | } | ||
| 626 | |||
| 627 | 649 | break; | |
| 628 | } | ||
| 629 | − | default: // GCOV_EXCL_LINE | |
| 630 | − | throw CompilerError(UNHANDLED_BRANCH, "PostfixUnaryExpr fall-through"); // GCOV_EXCL_LINE | |
| 631 | } | ||
| 632 | |||
| 633 |
2/4✓ Branch 183 → 184 taken 42599 times.
✗ Branch 183 → 316 not taken.
✗ Branch 184 → 185 not taken.
✓ Branch 184 → 203 taken 42599 times.
|
42599 | if (operandType.is(TY_INVALID)) { |
| 634 | ✗ | const std::string &varName = operandEntry ? operandEntry->name : ""; | |
| 635 | ✗ | SOFT_ERROR_ER(node, REFERENCED_UNDEFINED_VARIABLE, "Variable '" + varName + "' was referenced before declared") | |
| 636 | ✗ | } | |
| 637 | |||
| 638 |
2/4✓ Branch 203 → 204 taken 42599 times.
✗ Branch 203 → 315 not taken.
✓ Branch 204 → 205 taken 42599 times.
✗ Branch 204 → 315 not taken.
|
85198 | return ExprResult{node->setEvaluatedSymbolType(operandType, manIdx), operandEntry}; |
| 639 | } | ||
| 640 | |||
| 641 | 190746 | std::any TypeChecker::visitAtomicExpr(AtomicExprNode *node) { | |
| 642 | // Check if constant | ||
| 643 |
2/2✓ Branch 2 → 3 taken 37134 times.
✓ Branch 2 → 5 taken 153612 times.
|
190746 | if (node->constant) |
| 644 |
1/2✓ Branch 3 → 4 taken 37134 times.
✗ Branch 3 → 218 not taken.
|
37134 | return visit(node->constant); |
| 645 | |||
| 646 | // Check if value | ||
| 647 |
2/2✓ Branch 5 → 6 taken 44595 times.
✓ Branch 5 → 8 taken 109017 times.
|
153612 | if (node->value) |
| 648 |
2/2✓ Branch 6 → 7 taken 44590 times.
✓ Branch 6 → 218 taken 5 times.
|
44595 | return visit(node->value); |
| 649 | |||
| 650 | // Check for assign expression within parentheses | ||
| 651 |
2/2✓ Branch 8 → 9 taken 987 times.
✓ Branch 8 → 11 taken 108030 times.
|
109017 | if (node->assignExpr) |
| 652 |
2/2✓ Branch 9 → 10 taken 984 times.
✓ Branch 9 → 218 taken 3 times.
|
987 | return visit(node->assignExpr); |
| 653 | |||
| 654 | // Identifier (local or global variable access) | ||
| 655 |
1/2✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 108030 times.
|
108030 | assert(!node->fqIdentifier.empty()); |
| 656 | |||
| 657 |
1/2✓ Branch 14 → 15 taken 108030 times.
✗ Branch 14 → 218 not taken.
|
108030 | auto &[entry, accessScope, capture] = node->data.at(manIdx); |
| 658 | 108030 | accessScope = currentScope; | |
| 659 | |||
| 660 | // Check if a local or global variable can be found by searching for the name | ||
| 661 |
2/2✓ Branch 16 → 17 taken 105777 times.
✓ Branch 16 → 22 taken 2253 times.
|
108030 | if (node->identifierFragments.size() == 1) |
| 662 | 211554 | entry = accessScope->lookup(node->identifierFragments.back()); | |
| 663 | |||
| 664 | // If no local or global was found, search in the name registry | ||
| 665 |
2/2✓ Branch 22 → 23 taken 2436 times.
✓ Branch 22 → 35 taken 105594 times.
|
108030 | if (!entry) { |
| 666 |
1/2✓ Branch 23 → 24 taken 2436 times.
✗ Branch 23 → 218 not taken.
|
2436 | const NameRegistryEntry *registryEntry = sourceFile->getNameRegistryEntry(node->fqIdentifier); |
| 667 |
2/2✓ Branch 24 → 25 taken 1 time.
✓ Branch 24 → 34 taken 2435 times.
|
2436 | if (!registryEntry) |
| 668 |
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") |
| 669 | 2435 | entry = registryEntry->targetEntry; | |
| 670 | 2435 | accessScope = registryEntry->targetScope; | |
| 671 | } | ||
| 672 |
1/2✗ Branch 35 → 36 not taken.
✓ Branch 35 → 37 taken 108029 times.
|
108029 | assert(entry != nullptr); |
| 673 | 108029 | entry->used = true; | |
| 674 |
1/2✓ Branch 37 → 38 taken 108029 times.
✗ Branch 37 → 218 not taken.
|
108029 | capture = accessScope->symbolTable.lookupCapture(entry->name); |
| 675 | |||
| 676 |
1/2✓ Branch 38 → 39 taken 108029 times.
✗ Branch 38 → 218 not taken.
|
108029 | const QualType varType = entry->getQualType(); |
| 677 |
5/8✓ Branch 39 → 40 taken 108029 times.
✗ Branch 39 → 218 not taken.
✓ Branch 40 → 41 taken 9 times.
✓ Branch 40 → 45 taken 108020 times.
✓ Branch 41 → 42 taken 9 times.
✗ Branch 41 → 169 not taken.
✓ Branch 42 → 43 taken 9 times.
✗ Branch 42 → 169 not taken.
|
108038 | HANDLE_UNRESOLVED_TYPE_ER(varType) |
| 678 |
3/4✓ Branch 45 → 46 taken 108020 times.
✗ Branch 45 → 218 not taken.
✓ Branch 46 → 47 taken 2 times.
✓ Branch 46 → 56 taken 108018 times.
|
108020 | if (varType.is(TY_INVALID)) |
| 679 |
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.") |
| 680 | |||
| 681 |
7/8✓ Branch 56 → 57 taken 108018 times.
✗ Branch 56 → 177 not taken.
✓ Branch 57 → 58 taken 87 times.
✓ Branch 57 → 60 taken 107931 times.
✓ Branch 58 → 59 taken 20 times.
✓ Branch 58 → 60 taken 67 times.
✓ Branch 61 → 62 taken 20 times.
✓ Branch 61 → 90 taken 107998 times.
|
108018 | if (varType.isOneOf({TY_FUNCTION, TY_PROCEDURE}) && entry->global) { |
| 682 | // Check if overloaded function was referenced | ||
| 683 |
1/2✓ Branch 62 → 63 taken 20 times.
✗ Branch 62 → 218 not taken.
|
20 | const std::vector<Function *> *manifestations = entry->declNode->getFctManifestations(entry->name); |
| 684 |
2/2✓ Branch 64 → 65 taken 1 time.
✓ Branch 64 → 75 taken 19 times.
|
20 | if (manifestations->size() > 1) |
| 685 |
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") |
| 686 |
2/2✓ Branch 77 → 78 taken 1 time.
✓ Branch 77 → 88 taken 18 times.
|
19 | if (!manifestations->front()->templateTypes.empty()) |
| 687 |
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") |
| 688 | // Set referenced function to used | ||
| 689 | 18 | Function *referencedFunction = manifestations->front(); | |
| 690 | 18 | referencedFunction->used = true; | |
| 691 | 18 | referencedFunction->entry->used = true; | |
| 692 | } | ||
| 693 | |||
| 694 | // The base type should be an extended primitive | ||
| 695 |
1/2✓ Branch 90 → 91 taken 108016 times.
✗ Branch 90 → 218 not taken.
|
108016 | const QualType baseType = varType.getBase(); |
| 696 |
6/10✓ Branch 91 → 92 taken 108016 times.
✗ Branch 91 → 218 not taken.
✓ Branch 92 → 93 taken 4 times.
✓ Branch 92 → 96 taken 108012 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 108016 times.
|
108016 | if (!baseType.isExtendedPrimitive() && !baseType.is(TY_DYN)) |
| 697 | ✗ | SOFT_ERROR_ER(node, INVALID_SYMBOL_ACCESS, "A symbol of type " + varType.getName(false) + " cannot be accessed here") | |
| 698 | |||
| 699 | // Check if we have seen a 'this.' prefix, because the generator needs that | ||
| 700 |
6/8✓ Branch 109 → 110 taken 1 time.
✓ Branch 109 → 114 taken 108015 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 108015 times.
|
108016 | if (entry->scope->type == ScopeType::STRUCT && node->identifierFragments.front() != THIS_VARIABLE_NAME) |
| 701 |
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, |
| 702 | "The symbol '" + node->fqIdentifier + "' could not be found. Missing 'this.' prefix?") | ||
| 703 | |||
| 704 | // Ensure that the entry is public, if the symbol is imported. | ||
| 705 | // An exception are enum items. There it is sufficient, that the enum itself is public. | ||
| 706 |
7/8✓ Branch 125 → 126 taken 108015 times.
✗ Branch 125 → 218 not taken.
✓ Branch 126 → 127 taken 1981 times.
✓ Branch 126 → 129 taken 106034 times.
✓ Branch 127 → 128 taken 204 times.
✓ Branch 127 → 129 taken 1777 times.
✓ Branch 130 → 131 taken 204 times.
✓ Branch 130 → 144 taken 107811 times.
|
108015 | if (accessScope->isImportedBy(rootScope) && accessScope->type != ScopeType::ENUM) |
| 707 |
5/8✓ Branch 131 → 132 taken 204 times.
✗ Branch 131 → 209 not taken.
✓ Branch 132 → 133 taken 204 times.
✗ Branch 132 → 209 not taken.
✓ Branch 133 → 134 taken 204 times.
✗ Branch 133 → 209 not taken.
✓ Branch 134 → 135 taken 1 time.
✓ Branch 134 → 144 taken 203 times.
|
204 | if (!entry->getQualType().getBase().isPublic()) |
| 708 |
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") |
| 709 | |||
| 710 | // For enum item access, use access scope of the enum | ||
| 711 |
2/2✓ Branch 144 → 145 taken 2248 times.
✓ Branch 144 → 146 taken 105766 times.
|
108014 | if (entry->scope->type == ScopeType::ENUM) |
| 712 | 2248 | accessScope = entry->scope; | |
| 713 | |||
| 714 | // For struct access, use access scope of the struct | ||
| 715 |
3/4✓ Branch 146 → 147 taken 108014 times.
✗ Branch 146 → 218 not taken.
✓ Branch 147 → 148 taken 41268 times.
✓ Branch 147 → 156 taken 66746 times.
|
108014 | if (baseType.is(TY_STRUCT)) { |
| 716 |
1/2✓ Branch 148 → 149 taken 41268 times.
✗ Branch 148 → 218 not taken.
|
41268 | const std::string &structName = baseType.getSubType(); |
| 717 |
1/2✓ Branch 149 → 150 taken 41268 times.
✗ Branch 149 → 218 not taken.
|
41268 | const NameRegistryEntry *nameRegistryEntry = sourceFile->getNameRegistryEntry(structName); |
| 718 | // The struct may only be reachable transitively (i.e. it is not present in this file's name registry under | ||
| 719 | // its unqualified name). In that case, fall back to the struct's body scope, which is exactly what the | ||
| 720 | // registry entry's targetScope would point to (see SymbolTableBuilder struct registration). This keeps | ||
| 721 | // member access working across deep transitive imports instead of crashing. | ||
| 722 |
1/4✓ Branch 150 → 151 taken 41268 times.
✗ Branch 150 → 152 not taken.
✗ Branch 152 → 153 not taken.
✗ Branch 152 → 218 not taken.
|
41268 | accessScope = nameRegistryEntry != nullptr ? nameRegistryEntry->targetScope : baseType.getBodyScope(); |
| 723 |
1/2✗ Branch 154 → 155 not taken.
✓ Branch 154 → 156 taken 41268 times.
|
41268 | assert(accessScope != nullptr); |
| 724 | } | ||
| 725 | |||
| 726 |
2/4✓ Branch 156 → 157 taken 108014 times.
✗ Branch 156 → 217 not taken.
✓ Branch 157 → 158 taken 108014 times.
✗ Branch 157 → 217 not taken.
|
216028 | return ExprResult{node->setEvaluatedSymbolType(varType, manIdx), entry}; |
| 727 | } | ||
| 728 | |||
| 729 | } // namespace spice::compiler | ||
| 730 |