1
2
3
4
5
6 #ifndef SNGCM_AST_LITERAL_INCLUDED
7 #define SNGCM_AST_LITERAL_INCLUDED
8 #include <sngcm/ast/Node.hpp>
9 #include <sngcm/ast/NodeList.hpp>
10
11 namespace sngcm { namespace ast {
12
13 class LiteralNode : public Node
14 {
15 public:
16 LiteralNode(NodeType nodeType_, const Span& span_, const boost::uuids::uuid& moduleId_);
17 void Write(AstWriter& writer) override;
18 void Read(AstReader& reader) override;
19 void SetText(const std::u32string& text_);
20 const std::u32string& Text() const { return text; }
21 private:
22 std::u32string text;
23 };
24
25 LiteralNode* CreateIntegerLiteralNode(const Span& span, const boost::uuids::uuid& moduleId, uint64_t value, bool unsignedSuffix);
26 LiteralNode* CreateFloatingLiteralNode(const Span& span, const boost::uuids::uuid& moduleId, double value, bool float_);
27 LiteralNode* CreateCharacterLiteralNode(const Span& span, const boost::uuids::uuid& moduleId, char32_t value, int chrLitPrefix);
28 LiteralNode* CreateStringLiteralNode(const Span& span, const boost::uuids::uuid& moduleId, const std::u32string& value, int strLitPrefix);
29
30 class BooleanLiteralNode : public LiteralNode
31 {
32 public:
33 BooleanLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_);
34 BooleanLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_, bool value_);
35 Node* Clone(CloneContext& cloneContext) const override;
36 void Accept(Visitor& visitor) override;
37 void Write(AstWriter& writer) override;
38 void Read(AstReader& reader) override;
39 std::string ToString() const override;
40 bool Value() const { return value; }
41 private:
42 bool value;
43 };
44
45 class SByteLiteralNode : public LiteralNode
46 {
47 public:
48 SByteLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_);
49 SByteLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_, int8_t value_);
50 Node* Clone(CloneContext& cloneContext) const override;
51 void Accept(Visitor& visitor) override;
52 void Write(AstWriter& writer) override;
53 void Read(AstReader& reader) override;
54 std::string ToString() const override;
55 int8_t Value() const { return value; }
56 private:
57 int8_t value;
58 };
59
60 class ByteLiteralNode : public LiteralNode
61 {
62 public:
63 ByteLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_);
64 ByteLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_, uint8_t value_);
65 Node* Clone(CloneContext& cloneContext) const override;
66 void Accept(Visitor& visitor) override;
67 void Write(AstWriter& writer) override;
68 void Read(AstReader& reader) override;
69 std::string ToString() const override;
70 uint8_t Value() const { return value; }
71 private:
72 uint8_t value;
73 };
74
75 class ShortLiteralNode : public LiteralNode
76 {
77 public:
78 ShortLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_);
79 ShortLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_, int16_t value_);
80 Node* Clone(CloneContext& cloneContext) const override;
81 void Accept(Visitor& visitor) override;
82 void Write(AstWriter& writer) override;
83 void Read(AstReader& reader) override;
84 std::string ToString() const override;
85 int16_t Value() const { return value; }
86 private:
87 int16_t value;
88 };
89
90 class UShortLiteralNode : public LiteralNode
91 {
92 public:
93 UShortLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_);
94 UShortLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_, uint16_t value_);
95 Node* Clone(CloneContext& cloneContext) const override;
96 void Accept(Visitor& visitor) override;
97 void Write(AstWriter& writer) override;
98 void Read(AstReader& reader) override;
99 std::string ToString() const override;
100 uint16_t Value() const { return value; }
101 private:
102 uint16_t value;
103 };
104
105 class IntLiteralNode : public LiteralNode
106 {
107 public:
108 IntLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_);
109 IntLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_, int32_t value_);
110 Node* Clone(CloneContext& cloneContext) const override;
111 void Accept(Visitor& visitor) override;
112 void Write(AstWriter& writer) override;
113 void Read(AstReader& reader) override;
114 std::string ToString() const override;
115 int32_t Value() const { return value; }
116 void SetValue(int32_t value_) { value = value_; }
117 private:
118 int32_t value;
119 };
120
121 class UIntLiteralNode : public LiteralNode
122 {
123 public:
124 UIntLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_);
125 UIntLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_, uint32_t value_);
126 Node* Clone(CloneContext& cloneContext) const override;
127 void Accept(Visitor& visitor) override;
128 void Write(AstWriter& writer) override;
129 void Read(AstReader& reader) override;
130 std::string ToString() const override;
131 uint32_t Value() const { return value; }
132 private:
133 uint32_t value;
134 };
135
136 class LongLiteralNode : public LiteralNode
137 {
138 public:
139 LongLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_);
140 LongLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_, int64_t value_);
141 Node* Clone(CloneContext& cloneContext) const override;
142 void Accept(Visitor& visitor) override;
143 void Write(AstWriter& writer) override;
144 void Read(AstReader& reader) override;
145 std::string ToString() const override;
146 int64_t Value() const { return value; }
147 private:
148 int64_t value;
149 };
150
151 class ULongLiteralNode : public LiteralNode
152 {
153 public:
154 ULongLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_);
155 ULongLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_, uint64_t value_);
156 Node* Clone(CloneContext& cloneContext) const override;
157 void Accept(Visitor& visitor) override;
158 void Write(AstWriter& writer) override;
159 void Read(AstReader& reader) override;
160 std::string ToString() const override;
161 uint64_t Value() const { return value; }
162 private:
163 uint64_t value;
164 };
165
166 class FloatLiteralNode : public LiteralNode
167 {
168 public:
169 FloatLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_);
170 FloatLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_, float value_);
171 Node* Clone(CloneContext& cloneContext) const override;
172 void Accept(Visitor& visitor) override;
173 void Write(AstWriter& writer) override;
174 void Read(AstReader& reader) override;
175 std::string ToString() const override;
176 float Value() const { return value; }
177 private:
178 float value;
179 };
180
181 class DoubleLiteralNode : public LiteralNode
182 {
183 public:
184 DoubleLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_);
185 DoubleLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_, double value_);
186 Node* Clone(CloneContext& cloneContext) const override;
187 void Accept(Visitor& visitor) override;
188 void Write(AstWriter& writer) override;
189 void Read(AstReader& reader) override;
190 std::string ToString() const override;
191 double Value() const { return value; }
192 private:
193 double value;
194 };
195
196 class CharLiteralNode : public LiteralNode
197 {
198 public:
199 CharLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_);
200 CharLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_, char value_);
201 Node* Clone(CloneContext& cloneContext) const override;
202 void Accept(Visitor& visitor) override;
203 void Write(AstWriter& writer) override;
204 void Read(AstReader& reader) override;
205 std::string ToString() const override;
206 char Value() const { return value; }
207 private:
208 char value;
209 };
210
211 class WCharLiteralNode : public LiteralNode
212 {
213 public:
214 WCharLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_);
215 WCharLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_, char16_t value_);
216 Node* Clone(CloneContext& cloneContext) const override;
217 void Accept(Visitor& visitor) override;
218 void Write(AstWriter& writer) override;
219 void Read(AstReader& reader) override;
220 std::string ToString() const override;
221 char16_t Value() const { return value; }
222 private:
223 char16_t value;
224 };
225
226 class UCharLiteralNode : public LiteralNode
227 {
228 public:
229 UCharLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_);
230 UCharLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_, char32_t value_);
231 Node* Clone(CloneContext& cloneContext) const override;
232 void Accept(Visitor& visitor) override;
233 void Write(AstWriter& writer) override;
234 void Read(AstReader& reader) override;
235 std::string ToString() const override;
236 char32_t Value() const { return value; }
237 private:
238 char32_t value;
239 };
240
241 class StringLiteralNode : public LiteralNode
242 {
243 public:
244 StringLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_);
245 StringLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_, const std::string& value_);
246 Node* Clone(CloneContext& cloneContext) const override;
247 void Accept(Visitor& visitor) override;
248 void Write(AstWriter& writer) override;
249 void Read(AstReader& reader) override;
250 std::string ToString() const override;
251 const std::string& Value() const { return value; }
252 private:
253 std::string value;
254 };
255
256 class WStringLiteralNode : public LiteralNode
257 {
258 public:
259 WStringLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_);
260 WStringLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_, const std::u16string& value_);
261 Node* Clone(CloneContext& cloneContext) const override;
262 void Accept(Visitor& visitor) override;
263 void Write(AstWriter& writer) override;
264 void Read(AstReader& reader) override;
265 std::string ToString() const override;
266 const std::u16string& Value() const { return value; }
267 private:
268 std::u16string value;
269 };
270
271 class UStringLiteralNode : public LiteralNode
272 {
273 public:
274 UStringLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_);
275 UStringLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_, const std::u32string& value_);
276 Node* Clone(CloneContext& cloneContext) const override;
277 void Accept(Visitor& visitor) override;
278 void Write(AstWriter& writer) override;
279 void Read(AstReader& reader) override;
280 std::string ToString() const override;
281 const std::u32string& Value() const { return value; }
282 private:
283 std::u32string value;
284 };
285
286 class NullLiteralNode : public LiteralNode
287 {
288 public:
289 NullLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_);
290 Node* Clone(CloneContext& cloneContext) const override;
291 void Accept(Visitor& visitor) override;
292 std::string ToString() const override { return "null"; }
293 };
294
295 class ArrayLiteralNode : public LiteralNode
296 {
297 public:
298 ArrayLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_);
299 Node* Clone(CloneContext& cloneContext) const override;
300 void Accept(Visitor& visitor) override;
301 void Write(AstWriter& writer) override;
302 void Read(AstReader& reader) override;
303 std::string ToString() const override { return "array"; }
304 void AddValue(Node* value);
305 const NodeList<Node>& Values() const { return values; }
306 NodeList<Node>& Values() { return values; }
307 private:
308 NodeList<Node> values;
309 };
310
311 class StructuredLiteralNode : public LiteralNode
312 {
313 public:
314 StructuredLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_);
315 Node* Clone(CloneContext& cloneContext) const override;
316 void Accept(Visitor& visitor) override;
317 void Write(AstWriter& writer) override;
318 void Read(AstReader& reader) override;
319 std::string ToString() const override { return "structure"; }
320 void AddMember(Node* member);
321 const NodeList<Node>& Members() const { return members; }
322 NodeList<Node>& Members() { return members; }
323 private:
324 NodeList<Node> members;
325 };
326
327 class UuidLiteralNode : public LiteralNode
328 {
329 public:
330 UuidLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_);
331 UuidLiteralNode(const Span& span_, const boost::uuids::uuid& moduleId_, const boost::uuids::uuid& uuid_);
332 Node* Clone(CloneContext& cloneContext) const override;
333 void Accept(Visitor& visitor) override;
334 void Write(AstWriter& writer) override;
335 void Read(AstReader& reader) override;
336 std::string ToString() const override { return "uuid"; }
337 const boost::uuids::uuid& GetUuid() const { return uuid; }
338 private:
339 boost::uuids::uuid uuid;
340 };
341
342 } }
343
344 #endif // SNGCM_AST_LITERAL_INCLUDED