1
2
3
4
5
6 #include <sngcm/ast/Parameter.hpp>
7 #include <sngcm/ast/Identifier.hpp>
8 #include <sngcm/ast/Visitor.hpp>
9 #include <sngcm/ast/AstWriter.hpp>
10 #include <sngcm/ast/AstReader.hpp>
11
12 namespace sngcm { namespace ast {
13
14 ParameterNode::ParameterNode(const Span& span_, const boost::uuids::uuid& moduleId_) :
15 Node(NodeType::parameterNode, span_, moduleId_), typeExpr(), id(), artificialId(false)
16 {
17 }
18
19 ParameterNode::ParameterNode(const Span& span_, const boost::uuids::uuid& moduleId_, Node* typeExpr_, IdentifierNode* id_) :
20 Node(NodeType::parameterNode, span_, moduleId_), typeExpr(typeExpr_), id(id_), artificialId(false)
21 {
22 typeExpr->SetParent(this);
23 if (id)
24 {
25 id->SetParent(this);
26 }
27 }
28
29 Node* ParameterNode::Clone(CloneContext& cloneContext) const
30 {
31 IdentifierNode* clonedId = nullptr;
32 if (id)
33 {
34 clonedId = static_cast<IdentifierNode*>(id->Clone(cloneContext));
35 }
36 ParameterNode* clone = new ParameterNode(GetSpan(), ModuleId(), typeExpr->Clone(cloneContext), clonedId);
37 if (artificialId)
38 {
39 clone->artificialId = true;
40 }
41 return clone;
42 }
43
44 void ParameterNode::Accept(Visitor& visitor)
45 {
46 visitor.Visit(*this);
47 }
48
49 void ParameterNode::Write(AstWriter& writer)
50 {
51 Node::Write(writer);
52 writer.Write(typeExpr.get());
53 bool hasId = id != nullptr;
54 writer.GetBinaryWriter().Write(hasId);
55 if (hasId)
56 {
57 writer.Write(id.get());
58 }
59 writer.GetBinaryWriter().Write(artificialId);
60 }
61
62 void ParameterNode::Read(AstReader& reader)
63 {
64 Node::Read(reader);
65 typeExpr.reset(reader.ReadNode());
66 typeExpr->SetParent(this);
67 bool hasId = reader.GetBinaryReader().ReadBool();
68 if (hasId)
69 {
70 id.reset(reader.ReadIdentifierNode());
71 id->SetParent(this);
72 }
73 artificialId = reader.GetBinaryReader().ReadBool();
74 }
75
76 void ParameterNode::SetId(IdentifierNode* id_)
77 {
78 id.reset(id_);
79 id->SetParent(this);
80 artificialId = true;
81 }
82
83 } }