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_, const boost::uuids::uuid& moduleId_) : Node(NodeType::identifierNode, span_, moduleId_), identifier()
17 {
18 }
19
20 IdentifierNode::IdentifierNode(const Span& span_, const boost::uuids::uuid& moduleId_, NodeType nodeType_) : Node(nodeType_, span_, moduleId_), identifier()
21 {
22 }
23
24 IdentifierNode::IdentifierNode(const Span& span_, const boost::uuids::uuid& moduleId_, const std::u32string& identifier_) : Node(NodeType::identifierNode, span_, moduleId_), identifier(identifier_)
25 {
26 }
27
28 IdentifierNode::IdentifierNode(const Span& span_, const boost::uuids::uuid& moduleId_, NodeType nodeType_, const std::u32string& identifier_) : Node(nodeType_, span_, moduleId_), 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 boost::uuids::uuid& moduleId_, const soulng::lexer::Token& token) : Node(NodeType::identifierNode, span_, moduleId_)
42 {
43 identifier = std::u32string(token.match.begin, token.match.end);
44 }
45
46 Node* IdentifierNode::Clone(CloneContext& cloneContext) const
47 {
48 IdentifierNode* clone = new IdentifierNode(GetSpan(), ModuleId(), identifier);
49 return clone;
50 }
51
52 void IdentifierNode::Accept(Visitor& visitor)
53 {
54 visitor.Visit(*this);
55 }
56
57 void IdentifierNode::Write(AstWriter& writer)
58 {
59 Node::Write(writer);
60 writer.GetBinaryWriter().Write(identifier);
61 }
62
63 void IdentifierNode::Read(AstReader& reader)
64 {
65 Node::Read(reader);
66 identifier = reader.GetBinaryReader().ReadUtf32String();
67 }
68
69 std::string IdentifierNode::ToString() const
70 {
71 return ToUtf8(identifier);
72 }
73
74 bool IdentifierNode::IsInternal() const
75 {
76 return !identifier.empty() && identifier.front() == '@';
77 }
78
79 CursorIdNode::CursorIdNode(const Span& span_, const boost::uuids::uuid& moduleId_) : IdentifierNode(span_, moduleId_, NodeType::cursorIdNode)
80 {
81 }
82
83 CursorIdNode::CursorIdNode(const Span& span_, const boost::uuids::uuid& moduleId_, const std::u32string& identifier_) : IdentifierNode(span_, moduleId_, NodeType::cursorIdNode, identifier_)
84 {
85 }
86
87 Node* CursorIdNode::Clone(CloneContext& cloneContext) const
88 {
89 CursorIdNode* clone = new CursorIdNode(GetSpan(), ModuleId(), Str());
90 return clone;
91 }
92
93 void CursorIdNode::Accept(Visitor& visitor)
94 {
95 visitor.Visit(*this);
96 }
97
98 void CursorIdNode::Write(AstWriter& writer)
99 {
100 IdentifierNode::Write(writer);
101 }
102
103 void CursorIdNode::Read(AstReader& reader)
104 {
105 IdentifierNode::Read(reader);
106 }
107
108 } }