-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathast.cpp
More file actions
768 lines (663 loc) · 21.6 KB
/
Copy pathast.cpp
File metadata and controls
768 lines (663 loc) · 21.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
#include "ast.hpp"
// For node constructors, all children are taken as
// parameters, and must be passed in. Optional children
// may be NULL pointers. List children are pointers to
// std::lists of the appropriate type (pointer to some node type).
// Visit Children method for Program AST node
void ProgramNode::visit_children(Visitor* v) {
if (this->class_list) {
for(std::list<ClassNode*>::iterator iter = this->class_list->begin();
iter != this->class_list->end(); iter++) {
(*iter)->accept(v);
}
}
}
// Constructor for Program AST node
ProgramNode::ProgramNode(std::list<ClassNode*>* class_list) {
this->class_list = class_list;
}
// Visit Children method for Class AST node
void ClassNode::visit_children(Visitor* v) {
identifier_1->accept(v);
if (this->identifier_2) {
this->identifier_2->accept(v);
}
if (this->declaration_list) {
for(std::list<DeclarationNode*>::iterator iter = this->declaration_list->begin();
iter != this->declaration_list->end(); iter++) {
(*iter)->accept(v);
}
}
if (this->method_list) {
for(std::list<MethodNode*>::iterator iter = this->method_list->begin();
iter != this->method_list->end(); iter++) {
(*iter)->accept(v);
}
}
}
// Constructor for Class AST node
ClassNode::ClassNode(IdentifierNode* identifier_1, IdentifierNode* identifier_2, std::list<DeclarationNode*>* declaration_list, std::list<MethodNode*>* method_list) {
this->identifier_1 = identifier_1;
this->identifier_2 = identifier_2;
this->declaration_list = declaration_list;
this->method_list = method_list;
}
// Visit Children method for Method AST node
void MethodNode::visit_children(Visitor* v) {
identifier->accept(v);
if (this->parameter_list) {
for(std::list<ParameterNode*>::iterator iter = this->parameter_list->begin();
iter != this->parameter_list->end(); iter++) {
(*iter)->accept(v);
}
}
type->accept(v);
methodbody->accept(v);
}
// Constructor for Method AST node
MethodNode::MethodNode(IdentifierNode* identifier, std::list<ParameterNode*>* parameter_list, TypeNode* type, MethodBodyNode* methodbody) {
this->identifier = identifier;
this->parameter_list = parameter_list;
this->type = type;
this->methodbody = methodbody;
}
// Visit Children method for MethodBody AST node
void MethodBodyNode::visit_children(Visitor* v) {
if (this->declaration_list) {
for(std::list<DeclarationNode*>::iterator iter = this->declaration_list->begin();
iter != this->declaration_list->end(); iter++) {
(*iter)->accept(v);
}
}
if (this->statement_list) {
for(std::list<StatementNode*>::iterator iter = this->statement_list->begin();
iter != this->statement_list->end(); iter++) {
(*iter)->accept(v);
}
}
if (this->returnstatement) {
this->returnstatement->accept(v);
}
}
// Constructor for MethodBody AST node
MethodBodyNode::MethodBodyNode(std::list<DeclarationNode*>* declaration_list, std::list<StatementNode*>* statement_list, ReturnStatementNode* returnstatement) {
this->declaration_list = declaration_list;
this->statement_list = statement_list;
this->returnstatement = returnstatement;
}
// Visit Children method for Parameter AST node
void ParameterNode::visit_children(Visitor* v) {
type->accept(v);
identifier->accept(v);
}
// Constructor for Parameter AST node
ParameterNode::ParameterNode(TypeNode* type, IdentifierNode* identifier) {
this->type = type;
this->identifier = identifier;
}
// Visit Children method for Declaration AST node
void DeclarationNode::visit_children(Visitor* v) {
type->accept(v);
if (this->identifier_list) {
for(std::list<IdentifierNode*>::iterator iter = this->identifier_list->begin();
iter != this->identifier_list->end(); iter++) {
(*iter)->accept(v);
}
}
}
// Constructor for Declaration AST node
DeclarationNode::DeclarationNode(TypeNode* type, std::list<IdentifierNode*>* identifier_list) {
this->type = type;
this->identifier_list = identifier_list;
}
// Visit Children method for ReturnStatement AST node
void ReturnStatementNode::visit_children(Visitor* v) {
expression->accept(v);
}
// Constructor for ReturnStatement AST node
ReturnStatementNode::ReturnStatementNode(ExpressionNode* expression) {
this->expression = expression;
}
// Visit Children method for Assignment AST node
void AssignmentNode::visit_children(Visitor* v) {
identifier_1->accept(v);
if (this->identifier_2) {
this->identifier_2->accept(v);
}
expression->accept(v);
}
// Constructor for Assignment AST node
AssignmentNode::AssignmentNode(IdentifierNode* identifier_1, IdentifierNode* identifier_2, ExpressionNode* expression) {
this->identifier_1 = identifier_1;
this->identifier_2 = identifier_2;
this->expression = expression;
}
// Visit Children method for Call AST node
void CallNode::visit_children(Visitor* v) {
methodcall->accept(v);
}
// Constructor for Call AST node
CallNode::CallNode(MethodCallNode* methodcall) {
this->methodcall = methodcall;
}
// Visit Children method for IfElse AST node
void IfElseNode::visit_children(Visitor* v) {
expression->accept(v);
if (this->statement_list_1) {
for(std::list<StatementNode*>::iterator iter = this->statement_list_1->begin();
iter != this->statement_list_1->end(); iter++) {
(*iter)->accept(v);
}
}
if (this->statement_list_2) {
for(std::list<StatementNode*>::iterator iter = this->statement_list_2->begin();
iter != this->statement_list_2->end(); iter++) {
(*iter)->accept(v);
}
}
}
// Constructor for IfElse AST node
IfElseNode::IfElseNode(ExpressionNode* expression, std::list<StatementNode*>* statement_list_1, std::list<StatementNode*>* statement_list_2) {
this->expression = expression;
this->statement_list_1 = statement_list_1;
this->statement_list_2 = statement_list_2;
}
// Visit Children method for While AST node
void WhileNode::visit_children(Visitor* v) {
expression->accept(v);
if (this->statement_list) {
for(std::list<StatementNode*>::iterator iter = this->statement_list->begin();
iter != this->statement_list->end(); iter++) {
(*iter)->accept(v);
}
}
}
// Constructor for While AST node
WhileNode::WhileNode(ExpressionNode* expression, std::list<StatementNode*>* statement_list) {
this->expression = expression;
this->statement_list = statement_list;
}
// Visit Children method for DoWhile AST node
void DoWhileNode::visit_children(Visitor* v) {
if (this->statement_list) {
for(std::list<StatementNode*>::iterator iter = this->statement_list->begin();
iter != this->statement_list->end(); iter++) {
(*iter)->accept(v);
}
}
expression->accept(v);
}
// Constructor for DoWhile AST node
DoWhileNode::DoWhileNode(std::list<StatementNode*>* statement_list, ExpressionNode* expression) {
this->statement_list = statement_list;
this->expression = expression;
}
// Visit Children method for Print AST node
void PrintNode::visit_children(Visitor* v) {
expression->accept(v);
}
// Constructor for Print AST node
PrintNode::PrintNode(ExpressionNode* expression) {
this->expression = expression;
}
// Visit Children method for Plus AST node
void PlusNode::visit_children(Visitor* v) {
expression_1->accept(v);
expression_2->accept(v);
}
// Constructor for Plus AST node
PlusNode::PlusNode(ExpressionNode* expression_1, ExpressionNode* expression_2) {
this->expression_1 = expression_1;
this->expression_2 = expression_2;
}
// Visit Children method for Minus AST node
void MinusNode::visit_children(Visitor* v) {
expression_1->accept(v);
expression_2->accept(v);
}
// Constructor for Minus AST node
MinusNode::MinusNode(ExpressionNode* expression_1, ExpressionNode* expression_2) {
this->expression_1 = expression_1;
this->expression_2 = expression_2;
}
// Visit Children method for Times AST node
void TimesNode::visit_children(Visitor* v) {
expression_1->accept(v);
expression_2->accept(v);
}
// Constructor for Times AST node
TimesNode::TimesNode(ExpressionNode* expression_1, ExpressionNode* expression_2) {
this->expression_1 = expression_1;
this->expression_2 = expression_2;
}
// Visit Children method for Divide AST node
void DivideNode::visit_children(Visitor* v) {
expression_1->accept(v);
expression_2->accept(v);
}
// Constructor for Divide AST node
DivideNode::DivideNode(ExpressionNode* expression_1, ExpressionNode* expression_2) {
this->expression_1 = expression_1;
this->expression_2 = expression_2;
}
// Visit Children method for Greater AST node
void GreaterNode::visit_children(Visitor* v) {
expression_1->accept(v);
expression_2->accept(v);
}
// Constructor for Greater AST node
GreaterNode::GreaterNode(ExpressionNode* expression_1, ExpressionNode* expression_2) {
this->expression_1 = expression_1;
this->expression_2 = expression_2;
}
// Visit Children method for GreaterEqual AST node
void GreaterEqualNode::visit_children(Visitor* v) {
expression_1->accept(v);
expression_2->accept(v);
}
// Constructor for GreaterEqual AST node
GreaterEqualNode::GreaterEqualNode(ExpressionNode* expression_1, ExpressionNode* expression_2) {
this->expression_1 = expression_1;
this->expression_2 = expression_2;
}
// Visit Children method for Equal AST node
void EqualNode::visit_children(Visitor* v) {
expression_1->accept(v);
expression_2->accept(v);
}
// Constructor for Equal AST node
EqualNode::EqualNode(ExpressionNode* expression_1, ExpressionNode* expression_2) {
this->expression_1 = expression_1;
this->expression_2 = expression_2;
}
// Visit Children method for And AST node
void AndNode::visit_children(Visitor* v) {
expression_1->accept(v);
expression_2->accept(v);
}
// Constructor for And AST node
AndNode::AndNode(ExpressionNode* expression_1, ExpressionNode* expression_2) {
this->expression_1 = expression_1;
this->expression_2 = expression_2;
}
// Visit Children method for Or AST node
void OrNode::visit_children(Visitor* v) {
expression_1->accept(v);
expression_2->accept(v);
}
// Constructor for Or AST node
OrNode::OrNode(ExpressionNode* expression_1, ExpressionNode* expression_2) {
this->expression_1 = expression_1;
this->expression_2 = expression_2;
}
// Visit Children method for Not AST node
void NotNode::visit_children(Visitor* v) {
expression->accept(v);
}
// Constructor for Not AST node
NotNode::NotNode(ExpressionNode* expression) {
this->expression = expression;
}
// Visit Children method for Negation AST node
void NegationNode::visit_children(Visitor* v) {
expression->accept(v);
}
// Constructor for Negation AST node
NegationNode::NegationNode(ExpressionNode* expression) {
this->expression = expression;
}
// Visit Children method for MethodCall AST node
void MethodCallNode::visit_children(Visitor* v) {
identifier_1->accept(v);
if (this->identifier_2) {
this->identifier_2->accept(v);
}
if (this->expression_list) {
for(std::list<ExpressionNode*>::iterator iter = this->expression_list->begin();
iter != this->expression_list->end(); iter++) {
(*iter)->accept(v);
}
}
}
// Constructor for MethodCall AST node
MethodCallNode::MethodCallNode(IdentifierNode* identifier_1, IdentifierNode* identifier_2, std::list<ExpressionNode*>* expression_list) {
this->identifier_1 = identifier_1;
this->identifier_2 = identifier_2;
this->expression_list = expression_list;
}
// Visit Children method for MemberAccess AST node
void MemberAccessNode::visit_children(Visitor* v) {
identifier_1->accept(v);
identifier_2->accept(v);
}
// Constructor for MemberAccess AST node
MemberAccessNode::MemberAccessNode(IdentifierNode* identifier_1, IdentifierNode* identifier_2) {
this->identifier_1 = identifier_1;
this->identifier_2 = identifier_2;
}
// Visit Children method for Variable AST node
void VariableNode::visit_children(Visitor* v) {
identifier->accept(v);
}
// Constructor for Variable AST node
VariableNode::VariableNode(IdentifierNode* identifier) {
this->identifier = identifier;
}
// Visit Children method for IntegerLiteral AST node
void IntegerLiteralNode::visit_children(Visitor* v) {
integer->accept(v);
}
// Constructor for IntegerLiteral AST node
IntegerLiteralNode::IntegerLiteralNode(IntegerNode* integer) {
this->integer = integer;
}
// Visit Children method for BooleanLiteral AST node
void BooleanLiteralNode::visit_children(Visitor* v) {
integer->accept(v);
}
// Constructor for BooleanLiteral AST node
BooleanLiteralNode::BooleanLiteralNode(IntegerNode* integer) {
this->integer = integer;
}
// Visit Children method for New AST node
void NewNode::visit_children(Visitor* v) {
identifier->accept(v);
if (this->expression_list) {
for(std::list<ExpressionNode*>::iterator iter = this->expression_list->begin();
iter != this->expression_list->end(); iter++) {
(*iter)->accept(v);
}
}
}
// Constructor for New AST node
NewNode::NewNode(IdentifierNode* identifier, std::list<ExpressionNode*>* expression_list) {
this->identifier = identifier;
this->expression_list = expression_list;
}
// Visit Children method for IntegerType AST node
void IntegerTypeNode::visit_children(Visitor* v) {
}
// Visit Children method for BooleanType AST node
void BooleanTypeNode::visit_children(Visitor* v) {
}
// Visit Children method for ObjectType AST node
void ObjectTypeNode::visit_children(Visitor* v) {
identifier->accept(v);
}
// Constructor for ObjectType AST node
ObjectTypeNode::ObjectTypeNode(IdentifierNode* identifier) {
this->identifier = identifier;
}
// Visit Children method for None AST node
void NoneNode::visit_children(Visitor* v) {
}
// Definitions for print functions
// Push Level adds a new level to the printed tree (for a node with children)
void Print::pushLevel(std::string name, bool indent = false) {
if (this->elements)
this->stack.push(this->elements);
this->elements = new std::vector<std::string>();
std::stringstream ss;
if (indent)
this->indent += 1;
ss << name << "(";
this->elements->push_back(ss.str());
}
// Add Element adds a new leaf to the printed tree (for a node with no children)
void Print::addElement(std::string name) {
this->elements->push_back(name);
}
// Pop Level finishes the printing of a node with children, and matches with
// calls to push level.
void Print::popLevel(bool breaklines = false, bool deindent = false) {
std::stringstream ss;
ss << this->elements->at(0);
if (breaklines) {
ss << "\n";
for (unsigned int i = 0; i < this->indent; i++)
ss << " ";
}
for (std::vector<std::string>::iterator iter = this->elements->begin()+1; iter != this->elements->end(); iter++) {
ss << (*iter);
if (iter != this->elements->end() - 1) {
ss << ",";
if (breaklines) {
ss << "\n";
for (unsigned int i = 0; i < this->indent; i++)
ss << " ";
} else {
ss << " ";
}
} else {
if (breaklines) {
if (deindent)
this->indent -= 1;
ss << "\n";
for (unsigned int i = 0; i < this->indent; i++)
ss << " ";
}
}
}
delete this->elements;
ss << ")";
if (!stack.empty()) {
this->elements = stack.top();
this->elements->push_back(ss.str());
stack.pop();
} else
std::cout << ss.str() << std::endl;
}
// Define concrete implementations of all abstract visitor functions
// Concrete visit function for Program nodes
void Print::visitProgramNode(ProgramNode* node) {
this->pushLevel("Program", true);
node->visit_children(this);
this->popLevel(true, true);
}
// Concrete visit function for Class nodes
void Print::visitClassNode(ClassNode* node) {
this->pushLevel("Class", true);
node->visit_children(this);
this->popLevel(true, true);
}
// Concrete visit function for Method nodes
void Print::visitMethodNode(MethodNode* node) {
this->pushLevel("Method", true);
node->visit_children(this);
this->popLevel(true, true);
}
// Concrete visit function for MethodBody nodes
void Print::visitMethodBodyNode(MethodBodyNode* node) {
this->pushLevel("MethodBody", true);
node->visit_children(this);
this->popLevel(true, true);
}
// Concrete visit function for Parameter nodes
void Print::visitParameterNode(ParameterNode* node) {
this->pushLevel("Parameter");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for Declaration nodes
void Print::visitDeclarationNode(DeclarationNode* node) {
this->pushLevel("Declaration");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for ReturnStatement nodes
void Print::visitReturnStatementNode(ReturnStatementNode* node) {
this->pushLevel("ReturnStatement");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for Assignment nodes
void Print::visitAssignmentNode(AssignmentNode* node) {
this->pushLevel("Assignment");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for Call nodes
void Print::visitCallNode(CallNode* node) {
this->pushLevel("Call");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for IfElse nodes
void Print::visitIfElseNode(IfElseNode* node) {
this->pushLevel("IfElse", true);
node->visit_children(this);
this->popLevel(true, true);
}
// Concrete visit function for While nodes
void Print::visitWhileNode(WhileNode* node) {
this->pushLevel("While", true);
node->visit_children(this);
this->popLevel(true, true);
}
// Concrete visit function for DoWhile nodes
void Print::visitDoWhileNode(DoWhileNode* node) {
this->pushLevel("DoWhile", true);
node->visit_children(this);
this->popLevel(true, true);
}
// Concrete visit function for Print nodes
void Print::visitPrintNode(PrintNode* node) {
this->pushLevel("Print");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for Plus nodes
void Print::visitPlusNode(PlusNode* node) {
this->pushLevel("Plus");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for Minus nodes
void Print::visitMinusNode(MinusNode* node) {
this->pushLevel("Minus");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for Times nodes
void Print::visitTimesNode(TimesNode* node) {
this->pushLevel("Times");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for Divide nodes
void Print::visitDivideNode(DivideNode* node) {
this->pushLevel("Divide");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for Greater nodes
void Print::visitGreaterNode(GreaterNode* node) {
this->pushLevel("Greater");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for GreaterEqual nodes
void Print::visitGreaterEqualNode(GreaterEqualNode* node) {
this->pushLevel("GreaterEqual");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for Equal nodes
void Print::visitEqualNode(EqualNode* node) {
this->pushLevel("Equal");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for And nodes
void Print::visitAndNode(AndNode* node) {
this->pushLevel("And");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for Or nodes
void Print::visitOrNode(OrNode* node) {
this->pushLevel("Or");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for Not nodes
void Print::visitNotNode(NotNode* node) {
this->pushLevel("Not");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for Negation nodes
void Print::visitNegationNode(NegationNode* node) {
this->pushLevel("Negation");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for MethodCall nodes
void Print::visitMethodCallNode(MethodCallNode* node) {
this->pushLevel("MethodCall");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for MemberAccess nodes
void Print::visitMemberAccessNode(MemberAccessNode* node) {
this->pushLevel("MemberAccess");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for Variable nodes
void Print::visitVariableNode(VariableNode* node) {
this->pushLevel("Variable");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for IntegerLiteral nodes
void Print::visitIntegerLiteralNode(IntegerLiteralNode* node) {
this->pushLevel("IntegerLiteral");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for BooleanLiteral nodes
void Print::visitBooleanLiteralNode(BooleanLiteralNode* node) {
this->pushLevel("BooleanLiteral");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for New nodes
void Print::visitNewNode(NewNode* node) {
this->pushLevel("New");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for IntegerType nodes
void Print::visitIntegerTypeNode(IntegerTypeNode* node) {
this->addElement("IntegerType");
}
// Concrete visit function for BooleanType nodes
void Print::visitBooleanTypeNode(BooleanTypeNode* node) {
this->addElement("BooleanType");
}
// Concrete visit function for ObjectType nodes
void Print::visitObjectTypeNode(ObjectTypeNode* node) {
this->pushLevel("ObjectType");
node->visit_children(this);
this->popLevel();
}
// Concrete visit function for None nodes
void Print::visitNoneNode(NoneNode* node) {
this->addElement("None");
}
// Concrete visit function for Identifiers (leaf nodes)
void Print::visitIdentifierNode(IdentifierNode* node) {
std::stringstream ss;
// Print the name of the indentifier surrounded by quotes
ss << "\"" << node->name << "\"";
this->addElement(ss.str());
node->visit_children(this);
}
void Print::visitIntegerNode(IntegerNode* node) {
std::stringstream ss;
// Print the value of the integer
ss << node->value;
this->addElement(ss.str());
node->visit_children(this);
}