GCC Code Coverage Report


src/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
1801 / 1998
90.1%
Branches:
487 / 584, 62 excl
83.4%
Functions:
620 / 714
86.8%

ast/ast-nodes.spice
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 // Std imports
4 import "std/data/vector";
5 import "std/data/queue";
6 import "std/data/unordered-map";
7 import "std/data/pair";
8 import "std/type/any";
9 import "std/type/type-conversion";
10 import "std/io/file";
11
12 // Generic types
13 type ConcreteNode dyn;
14
15 // Own imports
16 import "@/ast/abstract-ast-visitor-intf";
17 import "@/reader/code-loc";
18 import "@/symboltablebuilder/type-qualifiers";
19 import "@/symboltablebuilder/symbol-table-entry";
20 import "@/symboltablebuilder/scope";
21 import "@/symboltablebuilder/capture";
22 import "@/ast/attributes";
23 import "@/symboltablebuilder/qual-type";
24 import "@/symboltablebuilder/super-type";
25 import "@/exception/semantic-error";
26 import "@/typechecker/builtin-functions";
27 import "@/typechecker/function-manager";
28 import "@/model/function";
29 import "@/model/generic-type";
30 import "@/model/struct";
31 import "@/model/interface";
32 import "@/model/union";
33
34 // Access tokens used when building type/function/scope signatures
35 public const string MEMBER_ACCESS_TOKEN = ".";
36 public const string SCOPE_ACCESS_TOKEN = "::";
37
38 // Operator overload function names
39 public const string OP_FCT_PREFIX = "op.";
40 public const string OP_FCT_PLUS = "op.plus";
41 public const string OP_FCT_MINUS = "op.minus";
42 public const string OP_FCT_MUL = "op.mul";
43 public const string OP_FCT_DIV = "op.div";
44 public const string OP_FCT_EQUAL = "op.equal";
45 public const string OP_FCT_NOT_EQUAL = "op.notequal";
46 public const string OP_FCT_LESS = "op.less";
47 public const string OP_FCT_GREATER = "op.greater";
48 public const string OP_FCT_LESS_EQUAL = "op.lessequal";
49 public const string OP_FCT_GREATER_EQUAL = "op.greaterequal";
50 public const string OP_FCT_SHL = "op.shl";
51 public const string OP_FCT_SHR = "op.shr";
52 public const string OP_FCT_BITWISE_AND = "op.bitwiseand";
53 public const string OP_FCT_BITWISE_OR = "op.bitwiseor";
54 public const string OP_FCT_BITWISE_XOR = "op.bitwisexor";
55 public const string OP_FCT_BITWISE_NOT = "op.bitwisenot";
56 public const string OP_FCT_PLUS_EQUAL = "op.plusequal";
57 public const string OP_FCT_MINUS_EQUAL = "op.minusequal";
58 public const string OP_FCT_MUL_EQUAL = "op.mulequal";
59 public const string OP_FCT_DIV_EQUAL = "op.divequal";
60 public const string OP_FCT_POSTFIX_PLUS_PLUS = "op.plusplus.post";
61 public const string OP_FCT_POSTFIX_MINUS_MINUS = "op.minusminus.post";
62 public const string OP_FCT_SUBSCRIPT = "op.subscript";
63 public const string OP_FCT_ASSIGN = "op.assign";
64
65 /**
66 * Saves a constant value for an AST node to realize features like array-out-of-bounds checks
67 *
68 * The compiler reads across the members of a compile time value, e.g. the longValue of an int constant in compile time
69 * arithmetic, or the boolValue of a non-bool condition. Spice unions are tagged and panic when an inactive field is read,
70 * so an untagged union is emulated here: all members share 8 bytes of storage and each member is a view on them, which
71 * reads and writes only its own bytes.
72 */
73 283230 public type CompileTimeValue struct {
74 283230 long storage = 0l
75 }
76
77 // Address of the shared storage, the members are views on
78 inline f<byte*> CompileTimeValue.getStorageAddress() {
79 unsafe {
80 return cast<byte*>(&this.storage);
81 }
82 }
83
84 1331 public f<double> CompileTimeValue.getDoubleValue() {
85 unsafe {
86 2662 const double* valuePtr = cast<double*>(this.getStorageAddress());
87 1331 return *valuePtr;
88 }
89 }
90 1351 public p CompileTimeValue.setDoubleValue(double value) {
91 unsafe {
92 2702 double* valuePtr = cast<double*>(this.getStorageAddress());
93 1351 *valuePtr = value;
94 }
95 1351 }
96
97 15557 public f<int> CompileTimeValue.getIntValue() {
98 unsafe {
99 31114 const int* valuePtr = cast<int*>(this.getStorageAddress());
100 15557 return *valuePtr;
101 }
102 }
103 16800 public p CompileTimeValue.setIntValue(int value) {
104 unsafe {
105 33600 int* valuePtr = cast<int*>(this.getStorageAddress());
106 16800 *valuePtr = value;
107 }
108 16800 }
109
110 2221 public f<short> CompileTimeValue.getShortValue() {
111 unsafe {
112 4442 const short* valuePtr = cast<short*>(this.getStorageAddress());
113 2221 return *valuePtr;
114 }
115 }
116 2233 public p CompileTimeValue.setShortValue(short value) {
117 unsafe {
118 4466 short* valuePtr = cast<short*>(this.getStorageAddress());
119 2233 *valuePtr = value;
120 }
121 2233 }
122
123 37249 public f<long> CompileTimeValue.getLongValue() {
124 37249 return this.storage;
125 }
126 30944 public p CompileTimeValue.setLongValue(long value) {
127 30944 this.storage = value;
128 30944 }
129
130 8757 public f<char> CompileTimeValue.getCharValue() {
131 unsafe {
132 17514 const char* valuePtr = cast<char*>(this.getStorageAddress());
133 8757 return *valuePtr;
134 }
135 }
136 9888 public p CompileTimeValue.setCharValue(char value) {
137 unsafe {
138 19776 char* valuePtr = cast<char*>(this.getStorageAddress());
139 9888 *valuePtr = value;
140 }
141 9888 }
142
143 // Offset into vector of strings in GlobalResourceManager
144 16178 public f<unsigned long> CompileTimeValue.getStringValueOffset() {
145 unsafe {
146 32356 const unsigned long* valuePtr = cast<unsigned long*>(this.getStorageAddress());
147 16178 return *valuePtr;
148 }
149 }
150 14698 public p CompileTimeValue.setStringValueOffset(unsigned long value) {
151 unsafe {
152 29396 unsigned long* valuePtr = cast<unsigned long*>(this.getStorageAddress());
153 14698 *valuePtr = value;
154 }
155 14698 }
156
157 // A bool occupies one byte, which is interpreted like a C++ bool (any non-zero value is true)
158 8623 public f<bool> CompileTimeValue.getBoolValue() {
159 17246 const byte* valuePtr = this.getStorageAddress();
160 8623 return *valuePtr != cast<byte>(0);
161 }
162 7696 public p CompileTimeValue.setBoolValue(bool value) {
163 15392 byte* valuePtr = this.getStorageAddress();
164 7696 *valuePtr = value ? cast<byte>(1) : cast<byte>(0);
165 7696 }
166
167 public type IVisitable interface {
168 public f<Any> accept(IAbstractAstVisitor*);
169 public f<const CodeLoc&> getCodeLoc();
170 // Address of the composed ASTNode. It is not typed as ASTNode*, because ASTNode is declared after this interface (and
171 // needs it for its 'visitable' field). Use getASTNode(IVisitable*) to retrieve the typed pointer.
172 public f<byte*> getASTNodeAddress();
173 }
174
175 // ========================================================= ASTNodeKind =========================================================
176
177 /**
178 * Kind of a concrete AST node. Spice has no virtual dispatch through a struct, so the functions below, that depend on the
179 * concrete node (e.g. returnsOnAllControlPaths), switch over the kind of the node instead.
180 */
181 public type ASTNodeKind enum {
182 INVALID,
183 ENTRY,
184 CONSTANT,
185 ATTR,
186 ATTR_LST,
187 QUALIFIER,
188 QUALIFIER_LST,
189 CUSTOM_DATA_TYPE,
190 BASE_DATA_TYPE,
191 DATA_TYPE,
192 TYPE_LST,
193 MAIN_FCT_DEF,
194 FCT_NAME,
195 FCT_DEF,
196 PROC_DEF,
197 STRUCT_DEF,
198 INTERFACE_DEF,
199 UNION_DEF,
200 ENUM_DEF,
201 GENERIC_TYPE_DEF,
202 ALIAS_DEF,
203 GLOBAL_VAR_DEF,
204 EXT_DECL,
205 IMPORT_DEF,
206 UNSAFE_BLOCK,
207 FOR_LOOP,
208 FOREACH_LOOP,
209 WHILE_LOOP,
210 DO_WHILE_LOOP,
211 IF_STMT,
212 ELSE_STMT,
213 SWITCH_STMT,
214 CASE_BRANCH,
215 DEFAULT_BRANCH,
216 ANONYMOUS_BLOCK_STMT,
217 STMT_LST,
218 TYPE_LST_WITH_ELLIPSIS,
219 TYPE_ALTS_LST,
220 DECL_STMT,
221 PARAM_LST,
222 ARG_LST,
223 ENUM_ITEM,
224 ENUM_ITEM_LST,
225 FIELD,
226 SIGNATURE,
227 EXPR_STMT,
228 MOD_ATTR,
229 TOP_LEVEL_DEF_ATTR,
230 LAMBDA_ATTR,
231 CASE_CONSTANT,
232 RETURN_STMT,
233 BREAK_STMT,
234 CONTINUE_STMT,
235 FALLTHROUGH_STMT,
236 ASSERT_STMT,
237 ASSIGN_EXPR,
238 TERNARY_EXPR,
239 LOGICAL_OR_EXPR,
240 LOGICAL_AND_EXPR,
241 BITWISE_OR_EXPR,
242 BITWISE_XOR_EXPR,
243 BITWISE_AND_EXPR,
244 EQUALITY_EXPR,
245 RELATIONAL_EXPR,
246 SHIFT_EXPR,
247 ADDITIVE_EXPR,
248 MULTIPLICATIVE_EXPR,
249 CAST_EXPR,
250 PREFIX_UNARY_EXPR,
251 POSTFIX_UNARY_EXPR,
252 ATOMIC_EXPR,
253 VALUE,
254 FCT_CALL,
255 ARRAY_INITIALIZATION,
256 STRUCT_INSTANTIATION,
257 LAMBDA_FUNC,
258 LAMBDA_PROC,
259 LAMBDA_EXPR,
260 FUNCTION_DATA_TYPE
261 }
262
263 // =========================================================== ASTNode ===========================================================
264
265 ✗ public type ASTNode struct {
266 2230956 public ASTNode* parent = nil<ASTNode*>
267 public Vector<ASTNode*> children
268 public CodeLoc codeLoc
269 // The node as an IVisitable*, set by the parser when it creates the node. A plain ASTNode* cannot be dispatched
270 // on (Spice has no virtual dispatch through a struct), so generic child traversal goes through this pointer.
271 2230956 public IVisitable* visitable = nil<IVisitable*>
272 // Kind of the concrete node. Set by the constructor of the concrete node
273 2230956 public ASTNodeKind kind = ASTNodeKind::INVALID
274 // Whether the node is an expression / statement node. Set by the constructors of ASTExprNode / ASTStmtNode
275 2230956 public bool isExprNode = false
276 2230956 public bool isStmtNode = false
277 }
278
279 2230956 public p ASTNode.ctor(const CodeLoc& codeLoc) {
280 2230956 this.codeLoc = codeLoc;
281 2230956 }
282
283 // Explicit destructor. AST nodes only ever live inside the BlockAllocator pool and are released via
284 // destructASTNode(), which destructs them as their concrete node type. This destructor then runs as part of
285 // the destruction of the composed node base. Defining it explicitly makes sure it is generated. The composed
286 // 'children' vector only holds non-owning pointers, so it is enough to let the implicitly appended member
287 // destruction free the vector storage.
288 2142680 public p ASTNode.dtor() {}
289
290 // Register a child node and set its parent to this node.
291 2434962 public p ASTNode.addChild(ASTNode* child) {
292 2434962 assert child != nil<ASTNode*>;
293 2434962 child.parent = this;
294 2434962 this.children.pushBack(child);
295 2434962 }
296
297 202 public f<const Vector<ASTNode*>&> ASTNode.getChildren() {
298 202 return this.children;
299 }
300
301 // Number of chars of context, that an error message shows around the erroneous code
302 const long ERROR_MESSAGE_CONTEXT = 20l;
303
304 // Whether the given char can be part of an identifier or keyword
305 7721 f<bool> isIdentifierChar(char c) {
306
12/12
✓ Branch 0 taken 5540 times.
✓ Branch 1 taken 2181 times.
✓ Branch 2 taken 6666 times.
✓ Branch 3 taken 1055 times.
✓ Branch 4 taken 5450 times.
✓ Branch 5 taken 1216 times.
✓ Branch 6 taken 6604 times.
✓ Branch 7 taken 62 times.
✓ Branch 8 taken 3047 times.
✓ Branch 9 taken 3557 times.
✓ Branch 10 taken 4 times.
✓ Branch 11 taken 6600 times.
7721 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
307 }
308
309 // Get the text of the source code interval [start, stop] (both inclusive), clamped to the source code
310 90440 f<String> getSourceText(const String& sourceCode, long start, long stop) {
311 90440 const long size = cast<long>(sourceCode.getLength());
312
1/2
✓ Branch 0 taken 90440 times.
✗ Branch 1 not taken.
90440 if stop >= size { stop = size - 1l; }
313
5/6
✓ Branch 0 taken 90421 times.
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 90421 times.
✓ Branch 4 taken 19 times.
✓ Branch 5 taken 90421 times.
90440 if start < 0l || start >= size || stop < start { return String(); }
314 90421 return sourceCode.getSubstring(cast<unsigned long>(start), stop - start + 1l);
315 }
316
317 // Get the char at the given offset of the source code
318 33162 f<char> getSourceChar(const String& sourceCode, long idx) {
319 33162 const String text = getSourceText(sourceCode, idx, idx);
320
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33162 times.
33162 if text.isEmpty() { return '\0'; }
321 unsafe {
322 66324 return text[0];
323 }
324 33162 }
325
326 // Get the length of the interval [start, stop]
327 6598 f<long> getIntervalLength(long start, long stop) {
328
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6598 times.
6598 return stop < start ? 0l : stop - start + 1l;
329 }
330
331 /**
332 * Get the error message snippet of this node: the source code line of the node with some context around it, and a marker
333 * below the code of the node.
334 *
335 * Note: The nodes do not know their source file, so the source code is read from the file, the code location points to.
336 *
337 * @return Error message snippet
338 */
339 3299 public f<String> ASTNode.getErrorMessage() {
340 // Without a source interval (e.g. for nodes that were not created by the parser), there is no snippet to show
341
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3299 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3299 times.
3299 if this.codeLoc.sourceIntervalStart < 0l || len(this.codeLoc.sourceFilePath) == 0 {
342 ✗ return String();
343 }
344 3299 Result<String> sourceCodeResult = readFile(this.codeLoc.sourceFilePath);
345
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3299 times.
3299 if !sourceCodeResult.isOk() {
346 ✗ return String();
347 }
348 3299 const String sourceCode = sourceCodeResult.unwrap();
349 3299 const long inputSize = cast<long>(sourceCode.getLength());
350 3299 const long sourceIntervalStart = this.codeLoc.sourceIntervalStart;
351 3299 const long sourceIntervalStop = this.codeLoc.sourceIntervalStop;
352 3299 long extStart = sourceIntervalStart;
353 3299 long extStop = sourceIntervalStop;
354
355 // If we have a multi-line interval, only use the first line
356 3299 const String nodeText = getSourceText(sourceCode, extStart, extStop);
357 3299 const long newLineOffset = nodeText.find('\n');
358
2/2
✓ Branch 0 taken 3271 times.
✓ Branch 1 taken 28 times.
3299 if newLineOffset != -1l {
359 28 extStop = extStart + newLineOffset;
360 28 }
361 3299 const long nodeEnd = extStop;
362
363 3299 long markerIndentation = 0l;
364
2/2
✓ Branch 0 taken 1122 times.
✓ Branch 1 taken 40131 times.
41253 while markerIndentation < ERROR_MESSAGE_CONTEXT {
365 40131 extStart--;
366 40131 const String extText = getSourceText(sourceCode, extStart, extStop);
367
4/4
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 40112 times.
✓ Branch 2 taken 2177 times.
✓ Branch 3 taken 37954 times.
40131 if extStart < 0l || extText.find('\n') != -1l {
368 2177 extStart++;
369 2177 break;
370 }
371 37954 markerIndentation++;
372 40131 }
373
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 10549 times.
10615 for long suffixContext = 0l; suffixContext < ERROR_MESSAGE_CONTEXT; suffixContext++ {
374 10549 extStop++;
375 10549 const String extText = getSourceText(sourceCode, extStart, extStop);
376
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10549 times.
✓ Branch 2 taken 3233 times.
✓ Branch 3 taken 7316 times.
10549 if extStop > inputSize || extText.find('\n') != -1l {
377 3233 extStop--;
378 3233 break;
379 }
380 10549 }
381
382 // The context size is only a rough suggestion. Do not cut the context in the middle of an identifier or keyword
383
6/6
✓ Branch 0 taken 3685 times.
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 3263 times.
✓ Branch 3 taken 422 times.
✓ Branch 4 taken 408 times.
✓ Branch 5 taken 3299 times.
3707 while extStart > 0l && isIdentifierChar(getSourceChar(sourceCode, extStart - 1l)) && isIdentifierChar(getSourceChar(sourceCode, extStart)) {
384 408 extStart--;
385 408 markerIndentation++;
386 408 }
387
5/6
✓ Branch 0 taken 3418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3222 times.
✓ Branch 3 taken 196 times.
✓ Branch 4 taken 119 times.
✓ Branch 5 taken 3299 times.
3418 while extStop + 1l < inputSize && isIdentifierChar(getSourceChar(sourceCode, extStop)) && isIdentifierChar(getSourceChar(sourceCode, extStop + 1l)) {
388 119 extStop++;
389 119 }
390
391 // Trim start
392
2/2
✓ Branch 0 taken 15588 times.
✓ Branch 1 taken 3299 times.
18887 while getSourceChar(sourceCode, extStart) == ' ' {
393 15588 extStart++;
394 15588 markerIndentation--;
395 15588 }
396
397 // Trim end
398
2/2
✓ Branch 0 taken 3271 times.
✓ Branch 1 taken 28 times.
3299 if getSourceChar(sourceCode, extStop) == '\n' {
399 28 extStop--;
400 28 }
401
4/4
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 3255 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 3299 times.
3313 while extStop > nodeEnd && getSourceChar(sourceCode, extStop) == ' ' {
402 14 extStop--;
403 14 }
404
405 3299 const String lineNumberStr = toString(this.codeLoc.line);
406 3299 markerIndentation += cast<long>(lineNumberStr.getLength()) + 2l;
407
408 // Build error message
409 3299 String errorMessage = lineNumberStr + " " + getSourceText(sourceCode, extStart, extStop) + "\n";
410
2/2
✓ Branch 0 taken 37299 times.
✓ Branch 1 taken 3299 times.
40598 for long i = 0l; i < markerIndentation; i++ {
411 37299 errorMessage += ' ';
412 37299 }
413 3299 const long sourceIntervalLength = getIntervalLength(sourceIntervalStart, sourceIntervalStop);
414 3299 const long extIntervalLength = getIntervalLength(extStart, extStop);
415
2/2
✓ Branch 0 taken 3241 times.
✓ Branch 1 taken 58 times.
3299 const long markerLength = sourceIntervalLength < extIntervalLength ? sourceIntervalLength : extIntervalLength;
416
2/2
✓ Branch 0 taken 126068 times.
✓ Branch 1 taken 3299 times.
129367 for long i = 0l; i < markerLength; i++ {
417 126068 errorMessage += '^';
418 126068 }
419 6598 return errorMessage;
420 3299 }
421
422 // ========================================================== EntryNode ==========================================================
423
424 3518 public type ASTEntryNode struct : IVisitable {
425 compose public ASTNode node
426
427 public Vector<IVisitable*> modAttrs
428 public Vector<IVisitable*> importDefs
429 public Vector<IVisitable*> topLevelDefs
430 public Vector<IVisitable*> switchStmts // All switch statements of this file for quick access, not part of the children
431 }
432
433 3963 public p ASTEntryNode.ctor(CodeLoc codeLoc) {
434 3963 this.node = ASTNode(codeLoc);
435 3963 this.kind = ASTNodeKind::ENTRY;
436 3963 }
437 29324 public f<Any> ASTEntryNode.accept(IAbstractAstVisitor* visitor) {
438 29324 return visitor.visitEntry(this);
439 }
440
441 // ======================================================= TopLevelDefNode =======================================================
442
443 63024 public type ASTTopLevelDefNode struct {
444 compose public ASTNode node
445 }
446
447 66116 public p ASTTopLevelDefNode.ctor(CodeLoc codeLoc) {
448 66116 this.node = ASTNode(codeLoc);
449 66116 }
450
451 // =========================================================== StmtNode ==========================================================
452
453 230205 public type ASTStmtNode struct {
454 compose public ASTNode node
455 240024 public bool unreachable = false
456 }
457
458 240024 public p ASTStmtNode.ctor(CodeLoc codeLoc) {
459 240024 this.node = ASTNode(codeLoc);
460 240024 this.isStmtNode = true;
461 240024 }
462
463 // =========================================================== ExprNode ==========================================================
464
465 1299908 public type ASTExprNode struct {
466 compose public ASTNode node
467 QualTypeList symbolTypes
468 }
469
470 1351584 public p ASTExprNode.ctor(CodeLoc codeLoc) {
471 1351584 this.node = ASTNode(codeLoc);
472 1351584 this.isExprNode = true;
473 1351584 }
474
475 // Defined after ASTExprNode, because it accesses the symbol types of expression nodes
476 6968276 public p ASTNode.resizeToNumberOfManifestations(unsigned long manifestationCount) {
477 // Reserve this node
478
2/2
✓ Branch 0 taken 2707254 times.
✓ Branch 1 taken 4261022 times.
6968276 if this.isExprNode {
479 4261022 ASTExprNode* exprNode = asExprNode(this);
480 // Reserve exactly the required capacity on the first fill. Most nodes have a single manifestation, but a vector grows to
481 // the initial capacity of several items on its first insertion. Later fills (revisits, that add manifestations) keep the
482 // geometric growth of the vector, to not reallocate on every revisit. The same applies to customItemsInitialization
483
2/2
✓ Branch 0 taken 2911001 times.
✓ Branch 1 taken 1350021 times.
4261022 if exprNode.symbolTypes.isEmpty() {
484 1350021 exprNode.symbolTypes.reserve(manifestationCount);
485 1350021 }
486
2/2
✓ Branch 0 taken 1847788 times.
✓ Branch 1 taken 4261022 times.
6108810 while exprNode.symbolTypes.getSize() < manifestationCount {
487 1847788 exprNode.symbolTypes.pushBack(QualType(SuperType::TY_INVALID));
488 1847788 }
489 4261022 }
490 // Resize children
491
2/2
✓ Branch 0 taken 6968276 times.
✓ Branch 1 taken 6855595 times.
13823871 foreach ASTNode* child : this.children {
492 6855595 assert child != nil<ASTNode*>;
493 6855595 child.resizeToNumberOfManifestations(manifestationCount);
494 6855595 }
495 // Do custom work
496 6968276 customItemsInitialization(this, manifestationCount);
497 6968276 }
498
499 1283070 #[ignoreUnusedReturnValue]
500 1283070 public f<QualType> ASTExprNode.setEvaluatedSymbolType(const QualType& symbolType, unsigned long idx) {
501 1283070 assert this.symbolTypes.getSize() > idx;
502 1283070 QualType& slot = this.symbolTypes.get(idx);
503 1283070 slot = symbolType;
504 1283070 return symbolType;
505 }
506
507 958311 public f<const QualType&> ASTExprNode.getEvaluatedSymbolType(unsigned long idx) {
508
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 958311 times.
958311 if !this.symbolTypes.isEmpty() {
509 958311 const QualType& symbolType = this.symbolTypes.get(idx);
510
2/2
✓ Branch 0 taken 735833 times.
✓ Branch 1 taken 222478 times.
958311 if !symbolType.is(SuperType::TY_INVALID) {
511 735833 return symbolType;
512 }
513 222478 }
514
1/2
✓ Branch 0 taken 222478 times.
✗ Branch 1 not taken.
222478 if this.children.getSize() != 1l {
515 ✗ panic(Error("Cannot deduce evaluated symbol type"));
516 }
517 222478 ASTExprNode* expr = asExprNode(this.children.front());
518 222478 return expr.getEvaluatedSymbolType(idx);
519 }
520
521 /**
522 * Get the expression node base of an AST node. ASTExprNode composes ASTNode as its first member and has no interface, so
523 * both share the same address.
524 *
525 * @param node AST node, which must be an expression node
526 * @return Expression node base
527 */
528 5217233 public f<ASTExprNode*> asExprNode(ASTNode* node) {
529 5217233 assert node.isExprNode;
530 5217233 ASTExprNode* exprNode = nil<ASTExprNode*>;
531 unsafe {
532 5217233 exprNode = cast<ASTExprNode*>(node);
533 }
534 5217233 return exprNode;
535 }
536
537 /**
538 * Get the statement node base of an AST node. ASTStmtNode composes ASTNode as its first member and has no interface, so
539 * both share the same address.
540 *
541 * @param node AST node, which must be a statement node
542 * @return Statement node base
543 */
544 368741 public f<ASTStmtNode*> asStmtNode(ASTNode* node) {
545 368741 assert node.isStmtNode;
546 368741 ASTStmtNode* stmtNode = nil<ASTStmtNode*>;
547 unsafe {
548 368741 stmtNode = cast<ASTStmtNode*>(node);
549 }
550 368741 return stmtNode;
551 }
552
553 // The node types below are declared here, ahead of the top-level-def/stmt nodes that reference them,
554 // because Spice requires a struct/interface to be defined before use within the same file (no forward
555 // declarations). Each one is either a leaf (no struct-pointer fields of its own) or only references
556 // other nodes already defined above/within this same block.
557
558 // ========================================================== ConstantNode =======================================================
559
560 public type PrimitiveValueType enum {
561 TYPE_NONE,
562 TYPE_DOUBLE,
563 TYPE_INT,
564 TYPE_SHORT,
565 TYPE_LONG,
566 TYPE_CHAR,
567 TYPE_STRING,
568 TYPE_BOOL
569 }
570
571 77788 public type ASTConstantNode struct : IVisitable {
572 compose public ASTExprNode node
573 80964 public PrimitiveValueType primitiveValueType = PrimitiveValueType::TYPE_NONE
574 80964 public bool isUnsigned = false // Only set for integer literals with an 'u' suffix (e.g. 1u, 1us, 1ul)
575 public CompileTimeValue compileTimeValue
576 }
577
578 80964 public p ASTConstantNode.ctor(CodeLoc codeLoc) {
579 80964 this.node = ASTExprNode(codeLoc);
580 80964 this.kind = ASTNodeKind::CONSTANT;
581 80964 }
582 320783 public f<Any> ASTConstantNode.accept(IAbstractAstVisitor* visitor) {
583 320783 return visitor.visitConstant(this);
584 }
585
586 // ============================================================ AttrNode =========================================================
587
588 3409 public type ASTAttrNode struct : IVisitable {
589 compose public ASTNode node
590 public String key
591 // Defaults to TARGET_INVALID / TYPE_INVALID (both enum ordinal 0) without naming the enum value
592 // here: attributes.spice imports this file, so resolving AttrTarget::TARGET_INVALID as a field default
593 // can hit a 'used before declared' error depending on which file is the compile entry point.
594 public AttrTarget target
595 public AttrType attrType
596 3601 public ASTConstantNode* value = nil<ASTConstantNode*>
597 }
598
599 3601 public p ASTAttrNode.ctor(CodeLoc codeLoc) {
600 3601 this.node = ASTNode(codeLoc);
601 3601 this.kind = ASTNodeKind::ATTR;
602 3601 }
603 16262 public f<Any> ASTAttrNode.accept(IAbstractAstVisitor* visitor) {
604 16262 return visitor.visitAttr(this);
605 }
606
607 // Returns the attribute's compile-time value, or nil if it was declared without one (bool attributes
608 // default to 'true' when omitted; callers apply that default themselves).
609 2568 public f<const CompileTimeValue*> ASTAttrNode.getValue() {
610
2/2
✓ Branch 0 taken 2428 times.
✓ Branch 1 taken 140 times.
2568 if this.value == nil<ASTConstantNode*> {
611 140 return nil<const CompileTimeValue*>;
612 }
613 2428 return &this.value.compileTimeValue;
614 }
615
616 // ========================================================== AttrLstNode ========================================================
617
618 2943 public type ASTAttrLstNode struct : IVisitable {
619 compose public ASTNode node
620 public Vector<ASTAttrNode*> attributes
621 }
622
623 3135 public p ASTAttrLstNode.ctor(CodeLoc codeLoc) {
624 3135 this.node = ASTNode(codeLoc);
625 3135 this.kind = ASTNodeKind::ATTR_LST;
626 3135 }
627 13974 public f<Any> ASTAttrLstNode.accept(IAbstractAstVisitor* visitor) {
628 13974 return visitor.visitAttrLst(this);
629 }
630
631 12942 public f<bool> ASTAttrLstNode.hasAttr(const String& key) {
632
2/2
✓ Branch 0 taken 14822 times.
✓ Branch 1 taken 10679 times.
25501 foreach const ASTAttrNode* attr : this.attributes {
633
2/2
✓ Branch 0 taken 2263 times.
✓ Branch 1 taken 12559 times.
14822 if attr.key == key {
634 2263 return true;
635 }
636 12559 }
637 10679 return false;
638 }
639
640 // Returns the attribute's values by copy (CompileTimeValue is a small, trivially-copyable union), so
641 // there is no shared/static-storage lifetime to manage for the synthesized default-bool fallback below.
642 6742 public f<Vector<CompileTimeValue>> ASTAttrLstNode.getAttrValuesByName(const String& key) {
643 6742 Vector<CompileTimeValue> attributeValues;
644
2/2
✓ Branch 0 taken 8130 times.
✓ Branch 1 taken 6742 times.
14872 foreach const ASTAttrNode* attr : this.attributes {
645
2/2
✓ Branch 0 taken 5562 times.
✓ Branch 1 taken 2568 times.
8130 if attr.key != key {
646 5562 continue;
647 }
648 2568 const CompileTimeValue* value = attr.getValue();
649
2/2
✓ Branch 0 taken 2428 times.
✓ Branch 1 taken 140 times.
2568 if value == nil<const CompileTimeValue*> {
650 // Attribute given without a value defaults to boolValue = true (bool attributes only)
651 140 CompileTimeValue defaultValue;
652 140 defaultValue.setBoolValue(true);
653 140 attributeValues.pushBack(defaultValue);
654 140 } else {
655 2428 attributeValues.pushBack(*value);
656 2428 }
657 2568 }
658 6742 return attributeValues;
659 }
660
661 // Precondition: hasAttr(key) must be true (matches every call site in ImportCollector/SymbolTableBuilder,
662 // which always guard with hasAttr first).
663 2128 public f<CompileTimeValue> ASTAttrLstNode.getAttrValueByName(const String& key) {
664 2128 const Vector<CompileTimeValue> values = this.getAttrValuesByName(key);
665 2128 assert !values.isEmpty();
666 4256 return values.get(values.getSize() - 1l);
667 2128 }
668
669 // ========================================================= QualifierNode =======================================================
670
671 public type QualifierType enum {
672 NONE,
673 CONST,
674 SIGNED,
675 UNSIGNED,
676 INLINE,
677 PUBLIC,
678 HEAP,
679 COMPOSE
680 }
681
682 144515 public type ASTQualifierNode struct : IVisitable {
683 compose public ASTNode node
684 150594 public QualifierType qualifierType = QualifierType::NONE
685 }
686
687 150594 public p ASTQualifierNode.ctor(CodeLoc codeLoc) {
688 150594 this.node = ASTNode(codeLoc);
689 150594 this.kind = ASTNodeKind::QUALIFIER;
690 150594 }
691 316221 public f<Any> ASTQualifierNode.accept(IAbstractAstVisitor* visitor) {
692 316221 return visitor.visitQualifier(this);
693 }
694
695 // ======================================================== QualifierLstNode =====================================================
696
697 120515 public type ASTQualifierLstNode struct : IVisitable {
698 compose public ASTNode node
699 public Vector<ASTQualifierNode*> qualifiers
700 }
701
702 125596 public p ASTQualifierLstNode.ctor(CodeLoc codeLoc) {
703 125596 this.node = ASTNode(codeLoc);
704 125596 this.kind = ASTNodeKind::QUALIFIER_LST;
705 125596 }
706 266042 public f<Any> ASTQualifierLstNode.accept(IAbstractAstVisitor* visitor) {
707 266042 return visitor.visitQualifierLst(this);
708 }
709
710 // ======================================================= CustomDataTypeNode ====================================================
711
712 70639 public type ASTCustomDataTypeNode struct : IVisitable {
713 compose public ASTExprNode node
714 72874 public IVisitable* templateTypeLst = nil<IVisitable*>
715 public String fqTypeName
716 public Vector<String> typeNameFragments
717 }
718
719 72874 public p ASTCustomDataTypeNode.ctor(CodeLoc codeLoc) {
720 72874 this.node = ASTExprNode(codeLoc);
721 72874 this.kind = ASTNodeKind::CUSTOM_DATA_TYPE;
722 72874 }
723 251805 public f<Any> ASTCustomDataTypeNode.accept(IAbstractAstVisitor* visitor) {
724 251805 return visitor.visitCustomDataType(this);
725 }
726
727 // ======================================================== BaseDataTypeNode =====================================================
728
729 public type BaseDataTypeType enum {
730 TYPE_NONE,
731 TYPE_DOUBLE,
732 TYPE_INT,
733 TYPE_SHORT,
734 TYPE_LONG,
735 TYPE_BYTE,
736 TYPE_CHAR,
737 TYPE_STRING,
738 TYPE_BOOL,
739 TYPE_DYN,
740 TYPE_CUSTOM,
741 TYPE_FUNCTION
742 }
743
744 190729 public type ASTBaseDataTypeNode struct : IVisitable {
745 compose public ASTExprNode node
746 198426 public ASTCustomDataTypeNode* customDataType = nil<ASTCustomDataTypeNode*>
747 198426 public IVisitable* functionDataType = nil<IVisitable*>
748 198426 public BaseDataTypeType baseType = BaseDataTypeType::TYPE_NONE
749 }
750
751 198426 public p ASTBaseDataTypeNode.ctor(CodeLoc codeLoc) {
752 198426 this.node = ASTExprNode(codeLoc);
753 198426 this.kind = ASTNodeKind::BASE_DATA_TYPE;
754 198426 }
755 690088 public f<Any> ASTBaseDataTypeNode.accept(IAbstractAstVisitor* visitor) {
756 690088 return visitor.visitBaseDataType(this);
757 }
758
759 // ========================================================== DataTypeNode =======================================================
760
761 public type TypeModifierType enum {
762 TYPE_PTR,
763 TYPE_REF,
764 TYPE_ARRAY
765 }
766
767 613733 public type TypeModifier struct {
768 55225 public TypeModifierType modifierType = TypeModifierType::TYPE_PTR
769 55225 public bool hasSize = false
770 55225 public unsigned int hardcodedSize = 0
771 public String sizeVarName
772 }
773
774 55225 public p TypeModifier.ctor(TypeModifierType modifierType, bool hasSize, unsigned int hardcodedSize, const String& sizeVarName) {
775 55225 this.modifierType = modifierType;
776 55225 this.hasSize = hasSize;
777 55225 this.hardcodedSize = hardcodedSize;
778 55225 this.sizeVarName = sizeVarName;
779 55225 }
780
781 190729 public type ASTDataTypeNode struct : IVisitable {
782 compose public ASTExprNode node
783 198427 public ASTQualifierLstNode* qualifierLst = nil<ASTQualifierLstNode*>
784 198427 public ASTBaseDataTypeNode* baseDataType = nil<ASTBaseDataTypeNode*>
785 198427 public bool isParamType = false
786 198427 public bool isGlobalType = false
787 198427 public bool isFieldType = false
788 198427 public bool isReturnType = false
789 public Queue<TypeModifier> tmQueue
790 }
791
792 198427 public p ASTDataTypeNode.ctor(CodeLoc codeLoc) {
793 198427 this.node = ASTExprNode(codeLoc);
794 198427 this.kind = ASTNodeKind::DATA_TYPE;
795 198427 }
796 700136 public f<Any> ASTDataTypeNode.accept(IAbstractAstVisitor* visitor) {
797 700136 return visitor.visitDataType(this);
798 }
799
800 // ========================================================== TypeLstNode ========================================================
801
802 29618 public type ASTTypeLstNode struct : IVisitable {
803 compose public ASTNode node
804 public Vector<ASTDataTypeNode*> dataTypes
805 }
806
807 30564 public p ASTTypeLstNode.ctor(CodeLoc codeLoc) {
808 30564 this.node = ASTNode(codeLoc);
809 30564 this.kind = ASTNodeKind::TYPE_LST;
810 30564 }
811 69451 public f<Any> ASTTypeLstNode.accept(IAbstractAstVisitor* visitor) {
812 69451 return visitor.visitTypeLst(this);
813 }
814
815 // ======================================================== MainFctDefNode =======================================================
816
817 754 public type ASTMainFctDefNode struct : IVisitable {
818 compose public ASTTopLevelDefNode node
819
820 1034 public IVisitable* attrs = nil<IVisitable*>
821 1034 public IVisitable* paramLst = nil<IVisitable*>
822 1034 public IVisitable* body = nil<IVisitable*>
823 1034 public bool takesArgs = false
824 1034 public SymbolTableEntry* entry = nil<SymbolTableEntry*>
825 1034 public Scope* bodyScope = nil<Scope*>
826 }
827
828 1034 public p ASTMainFctDefNode.ctor(CodeLoc codeLoc) {
829 1034 this.node = ASTTopLevelDefNode(codeLoc);
830 1034 this.kind = ASTNodeKind::MAIN_FCT_DEF;
831 1034 }
832 5663 public f<Any> ASTMainFctDefNode.accept(IAbstractAstVisitor* visitor) {
833 5663 return visitor.visitMainFctDef(this);
834 }
835
836 1018 public f<String> ASTMainFctDefNode.getScopeId() {
837 1018 return String("fct:main");
838 }
839
840
841 // ========================================================= FctNameNode =========================================================
842
843 43805 public type ASTFctNameNode struct : IVisitable {
844 compose public ASTNode node
845
846 public String name
847 public String structName
848 public String fqName
849 public Vector<String> nameFragments
850 }
851
852 45763 public p ASTFctNameNode.ctor(CodeLoc codeLoc) {
853 45763 this.node = ASTNode(codeLoc);
854 45763 this.kind = ASTNodeKind::FCT_NAME;
855 45763 }
856 91714 public f<Any> ASTFctNameNode.accept(IAbstractAstVisitor* visitor) {
857 91714 return visitor.visitFctName(this);
858 }
859
860
861 // ======================================================== FctDefBaseNode =======================================================
862
863 43805 public type ASTFctDefBaseNode struct {
864 compose public ASTTopLevelDefNode node
865
866 45764 public IVisitable* attrs = nil<IVisitable*>
867 45764 public ASTQualifierLstNode* qualifierLst = nil<ASTQualifierLstNode*>
868 45764 public ASTFctNameNode* name = nil<ASTFctNameNode*>
869 45764 public bool isMethod = false
870 45764 public bool hasTemplateTypes = false
871 45764 public bool hasParams = false
872 public TypeQualifiers qualifiers
873 45764 public ASTTypeLstNode* templateTypeLst = nil<ASTTypeLstNode*>
874 public Vector<Function*> manifestations
875 45764 public IVisitable* paramLst = nil<IVisitable*>
876 45764 public IVisitable* body = nil<IVisitable*>
877 45764 public SymbolTableEntry* entry = nil<SymbolTableEntry*>
878 45764 public Scope* structScope = nil<Scope*>
879 45764 public Scope* scope = nil<Scope*>
880 }
881
882 45764 public p ASTFctDefBaseNode.ctor(CodeLoc codeLoc) {
883 45764 this.node = ASTTopLevelDefNode(codeLoc);
884 45764 this.qualifiers = getTypeQualifiersOf(SuperType::TY_FUNCTION);
885 45764 }
886
887 45687 public f<String> ASTFctDefBaseNode.getSymbolTableEntryName() {
888 91374 return this.name.name + ":" + this.codeLoc.toString();
889 45687 }
890
891 // ========================================================== FctDefNode =========================================================
892
893 26986 public type ASTFctDefNode struct : IVisitable {
894 compose public ASTFctDefBaseNode node
895
896 28114 public ASTDataTypeNode* returnType = nil<ASTDataTypeNode*>
897 }
898
899 28114 public p ASTFctDefNode.ctor(CodeLoc codeLoc) {
900 28114 this.node = ASTFctDefBaseNode(codeLoc);
901 28114 this.kind = ASTNodeKind::FCT_DEF;
902 28114 }
903 201287 public f<Any> ASTFctDefNode.accept(IAbstractAstVisitor* visitor) {
904 201287 return visitor.visitFctDef(this);
905 }
906
907 56202 public f<String> ASTFctDefNode.getScopeId() {
908 112404 return String("fct:") + this.codeLoc.toString();
909 56202 }
910
911
912 // ========================================================== ProcDefNode ========================================================
913
914 16819 public type ASTProcDefNode struct : IVisitable {
915 compose public ASTFctDefBaseNode node
916
917 17650 public bool isCtor = false
918 }
919
920 17650 public p ASTProcDefNode.ctor(CodeLoc codeLoc) {
921 17650 this.node = ASTFctDefBaseNode(codeLoc);
922 17650 this.kind = ASTNodeKind::PROC_DEF;
923 17650 }
924 127017 public f<Any> ASTProcDefNode.accept(IAbstractAstVisitor* visitor) {
925 127017 return visitor.visitProcDef(this);
926 }
927
928 35269 public f<String> ASTProcDefNode.getScopeId() {
929 70538 return String("proc:") + this.codeLoc.toString();
930 35269 }
931
932
933 // ========================================================= StructDefNode =======================================================
934
935 3001 public type ASTStructDefNode struct : IVisitable {
936 compose public ASTTopLevelDefNode node
937
938 3233 public IVisitable* attrs = nil<IVisitable*>
939 public String structName
940 3233 public bool hasTemplateTypes = false
941 3233 public bool hasInterfaces = false
942 3233 public ASTTypeLstNode* templateTypeLst = nil<ASTTypeLstNode*>
943 3233 public ASTTypeLstNode* interfaceTypeLst = nil<ASTTypeLstNode*>
944 3233 public bool emitVTable = false
945 public Vector<Struct*> structManifestations
946 public UnorderedMap<String, Vector<Function*>> defaultFctManifestations
947 public Vector<IVisitable*> fields
948 3233 public ASTQualifierLstNode* qualifierLst = nil<ASTQualifierLstNode*>
949 public TypeQualifiers qualifiers
950 3233 public SymbolTableEntry* entry = nil<SymbolTableEntry*>
951 public unsigned long typeId
952 3233 public Scope* structScope = nil<Scope*>
953 }
954
955 3233 public p ASTStructDefNode.ctor(CodeLoc codeLoc) {
956 3233 this.node = ASTTopLevelDefNode(codeLoc);
957 3233 this.qualifiers = getTypeQualifiersOf(SuperType::TY_STRUCT);
958 3233 this.kind = ASTNodeKind::STRUCT_DEF;
959 3233 }
960 21877 public f<Any> ASTStructDefNode.accept(IAbstractAstVisitor* visitor) {
961 21877 return visitor.visitStructDef(this);
962 }
963
964
965 // ======================================================== InterfaceDefNode =====================================================
966
967 295 public type ASTInterfaceDefNode struct : IVisitable {
968 compose public ASTTopLevelDefNode node
969
970 327 public IVisitable* attrs = nil<IVisitable*>
971 public String interfaceName
972 327 public bool hasTemplateTypes = false
973 327 public ASTTypeLstNode* templateTypeLst = nil<ASTTypeLstNode*>
974 public Vector<IVisitable*> signatures
975 public Vector<Interface*> interfaceManifestations
976 327 public ASTQualifierLstNode* qualifierLst = nil<ASTQualifierLstNode*>
977 public TypeQualifiers qualifiers
978 327 public SymbolTableEntry* entry = nil<SymbolTableEntry*>
979 public unsigned long typeId
980 327 public Scope* interfaceScope = nil<Scope*>
981 }
982
983 327 public p ASTInterfaceDefNode.ctor(CodeLoc codeLoc) {
984 327 this.node = ASTTopLevelDefNode(codeLoc);
985 327 this.qualifiers = getTypeQualifiersOf(SuperType::TY_INTERFACE);
986 327 this.kind = ASTNodeKind::INTERFACE_DEF;
987 327 }
988 1918 public f<Any> ASTInterfaceDefNode.accept(IAbstractAstVisitor* visitor) {
989 1918 return visitor.visitInterfaceDef(this);
990 }
991
992
993 // ========================================================== UnionDefNode =======================================================
994
995 17 public type ASTUnionDefNode struct : IVisitable {
996 compose public ASTTopLevelDefNode node
997
998 26 public IVisitable* attrs = nil<IVisitable*>
999 public String unionName
1000 26 public bool hasTemplateTypes = false
1001 26 public ASTTypeLstNode* templateTypeLst = nil<ASTTypeLstNode*>
1002 public Vector<IVisitable*> fields
1003 public Vector<Union*> unionManifestations
1004 26 public ASTQualifierLstNode* qualifierLst = nil<ASTQualifierLstNode*>
1005 public TypeQualifiers qualifiers
1006 26 public SymbolTableEntry* entry = nil<SymbolTableEntry*>
1007 public unsigned long typeId
1008 26 public Scope* unionScope = nil<Scope*>
1009 }
1010
1011 26 public p ASTUnionDefNode.ctor(CodeLoc codeLoc) {
1012 26 this.node = ASTTopLevelDefNode(codeLoc);
1013 26 this.qualifiers = getTypeQualifiersOf(SuperType::TY_UNION);
1014 26 this.kind = ASTNodeKind::UNION_DEF;
1015 26 }
1016 130 public f<Any> ASTUnionDefNode.accept(IAbstractAstVisitor* visitor) {
1017 130 return visitor.visitUnionDef(this);
1018 }
1019
1020
1021 // ========================================================== EnumDefNode ========================================================
1022
1023 437 public type ASTEnumDefNode struct : IVisitable {
1024 compose public ASTTopLevelDefNode node
1025
1026 public String enumName
1027 466 public IVisitable* itemLst = nil<IVisitable*>
1028 466 public ASTQualifierLstNode* qualifierLst = nil<ASTQualifierLstNode*>
1029 public TypeQualifiers qualifiers
1030 466 public SymbolTableEntry* entry = nil<SymbolTableEntry*>
1031 public unsigned long typeId
1032 466 public Scope* enumScope = nil<Scope*>
1033 }
1034
1035 466 public p ASTEnumDefNode.ctor(CodeLoc codeLoc) {
1036 466 this.node = ASTTopLevelDefNode(codeLoc);
1037 466 this.qualifiers = getTypeQualifiersOf(SuperType::TY_ENUM);
1038 466 this.kind = ASTNodeKind::ENUM_DEF;
1039 466 }
1040 3188 public f<Any> ASTEnumDefNode.accept(IAbstractAstVisitor* visitor) {
1041 3188 return visitor.visitEnumDef(this);
1042 }
1043
1044
1045 // ======================================================= GenericTypeDefNode ====================================================
1046
1047 2909 public type ASTGenericTypeDefNode struct : IVisitable {
1048 compose public ASTTopLevelDefNode node
1049
1050 public String typeName
1051 3071 public IVisitable* typeAltsLst = nil<IVisitable*>
1052 3071 public SymbolTableEntry* entry = nil<SymbolTableEntry*>
1053 }
1054
1055 3071 public p ASTGenericTypeDefNode.ctor(CodeLoc codeLoc) {
1056 3071 this.node = ASTTopLevelDefNode(codeLoc);
1057 3071 this.kind = ASTNodeKind::GENERIC_TYPE_DEF;
1058 3071 }
1059 21892 public f<Any> ASTGenericTypeDefNode.accept(IAbstractAstVisitor* visitor) {
1060 21892 return visitor.visitGenericTypeDef(this);
1061 }
1062
1063
1064 // ========================================================== AliasDefNode =======================================================
1065
1066 153 public type ASTAliasDefNode struct : IVisitable {
1067 compose public ASTTopLevelDefNode node
1068
1069 159 public ASTQualifierLstNode* qualifierLst = nil<ASTQualifierLstNode*>
1070 public TypeQualifiers qualifiers
1071 public String aliasName
1072 public String dataTypeString
1073 159 public ASTDataTypeNode* dataType = nil<ASTDataTypeNode*>
1074 public unsigned long typeId
1075 159 public SymbolTableEntry* entry = nil<SymbolTableEntry*>
1076 159 public SymbolTableEntry* aliasedTypeContainerEntry = nil<SymbolTableEntry*>
1077 }
1078
1079 159 public p ASTAliasDefNode.ctor(CodeLoc codeLoc) {
1080 159 this.node = ASTTopLevelDefNode(codeLoc);
1081 159 this.qualifiers = getTypeQualifiersOf(SuperType::TY_ALIAS);
1082 159 this.kind = ASTNodeKind::ALIAS_DEF;
1083 159 }
1084 1029 public f<Any> ASTAliasDefNode.accept(IAbstractAstVisitor* visitor) {
1085 1029 return visitor.visitAliasDef(this);
1086 }
1087
1088
1089 // ======================================================== GlobalVarDefNode =====================================================
1090
1091 4205 public type ASTGlobalVarDefNode struct : IVisitable {
1092 compose public ASTTopLevelDefNode node
1093
1094 public String varName
1095 4289 public ASTDataTypeNode* dataType = nil<ASTDataTypeNode*>
1096 4289 public ASTConstantNode* constant = nil<ASTConstantNode*>
1097 4289 public bool hasValue = false
1098 4289 public SymbolTableEntry* entry = nil<SymbolTableEntry*>
1099 }
1100
1101 4289 public p ASTGlobalVarDefNode.ctor(CodeLoc codeLoc) {
1102 4289 this.node = ASTTopLevelDefNode(codeLoc);
1103 4289 this.kind = ASTNodeKind::GLOBAL_VAR_DEF;
1104 4289 }
1105 27729 public f<Any> ASTGlobalVarDefNode.accept(IAbstractAstVisitor* visitor) {
1106 27729 return visitor.visitGlobalVarDef(this);
1107 }
1108
1109
1110 // ========================================================== ExtDeclNode ========================================================
1111
1112 5041 public type ASTExtDeclNode struct : IVisitable {
1113 compose public ASTTopLevelDefNode node
1114
1115 5229 public IVisitable* attrs = nil<IVisitable*>
1116 public String extFunctionName
1117 5229 public ASTDataTypeNode* returnType = nil<ASTDataTypeNode*>
1118 5229 public IVisitable* argTypeLst = nil<IVisitable*>
1119 5229 public bool hasArgs = false
1120 5229 public Function* extFunction = nil<Function*>
1121 public Vector<Function*> extFunctionManifestations
1122 5229 public bool hasReturnType = false
1123 5229 public SymbolTableEntry* entry = nil<SymbolTableEntry*>
1124 }
1125
1126 5229 public p ASTExtDeclNode.ctor(CodeLoc codeLoc) {
1127 5229 this.node = ASTTopLevelDefNode(codeLoc);
1128 5229 this.kind = ASTNodeKind::EXT_DECL;
1129 5229 }
1130 37751 public f<Any> ASTExtDeclNode.accept(IAbstractAstVisitor* visitor) {
1131 37751 return visitor.visitExtDecl(this);
1132 }
1133
1134 10453 public f<String> ASTExtDeclNode.getScopeId() {
1135
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10453 times.
10453 return (this.hasReturnType ? String("func:") : String("proc:")) + this.codeLoc.toString();
1136 10453 }
1137
1138
1139 // ========================================================= ImportDefNode =======================================================
1140
1141 2407 public type ASTImportDefNode struct : IVisitable {
1142 compose public ASTTopLevelDefNode node
1143
1144 public String importPath
1145 public String importName
1146 2518 public SymbolTableEntry* entry = nil<SymbolTableEntry*>
1147 }
1148
1149 2518 public p ASTImportDefNode.ctor(CodeLoc codeLoc) {
1150 2518 this.node = ASTTopLevelDefNode(codeLoc);
1151 2518 this.kind = ASTNodeKind::IMPORT_DEF;
1152 2518 }
1153 19561 public f<Any> ASTImportDefNode.accept(IAbstractAstVisitor* visitor) {
1154 19561 return visitor.visitImportDef(this);
1155 }
1156
1157
1158 // ========================================================== UnsafeBlockNode ========================================================
1159
1160 12164 public type ASTUnsafeBlockNode struct : IVisitable {
1161 compose public ASTStmtNode node
1162
1163 12758 public IVisitable* body = nil<IVisitable*>
1164 12758 public Scope* bodyScope = nil<Scope*>
1165 }
1166
1167 12758 public p ASTUnsafeBlockNode.ctor(CodeLoc codeLoc) {
1168 12758 this.node = ASTStmtNode(codeLoc);
1169 12758 this.kind = ASTNodeKind::UNSAFE_BLOCK;
1170 12758 }
1171 62743 public f<Any> ASTUnsafeBlockNode.accept(IAbstractAstVisitor* visitor) {
1172 62743 return visitor.visitUnsafeBlock(this);
1173 }
1174
1175 37316 public f<String> ASTUnsafeBlockNode.getScopeId() {
1176 74632 return String("unsafe:") + this.codeLoc.toString();
1177 37316 }
1178
1179
1180 // ============================================================ Cleanup ==========================================================
1181
1182 263671 public type ResourcesForManifestationToCleanup struct {
1183 public Vector<Pair<SymbolTableEntry*, Function*>> dtorFunctionsToCall
1184 public Vector<SymbolTableEntry*> heapVarsToFree
1185 }
1186
1187 // ========================================================== ForLoopNode ========================================================
1188
1189 4222 public type ASTForLoopNode struct : IVisitable {
1190 compose public ASTStmtNode node
1191
1192 4405 public IVisitable* initDecl = nil<IVisitable*>
1193 4405 public IVisitable* condAssign = nil<IVisitable*>
1194 4405 public IVisitable* incAssign = nil<IVisitable*>
1195 4405 public IVisitable* body = nil<IVisitable*>
1196 4405 public Scope* headScope = nil<Scope*>
1197 4405 public Scope* bodyScope = nil<Scope*>
1198 public Vector<ResourcesForManifestationToCleanup> headResourcesToCleanup
1199 }
1200
1201 4405 public p ASTForLoopNode.ctor(CodeLoc codeLoc) {
1202 4405 this.node = ASTStmtNode(codeLoc);
1203 4405 this.kind = ASTNodeKind::FOR_LOOP;
1204 4405 }
1205 23416 public f<Any> ASTForLoopNode.accept(IAbstractAstVisitor* visitor) {
1206 23416 return visitor.visitForLoop(this);
1207 }
1208
1209 14698 public f<String> ASTForLoopNode.getScopeId() {
1210 29396 return String("for:") + this.codeLoc.toString();
1211 14698 }
1212
1213 14697 public f<String> ASTForLoopNode.getBodyScopeId() {
1214 29394 return String("for-body:") + this.codeLoc.toString();
1215 14697 }
1216
1217
1218 // ======================================================== ForeachLoopNode ======================================================
1219
1220 // Functions, that a foreach loop calls. They depend on the iterator type, so they are resolved once per manifestation
1221 public type ForeachLoopData struct {
1222 public Function* getIteratorFct = nil<Function*>
1223 public Function* getFct = nil<Function*>
1224 public Function* getIdxFct = nil<Function*>
1225 public Function* isValidFct = nil<Function*>
1226 public Function* nextFct = nil<Function*>
1227 public Function* calledItemCopyCtor = nil<Function*>
1228 }
1229
1230 428 public type ASTForeachLoopNode struct : IVisitable {
1231 compose public ASTStmtNode node
1232
1233 435 public IVisitable* idxVarDecl = nil<IVisitable*>
1234 435 public IVisitable* itemVarDecl = nil<IVisitable*>
1235 435 public IVisitable* iteratorAssign = nil<IVisitable*>
1236 435 public IVisitable* body = nil<IVisitable*>
1237 435 public Scope* headScope = nil<Scope*>
1238 435 public Scope* bodyScope = nil<Scope*>
1239 public Vector<ResourcesForManifestationToCleanup> headResourcesToCleanup
1240 public Vector<ForeachLoopData> data
1241 }
1242
1243 435 public p ASTForeachLoopNode.ctor(CodeLoc codeLoc) {
1244 435 this.node = ASTStmtNode(codeLoc);
1245 435 this.kind = ASTNodeKind::FOREACH_LOOP;
1246 435 }
1247 2185 public f<Any> ASTForeachLoopNode.accept(IAbstractAstVisitor* visitor) {
1248 2185 return visitor.visitForeachLoop(this);
1249 }
1250
1251 1318 public f<String> ASTForeachLoopNode.getScopeId() {
1252 2636 return String("foreach:") + this.codeLoc.toString();
1253 1318 }
1254
1255 1315 public f<String> ASTForeachLoopNode.getBodyScopeId() {
1256 2630 return String("foreach-body:") + this.codeLoc.toString();
1257 1315 }
1258
1259
1260 // ========================================================= WhileLoopNode =======================================================
1261
1262 1796 public type ASTWhileLoopNode struct : IVisitable {
1263 compose public ASTStmtNode node
1264
1265 1865 public IVisitable* condition = nil<IVisitable*>
1266 1865 public IVisitable* body = nil<IVisitable*>
1267 1865 public Scope* bodyScope = nil<Scope*>
1268 }
1269
1270 1865 public p ASTWhileLoopNode.ctor(CodeLoc codeLoc) {
1271 1865 this.node = ASTStmtNode(codeLoc);
1272 1865 this.kind = ASTNodeKind::WHILE_LOOP;
1273 1865 }
1274 9219 public f<Any> ASTWhileLoopNode.accept(IAbstractAstVisitor* visitor) {
1275 9219 return visitor.visitWhileLoop(this);
1276 }
1277
1278 5537 public f<String> ASTWhileLoopNode.getScopeId() {
1279 11074 return String("while:") + this.codeLoc.toString();
1280 5537 }
1281
1282
1283 // ======================================================== DoWhileLoopNode ======================================================
1284
1285 49 public type ASTDoWhileLoopNode struct : IVisitable {
1286 compose public ASTStmtNode node
1287
1288 50 public IVisitable* condition = nil<IVisitable*>
1289 50 public IVisitable* body = nil<IVisitable*>
1290 50 public Scope* bodyScope = nil<Scope*>
1291 }
1292
1293 50 public p ASTDoWhileLoopNode.ctor(CodeLoc codeLoc) {
1294 50 this.node = ASTStmtNode(codeLoc);
1295 50 this.kind = ASTNodeKind::DO_WHILE_LOOP;
1296 50 }
1297 312 public f<Any> ASTDoWhileLoopNode.accept(IAbstractAstVisitor* visitor) {
1298 312 return visitor.visitDoWhileLoop(this);
1299 }
1300
1301 213 public f<String> ASTDoWhileLoopNode.getScopeId() {
1302 426 return String("dowhile:") + this.codeLoc.toString();
1303 213 }
1304
1305
1306 // ========================================================== IfStmtNode ========================================================
1307
1308 24177 public type ASTIfStmtNode struct : IVisitable {
1309 compose public ASTStmtNode node
1310
1311 public Vector<bool> compileThenBranch
1312 public Vector<bool> compileElseBranch
1313 25175 public IVisitable* condition = nil<IVisitable*>
1314 25175 public IVisitable* thenBody = nil<IVisitable*>
1315 25175 public Scope* thenBodyScope = nil<Scope*>
1316 25175 public IVisitable* elseStmt = nil<IVisitable*>
1317 }
1318
1319 25175 public p ASTIfStmtNode.ctor(CodeLoc codeLoc) {
1320 25175 this.node = ASTStmtNode(codeLoc);
1321 25175 this.kind = ASTNodeKind::IF_STMT;
1322 25175 }
1323 47549 public f<bool> ASTIfStmtNode.doCompileThenBranch(unsigned long manIdx) {
1324
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47549 times.
47549 return this.compileThenBranch.isEmpty() || this.compileThenBranch.get(manIdx);
1325 }
1326 47549 public f<bool> ASTIfStmtNode.doCompileElseBranch(unsigned long manIdx) {
1327
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47549 times.
47549 return this.compileElseBranch.isEmpty() || this.compileElseBranch.get(manIdx);
1328 }
1329 129787 public f<Any> ASTIfStmtNode.accept(IAbstractAstVisitor* visitor) {
1330 129787 return visitor.visitIfStmt(this);
1331 }
1332
1333 79281 public f<String> ASTIfStmtNode.getScopeId() {
1334 158562 return String("if:") + this.codeLoc.toString();
1335 79281 }
1336
1337
1338 // ========================================================== ElseStmtNode =======================================================
1339
1340 1392 public type ASTElseStmtNode struct : IVisitable {
1341 compose public ASTStmtNode node
1342
1343 1397 public bool isElseIf = false
1344 1397 public IVisitable* ifStmt = nil<IVisitable*>
1345 1397 public IVisitable* body = nil<IVisitable*>
1346 1397 public Scope* elseBodyScope = nil<Scope*>
1347 }
1348
1349 1397 public p ASTElseStmtNode.ctor(CodeLoc codeLoc) {
1350 1397 this.node = ASTStmtNode(codeLoc);
1351 1397 this.kind = ASTNodeKind::ELSE_STMT;
1352 1397 }
1353 6875 public f<Any> ASTElseStmtNode.accept(IAbstractAstVisitor* visitor) {
1354 6875 return visitor.visitElseStmt(this);
1355 }
1356
1357 2348 public f<String> ASTElseStmtNode.getScopeId() {
1358 4696 return String("if:") + this.codeLoc.toString();
1359 2348 }
1360
1361
1362 // ========================================================= SwitchStmtNode ======================================================
1363
1364 30 public type ASTSwitchStmtNode struct : IVisitable {
1365 compose public ASTStmtNode node
1366
1367 39 public IVisitable* assignExpr = nil<IVisitable*>
1368 public Vector<IVisitable*> caseBranches
1369 39 public IVisitable* defaultBranch = nil<IVisitable*>
1370 39 public bool hasDefaultBranch = false
1371 39 public bool coversAllEnumItems = false
1372 }
1373
1374 39 public p ASTSwitchStmtNode.ctor(CodeLoc codeLoc) {
1375 39 this.node = ASTStmtNode(codeLoc);
1376 39 this.kind = ASTNodeKind::SWITCH_STMT;
1377 39 }
1378 175 public f<Any> ASTSwitchStmtNode.accept(IAbstractAstVisitor* visitor) {
1379 175 return visitor.visitSwitchStmt(this);
1380 }
1381
1382
1383 // ========================================================= CaseBranchNode ======================================================
1384
1385 183 public type ASTCaseBranchNode struct : IVisitable {
1386 compose public ASTNode node
1387
1388 public Vector<IVisitable*> caseConstants
1389 196 public IVisitable* body = nil<IVisitable*>
1390 196 public Scope* bodyScope = nil<Scope*>
1391 }
1392
1393 196 public p ASTCaseBranchNode.ctor(CodeLoc codeLoc) {
1394 196 this.node = ASTNode(codeLoc);
1395 196 this.kind = ASTNodeKind::CASE_BRANCH;
1396 196 }
1397 962 public f<Any> ASTCaseBranchNode.accept(IAbstractAstVisitor* visitor) {
1398 962 return visitor.visitCaseBranch(this);
1399 }
1400
1401 569 public f<String> ASTCaseBranchNode.getScopeId() {
1402 1138 return String("case:") + this.codeLoc.toString();
1403 569 }
1404
1405
1406 // ======================================================== DefaultBranchNode ====================================================
1407
1408 18 public type ASTDefaultBranchNode struct : IVisitable {
1409 compose public ASTNode node
1410
1411 20 public IVisitable* body = nil<IVisitable*>
1412 20 public Scope* bodyScope = nil<Scope*>
1413 }
1414
1415 20 public p ASTDefaultBranchNode.ctor(CodeLoc codeLoc) {
1416 20 this.node = ASTNode(codeLoc);
1417 20 this.kind = ASTNodeKind::DEFAULT_BRANCH;
1418 20 }
1419 99 public f<Any> ASTDefaultBranchNode.accept(IAbstractAstVisitor* visitor) {
1420 99 return visitor.visitDefaultBranch(this);
1421 }
1422
1423 58 public f<String> ASTDefaultBranchNode.getScopeId() {
1424 116 return String("default:") + this.codeLoc.toString();
1425 58 }
1426
1427
1428 // ===================================================== AnonymousBlockStmtNode ==================================================
1429
1430 126 public type ASTAnonymousBlockStmtNode struct : IVisitable {
1431 compose public ASTStmtNode node
1432
1433 126 public IVisitable* body = nil<IVisitable*>
1434 126 public Scope* bodyScope = nil<Scope*>
1435 }
1436
1437 126 public p ASTAnonymousBlockStmtNode.ctor(CodeLoc codeLoc) {
1438 126 this.node = ASTStmtNode(codeLoc);
1439 126 this.kind = ASTNodeKind::ANONYMOUS_BLOCK_STMT;
1440 126 }
1441 630 public f<Any> ASTAnonymousBlockStmtNode.accept(IAbstractAstVisitor* visitor) {
1442 630 return visitor.visitAnonymousBlockStmt(this);
1443 }
1444
1445 378 public f<String> ASTAnonymousBlockStmtNode.getScopeId() {
1446 756 return String("anon:") + this.codeLoc.toString();
1447 378 }
1448
1449
1450 // ========================================================== StmtLstNode ========================================================
1451
1452 88684 public type ASTStmtLstNode struct : IVisitable {
1453 compose public ASTNode node
1454 public Vector<IVisitable*> statements
1455 public CodeLoc closingBraceCodeLoc
1456 public Vector<ResourcesForManifestationToCleanup> resourcesToCleanup
1457 }
1458
1459 92800 public p ASTStmtLstNode.ctor(CodeLoc codeLoc) {
1460 92800 this.node = ASTNode(codeLoc);
1461 92800 this.kind = ASTNodeKind::STMT_LST;
1462 92800 }
1463 463604 public f<Any> ASTStmtLstNode.accept(IAbstractAstVisitor* visitor) {
1464 463604 return visitor.visitStmtLst(this);
1465 }
1466
1467
1468 // ==================================================== TypeLstWithEllipsisNode ==================================================
1469
1470 4970 public type ASTTypeLstWithEllipsisNode struct : IVisitable {
1471 compose public ASTNode node
1472
1473 5157 public ASTTypeLstNode* typeLst = nil<ASTTypeLstNode*>
1474 5157 public bool hasEllipsis = false
1475 }
1476
1477 5157 public p ASTTypeLstWithEllipsisNode.ctor(CodeLoc codeLoc) {
1478 5157 this.node = ASTNode(codeLoc);
1479 5157 this.kind = ASTNodeKind::TYPE_LST_WITH_ELLIPSIS;
1480 5157 }
1481 10489 public f<Any> ASTTypeLstWithEllipsisNode.accept(IAbstractAstVisitor* visitor) {
1482 10489 return visitor.visitTypeLstWithEllipsis(this);
1483 }
1484
1485
1486 // ======================================================== TypeAltsLstNode ======================================================
1487
1488 2909 public type ASTTypeAltsLstNode struct : IVisitable {
1489 compose public ASTNode node
1490
1491 public Vector<ASTDataTypeNode*> dataTypes
1492 }
1493
1494 3071 public p ASTTypeAltsLstNode.ctor(CodeLoc codeLoc) {
1495 3071 this.node = ASTNode(codeLoc);
1496 3071 this.kind = ASTNodeKind::TYPE_ALTS_LST;
1497 3071 }
1498 6159 public f<Any> ASTTypeAltsLstNode.accept(IAbstractAstVisitor* visitor) {
1499 6159 return visitor.visitTypeAltsLst(this);
1500 }
1501
1502
1503 // ========================================================== DeclStmtNode =======================================================
1504 // Declared before ParamLstNode (which composes a Vector<ASTDeclStmtNode*> below) since parseParamLst
1505 // back-annotates each param's 'isFctParam' field directly (not via dispatch), so the list needs to stay
1506 // concretely typed, which in turn needs DeclStmtNode defined first (same-file ordering rule).
1507
1508 // Ctors, that a declaration calls. They depend on the type of the variable, so they are resolved once per manifestation
1509 public type DeclStmtData struct {
1510 public bool isCtorCallRequired = false // For struct, in case there are reference fields, we need to call a user-defined ctor
1511 public Function* calledInitCtor = nil<Function*>
1512 public Function* calledCopyCtor = nil<Function*>
1513 }
1514
1515 80206 public type ASTDeclStmtNode struct : IVisitable {
1516 compose public ASTStmtNode node
1517
1518 public String varName
1519 83812 public ASTDataTypeNode* dataType = nil<ASTDataTypeNode*>
1520 83812 public bool hasAssignment = false
1521 83812 public IVisitable* assignExpr = nil<IVisitable*>
1522 83812 public bool isFctParam = false
1523 83812 public bool isForEachItem = false
1524 public Vector<SymbolTableEntry*> entries
1525 public Vector<DeclStmtData> data
1526 }
1527
1528 83812 public p ASTDeclStmtNode.ctor(CodeLoc codeLoc) {
1529 83812 this.node = ASTStmtNode(codeLoc);
1530 83812 this.kind = ASTNodeKind::DECL_STMT;
1531 83812 }
1532 373358 public f<Any> ASTDeclStmtNode.accept(IAbstractAstVisitor* visitor) {
1533 373358 return visitor.visitDeclStmt(this);
1534 }
1535
1536
1537 // ========================================================== ParamLstNode =======================================================
1538
1539 31772 public type ASTParamLstNode struct : IVisitable {
1540 compose public ASTNode node
1541 public Vector<ASTDeclStmtNode*> params
1542 }
1543
1544 33175 public p ASTParamLstNode.ctor(CodeLoc codeLoc) {
1545 33175 this.node = ASTNode(codeLoc);
1546 33175 this.kind = ASTNodeKind::PARAM_LST;
1547 33175 }
1548 164909 public f<Any> ASTParamLstNode.accept(IAbstractAstVisitor* visitor) {
1549 164909 return visitor.visitParamLst(this);
1550 }
1551
1552
1553 // =========================================================== ArgLstNode ========================================================
1554
1555 public type ArgInfo struct {
1556 public Function* copyCtor = nil<Function*>
1557 }
1558
1559 59513 public type ASTArgLstNode struct : IVisitable {
1560 compose public ASTNode node
1561
1562 public Vector<IVisitable*> args
1563 public Vector<Vector<ArgInfo>> argInfos // Per manifestation, since the copy ctors depend on the argument types
1564 }
1565
1566 61637 public p ASTArgLstNode.ctor(CodeLoc codeLoc) {
1567 61637 this.node = ASTNode(codeLoc);
1568 61637 this.kind = ASTNodeKind::ARG_LST;
1569 61637 }
1570 185775 public f<Any> ASTArgLstNode.accept(IAbstractAstVisitor* visitor) {
1571 185775 return visitor.visitArgLst(this);
1572 }
1573
1574
1575 // ========================================================== EnumItemNode =======================================================
1576 // Declared before EnumItemLstNode (which composes a Vector<ASTEnumItemNode*> below) since parseEnumDef
1577 // back-links each item's 'enumDef' field directly (not via dispatch), so the list needs to stay
1578 // concretely typed, which in turn needs EnumItemNode defined first (same-file ordering rule).
1579
1580 1686 public type ASTEnumItemNode struct : IVisitable {
1581 compose public ASTNode node
1582
1583 public String itemName
1584 1749 public bool hasValue = false
1585 public unsigned int itemValue
1586 1749 public ASTEnumDefNode* enumDef = nil<ASTEnumDefNode*>
1587 }
1588
1589 1749 public p ASTEnumItemNode.ctor(CodeLoc codeLoc) {
1590 1749 this.node = ASTNode(codeLoc);
1591 1749 this.kind = ASTNodeKind::ENUM_ITEM;
1592 1749 }
1593 3466 public f<Any> ASTEnumItemNode.accept(IAbstractAstVisitor* visitor) {
1594 3466 return visitor.visitEnumItem(this);
1595 }
1596
1597
1598 // ======================================================== EnumItemLstNode ======================================================
1599
1600 437 public type ASTEnumItemLstNode struct : IVisitable {
1601 compose public ASTNode node
1602 public Vector<ASTEnumItemNode*> items
1603 }
1604
1605 466 public p ASTEnumItemLstNode.ctor(CodeLoc codeLoc) {
1606 466 this.node = ASTNode(codeLoc);
1607 466 this.kind = ASTNodeKind::ENUM_ITEM_LST;
1608 466 }
1609 1373 public f<Any> ASTEnumItemLstNode.accept(IAbstractAstVisitor* visitor) {
1610 1373 return visitor.visitEnumItemLst(this);
1611 }
1612
1613
1614 // =========================================================== FieldNode =========================================================
1615
1616 7411 public type ASTFieldNode struct : IVisitable {
1617 compose public ASTNode node
1618 public String fieldName
1619 7861 public ASTDataTypeNode* dataType = nil<ASTDataTypeNode*>
1620 7861 public IVisitable* defaultValue = nil<IVisitable*>
1621 }
1622
1623 7861 public p ASTFieldNode.ctor(CodeLoc codeLoc) {
1624 7861 this.node = ASTNode(codeLoc);
1625 7861 this.kind = ASTNodeKind::FIELD;
1626 7861 }
1627 31265 public f<Any> ASTFieldNode.accept(IAbstractAstVisitor* visitor) {
1628 31265 return visitor.visitField(this);
1629 }
1630
1631
1632 // ========================================================= SignatureNode =======================================================
1633
1634 public type SignatureType enum {
1635 TYPE_NONE,
1636 TYPE_FUNCTION,
1637 TYPE_PROCEDURE
1638 }
1639
1640 694 public type ASTSignatureNode struct : IVisitable {
1641 compose public ASTNode node
1642
1643 749 public ASTQualifierLstNode* qualifierLst = nil<ASTQualifierLstNode*>
1644 749 public ASTDataTypeNode* returnType = nil<ASTDataTypeNode*>
1645 749 public ASTTypeLstNode* templateTypeLst = nil<ASTTypeLstNode*>
1646 749 public ASTTypeLstNode* paramTypeLst = nil<ASTTypeLstNode*>
1647 749 public bool hasReturnType = false
1648 749 public bool hasTemplateTypes = false
1649 749 public bool hasParams = false
1650 749 public SignatureType signatureType = SignatureType::TYPE_NONE
1651 public TypeQualifiers signatureQualifiers
1652 public Vector<Function*> signatureManifestations
1653 public String methodName
1654 749 public SymbolTableEntry* entry = nil<SymbolTableEntry*>
1655 }
1656
1657 749 public p ASTSignatureNode.ctor(CodeLoc codeLoc) {
1658 749 this.node = ASTNode(codeLoc);
1659 749 this.kind = ASTNodeKind::SIGNATURE;
1660 749 }
1661 2933 public f<Any> ASTSignatureNode.accept(IAbstractAstVisitor* visitor) {
1662 2933 return visitor.visitSignature(this);
1663 }
1664
1665
1666 // ========================================================== DeclStmtNode =======================================================
1667
1668 // ========================================================== ExprStmtNode =======================================================
1669
1670 61565 public type ASTExprStmtNode struct : IVisitable {
1671 compose public ASTStmtNode node
1672
1673 64128 public IVisitable* expr = nil<IVisitable*>
1674 }
1675
1676 64128 public p ASTExprStmtNode.ctor(CodeLoc codeLoc) {
1677 64128 this.node = ASTStmtNode(codeLoc);
1678 64128 this.kind = ASTNodeKind::EXPR_STMT;
1679 64128 }
1680 315206 public f<Any> ASTExprStmtNode.accept(IAbstractAstVisitor* visitor) {
1681 315206 return visitor.visitExprStmt(this);
1682 }
1683
1684
1685 // ========================================================== ModAttrNode ========================================================
1686
1687 1439 public type ASTModAttrNode struct : IVisitable {
1688 compose public ASTNode node
1689 1540 public ASTAttrLstNode* attrLst = nil<ASTAttrLstNode*>
1690 }
1691
1692 1540 public p ASTModAttrNode.ctor(CodeLoc codeLoc) {
1693 1540 this.node = ASTNode(codeLoc);
1694 1540 this.kind = ASTNodeKind::MOD_ATTR;
1695 1540 }
1696 12259 public f<Any> ASTModAttrNode.accept(IAbstractAstVisitor* visitor) {
1697 12259 return visitor.visitModAttr(this);
1698 }
1699
1700
1701 // =================================================== TopLevelDefAttrNode ================================================
1702
1703 1483 public type ASTTopLevelDefAttrNode struct : IVisitable {
1704 compose public ASTNode node
1705 1574 public ASTAttrLstNode* attrLst = nil<ASTAttrLstNode*>
1706 }
1707
1708 1574 public p ASTTopLevelDefAttrNode.ctor(CodeLoc codeLoc) {
1709 1574 this.node = ASTNode(codeLoc);
1710 1574 this.kind = ASTNodeKind::TOP_LEVEL_DEF_ATTR;
1711 1574 }
1712 4643 public f<Any> ASTTopLevelDefAttrNode.accept(IAbstractAstVisitor* visitor) {
1713 4643 return visitor.visitTopLevelDefinitionAttr(this);
1714 }
1715
1716
1717 // ======================================================== LambdaAttrNode =======================================================
1718
1719 21 public type ASTLambdaAttrNode struct : IVisitable {
1720 compose public ASTNode node
1721 21 public ASTAttrLstNode* attrLst = nil<ASTAttrLstNode*>
1722 }
1723
1724 21 public p ASTLambdaAttrNode.ctor(CodeLoc codeLoc) {
1725 21 this.node = ASTNode(codeLoc);
1726 21 this.kind = ASTNodeKind::LAMBDA_ATTR;
1727 21 }
1728 42 public f<Any> ASTLambdaAttrNode.accept(IAbstractAstVisitor* visitor) {
1729 42 return visitor.visitLambdaAttr(this);
1730 }
1731
1732
1733 // ========================================================= CaseConstantNode ====================================================
1734
1735 188 public type ASTCaseConstantNode struct : IVisitable {
1736 compose public ASTExprNode node
1737
1738 201 public ASTConstantNode* constant = nil<ASTConstantNode*>
1739 public Vector<String> identifierFragments
1740 public String fqIdentifier
1741 201 public const SymbolTableEntry* entry = nil<const SymbolTableEntry*>
1742 }
1743
1744 201 public p ASTCaseConstantNode.ctor(CodeLoc codeLoc) {
1745 201 this.node = ASTExprNode(codeLoc);
1746 201 this.kind = ASTNodeKind::CASE_CONSTANT;
1747 201 }
1748 983 public f<Any> ASTCaseConstantNode.accept(IAbstractAstVisitor* visitor) {
1749 983 return visitor.visitCaseConstant(this);
1750 }
1751
1752
1753 // ========================================================= ReturnStmtNode ======================================================
1754
1755 // Return type and copy ctor of a return statement. They depend on the return type, so they are resolved once per manifestation
1756 53156 public type ReturnStmtData struct {
1757 public QualType returnType
1758 53156 public Function* calledCopyCtor = nil<Function*>
1759 }
1760
1761 53156 public p ReturnStmtData.ctor() {
1762 53156 this.returnType = QualType(SuperType::TY_INVALID);
1763 53156 }
1764
1765 38531 public type ASTReturnStmtNode struct : IVisitable {
1766 compose public ASTStmtNode node
1767
1768 40235 public IVisitable* assignExpr = nil<IVisitable*>
1769 public Vector<ReturnStmtData> data
1770 40235 public bool hasReturnValue = false
1771 // Local variable, that is handed over to the caller without a copy (per manifestation). Its dtor is skipped on the
1772 // cleanup path of this return statement only, all other paths out of its scope still destruct it.
1773 public Vector<SymbolTableEntry*> returnedLocals
1774 }
1775
1776 40235 public p ASTReturnStmtNode.ctor(CodeLoc codeLoc) {
1777 40235 this.node = ASTStmtNode(codeLoc);
1778 40235 this.kind = ASTNodeKind::RETURN_STMT;
1779 40235 }
1780 204064 public f<Any> ASTReturnStmtNode.accept(IAbstractAstVisitor* visitor) {
1781 204064 return visitor.visitReturnStmt(this);
1782 }
1783
1784
1785 // ========================================================= BreakStmtNode =======================================================
1786
1787 709 public type ASTBreakStmtNode struct : IVisitable {
1788 compose public ASTStmtNode node
1789
1790 741 public int breakTimes = 1
1791 }
1792
1793 741 public p ASTBreakStmtNode.ctor(CodeLoc codeLoc) {
1794 741 this.node = ASTStmtNode(codeLoc);
1795 741 this.kind = ASTNodeKind::BREAK_STMT;
1796 741 }
1797 3679 public f<Any> ASTBreakStmtNode.accept(IAbstractAstVisitor* visitor) {
1798 3679 return visitor.visitBreakStmt(this);
1799 }
1800
1801
1802 // ======================================================== ContinueStmtNode =====================================================
1803
1804 730 public type ASTContinueStmtNode struct : IVisitable {
1805 compose public ASTStmtNode node
1806
1807 762 public int continueTimes = 1
1808 }
1809
1810 762 public p ASTContinueStmtNode.ctor(CodeLoc codeLoc) {
1811 762 this.node = ASTStmtNode(codeLoc);
1812 762 this.kind = ASTNodeKind::CONTINUE_STMT;
1813 762 }
1814 5056 public f<Any> ASTContinueStmtNode.accept(IAbstractAstVisitor* visitor) {
1815 5056 return visitor.visitContinueStmt(this);
1816 }
1817
1818
1819 // ======================================================= FallthroughStmtNode ===================================================
1820
1821 10 public type ASTFallthroughStmtNode struct : IVisitable {
1822 compose public ASTStmtNode node
1823
1824 }
1825
1826 16 public p ASTFallthroughStmtNode.ctor(CodeLoc codeLoc) {
1827 16 this.node = ASTStmtNode(codeLoc);
1828 16 this.kind = ASTNodeKind::FALLTHROUGH_STMT;
1829 16 }
1830 68 public f<Any> ASTFallthroughStmtNode.accept(IAbstractAstVisitor* visitor) {
1831 68 return visitor.visitFallthroughStmt(this);
1832 }
1833
1834
1835 // ========================================================= AssertStmtNode ======================================================
1836
1837 4070 public type ASTAssertStmtNode struct : IVisitable {
1838 compose public ASTStmtNode node
1839
1840 4080 public IVisitable* assignExpr = nil<IVisitable*>
1841 public String expressionString
1842 }
1843
1844 4080 public p ASTAssertStmtNode.ctor(CodeLoc codeLoc) {
1845 4080 this.node = ASTStmtNode(codeLoc);
1846 4080 this.kind = ASTNodeKind::ASSERT_STMT;
1847 4080 }
1848 21867 public f<Any> ASTAssertStmtNode.accept(IAbstractAstVisitor* visitor) {
1849 21867 return visitor.visitAssertStmt(this);
1850 }
1851
1852
1853 // ========================================================= AssignExprNode =======================================================
1854
1855 public type AssignOp enum {
1856 OP_NONE,
1857 OP_ASSIGN,
1858 OP_PLUS_EQUAL,
1859 OP_MINUS_EQUAL,
1860 OP_MUL_EQUAL,
1861 OP_DIV_EQUAL,
1862 OP_REM_EQUAL,
1863 OP_SHL_EQUAL,
1864 OP_SHR_EQUAL,
1865 OP_AND_EQUAL,
1866 OP_OR_EQUAL,
1867 OP_XOR_EQUAL
1868 }
1869
1870 29081 public type ASTAssignExprNode struct : IVisitable {
1871 compose public ASTExprNode node
1872 30299 public IVisitable* lhs = nil<IVisitable*>
1873 30299 public IVisitable* rhs = nil<IVisitable*>
1874 30299 public IVisitable* ternaryExpr = nil<IVisitable*>
1875 30299 public AssignOp op = AssignOp::OP_NONE
1876 public Vector<Vector<const Function*>> opFct // Operator overloading functions
1877 public Vector<const Function*> lhsDtorFct // Dtor of the lhs, if it gets overwritten
1878 }
1879
1880 30299 public p ASTAssignExprNode.ctor(CodeLoc codeLoc) {
1881 30299 this.node = ASTExprNode(codeLoc);
1882 30299 this.kind = ASTNodeKind::ASSIGN_EXPR;
1883 30299 }
1884 150536 public f<Any> ASTAssignExprNode.accept(IAbstractAstVisitor* visitor) {
1885 150536 return visitor.visitAssignExpr(this);
1886 }
1887
1888
1889 // ======================================================== TernaryExprNode ======================================================
1890
1891 // Copy ctor calls of a ternary. They depend on the operand types, so they are resolved once per manifestation
1892 public type TernaryExprData struct {
1893 public Function* calledCopyCtor = nil<Function*>
1894 public bool trueSideCallsCopyCtor = false
1895 public bool falseSideCallsCopyCtor = false
1896 }
1897
1898 2522 public type ASTTernaryExprNode struct : IVisitable {
1899 compose public ASTExprNode node
1900
1901 2600 public IVisitable* condition = nil<IVisitable*>
1902 2600 public IVisitable* trueExpr = nil<IVisitable*>
1903 2600 public IVisitable* falseExpr = nil<IVisitable*>
1904 public Vector<TernaryExprData> data
1905 2600 public bool isShortened = false
1906 }
1907
1908 2600 public p ASTTernaryExprNode.ctor(CodeLoc codeLoc) {
1909 2600 this.node = ASTExprNode(codeLoc);
1910 2600 this.kind = ASTNodeKind::TERNARY_EXPR;
1911 2600 }
1912 12494 public f<Any> ASTTernaryExprNode.accept(IAbstractAstVisitor* visitor) {
1913 12494 return visitor.visitTernaryExpr(this);
1914 }
1915
1916
1917 // ======================================================= LogicalOrExprNode =====================================================
1918
1919 3863 public type ASTLogicalOrExprNode struct : IVisitable {
1920 compose public ASTExprNode node
1921
1922 public Vector<IVisitable*> operands
1923 }
1924
1925 4054 public p ASTLogicalOrExprNode.ctor(CodeLoc codeLoc) {
1926 4054 this.node = ASTExprNode(codeLoc);
1927 4054 this.kind = ASTNodeKind::LOGICAL_OR_EXPR;
1928 4054 }
1929 18813 public f<Any> ASTLogicalOrExprNode.accept(IAbstractAstVisitor* visitor) {
1930 18813 return visitor.visitLogicalOrExpr(this);
1931 }
1932
1933
1934 // ======================================================= LogicalAndExprNode ====================================================
1935
1936 2066 public type ASTLogicalAndExprNode struct : IVisitable {
1937 compose public ASTExprNode node
1938
1939 public Vector<IVisitable*> operands
1940 }
1941
1942 2130 public p ASTLogicalAndExprNode.ctor(CodeLoc codeLoc) {
1943 2130 this.node = ASTExprNode(codeLoc);
1944 2130 this.kind = ASTNodeKind::LOGICAL_AND_EXPR;
1945 2130 }
1946 10295 public f<Any> ASTLogicalAndExprNode.accept(IAbstractAstVisitor* visitor) {
1947 10295 return visitor.visitLogicalAndExpr(this);
1948 }
1949
1950
1951 // ======================================================= BitwiseOrExprNode =====================================================
1952
1953 423 public type ASTBitwiseOrExprNode struct : IVisitable {
1954 compose public ASTExprNode node
1955 public Vector<IVisitable*> operands
1956 public Vector<Vector<const Function*>> opFct // Operator overloading functions
1957 }
1958
1959 430 public p ASTBitwiseOrExprNode.ctor(CodeLoc codeLoc) {
1960 430 this.node = ASTExprNode(codeLoc);
1961 430 this.kind = ASTNodeKind::BITWISE_OR_EXPR;
1962 430 }
1963 2288 public f<Any> ASTBitwiseOrExprNode.accept(IAbstractAstVisitor* visitor) {
1964 2288 return visitor.visitBitwiseOrExpr(this);
1965 }
1966
1967
1968 // ======================================================= BitwiseXorExprNode ====================================================
1969
1970 76 public type ASTBitwiseXorExprNode struct : IVisitable {
1971 compose public ASTExprNode node
1972 public Vector<IVisitable*> operands
1973 public Vector<Vector<const Function*>> opFct // Operator overloading functions
1974 }
1975
1976 77 public p ASTBitwiseXorExprNode.ctor(CodeLoc codeLoc) {
1977 77 this.node = ASTExprNode(codeLoc);
1978 77 this.kind = ASTNodeKind::BITWISE_XOR_EXPR;
1979 77 }
1980 393 public f<Any> ASTBitwiseXorExprNode.accept(IAbstractAstVisitor* visitor) {
1981 393 return visitor.visitBitwiseXorExpr(this);
1982 }
1983
1984
1985 // ======================================================= BitwiseAndExprNode ====================================================
1986
1987 259 public type ASTBitwiseAndExprNode struct : IVisitable {
1988 compose public ASTExprNode node
1989 public Vector<IVisitable*> operands
1990 public Vector<Vector<const Function*>> opFct // Operator overloading functions
1991 }
1992
1993 260 public p ASTBitwiseAndExprNode.ctor(CodeLoc codeLoc) {
1994 260 this.node = ASTExprNode(codeLoc);
1995 260 this.kind = ASTNodeKind::BITWISE_AND_EXPR;
1996 260 }
1997 1404 public f<Any> ASTBitwiseAndExprNode.accept(IAbstractAstVisitor* visitor) {
1998 1404 return visitor.visitBitwiseAndExpr(this);
1999 }
2000
2001
2002 // ======================================================== EqualityExprNode =====================================================
2003
2004 public type EqualityOp enum {
2005 OP_NONE,
2006 OP_EQUAL,
2007 OP_NOT_EQUAL
2008 }
2009
2010 26116 public type ASTEqualityExprNode struct : IVisitable {
2011 compose public ASTExprNode node
2012 public Vector<IVisitable*> operands
2013 27120 public EqualityOp op = EqualityOp::OP_NONE
2014 public Vector<Vector<const Function*>> opFct // Operator overloading functions
2015 }
2016
2017 27120 public p ASTEqualityExprNode.ctor(CodeLoc codeLoc) {
2018 27120 this.node = ASTExprNode(codeLoc);
2019 27120 this.kind = ASTNodeKind::EQUALITY_EXPR;
2020 27120 }
2021 137716 public f<Any> ASTEqualityExprNode.accept(IAbstractAstVisitor* visitor) {
2022 137716 return visitor.visitEqualityExpr(this);
2023 }
2024
2025
2026 // ======================================================= RelationalExprNode ====================================================
2027
2028 public type RelationalOp enum {
2029 OP_NONE,
2030 OP_LESS,
2031 OP_GREATER,
2032 OP_LESS_EQUAL,
2033 OP_GREATER_EQUAL
2034 }
2035
2036 15675 public type ASTRelationalExprNode struct : IVisitable {
2037 compose public ASTExprNode node
2038 public Vector<IVisitable*> operands
2039 16416 public RelationalOp op = RelationalOp::OP_NONE
2040 public Vector<Vector<const Function*>> opFct // Operator overloading functions
2041 }
2042
2043 16416 public p ASTRelationalExprNode.ctor(CodeLoc codeLoc) {
2044 16416 this.node = ASTExprNode(codeLoc);
2045 16416 this.kind = ASTNodeKind::RELATIONAL_EXPR;
2046 16416 }
2047 83459 public f<Any> ASTRelationalExprNode.accept(IAbstractAstVisitor* visitor) {
2048 83459 return visitor.visitRelationalExpr(this);
2049 }
2050
2051
2052 // ========================================================= ShiftExprNode =======================================================
2053
2054 public type ShiftOp enum {
2055 OP_SHIFT_LEFT,
2056 OP_SHIFT_RIGHT
2057 }
2058
2059 public type ShiftOpQueue alias Queue<Pair<ShiftOp, QualType>>;
2060
2061 607 public type ASTShiftExprNode struct : IVisitable {
2062 compose public ASTExprNode node
2063 public Vector<IVisitable*> operands
2064 public ShiftOpQueue opQueue
2065 public Vector<Vector<const Function*>> opFct // Operator overloading functions
2066 }
2067
2068 607 public p ASTShiftExprNode.ctor(CodeLoc codeLoc) {
2069 607 this.node = ASTExprNode(codeLoc);
2070 607 this.kind = ASTNodeKind::SHIFT_EXPR;
2071 607 }
2072 3341 public f<Any> ASTShiftExprNode.accept(IAbstractAstVisitor* visitor) {
2073 3341 return visitor.visitShiftExpr(this);
2074 }
2075
2076
2077 // ======================================================== AdditiveExprNode =====================================================
2078
2079 public type AdditiveOp enum {
2080 OP_PLUS,
2081 OP_MINUS
2082 }
2083
2084 public type AdditiveOpQueue alias Queue<Pair<AdditiveOp, QualType>>;
2085
2086 14283 public type ASTAdditiveExprNode struct : IVisitable {
2087 compose public ASTExprNode node
2088 public Vector<IVisitable*> operands
2089 public AdditiveOpQueue opQueue
2090 public Vector<Vector<const Function*>> opFct // Operator overloading functions
2091 }
2092
2093 14994 public p ASTAdditiveExprNode.ctor(CodeLoc codeLoc) {
2094 14994 this.node = ASTExprNode(codeLoc);
2095 14994 this.kind = ASTNodeKind::ADDITIVE_EXPR;
2096 14994 }
2097 75981 public f<Any> ASTAdditiveExprNode.accept(IAbstractAstVisitor* visitor) {
2098 75981 return visitor.visitAdditiveExpr(this);
2099 }
2100
2101
2102 // ===================================================== MultiplicativeExprNode ==================================================
2103
2104 public type MultiplicativeOp enum {
2105 OP_MUL,
2106 OP_DIV,
2107 OP_REM
2108 }
2109
2110 public type MultiplicativeOpQueue alias Queue<Pair<MultiplicativeOp, QualType>>;
2111
2112 3220 public type ASTMultiplicativeExprNode struct : IVisitable {
2113 compose public ASTExprNode node
2114 public Vector<IVisitable*> operands
2115 public MultiplicativeOpQueue opQueue
2116 public Vector<Vector<const Function*>> opFct // Operator overloading functions
2117 }
2118
2119 3335 public p ASTMultiplicativeExprNode.ctor(CodeLoc codeLoc) {
2120 3335 this.node = ASTExprNode(codeLoc);
2121 3335 this.kind = ASTNodeKind::MULTIPLICATIVE_EXPR;
2122 3335 }
2123 15805 public f<Any> ASTMultiplicativeExprNode.accept(IAbstractAstVisitor* visitor) {
2124 15805 return visitor.visitMultiplicativeExpr(this);
2125 }
2126
2127
2128 // ========================================================== CastExprNode =======================================================
2129
2130 12031 public type ASTCastExprNode struct : IVisitable {
2131 compose public ASTExprNode node
2132 12449 public IVisitable* prefixUnaryExpr = nil<IVisitable*>
2133 12449 public ASTDataTypeNode* dataType = nil<ASTDataTypeNode*>
2134 12449 public IVisitable* assignExpr = nil<IVisitable*>
2135 12449 public bool isCast = false
2136 }
2137
2138 12449 public p ASTCastExprNode.ctor(CodeLoc codeLoc) {
2139 12449 this.node = ASTExprNode(codeLoc);
2140 12449 this.kind = ASTNodeKind::CAST_EXPR;
2141 12449 }
2142 61394 public f<Any> ASTCastExprNode.accept(IAbstractAstVisitor* visitor) {
2143 61394 return visitor.visitCastExpr(this);
2144 }
2145
2146
2147 // ====================================================== PrefixUnaryExprNode ====================================================
2148
2149 public type PrefixUnaryOp enum {
2150 OP_NONE,
2151 OP_MINUS,
2152 OP_PLUS_PLUS,
2153 OP_MINUS_MINUS,
2154 OP_NOT,
2155 OP_BITWISE_NOT,
2156 OP_DEREFERENCE,
2157 OP_ADDRESS_OF
2158 }
2159
2160 6806 public type ASTPrefixUnaryExprNode struct : IVisitable {
2161 compose public ASTExprNode node
2162 7028 public IVisitable* prefixUnaryExpr = nil<IVisitable*>
2163 7028 public IVisitable* postfixUnaryExpr = nil<IVisitable*>
2164 7028 public PrefixUnaryOp op = PrefixUnaryOp::OP_NONE
2165 public Vector<Vector<const Function*>> opFct // Operator overloading functions
2166 }
2167
2168 7028 public p ASTPrefixUnaryExprNode.ctor(CodeLoc codeLoc) {
2169 7028 this.node = ASTExprNode(codeLoc);
2170 7028 this.kind = ASTNodeKind::PREFIX_UNARY_EXPR;
2171 7028 }
2172 36175 public f<Any> ASTPrefixUnaryExprNode.accept(IAbstractAstVisitor* visitor) {
2173 36175 return visitor.visitPrefixUnaryExpr(this);
2174 }
2175
2176
2177 // ====================================================== PostfixUnaryExprNode ===================================================
2178
2179 public type PostfixUnaryOp enum {
2180 OP_NONE,
2181 OP_SUBSCRIPT,
2182 OP_MEMBER_ACCESS,
2183 OP_PLUS_PLUS,
2184 OP_MINUS_MINUS,
2185 OP_ERR_PROPAGATION
2186 }
2187
2188 // Functions, that the error propagation operator calls. They depend on the Result<T> type of the operand, so they are resolved
2189 // once per manifestation
2190 public type ErrPropagationData struct {
2191 public const Function* isErrFct = nil<const Function*> // Result<T>.isErr()
2192 public const Function* unwrapFct = nil<const Function*> // Result<T>.unwrap()
2193 public const Function* getErrFct = nil<const Function*> // Result<T>.getErr()
2194 public const Function* ctorFct = nil<const Function*> // err<U>(const Error&), where Result<U> is the enclosing function's return type
2195 }
2196
2197 101073 public type ASTPostfixUnaryExprNode struct : IVisitable {
2198 compose public ASTExprNode node
2199 105647 public IVisitable* atomicExpr = nil<IVisitable*>
2200 105647 public IVisitable* postfixUnaryExpr = nil<IVisitable*>
2201 105647 public IVisitable* subscriptIndexExpr = nil<IVisitable*>
2202 105647 public PostfixUnaryOp op = PostfixUnaryOp::OP_NONE
2203 public Vector<Vector<const Function*>> opFct // Operator overloading functions
2204 public String identifier // Only set when operator is member access
2205 public Vector<ErrPropagationData> errPropData // Only set when operator is error propagation
2206 }
2207
2208 105647 public p ASTPostfixUnaryExprNode.ctor(CodeLoc codeLoc) {
2209 105647 this.node = ASTExprNode(codeLoc);
2210 105647 this.kind = ASTNodeKind::POSTFIX_UNARY_EXPR;
2211 105647 }
2212 524156 public f<Any> ASTPostfixUnaryExprNode.accept(IAbstractAstVisitor* visitor) {
2213 524156 return visitor.visitPostfixUnaryExpr(this);
2214 }
2215
2216
2217 // ========================================================= AtomicExprNode ======================================================
2218
2219 public type VarAccessData struct {
2220 public SymbolTableEntry* entry = nil<SymbolTableEntry*>
2221 public Scope* accessScope = nil<Scope*>
2222 public Capture* capture = nil<Capture*>
2223 }
2224
2225 382877 public type ASTAtomicExprNode struct : IVisitable {
2226 compose public ASTExprNode node
2227
2228 398583 public ASTConstantNode* constant = nil<ASTConstantNode*>
2229 398583 public IVisitable* value = nil<IVisitable*>
2230 398583 public IVisitable* assignExpr = nil<IVisitable*>
2231 public Vector<String> identifierFragments
2232 public String fqIdentifier
2233 public Vector<VarAccessData> data // Only set if identifier is set as well
2234 }
2235
2236 398583 public p ASTAtomicExprNode.ctor(CodeLoc codeLoc) {
2237 398583 this.node = ASTExprNode(codeLoc);
2238 398583 this.kind = ASTNodeKind::ATOMIC_EXPR;
2239 398583 }
2240 2013610 public f<Any> ASTAtomicExprNode.accept(IAbstractAstVisitor* visitor) {
2241 2013610 return visitor.visitAtomicExpr(this);
2242 }
2243
2244
2245 // =========================================================== ValueNode =========================================================
2246
2247 88107 public type ASTValueNode struct : IVisitable {
2248 compose public ASTExprNode node
2249
2250 91119 public IVisitable* fctCall = nil<IVisitable*>
2251 91119 public IVisitable* arrayInitialization = nil<IVisitable*>
2252 91119 public IVisitable* structInstantiation = nil<IVisitable*>
2253 91119 public IVisitable* lambdaFunc = nil<IVisitable*>
2254 91119 public IVisitable* lambdaProc = nil<IVisitable*>
2255 91119 public IVisitable* lambdaExpr = nil<IVisitable*>
2256 91119 public ASTDataTypeNode* nilType = nil<ASTDataTypeNode*>
2257 91119 public bool isNil = false
2258 }
2259
2260 91119 public p ASTValueNode.ctor(CodeLoc codeLoc) {
2261 91119 this.node = ASTExprNode(codeLoc);
2262 91119 this.kind = ASTNodeKind::VALUE;
2263 91119 }
2264 455534 public f<Any> ASTValueNode.accept(IAbstractAstVisitor* visitor) {
2265 455534 return visitor.visitValue(this);
2266 }
2267
2268
2269 // ========================================================== FctCallNode ========================================================
2270
2271 public type FctCallType enum {
2272 TYPE_ORDINARY,
2273 TYPE_METHOD,
2274 TYPE_CTOR,
2275 TYPE_FCT_PTR
2276 }
2277
2278 311675 public type FctCallData struct {
2279 104868 public FctCallType callType = FctCallType::TYPE_ORDINARY
2280 104868 public bool isImported = false
2281 public QualTypeList templateTypes
2282 public QualType thisType // Is filled if method or ctor call
2283 public ArgList args
2284 104868 public const Function* callee = nil<const Function*> // Stays nil if function pointer call
2285 104868 public Scope* calleeParentScope = nil<Scope*>
2286 public CompileTimeValue compileTimeValue
2287 104868 public bool compileTimeValueSet = false
2288 }
2289
2290 104868 public p FctCallData.ctor() {
2291 104868 this.thisType = QualType(SuperType::TY_DYN);
2292 104868 }
2293
2294 81891 public f<bool> FctCallData.isOrdinaryCall() { return this.callType == FctCallType::TYPE_ORDINARY; }
2295 240569 public f<bool> FctCallData.isMethodCall() { return this.callType == FctCallType::TYPE_METHOD; }
2296
2/2
✓ Branch 0 taken 46369 times.
✓ Branch 1 taken 34638 times.
81007 public f<bool> FctCallData.isVirtualMethodCall() { return this.isMethodCall() && this.thisType.isBase(SuperType::TY_INTERFACE); }
2297 306261 public f<bool> FctCallData.isCtorCall() { return this.callType == FctCallType::TYPE_CTOR; }
2298 788487 public f<bool> FctCallData.isFctPtrCall() { return this.callType == FctCallType::TYPE_FCT_PTR; }
2299
2300 1513 public p FctCallData.setCompileTimeValue(const CompileTimeValue& value) {
2301 1513 this.compileTimeValue = value;
2302 1513 this.compileTimeValueSet = true;
2303 1513 }
2304
2305 9532 public f<bool> FctCallData.hasCompileTimeValue() { return this.compileTimeValueSet; }
2306
2307 78307 public type ASTFctCallNode struct : IVisitable {
2308 compose public ASTExprNode node
2309
2310 80976 public ASTTypeLstNode* templateTypeLst = nil<ASTTypeLstNode*>
2311 80976 public ASTArgLstNode* argLst = nil<ASTArgLstNode*>
2312 80976 public bool hasArgs = false
2313 80976 public bool hasTemplateTypes = false
2314 public String fqFunctionName
2315 public Vector<String> functionNameFragments
2316 public Vector<FctCallData> data
2317 80976 public bool isErrorTraceOrigin = false // Set if this is a direct call to err<T>(...), and error return tracing is enabled
2318 }
2319
2320 80976 public p ASTFctCallNode.ctor(CodeLoc codeLoc) {
2321 80976 this.node = ASTExprNode(codeLoc);
2322 80976 this.kind = ASTNodeKind::FCT_CALL;
2323 80976 }
2324 400008 public f<Any> ASTFctCallNode.accept(IAbstractAstVisitor* visitor) {
2325 400008 return visitor.visitFctCall(this);
2326 }
2327
2328 /**
2329 * Check if right above the closest assign expression ancestor is a statement node
2330 *
2331 * @return Has return value receiver or not
2332 */
2333 43412 public f<bool> ASTFctCallNode.hasReturnValueReceiver() {
2334 43412 ASTNode* current = this.parent;
2335
2/2
✓ Branch 0 taken 3749 times.
✓ Branch 1 taken 140821 times.
144570 while current.kind != ASTNodeKind::ASSIGN_EXPR {
2336
2/2
✓ Branch 0 taken 5333 times.
✓ Branch 1 taken 135488 times.
140821 if current.kind == ASTNodeKind::EXPR_STMT {
2337 5333 return false;
2338 }
2339 // The call is (part of) an argument of another call, so the return value is used
2340
2/2
✓ Branch 0 taken 4069 times.
✓ Branch 1 taken 131419 times.
135488 if current.kind == ASTNodeKind::ARG_LST {
2341 4069 return true;
2342 }
2343 // Incrementing or decrementing the returned value counts as a use
2344
2/2
✓ Branch 0 taken 129170 times.
✓ Branch 1 taken 2249 times.
131419 if current.kind == ASTNodeKind::PREFIX_UNARY_EXPR {
2345 2249 const PrefixUnaryOp op = downcast<ASTPrefixUnaryExprNode>(current).op;
2346
4/4
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 2248 times.
✓ Branch 2 taken 2247 times.
✓ Branch 3 taken 2 times.
2249 if op == PrefixUnaryOp::OP_PLUS_PLUS || op == PrefixUnaryOp::OP_MINUS_MINUS {
2347 2 return true;
2348 }
2349 2247 }
2350
2/2
✓ Branch 0 taken 131188 times.
✓ Branch 1 taken 229 times.
131417 if current.kind == ASTNodeKind::POSTFIX_UNARY_EXPR {
2351 229 const PostfixUnaryOp op = downcast<ASTPostfixUnaryExprNode>(current).op;
2352
4/4
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 228 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 227 times.
229 if op == PostfixUnaryOp::OP_PLUS_PLUS || op == PostfixUnaryOp::OP_MINUS_MINUS {
2353 2 return true;
2354 }
2355 227 }
2356 // As soon as we have a node with more than one child, we know that the return value is used
2357
2/2
✓ Branch 0 taken 101158 times.
✓ Branch 1 taken 30257 times.
131415 if current.children.getSize() > 1l {
2358 30257 return true;
2359 }
2360 101158 current = current.parent;
2361 101158 }
2362 // Also check the condition of the assign expression
2363 3749 const ASTNode* assignExprParent = current.parent;
2364
1/2
✓ Branch 0 taken 3749 times.
✗ Branch 1 not taken.
3749 return current.children.getSize() > 1l || assignExprParent.kind != ASTNodeKind::EXPR_STMT;
2365 }
2366
2367
2368 // ==================================================== ArrayInitializationNode ==================================================
2369
2370 162 public type ASTArrayInitializationNode struct : IVisitable {
2371 compose public ASTExprNode node
2372
2373 180 public ASTArgLstNode* itemLst = nil<ASTArgLstNode*>
2374 180 public unsigned long actualSize = 0l
2375 }
2376
2377 180 public p ASTArrayInitializationNode.ctor(CodeLoc codeLoc) {
2378 180 this.node = ASTExprNode(codeLoc);
2379 180 this.kind = ASTNodeKind::ARRAY_INITIALIZATION;
2380 180 }
2381 864 public f<Any> ASTArrayInitializationNode.accept(IAbstractAstVisitor* visitor) {
2382 864 return visitor.visitArrayInitialization(this);
2383 }
2384
2385
2386 // ==================================================== StructInstantiationNode ==================================================
2387
2388 1460 public type ASTStructInstantiationNode struct : IVisitable {
2389 compose public ASTExprNode node
2390
2391 1538 public ASTTypeLstNode* templateTypeLst = nil<ASTTypeLstNode*>
2392 1538 public ASTArgLstNode* fieldLst = nil<ASTArgLstNode*>
2393 1538 public bool hasTemplateTypes = false
2394 public String fqStructName
2395 public Vector<String> structNameFragments
2396 public Vector<Struct*> instantiatedStructs
2397 // Per-manifestation (the struct itself may be/depend on a generic type, e.g. inside a generic function), per-field
2398 // copy ctor to call for a field value that needs to be deep-copied instead of raw-stored. Kept here rather than on
2399 // fieldLst.argInfos, since that one is only filled for the arguments of function calls.
2400 public Vector<Vector<Function*>> fieldCopyCtors
2401 }
2402
2403 1538 public p ASTStructInstantiationNode.ctor(CodeLoc codeLoc) {
2404 1538 this.node = ASTExprNode(codeLoc);
2405 1538 this.kind = ASTNodeKind::STRUCT_INSTANTIATION;
2406 1538 }
2407 7938 public f<Any> ASTStructInstantiationNode.accept(IAbstractAstVisitor* visitor) {
2408 7938 return visitor.visitStructInstantiation(this);
2409 }
2410
2411
2412 // ========================================================= LambdaBaseNode ======================================================
2413
2414 136 public type ASTLambdaBaseNode struct {
2415 compose public ASTExprNode node
2416 144 public IVisitable* paramLst = nil<IVisitable*>
2417 144 public bool hasParams = false
2418 144 public Scope* bodyScope = nil<Scope*>
2419 public Vector<Function> manifestations
2420 }
2421
2422 /**
2423 * Get the lambda base of a lambda node. All lambda nodes compose ASTLambdaBaseNode as their first member, which composes
2424 * ASTExprNode and therefore ASTNode as its first member, so they all share the same address.
2425 *
2426 * @param node AST node, which must be a lambda node
2427 * @return Lambda base node
2428 */
2429 478 public f<ASTLambdaBaseNode*> asLambdaBaseNode(ASTNode* node) {
2430 478 assert node.kind == ASTNodeKind::LAMBDA_FUNC || node.kind == ASTNodeKind::LAMBDA_PROC || node.kind == ASTNodeKind::LAMBDA_EXPR;
2431 unsafe {
2432 478 return cast<ASTLambdaBaseNode*>(node);
2433 }
2434 }
2435
2436 144 public p ASTLambdaBaseNode.ctor(CodeLoc codeLoc) {
2437 144 this.node = ASTExprNode(codeLoc);
2438 144 }
2439
2440 // ========================================================= LambdaFuncNode ======================================================
2441
2442 61 public type ASTLambdaFuncNode struct : IVisitable {
2443 compose public ASTLambdaBaseNode node
2444
2445 67 public ASTDataTypeNode* returnType = nil<ASTDataTypeNode*>
2446 67 public ASTLambdaAttrNode* lambdaAttr = nil<ASTLambdaAttrNode*>
2447 67 public IVisitable* body = nil<IVisitable*>
2448 }
2449
2450 67 public p ASTLambdaFuncNode.ctor(CodeLoc codeLoc) {
2451 67 this.node = ASTLambdaBaseNode(codeLoc);
2452 67 this.kind = ASTNodeKind::LAMBDA_FUNC;
2453 67 }
2454 323 public f<Any> ASTLambdaFuncNode.accept(IAbstractAstVisitor* visitor) {
2455 323 return visitor.visitLambdaFunc(this);
2456 }
2457
2458 194 public f<String> ASTLambdaFuncNode.getScopeId() {
2459 388 return String("lambda:") + this.codeLoc.toString();
2460 194 }
2461
2462
2463 // ========================================================= LambdaProcNode ======================================================
2464
2465 71 public type ASTLambdaProcNode struct : IVisitable {
2466 compose public ASTLambdaBaseNode node
2467
2468 73 public ASTLambdaAttrNode* lambdaAttr = nil<ASTLambdaAttrNode*>
2469 73 public IVisitable* body = nil<IVisitable*>
2470 }
2471
2472 73 public p ASTLambdaProcNode.ctor(CodeLoc codeLoc) {
2473 73 this.node = ASTLambdaBaseNode(codeLoc);
2474 73 this.kind = ASTNodeKind::LAMBDA_PROC;
2475 73 }
2476 361 public f<Any> ASTLambdaProcNode.accept(IAbstractAstVisitor* visitor) {
2477 361 return visitor.visitLambdaProc(this);
2478 }
2479
2480 217 public f<String> ASTLambdaProcNode.getScopeId() {
2481 434 return String("lambda:") + this.codeLoc.toString();
2482 217 }
2483
2484
2485 // ========================================================= LambdaExprNode =======================================================
2486
2487 4 public type ASTLambdaExprNode struct : IVisitable {
2488 compose public ASTLambdaBaseNode node
2489
2490 4 public IVisitable* lambdaExpr = nil<IVisitable*>
2491 }
2492
2493 4 public p ASTLambdaExprNode.ctor(CodeLoc codeLoc) {
2494 4 this.node = ASTLambdaBaseNode(codeLoc);
2495 4 this.kind = ASTNodeKind::LAMBDA_EXPR;
2496 4 }
2497 20 public f<Any> ASTLambdaExprNode.accept(IAbstractAstVisitor* visitor) {
2498 20 return visitor.visitLambdaExpr(this);
2499 }
2500
2501 12 public f<String> ASTLambdaExprNode.getScopeId() {
2502 24 return String("lambda:") + this.codeLoc.toString();
2503 12 }
2504
2505
2506 // ====================================================== FunctionDataTypeNode ===================================================
2507
2508 685 public type ASTFunctionDataTypeNode struct : IVisitable {
2509 compose public ASTExprNode node
2510
2511 706 public ASTDataTypeNode* returnType = nil<ASTDataTypeNode*>
2512 706 public ASTTypeLstNode* paramTypeLst = nil<ASTTypeLstNode*>
2513 706 public bool isFunction = false // Function or procedure
2514 }
2515
2516 706 public p ASTFunctionDataTypeNode.ctor(CodeLoc codeLoc) {
2517 706 this.node = ASTExprNode(codeLoc);
2518 706 this.kind = ASTNodeKind::FUNCTION_DATA_TYPE;
2519 706 }
2520 2381 public f<Any> ASTFunctionDataTypeNode.accept(IAbstractAstVisitor* visitor) {
2521 2381 return visitor.visitFunctionDataType(this);
2522 }
2523
2524 // ======================================================= Virtual methods =======================================================
2525
2526 // The following functions depend on the concrete node. Spice has no virtual dispatch through a struct, so they switch over
2527 // the kind of the node instead. The concrete node is reached via its IVisitable pointer, which has the same address as the
2528 // concrete node.
2529
2530 /**
2531 * Check if an lvalue expression denotes a direct field of 'this' (e.g. 'this.field', but not 'this.field.nestedField')
2532 *
2533 * @param node Lvalue expression
2534 * @return Direct field of 'this' or not
2535 */
2536 12557 public f<bool> isDirectFieldOfThis(const ASTNode* node) {
2537
2/2
✓ Branch 0 taken 457 times.
✓ Branch 1 taken 12100 times.
12557 if node.kind != ASTNodeKind::POSTFIX_UNARY_EXPR {
2538 457 return false;
2539 }
2540 12100 const ASTPostfixUnaryExprNode* postfixUnaryExpr = downcast<ASTPostfixUnaryExprNode>(node);
2541
2/2
✓ Branch 0 taken 591 times.
✓ Branch 1 taken 11509 times.
12100 if postfixUnaryExpr.op != PostfixUnaryOp::OP_MEMBER_ACCESS {
2542 591 return false;
2543 }
2544 11509 ASTNode* operandNode = getASTNode(postfixUnaryExpr.postfixUnaryExpr);
2545
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 11507 times.
11509 if operandNode.kind != ASTNodeKind::ATOMIC_EXPR {
2546 2 return false;
2547 }
2548 11507 const ASTAtomicExprNode* atomicExpr = downcast<ASTAtomicExprNode>(operandNode);
2549 11507 return atomicExpr.fqIdentifier == THIS_VARIABLE_NAME;
2550 }
2551
2552 /**
2553 * Get the concrete node of an AST node
2554 *
2555 * @param node AST node, which must be of the given concrete node type
2556 * @return Concrete node
2557 */
2558 3829210 public f<const ConcreteNode*> downcast<ConcreteNode>(const ASTNode* node) {
2559 unsafe {
2560 3829210 return cast<const ConcreteNode*>(node.visitable);
2561 }
2562 }
2563
2564 /**
2565 * Get the concrete node of a mutable AST node
2566 *
2567 * This is not an overload of downcast(), because the stage0 compiler 0.29.1 cannot tell a const from a non-const pointer
2568 * param in overload resolution, and reports every call of the overload pair as ambiguous. Turn it into a downcast() overload,
2569 * as soon as the stage0 compiler contains the fix for that (spicelang/spice#1663).
2570 *
2571 * @param node AST node, which must be of the given concrete node type
2572 * @return Concrete node
2573 */
2574 3133695 public f<ConcreteNode*> downcastMut<ConcreteNode>(ASTNode* node) {
2575 unsafe {
2576 3133695 return cast<ConcreteNode*>(node.visitable);
2577 }
2578 }
2579
2580 /**
2581 * Get the concrete node of an AST node, that is stored as IVisitable*
2582 *
2583 * @param node AST node, which must be of the given concrete node type
2584 * @return Concrete node
2585 */
2586 101254 public f<ConcreteNode*> downcast<ConcreteNode>(IVisitable* node) {
2587 unsafe {
2588 101254 return cast<ConcreteNode*>(node);
2589 }
2590 }
2591
2592 /**
2593 * Destruct an AST node as the given concrete node type, so that the members of the concrete node are destructed as well
2594 *
2595 * @param node AST node, which must be of the given concrete node type
2596 */
2597 2142680 p destructAs<ConcreteNode>(ASTNode* node) {
2598 2142680 ConcreteNode* concreteNode = downcastMut<ConcreteNode>(node);
2599 2142680 sDestruct(*concreteNode);
2600 2142680 }
2601
2602 /**
2603 * Destruct an AST node as its concrete node type. The node pool only knows the nodes as ASTNode, so destructing them as such
2604 * would leak the members of the concrete nodes (e.g. operand lists and names).
2605 *
2606 * @param node AST node to destruct
2607 */
2608 2142680 public p destructASTNode(ASTNode* node) {
2609
78/79
✓ Branch 0 taken 3518 times.
✓ Branch 1 taken 77788 times.
✓ Branch 2 taken 3409 times.
✓ Branch 3 taken 2943 times.
✓ Branch 4 taken 144515 times.
✓ Branch 5 taken 120515 times.
✓ Branch 6 taken 70639 times.
✓ Branch 7 taken 190729 times.
✓ Branch 8 taken 190729 times.
✓ Branch 9 taken 29618 times.
✓ Branch 10 taken 754 times.
✓ Branch 11 taken 43805 times.
✓ Branch 12 taken 26986 times.
✓ Branch 13 taken 16819 times.
✓ Branch 14 taken 3001 times.
✓ Branch 15 taken 295 times.
✓ Branch 16 taken 17 times.
✓ Branch 17 taken 437 times.
✓ Branch 18 taken 2909 times.
✓ Branch 19 taken 153 times.
✓ Branch 20 taken 4205 times.
✓ Branch 21 taken 5041 times.
✓ Branch 22 taken 2407 times.
✓ Branch 23 taken 12164 times.
✓ Branch 24 taken 4222 times.
✓ Branch 25 taken 428 times.
✓ Branch 26 taken 1796 times.
✓ Branch 27 taken 49 times.
✓ Branch 28 taken 24177 times.
✓ Branch 29 taken 1392 times.
✓ Branch 30 taken 30 times.
✓ Branch 31 taken 183 times.
✓ Branch 32 taken 18 times.
✓ Branch 33 taken 126 times.
✓ Branch 34 taken 88684 times.
✓ Branch 35 taken 4970 times.
✓ Branch 36 taken 2909 times.
✓ Branch 37 taken 80206 times.
✓ Branch 38 taken 31772 times.
✓ Branch 39 taken 59513 times.
✓ Branch 40 taken 1686 times.
✓ Branch 41 taken 437 times.
✓ Branch 42 taken 7411 times.
✓ Branch 43 taken 694 times.
✓ Branch 44 taken 61565 times.
✓ Branch 45 taken 1439 times.
✓ Branch 46 taken 1483 times.
✓ Branch 47 taken 21 times.
✓ Branch 48 taken 188 times.
✓ Branch 49 taken 38531 times.
✓ Branch 50 taken 709 times.
✓ Branch 51 taken 730 times.
✓ Branch 52 taken 10 times.
✓ Branch 53 taken 4070 times.
✓ Branch 54 taken 29081 times.
✓ Branch 55 taken 2522 times.
✓ Branch 56 taken 3863 times.
✓ Branch 57 taken 2066 times.
✓ Branch 58 taken 423 times.
✓ Branch 59 taken 76 times.
✓ Branch 60 taken 259 times.
✓ Branch 61 taken 26116 times.
✓ Branch 62 taken 15675 times.
✓ Branch 63 taken 607 times.
✓ Branch 64 taken 14283 times.
✓ Branch 65 taken 3220 times.
✓ Branch 66 taken 12031 times.
✓ Branch 67 taken 101073 times.
✓ Branch 68 taken 382877 times.
✓ Branch 69 taken 88107 times.
✓ Branch 70 taken 78307 times.
✓ Branch 71 taken 162 times.
✓ Branch 72 taken 1460 times.
✓ Branch 73 taken 61 times.
✓ Branch 74 taken 71 times.
✓ Branch 75 taken 4 times.
✗ Branch 76 not taken.
✓ Branch 77 taken 6806 times.
✓ Branch 78 taken 685 times.
2142680 switch node.kind {
2610 3518 case ASTNodeKind::ENTRY: { destructAs<ASTEntryNode>(node); }
2611 77788 case ASTNodeKind::CONSTANT: { destructAs<ASTConstantNode>(node); }
2612 3409 case ASTNodeKind::ATTR: { destructAs<ASTAttrNode>(node); }
2613 2943 case ASTNodeKind::ATTR_LST: { destructAs<ASTAttrLstNode>(node); }
2614 144515 case ASTNodeKind::QUALIFIER: { destructAs<ASTQualifierNode>(node); }
2615 120515 case ASTNodeKind::QUALIFIER_LST: { destructAs<ASTQualifierLstNode>(node); }
2616 70639 case ASTNodeKind::CUSTOM_DATA_TYPE: { destructAs<ASTCustomDataTypeNode>(node); }
2617 190729 case ASTNodeKind::BASE_DATA_TYPE: { destructAs<ASTBaseDataTypeNode>(node); }
2618 190729 case ASTNodeKind::DATA_TYPE: { destructAs<ASTDataTypeNode>(node); }
2619 29618 case ASTNodeKind::TYPE_LST: { destructAs<ASTTypeLstNode>(node); }
2620 754 case ASTNodeKind::MAIN_FCT_DEF: { destructAs<ASTMainFctDefNode>(node); }
2621 43805 case ASTNodeKind::FCT_NAME: { destructAs<ASTFctNameNode>(node); }
2622 26986 case ASTNodeKind::FCT_DEF: { destructAs<ASTFctDefNode>(node); }
2623 16819 case ASTNodeKind::PROC_DEF: { destructAs<ASTProcDefNode>(node); }
2624 3001 case ASTNodeKind::STRUCT_DEF: { destructAs<ASTStructDefNode>(node); }
2625 295 case ASTNodeKind::INTERFACE_DEF: { destructAs<ASTInterfaceDefNode>(node); }
2626 17 case ASTNodeKind::UNION_DEF: { destructAs<ASTUnionDefNode>(node); }
2627 437 case ASTNodeKind::ENUM_DEF: { destructAs<ASTEnumDefNode>(node); }
2628 2909 case ASTNodeKind::GENERIC_TYPE_DEF: { destructAs<ASTGenericTypeDefNode>(node); }
2629 153 case ASTNodeKind::ALIAS_DEF: { destructAs<ASTAliasDefNode>(node); }
2630 4205 case ASTNodeKind::GLOBAL_VAR_DEF: { destructAs<ASTGlobalVarDefNode>(node); }
2631 5041 case ASTNodeKind::EXT_DECL: { destructAs<ASTExtDeclNode>(node); }
2632 2407 case ASTNodeKind::IMPORT_DEF: { destructAs<ASTImportDefNode>(node); }
2633 12164 case ASTNodeKind::UNSAFE_BLOCK: { destructAs<ASTUnsafeBlockNode>(node); }
2634 4222 case ASTNodeKind::FOR_LOOP: { destructAs<ASTForLoopNode>(node); }
2635 428 case ASTNodeKind::FOREACH_LOOP: { destructAs<ASTForeachLoopNode>(node); }
2636 1796 case ASTNodeKind::WHILE_LOOP: { destructAs<ASTWhileLoopNode>(node); }
2637 49 case ASTNodeKind::DO_WHILE_LOOP: { destructAs<ASTDoWhileLoopNode>(node); }
2638 24177 case ASTNodeKind::IF_STMT: { destructAs<ASTIfStmtNode>(node); }
2639 1392 case ASTNodeKind::ELSE_STMT: { destructAs<ASTElseStmtNode>(node); }
2640 30 case ASTNodeKind::SWITCH_STMT: { destructAs<ASTSwitchStmtNode>(node); }
2641 183 case ASTNodeKind::CASE_BRANCH: { destructAs<ASTCaseBranchNode>(node); }
2642 18 case ASTNodeKind::DEFAULT_BRANCH: { destructAs<ASTDefaultBranchNode>(node); }
2643 126 case ASTNodeKind::ANONYMOUS_BLOCK_STMT: { destructAs<ASTAnonymousBlockStmtNode>(node); }
2644 88684 case ASTNodeKind::STMT_LST: { destructAs<ASTStmtLstNode>(node); }
2645 4970 case ASTNodeKind::TYPE_LST_WITH_ELLIPSIS: { destructAs<ASTTypeLstWithEllipsisNode>(node); }
2646 2909 case ASTNodeKind::TYPE_ALTS_LST: { destructAs<ASTTypeAltsLstNode>(node); }
2647 80206 case ASTNodeKind::DECL_STMT: { destructAs<ASTDeclStmtNode>(node); }
2648 31772 case ASTNodeKind::PARAM_LST: { destructAs<ASTParamLstNode>(node); }
2649 59513 case ASTNodeKind::ARG_LST: { destructAs<ASTArgLstNode>(node); }
2650 1686 case ASTNodeKind::ENUM_ITEM: { destructAs<ASTEnumItemNode>(node); }
2651 437 case ASTNodeKind::ENUM_ITEM_LST: { destructAs<ASTEnumItemLstNode>(node); }
2652 7411 case ASTNodeKind::FIELD: { destructAs<ASTFieldNode>(node); }
2653 694 case ASTNodeKind::SIGNATURE: { destructAs<ASTSignatureNode>(node); }
2654 61565 case ASTNodeKind::EXPR_STMT: { destructAs<ASTExprStmtNode>(node); }
2655 1439 case ASTNodeKind::MOD_ATTR: { destructAs<ASTModAttrNode>(node); }
2656 1483 case ASTNodeKind::TOP_LEVEL_DEF_ATTR: { destructAs<ASTTopLevelDefAttrNode>(node); }
2657 21 case ASTNodeKind::LAMBDA_ATTR: { destructAs<ASTLambdaAttrNode>(node); }
2658 188 case ASTNodeKind::CASE_CONSTANT: { destructAs<ASTCaseConstantNode>(node); }
2659 38531 case ASTNodeKind::RETURN_STMT: { destructAs<ASTReturnStmtNode>(node); }
2660 709 case ASTNodeKind::BREAK_STMT: { destructAs<ASTBreakStmtNode>(node); }
2661 730 case ASTNodeKind::CONTINUE_STMT: { destructAs<ASTContinueStmtNode>(node); }
2662 10 case ASTNodeKind::FALLTHROUGH_STMT: { destructAs<ASTFallthroughStmtNode>(node); }
2663 4070 case ASTNodeKind::ASSERT_STMT: { destructAs<ASTAssertStmtNode>(node); }
2664 29081 case ASTNodeKind::ASSIGN_EXPR: { destructAs<ASTAssignExprNode>(node); }
2665 2522 case ASTNodeKind::TERNARY_EXPR: { destructAs<ASTTernaryExprNode>(node); }
2666 3863 case ASTNodeKind::LOGICAL_OR_EXPR: { destructAs<ASTLogicalOrExprNode>(node); }
2667 2066 case ASTNodeKind::LOGICAL_AND_EXPR: { destructAs<ASTLogicalAndExprNode>(node); }
2668 423 case ASTNodeKind::BITWISE_OR_EXPR: { destructAs<ASTBitwiseOrExprNode>(node); }
2669 76 case ASTNodeKind::BITWISE_XOR_EXPR: { destructAs<ASTBitwiseXorExprNode>(node); }
2670 259 case ASTNodeKind::BITWISE_AND_EXPR: { destructAs<ASTBitwiseAndExprNode>(node); }
2671 26116 case ASTNodeKind::EQUALITY_EXPR: { destructAs<ASTEqualityExprNode>(node); }
2672 15675 case ASTNodeKind::RELATIONAL_EXPR: { destructAs<ASTRelationalExprNode>(node); }
2673 607 case ASTNodeKind::SHIFT_EXPR: { destructAs<ASTShiftExprNode>(node); }
2674 14283 case ASTNodeKind::ADDITIVE_EXPR: { destructAs<ASTAdditiveExprNode>(node); }
2675 3220 case ASTNodeKind::MULTIPLICATIVE_EXPR: { destructAs<ASTMultiplicativeExprNode>(node); }
2676 12031 case ASTNodeKind::CAST_EXPR: { destructAs<ASTCastExprNode>(node); }
2677 6806 case ASTNodeKind::PREFIX_UNARY_EXPR: { destructAs<ASTPrefixUnaryExprNode>(node); }
2678 101073 case ASTNodeKind::POSTFIX_UNARY_EXPR: { destructAs<ASTPostfixUnaryExprNode>(node); }
2679 382877 case ASTNodeKind::ATOMIC_EXPR: { destructAs<ASTAtomicExprNode>(node); }
2680 88107 case ASTNodeKind::VALUE: { destructAs<ASTValueNode>(node); }
2681 78307 case ASTNodeKind::FCT_CALL: { destructAs<ASTFctCallNode>(node); }
2682 162 case ASTNodeKind::ARRAY_INITIALIZATION: { destructAs<ASTArrayInitializationNode>(node); }
2683 1460 case ASTNodeKind::STRUCT_INSTANTIATION: { destructAs<ASTStructInstantiationNode>(node); }
2684 61 case ASTNodeKind::LAMBDA_FUNC: { destructAs<ASTLambdaFuncNode>(node); }
2685 71 case ASTNodeKind::LAMBDA_PROC: { destructAs<ASTLambdaProcNode>(node); }
2686 4 case ASTNodeKind::LAMBDA_EXPR: { destructAs<ASTLambdaExprNode>(node); }
2687 685 case ASTNodeKind::FUNCTION_DATA_TYPE: { destructAs<ASTFunctionDataTypeNode>(node); }
2688 ✗ default: { sDestruct(*node); } // Not constructed as a concrete node
2689 }
2690 2142680 }
2691
2692 /**
2693 * Check if this node is a function parameter. Only a DeclStmtNode can be one.
2694 *
2695 * @return Parameter or not
2696 */
2697 2948 public f<bool> ASTNode.isParam() {
2698
2/2
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 2887 times.
2948 if this.kind != ASTNodeKind::DECL_STMT {
2699 61 return false;
2700 }
2701 2887 const ASTDeclStmtNode* concreteNode = downcast<ASTDeclStmtNode>(this);
2702 2887 return concreteNode.isFctParam;
2703 }
2704
2705 /**
2706 * Get the function manifestation list of a declaration node.
2707 *
2708 * @param fctName Name of the function. Only relevant for struct defs, which hold the implicitly created default methods
2709 * @return Manifestation list
2710 */
2711 15400 public f<Vector<Function*>*> ASTNode.getFctManifestations(const String& fctName) {
2712 15400 Vector<Function*>* manifestations = nil<Vector<Function*>*>;
2713
5/6
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5584 times.
✓ Branch 3 taken 6786 times.
✓ Branch 4 taken 946 times.
✓ Branch 5 taken 2077 times.
15400 switch this.kind {
2714 case ASTNodeKind::FCT_DEF: {
2715 5584 ASTFctDefNode* concreteNode = downcastMut<ASTFctDefNode>(this);
2716 5584 manifestations = &concreteNode.node.manifestations;
2717 5584 }
2718 case ASTNodeKind::PROC_DEF: {
2719 6786 ASTProcDefNode* concreteNode = downcastMut<ASTProcDefNode>(this);
2720 6786 manifestations = &concreteNode.node.manifestations;
2721 6786 }
2722 case ASTNodeKind::EXT_DECL: {
2723 946 ASTExtDeclNode* concreteNode = downcastMut<ASTExtDeclNode>(this);
2724 946 manifestations = &concreteNode.extFunctionManifestations;
2725 946 }
2726 case ASTNodeKind::STRUCT_DEF: {
2727 2077 const ASTStructDefNode* concreteNode = downcast<ASTStructDefNode>(this);
2728
2/2
✓ Branch 0 taken 512 times.
✓ Branch 1 taken 1565 times.
2077 if !concreteNode.defaultFctManifestations.contains(fctName) {
2729 1565 concreteNode.defaultFctManifestations.upsert(fctName, Vector<Function*>());
2730 1565 }
2731 2077 manifestations = &concreteNode.defaultFctManifestations.get(fctName);
2732 2077 }
2733 case ASTNodeKind::SIGNATURE: {
2734 7 ASTSignatureNode* concreteNode = downcastMut<ASTSignatureNode>(this);
2735 7 manifestations = &concreteNode.signatureManifestations;
2736 7 }
2737 default: {
2738 ✗ panic(Error("Must be called on a FctDefNode, ProcDefNode, ExtDeclNode, StructDefNode or SignatureNode"));
2739 }
2740 }
2741 15400 return manifestations;
2742 }
2743
2744 /**
2745 * Get the operator overloading functions of a node, that supports operator overloading.
2746 *
2747 * @return Operator overloading functions per manifestation
2748 */
2749 837120 public f<Vector<Vector<const Function*>>*> ASTNode.getOpFctPointers() {
2750 837120 Vector<Vector<const Function*>>* opFctPointers = nil<Vector<Vector<const Function*>>*>;
2751
11/12
✓ Branch 0 taken 135316 times.
✓ Branch 1 taken 1770 times.
✓ Branch 2 taken 301 times.
✓ Branch 3 taken 1110 times.
✓ Branch 4 taken 119455 times.
✓ Branch 5 taken 72982 times.
✓ Branch 6 taken 3868 times.
✓ Branch 7 taken 70595 times.
✓ Branch 8 taken 13811 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 21886 times.
✓ Branch 11 taken 396026 times.
837120 switch this.kind {
2752 case ASTNodeKind::ASSIGN_EXPR: {
2753 135316 ASTAssignExprNode* concreteNode = downcastMut<ASTAssignExprNode>(this);
2754 135316 opFctPointers = &concreteNode.opFct;
2755 135316 }
2756 case ASTNodeKind::BITWISE_OR_EXPR: {
2757 1770 ASTBitwiseOrExprNode* concreteNode = downcastMut<ASTBitwiseOrExprNode>(this);
2758 1770 opFctPointers = &concreteNode.opFct;
2759 1770 }
2760 case ASTNodeKind::BITWISE_XOR_EXPR: {
2761 301 ASTBitwiseXorExprNode* concreteNode = downcastMut<ASTBitwiseXorExprNode>(this);
2762 301 opFctPointers = &concreteNode.opFct;
2763 301 }
2764 case ASTNodeKind::BITWISE_AND_EXPR: {
2765 1110 ASTBitwiseAndExprNode* concreteNode = downcastMut<ASTBitwiseAndExprNode>(this);
2766 1110 opFctPointers = &concreteNode.opFct;
2767 1110 }
2768 case ASTNodeKind::EQUALITY_EXPR: {
2769 119455 ASTEqualityExprNode* concreteNode = downcastMut<ASTEqualityExprNode>(this);
2770 119455 opFctPointers = &concreteNode.opFct;
2771 119455 }
2772 case ASTNodeKind::RELATIONAL_EXPR: {
2773 72982 ASTRelationalExprNode* concreteNode = downcastMut<ASTRelationalExprNode>(this);
2774 72982 opFctPointers = &concreteNode.opFct;
2775 72982 }
2776 case ASTNodeKind::SHIFT_EXPR: {
2777 3868 ASTShiftExprNode* concreteNode = downcastMut<ASTShiftExprNode>(this);
2778 3868 opFctPointers = &concreteNode.opFct;
2779 3868 }
2780 case ASTNodeKind::ADDITIVE_EXPR: {
2781 70595 ASTAdditiveExprNode* concreteNode = downcastMut<ASTAdditiveExprNode>(this);
2782 70595 opFctPointers = &concreteNode.opFct;
2783 70595 }
2784 case ASTNodeKind::MULTIPLICATIVE_EXPR: {
2785 13811 ASTMultiplicativeExprNode* concreteNode = downcastMut<ASTMultiplicativeExprNode>(this);
2786 13811 opFctPointers = &concreteNode.opFct;
2787 13811 }
2788 case ASTNodeKind::PREFIX_UNARY_EXPR: {
2789 21886 ASTPrefixUnaryExprNode* concreteNode = downcastMut<ASTPrefixUnaryExprNode>(this);
2790 21886 opFctPointers = &concreteNode.opFct;
2791 21886 }
2792 case ASTNodeKind::POSTFIX_UNARY_EXPR: {
2793 396026 ASTPostfixUnaryExprNode* concreteNode = downcastMut<ASTPostfixUnaryExprNode>(this);
2794 396026 opFctPointers = &concreteNode.opFct;
2795 396026 }
2796 default: {
2797 ✗ panic(Error("The given node does not overload the getOpFctPointers function"));
2798 }
2799 }
2800 837120 return opFctPointers;
2801 }
2802
2803 /**
2804 * Check if nodes of the given kind store operator overloading functions (getOpFctPointers)
2805 *
2806 * @param kind Node kind
2807 * @return Stores operator overloading functions or not
2808 */
2809 6968276 f<bool> hasOpFctPointers(ASTNodeKind kind) {
2810
2/2
✓ Branch 0 taken 701995 times.
✓ Branch 1 taken 6266281 times.
6968276 switch kind {
2811 case ASTNodeKind::ASSIGN_EXPR, ASTNodeKind::BITWISE_OR_EXPR, ASTNodeKind::BITWISE_XOR_EXPR, ASTNodeKind::BITWISE_AND_EXPR, ASTNodeKind::EQUALITY_EXPR, ASTNodeKind::RELATIONAL_EXPR, ASTNodeKind::SHIFT_EXPR, ASTNodeKind::ADDITIVE_EXPR, ASTNodeKind::MULTIPLICATIVE_EXPR, ASTNodeKind::PREFIX_UNARY_EXPR, ASTNodeKind::POSTFIX_UNARY_EXPR: {
2812 701995 return true;
2813 }
2814 default: {
2815 6266281 return false;
2816 }
2817 }
2818 ✗ }
2819
2820 // Do node-specific work when the AST gets resized to a number of manifestations
2821 6968276 p customItemsInitialization(ASTNode* node, unsigned long manifestationCount) {
2822
2/2
✓ Branch 0 taken 6864787 times.
✓ Branch 1 taken 103489 times.
6968276 if node.kind == ASTNodeKind::ASSIGN_EXPR {
2823 103489 const ASTAssignExprNode* assignExprNode = downcast<ASTAssignExprNode>(node);
2824
2/2
✓ Branch 0 taken 73214 times.
✓ Branch 1 taken 30275 times.
103489 if assignExprNode.lhsDtorFct.isEmpty() {
2825 30275 assignExprNode.lhsDtorFct.reserve(manifestationCount);
2826 30275 }
2827
2/2
✓ Branch 0 taken 44070 times.
✓ Branch 1 taken 103489 times.
147559 while assignExprNode.lhsDtorFct.getSize() < manifestationCount {
2828 44070 assignExprNode.lhsDtorFct.pushBack(nil<const Function*>);
2829 44070 }
2830 103489 }
2831
2/2
✓ Branch 0 taken 6266281 times.
✓ Branch 1 taken 701995 times.
6968276 if hasOpFctPointers(node.kind) {
2832 // Each manifestation starts with one empty operator function slot
2833 701995 Vector<Vector<const Function*>>* opFct = node.getOpFctPointers();
2834
2/2
✓ Branch 0 taken 496029 times.
✓ Branch 1 taken 205966 times.
701995 if opFct.isEmpty() {
2835 205966 opFct.reserve(manifestationCount);
2836 205966 }
2837
2/2
✓ Branch 0 taken 290544 times.
✓ Branch 1 taken 701995 times.
992539 while opFct.getSize() < manifestationCount {
2838 290544 Vector<const Function*> opFctsOfManifestation;
2839 290544 opFctsOfManifestation.pushBack(nil<const Function*>);
2840 290544 opFct.pushBack(opFctsOfManifestation);
2841 290544 }
2842 701995 }
2843
2/2
✓ Branch 0 taken 6696594 times.
✓ Branch 1 taken 271682 times.
6968276 if node.kind == ASTNodeKind::DECL_STMT {
2844 271682 const ASTDeclStmtNode* declStmtNode = downcast<ASTDeclStmtNode>(node);
2845
2/2
✓ Branch 0 taken 187947 times.
✓ Branch 1 taken 83735 times.
271682 if declStmtNode.entries.isEmpty() {
2846 83735 declStmtNode.entries.reserve(manifestationCount);
2847 83735 }
2848
2/2
✓ Branch 0 taken 112621 times.
✓ Branch 1 taken 271682 times.
384303 while declStmtNode.entries.getSize() < manifestationCount {
2849 112621 declStmtNode.entries.pushBack(nil<SymbolTableEntry*>);
2850 112621 }
2851
2/2
✓ Branch 0 taken 187947 times.
✓ Branch 1 taken 83735 times.
271682 if declStmtNode.data.isEmpty() {
2852 83735 declStmtNode.data.reserve(manifestationCount);
2853 83735 }
2854
2/2
✓ Branch 0 taken 112621 times.
✓ Branch 1 taken 271682 times.
384303 while declStmtNode.data.getSize() < manifestationCount {
2855 112621 declStmtNode.data.pushBack(DeclStmtData{});
2856 112621 }
2857 271682 }
2858
2/2
✓ Branch 0 taken 6775083 times.
✓ Branch 1 taken 193193 times.
6968276 if node.kind == ASTNodeKind::ARG_LST {
2859 193193 const ASTArgLstNode* argLstNode = downcast<ASTArgLstNode>(node);
2860
2/2
✓ Branch 0 taken 131618 times.
✓ Branch 1 taken 61575 times.
193193 if argLstNode.argInfos.isEmpty() {
2861 61575 argLstNode.argInfos.reserve(manifestationCount);
2862 61575 }
2863
2/2
✓ Branch 0 taken 78957 times.
✓ Branch 1 taken 193193 times.
272150 while argLstNode.argInfos.getSize() < manifestationCount {
2864 78957 argLstNode.argInfos.pushBack(Vector<ArgInfo>());
2865 78957 }
2866 193193 }
2867
2/2
✓ Branch 0 taken 6959880 times.
✓ Branch 1 taken 8396 times.
6968276 if node.kind == ASTNodeKind::TERNARY_EXPR {
2868 8396 const ASTTernaryExprNode* ternaryExprNode = downcast<ASTTernaryExprNode>(node);
2869
2/2
✓ Branch 0 taken 5798 times.
✓ Branch 1 taken 2598 times.
8396 if ternaryExprNode.data.isEmpty() {
2870 2598 ternaryExprNode.data.reserve(manifestationCount);
2871 2598 }
2872
2/2
✓ Branch 0 taken 3313 times.
✓ Branch 1 taken 8396 times.
11709 while ternaryExprNode.data.getSize() < manifestationCount {
2873 3313 ternaryExprNode.data.pushBack(TernaryExprData{});
2874 3313 }
2875 8396 }
2876
2/2
✓ Branch 0 taken 6604495 times.
✓ Branch 1 taken 363781 times.
6968276 if node.kind == ASTNodeKind::POSTFIX_UNARY_EXPR {
2877 363781 const ASTPostfixUnaryExprNode* postfixUnaryExprNode = downcast<ASTPostfixUnaryExprNode>(node);
2878
2/2
✓ Branch 0 taken 258286 times.
✓ Branch 1 taken 105495 times.
363781 if postfixUnaryExprNode.errPropData.isEmpty() {
2879 105495 postfixUnaryExprNode.errPropData.reserve(manifestationCount);
2880 105495 }
2881
2/2
✓ Branch 0 taken 148223 times.
✓ Branch 1 taken 363781 times.
512004 while postfixUnaryExprNode.errPropData.getSize() < manifestationCount {
2882 148223 postfixUnaryExprNode.errPropData.pushBack(ErrPropagationData{});
2883 148223 }
2884 363781 }
2885
2/2
✓ Branch 0 taken 6715286 times.
✓ Branch 1 taken 252990 times.
6968276 if node.kind == ASTNodeKind::FCT_CALL {
2886 252990 const ASTFctCallNode* fctCallNode = downcast<ASTFctCallNode>(node);
2887
2/2
✓ Branch 0 taken 172100 times.
✓ Branch 1 taken 80890 times.
252990 if fctCallNode.data.isEmpty() {
2888 80890 fctCallNode.data.reserve(manifestationCount);
2889 80890 }
2890
2/2
✓ Branch 0 taken 104868 times.
✓ Branch 1 taken 252990 times.
357858 while fctCallNode.data.getSize() < manifestationCount {
2891 104868 fctCallNode.data.pushBack(FctCallData());
2892 104868 }
2893 252990 }
2894
2/2
✓ Branch 0 taken 6964028 times.
✓ Branch 1 taken 4248 times.
6968276 if node.kind == ASTNodeKind::STRUCT_INSTANTIATION {
2895 4248 const ASTStructInstantiationNode* structInstantiationNode = downcast<ASTStructInstantiationNode>(node);
2896
2/2
✓ Branch 0 taken 2710 times.
✓ Branch 1 taken 1538 times.
4248 if structInstantiationNode.instantiatedStructs.isEmpty() {
2897 1538 structInstantiationNode.instantiatedStructs.reserve(manifestationCount);
2898 1538 }
2899
2/2
✓ Branch 0 taken 1779 times.
✓ Branch 1 taken 4248 times.
6027 while structInstantiationNode.instantiatedStructs.getSize() < manifestationCount {
2900 1779 structInstantiationNode.instantiatedStructs.pushBack(nil<Struct*>);
2901 1779 }
2902
2/2
✓ Branch 0 taken 2710 times.
✓ Branch 1 taken 1538 times.
4248 if structInstantiationNode.fieldCopyCtors.isEmpty() {
2903 1538 structInstantiationNode.fieldCopyCtors.reserve(manifestationCount);
2904 1538 }
2905
2/2
✓ Branch 0 taken 1779 times.
✓ Branch 1 taken 4248 times.
6027 while structInstantiationNode.fieldCopyCtors.getSize() < manifestationCount {
2906 1779 structInstantiationNode.fieldCopyCtors.pushBack(Vector<Function*>());
2907 1779 }
2908 4248 }
2909
6/6
✓ Branch 0 taken 6968133 times.
✓ Branch 1 taken 143 times.
✓ Branch 2 taken 164 times.
✓ Branch 3 taken 6967969 times.
✓ Branch 4 taken 6967961 times.
✓ Branch 5 taken 315 times.
6968276 if node.kind == ASTNodeKind::LAMBDA_FUNC || node.kind == ASTNodeKind::LAMBDA_PROC || node.kind == ASTNodeKind::LAMBDA_EXPR {
2910 // All lambda nodes compose ASTLambdaBaseNode as their first member, so they share the address of their lambda base
2911 315 ASTLambdaBaseNode* lambdaBaseNode = asLambdaBaseNode(node);
2912 315 const ParamList noParams;
2913 315 const Vector<GenericType> noTemplateTypes;
2914
2/2
✓ Branch 0 taken 171 times.
✓ Branch 1 taken 144 times.
315 if lambdaBaseNode.manifestations.isEmpty() {
2915 144 lambdaBaseNode.manifestations.reserve(manifestationCount);
2916 144 }
2917
2/2
✓ Branch 0 taken 158 times.
✓ Branch 1 taken 315 times.
473 while lambdaBaseNode.manifestations.getSize() < manifestationCount {
2918 // Placeholder for a default constructed Function. The type checker replaces it
2919 158 lambdaBaseNode.manifestations.pushBack(Function(String(""), nil<SymbolTableEntry*>, QualType(SuperType::TY_INVALID), QualType(SuperType::TY_INVALID), noParams, noTemplateTypes, node));
2920 158 }
2921 315 }
2922
2/2
✓ Branch 0 taken 6659643 times.
✓ Branch 1 taken 308633 times.
6968276 if node.kind == ASTNodeKind::STMT_LST {
2923 308633 const ASTStmtLstNode* stmtLstNode = downcast<ASTStmtLstNode>(node);
2924
2/2
✓ Branch 0 taken 215978 times.
✓ Branch 1 taken 92655 times.
308633 if stmtLstNode.resourcesToCleanup.isEmpty() {
2925 92655 stmtLstNode.resourcesToCleanup.reserve(manifestationCount);
2926 92655 }
2927
2/2
✓ Branch 0 taken 127003 times.
✓ Branch 1 taken 308633 times.
435636 while stmtLstNode.resourcesToCleanup.getSize() < manifestationCount {
2928 127003 stmtLstNode.resourcesToCleanup.pushBack(ResourcesForManifestationToCleanup{});
2929 127003 }
2930 308633 }
2931
2/2
✓ Branch 0 taken 6953442 times.
✓ Branch 1 taken 14834 times.
6968276 if node.kind == ASTNodeKind::FOR_LOOP {
2932 14834 const ASTForLoopNode* forLoopNode = downcast<ASTForLoopNode>(node);
2933
2/2
✓ Branch 0 taken 10437 times.
✓ Branch 1 taken 4397 times.
14834 if forLoopNode.headResourcesToCleanup.isEmpty() {
2934 4397 forLoopNode.headResourcesToCleanup.reserve(manifestationCount);
2935 4397 }
2936
2/2
✓ Branch 0 taken 6704 times.
✓ Branch 1 taken 14834 times.
21538 while forLoopNode.headResourcesToCleanup.getSize() < manifestationCount {
2937 6704 forLoopNode.headResourcesToCleanup.pushBack(ResourcesForManifestationToCleanup{});
2938 6704 }
2939 14834 }
2940
2/2
✓ Branch 0 taken 6967203 times.
✓ Branch 1 taken 1073 times.
6968276 if node.kind == ASTNodeKind::FOREACH_LOOP {
2941 1073 const ASTForeachLoopNode* foreachLoopNode = downcast<ASTForeachLoopNode>(node);
2942
2/2
✓ Branch 0 taken 639 times.
✓ Branch 1 taken 434 times.
1073 if foreachLoopNode.headResourcesToCleanup.isEmpty() {
2943 434 foreachLoopNode.headResourcesToCleanup.reserve(manifestationCount);
2944 434 }
2945
2/2
✓ Branch 0 taken 614 times.
✓ Branch 1 taken 1073 times.
1687 while foreachLoopNode.headResourcesToCleanup.getSize() < manifestationCount {
2946 614 foreachLoopNode.headResourcesToCleanup.pushBack(ResourcesForManifestationToCleanup{});
2947 614 }
2948
2/2
✓ Branch 0 taken 639 times.
✓ Branch 1 taken 434 times.
1073 if foreachLoopNode.data.isEmpty() {
2949 434 foreachLoopNode.data.reserve(manifestationCount);
2950 434 }
2951
2/2
✓ Branch 0 taken 614 times.
✓ Branch 1 taken 1073 times.
1687 while foreachLoopNode.data.getSize() < manifestationCount {
2952 614 foreachLoopNode.data.pushBack(ForeachLoopData{});
2953 614 }
2954 1073 }
2955
2/2
✓ Branch 0 taken 6835136 times.
✓ Branch 1 taken 133140 times.
6968276 if node.kind == ASTNodeKind::RETURN_STMT {
2956 133140 const ASTReturnStmtNode* returnStmtNode = downcast<ASTReturnStmtNode>(node);
2957
2/2
✓ Branch 0 taken 92938 times.
✓ Branch 1 taken 40202 times.
133140 if returnStmtNode.returnedLocals.isEmpty() {
2958 40202 returnStmtNode.returnedLocals.reserve(manifestationCount);
2959 40202 }
2960
2/2
✓ Branch 0 taken 53156 times.
✓ Branch 1 taken 133140 times.
186296 while returnStmtNode.returnedLocals.getSize() < manifestationCount {
2961 53156 returnStmtNode.returnedLocals.pushBack(nil<SymbolTableEntry*>);
2962 53156 }
2963
2/2
✓ Branch 0 taken 92938 times.
✓ Branch 1 taken 40202 times.
133140 if returnStmtNode.data.isEmpty() {
2964 40202 returnStmtNode.data.reserve(manifestationCount);
2965 40202 }
2966
2/2
✓ Branch 0 taken 53156 times.
✓ Branch 1 taken 133140 times.
186296 while returnStmtNode.data.getSize() < manifestationCount {
2967 53156 returnStmtNode.data.pushBack(ReturnStmtData());
2968 53156 }
2969 133140 }
2970
2/2
✓ Branch 0 taken 5662685 times.
✓ Branch 1 taken 1305591 times.
6968276 if node.kind == ASTNodeKind::ATOMIC_EXPR {
2971 1305591 const ASTAtomicExprNode* atomicExprNode = downcast<ASTAtomicExprNode>(node);
2972
2/2
✓ Branch 0 taken 907391 times.
✓ Branch 1 taken 398200 times.
1305591 if atomicExprNode.data.isEmpty() {
2973 398200 atomicExprNode.data.reserve(manifestationCount);
2974 398200 }
2975
2/2
✓ Branch 0 taken 540247 times.
✓ Branch 1 taken 1305591 times.
1845838 while atomicExprNode.data.getSize() < manifestationCount {
2976 540247 atomicExprNode.data.pushBack(VarAccessData{});
2977 540247 }
2978 1305591 }
2979
2/2
✓ Branch 0 taken 6880824 times.
✓ Branch 1 taken 87452 times.
6968276 if node.kind == ASTNodeKind::IF_STMT {
2980 87452 const ASTIfStmtNode* ifStmtNode = downcast<ASTIfStmtNode>(node);
2981
2/2
✓ Branch 0 taken 62302 times.
✓ Branch 1 taken 25150 times.
87452 if ifStmtNode.compileThenBranch.isEmpty() {
2982 25150 ifStmtNode.compileThenBranch.reserve(manifestationCount);
2983 25150 }
2984
2/2
✓ Branch 0 taken 36174 times.
✓ Branch 1 taken 87452 times.
123626 while ifStmtNode.compileThenBranch.getSize() < manifestationCount {
2985 36174 ifStmtNode.compileThenBranch.pushBack(true);
2986 36174 }
2987
2/2
✓ Branch 0 taken 62302 times.
✓ Branch 1 taken 25150 times.
87452 if ifStmtNode.compileElseBranch.isEmpty() {
2988 25150 ifStmtNode.compileElseBranch.reserve(manifestationCount);
2989 25150 }
2990
2/2
✓ Branch 0 taken 36174 times.
✓ Branch 1 taken 87452 times.
123626 while ifStmtNode.compileElseBranch.getSize() < manifestationCount {
2991 36174 ifStmtNode.compileElseBranch.pushBack(true);
2992 36174 }
2993 87452 }
2994 6968276 }
2995
2996 /**
2997 * Check if the given node returns on all control paths
2998 *
2999 * @param doSetPredecessorsUnreachable Whether statements after a returning statement are marked as unreachable. Can be
3000 * reset by the callee, if the return statement is only a modification of the result
3001 * @param manIdx Manifestation index
3002 * @return Returns on all control paths or not
3003 */
3004 407105 public f<bool> ASTNode.returnsOnAllControlPaths(bool* doSetPredecessorsUnreachable, unsigned long manIdx) {
3005
18/18
✓ Branch 0 taken 974 times.
✓ Branch 1 taken 28088 times.
✓ Branch 2 taken 17620 times.
✓ Branch 3 taken 3786 times.
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 28125 times.
✓ Branch 6 taken 67 times.
✓ Branch 7 taken 161821 times.
✓ Branch 8 taken 1745 times.
✓ Branch 9 taken 18 times.
✓ Branch 10 taken 21034 times.
✓ Branch 11 taken 45 times.
✓ Branch 12 taken 37 times.
✓ Branch 13 taken 136 times.
✓ Branch 14 taken 79555 times.
✓ Branch 15 taken 38613 times.
✓ Branch 16 taken 25359 times.
✓ Branch 17 taken 73 times.
407105 switch this.kind {
3006 case ASTNodeKind::MAIN_FCT_DEF: {
3007 974 const ASTMainFctDefNode* mainFctDefNode = downcast<ASTMainFctDefNode>(this);
3008 974 return returnsOnAllControlPaths(mainFctDefNode.body, doSetPredecessorsUnreachable, manIdx);
3009 }
3010 case ASTNodeKind::FCT_DEF: {
3011 28088 const ASTFctDefNode* fctDefNode = downcast<ASTFctDefNode>(this);
3012 28088 return returnsOnAllControlPaths(fctDefNode.body, doSetPredecessorsUnreachable, manIdx);
3013 }
3014 case ASTNodeKind::PROC_DEF: {
3015 17620 const ASTProcDefNode* procDefNode = downcast<ASTProcDefNode>(this);
3016 17620 return returnsOnAllControlPaths(procDefNode.body, doSetPredecessorsUnreachable, manIdx);
3017 }
3018 case ASTNodeKind::FOR_LOOP: {
3019 // If we have the guarantee that the loop condition is always true and the loop body returns on all control paths,
3020 // we can assume that the loop itself will always return
3021 3786 const ASTForLoopNode* forLoopNode = downcast<ASTForLoopNode>(this);
3022 3786 const bool condAlwaysTrue = isAlwaysTrue(forLoopNode.condAssign, manIdx);
3023
1/2
✓ Branch 0 taken 3786 times.
✗ Branch 1 not taken.
3786 return condAlwaysTrue && returnsOnAllControlPaths(forLoopNode.body, doSetPredecessorsUnreachable, manIdx);
3024 }
3025 case ASTNodeKind::WHILE_LOOP: {
3026 // If we have the guarantee that the loop condition is always true and the loop body returns on all control paths,
3027 // we can assume that the loop itself will always return
3028 1745 const ASTWhileLoopNode* whileLoopNode = downcast<ASTWhileLoopNode>(this);
3029 1745 const bool condAlwaysTrue = isAlwaysTrue(whileLoopNode.condition, manIdx);
3030
2/2
✓ Branch 0 taken 1643 times.
✓ Branch 1 taken 102 times.
1745 return condAlwaysTrue && returnsOnAllControlPaths(whileLoopNode.body, doSetPredecessorsUnreachable, manIdx);
3031 }
3032 case ASTNodeKind::DO_WHILE_LOOP: {
3033 // Do-while loops will always be executed at least once. So if the body returns on all control paths, the loop will as well
3034 18 const ASTDoWhileLoopNode* doWhileLoopNode = downcast<ASTDoWhileLoopNode>(this);
3035 18 return returnsOnAllControlPaths(doWhileLoopNode.body, doSetPredecessorsUnreachable, manIdx);
3036 }
3037 case ASTNodeKind::IF_STMT: {
3038 21034 const ASTIfStmtNode* ifStmtNode = downcast<ASTIfStmtNode>(this);
3039 // If the condition always evaluates to 'true' the then block must return
3040
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21034 times.
21034 if !ifStmtNode.doCompileElseBranch(manIdx) {
3041 ✗ return returnsOnAllControlPaths(ifStmtNode.thenBody, doSetPredecessorsUnreachable, manIdx);
3042 }
3043 // If the condition always evaluates to 'false' the else block must return
3044 21034 const bool hasElseStmt = ifStmtNode.elseStmt != nil<IVisitable*>;
3045
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21034 times.
21034 if !ifStmtNode.doCompileThenBranch(manIdx) {
3046
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ return hasElseStmt && returnsOnAllControlPaths(ifStmtNode.elseStmt, doSetPredecessorsUnreachable, manIdx);
3047 }
3048 // If the condition does not always evaluate to 'true' or 'false' we need to check both branches
3049
4/4
✓ Branch 0 taken 15507 times.
✓ Branch 1 taken 5527 times.
✓ Branch 2 taken 15462 times.
✓ Branch 3 taken 45 times.
21079 return returnsOnAllControlPaths(ifStmtNode.thenBody, doSetPredecessorsUnreachable, manIdx) && hasElseStmt
3050 21034 && returnsOnAllControlPaths(ifStmtNode.elseStmt, doSetPredecessorsUnreachable, manIdx);
3051 }
3052 case ASTNodeKind::ELSE_STMT: {
3053 45 const ASTElseStmtNode* elseStmtNode = downcast<ASTElseStmtNode>(this);
3054
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 15 times.
45 if elseStmtNode.isElseIf {
3055 30 return returnsOnAllControlPaths(elseStmtNode.ifStmt, doSetPredecessorsUnreachable, manIdx);
3056 }
3057 15 return returnsOnAllControlPaths(elseStmtNode.body, doSetPredecessorsUnreachable, manIdx);
3058 }
3059 case ASTNodeKind::SWITCH_STMT: {
3060 37 const ASTSwitchStmtNode* switchStmtNode = downcast<ASTSwitchStmtNode>(this);
3061
2/2
✓ Branch 0 taken 136 times.
✓ Branch 1 taken 22 times.
158 foreach IVisitable* caseBranch : switchStmtNode.caseBranches {
3062
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 121 times.
136 if !returnsOnAllControlPaths(caseBranch, doSetPredecessorsUnreachable, manIdx) {
3063 15 return false;
3064 }
3065 121 }
3066 // Without a default branch, the control flow continues after the switch if no case matches. The only exception is
3067 // a switch, that is exhaustive, because its cases cover all items of an enum
3068
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 13 times.
22 if switchStmtNode.defaultBranch == nil<IVisitable*> {
3069 13 return switchStmtNode.coversAllEnumItems;
3070 }
3071 9 return returnsOnAllControlPaths(switchStmtNode.defaultBranch, doSetPredecessorsUnreachable, manIdx);
3072 }
3073 case ASTNodeKind::CASE_BRANCH: {
3074 136 const ASTCaseBranchNode* caseBranchNode = downcast<ASTCaseBranchNode>(this);
3075 136 return returnsOnAllControlPaths(caseBranchNode.body, doSetPredecessorsUnreachable, manIdx);
3076 }
3077 case ASTNodeKind::DEFAULT_BRANCH: {
3078 9 const ASTDefaultBranchNode* defaultBranchNode = downcast<ASTDefaultBranchNode>(this);
3079 9 return returnsOnAllControlPaths(defaultBranchNode.body, doSetPredecessorsUnreachable, manIdx);
3080 }
3081 case ASTNodeKind::STMT_LST: {
3082 79555 const ASTStmtLstNode* stmtLstNode = downcast<ASTStmtLstNode>(this);
3083 // An empty statement list does not return at all
3084
2/2
✓ Branch 0 taken 174 times.
✓ Branch 1 taken 79381 times.
79555 if stmtLstNode.statements.isEmpty() {
3085 174 return false;
3086 }
3087 // A statement list returns on all control paths, if the one direct child statement returns on all control paths
3088 79381 bool returnsOnAllPaths = false;
3089
2/2
✓ Branch 0 taken 79381 times.
✓ Branch 1 taken 157363 times.
236744 foreach IVisitable* child : stmtLstNode.statements {
3090 157363 assert child != nil<IVisitable*>;
3091 157363 ASTNode* childNode = getASTNode(child);
3092
3093 // Prevent marking instructions as unreachable if doSetPredecessorsUnreachable is set to false
3094
4/4
✓ Branch 0 taken 154686 times.
✓ Branch 1 taken 2677 times.
✓ Branch 2 taken 157360 times.
✓ Branch 3 taken 3 times.
157363 if returnsOnAllPaths && *doSetPredecessorsUnreachable {
3095 3 ASTStmtNode* stmtNode = asStmtNode(childNode);
3096 3 stmtNode.unreachable = true;
3097 3 }
3098
3099
2/2
✓ Branch 0 taken 109190 times.
✓ Branch 1 taken 48173 times.
157363 if childNode.returnsOnAllControlPaths(doSetPredecessorsUnreachable, manIdx) {
3100 48173 returnsOnAllPaths = true;
3101 48173 }
3102 157363 }
3103 79381 return returnsOnAllPaths;
3104 }
3105 case ASTNodeKind::RETURN_STMT: {
3106 38613 return true;
3107 }
3108 case ASTNodeKind::ASSIGN_EXPR: {
3109 25359 const ASTAssignExprNode* assignExprNode = downcast<ASTAssignExprNode>(this);
3110 // If it's a ternary, do the default thing
3111
1/2
✓ Branch 0 taken 25359 times.
✗ Branch 1 not taken.
25359 if assignExprNode.op == AssignOp::OP_NONE {
3112 ✗ return returnsOnAllControlPaths(assignExprNode.ternaryExpr, doSetPredecessorsUnreachable, manIdx);
3113 }
3114
3115 // If it's a modification on the result variable, we technically return from the function, but at the end of the function.
3116 25359 ASTAtomicExprNode* atomicExpr = assignExprNode.getLhsAtomicNode();
3117
4/4
✓ Branch 0 taken 295 times.
✓ Branch 1 taken 25064 times.
✓ Branch 2 taken 2410 times.
✓ Branch 3 taken 22949 times.
25359 if atomicExpr != nil<ASTAtomicExprNode*> && atomicExpr.fqIdentifier == RETURN_VARIABLE_NAME {
3118 // If we assign the result variable, we technically return from the function, but at the end of the function.
3119 // Therefore, the following code is not unreachable, but will be executed in any case.
3120 2410 *doSetPredecessorsUnreachable = false;
3121 2410 return true;
3122 }
3123
3124 22949 return false;
3125 }
3126 case ASTNodeKind::FCT_CALL: {
3127 // Some builtin functions terminate the control flow, e.g. panic
3128 28125 const ASTFctCallNode* fctCallNode = downcast<ASTFctCallNode>(this);
3129 28125 BuiltinFunctionInfo builtinFunctionInfo;
3130
2/2
✓ Branch 0 taken 21936 times.
✓ Branch 1 taken 6189 times.
28125 return lookupBuiltinFunction(fctCallNode.fqFunctionName, builtinFunctionInfo) && builtinFunctionInfo.isFunctionTerminator;
3131 }
3132 case ASTNodeKind::LAMBDA_FUNC: {
3133 67 const ASTLambdaFuncNode* lambdaFuncNode = downcast<ASTLambdaFuncNode>(this);
3134 67 return returnsOnAllControlPaths(lambdaFuncNode.body, doSetPredecessorsUnreachable, manIdx);
3135 }
3136 case ASTNodeKind::LAMBDA_PROC: {
3137 73 const ASTLambdaProcNode* lambdaProcNode = downcast<ASTLambdaProcNode>(this);
3138 73 return returnsOnAllControlPaths(lambdaProcNode.body, doSetPredecessorsUnreachable, manIdx);
3139 }
3140 }
3141 // Default behavior: Returns on all control paths if the only child does
3142
2/2
✓ Branch 0 taken 27253 times.
✓ Branch 1 taken 134568 times.
161821 if this.children.getSize() != 1l {
3143 27253 return false;
3144 }
3145 134568 ASTNode* onlyChild = this.children.front();
3146 134568 return onlyChild.returnsOnAllControlPaths(doSetPredecessorsUnreachable, manIdx);
3147 }
3148
3149 // Shorthand for calling returnsOnAllControlPaths on a node, that is stored as IVisitable*
3150 68356 f<bool> returnsOnAllControlPaths(IVisitable* node, bool* doSetPredecessorsUnreachable, unsigned long manIdx) {
3151 68356 ASTNode* astNode = getASTNode(node);
3152 68356 return astNode.returnsOnAllControlPaths(doSetPredecessorsUnreachable, manIdx);
3153 }
3154
3155 // Check if the given node has a compile time value, which is 'true'
3156 5533 f<bool> isAlwaysTrue(IVisitable* node, unsigned long manIdx) {
3157 5533 ASTNode* astNode = getASTNode(node);
3158
2/2
✓ Branch 0 taken 5428 times.
✓ Branch 1 taken 105 times.
5533 if !astNode.hasCompileTimeValue(manIdx) {
3159 5428 return false;
3160 }
3161 105 const CompileTimeValue compileTimeValue = astNode.getCompileTimeValue(manIdx);
3162 105 return compileTimeValue.getBoolValue();
3163 }
3164
3165 /**
3166 * Check if the node is a function or procedure definition
3167 *
3168 * @return Function or procedure definition or not
3169 */
3170 5569602 public f<bool> ASTNode.isFctOrProcDef() {
3171
3/4
✓ Branch 0 taken 5569602 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2151411 times.
✓ Branch 3 taken 3418191 times.
5569602 return this.kind == ASTNodeKind::MAIN_FCT_DEF || this.kind == ASTNodeKind::FCT_DEF || this.kind == ASTNodeKind::PROC_DEF;
3172 }
3173
3174 /**
3175 * Get the signature of the function/procedure, this node defines
3176 *
3177 * @param manIdx Manifestation index
3178 * @return Function signature
3179 */
3180 8 public f<String> ASTNode.getFunctionSignature(unsigned long manIdx) {
3181 8 assert this.isFctOrProcDef(); // Must be called on a function/procedure def node
3182
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if this.kind == ASTNodeKind::MAIN_FCT_DEF {
3183 ✗ return String("f<int> main()");
3184 }
3185 8 ASTFctDefBaseNode* fctDefBaseNode = nil<ASTFctDefBaseNode*>;
3186
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if this.kind == ASTNodeKind::FCT_DEF {
3187 8 ASTFctDefNode* fctDefNode = downcastMut<ASTFctDefNode>(this);
3188 8 fctDefBaseNode = &fctDefNode.node;
3189 8 } else {
3190 ✗ ASTProcDefNode* procDefNode = downcastMut<ASTProcDefNode>(this);
3191 ✗ fctDefBaseNode = &procDefNode.node;
3192 ✗ }
3193 8 assert manIdx < fctDefBaseNode.manifestations.getSize();
3194 8 const Function* manifestation = fctDefBaseNode.manifestations.get(manIdx);
3195 8 return manifestation.getSignature();
3196 }
3197
3198 /**
3199 * Get the next statement list, this node is part of (the node itself, if it is a statement list)
3200 *
3201 * @return Next outer statement list
3202 */
3203 152399 public f<ASTStmtLstNode*> ASTNode.getNextOuterStmtLst() {
3204 152399 assert this.parent != nil<ASTNode*>;
3205
2/2
✓ Branch 0 taken 71546 times.
✓ Branch 1 taken 80853 times.
152399 if this.kind == ASTNodeKind::STMT_LST {
3206 71546 return downcastMut<ASTStmtLstNode>(this);
3207 }
3208 80853 return this.parent.getNextOuterStmtLst();
3209 }
3210
3211 /**
3212 * Get the signature of the function/procedure, this node is located in
3213 *
3214 * @param manIdx Manifestation index
3215 * @return Function signature
3216 */
3217 48 public f<String> ASTNode.getEnclosingFunctionSignature(unsigned long manIdx) {
3218 48 assert this.parent != nil<ASTNode*>;
3219
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 40 times.
48 if this.isFctOrProcDef() {
3220 8 return this.getFunctionSignature(manIdx);
3221 }
3222 40 return this.parent.getEnclosingFunctionSignature(manIdx);
3223 }
3224
3225 /**
3226 * Check if the node is a struct definition
3227 *
3228 * @return Struct definition or not
3229 */
3230 1016052 public f<bool> ASTNode.isStructDef() {
3231 1016052 return this.kind == ASTNodeKind::STRUCT_DEF;
3232 }
3233
3234 /**
3235 * Check if the node is a union definition
3236 *
3237 * @return Union definition or not
3238 */
3239 915055 public f<bool> ASTNode.isUnionDef() {
3240 915055 return this.kind == ASTNodeKind::UNION_DEF;
3241 }
3242
3243 /**
3244 * Check if the given node has a value, that is known at compile time
3245 *
3246 * @param manIdx Manifestation index
3247 * @return Has compile time value or not
3248 */
3249 122912 public f<bool> ASTNode.hasCompileTimeValue(unsigned long manIdx) {
3250
9/11
✓ Branch 0 taken 6944 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 36285 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 39860 times.
✓ Branch 6 taken 978 times.
✓ Branch 7 taken 2943 times.
✓ Branch 8 taken 11632 times.
✓ Branch 9 taken 7605 times.
✓ Branch 10 taken 16647 times.
122912 switch this.kind {
3251 case ASTNodeKind::CONSTANT: {
3252 6944 return true;
3253 }
3254 case ASTNodeKind::GLOBAL_VAR_DEF: {
3255 ✗ return true;
3256 }
3257 case ASTNodeKind::TERNARY_EXPR: {
3258 18 const ASTTernaryExprNode* ternaryExprNode = downcast<ASTTernaryExprNode>(this);
3259
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 const bool trueExprHasCompileTimeValue = ternaryExprNode.trueExpr == nil<IVisitable*> || hasCompileTimeValue(ternaryExprNode.trueExpr, manIdx);
3260
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 const bool falseExprHasCompileTimeValue = ternaryExprNode.falseExpr == nil<IVisitable*> || hasCompileTimeValue(ternaryExprNode.falseExpr, manIdx);
3261
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18 return hasCompileTimeValue(ternaryExprNode.condition, manIdx) && trueExprHasCompileTimeValue && falseExprHasCompileTimeValue;
3262 }
3263 case ASTNodeKind::LOGICAL_OR_EXPR,
3264 ASTNodeKind::LOGICAL_AND_EXPR,
3265 ASTNodeKind::BITWISE_OR_EXPR,
3266 ASTNodeKind::BITWISE_XOR_EXPR,
3267 ASTNodeKind::BITWISE_AND_EXPR,
3268 ASTNodeKind::EQUALITY_EXPR,
3269 ASTNodeKind::RELATIONAL_EXPR,
3270 ASTNodeKind::SHIFT_EXPR,
3271 ASTNodeKind::ADDITIVE_EXPR,
3272 ASTNodeKind::MULTIPLICATIVE_EXPR: {
3273 // All operands of these nodes are its children
3274
2/2
✓ Branch 0 taken 36388 times.
✓ Branch 1 taken 84 times.
36472 foreach ASTNode* operand : this.children {
3275
2/2
✓ Branch 0 taken 36201 times.
✓ Branch 1 taken 187 times.
36388 if !operand.hasCompileTimeValue(manIdx) {
3276 36201 return false;
3277 }
3278 187 }
3279 84 return true;
3280 }
3281 case ASTNodeKind::CAST_EXPR: {
3282 978 const ASTCastExprNode* castExprNode = downcast<ASTCastExprNode>(this);
3283
1/2
✓ Branch 0 taken 978 times.
✗ Branch 1 not taken.
978 return castExprNode.isCast ? hasCompileTimeValue(castExprNode.assignExpr, manIdx) : hasCompileTimeValue(castExprNode.prefixUnaryExpr, manIdx);
3284 }
3285 case ASTNodeKind::PREFIX_UNARY_EXPR: {
3286 2943 const ASTPrefixUnaryExprNode* prefixUnaryExprNode = downcast<ASTPrefixUnaryExprNode>(this);
3287
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2943 times.
2943 if prefixUnaryExprNode.postfixUnaryExpr != nil<IVisitable*> {
3288 ✗ return hasCompileTimeValue(prefixUnaryExprNode.postfixUnaryExpr, manIdx);
3289 }
3290 2943 const PrefixUnaryOp op = prefixUnaryExprNode.op;
3291
4/6
✓ Branch 0 taken 2943 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2923 times.
✓ Branch 3 taken 20 times.
✓ Branch 4 taken 2923 times.
✗ Branch 5 not taken.
2943 const bool isSupported = op == PrefixUnaryOp::OP_NONE || op == PrefixUnaryOp::OP_MINUS || op == PrefixUnaryOp::OP_PLUS_PLUS
3292
3/4
✓ Branch 0 taken 2923 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2734 times.
✓ Branch 3 taken 189 times.
2943 || op == PrefixUnaryOp::OP_MINUS_MINUS || op == PrefixUnaryOp::OP_NOT || op == PrefixUnaryOp::OP_BITWISE_NOT;
3293
2/2
✓ Branch 0 taken 188 times.
✓ Branch 1 taken 2755 times.
2943 return isSupported && hasCompileTimeValue(prefixUnaryExprNode.prefixUnaryExpr, manIdx);
3294 }
3295 case ASTNodeKind::POSTFIX_UNARY_EXPR: {
3296 11632 const ASTPostfixUnaryExprNode* postfixUnaryExprNode = downcast<ASTPostfixUnaryExprNode>(this);
3297
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11632 times.
11632 if postfixUnaryExprNode.atomicExpr != nil<IVisitable*> {
3298 ✗ return hasCompileTimeValue(postfixUnaryExprNode.atomicExpr, manIdx);
3299 }
3300 11632 const PostfixUnaryOp op = postfixUnaryExprNode.op;
3301
2/4
✓ Branch 0 taken 11632 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11632 times.
11632 const bool isSupported = op == PostfixUnaryOp::OP_NONE || op == PostfixUnaryOp::OP_PLUS_PLUS || op == PostfixUnaryOp::OP_MINUS_MINUS;
3302
2/2
✓ Branch 0 taken 11629 times.
✓ Branch 1 taken 3 times.
11632 return isSupported && hasCompileTimeValue(postfixUnaryExprNode.postfixUnaryExpr, manIdx);
3303 }
3304 case ASTNodeKind::VALUE: {
3305 7605 const ASTValueNode* valueNode = downcast<ASTValueNode>(this);
3306
2/2
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 7560 times.
7605 if valueNode.isNil {
3307 45 return true;
3308 }
3309 7560 }
3310 case ASTNodeKind::FCT_CALL: {
3311 16647 const ASTFctCallNode* fctCallNode = downcast<ASTFctCallNode>(this);
3312 16647 BuiltinFunctionInfo builtinFunctionInfo;
3313
2/2
✓ Branch 0 taken 7115 times.
✓ Branch 1 taken 9532 times.
16647 if !lookupBuiltinFunction(fctCallNode.fqFunctionName, builtinFunctionInfo) {
3314 7115 return false;
3315 }
3316 9532 const FctCallData& fctCallData = fctCallNode.data.get(manIdx);
3317 9532 return fctCallData.hasCompileTimeValue();
3318 }
3319 case ASTNodeKind::LAMBDA_FUNC, ASTNodeKind::LAMBDA_PROC, ASTNodeKind::LAMBDA_EXPR: {
3320 ✗ return false;
3321 }
3322 }
3323 // Default behavior: Has a compile time value if the only child has one
3324
2/2
✓ Branch 0 taken 25108 times.
✓ Branch 1 taken 22312 times.
47420 if this.children.getSize() != 1l {
3325 25108 return false;
3326 }
3327 22312 ASTNode* onlyChild = this.children.front();
3328 22312 return onlyChild.hasCompileTimeValue(manIdx);
3329 }
3330
3331 // Shorthand for calling hasCompileTimeValue on a node, that is stored as IVisitable*
3332 3790 f<bool> hasCompileTimeValue(IVisitable* node, unsigned long manIdx) {
3333 3790 ASTNode* astNode = getASTNode(node);
3334 3790 return astNode.hasCompileTimeValue(manIdx);
3335 }
3336
3337 /**
3338 * Get the value of the given node, that is known at compile time
3339 *
3340 * @param manIdx Manifestation index
3341 * @return Compile time value
3342 */
3343 95721 public f<CompileTimeValue> ASTNode.getCompileTimeValue(unsigned long manIdx) {
3344 95721 CompileTimeValue compileTimeValue;
3345
12/18
✓ Branch 0 taken 84966 times.
✓ Branch 1 taken 420 times.
✓ Branch 2 taken 94 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7448 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 16 times.
✓ Branch 9 taken 49 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 336 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 879 times.
✓ Branch 17 taken 1504 times.
95721 switch this.kind {
3346 case ASTNodeKind::CONSTANT: {
3347 84966 const ASTConstantNode* constantNode = downcast<ASTConstantNode>(this);
3348 84966 return constantNode.compileTimeValue;
3349 }
3350 case ASTNodeKind::GLOBAL_VAR_DEF: {
3351 420 const ASTGlobalVarDefNode* globalVarDefNode = downcast<ASTGlobalVarDefNode>(this);
3352 420 ASTNode* constantNode = cast<ASTNode*>(globalVarDefNode.constant);
3353 420 return constantNode.getCompileTimeValue(manIdx);
3354 }
3355 case ASTNodeKind::ENUM_ITEM: {
3356 94 const ASTEnumItemNode* enumItemNode = downcast<ASTEnumItemNode>(this);
3357 94 compileTimeValue.setIntValue(cast<int>(enumItemNode.itemValue));
3358 94 return compileTimeValue;
3359 }
3360 case ASTNodeKind::TERNARY_EXPR: {
3361 ✗ const ASTTernaryExprNode* ternaryExprNode = downcast<ASTTernaryExprNode>(this);
3362 ✗ assert ternaryExprNode.condition != nil<IVisitable*>;
3363
0/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ if ternaryExprNode.trueExpr == nil<IVisitable*> && ternaryExprNode.falseExpr == nil<IVisitable*> {
3364 ✗ return getCompileTimeValue(ternaryExprNode.condition, manIdx);
3365 }
3366
3367 // If the condition has no compile time value, we do not need to evaluate the true and false values
3368
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ if !hasCompileTimeValue(ternaryExprNode.condition, manIdx) {
3369 ✗ return compileTimeValue;
3370 }
3371
3372 // Check if the condition always evaluates to 'true'
3373 ✗ const CompileTimeValue conditionValue = getCompileTimeValue(ternaryExprNode.condition, manIdx);
3374
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ if conditionValue.getBoolValue() {
3375
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ IVisitable* trueValue = ternaryExprNode.isShortened ? ternaryExprNode.condition : ternaryExprNode.trueExpr;
3376 ✗ assert trueValue != nil<IVisitable*>;
3377 ✗ return getCompileTimeValue(trueValue, manIdx);
3378 }
3379
3380 ✗ assert ternaryExprNode.falseExpr != nil<IVisitable*>;
3381 ✗ return getCompileTimeValue(ternaryExprNode.falseExpr, manIdx);
3382 }
3383 case ASTNodeKind::LOGICAL_OR_EXPR: {
3384
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 if this.children.getSize() == 1l {
3385 ✗ return getChildCompileTimeValue(this, 0l, manIdx);
3386 }
3387 // Check if one expression evaluates to 'true'
3388
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 foreach ASTNode* operand : this.children {
3389 2 assert operand.hasCompileTimeValue(manIdx);
3390 // If one operand evaluates to 'true' the whole expression is 'true'
3391 2 const CompileTimeValue operandValue = operand.getCompileTimeValue(manIdx);
3392
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
2 if operandValue.getBoolValue() {
3393 1 compileTimeValue.setBoolValue(true);
3394 1 return compileTimeValue;
3395 }
3396 1 }
3397 // Return 'false'
3398 ✗ compileTimeValue.setBoolValue(false);
3399 ✗ return compileTimeValue;
3400 }
3401 case ASTNodeKind::LOGICAL_AND_EXPR: {
3402
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if this.children.getSize() == 1l {
3403 ✗ return getChildCompileTimeValue(this, 0l, manIdx);
3404 }
3405 // Check if all expressions evaluate to 'true'
3406
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 5 times.
20 foreach ASTNode* operand : this.children {
3407 15 assert operand.hasCompileTimeValue(manIdx);
3408 // If one operand evaluates to 'false' the whole expression is 'false'
3409 15 const CompileTimeValue operandValue = operand.getCompileTimeValue(manIdx);
3410
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 14 times.
15 if !operandValue.getBoolValue() {
3411 1 compileTimeValue.setBoolValue(false);
3412 1 return compileTimeValue;
3413 }
3414 14 }
3415 // All operands evaluate to 'true'
3416 5 compileTimeValue.setBoolValue(true);
3417 5 return compileTimeValue;
3418 }
3419 case ASTNodeKind::BITWISE_OR_EXPR, ASTNodeKind::BITWISE_XOR_EXPR, ASTNodeKind::BITWISE_AND_EXPR: {
3420
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ if this.children.getSize() == 1l {
3421 ✗ return getChildCompileTimeValue(this, 0l, manIdx);
3422 }
3423 ✗ compileTimeValue = getChildCompileTimeValue(this, 0l, manIdx);
3424
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ for unsigned long i = 1l; i < this.children.getSize(); i++ {
3425 ✗ ASTNode* operand = this.children.get(i);
3426 ✗ assert operand.hasCompileTimeValue(manIdx);
3427 ✗ const CompileTimeValue operandValue = operand.getCompileTimeValue(manIdx);
3428
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ if this.kind == ASTNodeKind::BITWISE_OR_EXPR {
3429 ✗ compileTimeValue.setLongValue(compileTimeValue.getLongValue() | operandValue.getLongValue());
3430
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ } else if this.kind == ASTNodeKind::BITWISE_XOR_EXPR {
3431 ✗ compileTimeValue.setLongValue(compileTimeValue.getLongValue() ^ operandValue.getLongValue());
3432 ✗ } else {
3433 ✗ compileTimeValue.setLongValue(compileTimeValue.getLongValue() & operandValue.getLongValue());
3434 ✗ }
3435 ✗ }
3436 ✗ return compileTimeValue;
3437 }
3438 case ASTNodeKind::EQUALITY_EXPR: {
3439
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if this.children.getSize() == 1l {
3440 ✗ return getChildCompileTimeValue(this, 0l, manIdx);
3441 }
3442 16 const ASTEqualityExprNode* equalityExprNode = downcast<ASTEqualityExprNode>(this);
3443 16 const CompileTimeValue op0Value = getChildCompileTimeValue(this, 0l, manIdx);
3444 16 const CompileTimeValue op1Value = getChildCompileTimeValue(this, 1l, manIdx);
3445
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 2 times.
16 if equalityExprNode.op == EqualityOp::OP_EQUAL {
3446 14 compileTimeValue.setBoolValue(op0Value.getLongValue() == op1Value.getLongValue());
3447 14 } else {
3448 2 assert equalityExprNode.op == EqualityOp::OP_NOT_EQUAL;
3449 2 compileTimeValue.setBoolValue(op0Value.getLongValue() != op1Value.getLongValue());
3450 2 }
3451 16 return compileTimeValue;
3452 }
3453 case ASTNodeKind::RELATIONAL_EXPR: {
3454
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 49 times.
49 if this.children.getSize() == 1l {
3455 ✗ return getChildCompileTimeValue(this, 0l, manIdx);
3456 }
3457 49 const ASTRelationalExprNode* relationalExprNode = downcast<ASTRelationalExprNode>(this);
3458 49 const CompileTimeValue op0Value = getChildCompileTimeValue(this, 0l, manIdx);
3459 49 const CompileTimeValue op1Value = getChildCompileTimeValue(this, 1l, manIdx);
3460 49 const RelationalOp op = relationalExprNode.op;
3461
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 46 times.
49 if op == RelationalOp::OP_LESS {
3462 3 compileTimeValue.setBoolValue(op0Value.getLongValue() < op1Value.getLongValue());
3463
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 4 times.
49 } else if op == RelationalOp::OP_GREATER {
3464 42 compileTimeValue.setBoolValue(op0Value.getLongValue() > op1Value.getLongValue());
3465
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
46 } else if op == RelationalOp::OP_LESS_EQUAL {
3466 2 compileTimeValue.setBoolValue(op0Value.getLongValue() <= op1Value.getLongValue());
3467 2 } else {
3468 2 assert op == RelationalOp::OP_GREATER_EQUAL;
3469 2 compileTimeValue.setBoolValue(op0Value.getLongValue() >= op1Value.getLongValue());
3470 46 }
3471 49 return compileTimeValue;
3472 }
3473 case ASTNodeKind::SHIFT_EXPR: {
3474
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ if this.children.getSize() == 1l {
3475 ✗ return getChildCompileTimeValue(this, 0l, manIdx);
3476 }
3477 ✗ const ASTShiftExprNode* shiftExprNode = downcast<ASTShiftExprNode>(this);
3478 ✗ compileTimeValue = getChildCompileTimeValue(this, 0l, manIdx);
3479 ✗ ShiftOpQueue opQueueCopy = shiftExprNode.opQueue;
3480
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ for unsigned long i = 1l; i < this.children.getSize(); i++ {
3481 ✗ ASTNode* operand = this.children.get(i);
3482 ✗ assert operand.hasCompileTimeValue(manIdx);
3483 ✗ const CompileTimeValue operandValue = operand.getCompileTimeValue(manIdx);
3484 ✗ const Pair<ShiftOp, QualType> opEntry = opQueueCopy.pop();
3485
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ if opEntry.getFirst() == ShiftOp::OP_SHIFT_LEFT {
3486 ✗ compileTimeValue.setLongValue(compileTimeValue.getLongValue() << operandValue.getLongValue());
3487 ✗ } else {
3488 ✗ assert opEntry.getFirst() == ShiftOp::OP_SHIFT_RIGHT;
3489 ✗ compileTimeValue.setLongValue(compileTimeValue.getLongValue() >> operandValue.getLongValue());
3490 ✗ }
3491 ✗ }
3492 ✗ return compileTimeValue;
3493 ✗ }
3494 case ASTNodeKind::ADDITIVE_EXPR: {
3495
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ if this.children.getSize() == 1l {
3496 ✗ return getChildCompileTimeValue(this, 0l, manIdx);
3497 }
3498 ✗ const ASTAdditiveExprNode* additiveExprNode = downcast<ASTAdditiveExprNode>(this);
3499 ✗ compileTimeValue = getChildCompileTimeValue(this, 0l, manIdx);
3500 ✗ AdditiveOpQueue opQueueCopy = additiveExprNode.opQueue;
3501
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ for unsigned long i = 1l; i < this.children.getSize(); i++ {
3502 ✗ ASTNode* operand = this.children.get(i);
3503 ✗ assert operand.hasCompileTimeValue(manIdx);
3504 ✗ const CompileTimeValue operandValue = operand.getCompileTimeValue(manIdx);
3505 ✗ const Pair<AdditiveOp, QualType> opEntry = opQueueCopy.pop();
3506
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ if opEntry.getFirst() == AdditiveOp::OP_PLUS {
3507 ✗ compileTimeValue.setLongValue(compileTimeValue.getLongValue() + operandValue.getLongValue());
3508 ✗ } else {
3509 ✗ assert opEntry.getFirst() == AdditiveOp::OP_MINUS;
3510 ✗ compileTimeValue.setLongValue(compileTimeValue.getLongValue() - operandValue.getLongValue());
3511 ✗ }
3512 ✗ }
3513 ✗ return compileTimeValue;
3514 ✗ }
3515 case ASTNodeKind::MULTIPLICATIVE_EXPR: {
3516
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if this.children.getSize() == 1l {
3517 ✗ return getChildCompileTimeValue(this, 0l, manIdx);
3518 }
3519 2 const ASTMultiplicativeExprNode* multiplicativeExprNode = downcast<ASTMultiplicativeExprNode>(this);
3520 2 compileTimeValue = getChildCompileTimeValue(this, 0l, manIdx);
3521 2 MultiplicativeOpQueue opQueueCopy = multiplicativeExprNode.opQueue;
3522
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 for unsigned long i = 1l; i < this.children.getSize(); i++ {
3523 3 ASTNode* operand = this.children.get(i);
3524 3 assert operand.hasCompileTimeValue(manIdx);
3525 3 const CompileTimeValue operandValue = operand.getCompileTimeValue(manIdx);
3526 3 const Pair<MultiplicativeOp, QualType> opEntry = opQueueCopy.pop();
3527 3 const MultiplicativeOp op = opEntry.getFirst();
3528
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if op == MultiplicativeOp::OP_MUL {
3529 ✗ compileTimeValue.setLongValue(compileTimeValue.getLongValue() * operandValue.getLongValue());
3530
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 time.
3 } else if op == MultiplicativeOp::OP_DIV {
3531
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
2 if operandValue.getLongValue() == 0l {
3532 1 abortWithSemanticError(operand, SemanticErrorType::DIVISION_BY_ZERO, "Dividing by zero is not allowed.");
3533 1 }
3534 2 compileTimeValue.setLongValue(compileTimeValue.getLongValue() / operandValue.getLongValue());
3535 2 } else {
3536 1 assert op == MultiplicativeOp::OP_REM;
3537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 if operandValue.getLongValue() == 0l {
3538 1 abortWithSemanticError(operand, SemanticErrorType::DIVISION_BY_ZERO, "Dividing by zero is not allowed.");
3539 1 }
3540 1 compileTimeValue.setLongValue(compileTimeValue.getLongValue() % operandValue.getLongValue());
3541 1 }
3542 1 }
3543 ✗ return compileTimeValue;
3544 ✗ }
3545 case ASTNodeKind::CAST_EXPR: {
3546 ✗ const ASTCastExprNode* castExprNode = downcast<ASTCastExprNode>(this);
3547
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ return castExprNode.isCast ? getCompileTimeValue(castExprNode.assignExpr, manIdx) : getCompileTimeValue(castExprNode.prefixUnaryExpr, manIdx);
3548 }
3549 case ASTNodeKind::PREFIX_UNARY_EXPR: {
3550 336 const ASTPrefixUnaryExprNode* prefixUnaryExprNode = downcast<ASTPrefixUnaryExprNode>(this);
3551
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 336 times.
336 if prefixUnaryExprNode.postfixUnaryExpr != nil<IVisitable*> {
3552 ✗ return getCompileTimeValue(prefixUnaryExprNode.postfixUnaryExpr, manIdx);
3553 }
3554 336 const CompileTimeValue opValue = getCompileTimeValue(prefixUnaryExprNode.prefixUnaryExpr, manIdx);
3555 336 const PrefixUnaryOp op = prefixUnaryExprNode.op;
3556
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 336 times.
336 if op == PrefixUnaryOp::OP_MINUS {
3557 ✗ compileTimeValue.setLongValue(-opValue.getLongValue());
3558
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 336 times.
336 } else if op == PrefixUnaryOp::OP_PLUS_PLUS {
3559 ✗ compileTimeValue.setLongValue(opValue.getLongValue() + 1l);
3560
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 336 times.
336 } else if op == PrefixUnaryOp::OP_MINUS_MINUS {
3561 ✗ compileTimeValue.setLongValue(opValue.getLongValue() - 1l);
3562
1/2
✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
336 } else if op == PrefixUnaryOp::OP_NOT {
3563 336 compileTimeValue.setBoolValue(!opValue.getBoolValue());
3564 336 } else {
3565 ✗ assert op == PrefixUnaryOp::OP_BITWISE_NOT;
3566 ✗ compileTimeValue.setLongValue(~opValue.getLongValue());
3567 336 }
3568 336 return compileTimeValue;
3569 }
3570 case ASTNodeKind::POSTFIX_UNARY_EXPR: {
3571 ✗ const ASTPostfixUnaryExprNode* postfixUnaryExprNode = downcast<ASTPostfixUnaryExprNode>(this);
3572
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ if postfixUnaryExprNode.atomicExpr != nil<IVisitable*> {
3573 ✗ return getCompileTimeValue(postfixUnaryExprNode.atomicExpr, manIdx);
3574 }
3575 // The postfix operators return the value before the modification
3576 ✗ const PostfixUnaryOp op = postfixUnaryExprNode.op;
3577 ✗ assert op == PostfixUnaryOp::OP_PLUS_PLUS || op == PostfixUnaryOp::OP_MINUS_MINUS;
3578 ✗ return getCompileTimeValue(postfixUnaryExprNode.postfixUnaryExpr, manIdx);
3579 }
3580 case ASTNodeKind::VALUE: {
3581 879 const ASTValueNode* valueNode = downcast<ASTValueNode>(this);
3582
2/2
✓ Branch 0 taken 487 times.
✓ Branch 1 taken 392 times.
879 if valueNode.isNil {
3583 487 compileTimeValue.setLongValue(0l);
3584 487 return compileTimeValue;
3585 }
3586 392 }
3587 case ASTNodeKind::FCT_CALL: {
3588 1504 const ASTFctCallNode* fctCallNode = downcast<ASTFctCallNode>(this);
3589 1504 const FctCallData& fctCallData = fctCallNode.data.get(manIdx);
3590 1504 return fctCallData.compileTimeValue;
3591 }
3592 }
3593 // Default behavior: Take the compile time value of the only child
3594
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7840 times.
7840 if this.children.getSize() != 1l {
3595 ✗ return compileTimeValue;
3596 }
3597 7840 return getChildCompileTimeValue(this, 0l, manIdx);
3598 }
3599
3600 // Shorthand for getting the compile time value of the child with the given index
3601 7974 f<CompileTimeValue> getChildCompileTimeValue(ASTNode* node, unsigned long childIdx, unsigned long manIdx) {
3602 7974 ASTNode* child = node.children.get(childIdx);
3603 7974 return child.getCompileTimeValue(manIdx);
3604 }
3605
3606 // Shorthand for calling getCompileTimeValue on a node, that is stored as IVisitable*
3607 336 f<CompileTimeValue> getCompileTimeValue(IVisitable* node, unsigned long manIdx) {
3608 336 ASTNode* astNode = getASTNode(node);
3609 336 return astNode.getCompileTimeValue(manIdx);
3610 }
3611
3612 /**
3613 * Get the atomic expression on the left hand side of an assignment, if there is one
3614 *
3615 * @return Atomic expression node or nil
3616 */
3617 25359 public f<ASTAtomicExprNode*> ASTAssignExprNode.getLhsAtomicNode() {
3618 25359 ASTNode* lhsNode = getASTNode(this.lhs);
3619
2/2
✓ Branch 0 taken 5201 times.
✓ Branch 1 taken 20158 times.
25359 if lhsNode.kind == ASTNodeKind::ATOMIC_EXPR {
3620 5201 return downcastMut<ASTAtomicExprNode>(lhsNode);
3621 }
3622 20158 ASTNode* lastChild = lhsNode.children.back();
3623
2/2
✓ Branch 0 taken 18644 times.
✓ Branch 1 taken 1514 times.
20158 if lastChild.kind == ASTNodeKind::ATOMIC_EXPR {
3624 18644 return downcastMut<ASTAtomicExprNode>(lastChild);
3625 }
3626 1514 ASTNode* firstGrandChild = lastChild.children.front();
3627
2/2
✓ Branch 0 taken 1219 times.
✓ Branch 1 taken 295 times.
1514 if firstGrandChild.kind == ASTNodeKind::ATOMIC_EXPR {
3628 1219 return downcastMut<ASTAtomicExprNode>(firstGrandChild);
3629 }
3630 295 return nil<ASTAtomicExprNode*>;
3631 }
3632
3633 // ====================================================== IVisitable.getCodeLoc ==================================================
3634
3635 // Every IVisitable node exposes its own code location. Passes use it to name the scope of an expression ('expr:' + code
3636 // location of the expression), so that later passes find the scope again from the node alone.
3637
3638 ✗ public f<const CodeLoc&> ASTEntryNode.getCodeLoc() { return this.codeLoc; }
3639 ✗ public f<const CodeLoc&> ASTConstantNode.getCodeLoc() { return this.codeLoc; }
3640 ✗ public f<const CodeLoc&> ASTAttrNode.getCodeLoc() { return this.codeLoc; }
3641 ✗ public f<const CodeLoc&> ASTAttrLstNode.getCodeLoc() { return this.codeLoc; }
3642 ✗ public f<const CodeLoc&> ASTQualifierNode.getCodeLoc() { return this.codeLoc; }
3643 ✗ public f<const CodeLoc&> ASTQualifierLstNode.getCodeLoc() { return this.codeLoc; }
3644 ✗ public f<const CodeLoc&> ASTCustomDataTypeNode.getCodeLoc() { return this.codeLoc; }
3645 ✗ public f<const CodeLoc&> ASTBaseDataTypeNode.getCodeLoc() { return this.codeLoc; }
3646 ✗ public f<const CodeLoc&> ASTDataTypeNode.getCodeLoc() { return this.codeLoc; }
3647 ✗ public f<const CodeLoc&> ASTTypeLstNode.getCodeLoc() { return this.codeLoc; }
3648 ✗ public f<const CodeLoc&> ASTMainFctDefNode.getCodeLoc() { return this.codeLoc; }
3649 ✗ public f<const CodeLoc&> ASTFctNameNode.getCodeLoc() { return this.codeLoc; }
3650 ✗ public f<const CodeLoc&> ASTFctDefNode.getCodeLoc() { return this.codeLoc; }
3651 ✗ public f<const CodeLoc&> ASTProcDefNode.getCodeLoc() { return this.codeLoc; }
3652 ✗ public f<const CodeLoc&> ASTStructDefNode.getCodeLoc() { return this.codeLoc; }
3653 ✗ public f<const CodeLoc&> ASTInterfaceDefNode.getCodeLoc() { return this.codeLoc; }
3654 ✗ public f<const CodeLoc&> ASTUnionDefNode.getCodeLoc() { return this.codeLoc; }
3655 ✗ public f<const CodeLoc&> ASTEnumDefNode.getCodeLoc() { return this.codeLoc; }
3656 ✗ public f<const CodeLoc&> ASTGenericTypeDefNode.getCodeLoc() { return this.codeLoc; }
3657 ✗ public f<const CodeLoc&> ASTAliasDefNode.getCodeLoc() { return this.codeLoc; }
3658 ✗ public f<const CodeLoc&> ASTGlobalVarDefNode.getCodeLoc() { return this.codeLoc; }
3659 ✗ public f<const CodeLoc&> ASTExtDeclNode.getCodeLoc() { return this.codeLoc; }
3660 ✗ public f<const CodeLoc&> ASTImportDefNode.getCodeLoc() { return this.codeLoc; }
3661 ✗ public f<const CodeLoc&> ASTUnsafeBlockNode.getCodeLoc() { return this.codeLoc; }
3662 ✗ public f<const CodeLoc&> ASTForLoopNode.getCodeLoc() { return this.codeLoc; }
3663 ✗ public f<const CodeLoc&> ASTForeachLoopNode.getCodeLoc() { return this.codeLoc; }
3664 ✗ public f<const CodeLoc&> ASTWhileLoopNode.getCodeLoc() { return this.codeLoc; }
3665 ✗ public f<const CodeLoc&> ASTDoWhileLoopNode.getCodeLoc() { return this.codeLoc; }
3666 ✗ public f<const CodeLoc&> ASTIfStmtNode.getCodeLoc() { return this.codeLoc; }
3667 ✗ public f<const CodeLoc&> ASTElseStmtNode.getCodeLoc() { return this.codeLoc; }
3668 ✗ public f<const CodeLoc&> ASTSwitchStmtNode.getCodeLoc() { return this.codeLoc; }
3669 183 public f<const CodeLoc&> ASTCaseBranchNode.getCodeLoc() { return this.codeLoc; }
3670 18 public f<const CodeLoc&> ASTDefaultBranchNode.getCodeLoc() { return this.codeLoc; }
3671 ✗ public f<const CodeLoc&> ASTAnonymousBlockStmtNode.getCodeLoc() { return this.codeLoc; }
3672 4840 public f<const CodeLoc&> ASTStmtLstNode.getCodeLoc() { return this.codeLoc; }
3673 ✗ public f<const CodeLoc&> ASTTypeLstWithEllipsisNode.getCodeLoc() { return this.codeLoc; }
3674 ✗ public f<const CodeLoc&> ASTTypeAltsLstNode.getCodeLoc() { return this.codeLoc; }
3675 ✗ public f<const CodeLoc&> ASTDeclStmtNode.getCodeLoc() { return this.codeLoc; }
3676 ✗ public f<const CodeLoc&> ASTParamLstNode.getCodeLoc() { return this.codeLoc; }
3677 ✗ public f<const CodeLoc&> ASTArgLstNode.getCodeLoc() { return this.codeLoc; }
3678 ✗ public f<const CodeLoc&> ASTEnumItemNode.getCodeLoc() { return this.codeLoc; }
3679 ✗ public f<const CodeLoc&> ASTEnumItemLstNode.getCodeLoc() { return this.codeLoc; }
3680 ✗ public f<const CodeLoc&> ASTFieldNode.getCodeLoc() { return this.codeLoc; }
3681 ✗ public f<const CodeLoc&> ASTSignatureNode.getCodeLoc() { return this.codeLoc; }
3682 ✗ public f<const CodeLoc&> ASTExprStmtNode.getCodeLoc() { return this.codeLoc; }
3683 ✗ public f<const CodeLoc&> ASTModAttrNode.getCodeLoc() { return this.codeLoc; }
3684 ✗ public f<const CodeLoc&> ASTTopLevelDefAttrNode.getCodeLoc() { return this.codeLoc; }
3685 ✗ public f<const CodeLoc&> ASTLambdaAttrNode.getCodeLoc() { return this.codeLoc; }
3686 ✗ public f<const CodeLoc&> ASTCaseConstantNode.getCodeLoc() { return this.codeLoc; }
3687 ✗ public f<const CodeLoc&> ASTReturnStmtNode.getCodeLoc() { return this.codeLoc; }
3688 ✗ public f<const CodeLoc&> ASTBreakStmtNode.getCodeLoc() { return this.codeLoc; }
3689 ✗ public f<const CodeLoc&> ASTContinueStmtNode.getCodeLoc() { return this.codeLoc; }
3690 ✗ public f<const CodeLoc&> ASTFallthroughStmtNode.getCodeLoc() { return this.codeLoc; }
3691 ✗ public f<const CodeLoc&> ASTAssertStmtNode.getCodeLoc() { return this.codeLoc; }
3692 1160 public f<const CodeLoc&> ASTAssignExprNode.getCodeLoc() { return this.codeLoc; }
3693 8 public f<const CodeLoc&> ASTTernaryExprNode.getCodeLoc() { return this.codeLoc; }
3694 6889 public f<const CodeLoc&> ASTLogicalOrExprNode.getCodeLoc() { return this.codeLoc; }
3695 4729 public f<const CodeLoc&> ASTLogicalAndExprNode.getCodeLoc() { return this.codeLoc; }
3696 1368 public f<const CodeLoc&> ASTBitwiseOrExprNode.getCodeLoc() { return this.codeLoc; }
3697 ✗ public f<const CodeLoc&> ASTBitwiseXorExprNode.getCodeLoc() { return this.codeLoc; }
3698 72 public f<const CodeLoc&> ASTBitwiseAndExprNode.getCodeLoc() { return this.codeLoc; }
3699 64265 public f<const CodeLoc&> ASTEqualityExprNode.getCodeLoc() { return this.codeLoc; }
3700 53601 public f<const CodeLoc&> ASTRelationalExprNode.getCodeLoc() { return this.codeLoc; }
3701 ✗ public f<const CodeLoc&> ASTShiftExprNode.getCodeLoc() { return this.codeLoc; }
3702 387 public f<const CodeLoc&> ASTAdditiveExprNode.getCodeLoc() { return this.codeLoc; }
3703 4858 public f<const CodeLoc&> ASTMultiplicativeExprNode.getCodeLoc() { return this.codeLoc; }
3704 896 public f<const CodeLoc&> ASTCastExprNode.getCodeLoc() { return this.codeLoc; }
3705 7765 public f<const CodeLoc&> ASTPrefixUnaryExprNode.getCodeLoc() { return this.codeLoc; }
3706 19734 public f<const CodeLoc&> ASTPostfixUnaryExprNode.getCodeLoc() { return this.codeLoc; }
3707 35600 public f<const CodeLoc&> ASTAtomicExprNode.getCodeLoc() { return this.codeLoc; }
3708 ✗ public f<const CodeLoc&> ASTValueNode.getCodeLoc() { return this.codeLoc; }
3709 ✗ public f<const CodeLoc&> ASTFctCallNode.getCodeLoc() { return this.codeLoc; }
3710 ✗ public f<const CodeLoc&> ASTArrayInitializationNode.getCodeLoc() { return this.codeLoc; }
3711 ✗ public f<const CodeLoc&> ASTStructInstantiationNode.getCodeLoc() { return this.codeLoc; }
3712 ✗ public f<const CodeLoc&> ASTLambdaFuncNode.getCodeLoc() { return this.codeLoc; }
3713 ✗ public f<const CodeLoc&> ASTLambdaProcNode.getCodeLoc() { return this.codeLoc; }
3714 ✗ public f<const CodeLoc&> ASTLambdaExprNode.getCodeLoc() { return this.codeLoc; }
3715 ✗ public f<const CodeLoc&> ASTFunctionDataTypeNode.getCodeLoc() { return this.codeLoc; }
3716
3717 // ====================================================== IVisitable.getASTNode ==================================================
3718
3719 // Every IVisitable node exposes its composed ASTNode. This is required to reach the node base of a child, that is stored as
3720 // IVisitable* because its type is declared later in this file.
3721
3722 /**
3723 * Get the composed ASTNode of a visitable node
3724 *
3725 * @param node Visitable node
3726 * @return Composed ASTNode
3727 */
3728 1890825 public f<ASTNode*> getASTNode(IVisitable* node) {
3729 unsafe {
3730 1890825 return cast<ASTNode*>(node.getASTNodeAddress());
3731 }
3732 }
3733
3734 ✗ public f<byte*> ASTEntryNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3735 77979 public f<byte*> ASTConstantNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3736 ✗ public f<byte*> ASTAttrNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3737 1 public f<byte*> ASTAttrLstNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3738 ✗ public f<byte*> ASTQualifierNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3739 ✗ public f<byte*> ASTQualifierLstNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3740 ✗ public f<byte*> ASTCustomDataTypeNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3741 ✗ public f<byte*> ASTBaseDataTypeNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3742 10048 public f<byte*> ASTDataTypeNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3743 ✗ public f<byte*> ASTTypeLstNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3744 757 public f<byte*> ASTMainFctDefNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3745 ✗ public f<byte*> ASTFctNameNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3746 26991 public f<byte*> ASTFctDefNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3747 16821 public f<byte*> ASTProcDefNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3748 3001 public f<byte*> ASTStructDefNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3749 295 public f<byte*> ASTInterfaceDefNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3750 17 public f<byte*> ASTUnionDefNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3751 437 public f<byte*> ASTEnumDefNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3752 2911 public f<byte*> ASTGenericTypeDefNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3753 153 public f<byte*> ASTAliasDefNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3754 4208 public f<byte*> ASTGlobalVarDefNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3755 5041 public f<byte*> ASTExtDeclNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3756 ✗ public f<byte*> ASTImportDefNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3757 47846 public f<byte*> ASTUnsafeBlockNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3758 19103 public f<byte*> ASTForLoopNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3759 1684 public f<byte*> ASTForeachLoopNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3760 7215 public f<byte*> ASTWhileLoopNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3761 262 public f<byte*> ASTDoWhileLoopNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3762 100134 public f<byte*> ASTIfStmtNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3763 45 public f<byte*> ASTElseStmtNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3764 171 public f<byte*> ASTSwitchStmtNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3765 148 public f<byte*> ASTCaseBranchNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3766 9 public f<byte*> ASTDefaultBranchNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3767 504 public f<byte*> ASTAnonymousBlockStmtNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3768 77241 public f<byte*> ASTStmtLstNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3769 ✗ public f<byte*> ASTTypeLstWithEllipsisNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3770 ✗ public f<byte*> ASTTypeAltsLstNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3771 104730 public f<byte*> ASTDeclStmtNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3772 32091 public f<byte*> ASTParamLstNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3773 ✗ public f<byte*> ASTArgLstNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3774 ✗ public f<byte*> ASTEnumItemNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3775 ✗ public f<byte*> ASTEnumItemLstNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3776 20705 public f<byte*> ASTFieldNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3777 ✗ public f<byte*> ASTSignatureNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3778 237357 public f<byte*> ASTExprStmtNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3779 ✗ public f<byte*> ASTModAttrNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3780 ✗ public f<byte*> ASTTopLevelDefAttrNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3781 ✗ public f<byte*> ASTLambdaAttrNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3782 97 public f<byte*> ASTCaseConstantNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3783 162887 public f<byte*> ASTReturnStmtNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3784 2296 public f<byte*> ASTBreakStmtNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3785 4185 public f<byte*> ASTContinueStmtNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3786 43 public f<byte*> ASTFallthroughStmtNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3787 18357 public f<byte*> ASTAssertStmtNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3788 61 public f<byte*> ASTAssignExprNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3789 4847 public f<byte*> ASTTernaryExprNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3790 9527 public f<byte*> ASTLogicalOrExprNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3791 6142 public f<byte*> ASTLogicalAndExprNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3792 1503 public f<byte*> ASTBitwiseOrExprNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3793 72 public f<byte*> ASTBitwiseXorExprNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3794 289 public f<byte*> ASTBitwiseAndExprNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3795 80711 public f<byte*> ASTEqualityExprNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3796 58236 public f<byte*> ASTRelationalExprNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3797 209 public f<byte*> ASTShiftExprNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3798 21004 public f<byte*> ASTAdditiveExprNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3799 5257 public f<byte*> ASTMultiplicativeExprNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3800 29624 public f<byte*> ASTCastExprNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3801 16709 public f<byte*> ASTPrefixUnaryExprNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3802 145416 public f<byte*> ASTPostfixUnaryExprNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3803 524028 public f<byte*> ASTAtomicExprNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3804 ✗ public f<byte*> ASTValueNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3805 1420 public f<byte*> ASTFctCallNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3806 ✗ public f<byte*> ASTArrayInitializationNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3807 ✗ public f<byte*> ASTStructInstantiationNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3808 ✗ public f<byte*> ASTLambdaFuncNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3809 ✗ public f<byte*> ASTLambdaProcNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3810 ✗ public f<byte*> ASTLambdaExprNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3811 ✗ public f<byte*> ASTFunctionDataTypeNode.getASTNodeAddress() { unsafe { return cast<byte*>(cast<ASTNode*>(this)); } }
3812
3813 /**
3814 * Address of an AST node, which is used as key for maps that are keyed by AST node (e.g. nodeToNodeId)
3815 *
3816 * @param node AST node
3817 * @return Address of the node
3818 */
3819 2266308 public f<long> getNodeAddress(const ASTNode* node) {
3820 unsafe {
3821 2266308 return cast<long>(node);
3822 }
3823 }
3824
3825 /**
3826 * Name of the scope that holds the temporaries of an expression.
3827 *
3828 * @param expr Expression
3829 * @return Scope id
3830 */
3831 152820 public f<String> getExprScopeId(IVisitable* expr) {
3832 152820 const CodeLoc& codeLoc = expr.getCodeLoc();
3833 305640 return String("expr:") + codeLoc.toString();
3834 152820 }
3835