1
2
3
4
5
6 #ifndef SNGCPP_AST_CLASS_INCLUDED
7 #define SNGCPP_AST_CLASS_INCLUDED
8 #include <sngcpp/ast/Statement.hpp>
9 #include <sngcpp/ast/Specifier.hpp>
10
11 namespace sngcpp { namespace ast {
12
13 enum class ClassKey : uint8_t
14 {
15 none, class_, struct_, union_, typename_
16 };
17
18 std::u32string ToString(ClassKey classKey);
19
20 class BaseClassSpecifierNode : public Node
21 {
22 public:
23 BaseClassSpecifierNode();
24 BaseClassSpecifierNode(const Span& span_, Specifier baseSpecifiers_, Node* className_);
25 void Accept(Visitor& visitor) override;
26 void Write(Writer& writer) override;
27 void Read(Reader& reader) override;
28 Specifier BaseSpecifiers() const { return baseSpecifiers; }
29 Node* ClassName() { return className.get(); }
30 private:
31 Specifier baseSpecifiers;
32 std::unique_ptr<Node> className;
33 };
34
35 class BaseClassSpecifierSequenceNode : public BinaryNode
36 {
37 public:
38 BaseClassSpecifierSequenceNode();
39 BaseClassSpecifierSequenceNode(const Span& span_, Node* left_, Node* right_);
40 void Accept(Visitor& visitor) override;
41 };
42
43 class ForwardClassDeclarationNode : public Node
44 {
45 public:
46 ForwardClassDeclarationNode();
47 ForwardClassDeclarationNode(const Span& span_, ClassKey classKey_, Node* className_);
48 void Accept(Visitor& visitor) override;
49 void Write(Writer& writer) override;
50 void Read(Reader& reader) override;
51 ClassKey GetClassKey() const { return classKey; }
52 Node* ClassName() { return className.get(); }
53 private:
54 ClassKey classKey;
55 std::unique_ptr<Node> className;
56 };
57
58 class ElaborateClassNameNode : public Node
59 {
60 public:
61 ElaborateClassNameNode();
62 ElaborateClassNameNode(const Span& span_, ClassKey classKey_, Node* className_);
63 void Accept(Visitor& visitor) override;
64 void Write(Writer& writer) override;
65 void Read(Reader& reader) override;
66 ClassKey GetClassKey() const { return classKey; }
67 Node* ClassName() { return className.get(); }
68 private:
69 ClassKey classKey;
70 std::unique_ptr<Node> className;
71 };
72
73 class ClassNode : public Node
74 {
75 public:
76 ClassNode();
77 ClassNode(const Span& span_, ClassKey classKey_, Node* className_, Specifier classVirtSpecifiers_, Node* baseClasses_);
78 void Accept(Visitor& visitor) override;
79 void Write(Writer& writer) override;
80 void Read(Reader& reader) override;
81 void AddDeclaration(const Span& span, Node* declaration);
82 Node* ClassName() { return className.get(); }
83 ClassKey GetClassKey() const { return classKey; }
84 Specifier ClassVirtSpecifiers() const { return classVirtSpecifiers; }
85 Node* BaseClasses() { return baseClasses.get(); }
86 Node* Declarations() { return declarations.get(); }
87 Specifier DefaultAccess() const;
88 void SetOpenBraceSpan(const Span& openBraceSpan_) { openBraceSpan = openBraceSpan_; }
89 void SetCloseBraceSpan(const Span& closeBraceSpan_) { closeBraceSpan = closeBraceSpan_; }
90 const Span& OpenBraceSpan() const { return openBraceSpan; }
91 const Span& CloseBraceSpan() const { return closeBraceSpan; }
92 private:
93 ClassKey classKey;
94 std::unique_ptr<Node> className;
95 Specifier classVirtSpecifiers;
96 std::unique_ptr<Node> baseClasses;
97 std::unique_ptr<Node> declarations;
98 Span openBraceSpan;
99 Span closeBraceSpan;
100 };
101
102 class MemberAccessDeclarationNode : public Node
103 {
104 public:
105 MemberAccessDeclarationNode();
106 MemberAccessDeclarationNode(const Span& span_, Specifier accessSpecifier_, Node* declaration_, bool explicitAccess_);
107 void Accept(Visitor& visitor) override;
108 void Write(Writer& writer) override;
109 void Read(Reader& reader) override;
110 Specifier AccessSpecifier() const { return accessSpecifier; }
111 Node* Declaration() { return declaration.get(); }
112 bool ExplicitAccess() const { return explicitAccess; }
113 private:
114 Specifier accessSpecifier;
115 std::unique_ptr<Node> declaration;
116 bool explicitAccess;
117 };
118
119 class MemberDeclarationNode : public Node
120 {
121 public:
122 MemberDeclarationNode();
123 MemberDeclarationNode(const Span& span_, Specifier specifiers_, Node* typeExpr_, Node* declarator_, Node* initializer_);
124 void Accept(Visitor& visitor) override;
125 void Write(Writer& writer) override;
126 void Read(Reader& reader) override;
127 Specifier Specifiers() const { return specifiers; }
128 Node* TypeExpr() { return typeExpr.get(); }
129 Node* Declarator() { return declarator.get(); }
130 Node* Initializer() { return initializer.get(); }
131 private:
132 Specifier specifiers;
133 std::unique_ptr<Node> typeExpr;
134 std::unique_ptr<Node> declarator;
135 std::unique_ptr<Node> initializer;
136 };
137
138 class SpecialMemberFunctionNode : public Node
139 {
140 public:
141 SpecialMemberFunctionNode();
142 SpecialMemberFunctionNode(const Span& span_, Specifier specifiers_, Node* declarator_, Node* ctorInitializer_, CompoundStatementNode* functionBody_);
143 void Accept(Visitor& visitor) override;
144 void Write(Writer& writer) override;
145 void Read(Reader& reader) override;
146 Specifier Specifiers() const { return specifiers; }
147 Node* Declarator() { return declarator.get(); }
148 Node* CtorInitializer() { return ctorInitializer.get(); }
149 CompoundStatementNode* FunctionBody() { return functionBody.get(); }
150 private:
151 Specifier specifiers;
152 std::unique_ptr<Node> declarator;
153 std::unique_ptr<Node> ctorInitializer;
154 std::unique_ptr<CompoundStatementNode> functionBody;
155 };
156
157 class CtorInitializerNode : public UnaryNode
158 {
159 public:
160 CtorInitializerNode();
161 CtorInitializerNode(const Span& span_, Node* memberInitializers_);
162 void Accept(Visitor& visitor) override;
163 };
164
165 class MemberInitializerNode : public Node
166 {
167 public:
168 MemberInitializerNode();
169 MemberInitializerNode(const Span& span_, Node* id_, Node* initializer_);
170 void Accept(Visitor& visitor) override;
171 void Write(Writer& writer) override;
172 void Read(Reader& reader) override;
173 Node* Id() { return id.get(); }
174 Node* Initializer() { return initializer.get(); }
175 private:
176 std::unique_ptr<Node> id;
177 std::unique_ptr<Node> initializer;
178 };
179
180 class MemberInitializerSequenceNode : public BinaryNode
181 {
182 public:
183 MemberInitializerSequenceNode();
184 MemberInitializerSequenceNode(const Span& span_, Node* left_, Node* right_);
185 void Accept(Visitor& visitor) override;
186 };
187
188 } }
189
190 #endif // SNGCPP_AST_CLASS_INCLUDED