Changes in src/CodeGen/CodeGenerator.cc [10a7775:03e5d14]
- File:
-
- 1 edited
-
src/CodeGen/CodeGenerator.cc (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r10a7775 r03e5d14 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 1 6:01:00201613 // Update Count : 2 5512 // Last Modified On : Fri May 06 15:40:35 2016 13 // Update Count : 243 14 14 // 15 15 … … 34 34 #include "GenType.h" 35 35 36 #include "InitTweak/InitTweak.h"37 38 36 using namespace std; 39 37 … … 69 67 string mangleName( DeclarationWithType *decl ) { 70 68 if ( decl->get_mangleName() != "" ) { 71 // need to incorporate scope level in order to differentiate names for destructors 72 return decl->get_scopedMangleName(); 69 return decl->get_mangleName(); 73 70 } else { 74 71 return decl->get_name(); … … 236 233 printDesignators( init->get_designators() ); 237 234 output << "{ "; 238 if ( init->begin_initializers() == init->end_initializers() ) { 239 // illegal to leave initializer list empty for scalar initializers, 240 // but always legal to have 0 241 output << "0"; 242 } else { 243 genCommaList( init->begin_initializers(), init->end_initializers() ); 244 } 235 genCommaList( init->begin_initializers(), init->end_initializers() ); 245 236 output << " }"; 246 237 } … … 257 248 std::list< Expression* >::iterator arg = applicationExpr->get_args().begin(); 258 249 switch ( opInfo.type ) { 259 case OT_CTOR:260 case OT_DTOR:261 {262 // if the first argument's type is const then GCC complains. In this263 // case, output an explicit ctor/dtor call and exit, rather than following264 // the normal path265 assert( arg != applicationExpr->get_args().end() );266 assert( (*arg)->get_results().size() >= 1 );267 Type * baseType = InitTweak::getPointerBase( (*arg)->get_results().front() );268 if ( baseType->get_isConst() ) {269 // cast away the qualifiers, to eliminate warnings270 Type * newType = baseType->clone();271 newType->get_qualifiers() = Type::Qualifiers();272 *arg = new CastExpr( *arg, new PointerType( Type::Qualifiers(), newType ) );273 varExpr->accept( *this );274 output << "(";275 genCommaList( applicationExpr->get_args().begin(), applicationExpr->get_args().end() );276 output << ")";277 return;278 }279 }280 // intentional fallthrough - instrinsic ctor/dtor for non-const objects should281 // be handled the same way as assignment282 250 case OT_PREFIXASSIGN: 283 251 case OT_POSTFIXASSIGN: … … 286 254 assert( arg != applicationExpr->get_args().end() ); 287 255 if ( AddressExpr *addrExpr = dynamic_cast< AddressExpr * >( *arg ) ) { 288 // remove & from first assignment/ctor argument 256 289 257 *arg = addrExpr->get_arg(); 290 258 } else { 291 // no address-of operator, so must be a pointer - add dereference292 259 UntypedExpr *newExpr = new UntypedExpr( new NameExpr( "*?" ) ); 293 260 newExpr->get_args().push_back( *arg ); 294 assert( (*arg)->get_results().size() == 1 );295 Type * type = InitTweak::getPointerBase( (*arg)->get_results().front() );296 assert( type );297 newExpr->get_results().push_back( type );298 261 *arg = newExpr; 299 262 } // if … … 320 283 break; 321 284 322 case OT_CTOR:323 case OT_DTOR:324 if ( applicationExpr->get_args().size() == 1 ) {325 // the expression fed into a single parameter constructor or destructor326 // may contain side effects - output as a void expression327 output << "((void)(";328 (*arg++)->accept( *this );329 output << ")) /* " << opInfo.inputName << " */";330 } else if ( applicationExpr->get_args().size() == 2 ) {331 // intrinsic two parameter constructors are essentially bitwise assignment332 output << "(";333 (*arg++)->accept( *this );334 output << opInfo.symbol;335 (*arg)->accept( *this );336 output << ") /* " << opInfo.inputName << " */";337 } else {338 // no constructors with 0 or more than 2 parameters339 assert( false );340 }341 break;342 343 285 case OT_PREFIX: 344 286 case OT_PREFIXASSIGN: … … 356 298 output << opInfo.symbol; 357 299 break; 358 359 300 360 301 case OT_INFIX: … … 403 344 case OT_CALL: 404 345 assert( false ); 405 406 407 case OT_CTOR:408 case OT_DTOR:409 if ( untypedExpr->get_args().size() == 1 ) {410 // the expression fed into a single parameter constructor or destructor411 // may contain side effects - output as a void expression412 output << "((void)(";413 (*arg++)->accept( *this );414 output << ")) /* " << opInfo.inputName << " */";415 } else if ( untypedExpr->get_args().size() == 2 ) {416 // intrinsic two parameter constructors are essentially bitwise assignment417 output << "(";418 (*arg++)->accept( *this );419 output << opInfo.symbol;420 (*arg)->accept( *this );421 output << ") /* " << opInfo.inputName << " */";422 } else {423 // no constructors with 0 or more than 2 parameters424 assert( false );425 }426 346 break; 427 347
Note:
See TracChangeset
for help on using the changeset viewer.