Ignore:
Timestamp:
Apr 19, 2022, 3:00:04 PM (3 years ago)
Author:
m3zulfiq <m3zulfiq@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
5b84a321
Parents:
ba897d21 (diff), bb7c77d (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:

added benchmark and evaluations chapter to thesis

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    rba897d21 r2e9b59b  
    274274        void CodeGenerator::postvisit( EnumDecl * enumDecl ) {
    275275                extension( enumDecl );
    276                 output << "enum ";
    277                 genAttributes( enumDecl->get_attributes() );
    278 
    279                 output << enumDecl->get_name();
    280 
    281276                std::list< Declaration* > &memb = enumDecl->get_members();
    282 
    283                 if ( ! memb.empty() ) {
    284                         output << " {" << endl;
    285 
    286                         ++indent;
     277                if (enumDecl->base && ! memb.empty()) {
     278                        unsigned long long last_val = -1;
    287279                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    288280                                ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i );
    289281                                assert( obj );
    290                                 output << indent << mangleName( obj );
    291                                 if ( obj->get_init() ) {
    292                                         output << " = ";
    293                                         obj->get_init()->accept( *visitor );
    294                                 } // if
    295                                 output << "," << endl;
     282                                output << "static const ";
     283                                output << genType(enumDecl->base, "", options) << " ";
     284                                output << mangleName( obj ) << " ";
     285                                output << " = ";
     286                                output << "(" << genType(enumDecl->base, "", options) << ")";
     287                                if ( (BasicType *)(enumDecl->base) && ((BasicType *)(enumDecl->base))->isWholeNumber() ) {
     288                                        if ( obj->get_init() ) {
     289                                                obj->get_init()->accept( *visitor );
     290                                                last_val = ((ConstantExpr *)(((SingleInit *)(obj->init))->value))->constant.get_ival();
     291                                        } else {
     292                                                output << ++last_val;
     293                                        } // if
     294                                } else {
     295                                        if ( obj->get_init() ) {
     296                                                obj->get_init()->accept( *visitor );
     297                                        } else {
     298                                                // Should not reach here!
     299                                        }
     300                                }
     301                                output << ";" << endl;
    296302                        } // for
    297 
     303                } else {
     304                        output << "enum ";
     305                        genAttributes( enumDecl->get_attributes() );
     306
     307                        output << enumDecl->get_name();
     308
     309                        if ( ! memb.empty() ) {
     310                                output << " {" << endl;
     311
     312                                ++indent;
     313                                for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
     314                                        ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i );
     315                                        assert( obj );
     316                                        output << indent << mangleName( obj );
     317                                        if ( obj->get_init() ) {
     318                                                output << " = ";
     319                                                obj->get_init()->accept( *visitor );
     320                                        } // if
     321                                        output << "," << endl;
     322                                } // for
    298323                        --indent;
    299 
    300324                        output << indent << "}";
     325                        } // if
    301326                } // if
    302327        }
     
    347372                                des->accept( *visitor );
    348373                        } else {
    349                                 // otherwise, it has to be a ConstantExpr or CastExpr, initializing array eleemnt
     374                                // otherwise, it has to be a ConstantExpr or CastExpr, initializing array element
    350375                                output << "[";
    351376                                des->accept( *visitor );
     
    661686                        output << opInfo->symbol;
    662687                } else {
     688                        // if (dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())
     689                        // && dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())->baseEnum->base) {
     690                        //      output << '(' <<genType(dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())->baseEnum->base, "", options) << ')';
     691                        // }
    663692                        output << mangleName( variableExpr->get_var() );
    664693                } // if
Note: See TracChangeset for help on using the changeset viewer.