1
2
3
4
5
6 #ifndef SNGCPP_AST_DECLARATOR_INCLUDED
7 #define SNGCPP_AST_DECLARATOR_INCLUDED
8 #include <sngcpp/ast/Statement.hpp>
9 #include <sngcpp/ast/Specifier.hpp>
10
11 namespace sngcpp { namespace ast {
12
13 class IdDeclaratorNode : public Node
14 {
15 public:
16 IdDeclaratorNode();
17 IdDeclaratorNode(const Span& span_, Node* idNode_);
18 void Accept(Visitor& visitor) override;
19 void Write(Writer& writer) override;
20 void Read(Reader& reader) override;
21 Node* IdNode() const { return idNode.get(); }
22 private:
23 std::unique_ptr<Node> idNode;
24 };
25
26 class ArrayDeclaratorNode : public Node
27 {
28 public:
29 ArrayDeclaratorNode();
30 ArrayDeclaratorNode(const Span& span_, Node* declarator_, Node* size_);
31 void Accept(Visitor& visitor) override;
32 void Write(Writer& writer) override;
33 void Read(Reader& reader) override;
34 Node* Declarator() { return declarator.get(); }
35 Node* Size() { return size.get(); }
36 private:
37 std::unique_ptr<Node> declarator;
38 std::unique_ptr<Node> size;
39 };
40
41 class FunctionDeclaratorNode : public Node
42 {
43 public:
44 FunctionDeclaratorNode();
45 FunctionDeclaratorNode(const Span& span_, Node* declarator_, Node* parameters_, Specifier cvSpecifiers_);
46 void Accept(Visitor& visitor) override;
47 void Write(Writer& writer) override;
48 void Read(Reader& reader) override;
49 bool IsFunctionDeclaratorNode() const override { return true; }
50 Node* Declarator() { return declarator.get(); }
51 Node* Parameters() { return parameters.get(); }
52 Specifier CVSpecifiers() const { return cvSpecifiers; }
53 private:
54 std::unique_ptr<Node> declarator;
55 std::unique_ptr<Node> parameters;
56 Specifier cvSpecifiers;
57 };
58
59 class FunctionPtrIdNode : public Node
60 {
61 public:
62 FunctionPtrIdNode();
63 FunctionPtrIdNode(const Span& span_, const std::u32string& id_);
64 void Accept(Visitor& visitor) override;
65 void Write(Writer& writer) override;
66 void Read(Reader& reader) override;
67 const std::u32string& Id() const { return id; }
68 private:
69 std::u32string id;
70 };
71
72 class MemberFunctionPtrIdNode : public Node
73 {
74 public:
75 MemberFunctionPtrIdNode();
76 MemberFunctionPtrIdNode(const Span& span_, Node* classNameNode_, const std::u32string& id_);
77 void Accept(Visitor& visitor) override;
78 void Write(Writer& writer) override;
79 void Read(Reader& reader) override;
80 Node* ClassNameNode() { return classNameNode.get(); }
81 const std::u32string& Id() const { return id; }
82 private:
83 std::unique_ptr<Node> classNameNode;
84 std::u32string id;
85 };
86
87 class InitDeclaratorNode : public Node
88 {
89 public:
90 InitDeclaratorNode();
91 InitDeclaratorNode(const Span& span_, Node* declarator_, Node* initializer_);
92 void Accept(Visitor& visitor) override;
93 void Write(Writer& writer) override;
94 void Read(Reader& reader) override;
95 Node* Declarator() { return declarator.get(); }
96 Node* Initializer() { return initializer.get(); }
97 private:
98 std::unique_ptr<Node> declarator;
99 std::unique_ptr<Node> initializer;
100 };
101
102 class AssignmentInitializerNode : public UnaryNode
103 {
104 public:
105 AssignmentInitializerNode();
106 AssignmentInitializerNode(const Span& span_, Node* initializer_);
107 void Accept(Visitor& visitor) override;
108 };
109
110 class ExpressionListInitializerNode : public UnaryNode
111 {
112 public:
113 ExpressionListInitializerNode();
114 ExpressionListInitializerNode(const Span& span_, Node* initializer_);
115 void Accept(Visitor& visitor) override;
116 };
117
118 class ExpressionInitializerNode : public UnaryNode
119 {
120 public:
121 ExpressionInitializerNode();
122 ExpressionInitializerNode(const Span& span_, Node* expr_);
123 void Accept(Visitor& visitor) override;
124 };
125
126 class BracedInitializerListNode : public UnaryNode
127 {
128 public:
129 BracedInitializerListNode();
130 BracedInitializerListNode(const Span& span_);
131 void Accept(Visitor& visitor) override;
132 void Write(Writer& writer) override;
133 void Read(Reader& reader) override;
134 void AddInitializer(const Span& span, Node* initializer);
135 void SetEndBraceSpan(const Span& endBraceSpan_) { endBraceSpan = endBraceSpan_; }
136 const Span& EndBraceSpan() const { return endBraceSpan; }
137 private:
138 Span endBraceSpan;
139 };
140
141 } }
142
143 #endif // SNGCPP_AST_DECLARATOR_INCLUDED