Changeset 37cdd97


Ignore:
Timestamp:
Feb 27, 2020, 5:24:09 PM (20 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
arm-eh, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr
Children:
427854b
Parents:
5452673
Message:

Added a ast node for suspend statements

Location:
src
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r5452673 r37cdd97  
    493493        }
    494494
     495        const ast::Stmt * visit(const ast::SuspendStmt * node ) override final {
     496                if ( inCache( node ) ) return nullptr;
     497                auto stmt = new SuspendStmt();
     498                stmt->then   = get<CompoundStmt>().accept1( node->then   );
     499                switch(node->type) {
     500                        case ast::SuspendStmt::None     : stmt->type = SuspendStmt::None     ; break;
     501                        case ast::SuspendStmt::Coroutine: stmt->type = SuspendStmt::Coroutine; break;
     502                        case ast::SuspendStmt::Generator: stmt->type = SuspendStmt::Generator; break;
     503                }
     504                return stmtPostamble( stmt, node );
     505        }
     506
    495507        const ast::Stmt * visit( const ast::WaitForStmt * node ) override final {
    496508                if ( inCache( node ) ) return nullptr;
     
    18591871        }
    18601872
     1873        virtual void visit( const SuspendStmt * old ) override final {
     1874                if ( inCache( old ) ) return;
     1875                ast::SuspendStmt::Type type;
     1876                switch (old->type) {
     1877                        case SuspendStmt::Coroutine: type = ast::SuspendStmt::Coroutine; break;
     1878                        case SuspendStmt::Generator: type = ast::SuspendStmt::Generator; break;
     1879                        case SuspendStmt::None     : type = ast::SuspendStmt::None     ; break;
     1880                        default: abort();
     1881                }
     1882                this->node = new ast::SuspendStmt(
     1883                        old->location,
     1884                        GET_ACCEPT_1(then  , CompoundStmt),
     1885                        type,
     1886                        GET_LABELS_V(old->labels)
     1887                );
     1888                cache.emplace( old, this->node );
     1889        }
     1890
    18611891        virtual void visit( const WaitForStmt * old ) override final {
    18621892                if ( inCache( old ) ) return;
  • src/AST/Fwd.hpp

    r5452673 r37cdd97  
    5353class CatchStmt;
    5454class FinallyStmt;
     55class SuspendStmt;
    5556class WaitForStmt;
    5657class WithStmt;
  • src/AST/Pass.hpp

    r5452673 r37cdd97  
    111111        const ast::Stmt *             visit( const ast::CatchStmt            * ) override final;
    112112        const ast::Stmt *             visit( const ast::FinallyStmt          * ) override final;
     113        const ast::Stmt *             visit( const ast::SuspendStmt          * ) override final;
    113114        const ast::Stmt *             visit( const ast::WaitForStmt          * ) override final;
    114115        const ast::Decl *             visit( const ast::WithStmt             * ) override final;
  • src/AST/Pass.impl.hpp

    r5452673 r37cdd97  
    823823
    824824//--------------------------------------------------------------------------
     825// FinallyStmt
     826template< typename pass_t >
     827const ast::Stmt * ast::Pass< pass_t >::visit( const ast::SuspendStmt * node ) {
     828        VISIT_START( node );
     829
     830        VISIT(
     831                maybe_accept( node, &SuspendStmt::then   );
     832        )
     833
     834        VISIT_END( Stmt, node );
     835}
     836
     837//--------------------------------------------------------------------------
    825838// WaitForStmt
    826839template< typename pass_t >
  • src/AST/Print.cpp

    r5452673 r37cdd97  
    674674                safe_print( node->body );
    675675                --indent;
     676
     677                return node;
     678        }
     679
     680        virtual const ast::Stmt * visit( const ast::SuspendStmt * node ) override final {
     681                os << "Suspend Statement";
     682                switch (node->type) {
     683                        case ast::SuspendStmt::None     : os << " with implicit target"; break;
     684                        case ast::SuspendStmt::Generator: os << " for generator"; break;
     685                        case ast::SuspendStmt::Coroutine: os << " for coroutine"; break;
     686                }
     687                os << endl;
     688
     689                ++indent;
     690                if(node->then) {
     691                        os << indent << " with post statement :" << endl;
     692                        safe_print( node->then );
     693                }
     694                ++indent;
    676695
    677696                return node;
  • src/AST/Stmt.hpp

    r5452673 r37cdd97  
    342342};
    343343
     344/// Suspend statement
     345class SuspendStmt final : public Stmt {
     346public:
     347        ptr<CompoundStmt> then;
     348        enum Type { None, Coroutine, Generator } type = None;
     349
     350        SuspendStmt( const CodeLocation & loc, const CompoundStmt * then, Type type, std::vector<Label> && labels = {} )
     351        : Stmt(loc, std::move(labels)), then(then), type(type) {}
     352
     353        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     354private:
     355        SuspendStmt * clone() const override { return new SuspendStmt{ *this }; }
     356        MUTATE_FRIEND
     357};
     358
    344359/// Wait for concurrency statement `when (...) waitfor (... , ...) ... timeout(...) ... else ...`
    345360class WaitForStmt final : public Stmt {
  • src/AST/Visitor.hpp

    r5452673 r37cdd97  
    4747    virtual const ast::Stmt *             visit( const ast::CatchStmt            * ) = 0;
    4848    virtual const ast::Stmt *             visit( const ast::FinallyStmt          * ) = 0;
     49    virtual const ast::Stmt *             visit( const ast::SuspendStmt          * ) = 0;
    4950    virtual const ast::Stmt *             visit( const ast::WaitForStmt          * ) = 0;
    5051    virtual const ast::Decl *             visit( const ast::WithStmt             * ) = 0;
  • src/Common/PassVisitor.h

    r5452673 r37cdd97  
    110110        virtual void visit( FinallyStmt * finallyStmt ) override final;
    111111        virtual void visit( const FinallyStmt * finallyStmt ) override final;
     112        virtual void visit( SuspendStmt * suspendStmt ) override final;
     113        virtual void visit( const SuspendStmt * suspendStmt ) override final;
    112114        virtual void visit( WaitForStmt * waitforStmt ) override final;
    113115        virtual void visit( const WaitForStmt * waitforStmt ) override final;
     
    276278        virtual Statement * mutate( CatchStmt * catchStmt ) override final;
    277279        virtual Statement * mutate( FinallyStmt * finallyStmt ) override final;
     280        virtual Statement * mutate( SuspendStmt * suspendStmt ) override final;
    278281        virtual Statement * mutate( WaitForStmt * waitforStmt ) override final;
    279282        virtual Declaration * mutate( WithStmt * withStmt ) override final;
  • src/Common/PassVisitor.impl.h

    r5452673 r37cdd97  
    15221522
    15231523//--------------------------------------------------------------------------
     1524// SuspendStmt
     1525template< typename pass_type >
     1526void PassVisitor< pass_type >::visit( SuspendStmt * node ) {
     1527        VISIT_START( node );
     1528
     1529        maybeAccept_impl( node->then  , *this );
     1530
     1531        VISIT_END( node );
     1532}
     1533
     1534template< typename pass_type >
     1535void PassVisitor< pass_type >::visit( const SuspendStmt * node ) {
     1536        VISIT_START( node );
     1537
     1538        maybeAccept_impl( node->then  , *this );
     1539
     1540        VISIT_END( node );
     1541}
     1542
     1543template< typename pass_type >
     1544Statement * PassVisitor< pass_type >::mutate( SuspendStmt * node ) {
     1545        MUTATE_START( node );
     1546
     1547        maybeMutate_impl( node->then  , *this );
     1548
     1549        MUTATE_END( Statement, node );
     1550}
     1551
     1552//--------------------------------------------------------------------------
    15241553// WaitForStmt
    15251554template< typename pass_type >
  • src/Parser/lex.ll

    r5452673 r37cdd97  
    6565#define FLOATXX(v) KEYWORD_RETURN(v);
    6666#else
    67 #define FLOATXX(v) IDENTIFIER_RETURN(); 
     67#define FLOATXX(v) IDENTIFIER_RETURN();
    6868#endif // HAVE_KEYWORDS_FLOATXX
    6969
     
    301301_Static_assert  { KEYWORD_RETURN(STATICASSERT); }               // C11
    302302struct                  { KEYWORD_RETURN(STRUCT); }
    303         /* suspend                      { KEYWORD_RETURN(SUSPEND); }                    // CFA */
     303suspend                 { KEYWORD_RETURN(SUSPEND); }                    // CFA
    304304switch                  { KEYWORD_RETURN(SWITCH); }
    305305thread                  { KEYWORD_RETURN(THREAD); }                             // C11
  • src/Parser/parser.yy

    r5452673 r37cdd97  
    278278%token OTYPE FTYPE DTYPE TTYPE TRAIT                                    // CFA
    279279%token SIZEOF OFFSETOF
    280 // %token SUSPEND RESUME                                                                        // CFA
     280// %token RESUME                                                                        // CFA
     281%token SUSPEND                                                                  // CFA
    281282%token ATTRIBUTE EXTENSION                                                              // GCC
    282283%token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN
     
    12591260        | RETURN '{' initializer_list_opt comma_opt '}' ';'
    12601261                { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; }
    1261         // | SUSPEND ';'
    1262         //      { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; }
    1263         // | SUSPEND compound_statement ';'
    1264         //      { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; }
     1262        | SUSPEND ';'
     1263                { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; }
     1264        | SUSPEND compound_statement ';'
     1265                { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; }
     1266        | SUSPEND COROUTINE ';'
     1267                { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; }
     1268        | SUSPEND COROUTINE compound_statement
     1269                { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; }
     1270        | SUSPEND GENERATOR ';'
     1271                { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; }
     1272        | SUSPEND GENERATOR compound_statement
     1273                { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; }
    12651274        | THROW assignment_expression_opt ';'                           // handles rethrow
    12661275                { $$ = new StatementNode( build_throw( $2 ) ); }
  • src/SynTree/Mutator.h

    r5452673 r37cdd97  
    5151        virtual Statement * mutate( CatchStmt * catchStmt ) = 0;
    5252        virtual Statement * mutate( FinallyStmt * catchStmt ) = 0;
     53        virtual Statement * mutate( SuspendStmt * suspendStmt ) = 0;
    5354        virtual Statement * mutate( WaitForStmt * waitforStmt ) = 0;
    5455        virtual Declaration * mutate( WithStmt * withStmt ) = 0;
  • src/SynTree/Statement.cc

    r5452673 r37cdd97  
    420420}
    421421
     422SuspendStmt::SuspendStmt( const SuspendStmt & other )
     423        : Statement( other )
     424        , then( maybeClone(other.then) )
     425{}
     426
     427SuspendStmt::~SuspendStmt() {
     428        delete then;
     429}
     430
     431void SuspendStmt::print( std::ostream & os, Indenter indent ) const {
     432        os << "Suspend Statement";
     433        switch (type) {
     434                case None     : os << " with implicit target"; break;
     435                case Generator: os << " for generator"       ; break;
     436                case Coroutine: os << " for coroutine"       ; break;
     437        }
     438        os << endl;
     439        indent += 1;
     440
     441        if(then) {
     442                os << indent << " with post statement :" << endl;
     443                then->print( os, indent + 1);
     444        }
     445}
     446
    422447WaitForStmt::WaitForStmt() : Statement() {
    423448        timeout.time      = nullptr;
  • src/SynTree/Statement.h

    r5452673 r37cdd97  
    422422};
    423423
     424class SuspendStmt : public Statement {
     425  public:
     426        CompoundStmt * then = nullptr;
     427        enum { None, Coroutine, Generator } type = None;
     428
     429        SuspendStmt() = default;
     430        SuspendStmt( const SuspendStmt & );
     431        virtual ~SuspendStmt();
     432
     433        virtual SuspendStmt * clone() const override { return new SuspendStmt( *this ); }
     434        virtual void accept( Visitor & v ) override { v.visit( this ); }
     435        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     436        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     437        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     438};
     439
    424440class WaitForStmt : public Statement {
    425441  public:
  • src/SynTree/SynTree.h

    r5452673 r37cdd97  
    5454class CatchStmt;
    5555class FinallyStmt;
     56class SuspendStmt;
    5657class WaitForStmt;
    5758class WithStmt;
  • src/SynTree/Visitor.h

    r5452673 r37cdd97  
    7878        virtual void visit( FinallyStmt * node ) { visit( const_cast<const FinallyStmt *>(node) ); }
    7979        virtual void visit( const FinallyStmt * finallyStmt ) = 0;
     80        virtual void visit( SuspendStmt * node ) { visit( const_cast<const SuspendStmt *>(node) ); }
     81        virtual void visit( const SuspendStmt * suspendStmt ) = 0;
    8082        virtual void visit( WaitForStmt * node ) { visit( const_cast<const WaitForStmt *>(node) ); }
    8183        virtual void visit( const WaitForStmt * waitforStmt ) = 0;
Note: See TracChangeset for help on using the changeset viewer.