Changeset ed5e798


Ignore:
Timestamp:
May 22, 2019, 11:38:23 AM (5 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
20de6fb, 3f840e3, 9a0cd9c
Parents:
746ae82 (diff), 28c89f4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r746ae82 red5e798  
    571571
    572572        const ast::Expr * visit( const ast::AddressExpr * node ) override final {
    573                 (void)node;
     573                auto expr = visitBaseExpr( node,
     574                        new AddressExpr(
     575                                get<Expression>().accept1(node->arg)
     576                        )
     577                );
     578                this->node = expr;
    574579                return nullptr;
    575580        }
    576581
    577582        const ast::Expr * visit( const ast::LabelAddressExpr * node ) override final {
    578                 (void)node;
     583                auto expr = visitBaseExpr( node,
     584                        new LabelAddressExpr(
     585                                makeLabel(nullptr, node->arg)
     586                        )
     587                );
     588                this->node = expr;
    579589                return nullptr;
    580590        }
    581591
    582592        const ast::Expr * visit( const ast::CastExpr * node ) override final {
    583                 (void)node;
     593                auto expr = visitBaseExpr( node,
     594                        new CastExpr(
     595                                get<Expression>().accept1(node->arg),
     596                                (node->isGenerated == ast::GeneratedCast)
     597                        )
     598                );
     599                this->node = expr;
    584600                return nullptr;
    585601        }
    586602
    587603        const ast::Expr * visit( const ast::KeywordCastExpr * node ) override final {
    588                 (void)node;
     604                KeywordCastExpr::Target castTarget = KeywordCastExpr::NUMBER_OF_TARGETS;
     605                switch (node->target) {
     606                        case ast::KeywordCastExpr::Coroutine:
     607                                castTarget = KeywordCastExpr::Coroutine;
     608                                break;
     609                        case ast::KeywordCastExpr::Thread:
     610                                castTarget = KeywordCastExpr::Thread;
     611                                break;
     612                        case ast::KeywordCastExpr::Monitor:
     613                                castTarget = KeywordCastExpr::Monitor;
     614                                break;
     615                        default:
     616                                break;
     617                }
     618                assert ( castTarget < KeywordCastExpr::NUMBER_OF_TARGETS );
     619                auto expr = visitBaseExpr( node,
     620                        new KeywordCastExpr(
     621                                get<Expression>().accept1(node->arg),
     622                                castTarget
     623                        )
     624                );
     625                this->node = expr;
    589626                return nullptr;
    590627        }
    591628
    592629        const ast::Expr * visit( const ast::VirtualCastExpr * node ) override final {
    593                 (void)node;
     630                auto expr = visitBaseExpr( node,
     631                        new VirtualCastExpr(
     632                                get<Expression>().accept1(node->arg),
     633                                nullptr // cast's "to" type is expr's result type; converted in visitBaseExpr
     634                        )
     635                );
     636                this->node = expr;
    594637                return nullptr;
    595638        }
    596639
    597640        const ast::Expr * visit( const ast::UntypedMemberExpr * node ) override final {
    598                 (void)node;
     641                auto expr = visitBaseExpr( node,
     642                        new UntypedMemberExpr(
     643                                get<Expression>().accept1(node->member),
     644                                get<Expression>().accept1(node->aggregate)
     645                        )
     646                );
     647                this->node = expr;
    599648                return nullptr;
    600649        }
    601650
    602651        const ast::Expr * visit( const ast::MemberExpr * node ) override final {
    603                 (void)node;
     652                auto expr = visitBaseExpr( node,
     653                        new MemberExpr(
     654                                inCache(node->member) ?
     655                                        dynamic_cast<DeclarationWithType *>(this->node) :
     656                                        get<DeclarationWithType>().accept1(node->member),
     657                                get<Expression>().accept1(node->aggregate)
     658                        )
     659                );
     660                this->node = expr;
    604661                return nullptr;
    605662        }
    606663
    607664        const ast::Expr * visit( const ast::VariableExpr * node ) override final {
    608                 (void)node;
    609                 return nullptr;
     665                auto expr = visitBaseExpr( node,
     666                        new VariableExpr(
     667                                inCache(node->var) ?
     668                                        dynamic_cast<DeclarationWithType *>(this->node) :
     669                                        get<DeclarationWithType>().accept1(node->var)
     670                        )
     671                );
     672                this->node = expr;
     673                return nullptr;
     674        }
     675
     676        bool isIntlikeConstantType(const ast::Type *t) {
     677                if ( const ast::BasicType * basicType = dynamic_cast< const ast::BasicType * >( t ) ) {
     678                        if ( basicType->isInteger() ) {
     679                                return true;
     680                        }
     681                } else if ( dynamic_cast< const ast::OneType * >( t ) ) {
     682                        return true;
     683                } else if ( dynamic_cast< const ast::ZeroType * >( t ) ) {
     684                        return true;
     685                } else if ( dynamic_cast< const ast::PointerType * >( t ) ) {
     686                        // null pointer constants, with zero int-values
     687                        return true;
     688                }
     689                return false;
     690        }
     691
     692        bool isFloatlikeConstantType(const ast::Type *t) {
     693                if ( const ast::BasicType * bty = dynamic_cast< const ast::BasicType * >( t ) ) {
     694                        if ( ! bty->isInteger() ) {
     695                                return true;
     696                        }
     697                }
     698                return false;
     699        }
     700
     701        bool isStringlikeConstantType(const ast::Type *t) {
     702                if ( const ast::ArrayType * aty = dynamic_cast< const ast::ArrayType * >( t ) ) {
     703                        if ( const ast::BasicType * bty = aty->base.as<ast::BasicType>() ) {
     704                           if ( bty->kind == ast::BasicType::Kind::Char ) {
     705                                   return true;
     706                           }
     707                        }
     708                }
     709                return false;
    610710        }
    611711
    612712        const ast::Expr * visit( const ast::ConstantExpr * node ) override final {
    613                 (void)node;
     713                ConstantExpr *rslt = nullptr;
     714                if (isIntlikeConstantType(node->result)) {
     715                        rslt = new ConstantExpr(Constant(
     716                                get<Type>().accept1(node->result),
     717                                node->rep,
     718                                (unsigned long long) node->intValue()
     719                        ));
     720                } else if (isFloatlikeConstantType(node->result)) {
     721                        rslt = new ConstantExpr(Constant(
     722                                get<Type>().accept1(node->result),
     723                                node->rep,
     724                                (double) node->floatValue()
     725                        ));
     726                } else if (isStringlikeConstantType(node->result)) {
     727                        rslt = new ConstantExpr(Constant::from_string(
     728                                node->rep
     729                        ));
     730                }
     731                assert(rslt);
     732                auto expr = visitBaseExpr( node, rslt );
     733                this->node = expr;
    614734                return nullptr;
    615735        }
    616736
    617737        const ast::Expr * visit( const ast::SizeofExpr * node ) override final {
    618                 (void)node;
     738                assert (node->expr || node->type);
     739                assert (! (node->expr && node->type));
     740                SizeofExpr *rslt;
     741                if (node->expr) {
     742                        rslt = new SizeofExpr(
     743                                get<Expression>().accept1(node->expr)
     744                        );
     745                        assert (!rslt->isType);
     746                }
     747                if (node->type) {
     748                        rslt = new SizeofExpr(
     749                                get<Type>().accept1(node->type)
     750                        );
     751                        assert (rslt->isType);
     752                }
     753                auto expr = visitBaseExpr( node, rslt );
     754                this->node = expr;
    619755                return nullptr;
    620756        }
    621757
    622758        const ast::Expr * visit( const ast::AlignofExpr * node ) override final {
    623                 (void)node;
     759                assert (node->expr || node->type);
     760                assert (! (node->expr && node->type));
     761                AlignofExpr *rslt;
     762                if (node->expr) {
     763                        rslt = new AlignofExpr(
     764                                get<Expression>().accept1(node->expr)
     765                        );
     766                        assert (!rslt->isType);
     767                }
     768                if (node->type) {
     769                        rslt = new AlignofExpr(
     770                                get<Type>().accept1(node->type)
     771                        );
     772                        assert (rslt->isType);
     773                }
     774                auto expr = visitBaseExpr( node, rslt );
     775                this->node = expr;
    624776                return nullptr;
    625777        }
    626778
    627779        const ast::Expr * visit( const ast::UntypedOffsetofExpr * node ) override final {
    628                 (void)node;
     780                auto expr = visitBaseExpr( node,
     781                        new UntypedOffsetofExpr(
     782                                get<Type>().accept1(node->type),
     783                                node->member
     784                        )
     785                );
     786                this->node = expr;
    629787                return nullptr;
    630788        }
    631789
    632790        const ast::Expr * visit( const ast::OffsetofExpr * node ) override final {
    633                 (void)node;
     791                auto expr = visitBaseExpr( node,
     792                        new OffsetofExpr(
     793                                get<Type>().accept1(node->type),
     794                                inCache(node->member) ?
     795                                        dynamic_cast<DeclarationWithType *>(this->node) :
     796                                        get<DeclarationWithType>().accept1(node->member)
     797                        )
     798                );
     799                this->node = expr;
    634800                return nullptr;
    635801        }
    636802
    637803        const ast::Expr * visit( const ast::OffsetPackExpr * node ) override final {
    638                 (void)node;
     804                auto expr = visitBaseExpr( node,
     805                        new OffsetPackExpr(
     806                                get<StructInstType>().accept1(node->type)
     807                        )
     808                );
     809                this->node = expr;
    639810                return nullptr;
    640811        }
    641812
    642813        const ast::Expr * visit( const ast::LogicalExpr * node ) override final {
    643                 (void)node;
     814                assert (node->isAnd == ast::LogicalFlag::AndExpr ||
     815                                node->isAnd == ast::LogicalFlag::OrExpr );
     816                auto expr = visitBaseExpr( node,
     817                        new LogicalExpr(
     818                                get<Expression>().accept1(node->arg1),
     819                                get<Expression>().accept1(node->arg2),
     820                                (node->isAnd == ast::LogicalFlag::AndExpr)
     821                        )
     822                );
     823                this->node = expr;
    644824                return nullptr;
    645825        }
    646826
    647827        const ast::Expr * visit( const ast::ConditionalExpr * node ) override final {
    648                 (void)node;
     828                auto expr = visitBaseExpr( node,
     829                        new ConditionalExpr(
     830                                get<Expression>().accept1(node->arg1),
     831                                get<Expression>().accept1(node->arg2),
     832                                get<Expression>().accept1(node->arg3)
     833                        )
     834                );
     835                this->node = expr;
    649836                return nullptr;
    650837        }
    651838
    652839        const ast::Expr * visit( const ast::CommaExpr * node ) override final {
    653                 (void)node;
     840                auto expr = visitBaseExpr( node,
     841                        new CommaExpr(
     842                                get<Expression>().accept1(node->arg1),
     843                                get<Expression>().accept1(node->arg2)
     844                        )
     845                );
     846                this->node = expr;
    654847                return nullptr;
    655848        }
     
    15471740                        new ast::CastExpr(
    15481741                                old->location,
    1549                                 nullptr, // cast's "to" type is expr's result type; converted in visitBaseExpr
     1742                                GET_ACCEPT_1(arg, Expr),
    15501743                                old->isGenerated ? ast::GeneratedCast : ast::ExplicitCast
    15511744                        )
     
    15531746        }
    15541747
    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 
     1748        virtual void visit( KeywordCastExpr * old) override final {
     1749                ast::KeywordCastExpr::Target castTarget = ast::KeywordCastExpr::NUMBER_OF_TARGETS;
     1750                switch (old->target) {
     1751                        case KeywordCastExpr::Coroutine:
     1752                                castTarget = ast::KeywordCastExpr::Coroutine;
     1753                                break;
     1754                        case KeywordCastExpr::Thread:
     1755                                castTarget = ast::KeywordCastExpr::Thread;
     1756                                break;
     1757                        case KeywordCastExpr::Monitor:
     1758                                castTarget = ast::KeywordCastExpr::Monitor;
     1759                                break;
     1760                        default:
     1761                                break;
     1762                }
     1763                assert ( castTarget < ast::KeywordCastExpr::NUMBER_OF_TARGETS );
     1764                this->node = visitBaseExpr( old,
     1765                        new ast::KeywordCastExpr(
     1766                                old->location,
     1767                                GET_ACCEPT_1(arg, Expr),
     1768                                castTarget
     1769                        )
     1770                );
     1771        }
     1772
     1773        virtual void visit( VirtualCastExpr * old ) override final {
     1774                this->node = visitBaseExpr( old,
     1775                        new ast::VirtualCastExpr(
     1776                                old->location,
     1777                                GET_ACCEPT_1(arg, Expr),
     1778                                nullptr // cast's "to" type is expr's result type; converted in visitBaseExpr
     1779                        )
     1780                );
     1781        }
     1782
     1783        virtual void visit( AddressExpr * old ) override final {
     1784                this->node = visitBaseExpr( old,
     1785                        new ast::AddressExpr(
     1786                                old->location,
     1787                                GET_ACCEPT_1(arg, Expr)
     1788                        )
     1789                );
     1790        }
     1791
     1792        virtual void visit( LabelAddressExpr * old ) override final {
     1793                this->node = visitBaseExpr( old,
     1794                        new ast::LabelAddressExpr(
     1795                                old->location,
     1796                                make_label(&old->arg)
     1797                        )
     1798                );
     1799        }
     1800
     1801        virtual void visit( UntypedMemberExpr * old ) override final {
     1802                this->node = visitBaseExpr( old,
     1803                        new ast::UntypedMemberExpr(
     1804                                old->location,
     1805                                GET_ACCEPT_1(member, Expr),
     1806                                GET_ACCEPT_1(aggregate, Expr)
     1807                        )
     1808                );
     1809        }
     1810
     1811        virtual void visit( MemberExpr * old ) override final {
     1812                this->node = visitBaseExpr( old,
     1813                        new ast::MemberExpr(
     1814                                old->location,
     1815                                inCache(old->member) ?
     1816                                        dynamic_cast<ast::DeclWithType *>(this->node) :
     1817                                        GET_ACCEPT_1(member, DeclWithType),
     1818                                GET_ACCEPT_1(aggregate, Expr)
     1819                        )
     1820                );
     1821        }
     1822
     1823        virtual void visit( VariableExpr * old ) override final {
     1824                this->node = visitBaseExpr( old,
     1825                        new ast::VariableExpr(
     1826                                old->location,
     1827                                inCache(old->var) ?
     1828                                        dynamic_cast<ast::DeclWithType *>(this->node) :
     1829                                        GET_ACCEPT_1(var, DeclWithType)
     1830                        )
     1831                );
     1832        }
     1833
     1834        bool isIntlikeConstantType(const Type *t) {
     1835                if ( const BasicType * basicType = dynamic_cast< const BasicType * >( t ) ) {
     1836                        if ( basicType->isInteger() ) {
     1837                                return true;
     1838                        }
     1839                } else if ( dynamic_cast< const OneType * >( t ) ) {
     1840                        return true;
     1841                } else if ( dynamic_cast< const ZeroType * >( t ) ) {
     1842                        return true;
     1843                } else if ( dynamic_cast< const PointerType * >( t ) ) {
     1844                        // null pointer constants, with zero int-values
     1845                        return true;
     1846                }
     1847                return false;
     1848        }
     1849
     1850        int isFloatlikeConstantType(const Type *t) {
     1851                if ( const BasicType * bty = dynamic_cast< const BasicType * >( t ) ) {
     1852                        if ( ! bty->isInteger() ) {
     1853                                return true;
     1854                        }
     1855                }
     1856                return false;
     1857        }
     1858
     1859        int isStringlikeConstantType(const Type *t) {
     1860                if ( const ArrayType * aty = dynamic_cast< const ArrayType * >( t ) ) {
     1861                        if ( const BasicType * bty = dynamic_cast< const BasicType * >( aty->base ) ) {
     1862                           if ( bty->kind == BasicType::Kind::Char ) {
     1863                                   return true;
     1864                           }
     1865                        }
     1866                }
     1867                return false;
     1868        }
     1869
     1870        virtual void visit( ConstantExpr * old ) override final {
     1871                ast::ConstantExpr *rslt = nullptr;
     1872                if (isIntlikeConstantType(old->result)) {
     1873                        rslt = new ast::ConstantExpr(
     1874                                old->location,
     1875                                GET_ACCEPT_1(result, Type),
     1876                                old->constant.get_value(),
     1877                                (unsigned long long) old->intValue()
     1878                        );
     1879                } else if (isFloatlikeConstantType(old->result)) {
     1880                        rslt = new ast::ConstantExpr(
     1881                                old->location,
     1882                                GET_ACCEPT_1(result, Type),
     1883                                old->constant.get_value(),
     1884                                (double) old->constant.get_dval()
     1885                        );
     1886                } else if (isStringlikeConstantType(old->result)) {
     1887                        rslt = ast::ConstantExpr::from_string(
     1888                                old->location,
     1889                                old->constant.get_value()
     1890                        );
     1891                }
     1892                assert(rslt);
     1893                this->node = visitBaseExpr( old, rslt );
     1894        }
     1895
     1896        virtual void visit( SizeofExpr * old ) override final {
     1897                assert (old->expr || old->type);
     1898                assert (! (old->expr && old->type));
     1899                ast::SizeofExpr *rslt;
     1900                if (old->expr) {
     1901                        assert(!old->isType);
     1902                        rslt = new ast::SizeofExpr(
     1903                                old->location,
     1904                                GET_ACCEPT_1(expr, Expr)
     1905                        );
     1906                }
     1907                if (old->type) {
     1908                        assert(old->isType);
     1909                        rslt = new ast::SizeofExpr(
     1910                                old->location,
     1911                                GET_ACCEPT_1(type, Type)
     1912                        );
     1913                }
     1914                this->node = visitBaseExpr( old, rslt );
     1915        }
     1916
     1917        virtual void visit( AlignofExpr * old ) override final {
     1918                assert (old->expr || old->type);
     1919                assert (! (old->expr && old->type));
     1920                ast::AlignofExpr *rslt;
     1921                if (old->expr) {
     1922                        assert(!old->isType);
     1923                        rslt = new ast::AlignofExpr(
     1924                                old->location,
     1925                                GET_ACCEPT_1(expr, Expr)
     1926                        );
     1927                }
     1928                if (old->type) {
     1929                        assert(old->isType);
     1930                        rslt = new ast::AlignofExpr(
     1931                                old->location,
     1932                                GET_ACCEPT_1(type, Type)
     1933                        );
     1934                }
     1935                this->node = visitBaseExpr( old, rslt );
     1936        }
     1937
     1938        virtual void visit( UntypedOffsetofExpr * old ) override final {
     1939                this->node = visitBaseExpr( old,
     1940                        new ast::UntypedOffsetofExpr(
     1941                                old->location,
     1942                                GET_ACCEPT_1(type, Type),
     1943                                old->member
     1944                        )
     1945                );
     1946        }
     1947
     1948        virtual void visit( OffsetofExpr * old ) override final {
     1949                this->node = visitBaseExpr( old,
     1950                        new ast::OffsetofExpr(
     1951                                old->location,
     1952                                GET_ACCEPT_1(type, Type),
     1953                                inCache(old->member) ?
     1954                                        dynamic_cast<ast::DeclWithType *>(this->node) :
     1955                                        GET_ACCEPT_1(member, DeclWithType)
     1956                        )
     1957                );
     1958        }
     1959
     1960        virtual void visit( OffsetPackExpr * old ) override final {
     1961                this->node = visitBaseExpr( old,
     1962                        new ast::OffsetPackExpr(
     1963                                old->location,
     1964                                GET_ACCEPT_1(type, StructInstType)
     1965                        )
     1966                );
     1967        }
     1968
     1969        virtual void visit( LogicalExpr * old ) override final {
     1970                this->node = visitBaseExpr( old,
     1971                        new ast::LogicalExpr(
     1972                                old->location,
     1973                                GET_ACCEPT_1(arg1, Expr),
     1974                                GET_ACCEPT_1(arg2, Expr),
     1975                                old->get_isAnd() ?
     1976                                        ast::LogicalFlag::AndExpr :
     1977                                        ast::LogicalFlag::OrExpr
     1978                        )
     1979                );
     1980        }
     1981
     1982        virtual void visit( ConditionalExpr * old ) override final {
     1983                this->node = visitBaseExpr( old,
     1984                        new ast::ConditionalExpr(
     1985                                old->location,
     1986                                GET_ACCEPT_1(arg1, Expr),
     1987                                GET_ACCEPT_1(arg2, Expr),
     1988                                GET_ACCEPT_1(arg3, Expr)
     1989                        )
     1990                );
     1991        }
     1992
     1993        virtual void visit( CommaExpr * old ) override final {
     1994                this->node = visitBaseExpr( old,
     1995                        new ast::CommaExpr(
     1996                                old->location,
     1997                                GET_ACCEPT_1(arg1, Expr),
     1998                                GET_ACCEPT_1(arg2, Expr)
     1999                        )
     2000                );
    16172001        }
    16182002
Note: See TracChangeset for help on using the changeset viewer.