1 #include "Template.hpp"
2 #include <soulng/util/Unicode.hpp>
3 #include <sngcpp/parser/Declaration.hpp>
4 #include <sngcpp/parser/Expression.hpp>
5 #include <sngcpp/parser/Function.hpp>
6 #include <sngcpp/parser/Identifier.hpp>
7 #include <sngcpp/parser/TypeExpr.hpp>
8 #include <sngcpp/lexer/CppLexer.hpp>
9 #include <sngcpp/lexer/CppTokens.hpp>
10
11
12
13 using namespace soulng::unicode;
14 using namespace CppTokens;
15 using namespace soulng::lexer;
16
17 soulng::parser::Match TemplateParser::TemplateDeclaration(CppLexer& lexer, sngcpp::cppparser::ParsingContext* ctx)
18 {
19 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
20
21
22
23
24
25
26
27 #endif // SOULNG_PARSER_DEBUG_SUPPORT
28 Span s = Span();
29 std::unique_ptr<sngcpp::ast::Node> templateParameterList;
30 std::unique_ptr<sngcpp::ast::Node> declaration;
31 soulng::parser::Match match(false);
32 soulng::parser::Match* parentMatch0 = &match;
33 {
34 soulng::parser::Match match(false);
35 soulng::parser::Match* parentMatch1 = &match;
36 {
37 soulng::parser::Match match(false);
38 soulng::parser::Match* parentMatch2 = &match;
39 {
40 soulng::parser::Match match(false);
41 soulng::parser::Match* parentMatch3 = &match;
42 {
43 soulng::parser::Match match(false);
44 soulng::parser::Match* parentMatch4 = &match;
45 {
46 int64_t pos = lexer.GetPos();
47 soulng::lexer::Span span = lexer.GetSpan();
48 soulng::parser::Match match(false);
49 if (*lexer == TEMPLATE)
50 {
51 ++lexer;
52 match.hit = true;
53 }
54 if (match.hit)
55 {
56 s = span;
57 }
58 *parentMatch4 = match;
59 }
60 *parentMatch3 = match;
61 }
62 if (match.hit)
63 {
64 soulng::parser::Match match(false);
65 soulng::parser::Match* parentMatch5 = &match;
66 {
67 soulng::parser::Match match(false);
68 if (*lexer == LANGLE)
69 {
70 ++lexer;
71 match.hit = true;
72 }
73 *parentMatch5 = match;
74 }
75 *parentMatch3 = match;
76 }
77 *parentMatch2 = match;
78 }
79 if (match.hit)
80 {
81 soulng::parser::Match match(false);
82 soulng::parser::Match* parentMatch6 = &match;
83 {
84 soulng::parser::Match match = TemplateParser::TemplateParameterList(lexer, ctx);
85 templateParameterList.reset(static_cast<sngcpp::ast::Node*>(match.value));
86 *parentMatch6 = match;
87 }
88 *parentMatch2 = match;
89 }
90 *parentMatch1 = match;
91 }
92 if (match.hit)
93 {
94 soulng::parser::Match match(false);
95 soulng::parser::Match* parentMatch7 = &match;
96 {
97 soulng::parser::Match match(true);
98 soulng::parser::Match* parentMatch8 = &match;
99 {
100 soulng::lexer::Span span = lexer.GetSpan();
101 soulng::parser::Match match(false);
102 if (*lexer == RANGLE)
103 {
104 ++lexer;
105 match.hit = true;
106 }
107 if (match.hit)
108 {
109 *parentMatch8 = match;
110 }
111 else
112 {
113 lexer.ThrowExpectationFailure(span, ToUtf32(GetTokenInfo(RANGLE)));
114 }
115 }
116 *parentMatch7 = match;
117 }
118 *parentMatch1 = match;
119 }
120 *parentMatch0 = match;
121 }
122 if (match.hit)
123 {
124 soulng::parser::Match match(false);
125 soulng::parser::Match* parentMatch9 = &match;
126 {
127 soulng::parser::Match match(false);
128 soulng::parser::Match* parentMatch10 = &match;
129 {
130 int64_t pos = lexer.GetPos();
131 soulng::lexer::Span span = lexer.GetSpan();
132 soulng::parser::Match match(true);
133 soulng::parser::Match* parentMatch11 = &match;
134 {
135 soulng::lexer::Span span = lexer.GetSpan();
136 soulng::parser::Match match = DeclarationParser::Declaration(lexer, ctx);
137 declaration.reset(static_cast<sngcpp::ast::Node*>(match.value));
138 if (match.hit)
139 {
140 *parentMatch11 = match;
141 }
142 else
143 {
144 lexer.ThrowExpectationFailure(span, U"Declaration");
145 }
146 }
147 if (match.hit)
148 {
149 s.end = span.end;
150 {
151 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
152
153 #endif // SOULNG_PARSER_DEBUG_SUPPORT
154 return soulng::parser::Match(true, new sngcpp::ast::TemplateDeclarationNode(s, templateParameterList.release(), declaration.release()));
155 }
156 }
157 *parentMatch10 = match;
158 }
159 *parentMatch9 = match;
160 }
161 *parentMatch0 = match;
162 }
163 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
164
165
166
167
168
169 #endif // SOULNG_PARSER_DEBUG_SUPPORT
170 if (!match.hit)
171 {
172 match.value = nullptr;
173 }
174 return match;
175 }
176
177 soulng::parser::Match TemplateParser::TemplateParameterList(CppLexer& lexer, sngcpp::cppparser::ParsingContext* ctx)
178 {
179 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
180
181
182
183
184
185
186
187 #endif // SOULNG_PARSER_DEBUG_SUPPORT
188 std::unique_ptr<sngcpp::ast::Node> node = std::unique_ptr<sngcpp::ast::Node>();
189 Span s = Span();
190 std::unique_ptr<sngcpp::ast::Node> left;
191 std::unique_ptr<sngcpp::ast::Node> right;
192 soulng::parser::Match match(false);
193 soulng::parser::Match* parentMatch0 = &match;
194 {
195 int64_t pos = lexer.GetPos();
196 soulng::parser::Match match(false);
197 soulng::parser::Match* parentMatch1 = &match;
198 {
199 soulng::parser::Match match(false);
200 soulng::parser::Match* parentMatch2 = &match;
201 {
202 soulng::parser::Match match(false);
203 soulng::parser::Match* parentMatch3 = &match;
204 {
205 int64_t pos = lexer.GetPos();
206 soulng::lexer::Span span = lexer.GetSpan();
207 soulng::parser::Match match = TemplateParser::TemplateParameter(lexer, ctx);
208 left.reset(static_cast<sngcpp::ast::Node*>(match.value));
209 if (match.hit)
210 {
211 s = span;
212 node.reset(left.release());
213 }
214 *parentMatch3 = match;
215 }
216 *parentMatch2 = match;
217 }
218 if (match.hit)
219 {
220 soulng::parser::Match match(false);
221 soulng::parser::Match* parentMatch4 = &match;
222 {
223 soulng::parser::Match match(true);
224 soulng::parser::Match* parentMatch5 = &match;
225 {
226 while (true)
227 {
228 int64_t save = lexer.GetPos();
229 {
230 soulng::parser::Match match(false);
231 soulng::parser::Match* parentMatch6 = &match;
232 {
233 soulng::parser::Match match(false);
234 soulng::parser::Match* parentMatch7 = &match;
235 {
236 soulng::parser::Match match(false);
237 if (*lexer == COMMA)
238 {
239 ++lexer;
240 match.hit = true;
241 }
242 *parentMatch7 = match;
243 }
244 if (match.hit)
245 {
246 soulng::parser::Match match(false);
247 soulng::parser::Match* parentMatch8 = &match;
248 {
249 soulng::parser::Match match(false);
250 soulng::parser::Match* parentMatch9 = &match;
251 {
252 int64_t pos = lexer.GetPos();
253 soulng::lexer::Span span = lexer.GetSpan();
254 soulng::parser::Match match = TemplateParser::TemplateParameter(lexer, ctx);
255 right.reset(static_cast<sngcpp::ast::Node*>(match.value));
256 if (match.hit)
257 {
258 s.end = span.end;
259 node.reset(new sngcpp::ast::TemplateParameterSequenceNode(s, node.release(), right.release()));
260 }
261 *parentMatch9 = match;
262 }
263 *parentMatch8 = match;
264 }
265 *parentMatch7 = match;
266 }
267 *parentMatch6 = match;
268 }
269 if (match.hit)
270 {
271 *parentMatch5 = match;
272 }
273 else
274 {
275 lexer.SetPos(save);
276 break;
277 }
278 }
279 }
280 }
281 *parentMatch4 = match;
282 }
283 *parentMatch2 = match;
284 }
285 *parentMatch1 = match;
286 }
287 if (match.hit)
288 {
289 {
290 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
291
292 #endif // SOULNG_PARSER_DEBUG_SUPPORT
293 return soulng::parser::Match(true, node.release());
294 }
295 }
296 *parentMatch0 = match;
297 }
298 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
299
300
301
302
303
304 #endif // SOULNG_PARSER_DEBUG_SUPPORT
305 if (!match.hit)
306 {
307 match.value = nullptr;
308 }
309 return match;
310 }
311
312 soulng::parser::Match TemplateParser::TemplateParameter(CppLexer& lexer, sngcpp::cppparser::ParsingContext* ctx)
313 {
314 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
315
316
317
318
319
320
321
322 #endif // SOULNG_PARSER_DEBUG_SUPPORT
323 std::unique_ptr<sngcpp::ast::Node> typeParam;
324 std::unique_ptr<sngcpp::ast::Node> paramDeclaration;
325 soulng::parser::Match match(false);
326 soulng::parser::Match* parentMatch0 = &match;
327 {
328 int64_t save = lexer.GetPos();
329 soulng::parser::Match match(false);
330 soulng::parser::Match* parentMatch1 = &match;
331 {
332 int64_t pos = lexer.GetPos();
333 soulng::parser::Match match = TemplateParser::TypeParameter(lexer, ctx);
334 typeParam.reset(static_cast<sngcpp::ast::Node*>(match.value));
335 if (match.hit)
336 {
337 {
338 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
339
340 #endif // SOULNG_PARSER_DEBUG_SUPPORT
341 return soulng::parser::Match(true, typeParam.release());
342 }
343 }
344 *parentMatch1 = match;
345 }
346 *parentMatch0 = match;
347 if (!match.hit)
348 {
349 soulng::parser::Match match(false);
350 soulng::parser::Match* parentMatch2 = &match;
351 lexer.SetPos(save);
352 {
353 soulng::parser::Match match(false);
354 soulng::parser::Match* parentMatch3 = &match;
355 {
356 int64_t pos = lexer.GetPos();
357 soulng::parser::Match match = FunctionParser::ParameterDeclaration(lexer, ctx);
358 paramDeclaration.reset(static_cast<sngcpp::ast::Node*>(match.value));
359 if (match.hit)
360 {
361 {
362 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
363
364 #endif // SOULNG_PARSER_DEBUG_SUPPORT
365 return soulng::parser::Match(true, paramDeclaration.release());
366 }
367 }
368 *parentMatch3 = match;
369 }
370 *parentMatch2 = match;
371 }
372 *parentMatch0 = match;
373 }
374 }
375 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
376
377
378
379
380
381 #endif // SOULNG_PARSER_DEBUG_SUPPORT
382 if (!match.hit)
383 {
384 match.value = nullptr;
385 }
386 return match;
387 }
388
389 soulng::parser::Match TemplateParser::TypeParameter(CppLexer& lexer, sngcpp::cppparser::ParsingContext* ctx)
390 {
391 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
392
393
394
395
396
397
398
399 #endif // SOULNG_PARSER_DEBUG_SUPPORT
400 bool typenameUsed = bool();
401 Span s = Span();
402 std::unique_ptr<soulng::parser::soulng::parser::Value<std::u32string>>id;
403 std::unique_ptr<sngcpp::ast::Node> typeExpr;
404 soulng::parser::Match match(false);
405 soulng::parser::Match* parentMatch0 = &match;
406 {
407 int64_t pos = lexer.GetPos();
408 soulng::parser::Match match(false);
409 soulng::parser::Match* parentMatch1 = &match;
410 {
411 soulng::parser::Match match(false);
412 soulng::parser::Match* parentMatch2 = &match;
413 {
414 soulng::parser::Match match(false);
415 soulng::parser::Match* parentMatch3 = &match;
416 {
417 soulng::parser::Match match(false);
418 soulng::parser::Match* parentMatch4 = &match;
419 {
420 soulng::parser::Match match(false);
421 soulng::parser::Match* parentMatch5 = &match;
422 {
423 int64_t save = lexer.GetPos();
424 soulng::parser::Match match(false);
425 soulng::parser::Match* parentMatch6 = &match;
426 {
427 int64_t pos = lexer.GetPos();
428 soulng::lexer::Span span = lexer.GetSpan();
429 soulng::parser::Match match(false);
430 if (*lexer == CLASS)
431 {
432 ++lexer;
433 match.hit = true;
434 }
435 if (match.hit)
436 {
437 s = span;
438 typenameUsed = false;
439 }
440 *parentMatch6 = match;
441 }
442 *parentMatch5 = match;
443 if (!match.hit)
444 {
445 soulng::parser::Match match(false);
446 soulng::parser::Match* parentMatch7 = &match;
447 lexer.SetPos(save);
448 {
449 soulng::parser::Match match(false);
450 soulng::parser::Match* parentMatch8 = &match;
451 {
452 int64_t pos = lexer.GetPos();
453 soulng::lexer::Span span = lexer.GetSpan();
454 soulng::parser::Match match(false);
455 if (*lexer == TYPENAME)
456 {
457 ++lexer;
458 match.hit = true;
459 }
460 if (match.hit)
461 {
462 s = span;
463 typenameUsed = true;
464 }
465 *parentMatch8 = match;
466 }
467 *parentMatch7 = match;
468 }
469 *parentMatch5 = match;
470 }
471 }
472 *parentMatch4 = match;
473 }
474 *parentMatch3 = match;
475 }
476 if (match.hit)
477 {
478 soulng::parser::Match match(false);
479 soulng::parser::Match* parentMatch9 = &match;
480 {
481 soulng::parser::Match match(false);
482 soulng::parser::Match* parentMatch10 = &match;
483 {
484 int64_t pos = lexer.GetPos();
485 soulng::lexer::Span span = lexer.GetSpan();
486 soulng::parser::Match match = IdentifierParser::Identifier(lexer);
487 id.reset(static_cast<soulng::parser::soulng::parser::Value<std::u32string>*>(match.value));
488 if (match.hit)
489 {
490 s.end = span.end;
491 }
492 *parentMatch10 = match;
493 }
494 *parentMatch9 = match;
495 }
496 *parentMatch3 = match;
497 }
498 *parentMatch2 = match;
499 }
500 if (match.hit)
501 {
502 soulng::parser::Match match(false);
503 soulng::parser::Match* parentMatch11 = &match;
504 {
505 soulng::parser::Match match(true);
506 int64_t save = lexer.GetPos();
507 soulng::parser::Match* parentMatch12 = &match;
508 {
509 soulng::parser::Match match(false);
510 soulng::parser::Match* parentMatch13 = &match;
511 {
512 soulng::parser::Match match(false);
513 soulng::parser::Match* parentMatch14 = &match;
514 {
515 soulng::parser::Match match(false);
516 if (*lexer == ASSIGN)
517 {
518 ++lexer;
519 match.hit = true;
520 }
521 *parentMatch14 = match;
522 }
523 if (match.hit)
524 {
525 soulng::parser::Match match(false);
526 soulng::parser::Match* parentMatch15 = &match;
527 {
528 soulng::parser::Match match(false);
529 soulng::parser::Match* parentMatch16 = &match;
530 {
531 int64_t pos = lexer.GetPos();
532 soulng::lexer::Span span = lexer.GetSpan();
533 soulng::parser::Match match = TypeExprParser::TypeExpr(lexer, ctx);
534 typeExpr.reset(static_cast<sngcpp::ast::Node*>(match.value));
535 if (match.hit)
536 {
537 s.end = span.end;
538 }
539 *parentMatch16 = match;
540 }
541 *parentMatch15 = match;
542 }
543 *parentMatch14 = match;
544 }
545 *parentMatch13 = match;
546 }
547 if (match.hit)
548 {
549 *parentMatch12 = match;
550 }
551 else
552 {
553 lexer.SetPos(save);
554 }
555 }
556 *parentMatch11 = match;
557 }
558 *parentMatch2 = match;
559 }
560 *parentMatch1 = match;
561 }
562 if (match.hit)
563 {
564 {
565 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
566
567 #endif // SOULNG_PARSER_DEBUG_SUPPORT
568 return soulng::parser::Match(true, new sngcpp::ast::TypeParameterNode(s, id->value, typeExpr.release(), typenameUsed));
569 }
570 }
571 *parentMatch0 = match;
572 }
573 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
574
575
576
577
578
579 #endif // SOULNG_PARSER_DEBUG_SUPPORT
580 if (!match.hit)
581 {
582 match.value = nullptr;
583 }
584 return match;
585 }
586
587 soulng::parser::Match TemplateParser::SimpleTemplateId(CppLexer& lexer, sngcpp::cppparser::ParsingContext* ctx)
588 {
589 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
590
591
592
593
594
595
596
597 #endif // SOULNG_PARSER_DEBUG_SUPPORT
598 int arity = int();
599 Span s = Span();
600 std::unique_ptr<sngcpp::ast::IdentifierNode> templateName;
601 std::unique_ptr<sngcpp::ast::Node> args;
602 soulng::parser::Match match(false);
603 soulng::parser::Match* parentMatch0 = &match;
604 {
605 int64_t pos = lexer.GetPos();
606 soulng::lexer::Span span = lexer.GetSpan();
607 soulng::parser::Match match(false);
608 soulng::parser::Match* parentMatch1 = &match;
609 {
610 soulng::parser::Match match(false);
611 soulng::parser::Match* parentMatch2 = &match;
612 {
613 soulng::parser::Match match(false);
614 soulng::parser::Match* parentMatch3 = &match;
615 {
616 soulng::parser::Match match(false);
617 soulng::parser::Match* parentMatch4 = &match;
618 {
619 soulng::parser::Match match(false);
620 soulng::parser::Match* parentMatch5 = &match;
621 {
622 int64_t pos = lexer.GetPos();
623 soulng::lexer::Span span = lexer.GetSpan();
624 soulng::parser::Match match = TemplateParser::TemplateName(lexer);
625 templateName.reset(static_cast<sngcpp::ast::IdentifierNode*>(match.value));
626 if (match.hit)
627 {
628 s = span;
629 }
630 *parentMatch5 = match;
631 }
632 *parentMatch4 = match;
633 }
634 if (match.hit)
635 {
636 soulng::parser::Match match(false);
637 soulng::parser::Match* parentMatch6 = &match;
638 {
639 soulng::parser::Match match(false);
640 soulng::parser::Match* parentMatch7 = &match;
641 {
642 int64_t pos = lexer.GetPos();
643 soulng::parser::Match match(false);
644 if (*lexer == LANGLE)
645 {
646 ++lexer;
647 match.hit = true;
648 }
649 if (match.hit)
650 {
651 ++lexer.langleCount;
652 ctx->BeginParsingTemplateId();
653 }
654 *parentMatch7 = match;
655 }
656 *parentMatch6 = match;
657 }
658 *parentMatch4 = match;
659 }
660 *parentMatch3 = match;
661 }
662 if (match.hit)
663 {
664 soulng::parser::Match match(false);
665 soulng::parser::Match* parentMatch8 = &match;
666 {
667 soulng::parser::Match match(true);
668 int64_t save = lexer.GetPos();
669 soulng::parser::Match* parentMatch9 = &match;
670 {
671 soulng::parser::Match match = TemplateParser::TemplateArgumentList(lexer, ctx, &arity);
672 args.reset(static_cast<sngcpp::ast::Node*>(match.value));
673 if (match.hit)
674 {
675 *parentMatch9 = match;
676 }
677 else
678 {
679 lexer.SetPos(save);
680 }
681 }
682 *parentMatch8 = match;
683 }
684 *parentMatch3 = match;
685 }
686 *parentMatch2 = match;
687 }
688 if (match.hit)
689 {
690 soulng::parser::Match match(false);
691 soulng::parser::Match* parentMatch10 = &match;
692 {
693 soulng::parser::Match match(false);
694 soulng::parser::Match* parentMatch11 = &match;
695 {
696 int64_t pos = lexer.GetPos();
697 soulng::parser::Match match(false);
698 if (*lexer == RANGLE)
699 {
700 ++lexer;
701 match.hit = true;
702 }
703 if (match.hit)
704 {
705 --lexer.langleCount;
706 ctx->EndParsingTemplateId();
707 }
708 else
709 {
710 --lexer.langleCount;
711 ctx->EndParsingTemplateId();
712 }
713 *parentMatch11 = match;
714 }
715 *parentMatch10 = match;
716 }
717 *parentMatch2 = match;
718 }
719 *parentMatch1 = match;
720 }
721 if (match.hit)
722 {
723 s.end = span.end;
724 {
725 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
726
727 #endif // SOULNG_PARSER_DEBUG_SUPPORT
728 return soulng::parser::Match(true, new sngcpp::ast::TemplateIdNode(s, templateName.release(), args.release(), arity));
729 }
730 }
731 *parentMatch0 = match;
732 }
733 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
734
735
736
737
738
739 #endif // SOULNG_PARSER_DEBUG_SUPPORT
740 if (!match.hit)
741 {
742 match.value = nullptr;
743 }
744 return match;
745 }
746
747 soulng::parser::Match TemplateParser::TemplateId(CppLexer& lexer, sngcpp::cppparser::ParsingContext* ctx)
748 {
749 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
750
751
752
753
754
755
756
757 #endif // SOULNG_PARSER_DEBUG_SUPPORT
758 std::unique_ptr<sngcpp::ast::Node> simpleTemplateId;
759 soulng::parser::Match match(false);
760 soulng::parser::Match* parentMatch0 = &match;
761 {
762 int64_t pos = lexer.GetPos();
763 soulng::parser::Match match = TemplateParser::SimpleTemplateId(lexer, ctx);
764 simpleTemplateId.reset(static_cast<sngcpp::ast::Node*>(match.value));
765 if (match.hit)
766 {
767 {
768 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
769
770 #endif // SOULNG_PARSER_DEBUG_SUPPORT
771 return soulng::parser::Match(true, simpleTemplateId.release());
772 }
773 }
774 *parentMatch0 = match;
775 }
776 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
777
778
779
780
781
782 #endif // SOULNG_PARSER_DEBUG_SUPPORT
783 if (!match.hit)
784 {
785 match.value = nullptr;
786 }
787 return match;
788 }
789
790 soulng::parser::Match TemplateParser::TemplateName(CppLexer& lexer)
791 {
792 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
793
794
795
796
797
798
799
800 #endif // SOULNG_PARSER_DEBUG_SUPPORT
801 std::unique_ptr<soulng::parser::soulng::parser::Value<std::u32string>>id;
802 soulng::parser::Match match(false);
803 soulng::parser::Match* parentMatch0 = &match;
804 {
805 int64_t pos = lexer.GetPos();
806 soulng::lexer::Span span = lexer.GetSpan();
807 soulng::parser::Match match = IdentifierParser::Identifier(lexer);
808 id.reset(static_cast<soulng::parser::soulng::parser::Value<std::u32string>*>(match.value));
809 if (match.hit)
810 {
811 {
812 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
813
814 #endif // SOULNG_PARSER_DEBUG_SUPPORT
815 return soulng::parser::Match(true, new sngcpp::ast::IdentifierNode(span, id->value));
816 }
817 }
818 *parentMatch0 = match;
819 }
820 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
821
822
823
824
825
826 #endif // SOULNG_PARSER_DEBUG_SUPPORT
827 if (!match.hit)
828 {
829 match.value = nullptr;
830 }
831 return match;
832 }
833
834 soulng::parser::Match TemplateParser::TemplateArgumentList(CppLexer& lexer, sngcpp::cppparser::ParsingContext* ctx, int* arity)
835 {
836 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
837
838
839
840
841
842
843
844 #endif // SOULNG_PARSER_DEBUG_SUPPORT
845 std::unique_ptr<sngcpp::ast::Node> arg = std::unique_ptr<sngcpp::ast::Node>();
846 std::unique_ptr<sngcpp::ast::Node> left;
847 std::unique_ptr<sngcpp::ast::Node> right;
848 soulng::parser::Match match(false);
849 soulng::parser::Match* parentMatch0 = &match;
850 {
851 int64_t pos = lexer.GetPos();
852 soulng::parser::Match match(false);
853 soulng::parser::Match* parentMatch1 = &match;
854 {
855 soulng::parser::Match match(false);
856 soulng::parser::Match* parentMatch2 = &match;
857 {
858 soulng::parser::Match match(false);
859 soulng::parser::Match* parentMatch3 = &match;
860 {
861 int64_t pos = lexer.GetPos();
862 soulng::lexer::Span span = lexer.GetSpan();
863 soulng::parser::Match match = TemplateParser::TemplateArgument(lexer, ctx);
864 left.reset(static_cast<sngcpp::ast::Node*>(match.value));
865 if (match.hit)
866 {
867 arg.reset(new sngcpp::ast::TemplateArgumentNode(span, left.release()));
868 ++*arity;
869 }
870 *parentMatch3 = match;
871 }
872 *parentMatch2 = match;
873 }
874 if (match.hit)
875 {
876 soulng::parser::Match match(false);
877 soulng::parser::Match* parentMatch4 = &match;
878 {
879 soulng::parser::Match match(true);
880 soulng::parser::Match* parentMatch5 = &match;
881 {
882 while (true)
883 {
884 int64_t save = lexer.GetPos();
885 {
886 soulng::parser::Match match(false);
887 soulng::parser::Match* parentMatch6 = &match;
888 {
889 soulng::parser::Match match(false);
890 soulng::parser::Match* parentMatch7 = &match;
891 {
892 soulng::parser::Match match(false);
893 if (*lexer == COMMA)
894 {
895 ++lexer;
896 match.hit = true;
897 }
898 *parentMatch7 = match;
899 }
900 if (match.hit)
901 {
902 soulng::parser::Match match(false);
903 soulng::parser::Match* parentMatch8 = &match;
904 {
905 soulng::parser::Match match(false);
906 soulng::parser::Match* parentMatch9 = &match;
907 {
908 int64_t pos = lexer.GetPos();
909 soulng::lexer::Span span = lexer.GetSpan();
910 soulng::parser::Match match = TemplateParser::TemplateArgument(lexer, ctx);
911 right.reset(static_cast<sngcpp::ast::Node*>(match.value));
912 if (match.hit)
913 {
914 arg.reset(new sngcpp::ast::TemplateArgumentSequenceNode(span, arg.release(), new sngcpp::ast::TemplateArgumentNode(span, right.release())));
915 ++*arity;
916 }
917 *parentMatch9 = match;
918 }
919 *parentMatch8 = match;
920 }
921 *parentMatch7 = match;
922 }
923 *parentMatch6 = match;
924 }
925 if (match.hit)
926 {
927 *parentMatch5 = match;
928 }
929 else
930 {
931 lexer.SetPos(save);
932 break;
933 }
934 }
935 }
936 }
937 *parentMatch4 = match;
938 }
939 *parentMatch2 = match;
940 }
941 *parentMatch1 = match;
942 }
943 if (match.hit)
944 {
945 {
946 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
947
948 #endif // SOULNG_PARSER_DEBUG_SUPPORT
949 return soulng::parser::Match(true, arg.release());
950 }
951 }
952 *parentMatch0 = match;
953 }
954 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
955
956
957
958
959
960 #endif // SOULNG_PARSER_DEBUG_SUPPORT
961 if (!match.hit)
962 {
963 match.value = nullptr;
964 }
965 return match;
966 }
967
968 soulng::parser::Match TemplateParser::TemplateArgument(CppLexer& lexer, sngcpp::cppparser::ParsingContext* ctx)
969 {
970 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
971
972
973
974
975
976
977
978 #endif // SOULNG_PARSER_DEBUG_SUPPORT
979 std::unique_ptr<sngcpp::ast::Node> typeExpr;
980 std::unique_ptr<sngcpp::ast::Node> condExpr;
981 soulng::parser::Match match(false);
982 soulng::parser::Match* parentMatch0 = &match;
983 {
984 int64_t save = lexer.GetPos();
985 soulng::parser::Match match(false);
986 soulng::parser::Match* parentMatch1 = &match;
987 {
988 int64_t pos = lexer.GetPos();
989 soulng::parser::Match match = TypeExprParser::TypeExpr(lexer, ctx);
990 typeExpr.reset(static_cast<sngcpp::ast::Node*>(match.value));
991 if (match.hit)
992 {
993 {
994 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
995
996 #endif // SOULNG_PARSER_DEBUG_SUPPORT
997 return soulng::parser::Match(true, typeExpr.release());
998 }
999 }
1000 *parentMatch1 = match;
1001 }
1002 *parentMatch0 = match;
1003 if (!match.hit)
1004 {
1005 soulng::parser::Match match(false);
1006 soulng::parser::Match* parentMatch2 = &match;
1007 lexer.SetPos(save);
1008 {
1009 soulng::parser::Match match(false);
1010 soulng::parser::Match* parentMatch3 = &match;
1011 {
1012 int64_t pos = lexer.GetPos();
1013 soulng::parser::Match match = ExpressionParser::ConditionalExpression(lexer, ctx);
1014 condExpr.reset(static_cast<sngcpp::ast::Node*>(match.value));
1015 if (match.hit)
1016 {
1017 {
1018 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
1019
1020 #endif // SOULNG_PARSER_DEBUG_SUPPORT
1021 return soulng::parser::Match(true, condExpr.release());
1022 }
1023 }
1024 *parentMatch3 = match;
1025 }
1026 *parentMatch2 = match;
1027 }
1028 *parentMatch0 = match;
1029 }
1030 }
1031 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
1032
1033
1034
1035
1036
1037 #endif // SOULNG_PARSER_DEBUG_SUPPORT
1038 if (!match.hit)
1039 {
1040 match.value = nullptr;
1041 }
1042 return match;
1043 }
1044
1045 soulng::parser::Match TemplateParser::ExplicitInstantiation(CppLexer& lexer, sngcpp::cppparser::ParsingContext* ctx)
1046 {
1047 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
1048
1049
1050
1051
1052
1053
1054
1055 #endif // SOULNG_PARSER_DEBUG_SUPPORT
1056 Span s = Span();
1057 std::unique_ptr<sngcpp::ast::Node> declaration;
1058 soulng::parser::Match match(false);
1059 soulng::parser::Match* parentMatch0 = &match;
1060 {
1061 soulng::parser::Match match(false);
1062 soulng::parser::Match* parentMatch1 = &match;
1063 {
1064 int64_t pos = lexer.GetPos();
1065 soulng::lexer::Span span = lexer.GetSpan();
1066 soulng::parser::Match match(false);
1067 if (*lexer == TEMPLATE)
1068 {
1069 ++lexer;
1070 match.hit = true;
1071 }
1072 if (match.hit)
1073 {
1074 s = span;
1075 }
1076 *parentMatch1 = match;
1077 }
1078 *parentMatch0 = match;
1079 }
1080 if (match.hit)
1081 {
1082 soulng::parser::Match match(false);
1083 soulng::parser::Match* parentMatch2 = &match;
1084 {
1085 soulng::parser::Match match(false);
1086 soulng::parser::Match* parentMatch3 = &match;
1087 {
1088 int64_t pos = lexer.GetPos();
1089 soulng::lexer::Span span = lexer.GetSpan();
1090 soulng::parser::Match match = DeclarationParser::Declaration(lexer, ctx);
1091 declaration.reset(static_cast<sngcpp::ast::Node*>(match.value));
1092 if (match.hit)
1093 {
1094 s.end = span.end;
1095 {
1096 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
1097
1098 #endif // SOULNG_PARSER_DEBUG_SUPPORT
1099 return soulng::parser::Match(true, new sngcpp::ast::ExplicitInstantiationNode(s, declaration.release()));
1100 }
1101 }
1102 *parentMatch3 = match;
1103 }
1104 *parentMatch2 = match;
1105 }
1106 *parentMatch0 = match;
1107 }
1108 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
1109
1110
1111
1112
1113
1114 #endif // SOULNG_PARSER_DEBUG_SUPPORT
1115 if (!match.hit)
1116 {
1117 match.value = nullptr;
1118 }
1119 return match;
1120 }
1121
1122 soulng::parser::Match TemplateParser::ExplicitSpecialization(CppLexer& lexer, sngcpp::cppparser::ParsingContext* ctx)
1123 {
1124 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
1125
1126
1127
1128
1129
1130
1131
1132 #endif // SOULNG_PARSER_DEBUG_SUPPORT
1133 Span s = Span();
1134 std::unique_ptr<sngcpp::ast::Node> declaration;
1135 soulng::parser::Match match(false);
1136 soulng::parser::Match* parentMatch0 = &match;
1137 {
1138 soulng::parser::Match match(false);
1139 soulng::parser::Match* parentMatch1 = &match;
1140 {
1141 soulng::parser::Match match(false);
1142 soulng::parser::Match* parentMatch2 = &match;
1143 {
1144 soulng::parser::Match match(false);
1145 soulng::parser::Match* parentMatch3 = &match;
1146 {
1147 int64_t pos = lexer.GetPos();
1148 soulng::lexer::Span span = lexer.GetSpan();
1149 soulng::parser::Match match(false);
1150 if (*lexer == TEMPLATE)
1151 {
1152 ++lexer;
1153 match.hit = true;
1154 }
1155 if (match.hit)
1156 {
1157 s = span;
1158 }
1159 *parentMatch3 = match;
1160 }
1161 *parentMatch2 = match;
1162 }
1163 if (match.hit)
1164 {
1165 soulng::parser::Match match(false);
1166 soulng::parser::Match* parentMatch4 = &match;
1167 {
1168 soulng::parser::Match match(false);
1169 if (*lexer == LANGLE)
1170 {
1171 ++lexer;
1172 match.hit = true;
1173 }
1174 *parentMatch4 = match;
1175 }
1176 *parentMatch2 = match;
1177 }
1178 *parentMatch1 = match;
1179 }
1180 if (match.hit)
1181 {
1182 soulng::parser::Match match(false);
1183 soulng::parser::Match* parentMatch5 = &match;
1184 {
1185 soulng::parser::Match match(false);
1186 if (*lexer == RANGLE)
1187 {
1188 ++lexer;
1189 match.hit = true;
1190 }
1191 *parentMatch5 = match;
1192 }
1193 *parentMatch1 = match;
1194 }
1195 *parentMatch0 = match;
1196 }
1197 if (match.hit)
1198 {
1199 soulng::parser::Match match(false);
1200 soulng::parser::Match* parentMatch6 = &match;
1201 {
1202 soulng::parser::Match match(false);
1203 soulng::parser::Match* parentMatch7 = &match;
1204 {
1205 int64_t pos = lexer.GetPos();
1206 soulng::lexer::Span span = lexer.GetSpan();
1207 soulng::parser::Match match = DeclarationParser::Declaration(lexer, ctx);
1208 declaration.reset(static_cast<sngcpp::ast::Node*>(match.value));
1209 if (match.hit)
1210 {
1211 s.end = span.end;
1212 {
1213 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
1214
1215 #endif // SOULNG_PARSER_DEBUG_SUPPORT
1216 return soulng::parser::Match(true, new sngcpp::ast::ExplicitSpecializationNode(s, declaration.release()));
1217 }
1218 }
1219 *parentMatch7 = match;
1220 }
1221 *parentMatch6 = match;
1222 }
1223 *parentMatch0 = match;
1224 }
1225 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
1226
1227
1228
1229
1230
1231 #endif // SOULNG_PARSER_DEBUG_SUPPORT
1232 if (!match.hit)
1233 {
1234 match.value = nullptr;
1235 }
1236 return match;
1237 }