1 #include "GlobalVariable.hpp"
2 #include <soulng/util/Unicode.hpp>
3 #include <sngcm/cmparser/Specifier.hpp>
4 #include <sngcm/cmparser/Identifier.hpp>
5 #include <sngcm/cmparser/TypeExpr.hpp>
6 #include <sngcm/cmparser/Expression.hpp>
7 #include <sngcm/cmlexer/CmajorLexer.hpp>
8 #include <sngcm/cmlexer/CmajorTokens.hpp>
9
10
11
12 using namespace soulng::unicode;
13 using namespace sngcm::ast;
14 using namespace CmajorTokens;
15
16 soulng::parser::Match GlobalVariableParser::GlobalVariable(CmajorLexer& lexer, boost::uuids::uuid* moduleId, ParsingContext* ctx, sngcm::ast::CompileUnitNode* cu)
17 {
18 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
19
20
21
22
23
24
25
26 #endif // SOULNG_PARSER_DEBUG_SUPPORT
27 Span s = Span();
28 std::unique_ptr<soulng::parser::soulng::parser::Value<sngcm::ast::Specifiers>>specifiers;
29 std::unique_ptr<sngcm::ast::Node> type;
30 std::unique_ptr<IdentifierNode> id;
31 std::unique_ptr<Node> initializer;
32 soulng::parser::Match match(false);
33 soulng::parser::Match* parentMatch0 = &match;
34 {
35 soulng::parser::Match match(false);
36 soulng::parser::Match* parentMatch1 = &match;
37 {
38 soulng::parser::Match match(false);
39 soulng::parser::Match* parentMatch2 = &match;
40 {
41 soulng::parser::Match match(false);
42 soulng::parser::Match* parentMatch3 = &match;
43 {
44 soulng::parser::Match match(false);
45 soulng::parser::Match* parentMatch4 = &match;
46 {
47 int64_t pos = lexer.GetPos();
48 soulng::lexer::Span span = lexer.GetSpan();
49 soulng::parser::Match match = SpecifierParser::Specifiers(lexer);
50 specifiers.reset(static_cast<soulng::parser::soulng::parser::Value<sngcm::ast::Specifiers>*>(match.value));
51 if (match.hit)
52 {
53 s = span;
54 }
55 *parentMatch4 = match;
56 }
57 *parentMatch3 = match;
58 }
59 if (match.hit)
60 {
61 soulng::parser::Match match(false);
62 soulng::parser::Match* parentMatch5 = &match;
63 {
64 soulng::parser::Match match = TypeExprParser::TypeExpr(lexer, moduleId, ctx);
65 type.reset(static_cast<sngcm::ast::Node*>(match.value));
66 *parentMatch5 = match;
67 }
68 *parentMatch3 = match;
69 }
70 *parentMatch2 = match;
71 }
72 if (match.hit)
73 {
74 soulng::parser::Match match(false);
75 soulng::parser::Match* parentMatch6 = &match;
76 {
77 soulng::parser::Match match = IdentifierParser::Identifier(lexer, moduleId);
78 id.reset(static_cast<IdentifierNode*>(match.value));
79 *parentMatch6 = match;
80 }
81 *parentMatch2 = match;
82 }
83 *parentMatch1 = match;
84 }
85 if (match.hit)
86 {
87 soulng::parser::Match match(false);
88 soulng::parser::Match* parentMatch7 = &match;
89 {
90 soulng::parser::Match match(true);
91 int64_t save = lexer.GetPos();
92 soulng::parser::Match* parentMatch8 = &match;
93 {
94 soulng::parser::Match match(false);
95 soulng::parser::Match* parentMatch9 = &match;
96 {
97 soulng::parser::Match match(false);
98 soulng::parser::Match* parentMatch10 = &match;
99 {
100 soulng::parser::Match match(false);
101 if (*lexer == ASSIGN)
102 {
103 ++lexer;
104 match.hit = true;
105 }
106 *parentMatch10 = match;
107 }
108 if (match.hit)
109 {
110 soulng::parser::Match match(false);
111 soulng::parser::Match* parentMatch11 = &match;
112 {
113 soulng::parser::Match match = ExpressionParser::Expression(lexer, moduleId, ctx);
114 initializer.reset(static_cast<Node*>(match.value));
115 *parentMatch11 = match;
116 }
117 *parentMatch10 = match;
118 }
119 *parentMatch9 = match;
120 }
121 if (match.hit)
122 {
123 *parentMatch8 = match;
124 }
125 else
126 {
127 lexer.SetPos(save);
128 }
129 }
130 *parentMatch7 = match;
131 }
132 *parentMatch1 = match;
133 }
134 *parentMatch0 = match;
135 }
136 if (match.hit)
137 {
138 soulng::parser::Match match(false);
139 soulng::parser::Match* parentMatch12 = &match;
140 {
141 soulng::parser::Match match(false);
142 soulng::parser::Match* parentMatch13 = &match;
143 {
144 int64_t pos = lexer.GetPos();
145 soulng::lexer::Span span = lexer.GetSpan();
146 soulng::parser::Match match(false);
147 if (*lexer == SEMICOLON)
148 {
149 ++lexer;
150 match.hit = true;
151 }
152 if (match.hit)
153 {
154 s.end = span.end;
155 GlobalVariableNode* value = new GlobalVariableNode(s, *moduleId, specifiers->value, type.release(), id.release(), cu);
156 value->SetInitializer(initializer.release());
157 {
158 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
159
160 #endif // SOULNG_PARSER_DEBUG_SUPPORT
161 return soulng::parser::Match(true, value);
162 }
163 }
164 *parentMatch13 = match;
165 }
166 *parentMatch12 = match;
167 }
168 *parentMatch0 = match;
169 }
170 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
171
172
173
174
175
176 #endif // SOULNG_PARSER_DEBUG_SUPPORT
177 if (!match.hit)
178 {
179 match.value = nullptr;
180 }
181 return match;
182 }