Ignore:
Timestamp:
Aug 25, 2017, 10:38:34 AM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    raf08051 r28e58fd  
    192192                        genCommaList( aggDecl->get_parameters().begin(), aggDecl->get_parameters().end() );
    193193                        output << ")" << endl;
     194                        output << indent;
    194195                }
    195196
     
    205206                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) {
    206207                                updateLocation( *i );
     208                                output << indent;
    207209                                (*i)->accept( *this );
    208210                                output << ";" << endl;
     
    244246                                assert( obj );
    245247                                updateLocation( obj );
    246                                 output << mangleName( obj );
     248                                output << indent << mangleName( obj );
    247249                                if ( obj->get_init() ) {
    248250                                        output << " = ";
     
    332334        void CodeGenerator::visit( __attribute__((unused)) ConstructorInit * init ){
    333335                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 << "}";
    336342        }
    337343
     
    347353                        if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( varExpr->get_var()->get_name(), opInfo ) ) {
    348354                                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 argument
    359                                                         *arg = addrExpr->get_arg();
    360                                                 } else {
    361                                                         // no address-of operator, so must be a pointer - add dereference
    362                                                         // 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 application
    364                                                         // 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                                                 } // if
    372                                                 break;
    373                                         }
    374 
    375                                   default:
    376                                         // do nothing
    377                                         ;
    378                                 } // switch
    379 
    380355                                switch ( opInfo.type ) {
    381356                                  case OT_INDEX:
     
    584559                if ( castExpr->get_result()->isVoid() ) {
    585560                        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.
    588565                        output << "(";
    589566                        output << genType( castExpr->get_result(), "", pretty, genC );
    590567                        output << ")";
    591                 } else {
    592                         // otherwise, the cast is to an lvalue type, so the cast should be dropped, since the result of a cast is
    593                         // never an lvalue in C
    594568                } // if
    595569                castExpr->get_arg()->accept( *this );
     
    706680                extension( commaExpr );
    707681                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                }
    708686                commaExpr->get_arg1()->accept( *this );
    709687                output << " , ";
    710688                commaExpr->get_arg2()->accept( *this );
    711689                output << ")";
     690        }
     691
     692        void CodeGenerator::visit( TupleAssignExpr * tupleExpr ) {
     693                assertf( ! genC, "TupleAssignExpr should not reach code generation." );
     694                tupleExpr->stmtExpr->accept( *this );
    712695        }
    713696
     
    759742                output << "(" << genType( compLitExpr->get_result(), "", pretty, genC ) << ")";
    760743                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 << " }";
    761751        }
    762752
     
    770760                for ( Statement * stmt : stmts ) {
    771761                        updateLocation( stmt );
    772             output << printLabels( stmt->get_labels() );
     762                        output << printLabels( stmt->get_labels() );
    773763                        if ( i+1 == numStmts ) {
    774764                                // last statement in a statement expression needs to be handled specially -
     
    815805        void CodeGenerator::visit( ExprStmt * exprStmt ) {
    816806                assert( exprStmt );
    817                 Expression * expr = exprStmt->get_expr();
    818807                if ( genC ) {
    819808                        // 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 );
    823812                output << ";";
    824813        }
Note: See TracChangeset for help on using the changeset viewer.