Changes in src/CodeGen/CodeGenerator.cc [08061589:4d2434a]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r08061589 r4d2434a 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : Sun Jul 31 08:42:18201613 // Update Count : 3 4511 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 15 15:53:15 2016 13 // Update Count : 306 14 14 // 15 15 … … 45 45 bool wantSpacing( Statement * stmt) { 46 46 return dynamic_cast< IfStmt * >( stmt ) || dynamic_cast< CompoundStmt * >( stmt ) || 47 dynamic_cast< WhileStmt * >( stmt ) || dynamic_cast< ForStmt * > ( stmt ) || dynamic_cast< SwitchStmt *>( stmt );47 dynamic_cast< WhileStmt * >( stmt ) || dynamic_cast< ForStmt * > ( stmt ) || dynamic_cast< SwitchStmt *>( stmt ); 48 48 } 49 49 … … 83 83 } 84 84 85 CodeGenerator::CodeGenerator( std::ostream &os ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ), printLabels( *this ) { }85 CodeGenerator::CodeGenerator( std::ostream &os ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ), printLabels( *this ) { } 86 86 87 87 CodeGenerator::CodeGenerator( std::ostream &os, std::string init, int indentation, bool infunp ) … … 155 155 objectDecl->get_init()->accept( *this ); 156 156 } // if 157 158 157 if ( objectDecl->get_bitfieldWidth() ) { 159 158 output << ":"; … … 173 172 174 173 cur_indent += CodeGenerator::tabsize; 175 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) {174 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 176 175 output << indent; 177 176 (*i)->accept( *this ); 178 177 output << ";" << endl; 179 } // for178 } 180 179 181 180 cur_indent -= CodeGenerator::tabsize; … … 258 257 (*iter)->accept( *this ); 259 258 output << "]"; 260 } // if261 } // for259 } 260 } 262 261 output << " = "; 263 262 } … … 271 270 printDesignators( init->get_designators() ); 272 271 output << "{ "; 273 if ( init->begin _initializers() == init->end_initializers() ) {272 if ( init->begin() == init->end() ) { 274 273 // illegal to leave initializer list empty for scalar initializers, but always legal to have 0 275 274 output << "0"; 276 275 } else { 277 genCommaList( init->begin _initializers(), init->end_initializers() );276 genCommaList( init->begin(), init->end() ); 278 277 } 279 278 output << " }"; … … 318 317 // do nothing 319 318 ; 320 } // switch319 } 321 320 322 321 switch ( opInfo.type ) { … … 386 385 // there are no intrinsic definitions of 0/1 or label addresses as functions 387 386 assert( false ); 388 } // switch387 } 389 388 } else { 390 389 varExpr->accept( *this ); … … 418 417 case OT_CALL: 419 418 assert( false ); 419 420 420 421 421 case OT_CTOR: … … 437 437 // no constructors with 0 or more than 2 parameters 438 438 assert( false ); 439 } // if439 } 440 440 break; 441 441 … … 470 470 // there are no intrinsic definitions of 0 or 1 as functions 471 471 assert( false ); 472 } // switch472 } 473 473 } else { 474 if ( nameExpr->get_name() == "Range" ) { // case V1 ... V2 or case V1~V2 475 assert( untypedExpr->get_args().size() == 2 ); 476 (*untypedExpr->get_args().begin())->accept( *this ); 477 output << " ... "; 478 (*--untypedExpr->get_args().end())->accept( *this ); 479 } else { // builtin routines 480 nameExpr->accept( *this ); 481 output << "("; 482 genCommaList( untypedExpr->get_args().begin(), untypedExpr->get_args().end() ); 483 output << ")"; 484 } // if 474 nameExpr->accept( *this ); 475 output << "("; 476 genCommaList( untypedExpr->get_args().begin(), untypedExpr->get_args().end() ); 477 output << ")"; 485 478 } // if 486 479 } else { … … 528 521 // otherwise, the cast is to an lvalue type, so the cast should be dropped, since the result of a cast is 529 522 // never an lvalue in C 530 } // if523 } 531 524 castExpr->get_arg()->accept( *this ); 532 525 output << ")"; … … 661 654 if ( wantSpacing( *i ) ) { 662 655 output << endl; 663 } // if656 } 664 657 } 665 658 cur_indent -= CodeGenerator::tabsize; … … 744 737 (*i)->accept( *this ); 745 738 output << endl; 746 } // for739 } 747 740 cur_indent -= CodeGenerator::tabsize; 748 741 } … … 766 759 output << "continue"; 767 760 break; 768 } // switch761 } 769 762 output << ";"; 770 763 } … … 805 798 if ( forStmt->get_condition() != 0 ) { 806 799 forStmt->get_condition()->accept( *this ); 807 } // if800 } 808 801 output << ";"; 809 802 … … 812 805 Expression * expr = new CastExpr( forStmt->get_increment() ); 813 806 expr->accept( *this ); 814 } // if807 } 815 808 output << ") "; 816 809
Note:
See TracChangeset
for help on using the changeset viewer.