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_, const boost::uuids::uuid& moduleId_) : Node(NodeType::delegateNode, span_, moduleId_), specifiers(Specifiers::none), returnTypeExpr(), id(), parameters()
13 {
14 }
15
16 DelegateNode::DelegateNode(const Span& span_, const boost::uuids::uuid& moduleId_, Specifiers specifiers_, Node* returnTypeExpr_, IdentifierNode* id_) :
17 Node(NodeType::delegateNode, span_, moduleId_), 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(), ModuleId(), 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_, const boost::uuids::uuid& moduleId_) :
67 Node(NodeType::classDelegateNode, span_, moduleId_), specifiers(Specifiers::none), returnTypeExpr(), id(), parameters()
68 {
69 }
70
71 ClassDelegateNode::ClassDelegateNode(const Span& span_, const boost::uuids::uuid& moduleId_, Specifiers specifiers_, Node* returnTypeExpr_, IdentifierNode* id_) :
72 Node(NodeType::classDelegateNode, span_, moduleId_), specifiers(specifiers_), returnTypeExpr(returnTypeExpr_), id(id_), parameters()
73 {
74 returnTypeExpr->SetParent(this);
75 id->SetParent(this);
76 }
77
78 Node* ClassDelegateNode::Clone(CloneContext& cloneContext) const
79 {
80 ClassDelegateNode* clone = new ClassDelegateNode(GetSpan(), ModuleId(), specifiers, returnTypeExpr->Clone(cloneContext), static_cast<IdentifierNode*>(id->Clone(cloneContext)));
81 int n = parameters.Count();
82 for (int i = 0; i < n; ++i)
83 {
84 clone->AddParameter(static_cast<ParameterNode*>(parameters[i]->Clone(cloneContext)));
85 }
86 return clone;
87 }
88
89 void ClassDelegateNode::Accept(Visitor& visitor)
90 {
91 visitor.Visit(*this);
92 }
93
94 void ClassDelegateNode::Write(AstWriter& writer)
95 {
96 Node::Write(writer);
97 writer.Write(specifiers);
98 writer.Write(returnTypeExpr.get());
99 writer.Write(id.get());
100 parameters.Write(writer);
101 }
102
103 void ClassDelegateNode::Read(AstReader& reader)
104 {
105 Node::Read(reader);
106 specifiers = reader.ReadSpecifiers();
107 returnTypeExpr.reset(reader.ReadNode());
108 returnTypeExpr->SetParent(this);
109 id.reset(reader.ReadIdentifierNode());
110 id->SetParent(this);
111 parameters.Read(reader);
112 parameters.SetParent(this);
113 }
114
115 void ClassDelegateNode::AddParameter(ParameterNode* parameter)
116 {
117 parameter->SetParent(this);
118 parameters.Add(parameter);
119 }
120
121 } }