1
2
3
4
5
6 #ifndef SNGCM_AST_EXPRESSION_INCLUDED
7 #define SNGCM_AST_EXPRESSION_INCLUDED
8 #include <sngcm/ast/Node.hpp>
9 #include <sngcm/ast/NodeList.hpp>
10
11 namespace sngcm { namespace ast {
12
13 class DotNode : public UnaryNode
14 {
15 public:
16 DotNode(const Span& span_, const boost::uuids::uuid& moduleId_);
17 DotNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* subject_, IdentifierNode* memberId_);
18 Node* Clone(CloneContext& cloneContext) const override;
19 void Accept(Visitor& visitor) override;
20 void Write(AstWriter& writer) override;
21 void Read(AstReader& reader) override;
22 std::string ToString() const override;
23 const IdentifierNode* MemberId() const { return memberId.get(); }
24 IdentifierNode* MemberId() { return memberId.get(); }
25 private:
26 std::unique_ptr<IdentifierNode> memberId;
27 };
28
29 class ArrowNode : public UnaryNode
30 {
31 public:
32 ArrowNode(const Span& span_, const boost::uuids::uuid& moduleId_);
33 ArrowNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* subject_, IdentifierNode* memberId_);
34 Node* Clone(CloneContext& cloneContext) const override;
35 void Accept(Visitor& visitor) override;
36 void Write(AstWriter& writer) override;
37 void Read(AstReader& reader) override;
38 std::string ToString() const override;
39 const IdentifierNode* MemberId() const { return memberId.get(); }
40 IdentifierNode* MemberId() { return memberId.get(); }
41 private:
42 std::unique_ptr<IdentifierNode> memberId;
43 };
44
45 class EquivalenceNode : public BinaryNode
46 {
47 public:
48 EquivalenceNode(const Span& span_, const boost::uuids::uuid& moduleId_);
49 EquivalenceNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* left_, Node* right_);
50 Node* Clone(CloneContext& cloneContext) const override;
51 void Accept(Visitor& visitor) override;
52 std::string ToString() const override;
53 };
54
55 class ImplicationNode : public BinaryNode
56 {
57 public:
58 ImplicationNode(const Span& span_, const boost::uuids::uuid& moduleId_);
59 ImplicationNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* left_, Node* right_);
60 Node* Clone(CloneContext& cloneContext) const override;
61 void Accept(Visitor& visitor) override;
62 std::string ToString() const override;
63 };
64
65 class DisjunctionNode : public BinaryNode
66 {
67 public:
68 DisjunctionNode(const Span& span_, const boost::uuids::uuid& moduleId_);
69 DisjunctionNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* left_, Node* right_);
70 Node* Clone(CloneContext& cloneContext) const override;
71 void Accept(Visitor& visitor) override;
72 std::string ToString() const override;
73 };
74
75 class ConjunctionNode : public BinaryNode
76 {
77 public:
78 ConjunctionNode(const Span& span_, const boost::uuids::uuid& moduleId_);
79 ConjunctionNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* left_, Node* right_);
80 Node* Clone(CloneContext& cloneContext) const override;
81 void Accept(Visitor& visitor) override;
82 std::string ToString() const override;
83 };
84
85 class BitOrNode : public BinaryNode
86 {
87 public:
88 BitOrNode(const Span& span_, const boost::uuids::uuid& moduleId_);
89 BitOrNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* left_, Node* right_);
90 Node* Clone(CloneContext& cloneContext) const override;
91 void Accept(Visitor& visitor) override;
92 std::string ToString() const override;
93 };
94
95 class BitXorNode : public BinaryNode
96 {
97 public:
98 BitXorNode(const Span& span_, const boost::uuids::uuid& moduleId_);
99 BitXorNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* left_, Node* right_);
100 Node* Clone(CloneContext& cloneContext) const override;
101 void Accept(Visitor& visitor) override;
102 std::string ToString() const override;
103 };
104
105 class BitAndNode : public BinaryNode
106 {
107 public:
108 BitAndNode(const Span& span_, const boost::uuids::uuid& moduleId_);
109 BitAndNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* left_, Node* right_);
110 Node* Clone(CloneContext& cloneContext) const override;
111 void Accept(Visitor& visitor) override;
112 std::string ToString() const override;
113 };
114
115 class EqualNode : public BinaryNode
116 {
117 public:
118 EqualNode(const Span& span_, const boost::uuids::uuid& moduleId_);
119 EqualNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* left_, Node* right_);
120 Node* Clone(CloneContext& cloneContext) const override;
121 void Accept(Visitor& visitor) override;
122 std::string ToString() const override;
123 };
124
125 class NotEqualNode : public BinaryNode
126 {
127 public:
128 NotEqualNode(const Span& span_, const boost::uuids::uuid& moduleId_);
129 NotEqualNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* left_, Node* right_);
130 Node* Clone(CloneContext& cloneContext) const override;
131 void Accept(Visitor& visitor) override;
132 std::string ToString() const override;
133 };
134
135 class LessNode : public BinaryNode
136 {
137 public:
138 LessNode(const Span& span_, const boost::uuids::uuid& moduleId_);
139 LessNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* left_, Node* right_);
140 Node* Clone(CloneContext& cloneContext) const override;
141 void Accept(Visitor& visitor) override;
142 std::string ToString() const override;
143 };
144
145 class GreaterNode : public BinaryNode
146 {
147 public:
148 GreaterNode(const Span& span_, const boost::uuids::uuid& moduleId_);
149 GreaterNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* left_, Node* right_);
150 Node* Clone(CloneContext& cloneContext) const override;
151 void Accept(Visitor& visitor) override;
152 std::string ToString() const override;
153 };
154
155 class LessOrEqualNode : public BinaryNode
156 {
157 public:
158 LessOrEqualNode(const Span& span_, const boost::uuids::uuid& moduleId_);
159 LessOrEqualNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* left_, Node* right_);
160 Node* Clone(CloneContext& cloneContext) const override;
161 void Accept(Visitor& visitor) override;
162 std::string ToString() const override;
163 };
164
165 class GreaterOrEqualNode : public BinaryNode
166 {
167 public:
168 GreaterOrEqualNode(const Span& span_, const boost::uuids::uuid& moduleId_);
169 GreaterOrEqualNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* left_, Node* right_);
170 Node* Clone(CloneContext& cloneContext) const override;
171 void Accept(Visitor& visitor) override;
172 std::string ToString() const override;
173 };
174
175 class ShiftLeftNode : public BinaryNode
176 {
177 public:
178 ShiftLeftNode(const Span& span_, const boost::uuids::uuid& moduleId_);
179 ShiftLeftNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* left_, Node* right_);
180 Node* Clone(CloneContext& cloneContext) const override;
181 void Accept(Visitor& visitor) override;
182 std::string ToString() const override;
183 };
184
185 class ShiftRightNode : public BinaryNode
186 {
187 public:
188 ShiftRightNode(const Span& span_, const boost::uuids::uuid& moduleId_);
189 ShiftRightNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* left_, Node* right_);
190 Node* Clone(CloneContext& cloneContext) const override;
191 void Accept(Visitor& visitor) override;
192 std::string ToString() const override;
193 };
194
195 class AddNode : public BinaryNode
196 {
197 public:
198 AddNode(const Span& span_, const boost::uuids::uuid& moduleId_);
199 AddNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* left_, Node* right_);
200 Node* Clone(CloneContext& cloneContext) const override;
201 void Accept(Visitor& visitor) override;
202 std::string ToString() const override;
203 };
204
205 class SubNode : public BinaryNode
206 {
207 public:
208 SubNode(const Span& span_, const boost::uuids::uuid& moduleId_);
209 SubNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* left_, Node* right_);
210 Node* Clone(CloneContext& cloneContext) const override;
211 void Accept(Visitor& visitor) override;
212 std::string ToString() const override;
213 };
214
215 class MulNode : public BinaryNode
216 {
217 public:
218 MulNode(const Span& span_, const boost::uuids::uuid& moduleId_);
219 MulNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* left_, Node* right_);
220 Node* Clone(CloneContext& cloneContext) const override;
221 void Accept(Visitor& visitor) override;
222 std::string ToString() const override;
223 };
224
225 class DivNode : public BinaryNode
226 {
227 public:
228 DivNode(const Span& span_, const boost::uuids::uuid& moduleId_);
229 DivNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* left_, Node* right_);
230 Node* Clone(CloneContext& cloneContext) const override;
231 void Accept(Visitor& visitor) override;
232 std::string ToString() const override;
233 };
234
235 class RemNode : public BinaryNode
236 {
237 public:
238 RemNode(const Span& span_, const boost::uuids::uuid& moduleId_);
239 RemNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* left_, Node* right_);
240 Node* Clone(CloneContext& cloneContext) const override;
241 void Accept(Visitor& visitor) override;
242 std::string ToString() const override;
243 };
244
245 class NotNode : public UnaryNode
246 {
247 public:
248 NotNode(const Span& span_, const boost::uuids::uuid& moduleId_);
249 NotNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* subject_);
250 Node* Clone(CloneContext& cloneContext) const override;
251 void Accept(Visitor& visitor) override;
252 std::string ToString() const override;
253 };
254
255 class UnaryPlusNode : public UnaryNode
256 {
257 public:
258 UnaryPlusNode(const Span& span_, const boost::uuids::uuid& moduleId_);
259 UnaryPlusNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* subject_);
260 Node* Clone(CloneContext& cloneContext) const override;
261 void Accept(Visitor& visitor) override;
262 std::string ToString() const override;
263 };
264
265 class UnaryMinusNode : public UnaryNode
266 {
267 public:
268 UnaryMinusNode(const Span& span_, const boost::uuids::uuid& moduleId_);
269 UnaryMinusNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* subject_);
270 Node* Clone(CloneContext& cloneContext) const override;
271 void Accept(Visitor& visitor) override;
272 std::string ToString() const override;
273 };
274
275 class PrefixIncrementNode : public UnaryNode
276 {
277 public:
278 PrefixIncrementNode(const Span& span_, const boost::uuids::uuid& moduleId_);
279 PrefixIncrementNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* subject_);
280 Node* Clone(CloneContext& cloneContext) const override;
281 void Accept(Visitor& visitor) override;
282 std::string ToString() const override;
283 };
284
285 class PrefixDecrementNode : public UnaryNode
286 {
287 public:
288 PrefixDecrementNode(const Span& span_, const boost::uuids::uuid& moduleId_);
289 PrefixDecrementNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* subject_);
290 Node* Clone(CloneContext& cloneContext) const override;
291 void Accept(Visitor& visitor) override;
292 std::string ToString() const override;
293 };
294
295 class ComplementNode : public UnaryNode
296 {
297 public:
298 ComplementNode(const Span& span_, const boost::uuids::uuid& moduleId_);
299 ComplementNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* subject_);
300 Node* Clone(CloneContext& cloneContext) const override;
301 void Accept(Visitor& visitor) override;
302 std::string ToString() const override;
303 };
304
305 class DerefNode : public UnaryNode
306 {
307 public:
308 DerefNode(const Span& span_, const boost::uuids::uuid& moduleId_);
309 DerefNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* subject_);
310 Node* Clone(CloneContext& cloneContext) const override;
311 void Accept(Visitor& visitor) override;
312 std::string ToString() const override;
313 };
314
315 class AddrOfNode : public UnaryNode
316 {
317 public:
318 AddrOfNode(const Span& span_, const boost::uuids::uuid& moduleId_);
319 AddrOfNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* subject_);
320 Node* Clone(CloneContext& cloneContext) const override;
321 void Accept(Visitor& visitor) override;
322 std::string ToString() const override;
323 };
324
325 class IsNode : public Node
326 {
327 public:
328 IsNode(const Span& span_, const boost::uuids::uuid& moduleId_);
329 IsNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* expr_, Node* targetTypeExpr_);
330 Node* Clone(CloneContext& cloneContext) const override;
331 void Accept(Visitor& visitor) override;
332 void Write(AstWriter& writer) override;
333 void Read(AstReader& reader) override;
334 const Node* Expr() const { return expr.get(); }
335 Node* Expr() { return expr.get(); }
336 const Node* TargetTypeExpr() const { return targetTypeExpr.get(); }
337 Node* TargetTypeExpr() { return targetTypeExpr.get(); }
338 std::string ToString() const override;
339 private:
340 std::unique_ptr<Node> expr;
341 std::unique_ptr<Node> targetTypeExpr;
342 };
343
344 class AsNode : public Node
345 {
346 public:
347 AsNode(const Span& span_, const boost::uuids::uuid& moduleId_);
348 AsNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* expr_, Node* targetTypeExpr_);
349 Node* Clone(CloneContext& cloneContext) const override;
350 void Accept(Visitor& visitor) override;
351 void Write(AstWriter& writer) override;
352 void Read(AstReader& reader) override;
353 const Node* Expr() const { return expr.get(); }
354 Node* Expr() { return expr.get(); }
355 const Node* TargetTypeExpr() const { return targetTypeExpr.get(); }
356 Node* TargetTypeExpr() { return targetTypeExpr.get(); }
357 std::string ToString() const override;
358 private:
359 std::unique_ptr<Node> expr;
360 std::unique_ptr<Node> targetTypeExpr;
361 };
362
363 class IndexingNode : public Node
364 {
365 public:
366 IndexingNode(const Span& span_, const boost::uuids::uuid& moduleId_);
367 IndexingNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* subject_, Node* index_);
368 Node* Clone(CloneContext& cloneContext) const override;
369 void Accept(Visitor& visitor) override;
370 void Write(AstWriter& writer) override;
371 void Read(AstReader& reader) override;
372 const Node* Subject() const { return subject.get(); }
373 Node* Subject() { return subject.get(); }
374 const Node* Index() const { return index.get(); }
375 Node* Index() { return index.get(); }
376 std::string ToString() const override;
377 private:
378 std::unique_ptr<Node> subject;
379 std::unique_ptr<Node> index;
380 };
381
382 class InvokeNode : public Node
383 {
384 public:
385 InvokeNode(const Span& span_, const boost::uuids::uuid& moduleId_);
386 InvokeNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* subject_);
387 Node* Clone(CloneContext& cloneContext) const override;
388 void Accept(Visitor& visitor) override;
389 void Write(AstWriter& writer) override;
390 void Read(AstReader& reader) override;
391 void AddArgument(Node* argument) override;
392 const Node* Subject() const { return subject.get(); }
393 Node* Subject() { return subject.get(); }
394 const NodeList<Node>& Arguments() const { return arguments; }
395 std::string ToString() const override;
396 private:
397 std::unique_ptr<Node> subject;
398 NodeList<Node> arguments;
399 };
400
401 class PostfixIncrementNode : public UnaryNode
402 {
403 public:
404 PostfixIncrementNode(const Span& span_, const boost::uuids::uuid& moduleId_);
405 PostfixIncrementNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* subject_);
406 Node* Clone(CloneContext& cloneContext) const override;
407 void Accept(Visitor& visitor) override;
408 std::string ToString() const override;
409 };
410
411 class PostfixDecrementNode : public UnaryNode
412 {
413 public:
414 PostfixDecrementNode(const Span& span_, const boost::uuids::uuid& moduleId_);
415 PostfixDecrementNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* subject_);
416 Node* Clone(CloneContext& cloneContext) const override;
417 void Accept(Visitor& visitor) override;
418 std::string ToString() const override;
419 };
420
421 class SizeOfNode : public Node
422 {
423 public:
424 SizeOfNode(const Span& span_, const boost::uuids::uuid& moduleId_);
425 SizeOfNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* expression_);
426 Node* Clone(CloneContext& cloneContext) const override;
427 void Accept(Visitor& visitor) override;
428 void Write(AstWriter& writer) override;
429 void Read(AstReader& reader) override;
430 const Node* Expression() const { return expression.get(); }
431 Node* Expression() { return expression.get(); }
432 std::string ToString() const override;
433 private:
434 std::unique_ptr<Node> expression;
435 };
436
437 class TypeNameNode : public Node
438 {
439 public:
440 TypeNameNode(const Span& span_, const boost::uuids::uuid& moduleId_);
441 TypeNameNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* expression_);
442 Node* Clone(CloneContext& cloneContext) const override;
443 void Accept(Visitor& visitor) override;
444 void Write(AstWriter& writer) override;
445 void Read(AstReader& reader) override;
446 const Node* Expression() const { return expression.get(); }
447 Node* Expression() { return expression.get(); }
448 std::string ToString() const override;
449 bool Static() const { return static_; }
450 void SetStatic() { static_ = true; }
451 private:
452 std::unique_ptr<Node> expression;
453 bool static_;
454 };
455
456 class TypeIdNode : public Node
457 {
458 public:
459 TypeIdNode(const Span& span_, const boost::uuids::uuid& moduleId_);
460 TypeIdNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* expression_);
461 Node* Clone(CloneContext& cloneContext) const override;
462 void Accept(Visitor& visitor) override;
463 void Write(AstWriter& writer) override;
464 void Read(AstReader& reader) override;
465 const Node* Expression() const { return expression.get(); }
466 Node* Expression() { return expression.get(); }
467 std::string ToString() const override;
468 private:
469 std::unique_ptr<Node> expression;
470 };
471
472 class CastNode : public Node
473 {
474 public:
475 CastNode(const Span& span_, const boost::uuids::uuid& moduleId_);
476 CastNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* targetTypeExpr_, Node* sourceExpr_);
477 Node* Clone(CloneContext& cloneContext) const override;
478 void Accept(Visitor& visitor) override;
479 void Write(AstWriter& writer) override;
480 void Read(AstReader& reader) override;
481 const Node* TargetTypeExpr() const { return targetTypeExpr.get(); }
482 Node* TargetTypeExpr() { return targetTypeExpr.get(); }
483 const Node* SourceExpr() const { return sourceExpr.get(); }
484 Node* SourceExpr() { return sourceExpr.get(); }
485 std::string ToString() const override;
486 private:
487 std::unique_ptr<Node> targetTypeExpr;
488 std::unique_ptr<Node> sourceExpr;
489 };
490
491 class ConstructNode : public Node
492 {
493 public:
494 ConstructNode(const Span& span_, const boost::uuids::uuid& moduleId_);
495 ConstructNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* typeExpr_);
496 Node* Clone(CloneContext& cloneContext) const override;
497 void Accept(Visitor& visitor) override;
498 void Write(AstWriter& writer) override;
499 void Read(AstReader& reader) override;
500 void AddArgument(Node* argument) override;
501 const Node* TypeExpr() const { return typeExpr.get(); }
502 Node* TypeExpr() { return typeExpr.get(); }
503 const NodeList<Node>& Arguments() const { return arguments; }
504 std::string ToString() const override;
505 private:
506 std::unique_ptr<Node> typeExpr;
507 NodeList<Node> arguments;
508 };
509
510 class NewNode : public Node
511 {
512 public:
513 NewNode(const Span& span_, const boost::uuids::uuid& moduleId_);
514 NewNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* typeExpr_);
515 Node* Clone(CloneContext& cloneContext) const override;
516 void Accept(Visitor& visitor) override;
517 void Write(AstWriter& writer) override;
518 void Read(AstReader& reader) override;
519 void AddArgument(Node* argument) override;
520 const Node* TypeExpr() const { return typeExpr.get(); }
521 Node* TypeExpr() { return typeExpr.get(); }
522 const NodeList<Node>& Arguments() const { return arguments; }
523 std::string ToString() const override;
524 private:
525 std::unique_ptr<Node> typeExpr;
526 NodeList<Node> arguments;
527 };
528
529 class ThisNode : public Node
530 {
531 public:
532 ThisNode(const Span& span_, const boost::uuids::uuid& moduleId_);
533 Node* Clone(CloneContext& cloneContext) const override;
534 void Accept(Visitor& visitor) override;
535 std::string ToString() const override;
536 };
537
538 class BaseNode : public Node
539 {
540 public:
541 BaseNode(const Span& span_, const boost::uuids::uuid& moduleId_);
542 Node* Clone(CloneContext& cloneContext) const override;
543 void Accept(Visitor& visitor) override;
544 std::string ToString() const override;
545 };
546
547 class ParenthesizedExpressionNode : public UnaryNode
548 {
549 public:
550 ParenthesizedExpressionNode(const Span& span_, const boost::uuids::uuid& moduleId_);
551 ParenthesizedExpressionNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* child_);
552 Node* Clone(CloneContext& cloneContext) const override;
553 void Write(AstWriter& writer) override;
554 void Read(AstReader& reader) override;
555 void Accept(Visitor& visitor) override;
556 std::string ToString() const override;
557 };
558
559 } }
560
561 #endif // SNGCM_AST_EXPRESSION_INCLUDED