Changeset e4d829b for src/CodeGen/CodeGenerator.cc
- Timestamp:
- Jun 20, 2017, 1:19:53 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 579263a
- Parents:
- c6d2e93
- git-author:
- Rob Schluntz <rschlunt@…> (06/20/17 13:16:13)
- git-committer:
- Rob Schluntz <rschlunt@…> (06/20/17 13:19:53)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
rc6d2e93 re4d829b 298 298 } 299 299 300 void CodeGenerator:: printDesignators( std::list< Expression * > & designators) {301 typedef std::list< Expression * > DesignatorList;300 void CodeGenerator::visit( Designation * designation ) { 301 std::list< Expression * > designators = designation->get_designators(); 302 302 if ( designators.size() == 0 ) return; 303 for ( DesignatorList::iterator iter = designators.begin(); iter != designators.end(); ++iter ) { 304 if ( dynamic_cast< NameExpr * >( *iter ) ) { 305 // if expression is a name, then initializing aggregate member 303 for ( Expression * des : designators ) { 304 if ( dynamic_cast< ConstantExpr * >( des ) ) { 305 // if expression is a ConstantExpr, then initializing array element 306 output << "["; 307 des->accept( *this ); 308 output << "]"; 309 } else { 310 // if not a ConstantExpr, it has to be a NameExpr or VariableExpr, initializing aggregate member 306 311 output << "."; 307 (*iter)->accept( *this ); 308 } else { 309 // if not a simple name, it has to be a constant expression, i.e. an array designator 310 output << "["; 311 (*iter)->accept( *this ); 312 output << "]"; 312 des->accept( *this ); 313 313 } // if 314 314 } // for … … 317 317 318 318 void CodeGenerator::visit( SingleInit * init ) { 319 printDesignators( init->get_designators() );320 319 init->get_value()->accept( *this ); 321 320 } 322 321 323 322 void CodeGenerator::visit( ListInit * init ) { 324 printDesignators( init->get_designators() ); 323 auto initBegin = init->begin(); 324 auto initEnd = init->end(); 325 auto desigBegin = init->get_designations().begin(); 326 auto desigEnd = init->get_designations().end(); 327 325 328 output << "{ "; 326 genCommaList( init->begin(), init->end() ); 329 for ( ; initBegin != initEnd && desigBegin != desigEnd; ) { 330 (*desigBegin)->accept( *this ); 331 (*initBegin)->accept( *this ); 332 ++initBegin, ++desigBegin; 333 if ( initBegin != initEnd ) { 334 output << ", "; 335 } 336 } 327 337 output << " }"; 338 assertf( initBegin == initEnd && desigBegin == desigEnd, "Initializers and designators not the same length. %s", toString( init ).c_str() ); 328 339 } 329 340 … … 726 737 727 738 void CodeGenerator::visit( TypeExpr * typeExpr ) { 728 assertf( ! genC, "TypeExpr should not reach code generation." ); 729 output<< genType( typeExpr->get_type(), "", pretty, genC ); 739 // if ( genC ) std::cerr << "typeexpr still exists: " << typeExpr << std::endl; 740 // assertf( ! genC, "TypeExpr should not reach code generation." ); 741 if ( ! genC ) { 742 output<< genType( typeExpr->get_type(), "", pretty, genC ); 743 } 730 744 } 731 745
Note: See TracChangeset
for help on using the changeset viewer.