- Timestamp:
- Feb 2, 2022, 7:51:30 PM (2 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- 941e14a
- Parents:
- fc72696c (diff), 4e7171f (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
- Files:
-
- 30 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
rfc72696c r17cb385 9 9 // Author : Thierry Delisle 10 10 // Created On : Thu May 09 15::37::05 2019 11 // Last Modified By : Andrew Beach12 // Last Modified On : Wed Jul 14 16:15:00 202113 // Update Count : 3711 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 2 13:19:22 2022 13 // Update Count : 41 14 14 // 15 15 … … 393 393 auto stmt = new IfStmt( 394 394 get<Expression>().accept1( node->cond ), 395 get<Statement>().accept1( node->then Part),396 get<Statement>().accept1( node->else Part),395 get<Statement>().accept1( node->then ), 396 get<Statement>().accept1( node->else_ ), 397 397 get<Statement>().acceptL( node->inits ) 398 398 ); … … 419 419 } 420 420 421 const ast::Stmt * visit( const ast::While Stmt * node ) override final {421 const ast::Stmt * visit( const ast::WhileDoStmt * node ) override final { 422 422 if ( inCache( node ) ) return nullptr; 423 423 auto inits = get<Statement>().acceptL( node->inits ); 424 auto stmt = new While Stmt(424 auto stmt = new WhileDoStmt( 425 425 get<Expression>().accept1( node->cond ), 426 426 get<Statement>().accept1( node->body ), 427 get<Statement>().accept1( node->else_ ), 427 428 inits, 428 429 node->isDoWhile … … 437 438 get<Expression>().accept1( node->cond ), 438 439 get<Expression>().accept1( node->inc ), 439 get<Statement>().accept1( node->body ) 440 get<Statement>().accept1( node->body ), 441 get<Statement>().accept1( node->else_ ) 440 442 ); 441 443 return stmtPostamble( stmt, node ); … … 1872 1874 old->location, 1873 1875 GET_ACCEPT_1(condition, Expr), 1874 GET_ACCEPT_1(then Part, Stmt),1875 GET_ACCEPT_1(else Part, Stmt),1876 GET_ACCEPT_1(then, Stmt), 1877 GET_ACCEPT_1(else_, Stmt), 1876 1878 GET_ACCEPT_V(initialization, Stmt), 1877 1879 GET_LABELS_V(old->labels) … … 1902 1904 } 1903 1905 1904 virtual void visit( const While Stmt * old ) override final {1906 virtual void visit( const WhileDoStmt * old ) override final { 1905 1907 if ( inCache( old ) ) return; 1906 this->node = new ast::While Stmt(1908 this->node = new ast::WhileDoStmt( 1907 1909 old->location, 1908 1910 GET_ACCEPT_1(condition, Expr), 1909 1911 GET_ACCEPT_1(body, Stmt), 1912 GET_ACCEPT_1(else_, Stmt), 1910 1913 GET_ACCEPT_V(initialization, Stmt), 1911 1914 old->isDoWhile, … … 1923 1926 GET_ACCEPT_1(increment, Expr), 1924 1927 GET_ACCEPT_1(body, Stmt), 1928 GET_ACCEPT_1(else_, Stmt), 1925 1929 GET_LABELS_V(old->labels) 1926 1930 ); -
src/AST/Fwd.hpp
rfc72696c r17cb385 10 10 // Created On : Wed May 8 16:05:00 2019 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 12 18:37:39 202113 // Update Count : 412 // Last Modified On : Tue Feb 1 09:08:33 2022 13 // Update Count : 5 14 14 // 15 15 … … 44 44 class DirectiveStmt; 45 45 class IfStmt; 46 class While Stmt;46 class WhileDoStmt; 47 47 class ForStmt; 48 48 class SwitchStmt; -
src/AST/Node.cpp
rfc72696c r17cb385 10 10 // Created On : Thu May 16 14:16:00 2019 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 12 18:25:06 202113 // Update Count : 212 // Last Modified On : Tue Feb 1 09:09:39 2022 13 // Update Count : 3 14 14 // 15 15 … … 146 146 template class ast::ptr_base< ast::IfStmt, ast::Node::ref_type::weak >; 147 147 template class ast::ptr_base< ast::IfStmt, ast::Node::ref_type::strong >; 148 template class ast::ptr_base< ast::While Stmt, ast::Node::ref_type::weak >;149 template class ast::ptr_base< ast::While Stmt, ast::Node::ref_type::strong >;148 template class ast::ptr_base< ast::WhileDoStmt, ast::Node::ref_type::weak >; 149 template class ast::ptr_base< ast::WhileDoStmt, ast::Node::ref_type::strong >; 150 150 template class ast::ptr_base< ast::ForStmt, ast::Node::ref_type::weak >; 151 151 template class ast::ptr_base< ast::ForStmt, ast::Node::ref_type::strong >; -
src/AST/Pass.hpp
rfc72696c r17cb385 146 146 const ast::Stmt * visit( const ast::DirectiveStmt * ) override final; 147 147 const ast::Stmt * visit( const ast::IfStmt * ) override final; 148 const ast::Stmt * visit( const ast::While Stmt* ) override final;148 const ast::Stmt * visit( const ast::WhileDoStmt * ) override final; 149 149 const ast::Stmt * visit( const ast::ForStmt * ) override final; 150 150 const ast::Stmt * visit( const ast::SwitchStmt * ) override final; -
src/AST/Pass.impl.hpp
rfc72696c r17cb385 756 756 maybe_accept( node, &IfStmt::inits ); 757 757 maybe_accept( node, &IfStmt::cond ); 758 maybe_accept_as_compound( node, &IfStmt::then Part);759 maybe_accept_as_compound( node, &IfStmt::else Part);758 maybe_accept_as_compound( node, &IfStmt::then ); 759 maybe_accept_as_compound( node, &IfStmt::else_ ); 760 760 } 761 761 … … 764 764 765 765 //-------------------------------------------------------------------------- 766 // While Stmt767 template< typename core_t > 768 const ast::Stmt * ast::Pass< core_t >::visit( const ast::While Stmt * node ) {766 // WhileDoStmt 767 template< typename core_t > 768 const ast::Stmt * ast::Pass< core_t >::visit( const ast::WhileDoStmt * node ) { 769 769 VISIT_START( node ); 770 770 … … 772 772 // while statements introduce a level of scope (for the initialization) 773 773 guard_symtab guard { *this }; 774 maybe_accept( node, &While Stmt::inits );775 maybe_accept( node, &While Stmt::cond );776 maybe_accept_as_compound( node, &While Stmt::body );774 maybe_accept( node, &WhileDoStmt::inits ); 775 maybe_accept( node, &WhileDoStmt::cond ); 776 maybe_accept_as_compound( node, &WhileDoStmt::body ); 777 777 } 778 778 -
src/AST/Print.cpp
rfc72696c r17cb385 511 511 ++indent; 512 512 os << indent; 513 safe_print( node->then Part);514 --indent; 515 516 if ( node->else Part!= 0 ) {513 safe_print( node->then ); 514 --indent; 515 516 if ( node->else_ != 0 ) { 517 517 os << indent << "... else:" << endl; 518 518 ++indent; 519 519 os << indent; 520 node->else Part->accept( *this );520 node->else_->accept( *this ); 521 521 --indent; 522 522 } // if … … 524 524 } 525 525 526 virtual const ast::Stmt * visit( const ast::While Stmt * node ) override final {526 virtual const ast::Stmt * visit( const ast::WhileDoStmt * node ) override final { 527 527 if ( node->isDoWhile ) { os << "Do-"; } 528 528 os << "While on condition:" << endl; -
src/AST/Stmt.hpp
rfc72696c r17cb385 10 10 // Created On : Wed May 8 13:00:00 2019 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 31 22:38:53202213 // Update Count : 1212 // Last Modified On : Tue Feb 1 17:44:46 2022 13 // Update Count : 24 14 14 // 15 15 … … 42 42 : ParseNode(loc), labels(std::move(labels)) {} 43 43 44 Stmt(const Stmt & o) : ParseNode(o), labels(o.labels) {}44 Stmt(const Stmt & o) : ParseNode(o), labels(o.labels) {} 45 45 46 46 const Stmt * accept( Visitor & v ) const override = 0; … … 56 56 57 57 CompoundStmt(const CodeLocation & loc, std::list<ptr<Stmt>> && ks = {}, 58 std::vector<Label> && labels = {} )58 std::vector<Label> && labels = {} ) 59 59 : Stmt(loc, std::move(labels)), kids(std::move(ks)) {} 60 60 61 CompoundStmt( const CompoundStmt & o );62 CompoundStmt( CompoundStmt && o ) = default;61 CompoundStmt( const CompoundStmt & o ); 62 CompoundStmt( CompoundStmt && o ) = default; 63 63 64 64 void push_back( const Stmt * s ) { kids.emplace_back( s ); } … … 88 88 ptr<Expr> expr; 89 89 90 ExprStmt( const CodeLocation & loc, const Expr* e, std::vector<Label>&& labels = {} )90 ExprStmt( const CodeLocation & loc, const Expr* e, std::vector<Label> && labels = {} ) 91 91 : Stmt(loc, std::move(labels)), expr(e) {} 92 92 … … 139 139 public: 140 140 ptr<Expr> cond; 141 ptr<Stmt> then Part;142 ptr<Stmt> else Part;141 ptr<Stmt> then; 142 ptr<Stmt> else_; 143 143 std::vector<ptr<Stmt>> inits; 144 144 145 IfStmt( const CodeLocation & loc, const Expr * cond, const Stmt * then Part,146 const Stmt * else Part= nullptr, std::vector<ptr<Stmt>> && inits = {},145 IfStmt( const CodeLocation & loc, const Expr * cond, const Stmt * then, 146 const Stmt * else_ = nullptr, std::vector<ptr<Stmt>> && inits = {}, 147 147 std::vector<Label> && labels = {} ) 148 : Stmt(loc, std::move(labels)), cond(cond), then Part(thenPart), elsePart(elsePart),148 : Stmt(loc, std::move(labels)), cond(cond), then(then), else_(else_), 149 149 inits(std::move(inits)) {} 150 150 … … 191 191 192 192 // While loop: while (...) ... else ... or do ... while (...) else ...; 193 class While Stmt final : public Stmt {193 class WhileDoStmt final : public Stmt { 194 194 public: 195 195 ptr<Expr> cond; 196 196 ptr<Stmt> body; 197 ptr<Stmt> else Part;197 ptr<Stmt> else_; 198 198 std::vector<ptr<Stmt>> inits; 199 199 bool isDoWhile; 200 200 201 While Stmt( const CodeLocation & loc, const Expr * cond, const Stmt * body,201 WhileDoStmt( const CodeLocation & loc, const Expr * cond, const Stmt * body, 202 202 std::vector<ptr<Stmt>> && inits, bool isDoWhile = false, std::vector<Label> && labels = {} ) 203 : Stmt(loc, std::move(labels)), cond(cond), body(body), inits(std::move(inits)), isDoWhile(isDoWhile) {} 204 205 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 206 private: 207 WhileStmt * clone() const override { return new WhileStmt{ *this }; } 203 : Stmt(loc, std::move(labels)), cond(cond), body(body), else_(nullptr), inits(std::move(inits)), isDoWhile(isDoWhile) {} 204 205 WhileDoStmt( const CodeLocation & loc, const Expr * cond, const Stmt * body, const Stmt * else_, 206 std::vector<ptr<Stmt>> && inits, bool isDoWhile = false, std::vector<Label> && labels = {} ) 207 : Stmt(loc, std::move(labels)), cond(cond), body(body), else_(else_), inits(std::move(inits)), isDoWhile(isDoWhile) {} 208 209 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 210 private: 211 WhileDoStmt * clone() const override { return new WhileDoStmt{ *this }; } 208 212 MUTATE_FRIEND 209 213 }; … … 216 220 ptr<Expr> inc; 217 221 ptr<Stmt> body; 218 ptr<Stmt> else Part;222 ptr<Stmt> else_; 219 223 220 224 ForStmt( const CodeLocation & loc, std::vector<ptr<Stmt>> && inits, const Expr * cond, 221 const Expr * inc, const Stmt * body, std::vector<Label> && labels = {} ) 222 : Stmt(loc, std::move(labels)), inits(std::move(inits)), cond(cond), inc(inc), body(body) {} 225 const Expr * inc, const Stmt * body, std::vector<Label> && label = {} ) 226 : Stmt(loc, std::move(label)), inits(std::move(inits)), cond(cond), inc(inc), body(body), else_(nullptr) {} 227 228 ForStmt( const CodeLocation & loc, std::vector<ptr<Stmt>> && inits, const Expr * cond, 229 const Expr * inc, const Stmt * body, const Stmt * else_, std::vector<Label> && labels = {} ) 230 : Stmt(loc, std::move(labels)), inits(std::move(inits)), cond(cond), inc(inc), body(body), else_(else_) {} 223 231 224 232 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } -
src/AST/Visitor.hpp
rfc72696c r17cb385 10 10 // Created On : Thr May 9 15:28:00 2019 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 12 18:25:07 202113 // Update Count : 112 // Last Modified On : Tue Feb 1 09:09:34 2022 13 // Update Count : 2 14 14 // 15 15 … … 38 38 virtual const ast::Stmt * visit( const ast::DirectiveStmt * ) = 0; 39 39 virtual const ast::Stmt * visit( const ast::IfStmt * ) = 0; 40 virtual const ast::Stmt * visit( const ast::While Stmt* ) = 0;40 virtual const ast::Stmt * visit( const ast::WhileDoStmt * ) = 0; 41 41 virtual const ast::Stmt * visit( const ast::ForStmt * ) = 0; 42 42 virtual const ast::Stmt * visit( const ast::SwitchStmt * ) = 0; -
src/CodeGen/CodeGenerator.cc
rfc72696c r17cb385 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 12 19:00:42 202113 // Update Count : 5 3612 // Last Modified On : Tue Feb 1 16:29:25 2022 13 // Update Count : 540 14 14 // 15 15 #include "CodeGenerator.h" … … 42 42 bool wantSpacing( Statement * stmt) { 43 43 return dynamic_cast< IfStmt * >( stmt ) || dynamic_cast< CompoundStmt * >( stmt ) || 44 dynamic_cast< While Stmt * >( stmt ) || dynamic_cast< ForStmt * >( stmt ) || dynamic_cast< SwitchStmt *>( stmt );44 dynamic_cast< WhileDoStmt * >( stmt ) || dynamic_cast< ForStmt * >( stmt ) || dynamic_cast< SwitchStmt *>( stmt ); 45 45 } 46 46 … … 955 955 output << " ) "; 956 956 957 ifStmt->get_then Part()->accept( *visitor );958 959 if ( ifStmt->get_else Part() != 0) {957 ifStmt->get_then()->accept( *visitor ); 958 959 if ( ifStmt->get_else() != 0) { 960 960 output << " else "; 961 ifStmt->get_else Part()->accept( *visitor );961 ifStmt->get_else()->accept( *visitor ); 962 962 } // if 963 963 } … … 1125 1125 } 1126 1126 1127 void CodeGenerator::postvisit( While Stmt * whileStmt ) {1128 if ( while Stmt->get_isDoWhile() ) {1127 void CodeGenerator::postvisit( WhileDoStmt * whileDoStmt ) { 1128 if ( whileDoStmt->get_isDoWhile() ) { 1129 1129 output << "do"; 1130 1130 } else { 1131 1131 output << "while ("; 1132 while Stmt->get_condition()->accept( *visitor );1132 whileDoStmt->get_condition()->accept( *visitor ); 1133 1133 output << ")"; 1134 1134 } // if 1135 1135 output << " "; 1136 1136 1137 output << CodeGenerator::printLabels( while Stmt->get_body()->get_labels() );1138 while Stmt->get_body()->accept( *visitor );1137 output << CodeGenerator::printLabels( whileDoStmt->get_body()->get_labels() ); 1138 whileDoStmt->get_body()->accept( *visitor ); 1139 1139 1140 1140 output << indent; 1141 1141 1142 if ( while Stmt->get_isDoWhile() ) {1142 if ( whileDoStmt->get_isDoWhile() ) { 1143 1143 output << " while ("; 1144 while Stmt->get_condition()->accept( *visitor );1144 whileDoStmt->get_condition()->accept( *visitor ); 1145 1145 output << ");"; 1146 1146 } // if -
src/CodeGen/CodeGenerator.h
rfc72696c r17cb385 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 12 18:35:38 202113 // Update Count : 6 312 // Last Modified On : Tue Feb 1 09:23:21 2022 13 // Update Count : 64 14 14 // 15 15 … … 116 116 void postvisit( WaitForStmt * ); 117 117 void postvisit( WithStmt * ); 118 void postvisit( While Stmt * );118 void postvisit( WhileDoStmt * ); 119 119 void postvisit( ForStmt * ); 120 120 void postvisit( NullStmt * ); -
src/Common/CodeLocationTools.cpp
rfc72696c r17cb385 10 10 // Created On : Fri Dec 4 15:42:00 2020 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 12 18:35:37 202113 // Update Count : 212 // Last Modified On : Tue Feb 1 09:14:39 2022 13 // Update Count : 3 14 14 // 15 15 … … 109 109 macro(DirectiveStmt, Stmt) \ 110 110 macro(IfStmt, Stmt) \ 111 macro(While Stmt, Stmt) \111 macro(WhileDoStmt, Stmt) \ 112 112 macro(ForStmt, Stmt) \ 113 113 macro(SwitchStmt, Stmt) \ -
src/Common/PassVisitor.h
rfc72696c r17cb385 92 92 virtual void visit( IfStmt * ifStmt ) override final; 93 93 virtual void visit( const IfStmt * ifStmt ) override final; 94 virtual void visit( While Stmt * whileStmt ) override final;95 virtual void visit( const While Stmt * whileStmt ) override final;94 virtual void visit( WhileDoStmt * whileDoStmt ) override final; 95 virtual void visit( const WhileDoStmt * whileDoStmt ) override final; 96 96 virtual void visit( ForStmt * forStmt ) override final; 97 97 virtual void visit( const ForStmt * forStmt ) override final; … … 277 277 virtual Statement * mutate( DirectiveStmt * dirStmt ) override final; 278 278 virtual Statement * mutate( IfStmt * ifStmt ) override final; 279 virtual Statement * mutate( While Stmt * whileStmt ) override final;279 virtual Statement * mutate( WhileDoStmt * whileDoStmt ) override final; 280 280 virtual Statement * mutate( ForStmt * forStmt ) override final; 281 281 virtual Statement * mutate( SwitchStmt * switchStmt ) override final; -
src/Common/PassVisitor.impl.h
rfc72696c r17cb385 1189 1189 maybeAccept_impl( node->initialization, *this ); 1190 1190 visitExpression ( node->condition ); 1191 node->then Part = visitStatement( node->thenPart);1192 node->else Part = visitStatement( node->elsePart);1191 node->then = visitStatement( node->then ); 1192 node->else_ = visitStatement( node->else_ ); 1193 1193 } 1194 1194 VISIT_END( node ); … … 1203 1203 maybeAccept_impl( node->initialization, *this ); 1204 1204 visitExpression ( node->condition ); 1205 visitStatement ( node->then Part);1206 visitStatement ( node->else Part);1205 visitStatement ( node->then ); 1206 visitStatement ( node->else_ ); 1207 1207 } 1208 1208 VISIT_END( node ); … … 1217 1217 maybeMutate_impl( node->initialization, *this ); 1218 1218 node->condition = mutateExpression( node->condition ); 1219 node->then Part = mutateStatement ( node->thenPart);1220 node->else Part = mutateStatement ( node->elsePart);1219 node->then = mutateStatement ( node->then ); 1220 node->else_ = mutateStatement ( node->else_ ); 1221 1221 } 1222 1222 MUTATE_END( Statement, node ); … … 1224 1224 1225 1225 //-------------------------------------------------------------------------- 1226 // While Stmt1227 template< typename pass_type > 1228 void PassVisitor< pass_type >::visit( While Stmt * node ) {1226 // WhileDoStmt 1227 template< typename pass_type > 1228 void PassVisitor< pass_type >::visit( WhileDoStmt * node ) { 1229 1229 VISIT_START( node ); 1230 1230 … … 1241 1241 1242 1242 template< typename pass_type > 1243 void PassVisitor< pass_type >::visit( const While Stmt * node ) {1243 void PassVisitor< pass_type >::visit( const WhileDoStmt * node ) { 1244 1244 VISIT_START( node ); 1245 1245 … … 1256 1256 1257 1257 template< typename pass_type > 1258 Statement * PassVisitor< pass_type >::mutate( While Stmt * node ) {1258 Statement * PassVisitor< pass_type >::mutate( WhileDoStmt * node ) { 1259 1259 MUTATE_START( node ); 1260 1260 -
src/ControlStruct/ForExprMutator.cc
rfc72696c r17cb385 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Mar 11 22:26:52 201913 // Update Count : 1 412 // Last Modified On : Tue Feb 1 09:26:12 2022 13 // Update Count : 16 14 14 // 15 15 … … 45 45 return hoist( forStmt, forStmt->initialization ); 46 46 } 47 Statement * ForExprMutator::postmutate( While Stmt * whileStmt ) {48 return hoist( while Stmt, whileStmt->initialization );47 Statement * ForExprMutator::postmutate( WhileDoStmt * whileDoStmt ) { 48 return hoist( whileDoStmt, whileDoStmt->initialization ); 49 49 } 50 50 } // namespace ControlStruct -
src/ControlStruct/ForExprMutator.h
rfc72696c r17cb385 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Jan 30 09:14:46202213 // Update Count : 612 // Last Modified On : Tue Feb 1 09:18:50 2022 13 // Update Count : 7 14 14 // 15 15 … … 18 18 class IfStmt; 19 19 class ForStmt; 20 class While Stmt;20 class WhileDoStmt; 21 21 class Statement; 22 22 … … 26 26 Statement * postmutate( IfStmt * ); 27 27 Statement * postmutate( ForStmt * ); 28 Statement * postmutate( While Stmt * );28 Statement * postmutate( WhileDoStmt * ); 29 29 }; 30 30 } // namespace ControlStruct -
src/ControlStruct/HoistControlDecls.cpp
rfc72696c r17cb385 10 10 // Created On : Fri Dec 3 15:34:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 31 18:52:35202213 // Update Count : 2 312 // Last Modified On : Tue Feb 1 18:59:47 2022 13 // Update Count : 25 14 14 // 15 15 … … 35 35 36 36 CompoundStmt * block = new CompoundStmt( stmt->location ); // create empty compound statement 37 // { 38 // } 37 // {} 39 38 40 39 for ( const Stmt * next : stmt->inits ) { // link conditional declarations into compound … … 69 68 return hoist<ForStmt>( stmt ); 70 69 } 71 const Stmt * postvisit( const While Stmt * stmt ) {72 return hoist<While Stmt>( stmt );70 const Stmt * postvisit( const WhileDoStmt * stmt ) { 71 return hoist<WhileDoStmt>( stmt ); 73 72 } 74 73 }; -
src/ControlStruct/LabelFixer.cc
rfc72696c r17cb385 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 31 22:28:31202213 // Update Count : 16 112 // Last Modified On : Tue Feb 1 09:12:09 2022 13 // Update Count : 162 14 14 // 15 15 … … 29 29 bool LabelFixer::Entry::insideLoop() { 30 30 return ( dynamic_cast< ForStmt * > ( definition ) || 31 dynamic_cast< While Stmt * > ( definition ) );31 dynamic_cast< WhileDoStmt * > ( definition ) ); 32 32 } 33 33 -
src/ControlStruct/LabelGeneratorNew.cpp
rfc72696c r17cb385 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 31 18:51:10202213 // Update Count : 7 112 // Last Modified On : Wed Feb 2 09:11:17 2022 13 // Update Count : 72 14 14 // 15 15 … … 28 28 static int current = 0; 29 29 30 assert ( ( (void)"CFA internal error: parameter statement cannot be null pointer", stmt ));30 assertf( stmt, "CFA internal error: parameter statement cannot be null pointer" ); 31 31 32 32 enum { size = 128 }; 33 33 char buf[size]; // space to build label 34 34 int len = snprintf( buf, size, "__L%d__%s", current++, suffix.c_str() ); 35 assert ( ( (void)"CFA Internal error: buffer overflow creating label", len < size ));35 assertf( len < size, "CFA Internal error: buffer overflow creating label" ); 36 36 37 37 // What does this do? 38 38 if ( ! stmt->labels.empty() ) { 39 39 len = snprintf( buf + len, size - len, "_%s__", stmt->labels.front().name.c_str() ); 40 assert ( ( (void)"CFA Internal error: buffer overflow creating label", len < size - len ));40 assertf( len < size - len, "CFA Internal error: buffer overflow creating label" ); 41 41 } // if 42 42 -
src/ControlStruct/MLEMutator.cc
rfc72696c r17cb385 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Wed Jan 22 11:50:00 202013 // Update Count : 22 311 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Feb 1 09:26:28 2022 13 // Update Count : 225 14 14 // 15 15 … … 39 39 namespace { 40 40 bool isLoop( const MultiLevelExitMutator::Entry & e ) { 41 return dynamic_cast< While Stmt * >( e.get_controlStructure() )41 return dynamic_cast< WhileDoStmt * >( e.get_controlStructure() ) 42 42 || dynamic_cast< ForStmt * >( e.get_controlStructure() ); 43 43 } … … 295 295 } 296 296 297 void MultiLevelExitMutator::premutate( While Stmt * whileStmt ) {298 return prehandleLoopStmt( while Stmt );297 void MultiLevelExitMutator::premutate( WhileDoStmt * whileDoStmt ) { 298 return prehandleLoopStmt( whileDoStmt ); 299 299 } 300 300 … … 303 303 } 304 304 305 Statement * MultiLevelExitMutator::postmutate( While Stmt * whileStmt ) {306 return posthandleLoopStmt( while Stmt );305 Statement * MultiLevelExitMutator::postmutate( WhileDoStmt * whileDoStmt ) { 306 return posthandleLoopStmt( whileDoStmt ); 307 307 } 308 308 -
src/ControlStruct/MLEMutator.h
rfc72696c r17cb385 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Wed Jan 22 11:50:00 202013 // Update Count : 4811 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Feb 1 09:27:24 2022 13 // Update Count : 50 14 14 // 15 15 … … 42 42 void premutate( CompoundStmt *cmpndStmt ); 43 43 Statement * postmutate( BranchStmt *branchStmt ) throw ( SemanticErrorException ); 44 void premutate( While Stmt *whileStmt );45 Statement * postmutate( While Stmt *whileStmt );44 void premutate( WhileDoStmt *whileDoStmt ); 45 Statement * postmutate( WhileDoStmt *whileDoStmt ); 46 46 void premutate( ForStmt *forStmt ); 47 47 Statement * postmutate( ForStmt *forStmt ); … … 67 67 stmt( stmt ), breakExit( breakExit ), contExit( contExit ) {} 68 68 69 explicit Entry( While Stmt *stmt, Label breakExit, Label contExit ) :69 explicit Entry( WhileDoStmt *stmt, Label breakExit, Label contExit ) : 70 70 stmt( stmt ), breakExit( breakExit ), contExit( contExit ) {} 71 71 -
src/ControlStruct/MultiLevelExit.cpp
rfc72696c r17cb385 10 10 // Created On : Mon Nov 1 13:48:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 31 22:35:08202213 // Update Count : 2 812 // Last Modified On : Tue Feb 1 18:48:47 2022 13 // Update Count : 29 14 14 // 15 15 … … 40 40 41 41 enum Kind { 42 ForStmtK, While StmtK, CompoundStmtK, IfStmtK, CaseStmtK, SwitchStmtK, TryStmtK42 ForStmtK, WhileDoStmtK, CompoundStmtK, IfStmtK, CaseStmtK, SwitchStmtK, TryStmtK 43 43 } kind; 44 44 … … 53 53 Entry( const ForStmt * stmt, Label breakExit, Label contExit ) : 54 54 stmt( stmt ), firstTarget( breakExit ), secondTarget( contExit ), kind( ForStmtK ) {} 55 Entry( const While Stmt * stmt, Label breakExit, Label contExit ) :56 stmt( stmt ), firstTarget( breakExit ), secondTarget( contExit ), kind( While StmtK ) {}55 Entry( const WhileDoStmt * stmt, Label breakExit, Label contExit ) : 56 stmt( stmt ), firstTarget( breakExit ), secondTarget( contExit ), kind( WhileDoStmtK ) {} 57 57 Entry( const CompoundStmt *stmt, Label breakExit ) : 58 58 stmt( stmt ), firstTarget( breakExit ), secondTarget(), kind( CompoundStmtK ) {} … … 66 66 stmt( stmt ), firstTarget( breakExit ), secondTarget(), kind( TryStmtK ) {} 67 67 68 bool isContTarget() const { return kind <= While StmtK; }68 bool isContTarget() const { return kind <= WhileDoStmtK; } 69 69 bool isBreakTarget() const { return kind != CaseStmtK; } 70 70 bool isFallTarget() const { return kind == CaseStmtK; } 71 71 bool isFallDefaultTarget() const { return kind == SwitchStmtK; } 72 72 73 Label useContExit() { assert( kind <= WhileStmtK ); return useTarget(secondTarget); } 73 // These routines set a target as being "used" by a BranchStmt 74 Label useContExit() { assert( kind <= WhileDoStmtK ); return useTarget(secondTarget); } 74 75 Label useBreakExit() { assert( kind != CaseStmtK ); return useTarget(firstTarget); } 75 76 Label useFallExit() { assert( kind == CaseStmtK ); return useTarget(firstTarget); } 76 77 Label useFallDefaultExit() { assert( kind == SwitchStmtK ); return useTarget(secondTarget); } 77 78 78 bool isContUsed() const { assert( kind <= WhileStmtK ); return secondTarget.used; } 79 // These routines check if a specific label for a statement is used by a BranchStmt 80 bool isContUsed() const { assert( kind <= WhileDoStmtK ); return secondTarget.used; } 79 81 bool isBreakUsed() const { assert( kind != CaseStmtK ); return firstTarget.used; } 80 82 bool isFallUsed() const { assert( kind == CaseStmtK ); return firstTarget.used; } … … 110 112 const CompoundStmt * previsit( const CompoundStmt * ); 111 113 const BranchStmt * postvisit( const BranchStmt * ); 112 void previsit( const While Stmt * );113 const While Stmt * postvisit( const WhileStmt * );114 void previsit( const WhileDoStmt * ); 115 const WhileDoStmt * postvisit( const WhileDoStmt * ); 114 116 void previsit( const ForStmt * ); 115 117 const ForStmt * postvisit( const ForStmt * ); … … 164 166 const CompoundStmt * stmt ) { 165 167 visit_children = false; 168 169 // if the stmt is labelled then generate a label to check in postvisit if the label is used 166 170 bool isLabeled = !stmt->labels.empty(); 167 171 if ( isLabeled ) { … … 217 221 } 218 222 223 // This routine updates targets on enclosing control structures to indicate which 224 // label is used by the BranchStmt that is passed 219 225 const BranchStmt * MultiLevelExitCore::postvisit( const BranchStmt * stmt ) { 220 226 vector<Entry>::reverse_iterator targetEntry = 221 227 enclosing_control_structures.rend(); 228 229 // Labels on different stmts require different approaches to access 222 230 switch ( stmt->kind ) { 223 231 case BranchStmt::Goto: … … 253 261 break; 254 262 } 263 // handle fallthrough in case/switch stmts 255 264 case BranchStmt::FallThrough: { 256 265 targetEntry = findEnclosingControlStructure( isFallthroughTarget ); … … 333 342 } 334 343 335 void MultiLevelExitCore::previsit( const While Stmt * stmt ) {344 void MultiLevelExitCore::previsit( const WhileDoStmt * stmt ) { 336 345 return prehandleLoopStmt( stmt ); 337 346 } 338 347 339 const While Stmt * MultiLevelExitCore::postvisit( const WhileStmt * stmt ) {348 const WhileDoStmt * MultiLevelExitCore::postvisit( const WhileDoStmt * stmt ) { 340 349 return posthandleLoopStmt( stmt ); 341 350 } … … 530 539 } 531 540 541 // if continue is used insert a continue label into the back of the body of the loop 532 542 if ( entry.isContUsed() ) { 533 543 CompoundStmt * new_body = new CompoundStmt( body->location ); 544 // {} 534 545 new_body->kids.push_back( body ); 546 // { 547 // body 548 // } 535 549 new_body->kids.push_back( 536 550 labelledNullStmt( body->location, entry.useContExit() ) ); 551 // { 552 // body 553 // ContinueLabel: {} 554 // } 537 555 return new_body; 538 556 } … … 548 566 Label contLabel = newLabel( "loopContinue", loopStmt ); 549 567 enclosing_control_structures.emplace_back( loopStmt, breakLabel, contLabel ); 568 // labels are added temporarily to see if they are used and then added permanently in postvisit if ther are used 569 // children will tag labels as being used during their traversal which occurs before postvisit 570 571 // GuardAction calls the lambda after the node is done being visited 550 572 GuardAction( [this](){ enclosing_control_structures.pop_back(); } ); 551 573 } … … 560 582 return mutate_field( 561 583 loopStmt, &LoopNode::body, mutateLoop( loopStmt->body, entry ) ); 584 // this call to mutate_field compares loopStmt->body and the result of mutateLoop 585 // if they are the same the node isn't mutated, if they differ then the new mutated node is returned 586 // the stmts will only differ if a label is used 562 587 } 563 588 -
src/Parser/ParseNode.h
rfc72696c r17cb385 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jan 29 09:45:56202213 // Update Count : 90 112 // Last Modified On : Wed Feb 2 09:15:49 2022 13 // Update Count : 905 14 14 // 15 15 … … 410 410 411 411 Expression * build_if_control( CondCtl * ctl, std::list< Statement * > & init ); 412 Statement * build_if( CondCtl * ctl, StatementNode * then _stmt, StatementNode * else_stmt);412 Statement * build_if( CondCtl * ctl, StatementNode * then, StatementNode * else_ ); 413 413 Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt ); 414 414 Statement * build_case( ExpressionNode * ctl ); 415 415 Statement * build_default(); 416 Statement * build_while( CondCtl * ctl, StatementNode * stmt );417 Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt );418 Statement * build_for( ForCtrl * forctl, StatementNode * stmt );416 Statement * build_while( CondCtl * ctl, StatementNode * stmt, StatementNode * else_ = nullptr ); 417 Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt, StatementNode * else_ = nullptr ); 418 Statement * build_for( ForCtrl * forctl, StatementNode * stmt, StatementNode * else_ = nullptr ); 419 419 Statement * build_branch( BranchStmt::Type kind ); 420 420 Statement * build_branch( std::string * identifier, BranchStmt::Type kind ); … … 424 424 Statement * build_resume( ExpressionNode * ctl ); 425 425 Statement * build_resume_at( ExpressionNode * ctl , ExpressionNode * target ); 426 Statement * build_try( StatementNode * try_ stmt, StatementNode * catch_stmt, StatementNode * finally_stmt);427 Statement * build_catch( CatchStmt::Kind kind, DeclarationNode * decl, ExpressionNode *cond, StatementNode *body );426 Statement * build_try( StatementNode * try_, StatementNode * catch_, StatementNode * finally_ ); 427 Statement * build_catch( CatchStmt::Kind kind, DeclarationNode * decl, ExpressionNode * cond, StatementNode * body ); 428 428 Statement * build_finally( StatementNode * stmt ); 429 429 Statement * build_compound( StatementNode * first ); -
src/Parser/StatementNode.cc
rfc72696c r17cb385 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // StatementNode.cc -- 7 // StatementNode.cc -- Transform from parse data-structures to AST data-structures, usually deleting the parse 8 // data-structure after the transformation. 8 9 // 9 10 // Author : Rodolfo G. Esteves 10 11 // Created On : Sat May 16 14:59:41 2015 11 12 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jan 29 09:45:51202213 // Update Count : 38413 // Last Modified On : Wed Feb 2 12:27:58 2022 14 // Update Count : 424 14 15 // 15 16 … … 63 64 // convert from StatementNode list to Statement list 64 65 StatementNode * node = dynamic_cast< StatementNode * >(prev); 65 std::list< Statement * > stmts;66 list< Statement * > stmts; 66 67 buildMoveList( stmt, stmts ); 67 68 // splice any new Statements to end of current Statements … … 78 79 } // build_expr 79 80 80 Expression * build_if_control( CondCtl * ctl, std::list< Statement * > & init ) {81 Expression * build_if_control( CondCtl * ctl, list< Statement * > & init ) { 81 82 if ( ctl->init != 0 ) { 82 83 buildMoveList( ctl->init, init ); … … 100 101 } // build_if_control 101 102 102 Statement * build_if( CondCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ) { 103 Statement * thenb, * elseb = nullptr; 104 std::list< Statement * > branches; 105 buildMoveList< Statement, StatementNode >( then_stmt, branches ); 106 assert( branches.size() == 1 ); 107 thenb = branches.front(); 108 109 if ( else_stmt ) { 110 std::list< Statement * > branches; 111 buildMoveList< Statement, StatementNode >( else_stmt, branches ); 112 assert( branches.size() == 1 ); 113 elseb = branches.front(); 114 } // if 115 116 std::list< Statement * > init; 117 Expression * cond = build_if_control( ctl, init ); 118 return new IfStmt( cond, thenb, elseb, init ); 103 Statement * build_if( CondCtl * ctl, StatementNode * then, StatementNode * else_ ) { 104 list< Statement * > astinit; // maybe empty 105 Expression * astcond = build_if_control( ctl, astinit ); // ctl deleted, cond/init set 106 107 Statement * astthen, * astelse = nullptr; 108 list< Statement * > aststmt; 109 buildMoveList< Statement, StatementNode >( then, aststmt ); 110 assert( aststmt.size() == 1 ); 111 astthen = aststmt.front(); 112 113 if ( else_ ) { 114 list< Statement * > aststmt; 115 buildMoveList< Statement, StatementNode >( else_, aststmt ); 116 assert( aststmt.size() == 1 ); 117 astelse = aststmt.front(); 118 } // if 119 120 return new IfStmt( astcond, astthen, astelse, astinit ); 119 121 } // build_if 120 122 121 123 Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt ) { 122 std::list< Statement * > branches;123 buildMoveList< Statement, StatementNode >( stmt, branches);124 if ( ! isSwitch ) { 125 for ( Statement * stmt : branches) {124 list< Statement * > aststmt; 125 buildMoveList< Statement, StatementNode >( stmt, aststmt ); 126 if ( ! isSwitch ) { // choose statement 127 for ( Statement * stmt : aststmt ) { 126 128 CaseStmt * caseStmt = strict_dynamic_cast< CaseStmt * >( stmt ); 127 129 if ( ! caseStmt->stmts.empty() ) { // code after "case" => end of case list … … 131 133 } // for 132 134 } // if 133 // branches.size() == 0 for switch (...) {}, i.e., no declaration or statements134 return new SwitchStmt( maybeMoveBuild< Expression >(ctl), branches);135 // aststmt.size() == 0 for switch (...) {}, i.e., no declaration or statements 136 return new SwitchStmt( maybeMoveBuild< Expression >(ctl), aststmt ); 135 137 } // build_switch 136 138 137 139 Statement * build_case( ExpressionNode * ctl ) { 138 std::list< Statement * > branches; 139 return new CaseStmt( maybeMoveBuild< Expression >(ctl), branches ); 140 return new CaseStmt( maybeMoveBuild< Expression >(ctl), {} ); // no init 140 141 } // build_case 141 142 142 143 Statement * build_default() { 143 std::list< Statement * > branches; 144 return new CaseStmt( nullptr, branches, true ); 144 return new CaseStmt( nullptr, {}, true ); // no init 145 145 } // build_default 146 146 147 Statement * build_while( CondCtl * ctl, StatementNode * stmt ) { 148 std::list< Statement * > branches; 149 buildMoveList< Statement, StatementNode >( stmt, branches ); 150 assert( branches.size() == 1 ); 151 152 std::list< Statement * > init; 153 Expression * cond = build_if_control( ctl, init ); 154 return new WhileStmt( cond, branches.front(), init, false ); 147 Statement * build_while( CondCtl * ctl, StatementNode * stmt, StatementNode * else_ ) { 148 list< Statement * > astinit; // maybe empty 149 Expression * astcond = build_if_control( ctl, astinit ); // ctl deleted, cond/init set 150 151 list< Statement * > aststmt; // loop body, compound created if empty 152 buildMoveList< Statement, StatementNode >( stmt, aststmt ); 153 assert( aststmt.size() == 1 ); 154 155 list< Statement * > astelse; // else clause, maybe empty 156 buildMoveList< Statement, StatementNode >( else_, astelse ); 157 158 return new WhileDoStmt( astcond, aststmt.front(), astelse.front(), astinit, false ); 155 159 } // build_while 156 160 157 Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt ) { 158 std::list< Statement * > branches; 159 buildMoveList< Statement, StatementNode >( stmt, branches ); 160 assert( branches.size() == 1 ); 161 162 std::list< Statement * > init; 163 return new WhileStmt( notZeroExpr( maybeMoveBuild< Expression >(ctl) ), branches.front(), init, true ); 161 Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt, StatementNode * else_ ) { 162 list< Statement * > aststmt; // loop body, compound created if empty 163 buildMoveList< Statement, StatementNode >( stmt, aststmt ); 164 assert( aststmt.size() == 1 ); // compound created if empty 165 166 list< Statement * > astelse; // else clause, maybe empty 167 buildMoveList< Statement, StatementNode >( else_, astelse ); 168 169 // do-while cannot have declarations in the contitional, so init is always empty 170 return new WhileDoStmt( notZeroExpr( maybeMoveBuild< Expression >(ctl) ), aststmt.front(), astelse.front(), {}, true ); 164 171 } // build_do_while 165 172 166 Statement * build_for( ForCtrl * forctl, StatementNode * stmt ) { 167 std::list< Statement * > branches; 168 buildMoveList< Statement, StatementNode >( stmt, branches ); 169 assert( branches.size() == 1 ); 170 171 std::list< Statement * > init; 172 if ( forctl->init != 0 ) { 173 buildMoveList( forctl->init, init ); 174 } // if 175 176 Expression * cond = 0; 177 if ( forctl->condition != 0 ) 178 cond = notZeroExpr( maybeMoveBuild< Expression >(forctl->condition) ); 179 180 Expression * incr = 0; 181 if ( forctl->change != 0 ) 182 incr = maybeMoveBuild< Expression >(forctl->change); 183 173 Statement * build_for( ForCtrl * forctl, StatementNode * stmt, StatementNode * else_ ) { 174 list< Statement * > astinit; // maybe empty 175 buildMoveList( forctl->init, astinit ); 176 177 Expression * astcond = nullptr; // maybe empty 178 astcond = notZeroExpr( maybeMoveBuild< Expression >(forctl->condition) ); 179 180 Expression * astincr = nullptr; // maybe empty 181 astincr = maybeMoveBuild< Expression >(forctl->change); 184 182 delete forctl; 185 return new ForStmt( init, cond, incr, branches.front() ); 183 184 list< Statement * > aststmt; // loop body, compound created if empty 185 buildMoveList< Statement, StatementNode >( stmt, aststmt ); 186 assert( aststmt.size() == 1 ); 187 188 list< Statement * > astelse; // else clause, maybe empty 189 buildMoveList< Statement, StatementNode >( else_, astelse ); 190 191 return new ForStmt( astinit, astcond, astincr, aststmt.front(), astelse.front() ); 186 192 } // build_for 187 193 … … 191 197 } // build_branch 192 198 193 Statement * build_branch( st d::string * identifier, BranchStmt::Type kind ) {199 Statement * build_branch( string * identifier, BranchStmt::Type kind ) { 194 200 Statement * ret = new BranchStmt( * identifier, kind ); 195 201 delete identifier; // allocated by lexer … … 202 208 203 209 Statement * build_return( ExpressionNode * ctl ) { 204 std::list< Expression * > exps;210 list< Expression * > exps; 205 211 buildMoveList( ctl, exps ); 206 212 return new ReturnStmt( exps.size() > 0 ? exps.back() : nullptr ); … … 208 214 209 215 Statement * build_throw( ExpressionNode * ctl ) { 210 std::list< Expression * > exps;216 list< Expression * > exps; 211 217 buildMoveList( ctl, exps ); 212 assertf( exps.size() < 2, " This means we are leaking memory");218 assertf( exps.size() < 2, "CFA internal error: leaking memory" ); 213 219 return new ThrowStmt( ThrowStmt::Terminate, !exps.empty() ? exps.back() : nullptr ); 214 220 } // build_throw 215 221 216 222 Statement * build_resume( ExpressionNode * ctl ) { 217 std::list< Expression * > exps;223 list< Expression * > exps; 218 224 buildMoveList( ctl, exps ); 219 assertf( exps.size() < 2, " This means we are leaking memory");225 assertf( exps.size() < 2, "CFA internal error: leaking memory" ); 220 226 return new ThrowStmt( ThrowStmt::Resume, !exps.empty() ? exps.back() : nullptr ); 221 227 } // build_resume … … 227 233 } // build_resume_at 228 234 229 Statement * build_try( StatementNode * try_ stmt, StatementNode * catch_stmt, StatementNode * finally_stmt) {230 std::list< CatchStmt * > branches;231 buildMoveList< CatchStmt, StatementNode >( catch_ stmt, branches);232 CompoundStmt * tryBlock = strict_dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(try_ stmt));233 FinallyStmt * finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_ stmt) );234 return new TryStmt( tryBlock, branches, finallyBlock );235 Statement * build_try( StatementNode * try_, StatementNode * catch_, StatementNode * finally_ ) { 236 list< CatchStmt * > aststmt; 237 buildMoveList< CatchStmt, StatementNode >( catch_, aststmt ); 238 CompoundStmt * tryBlock = strict_dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(try_)); 239 FinallyStmt * finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_) ); 240 return new TryStmt( tryBlock, aststmt, finallyBlock ); 235 241 } // build_try 236 242 237 243 Statement * build_catch( CatchStmt::Kind kind, DeclarationNode * decl, ExpressionNode * cond, StatementNode * body ) { 238 std::list< Statement * > branches;239 buildMoveList< Statement, StatementNode >( body, branches);240 assert( branches.size() == 1 );241 return new CatchStmt( kind, maybeMoveBuild< Declaration >(decl), maybeMoveBuild< Expression >(cond), branches.front() );244 list< Statement * > aststmt; 245 buildMoveList< Statement, StatementNode >( body, aststmt ); 246 assert( aststmt.size() == 1 ); 247 return new CatchStmt( kind, maybeMoveBuild< Declaration >(decl), maybeMoveBuild< Expression >(cond), aststmt.front() ); 242 248 } // build_catch 243 249 244 250 Statement * build_finally( StatementNode * stmt ) { 245 std::list< Statement * > branches;246 buildMoveList< Statement, StatementNode >( stmt, branches);247 assert( branches.size() == 1 );248 return new FinallyStmt( dynamic_cast< CompoundStmt * >( branches.front() ) );251 list< Statement * > aststmt; 252 buildMoveList< Statement, StatementNode >( stmt, aststmt ); 253 assert( aststmt.size() == 1 ); 254 return new FinallyStmt( dynamic_cast< CompoundStmt * >( aststmt.front() ) ); 249 255 } // build_finally 250 256 … … 254 260 node->type = type; 255 261 256 std::list< Statement * > stmts;262 list< Statement * > stmts; 257 263 buildMoveList< Statement, StatementNode >( then, stmts ); 258 264 if(!stmts.empty()) { … … 319 325 } // build_waitfor_timeout 320 326 321 WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when, StatementNode * else_ stmt, ExpressionNode * else_when ) {327 WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when, StatementNode * else_, ExpressionNode * else_when ) { 322 328 auto node = new WaitForStmt(); 323 329 … … 326 332 node->timeout.condition = notZeroExpr( maybeMoveBuild<Expression>( when ) ); 327 333 328 node->orelse.statement = maybeMoveBuild<Statement >( else_ stmt);334 node->orelse.statement = maybeMoveBuild<Statement >( else_ ); 329 335 node->orelse.condition = notZeroExpr( maybeMoveBuild<Expression>( else_when ) ); 330 336 … … 333 339 334 340 Statement * build_with( ExpressionNode * exprs, StatementNode * stmt ) { 335 std::list< Expression * > e;341 list< Expression * > e; 336 342 buildMoveList( exprs, e ); 337 343 Statement * s = maybeMoveBuild<Statement>( stmt ); … … 361 367 362 368 Statement * build_asm( bool voltile, Expression * instruction, ExpressionNode * output, ExpressionNode * input, ExpressionNode * clobber, LabelNode * gotolabels ) { 363 std::list< Expression * > out, in;364 std::list< ConstantExpr * > clob;369 list< Expression * > out, in; 370 list< ConstantExpr * > clob; 365 371 366 372 buildMoveList( output, out ); … … 375 381 376 382 Statement * build_mutex( ExpressionNode * exprs, StatementNode * stmt ) { 377 std::list< Expression * > expList;383 list< Expression * > expList; 378 384 buildMoveList( exprs, expList ); 379 385 Statement * body = maybeMoveBuild<Statement>( stmt ); -
src/Parser/parser.yy
rfc72696c r17cb385 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Jan 30 09:41:13 202213 // Update Count : 516 512 // Last Modified On : Tue Feb 1 11:06:13 2022 13 // Update Count : 5167 14 14 // 15 15 … … 1197 1197 { $$ = new StatementNode( build_while( $3, maybe_build_compound( $5 ) ) ); } 1198 1198 | WHILE '(' conditional_declaration ')' statement ELSE statement // CFA 1199 { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; } 1199 // { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; } 1200 { $$ = new StatementNode( build_while( $3, maybe_build_compound( $5 ), $7 ) ); } 1200 1201 | DO statement WHILE '(' ')' ';' // CFA => do while( 1 ) 1201 1202 { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), maybe_build_compound( $2 ) ) ); } … … 1203 1204 { $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 ) ) ); } 1204 1205 | DO statement WHILE '(' comma_expression ')' ELSE statement // CFA 1205 { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; } 1206 // { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; } 1207 { $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 ), $8 ) ); } 1206 1208 | FOR '(' ')' statement // CFA => for ( ;; ) 1207 1209 { $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), maybe_build_compound( $4 ) ) ); } … … 1209 1211 { $$ = new StatementNode( build_for( $3, maybe_build_compound( $5 ) ) ); } 1210 1212 | FOR '(' for_control_expression_list ')' statement ELSE statement // CFA 1211 { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; } 1213 // { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; } 1214 { $$ = new StatementNode( build_for( $3, maybe_build_compound( $5 ), $7 ) ); } 1212 1215 ; 1213 1216 -
src/ResolvExpr/Resolver.cc
rfc72696c r17cb385 9 9 // Author : Aaron B. Moss 10 10 // Created On : Sun May 17 12:17:01 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Fri Mar 27 11:58:00 202013 // Update Count : 24 211 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Feb 1 16:27:14 2022 13 // Update Count : 245 14 14 // 15 15 … … 80 80 void previsit( AsmStmt * asmStmt ); 81 81 void previsit( IfStmt * ifStmt ); 82 void previsit( While Stmt * whileStmt );82 void previsit( WhileDoStmt * whileDoStmt ); 83 83 void previsit( ForStmt * forStmt ); 84 84 void previsit( SwitchStmt * switchStmt ); … … 502 502 } 503 503 504 void Resolver_old::previsit( While Stmt * whileStmt ) {505 findIntegralExpression( while Stmt->condition, indexer );504 void Resolver_old::previsit( WhileDoStmt * whileDoStmt ) { 505 findIntegralExpression( whileDoStmt->condition, indexer ); 506 506 } 507 507 … … 572 572 573 573 void Resolver_old::previsit( CatchStmt * catchStmt ) { 574 // Until we are very sure this invarent (ifs that move between passes have then Part)574 // Until we are very sure this invarent (ifs that move between passes have then) 575 575 // holds, check it. This allows a check for when to decode the mangling. 576 576 if ( IfStmt * ifStmt = dynamic_cast<IfStmt *>( catchStmt->body ) ) { 577 assert( ifStmt->then Part);577 assert( ifStmt->then ); 578 578 } 579 579 // Encode the catchStmt so the condition can see the declaration. … … 588 588 // Decode the catchStmt so everything is stored properly. 589 589 IfStmt * ifStmt = dynamic_cast<IfStmt *>( catchStmt->body ); 590 if ( nullptr != ifStmt && nullptr == ifStmt->then Part) {590 if ( nullptr != ifStmt && nullptr == ifStmt->then ) { 591 591 assert( ifStmt->condition ); 592 assert( ifStmt->else Part);592 assert( ifStmt->else_ ); 593 593 catchStmt->cond = ifStmt->condition; 594 catchStmt->body = ifStmt->else Part;594 catchStmt->body = ifStmt->else_; 595 595 ifStmt->condition = nullptr; 596 ifStmt->else Part= nullptr;596 ifStmt->else_ = nullptr; 597 597 delete ifStmt; 598 598 } … … 1272 1272 const ast::AsmStmt * previsit( const ast::AsmStmt * ); 1273 1273 const ast::IfStmt * previsit( const ast::IfStmt * ); 1274 const ast::While Stmt * previsit( const ast::WhileStmt * );1274 const ast::WhileDoStmt * previsit( const ast::WhileDoStmt * ); 1275 1275 const ast::ForStmt * previsit( const ast::ForStmt * ); 1276 1276 const ast::SwitchStmt * previsit( const ast::SwitchStmt * ); … … 1581 1581 } 1582 1582 1583 const ast::While Stmt * Resolver_new::previsit( const ast::WhileStmt * whileStmt ) {1583 const ast::WhileDoStmt * Resolver_new::previsit( const ast::WhileDoStmt * whileDoStmt ) { 1584 1584 return ast::mutate_field( 1585 while Stmt, &ast::WhileStmt::cond, findIntegralExpression( whileStmt->cond, symtab ) );1585 whileDoStmt, &ast::WhileDoStmt::cond, findIntegralExpression( whileDoStmt->cond, symtab ) ); 1586 1586 } 1587 1587 … … 1669 1669 1670 1670 const ast::CatchStmt * Resolver_new::previsit( const ast::CatchStmt * catchStmt ) { 1671 // Until we are very sure this invarent (ifs that move between passes have then Part)1671 // Until we are very sure this invarent (ifs that move between passes have then) 1672 1672 // holds, check it. This allows a check for when to decode the mangling. 1673 1673 if ( auto ifStmt = catchStmt->body.as<ast::IfStmt>() ) { 1674 assert( ifStmt->then Part);1674 assert( ifStmt->then ); 1675 1675 } 1676 1676 // Encode the catchStmt so the condition can see the declaration. … … 1687 1687 // Decode the catchStmt so everything is stored properly. 1688 1688 const ast::IfStmt * ifStmt = catchStmt->body.as<ast::IfStmt>(); 1689 if ( nullptr != ifStmt && nullptr == ifStmt->then Part) {1689 if ( nullptr != ifStmt && nullptr == ifStmt->then ) { 1690 1690 assert( ifStmt->cond ); 1691 assert( ifStmt->else Part);1691 assert( ifStmt->else_ ); 1692 1692 ast::CatchStmt * stmt = ast::mutate( catchStmt ); 1693 1693 stmt->cond = ifStmt->cond; 1694 stmt->body = ifStmt->else Part;1694 stmt->body = ifStmt->else_; 1695 1695 // ifStmt should be implicately deleted here. 1696 1696 return stmt; -
src/SynTree/Mutator.h
rfc72696c r17cb385 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 12 18:35:36 202113 // Update Count : 1812 // Last Modified On : Tue Feb 1 09:26:49 2022 13 // Update Count : 20 14 14 // 15 15 #pragma once … … 42 42 virtual Statement * mutate( DirectiveStmt * dirStmt ) = 0; 43 43 virtual Statement * mutate( IfStmt * ifStmt ) = 0; 44 virtual Statement * mutate( While Stmt * whileStmt ) = 0;44 virtual Statement * mutate( WhileDoStmt * whileDoStmt ) = 0; 45 45 virtual Statement * mutate( ForStmt * forStmt ) = 0; 46 46 virtual Statement * mutate( SwitchStmt * switchStmt ) = 0; -
src/SynTree/Statement.cc
rfc72696c r17cb385 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Mon Jan 20 16:03:00 202013 // Update Count : 7111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 2 11:55:19 2022 13 // Update Count : 80 14 14 // 15 15 … … 145 145 } 146 146 147 IfStmt::IfStmt( Expression * condition, Statement * then Part, Statement * elsePart, std::list<Statement *> initialization ):148 Statement(), condition( condition ), then Part( thenPart ), elsePart( elsePart), initialization( initialization ) {}147 IfStmt::IfStmt( Expression * condition, Statement * then, Statement * else_, std::list<Statement *> initialization ): 148 Statement(), condition( condition ), then( then ), else_( else_ ), initialization( initialization ) {} 149 149 150 150 IfStmt::IfStmt( const IfStmt & other ) : 151 Statement( other ), condition( maybeClone( other.condition ) ), then Part( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart) ) {151 Statement( other ), condition( maybeClone( other.condition ) ), then( maybeClone( other.then ) ), else_( maybeClone( other.else_ ) ) { 152 152 cloneAll( other.initialization, initialization ); 153 153 } … … 156 156 deleteAll( initialization ); 157 157 delete condition; 158 delete then Part;159 delete else Part;158 delete then; 159 delete else_; 160 160 } 161 161 … … 177 177 178 178 os << indent+1; 179 then Part->print( os, indent+1 );180 181 if ( else Part!= nullptr ) {179 then->print( os, indent+1 ); 180 181 if ( else_ != nullptr ) { 182 182 os << indent << "... else: " << endl; 183 183 os << indent+1; 184 else Part->print( os, indent+1 );184 else_->print( os, indent+1 ); 185 185 } // if 186 186 } … … 246 246 } 247 247 248 WhileStmt::WhileStmt( Expression * condition, Statement * body, std::list< Statement * > & initialization, bool isDoWhile ): 249 Statement(), condition( condition), body( body), initialization( initialization ), isDoWhile( isDoWhile) { 250 } 251 252 WhileStmt::WhileStmt( const WhileStmt & other ): 248 WhileDoStmt::WhileDoStmt( Expression * condition, Statement * body, const std::list< Statement * > & initialization, bool isDoWhile ): 249 Statement(), condition( condition ), body( body ), else_( nullptr ), initialization( initialization ), isDoWhile( isDoWhile) { 250 } 251 252 WhileDoStmt::WhileDoStmt( Expression * condition, Statement * body, Statement * else_, const std::list< Statement * > & initialization, bool isDoWhile ): 253 Statement(), condition( condition), body( body ), else_( else_ ), initialization( initialization ), isDoWhile( isDoWhile) { 254 } 255 256 WhileDoStmt::WhileDoStmt( const WhileDoStmt & other ): 253 257 Statement( other ), condition( maybeClone( other.condition ) ), body( maybeClone( other.body ) ), isDoWhile( other.isDoWhile ) { 254 258 } 255 259 256 While Stmt::~WhileStmt() {260 WhileDoStmt::~WhileDoStmt() { 257 261 delete body; 258 262 delete condition; 259 263 } 260 264 261 void While Stmt::print( std::ostream & os, Indenter indent ) const {265 void WhileDoStmt::print( std::ostream & os, Indenter indent ) const { 262 266 os << "While on condition: " << endl ; 263 267 condition->print( os, indent+1 ); … … 268 272 } 269 273 270 ForStmt::ForStmt( std::list<Statement *> initialization, Expression * condition, Expression * increment, Statement * body ):271 Statement(), initialization( initialization ), condition( condition ), increment( increment ), body( body ) {274 ForStmt::ForStmt( std::list<Statement *> initialization, Expression * condition, Expression * increment, Statement * body, Statement * else_ ): 275 Statement(), initialization( initialization ), condition( condition ), increment( increment ), body( body ), else_( else_ ) { 272 276 } 273 277 274 278 ForStmt::ForStmt( const ForStmt & other ): 275 Statement( other ), condition( maybeClone( other.condition ) ), increment( maybeClone( other.increment ) ), body( maybeClone( other.body ) ) {279 Statement( other ), condition( maybeClone( other.condition ) ), increment( maybeClone( other.increment ) ), body( maybeClone( other.body ) ), else_( maybeClone( other.else_ ) ) { 276 280 cloneAll( other.initialization, initialization ); 277 281 … … 283 287 delete increment; 284 288 delete body; 289 delete else_; 285 290 } 286 291 … … 311 316 os << "\n" << indent << "... with body: \n" << indent+1; 312 317 body->print( os, indent+1 ); 318 } 319 320 if ( else_ != nullptr ) { 321 os << "\n" << indent << "... with body: \n" << indent+1; 322 else_->print( os, indent+1 ); 313 323 } 314 324 os << endl; -
src/SynTree/Statement.h
rfc72696c r17cb385 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jan 10 14:13:24 202013 // Update Count : 8512 // Last Modified On : Wed Feb 2 11:49:17 2022 13 // Update Count : 94 14 14 // 15 15 … … 148 148 public: 149 149 Expression * condition; 150 Statement * then Part;151 Statement * else Part;150 Statement * then; 151 Statement * else_; 152 152 std::list<Statement *> initialization; 153 153 154 IfStmt( Expression * condition, Statement * then Part, Statement * elsePart,154 IfStmt( Expression * condition, Statement * then, Statement * else_, 155 155 std::list<Statement *> initialization = std::list<Statement *>() ); 156 156 IfStmt( const IfStmt & other ); … … 160 160 Expression * get_condition() { return condition; } 161 161 void set_condition( Expression * newValue ) { condition = newValue; } 162 Statement * get_then Part() { return thenPart; }163 void set_then Part( Statement * newValue ) { thenPart= newValue; }164 Statement * get_else Part() { return elsePart; }165 void set_else Part( Statement * newValue ) { elsePart= newValue; }162 Statement * get_then() { return then; } 163 void set_then( Statement * newValue ) { then = newValue; } 164 Statement * get_else() { return else_; } 165 void set_else( Statement * newValue ) { else_ = newValue; } 166 166 167 167 virtual IfStmt * clone() const override { return new IfStmt( *this ); } … … 225 225 }; 226 226 227 class While Stmt : public Statement {227 class WhileDoStmt : public Statement { 228 228 public: 229 229 Expression * condition; 230 230 Statement * body; 231 Statement * else_; 231 232 std::list<Statement *> initialization; 232 233 bool isDoWhile; 233 234 234 WhileStmt( Expression * condition, Statement * body, std::list<Statement *> & initialization, bool isDoWhile = false ); 235 WhileStmt( const WhileStmt & other ); 236 virtual ~WhileStmt(); 235 WhileDoStmt( Expression * condition, Statement * body, const std::list<Statement *> & initialization, bool isDoWhile = false ); 236 WhileDoStmt( Expression * condition, Statement * body, Statement * else_, const std::list<Statement *> & initialization, bool isDoWhile = false ); 237 WhileDoStmt( const WhileDoStmt & other ); 238 virtual ~WhileDoStmt(); 237 239 238 240 Expression * get_condition() { return condition; } … … 243 245 void set_isDoWhile( bool newValue ) { isDoWhile = newValue; } 244 246 245 virtual While Stmt * clone() const override { return new WhileStmt( *this ); }247 virtual WhileDoStmt * clone() const override { return new WhileDoStmt( *this ); } 246 248 virtual void accept( Visitor & v ) override { v.visit( this ); } 247 249 virtual void accept( Visitor & v ) const override { v.visit( this ); } … … 256 258 Expression * increment; 257 259 Statement * body; 258 259 ForStmt( std::list<Statement *> initialization, Expression * condition = nullptr, Expression * increment = nullptr, Statement * body = nullptr ); 260 Statement * else_; 261 262 ForStmt( std::list<Statement *> initialization, Expression * condition = nullptr, Expression * increment = nullptr, Statement * body = nullptr, Statement * else_ = nullptr ); 260 263 ForStmt( const ForStmt & other ); 261 264 virtual ~ForStmt(); -
src/SynTree/SynTree.h
rfc72696c r17cb385 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 12 18:56:44 202113 // Update Count : 1 312 // Last Modified On : Tue Feb 1 09:22:33 2022 13 // Update Count : 14 14 14 // 15 15 … … 45 45 class DirectiveStmt; 46 46 class IfStmt; 47 class While Stmt;47 class WhileDoStmt; 48 48 class ForStmt; 49 49 class SwitchStmt; -
src/SynTree/Visitor.h
rfc72696c r17cb385 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 12 18:35:35 202113 // Update Count : 1 512 // Last Modified On : Tue Feb 1 09:26:57 2022 13 // Update Count : 17 14 14 // 15 15 … … 60 60 virtual void visit( IfStmt * node ) { visit( const_cast<const IfStmt *>(node) ); } 61 61 virtual void visit( const IfStmt * ifStmt ) = 0; 62 virtual void visit( While Stmt * node ) { visit( const_cast<const WhileStmt *>(node) ); }63 virtual void visit( const While Stmt * whileStmt ) = 0;62 virtual void visit( WhileDoStmt * node ) { visit( const_cast<const WhileDoStmt *>(node) ); } 63 virtual void visit( const WhileDoStmt * whileDoStmt ) = 0; 64 64 virtual void visit( ForStmt * node ) { visit( const_cast<const ForStmt *>(node) ); } 65 65 virtual void visit( const ForStmt * forStmt ) = 0;
Note: See TracChangeset
for help on using the changeset viewer.