- Timestamp:
- May 29, 2023, 11:44:29 AM (2 years ago)
- Branches:
- ADT
- Children:
- fa2c005
- Parents:
- 3a513d89 (diff), 2b78949 (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. - Location:
- src/AST
- Files:
-
- 9 edited
-
Convert.cpp (modified) (4 diffs)
-
Fwd.hpp (modified) (1 diff)
-
Node.cpp (modified) (1 diff)
-
Pass.hpp (modified) (1 diff)
-
Pass.impl.hpp (modified) (7 diffs)
-
Pass.proto.hpp (modified) (6 diffs)
-
Print.cpp (modified) (4 diffs)
-
Stmt.hpp (modified) (3 diffs)
-
Visitor.hpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r3a513d89 r044ae62 585 585 } 586 586 587 const ast::WhenClause * visit( const ast::WhenClause * node ) override final { 588 // There is no old-AST WhenClause, so this should never be called. 589 assert( !node ); 590 return nullptr; 591 } 592 587 593 const ast::Stmt * visit( const ast::WaitForStmt * node ) override final { 588 594 if ( inCache( node ) ) return nullptr; … … 591 597 for ( auto clause : node->clauses ) { 592 598 stmt->clauses.push_back({{ 593 get<Expression>().accept1( clause->target _func),599 get<Expression>().accept1( clause->target ), 594 600 get<Expression>().acceptL( clause->target_args ), 595 601 }, 596 602 get<Statement>().accept1( clause->stmt ), 597 get<Expression>().accept1( clause-> cond ),603 get<Expression>().accept1( clause->when_cond ), 598 604 }); 599 605 } … … 612 618 const ast::WaitForClause * visit( const ast::WaitForClause * node ) override final { 613 619 // There is no old-AST WaitForClause, so this should never be called. 620 assert( !node ); 621 return nullptr; 622 } 623 624 const ast::Stmt * visit( const ast::WaitUntilStmt * node ) override final { 625 // There is no old-AST WaitUntilStmt, so this should never be called. 614 626 assert( !node ); 615 627 return nullptr; … … 2199 2211 auto clause = new ast::WaitForClause( old->location ); 2200 2212 2201 clause->target _func= GET_ACCEPT_1(clauses[i].target.function, Expr);2213 clause->target = GET_ACCEPT_1(clauses[i].target.function, Expr); 2202 2214 clause->target_args = GET_ACCEPT_V(clauses[i].target.arguments, Expr); 2203 2215 clause->stmt = GET_ACCEPT_1(clauses[i].statement, Stmt); 2204 clause-> cond = GET_ACCEPT_1(clauses[i].condition, Expr);2216 clause->when_cond = GET_ACCEPT_1(clauses[i].condition, Expr); 2205 2217 2206 2218 stmt->clauses.push_back( clause ); -
src/AST/Fwd.hpp
r3a513d89 r044ae62 59 59 class FinallyClause; 60 60 class SuspendStmt; 61 class WhenClause; 61 62 class WaitForStmt; 62 63 class WaitForClause; 64 class WaitUntilStmt; 63 65 class WithStmt; 64 66 class DeclStmt; -
src/AST/Node.cpp
r3a513d89 r044ae62 176 176 template class ast::ptr_base< ast::FinallyClause, ast::Node::ref_type::weak >; 177 177 template class ast::ptr_base< ast::FinallyClause, ast::Node::ref_type::strong >; 178 template class ast::ptr_base< ast::WhenClause, ast::Node::ref_type::weak >; 179 template class ast::ptr_base< ast::WhenClause, ast::Node::ref_type::strong >; 178 180 template class ast::ptr_base< ast::WaitForStmt, ast::Node::ref_type::weak >; 179 181 template class ast::ptr_base< ast::WaitForStmt, ast::Node::ref_type::strong >; 180 182 template class ast::ptr_base< ast::WaitForClause, ast::Node::ref_type::weak >; 181 183 template class ast::ptr_base< ast::WaitForClause, ast::Node::ref_type::strong >; 184 template class ast::ptr_base< ast::WaitUntilStmt, ast::Node::ref_type::weak >; 185 template class ast::ptr_base< ast::WaitUntilStmt, ast::Node::ref_type::strong >; 182 186 template class ast::ptr_base< ast::WithStmt, ast::Node::ref_type::weak >; 183 187 template class ast::ptr_base< ast::WithStmt, ast::Node::ref_type::strong >; -
src/AST/Pass.hpp
r3a513d89 r044ae62 163 163 const ast::FinallyClause * visit( const ast::FinallyClause * ) override final; 164 164 const ast::Stmt * visit( const ast::SuspendStmt * ) override final; 165 const ast::WhenClause * visit( const ast::WhenClause * ) override final; 165 166 const ast::Stmt * visit( const ast::WaitForStmt * ) override final; 166 167 const ast::WaitForClause * visit( const ast::WaitForClause * ) override final; 168 const ast::Stmt * visit( const ast::WaitUntilStmt * ) override final; 167 169 const ast::Decl * visit( const ast::WithStmt * ) override final; 168 170 const ast::NullStmt * visit( const ast::NullStmt * ) override final; -
src/AST/Pass.impl.hpp
r3a513d89 r044ae62 22 22 #include "AST/TranslationUnit.hpp" 23 23 #include "AST/TypeSubstitution.hpp" 24 #include "Common/Iterate.hpp"25 24 26 25 #define VISIT_START( node ) \ … … 127 126 } 128 127 129 template< typename node_t >130 template< typename object_t, typename super_t, typename field_t >131 void __pass::result1< node_t >::apply( object_t * object, field_t super_t::* field ) {132 object->*field = value;133 }134 135 128 template< typename core_t > 136 129 template< typename node_t > … … 234 227 235 228 return {true, compound}; 236 }237 238 template< template <class...> class container_t >239 template< typename object_t, typename super_t, typename field_t >240 void __pass::resultNstmt<container_t>::apply(object_t * object, field_t super_t::* field) {241 auto & container = object->*field;242 __pedantic_pass_assert( container.size() <= values.size() );243 244 auto cit = enumerate(container).begin();245 246 container_t<ptr<Stmt>> nvals;247 for (delta & d : values) {248 if ( d.is_old ) {249 __pedantic_pass_assert( cit.idx <= d.old_idx );250 std::advance( cit, d.old_idx - cit.idx );251 nvals.push_back( std::move( (*cit).val) );252 } else {253 nvals.push_back( std::move(d.new_val) );254 }255 }256 257 container = std::move(nvals);258 }259 260 template< template <class...> class container_t >261 template< template <class...> class incontainer_t >262 void __pass::resultNstmt< container_t >::take_all( incontainer_t<ptr<Stmt>> * stmts ) {263 if (!stmts || stmts->empty()) return;264 265 std::transform(stmts->begin(), stmts->end(), std::back_inserter( values ),266 [](ast::ptr<ast::Stmt>& stmt) -> delta {267 return delta( stmt.release(), -1, false );268 });269 stmts->clear();270 differs = true;271 }272 273 template< template<class...> class container_t >274 template< template<class...> class incontainer_t >275 void __pass::resultNstmt< container_t >::take_all( incontainer_t<ptr<Decl>> * decls ) {276 if (!decls || decls->empty()) return;277 278 std::transform(decls->begin(), decls->end(), std::back_inserter( values ),279 [](ast::ptr<ast::Decl>& decl) -> delta {280 auto loc = decl->location;281 auto stmt = new DeclStmt( loc, decl.release() );282 return delta( stmt, -1, false );283 });284 decls->clear();285 differs = true;286 229 } 287 230 … … 353 296 354 297 return new_kids; 355 }356 357 template< template <class...> class container_t, typename node_t >358 template< typename object_t, typename super_t, typename field_t >359 void __pass::resultN<container_t, node_t>::apply(object_t * object, field_t super_t::* field) {360 auto & container = object->*field;361 __pedantic_pass_assert( container.size() == values.size() );362 363 for(size_t i = 0; i < container.size(); i++) {364 // Take all the elements that are different in 'values'365 // and swap them into 'container'366 if( values[i] != nullptr ) swap(container[i], values[i]);367 }368 369 // Now the original containers should still have the unchanged values370 // but also contain the new values371 298 } 372 299 … … 1097 1024 1098 1025 //-------------------------------------------------------------------------- 1026 // WhenClause 1027 template< typename core_t > 1028 const ast::WhenClause * ast::Pass< core_t >::visit( const ast::WhenClause * node ) { 1029 VISIT_START( node ); 1030 1031 if ( __visit_children() ) { 1032 maybe_accept( node, &WhenClause::target ); 1033 maybe_accept( node, &WhenClause::stmt ); 1034 maybe_accept( node, &WhenClause::when_cond ); 1035 } 1036 1037 VISIT_END( WhenClause, node ); 1038 } 1039 1040 //-------------------------------------------------------------------------- 1099 1041 // WaitForStmt 1100 1042 template< typename core_t > … … 1121 1063 1122 1064 if ( __visit_children() ) { 1123 maybe_accept( node, &WaitForClause::target _func);1065 maybe_accept( node, &WaitForClause::target ); 1124 1066 maybe_accept( node, &WaitForClause::target_args ); 1125 1067 maybe_accept( node, &WaitForClause::stmt ); 1126 maybe_accept( node, &WaitForClause:: cond );1068 maybe_accept( node, &WaitForClause::when_cond ); 1127 1069 } 1128 1070 1129 1071 VISIT_END( WaitForClause, node ); 1072 } 1073 1074 //-------------------------------------------------------------------------- 1075 // WaitUntilStmt 1076 template< typename core_t > 1077 const ast::Stmt * ast::Pass< core_t >::visit( const ast::WaitUntilStmt * node ) { 1078 VISIT_START( node ); 1079 1080 if ( __visit_children() ) { 1081 maybe_accept( node, &WaitUntilStmt::clauses ); 1082 maybe_accept( node, &WaitUntilStmt::timeout_time ); 1083 maybe_accept( node, &WaitUntilStmt::timeout_stmt ); 1084 maybe_accept( node, &WaitUntilStmt::timeout_cond ); 1085 maybe_accept( node, &WaitUntilStmt::else_stmt ); 1086 maybe_accept( node, &WaitUntilStmt::else_cond ); 1087 } 1088 1089 VISIT_END( Stmt, node ); 1130 1090 } 1131 1091 … … 2234 2194 } 2235 2195 2196 #undef __pedantic_pass_assertf 2197 #undef __pedantic_pass_assert 2236 2198 #undef VISIT_START 2237 2199 #undef VISIT_END -
src/AST/Pass.proto.hpp
r3a513d89 r044ae62 17 17 // IWYU pragma: private, include "Pass.hpp" 18 18 19 #include "Common/Iterate.hpp" 19 20 #include "Common/Stats/Heap.h" 20 21 namespace ast { … … 24 25 template<typename node_t> node_t * deepCopy( const node_t * ); 25 26 } 27 28 #ifdef PEDANTIC_PASS_ASSERT 29 #define __pedantic_pass_assert(...) assert (__VA_ARGS__) 30 #define __pedantic_pass_assertf(...) assertf(__VA_ARGS__) 31 #else 32 #define __pedantic_pass_assert(...) 33 #define __pedantic_pass_assertf(...) 34 #endif 26 35 27 36 namespace ast::__pass { … … 130 139 131 140 template< typename object_t, typename super_t, typename field_t > 132 void apply( object_t *, field_t super_t::* field ); 141 void apply( object_t * object, field_t super_t::* field ) { 142 object->*field = value; 143 } 133 144 }; 134 145 … … 150 161 151 162 template< typename object_t, typename super_t, typename field_t > 152 void apply( object_t *, field_t super_t::* field ); 163 void apply( object_t * object, field_t super_t::* field ) { 164 field_t & container = object->*field; 165 __pedantic_pass_assert( container.size() <= values.size() ); 166 167 auto cit = enumerate(container).begin(); 168 169 container_t<ptr<Stmt>> nvals; 170 for ( delta & d : values ) { 171 if ( d.is_old ) { 172 __pedantic_pass_assert( cit.idx <= d.old_idx ); 173 std::advance( cit, d.old_idx - cit.idx ); 174 nvals.push_back( std::move( (*cit).val ) ); 175 } else { 176 nvals.push_back( std::move( d.new_val ) ); 177 } 178 } 179 180 container = std::move(nvals); 181 } 153 182 154 183 template< template<class...> class incontainer_t > 155 void take_all( incontainer_t<ptr<Stmt>> * stmts ); 184 void take_all( incontainer_t<ptr<Stmt>> * stmts ) { 185 if ( !stmts || stmts->empty() ) return; 186 187 std::transform( stmts->begin(), stmts->end(), std::back_inserter( values ), 188 [](ast::ptr<ast::Stmt>& stmt) -> delta { 189 return delta( stmt.release(), -1, false ); 190 }); 191 stmts->clear(); 192 differs = true; 193 } 156 194 157 195 template< template<class...> class incontainer_t > 158 void take_all( incontainer_t<ptr<Decl>> * decls ); 196 void take_all( incontainer_t<ptr<Decl>> * decls ) { 197 if ( !decls || decls->empty() ) return; 198 199 std::transform( decls->begin(), decls->end(), std::back_inserter( values ), 200 [](ast::ptr<ast::Decl>& decl) -> delta { 201 ast::Decl const * d = decl.release(); 202 return delta( new DeclStmt( d->location, d ), -1, false ); 203 }); 204 decls->clear(); 205 differs = true; 206 } 159 207 }; 160 208 … … 166 214 167 215 template< typename object_t, typename super_t, typename field_t > 168 void apply( object_t *, field_t super_t::* field ); 216 void apply( object_t * object, field_t super_t::* field ) { 217 field_t & container = object->*field; 218 __pedantic_pass_assert( container.size() == values.size() ); 219 220 for ( size_t i = 0; i < container.size(); ++i ) { 221 // Take all the elements that are different in 'values' 222 // and swap them into 'container' 223 if ( values[i] != nullptr ) swap(container[i], values[i]); 224 } 225 // Now the original containers should still have the unchanged values 226 // but also contain the new values. 227 } 169 228 }; 170 229 … … 534 593 535 594 } // namespace ast::__pass 595 596 #undef __pedantic_pass_assertf 597 #undef __pedantic_pass_assert -
src/AST/Print.cpp
r3a513d89 r044ae62 208 208 } 209 209 210 void print( const ast::WaitStmt * node ) { 211 if ( node->timeout_time ) { 212 os << indent-1 << "timeout of:" << endl; 213 node->timeout_time->accept( *this ); 214 215 if ( node->timeout_stmt ) { 216 os << indent-1 << "... with statment:" << endl; 217 node->timeout_stmt->accept( *this ); 218 } 219 220 if ( node->timeout_cond ) { 221 os << indent-1 << "... with condition:" << endl; 222 node->timeout_cond->accept( *this ); 223 } 224 } 225 226 if ( node->else_stmt ) { 227 os << indent-1 << "else:" << endl; 228 node->else_stmt->accept( *this ); 229 230 if ( node->else_cond ) { 231 os << indent-1 << "... with condition:" << endl; 232 node->else_cond->accept( *this ); 233 } 234 } 235 } 236 210 237 void preprint( const ast::NamedTypeDecl * node ) { 211 238 if ( ! node->name.empty() ) { … … 761 788 } 762 789 790 virtual const ast::WhenClause * visit( const ast::WhenClause * node ) override final { 791 os << indent-1 << "target: "; 792 safe_print( node->target ); 793 794 if ( node->stmt ) { 795 os << indent-1 << "... with statment:" << endl; 796 node->stmt->accept( *this ); 797 } 798 799 if ( node->when_cond ) { 800 os << indent-1 << "... with when condition:" << endl; 801 node->when_cond->accept( *this ); 802 } 803 804 return node; 805 } 806 763 807 virtual const ast::Stmt * visit( const ast::WaitForStmt * node ) override final { 764 808 os << "Waitfor Statement" << endl; … … 798 842 virtual const ast::WaitForClause * visit( const ast::WaitForClause * node ) override final { 799 843 os << indent-1 << "target function: "; 800 safe_print( node->target _func);844 safe_print( node->target ); 801 845 802 846 if ( !node->target_args.empty() ) { … … 812 856 } 813 857 814 if ( node-> cond ) {858 if ( node->when_cond ) { 815 859 os << indent-1 << "... with condition:" << endl; 816 node->cond->accept( *this ); 817 } 818 860 node->when_cond->accept( *this ); 861 } 862 863 return node; 864 } 865 866 virtual const ast::Stmt * visit( const ast::WaitUntilStmt * node ) override final { 867 os << "Waituntil Statement" << endl; 868 indent += 2; 869 for( const auto & clause : node->clauses ) { 870 clause->accept( *this ); 871 } 872 print(node); // calls print( const ast::WaitStmt * node ) 819 873 return node; 820 874 } -
src/AST/Stmt.hpp
r3a513d89 r044ae62 378 378 }; 379 379 380 // Waitfor statement: when (...) waitfor (... , ...) ... timeout(...) ... else ...381 class WaitForStmt final : public Stmt { 382 public: 383 std::vector<ptr<WaitForClause>> clauses; 384 ptr<Expr> timeout_time;380 // Base class of WaitFor/WaitUntil statements 381 // form: KEYWORD(...) ... timeout(...) ... else ... 382 class WaitStmt : public Stmt { 383 public: 384 ptr<Expr> timeout_time; 385 385 ptr<Stmt> timeout_stmt; 386 386 ptr<Expr> timeout_cond; … … 388 388 ptr<Expr> else_cond; 389 389 390 WaitStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} ) 391 : Stmt(loc, std::move(labels)) {} 392 393 private: 394 WaitStmt * clone() const override = 0; 395 MUTATE_FRIEND 396 }; 397 398 // Base class for WaitFor/WaitUntil clauses 399 // form: when( when_cond ) KEYWORD( target ) stmt 400 class WhenClause : public StmtClause { 401 public: 402 ptr<Expr> target; 403 ptr<Stmt> stmt; 404 ptr<Expr> when_cond; 405 406 WhenClause( const CodeLocation & loc ) 407 : StmtClause( loc ) {} 408 409 const WhenClause * accept( Visitor & v ) const override { return v.visit( this ); } 410 private: 411 WhenClause * clone() const override { return new WhenClause{ *this }; } 412 MUTATE_FRIEND 413 }; 414 415 // Waitfor statement: when (...) waitfor (... , ...) ... timeout(...) ... else ... 416 class WaitForStmt final : public WaitStmt { 417 public: 418 std::vector<ptr<WaitForClause>> clauses; 419 390 420 WaitForStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} ) 391 : Stmt(loc, std::move(labels)) {}421 : WaitStmt(loc, std::move(labels)) {} 392 422 393 423 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } … … 398 428 399 429 // Clause in a waitfor statement: waitfor (..., ...) ... 400 class WaitForClause final : public StmtClause { 401 public: 402 ptr<Expr> target_func; 430 class WaitForClause final : public WhenClause { 431 public: 403 432 std::vector<ptr<Expr>> target_args; 404 ptr<Stmt> stmt;405 ptr<Expr> cond;406 433 407 434 WaitForClause( const CodeLocation & loc ) 408 : StmtClause( loc ) {}435 : WhenClause( loc ) {} 409 436 410 437 const WaitForClause * accept( Visitor & v ) const override { return v.visit( this ); } 411 438 private: 412 439 WaitForClause * clone() const override { return new WaitForClause{ *this }; } 440 MUTATE_FRIEND 441 }; 442 443 // waituntil statement: when (...) waituntil (...) ... timeout(...) ... else ... 444 class WaitUntilStmt final : public WaitStmt { 445 public: 446 // Non-ast node used during compilation to store data needed to generate predicates 447 // and set initial status values for clauses 448 // Used to create a tree corresponding to the structure of the clauses in a WaitUntil 449 struct ClauseNode { 450 enum Op { AND, OR, LEFT_OR, LEAF, ELSE, TIMEOUT } op; // operation/type tag 451 // LEFT_OR used with TIMEOUT/ELSE to indicate that we ignore right hand side after parsing 452 453 ClauseNode * left; 454 ClauseNode * right; 455 WhenClause * leaf; // only set if this node is a leaf (points into vector of clauses) 456 457 bool ambiguousWhen; // used to paint nodes of predicate tree based on when() clauses 458 bool whenState; // used to track if when_cond is toggled on or off for generating init values 459 bool childOfAnd; // true on leaf nodes that are children of AND, false otherwise 460 461 ClauseNode( Op op, ClauseNode * left, ClauseNode * right ) 462 : op(op), left(left), right(right), leaf(nullptr), 463 ambiguousWhen(false), whenState(true), childOfAnd(false) {} 464 ClauseNode( Op op, WhenClause * leaf ) 465 : op(op), left(nullptr), right(nullptr), leaf(leaf), 466 ambiguousWhen(false), whenState(true), childOfAnd(false) {} 467 ClauseNode( WhenClause * leaf ) : ClauseNode(LEAF, leaf) {} 468 469 ~ClauseNode() { 470 if ( left ) delete left; 471 if ( right ) delete right; 472 } 473 }; 474 475 std::vector<ptr<WhenClause>> clauses; 476 ClauseNode * predicateTree; 477 478 WaitUntilStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} ) 479 : WaitStmt(loc, std::move(labels)) {} 480 481 ~WaitUntilStmt() { delete predicateTree; } 482 483 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 484 private: 485 WaitUntilStmt * clone() const override { return new WaitUntilStmt{ *this }; } 413 486 MUTATE_FRIEND 414 487 }; -
src/AST/Visitor.hpp
r3a513d89 r044ae62 51 51 virtual const ast::FinallyClause * visit( const ast::FinallyClause * ) = 0; 52 52 virtual const ast::Stmt * visit( const ast::SuspendStmt * ) = 0; 53 virtual const ast::WhenClause * visit( const ast::WhenClause * ) = 0; 53 54 virtual const ast::Stmt * visit( const ast::WaitForStmt * ) = 0; 54 55 virtual const ast::WaitForClause * visit( const ast::WaitForClause * ) = 0; 56 virtual const ast::Stmt * visit( const ast::WaitUntilStmt * ) = 0; 55 57 virtual const ast::Decl * visit( const ast::WithStmt * ) = 0; 56 58 virtual const ast::NullStmt * visit( const ast::NullStmt * ) = 0;
Note:
See TracChangeset
for help on using the changeset viewer.