1
2
3
4
5
6 #ifndef SNGCPP_AST_ENUMERATION_INCLUDED
7 #define SNGCPP_AST_ENUMERATION_INCLUDED
8 #include <sngcpp/ast/Node.hpp>
9 #include <string>
10
11 namespace sngcpp { namespace ast {
12
13 enum class EnumKey : uint8_t
14 {
15 enum_, enumClass_, enumStruct_
16 };
17
18 std::u32string ToString(EnumKey enumKey);
19
20 class EnumTypeNode : public Node
21 {
22 public:
23 EnumTypeNode();
24 EnumTypeNode(const Span& span_, EnumKey enumKey_, Node* enumName_, Node* enumBase_);
25 void Accept(Visitor& visitor) override;
26 void Write(Writer& writer) override;
27 void Read(Reader& reader) override;
28 void AddEnumerator(const Span& span_, Node* enumerator_);
29 EnumKey GetEnumKey() const { return enumKey; }
30 Node* EnumName() { return enumName.get(); }
31 Node* EnumBase() { return enumBase.get(); }
32 Node* Enumerators() { return enumerators.get(); }
33 void SetOpenBraceSpan(const Span& openBraceSpan_) { openBraceSpan = openBraceSpan_; }
34 const Span& OpenBraceSpan() const { return openBraceSpan; }
35 void SetCloseBraceSpan(const Span& closeBraceSpan_) { closeBraceSpan = closeBraceSpan_; }
36 const Span& CloseBraceSpan() const { return closeBraceSpan; }
37 private:
38 EnumKey enumKey;
39 std::unique_ptr<Node> enumName;
40 std::unique_ptr<Node> enumBase;
41 std::unique_ptr<Node> enumerators;
42 Span openBraceSpan;
43 Span closeBraceSpan;
44 };
45
46 class EnumeratorNode : public Node
47 {
48 public:
49 EnumeratorNode();
50 EnumeratorNode(const Span& span_, const std::u32string& enumerator_, Node* value_, const std::u32string& valueStr_);
51 void Accept(Visitor& visitor) override;
52 void Write(Writer& writer) override;
53 void Read(Reader& reader) override;
54 const std::u32string& Enumerator() const { return enumerator; }
55 Node* Value() { return value.get(); }
56 const std::u32string& ValueStr() const { return valueStr; }
57 void SetAssignmentSignSpan(const Span& assignmentSignSpan_) { assignmentSignSpan = assignmentSignSpan_; }
58 const Span& AssignmentSignSpan() const { return assignmentSignSpan; }
59 private:
60 std::u32string enumerator;
61 std::unique_ptr<Node> value;
62 std::u32string valueStr;
63 Span assignmentSignSpan;
64 };
65
66 class EnumeratorSequenceNode : public BinaryNode
67 {
68 public:
69 EnumeratorSequenceNode();
70 EnumeratorSequenceNode(const Span& span_, Node* left_, Node* right_);
71 void Accept(Visitor& visitor) override;
72 };
73
74 } }
75
76 #endif // SNGCPP_AST_ENUMERATION_INCLUDED