Changeset cc79d97 for src/SymTab
- Timestamp:
- Jul 8, 2015, 1:44:42 PM (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:
- 71bd8c6
- Parents:
- 0a0a65b
- Location:
- src/SymTab
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
r0a0a65b rcc79d97 10 10 // Created On : Sun May 17 21:50:04 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Jul 07 10:41:23201513 // Update Count : 1 3612 // Last Modified On : Wed Jul 08 12:49:36 2015 13 // Update Count : 166 14 14 // 15 15 … … 48 48 #include "Indexer.h" 49 49 #include "FixFunction.h" 50 #include "ImplementationType.h"50 // #include "ImplementationType.h" 51 51 #include "utility.h" 52 52 #include "UniqueName.h" 53 53 #include "AddVisit.h" 54 54 #include "MakeLibCfa.h" 55 55 #include "TypeEquality.h" 56 56 57 57 #define debugPrint( x ) if ( doDebug ) { std::cout << x; } … … 157 157 class EliminateTypedef : public Mutator { 158 158 public: 159 EliminateTypedef() : scopeLevel( 0 ) {} 159 160 static void eliminateTypedef( std::list< Declaration * > &translationUnit ); 160 161 private: … … 166 167 virtual Type *mutate( TypeInstType *aggregateUseType ); 167 168 virtual Expression *mutate( CastExpr *castExpr ); 168 169 std::map< std::string, TypedefDecl * > typedefNames; 169 170 typedef std::map< std::string, std::pair< TypedefDecl *, int > > TypedefMap; 171 TypedefMap typedefNames; 172 int scopeLevel; 170 173 }; 171 174 … … 584 587 assignDecl2->fixUniqueId(); 585 588 589 // these should be built in the same way that the prelude 590 // functions are, so build a list containing the prototypes 591 // and allow MakeLibCfa to autogenerate the bodies. 586 592 std::list< Declaration * > assigns; 587 593 assigns.push_back( assignDecl ); … … 590 596 LibCfa::makeLibCfa( assigns ); 591 597 592 // need to remove the prototypes, since th ese can appearnested in a routine598 // need to remove the prototypes, since this may be nested in a routine 593 599 for (int start = 0, end = assigns.size()/2; start < end; start++) { 594 600 delete assigns.front(); … … 597 603 598 604 declsToAdd.insert( declsToAdd.begin(), assigns.begin(), assigns.end() ); 599 600 // return assignDecl;601 605 } 602 606 … … 797 801 798 802 Type *EliminateTypedef::mutate( TypeInstType *typeInst ) { 799 std::map< std::string, TypedefDecl * >::const_iterator def = typedefNames.find( typeInst->get_name() ); 803 // instances of typedef types will come here. If it is an instance 804 // of a typdef type, link the instance to its actual type. 805 TypedefMap::const_iterator def = typedefNames.find( typeInst->get_name() ); 800 806 if ( def != typedefNames.end() ) { 801 Type *ret = def->second ->get_base()->clone();807 Type *ret = def->second.first->get_base()->clone(); 802 808 ret->get_qualifiers() += typeInst->get_qualifiers(); 803 809 delete typeInst; … … 809 815 Declaration *EliminateTypedef::mutate( TypedefDecl *tyDecl ) { 810 816 Declaration *ret = Mutator::mutate( tyDecl ); 811 typedefNames[ tyDecl->get_name() ] = tyDecl; 817 if ( typedefNames.count( tyDecl->get_name() ) == 1 && typedefNames[ tyDecl->get_name() ].second == scopeLevel ) { 818 // typedef to the same name from the same scope 819 // must be from the same type 820 821 Type * t1 = tyDecl->get_base(); 822 Type * t2 = typedefNames[ tyDecl->get_name() ].first->get_base(); 823 if ( ! typeEquals( t1, t2, true ) ) { 824 throw SemanticError( "cannot redefine typedef: " + tyDecl->get_name() ); 825 } 826 } else { 827 typedefNames[ tyDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel ); 828 } // if 829 812 830 // When a typedef is a forward declaration: 813 831 // typedef struct screen SCREEN; … … 828 846 829 847 TypeDecl *EliminateTypedef::mutate( TypeDecl *typeDecl ) { 830 std::map< std::string, TypedefDecl * >::iterator i = typedefNames.find( typeDecl->get_name() );848 TypedefMap::iterator i = typedefNames.find( typeDecl->get_name() ); 831 849 if ( i != typedefNames.end() ) { 832 850 typedefNames.erase( i ) ; … … 836 854 837 855 DeclarationWithType *EliminateTypedef::mutate( FunctionDecl *funcDecl ) { 838 std::map< std::string, TypedefDecl * >oldNames = typedefNames;856 TypedefMap oldNames = typedefNames; 839 857 DeclarationWithType *ret = Mutator::mutate( funcDecl ); 840 858 typedefNames = oldNames; … … 843 861 844 862 ObjectDecl *EliminateTypedef::mutate( ObjectDecl *objDecl ) { 845 std::map< std::string, TypedefDecl * >oldNames = typedefNames;863 TypedefMap oldNames = typedefNames; 846 864 ObjectDecl *ret = Mutator::mutate( objDecl ); 847 865 typedefNames = oldNames; … … 850 868 851 869 Expression *EliminateTypedef::mutate( CastExpr *castExpr ) { 852 std::map< std::string, TypedefDecl * >oldNames = typedefNames;870 TypedefMap oldNames = typedefNames; 853 871 Expression *ret = Mutator::mutate( castExpr ); 854 872 typedefNames = oldNames; … … 857 875 858 876 CompoundStmt *EliminateTypedef::mutate( CompoundStmt *compoundStmt ) { 859 std::map< std::string, TypedefDecl * > oldNames = typedefNames; 877 TypedefMap oldNames = typedefNames; 878 scopeLevel += 1; 860 879 CompoundStmt *ret = Mutator::mutate( compoundStmt ); 880 scopeLevel -= 1; 861 881 std::list< Statement * >::iterator i = compoundStmt->get_kids().begin(); 862 882 while ( i != compoundStmt->get_kids().end() ) { -
src/SymTab/module.mk
r0a0a65b rcc79d97 10 10 ## Author : Richard C. Bilson 11 11 ## Created On : Mon Jun 1 17:49:17 2015 12 ## Last Modified By : Peter A. Buhr13 ## Last Modified On : Mon Jun 1 17:53:50201514 ## Update Count : 112 ## Last Modified By : Rob Schluntz 13 ## Last Modified On : Tue Jul 07 16:22:23 2015 14 ## Update Count : 2 15 15 ############################################################################### 16 16 … … 20 20 SymTab/Validate.cc \ 21 21 SymTab/FixFunction.cc \ 22 SymTab/ImplementationType.cc 23 22 SymTab/ImplementationType.cc \ 23 SymTab/TypeEquality.cc
Note: See TracChangeset
for help on using the changeset viewer.