GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 97.1% 400 / 0 / 412
Functions: 100.0% 36 / 0 / 36
Branches: 59.0% 459 / 0 / 778

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 7302 SymbolTableBuilder::SymbolTableBuilder(GlobalResourceManager &resourceManager, SourceFile *sourceFile)
17 7302 : CompilerPass(resourceManager, sourceFile), rootScope(sourceFile->globalScope.get()) {}
18
19 7302 std::any SymbolTableBuilder::visitEntry(EntryNode *node) {
20 // Initialize
21 7302 currentScope = rootScope;
22
23 // Visit children
24
2/2
✓ Branch 2 → 3 taken 7264 times.
✓ Branch 2 → 23 taken 38 times.
7302 visitChildren(node);
25
26 // Check if the main function exists
27
4/4
✓ Branch 4 → 5 taken 7258 times.
✓ Branch 4 → 7 taken 6 times.
✓ Branch 5 → 6 taken 7246 times.
✓ Branch 5 → 7 taken 12 times.
7264 const bool mainFctRequired = cliOptions.outputContainer == OutputContainer::EXECUTABLE && !cliOptions.noEntryFct;
28
6/6
✓ Branch 8 → 9 taken 1277 times.
✓ Branch 8 → 19 taken 5987 times.
✓ Branch 9 → 10 taken 1261 times.
✓ Branch 9 → 19 taken 16 times.
✓ Branch 10 → 11 taken 4 times.
✓ Branch 10 → 19 taken 1257 times.
7264 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 7260 times.
✗ Branch 19 → 33 not taken.
14520 return nullptr;
32 }
33
34 1269 std::any SymbolTableBuilder::visitMainFctDef(MainFctDefNode *node) {
35 // Visit attributes
36
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 6 taken 1267 times.
1269 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 1267 times.
✗ Branch 8 → 55 not taken.
✓ Branch 14 → 15 taken 2 times.
✓ Branch 14 → 23 taken 1265 times.
5068 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 1265 times.
✗ Branch 25 → 70 not taken.
3795 SymbolTableEntry *mainFctEntry = currentScope->insert(MAIN_FUNCTION_NAME, node);
45 1265 mainFctEntry->used = true;
46
47 // Create scope for main function body
48
1/2
✓ Branch 31 → 32 taken 1265 times.
✗ Branch 31 → 85 not taken.
1265 const std::string &scopeId = MainFctDefNode::getScopeId();
49
1/2
✓ Branch 32 → 33 taken 1265 times.
✗ Branch 32 → 83 not taken.
1265 node->bodyScope = currentScope = rootScope->createChildScope(scopeId, ScopeType::FUNC_PROC_BODY, &node->codeLoc);
50 1265 currentScope->isGenericScope = false;
51
52 // Declare variable for the return value in the function scope
53
1/2
✓ Branch 35 → 36 taken 1265 times.
✗ Branch 35 → 76 not taken.
3795 SymbolTableEntry *resultVarEntry = node->bodyScope->insert(RETURN_VARIABLE_NAME, node);
54 1265 resultVarEntry->used = true;
55
56 // Visit arguments in new scope
57
2/2
✓ Branch 41 → 42 taken 14 times.
✓ Branch 41 → 45 taken 1251 times.
1265 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 1263 times.
✓ Branch 45 → 81 taken 2 times.
1265 visit(node->body);
62
63 // Return to root scope
64 1263 currentScope = rootScope;
65
66 1263 hasMainFunction = true;
67
1/2
✓ Branch 47 → 48 taken 1263 times.
✗ Branch 47 → 82 not taken.
2526 return nullptr;
68 1265 }
69
70 65726 std::any SymbolTableBuilder::visitFctDef(FctDefNode *node) {
71 // Visit attributes
72
2/2
✓ Branch 2 → 3 taken 2032 times.
✓ Branch 2 → 6 taken 63694 times.
65726 if (node->attrs)
73
1/2
✓ Branch 3 → 4 taken 2032 times.
✗ Branch 3 → 98 not taken.
2032 visit(node->attrs);
74
75 // Build function qualifiers
76
2/2
✓ Branch 6 → 7 taken 62909 times.
✓ Branch 6 → 36 taken 2817 times.
65726 if (const QualifierLstNode *qualifierLst = node->qualifierLst; qualifierLst) {
77
2/2
✓ Branch 34 → 9 taken 80740 times.
✓ Branch 34 → 35 taken 62909 times.
206558 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
78
2/2
✓ Branch 11 → 12 taken 17625 times.
✓ Branch 11 → 13 taken 63115 times.
80740 if (qualifier->type == QualifierNode::QualifierType::TY_INLINE)
79 17625 node->qualifiers.isInline = true;
80
2/2
✓ Branch 13 → 14 taken 62537 times.
✓ Branch 13 → 15 taken 578 times.
63115 else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
81 62537 node->qualifiers.isPublic = true;
82
1/2
✓ Branch 15 → 16 taken 578 times.
✗ Branch 15 → 17 not taken.
578 else if (qualifier->type == QualifierNode::QualifierType::TY_CONST)
83 578 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 38033 times.
✓ Branch 36 → 51 taken 27693 times.
65726 if (node->isMethod) {
91
1/2
✓ Branch 38 → 39 taken 38033 times.
✗ Branch 38 → 109 not taken.
38033 const std::string scopeName = Struct::getScopeName(node->name->structName);
92
1/2
✓ Branch 40 → 41 taken 38033 times.
✗ Branch 40 → 121 not taken.
38033 node->structScope = currentScope = currentScope->getChildScope(scopeName);
93
1/2
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 49 taken 38033 times.
38033 if (!currentScope)
94 ✗ throw SemanticError(node, REFERENCED_UNDEFINED_STRUCT, "Struct '" + node->name->structName + "' could not be found");
95 38033 }
96
97 // Create scope for the function
98
2/4
✓ Branch 51 → 52 taken 65726 times.
✗ Branch 51 → 126 not taken.
✓ Branch 52 → 53 taken 65726 times.
✗ Branch 52 → 124 not taken.
65726 node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
99
6/6
✓ Branch 54 → 55 taken 60048 times.
✓ Branch 54 → 57 taken 5678 times.
✓ Branch 55 → 56 taken 37108 times.
✓ Branch 55 → 58 taken 22940 times.
✓ Branch 56 → 57 taken 7685 times.
✓ Branch 56 → 58 taken 29423 times.
65726 currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope);
100
101 // Create symbol for 'this' variable
102
2/2
✓ Branch 59 → 60 taken 38033 times.
✓ Branch 59 → 69 taken 27693 times.
65726 if (node->isMethod)
103
1/2
✓ Branch 62 → 63 taken 38033 times.
✗ Branch 62 → 129 not taken.
152132 currentScope->insert(THIS_VARIABLE_NAME, node);
104
105 // Create symbol for 'result' variable
106
1/2
✓ Branch 71 → 72 taken 65726 times.
✗ Branch 71 → 135 not taken.
197178 currentScope->insert(RETURN_VARIABLE_NAME, node);
107
108 // Create symbols for the parameters
109
2/2
✓ Branch 77 → 78 taken 43658 times.
✓ Branch 77 → 81 taken 22068 times.
65726 if (node->hasParams)
110
1/2
✓ Branch 78 → 79 taken 43658 times.
✗ Branch 78 → 139 not taken.
43658 visit(node->paramLst);
111
112 // Visit the function body
113
1/2
✓ Branch 81 → 82 taken 65726 times.
✗ Branch 81 → 140 not taken.
65726 visit(node->body);
114
115 // Leave function body scope
116 65726 currentScope = node->scope->parent;
117
118 // Insert symbol for function into the symbol table
119
1/2
✓ Branch 83 → 84 taken 65726 times.
✗ Branch 83 → 143 not taken.
131452 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 65726 const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName);
124
3/4
✓ Branch 89 → 90 taken 11549 times.
✓ Branch 89 → 91 taken 54177 times.
✓ Branch 90 → 91 taken 11549 times.
✗ Branch 90 → 92 not taken.
65726 if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry)
125 65726 sourceFile->addNameRegistryEntry(node->name->fqName, TY_FUNCTION, node->entry, currentScope, true);
126
127 // Leave the struct scope
128
2/2
✓ Branch 92 → 93 taken 38033 times.
✓ Branch 92 → 94 taken 27693 times.
65726 if (node->isMethod)
129 38033 currentScope = node->structScope->parent;
130
131
1/2
✓ Branch 94 → 95 taken 65726 times.
✗ Branch 94 → 144 not taken.
131452 return nullptr;
132 }
133
134 35755 std::any SymbolTableBuilder::visitProcDef(ProcDefNode *node) {
135 // Visit attributes
136
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 6 taken 35753 times.
35755 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 30481 times.
✓ Branch 6 → 36 taken 5272 times.
35753 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
141
2/2
✓ Branch 34 → 9 taken 34926 times.
✓ Branch 34 → 35 taken 30481 times.
95888 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
142
2/2
✓ Branch 11 → 12 taken 4455 times.
✓ Branch 11 → 13 taken 30471 times.
34926 if (qualifier->type == QualifierNode::QualifierType::TY_INLINE)
143 4455 node->qualifiers.isInline = true;
144
2/2
✓ Branch 13 → 14 taken 30455 times.
✓ Branch 13 → 15 taken 16 times.
30471 else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
145 30455 node->qualifiers.isPublic = true;
146
1/2
✓ Branch 15 → 16 taken 16 times.
✗ Branch 15 → 17 not taken.
16 else if (qualifier->type == QualifierNode::QualifierType::TY_CONST)
147 16 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 29403 times.
✓ Branch 36 → 51 taken 6350 times.
35753 if (node->isMethod) {
155
1/2
✓ Branch 38 → 39 taken 29403 times.
✗ Branch 38 → 108 not taken.
29403 const std::string &scopeName = Struct::getScopeName(node->name->structName);
156
1/2
✓ Branch 40 → 41 taken 29403 times.
✗ Branch 40 → 120 not taken.
29403 node->structScope = currentScope = currentScope->getChildScope(scopeName);
157
2/2
✓ Branch 41 → 42 taken 2 times.
✓ Branch 41 → 49 taken 29401 times.
29403 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 29403 }
160
161 // Create scope for the procedure
162
2/4
✓ Branch 51 → 52 taken 35751 times.
✗ Branch 51 → 125 not taken.
✓ Branch 52 → 53 taken 35751 times.
✗ Branch 52 → 123 not taken.
35751 node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
163
6/6
✓ Branch 54 → 55 taken 30153 times.
✓ Branch 54 → 57 taken 5598 times.
✓ Branch 55 → 56 taken 26466 times.
✓ Branch 55 → 58 taken 3687 times.
✓ Branch 56 → 57 taken 6976 times.
✓ Branch 56 → 58 taken 19490 times.
35751 currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope);
164
4/4
✓ Branch 59 → 60 taken 29401 times.
✓ Branch 59 → 63 taken 6350 times.
✓ Branch 61 → 62 taken 1291 times.
✓ Branch 61 → 63 taken 28110 times.
35751 currentScope->isDtorScope = node->isMethod && node->name->name == DTOR_FUNCTION_NAME;
165
166 // Create symbol for 'this' variable
167
2/2
✓ Branch 64 → 65 taken 29401 times.
✓ Branch 64 → 74 taken 6350 times.
35751 if (node->isMethod)
168
1/2
✓ Branch 67 → 68 taken 29401 times.
✗ Branch 67 → 128 not taken.
117604 currentScope->insert(THIS_VARIABLE_NAME, node);
169
170 // Create symbols for the parameters
171
2/2
✓ Branch 74 → 75 taken 26435 times.
✓ Branch 74 → 78 taken 9316 times.
35751 if (node->hasParams)
172
1/2
✓ Branch 75 → 76 taken 26435 times.
✗ Branch 75 → 132 not taken.
26435 visit(node->paramLst);
173
174 // Visit the procedure body
175
1/2
✓ Branch 78 → 79 taken 35751 times.
✗ Branch 78 → 133 not taken.
35751 visit(node->body);
176
177 // Leave procedure body scope
178 35751 currentScope = node->scope->parent;
179
180 // Insert symbol for procedure into the symbol table
181
1/2
✓ Branch 80 → 81 taken 35751 times.
✗ Branch 80 → 136 not taken.
71502 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 35751 const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName);
186
3/4
✓ Branch 86 → 87 taken 7032 times.
✓ Branch 86 → 88 taken 28719 times.
✓ Branch 87 → 88 taken 7032 times.
✗ Branch 87 → 89 not taken.
35751 if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry)
187 35751 sourceFile->addNameRegistryEntry(node->name->fqName, TY_PROCEDURE, node->entry, currentScope, true);
188
189 // Leave the struct scope
190
2/2
✓ Branch 89 → 90 taken 29401 times.
✓ Branch 89 → 91 taken 6350 times.
35751 if (node->isMethod)
191 29401 currentScope = node->structScope->parent;
192
193 // Check if this is a constructor
194 35751 node->isCtor = node->name->nameFragments.back() == CTOR_FUNCTION_NAME;
195
196
1/2
✓ Branch 93 → 94 taken 35751 times.
✗ Branch 93 → 137 not taken.
71502 return nullptr;
197 }
198
199 9659 std::any SymbolTableBuilder::visitStructDef(StructDefNode *node) {
200 // Visit attributes
201
2/2
✓ Branch 2 → 3 taken 262 times.
✓ Branch 2 → 6 taken 9397 times.
9659 if (node->attrs)
202
1/2
✓ Branch 3 → 4 taken 262 times.
✗ Branch 3 → 79 not taken.
262 visit(node->attrs);
203
204 // Check if this name already exists
205
3/4
✓ Branch 6 → 7 taken 9659 times.
✗ Branch 6 → 110 not taken.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 17 taken 9657 times.
19318 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 9657 times.
✗ Branch 18 → 89 not taken.
9657 const std::string &scopeName = Struct::getScopeName(node->structName);
210
1/2
✓ Branch 20 → 21 taken 9657 times.
✗ Branch 20 → 108 not taken.
9657 node->structScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::STRUCT, &node->codeLoc);
211 9657 currentScope->isGenericScope = node->hasTemplateTypes;
212
213 // Insert implicit field for each interface type
214
2/2
✓ Branch 21 → 22 taken 4092 times.
✓ Branch 21 → 43 taken 5565 times.
9657 if (node->hasInterfaces) {
215
2/2
✓ Branch 41 → 24 taken 4092 times.
✓ Branch 41 → 42 taken 4092 times.
12276 for (DataTypeNode *interfaceNode : node->interfaceTypeLst->dataTypes) {
216 4092 const std::string &interfaceName = interfaceNode->baseDataType->customDataType->typeNameFragments.back();
217
1/2
✓ Branch 27 → 28 taken 4092 times.
✗ Branch 27 → 94 not taken.
8184 SymbolTableEntry *interfaceFieldEntry = currentScope->insert("this." + interfaceName, interfaceNode);
218 4092 interfaceFieldEntry->used = true;
219 4092 interfaceFieldEntry->isImplicitField = true;
220 }
221 }
222
223 // Visit children
224
2/2
✓ Branch 43 → 44 taken 9655 times.
✓ Branch 43 → 96 taken 2 times.
9657 visitChildren(node);
225
226 // Leave the struct scope
227 9655 currentScope = node->structScope->parent;
228
229 // Build struct qualifiers
230
2/2
✓ Branch 45 → 46 taken 7975 times.
✓ Branch 45 → 70 taken 1680 times.
9655 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
231
2/2
✓ Branch 68 → 48 taken 7975 times.
✓ Branch 68 → 69 taken 7975 times.
23925 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
232
1/2
✓ Branch 50 → 51 taken 7975 times.
✗ Branch 50 → 54 not taken.
7975 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
233 7975 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 9655 times.
✗ Branch 70 → 108 not taken.
9655 node->entry = rootScope->insert(node->structName, node);
241 // Register the name in the exported name registry
242
1/2
✓ Branch 73 → 74 taken 9655 times.
✗ Branch 73 → 108 not taken.
9655 sourceFile->addNameRegistryEntry(node->structName, node->typeId, node->entry, node->structScope, true);
243
244
1/2
✓ Branch 74 → 75 taken 9655 times.
✗ Branch 74 → 107 not taken.
19310 return nullptr;
245 9657 }
246
247 1019 std::any SymbolTableBuilder::visitInterfaceDef(InterfaceDefNode *node) {
248 // Visit attributes
249
2/2
✓ Branch 2 → 3 taken 398 times.
✓ Branch 2 → 6 taken 621 times.
1019 if (node->attrs)
250
1/2
✓ Branch 3 → 4 taken 398 times.
✗ Branch 3 → 71 not taken.
398 visit(node->attrs);
251
252 // Check if this name already exists
253
3/4
✓ Branch 6 → 7 taken 1019 times.
✗ Branch 6 → 99 not taken.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 17 taken 1017 times.
2038 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 1017 times.
✗ Branch 18 → 81 not taken.
1017 const std::string &scopeName = Interface::getScopeName(node->interfaceName);
258
1/2
✓ Branch 20 → 21 taken 1017 times.
✗ Branch 20 → 97 not taken.
1017 node->interfaceScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::INTERFACE, &node->codeLoc);
259
260 // Visit signatures
261
2/2
✓ Branch 36 → 23 taken 7525 times.
✓ Branch 36 → 37 taken 1017 times.
9559 for (SignatureNode *signature : node->signatures)
262
1/2
✓ Branch 25 → 26 taken 7525 times.
✗ Branch 25 → 84 not taken.
7525 visit(signature);
263
264 // Leave the interface scope
265 1017 currentScope = node->interfaceScope->parent;
266
267 // Build interface qualifiers
268
2/2
✓ Branch 37 → 38 taken 977 times.
✓ Branch 37 → 62 taken 40 times.
1017 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
269
2/2
✓ Branch 60 → 40 taken 977 times.
✓ Branch 60 → 61 taken 977 times.
2931 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
270
1/2
✓ Branch 42 → 43 taken 977 times.
✗ Branch 42 → 46 not taken.
977 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
271 977 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 1017 times.
✗ Branch 62 → 97 not taken.
1017 node->entry = rootScope->insert(node->interfaceName, node);
279 // Register the name in the exported name registry
280
1/2
✓ Branch 65 → 66 taken 1017 times.
✗ Branch 65 → 97 not taken.
1017 sourceFile->addNameRegistryEntry(node->interfaceName, node->typeId, node->entry, node->interfaceScope, true);
281
282
1/2
✓ Branch 66 → 67 taken 1017 times.
✗ Branch 66 → 96 not taken.
2034 return nullptr;
283 1017 }
284
285 78 std::any SymbolTableBuilder::visitUnionDef(UnionDefNode *node) {
286 // Visit attributes
287
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 6 taken 78 times.
78 if (node->attrs)
288 ✗ visit(node->attrs);
289
290 // Check if this name already exists
291
2/4
✓ Branch 6 → 7 taken 78 times.
✗ Branch 6 → 84 not taken.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 17 taken 78 times.
156 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 78 times.
✗ Branch 18 → 67 not taken.
78 const std::string &scopeName = Union::getScopeName(node->unionName);
296
1/2
✓ Branch 20 → 21 taken 78 times.
✗ Branch 20 → 82 not taken.
78 node->unionScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::UNION, &node->codeLoc);
297 78 currentScope->isGenericScope = node->hasTemplateTypes;
298
299 // Visit children
300
2/2
✓ Branch 21 → 22 taken 76 times.
✓ Branch 21 → 70 taken 2 times.
78 visitChildren(node);
301
302 // Leave the union scope
303 76 currentScope = node->unionScope->parent;
304
305 // Build union qualifiers
306
2/2
✓ Branch 23 → 24 taken 42 times.
✓ Branch 23 → 48 taken 34 times.
76 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
307
2/2
✓ Branch 46 → 26 taken 42 times.
✓ Branch 46 → 47 taken 40 times.
124 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
308
2/2
✓ Branch 28 → 29 taken 40 times.
✓ Branch 28 → 32 taken 2 times.
42 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
309 40 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 74 times.
✗ Branch 48 → 82 not taken.
74 node->entry = rootScope->insert(node->unionName, node);
317 // Register the name in the exported name registry
318
1/2
✓ Branch 51 → 52 taken 74 times.
✗ Branch 51 → 82 not taken.
74 sourceFile->addNameRegistryEntry(node->unionName, node->typeId, node->entry, node->unionScope, true);
319
320
1/2
✓ Branch 52 → 53 taken 74 times.
✗ Branch 52 → 81 not taken.
148 return nullptr;
321 78 }
322
323 1970 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 1968 times.
3940 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 1968 node->enumScope = currentScope =
330
2/4
✓ Branch 13 → 14 taken 1968 times.
✗ Branch 13 → 62 not taken.
✓ Branch 14 → 15 taken 1968 times.
✗ Branch 14 → 60 not taken.
1968 rootScope->createChildScope(ENUM_SCOPE_PREFIX + node->enumName, ScopeType::ENUM, &node->codeLoc);
331
332 // Visit items
333
2/2
✓ Branch 16 → 17 taken 1966 times.
✓ Branch 16 → 63 taken 2 times.
1968 visit(node->itemLst);
334
335 // Leave the enum scope
336 1966 currentScope = node->enumScope->parent;
337
338 // Build enum qualifiers
339
2/2
✓ Branch 18 → 19 taken 1895 times.
✓ Branch 18 → 43 taken 71 times.
1966 if (node->qualifierLst) {
340
2/2
✓ Branch 41 → 21 taken 1895 times.
✓ Branch 41 → 42 taken 1895 times.
5685 for (const QualifierNode *qualifier : node->qualifierLst->qualifiers) {
341
1/2
✓ Branch 23 → 24 taken 1895 times.
✗ Branch 23 → 27 not taken.
1895 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
342 1895 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 1966 node->entry = rootScope->insert(node->enumName, node);
350 // Register the name in the exported name registry
351 1966 sourceFile->addNameRegistryEntry(node->enumName, node->typeId, node->entry, node->enumScope, true);
352
353
1/2
✓ Branch 47 → 48 taken 1966 times.
✗ Branch 47 → 74 not taken.
3932 return nullptr;
354 }
355
356 5141 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 5139 times.
10282 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 5139 node->entry = rootScope->insert(node->typeName, node);
363 5139 node->entry->used = true; // Generic types are always used
364
365
1/2
✓ Branch 16 → 17 taken 5139 times.
✗ Branch 16 → 29 not taken.
10278 return nullptr;
366 }
367
368 1189 std::any SymbolTableBuilder::visitAliasDef(AliasDefNode *node) {
369 // Check if this name already exists
370
3/4
✓ Branch 2 → 3 taken 1189 times.
✗ Branch 2 → 73 not taken.
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 1187 times.
2378 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 401 times.
✓ Branch 13 → 38 taken 786 times.
1187 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
375
2/2
✓ Branch 36 → 16 taken 401 times.
✓ Branch 36 → 37 taken 401 times.
1203 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
376
1/2
✓ Branch 18 → 19 taken 401 times.
✗ Branch 18 → 22 not taken.
401 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
377 401 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 1187 times.
✗ Branch 38 → 73 not taken.
1187 node->entry = rootScope->insert(node->aliasName, node);
385 // Register the name in the exported name registry
386
1/2
✓ Branch 41 → 42 taken 1187 times.
✗ Branch 41 → 73 not taken.
1187 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 1187 times.
✗ Branch 42 → 73 not taken.
1187 const std::string aliasedTypeContainerName = node->aliasName + ALIAS_CONTAINER_SUFFIX;
390
1/2
✓ Branch 43 → 44 taken 1187 times.
✗ Branch 43 → 71 not taken.
1187 node->aliasedTypeContainerEntry = rootScope->insert(aliasedTypeContainerName, node);
391
392
1/2
✓ Branch 46 → 47 taken 1187 times.
✗ Branch 46 → 70 not taken.
2374 return nullptr;
393 1187 }
394
395 10251 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 10249 times.
20502 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 10249 times.
✗ Branch 13 → 56 not taken.
✓ Branch 14 → 15 taken 10249 times.
✗ Branch 14 → 56 not taken.
✓ Branch 15 → 16 taken 10249 times.
✗ Branch 15 → 56 not taken.
✓ Branch 29 → 17 taken 26180 times.
✓ Branch 29 → 30 taken 10247 times.
36427 for (const auto &dependency : sourceFile->dependencies | std::views::values)
402
3/4
✓ Branch 18 → 19 taken 26180 times.
✗ Branch 18 → 56 not taken.
✓ Branch 19 → 20 taken 2 times.
✓ Branch 19 → 27 taken 26178 times.
26180 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 10247 node->entry = rootScope->insert(node->varName, node);
407 // Register the name in the exported name registry
408 10247 sourceFile->addNameRegistryEntry(node->varName, TY_INVALID, node->entry, currentScope, true);
409
410
1/2
✓ Branch 34 → 35 taken 10247 times.
✗ Branch 34 → 57 not taken.
20494 return nullptr;
411 }
412
413 12367 std::any SymbolTableBuilder::visitExtDecl(ExtDeclNode *node) {
414 // Visit attributes
415
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 6 taken 12365 times.
12367 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 12365 times.
24734 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 12365 times.
✗ Branch 17 → 43 not taken.
✓ Branch 18 → 19 taken 12365 times.
✗ Branch 18 → 41 not taken.
12365 rootScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
424
425 // Add the external declaration to the symbol table
426 12365 node->entry = rootScope->insert(node->extFunctionName, node);
427 // Register the name in the exported name registry
428
2/2
✓ Branch 23 → 24 taken 9838 times.
✓ Branch 23 → 25 taken 2527 times.
12365 const uint64_t typeId = node->returnType ? TY_FUNCTION : TY_PROCEDURE;
429 12365 sourceFile->addNameRegistryEntry(node->extFunctionName, typeId, node->entry, rootScope, /*keepNewOnCollision=*/true);
430
431
1/2
✓ Branch 27 → 28 taken 12365 times.
✗ Branch 27 → 44 not taken.
24730 return nullptr;
432 }
433
434 19604 std::any SymbolTableBuilder::visitUnsafeBlock(UnsafeBlockNode *node) {
435 // Create scope for the unsafe block body
436 19604 node->bodyScope = currentScope =
437
2/4
✓ Branch 2 → 3 taken 19604 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 19604 times.
✗ Branch 3 → 11 not taken.
19604 currentScope->createChildScope(node->getScopeId(), ScopeType::UNSAFE_BODY, &node->body->codeLoc);
438
439 // Visit body
440
1/2
✓ Branch 5 → 6 taken 19604 times.
✗ Branch 5 → 14 not taken.
19604 visit(node->body);
441
442 // Leave thread body scope
443 19604 currentScope = node->bodyScope->parent;
444
445
1/2
✓ Branch 7 → 8 taken 19604 times.
✗ Branch 7 → 15 not taken.
39208 return nullptr;
446 }
447
448 7246 std::any SymbolTableBuilder::visitForLoop(ForLoopNode *node) {
449 // Create scope for the loop body
450
2/4
✓ Branch 2 → 3 taken 7246 times.
✗ Branch 2 → 16 not taken.
✓ Branch 3 → 4 taken 7246 times.
✗ Branch 3 → 14 not taken.
7246 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 7246 times.
✗ Branch 5 → 17 not taken.
7246 visit(node->initDecl);
454
455 // Visit condition
456 7246 visitInExprScope(node->condAssign);
457
458 // Visit body
459
1/2
✓ Branch 8 → 9 taken 7246 times.
✗ Branch 8 → 18 not taken.
7246 visit(node->body);
460
461 // Leave for body scope
462 7246 currentScope = node->bodyScope->parent;
463
464
1/2
✓ Branch 10 → 11 taken 7246 times.
✗ Branch 10 → 19 not taken.
14492 return nullptr;
465 }
466
467 1523 std::any SymbolTableBuilder::visitForeachLoop(ForeachLoopNode *node) {
468 // Create scope for the loop body
469 1523 node->bodyScope = currentScope =
470
2/4
✓ Branch 2 → 3 taken 1523 times.
✗ Branch 2 → 19 not taken.
✓ Branch 3 → 4 taken 1523 times.
✗ Branch 3 → 17 not taken.
1523 currentScope->createChildScope(node->getScopeId(), ScopeType::FOREACH_BODY, &node->body->codeLoc);
471
472 // Visit index variable declaration
473
2/2
✓ Branch 5 → 6 taken 198 times.
✓ Branch 5 → 9 taken 1325 times.
1523 if (node->idxVarDecl)
474
1/2
✓ Branch 6 → 7 taken 198 times.
✗ Branch 6 → 20 not taken.
198 visit(node->idxVarDecl);
475
476 // Visit item variable declaration
477
1/2
✓ Branch 9 → 10 taken 1523 times.
✗ Branch 9 → 21 not taken.
1523 visit(node->itemVarDecl);
478
479 // Visit body
480
1/2
✓ Branch 11 → 12 taken 1523 times.
✗ Branch 11 → 22 not taken.
1523 visit(node->body);
481
482 // Leave foreach body scope
483 1523 currentScope = node->bodyScope->parent;
484
485
1/2
✓ Branch 13 → 14 taken 1523 times.
✗ Branch 13 → 23 not taken.
3046 return nullptr;
486 }
487
488 3655 std::any SymbolTableBuilder::visitWhileLoop(WhileLoopNode *node) {
489 // Create scope for the loop body
490 3655 node->bodyScope = currentScope =
491
2/4
✓ Branch 2 → 3 taken 3655 times.
✗ Branch 2 → 14 not taken.
✓ Branch 3 → 4 taken 3655 times.
✗ Branch 3 → 12 not taken.
3655 currentScope->createChildScope(node->getScopeId(), ScopeType::WHILE_BODY, &node->body->codeLoc);
492
493 // Visit condition
494 3655 visitInExprScope(node->condition);
495
496 // Visit body
497
1/2
✓ Branch 6 → 7 taken 3655 times.
✗ Branch 6 → 15 not taken.
3655 visit(node->body);
498
499 // Leave while body scope
500 3655 currentScope = node->bodyScope->parent;
501
502
1/2
✓ Branch 8 → 9 taken 3655 times.
✗ Branch 8 → 16 not taken.
7310 return nullptr;
503 }
504
505 43 std::any SymbolTableBuilder::visitDoWhileLoop(DoWhileLoopNode *node) {
506 // Create scope for the loop body
507 43 node->bodyScope = currentScope =
508
2/4
✓ Branch 2 → 3 taken 43 times.
✗ Branch 2 → 14 not taken.
✓ Branch 3 → 4 taken 43 times.
✗ Branch 3 → 12 not taken.
43 currentScope->createChildScope(node->getScopeId(), ScopeType::WHILE_BODY, &node->body->codeLoc);
509
510 // Visit condition
511 43 visitInExprScope(node->condition);
512
513 // Visit body
514
1/2
✓ Branch 6 → 7 taken 43 times.
✗ Branch 6 → 15 not taken.
43 visit(node->body);
515
516 // Leave do-while body scope
517 43 currentScope = node->bodyScope->parent;
518
519
1/2
✓ Branch 8 → 9 taken 43 times.
✗ Branch 8 → 16 not taken.
86 return nullptr;
520 }
521
522 46180 std::any SymbolTableBuilder::visitIfStmt(IfStmtNode *node) {
523 // Create scope for the then body
524 46180 node->thenBodyScope = currentScope =
525
2/4
✓ Branch 2 → 3 taken 46180 times.
✗ Branch 2 → 26 not taken.
✓ Branch 3 → 4 taken 46180 times.
✗ Branch 3 → 24 not taken.
46180 currentScope->createChildScope(node->getScopeId(), ScopeType::IF_ELSE_BODY, &node->thenBody->codeLoc);
526
527 // Visit condition
528 46180 visitInExprScope(node->condition);
529
530 // Visit then body (manifestations do not exist yet, so both branches are always visited here)
531
1/2
✓ Branch 7 → 8 taken 46180 times.
✗ Branch 7 → 11 not taken.
46180 if (node->doCompileThenBranch(manIdx))
532
1/2
✓ Branch 8 → 9 taken 46180 times.
✗ Branch 8 → 27 not taken.
46180 visit(node->thenBody);
533
534 // Leave then body scope
535 46180 currentScope = node->thenBodyScope->parent;
536
537 // Visit else stmt
538
5/6
✓ Branch 12 → 13 taken 46180 times.
✗ Branch 12 → 15 not taken.
✓ Branch 13 → 14 taken 4529 times.
✓ Branch 13 → 15 taken 41651 times.
✓ Branch 16 → 17 taken 4529 times.
✓ Branch 16 → 20 taken 41651 times.
46180 if (node->doCompileElseBranch(manIdx) && node->elseStmt)
539
1/2
✓ Branch 17 → 18 taken 4529 times.
✗ Branch 17 → 28 not taken.
4529 visit(node->elseStmt);
540
541
1/2
✓ Branch 20 → 21 taken 46180 times.
✗ Branch 20 → 29 not taken.
92360 return nullptr;
542 }
543
544 4529 std::any SymbolTableBuilder::visitElseStmt(ElseStmtNode *node) {
545 // Visit if statement in the case of an else if branch
546
2/2
✓ Branch 2 → 3 taken 2131 times.
✓ Branch 2 → 8 taken 2398 times.
4529 if (node->isElseIf) {
547
1/2
✓ Branch 3 → 4 taken 2131 times.
✗ Branch 3 → 17 not taken.
2131 visit(node->ifStmt);
548
1/2
✓ Branch 5 → 6 taken 2131 times.
✗ Branch 5 → 18 not taken.
4262 return nullptr;
549 }
550
551 // Create scope for the else body
552 2398 node->elseBodyScope = currentScope =
553
2/4
✓ Branch 8 → 9 taken 2398 times.
✗ Branch 8 → 21 not taken.
✓ Branch 9 → 10 taken 2398 times.
✗ Branch 9 → 19 not taken.
2398 currentScope->createChildScope(node->getScopeId(), ScopeType::IF_ELSE_BODY, &node->body->codeLoc);
554
555 // Visit else body
556
1/2
✓ Branch 11 → 12 taken 2398 times.
✗ Branch 11 → 22 not taken.
2398 visit(node->body);
557
558 // Leave else body scope
559 2398 currentScope = node->elseBodyScope->parent;
560
561
1/2
✓ Branch 13 → 14 taken 2398 times.
✗ Branch 13 → 23 not taken.
4796 return nullptr;
562 }
563
564 3255 std::any SymbolTableBuilder::visitCaseBranch(CaseBranchNode *node) {
565 // Create scope for the case branch
566
2/4
✓ Branch 2 → 3 taken 3255 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 3255 times.
✗ Branch 3 → 11 not taken.
3255 node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::CASE_BODY, &node->body->codeLoc);
567
568 // Visit case body
569
1/2
✓ Branch 5 → 6 taken 3255 times.
✗ Branch 5 → 14 not taken.
3255 visit(node->body);
570
571 // Leave case body scope
572 3255 currentScope = node->bodyScope->parent;
573
574
1/2
✓ Branch 7 → 8 taken 3255 times.
✗ Branch 7 → 15 not taken.
6510 return nullptr;
575 }
576
577 289 std::any SymbolTableBuilder::visitDefaultBranch(DefaultBranchNode *node) {
578 // Create scope for the default branch
579 289 node->bodyScope = currentScope =
580
2/4
✓ Branch 2 → 3 taken 289 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 289 times.
✗ Branch 3 → 11 not taken.
289 currentScope->createChildScope(node->getScopeId(), ScopeType::DEFAULT_BODY, &node->body->codeLoc);
581
582 // Visit default body
583
1/2
✓ Branch 5 → 6 taken 289 times.
✗ Branch 5 → 14 not taken.
289 visit(node->body);
584
585 // Leave default body scope
586 289 currentScope = node->bodyScope->parent;
587
588
1/2
✓ Branch 7 → 8 taken 289 times.
✗ Branch 7 → 15 not taken.
578 return nullptr;
589 }
590
591 141 std::any SymbolTableBuilder::visitAnonymousBlockStmt(AnonymousBlockStmtNode *node) {
592 // Create scope for the anonymous block body
593 141 node->bodyScope = currentScope =
594
2/4
✓ Branch 2 → 3 taken 141 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 141 times.
✗ Branch 3 → 11 not taken.
141 currentScope->createChildScope(node->getScopeId(), ScopeType::ANONYMOUS_BLOCK_BODY, &node->body->codeLoc);
595
596 // Visit body
597
1/2
✓ Branch 5 → 6 taken 141 times.
✗ Branch 5 → 14 not taken.
141 visit(node->body);
598
599 // Leave anonymous block body scope
600 141 currentScope = node->bodyScope->parent;
601
602
1/2
✓ Branch 7 → 8 taken 141 times.
✗ Branch 7 → 15 not taken.
282 return nullptr;
603 }
604
605 19410 std::any SymbolTableBuilder::visitEnumItem(EnumItemNode *node) {
606 // Check if enum item already exists in the same scope.
607
3/4
✓ Branch 2 → 3 taken 19410 times.
✗ Branch 2 → 42 not taken.
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 19408 times.
38820 if (currentScope->lookupStrict(node->itemName))
608
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");
609
610 // Add enum item entry to symbol table
611
1/2
✓ Branch 13 → 14 taken 19408 times.
✗ Branch 13 → 42 not taken.
19408 SymbolTableEntry *enumItemEntry = currentScope->insert(node->itemName, node);
612
613 // Add external registry entry
614
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 19408 times.
19408 assert(node->enumDef != nullptr);
615
2/4
✓ Branch 18 → 19 taken 19408 times.
✗ Branch 18 → 38 not taken.
✓ Branch 19 → 20 taken 19408 times.
✗ Branch 19 → 36 not taken.
19408 const std::string name = node->enumDef->enumName + SCOPE_ACCESS_TOKEN + node->itemName;
616
1/2
✓ Branch 21 → 22 taken 19408 times.
✗ Branch 21 → 40 not taken.
19408 sourceFile->addNameRegistryEntry(name, TY_INT, enumItemEntry, currentScope, true);
617
618
1/2
✓ Branch 22 → 23 taken 19408 times.
✗ Branch 22 → 39 not taken.
38816 return nullptr;
619 19408 }
620
621 26812 std::any SymbolTableBuilder::visitField(FieldNode *node) {
622 // Check if field already exists in the same scope.
623
2/2
✓ Branch 5 → 6 taken 4 times.
✓ Branch 5 → 13 taken 26808 times.
53624 if (currentScope->lookupStrict(node->fieldName))
624
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");
625
626 // Add field entry to symbol table
627 26808 currentScope->insert(node->fieldName, node);
628
629
1/2
✓ Branch 16 → 17 taken 26808 times.
✗ Branch 16 → 29 not taken.
53616 return nullptr;
630 }
631
632 7525 std::any SymbolTableBuilder::visitSignature(SignatureNode *node) {
633 // Build signature qualifiers
634
2/2
✓ Branch 2 → 3 taken 7443 times.
✓ Branch 2 → 32 taken 82 times.
7525 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
635
2/2
✓ Branch 30 → 5 taken 8123 times.
✓ Branch 30 → 31 taken 7443 times.
23009 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
636
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 8123 times.
8123 if (qualifier->type == QualifierNode::QualifierType::TY_INLINE)
637 ✗ node->signatureQualifiers.isInline = true;
638
2/2
✓ Branch 9 → 10 taken 7443 times.
✓ Branch 9 → 11 taken 680 times.
8123 else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
639 7443 node->signatureQualifiers.isPublic = true;
640
1/2
✓ Branch 11 → 12 taken 680 times.
✗ Branch 11 → 13 not taken.
680 else if (qualifier->type == QualifierNode::QualifierType::TY_CONST)
641 680 node->signatureQualifiers.isConst = true;
642 else
643 ✗ throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on a signature definition");
644 }
645 }
646
647 // Add signature entry to symbol table. We append the code location to disambiguate overloaded signatures
648 // (e.g. an interface declaring `getName()` and `getName(bool)`).
649
1/2
✓ Branch 32 → 33 taken 7525 times.
✗ Branch 32 → 53 not taken.
15050 node->entry = currentScope->insert(Function::getSymbolTableEntryName(node->methodName, node->codeLoc), node);
650
651
1/2
✓ Branch 37 → 38 taken 7525 times.
✗ Branch 37 → 54 not taken.
15050 return nullptr;
652 }
653
654 169316 std::any SymbolTableBuilder::visitDeclStmt(DeclStmtNode *node) {
655 // Check if variable already exists in the same scope.
656
2/2
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 169314 times.
338632 if (currentScope->lookupStrict(node->varName))
657
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");
658
659 // Visit the right side
660
2/2
✓ Branch 13 → 14 taken 62719 times.
✓ Branch 13 → 17 taken 106595 times.
169314 if (node->hasAssignment)
661
1/2
✓ Branch 14 → 15 taken 62719 times.
✗ Branch 14 → 33 not taken.
62719 visit(node->assignExpr);
662
663 // Add variable entry to symbol table
664 169314 SymbolTableEntry *varEntry = currentScope->insert(node->varName, node);
665 169314 varEntry->isParam = node->isFctParam;
666
667
1/2
✓ Branch 20 → 21 taken 169314 times.
✗ Branch 20 → 34 not taken.
338628 return nullptr;
668 }
669
670 2336 std::any SymbolTableBuilder::visitModAttr(ModAttrNode *node) {
671 // Visit attributes
672
2/2
✓ Branch 2 → 3 taken 2334 times.
✓ Branch 2 → 126 taken 2 times.
2336 visitChildren(node);
673
674 // Retrieve attributes
675 2334 const AttrLstNode *attrs = node->attrLst;
676
677 // Collect linker flags
678 2334 std::vector<const CompileTimeValue *> linkerFlagValues;
679 // core.linker.flag
680
2/4
✓ Branch 6 → 7 taken 2334 times.
✗ Branch 6 → 129 not taken.
✓ Branch 7 → 8 taken 2334 times.
✗ Branch 7 → 127 not taken.
4668 std::vector<const CompileTimeValue *> values = attrs->getAttrValuesByName(ATTR_CORE_LINKER_FLAG);
681
1/2
✓ Branch 16 → 17 taken 2334 times.
✗ Branch 16 → 133 not taken.
4668 linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end());
682 // core.linux.linker.flag
683 2334 const llvm::Triple &targetTriple = sourceFile->targetMachine->getTargetTriple();
684
2/2
✓ Branch 20 → 21 taken 2310 times.
✓ Branch 20 → 37 taken 24 times.
2334 if (targetTriple.isOSLinux()) {
685
2/4
✓ Branch 23 → 24 taken 2310 times.
✗ Branch 23 → 137 not taken.
✓ Branch 24 → 25 taken 2310 times.
✗ Branch 24 → 135 not taken.
4620 values = attrs->getAttrValuesByName(ATTR_CORE_LINUX_LINKER_FLAG);
686
1/2
✓ Branch 35 → 36 taken 2310 times.
✗ Branch 35 → 142 not taken.
4620 linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end());
687 }
688 // core.darwin.linker.flag
689
3/4
✓ Branch 37 → 38 taken 2334 times.
✗ Branch 37 → 187 not taken.
✓ Branch 38 → 39 taken 12 times.
✓ Branch 38 → 55 taken 2322 times.
2334 if (targetTriple.isOSDarwin()) {
690
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);
691
1/2
✓ Branch 53 → 54 taken 12 times.
✗ Branch 53 → 151 not taken.
24 linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end());
692 }
693 // core.windows.linker.flag
694
2/2
✓ Branch 56 → 57 taken 12 times.
✓ Branch 56 → 73 taken 2322 times.
2334 if (targetTriple.isOSWindows()) {
695
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);
696
1/2
✓ Branch 71 → 72 taken 12 times.
✗ Branch 71 → 160 not taken.
24 linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end());
697 }
698
2/2
✓ Branch 89 → 75 taken 5702 times.
✓ Branch 89 → 90 taken 2334 times.
10370 for (const CompileTimeValue *value : linkerFlagValues) {
699
1/2
✓ Branch 77 → 78 taken 5702 times.
✗ Branch 77 → 162 not taken.
5702 const std::string &flag = resourceManager.compileTimeStringValues.at(value->stringValueOffset);
700
1/2
✓ Branch 78 → 79 taken 5702 times.
✗ Branch 78 → 162 not taken.
5702 resourceManager.linker.addLinkerFlag(flag);
701
1/2
✓ Branch 79 → 80 taken 5702 times.
✗ Branch 79 → 162 not taken.
5702 sourceFile->sourceLinkerFlags.push_back(flag);
702 }
703
704 // core.linker.additionalSource
705
4/6
✓ Branch 90 → 91 taken 2334 times.
✗ Branch 90 → 165 not taken.
✓ Branch 91 → 92 taken 2334 times.
✗ Branch 91 → 163 not taken.
✓ Branch 116 → 94 taken 44 times.
✓ Branch 116 → 117 taken 2332 times.
4710 for (const CompileTimeValue *value : attrs->getAttrValuesByName(ATTR_CORE_LINKER_ADDITIONAL_SOURCE)) {
706
1/2
✓ Branch 96 → 97 taken 44 times.
✗ Branch 96 → 178 not taken.
44 const std::string &stringValue = resourceManager.compileTimeStringValues.at(value->stringValueOffset);
707
3/6
✓ Branch 97 → 98 taken 44 times.
✗ Branch 97 → 172 not taken.
✓ Branch 98 → 99 taken 44 times.
✗ Branch 98 → 169 not taken.
✓ Branch 99 → 100 taken 44 times.
✗ Branch 99 → 167 not taken.
44 const std::filesystem::path additionalSourcePath = sourceFile->filePath.parent_path() / stringValue;
708
3/4
✓ Branch 102 → 103 taken 44 times.
✗ Branch 102 → 175 not taken.
✓ Branch 103 → 104 taken 42 times.
✓ Branch 103 → 173 taken 2 times.
46 resourceManager.linker.addAdditionalSourcePath(additionalSourcePath);
709
1/2
✓ Branch 105 → 106 taken 42 times.
✗ Branch 105 → 176 not taken.
42 sourceFile->sourceAdditionalSourcePaths.push_back(additionalSourcePath);
710 2380 }
711
712
1/2
✓ Branch 120 → 121 taken 2332 times.
✗ Branch 120 → 186 not taken.
4664 return nullptr;
713 2336 }
714
715 11952 std::any SymbolTableBuilder::visitAttr(AttrNode *node) {
716 // Check if this attribute exists
717
1/2
✓ Branch 2 → 3 taken 11952 times.
✗ Branch 2 → 63 not taken.
11952 const auto it = ATTR_CONFIGS.find(node->key);
718
2/2
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 11950 times.
11952 if (it == ATTR_CONFIGS.end())
719
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 + "'");
720
721 // Check if the target is correct
722 11950 const auto &[target, type] = it->second;
723
2/2
✓ Branch 14 → 15 taken 2 times.
✓ Branch 14 → 22 taken 11948 times.
11950 if ((node->target & target) == 0)
724
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");
725
726 // Check if a value is present
727
4/4
✓ Branch 22 → 23 taken 2080 times.
✓ Branch 22 → 31 taken 9868 times.
✓ Branch 23 → 24 taken 2 times.
✓ Branch 23 → 31 taken 2078 times.
11948 if (!node->value && type != AttrNode::AttrType::TYPE_BOOL)
728
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");
729
730
1/2
✓ Branch 31 → 32 taken 11946 times.
✗ Branch 31 → 62 not taken.
23892 return nullptr;
731 }
732
733 109 std::any SymbolTableBuilder::visitLambdaFunc(LambdaFuncNode *node) {
734 // Create scope for the lambda body
735 109 const CodeLoc &codeLoc = node->body->codeLoc;
736
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);
737 // Requires capturing because the LLVM IR will end up in a separate function
738 109 currentScope->symbolTable.setCapturingRequired();
739 // Set to async scope if this is an async lambda
740
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))
741 ✗ node->bodyScope->isAsyncScope = node->lambdaAttr->attrLst->getAttrValueByName(ATTR_ASYNC)->boolValue;
742
743 // Create symbol for 'result' variable
744
1/2
✓ Branch 29 → 30 taken 109 times.
✗ Branch 29 → 65 not taken.
327 currentScope->insert(RETURN_VARIABLE_NAME, node);
745
746 // Create symbols for the parameters
747
2/2
✓ Branch 35 → 36 taken 99 times.
✓ Branch 35 → 39 taken 10 times.
109 if (node->hasParams)
748
1/2
✓ Branch 36 → 37 taken 99 times.
✗ Branch 36 → 69 not taken.
99 visit(node->paramLst);
749
750 // Visit body
751
1/2
✓ Branch 39 → 40 taken 109 times.
✗ Branch 39 → 70 not taken.
109 visit(node->body);
752
753 // Leave anonymous block body scope
754 109 currentScope = node->bodyScope->parent;
755
756
1/2
✓ Branch 41 → 42 taken 109 times.
✗ Branch 41 → 71 not taken.
218 return nullptr;
757 }
758
759 290 std::any SymbolTableBuilder::visitLambdaProc(LambdaProcNode *node) {
760 // Create scope for the lambda body
761 290 const CodeLoc &codeLoc = node->body->codeLoc;
762
2/4
✓ Branch 2 → 3 taken 290 times.
✗ Branch 2 → 39 not taken.
✓ Branch 3 → 4 taken 290 times.
✗ Branch 3 → 37 not taken.
290 node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::LAMBDA_BODY, &codeLoc);
763 // Requires capturing because the LLVM IR will end up in a separate function
764 290 currentScope->symbolTable.setCapturingRequired();
765 // Set to async scope if this is an async lambda
766
11/18
✓ Branch 6 → 7 taken 16 times.
✓ Branch 6 → 13 taken 274 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 274 times.
✓ Branch 16 → 17 taken 16 times.
✓ Branch 16 → 19 taken 274 times.
✓ Branch 19 → 20 taken 16 times.
✓ Branch 19 → 27 taken 274 times.
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 42 not taken.
✗ Branch 44 → 45 not taken.
✗ Branch 44 → 47 not taken.
322 if (node->lambdaAttr && node->lambdaAttr->attrLst->hasAttr(ATTR_ASYNC))
767
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;
768
769 // Create symbols for the parameters
770
2/2
✓ Branch 27 → 28 taken 218 times.
✓ Branch 27 → 31 taken 72 times.
290 if (node->hasParams)
771
1/2
✓ Branch 28 → 29 taken 218 times.
✗ Branch 28 → 55 not taken.
218 visit(node->paramLst);
772
773 // Visit body
774
1/2
✓ Branch 31 → 32 taken 290 times.
✗ Branch 31 → 56 not taken.
290 visit(node->body);
775
776 // Leave anonymous block body scope
777 290 currentScope = node->bodyScope->parent;
778
779
1/2
✓ Branch 33 → 34 taken 290 times.
✗ Branch 33 → 57 not taken.
580 return nullptr;
780 }
781
782 2 std::any SymbolTableBuilder::visitLambdaExpr(LambdaExprNode *node) {
783 // Create scope for the anonymous block body
784 2 const CodeLoc &codeLoc = node->lambdaExpr->codeLoc;
785
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);
786 // Requires capturing because the LLVM IR will end up in a separate function
787 2 currentScope->symbolTable.setCapturingRequired();
788
789 // Create symbols for the parameters
790
1/2
✓ Branch 6 → 7 taken 2 times.
✗ Branch 6 → 10 not taken.
2 if (node->hasParams)
791
1/2
✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 19 not taken.
2 visit(node->paramLst);
792
793 // Visit lambda expression
794
1/2
✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 20 not taken.
2 visit(node->lambdaExpr);
795
796 // Leave anonymous block body scope
797 2 currentScope = node->bodyScope->parent;
798
799
1/2
✓ Branch 12 → 13 taken 2 times.
✗ Branch 12 → 21 not taken.
4 return nullptr;
800 }
801
802 4808 std::any SymbolTableBuilder::visitTernaryExpr(TernaryExprNode *node) {
803 // Visit condition, which is evaluated unconditionally
804
1/2
✓ Branch 2 → 3 taken 4808 times.
✗ Branch 2 → 13 not taken.
4808 visit(node->condition);
805
806 // Visit the branches. Only one of them is evaluated, so each one gets its own scope for its temporaries.
807 // The true branch does not exist for shortened ternaries, as the condition takes its place.
808
3/4
✓ Branch 4 → 5 taken 4806 times.
✓ Branch 4 → 7 taken 2 times.
✓ Branch 5 → 6 taken 4806 times.
✗ Branch 5 → 7 not taken.
4808 if (node->trueExpr && !node->isShortened)
809 4806 visitInExprScope(node->trueExpr);
810
1/2
✓ Branch 7 → 8 taken 4808 times.
✗ Branch 7 → 9 not taken.
4808 if (node->falseExpr)
811 4808 visitInExprScope(node->falseExpr);
812
813
1/2
✓ Branch 9 → 10 taken 4808 times.
✗ Branch 9 → 14 not taken.
9616 return nullptr;
814 }
815
816 6975 std::any SymbolTableBuilder::visitLogicalOrExpr(LogicalOrExprNode *node) {
817 // Visit the first operand, which is evaluated unconditionally
818
1/2
✓ Branch 3 → 4 taken 6975 times.
✗ Branch 3 → 15 not taken.
6975 visit(node->operands.front());
819
820 // All further operands are only evaluated if the ones before did not short-circuit
821
2/2
✓ Branch 10 → 6 taken 9149 times.
✓ Branch 10 → 11 taken 6975 times.
16124 for (size_t i = 1; i < node->operands.size(); i++)
822 9149 visitInExprScope(node->operands[i]);
823
824
1/2
✓ Branch 11 → 12 taken 6975 times.
✗ Branch 11 → 16 not taken.
13950 return nullptr;
825 }
826
827 4777 std::any SymbolTableBuilder::visitLogicalAndExpr(LogicalAndExprNode *node) {
828 // Visit the first operand, which is evaluated unconditionally
829
1/2
✓ Branch 3 → 4 taken 4777 times.
✗ Branch 3 → 15 not taken.
4777 visit(node->operands.front());
830
831 // All further operands are only evaluated if the ones before did not short-circuit
832
2/2
✓ Branch 10 → 6 taken 6559 times.
✓ Branch 10 → 11 taken 4777 times.
11336 for (size_t i = 1; i < node->operands.size(); i++)
833 6559 visitInExprScope(node->operands[i]);
834
835
1/2
✓ Branch 11 → 12 taken 4777 times.
✗ Branch 11 → 16 not taken.
9554 return nullptr;
836 }
837
838 /**
839 * Visit an expression in a scope of its own. That scope holds the temporaries of the expression, which allows destructing them
840 * right after the expression was evaluated. This is required for conditions and for operands that are only evaluated
841 * conditionally, since a temporary of those must not be destructed if it never was constructed.
842 *
843 * @param expr Expression to visit
844 */
845 82446 void SymbolTableBuilder::visitInExprScope(ExprNode *expr) {
846 // Create scope for the expression
847
2/4
✓ Branch 2 → 3 taken 82446 times.
✗ Branch 2 → 10 not taken.
✓ Branch 3 → 4 taken 82446 times.
✗ Branch 3 → 8 not taken.
82446 currentScope = currentScope->createChildScope(expr->getExprScopeId(), ScopeType::EXPR_BODY, &expr->codeLoc);
848
849 // Visit the expression
850
1/2
✓ Branch 5 → 6 taken 82446 times.
✗ Branch 5 → 11 not taken.
82446 visit(expr);
851
852 // Leave expression scope
853 82446 currentScope = currentScope->parent;
854 82446 }
855
856 } // namespace spice::compiler
857