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