1
2
3
4
5
6 #ifndef SNGCM_AST_CLASS_INCLUDED
7 #define SNGCM_AST_CLASS_INCLUDED
8 #include <sngcm/ast/Function.hpp>
9 #include <sngcm/ast/Attribute.hpp>
10
11 namespace sngcm { namespace ast {
12
13 class ClassNode : public Node
14 {
15 public:
16 ClassNode(const Span& span_);
17 ClassNode(const Span& span_, Specifiers specifiers_, IdentifierNode* id_, Attributes* attributes_);
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 void AddTemplateParameter(TemplateParameterNode* templateParameter) override;
23 Specifiers GetSpecifiers() const override { return specifiers; }
24 void SetSpecifiers(Specifiers specifiers_) { specifiers = specifiers_; }
25 IdentifierNode* Id() const { return id.get(); }
26 void AddBaseClassOrInterface(Node* baseClassOrInterface);
27 const WhereConstraintNode* WhereConstraint() const { return constraint.get(); }
28 WhereConstraintNode* WhereConstraint() { return constraint.get(); }
29 void SetConstraint(WhereConstraintNode* whereConstraint);
30 void AddMember(Node* member);
31 const NodeList<TemplateParameterNode>& TemplateParameters() const { return templateParameters; }
32 const NodeList<Node>& BaseClassOrInterfaces() const { return baseClassOrInterfaces; }
33 const NodeList<Node>& Members() const { return members; }
34 Attributes* GetAttributes() const { return attributes.get(); }
35 void SetSpecifierSpan(const Span& specifierSpan_) { specifierSpan = specifierSpan_; }
36 const Span& SpecifierSpan() const { return specifierSpan; }
37 void SetClassSpan(const Span& classSpan_) { classSpan = classSpan_; }
38 const Span& ClassSpan() const { return classSpan; }
39 void SetBeginBraceSpan(const Span& beginBraceSpan_) { beginBraceSpan = beginBraceSpan_; }
40 const Span& BeginBraceSpan() const { return beginBraceSpan; }
41 void SetEndBraceSpan(const Span& endBraceSpan_) { endBraceSpan = endBraceSpan_; }
42 const Span& EndBraceSpan() const { return endBraceSpan; }
43 void ArrangeMembers();
44 private:
45 Specifiers specifiers;
46 Span specifierSpan;
47 Span classSpan;
48 Span beginBraceSpan;
49 Span endBraceSpan;
50 std::unique_ptr<IdentifierNode> id;
51 NodeList<TemplateParameterNode> templateParameters;
52 NodeList<Node> baseClassOrInterfaces;
53 std::unique_ptr<WhereConstraintNode> constraint;
54 NodeList<Node> members;
55 std::unique_ptr<Attributes> attributes;
56 };
57
58 class InitializerNode : public Node
59 {
60 public:
61 InitializerNode(NodeType nodeType_, const Span& span_);
62 void Write(AstWriter& writer) override;
63 void Read(AstReader& reader) override;
64 void AddArgument(Node* argument) override;
65 const NodeList<Node>& Arguments() const { return arguments; }
66 private:
67 NodeList<Node> arguments;
68 };
69
70 class ThisInitializerNode : public InitializerNode
71 {
72 public:
73 ThisInitializerNode(const Span& span_);
74 Node* Clone(CloneContext& cloneContext) const override;
75 void Accept(Visitor& visitor) override;
76 };
77
78 class BaseInitializerNode : public InitializerNode
79 {
80 public:
81 BaseInitializerNode(const Span& span_);
82 Node* Clone(CloneContext& cloneContext) const override;
83 void Accept(Visitor& visitor) override;
84 };
85
86 class MemberInitializerNode : public InitializerNode
87 {
88 public:
89 MemberInitializerNode(const Span& span_);
90 MemberInitializerNode(const Span& span_, IdentifierNode* memberId_);
91 Node* Clone(CloneContext& cloneContext) const override;
92 void Accept(Visitor& visitor) override;
93 void Write(AstWriter& writer) override;
94 void Read(AstReader& reader) override;
95 const IdentifierNode* MemberId() const { return memberId.get(); }
96 IdentifierNode* MemberId() { return memberId.get(); }
97 private:
98 std::unique_ptr<IdentifierNode> memberId;
99 };
100
101 class StaticConstructorNode : public FunctionNode
102 {
103 public:
104 StaticConstructorNode(const Span& span_);
105 StaticConstructorNode(const Span& span_, Specifiers specifiers_, Attributes* attributes_);
106 Node* Clone(CloneContext& cloneContext) const override;
107 void Accept(Visitor& visitor) override;
108 void Write(AstWriter& writer) override;
109 void Read(AstReader& reader) override;
110 void AddInitializer(InitializerNode* initializer);
111 const NodeList<InitializerNode>& Initializers() const { return initializers; }
112 void SetClassId(IdentifierNode* classId_) { classId.reset(classId_); }
113 IdentifierNode* ClassId() { return classId.get(); }
114 private:
115 NodeList<InitializerNode> initializers;
116 std::unique_ptr<IdentifierNode> classId;
117 };
118
119 class ConstructorNode : public FunctionNode
120 {
121 public:
122 ConstructorNode(const Span& span_);
123 ConstructorNode(const Span& span_, Specifiers specifiers_, Attributes* attributes_);
124 Node* Clone(CloneContext& cloneContext) const override;
125 void Accept(Visitor& visitor) override;
126 void Write(AstWriter& writer) override;
127 void Read(AstReader& reader) override;
128 void AddInitializer(InitializerNode* initializer);
129 const NodeList<InitializerNode>& Initializers() const { return initializers; }
130 void SetClassId(IdentifierNode* classId_) { classId.reset(classId_); }
131 IdentifierNode* ClassId() { return classId.get(); }
132 private:
133 NodeList<InitializerNode> initializers;
134 std::unique_ptr<IdentifierNode> classId;
135 };
136
137 class DestructorNode : public FunctionNode
138 {
139 public:
140 DestructorNode(const Span& span_);
141 DestructorNode(const Span& span_, Specifiers specifiers_, Attributes* attributes_);
142 Node* Clone(CloneContext& cloneContext) const override;
143 void Accept(Visitor& visitor) override;
144 void Write(AstWriter& writer) override;
145 void Read(AstReader& reader) override;
146 void SetClassId(IdentifierNode* classId_) { classId.reset(classId_); }
147 IdentifierNode* ClassId() { return classId.get(); }
148 private:
149 std::unique_ptr<IdentifierNode> classId;
150 };
151
152 class MemberFunctionNode : public FunctionNode
153 {
154 public:
155 MemberFunctionNode(const Span& span_);
156 MemberFunctionNode(const Span& span_, Specifiers specifiers_, Node* returnTypeExpr_, const std::u32string& groupId_, Attributes* attributes_);
157 Node* Clone(CloneContext& cloneContext) const override;
158 void Accept(Visitor& visitor) override;
159 bool IsConst() const { return (GetSpecifiers() & Specifiers::const_) != Specifiers::none; }
160 void SetConst() { SetSpecifiers(GetSpecifiers() | Specifiers::const_); }
161 };
162
163 class ConversionFunctionNode : public FunctionNode
164 {
165 public:
166 ConversionFunctionNode(const Span& span_);
167 ConversionFunctionNode(const Span& span_, Specifiers specifiers_, Node* returnTypeExpr_, Attributes* attributes_);
168 Node* Clone(CloneContext& cloneContext) const override;
169 void Accept(Visitor& visitor) override;
170 bool IsConst() const { return (GetSpecifiers() & Specifiers::const_) != Specifiers::none; }
171 void SetConst() { SetSpecifiers(GetSpecifiers() | Specifiers::const_); }
172 };
173
174 class MemberVariableNode : public Node
175 {
176 public:
177 MemberVariableNode(const Span& span_);
178 MemberVariableNode(const Span& span_, Specifiers specifiers_, Node* typeExpr_, IdentifierNode* id_, Attributes* attributes_);
179 Node* Clone(CloneContext& cloneContext) const override;
180 void Accept(Visitor& visitor) override;
181 void Write(AstWriter& writer) override;
182 void Read(AstReader& reader) override;
183 Specifiers GetSpecifiers() const override { return specifiers; }
184 Node* TypeExpr() const { return typeExpr.get(); }
185 IdentifierNode* Id() const { return id.get(); }
186 Attributes* GetAttributes() const { return attributes.get(); }
187 void SetSpecifierSpan(const Span& specifierSpan_) { specifierSpan = specifierSpan_; }
188 const Span& SpecifierSpan() const { return specifierSpan; }
189 private:
190 Specifiers specifiers;
191 Span specifierSpan;
192 std::unique_ptr<Node> typeExpr;
193 std::unique_ptr<IdentifierNode> id;
194 std::unique_ptr<Attributes> attributes;
195 };
196
197 } }
198
199 #endif // SNGCM_AST_CLASS_INCLUDED