1
2
3
4
5
6 #include <sngcm/ast/Identifier.hpp>
7 #include <sngcm/ast/Visitor.hpp>
8 #include <sngcm/ast/AstWriter.hpp>
9 #include <sngcm/ast/AstReader.hpp>
10 #include <soulng/util/Unicode.hpp>
11
12 namespace sngcm { namespace ast {
13
14 using namespace soulng::unicode;
15
16 IdentifierNode::IdentifierNode(const Span& span_) : Node(NodeType::identifierNode, span_), identifier()
17 {
18 }
19
20 IdentifierNode::IdentifierNode(const Span& span_, NodeType nodeType_) : Node(nodeType_, span_), identifier()
21 {
22 }
23
24 IdentifierNode::IdentifierNode(const Span& span_, const std::u32string& identifier_) : Node(NodeType::identifierNode, span_), identifier(identifier_)
25 {
26 }
27
28 IdentifierNode::IdentifierNode(const Span& span_, NodeType nodeType_, const std::u32string& identifier_) : Node(nodeType_, span_), identifier(identifier_)
29 {
30 std::u32string result;
31 for (char32_t c : identifier)
32 {
33 if (c != '`')
34 {
35 result.append(1, c);
36 }
37 }
38 std::swap(result, identifier);
39 }
40
41 IdentifierNode::IdentifierNode(const Span& span_, const soulng::lexer::Token& token) : Node(NodeType::identifierNode, span_)
42 {
43 identifier = std::u32string(token.match.begin, token.match.end);
44 }
45
46 Node* IdentifierNode::Clone(CloneContext& cloneContext) const
47 {
48 return new IdentifierNode(GetSpan(), identifier);
49 }
50
51 void IdentifierNode::Accept(Visitor& visitor)
52 {
53 visitor.Visit(*this);
54 }
55
56 void IdentifierNode::Write(AstWriter& writer)
57 {
58 Node::Write(writer);
59 writer.GetBinaryWriter().Write(identifier);
60 }
61
62 void IdentifierNode::Read(AstReader& reader)
63 {
64 Node::Read(reader);
65 identifier = reader.GetBinaryReader().ReadUtf32String();
66 }
67
68 std::string IdentifierNode::ToString() const
69 {
70 return ToUtf8(identifier);
71 }
72
73 CursorIdNode::CursorIdNode(const Span& span_) : IdentifierNode(span_, NodeType::cursorIdNode)
74 {
75 }
76
77 CursorIdNode::CursorIdNode(const Span& span_, const std::u32string& identifier_) : IdentifierNode(span_, NodeType::cursorIdNode, identifier_)
78 {
79 }
80
81 Node* CursorIdNode::Clone(CloneContext& cloneContext) const
82 {
83 return new CursorIdNode(GetSpan(), Str());
84 }
85
86 void CursorIdNode::Accept(Visitor& visitor)
87 {
88 visitor.Visit(*this);
89 }
90
91 void CursorIdNode::Write(AstWriter& writer)
92 {
93 IdentifierNode::Write(writer);
94 }
95
96 void CursorIdNode::Read(AstReader& reader)
97 {
98 IdentifierNode::Read(reader);
99 }
100
101 } }