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_) : Node(NodeType::parameterNode, span_), typeExpr(), id(), artificialId(false)
15 {
16 }
17
18 ParameterNode::ParameterNode(const Span& span_, Node* typeExpr_, IdentifierNode* id_) : Node(NodeType::parameterNode, span_), typeExpr(typeExpr_), id(id_), artificialId(false)
19 {
20 typeExpr->SetParent(this);
21 if (id)
22 {
23 id->SetParent(this);
24 }
25 }
26
27 Node* ParameterNode::Clone(CloneContext& cloneContext) const
28 {
29 IdentifierNode* clonedId = nullptr;
30 if (id)
31 {
32 clonedId = static_cast<IdentifierNode*>(id->Clone(cloneContext));
33 }
34 ParameterNode* clone = new ParameterNode(GetSpan(), typeExpr->Clone(cloneContext), clonedId);
35 if (artificialId)
36 {
37 clone->artificialId = true;
38 }
39 return clone;
40 }
41
42 void ParameterNode::Accept(Visitor& visitor)
43 {
44 visitor.Visit(*this);
45 }
46
47 void ParameterNode::Write(AstWriter& writer)
48 {
49 Node::Write(writer);
50 writer.Write(typeExpr.get());
51 bool hasId = id != nullptr;
52 writer.GetBinaryWriter().Write(hasId);
53 if (hasId)
54 {
55 writer.Write(id.get());
56 }
57 writer.GetBinaryWriter().Write(artificialId);
58 }
59
60 void ParameterNode::Read(AstReader& reader)
61 {
62 Node::Read(reader);
63 typeExpr.reset(reader.ReadNode());
64 typeExpr->SetParent(this);
65 bool hasId = reader.GetBinaryReader().ReadBool();
66 if (hasId)
67 {
68 id.reset(reader.ReadIdentifierNode());
69 id->SetParent(this);
70 }
71 artificialId = reader.GetBinaryReader().ReadBool();
72 }
73
74 void ParameterNode::SetId(IdentifierNode* id_)
75 {
76 id.reset(id_);
77 id->SetParent(this);
78 artificialId = true;
79 }
80
81 } }