1
2
3
4
5
6 #include <sngcm/ast/Interface.hpp>
7 #include <sngcm/ast/Identifier.hpp>
8 #include <sngcm/ast/Visitor.hpp>
9
10 namespace sngcm { namespace ast {
11
12 InterfaceNode::InterfaceNode(const Span& span_) : Node(NodeType::interfaceNode, span_), specifiers(), id(), members()
13 {
14 }
15
16 InterfaceNode::InterfaceNode(const Span& span_, Specifiers specifiers_, IdentifierNode* id_, Attributes* attributes_) :
17 Node(NodeType::interfaceNode, span_), specifiers(specifiers_), id(id_), members(), attributes(attributes_)
18 {
19 id->SetParent(this);
20 }
21
22 Node* InterfaceNode::Clone(CloneContext& cloneContext) const
23 {
24 Attributes* clonedAttributes = nullptr;
25 if (attributes)
26 {
27 clonedAttributes = attributes->Clone();
28 }
29 InterfaceNode* clone = new InterfaceNode(GetSpan(), specifiers, static_cast<IdentifierNode*>(id->Clone(cloneContext)), clonedAttributes);
30 int n = members.Count();
31 for (int i = 0; i < n; ++i)
32 {
33 clone->AddMember(members[i]->Clone(cloneContext));
34 }
35 clone->SetSpecifierSpan(specifierSpan);
36 clone->SetBeginBraceSpan(beginBraceSpan);
37 clone->SetEndBraceSpan(endBraceSpan);
38 return clone;
39 }
40
41 void InterfaceNode::Accept(Visitor& visitor)
42 {
43 visitor.Visit(*this);
44 }
45
46 void InterfaceNode::Write(AstWriter& writer)
47 {
48 Node::Write(writer);
49 bool hasAttributes = attributes != nullptr;
50 writer.GetBinaryWriter().Write(hasAttributes);
51 if (hasAttributes)
52 {
53 attributes->Write(writer);
54 }
55 writer.Write(id.get());
56 members.Write(writer);
57 writer.Write(specifierSpan);
58 writer.Write(beginBraceSpan);
59 writer.Write(endBraceSpan);
60 }
61
62 void InterfaceNode::Read(AstReader& reader)
63 {
64 Node::Read(reader);
65 bool hasAttributes = reader.GetBinaryReader().ReadBool();
66 if (hasAttributes)
67 {
68 attributes.reset(new Attributes());
69 attributes->Read(reader);
70 }
71 id.reset(reader.ReadIdentifierNode());
72 id->SetParent(this);
73 members.Read(reader);
74 members.SetParent(this);
75 specifierSpan = reader.ReadSpan();
76 beginBraceSpan = reader.ReadSpan();
77 endBraceSpan = reader.ReadSpan();
78 }
79
80 void InterfaceNode::AddMember(Node* member)
81 {
82 member->SetParent(this);
83 members.Add(member);
84 }
85
86 } }