Changeset 4819cac for src/CodeGen


Ignore:
Timestamp:
Aug 4, 2016, 4:11:11 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
4e2a1137
Parents:
f9cebb5 (diff), cf37a8e (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' into ctor

Conflicts:

src/CodeGen/CodeGenerator.cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    rf9cebb5 r4819cac  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By :
    12 // Last Modified On : Sun Jul 31 08:42:18 2016
    13 // Update Count     : 345
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Aug  4 11:16:21 2016
     13// Update Count     : 351
    1414//
    1515
     
    4848        }
    4949
    50         void CodeGenerator::extension( Expression *expr ) {
     50        void CodeGenerator::extension( Expression * expr ) {
    5151                if ( expr->get_extension() ) {
    5252                        output << "__extension__ ";
     
    5454        } // extension
    5555
    56         void CodeGenerator::extension( Declaration *decl ) {
     56        void CodeGenerator::extension( Declaration * decl ) {
    5757                if ( decl->get_extension() ) {
    5858                        output << "__extension__ ";
     
    7373        }
    7474
    75         ostream & operator<<( ostream & output, CodeGenerator::LabelPrinter &printLabels ) {
     75        ostream & operator<<( ostream & output, CodeGenerator::LabelPrinter & printLabels ) {
    7676                std::list< Label > & labs = *printLabels.labels;
    7777                // l.unique(); // assumes a sorted list. Why not use set? Does order matter?
     
    7979                        output << l.get_name() + ": ";
    8080                        printLabels.cg.genAttributes( l.get_attributes() );
    81                 }
     81                } // for
    8282                return output;
    8383        }
    8484
    85         CodeGenerator::CodeGenerator( std::ostream &os ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ), printLabels( *this ) {}
    86 
    87         CodeGenerator::CodeGenerator( std::ostream &os, std::string init, int indentation, bool infunp )
     85        CodeGenerator::CodeGenerator( std::ostream & os ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ), printLabels( *this ) {}
     86
     87        CodeGenerator::CodeGenerator( std::ostream & os, std::string init, int indentation, bool infunp )
    8888                        : indent( *this), cur_indent( indentation ), insideFunction( infunp ), output( os ), printLabels( *this ) {
    8989                //output << std::string( init );
    9090        }
    9191
    92         CodeGenerator::CodeGenerator( std::ostream &os, char *init, int indentation, bool infunp )
     92        CodeGenerator::CodeGenerator( std::ostream & os, char * init, int indentation, bool infunp )
    9393                        : indent( *this ), cur_indent( indentation ), insideFunction( infunp ), output( os ), printLabels( *this ) {
    9494                //output << std::string( init );
    9595        }
    9696
    97         string mangleName( DeclarationWithType *decl ) {
     97        string mangleName( DeclarationWithType * decl ) {
    9898                if ( decl->get_mangleName() != "" ) {
    9999                        // need to incorporate scope level in order to differentiate names for destructors
     
    112112                                        genCommaList( attr->get_parameters().begin(), attr->get_parameters().end() );
    113113                                        output << ")";
    114                                 }
     114                                } // if
    115115                                output << ",";
    116                         }
     116                        } // for
    117117                        output << ")) ";
    118                 }
     118                } // if
    119119        }
    120120
    121121
    122122        //*** Declarations
    123         void CodeGenerator::visit( FunctionDecl *functionDecl ) {
     123        void CodeGenerator::visit( FunctionDecl * functionDecl ) {
    124124                extension( functionDecl );
    125125                genAttributes( functionDecl->get_attributes() );
     
    146146        }
    147147
    148         void CodeGenerator::visit( ObjectDecl *objectDecl ) {
     148        void CodeGenerator::visit( ObjectDecl * objectDecl ) {
    149149                extension( objectDecl );
    150150                genAttributes( objectDecl->get_attributes() );
     
    164164        }
    165165
    166         void CodeGenerator::handleAggregate( AggregateDecl *aggDecl ) {
     166        void CodeGenerator::handleAggregate( AggregateDecl * aggDecl ) {
    167167                if ( aggDecl->get_name() != "" )
    168168                        output << aggDecl->get_name();
    169169
    170                 std::list< Declaration * > &memb = aggDecl->get_members();
     170                std::list< Declaration * > & memb = aggDecl->get_members();
    171171                if ( ! memb.empty() ) {
    172172//              if ( aggDecl->has_body() ) {
    173 //                      std::list< Declaration * > &memb = aggDecl->get_members();
     173//                      std::list< Declaration * > & memb = aggDecl->get_members();
    174174                        output << " {" << endl;
    175175
     
    187187        }
    188188
    189         void CodeGenerator::visit( StructDecl *structDecl ) {
     189        void CodeGenerator::visit( StructDecl * structDecl ) {
    190190                extension( structDecl );
    191191                output << "struct ";
     
    193193        }
    194194
    195         void CodeGenerator::visit( UnionDecl *unionDecl ) {
     195        void CodeGenerator::visit( UnionDecl * unionDecl ) {
    196196                extension( unionDecl );
    197197                output << "union ";
     
    199199        }
    200200
    201         void CodeGenerator::visit( EnumDecl *enumDecl ) {
     201        void CodeGenerator::visit( EnumDecl * enumDecl ) {
    202202                extension( enumDecl );
    203203                output << "enum ";
     
    213213                        cur_indent += CodeGenerator::tabsize;
    214214                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    215                                 ObjectDecl *obj = dynamic_cast< ObjectDecl* >( *i );
     215                                ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i );
    216216                                assert( obj );
    217217                                output << indent << mangleName( obj );
     
    229229        }
    230230
    231         void CodeGenerator::visit( TraitDecl *traitDecl ) {}
    232 
    233         void CodeGenerator::visit( TypedefDecl *typeDecl ) {
     231        void CodeGenerator::visit( TraitDecl * traitDecl ) {}
     232
     233        void CodeGenerator::visit( TypedefDecl * typeDecl ) {
    234234                assert( false && "Typedefs are removed and substituted in earlier passes." );
    235235                //output << "typedef ";
     
    237237        }
    238238
    239         void CodeGenerator::visit( TypeDecl *typeDecl ) {
     239        void CodeGenerator::visit( TypeDecl * typeDecl ) {
    240240                // really, we should mutate this into something that isn't a TypeDecl but that requires large-scale changes,
    241241                // still to be done
     
    265265        }
    266266
    267         void CodeGenerator::visit( SingleInit *init ) {
     267        void CodeGenerator::visit( SingleInit * init ) {
    268268                printDesignators( init->get_designators() );
    269269                init->get_value()->accept( *this );
    270270        }
    271271
    272         void CodeGenerator::visit( ListInit *init ) {
     272        void CodeGenerator::visit( ListInit * init ) {
    273273                printDesignators( init->get_designators() );
    274274                output << "{ ";
     
    278278                } else {
    279279                        genCommaList( init->begin(), init->end() );
    280                 }
     280                } // if
    281281                output << " }";
    282282        }
    283283
    284         void CodeGenerator::visit( Constant *constant ) {
     284        void CodeGenerator::visit( Constant * constant ) {
    285285                output << constant->get_value() ;
    286286        }
    287287
    288288        //*** Expressions
    289         void CodeGenerator::visit( ApplicationExpr *applicationExpr ) {
     289        void CodeGenerator::visit( ApplicationExpr * applicationExpr ) {
    290290                extension( applicationExpr );
    291                 if ( VariableExpr *varExpr = dynamic_cast< VariableExpr* >( applicationExpr->get_function() ) ) {
     291                if ( VariableExpr * varExpr = dynamic_cast< VariableExpr* >( applicationExpr->get_function() ) ) {
    292292                        OperatorInfo opInfo;
    293293                        if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( varExpr->get_var()->get_name(), opInfo ) ) {
     
    301301                                        {
    302302                                                assert( arg != applicationExpr->get_args().end() );
    303                                                 if ( AddressExpr *addrExpr = dynamic_cast< AddressExpr * >( *arg ) ) {
     303                                                if ( AddressExpr * addrExpr = dynamic_cast< AddressExpr * >( *arg ) ) {
    304304                                                        // remove & from first assignment/ctor argument
    305305                                                        *arg = addrExpr->get_arg();
    306306                                                } else {
    307307                                                        // no address-of operator, so must be a pointer - add dereference
    308                                                         UntypedExpr *newExpr = new UntypedExpr( new NameExpr( "*?" ) );
     308                                                        UntypedExpr * newExpr = new UntypedExpr( new NameExpr( "*?" ) );
    309309                                                        newExpr->get_args().push_back( *arg );
    310310                                                        assert( (*arg)->get_results().size() == 1 );
     
    354354                                                // no constructors with 0 or more than 2 parameters
    355355                                                assert( false );
    356                                         }
     356                                        } // if
    357357                                        break;
    358358
     
    403403        }
    404404
    405         void CodeGenerator::visit( UntypedExpr *untypedExpr ) {
     405        void CodeGenerator::visit( UntypedExpr * untypedExpr ) {
    406406                extension( untypedExpr );
    407                 if ( NameExpr *nameExpr = dynamic_cast< NameExpr* >( untypedExpr->get_function() ) ) {
     407                if ( NameExpr * nameExpr = dynamic_cast< NameExpr* >( untypedExpr->get_function() ) ) {
    408408                        OperatorInfo opInfo;
    409409                        if ( operatorLookup( nameExpr->get_name(), opInfo ) ) {
     
    474474                                } // switch
    475475                        } else {
    476                                 if ( nameExpr->get_name() == "Range" ) { // case V1 ... V2 or case V1~V2
     476                                if ( nameExpr->get_name() == "..." ) { // case V1 ... V2 or case V1~V2
    477477                                        assert( untypedExpr->get_args().size() == 2 );
    478478                                        (*untypedExpr->get_args().begin())->accept( *this );
     
    494494        }
    495495
    496         void CodeGenerator::visit( NameExpr *nameExpr ) {
     496        void CodeGenerator::visit( NameExpr * nameExpr ) {
    497497                extension( nameExpr );
    498498                OperatorInfo opInfo;
     
    505505        }
    506506
    507         void CodeGenerator::visit( AddressExpr *addressExpr ) {
     507        void CodeGenerator::visit( AddressExpr * addressExpr ) {
    508508                extension( addressExpr );
    509509                output << "(&";
    510510                // this hack makes sure that we don't convert "constant_zero" to "0" if we're taking its address
    511                 if ( VariableExpr *variableExpr = dynamic_cast< VariableExpr* >( addressExpr->get_arg() ) ) {
     511                if ( VariableExpr * variableExpr = dynamic_cast< VariableExpr* >( addressExpr->get_arg() ) ) {
    512512                        output << mangleName( variableExpr->get_var() );
    513513                } else {
     
    517517        }
    518518
    519         void CodeGenerator::visit( CastExpr *castExpr ) {
     519        void CodeGenerator::visit( CastExpr * castExpr ) {
    520520                extension( castExpr );
    521521                output << "(";
     
    535535        }
    536536
    537         void CodeGenerator::visit( UntypedMemberExpr *memberExpr ) {
     537        void CodeGenerator::visit( UntypedMemberExpr * memberExpr ) {
    538538                assert( false );
    539539        }
    540540
    541         void CodeGenerator::visit( MemberExpr *memberExpr ) {
     541        void CodeGenerator::visit( MemberExpr * memberExpr ) {
    542542                extension( memberExpr );
    543543                memberExpr->get_aggregate()->accept( *this );
     
    545545        }
    546546
    547         void CodeGenerator::visit( VariableExpr *variableExpr ) {
     547        void CodeGenerator::visit( VariableExpr * variableExpr ) {
    548548                extension( variableExpr );
    549549                OperatorInfo opInfo;
     
    555555        }
    556556
    557         void CodeGenerator::visit( ConstantExpr *constantExpr ) {
     557        void CodeGenerator::visit( ConstantExpr * constantExpr ) {
    558558                assert( constantExpr->get_constant() );
    559559                extension( constantExpr );
     
    561561        }
    562562
    563         void CodeGenerator::visit( SizeofExpr *sizeofExpr ) {
     563        void CodeGenerator::visit( SizeofExpr * sizeofExpr ) {
    564564                extension( sizeofExpr );
    565565                output << "sizeof(";
     
    572572        }
    573573
    574         void CodeGenerator::visit( AlignofExpr *alignofExpr ) {
     574        void CodeGenerator::visit( AlignofExpr * alignofExpr ) {
    575575                // use GCC extension to avoid bumping std to C11
    576576                extension( alignofExpr );
     
    584584        }
    585585
    586         void CodeGenerator::visit( UntypedOffsetofExpr *offsetofExpr ) {
     586        void CodeGenerator::visit( UntypedOffsetofExpr * offsetofExpr ) {
    587587                assert( false && "UntypedOffsetofExpr should not reach code generation." );
    588588        }
    589589
    590         void CodeGenerator::visit( OffsetofExpr *offsetofExpr ) {
     590        void CodeGenerator::visit( OffsetofExpr * offsetofExpr ) {
    591591                // use GCC builtin
    592592                output << "__builtin_offsetof(";
     
    596596        }
    597597
    598         void CodeGenerator::visit( OffsetPackExpr *offsetPackExpr ) {
     598        void CodeGenerator::visit( OffsetPackExpr * offsetPackExpr ) {
    599599                assert( false && "OffsetPackExpr should not reach code generation." );
    600600        }
    601601
    602         void CodeGenerator::visit( LogicalExpr *logicalExpr ) {
     602        void CodeGenerator::visit( LogicalExpr * logicalExpr ) {
    603603                extension( logicalExpr );
    604604                output << "(";
     
    613613        }
    614614
    615         void CodeGenerator::visit( ConditionalExpr *conditionalExpr ) {
     615        void CodeGenerator::visit( ConditionalExpr * conditionalExpr ) {
    616616                extension( conditionalExpr );
    617617                output << "(";
     
    624624        }
    625625
    626         void CodeGenerator::visit( CommaExpr *commaExpr ) {
     626        void CodeGenerator::visit( CommaExpr * commaExpr ) {
    627627                extension( commaExpr );
    628628                output << "(";
     
    633633        }
    634634
    635         void CodeGenerator::visit( TupleExpr *tupleExpr ) {}
    636 
    637         void CodeGenerator::visit( TypeExpr *typeExpr ) {}
    638 
    639         void CodeGenerator::visit( AsmExpr *asmExpr ) {
     635        void CodeGenerator::visit( TupleExpr * tupleExpr ) {}
     636
     637        void CodeGenerator::visit( TypeExpr * typeExpr ) {}
     638
     639        void CodeGenerator::visit( AsmExpr * asmExpr ) {
    640640                if ( asmExpr->get_inout() ) {
    641641                        output << "[ ";
     
    650650
    651651        //*** Statements
    652         void CodeGenerator::visit( CompoundStmt *compoundStmt ) {
     652        void CodeGenerator::visit( CompoundStmt * compoundStmt ) {
    653653                std::list<Statement*> ks = compoundStmt->get_kids();
    654654                output << "{" << endl;
     
    664664                                output << endl;
    665665                        } // if
    666                 }
     666                } // for
    667667                cur_indent -= CodeGenerator::tabsize;
    668668
     
    670670        }
    671671
    672         void CodeGenerator::visit( ExprStmt *exprStmt ) {
     672        void CodeGenerator::visit( ExprStmt * exprStmt ) {
    673673                assert( exprStmt );
    674674                // cast the top-level expression to void to reduce gcc warnings.
     
    678678        }
    679679
    680         void CodeGenerator::visit( AsmStmt *asmStmt ) {
     680        void CodeGenerator::visit( AsmStmt * asmStmt ) {
    681681                output << "asm ";
    682682                if ( asmStmt->get_voltile() ) output << "volatile ";
     
    701701        }
    702702
    703         void CodeGenerator::visit( IfStmt *ifStmt ) {
     703        void CodeGenerator::visit( IfStmt * ifStmt ) {
    704704                output << "if ( ";
    705705                ifStmt->get_condition()->accept( *this );
     
    714714        }
    715715
    716         void CodeGenerator::visit( SwitchStmt *switchStmt ) {
     716        void CodeGenerator::visit( SwitchStmt * switchStmt ) {
    717717                output << "switch ( " ;
    718718                switchStmt->get_condition()->accept( *this );
     
    721721                output << "{" << std::endl;
    722722                cur_indent += CodeGenerator::tabsize;
    723 
    724                 acceptAll( switchStmt->get_branches(), *this );
    725 
     723                acceptAll( switchStmt->get_statements(), *this );
    726724                cur_indent -= CodeGenerator::tabsize;
    727 
    728725                output << indent << "}";
    729726        }
    730727
    731         void CodeGenerator::visit( CaseStmt *caseStmt ) {
     728        void CodeGenerator::visit( CaseStmt * caseStmt ) {
    732729                output << indent;
    733730                if ( caseStmt->isDefault()) {
     
    750747        }
    751748
    752         void CodeGenerator::visit( BranchStmt *branchStmt ) {
     749        void CodeGenerator::visit( BranchStmt * branchStmt ) {
    753750                switch ( branchStmt->get_type()) {
    754751                  case BranchStmt::Goto:
     
    773770
    774771
    775         void CodeGenerator::visit( ReturnStmt *returnStmt ) {
     772        void CodeGenerator::visit( ReturnStmt * returnStmt ) {
    776773                output << "return ";
    777774                maybeAccept( returnStmt->get_expr(), *this );
     
    779776        }
    780777
    781         void CodeGenerator::visit( WhileStmt *whileStmt ) {
     778        void CodeGenerator::visit( WhileStmt * whileStmt ) {
    782779                if ( whileStmt->get_isDoWhile() ) {
    783780                        output << "do" ;
     
    801798        }
    802799
    803         void CodeGenerator::visit( ForStmt *forStmt ) {
     800        void CodeGenerator::visit( ForStmt * forStmt ) {
    804801                // initialization is always hoisted, so don't bother doing anything with that
    805802                output << "for (;";
     
    823820        }
    824821
    825         void CodeGenerator::visit( NullStmt *nullStmt ) {
     822        void CodeGenerator::visit( NullStmt * nullStmt ) {
    826823                //output << indent << CodeGenerator::printLabels( nullStmt->get_labels() );
    827824                output << "/* null statement */ ;";
    828825        }
    829826
    830         void CodeGenerator::visit( DeclStmt *declStmt ) {
     827        void CodeGenerator::visit( DeclStmt * declStmt ) {
    831828                declStmt->get_decl()->accept( *this );
    832829
     
    836833        }
    837834
    838         void CodeGenerator::handleStorageClass( Declaration *decl ) {
     835        void CodeGenerator::handleStorageClass( Declaration * decl ) {
    839836                switch ( decl->get_storageClass() ) {
    840837                  case DeclarationNode::Extern:
Note: See TracChangeset for help on using the changeset viewer.