1
2
3
4
5
6 #include <sngcm/ast/Delegate.hpp>
7 #include <sngcm/ast/Identifier.hpp>
8 #include <sngcm/ast/Visitor.hpp>
9
10 namespace sngcm { namespace ast {
11
12 DelegateNode::DelegateNode(const Span& span_) : Node(NodeType::delegateNode, span_), specifiers(Specifiers::none), returnTypeExpr(), id(), parameters()
13 {
14 }
15
16 DelegateNode::DelegateNode(const Span& span_, Specifiers specifiers_, Node* returnTypeExpr_, IdentifierNode* id_) :
17 Node(NodeType::delegateNode, span_), specifiers(specifiers_), returnTypeExpr(returnTypeExpr_), id(id_), parameters()
18 {
19 returnTypeExpr->SetParent(this);
20 id->SetParent(this);
21 }
22
23 Node* DelegateNode::Clone(CloneContext& cloneContext) const
24 {
25 DelegateNode* clone = new DelegateNode(GetSpan(), specifiers, returnTypeExpr->Clone(cloneContext), static_cast<IdentifierNode*>(id->Clone(cloneContext)));
26 int n = parameters.Count();
27 for (int i = 0; i < n; ++i)
28 {
29 clone->AddParameter(static_cast<ParameterNode*>(parameters[i]->Clone(cloneContext)));
30 }
31 return clone;
32 }
33
34 void DelegateNode::Accept(Visitor& visitor)
35 {
36 visitor.Visit(*this);
37 }
38
39 void DelegateNode::Write(AstWriter& writer)
40 {
41 Node::Write(writer);
42 writer.Write(specifiers);
43 writer.Write(returnTypeExpr.get());
44 writer.Write(id.get());
45 parameters.Write(writer);
46 }
47
48 void DelegateNode::Read(AstReader& reader)
49 {
50 Node::Read(reader);
51 specifiers = reader.ReadSpecifiers();
52 returnTypeExpr.reset(reader.ReadNode());
53 returnTypeExpr->SetParent(this);
54 id.reset(reader.ReadIdentifierNode());
55 id->SetParent(this);
56 parameters.Read(reader);
57 parameters.SetParent(this);
58 }
59
60 void DelegateNode::AddParameter(ParameterNode* parameter)
61 {
62 parameter->SetParent(this);
63 parameters.Add(parameter);
64 }
65
66 ClassDelegateNode::ClassDelegateNode(const Span& span_) : Node(NodeType::classDelegateNode, span_), specifiers(Specifiers::none), returnTypeExpr(), id(), parameters()
67 {
68 }
69
70 ClassDelegateNode::ClassDelegateNode(const Span& span_, Specifiers specifiers_, Node* returnTypeExpr_, IdentifierNode* id_) :
71 Node(NodeType::classDelegateNode, span_), specifiers(specifiers_), returnTypeExpr(returnTypeExpr_), id(id_), parameters()
72 {
73 returnTypeExpr->SetParent(this);
74 id->SetParent(this);
75 }
76
77 Node* ClassDelegateNode::Clone(CloneContext& cloneContext) const
78 {
79 ClassDelegateNode* clone = new ClassDelegateNode(GetSpan(), specifiers, returnTypeExpr->Clone(cloneContext), static_cast<IdentifierNode*>(id->Clone(cloneContext)));
80 int n = parameters.Count();
81 for (int i = 0; i < n; ++i)
82 {
83 clone->AddParameter(static_cast<ParameterNode*>(parameters[i]->Clone(cloneContext)));
84 }
85 return clone;
86 }
87
88 void ClassDelegateNode::Accept(Visitor& visitor)
89 {
90 visitor.Visit(*this);
91 }
92
93 void ClassDelegateNode::Write(AstWriter& writer)
94 {
95 Node::Write(writer);
96 writer.Write(specifiers);
97 writer.Write(returnTypeExpr.get());
98 writer.Write(id.get());
99 parameters.Write(writer);
100 }
101
102 void ClassDelegateNode::Read(AstReader& reader)
103 {
104 Node::Read(reader);
105 specifiers = reader.ReadSpecifiers();
106 returnTypeExpr.reset(reader.ReadNode());
107 returnTypeExpr->SetParent(this);
108 id.reset(reader.ReadIdentifierNode());
109 id->SetParent(this);
110 parameters.Read(reader);
111 parameters.SetParent(this);
112 }
113
114 void ClassDelegateNode::AddParameter(ParameterNode* parameter)
115 {
116 parameter->SetParent(this);
117 parameters.Add(parameter);
118 }
119
120 } }