Changes in src/AST/Convert.cpp [20de6fb:746ae82]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r20de6fb r746ae82 525 525 } 526 526 527 Expression * visitBaseExpr_skipResultType(const ast::Expr * src, Expression * tgt) { 528 529 tgt->location = src->location; 530 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 531 534 tgt->extension = src->extension; 532 533 535 convertInferUnion(tgt->inferParams, tgt->resnSlots, src->inferred); 536 534 537 return tgt; 535 }536 537 Expression * visitBaseExpr(const ast::Expr * src, Expression * tgt) {538 539 tgt->result = get<Type>().accept1(src->result);540 return visitBaseExpr_skipResultType(src, tgt);541 538 } 542 539 … … 574 571 575 572 const ast::Expr * visit( const ast::AddressExpr * node ) override final { 576 auto expr = visitBaseExpr( node, 577 new AddressExpr( 578 get<Expression>().accept1(node->arg) 579 ) 580 ); 581 this->node = expr; 573 (void)node; 582 574 return nullptr; 583 575 } 584 576 585 577 const ast::Expr * visit( const ast::LabelAddressExpr * node ) override final { 586 auto expr = visitBaseExpr( node, 587 new LabelAddressExpr( 588 makeLabel(nullptr, node->arg) 589 ) 590 ); 591 this->node = expr; 578 (void)node; 592 579 return nullptr; 593 580 } 594 581 595 582 const ast::Expr * visit( const ast::CastExpr * node ) override final { 596 auto expr = visitBaseExpr( node, 597 new CastExpr( 598 get<Expression>().accept1(node->arg), 599 (node->isGenerated == ast::GeneratedCast) 600 ) 601 ); 602 this->node = expr; 583 (void)node; 603 584 return nullptr; 604 585 } 605 586 606 587 const ast::Expr * visit( const ast::KeywordCastExpr * node ) override final { 607 KeywordCastExpr::Target castTarget = KeywordCastExpr::NUMBER_OF_TARGETS; 608 switch (node->target) { 609 case ast::KeywordCastExpr::Coroutine: 610 castTarget = KeywordCastExpr::Coroutine; 611 break; 612 case ast::KeywordCastExpr::Thread: 613 castTarget = KeywordCastExpr::Thread; 614 break; 615 case ast::KeywordCastExpr::Monitor: 616 castTarget = KeywordCastExpr::Monitor; 617 break; 618 default: 619 break; 620 } 621 assert ( castTarget < KeywordCastExpr::NUMBER_OF_TARGETS ); 622 auto expr = visitBaseExpr( node, 623 new KeywordCastExpr( 624 get<Expression>().accept1(node->arg), 625 castTarget 626 ) 627 ); 628 this->node = expr; 588 (void)node; 629 589 return nullptr; 630 590 } 631 591 632 592 const ast::Expr * visit( const ast::VirtualCastExpr * node ) override final { 633 auto expr = visitBaseExpr_skipResultType( node, 634 new VirtualCastExpr( 635 get<Expression>().accept1(node->arg), 636 get<Type>().accept1(node->result) 637 ) 638 ); 639 this->node = expr; 593 (void)node; 640 594 return nullptr; 641 595 } 642 596 643 597 const ast::Expr * visit( const ast::UntypedMemberExpr * node ) override final { 644 auto expr = visitBaseExpr( node, 645 new UntypedMemberExpr( 646 get<Expression>().accept1(node->member), 647 get<Expression>().accept1(node->aggregate) 648 ) 649 ); 650 this->node = expr; 598 (void)node; 651 599 return nullptr; 652 600 } 653 601 654 602 const ast::Expr * visit( const ast::MemberExpr * node ) override final { 655 auto expr = visitBaseExpr( node, 656 new MemberExpr( 657 inCache(node->member) ? 658 dynamic_cast<DeclarationWithType *>(this->node) : 659 get<DeclarationWithType>().accept1(node->member), 660 get<Expression>().accept1(node->aggregate) 661 ) 662 ); 663 this->node = expr; 603 (void)node; 664 604 return nullptr; 665 605 } 666 606 667 607 const ast::Expr * visit( const ast::VariableExpr * node ) override final { 668 auto expr = visitBaseExpr( node, 669 new VariableExpr( 670 inCache(node->var) ? 671 dynamic_cast<DeclarationWithType *>(this->node) : 672 get<DeclarationWithType>().accept1(node->var) 673 ) 674 ); 675 this->node = expr; 676 return nullptr; 677 } 678 679 bool isIntlikeConstantType(const ast::Type *t) { 680 if ( const ast::BasicType * basicType = dynamic_cast< const ast::BasicType * >( t ) ) { 681 if ( basicType->isInteger() ) { 682 return true; 683 } 684 } else if ( dynamic_cast< const ast::OneType * >( t ) ) { 685 return true; 686 } else if ( dynamic_cast< const ast::ZeroType * >( t ) ) { 687 return true; 688 } else if ( dynamic_cast< const ast::PointerType * >( t ) ) { 689 // null pointer constants, with zero int-values 690 return true; 691 } 692 return false; 693 } 694 695 bool isFloatlikeConstantType(const ast::Type *t) { 696 if ( const ast::BasicType * bty = dynamic_cast< const ast::BasicType * >( t ) ) { 697 if ( ! bty->isInteger() ) { 698 return true; 699 } 700 } 701 return false; 702 } 703 704 bool isStringlikeConstantType(const ast::Type *t) { 705 if ( const ast::ArrayType * aty = dynamic_cast< const ast::ArrayType * >( t ) ) { 706 if ( const ast::BasicType * bty = aty->base.as<ast::BasicType>() ) { 707 if ( bty->kind == ast::BasicType::Kind::Char ) { 708 return true; 709 } 710 } 711 } 712 return false; 608 (void)node; 609 return nullptr; 713 610 } 714 611 715 612 const ast::Expr * visit( const ast::ConstantExpr * node ) override final { 716 ConstantExpr *rslt = nullptr; 717 if (isIntlikeConstantType(node->result)) { 718 rslt = new ConstantExpr(Constant( 719 get<Type>().accept1(node->result), 720 node->rep, 721 (unsigned long long) node->intValue() 722 )); 723 } else if (isFloatlikeConstantType(node->result)) { 724 rslt = new ConstantExpr(Constant( 725 get<Type>().accept1(node->result), 726 node->rep, 727 (double) node->floatValue() 728 )); 729 } else if (isStringlikeConstantType(node->result)) { 730 rslt = new ConstantExpr(Constant::from_string( 731 node->rep 732 )); 733 } 734 assert(rslt); 735 auto expr = visitBaseExpr( node, rslt ); 736 this->node = expr; 613 (void)node; 737 614 return nullptr; 738 615 } 739 616 740 617 const ast::Expr * visit( const ast::SizeofExpr * node ) override final { 741 assert (node->expr || node->type); 742 assert (! (node->expr && node->type)); 743 SizeofExpr *rslt; 744 if (node->expr) { 745 rslt = new SizeofExpr( 746 get<Expression>().accept1(node->expr) 747 ); 748 assert (!rslt->isType); 749 } 750 if (node->type) { 751 rslt = new SizeofExpr( 752 get<Type>().accept1(node->type) 753 ); 754 assert (rslt->isType); 755 } 756 auto expr = visitBaseExpr( node, rslt ); 757 this->node = expr; 618 (void)node; 758 619 return nullptr; 759 620 } 760 621 761 622 const ast::Expr * visit( const ast::AlignofExpr * node ) override final { 762 assert (node->expr || node->type); 763 assert (! (node->expr && node->type)); 764 AlignofExpr *rslt; 765 if (node->expr) { 766 rslt = new AlignofExpr( 767 get<Expression>().accept1(node->expr) 768 ); 769 assert (!rslt->isType); 770 } 771 if (node->type) { 772 rslt = new AlignofExpr( 773 get<Type>().accept1(node->type) 774 ); 775 assert (rslt->isType); 776 } 777 auto expr = visitBaseExpr( node, rslt ); 778 this->node = expr; 623 (void)node; 779 624 return nullptr; 780 625 } 781 626 782 627 const ast::Expr * visit( const ast::UntypedOffsetofExpr * node ) override final { 783 auto expr = visitBaseExpr( node, 784 new UntypedOffsetofExpr( 785 get<Type>().accept1(node->type), 786 node->member 787 ) 788 ); 789 this->node = expr; 628 (void)node; 790 629 return nullptr; 791 630 } 792 631 793 632 const ast::Expr * visit( const ast::OffsetofExpr * node ) override final { 794 auto expr = visitBaseExpr( node, 795 new OffsetofExpr( 796 get<Type>().accept1(node->type), 797 inCache(node->member) ? 798 dynamic_cast<DeclarationWithType *>(this->node) : 799 get<DeclarationWithType>().accept1(node->member) 800 ) 801 ); 802 this->node = expr; 633 (void)node; 803 634 return nullptr; 804 635 } 805 636 806 637 const ast::Expr * visit( const ast::OffsetPackExpr * node ) override final { 807 auto expr = visitBaseExpr( node, 808 new OffsetPackExpr( 809 get<StructInstType>().accept1(node->type) 810 ) 811 ); 812 this->node = expr; 638 (void)node; 813 639 return nullptr; 814 640 } 815 641 816 642 const ast::Expr * visit( const ast::LogicalExpr * node ) override final { 817 assert (node->isAnd == ast::LogicalFlag::AndExpr || 818 node->isAnd == ast::LogicalFlag::OrExpr ); 819 auto expr = visitBaseExpr( node, 820 new LogicalExpr( 821 get<Expression>().accept1(node->arg1), 822 get<Expression>().accept1(node->arg2), 823 (node->isAnd == ast::LogicalFlag::AndExpr) 824 ) 825 ); 826 this->node = expr; 643 (void)node; 827 644 return nullptr; 828 645 } 829 646 830 647 const ast::Expr * visit( const ast::ConditionalExpr * node ) override final { 831 auto expr = visitBaseExpr( node, 832 new ConditionalExpr( 833 get<Expression>().accept1(node->arg1), 834 get<Expression>().accept1(node->arg2), 835 get<Expression>().accept1(node->arg3) 836 ) 837 ); 838 this->node = expr; 648 (void)node; 839 649 return nullptr; 840 650 } 841 651 842 652 const ast::Expr * visit( const ast::CommaExpr * node ) override final { 843 auto expr = visitBaseExpr( node, 844 new CommaExpr( 845 get<Expression>().accept1(node->arg1), 846 get<Expression>().accept1(node->arg2) 847 ) 848 ); 849 this->node = expr; 653 (void)node; 850 654 return nullptr; 851 655 } 852 656 853 657 const ast::Expr * visit( const ast::TypeExpr * node ) override final { 854 auto expr = visitBaseExpr( node, 855 new TypeExpr( 856 get<Type>().accept1(node->type) 857 ) 858 ); 859 this->node = expr; 658 (void)node; 860 659 return nullptr; 861 660 } 862 661 863 662 const ast::Expr * visit( const ast::AsmExpr * node ) override final { 864 auto expr = visitBaseExpr( node, 865 new AsmExpr( 866 get<Expression>().accept1(node->inout), 867 get<Expression>().accept1(node->constraint), 868 get<Expression>().accept1(node->operand) 869 ) 870 ); 871 this->node = expr; 663 (void)node; 872 664 return nullptr; 873 665 } 874 666 875 667 const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final { 876 auto rslt = new ImplicitCopyCtorExpr( 877 get<ApplicationExpr>().accept1(node->callExpr) 878 ); 879 880 rslt->tempDecls = get<ObjectDecl>().acceptL(node->tempDecls); 881 rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls); 882 rslt->dtors = get<Expression>().acceptL(node->dtors); 883 884 auto expr = visitBaseExpr( node, rslt ); 885 this->node = expr; 668 (void)node; 886 669 return nullptr; 887 670 } 888 671 889 672 const ast::Expr * visit( const ast::ConstructorExpr * node ) override final { 890 auto expr = visitBaseExpr( node, 891 new ConstructorExpr( 892 get<Expression>().accept1(node->callExpr) 893 ) 894 ); 895 this->node = expr; 673 (void)node; 896 674 return nullptr; 897 675 } 898 676 899 677 const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final { 900 auto expr = visitBaseExpr_skipResultType( node, 901 new CompoundLiteralExpr( 902 get<Type>().accept1(node->result), 903 get<Initializer>().accept1(node->init) 904 ) 905 ); 906 this->node = expr; 678 (void)node; 907 679 return nullptr; 908 680 } 909 681 910 682 const ast::Expr * visit( const ast::RangeExpr * node ) override final { 911 auto expr = visitBaseExpr( node, 912 new RangeExpr( 913 get<Expression>().accept1(node->low), 914 get<Expression>().accept1(node->high) 915 ) 916 ); 917 this->node = expr; 683 (void)node; 918 684 return nullptr; 919 685 } 920 686 921 687 const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final { 922 auto expr = visitBaseExpr( node, 923 new UntypedTupleExpr( 924 get<Expression>().acceptL(node->exprs) 925 ) 926 ); 927 this->node = expr; 688 (void)node; 928 689 return nullptr; 929 690 } 930 691 931 692 const ast::Expr * visit( const ast::TupleExpr * node ) override final { 932 auto expr = visitBaseExpr( node, 933 new UntypedTupleExpr( 934 get<Expression>().acceptL(node->exprs) 935 ) 936 ); 937 this->node = expr; 693 (void)node; 938 694 return nullptr; 939 695 } 940 696 941 697 const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final { 942 auto expr = visitBaseExpr( node, 943 new TupleIndexExpr( 944 get<Expression>().accept1(node->tuple), 945 node->index 946 ) 947 ); 948 this->node = expr; 698 (void)node; 949 699 return nullptr; 950 700 } 951 701 952 702 const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final { 953 auto expr = visitBaseExpr( node, 954 new TupleAssignExpr( 955 get<StmtExpr>().accept1(node->stmtExpr) 956 ) 957 ); 958 this->node = expr; 703 (void)node; 959 704 return nullptr; 960 705 } 961 706 962 707 const ast::Expr * visit( const ast::StmtExpr * node ) override final { 963 auto rslt = new StmtExpr( 964 get<CompoundStmt>().accept1(node->stmts) 965 ); 966 967 rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls); 968 rslt->dtors = get<Expression>().acceptL(node->dtors); 969 970 auto expr = visitBaseExpr( node, rslt ); 971 this->node = expr; 708 (void)node; 972 709 return nullptr; 973 710 } 974 711 975 712 const ast::Expr * visit( const ast::UniqueExpr * node ) override final { 976 auto rslt = new UniqueExpr( 977 get<Expression>().accept1(node->expr) 978 ); 979 980 rslt->object = get<ObjectDecl> ().accept1(node->object); 981 rslt->var = get<VariableExpr>().accept1(node->var); 982 983 auto expr = visitBaseExpr( node, rslt ); 984 this->node = expr; 713 (void)node; 985 714 return nullptr; 986 715 } 987 716 988 717 const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final { 989 std::list<InitAlternative> initAlts; 990 for (auto ia : node->initAlts) { 991 initAlts.push_back(InitAlternative( 992 get<Type> ().accept1(ia.type), 993 get<Designation>().accept1(ia.designation) 994 )); 995 } 996 auto expr = visitBaseExpr( node, 997 new UntypedInitExpr( 998 get<Expression>().accept1(node->expr), 999 initAlts 1000 ) 1001 ); 1002 this->node = expr; 718 (void)node; 1003 719 return nullptr; 1004 720 } 1005 721 1006 722 const ast::Expr * visit( const ast::InitExpr * node ) override final { 1007 auto expr = visitBaseExpr( node, 1008 new InitExpr( 1009 get<Expression>().accept1(node->expr), 1010 get<Designation>().accept1(node->designation) 1011 ) 1012 ); 1013 this->node = expr; 723 (void)node; 1014 724 return nullptr; 1015 725 } 1016 726 1017 727 const ast::Expr * visit( const ast::DeletedExpr * node ) override final { 1018 auto expr = visitBaseExpr( node, 1019 new DeletedExpr( 1020 get<Expression>().accept1(node->expr), 1021 inCache(node->deleteStmt) ? 1022 this->node : 1023 get<BaseSyntaxNode>().accept1(node->deleteStmt) 1024 ) 1025 ); 1026 this->node = expr; 728 (void)node; 1027 729 return nullptr; 1028 730 } 1029 731 1030 732 const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final { 1031 auto expr = visitBaseExpr( node, 1032 new DefaultArgExpr( 1033 get<Expression>().accept1(node->expr) 1034 ) 1035 ); 1036 this->node = expr; 733 (void)node; 1037 734 return nullptr; 1038 735 } 1039 736 1040 737 const ast::Expr * visit( const ast::GenericExpr * node ) override final { 1041 std::list<GenericExpr::Association> associations; 1042 for (auto association : node->associations) { 1043 associations.push_back(GenericExpr::Association( 1044 get<Type> ().accept1(association.type), 1045 get<Expression>().accept1(association.expr) 1046 )); 1047 } 1048 auto expr = visitBaseExpr( node, 1049 new GenericExpr( 1050 get<Expression>().accept1(node->control), 1051 associations 1052 ) 1053 ); 1054 this->node = expr; 738 (void)node; 1055 739 return nullptr; 1056 740 } … … 1819 1503 } 1820 1504 1821 ast::Expr * visitBaseExpr_SkipResultType(Expression * old, ast::Expr * nw) { 1822 1505 ast::Expr * visitBaseExpr(Expression * old, ast::Expr * nw) { 1506 1507 nw->result = GET_ACCEPT_1(result, Type); 1823 1508 nw->env = convertTypeSubstitution(old->env); 1824 1509 … … 1827 1512 1828 1513 return nw; 1829 }1830 1831 ast::Expr * visitBaseExpr(Expression * old, ast::Expr * nw) {1832 1833 nw->result = GET_ACCEPT_1(result, Type);1834 return visitBaseExpr_SkipResultType(old, nw);;1835 1514 } 1836 1515 … … 1868 1547 new ast::CastExpr( 1869 1548 old->location, 1870 GET_ACCEPT_1(arg, Expr),1549 nullptr, // cast's "to" type is expr's result type; converted in visitBaseExpr 1871 1550 old->isGenerated ? ast::GeneratedCast : ast::ExplicitCast 1872 1551 ) … … 1874 1553 } 1875 1554 1876 virtual void visit( KeywordCastExpr * old) override final { 1877 ast::KeywordCastExpr::Target castTarget = ast::KeywordCastExpr::NUMBER_OF_TARGETS; 1878 switch (old->target) { 1879 case KeywordCastExpr::Coroutine: 1880 castTarget = ast::KeywordCastExpr::Coroutine; 1881 break; 1882 case KeywordCastExpr::Thread: 1883 castTarget = ast::KeywordCastExpr::Thread; 1884 break; 1885 case KeywordCastExpr::Monitor: 1886 castTarget = ast::KeywordCastExpr::Monitor; 1887 break; 1888 default: 1889 break; 1890 } 1891 assert ( castTarget < ast::KeywordCastExpr::NUMBER_OF_TARGETS ); 1892 this->node = visitBaseExpr( old, 1893 new ast::KeywordCastExpr( 1894 old->location, 1895 GET_ACCEPT_1(arg, Expr), 1896 castTarget 1897 ) 1898 ); 1899 } 1900 1901 virtual void visit( VirtualCastExpr * old ) override final { 1902 this->node = visitBaseExpr_SkipResultType( old, 1903 new ast::VirtualCastExpr( 1904 old->location, 1905 GET_ACCEPT_1(arg, Expr), 1906 GET_ACCEPT_1(result, Type) 1907 ) 1908 ); 1909 } 1910 1911 virtual void visit( AddressExpr * old ) override final { 1912 this->node = visitBaseExpr( old, 1913 new ast::AddressExpr( 1914 old->location, 1915 GET_ACCEPT_1(arg, Expr) 1916 ) 1917 ); 1918 } 1919 1920 virtual void visit( LabelAddressExpr * old ) override final { 1921 this->node = visitBaseExpr( old, 1922 new ast::LabelAddressExpr( 1923 old->location, 1924 make_label(&old->arg) 1925 ) 1926 ); 1927 } 1928 1929 virtual void visit( UntypedMemberExpr * old ) override final { 1930 this->node = visitBaseExpr( old, 1931 new ast::UntypedMemberExpr( 1932 old->location, 1933 GET_ACCEPT_1(member, Expr), 1934 GET_ACCEPT_1(aggregate, Expr) 1935 ) 1936 ); 1937 } 1938 1939 virtual void visit( MemberExpr * old ) override final { 1940 this->node = visitBaseExpr( old, 1941 new ast::MemberExpr( 1942 old->location, 1943 inCache(old->member) ? 1944 dynamic_cast<ast::DeclWithType *>(this->node) : 1945 GET_ACCEPT_1(member, DeclWithType), 1946 GET_ACCEPT_1(aggregate, Expr) 1947 ) 1948 ); 1949 } 1950 1951 virtual void visit( VariableExpr * old ) override final { 1952 this->node = visitBaseExpr( old, 1953 new ast::VariableExpr( 1954 old->location, 1955 inCache(old->var) ? 1956 dynamic_cast<ast::DeclWithType *>(this->node) : 1957 GET_ACCEPT_1(var, DeclWithType) 1958 ) 1959 ); 1960 } 1961 1962 bool isIntlikeConstantType(const Type *t) { 1963 if ( const BasicType * basicType = dynamic_cast< const BasicType * >( t ) ) { 1964 if ( basicType->isInteger() ) { 1965 return true; 1966 } 1967 } else if ( dynamic_cast< const OneType * >( t ) ) { 1968 return true; 1969 } else if ( dynamic_cast< const ZeroType * >( t ) ) { 1970 return true; 1971 } else if ( dynamic_cast< const PointerType * >( t ) ) { 1972 // null pointer constants, with zero int-values 1973 return true; 1974 } 1975 return false; 1976 } 1977 1978 int isFloatlikeConstantType(const Type *t) { 1979 if ( const BasicType * bty = dynamic_cast< const BasicType * >( t ) ) { 1980 if ( ! bty->isInteger() ) { 1981 return true; 1982 } 1983 } 1984 return false; 1985 } 1986 1987 int isStringlikeConstantType(const Type *t) { 1988 if ( const ArrayType * aty = dynamic_cast< const ArrayType * >( t ) ) { 1989 if ( const BasicType * bty = dynamic_cast< const BasicType * >( aty->base ) ) { 1990 if ( bty->kind == BasicType::Kind::Char ) { 1991 return true; 1992 } 1993 } 1994 } 1995 return false; 1996 } 1997 1998 virtual void visit( ConstantExpr * old ) override final { 1999 ast::ConstantExpr *rslt = nullptr; 2000 if (isIntlikeConstantType(old->result)) { 2001 rslt = new ast::ConstantExpr( 2002 old->location, 2003 GET_ACCEPT_1(result, Type), 2004 old->constant.get_value(), 2005 (unsigned long long) old->intValue() 2006 ); 2007 } else if (isFloatlikeConstantType(old->result)) { 2008 rslt = new ast::ConstantExpr( 2009 old->location, 2010 GET_ACCEPT_1(result, Type), 2011 old->constant.get_value(), 2012 (double) old->constant.get_dval() 2013 ); 2014 } else if (isStringlikeConstantType(old->result)) { 2015 rslt = ast::ConstantExpr::from_string( 2016 old->location, 2017 old->constant.get_value() 2018 ); 2019 } 2020 assert(rslt); 2021 this->node = visitBaseExpr( old, rslt ); 2022 } 2023 2024 virtual void visit( SizeofExpr * old ) override final { 2025 assert (old->expr || old->type); 2026 assert (! (old->expr && old->type)); 2027 ast::SizeofExpr *rslt; 2028 if (old->expr) { 2029 assert(!old->isType); 2030 rslt = new ast::SizeofExpr( 2031 old->location, 2032 GET_ACCEPT_1(expr, Expr) 2033 ); 2034 } 2035 if (old->type) { 2036 assert(old->isType); 2037 rslt = new ast::SizeofExpr( 2038 old->location, 2039 GET_ACCEPT_1(type, Type) 2040 ); 2041 } 2042 this->node = visitBaseExpr( old, rslt ); 2043 } 2044 2045 virtual void visit( AlignofExpr * old ) override final { 2046 assert (old->expr || old->type); 2047 assert (! (old->expr && old->type)); 2048 ast::AlignofExpr *rslt; 2049 if (old->expr) { 2050 assert(!old->isType); 2051 rslt = new ast::AlignofExpr( 2052 old->location, 2053 GET_ACCEPT_1(expr, Expr) 2054 ); 2055 } 2056 if (old->type) { 2057 assert(old->isType); 2058 rslt = new ast::AlignofExpr( 2059 old->location, 2060 GET_ACCEPT_1(type, Type) 2061 ); 2062 } 2063 this->node = visitBaseExpr( old, rslt ); 2064 } 2065 2066 virtual void visit( UntypedOffsetofExpr * old ) override final { 2067 this->node = visitBaseExpr( old, 2068 new ast::UntypedOffsetofExpr( 2069 old->location, 2070 GET_ACCEPT_1(type, Type), 2071 old->member 2072 ) 2073 ); 2074 } 2075 2076 virtual void visit( OffsetofExpr * old ) override final { 2077 this->node = visitBaseExpr( old, 2078 new ast::OffsetofExpr( 2079 old->location, 2080 GET_ACCEPT_1(type, Type), 2081 inCache(old->member) ? 2082 dynamic_cast<ast::DeclWithType *>(this->node) : 2083 GET_ACCEPT_1(member, DeclWithType) 2084 ) 2085 ); 2086 } 2087 2088 virtual void visit( OffsetPackExpr * old ) override final { 2089 this->node = visitBaseExpr( old, 2090 new ast::OffsetPackExpr( 2091 old->location, 2092 GET_ACCEPT_1(type, StructInstType) 2093 ) 2094 ); 2095 } 2096 2097 virtual void visit( LogicalExpr * old ) override final { 2098 this->node = visitBaseExpr( old, 2099 new ast::LogicalExpr( 2100 old->location, 2101 GET_ACCEPT_1(arg1, Expr), 2102 GET_ACCEPT_1(arg2, Expr), 2103 old->get_isAnd() ? 2104 ast::LogicalFlag::AndExpr : 2105 ast::LogicalFlag::OrExpr 2106 ) 2107 ); 2108 } 2109 2110 virtual void visit( ConditionalExpr * old ) override final { 2111 this->node = visitBaseExpr( old, 2112 new ast::ConditionalExpr( 2113 old->location, 2114 GET_ACCEPT_1(arg1, Expr), 2115 GET_ACCEPT_1(arg2, Expr), 2116 GET_ACCEPT_1(arg3, Expr) 2117 ) 2118 ); 2119 } 2120 2121 virtual void visit( CommaExpr * old ) override final { 2122 this->node = visitBaseExpr( old, 2123 new ast::CommaExpr( 2124 old->location, 2125 GET_ACCEPT_1(arg1, Expr), 2126 GET_ACCEPT_1(arg2, Expr) 2127 ) 2128 ); 2129 } 2130 2131 virtual void visit( TypeExpr * old ) override final { 2132 this->node = visitBaseExpr( old, 2133 new ast::TypeExpr( 2134 old->location, 2135 GET_ACCEPT_1(type, Type) 2136 ) 2137 ); 2138 } 2139 2140 virtual void visit( AsmExpr * old ) override final { 2141 this->node = visitBaseExpr( old, 2142 new ast::AsmExpr( 2143 old->location, 2144 GET_ACCEPT_1(inout, Expr), 2145 GET_ACCEPT_1(constraint, Expr), 2146 GET_ACCEPT_1(operand, Expr) 2147 ) 2148 ); 2149 } 2150 2151 virtual void visit( ImplicitCopyCtorExpr * old ) override final { 2152 auto rslt = new ast::ImplicitCopyCtorExpr( 2153 old->location, 2154 GET_ACCEPT_1(callExpr, ApplicationExpr) 2155 ); 2156 2157 rslt->tempDecls = GET_ACCEPT_V(tempDecls, ObjectDecl); 2158 rslt->returnDecls = GET_ACCEPT_V(returnDecls, ObjectDecl); 2159 rslt->dtors = GET_ACCEPT_V(dtors, Expr); 2160 2161 this->node = visitBaseExpr( old, rslt ); 2162 } 2163 2164 virtual void visit( ConstructorExpr * old ) override final { 2165 this->node = visitBaseExpr( old, 2166 new ast::ConstructorExpr( 2167 old->location, 2168 GET_ACCEPT_1(callExpr, Expr) 2169 ) 2170 ); 2171 } 2172 2173 virtual void visit( CompoundLiteralExpr * old ) override final { 2174 this->node = visitBaseExpr_SkipResultType( old, 2175 new ast::CompoundLiteralExpr( 2176 old->location, 2177 GET_ACCEPT_1(result, Type), 2178 GET_ACCEPT_1(initializer, Init) 2179 ) 2180 ); 2181 } 2182 2183 virtual void visit( RangeExpr * old ) override final { 2184 this->node = visitBaseExpr( old, 2185 new ast::RangeExpr( 2186 old->location, 2187 GET_ACCEPT_1(low, Expr), 2188 GET_ACCEPT_1(high, Expr) 2189 ) 2190 ); 2191 } 2192 2193 virtual void visit( UntypedTupleExpr * old ) override final { 2194 this->node = visitBaseExpr( old, 2195 new ast::UntypedTupleExpr( 2196 old->location, 2197 GET_ACCEPT_V(exprs, Expr) 2198 ) 2199 ); 2200 } 2201 2202 virtual void visit( TupleExpr * old ) override final { 2203 this->node = visitBaseExpr( old, 2204 new ast::TupleExpr( 2205 old->location, 2206 GET_ACCEPT_V(exprs, Expr) 2207 ) 2208 ); 2209 } 2210 2211 virtual void visit( TupleIndexExpr * old ) override final { 2212 this->node = visitBaseExpr( old, 2213 new ast::TupleIndexExpr( 2214 old->location, 2215 GET_ACCEPT_1(tuple, Expr), 2216 old->index 2217 ) 2218 ); 2219 } 2220 2221 virtual void visit( TupleAssignExpr * old ) override final { 2222 this->node = visitBaseExpr_SkipResultType( old, 2223 new ast::TupleAssignExpr( 2224 old->location, 2225 GET_ACCEPT_1(result, Type), 2226 GET_ACCEPT_1(stmtExpr, StmtExpr) 2227 ) 2228 ); 2229 } 2230 2231 virtual void visit( StmtExpr * old ) override final { 2232 auto rslt = new ast::StmtExpr( 2233 old->location, 2234 GET_ACCEPT_1(statements, CompoundStmt) 2235 ); 2236 rslt->returnDecls = GET_ACCEPT_V(returnDecls, ObjectDecl); 2237 rslt->dtors = GET_ACCEPT_V(dtors , Expr); 2238 2239 this->node = visitBaseExpr_SkipResultType( old, rslt ); 2240 } 2241 2242 virtual void visit( UniqueExpr * old ) override final { 2243 auto rslt = new ast::UniqueExpr( 2244 old->location, 2245 GET_ACCEPT_1(expr, Expr) 2246 ); 2247 rslt->object = GET_ACCEPT_1(object, ObjectDecl); 2248 rslt->var = GET_ACCEPT_1(var , VariableExpr); 2249 2250 this->node = visitBaseExpr( old, rslt ); 2251 } 2252 2253 virtual void visit( UntypedInitExpr * old ) override final { 2254 std::vector<ast::InitAlternative> initAlts; 2255 for (auto ia : old->initAlts) { 2256 initAlts.push_back(ast::InitAlternative( 2257 getAccept1< ast::Type, Type * >( ia.type ), 2258 getAccept1< ast::Designation, Designation * >( ia.designation ) 2259 )); 2260 } 2261 this->node = visitBaseExpr( old, 2262 new ast::UntypedInitExpr( 2263 old->location, 2264 GET_ACCEPT_1(expr, Expr), 2265 std::move(initAlts) 2266 ) 2267 ); 2268 } 2269 2270 virtual void visit( InitExpr * old ) override final { 2271 this->node = visitBaseExpr( old, 2272 new ast::InitExpr( 2273 old->location, 2274 GET_ACCEPT_1(expr, Expr), 2275 GET_ACCEPT_1(designation, Designation) 2276 ) 2277 ); 2278 } 2279 2280 virtual void visit( DeletedExpr * old ) override final { 2281 this->node = visitBaseExpr( old, 2282 new ast::DeletedExpr( 2283 old->location, 2284 GET_ACCEPT_1(expr, Expr), 2285 inCache(old->deleteStmt) ? 2286 this->node : 2287 GET_ACCEPT_1(deleteStmt, Node) 2288 ) 2289 ); 2290 } 2291 2292 virtual void visit( DefaultArgExpr * old ) override final { 2293 this->node = visitBaseExpr( old, 2294 new ast::DefaultArgExpr( 2295 old->location, 2296 GET_ACCEPT_1(expr, Expr) 2297 ) 2298 ); 2299 } 2300 2301 virtual void visit( GenericExpr * old ) override final { 2302 std::vector<ast::GenericExpr::Association> associations; 2303 for (auto association : old->associations) { 2304 associations.push_back(ast::GenericExpr::Association( 2305 getAccept1< ast::Type, Type * >( association.type ), 2306 getAccept1< ast::Expr, Expression * >( association.expr ) 2307 )); 2308 } 2309 this->node = visitBaseExpr( old, 2310 new ast::GenericExpr( 2311 old->location, 2312 GET_ACCEPT_1(control, Expr), 2313 std::move(associations) 2314 ) 2315 ); 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 2316 1685 } 2317 1686
Note: See TracChangeset
for help on using the changeset viewer.