Changeset 145f1fc
- Timestamp:
- Jul 15, 2015, 2:59:57 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 1ab4ce2, 2794fff, e45215c
- Parents:
- 85c4ef0
- Location:
- src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r85c4ef0 r145f1fc 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Fri Jun 26 16:52:58201513 // Update Count : 1 4411 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jul 15 14:47:42 2015 13 // Update Count : 177 14 14 // 15 15 … … 38 38 int CodeGenerator::tabsize = 4; 39 39 40 // the kinds of statements that would ideally be separated by morewhitespace40 // the kinds of statements that would ideally be followed by whitespace 41 41 bool wantSpacing( Statement * stmt) { 42 42 return dynamic_cast< IfStmt * >( stmt ) || dynamic_cast< CompoundStmt * >( stmt ) || … … 588 588 589 589 void CodeGenerator::visit( ForStmt *forStmt ) { 590 output << "for ("; 591 592 if ( forStmt->get_initialization() != 0 ) 593 forStmt->get_initialization()->accept( *this ); 594 else 595 output << ";"; 596 590 // initialization is always hoisted, so don't 591 // bother doing anything with that 592 output << "for (;"; 593 597 594 if ( forStmt->get_condition() != 0 ) 598 595 forStmt->get_condition()->accept( *this ); -
src/ControlStruct/ForExprMutator.cc
r85c4ef0 r145f1fc 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue May 19 15:31:47201513 // Update Count : 211 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Jul 14 12:14:44 2015 13 // Update Count : 10 14 14 // 15 15 … … 22 22 // recurse down all nest for loops to hoist any initializer declarations to make them C89 (rather than C99) 23 23 forStmt->set_body( forStmt->get_body()->acceptMutator( *this ) ); 24 if ( DeclStmt *decl = dynamic_cast< DeclStmt * > ( forStmt->get_initialization() ) ) {25 // create compound statement, move initializer declaration outside, leave _for_ as-is26 CompoundStmt *block = new CompoundStmt( std::list< Label >() );27 std::list<Statement *> &stmts = block->get_kids();28 24 29 stmts.push_back( decl ); 30 forStmt->set_initialization( 0 ); 31 stmts.push_back( forStmt ); 25 std::list<Statement *> &init = forStmt->get_initialization(); 26 if ( init.size() == 0 ) { 27 return forStmt; 28 } // if 32 29 33 return block; 34 } // if 30 // create compound statement, move initializers outside, leave _for_ as-is 31 CompoundStmt *block = new CompoundStmt( std::list< Label >() ); 32 std::list<Statement *> &stmts = block->get_kids(); 33 for ( std::list<Statement *>::iterator it = init.begin(); it != init.end(); ++it ) { 34 stmts.push_back( *it ); 35 } // for 36 37 // add for to the new block 38 stmts.push_back( forStmt ); 39 forStmt->set_initialization( std::list<Statement *>() ); 40 return block; 35 41 36 42 return forStmt; -
src/ControlStruct/Mutate.cc
r85c4ef0 r145f1fc 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Ju n 03 23:08:43201513 // Update Count : 512 // Last Modified On : Wed Jul 15 14:50:04 2015 13 // Update Count : 7 14 14 // 15 15 … … 36 36 namespace ControlStruct { 37 37 void mutate( std::list< Declaration * > translationUnit ) { 38 // ForExprMutator formut; 38 // hoist initialization out of for statements 39 ForExprMutator formut; 39 40 40 41 // normalizes label definitions and generates multi-level … … 51 52 // LabelTypeChecker lbl; 52 53 53 //mutateAll( translationUnit, formut );54 mutateAll( translationUnit, formut ); 54 55 acceptAll( translationUnit, lfix ); 55 56 mutateAll( translationUnit, chmut ); -
src/GenPoly/PolyMutator.cc
r85c4ef0 r145f1fc 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue May 19 07:45:50201513 // Update Count : 111 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jul 15 14:50:58 2015 13 // Update Count : 3 14 14 // 15 15 … … 92 92 Statement * PolyMutator::mutate(ForStmt *forStmt) { 93 93 forStmt->set_body( mutateStatement( forStmt->get_body() ) ); 94 forStmt->set_initialization( maybeMutate( forStmt->get_initialization(), *this ));94 mutateAll( forStmt->get_initialization(), *this ); 95 95 forStmt->set_condition( mutateExpression( forStmt->get_condition() ) ); 96 96 forStmt->set_increment( mutateExpression( forStmt->get_increment() ) ); -
src/Parser/StatementNode.cc
r85c4ef0 r145f1fc 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 14:59:41 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sat Jun 6 23:25:41201513 // Update Count : 1911 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Jul 14 12:20:44 2015 13 // Update Count : 21 14 14 // 15 15 … … 271 271 assert( ctl != 0 ); 272 272 273 Statement *stmt = 0; 274 if ( ctl->get_init() != 0 ) 275 stmt = ctl->get_init()->build(); 273 std::list<Statement *> init; 274 if ( ctl->get_init() != 0 ) { 275 buildList( ctl->get_init(), init ); 276 } 276 277 277 278 Expression *cond = 0; … … 283 284 incr = ctl->get_change()->build(); 284 285 285 return new ForStmt( labs, stmt, cond, incr, branches.front() );286 return new ForStmt( labs, init, cond, incr, branches.front() ); 286 287 } 287 288 case Switch: -
src/ResolvExpr/Resolver.cc
r85c4ef0 r145f1fc 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 12:17:01 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Fri Jul 3 16:18:20201513 // Update Count : 1 5911 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jul 15 14:54:04 2015 13 // Update Count : 167 14 14 // 15 15 … … 226 226 227 227 void Resolver::visit( ForStmt *forStmt ) { 228 // SymTab::Indexer::visit( forStmt ); 229 Expression *newExpr; 230 // for statements introduce a level of scope 231 enterScope(); 232 maybeAccept( forStmt->get_initialization(), *this ); 228 SymTab::Indexer::visit( forStmt ); 229 233 230 if ( forStmt->get_condition() ) { 234 newExpr = findSingleExpression( forStmt->get_condition(), *this );231 Expression * newExpr = findSingleExpression( forStmt->get_condition(), *this ); 235 232 delete forStmt->get_condition(); 236 233 forStmt->set_condition( newExpr ); 237 234 } // if 238 235 239 236 if ( forStmt->get_increment() ) { 240 newExpr = findVoidExpression( forStmt->get_increment(), *this );237 Expression * newExpr = findVoidExpression( forStmt->get_increment(), *this ); 241 238 delete forStmt->get_increment(); 242 239 forStmt->set_increment( newExpr ); 243 240 } // if 244 245 maybeAccept( forStmt->get_condition(), *this );246 maybeAccept( forStmt->get_increment(), *this );247 maybeAccept( forStmt->get_body(), *this );248 leaveScope();249 241 } 250 242 -
src/SymTab/AddVisit.h
r85c4ef0 r145f1fc 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 16:14:32 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sun May 17 16:16:38201513 // Update Count : 311 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Jul 14 12:26:17 2015 13 // Update Count : 4 14 14 // 15 15 … … 57 57 inline void addVisit(ForStmt *forStmt, Visitor &visitor) { 58 58 addVisitStatement( forStmt->get_body(), visitor ); 59 maybeAccept( forStmt->get_initialization(), visitor );59 acceptAll( forStmt->get_initialization(), visitor ); 60 60 maybeAccept( forStmt->get_condition(), visitor ); 61 61 maybeAccept( forStmt->get_increment(), visitor ); -
src/SymTab/Validate.cc
r85c4ef0 r145f1fc 10 10 // Created On : Sun May 17 21:50:04 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Mon Jul 13 14:38:19201513 // Update Count : 18 412 // Last Modified On : Tue Jul 14 12:27:54 2015 13 // Update Count : 186 14 14 // 15 15 … … 530 530 init->get_args().push_back( new NameExpr( "0" ) ); 531 531 Statement *initStmt = new ExprStmt( noLabels, init ); 532 532 std::list<Statement *> initList; 533 initList.push_back( initStmt ); 534 533 535 UntypedExpr *cond = new UntypedExpr( new NameExpr( "?<?" ) ); 534 536 cond->get_args().push_back( new VariableExpr( index ) ); … … 555 557 assignExpr->get_args().push_back( srcIndex ); 556 558 557 *out++ = new ForStmt( noLabels, init Stmt, cond, inc, new ExprStmt( noLabels, assignExpr ) );559 *out++ = new ForStmt( noLabels, initList, cond, inc, new ExprStmt( noLabels, assignExpr ) ); 558 560 } 559 561 -
src/SynTree/Mutator.cc
r85c4ef0 r145f1fc 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Mon May 18 10:10:46201513 // Update Count : 111 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Jul 14 12:31:39 2015 13 // Update Count : 2 14 14 // 15 15 … … 109 109 110 110 Statement *Mutator::mutate( ForStmt *forStmt ) { 111 forStmt->set_initialization( maybeMutate( forStmt->get_initialization(), *this ));111 mutateAll( forStmt->get_initialization(), *this ); 112 112 forStmt->set_condition( maybeMutate( forStmt->get_condition(), *this ) ); 113 113 forStmt->set_increment( maybeMutate( forStmt->get_increment(), *this ) ); -
src/SynTree/Statement.cc
r85c4ef0 r145f1fc 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Mon Jun 29 17:37:10 201513 // Update Count : 2 211 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jul 15 14:57:40 2015 13 // Update Count : 27 14 14 // 15 15 … … 192 192 } 193 193 194 ForStmt::ForStmt( std::list<Label> labels, Statement *initialization_, Expression *condition_, Expression *increment_, Statement *body_ ):194 ForStmt::ForStmt( std::list<Label> labels, std::list<Statement *> initialization_, Expression *condition_, Expression *increment_, Statement *body_ ): 195 195 Statement( labels ), initialization( initialization_ ), condition( condition_ ), increment( increment_ ), body( body_ ) { 196 196 } 197 197 198 198 ForStmt::~ForStmt() { 199 delete initialization;199 deleteAll( initialization ); 200 200 delete condition; 201 201 delete increment; … … 213 213 214 214 os << string( indent + 2, ' ' ) << "initialization: \n"; 215 if ( initialization != 0 ) 216 initialization->print( os, indent + 4 ); 215 for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) { 216 (*it)->print( os, indent + 4 ); 217 } 217 218 218 219 os << "\n" << string( indent + 2, ' ' ) << "condition: \n"; -
src/SynTree/Statement.h
r85c4ef0 r145f1fc 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue Ju n 23 11:44:27201513 // Update Count : 2 011 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Jul 14 12:14:54 2015 13 // Update Count : 24 14 14 // 15 15 … … 199 199 class ForStmt : public Statement { 200 200 public: 201 ForStmt( std::list<Label> labels, Statement *initialization = 0,201 ForStmt( std::list<Label> labels, std::list<Statement *> initialization, 202 202 Expression *condition = 0, Expression *increment = 0, Statement *body = 0 ); 203 203 virtual ~ForStmt(); 204 204 205 Statement *get_initialization() { return initialization; }206 void set_initialization( Statement *newValue ) { initialization = newValue; }205 std::list<Statement *> &get_initialization() { return initialization; } 206 void set_initialization( std::list<Statement *> newValue ) { initialization = newValue; } 207 207 Expression *get_condition() { return condition; } 208 208 void set_condition( Expression *newValue ) { condition = newValue; } … … 217 217 virtual void print( std::ostream &os, int indent = 0 ) const; 218 218 private: 219 Statement *initialization;219 std::list<Statement *> initialization; 220 220 Expression *condition; 221 221 Expression *increment; -
src/SynTree/Visitor.cc
r85c4ef0 r145f1fc 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Mon May 18 11:14:51201513 // Update Count : 211 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Jul 14 12:31:03 2015 13 // Update Count : 3 14 14 // 15 15 … … 94 94 95 95 void Visitor::visit( ForStmt *forStmt ) { 96 // ForStmt still needs to be fixed 97 maybeAccept( forStmt->get_initialization(), *this ); 96 acceptAll( forStmt->get_initialization(), *this ); 98 97 maybeAccept( forStmt->get_condition(), *this ); 99 98 maybeAccept( forStmt->get_increment(), *this );
Note: See TracChangeset
for help on using the changeset viewer.