GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 96.2% 350 / 0 / 364
Functions: 100.0% 31 / 0 / 31
Branches: 58.4% 410 / 0 / 702

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