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