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 <symboltablebuilder/Scope.h> | ||
| 12 | |||
| 13 | namespace spice::compiler { | ||
| 14 | |||
| 15 | 1315 | SymbolTableBuilder::SymbolTableBuilder(GlobalResourceManager &resourceManager, SourceFile *sourceFile) | |
| 16 | 1315 | : CompilerPass(resourceManager, sourceFile), rootScope(sourceFile->globalScope.get()) {} | |
| 17 | |||
| 18 | 1315 | std::any SymbolTableBuilder::visitEntry(EntryNode *node) { | |
| 19 | // Initialize | ||
| 20 | 1315 | currentScope = rootScope; | |
| 21 | |||
| 22 | // Visit children | ||
| 23 |
2/2✓ Branch 2 → 3 taken 1298 times.
✓ Branch 2 → 23 taken 17 times.
|
1315 | visitChildren(node); |
| 24 | |||
| 25 | // Check if the main function exists | ||
| 26 |
4/4✓ Branch 4 → 5 taken 1295 times.
✓ Branch 4 → 7 taken 3 times.
✓ Branch 5 → 6 taken 1290 times.
✓ Branch 5 → 7 taken 5 times.
|
1298 | const bool mainFctRequired = cliOptions.outputContainer == OutputContainer::EXECUTABLE && !cliOptions.noEntryFct; |
| 27 |
6/6✓ Branch 8 → 9 taken 437 times.
✓ Branch 8 → 19 taken 861 times.
✓ Branch 9 → 10 taken 430 times.
✓ Branch 9 → 19 taken 7 times.
✓ Branch 10 → 11 taken 2 times.
✓ Branch 10 → 19 taken 428 times.
|
1298 | if (sourceFile->isMainFile && mainFctRequired && !hasMainFunction) |
| 28 |
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); |
| 29 | |||
| 30 |
1/2✓ Branch 19 → 20 taken 1296 times.
✗ Branch 19 → 33 not taken.
|
2592 | return nullptr; |
| 31 | } | ||
| 32 | |||
| 33 | 433 | std::any SymbolTableBuilder::visitMainFctDef(MainFctDefNode *node) { | |
| 34 | // Visit attributes | ||
| 35 |
2/2✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 6 taken 432 times.
|
433 | if (node->attrs) |
| 36 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 52 taken 1 time.
|
1 | visit(node->attrs); |
| 37 | |||
| 38 | // Check if the function is already defined | ||
| 39 |
3/4✓ Branch 8 → 9 taken 432 times.
✗ Branch 8 → 55 not taken.
✓ Branch 14 → 15 taken 1 time.
✓ Branch 14 → 23 taken 431 times.
|
1728 | if (rootScope->lookupStrict(MAIN_FUNCTION_NAME)) |
| 40 |
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"); |
| 41 | |||
| 42 | // Insert symbol for main function | ||
| 43 |
1/2✓ Branch 25 → 26 taken 431 times.
✗ Branch 25 → 70 not taken.
|
1293 | SymbolTableEntry *mainFctEntry = currentScope->insert(MAIN_FUNCTION_NAME, node); |
| 44 | 431 | mainFctEntry->used = true; | |
| 45 | |||
| 46 | // Create scope for main function body | ||
| 47 |
1/2✓ Branch 31 → 32 taken 431 times.
✗ Branch 31 → 85 not taken.
|
431 | const std::string &scopeId = MainFctDefNode::getScopeId(); |
| 48 |
1/2✓ Branch 32 → 33 taken 431 times.
✗ Branch 32 → 83 not taken.
|
431 | node->bodyScope = currentScope = rootScope->createChildScope(scopeId, ScopeType::FUNC_PROC_BODY, &node->codeLoc); |
| 49 | 431 | currentScope->isGenericScope = false; | |
| 50 | |||
| 51 | // Declare variable for the return value in the function scope | ||
| 52 |
1/2✓ Branch 35 → 36 taken 431 times.
✗ Branch 35 → 76 not taken.
|
1293 | SymbolTableEntry *resultVarEntry = node->bodyScope->insert(RETURN_VARIABLE_NAME, node); |
| 53 | 431 | resultVarEntry->used = true; | |
| 54 | |||
| 55 | // Visit arguments in new scope | ||
| 56 |
2/2✓ Branch 41 → 42 taken 7 times.
✓ Branch 41 → 45 taken 424 times.
|
431 | if (node->takesArgs) |
| 57 |
1/2✓ Branch 42 → 43 taken 7 times.
✗ Branch 42 → 80 not taken.
|
7 | visit(node->paramLst); |
| 58 | |||
| 59 | // Visit function body in new scope | ||
| 60 |
2/2✓ Branch 45 → 46 taken 430 times.
✓ Branch 45 → 81 taken 1 time.
|
431 | visit(node->body); |
| 61 | |||
| 62 | // Return to root scope | ||
| 63 | 430 | currentScope = rootScope; | |
| 64 | |||
| 65 | 430 | hasMainFunction = true; | |
| 66 |
1/2✓ Branch 47 → 48 taken 430 times.
✗ Branch 47 → 82 not taken.
|
860 | return nullptr; |
| 67 | 431 | } | |
| 68 | |||
| 69 | 8981 | std::any SymbolTableBuilder::visitFctDef(FctDefNode *node) { | |
| 70 | // Visit attributes | ||
| 71 |
2/2✓ Branch 2 → 3 taken 376 times.
✓ Branch 2 → 6 taken 8605 times.
|
8981 | if (node->attrs) |
| 72 |
1/2✓ Branch 3 → 4 taken 376 times.
✗ Branch 3 → 98 not taken.
|
376 | visit(node->attrs); |
| 73 | |||
| 74 | // Build function qualifiers | ||
| 75 |
2/2✓ Branch 6 → 7 taken 8774 times.
✓ Branch 6 → 36 taken 207 times.
|
8981 | if (const QualifierLstNode *qualifierLst = node->qualifierLst; qualifierLst) { |
| 76 |
2/2✓ Branch 34 → 9 taken 11964 times.
✓ Branch 34 → 35 taken 8774 times.
|
29512 | for (const QualifierNode *qualifier : qualifierLst->qualifiers) { |
| 77 |
2/2✓ Branch 11 → 12 taken 3197 times.
✓ Branch 11 → 13 taken 8767 times.
|
11964 | if (qualifier->type == QualifierNode::QualifierType::TY_INLINE) |
| 78 | 3197 | node->qualifiers.isInline = true; | |
| 79 |
2/2✓ Branch 13 → 14 taken 8729 times.
✓ Branch 13 → 15 taken 38 times.
|
8767 | else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC) |
| 80 | 8729 | node->qualifiers.isPublic = true; | |
| 81 |
1/2✓ Branch 15 → 16 taken 38 times.
✗ Branch 15 → 17 not taken.
|
38 | else if (qualifier->type == QualifierNode::QualifierType::TY_CONST) |
| 82 | 38 | node->qualifiers.isConst = true; | |
| 83 | else | ||
| 84 | ✗ | throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on a function definition"); | |
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | // Change to struct scope if this function is a method | ||
| 89 |
2/2✓ Branch 36 → 37 taken 3639 times.
✓ Branch 36 → 51 taken 5342 times.
|
8981 | if (node->isMethod) { |
| 90 |
1/2✓ Branch 38 → 39 taken 3639 times.
✗ Branch 38 → 109 not taken.
|
3639 | const std::string scopeName = Struct::getScopeName(node->name->structName); |
| 91 |
1/2✓ Branch 40 → 41 taken 3639 times.
✗ Branch 40 → 121 not taken.
|
3639 | node->structScope = currentScope = currentScope->getChildScope(scopeName); |
| 92 |
1/2✗ Branch 41 → 42 not taken.
✓ Branch 41 → 49 taken 3639 times.
|
3639 | if (!currentScope) |
| 93 | ✗ | throw SemanticError(node, REFERENCED_UNDEFINED_STRUCT, "Struct '" + node->name->structName + "' could not be found"); | |
| 94 | 3639 | } | |
| 95 | |||
| 96 | // Create scope for the function | ||
| 97 |
2/4✓ Branch 51 → 52 taken 8981 times.
✗ Branch 51 → 126 not taken.
✓ Branch 52 → 53 taken 8981 times.
✗ Branch 52 → 124 not taken.
|
8981 | node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc); |
| 98 |
6/6✓ Branch 54 → 55 taken 7866 times.
✓ Branch 54 → 57 taken 1115 times.
✓ Branch 55 → 56 taken 3490 times.
✓ Branch 55 → 58 taken 4376 times.
✓ Branch 56 → 57 taken 1139 times.
✓ Branch 56 → 58 taken 2351 times.
|
8981 | currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope); |
| 99 | |||
| 100 | // Create symbol for 'this' variable | ||
| 101 |
2/2✓ Branch 59 → 60 taken 3639 times.
✓ Branch 59 → 69 taken 5342 times.
|
8981 | if (node->isMethod) |
| 102 |
1/2✓ Branch 62 → 63 taken 3639 times.
✗ Branch 62 → 129 not taken.
|
14556 | currentScope->insert(THIS_VARIABLE_NAME, node); |
| 103 | |||
| 104 | // Create symbol for 'result' variable | ||
| 105 |
1/2✓ Branch 71 → 72 taken 8981 times.
✗ Branch 71 → 135 not taken.
|
26943 | currentScope->insert(RETURN_VARIABLE_NAME, node); |
| 106 | |||
| 107 | // Create symbols for the parameters | ||
| 108 |
2/2✓ Branch 77 → 78 taken 6940 times.
✓ Branch 77 → 81 taken 2041 times.
|
8981 | if (node->hasParams) |
| 109 |
1/2✓ Branch 78 → 79 taken 6940 times.
✗ Branch 78 → 139 not taken.
|
6940 | visit(node->paramLst); |
| 110 | |||
| 111 | // Visit the function body | ||
| 112 |
1/2✓ Branch 81 → 82 taken 8981 times.
✗ Branch 81 → 140 not taken.
|
8981 | visit(node->body); |
| 113 | |||
| 114 | // Leave function body scope | ||
| 115 | 8981 | currentScope = node->scope->parent; | |
| 116 | |||
| 117 | // Insert symbol for function into the symbol table | ||
| 118 |
1/2✓ Branch 83 → 84 taken 8981 times.
✗ Branch 83 → 143 not taken.
|
17962 | node->entry = currentScope->insert(node->getSymbolTableEntryName(), node); |
| 119 | |||
| 120 | // Add to external name registry | ||
| 121 | // if a function has overloads, they both refer to the same entry in the registry. So we only register the name once | ||
| 122 | 8981 | const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName); | |
| 123 |
3/4✓ Branch 89 → 90 taken 2324 times.
✓ Branch 89 → 91 taken 6657 times.
✓ Branch 90 → 91 taken 2324 times.
✗ Branch 90 → 92 not taken.
|
8981 | if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry) |
| 124 | 8981 | sourceFile->addNameRegistryEntry(node->name->fqName, TY_FUNCTION, node->entry, currentScope, true); | |
| 125 | |||
| 126 | // Leave the struct scope | ||
| 127 |
2/2✓ Branch 92 → 93 taken 3639 times.
✓ Branch 92 → 94 taken 5342 times.
|
8981 | if (node->isMethod) |
| 128 | 3639 | currentScope = node->structScope->parent; | |
| 129 | |||
| 130 |
1/2✓ Branch 94 → 95 taken 8981 times.
✗ Branch 94 → 144 not taken.
|
17962 | return nullptr; |
| 131 | } | ||
| 132 | |||
| 133 | 4837 | std::any SymbolTableBuilder::visitProcDef(ProcDefNode *node) { | |
| 134 | // Visit attributes | ||
| 135 |
2/2✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 6 taken 4836 times.
|
4837 | if (node->attrs) |
| 136 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 97 taken 1 time.
|
1 | visit(node->attrs); |
| 137 | |||
| 138 | // Build procedure qualifiers | ||
| 139 |
2/2✓ Branch 6 → 7 taken 4216 times.
✓ Branch 6 → 36 taken 620 times.
|
4836 | if (const QualifierLstNode *qualifierLst = node->qualifierLst) { |
| 140 |
2/2✓ Branch 34 → 9 taken 4775 times.
✓ Branch 34 → 35 taken 4216 times.
|
13207 | for (const QualifierNode *qualifier : qualifierLst->qualifiers) { |
| 141 |
2/2✓ Branch 11 → 12 taken 562 times.
✓ Branch 11 → 13 taken 4213 times.
|
4775 | if (qualifier->type == QualifierNode::QualifierType::TY_INLINE) |
| 142 | 562 | node->qualifiers.isInline = true; | |
| 143 |
2/2✓ Branch 13 → 14 taken 4212 times.
✓ Branch 13 → 15 taken 1 time.
|
4213 | else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC) |
| 144 | 4212 | node->qualifiers.isPublic = true; | |
| 145 |
1/2✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 17 not taken.
|
1 | else if (qualifier->type == QualifierNode::QualifierType::TY_CONST) |
| 146 | 1 | node->qualifiers.isConst = true; | |
| 147 | else | ||
| 148 | ✗ | throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on a procedure definition"); | |
| 149 | } | ||
| 150 | } | ||
| 151 | |||
| 152 | // Change to struct scope if this procedure is a method | ||
| 153 |
2/2✓ Branch 36 → 37 taken 3871 times.
✓ Branch 36 → 51 taken 965 times.
|
4836 | if (node->isMethod) { |
| 154 |
1/2✓ Branch 38 → 39 taken 3871 times.
✗ Branch 38 → 108 not taken.
|
3871 | const std::string &scopeName = Struct::getScopeName(node->name->structName); |
| 155 |
1/2✓ Branch 40 → 41 taken 3871 times.
✗ Branch 40 → 120 not taken.
|
3871 | node->structScope = currentScope = currentScope->getChildScope(scopeName); |
| 156 |
2/2✓ Branch 41 → 42 taken 1 time.
✓ Branch 41 → 49 taken 3870 times.
|
3871 | if (!currentScope) |
| 157 |
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"); |
| 158 | 3871 | } | |
| 159 | |||
| 160 | // Create scope for the procedure | ||
| 161 |
2/4✓ Branch 51 → 52 taken 4835 times.
✗ Branch 51 → 125 not taken.
✓ Branch 52 → 53 taken 4835 times.
✗ Branch 52 → 123 not taken.
|
4835 | node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc); |
| 162 |
6/6✓ Branch 54 → 55 taken 3518 times.
✓ Branch 54 → 57 taken 1317 times.
✓ Branch 55 → 56 taken 3162 times.
✓ Branch 55 → 58 taken 356 times.
✓ Branch 56 → 57 taken 954 times.
✓ Branch 56 → 58 taken 2208 times.
|
4835 | currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope); |
| 163 |
4/4✓ Branch 59 → 60 taken 3870 times.
✓ Branch 59 → 63 taken 965 times.
✓ Branch 61 → 62 taken 135 times.
✓ Branch 61 → 63 taken 3735 times.
|
4835 | currentScope->isDtorScope = node->isMethod && node->name->name == DTOR_FUNCTION_NAME; |
| 164 | |||
| 165 | // Create symbol for 'this' variable | ||
| 166 |
2/2✓ Branch 64 → 65 taken 3870 times.
✓ Branch 64 → 74 taken 965 times.
|
4835 | if (node->isMethod) |
| 167 |
1/2✓ Branch 67 → 68 taken 3870 times.
✗ Branch 67 → 128 not taken.
|
15480 | currentScope->insert(THIS_VARIABLE_NAME, node); |
| 168 | |||
| 169 | // Create symbols for the parameters | ||
| 170 |
2/2✓ Branch 74 → 75 taken 3621 times.
✓ Branch 74 → 78 taken 1214 times.
|
4835 | if (node->hasParams) |
| 171 |
1/2✓ Branch 75 → 76 taken 3621 times.
✗ Branch 75 → 132 not taken.
|
3621 | visit(node->paramLst); |
| 172 | |||
| 173 | // Visit the procedure body | ||
| 174 |
1/2✓ Branch 78 → 79 taken 4835 times.
✗ Branch 78 → 133 not taken.
|
4835 | visit(node->body); |
| 175 | |||
| 176 | // Leave procedure body scope | ||
| 177 | 4835 | currentScope = node->scope->parent; | |
| 178 | |||
| 179 | // Insert symbol for procedure into the symbol table | ||
| 180 |
1/2✓ Branch 80 → 81 taken 4835 times.
✗ Branch 80 → 136 not taken.
|
9670 | node->entry = currentScope->insert(node->getSymbolTableEntryName(), node); |
| 181 | |||
| 182 | // Add to external name registry | ||
| 183 | // if a procedure has overloads, they both refer to the same entry in the registry. So we only register the name once | ||
| 184 | 4835 | const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName); | |
| 185 |
3/4✓ Branch 86 → 87 taken 1306 times.
✓ Branch 86 → 88 taken 3529 times.
✓ Branch 87 → 88 taken 1306 times.
✗ Branch 87 → 89 not taken.
|
4835 | if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry) |
| 186 | 4835 | sourceFile->addNameRegistryEntry(node->name->fqName, TY_PROCEDURE, node->entry, currentScope, true); | |
| 187 | |||
| 188 | // Leave the struct scope | ||
| 189 |
2/2✓ Branch 89 → 90 taken 3870 times.
✓ Branch 89 → 91 taken 965 times.
|
4835 | if (node->isMethod) |
| 190 | 3870 | currentScope = node->structScope->parent; | |
| 191 | |||
| 192 | // Check if this is a constructor | ||
| 193 | 4835 | node->isCtor = node->name->nameFragments.back() == CTOR_FUNCTION_NAME; | |
| 194 | |||
| 195 |
1/2✓ Branch 93 → 94 taken 4835 times.
✗ Branch 93 → 137 not taken.
|
9670 | return nullptr; |
| 196 | } | ||
| 197 | |||
| 198 | 823 | std::any SymbolTableBuilder::visitStructDef(StructDefNode *node) { | |
| 199 | // Visit attributes | ||
| 200 |
2/2✓ Branch 2 → 3 taken 67 times.
✓ Branch 2 → 6 taken 756 times.
|
823 | if (node->attrs) |
| 201 |
1/2✓ Branch 3 → 4 taken 67 times.
✗ Branch 3 → 79 not taken.
|
67 | visit(node->attrs); |
| 202 | |||
| 203 | // Check if this name already exists | ||
| 204 |
3/4✓ Branch 6 → 7 taken 823 times.
✗ Branch 6 → 110 not taken.
✓ Branch 9 → 10 taken 1 time.
✓ Branch 9 → 17 taken 822 times.
|
1646 | if (rootScope->lookupStrict(node->structName)) |
| 205 |
3/6✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 85 not taken.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 83 not taken.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 80 not taken.
|
1 | throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->structName + "'"); |
| 206 | |||
| 207 | // Create scope for the struct | ||
| 208 |
1/2✓ Branch 18 → 19 taken 822 times.
✗ Branch 18 → 89 not taken.
|
822 | const std::string &scopeName = Struct::getScopeName(node->structName); |
| 209 |
1/2✓ Branch 20 → 21 taken 822 times.
✗ Branch 20 → 108 not taken.
|
822 | node->structScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::STRUCT, &node->codeLoc); |
| 210 | 822 | currentScope->isGenericScope = node->hasTemplateTypes; | |
| 211 | |||
| 212 | // Insert implicit field for each interface type | ||
| 213 |
2/2✓ Branch 21 → 22 taken 156 times.
✓ Branch 21 → 43 taken 666 times.
|
822 | if (node->hasInterfaces) { |
| 214 |
2/2✓ Branch 41 → 24 taken 156 times.
✓ Branch 41 → 42 taken 156 times.
|
468 | for (DataTypeNode *interfaceNode : node->interfaceTypeLst->dataTypes) { |
| 215 | 156 | const std::string &interfaceName = interfaceNode->baseDataType->customDataType->typeNameFragments.back(); | |
| 216 |
1/2✓ Branch 27 → 28 taken 156 times.
✗ Branch 27 → 94 not taken.
|
312 | SymbolTableEntry *interfaceFieldEntry = currentScope->insert("this." + interfaceName, interfaceNode); |
| 217 | 156 | interfaceFieldEntry->used = true; | |
| 218 | 156 | interfaceFieldEntry->isImplicitField = true; | |
| 219 | } | ||
| 220 | } | ||
| 221 | |||
| 222 | // Visit children | ||
| 223 |
2/2✓ Branch 43 → 44 taken 821 times.
✓ Branch 43 → 96 taken 1 time.
|
822 | visitChildren(node); |
| 224 | |||
| 225 | // Leave the struct scope | ||
| 226 | 821 | currentScope = node->structScope->parent; | |
| 227 | |||
| 228 | // Build struct qualifiers | ||
| 229 |
2/2✓ Branch 45 → 46 taken 639 times.
✓ Branch 45 → 70 taken 182 times.
|
821 | if (const QualifierLstNode *qualifierLst = node->qualifierLst) { |
| 230 |
2/2✓ Branch 68 → 48 taken 639 times.
✓ Branch 68 → 69 taken 639 times.
|
1917 | for (const QualifierNode *qualifier : qualifierLst->qualifiers) { |
| 231 |
1/2✓ Branch 50 → 51 taken 639 times.
✗ Branch 50 → 54 not taken.
|
639 | if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC) |
| 232 | 639 | node->qualifiers.isPublic = true; | |
| 233 | else | ||
| 234 | ✗ | throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on a struct definition"); | |
| 235 | } | ||
| 236 | } | ||
| 237 | |||
| 238 | // Add the struct to the symbol table | ||
| 239 |
1/2✓ Branch 70 → 71 taken 821 times.
✗ Branch 70 → 108 not taken.
|
821 | node->entry = rootScope->insert(node->structName, node); |
| 240 | // Register the name in the exported name registry | ||
| 241 |
1/2✓ Branch 73 → 74 taken 821 times.
✗ Branch 73 → 108 not taken.
|
821 | sourceFile->addNameRegistryEntry(node->structName, node->typeId, node->entry, node->structScope, true); |
| 242 | |||
| 243 |
1/2✓ Branch 74 → 75 taken 821 times.
✗ Branch 74 → 107 not taken.
|
1642 | return nullptr; |
| 244 | 822 | } | |
| 245 | |||
| 246 | 112 | std::any SymbolTableBuilder::visitInterfaceDef(InterfaceDefNode *node) { | |
| 247 | // Visit attributes | ||
| 248 |
2/2✓ Branch 2 → 3 taken 81 times.
✓ Branch 2 → 6 taken 31 times.
|
112 | if (node->attrs) |
| 249 |
1/2✓ Branch 3 → 4 taken 81 times.
✗ Branch 3 → 71 not taken.
|
81 | visit(node->attrs); |
| 250 | |||
| 251 | // Check if this name already exists | ||
| 252 |
3/4✓ Branch 6 → 7 taken 112 times.
✗ Branch 6 → 99 not taken.
✓ Branch 9 → 10 taken 1 time.
✓ Branch 9 → 17 taken 111 times.
|
224 | if (rootScope->lookupStrict(node->interfaceName)) |
| 253 |
3/6✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 77 not taken.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 75 not taken.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 72 not taken.
|
1 | throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->interfaceName + "'"); |
| 254 | |||
| 255 | // Create scope for the interface | ||
| 256 |
1/2✓ Branch 18 → 19 taken 111 times.
✗ Branch 18 → 81 not taken.
|
111 | const std::string &scopeName = Interface::getScopeName(node->interfaceName); |
| 257 |
1/2✓ Branch 20 → 21 taken 111 times.
✗ Branch 20 → 97 not taken.
|
111 | node->interfaceScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::INTERFACE, &node->codeLoc); |
| 258 | |||
| 259 | // Visit signatures | ||
| 260 |
2/2✓ Branch 36 → 23 taken 253 times.
✓ Branch 36 → 37 taken 111 times.
|
475 | for (SignatureNode *signature : node->signatures) |
| 261 |
1/2✓ Branch 25 → 26 taken 253 times.
✗ Branch 25 → 84 not taken.
|
253 | visit(signature); |
| 262 | |||
| 263 | // Leave the interface scope | ||
| 264 | 111 | currentScope = node->interfaceScope->parent; | |
| 265 | |||
| 266 | // Build interface qualifiers | ||
| 267 |
2/2✓ Branch 37 → 38 taken 94 times.
✓ Branch 37 → 62 taken 17 times.
|
111 | if (const QualifierLstNode *qualifierLst = node->qualifierLst) { |
| 268 |
2/2✓ Branch 60 → 40 taken 94 times.
✓ Branch 60 → 61 taken 94 times.
|
282 | for (const QualifierNode *qualifier : qualifierLst->qualifiers) { |
| 269 |
1/2✓ Branch 42 → 43 taken 94 times.
✗ Branch 42 → 46 not taken.
|
94 | if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC) |
| 270 | 94 | node->qualifiers.isPublic = true; | |
| 271 | else | ||
| 272 | ✗ | throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on an interface definition"); | |
| 273 | } | ||
| 274 | } | ||
| 275 | |||
| 276 | // Add the interface to the symbol table | ||
| 277 |
1/2✓ Branch 62 → 63 taken 111 times.
✗ Branch 62 → 97 not taken.
|
111 | node->entry = rootScope->insert(node->interfaceName, node); |
| 278 | // Register the name in the exported name registry | ||
| 279 |
1/2✓ Branch 65 → 66 taken 111 times.
✗ Branch 65 → 97 not taken.
|
111 | sourceFile->addNameRegistryEntry(node->interfaceName, node->typeId, node->entry, node->interfaceScope, true); |
| 280 | |||
| 281 |
1/2✓ Branch 66 → 67 taken 111 times.
✗ Branch 66 → 96 not taken.
|
222 | return nullptr; |
| 282 | 111 | } | |
| 283 | |||
| 284 | 79 | std::any SymbolTableBuilder::visitEnumDef(EnumDefNode *node) { | |
| 285 | // Check if this name already exists | ||
| 286 |
2/2✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 78 times.
|
158 | if (rootScope->lookupStrict(node->enumName)) |
| 287 |
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 + "'"); |
| 288 | |||
| 289 | // Create scope for the enum | ||
| 290 | 78 | node->enumScope = currentScope = | |
| 291 |
2/4✓ Branch 13 → 14 taken 78 times.
✗ Branch 13 → 62 not taken.
✓ Branch 14 → 15 taken 78 times.
✗ Branch 14 → 60 not taken.
|
78 | rootScope->createChildScope(ENUM_SCOPE_PREFIX + node->enumName, ScopeType::ENUM, &node->codeLoc); |
| 292 | |||
| 293 | // Visit items | ||
| 294 |
2/2✓ Branch 16 → 17 taken 77 times.
✓ Branch 16 → 63 taken 1 time.
|
78 | visit(node->itemLst); |
| 295 | |||
| 296 | // Leave the enum scope | ||
| 297 | 77 | currentScope = node->enumScope->parent; | |
| 298 | |||
| 299 | // Build enum qualifiers | ||
| 300 |
2/2✓ Branch 18 → 19 taken 60 times.
✓ Branch 18 → 43 taken 17 times.
|
77 | if (node->qualifierLst) { |
| 301 |
2/2✓ Branch 41 → 21 taken 60 times.
✓ Branch 41 → 42 taken 60 times.
|
180 | for (const QualifierNode *qualifier : node->qualifierLst->qualifiers) { |
| 302 |
1/2✓ Branch 23 → 24 taken 60 times.
✗ Branch 23 → 27 not taken.
|
60 | if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC) |
| 303 | 60 | node->qualifiers.isPublic = true; | |
| 304 | else | ||
| 305 | ✗ | throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on an enum definition"); | |
| 306 | } | ||
| 307 | } | ||
| 308 | |||
| 309 | // Add the enum to the symbol table | ||
| 310 | 77 | node->entry = rootScope->insert(node->enumName, node); | |
| 311 | // Register the name in the exported name registry | ||
| 312 | 77 | sourceFile->addNameRegistryEntry(node->enumName, node->typeId, node->entry, node->enumScope, true); | |
| 313 | |||
| 314 |
1/2✓ Branch 47 → 48 taken 77 times.
✗ Branch 47 → 74 not taken.
|
154 | return nullptr; |
| 315 | } | ||
| 316 | |||
| 317 | 1085 | std::any SymbolTableBuilder::visitGenericTypeDef(GenericTypeDefNode *node) { | |
| 318 | // Check if this name already exists | ||
| 319 |
2/2✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 1084 times.
|
2170 | if (rootScope->lookupStrict(node->typeName)) |
| 320 |
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 + "'"); |
| 321 | |||
| 322 | // Create the generic type to the symbol table | ||
| 323 | 1084 | node->entry = rootScope->insert(node->typeName, node); | |
| 324 | 1084 | node->entry->used = true; // Generic types are always used | |
| 325 | |||
| 326 |
1/2✓ Branch 16 → 17 taken 1084 times.
✗ Branch 16 → 29 not taken.
|
2168 | return nullptr; |
| 327 | } | ||
| 328 | |||
| 329 | 112 | std::any SymbolTableBuilder::visitAliasDef(AliasDefNode *node) { | |
| 330 | // Check if this name already exists | ||
| 331 |
3/4✓ Branch 2 → 3 taken 112 times.
✗ Branch 2 → 73 not taken.
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 111 times.
|
224 | if (rootScope->lookupStrict(node->aliasName)) |
| 332 |
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 + "'"); |
| 333 | |||
| 334 | // Build alias qualifiers | ||
| 335 |
2/2✓ Branch 13 → 14 taken 33 times.
✓ Branch 13 → 38 taken 78 times.
|
111 | if (const QualifierLstNode *qualifierLst = node->qualifierLst) { |
| 336 |
2/2✓ Branch 36 → 16 taken 33 times.
✓ Branch 36 → 37 taken 33 times.
|
99 | for (const QualifierNode *qualifier : qualifierLst->qualifiers) { |
| 337 |
1/2✓ Branch 18 → 19 taken 33 times.
✗ Branch 18 → 22 not taken.
|
33 | if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC) |
| 338 | 33 | node->qualifiers.isPublic = true; | |
| 339 | else | ||
| 340 | ✗ | throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on an alias definition"); | |
| 341 | } | ||
| 342 | } | ||
| 343 | |||
| 344 | // Add the alias to the symbol table | ||
| 345 |
1/2✓ Branch 38 → 39 taken 111 times.
✗ Branch 38 → 73 not taken.
|
111 | node->entry = rootScope->insert(node->aliasName, node); |
| 346 | // Register the name in the exported name registry | ||
| 347 |
1/2✓ Branch 41 → 42 taken 111 times.
✗ Branch 41 → 73 not taken.
|
111 | sourceFile->addNameRegistryEntry(node->aliasName, node->typeId, node->entry, rootScope, true); |
| 348 | |||
| 349 | // Add another symbol for the aliased type container | ||
| 350 |
1/2✓ Branch 42 → 43 taken 111 times.
✗ Branch 42 → 73 not taken.
|
111 | const std::string aliasedTypeContainerName = node->aliasName + ALIAS_CONTAINER_SUFFIX; |
| 351 |
1/2✓ Branch 43 → 44 taken 111 times.
✗ Branch 43 → 71 not taken.
|
111 | node->aliasedTypeContainerEntry = rootScope->insert(aliasedTypeContainerName, node); |
| 352 | |||
| 353 |
1/2✓ Branch 46 → 47 taken 111 times.
✗ Branch 46 → 70 not taken.
|
222 | return nullptr; |
| 354 | 111 | } | |
| 355 | |||
| 356 | 1347 | std::any SymbolTableBuilder::visitGlobalVarDef(GlobalVarDefNode *node) { | |
| 357 | // Check if this name already exists | ||
| 358 |
2/2✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 1346 times.
|
2694 | if (rootScope->lookupStrict(node->varName)) |
| 359 |
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 + "'"); |
| 360 | |||
| 361 | // Check if global already exists in an imported source file | ||
| 362 |
5/8✓ Branch 13 → 14 taken 1346 times.
✗ Branch 13 → 56 not taken.
✓ Branch 14 → 15 taken 1346 times.
✗ Branch 14 → 56 not taken.
✓ Branch 15 → 16 taken 1346 times.
✗ Branch 15 → 56 not taken.
✓ Branch 29 → 17 taken 526 times.
✓ Branch 29 → 30 taken 1345 times.
|
1871 | for (const auto &dependency : sourceFile->dependencies | std::views::values) |
| 363 |
3/4✓ Branch 18 → 19 taken 526 times.
✗ Branch 18 → 56 not taken.
✓ Branch 19 → 20 taken 1 time.
✓ Branch 19 → 27 taken 525 times.
|
526 | if (dependency->exportedNameRegistry.contains(node->varName)) |
| 364 |
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"); |
| 365 | |||
| 366 | // Add the global to the symbol table | ||
| 367 | 1345 | node->entry = rootScope->insert(node->varName, node); | |
| 368 | // Register the name in the exported name registry | ||
| 369 | 1345 | sourceFile->addNameRegistryEntry(node->varName, TY_INVALID, node->entry, currentScope, true); | |
| 370 | |||
| 371 |
1/2✓ Branch 34 → 35 taken 1345 times.
✗ Branch 34 → 57 not taken.
|
2690 | return nullptr; |
| 372 | } | ||
| 373 | |||
| 374 | 1195 | std::any SymbolTableBuilder::visitExtDecl(ExtDeclNode *node) { | |
| 375 | // Visit attributes | ||
| 376 |
2/2✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 6 taken 1194 times.
|
1195 | if (node->attrs) |
| 377 |
1/2✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 31 not taken.
|
1 | visit(node->attrs); |
| 378 | |||
| 379 | // Check if this name already exists | ||
| 380 |
2/2✓ Branch 9 → 10 taken 1 time.
✓ Branch 9 → 17 taken 1194 times.
|
2390 | if (rootScope->lookupStrict(node->extFunctionName)) |
| 381 |
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 + "'"); |
| 382 | |||
| 383 | // Create scope for the external function (this is required in case of forceSubstantiation in FunctionManager::matchFunction) | ||
| 384 |
2/4✓ Branch 17 → 18 taken 1194 times.
✗ Branch 17 → 43 not taken.
✓ Branch 18 → 19 taken 1194 times.
✗ Branch 18 → 41 not taken.
|
1194 | rootScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc); |
| 385 | |||
| 386 | // Add the external declaration to the symbol table | ||
| 387 | 1194 | node->entry = rootScope->insert(node->extFunctionName, node); | |
| 388 | // Register the name in the exported name registry | ||
| 389 |
2/2✓ Branch 23 → 24 taken 774 times.
✓ Branch 23 → 25 taken 420 times.
|
1194 | const uint64_t typeId = node->returnType ? TY_FUNCTION : TY_PROCEDURE; |
| 390 | 1194 | sourceFile->addNameRegistryEntry(node->extFunctionName, typeId, node->entry, rootScope, /*keepNewOnCollision=*/true); | |
| 391 | |||
| 392 |
1/2✓ Branch 27 → 28 taken 1194 times.
✗ Branch 27 → 44 not taken.
|
2388 | return nullptr; |
| 393 | } | ||
| 394 | |||
| 395 | 2976 | std::any SymbolTableBuilder::visitUnsafeBlock(UnsafeBlockNode *node) { | |
| 396 | // Create scope for the unsafe block body | ||
| 397 | 2976 | node->bodyScope = currentScope = | |
| 398 |
2/4✓ Branch 2 → 3 taken 2976 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 2976 times.
✗ Branch 3 → 11 not taken.
|
2976 | currentScope->createChildScope(node->getScopeId(), ScopeType::UNSAFE_BODY, &node->body->codeLoc); |
| 399 | |||
| 400 | // Visit body | ||
| 401 |
1/2✓ Branch 5 → 6 taken 2976 times.
✗ Branch 5 → 14 not taken.
|
2976 | visit(node->body); |
| 402 | |||
| 403 | // Leave thread body scope | ||
| 404 | 2976 | currentScope = node->bodyScope->parent; | |
| 405 | |||
| 406 |
1/2✓ Branch 7 → 8 taken 2976 times.
✗ Branch 7 → 15 not taken.
|
5952 | return nullptr; |
| 407 | } | ||
| 408 | |||
| 409 | 1565 | std::any SymbolTableBuilder::visitForLoop(ForLoopNode *node) { | |
| 410 | // Create scope for the loop body | ||
| 411 |
2/4✓ Branch 2 → 3 taken 1565 times.
✗ Branch 2 → 15 not taken.
✓ Branch 3 → 4 taken 1565 times.
✗ Branch 3 → 13 not taken.
|
1565 | node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FOR_BODY, &node->body->codeLoc); |
| 412 | |||
| 413 | // Visit loop variable declaration | ||
| 414 |
1/2✓ Branch 5 → 6 taken 1565 times.
✗ Branch 5 → 16 not taken.
|
1565 | visit(node->initDecl); |
| 415 | |||
| 416 | // Visit body | ||
| 417 |
1/2✓ Branch 7 → 8 taken 1565 times.
✗ Branch 7 → 17 not taken.
|
1565 | visit(node->body); |
| 418 | |||
| 419 | // Leave for body scope | ||
| 420 | 1565 | currentScope = node->bodyScope->parent; | |
| 421 | |||
| 422 |
1/2✓ Branch 9 → 10 taken 1565 times.
✗ Branch 9 → 18 not taken.
|
3130 | return nullptr; |
| 423 | } | ||
| 424 | |||
| 425 | 154 | std::any SymbolTableBuilder::visitForeachLoop(ForeachLoopNode *node) { | |
| 426 | // Create scope for the loop body | ||
| 427 | 154 | node->bodyScope = currentScope = | |
| 428 |
2/4✓ Branch 2 → 3 taken 154 times.
✗ Branch 2 → 19 not taken.
✓ Branch 3 → 4 taken 154 times.
✗ Branch 3 → 17 not taken.
|
154 | currentScope->createChildScope(node->getScopeId(), ScopeType::FOREACH_BODY, &node->body->codeLoc); |
| 429 | |||
| 430 | // Visit index variable declaration | ||
| 431 |
2/2✓ Branch 5 → 6 taken 8 times.
✓ Branch 5 → 9 taken 146 times.
|
154 | if (node->idxVarDecl) |
| 432 |
1/2✓ Branch 6 → 7 taken 8 times.
✗ Branch 6 → 20 not taken.
|
8 | visit(node->idxVarDecl); |
| 433 | |||
| 434 | // Visit item variable declaration | ||
| 435 |
1/2✓ Branch 9 → 10 taken 154 times.
✗ Branch 9 → 21 not taken.
|
154 | visit(node->itemVarDecl); |
| 436 | |||
| 437 | // Visit body | ||
| 438 |
1/2✓ Branch 11 → 12 taken 154 times.
✗ Branch 11 → 22 not taken.
|
154 | visit(node->body); |
| 439 | |||
| 440 | // Leave foreach body scope | ||
| 441 | 154 | currentScope = node->bodyScope->parent; | |
| 442 | |||
| 443 |
1/2✓ Branch 13 → 14 taken 154 times.
✗ Branch 13 → 23 not taken.
|
308 | return nullptr; |
| 444 | } | ||
| 445 | |||
| 446 | 888 | std::any SymbolTableBuilder::visitWhileLoop(WhileLoopNode *node) { | |
| 447 | // Create scope for the loop body | ||
| 448 | 888 | node->bodyScope = currentScope = | |
| 449 |
2/4✓ Branch 2 → 3 taken 888 times.
✗ Branch 2 → 15 not taken.
✓ Branch 3 → 4 taken 888 times.
✗ Branch 3 → 13 not taken.
|
888 | currentScope->createChildScope(node->getScopeId(), ScopeType::WHILE_BODY, &node->body->codeLoc); |
| 450 | |||
| 451 | // Visit condition | ||
| 452 |
1/2✓ Branch 5 → 6 taken 888 times.
✗ Branch 5 → 16 not taken.
|
888 | visit(node->condition); |
| 453 | |||
| 454 | // Visit body | ||
| 455 |
1/2✓ Branch 7 → 8 taken 888 times.
✗ Branch 7 → 17 not taken.
|
888 | visit(node->body); |
| 456 | |||
| 457 | // Leave while body scope | ||
| 458 | 888 | currentScope = node->bodyScope->parent; | |
| 459 | |||
| 460 |
1/2✓ Branch 9 → 10 taken 888 times.
✗ Branch 9 → 18 not taken.
|
1776 | return nullptr; |
| 461 | } | ||
| 462 | |||
| 463 | 8 | std::any SymbolTableBuilder::visitDoWhileLoop(DoWhileLoopNode *node) { | |
| 464 | // Create scope for the loop body | ||
| 465 | 8 | node->bodyScope = currentScope = | |
| 466 |
2/4✓ Branch 2 → 3 taken 8 times.
✗ Branch 2 → 15 not taken.
✓ Branch 3 → 4 taken 8 times.
✗ Branch 3 → 13 not taken.
|
8 | currentScope->createChildScope(node->getScopeId(), ScopeType::WHILE_BODY, &node->body->codeLoc); |
| 467 | |||
| 468 | // Visit condition | ||
| 469 |
1/2✓ Branch 5 → 6 taken 8 times.
✗ Branch 5 → 16 not taken.
|
8 | visit(node->condition); |
| 470 | |||
| 471 | // Visit body | ||
| 472 |
1/2✓ Branch 7 → 8 taken 8 times.
✗ Branch 7 → 17 not taken.
|
8 | visit(node->body); |
| 473 | |||
| 474 | // Leave do-while body scope | ||
| 475 | 8 | currentScope = node->bodyScope->parent; | |
| 476 | |||
| 477 |
1/2✓ Branch 9 → 10 taken 8 times.
✗ Branch 9 → 18 not taken.
|
16 | return nullptr; |
| 478 | } | ||
| 479 | |||
| 480 | 4889 | std::any SymbolTableBuilder::visitIfStmt(IfStmtNode *node) { | |
| 481 | // Create scope for the then body | ||
| 482 | 4889 | node->thenBodyScope = currentScope = | |
| 483 |
2/4✓ Branch 2 → 3 taken 4889 times.
✗ Branch 2 → 22 not taken.
✓ Branch 3 → 4 taken 4889 times.
✗ Branch 3 → 20 not taken.
|
4889 | currentScope->createChildScope(node->getScopeId(), ScopeType::IF_ELSE_BODY, &node->thenBody->codeLoc); |
| 484 | |||
| 485 | // Visit condition | ||
| 486 |
1/2✓ Branch 5 → 6 taken 4889 times.
✗ Branch 5 → 23 not taken.
|
4889 | visit(node->condition); |
| 487 | |||
| 488 | // Visit then body | ||
| 489 |
1/2✓ Branch 7 → 8 taken 4889 times.
✗ Branch 7 → 11 not taken.
|
4889 | if (node->compileThenBranch) |
| 490 |
1/2✓ Branch 8 → 9 taken 4889 times.
✗ Branch 8 → 24 not taken.
|
4889 | visit(node->thenBody); |
| 491 | |||
| 492 | // Leave then body scope | ||
| 493 | 4889 | currentScope = node->thenBodyScope->parent; | |
| 494 | |||
| 495 | // Visit else stmt | ||
| 496 |
3/4✓ Branch 11 → 12 taken 4889 times.
✗ Branch 11 → 16 not taken.
✓ Branch 12 → 13 taken 285 times.
✓ Branch 12 → 16 taken 4604 times.
|
4889 | if (node->compileElseBranch && node->elseStmt) |
| 497 |
1/2✓ Branch 13 → 14 taken 285 times.
✗ Branch 13 → 25 not taken.
|
285 | visit(node->elseStmt); |
| 498 | |||
| 499 |
1/2✓ Branch 16 → 17 taken 4889 times.
✗ Branch 16 → 26 not taken.
|
9778 | return nullptr; |
| 500 | } | ||
| 501 | |||
| 502 | 285 | std::any SymbolTableBuilder::visitElseStmt(ElseStmtNode *node) { | |
| 503 | // Visit if statement in the case of an else if branch | ||
| 504 |
2/2✓ Branch 2 → 3 taken 100 times.
✓ Branch 2 → 8 taken 185 times.
|
285 | if (node->isElseIf) { |
| 505 |
1/2✓ Branch 3 → 4 taken 100 times.
✗ Branch 3 → 17 not taken.
|
100 | visit(node->ifStmt); |
| 506 |
1/2✓ Branch 5 → 6 taken 100 times.
✗ Branch 5 → 18 not taken.
|
200 | return nullptr; |
| 507 | } | ||
| 508 | |||
| 509 | // Create scope for the else body | ||
| 510 | 185 | node->elseBodyScope = currentScope = | |
| 511 |
2/4✓ Branch 8 → 9 taken 185 times.
✗ Branch 8 → 21 not taken.
✓ Branch 9 → 10 taken 185 times.
✗ Branch 9 → 19 not taken.
|
185 | currentScope->createChildScope(node->getScopeId(), ScopeType::IF_ELSE_BODY, &node->body->codeLoc); |
| 512 | |||
| 513 | // Visit else body | ||
| 514 |
1/2✓ Branch 11 → 12 taken 185 times.
✗ Branch 11 → 22 not taken.
|
185 | visit(node->body); |
| 515 | |||
| 516 | // Leave else body scope | ||
| 517 | 185 | currentScope = node->elseBodyScope->parent; | |
| 518 | |||
| 519 |
1/2✓ Branch 13 → 14 taken 185 times.
✗ Branch 13 → 23 not taken.
|
370 | return nullptr; |
| 520 | } | ||
| 521 | |||
| 522 | 53 | std::any SymbolTableBuilder::visitCaseBranch(CaseBranchNode *node) { | |
| 523 | // Create scope for the case branch | ||
| 524 |
2/4✓ Branch 2 → 3 taken 53 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 53 times.
✗ Branch 3 → 11 not taken.
|
53 | node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::CASE_BODY, &node->body->codeLoc); |
| 525 | |||
| 526 | // Visit case body | ||
| 527 |
1/2✓ Branch 5 → 6 taken 53 times.
✗ Branch 5 → 14 not taken.
|
53 | visit(node->body); |
| 528 | |||
| 529 | // Leave case body scope | ||
| 530 | 53 | currentScope = node->bodyScope->parent; | |
| 531 | |||
| 532 |
1/2✓ Branch 7 → 8 taken 53 times.
✗ Branch 7 → 15 not taken.
|
106 | return nullptr; |
| 533 | } | ||
| 534 | |||
| 535 | 6 | std::any SymbolTableBuilder::visitDefaultBranch(DefaultBranchNode *node) { | |
| 536 | // Create scope for the default branch | ||
| 537 | 6 | node->bodyScope = currentScope = | |
| 538 |
2/4✓ Branch 2 → 3 taken 6 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 6 times.
✗ Branch 3 → 11 not taken.
|
6 | currentScope->createChildScope(node->getScopeId(), ScopeType::DEFAULT_BODY, &node->body->codeLoc); |
| 539 | |||
| 540 | // Visit default body | ||
| 541 |
1/2✓ Branch 5 → 6 taken 6 times.
✗ Branch 5 → 14 not taken.
|
6 | visit(node->body); |
| 542 | |||
| 543 | // Leave default body scope | ||
| 544 | 6 | currentScope = node->bodyScope->parent; | |
| 545 | |||
| 546 |
1/2✓ Branch 7 → 8 taken 6 times.
✗ Branch 7 → 15 not taken.
|
12 | return nullptr; |
| 547 | } | ||
| 548 | |||
| 549 | 34 | std::any SymbolTableBuilder::visitAnonymousBlockStmt(AnonymousBlockStmtNode *node) { | |
| 550 | // Create scope for the anonymous block body | ||
| 551 | 34 | node->bodyScope = currentScope = | |
| 552 |
2/4✓ Branch 2 → 3 taken 34 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 34 times.
✗ Branch 3 → 11 not taken.
|
34 | currentScope->createChildScope(node->getScopeId(), ScopeType::ANONYMOUS_BLOCK_BODY, &node->body->codeLoc); |
| 553 | |||
| 554 | // Visit body | ||
| 555 |
1/2✓ Branch 5 → 6 taken 34 times.
✗ Branch 5 → 14 not taken.
|
34 | visit(node->body); |
| 556 | |||
| 557 | // Leave anonymous block body scope | ||
| 558 | 34 | currentScope = node->bodyScope->parent; | |
| 559 | |||
| 560 |
1/2✓ Branch 7 → 8 taken 34 times.
✗ Branch 7 → 15 not taken.
|
68 | return nullptr; |
| 561 | } | ||
| 562 | |||
| 563 | 1185 | std::any SymbolTableBuilder::visitEnumItem(EnumItemNode *node) { | |
| 564 | // Check if enum item already exists in the same scope. | ||
| 565 |
3/4✓ Branch 2 → 3 taken 1185 times.
✗ Branch 2 → 42 not taken.
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 1184 times.
|
2370 | if (currentScope->lookupStrict(node->itemName)) |
| 566 |
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"); |
| 567 | |||
| 568 | // Add enum item entry to symbol table | ||
| 569 |
1/2✓ Branch 13 → 14 taken 1184 times.
✗ Branch 13 → 42 not taken.
|
1184 | SymbolTableEntry *enumItemEntry = currentScope->insert(node->itemName, node); |
| 570 | |||
| 571 | // Add external registry entry | ||
| 572 |
1/2✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 1184 times.
|
1184 | assert(node->enumDef != nullptr); |
| 573 |
2/4✓ Branch 18 → 19 taken 1184 times.
✗ Branch 18 → 38 not taken.
✓ Branch 19 → 20 taken 1184 times.
✗ Branch 19 → 36 not taken.
|
1184 | const std::string name = node->enumDef->enumName + SCOPE_ACCESS_TOKEN + node->itemName; |
| 574 |
1/2✓ Branch 21 → 22 taken 1184 times.
✗ Branch 21 → 40 not taken.
|
1184 | sourceFile->addNameRegistryEntry(name, TY_INT, enumItemEntry, currentScope, true); |
| 575 | |||
| 576 |
1/2✓ Branch 22 → 23 taken 1184 times.
✗ Branch 22 → 39 not taken.
|
2368 | return nullptr; |
| 577 | 1184 | } | |
| 578 | |||
| 579 | 1747 | std::any SymbolTableBuilder::visitField(FieldNode *node) { | |
| 580 | // Check if field already exists in the same scope. | ||
| 581 |
2/2✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 1746 times.
|
3494 | if (currentScope->lookupStrict(node->fieldName)) |
| 582 |
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"); |
| 583 | |||
| 584 | // Add field entry to symbol table | ||
| 585 | 1746 | currentScope->insert(node->fieldName, node); | |
| 586 | |||
| 587 |
1/2✓ Branch 16 → 17 taken 1746 times.
✗ Branch 16 → 29 not taken.
|
3492 | return nullptr; |
| 588 | } | ||
| 589 | |||
| 590 | 253 | std::any SymbolTableBuilder::visitSignature(SignatureNode *node) { | |
| 591 | // Build signature qualifiers | ||
| 592 |
2/2✓ Branch 2 → 3 taken 15 times.
✓ Branch 2 → 32 taken 238 times.
|
253 | if (const QualifierLstNode *qualifierLst = node->qualifierLst) { |
| 593 |
2/2✓ Branch 30 → 5 taken 15 times.
✓ Branch 30 → 31 taken 15 times.
|
45 | for (const QualifierNode *qualifier : qualifierLst->qualifiers) { |
| 594 |
1/2✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 15 times.
|
15 | if (qualifier->type == QualifierNode::QualifierType::TY_INLINE) |
| 595 | ✗ | node->signatureQualifiers.isInline = true; | |
| 596 |
1/2✓ Branch 9 → 10 taken 15 times.
✗ Branch 9 → 11 not taken.
|
15 | else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC) |
| 597 | 15 | node->signatureQualifiers.isPublic = true; | |
| 598 | ✗ | else if (qualifier->type == QualifierNode::QualifierType::TY_CONST) | |
| 599 | ✗ | node->signatureQualifiers.isConst = true; | |
| 600 | else | ||
| 601 | ✗ | throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on a signature definition"); | |
| 602 | } | ||
| 603 | } | ||
| 604 | |||
| 605 | // Add signature entry to symbol table | ||
| 606 | 253 | node->entry = currentScope->insert(node->methodName, node); | |
| 607 | |||
| 608 |
1/2✓ Branch 35 → 36 taken 253 times.
✗ Branch 35 → 49 not taken.
|
506 | return nullptr; |
| 609 | } | ||
| 610 | |||
| 611 | 24159 | std::any SymbolTableBuilder::visitDeclStmt(DeclStmtNode *node) { | |
| 612 | // Check if variable already exists in the same scope. | ||
| 613 |
2/2✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 24158 times.
|
48318 | if (currentScope->lookupStrict(node->varName)) |
| 614 |
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"); |
| 615 | |||
| 616 | // Visit the right side | ||
| 617 |
2/2✓ Branch 13 → 14 taken 8611 times.
✓ Branch 13 → 17 taken 15547 times.
|
24158 | if (node->hasAssignment) |
| 618 |
1/2✓ Branch 14 → 15 taken 8611 times.
✗ Branch 14 → 33 not taken.
|
8611 | visit(node->assignExpr); |
| 619 | |||
| 620 | // Add variable entry to symbol table | ||
| 621 | 24158 | SymbolTableEntry *varEntry = currentScope->insert(node->varName, node); | |
| 622 | 24158 | varEntry->isParam = node->isFctParam; | |
| 623 | |||
| 624 |
1/2✓ Branch 20 → 21 taken 24158 times.
✗ Branch 20 → 34 not taken.
|
48316 | return nullptr; |
| 625 | } | ||
| 626 | |||
| 627 | 416 | std::any SymbolTableBuilder::visitModAttr(ModAttrNode *node) { | |
| 628 | // Visit attributes | ||
| 629 |
2/2✓ Branch 2 → 3 taken 415 times.
✓ Branch 2 → 122 taken 1 time.
|
416 | visitChildren(node); |
| 630 | |||
| 631 | // Retrieve attributes | ||
| 632 | 415 | const AttrLstNode *attrs = node->attrLst; | |
| 633 | |||
| 634 | // Collect linker flags | ||
| 635 | 415 | std::vector<const CompileTimeValue *> linkerFlagValues; | |
| 636 | // core.linker.flag | ||
| 637 |
2/4✓ Branch 6 → 7 taken 415 times.
✗ Branch 6 → 125 not taken.
✓ Branch 7 → 8 taken 415 times.
✗ Branch 7 → 123 not taken.
|
830 | std::vector<const CompileTimeValue *> values = attrs->getAttrValuesByName(ATTR_CORE_LINKER_FLAG); |
| 638 |
1/2✓ Branch 16 → 17 taken 415 times.
✗ Branch 16 → 129 not taken.
|
830 | linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end()); |
| 639 | // core.linux.linker.flag | ||
| 640 | 415 | const llvm::Triple &targetTriple = sourceFile->targetMachine->getTargetTriple(); | |
| 641 |
2/2✓ Branch 20 → 21 taken 405 times.
✓ Branch 20 → 37 taken 10 times.
|
415 | if (targetTriple.isOSLinux()) { |
| 642 |
2/4✓ Branch 23 → 24 taken 405 times.
✗ Branch 23 → 133 not taken.
✓ Branch 24 → 25 taken 405 times.
✗ Branch 24 → 131 not taken.
|
810 | values = attrs->getAttrValuesByName(ATTR_CORE_LINUX_LINKER_FLAG); |
| 643 |
1/2✓ Branch 35 → 36 taken 405 times.
✗ Branch 35 → 138 not taken.
|
810 | linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end()); |
| 644 | } | ||
| 645 | // core.darwin.linker.flag | ||
| 646 |
3/4✓ Branch 37 → 38 taken 415 times.
✗ Branch 37 → 180 not taken.
✓ Branch 38 → 39 taken 5 times.
✓ Branch 38 → 55 taken 410 times.
|
415 | if (targetTriple.isOSDarwin()) { |
| 647 |
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); |
| 648 |
1/2✓ Branch 53 → 54 taken 5 times.
✗ Branch 53 → 147 not taken.
|
10 | linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end()); |
| 649 | } | ||
| 650 | // core.windows.linker.flag | ||
| 651 |
2/2✓ Branch 56 → 57 taken 5 times.
✓ Branch 56 → 73 taken 410 times.
|
415 | if (targetTriple.isOSWindows()) { |
| 652 |
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); |
| 653 |
1/2✓ Branch 71 → 72 taken 5 times.
✗ Branch 71 → 156 not taken.
|
10 | linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end()); |
| 654 | } | ||
| 655 |
2/2✓ Branch 88 → 75 taken 261 times.
✓ Branch 88 → 89 taken 415 times.
|
1091 | for (const CompileTimeValue *value : linkerFlagValues) |
| 656 |
2/4✓ Branch 77 → 78 taken 261 times.
✗ Branch 77 → 158 not taken.
✓ Branch 78 → 79 taken 261 times.
✗ Branch 78 → 158 not taken.
|
261 | resourceManager.linker.addLinkerFlag(resourceManager.compileTimeStringValues.at(value->stringValueOffset)); |
| 657 | |||
| 658 | // core.linker.additionalSource | ||
| 659 |
4/6✓ Branch 89 → 90 taken 415 times.
✗ Branch 89 → 161 not taken.
✓ Branch 90 → 91 taken 415 times.
✗ Branch 90 → 159 not taken.
✓ Branch 112 → 93 taken 3 times.
✓ Branch 112 → 113 taken 414 times.
|
832 | for (const CompileTimeValue *value : attrs->getAttrValuesByName(ATTR_CORE_LINKER_ADDITIONAL_SOURCE)) { |
| 660 |
1/2✓ Branch 95 → 96 taken 3 times.
✗ Branch 95 → 172 not taken.
|
3 | const std::string &stringValue = resourceManager.compileTimeStringValues.at(value->stringValueOffset); |
| 661 |
5/8✓ Branch 96 → 97 taken 3 times.
✗ Branch 96 → 170 not taken.
✓ Branch 97 → 98 taken 3 times.
✗ Branch 97 → 167 not taken.
✓ Branch 98 → 99 taken 3 times.
✗ Branch 98 → 165 not taken.
✓ Branch 99 → 100 taken 2 times.
✓ Branch 99 → 163 taken 1 time.
|
6 | resourceManager.linker.addAdditionalSourcePath(sourceFile->filePath.parent_path() / stringValue); |
| 662 | 416 | } | |
| 663 | |||
| 664 |
1/2✓ Branch 116 → 117 taken 414 times.
✗ Branch 116 → 179 not taken.
|
828 | return nullptr; |
| 665 | 416 | } | |
| 666 | |||
| 667 | 1303 | std::any SymbolTableBuilder::visitAttr(AttrNode *node) { | |
| 668 | // Check if this attribute exists | ||
| 669 |
1/2✓ Branch 2 → 3 taken 1303 times.
✗ Branch 2 → 63 not taken.
|
1303 | const auto it = ATTR_CONFIGS.find(node->key); |
| 670 |
2/2✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 1302 times.
|
1303 | if (it == ATTR_CONFIGS.end()) |
| 671 |
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 + "'"); |
| 672 | |||
| 673 | // Check if the target is correct | ||
| 674 | 1302 | const auto &[target, type] = it->second; | |
| 675 |
2/2✓ Branch 14 → 15 taken 1 time.
✓ Branch 14 → 22 taken 1301 times.
|
1302 | if ((node->target & target) == 0) |
| 676 |
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"); |
| 677 | |||
| 678 | // Check if a value is present | ||
| 679 |
4/4✓ Branch 22 → 23 taken 380 times.
✓ Branch 22 → 31 taken 921 times.
✓ Branch 23 → 24 taken 1 time.
✓ Branch 23 → 31 taken 379 times.
|
1301 | if (!node->value && type != AttrNode::AttrType::TYPE_BOOL) |
| 680 |
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"); |
| 681 | |||
| 682 |
1/2✓ Branch 31 → 32 taken 1300 times.
✗ Branch 31 → 62 not taken.
|
2600 | return nullptr; |
| 683 | } | ||
| 684 | |||
| 685 | 16 | std::any SymbolTableBuilder::visitLambdaFunc(LambdaFuncNode *node) { | |
| 686 | // Create scope for the lambda body | ||
| 687 | 16 | const CodeLoc &codeLoc = node->body->codeLoc; | |
| 688 |
2/4✓ Branch 2 → 3 taken 16 times.
✗ Branch 2 → 47 not taken.
✓ Branch 3 → 4 taken 16 times.
✗ Branch 3 → 45 not taken.
|
16 | node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::LAMBDA_BODY, &codeLoc); |
| 689 | // Requires capturing because the LLVM IR will end up in a separate function | ||
| 690 | 16 | currentScope->symbolTable.setCapturingRequired(); | |
| 691 | // Set to async scope if this is an async lambda | ||
| 692 |
4/18✗ Branch 6 → 7 not taken.
✓ Branch 6 → 13 taken 16 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 16 times.
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 19 taken 16 times.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 27 taken 16 times.
✗ Branch 48 → 49 not taken.
✗ Branch 48 → 50 not taken.
✗ Branch 52 → 53 not taken.
✗ Branch 52 → 55 not taken.
|
16 | if (node->lambdaAttr && node->lambdaAttr->attrLst->hasAttr(ATTR_ASYNC)) |
| 693 | ✗ | node->bodyScope->isAsyncScope = node->lambdaAttr->attrLst->getAttrValueByName(ATTR_ASYNC)->boolValue; | |
| 694 | |||
| 695 | // Create symbol for 'result' variable | ||
| 696 |
1/2✓ Branch 29 → 30 taken 16 times.
✗ Branch 29 → 65 not taken.
|
48 | currentScope->insert(RETURN_VARIABLE_NAME, node); |
| 697 | |||
| 698 | // Create symbols for the parameters | ||
| 699 |
2/2✓ Branch 35 → 36 taken 12 times.
✓ Branch 35 → 39 taken 4 times.
|
16 | if (node->hasParams) |
| 700 |
1/2✓ Branch 36 → 37 taken 12 times.
✗ Branch 36 → 69 not taken.
|
12 | visit(node->paramLst); |
| 701 | |||
| 702 | // Visit body | ||
| 703 |
1/2✓ Branch 39 → 40 taken 16 times.
✗ Branch 39 → 70 not taken.
|
16 | visit(node->body); |
| 704 | |||
| 705 | // Leave anonymous block body scope | ||
| 706 | 16 | currentScope = node->bodyScope->parent; | |
| 707 | |||
| 708 |
1/2✓ Branch 41 → 42 taken 16 times.
✗ Branch 41 → 71 not taken.
|
32 | return nullptr; |
| 709 | } | ||
| 710 | |||
| 711 | 21 | std::any SymbolTableBuilder::visitLambdaProc(LambdaProcNode *node) { | |
| 712 | // Create scope for the lambda body | ||
| 713 | 21 | const CodeLoc &codeLoc = node->body->codeLoc; | |
| 714 |
2/4✓ Branch 2 → 3 taken 21 times.
✗ Branch 2 → 39 not taken.
✓ Branch 3 → 4 taken 21 times.
✗ Branch 3 → 37 not taken.
|
21 | node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::LAMBDA_BODY, &codeLoc); |
| 715 | // Requires capturing because the LLVM IR will end up in a separate function | ||
| 716 | 21 | currentScope->symbolTable.setCapturingRequired(); | |
| 717 | // Set to async scope if this is an async lambda | ||
| 718 |
11/18✓ Branch 6 → 7 taken 6 times.
✓ Branch 6 → 13 taken 15 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 15 times.
✓ Branch 16 → 17 taken 6 times.
✓ Branch 16 → 19 taken 15 times.
✓ Branch 19 → 20 taken 6 times.
✓ Branch 19 → 27 taken 15 times.
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 42 not taken.
✗ Branch 44 → 45 not taken.
✗ Branch 44 → 47 not taken.
|
33 | if (node->lambdaAttr && node->lambdaAttr->attrLst->hasAttr(ATTR_ASYNC)) |
| 719 |
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; |
| 720 | |||
| 721 | // Create symbols for the parameters | ||
| 722 |
2/2✓ Branch 27 → 28 taken 11 times.
✓ Branch 27 → 31 taken 10 times.
|
21 | if (node->hasParams) |
| 723 |
1/2✓ Branch 28 → 29 taken 11 times.
✗ Branch 28 → 55 not taken.
|
11 | visit(node->paramLst); |
| 724 | |||
| 725 | // Visit body | ||
| 726 |
1/2✓ Branch 31 → 32 taken 21 times.
✗ Branch 31 → 56 not taken.
|
21 | visit(node->body); |
| 727 | |||
| 728 | // Leave anonymous block body scope | ||
| 729 | 21 | currentScope = node->bodyScope->parent; | |
| 730 | |||
| 731 |
1/2✓ Branch 33 → 34 taken 21 times.
✗ Branch 33 → 57 not taken.
|
42 | return nullptr; |
| 732 | } | ||
| 733 | |||
| 734 | 1 | std::any SymbolTableBuilder::visitLambdaExpr(LambdaExprNode *node) { | |
| 735 | // Create scope for the anonymous block body | ||
| 736 | 1 | const CodeLoc &codeLoc = node->lambdaExpr->codeLoc; | |
| 737 |
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); |
| 738 | // Requires capturing because the LLVM IR will end up in a separate function | ||
| 739 | 1 | currentScope->symbolTable.setCapturingRequired(); | |
| 740 | |||
| 741 | // Create symbols for the parameters | ||
| 742 |
1/2✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 10 not taken.
|
1 | if (node->hasParams) |
| 743 |
1/2✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 19 not taken.
|
1 | visit(node->paramLst); |
| 744 | |||
| 745 | // Visit lambda expression | ||
| 746 |
1/2✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 20 not taken.
|
1 | visit(node->lambdaExpr); |
| 747 | |||
| 748 | // Leave anonymous block body scope | ||
| 749 | 1 | currentScope = node->bodyScope->parent; | |
| 750 | |||
| 751 |
1/2✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 21 not taken.
|
2 | return nullptr; |
| 752 | } | ||
| 753 | |||
| 754 | } // namespace spice::compiler | ||
| 755 |