1
2
3
4
5
6 #ifndef SNGCM_AST_ATTRIBUTE_INCLUDED
7 #define SNGCM_AST_ATTRIBUTE_INCLUDED
8 #include <sngcm/ast/Node.hpp>
9
10 namespace sngcm { namespace ast {
11
12 class AttributeNode : public Node
13 {
14 public:
15 AttributeNode(const Span& span_, const boost::uuids::uuid& moduleId_);
16 AttributeNode(const Span& span_, const boost::uuids::uuid& moduleId_, const std::u32string& name_, const std::u32string& value_);
17 AttributeNode(const AttributeNode&) = delete;
18 AttributeNode& operator=(const AttributeNode&) = delete;
19 const std::u32string& Name() const { return name; }
20 const std::u32string& Value() const { return value; }
21 Node* Clone(CloneContext& cloneContext) const override;
22 void Accept(Visitor& visitor) override;
23 void Write(AstWriter& writer) override;
24 void Read(AstReader& reader) override;
25 private:
26 std::u32string name;
27 std::u32string value;
28 };
29
30 class AttributesNode : public Node
31 {
32 public:
33 AttributesNode(const Span& span_, const boost::uuids::uuid& moduleId_);
34 AttributesNode(const AttributesNode&) = delete;
35 AttributesNode& operator=(const AttributesNode&) = delete;
36 const std::std::vector<std::std::unique_ptr<AttributeNode>>&GetAttributes() const{returnattributes;}
37 void AddAttribute(const Span& span, const boost::uuids::uuid& moduleId, const std::u32string& name);
38 void AddAttribute(const Span& span, const boost::uuids::uuid& moduleId, const std::u32string& name, const std::u32string& value);
39 AttributeNode* GetAttribute(const std::u32string& name) const;
40 Node* Clone(CloneContext& cloneContext) const override;
41 void Accept(Visitor& visitor) override;
42 void Write(AstWriter& writer) override;
43 void Read(AstReader& reader) override;
44 private:
45 std::vector<std::std::unique_ptr<AttributeNode>>attributes;
46 std::map<std::u32string, AttributeNode*> attributeMap;
47 void AddAttribute(AttributeNode* attribute);
48 };
49
50 class AttributeNotUniqueException : public std::runtime_error
51 {
52 public:
53 AttributeNotUniqueException(const std::string& message_, const Span& span_, const boost::uuids::uuid& moduleId_,
54 const Span& prevSpan_, const boost::uuids::uuid& prevModuleId_);
55 const Span& GetSpan() const { return span; }
56 const boost::uuids::uuid& ModuleId() const { return moduleId; }
57 const Span& PrevSpan() const { return prevSpan; }
58 const boost::uuids::uuid& PrevModuleId() const { return prevModuleId; }
59 private:
60 Span span;
61 boost::uuids::uuid moduleId;
62 Span prevSpan;
63 boost::uuids::uuid prevModuleId;
64 };
65
66 } }
67
68 #endif // SNGCM_AST_ATTRIBUTE_INCLUDED
69