1
2
3
4
5
6 #ifndef SNGCM_AST_NAMESPACE_INCLUDED
7 #define SNGCM_AST_NAMESPACE_INCLUDED
8 #include <sngcm/ast/Node.hpp>
9 #include <sngcm/ast/NodeList.hpp>
10
11 namespace sngcm { namespace ast {
12
13 class IdentifierNode;
14
15 enum class NsFlags : int8_t
16 {
17 none= 0, isUnnamedNs= 1 << 0, hasUnnamedNs= 1 << 1
18 };
19
20 constexpr, inlineNsFlags operator|(NsFlags left, NsFlags right)
21 {
22 return static_cast<NsFlags>(static_cast<int8_t>(left) | static_cast<int8_t>(right));
23 }
24
25 constexpr, inlineNsFlags operator&(NsFlags left, NsFlags right)
26 {
27 return static_cast<NsFlags>(static_cast<int8_t>(left) & static_cast<int8_t>(right));
28 }
29
30 class NamespaceNode : public Node
31 {
32 public:
33 NamespaceNode(const Span& span_, const boost::uuids::uuid& moduleId_);
34 NamespaceNode(const Span& span_, const boost::uuids::uuid& moduleId_, IdentifierNode* id_);
35 Node* Clone(CloneContext& cloneContext) const override;
36 void Accept(Visitor& visitor) override;
37 void Write(AstWriter& writer) override;
38 void Read(AstReader& reader) override;
39 void AddMember(Node* member);
40 IdentifierNode* Id() const;
41 NodeList<Node>& Members() { return members; }
42 const NodeList<Node>& Members() const { return members; }
43 bool IsUnnamedNs() const { return (flags & NsFlags::isUnnamedNs) != NsFlags::none; }
44 void SetUnnamedNs() { flags = flags | NsFlags::isUnnamedNs; }
45 bool HasUnnamedNs() const { return (flags & NsFlags::hasUnnamedNs) != NsFlags::none; }
46 void SetHasUnnamedNs() { flags = flags | NsFlags::hasUnnamedNs; }
47 private:
48 std::unique_ptr<IdentifierNode> id;
49 NodeList<Node> members;
50 NsFlags flags;
51 };
52
53 class AliasNode : public Node
54 {
55 public:
56 AliasNode(const Span& span_, const boost::uuids::uuid& moduleId_);
57 AliasNode(const Span& span_, const boost::uuids::uuid& moduleId_, IdentifierNode* id_, IdentifierNode* qid_);
58 Node* Clone(CloneContext& cloneContext) const override;
59 void Accept(Visitor& visitor) override;
60 void Write(AstWriter& writer) override;
61 void Read(AstReader& reader) override;
62 IdentifierNode* Id() const;
63 IdentifierNode* Qid() const;
64 private:
65 std::unique_ptr<IdentifierNode> id;
66 std::unique_ptr<IdentifierNode> qid;
67 };
68
69 class NamespaceImportNode : public Node
70 {
71 public:
72 NamespaceImportNode(const Span& span_, const boost::uuids::uuid& moduleId_);
73 NamespaceImportNode(const Span& span_, const boost::uuids::uuid& moduleId_, IdentifierNode* ns_);
74 Node* Clone(CloneContext& cloneContext) const override;
75 void Accept(Visitor& visitor) override;
76 void Write(AstWriter& writer) override;
77 void Read(AstReader& reader) override;
78 IdentifierNode* Ns() const;
79 private:
80 std::unique_ptr<IdentifierNode> ns;
81 };
82
83 } }
84
85 #endif // SNGCM_AST_NAMESPACE_INCLUDED