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