Changeset 37cdd97
- Timestamp:
- Feb 27, 2020, 5:24:09 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 427854b
- Parents:
- 5452673
- Location:
- src
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r5452673 r37cdd97 493 493 } 494 494 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 495 507 const ast::Stmt * visit( const ast::WaitForStmt * node ) override final { 496 508 if ( inCache( node ) ) return nullptr; … … 1859 1871 } 1860 1872 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 1861 1891 virtual void visit( const WaitForStmt * old ) override final { 1862 1892 if ( inCache( old ) ) return; -
src/AST/Fwd.hpp
r5452673 r37cdd97 53 53 class CatchStmt; 54 54 class FinallyStmt; 55 class SuspendStmt; 55 56 class WaitForStmt; 56 57 class WithStmt; -
src/AST/Pass.hpp
r5452673 r37cdd97 111 111 const ast::Stmt * visit( const ast::CatchStmt * ) override final; 112 112 const ast::Stmt * visit( const ast::FinallyStmt * ) override final; 113 const ast::Stmt * visit( const ast::SuspendStmt * ) override final; 113 114 const ast::Stmt * visit( const ast::WaitForStmt * ) override final; 114 115 const ast::Decl * visit( const ast::WithStmt * ) override final; -
src/AST/Pass.impl.hpp
r5452673 r37cdd97 823 823 824 824 //-------------------------------------------------------------------------- 825 // FinallyStmt 826 template< typename pass_t > 827 const 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 //-------------------------------------------------------------------------- 825 838 // WaitForStmt 826 839 template< typename pass_t > -
src/AST/Print.cpp
r5452673 r37cdd97 674 674 safe_print( node->body ); 675 675 --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; 676 695 677 696 return node; -
src/AST/Stmt.hpp
r5452673 r37cdd97 342 342 }; 343 343 344 /// Suspend statement 345 class SuspendStmt final : public Stmt { 346 public: 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 ); } 354 private: 355 SuspendStmt * clone() const override { return new SuspendStmt{ *this }; } 356 MUTATE_FRIEND 357 }; 358 344 359 /// Wait for concurrency statement `when (...) waitfor (... , ...) ... timeout(...) ... else ...` 345 360 class WaitForStmt final : public Stmt { -
src/AST/Visitor.hpp
r5452673 r37cdd97 47 47 virtual const ast::Stmt * visit( const ast::CatchStmt * ) = 0; 48 48 virtual const ast::Stmt * visit( const ast::FinallyStmt * ) = 0; 49 virtual const ast::Stmt * visit( const ast::SuspendStmt * ) = 0; 49 50 virtual const ast::Stmt * visit( const ast::WaitForStmt * ) = 0; 50 51 virtual const ast::Decl * visit( const ast::WithStmt * ) = 0; -
src/Common/PassVisitor.h
r5452673 r37cdd97 110 110 virtual void visit( FinallyStmt * finallyStmt ) override final; 111 111 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; 112 114 virtual void visit( WaitForStmt * waitforStmt ) override final; 113 115 virtual void visit( const WaitForStmt * waitforStmt ) override final; … … 276 278 virtual Statement * mutate( CatchStmt * catchStmt ) override final; 277 279 virtual Statement * mutate( FinallyStmt * finallyStmt ) override final; 280 virtual Statement * mutate( SuspendStmt * suspendStmt ) override final; 278 281 virtual Statement * mutate( WaitForStmt * waitforStmt ) override final; 279 282 virtual Declaration * mutate( WithStmt * withStmt ) override final; -
src/Common/PassVisitor.impl.h
r5452673 r37cdd97 1522 1522 1523 1523 //-------------------------------------------------------------------------- 1524 // SuspendStmt 1525 template< typename pass_type > 1526 void PassVisitor< pass_type >::visit( SuspendStmt * node ) { 1527 VISIT_START( node ); 1528 1529 maybeAccept_impl( node->then , *this ); 1530 1531 VISIT_END( node ); 1532 } 1533 1534 template< typename pass_type > 1535 void 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 1543 template< typename pass_type > 1544 Statement * 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 //-------------------------------------------------------------------------- 1524 1553 // WaitForStmt 1525 1554 template< typename pass_type > -
src/Parser/lex.ll
r5452673 r37cdd97 65 65 #define FLOATXX(v) KEYWORD_RETURN(v); 66 66 #else 67 #define FLOATXX(v) IDENTIFIER_RETURN(); 67 #define FLOATXX(v) IDENTIFIER_RETURN(); 68 68 #endif // HAVE_KEYWORDS_FLOATXX 69 69 … … 301 301 _Static_assert { KEYWORD_RETURN(STATICASSERT); } // C11 302 302 struct { KEYWORD_RETURN(STRUCT); } 303 /* suspend { KEYWORD_RETURN(SUSPEND); } // CFA */ 303 suspend { KEYWORD_RETURN(SUSPEND); } // CFA 304 304 switch { KEYWORD_RETURN(SWITCH); } 305 305 thread { KEYWORD_RETURN(THREAD); } // C11 -
src/Parser/parser.yy
r5452673 r37cdd97 278 278 %token OTYPE FTYPE DTYPE TTYPE TRAIT // CFA 279 279 %token SIZEOF OFFSETOF 280 // %token SUSPEND RESUME // CFA 280 // %token RESUME // CFA 281 %token SUSPEND // CFA 281 282 %token ATTRIBUTE EXTENSION // GCC 282 283 %token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN … … 1259 1260 | RETURN '{' initializer_list_opt comma_opt '}' ';' 1260 1261 { 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; } 1265 1274 | THROW assignment_expression_opt ';' // handles rethrow 1266 1275 { $$ = new StatementNode( build_throw( $2 ) ); } -
src/SynTree/Mutator.h
r5452673 r37cdd97 51 51 virtual Statement * mutate( CatchStmt * catchStmt ) = 0; 52 52 virtual Statement * mutate( FinallyStmt * catchStmt ) = 0; 53 virtual Statement * mutate( SuspendStmt * suspendStmt ) = 0; 53 54 virtual Statement * mutate( WaitForStmt * waitforStmt ) = 0; 54 55 virtual Declaration * mutate( WithStmt * withStmt ) = 0; -
src/SynTree/Statement.cc
r5452673 r37cdd97 420 420 } 421 421 422 SuspendStmt::SuspendStmt( const SuspendStmt & other ) 423 : Statement( other ) 424 , then( maybeClone(other.then) ) 425 {} 426 427 SuspendStmt::~SuspendStmt() { 428 delete then; 429 } 430 431 void 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 422 447 WaitForStmt::WaitForStmt() : Statement() { 423 448 timeout.time = nullptr; -
src/SynTree/Statement.h
r5452673 r37cdd97 422 422 }; 423 423 424 class 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 424 440 class WaitForStmt : public Statement { 425 441 public: -
src/SynTree/SynTree.h
r5452673 r37cdd97 54 54 class CatchStmt; 55 55 class FinallyStmt; 56 class SuspendStmt; 56 57 class WaitForStmt; 57 58 class WithStmt; -
src/SynTree/Visitor.h
r5452673 r37cdd97 78 78 virtual void visit( FinallyStmt * node ) { visit( const_cast<const FinallyStmt *>(node) ); } 79 79 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; 80 82 virtual void visit( WaitForStmt * node ) { visit( const_cast<const WaitForStmt *>(node) ); } 81 83 virtual void visit( const WaitForStmt * waitforStmt ) = 0;
Note: See TracChangeset
for help on using the changeset viewer.