Changeset 724c2b6
- Timestamp:
- Jul 15, 2015, 4:47:48 PM (8 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:
- 1db21619
- Parents:
- 9163b9c (diff), 1ab4ce2 (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:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r9163b9c r724c2b6 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
r9163b9c r724c2b6 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
r9163b9c r724c2b6 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
r9163b9c r724c2b6 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
r9163b9c r724c2b6 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
r9163b9c r724c2b6 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
r9163b9c r724c2b6 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
r9163b9c r724c2b6 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 … … 535 535 init->get_args().push_back( new NameExpr( "0" ) ); 536 536 Statement *initStmt = new ExprStmt( noLabels, init ); 537 537 std::list<Statement *> initList; 538 initList.push_back( initStmt ); 539 538 540 UntypedExpr *cond = new UntypedExpr( new NameExpr( "?<?" ) ); 539 541 cond->get_args().push_back( new VariableExpr( index ) ); … … 560 562 assignExpr->get_args().push_back( srcIndex ); 561 563 562 *out++ = new ForStmt( noLabels, init Stmt, cond, inc, new ExprStmt( noLabels, assignExpr ) );564 *out++ = new ForStmt( noLabels, initList, cond, inc, new ExprStmt( noLabels, assignExpr ) ); 563 565 } 564 566 -
src/SynTree/Mutator.cc
r9163b9c r724c2b6 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
r9163b9c r724c2b6 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
r9163b9c r724c2b6 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
r9163b9c r724c2b6 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 ); -
src/main.cc
r9163b9c r724c2b6 10 10 // Created On : Fri May 15 23:12:02 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Mon Jul 06 15:01:26201513 // Update Count : 7912 // Last Modified On : Wed Jul 15 16:45:24 2015 13 // Update Count : 145 14 14 // 15 15 … … 54 54 if ( errorp ) std::cerr << x << std::endl; 55 55 56 void parse( FILE * input, LinkageSpec::Type t, bool shouldExit = false ); 56 static void parse( FILE * input, LinkageSpec::Type t, bool shouldExit = false ); 57 static void dump( std::list< Declaration * > & translationUnit ); 57 58 58 59 bool … … 64 65 libcfap = false, 65 66 nopreludep = false, 66 protop = false,67 noprotop = false, 67 68 parsep = false, 68 69 resolvep = false, // used in AlternativeFinder … … 81 82 { "grammar", no_argument, 0, Grammar }, 82 83 { "libcfa", no_argument, 0, LibCFA }, 83 { "no preamble", no_argument, 0, Nopreamble },84 { "no-preamble", no_argument, 0, Nopreamble }, 84 85 { "parse", no_argument, 0, Parse }, 85 { " prototypes", no_argument, 0, Prototypes },86 { "no-prototypes", no_argument, 0, Prototypes }, 86 87 { "resolver", no_argument, 0, Resolver }, 87 88 { "symbol", no_argument, 0, Symbol }, … … 131 132 case Prototypes: 132 133 case 'p': // generate prototypes for preamble functions 133 protop = true;134 noprotop = true; 134 135 break; 135 136 case Parse: … … 221 222 Parser::get_parser().freeTree(); 222 223 if ( astp ) { 223 printAll( translationUnit, std::cout );224 dump( translationUnit ); 224 225 return 0; 225 226 } // if … … 242 243 243 244 if ( validp ) { 244 printAll( translationUnit, std::cout );245 dump( translationUnit ); 245 246 return 0; 246 247 } // if … … 252 253 253 254 if ( libcfap ) { 254 protop = true;255 255 // generate the bodies of cfa library functions 256 256 LibCfa::makeLibCfa( translationUnit ); … … 258 258 259 259 if ( bresolvep ) { 260 printAll( translationUnit, std::cout );260 dump( translationUnit ); 261 261 return 0; 262 262 } // if … … 265 265 ResolvExpr::resolve( translationUnit ); 266 266 if ( exprp ) { 267 printAll( translationUnit, std::cout );267 dump( translationUnit ); 268 268 } 269 269 … … 279 279 // print tree right before code generation 280 280 if ( codegenp ) { 281 printAll( translationUnit, std::cout );282 return 0; 283 } // if 284 285 CodeGen::generate( translationUnit, *output, true ); //protop );281 dump( translationUnit ); 282 return 0; 283 } // if 284 285 CodeGen::generate( translationUnit, *output, ! noprotop ); 286 286 287 287 if ( output != &std::cout ) { … … 290 290 } catch ( SemanticError &e ) { 291 291 if ( errorp ) { 292 printAll( translationUnit, std::cerr);292 dump( translationUnit ); 293 293 } 294 294 e.print( std::cerr ); … … 315 315 } // main 316 316 317 void parse( FILE * input, LinkageSpec::Type linkage, bool shouldExit ) {317 static void parse( FILE * input, LinkageSpec::Type linkage, bool shouldExit ) { 318 318 Parser::get_parser().set_linkage( linkage ); 319 319 Parser::get_parser().parse( input ); … … 325 325 } 326 326 327 static bool notPrelude( Declaration * decl ) { 328 return ! LinkageSpec::isBuiltin( decl->get_linkage() ); 329 } 330 331 static void dump( std::list< Declaration * > & translationUnit ) { 332 std::list< Declaration * > decls; 333 if ( noprotop ) { 334 filter( translationUnit.begin(), translationUnit.end(), 335 std::back_inserter( decls ), notPrelude ); 336 } else { 337 decls = translationUnit; 338 } 339 340 printAll( decls, std::cout ); 341 } 342 343 327 344 // Local Variables: // 328 345 // tab-width: 4 //
Note: See TracChangeset
for help on using the changeset viewer.