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