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