1
2
3
4
5
6 #ifndef SNGCM_AST_ENUMERATION_INCLUDED
7 #define SNGCM_AST_ENUMERATION_INCLUDED
8 #include <sngcm/ast/Function.hpp>
9 #include <sngcm/ast/NodeList.hpp>
10 #include <sngcm/ast/Specifier.hpp>
11
12 namespace sngcm { namespace ast {
13
14 class IdentifierNode;
15 class EnumConstantNode;
16
17 class EnumTypeNode : public Node
18 {
19 public:
20 EnumTypeNode(const Span& span_, const boost::uuids::uuid& moduleId_);
21 EnumTypeNode(const Span& span_, const boost::uuids::uuid& moduleId_, Specifiers specifiers_, IdentifierNode* id_);
22 Node* Clone(CloneContext& cloneContext) const override;
23 void Accept(Visitor& visitor) override;
24 void Write(AstWriter& writer) override;
25 void Read(AstReader& reader) override;
26 void AddConstant(EnumConstantNode* constant);
27 EnumConstantNode* GetLastConstant() const;
28 Specifiers GetSpecifiers() const override { return specifiers; }
29 IdentifierNode* Id() const { return id.get(); }
30 void SetUnderlyingType(Node* underlyingType_);
31 Node* GetUnderlyingType() const { return underlyingType.get(); }
32 const NodeList<EnumConstantNode>& Constants() const { return constants; }
33 void SetBeginBraceSpan(const Span& beginBraceSpan_) { beginBraceSpan = beginBraceSpan_; }
34 const Span& BeginBraceSpan() const { return beginBraceSpan; }
35 void SetEndBraceSpan(const Span& endBraceSpan_) { endBraceSpan = endBraceSpan_; }
36 const Span& EndBraceSpan() const { return endBraceSpan; }
37 private:
38 Specifiers specifiers;
39 std::unique_ptr<IdentifierNode> id;
40 std::unique_ptr<Node> underlyingType;
41 NodeList<EnumConstantNode> constants;
42 Span beginBraceSpan;
43 Span endBraceSpan;
44 };
45
46 class EnumConstantNode : public Node
47 {
48 public:
49 EnumConstantNode(const Span& span_, const boost::uuids::uuid& moduleId_);
50 EnumConstantNode(const Span& span_, const boost::uuids::uuid& moduleId_, IdentifierNode* id_, Node* value_);
51 Node* Clone(CloneContext& cloneContext) const override;
52 void Accept(Visitor& visitor) override;
53 void Write(AstWriter& writer) override;
54 void Read(AstReader& reader) override;
55 Node* GetValue() const { return value.get(); }
56 IdentifierNode* Id() const { return id.get(); }
57 void SetHasValue() { hasValue = true; }
58 bool HasValue() const { return hasValue; }
59 void SetStrValue(const std::u32string& strValue_) { strValue = strValue_; }
60 const std::u32string& StrValue() const { return strValue; }
61 private:
62 std::unique_ptr<IdentifierNode> id;
63 std::unique_ptr<Node> value;
64 bool hasValue;
65 std::u32string strValue;
66 };
67
68 Node* MakeNextEnumConstantValue(const Span& span, const boost::uuids::uuid& moduleId_, EnumTypeNode* enumType);
69
70 } }
71
72 #endif // SNGCM_AST_ENUMERATION_INCLUDED