GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 96.9% 377 / 0 / 389
Functions: 100.0% 32 / 0 / 32
Branches: 58.9% 445 / 0 / 756

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 6079 SymbolTableBuilder::SymbolTableBuilder(GlobalResourceManager &resourceManager, SourceFile *sourceFile)
17 6079 : CompilerPass(resourceManager, sourceFile), rootScope(sourceFile->globalScope.get()) {}
18
19 6079 std::any SymbolTableBuilder::visitEntry(EntryNode *node) {
20 // Initialize
21 6079 currentScope = rootScope;
22
23 // Visit children
24
2/2
✓ Branch 2 → 3 taken 6041 times.
✓ Branch 2 → 23 taken 38 times.
6079 visitChildren(node);
25
26 // Check if the main function exists
27
4/4
✓ Branch 4 → 5 taken 6035 times.
✓ Branch 4 → 7 taken 6 times.
✓ Branch 5 → 6 taken 6023 times.
✓ Branch 5 → 7 taken 12 times.
6041 const bool mainFctRequired = cliOptions.outputContainer == OutputContainer::EXECUTABLE && !cliOptions.noEntryFct;
28
6/6
✓ Branch 8 → 9 taken 1224 times.
✓ Branch 8 → 19 taken 4817 times.
✓ Branch 9 → 10 taken 1208 times.
✓ Branch 9 → 19 taken 16 times.
✓ Branch 10 → 11 taken 4 times.
✓ Branch 10 → 19 taken 1204 times.
6041 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 6037 times.
✗ Branch 19 → 33 not taken.
12074 return nullptr;
32 }
33
34 1216 std::any SymbolTableBuilder::visitMainFctDef(MainFctDefNode *node) {
35 // Visit attributes
36
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 6 taken 1214 times.
1216 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 1214 times.
✗ Branch 8 → 55 not taken.
✓ Branch 14 → 15 taken 2 times.
✓ Branch 14 → 23 taken 1212 times.
4856 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 1212 times.
✗ Branch 25 → 70 not taken.
3636 SymbolTableEntry *mainFctEntry = currentScope->insert(MAIN_FUNCTION_NAME, node);
45 1212 mainFctEntry->used = true;
46
47 // Create scope for main function body
48
1/2
✓ Branch 31 → 32 taken 1212 times.
✗ Branch 31 → 85 not taken.
1212 const std::string &scopeId = MainFctDefNode::getScopeId();
49
1/2
✓ Branch 32 → 33 taken 1212 times.
✗ Branch 32 → 83 not taken.
1212 node->bodyScope = currentScope = rootScope->createChildScope(scopeId, ScopeType::FUNC_PROC_BODY, &node->codeLoc);
50 1212 currentScope->isGenericScope = false;
51
52 // Declare variable for the return value in the function scope
53
1/2
✓ Branch 35 → 36 taken 1212 times.
✗ Branch 35 → 76 not taken.
3636 SymbolTableEntry *resultVarEntry = node->bodyScope->insert(RETURN_VARIABLE_NAME, node);
54 1212 resultVarEntry->used = true;
55
56 // Visit arguments in new scope
57
2/2
✓ Branch 41 → 42 taken 14 times.
✓ Branch 41 → 45 taken 1198 times.
1212 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 1210 times.
✓ Branch 45 → 81 taken 2 times.
1212 visit(node->body);
62
63 // Return to root scope
64 1210 currentScope = rootScope;
65
66 1210 hasMainFunction = true;
67
1/2
✓ Branch 47 → 48 taken 1210 times.
✗ Branch 47 → 82 not taken.
2420 return nullptr;
68 1212 }
69
70 48728 std::any SymbolTableBuilder::visitFctDef(FctDefNode *node) {
71 // Visit attributes
72
2/2
✓ Branch 2 → 3 taken 1612 times.
✓ Branch 2 → 6 taken 47116 times.
48728 if (node->attrs)
73
1/2
✓ Branch 3 → 4 taken 1612 times.
✗ Branch 3 → 98 not taken.
1612 visit(node->attrs);
74
75 // Build function qualifiers
76
2/2
✓ Branch 6 → 7 taken 46597 times.
✓ Branch 6 → 36 taken 2131 times.
48728 if (const QualifierLstNode *qualifierLst = node->qualifierLst; qualifierLst) {
77
2/2
✓ Branch 34 → 9 taken 62046 times.
✓ Branch 34 → 35 taken 46597 times.
155240 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
78
2/2
✓ Branch 11 → 12 taken 15441 times.
✓ Branch 11 → 13 taken 46605 times.
62046 if (qualifier->type == QualifierNode::QualifierType::TY_INLINE)
79 15441 node->qualifiers.isInline = true;
80
2/2
✓ Branch 13 → 14 taken 46341 times.
✓ Branch 13 → 15 taken 264 times.
46605 else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
81 46341 node->qualifiers.isPublic = true;
82
1/2
✓ Branch 15 → 16 taken 264 times.
✗ Branch 15 → 17 not taken.
264 else if (qualifier->type == QualifierNode::QualifierType::TY_CONST)
83 264 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 24905 times.
✓ Branch 36 → 51 taken 23823 times.
48728 if (node->isMethod) {
91
1/2
✓ Branch 38 → 39 taken 24905 times.
✗ Branch 38 → 109 not taken.
24905 const std::string scopeName = Struct::getScopeName(node->name->structName);
92
1/2
✓ Branch 40 → 41 taken 24905 times.
✗ Branch 40 → 121 not taken.
24905 node->structScope = currentScope = currentScope->getChildScope(scopeName);
93
1/2
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 49 taken 24905 times.
24905 if (!currentScope)
94 throw SemanticError(node, REFERENCED_UNDEFINED_STRUCT, "Struct '" + node->name->structName + "' could not be found");
95 24905 }
96
97 // Create scope for the function
98
2/4
✓ Branch 51 → 52 taken 48728 times.
✗ Branch 51 → 126 not taken.
✓ Branch 52 → 53 taken 48728 times.
✗ Branch 52 → 124 not taken.
48728 node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
99
6/6
✓ Branch 54 → 55 taken 43796 times.
✓ Branch 54 → 57 taken 4932 times.
✓ Branch 55 → 56 taken 24216 times.
✓ Branch 55 → 58 taken 19580 times.
✓ Branch 56 → 57 taken 6545 times.
✓ Branch 56 → 58 taken 17671 times.
48728 currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope);
100
101 // Create symbol for 'this' variable
102
2/2
✓ Branch 59 → 60 taken 24905 times.
✓ Branch 59 → 69 taken 23823 times.
48728 if (node->isMethod)
103
1/2
✓ Branch 62 → 63 taken 24905 times.
✗ Branch 62 → 129 not taken.
99620 currentScope->insert(THIS_VARIABLE_NAME, node);
104
105 // Create symbol for 'result' variable
106
1/2
✓ Branch 71 → 72 taken 48728 times.
✗ Branch 71 → 135 not taken.
146184 currentScope->insert(RETURN_VARIABLE_NAME, node);
107
108 // Create symbols for the parameters
109
2/2
✓ Branch 77 → 78 taken 35398 times.
✓ Branch 77 → 81 taken 13330 times.
48728 if (node->hasParams)
110
1/2
✓ Branch 78 → 79 taken 35398 times.
✗ Branch 78 → 139 not taken.
35398 visit(node->paramLst);
111
112 // Visit the function body
113
1/2
✓ Branch 81 → 82 taken 48728 times.
✗ Branch 81 → 140 not taken.
48728 visit(node->body);
114
115 // Leave function body scope
116 48728 currentScope = node->scope->parent;
117
118 // Insert symbol for function into the symbol table
119
1/2
✓ Branch 83 → 84 taken 48728 times.
✗ Branch 83 → 143 not taken.
97456 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 48728 const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName);
124
3/4
✓ Branch 89 → 90 taken 10253 times.
✓ Branch 89 → 91 taken 38475 times.
✓ Branch 90 → 91 taken 10253 times.
✗ Branch 90 → 92 not taken.
48728 if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry)
125 48728 sourceFile->addNameRegistryEntry(node->name->fqName, TY_FUNCTION, node->entry, currentScope, true);
126
127 // Leave the struct scope
128
2/2
✓ Branch 92 → 93 taken 24905 times.
✓ Branch 92 → 94 taken 23823 times.
48728 if (node->isMethod)
129 24905 currentScope = node->structScope->parent;
130
131
1/2
✓ Branch 94 → 95 taken 48728 times.
✗ Branch 94 → 144 not taken.
97456 return nullptr;
132 }
133
134 29256 std::any SymbolTableBuilder::visitProcDef(ProcDefNode *node) {
135 // Visit attributes
136
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 6 taken 29254 times.
29256 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 24645 times.
✓ Branch 6 → 36 taken 4609 times.
29254 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
141
2/2
✓ Branch 34 → 9 taken 28466 times.
✓ Branch 34 → 35 taken 24645 times.
77756 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
142
2/2
✓ Branch 11 → 12 taken 3831 times.
✓ Branch 11 → 13 taken 24635 times.
28466 if (qualifier->type == QualifierNode::QualifierType::TY_INLINE)
143 3831 node->qualifiers.isInline = true;
144
2/2
✓ Branch 13 → 14 taken 24627 times.
✓ Branch 13 → 15 taken 8 times.
24635 else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
145 24627 node->qualifiers.isPublic = true;
146
1/2
✓ Branch 15 → 16 taken 8 times.
✗ Branch 15 → 17 not taken.
8 else if (qualifier->type == QualifierNode::QualifierType::TY_CONST)
147 8 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 23940 times.
✓ Branch 36 → 51 taken 5314 times.
29254 if (node->isMethod) {
155
1/2
✓ Branch 38 → 39 taken 23940 times.
✗ Branch 38 → 108 not taken.
23940 const std::string &scopeName = Struct::getScopeName(node->name->structName);
156
1/2
✓ Branch 40 → 41 taken 23940 times.
✗ Branch 40 → 120 not taken.
23940 node->structScope = currentScope = currentScope->getChildScope(scopeName);
157
2/2
✓ Branch 41 → 42 taken 2 times.
✓ Branch 41 → 49 taken 23938 times.
23940 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 23940 }
160
161 // Create scope for the procedure
162
2/4
✓ Branch 51 → 52 taken 29252 times.
✗ Branch 51 → 125 not taken.
✓ Branch 52 → 53 taken 29252 times.
✗ Branch 52 → 123 not taken.
29252 node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
163
6/6
✓ Branch 54 → 55 taken 24210 times.
✓ Branch 54 → 57 taken 5042 times.
✓ Branch 55 → 56 taken 21271 times.
✓ Branch 55 → 58 taken 2939 times.
✓ Branch 56 → 57 taken 5798 times.
✓ Branch 56 → 58 taken 15473 times.
29252 currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope);
164
4/4
✓ Branch 59 → 60 taken 23938 times.
✓ Branch 59 → 63 taken 5314 times.
✓ Branch 61 → 62 taken 996 times.
✓ Branch 61 → 63 taken 22942 times.
29252 currentScope->isDtorScope = node->isMethod && node->name->name == DTOR_FUNCTION_NAME;
165
166 // Create symbol for 'this' variable
167
2/2
✓ Branch 64 → 65 taken 23938 times.
✓ Branch 64 → 74 taken 5314 times.
29252 if (node->isMethod)
168
1/2
✓ Branch 67 → 68 taken 23938 times.
✗ Branch 67 → 128 not taken.
95752 currentScope->insert(THIS_VARIABLE_NAME, node);
169
170 // Create symbols for the parameters
171
2/2
✓ Branch 74 → 75 taken 21629 times.
✓ Branch 74 → 78 taken 7623 times.
29252 if (node->hasParams)
172
1/2
✓ Branch 75 → 76 taken 21629 times.
✗ Branch 75 → 132 not taken.
21629 visit(node->paramLst);
173
174 // Visit the procedure body
175
1/2
✓ Branch 78 → 79 taken 29252 times.
✗ Branch 78 → 133 not taken.
29252 visit(node->body);
176
177 // Leave procedure body scope
178 29252 currentScope = node->scope->parent;
179
180 // Insert symbol for procedure into the symbol table
181
1/2
✓ Branch 80 → 81 taken 29252 times.
✗ Branch 80 → 136 not taken.
58504 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 29252 const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName);
186
3/4
✓ Branch 86 → 87 taken 6048 times.
✓ Branch 86 → 88 taken 23204 times.
✓ Branch 87 → 88 taken 6048 times.
✗ Branch 87 → 89 not taken.
29252 if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry)
187 29252 sourceFile->addNameRegistryEntry(node->name->fqName, TY_PROCEDURE, node->entry, currentScope, true);
188
189 // Leave the struct scope
190
2/2
✓ Branch 89 → 90 taken 23938 times.
✓ Branch 89 → 91 taken 5314 times.
29252 if (node->isMethod)
191 23938 currentScope = node->structScope->parent;
192
193 // Check if this is a constructor
194 29252 node->isCtor = node->name->nameFragments.back() == CTOR_FUNCTION_NAME;
195
196
1/2
✓ Branch 93 → 94 taken 29252 times.
✗ Branch 93 → 137 not taken.
58504 return nullptr;
197 }
198
199 7463 std::any SymbolTableBuilder::visitStructDef(StructDefNode *node) {
200 // Visit attributes
201
2/2
✓ Branch 2 → 3 taken 248 times.
✓ Branch 2 → 6 taken 7215 times.
7463 if (node->attrs)
202
1/2
✓ Branch 3 → 4 taken 248 times.
✗ Branch 3 → 79 not taken.
248 visit(node->attrs);
203
204 // Check if this name already exists
205
3/4
✓ Branch 6 → 7 taken 7463 times.
✗ Branch 6 → 110 not taken.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 17 taken 7461 times.
14926 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 7461 times.
✗ Branch 18 → 89 not taken.
7461 const std::string &scopeName = Struct::getScopeName(node->structName);
210
1/2
✓ Branch 20 → 21 taken 7461 times.
✗ Branch 20 → 108 not taken.
7461 node->structScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::STRUCT, &node->codeLoc);
211 7461 currentScope->isGenericScope = node->hasTemplateTypes;
212
213 // Insert implicit field for each interface type
214
2/2
✓ Branch 21 → 22 taken 742 times.
✓ Branch 21 → 43 taken 6719 times.
7461 if (node->hasInterfaces) {
215
2/2
✓ Branch 41 → 24 taken 742 times.
✓ Branch 41 → 42 taken 742 times.
2226 for (DataTypeNode *interfaceNode : node->interfaceTypeLst->dataTypes) {
216 742 const std::string &interfaceName = interfaceNode->baseDataType->customDataType->typeNameFragments.back();
217
1/2
✓ Branch 27 → 28 taken 742 times.
✗ Branch 27 → 94 not taken.
1484 SymbolTableEntry *interfaceFieldEntry = currentScope->insert("this." + interfaceName, interfaceNode);
218 742 interfaceFieldEntry->used = true;
219 742 interfaceFieldEntry->isImplicitField = true;
220 }
221 }
222
223 // Visit children
224
2/2
✓ Branch 43 → 44 taken 7459 times.
✓ Branch 43 → 96 taken 2 times.
7461 visitChildren(node);
225
226 // Leave the struct scope
227 7459 currentScope = node->structScope->parent;
228
229 // Build struct qualifiers
230
2/2
✓ Branch 45 → 46 taken 5947 times.
✓ Branch 45 → 70 taken 1512 times.
7459 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
231
2/2
✓ Branch 68 → 48 taken 5947 times.
✓ Branch 68 → 69 taken 5947 times.
17841 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
232
1/2
✓ Branch 50 → 51 taken 5947 times.
✗ Branch 50 → 54 not taken.
5947 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
233 5947 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 7459 times.
✗ Branch 70 → 108 not taken.
7459 node->entry = rootScope->insert(node->structName, node);
241 // Register the name in the exported name registry
242
1/2
✓ Branch 73 → 74 taken 7459 times.
✗ Branch 73 → 108 not taken.
7459 sourceFile->addNameRegistryEntry(node->structName, node->typeId, node->entry, node->structScope, true);
243
244
1/2
✓ Branch 74 → 75 taken 7459 times.
✗ Branch 74 → 107 not taken.
14918 return nullptr;
245 7461 }
246
247 805 std::any SymbolTableBuilder::visitInterfaceDef(InterfaceDefNode *node) {
248 // Visit attributes
249
2/2
✓ Branch 2 → 3 taken 370 times.
✓ Branch 2 → 6 taken 435 times.
805 if (node->attrs)
250
1/2
✓ Branch 3 → 4 taken 370 times.
✗ Branch 3 → 71 not taken.
370 visit(node->attrs);
251
252 // Check if this name already exists
253
3/4
✓ Branch 6 → 7 taken 805 times.
✗ Branch 6 → 99 not taken.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 17 taken 803 times.
1610 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 803 times.
✗ Branch 18 → 81 not taken.
803 const std::string &scopeName = Interface::getScopeName(node->interfaceName);
258
1/2
✓ Branch 20 → 21 taken 803 times.
✗ Branch 20 → 97 not taken.
803 node->interfaceScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::INTERFACE, &node->codeLoc);
259
260 // Visit signatures
261
2/2
✓ Branch 36 → 23 taken 4867 times.
✓ Branch 36 → 37 taken 803 times.
6473 for (SignatureNode *signature : node->signatures)
262
1/2
✓ Branch 25 → 26 taken 4867 times.
✗ Branch 25 → 84 not taken.
4867 visit(signature);
263
264 // Leave the interface scope
265 803 currentScope = node->interfaceScope->parent;
266
267 // Build interface qualifiers
268
2/2
✓ Branch 37 → 38 taken 763 times.
✓ Branch 37 → 62 taken 40 times.
803 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
269
2/2
✓ Branch 60 → 40 taken 763 times.
✓ Branch 60 → 61 taken 763 times.
2289 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
270
1/2
✓ Branch 42 → 43 taken 763 times.
✗ Branch 42 → 46 not taken.
763 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
271 763 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 803 times.
✗ Branch 62 → 97 not taken.
803 node->entry = rootScope->insert(node->interfaceName, node);
279 // Register the name in the exported name registry
280
1/2
✓ Branch 65 → 66 taken 803 times.
✗ Branch 65 → 97 not taken.
803 sourceFile->addNameRegistryEntry(node->interfaceName, node->typeId, node->entry, node->interfaceScope, true);
281
282
1/2
✓ Branch 66 → 67 taken 803 times.
✗ Branch 66 → 96 not taken.
1606 return nullptr;
283 803 }
284
285 68 std::any SymbolTableBuilder::visitUnionDef(UnionDefNode *node) {
286 // Visit attributes
287
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 6 taken 68 times.
68 if (node->attrs)
288 visit(node->attrs);
289
290 // Check if this name already exists
291
2/4
✓ Branch 6 → 7 taken 68 times.
✗ Branch 6 → 84 not taken.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 17 taken 68 times.
136 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 68 times.
✗ Branch 18 → 67 not taken.
68 const std::string &scopeName = Union::getScopeName(node->unionName);
296
1/2
✓ Branch 20 → 21 taken 68 times.
✗ Branch 20 → 82 not taken.
68 node->unionScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::UNION, &node->codeLoc);
297 68 currentScope->isGenericScope = node->hasTemplateTypes;
298
299 // Visit children
300
2/2
✓ Branch 21 → 22 taken 66 times.
✓ Branch 21 → 70 taken 2 times.
68 visitChildren(node);
301
302 // Leave the union scope
303 66 currentScope = node->unionScope->parent;
304
305 // Build union qualifiers
306
2/2
✓ Branch 23 → 24 taken 32 times.
✓ Branch 23 → 48 taken 34 times.
66 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
307
2/2
✓ Branch 46 → 26 taken 32 times.
✓ Branch 46 → 47 taken 30 times.
94 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
308
2/2
✓ Branch 28 → 29 taken 30 times.
✓ Branch 28 → 32 taken 2 times.
32 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
309 30 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 64 times.
✗ Branch 48 → 82 not taken.
64 node->entry = rootScope->insert(node->unionName, node);
317 // Register the name in the exported name registry
318
1/2
✓ Branch 51 → 52 taken 64 times.
✗ Branch 51 → 82 not taken.
64 sourceFile->addNameRegistryEntry(node->unionName, node->typeId, node->entry, node->unionScope, true);
319
320
1/2
✓ Branch 52 → 53 taken 64 times.
✗ Branch 52 → 81 not taken.
128 return nullptr;
321 68 }
322
323 1232 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 1230 times.
2464 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 1230 node->enumScope = currentScope =
330
2/4
✓ Branch 13 → 14 taken 1230 times.
✗ Branch 13 → 62 not taken.
✓ Branch 14 → 15 taken 1230 times.
✗ Branch 14 → 60 not taken.
1230 rootScope->createChildScope(ENUM_SCOPE_PREFIX + node->enumName, ScopeType::ENUM, &node->codeLoc);
331
332 // Visit items
333
2/2
✓ Branch 16 → 17 taken 1228 times.
✓ Branch 16 → 63 taken 2 times.
1230 visit(node->itemLst);
334
335 // Leave the enum scope
336 1228 currentScope = node->enumScope->parent;
337
338 // Build enum qualifiers
339
2/2
✓ Branch 18 → 19 taken 1149 times.
✓ Branch 18 → 43 taken 79 times.
1228 if (node->qualifierLst) {
340
2/2
✓ Branch 41 → 21 taken 1149 times.
✓ Branch 41 → 42 taken 1149 times.
3447 for (const QualifierNode *qualifier : node->qualifierLst->qualifiers) {
341
1/2
✓ Branch 23 → 24 taken 1149 times.
✗ Branch 23 → 27 not taken.
1149 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
342 1149 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 1228 node->entry = rootScope->insert(node->enumName, node);
350 // Register the name in the exported name registry
351 1228 sourceFile->addNameRegistryEntry(node->enumName, node->typeId, node->entry, node->enumScope, true);
352
353
1/2
✓ Branch 47 → 48 taken 1228 times.
✗ Branch 47 → 74 not taken.
2456 return nullptr;
354 }
355
356 4499 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 4497 times.
8998 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 4497 node->entry = rootScope->insert(node->typeName, node);
363 4497 node->entry->used = true; // Generic types are always used
364
365
1/2
✓ Branch 16 → 17 taken 4497 times.
✗ Branch 16 → 29 not taken.
8994 return nullptr;
366 }
367
368 707 std::any SymbolTableBuilder::visitAliasDef(AliasDefNode *node) {
369 // Check if this name already exists
370
3/4
✓ Branch 2 → 3 taken 707 times.
✗ Branch 2 → 73 not taken.
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 705 times.
1414 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 221 times.
✓ Branch 13 → 38 taken 484 times.
705 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
375
2/2
✓ Branch 36 → 16 taken 221 times.
✓ Branch 36 → 37 taken 221 times.
663 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
376
1/2
✓ Branch 18 → 19 taken 221 times.
✗ Branch 18 → 22 not taken.
221 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
377 221 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 705 times.
✗ Branch 38 → 73 not taken.
705 node->entry = rootScope->insert(node->aliasName, node);
385 // Register the name in the exported name registry
386
1/2
✓ Branch 41 → 42 taken 705 times.
✗ Branch 41 → 73 not taken.
705 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 705 times.
✗ Branch 42 → 73 not taken.
705 const std::string aliasedTypeContainerName = node->aliasName + ALIAS_CONTAINER_SUFFIX;
390
1/2
✓ Branch 43 → 44 taken 705 times.
✗ Branch 43 → 71 not taken.
705 node->aliasedTypeContainerEntry = rootScope->insert(aliasedTypeContainerName, node);
391
392
1/2
✓ Branch 46 → 47 taken 705 times.
✗ Branch 46 → 70 not taken.
1410 return nullptr;
393 705 }
394
395 5945 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 5943 times.
11890 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 5943 times.
✗ Branch 13 → 56 not taken.
✓ Branch 14 → 15 taken 5943 times.
✗ Branch 14 → 56 not taken.
✓ Branch 15 → 16 taken 5943 times.
✗ Branch 15 → 56 not taken.
✓ Branch 29 → 17 taken 10958 times.
✓ Branch 29 → 30 taken 5941 times.
16899 for (const auto &dependency : sourceFile->dependencies | std::views::values)
402
3/4
✓ Branch 18 → 19 taken 10958 times.
✗ Branch 18 → 56 not taken.
✓ Branch 19 → 20 taken 2 times.
✓ Branch 19 → 27 taken 10956 times.
10958 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 5941 node->entry = rootScope->insert(node->varName, node);
407 // Register the name in the exported name registry
408 5941 sourceFile->addNameRegistryEntry(node->varName, TY_INVALID, node->entry, currentScope, true);
409
410
1/2
✓ Branch 34 → 35 taken 5941 times.
✗ Branch 34 → 57 not taken.
11882 return nullptr;
411 }
412
413 8887 std::any SymbolTableBuilder::visitExtDecl(ExtDeclNode *node) {
414 // Visit attributes
415
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 6 taken 8885 times.
8887 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 8885 times.
17774 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 8885 times.
✗ Branch 17 → 43 not taken.
✓ Branch 18 → 19 taken 8885 times.
✗ Branch 18 → 41 not taken.
8885 rootScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
424
425 // Add the external declaration to the symbol table
426 8885 node->entry = rootScope->insert(node->extFunctionName, node);
427 // Register the name in the exported name registry
428
2/2
✓ Branch 23 → 24 taken 7268 times.
✓ Branch 23 → 25 taken 1617 times.
8885 const uint64_t typeId = node->returnType ? TY_FUNCTION : TY_PROCEDURE;
429 8885 sourceFile->addNameRegistryEntry(node->extFunctionName, typeId, node->entry, rootScope, /*keepNewOnCollision=*/true);
430
431
1/2
✓ Branch 27 → 28 taken 8885 times.
✗ Branch 27 → 44 not taken.
17770 return nullptr;
432 }
433
434 17404 std::any SymbolTableBuilder::visitUnsafeBlock(UnsafeBlockNode *node) {
435 // Create scope for the unsafe block body
436 17404 node->bodyScope = currentScope =
437
2/4
✓ Branch 2 → 3 taken 17404 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 17404 times.
✗ Branch 3 → 11 not taken.
17404 currentScope->createChildScope(node->getScopeId(), ScopeType::UNSAFE_BODY, &node->body->codeLoc);
438
439 // Visit body
440
1/2
✓ Branch 5 → 6 taken 17404 times.
✗ Branch 5 → 14 not taken.
17404 visit(node->body);
441
442 // Leave thread body scope
443 17404 currentScope = node->bodyScope->parent;
444
445
1/2
✓ Branch 7 → 8 taken 17404 times.
✗ Branch 7 → 15 not taken.
34808 return nullptr;
446 }
447
448 6412 std::any SymbolTableBuilder::visitForLoop(ForLoopNode *node) {
449 // Create scope for the loop body
450
2/4
✓ Branch 2 → 3 taken 6412 times.
✗ Branch 2 → 15 not taken.
✓ Branch 3 → 4 taken 6412 times.
✗ Branch 3 → 13 not taken.
6412 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 6412 times.
✗ Branch 5 → 16 not taken.
6412 visit(node->initDecl);
454
455 // Visit body
456
1/2
✓ Branch 7 → 8 taken 6412 times.
✗ Branch 7 → 17 not taken.
6412 visit(node->body);
457
458 // Leave for body scope
459 6412 currentScope = node->bodyScope->parent;
460
461
1/2
✓ Branch 9 → 10 taken 6412 times.
✗ Branch 9 → 18 not taken.
12824 return nullptr;
462 }
463
464 819 std::any SymbolTableBuilder::visitForeachLoop(ForeachLoopNode *node) {
465 // Create scope for the loop body
466 819 node->bodyScope = currentScope =
467
2/4
✓ Branch 2 → 3 taken 819 times.
✗ Branch 2 → 19 not taken.
✓ Branch 3 → 4 taken 819 times.
✗ Branch 3 → 17 not taken.
819 currentScope->createChildScope(node->getScopeId(), ScopeType::FOREACH_BODY, &node->body->codeLoc);
468
469 // Visit index variable declaration
470
2/2
✓ Branch 5 → 6 taken 116 times.
✓ Branch 5 → 9 taken 703 times.
819 if (node->idxVarDecl)
471
1/2
✓ Branch 6 → 7 taken 116 times.
✗ Branch 6 → 20 not taken.
116 visit(node->idxVarDecl);
472
473 // Visit item variable declaration
474
1/2
✓ Branch 9 → 10 taken 819 times.
✗ Branch 9 → 21 not taken.
819 visit(node->itemVarDecl);
475
476 // Visit body
477
1/2
✓ Branch 11 → 12 taken 819 times.
✗ Branch 11 → 22 not taken.
819 visit(node->body);
478
479 // Leave foreach body scope
480 819 currentScope = node->bodyScope->parent;
481
482
1/2
✓ Branch 13 → 14 taken 819 times.
✗ Branch 13 → 23 not taken.
1638 return nullptr;
483 }
484
485 2987 std::any SymbolTableBuilder::visitWhileLoop(WhileLoopNode *node) {
486 // Create scope for the loop body
487 2987 node->bodyScope = currentScope =
488
2/4
✓ Branch 2 → 3 taken 2987 times.
✗ Branch 2 → 15 not taken.
✓ Branch 3 → 4 taken 2987 times.
✗ Branch 3 → 13 not taken.
2987 currentScope->createChildScope(node->getScopeId(), ScopeType::WHILE_BODY, &node->body->codeLoc);
489
490 // Visit condition
491
1/2
✓ Branch 5 → 6 taken 2987 times.
✗ Branch 5 → 16 not taken.
2987 visit(node->condition);
492
493 // Visit body
494
1/2
✓ Branch 7 → 8 taken 2987 times.
✗ Branch 7 → 17 not taken.
2987 visit(node->body);
495
496 // Leave while body scope
497 2987 currentScope = node->bodyScope->parent;
498
499
1/2
✓ Branch 9 → 10 taken 2987 times.
✗ Branch 9 → 18 not taken.
5974 return nullptr;
500 }
501
502 33 std::any SymbolTableBuilder::visitDoWhileLoop(DoWhileLoopNode *node) {
503 // Create scope for the loop body
504 33 node->bodyScope = currentScope =
505
2/4
✓ Branch 2 → 3 taken 33 times.
✗ Branch 2 → 15 not taken.
✓ Branch 3 → 4 taken 33 times.
✗ Branch 3 → 13 not taken.
33 currentScope->createChildScope(node->getScopeId(), ScopeType::WHILE_BODY, &node->body->codeLoc);
506
507 // Visit condition
508
1/2
✓ Branch 5 → 6 taken 33 times.
✗ Branch 5 → 16 not taken.
33 visit(node->condition);
509
510 // Visit body
511
1/2
✓ Branch 7 → 8 taken 33 times.
✗ Branch 7 → 17 not taken.
33 visit(node->body);
512
513 // Leave do-while body scope
514 33 currentScope = node->bodyScope->parent;
515
516
1/2
✓ Branch 9 → 10 taken 33 times.
✗ Branch 9 → 18 not taken.
66 return nullptr;
517 }
518
519 37620 std::any SymbolTableBuilder::visitIfStmt(IfStmtNode *node) {
520 // Create scope for the then body
521 37620 node->thenBodyScope = currentScope =
522
2/4
✓ Branch 2 → 3 taken 37620 times.
✗ Branch 2 → 27 not taken.
✓ Branch 3 → 4 taken 37620 times.
✗ Branch 3 → 25 not taken.
37620 currentScope->createChildScope(node->getScopeId(), ScopeType::IF_ELSE_BODY, &node->thenBody->codeLoc);
523
524 // Visit condition
525
1/2
✓ Branch 5 → 6 taken 37620 times.
✗ Branch 5 → 28 not taken.
37620 visit(node->condition);
526
527 // Visit then body (manifestations do not exist yet, so both branches are always visited here)
528
1/2
✓ Branch 8 → 9 taken 37620 times.
✗ Branch 8 → 12 not taken.
37620 if (node->doCompileThenBranch(manIdx))
529
1/2
✓ Branch 9 → 10 taken 37620 times.
✗ Branch 9 → 29 not taken.
37620 visit(node->thenBody);
530
531 // Leave then body scope
532 37620 currentScope = node->thenBodyScope->parent;
533
534 // Visit else stmt
535
5/6
✓ Branch 13 → 14 taken 37620 times.
✗ Branch 13 → 16 not taken.
✓ Branch 14 → 15 taken 2933 times.
✓ Branch 14 → 16 taken 34687 times.
✓ Branch 17 → 18 taken 2933 times.
✓ Branch 17 → 21 taken 34687 times.
37620 if (node->doCompileElseBranch(manIdx) && node->elseStmt)
536
1/2
✓ Branch 18 → 19 taken 2933 times.
✗ Branch 18 → 30 not taken.
2933 visit(node->elseStmt);
537
538
1/2
✓ Branch 21 → 22 taken 37620 times.
✗ Branch 21 → 31 not taken.
75240 return nullptr;
539 }
540
541 2933 std::any SymbolTableBuilder::visitElseStmt(ElseStmtNode *node) {
542 // Visit if statement in the case of an else if branch
543
2/2
✓ Branch 2 → 3 taken 1185 times.
✓ Branch 2 → 8 taken 1748 times.
2933 if (node->isElseIf) {
544
1/2
✓ Branch 3 → 4 taken 1185 times.
✗ Branch 3 → 17 not taken.
1185 visit(node->ifStmt);
545
1/2
✓ Branch 5 → 6 taken 1185 times.
✗ Branch 5 → 18 not taken.
2370 return nullptr;
546 }
547
548 // Create scope for the else body
549 1748 node->elseBodyScope = currentScope =
550
2/4
✓ Branch 8 → 9 taken 1748 times.
✗ Branch 8 → 21 not taken.
✓ Branch 9 → 10 taken 1748 times.
✗ Branch 9 → 19 not taken.
1748 currentScope->createChildScope(node->getScopeId(), ScopeType::IF_ELSE_BODY, &node->body->codeLoc);
551
552 // Visit else body
553
1/2
✓ Branch 11 → 12 taken 1748 times.
✗ Branch 11 → 22 not taken.
1748 visit(node->body);
554
555 // Leave else body scope
556 1748 currentScope = node->elseBodyScope->parent;
557
558
1/2
✓ Branch 13 → 14 taken 1748 times.
✗ Branch 13 → 23 not taken.
3496 return nullptr;
559 }
560
561 1539 std::any SymbolTableBuilder::visitCaseBranch(CaseBranchNode *node) {
562 // Create scope for the case branch
563
2/4
✓ Branch 2 → 3 taken 1539 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 1539 times.
✗ Branch 3 → 11 not taken.
1539 node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::CASE_BODY, &node->body->codeLoc);
564
565 // Visit case body
566
1/2
✓ Branch 5 → 6 taken 1539 times.
✗ Branch 5 → 14 not taken.
1539 visit(node->body);
567
568 // Leave case body scope
569 1539 currentScope = node->bodyScope->parent;
570
571
1/2
✓ Branch 7 → 8 taken 1539 times.
✗ Branch 7 → 15 not taken.
3078 return nullptr;
572 }
573
574 157 std::any SymbolTableBuilder::visitDefaultBranch(DefaultBranchNode *node) {
575 // Create scope for the default branch
576 157 node->bodyScope = currentScope =
577
2/4
✓ Branch 2 → 3 taken 157 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 157 times.
✗ Branch 3 → 11 not taken.
157 currentScope->createChildScope(node->getScopeId(), ScopeType::DEFAULT_BODY, &node->body->codeLoc);
578
579 // Visit default body
580
1/2
✓ Branch 5 → 6 taken 157 times.
✗ Branch 5 → 14 not taken.
157 visit(node->body);
581
582 // Leave default body scope
583 157 currentScope = node->bodyScope->parent;
584
585
1/2
✓ Branch 7 → 8 taken 157 times.
✗ Branch 7 → 15 not taken.
314 return nullptr;
586 }
587
588 123 std::any SymbolTableBuilder::visitAnonymousBlockStmt(AnonymousBlockStmtNode *node) {
589 // Create scope for the anonymous block body
590 123 node->bodyScope = currentScope =
591
2/4
✓ Branch 2 → 3 taken 123 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 123 times.
✗ Branch 3 → 11 not taken.
123 currentScope->createChildScope(node->getScopeId(), ScopeType::ANONYMOUS_BLOCK_BODY, &node->body->codeLoc);
592
593 // Visit body
594
1/2
✓ Branch 5 → 6 taken 123 times.
✗ Branch 5 → 14 not taken.
123 visit(node->body);
595
596 // Leave anonymous block body scope
597 123 currentScope = node->bodyScope->parent;
598
599
1/2
✓ Branch 7 → 8 taken 123 times.
✗ Branch 7 → 15 not taken.
246 return nullptr;
600 }
601
602 11048 std::any SymbolTableBuilder::visitEnumItem(EnumItemNode *node) {
603 // Check if enum item already exists in the same scope.
604
3/4
✓ Branch 2 → 3 taken 11048 times.
✗ Branch 2 → 42 not taken.
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 11046 times.
22096 if (currentScope->lookupStrict(node->itemName))
605
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");
606
607 // Add enum item entry to symbol table
608
1/2
✓ Branch 13 → 14 taken 11046 times.
✗ Branch 13 → 42 not taken.
11046 SymbolTableEntry *enumItemEntry = currentScope->insert(node->itemName, node);
609
610 // Add external registry entry
611
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 11046 times.
11046 assert(node->enumDef != nullptr);
612
2/4
✓ Branch 18 → 19 taken 11046 times.
✗ Branch 18 → 38 not taken.
✓ Branch 19 → 20 taken 11046 times.
✗ Branch 19 → 36 not taken.
11046 const std::string name = node->enumDef->enumName + SCOPE_ACCESS_TOKEN + node->itemName;
613
1/2
✓ Branch 21 → 22 taken 11046 times.
✗ Branch 21 → 40 not taken.
11046 sourceFile->addNameRegistryEntry(name, TY_INT, enumItemEntry, currentScope, true);
614
615
1/2
✓ Branch 22 → 23 taken 11046 times.
✗ Branch 22 → 39 not taken.
22092 return nullptr;
616 11046 }
617
618 15357 std::any SymbolTableBuilder::visitField(FieldNode *node) {
619 // Check if field already exists in the same scope.
620
2/2
✓ Branch 5 → 6 taken 4 times.
✓ Branch 5 → 13 taken 15353 times.
30714 if (currentScope->lookupStrict(node->fieldName))
621
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");
622
623 // Add field entry to symbol table
624 15353 currentScope->insert(node->fieldName, node);
625
626
1/2
✓ Branch 16 → 17 taken 15353 times.
✗ Branch 16 → 29 not taken.
30706 return nullptr;
627 }
628
629 4867 std::any SymbolTableBuilder::visitSignature(SignatureNode *node) {
630 // Build signature qualifiers
631
2/2
✓ Branch 2 → 3 taken 4775 times.
✓ Branch 2 → 32 taken 92 times.
4867 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
632
2/2
✓ Branch 30 → 5 taken 5047 times.
✓ Branch 30 → 31 taken 4775 times.
14597 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
633
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 5047 times.
5047 if (qualifier->type == QualifierNode::QualifierType::TY_INLINE)
634 node->signatureQualifiers.isInline = true;
635
2/2
✓ Branch 9 → 10 taken 4775 times.
✓ Branch 9 → 11 taken 272 times.
5047 else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
636 4775 node->signatureQualifiers.isPublic = true;
637
1/2
✓ Branch 11 → 12 taken 272 times.
✗ Branch 11 → 13 not taken.
272 else if (qualifier->type == QualifierNode::QualifierType::TY_CONST)
638 272 node->signatureQualifiers.isConst = true;
639 else
640 throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on a signature definition");
641 }
642 }
643
644 // Add signature entry to symbol table. We append the code location to disambiguate overloaded signatures
645 // (e.g. an interface declaring `getName()` and `getName(bool)`).
646
1/2
✓ Branch 32 → 33 taken 4867 times.
✗ Branch 32 → 53 not taken.
9734 node->entry = currentScope->insert(Function::getSymbolTableEntryName(node->methodName, node->codeLoc), node);
647
648
1/2
✓ Branch 37 → 38 taken 4867 times.
✗ Branch 37 → 54 not taken.
9734 return nullptr;
649 }
650
651 135079 std::any SymbolTableBuilder::visitDeclStmt(DeclStmtNode *node) {
652 // Check if variable already exists in the same scope.
653
2/2
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 135077 times.
270158 if (currentScope->lookupStrict(node->varName))
654
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");
655
656 // Visit the right side
657
2/2
✓ Branch 13 → 14 taken 48923 times.
✓ Branch 13 → 17 taken 86154 times.
135077 if (node->hasAssignment)
658
1/2
✓ Branch 14 → 15 taken 48923 times.
✗ Branch 14 → 33 not taken.
48923 visit(node->assignExpr);
659
660 // Add variable entry to symbol table
661 135077 SymbolTableEntry *varEntry = currentScope->insert(node->varName, node);
662 135077 varEntry->isParam = node->isFctParam;
663
664
1/2
✓ Branch 20 → 21 taken 135077 times.
✗ Branch 20 → 34 not taken.
270154 return nullptr;
665 }
666
667 2152 std::any SymbolTableBuilder::visitModAttr(ModAttrNode *node) {
668 // Visit attributes
669
2/2
✓ Branch 2 → 3 taken 2150 times.
✓ Branch 2 → 126 taken 2 times.
2152 visitChildren(node);
670
671 // Retrieve attributes
672 2150 const AttrLstNode *attrs = node->attrLst;
673
674 // Collect linker flags
675 2150 std::vector<const CompileTimeValue *> linkerFlagValues;
676 // core.linker.flag
677
2/4
✓ Branch 6 → 7 taken 2150 times.
✗ Branch 6 → 129 not taken.
✓ Branch 7 → 8 taken 2150 times.
✗ Branch 7 → 127 not taken.
4300 std::vector<const CompileTimeValue *> values = attrs->getAttrValuesByName(ATTR_CORE_LINKER_FLAG);
678
1/2
✓ Branch 16 → 17 taken 2150 times.
✗ Branch 16 → 133 not taken.
4300 linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end());
679 // core.linux.linker.flag
680 2150 const llvm::Triple &targetTriple = sourceFile->targetMachine->getTargetTriple();
681
2/2
✓ Branch 20 → 21 taken 2126 times.
✓ Branch 20 → 37 taken 24 times.
2150 if (targetTriple.isOSLinux()) {
682
2/4
✓ Branch 23 → 24 taken 2126 times.
✗ Branch 23 → 137 not taken.
✓ Branch 24 → 25 taken 2126 times.
✗ Branch 24 → 135 not taken.
4252 values = attrs->getAttrValuesByName(ATTR_CORE_LINUX_LINKER_FLAG);
683
1/2
✓ Branch 35 → 36 taken 2126 times.
✗ Branch 35 → 142 not taken.
4252 linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end());
684 }
685 // core.darwin.linker.flag
686
3/4
✓ Branch 37 → 38 taken 2150 times.
✗ Branch 37 → 187 not taken.
✓ Branch 38 → 39 taken 12 times.
✓ Branch 38 → 55 taken 2138 times.
2150 if (targetTriple.isOSDarwin()) {
687
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);
688
1/2
✓ Branch 53 → 54 taken 12 times.
✗ Branch 53 → 151 not taken.
24 linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end());
689 }
690 // core.windows.linker.flag
691
2/2
✓ Branch 56 → 57 taken 12 times.
✓ Branch 56 → 73 taken 2138 times.
2150 if (targetTriple.isOSWindows()) {
692
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);
693
1/2
✓ Branch 71 → 72 taken 12 times.
✗ Branch 71 → 160 not taken.
24 linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end());
694 }
695
2/2
✓ Branch 89 → 75 taken 2992 times.
✓ Branch 89 → 90 taken 2150 times.
7292 for (const CompileTimeValue *value : linkerFlagValues) {
696
1/2
✓ Branch 77 → 78 taken 2992 times.
✗ Branch 77 → 162 not taken.
2992 const std::string &flag = resourceManager.compileTimeStringValues.at(value->stringValueOffset);
697
1/2
✓ Branch 78 → 79 taken 2992 times.
✗ Branch 78 → 162 not taken.
2992 resourceManager.linker.addLinkerFlag(flag);
698
1/2
✓ Branch 79 → 80 taken 2992 times.
✗ Branch 79 → 162 not taken.
2992 sourceFile->sourceLinkerFlags.push_back(flag);
699 }
700
701 // core.linker.additionalSource
702
4/6
✓ Branch 90 → 91 taken 2150 times.
✗ Branch 90 → 165 not taken.
✓ Branch 91 → 92 taken 2150 times.
✗ Branch 91 → 163 not taken.
✓ Branch 116 → 94 taken 24 times.
✓ Branch 116 → 117 taken 2148 times.
4322 for (const CompileTimeValue *value : attrs->getAttrValuesByName(ATTR_CORE_LINKER_ADDITIONAL_SOURCE)) {
703
1/2
✓ Branch 96 → 97 taken 24 times.
✗ Branch 96 → 178 not taken.
24 const std::string &stringValue = resourceManager.compileTimeStringValues.at(value->stringValueOffset);
704
3/6
✓ Branch 97 → 98 taken 24 times.
✗ Branch 97 → 172 not taken.
✓ Branch 98 → 99 taken 24 times.
✗ Branch 98 → 169 not taken.
✓ Branch 99 → 100 taken 24 times.
✗ Branch 99 → 167 not taken.
24 const std::filesystem::path additionalSourcePath = sourceFile->filePath.parent_path() / stringValue;
705
3/4
✓ Branch 102 → 103 taken 24 times.
✗ Branch 102 → 175 not taken.
✓ Branch 103 → 104 taken 22 times.
✓ Branch 103 → 173 taken 2 times.
26 resourceManager.linker.addAdditionalSourcePath(additionalSourcePath);
706
1/2
✓ Branch 105 → 106 taken 22 times.
✗ Branch 105 → 176 not taken.
22 sourceFile->sourceAdditionalSourcePaths.push_back(additionalSourcePath);
707 2176 }
708
709
1/2
✓ Branch 120 → 121 taken 2148 times.
✗ Branch 120 → 186 not taken.
4296 return nullptr;
710 2152 }
711
712 8112 std::any SymbolTableBuilder::visitAttr(AttrNode *node) {
713 // Check if this attribute exists
714
1/2
✓ Branch 2 → 3 taken 8112 times.
✗ Branch 2 → 63 not taken.
8112 const auto it = ATTR_CONFIGS.find(node->key);
715
2/2
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 8110 times.
8112 if (it == ATTR_CONFIGS.end())
716
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 + "'");
717
718 // Check if the target is correct
719 8110 const auto &[target, type] = it->second;
720
2/2
✓ Branch 14 → 15 taken 2 times.
✓ Branch 14 → 22 taken 8108 times.
8110 if ((node->target & target) == 0)
721
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");
722
723 // Check if a value is present
724
4/4
✓ Branch 22 → 23 taken 1640 times.
✓ Branch 22 → 31 taken 6468 times.
✓ Branch 23 → 24 taken 2 times.
✓ Branch 23 → 31 taken 1638 times.
8108 if (!node->value && type != AttrNode::AttrType::TYPE_BOOL)
725
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");
726
727
1/2
✓ Branch 31 → 32 taken 8106 times.
✗ Branch 31 → 62 not taken.
16212 return nullptr;
728 }
729
730 109 std::any SymbolTableBuilder::visitLambdaFunc(LambdaFuncNode *node) {
731 // Create scope for the lambda body
732 109 const CodeLoc &codeLoc = node->body->codeLoc;
733
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);
734 // Requires capturing because the LLVM IR will end up in a separate function
735 109 currentScope->symbolTable.setCapturingRequired();
736 // Set to async scope if this is an async lambda
737
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))
738 node->bodyScope->isAsyncScope = node->lambdaAttr->attrLst->getAttrValueByName(ATTR_ASYNC)->boolValue;
739
740 // Create symbol for 'result' variable
741
1/2
✓ Branch 29 → 30 taken 109 times.
✗ Branch 29 → 65 not taken.
327 currentScope->insert(RETURN_VARIABLE_NAME, node);
742
743 // Create symbols for the parameters
744
2/2
✓ Branch 35 → 36 taken 99 times.
✓ Branch 35 → 39 taken 10 times.
109 if (node->hasParams)
745
1/2
✓ Branch 36 → 37 taken 99 times.
✗ Branch 36 → 69 not taken.
99 visit(node->paramLst);
746
747 // Visit body
748
1/2
✓ Branch 39 → 40 taken 109 times.
✗ Branch 39 → 70 not taken.
109 visit(node->body);
749
750 // Leave anonymous block body scope
751 109 currentScope = node->bodyScope->parent;
752
753
1/2
✓ Branch 41 → 42 taken 109 times.
✗ Branch 41 → 71 not taken.
218 return nullptr;
754 }
755
756 150 std::any SymbolTableBuilder::visitLambdaProc(LambdaProcNode *node) {
757 // Create scope for the lambda body
758 150 const CodeLoc &codeLoc = node->body->codeLoc;
759
2/4
✓ Branch 2 → 3 taken 150 times.
✗ Branch 2 → 39 not taken.
✓ Branch 3 → 4 taken 150 times.
✗ Branch 3 → 37 not taken.
150 node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::LAMBDA_BODY, &codeLoc);
760 // Requires capturing because the LLVM IR will end up in a separate function
761 150 currentScope->symbolTable.setCapturingRequired();
762 // Set to async scope if this is an async lambda
763
11/18
✓ Branch 6 → 7 taken 16 times.
✓ Branch 6 → 13 taken 134 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 134 times.
✓ Branch 16 → 17 taken 16 times.
✓ Branch 16 → 19 taken 134 times.
✓ Branch 19 → 20 taken 16 times.
✓ Branch 19 → 27 taken 134 times.
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 42 not taken.
✗ Branch 44 → 45 not taken.
✗ Branch 44 → 47 not taken.
182 if (node->lambdaAttr && node->lambdaAttr->attrLst->hasAttr(ATTR_ASYNC))
764
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;
765
766 // Create symbols for the parameters
767
2/2
✓ Branch 27 → 28 taken 118 times.
✓ Branch 27 → 31 taken 32 times.
150 if (node->hasParams)
768
1/2
✓ Branch 28 → 29 taken 118 times.
✗ Branch 28 → 55 not taken.
118 visit(node->paramLst);
769
770 // Visit body
771
1/2
✓ Branch 31 → 32 taken 150 times.
✗ Branch 31 → 56 not taken.
150 visit(node->body);
772
773 // Leave anonymous block body scope
774 150 currentScope = node->bodyScope->parent;
775
776
1/2
✓ Branch 33 → 34 taken 150 times.
✗ Branch 33 → 57 not taken.
300 return nullptr;
777 }
778
779 2 std::any SymbolTableBuilder::visitLambdaExpr(LambdaExprNode *node) {
780 // Create scope for the anonymous block body
781 2 const CodeLoc &codeLoc = node->lambdaExpr->codeLoc;
782
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);
783 // Requires capturing because the LLVM IR will end up in a separate function
784 2 currentScope->symbolTable.setCapturingRequired();
785
786 // Create symbols for the parameters
787
1/2
✓ Branch 6 → 7 taken 2 times.
✗ Branch 6 → 10 not taken.
2 if (node->hasParams)
788
1/2
✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 19 not taken.
2 visit(node->paramLst);
789
790 // Visit lambda expression
791
1/2
✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 20 not taken.
2 visit(node->lambdaExpr);
792
793 // Leave anonymous block body scope
794 2 currentScope = node->bodyScope->parent;
795
796
1/2
✓ Branch 12 → 13 taken 2 times.
✗ Branch 12 → 21 not taken.
4 return nullptr;
797 }
798
799 } // namespace spice::compiler
800