- Timestamp:
- Sep 23, 2024, 11:14:56 AM (3 months ago)
- Branches:
- master
- Children:
- 738a9b4
- Parents:
- b723b63
- Location:
- src/AST
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Fwd.hpp
rb723b63 rfca78f1 49 49 class WhileDoStmt; 50 50 class ForStmt; 51 class ForeachStmt; 51 52 class SwitchStmt; 52 53 class CaseClause; -
src/AST/Pass.hpp
rb723b63 rfca78f1 138 138 const ast::Stmt * visit( const ast::WhileDoStmt * ) override final; 139 139 const ast::Stmt * visit( const ast::ForStmt * ) override final; 140 const ast::Stmt * visit( const ast::ForeachStmt * ) override final; 140 141 const ast::Stmt * visit( const ast::SwitchStmt * ) override final; 141 142 const ast::CaseClause * visit( const ast::CaseClause * ) override final; -
src/AST/Pass.impl.hpp
rb723b63 rfca78f1 803 803 maybe_accept_top( node, &ForStmt::cond ); 804 804 maybe_accept_top( node, &ForStmt::inc ); 805 maybe_accept_top( node, &ForStmt::range_over );806 805 maybe_accept_as_compound( node, &ForStmt::body ); 807 806 maybe_accept_as_compound( node, &ForStmt::else_ ); 807 } 808 809 VISIT_END( Stmt, node ); 810 } 811 812 //-------------------------------------------------------------------------- 813 // ForeachStmt 814 template< typename core_t > 815 const ast::Stmt * ast::Pass< core_t >::visit( const ast::ForeachStmt * node ) { 816 VISIT_START( node ); 817 818 if ( __visit_children() ) { 819 // for statements introduce a level of scope (for the initialization) 820 guard_symtab guard { *this }; 821 // xxx - old ast does not create WithStmtsToAdd scope for loop inits. should revisit this later. 822 maybe_accept( node, &ForeachStmt::inits ); 823 maybe_accept_top( node, &ForeachStmt::range ); 824 maybe_accept_as_compound( node, &ForeachStmt::body ); 825 maybe_accept_as_compound( node, &ForeachStmt::else_ ); 808 826 } 809 827 -
src/AST/Print.cpp
rb723b63 rfca78f1 637 637 } 638 638 639 virtual const ast::Stmt * visit( const ast::ForeachStmt * node ) override final { 640 os << "Range for Statement" << endl; 641 642 if ( ! node->inits.empty() ) { 643 os << indent << "... initialization:" << endl; 644 ++indent; 645 for ( const ast::Stmt * stmt : node->inits ) { 646 os << indent+1; 647 safe_print( stmt ); 648 } 649 --indent; 650 } 651 652 if ( node->isIncreasing ) { 653 os << indent << "increasing" << endl; 654 } else { 655 os << indent << "decreasing" << endl; 656 } 657 658 if ( !node->range ) { 659 os << indent << "... over range:" << endl; 660 ++indent; 661 node->range->accept( *this ); 662 --indent; 663 } 664 665 if ( node->body ) { 666 os << indent << "... with body:" << endl; 667 ++indent; 668 os << indent; 669 node->body->accept( *this ); 670 --indent; 671 } 672 673 if ( node->else_ ) { 674 os << indent << "... with else:" << endl; 675 ++indent; 676 os << indent; 677 node->else_->accept( *this ); 678 --indent; 679 } 680 681 os << endl; 682 print( node->labels ); 683 684 return node; 685 } 686 639 687 virtual const ast::Stmt * visit( const ast::SwitchStmt * node ) override final { 640 688 os << "Switch on condition: "; -
src/AST/Stmt.hpp
rb723b63 rfca78f1 237 237 ptr<Expr> cond; 238 238 ptr<Expr> inc; 239 ptr<Expr> range_over;240 bool is_inc;241 239 ptr<Stmt> body; 242 240 ptr<Stmt> else_; … … 245 243 const Expr * inc, const Stmt * body, const std::vector<Label> && label = {} ) 246 244 : Stmt(loc, std::move(label)), inits(std::move(inits)), cond(cond), inc(inc), 247 range_over(nullptr),body(body), else_(nullptr) {}245 body(body), else_(nullptr) {} 248 246 249 247 ForStmt( const CodeLocation & loc, const std::vector<ptr<Stmt>> && inits, const Expr * cond, 250 248 const Expr * inc, const Stmt * body, const Stmt * else_, const std::vector<Label> && labels = {} ) 251 249 : Stmt(loc, std::move(labels)), inits(std::move(inits)), cond(cond), inc(inc), 252 range_over(nullptr), body(body), else_(else_) {}253 254 ForStmt( const CodeLocation & loc, const std::vector<ptr<Stmt>> && inits, const Expr * range_over, bool is_inc,255 const Stmt * body, const Stmt * else_ )256 : Stmt(loc, std::move(labels)), inits(std::move(inits)), range_over(range_over), is_inc(is_inc),257 250 body(body), else_(else_) {} 258 251 … … 260 253 private: 261 254 ForStmt * clone() const override { return new ForStmt{ *this }; } 255 MUTATE_FRIEND 256 }; 257 258 enum RangeDirection { DecreasingRange, IncreasingRange }; 259 260 // For-each loop: for (... : ...) ... else ... 261 class ForeachStmt final : public Stmt { 262 public: 263 std::vector<ptr<Stmt>> inits; 264 ptr<Expr> range; 265 ptr<Stmt> body; 266 ptr<Stmt> else_; 267 // This is a property of the range, but there is no place to store it. 268 RangeDirection isIncreasing; 269 270 ForeachStmt( const CodeLocation & loc, const std::vector<ptr<Stmt>> && inits, 271 const Expr * range_over, RangeDirection isInc, const Stmt * body, const Stmt * else_ ) 272 : Stmt(loc, std::move(labels)), inits(std::move(inits)), range(range_over), 273 body(body), else_(else_), isIncreasing(isInc) {} 274 275 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 276 private: 277 ForeachStmt * clone() const override { return new ForeachStmt{ *this }; } 262 278 MUTATE_FRIEND 263 279 }; -
src/AST/Visitor.hpp
rb723b63 rfca78f1 41 41 virtual const ast::Stmt * visit( const ast::WhileDoStmt * ) = 0; 42 42 virtual const ast::Stmt * visit( const ast::ForStmt * ) = 0; 43 virtual const ast::Stmt * visit( const ast::ForeachStmt * ) = 0; 43 44 virtual const ast::Stmt * visit( const ast::SwitchStmt * ) = 0; 44 45 virtual const ast::CaseClause * visit( const ast::CaseClause * ) = 0;
Note: See TracChangeset
for help on using the changeset viewer.