Changeset 9163b9c
- Timestamp:
- Jul 14, 2015, 11:31:54 AM (9 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:
- 34e3732, 724c2b6
- Parents:
- 0215a76f (diff), dfee306 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
r0215a76f r9163b9c 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. … … 827 835 } 828 836 829 Declaration *EliminateTypedef::mutate( TypedefDecl * tyDecl ) {837 Declaration *EliminateTypedef::mutate( TypedefDecl * tyDecl ) { 830 838 Declaration *ret = Mutator::mutate( tyDecl ); 831 839 if ( typedefNames.count( tyDecl->get_name() ) == 1 && typedefNames[ tyDecl->get_name() ].second == scopeLevel ) { … … 837 845 if ( ! typeEquals( t1, t2, true ) ) { 838 846 throw SemanticError( "cannot redefine typedef: " + tyDecl->get_name() ); 839 } 847 } 840 848 } else { 841 849 typedefNames[ tyDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel ); … … 859 867 } 860 868 861 TypeDecl *EliminateTypedef::mutate( TypeDecl * typeDecl ) {869 TypeDecl *EliminateTypedef::mutate( TypeDecl * typeDecl ) { 862 870 TypedefMap::iterator i = typedefNames.find( typeDecl->get_name() ); 863 871 if ( i != typedefNames.end() ) { … … 867 875 } 868 876 869 DeclarationWithType *EliminateTypedef::mutate( FunctionDecl * funcDecl ) {877 DeclarationWithType *EliminateTypedef::mutate( FunctionDecl * funcDecl ) { 870 878 TypedefMap oldNames = typedefNames; 871 879 DeclarationWithType *ret = Mutator::mutate( funcDecl ); … … 874 882 } 875 883 876 ObjectDecl *EliminateTypedef::mutate( ObjectDecl * objDecl ) {884 ObjectDecl *EliminateTypedef::mutate( ObjectDecl * objDecl ) { 877 885 TypedefMap oldNames = typedefNames; 878 886 ObjectDecl *ret = Mutator::mutate( objDecl ); … … 881 889 } 882 890 883 Expression *EliminateTypedef::mutate( CastExpr * castExpr ) {891 Expression *EliminateTypedef::mutate( CastExpr * castExpr ) { 884 892 TypedefMap oldNames = typedefNames; 885 893 Expression *ret = Mutator::mutate( castExpr ); … … 888 896 } 889 897 890 CompoundStmt *EliminateTypedef::mutate( CompoundStmt * compoundStmt ) {898 CompoundStmt *EliminateTypedef::mutate( CompoundStmt * compoundStmt ) { 891 899 TypedefMap oldNames = typedefNames; 892 900 scopeLevel += 1; … … 895 903 std::list< Statement * >::iterator i = compoundStmt->get_kids().begin(); 896 904 while ( i != compoundStmt->get_kids().end() ) { 897 std::list< Statement * >::iterator next = i; 898 ++next; 905 std::list< Statement * >::iterator next = i+1; 899 906 if ( DeclStmt *declStmt = dynamic_cast< DeclStmt * >( *i ) ) { 900 907 if ( dynamic_cast< TypedefDecl * >( declStmt->get_decl() ) ) { … … 908 915 return ret; 909 916 } 917 918 // there may be typedefs nested within aggregates 919 // in order for everything to work properly, these 920 // should be removed as well 921 template<typename AggDecl> 922 AggDecl *EliminateTypedef::handleAggregate( AggDecl * aggDecl ) { 923 std::list<Declaration *>::iterator it = aggDecl->get_members().begin(); 924 for ( ; it != aggDecl->get_members().end(); ) { 925 std::list< Declaration * >::iterator next = it+1; 926 if ( dynamic_cast< TypedefDecl * >( *it ) ) { 927 delete *it; 928 aggDecl->get_members().erase( it ); 929 } // if 930 it = next; 931 } 932 return aggDecl; 933 } 934 935 Declaration *EliminateTypedef::mutate( StructDecl * structDecl ) { 936 Mutator::mutate( structDecl ); 937 return handleAggregate( structDecl ); 938 } 939 940 Declaration *EliminateTypedef::mutate( UnionDecl * unionDecl ) { 941 Mutator::mutate( unionDecl ); 942 return handleAggregate( unionDecl ); 943 } 944 945 Declaration *EliminateTypedef::mutate( EnumDecl * enumDecl ) { 946 Mutator::mutate( enumDecl ); 947 return handleAggregate( enumDecl ); 948 } 949 950 Declaration *EliminateTypedef::mutate( ContextDecl * contextDecl ) { 951 Mutator::mutate( contextDecl ); 952 return handleAggregate( contextDecl ); 953 } 954 910 955 } // namespace SymTab 911 956
Note: See TracChangeset
for help on using the changeset viewer.