Changeset e4d829b for src/CodeGen


Ignore:
Timestamp:
Jun 20, 2017, 1:19:53 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
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:
579263a
Parents:
c6d2e93
git-author:
Rob Schluntz <rschlunt@…> (06/20/17 13:16:13)
git-committer:
Rob Schluntz <rschlunt@…> (06/20/17 13:19:53)
Message:

major effort on designations, works in many cases

Location:
src/CodeGen
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    rc6d2e93 re4d829b  
    298298        }
    299299
    300         void CodeGenerator::printDesignators( std::list< Expression * > & designators ) {
    301                 typedef std::list< Expression * > DesignatorList;
     300        void CodeGenerator::visit( Designation * designation ) {
     301                std::list< Expression * > designators = designation->get_designators();
    302302                if ( designators.size() == 0 ) return;
    303                 for ( DesignatorList::iterator iter = designators.begin(); iter != designators.end(); ++iter ) {
    304                         if ( dynamic_cast< NameExpr * >( *iter ) ) {
    305                                 // if expression is a name, then initializing aggregate member
     303                for ( Expression * des : designators ) {
     304                        if ( dynamic_cast< ConstantExpr * >( des ) ) {
     305                                // if expression is a ConstantExpr, then initializing array element
     306                                output << "[";
     307                                des->accept( *this );
     308                                output << "]";
     309                        } else {
     310                                // if not a ConstantExpr, it has to be a NameExpr or VariableExpr, initializing aggregate member
    306311                                output << ".";
    307                                 (*iter)->accept( *this );
    308                         } else {
    309                                 // if not a simple name, it has to be a constant expression, i.e. an array designator
    310                                 output << "[";
    311                                 (*iter)->accept( *this );
    312                                 output << "]";
     312                                des->accept( *this );
    313313                        } // if
    314314                } // for
     
    317317
    318318        void CodeGenerator::visit( SingleInit * init ) {
    319                 printDesignators( init->get_designators() );
    320319                init->get_value()->accept( *this );
    321320        }
    322321
    323322        void CodeGenerator::visit( ListInit * init ) {
    324                 printDesignators( init->get_designators() );
     323                auto initBegin = init->begin();
     324                auto initEnd = init->end();
     325                auto desigBegin = init->get_designations().begin();
     326                auto desigEnd = init->get_designations().end();
     327
    325328                output << "{ ";
    326                 genCommaList( init->begin(), init->end() );
     329                for ( ; initBegin != initEnd && desigBegin != desigEnd; ) {
     330                        (*desigBegin)->accept( *this );
     331                        (*initBegin)->accept( *this );
     332                        ++initBegin, ++desigBegin;
     333                        if ( initBegin != initEnd ) {
     334                                output << ", ";
     335                        }
     336                }
    327337                output << " }";
     338                assertf( initBegin == initEnd && desigBegin == desigEnd, "Initializers and designators not the same length. %s", toString( init ).c_str() );
    328339        }
    329340
     
    726737
    727738        void CodeGenerator::visit( TypeExpr * typeExpr ) {
    728                 assertf( ! genC, "TypeExpr should not reach code generation." );
    729                 output<< genType( typeExpr->get_type(), "", pretty, genC );
     739                // if ( genC ) std::cerr << "typeexpr still exists: " << typeExpr << std::endl;
     740                // assertf( ! genC, "TypeExpr should not reach code generation." );
     741                if ( ! genC ) {
     742                        output<< genType( typeExpr->get_type(), "", pretty, genC );
     743                }
    730744        }
    731745
  • src/CodeGen/CodeGenerator.h

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