Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r8e9cbb2 r4b2589a  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jul  4 20:38:32 2016
    13 // Update Count     : 300
     12// Last Modified On : Thu Jun  9 13:21:00 2016
     13// Update Count     : 256
    1414//
    1515
     
    4747                        dynamic_cast< WhileStmt * >( stmt ) || dynamic_cast< ForStmt * > ( stmt ) || dynamic_cast< SwitchStmt *>( stmt );
    4848        }
    49 
    50         void CodeGenerator::extension( Expression *expr ) {
    51                 if ( expr->get_extension() ) {
    52                         output << "__extension__ ";
    53                 } // if
    54         } // extension
    55 
    56         void CodeGenerator::extension( Declaration *decl ) {
    57                 if ( decl->get_extension() ) {
    58                         output << "__extension__ ";
    59                 } // if
    60         } // extension
    6149
    6250        ostream & CodeGenerator::Indenter::operator()( ostream & output ) const {
     
    122110        //*** Declarations
    123111        void CodeGenerator::visit( FunctionDecl *functionDecl ) {
    124                 extension( functionDecl );
    125112                genAttributes( functionDecl->get_attributes() );
    126113
     
    147134
    148135        void CodeGenerator::visit( ObjectDecl *objectDecl ) {
    149                 extension( objectDecl );
    150136                handleStorageClass( objectDecl );
    151137                output << genType( objectDecl->get_type(), mangleName( objectDecl ) );
     
    184170
    185171        void CodeGenerator::visit( StructDecl *structDecl ) {
    186                 extension( structDecl );
    187172                output << "struct ";
    188173                handleAggregate( structDecl );
    189174        }
    190175
    191         void CodeGenerator::visit( UnionDecl *unionDecl ) {
    192                 extension( unionDecl );
     176        void CodeGenerator::visit( UnionDecl *aggregateDecl ) {
    193177                output << "union ";
    194                 handleAggregate( unionDecl );
    195         }
    196 
    197         void CodeGenerator::visit( EnumDecl *enumDecl ) {
    198                 extension( enumDecl );
     178                handleAggregate( aggregateDecl );
     179        }
     180
     181        void CodeGenerator::visit( EnumDecl *aggDecl ) {
    199182                output << "enum ";
    200183
    201                 if ( enumDecl->get_name() != "" )
    202                         output << enumDecl->get_name();
    203 
    204                 std::list< Declaration* > &memb = enumDecl->get_members();
     184                if ( aggDecl->get_name() != "" )
     185                        output << aggDecl->get_name();
     186
     187                std::list< Declaration* > &memb = aggDecl->get_members();
    205188
    206189                if ( ! memb.empty() ) {
     
    225208        }
    226209
    227         void CodeGenerator::visit( TraitDecl *traitDecl ) {}
     210        void CodeGenerator::visit( TraitDecl *aggregateDecl ) {}
    228211
    229212        void CodeGenerator::visit( TypedefDecl *typeDecl ) {
    230                 assert( false && "Typedefs are removed and substituted in earlier passes." );
    231                 //output << "typedef ";
    232                 //output << genType( typeDecl->get_base(), typeDecl->get_name() );
     213                output << "typedef ";
     214                output << genType( typeDecl->get_base(), typeDecl->get_name() );
    233215        }
    234216
     
    236218                // really, we should mutate this into something that isn't a TypeDecl but that requires large-scale changes,
    237219                // still to be done
    238                 extension( typeDecl );
    239220                output << "extern unsigned long " << typeDecl->get_name();
    240221                if ( typeDecl->get_base() ) {
     
    270251                output << "{ ";
    271252                if ( init->begin_initializers() == init->end_initializers() ) {
    272                         // illegal to leave initializer list empty for scalar initializers, but always legal to have 0
     253                        // illegal to leave initializer list empty for scalar initializers,
     254                        // but always legal to have 0
    273255                        output << "0";
    274256                } else {
     
    335317                                  case OT_DTOR:
    336318                                        if ( applicationExpr->get_args().size() == 1 ) {
    337                                                 // the expression fed into a single parameter constructor or destructor may contain side
    338                                                 // effects, so must still output this expression
     319                                                // the expression fed into a single parameter constructor or destructor
     320                                                // may contain side effects, so must still output this expression
    339321                                                output << "(";
    340322                                                (*arg++)->accept( *this );
     
    421403                                  case OT_DTOR:
    422404                                        if ( untypedExpr->get_args().size() == 1 ) {
    423                                                 // the expression fed into a single parameter constructor or destructor may contain side
    424                                                 // effects, so must still output this expression
     405                                                // the expression fed into a single parameter constructor or destructor
     406                                                // may contain side effects, so must still output this expression
    425407                                                output << "(";
    426408                                                (*arg++)->accept( *this );
     
    518500                        output << ")";
    519501                } else {
    520                         // otherwise, the cast is to an lvalue type, so the cast should be dropped, since the result of a cast is
     502                        // otherwise, the cast is to an lvalue type, so the cast
     503                        // should be dropped, since the result of a cast is
    521504                        // never an lvalue in C
    522505                }
     
    563546
    564547        void CodeGenerator::visit( AlignofExpr *alignofExpr ) {
     548                extension( alignofExpr );
    565549                // use GCC extension to avoid bumping std to C11
    566                 extension( alignofExpr );
    567550                output << "__alignof__(";
    568551                if ( alignofExpr->get_isType() ) {
     
    575558
    576559        void CodeGenerator::visit( UntypedOffsetofExpr *offsetofExpr ) {
    577                 assert( false && "UntypedOffsetofExpr should not reach code generation." );
     560                assert( false && "UntypedOffsetofExpr should not reach code generation" );
    578561        }
    579562
    580563        void CodeGenerator::visit( OffsetofExpr *offsetofExpr ) {
     564                extension( offsetofExpr );
    581565                // use GCC builtin
    582566                output << "__builtin_offsetof(";
     
    587571
    588572        void CodeGenerator::visit( OffsetPackExpr *offsetPackExpr ) {
    589                 assert( false && "OffsetPackExpr should not reach code generation." );
     573                assert( false && "OffsetPackExpr should not reach code generation" );
    590574        }
    591575
     
    628612
    629613        void CodeGenerator::visit( AsmExpr *asmExpr ) {
     614                extension( asmExpr );
    630615                if ( asmExpr->get_inout() ) {
    631616                        output << "[ ";
     
    792777
    793778        void CodeGenerator::visit( ForStmt *forStmt ) {
    794                 // initialization is always hoisted, so don't bother doing anything with that
     779                // initialization is always hoisted, so don't
     780                // bother doing anything with that
    795781                output << "for (;";
    796782
Note: See TracChangeset for help on using the changeset viewer.