1 #include "Interface.hpp"
2 #include <soulng/util/Unicode.hpp>
3 #include <sngcm/cmparser/Attribute.hpp>
4 #include <sngcm/cmparser/Specifier.hpp>
5 #include <sngcm/cmparser/Identifier.hpp>
6 #include <sngcm/cmparser/TypeExpr.hpp>
7 #include <sngcm/cmparser/Parameter.hpp>
8 #include <sngcm/cmlexer/CmajorLexer.hpp>
9 #include <sngcm/cmlexer/CmajorTokens.hpp>
10
11
12
13 using namespace soulng::unicode;
14 using namespace sngcm::ast;
15 using namespace CmajorTokens;
16
17 soulng::parser::Match InterfaceParser::Interface(CmajorLexer& lexer, boost::uuids::uuid* moduleId, ParsingContext* ctx)
18 {
19 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
20
21
22
23
24
25
26
27 #endif // SOULNG_PARSER_DEBUG_SUPPORT
28 std::unique_ptr<InterfaceNode> intf = std::unique_ptr<InterfaceNode>();
29 Span s = Span();
30 Span specifierSpan = Span();
31 Span beginBraceSpan = Span();
32 Span endBraceSpan = Span();
33 std::unique_ptr<sngcm::ast::AttributesNode> attrs;
34 std::unique_ptr<soulng::parser::soulng::parser::Value<sngcm::ast::Specifiers>>specifiers;
35 std::unique_ptr<IdentifierNode> id;
36 soulng::parser::Match match(false);
37 soulng::parser::Match* parentMatch0 = &match;
38 {
39 int64_t pos = lexer.GetPos();
40 soulng::parser::Match match(false);
41 soulng::parser::Match* parentMatch1 = &match;
42 {
43 soulng::parser::Match match(false);
44 soulng::parser::Match* parentMatch2 = &match;
45 {
46 soulng::parser::Match match(false);
47 soulng::parser::Match* parentMatch3 = &match;
48 {
49 soulng::parser::Match match(false);
50 soulng::parser::Match* parentMatch4 = &match;
51 {
52 soulng::parser::Match match(false);
53 soulng::parser::Match* parentMatch5 = &match;
54 {
55 soulng::parser::Match match(false);
56 soulng::parser::Match* parentMatch6 = &match;
57 {
58 soulng::parser::Match match(false);
59 soulng::parser::Match* parentMatch7 = &match;
60 {
61 soulng::parser::Match match(false);
62 soulng::parser::Match* parentMatch8 = &match;
63 {
64 soulng::parser::Match match(false);
65 soulng::parser::Match* parentMatch9 = &match;
66 {
67 int64_t pos = lexer.GetPos();
68 soulng::lexer::Span span = lexer.GetSpan();
69 soulng::parser::Match match(true);
70 if (match.hit)
71 {
72 s = span;
73 }
74 *parentMatch9 = match;
75 }
76 *parentMatch8 = match;
77 }
78 if (match.hit)
79 {
80 soulng::parser::Match match(false);
81 soulng::parser::Match* parentMatch10 = &match;
82 {
83 soulng::parser::Match match(true);
84 int64_t save = lexer.GetPos();
85 soulng::parser::Match* parentMatch11 = &match;
86 {
87 soulng::parser::Match match = AttributeParser::Attributes(lexer, moduleId);
88 attrs.reset(static_cast<sngcm::ast::AttributesNode*>(match.value));
89 if (match.hit)
90 {
91 *parentMatch11 = match;
92 }
93 else
94 {
95 lexer.SetPos(save);
96 }
97 }
98 *parentMatch10 = match;
99 }
100 *parentMatch8 = match;
101 }
102 *parentMatch7 = match;
103 }
104 if (match.hit)
105 {
106 soulng::parser::Match match(false);
107 soulng::parser::Match* parentMatch12 = &match;
108 {
109 soulng::parser::Match match(false);
110 soulng::parser::Match* parentMatch13 = &match;
111 {
112 int64_t pos = lexer.GetPos();
113 soulng::lexer::Span span = lexer.GetSpan();
114 soulng::parser::Match match = SpecifierParser::Specifiers(lexer);
115 specifiers.reset(static_cast<soulng::parser::soulng::parser::Value<sngcm::ast::Specifiers>*>(match.value));
116 if (match.hit)
117 {
118 specifierSpan = span;
119 }
120 *parentMatch13 = match;
121 }
122 *parentMatch12 = match;
123 }
124 *parentMatch7 = match;
125 }
126 *parentMatch6 = match;
127 }
128 if (match.hit)
129 {
130 soulng::parser::Match match(false);
131 soulng::parser::Match* parentMatch14 = &match;
132 {
133 soulng::parser::Match match(false);
134 if (*lexer == INTERFACE)
135 {
136 ++lexer;
137 match.hit = true;
138 }
139 *parentMatch14 = match;
140 }
141 *parentMatch6 = match;
142 }
143 *parentMatch5 = match;
144 }
145 if (match.hit)
146 {
147 soulng::parser::Match match(false);
148 soulng::parser::Match* parentMatch15 = &match;
149 {
150 soulng::parser::Match match(false);
151 soulng::parser::Match* parentMatch16 = &match;
152 {
153 int64_t pos = lexer.GetPos();
154 soulng::lexer::Span span = lexer.GetSpan();
155 soulng::parser::Match match(true);
156 soulng::parser::Match* parentMatch17 = &match;
157 {
158 soulng::lexer::Span span = lexer.GetSpan();
159 soulng::parser::Match match = IdentifierParser::Identifier(lexer, moduleId);
160 id.reset(static_cast<IdentifierNode*>(match.value));
161 if (match.hit)
162 {
163 *parentMatch17 = match;
164 }
165 else
166 {
167 lexer.ThrowExpectationFailure(span, U"identifier");
168 }
169 }
170 if (match.hit)
171 {
172 s.end = span.end;
173 intf.reset(new InterfaceNode(s, *moduleId, specifiers->value, id.release(), attrs.release()));
174 intf->SetSpecifierSpan(specifierSpan);
175 }
176 *parentMatch16 = match;
177 }
178 *parentMatch15 = match;
179 }
180 *parentMatch5 = match;
181 }
182 *parentMatch4 = match;
183 }
184 if (match.hit)
185 {
186 soulng::parser::Match match(false);
187 soulng::parser::Match* parentMatch18 = &match;
188 {
189 soulng::parser::Match match(false);
190 soulng::parser::Match* parentMatch19 = &match;
191 {
192 int64_t pos = lexer.GetPos();
193 soulng::lexer::Span span = lexer.GetSpan();
194 soulng::parser::Match match(true);
195 soulng::parser::Match* parentMatch20 = &match;
196 {
197 soulng::lexer::Span span = lexer.GetSpan();
198 soulng::parser::Match match(false);
199 if (*lexer == LBRACE)
200 {
201 ++lexer;
202 match.hit = true;
203 }
204 if (match.hit)
205 {
206 *parentMatch20 = match;
207 }
208 else
209 {
210 lexer.ThrowExpectationFailure(span, ToUtf32(GetTokenInfo(LBRACE)));
211 }
212 }
213 if (match.hit)
214 {
215 beginBraceSpan = span;
216 }
217 *parentMatch19 = match;
218 }
219 *parentMatch18 = match;
220 }
221 *parentMatch4 = match;
222 }
223 *parentMatch3 = match;
224 }
225 if (match.hit)
226 {
227 soulng::parser::Match match(false);
228 soulng::parser::Match* parentMatch21 = &match;
229 {
230 soulng::parser::Match match = InterfaceParser::InterfaceContent(lexer, moduleId, ctx, intf.get());
231 *parentMatch21 = match;
232 }
233 *parentMatch3 = match;
234 }
235 *parentMatch2 = match;
236 }
237 if (match.hit)
238 {
239 soulng::parser::Match match(false);
240 soulng::parser::Match* parentMatch22 = &match;
241 {
242 soulng::parser::Match match(false);
243 soulng::parser::Match* parentMatch23 = &match;
244 {
245 int64_t pos = lexer.GetPos();
246 soulng::lexer::Span span = lexer.GetSpan();
247 soulng::parser::Match match(true);
248 soulng::parser::Match* parentMatch24 = &match;
249 {
250 soulng::lexer::Span span = lexer.GetSpan();
251 soulng::parser::Match match(false);
252 if (*lexer == RBRACE)
253 {
254 ++lexer;
255 match.hit = true;
256 }
257 if (match.hit)
258 {
259 *parentMatch24 = match;
260 }
261 else
262 {
263 lexer.ThrowExpectationFailure(span, ToUtf32(GetTokenInfo(RBRACE)));
264 }
265 }
266 if (match.hit)
267 {
268 endBraceSpan = span;
269 intf->SetBeginBraceSpan(beginBraceSpan);
270 intf->SetEndBraceSpan(endBraceSpan);
271 }
272 *parentMatch23 = match;
273 }
274 *parentMatch22 = match;
275 }
276 *parentMatch2 = match;
277 }
278 *parentMatch1 = match;
279 }
280 if (match.hit)
281 {
282 {
283 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
284
285 #endif // SOULNG_PARSER_DEBUG_SUPPORT
286 return soulng::parser::Match(true, intf.release());
287 }
288 }
289 *parentMatch0 = match;
290 }
291 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
292
293
294
295
296
297 #endif // SOULNG_PARSER_DEBUG_SUPPORT
298 if (!match.hit)
299 {
300 match.value = nullptr;
301 }
302 return match;
303 }
304
305 soulng::parser::Match InterfaceParser::InterfaceContent(CmajorLexer& lexer, boost::uuids::uuid* moduleId, ParsingContext* ctx, sngcm::ast::InterfaceNode* intf)
306 {
307 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
308
309
310
311
312
313
314
315 #endif // SOULNG_PARSER_DEBUG_SUPPORT
316 std::unique_ptr<Node> intfMemFun;
317 soulng::parser::Match match(true);
318 soulng::parser::Match* parentMatch0 = &match;
319 {
320 while (true)
321 {
322 int64_t save = lexer.GetPos();
323 {
324 soulng::parser::Match match(false);
325 soulng::parser::Match* parentMatch1 = &match;
326 {
327 soulng::parser::Match match(false);
328 soulng::parser::Match* parentMatch2 = &match;
329 {
330 int64_t pos = lexer.GetPos();
331 soulng::parser::Match match = InterfaceParser::InterfaceMemFun(lexer, moduleId, ctx);
332 intfMemFun.reset(static_cast<Node*>(match.value));
333 if (match.hit)
334 {
335 intf->AddMember(intfMemFun.release());
336 }
337 *parentMatch2 = match;
338 }
339 *parentMatch1 = match;
340 }
341 if (match.hit)
342 {
343 *parentMatch0 = match;
344 }
345 else
346 {
347 lexer.SetPos(save);
348 break;
349 }
350 }
351 }
352 }
353 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
354
355
356
357
358
359 #endif // SOULNG_PARSER_DEBUG_SUPPORT
360 if (!match.hit)
361 {
362 match.value = nullptr;
363 }
364 return match;
365 }
366
367 soulng::parser::Match InterfaceParser::InterfaceMemFun(CmajorLexer& lexer, boost::uuids::uuid* moduleId, ParsingContext* ctx)
368 {
369 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
370
371
372
373
374
375
376
377 #endif // SOULNG_PARSER_DEBUG_SUPPORT
378 std::unique_ptr<MemberFunctionNode> memFun = std::unique_ptr<MemberFunctionNode>();
379 Span s = Span();
380 std::unique_ptr<sngcm::ast::AttributesNode> attrs;
381 std::unique_ptr<sngcm::ast::Node> returnType;
382 std::unique_ptr<soulng::parser::soulng::parser::Value<std::u32string>>groupId;
383 soulng::parser::Match match(false);
384 soulng::parser::Match* parentMatch0 = &match;
385 {
386 soulng::parser::Match match(false);
387 soulng::parser::Match* parentMatch1 = &match;
388 {
389 soulng::parser::Match match(false);
390 soulng::parser::Match* parentMatch2 = &match;
391 {
392 soulng::parser::Match match(false);
393 soulng::parser::Match* parentMatch3 = &match;
394 {
395 soulng::parser::Match match(false);
396 soulng::parser::Match* parentMatch4 = &match;
397 {
398 soulng::parser::Match match(false);
399 soulng::parser::Match* parentMatch5 = &match;
400 {
401 int64_t pos = lexer.GetPos();
402 soulng::lexer::Span span = lexer.GetSpan();
403 soulng::parser::Match match(true);
404 if (match.hit)
405 {
406 s = span;
407 }
408 *parentMatch5 = match;
409 }
410 *parentMatch4 = match;
411 }
412 if (match.hit)
413 {
414 soulng::parser::Match match(false);
415 soulng::parser::Match* parentMatch6 = &match;
416 {
417 soulng::parser::Match match(true);
418 int64_t save = lexer.GetPos();
419 soulng::parser::Match* parentMatch7 = &match;
420 {
421 soulng::parser::Match match = AttributeParser::Attributes(lexer, moduleId);
422 attrs.reset(static_cast<sngcm::ast::AttributesNode*>(match.value));
423 if (match.hit)
424 {
425 *parentMatch7 = match;
426 }
427 else
428 {
429 lexer.SetPos(save);
430 }
431 }
432 *parentMatch6 = match;
433 }
434 *parentMatch4 = match;
435 }
436 *parentMatch3 = match;
437 }
438 if (match.hit)
439 {
440 soulng::parser::Match match(false);
441 soulng::parser::Match* parentMatch8 = &match;
442 {
443 soulng::parser::Match match = TypeExprParser::TypeExpr(lexer, moduleId, ctx);
444 returnType.reset(static_cast<sngcm::ast::Node*>(match.value));
445 *parentMatch8 = match;
446 }
447 *parentMatch3 = match;
448 }
449 *parentMatch2 = match;
450 }
451 if (match.hit)
452 {
453 soulng::parser::Match match(false);
454 soulng::parser::Match* parentMatch9 = &match;
455 {
456 soulng::parser::Match match(false);
457 soulng::parser::Match* parentMatch10 = &match;
458 {
459 int64_t pos = lexer.GetPos();
460 soulng::lexer::Span span = lexer.GetSpan();
461 soulng::parser::Match match(true);
462 soulng::parser::Match* parentMatch11 = &match;
463 {
464 soulng::lexer::Span span = lexer.GetSpan();
465 soulng::parser::Match match = InterfaceParser::InterfaceFunctionGroupId(lexer);
466 groupId.reset(static_cast<soulng::parser::soulng::parser::Value<std::u32string>*>(match.value));
467 if (match.hit)
468 {
469 *parentMatch11 = match;
470 }
471 else
472 {
473 lexer.ThrowExpectationFailure(span, U"interface function group identifier");
474 }
475 }
476 if (match.hit)
477 {
478 s.end = span.end;
479 memFun.reset(new MemberFunctionNode(s, *moduleId, Specifiers(), returnType.release(), groupId->value, attrs.release()));
480 }
481 *parentMatch10 = match;
482 }
483 *parentMatch9 = match;
484 }
485 *parentMatch2 = match;
486 }
487 *parentMatch1 = match;
488 }
489 if (match.hit)
490 {
491 soulng::parser::Match match(false);
492 soulng::parser::Match* parentMatch12 = &match;
493 {
494 soulng::parser::Match match(true);
495 soulng::parser::Match* parentMatch13 = &match;
496 {
497 soulng::lexer::Span span = lexer.GetSpan();
498 soulng::parser::Match match = ParameterParser::ParameterList(lexer, moduleId, ctx, memFun.get());
499 if (match.hit)
500 {
501 *parentMatch13 = match;
502 }
503 else
504 {
505 lexer.ThrowExpectationFailure(span, U"parameter list");
506 }
507 }
508 *parentMatch12 = match;
509 }
510 *parentMatch1 = match;
511 }
512 *parentMatch0 = match;
513 }
514 if (match.hit)
515 {
516 soulng::parser::Match match(false);
517 soulng::parser::Match* parentMatch14 = &match;
518 {
519 soulng::parser::Match match(false);
520 soulng::parser::Match* parentMatch15 = &match;
521 {
522 int64_t pos = lexer.GetPos();
523 soulng::parser::Match match(true);
524 soulng::parser::Match* parentMatch16 = &match;
525 {
526 soulng::lexer::Span span = lexer.GetSpan();
527 soulng::parser::Match match(false);
528 if (*lexer == SEMICOLON)
529 {
530 ++lexer;
531 match.hit = true;
532 }
533 if (match.hit)
534 {
535 *parentMatch16 = match;
536 }
537 else
538 {
539 lexer.ThrowExpectationFailure(span, ToUtf32(GetTokenInfo(SEMICOLON)));
540 }
541 }
542 if (match.hit)
543 {
544 {
545 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
546
547 #endif // SOULNG_PARSER_DEBUG_SUPPORT
548 return soulng::parser::Match(true, memFun.release());
549 }
550 }
551 *parentMatch15 = match;
552 }
553 *parentMatch14 = match;
554 }
555 *parentMatch0 = match;
556 }
557 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
558
559
560
561
562
563 #endif // SOULNG_PARSER_DEBUG_SUPPORT
564 if (!match.hit)
565 {
566 match.value = nullptr;
567 }
568 return match;
569 }
570
571 soulng::parser::Match InterfaceParser::InterfaceFunctionGroupId(CmajorLexer& lexer)
572 {
573 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
574
575
576
577
578
579
580
581 #endif // SOULNG_PARSER_DEBUG_SUPPORT
582 soulng::parser::Match match(false);
583 soulng::parser::Match* parentMatch0 = &match;
584 {
585 int64_t pos = lexer.GetPos();
586 soulng::lexer::Span span = lexer.GetSpan();
587 soulng::parser::Match match(false);
588 if (*lexer == ID)
589 {
590 ++lexer;
591 match.hit = true;
592 }
593 if (match.hit)
594 {
595 {
596 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
597
598 #endif // SOULNG_PARSER_DEBUG_SUPPORT
599 return soulng::parser::Match(true, new soulng::parser::Value<std::u32string>(lexer.GetMatch(span)));
600 }
601 }
602 *parentMatch0 = match;
603 }
604 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
605
606
607
608
609
610 #endif // SOULNG_PARSER_DEBUG_SUPPORT
611 if (!match.hit)
612 {
613 match.value = nullptr;
614 }
615 return match;
616 }