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