Changes in src/CodeGen/CodeGenerator.cc [7f5566b:971ae89]
- File:
-
- 1 edited
-
src/CodeGen/CodeGenerator.cc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r7f5566b r971ae89 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 Jul 27 14:40:06201513 // Update Count : 2 1811 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Sep 17 15:24:08 2015 13 // Update Count : 231 14 14 // 15 15 … … 186 186 } 187 187 188 void CodeGenerator::printDesignators( std::list< Expression * > & designators ) { 189 typedef std::list< Expression * > DesignatorList; 190 if ( designators.size() == 0 ) return; 191 for ( DesignatorList::iterator iter = designators.begin(); iter != designators.end(); ++iter ) { 192 if ( dynamic_cast< NameExpr * >( *iter ) ) { 193 // if expression is a name, then initializing aggregate member 194 output << "."; 195 (*iter)->accept( *this ); 196 } else { 197 // if not a simple name, it has to be a constant expression, i.e. an array designator 198 output << "["; 199 (*iter)->accept( *this ); 200 output << "]"; 201 } 202 } 203 output << " = "; 204 } 205 188 206 void CodeGenerator::visit( SingleInit *init ) { 207 printDesignators( init->get_designators() ); 189 208 init->get_value()->accept( *this ); 190 209 } 191 210 192 211 void CodeGenerator::visit( ListInit *init ) { 212 printDesignators( init->get_designators() ); 193 213 output << "{ "; 194 214 genCommaList( init->begin_initializers(), init->end_initializers() ); … … 372 392 373 393 void CodeGenerator::visit( CastExpr *castExpr ) { 374 output << "(("; 375 if ( castExpr->get_results().empty() ) { 376 output << "void" ; 377 } else { 378 output << genType( castExpr->get_results().front(), "" ); 379 } // if 380 output << ")"; 381 castExpr->get_arg()->accept( *this ); 382 output << ")"; 394 // if the cast is to an lvalue type, then the cast 395 // should be dropped, since the result of a cast is 396 // never an lvalue in C 397 if ( castExpr->get_results().front()->get_isLvalue() ) { 398 castExpr->get_arg()->accept( *this ); 399 } else { 400 output << "(("; 401 if ( castExpr->get_results().empty() ) { 402 output << "void" ; 403 } else { 404 output << genType( castExpr->get_results().front(), "" ); 405 } // if 406 output << ")"; 407 castExpr->get_arg()->accept( *this ); 408 output << ")"; 409 } 383 410 } 384 411
Note:
See TracChangeset
for help on using the changeset viewer.