Ignore:
Timestamp:
Mar 28, 2022, 10:41:45 AM (2 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
8e819a9
Parents:
f5bace8
Message:

Added StmtClause? and converted the existing nodes that should be clauses.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    rf5bace8 r400b8be  
    353353        }
    354354
     355        void clausePostamble( Statement * stmt, const ast::StmtClause * node ) {
     356                stmt->location = node->location;
     357                this->node = stmt;
     358        }
     359
    355360        const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final {
    356361                if ( inCache( node ) ) return nullptr;
     
    401406                auto stmt = new SwitchStmt(
    402407                        get<Expression>().accept1( node->cond ),
    403                         get<Statement>().acceptL( node->stmts )
     408                        get<Statement>().acceptL( node->cases )
    404409                );
    405410                return stmtPostamble( stmt, node );
    406411        }
    407412
    408         const ast::Stmt * visit( const ast::CaseStmt * node ) override final {
     413        const ast::CaseClause * visit( const ast::CaseClause * node ) override final {
    409414                if ( inCache( node ) ) return nullptr;
    410415                auto stmt = new CaseStmt(
     
    413418                        node->isDefault()
    414419                );
    415                 return stmtPostamble( stmt, node );
     420                clausePostamble( stmt, node );
     421                return nullptr;
    416422        }
    417423
     
    509515        }
    510516
    511         const ast::Stmt * visit( const ast::CatchStmt * node ) override final {
     517        const ast::CatchClause * visit( const ast::CatchClause * node ) override final {
    512518                if ( inCache( node ) ) return nullptr;
    513519                CatchStmt::Kind kind;
     
    520526                        break;
    521527                default:
    522                         assertf(false, "Invalid ast::CatchStmt::Kind: %d\n", node->kind);
     528                        assertf(false, "Invalid ast::ExceptionKind: %d\n", node->kind);
    523529                }
    524530                auto stmt = new CatchStmt(
     
    528534                        get<Statement>().accept1( node->body )
    529535                );
    530                 return stmtPostamble( stmt, node );
    531         }
    532 
    533         const ast::Stmt * visit( const ast::FinallyStmt * node ) override final {
     536                return clausePostamble( stmt, node ), nullptr;
     537        }
     538
     539        const ast::FinallyClause * visit( const ast::FinallyClause * node ) override final {
    534540                if ( inCache( node ) ) return nullptr;
    535541                auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) );
    536                 return stmtPostamble( stmt, node );
     542                return clausePostamble( stmt, node ), nullptr;
    537543        }
    538544
     
    18841890                        old->location,
    18851891                        GET_ACCEPT_1(condition, Expr),
    1886                         GET_ACCEPT_V(statements, Stmt),
     1892                        GET_ACCEPT_V(statements, CaseClause),
    18871893                        GET_LABELS_V(old->labels)
    18881894                );
     
    18921898        virtual void visit( const CaseStmt * old ) override final {
    18931899                if ( inCache( old ) ) return;
    1894                 this->node = new ast::CaseStmt(
     1900                this->node = new ast::CaseClause(
    18951901                        old->location,
    18961902                        GET_ACCEPT_1(condition, Expr),
    1897                         GET_ACCEPT_V(stmts, Stmt),
    1898                         GET_LABELS_V(old->labels)
    1899                 );
     1903                        GET_ACCEPT_V(stmts, Stmt)
     1904                );
     1905                auto labels = GET_LABELS_V(old->labels);
     1906                assertf(labels.empty(), "Labels found on CaseStmt.");
    19001907                cache.emplace( old, this->node );
    19011908        }
     
    20052012                        old->location,
    20062013                        GET_ACCEPT_1(block, CompoundStmt),
    2007                         GET_ACCEPT_V(handlers, CatchStmt),
    2008                         GET_ACCEPT_1(finallyBlock, FinallyStmt),
     2014                        GET_ACCEPT_V(handlers, CatchClause),
     2015                        GET_ACCEPT_1(finallyBlock, FinallyClause),
    20092016                        GET_LABELS_V(old->labels)
    20102017                );
     
    20262033                }
    20272034
    2028                 this->node = new ast::CatchStmt(
     2035                this->node = new ast::CatchClause(
    20292036                        old->location,
    20302037                        kind,
    20312038                        GET_ACCEPT_1(decl, Decl),
    20322039                        GET_ACCEPT_1(cond, Expr),
    2033                         GET_ACCEPT_1(body, Stmt),
    2034                         GET_LABELS_V(old->labels)
    2035                 );
     2040                        GET_ACCEPT_1(body, Stmt)
     2041                );
     2042                auto labels = GET_LABELS_V(old->labels);
     2043                assertf(labels.empty(), "Labels found on CatchStmt.");
    20362044                cache.emplace( old, this->node );
    20372045        }
     
    20392047        virtual void visit( const FinallyStmt * old ) override final {
    20402048                if ( inCache( old ) ) return;
    2041                 this->node = new ast::FinallyStmt(
    2042                         old->location,
    2043                         GET_ACCEPT_1(block, CompoundStmt),
    2044                         GET_LABELS_V(old->labels)
    2045                 );
     2049                this->node = new ast::FinallyClause(
     2050                        old->location,
     2051                        GET_ACCEPT_1(block, CompoundStmt)
     2052                );
     2053                auto labels = GET_LABELS_V(old->labels);
     2054                assertf(labels.empty(), "Labels found on FinallyStmt.");
    20462055                cache.emplace( old, this->node );
    20472056        }
Note: See TracChangeset for help on using the changeset viewer.