Changes in src/CodeGen/CodeGenerator.cc [8e9cbb2:4b2589a]
- File:
-
- 1 edited
-
src/CodeGen/CodeGenerator.cc (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r8e9cbb2 r4b2589a 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jul 4 20:38:32201613 // Update Count : 30012 // Last Modified On : Thu Jun 9 13:21:00 2016 13 // Update Count : 256 14 14 // 15 15 … … 47 47 dynamic_cast< WhileStmt * >( stmt ) || dynamic_cast< ForStmt * > ( stmt ) || dynamic_cast< SwitchStmt *>( stmt ); 48 48 } 49 50 void CodeGenerator::extension( Expression *expr ) {51 if ( expr->get_extension() ) {52 output << "__extension__ ";53 } // if54 } // extension55 56 void CodeGenerator::extension( Declaration *decl ) {57 if ( decl->get_extension() ) {58 output << "__extension__ ";59 } // if60 } // extension61 49 62 50 ostream & CodeGenerator::Indenter::operator()( ostream & output ) const { … … 122 110 //*** Declarations 123 111 void CodeGenerator::visit( FunctionDecl *functionDecl ) { 124 extension( functionDecl );125 112 genAttributes( functionDecl->get_attributes() ); 126 113 … … 147 134 148 135 void CodeGenerator::visit( ObjectDecl *objectDecl ) { 149 extension( objectDecl );150 136 handleStorageClass( objectDecl ); 151 137 output << genType( objectDecl->get_type(), mangleName( objectDecl ) ); … … 184 170 185 171 void CodeGenerator::visit( StructDecl *structDecl ) { 186 extension( structDecl );187 172 output << "struct "; 188 173 handleAggregate( structDecl ); 189 174 } 190 175 191 void CodeGenerator::visit( UnionDecl *unionDecl ) { 192 extension( unionDecl ); 176 void CodeGenerator::visit( UnionDecl *aggregateDecl ) { 193 177 output << "union "; 194 handleAggregate( unionDecl ); 195 } 196 197 void CodeGenerator::visit( EnumDecl *enumDecl ) { 198 extension( enumDecl ); 178 handleAggregate( aggregateDecl ); 179 } 180 181 void CodeGenerator::visit( EnumDecl *aggDecl ) { 199 182 output << "enum "; 200 183 201 if ( enumDecl->get_name() != "" )202 output << enumDecl->get_name();203 204 std::list< Declaration* > &memb = enumDecl->get_members();184 if ( aggDecl->get_name() != "" ) 185 output << aggDecl->get_name(); 186 187 std::list< Declaration* > &memb = aggDecl->get_members(); 205 188 206 189 if ( ! memb.empty() ) { … … 225 208 } 226 209 227 void CodeGenerator::visit( TraitDecl * traitDecl ) {}210 void CodeGenerator::visit( TraitDecl *aggregateDecl ) {} 228 211 229 212 void CodeGenerator::visit( TypedefDecl *typeDecl ) { 230 assert( false && "Typedefs are removed and substituted in earlier passes." ); 231 //output << "typedef "; 232 //output << genType( typeDecl->get_base(), typeDecl->get_name() ); 213 output << "typedef "; 214 output << genType( typeDecl->get_base(), typeDecl->get_name() ); 233 215 } 234 216 … … 236 218 // really, we should mutate this into something that isn't a TypeDecl but that requires large-scale changes, 237 219 // still to be done 238 extension( typeDecl );239 220 output << "extern unsigned long " << typeDecl->get_name(); 240 221 if ( typeDecl->get_base() ) { … … 270 251 output << "{ "; 271 252 if ( init->begin_initializers() == init->end_initializers() ) { 272 // illegal to leave initializer list empty for scalar initializers, but always legal to have 0 253 // illegal to leave initializer list empty for scalar initializers, 254 // but always legal to have 0 273 255 output << "0"; 274 256 } else { … … 335 317 case OT_DTOR: 336 318 if ( applicationExpr->get_args().size() == 1 ) { 337 // the expression fed into a single parameter constructor or destructor may contain side338 // effects, so must still output this expression319 // the expression fed into a single parameter constructor or destructor 320 // may contain side effects, so must still output this expression 339 321 output << "("; 340 322 (*arg++)->accept( *this ); … … 421 403 case OT_DTOR: 422 404 if ( untypedExpr->get_args().size() == 1 ) { 423 // the expression fed into a single parameter constructor or destructor may contain side424 // effects, so must still output this expression405 // the expression fed into a single parameter constructor or destructor 406 // may contain side effects, so must still output this expression 425 407 output << "("; 426 408 (*arg++)->accept( *this ); … … 518 500 output << ")"; 519 501 } else { 520 // otherwise, the cast is to an lvalue type, so the cast should be dropped, since the result of a cast is 502 // otherwise, the cast is to an lvalue type, so the cast 503 // should be dropped, since the result of a cast is 521 504 // never an lvalue in C 522 505 } … … 563 546 564 547 void CodeGenerator::visit( AlignofExpr *alignofExpr ) { 548 extension( alignofExpr ); 565 549 // use GCC extension to avoid bumping std to C11 566 extension( alignofExpr );567 550 output << "__alignof__("; 568 551 if ( alignofExpr->get_isType() ) { … … 575 558 576 559 void CodeGenerator::visit( UntypedOffsetofExpr *offsetofExpr ) { 577 assert( false && "UntypedOffsetofExpr should not reach code generation ." );560 assert( false && "UntypedOffsetofExpr should not reach code generation" ); 578 561 } 579 562 580 563 void CodeGenerator::visit( OffsetofExpr *offsetofExpr ) { 564 extension( offsetofExpr ); 581 565 // use GCC builtin 582 566 output << "__builtin_offsetof("; … … 587 571 588 572 void CodeGenerator::visit( OffsetPackExpr *offsetPackExpr ) { 589 assert( false && "OffsetPackExpr should not reach code generation ." );573 assert( false && "OffsetPackExpr should not reach code generation" ); 590 574 } 591 575 … … 628 612 629 613 void CodeGenerator::visit( AsmExpr *asmExpr ) { 614 extension( asmExpr ); 630 615 if ( asmExpr->get_inout() ) { 631 616 output << "[ "; … … 792 777 793 778 void CodeGenerator::visit( ForStmt *forStmt ) { 794 // initialization is always hoisted, so don't bother doing anything with that 779 // initialization is always hoisted, so don't 780 // bother doing anything with that 795 781 output << "for (;"; 796 782
Note:
See TracChangeset
for help on using the changeset viewer.