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