GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 96.4% 397 / 0 / 412
Functions: 100.0% 36 / 0 / 36
Branches: 58.5% 455 / 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 11594 SymbolTableBuilder::SymbolTableBuilder(GlobalResourceManager &resourceManager, SourceFile *sourceFile)
17 11594 : CompilerPass(resourceManager, sourceFile), rootScope(sourceFile->globalScope.get()) {}
18
19 11594 std::any SymbolTableBuilder::visitEntry(EntryNode *node) {
20 // Initialize
21 11594 currentScope = rootScope;
22
23 // Visit children
24
2/2
✓ Branch 2 → 3 taken 11556 times.
✓ Branch 2 → 23 taken 38 times.
11594 visitChildren(node);
25
26 // Check if the main function exists
27
4/4
✓ Branch 4 → 5 taken 11550 times.
✓ Branch 4 → 7 taken 6 times.
✓ Branch 5 → 6 taken 11538 times.
✓ Branch 5 → 7 taken 12 times.
11556 const bool mainFctRequired = cliOptions.outputContainer == OutputContainer::EXECUTABLE && !cliOptions.noEntryFct;
28
6/6
✓ Branch 8 → 9 taken 1331 times.
✓ Branch 8 → 19 taken 10225 times.
✓ Branch 9 → 10 taken 1315 times.
✓ Branch 9 → 19 taken 16 times.
✓ Branch 10 → 11 taken 4 times.
✓ Branch 10 → 19 taken 1311 times.
11556 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 11552 times.
✗ Branch 19 → 33 not taken.
23104 return nullptr;
32 }
33
34 1323 std::any SymbolTableBuilder::visitMainFctDef(MainFctDefNode *node) {
35 // Visit attributes
36
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 6 taken 1321 times.
1323 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 1321 times.
✗ Branch 8 → 55 not taken.
✓ Branch 14 → 15 taken 2 times.
✓ Branch 14 → 23 taken 1319 times.
5284 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 1319 times.
✗ Branch 25 → 70 not taken.
3957 SymbolTableEntry *mainFctEntry = currentScope->insert(MAIN_FUNCTION_NAME, node);
45 1319 mainFctEntry->used = true;
46
47 // Create scope for main function body
48
1/2
✓ Branch 31 → 32 taken 1319 times.
✗ Branch 31 → 85 not taken.
1319 const std::string &scopeId = MainFctDefNode::getScopeId();
49
1/2
✓ Branch 32 → 33 taken 1319 times.
✗ Branch 32 → 83 not taken.
1319 node->bodyScope = currentScope = rootScope->createChildScope(scopeId, ScopeType::FUNC_PROC_BODY, &node->codeLoc);
50 1319 currentScope->isGenericScope = false;
51
52 // Declare variable for the return value in the function scope
53
1/2
✓ Branch 35 → 36 taken 1319 times.
✗ Branch 35 → 76 not taken.
3957 SymbolTableEntry *resultVarEntry = node->bodyScope->insert(RETURN_VARIABLE_NAME, node);
54 1319 resultVarEntry->used = true;
55
56 // Visit arguments in new scope
57
2/2
✓ Branch 41 → 42 taken 14 times.
✓ Branch 41 → 45 taken 1305 times.
1319 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 1317 times.
✓ Branch 45 → 81 taken 2 times.
1319 visit(node->body);
62
63 // Return to root scope
64 1317 currentScope = rootScope;
65
66 1317 hasMainFunction = true;
67
1/2
✓ Branch 47 → 48 taken 1317 times.
✗ Branch 47 → 82 not taken.
2634 return nullptr;
68 1319 }
69
70 142036 std::any SymbolTableBuilder::visitFctDef(FctDefNode *node) {
71 // Visit attributes
72
2/2
✓ Branch 2 → 3 taken 4050 times.
✓ Branch 2 → 6 taken 137986 times.
142036 if (node->attrs)
73
1/2
✓ Branch 3 → 4 taken 4050 times.
✗ Branch 3 → 98 not taken.
4050 visit(node->attrs);
74
75 // Build function qualifiers
76
2/2
✓ Branch 6 → 7 taken 124300 times.
✓ Branch 6 → 36 taken 17736 times.
142036 if (const QualifierLstNode *qualifierLst = node->qualifierLst; qualifierLst) {
77
2/2
✓ Branch 34 → 9 taken 148049 times.
✓ Branch 34 → 35 taken 124300 times.
396649 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
78
2/2
✓ Branch 11 → 12 taken 23576 times.
✓ Branch 11 → 13 taken 124473 times.
148049 if (qualifier->type == QualifierNode::QualifierType::TY_INLINE)
79 23576 node->qualifiers.isInline = true;
80
2/2
✓ Branch 13 → 14 taken 123085 times.
✓ Branch 13 → 15 taken 1388 times.
124473 else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
81 123085 node->qualifiers.isPublic = true;
82
1/2
✓ Branch 15 → 16 taken 1388 times.
✗ Branch 15 → 17 not taken.
1388 else if (qualifier->type == QualifierNode::QualifierType::TY_CONST)
83 1388 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 95975 times.
✓ Branch 36 → 51 taken 46061 times.
142036 if (node->isMethod) {
91
1/2
✓ Branch 38 → 39 taken 95975 times.
✗ Branch 38 → 109 not taken.
95975 const std::string scopeName = Struct::getScopeName(node->name->structName);
92
1/2
✓ Branch 40 → 41 taken 95975 times.
✗ Branch 40 → 121 not taken.
95975 node->structScope = currentScope = currentScope->getChildScope(scopeName);
93
1/2
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 49 taken 95975 times.
95975 if (!currentScope)
94 ✗ throw SemanticError(node, REFERENCED_UNDEFINED_STRUCT, "Struct '" + node->name->structName + "' could not be found");
95 95975 }
96
97 // Create scope for the function
98
2/4
✓ Branch 51 → 52 taken 142036 times.
✗ Branch 51 → 126 not taken.
✓ Branch 52 → 53 taken 142036 times.
✗ Branch 52 → 124 not taken.
142036 node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
99
6/6
✓ Branch 54 → 55 taken 133095 times.
✓ Branch 54 → 57 taken 8941 times.
✓ Branch 55 → 56 taken 94064 times.
✓ Branch 55 → 58 taken 39031 times.
✓ Branch 56 → 57 taken 12617 times.
✓ Branch 56 → 58 taken 81447 times.
142036 currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope);
100
101 // Create symbol for 'this' variable
102
2/2
✓ Branch 59 → 60 taken 95975 times.
✓ Branch 59 → 69 taken 46061 times.
142036 if (node->isMethod)
103
1/2
✓ Branch 62 → 63 taken 95975 times.
✗ Branch 62 → 129 not taken.
383900 currentScope->insert(THIS_VARIABLE_NAME, node);
104
105 // Create symbol for 'result' variable
106
1/2
✓ Branch 71 → 72 taken 142036 times.
✗ Branch 71 → 135 not taken.
426108 currentScope->insert(RETURN_VARIABLE_NAME, node);
107
108 // Create symbols for the parameters
109
2/2
✓ Branch 77 → 78 taken 94932 times.
✓ Branch 77 → 81 taken 47104 times.
142036 if (node->hasParams)
110
1/2
✓ Branch 78 → 79 taken 94932 times.
✗ Branch 78 → 139 not taken.
94932 visit(node->paramLst);
111
112 // Visit the function body
113
1/2
✓ Branch 81 → 82 taken 142036 times.
✗ Branch 81 → 140 not taken.
142036 visit(node->body);
114
115 // Leave function body scope
116 142036 currentScope = node->scope->parent;
117
118 // Insert symbol for function into the symbol table
119
1/2
✓ Branch 83 → 84 taken 142036 times.
✗ Branch 83 → 143 not taken.
284072 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 142036 const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName);
124
3/4
✓ Branch 89 → 90 taken 15006 times.
✓ Branch 89 → 91 taken 127030 times.
✓ Branch 90 → 91 taken 15006 times.
✗ Branch 90 → 92 not taken.
142036 if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry)
125 142036 sourceFile->addNameRegistryEntry(node->name->fqName, TY_FUNCTION, node->entry, currentScope, true);
126
127 // Leave the struct scope
128
2/2
✓ Branch 92 → 93 taken 95975 times.
✓ Branch 92 → 94 taken 46061 times.
142036 if (node->isMethod)
129 95975 currentScope = node->structScope->parent;
130
131
1/2
✓ Branch 94 → 95 taken 142036 times.
✗ Branch 94 → 144 not taken.
284072 return nullptr;
132 }
133
134 61301 std::any SymbolTableBuilder::visitProcDef(ProcDefNode *node) {
135 // Visit attributes
136
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 6 taken 61299 times.
61301 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 50609 times.
✓ Branch 6 → 36 taken 10690 times.
61299 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
141
2/2
✓ Branch 34 → 9 taken 57080 times.
✓ Branch 34 → 35 taken 50609 times.
158298 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
142
2/2
✓ Branch 11 → 12 taken 6481 times.
✓ Branch 11 → 13 taken 50599 times.
57080 if (qualifier->type == QualifierNode::QualifierType::TY_INLINE)
143 6481 node->qualifiers.isInline = true;
144
2/2
✓ Branch 13 → 14 taken 50533 times.
✓ Branch 13 → 15 taken 66 times.
50599 else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
145 50533 node->qualifiers.isPublic = true;
146
1/2
✓ Branch 15 → 16 taken 66 times.
✗ Branch 15 → 17 not taken.
66 else if (qualifier->type == QualifierNode::QualifierType::TY_CONST)
147 66 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 50745 times.
✓ Branch 36 → 51 taken 10554 times.
61299 if (node->isMethod) {
155
1/2
✓ Branch 38 → 39 taken 50745 times.
✗ Branch 38 → 108 not taken.
50745 const std::string &scopeName = Struct::getScopeName(node->name->structName);
156
1/2
✓ Branch 40 → 41 taken 50745 times.
✗ Branch 40 → 120 not taken.
50745 node->structScope = currentScope = currentScope->getChildScope(scopeName);
157
2/2
✓ Branch 41 → 42 taken 2 times.
✓ Branch 41 → 49 taken 50743 times.
50745 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 50745 }
160
161 // Create scope for the procedure
162
2/4
✓ Branch 51 → 52 taken 61297 times.
✗ Branch 51 → 125 not taken.
✓ Branch 52 → 53 taken 61297 times.
✗ Branch 52 → 123 not taken.
61297 node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
163
6/6
✓ Branch 54 → 55 taken 53931 times.
✓ Branch 54 → 57 taken 7366 times.
✓ Branch 55 → 56 taken 47276 times.
✓ Branch 55 → 58 taken 6655 times.
✓ Branch 56 → 57 taken 12236 times.
✓ Branch 56 → 58 taken 35040 times.
61297 currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope);
164
4/4
✓ Branch 59 → 60 taken 50743 times.
✓ Branch 59 → 63 taken 10554 times.
✓ Branch 61 → 62 taken 2069 times.
✓ Branch 61 → 63 taken 48674 times.
61297 currentScope->isDtorScope = node->isMethod && node->name->name == DTOR_FUNCTION_NAME;
165
166 // Create symbol for 'this' variable
167
2/2
✓ Branch 64 → 65 taken 50743 times.
✓ Branch 64 → 74 taken 10554 times.
61297 if (node->isMethod)
168
1/2
✓ Branch 67 → 68 taken 50743 times.
✗ Branch 67 → 128 not taken.
202972 currentScope->insert(THIS_VARIABLE_NAME, node);
169
170 // Create symbols for the parameters
171
2/2
✓ Branch 74 → 75 taken 45229 times.
✓ Branch 74 → 78 taken 16068 times.
61297 if (node->hasParams)
172
1/2
✓ Branch 75 → 76 taken 45229 times.
✗ Branch 75 → 132 not taken.
45229 visit(node->paramLst);
173
174 // Visit the procedure body
175
1/2
✓ Branch 78 → 79 taken 61297 times.
✗ Branch 78 → 133 not taken.
61297 visit(node->body);
176
177 // Leave procedure body scope
178 61297 currentScope = node->scope->parent;
179
180 // Insert symbol for procedure into the symbol table
181
1/2
✓ Branch 80 → 81 taken 61297 times.
✗ Branch 80 → 136 not taken.
122594 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 61297 const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName);
186
3/4
✓ Branch 86 → 87 taken 10634 times.
✓ Branch 86 → 88 taken 50663 times.
✓ Branch 87 → 88 taken 10634 times.
✗ Branch 87 → 89 not taken.
61297 if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry)
187 61297 sourceFile->addNameRegistryEntry(node->name->fqName, TY_PROCEDURE, node->entry, currentScope, true);
188
189 // Leave the struct scope
190
2/2
✓ Branch 89 → 90 taken 50743 times.
✓ Branch 89 → 91 taken 10554 times.
61297 if (node->isMethod)
191 50743 currentScope = node->structScope->parent;
192
193 // Check if this is a constructor
194 61297 node->isCtor = node->name->nameFragments.back() == CTOR_FUNCTION_NAME;
195
196
1/2
✓ Branch 93 → 94 taken 61297 times.
✗ Branch 93 → 137 not taken.
122594 return nullptr;
197 }
198
199 16363 std::any SymbolTableBuilder::visitStructDef(StructDefNode *node) {
200 // Visit attributes
201
2/2
✓ Branch 2 → 3 taken 290 times.
✓ Branch 2 → 6 taken 16073 times.
16363 if (node->attrs)
202
1/2
✓ Branch 3 → 4 taken 290 times.
✗ Branch 3 → 79 not taken.
290 visit(node->attrs);
203
204 // Check if this name already exists
205
3/4
✓ Branch 6 → 7 taken 16363 times.
✗ Branch 6 → 110 not taken.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 17 taken 16361 times.
32726 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 16361 times.
✗ Branch 18 → 89 not taken.
16361 const std::string &scopeName = Struct::getScopeName(node->structName);
210
1/2
✓ Branch 20 → 21 taken 16361 times.
✗ Branch 20 → 108 not taken.
16361 node->structScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::STRUCT, &node->codeLoc);
211 16361 currentScope->isGenericScope = node->hasTemplateTypes;
212
213 // Insert implicit field for each interface type
214
2/2
✓ Branch 21 → 22 taken 5976 times.
✓ Branch 21 → 43 taken 10385 times.
16361 if (node->hasInterfaces) {
215
2/2
✓ Branch 41 → 24 taken 5976 times.
✓ Branch 41 → 42 taken 5976 times.
17928 for (DataTypeNode *interfaceNode : node->interfaceTypeLst->dataTypes) {
216 5976 const std::string &interfaceName = interfaceNode->baseDataType->customDataType->typeNameFragments.back();
217
1/2
✓ Branch 27 → 28 taken 5976 times.
✗ Branch 27 → 94 not taken.
11952 SymbolTableEntry *interfaceFieldEntry = currentScope->insert("this." + interfaceName, interfaceNode);
218 5976 interfaceFieldEntry->used = true;
219 5976 interfaceFieldEntry->isImplicitField = true;
220 }
221 }
222
223 // Visit children
224
2/2
✓ Branch 43 → 44 taken 16359 times.
✓ Branch 43 → 96 taken 2 times.
16361 visitChildren(node);
225
226 // Leave the struct scope
227 16359 currentScope = node->structScope->parent;
228
229 // Build struct qualifiers
230
2/2
✓ Branch 45 → 46 taken 14067 times.
✓ Branch 45 → 70 taken 2292 times.
16359 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
231
2/2
✓ Branch 68 → 48 taken 14067 times.
✓ Branch 68 → 69 taken 14067 times.
42201 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
232
1/2
✓ Branch 50 → 51 taken 14067 times.
✗ Branch 50 → 54 not taken.
14067 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
233 14067 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 16359 times.
✗ Branch 70 → 108 not taken.
16359 node->entry = rootScope->insert(node->structName, node);
241 // Register the name in the exported name registry
242
1/2
✓ Branch 73 → 74 taken 16359 times.
✗ Branch 73 → 108 not taken.
16359 sourceFile->addNameRegistryEntry(node->structName, node->typeId, node->entry, node->structScope, true);
243
244
1/2
✓ Branch 74 → 75 taken 16359 times.
✗ Branch 74 → 107 not taken.
32718 return nullptr;
245 16361 }
246
247 823 std::any SymbolTableBuilder::visitInterfaceDef(InterfaceDefNode *node) {
248 // Visit attributes
249
2/2
✓ Branch 2 → 3 taken 456 times.
✓ Branch 2 → 6 taken 367 times.
823 if (node->attrs)
250
1/2
✓ Branch 3 → 4 taken 456 times.
✗ Branch 3 → 71 not taken.
456 visit(node->attrs);
251
252 // Check if this name already exists
253
3/4
✓ Branch 6 → 7 taken 823 times.
✗ Branch 6 → 99 not taken.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 17 taken 821 times.
1646 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 821 times.
✗ Branch 18 → 81 not taken.
821 const std::string &scopeName = Interface::getScopeName(node->interfaceName);
258
1/2
✓ Branch 20 → 21 taken 821 times.
✗ Branch 20 → 97 not taken.
821 node->interfaceScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::INTERFACE, &node->codeLoc);
259
260 // Visit signatures
261
2/2
✓ Branch 36 → 23 taken 5917 times.
✓ Branch 36 → 37 taken 821 times.
7559 for (SignatureNode *signature : node->signatures)
262
1/2
✓ Branch 25 → 26 taken 5917 times.
✗ Branch 25 → 84 not taken.
5917 visit(signature);
263
264 // Leave the interface scope
265 821 currentScope = node->interfaceScope->parent;
266
267 // Build interface qualifiers
268
2/2
✓ Branch 37 → 38 taken 781 times.
✓ Branch 37 → 62 taken 40 times.
821 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
269
2/2
✓ Branch 60 → 40 taken 781 times.
✓ Branch 60 → 61 taken 781 times.
2343 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
270
1/2
✓ Branch 42 → 43 taken 781 times.
✗ Branch 42 → 46 not taken.
781 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
271 781 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 821 times.
✗ Branch 62 → 97 not taken.
821 node->entry = rootScope->insert(node->interfaceName, node);
279 // Register the name in the exported name registry
280
1/2
✓ Branch 65 → 66 taken 821 times.
✗ Branch 65 → 97 not taken.
821 sourceFile->addNameRegistryEntry(node->interfaceName, node->typeId, node->entry, node->interfaceScope, true);
281
282
1/2
✓ Branch 66 → 67 taken 821 times.
✗ Branch 66 → 96 not taken.
1642 return nullptr;
283 821 }
284
285 38 std::any SymbolTableBuilder::visitUnionDef(UnionDefNode *node) {
286 // Visit attributes
287
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 6 taken 38 times.
38 if (node->attrs)
288 ✗ visit(node->attrs);
289
290 // Check if this name already exists
291
2/4
✓ Branch 6 → 7 taken 38 times.
✗ Branch 6 → 84 not taken.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 17 taken 38 times.
76 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 38 times.
✗ Branch 18 → 67 not taken.
38 const std::string &scopeName = Union::getScopeName(node->unionName);
296
1/2
✓ Branch 20 → 21 taken 38 times.
✗ Branch 20 → 82 not taken.
38 node->unionScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::UNION, &node->codeLoc);
297 38 currentScope->isGenericScope = node->hasTemplateTypes;
298
299 // Visit children
300
2/2
✓ Branch 21 → 22 taken 36 times.
✓ Branch 21 → 70 taken 2 times.
38 visitChildren(node);
301
302 // Leave the union scope
303 36 currentScope = node->unionScope->parent;
304
305 // Build union qualifiers
306
2/2
✓ Branch 23 → 24 taken 2 times.
✓ Branch 23 → 48 taken 34 times.
36 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
307
1/2
✓ Branch 46 → 26 taken 2 times.
✗ Branch 46 → 47 not taken.
4 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
308
1/2
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 32 taken 2 times.
2 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
309 ✗ 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 34 times.
✗ Branch 48 → 82 not taken.
34 node->entry = rootScope->insert(node->unionName, node);
317 // Register the name in the exported name registry
318
1/2
✓ Branch 51 → 52 taken 34 times.
✗ Branch 51 → 82 not taken.
34 sourceFile->addNameRegistryEntry(node->unionName, node->typeId, node->entry, node->unionScope, true);
319
320
1/2
✓ Branch 52 → 53 taken 34 times.
✗ Branch 52 → 81 not taken.
68 return nullptr;
321 38 }
322
323 4736 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 4734 times.
9472 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 4734 node->enumScope = currentScope =
330
2/4
✓ Branch 13 → 14 taken 4734 times.
✗ Branch 13 → 62 not taken.
✓ Branch 14 → 15 taken 4734 times.
✗ Branch 14 → 60 not taken.
4734 rootScope->createChildScope(ENUM_SCOPE_PREFIX + node->enumName, ScopeType::ENUM, &node->codeLoc);
331
332 // Visit items
333
2/2
✓ Branch 16 → 17 taken 4732 times.
✓ Branch 16 → 63 taken 2 times.
4734 visit(node->itemLst);
334
335 // Leave the enum scope
336 4732 currentScope = node->enumScope->parent;
337
338 // Build enum qualifiers
339
2/2
✓ Branch 18 → 19 taken 4347 times.
✓ Branch 18 → 43 taken 385 times.
4732 if (node->qualifierLst) {
340
2/2
✓ Branch 41 → 21 taken 4347 times.
✓ Branch 41 → 42 taken 4347 times.
13041 for (const QualifierNode *qualifier : node->qualifierLst->qualifiers) {
341
1/2
✓ Branch 23 → 24 taken 4347 times.
✗ Branch 23 → 27 not taken.
4347 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
342 4347 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 4732 node->entry = rootScope->insert(node->enumName, node);
350 // Register the name in the exported name registry
351 4732 sourceFile->addNameRegistryEntry(node->enumName, node->typeId, node->entry, node->enumScope, true);
352
353
1/2
✓ Branch 47 → 48 taken 4732 times.
✗ Branch 47 → 74 not taken.
9464 return nullptr;
354 }
355
356 7457 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 7455 times.
14914 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 7455 node->entry = rootScope->insert(node->typeName, node);
363 7455 node->entry->used = true; // Generic types are always used
364
365
1/2
✓ Branch 16 → 17 taken 7455 times.
✗ Branch 16 → 29 not taken.
14910 return nullptr;
366 }
367
368 3209 std::any SymbolTableBuilder::visitAliasDef(AliasDefNode *node) {
369 // Check if this name already exists
370
3/4
✓ Branch 2 → 3 taken 3209 times.
✗ Branch 2 → 73 not taken.
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 3207 times.
6418 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 2057 times.
✓ Branch 13 → 38 taken 1150 times.
3207 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
375
2/2
✓ Branch 36 → 16 taken 2057 times.
✓ Branch 36 → 37 taken 2057 times.
6171 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
376
1/2
✓ Branch 18 → 19 taken 2057 times.
✗ Branch 18 → 22 not taken.
2057 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
377 2057 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 3207 times.
✗ Branch 38 → 73 not taken.
3207 node->entry = rootScope->insert(node->aliasName, node);
385 // Register the name in the exported name registry
386
1/2
✓ Branch 41 → 42 taken 3207 times.
✗ Branch 41 → 73 not taken.
3207 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 3207 times.
✗ Branch 42 → 73 not taken.
3207 const std::string aliasedTypeContainerName = node->aliasName + ALIAS_CONTAINER_SUFFIX;
390
1/2
✓ Branch 43 → 44 taken 3207 times.
✗ Branch 43 → 71 not taken.
3207 node->aliasedTypeContainerEntry = rootScope->insert(aliasedTypeContainerName, node);
391
392
1/2
✓ Branch 46 → 47 taken 3207 times.
✗ Branch 46 → 70 not taken.
6414 return nullptr;
393 3207 }
394
395 21485 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 21483 times.
42970 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 21483 times.
✗ Branch 13 → 56 not taken.
✓ Branch 14 → 15 taken 21483 times.
✗ Branch 14 → 56 not taken.
✓ Branch 15 → 16 taken 21483 times.
✗ Branch 15 → 56 not taken.
✓ Branch 29 → 17 taken 102828 times.
✓ Branch 29 → 30 taken 21481 times.
124309 for (const auto &dependency : sourceFile->dependencies | std::views::values)
402
3/4
✓ Branch 18 → 19 taken 102828 times.
✗ Branch 18 → 56 not taken.
✓ Branch 19 → 20 taken 2 times.
✓ Branch 19 → 27 taken 102826 times.
102828 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 21481 node->entry = rootScope->insert(node->varName, node);
407 // Register the name in the exported name registry
408 21481 sourceFile->addNameRegistryEntry(node->varName, TY_INVALID, node->entry, currentScope, true);
409
410
1/2
✓ Branch 34 → 35 taken 21481 times.
✗ Branch 34 → 57 not taken.
42962 return nullptr;
411 }
412
413 17454 std::any SymbolTableBuilder::visitExtDecl(ExtDeclNode *node) {
414 // Visit attributes
415
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 6 taken 17452 times.
17454 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 17452 times.
34908 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 17452 times.
✗ Branch 17 → 43 not taken.
✓ Branch 18 → 19 taken 17452 times.
✗ Branch 18 → 41 not taken.
17452 rootScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
424
425 // Add the external declaration to the symbol table
426 17452 node->entry = rootScope->insert(node->extFunctionName, node);
427 // Register the name in the exported name registry
428
2/2
✓ Branch 23 → 24 taken 13827 times.
✓ Branch 23 → 25 taken 3625 times.
17452 const uint64_t typeId = node->returnType ? TY_FUNCTION : TY_PROCEDURE;
429 17452 sourceFile->addNameRegistryEntry(node->extFunctionName, typeId, node->entry, rootScope, /*keepNewOnCollision=*/true);
430
431
1/2
✓ Branch 27 → 28 taken 17452 times.
✗ Branch 27 → 44 not taken.
34904 return nullptr;
432 }
433
434 29963 std::any SymbolTableBuilder::visitUnsafeBlock(UnsafeBlockNode *node) {
435 // Create scope for the unsafe block body
436 29963 node->bodyScope = currentScope =
437
2/4
✓ Branch 2 → 3 taken 29963 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 29963 times.
✗ Branch 3 → 11 not taken.
29963 currentScope->createChildScope(node->getScopeId(), ScopeType::UNSAFE_BODY, &node->body->codeLoc);
438
439 // Visit body
440
1/2
✓ Branch 5 → 6 taken 29963 times.
✗ Branch 5 → 14 not taken.
29963 visit(node->body);
441
442 // Leave thread body scope
443 29963 currentScope = node->bodyScope->parent;
444
445
1/2
✓ Branch 7 → 8 taken 29963 times.
✗ Branch 7 → 15 not taken.
59926 return nullptr;
446 }
447
448 12760 std::any SymbolTableBuilder::visitForLoop(ForLoopNode *node) {
449 // Create scope for the loop body
450
2/4
✓ Branch 2 → 3 taken 12760 times.
✗ Branch 2 → 16 not taken.
✓ Branch 3 → 4 taken 12760 times.
✗ Branch 3 → 14 not taken.
12760 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 12760 times.
✗ Branch 5 → 17 not taken.
12760 visit(node->initDecl);
454
455 // Visit condition
456 12760 visitInExprScope(node->condAssign);
457
458 // Visit body
459
1/2
✓ Branch 8 → 9 taken 12760 times.
✗ Branch 8 → 18 not taken.
12760 visit(node->body);
460
461 // Leave for body scope
462 12760 currentScope = node->bodyScope->parent;
463
464
1/2
✓ Branch 10 → 11 taken 12760 times.
✗ Branch 10 → 19 not taken.
25520 return nullptr;
465 }
466
467 15383 std::any SymbolTableBuilder::visitForeachLoop(ForeachLoopNode *node) {
468 // Create scope for the loop body
469 15383 node->bodyScope = currentScope =
470
2/4
✓ Branch 2 → 3 taken 15383 times.
✗ Branch 2 → 19 not taken.
✓ Branch 3 → 4 taken 15383 times.
✗ Branch 3 → 17 not taken.
15383 currentScope->createChildScope(node->getScopeId(), ScopeType::FOREACH_BODY, &node->body->codeLoc);
471
472 // Visit index variable declaration
473
2/2
✓ Branch 5 → 6 taken 1164 times.
✓ Branch 5 → 9 taken 14219 times.
15383 if (node->idxVarDecl)
474
1/2
✓ Branch 6 → 7 taken 1164 times.
✗ Branch 6 → 20 not taken.
1164 visit(node->idxVarDecl);
475
476 // Visit item variable declaration
477
1/2
✓ Branch 9 → 10 taken 15383 times.
✗ Branch 9 → 21 not taken.
15383 visit(node->itemVarDecl);
478
479 // Visit body
480
1/2
✓ Branch 11 → 12 taken 15383 times.
✗ Branch 11 → 22 not taken.
15383 visit(node->body);
481
482 // Leave foreach body scope
483 15383 currentScope = node->bodyScope->parent;
484
485
1/2
✓ Branch 13 → 14 taken 15383 times.
✗ Branch 13 → 23 not taken.
30766 return nullptr;
486 }
487
488 10345 std::any SymbolTableBuilder::visitWhileLoop(WhileLoopNode *node) {
489 // Create scope for the loop body
490 10345 node->bodyScope = currentScope =
491
2/4
✓ Branch 2 → 3 taken 10345 times.
✗ Branch 2 → 14 not taken.
✓ Branch 3 → 4 taken 10345 times.
✗ Branch 3 → 12 not taken.
10345 currentScope->createChildScope(node->getScopeId(), ScopeType::WHILE_BODY, &node->body->codeLoc);
492
493 // Visit condition
494 10345 visitInExprScope(node->condition);
495
496 // Visit body
497
1/2
✓ Branch 6 → 7 taken 10345 times.
✗ Branch 6 → 15 not taken.
10345 visit(node->body);
498
499 // Leave while body scope
500 10345 currentScope = node->bodyScope->parent;
501
502
1/2
✓ Branch 8 → 9 taken 10345 times.
✗ Branch 8 → 16 not taken.
20690 return nullptr;
503 }
504
505 187 std::any SymbolTableBuilder::visitDoWhileLoop(DoWhileLoopNode *node) {
506 // Create scope for the loop body
507 187 node->bodyScope = currentScope =
508
2/4
✓ Branch 2 → 3 taken 187 times.
✗ Branch 2 → 14 not taken.
✓ Branch 3 → 4 taken 187 times.
✗ Branch 3 → 12 not taken.
187 currentScope->createChildScope(node->getScopeId(), ScopeType::WHILE_BODY, &node->body->codeLoc);
509
510 // Visit condition
511 187 visitInExprScope(node->condition);
512
513 // Visit body
514
1/2
✓ Branch 6 → 7 taken 187 times.
✗ Branch 6 → 15 not taken.
187 visit(node->body);
515
516 // Leave do-while body scope
517 187 currentScope = node->bodyScope->parent;
518
519
1/2
✓ Branch 8 → 9 taken 187 times.
✗ Branch 8 → 16 not taken.
374 return nullptr;
520 }
521
522 161380 std::any SymbolTableBuilder::visitIfStmt(IfStmtNode *node) {
523 // Create scope for the then body
524 161380 node->thenBodyScope = currentScope =
525
2/4
✓ Branch 2 → 3 taken 161380 times.
✗ Branch 2 → 26 not taken.
✓ Branch 3 → 4 taken 161380 times.
✗ Branch 3 → 24 not taken.
161380 currentScope->createChildScope(node->getScopeId(), ScopeType::IF_ELSE_BODY, &node->thenBody->codeLoc);
526
527 // Visit condition
528 161380 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 161380 times.
✗ Branch 7 → 11 not taken.
161380 if (node->doCompileThenBranch(manIdx))
532
1/2
✓ Branch 8 → 9 taken 161380 times.
✗ Branch 8 → 27 not taken.
161380 visit(node->thenBody);
533
534 // Leave then body scope
535 161380 currentScope = node->thenBodyScope->parent;
536
537 // Visit else stmt
538
5/6
✓ Branch 12 → 13 taken 161380 times.
✗ Branch 12 → 15 not taken.
✓ Branch 13 → 14 taken 24617 times.
✓ Branch 13 → 15 taken 136763 times.
✓ Branch 16 → 17 taken 24617 times.
✓ Branch 16 → 20 taken 136763 times.
161380 if (node->doCompileElseBranch(manIdx) && node->elseStmt)
539
1/2
✓ Branch 17 → 18 taken 24617 times.
✗ Branch 17 → 28 not taken.
24617 visit(node->elseStmt);
540
541
1/2
✓ Branch 20 → 21 taken 161380 times.
✗ Branch 20 → 29 not taken.
322760 return nullptr;
542 }
543
544 24617 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 13903 times.
✓ Branch 2 → 8 taken 10714 times.
24617 if (node->isElseIf) {
547
1/2
✓ Branch 3 → 4 taken 13903 times.
✗ Branch 3 → 17 not taken.
13903 visit(node->ifStmt);
548
1/2
✓ Branch 5 → 6 taken 13903 times.
✗ Branch 5 → 18 not taken.
27806 return nullptr;
549 }
550
551 // Create scope for the else body
552 10714 node->elseBodyScope = currentScope =
553
2/4
✓ Branch 8 → 9 taken 10714 times.
✗ Branch 8 → 21 not taken.
✓ Branch 9 → 10 taken 10714 times.
✗ Branch 9 → 19 not taken.
10714 currentScope->createChildScope(node->getScopeId(), ScopeType::IF_ELSE_BODY, &node->body->codeLoc);
554
555 // Visit else body
556
1/2
✓ Branch 11 → 12 taken 10714 times.
✗ Branch 11 → 22 not taken.
10714 visit(node->body);
557
558 // Leave else body scope
559 10714 currentScope = node->elseBodyScope->parent;
560
561
1/2
✓ Branch 13 → 14 taken 10714 times.
✗ Branch 13 → 23 not taken.
21428 return nullptr;
562 }
563
564 26827 std::any SymbolTableBuilder::visitCaseBranch(CaseBranchNode *node) {
565 // Create scope for the case branch
566
2/4
✓ Branch 2 → 3 taken 26827 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 26827 times.
✗ Branch 3 → 11 not taken.
26827 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 26827 times.
✗ Branch 5 → 14 not taken.
26827 visit(node->body);
570
571 // Leave case body scope
572 26827 currentScope = node->bodyScope->parent;
573
574
1/2
✓ Branch 7 → 8 taken 26827 times.
✗ Branch 7 → 15 not taken.
53654 return nullptr;
575 }
576
577 1469 std::any SymbolTableBuilder::visitDefaultBranch(DefaultBranchNode *node) {
578 // Create scope for the default branch
579 1469 node->bodyScope = currentScope =
580
2/4
✓ Branch 2 → 3 taken 1469 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 1469 times.
✗ Branch 3 → 11 not taken.
1469 currentScope->createChildScope(node->getScopeId(), ScopeType::DEFAULT_BODY, &node->body->codeLoc);
581
582 // Visit default body
583
1/2
✓ Branch 5 → 6 taken 1469 times.
✗ Branch 5 → 14 not taken.
1469 visit(node->body);
584
585 // Leave default body scope
586 1469 currentScope = node->bodyScope->parent;
587
588
1/2
✓ Branch 7 → 8 taken 1469 times.
✗ Branch 7 → 15 not taken.
2938 return nullptr;
589 }
590
591 365 std::any SymbolTableBuilder::visitAnonymousBlockStmt(AnonymousBlockStmtNode *node) {
592 // Create scope for the anonymous block body
593 365 node->bodyScope = currentScope =
594
2/4
✓ Branch 2 → 3 taken 365 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 365 times.
✗ Branch 3 → 11 not taken.
365 currentScope->createChildScope(node->getScopeId(), ScopeType::ANONYMOUS_BLOCK_BODY, &node->body->codeLoc);
595
596 // Visit body
597
1/2
✓ Branch 5 → 6 taken 365 times.
✗ Branch 5 → 14 not taken.
365 visit(node->body);
598
599 // Leave anonymous block body scope
600 365 currentScope = node->bodyScope->parent;
601
602
1/2
✓ Branch 7 → 8 taken 365 times.
✗ Branch 7 → 15 not taken.
730 return nullptr;
603 }
604
605 52978 std::any SymbolTableBuilder::visitEnumItem(EnumItemNode *node) {
606 // Check if enum item already exists in the same scope.
607
3/4
✓ Branch 2 → 3 taken 52978 times.
✗ Branch 2 → 42 not taken.
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 52976 times.
105956 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 52976 times.
✗ Branch 13 → 42 not taken.
52976 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 52976 times.
52976 assert(node->enumDef != nullptr);
615
2/4
✓ Branch 18 → 19 taken 52976 times.
✗ Branch 18 → 38 not taken.
✓ Branch 19 → 20 taken 52976 times.
✗ Branch 19 → 36 not taken.
52976 const std::string name = node->enumDef->enumName + SCOPE_ACCESS_TOKEN + node->itemName;
616
1/2
✓ Branch 21 → 22 taken 52976 times.
✗ Branch 21 → 40 not taken.
52976 sourceFile->addNameRegistryEntry(name, TY_INT, enumItemEntry, currentScope, true);
617
618
1/2
✓ Branch 22 → 23 taken 52976 times.
✗ Branch 22 → 39 not taken.
105952 return nullptr;
619 52976 }
620
621 65350 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 65346 times.
130700 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 65346 currentScope->insert(node->fieldName, node);
628
629
1/2
✓ Branch 16 → 17 taken 65346 times.
✗ Branch 16 → 29 not taken.
130692 return nullptr;
630 }
631
632 5917 std::any SymbolTableBuilder::visitSignature(SignatureNode *node) {
633 // Build signature qualifiers
634
2/2
✓ Branch 2 → 3 taken 5811 times.
✓ Branch 2 → 32 taken 106 times.
5917 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
635
2/2
✓ Branch 30 → 5 taken 5811 times.
✓ Branch 30 → 31 taken 5811 times.
17433 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
636
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 5811 times.
5811 if (qualifier->type == QualifierNode::QualifierType::TY_INLINE)
637 ✗ node->signatureQualifiers.isInline = true;
638
1/2
✓ Branch 9 → 10 taken 5811 times.
✗ Branch 9 → 11 not taken.
5811 else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
639 5811 node->signatureQualifiers.isPublic = true;
640 ✗ else if (qualifier->type == QualifierNode::QualifierType::TY_CONST)
641 ✗ 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 5917 times.
✗ Branch 32 → 53 not taken.
11834 node->entry = currentScope->insert(Function::getSymbolTableEntryName(node->methodName, node->codeLoc), node);
650
651
1/2
✓ Branch 37 → 38 taken 5917 times.
✗ Branch 37 → 54 not taken.
11834 return nullptr;
652 }
653
654 469672 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 469670 times.
939344 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 223611 times.
✓ Branch 13 → 17 taken 246059 times.
469670 if (node->hasAssignment)
661
1/2
✓ Branch 14 → 15 taken 223611 times.
✗ Branch 14 → 33 not taken.
223611 visit(node->assignExpr);
662
663 // Add variable entry to symbol table
664 469670 SymbolTableEntry *varEntry = currentScope->insert(node->varName, node);
665 469670 varEntry->isParam = node->isFctParam;
666
667
1/2
✓ Branch 20 → 21 taken 469670 times.
✗ Branch 20 → 34 not taken.
939340 return nullptr;
668 }
669
670 2582 std::any SymbolTableBuilder::visitModAttr(ModAttrNode *node) {
671 // Visit attributes
672
2/2
✓ Branch 2 → 3 taken 2580 times.
✓ Branch 2 → 126 taken 2 times.
2582 visitChildren(node);
673
674 // Retrieve attributes
675 2580 const AttrLstNode *attrs = node->attrLst;
676
677 // Collect linker flags
678 2580 std::vector<const CompileTimeValue *> linkerFlagValues;
679 // core.linker.flag
680
2/4
✓ Branch 6 → 7 taken 2580 times.
✗ Branch 6 → 129 not taken.
✓ Branch 7 → 8 taken 2580 times.
✗ Branch 7 → 127 not taken.
5160 std::vector<const CompileTimeValue *> values = attrs->getAttrValuesByName(ATTR_CORE_LINKER_FLAG);
681
1/2
✓ Branch 16 → 17 taken 2580 times.
✗ Branch 16 → 133 not taken.
5160 linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end());
682 // core.linux.linker.flag
683 2580 const llvm::Triple &targetTriple = sourceFile->targetMachine->getTargetTriple();
684
2/2
✓ Branch 20 → 21 taken 2556 times.
✓ Branch 20 → 37 taken 24 times.
2580 if (targetTriple.isOSLinux()) {
685
2/4
✓ Branch 23 → 24 taken 2556 times.
✗ Branch 23 → 137 not taken.
✓ Branch 24 → 25 taken 2556 times.
✗ Branch 24 → 135 not taken.
5112 values = attrs->getAttrValuesByName(ATTR_CORE_LINUX_LINKER_FLAG);
686
1/2
✓ Branch 35 → 36 taken 2556 times.
✗ Branch 35 → 142 not taken.
5112 linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end());
687 }
688 // core.darwin.linker.flag
689
3/4
✓ Branch 37 → 38 taken 2580 times.
✗ Branch 37 → 187 not taken.
✓ Branch 38 → 39 taken 12 times.
✓ Branch 38 → 55 taken 2568 times.
2580 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 2568 times.
2580 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 8942 times.
✓ Branch 89 → 90 taken 2580 times.
14102 for (const CompileTimeValue *value : linkerFlagValues) {
699
1/2
✓ Branch 77 → 78 taken 8942 times.
✗ Branch 77 → 162 not taken.
8942 const std::string &flag = resourceManager.compileTimeStringValues.at(value->stringValueOffset);
700
1/2
✓ Branch 78 → 79 taken 8942 times.
✗ Branch 78 → 162 not taken.
8942 resourceManager.linker.addLinkerFlag(flag);
701
1/2
✓ Branch 79 → 80 taken 8942 times.
✗ Branch 79 → 162 not taken.
8942 sourceFile->sourceLinkerFlags.push_back(flag);
702 }
703
704 // core.linker.additionalSource
705
4/6
✓ Branch 90 → 91 taken 2580 times.
✗ Branch 90 → 165 not taken.
✓ Branch 91 → 92 taken 2580 times.
✗ Branch 91 → 163 not taken.
✓ Branch 116 → 94 taken 68 times.
✓ Branch 116 → 117 taken 2578 times.
5226 for (const CompileTimeValue *value : attrs->getAttrValuesByName(ATTR_CORE_LINKER_ADDITIONAL_SOURCE)) {
706
1/2
✓ Branch 96 → 97 taken 68 times.
✗ Branch 96 → 178 not taken.
68 const std::string &stringValue = resourceManager.compileTimeStringValues.at(value->stringValueOffset);
707
3/6
✓ Branch 97 → 98 taken 68 times.
✗ Branch 97 → 172 not taken.
✓ Branch 98 → 99 taken 68 times.
✗ Branch 98 → 169 not taken.
✓ Branch 99 → 100 taken 68 times.
✗ Branch 99 → 167 not taken.
68 const std::filesystem::path additionalSourcePath = sourceFile->filePath.parent_path() / stringValue;
708
3/4
✓ Branch 102 → 103 taken 68 times.
✗ Branch 102 → 175 not taken.
✓ Branch 103 → 104 taken 66 times.
✓ Branch 103 → 173 taken 2 times.
70 resourceManager.linker.addAdditionalSourcePath(additionalSourcePath);
709
1/2
✓ Branch 105 → 106 taken 66 times.
✗ Branch 105 → 176 not taken.
66 sourceFile->sourceAdditionalSourcePaths.push_back(additionalSourcePath);
710 2650 }
711
712
1/2
✓ Branch 120 → 121 taken 2578 times.
✗ Branch 120 → 186 not taken.
5156 return nullptr;
713 2582 }
714
715 19138 std::any SymbolTableBuilder::visitAttr(AttrNode *node) {
716 // Check if this attribute exists
717
1/2
✓ Branch 2 → 3 taken 19138 times.
✗ Branch 2 → 63 not taken.
19138 const auto it = ATTR_CONFIGS.find(node->key);
718
2/2
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 19136 times.
19138 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 19136 const auto &[target, type] = it->second;
723
2/2
✓ Branch 14 → 15 taken 2 times.
✓ Branch 14 → 22 taken 19134 times.
19136 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 4122 times.
✓ Branch 22 → 31 taken 15012 times.
✓ Branch 23 → 24 taken 2 times.
✓ Branch 23 → 31 taken 4120 times.
19134 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 19132 times.
✗ Branch 31 → 62 not taken.
38264 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 1554 std::any SymbolTableBuilder::visitLambdaProc(LambdaProcNode *node) {
760 // Create scope for the lambda body
761 1554 const CodeLoc &codeLoc = node->body->codeLoc;
762
2/4
✓ Branch 2 → 3 taken 1554 times.
✗ Branch 2 → 39 not taken.
✓ Branch 3 → 4 taken 1554 times.
✗ Branch 3 → 37 not taken.
1554 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 1554 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 1538 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 1538 times.
✓ Branch 16 → 17 taken 16 times.
✓ Branch 16 → 19 taken 1538 times.
✓ Branch 19 → 20 taken 16 times.
✓ Branch 19 → 27 taken 1538 times.
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 42 not taken.
✗ Branch 44 → 45 not taken.
✗ Branch 44 → 47 not taken.
1586 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 1166 times.
✓ Branch 27 → 31 taken 388 times.
1554 if (node->hasParams)
771
1/2
✓ Branch 28 → 29 taken 1166 times.
✗ Branch 28 → 55 not taken.
1166 visit(node->paramLst);
772
773 // Visit body
774
1/2
✓ Branch 31 → 32 taken 1554 times.
✗ Branch 31 → 56 not taken.
1554 visit(node->body);
775
776 // Leave anonymous block body scope
777 1554 currentScope = node->bodyScope->parent;
778
779
1/2
✓ Branch 33 → 34 taken 1554 times.
✗ Branch 33 → 57 not taken.
3108 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 10129 std::any SymbolTableBuilder::visitTernaryExpr(TernaryExprNode *node) {
803 // Visit condition, which is evaluated unconditionally
804
1/2
✓ Branch 2 → 3 taken 10129 times.
✗ Branch 2 → 13 not taken.
10129 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 10127 times.
✓ Branch 4 → 7 taken 2 times.
✓ Branch 5 → 6 taken 10127 times.
✗ Branch 5 → 7 not taken.
10129 if (node->trueExpr && !node->isShortened)
809 10127 visitInExprScope(node->trueExpr);
810
1/2
✓ Branch 7 → 8 taken 10129 times.
✗ Branch 7 → 9 not taken.
10129 if (node->falseExpr)
811 10129 visitInExprScope(node->falseExpr);
812
813
1/2
✓ Branch 9 → 10 taken 10129 times.
✗ Branch 9 → 14 not taken.
20258 return nullptr;
814 }
815
816 16833 std::any SymbolTableBuilder::visitLogicalOrExpr(LogicalOrExprNode *node) {
817 // Visit the first operand, which is evaluated unconditionally
818
1/2
✓ Branch 3 → 4 taken 16833 times.
✗ Branch 3 → 15 not taken.
16833 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 23977 times.
✓ Branch 10 → 11 taken 16833 times.
40810 for (size_t i = 1; i < node->operands.size(); i++)
822 23977 visitInExprScope(node->operands[i]);
823
824
1/2
✓ Branch 11 → 12 taken 16833 times.
✗ Branch 11 → 16 not taken.
33666 return nullptr;
825 }
826
827 23185 std::any SymbolTableBuilder::visitLogicalAndExpr(LogicalAndExprNode *node) {
828 // Visit the first operand, which is evaluated unconditionally
829
1/2
✓ Branch 3 → 4 taken 23185 times.
✗ Branch 3 → 15 not taken.
23185 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 28703 times.
✓ Branch 10 → 11 taken 23185 times.
51888 for (size_t i = 1; i < node->operands.size(); i++)
833 28703 visitInExprScope(node->operands[i]);
834
835
1/2
✓ Branch 11 → 12 taken 23185 times.
✗ Branch 11 → 16 not taken.
46370 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 257608 void SymbolTableBuilder::visitInExprScope(ExprNode *expr) {
846 // Create scope for the expression
847
2/4
✓ Branch 2 → 3 taken 257608 times.
✗ Branch 2 → 10 not taken.
✓ Branch 3 → 4 taken 257608 times.
✗ Branch 3 → 8 not taken.
257608 currentScope = currentScope->createChildScope(expr->getExprScopeId(), ScopeType::EXPR_BODY, &expr->codeLoc);
848
849 // Visit the expression
850
1/2
✓ Branch 5 → 6 taken 257608 times.
✗ Branch 5 → 11 not taken.
257608 visit(expr);
851
852 // Leave expression scope
853 257608 currentScope = currentScope->parent;
854 257608 }
855
856 } // namespace spice::compiler
857