src/typechecker/TypeCheckerTopLevelDefinitions.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2026 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #include "TypeChecker.h" | ||
| 4 | |||
| 5 | #include <ast/ASTNodes.h> | ||
| 6 | #include <global/TypeRegistry.h> | ||
| 7 | |||
| 8 | namespace spice::compiler { | ||
| 9 | |||
| 10 | 1071 | std::any TypeChecker::visitMainFctDef(MainFctDefNode *node) { | |
| 11 |
2/2✓ Branch 2 → 3 taken 504 times.
✓ Branch 2 → 4 taken 567 times.
|
1071 | if (typeCheckerMode == TC_MODE_PRE) |
| 12 | 504 | return visitMainFctDefPrepare(node); | |
| 13 | else | ||
| 14 | 567 | return visitMainFctDefCheck(node); | |
| 15 | } | ||
| 16 | |||
| 17 | 61627 | std::any TypeChecker::visitFctDef(FctDefNode *node) { | |
| 18 |
2/2✓ Branch 2 → 3 taken 19896 times.
✓ Branch 2 → 4 taken 41731 times.
|
61627 | if (typeCheckerMode == TC_MODE_PRE) |
| 19 | 19896 | return visitFctDefPrepare(node); | |
| 20 | else | ||
| 21 | 41731 | return visitFctDefCheck(node); | |
| 22 | } | ||
| 23 | |||
| 24 | 33072 | std::any TypeChecker::visitProcDef(ProcDefNode *node) { | |
| 25 |
2/2✓ Branch 2 → 3 taken 10528 times.
✓ Branch 2 → 4 taken 22544 times.
|
33072 | if (typeCheckerMode == TC_MODE_PRE) |
| 26 | 10528 | return visitProcDefPrepare(node); | |
| 27 | else | ||
| 28 | 22544 | return visitProcDefCheck(node); | |
| 29 | } | ||
| 30 | |||
| 31 | 8085 | std::any TypeChecker::visitStructDef(StructDefNode *node) { | |
| 32 |
2/2✓ Branch 2 → 3 taken 2802 times.
✓ Branch 2 → 4 taken 5283 times.
|
8085 | if (typeCheckerMode == TC_MODE_PRE) |
| 33 | 2802 | return visitStructDefPrepare(node); | |
| 34 | else | ||
| 35 | 5283 | return visitStructDefCheck(node); | |
| 36 | } | ||
| 37 | |||
| 38 | 786 | std::any TypeChecker::visitInterfaceDef(InterfaceDefNode *node) { | |
| 39 |
2/2✓ Branch 2 → 3 taken 363 times.
✓ Branch 2 → 4 taken 423 times.
|
786 | if (typeCheckerMode == TC_MODE_PRE) |
| 40 | 363 | return visitInterfaceDefPrepare(node); | |
| 41 |
1/2✓ Branch 4 → 5 taken 423 times.
✗ Branch 4 → 8 not taken.
|
846 | return nullptr; |
| 42 | } | ||
| 43 | |||
| 44 | 12 | std::any TypeChecker::visitForwardDecl(ForwardDeclNode *node) { | |
| 45 |
2/2✓ Branch 2 → 3 taken 6 times.
✓ Branch 2 → 6 taken 6 times.
|
12 | if (typeCheckerMode != TC_MODE_PRE) |
| 46 |
1/2✓ Branch 3 → 4 taken 6 times.
✗ Branch 3 → 29 not taken.
|
12 | return nullptr; |
| 47 | |||
| 48 |
2/4✓ Branch 6 → 7 taken 6 times.
✗ Branch 6 → 9 not taken.
✓ Branch 7 → 8 taken 6 times.
✗ Branch 7 → 9 not taken.
|
6 | assert(node->entry != nullptr && node->typeScope != nullptr); |
| 49 | // A duplicate forward declaration shares its entry with the original; the entry's type is already populated. | ||
| 50 |
4/6✓ Branch 10 → 11 taken 6 times.
✗ Branch 10 → 38 not taken.
✓ Branch 11 → 12 taken 6 times.
✗ Branch 11 → 30 not taken.
✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 16 taken 5 times.
|
6 | if (!node->entry->getQualType().isOneOf({TY_INVALID, TY_DYN})) |
| 51 |
1/2✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 32 not taken.
|
2 | return nullptr; |
| 52 | 5 | const TypeChainElementData data = {.bodyScope = node->typeScope}; | |
| 53 |
1/2✓ Branch 16 → 17 taken 5 times.
✗ Branch 16 → 18 not taken.
|
5 | const SuperType superType = node->isStruct ? TY_STRUCT : TY_INTERFACE; |
| 54 |
1/2✓ Branch 20 → 21 taken 5 times.
✗ Branch 20 → 33 not taken.
|
5 | const Type *type = TypeRegistry::getOrInsert(superType, node->typeName, node->typeId, data, {}); |
| 55 |
2/4✓ Branch 22 → 23 taken 5 times.
✗ Branch 22 → 36 not taken.
✓ Branch 23 → 24 taken 5 times.
✗ Branch 23 → 36 not taken.
|
5 | node->entry->updateType(QualType(type, node->qualifiers), false); |
| 56 |
1/2✓ Branch 24 → 25 taken 5 times.
✗ Branch 24 → 37 not taken.
|
10 | return nullptr; |
| 57 | } | ||
| 58 | |||
| 59 | 1053 | std::any TypeChecker::visitEnumDef(EnumDefNode *node) { | |
| 60 |
2/2✓ Branch 2 → 3 taken 366 times.
✓ Branch 2 → 4 taken 687 times.
|
1053 | if (typeCheckerMode == TC_MODE_PRE) |
| 61 | 366 | return visitEnumDefPrepare(node); | |
| 62 |
1/2✓ Branch 4 → 5 taken 687 times.
✗ Branch 4 → 8 not taken.
|
1374 | return nullptr; |
| 63 | } | ||
| 64 | |||
| 65 | 6031 | std::any TypeChecker::visitGenericTypeDef(GenericTypeDefNode *node) { | |
| 66 |
2/2✓ Branch 2 → 3 taken 1921 times.
✓ Branch 2 → 4 taken 4110 times.
|
6031 | if (typeCheckerMode == TC_MODE_PRE) |
| 67 | 1921 | return visitGenericTypeDefPrepare(node); | |
| 68 |
1/2✓ Branch 4 → 5 taken 4110 times.
✗ Branch 4 → 8 not taken.
|
8220 | return nullptr; |
| 69 | } | ||
| 70 | |||
| 71 | 956 | std::any TypeChecker::visitAliasDef(AliasDefNode *node) { | |
| 72 |
2/2✓ Branch 2 → 3 taken 340 times.
✓ Branch 2 → 4 taken 616 times.
|
956 | if (typeCheckerMode == TC_MODE_PRE) |
| 73 | 340 | return visitAliasDefPrepare(node); | |
| 74 |
1/2✓ Branch 4 → 5 taken 616 times.
✗ Branch 4 → 8 not taken.
|
1232 | return nullptr; |
| 75 | } | ||
| 76 | |||
| 77 | 5723 | std::any TypeChecker::visitGlobalVarDef(GlobalVarDefNode *node) { | |
| 78 |
2/2✓ Branch 2 → 3 taken 2363 times.
✓ Branch 2 → 4 taken 3360 times.
|
5723 | if (typeCheckerMode == TC_MODE_PRE) |
| 79 | 2363 | return visitGlobalVarDefPrepare(node); | |
| 80 |
1/2✓ Branch 4 → 5 taken 3360 times.
✗ Branch 4 → 8 not taken.
|
6720 | return nullptr; |
| 81 | } | ||
| 82 | |||
| 83 | 8657 | std::any TypeChecker::visitExtDecl(ExtDeclNode *node) { | |
| 84 |
2/2✓ Branch 2 → 3 taken 2961 times.
✓ Branch 2 → 4 taken 5696 times.
|
8657 | if (typeCheckerMode == TC_MODE_PRE) |
| 85 | 2961 | return visitExtDeclPrepare(node); | |
| 86 |
1/2✓ Branch 4 → 5 taken 5696 times.
✗ Branch 4 → 8 not taken.
|
11392 | return nullptr; |
| 87 | } | ||
| 88 | |||
| 89 | 7220 | std::any TypeChecker::visitImportDef(ImportDefNode *node) { | |
| 90 |
2/2✓ Branch 2 → 3 taken 2518 times.
✓ Branch 2 → 4 taken 4702 times.
|
7220 | if (typeCheckerMode == TC_MODE_PRE) |
| 91 | 2518 | return visitImportDefPrepare(node); | |
| 92 |
1/2✓ Branch 4 → 5 taken 4702 times.
✗ Branch 4 → 8 not taken.
|
9404 | return nullptr; |
| 93 | } | ||
| 94 | |||
| 95 | } // namespace spice::compiler | ||
| 96 |