GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 95.3% 404 / 0 / 424
Functions: 100.0% 33 / 0 / 33
Branches: 57.2% 458 / 0 / 800

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 2423 SymbolTableBuilder::SymbolTableBuilder(GlobalResourceManager &resourceManager, SourceFile *sourceFile)
17 2423 : CompilerPass(resourceManager, sourceFile), rootScope(sourceFile->globalScope.get()) {}
18
19 2423 std::any SymbolTableBuilder::visitEntry(EntryNode *node) {
20 // Initialize
21 2423 currentScope = rootScope;
22
23 // Visit children
24
2/2
✓ Branch 2 → 3 taken 2405 times.
✓ Branch 2 → 23 taken 18 times.
2423 visitChildren(node);
25
26 // Check if the main function exists
27
4/4
✓ Branch 4 → 5 taken 2402 times.
✓ Branch 4 → 7 taken 3 times.
✓ Branch 5 → 6 taken 2397 times.
✓ Branch 5 → 7 taken 5 times.
2405 const bool mainFctRequired = cliOptions.outputContainer == OutputContainer::EXECUTABLE && !cliOptions.noEntryFct;
28
6/6
✓ Branch 8 → 9 taken 532 times.
✓ Branch 8 → 19 taken 1873 times.
✓ Branch 9 → 10 taken 525 times.
✓ Branch 9 → 19 taken 7 times.
✓ Branch 10 → 11 taken 2 times.
✓ Branch 10 → 19 taken 523 times.
2405 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 2403 times.
✗ Branch 19 → 33 not taken.
4806 return nullptr;
32 }
33
34 528 std::any SymbolTableBuilder::visitMainFctDef(MainFctDefNode *node) {
35 // Visit attributes
36
2/2
✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 6 taken 527 times.
528 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 527 times.
✗ Branch 8 → 55 not taken.
✓ Branch 14 → 15 taken 1 time.
✓ Branch 14 → 23 taken 526 times.
2108 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 526 times.
✗ Branch 25 → 70 not taken.
1578 SymbolTableEntry *mainFctEntry = currentScope->insert(MAIN_FUNCTION_NAME, node);
45 526 mainFctEntry->used = true;
46
47 // Create scope for main function body
48
1/2
✓ Branch 31 → 32 taken 526 times.
✗ Branch 31 → 85 not taken.
526 const std::string &scopeId = MainFctDefNode::getScopeId();
49
1/2
✓ Branch 32 → 33 taken 526 times.
✗ Branch 32 → 83 not taken.
526 node->bodyScope = currentScope = rootScope->createChildScope(scopeId, ScopeType::FUNC_PROC_BODY, &node->codeLoc);
50 526 currentScope->isGenericScope = false;
51
52 // Declare variable for the return value in the function scope
53
1/2
✓ Branch 35 → 36 taken 526 times.
✗ Branch 35 → 76 not taken.
1578 SymbolTableEntry *resultVarEntry = node->bodyScope->insert(RETURN_VARIABLE_NAME, node);
54 526 resultVarEntry->used = true;
55
56 // Visit arguments in new scope
57
2/2
✓ Branch 41 → 42 taken 7 times.
✓ Branch 41 → 45 taken 519 times.
526 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 525 times.
✓ Branch 45 → 81 taken 1 time.
526 visit(node->body);
62
63 // Return to root scope
64 525 currentScope = rootScope;
65
66 525 hasMainFunction = true;
67
1/2
✓ Branch 47 → 48 taken 525 times.
✗ Branch 47 → 82 not taken.
1050 return nullptr;
68 526 }
69
70 19959 std::any SymbolTableBuilder::visitFctDef(FctDefNode *node) {
71 // Visit attributes
72
2/2
✓ Branch 2 → 3 taken 689 times.
✓ Branch 2 → 6 taken 19270 times.
19959 if (node->attrs)
73
1/2
✓ Branch 3 → 4 taken 689 times.
✗ Branch 3 → 98 not taken.
689 visit(node->attrs);
74
75 // Build function qualifiers
76
2/2
✓ Branch 6 → 7 taken 19333 times.
✓ Branch 6 → 36 taken 626 times.
19959 if (const QualifierLstNode *qualifierLst = node->qualifierLst; qualifierLst) {
77
2/2
✓ Branch 34 → 9 taken 24841 times.
✓ Branch 34 → 35 taken 19333 times.
63507 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
78
2/2
✓ Branch 11 → 12 taken 5511 times.
✓ Branch 11 → 13 taken 19330 times.
24841 if (qualifier->type == QualifierNode::QualifierType::TY_INLINE)
79 5511 node->qualifiers.isInline = true;
80
2/2
✓ Branch 13 → 14 taken 19218 times.
✓ Branch 13 → 15 taken 112 times.
19330 else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
81 19218 node->qualifiers.isPublic = true;
82
1/2
✓ Branch 15 → 16 taken 112 times.
✗ Branch 15 → 17 not taken.
112 else if (qualifier->type == QualifierNode::QualifierType::TY_CONST)
83 112 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 9917 times.
✓ Branch 36 → 51 taken 10042 times.
19959 if (node->isMethod) {
91
1/2
✓ Branch 38 → 39 taken 9917 times.
✗ Branch 38 → 109 not taken.
9917 const std::string scopeName = Struct::getScopeName(node->name->structName);
92
1/2
✓ Branch 40 → 41 taken 9917 times.
✗ Branch 40 → 121 not taken.
9917 node->structScope = currentScope = currentScope->getChildScope(scopeName);
93
1/2
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 49 taken 9917 times.
9917 if (!currentScope)
94 throw SemanticError(node, REFERENCED_UNDEFINED_STRUCT, "Struct '" + node->name->structName + "' could not be found");
95 9917 }
96
97 // Create scope for the function
98
2/4
✓ Branch 51 → 52 taken 19959 times.
✗ Branch 51 → 126 not taken.
✓ Branch 52 → 53 taken 19959 times.
✗ Branch 52 → 124 not taken.
19959 node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
99
6/6
✓ Branch 54 → 55 taken 17883 times.
✓ Branch 54 → 57 taken 2076 times.
✓ Branch 55 → 56 taken 9611 times.
✓ Branch 55 → 58 taken 8272 times.
✓ Branch 56 → 57 taken 2536 times.
✓ Branch 56 → 58 taken 7075 times.
19959 currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope);
100
101 // Create symbol for 'this' variable
102
2/2
✓ Branch 59 → 60 taken 9917 times.
✓ Branch 59 → 69 taken 10042 times.
19959 if (node->isMethod)
103
1/2
✓ Branch 62 → 63 taken 9917 times.
✗ Branch 62 → 129 not taken.
39668 currentScope->insert(THIS_VARIABLE_NAME, node);
104
105 // Create symbol for 'result' variable
106
1/2
✓ Branch 71 → 72 taken 19959 times.
✗ Branch 71 → 135 not taken.
59877 currentScope->insert(RETURN_VARIABLE_NAME, node);
107
108 // Create symbols for the parameters
109
2/2
✓ Branch 77 → 78 taken 14794 times.
✓ Branch 77 → 81 taken 5165 times.
19959 if (node->hasParams)
110
1/2
✓ Branch 78 → 79 taken 14794 times.
✗ Branch 78 → 139 not taken.
14794 visit(node->paramLst);
111
112 // Visit the function body
113
1/2
✓ Branch 81 → 82 taken 19959 times.
✗ Branch 81 → 140 not taken.
19959 visit(node->body);
114
115 // Leave function body scope
116 19959 currentScope = node->scope->parent;
117
118 // Insert symbol for function into the symbol table
119
1/2
✓ Branch 83 → 84 taken 19959 times.
✗ Branch 83 → 143 not taken.
39918 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 19959 const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName);
124
3/4
✓ Branch 89 → 90 taken 4423 times.
✓ Branch 89 → 91 taken 15536 times.
✓ Branch 90 → 91 taken 4423 times.
✗ Branch 90 → 92 not taken.
19959 if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry)
125 19959 sourceFile->addNameRegistryEntry(node->name->fqName, TY_FUNCTION, node->entry, currentScope, true);
126
127 // Leave the struct scope
128
2/2
✓ Branch 92 → 93 taken 9917 times.
✓ Branch 92 → 94 taken 10042 times.
19959 if (node->isMethod)
129 9917 currentScope = node->structScope->parent;
130
131
1/2
✓ Branch 94 → 95 taken 19959 times.
✗ Branch 94 → 144 not taken.
39918 return nullptr;
132 }
133
134 10560 std::any SymbolTableBuilder::visitProcDef(ProcDefNode *node) {
135 // Visit attributes
136
2/2
✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 6 taken 10559 times.
10560 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 9545 times.
✓ Branch 6 → 36 taken 1014 times.
10559 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
141
2/2
✓ Branch 34 → 9 taken 10663 times.
✓ Branch 34 → 35 taken 9545 times.
29753 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
142
2/2
✓ Branch 11 → 12 taken 1120 times.
✓ Branch 11 → 13 taken 9543 times.
10663 if (qualifier->type == QualifierNode::QualifierType::TY_INLINE)
143 1120 node->qualifiers.isInline = true;
144
2/2
✓ Branch 13 → 14 taken 9540 times.
✓ Branch 13 → 15 taken 3 times.
9543 else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
145 9540 node->qualifiers.isPublic = true;
146
1/2
✓ Branch 15 → 16 taken 3 times.
✗ Branch 15 → 17 not taken.
3 else if (qualifier->type == QualifierNode::QualifierType::TY_CONST)
147 3 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 8789 times.
✓ Branch 36 → 51 taken 1770 times.
10559 if (node->isMethod) {
155
1/2
✓ Branch 38 → 39 taken 8789 times.
✗ Branch 38 → 108 not taken.
8789 const std::string &scopeName = Struct::getScopeName(node->name->structName);
156
1/2
✓ Branch 40 → 41 taken 8789 times.
✗ Branch 40 → 120 not taken.
8789 node->structScope = currentScope = currentScope->getChildScope(scopeName);
157
2/2
✓ Branch 41 → 42 taken 1 time.
✓ Branch 41 → 49 taken 8788 times.
8789 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 8789 }
160
161 // Create scope for the procedure
162
2/4
✓ Branch 51 → 52 taken 10558 times.
✗ Branch 51 → 125 not taken.
✓ Branch 52 → 53 taken 10558 times.
✗ Branch 52 → 123 not taken.
10558 node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
163
6/6
✓ Branch 54 → 55 taken 8299 times.
✓ Branch 54 → 57 taken 2259 times.
✓ Branch 55 → 56 taken 7628 times.
✓ Branch 55 → 58 taken 671 times.
✓ Branch 56 → 57 taken 2239 times.
✓ Branch 56 → 58 taken 5389 times.
10558 currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope);
164
4/4
✓ Branch 59 → 60 taken 8788 times.
✓ Branch 59 → 63 taken 1770 times.
✓ Branch 61 → 62 taken 311 times.
✓ Branch 61 → 63 taken 8477 times.
10558 currentScope->isDtorScope = node->isMethod && node->name->name == DTOR_FUNCTION_NAME;
165
166 // Create symbol for 'this' variable
167
2/2
✓ Branch 64 → 65 taken 8788 times.
✓ Branch 64 → 74 taken 1770 times.
10558 if (node->isMethod)
168
1/2
✓ Branch 67 → 68 taken 8788 times.
✗ Branch 67 → 128 not taken.
35152 currentScope->insert(THIS_VARIABLE_NAME, node);
169
170 // Create symbols for the parameters
171
2/2
✓ Branch 74 → 75 taken 8145 times.
✓ Branch 74 → 78 taken 2413 times.
10558 if (node->hasParams)
172
1/2
✓ Branch 75 → 76 taken 8145 times.
✗ Branch 75 → 132 not taken.
8145 visit(node->paramLst);
173
174 // Visit the procedure body
175
1/2
✓ Branch 78 → 79 taken 10558 times.
✗ Branch 78 → 133 not taken.
10558 visit(node->body);
176
177 // Leave procedure body scope
178 10558 currentScope = node->scope->parent;
179
180 // Insert symbol for procedure into the symbol table
181
1/2
✓ Branch 80 → 81 taken 10558 times.
✗ Branch 80 → 136 not taken.
21116 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 10558 const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName);
186
3/4
✓ Branch 86 → 87 taken 2375 times.
✓ Branch 86 → 88 taken 8183 times.
✓ Branch 87 → 88 taken 2375 times.
✗ Branch 87 → 89 not taken.
10558 if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry)
187 10558 sourceFile->addNameRegistryEntry(node->name->fqName, TY_PROCEDURE, node->entry, currentScope, true);
188
189 // Leave the struct scope
190
2/2
✓ Branch 89 → 90 taken 8788 times.
✓ Branch 89 → 91 taken 1770 times.
10558 if (node->isMethod)
191 8788 currentScope = node->structScope->parent;
192
193 // Check if this is a constructor
194 10558 node->isCtor = node->name->nameFragments.back() == CTOR_FUNCTION_NAME;
195
196
1/2
✓ Branch 93 → 94 taken 10558 times.
✗ Branch 93 → 137 not taken.
21116 return nullptr;
197 }
198
199 /**
200 * Resolve an already-existing symbol when a struct or interface definition is being built.
201 *
202 * Handles three cases:
203 * - an in-file forward declaration of the same kind exists: upgrade it by reusing its entry, scope and typeId,
204 * un-mark the scope as forward-declared and remember the forward decl's codeLoc for later ordering checks.
205 * - a non-forward-decl symbol, or a forward decl of the wrong kind, exists: throw a duplicate-symbol error.
206 * - a matching forward declaration was imported from another file: adopt its typeId so that type identity is
207 * preserved across files (e.g. when breaking circular imports via a forward-decl-only header file).
208 *
209 * @param node Struct or interface definition node being built
210 * @param name Type name
211 * @param isStruct true for a struct definition, false for an interface definition
212 * @param entry [out] reused forward-decl entry when upgrading, otherwise left untouched
213 * @param scope [out] reused forward-decl scope when upgrading, otherwise left untouched
214 * @param typeId [in,out] adopted from a matching forward declaration when one exists
215 * @return true if an in-file forward declaration was upgraded (entry and scope reused)
216 */
217 3182 bool SymbolTableBuilder::resolveForwardDeclaration(TopLevelDefNode *node, const std::string &name, bool isStruct,
218 SymbolTableEntry *&entry, Scope *&scope, uint64_t &typeId) {
219
2/2
✓ Branch 5 → 6 taken 5 times.
✓ Branch 5 → 36 taken 3177 times.
6364 if (SymbolTableEntry *existing = rootScope->lookupStrict(name)) {
220
2/2
✓ Branch 7 → 8 taken 2 times.
✓ Branch 7 → 15 taken 3 times.
5 if (!existing->declNode->isForwardDecl())
221
3/6
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 53 not taken.
✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 51 not taken.
✓ Branch 11 → 12 taken 2 times.
✗ Branch 11 → 48 not taken.
2 throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + name + "'");
222 3 auto *fwdNode = static_cast<ForwardDeclNode *>(existing->declNode);
223
2/2
✓ Branch 15 → 16 taken 1 time.
✓ Branch 15 → 35 taken 2 times.
3 if (fwdNode->isStruct != isStruct)
224 throw SemanticError(node, DUPLICATE_SYMBOL,
225
4/8
✓ Branch 20 → 21 taken 1 time.
✗ Branch 20 → 22 not taken.
✓ Branch 23 → 24 taken 1 time.
✗ Branch 23 → 68 not taken.
✓ Branch 24 → 25 taken 1 time.
✗ Branch 24 → 66 not taken.
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 64 not taken.
2 "'" + name + "' was forward-declared as " + (fwdNode->isStruct ? "a struct" : "an interface") +
226
4/8
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 1 time.
✓ Branch 26 → 27 taken 1 time.
✗ Branch 26 → 62 not taken.
✓ Branch 27 → 28 taken 1 time.
✗ Branch 27 → 60 not taken.
✓ Branch 28 → 29 taken 1 time.
✗ Branch 28 → 57 not taken.
3 ", cannot define it as " + (isStruct ? "a struct" : "an interface"));
227 // Upgrade: reuse the forward declaration's entry, scope, and typeId
228 2 entry = existing;
229 2 scope = fwdNode->typeScope;
230 2 scope->isForwardDeclScope = false;
231 2 typeId = fwdNode->typeId;
232 // Preserve the forward declaration's codeLoc so ordering checks accept uses between forward decl and full def
233 2 existing->forwardDeclCodeLoc = &fwdNode->codeLoc;
234 // Update the entry to point to the full definition now
235 2 existing->declNode = node;
236 2 return true;
237 }
238
239 // A matching forward declaration may have been imported from another source file. Adopt its typeId.
240 3177 if (const NameRegistryEntry *importedFwd = sourceFile->getNameRegistryEntry(name);
241
2/8
✗ Branch 37 → 38 not taken.
✓ Branch 37 → 42 taken 3177 times.
✗ Branch 38 → 39 not taken.
✗ Branch 38 → 42 not taken.
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 42 not taken.
✗ Branch 43 → 44 not taken.
✓ Branch 43 → 46 taken 3177 times.
3177 importedFwd != nullptr && importedFwd->targetEntry != nullptr && importedFwd->targetEntry->declNode->isForwardDecl()) {
242 const auto *fwdNode = static_cast<const ForwardDeclNode *>(importedFwd->targetEntry->declNode);
243 if (fwdNode->isStruct == isStruct)
244 typeId = fwdNode->typeId;
245 }
246 3177 return false;
247 }
248
249 2815 std::any SymbolTableBuilder::visitStructDef(StructDefNode *node) {
250 // Visit attributes
251
2/2
✓ Branch 2 → 3 taken 106 times.
✓ Branch 2 → 6 taken 2709 times.
2815 if (node->attrs)
252
1/2
✓ Branch 3 → 4 taken 106 times.
✗ Branch 3 → 73 not taken.
106 visit(node->attrs);
253
254 // Check if this name already exists; upgrade a matching forward declaration if present
255 const bool upgradingForwardDecl =
256 2815 resolveForwardDeclaration(node, node->structName, true, node->entry, node->structScope, node->typeId);
257
258
2/2
✓ Branch 7 → 8 taken 2812 times.
✓ Branch 7 → 14 taken 2 times.
2814 if (!upgradingForwardDecl) {
259 // Create scope for the struct
260
1/2
✓ Branch 9 → 10 taken 2812 times.
✗ Branch 9 → 74 not taken.
2812 const std::string &scopeName = Struct::getScopeName(node->structName);
261
1/2
✓ Branch 11 → 12 taken 2812 times.
✗ Branch 11 → 77 not taken.
2812 node->structScope = rootScope->createChildScope(scopeName, ScopeType::STRUCT, &node->codeLoc);
262 2812 }
263 2814 currentScope = node->structScope;
264 2814 currentScope->isGenericScope = node->hasTemplateTypes;
265
266 // Insert implicit field for each interface type
267
2/2
✓ Branch 14 → 15 taken 375 times.
✓ Branch 14 → 36 taken 2439 times.
2814 if (node->hasInterfaces) {
268
2/2
✓ Branch 34 → 17 taken 375 times.
✓ Branch 34 → 35 taken 375 times.
1125 for (DataTypeNode *interfaceNode : node->interfaceTypeLst->dataTypes) {
269 375 const std::string &interfaceName = interfaceNode->baseDataType->customDataType->typeNameFragments.back();
270
1/2
✓ Branch 20 → 21 taken 375 times.
✗ Branch 20 → 82 not taken.
750 SymbolTableEntry *interfaceFieldEntry = currentScope->insert("this." + interfaceName, interfaceNode);
271 375 interfaceFieldEntry->used = true;
272 375 interfaceFieldEntry->isImplicitField = true;
273 }
274 }
275
276 // Visit children
277
2/2
✓ Branch 36 → 37 taken 2813 times.
✓ Branch 36 → 84 taken 1 time.
2814 visitChildren(node);
278
279 // Leave the struct scope
280 2813 currentScope = node->structScope->parent;
281
282 // Build struct qualifiers
283
2/2
✓ Branch 38 → 39 taken 2562 times.
✓ Branch 38 → 63 taken 251 times.
2813 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
284
2/2
✓ Branch 61 → 41 taken 2562 times.
✓ Branch 61 → 62 taken 2562 times.
7686 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
285
1/2
✓ Branch 43 → 44 taken 2562 times.
✗ Branch 43 → 47 not taken.
2562 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
286 2562 node->qualifiers.isPublic = true;
287 else
288 throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on a struct definition");
289 }
290 }
291
292 // Add the struct to the symbol table (skipped when upgrading from a forward declaration)
293
2/2
✓ Branch 63 → 64 taken 2811 times.
✓ Branch 63 → 68 taken 2 times.
2813 if (!upgradingForwardDecl)
294 5622 node->entry = rootScope->insert(node->structName, node);
295 // Register the name in the exported name registry
296 2813 sourceFile->addNameRegistryEntry(node->structName, node->typeId, node->entry, node->structScope, true);
297
298
1/2
✓ Branch 69 → 70 taken 2813 times.
✗ Branch 69 → 95 not taken.
5626 return nullptr;
299 }
300
301 367 std::any SymbolTableBuilder::visitInterfaceDef(InterfaceDefNode *node) {
302 // Visit attributes
303
2/2
✓ Branch 2 → 3 taken 153 times.
✓ Branch 2 → 6 taken 214 times.
367 if (node->attrs)
304
1/2
✓ Branch 3 → 4 taken 153 times.
✗ Branch 3 → 65 not taken.
153 visit(node->attrs);
305
306 // Check if this name already exists; upgrade a matching forward declaration if present
307 const bool upgradingForwardDecl =
308 367 resolveForwardDeclaration(node, node->interfaceName, false, node->entry, node->interfaceScope, node->typeId);
309
310
1/2
✓ Branch 7 → 8 taken 365 times.
✗ Branch 7 → 14 not taken.
365 if (!upgradingForwardDecl) {
311 // Create scope for the interface
312
1/2
✓ Branch 9 → 10 taken 365 times.
✗ Branch 9 → 66 not taken.
365 const std::string &scopeName = Interface::getScopeName(node->interfaceName);
313
1/2
✓ Branch 11 → 12 taken 365 times.
✗ Branch 11 → 69 not taken.
365 node->interfaceScope = rootScope->createChildScope(scopeName, ScopeType::INTERFACE, &node->codeLoc);
314 365 }
315 365 currentScope = node->interfaceScope;
316
317 // Visit signatures
318
2/2
✓ Branch 29 → 16 taken 1332 times.
✓ Branch 29 → 30 taken 365 times.
2062 for (SignatureNode *signature : node->signatures)
319
1/2
✓ Branch 18 → 19 taken 1332 times.
✗ Branch 18 → 72 not taken.
1332 visit(signature);
320
321 // Leave the interface scope
322 365 currentScope = node->interfaceScope->parent;
323
324 // Build interface qualifiers
325
2/2
✓ Branch 30 → 31 taken 346 times.
✓ Branch 30 → 55 taken 19 times.
365 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
326
2/2
✓ Branch 53 → 33 taken 346 times.
✓ Branch 53 → 54 taken 346 times.
1038 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
327
1/2
✓ Branch 35 → 36 taken 346 times.
✗ Branch 35 → 39 not taken.
346 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
328 346 node->qualifiers.isPublic = true;
329 else
330 throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on an interface definition");
331 }
332 }
333
334 // Add the interface to the symbol table (skipped when upgrading from a forward declaration)
335
1/2
✓ Branch 55 → 56 taken 365 times.
✗ Branch 55 → 60 not taken.
365 if (!upgradingForwardDecl)
336 730 node->entry = rootScope->insert(node->interfaceName, node);
337 // Register the name in the exported name registry
338 365 sourceFile->addNameRegistryEntry(node->interfaceName, node->typeId, node->entry, node->interfaceScope, true);
339
340
1/2
✓ Branch 61 → 62 taken 365 times.
✗ Branch 61 → 84 not taken.
730 return nullptr;
341 }
342
343 6 std::any SymbolTableBuilder::visitForwardDecl(ForwardDeclNode *node) {
344 // Visit attributes
345
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 6 taken 6 times.
6 if (node->attrs)
346 visit(node->attrs);
347
348 // Check for duplicate that is not itself a forward declaration
349
3/4
✓ Branch 6 → 7 taken 6 times.
✗ Branch 6 → 118 not taken.
✓ Branch 9 → 10 taken 1 time.
✓ Branch 9 → 30 taken 5 times.
12 if (SymbolTableEntry *existing = rootScope->lookupStrict(node->typeName)) {
350
2/4
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 118 not taken.
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 19 taken 1 time.
1 if (!existing->declNode->isForwardDecl())
351 throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->typeName + "'");
352 // Duplicate forward declaration is silently accepted (idempotent). Reuse the existing entry, scope, and typeId
353 // so that subsequent passes (e.g. the type checker) find the same fields populated as on the first node.
354 1 auto *fwdNode = static_cast<ForwardDeclNode *>(existing->declNode);
355
1/2
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 27 taken 1 time.
1 if (fwdNode->isStruct != node->isStruct)
356 throw SemanticError(node, DUPLICATE_SYMBOL,
357 "Forward declaration of '" + node->typeName + "' conflicts with an earlier forward declaration of a different kind");
358 1 node->entry = existing;
359 1 node->typeScope = fwdNode->typeScope;
360 1 node->typeId = fwdNode->typeId;
361
1/2
✓ Branch 27 → 28 taken 1 time.
✗ Branch 27 → 96 not taken.
2 return nullptr;
362 }
363
364 // Create a placeholder scope for the forward-declared type
365 const std::string &scopeName =
366
4/14
✓ Branch 30 → 31 taken 5 times.
✗ Branch 30 → 33 not taken.
✓ Branch 32 → 35 taken 5 times.
✗ Branch 32 → 97 not taken.
✗ Branch 34 → 35 not taken.
✗ Branch 34 → 97 not taken.
✗ Branch 35 → 36 not taken.
✓ Branch 35 → 37 taken 5 times.
✓ Branch 37 → 38 taken 5 times.
✗ Branch 37 → 39 not taken.
✗ Branch 97 → 98 not taken.
✗ Branch 97 → 99 not taken.
✗ Branch 101 → 102 not taken.
✗ Branch 101 → 103 not taken.
5 node->isStruct ? Struct::getScopeName(node->typeName) : Interface::getScopeName(node->typeName);
367
1/2
✓ Branch 39 → 40 taken 5 times.
✗ Branch 39 → 41 not taken.
5 const ScopeType st = node->isStruct ? ScopeType::STRUCT : ScopeType::INTERFACE;
368
1/2
✓ Branch 42 → 43 taken 5 times.
✗ Branch 42 → 116 not taken.
5 node->typeScope = rootScope->createChildScope(scopeName, st, &node->codeLoc);
369 5 node->typeScope->isForwardDeclScope = true;
370
371 // Build qualifiers
372
2/2
✓ Branch 43 → 44 taken 1 time.
✓ Branch 43 → 68 taken 4 times.
5 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
373
2/2
✓ Branch 66 → 46 taken 1 time.
✓ Branch 66 → 67 taken 1 time.
3 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
374
1/2
✓ Branch 48 → 49 taken 1 time.
✗ Branch 48 → 52 not taken.
1 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
375 1 node->qualifiers.isPublic = true;
376 else
377 throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT,
378 "Cannot use this qualifier on a forward declaration");
379 }
380 }
381
382 // Register the placeholder symbol
383
1/2
✓ Branch 68 → 69 taken 5 times.
✗ Branch 68 → 116 not taken.
5 node->entry = rootScope->insert(node->typeName, node);
384
1/2
✓ Branch 71 → 72 taken 5 times.
✗ Branch 71 → 116 not taken.
5 sourceFile->addNameRegistryEntry(node->typeName, node->typeId, node->entry, node->typeScope, true);
385
386
1/2
✓ Branch 72 → 73 taken 5 times.
✗ Branch 72 → 115 not taken.
5 return nullptr;
387 5 }
388
389 370 std::any SymbolTableBuilder::visitEnumDef(EnumDefNode *node) {
390 // Check if this name already exists
391
2/2
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 369 times.
740 if (rootScope->lookupStrict(node->enumName))
392
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 + "'");
393
394 // Create scope for the enum
395 369 node->enumScope = currentScope =
396
2/4
✓ Branch 13 → 14 taken 369 times.
✗ Branch 13 → 62 not taken.
✓ Branch 14 → 15 taken 369 times.
✗ Branch 14 → 60 not taken.
369 rootScope->createChildScope(ENUM_SCOPE_PREFIX + node->enumName, ScopeType::ENUM, &node->codeLoc);
397
398 // Visit items
399
2/2
✓ Branch 16 → 17 taken 368 times.
✓ Branch 16 → 63 taken 1 time.
369 visit(node->itemLst);
400
401 // Leave the enum scope
402 368 currentScope = node->enumScope->parent;
403
404 // Build enum qualifiers
405
2/2
✓ Branch 18 → 19 taken 332 times.
✓ Branch 18 → 43 taken 36 times.
368 if (node->qualifierLst) {
406
2/2
✓ Branch 41 → 21 taken 332 times.
✓ Branch 41 → 42 taken 332 times.
996 for (const QualifierNode *qualifier : node->qualifierLst->qualifiers) {
407
1/2
✓ Branch 23 → 24 taken 332 times.
✗ Branch 23 → 27 not taken.
332 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
408 332 node->qualifiers.isPublic = true;
409 else
410 throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on an enum definition");
411 }
412 }
413
414 // Add the enum to the symbol table
415 368 node->entry = rootScope->insert(node->enumName, node);
416 // Register the name in the exported name registry
417 368 sourceFile->addNameRegistryEntry(node->enumName, node->typeId, node->entry, node->enumScope, true);
418
419
1/2
✓ Branch 47 → 48 taken 368 times.
✗ Branch 47 → 74 not taken.
736 return nullptr;
420 }
421
422 1928 std::any SymbolTableBuilder::visitGenericTypeDef(GenericTypeDefNode *node) {
423 // Check if this name already exists
424
2/2
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 1927 times.
3856 if (rootScope->lookupStrict(node->typeName))
425
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 + "'");
426
427 // Create the generic type to the symbol table
428 1927 node->entry = rootScope->insert(node->typeName, node);
429 1927 node->entry->used = true; // Generic types are always used
430
431
1/2
✓ Branch 16 → 17 taken 1927 times.
✗ Branch 16 → 29 not taken.
3854 return nullptr;
432 }
433
434 342 std::any SymbolTableBuilder::visitAliasDef(AliasDefNode *node) {
435 // Check if this name already exists
436
3/4
✓ Branch 2 → 3 taken 342 times.
✗ Branch 2 → 73 not taken.
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 341 times.
684 if (rootScope->lookupStrict(node->aliasName))
437
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 + "'");
438
439 // Build alias qualifiers
440
2/2
✓ Branch 13 → 14 taken 104 times.
✓ Branch 13 → 38 taken 237 times.
341 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
441
2/2
✓ Branch 36 → 16 taken 104 times.
✓ Branch 36 → 37 taken 104 times.
312 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
442
1/2
✓ Branch 18 → 19 taken 104 times.
✗ Branch 18 → 22 not taken.
104 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
443 104 node->qualifiers.isPublic = true;
444 else
445 throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on an alias definition");
446 }
447 }
448
449 // Add the alias to the symbol table
450
1/2
✓ Branch 38 → 39 taken 341 times.
✗ Branch 38 → 73 not taken.
341 node->entry = rootScope->insert(node->aliasName, node);
451 // Register the name in the exported name registry
452
1/2
✓ Branch 41 → 42 taken 341 times.
✗ Branch 41 → 73 not taken.
341 sourceFile->addNameRegistryEntry(node->aliasName, node->typeId, node->entry, rootScope, true);
453
454 // Add another symbol for the aliased type container
455
1/2
✓ Branch 42 → 43 taken 341 times.
✗ Branch 42 → 73 not taken.
341 const std::string aliasedTypeContainerName = node->aliasName + ALIAS_CONTAINER_SUFFIX;
456
1/2
✓ Branch 43 → 44 taken 341 times.
✗ Branch 43 → 71 not taken.
341 node->aliasedTypeContainerEntry = rootScope->insert(aliasedTypeContainerName, node);
457
458
1/2
✓ Branch 46 → 47 taken 341 times.
✗ Branch 46 → 70 not taken.
682 return nullptr;
459 341 }
460
461 2370 std::any SymbolTableBuilder::visitGlobalVarDef(GlobalVarDefNode *node) {
462 // Check if this name already exists
463
2/2
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 2369 times.
4740 if (rootScope->lookupStrict(node->varName))
464
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 + "'");
465
466 // Check if global already exists in an imported source file
467
5/8
✓ Branch 13 → 14 taken 2369 times.
✗ Branch 13 → 56 not taken.
✓ Branch 14 → 15 taken 2369 times.
✗ Branch 14 → 56 not taken.
✓ Branch 15 → 16 taken 2369 times.
✗ Branch 15 → 56 not taken.
✓ Branch 29 → 17 taken 4321 times.
✓ Branch 29 → 30 taken 2368 times.
6689 for (const auto &dependency : sourceFile->dependencies | std::views::values)
468
3/4
✓ Branch 18 → 19 taken 4321 times.
✗ Branch 18 → 56 not taken.
✓ Branch 19 → 20 taken 1 time.
✓ Branch 19 → 27 taken 4320 times.
4321 if (dependency->exportedNameRegistry.contains(node->varName))
469
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");
470
471 // Add the global to the symbol table
472 2368 node->entry = rootScope->insert(node->varName, node);
473 // Register the name in the exported name registry
474 2368 sourceFile->addNameRegistryEntry(node->varName, TY_INVALID, node->entry, currentScope, true);
475
476
1/2
✓ Branch 34 → 35 taken 2368 times.
✗ Branch 34 → 57 not taken.
4736 return nullptr;
477 }
478
479 2967 std::any SymbolTableBuilder::visitExtDecl(ExtDeclNode *node) {
480 // Visit attributes
481
2/2
✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 6 taken 2966 times.
2967 if (node->attrs)
482
1/2
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 31 not taken.
1 visit(node->attrs);
483
484 // Check if this name already exists
485
2/2
✓ Branch 9 → 10 taken 1 time.
✓ Branch 9 → 17 taken 2966 times.
5934 if (rootScope->lookupStrict(node->extFunctionName))
486
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 + "'");
487
488 // Create scope for the external function (this is required in case of forceSubstantiation in FunctionManager::matchFunction)
489
2/4
✓ Branch 17 → 18 taken 2966 times.
✗ Branch 17 → 43 not taken.
✓ Branch 18 → 19 taken 2966 times.
✗ Branch 18 → 41 not taken.
2966 rootScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
490
491 // Add the external declaration to the symbol table
492 2966 node->entry = rootScope->insert(node->extFunctionName, node);
493 // Register the name in the exported name registry
494
2/2
✓ Branch 23 → 24 taken 1968 times.
✓ Branch 23 → 25 taken 998 times.
2966 const uint64_t typeId = node->returnType ? TY_FUNCTION : TY_PROCEDURE;
495 2966 sourceFile->addNameRegistryEntry(node->extFunctionName, typeId, node->entry, rootScope, /*keepNewOnCollision=*/true);
496
497
1/2
✓ Branch 27 → 28 taken 2966 times.
✗ Branch 27 → 44 not taken.
5932 return nullptr;
498 }
499
500 5345 std::any SymbolTableBuilder::visitUnsafeBlock(UnsafeBlockNode *node) {
501 // Create scope for the unsafe block body
502 5345 node->bodyScope = currentScope =
503
2/4
✓ Branch 2 → 3 taken 5345 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 5345 times.
✗ Branch 3 → 11 not taken.
5345 currentScope->createChildScope(node->getScopeId(), ScopeType::UNSAFE_BODY, &node->body->codeLoc);
504
505 // Visit body
506
1/2
✓ Branch 5 → 6 taken 5345 times.
✗ Branch 5 → 14 not taken.
5345 visit(node->body);
507
508 // Leave thread body scope
509 5345 currentScope = node->bodyScope->parent;
510
511
1/2
✓ Branch 7 → 8 taken 5345 times.
✗ Branch 7 → 15 not taken.
10690 return nullptr;
512 }
513
514 2833 std::any SymbolTableBuilder::visitForLoop(ForLoopNode *node) {
515 // Create scope for the loop body
516
2/4
✓ Branch 2 → 3 taken 2833 times.
✗ Branch 2 → 15 not taken.
✓ Branch 3 → 4 taken 2833 times.
✗ Branch 3 → 13 not taken.
2833 node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FOR_BODY, &node->body->codeLoc);
517
518 // Visit loop variable declaration
519
1/2
✓ Branch 5 → 6 taken 2833 times.
✗ Branch 5 → 16 not taken.
2833 visit(node->initDecl);
520
521 // Visit body
522
1/2
✓ Branch 7 → 8 taken 2833 times.
✗ Branch 7 → 17 not taken.
2833 visit(node->body);
523
524 // Leave for body scope
525 2833 currentScope = node->bodyScope->parent;
526
527
1/2
✓ Branch 9 → 10 taken 2833 times.
✗ Branch 9 → 18 not taken.
5666 return nullptr;
528 }
529
530 471 std::any SymbolTableBuilder::visitForeachLoop(ForeachLoopNode *node) {
531 // Create scope for the loop body
532 471 node->bodyScope = currentScope =
533
2/4
✓ Branch 2 → 3 taken 471 times.
✗ Branch 2 → 19 not taken.
✓ Branch 3 → 4 taken 471 times.
✗ Branch 3 → 17 not taken.
471 currentScope->createChildScope(node->getScopeId(), ScopeType::FOREACH_BODY, &node->body->codeLoc);
534
535 // Visit index variable declaration
536
2/2
✓ Branch 5 → 6 taken 58 times.
✓ Branch 5 → 9 taken 413 times.
471 if (node->idxVarDecl)
537
1/2
✓ Branch 6 → 7 taken 58 times.
✗ Branch 6 → 20 not taken.
58 visit(node->idxVarDecl);
538
539 // Visit item variable declaration
540
1/2
✓ Branch 9 → 10 taken 471 times.
✗ Branch 9 → 21 not taken.
471 visit(node->itemVarDecl);
541
542 // Visit body
543
1/2
✓ Branch 11 → 12 taken 471 times.
✗ Branch 11 → 22 not taken.
471 visit(node->body);
544
545 // Leave foreach body scope
546 471 currentScope = node->bodyScope->parent;
547
548
1/2
✓ Branch 13 → 14 taken 471 times.
✗ Branch 13 → 23 not taken.
942 return nullptr;
549 }
550
551 1667 std::any SymbolTableBuilder::visitWhileLoop(WhileLoopNode *node) {
552 // Create scope for the loop body
553 1667 node->bodyScope = currentScope =
554
2/4
✓ Branch 2 → 3 taken 1667 times.
✗ Branch 2 → 15 not taken.
✓ Branch 3 → 4 taken 1667 times.
✗ Branch 3 → 13 not taken.
1667 currentScope->createChildScope(node->getScopeId(), ScopeType::WHILE_BODY, &node->body->codeLoc);
555
556 // Visit condition
557
1/2
✓ Branch 5 → 6 taken 1667 times.
✗ Branch 5 → 16 not taken.
1667 visit(node->condition);
558
559 // Visit body
560
1/2
✓ Branch 7 → 8 taken 1667 times.
✗ Branch 7 → 17 not taken.
1667 visit(node->body);
561
562 // Leave while body scope
563 1667 currentScope = node->bodyScope->parent;
564
565
1/2
✓ Branch 9 → 10 taken 1667 times.
✗ Branch 9 → 18 not taken.
3334 return nullptr;
566 }
567
568 16 std::any SymbolTableBuilder::visitDoWhileLoop(DoWhileLoopNode *node) {
569 // Create scope for the loop body
570 16 node->bodyScope = currentScope =
571
2/4
✓ Branch 2 → 3 taken 16 times.
✗ Branch 2 → 15 not taken.
✓ Branch 3 → 4 taken 16 times.
✗ Branch 3 → 13 not taken.
16 currentScope->createChildScope(node->getScopeId(), ScopeType::WHILE_BODY, &node->body->codeLoc);
572
573 // Visit condition
574
1/2
✓ Branch 5 → 6 taken 16 times.
✗ Branch 5 → 16 not taken.
16 visit(node->condition);
575
576 // Visit body
577
1/2
✓ Branch 7 → 8 taken 16 times.
✗ Branch 7 → 17 not taken.
16 visit(node->body);
578
579 // Leave do-while body scope
580 16 currentScope = node->bodyScope->parent;
581
582
1/2
✓ Branch 9 → 10 taken 16 times.
✗ Branch 9 → 18 not taken.
32 return nullptr;
583 }
584
585 10887 std::any SymbolTableBuilder::visitIfStmt(IfStmtNode *node) {
586 // Create scope for the then body
587 10887 node->thenBodyScope = currentScope =
588
2/4
✓ Branch 2 → 3 taken 10887 times.
✗ Branch 2 → 27 not taken.
✓ Branch 3 → 4 taken 10887 times.
✗ Branch 3 → 25 not taken.
10887 currentScope->createChildScope(node->getScopeId(), ScopeType::IF_ELSE_BODY, &node->thenBody->codeLoc);
589
590 // Visit condition
591
1/2
✓ Branch 5 → 6 taken 10887 times.
✗ Branch 5 → 28 not taken.
10887 visit(node->condition);
592
593 // Visit then body (manifestations do not exist yet, so both branches are always visited here)
594
1/2
✓ Branch 8 → 9 taken 10887 times.
✗ Branch 8 → 12 not taken.
10887 if (node->doCompileThenBranch(manIdx))
595
1/2
✓ Branch 9 → 10 taken 10887 times.
✗ Branch 9 → 29 not taken.
10887 visit(node->thenBody);
596
597 // Leave then body scope
598 10887 currentScope = node->thenBodyScope->parent;
599
600 // Visit else stmt
601
5/6
✓ Branch 13 → 14 taken 10887 times.
✗ Branch 13 → 16 not taken.
✓ Branch 14 → 15 taken 952 times.
✓ Branch 14 → 16 taken 9935 times.
✓ Branch 17 → 18 taken 952 times.
✓ Branch 17 → 21 taken 9935 times.
10887 if (node->doCompileElseBranch(manIdx) && node->elseStmt)
602
1/2
✓ Branch 18 → 19 taken 952 times.
✗ Branch 18 → 30 not taken.
952 visit(node->elseStmt);
603
604
1/2
✓ Branch 21 → 22 taken 10887 times.
✗ Branch 21 → 31 not taken.
21774 return nullptr;
605 }
606
607 952 std::any SymbolTableBuilder::visitElseStmt(ElseStmtNode *node) {
608 // Visit if statement in the case of an else if branch
609
2/2
✓ Branch 2 → 3 taken 376 times.
✓ Branch 2 → 8 taken 576 times.
952 if (node->isElseIf) {
610
1/2
✓ Branch 3 → 4 taken 376 times.
✗ Branch 3 → 17 not taken.
376 visit(node->ifStmt);
611
1/2
✓ Branch 5 → 6 taken 376 times.
✗ Branch 5 → 18 not taken.
752 return nullptr;
612 }
613
614 // Create scope for the else body
615 576 node->elseBodyScope = currentScope =
616
2/4
✓ Branch 8 → 9 taken 576 times.
✗ Branch 8 → 21 not taken.
✓ Branch 9 → 10 taken 576 times.
✗ Branch 9 → 19 not taken.
576 currentScope->createChildScope(node->getScopeId(), ScopeType::IF_ELSE_BODY, &node->body->codeLoc);
617
618 // Visit else body
619
1/2
✓ Branch 11 → 12 taken 576 times.
✗ Branch 11 → 22 not taken.
576 visit(node->body);
620
621 // Leave else body scope
622 576 currentScope = node->elseBodyScope->parent;
623
624
1/2
✓ Branch 13 → 14 taken 576 times.
✗ Branch 13 → 23 not taken.
1152 return nullptr;
625 }
626
627 662 std::any SymbolTableBuilder::visitCaseBranch(CaseBranchNode *node) {
628 // Create scope for the case branch
629
2/4
✓ Branch 2 → 3 taken 662 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 662 times.
✗ Branch 3 → 11 not taken.
662 node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::CASE_BODY, &node->body->codeLoc);
630
631 // Visit case body
632
1/2
✓ Branch 5 → 6 taken 662 times.
✗ Branch 5 → 14 not taken.
662 visit(node->body);
633
634 // Leave case body scope
635 662 currentScope = node->bodyScope->parent;
636
637
1/2
✓ Branch 7 → 8 taken 662 times.
✗ Branch 7 → 15 not taken.
1324 return nullptr;
638 }
639
640 69 std::any SymbolTableBuilder::visitDefaultBranch(DefaultBranchNode *node) {
641 // Create scope for the default branch
642 69 node->bodyScope = currentScope =
643
2/4
✓ Branch 2 → 3 taken 69 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 69 times.
✗ Branch 3 → 11 not taken.
69 currentScope->createChildScope(node->getScopeId(), ScopeType::DEFAULT_BODY, &node->body->codeLoc);
644
645 // Visit default body
646
1/2
✓ Branch 5 → 6 taken 69 times.
✗ Branch 5 → 14 not taken.
69 visit(node->body);
647
648 // Leave default body scope
649 69 currentScope = node->bodyScope->parent;
650
651
1/2
✓ Branch 7 → 8 taken 69 times.
✗ Branch 7 → 15 not taken.
138 return nullptr;
652 }
653
654 43 std::any SymbolTableBuilder::visitAnonymousBlockStmt(AnonymousBlockStmtNode *node) {
655 // Create scope for the anonymous block body
656 43 node->bodyScope = currentScope =
657
2/4
✓ Branch 2 → 3 taken 43 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 43 times.
✗ Branch 3 → 11 not taken.
43 currentScope->createChildScope(node->getScopeId(), ScopeType::ANONYMOUS_BLOCK_BODY, &node->body->codeLoc);
658
659 // Visit body
660
1/2
✓ Branch 5 → 6 taken 43 times.
✗ Branch 5 → 14 not taken.
43 visit(node->body);
661
662 // Leave anonymous block body scope
663 43 currentScope = node->bodyScope->parent;
664
665
1/2
✓ Branch 7 → 8 taken 43 times.
✗ Branch 7 → 15 not taken.
86 return nullptr;
666 }
667
668 4910 std::any SymbolTableBuilder::visitEnumItem(EnumItemNode *node) {
669 // Check if enum item already exists in the same scope.
670
3/4
✓ Branch 2 → 3 taken 4910 times.
✗ Branch 2 → 42 not taken.
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 4909 times.
9820 if (currentScope->lookupStrict(node->itemName))
671
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");
672
673 // Add enum item entry to symbol table
674
1/2
✓ Branch 13 → 14 taken 4909 times.
✗ Branch 13 → 42 not taken.
4909 SymbolTableEntry *enumItemEntry = currentScope->insert(node->itemName, node);
675
676 // Add external registry entry
677
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 4909 times.
4909 assert(node->enumDef != nullptr);
678
2/4
✓ Branch 18 → 19 taken 4909 times.
✗ Branch 18 → 38 not taken.
✓ Branch 19 → 20 taken 4909 times.
✗ Branch 19 → 36 not taken.
4909 const std::string name = node->enumDef->enumName + SCOPE_ACCESS_TOKEN + node->itemName;
679
1/2
✓ Branch 21 → 22 taken 4909 times.
✗ Branch 21 → 40 not taken.
4909 sourceFile->addNameRegistryEntry(name, TY_INT, enumItemEntry, currentScope, true);
680
681
1/2
✓ Branch 22 → 23 taken 4909 times.
✗ Branch 22 → 39 not taken.
9818 return nullptr;
682 4909 }
683
684 5295 std::any SymbolTableBuilder::visitField(FieldNode *node) {
685 // Check if field already exists in the same scope.
686
2/2
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 5294 times.
10590 if (currentScope->lookupStrict(node->fieldName))
687
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");
688
689 // Add field entry to symbol table
690 5294 currentScope->insert(node->fieldName, node);
691
692
1/2
✓ Branch 16 → 17 taken 5294 times.
✗ Branch 16 → 29 not taken.
10588 return nullptr;
693 }
694
695 1332 std::any SymbolTableBuilder::visitSignature(SignatureNode *node) {
696 // Build signature qualifiers
697
2/2
✓ Branch 2 → 3 taken 735 times.
✓ Branch 2 → 32 taken 597 times.
1332 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
698
2/2
✓ Branch 30 → 5 taken 871 times.
✓ Branch 30 → 31 taken 735 times.
2341 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
699
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 871 times.
871 if (qualifier->type == QualifierNode::QualifierType::TY_INLINE)
700 node->signatureQualifiers.isInline = true;
701
2/2
✓ Branch 9 → 10 taken 735 times.
✓ Branch 9 → 11 taken 136 times.
871 else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
702 735 node->signatureQualifiers.isPublic = true;
703
1/2
✓ Branch 11 → 12 taken 136 times.
✗ Branch 11 → 13 not taken.
136 else if (qualifier->type == QualifierNode::QualifierType::TY_CONST)
704 136 node->signatureQualifiers.isConst = true;
705 else
706 throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on a signature definition");
707 }
708 }
709
710 // Add signature entry to symbol table. We append the code location to disambiguate overloaded signatures
711 // (e.g. an interface declaring `getName()` and `getName(bool)`).
712
1/2
✓ Branch 32 → 33 taken 1332 times.
✗ Branch 32 → 53 not taken.
2664 node->entry = currentScope->insert(Function::getSymbolTableEntryName(node->methodName, node->codeLoc), node);
713
714
1/2
✓ Branch 37 → 38 taken 1332 times.
✗ Branch 37 → 54 not taken.
2664 return nullptr;
715 }
716
717 51134 std::any SymbolTableBuilder::visitDeclStmt(DeclStmtNode *node) {
718 // Check if variable already exists in the same scope.
719
2/2
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 51133 times.
102268 if (currentScope->lookupStrict(node->varName))
720
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");
721
722 // Visit the right side
723
2/2
✓ Branch 13 → 14 taken 18304 times.
✓ Branch 13 → 17 taken 32829 times.
51133 if (node->hasAssignment)
724
1/2
✓ Branch 14 → 15 taken 18304 times.
✗ Branch 14 → 33 not taken.
18304 visit(node->assignExpr);
725
726 // Add variable entry to symbol table
727 51133 SymbolTableEntry *varEntry = currentScope->insert(node->varName, node);
728 51133 varEntry->isParam = node->isFctParam;
729
730
1/2
✓ Branch 20 → 21 taken 51133 times.
✗ Branch 20 → 34 not taken.
102266 return nullptr;
731 }
732
733 686 std::any SymbolTableBuilder::visitModAttr(ModAttrNode *node) {
734 // Visit attributes
735
2/2
✓ Branch 2 → 3 taken 685 times.
✓ Branch 2 → 126 taken 1 time.
686 visitChildren(node);
736
737 // Retrieve attributes
738 685 const AttrLstNode *attrs = node->attrLst;
739
740 // Collect linker flags
741 685 std::vector<const CompileTimeValue *> linkerFlagValues;
742 // core.linker.flag
743
2/4
✓ Branch 6 → 7 taken 685 times.
✗ Branch 6 → 129 not taken.
✓ Branch 7 → 8 taken 685 times.
✗ Branch 7 → 127 not taken.
1370 std::vector<const CompileTimeValue *> values = attrs->getAttrValuesByName(ATTR_CORE_LINKER_FLAG);
744
1/2
✓ Branch 16 → 17 taken 685 times.
✗ Branch 16 → 133 not taken.
1370 linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end());
745 // core.linux.linker.flag
746 685 const llvm::Triple &targetTriple = sourceFile->targetMachine->getTargetTriple();
747
2/2
✓ Branch 20 → 21 taken 675 times.
✓ Branch 20 → 37 taken 10 times.
685 if (targetTriple.isOSLinux()) {
748
2/4
✓ Branch 23 → 24 taken 675 times.
✗ Branch 23 → 137 not taken.
✓ Branch 24 → 25 taken 675 times.
✗ Branch 24 → 135 not taken.
1350 values = attrs->getAttrValuesByName(ATTR_CORE_LINUX_LINKER_FLAG);
749
1/2
✓ Branch 35 → 36 taken 675 times.
✗ Branch 35 → 142 not taken.
1350 linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end());
750 }
751 // core.darwin.linker.flag
752
3/4
✓ Branch 37 → 38 taken 685 times.
✗ Branch 37 → 187 not taken.
✓ Branch 38 → 39 taken 5 times.
✓ Branch 38 → 55 taken 680 times.
685 if (targetTriple.isOSDarwin()) {
753
2/4
✓ Branch 41 → 42 taken 5 times.
✗ Branch 41 → 146 not taken.
✓ Branch 42 → 43 taken 5 times.
✗ Branch 42 → 144 not taken.
10 values = attrs->getAttrValuesByName(ATTR_CORE_DARWIN_LINKER_FLAG);
754
1/2
✓ Branch 53 → 54 taken 5 times.
✗ Branch 53 → 151 not taken.
10 linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end());
755 }
756 // core.windows.linker.flag
757
2/2
✓ Branch 56 → 57 taken 5 times.
✓ Branch 56 → 73 taken 680 times.
685 if (targetTriple.isOSWindows()) {
758
2/4
✓ Branch 59 → 60 taken 5 times.
✗ Branch 59 → 155 not taken.
✓ Branch 60 → 61 taken 5 times.
✗ Branch 60 → 153 not taken.
10 values = attrs->getAttrValuesByName(ATTR_CORE_WINDOWS_LINKER_FLAG);
759
1/2
✓ Branch 71 → 72 taken 5 times.
✗ Branch 71 → 160 not taken.
10 linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end());
760 }
761
2/2
✓ Branch 89 → 75 taken 1383 times.
✓ Branch 89 → 90 taken 685 times.
2753 for (const CompileTimeValue *value : linkerFlagValues) {
762
1/2
✓ Branch 77 → 78 taken 1383 times.
✗ Branch 77 → 162 not taken.
1383 const std::string &flag = resourceManager.compileTimeStringValues.at(value->stringValueOffset);
763
1/2
✓ Branch 78 → 79 taken 1383 times.
✗ Branch 78 → 162 not taken.
1383 resourceManager.linker.addLinkerFlag(flag);
764
1/2
✓ Branch 79 → 80 taken 1383 times.
✗ Branch 79 → 162 not taken.
1383 sourceFile->sourceLinkerFlags.push_back(flag);
765 }
766
767 // core.linker.additionalSource
768
4/6
✓ Branch 90 → 91 taken 685 times.
✗ Branch 90 → 165 not taken.
✓ Branch 91 → 92 taken 685 times.
✗ Branch 91 → 163 not taken.
✓ Branch 116 → 94 taken 12 times.
✓ Branch 116 → 117 taken 684 times.
1381 for (const CompileTimeValue *value : attrs->getAttrValuesByName(ATTR_CORE_LINKER_ADDITIONAL_SOURCE)) {
769
1/2
✓ Branch 96 → 97 taken 12 times.
✗ Branch 96 → 178 not taken.
12 const std::string &stringValue = resourceManager.compileTimeStringValues.at(value->stringValueOffset);
770
3/6
✓ Branch 97 → 98 taken 12 times.
✗ Branch 97 → 172 not taken.
✓ Branch 98 → 99 taken 12 times.
✗ Branch 98 → 169 not taken.
✓ Branch 99 → 100 taken 12 times.
✗ Branch 99 → 167 not taken.
12 const std::filesystem::path additionalSourcePath = sourceFile->filePath.parent_path() / stringValue;
771
3/4
✓ Branch 102 → 103 taken 12 times.
✗ Branch 102 → 175 not taken.
✓ Branch 103 → 104 taken 11 times.
✓ Branch 103 → 173 taken 1 time.
13 resourceManager.linker.addAdditionalSourcePath(additionalSourcePath);
772
1/2
✓ Branch 105 → 106 taken 11 times.
✗ Branch 105 → 176 not taken.
11 sourceFile->sourceAdditionalSourcePaths.push_back(additionalSourcePath);
773 698 }
774
775
1/2
✓ Branch 120 → 121 taken 684 times.
✗ Branch 120 → 186 not taken.
1368 return nullptr;
776 686 }
777
778 3367 std::any SymbolTableBuilder::visitAttr(AttrNode *node) {
779 // Check if this attribute exists
780
1/2
✓ Branch 2 → 3 taken 3367 times.
✗ Branch 2 → 63 not taken.
3367 const auto it = ATTR_CONFIGS.find(node->key);
781
2/2
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 13 taken 3366 times.
3367 if (it == ATTR_CONFIGS.end())
782
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 + "'");
783
784 // Check if the target is correct
785 3366 const auto &[target, type] = it->second;
786
2/2
✓ Branch 14 → 15 taken 1 time.
✓ Branch 14 → 22 taken 3365 times.
3366 if ((node->target & target) == 0)
787
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");
788
789 // Check if a value is present
790
4/4
✓ Branch 22 → 23 taken 702 times.
✓ Branch 22 → 31 taken 2663 times.
✓ Branch 23 → 24 taken 1 time.
✓ Branch 23 → 31 taken 701 times.
3365 if (!node->value && type != AttrNode::AttrType::TYPE_BOOL)
791
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");
792
793
1/2
✓ Branch 31 → 32 taken 3364 times.
✗ Branch 31 → 62 not taken.
6728 return nullptr;
794 }
795
796 22 std::any SymbolTableBuilder::visitLambdaFunc(LambdaFuncNode *node) {
797 // Create scope for the lambda body
798 22 const CodeLoc &codeLoc = node->body->codeLoc;
799
2/4
✓ Branch 2 → 3 taken 22 times.
✗ Branch 2 → 47 not taken.
✓ Branch 3 → 4 taken 22 times.
✗ Branch 3 → 45 not taken.
22 node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::LAMBDA_BODY, &codeLoc);
800 // Requires capturing because the LLVM IR will end up in a separate function
801 22 currentScope->symbolTable.setCapturingRequired();
802 // Set to async scope if this is an async lambda
803
4/18
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 13 taken 22 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 22 times.
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 19 taken 22 times.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 27 taken 22 times.
✗ Branch 48 → 49 not taken.
✗ Branch 48 → 50 not taken.
✗ Branch 52 → 53 not taken.
✗ Branch 52 → 55 not taken.
22 if (node->lambdaAttr && node->lambdaAttr->attrLst->hasAttr(ATTR_ASYNC))
804 node->bodyScope->isAsyncScope = node->lambdaAttr->attrLst->getAttrValueByName(ATTR_ASYNC)->boolValue;
805
806 // Create symbol for 'result' variable
807
1/2
✓ Branch 29 → 30 taken 22 times.
✗ Branch 29 → 65 not taken.
66 currentScope->insert(RETURN_VARIABLE_NAME, node);
808
809 // Create symbols for the parameters
810
2/2
✓ Branch 35 → 36 taken 17 times.
✓ Branch 35 → 39 taken 5 times.
22 if (node->hasParams)
811
1/2
✓ Branch 36 → 37 taken 17 times.
✗ Branch 36 → 69 not taken.
17 visit(node->paramLst);
812
813 // Visit body
814
1/2
✓ Branch 39 → 40 taken 22 times.
✗ Branch 39 → 70 not taken.
22 visit(node->body);
815
816 // Leave anonymous block body scope
817 22 currentScope = node->bodyScope->parent;
818
819
1/2
✓ Branch 41 → 42 taken 22 times.
✗ Branch 41 → 71 not taken.
44 return nullptr;
820 }
821
822 72 std::any SymbolTableBuilder::visitLambdaProc(LambdaProcNode *node) {
823 // Create scope for the lambda body
824 72 const CodeLoc &codeLoc = node->body->codeLoc;
825
2/4
✓ Branch 2 → 3 taken 72 times.
✗ Branch 2 → 39 not taken.
✓ Branch 3 → 4 taken 72 times.
✗ Branch 3 → 37 not taken.
72 node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::LAMBDA_BODY, &codeLoc);
826 // Requires capturing because the LLVM IR will end up in a separate function
827 72 currentScope->symbolTable.setCapturingRequired();
828 // Set to async scope if this is an async lambda
829
11/18
✓ Branch 6 → 7 taken 6 times.
✓ Branch 6 → 13 taken 66 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 66 times.
✓ Branch 16 → 17 taken 6 times.
✓ Branch 16 → 19 taken 66 times.
✓ Branch 19 → 20 taken 6 times.
✓ Branch 19 → 27 taken 66 times.
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 42 not taken.
✗ Branch 44 → 45 not taken.
✗ Branch 44 → 47 not taken.
84 if (node->lambdaAttr && node->lambdaAttr->attrLst->hasAttr(ATTR_ASYNC))
830
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;
831
832 // Create symbols for the parameters
833
2/2
✓ Branch 27 → 28 taken 58 times.
✓ Branch 27 → 31 taken 14 times.
72 if (node->hasParams)
834
1/2
✓ Branch 28 → 29 taken 58 times.
✗ Branch 28 → 55 not taken.
58 visit(node->paramLst);
835
836 // Visit body
837
1/2
✓ Branch 31 → 32 taken 72 times.
✗ Branch 31 → 56 not taken.
72 visit(node->body);
838
839 // Leave anonymous block body scope
840 72 currentScope = node->bodyScope->parent;
841
842
1/2
✓ Branch 33 → 34 taken 72 times.
✗ Branch 33 → 57 not taken.
144 return nullptr;
843 }
844
845 1 std::any SymbolTableBuilder::visitLambdaExpr(LambdaExprNode *node) {
846 // Create scope for the anonymous block body
847 1 const CodeLoc &codeLoc = node->lambdaExpr->codeLoc;
848
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);
849 // Requires capturing because the LLVM IR will end up in a separate function
850 1 currentScope->symbolTable.setCapturingRequired();
851
852 // Create symbols for the parameters
853
1/2
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 10 not taken.
1 if (node->hasParams)
854
1/2
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 19 not taken.
1 visit(node->paramLst);
855
856 // Visit lambda expression
857
1/2
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 20 not taken.
1 visit(node->lambdaExpr);
858
859 // Leave anonymous block body scope
860 1 currentScope = node->bodyScope->parent;
861
862
1/2
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 21 not taken.
2 return nullptr;
863 }
864
865 } // namespace spice::compiler
866