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