1
2
3
4
5
6 #include <sngcm/ast/Expression.hpp>
7 #include <sngcm/ast/Identifier.hpp>
8 #include <sngcm/ast/Visitor.hpp>
9
10 namespace sngcm { namespace ast {
11
12 DotNode::DotNode(const Span& span_) : UnaryNode(NodeType::dotNode, span_), memberId()
13 {
14 }
15
16 DotNode::DotNode(const Span& span_, Node* subject_, IdentifierNode* memberId_) : UnaryNode(NodeType::dotNode, span_, subject_), memberId(memberId_)
17 {
18 memberId->SetParent(this);
19 }
20
21 Node* DotNode::Clone(CloneContext& cloneContext) const
22 {
23 return new DotNode(GetSpan(), Subject()->Clone(cloneContext), static_cast<IdentifierNode*>(memberId->Clone(cloneContext)));
24 }
25
26 void DotNode::Accept(Visitor& visitor)
27 {
28 visitor.Visit(*this);
29 }
30
31 void DotNode::Write(AstWriter& writer)
32 {
33 UnaryNode::Write(writer);
34 writer.Write(memberId.get());
35 }
36
37 void DotNode::Read(AstReader& reader)
38 {
39 UnaryNode::Read(reader);
40 memberId.reset(reader.ReadIdentifierNode());
41 memberId->SetParent(this);
42 }
43
44 std::string DotNode::ToString() const
45 {
46 return Subject()->ToString() + "." + memberId->ToString();
47 }
48
49 ArrowNode::ArrowNode(const Span& span_) : UnaryNode(NodeType::arrowNode, span_), memberId()
50 {
51 }
52
53 ArrowNode::ArrowNode(const Span& span_, Node* subject_, IdentifierNode* memberId_) : UnaryNode(NodeType::arrowNode, span_, subject_), memberId(memberId_)
54 {
55 memberId->SetParent(this);
56 }
57
58 Node* ArrowNode::Clone(CloneContext& cloneContext) const
59 {
60 return new ArrowNode(GetSpan(), Subject()->Clone(cloneContext), static_cast<IdentifierNode*>(memberId->Clone(cloneContext)));
61 }
62
63 void ArrowNode::Accept(Visitor& visitor)
64 {
65 visitor.Visit(*this);
66 }
67
68 void ArrowNode::Write(AstWriter& writer)
69 {
70 UnaryNode::Write(writer);
71 writer.Write(memberId.get());
72 }
73
74 void ArrowNode::Read(AstReader& reader)
75 {
76 UnaryNode::Read(reader);
77 memberId.reset(reader.ReadIdentifierNode());
78 memberId->SetParent(this);
79 }
80
81 std::string ArrowNode::ToString() const
82 {
83 return Subject()->ToString() + "->" + memberId->ToString();
84 }
85
86 EquivalenceNode::EquivalenceNode(const Span& span_) : BinaryNode(NodeType::equivalenceNode, span_)
87 {
88 }
89
90 EquivalenceNode::EquivalenceNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::equivalenceNode, span_, left_, right_)
91 {
92 }
93
94 Node* EquivalenceNode::Clone(CloneContext& cloneContext) const
95 {
96 return new EquivalenceNode(GetSpan(), Left()->Clone(cloneContext), Right()->Clone(cloneContext));
97 }
98
99 void EquivalenceNode::Accept(Visitor& visitor)
100 {
101 visitor.Visit(*this);
102 }
103
104 std::string EquivalenceNode::ToString() const
105 {
106 return Left()->ToString() + "<=>" + Right()->ToString();
107 }
108
109 ImplicationNode::ImplicationNode(const Span& span_) : BinaryNode(NodeType::implicationNode, span_)
110 {
111 }
112
113 ImplicationNode::ImplicationNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::implicationNode, span_, left_, right_)
114 {
115 }
116
117 Node* ImplicationNode::Clone(CloneContext& cloneContext) const
118 {
119 return new ImplicationNode(GetSpan(), Left()->Clone(cloneContext), Right()->Clone(cloneContext));
120 }
121
122 void ImplicationNode::Accept(Visitor& visitor)
123 {
124 visitor.Visit(*this);
125 }
126
127 std::string ImplicationNode::ToString() const
128 {
129 return Left()->ToString() + "=>" + Right()->ToString();
130 }
131
132 DisjunctionNode::DisjunctionNode(const Span& span_) : BinaryNode(NodeType::disjunctionNode, span_)
133 {
134 }
135
136 DisjunctionNode::DisjunctionNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::disjunctionNode, span_, left_, right_)
137 {
138 }
139
140 Node* DisjunctionNode::Clone(CloneContext& cloneContext) const
141 {
142 return new DisjunctionNode(GetSpan(), Left()->Clone(cloneContext), Right()->Clone(cloneContext));
143 }
144
145 void DisjunctionNode::Accept(Visitor& visitor)
146 {
147 visitor.Visit(*this);
148 }
149
150 std::string DisjunctionNode::ToString() const
151 {
152 return Left()->ToString() + " || " + Right()->ToString();
153 }
154
155 ConjunctionNode::ConjunctionNode(const Span& span_) : BinaryNode(NodeType::conjunctionNode, span_)
156 {
157 }
158
159 ConjunctionNode::ConjunctionNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::conjunctionNode, span_, left_, right_)
160 {
161 }
162
163 Node* ConjunctionNode::Clone(CloneContext& cloneContext) const
164 {
165 return new ConjunctionNode(GetSpan(), Left()->Clone(cloneContext), Right()->Clone(cloneContext));
166 }
167
168 void ConjunctionNode::Accept(Visitor& visitor)
169 {
170 visitor.Visit(*this);
171 }
172
173 std::string ConjunctionNode::ToString() const
174 {
175 return Left()->ToString() + " && " + Right()->ToString();
176 }
177
178 BitOrNode::BitOrNode(const Span& span_) : BinaryNode(NodeType::bitOrNode, span_)
179 {
180 }
181
182 BitOrNode::BitOrNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::bitOrNode, span_, left_, right_)
183 {
184 }
185
186 Node* BitOrNode::Clone(CloneContext& cloneContext) const
187 {
188 return new BitOrNode(GetSpan(), Left()->Clone(cloneContext), Right()->Clone(cloneContext));
189 }
190
191 void BitOrNode::Accept(Visitor& visitor)
192 {
193 visitor.Visit(*this);
194 }
195
196 std::string BitOrNode::ToString() const
197 {
198 return Left()->ToString() + " | " + Right()->ToString();
199 }
200
201 BitXorNode::BitXorNode(const Span& span_) : BinaryNode(NodeType::bitXorNode, span_)
202 {
203 }
204
205 BitXorNode::BitXorNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::bitXorNode, span_, left_, right_)
206 {
207 }
208
209 Node* BitXorNode::Clone(CloneContext& cloneContext) const
210 {
211 return new BitXorNode(GetSpan(), Left()->Clone(cloneContext), Right()->Clone(cloneContext));
212 }
213
214 void BitXorNode::Accept(Visitor& visitor)
215 {
216 visitor.Visit(*this);
217 }
218
219 std::string BitXorNode::ToString() const
220 {
221 return Left()->ToString() + " ^ " + Right()->ToString();
222 }
223
224 BitAndNode::BitAndNode(const Span& span_) : BinaryNode(NodeType::bitAndNode, span_)
225 {
226 }
227
228 BitAndNode::BitAndNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::bitAndNode, span_, left_, right_)
229 {
230 }
231
232 Node* BitAndNode::Clone(CloneContext& cloneContext) const
233 {
234 return new BitAndNode(GetSpan(), Left()->Clone(cloneContext), Right()->Clone(cloneContext));
235 }
236
237 void BitAndNode::Accept(Visitor& visitor)
238 {
239 visitor.Visit(*this);
240 }
241
242 std::string BitAndNode::ToString() const
243 {
244 return Left()->ToString() + " & " + Right()->ToString();
245 }
246
247 EqualNode::EqualNode(const Span& span_) : BinaryNode(NodeType::equalNode, span_)
248 {
249 }
250
251 EqualNode::EqualNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::equalNode, span_, left_, right_)
252 {
253 }
254
255 Node* EqualNode::Clone(CloneContext& cloneContext) const
256 {
257 return new EqualNode(GetSpan(), Left()->Clone(cloneContext), Right()->Clone(cloneContext));
258 }
259
260 void EqualNode::Accept(Visitor& visitor)
261 {
262 visitor.Visit(*this);
263 }
264
265 std::string EqualNode::ToString() const
266 {
267 return Left()->ToString() + " == " + Right()->ToString();
268 }
269
270 NotEqualNode::NotEqualNode(const Span& span_) : BinaryNode(NodeType::notEqualNode, span_)
271 {
272 }
273
274 NotEqualNode::NotEqualNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::notEqualNode, span_, left_, right_)
275 {
276 }
277
278 Node* NotEqualNode::Clone(CloneContext& cloneContext) const
279 {
280 return new NotEqualNode(GetSpan(), Left()->Clone(cloneContext), Right()->Clone(cloneContext));
281 }
282
283 void NotEqualNode::Accept(Visitor& visitor)
284 {
285 visitor.Visit(*this);
286 }
287
288 std::string NotEqualNode::ToString() const
289 {
290 return Left()->ToString() + " != " + Right()->ToString();
291 }
292
293 LessNode::LessNode(const Span& span_) : BinaryNode(NodeType::lessNode, span_)
294 {
295 }
296
297 LessNode::LessNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::lessNode, span_, left_, right_)
298 {
299 }
300
301 Node* LessNode::Clone(CloneContext& cloneContext) const
302 {
303 return new LessNode(GetSpan(), Left()->Clone(cloneContext), Right()->Clone(cloneContext));
304 }
305
306 void LessNode::Accept(Visitor& visitor)
307 {
308 visitor.Visit(*this);
309 }
310
311 std::string LessNode::ToString() const
312 {
313 return Left()->ToString() + " < " + Right()->ToString();
314 }
315
316 GreaterNode::GreaterNode(const Span& span_) : BinaryNode(NodeType::greaterNode, span_)
317 {
318 }
319
320 GreaterNode::GreaterNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::greaterNode, span_, left_, right_)
321 {
322 }
323
324 Node* GreaterNode::Clone(CloneContext& cloneContext) const
325 {
326 return new GreaterNode(GetSpan(), Left()->Clone(cloneContext), Right()->Clone(cloneContext));
327 }
328
329 void GreaterNode::Accept(Visitor& visitor)
330 {
331 visitor.Visit(*this);
332 }
333
334 std::string GreaterNode::ToString() const
335 {
336 return Left()->ToString() + " > " + Right()->ToString();
337 }
338
339 LessOrEqualNode::LessOrEqualNode(const Span& span_) : BinaryNode(NodeType::lessOrEqualNode, span_)
340 {
341 }
342
343 LessOrEqualNode::LessOrEqualNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::lessOrEqualNode, span_, left_, right_)
344 {
345 }
346
347 Node* LessOrEqualNode::Clone(CloneContext& cloneContext) const
348 {
349 return new LessOrEqualNode(GetSpan(), Left()->Clone(cloneContext), Right()->Clone(cloneContext));
350 }
351
352 void LessOrEqualNode::Accept(Visitor& visitor)
353 {
354 visitor.Visit(*this);
355 }
356
357 std::string LessOrEqualNode::ToString() const
358 {
359 return Left()->ToString() + " <= " + Right()->ToString();
360 }
361
362 GreaterOrEqualNode::GreaterOrEqualNode(const Span& span_) : BinaryNode(NodeType::greaterOrEqualNode, span_)
363 {
364 }
365
366 GreaterOrEqualNode::GreaterOrEqualNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::greaterOrEqualNode, span_, left_, right_)
367 {
368 }
369
370 Node* GreaterOrEqualNode::Clone(CloneContext& cloneContext) const
371 {
372 return new GreaterOrEqualNode(GetSpan(), Left()->Clone(cloneContext), Right()->Clone(cloneContext));
373 }
374
375 void GreaterOrEqualNode::Accept(Visitor& visitor)
376 {
377 visitor.Visit(*this);
378 }
379
380 std::string GreaterOrEqualNode::ToString() const
381 {
382 return Left()->ToString() + " >= " + Right()->ToString();
383 }
384
385 ShiftLeftNode::ShiftLeftNode(const Span& span_) : BinaryNode(NodeType::shiftLeftNode, span_)
386 {
387 }
388
389 ShiftLeftNode::ShiftLeftNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::shiftLeftNode, span_, left_, right_)
390 {
391 }
392
393 Node* ShiftLeftNode::Clone(CloneContext& cloneContext) const
394 {
395 return new ShiftLeftNode(GetSpan(), Left()->Clone(cloneContext), Right()->Clone(cloneContext));
396 }
397
398 void ShiftLeftNode::Accept(Visitor& visitor)
399 {
400 visitor.Visit(*this);
401 }
402
403 std::string ShiftLeftNode::ToString() const
404 {
405 return Left()->ToString() + " << " + Right()->ToString();
406 }
407
408 ShiftRightNode::ShiftRightNode(const Span& span_) : BinaryNode(NodeType::shiftRightNode, span_)
409 {
410 }
411
412 ShiftRightNode::ShiftRightNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::shiftRightNode, span_, left_, right_)
413 {
414 }
415
416 Node* ShiftRightNode::Clone(CloneContext& cloneContext) const
417 {
418 return new ShiftRightNode(GetSpan(), Left()->Clone(cloneContext), Right()->Clone(cloneContext));
419 }
420
421 void ShiftRightNode::Accept(Visitor& visitor)
422 {
423 visitor.Visit(*this);
424 }
425
426 std::string ShiftRightNode::ToString() const
427 {
428 return Left()->ToString() + " >> " + Right()->ToString();
429 }
430
431 AddNode::AddNode(const Span& span_) : BinaryNode(NodeType::addNode, span_)
432 {
433 }
434
435 AddNode::AddNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::addNode, span_, left_, right_)
436 {
437 }
438
439 Node* AddNode::Clone(CloneContext& cloneContext) const
440 {
441 return new AddNode(GetSpan(), Left()->Clone(cloneContext), Right()->Clone(cloneContext));
442 }
443
444 void AddNode::Accept(Visitor& visitor)
445 {
446 visitor.Visit(*this);
447 }
448
449 std::string AddNode::ToString() const
450 {
451 return Left()->ToString() + " + " + Right()->ToString();
452 }
453
454 SubNode::SubNode(const Span& span_) : BinaryNode(NodeType::subNode, span_)
455 {
456 }
457
458 SubNode::SubNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::subNode, span_, left_, right_)
459 {
460 }
461
462 Node* SubNode::Clone(CloneContext& cloneContext) const
463 {
464 return new SubNode(GetSpan(), Left()->Clone(cloneContext), Right()->Clone(cloneContext));
465 }
466
467 void SubNode::Accept(Visitor& visitor)
468 {
469 visitor.Visit(*this);
470 }
471
472 std::string SubNode::ToString() const
473 {
474 return Left()->ToString() + " - " + Right()->ToString();
475 }
476
477 MulNode::MulNode(const Span& span_) : BinaryNode(NodeType::mulNode, span_)
478 {
479 }
480
481 MulNode::MulNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::mulNode, span_, left_, right_)
482 {
483 }
484
485 Node* MulNode::Clone(CloneContext& cloneContext) const
486 {
487 return new MulNode(GetSpan(), Left()->Clone(cloneContext), Right()->Clone(cloneContext));
488 }
489
490 void MulNode::Accept(Visitor& visitor)
491 {
492 visitor.Visit(*this);
493 }
494
495 std::string MulNode::ToString() const
496 {
497 return Left()->ToString() + " * " + Right()->ToString();
498 }
499
500 DivNode::DivNode(const Span& span_) : BinaryNode(NodeType::divNode, span_)
501 {
502 }
503
504 DivNode::DivNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::divNode, span_, left_, right_)
505 {
506 }
507
508 Node* DivNode::Clone(CloneContext& cloneContext) const
509 {
510 return new DivNode(GetSpan(), Left()->Clone(cloneContext), Right()->Clone(cloneContext));
511 }
512
513 void DivNode::Accept(Visitor& visitor)
514 {
515 visitor.Visit(*this);
516 }
517
518 std::string DivNode::ToString() const
519 {
520 return Left()->ToString() + " / " + Right()->ToString();
521 }
522
523 RemNode::RemNode(const Span& span_) : BinaryNode(NodeType::remNode, span_)
524 {
525 }
526
527 RemNode::RemNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::remNode, span_, left_, right_)
528 {
529 }
530
531 Node* RemNode::Clone(CloneContext& cloneContext) const
532 {
533 return new RemNode(GetSpan(), Left()->Clone(cloneContext), Right()->Clone(cloneContext));
534 }
535
536 void RemNode::Accept(Visitor& visitor)
537 {
538 visitor.Visit(*this);
539 }
540
541 std::string RemNode::ToString() const
542 {
543 return Left()->ToString() + " % " + Right()->ToString();
544 }
545
546 NotNode::NotNode(const Span& span_) : UnaryNode(NodeType::notNode, span_)
547 {
548 }
549
550 NotNode::NotNode(const Span& span_, Node* subject_) : UnaryNode(NodeType::notNode, span_, subject_)
551 {
552 }
553
554 Node* NotNode::Clone(CloneContext& cloneContext) const
555 {
556 return new NotNode(GetSpan(), Subject()->Clone(cloneContext));
557 }
558
559 void NotNode::Accept(Visitor& visitor)
560 {
561 visitor.Visit(*this);
562 }
563
564 std::string NotNode::ToString() const
565 {
566 return "!" + Subject()->ToString();
567 }
568
569 UnaryPlusNode::UnaryPlusNode(const Span& span_) : UnaryNode(NodeType::unaryPlusNode, span_)
570 {
571 }
572
573 UnaryPlusNode::UnaryPlusNode(const Span& span_, Node* subject_) : UnaryNode(NodeType::unaryPlusNode, span_, subject_)
574 {
575 }
576
577 Node* UnaryPlusNode::Clone(CloneContext& cloneContext) const
578 {
579 return new UnaryPlusNode(GetSpan(), Subject()->Clone(cloneContext));
580 }
581
582 void UnaryPlusNode::Accept(Visitor& visitor)
583 {
584 visitor.Visit(*this);
585 }
586
587 std::string UnaryPlusNode::ToString() const
588 {
589 return "+" + Subject()->ToString();
590 }
591
592 UnaryMinusNode::UnaryMinusNode(const Span& span_) : UnaryNode(NodeType::unaryMinusNode, span_)
593 {
594 }
595
596 UnaryMinusNode::UnaryMinusNode(const Span& span_, Node* subject_) : UnaryNode(NodeType::unaryMinusNode, span_, subject_)
597 {
598 }
599
600 Node* UnaryMinusNode::Clone(CloneContext& cloneContext) const
601 {
602 return new UnaryMinusNode(GetSpan(), Subject()->Clone(cloneContext));
603 }
604
605 void UnaryMinusNode::Accept(Visitor& visitor)
606 {
607 visitor.Visit(*this);
608 }
609
610 std::string UnaryMinusNode::ToString() const
611 {
612 return "-" + Subject()->ToString();
613 }
614
615 PrefixIncrementNode::PrefixIncrementNode(const Span& span_) : UnaryNode(NodeType::prefixIncrementNode, span_)
616 {
617 }
618
619 PrefixIncrementNode::PrefixIncrementNode(const Span& span_, Node* subject_) : UnaryNode(NodeType::prefixIncrementNode, span_, subject_)
620 {
621 }
622
623 Node* PrefixIncrementNode::Clone(CloneContext& cloneContext) const
624 {
625 return new PrefixIncrementNode(GetSpan(), Subject()->Clone(cloneContext));
626 }
627
628 void PrefixIncrementNode::Accept(Visitor& visitor)
629 {
630 visitor.Visit(*this);
631 }
632
633 std::string PrefixIncrementNode::ToString() const
634 {
635 return "++" + Subject()->ToString();
636 }
637
638 PrefixDecrementNode::PrefixDecrementNode(const Span& span_) : UnaryNode(NodeType::prefixDecrementNode, span_)
639 {
640 }
641
642 PrefixDecrementNode::PrefixDecrementNode(const Span& span_, Node* subject_) : UnaryNode(NodeType::prefixDecrementNode, span_, subject_)
643 {
644 }
645
646 Node* PrefixDecrementNode::Clone(CloneContext& cloneContext) const
647 {
648 return new PrefixDecrementNode(GetSpan(), Subject()->Clone(cloneContext));
649 }
650
651 void PrefixDecrementNode::Accept(Visitor& visitor)
652 {
653 visitor.Visit(*this);
654 }
655
656 std::string PrefixDecrementNode::ToString() const
657 {
658 return "--" + Subject()->ToString();
659 }
660
661 ComplementNode::ComplementNode(const Span& span_) : UnaryNode(NodeType::complementNode, span_)
662 {
663 }
664
665 ComplementNode::ComplementNode(const Span& span_, Node* subject_) : UnaryNode(NodeType::complementNode, span_, subject_)
666 {
667 }
668
669 Node* ComplementNode::Clone(CloneContext& cloneContext) const
670 {
671 return new ComplementNode(GetSpan(), Subject()->Clone(cloneContext));
672 }
673
674 void ComplementNode::Accept(Visitor& visitor)
675 {
676 visitor.Visit(*this);
677 }
678
679 std::string ComplementNode::ToString() const
680 {
681 return "~" + Subject()->ToString();
682 }
683
684 DerefNode::DerefNode(const Span& span_) : UnaryNode(NodeType::derefNode, span_)
685 {
686 }
687
688 DerefNode::DerefNode(const Span& span_, Node* subject_) : UnaryNode(NodeType::derefNode, span_, subject_)
689 {
690 }
691
692 Node* DerefNode::Clone(CloneContext& cloneContext) const
693 {
694 return new DerefNode(GetSpan(), Subject()->Clone(cloneContext));
695 }
696
697 void DerefNode::Accept(Visitor& visitor)
698 {
699 visitor.Visit(*this);
700 }
701
702 std::string DerefNode::ToString() const
703 {
704 return "*" + Subject()->ToString();
705 }
706
707 AddrOfNode::AddrOfNode(const Span& span_) : UnaryNode(NodeType::addrOfNode, span_)
708 {
709 }
710
711 AddrOfNode::AddrOfNode(const Span& span_, Node* subject_) : UnaryNode(NodeType::addrOfNode, span_, subject_)
712 {
713 }
714
715 Node* AddrOfNode::Clone(CloneContext& cloneContext) const
716 {
717 return new AddrOfNode(GetSpan(), Subject()->Clone(cloneContext));
718 }
719
720 void AddrOfNode::Accept(Visitor& visitor)
721 {
722 visitor.Visit(*this);
723 }
724
725 std::string AddrOfNode::ToString() const
726 {
727 return "&" + Subject()->ToString();
728 }
729
730 IsNode::IsNode(const Span& span_) : Node(NodeType::isNode, span_), expr(), targetTypeExpr()
731 {
732 }
733
734 IsNode::IsNode(const Span& span_, Node* expr_, Node* targetTypeExpr_) : Node(NodeType::isNode, span_), expr(expr_), targetTypeExpr(targetTypeExpr_)
735 {
736 expr->SetParent(this);
737 targetTypeExpr->SetParent(this);
738 }
739
740 Node* IsNode::Clone(CloneContext& cloneContext) const
741 {
742 return new IsNode(GetSpan(), expr->Clone(cloneContext), targetTypeExpr->Clone(cloneContext));
743 }
744
745 void IsNode::Accept(Visitor& visitor)
746 {
747 visitor.Visit(*this);
748 }
749
750 void IsNode::Write(AstWriter& writer)
751 {
752 Node::Write(writer);
753 writer.Write(expr.get());
754 writer.Write(targetTypeExpr.get());
755 }
756
757 void IsNode::Read(AstReader& reader)
758 {
759 Node::Read(reader);
760 expr.reset(reader.ReadNode());
761 expr->SetParent(this);
762 targetTypeExpr.reset(reader.ReadNode());
763 targetTypeExpr->SetParent(this);
764 }
765
766 std::string IsNode::ToString() const
767 {
768 return expr->ToString() + " is " + targetTypeExpr->ToString();
769 }
770
771 AsNode::AsNode(const Span& span_) : Node(NodeType::asNode, span_), expr(), targetTypeExpr()
772 {
773 }
774
775 AsNode::AsNode(const Span& span_, Node* expr_, Node* targetTypeExpr_) : Node(NodeType::asNode, span_), expr(expr_), targetTypeExpr(targetTypeExpr_)
776 {
777 expr->SetParent(this);
778 targetTypeExpr->SetParent(this);
779 }
780
781 Node* AsNode::Clone(CloneContext& cloneContext) const
782 {
783 return new AsNode(GetSpan(), expr->Clone(cloneContext), targetTypeExpr->Clone(cloneContext));
784 }
785
786 void AsNode::Accept(Visitor& visitor)
787 {
788 visitor.Visit(*this);
789 }
790
791 void AsNode::Write(AstWriter& writer)
792 {
793 Node::Write(writer);
794 writer.Write(expr.get());
795 writer.Write(targetTypeExpr.get());
796 }
797
798 void AsNode::Read(AstReader& reader)
799 {
800 Node::Read(reader);
801 expr.reset(reader.ReadNode());
802 expr->SetParent(this);
803 targetTypeExpr.reset(reader.ReadNode());
804 targetTypeExpr->SetParent(this);
805 }
806
807 std::string AsNode::ToString() const
808 {
809 return expr->ToString() + " as " + targetTypeExpr->ToString();
810 }
811
812 IndexingNode::IndexingNode(const Span& span_) : Node(NodeType::indexingNode, span_), subject(), index()
813 {
814 }
815
816 IndexingNode::IndexingNode(const Span& span_, Node* subject_, Node* index_) : Node(NodeType::indexingNode, span_), subject(subject_), index(index_)
817 {
818 subject->SetParent(this);
819 index->SetParent(this);
820 }
821
822 Node* IndexingNode::Clone(CloneContext& cloneContext) const
823 {
824 return new IndexingNode(GetSpan(), subject->Clone(cloneContext), index->Clone(cloneContext));
825 }
826
827 void IndexingNode::Accept(Visitor& visitor)
828 {
829 visitor.Visit(*this);
830 }
831
832 void IndexingNode::Write(AstWriter& writer)
833 {
834 Node::Write(writer);
835 writer.Write(subject.get());
836 writer.Write(index.get());
837 }
838
839 void IndexingNode::Read(AstReader& reader)
840 {
841 Node::Read(reader);
842 subject.reset(reader.ReadNode());
843 subject->SetParent(this);
844 index.reset(reader.ReadNode());
845 index->SetParent(this);
846 }
847
848 std::string IndexingNode::ToString() const
849 {
850 return subject->ToString() + "[" + index->ToString() + "]";
851 }
852
853 InvokeNode::InvokeNode(const Span& span_) : Node(NodeType::invokeNode, span_), subject(), arguments()
854 {
855 }
856
857 InvokeNode::InvokeNode(const Span& span_, Node* subject_) : Node(NodeType::invokeNode, span_), subject(subject_), arguments()
858 {
859 subject->SetParent(this);
860 }
861
862 Node* InvokeNode::Clone(CloneContext& cloneContext) const
863 {
864 InvokeNode* clone = new InvokeNode(GetSpan(), subject->Clone(cloneContext));
865 int n = arguments.Count();
866 for (int i = 0; i < n; ++i)
867 {
868 Node* argument = arguments[i];
869 clone->AddArgument(argument->Clone(cloneContext));
870 }
871 return clone;
872 }
873
874 void InvokeNode::Accept(Visitor& visitor)
875 {
876 visitor.Visit(*this);
877 }
878
879 void InvokeNode::Write(AstWriter& writer)
880 {
881 Node::Write(writer);
882 writer.Write(subject.get());
883 arguments.Write(writer);
884 }
885
886 void InvokeNode::Read(AstReader& reader)
887 {
888 Node::Read(reader);
889 subject.reset(reader.ReadNode());
890 subject->SetParent(this);
891 arguments.Read(reader);
892 arguments.SetParent(this);
893 }
894
895 void InvokeNode::AddArgument(Node* argument)
896 {
897 argument->SetParent(this);
898 arguments.Add(argument);
899 }
900
901 std::string InvokeNode::ToString() const
902 {
903 std::string s = subject->ToString();
904 s.append("(");
905 int n = arguments.Count();
906 for (int i = 0; i < n; ++i)
907 {
908 if (i > 0)
909 {
910 s.append(", ");
911 }
912 s.append(arguments[i]->ToString());
913 }
914 s.append(")");
915 return s;
916 }
917
918 PostfixIncrementNode::PostfixIncrementNode(const Span& span_) : UnaryNode(NodeType::postfixIncrementNode, span_)
919 {
920 }
921
922 PostfixIncrementNode::PostfixIncrementNode(const Span& span_, Node* subject_) : UnaryNode(NodeType::postfixIncrementNode, span_, subject_)
923 {
924 }
925
926 Node* PostfixIncrementNode::Clone(CloneContext& cloneContext) const
927 {
928 return new PostfixIncrementNode(GetSpan(), Subject()->Clone(cloneContext));
929 }
930
931 void PostfixIncrementNode::Accept(Visitor& visitor)
932 {
933 visitor.Visit(*this);
934 }
935
936 std::string PostfixIncrementNode::ToString() const
937 {
938 return Subject()->ToString() + "++";
939 }
940
941 PostfixDecrementNode::PostfixDecrementNode(const Span& span_) : UnaryNode(NodeType::postfixDecrementNode, span_)
942 {
943 }
944
945 PostfixDecrementNode::PostfixDecrementNode(const Span& span_, Node* subject_) : UnaryNode(NodeType::postfixDecrementNode, span_, subject_)
946 {
947 }
948
949 Node* PostfixDecrementNode::Clone(CloneContext& cloneContext) const
950 {
951 return new PostfixDecrementNode(GetSpan(), Subject()->Clone(cloneContext));
952 }
953
954 void PostfixDecrementNode::Accept(Visitor& visitor)
955 {
956 visitor.Visit(*this);
957 }
958
959 std::string PostfixDecrementNode::ToString() const
960 {
961 return Subject()->ToString() + "--";
962 }
963
964 SizeOfNode::SizeOfNode(const Span& span_) : Node(NodeType::sizeOfNode, span_), expression()
965 {
966 }
967
968 SizeOfNode::SizeOfNode(const Span& span_, Node* expression_) : Node(NodeType::sizeOfNode, span_), expression(expression_)
969 {
970 expression->SetParent(this);
971 }
972
973 Node* SizeOfNode::Clone(CloneContext& cloneContext) const
974 {
975 return new SizeOfNode(GetSpan(), expression->Clone(cloneContext));
976 }
977
978 void SizeOfNode::Accept(Visitor& visitor)
979 {
980 visitor.Visit(*this);
981 }
982
983 void SizeOfNode::Write(AstWriter& writer)
984 {
985 Node::Write(writer);
986 writer.Write(expression.get());
987 }
988
989 void SizeOfNode::Read(AstReader& reader)
990 {
991 Node::Read(reader);
992 expression.reset(reader.ReadNode());
993 expression->SetParent(this);
994 }
995
996 std::string SizeOfNode::ToString() const
997 {
998 return "sizeof(" + expression->ToString() + ")";
999 }
1000
1001 TypeNameNode::TypeNameNode(const Span& span_) : Node(NodeType::typeNameNode, span_), expression(), static_(false)
1002 {
1003 }
1004
1005 TypeNameNode::TypeNameNode(const Span& span_, Node* expression_) : Node(NodeType::typeNameNode, span_), expression(expression_), static_(false)
1006 {
1007 expression->SetParent(this);
1008 }
1009
1010 Node* TypeNameNode::Clone(CloneContext& cloneContext) const
1011 {
1012 TypeNameNode* typeNameNode = new TypeNameNode(GetSpan(), expression->Clone(cloneContext));
1013 if (static_)
1014 {
1015 typeNameNode->SetStatic();
1016 }
1017 return typeNameNode;
1018 }
1019
1020 void TypeNameNode::Accept(Visitor& visitor)
1021 {
1022 visitor.Visit(*this);
1023 }
1024
1025 void TypeNameNode::Write(AstWriter& writer)
1026 {
1027 Node::Write(writer);
1028 writer.Write(expression.get());
1029 writer.GetBinaryWriter().Write(static_);
1030 }
1031
1032 void TypeNameNode::Read(AstReader& reader)
1033 {
1034 Node::Read(reader);
1035 expression.reset(reader.ReadNode());
1036 expression->SetParent(this);
1037 static_ = reader.GetBinaryReader().ReadBool();
1038 }
1039
1040 std::string TypeNameNode::ToString() const
1041 {
1042 return "typename(" + expression->ToString() + ")";
1043 }
1044
1045 TypeIdNode::TypeIdNode(const Span& span_) : Node(NodeType::typeIdNode, span_), expression()
1046 {
1047 }
1048
1049 TypeIdNode::TypeIdNode(const Span& span_, Node* expression_) : Node(NodeType::typeIdNode, span_), expression(expression_)
1050 {
1051 expression->SetParent(this);
1052 }
1053
1054 Node* TypeIdNode::Clone(CloneContext& cloneContext) const
1055 {
1056 return new TypeIdNode(GetSpan(), expression->Clone(cloneContext));
1057 }
1058
1059 void TypeIdNode::Accept(Visitor& visitor)
1060 {
1061 visitor.Visit(*this);
1062 }
1063
1064 void TypeIdNode::Write(AstWriter& writer)
1065 {
1066 Node::Write(writer);
1067 writer.Write(expression.get());
1068 }
1069
1070 void TypeIdNode::Read(AstReader& reader)
1071 {
1072 Node::Read(reader);
1073 expression.reset(reader.ReadNode());
1074 expression->SetParent(this);
1075 }
1076
1077 std::string TypeIdNode::ToString() const
1078 {
1079 return "typeid(" + expression->ToString() + ")";
1080 }
1081
1082 CastNode::CastNode(const Span& span_) : Node(NodeType::castNode, span_), targetTypeExpr(), sourceExpr()
1083 {
1084 }
1085
1086 CastNode::CastNode(const Span& span_, Node* targetTypeExpr_, Node* sourceExpr_) : Node(NodeType::castNode, span_), targetTypeExpr(targetTypeExpr_), sourceExpr(sourceExpr_)
1087 {
1088 targetTypeExpr->SetParent(this);
1089 sourceExpr->SetParent(this);
1090 }
1091
1092 Node* CastNode::Clone(CloneContext& cloneContext) const
1093 {
1094 return new CastNode(GetSpan(), targetTypeExpr->Clone(cloneContext), sourceExpr->Clone(cloneContext));
1095 }
1096
1097 void CastNode::Accept(Visitor& visitor)
1098 {
1099 visitor.Visit(*this);
1100 }
1101
1102 void CastNode::Write(AstWriter& writer)
1103 {
1104 Node::Write(writer);
1105 writer.Write(targetTypeExpr.get());
1106 writer.Write(sourceExpr.get());
1107 }
1108
1109 void CastNode::Read(AstReader& reader)
1110 {
1111 Node::Read(reader);
1112 targetTypeExpr.reset(reader.ReadNode());
1113 targetTypeExpr->SetParent(this);
1114 sourceExpr.reset(reader.ReadNode());
1115 sourceExpr->SetParent(this);
1116 }
1117
1118 std::string CastNode::ToString() const
1119 {
1120 return "cast<" + targetTypeExpr->ToString() + ">(" + sourceExpr->ToString() + ")";
1121 }
1122
1123 ConstructNode::ConstructNode(const Span& span_) : Node(NodeType::constructNode, span_), typeExpr(), arguments()
1124 {
1125 }
1126
1127 ConstructNode::ConstructNode(const Span& span_, Node* typeExpr_) : Node(NodeType::constructNode, span_), typeExpr(typeExpr_), arguments()
1128 {
1129 typeExpr->SetParent(this);
1130 }
1131
1132 Node* ConstructNode::Clone(CloneContext& cloneContext) const
1133 {
1134 ConstructNode* clone = new ConstructNode(GetSpan(), typeExpr->Clone(cloneContext));
1135 int n = arguments.Count();
1136 for (int i = 0; i < n; ++i)
1137 {
1138 Node* argument = arguments[i];
1139 clone->AddArgument(argument->Clone(cloneContext));
1140 }
1141 return clone;
1142 }
1143
1144 void ConstructNode::Accept(Visitor& visitor)
1145 {
1146 visitor.Visit(*this);
1147 }
1148
1149 void ConstructNode::Write(AstWriter& writer)
1150 {
1151 Node::Write(writer);
1152 writer.Write(typeExpr.get());
1153 arguments.Write(writer);
1154 }
1155
1156 void ConstructNode::Read(AstReader& reader)
1157 {
1158 Node::Read(reader);
1159 typeExpr.reset(reader.ReadNode());
1160 typeExpr->SetParent(this);
1161 arguments.Read(reader);
1162 arguments.SetParent(this);
1163 }
1164
1165 void ConstructNode::AddArgument(Node* argument)
1166 {
1167 argument->SetParent(this);
1168 arguments.Add(argument);
1169 }
1170
1171 std::string ConstructNode::ToString() const
1172 {
1173 std::string s = "construct<" + typeExpr->ToString() + ">(";
1174 int n = arguments.Count();
1175 for (int i = 0; i < n; ++i)
1176 {
1177 if (i > 0)
1178 {
1179 s.append(", ");
1180 }
1181 s.append(arguments[i]->ToString());
1182 }
1183 s.append(")");
1184 return s;
1185 }
1186
1187 NewNode::NewNode(const Span& span_) : Node(NodeType::newNode, span_), typeExpr(), arguments()
1188 {
1189 }
1190
1191 NewNode::NewNode(const Span& span_, Node* typeExpr_) : Node(NodeType::newNode, span_), typeExpr(typeExpr_), arguments()
1192 {
1193 typeExpr->SetParent(this);
1194 }
1195
1196 Node* NewNode::Clone(CloneContext& cloneContext) const
1197 {
1198 NewNode* clone = new NewNode(GetSpan(), typeExpr->Clone(cloneContext));
1199 int n = arguments.Count();
1200 for (int i = 0; i < n; ++i)
1201 {
1202 Node* argument = arguments[i];
1203 clone->AddArgument(argument->Clone(cloneContext));
1204 }
1205 return clone;
1206 }
1207
1208 void NewNode::Accept(Visitor& visitor)
1209 {
1210 visitor.Visit(*this);
1211 }
1212
1213 void NewNode::Write(AstWriter& writer)
1214 {
1215 Node::Write(writer);
1216 writer.Write(typeExpr.get());
1217 arguments.Write(writer);
1218 }
1219
1220 void NewNode::Read(AstReader& reader)
1221 {
1222 Node::Read(reader);
1223 typeExpr.reset(reader.ReadNode());
1224 typeExpr->SetParent(this);
1225 arguments.Read(reader);
1226 arguments.SetParent(this);
1227 }
1228
1229 void NewNode::AddArgument(Node* argument)
1230 {
1231 argument->SetParent(this);
1232 arguments.Add(argument);
1233 }
1234
1235 std::string NewNode::ToString() const
1236 {
1237 std::string s = "new ";
1238 s.append(typeExpr->ToString()).append("(");
1239 int n = arguments.Count();
1240 for (int i = 0; i < n; ++i)
1241 {
1242 if (i > 0)
1243 {
1244 s.append(", ");
1245 }
1246 s.append(arguments[i]->ToString());
1247 }
1248 s.append(")");
1249 return s;
1250 }
1251
1252 ThisNode::ThisNode(const Span& span_) : Node(NodeType::thisNode, span_)
1253 {
1254 }
1255
1256 Node* ThisNode::Clone(CloneContext& cloneContext) const
1257 {
1258 return new ThisNode(GetSpan());
1259 }
1260
1261 void ThisNode::Accept(Visitor& visitor)
1262 {
1263 visitor.Visit(*this);
1264 }
1265
1266 std::string ThisNode::ToString() const
1267 {
1268 return "this";
1269 }
1270
1271 BaseNode::BaseNode(const Span& span_) : Node(NodeType::baseNode, span_)
1272 {
1273 }
1274
1275 Node* BaseNode::Clone(CloneContext& cloneContext) const
1276 {
1277 return new BaseNode(GetSpan());
1278 }
1279
1280 void BaseNode::Accept(Visitor& visitor)
1281 {
1282 visitor.Visit(*this);
1283 }
1284
1285 std::string BaseNode::ToString() const
1286 {
1287 return "base";
1288 }
1289
1290 ParenthesizedExpressionNode::ParenthesizedExpressionNode(const Span& span_) : UnaryNode(NodeType::parenthesizedExpressionNode, span_)
1291 {
1292 }
1293
1294 ParenthesizedExpressionNode::ParenthesizedExpressionNode(const Span& span_, Node* child_) : UnaryNode(NodeType::parenthesizedExpressionNode, span_, child_)
1295 {
1296 }
1297
1298 Node* ParenthesizedExpressionNode::Clone(CloneContext& cloneContext) const
1299 {
1300 ParenthesizedExpressionNode* clone = new ParenthesizedExpressionNode(GetSpan(), Subject()->Clone(cloneContext));
1301 return clone;
1302 }
1303
1304 void ParenthesizedExpressionNode::Write(AstWriter& writer)
1305 {
1306 UnaryNode::Write(writer);
1307 }
1308
1309 void ParenthesizedExpressionNode::Read(AstReader& reader)
1310 {
1311 UnaryNode::Read(reader);
1312 }
1313
1314 void ParenthesizedExpressionNode::Accept(Visitor& visitor)
1315 {
1316 visitor.Visit(*this);
1317 }
1318
1319 std::string ParenthesizedExpressionNode::ToString() const
1320 {
1321 return "(" + Subject()->ToString() + ")";
1322 }
1323
1324 } }