Changes in / [dfee306:cff1143]
- File:
-
- 1 edited
-
src/SymTab/Validate.cc (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
rdfee306 rcff1143 10 10 // Created On : Sun May 17 21:50:04 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Mon Jul 13 14:38:19201513 // Update Count : 1 8412 // Last Modified On : Wed Jul 08 12:49:36 2015 13 // Update Count : 166 14 14 // 15 15 … … 172 172 virtual Type *mutate( TypeInstType *aggregateUseType ); 173 173 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 );182 174 183 175 typedef std::map< std::string, std::pair< TypedefDecl *, int > > TypedefMap; … … 813 805 } 814 806 815 Type *EliminateTypedef::mutate( TypeInstType * typeInst ) {807 Type *EliminateTypedef::mutate( TypeInstType *typeInst ) { 816 808 // instances of typedef types will come here. If it is an instance 817 809 // of a typdef type, link the instance to its actual type. … … 826 818 } 827 819 828 Declaration *EliminateTypedef::mutate( TypedefDecl * tyDecl ) {820 Declaration *EliminateTypedef::mutate( TypedefDecl *tyDecl ) { 829 821 Declaration *ret = Mutator::mutate( tyDecl ); 830 822 if ( typedefNames.count( tyDecl->get_name() ) == 1 && typedefNames[ tyDecl->get_name() ].second == scopeLevel ) { … … 836 828 if ( ! typeEquals( t1, t2, true ) ) { 837 829 throw SemanticError( "cannot redefine typedef: " + tyDecl->get_name() ); 838 } 830 } 839 831 } else { 840 832 typedefNames[ tyDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel ); … … 858 850 } 859 851 860 TypeDecl *EliminateTypedef::mutate( TypeDecl * typeDecl ) {852 TypeDecl *EliminateTypedef::mutate( TypeDecl *typeDecl ) { 861 853 TypedefMap::iterator i = typedefNames.find( typeDecl->get_name() ); 862 854 if ( i != typedefNames.end() ) { … … 866 858 } 867 859 868 DeclarationWithType *EliminateTypedef::mutate( FunctionDecl * funcDecl ) {860 DeclarationWithType *EliminateTypedef::mutate( FunctionDecl *funcDecl ) { 869 861 TypedefMap oldNames = typedefNames; 870 862 DeclarationWithType *ret = Mutator::mutate( funcDecl ); … … 873 865 } 874 866 875 ObjectDecl *EliminateTypedef::mutate( ObjectDecl * objDecl ) {867 ObjectDecl *EliminateTypedef::mutate( ObjectDecl *objDecl ) { 876 868 TypedefMap oldNames = typedefNames; 877 869 ObjectDecl *ret = Mutator::mutate( objDecl ); … … 880 872 } 881 873 882 Expression *EliminateTypedef::mutate( CastExpr * castExpr ) {874 Expression *EliminateTypedef::mutate( CastExpr *castExpr ) { 883 875 TypedefMap oldNames = typedefNames; 884 876 Expression *ret = Mutator::mutate( castExpr ); … … 887 879 } 888 880 889 CompoundStmt *EliminateTypedef::mutate( CompoundStmt * compoundStmt ) {881 CompoundStmt *EliminateTypedef::mutate( CompoundStmt *compoundStmt ) { 890 882 TypedefMap oldNames = typedefNames; 891 883 scopeLevel += 1; … … 894 886 std::list< Statement * >::iterator i = compoundStmt->get_kids().begin(); 895 887 while ( i != compoundStmt->get_kids().end() ) { 896 std::list< Statement * >::iterator next = i+1; 888 std::list< Statement * >::iterator next = i; 889 ++next; 897 890 if ( DeclStmt *declStmt = dynamic_cast< DeclStmt * >( *i ) ) { 898 891 if ( dynamic_cast< TypedefDecl * >( declStmt->get_decl() ) ) { … … 906 899 return ret; 907 900 } 908 909 // there may be typedefs nested within aggregates910 // in order for everything to work properly, these911 // should be removed as well912 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 } // if921 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 946 901 } // namespace SymTab 947 902
Note:
See TracChangeset
for help on using the changeset viewer.