Changeset 9163b9c


Ignore:
Timestamp:
Jul 14, 2015, 11:31:54 AM (9 years ago)
Author:
Aaron Moss <a3moss@…>
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:
34e3732, 724c2b6
Parents:
0215a76f (diff), dfee306 (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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    r0215a76f r9163b9c  
    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
     
    172172                virtual Type *mutate( TypeInstType *aggregateUseType );
    173173                virtual Expression *mutate( CastExpr *castExpr );
     174
     175                virtual Declaration *mutate( StructDecl * structDecl );
     176                virtual Declaration *mutate( UnionDecl * unionDecl );
     177                virtual Declaration *mutate( EnumDecl * enumDecl );
     178                virtual Declaration *mutate( ContextDecl * contextDecl );
     179
     180                template<typename AggDecl>
     181                AggDecl *handleAggregate( AggDecl * aggDecl );
    174182
    175183                typedef std::map< std::string, std::pair< TypedefDecl *, int > > TypedefMap;
     
    805813        }
    806814
    807         Type *EliminateTypedef::mutate( TypeInstType *typeInst ) {
     815        Type *EliminateTypedef::mutate( TypeInstType * typeInst ) {
    808816                // instances of typedef types will come here. If it is an instance
    809817                // of a typdef type, link the instance to its actual type.
     
    827835        }
    828836
    829         Declaration *EliminateTypedef::mutate( TypedefDecl *tyDecl ) {
     837        Declaration *EliminateTypedef::mutate( TypedefDecl * tyDecl ) {
    830838                Declaration *ret = Mutator::mutate( tyDecl );
    831839                if ( typedefNames.count( tyDecl->get_name() ) == 1 && typedefNames[ tyDecl->get_name() ].second == scopeLevel ) {
     
    837845                        if ( ! typeEquals( t1, t2, true ) ) {
    838846                                throw SemanticError( "cannot redefine typedef: " + tyDecl->get_name() );
    839                         } 
     847                        }
    840848                } else {
    841849                        typedefNames[ tyDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel );
     
    859867        }
    860868
    861         TypeDecl *EliminateTypedef::mutate( TypeDecl *typeDecl ) {
     869        TypeDecl *EliminateTypedef::mutate( TypeDecl * typeDecl ) {
    862870                TypedefMap::iterator i = typedefNames.find( typeDecl->get_name() );
    863871                if ( i != typedefNames.end() ) {
     
    867875        }
    868876
    869         DeclarationWithType *EliminateTypedef::mutate( FunctionDecl *funcDecl ) {
     877        DeclarationWithType *EliminateTypedef::mutate( FunctionDecl * funcDecl ) {
    870878                TypedefMap oldNames = typedefNames;
    871879                DeclarationWithType *ret = Mutator::mutate( funcDecl );
     
    874882        }
    875883
    876         ObjectDecl *EliminateTypedef::mutate( ObjectDecl *objDecl ) {
     884        ObjectDecl *EliminateTypedef::mutate( ObjectDecl * objDecl ) {
    877885                TypedefMap oldNames = typedefNames;
    878886                ObjectDecl *ret = Mutator::mutate( objDecl );
     
    881889        }
    882890
    883         Expression *EliminateTypedef::mutate( CastExpr *castExpr ) {
     891        Expression *EliminateTypedef::mutate( CastExpr * castExpr ) {
    884892                TypedefMap oldNames = typedefNames;
    885893                Expression *ret = Mutator::mutate( castExpr );
     
    888896        }
    889897
    890         CompoundStmt *EliminateTypedef::mutate( CompoundStmt *compoundStmt ) {
     898        CompoundStmt *EliminateTypedef::mutate( CompoundStmt * compoundStmt ) {
    891899                TypedefMap oldNames = typedefNames;
    892900                scopeLevel += 1;
     
    895903                std::list< Statement * >::iterator i = compoundStmt->get_kids().begin();
    896904                while ( i != compoundStmt->get_kids().end() ) {
    897                         std::list< Statement * >::iterator next = i;
    898                         ++next;
     905                        std::list< Statement * >::iterator next = i+1;
    899906                        if ( DeclStmt *declStmt = dynamic_cast< DeclStmt * >( *i ) ) {
    900907                                if ( dynamic_cast< TypedefDecl * >( declStmt->get_decl() ) ) {
     
    908915                return ret;
    909916        }
     917
     918        // there may be typedefs nested within aggregates
     919        // in order for everything to work properly, these
     920        // should be removed as well
     921        template<typename AggDecl>
     922        AggDecl *EliminateTypedef::handleAggregate( AggDecl * aggDecl ) {
     923                std::list<Declaration *>::iterator it = aggDecl->get_members().begin();
     924                for ( ; it != aggDecl->get_members().end(); ) {
     925                        std::list< Declaration * >::iterator next = it+1;
     926                        if ( dynamic_cast< TypedefDecl * >( *it ) ) {
     927                                delete *it;
     928                                aggDecl->get_members().erase( it );
     929                        } // if
     930                        it = next;
     931                }
     932                return aggDecl;
     933        }
     934
     935        Declaration *EliminateTypedef::mutate( StructDecl * structDecl ) {
     936                Mutator::mutate( structDecl );
     937                return handleAggregate( structDecl );
     938        }
     939
     940        Declaration *EliminateTypedef::mutate( UnionDecl * unionDecl ) {
     941                Mutator::mutate( unionDecl );
     942                return handleAggregate( unionDecl );
     943        }
     944
     945        Declaration *EliminateTypedef::mutate( EnumDecl * enumDecl ) {
     946                Mutator::mutate( enumDecl );
     947                return handleAggregate( enumDecl );
     948        }
     949
     950                Declaration *EliminateTypedef::mutate( ContextDecl * contextDecl ) {
     951                Mutator::mutate( contextDecl );
     952                return handleAggregate( contextDecl );
     953        }
     954
    910955} // namespace SymTab
    911956
Note: See TracChangeset for help on using the changeset viewer.