1
2
3
4
5
6 #include <sngcm/ast/Concept.hpp>
7 #include <sngcm/ast/Identifier.hpp>
8 #include <sngcm/ast/Visitor.hpp>
9 #include <soulng/util/Unicode.hpp>
10
11 namespace sngcm { namespace ast {
12
13 using namespace soulng::unicode;
14
15 ConstraintNode::ConstraintNode(NodeType nodeType_, const Span& span_) : Node(nodeType_, span_)
16 {
17 }
18
19 ParenthesizedConstraintNode::ParenthesizedConstraintNode(const Span& span_) : ConstraintNode(NodeType::parenthesizedConstraintNode, span_)
20 {
21 }
22
23 ParenthesizedConstraintNode::ParenthesizedConstraintNode(const Span& span_, ConstraintNode* constraint_) : ConstraintNode(NodeType::parenthesizedConstraintNode, span_), constraint(constraint_)
24 {
25 }
26
27 Node* ParenthesizedConstraintNode::Clone(CloneContext& cloneContext) const
28 {
29 return new ParenthesizedConstraintNode(GetSpan(), static_cast<ConstraintNode*>(constraint->Clone(cloneContext)));
30 }
31
32 void ParenthesizedConstraintNode::Accept(Visitor& visitor)
33 {
34 visitor.Visit(*this);
35 }
36
37 void ParenthesizedConstraintNode::Write(AstWriter& writer)
38 {
39 ConstraintNode::Write(writer);
40 writer.Write(constraint.get());
41 }
42
43 void ParenthesizedConstraintNode::Read(AstReader& reader)
44 {
45 ConstraintNode::Read(reader);
46 constraint.reset(reader.ReadConstraintNode());
47 }
48
49 std::string ParenthesizedConstraintNode::ToString() const
50 {
51 return "(" + constraint->ToString() + ")";
52 }
53
54 BinaryConstraintNode::BinaryConstraintNode(NodeType nodeType_, const Span& span_) : ConstraintNode(nodeType_, span_), left(), right()
55 {
56 }
57
58 BinaryConstraintNode::BinaryConstraintNode(NodeType nodeType_, const Span& span_, ConstraintNode* left_, ConstraintNode* right_) : ConstraintNode(nodeType_, span_), left(left_), right(right_)
59 {
60 left->SetParent(this);
61 right->SetParent(this);
62 }
63
64 void BinaryConstraintNode::Write(AstWriter& writer)
65 {
66 ConstraintNode::Write(writer);
67 writer.Write(left.get());
68 writer.Write(right.get());
69 }
70
71 void BinaryConstraintNode::Read(AstReader& reader)
72 {
73 ConstraintNode::Read(reader);
74 left.reset(reader.ReadConstraintNode());
75 left->SetParent(this);
76 right.reset(reader.ReadConstraintNode());
77 right->SetParent(this);
78 }
79
80 DisjunctiveConstraintNode::DisjunctiveConstraintNode(const Span& span_) : BinaryConstraintNode(NodeType::disjunctiveConstraintNode, span_)
81 {
82 }
83
84 DisjunctiveConstraintNode::DisjunctiveConstraintNode(const Span& span_, ConstraintNode* left_, ConstraintNode* right_) :
85 BinaryConstraintNode(NodeType::disjunctiveConstraintNode, span_, left_, right_)
86 {
87 }
88
89 Node* DisjunctiveConstraintNode::Clone(CloneContext& cloneContext) const
90 {
91 return new DisjunctiveConstraintNode(GetSpan(), static_cast<ConstraintNode*>(Left()->Clone(cloneContext)), static_cast<ConstraintNode*>(Right()->Clone(cloneContext)));
92 }
93
94 void DisjunctiveConstraintNode::Accept(Visitor& visitor)
95 {
96 visitor.Visit(*this);
97 }
98
99 std::string DisjunctiveConstraintNode::ToString() const
100 {
101 return Left()->ToString() + " or " + Right()->ToString();
102 }
103
104 ConjunctiveConstraintNode::ConjunctiveConstraintNode(const Span& span_) : BinaryConstraintNode(NodeType::conjunctiveConstraintNode, span_)
105 {
106 }
107
108 ConjunctiveConstraintNode::ConjunctiveConstraintNode(const Span& span_, ConstraintNode* left_, ConstraintNode* right_) :
109 BinaryConstraintNode(NodeType::conjunctiveConstraintNode, span_, left_, right_)
110 {
111 }
112
113 Node* ConjunctiveConstraintNode::Clone(CloneContext& cloneContext) const
114 {
115 return new ConjunctiveConstraintNode(GetSpan(), static_cast<ConstraintNode*>(Left()->Clone(cloneContext)), static_cast<ConstraintNode*>(Right()->Clone(cloneContext)));
116 }
117
118 void ConjunctiveConstraintNode::Accept(Visitor& visitor)
119 {
120 visitor.Visit(*this);
121 }
122
123 std::string ConjunctiveConstraintNode::ToString() const
124 {
125 return Left()->ToString() + " and " + Right()->ToString();
126 }
127
128
129 WhereConstraintNode::WhereConstraintNode(const Span& span_) : ConstraintNode(NodeType::whereConstraintNode, span_), constraint(), headerConstraint(false), semicolon(false)
130 {
131 }
132
133 WhereConstraintNode::WhereConstraintNode(const Span& span_, ConstraintNode* constraint_) :
134 ConstraintNode(NodeType::whereConstraintNode, span_), constraint(constraint_), headerConstraint(false), semicolon(false)
135 {
136 constraint->SetParent(this);
137 }
138
139 Node* WhereConstraintNode::Clone(CloneContext& cloneContext) const
140 {
141 WhereConstraintNode* clone = new WhereConstraintNode(GetSpan(), static_cast<ConstraintNode*>(constraint->Clone(cloneContext)));
142 if (headerConstraint)
143 {
144 clone->SetHeaderConstraint();
145 }
146 if (semicolon)
147 {
148 clone->SetSemicolon();
149 }
150 return clone;
151 }
152
153 void WhereConstraintNode::Accept(Visitor& visitor)
154 {
155 visitor.Visit(*this);
156 }
157
158 void WhereConstraintNode::Write(AstWriter& writer)
159 {
160 ConstraintNode::Write(writer);
161 writer.Write(constraint.get());
162 writer.GetBinaryWriter().Write(headerConstraint);
163 writer.GetBinaryWriter().Write(semicolon);
164 }
165
166 void WhereConstraintNode::Read(AstReader& reader)
167 {
168 ConstraintNode::Read(reader);
169 constraint.reset(reader.ReadConstraintNode());
170 constraint->SetParent(this);
171 headerConstraint = reader.GetBinaryReader().ReadBool();
172 semicolon = reader.GetBinaryReader().ReadBool();
173 }
174
175 std::string WhereConstraintNode::ToString() const
176 {
177 return "where " + constraint->ToString();
178 }
179
180 PredicateConstraintNode::PredicateConstraintNode(const Span& span_) : ConstraintNode(NodeType::predicateConstraintNode, span_), invokeExpr()
181 {
182 }
183
184 PredicateConstraintNode::PredicateConstraintNode(const Span& span_, Node* invokeExpr_) : ConstraintNode(NodeType::predicateConstraintNode, span_), invokeExpr(invokeExpr_)
185 {
186 invokeExpr->SetParent(this);
187 }
188
189 Node* PredicateConstraintNode::Clone(CloneContext& cloneContext) const
190 {
191 return new PredicateConstraintNode(GetSpan(), invokeExpr->Clone(cloneContext));
192 }
193
194 void PredicateConstraintNode::Accept(Visitor& visitor)
195 {
196 visitor.Visit(*this);
197 }
198
199 void PredicateConstraintNode::Write(AstWriter& writer)
200 {
201 ConstraintNode::Write(writer);
202 writer.Write(invokeExpr.get());
203 }
204
205 void PredicateConstraintNode::Read(AstReader& reader)
206 {
207 ConstraintNode::Read(reader);
208 invokeExpr.reset(reader.ReadNode());
209 invokeExpr->SetParent(this);
210 }
211
212 std::string PredicateConstraintNode::ToString() const
213 {
214 return invokeExpr->ToString();
215 }
216
217 IsConstraintNode::IsConstraintNode(const Span& span_) : ConstraintNode(NodeType::isConstraintNode, span_), typeExpr(), conceptOrTypeName()
218 {
219 }
220
221 IsConstraintNode::IsConstraintNode(const Span& span_, Node* typeExpr_, Node* conceptOrTypeName_) :
222 ConstraintNode(NodeType::isConstraintNode, span_), typeExpr(typeExpr_), conceptOrTypeName(conceptOrTypeName_)
223 {
224 typeExpr->SetParent(this);
225 conceptOrTypeName->SetParent(this);
226 }
227
228 Node* IsConstraintNode::Clone(CloneContext& cloneContext) const
229 {
230 return new IsConstraintNode(GetSpan(), typeExpr->Clone(cloneContext), conceptOrTypeName->Clone(cloneContext));
231 }
232
233 void IsConstraintNode::Accept(Visitor& visitor)
234 {
235 visitor.Visit(*this);
236 }
237
238 void IsConstraintNode::Write(AstWriter& writer)
239 {
240 ConstraintNode::Write(writer);
241 writer.Write(typeExpr.get());
242 writer.Write(conceptOrTypeName.get());
243 }
244
245 void IsConstraintNode::Read(AstReader& reader)
246 {
247 ConstraintNode::Read(reader);
248 typeExpr.reset(reader.ReadNode());
249 typeExpr->SetParent(this);
250 conceptOrTypeName.reset(reader.ReadNode());
251 conceptOrTypeName->SetParent(this);
252 }
253
254 std::string IsConstraintNode::ToString() const
255 {
256 return typeExpr->ToString() + " is " + conceptOrTypeName->ToString();
257 }
258
259 MultiParamConstraintNode::MultiParamConstraintNode(const Span& span_) : ConstraintNode(NodeType::multiParamConstraintNode, span_), conceptId(), typeExprs()
260 {
261 }
262
263 MultiParamConstraintNode::MultiParamConstraintNode(const Span& span_, IdentifierNode* conceptId_) : ConstraintNode(NodeType::multiParamConstraintNode, span_), conceptId(conceptId_), typeExprs()
264 {
265 conceptId->SetParent(this);
266 }
267
268 Node* MultiParamConstraintNode::Clone(CloneContext& cloneContext) const
269 {
270 MultiParamConstraintNode* clone = new MultiParamConstraintNode(GetSpan(), static_cast<IdentifierNode*>(conceptId->Clone(cloneContext)));
271 int n = typeExprs.Count();
272 for (int i = 0; i < n; ++i)
273 {
274 clone->AddTypeExpr(typeExprs[i]->Clone(cloneContext));
275 }
276 return clone;
277 }
278
279 void MultiParamConstraintNode::Accept(Visitor& visitor)
280 {
281 visitor.Visit(*this);
282 }
283
284 void MultiParamConstraintNode::Write(AstWriter& writer)
285 {
286 ConstraintNode::Write(writer);
287 writer.Write(conceptId.get());
288 typeExprs.Write(writer);
289 }
290
291 void MultiParamConstraintNode::Read(AstReader& reader)
292 {
293 ConstraintNode::Read(reader);
294 conceptId.reset(reader.ReadIdentifierNode());
295 conceptId->SetParent(this);
296 typeExprs.Read(reader);
297 typeExprs.SetParent(this);
298 }
299
300 void MultiParamConstraintNode::AddTypeExpr(Node* typeExpr)
301 {
302 typeExpr->SetParent(this);
303 typeExprs.Add(typeExpr);
304 }
305
306 std::string MultiParamConstraintNode::ToString() const
307 {
308 std::string s = conceptId->ToString();
309 s.append(1, '<');
310 int n = typeExprs.Count();
311 for (int i = 0; i < n; ++i)
312 {
313 if (i > 0)
314 {
315 s.append(", ");
316 }
317 s.append(typeExprs[i]->ToString());
318 }
319 s.append(1, '>');
320 return s;
321 }
322
323 TypeNameConstraintNode::TypeNameConstraintNode(const Span& span_) : ConstraintNode(NodeType::typeNameConstraintNode, span_), typeId()
324 {
325 }
326
327 TypeNameConstraintNode::TypeNameConstraintNode(const Span& span_, Node* typeId_) : ConstraintNode(NodeType::typeNameConstraintNode, span_), typeId(typeId_)
328 {
329 typeId->SetParent(this);
330 }
331
332 Node* TypeNameConstraintNode::Clone(CloneContext& cloneContext) const
333 {
334 return new TypeNameConstraintNode(GetSpan(), typeId->Clone(cloneContext));
335 }
336
337 void TypeNameConstraintNode::Accept(Visitor& visitor)
338 {
339 visitor.Visit(*this);
340 }
341
342 void TypeNameConstraintNode::Write(AstWriter& writer)
343 {
344 ConstraintNode::Write(writer);
345 writer.Write(typeId.get());
346 }
347
348 void TypeNameConstraintNode::Read(AstReader& reader)
349 {
350 ConstraintNode::Read(reader);
351 typeId.reset(reader.ReadNode());
352 }
353
354 std::string TypeNameConstraintNode::ToString() const
355 {
356 return "typename " + typeId->ToString();
357 }
358
359 SignatureConstraintNode::SignatureConstraintNode(NodeType nodeType_, const Span& span_) : ConstraintNode(nodeType_, span_)
360 {
361 }
362
363 ConstructorConstraintNode::ConstructorConstraintNode(const Span& span_) : SignatureConstraintNode(NodeType::constructorConstraintNode, span_), typeParamId(), parameters()
364 {
365 }
366
367 ConstructorConstraintNode::ConstructorConstraintNode(const Span& span_, IdentifierNode* typeParamId_) :
368 SignatureConstraintNode(NodeType::constructorConstraintNode, span_), typeParamId(typeParamId_), parameters()
369 {
370 typeParamId->SetParent(this);
371 }
372
373 Node* ConstructorConstraintNode::Clone(CloneContext& cloneContext) const
374 {
375 ConstructorConstraintNode* clone = new ConstructorConstraintNode(GetSpan(), static_cast<IdentifierNode*>(typeParamId->Clone(cloneContext)));
376 int n = parameters.Count();
377 for (int i = 0; i < n; ++i)
378 {
379 clone->AddParameter(static_cast<ParameterNode*>(parameters[i]->Clone(cloneContext)));
380 }
381 return clone;
382 }
383
384 void ConstructorConstraintNode::Accept(Visitor& visitor)
385 {
386 visitor.Visit(*this);
387 }
388
389 void ConstructorConstraintNode::Write(AstWriter& writer)
390 {
391 SignatureConstraintNode::Write(writer);
392 writer.Write(typeParamId.get());
393 parameters.Write(writer);
394 }
395
396 void ConstructorConstraintNode::Read(AstReader& reader)
397 {
398 SignatureConstraintNode::Read(reader);
399 typeParamId.reset(static_cast<IdentifierNode*>(reader.ReadNode()));
400 typeParamId->SetParent(this);
401 parameters.Read(reader);
402 parameters.SetParent(this);
403 }
404
405 std::string ConstructorConstraintNode::ToString() const
406 {
407 std::string s = typeParamId->ToString();
408 s.append(1, '(');
409 int n = parameters.Count();
410 for (int i = 0; i < n; ++i)
411 {
412 if (i > 0)
413 {
414 s.append(", ");
415 }
416 ParameterNode* p = parameters[i];
417 s.append(p->TypeExpr()->ToString());
418 }
419 s.append(1, ')');
420 return s;
421 }
422
423 void ConstructorConstraintNode::AddParameter(ParameterNode* parameter)
424 {
425 parameter->SetParent(this);
426 parameters.Add(parameter);
427 }
428
429 DestructorConstraintNode::DestructorConstraintNode(const Span& span_) : SignatureConstraintNode(NodeType::destructorConstraintNode, span_), typeParamId()
430 {
431 }
432
433 DestructorConstraintNode::DestructorConstraintNode(const Span& span_, IdentifierNode* typeParamId_) : SignatureConstraintNode(NodeType::destructorConstraintNode, span_), typeParamId(typeParamId_)
434 {
435 typeParamId->SetParent(this);
436 }
437
438 Node* DestructorConstraintNode::Clone(CloneContext& cloneContext) const
439 {
440 return new DestructorConstraintNode(GetSpan(), static_cast<IdentifierNode*>(typeParamId->Clone(cloneContext)));
441 }
442
443 void DestructorConstraintNode::Accept(Visitor& visitor)
444 {
445 visitor.Visit(*this);
446 }
447
448 void DestructorConstraintNode::Write(AstWriter& writer)
449 {
450 SignatureConstraintNode::Write(writer);
451 writer.Write(typeParamId.get());
452 }
453
454 void DestructorConstraintNode::Read(AstReader& reader)
455 {
456 SignatureConstraintNode::Read(reader);
457 typeParamId.reset(reader.ReadIdentifierNode());
458 typeParamId->SetParent(this);
459 }
460
461 std::string DestructorConstraintNode::ToString() const
462 {
463 std::string s = "~" + typeParamId->ToString();
464 s.append("()");
465 return s;
466 }
467
468 MemberFunctionConstraintNode::MemberFunctionConstraintNode(const Span& span_) :
469 SignatureConstraintNode(NodeType::memberFunctionConstraintNode, span_), returnTypeExpr(), typeParamId(), groupId(), parameters()
470 {
471 }
472
473 MemberFunctionConstraintNode::MemberFunctionConstraintNode(const Span& span_, Node* returnTypeExpr_, IdentifierNode* typeParamId_, const std::u32string& groupId_) :
474 SignatureConstraintNode(NodeType::memberFunctionConstraintNode, span_), returnTypeExpr(returnTypeExpr_), typeParamId(typeParamId_), groupId(groupId_), parameters()
475 {
476 returnTypeExpr->SetParent(this);
477 typeParamId->SetParent(this);
478 }
479
480 Node* MemberFunctionConstraintNode::Clone(CloneContext& cloneContext) const
481 {
482 MemberFunctionConstraintNode* clone = new MemberFunctionConstraintNode(GetSpan(), returnTypeExpr->Clone(cloneContext), static_cast<IdentifierNode*>(typeParamId->Clone(cloneContext)), groupId);
483 int n = parameters.Count();
484 for (int i = 0; i < n; ++i)
485 {
486 clone->AddParameter(static_cast<ParameterNode*>(parameters[i]->Clone(cloneContext)));
487 }
488 return clone;
489 }
490
491 void MemberFunctionConstraintNode::Accept(Visitor& visitor)
492 {
493 visitor.Visit(*this);
494 }
495
496 void MemberFunctionConstraintNode::Write(AstWriter& writer)
497 {
498 SignatureConstraintNode::Write(writer);
499 writer.Write(returnTypeExpr.get());
500 writer.Write(typeParamId.get());
501 writer.GetBinaryWriter().Write(groupId);
502 parameters.Write(writer);
503 }
504
505 void MemberFunctionConstraintNode::Read(AstReader& reader)
506 {
507 SignatureConstraintNode::Read(reader);
508 returnTypeExpr.reset(reader.ReadNode());
509 returnTypeExpr->SetParent(this);
510 typeParamId.reset(reader.ReadIdentifierNode());
511 typeParamId->SetParent(this);
512 groupId = reader.GetBinaryReader().ReadUtf32String();
513 parameters.Read(reader);
514 parameters.SetParent(this);
515 }
516
517 void MemberFunctionConstraintNode::AddParameter(ParameterNode* parameter)
518 {
519 parameter->SetParent(this);
520 parameters.Add(parameter);
521 }
522
523 std::string MemberFunctionConstraintNode::ToString() const
524 {
525 std::string s;
526 if (returnTypeExpr)
527 {
528 s.append(returnTypeExpr->ToString()).append(" ");
529 }
530 s.append(typeParamId->ToString());
531 s.append(".").append(ToUtf8(groupId));
532 s.append(1, '(');
533 int n = parameters.Count();
534 for (int i = 0; i < n; ++i)
535 {
536 if (i > 0)
537 {
538 s.append(", ");
539 }
540 ParameterNode* p = parameters[i];
541 s.append(p->TypeExpr()->ToString());
542 }
543 s.append(1, ')');
544 return s;
545 }
546
547 FunctionConstraintNode::FunctionConstraintNode(const Span& span_) : SignatureConstraintNode(NodeType::functionConstraintNode, span_), returnTypeExpr(), groupId(), parameters()
548 {
549 }
550
551 FunctionConstraintNode::FunctionConstraintNode(const Span& span_, Node* returnTypeExpr_, const std::u32string& groupId_)
552 : SignatureConstraintNode(NodeType::functionConstraintNode, span_), returnTypeExpr(returnTypeExpr_), groupId(groupId_), parameters()
553 {
554 returnTypeExpr->SetParent(this);
555 }
556
557 Node* FunctionConstraintNode::Clone(CloneContext& cloneContext) const
558 {
559 FunctionConstraintNode* clone = new FunctionConstraintNode(GetSpan(), returnTypeExpr->Clone(cloneContext), groupId);
560 int n = parameters.Count();
561 for (int i = 0; i < n; ++i)
562 {
563 clone->AddParameter(static_cast<ParameterNode*>(parameters[i]->Clone(cloneContext)));
564 }
565 return clone;
566 }
567
568 void FunctionConstraintNode::Accept(Visitor& visitor)
569 {
570 visitor.Visit(*this);
571 }
572
573 void FunctionConstraintNode::Write(AstWriter& writer)
574 {
575 SignatureConstraintNode::Write(writer);
576 writer.Write(returnTypeExpr.get());
577 writer.GetBinaryWriter().Write(groupId);
578 parameters.Write(writer);
579 }
580
581 void FunctionConstraintNode::Read(AstReader& reader)
582 {
583 SignatureConstraintNode::Read(reader);
584 returnTypeExpr.reset(reader.ReadNode());
585 returnTypeExpr->SetParent(this);
586 groupId = reader.GetBinaryReader().ReadUtf32String();
587 parameters.Read(reader);
588 parameters.SetParent(this);
589 }
590
591 void FunctionConstraintNode::AddParameter(ParameterNode* parameter)
592 {
593 parameter->SetParent(this);
594 parameters.Add(parameter);
595 }
596
597 std::string FunctionConstraintNode::ToString() const
598 {
599 std::string s;
600 if (returnTypeExpr)
601 {
602 s.append(returnTypeExpr->ToString()).append(" ");
603 }
604 s.append(ToUtf8(groupId));
605 s.append(1, '(');
606 int n = parameters.Count();
607 for (int i = 0; i < n; ++i)
608 {
609 if (i > 0)
610 {
611 s.append(", ");
612 }
613 ParameterNode* p = parameters[i];
614 s.append(p->TypeExpr()->ToString());
615 }
616 s.append(1, ')');
617 return s;
618 }
619
620 AxiomStatementNode::AxiomStatementNode(const Span& span_) : Node(NodeType::axiomStatementNode, span_), expression(), text()
621 {
622 }
623
624 AxiomStatementNode::AxiomStatementNode(const Span& span_, Node* expression_, const std::u32string& text_) : Node(NodeType::axiomStatementNode, span_), expression(expression_), text(text_)
625 {
626 expression->SetParent(this);
627 }
628
629 Node* AxiomStatementNode::Clone(CloneContext& cloneContext) const
630 {
631 return new AxiomStatementNode(GetSpan(), expression->Clone(cloneContext), text);
632 }
633
634 void AxiomStatementNode::Accept(Visitor& visitor)
635 {
636 visitor.Visit(*this);
637 }
638
639 void AxiomStatementNode::Write(AstWriter& writer)
640 {
641 Node::Write(writer);
642 writer.Write(expression.get());
643 writer.GetBinaryWriter().Write(text);
644 }
645
646 void AxiomStatementNode::Read(AstReader& reader)
647 {
648 Node::Read(reader);
649 expression.reset(reader.ReadNode());
650 expression->SetParent(this);
651 text = reader.GetBinaryReader().ReadUtf32String();
652 }
653
654 std::string AxiomStatementNode::ToString() const
655 {
656 return ToUtf8(text);
657 }
658
659 AxiomNode::AxiomNode(const Span& span_) : Node(NodeType::axiomNode, span_), id(), parameters(), statements()
660 {
661 }
662
663 AxiomNode::AxiomNode(const Span& span_, IdentifierNode* id_) : Node(NodeType::axiomNode, span_), id(id_), parameters(), statements()
664 {
665 id->SetParent(this);
666 }
667
668 Node* AxiomNode::Clone(CloneContext& cloneContext) const
669 {
670 AxiomNode* clone = new AxiomNode(GetSpan(), static_cast<IdentifierNode*>(id->Clone(cloneContext)));
671 int np = parameters.Count();
672 for (int i = 0; i < np; ++i)
673 {
674 clone->AddParameter(static_cast<ParameterNode*>(parameters[i]->Clone(cloneContext)));
675 }
676 int ns = statements.Count();
677 for (int i = 0; i < ns; ++i)
678 {
679 clone->AddStatement(static_cast<AxiomStatementNode*>(statements[i]->Clone(cloneContext)));
680 }
681 clone->SetBeginBraceSpan(beginBraceSpan);
682 clone->SetEndBraceSpan(endBraceSpan);
683 return clone;
684 }
685
686 void AxiomNode::Accept(Visitor& visitor)
687 {
688 visitor.Visit(*this);
689 }
690
691 void AxiomNode::Write(AstWriter& writer)
692 {
693 Node::Write(writer);
694 writer.Write(id.get());
695 parameters.Write(writer);
696 statements.Write(writer);
697 writer.Write(beginBraceSpan);
698 writer.Write(endBraceSpan);
699 }
700
701 void AxiomNode::Read(AstReader& reader)
702 {
703 Node::Read(reader);
704 id.reset(reader.ReadIdentifierNode());
705 id->SetParent(this);
706 parameters.Read(reader);
707 parameters.SetParent(this);
708 statements.Read(reader);
709 statements.SetParent(this);
710 beginBraceSpan = reader.ReadSpan();
711 endBraceSpan = reader.ReadSpan();
712 }
713
714 void AxiomNode::AddParameter(ParameterNode* parameter)
715 {
716 parameter->SetParent(this);
717 parameters.Add(parameter);
718 }
719
720 void AxiomNode::AddStatement(AxiomStatementNode* statement)
721 {
722 statement->SetParent(this);
723 statements.Add(statement);
724 }
725
726 ConceptIdNode::ConceptIdNode(const Span& span_) : Node(NodeType::conceptIdNode, span_), id(), typeParameters()
727 {
728 }
729
730 ConceptIdNode::ConceptIdNode(const Span& span_, IdentifierNode* id_) : Node(NodeType::conceptIdNode, span_), id(id_), typeParameters()
731 {
732 id->SetParent(this);
733 }
734
735 Node* ConceptIdNode::Clone(CloneContext& cloneContext) const
736 {
737 ConceptIdNode* clone = new ConceptIdNode(GetSpan(), static_cast<IdentifierNode*>(id->Clone(cloneContext)));
738 int n = typeParameters.Count();
739 for (int i = 0; i < n; ++i)
740 {
741 clone->AddTypeParameter(typeParameters[i]->Clone(cloneContext));
742 }
743 return clone;
744 }
745
746 void ConceptIdNode::Accept(Visitor& visitor)
747 {
748 visitor.Visit(*this);
749 }
750
751 void ConceptIdNode::Write(AstWriter& writer)
752 {
753 Node::Write(writer);
754 writer.Write(id.get());
755 typeParameters.Write(writer);
756 }
757
758 void ConceptIdNode::Read(AstReader& reader)
759 {
760 Node::Read(reader);
761 id.reset(reader.ReadIdentifierNode());
762 id->SetParent(this);
763 typeParameters.Read(reader);
764 typeParameters.SetParent(this);
765 }
766
767 void ConceptIdNode::AddTypeParameter(Node* typeParameter)
768 {
769 typeParameter->SetParent(this);
770 typeParameters.Add(typeParameter);
771 }
772
773 std::string ConceptIdNode::ToString() const
774 {
775 std::string s = id->ToString();
776 s.append(1, '<');
777 int n = typeParameters.Count();
778 for (int i = 0; i < n; ++i)
779 {
780 if (i > 0)
781 {
782 s.append(", ");
783 }
784 s.append(typeParameters[i]->ToString());
785 }
786 s.append(1, '>');
787 return s;
788 }
789
790 ConceptNode::ConceptNode(const Span& span_) : Node(NodeType::conceptNode, span_), specifiers(Specifiers::none), id(), typeParameters(), refinement(), constraints(), axioms()
791 {
792 }
793
794 ConceptNode::ConceptNode(NodeType nodeType_, const Span& span_) : Node(nodeType_, span_), specifiers(Specifiers::none), id(), typeParameters(), refinement(), constraints(), axioms()
795 {
796 }
797
798 ConceptNode::ConceptNode(const Span& span_, Specifiers specifiers_, IdentifierNode* id_) :
799 Node(NodeType::conceptNode, span_), specifiers(specifiers_), id(id_), typeParameters(), refinement(), constraints(), axioms()
800 {
801 id->SetParent(this);
802 }
803
804 ConceptNode::ConceptNode(NodeType nodeType_, const Span& span_, Specifiers specifiers_, IdentifierNode* id_) :
805 Node(nodeType_, span_), specifiers(specifiers_), id(id_), typeParameters(), refinement(), constraints(), axioms()
806 {
807 id->SetParent(this);
808 }
809
810 Node* ConceptNode::Clone(CloneContext& cloneContext) const
811 {
812 ConceptNode* clone = new ConceptNode(GetSpan(), specifiers, static_cast<IdentifierNode*>(id->Clone(cloneContext)));
813 int nt = typeParameters.Count();
814 for (int i = 0; i < nt; ++i)
815 {
816 clone->AddTypeParameter(static_cast<IdentifierNode*>(typeParameters[i]->Clone(cloneContext)));
817 }
818 if (refinement)
819 {
820 clone->SetRefinement(static_cast<ConceptIdNode*>(refinement->Clone(cloneContext)));
821 }
822 int nc = constraints.Count();
823 for (int i = 0; i < nc; ++i)
824 {
825 clone->AddConstraint(static_cast<ConstraintNode*>(constraints[i]->Clone(cloneContext)));
826 }
827 int na = axioms.Count();
828 for (int i = 0; i < na; ++i)
829 {
830 clone->AddAxiom(static_cast<AxiomNode*>(axioms[i]->Clone(cloneContext)));
831 }
832 clone->SetBeginBraceSpan(beginBraceSpan);
833 clone->SetEndBraceSpan(endBraceSpan);
834 return clone;
835 }
836
837 void ConceptNode::Accept(Visitor& visitor)
838 {
839 visitor.Visit(*this);
840 }
841
842 void ConceptNode::Write(AstWriter& writer)
843 {
844 Node::Write(writer);
845 writer.Write(specifiers);
846 writer.Write(id.get());
847 typeParameters.Write(writer);
848 bool hasRefinement = refinement != nullptr;
849 writer.GetBinaryWriter().Write(hasRefinement);
850 if (hasRefinement)
851 {
852 writer.Write(refinement.get());
853 }
854 constraints.Write(writer);
855 axioms.Write(writer);
856 writer.Write(beginBraceSpan);
857 writer.Write(endBraceSpan);
858 }
859
860 void ConceptNode::Read(AstReader& reader)
861 {
862 Node::Read(reader);
863 specifiers = reader.ReadSpecifiers();
864 id.reset(reader.ReadIdentifierNode());
865 id->SetParent(this);
866 typeParameters.Read(reader);
867 typeParameters.SetParent(this);
868 bool hasRefinement = reader.GetBinaryReader().ReadBool();
869 if (hasRefinement)
870 {
871 refinement.reset(reader.ReadConceptIdNode());
872 refinement->SetParent(this);
873 }
874 constraints.Read(reader);
875 constraints.SetParent(this);
876 axioms.Read(reader);
877 axioms.SetParent(this);
878 beginBraceSpan = reader.ReadSpan();
879 endBraceSpan = reader.ReadSpan();
880 }
881
882 void ConceptNode::AddTypeParameter(IdentifierNode* typeParameter)
883 {
884 typeParameter->SetParent(this);
885 typeParameters.Add(typeParameter);
886 }
887
888 void ConceptNode::SetRefinement(ConceptIdNode* refinement_)
889 {
890 refinement.reset(refinement_);
891 refinement->SetParent(this);
892 }
893
894 void ConceptNode::AddConstraint(ConstraintNode* constraint)
895 {
896 constraint->SetParent(this);
897 constraints.Add(constraint);
898 }
899
900 void ConceptNode::AddAxiom(AxiomNode* axiom_)
901 {
902 axiom_->SetParent(this);
903 axioms.Add(axiom_);
904 }
905
906 IntrinsicConstraintNode::IntrinsicConstraintNode(NodeType nodeType_) : ConstraintNode(nodeType_, Span())
907 {
908 }
909
910 SameConstraintNode::SameConstraintNode() : IntrinsicConstraintNode(NodeType::sameConstraintNode)
911 {
912 }
913
914 SameConstraintNode::SameConstraintNode(const Span& span_) : IntrinsicConstraintNode(NodeType::sameConstraintNode)
915 {
916 }
917
918 void SameConstraintNode::Accept(Visitor& visitor)
919 {
920 visitor.Visit(*this);
921 }
922
923 Node* SameConstraintNode::Clone(CloneContext& cloneContext) const
924 {
925 return new SameConstraintNode();
926 }
927
928 DerivedConstraintNode::DerivedConstraintNode() : IntrinsicConstraintNode(NodeType::derivedConstraintNode)
929 {
930 }
931
932 DerivedConstraintNode::DerivedConstraintNode(const Span& span_) : IntrinsicConstraintNode(NodeType::derivedConstraintNode)
933 {
934 }
935
936 void DerivedConstraintNode::Accept(Visitor& visitor)
937 {
938 visitor.Visit(*this);
939 }
940
941 Node* DerivedConstraintNode::Clone(CloneContext& cloneContext) const
942 {
943 return new DerivedConstraintNode();
944 }
945
946 ConvertibleConstraintNode::ConvertibleConstraintNode() : IntrinsicConstraintNode(NodeType::convertibleConstraintNode)
947 {
948 }
949
950 ConvertibleConstraintNode::ConvertibleConstraintNode(const Span& span_) : IntrinsicConstraintNode(NodeType::convertibleConstraintNode)
951 {
952 }
953
954 void ConvertibleConstraintNode::Accept(Visitor& visitor)
955 {
956 visitor.Visit(*this);
957 }
958
959 Node* ConvertibleConstraintNode::Clone(CloneContext& cloneContext) const
960 {
961 return new ConvertibleConstraintNode();
962 }
963
964 ExplicitlyConvertibleConstraintNode::ExplicitlyConvertibleConstraintNode() : IntrinsicConstraintNode(NodeType::explicitlyConvertibleConstraintNode)
965 {
966 }
967
968 ExplicitlyConvertibleConstraintNode::ExplicitlyConvertibleConstraintNode(const Span& span_) : IntrinsicConstraintNode(NodeType::explicitlyConvertibleConstraintNode)
969 {
970 }
971
972 void ExplicitlyConvertibleConstraintNode::Accept(Visitor& visitor)
973 {
974 visitor.Visit(*this);
975 }
976
977 Node* ExplicitlyConvertibleConstraintNode::Clone(CloneContext& cloneContext) const
978 {
979 return new ExplicitlyConvertibleConstraintNode();
980 }
981
982 CommonConstraintNode::CommonConstraintNode() : IntrinsicConstraintNode(NodeType::commonConstraintNode)
983 {
984 }
985
986 CommonConstraintNode::CommonConstraintNode(const Span& span_) : IntrinsicConstraintNode(NodeType::commonConstraintNode)
987 {
988 }
989
990 void CommonConstraintNode::Accept(Visitor& visitor)
991 {
992 visitor.Visit(*this);
993 }
994
995 Node* CommonConstraintNode::Clone(CloneContext& cloneContext) const
996 {
997 return new CommonConstraintNode();
998 }
999
1000 NonreferenceTypeConstraintNode::NonreferenceTypeConstraintNode() : IntrinsicConstraintNode(NodeType::nonreferenceTypeConstraintNode)
1001 {
1002 }
1003
1004 NonreferenceTypeConstraintNode::NonreferenceTypeConstraintNode(const Span& span_) : IntrinsicConstraintNode(NodeType::nonreferenceTypeConstraintNode)
1005 {
1006 }
1007
1008 void NonreferenceTypeConstraintNode::Accept(Visitor& visitor)
1009 {
1010 visitor.Visit(*this);
1011 }
1012
1013 Node* NonreferenceTypeConstraintNode::Clone(CloneContext& cloneContext) const
1014 {
1015 return new NonreferenceTypeConstraintNode();
1016 }
1017
1018 SameConceptNode::SameConceptNode() : ConceptNode(NodeType::sameConceptNode, Span(), Specifiers::public_, new IdentifierNode(Span(), U"Same"))
1019 {
1020 AddTypeParameter(new IdentifierNode(Span(), U"T"));
1021 AddTypeParameter(new IdentifierNode(Span(), U"U"));
1022 AddConstraint(new SameConstraintNode());
1023 }
1024
1025 SameConceptNode::SameConceptNode(const Span& span_) : ConceptNode(NodeType::sameConceptNode, span_)
1026 {
1027 }
1028
1029 DerivedConceptNode::DerivedConceptNode() : ConceptNode(NodeType::derivedConceptNode, Span(), Specifiers::public_, new IdentifierNode(Span(), U"Derived"))
1030 {
1031 AddTypeParameter(new IdentifierNode(Span(), U"T"));
1032 AddTypeParameter(new IdentifierNode(Span(), U"U"));
1033 AddConstraint(new DerivedConstraintNode());
1034 }
1035
1036 DerivedConceptNode::DerivedConceptNode(const Span& span_) : ConceptNode(NodeType::derivedConceptNode, span_)
1037 {
1038 }
1039
1040 ConvertibleConceptNode::ConvertibleConceptNode() : ConceptNode(NodeType::convertibleConceptNode, Span(), Specifiers::public_, new IdentifierNode(Span(), U"Convertible"))
1041 {
1042 AddTypeParameter(new IdentifierNode(Span(), U"T"));
1043 AddTypeParameter(new IdentifierNode(Span(), U"U"));
1044 AddConstraint(new ConvertibleConstraintNode());
1045 }
1046
1047 ConvertibleConceptNode::ConvertibleConceptNode(const Span& span_) : ConceptNode(NodeType::convertibleConceptNode, span_)
1048 {
1049 }
1050
1051 ExplicitlyConvertibleConceptNode::ExplicitlyConvertibleConceptNode() :
1052 ConceptNode(NodeType::explicitlyConvertibleConceptNode, Span(), Specifiers::public_, new IdentifierNode(Span(), U"ExplicitlyConvertible"))
1053 {
1054 AddTypeParameter(new IdentifierNode(Span(), U"T"));
1055 AddTypeParameter(new IdentifierNode(Span(), U"U"));
1056 AddConstraint(new ExplicitlyConvertibleConstraintNode());
1057 }
1058
1059 ExplicitlyConvertibleConceptNode::ExplicitlyConvertibleConceptNode(const Span& span_) : ConceptNode(NodeType::explicitlyConvertibleConceptNode, span_)
1060 {
1061 }
1062
1063 CommonConceptNode::CommonConceptNode() : ConceptNode(NodeType::commonConceptNode, Span(), Specifiers::public_, new IdentifierNode(Span(), U"Common"))
1064 {
1065 AddTypeParameter(new IdentifierNode(Span(), U"T"));
1066 AddTypeParameter(new IdentifierNode(Span(), U"U"));
1067 AddConstraint(new CommonConstraintNode());
1068 }
1069
1070 CommonConceptNode::CommonConceptNode(const Span& span_) : ConceptNode(NodeType::commonConceptNode, span_)
1071 {
1072 }
1073
1074 NonreferenceTypeConceptNode::NonreferenceTypeConceptNode() : ConceptNode(NodeType::nonreferenceTypeConceptNode, Span(), Specifiers::public_, new IdentifierNode(Span(), U"NonreferenceType"))
1075 {
1076 AddTypeParameter(new IdentifierNode(Span(), U"T"));
1077 AddConstraint(new NonreferenceTypeConstraintNode());
1078 }
1079
1080 NonreferenceTypeConceptNode::NonreferenceTypeConceptNode(const Span& span_) : ConceptNode(NodeType::nonreferenceTypeConceptNode, span_)
1081 {
1082 }
1083
1084 } }