src/symboltablebuilder/SymbolTableBuilder.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2026 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #include "SymbolTableBuilder.h" | ||
| 4 | |||
| 5 | #include <SourceFile.h> | ||
| 6 | #include <ast/ASTBuilder.h> | ||
| 7 | #include <ast/Attributes.h> | ||
| 8 | #include <driver/Driver.h> | ||
| 9 | #include <exception/SemanticError.h> | ||
| 10 | #include <global/GlobalResourceManager.h> | ||
| 11 | #include <model/Function.h> | ||
| 12 | #include <symboltablebuilder/Scope.h> | ||
| 13 | |||
| 14 | namespace spice::compiler { | ||
| 15 | |||
| 16 | 2403 | SymbolTableBuilder::SymbolTableBuilder(GlobalResourceManager &resourceManager, SourceFile *sourceFile) | |
| 17 | 2403 | : CompilerPass(resourceManager, sourceFile), rootScope(sourceFile->globalScope.get()) {} | |
| 18 | |||
| 19 | 2403 | std::any SymbolTableBuilder::visitEntry(EntryNode *node) { | |
| 20 | // Initialize | ||
| 21 | 2403 | currentScope = rootScope; | |
| 22 | |||
| 23 | // Visit children | ||
| 24 |
2/2✓ Branch 2 → 3 taken 2385 times.
✓ Branch 2 → 23 taken 18 times.
|
2403 | visitChildren(node); |
| 25 | |||
| 26 | // Check if the main function exists | ||
| 27 |
4/4✓ Branch 4 → 5 taken 2382 times.
✓ Branch 4 → 7 taken 3 times.
✓ Branch 5 → 6 taken 2377 times.
✓ Branch 5 → 7 taken 5 times.
|
2385 | const bool mainFctRequired = cliOptions.outputContainer == OutputContainer::EXECUTABLE && !cliOptions.noEntryFct; |
| 28 |
6/6✓ Branch 8 → 9 taken 524 times.
✓ Branch 8 → 19 taken 1861 times.
✓ Branch 9 → 10 taken 517 times.
✓ Branch 9 → 19 taken 7 times.
✓ Branch 10 → 11 taken 2 times.
✓ Branch 10 → 19 taken 515 times.
|
2385 | if (sourceFile->isMainFile && mainFctRequired && !hasMainFunction) |
| 29 |
2/4✓ Branch 14 → 15 taken 2 times.
✗ Branch 14 → 27 not taken.
✓ Branch 15 → 16 taken 2 times.
✗ Branch 15 → 24 not taken.
|
6 | throw SemanticError(node, MISSING_MAIN_FUNCTION, "No main function found", false); |
| 30 | |||
| 31 |
1/2✓ Branch 19 → 20 taken 2383 times.
✗ Branch 19 → 33 not taken.
|
4766 | return nullptr; |
| 32 | } | ||
| 33 | |||
| 34 | 520 | std::any SymbolTableBuilder::visitMainFctDef(MainFctDefNode *node) { | |
| 35 | // Visit attributes | ||
| 36 |
2/2✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 6 taken 519 times.
|
520 | if (node->attrs) |
| 37 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 52 taken 1 time.
|
1 | visit(node->attrs); |
| 38 | |||
| 39 | // Check if the function is already defined | ||
| 40 |
3/4✓ Branch 8 → 9 taken 519 times.
✗ Branch 8 → 55 not taken.
✓ Branch 14 → 15 taken 1 time.
✓ Branch 14 → 23 taken 518 times.
|
2076 | if (rootScope->lookupStrict(MAIN_FUNCTION_NAME)) |
| 41 |
2/4✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 62 not taken.
✓ Branch 19 → 20 taken 1 time.
✗ Branch 19 → 59 not taken.
|
3 | throw SemanticError(node, FUNCTION_DECLARED_TWICE, "Main function is declared twice"); |
| 42 | |||
| 43 | // Insert symbol for main function | ||
| 44 |
1/2✓ Branch 25 → 26 taken 518 times.
✗ Branch 25 → 70 not taken.
|
1554 | SymbolTableEntry *mainFctEntry = currentScope->insert(MAIN_FUNCTION_NAME, node); |
| 45 | 518 | mainFctEntry->used = true; | |
| 46 | |||
| 47 | // Create scope for main function body | ||
| 48 |
1/2✓ Branch 31 → 32 taken 518 times.
✗ Branch 31 → 85 not taken.
|
518 | const std::string &scopeId = MainFctDefNode::getScopeId(); |
| 49 |
1/2✓ Branch 32 → 33 taken 518 times.
✗ Branch 32 → 83 not taken.
|
518 | node->bodyScope = currentScope = rootScope->createChildScope(scopeId, ScopeType::FUNC_PROC_BODY, &node->codeLoc); |
| 50 | 518 | currentScope->isGenericScope = false; | |
| 51 | |||
| 52 | // Declare variable for the return value in the function scope | ||
| 53 |
1/2✓ Branch 35 → 36 taken 518 times.
✗ Branch 35 → 76 not taken.
|
1554 | SymbolTableEntry *resultVarEntry = node->bodyScope->insert(RETURN_VARIABLE_NAME, node); |
| 54 | 518 | resultVarEntry->used = true; | |
| 55 | |||
| 56 | // Visit arguments in new scope | ||
| 57 |
2/2✓ Branch 41 → 42 taken 7 times.
✓ Branch 41 → 45 taken 511 times.
|
518 | if (node->takesArgs) |
| 58 |
1/2✓ Branch 42 → 43 taken 7 times.
✗ Branch 42 → 80 not taken.
|
7 | visit(node->paramLst); |
| 59 | |||
| 60 | // Visit function body in new scope | ||
| 61 |
2/2✓ Branch 45 → 46 taken 517 times.
✓ Branch 45 → 81 taken 1 time.
|
518 | visit(node->body); |
| 62 | |||
| 63 | // Return to root scope | ||
| 64 | 517 | currentScope = rootScope; | |
| 65 | |||
| 66 | 517 | hasMainFunction = true; | |
| 67 |
1/2✓ Branch 47 → 48 taken 517 times.
✗ Branch 47 → 82 not taken.
|
1034 | return nullptr; |
| 68 | 518 | } | |
| 69 | |||
| 70 | 19950 | std::any SymbolTableBuilder::visitFctDef(FctDefNode *node) { | |
| 71 | // Visit attributes | ||
| 72 |
2/2✓ Branch 2 → 3 taken 692 times.
✓ Branch 2 → 6 taken 19258 times.
|
19950 | if (node->attrs) |
| 73 |
1/2✓ Branch 3 → 4 taken 692 times.
✗ Branch 3 → 98 not taken.
|
692 | visit(node->attrs); |
| 74 | |||
| 75 | // Build function qualifiers | ||
| 76 |
2/2✓ Branch 6 → 7 taken 19326 times.
✓ Branch 6 → 36 taken 624 times.
|
19950 | if (const QualifierLstNode *qualifierLst = node->qualifierLst; qualifierLst) { |
| 77 |
2/2✓ Branch 34 → 9 taken 24814 times.
✓ Branch 34 → 35 taken 19326 times.
|
63466 | for (const QualifierNode *qualifier : qualifierLst->qualifiers) { |
| 78 |
2/2✓ Branch 11 → 12 taken 5491 times.
✓ Branch 11 → 13 taken 19323 times.
|
24814 | if (qualifier->type == QualifierNode::QualifierType::TY_INLINE) |
| 79 | 5491 | node->qualifiers.isInline = true; | |
| 80 |
2/2✓ Branch 13 → 14 taken 19211 times.
✓ Branch 13 → 15 taken 112 times.
|
19323 | else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC) |
| 81 | 19211 | node->qualifiers.isPublic = true; | |
| 82 |
1/2✓ Branch 15 → 16 taken 112 times.
✗ Branch 15 → 17 not taken.
|
112 | else if (qualifier->type == QualifierNode::QualifierType::TY_CONST) |
| 83 | 112 | node->qualifiers.isConst = true; | |
| 84 | else | ||
| 85 | ✗ | throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on a function definition"); | |
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | // Change to struct scope if this function is a method | ||
| 90 |
2/2✓ Branch 36 → 37 taken 9933 times.
✓ Branch 36 → 51 taken 10017 times.
|
19950 | if (node->isMethod) { |
| 91 |
1/2✓ Branch 38 → 39 taken 9933 times.
✗ Branch 38 → 109 not taken.
|
9933 | const std::string scopeName = Struct::getScopeName(node->name->structName); |
| 92 |
1/2✓ Branch 40 → 41 taken 9933 times.
✗ Branch 40 → 121 not taken.
|
9933 | node->structScope = currentScope = currentScope->getChildScope(scopeName); |
| 93 |
1/2✗ Branch 41 → 42 not taken.
✓ Branch 41 → 49 taken 9933 times.
|
9933 | if (!currentScope) |
| 94 | ✗ | throw SemanticError(node, REFERENCED_UNDEFINED_STRUCT, "Struct '" + node->name->structName + "' could not be found"); | |
| 95 | 9933 | } | |
| 96 | |||
| 97 | // Create scope for the function | ||
| 98 |
2/4✓ Branch 51 → 52 taken 19950 times.
✗ Branch 51 → 126 not taken.
✓ Branch 52 → 53 taken 19950 times.
✗ Branch 52 → 124 not taken.
|
19950 | node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc); |
| 99 |
6/6✓ Branch 54 → 55 taken 17866 times.
✓ Branch 54 → 57 taken 2084 times.
✓ Branch 55 → 56 taken 9628 times.
✓ Branch 55 → 58 taken 8238 times.
✓ Branch 56 → 57 taken 2572 times.
✓ Branch 56 → 58 taken 7056 times.
|
19950 | currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope); |
| 100 | |||
| 101 | // Create symbol for 'this' variable | ||
| 102 |
2/2✓ Branch 59 → 60 taken 9933 times.
✓ Branch 59 → 69 taken 10017 times.
|
19950 | if (node->isMethod) |
| 103 |
1/2✓ Branch 62 → 63 taken 9933 times.
✗ Branch 62 → 129 not taken.
|
39732 | currentScope->insert(THIS_VARIABLE_NAME, node); |
| 104 | |||
| 105 | // Create symbol for 'result' variable | ||
| 106 |
1/2✓ Branch 71 → 72 taken 19950 times.
✗ Branch 71 → 135 not taken.
|
59850 | currentScope->insert(RETURN_VARIABLE_NAME, node); |
| 107 | |||
| 108 | // Create symbols for the parameters | ||
| 109 |
2/2✓ Branch 77 → 78 taken 14757 times.
✓ Branch 77 → 81 taken 5193 times.
|
19950 | if (node->hasParams) |
| 110 |
1/2✓ Branch 78 → 79 taken 14757 times.
✗ Branch 78 → 139 not taken.
|
14757 | visit(node->paramLst); |
| 111 | |||
| 112 | // Visit the function body | ||
| 113 |
1/2✓ Branch 81 → 82 taken 19950 times.
✗ Branch 81 → 140 not taken.
|
19950 | visit(node->body); |
| 114 | |||
| 115 | // Leave function body scope | ||
| 116 | 19950 | currentScope = node->scope->parent; | |
| 117 | |||
| 118 | // Insert symbol for function into the symbol table | ||
| 119 |
1/2✓ Branch 83 → 84 taken 19950 times.
✗ Branch 83 → 143 not taken.
|
39900 | node->entry = currentScope->insert(node->getSymbolTableEntryName(), node); |
| 120 | |||
| 121 | // Add to external name registry | ||
| 122 | // if a function has overloads, they both refer to the same entry in the registry. So we only register the name once | ||
| 123 | 19950 | const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName); | |
| 124 |
3/4✓ Branch 89 → 90 taken 4558 times.
✓ Branch 89 → 91 taken 15392 times.
✓ Branch 90 → 91 taken 4558 times.
✗ Branch 90 → 92 not taken.
|
19950 | if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry) |
| 125 | 19950 | sourceFile->addNameRegistryEntry(node->name->fqName, TY_FUNCTION, node->entry, currentScope, true); | |
| 126 | |||
| 127 | // Leave the struct scope | ||
| 128 |
2/2✓ Branch 92 → 93 taken 9933 times.
✓ Branch 92 → 94 taken 10017 times.
|
19950 | if (node->isMethod) |
| 129 | 9933 | currentScope = node->structScope->parent; | |
| 130 | |||
| 131 |
1/2✓ Branch 94 → 95 taken 19950 times.
✗ Branch 94 → 144 not taken.
|
39900 | return nullptr; |
| 132 | } | ||
| 133 | |||
| 134 | 10598 | std::any SymbolTableBuilder::visitProcDef(ProcDefNode *node) { | |
| 135 | // Visit attributes | ||
| 136 |
2/2✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 6 taken 10597 times.
|
10598 | if (node->attrs) |
| 137 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 97 taken 1 time.
|
1 | visit(node->attrs); |
| 138 | |||
| 139 | // Build procedure qualifiers | ||
| 140 |
2/2✓ Branch 6 → 7 taken 9580 times.
✓ Branch 6 → 36 taken 1017 times.
|
10597 | if (const QualifierLstNode *qualifierLst = node->qualifierLst) { |
| 141 |
2/2✓ Branch 34 → 9 taken 10698 times.
✓ Branch 34 → 35 taken 9580 times.
|
29858 | for (const QualifierNode *qualifier : qualifierLst->qualifiers) { |
| 142 |
2/2✓ Branch 11 → 12 taken 1120 times.
✓ Branch 11 → 13 taken 9578 times.
|
10698 | if (qualifier->type == QualifierNode::QualifierType::TY_INLINE) |
| 143 | 1120 | node->qualifiers.isInline = true; | |
| 144 |
2/2✓ Branch 13 → 14 taken 9575 times.
✓ Branch 13 → 15 taken 3 times.
|
9578 | else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC) |
| 145 | 9575 | node->qualifiers.isPublic = true; | |
| 146 |
1/2✓ Branch 15 → 16 taken 3 times.
✗ Branch 15 → 17 not taken.
|
3 | else if (qualifier->type == QualifierNode::QualifierType::TY_CONST) |
| 147 | 3 | node->qualifiers.isConst = true; | |
| 148 | else | ||
| 149 | ✗ | throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on a procedure definition"); | |
| 150 | } | ||
| 151 | } | ||
| 152 | |||
| 153 | // Change to struct scope if this procedure is a method | ||
| 154 |
2/2✓ Branch 36 → 37 taken 8826 times.
✓ Branch 36 → 51 taken 1771 times.
|
10597 | if (node->isMethod) { |
| 155 |
1/2✓ Branch 38 → 39 taken 8826 times.
✗ Branch 38 → 108 not taken.
|
8826 | const std::string &scopeName = Struct::getScopeName(node->name->structName); |
| 156 |
1/2✓ Branch 40 → 41 taken 8826 times.
✗ Branch 40 → 120 not taken.
|
8826 | node->structScope = currentScope = currentScope->getChildScope(scopeName); |
| 157 |
2/2✓ Branch 41 → 42 taken 1 time.
✓ Branch 41 → 49 taken 8825 times.
|
8826 | if (!currentScope) |
| 158 |
3/6✓ Branch 43 → 44 taken 1 time.
✗ Branch 43 → 116 not taken.
✓ Branch 44 → 45 taken 1 time.
✗ Branch 44 → 114 not taken.
✓ Branch 45 → 46 taken 1 time.
✗ Branch 45 → 111 not taken.
|
1 | throw SemanticError(node, REFERENCED_UNDEFINED_STRUCT, "Struct '" + node->name->structName + "' could not be found"); |
| 159 | 8826 | } | |
| 160 | |||
| 161 | // Create scope for the procedure | ||
| 162 |
2/4✓ Branch 51 → 52 taken 10596 times.
✗ Branch 51 → 125 not taken.
✓ Branch 52 → 53 taken 10596 times.
✗ Branch 52 → 123 not taken.
|
10596 | node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc); |
| 163 |
6/6✓ Branch 54 → 55 taken 8339 times.
✓ Branch 54 → 57 taken 2257 times.
✓ Branch 55 → 56 taken 7671 times.
✓ Branch 55 → 58 taken 668 times.
✓ Branch 56 → 57 taken 2281 times.
✓ Branch 56 → 58 taken 5390 times.
|
10596 | currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope); |
| 164 |
4/4✓ Branch 59 → 60 taken 8825 times.
✓ Branch 59 → 63 taken 1771 times.
✓ Branch 61 → 62 taken 310 times.
✓ Branch 61 → 63 taken 8515 times.
|
10596 | currentScope->isDtorScope = node->isMethod && node->name->name == DTOR_FUNCTION_NAME; |
| 165 | |||
| 166 | // Create symbol for 'this' variable | ||
| 167 |
2/2✓ Branch 64 → 65 taken 8825 times.
✓ Branch 64 → 74 taken 1771 times.
|
10596 | if (node->isMethod) |
| 168 |
1/2✓ Branch 67 → 68 taken 8825 times.
✗ Branch 67 → 128 not taken.
|
35300 | currentScope->insert(THIS_VARIABLE_NAME, node); |
| 169 | |||
| 170 | // Create symbols for the parameters | ||
| 171 |
2/2✓ Branch 74 → 75 taken 8180 times.
✓ Branch 74 → 78 taken 2416 times.
|
10596 | if (node->hasParams) |
| 172 |
1/2✓ Branch 75 → 76 taken 8180 times.
✗ Branch 75 → 132 not taken.
|
8180 | visit(node->paramLst); |
| 173 | |||
| 174 | // Visit the procedure body | ||
| 175 |
1/2✓ Branch 78 → 79 taken 10596 times.
✗ Branch 78 → 133 not taken.
|
10596 | visit(node->body); |
| 176 | |||
| 177 | // Leave procedure body scope | ||
| 178 | 10596 | currentScope = node->scope->parent; | |
| 179 | |||
| 180 | // Insert symbol for procedure into the symbol table | ||
| 181 |
1/2✓ Branch 80 → 81 taken 10596 times.
✗ Branch 80 → 136 not taken.
|
21192 | node->entry = currentScope->insert(node->getSymbolTableEntryName(), node); |
| 182 | |||
| 183 | // Add to external name registry | ||
| 184 | // if a procedure has overloads, they both refer to the same entry in the registry. So we only register the name once | ||
| 185 | 10596 | const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName); | |
| 186 |
3/4✓ Branch 86 → 87 taken 2413 times.
✓ Branch 86 → 88 taken 8183 times.
✓ Branch 87 → 88 taken 2413 times.
✗ Branch 87 → 89 not taken.
|
10596 | if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry) |
| 187 | 10596 | sourceFile->addNameRegistryEntry(node->name->fqName, TY_PROCEDURE, node->entry, currentScope, true); | |
| 188 | |||
| 189 | // Leave the struct scope | ||
| 190 |
2/2✓ Branch 89 → 90 taken 8825 times.
✓ Branch 89 → 91 taken 1771 times.
|
10596 | if (node->isMethod) |
| 191 | 8825 | currentScope = node->structScope->parent; | |
| 192 | |||
| 193 | // Check if this is a constructor | ||
| 194 | 10596 | node->isCtor = node->name->nameFragments.back() == CTOR_FUNCTION_NAME; | |
| 195 | |||
| 196 |
1/2✓ Branch 93 → 94 taken 10596 times.
✗ Branch 93 → 137 not taken.
|
21192 | return nullptr; |
| 197 | } | ||
| 198 | |||
| 199 | /** | ||
| 200 | * Resolve an already-existing symbol when a struct or interface definition is being built. | ||
| 201 | * | ||
| 202 | * Handles three cases: | ||
| 203 | * - an in-file forward declaration of the same kind exists: upgrade it by reusing its entry, scope and typeId, | ||
| 204 | * un-mark the scope as forward-declared and remember the forward decl's codeLoc for later ordering checks. | ||
| 205 | * - a non-forward-decl symbol, or a forward decl of the wrong kind, exists: throw a duplicate-symbol error. | ||
| 206 | * - a matching forward declaration was imported from another file: adopt its typeId so that type identity is | ||
| 207 | * preserved across files (e.g. when breaking circular imports via a forward-decl-only header file). | ||
| 208 | * | ||
| 209 | * @param node Struct or interface definition node being built | ||
| 210 | * @param name Type name | ||
| 211 | * @param isStruct true for a struct definition, false for an interface definition | ||
| 212 | * @param entry [out] reused forward-decl entry when upgrading, otherwise left untouched | ||
| 213 | * @param scope [out] reused forward-decl scope when upgrading, otherwise left untouched | ||
| 214 | * @param typeId [in,out] adopted from a matching forward declaration when one exists | ||
| 215 | * @return true if an in-file forward declaration was upgraded (entry and scope reused) | ||
| 216 | */ | ||
| 217 | 3177 | bool SymbolTableBuilder::resolveForwardDeclaration(TopLevelDefNode *node, const std::string &name, bool isStruct, | |
| 218 | SymbolTableEntry *&entry, Scope *&scope, uint64_t &typeId) { | ||
| 219 |
2/2✓ Branch 5 → 6 taken 5 times.
✓ Branch 5 → 36 taken 3172 times.
|
6354 | if (SymbolTableEntry *existing = rootScope->lookupStrict(name)) { |
| 220 |
2/2✓ Branch 7 → 8 taken 2 times.
✓ Branch 7 → 15 taken 3 times.
|
5 | if (!existing->declNode->isForwardDecl()) |
| 221 |
3/6✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 53 not taken.
✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 51 not taken.
✓ Branch 11 → 12 taken 2 times.
✗ Branch 11 → 48 not taken.
|
2 | throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + name + "'"); |
| 222 | 3 | auto *fwdNode = static_cast<ForwardDeclNode *>(existing->declNode); | |
| 223 |
2/2✓ Branch 15 → 16 taken 1 time.
✓ Branch 15 → 35 taken 2 times.
|
3 | if (fwdNode->isStruct != isStruct) |
| 224 | ✗ | throw SemanticError(node, DUPLICATE_SYMBOL, | |
| 225 |
4/8✓ Branch 20 → 21 taken 1 time.
✗ Branch 20 → 22 not taken.
✓ Branch 23 → 24 taken 1 time.
✗ Branch 23 → 68 not taken.
✓ Branch 24 → 25 taken 1 time.
✗ Branch 24 → 66 not taken.
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 64 not taken.
|
2 | "'" + name + "' was forward-declared as " + (fwdNode->isStruct ? "a struct" : "an interface") + |
| 226 |
4/8✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 1 time.
✓ Branch 26 → 27 taken 1 time.
✗ Branch 26 → 62 not taken.
✓ Branch 27 → 28 taken 1 time.
✗ Branch 27 → 60 not taken.
✓ Branch 28 → 29 taken 1 time.
✗ Branch 28 → 57 not taken.
|
3 | ", cannot define it as " + (isStruct ? "a struct" : "an interface")); |
| 227 | // Upgrade: reuse the forward declaration's entry, scope, and typeId | ||
| 228 | 2 | entry = existing; | |
| 229 | 2 | scope = fwdNode->typeScope; | |
| 230 | 2 | scope->isForwardDeclScope = false; | |
| 231 | 2 | typeId = fwdNode->typeId; | |
| 232 | // Preserve the forward declaration's codeLoc so ordering checks accept uses between forward decl and full def | ||
| 233 | 2 | existing->forwardDeclCodeLoc = &fwdNode->codeLoc; | |
| 234 | // Update the entry to point to the full definition now | ||
| 235 | 2 | existing->declNode = node; | |
| 236 | 2 | return true; | |
| 237 | } | ||
| 238 | |||
| 239 | // A matching forward declaration may have been imported from another source file. Adopt its typeId. | ||
| 240 | 3172 | if (const NameRegistryEntry *importedFwd = sourceFile->getNameRegistryEntry(name); | |
| 241 |
7/8✓ Branch 37 → 38 taken 15 times.
✓ Branch 37 → 42 taken 3157 times.
✓ Branch 38 → 39 taken 15 times.
✗ Branch 38 → 42 not taken.
✓ Branch 40 → 41 taken 1 time.
✓ Branch 40 → 42 taken 14 times.
✓ Branch 43 → 44 taken 1 time.
✓ Branch 43 → 46 taken 3171 times.
|
3172 | importedFwd != nullptr && importedFwd->targetEntry != nullptr && importedFwd->targetEntry->declNode->isForwardDecl()) { |
| 242 | 1 | const auto *fwdNode = static_cast<const ForwardDeclNode *>(importedFwd->targetEntry->declNode); | |
| 243 |
1/2✓ Branch 44 → 45 taken 1 time.
✗ Branch 44 → 46 not taken.
|
1 | if (fwdNode->isStruct == isStruct) |
| 244 | 1 | typeId = fwdNode->typeId; | |
| 245 | } | ||
| 246 | 3172 | return false; | |
| 247 | } | ||
| 248 | |||
| 249 | 2811 | std::any SymbolTableBuilder::visitStructDef(StructDefNode *node) { | |
| 250 | // Visit attributes | ||
| 251 |
2/2✓ Branch 2 → 3 taken 105 times.
✓ Branch 2 → 6 taken 2706 times.
|
2811 | if (node->attrs) |
| 252 |
1/2✓ Branch 3 → 4 taken 105 times.
✗ Branch 3 → 73 not taken.
|
105 | visit(node->attrs); |
| 253 | |||
| 254 | // Check if this name already exists; upgrade a matching forward declaration if present | ||
| 255 | const bool upgradingForwardDecl = | ||
| 256 | 2811 | resolveForwardDeclaration(node, node->structName, true, node->entry, node->structScope, node->typeId); | |
| 257 | |||
| 258 |
2/2✓ Branch 7 → 8 taken 2808 times.
✓ Branch 7 → 14 taken 2 times.
|
2810 | if (!upgradingForwardDecl) { |
| 259 | // Create scope for the struct | ||
| 260 |
1/2✓ Branch 9 → 10 taken 2808 times.
✗ Branch 9 → 74 not taken.
|
2808 | const std::string &scopeName = Struct::getScopeName(node->structName); |
| 261 |
1/2✓ Branch 11 → 12 taken 2808 times.
✗ Branch 11 → 77 not taken.
|
2808 | node->structScope = rootScope->createChildScope(scopeName, ScopeType::STRUCT, &node->codeLoc); |
| 262 | 2808 | } | |
| 263 | 2810 | currentScope = node->structScope; | |
| 264 | 2810 | currentScope->isGenericScope = node->hasTemplateTypes; | |
| 265 | |||
| 266 | // Insert implicit field for each interface type | ||
| 267 |
2/2✓ Branch 14 → 15 taken 374 times.
✓ Branch 14 → 36 taken 2436 times.
|
2810 | if (node->hasInterfaces) { |
| 268 |
2/2✓ Branch 34 → 17 taken 374 times.
✓ Branch 34 → 35 taken 374 times.
|
1122 | for (DataTypeNode *interfaceNode : node->interfaceTypeLst->dataTypes) { |
| 269 | 374 | const std::string &interfaceName = interfaceNode->baseDataType->customDataType->typeNameFragments.back(); | |
| 270 |
1/2✓ Branch 20 → 21 taken 374 times.
✗ Branch 20 → 82 not taken.
|
748 | SymbolTableEntry *interfaceFieldEntry = currentScope->insert("this." + interfaceName, interfaceNode); |
| 271 | 374 | interfaceFieldEntry->used = true; | |
| 272 | 374 | interfaceFieldEntry->isImplicitField = true; | |
| 273 | } | ||
| 274 | } | ||
| 275 | |||
| 276 | // Visit children | ||
| 277 |
2/2✓ Branch 36 → 37 taken 2809 times.
✓ Branch 36 → 84 taken 1 time.
|
2810 | visitChildren(node); |
| 278 | |||
| 279 | // Leave the struct scope | ||
| 280 | 2809 | currentScope = node->structScope->parent; | |
| 281 | |||
| 282 | // Build struct qualifiers | ||
| 283 |
2/2✓ Branch 38 → 39 taken 2559 times.
✓ Branch 38 → 63 taken 250 times.
|
2809 | if (const QualifierLstNode *qualifierLst = node->qualifierLst) { |
| 284 |
2/2✓ Branch 61 → 41 taken 2559 times.
✓ Branch 61 → 62 taken 2559 times.
|
7677 | for (const QualifierNode *qualifier : qualifierLst->qualifiers) { |
| 285 |
1/2✓ Branch 43 → 44 taken 2559 times.
✗ Branch 43 → 47 not taken.
|
2559 | if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC) |
| 286 | 2559 | node->qualifiers.isPublic = true; | |
| 287 | else | ||
| 288 | ✗ | throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on a struct definition"); | |
| 289 | } | ||
| 290 | } | ||
| 291 | |||
| 292 | // Add the struct to the symbol table (skipped when upgrading from a forward declaration) | ||
| 293 |
2/2✓ Branch 63 → 64 taken 2807 times.
✓ Branch 63 → 68 taken 2 times.
|
2809 | if (!upgradingForwardDecl) |
| 294 | 5614 | node->entry = rootScope->insert(node->structName, node); | |
| 295 | // Register the name in the exported name registry | ||
| 296 | 2809 | sourceFile->addNameRegistryEntry(node->structName, node->typeId, node->entry, node->structScope, true); | |
| 297 | |||
| 298 |
1/2✓ Branch 69 → 70 taken 2809 times.
✗ Branch 69 → 95 not taken.
|
5618 | return nullptr; |
| 299 | } | ||
| 300 | |||
| 301 | 366 | std::any SymbolTableBuilder::visitInterfaceDef(InterfaceDefNode *node) { | |
| 302 | // Visit attributes | ||
| 303 |
2/2✓ Branch 2 → 3 taken 153 times.
✓ Branch 2 → 6 taken 213 times.
|
366 | if (node->attrs) |
| 304 |
1/2✓ Branch 3 → 4 taken 153 times.
✗ Branch 3 → 65 not taken.
|
153 | visit(node->attrs); |
| 305 | |||
| 306 | // Check if this name already exists; upgrade a matching forward declaration if present | ||
| 307 | const bool upgradingForwardDecl = | ||
| 308 | 366 | resolveForwardDeclaration(node, node->interfaceName, false, node->entry, node->interfaceScope, node->typeId); | |
| 309 | |||
| 310 |
1/2✓ Branch 7 → 8 taken 364 times.
✗ Branch 7 → 14 not taken.
|
364 | if (!upgradingForwardDecl) { |
| 311 | // Create scope for the interface | ||
| 312 |
1/2✓ Branch 9 → 10 taken 364 times.
✗ Branch 9 → 66 not taken.
|
364 | const std::string &scopeName = Interface::getScopeName(node->interfaceName); |
| 313 |
1/2✓ Branch 11 → 12 taken 364 times.
✗ Branch 11 → 69 not taken.
|
364 | node->interfaceScope = rootScope->createChildScope(scopeName, ScopeType::INTERFACE, &node->codeLoc); |
| 314 | 364 | } | |
| 315 | 364 | currentScope = node->interfaceScope; | |
| 316 | |||
| 317 | // Visit signatures | ||
| 318 |
2/2✓ Branch 29 → 16 taken 1331 times.
✓ Branch 29 → 30 taken 364 times.
|
2059 | for (SignatureNode *signature : node->signatures) |
| 319 |
1/2✓ Branch 18 → 19 taken 1331 times.
✗ Branch 18 → 72 not taken.
|
1331 | visit(signature); |
| 320 | |||
| 321 | // Leave the interface scope | ||
| 322 | 364 | currentScope = node->interfaceScope->parent; | |
| 323 | |||
| 324 | // Build interface qualifiers | ||
| 325 |
2/2✓ Branch 30 → 31 taken 345 times.
✓ Branch 30 → 55 taken 19 times.
|
364 | if (const QualifierLstNode *qualifierLst = node->qualifierLst) { |
| 326 |
2/2✓ Branch 53 → 33 taken 345 times.
✓ Branch 53 → 54 taken 345 times.
|
1035 | for (const QualifierNode *qualifier : qualifierLst->qualifiers) { |
| 327 |
1/2✓ Branch 35 → 36 taken 345 times.
✗ Branch 35 → 39 not taken.
|
345 | if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC) |
| 328 | 345 | node->qualifiers.isPublic = true; | |
| 329 | else | ||
| 330 | ✗ | throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on an interface definition"); | |
| 331 | } | ||
| 332 | } | ||
| 333 | |||
| 334 | // Add the interface to the symbol table (skipped when upgrading from a forward declaration) | ||
| 335 |
1/2✓ Branch 55 → 56 taken 364 times.
✗ Branch 55 → 60 not taken.
|
364 | if (!upgradingForwardDecl) |
| 336 | 728 | node->entry = rootScope->insert(node->interfaceName, node); | |
| 337 | // Register the name in the exported name registry | ||
| 338 | 364 | sourceFile->addNameRegistryEntry(node->interfaceName, node->typeId, node->entry, node->interfaceScope, true); | |
| 339 | |||
| 340 |
1/2✓ Branch 61 → 62 taken 364 times.
✗ Branch 61 → 84 not taken.
|
728 | return nullptr; |
| 341 | } | ||
| 342 | |||
| 343 | 7 | std::any SymbolTableBuilder::visitForwardDecl(ForwardDeclNode *node) { | |
| 344 | // Visit attributes | ||
| 345 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 6 taken 7 times.
|
7 | if (node->attrs) |
| 346 | ✗ | visit(node->attrs); | |
| 347 | |||
| 348 | // Check for duplicate that is not itself a forward declaration | ||
| 349 |
3/4✓ Branch 6 → 7 taken 7 times.
✗ Branch 6 → 118 not taken.
✓ Branch 9 → 10 taken 1 time.
✓ Branch 9 → 30 taken 6 times.
|
14 | if (SymbolTableEntry *existing = rootScope->lookupStrict(node->typeName)) { |
| 350 |
2/4✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 118 not taken.
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 19 taken 1 time.
|
1 | if (!existing->declNode->isForwardDecl()) |
| 351 | ✗ | throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->typeName + "'"); | |
| 352 | // Duplicate forward declaration is silently accepted (idempotent). Reuse the existing entry, scope, and typeId | ||
| 353 | // so that subsequent passes (e.g. the type checker) find the same fields populated as on the first node. | ||
| 354 | 1 | auto *fwdNode = static_cast<ForwardDeclNode *>(existing->declNode); | |
| 355 |
1/2✗ Branch 19 → 20 not taken.
✓ Branch 19 → 27 taken 1 time.
|
1 | if (fwdNode->isStruct != node->isStruct) |
| 356 | ✗ | throw SemanticError(node, DUPLICATE_SYMBOL, | |
| 357 | ✗ | "Forward declaration of '" + node->typeName + "' conflicts with an earlier forward declaration of a different kind"); | |
| 358 | 1 | node->entry = existing; | |
| 359 | 1 | node->typeScope = fwdNode->typeScope; | |
| 360 | 1 | node->typeId = fwdNode->typeId; | |
| 361 |
1/2✓ Branch 27 → 28 taken 1 time.
✗ Branch 27 → 96 not taken.
|
2 | return nullptr; |
| 362 | } | ||
| 363 | |||
| 364 | // Create a placeholder scope for the forward-declared type | ||
| 365 | const std::string &scopeName = | ||
| 366 |
4/14✓ Branch 30 → 31 taken 6 times.
✗ Branch 30 → 33 not taken.
✓ Branch 32 → 35 taken 6 times.
✗ Branch 32 → 97 not taken.
✗ Branch 34 → 35 not taken.
✗ Branch 34 → 97 not taken.
✗ Branch 35 → 36 not taken.
✓ Branch 35 → 37 taken 6 times.
✓ Branch 37 → 38 taken 6 times.
✗ Branch 37 → 39 not taken.
✗ Branch 97 → 98 not taken.
✗ Branch 97 → 99 not taken.
✗ Branch 101 → 102 not taken.
✗ Branch 101 → 103 not taken.
|
6 | node->isStruct ? Struct::getScopeName(node->typeName) : Interface::getScopeName(node->typeName); |
| 367 |
1/2✓ Branch 39 → 40 taken 6 times.
✗ Branch 39 → 41 not taken.
|
6 | const ScopeType st = node->isStruct ? ScopeType::STRUCT : ScopeType::INTERFACE; |
| 368 |
1/2✓ Branch 42 → 43 taken 6 times.
✗ Branch 42 → 116 not taken.
|
6 | node->typeScope = rootScope->createChildScope(scopeName, st, &node->codeLoc); |
| 369 | 6 | node->typeScope->isForwardDeclScope = true; | |
| 370 | |||
| 371 | // Build qualifiers | ||
| 372 |
2/2✓ Branch 43 → 44 taken 2 times.
✓ Branch 43 → 68 taken 4 times.
|
6 | if (const QualifierLstNode *qualifierLst = node->qualifierLst) { |
| 373 |
2/2✓ Branch 66 → 46 taken 2 times.
✓ Branch 66 → 67 taken 2 times.
|
6 | for (const QualifierNode *qualifier : qualifierLst->qualifiers) { |
| 374 |
1/2✓ Branch 48 → 49 taken 2 times.
✗ Branch 48 → 52 not taken.
|
2 | if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC) |
| 375 | 2 | node->qualifiers.isPublic = true; | |
| 376 | else | ||
| 377 | ✗ | throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, | |
| 378 | ✗ | "Cannot use this qualifier on a forward declaration"); | |
| 379 | } | ||
| 380 | } | ||
| 381 | |||
| 382 | // Register the placeholder symbol | ||
| 383 |
1/2✓ Branch 68 → 69 taken 6 times.
✗ Branch 68 → 116 not taken.
|
6 | node->entry = rootScope->insert(node->typeName, node); |
| 384 |
1/2✓ Branch 71 → 72 taken 6 times.
✗ Branch 71 → 116 not taken.
|
6 | sourceFile->addNameRegistryEntry(node->typeName, node->typeId, node->entry, node->typeScope, true); |
| 385 | |||
| 386 |
1/2✓ Branch 72 → 73 taken 6 times.
✗ Branch 72 → 115 not taken.
|
6 | return nullptr; |
| 387 | 6 | } | |
| 388 | |||
| 389 | 369 | std::any SymbolTableBuilder::visitEnumDef(EnumDefNode *node) { | |
| 390 | // Check if this name already exists | ||
| 391 |
2/2✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 368 times.
|
738 | if (rootScope->lookupStrict(node->enumName)) |
| 392 |
3/6✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 56 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 54 not taken.
✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 51 not taken.
|
1 | throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->enumName + "'"); |
| 393 | |||
| 394 | // Create scope for the enum | ||
| 395 | 368 | node->enumScope = currentScope = | |
| 396 |
2/4✓ Branch 13 → 14 taken 368 times.
✗ Branch 13 → 62 not taken.
✓ Branch 14 → 15 taken 368 times.
✗ Branch 14 → 60 not taken.
|
368 | rootScope->createChildScope(ENUM_SCOPE_PREFIX + node->enumName, ScopeType::ENUM, &node->codeLoc); |
| 397 | |||
| 398 | // Visit items | ||
| 399 |
2/2✓ Branch 16 → 17 taken 367 times.
✓ Branch 16 → 63 taken 1 time.
|
368 | visit(node->itemLst); |
| 400 | |||
| 401 | // Leave the enum scope | ||
| 402 | 367 | currentScope = node->enumScope->parent; | |
| 403 | |||
| 404 | // Build enum qualifiers | ||
| 405 |
2/2✓ Branch 18 → 19 taken 331 times.
✓ Branch 18 → 43 taken 36 times.
|
367 | if (node->qualifierLst) { |
| 406 |
2/2✓ Branch 41 → 21 taken 331 times.
✓ Branch 41 → 42 taken 331 times.
|
993 | for (const QualifierNode *qualifier : node->qualifierLst->qualifiers) { |
| 407 |
1/2✓ Branch 23 → 24 taken 331 times.
✗ Branch 23 → 27 not taken.
|
331 | if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC) |
| 408 | 331 | node->qualifiers.isPublic = true; | |
| 409 | else | ||
| 410 | ✗ | throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on an enum definition"); | |
| 411 | } | ||
| 412 | } | ||
| 413 | |||
| 414 | // Add the enum to the symbol table | ||
| 415 | 367 | node->entry = rootScope->insert(node->enumName, node); | |
| 416 | // Register the name in the exported name registry | ||
| 417 | 367 | sourceFile->addNameRegistryEntry(node->enumName, node->typeId, node->entry, node->enumScope, true); | |
| 418 | |||
| 419 |
1/2✓ Branch 47 → 48 taken 367 times.
✗ Branch 47 → 74 not taken.
|
734 | return nullptr; |
| 420 | } | ||
| 421 | |||
| 422 | 1929 | std::any SymbolTableBuilder::visitGenericTypeDef(GenericTypeDefNode *node) { | |
| 423 | // Check if this name already exists | ||
| 424 |
2/2✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 1928 times.
|
3858 | if (rootScope->lookupStrict(node->typeName)) |
| 425 |
3/6✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 25 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 23 not taken.
✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 20 not taken.
|
1 | throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->typeName + "'"); |
| 426 | |||
| 427 | // Create the generic type to the symbol table | ||
| 428 | 1928 | node->entry = rootScope->insert(node->typeName, node); | |
| 429 | 1928 | node->entry->used = true; // Generic types are always used | |
| 430 | |||
| 431 |
1/2✓ Branch 16 → 17 taken 1928 times.
✗ Branch 16 → 29 not taken.
|
3856 | return nullptr; |
| 432 | } | ||
| 433 | |||
| 434 | 342 | std::any SymbolTableBuilder::visitAliasDef(AliasDefNode *node) { | |
| 435 | // Check if this name already exists | ||
| 436 |
3/4✓ Branch 2 → 3 taken 342 times.
✗ Branch 2 → 73 not taken.
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 341 times.
|
684 | if (rootScope->lookupStrict(node->aliasName)) |
| 437 |
3/6✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 56 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 54 not taken.
✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 51 not taken.
|
1 | throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->aliasName + "'"); |
| 438 | |||
| 439 | // Build alias qualifiers | ||
| 440 |
2/2✓ Branch 13 → 14 taken 104 times.
✓ Branch 13 → 38 taken 237 times.
|
341 | if (const QualifierLstNode *qualifierLst = node->qualifierLst) { |
| 441 |
2/2✓ Branch 36 → 16 taken 104 times.
✓ Branch 36 → 37 taken 104 times.
|
312 | for (const QualifierNode *qualifier : qualifierLst->qualifiers) { |
| 442 |
1/2✓ Branch 18 → 19 taken 104 times.
✗ Branch 18 → 22 not taken.
|
104 | if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC) |
| 443 | 104 | node->qualifiers.isPublic = true; | |
| 444 | else | ||
| 445 | ✗ | throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on an alias definition"); | |
| 446 | } | ||
| 447 | } | ||
| 448 | |||
| 449 | // Add the alias to the symbol table | ||
| 450 |
1/2✓ Branch 38 → 39 taken 341 times.
✗ Branch 38 → 73 not taken.
|
341 | node->entry = rootScope->insert(node->aliasName, node); |
| 451 | // Register the name in the exported name registry | ||
| 452 |
1/2✓ Branch 41 → 42 taken 341 times.
✗ Branch 41 → 73 not taken.
|
341 | sourceFile->addNameRegistryEntry(node->aliasName, node->typeId, node->entry, rootScope, true); |
| 453 | |||
| 454 | // Add another symbol for the aliased type container | ||
| 455 |
1/2✓ Branch 42 → 43 taken 341 times.
✗ Branch 42 → 73 not taken.
|
341 | const std::string aliasedTypeContainerName = node->aliasName + ALIAS_CONTAINER_SUFFIX; |
| 456 |
1/2✓ Branch 43 → 44 taken 341 times.
✗ Branch 43 → 71 not taken.
|
341 | node->aliasedTypeContainerEntry = rootScope->insert(aliasedTypeContainerName, node); |
| 457 | |||
| 458 |
1/2✓ Branch 46 → 47 taken 341 times.
✗ Branch 46 → 70 not taken.
|
682 | return nullptr; |
| 459 | 341 | } | |
| 460 | |||
| 461 | 2380 | std::any SymbolTableBuilder::visitGlobalVarDef(GlobalVarDefNode *node) { | |
| 462 | // Check if this name already exists | ||
| 463 |
2/2✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 2379 times.
|
4760 | if (rootScope->lookupStrict(node->varName)) |
| 464 |
3/6✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 43 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 41 not taken.
✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 38 not taken.
|
1 | throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->varName + "'"); |
| 465 | |||
| 466 | // Check if global already exists in an imported source file | ||
| 467 |
5/8✓ Branch 13 → 14 taken 2379 times.
✗ Branch 13 → 56 not taken.
✓ Branch 14 → 15 taken 2379 times.
✗ Branch 14 → 56 not taken.
✓ Branch 15 → 16 taken 2379 times.
✗ Branch 15 → 56 not taken.
✓ Branch 29 → 17 taken 4367 times.
✓ Branch 29 → 30 taken 2378 times.
|
6745 | for (const auto &dependency : sourceFile->dependencies | std::views::values) |
| 468 |
3/4✓ Branch 18 → 19 taken 4367 times.
✗ Branch 18 → 56 not taken.
✓ Branch 19 → 20 taken 1 time.
✓ Branch 19 → 27 taken 4366 times.
|
4367 | if (dependency->exportedNameRegistry.contains(node->varName)) |
| 469 |
3/6✓ Branch 21 → 22 taken 1 time.
✗ Branch 21 → 52 not taken.
✓ Branch 22 → 23 taken 1 time.
✗ Branch 22 → 50 not taken.
✓ Branch 23 → 24 taken 1 time.
✗ Branch 23 → 47 not taken.
|
1 | throw SemanticError(node, GLOBAL_DECLARED_TWICE, "Duplicate global variable '" + node->varName + "' in other module"); |
| 470 | |||
| 471 | // Add the global to the symbol table | ||
| 472 | 2378 | node->entry = rootScope->insert(node->varName, node); | |
| 473 | // Register the name in the exported name registry | ||
| 474 | 2378 | sourceFile->addNameRegistryEntry(node->varName, TY_INVALID, node->entry, currentScope, true); | |
| 475 | |||
| 476 |
1/2✓ Branch 34 → 35 taken 2378 times.
✗ Branch 34 → 57 not taken.
|
4756 | return nullptr; |
| 477 | } | ||
| 478 | |||
| 479 | 2963 | std::any SymbolTableBuilder::visitExtDecl(ExtDeclNode *node) { | |
| 480 | // Visit attributes | ||
| 481 |
2/2✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 6 taken 2962 times.
|
2963 | if (node->attrs) |
| 482 |
1/2✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 31 not taken.
|
1 | visit(node->attrs); |
| 483 | |||
| 484 | // Check if this name already exists | ||
| 485 |
2/2✓ Branch 9 → 10 taken 1 time.
✓ Branch 9 → 17 taken 2962 times.
|
5926 | if (rootScope->lookupStrict(node->extFunctionName)) |
| 486 |
3/6✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 37 not taken.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 35 not taken.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 32 not taken.
|
1 | throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->extFunctionName + "'"); |
| 487 | |||
| 488 | // Create scope for the external function (this is required in case of forceSubstantiation in FunctionManager::matchFunction) | ||
| 489 |
2/4✓ Branch 17 → 18 taken 2962 times.
✗ Branch 17 → 43 not taken.
✓ Branch 18 → 19 taken 2962 times.
✗ Branch 18 → 41 not taken.
|
2962 | rootScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc); |
| 490 | |||
| 491 | // Add the external declaration to the symbol table | ||
| 492 | 2962 | node->entry = rootScope->insert(node->extFunctionName, node); | |
| 493 | // Register the name in the exported name registry | ||
| 494 |
2/2✓ Branch 23 → 24 taken 1966 times.
✓ Branch 23 → 25 taken 996 times.
|
2962 | const uint64_t typeId = node->returnType ? TY_FUNCTION : TY_PROCEDURE; |
| 495 | 2962 | sourceFile->addNameRegistryEntry(node->extFunctionName, typeId, node->entry, rootScope, /*keepNewOnCollision=*/true); | |
| 496 | |||
| 497 |
1/2✓ Branch 27 → 28 taken 2962 times.
✗ Branch 27 → 44 not taken.
|
5924 | return nullptr; |
| 498 | } | ||
| 499 | |||
| 500 | 5375 | std::any SymbolTableBuilder::visitUnsafeBlock(UnsafeBlockNode *node) { | |
| 501 | // Create scope for the unsafe block body | ||
| 502 | 5375 | node->bodyScope = currentScope = | |
| 503 |
2/4✓ Branch 2 → 3 taken 5375 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 5375 times.
✗ Branch 3 → 11 not taken.
|
5375 | currentScope->createChildScope(node->getScopeId(), ScopeType::UNSAFE_BODY, &node->body->codeLoc); |
| 504 | |||
| 505 | // Visit body | ||
| 506 |
1/2✓ Branch 5 → 6 taken 5375 times.
✗ Branch 5 → 14 not taken.
|
5375 | visit(node->body); |
| 507 | |||
| 508 | // Leave thread body scope | ||
| 509 | 5375 | currentScope = node->bodyScope->parent; | |
| 510 | |||
| 511 |
1/2✓ Branch 7 → 8 taken 5375 times.
✗ Branch 7 → 15 not taken.
|
10750 | return nullptr; |
| 512 | } | ||
| 513 | |||
| 514 | 2826 | std::any SymbolTableBuilder::visitForLoop(ForLoopNode *node) { | |
| 515 | // Create scope for the loop body | ||
| 516 |
2/4✓ Branch 2 → 3 taken 2826 times.
✗ Branch 2 → 15 not taken.
✓ Branch 3 → 4 taken 2826 times.
✗ Branch 3 → 13 not taken.
|
2826 | node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FOR_BODY, &node->body->codeLoc); |
| 517 | |||
| 518 | // Visit loop variable declaration | ||
| 519 |
1/2✓ Branch 5 → 6 taken 2826 times.
✗ Branch 5 → 16 not taken.
|
2826 | visit(node->initDecl); |
| 520 | |||
| 521 | // Visit body | ||
| 522 |
1/2✓ Branch 7 → 8 taken 2826 times.
✗ Branch 7 → 17 not taken.
|
2826 | visit(node->body); |
| 523 | |||
| 524 | // Leave for body scope | ||
| 525 | 2826 | currentScope = node->bodyScope->parent; | |
| 526 | |||
| 527 |
1/2✓ Branch 9 → 10 taken 2826 times.
✗ Branch 9 → 18 not taken.
|
5652 | return nullptr; |
| 528 | } | ||
| 529 | |||
| 530 | 471 | std::any SymbolTableBuilder::visitForeachLoop(ForeachLoopNode *node) { | |
| 531 | // Create scope for the loop body | ||
| 532 | 471 | node->bodyScope = currentScope = | |
| 533 |
2/4✓ Branch 2 → 3 taken 471 times.
✗ Branch 2 → 19 not taken.
✓ Branch 3 → 4 taken 471 times.
✗ Branch 3 → 17 not taken.
|
471 | currentScope->createChildScope(node->getScopeId(), ScopeType::FOREACH_BODY, &node->body->codeLoc); |
| 534 | |||
| 535 | // Visit index variable declaration | ||
| 536 |
2/2✓ Branch 5 → 6 taken 58 times.
✓ Branch 5 → 9 taken 413 times.
|
471 | if (node->idxVarDecl) |
| 537 |
1/2✓ Branch 6 → 7 taken 58 times.
✗ Branch 6 → 20 not taken.
|
58 | visit(node->idxVarDecl); |
| 538 | |||
| 539 | // Visit item variable declaration | ||
| 540 |
1/2✓ Branch 9 → 10 taken 471 times.
✗ Branch 9 → 21 not taken.
|
471 | visit(node->itemVarDecl); |
| 541 | |||
| 542 | // Visit body | ||
| 543 |
1/2✓ Branch 11 → 12 taken 471 times.
✗ Branch 11 → 22 not taken.
|
471 | visit(node->body); |
| 544 | |||
| 545 | // Leave foreach body scope | ||
| 546 | 471 | currentScope = node->bodyScope->parent; | |
| 547 | |||
| 548 |
1/2✓ Branch 13 → 14 taken 471 times.
✗ Branch 13 → 23 not taken.
|
942 | return nullptr; |
| 549 | } | ||
| 550 | |||
| 551 | 1660 | std::any SymbolTableBuilder::visitWhileLoop(WhileLoopNode *node) { | |
| 552 | // Create scope for the loop body | ||
| 553 | 1660 | node->bodyScope = currentScope = | |
| 554 |
2/4✓ Branch 2 → 3 taken 1660 times.
✗ Branch 2 → 15 not taken.
✓ Branch 3 → 4 taken 1660 times.
✗ Branch 3 → 13 not taken.
|
1660 | currentScope->createChildScope(node->getScopeId(), ScopeType::WHILE_BODY, &node->body->codeLoc); |
| 555 | |||
| 556 | // Visit condition | ||
| 557 |
1/2✓ Branch 5 → 6 taken 1660 times.
✗ Branch 5 → 16 not taken.
|
1660 | visit(node->condition); |
| 558 | |||
| 559 | // Visit body | ||
| 560 |
1/2✓ Branch 7 → 8 taken 1660 times.
✗ Branch 7 → 17 not taken.
|
1660 | visit(node->body); |
| 561 | |||
| 562 | // Leave while body scope | ||
| 563 | 1660 | currentScope = node->bodyScope->parent; | |
| 564 | |||
| 565 |
1/2✓ Branch 9 → 10 taken 1660 times.
✗ Branch 9 → 18 not taken.
|
3320 | return nullptr; |
| 566 | } | ||
| 567 | |||
| 568 | 16 | std::any SymbolTableBuilder::visitDoWhileLoop(DoWhileLoopNode *node) { | |
| 569 | // Create scope for the loop body | ||
| 570 | 16 | node->bodyScope = currentScope = | |
| 571 |
2/4✓ Branch 2 → 3 taken 16 times.
✗ Branch 2 → 15 not taken.
✓ Branch 3 → 4 taken 16 times.
✗ Branch 3 → 13 not taken.
|
16 | currentScope->createChildScope(node->getScopeId(), ScopeType::WHILE_BODY, &node->body->codeLoc); |
| 572 | |||
| 573 | // Visit condition | ||
| 574 |
1/2✓ Branch 5 → 6 taken 16 times.
✗ Branch 5 → 16 not taken.
|
16 | visit(node->condition); |
| 575 | |||
| 576 | // Visit body | ||
| 577 |
1/2✓ Branch 7 → 8 taken 16 times.
✗ Branch 7 → 17 not taken.
|
16 | visit(node->body); |
| 578 | |||
| 579 | // Leave do-while body scope | ||
| 580 | 16 | currentScope = node->bodyScope->parent; | |
| 581 | |||
| 582 |
1/2✓ Branch 9 → 10 taken 16 times.
✗ Branch 9 → 18 not taken.
|
32 | return nullptr; |
| 583 | } | ||
| 584 | |||
| 585 | 10901 | std::any SymbolTableBuilder::visitIfStmt(IfStmtNode *node) { | |
| 586 | // Create scope for the then body | ||
| 587 | 10901 | node->thenBodyScope = currentScope = | |
| 588 |
2/4✓ Branch 2 → 3 taken 10901 times.
✗ Branch 2 → 27 not taken.
✓ Branch 3 → 4 taken 10901 times.
✗ Branch 3 → 25 not taken.
|
10901 | currentScope->createChildScope(node->getScopeId(), ScopeType::IF_ELSE_BODY, &node->thenBody->codeLoc); |
| 589 | |||
| 590 | // Visit condition | ||
| 591 |
1/2✓ Branch 5 → 6 taken 10901 times.
✗ Branch 5 → 28 not taken.
|
10901 | visit(node->condition); |
| 592 | |||
| 593 | // Visit then body (manifestations do not exist yet, so both branches are always visited here) | ||
| 594 |
1/2✓ Branch 8 → 9 taken 10901 times.
✗ Branch 8 → 12 not taken.
|
10901 | if (node->doCompileThenBranch(manIdx)) |
| 595 |
1/2✓ Branch 9 → 10 taken 10901 times.
✗ Branch 9 → 29 not taken.
|
10901 | visit(node->thenBody); |
| 596 | |||
| 597 | // Leave then body scope | ||
| 598 | 10901 | currentScope = node->thenBodyScope->parent; | |
| 599 | |||
| 600 | // Visit else stmt | ||
| 601 |
5/6✓ Branch 13 → 14 taken 10901 times.
✗ Branch 13 → 16 not taken.
✓ Branch 14 → 15 taken 958 times.
✓ Branch 14 → 16 taken 9943 times.
✓ Branch 17 → 18 taken 958 times.
✓ Branch 17 → 21 taken 9943 times.
|
10901 | if (node->doCompileElseBranch(manIdx) && node->elseStmt) |
| 602 |
1/2✓ Branch 18 → 19 taken 958 times.
✗ Branch 18 → 30 not taken.
|
958 | visit(node->elseStmt); |
| 603 | |||
| 604 |
1/2✓ Branch 21 → 22 taken 10901 times.
✗ Branch 21 → 31 not taken.
|
21802 | return nullptr; |
| 605 | } | ||
| 606 | |||
| 607 | 958 | std::any SymbolTableBuilder::visitElseStmt(ElseStmtNode *node) { | |
| 608 | // Visit if statement in the case of an else if branch | ||
| 609 |
2/2✓ Branch 2 → 3 taken 376 times.
✓ Branch 2 → 8 taken 582 times.
|
958 | if (node->isElseIf) { |
| 610 |
1/2✓ Branch 3 → 4 taken 376 times.
✗ Branch 3 → 17 not taken.
|
376 | visit(node->ifStmt); |
| 611 |
1/2✓ Branch 5 → 6 taken 376 times.
✗ Branch 5 → 18 not taken.
|
752 | return nullptr; |
| 612 | } | ||
| 613 | |||
| 614 | // Create scope for the else body | ||
| 615 | 582 | node->elseBodyScope = currentScope = | |
| 616 |
2/4✓ Branch 8 → 9 taken 582 times.
✗ Branch 8 → 21 not taken.
✓ Branch 9 → 10 taken 582 times.
✗ Branch 9 → 19 not taken.
|
582 | currentScope->createChildScope(node->getScopeId(), ScopeType::IF_ELSE_BODY, &node->body->codeLoc); |
| 617 | |||
| 618 | // Visit else body | ||
| 619 |
1/2✓ Branch 11 → 12 taken 582 times.
✗ Branch 11 → 22 not taken.
|
582 | visit(node->body); |
| 620 | |||
| 621 | // Leave else body scope | ||
| 622 | 582 | currentScope = node->elseBodyScope->parent; | |
| 623 | |||
| 624 |
1/2✓ Branch 13 → 14 taken 582 times.
✗ Branch 13 → 23 not taken.
|
1164 | return nullptr; |
| 625 | } | ||
| 626 | |||
| 627 | 662 | std::any SymbolTableBuilder::visitCaseBranch(CaseBranchNode *node) { | |
| 628 | // Create scope for the case branch | ||
| 629 |
2/4✓ Branch 2 → 3 taken 662 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 662 times.
✗ Branch 3 → 11 not taken.
|
662 | node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::CASE_BODY, &node->body->codeLoc); |
| 630 | |||
| 631 | // Visit case body | ||
| 632 |
1/2✓ Branch 5 → 6 taken 662 times.
✗ Branch 5 → 14 not taken.
|
662 | visit(node->body); |
| 633 | |||
| 634 | // Leave case body scope | ||
| 635 | 662 | currentScope = node->bodyScope->parent; | |
| 636 | |||
| 637 |
1/2✓ Branch 7 → 8 taken 662 times.
✗ Branch 7 → 15 not taken.
|
1324 | return nullptr; |
| 638 | } | ||
| 639 | |||
| 640 | 69 | std::any SymbolTableBuilder::visitDefaultBranch(DefaultBranchNode *node) { | |
| 641 | // Create scope for the default branch | ||
| 642 | 69 | node->bodyScope = currentScope = | |
| 643 |
2/4✓ Branch 2 → 3 taken 69 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 69 times.
✗ Branch 3 → 11 not taken.
|
69 | currentScope->createChildScope(node->getScopeId(), ScopeType::DEFAULT_BODY, &node->body->codeLoc); |
| 644 | |||
| 645 | // Visit default body | ||
| 646 |
1/2✓ Branch 5 → 6 taken 69 times.
✗ Branch 5 → 14 not taken.
|
69 | visit(node->body); |
| 647 | |||
| 648 | // Leave default body scope | ||
| 649 | 69 | currentScope = node->bodyScope->parent; | |
| 650 | |||
| 651 |
1/2✓ Branch 7 → 8 taken 69 times.
✗ Branch 7 → 15 not taken.
|
138 | return nullptr; |
| 652 | } | ||
| 653 | |||
| 654 | 43 | std::any SymbolTableBuilder::visitAnonymousBlockStmt(AnonymousBlockStmtNode *node) { | |
| 655 | // Create scope for the anonymous block body | ||
| 656 | 43 | node->bodyScope = currentScope = | |
| 657 |
2/4✓ Branch 2 → 3 taken 43 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 43 times.
✗ Branch 3 → 11 not taken.
|
43 | currentScope->createChildScope(node->getScopeId(), ScopeType::ANONYMOUS_BLOCK_BODY, &node->body->codeLoc); |
| 658 | |||
| 659 | // Visit body | ||
| 660 |
1/2✓ Branch 5 → 6 taken 43 times.
✗ Branch 5 → 14 not taken.
|
43 | visit(node->body); |
| 661 | |||
| 662 | // Leave anonymous block body scope | ||
| 663 | 43 | currentScope = node->bodyScope->parent; | |
| 664 | |||
| 665 |
1/2✓ Branch 7 → 8 taken 43 times.
✗ Branch 7 → 15 not taken.
|
86 | return nullptr; |
| 666 | } | ||
| 667 | |||
| 668 | 4907 | std::any SymbolTableBuilder::visitEnumItem(EnumItemNode *node) { | |
| 669 | // Check if enum item already exists in the same scope. | ||
| 670 |
3/4✓ Branch 2 → 3 taken 4907 times.
✗ Branch 2 → 42 not taken.
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 4906 times.
|
9814 | if (currentScope->lookupStrict(node->itemName)) |
| 671 |
3/6✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 32 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 30 not taken.
✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 27 not taken.
|
1 | throw SemanticError(node, VARIABLE_DECLARED_TWICE, "The enum item '" + node->itemName + "' was declared more than once"); |
| 672 | |||
| 673 | // Add enum item entry to symbol table | ||
| 674 |
1/2✓ Branch 13 → 14 taken 4906 times.
✗ Branch 13 → 42 not taken.
|
4906 | SymbolTableEntry *enumItemEntry = currentScope->insert(node->itemName, node); |
| 675 | |||
| 676 | // Add external registry entry | ||
| 677 |
1/2✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 4906 times.
|
4906 | assert(node->enumDef != nullptr); |
| 678 |
2/4✓ Branch 18 → 19 taken 4906 times.
✗ Branch 18 → 38 not taken.
✓ Branch 19 → 20 taken 4906 times.
✗ Branch 19 → 36 not taken.
|
4906 | const std::string name = node->enumDef->enumName + SCOPE_ACCESS_TOKEN + node->itemName; |
| 679 |
1/2✓ Branch 21 → 22 taken 4906 times.
✗ Branch 21 → 40 not taken.
|
4906 | sourceFile->addNameRegistryEntry(name, TY_INT, enumItemEntry, currentScope, true); |
| 680 | |||
| 681 |
1/2✓ Branch 22 → 23 taken 4906 times.
✗ Branch 22 → 39 not taken.
|
9812 | return nullptr; |
| 682 | 4906 | } | |
| 683 | |||
| 684 | 5311 | std::any SymbolTableBuilder::visitField(FieldNode *node) { | |
| 685 | // Check if field already exists in the same scope. | ||
| 686 |
2/2✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 5310 times.
|
10622 | if (currentScope->lookupStrict(node->fieldName)) |
| 687 |
3/6✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 25 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 23 not taken.
✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 20 not taken.
|
1 | throw SemanticError(node, VARIABLE_DECLARED_TWICE, "The field '" + node->fieldName + "' was declared more than once"); |
| 688 | |||
| 689 | // Add field entry to symbol table | ||
| 690 | 5310 | currentScope->insert(node->fieldName, node); | |
| 691 | |||
| 692 |
1/2✓ Branch 16 → 17 taken 5310 times.
✗ Branch 16 → 29 not taken.
|
10620 | return nullptr; |
| 693 | } | ||
| 694 | |||
| 695 | 1331 | std::any SymbolTableBuilder::visitSignature(SignatureNode *node) { | |
| 696 | // Build signature qualifiers | ||
| 697 |
2/2✓ Branch 2 → 3 taken 734 times.
✓ Branch 2 → 32 taken 597 times.
|
1331 | if (const QualifierLstNode *qualifierLst = node->qualifierLst) { |
| 698 |
2/2✓ Branch 30 → 5 taken 870 times.
✓ Branch 30 → 31 taken 734 times.
|
2338 | for (const QualifierNode *qualifier : qualifierLst->qualifiers) { |
| 699 |
1/2✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 870 times.
|
870 | if (qualifier->type == QualifierNode::QualifierType::TY_INLINE) |
| 700 | ✗ | node->signatureQualifiers.isInline = true; | |
| 701 |
2/2✓ Branch 9 → 10 taken 734 times.
✓ Branch 9 → 11 taken 136 times.
|
870 | else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC) |
| 702 | 734 | node->signatureQualifiers.isPublic = true; | |
| 703 |
1/2✓ Branch 11 → 12 taken 136 times.
✗ Branch 11 → 13 not taken.
|
136 | else if (qualifier->type == QualifierNode::QualifierType::TY_CONST) |
| 704 | 136 | node->signatureQualifiers.isConst = true; | |
| 705 | else | ||
| 706 | ✗ | throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on a signature definition"); | |
| 707 | } | ||
| 708 | } | ||
| 709 | |||
| 710 | // Add signature entry to symbol table. We append the code location to disambiguate overloaded signatures | ||
| 711 | // (e.g. an interface declaring `getName()` and `getName(bool)`). | ||
| 712 |
1/2✓ Branch 32 → 33 taken 1331 times.
✗ Branch 32 → 53 not taken.
|
2662 | node->entry = currentScope->insert(Function::getSymbolTableEntryName(node->methodName, node->codeLoc), node); |
| 713 | |||
| 714 |
1/2✓ Branch 37 → 38 taken 1331 times.
✗ Branch 37 → 54 not taken.
|
2662 | return nullptr; |
| 715 | } | ||
| 716 | |||
| 717 | 51136 | std::any SymbolTableBuilder::visitDeclStmt(DeclStmtNode *node) { | |
| 718 | // Check if variable already exists in the same scope. | ||
| 719 |
2/2✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 51135 times.
|
102272 | if (currentScope->lookupStrict(node->varName)) |
| 720 |
3/6✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 29 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 27 not taken.
✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 24 not taken.
|
1 | throw SemanticError(node, VARIABLE_DECLARED_TWICE, "The variable '" + node->varName + "' was declared more than once"); |
| 721 | |||
| 722 | // Visit the right side | ||
| 723 |
2/2✓ Branch 13 → 14 taken 18329 times.
✓ Branch 13 → 17 taken 32806 times.
|
51135 | if (node->hasAssignment) |
| 724 |
1/2✓ Branch 14 → 15 taken 18329 times.
✗ Branch 14 → 33 not taken.
|
18329 | visit(node->assignExpr); |
| 725 | |||
| 726 | // Add variable entry to symbol table | ||
| 727 | 51135 | SymbolTableEntry *varEntry = currentScope->insert(node->varName, node); | |
| 728 | 51135 | varEntry->isParam = node->isFctParam; | |
| 729 | |||
| 730 |
1/2✓ Branch 20 → 21 taken 51135 times.
✗ Branch 20 → 34 not taken.
|
102270 | return nullptr; |
| 731 | } | ||
| 732 | |||
| 733 | 683 | std::any SymbolTableBuilder::visitModAttr(ModAttrNode *node) { | |
| 734 | // Visit attributes | ||
| 735 |
2/2✓ Branch 2 → 3 taken 682 times.
✓ Branch 2 → 122 taken 1 time.
|
683 | visitChildren(node); |
| 736 | |||
| 737 | // Retrieve attributes | ||
| 738 | 682 | const AttrLstNode *attrs = node->attrLst; | |
| 739 | |||
| 740 | // Collect linker flags | ||
| 741 | 682 | std::vector<const CompileTimeValue *> linkerFlagValues; | |
| 742 | // core.linker.flag | ||
| 743 |
2/4✓ Branch 6 → 7 taken 682 times.
✗ Branch 6 → 125 not taken.
✓ Branch 7 → 8 taken 682 times.
✗ Branch 7 → 123 not taken.
|
1364 | std::vector<const CompileTimeValue *> values = attrs->getAttrValuesByName(ATTR_CORE_LINKER_FLAG); |
| 744 |
1/2✓ Branch 16 → 17 taken 682 times.
✗ Branch 16 → 129 not taken.
|
1364 | linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end()); |
| 745 | // core.linux.linker.flag | ||
| 746 | 682 | const llvm::Triple &targetTriple = sourceFile->targetMachine->getTargetTriple(); | |
| 747 |
2/2✓ Branch 20 → 21 taken 672 times.
✓ Branch 20 → 37 taken 10 times.
|
682 | if (targetTriple.isOSLinux()) { |
| 748 |
2/4✓ Branch 23 → 24 taken 672 times.
✗ Branch 23 → 133 not taken.
✓ Branch 24 → 25 taken 672 times.
✗ Branch 24 → 131 not taken.
|
1344 | values = attrs->getAttrValuesByName(ATTR_CORE_LINUX_LINKER_FLAG); |
| 749 |
1/2✓ Branch 35 → 36 taken 672 times.
✗ Branch 35 → 138 not taken.
|
1344 | linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end()); |
| 750 | } | ||
| 751 | // core.darwin.linker.flag | ||
| 752 |
3/4✓ Branch 37 → 38 taken 682 times.
✗ Branch 37 → 180 not taken.
✓ Branch 38 → 39 taken 5 times.
✓ Branch 38 → 55 taken 677 times.
|
682 | if (targetTriple.isOSDarwin()) { |
| 753 |
2/4✓ Branch 41 → 42 taken 5 times.
✗ Branch 41 → 142 not taken.
✓ Branch 42 → 43 taken 5 times.
✗ Branch 42 → 140 not taken.
|
10 | values = attrs->getAttrValuesByName(ATTR_CORE_DARWIN_LINKER_FLAG); |
| 754 |
1/2✓ Branch 53 → 54 taken 5 times.
✗ Branch 53 → 147 not taken.
|
10 | linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end()); |
| 755 | } | ||
| 756 | // core.windows.linker.flag | ||
| 757 |
2/2✓ Branch 56 → 57 taken 5 times.
✓ Branch 56 → 73 taken 677 times.
|
682 | if (targetTriple.isOSWindows()) { |
| 758 |
2/4✓ Branch 59 → 60 taken 5 times.
✗ Branch 59 → 151 not taken.
✓ Branch 60 → 61 taken 5 times.
✗ Branch 60 → 149 not taken.
|
10 | values = attrs->getAttrValuesByName(ATTR_CORE_WINDOWS_LINKER_FLAG); |
| 759 |
1/2✓ Branch 71 → 72 taken 5 times.
✗ Branch 71 → 156 not taken.
|
10 | linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end()); |
| 760 | } | ||
| 761 |
2/2✓ Branch 88 → 75 taken 1383 times.
✓ Branch 88 → 89 taken 682 times.
|
2747 | for (const CompileTimeValue *value : linkerFlagValues) |
| 762 |
2/4✓ Branch 77 → 78 taken 1383 times.
✗ Branch 77 → 158 not taken.
✓ Branch 78 → 79 taken 1383 times.
✗ Branch 78 → 158 not taken.
|
1383 | resourceManager.linker.addLinkerFlag(resourceManager.compileTimeStringValues.at(value->stringValueOffset)); |
| 763 | |||
| 764 | // core.linker.additionalSource | ||
| 765 |
4/6✓ Branch 89 → 90 taken 682 times.
✗ Branch 89 → 161 not taken.
✓ Branch 90 → 91 taken 682 times.
✗ Branch 90 → 159 not taken.
✓ Branch 112 → 93 taken 12 times.
✓ Branch 112 → 113 taken 681 times.
|
1375 | for (const CompileTimeValue *value : attrs->getAttrValuesByName(ATTR_CORE_LINKER_ADDITIONAL_SOURCE)) { |
| 766 |
1/2✓ Branch 95 → 96 taken 12 times.
✗ Branch 95 → 172 not taken.
|
12 | const std::string &stringValue = resourceManager.compileTimeStringValues.at(value->stringValueOffset); |
| 767 |
5/8✓ Branch 96 → 97 taken 12 times.
✗ Branch 96 → 170 not taken.
✓ Branch 97 → 98 taken 12 times.
✗ Branch 97 → 167 not taken.
✓ Branch 98 → 99 taken 12 times.
✗ Branch 98 → 165 not taken.
✓ Branch 99 → 100 taken 11 times.
✓ Branch 99 → 163 taken 1 time.
|
15 | resourceManager.linker.addAdditionalSourcePath(sourceFile->filePath.parent_path() / stringValue); |
| 768 | 683 | } | |
| 769 | |||
| 770 |
1/2✓ Branch 116 → 117 taken 681 times.
✗ Branch 116 → 179 not taken.
|
1362 | return nullptr; |
| 771 | 683 | } | |
| 772 | |||
| 773 | 3365 | std::any SymbolTableBuilder::visitAttr(AttrNode *node) { | |
| 774 | // Check if this attribute exists | ||
| 775 |
1/2✓ Branch 2 → 3 taken 3365 times.
✗ Branch 2 → 63 not taken.
|
3365 | const auto it = ATTR_CONFIGS.find(node->key); |
| 776 |
2/2✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 3364 times.
|
3365 | if (it == ATTR_CONFIGS.end()) |
| 777 |
3/6✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 40 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 38 not taken.
✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 35 not taken.
|
1 | throw SemanticError(node, UNKNOWN_ATTR, "Unknown attribute '" + node->key + "'"); |
| 778 | |||
| 779 | // Check if the target is correct | ||
| 780 | 3364 | const auto &[target, type] = it->second; | |
| 781 |
2/2✓ Branch 14 → 15 taken 1 time.
✓ Branch 14 → 22 taken 3363 times.
|
3364 | if ((node->target & target) == 0) |
| 782 |
3/6✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 49 not taken.
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 47 not taken.
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 44 not taken.
|
1 | throw SemanticError(node, INVALID_ATTR_TARGET, "Attribute '" + node->key + "' cannot be used on this target"); |
| 783 | |||
| 784 | // Check if a value is present | ||
| 785 |
4/4✓ Branch 22 → 23 taken 705 times.
✓ Branch 22 → 31 taken 2658 times.
✓ Branch 23 → 24 taken 1 time.
✓ Branch 23 → 31 taken 704 times.
|
3363 | if (!node->value && type != AttrNode::AttrType::TYPE_BOOL) |
| 786 |
3/6✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 58 not taken.
✓ Branch 26 → 27 taken 1 time.
✗ Branch 26 → 56 not taken.
✓ Branch 27 → 28 taken 1 time.
✗ Branch 27 → 53 not taken.
|
1 | throw SemanticError(node, MISSING_ATTR_VALUE, "Attribute '" + node->key + "' requires a value"); |
| 787 | |||
| 788 |
1/2✓ Branch 31 → 32 taken 3362 times.
✗ Branch 31 → 62 not taken.
|
6724 | return nullptr; |
| 789 | } | ||
| 790 | |||
| 791 | 22 | std::any SymbolTableBuilder::visitLambdaFunc(LambdaFuncNode *node) { | |
| 792 | // Create scope for the lambda body | ||
| 793 | 22 | const CodeLoc &codeLoc = node->body->codeLoc; | |
| 794 |
2/4✓ Branch 2 → 3 taken 22 times.
✗ Branch 2 → 47 not taken.
✓ Branch 3 → 4 taken 22 times.
✗ Branch 3 → 45 not taken.
|
22 | node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::LAMBDA_BODY, &codeLoc); |
| 795 | // Requires capturing because the LLVM IR will end up in a separate function | ||
| 796 | 22 | currentScope->symbolTable.setCapturingRequired(); | |
| 797 | // Set to async scope if this is an async lambda | ||
| 798 |
4/18✗ Branch 6 → 7 not taken.
✓ Branch 6 → 13 taken 22 times.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 48 not taken.
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 48 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 13 not taken.
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 22 times.
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 19 taken 22 times.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 27 taken 22 times.
✗ Branch 48 → 49 not taken.
✗ Branch 48 → 50 not taken.
✗ Branch 52 → 53 not taken.
✗ Branch 52 → 55 not taken.
|
22 | if (node->lambdaAttr && node->lambdaAttr->attrLst->hasAttr(ATTR_ASYNC)) |
| 799 | ✗ | node->bodyScope->isAsyncScope = node->lambdaAttr->attrLst->getAttrValueByName(ATTR_ASYNC)->boolValue; | |
| 800 | |||
| 801 | // Create symbol for 'result' variable | ||
| 802 |
1/2✓ Branch 29 → 30 taken 22 times.
✗ Branch 29 → 65 not taken.
|
66 | currentScope->insert(RETURN_VARIABLE_NAME, node); |
| 803 | |||
| 804 | // Create symbols for the parameters | ||
| 805 |
2/2✓ Branch 35 → 36 taken 17 times.
✓ Branch 35 → 39 taken 5 times.
|
22 | if (node->hasParams) |
| 806 |
1/2✓ Branch 36 → 37 taken 17 times.
✗ Branch 36 → 69 not taken.
|
17 | visit(node->paramLst); |
| 807 | |||
| 808 | // Visit body | ||
| 809 |
1/2✓ Branch 39 → 40 taken 22 times.
✗ Branch 39 → 70 not taken.
|
22 | visit(node->body); |
| 810 | |||
| 811 | // Leave anonymous block body scope | ||
| 812 | 22 | currentScope = node->bodyScope->parent; | |
| 813 | |||
| 814 |
1/2✓ Branch 41 → 42 taken 22 times.
✗ Branch 41 → 71 not taken.
|
44 | return nullptr; |
| 815 | } | ||
| 816 | |||
| 817 | 72 | std::any SymbolTableBuilder::visitLambdaProc(LambdaProcNode *node) { | |
| 818 | // Create scope for the lambda body | ||
| 819 | 72 | const CodeLoc &codeLoc = node->body->codeLoc; | |
| 820 |
2/4✓ Branch 2 → 3 taken 72 times.
✗ Branch 2 → 39 not taken.
✓ Branch 3 → 4 taken 72 times.
✗ Branch 3 → 37 not taken.
|
72 | node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::LAMBDA_BODY, &codeLoc); |
| 821 | // Requires capturing because the LLVM IR will end up in a separate function | ||
| 822 | 72 | currentScope->symbolTable.setCapturingRequired(); | |
| 823 | // Set to async scope if this is an async lambda | ||
| 824 |
11/18✓ Branch 6 → 7 taken 6 times.
✓ Branch 6 → 13 taken 66 times.
✓ Branch 9 → 10 taken 6 times.
✗ Branch 9 → 40 not taken.
✓ Branch 10 → 11 taken 6 times.
✗ Branch 10 → 40 not taken.
✓ Branch 11 → 12 taken 6 times.
✗ Branch 11 → 13 not taken.
✓ Branch 14 → 15 taken 6 times.
✓ Branch 14 → 16 taken 66 times.
✓ Branch 16 → 17 taken 6 times.
✓ Branch 16 → 19 taken 66 times.
✓ Branch 19 → 20 taken 6 times.
✓ Branch 19 → 27 taken 66 times.
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 42 not taken.
✗ Branch 44 → 45 not taken.
✗ Branch 44 → 47 not taken.
|
84 | if (node->lambdaAttr && node->lambdaAttr->attrLst->hasAttr(ATTR_ASYNC)) |
| 825 |
2/4✓ Branch 22 → 23 taken 6 times.
✗ Branch 22 → 51 not taken.
✓ Branch 23 → 24 taken 6 times.
✗ Branch 23 → 49 not taken.
|
18 | node->bodyScope->isAsyncScope = node->lambdaAttr->attrLst->getAttrValueByName(ATTR_ASYNC)->boolValue; |
| 826 | |||
| 827 | // Create symbols for the parameters | ||
| 828 |
2/2✓ Branch 27 → 28 taken 58 times.
✓ Branch 27 → 31 taken 14 times.
|
72 | if (node->hasParams) |
| 829 |
1/2✓ Branch 28 → 29 taken 58 times.
✗ Branch 28 → 55 not taken.
|
58 | visit(node->paramLst); |
| 830 | |||
| 831 | // Visit body | ||
| 832 |
1/2✓ Branch 31 → 32 taken 72 times.
✗ Branch 31 → 56 not taken.
|
72 | visit(node->body); |
| 833 | |||
| 834 | // Leave anonymous block body scope | ||
| 835 | 72 | currentScope = node->bodyScope->parent; | |
| 836 | |||
| 837 |
1/2✓ Branch 33 → 34 taken 72 times.
✗ Branch 33 → 57 not taken.
|
144 | return nullptr; |
| 838 | } | ||
| 839 | |||
| 840 | 1 | std::any SymbolTableBuilder::visitLambdaExpr(LambdaExprNode *node) { | |
| 841 | // Create scope for the anonymous block body | ||
| 842 | 1 | const CodeLoc &codeLoc = node->lambdaExpr->codeLoc; | |
| 843 |
2/4✓ Branch 2 → 3 taken 1 time.
✗ Branch 2 → 18 not taken.
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 16 not taken.
|
1 | node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::LAMBDA_BODY, &codeLoc); |
| 844 | // Requires capturing because the LLVM IR will end up in a separate function | ||
| 845 | 1 | currentScope->symbolTable.setCapturingRequired(); | |
| 846 | |||
| 847 | // Create symbols for the parameters | ||
| 848 |
1/2✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 10 not taken.
|
1 | if (node->hasParams) |
| 849 |
1/2✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 19 not taken.
|
1 | visit(node->paramLst); |
| 850 | |||
| 851 | // Visit lambda expression | ||
| 852 |
1/2✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 20 not taken.
|
1 | visit(node->lambdaExpr); |
| 853 | |||
| 854 | // Leave anonymous block body scope | ||
| 855 | 1 | currentScope = node->bodyScope->parent; | |
| 856 | |||
| 857 |
1/2✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 21 not taken.
|
2 | return nullptr; |
| 858 | } | ||
| 859 | |||
| 860 | } // namespace spice::compiler | ||
| 861 |