Phasor 2.2.0
Stack VM based Programming Language
Loading...
Searching...
No Matches
AST.hpp
Go to the documentation of this file.
1#pragma once
2#include <iostream>
3#include <memory>
4#include <string>
5#include <vector>
6
7namespace Phasor
8{
10namespace AST
11{
12
13// Forward declarations
14struct Node;
15struct Expression;
16struct Statement;
17struct Program;
18
20struct Node
21{
22 virtual ~Node() = default;
23 virtual void print(int indent = 0) const = 0;
24};
25
27struct Expression : public Node
28{
29};
30
32struct Statement : public Node
33{
34};
35
37struct Program : public Node
38{
39 std::vector<std::unique_ptr<Statement>> statements;
40 void print(int indent = 0) const override
41 {
42 for (const auto &stmt : statements)
43 {
44 stmt->print(indent);
45 }
46 }
47};
48
50struct TypeNode : public Node
51{
52 std::string name;
53 bool isPointer = false;
54 std::vector<int> arrayDimensions;
55
56 TypeNode(std::string n, bool ptr = false, std::vector<int> dims = {}) : name(n), isPointer(ptr), arrayDimensions(std::move(dims))
57 {
58 }
59 void print(int indent = 0) const override
60 {
61 std::cout << std::string(indent, ' ') << "Type: " << name << (isPointer ? "*" : "") << "\n";
62 for (int dim : arrayDimensions) {
63 std::cout << std::string(indent + 2, ' ') << "ArrayDim: " << dim << "\n";
64 }
65 }
66};
67
69struct NumberExpr : public Expression
70{
71 std::string value;
72 NumberExpr(std::string v) : value(v)
73 {
74 }
75 void print(int indent = 0) const override
76 {
77 std::cout << std::string(indent, ' ') << "Number: " << value << "\n";
78 }
79};
80
82struct StringExpr : public Expression
83{
84 std::string value;
85 StringExpr(std::string v) : value(v)
86 {
87 }
88 void print(int indent = 0) const override
89 {
90 std::cout << std::string(indent, ' ') << "String: " << value << "\n";
91 }
92};
93
96{
97 std::string name;
98 IdentifierExpr(std::string n) : name(n)
99 {
100 }
101 void print(int indent = 0) const override
102 {
103 std::cout << std::string(indent, ' ') << "Identifier: " << name << "\n";
104 }
105};
106
108struct BooleanExpr : public Expression
109{
110 bool value;
111 BooleanExpr(bool v) : value(v)
112 {
113 }
114 void print(int indent = 0) const override
115 {
116 std::cout << std::string(indent, ' ') << "Boolean: " << (value ? "true" : "false") << "\n";
117 }
118};
119
121struct NullExpr : public Expression
122{
123 void print(int indent = 0) const override
124 {
125 std::cout << std::string(indent, ' ') << "Null\n";
126 }
127};
128
130enum class UnaryOp
131{
132 Negate, // -x
133 Not, // !x
136};
137
155
157enum class PostfixOp
158{
159 Increment, // x++
161};
162
164struct PostfixExpr : public Expression
165{
167 std::unique_ptr<Expression> operand;
168
169 PostfixExpr(PostfixOp o, std::unique_ptr<Expression> expr) : op(o), operand(std::move(expr))
170 {
171 }
172
173 void print(int indent = 0) const override
174 {
175 std::cout << std::string(indent, ' ') << "PostfixExpr: ";
176 switch (op)
177 {
179 std::cout << "++\n";
180 break;
182 std::cout << "--\n";
183 break;
184 }
185 operand->print(indent + 2);
186 }
187};
188
190struct UnaryExpr : public Expression
191{
193 std::unique_ptr<Expression> operand;
194
195 UnaryExpr(UnaryOp o, std::unique_ptr<Expression> expr) : op(o), operand(std::move(expr))
196 {
197 }
198
199 void print(int indent = 0) const override
200 {
201 std::cout << std::string(indent, ' ') << "UnaryExpr: ";
202 switch (op)
203 {
204 case UnaryOp::Negate:
205 std::cout << "-\n";
206 break;
207 case UnaryOp::Not:
208 std::cout << "!\n";
209 break;
211 std::cout << "&\n";
212 break;
214 std::cout << "*\n";
215 break;
216 }
217 operand->print(indent + 2);
218 }
219};
220
222struct BinaryExpr : public Expression
223{
224 std::unique_ptr<Expression> left;
226 std::unique_ptr<Expression> right;
227
228 BinaryExpr(std::unique_ptr<Expression> l, BinaryOp o, std::unique_ptr<Expression> r)
229 : left(std::move(l)), op(o), right(std::move(r))
230 {
231 }
232
233 void print(int indent = 0) const override
234 {
235 std::cout << std::string(indent, ' ') << "BinaryExpr: ";
236 switch (op)
237 {
238 case BinaryOp::Add:
239 std::cout << "+\n";
240 break;
242 std::cout << "-\n";
243 break;
245 std::cout << "*\n";
246 break;
247 case BinaryOp::Divide:
248 std::cout << "/\n";
249 break;
250 case BinaryOp::Modulo:
251 std::cout << "%\n";
252 break;
253 case BinaryOp::And:
254 std::cout << "&&\n";
255 break;
256 case BinaryOp::Or:
257 std::cout << "||\n";
258 break;
259 case BinaryOp::Equal:
260 std::cout << "==\n";
261 break;
263 std::cout << "!=\n";
264 break;
266 std::cout << "<\n";
267 break;
269 std::cout << ">\n";
270 break;
272 std::cout << "<=\n";
273 break;
275 std::cout << ">=\n";
276 break;
277 }
278 left->print(indent + 2);
279 right->print(indent + 2);
280 }
281};
282
285{
286 std::unique_ptr<Expression> array;
287 std::unique_ptr<Expression> index;
288
289 ArrayAccessExpr(std::unique_ptr<Expression> arr, std::unique_ptr<Expression> idx)
290 : array(std::move(arr)), index(std::move(idx))
291 {
292 }
293
294 void print(int indent = 0) const override
295 {
296 std::cout << std::string(indent, ' ') << "ArrayAccess:\n";
297 array->print(indent + 2);
298 std::cout << std::string(indent + 2, ' ') << "Index:\n";
299 index->print(indent + 4);
300 }
301};
302
305{
306 std::vector<std::unique_ptr<Expression>> elements;
307 ArrayLiteralExpr(std::vector<std::unique_ptr<Expression>> elems) : elements(std::move(elems)) {}
308 void print(int indent = 0) const override
309 {
310 std::cout << std::string(indent, ' ') << "ArrayLiteral:\n";
311 for (const auto &elem : elements) elem->print(indent + 2);
312 }
313};
314
317{
318 std::unique_ptr<Expression> object;
319 std::string member;
320
321 MemberAccessExpr(std::unique_ptr<Expression> obj, std::string mem) : object(std::move(obj)), member(mem)
322 {
323 }
324
325 void print(int indent = 0) const override
326 {
327 std::cout << std::string(indent, ' ') << "MemberAccess: ." << member << "\n";
328 object->print(indent + 2);
329 }
330};
331
333struct CallExpr : public Expression
334{
335 std::string callee;
336 std::vector<std::unique_ptr<Expression>> arguments;
337
338 CallExpr(std::string name, std::vector<std::unique_ptr<Expression>> args) : callee(name), arguments(std::move(args))
339 {
340 }
341
342 void print(int indent = 0) const override
343 {
344 std::cout << std::string(indent, ' ') << "CallExpr: " << callee << "\n";
345 for (const auto &arg : arguments)
346 {
347 arg->print(indent + 2);
348 }
349 }
350};
351
354{
355 std::unique_ptr<Expression> target;
356 std::unique_ptr<Expression> value;
357
358 AssignmentExpr(std::unique_ptr<Expression> t, std::unique_ptr<Expression> v)
359 : target(std::move(t)), value(std::move(v))
360 {
361 }
362
363 void print(int indent = 0) const override
364 {
365 std::cout << std::string(indent, ' ') << "AssignmentExpr:\n";
366 std::cout << std::string(indent + 2, ' ') << "Target:\n";
367 target->print(indent + 4);
368 std::cout << std::string(indent + 2, ' ') << "Value:\n";
369 value->print(indent + 4);
370 }
371};
372
374struct VarDecl : public Statement
375{
376 std::string name;
377 std::unique_ptr<Expression> initializer;
378 VarDecl(std::string n, std::unique_ptr<Expression> init) : name(n), initializer(std::move(init))
379 {
380 }
381 void print(int indent = 0) const override
382 {
383 std::cout << std::string(indent, ' ') << "VarDecl: " << name << "\n";
384 if (initializer)
385 initializer->print(indent + 2);
386 }
387};
388
391{
392 std::unique_ptr<Expression> expression;
393 ExpressionStmt(std::unique_ptr<Expression> expr) : expression(std::move(expr))
394 {
395 }
396 void print(int indent = 0) const override
397 {
398 expression->print(indent);
399 }
400};
401
403struct PrintStmt : public Statement
404{
405 std::unique_ptr<Expression> expression;
406 PrintStmt(std::unique_ptr<Expression> expr) : expression(std::move(expr))
407 {
408 }
409 void print(int indent = 0) const override
410 {
411 std::cout << std::string(indent, ' ') << "PrintStmt:\n";
412 expression->print(indent + 2);
413 }
414};
415
417struct ImportStmt : public Statement
418{
419 std::string modulePath;
420 ImportStmt(std::string path) : modulePath(path)
421 {
422 }
423 void print(int indent = 0) const override
424 {
425 std::cout << std::string(indent, ' ') << "ImportStmt: " << modulePath << "\n";
426 }
427};
428
430struct ExportStmt : public Statement
431{
432 std::unique_ptr<Statement> declaration;
433 ExportStmt(std::unique_ptr<Statement> decl) : declaration(std::move(decl))
434 {
435 }
436 void print(int indent = 0) const override
437 {
438 std::cout << std::string(indent, ' ') << "ExportStmt:\n";
439 declaration->print(indent + 2);
440 }
441};
442
444struct BlockStmt : public Statement
445{
446 std::vector<std::unique_ptr<Statement>> statements;
447 BlockStmt(std::vector<std::unique_ptr<Statement>> stmts) : statements(std::move(stmts))
448 {
449 }
450 void print(int indent = 0) const override
451 {
452 std::cout << std::string(indent, ' ') << "BlockStmt:\n";
453 for (const auto &stmt : statements)
454 {
455 stmt->print(indent + 2);
456 }
457 }
458};
459
461struct ReturnStmt : public Statement
462{
463 std::unique_ptr<Expression> value;
464 ReturnStmt(std::unique_ptr<Expression> val) : value(std::move(val))
465 {
466 }
467 void print(int indent = 0) const override
468 {
469 std::cout << std::string(indent, ' ') << "ReturnStmt:\n";
470 if (value)
471 value->print(indent + 2);
472 }
473};
474
476struct BreakStmt : public Statement
477{
478 void print(int indent = 0) const override
479 {
480 std::cout << std::string(indent, ' ') << "BreakStmt\n";
481 }
482};
483
485struct ContinueStmt : public Statement
486{
487 void print(int indent = 0) const override
488 {
489 std::cout << std::string(indent, ' ') << "ContinueStmt\n";
490 }
491};
492
494struct IfStmt : public Statement
495{
496 std::unique_ptr<Expression> condition;
497 std::unique_ptr<Statement> thenBranch;
498 std::unique_ptr<Statement> elseBranch;
499
500 IfStmt(std::unique_ptr<Expression> cond, std::unique_ptr<Statement> thenB, std::unique_ptr<Statement> elseB)
501 : condition(std::move(cond)), thenBranch(std::move(thenB)), elseBranch(std::move(elseB))
502 {
503 }
504
505 void print(int indent = 0) const override
506 {
507 std::cout << std::string(indent, ' ') << "IfStmt:\n";
508 condition->print(indent + 2);
509 thenBranch->print(indent + 2);
510 if (elseBranch)
511 {
512 std::cout << std::string(indent, ' ') << "Else:\n";
513 elseBranch->print(indent + 2);
514 }
515 }
516};
517
519struct WhileStmt : public Statement
520{
521 std::unique_ptr<Expression> condition;
522 std::unique_ptr<Statement> body;
523
524 WhileStmt(std::unique_ptr<Expression> cond, std::unique_ptr<Statement> b)
525 : condition(std::move(cond)), body(std::move(b))
526 {
527 }
528
529 void print(int indent = 0) const override
530 {
531 std::cout << std::string(indent, ' ') << "WhileStmt:\n";
532 condition->print(indent + 2);
533 body->print(indent + 2);
534 }
535};
536
538struct ForStmt : public Statement
539{
540 std::unique_ptr<Statement> initializer;
541 std::unique_ptr<Expression> condition;
542 std::unique_ptr<Expression> increment;
543 std::unique_ptr<Statement> body;
544
545 ForStmt(std::unique_ptr<Statement> init, std::unique_ptr<Expression> cond, std::unique_ptr<Expression> incr,
546 std::unique_ptr<Statement> b)
547 : initializer(std::move(init)), condition(std::move(cond)), increment(std::move(incr)), body(std::move(b))
548 {
549 }
550
551 void print(int indent = 0) const override
552 {
553 std::cout << std::string(indent, ' ') << "ForStmt:\n";
554 if (initializer)
555 initializer->print(indent + 2);
556 if (condition)
557 condition->print(indent + 2);
558 if (increment)
559 increment->print(indent + 2);
560 body->print(indent + 2);
561 }
562};
563
566{
567 std::unique_ptr<BlockStmt> block;
568 UnsafeBlockStmt(std::unique_ptr<BlockStmt> b) : block(std::move(b))
569 {
570 }
571 void print(int indent = 0) const override
572 {
573 std::cout << std::string(indent, ' ') << "UnsafeBlockStmt:\n";
574 block->print(indent + 2);
575 }
576};
577
579struct FunctionDecl : public Statement
580{
581 std::string name;
582 struct Param
583 {
584 std::string name;
585 std::unique_ptr<TypeNode> type;
586 };
587 std::vector<Param> params;
588 std::unique_ptr<TypeNode> returnType;
589 std::unique_ptr<BlockStmt> body;
590
591 FunctionDecl(std::string n, std::vector<Param> p, std::unique_ptr<TypeNode> rt, std::unique_ptr<BlockStmt> b)
592 : name(n), params(std::move(p)), returnType(std::move(rt)), body(std::move(b))
593 {
594 }
595
596 void print(int indent = 0) const override
597 {
598 std::cout << std::string(indent, ' ') << "FunctionDecl: " << name << "\n";
599 for (const auto &param : params)
600 {
601 std::cout << std::string(indent + 2, ' ') << "Param: " << param.name << " Type: ";
602 param.type->print(0);
603 }
604 std::cout << std::string(indent + 2, ' ') << "Return Type: ";
605 if (returnType)
606 returnType->print(0);
607 else
608 std::cout << "void\n";
609 if (body)
610 body->print(indent + 2);
611 }
612};
613
616{
617 std::string name;
618 std::unique_ptr<TypeNode> type;
619
620 StructField(std::string n, std::unique_ptr<TypeNode> t) : name(std::move(n)), type(std::move(t))
621 {
622 }
623};
624
626struct StructDecl : public Statement
627{
628 std::string name;
629 std::vector<StructField> fields;
630
631 StructDecl(std::string n, std::vector<StructField> f) : name(std::move(n)), fields(std::move(f))
632 {
633 }
634
635 void print(int indent = 0) const override
636 {
637 std::cout << std::string(indent, ' ') << "StructDecl: " << name << "\n";
638 for (const auto &field : fields)
639 {
640 std::cout << std::string(indent + 2, ' ') << field.name << ": ";
641 field.type->print(0);
642 }
643 }
644};
645
648{
649 std::string structName;
650 std::vector<std::pair<std::string, std::unique_ptr<Expression>>> fieldValues;
651
652 StructInstanceExpr(std::string name, std::vector<std::pair<std::string, std::unique_ptr<Expression>>> fields)
653 : structName(std::move(name)), fieldValues(std::move(fields))
654 {
655 }
656
657 void print(int indent = 0) const override
658 {
659 std::cout << std::string(indent, ' ') << "StructInstance: " << structName << "\n";
660 for (const auto &field : fieldValues)
661 {
662 std::cout << std::string(indent + 2, ' ') << field.first << ":\n";
663 field.second->print(indent + 4);
664 }
665 }
666};
667
670{
671 std::unique_ptr<Expression> object;
672 std::string fieldName;
673
674 FieldAccessExpr(std::unique_ptr<Expression> obj, std::string field)
675 : object(std::move(obj)), fieldName(std::move(field))
676 {
677 }
678
679 void print(int indent = 0) const override
680 {
681 std::cout << std::string(indent, ' ') << "FieldAccess: ." << fieldName << "\n";
682 object->print(indent + 2);
683 }
684};
685
688{
689 std::unique_ptr<Expression> value;
690 std::vector<std::unique_ptr<Statement>> statements;
691
692 CaseClause(std::unique_ptr<Expression> v, std::vector<std::unique_ptr<Statement>> stmts)
693 : value(std::move(v)), statements(std::move(stmts))
694 {
695 }
696};
697
699struct SwitchStmt : public Statement
700{
701 std::unique_ptr<Expression> expr;
702 std::vector<CaseClause> cases;
703 std::vector<std::unique_ptr<Statement>> defaultStmts;
704
705 SwitchStmt(std::unique_ptr<Expression> e, std::vector<CaseClause> c, std::vector<std::unique_ptr<Statement>> d)
706 : expr(std::move(e)), cases(std::move(c)), defaultStmts(std::move(d))
707 {
708 }
709
710 void print(int indent = 0) const override
711 {
712 std::cout << std::string(indent, ' ') << "SwitchStmt:\n";
713 expr->print(indent + 2);
714 for (const auto &c : cases)
715 {
716 std::cout << std::string(indent + 2, ' ') << "case:\n";
717 c.value->print(indent + 4);
718 for (const auto &stmt : c.statements)
719 {
720 stmt->print(indent + 4);
721 }
722 }
723 if (!defaultStmts.empty())
724 {
725 std::cout << std::string(indent + 2, ' ') << "default:\n";
726 for (const auto &stmt : defaultStmts)
727 {
728 stmt->print(indent + 4);
729 }
730 }
731 }
732};
733} // namespace AST
734} // namespace Phasor
Abstract Syntax Tree (AST) namespace.
Definition AST.hpp:11
BinaryOp
Binary operator types.
Definition AST.hpp:140
UnaryOp
Unary operator types.
Definition AST.hpp:131
PostfixOp
Postfix operator types.
Definition AST.hpp:158
The Phasor Programming Language and Runtime.
Definition AST.hpp:8
ArrayAccessExpr(std::unique_ptr< Expression > arr, std::unique_ptr< Expression > idx)
Definition AST.hpp:289
std::unique_ptr< Expression > array
Definition AST.hpp:286
void print(int indent=0) const override
Definition AST.hpp:294
std::unique_ptr< Expression > index
Definition AST.hpp:287
void print(int indent=0) const override
Definition AST.hpp:308
std::vector< std::unique_ptr< Expression > > elements
Definition AST.hpp:306
ArrayLiteralExpr(std::vector< std::unique_ptr< Expression > > elems)
Definition AST.hpp:307
AssignmentExpr(std::unique_ptr< Expression > t, std::unique_ptr< Expression > v)
Definition AST.hpp:358
std::unique_ptr< Expression > target
Definition AST.hpp:355
std::unique_ptr< Expression > value
Definition AST.hpp:356
void print(int indent=0) const override
Definition AST.hpp:363
std::unique_ptr< Expression > right
Definition AST.hpp:226
BinaryExpr(std::unique_ptr< Expression > l, BinaryOp o, std::unique_ptr< Expression > r)
Definition AST.hpp:228
std::unique_ptr< Expression > left
Definition AST.hpp:224
void print(int indent=0) const override
Definition AST.hpp:233
std::vector< std::unique_ptr< Statement > > statements
Definition AST.hpp:446
void print(int indent=0) const override
Definition AST.hpp:450
BlockStmt(std::vector< std::unique_ptr< Statement > > stmts)
Definition AST.hpp:447
void print(int indent=0) const override
Definition AST.hpp:114
Break Statement Node.
Definition AST.hpp:477
void print(int indent=0) const override
Definition AST.hpp:478
CallExpr(std::string name, std::vector< std::unique_ptr< Expression > > args)
Definition AST.hpp:338
std::string callee
Definition AST.hpp:335
std::vector< std::unique_ptr< Expression > > arguments
Definition AST.hpp:336
void print(int indent=0) const override
Definition AST.hpp:342
CaseClause(std::unique_ptr< Expression > v, std::vector< std::unique_ptr< Statement > > stmts)
Definition AST.hpp:692
std::vector< std::unique_ptr< Statement > > statements
Definition AST.hpp:690
std::unique_ptr< Expression > value
Definition AST.hpp:689
Continue Statement Node.
Definition AST.hpp:486
void print(int indent=0) const override
Definition AST.hpp:487
ExportStmt(std::unique_ptr< Statement > decl)
Definition AST.hpp:433
void print(int indent=0) const override
Definition AST.hpp:436
std::unique_ptr< Statement > declaration
Definition AST.hpp:432
Expression Node.
Definition AST.hpp:28
std::unique_ptr< Expression > expression
Definition AST.hpp:392
ExpressionStmt(std::unique_ptr< Expression > expr)
Definition AST.hpp:393
void print(int indent=0) const override
Definition AST.hpp:396
FieldAccessExpr(std::unique_ptr< Expression > obj, std::string field)
Definition AST.hpp:674
void print(int indent=0) const override
Definition AST.hpp:679
std::unique_ptr< Expression > object
Definition AST.hpp:671
std::unique_ptr< Statement > initializer
Definition AST.hpp:540
std::unique_ptr< Expression > increment
Definition AST.hpp:542
void print(int indent=0) const override
Definition AST.hpp:551
std::unique_ptr< Statement > body
Definition AST.hpp:543
ForStmt(std::unique_ptr< Statement > init, std::unique_ptr< Expression > cond, std::unique_ptr< Expression > incr, std::unique_ptr< Statement > b)
Definition AST.hpp:545
std::unique_ptr< Expression > condition
Definition AST.hpp:541
std::unique_ptr< TypeNode > type
Definition AST.hpp:585
FunctionDecl(std::string n, std::vector< Param > p, std::unique_ptr< TypeNode > rt, std::unique_ptr< BlockStmt > b)
Definition AST.hpp:591
std::unique_ptr< TypeNode > returnType
Definition AST.hpp:588
void print(int indent=0) const override
Definition AST.hpp:596
std::vector< Param > params
Definition AST.hpp:587
std::unique_ptr< BlockStmt > body
Definition AST.hpp:589
IdentifierExpr(std::string n)
Definition AST.hpp:98
void print(int indent=0) const override
Definition AST.hpp:101
void print(int indent=0) const override
Definition AST.hpp:505
std::unique_ptr< Statement > elseBranch
Definition AST.hpp:498
std::unique_ptr< Expression > condition
Definition AST.hpp:496
IfStmt(std::unique_ptr< Expression > cond, std::unique_ptr< Statement > thenB, std::unique_ptr< Statement > elseB)
Definition AST.hpp:500
std::unique_ptr< Statement > thenBranch
Definition AST.hpp:497
ImportStmt(std::string path)
Definition AST.hpp:420
std::string modulePath
Definition AST.hpp:419
void print(int indent=0) const override
Definition AST.hpp:423
std::unique_ptr< Expression > object
Definition AST.hpp:318
void print(int indent=0) const override
Definition AST.hpp:325
MemberAccessExpr(std::unique_ptr< Expression > obj, std::string mem)
Definition AST.hpp:321
AST Node.
Definition AST.hpp:21
virtual void print(int indent=0) const =0
virtual ~Node()=default
NULL Expression Node.
Definition AST.hpp:122
void print(int indent=0) const override
Definition AST.hpp:123
std::string value
Definition AST.hpp:71
NumberExpr(std::string v)
Definition AST.hpp:72
void print(int indent=0) const override
Definition AST.hpp:75
PostfixExpr(PostfixOp o, std::unique_ptr< Expression > expr)
Definition AST.hpp:169
std::unique_ptr< Expression > operand
Definition AST.hpp:167
void print(int indent=0) const override
Definition AST.hpp:173
std::unique_ptr< Expression > expression
Definition AST.hpp:405
void print(int indent=0) const override
Definition AST.hpp:409
PrintStmt(std::unique_ptr< Expression > expr)
Definition AST.hpp:406
Program Node.
Definition AST.hpp:38
std::vector< std::unique_ptr< Statement > > statements
Definition AST.hpp:39
void print(int indent=0) const override
Definition AST.hpp:40
ReturnStmt(std::unique_ptr< Expression > val)
Definition AST.hpp:464
std::unique_ptr< Expression > value
Definition AST.hpp:463
void print(int indent=0) const override
Definition AST.hpp:467
Statement Node.
Definition AST.hpp:33
void print(int indent=0) const override
Definition AST.hpp:88
std::string value
Definition AST.hpp:84
StringExpr(std::string v)
Definition AST.hpp:85
void print(int indent=0) const override
Definition AST.hpp:635
std::vector< StructField > fields
Definition AST.hpp:629
std::string name
Definition AST.hpp:628
StructDecl(std::string n, std::vector< StructField > f)
Definition AST.hpp:631
StructField(std::string n, std::unique_ptr< TypeNode > t)
Definition AST.hpp:620
std::unique_ptr< TypeNode > type
Definition AST.hpp:618
StructInstanceExpr(std::string name, std::vector< std::pair< std::string, std::unique_ptr< Expression > > > fields)
Definition AST.hpp:652
std::vector< std::pair< std::string, std::unique_ptr< Expression > > > fieldValues
Definition AST.hpp:650
void print(int indent=0) const override
Definition AST.hpp:657
SwitchStmt(std::unique_ptr< Expression > e, std::vector< CaseClause > c, std::vector< std::unique_ptr< Statement > > d)
Definition AST.hpp:705
void print(int indent=0) const override
Definition AST.hpp:710
std::vector< CaseClause > cases
Definition AST.hpp:702
std::vector< std::unique_ptr< Statement > > defaultStmts
Definition AST.hpp:703
std::unique_ptr< Expression > expr
Definition AST.hpp:701
TypeNode(std::string n, bool ptr=false, std::vector< int > dims={})
Definition AST.hpp:56
void print(int indent=0) const override
Definition AST.hpp:59
std::vector< int > arrayDimensions
Definition AST.hpp:54
std::string name
Definition AST.hpp:52
UnaryExpr(UnaryOp o, std::unique_ptr< Expression > expr)
Definition AST.hpp:195
std::unique_ptr< Expression > operand
Definition AST.hpp:193
void print(int indent=0) const override
Definition AST.hpp:199
UnsafeBlockStmt(std::unique_ptr< BlockStmt > b)
Definition AST.hpp:568
void print(int indent=0) const override
Definition AST.hpp:571
std::unique_ptr< BlockStmt > block
Definition AST.hpp:567
void print(int indent=0) const override
Definition AST.hpp:381
VarDecl(std::string n, std::unique_ptr< Expression > init)
Definition AST.hpp:378
std::string name
Definition AST.hpp:376
std::unique_ptr< Expression > initializer
Definition AST.hpp:377
WhileStmt(std::unique_ptr< Expression > cond, std::unique_ptr< Statement > b)
Definition AST.hpp:524
std::unique_ptr< Expression > condition
Definition AST.hpp:521
std::unique_ptr< Statement > body
Definition AST.hpp:522
void print(int indent=0) const override
Definition AST.hpp:529