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_);
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, uint64_t value, bool unsignedSuffix);
26 LiteralNode* CreateFloatingLiteralNode(const Span& span, double value, bool float_);
27 LiteralNode* CreateCharacterLiteralNode(const Span& span, char32_t value, int chrLitPrefix);
28 LiteralNode* CreateStringLiteralNode(const Span& span, const std::u32string& value, int strLitPrefix);
29
30 class BooleanLiteralNode : public LiteralNode
31 {
32 public:
33 BooleanLiteralNode(const Span& span_);
34 BooleanLiteralNode(const Span& span_, 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_);
49 SByteLiteralNode(const Span& span_, 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_);
64 ByteLiteralNode(const Span& span_, 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_);
79 ShortLiteralNode(const Span& span_, 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_);
94 UShortLiteralNode(const Span& span_, 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_);
109 IntLiteralNode(const Span& span_, 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 private:
117 int32_t value;
118 };
119
120 class UIntLiteralNode : public LiteralNode
121 {
122 public:
123 UIntLiteralNode(const Span& span_);
124 UIntLiteralNode(const Span& span_, uint32_t value_);
125 Node* Clone(CloneContext& cloneContext) const override;
126 void Accept(Visitor& visitor) override;
127 void Write(AstWriter& writer) override;
128 void Read(AstReader& reader) override;
129 std::string ToString() const override;
130 uint32_t Value() const { return value; }
131 private:
132 uint32_t value;
133 };
134
135 class LongLiteralNode : public LiteralNode
136 {
137 public:
138 LongLiteralNode(const Span& span_);
139 LongLiteralNode(const Span& span_, int64_t value_);
140 Node* Clone(CloneContext& cloneContext) const override;
141 void Accept(Visitor& visitor) override;
142 void Write(AstWriter& writer) override;
143 void Read(AstReader& reader) override;
144 std::string ToString() const override;
145 int64_t Value() const { return value; }
146 private:
147 int64_t value;
148 };
149
150 class ULongLiteralNode : public LiteralNode
151 {
152 public:
153 ULongLiteralNode(const Span& span_);
154 ULongLiteralNode(const Span& span_, uint64_t value_);
155 Node* Clone(CloneContext& cloneContext) const override;
156 void Accept(Visitor& visitor) override;
157 void Write(AstWriter& writer) override;
158 void Read(AstReader& reader) override;
159 std::string ToString() const override;
160 uint64_t Value() const { return value; }
161 private:
162 uint64_t value;
163 };
164
165 class FloatLiteralNode : public LiteralNode
166 {
167 public:
168 FloatLiteralNode(const Span& span_);
169 FloatLiteralNode(const Span& span_, float value_);
170 Node* Clone(CloneContext& cloneContext) const override;
171 void Accept(Visitor& visitor) override;
172 void Write(AstWriter& writer) override;
173 void Read(AstReader& reader) override;
174 std::string ToString() const override;
175 float Value() const { return value; }
176 private:
177 float value;
178 };
179
180 class DoubleLiteralNode : public LiteralNode
181 {
182 public:
183 DoubleLiteralNode(const Span& span_);
184 DoubleLiteralNode(const Span& span_, double value_);
185 Node* Clone(CloneContext& cloneContext) const override;
186 void Accept(Visitor& visitor) override;
187 void Write(AstWriter& writer) override;
188 void Read(AstReader& reader) override;
189 std::string ToString() const override;
190 double Value() const { return value; }
191 private:
192 double value;
193 };
194
195 class CharLiteralNode : public LiteralNode
196 {
197 public:
198 CharLiteralNode(const Span& span_);
199 CharLiteralNode(const Span& span_, char value_);
200 Node* Clone(CloneContext& cloneContext) const override;
201 void Accept(Visitor& visitor) override;
202 void Write(AstWriter& writer) override;
203 void Read(AstReader& reader) override;
204 std::string ToString() const override;
205 char Value() const { return value; }
206 private:
207 char value;
208 };
209
210 class WCharLiteralNode : public LiteralNode
211 {
212 public:
213 WCharLiteralNode(const Span& span_);
214 WCharLiteralNode(const Span& span_, char16_t value_);
215 Node* Clone(CloneContext& cloneContext) const override;
216 void Accept(Visitor& visitor) override;
217 void Write(AstWriter& writer) override;
218 void Read(AstReader& reader) override;
219 std::string ToString() const override;
220 char16_t Value() const { return value; }
221 private:
222 char16_t value;
223 };
224
225 class UCharLiteralNode : public LiteralNode
226 {
227 public:
228 UCharLiteralNode(const Span& span_);
229 UCharLiteralNode(const Span& span_, char32_t value_);
230 Node* Clone(CloneContext& cloneContext) const override;
231 void Accept(Visitor& visitor) override;
232 void Write(AstWriter& writer) override;
233 void Read(AstReader& reader) override;
234 std::string ToString() const override;
235 char32_t Value() const { return value; }
236 private:
237 char32_t value;
238 };
239
240 class StringLiteralNode : public LiteralNode
241 {
242 public:
243 StringLiteralNode(const Span& span_);
244 StringLiteralNode(const Span& span_, const std::string& value_);
245 Node* Clone(CloneContext& cloneContext) const override;
246 void Accept(Visitor& visitor) override;
247 void Write(AstWriter& writer) override;
248 void Read(AstReader& reader) override;
249 std::string ToString() const override;
250 const std::string& Value() const { return value; }
251 private:
252 std::string value;
253 };
254
255 class WStringLiteralNode : public LiteralNode
256 {
257 public:
258 WStringLiteralNode(const Span& span_);
259 WStringLiteralNode(const Span& span_, const std::u16string& value_);
260 Node* Clone(CloneContext& cloneContext) const override;
261 void Accept(Visitor& visitor) override;
262 void Write(AstWriter& writer) override;
263 void Read(AstReader& reader) override;
264 std::string ToString() const override;
265 const std::u16string& Value() const { return value; }
266 private:
267 std::u16string value;
268 };
269
270 class UStringLiteralNode : public LiteralNode
271 {
272 public:
273 UStringLiteralNode(const Span& span_);
274 UStringLiteralNode(const Span& span_, const std::u32string& value_);
275 Node* Clone(CloneContext& cloneContext) const override;
276 void Accept(Visitor& visitor) override;
277 void Write(AstWriter& writer) override;
278 void Read(AstReader& reader) override;
279 std::string ToString() const override;
280 const std::u32string& Value() const { return value; }
281 private:
282 std::u32string value;
283 };
284
285 class NullLiteralNode : public LiteralNode
286 {
287 public:
288 NullLiteralNode(const Span& span_);
289 Node* Clone(CloneContext& cloneContext) const override;
290 void Accept(Visitor& visitor) override;
291 std::string ToString() const override { return "null"; }
292 };
293
294 class ArrayLiteralNode : public LiteralNode
295 {
296 public:
297 ArrayLiteralNode(const Span& span_);
298 Node* Clone(CloneContext& cloneContext) const override;
299 void Accept(Visitor& visitor) override;
300 void Write(AstWriter& writer) override;
301 void Read(AstReader& reader) override;
302 std::string ToString() const override { return "array"; }
303 void AddValue(Node* value);
304 const NodeList<Node>& Values() const { return values; }
305 NodeList<Node>& Values() { return values; }
306 private:
307 NodeList<Node> values;
308 };
309
310 class StructuredLiteralNode : public LiteralNode
311 {
312 public:
313 StructuredLiteralNode(const Span& span_);
314 Node* Clone(CloneContext& cloneContext) const override;
315 void Accept(Visitor& visitor) override;
316 void Write(AstWriter& writer) override;
317 void Read(AstReader& reader) override;
318 std::string ToString() const override { return "structure"; }
319 void AddMember(Node* member);
320 const NodeList<Node>& Members() const { return members; }
321 NodeList<Node>& Members() { return members; }
322 private:
323 NodeList<Node> members;
324 };
325
326 class UuidLiteralNode : public LiteralNode
327 {
328 public:
329 UuidLiteralNode(const Span& span_);
330 UuidLiteralNode(const Span& span_, const boost::uuids::uuid& uuid_);
331 Node* Clone(CloneContext& cloneContext) const override;
332 void Accept(Visitor& visitor) override;
333 void Write(AstWriter& writer) override;
334 void Read(AstReader& reader) override;
335 std::string ToString() const override { return "uuid"; }
336 const boost::uuids::uuid& GetUuid() const { return uuid; }
337 private:
338 boost::uuids::uuid uuid;
339 };
340
341 } }
342
343 #endif // SNGCM_AST_LITERAL_INCLUDED