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 | 10328 | SymbolTableBuilder::SymbolTableBuilder(GlobalResourceManager &resourceManager, SourceFile *sourceFile) | |
| 17 | 10328 | : CompilerPass(resourceManager, sourceFile), rootScope(sourceFile->globalScope.get()) {} | |
| 18 | |||
| 19 | 10328 | std::any SymbolTableBuilder::visitEntry(EntryNode *node) { | |
| 20 | // Initialize | ||
| 21 | 10328 | currentScope = rootScope; | |
| 22 | |||
| 23 | // Visit children | ||
| 24 |
2/2✓ Branch 2 → 3 taken 10290 times.
✓ Branch 2 → 23 taken 38 times.
|
10328 | visitChildren(node); |
| 25 | |||
| 26 | // Check if the main function exists | ||
| 27 |
4/4✓ Branch 4 → 5 taken 10284 times.
✓ Branch 4 → 7 taken 6 times.
✓ Branch 5 → 6 taken 10272 times.
✓ Branch 5 → 7 taken 12 times.
|
10290 | const bool mainFctRequired = cliOptions.outputContainer == OutputContainer::EXECUTABLE && !cliOptions.noEntryFct; |
| 28 |
6/6✓ Branch 8 → 9 taken 1305 times.
✓ Branch 8 → 19 taken 8985 times.
✓ Branch 9 → 10 taken 1289 times.
✓ Branch 9 → 19 taken 16 times.
✓ Branch 10 → 11 taken 4 times.
✓ Branch 10 → 19 taken 1285 times.
|
10290 | if (sourceFile->isMainFile && mainFctRequired && !hasMainFunction) |
| 29 |
2/4✓ Branch 14 → 15 taken 4 times.
✗ Branch 14 → 27 not taken.
✓ Branch 15 → 16 taken 4 times.
✗ Branch 15 → 24 not taken.
|
12 | throw SemanticError(node, MISSING_MAIN_FUNCTION, "No main function found", false); |
| 30 | |||
| 31 |
1/2✓ Branch 19 → 20 taken 10286 times.
✗ Branch 19 → 33 not taken.
|
20572 | return nullptr; |
| 32 | } | ||
| 33 | |||
| 34 | 1297 | std::any SymbolTableBuilder::visitMainFctDef(MainFctDefNode *node) { | |
| 35 | // Visit attributes | ||
| 36 |
2/2✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 6 taken 1295 times.
|
1297 | if (node->attrs) |
| 37 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 52 taken 2 times.
|
2 | visit(node->attrs); |
| 38 | |||
| 39 | // Check if the function is already defined | ||
| 40 |
3/4✓ Branch 8 → 9 taken 1295 times.
✗ Branch 8 → 55 not taken.
✓ Branch 14 → 15 taken 2 times.
✓ Branch 14 → 23 taken 1293 times.
|
5180 | if (rootScope->lookupStrict(MAIN_FUNCTION_NAME)) |
| 41 |
2/4✓ Branch 18 → 19 taken 2 times.
✗ Branch 18 → 62 not taken.
✓ Branch 19 → 20 taken 2 times.
✗ Branch 19 → 59 not taken.
|
6 | 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 1293 times.
✗ Branch 25 → 70 not taken.
|
3879 | SymbolTableEntry *mainFctEntry = currentScope->insert(MAIN_FUNCTION_NAME, node); |
| 45 | 1293 | mainFctEntry->used = true; | |
| 46 | |||
| 47 | // Create scope for main function body | ||
| 48 |
1/2✓ Branch 31 → 32 taken 1293 times.
✗ Branch 31 → 85 not taken.
|
1293 | const std::string &scopeId = MainFctDefNode::getScopeId(); |
| 49 |
1/2✓ Branch 32 → 33 taken 1293 times.
✗ Branch 32 → 83 not taken.
|
1293 | node->bodyScope = currentScope = rootScope->createChildScope(scopeId, ScopeType::FUNC_PROC_BODY, &node->codeLoc); |
| 50 | 1293 | currentScope->isGenericScope = false; | |
| 51 | |||
| 52 | // Declare variable for the return value in the function scope | ||
| 53 |
1/2✓ Branch 35 → 36 taken 1293 times.
✗ Branch 35 → 76 not taken.
|
3879 | SymbolTableEntry *resultVarEntry = node->bodyScope->insert(RETURN_VARIABLE_NAME, node); |
| 54 | 1293 | resultVarEntry->used = true; | |
| 55 | |||
| 56 | // Visit arguments in new scope | ||
| 57 |
2/2✓ Branch 41 → 42 taken 14 times.
✓ Branch 41 → 45 taken 1279 times.
|
1293 | if (node->takesArgs) |
| 58 |
1/2✓ Branch 42 → 43 taken 14 times.
✗ Branch 42 → 80 not taken.
|
14 | visit(node->paramLst); |
| 59 | |||
| 60 | // Visit function body in new scope | ||
| 61 |
2/2✓ Branch 45 → 46 taken 1291 times.
✓ Branch 45 → 81 taken 2 times.
|
1293 | visit(node->body); |
| 62 | |||
| 63 | // Return to root scope | ||
| 64 | 1291 | currentScope = rootScope; | |
| 65 | |||
| 66 | 1291 | hasMainFunction = true; | |
| 67 |
1/2✓ Branch 47 → 48 taken 1291 times.
✗ Branch 47 → 82 not taken.
|
2582 | return nullptr; |
| 68 | 1293 | } | |
| 69 | |||
| 70 | 114490 | std::any SymbolTableBuilder::visitFctDef(FctDefNode *node) { | |
| 71 | // Visit attributes | ||
| 72 |
2/2✓ Branch 2 → 3 taken 3508 times.
✓ Branch 2 → 6 taken 110982 times.
|
114490 | if (node->attrs) |
| 73 |
1/2✓ Branch 3 → 4 taken 3508 times.
✗ Branch 3 → 98 not taken.
|
3508 | visit(node->attrs); |
| 74 | |||
| 75 | // Build function qualifiers | ||
| 76 |
2/2✓ Branch 6 → 7 taken 103402 times.
✓ Branch 6 → 36 taken 11088 times.
|
114490 | if (const QualifierLstNode *qualifierLst = node->qualifierLst; qualifierLst) { |
| 77 |
2/2✓ Branch 34 → 9 taken 125555 times.
✓ Branch 34 → 35 taken 103402 times.
|
332359 | for (const QualifierNode *qualifier : qualifierLst->qualifiers) { |
| 78 |
2/2✓ Branch 11 → 12 taken 22012 times.
✓ Branch 11 → 13 taken 103543 times.
|
125555 | if (qualifier->type == QualifierNode::QualifierType::TY_INLINE) |
| 79 | 22012 | node->qualifiers.isInline = true; | |
| 80 |
2/2✓ Branch 13 → 14 taken 102371 times.
✓ Branch 13 → 15 taken 1172 times.
|
103543 | else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC) |
| 81 | 102371 | node->qualifiers.isPublic = true; | |
| 82 |
1/2✓ Branch 15 → 16 taken 1172 times.
✗ Branch 15 → 17 not taken.
|
1172 | else if (qualifier->type == QualifierNode::QualifierType::TY_CONST) |
| 83 | 1172 | 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 75091 times.
✓ Branch 36 → 51 taken 39399 times.
|
114490 | if (node->isMethod) { |
| 91 |
1/2✓ Branch 38 → 39 taken 75091 times.
✗ Branch 38 → 109 not taken.
|
75091 | const std::string scopeName = Struct::getScopeName(node->name->structName); |
| 92 |
1/2✓ Branch 40 → 41 taken 75091 times.
✗ Branch 40 → 121 not taken.
|
75091 | node->structScope = currentScope = currentScope->getChildScope(scopeName); |
| 93 |
1/2✗ Branch 41 → 42 not taken.
✓ Branch 41 → 49 taken 75091 times.
|
75091 | if (!currentScope) |
| 94 | ✗ | throw SemanticError(node, REFERENCED_UNDEFINED_STRUCT, "Struct '" + node->name->structName + "' could not be found"); | |
| 95 | 75091 | } | |
| 96 | |||
| 97 | // Create scope for the function | ||
| 98 |
2/4✓ Branch 51 → 52 taken 114490 times.
✗ Branch 51 → 126 not taken.
✓ Branch 52 → 53 taken 114490 times.
✗ Branch 52 → 124 not taken.
|
114490 | node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc); |
| 99 |
6/6✓ Branch 54 → 55 taken 106241 times.
✓ Branch 54 → 57 taken 8249 times.
✓ Branch 55 → 56 taken 73380 times.
✓ Branch 55 → 58 taken 32861 times.
✓ Branch 56 → 57 taken 11497 times.
✓ Branch 56 → 58 taken 61883 times.
|
114490 | currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope); |
| 100 | |||
| 101 | // Create symbol for 'this' variable | ||
| 102 |
2/2✓ Branch 59 → 60 taken 75091 times.
✓ Branch 59 → 69 taken 39399 times.
|
114490 | if (node->isMethod) |
| 103 |
1/2✓ Branch 62 → 63 taken 75091 times.
✗ Branch 62 → 129 not taken.
|
300364 | currentScope->insert(THIS_VARIABLE_NAME, node); |
| 104 | |||
| 105 | // Create symbol for 'result' variable | ||
| 106 |
1/2✓ Branch 71 → 72 taken 114490 times.
✗ Branch 71 → 135 not taken.
|
343470 | currentScope->insert(RETURN_VARIABLE_NAME, node); |
| 107 | |||
| 108 | // Create symbols for the parameters | ||
| 109 |
2/2✓ Branch 77 → 78 taken 74148 times.
✓ Branch 77 → 81 taken 40342 times.
|
114490 | if (node->hasParams) |
| 110 |
1/2✓ Branch 78 → 79 taken 74148 times.
✗ Branch 78 → 139 not taken.
|
74148 | visit(node->paramLst); |
| 111 | |||
| 112 | // Visit the function body | ||
| 113 |
1/2✓ Branch 81 → 82 taken 114490 times.
✗ Branch 81 → 140 not taken.
|
114490 | visit(node->body); |
| 114 | |||
| 115 | // Leave function body scope | ||
| 116 | 114490 | currentScope = node->scope->parent; | |
| 117 | |||
| 118 | // Insert symbol for function into the symbol table | ||
| 119 |
1/2✓ Branch 83 → 84 taken 114490 times.
✗ Branch 83 → 143 not taken.
|
228980 | 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 | 114490 | const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName); | |
| 124 |
3/4✓ Branch 89 → 90 taken 13654 times.
✓ Branch 89 → 91 taken 100836 times.
✓ Branch 90 → 91 taken 13654 times.
✗ Branch 90 → 92 not taken.
|
114490 | if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry) |
| 125 | 114490 | sourceFile->addNameRegistryEntry(node->name->fqName, TY_FUNCTION, node->entry, currentScope, true); | |
| 126 | |||
| 127 | // Leave the struct scope | ||
| 128 |
2/2✓ Branch 92 → 93 taken 75091 times.
✓ Branch 92 → 94 taken 39399 times.
|
114490 | if (node->isMethod) |
| 129 | 75091 | currentScope = node->structScope->parent; | |
| 130 | |||
| 131 |
1/2✓ Branch 94 → 95 taken 114490 times.
✗ Branch 94 → 144 not taken.
|
228980 | return nullptr; |
| 132 | } | ||
| 133 | |||
| 134 | 52631 | std::any SymbolTableBuilder::visitProcDef(ProcDefNode *node) { | |
| 135 | // Visit attributes | ||
| 136 |
2/2✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 6 taken 52629 times.
|
52631 | if (node->attrs) |
| 137 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 97 taken 2 times.
|
2 | visit(node->attrs); |
| 138 | |||
| 139 | // Build procedure qualifiers | ||
| 140 |
2/2✓ Branch 6 → 7 taken 44343 times.
✓ Branch 6 → 36 taken 8286 times.
|
52629 | if (const QualifierLstNode *qualifierLst = node->qualifierLst) { |
| 141 |
2/2✓ Branch 34 → 9 taken 50350 times.
✓ Branch 34 → 35 taken 44343 times.
|
139036 | for (const QualifierNode *qualifier : qualifierLst->qualifiers) { |
| 142 |
2/2✓ Branch 11 → 12 taken 6017 times.
✓ Branch 11 → 13 taken 44333 times.
|
50350 | if (qualifier->type == QualifierNode::QualifierType::TY_INLINE) |
| 143 | 6017 | node->qualifiers.isInline = true; | |
| 144 |
2/2✓ Branch 13 → 14 taken 44275 times.
✓ Branch 13 → 15 taken 58 times.
|
44333 | else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC) |
| 145 | 44275 | node->qualifiers.isPublic = true; | |
| 146 |
1/2✓ Branch 15 → 16 taken 58 times.
✗ Branch 15 → 17 not taken.
|
58 | else if (qualifier->type == QualifierNode::QualifierType::TY_CONST) |
| 147 | 58 | 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 43867 times.
✓ Branch 36 → 51 taken 8762 times.
|
52629 | if (node->isMethod) { |
| 155 |
1/2✓ Branch 38 → 39 taken 43867 times.
✗ Branch 38 → 108 not taken.
|
43867 | const std::string &scopeName = Struct::getScopeName(node->name->structName); |
| 156 |
1/2✓ Branch 40 → 41 taken 43867 times.
✗ Branch 40 → 120 not taken.
|
43867 | node->structScope = currentScope = currentScope->getChildScope(scopeName); |
| 157 |
2/2✓ Branch 41 → 42 taken 2 times.
✓ Branch 41 → 49 taken 43865 times.
|
43867 | if (!currentScope) |
| 158 |
3/6✓ Branch 43 → 44 taken 2 times.
✗ Branch 43 → 116 not taken.
✓ Branch 44 → 45 taken 2 times.
✗ Branch 44 → 114 not taken.
✓ Branch 45 → 46 taken 2 times.
✗ Branch 45 → 111 not taken.
|
2 | throw SemanticError(node, REFERENCED_UNDEFINED_STRUCT, "Struct '" + node->name->structName + "' could not be found"); |
| 159 | 43867 | } | |
| 160 | |||
| 161 | // Create scope for the procedure | ||
| 162 |
2/4✓ Branch 51 → 52 taken 52627 times.
✗ Branch 51 → 125 not taken.
✓ Branch 52 → 53 taken 52627 times.
✗ Branch 52 → 123 not taken.
|
52627 | node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc); |
| 163 |
6/6✓ Branch 54 → 55 taken 45769 times.
✓ Branch 54 → 57 taken 6858 times.
✓ Branch 55 → 56 taken 40582 times.
✓ Branch 55 → 58 taken 5187 times.
✓ Branch 56 → 57 taken 11160 times.
✓ Branch 56 → 58 taken 29422 times.
|
52627 | currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope); |
| 164 |
4/4✓ Branch 59 → 60 taken 43865 times.
✓ Branch 59 → 63 taken 8762 times.
✓ Branch 61 → 62 taken 1753 times.
✓ Branch 61 → 63 taken 42112 times.
|
52627 | currentScope->isDtorScope = node->isMethod && node->name->name == DTOR_FUNCTION_NAME; |
| 165 | |||
| 166 | // Create symbol for 'this' variable | ||
| 167 |
2/2✓ Branch 64 → 65 taken 43865 times.
✓ Branch 64 → 74 taken 8762 times.
|
52627 | if (node->isMethod) |
| 168 |
1/2✓ Branch 67 → 68 taken 43865 times.
✗ Branch 67 → 128 not taken.
|
175460 | currentScope->insert(THIS_VARIABLE_NAME, node); |
| 169 | |||
| 170 | // Create symbols for the parameters | ||
| 171 |
2/2✓ Branch 74 → 75 taken 38401 times.
✓ Branch 74 → 78 taken 14226 times.
|
52627 | if (node->hasParams) |
| 172 |
1/2✓ Branch 75 → 76 taken 38401 times.
✗ Branch 75 → 132 not taken.
|
38401 | visit(node->paramLst); |
| 173 | |||
| 174 | // Visit the procedure body | ||
| 175 |
1/2✓ Branch 78 → 79 taken 52627 times.
✗ Branch 78 → 133 not taken.
|
52627 | visit(node->body); |
| 176 | |||
| 177 | // Leave procedure body scope | ||
| 178 | 52627 | currentScope = node->scope->parent; | |
| 179 | |||
| 180 | // Insert symbol for procedure into the symbol table | ||
| 181 |
1/2✓ Branch 80 → 81 taken 52627 times.
✗ Branch 80 → 136 not taken.
|
105254 | 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 | 52627 | const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName); | |
| 186 |
3/4✓ Branch 86 → 87 taken 9658 times.
✓ Branch 86 → 88 taken 42969 times.
✓ Branch 87 → 88 taken 9658 times.
✗ Branch 87 → 89 not taken.
|
52627 | if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry) |
| 187 | 52627 | sourceFile->addNameRegistryEntry(node->name->fqName, TY_PROCEDURE, node->entry, currentScope, true); | |
| 188 | |||
| 189 | // Leave the struct scope | ||
| 190 |
2/2✓ Branch 89 → 90 taken 43865 times.
✓ Branch 89 → 91 taken 8762 times.
|
52627 | if (node->isMethod) |
| 191 | 43865 | currentScope = node->structScope->parent; | |
| 192 | |||
| 193 | // Check if this is a constructor | ||
| 194 | 52627 | node->isCtor = node->name->nameFragments.back() == CTOR_FUNCTION_NAME; | |
| 195 | |||
| 196 |
1/2✓ Branch 93 → 94 taken 52627 times.
✗ Branch 93 → 137 not taken.
|
105254 | return nullptr; |
| 197 | } | ||
| 198 | |||
| 199 | 14097 | std::any SymbolTableBuilder::visitStructDef(StructDefNode *node) { | |
| 200 | // Visit attributes | ||
| 201 |
2/2✓ Branch 2 → 3 taken 280 times.
✓ Branch 2 → 6 taken 13817 times.
|
14097 | if (node->attrs) |
| 202 |
1/2✓ Branch 3 → 4 taken 280 times.
✗ Branch 3 → 79 not taken.
|
280 | visit(node->attrs); |
| 203 | |||
| 204 | // Check if this name already exists | ||
| 205 |
3/4✓ Branch 6 → 7 taken 14097 times.
✗ Branch 6 → 110 not taken.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 17 taken 14095 times.
|
28194 | if (rootScope->lookupStrict(node->structName)) |
| 206 |
3/6✓ Branch 11 → 12 taken 2 times.
✗ Branch 11 → 85 not taken.
✓ Branch 12 → 13 taken 2 times.
✗ Branch 12 → 83 not taken.
✓ Branch 13 → 14 taken 2 times.
✗ Branch 13 → 80 not taken.
|
2 | throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->structName + "'"); |
| 207 | |||
| 208 | // Create scope for the struct | ||
| 209 |
1/2✓ Branch 18 → 19 taken 14095 times.
✗ Branch 18 → 89 not taken.
|
14095 | const std::string &scopeName = Struct::getScopeName(node->structName); |
| 210 |
1/2✓ Branch 20 → 21 taken 14095 times.
✗ Branch 20 → 108 not taken.
|
14095 | node->structScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::STRUCT, &node->codeLoc); |
| 211 | 14095 | currentScope->isGenericScope = node->hasTemplateTypes; | |
| 212 | |||
| 213 | // Insert implicit field for each interface type | ||
| 214 |
2/2✓ Branch 21 → 22 taken 5134 times.
✓ Branch 21 → 43 taken 8961 times.
|
14095 | if (node->hasInterfaces) { |
| 215 |
2/2✓ Branch 41 → 24 taken 5134 times.
✓ Branch 41 → 42 taken 5134 times.
|
15402 | for (DataTypeNode *interfaceNode : node->interfaceTypeLst->dataTypes) { |
| 216 | 5134 | const std::string &interfaceName = interfaceNode->baseDataType->customDataType->typeNameFragments.back(); | |
| 217 |
1/2✓ Branch 27 → 28 taken 5134 times.
✗ Branch 27 → 94 not taken.
|
10268 | SymbolTableEntry *interfaceFieldEntry = currentScope->insert("this." + interfaceName, interfaceNode); |
| 218 | 5134 | interfaceFieldEntry->used = true; | |
| 219 | 5134 | interfaceFieldEntry->isImplicitField = true; | |
| 220 | } | ||
| 221 | } | ||
| 222 | |||
| 223 | // Visit children | ||
| 224 |
2/2✓ Branch 43 → 44 taken 14093 times.
✓ Branch 43 → 96 taken 2 times.
|
14095 | visitChildren(node); |
| 225 | |||
| 226 | // Leave the struct scope | ||
| 227 | 14093 | currentScope = node->structScope->parent; | |
| 228 | |||
| 229 | // Build struct qualifiers | ||
| 230 |
2/2✓ Branch 45 → 46 taken 11939 times.
✓ Branch 45 → 70 taken 2154 times.
|
14093 | if (const QualifierLstNode *qualifierLst = node->qualifierLst) { |
| 231 |
2/2✓ Branch 68 → 48 taken 11939 times.
✓ Branch 68 → 69 taken 11939 times.
|
35817 | for (const QualifierNode *qualifier : qualifierLst->qualifiers) { |
| 232 |
1/2✓ Branch 50 → 51 taken 11939 times.
✗ Branch 50 → 54 not taken.
|
11939 | if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC) |
| 233 | 11939 | 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 14093 times.
✗ Branch 70 → 108 not taken.
|
14093 | node->entry = rootScope->insert(node->structName, node); |
| 241 | // Register the name in the exported name registry | ||
| 242 |
1/2✓ Branch 73 → 74 taken 14093 times.
✗ Branch 73 → 108 not taken.
|
14093 | sourceFile->addNameRegistryEntry(node->structName, node->typeId, node->entry, node->structScope, true); |
| 243 | |||
| 244 |
1/2✓ Branch 74 → 75 taken 14093 times.
✗ Branch 74 → 107 not taken.
|
28186 | return nullptr; |
| 245 | 14095 | } | |
| 246 | |||
| 247 | 761 | std::any SymbolTableBuilder::visitInterfaceDef(InterfaceDefNode *node) { | |
| 248 | // Visit attributes | ||
| 249 |
2/2✓ Branch 2 → 3 taken 436 times.
✓ Branch 2 → 6 taken 325 times.
|
761 | if (node->attrs) |
| 250 |
1/2✓ Branch 3 → 4 taken 436 times.
✗ Branch 3 → 71 not taken.
|
436 | visit(node->attrs); |
| 251 | |||
| 252 | // Check if this name already exists | ||
| 253 |
3/4✓ Branch 6 → 7 taken 761 times.
✗ Branch 6 → 99 not taken.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 17 taken 759 times.
|
1522 | if (rootScope->lookupStrict(node->interfaceName)) |
| 254 |
3/6✓ Branch 11 → 12 taken 2 times.
✗ Branch 11 → 77 not taken.
✓ Branch 12 → 13 taken 2 times.
✗ Branch 12 → 75 not taken.
✓ Branch 13 → 14 taken 2 times.
✗ Branch 13 → 72 not taken.
|
2 | throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->interfaceName + "'"); |
| 255 | |||
| 256 | // Create scope for the interface | ||
| 257 |
1/2✓ Branch 18 → 19 taken 759 times.
✗ Branch 18 → 81 not taken.
|
759 | const std::string &scopeName = Interface::getScopeName(node->interfaceName); |
| 258 |
1/2✓ Branch 20 → 21 taken 759 times.
✗ Branch 20 → 97 not taken.
|
759 | node->interfaceScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::INTERFACE, &node->codeLoc); |
| 259 | |||
| 260 | // Visit signatures | ||
| 261 |
2/2✓ Branch 36 → 23 taken 5177 times.
✓ Branch 36 → 37 taken 759 times.
|
6695 | for (SignatureNode *signature : node->signatures) |
| 262 |
1/2✓ Branch 25 → 26 taken 5177 times.
✗ Branch 25 → 84 not taken.
|
5177 | visit(signature); |
| 263 | |||
| 264 | // Leave the interface scope | ||
| 265 | 759 | currentScope = node->interfaceScope->parent; | |
| 266 | |||
| 267 | // Build interface qualifiers | ||
| 268 |
2/2✓ Branch 37 → 38 taken 719 times.
✓ Branch 37 → 62 taken 40 times.
|
759 | if (const QualifierLstNode *qualifierLst = node->qualifierLst) { |
| 269 |
2/2✓ Branch 60 → 40 taken 719 times.
✓ Branch 60 → 61 taken 719 times.
|
2157 | for (const QualifierNode *qualifier : qualifierLst->qualifiers) { |
| 270 |
1/2✓ Branch 42 → 43 taken 719 times.
✗ Branch 42 → 46 not taken.
|
719 | if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC) |
| 271 | 719 | 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 759 times.
✗ Branch 62 → 97 not taken.
|
759 | node->entry = rootScope->insert(node->interfaceName, node); |
| 279 | // Register the name in the exported name registry | ||
| 280 |
1/2✓ Branch 65 → 66 taken 759 times.
✗ Branch 65 → 97 not taken.
|
759 | sourceFile->addNameRegistryEntry(node->interfaceName, node->typeId, node->entry, node->interfaceScope, true); |
| 281 | |||
| 282 |
1/2✓ Branch 66 → 67 taken 759 times.
✗ Branch 66 → 96 not taken.
|
1518 | return nullptr; |
| 283 | 759 | } | |
| 284 | |||
| 285 | 84 | std::any SymbolTableBuilder::visitUnionDef(UnionDefNode *node) { | |
| 286 | // Visit attributes | ||
| 287 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 6 taken 84 times.
|
84 | if (node->attrs) |
| 288 | ✗ | visit(node->attrs); | |
| 289 | |||
| 290 | // Check if this name already exists | ||
| 291 |
2/4✓ Branch 6 → 7 taken 84 times.
✗ Branch 6 → 84 not taken.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 17 taken 84 times.
|
168 | if (rootScope->lookupStrict(node->unionName)) |
| 292 | ✗ | throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->unionName + "'"); | |
| 293 | |||
| 294 | // Create scope for the union | ||
| 295 |
1/2✓ Branch 18 → 19 taken 84 times.
✗ Branch 18 → 67 not taken.
|
84 | const std::string &scopeName = Union::getScopeName(node->unionName); |
| 296 |
1/2✓ Branch 20 → 21 taken 84 times.
✗ Branch 20 → 82 not taken.
|
84 | node->unionScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::UNION, &node->codeLoc); |
| 297 | 84 | currentScope->isGenericScope = node->hasTemplateTypes; | |
| 298 | |||
| 299 | // Visit children | ||
| 300 |
2/2✓ Branch 21 → 22 taken 82 times.
✓ Branch 21 → 70 taken 2 times.
|
84 | visitChildren(node); |
| 301 | |||
| 302 | // Leave the union scope | ||
| 303 | 82 | currentScope = node->unionScope->parent; | |
| 304 | |||
| 305 | // Build union qualifiers | ||
| 306 |
2/2✓ Branch 23 → 24 taken 48 times.
✓ Branch 23 → 48 taken 34 times.
|
82 | if (const QualifierLstNode *qualifierLst = node->qualifierLst) { |
| 307 |
2/2✓ Branch 46 → 26 taken 48 times.
✓ Branch 46 → 47 taken 46 times.
|
142 | for (const QualifierNode *qualifier : qualifierLst->qualifiers) { |
| 308 |
2/2✓ Branch 28 → 29 taken 46 times.
✓ Branch 28 → 32 taken 2 times.
|
48 | if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC) |
| 309 | 46 | node->qualifiers.isPublic = true; | |
| 310 | else | ||
| 311 |
2/4✓ Branch 35 → 36 taken 2 times.
✗ Branch 35 → 74 not taken.
✓ Branch 36 → 37 taken 2 times.
✗ Branch 36 → 71 not taken.
|
6 | throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on a union definition"); |
| 312 | } | ||
| 313 | } | ||
| 314 | |||
| 315 | // Add the union to the symbol table | ||
| 316 |
1/2✓ Branch 48 → 49 taken 80 times.
✗ Branch 48 → 82 not taken.
|
80 | node->entry = rootScope->insert(node->unionName, node); |
| 317 | // Register the name in the exported name registry | ||
| 318 |
1/2✓ Branch 51 → 52 taken 80 times.
✗ Branch 51 → 82 not taken.
|
80 | sourceFile->addNameRegistryEntry(node->unionName, node->typeId, node->entry, node->unionScope, true); |
| 319 | |||
| 320 |
1/2✓ Branch 52 → 53 taken 80 times.
✗ Branch 52 → 81 not taken.
|
160 | return nullptr; |
| 321 | 84 | } | |
| 322 | |||
| 323 | 4078 | std::any SymbolTableBuilder::visitEnumDef(EnumDefNode *node) { | |
| 324 | // Check if this name already exists | ||
| 325 |
2/2✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 4076 times.
|
8156 | if (rootScope->lookupStrict(node->enumName)) |
| 326 |
3/6✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 56 not taken.
✓ Branch 8 → 9 taken 2 times.
✗ Branch 8 → 54 not taken.
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 51 not taken.
|
2 | throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->enumName + "'"); |
| 327 | |||
| 328 | // Create scope for the enum | ||
| 329 | 4076 | node->enumScope = currentScope = | |
| 330 |
2/4✓ Branch 13 → 14 taken 4076 times.
✗ Branch 13 → 62 not taken.
✓ Branch 14 → 15 taken 4076 times.
✗ Branch 14 → 60 not taken.
|
4076 | rootScope->createChildScope(ENUM_SCOPE_PREFIX + node->enumName, ScopeType::ENUM, &node->codeLoc); |
| 331 | |||
| 332 | // Visit items | ||
| 333 |
2/2✓ Branch 16 → 17 taken 4074 times.
✓ Branch 16 → 63 taken 2 times.
|
4076 | visit(node->itemLst); |
| 334 | |||
| 335 | // Leave the enum scope | ||
| 336 | 4074 | currentScope = node->enumScope->parent; | |
| 337 | |||
| 338 | // Build enum qualifiers | ||
| 339 |
2/2✓ Branch 18 → 19 taken 3741 times.
✓ Branch 18 → 43 taken 333 times.
|
4074 | if (node->qualifierLst) { |
| 340 |
2/2✓ Branch 41 → 21 taken 3741 times.
✓ Branch 41 → 42 taken 3741 times.
|
11223 | for (const QualifierNode *qualifier : node->qualifierLst->qualifiers) { |
| 341 |
1/2✓ Branch 23 → 24 taken 3741 times.
✗ Branch 23 → 27 not taken.
|
3741 | if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC) |
| 342 | 3741 | node->qualifiers.isPublic = true; | |
| 343 | else | ||
| 344 | ✗ | throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on an enum definition"); | |
| 345 | } | ||
| 346 | } | ||
| 347 | |||
| 348 | // Add the enum to the symbol table | ||
| 349 | 4074 | node->entry = rootScope->insert(node->enumName, node); | |
| 350 | // Register the name in the exported name registry | ||
| 351 | 4074 | sourceFile->addNameRegistryEntry(node->enumName, node->typeId, node->entry, node->enumScope, true); | |
| 352 | |||
| 353 |
1/2✓ Branch 47 → 48 taken 4074 times.
✗ Branch 47 → 74 not taken.
|
8148 | return nullptr; |
| 354 | } | ||
| 355 | |||
| 356 | 6919 | std::any SymbolTableBuilder::visitGenericTypeDef(GenericTypeDefNode *node) { | |
| 357 | // Check if this name already exists | ||
| 358 |
2/2✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 6917 times.
|
13838 | if (rootScope->lookupStrict(node->typeName)) |
| 359 |
3/6✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 25 not taken.
✓ Branch 8 → 9 taken 2 times.
✗ Branch 8 → 23 not taken.
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 20 not taken.
|
2 | throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->typeName + "'"); |
| 360 | |||
| 361 | // Create the generic type to the symbol table | ||
| 362 | 6917 | node->entry = rootScope->insert(node->typeName, node); | |
| 363 | 6917 | node->entry->used = true; // Generic types are always used | |
| 364 | |||
| 365 |
1/2✓ Branch 16 → 17 taken 6917 times.
✗ Branch 16 → 29 not taken.
|
13834 | return nullptr; |
| 366 | } | ||
| 367 | |||
| 368 | 2717 | std::any SymbolTableBuilder::visitAliasDef(AliasDefNode *node) { | |
| 369 | // Check if this name already exists | ||
| 370 |
3/4✓ Branch 2 → 3 taken 2717 times.
✗ Branch 2 → 73 not taken.
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 2715 times.
|
5434 | if (rootScope->lookupStrict(node->aliasName)) |
| 371 |
3/6✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 56 not taken.
✓ Branch 8 → 9 taken 2 times.
✗ Branch 8 → 54 not taken.
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 51 not taken.
|
2 | throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->aliasName + "'"); |
| 372 | |||
| 373 | // Build alias qualifiers | ||
| 374 |
2/2✓ Branch 13 → 14 taken 1693 times.
✓ Branch 13 → 38 taken 1022 times.
|
2715 | if (const QualifierLstNode *qualifierLst = node->qualifierLst) { |
| 375 |
2/2✓ Branch 36 → 16 taken 1693 times.
✓ Branch 36 → 37 taken 1693 times.
|
5079 | for (const QualifierNode *qualifier : qualifierLst->qualifiers) { |
| 376 |
1/2✓ Branch 18 → 19 taken 1693 times.
✗ Branch 18 → 22 not taken.
|
1693 | if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC) |
| 377 | 1693 | node->qualifiers.isPublic = true; | |
| 378 | else | ||
| 379 | ✗ | throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on an alias definition"); | |
| 380 | } | ||
| 381 | } | ||
| 382 | |||
| 383 | // Add the alias to the symbol table | ||
| 384 |
1/2✓ Branch 38 → 39 taken 2715 times.
✗ Branch 38 → 73 not taken.
|
2715 | node->entry = rootScope->insert(node->aliasName, node); |
| 385 | // Register the name in the exported name registry | ||
| 386 |
1/2✓ Branch 41 → 42 taken 2715 times.
✗ Branch 41 → 73 not taken.
|
2715 | sourceFile->addNameRegistryEntry(node->aliasName, node->typeId, node->entry, rootScope, true); |
| 387 | |||
| 388 | // Add another symbol for the aliased type container | ||
| 389 |
1/2✓ Branch 42 → 43 taken 2715 times.
✗ Branch 42 → 73 not taken.
|
2715 | const std::string aliasedTypeContainerName = node->aliasName + ALIAS_CONTAINER_SUFFIX; |
| 390 |
1/2✓ Branch 43 → 44 taken 2715 times.
✗ Branch 43 → 71 not taken.
|
2715 | node->aliasedTypeContainerEntry = rootScope->insert(aliasedTypeContainerName, node); |
| 391 | |||
| 392 |
1/2✓ Branch 46 → 47 taken 2715 times.
✗ Branch 46 → 70 not taken.
|
5430 | return nullptr; |
| 393 | 2715 | } | |
| 394 | |||
| 395 | 18689 | std::any SymbolTableBuilder::visitGlobalVarDef(GlobalVarDefNode *node) { | |
| 396 | // Check if this name already exists | ||
| 397 |
2/2✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 18687 times.
|
37378 | if (rootScope->lookupStrict(node->varName)) |
| 398 |
3/6✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 43 not taken.
✓ Branch 8 → 9 taken 2 times.
✗ Branch 8 → 41 not taken.
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 38 not taken.
|
2 | throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->varName + "'"); |
| 399 | |||
| 400 | // Check if global already exists in an imported source file | ||
| 401 |
5/8✓ Branch 13 → 14 taken 18687 times.
✗ Branch 13 → 56 not taken.
✓ Branch 14 → 15 taken 18687 times.
✗ Branch 14 → 56 not taken.
✓ Branch 15 → 16 taken 18687 times.
✗ Branch 15 → 56 not taken.
✓ Branch 29 → 17 taken 75140 times.
✓ Branch 29 → 30 taken 18685 times.
|
93825 | for (const auto &dependency : sourceFile->dependencies | std::views::values) |
| 402 |
3/4✓ Branch 18 → 19 taken 75140 times.
✗ Branch 18 → 56 not taken.
✓ Branch 19 → 20 taken 2 times.
✓ Branch 19 → 27 taken 75138 times.
|
75140 | if (dependency->exportedNameRegistry.contains(node->varName)) |
| 403 |
3/6✓ Branch 21 → 22 taken 2 times.
✗ Branch 21 → 52 not taken.
✓ Branch 22 → 23 taken 2 times.
✗ Branch 22 → 50 not taken.
✓ Branch 23 → 24 taken 2 times.
✗ Branch 23 → 47 not taken.
|
2 | throw SemanticError(node, GLOBAL_DECLARED_TWICE, "Duplicate global variable '" + node->varName + "' in other module"); |
| 404 | |||
| 405 | // Add the global to the symbol table | ||
| 406 | 18685 | node->entry = rootScope->insert(node->varName, node); | |
| 407 | // Register the name in the exported name registry | ||
| 408 | 18685 | sourceFile->addNameRegistryEntry(node->varName, TY_INVALID, node->entry, currentScope, true); | |
| 409 | |||
| 410 |
1/2✓ Branch 34 → 35 taken 18685 times.
✗ Branch 34 → 57 not taken.
|
37370 | return nullptr; |
| 411 | } | ||
| 412 | |||
| 413 | 15650 | std::any SymbolTableBuilder::visitExtDecl(ExtDeclNode *node) { | |
| 414 | // Visit attributes | ||
| 415 |
2/2✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 6 taken 15648 times.
|
15650 | if (node->attrs) |
| 416 |
1/2✓ Branch 3 → 4 taken 2 times.
✗ Branch 3 → 31 not taken.
|
2 | visit(node->attrs); |
| 417 | |||
| 418 | // Check if this name already exists | ||
| 419 |
2/2✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 17 taken 15648 times.
|
31300 | if (rootScope->lookupStrict(node->extFunctionName)) |
| 420 |
3/6✓ Branch 11 → 12 taken 2 times.
✗ Branch 11 → 37 not taken.
✓ Branch 12 → 13 taken 2 times.
✗ Branch 12 → 35 not taken.
✓ Branch 13 → 14 taken 2 times.
✗ Branch 13 → 32 not taken.
|
2 | throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->extFunctionName + "'"); |
| 421 | |||
| 422 | // Create scope for the external function (this is required in case of forceSubstantiation in FunctionManager::matchFunction) | ||
| 423 |
2/4✓ Branch 17 → 18 taken 15648 times.
✗ Branch 17 → 43 not taken.
✓ Branch 18 → 19 taken 15648 times.
✗ Branch 18 → 41 not taken.
|
15648 | rootScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc); |
| 424 | |||
| 425 | // Add the external declaration to the symbol table | ||
| 426 | 15648 | node->entry = rootScope->insert(node->extFunctionName, node); | |
| 427 | // Register the name in the exported name registry | ||
| 428 |
2/2✓ Branch 23 → 24 taken 12395 times.
✓ Branch 23 → 25 taken 3253 times.
|
15648 | const uint64_t typeId = node->returnType ? TY_FUNCTION : TY_PROCEDURE; |
| 429 | 15648 | sourceFile->addNameRegistryEntry(node->extFunctionName, typeId, node->entry, rootScope, /*keepNewOnCollision=*/true); | |
| 430 | |||
| 431 |
1/2✓ Branch 27 → 28 taken 15648 times.
✗ Branch 27 → 44 not taken.
|
31296 | return nullptr; |
| 432 | } | ||
| 433 | |||
| 434 | 26520 | std::any SymbolTableBuilder::visitUnsafeBlock(UnsafeBlockNode *node) { | |
| 435 | // Create scope for the unsafe block body | ||
| 436 | 26520 | node->bodyScope = currentScope = | |
| 437 |
2/4✓ Branch 2 → 3 taken 26520 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 26520 times.
✗ Branch 3 → 11 not taken.
|
26520 | currentScope->createChildScope(node->getScopeId(), ScopeType::UNSAFE_BODY, &node->body->codeLoc); |
| 438 | |||
| 439 | // Visit body | ||
| 440 |
1/2✓ Branch 5 → 6 taken 26520 times.
✗ Branch 5 → 14 not taken.
|
26520 | visit(node->body); |
| 441 | |||
| 442 | // Leave thread body scope | ||
| 443 | 26520 | currentScope = node->bodyScope->parent; | |
| 444 | |||
| 445 |
1/2✓ Branch 7 → 8 taken 26520 times.
✗ Branch 7 → 15 not taken.
|
53040 | return nullptr; |
| 446 | } | ||
| 447 | |||
| 448 | 9612 | std::any SymbolTableBuilder::visitForLoop(ForLoopNode *node) { | |
| 449 | // Create scope for the loop body | ||
| 450 |
2/4✓ Branch 2 → 3 taken 9612 times.
✗ Branch 2 → 16 not taken.
✓ Branch 3 → 4 taken 9612 times.
✗ Branch 3 → 14 not taken.
|
9612 | node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FOR_BODY, &node->body->codeLoc); |
| 451 | |||
| 452 | // Visit loop variable declaration | ||
| 453 |
1/2✓ Branch 5 → 6 taken 9612 times.
✗ Branch 5 → 17 not taken.
|
9612 | visit(node->initDecl); |
| 454 | |||
| 455 | // Visit condition | ||
| 456 | 9612 | visitInExprScope(node->condAssign); | |
| 457 | |||
| 458 | // Visit body | ||
| 459 |
1/2✓ Branch 8 → 9 taken 9612 times.
✗ Branch 8 → 18 not taken.
|
9612 | visit(node->body); |
| 460 | |||
| 461 | // Leave for body scope | ||
| 462 | 9612 | currentScope = node->bodyScope->parent; | |
| 463 | |||
| 464 |
1/2✓ Branch 10 → 11 taken 9612 times.
✗ Branch 10 → 19 not taken.
|
19224 | return nullptr; |
| 465 | } | ||
| 466 | |||
| 467 | 9985 | std::any SymbolTableBuilder::visitForeachLoop(ForeachLoopNode *node) { | |
| 468 | // Create scope for the loop body | ||
| 469 | 9985 | node->bodyScope = currentScope = | |
| 470 |
2/4✓ Branch 2 → 3 taken 9985 times.
✗ Branch 2 → 19 not taken.
✓ Branch 3 → 4 taken 9985 times.
✗ Branch 3 → 17 not taken.
|
9985 | currentScope->createChildScope(node->getScopeId(), ScopeType::FOREACH_BODY, &node->body->codeLoc); |
| 471 | |||
| 472 | // Visit index variable declaration | ||
| 473 |
2/2✓ Branch 5 → 6 taken 996 times.
✓ Branch 5 → 9 taken 8989 times.
|
9985 | if (node->idxVarDecl) |
| 474 |
1/2✓ Branch 6 → 7 taken 996 times.
✗ Branch 6 → 20 not taken.
|
996 | visit(node->idxVarDecl); |
| 475 | |||
| 476 | // Visit item variable declaration | ||
| 477 |
1/2✓ Branch 9 → 10 taken 9985 times.
✗ Branch 9 → 21 not taken.
|
9985 | visit(node->itemVarDecl); |
| 478 | |||
| 479 | // Visit body | ||
| 480 |
1/2✓ Branch 11 → 12 taken 9985 times.
✗ Branch 11 → 22 not taken.
|
9985 | visit(node->body); |
| 481 | |||
| 482 | // Leave foreach body scope | ||
| 483 | 9985 | currentScope = node->bodyScope->parent; | |
| 484 | |||
| 485 |
1/2✓ Branch 13 → 14 taken 9985 times.
✗ Branch 13 → 23 not taken.
|
19970 | return nullptr; |
| 486 | } | ||
| 487 | |||
| 488 | 8369 | std::any SymbolTableBuilder::visitWhileLoop(WhileLoopNode *node) { | |
| 489 | // Create scope for the loop body | ||
| 490 | 8369 | node->bodyScope = currentScope = | |
| 491 |
2/4✓ Branch 2 → 3 taken 8369 times.
✗ Branch 2 → 14 not taken.
✓ Branch 3 → 4 taken 8369 times.
✗ Branch 3 → 12 not taken.
|
8369 | currentScope->createChildScope(node->getScopeId(), ScopeType::WHILE_BODY, &node->body->codeLoc); |
| 492 | |||
| 493 | // Visit condition | ||
| 494 | 8369 | visitInExprScope(node->condition); | |
| 495 | |||
| 496 | // Visit body | ||
| 497 |
1/2✓ Branch 6 → 7 taken 8369 times.
✗ Branch 6 → 15 not taken.
|
8369 | visit(node->body); |
| 498 | |||
| 499 | // Leave while body scope | ||
| 500 | 8369 | currentScope = node->bodyScope->parent; | |
| 501 | |||
| 502 |
1/2✓ Branch 8 → 9 taken 8369 times.
✗ Branch 8 → 16 not taken.
|
16738 | return nullptr; |
| 503 | } | ||
| 504 | |||
| 505 | 163 | std::any SymbolTableBuilder::visitDoWhileLoop(DoWhileLoopNode *node) { | |
| 506 | // Create scope for the loop body | ||
| 507 | 163 | node->bodyScope = currentScope = | |
| 508 |
2/4✓ Branch 2 → 3 taken 163 times.
✗ Branch 2 → 14 not taken.
✓ Branch 3 → 4 taken 163 times.
✗ Branch 3 → 12 not taken.
|
163 | currentScope->createChildScope(node->getScopeId(), ScopeType::WHILE_BODY, &node->body->codeLoc); |
| 509 | |||
| 510 | // Visit condition | ||
| 511 | 163 | visitInExprScope(node->condition); | |
| 512 | |||
| 513 | // Visit body | ||
| 514 |
1/2✓ Branch 6 → 7 taken 163 times.
✗ Branch 6 → 15 not taken.
|
163 | visit(node->body); |
| 515 | |||
| 516 | // Leave do-while body scope | ||
| 517 | 163 | currentScope = node->bodyScope->parent; | |
| 518 | |||
| 519 |
1/2✓ Branch 8 → 9 taken 163 times.
✗ Branch 8 → 16 not taken.
|
326 | return nullptr; |
| 520 | } | ||
| 521 | |||
| 522 | 107952 | std::any SymbolTableBuilder::visitIfStmt(IfStmtNode *node) { | |
| 523 | // Create scope for the then body | ||
| 524 | 107952 | node->thenBodyScope = currentScope = | |
| 525 |
2/4✓ Branch 2 → 3 taken 107952 times.
✗ Branch 2 → 26 not taken.
✓ Branch 3 → 4 taken 107952 times.
✗ Branch 3 → 24 not taken.
|
107952 | currentScope->createChildScope(node->getScopeId(), ScopeType::IF_ELSE_BODY, &node->thenBody->codeLoc); |
| 526 | |||
| 527 | // Visit condition | ||
| 528 | 107952 | visitInExprScope(node->condition); | |
| 529 | |||
| 530 | // Visit then body (manifestations do not exist yet, so both branches are always visited here) | ||
| 531 |
1/2✓ Branch 7 → 8 taken 107952 times.
✗ Branch 7 → 11 not taken.
|
107952 | if (node->doCompileThenBranch(manIdx)) |
| 532 |
1/2✓ Branch 8 → 9 taken 107952 times.
✗ Branch 8 → 27 not taken.
|
107952 | visit(node->thenBody); |
| 533 | |||
| 534 | // Leave then body scope | ||
| 535 | 107952 | currentScope = node->thenBodyScope->parent; | |
| 536 | |||
| 537 | // Visit else stmt | ||
| 538 |
5/6✓ Branch 12 → 13 taken 107952 times.
✗ Branch 12 → 15 not taken.
✓ Branch 13 → 14 taken 18145 times.
✓ Branch 13 → 15 taken 89807 times.
✓ Branch 16 → 17 taken 18145 times.
✓ Branch 16 → 20 taken 89807 times.
|
107952 | if (node->doCompileElseBranch(manIdx) && node->elseStmt) |
| 539 |
1/2✓ Branch 17 → 18 taken 18145 times.
✗ Branch 17 → 28 not taken.
|
18145 | visit(node->elseStmt); |
| 540 | |||
| 541 |
1/2✓ Branch 20 → 21 taken 107952 times.
✗ Branch 20 → 29 not taken.
|
215904 | return nullptr; |
| 542 | } | ||
| 543 | |||
| 544 | 18145 | std::any SymbolTableBuilder::visitElseStmt(ElseStmtNode *node) { | |
| 545 | // Visit if statement in the case of an else if branch | ||
| 546 |
2/2✓ Branch 2 → 3 taken 10225 times.
✓ Branch 2 → 8 taken 7920 times.
|
18145 | if (node->isElseIf) { |
| 547 |
1/2✓ Branch 3 → 4 taken 10225 times.
✗ Branch 3 → 17 not taken.
|
10225 | visit(node->ifStmt); |
| 548 |
1/2✓ Branch 5 → 6 taken 10225 times.
✗ Branch 5 → 18 not taken.
|
20450 | return nullptr; |
| 549 | } | ||
| 550 | |||
| 551 | // Create scope for the else body | ||
| 552 | 7920 | node->elseBodyScope = currentScope = | |
| 553 |
2/4✓ Branch 8 → 9 taken 7920 times.
✗ Branch 8 → 21 not taken.
✓ Branch 9 → 10 taken 7920 times.
✗ Branch 9 → 19 not taken.
|
7920 | currentScope->createChildScope(node->getScopeId(), ScopeType::IF_ELSE_BODY, &node->body->codeLoc); |
| 554 | |||
| 555 | // Visit else body | ||
| 556 |
1/2✓ Branch 11 → 12 taken 7920 times.
✗ Branch 11 → 22 not taken.
|
7920 | visit(node->body); |
| 557 | |||
| 558 | // Leave else body scope | ||
| 559 | 7920 | currentScope = node->elseBodyScope->parent; | |
| 560 | |||
| 561 |
1/2✓ Branch 13 → 14 taken 7920 times.
✗ Branch 13 → 23 not taken.
|
15840 | return nullptr; |
| 562 | } | ||
| 563 | |||
| 564 | 16381 | std::any SymbolTableBuilder::visitCaseBranch(CaseBranchNode *node) { | |
| 565 | // Create scope for the case branch | ||
| 566 |
2/4✓ Branch 2 → 3 taken 16381 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 16381 times.
✗ Branch 3 → 11 not taken.
|
16381 | node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::CASE_BODY, &node->body->codeLoc); |
| 567 | |||
| 568 | // Visit case body | ||
| 569 |
1/2✓ Branch 5 → 6 taken 16381 times.
✗ Branch 5 → 14 not taken.
|
16381 | visit(node->body); |
| 570 | |||
| 571 | // Leave case body scope | ||
| 572 | 16381 | currentScope = node->bodyScope->parent; | |
| 573 | |||
| 574 |
1/2✓ Branch 7 → 8 taken 16381 times.
✗ Branch 7 → 15 not taken.
|
32762 | return nullptr; |
| 575 | } | ||
| 576 | |||
| 577 | 929 | std::any SymbolTableBuilder::visitDefaultBranch(DefaultBranchNode *node) { | |
| 578 | // Create scope for the default branch | ||
| 579 | 929 | node->bodyScope = currentScope = | |
| 580 |
2/4✓ Branch 2 → 3 taken 929 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 929 times.
✗ Branch 3 → 11 not taken.
|
929 | currentScope->createChildScope(node->getScopeId(), ScopeType::DEFAULT_BODY, &node->body->codeLoc); |
| 581 | |||
| 582 | // Visit default body | ||
| 583 |
1/2✓ Branch 5 → 6 taken 929 times.
✗ Branch 5 → 14 not taken.
|
929 | visit(node->body); |
| 584 | |||
| 585 | // Leave default body scope | ||
| 586 | 929 | currentScope = node->bodyScope->parent; | |
| 587 | |||
| 588 |
1/2✓ Branch 7 → 8 taken 929 times.
✗ Branch 7 → 15 not taken.
|
1858 | return nullptr; |
| 589 | } | ||
| 590 | |||
| 591 | 321 | std::any SymbolTableBuilder::visitAnonymousBlockStmt(AnonymousBlockStmtNode *node) { | |
| 592 | // Create scope for the anonymous block body | ||
| 593 | 321 | node->bodyScope = currentScope = | |
| 594 |
2/4✓ Branch 2 → 3 taken 321 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 321 times.
✗ Branch 3 → 11 not taken.
|
321 | currentScope->createChildScope(node->getScopeId(), ScopeType::ANONYMOUS_BLOCK_BODY, &node->body->codeLoc); |
| 595 | |||
| 596 | // Visit body | ||
| 597 |
1/2✓ Branch 5 → 6 taken 321 times.
✗ Branch 5 → 14 not taken.
|
321 | visit(node->body); |
| 598 | |||
| 599 | // Leave anonymous block body scope | ||
| 600 | 321 | currentScope = node->bodyScope->parent; | |
| 601 | |||
| 602 |
1/2✓ Branch 7 → 8 taken 321 times.
✗ Branch 7 → 15 not taken.
|
642 | return nullptr; |
| 603 | } | ||
| 604 | |||
| 605 | 45378 | std::any SymbolTableBuilder::visitEnumItem(EnumItemNode *node) { | |
| 606 | // Check if enum item already exists in the same scope. | ||
| 607 |
3/4✓ Branch 2 → 3 taken 45378 times.
✗ Branch 2 → 42 not taken.
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 45376 times.
|
90756 | if (currentScope->lookupStrict(node->itemName)) |
| 608 |
3/6✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 32 not taken.
✓ Branch 8 → 9 taken 2 times.
✗ Branch 8 → 30 not taken.
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 27 not taken.
|
2 | throw SemanticError(node, VARIABLE_DECLARED_TWICE, "The enum item '" + node->itemName + "' was declared more than once"); |
| 609 | |||
| 610 | // Add enum item entry to symbol table | ||
| 611 |
1/2✓ Branch 13 → 14 taken 45376 times.
✗ Branch 13 → 42 not taken.
|
45376 | SymbolTableEntry *enumItemEntry = currentScope->insert(node->itemName, node); |
| 612 | |||
| 613 | // Add external registry entry | ||
| 614 |
1/2✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 45376 times.
|
45376 | assert(node->enumDef != nullptr); |
| 615 |
2/4✓ Branch 18 → 19 taken 45376 times.
✗ Branch 18 → 38 not taken.
✓ Branch 19 → 20 taken 45376 times.
✗ Branch 19 → 36 not taken.
|
45376 | const std::string name = node->enumDef->enumName + SCOPE_ACCESS_TOKEN + node->itemName; |
| 616 |
1/2✓ Branch 21 → 22 taken 45376 times.
✗ Branch 21 → 40 not taken.
|
45376 | sourceFile->addNameRegistryEntry(name, TY_INT, enumItemEntry, currentScope, true); |
| 617 | |||
| 618 |
1/2✓ Branch 22 → 23 taken 45376 times.
✗ Branch 22 → 39 not taken.
|
90752 | return nullptr; |
| 619 | 45376 | } | |
| 620 | |||
| 621 | 54792 | std::any SymbolTableBuilder::visitField(FieldNode *node) { | |
| 622 | // Check if field already exists in the same scope. | ||
| 623 |
2/2✓ Branch 5 → 6 taken 4 times.
✓ Branch 5 → 13 taken 54788 times.
|
109584 | if (currentScope->lookupStrict(node->fieldName)) |
| 624 |
3/6✓ Branch 7 → 8 taken 4 times.
✗ Branch 7 → 25 not taken.
✓ Branch 8 → 9 taken 4 times.
✗ Branch 8 → 23 not taken.
✓ Branch 9 → 10 taken 4 times.
✗ Branch 9 → 20 not taken.
|
4 | throw SemanticError(node, VARIABLE_DECLARED_TWICE, "The field '" + node->fieldName + "' was declared more than once"); |
| 625 | |||
| 626 | // Add field entry to symbol table | ||
| 627 | 54788 | currentScope->insert(node->fieldName, node); | |
| 628 | |||
| 629 |
1/2✓ Branch 16 → 17 taken 54788 times.
✗ Branch 16 → 29 not taken.
|
109576 | return nullptr; |
| 630 | } | ||
| 631 | |||
| 632 | 5177 | std::any SymbolTableBuilder::visitSignature(SignatureNode *node) { | |
| 633 | // Build signature qualifiers | ||
| 634 |
2/2✓ Branch 2 → 3 taken 5079 times.
✓ Branch 2 → 32 taken 98 times.
|
5177 | if (const QualifierLstNode *qualifierLst = node->qualifierLst) { |
| 635 |
2/2✓ Branch 30 → 5 taken 5079 times.
✓ Branch 30 → 31 taken 5079 times.
|
15237 | for (const QualifierNode *qualifier : qualifierLst->qualifiers) { |
| 636 |
1/2✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 5079 times.
|
5079 | if (qualifier->type == QualifierNode::QualifierType::TY_INLINE) |
| 637 | ✗ | node->signatureQualifiers.isInline = true; | |
| 638 |
1/2✓ Branch 9 → 10 taken 5079 times.
✗ Branch 9 → 11 not taken.
|
5079 | else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC) |
| 639 | 5079 | node->signatureQualifiers.isPublic = true; | |
| 640 | ✗ | else if (qualifier->type == QualifierNode::QualifierType::TY_CONST) | |
| 641 | ✗ | node->signatureQualifiers.isConst = true; | |
| 642 | else | ||
| 643 | ✗ | throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on a signature definition"); | |
| 644 | } | ||
| 645 | } | ||
| 646 | |||
| 647 | // Add signature entry to symbol table. We append the code location to disambiguate overloaded signatures | ||
| 648 | // (e.g. an interface declaring `getName()` and `getName(bool)`). | ||
| 649 |
1/2✓ Branch 32 → 33 taken 5177 times.
✗ Branch 32 → 53 not taken.
|
10354 | node->entry = currentScope->insert(Function::getSymbolTableEntryName(node->methodName, node->codeLoc), node); |
| 650 | |||
| 651 |
1/2✓ Branch 37 → 38 taken 5177 times.
✗ Branch 37 → 54 not taken.
|
10354 | return nullptr; |
| 652 | } | ||
| 653 | |||
| 654 | 328780 | std::any SymbolTableBuilder::visitDeclStmt(DeclStmtNode *node) { | |
| 655 | // Check if variable already exists in the same scope. | ||
| 656 |
2/2✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 328778 times.
|
657560 | if (currentScope->lookupStrict(node->varName)) |
| 657 |
3/6✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 29 not taken.
✓ Branch 8 → 9 taken 2 times.
✗ Branch 8 → 27 not taken.
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 24 not taken.
|
2 | throw SemanticError(node, VARIABLE_DECLARED_TWICE, "The variable '" + node->varName + "' was declared more than once"); |
| 658 | |||
| 659 | // Visit the right side | ||
| 660 |
2/2✓ Branch 13 → 14 taken 141539 times.
✓ Branch 13 → 17 taken 187239 times.
|
328778 | if (node->hasAssignment) |
| 661 |
1/2✓ Branch 14 → 15 taken 141539 times.
✗ Branch 14 → 33 not taken.
|
141539 | visit(node->assignExpr); |
| 662 | |||
| 663 | // Add variable entry to symbol table | ||
| 664 | 328778 | SymbolTableEntry *varEntry = currentScope->insert(node->varName, node); | |
| 665 | 328778 | varEntry->isParam = node->isFctParam; | |
| 666 | |||
| 667 |
1/2✓ Branch 20 → 21 taken 328778 times.
✗ Branch 20 → 34 not taken.
|
657556 | return nullptr; |
| 668 | } | ||
| 669 | |||
| 670 | 2478 | std::any SymbolTableBuilder::visitModAttr(ModAttrNode *node) { | |
| 671 | // Visit attributes | ||
| 672 |
2/2✓ Branch 2 → 3 taken 2476 times.
✓ Branch 2 → 126 taken 2 times.
|
2478 | visitChildren(node); |
| 673 | |||
| 674 | // Retrieve attributes | ||
| 675 | 2476 | const AttrLstNode *attrs = node->attrLst; | |
| 676 | |||
| 677 | // Collect linker flags | ||
| 678 | 2476 | std::vector<const CompileTimeValue *> linkerFlagValues; | |
| 679 | // core.linker.flag | ||
| 680 |
2/4✓ Branch 6 → 7 taken 2476 times.
✗ Branch 6 → 129 not taken.
✓ Branch 7 → 8 taken 2476 times.
✗ Branch 7 → 127 not taken.
|
4952 | std::vector<const CompileTimeValue *> values = attrs->getAttrValuesByName(ATTR_CORE_LINKER_FLAG); |
| 681 |
1/2✓ Branch 16 → 17 taken 2476 times.
✗ Branch 16 → 133 not taken.
|
4952 | linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end()); |
| 682 | // core.linux.linker.flag | ||
| 683 | 2476 | const llvm::Triple &targetTriple = sourceFile->targetMachine->getTargetTriple(); | |
| 684 |
2/2✓ Branch 20 → 21 taken 2452 times.
✓ Branch 20 → 37 taken 24 times.
|
2476 | if (targetTriple.isOSLinux()) { |
| 685 |
2/4✓ Branch 23 → 24 taken 2452 times.
✗ Branch 23 → 137 not taken.
✓ Branch 24 → 25 taken 2452 times.
✗ Branch 24 → 135 not taken.
|
4904 | values = attrs->getAttrValuesByName(ATTR_CORE_LINUX_LINKER_FLAG); |
| 686 |
1/2✓ Branch 35 → 36 taken 2452 times.
✗ Branch 35 → 142 not taken.
|
4904 | linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end()); |
| 687 | } | ||
| 688 | // core.darwin.linker.flag | ||
| 689 |
3/4✓ Branch 37 → 38 taken 2476 times.
✗ Branch 37 → 187 not taken.
✓ Branch 38 → 39 taken 12 times.
✓ Branch 38 → 55 taken 2464 times.
|
2476 | if (targetTriple.isOSDarwin()) { |
| 690 |
2/4✓ Branch 41 → 42 taken 12 times.
✗ Branch 41 → 146 not taken.
✓ Branch 42 → 43 taken 12 times.
✗ Branch 42 → 144 not taken.
|
24 | values = attrs->getAttrValuesByName(ATTR_CORE_DARWIN_LINKER_FLAG); |
| 691 |
1/2✓ Branch 53 → 54 taken 12 times.
✗ Branch 53 → 151 not taken.
|
24 | linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end()); |
| 692 | } | ||
| 693 | // core.windows.linker.flag | ||
| 694 |
2/2✓ Branch 56 → 57 taken 12 times.
✓ Branch 56 → 73 taken 2464 times.
|
2476 | if (targetTriple.isOSWindows()) { |
| 695 |
2/4✓ Branch 59 → 60 taken 12 times.
✗ Branch 59 → 155 not taken.
✓ Branch 60 → 61 taken 12 times.
✗ Branch 60 → 153 not taken.
|
24 | values = attrs->getAttrValuesByName(ATTR_CORE_WINDOWS_LINKER_FLAG); |
| 696 |
1/2✓ Branch 71 → 72 taken 12 times.
✗ Branch 71 → 160 not taken.
|
24 | linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end()); |
| 697 | } | ||
| 698 |
2/2✓ Branch 89 → 75 taken 7862 times.
✓ Branch 89 → 90 taken 2476 times.
|
12814 | for (const CompileTimeValue *value : linkerFlagValues) { |
| 699 |
1/2✓ Branch 77 → 78 taken 7862 times.
✗ Branch 77 → 162 not taken.
|
7862 | const std::string &flag = resourceManager.compileTimeStringValues.at(value->stringValueOffset); |
| 700 |
1/2✓ Branch 78 → 79 taken 7862 times.
✗ Branch 78 → 162 not taken.
|
7862 | resourceManager.linker.addLinkerFlag(flag); |
| 701 |
1/2✓ Branch 79 → 80 taken 7862 times.
✗ Branch 79 → 162 not taken.
|
7862 | sourceFile->sourceLinkerFlags.push_back(flag); |
| 702 | } | ||
| 703 | |||
| 704 | // core.linker.additionalSource | ||
| 705 |
4/6✓ Branch 90 → 91 taken 2476 times.
✗ Branch 90 → 165 not taken.
✓ Branch 91 → 92 taken 2476 times.
✗ Branch 91 → 163 not taken.
✓ Branch 116 → 94 taken 60 times.
✓ Branch 116 → 117 taken 2474 times.
|
5010 | for (const CompileTimeValue *value : attrs->getAttrValuesByName(ATTR_CORE_LINKER_ADDITIONAL_SOURCE)) { |
| 706 |
1/2✓ Branch 96 → 97 taken 60 times.
✗ Branch 96 → 178 not taken.
|
60 | const std::string &stringValue = resourceManager.compileTimeStringValues.at(value->stringValueOffset); |
| 707 |
3/6✓ Branch 97 → 98 taken 60 times.
✗ Branch 97 → 172 not taken.
✓ Branch 98 → 99 taken 60 times.
✗ Branch 98 → 169 not taken.
✓ Branch 99 → 100 taken 60 times.
✗ Branch 99 → 167 not taken.
|
60 | const std::filesystem::path additionalSourcePath = sourceFile->filePath.parent_path() / stringValue; |
| 708 |
3/4✓ Branch 102 → 103 taken 60 times.
✗ Branch 102 → 175 not taken.
✓ Branch 103 → 104 taken 58 times.
✓ Branch 103 → 173 taken 2 times.
|
62 | resourceManager.linker.addAdditionalSourcePath(additionalSourcePath); |
| 709 |
1/2✓ Branch 105 → 106 taken 58 times.
✗ Branch 105 → 176 not taken.
|
58 | sourceFile->sourceAdditionalSourcePaths.push_back(additionalSourcePath); |
| 710 | 2538 | } | |
| 711 | |||
| 712 |
1/2✓ Branch 120 → 121 taken 2474 times.
✗ Branch 120 → 186 not taken.
|
4948 | return nullptr; |
| 713 | 2478 | } | |
| 714 | |||
| 715 | 16892 | std::any SymbolTableBuilder::visitAttr(AttrNode *node) { | |
| 716 | // Check if this attribute exists | ||
| 717 |
1/2✓ Branch 2 → 3 taken 16892 times.
✗ Branch 2 → 63 not taken.
|
16892 | const auto it = ATTR_CONFIGS.find(node->key); |
| 718 |
2/2✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 16890 times.
|
16892 | if (it == ATTR_CONFIGS.end()) |
| 719 |
3/6✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 40 not taken.
✓ Branch 8 → 9 taken 2 times.
✗ Branch 8 → 38 not taken.
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 35 not taken.
|
2 | throw SemanticError(node, UNKNOWN_ATTR, "Unknown attribute '" + node->key + "'"); |
| 720 | |||
| 721 | // Check if the target is correct | ||
| 722 | 16890 | const auto &[target, type] = it->second; | |
| 723 |
2/2✓ Branch 14 → 15 taken 2 times.
✓ Branch 14 → 22 taken 16888 times.
|
16890 | if ((node->target & target) == 0) |
| 724 |
3/6✓ Branch 16 → 17 taken 2 times.
✗ Branch 16 → 49 not taken.
✓ Branch 17 → 18 taken 2 times.
✗ Branch 17 → 47 not taken.
✓ Branch 18 → 19 taken 2 times.
✗ Branch 18 → 44 not taken.
|
2 | throw SemanticError(node, INVALID_ATTR_TARGET, "Attribute '" + node->key + "' cannot be used on this target"); |
| 725 | |||
| 726 | // Check if a value is present | ||
| 727 |
4/4✓ Branch 22 → 23 taken 3572 times.
✓ Branch 22 → 31 taken 13316 times.
✓ Branch 23 → 24 taken 2 times.
✓ Branch 23 → 31 taken 3570 times.
|
16888 | if (!node->value && type != AttrNode::AttrType::TYPE_BOOL) |
| 728 |
3/6✓ Branch 25 → 26 taken 2 times.
✗ Branch 25 → 58 not taken.
✓ Branch 26 → 27 taken 2 times.
✗ Branch 26 → 56 not taken.
✓ Branch 27 → 28 taken 2 times.
✗ Branch 27 → 53 not taken.
|
2 | throw SemanticError(node, MISSING_ATTR_VALUE, "Attribute '" + node->key + "' requires a value"); |
| 729 | |||
| 730 |
1/2✓ Branch 31 → 32 taken 16886 times.
✗ Branch 31 → 62 not taken.
|
33772 | return nullptr; |
| 731 | } | ||
| 732 | |||
| 733 | 109 | std::any SymbolTableBuilder::visitLambdaFunc(LambdaFuncNode *node) { | |
| 734 | // Create scope for the lambda body | ||
| 735 | 109 | const CodeLoc &codeLoc = node->body->codeLoc; | |
| 736 |
2/4✓ Branch 2 → 3 taken 109 times.
✗ Branch 2 → 47 not taken.
✓ Branch 3 → 4 taken 109 times.
✗ Branch 3 → 45 not taken.
|
109 | 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 | 109 | currentScope->symbolTable.setCapturingRequired(); | |
| 739 | // Set to async scope if this is an async lambda | ||
| 740 |
4/18✗ Branch 6 → 7 not taken.
✓ Branch 6 → 13 taken 109 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 109 times.
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 19 taken 109 times.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 27 taken 109 times.
✗ Branch 48 → 49 not taken.
✗ Branch 48 → 50 not taken.
✗ Branch 52 → 53 not taken.
✗ Branch 52 → 55 not taken.
|
109 | if (node->lambdaAttr && node->lambdaAttr->attrLst->hasAttr(ATTR_ASYNC)) |
| 741 | ✗ | node->bodyScope->isAsyncScope = node->lambdaAttr->attrLst->getAttrValueByName(ATTR_ASYNC)->boolValue; | |
| 742 | |||
| 743 | // Create symbol for 'result' variable | ||
| 744 |
1/2✓ Branch 29 → 30 taken 109 times.
✗ Branch 29 → 65 not taken.
|
327 | currentScope->insert(RETURN_VARIABLE_NAME, node); |
| 745 | |||
| 746 | // Create symbols for the parameters | ||
| 747 |
2/2✓ Branch 35 → 36 taken 99 times.
✓ Branch 35 → 39 taken 10 times.
|
109 | if (node->hasParams) |
| 748 |
1/2✓ Branch 36 → 37 taken 99 times.
✗ Branch 36 → 69 not taken.
|
99 | visit(node->paramLst); |
| 749 | |||
| 750 | // Visit body | ||
| 751 |
1/2✓ Branch 39 → 40 taken 109 times.
✗ Branch 39 → 70 not taken.
|
109 | visit(node->body); |
| 752 | |||
| 753 | // Leave anonymous block body scope | ||
| 754 | 109 | currentScope = node->bodyScope->parent; | |
| 755 | |||
| 756 |
1/2✓ Branch 41 → 42 taken 109 times.
✗ Branch 41 → 71 not taken.
|
218 | return nullptr; |
| 757 | } | ||
| 758 | |||
| 759 | 1354 | std::any SymbolTableBuilder::visitLambdaProc(LambdaProcNode *node) { | |
| 760 | // Create scope for the lambda body | ||
| 761 | 1354 | const CodeLoc &codeLoc = node->body->codeLoc; | |
| 762 |
2/4✓ Branch 2 → 3 taken 1354 times.
✗ Branch 2 → 39 not taken.
✓ Branch 3 → 4 taken 1354 times.
✗ Branch 3 → 37 not taken.
|
1354 | node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::LAMBDA_BODY, &codeLoc); |
| 763 | // Requires capturing because the LLVM IR will end up in a separate function | ||
| 764 | 1354 | currentScope->symbolTable.setCapturingRequired(); | |
| 765 | // Set to async scope if this is an async lambda | ||
| 766 |
11/18✓ Branch 6 → 7 taken 16 times.
✓ Branch 6 → 13 taken 1338 times.
✓ Branch 9 → 10 taken 16 times.
✗ Branch 9 → 40 not taken.
✓ Branch 10 → 11 taken 16 times.
✗ Branch 10 → 40 not taken.
✓ Branch 11 → 12 taken 16 times.
✗ Branch 11 → 13 not taken.
✓ Branch 14 → 15 taken 16 times.
✓ Branch 14 → 16 taken 1338 times.
✓ Branch 16 → 17 taken 16 times.
✓ Branch 16 → 19 taken 1338 times.
✓ Branch 19 → 20 taken 16 times.
✓ Branch 19 → 27 taken 1338 times.
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 42 not taken.
✗ Branch 44 → 45 not taken.
✗ Branch 44 → 47 not taken.
|
1386 | if (node->lambdaAttr && node->lambdaAttr->attrLst->hasAttr(ATTR_ASYNC)) |
| 767 |
2/4✓ Branch 22 → 23 taken 16 times.
✗ Branch 22 → 51 not taken.
✓ Branch 23 → 24 taken 16 times.
✗ Branch 23 → 49 not taken.
|
48 | node->bodyScope->isAsyncScope = node->lambdaAttr->attrLst->getAttrValueByName(ATTR_ASYNC)->boolValue; |
| 768 | |||
| 769 | // Create symbols for the parameters | ||
| 770 |
2/2✓ Branch 27 → 28 taken 1014 times.
✓ Branch 27 → 31 taken 340 times.
|
1354 | if (node->hasParams) |
| 771 |
1/2✓ Branch 28 → 29 taken 1014 times.
✗ Branch 28 → 55 not taken.
|
1014 | visit(node->paramLst); |
| 772 | |||
| 773 | // Visit body | ||
| 774 |
1/2✓ Branch 31 → 32 taken 1354 times.
✗ Branch 31 → 56 not taken.
|
1354 | visit(node->body); |
| 775 | |||
| 776 | // Leave anonymous block body scope | ||
| 777 | 1354 | currentScope = node->bodyScope->parent; | |
| 778 | |||
| 779 |
1/2✓ Branch 33 → 34 taken 1354 times.
✗ Branch 33 → 57 not taken.
|
2708 | return nullptr; |
| 780 | } | ||
| 781 | |||
| 782 | 2 | std::any SymbolTableBuilder::visitLambdaExpr(LambdaExprNode *node) { | |
| 783 | // Create scope for the anonymous block body | ||
| 784 | 2 | const CodeLoc &codeLoc = node->lambdaExpr->codeLoc; | |
| 785 |
2/4✓ Branch 2 → 3 taken 2 times.
✗ Branch 2 → 18 not taken.
✓ Branch 3 → 4 taken 2 times.
✗ Branch 3 → 16 not taken.
|
2 | node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::LAMBDA_BODY, &codeLoc); |
| 786 | // Requires capturing because the LLVM IR will end up in a separate function | ||
| 787 | 2 | currentScope->symbolTable.setCapturingRequired(); | |
| 788 | |||
| 789 | // Create symbols for the parameters | ||
| 790 |
1/2✓ Branch 6 → 7 taken 2 times.
✗ Branch 6 → 10 not taken.
|
2 | if (node->hasParams) |
| 791 |
1/2✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 19 not taken.
|
2 | visit(node->paramLst); |
| 792 | |||
| 793 | // Visit lambda expression | ||
| 794 |
1/2✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 20 not taken.
|
2 | visit(node->lambdaExpr); |
| 795 | |||
| 796 | // Leave anonymous block body scope | ||
| 797 | 2 | currentScope = node->bodyScope->parent; | |
| 798 | |||
| 799 |
1/2✓ Branch 12 → 13 taken 2 times.
✗ Branch 12 → 21 not taken.
|
4 | return nullptr; |
| 800 | } | ||
| 801 | |||
| 802 | 8047 | std::any SymbolTableBuilder::visitTernaryExpr(TernaryExprNode *node) { | |
| 803 | // Visit condition, which is evaluated unconditionally | ||
| 804 |
1/2✓ Branch 2 → 3 taken 8047 times.
✗ Branch 2 → 13 not taken.
|
8047 | visit(node->condition); |
| 805 | |||
| 806 | // Visit the branches. Only one of them is evaluated, so each one gets its own scope for its temporaries. | ||
| 807 | // The true branch does not exist for shortened ternaries, as the condition takes its place. | ||
| 808 |
3/4✓ Branch 4 → 5 taken 8045 times.
✓ Branch 4 → 7 taken 2 times.
✓ Branch 5 → 6 taken 8045 times.
✗ Branch 5 → 7 not taken.
|
8047 | if (node->trueExpr && !node->isShortened) |
| 809 | 8045 | visitInExprScope(node->trueExpr); | |
| 810 |
1/2✓ Branch 7 → 8 taken 8047 times.
✗ Branch 7 → 9 not taken.
|
8047 | if (node->falseExpr) |
| 811 | 8047 | visitInExprScope(node->falseExpr); | |
| 812 | |||
| 813 |
1/2✓ Branch 9 → 10 taken 8047 times.
✗ Branch 9 → 14 not taken.
|
16094 | return nullptr; |
| 814 | } | ||
| 815 | |||
| 816 | 12575 | std::any SymbolTableBuilder::visitLogicalOrExpr(LogicalOrExprNode *node) { | |
| 817 | // Visit the first operand, which is evaluated unconditionally | ||
| 818 |
1/2✓ Branch 3 → 4 taken 12575 times.
✗ Branch 3 → 15 not taken.
|
12575 | visit(node->operands.front()); |
| 819 | |||
| 820 | // All further operands are only evaluated if the ones before did not short-circuit | ||
| 821 |
2/2✓ Branch 10 → 6 taken 18215 times.
✓ Branch 10 → 11 taken 12575 times.
|
30790 | for (size_t i = 1; i < node->operands.size(); i++) |
| 822 | 18215 | visitInExprScope(node->operands[i]); | |
| 823 | |||
| 824 |
1/2✓ Branch 11 → 12 taken 12575 times.
✗ Branch 11 → 16 not taken.
|
25150 | return nullptr; |
| 825 | } | ||
| 826 | |||
| 827 | 12909 | std::any SymbolTableBuilder::visitLogicalAndExpr(LogicalAndExprNode *node) { | |
| 828 | // Visit the first operand, which is evaluated unconditionally | ||
| 829 |
1/2✓ Branch 3 → 4 taken 12909 times.
✗ Branch 3 → 15 not taken.
|
12909 | visit(node->operands.front()); |
| 830 | |||
| 831 | // All further operands are only evaluated if the ones before did not short-circuit | ||
| 832 |
2/2✓ Branch 10 → 6 taken 15851 times.
✓ Branch 10 → 11 taken 12909 times.
|
28760 | for (size_t i = 1; i < node->operands.size(); i++) |
| 833 | 15851 | visitInExprScope(node->operands[i]); | |
| 834 | |||
| 835 |
1/2✓ Branch 11 → 12 taken 12909 times.
✗ Branch 11 → 16 not taken.
|
25818 | return nullptr; |
| 836 | } | ||
| 837 | |||
| 838 | /** | ||
| 839 | * Visit an expression in a scope of its own. That scope holds the temporaries of the expression, which allows destructing them | ||
| 840 | * right after the expression was evaluated. This is required for conditions and for operands that are only evaluated | ||
| 841 | * conditionally, since a temporary of those must not be destructed if it never was constructed. | ||
| 842 | * | ||
| 843 | * @param expr Expression to visit | ||
| 844 | */ | ||
| 845 | 176254 | void SymbolTableBuilder::visitInExprScope(ExprNode *expr) { | |
| 846 | // Create scope for the expression | ||
| 847 |
2/4✓ Branch 2 → 3 taken 176254 times.
✗ Branch 2 → 10 not taken.
✓ Branch 3 → 4 taken 176254 times.
✗ Branch 3 → 8 not taken.
|
176254 | currentScope = currentScope->createChildScope(expr->getExprScopeId(), ScopeType::EXPR_BODY, &expr->codeLoc); |
| 848 | |||
| 849 | // Visit the expression | ||
| 850 |
1/2✓ Branch 5 → 6 taken 176254 times.
✗ Branch 5 → 11 not taken.
|
176254 | visit(expr); |
| 851 | |||
| 852 | // Leave expression scope | ||
| 853 | 176254 | currentScope = currentScope->parent; | |
| 854 | 176254 | } | |
| 855 | |||
| 856 | } // namespace spice::compiler | ||
| 857 |