Changeset 94b4364


Ignore:
Timestamp:
Jun 16, 2015, 3:49:36 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
94e0864d
Parents:
b5b0907
Message:

implemented resolver methods for aggregate initialization

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    rb5b0907 r94b4364  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Mon Jun 15 12:43:21 2015
    13 // Update Count     : 138
     12// Last Modified On : Mon Jun 15 12:47:16 2015
     13// Update Count     : 142
    1414//
    1515
     
    7171                } // if
    7272        }
    73  
     73
    7474        //*** Declarations
    7575        void CodeGenerator::visit( FunctionDecl *functionDecl ) {
     
    113113
    114114                if ( ! memb.empty() ) {
    115                         output << endl << indent << "{" << endl;
     115                        output << " {" << endl;
    116116
    117117                        cur_indent += CodeGenerator::tabsize;
  • src/ResolvExpr/Resolver.cc

    rb5b0907 r94b4364  
    1010// Created On       : Sun May 17 12:17:01 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Jun 10 16:11:19 2015
    13 // Update Count     : 77
     12// Last Modified On : Tue Jun 16 14:50:11 2015
     13// Update Count     : 154
    1414//
    1515
     
    3737                virtual void visit( ObjectDecl *functionDecl );
    3838                virtual void visit( TypeDecl *typeDecl );
     39
    3940                virtual void visit( ArrayType * at );
    4041
     
    5152                virtual void visit( ListInit *listInit );
    5253          private:
     54        typedef std::list< Initializer * >::iterator InitIterator;
     55
     56          void resolveAggrInit( AggregateDecl *, InitIterator &, InitIterator & );
     57          void resolveSingleAggrInit( Declaration *, InitIterator &, InitIterator & );
     58
    5359                std::list< Type * > functionReturn;
    5460                Type *initContext;
     
    167173                        delete at->get_dimension();
    168174                        at->set_dimension( newExpr );
    169 
    170175                }
    171176                Visitor::visit( at );
    172177        }
    173  
     178
    174179        void Resolver::visit( TypeDecl *typeDecl ) {
    175180                if ( typeDecl->get_base() ) {
     
    179184                SymTab::Indexer::visit( typeDecl );
    180185        }
    181  
     186
    182187        void Resolver::visit( FunctionDecl *functionDecl ) {
    183188#if 0
     
    329334        }
    330335
    331         void Resolver::visit( ListInit *listInit ) {
     336        void Resolver::resolveSingleAggrInit( Declaration * dcl, InitIterator & init, InitIterator & initEnd ) {
     337                DeclarationWithType * dt = dynamic_cast< DeclarationWithType * >( dcl );
     338                assert( dt );
     339                initContext = dt->get_type();
     340                try {
     341                        if ( init == initEnd ) return; // stop when there are no more initializers
     342                        (*init)->accept( *this );
     343                        ++init; // made it past an initializer
     344                } catch( SemanticError & ) {
     345                        // need to delve deeper, if you can
     346                        if ( StructInstType * sit = dynamic_cast< StructInstType * >( dt->get_type() ) ) {
     347                                resolveAggrInit( sit->get_baseStruct(), init, initEnd );
     348                        } else if ( UnionInstType * uit = dynamic_cast< UnionInstType * >( dt->get_type() ) ) {
     349                                resolveAggrInit( uit->get_baseUnion(), init, initEnd );
     350                        } else {
     351                                // might need to rethink what is being thrown
     352                                throw;
     353                        } // if
     354                }
     355        }
     356
     357        void Resolver::resolveAggrInit( AggregateDecl * aggr, InitIterator & init, InitIterator & initEnd ) {
     358                if ( StructDecl * st = dynamic_cast< StructDecl * >( aggr ) ) {
     359                        // want to resolve each initializer to the members of the struct,
     360                        // but if there are more initializers than members we should stop
     361                        list< Declaration * >::iterator it = st->get_members().begin();
     362                        for ( ; it != st->get_members().end(); ++it) {
     363                                resolveSingleAggrInit( *it, init, initEnd );
     364                        }
     365                } else if ( UnionDecl * un = dynamic_cast< UnionDecl * >( aggr ) ) {
     366                        // only resolve to the first member of a union
     367                        resolveSingleAggrInit( *un->get_members().begin(), init, initEnd );
     368                } // if
     369        }
     370
     371        void Resolver::visit( ListInit * listInit ) {
     372                InitIterator iter = listInit->begin_initializers();
     373                InitIterator end = listInit->end_initializers();
     374
    332375                if ( ArrayType * at = dynamic_cast< ArrayType * >( initContext ) ) {
    333                         std::list< Initializer * >::iterator iter( listInit->begin_initializers() );
    334                         for ( ; iter != listInit->end_initializers(); ++iter ) {
     376                        // resolve each member to the base type of the array
     377                        for ( ; iter != end; ++iter ) {
    335378                                initContext = at->get_base();
    336379                                (*iter)->accept( *this );
    337380                        } // for
     381                } else if ( StructInstType * st = dynamic_cast< StructInstType * >( initContext ) ) {
     382                        resolveAggrInit( st->get_baseStruct(), iter, end );
    338383                } else if ( UnionInstType *st = dynamic_cast< UnionInstType * >( initContext ) ) {
    339                         DeclarationWithType *dt = dynamic_cast< DeclarationWithType * >( *st->get_baseUnion()->get_members().begin() );
    340                         initContext = dt->get_type();
    341                         (*listInit->begin_initializers())->accept( *this );
     384                        resolveAggrInit( st->get_baseUnion(), iter, end );
    342385                } else {
    343386                        // basic types are handled here
Note: See TracChangeset for help on using the changeset viewer.