Changeset b9fa85b


Ignore:
Timestamp:
Sep 10, 2020, 10:33:51 AM (14 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast-unique-expr
Children:
98e8b3b
Parents:
1c01c58
Message:

Should fix both trac #173 by porting the catch scoping hack to the new ast and the incompatability with older compiler intoduce in the read addition.

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Pass.hpp

    r1c01c58 rb9fa85b  
    118118
    119119        // Versions of the above for older compilers.
     120        template< typename... Args >
    120121        static void run( std::list< ptr<Decl> > & decls ) {
    121122                Pass<core_t> visitor;
     
    123124        }
    124125
    125         static auto read( Node const * node ) {
     126        template< typename node_type, typename... Args >
     127        static auto read( node_type const * node ) {
    126128                Pass<core_t> visitor;
    127                 Node const * temp = node->accept( visitor );
     129                node_type const * temp = node->accept( visitor );
    128130                assert( temp == node );
    129131                return visitor.get_result();
  • src/ResolvExpr/Resolver.cc

    r1c01c58 rb9fa85b  
    12591259                const ast::ThrowStmt *       previsit( const ast::ThrowStmt * );
    12601260                const ast::CatchStmt *       previsit( const ast::CatchStmt * );
     1261                const ast::CatchStmt *       postvisit( const ast::CatchStmt * );
    12611262                const ast::WaitForStmt *     previsit( const ast::WaitForStmt * );
    12621263
     
    14911492
    14921493        const ast::CatchStmt * Resolver_new::previsit( const ast::CatchStmt * catchStmt ) {
    1493                 // TODO: This will need a fix for the decl/cond scoping problem.
     1494                // Until we are very sure this invarent (ifs that move between passes have thenPart)
     1495                // holds, check it. This allows a check for when to decode the mangling.
     1496                if ( auto ifStmt = catchStmt->body.as<ast::IfStmt>() ) {
     1497                        assert( ifStmt->thenPart );
     1498                }
     1499                // Encode the catchStmt so the condition can see the declaration.
    14941500                if ( catchStmt->cond ) {
    1495                         ast::ptr< ast::Type > boolType = new ast::BasicType{ ast::BasicType::Bool };
    1496                         catchStmt = ast::mutate_field(
    1497                                 catchStmt, &ast::CatchStmt::cond,
    1498                                 findSingleExpression( catchStmt->cond, boolType, symtab ) );
     1501                        ast::CatchStmt * stmt = mutate( catchStmt );
     1502                        stmt->body = new ast::IfStmt( stmt->location, stmt->cond, nullptr, stmt->body );
     1503                        stmt->cond = nullptr;
     1504                        return stmt;
     1505                }
     1506                return catchStmt;
     1507        }
     1508
     1509        const ast::CatchStmt * Resolver_new::postvisit( const ast::CatchStmt * catchStmt ) {
     1510                // Decode the catchStmt so everything is stored properly.
     1511                const ast::IfStmt * ifStmt = catchStmt->body.as<ast::IfStmt>();
     1512                if ( nullptr != ifStmt && nullptr == ifStmt->thenPart ) {
     1513                        assert( ifStmt->cond );
     1514                        assert( ifStmt->elsePart );
     1515                        ast::CatchStmt * stmt = ast::mutate( catchStmt );
     1516                        stmt->cond = ifStmt->cond;
     1517                        stmt->body = ifStmt->elsePart;
     1518                        // ifStmt should be implicately deleted here.
     1519                        return stmt;
    14991520                }
    15001521                return catchStmt;
Note: See TracChangeset for help on using the changeset viewer.