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