Changes in src/AST/Convert.cpp [746ae82:20de6fb]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r746ae82 r20de6fb 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); 531 tgt->extension = src->extension; 532 533 convertInferUnion(tgt->inferParams, tgt->resnSlots, src->inferred); 534 return tgt; 535 } 536 527 537 Expression * visitBaseExpr(const ast::Expr * src, Expression * tgt) { 528 538 529 tgt->location = src->location;530 531 539 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; 540 return visitBaseExpr_skipResultType(src, tgt); 538 541 } 539 542 … … 571 574 572 575 const ast::Expr * visit( const ast::AddressExpr * node ) override final { 573 (void)node; 576 auto expr = visitBaseExpr( node, 577 new AddressExpr( 578 get<Expression>().accept1(node->arg) 579 ) 580 ); 581 this->node = expr; 574 582 return nullptr; 575 583 } 576 584 577 585 const ast::Expr * visit( const ast::LabelAddressExpr * node ) override final { 578 (void)node; 586 auto expr = visitBaseExpr( node, 587 new LabelAddressExpr( 588 makeLabel(nullptr, node->arg) 589 ) 590 ); 591 this->node = expr; 579 592 return nullptr; 580 593 } 581 594 582 595 const ast::Expr * visit( const ast::CastExpr * node ) override final { 583 (void)node; 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; 584 603 return nullptr; 585 604 } 586 605 587 606 const ast::Expr * visit( const ast::KeywordCastExpr * node ) override final { 588 (void)node; 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; 589 629 return nullptr; 590 630 } 591 631 592 632 const ast::Expr * visit( const ast::VirtualCastExpr * node ) override final { 593 (void)node; 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; 594 640 return nullptr; 595 641 } 596 642 597 643 const ast::Expr * visit( const ast::UntypedMemberExpr * node ) override final { 598 (void)node; 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; 599 651 return nullptr; 600 652 } 601 653 602 654 const ast::Expr * visit( const ast::MemberExpr * node ) override final { 603 (void)node; 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; 604 664 return nullptr; 605 665 } 606 666 607 667 const ast::Expr * visit( const ast::VariableExpr * node ) override final { 608 (void)node; 609 return nullptr; 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; 610 713 } 611 714 612 715 const ast::Expr * visit( const ast::ConstantExpr * node ) override final { 613 (void)node; 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; 614 737 return nullptr; 615 738 } 616 739 617 740 const ast::Expr * visit( const ast::SizeofExpr * node ) override final { 618 (void)node; 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; 619 758 return nullptr; 620 759 } 621 760 622 761 const ast::Expr * visit( const ast::AlignofExpr * node ) override final { 623 (void)node; 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; 624 779 return nullptr; 625 780 } 626 781 627 782 const ast::Expr * visit( const ast::UntypedOffsetofExpr * node ) override final { 628 (void)node; 783 auto expr = visitBaseExpr( node, 784 new UntypedOffsetofExpr( 785 get<Type>().accept1(node->type), 786 node->member 787 ) 788 ); 789 this->node = expr; 629 790 return nullptr; 630 791 } 631 792 632 793 const ast::Expr * visit( const ast::OffsetofExpr * node ) override final { 633 (void)node; 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; 634 803 return nullptr; 635 804 } 636 805 637 806 const ast::Expr * visit( const ast::OffsetPackExpr * node ) override final { 638 (void)node; 807 auto expr = visitBaseExpr( node, 808 new OffsetPackExpr( 809 get<StructInstType>().accept1(node->type) 810 ) 811 ); 812 this->node = expr; 639 813 return nullptr; 640 814 } 641 815 642 816 const ast::Expr * visit( const ast::LogicalExpr * node ) override final { 643 (void)node; 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; 644 827 return nullptr; 645 828 } 646 829 647 830 const ast::Expr * visit( const ast::ConditionalExpr * node ) override final { 648 (void)node; 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; 649 839 return nullptr; 650 840 } 651 841 652 842 const ast::Expr * visit( const ast::CommaExpr * node ) override final { 653 (void)node; 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; 654 850 return nullptr; 655 851 } 656 852 657 853 const ast::Expr * visit( const ast::TypeExpr * node ) override final { 658 (void)node; 854 auto expr = visitBaseExpr( node, 855 new TypeExpr( 856 get<Type>().accept1(node->type) 857 ) 858 ); 859 this->node = expr; 659 860 return nullptr; 660 861 } 661 862 662 863 const ast::Expr * visit( const ast::AsmExpr * node ) override final { 663 (void)node; 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; 664 872 return nullptr; 665 873 } 666 874 667 875 const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final { 668 (void)node; 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; 669 886 return nullptr; 670 887 } 671 888 672 889 const ast::Expr * visit( const ast::ConstructorExpr * node ) override final { 673 (void)node; 890 auto expr = visitBaseExpr( node, 891 new ConstructorExpr( 892 get<Expression>().accept1(node->callExpr) 893 ) 894 ); 895 this->node = expr; 674 896 return nullptr; 675 897 } 676 898 677 899 const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final { 678 (void)node; 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; 679 907 return nullptr; 680 908 } 681 909 682 910 const ast::Expr * visit( const ast::RangeExpr * node ) override final { 683 (void)node; 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; 684 918 return nullptr; 685 919 } 686 920 687 921 const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final { 688 (void)node; 922 auto expr = visitBaseExpr( node, 923 new UntypedTupleExpr( 924 get<Expression>().acceptL(node->exprs) 925 ) 926 ); 927 this->node = expr; 689 928 return nullptr; 690 929 } 691 930 692 931 const ast::Expr * visit( const ast::TupleExpr * node ) override final { 693 (void)node; 932 auto expr = visitBaseExpr( node, 933 new UntypedTupleExpr( 934 get<Expression>().acceptL(node->exprs) 935 ) 936 ); 937 this->node = expr; 694 938 return nullptr; 695 939 } 696 940 697 941 const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final { 698 (void)node; 942 auto expr = visitBaseExpr( node, 943 new TupleIndexExpr( 944 get<Expression>().accept1(node->tuple), 945 node->index 946 ) 947 ); 948 this->node = expr; 699 949 return nullptr; 700 950 } 701 951 702 952 const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final { 703 (void)node; 953 auto expr = visitBaseExpr( node, 954 new TupleAssignExpr( 955 get<StmtExpr>().accept1(node->stmtExpr) 956 ) 957 ); 958 this->node = expr; 704 959 return nullptr; 705 960 } 706 961 707 962 const ast::Expr * visit( const ast::StmtExpr * node ) override final { 708 (void)node; 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; 709 972 return nullptr; 710 973 } 711 974 712 975 const ast::Expr * visit( const ast::UniqueExpr * node ) override final { 713 (void)node; 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; 714 985 return nullptr; 715 986 } 716 987 717 988 const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final { 718 (void)node; 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; 719 1003 return nullptr; 720 1004 } 721 1005 722 1006 const ast::Expr * visit( const ast::InitExpr * node ) override final { 723 (void)node; 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; 724 1014 return nullptr; 725 1015 } 726 1016 727 1017 const ast::Expr * visit( const ast::DeletedExpr * node ) override final { 728 (void)node; 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; 729 1027 return nullptr; 730 1028 } 731 1029 732 1030 const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final { 733 (void)node; 1031 auto expr = visitBaseExpr( node, 1032 new DefaultArgExpr( 1033 get<Expression>().accept1(node->expr) 1034 ) 1035 ); 1036 this->node = expr; 734 1037 return nullptr; 735 1038 } 736 1039 737 1040 const ast::Expr * visit( const ast::GenericExpr * node ) override final { 738 (void)node; 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; 739 1055 return nullptr; 740 1056 } … … 1503 1819 } 1504 1820 1505 ast::Expr * visitBaseExpr(Expression * old, ast::Expr * nw) { 1506 1507 nw->result = GET_ACCEPT_1(result, Type); 1821 ast::Expr * visitBaseExpr_SkipResultType(Expression * old, ast::Expr * nw) { 1822 1508 1823 nw->env = convertTypeSubstitution(old->env); 1509 1824 … … 1514 1829 } 1515 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 } 1836 1516 1837 virtual void visit( ApplicationExpr * old ) override final { 1517 1838 this->node = visitBaseExpr( old, … … 1547 1868 new ast::CastExpr( 1548 1869 old->location, 1549 nullptr, // cast's "to" type is expr's result type; converted in visitBaseExpr1870 GET_ACCEPT_1(arg, Expr), 1550 1871 old->isGenerated ? ast::GeneratedCast : ast::ExplicitCast 1551 1872 ) … … 1553 1874 } 1554 1875 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 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 ); 1685 2316 } 1686 2317
Note: See TracChangeset
for help on using the changeset viewer.