1
2
3
4
5
6 #include <sngcpp/ast/Template.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 TypeParameterNode::TypeParameterNode() : Node(NodeType::typeParameterNode)
14 {
15 }
16
17 TypeParameterNode::TypeParameterNode(const Span& span_, const std::u32string& id_, Node* defaultTemplateParameter_, bool typenameUsed_) :
18 Node(NodeType::typeParameterNode, span_), id(id_), defaultTemplateParameter(defaultTemplateParameter_), typenameUsed(typenameUsed_)
19 {
20 }
21
22 void TypeParameterNode::Accept(Visitor& visitor)
23 {
24 visitor.Visit(*this);
25 }
26
27 void TypeParameterNode::Write(Writer& writer)
28 {
29 Node::Write(writer);
30 writer.GetBinaryWriter().Write(id);
31 writer.GetBinaryWriter().Write(defaultTemplateParameter != nullptr);
32 if (defaultTemplateParameter)
33 {
34 defaultTemplateParameter->Write(writer);
35 }
36 writer.GetBinaryWriter().Write(typenameUsed);
37 }
38
39 void TypeParameterNode::Read(Reader& reader)
40 {
41 Node::Read(reader);
42 id = reader.GetBinaryReader().ReadUtf32String();
43 bool hasDefault = reader.GetBinaryReader().ReadBool();
44 if (hasDefault)
45 {
46 defaultTemplateParameter.reset(reader.ReadNode());
47 }
48 typenameUsed = reader.GetBinaryReader().ReadBool();
49 }
50
51 TemplateParameterSequenceNode::TemplateParameterSequenceNode() : BinaryNode(NodeType::templateParameterSequenceNode)
52 {
53 }
54
55 TemplateParameterSequenceNode::TemplateParameterSequenceNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::templateParameterSequenceNode, span_, left_, right_)
56 {
57 }
58
59 void TemplateParameterSequenceNode::Accept(Visitor& visitor)
60 {
61 visitor.Visit(*this);
62 }
63
64 TemplateDeclarationNode::TemplateDeclarationNode() : Node(NodeType::templateDeclarationNode)
65 {
66 }
67
68 TemplateDeclarationNode::TemplateDeclarationNode(const Span& span_, Node* templateParameters_, Node* declaration_) :
69 Node(NodeType::templateDeclarationNode, span_), templateParameters(templateParameters_), declaration(declaration_)
70 {
71 }
72
73 void TemplateDeclarationNode::Accept(Visitor& visitor)
74 {
75 visitor.Visit(*this);
76 }
77
78 void TemplateDeclarationNode::Write(Writer& writer)
79 {
80 Node::Write(writer);
81 templateParameters->Write(writer);
82 declaration->Write(writer);
83 }
84
85 void TemplateDeclarationNode::Read(Reader& reader)
86 {
87 Node::Read(reader);
88 templateParameters.reset(reader.ReadNode());
89 declaration.reset(reader.ReadNode());
90 }
91
92 TemplateArgumentSequenceNode::TemplateArgumentSequenceNode() : BinaryNode(NodeType::templateArgumentSequenceNode)
93 {
94 }
95
96 TemplateArgumentSequenceNode::TemplateArgumentSequenceNode(const Span& span_, Node* left_, Node* right_) : BinaryNode(NodeType::templateArgumentSequenceNode, span_, left_, right_)
97 {
98 }
99
100 void TemplateArgumentSequenceNode::Accept(Visitor& visitor)
101 {
102 visitor.Visit(*this);
103 }
104
105 TemplateIdNode::TemplateIdNode() : Node(NodeType::templateIdNode), arity(0)
106 {
107 }
108
109 TemplateIdNode::TemplateIdNode(const Span& span_, IdentifierNode* id_, Node* templateArguments_, int arity_) :
110 Node(NodeType::templateIdNode, span_), id(id_), templateArguments(templateArguments_), arity(arity_)
111 {
112 }
113
114 void TemplateIdNode::Accept(Visitor& visitor)
115 {
116 visitor.Visit(*this);
117 }
118
119 void TemplateIdNode::Write(Writer& writer)
120 {
121 Node::Write(writer);
122 id->Write(writer);
123 bool hasTemplateArguments = templateArguments != nullptr;
124 writer.GetBinaryWriter().Write(hasTemplateArguments);
125 if (hasTemplateArguments)
126 {
127 templateArguments->Write(writer);
128 }
129 writer.GetBinaryWriter().Write(int32_t(arity));
130 }
131
132 void TemplateIdNode::Read(Reader& reader)
133 {
134 Node::Read(reader);
135 id.reset(reader.ReadIdentifierNode());
136 bool hasTemplateArguments = reader.GetBinaryReader().ReadBool();
137 if (hasTemplateArguments)
138 {
139 templateArguments.reset(reader.ReadNode());
140 }
141 arity = reader.GetBinaryReader().ReadInt();
142 }
143
144 TemplateArgumentNode::TemplateArgumentNode() : Node(NodeType::templateArgumentNode)
145 {
146 }
147
148 TemplateArgumentNode::TemplateArgumentNode(const Span& span_, Node* arg_) : Node(NodeType::templateArgumentNode, span_), arg(arg_)
149 {
150 }
151
152 void TemplateArgumentNode::Accept(Visitor& visitor)
153 {
154 visitor.Visit(*this);
155 }
156
157 void TemplateArgumentNode::Write(Writer& writer)
158 {
159 Node::Write(writer);
160 arg->Write(writer);
161 }
162
163 void TemplateArgumentNode::Read(Reader& reader)
164 {
165 Node::Read(reader);
166 arg.reset(reader.ReadNode());
167 }
168
169 ExplicitInstantiationNode::ExplicitInstantiationNode() : UnaryNode(NodeType::explicitInstantiationNode)
170 {
171 }
172
173 ExplicitInstantiationNode::ExplicitInstantiationNode(const Span& span_, Node* declaration_) : UnaryNode(NodeType::explicitInstantiationNode, span_, declaration_)
174 {
175 }
176
177 void ExplicitInstantiationNode::Accept(Visitor& visitor)
178 {
179 visitor.Visit(*this);
180 }
181
182 ExplicitSpecializationNode::ExplicitSpecializationNode() : UnaryNode(NodeType::explicitSpecializationNode)
183 {
184 }
185
186 ExplicitSpecializationNode::ExplicitSpecializationNode(const Span& span_, Node* declaration_) : UnaryNode(NodeType::explicitSpecializationNode, span_, declaration_)
187 {
188 }
189
190 void ExplicitSpecializationNode::Accept(Visitor& visitor)
191 {
192 visitor.Visit(*this);
193 }
194
195 } }