Changes in / [dfee306:cff1143]


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    rdfee306 rcff1143  
    1010// Created On       : Sun May 17 21:50:04 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Mon Jul 13 14:38:19 2015
    13 // Update Count     : 184
     12// Last Modified On : Wed Jul 08 12:49:36 2015
     13// Update Count     : 166
    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 );
    182174
    183175                typedef std::map< std::string, std::pair< TypedefDecl *, int > > TypedefMap;
     
    813805        }
    814806
    815         Type *EliminateTypedef::mutate( TypeInstType * typeInst ) {
     807        Type *EliminateTypedef::mutate( TypeInstType *typeInst ) {
    816808                // instances of typedef types will come here. If it is an instance
    817809                // of a typdef type, link the instance to its actual type.
     
    826818        }
    827819
    828         Declaration *EliminateTypedef::mutate( TypedefDecl * tyDecl ) {
     820        Declaration *EliminateTypedef::mutate( TypedefDecl *tyDecl ) {
    829821                Declaration *ret = Mutator::mutate( tyDecl );
    830822                if ( typedefNames.count( tyDecl->get_name() ) == 1 && typedefNames[ tyDecl->get_name() ].second == scopeLevel ) {
     
    836828                        if ( ! typeEquals( t1, t2, true ) ) {
    837829                                throw SemanticError( "cannot redefine typedef: " + tyDecl->get_name() );
    838                         }
     830                        } 
    839831                } else {
    840832                        typedefNames[ tyDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel );
     
    858850        }
    859851
    860         TypeDecl *EliminateTypedef::mutate( TypeDecl * typeDecl ) {
     852        TypeDecl *EliminateTypedef::mutate( TypeDecl *typeDecl ) {
    861853                TypedefMap::iterator i = typedefNames.find( typeDecl->get_name() );
    862854                if ( i != typedefNames.end() ) {
     
    866858        }
    867859
    868         DeclarationWithType *EliminateTypedef::mutate( FunctionDecl * funcDecl ) {
     860        DeclarationWithType *EliminateTypedef::mutate( FunctionDecl *funcDecl ) {
    869861                TypedefMap oldNames = typedefNames;
    870862                DeclarationWithType *ret = Mutator::mutate( funcDecl );
     
    873865        }
    874866
    875         ObjectDecl *EliminateTypedef::mutate( ObjectDecl * objDecl ) {
     867        ObjectDecl *EliminateTypedef::mutate( ObjectDecl *objDecl ) {
    876868                TypedefMap oldNames = typedefNames;
    877869                ObjectDecl *ret = Mutator::mutate( objDecl );
     
    880872        }
    881873
    882         Expression *EliminateTypedef::mutate( CastExpr * castExpr ) {
     874        Expression *EliminateTypedef::mutate( CastExpr *castExpr ) {
    883875                TypedefMap oldNames = typedefNames;
    884876                Expression *ret = Mutator::mutate( castExpr );
     
    887879        }
    888880
    889         CompoundStmt *EliminateTypedef::mutate( CompoundStmt * compoundStmt ) {
     881        CompoundStmt *EliminateTypedef::mutate( CompoundStmt *compoundStmt ) {
    890882                TypedefMap oldNames = typedefNames;
    891883                scopeLevel += 1;
     
    894886                std::list< Statement * >::iterator i = compoundStmt->get_kids().begin();
    895887                while ( i != compoundStmt->get_kids().end() ) {
    896                         std::list< Statement * >::iterator next = i+1;
     888                        std::list< Statement * >::iterator next = i;
     889                        ++next;
    897890                        if ( DeclStmt *declStmt = dynamic_cast< DeclStmt * >( *i ) ) {
    898891                                if ( dynamic_cast< TypedefDecl * >( declStmt->get_decl() ) ) {
     
    906899                return ret;
    907900        }
    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 
    946901} // namespace SymTab
    947902
Note: See TracChangeset for help on using the changeset viewer.