Changes in src/AST/Convert.cpp [746ae82:dd6d7c6]
- File:
-
- 1 edited
-
src/AST/Convert.cpp (modified) (51 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r746ae82 rdd6d7c6 265 265 stmt->location = node->location; 266 266 stmt->labels = makeLabelL( stmt, node->labels ); 267 cache.emplace( node, stmt ); 267 268 this->node = stmt; 268 269 return nullptr; … … 270 271 271 272 const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final { 273 if ( inCache( node ) ) return nullptr; 272 274 auto stmt = new CompoundStmt( get<Statement>().acceptL( node->kids ) ); 273 275 stmtPostamble( stmt, node ); … … 276 278 277 279 const ast::Stmt * visit( const ast::ExprStmt * node ) override final { 280 if ( inCache( node ) ) return nullptr; 278 281 auto stmt = new ExprStmt( get<Expression>().accept1( node->expr ) ); 279 282 return stmtPostamble( stmt, node ); … … 281 284 282 285 const ast::Stmt * visit( const ast::AsmStmt * node ) override final { 286 if ( inCache( node ) ) return nullptr; 283 287 auto stmt = new AsmStmt( 284 288 node->isVolatile, … … 293 297 294 298 const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final { 299 if ( inCache( node ) ) return nullptr; 295 300 auto stmt = new DirectiveStmt( node->directive ); 296 301 return stmtPostamble( stmt, node ); … … 298 303 299 304 const ast::Stmt * visit( const ast::IfStmt * node ) override final { 305 if ( inCache( node ) ) return nullptr; 300 306 auto stmt = new IfStmt( 301 307 get<Expression>().accept1( node->cond ), … … 308 314 309 315 const ast::Stmt * visit( const ast::SwitchStmt * node ) override final { 316 if ( inCache( node ) ) return nullptr; 310 317 auto stmt = new SwitchStmt( 311 318 get<Expression>().accept1( node->cond ), … … 316 323 317 324 const ast::Stmt * visit( const ast::CaseStmt * node ) override final { 325 if ( inCache( node ) ) return nullptr; 318 326 auto stmt = new CaseStmt( 319 327 get<Expression>().accept1( node->cond ), … … 325 333 326 334 const ast::Stmt * visit( const ast::WhileStmt * node ) override final { 335 if ( inCache( node ) ) return nullptr; 327 336 auto inits = get<Statement>().acceptL( node->inits ); 328 337 auto stmt = new WhileStmt( … … 336 345 337 346 const ast::Stmt * visit( const ast::ForStmt * node ) override final { 347 if ( inCache( node ) ) return nullptr; 338 348 auto stmt = new ForStmt( 339 349 get<Statement>().acceptL( node->inits ), … … 346 356 347 357 const ast::Stmt * visit( const ast::BranchStmt * node ) override final { 358 if ( inCache( node ) ) return nullptr; 348 359 BranchStmt * stmt; 349 360 if (node->computedTarget) { … … 375 386 376 387 const ast::Stmt * visit( const ast::ReturnStmt * node ) override final { 388 if ( inCache( node ) ) return nullptr; 377 389 auto stmt = new ReturnStmt( get<Expression>().accept1( node->expr ) ); 378 390 return stmtPostamble( stmt, node ); … … 380 392 381 393 const ast::Stmt * visit( const ast::ThrowStmt * node ) override final { 394 if ( inCache( node ) ) return nullptr; 382 395 ThrowStmt::Kind kind; 383 396 switch (node->kind) { … … 400 413 401 414 const ast::Stmt * visit( const ast::TryStmt * node ) override final { 415 if ( inCache( node ) ) return nullptr; 402 416 auto handlers = get<CatchStmt>().acceptL( node->handlers ); 403 417 auto stmt = new TryStmt( … … 410 424 411 425 const ast::Stmt * visit( const ast::CatchStmt * node ) override final { 426 if ( inCache( node ) ) return nullptr; 412 427 CatchStmt::Kind kind; 413 428 switch (node->kind) { … … 431 446 432 447 const ast::Stmt * visit( const ast::FinallyStmt * node ) override final { 448 if ( inCache( node ) ) return nullptr; 433 449 auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) ); 434 450 return stmtPostamble( stmt, node ); … … 436 452 437 453 const ast::Stmt * visit( const ast::WaitForStmt * node ) override final { 454 if ( inCache( node ) ) return nullptr; 438 455 auto stmt = new WaitForStmt; 439 456 stmt->clauses.reserve( node->clauses.size() ); … … 460 477 461 478 const ast::Stmt * visit( const ast::WithStmt * node ) override final { 479 if ( inCache( node ) ) return nullptr; 462 480 auto stmt = new WithStmt( 463 481 get<Expression>().acceptL( node->exprs ), … … 468 486 469 487 const ast::NullStmt * visit( const ast::NullStmt * node ) override final { 488 if ( inCache( node ) ) return nullptr; 470 489 auto stmt = new NullStmt(); 471 490 stmtPostamble( stmt, node ); … … 474 493 475 494 const ast::Stmt * visit( const ast::DeclStmt * node ) override final { 495 if ( inCache( node ) ) return nullptr; 476 496 auto stmt = new DeclStmt( get<Declaration>().accept1( node->decl ) ); 477 497 return stmtPostamble( stmt, node ); … … 479 499 480 500 const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * node ) override final { 481 (void)node; 482 return nullptr; 501 if ( inCache( node ) ) return nullptr; 502 auto stmt = new ImplicitCtorDtorStmt{ 503 get<Statement>().accept1( node->callStmt ) 504 }; 505 return stmtPostamble( stmt, node ); 483 506 } 484 507 … … 525 548 } 526 549 550 Expression * visitBaseExpr_skipResultType(const ast::Expr * src, Expression * tgt) { 551 552 tgt->location = src->location; 553 tgt->env = convertTypeSubstitution(src->env); 554 tgt->extension = src->extension; 555 556 convertInferUnion(tgt->inferParams, tgt->resnSlots, src->inferred); 557 return tgt; 558 } 559 527 560 Expression * visitBaseExpr(const ast::Expr * src, Expression * tgt) { 528 561 529 tgt->location = src->location;530 531 562 tgt->result = get<Type>().accept1(src->result); 532 tgt->env = convertTypeSubstitution(src->env); 533 534 tgt->extension = src->extension; 535 convertInferUnion(tgt->inferParams, tgt->resnSlots, src->inferred); 536 537 return tgt; 563 return visitBaseExpr_skipResultType(src, tgt); 538 564 } 539 565 … … 571 597 572 598 const ast::Expr * visit( const ast::AddressExpr * node ) override final { 573 (void)node; 599 auto expr = visitBaseExpr( node, 600 new AddressExpr( 601 get<Expression>().accept1(node->arg) 602 ) 603 ); 604 this->node = expr; 574 605 return nullptr; 575 606 } 576 607 577 608 const ast::Expr * visit( const ast::LabelAddressExpr * node ) override final { 578 (void)node; 609 auto expr = visitBaseExpr( node, 610 new LabelAddressExpr( 611 makeLabel(nullptr, node->arg) 612 ) 613 ); 614 this->node = expr; 579 615 return nullptr; 580 616 } 581 617 582 618 const ast::Expr * visit( const ast::CastExpr * node ) override final { 583 (void)node; 619 auto expr = visitBaseExpr( node, 620 new CastExpr( 621 get<Expression>().accept1(node->arg), 622 (node->isGenerated == ast::GeneratedCast) 623 ) 624 ); 625 this->node = expr; 584 626 return nullptr; 585 627 } 586 628 587 629 const ast::Expr * visit( const ast::KeywordCastExpr * node ) override final { 588 (void)node; 630 KeywordCastExpr::Target castTarget = KeywordCastExpr::NUMBER_OF_TARGETS; 631 switch (node->target) { 632 case ast::KeywordCastExpr::Coroutine: 633 castTarget = KeywordCastExpr::Coroutine; 634 break; 635 case ast::KeywordCastExpr::Thread: 636 castTarget = KeywordCastExpr::Thread; 637 break; 638 case ast::KeywordCastExpr::Monitor: 639 castTarget = KeywordCastExpr::Monitor; 640 break; 641 default: 642 break; 643 } 644 assert ( castTarget < KeywordCastExpr::NUMBER_OF_TARGETS ); 645 auto expr = visitBaseExpr( node, 646 new KeywordCastExpr( 647 get<Expression>().accept1(node->arg), 648 castTarget 649 ) 650 ); 651 this->node = expr; 589 652 return nullptr; 590 653 } 591 654 592 655 const ast::Expr * visit( const ast::VirtualCastExpr * node ) override final { 593 (void)node; 656 auto expr = visitBaseExpr_skipResultType( node, 657 new VirtualCastExpr( 658 get<Expression>().accept1(node->arg), 659 get<Type>().accept1(node->result) 660 ) 661 ); 662 this->node = expr; 594 663 return nullptr; 595 664 } 596 665 597 666 const ast::Expr * visit( const ast::UntypedMemberExpr * node ) override final { 598 (void)node; 667 auto expr = visitBaseExpr( node, 668 new UntypedMemberExpr( 669 get<Expression>().accept1(node->member), 670 get<Expression>().accept1(node->aggregate) 671 ) 672 ); 673 this->node = expr; 599 674 return nullptr; 600 675 } 601 676 602 677 const ast::Expr * visit( const ast::MemberExpr * node ) override final { 603 (void)node; 678 auto expr = visitBaseExpr( node, 679 new MemberExpr( 680 inCache(node->member) ? 681 dynamic_cast<DeclarationWithType *>(this->node) : 682 get<DeclarationWithType>().accept1(node->member), 683 get<Expression>().accept1(node->aggregate) 684 ) 685 ); 686 this->node = expr; 604 687 return nullptr; 605 688 } 606 689 607 690 const ast::Expr * visit( const ast::VariableExpr * node ) override final { 608 (void)node; 609 return nullptr; 691 auto expr = visitBaseExpr( node, 692 new VariableExpr( 693 inCache(node->var) ? 694 dynamic_cast<DeclarationWithType *>(this->node) : 695 get<DeclarationWithType>().accept1(node->var) 696 ) 697 ); 698 this->node = expr; 699 return nullptr; 700 } 701 702 bool isIntlikeConstantType(const ast::Type *t) { 703 if ( const ast::BasicType * basicType = dynamic_cast< const ast::BasicType * >( t ) ) { 704 if ( basicType->isInteger() ) { 705 return true; 706 } 707 } else if ( dynamic_cast< const ast::OneType * >( t ) ) { 708 return true; 709 } else if ( dynamic_cast< const ast::ZeroType * >( t ) ) { 710 return true; 711 } else if ( dynamic_cast< const ast::PointerType * >( t ) ) { 712 // null pointer constants, with zero int-values 713 return true; 714 } 715 return false; 716 } 717 718 bool isFloatlikeConstantType(const ast::Type *t) { 719 if ( const ast::BasicType * bty = dynamic_cast< const ast::BasicType * >( t ) ) { 720 if ( ! bty->isInteger() ) { 721 return true; 722 } 723 } 724 return false; 725 } 726 727 bool isStringlikeConstantType(const ast::Type *t) { 728 if ( const ast::ArrayType * aty = dynamic_cast< const ast::ArrayType * >( t ) ) { 729 if ( const ast::BasicType * bty = aty->base.as<ast::BasicType>() ) { 730 if ( bty->kind == ast::BasicType::Kind::Char ) { 731 return true; 732 } 733 } 734 } 735 return false; 610 736 } 611 737 612 738 const ast::Expr * visit( const ast::ConstantExpr * node ) override final { 613 (void)node; 739 ConstantExpr *rslt = nullptr; 740 if (isIntlikeConstantType(node->result)) { 741 rslt = new ConstantExpr(Constant( 742 get<Type>().accept1(node->result), 743 node->rep, 744 (unsigned long long) node->intValue() 745 )); 746 } else if (isFloatlikeConstantType(node->result)) { 747 rslt = new ConstantExpr(Constant( 748 get<Type>().accept1(node->result), 749 node->rep, 750 (double) node->floatValue() 751 )); 752 } else if (isStringlikeConstantType(node->result)) { 753 rslt = new ConstantExpr(Constant::from_string( 754 node->rep 755 )); 756 } 757 assert(rslt); 758 auto expr = visitBaseExpr( node, rslt ); 759 this->node = expr; 614 760 return nullptr; 615 761 } 616 762 617 763 const ast::Expr * visit( const ast::SizeofExpr * node ) override final { 618 (void)node; 764 assert (node->expr || node->type); 765 assert (! (node->expr && node->type)); 766 SizeofExpr *rslt; 767 if (node->expr) { 768 rslt = new SizeofExpr( 769 get<Expression>().accept1(node->expr) 770 ); 771 assert (!rslt->isType); 772 } 773 if (node->type) { 774 rslt = new SizeofExpr( 775 get<Type>().accept1(node->type) 776 ); 777 assert (rslt->isType); 778 } 779 auto expr = visitBaseExpr( node, rslt ); 780 this->node = expr; 619 781 return nullptr; 620 782 } 621 783 622 784 const ast::Expr * visit( const ast::AlignofExpr * node ) override final { 623 (void)node; 785 assert (node->expr || node->type); 786 assert (! (node->expr && node->type)); 787 AlignofExpr *rslt; 788 if (node->expr) { 789 rslt = new AlignofExpr( 790 get<Expression>().accept1(node->expr) 791 ); 792 assert (!rslt->isType); 793 } 794 if (node->type) { 795 rslt = new AlignofExpr( 796 get<Type>().accept1(node->type) 797 ); 798 assert (rslt->isType); 799 } 800 auto expr = visitBaseExpr( node, rslt ); 801 this->node = expr; 624 802 return nullptr; 625 803 } 626 804 627 805 const ast::Expr * visit( const ast::UntypedOffsetofExpr * node ) override final { 628 (void)node; 806 auto expr = visitBaseExpr( node, 807 new UntypedOffsetofExpr( 808 get<Type>().accept1(node->type), 809 node->member 810 ) 811 ); 812 this->node = expr; 629 813 return nullptr; 630 814 } 631 815 632 816 const ast::Expr * visit( const ast::OffsetofExpr * node ) override final { 633 (void)node; 817 auto expr = visitBaseExpr( node, 818 new OffsetofExpr( 819 get<Type>().accept1(node->type), 820 inCache(node->member) ? 821 dynamic_cast<DeclarationWithType *>(this->node) : 822 get<DeclarationWithType>().accept1(node->member) 823 ) 824 ); 825 this->node = expr; 634 826 return nullptr; 635 827 } 636 828 637 829 const ast::Expr * visit( const ast::OffsetPackExpr * node ) override final { 638 (void)node; 830 auto expr = visitBaseExpr( node, 831 new OffsetPackExpr( 832 get<StructInstType>().accept1(node->type) 833 ) 834 ); 835 this->node = expr; 639 836 return nullptr; 640 837 } 641 838 642 839 const ast::Expr * visit( const ast::LogicalExpr * node ) override final { 643 (void)node; 840 assert (node->isAnd == ast::LogicalFlag::AndExpr || 841 node->isAnd == ast::LogicalFlag::OrExpr ); 842 auto expr = visitBaseExpr( node, 843 new LogicalExpr( 844 get<Expression>().accept1(node->arg1), 845 get<Expression>().accept1(node->arg2), 846 (node->isAnd == ast::LogicalFlag::AndExpr) 847 ) 848 ); 849 this->node = expr; 644 850 return nullptr; 645 851 } 646 852 647 853 const ast::Expr * visit( const ast::ConditionalExpr * node ) override final { 648 (void)node; 854 auto expr = visitBaseExpr( node, 855 new ConditionalExpr( 856 get<Expression>().accept1(node->arg1), 857 get<Expression>().accept1(node->arg2), 858 get<Expression>().accept1(node->arg3) 859 ) 860 ); 861 this->node = expr; 649 862 return nullptr; 650 863 } 651 864 652 865 const ast::Expr * visit( const ast::CommaExpr * node ) override final { 653 (void)node; 866 auto expr = visitBaseExpr( node, 867 new CommaExpr( 868 get<Expression>().accept1(node->arg1), 869 get<Expression>().accept1(node->arg2) 870 ) 871 ); 872 this->node = expr; 654 873 return nullptr; 655 874 } 656 875 657 876 const ast::Expr * visit( const ast::TypeExpr * node ) override final { 658 (void)node; 877 auto expr = visitBaseExpr( node, 878 new TypeExpr( 879 get<Type>().accept1(node->type) 880 ) 881 ); 882 this->node = expr; 659 883 return nullptr; 660 884 } 661 885 662 886 const ast::Expr * visit( const ast::AsmExpr * node ) override final { 663 (void)node; 887 auto expr = visitBaseExpr( node, 888 new AsmExpr( 889 get<Expression>().accept1(node->inout), 890 get<Expression>().accept1(node->constraint), 891 get<Expression>().accept1(node->operand) 892 ) 893 ); 894 this->node = expr; 664 895 return nullptr; 665 896 } 666 897 667 898 const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final { 668 (void)node; 899 auto rslt = new ImplicitCopyCtorExpr( 900 get<ApplicationExpr>().accept1(node->callExpr) 901 ); 902 903 rslt->tempDecls = get<ObjectDecl>().acceptL(node->tempDecls); 904 rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls); 905 rslt->dtors = get<Expression>().acceptL(node->dtors); 906 907 auto expr = visitBaseExpr( node, rslt ); 908 this->node = expr; 669 909 return nullptr; 670 910 } 671 911 672 912 const ast::Expr * visit( const ast::ConstructorExpr * node ) override final { 673 (void)node; 913 auto expr = visitBaseExpr( node, 914 new ConstructorExpr( 915 get<Expression>().accept1(node->callExpr) 916 ) 917 ); 918 this->node = expr; 674 919 return nullptr; 675 920 } 676 921 677 922 const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final { 678 (void)node; 923 auto expr = visitBaseExpr_skipResultType( node, 924 new CompoundLiteralExpr( 925 get<Type>().accept1(node->result), 926 get<Initializer>().accept1(node->init) 927 ) 928 ); 929 this->node = expr; 679 930 return nullptr; 680 931 } 681 932 682 933 const ast::Expr * visit( const ast::RangeExpr * node ) override final { 683 (void)node; 934 auto expr = visitBaseExpr( node, 935 new RangeExpr( 936 get<Expression>().accept1(node->low), 937 get<Expression>().accept1(node->high) 938 ) 939 ); 940 this->node = expr; 684 941 return nullptr; 685 942 } 686 943 687 944 const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final { 688 (void)node; 945 auto expr = visitBaseExpr( node, 946 new UntypedTupleExpr( 947 get<Expression>().acceptL(node->exprs) 948 ) 949 ); 950 this->node = expr; 689 951 return nullptr; 690 952 } 691 953 692 954 const ast::Expr * visit( const ast::TupleExpr * node ) override final { 693 (void)node; 955 auto expr = visitBaseExpr( node, 956 new UntypedTupleExpr( 957 get<Expression>().acceptL(node->exprs) 958 ) 959 ); 960 this->node = expr; 694 961 return nullptr; 695 962 } 696 963 697 964 const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final { 698 (void)node; 965 auto expr = visitBaseExpr( node, 966 new TupleIndexExpr( 967 get<Expression>().accept1(node->tuple), 968 node->index 969 ) 970 ); 971 this->node = expr; 699 972 return nullptr; 700 973 } 701 974 702 975 const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final { 703 (void)node; 976 auto expr = visitBaseExpr( node, 977 new TupleAssignExpr( 978 get<StmtExpr>().accept1(node->stmtExpr) 979 ) 980 ); 981 this->node = expr; 704 982 return nullptr; 705 983 } 706 984 707 985 const ast::Expr * visit( const ast::StmtExpr * node ) override final { 708 (void)node; 986 auto rslt = new StmtExpr( 987 get<CompoundStmt>().accept1(node->stmts) 988 ); 989 990 rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls); 991 rslt->dtors = get<Expression>().acceptL(node->dtors); 992 993 auto expr = visitBaseExpr( node, rslt ); 994 this->node = expr; 709 995 return nullptr; 710 996 } 711 997 712 998 const ast::Expr * visit( const ast::UniqueExpr * node ) override final { 713 (void)node; 999 auto rslt = new UniqueExpr( 1000 get<Expression>().accept1(node->expr) 1001 ); 1002 1003 rslt->object = get<ObjectDecl> ().accept1(node->object); 1004 rslt->var = get<VariableExpr>().accept1(node->var); 1005 1006 auto expr = visitBaseExpr( node, rslt ); 1007 this->node = expr; 714 1008 return nullptr; 715 1009 } 716 1010 717 1011 const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final { 718 (void)node; 1012 std::list<InitAlternative> initAlts; 1013 for (auto ia : node->initAlts) { 1014 initAlts.push_back(InitAlternative( 1015 get<Type> ().accept1(ia.type), 1016 get<Designation>().accept1(ia.designation) 1017 )); 1018 } 1019 auto expr = visitBaseExpr( node, 1020 new UntypedInitExpr( 1021 get<Expression>().accept1(node->expr), 1022 initAlts 1023 ) 1024 ); 1025 this->node = expr; 719 1026 return nullptr; 720 1027 } 721 1028 722 1029 const ast::Expr * visit( const ast::InitExpr * node ) override final { 723 (void)node; 1030 auto expr = visitBaseExpr( node, 1031 new InitExpr( 1032 get<Expression>().accept1(node->expr), 1033 get<Designation>().accept1(node->designation) 1034 ) 1035 ); 1036 this->node = expr; 724 1037 return nullptr; 725 1038 } 726 1039 727 1040 const ast::Expr * visit( const ast::DeletedExpr * node ) override final { 728 (void)node; 1041 auto expr = visitBaseExpr( node, 1042 new DeletedExpr( 1043 get<Expression>().accept1(node->expr), 1044 inCache(node->deleteStmt) ? 1045 this->node : 1046 get<BaseSyntaxNode>().accept1(node->deleteStmt) 1047 ) 1048 ); 1049 this->node = expr; 729 1050 return nullptr; 730 1051 } 731 1052 732 1053 const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final { 733 (void)node; 1054 auto expr = visitBaseExpr( node, 1055 new DefaultArgExpr( 1056 get<Expression>().accept1(node->expr) 1057 ) 1058 ); 1059 this->node = expr; 734 1060 return nullptr; 735 1061 } 736 1062 737 1063 const ast::Expr * visit( const ast::GenericExpr * node ) override final { 738 (void)node; 1064 std::list<GenericExpr::Association> associations; 1065 for (auto association : node->associations) { 1066 associations.push_back(GenericExpr::Association( 1067 get<Type> ().accept1(association.type), 1068 get<Expression>().accept1(association.expr) 1069 )); 1070 } 1071 auto expr = visitBaseExpr( node, 1072 new GenericExpr( 1073 get<Expression>().accept1(node->control), 1074 associations 1075 ) 1076 ); 1077 this->node = expr; 739 1078 return nullptr; 740 1079 } … … 948 1287 949 1288 const ast::Designation * visit( const ast::Designation * node ) override final { 950 (void)node; 1289 auto designation = new Designation( get<Expression>().acceptL( node->designators ) ); 1290 designation->location = node->location; 1291 this->node = designation; 951 1292 return nullptr; 952 1293 } 953 1294 954 1295 const ast::Init * visit( const ast::SingleInit * node ) override final { 955 (void)node; 1296 auto init = new SingleInit( 1297 get<Expression>().accept1( node->value ), 1298 ast::MaybeConstruct == node->maybeConstructed 1299 ); 1300 init->location = node->location; 1301 this->node = init; 956 1302 return nullptr; 957 1303 } 958 1304 959 1305 const ast::Init * visit( const ast::ListInit * node ) override final { 960 (void)node; 1306 auto init = new ListInit( 1307 get<Initializer>().acceptL( node->initializers ), 1308 get<Designation>().acceptL( node->designations ), 1309 ast::MaybeConstruct == node->maybeConstructed 1310 ); 1311 init->location = node->location; 1312 this->node = init; 961 1313 return nullptr; 962 1314 } 963 1315 964 1316 const ast::Init * visit( const ast::ConstructorInit * node ) override final { 965 (void)node; 1317 auto init = new ConstructorInit( 1318 get<Statement>().accept1( node->ctor ), 1319 get<Statement>().accept1( node->dtor ), 1320 get<Initializer>().accept1( node->init ) 1321 ); 1322 init->location = node->location; 1323 this->node = init; 966 1324 return nullptr; 967 1325 } 968 1326 969 1327 const ast::Attribute * visit( const ast::Attribute * node ) override final { 970 (void)node; 1328 auto attr = new Attribute( 1329 node->name, 1330 get<Expression>().acceptL(node->parameters) 1331 ); 1332 this->node = attr; 971 1333 return nullptr; 972 1334 } 973 1335 974 1336 const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) override final { 975 (void)node; 1337 // Handled by convertTypeSubstitution helper instead. 1338 // TypeSubstitution is not a node in the old model, so the conversion result wouldn't fit in this->node. 1339 assert( 0 ); 976 1340 return nullptr; 977 1341 } … … 1084 1448 virtual void visit( FunctionDecl * old ) override final { 1085 1449 if ( inCache( old ) ) return; 1086 // TODO 1087 auto decl = (ast::FunctionDecl *)nullptr; 1450 auto decl = new ast::FunctionDecl{ 1451 old->location, 1452 old->name, 1453 GET_ACCEPT_1(type, FunctionType), 1454 GET_ACCEPT_1(statements, CompoundStmt), 1455 { old->storageClasses.val }, 1456 { old->linkage.val }, 1457 GET_ACCEPT_V(attributes, Attribute), 1458 { old->get_funcSpec().val } 1459 }; 1460 decl->scopeLevel = old->scopeLevel; 1461 decl->mangleName = old->mangleName; 1462 decl->isDeleted = old->isDeleted; 1463 decl->uniqueId = old->uniqueId; 1464 decl->extension = old->extension; 1088 1465 cache.emplace( old, decl ); 1466 1467 this->node = decl; 1089 1468 } 1090 1469 … … 1171 1550 1172 1551 virtual void visit( TypeDecl * old ) override final { 1173 if ( inCache( old ) ) return; 1174 // TODO 1175 auto decl = (ast::TypeDecl *)nullptr; 1552 if ( inCache( old ) ) return; 1553 auto decl = new ast::TypeDecl{ 1554 old->location, 1555 old->name, 1556 { old->storageClasses.val }, 1557 GET_ACCEPT_1(base, Type), 1558 (ast::TypeVar::Kind)(unsigned)old->kind, 1559 old->sized, 1560 GET_ACCEPT_1(init, Type) 1561 }; 1562 decl->assertions = GET_ACCEPT_V(assertions, DeclWithType); 1563 decl->params = GET_ACCEPT_V(parameters, TypeDecl); 1564 decl->extension = old->extension; 1565 decl->uniqueId = old->uniqueId; 1176 1566 cache.emplace( old, decl ); 1567 1568 this->node = decl; 1177 1569 } 1178 1570 … … 1194 1586 } 1195 1587 1196 virtual void visit( AsmDecl * ) override final { 1197 1198 } 1199 1200 virtual void visit( StaticAssertDecl * ) override final { 1201 1588 virtual void visit( AsmDecl * old ) override final { 1589 auto decl = new ast::AsmDecl{ 1590 old->location, 1591 GET_ACCEPT_1(stmt, AsmStmt) 1592 }; 1593 decl->extension = old->extension; 1594 decl->uniqueId = old->uniqueId; 1595 decl->storage = { old->storageClasses.val }; 1596 1597 this->node = decl; 1598 } 1599 1600 virtual void visit( StaticAssertDecl * old ) override final { 1601 auto decl = new ast::StaticAssertDecl{ 1602 old->location, 1603 GET_ACCEPT_1(condition, Expr), 1604 GET_ACCEPT_1(message, ConstantExpr) 1605 }; 1606 decl->extension = old->extension; 1607 decl->uniqueId = old->uniqueId; 1608 decl->storage = { old->storageClasses.val }; 1609 1610 this->node = decl; 1202 1611 } 1203 1612 1204 1613 virtual void visit( CompoundStmt * old ) override final { 1614 if ( inCache( old ) ) return; 1205 1615 auto stmt = new ast::CompoundStmt( 1206 1616 old->location, … … 1210 1620 1211 1621 this->node = stmt; 1622 cache.emplace( old, this->node ); 1212 1623 } 1213 1624 1214 1625 virtual void visit( ExprStmt * old ) override final { 1626 if ( inCache( old ) ) return; 1215 1627 this->node = new ast::ExprStmt( 1216 1628 old->location, … … 1218 1630 GET_LABELS_V(old->labels) 1219 1631 ); 1632 cache.emplace( old, this->node ); 1220 1633 } 1221 1634 1222 1635 virtual void visit( AsmStmt * old ) override final { 1636 if ( inCache( old ) ) return; 1223 1637 this->node = new ast::AsmStmt( 1224 1638 old->location, … … 1231 1645 GET_LABELS_V(old->labels) 1232 1646 ); 1647 cache.emplace( old, this->node ); 1233 1648 } 1234 1649 1235 1650 virtual void visit( DirectiveStmt * old ) override final { 1651 if ( inCache( old ) ) return; 1236 1652 this->node = new ast::DirectiveStmt( 1237 1653 old->location, … … 1239 1655 GET_LABELS_V(old->labels) 1240 1656 ); 1657 cache.emplace( old, this->node ); 1241 1658 } 1242 1659 1243 1660 virtual void visit( IfStmt * old ) override final { 1661 if ( inCache( old ) ) return; 1244 1662 this->node = new ast::IfStmt( 1245 1663 old->location, … … 1250 1668 GET_LABELS_V(old->labels) 1251 1669 ); 1670 cache.emplace( old, this->node ); 1252 1671 } 1253 1672 1254 1673 virtual void visit( SwitchStmt * old ) override final { 1674 if ( inCache( old ) ) return; 1255 1675 this->node = new ast::SwitchStmt( 1256 1676 old->location, … … 1259 1679 GET_LABELS_V(old->labels) 1260 1680 ); 1681 cache.emplace( old, this->node ); 1261 1682 } 1262 1683 1263 1684 virtual void visit( CaseStmt * old ) override final { 1685 if ( inCache( old ) ) return; 1264 1686 this->node = new ast::CaseStmt( 1265 1687 old->location, … … 1268 1690 GET_LABELS_V(old->labels) 1269 1691 ); 1692 cache.emplace( old, this->node ); 1270 1693 } 1271 1694 1272 1695 virtual void visit( WhileStmt * old ) override final { 1696 if ( inCache( old ) ) return; 1273 1697 this->node = new ast::WhileStmt( 1274 1698 old->location, … … 1279 1703 GET_LABELS_V(old->labels) 1280 1704 ); 1705 cache.emplace( old, this->node ); 1281 1706 } 1282 1707 1283 1708 virtual void visit( ForStmt * old ) override final { 1709 if ( inCache( old ) ) return; 1284 1710 this->node = new ast::ForStmt( 1285 1711 old->location, … … 1290 1716 GET_LABELS_V(old->labels) 1291 1717 ); 1718 cache.emplace( old, this->node ); 1292 1719 } 1293 1720 1294 1721 virtual void visit( BranchStmt * old ) override final { 1722 if ( inCache( old ) ) return; 1295 1723 if (old->computedTarget) { 1296 1724 this->node = new ast::BranchStmt( … … 1326 1754 this->node = stmt; 1327 1755 } 1756 cache.emplace( old, this->node ); 1328 1757 } 1329 1758 1330 1759 virtual void visit( ReturnStmt * old ) override final { 1760 if ( inCache( old ) ) return; 1331 1761 this->node = new ast::ReturnStmt( 1332 1762 old->location, … … 1334 1764 GET_LABELS_V(old->labels) 1335 1765 ); 1766 cache.emplace( old, this->node ); 1336 1767 } 1337 1768 1338 1769 virtual void visit( ThrowStmt * old ) override final { 1770 if ( inCache( old ) ) return; 1339 1771 ast::ThrowStmt::Kind kind; 1340 1772 switch (old->kind) { … … 1356 1788 GET_LABELS_V(old->labels) 1357 1789 ); 1790 cache.emplace( old, this->node ); 1358 1791 } 1359 1792 1360 1793 virtual void visit( TryStmt * old ) override final { 1794 if ( inCache( old ) ) return; 1361 1795 this->node = new ast::TryStmt( 1362 1796 old->location, … … 1366 1800 GET_LABELS_V(old->labels) 1367 1801 ); 1802 cache.emplace( old, this->node ); 1368 1803 } 1369 1804 1370 1805 virtual void visit( CatchStmt * old ) override final { 1806 if ( inCache( old ) ) return; 1371 1807 ast::CatchStmt::Kind kind; 1372 1808 switch (old->kind) { … … 1389 1825 GET_LABELS_V(old->labels) 1390 1826 ); 1827 cache.emplace( old, this->node ); 1391 1828 } 1392 1829 1393 1830 virtual void visit( FinallyStmt * old ) override final { 1831 if ( inCache( old ) ) return; 1394 1832 this->node = new ast::FinallyStmt( 1395 1833 old->location, … … 1397 1835 GET_LABELS_V(old->labels) 1398 1836 ); 1837 cache.emplace( old, this->node ); 1399 1838 } 1400 1839 1401 1840 virtual void visit( WaitForStmt * old ) override final { 1841 if ( inCache( old ) ) return; 1402 1842 ast::WaitForStmt * stmt = new ast::WaitForStmt( 1403 1843 old->location, … … 1427 1867 1428 1868 this->node = stmt; 1869 cache.emplace( old, this->node ); 1429 1870 } 1430 1871 1431 1872 virtual void visit( WithStmt * old ) override final { 1873 if ( inCache( old ) ) return; 1432 1874 this->node = new ast::WithStmt( 1433 1875 old->location, … … 1436 1878 GET_LABELS_V(old->labels) 1437 1879 ); 1880 cache.emplace( old, this->node ); 1438 1881 } 1439 1882 1440 1883 virtual void visit( NullStmt * old ) override final { 1884 if ( inCache( old ) ) return; 1441 1885 this->node = new ast::NullStmt( 1442 1886 old->location, 1443 1887 GET_LABELS_V(old->labels) 1444 1888 ); 1889 cache.emplace( old, this->node ); 1445 1890 } 1446 1891 1447 1892 virtual void visit( DeclStmt * old ) override final { 1893 if ( inCache( old ) ) return; 1448 1894 this->node = new ast::DeclStmt( 1449 1895 old->location, … … 1451 1897 GET_LABELS_V(old->labels) 1452 1898 ); 1899 cache.emplace( old, this->node ); 1453 1900 } 1454 1901 1455 1902 virtual void visit( ImplicitCtorDtorStmt * old ) override final { 1903 if ( inCache( old ) ) return; 1456 1904 this->node = new ast::ImplicitCtorDtorStmt( 1457 1905 old->location, … … 1459 1907 GET_LABELS_V(old->labels) 1460 1908 ); 1909 cache.emplace( old, this->node ); 1461 1910 } 1462 1911 … … 1503 1952 } 1504 1953 1505 ast::Expr * visitBaseExpr(Expression * old, ast::Expr * nw) { 1506 1507 nw->result = GET_ACCEPT_1(result, Type); 1954 ast::Expr * visitBaseExpr_SkipResultType(Expression * old, ast::Expr * nw) { 1955 1508 1956 nw->env = convertTypeSubstitution(old->env); 1509 1957 … … 1512 1960 1513 1961 return nw; 1962 } 1963 1964 ast::Expr * visitBaseExpr(Expression * old, ast::Expr * nw) { 1965 1966 nw->result = GET_ACCEPT_1(result, Type); 1967 return visitBaseExpr_SkipResultType(old, nw);; 1514 1968 } 1515 1969 … … 1547 2001 new ast::CastExpr( 1548 2002 old->location, 1549 nullptr, // cast's "to" type is expr's result type; converted in visitBaseExpr2003 GET_ACCEPT_1(arg, Expr), 1550 2004 old->isGenerated ? ast::GeneratedCast : ast::ExplicitCast 1551 2005 ) … … 1553 2007 } 1554 2008 1555 virtual void visit( KeywordCastExpr * ) override final { 1556 1557 } 1558 1559 virtual void visit( VirtualCastExpr * ) override final { 1560 1561 } 1562 1563 virtual void visit( AddressExpr * ) override final { 1564 1565 } 1566 1567 virtual void visit( LabelAddressExpr * ) override final { 1568 1569 } 1570 1571 virtual void visit( UntypedMemberExpr * ) override final { 1572 1573 } 1574 1575 virtual void visit( MemberExpr * ) override final { 1576 1577 } 1578 1579 virtual void visit( VariableExpr * ) override final { 1580 1581 } 1582 1583 virtual void visit( ConstantExpr * ) override final { 1584 1585 } 1586 1587 virtual void visit( SizeofExpr * ) override final { 1588 1589 } 1590 1591 virtual void visit( AlignofExpr * ) override final { 1592 1593 } 1594 1595 virtual void visit( UntypedOffsetofExpr * ) override final { 1596 1597 } 1598 1599 virtual void visit( OffsetofExpr * ) override final { 1600 1601 } 1602 1603 virtual void visit( OffsetPackExpr * ) override final { 1604 1605 } 1606 1607 virtual void visit( LogicalExpr * ) override final { 1608 1609 } 1610 1611 virtual void visit( ConditionalExpr * ) override final { 1612 1613 } 1614 1615 virtual void visit( CommaExpr * ) override final { 1616 1617 } 1618 1619 virtual void visit( TypeExpr * ) override final { 1620 1621 } 1622 1623 virtual void visit( AsmExpr * ) override final { 1624 1625 } 1626 1627 virtual void visit( ImplicitCopyCtorExpr * ) override final { 1628 1629 } 1630 1631 virtual void visit( ConstructorExpr * ) override final { 1632 1633 } 1634 1635 virtual void visit( CompoundLiteralExpr * ) override final { 1636 1637 } 1638 1639 virtual void visit( RangeExpr * ) override final { 1640 1641 } 1642 1643 virtual void visit( UntypedTupleExpr * ) override final { 1644 1645 } 1646 1647 virtual void visit( TupleExpr * ) override final { 1648 1649 } 1650 1651 virtual void visit( TupleIndexExpr * ) override final { 1652 1653 } 1654 1655 virtual void visit( TupleAssignExpr * ) override final { 1656 1657 } 1658 1659 virtual void visit( StmtExpr * ) override final { 1660 1661 } 1662 1663 virtual void visit( UniqueExpr * ) override final { 1664 1665 } 1666 1667 virtual void visit( UntypedInitExpr * ) override final { 1668 1669 } 1670 1671 virtual void visit( InitExpr * ) override final { 1672 1673 } 1674 1675 virtual void visit( DeletedExpr * ) override final { 1676 1677 } 1678 1679 virtual void visit( DefaultArgExpr * ) override final { 1680 1681 } 1682 1683 virtual void visit( GenericExpr * ) override final { 1684 2009 virtual void visit( KeywordCastExpr * old) override final { 2010 ast::KeywordCastExpr::Target castTarget = ast::KeywordCastExpr::NUMBER_OF_TARGETS; 2011 switch (old->target) { 2012 case KeywordCastExpr::Coroutine: 2013 castTarget = ast::KeywordCastExpr::Coroutine; 2014 break; 2015 case KeywordCastExpr::Thread: 2016 castTarget = ast::KeywordCastExpr::Thread; 2017 break; 2018 case KeywordCastExpr::Monitor: 2019 castTarget = ast::KeywordCastExpr::Monitor; 2020 break; 2021 default: 2022 break; 2023 } 2024 assert ( castTarget < ast::KeywordCastExpr::NUMBER_OF_TARGETS ); 2025 this->node = visitBaseExpr( old, 2026 new ast::KeywordCastExpr( 2027 old->location, 2028 GET_ACCEPT_1(arg, Expr), 2029 castTarget 2030 ) 2031 ); 2032 } 2033 2034 virtual void visit( VirtualCastExpr * old ) override final { 2035 this->node = visitBaseExpr_SkipResultType( old, 2036 new ast::VirtualCastExpr( 2037 old->location, 2038 GET_ACCEPT_1(arg, Expr), 2039 GET_ACCEPT_1(result, Type) 2040 ) 2041 ); 2042 } 2043 2044 virtual void visit( AddressExpr * old ) override final { 2045 this->node = visitBaseExpr( old, 2046 new ast::AddressExpr( 2047 old->location, 2048 GET_ACCEPT_1(arg, Expr) 2049 ) 2050 ); 2051 } 2052 2053 virtual void visit( LabelAddressExpr * old ) override final { 2054 this->node = visitBaseExpr( old, 2055 new ast::LabelAddressExpr( 2056 old->location, 2057 make_label(&old->arg) 2058 ) 2059 ); 2060 } 2061 2062 virtual void visit( UntypedMemberExpr * old ) override final { 2063 this->node = visitBaseExpr( old, 2064 new ast::UntypedMemberExpr( 2065 old->location, 2066 GET_ACCEPT_1(member, Expr), 2067 GET_ACCEPT_1(aggregate, Expr) 2068 ) 2069 ); 2070 } 2071 2072 virtual void visit( MemberExpr * old ) override final { 2073 this->node = visitBaseExpr( old, 2074 new ast::MemberExpr( 2075 old->location, 2076 inCache(old->member) ? 2077 dynamic_cast<ast::DeclWithType *>(this->node) : 2078 GET_ACCEPT_1(member, DeclWithType), 2079 GET_ACCEPT_1(aggregate, Expr) 2080 ) 2081 ); 2082 } 2083 2084 virtual void visit( VariableExpr * old ) override final { 2085 this->node = visitBaseExpr( old, 2086 new ast::VariableExpr( 2087 old->location, 2088 inCache(old->var) ? 2089 dynamic_cast<ast::DeclWithType *>(this->node) : 2090 GET_ACCEPT_1(var, DeclWithType) 2091 ) 2092 ); 2093 } 2094 2095 bool isIntlikeConstantType(const Type *t) { 2096 if ( const BasicType * basicType = dynamic_cast< const BasicType * >( t ) ) { 2097 if ( basicType->isInteger() ) { 2098 return true; 2099 } 2100 } else if ( dynamic_cast< const OneType * >( t ) ) { 2101 return true; 2102 } else if ( dynamic_cast< const ZeroType * >( t ) ) { 2103 return true; 2104 } else if ( dynamic_cast< const PointerType * >( t ) ) { 2105 // null pointer constants, with zero int-values 2106 return true; 2107 } 2108 return false; 2109 } 2110 2111 int isFloatlikeConstantType(const Type *t) { 2112 if ( const BasicType * bty = dynamic_cast< const BasicType * >( t ) ) { 2113 if ( ! bty->isInteger() ) { 2114 return true; 2115 } 2116 } 2117 return false; 2118 } 2119 2120 int isStringlikeConstantType(const Type *t) { 2121 if ( const ArrayType * aty = dynamic_cast< const ArrayType * >( t ) ) { 2122 if ( const BasicType * bty = dynamic_cast< const BasicType * >( aty->base ) ) { 2123 if ( bty->kind == BasicType::Kind::Char ) { 2124 return true; 2125 } 2126 } 2127 } 2128 return false; 2129 } 2130 2131 virtual void visit( ConstantExpr * old ) override final { 2132 ast::ConstantExpr *rslt = nullptr; 2133 if (isIntlikeConstantType(old->result)) { 2134 rslt = new ast::ConstantExpr( 2135 old->location, 2136 GET_ACCEPT_1(result, Type), 2137 old->constant.get_value(), 2138 (unsigned long long) old->intValue() 2139 ); 2140 } else if (isFloatlikeConstantType(old->result)) { 2141 rslt = new ast::ConstantExpr( 2142 old->location, 2143 GET_ACCEPT_1(result, Type), 2144 old->constant.get_value(), 2145 (double) old->constant.get_dval() 2146 ); 2147 } else if (isStringlikeConstantType(old->result)) { 2148 rslt = ast::ConstantExpr::from_string( 2149 old->location, 2150 old->constant.get_value() 2151 ); 2152 } 2153 assert(rslt); 2154 this->node = visitBaseExpr( old, rslt ); 2155 } 2156 2157 virtual void visit( SizeofExpr * old ) override final { 2158 assert (old->expr || old->type); 2159 assert (! (old->expr && old->type)); 2160 ast::SizeofExpr *rslt; 2161 if (old->expr) { 2162 assert(!old->isType); 2163 rslt = new ast::SizeofExpr( 2164 old->location, 2165 GET_ACCEPT_1(expr, Expr) 2166 ); 2167 } 2168 if (old->type) { 2169 assert(old->isType); 2170 rslt = new ast::SizeofExpr( 2171 old->location, 2172 GET_ACCEPT_1(type, Type) 2173 ); 2174 } 2175 this->node = visitBaseExpr( old, rslt ); 2176 } 2177 2178 virtual void visit( AlignofExpr * old ) override final { 2179 assert (old->expr || old->type); 2180 assert (! (old->expr && old->type)); 2181 ast::AlignofExpr *rslt; 2182 if (old->expr) { 2183 assert(!old->isType); 2184 rslt = new ast::AlignofExpr( 2185 old->location, 2186 GET_ACCEPT_1(expr, Expr) 2187 ); 2188 } 2189 if (old->type) { 2190 assert(old->isType); 2191 rslt = new ast::AlignofExpr( 2192 old->location, 2193 GET_ACCEPT_1(type, Type) 2194 ); 2195 } 2196 this->node = visitBaseExpr( old, rslt ); 2197 } 2198 2199 virtual void visit( UntypedOffsetofExpr * old ) override final { 2200 this->node = visitBaseExpr( old, 2201 new ast::UntypedOffsetofExpr( 2202 old->location, 2203 GET_ACCEPT_1(type, Type), 2204 old->member 2205 ) 2206 ); 2207 } 2208 2209 virtual void visit( OffsetofExpr * old ) override final { 2210 this->node = visitBaseExpr( old, 2211 new ast::OffsetofExpr( 2212 old->location, 2213 GET_ACCEPT_1(type, Type), 2214 inCache(old->member) ? 2215 dynamic_cast<ast::DeclWithType *>(this->node) : 2216 GET_ACCEPT_1(member, DeclWithType) 2217 ) 2218 ); 2219 } 2220 2221 virtual void visit( OffsetPackExpr * old ) override final { 2222 this->node = visitBaseExpr( old, 2223 new ast::OffsetPackExpr( 2224 old->location, 2225 GET_ACCEPT_1(type, StructInstType) 2226 ) 2227 ); 2228 } 2229 2230 virtual void visit( LogicalExpr * old ) override final { 2231 this->node = visitBaseExpr( old, 2232 new ast::LogicalExpr( 2233 old->location, 2234 GET_ACCEPT_1(arg1, Expr), 2235 GET_ACCEPT_1(arg2, Expr), 2236 old->get_isAnd() ? 2237 ast::LogicalFlag::AndExpr : 2238 ast::LogicalFlag::OrExpr 2239 ) 2240 ); 2241 } 2242 2243 virtual void visit( ConditionalExpr * old ) override final { 2244 this->node = visitBaseExpr( old, 2245 new ast::ConditionalExpr( 2246 old->location, 2247 GET_ACCEPT_1(arg1, Expr), 2248 GET_ACCEPT_1(arg2, Expr), 2249 GET_ACCEPT_1(arg3, Expr) 2250 ) 2251 ); 2252 } 2253 2254 virtual void visit( CommaExpr * old ) override final { 2255 this->node = visitBaseExpr( old, 2256 new ast::CommaExpr( 2257 old->location, 2258 GET_ACCEPT_1(arg1, Expr), 2259 GET_ACCEPT_1(arg2, Expr) 2260 ) 2261 ); 2262 } 2263 2264 virtual void visit( TypeExpr * old ) override final { 2265 this->node = visitBaseExpr( old, 2266 new ast::TypeExpr( 2267 old->location, 2268 GET_ACCEPT_1(type, Type) 2269 ) 2270 ); 2271 } 2272 2273 virtual void visit( AsmExpr * old ) override final { 2274 this->node = visitBaseExpr( old, 2275 new ast::AsmExpr( 2276 old->location, 2277 GET_ACCEPT_1(inout, Expr), 2278 GET_ACCEPT_1(constraint, Expr), 2279 GET_ACCEPT_1(operand, Expr) 2280 ) 2281 ); 2282 } 2283 2284 virtual void visit( ImplicitCopyCtorExpr * old ) override final { 2285 auto rslt = new ast::ImplicitCopyCtorExpr( 2286 old->location, 2287 GET_ACCEPT_1(callExpr, ApplicationExpr) 2288 ); 2289 2290 rslt->tempDecls = GET_ACCEPT_V(tempDecls, ObjectDecl); 2291 rslt->returnDecls = GET_ACCEPT_V(returnDecls, ObjectDecl); 2292 rslt->dtors = GET_ACCEPT_V(dtors, Expr); 2293 2294 this->node = visitBaseExpr( old, rslt ); 2295 } 2296 2297 virtual void visit( ConstructorExpr * old ) override final { 2298 this->node = visitBaseExpr( old, 2299 new ast::ConstructorExpr( 2300 old->location, 2301 GET_ACCEPT_1(callExpr, Expr) 2302 ) 2303 ); 2304 } 2305 2306 virtual void visit( CompoundLiteralExpr * old ) override final { 2307 this->node = visitBaseExpr_SkipResultType( old, 2308 new ast::CompoundLiteralExpr( 2309 old->location, 2310 GET_ACCEPT_1(result, Type), 2311 GET_ACCEPT_1(initializer, Init) 2312 ) 2313 ); 2314 } 2315 2316 virtual void visit( RangeExpr * old ) override final { 2317 this->node = visitBaseExpr( old, 2318 new ast::RangeExpr( 2319 old->location, 2320 GET_ACCEPT_1(low, Expr), 2321 GET_ACCEPT_1(high, Expr) 2322 ) 2323 ); 2324 } 2325 2326 virtual void visit( UntypedTupleExpr * old ) override final { 2327 this->node = visitBaseExpr( old, 2328 new ast::UntypedTupleExpr( 2329 old->location, 2330 GET_ACCEPT_V(exprs, Expr) 2331 ) 2332 ); 2333 } 2334 2335 virtual void visit( TupleExpr * old ) override final { 2336 this->node = visitBaseExpr( old, 2337 new ast::TupleExpr( 2338 old->location, 2339 GET_ACCEPT_V(exprs, Expr) 2340 ) 2341 ); 2342 } 2343 2344 virtual void visit( TupleIndexExpr * old ) override final { 2345 this->node = visitBaseExpr( old, 2346 new ast::TupleIndexExpr( 2347 old->location, 2348 GET_ACCEPT_1(tuple, Expr), 2349 old->index 2350 ) 2351 ); 2352 } 2353 2354 virtual void visit( TupleAssignExpr * old ) override final { 2355 this->node = visitBaseExpr_SkipResultType( old, 2356 new ast::TupleAssignExpr( 2357 old->location, 2358 GET_ACCEPT_1(result, Type), 2359 GET_ACCEPT_1(stmtExpr, StmtExpr) 2360 ) 2361 ); 2362 } 2363 2364 virtual void visit( StmtExpr * old ) override final { 2365 auto rslt = new ast::StmtExpr( 2366 old->location, 2367 GET_ACCEPT_1(statements, CompoundStmt) 2368 ); 2369 rslt->returnDecls = GET_ACCEPT_V(returnDecls, ObjectDecl); 2370 rslt->dtors = GET_ACCEPT_V(dtors , Expr); 2371 2372 this->node = visitBaseExpr_SkipResultType( old, rslt ); 2373 } 2374 2375 virtual void visit( UniqueExpr * old ) override final { 2376 auto rslt = new ast::UniqueExpr( 2377 old->location, 2378 GET_ACCEPT_1(expr, Expr) 2379 ); 2380 rslt->object = GET_ACCEPT_1(object, ObjectDecl); 2381 rslt->var = GET_ACCEPT_1(var , VariableExpr); 2382 2383 this->node = visitBaseExpr( old, rslt ); 2384 } 2385 2386 virtual void visit( UntypedInitExpr * old ) override final { 2387 std::vector<ast::InitAlternative> initAlts; 2388 for (auto ia : old->initAlts) { 2389 initAlts.push_back(ast::InitAlternative( 2390 getAccept1< ast::Type, Type * >( ia.type ), 2391 getAccept1< ast::Designation, Designation * >( ia.designation ) 2392 )); 2393 } 2394 this->node = visitBaseExpr( old, 2395 new ast::UntypedInitExpr( 2396 old->location, 2397 GET_ACCEPT_1(expr, Expr), 2398 std::move(initAlts) 2399 ) 2400 ); 2401 } 2402 2403 virtual void visit( InitExpr * old ) override final { 2404 this->node = visitBaseExpr( old, 2405 new ast::InitExpr( 2406 old->location, 2407 GET_ACCEPT_1(expr, Expr), 2408 GET_ACCEPT_1(designation, Designation) 2409 ) 2410 ); 2411 } 2412 2413 virtual void visit( DeletedExpr * old ) override final { 2414 this->node = visitBaseExpr( old, 2415 new ast::DeletedExpr( 2416 old->location, 2417 GET_ACCEPT_1(expr, Expr), 2418 inCache(old->deleteStmt) ? 2419 this->node : 2420 GET_ACCEPT_1(deleteStmt, Node) 2421 ) 2422 ); 2423 } 2424 2425 virtual void visit( DefaultArgExpr * old ) override final { 2426 this->node = visitBaseExpr( old, 2427 new ast::DefaultArgExpr( 2428 old->location, 2429 GET_ACCEPT_1(expr, Expr) 2430 ) 2431 ); 2432 } 2433 2434 virtual void visit( GenericExpr * old ) override final { 2435 std::vector<ast::GenericExpr::Association> associations; 2436 for (auto association : old->associations) { 2437 associations.push_back(ast::GenericExpr::Association( 2438 getAccept1< ast::Type, Type * >( association.type ), 2439 getAccept1< ast::Expr, Expression * >( association.expr ) 2440 )); 2441 } 2442 this->node = visitBaseExpr( old, 2443 new ast::GenericExpr( 2444 old->location, 2445 GET_ACCEPT_1(control, Expr), 2446 std::move(associations) 2447 ) 2448 ); 1685 2449 } 1686 2450 … … 1878 2642 } 1879 2643 1880 virtual void visit( Designation * ) override final { 1881 1882 } 1883 1884 virtual void visit( SingleInit * ) override final { 1885 1886 } 1887 1888 virtual void visit( ListInit * ) override final { 1889 1890 } 1891 1892 virtual void visit( ConstructorInit * ) override final { 1893 2644 virtual void visit( Designation * old ) override final { 2645 this->node = new ast::Designation( 2646 old->location, 2647 GET_ACCEPT_V(designators, Expr) 2648 ); 2649 } 2650 2651 virtual void visit( SingleInit * old ) override final { 2652 this->node = new ast::SingleInit( 2653 old->location, 2654 GET_ACCEPT_1(value, Expr), 2655 (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::DoConstruct 2656 ); 2657 } 2658 2659 virtual void visit( ListInit * old ) override final { 2660 this->node = new ast::ListInit( 2661 old->location, 2662 GET_ACCEPT_V(initializers, Init), 2663 GET_ACCEPT_V(designations, Designation), 2664 (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::DoConstruct 2665 ); 2666 } 2667 2668 virtual void visit( ConstructorInit * old ) override final { 2669 this->node = new ast::ConstructorInit( 2670 old->location, 2671 GET_ACCEPT_1(ctor, Stmt), 2672 GET_ACCEPT_1(dtor, Stmt), 2673 GET_ACCEPT_1(init, Init) 2674 ); 1894 2675 } 1895 2676 1896 2677 virtual void visit( Constant * ) override final { 1897 1898 } 1899 1900 virtual void visit( Attribute * ) override final { 1901 2678 // Handled in visit( ConstantEpxr * ). 2679 // In the new tree, Constant fields are inlined into containing ConstantExpression. 2680 assert( 0 ); 2681 } 2682 2683 virtual void visit( Attribute * old ) override final { 2684 this->node = new ast::Attribute( 2685 old->name, 2686 GET_ACCEPT_V( parameters, Expr ) 2687 ); 1902 2688 } 1903 2689 1904 2690 virtual void visit( AttrExpr * ) override final { 1905 1906 assert( 0 ); 2691 assertf( false, "AttrExpr deprecated in new AST." ); 1907 2692 } 1908 2693 };
Note:
See TracChangeset
for help on using the changeset viewer.