Changes in / [cff1143:dfee306]


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    rcff1143 rdfee306  
    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.
     
    818826        }
    819827
    820         Declaration *EliminateTypedef::mutate( TypedefDecl *tyDecl ) {
     828        Declaration *EliminateTypedef::mutate( TypedefDecl * tyDecl ) {
    821829                Declaration *ret = Mutator::mutate( tyDecl );
    822830                if ( typedefNames.count( tyDecl->get_name() ) == 1 && typedefNames[ tyDecl->get_name() ].second == scopeLevel ) {
     
    828836                        if ( ! typeEquals( t1, t2, true ) ) {
    829837                                throw SemanticError( "cannot redefine typedef: " + tyDecl->get_name() );
    830                         } 
     838                        }
    831839                } else {
    832840                        typedefNames[ tyDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel );
     
    850858        }
    851859
    852         TypeDecl *EliminateTypedef::mutate( TypeDecl *typeDecl ) {
     860        TypeDecl *EliminateTypedef::mutate( TypeDecl * typeDecl ) {
    853861                TypedefMap::iterator i = typedefNames.find( typeDecl->get_name() );
    854862                if ( i != typedefNames.end() ) {
     
    858866        }
    859867
    860         DeclarationWithType *EliminateTypedef::mutate( FunctionDecl *funcDecl ) {
     868        DeclarationWithType *EliminateTypedef::mutate( FunctionDecl * funcDecl ) {
    861869                TypedefMap oldNames = typedefNames;
    862870                DeclarationWithType *ret = Mutator::mutate( funcDecl );
     
    865873        }
    866874
    867         ObjectDecl *EliminateTypedef::mutate( ObjectDecl *objDecl ) {
     875        ObjectDecl *EliminateTypedef::mutate( ObjectDecl * objDecl ) {
    868876                TypedefMap oldNames = typedefNames;
    869877                ObjectDecl *ret = Mutator::mutate( objDecl );
     
    872880        }
    873881
    874         Expression *EliminateTypedef::mutate( CastExpr *castExpr ) {
     882        Expression *EliminateTypedef::mutate( CastExpr * castExpr ) {
    875883                TypedefMap oldNames = typedefNames;
    876884                Expression *ret = Mutator::mutate( castExpr );
     
    879887        }
    880888
    881         CompoundStmt *EliminateTypedef::mutate( CompoundStmt *compoundStmt ) {
     889        CompoundStmt *EliminateTypedef::mutate( CompoundStmt * compoundStmt ) {
    882890                TypedefMap oldNames = typedefNames;
    883891                scopeLevel += 1;
     
    886894                std::list< Statement * >::iterator i = compoundStmt->get_kids().begin();
    887895                while ( i != compoundStmt->get_kids().end() ) {
    888                         std::list< Statement * >::iterator next = i;
    889                         ++next;
     896                        std::list< Statement * >::iterator next = i+1;
    890897                        if ( DeclStmt *declStmt = dynamic_cast< DeclStmt * >( *i ) ) {
    891898                                if ( dynamic_cast< TypedefDecl * >( declStmt->get_decl() ) ) {
     
    899906                return ret;
    900907        }
     908
     909        // there may be typedefs nested within aggregates
     910        // in order for everything to work properly, these
     911        // should be removed as well
     912        template<typename AggDecl>
     913        AggDecl *EliminateTypedef::handleAggregate( AggDecl * aggDecl ) {
     914                std::list<Declaration *>::iterator it = aggDecl->get_members().begin();
     915                for ( ; it != aggDecl->get_members().end(); ) {
     916                        std::list< Declaration * >::iterator next = it+1;
     917                        if ( dynamic_cast< TypedefDecl * >( *it ) ) {
     918                                delete *it;
     919                                aggDecl->get_members().erase( it );
     920                        } // if
     921                        it = next;
     922                }
     923                return aggDecl;
     924        }
     925
     926        Declaration *EliminateTypedef::mutate( StructDecl * structDecl ) {
     927                Mutator::mutate( structDecl );
     928                return handleAggregate( structDecl );
     929        }
     930
     931        Declaration *EliminateTypedef::mutate( UnionDecl * unionDecl ) {
     932                Mutator::mutate( unionDecl );
     933                return handleAggregate( unionDecl );
     934        }
     935
     936        Declaration *EliminateTypedef::mutate( EnumDecl * enumDecl ) {
     937                Mutator::mutate( enumDecl );
     938                return handleAggregate( enumDecl );
     939        }
     940
     941                Declaration *EliminateTypedef::mutate( ContextDecl * contextDecl ) {
     942                Mutator::mutate( contextDecl );
     943                return handleAggregate( contextDecl );
     944        }
     945
    901946} // namespace SymTab
    902947
Note: See TracChangeset for help on using the changeset viewer.