Changes in / [cff1143:dfee306]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
rcff1143 rdfee306 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 … … 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 ); 174 182 175 183 typedef std::map< std::string, std::pair< TypedefDecl *, int > > TypedefMap; … … 805 813 } 806 814 807 Type *EliminateTypedef::mutate( TypeInstType * typeInst ) {815 Type *EliminateTypedef::mutate( TypeInstType * typeInst ) { 808 816 // instances of typedef types will come here. If it is an instance 809 817 // of a typdef type, link the instance to its actual type. … … 818 826 } 819 827 820 Declaration *EliminateTypedef::mutate( TypedefDecl * tyDecl ) {828 Declaration *EliminateTypedef::mutate( TypedefDecl * tyDecl ) { 821 829 Declaration *ret = Mutator::mutate( tyDecl ); 822 830 if ( typedefNames.count( tyDecl->get_name() ) == 1 && typedefNames[ tyDecl->get_name() ].second == scopeLevel ) { … … 828 836 if ( ! typeEquals( t1, t2, true ) ) { 829 837 throw SemanticError( "cannot redefine typedef: " + tyDecl->get_name() ); 830 } 838 } 831 839 } else { 832 840 typedefNames[ tyDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel ); … … 850 858 } 851 859 852 TypeDecl *EliminateTypedef::mutate( TypeDecl * typeDecl ) {860 TypeDecl *EliminateTypedef::mutate( TypeDecl * typeDecl ) { 853 861 TypedefMap::iterator i = typedefNames.find( typeDecl->get_name() ); 854 862 if ( i != typedefNames.end() ) { … … 858 866 } 859 867 860 DeclarationWithType *EliminateTypedef::mutate( FunctionDecl * funcDecl ) {868 DeclarationWithType *EliminateTypedef::mutate( FunctionDecl * funcDecl ) { 861 869 TypedefMap oldNames = typedefNames; 862 870 DeclarationWithType *ret = Mutator::mutate( funcDecl ); … … 865 873 } 866 874 867 ObjectDecl *EliminateTypedef::mutate( ObjectDecl * objDecl ) {875 ObjectDecl *EliminateTypedef::mutate( ObjectDecl * objDecl ) { 868 876 TypedefMap oldNames = typedefNames; 869 877 ObjectDecl *ret = Mutator::mutate( objDecl ); … … 872 880 } 873 881 874 Expression *EliminateTypedef::mutate( CastExpr * castExpr ) {882 Expression *EliminateTypedef::mutate( CastExpr * castExpr ) { 875 883 TypedefMap oldNames = typedefNames; 876 884 Expression *ret = Mutator::mutate( castExpr ); … … 879 887 } 880 888 881 CompoundStmt *EliminateTypedef::mutate( CompoundStmt * compoundStmt ) {889 CompoundStmt *EliminateTypedef::mutate( CompoundStmt * compoundStmt ) { 882 890 TypedefMap oldNames = typedefNames; 883 891 scopeLevel += 1; … … 886 894 std::list< Statement * >::iterator i = compoundStmt->get_kids().begin(); 887 895 while ( i != compoundStmt->get_kids().end() ) { 888 std::list< Statement * >::iterator next = i; 889 ++next; 896 std::list< Statement * >::iterator next = i+1; 890 897 if ( DeclStmt *declStmt = dynamic_cast< DeclStmt * >( *i ) ) { 891 898 if ( dynamic_cast< TypedefDecl * >( declStmt->get_decl() ) ) { … … 899 906 return ret; 900 907 } 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 901 946 } // namespace SymTab 902 947
Note:
See TracChangeset
for help on using the changeset viewer.