GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 96.4% 402 / 0 / 417
Functions: 100.0% 37 / 0 / 37
Branches: 59.1% 469 / 0 / 794

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 5127 SymbolTableBuilder::SymbolTableBuilder(GlobalResourceManager &resourceManager, SourceFile *sourceFile)
17 5127 : CompilerPass(resourceManager, sourceFile), rootScope(sourceFile->globalScope.get()) {}
18
19 5127 std::any SymbolTableBuilder::visitEntry(EntryNode *node) {
20 // Initialize
21 5127 currentScope = rootScope;
22
23 // Visit children
24
2/2
✓ Branch 2 → 3 taken 5089 times.
✓ Branch 2 → 23 taken 38 times.
5127 visitChildren(node);
25
26 // Check if the main function exists
27
4/4
✓ Branch 4 → 5 taken 5083 times.
✓ Branch 4 → 7 taken 6 times.
✓ Branch 5 → 6 taken 5071 times.
✓ Branch 5 → 7 taken 12 times.
5089 const bool mainFctRequired = cliOptions.outputContainer == OutputContainer::EXECUTABLE && !cliOptions.noEntryFct;
28
6/6
✓ Branch 8 → 9 taken 1257 times.
✓ Branch 8 → 19 taken 3832 times.
✓ Branch 9 → 10 taken 1241 times.
✓ Branch 9 → 19 taken 16 times.
✓ Branch 10 → 11 taken 4 times.
✓ Branch 10 → 19 taken 1237 times.
5089 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 5085 times.
✗ Branch 19 → 33 not taken.
10170 return nullptr;
32 }
33
34 1249 std::any SymbolTableBuilder::visitMainFctDef(MainFctDefNode *node) {
35 // Visit attributes
36
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 6 taken 1247 times.
1249 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 1247 times.
✗ Branch 8 → 55 not taken.
✓ Branch 14 → 15 taken 2 times.
✓ Branch 14 → 23 taken 1245 times.
4988 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 1245 times.
✗ Branch 25 → 70 not taken.
3735 SymbolTableEntry *mainFctEntry = currentScope->insert(MAIN_FUNCTION_NAME, node);
45 1245 mainFctEntry->used = true;
46
47 // Create scope for main function body
48
1/2
✓ Branch 31 → 32 taken 1245 times.
✗ Branch 31 → 85 not taken.
1245 const std::string &scopeId = MainFctDefNode::getScopeId();
49
1/2
✓ Branch 32 → 33 taken 1245 times.
✗ Branch 32 → 83 not taken.
1245 node->bodyScope = currentScope = rootScope->createChildScope(scopeId, ScopeType::FUNC_PROC_BODY, &node->codeLoc);
50 1245 currentScope->isGenericScope = false;
51
52 // Declare variable for the return value in the function scope
53
1/2
✓ Branch 35 → 36 taken 1245 times.
✗ Branch 35 → 76 not taken.
3735 SymbolTableEntry *resultVarEntry = node->bodyScope->insert(RETURN_VARIABLE_NAME, node);
54 1245 resultVarEntry->used = true;
55
56 // Visit arguments in new scope
57
2/2
✓ Branch 41 → 42 taken 14 times.
✓ Branch 41 → 45 taken 1231 times.
1245 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 1243 times.
✓ Branch 45 → 81 taken 2 times.
1245 visit(node->body);
62
63 // Return to root scope
64 1243 currentScope = rootScope;
65
66 1243 hasMainFunction = true;
67
1/2
✓ Branch 47 → 48 taken 1243 times.
✗ Branch 47 → 82 not taken.
2486 return nullptr;
68 1245 }
69
70 36347 std::any SymbolTableBuilder::visitFctDef(FctDefNode *node) {
71 // Visit attributes
72
2/2
✓ Branch 2 → 3 taken 1320 times.
✓ Branch 2 → 6 taken 35027 times.
36347 if (node->attrs)
73
1/2
✓ Branch 3 → 4 taken 1320 times.
✗ Branch 3 → 98 not taken.
1320 visit(node->attrs);
74
75 // Build function qualifiers
76
2/2
✓ Branch 6 → 7 taken 34638 times.
✓ Branch 6 → 36 taken 1709 times.
36347 if (const QualifierLstNode *qualifierLst = node->qualifierLst; qualifierLst) {
77
2/2
✓ Branch 34 → 9 taken 48560 times.
✓ Branch 34 → 35 taken 34638 times.
117836 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
78
2/2
✓ Branch 11 → 12 taken 14011 times.
✓ Branch 11 → 13 taken 34549 times.
48560 if (qualifier->type == QualifierNode::QualifierType::TY_INLINE)
79 14011 node->qualifiers.isInline = true;
80
2/2
✓ Branch 13 → 14 taken 34389 times.
✓ Branch 13 → 15 taken 160 times.
34549 else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
81 34389 node->qualifiers.isPublic = true;
82
1/2
✓ Branch 15 → 16 taken 160 times.
✗ Branch 15 → 17 not taken.
160 else if (qualifier->type == QualifierNode::QualifierType::TY_CONST)
83 160 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 16759 times.
✓ Branch 36 → 51 taken 19588 times.
36347 if (node->isMethod) {
91
1/2
✓ Branch 38 → 39 taken 16759 times.
✗ Branch 38 → 109 not taken.
16759 const std::string scopeName = Struct::getScopeName(node->name->structName);
92
1/2
✓ Branch 40 → 41 taken 16759 times.
✗ Branch 40 → 121 not taken.
16759 node->structScope = currentScope = currentScope->getChildScope(scopeName);
93
1/2
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 49 taken 16759 times.
16759 if (!currentScope)
94 ✗ throw SemanticError(node, REFERENCED_UNDEFINED_STRUCT, "Struct '" + node->name->structName + "' could not be found");
95 16759 }
96
97 // Create scope for the function
98
2/4
✓ Branch 51 → 52 taken 36347 times.
✗ Branch 51 → 126 not taken.
✓ Branch 52 → 53 taken 36347 times.
✗ Branch 52 → 124 not taken.
36347 node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
99
6/6
✓ Branch 54 → 55 taken 31935 times.
✓ Branch 54 → 57 taken 4412 times.
✓ Branch 55 → 56 taken 16230 times.
✓ Branch 55 → 58 taken 15705 times.
✓ Branch 56 → 57 taken 5753 times.
✓ Branch 56 → 58 taken 10477 times.
36347 currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope);
100
101 // Create symbol for 'this' variable
102
2/2
✓ Branch 59 → 60 taken 16759 times.
✓ Branch 59 → 69 taken 19588 times.
36347 if (node->isMethod)
103
1/2
✓ Branch 62 → 63 taken 16759 times.
✗ Branch 62 → 129 not taken.
67036 currentScope->insert(THIS_VARIABLE_NAME, node);
104
105 // Create symbol for 'result' variable
106
1/2
✓ Branch 71 → 72 taken 36347 times.
✗ Branch 71 → 135 not taken.
109041 currentScope->insert(RETURN_VARIABLE_NAME, node);
107
108 // Create symbols for the parameters
109
2/2
✓ Branch 77 → 78 taken 26328 times.
✓ Branch 77 → 81 taken 10019 times.
36347 if (node->hasParams)
110
1/2
✓ Branch 78 → 79 taken 26328 times.
✗ Branch 78 → 139 not taken.
26328 visit(node->paramLst);
111
112 // Visit the function body
113
1/2
✓ Branch 81 → 82 taken 36347 times.
✗ Branch 81 → 140 not taken.
36347 visit(node->body);
114
115 // Leave function body scope
116 36347 currentScope = node->scope->parent;
117
118 // Insert symbol for function into the symbol table
119
1/2
✓ Branch 83 → 84 taken 36347 times.
✗ Branch 83 → 143 not taken.
72694 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 36347 const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName);
124
3/4
✓ Branch 89 → 90 taken 7773 times.
✓ Branch 89 → 91 taken 28574 times.
✓ Branch 90 → 91 taken 7773 times.
✗ Branch 90 → 92 not taken.
36347 if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry)
125 36347 sourceFile->addNameRegistryEntry(node->name->fqName, TY_FUNCTION, node->entry, currentScope, true);
126
127 // Leave the struct scope
128
2/2
✓ Branch 92 → 93 taken 16759 times.
✓ Branch 92 → 94 taken 19588 times.
36347 if (node->isMethod)
129 16759 currentScope = node->structScope->parent;
130
131
1/2
✓ Branch 94 → 95 taken 36347 times.
✗ Branch 94 → 144 not taken.
72694 return nullptr;
132 }
133
134 23093 std::any SymbolTableBuilder::visitProcDef(ProcDefNode *node) {
135 // Visit attributes
136
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 6 taken 23091 times.
23093 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 18756 times.
✓ Branch 6 → 36 taken 4335 times.
23091 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
141
2/2
✓ Branch 34 → 9 taken 22276 times.
✓ Branch 34 → 35 taken 18756 times.
59788 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
142
2/2
✓ Branch 11 → 12 taken 3530 times.
✓ Branch 11 → 13 taken 18746 times.
22276 if (qualifier->type == QualifierNode::QualifierType::TY_INLINE)
143 3530 node->qualifiers.isInline = true;
144
2/2
✓ Branch 13 → 14 taken 18740 times.
✓ Branch 13 → 15 taken 6 times.
18746 else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
145 18740 node->qualifiers.isPublic = true;
146
1/2
✓ Branch 15 → 16 taken 6 times.
✗ Branch 15 → 17 not taken.
6 else if (qualifier->type == QualifierNode::QualifierType::TY_CONST)
147 6 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 18347 times.
✓ Branch 36 → 51 taken 4744 times.
23091 if (node->isMethod) {
155
1/2
✓ Branch 38 → 39 taken 18347 times.
✗ Branch 38 → 108 not taken.
18347 const std::string &scopeName = Struct::getScopeName(node->name->structName);
156
1/2
✓ Branch 40 → 41 taken 18347 times.
✗ Branch 40 → 120 not taken.
18347 node->structScope = currentScope = currentScope->getChildScope(scopeName);
157
2/2
✓ Branch 41 → 42 taken 2 times.
✓ Branch 41 → 49 taken 18345 times.
18347 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 18347 }
160
161 // Create scope for the procedure
162
2/4
✓ Branch 51 → 52 taken 23089 times.
✗ Branch 51 → 125 not taken.
✓ Branch 52 → 53 taken 23089 times.
✗ Branch 52 → 123 not taken.
23089 node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
163
6/6
✓ Branch 54 → 55 taken 18500 times.
✓ Branch 54 → 57 taken 4589 times.
✓ Branch 55 → 56 taken 15932 times.
✓ Branch 55 → 58 taken 2568 times.
✓ Branch 56 → 57 taken 5195 times.
✓ Branch 56 → 58 taken 10737 times.
23089 currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope);
164
4/4
✓ Branch 59 → 60 taken 18345 times.
✓ Branch 59 → 63 taken 4744 times.
✓ Branch 61 → 62 taken 708 times.
✓ Branch 61 → 63 taken 17637 times.
23089 currentScope->isDtorScope = node->isMethod && node->name->name == DTOR_FUNCTION_NAME;
165
166 // Create symbol for 'this' variable
167
2/2
✓ Branch 64 → 65 taken 18345 times.
✓ Branch 64 → 74 taken 4744 times.
23089 if (node->isMethod)
168
1/2
✓ Branch 67 → 68 taken 18345 times.
✗ Branch 67 → 128 not taken.
73380 currentScope->insert(THIS_VARIABLE_NAME, node);
169
170 // Create symbols for the parameters
171
2/2
✓ Branch 74 → 75 taken 16571 times.
✓ Branch 74 → 78 taken 6518 times.
23089 if (node->hasParams)
172
1/2
✓ Branch 75 → 76 taken 16571 times.
✗ Branch 75 → 132 not taken.
16571 visit(node->paramLst);
173
174 // Visit the procedure body
175
1/2
✓ Branch 78 → 79 taken 23089 times.
✗ Branch 78 → 133 not taken.
23089 visit(node->body);
176
177 // Leave procedure body scope
178 23089 currentScope = node->scope->parent;
179
180 // Insert symbol for procedure into the symbol table
181
1/2
✓ Branch 80 → 81 taken 23089 times.
✗ Branch 80 → 136 not taken.
46178 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 23089 const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName);
186
3/4
✓ Branch 86 → 87 taken 5296 times.
✓ Branch 86 → 88 taken 17793 times.
✓ Branch 87 → 88 taken 5296 times.
✗ Branch 87 → 89 not taken.
23089 if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry)
187 23089 sourceFile->addNameRegistryEntry(node->name->fqName, TY_PROCEDURE, node->entry, currentScope, true);
188
189 // Leave the struct scope
190
2/2
✓ Branch 89 → 90 taken 18345 times.
✓ Branch 89 → 91 taken 4744 times.
23089 if (node->isMethod)
191 18345 currentScope = node->structScope->parent;
192
193 // Check if this is a constructor
194 23089 node->isCtor = node->name->nameFragments.back() == CTOR_FUNCTION_NAME;
195
196
1/2
✓ Branch 93 → 94 taken 23089 times.
✗ Branch 93 → 137 not taken.
46178 return nullptr;
197 }
198
199 4104 std::any SymbolTableBuilder::visitStructDef(StructDefNode *node) {
200 // Visit attributes
201
2/2
✓ Branch 2 → 3 taken 227 times.
✓ Branch 2 → 6 taken 3877 times.
4104 if (node->attrs)
202
1/2
✓ Branch 3 → 4 taken 227 times.
✗ Branch 3 → 79 not taken.
227 visit(node->attrs);
203
204 // Check if this name already exists
205
3/4
✓ Branch 6 → 7 taken 4104 times.
✗ Branch 6 → 110 not taken.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 17 taken 4102 times.
8208 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 4102 times.
✗ Branch 18 → 89 not taken.
4102 const std::string &scopeName = Struct::getScopeName(node->structName);
210
1/2
✓ Branch 20 → 21 taken 4102 times.
✗ Branch 20 → 108 not taken.
4102 node->structScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::STRUCT, &node->codeLoc);
211 4102 currentScope->isGenericScope = node->hasTemplateTypes;
212
213 // Insert implicit field for each interface type
214
2/2
✓ Branch 21 → 22 taken 564 times.
✓ Branch 21 → 43 taken 3538 times.
4102 if (node->hasInterfaces) {
215
2/2
✓ Branch 41 → 24 taken 564 times.
✓ Branch 41 → 42 taken 564 times.
1692 for (DataTypeNode *interfaceNode : node->interfaceTypeLst->dataTypes) {
216 564 const std::string &interfaceName = interfaceNode->baseDataType->customDataType->typeNameFragments.back();
217
1/2
✓ Branch 27 → 28 taken 564 times.
✗ Branch 27 → 94 not taken.
1128 SymbolTableEntry *interfaceFieldEntry = currentScope->insert("this." + interfaceName, interfaceNode);
218 564 interfaceFieldEntry->used = true;
219 564 interfaceFieldEntry->isImplicitField = true;
220 }
221 }
222
223 // Visit children
224
2/2
✓ Branch 43 → 44 taken 4100 times.
✓ Branch 43 → 96 taken 2 times.
4102 visitChildren(node);
225
226 // Leave the struct scope
227 4100 currentScope = node->structScope->parent;
228
229 // Build struct qualifiers
230
2/2
✓ Branch 45 → 46 taken 2590 times.
✓ Branch 45 → 70 taken 1510 times.
4100 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
231
2/2
✓ Branch 68 → 48 taken 2590 times.
✓ Branch 68 → 69 taken 2590 times.
7770 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
232
1/2
✓ Branch 50 → 51 taken 2590 times.
✗ Branch 50 → 54 not taken.
2590 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
233 2590 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 4100 times.
✗ Branch 70 → 108 not taken.
4100 node->entry = rootScope->insert(node->structName, node);
241 // Register the name in the exported name registry
242
1/2
✓ Branch 73 → 74 taken 4100 times.
✗ Branch 73 → 108 not taken.
4100 sourceFile->addNameRegistryEntry(node->structName, node->typeId, node->entry, node->structScope, true);
243
244
1/2
✓ Branch 74 → 75 taken 4100 times.
✗ Branch 74 → 107 not taken.
8200 return nullptr;
245 4102 }
246
247 417 std::any SymbolTableBuilder::visitInterfaceDef(InterfaceDefNode *node) {
248 // Visit attributes
249
2/2
✓ Branch 2 → 3 taken 330 times.
✓ Branch 2 → 6 taken 87 times.
417 if (node->attrs)
250
1/2
✓ Branch 3 → 4 taken 330 times.
✗ Branch 3 → 71 not taken.
330 visit(node->attrs);
251
252 // Check if this name already exists
253
3/4
✓ Branch 6 → 7 taken 417 times.
✗ Branch 6 → 99 not taken.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 17 taken 415 times.
834 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 415 times.
✗ Branch 18 → 81 not taken.
415 const std::string &scopeName = Interface::getScopeName(node->interfaceName);
258
1/2
✓ Branch 20 → 21 taken 415 times.
✗ Branch 20 → 97 not taken.
415 node->interfaceScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::INTERFACE, &node->codeLoc);
259
260 // Visit signatures
261
2/2
✓ Branch 36 → 23 taken 948 times.
✓ Branch 36 → 37 taken 415 times.
1778 for (SignatureNode *signature : node->signatures)
262
1/2
✓ Branch 25 → 26 taken 948 times.
✗ Branch 25 → 84 not taken.
948 visit(signature);
263
264 // Leave the interface scope
265 415 currentScope = node->interfaceScope->parent;
266
267 // Build interface qualifiers
268
2/2
✓ Branch 37 → 38 taken 375 times.
✓ Branch 37 → 62 taken 40 times.
415 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
269
2/2
✓ Branch 60 → 40 taken 375 times.
✓ Branch 60 → 61 taken 375 times.
1125 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
270
1/2
✓ Branch 42 → 43 taken 375 times.
✗ Branch 42 → 46 not taken.
375 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
271 375 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 415 times.
✗ Branch 62 → 97 not taken.
415 node->entry = rootScope->insert(node->interfaceName, node);
279 // Register the name in the exported name registry
280
1/2
✓ Branch 65 → 66 taken 415 times.
✗ Branch 65 → 97 not taken.
415 sourceFile->addNameRegistryEntry(node->interfaceName, node->typeId, node->entry, node->interfaceScope, true);
281
282
1/2
✓ Branch 66 → 67 taken 415 times.
✗ Branch 66 → 96 not taken.
830 return nullptr;
283 415 }
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 652 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 650 times.
1304 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 650 node->enumScope = currentScope =
330
2/4
✓ Branch 13 → 14 taken 650 times.
✗ Branch 13 → 62 not taken.
✓ Branch 14 → 15 taken 650 times.
✗ Branch 14 → 60 not taken.
650 rootScope->createChildScope(ENUM_SCOPE_PREFIX + node->enumName, ScopeType::ENUM, &node->codeLoc);
331
332 // Visit items
333
2/2
✓ Branch 16 → 17 taken 648 times.
✓ Branch 16 → 63 taken 2 times.
650 visit(node->itemLst);
334
335 // Leave the enum scope
336 648 currentScope = node->enumScope->parent;
337
338 // Build enum qualifiers
339
2/2
✓ Branch 18 → 19 taken 595 times.
✓ Branch 18 → 43 taken 53 times.
648 if (node->qualifierLst) {
340
2/2
✓ Branch 41 → 21 taken 595 times.
✓ Branch 41 → 42 taken 595 times.
1785 for (const QualifierNode *qualifier : node->qualifierLst->qualifiers) {
341
1/2
✓ Branch 23 → 24 taken 595 times.
✗ Branch 23 → 27 not taken.
595 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
342 595 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 648 node->entry = rootScope->insert(node->enumName, node);
350 // Register the name in the exported name registry
351 648 sourceFile->addNameRegistryEntry(node->enumName, node->typeId, node->entry, node->enumScope, true);
352
353
1/2
✓ Branch 47 → 48 taken 648 times.
✗ Branch 47 → 74 not taken.
1296 return nullptr;
354 }
355
356 4048 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 4046 times.
8096 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 4046 node->entry = rootScope->insert(node->typeName, node);
363 4046 node->entry->used = true; // Generic types are always used
364
365
1/2
✓ Branch 16 → 17 taken 4046 times.
✗ Branch 16 → 29 not taken.
8092 return nullptr;
366 }
367
368 299 std::any SymbolTableBuilder::visitAliasDef(AliasDefNode *node) {
369 // Check if this name already exists
370
3/4
✓ Branch 2 → 3 taken 299 times.
✗ Branch 2 → 73 not taken.
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 297 times.
598 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 95 times.
✓ Branch 13 → 38 taken 202 times.
297 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
375
2/2
✓ Branch 36 → 16 taken 95 times.
✓ Branch 36 → 37 taken 95 times.
285 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
376
1/2
✓ Branch 18 → 19 taken 95 times.
✗ Branch 18 → 22 not taken.
95 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
377 95 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 297 times.
✗ Branch 38 → 73 not taken.
297 node->entry = rootScope->insert(node->aliasName, node);
385 // Register the name in the exported name registry
386
1/2
✓ Branch 41 → 42 taken 297 times.
✗ Branch 41 → 73 not taken.
297 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 297 times.
✗ Branch 42 → 73 not taken.
297 const std::string aliasedTypeContainerName = node->aliasName + ALIAS_CONTAINER_SUFFIX;
390
1/2
✓ Branch 43 → 44 taken 297 times.
✗ Branch 43 → 71 not taken.
297 node->aliasedTypeContainerEntry = rootScope->insert(aliasedTypeContainerName, node);
391
392
1/2
✓ Branch 46 → 47 taken 297 times.
✗ Branch 46 → 70 not taken.
594 return nullptr;
393 297 }
394
395 5309 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 5307 times.
10618 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 5307 times.
✗ Branch 13 → 56 not taken.
✓ Branch 14 → 15 taken 5307 times.
✗ Branch 14 → 56 not taken.
✓ Branch 15 → 16 taken 5307 times.
✗ Branch 15 → 56 not taken.
✓ Branch 29 → 17 taken 4138 times.
✓ Branch 29 → 30 taken 5305 times.
9443 for (const auto &dependency : sourceFile->dependencies | std::views::values)
402
3/4
✓ Branch 18 → 19 taken 4138 times.
✗ Branch 18 → 56 not taken.
✓ Branch 19 → 20 taken 2 times.
✓ Branch 19 → 27 taken 4136 times.
4138 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 5305 node->entry = rootScope->insert(node->varName, node);
407 // Register the name in the exported name registry
408 5305 sourceFile->addNameRegistryEntry(node->varName, TY_INVALID, node->entry, currentScope, true);
409
410
1/2
✓ Branch 34 → 35 taken 5305 times.
✗ Branch 34 → 57 not taken.
10610 return nullptr;
411 }
412
413 6754 std::any SymbolTableBuilder::visitExtDecl(ExtDeclNode *node) {
414 // Visit attributes
415
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 6 taken 6752 times.
6754 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 6752 times.
13508 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 6752 times.
✗ Branch 17 → 43 not taken.
✓ Branch 18 → 19 taken 6752 times.
✗ Branch 18 → 41 not taken.
6752 rootScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
424
425 // Add the external declaration to the symbol table
426 6752 node->entry = rootScope->insert(node->extFunctionName, node);
427 // Register the name in the exported name registry
428
2/2
✓ Branch 23 → 24 taken 5820 times.
✓ Branch 23 → 25 taken 932 times.
6752 const uint64_t typeId = node->returnType ? TY_FUNCTION : TY_PROCEDURE;
429 6752 sourceFile->addNameRegistryEntry(node->extFunctionName, typeId, node->entry, rootScope, /*keepNewOnCollision=*/true);
430
431
1/2
✓ Branch 27 → 28 taken 6752 times.
✗ Branch 27 → 44 not taken.
13504 return nullptr;
432 }
433
434 15638 std::any SymbolTableBuilder::visitUnsafeBlock(UnsafeBlockNode *node) {
435 // Create scope for the unsafe block body
436 15638 node->bodyScope = currentScope =
437
2/4
✓ Branch 2 → 3 taken 15638 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 15638 times.
✗ Branch 3 → 11 not taken.
15638 currentScope->createChildScope(node->getScopeId(), ScopeType::UNSAFE_BODY, &node->body->codeLoc);
438
439 // Visit body
440
1/2
✓ Branch 5 → 6 taken 15638 times.
✗ Branch 5 → 14 not taken.
15638 visit(node->body);
441
442 // Leave thread body scope
443 15638 currentScope = node->bodyScope->parent;
444
445
1/2
✓ Branch 7 → 8 taken 15638 times.
✗ Branch 7 → 15 not taken.
31276 return nullptr;
446 }
447
448 5704 std::any SymbolTableBuilder::visitForLoop(ForLoopNode *node) {
449 // Create scope for the loop body
450
2/4
✓ Branch 2 → 3 taken 5704 times.
✗ Branch 2 → 16 not taken.
✓ Branch 3 → 4 taken 5704 times.
✗ Branch 3 → 14 not taken.
5704 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 5704 times.
✗ Branch 5 → 17 not taken.
5704 visit(node->initDecl);
454
455 // Visit condition
456 5704 visitInExprScope(node->condAssign);
457
458 // Visit body
459
1/2
✓ Branch 8 → 9 taken 5704 times.
✗ Branch 8 → 18 not taken.
5704 visit(node->body);
460
461 // Leave for body scope
462 5704 currentScope = node->bodyScope->parent;
463
464
1/2
✓ Branch 10 → 11 taken 5704 times.
✗ Branch 10 → 19 not taken.
11408 return nullptr;
465 }
466
467 611 std::any SymbolTableBuilder::visitForeachLoop(ForeachLoopNode *node) {
468 // Create scope for the loop body
469 611 node->bodyScope = currentScope =
470
2/4
✓ Branch 2 → 3 taken 611 times.
✗ Branch 2 → 19 not taken.
✓ Branch 3 → 4 taken 611 times.
✗ Branch 3 → 17 not taken.
611 currentScope->createChildScope(node->getScopeId(), ScopeType::FOREACH_BODY, &node->body->codeLoc);
471
472 // Visit index variable declaration
473
2/2
✓ Branch 5 → 6 taken 30 times.
✓ Branch 5 → 9 taken 581 times.
611 if (node->idxVarDecl)
474
1/2
✓ Branch 6 → 7 taken 30 times.
✗ Branch 6 → 20 not taken.
30 visit(node->idxVarDecl);
475
476 // Visit item variable declaration
477
1/2
✓ Branch 9 → 10 taken 611 times.
✗ Branch 9 → 21 not taken.
611 visit(node->itemVarDecl);
478
479 // Visit body
480
1/2
✓ Branch 11 → 12 taken 611 times.
✗ Branch 11 → 22 not taken.
611 visit(node->body);
481
482 // Leave foreach body scope
483 611 currentScope = node->bodyScope->parent;
484
485
1/2
✓ Branch 13 → 14 taken 611 times.
✗ Branch 13 → 23 not taken.
1222 return nullptr;
486 }
487
488 2617 std::any SymbolTableBuilder::visitWhileLoop(WhileLoopNode *node) {
489 // Create scope for the loop body
490 2617 node->bodyScope = currentScope =
491
2/4
✓ Branch 2 → 3 taken 2617 times.
✗ Branch 2 → 14 not taken.
✓ Branch 3 → 4 taken 2617 times.
✗ Branch 3 → 12 not taken.
2617 currentScope->createChildScope(node->getScopeId(), ScopeType::WHILE_BODY, &node->body->codeLoc);
492
493 // Visit condition
494 2617 visitInExprScope(node->condition);
495
496 // Visit body
497
1/2
✓ Branch 6 → 7 taken 2617 times.
✗ Branch 6 → 15 not taken.
2617 visit(node->body);
498
499 // Leave while body scope
500 2617 currentScope = node->bodyScope->parent;
501
502
1/2
✓ Branch 8 → 9 taken 2617 times.
✗ Branch 8 → 16 not taken.
5234 return nullptr;
503 }
504
505 65 std::any SymbolTableBuilder::visitDoWhileLoop(DoWhileLoopNode *node) {
506 // Create scope for the loop body
507 65 node->bodyScope = currentScope =
508
2/4
✓ Branch 2 → 3 taken 65 times.
✗ Branch 2 → 14 not taken.
✓ Branch 3 → 4 taken 65 times.
✗ Branch 3 → 12 not taken.
65 currentScope->createChildScope(node->getScopeId(), ScopeType::WHILE_BODY, &node->body->codeLoc);
509
510 // Visit condition
511 65 visitInExprScope(node->condition);
512
513 // Visit body
514
1/2
✓ Branch 6 → 7 taken 65 times.
✗ Branch 6 → 15 not taken.
65 visit(node->body);
515
516 // Leave do-while body scope
517 65 currentScope = node->bodyScope->parent;
518
519
1/2
✓ Branch 8 → 9 taken 65 times.
✗ Branch 8 → 16 not taken.
130 return nullptr;
520 }
521
522 32849 std::any SymbolTableBuilder::visitIfStmt(IfStmtNode *node) {
523 // Create scope for the then body
524 32849 node->thenBodyScope = currentScope =
525
2/4
✓ Branch 2 → 3 taken 32849 times.
✗ Branch 2 → 26 not taken.
✓ Branch 3 → 4 taken 32849 times.
✗ Branch 3 → 24 not taken.
32849 currentScope->createChildScope(node->getScopeId(), ScopeType::IF_ELSE_BODY, &node->thenBody->codeLoc);
526
527 // Visit condition
528 32849 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 32849 times.
✗ Branch 7 → 11 not taken.
32849 if (node->doCompileThenBranch(manIdx))
532
1/2
✓ Branch 8 → 9 taken 32849 times.
✗ Branch 8 → 27 not taken.
32849 visit(node->thenBody);
533
534 // Leave then body scope
535 32849 currentScope = node->thenBodyScope->parent;
536
537 // Visit else stmt
538
5/6
✓ Branch 12 → 13 taken 32849 times.
✗ Branch 12 → 15 not taken.
✓ Branch 13 → 14 taken 2110 times.
✓ Branch 13 → 15 taken 30739 times.
✓ Branch 16 → 17 taken 2110 times.
✓ Branch 16 → 20 taken 30739 times.
32849 if (node->doCompileElseBranch(manIdx) && node->elseStmt)
539
1/2
✓ Branch 17 → 18 taken 2110 times.
✗ Branch 17 → 28 not taken.
2110 visit(node->elseStmt);
540
541
1/2
✓ Branch 20 → 21 taken 32849 times.
✗ Branch 20 → 29 not taken.
65698 return nullptr;
542 }
543
544 2110 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 883 times.
✓ Branch 2 → 8 taken 1227 times.
2110 if (node->isElseIf) {
547
1/2
✓ Branch 3 → 4 taken 883 times.
✗ Branch 3 → 17 not taken.
883 visit(node->ifStmt);
548
1/2
✓ Branch 5 → 6 taken 883 times.
✗ Branch 5 → 18 not taken.
1766 return nullptr;
549 }
550
551 // Create scope for the else body
552 1227 node->elseBodyScope = currentScope =
553
2/4
✓ Branch 8 → 9 taken 1227 times.
✗ Branch 8 → 21 not taken.
✓ Branch 9 → 10 taken 1227 times.
✗ Branch 9 → 19 not taken.
1227 currentScope->createChildScope(node->getScopeId(), ScopeType::IF_ELSE_BODY, &node->body->codeLoc);
554
555 // Visit else body
556
1/2
✓ Branch 11 → 12 taken 1227 times.
✗ Branch 11 → 22 not taken.
1227 visit(node->body);
557
558 // Leave else body scope
559 1227 currentScope = node->elseBodyScope->parent;
560
561
1/2
✓ Branch 13 → 14 taken 1227 times.
✗ Branch 13 → 23 not taken.
2454 return nullptr;
562 }
563
564 309 std::any SymbolTableBuilder::visitCaseBranch(CaseBranchNode *node) {
565 // Create scope for the case branch
566
2/4
✓ Branch 2 → 3 taken 309 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 309 times.
✗ Branch 3 → 11 not taken.
309 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 309 times.
✗ Branch 5 → 14 not taken.
309 visit(node->body);
570
571 // Leave case body scope
572 309 currentScope = node->bodyScope->parent;
573
574
1/2
✓ Branch 7 → 8 taken 309 times.
✗ Branch 7 → 15 not taken.
618 return nullptr;
575 }
576
577 29 std::any SymbolTableBuilder::visitDefaultBranch(DefaultBranchNode *node) {
578 // Create scope for the default branch
579 29 node->bodyScope = currentScope =
580
2/4
✓ Branch 2 → 3 taken 29 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 29 times.
✗ Branch 3 → 11 not taken.
29 currentScope->createChildScope(node->getScopeId(), ScopeType::DEFAULT_BODY, &node->body->codeLoc);
581
582 // Visit default body
583
1/2
✓ Branch 5 → 6 taken 29 times.
✗ Branch 5 → 14 not taken.
29 visit(node->body);
584
585 // Leave default body scope
586 29 currentScope = node->bodyScope->parent;
587
588
1/2
✓ Branch 7 → 8 taken 29 times.
✗ Branch 7 → 15 not taken.
58 return nullptr;
589 }
590
591 143 std::any SymbolTableBuilder::visitAnonymousBlockStmt(AnonymousBlockStmtNode *node) {
592 // Create scope for the anonymous block body
593 143 node->bodyScope = currentScope =
594
2/4
✓ Branch 2 → 3 taken 143 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 143 times.
✗ Branch 3 → 11 not taken.
143 currentScope->createChildScope(node->getScopeId(), ScopeType::ANONYMOUS_BLOCK_BODY, &node->body->codeLoc);
595
596 // Visit body
597
1/2
✓ Branch 5 → 6 taken 143 times.
✗ Branch 5 → 14 not taken.
143 visit(node->body);
598
599 // Leave anonymous block body scope
600 143 currentScope = node->bodyScope->parent;
601
602
1/2
✓ Branch 7 → 8 taken 143 times.
✗ Branch 7 → 15 not taken.
286 return nullptr;
603 }
604
605 3356 std::any SymbolTableBuilder::visitEnumItem(EnumItemNode *node) {
606 // Check if enum item already exists in the same scope.
607
3/4
✓ Branch 2 → 3 taken 3356 times.
✗ Branch 2 → 42 not taken.
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 3354 times.
6712 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 3354 times.
✗ Branch 13 → 42 not taken.
3354 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 3354 times.
3354 assert(node->enumDef != nullptr);
615
2/4
✓ Branch 18 → 19 taken 3354 times.
✗ Branch 18 → 38 not taken.
✓ Branch 19 → 20 taken 3354 times.
✗ Branch 19 → 36 not taken.
3354 const std::string name = node->enumDef->enumName + SCOPE_ACCESS_TOKEN + node->itemName;
616
1/2
✓ Branch 21 → 22 taken 3354 times.
✗ Branch 21 → 40 not taken.
3354 sourceFile->addNameRegistryEntry(name, TY_INT, enumItemEntry, currentScope, true);
617
618
1/2
✓ Branch 22 → 23 taken 3354 times.
✗ Branch 22 → 39 not taken.
6708 return nullptr;
619 3354 }
620
621 10206 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 10202 times.
20412 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 10202 currentScope->insert(node->fieldName, node);
628
629
1/2
✓ Branch 16 → 17 taken 10202 times.
✗ Branch 16 → 29 not taken.
20404 return nullptr;
630 }
631
632 948 std::any SymbolTableBuilder::visitSignature(SignatureNode *node) {
633 // Build signature qualifiers
634
2/2
✓ Branch 2 → 3 taken 904 times.
✓ Branch 2 → 32 taken 44 times.
948 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
635
2/2
✓ Branch 30 → 5 taken 904 times.
✓ Branch 30 → 31 taken 904 times.
2712 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
636
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 904 times.
904 if (qualifier->type == QualifierNode::QualifierType::TY_INLINE)
637 ✗ node->signatureQualifiers.isInline = true;
638
1/2
✓ Branch 9 → 10 taken 904 times.
✗ Branch 9 → 11 not taken.
904 else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
639 904 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 948 times.
✗ Branch 32 → 53 not taken.
1896 node->entry = currentScope->insert(Function::getSymbolTableEntryName(node->methodName, node->codeLoc), node);
650
651
1/2
✓ Branch 37 → 38 taken 948 times.
✗ Branch 37 → 54 not taken.
1896 return nullptr;
652 }
653
654 109031 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 109029 times.
218062 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 40760 times.
✓ Branch 13 → 17 taken 68269 times.
109029 if (node->hasAssignment)
661
1/2
✓ Branch 14 → 15 taken 40760 times.
✗ Branch 14 → 33 not taken.
40760 visit(node->assignExpr);
662
663 // Add variable entry to symbol table
664 109029 SymbolTableEntry *varEntry = currentScope->insert(node->varName, node);
665 109029 varEntry->isParam = node->isFctParam;
666
667
1/2
✓ Branch 20 → 21 taken 109029 times.
✗ Branch 20 → 34 not taken.
218058 return nullptr;
668 }
669
670 2023 std::any SymbolTableBuilder::visitModAttr(ModAttrNode *node) {
671 // Visit attributes
672
2/2
✓ Branch 2 → 3 taken 2021 times.
✓ Branch 2 → 140 taken 2 times.
2023 visitChildren(node);
673
674 // Retrieve attributes
675 2021 const AttrLstNode *attrs = node->attrLst;
676
677 // Collect and register linker flags.
678 // On Linux, platform-independent flags (core.linker.flag) are wrapped in --start-group/--end-group
679 // so the linker rescans the archive group until all circular symbol references are resolved (e.g.
680 // LLVM's core static archives have mutual dependencies that alphabetical ordering cannot satisfy).
681 2021 const llvm::Triple &targetTriple = sourceFile->targetMachine->getTargetTriple();
682 2021 const bool wrapInGroup = targetTriple.isOSLinux();
683 2649 auto addFlag = [&](const std::string &flag) {
684 628 resourceManager.linker.addLinkerFlag(flag);
685 628 sourceFile->sourceLinkerFlags.push_back(flag);
686 2649 };
687
688 // core.linker.flag — platform-independent; wrapped in a group on Linux
689
2/4
✓ Branch 9 → 10 taken 2021 times.
✗ Branch 9 → 143 not taken.
✓ Branch 10 → 11 taken 2021 times.
✗ Branch 10 → 141 not taken.
4042 const std::vector<const CompileTimeValue *> coreValues = attrs->getAttrValuesByName(ATTR_CORE_LINKER_FLAG);
690
6/6
✓ Branch 13 → 14 taken 1997 times.
✓ Branch 13 → 17 taken 24 times.
✓ Branch 15 → 16 taken 28 times.
✓ Branch 15 → 17 taken 1969 times.
✓ Branch 18 → 19 taken 28 times.
✓ Branch 18 → 26 taken 1993 times.
2021 if (wrapInGroup && !coreValues.empty())
691
2/4
✓ Branch 21 → 22 taken 28 times.
✗ Branch 21 → 149 not taken.
✓ Branch 22 → 23 taken 28 times.
✗ Branch 22 → 147 not taken.
56 addFlag("-Wl,--start-group");
692
2/2
✓ Branch 41 → 28 taken 536 times.
✓ Branch 41 → 42 taken 2021 times.
4578 for (const CompileTimeValue *value : coreValues)
693
2/4
✓ Branch 30 → 31 taken 536 times.
✗ Branch 30 → 153 not taken.
✓ Branch 31 → 32 taken 536 times.
✗ Branch 31 → 153 not taken.
536 addFlag(resourceManager.compileTimeStringValues.at(value->stringValueOffset));
694
6/6
✓ Branch 42 → 43 taken 1997 times.
✓ Branch 42 → 46 taken 24 times.
✓ Branch 44 → 45 taken 28 times.
✓ Branch 44 → 46 taken 1969 times.
✓ Branch 47 → 48 taken 28 times.
✓ Branch 47 → 55 taken 1993 times.
2021 if (wrapInGroup && !coreValues.empty())
695
2/4
✓ Branch 50 → 51 taken 28 times.
✗ Branch 50 → 156 not taken.
✓ Branch 51 → 52 taken 28 times.
✗ Branch 51 → 154 not taken.
56 addFlag("-Wl,--end-group");
696
697 // Platform-specific flags — always come after the (possibly grouped) core flags
698 2021 std::vector<const CompileTimeValue *> platformValues;
699
2/2
✓ Branch 56 → 57 taken 1997 times.
✓ Branch 56 → 66 taken 24 times.
2021 if (targetTriple.isOSLinux())
700
2/4
✓ Branch 59 → 60 taken 1997 times.
✗ Branch 59 → 162 not taken.
✓ Branch 60 → 61 taken 1997 times.
✗ Branch 60 → 160 not taken.
5991 platformValues = attrs->getAttrValuesByName(ATTR_CORE_LINUX_LINKER_FLAG);
701
3/4
✓ Branch 66 → 67 taken 24 times.
✗ Branch 66 → 206 not taken.
✓ Branch 67 → 68 taken 12 times.
✓ Branch 67 → 77 taken 12 times.
24 else if (targetTriple.isOSDarwin())
702
2/4
✓ Branch 70 → 71 taken 12 times.
✗ Branch 70 → 169 not taken.
✓ Branch 71 → 72 taken 12 times.
✗ Branch 71 → 167 not taken.
36 platformValues = attrs->getAttrValuesByName(ATTR_CORE_DARWIN_LINKER_FLAG);
703
1/2
✓ Branch 78 → 79 taken 12 times.
✗ Branch 78 → 88 not taken.
12 else if (targetTriple.isOSWindows())
704
2/4
✓ Branch 81 → 82 taken 12 times.
✗ Branch 81 → 176 not taken.
✓ Branch 82 → 83 taken 12 times.
✗ Branch 82 → 174 not taken.
36 platformValues = attrs->getAttrValuesByName(ATTR_CORE_WINDOWS_LINKER_FLAG);
705
2/2
✓ Branch 103 → 90 taken 36 times.
✓ Branch 103 → 104 taken 2021 times.
4078 for (const CompileTimeValue *value : platformValues)
706
2/4
✓ Branch 92 → 93 taken 36 times.
✗ Branch 92 → 181 not taken.
✓ Branch 93 → 94 taken 36 times.
✗ Branch 93 → 181 not taken.
36 addFlag(resourceManager.compileTimeStringValues.at(value->stringValueOffset));
707
708 // core.linker.additionalSource
709
4/6
✓ Branch 104 → 105 taken 2021 times.
✗ Branch 104 → 184 not taken.
✓ Branch 105 → 106 taken 2021 times.
✗ Branch 105 → 182 not taken.
✓ Branch 130 → 108 taken 6 times.
✓ Branch 130 → 131 taken 2019 times.
4046 for (const CompileTimeValue *value : attrs->getAttrValuesByName(ATTR_CORE_LINKER_ADDITIONAL_SOURCE)) {
710
1/2
✓ Branch 110 → 111 taken 6 times.
✗ Branch 110 → 197 not taken.
6 const std::string &stringValue = resourceManager.compileTimeStringValues.at(value->stringValueOffset);
711
3/6
✓ Branch 111 → 112 taken 6 times.
✗ Branch 111 → 191 not taken.
✓ Branch 112 → 113 taken 6 times.
✗ Branch 112 → 188 not taken.
✓ Branch 113 → 114 taken 6 times.
✗ Branch 113 → 186 not taken.
6 const std::filesystem::path additionalSourcePath = sourceFile->filePath.parent_path() / stringValue;
712
3/4
✓ Branch 116 → 117 taken 6 times.
✗ Branch 116 → 194 not taken.
✓ Branch 117 → 118 taken 4 times.
✓ Branch 117 → 192 taken 2 times.
8 resourceManager.linker.addAdditionalSourcePath(additionalSourcePath);
713
1/2
✓ Branch 119 → 120 taken 4 times.
✗ Branch 119 → 195 not taken.
4 sourceFile->sourceAdditionalSourcePaths.push_back(additionalSourcePath);
714 2029 }
715
716
1/2
✓ Branch 134 → 135 taken 2019 times.
✗ Branch 134 → 205 not taken.
4038 return nullptr;
717 2023 }
718
719 4765 std::any SymbolTableBuilder::visitAttr(AttrNode *node) {
720 // Check if this attribute exists
721
1/2
✓ Branch 2 → 3 taken 4765 times.
✗ Branch 2 → 63 not taken.
4765 const auto it = ATTR_CONFIGS.find(node->key);
722
2/2
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 4763 times.
4765 if (it == ATTR_CONFIGS.end())
723
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 + "'");
724
725 // Check if the target is correct
726 4763 const auto &[target, type] = it->second;
727
2/2
✓ Branch 14 → 15 taken 2 times.
✓ Branch 14 → 22 taken 4761 times.
4763 if ((node->target & target) == 0)
728
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");
729
730 // Check if a value is present
731
4/4
✓ Branch 22 → 23 taken 1330 times.
✓ Branch 22 → 31 taken 3431 times.
✓ Branch 23 → 24 taken 2 times.
✓ Branch 23 → 31 taken 1328 times.
4761 if (!node->value && type != AttrNode::AttrType::TYPE_BOOL)
732
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");
733
734
1/2
✓ Branch 31 → 32 taken 4759 times.
✗ Branch 31 → 62 not taken.
9518 return nullptr;
735 }
736
737 110 std::any SymbolTableBuilder::visitLambdaFunc(LambdaFuncNode *node) {
738 // Create scope for the lambda body
739 110 const CodeLoc &codeLoc = node->body->codeLoc;
740
2/4
✓ Branch 2 → 3 taken 110 times.
✗ Branch 2 → 47 not taken.
✓ Branch 3 → 4 taken 110 times.
✗ Branch 3 → 45 not taken.
110 node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::LAMBDA_BODY, &codeLoc);
741 // Requires capturing because the LLVM IR will end up in a separate function
742 110 currentScope->symbolTable.setCapturingRequired();
743 // Set to async scope if this is an async lambda
744
4/18
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 13 taken 110 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 110 times.
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 19 taken 110 times.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 27 taken 110 times.
✗ Branch 48 → 49 not taken.
✗ Branch 48 → 50 not taken.
✗ Branch 52 → 53 not taken.
✗ Branch 52 → 55 not taken.
110 if (node->lambdaAttr && node->lambdaAttr->attrLst->hasAttr(ATTR_ASYNC))
745 ✗ node->bodyScope->isAsyncScope = node->lambdaAttr->attrLst->getAttrValueByName(ATTR_ASYNC)->boolValue;
746
747 // Create symbol for 'result' variable
748
1/2
✓ Branch 29 → 30 taken 110 times.
✗ Branch 29 → 65 not taken.
330 currentScope->insert(RETURN_VARIABLE_NAME, node);
749
750 // Create symbols for the parameters
751
2/2
✓ Branch 35 → 36 taken 99 times.
✓ Branch 35 → 39 taken 11 times.
110 if (node->hasParams)
752
1/2
✓ Branch 36 → 37 taken 99 times.
✗ Branch 36 → 69 not taken.
99 visit(node->paramLst);
753
754 // Visit body
755
1/2
✓ Branch 39 → 40 taken 110 times.
✗ Branch 39 → 70 not taken.
110 visit(node->body);
756
757 // Leave anonymous block body scope
758 110 currentScope = node->bodyScope->parent;
759
760
1/2
✓ Branch 41 → 42 taken 110 times.
✗ Branch 41 → 71 not taken.
220 return nullptr;
761 }
762
763 74 std::any SymbolTableBuilder::visitLambdaProc(LambdaProcNode *node) {
764 // Create scope for the lambda body
765 74 const CodeLoc &codeLoc = node->body->codeLoc;
766
2/4
✓ Branch 2 → 3 taken 74 times.
✗ Branch 2 → 39 not taken.
✓ Branch 3 → 4 taken 74 times.
✗ Branch 3 → 37 not taken.
74 node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::LAMBDA_BODY, &codeLoc);
767 // Requires capturing because the LLVM IR will end up in a separate function
768 74 currentScope->symbolTable.setCapturingRequired();
769 // Set to async scope if this is an async lambda
770
11/18
✓ Branch 6 → 7 taken 16 times.
✓ Branch 6 → 13 taken 58 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 58 times.
✓ Branch 16 → 17 taken 16 times.
✓ Branch 16 → 19 taken 58 times.
✓ Branch 19 → 20 taken 16 times.
✓ Branch 19 → 27 taken 58 times.
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 42 not taken.
✗ Branch 44 → 45 not taken.
✗ Branch 44 → 47 not taken.
106 if (node->lambdaAttr && node->lambdaAttr->attrLst->hasAttr(ATTR_ASYNC))
771
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;
772
773 // Create symbols for the parameters
774
2/2
✓ Branch 27 → 28 taken 46 times.
✓ Branch 27 → 31 taken 28 times.
74 if (node->hasParams)
775
1/2
✓ Branch 28 → 29 taken 46 times.
✗ Branch 28 → 55 not taken.
46 visit(node->paramLst);
776
777 // Visit body
778
1/2
✓ Branch 31 → 32 taken 74 times.
✗ Branch 31 → 56 not taken.
74 visit(node->body);
779
780 // Leave anonymous block body scope
781 74 currentScope = node->bodyScope->parent;
782
783
1/2
✓ Branch 33 → 34 taken 74 times.
✗ Branch 33 → 57 not taken.
148 return nullptr;
784 }
785
786 2 std::any SymbolTableBuilder::visitLambdaExpr(LambdaExprNode *node) {
787 // Create scope for the anonymous block body
788 2 const CodeLoc &codeLoc = node->lambdaExpr->codeLoc;
789
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);
790 // Requires capturing because the LLVM IR will end up in a separate function
791 2 currentScope->symbolTable.setCapturingRequired();
792
793 // Create symbols for the parameters
794
1/2
✓ Branch 6 → 7 taken 2 times.
✗ Branch 6 → 10 not taken.
2 if (node->hasParams)
795
1/2
✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 19 not taken.
2 visit(node->paramLst);
796
797 // Visit lambda expression
798
1/2
✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 20 not taken.
2 visit(node->lambdaExpr);
799
800 // Leave anonymous block body scope
801 2 currentScope = node->bodyScope->parent;
802
803
1/2
✓ Branch 12 → 13 taken 2 times.
✗ Branch 12 → 21 not taken.
4 return nullptr;
804 }
805
806 3451 std::any SymbolTableBuilder::visitTernaryExpr(TernaryExprNode *node) {
807 // Visit condition, which is evaluated unconditionally
808
1/2
✓ Branch 2 → 3 taken 3451 times.
✗ Branch 2 → 13 not taken.
3451 visit(node->condition);
809
810 // Visit the branches. Only one of them is evaluated, so each one gets its own scope for its temporaries.
811 // The true branch does not exist for shortened ternaries, as the condition takes its place.
812
3/4
✓ Branch 4 → 5 taken 3449 times.
✓ Branch 4 → 7 taken 2 times.
✓ Branch 5 → 6 taken 3449 times.
✗ Branch 5 → 7 not taken.
3451 if (node->trueExpr && !node->isShortened)
813 3449 visitInExprScope(node->trueExpr);
814
1/2
✓ Branch 7 → 8 taken 3451 times.
✗ Branch 7 → 9 not taken.
3451 if (node->falseExpr)
815 3451 visitInExprScope(node->falseExpr);
816
817
1/2
✓ Branch 9 → 10 taken 3451 times.
✗ Branch 9 → 14 not taken.
6902 return nullptr;
818 }
819
820 5323 std::any SymbolTableBuilder::visitLogicalOrExpr(LogicalOrExprNode *node) {
821 // Visit the first operand, which is evaluated unconditionally
822
1/2
✓ Branch 3 → 4 taken 5323 times.
✗ Branch 3 → 15 not taken.
5323 visit(node->operands.front());
823
824 // All further operands are only evaluated if the ones before did not short-circuit
825
2/2
✓ Branch 10 → 6 taken 6727 times.
✓ Branch 10 → 11 taken 5323 times.
12050 for (size_t i = 1; i < node->operands.size(); i++)
826 6727 visitInExprScope(node->operands[i]);
827
828
1/2
✓ Branch 11 → 12 taken 5323 times.
✗ Branch 11 → 16 not taken.
10646 return nullptr;
829 }
830
831 2841 std::any SymbolTableBuilder::visitLogicalAndExpr(LogicalAndExprNode *node) {
832 // Visit the first operand, which is evaluated unconditionally
833
1/2
✓ Branch 3 → 4 taken 2841 times.
✗ Branch 3 → 15 not taken.
2841 visit(node->operands.front());
834
835 // All further operands are only evaluated if the ones before did not short-circuit
836
2/2
✓ Branch 10 → 6 taken 3135 times.
✓ Branch 10 → 11 taken 2841 times.
5976 for (size_t i = 1; i < node->operands.size(); i++)
837 3135 visitInExprScope(node->operands[i]);
838
839
1/2
✓ Branch 11 → 12 taken 2841 times.
✗ Branch 11 → 16 not taken.
5682 return nullptr;
840 }
841
842 /**
843 * Visit an expression in a scope of its own. That scope holds the temporaries of the expression, which allows destructing them
844 * right after the expression was evaluated. This is required for conditions and for operands that are only evaluated
845 * conditionally, since a temporary of those must not be destructed if it never was constructed.
846 *
847 * @param expr Expression to visit
848 */
849 57997 void SymbolTableBuilder::visitInExprScope(ExprNode *expr) {
850 // Create scope for the expression
851
2/4
✓ Branch 2 → 3 taken 57997 times.
✗ Branch 2 → 10 not taken.
✓ Branch 3 → 4 taken 57997 times.
✗ Branch 3 → 8 not taken.
57997 currentScope = currentScope->createChildScope(expr->getExprScopeId(), ScopeType::EXPR_BODY, &expr->codeLoc);
852
853 // Visit the expression
854
1/2
✓ Branch 5 → 6 taken 57997 times.
✗ Branch 5 → 11 not taken.
57997 visit(expr);
855
856 // Leave expression scope
857 57997 currentScope = currentScope->parent;
858 57997 }
859
860 } // namespace spice::compiler
861