Changeset 85c4ef0


Ignore:
Timestamp:
Jul 13, 2015, 2:41:40 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:
145f1fc, dfee306
Parents:
e5609dd
Message:

typedefs nested within aggregates are handled

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    re5609dd r85c4ef0  
    1010// Created On       : Sun May 17 21:50:04 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Jul 08 12:49:36 2015
    13 // Update Count     : 166
     12// Last Modified On : Mon Jul 13 14:38:19 2015
     13// Update Count     : 184
    1414//
    1515
     
    167167                virtual Type *mutate( TypeInstType *aggregateUseType );
    168168                virtual Expression *mutate( CastExpr *castExpr );
     169
     170                virtual Declaration *mutate( StructDecl * structDecl );
     171                virtual Declaration *mutate( UnionDecl * unionDecl );
     172                virtual Declaration *mutate( EnumDecl * enumDecl );
     173                virtual Declaration *mutate( ContextDecl * contextDecl );
     174
     175                template<typename AggDecl>
     176                AggDecl *handleAggregate( AggDecl * aggDecl );
    169177
    170178                typedef std::map< std::string, std::pair< TypedefDecl *, int > > TypedefMap;
     
    800808        }
    801809
    802         Type *EliminateTypedef::mutate( TypeInstType *typeInst ) {
     810        Type *EliminateTypedef::mutate( TypeInstType * typeInst ) {
    803811                // instances of typedef types will come here. If it is an instance
    804812                // of a typdef type, link the instance to its actual type.
     
    813821        }
    814822
    815         Declaration *EliminateTypedef::mutate( TypedefDecl *tyDecl ) {
     823        Declaration *EliminateTypedef::mutate( TypedefDecl * tyDecl ) {
    816824                Declaration *ret = Mutator::mutate( tyDecl );
    817825                if ( typedefNames.count( tyDecl->get_name() ) == 1 && typedefNames[ tyDecl->get_name() ].second == scopeLevel ) {
     
    823831                        if ( ! typeEquals( t1, t2, true ) ) {
    824832                                throw SemanticError( "cannot redefine typedef: " + tyDecl->get_name() );
    825                         } 
     833                        }
    826834                } else {
    827835                        typedefNames[ tyDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel );
     
    845853        }
    846854
    847         TypeDecl *EliminateTypedef::mutate( TypeDecl *typeDecl ) {
     855        TypeDecl *EliminateTypedef::mutate( TypeDecl * typeDecl ) {
    848856                TypedefMap::iterator i = typedefNames.find( typeDecl->get_name() );
    849857                if ( i != typedefNames.end() ) {
     
    853861        }
    854862
    855         DeclarationWithType *EliminateTypedef::mutate( FunctionDecl *funcDecl ) {
     863        DeclarationWithType *EliminateTypedef::mutate( FunctionDecl * funcDecl ) {
    856864                TypedefMap oldNames = typedefNames;
    857865                DeclarationWithType *ret = Mutator::mutate( funcDecl );
     
    860868        }
    861869
    862         ObjectDecl *EliminateTypedef::mutate( ObjectDecl *objDecl ) {
     870        ObjectDecl *EliminateTypedef::mutate( ObjectDecl * objDecl ) {
    863871                TypedefMap oldNames = typedefNames;
    864872                ObjectDecl *ret = Mutator::mutate( objDecl );
     
    867875        }
    868876
    869         Expression *EliminateTypedef::mutate( CastExpr *castExpr ) {
     877        Expression *EliminateTypedef::mutate( CastExpr * castExpr ) {
    870878                TypedefMap oldNames = typedefNames;
    871879                Expression *ret = Mutator::mutate( castExpr );
     
    874882        }
    875883
    876         CompoundStmt *EliminateTypedef::mutate( CompoundStmt *compoundStmt ) {
     884        CompoundStmt *EliminateTypedef::mutate( CompoundStmt * compoundStmt ) {
    877885                TypedefMap oldNames = typedefNames;
    878886                scopeLevel += 1;
     
    881889                std::list< Statement * >::iterator i = compoundStmt->get_kids().begin();
    882890                while ( i != compoundStmt->get_kids().end() ) {
    883                         std::list< Statement * >::iterator next = i;
    884                         ++next;
     891                        std::list< Statement * >::iterator next = i+1;
    885892                        if ( DeclStmt *declStmt = dynamic_cast< DeclStmt * >( *i ) ) {
    886893                                if ( dynamic_cast< TypedefDecl * >( declStmt->get_decl() ) ) {
     
    894901                return ret;
    895902        }
     903
     904        // there may be typedefs nested within aggregates
     905        // in order for everything to work properly, these
     906        // should be removed as well
     907        template<typename AggDecl>
     908        AggDecl *EliminateTypedef::handleAggregate( AggDecl * aggDecl ) {
     909                std::list<Declaration *>::iterator it = aggDecl->get_members().begin();
     910                for ( ; it != aggDecl->get_members().end(); ) {
     911                        std::list< Declaration * >::iterator next = it+1;
     912                        if ( dynamic_cast< TypedefDecl * >( *it ) ) {
     913                                delete *it;
     914                                aggDecl->get_members().erase( it );
     915                        } // if
     916                        it = next;
     917                }
     918                return aggDecl;
     919        }
     920
     921        Declaration *EliminateTypedef::mutate( StructDecl * structDecl ) {
     922                Mutator::mutate( structDecl );
     923                return handleAggregate( structDecl );
     924        }
     925
     926        Declaration *EliminateTypedef::mutate( UnionDecl * unionDecl ) {
     927                Mutator::mutate( unionDecl );
     928                return handleAggregate( unionDecl );
     929        }
     930
     931        Declaration *EliminateTypedef::mutate( EnumDecl * enumDecl ) {
     932                Mutator::mutate( enumDecl );
     933                return handleAggregate( enumDecl );
     934        }
     935
     936                Declaration *EliminateTypedef::mutate( ContextDecl * contextDecl ) {
     937                Mutator::mutate( contextDecl );
     938                return handleAggregate( contextDecl );
     939        }
     940
    896941} // namespace SymTab
    897942
Note: See TracChangeset for help on using the changeset viewer.