Changes in src/AST/Convert.cpp [dd6d7c6:746ae82]
- File:
-
- 1 edited
-
src/AST/Convert.cpp (modified) (51 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
rdd6d7c6 r746ae82 265 265 stmt->location = node->location; 266 266 stmt->labels = makeLabelL( stmt, node->labels ); 267 cache.emplace( node, stmt );268 267 this->node = stmt; 269 268 return nullptr; … … 271 270 272 271 const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final { 273 if ( inCache( node ) ) return nullptr;274 272 auto stmt = new CompoundStmt( get<Statement>().acceptL( node->kids ) ); 275 273 stmtPostamble( stmt, node ); … … 278 276 279 277 const ast::Stmt * visit( const ast::ExprStmt * node ) override final { 280 if ( inCache( node ) ) return nullptr;281 278 auto stmt = new ExprStmt( get<Expression>().accept1( node->expr ) ); 282 279 return stmtPostamble( stmt, node ); … … 284 281 285 282 const ast::Stmt * visit( const ast::AsmStmt * node ) override final { 286 if ( inCache( node ) ) return nullptr;287 283 auto stmt = new AsmStmt( 288 284 node->isVolatile, … … 297 293 298 294 const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final { 299 if ( inCache( node ) ) return nullptr;300 295 auto stmt = new DirectiveStmt( node->directive ); 301 296 return stmtPostamble( stmt, node ); … … 303 298 304 299 const ast::Stmt * visit( const ast::IfStmt * node ) override final { 305 if ( inCache( node ) ) return nullptr;306 300 auto stmt = new IfStmt( 307 301 get<Expression>().accept1( node->cond ), … … 314 308 315 309 const ast::Stmt * visit( const ast::SwitchStmt * node ) override final { 316 if ( inCache( node ) ) return nullptr;317 310 auto stmt = new SwitchStmt( 318 311 get<Expression>().accept1( node->cond ), … … 323 316 324 317 const ast::Stmt * visit( const ast::CaseStmt * node ) override final { 325 if ( inCache( node ) ) return nullptr;326 318 auto stmt = new CaseStmt( 327 319 get<Expression>().accept1( node->cond ), … … 333 325 334 326 const ast::Stmt * visit( const ast::WhileStmt * node ) override final { 335 if ( inCache( node ) ) return nullptr;336 327 auto inits = get<Statement>().acceptL( node->inits ); 337 328 auto stmt = new WhileStmt( … … 345 336 346 337 const ast::Stmt * visit( const ast::ForStmt * node ) override final { 347 if ( inCache( node ) ) return nullptr;348 338 auto stmt = new ForStmt( 349 339 get<Statement>().acceptL( node->inits ), … … 356 346 357 347 const ast::Stmt * visit( const ast::BranchStmt * node ) override final { 358 if ( inCache( node ) ) return nullptr;359 348 BranchStmt * stmt; 360 349 if (node->computedTarget) { … … 386 375 387 376 const ast::Stmt * visit( const ast::ReturnStmt * node ) override final { 388 if ( inCache( node ) ) return nullptr;389 377 auto stmt = new ReturnStmt( get<Expression>().accept1( node->expr ) ); 390 378 return stmtPostamble( stmt, node ); … … 392 380 393 381 const ast::Stmt * visit( const ast::ThrowStmt * node ) override final { 394 if ( inCache( node ) ) return nullptr;395 382 ThrowStmt::Kind kind; 396 383 switch (node->kind) { … … 413 400 414 401 const ast::Stmt * visit( const ast::TryStmt * node ) override final { 415 if ( inCache( node ) ) return nullptr;416 402 auto handlers = get<CatchStmt>().acceptL( node->handlers ); 417 403 auto stmt = new TryStmt( … … 424 410 425 411 const ast::Stmt * visit( const ast::CatchStmt * node ) override final { 426 if ( inCache( node ) ) return nullptr;427 412 CatchStmt::Kind kind; 428 413 switch (node->kind) { … … 446 431 447 432 const ast::Stmt * visit( const ast::FinallyStmt * node ) override final { 448 if ( inCache( node ) ) return nullptr;449 433 auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) ); 450 434 return stmtPostamble( stmt, node ); … … 452 436 453 437 const ast::Stmt * visit( const ast::WaitForStmt * node ) override final { 454 if ( inCache( node ) ) return nullptr;455 438 auto stmt = new WaitForStmt; 456 439 stmt->clauses.reserve( node->clauses.size() ); … … 477 460 478 461 const ast::Stmt * visit( const ast::WithStmt * node ) override final { 479 if ( inCache( node ) ) return nullptr;480 462 auto stmt = new WithStmt( 481 463 get<Expression>().acceptL( node->exprs ), … … 486 468 487 469 const ast::NullStmt * visit( const ast::NullStmt * node ) override final { 488 if ( inCache( node ) ) return nullptr;489 470 auto stmt = new NullStmt(); 490 471 stmtPostamble( stmt, node ); … … 493 474 494 475 const ast::Stmt * visit( const ast::DeclStmt * node ) override final { 495 if ( inCache( node ) ) return nullptr;496 476 auto stmt = new DeclStmt( get<Declaration>().accept1( node->decl ) ); 497 477 return stmtPostamble( stmt, node ); … … 499 479 500 480 const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * node ) override final { 501 if ( inCache( node ) ) return nullptr; 502 auto stmt = new ImplicitCtorDtorStmt{ 503 get<Statement>().accept1( node->callStmt ) 504 }; 505 return stmtPostamble( stmt, node ); 481 (void)node; 482 return nullptr; 506 483 } 507 484 … … 548 525 } 549 526 550 Expression * visitBaseExpr_skipResultType(const ast::Expr * src, Expression * tgt) { 551 552 tgt->location = src->location; 553 tgt->env = convertTypeSubstitution(src->env); 527 Expression * visitBaseExpr(const ast::Expr * src, Expression * tgt) { 528 529 tgt->location = src->location; 530 531 tgt->result = get<Type>().accept1(src->result); 532 tgt->env = convertTypeSubstitution(src->env); 533 554 534 tgt->extension = src->extension; 555 556 535 convertInferUnion(tgt->inferParams, tgt->resnSlots, src->inferred); 536 557 537 return tgt; 558 }559 560 Expression * visitBaseExpr(const ast::Expr * src, Expression * tgt) {561 562 tgt->result = get<Type>().accept1(src->result);563 return visitBaseExpr_skipResultType(src, tgt);564 538 } 565 539 … … 597 571 598 572 const ast::Expr * visit( const ast::AddressExpr * node ) override final { 599 auto expr = visitBaseExpr( node, 600 new AddressExpr( 601 get<Expression>().accept1(node->arg) 602 ) 603 ); 604 this->node = expr; 573 (void)node; 605 574 return nullptr; 606 575 } 607 576 608 577 const ast::Expr * visit( const ast::LabelAddressExpr * node ) override final { 609 auto expr = visitBaseExpr( node, 610 new LabelAddressExpr( 611 makeLabel(nullptr, node->arg) 612 ) 613 ); 614 this->node = expr; 578 (void)node; 615 579 return nullptr; 616 580 } 617 581 618 582 const ast::Expr * visit( const ast::CastExpr * node ) override final { 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; 583 (void)node; 626 584 return nullptr; 627 585 } 628 586 629 587 const ast::Expr * visit( const ast::KeywordCastExpr * node ) override final { 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; 588 (void)node; 652 589 return nullptr; 653 590 } 654 591 655 592 const ast::Expr * visit( const ast::VirtualCastExpr * node ) override final { 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; 593 (void)node; 663 594 return nullptr; 664 595 } 665 596 666 597 const ast::Expr * visit( const ast::UntypedMemberExpr * node ) override final { 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; 598 (void)node; 674 599 return nullptr; 675 600 } 676 601 677 602 const ast::Expr * visit( const ast::MemberExpr * node ) override final { 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; 603 (void)node; 687 604 return nullptr; 688 605 } 689 606 690 607 const ast::Expr * visit( const ast::VariableExpr * node ) override final { 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; 608 (void)node; 609 return nullptr; 736 610 } 737 611 738 612 const ast::Expr * visit( const ast::ConstantExpr * node ) override final { 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; 613 (void)node; 760 614 return nullptr; 761 615 } 762 616 763 617 const ast::Expr * visit( const ast::SizeofExpr * node ) override final { 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; 618 (void)node; 781 619 return nullptr; 782 620 } 783 621 784 622 const ast::Expr * visit( const ast::AlignofExpr * node ) override final { 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; 623 (void)node; 802 624 return nullptr; 803 625 } 804 626 805 627 const ast::Expr * visit( const ast::UntypedOffsetofExpr * node ) override final { 806 auto expr = visitBaseExpr( node, 807 new UntypedOffsetofExpr( 808 get<Type>().accept1(node->type), 809 node->member 810 ) 811 ); 812 this->node = expr; 628 (void)node; 813 629 return nullptr; 814 630 } 815 631 816 632 const ast::Expr * visit( const ast::OffsetofExpr * node ) override final { 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; 633 (void)node; 826 634 return nullptr; 827 635 } 828 636 829 637 const ast::Expr * visit( const ast::OffsetPackExpr * node ) override final { 830 auto expr = visitBaseExpr( node, 831 new OffsetPackExpr( 832 get<StructInstType>().accept1(node->type) 833 ) 834 ); 835 this->node = expr; 638 (void)node; 836 639 return nullptr; 837 640 } 838 641 839 642 const ast::Expr * visit( const ast::LogicalExpr * node ) override final { 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; 643 (void)node; 850 644 return nullptr; 851 645 } 852 646 853 647 const ast::Expr * visit( const ast::ConditionalExpr * node ) override final { 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; 648 (void)node; 862 649 return nullptr; 863 650 } 864 651 865 652 const ast::Expr * visit( const ast::CommaExpr * node ) override final { 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; 653 (void)node; 873 654 return nullptr; 874 655 } 875 656 876 657 const ast::Expr * visit( const ast::TypeExpr * node ) override final { 877 auto expr = visitBaseExpr( node, 878 new TypeExpr( 879 get<Type>().accept1(node->type) 880 ) 881 ); 882 this->node = expr; 658 (void)node; 883 659 return nullptr; 884 660 } 885 661 886 662 const ast::Expr * visit( const ast::AsmExpr * node ) override final { 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; 663 (void)node; 895 664 return nullptr; 896 665 } 897 666 898 667 const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final { 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; 668 (void)node; 909 669 return nullptr; 910 670 } 911 671 912 672 const ast::Expr * visit( const ast::ConstructorExpr * node ) override final { 913 auto expr = visitBaseExpr( node, 914 new ConstructorExpr( 915 get<Expression>().accept1(node->callExpr) 916 ) 917 ); 918 this->node = expr; 673 (void)node; 919 674 return nullptr; 920 675 } 921 676 922 677 const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final { 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; 678 (void)node; 930 679 return nullptr; 931 680 } 932 681 933 682 const ast::Expr * visit( const ast::RangeExpr * node ) override final { 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; 683 (void)node; 941 684 return nullptr; 942 685 } 943 686 944 687 const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final { 945 auto expr = visitBaseExpr( node, 946 new UntypedTupleExpr( 947 get<Expression>().acceptL(node->exprs) 948 ) 949 ); 950 this->node = expr; 688 (void)node; 951 689 return nullptr; 952 690 } 953 691 954 692 const ast::Expr * visit( const ast::TupleExpr * node ) override final { 955 auto expr = visitBaseExpr( node, 956 new UntypedTupleExpr( 957 get<Expression>().acceptL(node->exprs) 958 ) 959 ); 960 this->node = expr; 693 (void)node; 961 694 return nullptr; 962 695 } 963 696 964 697 const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final { 965 auto expr = visitBaseExpr( node, 966 new TupleIndexExpr( 967 get<Expression>().accept1(node->tuple), 968 node->index 969 ) 970 ); 971 this->node = expr; 698 (void)node; 972 699 return nullptr; 973 700 } 974 701 975 702 const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final { 976 auto expr = visitBaseExpr( node, 977 new TupleAssignExpr( 978 get<StmtExpr>().accept1(node->stmtExpr) 979 ) 980 ); 981 this->node = expr; 703 (void)node; 982 704 return nullptr; 983 705 } 984 706 985 707 const ast::Expr * visit( const ast::StmtExpr * node ) override final { 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; 708 (void)node; 995 709 return nullptr; 996 710 } 997 711 998 712 const ast::Expr * visit( const ast::UniqueExpr * node ) override final { 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; 713 (void)node; 1008 714 return nullptr; 1009 715 } 1010 716 1011 717 const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final { 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; 718 (void)node; 1026 719 return nullptr; 1027 720 } 1028 721 1029 722 const ast::Expr * visit( const ast::InitExpr * node ) override final { 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; 723 (void)node; 1037 724 return nullptr; 1038 725 } 1039 726 1040 727 const ast::Expr * visit( const ast::DeletedExpr * node ) override final { 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; 728 (void)node; 1050 729 return nullptr; 1051 730 } 1052 731 1053 732 const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final { 1054 auto expr = visitBaseExpr( node, 1055 new DefaultArgExpr( 1056 get<Expression>().accept1(node->expr) 1057 ) 1058 ); 1059 this->node = expr; 733 (void)node; 1060 734 return nullptr; 1061 735 } 1062 736 1063 737 const ast::Expr * visit( const ast::GenericExpr * node ) override final { 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; 738 (void)node; 1078 739 return nullptr; 1079 740 } … … 1287 948 1288 949 const ast::Designation * visit( const ast::Designation * node ) override final { 1289 auto designation = new Designation( get<Expression>().acceptL( node->designators ) ); 1290 designation->location = node->location; 1291 this->node = designation; 950 (void)node; 1292 951 return nullptr; 1293 952 } 1294 953 1295 954 const ast::Init * visit( const ast::SingleInit * node ) override final { 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; 955 (void)node; 1302 956 return nullptr; 1303 957 } 1304 958 1305 959 const ast::Init * visit( const ast::ListInit * node ) override final { 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; 960 (void)node; 1313 961 return nullptr; 1314 962 } 1315 963 1316 964 const ast::Init * visit( const ast::ConstructorInit * node ) override final { 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; 965 (void)node; 1324 966 return nullptr; 1325 967 } 1326 968 1327 969 const ast::Attribute * visit( const ast::Attribute * node ) override final { 1328 auto attr = new Attribute( 1329 node->name, 1330 get<Expression>().acceptL(node->parameters) 1331 ); 1332 this->node = attr; 970 (void)node; 1333 971 return nullptr; 1334 972 } 1335 973 1336 974 const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) override final { 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 ); 975 (void)node; 1340 976 return nullptr; 1341 977 } … … 1448 1084 virtual void visit( FunctionDecl * old ) override final { 1449 1085 if ( inCache( old ) ) return; 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; 1086 // TODO 1087 auto decl = (ast::FunctionDecl *)nullptr; 1465 1088 cache.emplace( old, decl ); 1466 1467 this->node = decl;1468 1089 } 1469 1090 … … 1550 1171 1551 1172 virtual void visit( TypeDecl * old ) override final { 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; 1173 if ( inCache( old ) ) return; 1174 // TODO 1175 auto decl = (ast::TypeDecl *)nullptr; 1566 1176 cache.emplace( old, decl ); 1567 1568 this->node = decl;1569 1177 } 1570 1178 … … 1586 1194 } 1587 1195 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; 1196 virtual void visit( AsmDecl * ) override final { 1197 1198 } 1199 1200 virtual void visit( StaticAssertDecl * ) override final { 1201 1611 1202 } 1612 1203 1613 1204 virtual void visit( CompoundStmt * old ) override final { 1614 if ( inCache( old ) ) return;1615 1205 auto stmt = new ast::CompoundStmt( 1616 1206 old->location, … … 1620 1210 1621 1211 this->node = stmt; 1622 cache.emplace( old, this->node );1623 1212 } 1624 1213 1625 1214 virtual void visit( ExprStmt * old ) override final { 1626 if ( inCache( old ) ) return;1627 1215 this->node = new ast::ExprStmt( 1628 1216 old->location, … … 1630 1218 GET_LABELS_V(old->labels) 1631 1219 ); 1632 cache.emplace( old, this->node );1633 1220 } 1634 1221 1635 1222 virtual void visit( AsmStmt * old ) override final { 1636 if ( inCache( old ) ) return;1637 1223 this->node = new ast::AsmStmt( 1638 1224 old->location, … … 1645 1231 GET_LABELS_V(old->labels) 1646 1232 ); 1647 cache.emplace( old, this->node );1648 1233 } 1649 1234 1650 1235 virtual void visit( DirectiveStmt * old ) override final { 1651 if ( inCache( old ) ) return;1652 1236 this->node = new ast::DirectiveStmt( 1653 1237 old->location, … … 1655 1239 GET_LABELS_V(old->labels) 1656 1240 ); 1657 cache.emplace( old, this->node );1658 1241 } 1659 1242 1660 1243 virtual void visit( IfStmt * old ) override final { 1661 if ( inCache( old ) ) return;1662 1244 this->node = new ast::IfStmt( 1663 1245 old->location, … … 1668 1250 GET_LABELS_V(old->labels) 1669 1251 ); 1670 cache.emplace( old, this->node );1671 1252 } 1672 1253 1673 1254 virtual void visit( SwitchStmt * old ) override final { 1674 if ( inCache( old ) ) return;1675 1255 this->node = new ast::SwitchStmt( 1676 1256 old->location, … … 1679 1259 GET_LABELS_V(old->labels) 1680 1260 ); 1681 cache.emplace( old, this->node );1682 1261 } 1683 1262 1684 1263 virtual void visit( CaseStmt * old ) override final { 1685 if ( inCache( old ) ) return;1686 1264 this->node = new ast::CaseStmt( 1687 1265 old->location, … … 1690 1268 GET_LABELS_V(old->labels) 1691 1269 ); 1692 cache.emplace( old, this->node );1693 1270 } 1694 1271 1695 1272 virtual void visit( WhileStmt * old ) override final { 1696 if ( inCache( old ) ) return;1697 1273 this->node = new ast::WhileStmt( 1698 1274 old->location, … … 1703 1279 GET_LABELS_V(old->labels) 1704 1280 ); 1705 cache.emplace( old, this->node );1706 1281 } 1707 1282 1708 1283 virtual void visit( ForStmt * old ) override final { 1709 if ( inCache( old ) ) return;1710 1284 this->node = new ast::ForStmt( 1711 1285 old->location, … … 1716 1290 GET_LABELS_V(old->labels) 1717 1291 ); 1718 cache.emplace( old, this->node );1719 1292 } 1720 1293 1721 1294 virtual void visit( BranchStmt * old ) override final { 1722 if ( inCache( old ) ) return;1723 1295 if (old->computedTarget) { 1724 1296 this->node = new ast::BranchStmt( … … 1754 1326 this->node = stmt; 1755 1327 } 1756 cache.emplace( old, this->node );1757 1328 } 1758 1329 1759 1330 virtual void visit( ReturnStmt * old ) override final { 1760 if ( inCache( old ) ) return;1761 1331 this->node = new ast::ReturnStmt( 1762 1332 old->location, … … 1764 1334 GET_LABELS_V(old->labels) 1765 1335 ); 1766 cache.emplace( old, this->node );1767 1336 } 1768 1337 1769 1338 virtual void visit( ThrowStmt * old ) override final { 1770 if ( inCache( old ) ) return;1771 1339 ast::ThrowStmt::Kind kind; 1772 1340 switch (old->kind) { … … 1788 1356 GET_LABELS_V(old->labels) 1789 1357 ); 1790 cache.emplace( old, this->node );1791 1358 } 1792 1359 1793 1360 virtual void visit( TryStmt * old ) override final { 1794 if ( inCache( old ) ) return;1795 1361 this->node = new ast::TryStmt( 1796 1362 old->location, … … 1800 1366 GET_LABELS_V(old->labels) 1801 1367 ); 1802 cache.emplace( old, this->node );1803 1368 } 1804 1369 1805 1370 virtual void visit( CatchStmt * old ) override final { 1806 if ( inCache( old ) ) return;1807 1371 ast::CatchStmt::Kind kind; 1808 1372 switch (old->kind) { … … 1825 1389 GET_LABELS_V(old->labels) 1826 1390 ); 1827 cache.emplace( old, this->node );1828 1391 } 1829 1392 1830 1393 virtual void visit( FinallyStmt * old ) override final { 1831 if ( inCache( old ) ) return;1832 1394 this->node = new ast::FinallyStmt( 1833 1395 old->location, … … 1835 1397 GET_LABELS_V(old->labels) 1836 1398 ); 1837 cache.emplace( old, this->node );1838 1399 } 1839 1400 1840 1401 virtual void visit( WaitForStmt * old ) override final { 1841 if ( inCache( old ) ) return;1842 1402 ast::WaitForStmt * stmt = new ast::WaitForStmt( 1843 1403 old->location, … … 1867 1427 1868 1428 this->node = stmt; 1869 cache.emplace( old, this->node );1870 1429 } 1871 1430 1872 1431 virtual void visit( WithStmt * old ) override final { 1873 if ( inCache( old ) ) return;1874 1432 this->node = new ast::WithStmt( 1875 1433 old->location, … … 1878 1436 GET_LABELS_V(old->labels) 1879 1437 ); 1880 cache.emplace( old, this->node );1881 1438 } 1882 1439 1883 1440 virtual void visit( NullStmt * old ) override final { 1884 if ( inCache( old ) ) return;1885 1441 this->node = new ast::NullStmt( 1886 1442 old->location, 1887 1443 GET_LABELS_V(old->labels) 1888 1444 ); 1889 cache.emplace( old, this->node );1890 1445 } 1891 1446 1892 1447 virtual void visit( DeclStmt * old ) override final { 1893 if ( inCache( old ) ) return;1894 1448 this->node = new ast::DeclStmt( 1895 1449 old->location, … … 1897 1451 GET_LABELS_V(old->labels) 1898 1452 ); 1899 cache.emplace( old, this->node );1900 1453 } 1901 1454 1902 1455 virtual void visit( ImplicitCtorDtorStmt * old ) override final { 1903 if ( inCache( old ) ) return;1904 1456 this->node = new ast::ImplicitCtorDtorStmt( 1905 1457 old->location, … … 1907 1459 GET_LABELS_V(old->labels) 1908 1460 ); 1909 cache.emplace( old, this->node );1910 1461 } 1911 1462 … … 1952 1503 } 1953 1504 1954 ast::Expr * visitBaseExpr_SkipResultType(Expression * old, ast::Expr * nw) { 1955 1505 ast::Expr * visitBaseExpr(Expression * old, ast::Expr * nw) { 1506 1507 nw->result = GET_ACCEPT_1(result, Type); 1956 1508 nw->env = convertTypeSubstitution(old->env); 1957 1509 … … 1960 1512 1961 1513 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);;1968 1514 } 1969 1515 … … 2001 1547 new ast::CastExpr( 2002 1548 old->location, 2003 GET_ACCEPT_1(arg, Expr),1549 nullptr, // cast's "to" type is expr's result type; converted in visitBaseExpr 2004 1550 old->isGenerated ? ast::GeneratedCast : ast::ExplicitCast 2005 1551 ) … … 2007 1553 } 2008 1554 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 ); 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 2449 1685 } 2450 1686 … … 2642 1878 } 2643 1879 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 ); 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 2675 1894 } 2676 1895 2677 1896 virtual void visit( Constant * ) override final { 2678 // Handled in visit( ConstantEpxr * ). 2679 // In the new tree, Constant fields are inlined into containing ConstantExpression. 1897 1898 } 1899 1900 virtual void visit( Attribute * ) override final { 1901 1902 } 1903 1904 virtual void visit( AttrExpr * ) override final { 1905 2680 1906 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 );2688 }2689 2690 virtual void visit( AttrExpr * ) override final {2691 assertf( false, "AttrExpr deprecated in new AST." );2692 1907 } 2693 1908 };
Note:
See TracChangeset
for help on using the changeset viewer.