Changes in src/SymTab/Validate.cc [0215a76f:85c4ef0]
- File:
-
- 1 edited
-
src/SymTab/Validate.cc (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
r0215a76f 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 … … 60 60 class HoistStruct : public Visitor { 61 61 public: 62 /// Flattens nested struct types63 62 static void hoistStruct( std::list< Declaration * > &translationUnit ); 64 63 … … 85 84 }; 86 85 87 /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers88 86 class Pass1 : public Visitor { 89 87 typedef Visitor Parent; … … 91 89 virtual void visit( FunctionType *func ); 92 90 }; 93 94 /// Associates forward declarations of aggregates with their definitions 91 95 92 class Pass2 : public Indexer { 96 93 typedef Indexer Parent; … … 113 110 }; 114 111 115 /// Replaces array and function types in forall lists by appropriate pointer type116 112 class Pass3 : public Indexer { 117 113 typedef Indexer Parent; … … 127 123 class AddStructAssignment : public Visitor { 128 124 public: 129 /// Generates assignment operators for aggregate types as required130 125 static void addStructAssignment( std::list< Declaration * > &translationUnit ); 131 126 … … 172 167 virtual Type *mutate( TypeInstType *aggregateUseType ); 173 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 ); 174 177 175 178 typedef std::map< std::string, std::pair< TypedefDecl *, int > > TypedefMap; … … 441 444 } 442 445 443 /// Fix up assertions444 446 void forallFixer( Type *func ) { 447 // Fix up assertions 445 448 for ( std::list< TypeDecl * >::iterator type = func->get_forall().begin(); type != func->get_forall().end(); ++type ) { 446 449 std::list< DeclarationWithType * > toBeDone, nextRound; … … 805 808 } 806 809 807 Type *EliminateTypedef::mutate( TypeInstType * typeInst ) {810 Type *EliminateTypedef::mutate( TypeInstType * typeInst ) { 808 811 // instances of typedef types will come here. If it is an instance 809 812 // of a typdef type, link the instance to its actual type. … … 812 815 Type *ret = def->second.first->get_base()->clone(); 813 816 ret->get_qualifiers() += typeInst->get_qualifiers(); 814 // place instance parameters on the typedef'd type815 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 }823 817 delete typeInst; 824 818 return ret; … … 827 821 } 828 822 829 Declaration *EliminateTypedef::mutate( TypedefDecl * tyDecl ) {823 Declaration *EliminateTypedef::mutate( TypedefDecl * tyDecl ) { 830 824 Declaration *ret = Mutator::mutate( tyDecl ); 831 825 if ( typedefNames.count( tyDecl->get_name() ) == 1 && typedefNames[ tyDecl->get_name() ].second == scopeLevel ) { … … 837 831 if ( ! typeEquals( t1, t2, true ) ) { 838 832 throw SemanticError( "cannot redefine typedef: " + tyDecl->get_name() ); 839 } 833 } 840 834 } else { 841 835 typedefNames[ tyDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel ); … … 859 853 } 860 854 861 TypeDecl *EliminateTypedef::mutate( TypeDecl * typeDecl ) {855 TypeDecl *EliminateTypedef::mutate( TypeDecl * typeDecl ) { 862 856 TypedefMap::iterator i = typedefNames.find( typeDecl->get_name() ); 863 857 if ( i != typedefNames.end() ) { … … 867 861 } 868 862 869 DeclarationWithType *EliminateTypedef::mutate( FunctionDecl * funcDecl ) {863 DeclarationWithType *EliminateTypedef::mutate( FunctionDecl * funcDecl ) { 870 864 TypedefMap oldNames = typedefNames; 871 865 DeclarationWithType *ret = Mutator::mutate( funcDecl ); … … 874 868 } 875 869 876 ObjectDecl *EliminateTypedef::mutate( ObjectDecl * objDecl ) {870 ObjectDecl *EliminateTypedef::mutate( ObjectDecl * objDecl ) { 877 871 TypedefMap oldNames = typedefNames; 878 872 ObjectDecl *ret = Mutator::mutate( objDecl ); … … 881 875 } 882 876 883 Expression *EliminateTypedef::mutate( CastExpr * castExpr ) {877 Expression *EliminateTypedef::mutate( CastExpr * castExpr ) { 884 878 TypedefMap oldNames = typedefNames; 885 879 Expression *ret = Mutator::mutate( castExpr ); … … 888 882 } 889 883 890 CompoundStmt *EliminateTypedef::mutate( CompoundStmt * compoundStmt ) {884 CompoundStmt *EliminateTypedef::mutate( CompoundStmt * compoundStmt ) { 891 885 TypedefMap oldNames = typedefNames; 892 886 scopeLevel += 1; … … 895 889 std::list< Statement * >::iterator i = compoundStmt->get_kids().begin(); 896 890 while ( i != compoundStmt->get_kids().end() ) { 897 std::list< Statement * >::iterator next = i; 898 ++next; 891 std::list< Statement * >::iterator next = i+1; 899 892 if ( DeclStmt *declStmt = dynamic_cast< DeclStmt * >( *i ) ) { 900 893 if ( dynamic_cast< TypedefDecl * >( declStmt->get_decl() ) ) { … … 908 901 return ret; 909 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 910 941 } // namespace SymTab 911 942
Note:
See TracChangeset
for help on using the changeset viewer.