GCC Code Coverage Report


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

src/symboltablebuilder/SymbolTableBuilder.cpp
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 #include "SymbolTableBuilder.h"
4
5 #include <SourceFile.h>
6 #include <ast/ASTBuilder.h>
7 #include <ast/Attributes.h>
8 #include <driver/Driver.h>
9 #include <exception/SemanticError.h>
10 #include <global/GlobalResourceManager.h>
11 #include <model/Function.h>
12 #include <symboltablebuilder/Scope.h>
13
14 namespace spice::compiler {
15
16 6301 SymbolTableBuilder::SymbolTableBuilder(GlobalResourceManager &resourceManager, SourceFile *sourceFile)
17 6301 : CompilerPass(resourceManager, sourceFile), rootScope(sourceFile->globalScope.get()) {}
18
19 6301 std::any SymbolTableBuilder::visitEntry(EntryNode *node) {
20 // Initialize
21 6301 currentScope = rootScope;
22
23 // Visit children
24
2/2
✓ Branch 2 → 3 taken 6263 times.
✓ Branch 2 → 23 taken 38 times.
6301 visitChildren(node);
25
26 // Check if the main function exists
27
4/4
✓ Branch 4 → 5 taken 6257 times.
✓ Branch 4 → 7 taken 6 times.
✓ Branch 5 → 6 taken 6245 times.
✓ Branch 5 → 7 taken 12 times.
6263 const bool mainFctRequired = cliOptions.outputContainer == OutputContainer::EXECUTABLE && !cliOptions.noEntryFct;
28
6/6
✓ Branch 8 → 9 taken 1260 times.
✓ Branch 8 → 19 taken 5003 times.
✓ Branch 9 → 10 taken 1244 times.
✓ Branch 9 → 19 taken 16 times.
✓ Branch 10 → 11 taken 4 times.
✓ Branch 10 → 19 taken 1240 times.
6263 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 6259 times.
✗ Branch 19 → 33 not taken.
12518 return nullptr;
32 }
33
34 1252 std::any SymbolTableBuilder::visitMainFctDef(MainFctDefNode *node) {
35 // Visit attributes
36
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 6 taken 1250 times.
1252 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 1250 times.
✗ Branch 8 → 55 not taken.
✓ Branch 14 → 15 taken 2 times.
✓ Branch 14 → 23 taken 1248 times.
5000 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 1248 times.
✗ Branch 25 → 70 not taken.
3744 SymbolTableEntry *mainFctEntry = currentScope->insert(MAIN_FUNCTION_NAME, node);
45 1248 mainFctEntry->used = true;
46
47 // Create scope for main function body
48
1/2
✓ Branch 31 → 32 taken 1248 times.
✗ Branch 31 → 85 not taken.
1248 const std::string &scopeId = MainFctDefNode::getScopeId();
49
1/2
✓ Branch 32 → 33 taken 1248 times.
✗ Branch 32 → 83 not taken.
1248 node->bodyScope = currentScope = rootScope->createChildScope(scopeId, ScopeType::FUNC_PROC_BODY, &node->codeLoc);
50 1248 currentScope->isGenericScope = false;
51
52 // Declare variable for the return value in the function scope
53
1/2
✓ Branch 35 → 36 taken 1248 times.
✗ Branch 35 → 76 not taken.
3744 SymbolTableEntry *resultVarEntry = node->bodyScope->insert(RETURN_VARIABLE_NAME, node);
54 1248 resultVarEntry->used = true;
55
56 // Visit arguments in new scope
57
2/2
✓ Branch 41 → 42 taken 14 times.
✓ Branch 41 → 45 taken 1234 times.
1248 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 1246 times.
✓ Branch 45 → 81 taken 2 times.
1248 visit(node->body);
62
63 // Return to root scope
64 1246 currentScope = rootScope;
65
66 1246 hasMainFunction = true;
67
1/2
✓ Branch 47 → 48 taken 1246 times.
✗ Branch 47 → 82 not taken.
2492 return nullptr;
68 1248 }
69
70 50286 std::any SymbolTableBuilder::visitFctDef(FctDefNode *node) {
71 // Visit attributes
72
2/2
✓ Branch 2 → 3 taken 1660 times.
✓ Branch 2 → 6 taken 48626 times.
50286 if (node->attrs)
73
1/2
✓ Branch 3 → 4 taken 1660 times.
✗ Branch 3 → 98 not taken.
1660 visit(node->attrs);
74
75 // Build function qualifiers
76
2/2
✓ Branch 6 → 7 taken 47977 times.
✓ Branch 6 → 36 taken 2309 times.
50286 if (const QualifierLstNode *qualifierLst = node->qualifierLst; qualifierLst) {
77
2/2
✓ Branch 34 → 9 taken 64024 times.
✓ Branch 34 → 35 taken 47977 times.
159978 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
78
2/2
✓ Branch 11 → 12 taken 16075 times.
✓ Branch 11 → 13 taken 47949 times.
64024 if (qualifier->type == QualifierNode::QualifierType::TY_INLINE)
79 16075 node->qualifiers.isInline = true;
80
2/2
✓ Branch 13 → 14 taken 47683 times.
✓ Branch 13 → 15 taken 266 times.
47949 else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
81 47683 node->qualifiers.isPublic = true;
82
1/2
✓ Branch 15 → 16 taken 266 times.
✗ Branch 15 → 17 not taken.
266 else if (qualifier->type == QualifierNode::QualifierType::TY_CONST)
83 266 node->qualifiers.isConst = true;
84 else
85 throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on a function definition");
86 }
87 }
88
89 // Change to struct scope if this function is a method
90
2/2
✓ Branch 36 → 37 taken 25637 times.
✓ Branch 36 → 51 taken 24649 times.
50286 if (node->isMethod) {
91
1/2
✓ Branch 38 → 39 taken 25637 times.
✗ Branch 38 → 109 not taken.
25637 const std::string scopeName = Struct::getScopeName(node->name->structName);
92
1/2
✓ Branch 40 → 41 taken 25637 times.
✗ Branch 40 → 121 not taken.
25637 node->structScope = currentScope = currentScope->getChildScope(scopeName);
93
1/2
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 49 taken 25637 times.
25637 if (!currentScope)
94 throw SemanticError(node, REFERENCED_UNDEFINED_STRUCT, "Struct '" + node->name->structName + "' could not be found");
95 25637 }
96
97 // Create scope for the function
98
2/4
✓ Branch 51 → 52 taken 50286 times.
✗ Branch 51 → 126 not taken.
✓ Branch 52 → 53 taken 50286 times.
✗ Branch 52 → 124 not taken.
50286 node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
99
6/6
✓ Branch 54 → 55 taken 45168 times.
✓ Branch 54 → 57 taken 5118 times.
✓ Branch 55 → 56 taken 24932 times.
✓ Branch 55 → 58 taken 20236 times.
✓ Branch 56 → 57 taken 6763 times.
✓ Branch 56 → 58 taken 18169 times.
50286 currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope);
100
101 // Create symbol for 'this' variable
102
2/2
✓ Branch 59 → 60 taken 25637 times.
✓ Branch 59 → 69 taken 24649 times.
50286 if (node->isMethod)
103
1/2
✓ Branch 62 → 63 taken 25637 times.
✗ Branch 62 → 129 not taken.
102548 currentScope->insert(THIS_VARIABLE_NAME, node);
104
105 // Create symbol for 'result' variable
106
1/2
✓ Branch 71 → 72 taken 50286 times.
✗ Branch 71 → 135 not taken.
150858 currentScope->insert(RETURN_VARIABLE_NAME, node);
107
108 // Create symbols for the parameters
109
2/2
✓ Branch 77 → 78 taken 36448 times.
✓ Branch 77 → 81 taken 13838 times.
50286 if (node->hasParams)
110
1/2
✓ Branch 78 → 79 taken 36448 times.
✗ Branch 78 → 139 not taken.
36448 visit(node->paramLst);
111
112 // Visit the function body
113
1/2
✓ Branch 81 → 82 taken 50286 times.
✗ Branch 81 → 140 not taken.
50286 visit(node->body);
114
115 // Leave function body scope
116 50286 currentScope = node->scope->parent;
117
118 // Insert symbol for function into the symbol table
119
1/2
✓ Branch 83 → 84 taken 50286 times.
✗ Branch 83 → 143 not taken.
100572 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 50286 const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName);
124
3/4
✓ Branch 89 → 90 taken 10473 times.
✓ Branch 89 → 91 taken 39813 times.
✓ Branch 90 → 91 taken 10473 times.
✗ Branch 90 → 92 not taken.
50286 if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry)
125 50286 sourceFile->addNameRegistryEntry(node->name->fqName, TY_FUNCTION, node->entry, currentScope, true);
126
127 // Leave the struct scope
128
2/2
✓ Branch 92 → 93 taken 25637 times.
✓ Branch 92 → 94 taken 24649 times.
50286 if (node->isMethod)
129 25637 currentScope = node->structScope->parent;
130
131
1/2
✓ Branch 94 → 95 taken 50286 times.
✗ Branch 94 → 144 not taken.
100572 return nullptr;
132 }
133
134 30276 std::any SymbolTableBuilder::visitProcDef(ProcDefNode *node) {
135 // Visit attributes
136
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 6 taken 30274 times.
30276 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 25465 times.
✓ Branch 6 → 36 taken 4809 times.
30274 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
141
2/2
✓ Branch 34 → 9 taken 29456 times.
✓ Branch 34 → 35 taken 25465 times.
80386 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
142
2/2
✓ Branch 11 → 12 taken 4001 times.
✓ Branch 11 → 13 taken 25455 times.
29456 if (qualifier->type == QualifierNode::QualifierType::TY_INLINE)
143 4001 node->qualifiers.isInline = true;
144
2/2
✓ Branch 13 → 14 taken 25447 times.
✓ Branch 13 → 15 taken 8 times.
25455 else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
145 25447 node->qualifiers.isPublic = true;
146
1/2
✓ Branch 15 → 16 taken 8 times.
✗ Branch 15 → 17 not taken.
8 else if (qualifier->type == QualifierNode::QualifierType::TY_CONST)
147 8 node->qualifiers.isConst = true;
148 else
149 throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on a procedure definition");
150 }
151 }
152
153 // Change to struct scope if this procedure is a method
154
2/2
✓ Branch 36 → 37 taken 24686 times.
✓ Branch 36 → 51 taken 5588 times.
30274 if (node->isMethod) {
155
1/2
✓ Branch 38 → 39 taken 24686 times.
✗ Branch 38 → 108 not taken.
24686 const std::string &scopeName = Struct::getScopeName(node->name->structName);
156
1/2
✓ Branch 40 → 41 taken 24686 times.
✗ Branch 40 → 120 not taken.
24686 node->structScope = currentScope = currentScope->getChildScope(scopeName);
157
2/2
✓ Branch 41 → 42 taken 2 times.
✓ Branch 41 → 49 taken 24684 times.
24686 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 24686 }
160
161 // Create scope for the procedure
162
2/4
✓ Branch 51 → 52 taken 30272 times.
✗ Branch 51 → 125 not taken.
✓ Branch 52 → 53 taken 30272 times.
✗ Branch 52 → 123 not taken.
30272 node->scope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
163
6/6
✓ Branch 54 → 55 taken 24996 times.
✓ Branch 54 → 57 taken 5276 times.
✓ Branch 55 → 56 taken 21905 times.
✓ Branch 55 → 58 taken 3091 times.
✓ Branch 56 → 57 taken 5992 times.
✓ Branch 56 → 58 taken 15913 times.
30272 currentScope->isGenericScope = node->hasTemplateTypes || (node->structScope && node->structScope->isGenericScope);
164
4/4
✓ Branch 59 → 60 taken 24684 times.
✓ Branch 59 → 63 taken 5588 times.
✓ Branch 61 → 62 taken 1026 times.
✓ Branch 61 → 63 taken 23658 times.
30272 currentScope->isDtorScope = node->isMethod && node->name->name == DTOR_FUNCTION_NAME;
165
166 // Create symbol for 'this' variable
167
2/2
✓ Branch 64 → 65 taken 24684 times.
✓ Branch 64 → 74 taken 5588 times.
30272 if (node->isMethod)
168
1/2
✓ Branch 67 → 68 taken 24684 times.
✗ Branch 67 → 128 not taken.
98736 currentScope->insert(THIS_VARIABLE_NAME, node);
169
170 // Create symbols for the parameters
171
2/2
✓ Branch 74 → 75 taken 22395 times.
✓ Branch 74 → 78 taken 7877 times.
30272 if (node->hasParams)
172
1/2
✓ Branch 75 → 76 taken 22395 times.
✗ Branch 75 → 132 not taken.
22395 visit(node->paramLst);
173
174 // Visit the procedure body
175
1/2
✓ Branch 78 → 79 taken 30272 times.
✗ Branch 78 → 133 not taken.
30272 visit(node->body);
176
177 // Leave procedure body scope
178 30272 currentScope = node->scope->parent;
179
180 // Insert symbol for procedure into the symbol table
181
1/2
✓ Branch 80 → 81 taken 30272 times.
✗ Branch 80 → 136 not taken.
60544 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 30272 const NameRegistryEntry *existingRegistryEntry = sourceFile->getNameRegistryEntry(node->name->fqName);
186
3/4
✓ Branch 86 → 87 taken 6270 times.
✓ Branch 86 → 88 taken 24002 times.
✓ Branch 87 → 88 taken 6270 times.
✗ Branch 87 → 89 not taken.
30272 if (!existingRegistryEntry || existingRegistryEntry->targetEntry != node->entry)
187 30272 sourceFile->addNameRegistryEntry(node->name->fqName, TY_PROCEDURE, node->entry, currentScope, true);
188
189 // Leave the struct scope
190
2/2
✓ Branch 89 → 90 taken 24684 times.
✓ Branch 89 → 91 taken 5588 times.
30272 if (node->isMethod)
191 24684 currentScope = node->structScope->parent;
192
193 // Check if this is a constructor
194 30272 node->isCtor = node->name->nameFragments.back() == CTOR_FUNCTION_NAME;
195
196
1/2
✓ Branch 93 → 94 taken 30272 times.
✗ Branch 93 → 137 not taken.
60544 return nullptr;
197 }
198
199 7653 std::any SymbolTableBuilder::visitStructDef(StructDefNode *node) {
200 // Visit attributes
201
2/2
✓ Branch 2 → 3 taken 256 times.
✓ Branch 2 → 6 taken 7397 times.
7653 if (node->attrs)
202
1/2
✓ Branch 3 → 4 taken 256 times.
✗ Branch 3 → 79 not taken.
256 visit(node->attrs);
203
204 // Check if this name already exists
205
3/4
✓ Branch 6 → 7 taken 7653 times.
✗ Branch 6 → 110 not taken.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 17 taken 7651 times.
15306 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 7651 times.
✗ Branch 18 → 89 not taken.
7651 const std::string &scopeName = Struct::getScopeName(node->structName);
210
1/2
✓ Branch 20 → 21 taken 7651 times.
✗ Branch 20 → 108 not taken.
7651 node->structScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::STRUCT, &node->codeLoc);
211 7651 currentScope->isGenericScope = node->hasTemplateTypes;
212
213 // Insert implicit field for each interface type
214
2/2
✓ Branch 21 → 22 taken 774 times.
✓ Branch 21 → 43 taken 6877 times.
7651 if (node->hasInterfaces) {
215
2/2
✓ Branch 41 → 24 taken 774 times.
✓ Branch 41 → 42 taken 774 times.
2322 for (DataTypeNode *interfaceNode : node->interfaceTypeLst->dataTypes) {
216 774 const std::string &interfaceName = interfaceNode->baseDataType->customDataType->typeNameFragments.back();
217
1/2
✓ Branch 27 → 28 taken 774 times.
✗ Branch 27 → 94 not taken.
1548 SymbolTableEntry *interfaceFieldEntry = currentScope->insert("this." + interfaceName, interfaceNode);
218 774 interfaceFieldEntry->used = true;
219 774 interfaceFieldEntry->isImplicitField = true;
220 }
221 }
222
223 // Visit children
224
2/2
✓ Branch 43 → 44 taken 7649 times.
✓ Branch 43 → 96 taken 2 times.
7651 visitChildren(node);
225
226 // Leave the struct scope
227 7649 currentScope = node->structScope->parent;
228
229 // Build struct qualifiers
230
2/2
✓ Branch 45 → 46 taken 6069 times.
✓ Branch 45 → 70 taken 1580 times.
7649 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
231
2/2
✓ Branch 68 → 48 taken 6069 times.
✓ Branch 68 → 69 taken 6069 times.
18207 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
232
1/2
✓ Branch 50 → 51 taken 6069 times.
✗ Branch 50 → 54 not taken.
6069 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
233 6069 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 7649 times.
✗ Branch 70 → 108 not taken.
7649 node->entry = rootScope->insert(node->structName, node);
241 // Register the name in the exported name registry
242
1/2
✓ Branch 73 → 74 taken 7649 times.
✗ Branch 73 → 108 not taken.
7649 sourceFile->addNameRegistryEntry(node->structName, node->typeId, node->entry, node->structScope, true);
243
244
1/2
✓ Branch 74 → 75 taken 7649 times.
✗ Branch 74 → 107 not taken.
15298 return nullptr;
245 7651 }
246
247 821 std::any SymbolTableBuilder::visitInterfaceDef(InterfaceDefNode *node) {
248 // Visit attributes
249
2/2
✓ Branch 2 → 3 taken 386 times.
✓ Branch 2 → 6 taken 435 times.
821 if (node->attrs)
250
1/2
✓ Branch 3 → 4 taken 386 times.
✗ Branch 3 → 71 not taken.
386 visit(node->attrs);
251
252 // Check if this name already exists
253
3/4
✓ Branch 6 → 7 taken 821 times.
✗ Branch 6 → 99 not taken.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 17 taken 819 times.
1642 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 819 times.
✗ Branch 18 → 81 not taken.
819 const std::string &scopeName = Interface::getScopeName(node->interfaceName);
258
1/2
✓ Branch 20 → 21 taken 819 times.
✗ Branch 20 → 97 not taken.
819 node->interfaceScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::INTERFACE, &node->codeLoc);
259
260 // Visit signatures
261
2/2
✓ Branch 36 → 23 taken 4907 times.
✓ Branch 36 → 37 taken 819 times.
6545 for (SignatureNode *signature : node->signatures)
262
1/2
✓ Branch 25 → 26 taken 4907 times.
✗ Branch 25 → 84 not taken.
4907 visit(signature);
263
264 // Leave the interface scope
265 819 currentScope = node->interfaceScope->parent;
266
267 // Build interface qualifiers
268
2/2
✓ Branch 37 → 38 taken 779 times.
✓ Branch 37 → 62 taken 40 times.
819 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
269
2/2
✓ Branch 60 → 40 taken 779 times.
✓ Branch 60 → 61 taken 779 times.
2337 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
270
1/2
✓ Branch 42 → 43 taken 779 times.
✗ Branch 42 → 46 not taken.
779 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
271 779 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 819 times.
✗ Branch 62 → 97 not taken.
819 node->entry = rootScope->insert(node->interfaceName, node);
279 // Register the name in the exported name registry
280
1/2
✓ Branch 65 → 66 taken 819 times.
✗ Branch 65 → 97 not taken.
819 sourceFile->addNameRegistryEntry(node->interfaceName, node->typeId, node->entry, node->interfaceScope, true);
281
282
1/2
✓ Branch 66 → 67 taken 819 times.
✗ Branch 66 → 96 not taken.
1638 return nullptr;
283 819 }
284
285 68 std::any SymbolTableBuilder::visitUnionDef(UnionDefNode *node) {
286 // Visit attributes
287
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 6 taken 68 times.
68 if (node->attrs)
288 visit(node->attrs);
289
290 // Check if this name already exists
291
2/4
✓ Branch 6 → 7 taken 68 times.
✗ Branch 6 → 84 not taken.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 17 taken 68 times.
136 if (rootScope->lookupStrict(node->unionName))
292 throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->unionName + "'");
293
294 // Create scope for the union
295
1/2
✓ Branch 18 → 19 taken 68 times.
✗ Branch 18 → 67 not taken.
68 const std::string &scopeName = Union::getScopeName(node->unionName);
296
1/2
✓ Branch 20 → 21 taken 68 times.
✗ Branch 20 → 82 not taken.
68 node->unionScope = currentScope = rootScope->createChildScope(scopeName, ScopeType::UNION, &node->codeLoc);
297 68 currentScope->isGenericScope = node->hasTemplateTypes;
298
299 // Visit children
300
2/2
✓ Branch 21 → 22 taken 66 times.
✓ Branch 21 → 70 taken 2 times.
68 visitChildren(node);
301
302 // Leave the union scope
303 66 currentScope = node->unionScope->parent;
304
305 // Build union qualifiers
306
2/2
✓ Branch 23 → 24 taken 32 times.
✓ Branch 23 → 48 taken 34 times.
66 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
307
2/2
✓ Branch 46 → 26 taken 32 times.
✓ Branch 46 → 47 taken 30 times.
94 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
308
2/2
✓ Branch 28 → 29 taken 30 times.
✓ Branch 28 → 32 taken 2 times.
32 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
309 30 node->qualifiers.isPublic = true;
310 else
311
2/4
✓ Branch 35 → 36 taken 2 times.
✗ Branch 35 → 74 not taken.
✓ Branch 36 → 37 taken 2 times.
✗ Branch 36 → 71 not taken.
6 throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on a union definition");
312 }
313 }
314
315 // Add the union to the symbol table
316
1/2
✓ Branch 48 → 49 taken 64 times.
✗ Branch 48 → 82 not taken.
64 node->entry = rootScope->insert(node->unionName, node);
317 // Register the name in the exported name registry
318
1/2
✓ Branch 51 → 52 taken 64 times.
✗ Branch 51 → 82 not taken.
64 sourceFile->addNameRegistryEntry(node->unionName, node->typeId, node->entry, node->unionScope, true);
319
320
1/2
✓ Branch 52 → 53 taken 64 times.
✗ Branch 52 → 81 not taken.
128 return nullptr;
321 68 }
322
323 1250 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 1248 times.
2500 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 1248 node->enumScope = currentScope =
330
2/4
✓ Branch 13 → 14 taken 1248 times.
✗ Branch 13 → 62 not taken.
✓ Branch 14 → 15 taken 1248 times.
✗ Branch 14 → 60 not taken.
1248 rootScope->createChildScope(ENUM_SCOPE_PREFIX + node->enumName, ScopeType::ENUM, &node->codeLoc);
331
332 // Visit items
333
2/2
✓ Branch 16 → 17 taken 1246 times.
✓ Branch 16 → 63 taken 2 times.
1248 visit(node->itemLst);
334
335 // Leave the enum scope
336 1246 currentScope = node->enumScope->parent;
337
338 // Build enum qualifiers
339
2/2
✓ Branch 18 → 19 taken 1167 times.
✓ Branch 18 → 43 taken 79 times.
1246 if (node->qualifierLst) {
340
2/2
✓ Branch 41 → 21 taken 1167 times.
✓ Branch 41 → 42 taken 1167 times.
3501 for (const QualifierNode *qualifier : node->qualifierLst->qualifiers) {
341
1/2
✓ Branch 23 → 24 taken 1167 times.
✗ Branch 23 → 27 not taken.
1167 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
342 1167 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 1246 node->entry = rootScope->insert(node->enumName, node);
350 // Register the name in the exported name registry
351 1246 sourceFile->addNameRegistryEntry(node->enumName, node->typeId, node->entry, node->enumScope, true);
352
353
1/2
✓ Branch 47 → 48 taken 1246 times.
✗ Branch 47 → 74 not taken.
2492 return nullptr;
354 }
355
356 4681 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 4679 times.
9362 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 4679 node->entry = rootScope->insert(node->typeName, node);
363 4679 node->entry->used = true; // Generic types are always used
364
365
1/2
✓ Branch 16 → 17 taken 4679 times.
✗ Branch 16 → 29 not taken.
9358 return nullptr;
366 }
367
368 711 std::any SymbolTableBuilder::visitAliasDef(AliasDefNode *node) {
369 // Check if this name already exists
370
3/4
✓ Branch 2 → 3 taken 711 times.
✗ Branch 2 → 73 not taken.
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 709 times.
1422 if (rootScope->lookupStrict(node->aliasName))
371
3/6
✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 56 not taken.
✓ Branch 8 → 9 taken 2 times.
✗ Branch 8 → 54 not taken.
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 51 not taken.
2 throw SemanticError(node, DUPLICATE_SYMBOL, "Duplicate symbol '" + node->aliasName + "'");
372
373 // Build alias qualifiers
374
2/2
✓ Branch 13 → 14 taken 223 times.
✓ Branch 13 → 38 taken 486 times.
709 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
375
2/2
✓ Branch 36 → 16 taken 223 times.
✓ Branch 36 → 37 taken 223 times.
669 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
376
1/2
✓ Branch 18 → 19 taken 223 times.
✗ Branch 18 → 22 not taken.
223 if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
377 223 node->qualifiers.isPublic = true;
378 else
379 throw SemanticError(qualifier, QUALIFIER_AT_ILLEGAL_CONTEXT, "Cannot use this qualifier on an alias definition");
380 }
381 }
382
383 // Add the alias to the symbol table
384
1/2
✓ Branch 38 → 39 taken 709 times.
✗ Branch 38 → 73 not taken.
709 node->entry = rootScope->insert(node->aliasName, node);
385 // Register the name in the exported name registry
386
1/2
✓ Branch 41 → 42 taken 709 times.
✗ Branch 41 → 73 not taken.
709 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 709 times.
✗ Branch 42 → 73 not taken.
709 const std::string aliasedTypeContainerName = node->aliasName + ALIAS_CONTAINER_SUFFIX;
390
1/2
✓ Branch 43 → 44 taken 709 times.
✗ Branch 43 → 71 not taken.
709 node->aliasedTypeContainerEntry = rootScope->insert(aliasedTypeContainerName, node);
391
392
1/2
✓ Branch 46 → 47 taken 709 times.
✗ Branch 46 → 70 not taken.
1418 return nullptr;
393 709 }
394
395 6315 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 6313 times.
12630 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 6313 times.
✗ Branch 13 → 56 not taken.
✓ Branch 14 → 15 taken 6313 times.
✗ Branch 14 → 56 not taken.
✓ Branch 15 → 16 taken 6313 times.
✗ Branch 15 → 56 not taken.
✓ Branch 29 → 17 taken 11446 times.
✓ Branch 29 → 30 taken 6311 times.
17757 for (const auto &dependency : sourceFile->dependencies | std::views::values)
402
3/4
✓ Branch 18 → 19 taken 11446 times.
✗ Branch 18 → 56 not taken.
✓ Branch 19 → 20 taken 2 times.
✓ Branch 19 → 27 taken 11444 times.
11446 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 6311 node->entry = rootScope->insert(node->varName, node);
407 // Register the name in the exported name registry
408 6311 sourceFile->addNameRegistryEntry(node->varName, TY_INVALID, node->entry, currentScope, true);
409
410
1/2
✓ Branch 34 → 35 taken 6311 times.
✗ Branch 34 → 57 not taken.
12622 return nullptr;
411 }
412
413 9195 std::any SymbolTableBuilder::visitExtDecl(ExtDeclNode *node) {
414 // Visit attributes
415
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 6 taken 9193 times.
9195 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 9193 times.
18390 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 9193 times.
✗ Branch 17 → 43 not taken.
✓ Branch 18 → 19 taken 9193 times.
✗ Branch 18 → 41 not taken.
9193 rootScope->createChildScope(node->getScopeId(), ScopeType::FUNC_PROC_BODY, &node->codeLoc);
424
425 // Add the external declaration to the symbol table
426 9193 node->entry = rootScope->insert(node->extFunctionName, node);
427 // Register the name in the exported name registry
428
2/2
✓ Branch 23 → 24 taken 7542 times.
✓ Branch 23 → 25 taken 1651 times.
9193 const uint64_t typeId = node->returnType ? TY_FUNCTION : TY_PROCEDURE;
429 9193 sourceFile->addNameRegistryEntry(node->extFunctionName, typeId, node->entry, rootScope, /*keepNewOnCollision=*/true);
430
431
1/2
✓ Branch 27 → 28 taken 9193 times.
✗ Branch 27 → 44 not taken.
18386 return nullptr;
432 }
433
434 18202 std::any SymbolTableBuilder::visitUnsafeBlock(UnsafeBlockNode *node) {
435 // Create scope for the unsafe block body
436 18202 node->bodyScope = currentScope =
437
2/4
✓ Branch 2 → 3 taken 18202 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 18202 times.
✗ Branch 3 → 11 not taken.
18202 currentScope->createChildScope(node->getScopeId(), ScopeType::UNSAFE_BODY, &node->body->codeLoc);
438
439 // Visit body
440
1/2
✓ Branch 5 → 6 taken 18202 times.
✗ Branch 5 → 14 not taken.
18202 visit(node->body);
441
442 // Leave thread body scope
443 18202 currentScope = node->bodyScope->parent;
444
445
1/2
✓ Branch 7 → 8 taken 18202 times.
✗ Branch 7 → 15 not taken.
36404 return nullptr;
446 }
447
448 6680 std::any SymbolTableBuilder::visitForLoop(ForLoopNode *node) {
449 // Create scope for the loop body
450
2/4
✓ Branch 2 → 3 taken 6680 times.
✗ Branch 2 → 16 not taken.
✓ Branch 3 → 4 taken 6680 times.
✗ Branch 3 → 14 not taken.
6680 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 6680 times.
✗ Branch 5 → 17 not taken.
6680 visit(node->initDecl);
454
455 // Visit condition
456 6680 visitInExprScope(node->condAssign);
457
458 // Visit body
459
1/2
✓ Branch 8 → 9 taken 6680 times.
✗ Branch 8 → 18 not taken.
6680 visit(node->body);
460
461 // Leave for body scope
462 6680 currentScope = node->bodyScope->parent;
463
464
1/2
✓ Branch 10 → 11 taken 6680 times.
✗ Branch 10 → 19 not taken.
13360 return nullptr;
465 }
466
467 835 std::any SymbolTableBuilder::visitForeachLoop(ForeachLoopNode *node) {
468 // Create scope for the loop body
469 835 node->bodyScope = currentScope =
470
2/4
✓ Branch 2 → 3 taken 835 times.
✗ Branch 2 → 19 not taken.
✓ Branch 3 → 4 taken 835 times.
✗ Branch 3 → 17 not taken.
835 currentScope->createChildScope(node->getScopeId(), ScopeType::FOREACH_BODY, &node->body->codeLoc);
471
472 // Visit index variable declaration
473
2/2
✓ Branch 5 → 6 taken 126 times.
✓ Branch 5 → 9 taken 709 times.
835 if (node->idxVarDecl)
474
1/2
✓ Branch 6 → 7 taken 126 times.
✗ Branch 6 → 20 not taken.
126 visit(node->idxVarDecl);
475
476 // Visit item variable declaration
477
1/2
✓ Branch 9 → 10 taken 835 times.
✗ Branch 9 → 21 not taken.
835 visit(node->itemVarDecl);
478
479 // Visit body
480
1/2
✓ Branch 11 → 12 taken 835 times.
✗ Branch 11 → 22 not taken.
835 visit(node->body);
481
482 // Leave foreach body scope
483 835 currentScope = node->bodyScope->parent;
484
485
1/2
✓ Branch 13 → 14 taken 835 times.
✗ Branch 13 → 23 not taken.
1670 return nullptr;
486 }
487
488 3159 std::any SymbolTableBuilder::visitWhileLoop(WhileLoopNode *node) {
489 // Create scope for the loop body
490 3159 node->bodyScope = currentScope =
491
2/4
✓ Branch 2 → 3 taken 3159 times.
✗ Branch 2 → 14 not taken.
✓ Branch 3 → 4 taken 3159 times.
✗ Branch 3 → 12 not taken.
3159 currentScope->createChildScope(node->getScopeId(), ScopeType::WHILE_BODY, &node->body->codeLoc);
492
493 // Visit condition
494 3159 visitInExprScope(node->condition);
495
496 // Visit body
497
1/2
✓ Branch 6 → 7 taken 3159 times.
✗ Branch 6 → 15 not taken.
3159 visit(node->body);
498
499 // Leave while body scope
500 3159 currentScope = node->bodyScope->parent;
501
502
1/2
✓ Branch 8 → 9 taken 3159 times.
✗ Branch 8 → 16 not taken.
6318 return nullptr;
503 }
504
505 37 std::any SymbolTableBuilder::visitDoWhileLoop(DoWhileLoopNode *node) {
506 // Create scope for the loop body
507 37 node->bodyScope = currentScope =
508
2/4
✓ Branch 2 → 3 taken 37 times.
✗ Branch 2 → 14 not taken.
✓ Branch 3 → 4 taken 37 times.
✗ Branch 3 → 12 not taken.
37 currentScope->createChildScope(node->getScopeId(), ScopeType::WHILE_BODY, &node->body->codeLoc);
509
510 // Visit condition
511 37 visitInExprScope(node->condition);
512
513 // Visit body
514
1/2
✓ Branch 6 → 7 taken 37 times.
✗ Branch 6 → 15 not taken.
37 visit(node->body);
515
516 // Leave do-while body scope
517 37 currentScope = node->bodyScope->parent;
518
519
1/2
✓ Branch 8 → 9 taken 37 times.
✗ Branch 8 → 16 not taken.
74 return nullptr;
520 }
521
522 39650 std::any SymbolTableBuilder::visitIfStmt(IfStmtNode *node) {
523 // Create scope for the then body
524 39650 node->thenBodyScope = currentScope =
525
2/4
✓ Branch 2 → 3 taken 39650 times.
✗ Branch 2 → 26 not taken.
✓ Branch 3 → 4 taken 39650 times.
✗ Branch 3 → 24 not taken.
39650 currentScope->createChildScope(node->getScopeId(), ScopeType::IF_ELSE_BODY, &node->thenBody->codeLoc);
526
527 // Visit condition
528 39650 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 39650 times.
✗ Branch 7 → 11 not taken.
39650 if (node->doCompileThenBranch(manIdx))
532
1/2
✓ Branch 8 → 9 taken 39650 times.
✗ Branch 8 → 27 not taken.
39650 visit(node->thenBody);
533
534 // Leave then body scope
535 39650 currentScope = node->thenBodyScope->parent;
536
537 // Visit else stmt
538
5/6
✓ Branch 12 → 13 taken 39650 times.
✗ Branch 12 → 15 not taken.
✓ Branch 13 → 14 taken 3063 times.
✓ Branch 13 → 15 taken 36587 times.
✓ Branch 16 → 17 taken 3063 times.
✓ Branch 16 → 20 taken 36587 times.
39650 if (node->doCompileElseBranch(manIdx) && node->elseStmt)
539
1/2
✓ Branch 17 → 18 taken 3063 times.
✗ Branch 17 → 28 not taken.
3063 visit(node->elseStmt);
540
541
1/2
✓ Branch 20 → 21 taken 39650 times.
✗ Branch 20 → 29 not taken.
79300 return nullptr;
542 }
543
544 3063 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 1253 times.
✓ Branch 2 → 8 taken 1810 times.
3063 if (node->isElseIf) {
547
1/2
✓ Branch 3 → 4 taken 1253 times.
✗ Branch 3 → 17 not taken.
1253 visit(node->ifStmt);
548
1/2
✓ Branch 5 → 6 taken 1253 times.
✗ Branch 5 → 18 not taken.
2506 return nullptr;
549 }
550
551 // Create scope for the else body
552 1810 node->elseBodyScope = currentScope =
553
2/4
✓ Branch 8 → 9 taken 1810 times.
✗ Branch 8 → 21 not taken.
✓ Branch 9 → 10 taken 1810 times.
✗ Branch 9 → 19 not taken.
1810 currentScope->createChildScope(node->getScopeId(), ScopeType::IF_ELSE_BODY, &node->body->codeLoc);
554
555 // Visit else body
556
1/2
✓ Branch 11 → 12 taken 1810 times.
✗ Branch 11 → 22 not taken.
1810 visit(node->body);
557
558 // Leave else body scope
559 1810 currentScope = node->elseBodyScope->parent;
560
561
1/2
✓ Branch 13 → 14 taken 1810 times.
✗ Branch 13 → 23 not taken.
3620 return nullptr;
562 }
563
564 1539 std::any SymbolTableBuilder::visitCaseBranch(CaseBranchNode *node) {
565 // Create scope for the case branch
566
2/4
✓ Branch 2 → 3 taken 1539 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 1539 times.
✗ Branch 3 → 11 not taken.
1539 node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::CASE_BODY, &node->body->codeLoc);
567
568 // Visit case body
569
1/2
✓ Branch 5 → 6 taken 1539 times.
✗ Branch 5 → 14 not taken.
1539 visit(node->body);
570
571 // Leave case body scope
572 1539 currentScope = node->bodyScope->parent;
573
574
1/2
✓ Branch 7 → 8 taken 1539 times.
✗ Branch 7 → 15 not taken.
3078 return nullptr;
575 }
576
577 157 std::any SymbolTableBuilder::visitDefaultBranch(DefaultBranchNode *node) {
578 // Create scope for the default branch
579 157 node->bodyScope = currentScope =
580
2/4
✓ Branch 2 → 3 taken 157 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 157 times.
✗ Branch 3 → 11 not taken.
157 currentScope->createChildScope(node->getScopeId(), ScopeType::DEFAULT_BODY, &node->body->codeLoc);
581
582 // Visit default body
583
1/2
✓ Branch 5 → 6 taken 157 times.
✗ Branch 5 → 14 not taken.
157 visit(node->body);
584
585 // Leave default body scope
586 157 currentScope = node->bodyScope->parent;
587
588
1/2
✓ Branch 7 → 8 taken 157 times.
✗ Branch 7 → 15 not taken.
314 return nullptr;
589 }
590
591 123 std::any SymbolTableBuilder::visitAnonymousBlockStmt(AnonymousBlockStmtNode *node) {
592 // Create scope for the anonymous block body
593 123 node->bodyScope = currentScope =
594
2/4
✓ Branch 2 → 3 taken 123 times.
✗ Branch 2 → 13 not taken.
✓ Branch 3 → 4 taken 123 times.
✗ Branch 3 → 11 not taken.
123 currentScope->createChildScope(node->getScopeId(), ScopeType::ANONYMOUS_BLOCK_BODY, &node->body->codeLoc);
595
596 // Visit body
597
1/2
✓ Branch 5 → 6 taken 123 times.
✗ Branch 5 → 14 not taken.
123 visit(node->body);
598
599 // Leave anonymous block body scope
600 123 currentScope = node->bodyScope->parent;
601
602
1/2
✓ Branch 7 → 8 taken 123 times.
✗ Branch 7 → 15 not taken.
246 return nullptr;
603 }
604
605 11084 std::any SymbolTableBuilder::visitEnumItem(EnumItemNode *node) {
606 // Check if enum item already exists in the same scope.
607
3/4
✓ Branch 2 → 3 taken 11084 times.
✗ Branch 2 → 42 not taken.
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 11082 times.
22168 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 11082 times.
✗ Branch 13 → 42 not taken.
11082 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 11082 times.
11082 assert(node->enumDef != nullptr);
615
2/4
✓ Branch 18 → 19 taken 11082 times.
✗ Branch 18 → 38 not taken.
✓ Branch 19 → 20 taken 11082 times.
✗ Branch 19 → 36 not taken.
11082 const std::string name = node->enumDef->enumName + SCOPE_ACCESS_TOKEN + node->itemName;
616
1/2
✓ Branch 21 → 22 taken 11082 times.
✗ Branch 21 → 40 not taken.
11082 sourceFile->addNameRegistryEntry(name, TY_INT, enumItemEntry, currentScope, true);
617
618
1/2
✓ Branch 22 → 23 taken 11082 times.
✗ Branch 22 → 39 not taken.
22164 return nullptr;
619 11082 }
620
621 15911 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 15907 times.
31822 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 15907 currentScope->insert(node->fieldName, node);
628
629
1/2
✓ Branch 16 → 17 taken 15907 times.
✗ Branch 16 → 29 not taken.
31814 return nullptr;
630 }
631
632 4907 std::any SymbolTableBuilder::visitSignature(SignatureNode *node) {
633 // Build signature qualifiers
634
2/2
✓ Branch 2 → 3 taken 4815 times.
✓ Branch 2 → 32 taken 92 times.
4907 if (const QualifierLstNode *qualifierLst = node->qualifierLst) {
635
2/2
✓ Branch 30 → 5 taken 5087 times.
✓ Branch 30 → 31 taken 4815 times.
14717 for (const QualifierNode *qualifier : qualifierLst->qualifiers) {
636
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 5087 times.
5087 if (qualifier->type == QualifierNode::QualifierType::TY_INLINE)
637 node->signatureQualifiers.isInline = true;
638
2/2
✓ Branch 9 → 10 taken 4815 times.
✓ Branch 9 → 11 taken 272 times.
5087 else if (qualifier->type == QualifierNode::QualifierType::TY_PUBLIC)
639 4815 node->signatureQualifiers.isPublic = true;
640
1/2
✓ Branch 11 → 12 taken 272 times.
✗ Branch 11 → 13 not taken.
272 else if (qualifier->type == QualifierNode::QualifierType::TY_CONST)
641 272 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 4907 times.
✗ Branch 32 → 53 not taken.
9814 node->entry = currentScope->insert(Function::getSymbolTableEntryName(node->methodName, node->codeLoc), node);
650
651
1/2
✓ Branch 37 → 38 taken 4907 times.
✗ Branch 37 → 54 not taken.
9814 return nullptr;
652 }
653
654 140075 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 140073 times.
280150 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 50893 times.
✓ Branch 13 → 17 taken 89180 times.
140073 if (node->hasAssignment)
661
1/2
✓ Branch 14 → 15 taken 50893 times.
✗ Branch 14 → 33 not taken.
50893 visit(node->assignExpr);
662
663 // Add variable entry to symbol table
664 140073 SymbolTableEntry *varEntry = currentScope->insert(node->varName, node);
665 140073 varEntry->isParam = node->isFctParam;
666
667
1/2
✓ Branch 20 → 21 taken 140073 times.
✗ Branch 20 → 34 not taken.
280146 return nullptr;
668 }
669
670 2248 std::any SymbolTableBuilder::visitModAttr(ModAttrNode *node) {
671 // Visit attributes
672
2/2
✓ Branch 2 → 3 taken 2246 times.
✓ Branch 2 → 126 taken 2 times.
2248 visitChildren(node);
673
674 // Retrieve attributes
675 2246 const AttrLstNode *attrs = node->attrLst;
676
677 // Collect linker flags
678 2246 std::vector<const CompileTimeValue *> linkerFlagValues;
679 // core.linker.flag
680
2/4
✓ Branch 6 → 7 taken 2246 times.
✗ Branch 6 → 129 not taken.
✓ Branch 7 → 8 taken 2246 times.
✗ Branch 7 → 127 not taken.
4492 std::vector<const CompileTimeValue *> values = attrs->getAttrValuesByName(ATTR_CORE_LINKER_FLAG);
681
1/2
✓ Branch 16 → 17 taken 2246 times.
✗ Branch 16 → 133 not taken.
4492 linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end());
682 // core.linux.linker.flag
683 2246 const llvm::Triple &targetTriple = sourceFile->targetMachine->getTargetTriple();
684
2/2
✓ Branch 20 → 21 taken 2222 times.
✓ Branch 20 → 37 taken 24 times.
2246 if (targetTriple.isOSLinux()) {
685
2/4
✓ Branch 23 → 24 taken 2222 times.
✗ Branch 23 → 137 not taken.
✓ Branch 24 → 25 taken 2222 times.
✗ Branch 24 → 135 not taken.
4444 values = attrs->getAttrValuesByName(ATTR_CORE_LINUX_LINKER_FLAG);
686
1/2
✓ Branch 35 → 36 taken 2222 times.
✗ Branch 35 → 142 not taken.
4444 linkerFlagValues.insert(linkerFlagValues.end(), values.begin(), values.end());
687 }
688 // core.darwin.linker.flag
689
3/4
✓ Branch 37 → 38 taken 2246 times.
✗ Branch 37 → 187 not taken.
✓ Branch 38 → 39 taken 12 times.
✓ Branch 38 → 55 taken 2234 times.
2246 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 2234 times.
2246 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 3002 times.
✓ Branch 89 → 90 taken 2246 times.
7494 for (const CompileTimeValue *value : linkerFlagValues) {
699
1/2
✓ Branch 77 → 78 taken 3002 times.
✗ Branch 77 → 162 not taken.
3002 const std::string &flag = resourceManager.compileTimeStringValues.at(value->stringValueOffset);
700
1/2
✓ Branch 78 → 79 taken 3002 times.
✗ Branch 78 → 162 not taken.
3002 resourceManager.linker.addLinkerFlag(flag);
701
1/2
✓ Branch 79 → 80 taken 3002 times.
✗ Branch 79 → 162 not taken.
3002 sourceFile->sourceLinkerFlags.push_back(flag);
702 }
703
704 // core.linker.additionalSource
705
4/6
✓ Branch 90 → 91 taken 2246 times.
✗ Branch 90 → 165 not taken.
✓ Branch 91 → 92 taken 2246 times.
✗ Branch 91 → 163 not taken.
✓ Branch 116 → 94 taken 24 times.
✓ Branch 116 → 117 taken 2244 times.
4514 for (const CompileTimeValue *value : attrs->getAttrValuesByName(ATTR_CORE_LINKER_ADDITIONAL_SOURCE)) {
706
1/2
✓ Branch 96 → 97 taken 24 times.
✗ Branch 96 → 178 not taken.
24 const std::string &stringValue = resourceManager.compileTimeStringValues.at(value->stringValueOffset);
707
3/6
✓ Branch 97 → 98 taken 24 times.
✗ Branch 97 → 172 not taken.
✓ Branch 98 → 99 taken 24 times.
✗ Branch 98 → 169 not taken.
✓ Branch 99 → 100 taken 24 times.
✗ Branch 99 → 167 not taken.
24 const std::filesystem::path additionalSourcePath = sourceFile->filePath.parent_path() / stringValue;
708
3/4
✓ Branch 102 → 103 taken 24 times.
✗ Branch 102 → 175 not taken.
✓ Branch 103 → 104 taken 22 times.
✓ Branch 103 → 173 taken 2 times.
26 resourceManager.linker.addAdditionalSourcePath(additionalSourcePath);
709
1/2
✓ Branch 105 → 106 taken 22 times.
✗ Branch 105 → 176 not taken.
22 sourceFile->sourceAdditionalSourcePaths.push_back(additionalSourcePath);
710 2272 }
711
712
1/2
✓ Branch 120 → 121 taken 2244 times.
✗ Branch 120 → 186 not taken.
4488 return nullptr;
713 2248 }
714
715 8288 std::any SymbolTableBuilder::visitAttr(AttrNode *node) {
716 // Check if this attribute exists
717
1/2
✓ Branch 2 → 3 taken 8288 times.
✗ Branch 2 → 63 not taken.
8288 const auto it = ATTR_CONFIGS.find(node->key);
718
2/2
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 13 taken 8286 times.
8288 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 8286 const auto &[target, type] = it->second;
723
2/2
✓ Branch 14 → 15 taken 2 times.
✓ Branch 14 → 22 taken 8284 times.
8286 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 1688 times.
✓ Branch 22 → 31 taken 6596 times.
✓ Branch 23 → 24 taken 2 times.
✓ Branch 23 → 31 taken 1686 times.
8284 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 8282 times.
✗ Branch 31 → 62 not taken.
16564 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 150 std::any SymbolTableBuilder::visitLambdaProc(LambdaProcNode *node) {
760 // Create scope for the lambda body
761 150 const CodeLoc &codeLoc = node->body->codeLoc;
762
2/4
✓ Branch 2 → 3 taken 150 times.
✗ Branch 2 → 39 not taken.
✓ Branch 3 → 4 taken 150 times.
✗ Branch 3 → 37 not taken.
150 node->bodyScope = currentScope = currentScope->createChildScope(node->getScopeId(), ScopeType::LAMBDA_BODY, &codeLoc);
763 // Requires capturing because the LLVM IR will end up in a separate function
764 150 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 134 times.
✓ Branch 9 → 10 taken 16 times.
✗ Branch 9 → 40 not taken.
✓ Branch 10 → 11 taken 16 times.
✗ Branch 10 → 40 not taken.
✓ Branch 11 → 12 taken 16 times.
✗ Branch 11 → 13 not taken.
✓ Branch 14 → 15 taken 16 times.
✓ Branch 14 → 16 taken 134 times.
✓ Branch 16 → 17 taken 16 times.
✓ Branch 16 → 19 taken 134 times.
✓ Branch 19 → 20 taken 16 times.
✓ Branch 19 → 27 taken 134 times.
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 42 not taken.
✗ Branch 44 → 45 not taken.
✗ Branch 44 → 47 not taken.
182 if (node->lambdaAttr && node->lambdaAttr->attrLst->hasAttr(ATTR_ASYNC))
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 118 times.
✓ Branch 27 → 31 taken 32 times.
150 if (node->hasParams)
771
1/2
✓ Branch 28 → 29 taken 118 times.
✗ Branch 28 → 55 not taken.
118 visit(node->paramLst);
772
773 // Visit body
774
1/2
✓ Branch 31 → 32 taken 150 times.
✗ Branch 31 → 56 not taken.
150 visit(node->body);
775
776 // Leave anonymous block body scope
777 150 currentScope = node->bodyScope->parent;
778
779
1/2
✓ Branch 33 → 34 taken 150 times.
✗ Branch 33 → 57 not taken.
300 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 4199 std::any SymbolTableBuilder::visitTernaryExpr(TernaryExprNode *node) {
803 // Visit condition, which is evaluated unconditionally
804
1/2
✓ Branch 2 → 3 taken 4199 times.
✗ Branch 2 → 13 not taken.
4199 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 4197 times.
✓ Branch 4 → 7 taken 2 times.
✓ Branch 5 → 6 taken 4197 times.
✗ Branch 5 → 7 not taken.
4199 if (node->trueExpr && !node->isShortened)
809 4197 visitInExprScope(node->trueExpr);
810
1/2
✓ Branch 7 → 8 taken 4199 times.
✗ Branch 7 → 9 not taken.
4199 if (node->falseExpr)
811 4199 visitInExprScope(node->falseExpr);
812
813
1/2
✓ Branch 9 → 10 taken 4199 times.
✗ Branch 9 → 14 not taken.
8398 return nullptr;
814 }
815
816 6097 std::any SymbolTableBuilder::visitLogicalOrExpr(LogicalOrExprNode *node) {
817 // Visit the first operand, which is evaluated unconditionally
818
1/2
✓ Branch 3 → 4 taken 6097 times.
✗ Branch 3 → 15 not taken.
6097 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 7883 times.
✓ Branch 10 → 11 taken 6097 times.
13980 for (size_t i = 1; i < node->operands.size(); i++)
822 7883 visitInExprScope(node->operands[i]);
823
824
1/2
✓ Branch 11 → 12 taken 6097 times.
✗ Branch 11 → 16 not taken.
12194 return nullptr;
825 }
826
827 3695 std::any SymbolTableBuilder::visitLogicalAndExpr(LogicalAndExprNode *node) {
828 // Visit the first operand, which is evaluated unconditionally
829
1/2
✓ Branch 3 → 4 taken 3695 times.
✗ Branch 3 → 15 not taken.
3695 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 4639 times.
✓ Branch 10 → 11 taken 3695 times.
8334 for (size_t i = 1; i < node->operands.size(); i++)
833 4639 visitInExprScope(node->operands[i]);
834
835
1/2
✓ Branch 11 → 12 taken 3695 times.
✗ Branch 11 → 16 not taken.
7390 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 70444 void SymbolTableBuilder::visitInExprScope(ExprNode *expr) {
846 // Create scope for the expression
847
2/4
✓ Branch 2 → 3 taken 70444 times.
✗ Branch 2 → 10 not taken.
✓ Branch 3 → 4 taken 70444 times.
✗ Branch 3 → 8 not taken.
70444 currentScope = currentScope->createChildScope(expr->getExprScopeId(), ScopeType::EXPR_BODY, &expr->codeLoc);
848
849 // Visit the expression
850
1/2
✓ Branch 5 → 6 taken 70444 times.
✗ Branch 5 → 11 not taken.
70444 visit(expr);
851
852 // Leave expression scope
853 70444 currentScope = currentScope->parent;
854 70444 }
855
856 } // namespace spice::compiler
857