GCC Code Coverage Report


Directory: ../
File: src/symboltablebuilder/SymbolTableBuilder.cpp
Date: 2025-12-19 06:54:40
Coverage Exec Excl Total
Lines: 96.2% 350 0 364
Functions: 100.0% 31 0 31
Branches: 58.4% 410 0 702

Line Branch Exec Source
1 // Copyright (c) 2021-2025 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 1199 SymbolTableBuilder::SymbolTableBuilder(GlobalResourceManager &resourceManager, SourceFile *sourceFile)
14 1199 : CompilerPass(resourceManager, sourceFile), rootScope(sourceFile->globalScope.get()) {}
15
16 1199 std::any SymbolTableBuilder::visitEntry(EntryNode *node) {
17 // Initialize
18 1199 currentScope = rootScope;
19
20 // Visit children
21
2/2
✓ Branch 2 → 3 taken 1183 times.
✓ Branch 2 → 18 taken 16 times.
1199 visitChildren(node);
22
23 // Check if the main function exists
24
6/6
✓ Branch 4 → 5 taken 407 times.
✓ Branch 4 → 15 taken 776 times.
✓ Branch 5 → 6 taken 403 times.
✓ Branch 5 → 15 taken 4 times.
✓ Branch 6 → 7 taken 2 times.
✓ Branch 6 → 15 taken 401 times.
1183 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 1181 times.
✗ Branch 15 → 28 not taken.
1181 return nullptr;
28 }
29
30 406 std::any SymbolTableBuilder::visitMainFctDef(MainFctDefNode *node) {
31 // Visit attributes
32
2/2
✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 6 taken 405 times.
406 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 405 times.
✗ Branch 8 → 54 not taken.
✓ Branch 14 → 15 taken 1 time.
✓ Branch 14 → 23 taken 404 times.
1620 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 404 times.
✗ Branch 25 → 69 not taken.
1212 SymbolTableEntry *mainFctEntry = currentScope->insert(MAIN_FUNCTION_NAME, node);
41 404 mainFctEntry->used = true;
42
43 // Create scope for main function body
44
1/2
✓ Branch 31 → 32 taken 404 times.
✗ Branch 31 → 84 not taken.
404 const std::string &scopeId = MainFctDefNode::getScopeId();
45
1/2
✓ Branch 32 → 33 taken 404 times.
✗ Branch 32 → 82 not taken.
404 node->bodyScope = currentScope = rootScope->createChildScope(scopeId, ScopeType::FUNC_PROC_BODY, &node->codeLoc);
46 404 currentScope->isGenericScope = false;
47
48 // Declare variable for the return value in the function scope
49
1/2
✓ Branch 35 → 36 taken 404 times.
✗ Branch 35 → 75 not taken.
1212 SymbolTableEntry *resultVarEntry = node->bodyScope->insert(RETURN_VARIABLE_NAME, node);
50 404 resultVarEntry->used = true;
51
52 // Visit arguments in new scope
53
2/2
✓ Branch 41 → 42 taken 4 times.
✓ Branch 41 → 45 taken 400 times.
404 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 403 times.
✓ Branch 45 → 80 taken 1 time.
404 visit(node->body);
58
59 // Return to root scope
60 403 currentScope = rootScope;
61
62 403 hasMainFunction = true;
63
1/2
✓ Branch 47 → 48 taken 403 times.
✗ Branch 47 → 81 not taken.
806 return nullptr;
64 404 }
65
66 8117 std::any SymbolTableBuilder::visitFctDef(FctDefNode *node) {
67 // Visit attributes
68
2/2
✓ Branch 2 → 3 taken 333 times.
✓ Branch 2 → 6 taken 7784 times.
8117 if (node->attrs)
69
1/2
✓ Branch 3 → 4 taken 333 times.
✗ Branch 3 → 89 not taken.
333 visit(node->attrs);
70
71 // Build function qualifiers
72
2/2
✓ Branch 6 → 7 taken 7935 times.
✓ Branch 6 → 28 taken 182 times.
8117 if (const QualifierLstNode *qualifierLst = node->qualifierLst; qualifierLst) {
73
2/2
✓ Branch 26 → 9 taken 10727 times.
✓ Branch 26 → 27 taken 7935 times.
18662 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
74
2/2
✓ Branch 10 → 11 taken 2815 times.
✓ Branch 10 → 12 taken 7912 times.
10727 if (qualifier->type == QualifierNode::QualifierType::TY_INLINE)
75 2815 node->qualifiers.isInline = true;
76
2/2
✓ Branch 12 → 13 taken 7897 times.
✓ Branch 12 → 14 taken 15 times.
7912 else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
77 7897 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 3269 times.
✓ Branch 28 → 43 taken 4848 times.
8117 if (node->isMethod) {
87
1/2
✓ Branch 30 → 31 taken 3269 times.
✗ Branch 30 → 100 not taken.
3269 const std::string scopeName = Struct::getScopeName(node->name->structName);
88
1/2
✓ Branch 32 → 33 taken 3269 times.
✗ Branch 32 → 112 not taken.
3269 node->structScope = currentScope = currentScope->getChildScope(scopeName);
89
1/2
✗ Branch 33 → 34 not taken.
✓ Branch 33 → 41 taken 3269 times.
3269 if (!currentScope)
90 throw SemanticError(node, REFERENCED_UNDEFINED_STRUCT, "Struct '" + node->name->structName + "' could not be found");
91 3269 }
92
93 // Create scope for the function
94
2/4
✓ Branch 43 → 44 taken 8117 times.
✗ Branch 43 → 117 not taken.
✓ Branch 44 → 45 taken 8117 times.
✗ Branch 44 → 115 not taken.
8117 node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
95
6/6
✓ Branch 46 → 47 taken 7018 times.
✓ Branch 46 → 49 taken 1099 times.
✓ Branch 47 → 48 taken 3141 times.
✓ Branch 47 → 50 taken 3877 times.
✓ Branch 48 → 49 taken 1014 times.
✓ Branch 48 → 50 taken 2127 times.
8117 currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope);
96
97 // Create symbol for 'this' variable
98
2/2
✓ Branch 51 → 52 taken 3269 times.
✓ Branch 51 → 61 taken 4848 times.
8117 if (node->isMethod)
99
1/2
✓ Branch 54 → 55 taken 3269 times.
✗ Branch 54 → 120 not taken.
13076 currentScope->insert(THIS_VARIABLE_NAME, node);
100
101 // Create symbol for 'result' variable
102
1/2
✓ Branch 63 → 64 taken 8117 times.
✗ Branch 63 → 126 not taken.
24351 currentScope->insert(RETURN_VARIABLE_NAME, node);
103
104 // Create symbols for the parameters
105
2/2
✓ Branch 69 → 70 taken 6251 times.
✓ Branch 69 → 73 taken 1866 times.
8117 if (node->hasParams)
106
1/2
✓ Branch 70 → 71 taken 6251 times.
✗ Branch 70 → 130 not taken.
6251 visit(node->paramLst);
107
108 // Visit the function body
109
1/2
✓ Branch 73 → 74 taken 8117 times.
✗ Branch 73 → 131 not taken.
8117 visit(node->body);
110
111 // Leave function body scope
112 8117 currentScope = node->scope->parent;
113
114 // Insert symbol for function into the symbol table
115
1/2
✓ Branch 75 → 76 taken 8117 times.
✗ Branch 75 → 134 not taken.
16234 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 8117 const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName);
120
3/4
✓ Branch 81 → 82 taken 2078 times.
✓ Branch 81 → 83 taken 6039 times.
✓ Branch 82 → 83 taken 2078 times.
✗ Branch 82 → 84 not taken.
8117 if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry)
121 8117 sourceFile->addNameRegistryEntry(node->name->fqName, TY_FUNCTION, node->entry, currentScope, true);
122
123 // Leave the struct scope
124
2/2
✓ Branch 84 → 85 taken 3269 times.
✓ Branch 84 → 86 taken 4848 times.
8117 if (node->isMethod)
125 3269 currentScope = node->structScope->parent;
126
127
1/2
✓ Branch 86 → 87 taken 8117 times.
✗ Branch 86 → 135 not taken.
8117 return nullptr;
128 }
129
130 4195 std::any SymbolTableBuilder::visitProcDef(ProcDefNode *node) {
131 // Visit attributes
132
2/2
✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 6 taken 4194 times.
4195 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 3648 times.
✓ Branch 6 → 28 taken 546 times.
4194 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
137
2/2
✓ Branch 26 → 9 taken 4167 times.
✓ Branch 26 → 27 taken 3648 times.
7815 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
138
2/2
✓ Branch 10 → 11 taken 520 times.
✓ Branch 10 → 12 taken 3647 times.
4167 if (qualifier->type == QualifierNode::QualifierType::TY_INLINE)
139 520 node->qualifiers.isInline = true;
140
1/2
✓ Branch 12 → 13 taken 3647 times.
✗ Branch 12 → 14 not taken.
3647 else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
141 3647 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 3434 times.
✓ Branch 28 → 43 taken 760 times.
4194 if (node->isMethod) {
151
1/2
✓ Branch 30 → 31 taken 3434 times.
✗ Branch 30 → 99 not taken.
3434 const std::string &scopeName = Struct::getScopeName(node->name->structName);
152
1/2
✓ Branch 32 → 33 taken 3434 times.
✗ Branch 32 → 111 not taken.
3434 node->structScope = currentScope = currentScope->getChildScope(scopeName);
153
2/2
✓ Branch 33 → 34 taken 1 time.
✓ Branch 33 → 41 taken 3433 times.
3434 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 3434 }
156
157 // Create scope for the procedure
158
2/4
✓ Branch 43 → 44 taken 4193 times.
✗ Branch 43 → 116 not taken.
✓ Branch 44 → 45 taken 4193 times.
✗ Branch 44 → 114 not taken.
4193 node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
159
6/6
✓ Branch 46 → 47 taken 3015 times.
✓ Branch 46 → 49 taken 1178 times.
✓ Branch 47 → 48 taken 2789 times.
✓ Branch 47 → 50 taken 226 times.
✓ Branch 48 → 49 taken 857 times.
✓ Branch 48 → 50 taken 1932 times.
4193 currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope);
160
4/4
✓ Branch 51 → 52 taken 3433 times.
✓ Branch 51 → 55 taken 760 times.
✓ Branch 53 → 54 taken 117 times.
✓ Branch 53 → 55 taken 3316 times.
4193 currentScope->isDtorScope = node->isMethod && node->name->name == DTOR_FUNCTION_NAME;
161
162 // Create symbol for 'this' variable
163
2/2
✓ Branch 56 → 57 taken 3433 times.
✓ Branch 56 → 66 taken 760 times.
4193 if (node->isMethod)
164
1/2
✓ Branch 59 → 60 taken 3433 times.
✗ Branch 59 → 119 not taken.
13732 currentScope->insert(THIS_VARIABLE_NAME, node);
165
166 // Create symbols for the parameters
167
2/2
✓ Branch 66 → 67 taken 3109 times.
✓ Branch 66 → 70 taken 1084 times.
4193 if (node->hasParams)
168
1/2
✓ Branch 67 → 68 taken 3109 times.
✗ Branch 67 → 123 not taken.
3109 visit(node->paramLst);
169
170 // Visit the procedure body
171
1/2
✓ Branch 70 → 71 taken 4193 times.
✗ Branch 70 → 124 not taken.
4193 visit(node->body);
172
173 // Leave procedure body scope
174 4193 currentScope = node->scope->parent;
175
176 // Insert symbol for procedure into the symbol table
177
1/2
✓ Branch 72 → 73 taken 4193 times.
✗ Branch 72 → 127 not taken.
8386 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 4193 const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName);
182
3/4
✓ Branch 78 → 79 taken 1159 times.
✓ Branch 78 → 80 taken 3034 times.
✓ Branch 79 → 80 taken 1159 times.
✗ Branch 79 → 81 not taken.
4193 if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry)
183 4193 sourceFile->addNameRegistryEntry(node->name->fqName, TY_PROCEDURE, node->entry, currentScope, true);
184
185 // Leave the struct scope
186
2/2
✓ Branch 81 → 82 taken 3433 times.
✓ Branch 81 → 83 taken 760 times.
4193 if (node->isMethod)
187 3433 currentScope = node->structScope->parent;
188
189 // Check if this is a constructor
190 4193 node->isCtor = node->name->nameFragments.back() == CTOR_FUNCTION_NAME;
191
192
1/2
✓ Branch 85 → 86 taken 4193 times.
✗ Branch 85 → 128 not taken.
4193 return nullptr;
193 }
194
195 717 std::any SymbolTableBuilder::visitStructDef(StructDefNode *node) {
196 // Visit attributes
197
2/2
✓ Branch 2 → 3 taken 63 times.
✓ Branch 2 → 6 taken 654 times.
717 if (node->attrs)
198
1/2
✓ Branch 3 → 4 taken 63 times.
✗ Branch 3 → 63 not taken.
63 visit(node->attrs);
199
200 // Check if this name already exists
201
3/4
✓ Branch 6 → 7 taken 717 times.
✗ Branch 6 → 94 not taken.
✓ Branch 9 → 10 taken 1 time.
✓ Branch 9 → 17 taken 716 times.
1434 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 716 times.
✗ Branch 18 → 73 not taken.
716 const std::string &scopeName = Struct::getScopeName(node->structName);
206
1/2
✓ Branch 20 → 21 taken 716 times.
✗ Branch 20 → 92 not taken.
716 node->structScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::STRUCT, &node->codeLoc);
207 716 currentScope->isGenericScope = node->hasTemplateTypes;
208
209 // Insert implicit field for each interface type
210
2/2
✓ Branch 21 → 22 taken 139 times.
✓ Branch 21 → 35 taken 577 times.
716 if (node->hasInterfaces) {
211
2/2
✓ Branch 33 → 24 taken 139 times.
✓ Branch 33 → 34 taken 139 times.
278 for (DataTypeNode *interfaceNode : node->interfaceTypeLst->dataTypes) {
212 139 const std::string &interfaceName = interfaceNode->baseDataType->customDataType->typeNameFragments.back();
213
1/2
✓ Branch 26 → 27 taken 139 times.
✗ Branch 26 → 78 not taken.
278 SymbolTableEntry *interfaceFieldEntry = currentScope->insert("this." + interfaceName, interfaceNode);
214 139 interfaceFieldEntry->used = true;
215 139 interfaceFieldEntry->isImplicitField = true;
216 }
217 }
218
219 // Visit children
220
2/2
✓ Branch 35 → 36 taken 715 times.
✓ Branch 35 → 80 taken 1 time.
716 visitChildren(node);
221
222 // Leave the struct scope
223 715 currentScope = node->structScope->parent;
224
225 // Build struct qualifiers
226
2/2
✓ Branch 37 → 38 taken 565 times.
✓ Branch 37 → 55 taken 150 times.
715 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
227
2/2
✓ Branch 53 → 40 taken 565 times.
✓ Branch 53 → 54 taken 565 times.
1130 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
228
1/2
✓ Branch 41 → 42 taken 565 times.
✗ Branch 41 → 43 not taken.
565 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
229 565 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 715 times.
✗ Branch 55 → 92 not taken.
715 node->entry = rootScope->insert(node->structName, node);
237 // Register the name in the exported name registry
238
1/2
✓ Branch 58 → 59 taken 715 times.
✗ Branch 58 → 92 not taken.
715 sourceFile->addNameRegistryEntry(node->structName, node->typeId, node->entry, node->structScope, true);
239
240
1/2
✓ Branch 59 → 60 taken 715 times.
✗ Branch 59 → 91 not taken.
1430 return nullptr;
241 716 }
242
243 104 std::any SymbolTableBuilder::visitInterfaceDef(InterfaceDefNode *node) {
244 // Visit attributes
245
2/2
✓ Branch 2 → 3 taken 75 times.
✓ Branch 2 → 6 taken 29 times.
104 if (node->attrs)
246
1/2
✓ Branch 3 → 4 taken 75 times.
✗ Branch 3 → 55 not taken.
75 visit(node->attrs);
247
248 // Check if this name already exists
249
3/4
✓ Branch 6 → 7 taken 104 times.
✗ Branch 6 → 83 not taken.
✓ Branch 9 → 10 taken 1 time.
✓ Branch 9 → 17 taken 103 times.
208 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 103 times.
✗ Branch 18 → 65 not taken.
103 const std::string &scopeName = Interface::getScopeName(node->interfaceName);
254
1/2
✓ Branch 20 → 21 taken 103 times.
✗ Branch 20 → 81 not taken.
103 node->interfaceScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::INTERFACE, &node->codeLoc);
255
256 // Visit signatures
257
2/2
✓ Branch 28 → 23 taken 236 times.
✓ Branch 28 → 29 taken 103 times.
339 for (SignatureNode *signature : node->signatures)
258
1/2
✓ Branch 24 → 25 taken 236 times.
✗ Branch 24 → 68 not taken.
236 visit(signature);
259
260 // Leave the interface scope
261 103 currentScope = node->interfaceScope->parent;
262
263 // Build interface qualifiers
264
2/2
✓ Branch 29 → 30 taken 87 times.
✓ Branch 29 → 47 taken 16 times.
103 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
265
2/2
✓ Branch 45 → 32 taken 87 times.
✓ Branch 45 → 46 taken 87 times.
174 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
266
1/2
✓ Branch 33 → 34 taken 87 times.
✗ Branch 33 → 35 not taken.
87 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
267 87 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 103 times.
✗ Branch 47 → 81 not taken.
103 node->entry = rootScope->insert(node->interfaceName, node);
275 // Register the name in the exported name registry
276
1/2
✓ Branch 50 → 51 taken 103 times.
✗ Branch 50 → 81 not taken.
103 sourceFile->addNameRegistryEntry(node->interfaceName, node->typeId, node->entry, node->interfaceScope, true);
277
278
1/2
✓ Branch 51 → 52 taken 103 times.
✗ Branch 51 → 80 not taken.
206 return nullptr;
279 103 }
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 977 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 976 times.
1954 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 976 node->entry = rootScope->insert(node->typeName, node);
321 976 node->entry->used = true; // Generic types are always used
322
323
1/2
✓ Branch 16 → 17 taken 976 times.
✗ Branch 16 → 28 not taken.
976 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 1197 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 1196 times.
2394 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 1196 times.
✗ Branch 13 → 55 not taken.
✓ Branch 14 → 15 taken 1196 times.
✗ Branch 14 → 55 not taken.
✓ Branch 15 → 16 taken 1196 times.
✗ Branch 15 → 55 not taken.
✓ Branch 29 → 17 taken 416 times.
✓ Branch 29 → 30 taken 1195 times.
1611 for (const auto &dependency : sourceFile->dependencies | std::views::values)
360
3/4
✓ Branch 18 → 19 taken 416 times.
✗ Branch 18 → 55 not taken.
✓ Branch 19 → 20 taken 1 time.
✓ Branch 19 → 27 taken 415 times.
416 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 1195 node->entry = rootScope->insert(node->varName, node);
365 // Register the name in the exported name registry
366 1195 sourceFile->addNameRegistryEntry(node->varName, TY_INVALID, node->entry, currentScope, true);
367
368
1/2
✓ Branch 34 → 35 taken 1195 times.
✗ Branch 34 → 56 not taken.
1195 return nullptr;
369 }
370
371 1032 std::any SymbolTableBuilder::visitExtDecl(ExtDeclNode *node) {
372 // Visit attributes
373
2/2
✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 6 taken 1031 times.
1032 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 1031 times.
2064 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 1031 times.
✗ Branch 17 → 42 not taken.
✓ Branch 18 → 19 taken 1031 times.
✗ Branch 18 → 40 not taken.
1031 rootScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
382
383 // Add the external declaration to the symbol table
384 1031 node->entry = rootScope->insert(node->extFunctionName, node);
385 // Register the name in the exported name registry
386
2/2
✓ Branch 23 → 24 taken 675 times.
✓ Branch 23 → 25 taken 356 times.
1031 const uint64_t typeId = node->returnType ? TY_FUNCTION : TY_PROCEDURE;
387 1031 sourceFile->addNameRegistryEntry(node->extFunctionName, typeId, node->entry, rootScope, /*keepNewOnCollision=*/true);
388
389
1/2
✓ Branch 27 → 28 taken 1031 times.
✗ Branch 27 → 43 not taken.
1031 return nullptr;
390 }
391
392 2665 std::any SymbolTableBuilder::visitUnsafeBlock(UnsafeBlockNode *node) {
393 // Create scope for the unsafe block body
394 2665 node->bodyScope = currentScope =
395
2/4
✓ Branch 2 → 3 taken 2665 times.
✗ Branch 2 → 12 not taken.
✓ Branch 3 → 4 taken 2665 times.
✗ Branch 3 → 10 not taken.
2665 currentScope->createChildScope(node->getScopeId(), ScopeType::UNSAFE_BODY, &node->body->codeLoc);
396
397 // Visit body
398
1/2
✓ Branch 5 → 6 taken 2665 times.
✗ Branch 5 → 13 not taken.
2665 visit(node->body);
399
400 // Leave thread body scope
401 2665 currentScope = node->bodyScope->parent;
402
403
1/2
✓ Branch 7 → 8 taken 2665 times.
✗ Branch 7 → 14 not taken.
2665 return nullptr;
404 }
405
406 1424 std::any SymbolTableBuilder::visitForLoop(ForLoopNode *node) {
407 // Create scope for the loop body
408
2/4
✓ Branch 2 → 3 taken 1424 times.
✗ Branch 2 → 14 not taken.
✓ Branch 3 → 4 taken 1424 times.
✗ Branch 3 → 12 not taken.
1424 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 1424 times.
✗ Branch 5 → 15 not taken.
1424 visit(node->initDecl);
412
413 // Visit body
414
1/2
✓ Branch 7 → 8 taken 1424 times.
✗ Branch 7 → 16 not taken.
1424 visit(node->body);
415
416 // Leave for body scope
417 1424 currentScope = node->bodyScope->parent;
418
419
1/2
✓ Branch 9 → 10 taken 1424 times.
✗ Branch 9 → 17 not taken.
1424 return nullptr;
420 }
421
422 124 std::any SymbolTableBuilder::visitForeachLoop(ForeachLoopNode *node) {
423 // Create scope for the loop body
424 124 node->bodyScope = currentScope =
425
2/4
✓ Branch 2 → 3 taken 124 times.
✗ Branch 2 → 18 not taken.
✓ Branch 3 → 4 taken 124 times.
✗ Branch 3 → 16 not taken.
124 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 118 times.
124 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 124 times.
✗ Branch 9 → 20 not taken.
124 visit(node->itemVarDecl);
433
434 // Visit body
435
1/2
✓ Branch 11 → 12 taken 124 times.
✗ Branch 11 → 21 not taken.
124 visit(node->body);
436
437 // Leave foreach body scope
438 124 currentScope = node->bodyScope->parent;
439
440
1/2
✓ Branch 13 → 14 taken 124 times.
✗ Branch 13 → 22 not taken.
124 return nullptr;
441 }
442
443 807 std::any SymbolTableBuilder::visitWhileLoop(WhileLoopNode *node) {
444 // Create scope for the loop body
445 807 node->bodyScope = currentScope =
446
2/4
✓ Branch 2 → 3 taken 807 times.
✗ Branch 2 → 14 not taken.
✓ Branch 3 → 4 taken 807 times.
✗ Branch 3 → 12 not taken.
807 currentScope->createChildScope(node->getScopeId(), ScopeType::WHILE_BODY, &node->body->codeLoc);
447
448 // Visit condition
449
1/2
✓ Branch 5 → 6 taken 807 times.
✗ Branch 5 → 15 not taken.
807 visit(node->condition);
450
451 // Visit body
452
1/2
✓ Branch 7 → 8 taken 807 times.
✗ Branch 7 → 16 not taken.
807 visit(node->body);
453
454 // Leave while body scope
455 807 currentScope = node->bodyScope->parent;
456
457
1/2
✓ Branch 9 → 10 taken 807 times.
✗ Branch 9 → 17 not taken.
807 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 4348 std::any SymbolTableBuilder::visitIfStmt(IfStmtNode *node) {
478 // Create scope for the then body
479 4348 node->thenBodyScope = currentScope =
480
2/4
✓ Branch 2 → 3 taken 4348 times.
✗ Branch 2 → 18 not taken.
✓ Branch 3 → 4 taken 4348 times.
✗ Branch 3 → 16 not taken.
4348 currentScope->createChildScope(node->getScopeId(), ScopeType::IF_ELSE_BODY, &node->thenBody->codeLoc);
481
482 // Visit condition
483
1/2
✓ Branch 5 → 6 taken 4348 times.
✗ Branch 5 → 19 not taken.
4348 visit(node->condition);
484
485 // Visit then body
486
1/2
✓ Branch 7 → 8 taken 4348 times.
✗ Branch 7 → 20 not taken.
4348 visit(node->thenBody);
487
488 // Leave then body scope
489 4348 currentScope = node->thenBodyScope->parent;
490
491 // Visit else stmt
492
2/2
✓ Branch 9 → 10 taken 249 times.
✓ Branch 9 → 13 taken 4099 times.
4348 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 4348 times.
✗ Branch 13 → 22 not taken.
4348 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 1541 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 1540 times.
3082 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 1540 currentScope->insert(node->fieldName, node);
582
583
1/2
✓ Branch 16 → 17 taken 1540 times.
✗ Branch 16 → 28 not taken.
1540 return nullptr;
584 }
585
586 236 std::any SymbolTableBuilder::visitSignature(SignatureNode *node) {
587 // Build signature qualifiers
588
2/2
✓ Branch 2 → 3 taken 14 times.
✓ Branch 2 → 24 taken 222 times.
236 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 236 node->entry = currentScope->insert(node->methodName, node);
603
604
1/2
✓ Branch 27 → 28 taken 236 times.
✗ Branch 27 → 40 not taken.
236 return nullptr;
605 }
606
607 21360 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 21359 times.
42720 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 7626 times.
✓ Branch 13 → 17 taken 13733 times.
21359 if (node->hasAssignment)
614
1/2
✓ Branch 14 → 15 taken 7626 times.
✗ Branch 14 → 32 not taken.
7626 visit(node->assignExpr);
615
616 // Add variable entry to symbol table
617 21359 SymbolTableEntry *varEntry = currentScope->insert(node->varName, node);
618 21359 varEntry->isParam = node->isFctParam;
619
620
1/2
✓ Branch 20 → 21 taken 21359 times.
✗ Branch 20 → 33 not taken.
21359 return nullptr;
621 }
622
623 362 std::any SymbolTableBuilder::visitModAttr(ModAttrNode *node) {
624 // Visit attributes
625
2/2
✓ Branch 2 → 3 taken 361 times.
✓ Branch 2 → 101 taken 1 time.
362 visitChildren(node);
626
627 // Retrieve attributes
628 361 const AttrLstNode *attrs = node->attrLst;
629
630 // Collect linker flags
631 361 std::vector<const CompileTimeValue *> linkerFlagValues;
632 // core.linker.flag
633
2/4
✓ Branch 6 → 7 taken 361 times.
✗ Branch 6 → 104 not taken.
✓ Branch 7 → 8 taken 361 times.
✗ Branch 7 → 102 not taken.
722 std::vector<const CompileTimeValue *> values = attrs->getAttrValuesByName(ATTR_CORE_LINKER_FLAG);
634
1/2
✓ Branch 14 → 15 taken 361 times.
✗ Branch 14 → 108 not taken.
361 linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end());
635 // core.linux.linker.flag
636 361 const llvm::Triple &targetTriple = sourceFile->targetMachine->getTargetTriple();
637
2/2
✓ Branch 18 → 19 taken 351 times.
✓ Branch 18 → 33 taken 10 times.
361 if (targetTriple.isOSLinux()) {
638
2/4
✓ Branch 21 → 22 taken 351 times.
✗ Branch 21 → 112 not taken.
✓ Branch 22 → 23 taken 351 times.
✗ Branch 22 → 110 not taken.
702 values = attrs->getAttrValuesByName(ATTR_CORE_LINUX_LINKER_FLAG);
639
1/2
✓ Branch 31 → 32 taken 351 times.
✗ Branch 31 → 117 not taken.
351 linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end());
640 }
641 // core.darwin.linker.flag
642
3/4
✓ Branch 33 → 34 taken 361 times.
✗ Branch 33 → 160 not taken.
✓ Branch 34 → 35 taken 5 times.
✓ Branch 34 → 49 taken 356 times.
361 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 356 times.
361 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 361 times.
618 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 361 times.
✗ Branch 75 → 140 not taken.
✓ Branch 76 → 77 taken 361 times.
✗ Branch 76 → 138 not taken.
✓ Branch 94 → 81 taken 2 times.
✓ Branch 94 → 95 taken 361 times.
1085 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 363 }
660
661
1/2
✓ Branch 96 → 97 taken 361 times.
✗ Branch 96 → 159 not taken.
722 return nullptr;
662 361 }
663
664 1186 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 1185 times.
1186 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 1185 const auto &[target, type] = ATTR_CONFIGS.at(node->key);
671
2/2
✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 20 taken 1184 times.
1185 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 334 times.
✓ Branch 20 → 29 taken 850 times.
✓ Branch 21 → 22 taken 1 time.
✓ Branch 21 → 29 taken 333 times.
1184 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 1183 times.
✗ Branch 29 → 59 not taken.
1183 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