1
2
3
4
5
6 #include <sngcpp/ast/Expression.hpp>
7 #include <sngcpp/ast/Visitor.hpp>
8 #include <sngcpp/ast/Writer.hpp>
9 #include <sngcpp/ast/Reader.hpp>
10
11 namespace sngcpp { namespace ast {
12
13 std::u32string OpStr(Operator op)
14 {
15 switch (op)
16 {
17 case Operator::assign: return U" = ";
18 case Operator::mulAssign: return U" *= ";
19 case Operator::divAssign: return U" /= ";
20 case Operator::remAssign: return U" %= ";
21 case Operator::addAssign: return U" += ";
22 case Operator::subAssign: return U" -= ";
23 case Operator::shiftRightAssign: return U" >>= ";
24 case Operator::shiftLeftAssign: return U" <<= ";
25 case Operator::andAssign: return U" &= ";
26 case Operator::xorAssign: return U" ^= ";
27 case Operator::orAssign: return U" |= ";
28 case Operator::equal: return U" == ";
29 case Operator::notEqual: return U" != ";
30 case Operator::lessOrEqual: return U" <= ";
31 case Operator::greaterOrEqual: return U" >= ";
32 case Operator::less: return U" < ";
33 case Operator::greater: return U" > ";
34 case Operator::shiftLeft: return U" << ";
35 case Operator::shiftRight: return U" >> ";
36 case Operator::add: return U" + ";
37 case Operator::sub: return U" - ";
38 case Operator::mul: return U" * ";
39 case Operator::div: return U" / ";
40 case Operator::rem: return U" % ";
41 case Operator::dotStar: return U".*";
42 case Operator::arrowStar: return U"->*";
43 case Operator::arrow: return U"->";
44 case Operator::inc: return U"++";
45 case Operator::dec: return U"--";
46 case Operator::deref: return U"*";
47 case Operator::addrOf: return U"&";
48 case Operator::unaryPlus: return U"+";
49 case Operator::unaryMinus: return U"-";
50 case Operator::not_: return U"!";
51 case Operator::complement: return U"~";
52 case Operator::sizeOf: return U"sizeof";
53 case Operator::alignOf: return U"alignof";
54 case Operator::dynamicCast: return U"dynamic_cast";
55 case Operator::staticCast: return U"static_cast";
56 case Operator::reinterpretCast: return U"reinterpret_cast";
57 case Operator::constCast: return U"const_cast";
58 case Operator::logicalAnd: return U" && ";
59 case Operator::logicalOr: return U" || ";
60 case Operator::xor_: return U" ^ ";
61 case Operator::and_: return U" & ";
62 case Operator::or_: return U" | ";
63 case Operator::apply: return U"()";
64 case Operator::subscript: return U"[]";
65 case Operator::comma: return U", ";
66 case Operator::newArray: return U"new []";
67 case Operator::deleteArray: return U"delete []";
68 case Operator::new_: return U"new";
69 case Operator::delete_: return U"delete";
70 }
71 return std::u32string();
72 }
73
74 ExpressionSequenceNode::ExpressionSequenceNode() : BinaryNode(NodeType::expressionSequenceNode)
75 {
76 }
77
78 ExpressionSequenceNode::ExpressionSequenceNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::expressionSequenceNode, span_, left_, right_)
79 {
80 }
81
82 void ExpressionSequenceNode::Accept(Visitor& visitor)
83 {
84 visitor.Visit(*this);
85 }
86
87 CommaExpressionNode::CommaExpressionNode() : BinaryNode(NodeType::commaExpressionNode)
88 {
89 }
90
91 CommaExpressionNode::CommaExpressionNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::commaExpressionNode, span_, left_, right_)
92 {
93 }
94
95 void CommaExpressionNode::Accept(Visitor& visitor)
96 {
97 visitor.Visit(*this);
98 }
99
100 AssignmentExpressionNode::AssignmentExpressionNode() : BinaryNode(NodeType::assignmentExpressionNode)
101 {
102 }
103
104 AssignmentExpressionNode::AssignmentExpressionNode(const Span& span_, Node* left_, Operator op_, Node* right_) : BinaryNode(NodeType::assignmentExpressionNode, span_, left_, right_), op(op_)
105 {
106 }
107
108 void AssignmentExpressionNode::Accept(Visitor& visitor)
109 {
110 visitor.Visit(*this);
111 }
112
113 void AssignmentExpressionNode::Write(Writer& writer)
114 {
115 BinaryNode::Write(writer);
116 writer.Write(op);
117 }
118
119 void AssignmentExpressionNode::Read(Reader& reader)
120 {
121 BinaryNode::Read(reader);
122 op = reader.ReadOperator();
123 }
124
125 ConditionalExpressionNode::ConditionalExpressionNode() : Node(NodeType::conditionalExpressionNode)
126 {
127 }
128
129 ConditionalExpressionNode::ConditionalExpressionNode(const Span& span_, Node* condition_, Node* thenExpr_, Node* elseExpr_) :
130 Node(NodeType::conditionalExpressionNode, span_), condition(condition_), thenExpr(thenExpr_), elseExpr(elseExpr_)
131 {
132 }
133
134 void ConditionalExpressionNode::Accept(Visitor& visitor)
135 {
136 visitor.Visit(*this);
137 }
138
139 void ConditionalExpressionNode::Write(Writer& writer)
140 {
141 Node::Write(writer);
142 condition->Write(writer);
143 thenExpr->Write(writer);
144 elseExpr->Write(writer);
145 }
146
147 void ConditionalExpressionNode::Read(Reader& reader)
148 {
149 Node::Read(reader);
150 condition.reset(reader.ReadNode());
151 thenExpr.reset(reader.ReadNode());
152 elseExpr.reset(reader.ReadNode());
153 }
154
155 ThrowExpressionNode::ThrowExpressionNode() : UnaryNode(NodeType::throwExpressionNode)
156 {
157 }
158
159 ThrowExpressionNode::ThrowExpressionNode(const Span& span_, Node* exceptionExpr_) : UnaryNode(NodeType::throwExpressionNode, span_, exceptionExpr_)
160 {
161 }
162
163 void ThrowExpressionNode::Accept(Visitor& visitor)
164 {
165 visitor.Visit(*this);
166 }
167
168 LogicalOrExpressionNode::LogicalOrExpressionNode() : BinaryNode(NodeType::logicalOrExpressionNode)
169 {
170 }
171
172 LogicalOrExpressionNode::LogicalOrExpressionNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::logicalOrExpressionNode, span_, left_, right_)
173 {
174 }
175
176 void LogicalOrExpressionNode::Accept(Visitor& visitor)
177 {
178 visitor.Visit(*this);
179 }
180
181 LogicalAndExpressionNode::LogicalAndExpressionNode() : BinaryNode(NodeType::logicalAndExpressionNode)
182 {
183 }
184
185 LogicalAndExpressionNode::LogicalAndExpressionNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::logicalAndExpressionNode, span_, left_, right_)
186 {
187 }
188
189 void LogicalAndExpressionNode::Accept(Visitor& visitor)
190 {
191 visitor.Visit(*this);
192 }
193
194 InclusiveOrExpressionNode::InclusiveOrExpressionNode() : BinaryNode(NodeType::inclusiveOrExpressionNode)
195 {
196 }
197
198 InclusiveOrExpressionNode::InclusiveOrExpressionNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::inclusiveOrExpressionNode, span_, left_, right_)
199 {
200 }
201
202 void InclusiveOrExpressionNode::Accept(Visitor& visitor)
203 {
204 visitor.Visit(*this);
205 }
206
207 ExclusiveOrExpressionNode::ExclusiveOrExpressionNode() : BinaryNode(NodeType::exclusiveOrExpressionNode)
208 {
209 }
210
211 ExclusiveOrExpressionNode::ExclusiveOrExpressionNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::exclusiveOrExpressionNode, span_, left_, right_)
212 {
213 }
214
215 void ExclusiveOrExpressionNode::Accept(Visitor& visitor)
216 {
217 visitor.Visit(*this);
218 }
219
220 AndExpressionNode::AndExpressionNode() : BinaryNode(NodeType::andExpressionNode)
221 {
222 }
223
224 AndExpressionNode::AndExpressionNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::andExpressionNode, span_, left_, right_)
225 {
226 }
227
228 void AndExpressionNode::Accept(Visitor& visitor)
229 {
230 visitor.Visit(*this);
231 }
232
233 EqualityExpressionNode::EqualityExpressionNode() : BinaryNode(NodeType::equalityExpressionNode), op()
234 {
235 }
236
237 EqualityExpressionNode::EqualityExpressionNode(const Span& span_, Node* left_, Node* right_, Operator op_) : BinaryNode(NodeType::equalityExpressionNode, span_, left_, right_), op(op_)
238 {
239 }
240
241 void EqualityExpressionNode::Accept(Visitor& visitor)
242 {
243 visitor.Visit(*this);
244 }
245
246 void EqualityExpressionNode::Write(Writer& writer)
247 {
248 BinaryNode::Write(writer);
249 writer.Write(op);
250 }
251
252 void EqualityExpressionNode::Read(Reader& reader)
253 {
254 BinaryNode::Read(reader);
255 op = reader.ReadOperator();
256 }
257
258 RelationalExpressionNode::RelationalExpressionNode() : BinaryNode(NodeType::relationalExpressionNode), op()
259 {
260 }
261
262 RelationalExpressionNode::RelationalExpressionNode(const Span& span_, Node* left_, Node* right_, Operator op_) : BinaryNode(NodeType::relationalExpressionNode, span_, left_, right_), op(op_)
263 {
264 }
265
266 void RelationalExpressionNode::Accept(Visitor& visitor)
267 {
268 visitor.Visit(*this);
269 }
270
271 void RelationalExpressionNode::Write(Writer& writer)
272 {
273 BinaryNode::Write(writer);
274 writer.Write(op);
275 }
276
277 void RelationalExpressionNode::Read(Reader& reader)
278 {
279 BinaryNode::Read(reader);
280 op = reader.ReadOperator();
281 }
282
283 ShiftExpressionNode::ShiftExpressionNode() : BinaryNode(NodeType::shiftExpressionNode), op()
284 {
285 }
286
287 ShiftExpressionNode::ShiftExpressionNode(const Span& span_, Node* left_, Node* right_, Operator op_) : BinaryNode(NodeType::shiftExpressionNode, span_, left_, right_), op(op_)
288 {
289 }
290
291 void ShiftExpressionNode::Accept(Visitor& visitor)
292 {
293 visitor.Visit(*this);
294 }
295
296 void ShiftExpressionNode::Write(Writer& writer)
297 {
298 BinaryNode::Write(writer);
299 writer.Write(op);
300 }
301
302 void ShiftExpressionNode::Read(Reader& reader)
303 {
304 BinaryNode::Read(reader);
305 op = reader.ReadOperator();
306 }
307
308 AdditiveExpressionNode::AdditiveExpressionNode() : BinaryNode(NodeType::additiveExpressionNode), op()
309 {
310 }
311
312 AdditiveExpressionNode::AdditiveExpressionNode(const Span& span_, Node* left_, Node* right_, Operator op_) : BinaryNode(NodeType::additiveExpressionNode, span_, left_, right_), op(op_)
313 {
314 }
315
316 void AdditiveExpressionNode::Accept(Visitor& visitor)
317 {
318 visitor.Visit(*this);
319 }
320
321 void AdditiveExpressionNode::Write(Writer& writer)
322 {
323 BinaryNode::Write(writer);
324 writer.Write(op);
325 }
326
327 void AdditiveExpressionNode::Read(Reader& reader)
328 {
329 BinaryNode::Read(reader);
330 op = reader.ReadOperator();
331 }
332
333 MultiplicativeExpressionNode::MultiplicativeExpressionNode() : BinaryNode(NodeType::multiplicativeExpressionNode), op()
334 {
335 }
336
337 MultiplicativeExpressionNode::MultiplicativeExpressionNode(const Span& span_, Node* left_, Node* right_, Operator op_) : BinaryNode(NodeType::multiplicativeExpressionNode, span_, left_, right_), op(op_)
338 {
339 }
340
341 void MultiplicativeExpressionNode::Accept(Visitor& visitor)
342 {
343 visitor.Visit(*this);
344 }
345
346 void MultiplicativeExpressionNode::Write(Writer& writer)
347 {
348 BinaryNode::Write(writer);
349 writer.Write(op);
350 }
351
352 void MultiplicativeExpressionNode::Read(Reader& reader)
353 {
354 BinaryNode::Read(reader);
355 op = reader.ReadOperator();
356 }
357
358 PMExpressionNode::PMExpressionNode() : BinaryNode(NodeType::pmExpressionNode), op()
359 {
360 }
361
362 PMExpressionNode::PMExpressionNode(const Span& span_, Node* left_, Node* right_, Operator op_) : BinaryNode(NodeType::pmExpressionNode, span_, left_, right_), op(op_)
363 {
364 }
365
366 void PMExpressionNode::Accept(Visitor& visitor)
367 {
368 visitor.Visit(*this);
369 }
370
371 void PMExpressionNode::Write(Writer& writer)
372 {
373 BinaryNode::Write(writer);
374 writer.Write(op);
375 }
376
377 void PMExpressionNode::Read(Reader& reader)
378 {
379 BinaryNode::Read(reader);
380 op = reader.ReadOperator();
381 }
382
383 CastExpressionNode::CastExpressionNode() : Node(NodeType::castExpressionNode)
384 {
385 }
386
387 CastExpressionNode::CastExpressionNode(const Span& span_, Node* typeExpr_, Node* expr_) : Node(NodeType::castExpressionNode, span_), typeExpr(typeExpr_), expr(expr_)
388 {
389 }
390
391 void CastExpressionNode::Accept(Visitor& visitor)
392 {
393 visitor.Visit(*this);
394 }
395
396 void CastExpressionNode::Write(Writer& writer)
397 {
398 Node::Write(writer);
399 typeExpr->Write(writer);
400 expr->Write(writer);
401 }
402
403 void CastExpressionNode::Read(Reader& reader)
404 {
405 Node::Read(reader);
406 typeExpr.reset(reader.ReadNode());
407 expr.reset(reader.ReadNode());
408 }
409
410 UnaryExpressionNode::UnaryExpressionNode() : UnaryNode(NodeType::unaryExpressionNode), op()
411 {
412 }
413
414 UnaryExpressionNode::UnaryExpressionNode(const Span& span_, Operator op_, Node* expr_) : UnaryNode(NodeType::unaryExpressionNode, span_, expr_), op(op_)
415 {
416 }
417
418 void UnaryExpressionNode::Accept(Visitor& visitor)
419 {
420 visitor.Visit(*this);
421 }
422
423 void UnaryExpressionNode::Write(Writer& writer)
424 {
425 UnaryNode::Write(writer);
426 writer.Write(op);
427 }
428
429 void UnaryExpressionNode::Read(Reader& reader)
430 {
431 UnaryNode::Read(reader);
432 op = reader.ReadOperator();
433 }
434
435 NewExpressionNode::NewExpressionNode() : Node(NodeType::newExpressionNode)
436 {
437 }
438
439 NewExpressionNode::NewExpressionNode(const Span& span_, Node* placement_, Node* typeExpr_, Node* initializer_) :
440 Node(NodeType::newExpressionNode, span_), placement(placement_), typeExpr(typeExpr_), initializer(initializer_)
441 {
442 }
443
444 void NewExpressionNode::Accept(Visitor& visitor)
445 {
446 visitor.Visit(*this);
447 }
448
449 void NewExpressionNode::Write(Writer& writer)
450 {
451 Node::Write(writer);
452 writer.GetBinaryWriter().Write(placement != nullptr);
453 if (placement)
454 {
455 placement->Write(writer);
456 }
457 typeExpr->Write(writer);
458 writer.GetBinaryWriter().Write(initializer != nullptr);
459 if (initializer)
460 {
461 initializer->Write(writer);
462 }
463 }
464
465 void NewExpressionNode::Read(Reader& reader)
466 {
467 Node::Read(reader);
468 bool hasPlacement = reader.GetBinaryReader().ReadBool();
469 if (hasPlacement)
470 {
471 placement.reset(reader.ReadNode());
472 }
473 typeExpr.reset(reader.ReadNode());
474 bool hasInitializer = reader.GetBinaryReader().ReadBool();
475 if (hasInitializer)
476 {
477 initializer.reset(reader.ReadNode());
478 }
479 }
480
481 DeleteExpressionNode::DeleteExpressionNode() : UnaryNode(NodeType::deleteExpressionNode), array_()
482 {
483 }
484
485 DeleteExpressionNode::DeleteExpressionNode(const Span& span_, bool array__, Node* ptr_) : UnaryNode(NodeType::deleteExpressionNode, span_, ptr_), array_(array__)
486 {
487 }
488
489 void DeleteExpressionNode::Accept(Visitor& visitor)
490 {
491 visitor.Visit(*this);
492 }
493
494 void DeleteExpressionNode::Write(Writer& writer)
495 {
496 UnaryNode::Write(writer);
497 writer.GetBinaryWriter().Write(array_);
498 }
499
500 void DeleteExpressionNode::Read(Reader& reader)
501 {
502 UnaryNode::Read(reader);
503 array_ = reader.GetBinaryReader().ReadBool();
504 }
505
506 SubscriptExpressionNode::SubscriptExpressionNode() : UnaryNode(NodeType::subscriptExpressionNode)
507 {
508 }
509
510 SubscriptExpressionNode::SubscriptExpressionNode(const Span& span_, Node* subject_, Node* index_) : UnaryNode(NodeType::subscriptExpressionNode, span_, subject_), index(index_)
511 {
512 }
513
514 void SubscriptExpressionNode::Accept(Visitor& visitor)
515 {
516 visitor.Visit(*this);
517 }
518
519 void SubscriptExpressionNode::Write(Writer& writer)
520 {
521 UnaryNode::Write(writer);
522 index->Write(writer);
523 }
524
525 void SubscriptExpressionNode::Read(Reader& reader)
526 {
527 UnaryNode::Read(reader);
528 index.reset(reader.ReadNode());
529 }
530
531 InvokeExpressionNode::InvokeExpressionNode() : UnaryNode(NodeType::invokeExpressionNode)
532 {
533 }
534
535 InvokeExpressionNode::InvokeExpressionNode(const Span& span_, Node* subject_, Node* arguments_) : UnaryNode(NodeType::invokeExpressionNode, span_, subject_), arguments(arguments_)
536 {
537 }
538
539 void InvokeExpressionNode::Accept(Visitor& visitor)
540 {
541 visitor.Visit(*this);
542 }
543
544 void InvokeExpressionNode::Write(Writer& writer)
545 {
546 UnaryNode::Write(writer);
547 writer.GetBinaryWriter().Write(arguments != nullptr);
548 if (arguments)
549 {
550 arguments->Write(writer);
551 }
552 }
553
554 void InvokeExpressionNode::Read(Reader& reader)
555 {
556 UnaryNode::Read(reader);
557 bool hasArguments = reader.GetBinaryReader().ReadBool();
558 if (hasArguments)
559 {
560 arguments.reset(reader.ReadNode());
561 }
562 }
563
564 DotNode::DotNode() : UnaryNode(NodeType::dotNode)
565 {
566 }
567
568 DotNode::DotNode(const Span& span_, Node* subject_, Node* id_) : UnaryNode(NodeType::dotNode, span_, subject_), id(id_)
569 {
570 }
571
572 void DotNode::Accept(Visitor& visitor)
573 {
574 visitor.Visit(*this);
575 }
576
577 void DotNode::Write(Writer& writer)
578 {
579 UnaryNode::Write(writer);
580 id->Write(writer);
581 }
582
583 void DotNode::Read(Reader& reader)
584 {
585 UnaryNode::Read(reader);
586 id.reset(reader.ReadNode());
587 }
588
589 ArrowNode::ArrowNode() : UnaryNode(NodeType::arrowNode)
590 {
591 }
592
593 ArrowNode::ArrowNode(const Span& span_, Node* subject_, Node* id_) : UnaryNode(NodeType::arrowNode, span_, subject_), id(id_)
594 {
595 }
596
597 void ArrowNode::Accept(Visitor& visitor)
598 {
599 visitor.Visit(*this);
600 }
601
602 void ArrowNode::Write(Writer& writer)
603 {
604 UnaryNode::Write(writer);
605 id->Write(writer);
606 }
607
608 void ArrowNode::Read(Reader& reader)
609 {
610 UnaryNode::Read(reader);
611 id.reset(reader.ReadNode());
612 }
613
614 PostfixIncNode::PostfixIncNode() : UnaryNode(NodeType::postfixIncNode)
615 {
616 }
617
618 PostfixIncNode::PostfixIncNode(const Span& span_, Node* subject_) : UnaryNode(NodeType::postfixIncNode, span_, subject_)
619 {
620 }
621
622 void PostfixIncNode::Accept(Visitor& visitor)
623 {
624 visitor.Visit(*this);
625 }
626
627 PostfixDecNode::PostfixDecNode() : UnaryNode(NodeType::postfixDecNode)
628 {
629 }
630
631 PostfixDecNode::PostfixDecNode(const Span& span_, Node* subject_) : UnaryNode(NodeType::postfixDecNode, span_, subject_)
632 {
633 }
634
635 void PostfixDecNode::Accept(Visitor& visitor)
636 {
637 visitor.Visit(*this);
638 }
639
640 CppCastExpressionNode::CppCastExpressionNode() : Node(NodeType::cppCastExpressionNode), op()
641 {
642 }
643
644 CppCastExpressionNode::CppCastExpressionNode(const Span& span_, Node* typeExpr_, Node* expr_, Operator op_) : Node(NodeType::cppCastExpressionNode, span_), typeExpr(typeExpr_), expr(expr_), op(op_)
645 {
646 }
647
648 void CppCastExpressionNode::Accept(Visitor& visitor)
649 {
650 visitor.Visit(*this);
651 }
652
653 void CppCastExpressionNode::Write(Writer& writer)
654 {
655 Node::Write(writer);
656 typeExpr->Write(writer);
657 expr->Write(writer);
658 writer.Write(op);
659 }
660
661 void CppCastExpressionNode::Read(Reader& reader)
662 {
663 Node::Read(reader);
664 typeExpr.reset(reader.ReadNode());
665 expr.reset(reader.ReadNode());
666 op = reader.ReadOperator();
667 }
668
669 TypeIdExpressionNode::TypeIdExpressionNode() : UnaryNode(NodeType::typeIdExpressionNode)
670 {
671 }
672
673 TypeIdExpressionNode::TypeIdExpressionNode(const Span& span_, Node* subject_) : UnaryNode(NodeType::typeIdExpressionNode, span_, subject_)
674 {
675 }
676
677 void TypeIdExpressionNode::Accept(Visitor& visitor)
678 {
679 visitor.Visit(*this);
680 }
681
682 ThisNode::ThisNode() : Node(NodeType::thisNode)
683 {
684 }
685
686 ThisNode::ThisNode(const Span& span_) : Node(NodeType::thisNode, span_)
687 {
688 }
689
690 void ThisNode::Accept(Visitor& visitor)
691 {
692 visitor.Visit(*this);
693 }
694
695 IdentifierNode::IdentifierNode() : Node(NodeType::identifierNode)
696 {
697 }
698
699 IdentifierNode::IdentifierNode(NodeType nodeType_) : Node(nodeType_)
700 {
701 }
702
703 IdentifierNode::IdentifierNode(const Span& span_, const std::u32string& identifier_) : Node(NodeType::identifierNode, span_), identifier(identifier_)
704 {
705 }
706
707 IdentifierNode::IdentifierNode(NodeType nodeType_, const Span& span_, const std::u32string& identifier_) : Node(nodeType_, span_), identifier(identifier_)
708 {
709 }
710
711 void IdentifierNode::Accept(Visitor& visitor)
712 {
713 visitor.Visit(*this);
714 }
715
716 void IdentifierNode::Write(Writer& writer)
717 {
718 Node::Write(writer);
719 writer.GetBinaryWriter().Write(identifier);
720 }
721
722 void IdentifierNode::Read(Reader& reader)
723 {
724 Node::Read(reader);
725 identifier = reader.GetBinaryReader().ReadUtf32String();
726 }
727
728 OperatorFunctionIdNode::OperatorFunctionIdNode() : IdentifierNode(NodeType::operatorFunctionIdNode), op()
729 {
730 }
731
732 OperatorFunctionIdNode::OperatorFunctionIdNode(const Span& span_, Operator op_) : IdentifierNode(NodeType::operatorFunctionIdNode, span_, U"operator"), op(op_)
733 {
734 }
735
736 void OperatorFunctionIdNode::Accept(Visitor& visitor)
737 {
738 visitor.Visit(*this);
739 }
740
741 void OperatorFunctionIdNode::Write(Writer& writer)
742 {
743 IdentifierNode::Write(writer);
744 writer.Write(op);
745 }
746
747 void OperatorFunctionIdNode::Read(Reader& reader)
748 {
749 IdentifierNode::Read(reader);
750 op = reader.ReadOperator();
751 }
752
753 std::u32string OperatorFunctionIdNode::OpStr() const
754 {
755 switch (op)
756 {
757 case Operator::newArray: return U" new[]";
758 case Operator::deleteArray: return U" delete[]";
759 case Operator::new_: return U" new";
760 case Operator::delete_: return U" delete";
761 case Operator::assign: return U"=";
762 case Operator::mulAssign: return U"*=";
763 case Operator::divAssign: return U"/=";
764 case Operator::remAssign: return U"%=";
765 case Operator::addAssign: return U"+=";
766 case Operator::subAssign: return U"-=";
767 case Operator::shiftLeftAssign: return U"<<=";
768 case Operator::shiftRightAssign: return U">>=";
769 case Operator::andAssign: return U"&=";
770 case Operator::xorAssign: return U"^=";
771 case Operator::orAssign: return U"|=";
772 case Operator::inc: return U"++";
773 case Operator::dec: return U"--";
774 case Operator::shiftLeft: return U"<<";
775 case Operator::shiftRight: return U">>";
776 case Operator::logicalAnd: return U"&&";
777 case Operator::logicalOr: return U"||";
778 case Operator::equal: return U"==";
779 case Operator::notEqual: return U"!=";
780 case Operator::lessOrEqual: return U"<=";
781 case Operator::greaterOrEqual: return U">=";
782 case Operator::dotStar: return U".*";
783 case Operator::arrowStar: return U"->*";
784 case Operator::arrow: return U"->";
785 case Operator::apply: return U"()";
786 case Operator::subscript: return U"[]";
787 case Operator::less: return U"<";
788 case Operator::greater: return U">";
789 case Operator::add: return U"+";
790 case Operator::sub: return U"-";
791 case Operator::mul: return U"*";
792 case Operator::div: return U"/";
793 case Operator::rem: return U"%";
794 case Operator::xor_: return U"^";
795 case Operator::and_: return U"&";
796 case Operator::or_: return U"|";
797 case Operator::complement: return U"~";
798 case Operator::not_: return U"!";
799 case Operator::comma: return U",";
800 }
801 return std::u32string();
802 }
803
804 std::u32string OperatorFunctionIdNode::Str() const
805 {
806 switch (op)
807 {
808 case Operator::newArray: return U"operator new[]";
809 case Operator::deleteArray: return U"operator delete[]";
810 case Operator::new_: return U"operator new";
811 case Operator::delete_: return U"operator delete";
812 case Operator::assign: return U"operator=";
813 case Operator::mulAssign: return U"operator*=";
814 case Operator::divAssign: return U"operator/=";
815 case Operator::remAssign: return U"operator%=";
816 case Operator::addAssign: return U"operator+=";
817 case Operator::subAssign: return U"operator-=";
818 case Operator::shiftLeftAssign: return U"operator<<=";
819 case Operator::shiftRightAssign: return U"operator>>=";
820 case Operator::andAssign: return U"operator&=";
821 case Operator::xorAssign: return U"operator^=";
822 case Operator::orAssign: return U"operator|=";
823 case Operator::inc: return U"operator++";
824 case Operator::dec: return U"operator--";
825 case Operator::shiftLeft: return U"operator<<";
826 case Operator::shiftRight: return U"operator>>";
827 case Operator::logicalAnd: return U"operator&&";
828 case Operator::logicalOr: return U"operator||";
829 case Operator::equal: return U"operator==";
830 case Operator::notEqual: return U"operator!=";
831 case Operator::lessOrEqual: return U"operator<=";
832 case Operator::greaterOrEqual: return U"operator>=";
833 case Operator::dotStar: return U"operator.*";
834 case Operator::arrowStar: return U"operator->*";
835 case Operator::arrow: return U"operator->";
836 case Operator::apply: return U"operator()";
837 case Operator::subscript: return U"operator[]";
838 case Operator::less: return U"operator<";
839 case Operator::greater: return U"operator>";
840 case Operator::add: return U"operator+";
841 case Operator::sub: return U"operator-";
842 case Operator::mul: return U"operator*";
843 case Operator::div: return U"operator/";
844 case Operator::rem: return U"operator%";
845 case Operator::xor_: return U"operator^";
846 case Operator::and_: return U"operator&";
847 case Operator::or_: return U"operator|";
848 case Operator::complement: return U"operator~";
849 case Operator::not_: return U"operator!";
850 case Operator::comma: return U"operator,";
851 }
852 return std::u32string();
853 }
854
855 std::u32string OperatorFunctionIdNode::GroupName() const
856 {
857 switch (op)
858 {
859 case Operator::newArray: return U"operator_new_array";
860 case Operator::deleteArray: return U"operator_delete_array";
861 case Operator::new_: return U"operator_new";
862 case Operator::delete_: return U"operator_delete";
863 case Operator::assign: return U"operator_assign";
864 case Operator::mulAssign: return U"operator_mul_assign";
865 case Operator::divAssign: return U"operator_div_assign";
866 case Operator::remAssign: return U"operator_rem_assign";
867 case Operator::addAssign: return U"operator_add_assign";
868 case Operator::subAssign: return U"operator_sub_assign";
869 case Operator::shiftLeftAssign: return U"operator_shift_left_assign";
870 case Operator::shiftRightAssign: return U"operator_shift_right_assign";
871 case Operator::andAssign: return U"operator_and_assign";
872 case Operator::xorAssign: return U"operator_xor_assign";
873 case Operator::orAssign: return U"operator_or_assign";
874 case Operator::inc: return U"operator_inc";
875 case Operator::dec: return U"operator_dec";
876 case Operator::shiftLeft: return U"operator_shift_left";
877 case Operator::shiftRight: return U"operator_shift_right";
878 case Operator::logicalAnd: return U"operator_logical_and";
879 case Operator::logicalOr: return U"operator_logical_or";
880 case Operator::equal: return U"operator_equal";
881 case Operator::notEqual: return U"operator_not_equal";
882 case Operator::lessOrEqual: return U"operator_less_or_equal";
883 case Operator::greaterOrEqual: return U"operator_greater_or_equal";
884 case Operator::dotStar: return U"operator_dot_star";
885 case Operator::arrowStar: return U"operator_arrow_star";
886 case Operator::arrow: return U"operator_arrow";
887 case Operator::apply: return U"operator_apply";
888 case Operator::subscript: return U"operator_subscript";
889 case Operator::less: return U"operator_less";
890 case Operator::greater: return U"operator_greater";
891 case Operator::add: return U"operator_add";
892 case Operator::sub: return U"operator_sub";
893 case Operator::mul: return U"operator_mul";
894 case Operator::div: return U"operator_div";
895 case Operator::rem: return U"operator_rem";
896 case Operator::xor_: return U"operator_xor";
897 case Operator::and_: return U"operator_and";
898 case Operator::or_: return U"operator_or";
899 case Operator::complement: return U"operator_complement";
900 case Operator::not_: return U"operator_not";
901 case Operator::comma: return U"operator_comma";
902 }
903 return std::u32string();
904 }
905
906 ConversionFunctionIdNode::ConversionFunctionIdNode() : IdentifierNode(NodeType::conversionFunctionIdNode)
907 {
908 }
909
910 ConversionFunctionIdNode::ConversionFunctionIdNode(const Span& span_, Node* typeExpr_) : IdentifierNode(NodeType::conversionFunctionIdNode, span_, U"operator"), typeExpr(typeExpr_)
911 {
912 }
913
914 void ConversionFunctionIdNode::Accept(Visitor& visitor)
915 {
916 visitor.Visit(*this);
917 }
918
919 void ConversionFunctionIdNode::Write(Writer& writer)
920 {
921 IdentifierNode::Write(writer);
922 typeExpr->Write(writer);
923 }
924
925 void ConversionFunctionIdNode::Read(Reader& reader)
926 {
927 IdentifierNode::Read(reader);
928 typeExpr.reset(reader.ReadNode());
929 }
930
931 DtorIdNode::DtorIdNode() : IdentifierNode(NodeType::dtorIdNode)
932 {
933 }
934
935 DtorIdNode::DtorIdNode(const Span& span_, const std::u32string& identifier_) : IdentifierNode(NodeType::dtorIdNode, span_, identifier_)
936 {
937 }
938
939 void DtorIdNode::Accept(Visitor& visitor)
940 {
941 visitor.Visit(*this);
942 }
943
944 NestedIdNode::NestedIdNode() : BinaryNode(NodeType::nestedIdNode)
945 {
946 }
947
948 NestedIdNode::NestedIdNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::nestedIdNode, span_, left_, right_)
949 {
950 }
951
952 void NestedIdNode::Accept(Visitor& visitor)
953 {
954 visitor.Visit(*this);
955 }
956
957 ParenthesizedExprNode::ParenthesizedExprNode() : UnaryNode(NodeType::parenthesizedExprNode)
958 {
959 }
960
961 ParenthesizedExprNode::ParenthesizedExprNode(const Span& span_, Node* expr_) : UnaryNode(NodeType::parenthesizedExprNode, span_, expr_)
962 {
963 }
964
965 void ParenthesizedExprNode::Accept(Visitor& visitor)
966 {
967 visitor.Visit(*this);
968 }
969
970 LambdaExpressionNode::LambdaExpressionNode() : Node(NodeType::lambdaExpressionNode)
971 {
972 }
973
974 LambdaExpressionNode::LambdaExpressionNode(const Span& span_) : Node(NodeType::lambdaExpressionNode, span_)
975 {
976 }
977
978 void LambdaExpressionNode::AddCapture(Node* capture)
979 {
980 if (captures)
981 {
982 captures.reset(new CaptureSequenceNode(capture->GetSpan(), captures.release(), capture));
983 }
984 else
985 {
986 captures.reset(capture);
987 }
988 }
989
990 void LambdaExpressionNode::SetParameters(Node* parameters_)
991 {
992 parameters.reset(parameters_);
993 }
994
995 void LambdaExpressionNode::SetBody(CompoundStatementNode* body_)
996 {
997 body.reset(body_);
998 }
999
1000 void LambdaExpressionNode::Accept(Visitor& visitor)
1001 {
1002 visitor.Visit(*this);
1003 }
1004
1005 void LambdaExpressionNode::Write(Writer& writer)
1006 {
1007 Node::Write(writer);
1008 writer.GetBinaryWriter().Write(captures != nullptr);
1009 if (captures)
1010 {
1011 captures->Write(writer);
1012 }
1013 writer.GetBinaryWriter().Write(parameters != nullptr);
1014 if (parameters)
1015 {
1016 parameters->Write(writer);
1017 }
1018 body->Write(writer);
1019 }
1020
1021 void LambdaExpressionNode::Read(Reader& reader)
1022 {
1023 Node::Read(reader);
1024 bool hasCaptures = reader.GetBinaryReader().ReadBool();
1025 if (hasCaptures)
1026 {
1027 captures.reset(reader.ReadNode());
1028 }
1029 bool hasParameters = reader.GetBinaryReader().ReadBool();
1030 if (hasParameters)
1031 {
1032 parameters.reset(reader.ReadNode());
1033 }
1034 body.reset(reader.ReadCompoundStatementNode());
1035 }
1036
1037 CaptureSequenceNode::CaptureSequenceNode() : BinaryNode(NodeType::captureSequenceNode)
1038 {
1039 }
1040
1041 CaptureSequenceNode::CaptureSequenceNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::captureSequenceNode, span_, left_, right_)
1042 {
1043 }
1044
1045 void CaptureSequenceNode::Accept(Visitor& visitor)
1046 {
1047 visitor.Visit(*this);
1048 }
1049
1050 AssignCaptureNode::AssignCaptureNode() : Node(NodeType::assignCaptureNode)
1051 {
1052 }
1053
1054 AssignCaptureNode::AssignCaptureNode(const Span& span_) : Node(NodeType::assignCaptureNode, span_)
1055 {
1056 }
1057
1058 void AssignCaptureNode::Accept(Visitor& visitor)
1059 {
1060 visitor.Visit(*this);
1061 }
1062
1063 RefCaptureNode::RefCaptureNode() : Node(NodeType::refCaptureNode)
1064 {
1065 }
1066
1067 RefCaptureNode::RefCaptureNode(const Span& span_) : Node(NodeType::refCaptureNode, span_)
1068 {
1069 }
1070
1071 void RefCaptureNode::Accept(Visitor& visitor)
1072 {
1073 visitor.Visit(*this);
1074 }
1075
1076 ThisCaptureNode::ThisCaptureNode() : Node(NodeType::thisCaptureNode)
1077 {
1078 }
1079
1080 ThisCaptureNode::ThisCaptureNode(const Span& span_) : Node(NodeType::thisCaptureNode, span_)
1081 {
1082 }
1083
1084 void ThisCaptureNode::Accept(Visitor& visitor)
1085 {
1086 visitor.Visit(*this);
1087 }
1088
1089 IdentifierCaptureNode::IdentifierCaptureNode() : UnaryNode(NodeType::identifierCaptureNode)
1090 {
1091 }
1092
1093 IdentifierCaptureNode::IdentifierCaptureNode(const Span& span_, IdentifierNode* id_) : UnaryNode(NodeType::identifierCaptureNode, span_, id_)
1094 {
1095 }
1096
1097 void IdentifierCaptureNode::Accept(Visitor& visitor)
1098 {
1099 visitor.Visit(*this);
1100 }
1101
1102 } }