1 #include "Function.hpp"
  2 #include <soulng/util/Unicode.hpp>
  3 #include <sngcpp/parser/Class.hpp>
  4 #include <sngcpp/parser/Declaration.hpp>
  5 #include <sngcpp/parser/Declarator.hpp>
  6 #include <sngcpp/parser/Statement.hpp>
  7 #include <sngcpp/parser/TypeExpr.hpp>
  8 #include <sngcpp/lexer/CppLexer.hpp>
  9 #include <sngcpp/lexer/CppTokens.hpp>
 10 
 11 // this file has been automatically generated from 'D:/work/soulng-project/sngcpp/parser/Function.parser' using soulng parser generator spg version 3.0.0
 12 
 13 using namespace soulng::unicode;
 14 using namespace CppTokens;
 15 using namespace soulng::lexer;
 16 
 17 soulng::parser::Match FunctionParser::FunctionDefinition(CppLexer& lexersngcpp::cppparser::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<sngcpp::ast::Node> declarator = std::unique_ptr<sngcpp::ast::Node>();
 29     sngcpp::ast::Specifier defaultOrDeleteSpecifier = sngcpp::ast::Specifier();
 30     Span s = Span();
 31     std::unique_ptr<soulng::parser::soulng::parser::Value<sngcpp::ast::Specifier>>declSpecifiers;
 32     std::unique_ptr<sngcpp::ast::Node> typeExpr;
 33     std::unique_ptr<sngcpp::ast::Node> d;
 34     std::unique_ptr<soulng::parser::soulng::parser::Value<sngcpp::ast::Specifier>>virtPureSpecifiers;
 35     std::unique_ptr<sngcpp::ast::CompoundStatementNode> body;
 36     soulng::parser::Match match(false);
 37     soulng::parser::Match* parentMatch0 = &match;
 38     {
 39         soulng::parser::Match match(false);
 40         soulng::parser::Match* parentMatch1 = &match;
 41         {
 42             soulng::parser::Match match(false);
 43             soulng::parser::Match* parentMatch2 = &match;
 44             {
 45                 soulng::parser::Match match(false);
 46                 soulng::parser::Match* parentMatch3 = &match;
 47                 {
 48                     soulng::parser::Match match(false);
 49                     soulng::parser::Match* parentMatch4 = &match;
 50                     {
 51                         int64_t pos = lexer.GetPos();
 52                         soulng::lexer::Span span = lexer.GetSpan();
 53                         soulng::parser::Match match = DeclarationParser::DeclSpecifiers(lexer);
 54                         declSpecifiers.reset(static_cast<soulng::parser::soulng::parser::Value<sngcpp::ast::Specifier>*>(match.value));
 55                         if (match.hit)
 56                         {
 57                             s = span;
 58                         }
 59                         *parentMatch4 = match;
 60                     }
 61                     *parentMatch3 = match;
 62                 }
 63                 if (match.hit)
 64                 {
 65                     soulng::parser::Match match(false);
 66                     soulng::parser::Match* parentMatch5 = &match;
 67                     {
 68                         soulng::parser::Match match = TypeExprParser::TypeExpr(lexerctx);
 69                         typeExpr.reset(static_cast<sngcpp::ast::Node*>(match.value));
 70                         *parentMatch5 = match;
 71                     }
 72                     *parentMatch3 = match;
 73                 }
 74                 *parentMatch2 = match;
 75             }
 76             if (match.hit)
 77             {
 78                 soulng::parser::Match match(false);
 79                 soulng::parser::Match* parentMatch6 = &match;
 80                 {
 81                     soulng::parser::Match match(false);
 82                     soulng::parser::Match* parentMatch7 = &match;
 83                     {
 84                         int64_t pos = lexer.GetPos();
 85                         bool pass = true;
 86                         soulng::parser::Match match = DeclaratorParser::Declarator(lexerctx);
 87                         d.reset(static_cast<sngcpp::ast::Node*>(match.value));
 88                         if (match.hit)
 89                         {
 90                             declarator.reset(d.release());
 91                             pass = sngcpp::ast::IsFunctionDeclarator(declarator.get());
 92                         }
 93                         if (match.hit && !pass)
 94                         {
 95                             match = soulng::parser::Match(false);
 96                         }
 97                         *parentMatch7 = match;
 98                     }
 99                     *parentMatch6 = match;
100                 }
101                 *parentMatch2 = match;
102             }
103             *parentMatch1 = match;
104         }
105         if (match.hit)
106         {
107             soulng::parser::Match match(false);
108             soulng::parser::Match* parentMatch8 = &match;
109             {
110                 soulng::parser::Match match = ClassParser::VirtPureSpecifiers(lexertrue);
111                 virtPureSpecifiers.reset(static_cast<soulng::parser::soulng::parser::Value<sngcpp::ast::Specifier>*>(match.value));
112                 *parentMatch8 = match;
113             }
114             *parentMatch1 = match;
115         }
116         *parentMatch0 = match;
117     }
118     if (match.hit)
119     {
120         soulng::parser::Match match(false);
121         soulng::parser::Match* parentMatch9 = &match;
122         {
123             soulng::parser::Match match(false);
124             soulng::parser::Match* parentMatch10 = &match;
125             {
126                 int64_t pos = lexer.GetPos();
127                 soulng::parser::Match match(false);
128                 soulng::parser::Match* parentMatch11 = &match;
129                 {
130                     soulng::parser::Match match(false);
131                     soulng::parser::Match* parentMatch12 = &match;
132                     {
133                         int64_t save = lexer.GetPos();
134                         soulng::parser::Match match(false);
135                         soulng::parser::Match* parentMatch13 = &match;
136                         {
137                             int64_t save = lexer.GetPos();
138                             soulng::parser::Match match(false);
139                             soulng::parser::Match* parentMatch14 = &match;
140                             {
141                                 int64_t pos = lexer.GetPos();
142                                 soulng::lexer::Span span = lexer.GetSpan();
143                                 soulng::parser::Match match = FunctionParser::FunctionBody(lexerctx);
144                                 body.reset(static_cast<sngcpp::ast::CompoundStatementNode*>(match.value));
145                                 if (match.hit)
146                                 {
147                                     s.end = span.end;
148                                 }
149                                 *parentMatch14 = match;
150                             }
151                             *parentMatch13 = match;
152                             if (!match.hit)
153                             {
154                                 soulng::parser::Match match(false);
155                                 soulng::parser::Match* parentMatch15 = &match;
156                                 lexer.SetPos(save);
157                                 {
158                                     soulng::parser::Match match(false);
159                                     soulng::parser::Match* parentMatch16 = &match;
160                                     {
161                                         soulng::parser::Match match(false);
162                                         soulng::parser::Match* parentMatch17 = &match;
163                                         {
164                                             soulng::parser::Match match(false);
165                                             if (*lexer == ASSIGN)
166                                             {
167                                                 ++lexer;
168                                                 match.hit = true;
169                                             }
170                                             *parentMatch17 = match;
171                                         }
172                                         if (match.hit)
173                                         {
174                                             soulng::parser::Match match(false);
175                                             soulng::parser::Match* parentMatch18 = &match;
176                                             {
177                                                 soulng::parser::Match match(false);
178                                                 soulng::parser::Match* parentMatch19 = &match;
179                                                 {
180                                                     soulng::parser::Match match(false);
181                                                     soulng::parser::Match* parentMatch20 = &match;
182                                                     {
183                                                         int64_t save = lexer.GetPos();
184                                                         soulng::parser::Match match(false);
185                                                         soulng::parser::Match* parentMatch21 = &match;
186                                                         {
187                                                             int64_t pos = lexer.GetPos();
188                                                             soulng::parser::Match match(false);
189                                                             if (*lexer == DEFAULT)
190                                                             {
191                                                                 ++lexer;
192                                                                 match.hit = true;
193                                                             }
194                                                             if (match.hit)
195                                                             {
196                                                                 defaultOrDeleteSpecifier = sngcpp::ast::Specifier::default_;
197                                                             }
198                                                             *parentMatch21 = match;
199                                                         }
200                                                         *parentMatch20 = match;
201                                                         if (!match.hit)
202                                                         {
203                                                             soulng::parser::Match match(false);
204                                                             soulng::parser::Match* parentMatch22 = &match;
205                                                             lexer.SetPos(save);
206                                                             {
207                                                                 soulng::parser::Match match(false);
208                                                                 soulng::parser::Match* parentMatch23 = &match;
209                                                                 {
210                                                                     int64_t pos = lexer.GetPos();
211                                                                     soulng::parser::Match match(false);
212                                                                     if (*lexer == DELETE)
213                                                                     {
214                                                                         ++lexer;
215                                                                         match.hit = true;
216                                                                     }
217                                                                     if (match.hit)
218                                                                     {
219                                                                         defaultOrDeleteSpecifier = sngcpp::ast::Specifier::delete_;
220                                                                     }
221                                                                     *parentMatch23 = match;
222                                                                 }
223                                                                 *parentMatch22 = match;
224                                                             }
225                                                             *parentMatch20 = match;
226                                                         }
227                                                     }
228                                                     *parentMatch19 = match;
229                                                 }
230                                                 *parentMatch18 = match;
231                                             }
232                                             *parentMatch17 = match;
233                                         }
234                                         *parentMatch16 = match;
235                                     }
236                                     if (match.hit)
237                                     {
238                                         soulng::parser::Match match(false);
239                                         soulng::parser::Match* parentMatch24 = &match;
240                                         {
241                                             soulng::parser::Match match(false);
242                                             soulng::parser::Match* parentMatch25 = &match;
243                                             {
244                                                 int64_t pos = lexer.GetPos();
245                                                 soulng::lexer::Span span = lexer.GetSpan();
246                                                 soulng::parser::Match match(false);
247                                                 if (*lexer == SEMICOLON)
248                                                 {
249                                                     ++lexer;
250                                                     match.hit = true;
251                                                 }
252                                                 if (match.hit)
253                                                 {
254                                                     s.end = span.end;
255                                                 }
256                                                 *parentMatch25 = match;
257                                             }
258                                             *parentMatch24 = match;
259                                         }
260                                         *parentMatch16 = match;
261                                     }
262                                     *parentMatch15 = match;
263                                 }
264                                 *parentMatch13 = match;
265                             }
266                         }
267                         *parentMatch12 = match;
268                         if (!match.hit)
269                         {
270                             soulng::parser::Match match(false);
271                             soulng::parser::Match* parentMatch26 = &match;
272                             lexer.SetPos(save);
273                             {
274                                 soulng::parser::Match match(false);
275                                 soulng::parser::Match* parentMatch27 = &match;
276                                 {
277                                     int64_t pos = lexer.GetPos();
278                                     soulng::lexer::Span span = lexer.GetSpan();
279                                     bool pass = true;
280                                     soulng::parser::Match match(false);
281                                     if (*lexer == SEMICOLON)
282                                     {
283                                         ++lexer;
284                                         match.hit = true;
285                                     }
286                                     if (match.hit)
287                                     {
288                                         s.end = span.end;
289                                         pass = sngcpp::ast::HasPureSpecifier(virtPureSpecifiers->value);
290                                     }
291                                     if (match.hit && !pass)
292                                     {
293                                         match = soulng::parser::Match(false);
294                                     }
295                                     *parentMatch27 = match;
296                                 }
297                                 *parentMatch26 = match;
298                             }
299                             *parentMatch12 = match;
300                         }
301                     }
302                     *parentMatch11 = match;
303                 }
304                 if (match.hit)
305                 {
306                     {
307                         #ifdef SOULNG_PARSER_DEBUG_SUPPORT
308 
309                         #endif // SOULNG_PARSER_DEBUG_SUPPORT
310                         return soulng::parser::Match(truenew sngcpp::ast::FunctionNode(sdeclSpecifiers->value | defaultOrDeleteSpecifier | virtPureSpecifiers->valuetypeExpr.release()declarator.release()body.release()));
311                     }
312                 }
313                 *parentMatch10 = match;
314             }
315             *parentMatch9 = match;
316         }
317         *parentMatch0 = match;
318     }
319     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
320 
321 
322 
323 
324 
325     #endif // SOULNG_PARSER_DEBUG_SUPPORT
326     if (!match.hit)
327     {
328         match.value = nullptr;
329     }
330     return match;
331 }
332 
333 soulng::parser::Match FunctionParser::FunctionBody(CppLexer& lexersngcpp::cppparser::ParsingContext* ctx)
334 {
335     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
336 
337 
338 
339 
340 
341 
342 
343     #endif // SOULNG_PARSER_DEBUG_SUPPORT
344     std::unique_ptr<sngcpp::ast::CompoundStatementNode> body;
345     soulng::parser::Match match(false);
346     soulng::parser::Match* parentMatch0 = &match;
347     {
348         soulng::parser::Match match(false);
349         soulng::parser::Match* parentMatch1 = &match;
350         {
351             int64_t pos = lexer.GetPos();
352             soulng::parser::Match match(true);
353             if (match.hit)
354             {
355                 ctx->BeginFunctionBody();
356             }
357             *parentMatch1 = match;
358         }
359         *parentMatch0 = match;
360     }
361     if (match.hit)
362     {
363         soulng::parser::Match match(false);
364         soulng::parser::Match* parentMatch2 = &match;
365         {
366             soulng::parser::Match match(false);
367             soulng::parser::Match* parentMatch3 = &match;
368             {
369                 int64_t pos = lexer.GetPos();
370                 soulng::parser::Match match = StatementParser::CompoundStatement(lexerctx);
371                 body.reset(static_cast<sngcpp::ast::CompoundStatementNode*>(match.value));
372                 if (match.hit)
373                 {
374                     ctx->EndFunctionBody();
375                     {
376                         #ifdef SOULNG_PARSER_DEBUG_SUPPORT
377 
378                         #endif // SOULNG_PARSER_DEBUG_SUPPORT
379                         return soulng::parser::Match(truebody.release());
380                     }
381                 }
382                 else
383                 {
384                     ctx->EndFunctionBody();
385                 }
386                 *parentMatch3 = match;
387             }
388             *parentMatch2 = match;
389         }
390         *parentMatch0 = match;
391     }
392     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
393 
394 
395 
396 
397 
398     #endif // SOULNG_PARSER_DEBUG_SUPPORT
399     if (!match.hit)
400     {
401         match.value = nullptr;
402     }
403     return match;
404 }
405 
406 soulng::parser::Match FunctionParser::ParameterList(CppLexer& lexersngcpp::cppparser::ParsingContext* ctx)
407 {
408     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
409 
410 
411 
412 
413 
414 
415 
416     #endif // SOULNG_PARSER_DEBUG_SUPPORT
417     std::unique_ptr<sngcpp::ast::Node> param = std::unique_ptr<sngcpp::ast::Node>();
418     Span s = Span();
419     std::unique_ptr<sngcpp::ast::Node> left;
420     std::unique_ptr<sngcpp::ast::Node> right;
421     soulng::parser::Match match(false);
422     soulng::parser::Match* parentMatch0 = &match;
423     {
424         soulng::parser::Match match(false);
425         soulng::parser::Match* parentMatch1 = &match;
426         {
427             soulng::parser::Match match(false);
428             soulng::parser::Match* parentMatch2 = &match;
429             {
430                 int64_t pos = lexer.GetPos();
431                 soulng::lexer::Span span = lexer.GetSpan();
432                 soulng::parser::Match match(false);
433                 if (*lexer == LPAREN)
434                 {
435                     ++lexer;
436                     match.hit = true;
437                 }
438                 if (match.hit)
439                 {
440                     s = span;
441                 }
442                 *parentMatch2 = match;
443             }
444             *parentMatch1 = match;
445         }
446         if (match.hit)
447         {
448             soulng::parser::Match match(false);
449             soulng::parser::Match* parentMatch3 = &match;
450             {
451                 soulng::parser::Match match(true);
452                 int64_t save = lexer.GetPos();
453                 soulng::parser::Match* parentMatch4 = &match;
454                 {
455                     soulng::parser::Match match(false);
456                     soulng::parser::Match* parentMatch5 = &match;
457                     {
458                         soulng::parser::Match match(false);
459                         soulng::parser::Match* parentMatch6 = &match;
460                         {
461                             soulng::parser::Match match(false);
462                             soulng::parser::Match* parentMatch7 = &match;
463                             {
464                                 int64_t pos = lexer.GetPos();
465                                 soulng::parser::Match match = FunctionParser::ParameterDeclaration(lexerctx);
466                                 left.reset(static_cast<sngcpp::ast::Node*>(match.value));
467                                 if (match.hit)
468                                 {
469                                     param.reset(left.release());
470                                 }
471                                 *parentMatch7 = match;
472                             }
473                             *parentMatch6 = match;
474                         }
475                         if (match.hit)
476                         {
477                             soulng::parser::Match match(false);
478                             soulng::parser::Match* parentMatch8 = &match;
479                             {
480                                 soulng::parser::Match match(true);
481                                 soulng::parser::Match* parentMatch9 = &match;
482                                 {
483                                     while (true)
484                                     {
485                                         int64_t save = lexer.GetPos();
486                                         {
487                                             soulng::parser::Match match(false);
488                                             soulng::parser::Match* parentMatch10 = &match;
489                                             {
490                                                 soulng::parser::Match match(false);
491                                                 soulng::parser::Match* parentMatch11 = &match;
492                                                 {
493                                                     soulng::parser::Match match(false);
494                                                     if (*lexer == COMMA)
495                                                     {
496                                                         ++lexer;
497                                                         match.hit = true;
498                                                     }
499                                                     *parentMatch11 = match;
500                                                 }
501                                                 if (match.hit)
502                                                 {
503                                                     soulng::parser::Match match(false);
504                                                     soulng::parser::Match* parentMatch12 = &match;
505                                                     {
506                                                         soulng::parser::Match match(false);
507                                                         soulng::parser::Match* parentMatch13 = &match;
508                                                         {
509                                                             int64_t pos = lexer.GetPos();
510                                                             soulng::lexer::Span span = lexer.GetSpan();
511                                                             soulng::parser::Match match = FunctionParser::ParameterDeclaration(lexerctx);
512                                                             right.reset(static_cast<sngcpp::ast::Node*>(match.value));
513                                                             if (match.hit)
514                                                             {
515                                                                 s.end = span.end;
516                                                                 param.reset(new sngcpp::ast::ParameterSequenceNode(sparam.release()right.release()));
517                                                             }
518                                                             *parentMatch13 = match;
519                                                         }
520                                                         *parentMatch12 = match;
521                                                     }
522                                                     *parentMatch11 = match;
523                                                 }
524                                                 *parentMatch10 = match;
525                                             }
526                                             if (match.hit)
527                                             {
528                                                 *parentMatch9 = match;
529                                             }
530                                             else
531                                             {
532                                                 lexer.SetPos(save);
533                                                 break;
534                                             }
535                                         }
536                                     }
537                                 }
538                                 *parentMatch8 = match;
539                             }
540                             *parentMatch6 = match;
541                         }
542                         *parentMatch5 = match;
543                     }
544                     if (match.hit)
545                     {
546                         *parentMatch4 = match;
547                     }
548                     else
549                     {
550                         lexer.SetPos(save);
551                     }
552                 }
553                 *parentMatch3 = match;
554             }
555             *parentMatch1 = match;
556         }
557         *parentMatch0 = match;
558     }
559     if (match.hit)
560     {
561         soulng::parser::Match match(false);
562         soulng::parser::Match* parentMatch14 = &match;
563         {
564             soulng::parser::Match match(false);
565             soulng::parser::Match* parentMatch15 = &match;
566             {
567                 int64_t pos = lexer.GetPos();
568                 soulng::lexer::Span span = lexer.GetSpan();
569                 soulng::parser::Match match(false);
570                 if (*lexer == RPAREN)
571                 {
572                     ++lexer;
573                     match.hit = true;
574                 }
575                 if (match.hit)
576                 {
577                     s.end = span.end;
578                     {
579                         #ifdef SOULNG_PARSER_DEBUG_SUPPORT
580 
581                         #endif // SOULNG_PARSER_DEBUG_SUPPORT
582                         return soulng::parser::Match(trueparam.release());
583                     }
584                 }
585                 *parentMatch15 = match;
586             }
587             *parentMatch14 = match;
588         }
589         *parentMatch0 = match;
590     }
591     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
592 
593 
594 
595 
596 
597     #endif // SOULNG_PARSER_DEBUG_SUPPORT
598     if (!match.hit)
599     {
600         match.value = nullptr;
601     }
602     return match;
603 }
604 
605 soulng::parser::Match FunctionParser::ParameterDeclaration(CppLexer& lexersngcpp::cppparser::ParsingContext* ctx)
606 {
607     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
608 
609 
610 
611 
612 
613 
614 
615     #endif // SOULNG_PARSER_DEBUG_SUPPORT
616     Span s = Span();
617     std::unique_ptr<sngcpp::ast::Node> typeExpr;
618     std::unique_ptr<sngcpp::ast::Node> declarator;
619     soulng::parser::Match match(false);
620     soulng::parser::Match* parentMatch0 = &match;
621     {
622         int64_t pos = lexer.GetPos();
623         soulng::parser::Match match(false);
624         soulng::parser::Match* parentMatch1 = &match;
625         {
626             soulng::parser::Match match(false);
627             soulng::parser::Match* parentMatch2 = &match;
628             {
629                 soulng::parser::Match match(false);
630                 soulng::parser::Match* parentMatch3 = &match;
631                 {
632                     int64_t pos = lexer.GetPos();
633                     soulng::lexer::Span span = lexer.GetSpan();
634                     soulng::parser::Match match = TypeExprParser::TypeExpr(lexerctx);
635                     typeExpr.reset(static_cast<sngcpp::ast::Node*>(match.value));
636                     if (match.hit)
637                     {
638                         s = span;
639                     }
640                     *parentMatch3 = match;
641                 }
642                 *parentMatch2 = match;
643             }
644             if (match.hit)
645             {
646                 soulng::parser::Match match(false);
647                 soulng::parser::Match* parentMatch4 = &match;
648                 {
649                     soulng::parser::Match match(true);
650                     int64_t save = lexer.GetPos();
651                     soulng::parser::Match* parentMatch5 = &match;
652                     {
653                         soulng::parser::Match match(false);
654                         soulng::parser::Match* parentMatch6 = &match;
655                         {
656                             soulng::parser::Match match(false);
657                             soulng::parser::Match* parentMatch7 = &match;
658                             {
659                                 int64_t pos = lexer.GetPos();
660                                 soulng::lexer::Span span = lexer.GetSpan();
661                                 soulng::parser::Match match = DeclaratorParser::Declarator(lexerctx);
662                                 declarator.reset(static_cast<sngcpp::ast::Node*>(match.value));
663                                 if (match.hit)
664                                 {
665                                     s.end = span.end;
666                                 }
667                                 *parentMatch7 = match;
668                             }
669                             *parentMatch6 = match;
670                         }
671                         if (match.hit)
672                         {
673                             *parentMatch5 = match;
674                         }
675                         else
676                         {
677                             lexer.SetPos(save);
678                         }
679                     }
680                     *parentMatch4 = match;
681                 }
682                 *parentMatch2 = match;
683             }
684             *parentMatch1 = match;
685         }
686         if (match.hit)
687         {
688             {
689                 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
690 
691                 #endif // SOULNG_PARSER_DEBUG_SUPPORT
692                 return soulng::parser::Match(truenew sngcpp::ast::ParameterNode(stypeExpr.release()declarator.release()));
693             }
694         }
695         *parentMatch0 = match;
696     }
697     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
698 
699 
700 
701 
702 
703     #endif // SOULNG_PARSER_DEBUG_SUPPORT
704     if (!match.hit)
705     {
706         match.value = nullptr;
707     }
708     return match;
709 }