Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r486341f r066d77a  
    307307                                                } else {
    308308                                                        // no address-of operator, so must be a pointer - add dereference
     309                                                        // NOTE: if the assertion starts to trigger, check that the application expr isn't being shared.
     310                                                        // Since its arguments are modified here, this assertion most commonly triggers when the application
     311                                                        // is visited multiple times.
    309312                                                        UntypedExpr * newExpr = new UntypedExpr( new NameExpr( "*?" ) );
    310313                                                        newExpr->get_args().push_back( *arg );
    311                                                         assert( (*arg)->get_results().size() == 1 );
    312                                                         Type * type = InitTweak::getPointerBase( (*arg)->get_results().front() );
    313                                                         assert( type );
    314                                                         newExpr->get_results().push_back( type->clone() );
     314                                                        Type * type = InitTweak::getPointerBase( (*arg)->get_result() );
     315                                                        assertf( type, "First argument to a derefence must be a pointer. Ensure that expressions are not being shared." );
     316                                                        newExpr->set_result( type->clone() );
    315317                                                        *arg = newExpr;
    316318                                                } // if
     
    527529                extension( castExpr );
    528530                output << "(";
    529                 if ( castExpr->get_results().empty() ) {
     531                if ( castExpr->get_result()->isVoid() ) {
    530532                        output << "(void)" ;
    531                 } else if ( ! castExpr->get_results().front()->get_isLvalue() ) {
     533                } else if ( ! castExpr->get_result()->get_isLvalue() ) {
    532534                        // at least one result type of cast, but not an lvalue
    533535                        output << "(";
    534                         output << genType( castExpr->get_results().front(), "" );
     536                        output << genType( castExpr->get_result(), "" );
    535537                        output << ")";
    536538                } else {
     
    640642        }
    641643
    642         void CodeGenerator::visit( TupleExpr * tupleExpr ) {}
     644        void CodeGenerator::visit( TupleExpr * tupleExpr ) { assert( false ); }
    643645
    644646        void CodeGenerator::visit( TypeExpr * typeExpr ) {}
     
    654656                asmExpr->get_operand()->accept( *this );
    655657                output << " )";
     658        }
     659
     660        void CodeGenerator::visit( CompoundLiteralExpr *compLitExpr ) {
     661                assert( compLitExpr->get_type() && dynamic_cast< ListInit * > ( compLitExpr->get_initializer() ) );
     662                output << "(" << genType( compLitExpr->get_type(), "" ) << ")";
     663                compLitExpr->get_initializer()->accept( *this );
     664        }
     665
     666        void CodeGenerator::visit( StmtExpr * stmtExpr ) {
     667                std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids();
     668                output << "({" << std::endl;
     669                cur_indent += CodeGenerator::tabsize;
     670                unsigned int numStmts = stmts.size();
     671                unsigned int i = 0;
     672                for ( Statement * stmt : stmts ) {
     673                        output << indent << printLabels( stmt->get_labels() );
     674                        if ( i+1 == numStmts ) {
     675                                // last statement in a statement expression needs to be handled specially -
     676                                // cannot cast to void, otherwise the expression statement has no value
     677                                if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( stmt ) ) {
     678                                        exprStmt->get_expr()->accept( *this );
     679                                        output << ";" << endl;
     680                                        ++i;
     681                                        break;
     682                                }
     683                        }
     684                        stmt->accept( *this );
     685                        output << endl;
     686                        if ( wantSpacing( stmt ) ) {
     687                                output << endl;
     688                        } // if
     689                        ++i;
     690                }
     691                cur_indent -= CodeGenerator::tabsize;
     692                output << indent << "})";
    656693        }
    657694
Note: See TracChangeset for help on using the changeset viewer.