GCC Code Coverage Report


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

src/symboltablebuilder/SymbolTableBuilder.cpp
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 #include "SymbolTableBuilder.h"
4
5 #include <SourceFile.h>
6 #include <ast/ASTBuilder.h>
7 #include <ast/Attributes.h>
8 #include <driver/Driver.h>
9 #include <exception/SemanticError.h>
10 #include <global/GlobalResourceManager.h>
11 #include <model/Function.h>
12 #include <symboltablebuilder/Scope.h>
13
14 namespace spice::compiler {
15
16 6219 SymbolTableBuilder::SymbolTableBuilder(GlobalResourceManager &resourceManager, SourceFile *sourceFile)
17 6219 : CompilerPass(resourceManager, sourceFile), rootScope(sourceFile->globalScope.get()) {}
18
19 6219 std::any SymbolTableBuilder::visitEntry(EntryNode *node) {
20 // Initialize
21 6219 currentScope = rootScope;
22
23 // Visit children
24
2/2
✓ Branch 2 → 3 taken 6181 times.
✓ Branch 2 → 23 taken 38 times.
6219 visitChildren(node);
25
26 // Check if the main function exists
27
4/4
✓ Branch 4 → 5 taken 6175 times.
✓ Branch 4 → 7 taken 6 times.
✓ Branch 5 → 6 taken 6163 times.
✓ Branch 5 → 7 taken 12 times.
6181 const bool mainFctRequired = cliOptions.outputContainer == OutputContainer::EXECUTABLE && !cliOptions.noEntryFct;
28
6/6
✓ Branch 8 → 9 taken 1246 times.
✓ Branch 8 → 19 taken 4935 times.
✓ Branch 9 → 10 taken 1230 times.
✓ Branch 9 → 19 taken 16 times.
✓ Branch 10 → 11 taken 4 times.
✓ Branch 10 → 19 taken 1226 times.
6181 if (sourceFile->isMainFile && mainFctRequired && !hasMainFunction)
29
2/4
✓ Branch 14 → 15 taken 4 times.
✗ Branch 14 → 27 not taken.
✓ Branch 15 → 16 taken 4 times.
✗ Branch 15 → 24 not taken.
12 throw SemanticError(node, MISSING_MAIN_FUNCTION, "No main function found", false);
30
31
1/2
✓ Branch 19 → 20 taken 6177 times.
✗ Branch 19 → 33 not taken.
12354 return nullptr;
32 }
33
34 1238 std::any SymbolTableBuilder::visitMainFctDef(MainFctDefNode *node) {
35 // Visit attributes
36
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 6 taken 1236 times.
1238 if (node->attrs)
37
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 52 taken 2 times.
2 visit(node->attrs);
38
39 // Check if the function is already defined
40
3/4
✓ Branch 8 → 9 taken 1236 times.
✗ Branch 8 → 55 not taken.
✓ Branch 14 → 15 taken 2 times.
✓ Branch 14 → 23 taken 1234 times.
4944 if (rootScope->lookupStrict(MAIN_FUNCTION_NAME))
41
2/4
✓ Branch 18 → 19 taken 2 times.
✗ Branch 18 → 62 not taken.
✓ Branch 19 → 20 taken 2 times.
✗ Branch 19 → 59 not taken.
6 throw SemanticError(node, FUNCTION_DECLARED_TWICE, "Main function is declared twice");
42
43 // Insert symbol for main function
44
1/2
✓ Branch 25 → 26 taken 1234 times.
✗ Branch 25 → 70 not taken.
3702 SymbolTableEntry *mainFctEntry = currentScope->insert(MAIN_FUNCTION_NAME, node);
45 1234 mainFctEntry->used = true;
46
47 // Create scope for main function body
48
1/2
✓ Branch 31 → 32 taken 1234 times.
✗ Branch 31 → 85 not taken.
1234 const std::string &scopeId = MainFctDefNode::getScopeId();
49
1/2
✓ Branch 32 → 33 taken 1234 times.
✗ Branch 32 → 83 not taken.
1234 node->bodyScope = currentScope = rootScope->createChildScope(scopeId, ScopeType::FUNC_PROC_BODY, &node->codeLoc);
50 1234 currentScope->isGenericScope = false;
51
52 // Declare variable for the return value in the function scope
53
1/2
✓ Branch 35 → 36 taken 1234 times.
✗ Branch 35 → 76 not taken.
3702 SymbolTableEntry *resultVarEntry = node->bodyScope->insert(RETURN_VARIABLE_NAME, node);
54 1234 resultVarEntry->used = true;
55
56 // Visit arguments in new scope
57
2/2
✓ Branch 41 → 42 taken 14 times.
✓ Branch 41 → 45 taken 1220 times.
1234 if (node->takesArgs)
58
1/2
✓ Branch 42 → 43 taken 14 times.
✗ Branch 42 → 80 not taken.
14 visit(node->paramLst);
59
60 // Visit function body in new scope
61
2/2
✓ Branch 45 → 46 taken 1232 times.
✓ Branch 45 → 81 taken 2 times.
1234 visit(node->body);
62
63 // Return to root scope
64 1232 currentScope = rootScope;
65
66 1232 hasMainFunction = true;
67
1/2
✓ Branch 47 → 48 taken 1232 times.
✗ Branch 47 → 82 not taken.
2464 return nullptr;
68 1234 }
69
70 49900 std::any SymbolTableBuilder::visitFctDef(FctDefNode *node) {
71 // Visit attributes
72
2/2
✓ Branch 2 → 3 taken 1654 times.
✓ Branch 2 → 6 taken 48246 times.
49900 if (node->attrs)
73
1/2
✓ Branch 3 → 4 taken 1654 times.
✗ Branch 3 → 98 not taken.
1654 visit(node->attrs);
74
75 // Build function qualifiers
76
2/2
✓ Branch 6 → 7 taken 47695 times.
✓ Branch 6 → 36 taken 2205 times.
49900 if (const QualifierLstNode *qualifierLst = node->qualifierLst; qualifierLst) {
77
2/2
✓ Branch 34 → 9 taken 63616 times.
✓ Branch 34 → 35 taken 47695 times.
159006 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
78
2/2
✓ Branch 11 → 12 taken 15935 times.
✓ Branch 11 → 13 taken 47681 times.
63616 if (qualifier->type == QualifierNode::QualifierType::TY_INLINE)
79 15935 node->qualifiers.isInline = true;
80
2/2
✓ Branch 13 → 14 taken 47415 times.
✓ Branch 13 → 15 taken 266 times.
47681 else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
81 47415 node->qualifiers.isPublic = true;
82
1/2
✓ Branch 15 → 16 taken 266 times.
✗ Branch 15 → 17 not taken.
266 else if (qualifier->type == QualifierNode::QualifierType::TY_CONST)
83 266 node->qualifiers.isConst = true;
84 else
85 throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on a function definition");
86 }
87 }
88
89 // Change to struct scope if this function is a method
90
2/2
✓ Branch 36 → 37 taken 25489 times.
✓ Branch 36 → 51 taken 24411 times.
49900 if (node->isMethod) {
91
1/2
✓ Branch 38 → 39 taken 25489 times.
✗ Branch 38 → 109 not taken.
25489 const std::string scopeName = Struct::getScopeName(node->name->structName);
92
1/2
✓ Branch 40 → 41 taken 25489 times.
✗ Branch 40 → 121 not taken.
25489 node->structScope = currentScope = currentScope->getChildScope(scopeName);
93
1/2
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 49 taken 25489 times.
25489 if (!currentScope)
94 throw SemanticError(node, REFERENCED_UNDEFINED_STRUCT, "Struct '" + node->name->structName + "' could not be found");
95 25489 }
96
97 // Create scope for the function
98
2/4
✓ Branch 51 → 52 taken 49900 times.
✗ Branch 51 → 126 not taken.
✓ Branch 52 → 53 taken 49900 times.
✗ Branch 52 → 124 not taken.
49900 node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
99
6/6
✓ Branch 54 → 55 taken 44828 times.
✓ Branch 54 → 57 taken 5072 times.
✓ Branch 55 → 56 taken 24786 times.
✓ Branch 55 → 58 taken 20042 times.
✓ Branch 56 → 57 taken 6695 times.
✓ Branch 56 → 58 taken 18091 times.
49900 currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope);
100
101 // Create symbol for 'this' variable
102
2/2
✓ Branch 59 → 60 taken 25489 times.
✓ Branch 59 → 69 taken 24411 times.
49900 if (node->isMethod)
103
1/2
✓ Branch 62 → 63 taken 25489 times.
✗ Branch 62 → 129 not taken.
101956 currentScope->insert(THIS_VARIABLE_NAME, node);
104
105 // Create symbol for 'result' variable
106
1/2
✓ Branch 71 → 72 taken 49900 times.
✗ Branch 71 → 135 not taken.
149700 currentScope->insert(RETURN_VARIABLE_NAME, node);
107
108 // Create symbols for the parameters
109
2/2
✓ Branch 77 → 78 taken 36182 times.
✓ Branch 77 → 81 taken 13718 times.
49900 if (node->hasParams)
110
1/2
✓ Branch 78 → 79 taken 36182 times.
✗ Branch 78 → 139 not taken.
36182 visit(node->paramLst);
111
112 // Visit the function body
113
1/2
✓ Branch 81 → 82 taken 49900 times.
✗ Branch 81 → 140 not taken.
49900 visit(node->body);
114
115 // Leave function body scope
116 49900 currentScope = node->scope->parent;
117
118 // Insert symbol for function into the symbol table
119
1/2
✓ Branch 83 → 84 taken 49900 times.
✗ Branch 83 → 143 not taken.
99800 node->entry = currentScope->insert(node->getSymbolTableEntryName(), node);
120
121 // Add to external name registry
122 // if a function has overloads, they both refer to the same entry in the registry. So we only register the name once
123 49900 const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName);
124
3/4
✓ Branch 89 → 90 taken 10439 times.
✓ Branch 89 → 91 taken 39461 times.
✓ Branch 90 → 91 taken 10439 times.
✗ Branch 90 → 92 not taken.
49900 if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry)
125 49900 sourceFile->addNameRegistryEntry(node->name->fqName, TY_FUNCTION, node->entry, currentScope, true);
126
127 // Leave the struct scope
128
2/2
✓ Branch 92 → 93 taken 25489 times.
✓ Branch 92 → 94 taken 24411 times.
49900 if (node->isMethod)
129 25489 currentScope = node->structScope->parent;
130
131
1/2
✓ Branch 94 → 95 taken 49900 times.
✗ Branch 94 → 144 not taken.
99800 return nullptr;
132 }
133
134 30012 std::any SymbolTableBuilder::visitProcDef(ProcDefNode *node) {
135 // Visit attributes
136
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 6 taken 30010 times.
30012 if (node->attrs)
137
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 97 taken 2 times.
2 visit(node->attrs);
138
139 // Build procedure qualifiers
140
2/2
✓ Branch 6 → 7 taken 25265 times.
✓ Branch 6 → 36 taken 4745 times.
30010 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
141
2/2
✓ Branch 34 → 9 taken 29214 times.
✓ Branch 34 → 35 taken 25265 times.
79744 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
142
2/2
✓ Branch 11 → 12 taken 3959 times.
✓ Branch 11 → 13 taken 25255 times.
29214 if (qualifier->type == QualifierNode::QualifierType::TY_INLINE)
143 3959 node->qualifiers.isInline = true;
144
2/2
✓ Branch 13 → 14 taken 25247 times.
✓ Branch 13 → 15 taken 8 times.
25255 else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
145 25247 node->qualifiers.isPublic = true;
146
1/2
✓ Branch 15 → 16 taken 8 times.
✗ Branch 15 → 17 not taken.
8 else if (qualifier->type == QualifierNode::QualifierType::TY_CONST)
147 8 node->qualifiers.isConst = true;
148 else
149 throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on a procedure definition");
150 }
151 }
152
153 // Change to struct scope if this procedure is a method
154
2/2
✓ Branch 36 → 37 taken 24518 times.
✓ Branch 36 → 51 taken 5492 times.
30010 if (node->isMethod) {
155
1/2
✓ Branch 38 → 39 taken 24518 times.
✗ Branch 38 → 108 not taken.
24518 const std::string &scopeName = Struct::getScopeName(node->name->structName);
156
1/2
✓ Branch 40 → 41 taken 24518 times.
✗ Branch 40 → 120 not taken.
24518 node->structScope = currentScope = currentScope->getChildScope(scopeName);
157
2/2
✓ Branch 41 → 42 taken 2 times.
✓ Branch 41 → 49 taken 24516 times.
24518 if (!currentScope)
158
3/6
✓ Branch 43 → 44 taken 2 times.
✗ Branch 43 → 116 not taken.
✓ Branch 44 → 45 taken 2 times.
✗ Branch 44 → 114 not taken.
✓ Branch 45 → 46 taken 2 times.
✗ Branch 45 → 111 not taken.
2 throw SemanticError(node, REFERENCED_UNDEFINED_STRUCT, "Struct '" + node->name->structName + "' could not be found");
159 24518 }
160
161 // Create scope for the procedure
162
2/4
✓ Branch 51 → 52 taken 30008 times.
✗ Branch 51 → 125 not taken.
✓ Branch 52 → 53 taken 30008 times.
✗ Branch 52 → 123 not taken.
30008 node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
163
6/6
✓ Branch 54 → 55 taken 24776 times.
✓ Branch 54 → 57 taken 5232 times.
✓ Branch 55 → 56 taken 21753 times.
✓ Branch 55 → 58 taken 3023 times.
✓ Branch 56 → 57 taken 5930 times.
✓ Branch 56 → 58 taken 15823 times.
30008 currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope);
164
4/4
✓ Branch 59 → 60 taken 24516 times.
✓ Branch 59 → 63 taken 5492 times.
✓ Branch 61 → 62 taken 1016 times.
✓ Branch 61 → 63 taken 23500 times.
30008 currentScope->isDtorScope = node->isMethod && node->name->name == DTOR_FUNCTION_NAME;
165
166 // Create symbol for 'this' variable
167
2/2
✓ Branch 64 → 65 taken 24516 times.
✓ Branch 64 → 74 taken 5492 times.
30008 if (node->isMethod)
168
1/2
✓ Branch 67 → 68 taken 24516 times.
✗ Branch 67 → 128 not taken.
98064 currentScope->insert(THIS_VARIABLE_NAME, node);
169
170 // Create symbols for the parameters
171
2/2
✓ Branch 74 → 75 taken 22209 times.
✓ Branch 74 → 78 taken 7799 times.
30008 if (node->hasParams)
172
1/2
✓ Branch 75 → 76 taken 22209 times.
✗ Branch 75 → 132 not taken.
22209 visit(node->paramLst);
173
174 // Visit the procedure body
175
1/2
✓ Branch 78 → 79 taken 30008 times.
✗ Branch 78 → 133 not taken.
30008 visit(node->body);
176
177 // Leave procedure body scope
178 30008 currentScope = node->scope->parent;
179
180 // Insert symbol for procedure into the symbol table
181
1/2
✓ Branch 80 → 81 taken 30008 times.
✗ Branch 80 → 136 not taken.
60016 node->entry = currentScope->insert(node->getSymbolTableEntryName(), node);
182
183 // Add to external name registry
184 // if a procedure has overloads, they both refer to the same entry in the registry. So we only register the name once
185 30008 const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName);
186
3/4
✓ Branch 86 → 87 taken 6224 times.
✓ Branch 86 → 88 taken 23784 times.
✓ Branch 87 → 88 taken 6224 times.
✗ Branch 87 → 89 not taken.
30008 if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry)
187 30008 sourceFile->addNameRegistryEntry(node->name->fqName, TY_PROCEDURE, node->entry, currentScope, true);
188
189 // Leave the struct scope
190
2/2
✓ Branch 89 → 90 taken 24516 times.
✓ Branch 89 → 91 taken 5492 times.
30008 if (node->isMethod)
191 24516 currentScope = node->structScope->parent;
192
193 // Check if this is a constructor
194 30008 node->isCtor = node->name->nameFragments.back() == CTOR_FUNCTION_NAME;
195
196
1/2
✓ Branch 93 → 94 taken 30008 times.
✗ Branch 93 → 137 not taken.
60016 return nullptr;
197 }
198
199 7591 std::any SymbolTableBuilder::visitStructDef(StructDefNode *node) {
200 // Visit attributes
201
2/2
✓ Branch 2 → 3 taken 254 times.
✓ Branch 2 → 6 taken 7337 times.
7591 if (node->attrs)
202
1/2
✓ Branch 3 → 4 taken 254 times.
✗ Branch 3 → 79 not taken.
254 visit(node->attrs);
203
204 // Check if this name already exists
205
3/4
✓ Branch 6 → 7 taken 7591 times.
✗ Branch 6 → 110 not taken.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 17 taken 7589 times.
15182 if (rootScope->lookupStrict(node->structName))
206
3/6
✓ Branch 11 → 12 taken 2 times.
✗ Branch 11 → 85 not taken.
✓ Branch 12 → 13 taken 2 times.
✗ Branch 12 → 83 not taken.
✓ Branch 13 → 14 taken 2 times.
✗ Branch 13 → 80 not taken.
2 throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->structName + "'");
207
208 // Create scope for the struct
209
1/2
✓ Branch 18 → 19 taken 7589 times.
✗ Branch 18 → 89 not taken.
7589 const std::string &scopeName = Struct::getScopeName(node->structName);
210
1/2
✓ Branch 20 → 21 taken 7589 times.
✗ Branch 20 → 108 not taken.
7589 node->structScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::STRUCT, &node->codeLoc);
211 7589 currentScope->isGenericScope = node->hasTemplateTypes;
212
213 // Insert implicit field for each interface type
214
2/2
✓ Branch 21 → 22 taken 766 times.
✓ Branch 21 → 43 taken 6823 times.
7589 if (node->hasInterfaces) {
215
2/2
✓ Branch 41 → 24 taken 766 times.
✓ Branch 41 → 42 taken 766 times.
2298 for (DataTypeNode *interfaceNode : node->interfaceTypeLst->dataTypes) {
216 766 const std::string &interfaceName = interfaceNode->baseDataType->customDataType->typeNameFragments.back();
217
1/2
✓ Branch 27 → 28 taken 766 times.
✗ Branch 27 → 94 not taken.
1532 SymbolTableEntry *interfaceFieldEntry = currentScope->insert("this." + interfaceName, interfaceNode);
218 766 interfaceFieldEntry->used = true;
219 766 interfaceFieldEntry->isImplicitField = true;
220 }
221 }
222
223 // Visit children
224
2/2
✓ Branch 43 → 44 taken 7587 times.
✓ Branch 43 → 96 taken 2 times.
7589 visitChildren(node);
225
226 // Leave the struct scope
227 7587 currentScope = node->structScope->parent;
228
229 // Build struct qualifiers
230
2/2
✓ Branch 45 → 46 taken 6025 times.
✓ Branch 45 → 70 taken 1562 times.
7587 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
231
2/2
✓ Branch 68 → 48 taken 6025 times.
✓ Branch 68 → 69 taken 6025 times.
18075 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
232
1/2
✓ Branch 50 → 51 taken 6025 times.
✗ Branch 50 → 54 not taken.
6025 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
233 6025 node->qualifiers.isPublic = true;
234 else
235 throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on a struct definition");
236 }
237 }
238
239 // Add the struct to the symbol table
240
1/2
✓ Branch 70 → 71 taken 7587 times.
✗ Branch 70 → 108 not taken.
7587 node->entry = rootScope->insert(node->structName, node);
241 // Register the name in the exported name registry
242
1/2
✓ Branch 73 → 74 taken 7587 times.
✗ Branch 73 → 108 not taken.
7587 sourceFile->addNameRegistryEntry(node->structName, node->typeId, node->entry, node->structScope, true);
243
244
1/2
✓ Branch 74 → 75 taken 7587 times.
✗ Branch 74 → 107 not taken.
15174 return nullptr;
245 7589 }
246
247 817 std::any SymbolTableBuilder::visitInterfaceDef(InterfaceDefNode *node) {
248 // Visit attributes
249
2/2
✓ Branch 2 → 3 taken 382 times.
✓ Branch 2 → 6 taken 435 times.
817 if (node->attrs)
250
1/2
✓ Branch 3 → 4 taken 382 times.
✗ Branch 3 → 71 not taken.
382 visit(node->attrs);
251
252 // Check if this name already exists
253
3/4
✓ Branch 6 → 7 taken 817 times.
✗ Branch 6 → 99 not taken.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 17 taken 815 times.
1634 if (rootScope->lookupStrict(node->interfaceName))
254
3/6
✓ Branch 11 → 12 taken 2 times.
✗ Branch 11 → 77 not taken.
✓ Branch 12 → 13 taken 2 times.
✗ Branch 12 → 75 not taken.
✓ Branch 13 → 14 taken 2 times.
✗ Branch 13 → 72 not taken.
2 throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->interfaceName + "'");
255
256 // Create scope for the interface
257
1/2
✓ Branch 18 → 19 taken 815 times.
✗ Branch 18 → 81 not taken.
815 const std::string &scopeName = Interface::getScopeName(node->interfaceName);
258
1/2
✓ Branch 20 → 21 taken 815 times.
✗ Branch 20 → 97 not taken.
815 node->interfaceScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::INTERFACE, &node->codeLoc);
259
260 // Visit signatures
261
2/2
✓ Branch 36 → 23 taken 4897 times.
✓ Branch 36 → 37 taken 815 times.
6527 for (SignatureNode *signature : node->signatures)
262
1/2
✓ Branch 25 → 26 taken 4897 times.
✗ Branch 25 → 84 not taken.
4897 visit(signature);
263
264 // Leave the interface scope
265 815 currentScope = node->interfaceScope->parent;
266
267 // Build interface qualifiers
268
2/2
✓ Branch 37 → 38 taken 775 times.
✓ Branch 37 → 62 taken 40 times.
815 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
269
2/2
✓ Branch 60 → 40 taken 775 times.
✓ Branch 60 → 61 taken 775 times.
2325 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
270
1/2
✓ Branch 42 → 43 taken 775 times.
✗ Branch 42 → 46 not taken.
775 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
271 775 node->qualifiers.isPublic = true;
272 else
273 throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on an interface definition");
274 }
275 }
276
277 // Add the interface to the symbol table
278
1/2
✓ Branch 62 → 63 taken 815 times.
✗ Branch 62 → 97 not taken.
815 node->entry = rootScope->insert(node->interfaceName, node);
279 // Register the name in the exported name registry
280
1/2
✓ Branch 65 → 66 taken 815 times.
✗ Branch 65 → 97 not taken.
815 sourceFile->addNameRegistryEntry(node->interfaceName, node->typeId, node->entry, node->interfaceScope, true);
281
282
1/2
✓ Branch 66 → 67 taken 815 times.
✗ Branch 66 → 96 not taken.
1630 return nullptr;
283 815 }
284
285 68 std::any SymbolTableBuilder::visitUnionDef(UnionDefNode *node) {
286 // Visit attributes
287
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 6 taken 68 times.
68 if (node->attrs)
288 visit(node->attrs);
289
290 // Check if this name already exists
291
2/4
✓ Branch 6 → 7 taken 68 times.
✗ Branch 6 → 84 not taken.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 17 taken 68 times.
136 if (rootScope->lookupStrict(node->unionName))
292 throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->unionName + "'");
293
294 // Create scope for the union
295
1/2
✓ Branch 18 → 19 taken 68 times.
✗ Branch 18 → 67 not taken.
68 const std::string &scopeName = Union::getScopeName(node->unionName);
296
1/2
✓ Branch 20 → 21 taken 68 times.
✗ Branch 20 → 82 not taken.
68 node->unionScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::UNION, &node->codeLoc);
297 68 currentScope->isGenericScope = node->hasTemplateTypes;
298
299 // Visit children
300
2/2
✓ Branch 21 → 22 taken 66 times.
✓ Branch 21 → 70 taken 2 times.
68 visitChildren(node);
301
302 // Leave the union scope
303 66 currentScope = node->unionScope->parent;
304
305 // Build union qualifiers
306
2/2
✓ Branch 23 → 24 taken 32 times.
✓ Branch 23 → 48 taken 34 times.
66 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
307
2/2
✓ Branch 46 → 26 taken 32 times.
✓ Branch 46 → 47 taken 30 times.
94 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
308
2/2
✓ Branch 28 → 29 taken 30 times.
✓ Branch 28 → 32 taken 2 times.
32 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
309 30 node->qualifiers.isPublic = true;
310 else
311
2/4
✓ Branch 35 → 36 taken 2 times.
✗ Branch 35 → 74 not taken.
✓ Branch 36 → 37 taken 2 times.
✗ Branch 36 → 71 not taken.
6 throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on a union definition");
312 }
313 }
314
315 // Add the union to the symbol table
316
1/2
✓ Branch 48 → 49 taken 64 times.
✗ Branch 48 → 82 not taken.
64 node->entry = rootScope->insert(node->unionName, node);
317 // Register the name in the exported name registry
318
1/2
✓ Branch 51 → 52 taken 64 times.
✗ Branch 51 → 82 not taken.
64 sourceFile->addNameRegistryEntry(node->unionName, node->typeId, node->entry, node->unionScope, true);
319
320
1/2
✓ Branch 52 → 53 taken 64 times.
✗ Branch 52 → 81 not taken.
128 return nullptr;
321 68 }
322
323 1246 std::any SymbolTableBuilder::visitEnumDef(EnumDefNode *node) {
324 // Check if this name already exists
325
2/2
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 1244 times.
2492 if (rootScope->lookupStrict(node->enumName))
326
3/6
✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 56 not taken.
✓ Branch 8 → 9 taken 2 times.
✗ Branch 8 → 54 not taken.
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 51 not taken.
2 throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->enumName + "'");
327
328 // Create scope for the enum
329 1244 node->enumScope = currentScope =
330
2/4
✓ Branch 13 → 14 taken 1244 times.
✗ Branch 13 → 62 not taken.
✓ Branch 14 → 15 taken 1244 times.
✗ Branch 14 → 60 not taken.
1244 rootScope->createChildScope(ENUM_SCOPE_PREFIX + node->enumName, ScopeType::ENUM, &node->codeLoc);
331
332 // Visit items
333
2/2
✓ Branch 16 → 17 taken 1242 times.
✓ Branch 16 → 63 taken 2 times.
1244 visit(node->itemLst);
334
335 // Leave the enum scope
336 1242 currentScope = node->enumScope->parent;
337
338 // Build enum qualifiers
339
2/2
✓ Branch 18 → 19 taken 1163 times.
✓ Branch 18 → 43 taken 79 times.
1242 if (node->qualifierLst) {
340
2/2
✓ Branch 41 → 21 taken 1163 times.
✓ Branch 41 → 42 taken 1163 times.
3489 for (const QualifierNode *qualifier : node->qualifierLst->qualifiers) {
341
1/2
✓ Branch 23 → 24 taken 1163 times.
✗ Branch 23 → 27 not taken.
1163 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
342 1163 node->qualifiers.isPublic = true;
343 else
344 throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on an enum definition");
345 }
346 }
347
348 // Add the enum to the symbol table
349 1242 node->entry = rootScope->insert(node->enumName, node);
350 // Register the name in the exported name registry
351 1242 sourceFile->addNameRegistryEntry(node->enumName, node->typeId, node->entry, node->enumScope, true);
352
353
1/2
✓ Branch 47 → 48 taken 1242 times.
✗ Branch 47 → 74 not taken.
2484 return nullptr;
354 }
355
356 4637 std::any SymbolTableBuilder::visitGenericTypeDef(GenericTypeDefNode *node) {
357 // Check if this name already exists
358
2/2
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 4635 times.
9274 if (rootScope->lookupStrict(node->typeName))
359
3/6
✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 25 not taken.
✓ Branch 8 → 9 taken 2 times.
✗ Branch 8 → 23 not taken.
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 20 not taken.
2 throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->typeName + "'");
360
361 // Create the generic type to the symbol table
362 4635 node->entry = rootScope->insert(node->typeName, node);
363 4635 node->entry->used = true; // Generic types are always used
364
365
1/2
✓ Branch 16 → 17 taken 4635 times.
✗ Branch 16 → 29 not taken.
9270 return nullptr;
366 }
367
368 709 std::any SymbolTableBuilder::visitAliasDef(AliasDefNode *node) {
369 // Check if this name already exists
370
3/4
✓ Branch 2 → 3 taken 709 times.
✗ Branch 2 → 73 not taken.
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 707 times.
1418 if (rootScope->lookupStrict(node->aliasName))
371
3/6
✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 56 not taken.
✓ Branch 8 → 9 taken 2 times.
✗ Branch 8 → 54 not taken.
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 51 not taken.
2 throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->aliasName + "'");
372
373 // Build alias qualifiers
374
2/2
✓ Branch 13 → 14 taken 223 times.
✓ Branch 13 → 38 taken 484 times.
707 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
375
2/2
✓ Branch 36 → 16 taken 223 times.
✓ Branch 36 → 37 taken 223 times.
669 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
376
1/2
✓ Branch 18 → 19 taken 223 times.
✗ Branch 18 → 22 not taken.
223 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
377 223 node->qualifiers.isPublic = true;
378 else
379 throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on an alias definition");
380 }
381 }
382
383 // Add the alias to the symbol table
384
1/2
✓ Branch 38 → 39 taken 707 times.
✗ Branch 38 → 73 not taken.
707 node->entry = rootScope->insert(node->aliasName, node);
385 // Register the name in the exported name registry
386
1/2
✓ Branch 41 → 42 taken 707 times.
✗ Branch 41 → 73 not taken.
707 sourceFile->addNameRegistryEntry(node->aliasName, node->typeId, node->entry, rootScope, true);
387
388 // Add another symbol for the aliased type container
389
1/2
✓ Branch 42 → 43 taken 707 times.
✗ Branch 42 → 73 not taken.
707 const std::string aliasedTypeContainerName = node->aliasName + ALIAS_CONTAINER_SUFFIX;
390
1/2
✓ Branch 43 → 44 taken 707 times.
✗ Branch 43 → 71 not taken.
707 node->aliasedTypeContainerEntry = rootScope->insert(aliasedTypeContainerName, node);
391
392
1/2
✓ Branch 46 → 47 taken 707 times.
✗ Branch 46 → 70 not taken.
1414 return nullptr;
393 707 }
394
395 6249 std::any SymbolTableBuilder::visitGlobalVarDef(GlobalVarDefNode *node) {
396 // Check if this name already exists
397
2/2
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 6247 times.
12498 if (rootScope->lookupStrict(node->varName))
398
3/6
✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 43 not taken.
✓ Branch 8 → 9 taken 2 times.
✗ Branch 8 → 41 not taken.
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 38 not taken.
2 throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->varName + "'");
399
400 // Check if global already exists in an imported source file
401
5/8
✓ Branch 13 → 14 taken 6247 times.
✗ Branch 13 → 56 not taken.
✓ Branch 14 → 15 taken 6247 times.
✗ Branch 14 → 56 not taken.
✓ Branch 15 → 16 taken 6247 times.
✗ Branch 15 → 56 not taken.
✓ Branch 29 → 17 taken 11260 times.
✓ Branch 29 → 30 taken 6245 times.
17505 for (const auto &dependency : sourceFile->dependencies | std::views::values)
402
3/4
✓ Branch 18 → 19 taken 11260 times.
✗ Branch 18 → 56 not taken.
✓ Branch 19 → 20 taken 2 times.
✓ Branch 19 → 27 taken 11258 times.
11260 if (dependency->exportedNameRegistry.contains(node->varName))
403
3/6
✓ Branch 21 → 22 taken 2 times.
✗ Branch 21 → 52 not taken.
✓ Branch 22 → 23 taken 2 times.
✗ Branch 22 → 50 not taken.
✓ Branch 23 → 24 taken 2 times.
✗ Branch 23 → 47 not taken.
2 throw SemanticError(node, GLOBAL_DECLARED_TWICE, "Duplicate global variable '" + node->varName + "' in other module");
404
405 // Add the global to the symbol table
406 6245 node->entry = rootScope->insert(node->varName, node);
407 // Register the name in the exported name registry
408 6245 sourceFile->addNameRegistryEntry(node->varName, TY_INVALID, node->entry, currentScope, true);
409
410
1/2
✓ Branch 34 → 35 taken 6245 times.
✗ Branch 34 → 57 not taken.
12490 return nullptr;
411 }
412
413 9117 std::any SymbolTableBuilder::visitExtDecl(ExtDeclNode *node) {
414 // Visit attributes
415
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 6 taken 9115 times.
9117 if (node->attrs)
416
1/2
✓ Branch 3 → 4 taken 2 times.
✗ Branch 3 → 31 not taken.
2 visit(node->attrs);
417
418 // Check if this name already exists
419
2/2
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 17 taken 9115 times.
18234 if (rootScope->lookupStrict(node->extFunctionName))
420
3/6
✓ Branch 11 → 12 taken 2 times.
✗ Branch 11 → 37 not taken.
✓ Branch 12 → 13 taken 2 times.
✗ Branch 12 → 35 not taken.
✓ Branch 13 → 14 taken 2 times.
✗ Branch 13 → 32 not taken.
2 throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->extFunctionName + "'");
421
422 // Create scope for the external function (this is required in case of forceSubstantiation in FunctionManager::matchFunction)
423
2/4
✓ Branch 17 → 18 taken 9115 times.
✗ Branch 17 → 43 not taken.
✓ Branch 18 → 19 taken 9115 times.
✗ Branch 18 → 41 not taken.
9115 rootScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
424
425 // Add the external declaration to the symbol table
426 9115 node->entry = rootScope->insert(node->extFunctionName, node);
427 // Register the name in the exported name registry
428
2/2
✓ Branch 23 → 24 taken 7470 times.
✓ Branch 23 → 25 taken 1645 times.
9115 const uint64_t typeId = node->returnType ? TY_FUNCTION : TY_PROCEDURE;
429 9115 sourceFile->addNameRegistryEntry(node->extFunctionName, typeId, node->entry, rootScope, /*keepNewOnCollision=*/true);
430
431
1/2
✓ Branch 27 → 28 taken 9115 times.
✗ Branch 27 → 44 not taken.
18230 return nullptr;
432 }
433
434 18028 std::any SymbolTableBuilder::visitUnsafeBlock(UnsafeBlockNode *node) {
435 // Create scope for the unsafe block body
436 18028 node->bodyScope = currentScope =
437
2/4
✓ Branch 2 → 3 taken 18028 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 18028 times.
✗ Branch 3 → 11 not taken.
18028 currentScope->createChildScope(node->getScopeId(), ScopeType::UNSAFE_BODY, &node->body->codeLoc);
438
439 // Visit body
440
1/2
✓ Branch 5 → 6 taken 18028 times.
✗ Branch 5 → 14 not taken.
18028 visit(node->body);
441
442 // Leave thread body scope
443 18028 currentScope = node->bodyScope->parent;
444
445
1/2
✓ Branch 7 → 8 taken 18028 times.
✗ Branch 7 → 15 not taken.
36056 return nullptr;
446 }
447
448 6628 std::any SymbolTableBuilder::visitForLoop(ForLoopNode *node) {
449 // Create scope for the loop body
450
2/4
✓ Branch 2 → 3 taken 6628 times.
✗ Branch 2 → 15 not taken.
✓ Branch 3 → 4 taken 6628 times.
✗ Branch 3 → 13 not taken.
6628 node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FOR_BODY, &node->body->codeLoc);
451
452 // Visit loop variable declaration
453
1/2
✓ Branch 5 → 6 taken 6628 times.
✗ Branch 5 → 16 not taken.
6628 visit(node->initDecl);
454
455 // Visit body
456
1/2
✓ Branch 7 → 8 taken 6628 times.
✗ Branch 7 → 17 not taken.
6628 visit(node->body);
457
458 // Leave for body scope
459 6628 currentScope = node->bodyScope->parent;
460
461
1/2
✓ Branch 9 → 10 taken 6628 times.
✗ Branch 9 → 18 not taken.
13256 return nullptr;
462 }
463
464 831 std::any SymbolTableBuilder::visitForeachLoop(ForeachLoopNode *node) {
465 // Create scope for the loop body
466 831 node->bodyScope = currentScope =
467
2/4
✓ Branch 2 → 3 taken 831 times.
✗ Branch 2 → 19 not taken.
✓ Branch 3 → 4 taken 831 times.
✗ Branch 3 → 17 not taken.
831 currentScope->createChildScope(node->getScopeId(), ScopeType::FOREACH_BODY, &node->body->codeLoc);
468
469 // Visit index variable declaration
470
2/2
✓ Branch 5 → 6 taken 124 times.
✓ Branch 5 → 9 taken 707 times.
831 if (node->idxVarDecl)
471
1/2
✓ Branch 6 → 7 taken 124 times.
✗ Branch 6 → 20 not taken.
124 visit(node->idxVarDecl);
472
473 // Visit item variable declaration
474
1/2
✓ Branch 9 → 10 taken 831 times.
✗ Branch 9 → 21 not taken.
831 visit(node->itemVarDecl);
475
476 // Visit body
477
1/2
✓ Branch 11 → 12 taken 831 times.
✗ Branch 11 → 22 not taken.
831 visit(node->body);
478
479 // Leave foreach body scope
480 831 currentScope = node->bodyScope->parent;
481
482
1/2
✓ Branch 13 → 14 taken 831 times.
✗ Branch 13 → 23 not taken.
1662 return nullptr;
483 }
484
485 3125 std::any SymbolTableBuilder::visitWhileLoop(WhileLoopNode *node) {
486 // Create scope for the loop body
487 3125 node->bodyScope = currentScope =
488
2/4
✓ Branch 2 → 3 taken 3125 times.
✗ Branch 2 → 15 not taken.
✓ Branch 3 → 4 taken 3125 times.
✗ Branch 3 → 13 not taken.
3125 currentScope->createChildScope(node->getScopeId(), ScopeType::WHILE_BODY, &node->body->codeLoc);
489
490 // Visit condition
491
1/2
✓ Branch 5 → 6 taken 3125 times.
✗ Branch 5 → 16 not taken.
3125 visit(node->condition);
492
493 // Visit body
494
1/2
✓ Branch 7 → 8 taken 3125 times.
✗ Branch 7 → 17 not taken.
3125 visit(node->body);
495
496 // Leave while body scope
497 3125 currentScope = node->bodyScope->parent;
498
499
1/2
✓ Branch 9 → 10 taken 3125 times.
✗ Branch 9 → 18 not taken.
6250 return nullptr;
500 }
501
502 33 std::any SymbolTableBuilder::visitDoWhileLoop(DoWhileLoopNode *node) {
503 // Create scope for the loop body
504 33 node->bodyScope = currentScope =
505
2/4
✓ Branch 2 → 3 taken 33 times.
✗ Branch 2 → 15 not taken.
✓ Branch 3 → 4 taken 33 times.
✗ Branch 3 → 13 not taken.
33 currentScope->createChildScope(node->getScopeId(), ScopeType::WHILE_BODY, &node->body->codeLoc);
506
507 // Visit condition
508
1/2
✓ Branch 5 → 6 taken 33 times.
✗ Branch 5 → 16 not taken.
33 visit(node->condition);
509
510 // Visit body
511
1/2
✓ Branch 7 → 8 taken 33 times.
✗ Branch 7 → 17 not taken.
33 visit(node->body);
512
513 // Leave do-while body scope
514 33 currentScope = node->bodyScope->parent;
515
516
1/2
✓ Branch 9 → 10 taken 33 times.
✗ Branch 9 → 18 not taken.
66 return nullptr;
517 }
518
519 39180 std::any SymbolTableBuilder::visitIfStmt(IfStmtNode *node) {
520 // Create scope for the then body
521 39180 node->thenBodyScope = currentScope =
522
2/4
✓ Branch 2 → 3 taken 39180 times.
✗ Branch 2 → 27 not taken.
✓ Branch 3 → 4 taken 39180 times.
✗ Branch 3 → 25 not taken.
39180 currentScope->createChildScope(node->getScopeId(), ScopeType::IF_ELSE_BODY, &node->thenBody->codeLoc);
523
524 // Visit condition
525
1/2
✓ Branch 5 → 6 taken 39180 times.
✗ Branch 5 → 28 not taken.
39180 visit(node->condition);
526
527 // Visit then body (manifestations do not exist yet, so both branches are always visited here)
528
1/2
✓ Branch 8 → 9 taken 39180 times.
✗ Branch 8 → 12 not taken.
39180 if (node->doCompileThenBranch(manIdx))
529
1/2
✓ Branch 9 → 10 taken 39180 times.
✗ Branch 9 → 29 not taken.
39180 visit(node->thenBody);
530
531 // Leave then body scope
532 39180 currentScope = node->thenBodyScope->parent;
533
534 // Visit else stmt
535
5/6
✓ Branch 13 → 14 taken 39180 times.
✗ Branch 13 → 16 not taken.
✓ Branch 14 → 15 taken 3029 times.
✓ Branch 14 → 16 taken 36151 times.
✓ Branch 17 → 18 taken 3029 times.
✓ Branch 17 → 21 taken 36151 times.
39180 if (node->doCompileElseBranch(manIdx) && node->elseStmt)
536
1/2
✓ Branch 18 → 19 taken 3029 times.
✗ Branch 18 → 30 not taken.
3029 visit(node->elseStmt);
537
538
1/2
✓ Branch 21 → 22 taken 39180 times.
✗ Branch 21 → 31 not taken.
78360 return nullptr;
539 }
540
541 3029 std::any SymbolTableBuilder::visitElseStmt(ElseStmtNode *node) {
542 // Visit if statement in the case of an else if branch
543
2/2
✓ Branch 2 → 3 taken 1235 times.
✓ Branch 2 → 8 taken 1794 times.
3029 if (node->isElseIf) {
544
1/2
✓ Branch 3 → 4 taken 1235 times.
✗ Branch 3 → 17 not taken.
1235 visit(node->ifStmt);
545
1/2
✓ Branch 5 → 6 taken 1235 times.
✗ Branch 5 → 18 not taken.
2470 return nullptr;
546 }
547
548 // Create scope for the else body
549 1794 node->elseBodyScope = currentScope =
550
2/4
✓ Branch 8 → 9 taken 1794 times.
✗ Branch 8 → 21 not taken.
✓ Branch 9 → 10 taken 1794 times.
✗ Branch 9 → 19 not taken.
1794 currentScope->createChildScope(node->getScopeId(), ScopeType::IF_ELSE_BODY, &node->body->codeLoc);
551
552 // Visit else body
553
1/2
✓ Branch 11 → 12 taken 1794 times.
✗ Branch 11 → 22 not taken.
1794 visit(node->body);
554
555 // Leave else body scope
556 1794 currentScope = node->elseBodyScope->parent;
557
558
1/2
✓ Branch 13 → 14 taken 1794 times.
✗ Branch 13 → 23 not taken.
3588 return nullptr;
559 }
560
561 1539 std::any SymbolTableBuilder::visitCaseBranch(CaseBranchNode *node) {
562 // Create scope for the case branch
563
2/4
✓ Branch 2 → 3 taken 1539 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 1539 times.
✗ Branch 3 → 11 not taken.
1539 node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::CASE_BODY, &node->body->codeLoc);
564
565 // Visit case body
566
1/2
✓ Branch 5 → 6 taken 1539 times.
✗ Branch 5 → 14 not taken.
1539 visit(node->body);
567
568 // Leave case body scope
569 1539 currentScope = node->bodyScope->parent;
570
571
1/2
✓ Branch 7 → 8 taken 1539 times.
✗ Branch 7 → 15 not taken.
3078 return nullptr;
572 }
573
574 157 std::any SymbolTableBuilder::visitDefaultBranch(DefaultBranchNode *node) {
575 // Create scope for the default branch
576 157 node->bodyScope = currentScope =
577
2/4
✓ Branch 2 → 3 taken 157 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 157 times.
✗ Branch 3 → 11 not taken.
157 currentScope->createChildScope(node->getScopeId(), ScopeType::DEFAULT_BODY, &node->body->codeLoc);
578
579 // Visit default body
580
1/2
✓ Branch 5 → 6 taken 157 times.
✗ Branch 5 → 14 not taken.
157 visit(node->body);
581
582 // Leave default body scope
583 157 currentScope = node->bodyScope->parent;
584
585
1/2
✓ Branch 7 → 8 taken 157 times.
✗ Branch 7 → 15 not taken.
314 return nullptr;
586 }
587
588 123 std::any SymbolTableBuilder::visitAnonymousBlockStmt(AnonymousBlockStmtNode *node) {
589 // Create scope for the anonymous block body
590 123 node->bodyScope = currentScope =
591
2/4
✓ Branch 2 → 3 taken 123 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 123 times.
✗ Branch 3 → 11 not taken.
123 currentScope->createChildScope(node->getScopeId(), ScopeType::ANONYMOUS_BLOCK_BODY, &node->body->codeLoc);
592
593 // Visit body
594
1/2
✓ Branch 5 → 6 taken 123 times.
✗ Branch 5 → 14 not taken.
123 visit(node->body);
595
596 // Leave anonymous block body scope
597 123 currentScope = node->bodyScope->parent;
598
599
1/2
✓ Branch 7 → 8 taken 123 times.
✗ Branch 7 → 15 not taken.
246 return nullptr;
600 }
601
602 11076 std::any SymbolTableBuilder::visitEnumItem(EnumItemNode *node) {
603 // Check if enum item already exists in the same scope.
604
3/4
✓ Branch 2 → 3 taken 11076 times.
✗ Branch 2 → 42 not taken.
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 11074 times.
22152 if (currentScope->lookupStrict(node->itemName))
605
3/6
✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 32 not taken.
✓ Branch 8 → 9 taken 2 times.
✗ Branch 8 → 30 not taken.
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 27 not taken.
2 throw SemanticError(node, VARIABLE_DECLARED_TWICE, "The enum item '" + node->itemName + "' was declared more than once");
606
607 // Add enum item entry to symbol table
608
1/2
✓ Branch 13 → 14 taken 11074 times.
✗ Branch 13 → 42 not taken.
11074 SymbolTableEntry *enumItemEntry = currentScope->insert(node->itemName, node);
609
610 // Add external registry entry
611
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 11074 times.
11074 assert(node->enumDef != nullptr);
612
2/4
✓ Branch 18 → 19 taken 11074 times.
✗ Branch 18 → 38 not taken.
✓ Branch 19 → 20 taken 11074 times.
✗ Branch 19 → 36 not taken.
11074 const std::string name = node->enumDef->enumName + SCOPE_ACCESS_TOKEN + node->itemName;
613
1/2
✓ Branch 21 → 22 taken 11074 times.
✗ Branch 21 → 40 not taken.
11074 sourceFile->addNameRegistryEntry(name, TY_INT, enumItemEntry, currentScope, true);
614
615
1/2
✓ Branch 22 → 23 taken 11074 times.
✗ Branch 22 → 39 not taken.
22148 return nullptr;
616 11074 }
617
618 15745 std::any SymbolTableBuilder::visitField(FieldNode *node) {
619 // Check if field already exists in the same scope.
620
2/2
✓ Branch 5 → 6 taken 4 times.
✓ Branch 5 → 13 taken 15741 times.
31490 if (currentScope->lookupStrict(node->fieldName))
621
3/6
✓ Branch 7 → 8 taken 4 times.
✗ Branch 7 → 25 not taken.
✓ Branch 8 → 9 taken 4 times.
✗ Branch 8 → 23 not taken.
✓ Branch 9 → 10 taken 4 times.
✗ Branch 9 → 20 not taken.
4 throw SemanticError(node, VARIABLE_DECLARED_TWICE, "The field '" + node->fieldName + "' was declared more than once");
622
623 // Add field entry to symbol table
624 15741 currentScope->insert(node->fieldName, node);
625
626
1/2
✓ Branch 16 → 17 taken 15741 times.
✗ Branch 16 → 29 not taken.
31482 return nullptr;
627 }
628
629 4897 std::any SymbolTableBuilder::visitSignature(SignatureNode *node) {
630 // Build signature qualifiers
631
2/2
✓ Branch 2 → 3 taken 4805 times.
✓ Branch 2 → 32 taken 92 times.
4897 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
632
2/2
✓ Branch 30 → 5 taken 5077 times.
✓ Branch 30 → 31 taken 4805 times.
14687 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
633
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 5077 times.
5077 if (qualifier->type == QualifierNode::QualifierType::TY_INLINE)
634 node->signatureQualifiers.isInline = true;
635
2/2
✓ Branch 9 → 10 taken 4805 times.
✓ Branch 9 → 11 taken 272 times.
5077 else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
636 4805 node->signatureQualifiers.isPublic = true;
637
1/2
✓ Branch 11 → 12 taken 272 times.
✗ Branch 11 → 13 not taken.
272 else if (qualifier->type == QualifierNode::QualifierType::TY_CONST)
638 272 node->signatureQualifiers.isConst = true;
639 else
640 throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on a signature definition");
641 }
642 }
643
644 // Add signature entry to symbol table. We append the code location to disambiguate overloaded signatures
645 // (e.g. an interface declaring `getName()` and `getName(bool)`).
646
1/2
✓ Branch 32 → 33 taken 4897 times.
✗ Branch 32 → 53 not taken.
9794 node->entry = currentScope->insert(Function::getSymbolTableEntryName(node->methodName, node->codeLoc), node);
647
648
1/2
✓ Branch 37 → 38 taken 4897 times.
✗ Branch 37 → 54 not taken.
9794 return nullptr;
649 }
650
651 138875 std::any SymbolTableBuilder::visitDeclStmt(DeclStmtNode *node) {
652 // Check if variable already exists in the same scope.
653
2/2
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 138873 times.
277750 if (currentScope->lookupStrict(node->varName))
654
3/6
✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 29 not taken.
✓ Branch 8 → 9 taken 2 times.
✗ Branch 8 → 27 not taken.
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 24 not taken.
2 throw SemanticError(node, VARIABLE_DECLARED_TWICE, "The variable '" + node->varName + "' was declared more than once");
655
656 // Visit the right side
657
2/2
✓ Branch 13 → 14 taken 50511 times.
✓ Branch 13 → 17 taken 88362 times.
138873 if (node->hasAssignment)
658
1/2
✓ Branch 14 → 15 taken 50511 times.
✗ Branch 14 → 33 not taken.
50511 visit(node->assignExpr);
659
660 // Add variable entry to symbol table
661 138873 SymbolTableEntry *varEntry = currentScope->insert(node->varName, node);
662 138873 varEntry->isParam = node->isFctParam;
663
664
1/2
✓ Branch 20 → 21 taken 138873 times.
✗ Branch 20 → 34 not taken.
277746 return nullptr;
665 }
666
667 2218 std::any SymbolTableBuilder::visitModAttr(ModAttrNode *node) {
668 // Visit attributes
669
2/2
✓ Branch 2 → 3 taken 2216 times.
✓ Branch 2 → 126 taken 2 times.
2218 visitChildren(node);
670
671 // Retrieve attributes
672 2216 const AttrLstNode *attrs = node->attrLst;
673
674 // Collect linker flags
675 2216 std::vector<const CompileTimeValue *> linkerFlagValues;
676 // core.linker.flag
677
2/4
✓ Branch 6 → 7 taken 2216 times.
✗ Branch 6 → 129 not taken.
✓ Branch 7 → 8 taken 2216 times.
✗ Branch 7 → 127 not taken.
4432 std::vector<const CompileTimeValue *> values = attrs->getAttrValuesByName(ATTR_CORE_LINKER_FLAG);
678
1/2
✓ Branch 16 → 17 taken 2216 times.
✗ Branch 16 → 133 not taken.
4432 linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end());
679 // core.linux.linker.flag
680 2216 const llvm::Triple &targetTriple = sourceFile->targetMachine->getTargetTriple();
681
2/2
✓ Branch 20 → 21 taken 2192 times.
✓ Branch 20 → 37 taken 24 times.
2216 if (targetTriple.isOSLinux()) {
682
2/4
✓ Branch 23 → 24 taken 2192 times.
✗ Branch 23 → 137 not taken.
✓ Branch 24 → 25 taken 2192 times.
✗ Branch 24 → 135 not taken.
4384 values = attrs->getAttrValuesByName(ATTR_CORE_LINUX_LINKER_FLAG);
683
1/2
✓ Branch 35 → 36 taken 2192 times.
✗ Branch 35 → 142 not taken.
4384 linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end());
684 }
685 // core.darwin.linker.flag
686
3/4
✓ Branch 37 → 38 taken 2216 times.
✗ Branch 37 → 187 not taken.
✓ Branch 38 → 39 taken 12 times.
✓ Branch 38 → 55 taken 2204 times.
2216 if (targetTriple.isOSDarwin()) {
687
2/4
✓ Branch 41 → 42 taken 12 times.
✗ Branch 41 → 146 not taken.
✓ Branch 42 → 43 taken 12 times.
✗ Branch 42 → 144 not taken.
24 values = attrs->getAttrValuesByName(ATTR_CORE_DARWIN_LINKER_FLAG);
688
1/2
✓ Branch 53 → 54 taken 12 times.
✗ Branch 53 → 151 not taken.
24 linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end());
689 }
690 // core.windows.linker.flag
691
2/2
✓ Branch 56 → 57 taken 12 times.
✓ Branch 56 → 73 taken 2204 times.
2216 if (targetTriple.isOSWindows()) {
692
2/4
✓ Branch 59 → 60 taken 12 times.
✗ Branch 59 → 155 not taken.
✓ Branch 60 → 61 taken 12 times.
✗ Branch 60 → 153 not taken.
24 values = attrs->getAttrValuesByName(ATTR_CORE_WINDOWS_LINKER_FLAG);
693
1/2
✓ Branch 71 → 72 taken 12 times.
✗ Branch 71 → 160 not taken.
24 linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end());
694 }
695
2/2
✓ Branch 89 → 75 taken 2998 times.
✓ Branch 89 → 90 taken 2216 times.
7430 for (const CompileTimeValue *value : linkerFlagValues) {
696
1/2
✓ Branch 77 → 78 taken 2998 times.
✗ Branch 77 → 162 not taken.
2998 const std::string &flag = resourceManager.compileTimeStringValues.at(value->stringValueOffset);
697
1/2
✓ Branch 78 → 79 taken 2998 times.
✗ Branch 78 → 162 not taken.
2998 resourceManager.linker.addLinkerFlag(flag);
698
1/2
✓ Branch 79 → 80 taken 2998 times.
✗ Branch 79 → 162 not taken.
2998 sourceFile->sourceLinkerFlags.push_back(flag);
699 }
700
701 // core.linker.additionalSource
702
4/6
✓ Branch 90 → 91 taken 2216 times.
✗ Branch 90 → 165 not taken.
✓ Branch 91 → 92 taken 2216 times.
✗ Branch 91 → 163 not taken.
✓ Branch 116 → 94 taken 30 times.
✓ Branch 116 → 117 taken 2214 times.
4460 for (const CompileTimeValue *value : attrs->getAttrValuesByName(ATTR_CORE_LINKER_ADDITIONAL_SOURCE)) {
703
1/2
✓ Branch 96 → 97 taken 30 times.
✗ Branch 96 → 178 not taken.
30 const std::string &stringValue = resourceManager.compileTimeStringValues.at(value->stringValueOffset);
704
3/6
✓ Branch 97 → 98 taken 30 times.
✗ Branch 97 → 172 not taken.
✓ Branch 98 → 99 taken 30 times.
✗ Branch 98 → 169 not taken.
✓ Branch 99 → 100 taken 30 times.
✗ Branch 99 → 167 not taken.
30 const std::filesystem::path additionalSourcePath = sourceFile->filePath.parent_path() / stringValue;
705
3/4
✓ Branch 102 → 103 taken 30 times.
✗ Branch 102 → 175 not taken.
✓ Branch 103 → 104 taken 28 times.
✓ Branch 103 → 173 taken 2 times.
32 resourceManager.linker.addAdditionalSourcePath(additionalSourcePath);
706
1/2
✓ Branch 105 → 106 taken 28 times.
✗ Branch 105 → 176 not taken.
28 sourceFile->sourceAdditionalSourcePaths.push_back(additionalSourcePath);
707 2248 }
708
709
1/2
✓ Branch 120 → 121 taken 2214 times.
✗ Branch 120 → 186 not taken.
4428 return nullptr;
710 2218 }
711
712 8256 std::any SymbolTableBuilder::visitAttr(AttrNode *node) {
713 // Check if this attribute exists
714
1/2
✓ Branch 2 → 3 taken 8256 times.
✗ Branch 2 → 63 not taken.
8256 const auto it = ATTR_CONFIGS.find(node->key);
715
2/2
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 8254 times.
8256 if (it == ATTR_CONFIGS.end())
716
3/6
✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 40 not taken.
✓ Branch 8 → 9 taken 2 times.
✗ Branch 8 → 38 not taken.
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 35 not taken.
2 throw SemanticError(node, UNKNOWN_ATTR, "Unknown attribute '" + node->key + "'");
717
718 // Check if the target is correct
719 8254 const auto &[target, type] = it->second;
720
2/2
✓ Branch 14 → 15 taken 2 times.
✓ Branch 14 → 22 taken 8252 times.
8254 if ((node->target & target) == 0)
721
3/6
✓ Branch 16 → 17 taken 2 times.
✗ Branch 16 → 49 not taken.
✓ Branch 17 → 18 taken 2 times.
✗ Branch 17 → 47 not taken.
✓ Branch 18 → 19 taken 2 times.
✗ Branch 18 → 44 not taken.
2 throw SemanticError(node, INVALID_ATTR_TARGET, "Attribute '" + node->key + "' cannot be used on this target");
722
723 // Check if a value is present
724
4/4
✓ Branch 22 → 23 taken 1682 times.
✓ Branch 22 → 31 taken 6570 times.
✓ Branch 23 → 24 taken 2 times.
✓ Branch 23 → 31 taken 1680 times.
8252 if (!node->value && type != AttrNode::AttrType::TYPE_BOOL)
725
3/6
✓ Branch 25 → 26 taken 2 times.
✗ Branch 25 → 58 not taken.
✓ Branch 26 → 27 taken 2 times.
✗ Branch 26 → 56 not taken.
✓ Branch 27 → 28 taken 2 times.
✗ Branch 27 → 53 not taken.
2 throw SemanticError(node, MISSING_ATTR_VALUE, "Attribute '" + node->key + "' requires a value");
726
727
1/2
✓ Branch 31 → 32 taken 8250 times.
✗ Branch 31 → 62 not taken.
16500 return nullptr;
728 }
729
730 109 std::any SymbolTableBuilder::visitLambdaFunc(LambdaFuncNode *node) {
731 // Create scope for the lambda body
732 109 const CodeLoc &codeLoc = node->body->codeLoc;
733
2/4
✓ Branch 2 → 3 taken 109 times.
✗ Branch 2 → 47 not taken.
✓ Branch 3 → 4 taken 109 times.
✗ Branch 3 → 45 not taken.
109 node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::LAMBDA_BODY, &codeLoc);
734 // Requires capturing because the LLVM IR will end up in a separate function
735 109 currentScope->symbolTable.setCapturingRequired();
736 // Set to async scope if this is an async lambda
737
4/18
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 13 taken 109 times.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 48 not taken.
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 48 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 13 not taken.
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 109 times.
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 19 taken 109 times.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 27 taken 109 times.
✗ Branch 48 → 49 not taken.
✗ Branch 48 → 50 not taken.
✗ Branch 52 → 53 not taken.
✗ Branch 52 → 55 not taken.
109 if (node->lambdaAttr && node->lambdaAttr->attrLst->hasAttr(ATTR_ASYNC))
738 node->bodyScope->isAsyncScope = node->lambdaAttr->attrLst->getAttrValueByName(ATTR_ASYNC)->boolValue;
739
740 // Create symbol for 'result' variable
741
1/2
✓ Branch 29 → 30 taken 109 times.
✗ Branch 29 → 65 not taken.
327 currentScope->insert(RETURN_VARIABLE_NAME, node);
742
743 // Create symbols for the parameters
744
2/2
✓ Branch 35 → 36 taken 99 times.
✓ Branch 35 → 39 taken 10 times.
109 if (node->hasParams)
745
1/2
✓ Branch 36 → 37 taken 99 times.
✗ Branch 36 → 69 not taken.
99 visit(node->paramLst);
746
747 // Visit body
748
1/2
✓ Branch 39 → 40 taken 109 times.
✗ Branch 39 → 70 not taken.
109 visit(node->body);
749
750 // Leave anonymous block body scope
751 109 currentScope = node->bodyScope->parent;
752
753
1/2
✓ Branch 41 → 42 taken 109 times.
✗ Branch 41 → 71 not taken.
218 return nullptr;
754 }
755
756 150 std::any SymbolTableBuilder::visitLambdaProc(LambdaProcNode *node) {
757 // Create scope for the lambda body
758 150 const CodeLoc &codeLoc = node->body->codeLoc;
759
2/4
✓ Branch 2 → 3 taken 150 times.
✗ Branch 2 → 39 not taken.
✓ Branch 3 → 4 taken 150 times.
✗ Branch 3 → 37 not taken.
150 node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::LAMBDA_BODY, &codeLoc);
760 // Requires capturing because the LLVM IR will end up in a separate function
761 150 currentScope->symbolTable.setCapturingRequired();
762 // Set to async scope if this is an async lambda
763
11/18
✓ Branch 6 → 7 taken 16 times.
✓ Branch 6 → 13 taken 134 times.
✓ Branch 9 → 10 taken 16 times.
✗ Branch 9 → 40 not taken.
✓ Branch 10 → 11 taken 16 times.
✗ Branch 10 → 40 not taken.
✓ Branch 11 → 12 taken 16 times.
✗ Branch 11 → 13 not taken.
✓ Branch 14 → 15 taken 16 times.
✓ Branch 14 → 16 taken 134 times.
✓ Branch 16 → 17 taken 16 times.
✓ Branch 16 → 19 taken 134 times.
✓ Branch 19 → 20 taken 16 times.
✓ Branch 19 → 27 taken 134 times.
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 42 not taken.
✗ Branch 44 → 45 not taken.
✗ Branch 44 → 47 not taken.
182 if (node->lambdaAttr && node->lambdaAttr->attrLst->hasAttr(ATTR_ASYNC))
764
2/4
✓ Branch 22 → 23 taken 16 times.
✗ Branch 22 → 51 not taken.
✓ Branch 23 → 24 taken 16 times.
✗ Branch 23 → 49 not taken.
48 node->bodyScope->isAsyncScope = node->lambdaAttr->attrLst->getAttrValueByName(ATTR_ASYNC)->boolValue;
765
766 // Create symbols for the parameters
767
2/2
✓ Branch 27 → 28 taken 118 times.
✓ Branch 27 → 31 taken 32 times.
150 if (node->hasParams)
768
1/2
✓ Branch 28 → 29 taken 118 times.
✗ Branch 28 → 55 not taken.
118 visit(node->paramLst);
769
770 // Visit body
771
1/2
✓ Branch 31 → 32 taken 150 times.
✗ Branch 31 → 56 not taken.
150 visit(node->body);
772
773 // Leave anonymous block body scope
774 150 currentScope = node->bodyScope->parent;
775
776
1/2
✓ Branch 33 → 34 taken 150 times.
✗ Branch 33 → 57 not taken.
300 return nullptr;
777 }
778
779 2 std::any SymbolTableBuilder::visitLambdaExpr(LambdaExprNode *node) {
780 // Create scope for the anonymous block body
781 2 const CodeLoc &codeLoc = node->lambdaExpr->codeLoc;
782
2/4
✓ Branch 2 → 3 taken 2 times.
✗ Branch 2 → 18 not taken.
✓ Branch 3 → 4 taken 2 times.
✗ Branch 3 → 16 not taken.
2 node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::LAMBDA_BODY, &codeLoc);
783 // Requires capturing because the LLVM IR will end up in a separate function
784 2 currentScope->symbolTable.setCapturingRequired();
785
786 // Create symbols for the parameters
787
1/2
✓ Branch 6 → 7 taken 2 times.
✗ Branch 6 → 10 not taken.
2 if (node->hasParams)
788
1/2
✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 19 not taken.
2 visit(node->paramLst);
789
790 // Visit lambda expression
791
1/2
✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 20 not taken.
2 visit(node->lambdaExpr);
792
793 // Leave anonymous block body scope
794 2 currentScope = node->bodyScope->parent;
795
796
1/2
✓ Branch 12 → 13 taken 2 times.
✗ Branch 12 → 21 not taken.
4 return nullptr;
797 }
798
799 } // namespace spice::compiler
800