src/typechecker/TypeCheckerStatements.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 <ast/ASTNodes.h> | ||
| 7 | #include <global/GlobalResourceManager.h> | ||
| 8 | #include <symboltablebuilder/Scope.h> | ||
| 9 | #include <symboltablebuilder/SymbolTableBuilder.h> | ||
| 10 | #include <typechecker/FunctionManager.h> | ||
| 11 | #include <typechecker/MacroDefs.h> | ||
| 12 | |||
| 13 | namespace spice::compiler { | ||
| 14 | |||
| 15 | 58374 | std::any TypeChecker::visitStmtLst(StmtLstNode *node) { | |
| 16 | // Visit nodes in this scope | ||
| 17 |
2/2✓ Branch 23 → 4 taken 114076 times.
✓ Branch 23 → 24 taken 58340 times.
|
230790 | for (StmtNode *stmt : node->statements) { |
| 18 |
1/2✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 114076 times.
|
114076 | if (!stmt) |
| 19 | ✗ | continue; | |
| 20 | // Print warning if statement is unreachable | ||
| 21 |
2/2✓ Branch 8 → 9 taken 20 times.
✓ Branch 8 → 11 taken 114056 times.
|
114076 | if (stmt->unreachable) { |
| 22 |
1/2✓ Branch 9 → 10 taken 20 times.
✗ Branch 9 → 29 not taken.
|
20 | warnings.emplace_back(stmt->codeLoc, UNREACHABLE_CODE, "This statement is unreachable"); |
| 23 | 20 | continue; | |
| 24 | } | ||
| 25 | // Visit the statement | ||
| 26 |
2/2✓ Branch 11 → 12 taken 114022 times.
✓ Branch 11 → 30 taken 34 times.
|
114056 | visit(stmt); |
| 27 | } | ||
| 28 | |||
| 29 | // Do cleanup of this scope, e.g. dtor calls for struct instances | ||
| 30 | 58340 | doScopeCleanup(node); | |
| 31 | |||
| 32 |
1/2✓ Branch 25 → 26 taken 58340 times.
✗ Branch 25 → 32 not taken.
|
116680 | return nullptr; |
| 33 | } | ||
| 34 | |||
| 35 | 93339 | std::any TypeChecker::visitDeclStmt(DeclStmtNode *node) { | |
| 36 | // Retrieve entry of the lhs variable | ||
| 37 |
1/2✓ Branch 2 → 3 taken 93339 times.
✗ Branch 2 → 178 not taken.
|
93339 | SymbolTableEntry *localVarEntry = currentScope->lookupStrict(node->varName); |
| 38 |
1/2✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 93339 times.
|
93339 | assert(localVarEntry != nullptr); |
| 39 | |||
| 40 | 93339 | QualType localVarType; | |
| 41 |
2/2✓ Branch 7 → 8 taken 27634 times.
✓ Branch 7 → 66 taken 65705 times.
|
93339 | if (node->hasAssignment) { |
| 42 | // Visit the right side | ||
| 43 |
3/4✓ Branch 8 → 9 taken 27629 times.
✓ Branch 8 → 125 taken 5 times.
✓ Branch 9 → 10 taken 27629 times.
✗ Branch 9 → 123 not taken.
|
27634 | auto rhs = std::any_cast<ExprResult>(visit(node->assignExpr)); |
| 44 | 27629 | auto [rhsTy, rhsEntry] = rhs; | |
| 45 | |||
| 46 | // Capture anonymous info up front: getAssignResultType may delete the anonymous entry (temp stealing | ||
| 47 | // in performStructAssign), turning rhsEntry into a dangling pointer. | ||
| 48 |
4/4✓ Branch 11 → 12 taken 5614 times.
✓ Branch 11 → 14 taken 22015 times.
✓ Branch 12 → 13 taken 2446 times.
✓ Branch 12 → 14 taken 3168 times.
|
27629 | const bool rhsIsAnonymous = rhsEntry != nullptr && rhsEntry->anonymous; |
| 49 |
3/4✓ Branch 15 → 16 taken 2446 times.
✓ Branch 15 → 17 taken 25183 times.
✓ Branch 16 → 18 taken 2446 times.
✗ Branch 16 → 147 not taken.
|
27629 | const std::string rhsEntryName = rhsIsAnonymous ? rhsEntry->name : std::string(); |
| 50 | |||
| 51 | // Visit data type | ||
| 52 |
3/4✓ Branch 18 → 19 taken 27626 times.
✓ Branch 18 → 128 taken 3 times.
✓ Branch 19 → 20 taken 27626 times.
✗ Branch 19 → 126 not taken.
|
27629 | localVarType = std::any_cast<QualType>(visit(node->dataType)); |
| 53 | |||
| 54 | // Check if type has to be inferred or both types are fixed | ||
| 55 |
8/10✓ Branch 21 → 22 taken 27626 times.
✗ Branch 21 → 145 not taken.
✓ Branch 22 → 23 taken 27622 times.
✓ Branch 22 → 26 taken 4 times.
✓ Branch 23 → 24 taken 27622 times.
✗ Branch 23 → 145 not taken.
✓ Branch 24 → 25 taken 27600 times.
✓ Branch 24 → 26 taken 22 times.
✓ Branch 27 → 28 taken 27600 times.
✓ Branch 27 → 55 taken 26 times.
|
27626 | if (!localVarType.is(TY_UNRESOLVED) && !rhsTy.is(TY_UNRESOLVED)) { |
| 56 | 27600 | const ExprResult lhsResult = {localVarType, localVarEntry}; | |
| 57 |
2/2✓ Branch 28 → 29 taken 27589 times.
✓ Branch 28 → 143 taken 11 times.
|
27600 | const auto [type, copyCtor] = opRuleManager.getAssignResultType(node, lhsResult, rhs, true); |
| 58 | 27589 | localVarType = type; | |
| 59 | 27589 | node->calledCopyCtor = copyCtor; | |
| 60 | |||
| 61 | // If this is a struct type, check if the type is known. If not, error out. A type that already carries a | ||
| 62 | // body scope is genuinely resolved (e.g. it reached here through a generic substantiation or a deep | ||
| 63 | // transitive import); only its unqualified name happens to be absent from this file's name registry, which | ||
| 64 | // is not an error. | ||
| 65 |
7/12✓ Branch 31 → 32 taken 27589 times.
✗ Branch 31 → 130 not taken.
✓ Branch 32 → 33 taken 5635 times.
✓ Branch 32 → 41 taken 21954 times.
✓ Branch 33 → 34 taken 5635 times.
✗ Branch 33 → 130 not taken.
✓ Branch 34 → 35 taken 5635 times.
✗ Branch 34 → 130 not taken.
✓ Branch 35 → 36 taken 5635 times.
✗ Branch 35 → 130 not taken.
✗ Branch 36 → 37 not taken.
✓ Branch 36 → 41 taken 5635 times.
|
27589 | if (localVarType.isBase(TY_STRUCT) && !sourceFile->getNameRegistryEntry(localVarType.getBase().getSubType()) && |
| 66 |
1/8✗ Branch 37 → 38 not taken.
✗ Branch 37 → 130 not taken.
✗ Branch 38 → 39 not taken.
✗ Branch 38 → 130 not taken.
✗ Branch 39 → 40 not taken.
✗ Branch 39 → 41 not taken.
✗ Branch 42 → 43 not taken.
✓ Branch 42 → 54 taken 27589 times.
|
27589 | localVarType.getBase().getBodyScope() == nullptr) { |
| 67 | ✗ | const std::string structName = localVarType.getBase().getSubType(); | |
| 68 | ✗ | softError(node->dataType, UNKNOWN_DATATYPE, "Unknown struct type '" + structName + "'. Forgot to import?"); | |
| 69 | ✗ | localVarType = QualType(TY_UNRESOLVED); | |
| 70 | ✗ | } | |
| 71 | } else { | ||
| 72 |
1/2✓ Branch 55 → 56 taken 26 times.
✗ Branch 55 → 144 not taken.
|
26 | localVarType = QualType(TY_UNRESOLVED); |
| 73 | } | ||
| 74 | |||
| 75 | // If there is an anonymous entry attached (e.g. for struct instantiation) and we take over ownership, delete it. | ||
| 76 | // Safe to call even if performStructAssign already deleted it: map::erase by key is a no-op when absent. | ||
| 77 |
7/8✓ Branch 57 → 58 taken 27615 times.
✗ Branch 57 → 145 not taken.
✓ Branch 58 → 59 taken 26422 times.
✓ Branch 58 → 61 taken 1193 times.
✓ Branch 59 → 60 taken 2386 times.
✓ Branch 59 → 61 taken 24036 times.
✓ Branch 62 → 63 taken 2386 times.
✓ Branch 62 → 64 taken 25229 times.
|
27615 | if (!localVarType.isRef() && rhsIsAnonymous) |
| 78 |
1/2✓ Branch 63 → 64 taken 2386 times.
✗ Branch 63 → 145 not taken.
|
2386 | currentScope->symbolTable.deleteAnonymous(rhsEntryName); |
| 79 | 27629 | } else { | |
| 80 | // Visit data type | ||
| 81 |
2/4✓ Branch 66 → 67 taken 65705 times.
✗ Branch 66 → 150 not taken.
✓ Branch 67 → 68 taken 65705 times.
✗ Branch 67 → 148 not taken.
|
65705 | localVarType = std::any_cast<QualType>(visit(node->dataType)); |
| 82 | |||
| 83 | // References with no initialization are illegal | ||
| 84 |
9/10✓ Branch 69 → 70 taken 65705 times.
✗ Branch 69 → 178 not taken.
✓ Branch 70 → 71 taken 18517 times.
✓ Branch 70 → 74 taken 47188 times.
✓ Branch 71 → 72 taken 476 times.
✓ Branch 71 → 74 taken 18041 times.
✓ Branch 72 → 73 taken 1 time.
✓ Branch 72 → 74 taken 475 times.
✓ Branch 75 → 76 taken 1 time.
✓ Branch 75 → 83 taken 65704 times.
|
65705 | if (localVarType.isRef() && !node->isFctParam && !node->isForEachItem) |
| 85 |
2/4✓ Branch 78 → 79 taken 1 time.
✗ Branch 78 → 154 not taken.
✓ Branch 79 → 80 taken 1 time.
✗ Branch 79 → 152 not taken.
|
2 | softError(node, REFERENCE_WITHOUT_INITIALIZER, "References must always be initialized directly"); |
| 86 | |||
| 87 | // If this is a struct, check for the default ctor | ||
| 88 |
9/10✓ Branch 83 → 84 taken 65705 times.
✗ Branch 83 → 178 not taken.
✓ Branch 84 → 85 taken 5682 times.
✓ Branch 84 → 88 taken 60023 times.
✓ Branch 85 → 86 taken 808 times.
✓ Branch 85 → 88 taken 4874 times.
✓ Branch 86 → 87 taken 788 times.
✓ Branch 86 → 88 taken 20 times.
✓ Branch 89 → 90 taken 788 times.
✓ Branch 89 → 116 taken 64917 times.
|
65705 | if (localVarType.is(TY_STRUCT) && !node->isFctParam && !node->isForEachItem) { |
| 89 |
1/2✓ Branch 90 → 91 taken 788 times.
✗ Branch 90 → 178 not taken.
|
788 | Scope *matchScope = localVarType.getBodyScope(); |
| 90 |
1/2✗ Branch 91 → 92 not taken.
✓ Branch 91 → 93 taken 788 times.
|
788 | assert(matchScope != nullptr); |
| 91 | // Check if we are required to call a ctor | ||
| 92 |
1/2✓ Branch 93 → 94 taken 788 times.
✗ Branch 93 → 178 not taken.
|
788 | node->isCtorCallRequired = !localVarType.isTriviallyConstructible(node); |
| 93 | // Check if we have a no-args ctor to call | ||
| 94 | 788 | const QualType &thisType = localVarType; | |
| 95 |
2/4✓ Branch 98 → 99 taken 788 times.
✗ Branch 98 → 160 not taken.
✓ Branch 99 → 100 taken 788 times.
✗ Branch 99 → 158 not taken.
|
2364 | node->calledInitCtor = FunctionManager::match(matchScope, CTOR_FUNCTION_NAME, thisType, {}, {}, false, node); |
| 96 |
4/4✓ Branch 104 → 105 taken 27 times.
✓ Branch 104 → 116 taken 761 times.
✓ Branch 105 → 106 taken 5 times.
✓ Branch 105 → 116 taken 22 times.
|
788 | if (node->calledInitCtor == nullptr && node->isCtorCallRequired) { |
| 97 |
1/2✓ Branch 106 → 107 taken 5 times.
✗ Branch 106 → 176 not taken.
|
5 | const std::string &structName = localVarType.getSubType(); |
| 98 |
2/4✓ Branch 107 → 108 taken 5 times.
✗ Branch 107 → 172 not taken.
✓ Branch 108 → 109 taken 5 times.
✗ Branch 108 → 170 not taken.
|
5 | const auto msg = "Struct '" + structName + "' is not trivially constructible and has no no-args constructor."; |
| 99 |
3/6✓ Branch 110 → 111 taken 5 times.
✗ Branch 110 → 174 not taken.
✓ Branch 111 → 112 taken 5 times.
✗ Branch 111 → 173 not taken.
✓ Branch 112 → 113 taken 5 times.
✗ Branch 112 → 173 not taken.
|
5 | SOFT_ERROR_QT(node, NO_MATCHING_CTOR_FOUND, msg); |
| 100 | 5 | } | |
| 101 | } | ||
| 102 | } | ||
| 103 | |||
| 104 | // Update the type of the variable | ||
| 105 |
1/2✓ Branch 116 → 117 taken 93315 times.
✗ Branch 116 → 178 not taken.
|
93315 | localVarEntry->updateType(localVarType, true); |
| 106 |
1/2✓ Branch 117 → 118 taken 93315 times.
✗ Branch 117 → 178 not taken.
|
93315 | node->entries.at(manIdx) = localVarEntry; |
| 107 | |||
| 108 | // Update the state of the variable | ||
| 109 |
1/2✓ Branch 118 → 119 taken 93315 times.
✗ Branch 118 → 177 not taken.
|
93315 | localVarEntry->updateState(INITIALIZED, node); |
| 110 | |||
| 111 |
1/2✓ Branch 119 → 120 taken 93315 times.
✗ Branch 119 → 178 not taken.
|
93315 | return localVarType; |
| 112 | } | ||
| 113 | |||
| 114 | 27350 | std::any TypeChecker::visitReturnStmt(ReturnStmtNode *node) { | |
| 115 | // Retrieve return variable entry | ||
| 116 |
1/2✓ Branch 4 → 5 taken 27350 times.
✗ Branch 4 → 100 not taken.
|
82050 | SymbolTableEntry *returnVar = currentScope->lookup(RETURN_VARIABLE_NAME); |
| 117 | 27350 | const bool isFunction = returnVar != nullptr; | |
| 118 |
4/6✓ Branch 10 → 11 taken 27045 times.
✓ Branch 10 → 13 taken 305 times.
✓ Branch 11 → 12 taken 27045 times.
✗ Branch 11 → 139 not taken.
✓ Branch 13 → 14 taken 305 times.
✗ Branch 13 → 139 not taken.
|
27350 | const QualType returnType = isFunction ? returnVar->getQualType() : QualType(TY_DYN); |
| 119 | |||
| 120 | // Check if procedure with return value | ||
| 121 |
2/2✓ Branch 14 → 15 taken 305 times.
✓ Branch 14 → 29 taken 27045 times.
|
27350 | if (!isFunction) { |
| 122 |
2/2✓ Branch 15 → 16 taken 2 times.
✓ Branch 15 → 26 taken 303 times.
|
305 | if (node->hasReturnValue) |
| 123 |
4/8✓ Branch 18 → 19 taken 2 times.
✗ Branch 18 → 106 not taken.
✓ Branch 19 → 20 taken 2 times.
✗ Branch 19 → 104 not taken.
✓ Branch 22 → 23 taken 2 times.
✗ Branch 22 → 110 not taken.
✓ Branch 23 → 24 taken 2 times.
✗ Branch 23 → 110 not taken.
|
8 | SOFT_ERROR_ER(node->assignExpr, RETURN_WITH_VALUE_IN_PROCEDURE, "Return with value in procedure is not allowed") |
| 124 |
1/2✓ Branch 26 → 27 taken 303 times.
✗ Branch 26 → 111 not taken.
|
606 | return nullptr; |
| 125 | } | ||
| 126 | |||
| 127 |
7/8✓ Branch 29 → 30 taken 9 times.
✓ Branch 29 → 34 taken 27036 times.
✓ Branch 31 → 32 taken 9 times.
✗ Branch 31 → 139 not taken.
✓ Branch 32 → 33 taken 2 times.
✓ Branch 32 → 34 taken 7 times.
✓ Branch 35 → 36 taken 2 times.
✓ Branch 35 → 46 taken 27043 times.
|
27045 | if (!node->hasReturnValue && !returnVar->getLifecycle().isInitialized()) |
| 128 |
4/8✓ Branch 38 → 39 taken 2 times.
✗ Branch 38 → 114 not taken.
✓ Branch 39 → 40 taken 2 times.
✗ Branch 39 → 112 not taken.
✓ Branch 42 → 43 taken 2 times.
✗ Branch 42 → 118 not taken.
✓ Branch 43 → 44 taken 2 times.
✗ Branch 43 → 118 not taken.
|
8 | SOFT_ERROR_QT(node, RETURN_WITHOUT_VALUE_RESULT, "Return without value, but result variable is not initialized yet") |
| 129 | |||
| 130 |
2/2✓ Branch 46 → 47 taken 7 times.
✓ Branch 46 → 50 taken 27036 times.
|
27043 | if (!node->hasReturnValue) |
| 131 |
1/2✓ Branch 47 → 48 taken 7 times.
✗ Branch 47 → 119 not taken.
|
14 | return nullptr; |
| 132 | |||
| 133 | // Visit right side | ||
| 134 |
2/4✓ Branch 50 → 51 taken 27036 times.
✗ Branch 50 → 122 not taken.
✓ Branch 51 → 52 taken 27036 times.
✗ Branch 51 → 120 not taken.
|
27036 | const auto rhs = std::any_cast<ExprResult>(visit(node->assignExpr)); |
| 135 |
2/6✓ Branch 53 → 54 taken 27036 times.
✗ Branch 53 → 139 not taken.
✗ Branch 54 → 55 not taken.
✓ Branch 54 → 57 taken 27036 times.
✗ Branch 55 → 56 not taken.
✗ Branch 55 → 139 not taken.
|
27036 | HANDLE_UNRESOLVED_TYPE_QT(rhs.type) |
| 136 | |||
| 137 | // A native lambda stores its captures in this frame, so returning a capturing lambda would let it outlive its | ||
| 138 | // captures. Direct the user to the owning std Lambda wrapper. Non-capturing lambdas (plain function pointers) | ||
| 139 | // are safe to return. The std Lambda wrapper hands its captures-flagged lambda back from get(), so std is exempt. | ||
| 140 |
10/14✓ Branch 57 → 58 taken 27036 times.
✗ Branch 57 → 123 not taken.
✓ Branch 58 → 59 taken 27036 times.
✗ Branch 58 → 123 not taken.
✓ Branch 59 → 60 taken 32 times.
✓ Branch 59 → 64 taken 27004 times.
✓ Branch 60 → 61 taken 32 times.
✗ Branch 60 → 123 not taken.
✓ Branch 61 → 62 taken 1 time.
✓ Branch 61 → 64 taken 31 times.
✓ Branch 62 → 63 taken 1 time.
✗ Branch 62 → 64 not taken.
✓ Branch 65 → 66 taken 1 time.
✓ Branch 65 → 79 taken 27035 times.
|
27036 | if (rhs.type.getBase().isOneOf({TY_FUNCTION, TY_PROCEDURE}) && rhs.type.hasLambdaCaptures() && !sourceFile->isStdFile) |
| 141 |
8/16✓ Branch 66 → 67 taken 1 time.
✗ Branch 66 → 131 not taken.
✓ Branch 67 → 68 taken 1 time.
✗ Branch 67 → 131 not taken.
✓ Branch 68 → 69 taken 1 time.
✗ Branch 68 → 131 not taken.
✓ Branch 69 → 70 taken 1 time.
✗ Branch 69 → 129 not taken.
✓ Branch 70 → 71 taken 1 time.
✗ Branch 70 → 127 not taken.
✓ Branch 71 → 72 taken 1 time.
✗ Branch 71 → 125 not taken.
✓ Branch 75 → 76 taken 1 time.
✗ Branch 75 → 136 not taken.
✓ Branch 76 → 77 taken 1 time.
✗ Branch 76 → 136 not taken.
|
2 | SOFT_ERROR_ER(node->assignExpr, LAMBDA_CAPTURE_ESCAPE, |
| 142 | "A capturing lambda cannot be returned, because its captures live in this frame and would dangle. " | ||
| 143 | "Wrap it in 'Lambda<" + | ||
| 144 | rhs.type.getBase().getWithLambdaCaptures(false).getName(false) + ">' from std/type/lambda instead.") | ||
| 145 | |||
| 146 | // Capture anonymous info up front: getAssignResultType may delete the anonymous entry (temp stealing | ||
| 147 | // in performStructAssign), turning rhs.entry into a dangling pointer. | ||
| 148 |
4/4✓ Branch 79 → 80 taken 8161 times.
✓ Branch 79 → 82 taken 18874 times.
✓ Branch 80 → 81 taken 3254 times.
✓ Branch 80 → 82 taken 4907 times.
|
27035 | const bool rhsIsAnonymous = rhs.entry != nullptr && rhs.entry->anonymous; |
| 149 |
3/4✓ Branch 83 → 84 taken 3254 times.
✓ Branch 83 → 85 taken 23781 times.
✓ Branch 84 → 86 taken 3254 times.
✗ Branch 84 → 139 not taken.
|
27035 | const std::string rhsEntryName = rhsIsAnonymous ? rhs.entry->name : std::string(); |
| 150 | |||
| 151 | // Check if types match | ||
| 152 | 27035 | const ExprResult returnResult = {returnType, returnVar}; | |
| 153 |
2/2✓ Branch 86 → 87 taken 27032 times.
✓ Branch 86 → 137 taken 3 times.
|
27035 | auto [_, copyCtor] = opRuleManager.getAssignResultType(node->assignExpr, returnResult, rhs, false, true, ERROR_MSG_RETURN); |
| 154 | 27032 | node->calledCopyCtor = copyCtor; | |
| 155 | |||
| 156 | // Check if the dtor call on the return value can be skipped | ||
| 157 |
2/2✓ Branch 89 → 90 taken 8161 times.
✓ Branch 89 → 93 taken 18871 times.
|
27032 | if (rhs.entry != nullptr) { |
| 158 |
2/2✓ Branch 90 → 91 taken 3254 times.
✓ Branch 90 → 92 taken 4907 times.
|
8161 | if (rhsIsAnonymous) { |
| 159 | // If there is an anonymous entry attached (e.g. for struct instantiation), delete it. | ||
| 160 | // Safe even if performStructAssign already deleted it: map::erase by key is a no-op when absent. | ||
| 161 |
1/2✓ Branch 91 → 93 taken 3254 times.
✗ Branch 91 → 137 not taken.
|
3254 | currentScope->symbolTable.deleteAnonymous(rhsEntryName); |
| 162 | } else { | ||
| 163 | // Otherwise omit the destructor call, because the caller destructs the value | ||
| 164 | 4907 | rhs.entry->omitDtorCall = true; | |
| 165 | } | ||
| 166 | } | ||
| 167 | |||
| 168 |
1/2✓ Branch 93 → 94 taken 27032 times.
✗ Branch 93 → 137 not taken.
|
27032 | return node->returnType = returnType; |
| 169 | 27035 | } | |
| 170 | |||
| 171 | 240 | std::any TypeChecker::visitBreakStmt(BreakStmtNode *node) { | |
| 172 | // Check if the stated number is valid | ||
| 173 |
2/2✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 12 taken 239 times.
|
240 | if (node->breakTimes < 1) |
| 174 |
4/8✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 31 not taken.
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 29 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 35 not taken.
✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 35 not taken.
|
2 | SOFT_ERROR_ER(node, INVALID_BREAK_NUMBER, "Break count must be >= 1, you provided " + std::to_string(node->breakTimes)) |
| 175 | |||
| 176 | // Check if we can break this often | ||
| 177 | 239 | const unsigned int maxBreaks = currentScope->getLoopNestingDepth(); | |
| 178 |
2/2✓ Branch 13 → 14 taken 1 time.
✓ Branch 13 → 25 taken 238 times.
|
239 | if (static_cast<unsigned int>(node->breakTimes) > maxBreaks) |
| 179 |
5/10✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 40 not taken.
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 38 not taken.
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 36 not taken.
✓ Branch 21 → 22 taken 1 time.
✗ Branch 21 → 45 not taken.
✓ Branch 22 → 23 taken 1 time.
✗ Branch 22 → 45 not taken.
|
2 | SOFT_ERROR_ER(node, INVALID_BREAK_NUMBER, "We can only break " + std::to_string(maxBreaks) + " time(s) here") |
| 180 | |||
| 181 |
1/2✓ Branch 25 → 26 taken 238 times.
✗ Branch 25 → 46 not taken.
|
476 | return nullptr; |
| 182 | } | ||
| 183 | |||
| 184 | 749 | std::any TypeChecker::visitContinueStmt(ContinueStmtNode *node) { | |
| 185 | // Check if the stated number is valid | ||
| 186 |
2/2✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 12 taken 748 times.
|
749 | if (node->continueTimes < 1) |
| 187 |
4/8✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 31 not taken.
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 29 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 35 not taken.
✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 35 not taken.
|
2 | SOFT_ERROR_ER(node, INVALID_CONTINUE_NUMBER, |
| 188 | "Continue count must be >= 1, you provided " + std::to_string(node->continueTimes)) | ||
| 189 | |||
| 190 | // Check if we can continue this often | ||
| 191 | 748 | const unsigned int maxContinues = currentScope->getLoopNestingDepth(); | |
| 192 |
2/2✓ Branch 13 → 14 taken 1 time.
✓ Branch 13 → 25 taken 747 times.
|
748 | if (static_cast<unsigned int>(node->continueTimes) > maxContinues) |
| 193 |
5/10✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 40 not taken.
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 38 not taken.
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 36 not taken.
✓ Branch 21 → 22 taken 1 time.
✗ Branch 21 → 45 not taken.
✓ Branch 22 → 23 taken 1 time.
✗ Branch 22 → 45 not taken.
|
2 | SOFT_ERROR_ER(node, INVALID_CONTINUE_NUMBER, "We can only continue " + std::to_string(maxContinues) + " time(s) here") |
| 194 | |||
| 195 |
1/2✓ Branch 25 → 26 taken 747 times.
✗ Branch 25 → 46 not taken.
|
1494 | return nullptr; |
| 196 | } | ||
| 197 | |||
| 198 | 6 | std::any TypeChecker::visitFallthroughStmt(FallthroughStmtNode *node) { | |
| 199 | // Check if we can do a fallthrough here | ||
| 200 |
2/2✓ Branch 3 → 4 taken 2 times.
✓ Branch 3 → 14 taken 4 times.
|
6 | if (!currentScope->isInCaseBranch()) |
| 201 |
4/8✓ Branch 6 → 7 taken 2 times.
✗ Branch 6 → 20 not taken.
✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 18 not taken.
✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 24 not taken.
✓ Branch 11 → 12 taken 2 times.
✗ Branch 11 → 24 not taken.
|
8 | SOFT_ERROR_ER(node, FALLTHROUGH_NOT_ALLOWED, "Fallthrough is only allowed in case branches") |
| 202 | |||
| 203 |
1/2✓ Branch 14 → 15 taken 4 times.
✗ Branch 14 → 25 not taken.
|
8 | return nullptr; |
| 204 | } | ||
| 205 | |||
| 206 | 4666 | std::any TypeChecker::visitAssertStmt(AssertStmtNode *node) { | |
| 207 | // Visit condition | ||
| 208 |
2/4✓ Branch 2 → 3 taken 4666 times.
✗ Branch 2 → 30 not taken.
✓ Branch 3 → 4 taken 4666 times.
✗ Branch 3 → 28 not taken.
|
4666 | const QualType conditionType = std::any_cast<ExprResult>(visit(node->assignExpr)).type; |
| 209 |
2/8✓ Branch 5 → 6 taken 4666 times.
✗ Branch 5 → 41 not taken.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 11 taken 4666 times.
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 32 not taken.
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 32 not taken.
|
4666 | HANDLE_UNRESOLVED_TYPE_ER(conditionType) |
| 210 | |||
| 211 | // Check if condition evaluates to bool | ||
| 212 |
3/4✓ Branch 11 → 12 taken 4666 times.
✗ Branch 11 → 41 not taken.
✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 23 taken 4665 times.
|
4666 | if (!conditionType.is(TY_BOOL)) |
| 213 |
4/8✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 35 not taken.
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 33 not taken.
✓ Branch 19 → 20 taken 1 time.
✗ Branch 19 → 39 not taken.
✓ Branch 20 → 21 taken 1 time.
✗ Branch 20 → 39 not taken.
|
4 | SOFT_ERROR_ER(node->assignExpr, ASSERTION_CONDITION_BOOL, "The asserted condition must be of type bool") |
| 214 | |||
| 215 |
1/2✓ Branch 23 → 24 taken 4665 times.
✗ Branch 23 → 40 not taken.
|
9330 | return nullptr; |
| 216 | } | ||
| 217 | |||
| 218 | } // namespace spice::compiler | ||
| 219 |