1 #include "Constant.hpp"
2 #include <soulng/util/Unicode.hpp>
3 #include <sngcm/cmparser/Specifier.hpp>
4 #include <sngcm/cmparser/TypeExpr.hpp>
5 #include <sngcm/cmparser/Identifier.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 ConstantParser::Constant(CmajorLexer& lexer, boost::uuids::uuid* moduleId, ParsingContext* ctx)
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 Span v = Span();
29 std::unique_ptr<Node> e = std::unique_ptr<Node>();
30 std::unique_ptr<soulng::parser::soulng::parser::Value<sngcm::ast::Specifiers>>specifiers;
31 std::unique_ptr<sngcm::ast::Node> type;
32 std::unique_ptr<IdentifierNode> id;
33 std::unique_ptr<Node> expr;
34 soulng::parser::Match match(false);
35 soulng::parser::Match* parentMatch0 = &match;
36 {
37 soulng::parser::Match match(false);
38 soulng::parser::Match* parentMatch1 = &match;
39 {
40 soulng::parser::Match match(false);
41 soulng::parser::Match* parentMatch2 = &match;
42 {
43 soulng::parser::Match match(false);
44 soulng::parser::Match* parentMatch3 = &match;
45 {
46 soulng::parser::Match match(false);
47 soulng::parser::Match* parentMatch4 = &match;
48 {
49 soulng::parser::Match match(false);
50 soulng::parser::Match* parentMatch5 = &match;
51 {
52 soulng::parser::Match match(false);
53 soulng::parser::Match* parentMatch6 = &match;
54 {
55 int64_t pos = lexer.GetPos();
56 soulng::lexer::Span span = lexer.GetSpan();
57 soulng::parser::Match match = SpecifierParser::Specifiers(lexer);
58 specifiers.reset(static_cast<soulng::parser::soulng::parser::Value<sngcm::ast::Specifiers>*>(match.value));
59 if (match.hit)
60 {
61 s = span;
62 }
63 *parentMatch6 = match;
64 }
65 *parentMatch5 = match;
66 }
67 if (match.hit)
68 {
69 soulng::parser::Match match(false);
70 soulng::parser::Match* parentMatch7 = &match;
71 {
72 soulng::parser::Match match(false);
73 if (*lexer == CONST)
74 {
75 ++lexer;
76 match.hit = true;
77 }
78 *parentMatch7 = match;
79 }
80 *parentMatch5 = match;
81 }
82 *parentMatch4 = match;
83 }
84 if (match.hit)
85 {
86 soulng::parser::Match match(false);
87 soulng::parser::Match* parentMatch8 = &match;
88 {
89 soulng::parser::Match match(true);
90 soulng::parser::Match* parentMatch9 = &match;
91 {
92 soulng::lexer::Span span = lexer.GetSpan();
93 soulng::parser::Match match = TypeExprParser::TypeExpr(lexer, moduleId, ctx);
94 type.reset(static_cast<sngcm::ast::Node*>(match.value));
95 if (match.hit)
96 {
97 *parentMatch9 = match;
98 }
99 else
100 {
101 lexer.ThrowExpectationFailure(span, U"type expression");
102 }
103 }
104 *parentMatch8 = match;
105 }
106 *parentMatch4 = match;
107 }
108 *parentMatch3 = match;
109 }
110 if (match.hit)
111 {
112 soulng::parser::Match match(false);
113 soulng::parser::Match* parentMatch10 = &match;
114 {
115 soulng::parser::Match match(false);
116 soulng::parser::Match* parentMatch11 = &match;
117 {
118 int64_t pos = lexer.GetPos();
119 soulng::lexer::Span span = lexer.GetSpan();
120 soulng::parser::Match match(true);
121 soulng::parser::Match* parentMatch12 = &match;
122 {
123 soulng::lexer::Span span = lexer.GetSpan();
124 soulng::parser::Match match = IdentifierParser::Identifier(lexer, moduleId);
125 id.reset(static_cast<IdentifierNode*>(match.value));
126 if (match.hit)
127 {
128 *parentMatch12 = match;
129 }
130 else
131 {
132 lexer.ThrowExpectationFailure(span, U"identifier");
133 }
134 }
135 if (match.hit)
136 {
137 v = span;
138 }
139 *parentMatch11 = match;
140 }
141 *parentMatch10 = match;
142 }
143 *parentMatch3 = match;
144 }
145 *parentMatch2 = match;
146 }
147 if (match.hit)
148 {
149 soulng::parser::Match match(false);
150 soulng::parser::Match* parentMatch13 = &match;
151 {
152 soulng::parser::Match match(false);
153 if (*lexer == ASSIGN)
154 {
155 ++lexer;
156 match.hit = true;
157 }
158 *parentMatch13 = match;
159 }
160 *parentMatch2 = match;
161 }
162 *parentMatch1 = match;
163 }
164 if (match.hit)
165 {
166 soulng::parser::Match match(false);
167 soulng::parser::Match* parentMatch14 = &match;
168 {
169 soulng::parser::Match match(false);
170 soulng::parser::Match* parentMatch15 = &match;
171 {
172 int64_t pos = lexer.GetPos();
173 soulng::parser::Match match = ExpressionParser::Expression(lexer, moduleId, ctx);
174 expr.reset(static_cast<Node*>(match.value));
175 if (match.hit)
176 {
177 e.reset(expr.release());
178 }
179 *parentMatch15 = match;
180 }
181 *parentMatch14 = match;
182 }
183 *parentMatch1 = match;
184 }
185 *parentMatch0 = match;
186 }
187 if (match.hit)
188 {
189 soulng::parser::Match match(false);
190 soulng::parser::Match* parentMatch16 = &match;
191 {
192 soulng::parser::Match match(false);
193 soulng::parser::Match* parentMatch17 = &match;
194 {
195 int64_t pos = lexer.GetPos();
196 soulng::parser::Match match(false);
197 if (*lexer == SEMICOLON)
198 {
199 ++lexer;
200 match.hit = true;
201 }
202 if (match.hit)
203 {
204 e->SetFullSpan();
205 v.end = e->GetSpan().end;
206 s.end = e->GetSpan().end;
207 ConstantNode* value = new ConstantNode(s, *moduleId, specifiers->value, type.release(), id.release(), e.release());
208 value->SetStrValue(lexer.GetMatch(v));
209 {
210 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
211
212 #endif // SOULNG_PARSER_DEBUG_SUPPORT
213 return soulng::parser::Match(true, value);
214 }
215 }
216 *parentMatch17 = match;
217 }
218 *parentMatch16 = match;
219 }
220 *parentMatch0 = match;
221 }
222 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
223
224
225
226
227
228 #endif // SOULNG_PARSER_DEBUG_SUPPORT
229 if (!match.hit)
230 {
231 match.value = nullptr;
232 }
233 return match;
234 }