Changeset 67fa9f9 for src/CodeGen


Ignore:
Timestamp:
Jul 5, 2017, 10:50:22 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:
0614d14
Parents:
11dbfe1 (diff), 307a732 (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

Location:
src/CodeGen
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r11dbfe1 r67fa9f9  
    288288        }
    289289
    290         void CodeGenerator::printDesignators( std::list< Expression * > & designators ) {
    291                 typedef std::list< Expression * > DesignatorList;
     290        void CodeGenerator::visit( Designation * designation ) {
     291                std::list< Expression * > designators = designation->get_designators();
    292292                if ( designators.size() == 0 ) return;
    293                 for ( DesignatorList::iterator iter = designators.begin(); iter != designators.end(); ++iter ) {
    294                         if ( dynamic_cast< NameExpr * >( *iter ) ) {
    295                                 // if expression is a name, then initializing aggregate member
     293                for ( Expression * des : designators ) {
     294                        if ( dynamic_cast< NameExpr * >( des ) || dynamic_cast< VariableExpr * >( des ) ) {
     295                                // if expression is a NameExpr or VariableExpr, then initializing aggregate member
    296296                                output << ".";
    297                                 (*iter)->accept( *this );
     297                                des->accept( *this );
    298298                        } else {
    299                                 // if not a simple name, it has to be a constant expression, i.e. an array designator
     299                                // otherwise, it has to be a ConstantExpr or CastExpr, initializing array eleemnt
    300300                                output << "[";
    301                                 (*iter)->accept( *this );
     301                                des->accept( *this );
    302302                                output << "]";
    303303                        } // if
     
    307307
    308308        void CodeGenerator::visit( SingleInit * init ) {
    309                 printDesignators( init->get_designators() );
    310309                init->get_value()->accept( *this );
    311310        }
    312311
    313312        void CodeGenerator::visit( ListInit * init ) {
    314                 printDesignators( init->get_designators() );
     313                auto initBegin = init->begin();
     314                auto initEnd = init->end();
     315                auto desigBegin = init->get_designations().begin();
     316                auto desigEnd = init->get_designations().end();
     317
    315318                output << "{ ";
    316                 genCommaList( init->begin(), init->end() );
     319                for ( ; initBegin != initEnd && desigBegin != desigEnd; ) {
     320                        (*desigBegin)->accept( *this );
     321                        (*initBegin)->accept( *this );
     322                        ++initBegin, ++desigBegin;
     323                        if ( initBegin != initEnd ) {
     324                                output << ", ";
     325                        }
     326                }
    317327                output << " }";
     328                assertf( initBegin == initEnd && desigBegin == desigEnd, "Initializers and designators not the same length. %s", toString( init ).c_str() );
    318329        }
    319330
     
    716727
    717728        void CodeGenerator::visit( TypeExpr * typeExpr ) {
    718                 assertf( ! genC, "TypeExpr should not reach code generation." );
    719                 output<< genType( typeExpr->get_type(), "", pretty, genC );
     729                // if ( genC ) std::cerr << "typeexpr still exists: " << typeExpr << std::endl;
     730                // assertf( ! genC, "TypeExpr should not reach code generation." );
     731                if ( ! genC ) {
     732                        output<< genType( typeExpr->get_type(), "", pretty, genC );
     733                }
    720734        }
    721735
  • src/CodeGen/CodeGenerator.h

    r11dbfe1 r67fa9f9  
    4747
    4848                //*** Initializer
     49                virtual void visit( Designation * );
    4950                virtual void visit( SingleInit * );
    5051                virtual void visit( ListInit * );
     
    137138                bool lineMarks = false;
    138139
    139                 void printDesignators( std::list< Expression * > & );
    140140                void handleStorageClass( DeclarationWithType *decl );
    141141                void handleAggregate( AggregateDecl *aggDecl, const std::string & kind );
Note: See TracChangeset for help on using the changeset viewer.