Changeset 85c4ef0
- Timestamp:
- Jul 13, 2015, 2:41:40 PM (10 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
re5609dd r85c4ef0 10 10 // Created On : Sun May 17 21:50:04 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jul 08 12:49:36201513 // Update Count : 1 6612 // Last Modified On : Mon Jul 13 14:38:19 2015 13 // Update Count : 184 14 14 // 15 15 … … 167 167 virtual Type *mutate( TypeInstType *aggregateUseType ); 168 168 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 ); 169 177 170 178 typedef std::map< std::string, std::pair< TypedefDecl *, int > > TypedefMap; … … 800 808 } 801 809 802 Type *EliminateTypedef::mutate( TypeInstType * typeInst ) {810 Type *EliminateTypedef::mutate( TypeInstType * typeInst ) { 803 811 // instances of typedef types will come here. If it is an instance 804 812 // of a typdef type, link the instance to its actual type. … … 813 821 } 814 822 815 Declaration *EliminateTypedef::mutate( TypedefDecl * tyDecl ) {823 Declaration *EliminateTypedef::mutate( TypedefDecl * tyDecl ) { 816 824 Declaration *ret = Mutator::mutate( tyDecl ); 817 825 if ( typedefNames.count( tyDecl->get_name() ) == 1 && typedefNames[ tyDecl->get_name() ].second == scopeLevel ) { … … 823 831 if ( ! typeEquals( t1, t2, true ) ) { 824 832 throw SemanticError( "cannot redefine typedef: " + tyDecl->get_name() ); 825 } 833 } 826 834 } else { 827 835 typedefNames[ tyDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel ); … … 845 853 } 846 854 847 TypeDecl *EliminateTypedef::mutate( TypeDecl * typeDecl ) {855 TypeDecl *EliminateTypedef::mutate( TypeDecl * typeDecl ) { 848 856 TypedefMap::iterator i = typedefNames.find( typeDecl->get_name() ); 849 857 if ( i != typedefNames.end() ) { … … 853 861 } 854 862 855 DeclarationWithType *EliminateTypedef::mutate( FunctionDecl * funcDecl ) {863 DeclarationWithType *EliminateTypedef::mutate( FunctionDecl * funcDecl ) { 856 864 TypedefMap oldNames = typedefNames; 857 865 DeclarationWithType *ret = Mutator::mutate( funcDecl ); … … 860 868 } 861 869 862 ObjectDecl *EliminateTypedef::mutate( ObjectDecl * objDecl ) {870 ObjectDecl *EliminateTypedef::mutate( ObjectDecl * objDecl ) { 863 871 TypedefMap oldNames = typedefNames; 864 872 ObjectDecl *ret = Mutator::mutate( objDecl ); … … 867 875 } 868 876 869 Expression *EliminateTypedef::mutate( CastExpr * castExpr ) {877 Expression *EliminateTypedef::mutate( CastExpr * castExpr ) { 870 878 TypedefMap oldNames = typedefNames; 871 879 Expression *ret = Mutator::mutate( castExpr ); … … 874 882 } 875 883 876 CompoundStmt *EliminateTypedef::mutate( CompoundStmt * compoundStmt ) {884 CompoundStmt *EliminateTypedef::mutate( CompoundStmt * compoundStmt ) { 877 885 TypedefMap oldNames = typedefNames; 878 886 scopeLevel += 1; … … 881 889 std::list< Statement * >::iterator i = compoundStmt->get_kids().begin(); 882 890 while ( i != compoundStmt->get_kids().end() ) { 883 std::list< Statement * >::iterator next = i; 884 ++next; 891 std::list< Statement * >::iterator next = i+1; 885 892 if ( DeclStmt *declStmt = dynamic_cast< DeclStmt * >( *i ) ) { 886 893 if ( dynamic_cast< TypedefDecl * >( declStmt->get_decl() ) ) { … … 894 901 return ret; 895 902 } 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 896 941 } // namespace SymTab 897 942
Note: See TracChangeset
for help on using the changeset viewer.