1
2
3
4
5
6 #include <sngcm/ast/Literal.hpp>
7 #include <sngcm/ast/Visitor.hpp>
8 #include <sngcm/ast/AstWriter.hpp>
9 #include <sngcm/ast/AstReader.hpp>
10 #include <soulng/util/TextUtils.hpp>
11 #include <soulng/util/Unicode.hpp>
12 #include <boost/uuid/uuid_generators.hpp>
13 #include <limits>
14
15 namespace sngcm { namespace ast {
16
17 using namespace soulng::unicode;
18
19 LiteralNode::LiteralNode(NodeType nodeType_, const Span& span_) : Node(nodeType_, span_)
20 {
21 }
22
23 void LiteralNode::Write(AstWriter& writer)
24 {
25 Node::Write(writer);
26 writer.GetBinaryWriter().Write(text);
27 }
28
29 void LiteralNode::Read(AstReader& reader)
30 {
31 Node::Read(reader);
32 text = reader.GetBinaryReader().ReadUtf32String();
33 }
34
35 void LiteralNode::SetText(const std::u32string& text_)
36 {
37 text = text_;
38 }
39
40 LiteralNode* CreateIntegerLiteralNode(const Span& span, uint64_t value, bool unsignedSuffix)
41 {
42 if (unsignedSuffix)
43 {
44 if (value <= std::numeric_limits<uint8_t>::max()) return new ByteLiteralNode(span, static_cast<uint8_t>(value));
45 if (value <= std::numeric_limits<uint16_t>::max()) return new UShortLiteralNode(span, static_cast<uint16_t>(value));
46 if (value <= std::numeric_limits<uint32_t>::max()) return new UIntLiteralNode(span, static_cast<uint32_t>(value));
47 return new ULongLiteralNode(span, value);
48 }
49 else
50 {
51 if (value <= std::numeric_limits<int8_t>::max()) return new SByteLiteralNode(span, static_cast<int8_t>(value));
52 if (value <= std::numeric_limits<uint8_t>::max()) return new ByteLiteralNode(span, static_cast<uint8_t>(value));
53 if (value <= std::numeric_limits<int16_t>::max()) return new ShortLiteralNode(span, static_cast<int16_t>(value));
54 if (value <= std::numeric_limits<uint16_t>::max()) return new UShortLiteralNode(span, static_cast<uint16_t>(value));
55 if (value <= std::numeric_limits<int32_t>::max()) return new IntLiteralNode(span, static_cast<int32_t>(value));
56 if (value <= std::numeric_limits<uint32_t>::max()) return new UIntLiteralNode(span, static_cast<uint32_t>(value));
57 #pragma warning(disable : 4018)
58 if (value <= std::numeric_limits<int64_t>::max()) return new LongLiteralNode(span, static_cast<int64_t>(value));
59 #pragma warning(default : 4018)
60 return new ULongLiteralNode(span, value);
61 }
62 }
63
64 LiteralNode* CreateFloatingLiteralNode(const Span& span, double value, bool float_)
65 {
66 if (float_)
67 {
68 return new FloatLiteralNode(span, static_cast<float>(value));
69 }
70 else
71 {
72 return new DoubleLiteralNode(span, value);
73 }
74 }
75
76 LiteralNode* CreateCharacterLiteralNode(const Span& span, char32_t value, int chrLitPrefix)
77 {
78 switch (chrLitPrefix)
79 {
80 case 0:
81 {
82 return new CharLiteralNode(span, static_cast<char>(value));
83 }
84 case 1:
85 {
86 return new WCharLiteralNode(span, static_cast<char16_t>(value));
87 }
88 case 2:
89 {
90 return new UCharLiteralNode(span, value);
91 }
92 }
93 return nullptr;
94 }
95
96 LiteralNode* CreateStringLiteralNode(const Span& span, const std::u32string& value, int strLitPrefix)
97 {
98 switch (strLitPrefix)
99 {
100 case 0:
101 {
102 return new StringLiteralNode(span, ToUtf8(value));
103 }
104 case 1:
105 {
106 return new WStringLiteralNode(span, ToUtf16(value));
107 }
108 case 2:
109 {
110 return new UStringLiteralNode(span, value);
111 }
112 }
113 return nullptr;
114 }
115
116 BooleanLiteralNode::BooleanLiteralNode(const Span& span_) : LiteralNode(NodeType::booleanLiteralNode, span_), value(false)
117 {
118 }
119
120 BooleanLiteralNode::BooleanLiteralNode(const Span& span_, bool value_) : LiteralNode(NodeType::booleanLiteralNode, span_), value(value_)
121 {
122 }
123
124 Node* BooleanLiteralNode::Clone(CloneContext& cloneContext) const
125 {
126 return new BooleanLiteralNode(GetSpan(), value);
127 }
128
129 void BooleanLiteralNode::Accept(Visitor& visitor)
130 {
131 visitor.Visit(*this);
132 }
133
134 void BooleanLiteralNode::Write(AstWriter& writer)
135 {
136 LiteralNode::Write(writer);
137 writer.GetBinaryWriter().Write(value);
138 }
139
140 void BooleanLiteralNode::Read(AstReader& reader)
141 {
142 LiteralNode::Read(reader);
143 value = reader.GetBinaryReader().ReadBool();
144 }
145
146 std::string BooleanLiteralNode::ToString() const
147 {
148 if (value) return "true"; else return "false";
149 }
150
151 SByteLiteralNode::SByteLiteralNode(const Span& span_) : LiteralNode(NodeType::sbyteLiteralNode, span_), value(0)
152 {
153 }
154
155 SByteLiteralNode::SByteLiteralNode(const Span& span_, int8_t value_) : LiteralNode(NodeType::sbyteLiteralNode, span_), value(value_)
156 {
157 }
158
159 Node* SByteLiteralNode::Clone(CloneContext& cloneContext) const
160 {
161 return new SByteLiteralNode(GetSpan(), value);
162 }
163
164 void SByteLiteralNode::Accept(Visitor& visitor)
165 {
166 visitor.Visit(*this);
167 }
168
169 void SByteLiteralNode::Write(AstWriter& writer)
170 {
171 LiteralNode::Write(writer);
172 writer.GetBinaryWriter().Write(value);
173 }
174
175 void SByteLiteralNode::Read(AstReader& reader)
176 {
177 LiteralNode::Read(reader);
178 value = reader.GetBinaryReader().ReadSByte();
179 }
180
181 std::string SByteLiteralNode::ToString() const
182 {
183 return std::to_string(value);
184 }
185
186 ByteLiteralNode::ByteLiteralNode(const Span& span_) : LiteralNode(NodeType::byteLiteralNode, span_), value(0u)
187 {
188 }
189
190 ByteLiteralNode::ByteLiteralNode(const Span& span_, uint8_t value_) : LiteralNode(NodeType::byteLiteralNode, span_), value(value_)
191 {
192 }
193
194 Node* ByteLiteralNode::Clone(CloneContext& cloneContext) const
195 {
196 return new ByteLiteralNode(GetSpan(), value);
197 }
198
199 void ByteLiteralNode::Accept(Visitor& visitor)
200 {
201 visitor.Visit(*this);
202 }
203
204 void ByteLiteralNode::Write(AstWriter& writer)
205 {
206 LiteralNode::Write(writer);
207 writer.GetBinaryWriter().Write(value);
208 }
209
210 void ByteLiteralNode::Read(AstReader& reader)
211 {
212 LiteralNode::Read(reader);
213 value = reader.GetBinaryReader().ReadByte();
214 }
215
216 std::string ByteLiteralNode::ToString() const
217 {
218 return std::to_string(value) + "u";
219 }
220
221 ShortLiteralNode::ShortLiteralNode(const Span& span_) : LiteralNode(NodeType::shortLiteralNode, span_), value(0)
222 {
223 }
224
225 ShortLiteralNode::ShortLiteralNode(const Span& span_, int16_t value_) : LiteralNode(NodeType::shortLiteralNode, span_), value(value_)
226 {
227 }
228
229 Node* ShortLiteralNode::Clone(CloneContext& cloneContext) const
230 {
231 return new ShortLiteralNode(GetSpan(), value);
232 }
233
234 void ShortLiteralNode::Accept(Visitor& visitor)
235 {
236 visitor.Visit(*this);
237 }
238
239 void ShortLiteralNode::Write(AstWriter& writer)
240 {
241 LiteralNode::Write(writer);
242 writer.GetBinaryWriter().Write(value);
243 }
244
245 void ShortLiteralNode::Read(AstReader& reader)
246 {
247 LiteralNode::Read(reader);
248 value = reader.GetBinaryReader().ReadShort();
249 }
250
251 std::string ShortLiteralNode::ToString() const
252 {
253 return std::to_string(value);
254 }
255
256 UShortLiteralNode::UShortLiteralNode(const Span& span_) : LiteralNode(NodeType::ushortLiteralNode, span_), value(0u)
257 {
258 }
259
260 UShortLiteralNode::UShortLiteralNode(const Span& span_, uint16_t value_) : LiteralNode(NodeType::ushortLiteralNode, span_), value(value_)
261 {
262 }
263
264 Node* UShortLiteralNode::Clone(CloneContext& cloneContext) const
265 {
266 return new UShortLiteralNode(GetSpan(), value);
267 }
268
269 void UShortLiteralNode::Accept(Visitor& visitor)
270 {
271 visitor.Visit(*this);
272 }
273
274 void UShortLiteralNode::Write(AstWriter& writer)
275 {
276 LiteralNode::Write(writer);
277 writer.GetBinaryWriter().Write(value);
278 }
279
280 void UShortLiteralNode::Read(AstReader& reader)
281 {
282 LiteralNode::Read(reader);
283 value = reader.GetBinaryReader().ReadUShort();
284 }
285
286 std::string UShortLiteralNode::ToString() const
287 {
288 return std::to_string(value) + "u";
289 }
290
291 IntLiteralNode::IntLiteralNode(const Span& span_) : LiteralNode(NodeType::intLiteralNode, span_), value(0)
292 {
293 }
294
295 IntLiteralNode::IntLiteralNode(const Span& span_, int32_t value_) : LiteralNode(NodeType::intLiteralNode, span_), value(value_)
296 {
297 }
298
299 Node* IntLiteralNode::Clone(CloneContext& cloneContext) const
300 {
301 return new IntLiteralNode(GetSpan(), value);
302 }
303
304 void IntLiteralNode::Accept(Visitor& visitor)
305 {
306 visitor.Visit(*this);
307 }
308
309 void IntLiteralNode::Write(AstWriter& writer)
310 {
311 LiteralNode::Write(writer);
312 writer.GetBinaryWriter().Write(value);
313 }
314
315 void IntLiteralNode::Read(AstReader& reader)
316 {
317 LiteralNode::Read(reader);
318 value = reader.GetBinaryReader().ReadInt();
319 }
320
321 std::string IntLiteralNode::ToString() const
322 {
323 return std::to_string(value);
324 }
325
326 UIntLiteralNode::UIntLiteralNode(const Span& span_) : LiteralNode(NodeType::uintLiteralNode, span_), value(0u)
327 {
328 }
329
330 UIntLiteralNode::UIntLiteralNode(const Span& span_, uint32_t value_) : LiteralNode(NodeType::uintLiteralNode, span_), value(value_)
331 {
332 }
333
334 Node* UIntLiteralNode::Clone(CloneContext& cloneContext) const
335 {
336 return new UIntLiteralNode(GetSpan(), value);
337 }
338
339 void UIntLiteralNode::Accept(Visitor& visitor)
340 {
341 visitor.Visit(*this);
342 }
343
344 void UIntLiteralNode::Write(AstWriter& writer)
345 {
346 LiteralNode::Write(writer);
347 writer.GetBinaryWriter().Write(value);
348 }
349
350 void UIntLiteralNode::Read(AstReader& reader)
351 {
352 LiteralNode::Read(reader);
353 value = reader.GetBinaryReader().ReadUInt();
354 }
355
356 std::string UIntLiteralNode::ToString() const
357 {
358 return std::to_string(value) + "u";
359 }
360
361 LongLiteralNode::LongLiteralNode(const Span& span_) : LiteralNode(NodeType::longLiteralNode, span_), value(0)
362 {
363 }
364
365 LongLiteralNode::LongLiteralNode(const Span& span_, int64_t value_) : LiteralNode(NodeType::longLiteralNode, span_), value(value_)
366 {
367 }
368
369 Node* LongLiteralNode::Clone(CloneContext& cloneContext) const
370 {
371 return new LongLiteralNode(GetSpan(), value);
372 }
373
374 void LongLiteralNode::Accept(Visitor& visitor)
375 {
376 visitor.Visit(*this);
377 }
378
379 void LongLiteralNode::Write(AstWriter& writer)
380 {
381 LiteralNode::Write(writer);
382 writer.GetBinaryWriter().Write(value);
383 }
384
385 void LongLiteralNode::Read(AstReader& reader)
386 {
387 LiteralNode::Read(reader);
388 value = reader.GetBinaryReader().ReadLong();
389 }
390
391 std::string LongLiteralNode::ToString() const
392 {
393 return std::to_string(value);
394 }
395
396 ULongLiteralNode::ULongLiteralNode(const Span& span_) : LiteralNode(NodeType::ulongLiteralNode, span_), value(0u)
397 {
398 }
399
400 ULongLiteralNode::ULongLiteralNode(const Span& span_, uint64_t value_) : LiteralNode(NodeType::ulongLiteralNode, span_), value(value_)
401 {
402 }
403
404 Node* ULongLiteralNode::Clone(CloneContext& cloneContext) const
405 {
406 return new ULongLiteralNode(GetSpan(), value);
407 }
408
409 void ULongLiteralNode::Accept(Visitor& visitor)
410 {
411 visitor.Visit(*this);
412 }
413
414 void ULongLiteralNode::Write(AstWriter& writer)
415 {
416 LiteralNode::Write(writer);
417 writer.GetBinaryWriter().Write(value);
418 }
419
420 void ULongLiteralNode::Read(AstReader& reader)
421 {
422 LiteralNode::Read(reader);
423 value = reader.GetBinaryReader().ReadULong();
424 }
425
426 std::string ULongLiteralNode::ToString() const
427 {
428 return std::to_string(value) + "u";
429 }
430
431 FloatLiteralNode::FloatLiteralNode(const Span& span_) : LiteralNode(NodeType::floatLiteralNode, span_), value(0)
432 {
433 }
434
435 FloatLiteralNode::FloatLiteralNode(const Span& span_, float value_) : LiteralNode(NodeType::floatLiteralNode, span_), value(value_)
436 {
437 }
438
439 Node* FloatLiteralNode::Clone(CloneContext& cloneContext) const
440 {
441 return new FloatLiteralNode(GetSpan(), value);
442 }
443
444 void FloatLiteralNode::Accept(Visitor& visitor)
445 {
446 visitor.Visit(*this);
447 }
448
449 void FloatLiteralNode::Write(AstWriter& writer)
450 {
451 LiteralNode::Write(writer);
452 writer.GetBinaryWriter().Write(value);
453 }
454
455 void FloatLiteralNode::Read(AstReader& reader)
456 {
457 LiteralNode::Read(reader);
458 value = reader.GetBinaryReader().ReadFloat();
459 }
460
461 std::string FloatLiteralNode::ToString() const
462 {
463 return std::to_string(value) + "f";
464 }
465
466 DoubleLiteralNode::DoubleLiteralNode(const Span& span_) : LiteralNode(NodeType::doubleLiteralNode, span_), value(0)
467 {
468 }
469
470 DoubleLiteralNode::DoubleLiteralNode(const Span& span_, double value_) : LiteralNode(NodeType::doubleLiteralNode, span_), value(value_)
471 {
472 }
473
474 Node* DoubleLiteralNode::Clone(CloneContext& cloneContext) const
475 {
476 return new DoubleLiteralNode(GetSpan(), value);
477 }
478
479 void DoubleLiteralNode::Accept(Visitor& visitor)
480 {
481 visitor.Visit(*this);
482 }
483
484 void DoubleLiteralNode::Write(AstWriter& writer)
485 {
486 LiteralNode::Write(writer);
487 writer.GetBinaryWriter().Write(value);
488 }
489
490 void DoubleLiteralNode::Read(AstReader& reader)
491 {
492 LiteralNode::Read(reader);
493 value = reader.GetBinaryReader().ReadDouble();
494 }
495
496 std::string DoubleLiteralNode::ToString() const
497 {
498 return std::to_string(value);
499 }
500
501 CharLiteralNode::CharLiteralNode(const Span& span_) : LiteralNode(NodeType::charLiteralNode, span_), value('\0')
502 {
503 }
504
505 CharLiteralNode::CharLiteralNode(const Span& span_, char value_) : LiteralNode(NodeType::charLiteralNode, span_), value(value_)
506 {
507 }
508
509 Node* CharLiteralNode::Clone(CloneContext& cloneContext) const
510 {
511 return new CharLiteralNode(GetSpan(), value);
512 }
513
514 void CharLiteralNode::Accept(Visitor& visitor)
515 {
516 visitor.Visit(*this);
517 }
518
519 void CharLiteralNode::Write(AstWriter& writer)
520 {
521 LiteralNode::Write(writer);
522 writer.GetBinaryWriter().Write(value);
523 }
524
525 void CharLiteralNode::Read(AstReader& reader)
526 {
527 LiteralNode::Read(reader);
528 value = reader.GetBinaryReader().ReadChar();
529 }
530
531 std::string CharLiteralNode::ToString() const
532 {
533 return "'" + CharStr(value) + "'";
534 }
535
536 WCharLiteralNode::WCharLiteralNode(const Span& span_) : LiteralNode(NodeType::wcharLiteralNode, span_), value('\0')
537 {
538 }
539
540 WCharLiteralNode::WCharLiteralNode(const Span& span_, char16_t value_) : LiteralNode(NodeType::wcharLiteralNode, span_), value(value_)
541 {
542 }
543
544 Node* WCharLiteralNode::Clone(CloneContext& cloneContext) const
545 {
546 return new WCharLiteralNode(GetSpan(), value);
547 }
548
549 void WCharLiteralNode::Accept(Visitor& visitor)
550 {
551 visitor.Visit(*this);
552 }
553
554 void WCharLiteralNode::Write(AstWriter& writer)
555 {
556 LiteralNode::Write(writer);
557 writer.GetBinaryWriter().Write(value);
558 }
559
560 void WCharLiteralNode::Read(AstReader& reader)
561 {
562 LiteralNode::Read(reader);
563 value = reader.GetBinaryReader().ReadWChar();
564 }
565
566 std::string WCharLiteralNode::ToString() const
567 {
568 return "w'" + ToUtf8(CharStr(char32_t(value))) + "'";
569 }
570
571 UCharLiteralNode::UCharLiteralNode(const Span& span_) : LiteralNode(NodeType::ucharLiteralNode, span_), value('\0')
572 {
573 }
574
575 UCharLiteralNode::UCharLiteralNode(const Span& span_, char32_t value_) : LiteralNode(NodeType::ucharLiteralNode, span_), value(value_)
576 {
577 }
578
579 Node* UCharLiteralNode::Clone(CloneContext& cloneContext) const
580 {
581 return new UCharLiteralNode(GetSpan(), value);
582 }
583
584 void UCharLiteralNode::Accept(Visitor& visitor)
585 {
586 visitor.Visit(*this);
587 }
588
589 void UCharLiteralNode::Write(AstWriter& writer)
590 {
591 LiteralNode::Write(writer);
592 writer.GetBinaryWriter().Write(value);
593 }
594
595 void UCharLiteralNode::Read(AstReader& reader)
596 {
597 LiteralNode::Read(reader);
598 value = reader.GetBinaryReader().ReadUChar();
599 }
600
601 std::string UCharLiteralNode::ToString() const
602 {
603 return "u'" + ToUtf8(CharStr(value)) + "'";
604 }
605
606 StringLiteralNode::StringLiteralNode(const Span& span_) : LiteralNode(NodeType::stringLiteralNode, span_), value()
607 {
608 }
609
610 StringLiteralNode::StringLiteralNode(const Span& span_, const std::string& value_) : LiteralNode(NodeType::stringLiteralNode, span_), value(value_)
611 {
612 }
613
614 Node* StringLiteralNode::Clone(CloneContext& cloneContext) const
615 {
616 return new StringLiteralNode(GetSpan(), value);
617 }
618
619 void StringLiteralNode::Accept(Visitor& visitor)
620 {
621 visitor.Visit(*this);
622 }
623
624 void StringLiteralNode::Write(AstWriter& writer)
625 {
626 LiteralNode::Write(writer);
627 writer.GetBinaryWriter().Write(value);
628 }
629
630 void StringLiteralNode::Read(AstReader& reader)
631 {
632 LiteralNode::Read(reader);
633 value = reader.GetBinaryReader().ReadUtf8String();
634 }
635
636 std::string StringLiteralNode::ToString() const
637 {
638 return "\"" + StringStr(value) + "\"";
639 }
640
641 WStringLiteralNode::WStringLiteralNode(const Span& span_) : LiteralNode(NodeType::wstringLiteralNode, span_), value()
642 {
643 }
644
645 WStringLiteralNode::WStringLiteralNode(const Span& span_, const std::u16string& value_) : LiteralNode(NodeType::wstringLiteralNode, span_), value(value_)
646 {
647 }
648
649 Node* WStringLiteralNode::Clone(CloneContext& cloneContext) const
650 {
651 return new WStringLiteralNode(GetSpan(), value);
652 }
653
654 void WStringLiteralNode::Accept(Visitor& visitor)
655 {
656 visitor.Visit(*this);
657 }
658
659 void WStringLiteralNode::Write(AstWriter& writer)
660 {
661 LiteralNode::Write(writer);
662 writer.GetBinaryWriter().Write(value);
663 }
664
665 void WStringLiteralNode::Read(AstReader& reader)
666 {
667 LiteralNode::Read(reader);
668 value = reader.GetBinaryReader().ReadUtf16String();
669 }
670
671 std::string WStringLiteralNode::ToString() const
672 {
673 return "\"" + StringStr(ToUtf8(value)) + "\"";
674 }
675
676 UStringLiteralNode::UStringLiteralNode(const Span& span_) : LiteralNode(NodeType::ustringLiteralNode, span_), value()
677 {
678 }
679
680 UStringLiteralNode::UStringLiteralNode(const Span& span_, const std::u32string& value_) : LiteralNode(NodeType::ustringLiteralNode, span_), value(value_)
681 {
682 }
683
684 Node* UStringLiteralNode::Clone(CloneContext& cloneContext) const
685 {
686 return new UStringLiteralNode(GetSpan(), value);
687 }
688
689 void UStringLiteralNode::Accept(Visitor& visitor)
690 {
691 visitor.Visit(*this);
692 }
693
694 void UStringLiteralNode::Write(AstWriter& writer)
695 {
696 LiteralNode::Write(writer);
697 writer.GetBinaryWriter().Write(value);
698 }
699
700 void UStringLiteralNode::Read(AstReader& reader)
701 {
702 LiteralNode::Read(reader);
703 value = reader.GetBinaryReader().ReadUtf32String();
704 }
705
706 std::string UStringLiteralNode::ToString() const
707 {
708 return "\"" + StringStr(ToUtf8(value)) + "\"";
709 }
710
711 NullLiteralNode::NullLiteralNode(const Span& span_) : LiteralNode(NodeType::nullLiteralNode, span_)
712 {
713 }
714
715 Node* NullLiteralNode::Clone(CloneContext& cloneContext) const
716 {
717 return new NullLiteralNode(GetSpan());
718 }
719
720 void NullLiteralNode::Accept(Visitor& visitor)
721 {
722 visitor.Visit(*this);
723 }
724
725 ArrayLiteralNode::ArrayLiteralNode(const Span& span_) : LiteralNode(NodeType::arrayLiteralNode, span_)
726 {
727 }
728
729 Node* ArrayLiteralNode::Clone(CloneContext& cloneContext) const
730 {
731 ArrayLiteralNode* clone = new ArrayLiteralNode(GetSpan());
732 int n = values.Count();
733 for (int i = 0; i < n; ++i)
734 {
735 clone->AddValue(values[i]->Clone(cloneContext));
736 }
737 return clone;
738 }
739
740 void ArrayLiteralNode::Accept(Visitor& visitor)
741 {
742 visitor.Visit(*this);
743 }
744
745 void ArrayLiteralNode::Write(AstWriter& writer)
746 {
747 LiteralNode::Write(writer);
748 values.Write(writer);
749 }
750
751 void ArrayLiteralNode::Read(AstReader& reader)
752 {
753 LiteralNode::Read(reader);
754 values.Read(reader);
755 }
756
757 void ArrayLiteralNode::AddValue(Node* value)
758 {
759 value->SetParent(this);
760 values.Add(value);
761 }
762
763 StructuredLiteralNode::StructuredLiteralNode(const Span& span_) : LiteralNode(NodeType::structuredLiteralNode, span_)
764 {
765 }
766
767 Node* StructuredLiteralNode::Clone(CloneContext& cloneContext) const
768 {
769 StructuredLiteralNode* clone = new StructuredLiteralNode(GetSpan());
770 int n = members.Count();
771 for (int i = 0; i < n; ++i)
772 {
773 clone->AddMember(members[i]->Clone(cloneContext));
774 }
775 return clone;
776 }
777
778 void StructuredLiteralNode::Accept(Visitor& visitor)
779 {
780 visitor.Visit(*this);
781 }
782
783 void StructuredLiteralNode::Write(AstWriter& writer)
784 {
785 LiteralNode::Write(writer);
786 members.Write(writer);
787 }
788
789 void StructuredLiteralNode::Read(AstReader& reader)
790 {
791 LiteralNode::Read(reader);
792 members.Read(reader);
793 }
794
795 void StructuredLiteralNode::AddMember(Node* member)
796 {
797 member->SetParent(this);
798 members.Add(member);
799 }
800
801 UuidLiteralNode::UuidLiteralNode(const Span& span_) : LiteralNode(NodeType::uuidLiteralNode, span_), uuid(boost::uuids::nil_generator()())
802 {
803 }
804
805 UuidLiteralNode::UuidLiteralNode(const Span& span_, const boost::uuids::uuid& uuid_): LiteralNode(NodeType::uuidLiteralNode, span_), uuid(uuid_)
806 {
807 }
808
809 Node* UuidLiteralNode::Clone(CloneContext& cloneContext) const
810 {
811 return new UuidLiteralNode(GetSpan(), uuid);
812 }
813
814 void UuidLiteralNode::Accept(Visitor& visitor)
815 {
816 visitor.Visit(*this);
817 }
818
819 void UuidLiteralNode::Write(AstWriter& writer)
820 {
821 LiteralNode::Write(writer);
822 writer.GetBinaryWriter().Write(uuid);
823 }
824
825 void UuidLiteralNode::Read(AstReader& reader)
826 {
827 LiteralNode::Read(reader);
828 reader.GetBinaryReader().ReadUuid(uuid);
829 }
830
831 } }