Changeset 28e58fd for src/CodeGen/CodeGenerator.cc
- Timestamp:
- Aug 25, 2017, 10:38:34 AM (8 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:
- 800d275
- Parents:
- af08051 (diff), 3eab308c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
raf08051 r28e58fd 192 192 genCommaList( aggDecl->get_parameters().begin(), aggDecl->get_parameters().end() ); 193 193 output << ")" << endl; 194 output << indent; 194 195 } 195 196 … … 205 206 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) { 206 207 updateLocation( *i ); 208 output << indent; 207 209 (*i)->accept( *this ); 208 210 output << ";" << endl; … … 244 246 assert( obj ); 245 247 updateLocation( obj ); 246 output << mangleName( obj );248 output << indent << mangleName( obj ); 247 249 if ( obj->get_init() ) { 248 250 output << " = "; … … 332 334 void CodeGenerator::visit( __attribute__((unused)) ConstructorInit * init ){ 333 335 assertf( ! genC, "ConstructorInit nodes should not reach code generation." ); 334 // xxx - generate something reasonable for constructor/destructor pairs 335 output << "<ctorinit>"; 336 // pseudo-output for constructor/destructor pairs 337 output << "<ctorinit>{" << std::endl << ++indent << "ctor: "; 338 maybeAccept( init->get_ctor(), *this ); 339 output << ", " << std::endl << indent << "dtor: "; 340 maybeAccept( init->get_dtor(), *this ); 341 output << std::endl << --indent << "}"; 336 342 } 337 343 … … 347 353 if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( varExpr->get_var()->get_name(), opInfo ) ) { 348 354 std::list< Expression* >::iterator arg = applicationExpr->get_args().begin(); 349 switch ( opInfo.type ) {350 case OT_PREFIXASSIGN:351 case OT_POSTFIXASSIGN:352 case OT_INFIXASSIGN:353 case OT_CTOR:354 case OT_DTOR:355 {356 assert( arg != applicationExpr->get_args().end() );357 if ( AddressExpr * addrExpr = dynamic_cast< AddressExpr * >( *arg ) ) {358 // remove & from first assignment/ctor argument359 *arg = addrExpr->get_arg();360 } else {361 // no address-of operator, so must be a pointer - add dereference362 // NOTE: if the assertion starts to trigger, check that the application expr isn't being shared.363 // Since its arguments are modified here, this assertion most commonly triggers when the application364 // is visited multiple times.365 UntypedExpr * newExpr = new UntypedExpr( new NameExpr( "*?" ) );366 newExpr->get_args().push_back( *arg );367 Type * type = InitTweak::getPointerBase( (*arg)->get_result() );368 assertf( type, "First argument to a derefence must be a pointer. Ensure that expressions are not being shared." );369 newExpr->set_result( type->clone() );370 *arg = newExpr;371 } // if372 break;373 }374 375 default:376 // do nothing377 ;378 } // switch379 380 355 switch ( opInfo.type ) { 381 356 case OT_INDEX: … … 584 559 if ( castExpr->get_result()->isVoid() ) { 585 560 output << "(void)" ; 586 } else if ( ! castExpr->get_result()->get_lvalue() ) { 587 // at least one result type of cast, but not an lvalue 561 } else { 562 // at least one result type of cast. 563 // Note: previously, lvalue casts were skipped. Since it's now impossible for the user to write 564 // an lvalue cast, this has been taken out. 588 565 output << "("; 589 566 output << genType( castExpr->get_result(), "", pretty, genC ); 590 567 output << ")"; 591 } else {592 // otherwise, the cast is to an lvalue type, so the cast should be dropped, since the result of a cast is593 // never an lvalue in C594 568 } // if 595 569 castExpr->get_arg()->accept( *this ); … … 706 680 extension( commaExpr ); 707 681 output << "("; 682 if ( genC ) { 683 // arg1 of a CommaExpr is never used, so it can be safely cast to void to reduce gcc warnings. 684 commaExpr->set_arg1( new CastExpr( commaExpr->get_arg1() ) ); 685 } 708 686 commaExpr->get_arg1()->accept( *this ); 709 687 output << " , "; 710 688 commaExpr->get_arg2()->accept( *this ); 711 689 output << ")"; 690 } 691 692 void CodeGenerator::visit( TupleAssignExpr * tupleExpr ) { 693 assertf( ! genC, "TupleAssignExpr should not reach code generation." ); 694 tupleExpr->stmtExpr->accept( *this ); 712 695 } 713 696 … … 759 742 output << "(" << genType( compLitExpr->get_result(), "", pretty, genC ) << ")"; 760 743 compLitExpr->get_initializer()->accept( *this ); 744 } 745 746 void CodeGenerator::visit( UniqueExpr * unqExpr ) { 747 assertf( ! genC, "Unique expressions should not reach code generation." ); 748 output << "unq<" << unqExpr->get_id() << ">{ "; 749 unqExpr->get_expr()->accept( *this ); 750 output << " }"; 761 751 } 762 752 … … 770 760 for ( Statement * stmt : stmts ) { 771 761 updateLocation( stmt ); 772 762 output << printLabels( stmt->get_labels() ); 773 763 if ( i+1 == numStmts ) { 774 764 // last statement in a statement expression needs to be handled specially - … … 815 805 void CodeGenerator::visit( ExprStmt * exprStmt ) { 816 806 assert( exprStmt ); 817 Expression * expr = exprStmt->get_expr();818 807 if ( genC ) { 819 808 // cast the top-level expression to void to reduce gcc warnings. 820 expr = new CastExpr( expr);821 } 822 expr ->accept( *this );809 exprStmt->set_expr( new CastExpr( exprStmt->get_expr() ) ); 810 } 811 exprStmt->get_expr()->accept( *this ); 823 812 output << ";"; 824 813 }
Note:
See TracChangeset
for help on using the changeset viewer.