Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    r85c4ef0 r0215a76f  
    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
     
    6060        class HoistStruct : public Visitor {
    6161          public:
     62                /// Flattens nested struct types
    6263                static void hoistStruct( std::list< Declaration * > &translationUnit );
    6364 
     
    8485        };
    8586
     87        /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers
    8688        class Pass1 : public Visitor {
    8789                typedef Visitor Parent;
     
    8991                virtual void visit( FunctionType *func );
    9092        };
    91  
     93
     94        /// Associates forward declarations of aggregates with their definitions
    9295        class Pass2 : public Indexer {
    9396                typedef Indexer Parent;
     
    110113        };
    111114
     115        /// Replaces array and function types in forall lists by appropriate pointer type
    112116        class Pass3 : public Indexer {
    113117                typedef Indexer Parent;
     
    123127        class AddStructAssignment : public Visitor {
    124128          public:
     129                /// Generates assignment operators for aggregate types as required
    125130                static void addStructAssignment( std::list< Declaration * > &translationUnit );
    126131
     
    167172                virtual Type *mutate( TypeInstType *aggregateUseType );
    168173                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 );
    177174
    178175                typedef std::map< std::string, std::pair< TypedefDecl *, int > > TypedefMap;
     
    444441        }
    445442
     443        /// Fix up assertions
    446444        void forallFixer( Type *func ) {
    447                 // Fix up assertions
    448445                for ( std::list< TypeDecl * >::iterator type = func->get_forall().begin(); type != func->get_forall().end(); ++type ) {
    449446                        std::list< DeclarationWithType * > toBeDone, nextRound;
     
    808805        }
    809806
    810         Type *EliminateTypedef::mutate( TypeInstType * typeInst ) {
     807        Type *EliminateTypedef::mutate( TypeInstType *typeInst ) {
    811808                // instances of typedef types will come here. If it is an instance
    812809                // of a typdef type, link the instance to its actual type.
     
    815812                        Type *ret = def->second.first->get_base()->clone();
    816813                        ret->get_qualifiers() += typeInst->get_qualifiers();
     814                        // place instance parameters on the typedef'd type
     815                        if ( ! typeInst->get_parameters().empty() ) {
     816                                ReferenceToType *rtt = dynamic_cast<ReferenceToType*>(ret);
     817                                if ( ! rtt ) {
     818                                        throw SemanticError("cannot apply type parameters to base type of " + typeInst->get_name());
     819                                }
     820                                rtt->get_parameters().clear();
     821                                cloneAll(typeInst->get_parameters(), rtt->get_parameters());
     822                        }
    817823                        delete typeInst;
    818824                        return ret;
     
    821827        }
    822828
    823         Declaration *EliminateTypedef::mutate( TypedefDecl * tyDecl ) {
     829        Declaration *EliminateTypedef::mutate( TypedefDecl *tyDecl ) {
    824830                Declaration *ret = Mutator::mutate( tyDecl );
    825831                if ( typedefNames.count( tyDecl->get_name() ) == 1 && typedefNames[ tyDecl->get_name() ].second == scopeLevel ) {
     
    831837                        if ( ! typeEquals( t1, t2, true ) ) {
    832838                                throw SemanticError( "cannot redefine typedef: " + tyDecl->get_name() );
    833                         }
     839                        } 
    834840                } else {
    835841                        typedefNames[ tyDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel );
     
    853859        }
    854860
    855         TypeDecl *EliminateTypedef::mutate( TypeDecl * typeDecl ) {
     861        TypeDecl *EliminateTypedef::mutate( TypeDecl *typeDecl ) {
    856862                TypedefMap::iterator i = typedefNames.find( typeDecl->get_name() );
    857863                if ( i != typedefNames.end() ) {
     
    861867        }
    862868
    863         DeclarationWithType *EliminateTypedef::mutate( FunctionDecl * funcDecl ) {
     869        DeclarationWithType *EliminateTypedef::mutate( FunctionDecl *funcDecl ) {
    864870                TypedefMap oldNames = typedefNames;
    865871                DeclarationWithType *ret = Mutator::mutate( funcDecl );
     
    868874        }
    869875
    870         ObjectDecl *EliminateTypedef::mutate( ObjectDecl * objDecl ) {
     876        ObjectDecl *EliminateTypedef::mutate( ObjectDecl *objDecl ) {
    871877                TypedefMap oldNames = typedefNames;
    872878                ObjectDecl *ret = Mutator::mutate( objDecl );
     
    875881        }
    876882
    877         Expression *EliminateTypedef::mutate( CastExpr * castExpr ) {
     883        Expression *EliminateTypedef::mutate( CastExpr *castExpr ) {
    878884                TypedefMap oldNames = typedefNames;
    879885                Expression *ret = Mutator::mutate( castExpr );
     
    882888        }
    883889
    884         CompoundStmt *EliminateTypedef::mutate( CompoundStmt * compoundStmt ) {
     890        CompoundStmt *EliminateTypedef::mutate( CompoundStmt *compoundStmt ) {
    885891                TypedefMap oldNames = typedefNames;
    886892                scopeLevel += 1;
     
    889895                std::list< Statement * >::iterator i = compoundStmt->get_kids().begin();
    890896                while ( i != compoundStmt->get_kids().end() ) {
    891                         std::list< Statement * >::iterator next = i+1;
     897                        std::list< Statement * >::iterator next = i;
     898                        ++next;
    892899                        if ( DeclStmt *declStmt = dynamic_cast< DeclStmt * >( *i ) ) {
    893900                                if ( dynamic_cast< TypedefDecl * >( declStmt->get_decl() ) ) {
     
    901908                return ret;
    902909        }
    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 
    941910} // namespace SymTab
    942911
Note: See TracChangeset for help on using the changeset viewer.