Changes in src/CodeGen/CodeGenerator.cc [03e5d14:c2ce2350]
- File:
-
- 1 edited
-
src/CodeGen/CodeGenerator.cc (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r03e5d14 rc2ce2350 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Fri May 06 15:40:35201613 // Update Count : 2 4312 // Last Modified On : Wed Apr 27 11:59:36 2016 13 // Update Count : 255 14 14 // 15 15 … … 67 67 string mangleName( DeclarationWithType *decl ) { 68 68 if ( decl->get_mangleName() != "" ) { 69 return decl->get_mangleName(); 69 // need to incorporate scope level in order to differentiate names for destructors 70 return decl->get_scopedMangleName(); 70 71 } else { 71 72 return decl->get_name(); … … 75 76 //*** Declarations 76 77 void CodeGenerator::visit( FunctionDecl *functionDecl ) { 77 // generalize this78 FunctionDecl::Attribute attr = functionDecl->get_attribute();79 switch ( attr.type ) {80 case FunctionDecl::Attribute::Constructor:81 output << "__attribute__ ((constructor";82 if ( attr.priority != FunctionDecl::Attribute::Default ) {83 output << "(" << attr.priority << ")";84 }85 output << ")) ";86 break;87 case FunctionDecl::Attribute::Destructor:88 output << "__attribute__ ((destructor";89 if ( attr.priority != FunctionDecl::Attribute::Default ) {90 output << "(" << attr.priority << ")";91 }92 output << ")) ";93 break;94 default:95 break;96 }97 78 handleStorageClass( functionDecl ); 98 79 if ( functionDecl->get_isInline() ) { … … 233 214 printDesignators( init->get_designators() ); 234 215 output << "{ "; 235 genCommaList( init->begin_initializers(), init->end_initializers() ); 216 if ( init->begin_initializers() == init->end_initializers() ) { 217 // illegal to leave initializer list empty for scalar initializers, 218 // but always legal to have 0 219 output << "0"; 220 } else { 221 genCommaList( init->begin_initializers(), init->end_initializers() ); 222 } 236 223 output << " }"; 237 224 } … … 251 238 case OT_POSTFIXASSIGN: 252 239 case OT_INFIXASSIGN: 240 case OT_CTOR: 241 case OT_DTOR: 253 242 { 254 243 assert( arg != applicationExpr->get_args().end() ); 255 244 if ( AddressExpr *addrExpr = dynamic_cast< AddressExpr * >( *arg ) ) { 256 245 // remove & from first assignment/ctor argument 257 246 *arg = addrExpr->get_arg(); 258 247 } else { 248 // no address-of operator, so must be a pointer - add dereference 259 249 UntypedExpr *newExpr = new UntypedExpr( new NameExpr( "*?" ) ); 260 250 newExpr->get_args().push_back( *arg ); … … 283 273 break; 284 274 275 case OT_CTOR: 276 case OT_DTOR: 277 if ( applicationExpr->get_args().size() == 1 ) { 278 // the expression fed into a single parameter constructor or destructor 279 // may contain side effects - output as a void expression 280 output << "((void)("; 281 (*arg++)->accept( *this ); 282 output << ")) /* " << opInfo.inputName << " */"; 283 } else if ( applicationExpr->get_args().size() == 2 ) { 284 // intrinsic two parameter constructors are essentially bitwise assignment 285 output << "("; 286 (*arg++)->accept( *this ); 287 output << opInfo.symbol; 288 (*arg)->accept( *this ); 289 output << ") /* " << opInfo.inputName << " */"; 290 } else { 291 // no constructors with 0 or more than 2 parameters 292 assert( false ); 293 } 294 break; 295 285 296 case OT_PREFIX: 286 297 case OT_PREFIXASSIGN: … … 298 309 output << opInfo.symbol; 299 310 break; 311 300 312 301 313 case OT_INFIX: … … 344 356 case OT_CALL: 345 357 assert( false ); 358 359 360 case OT_CTOR: 361 case OT_DTOR: 362 if ( untypedExpr->get_args().size() == 1 ) { 363 // the expression fed into a single parameter constructor or destructor 364 // may contain side effects - output as a void expression 365 output << "((void)("; 366 (*arg++)->accept( *this ); 367 output << ")) /* " << opInfo.inputName << " */"; 368 } else if ( untypedExpr->get_args().size() == 2 ) { 369 // intrinsic two parameter constructors are essentially bitwise assignment 370 output << "("; 371 (*arg++)->accept( *this ); 372 output << opInfo.symbol; 373 (*arg)->accept( *this ); 374 output << ") /* " << opInfo.inputName << " */"; 375 } else { 376 // no constructors with 0 or more than 2 parameters 377 assert( false ); 378 } 346 379 break; 347 380
Note:
See TracChangeset
for help on using the changeset viewer.