Changeset 46f6134
- Timestamp:
- Aug 29, 2016, 12:20:45 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- ad4581b, b542bfb
- Parents:
- 5e644d3e
- Location:
- src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/ScopedMap.h
r5e644d3e r46f6134 42 42 typedef typename Scope::pointer pointer; 43 43 typedef typename Scope::const_pointer const_pointer; 44 44 45 45 class iterator : public std::iterator< std::bidirectional_iterator_tag, 46 46 value_type > { … … 68 68 } 69 69 70 iterator(scope_list const&_scopes, const wrapped_iterator &_it, size_type _i)70 iterator(scope_list &_scopes, const wrapped_iterator &_it, size_type _i) 71 71 : scopes(&_scopes), it(_it), i(_i) {} 72 72 public: … … 76 76 return *this; 77 77 } 78 78 79 79 reference operator* () { return *it; } 80 80 pointer operator-> () { return it.operator->(); } … … 109 109 110 110 private: 111 scope_list const*scopes;111 scope_list *scopes; 112 112 wrapped_iterator it; 113 113 size_type i; … … 189 189 size_type i; 190 190 }; 191 191 192 192 /// Starts a new scope 193 193 void beginScope() { 194 Scope scope; 195 scopes.push_back(scope); 194 scopes.emplace_back(); 196 195 } 197 196 … … 227 226 return const_iterator( const_cast< ScopedMap< Key, Value >* >(this)->find( key ) ); 228 227 } 229 228 230 229 /// Finds the given key in the outermost scope inside the given scope where it occurs 231 230 iterator findNext( const_iterator &it, const Key &key ) { … … 247 246 return std::make_pair( iterator(scopes, res.first, scopes.size()-1), res.second ); 248 247 } 248 249 std::pair< iterator, bool > insert( value_type &&value ) { 250 std::pair< typename Scope::iterator, bool > res = scopes.back().insert( std::move( value ) ); 251 return std::make_pair( iterator(scopes, std::move( res.first ), scopes.size()-1), std::move( res.second ) ); 252 } 253 249 254 std::pair< iterator, bool > insert( const Key &key, const Value &value ) { return insert( std::make_pair( key, value ) ); } 255 std::pair< iterator, bool > insert( const Key &key, Value &&value ) { return insert( std::make_pair( key, std::move( value ) ) ); } 250 256 251 257 Value& operator[] ( const Key &key ) { … … 254 260 return insert( key, Value() ).first->second; 255 261 } 262 263 iterator erase( iterator pos ) { 264 Scope& scope = (*pos.scopes) [ pos.i ]; 265 const typename iterator::wrapped_iterator& new_it = scope.erase( pos.it ); 266 iterator it( *pos.scopes, new_it, pos.i ); 267 return it.next_valid(); 268 } 269 270 size_type count( const Key &key ) const { 271 size_type c = 0; 272 auto it = find( key ); 273 auto end = cend(); 274 275 while(it != end) { 276 c++; 277 it = findNext(it, key); 278 } 279 280 return c; 281 } 282 256 283 }; 257 284 } // namespace GenPoly -
src/SymTab/Validate.cc
r5e644d3e r46f6134 49 49 #include "SynTree/Statement.h" 50 50 #include "SynTree/TypeSubstitution.h" 51 #include "GenPoly/ScopedMap.h" 51 52 #include "Indexer.h" 52 53 #include "FixFunction.h" … … 162 163 void addImplicitTypedef( AggDecl * aggDecl ); 163 164 164 typedef std::map< std::string, std::pair< TypedefDecl *, int > > TypedefMap; 165 typedef std::unique_ptr<TypedefDecl> TypedefDeclPtr; 166 typedef GenPoly::ScopedMap< std::string, std::pair< TypedefDeclPtr, int > > TypedefMap; 165 167 typedef std::map< std::string, TypeDecl * > TypeDeclMap; 166 168 TypedefMap typedefNames; … … 549 551 } 550 552 } else { 551 typedefNames[ tyDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel );553 typedefNames[ tyDecl->get_name() ] = std::make_pair( TypedefDeclPtr( tyDecl ), scopeLevel ); 552 554 } // if 553 555 … … 567 569 return new EnumDecl( enumDecl->get_name() ); 568 570 } else { 569 return ret ;571 return ret->clone(); 570 572 } // if 571 573 } … … 582 584 583 585 DeclarationWithType *EliminateTypedef::mutate( FunctionDecl * funcDecl ) { 584 TypedefMap oldNames = typedefNames;586 typedefNames.beginScope(); 585 587 DeclarationWithType *ret = Mutator::mutate( funcDecl ); 586 typedefNames = oldNames;588 typedefNames.endScope(); 587 589 return ret; 588 590 } 589 591 590 592 DeclarationWithType *EliminateTypedef::mutate( ObjectDecl * objDecl ) { 591 TypedefMap oldNames = typedefNames;593 typedefNames.beginScope(); 592 594 DeclarationWithType *ret = Mutator::mutate( objDecl ); 593 typedefNames = oldNames;595 typedefNames.endScope(); 594 596 // is the type a function? 595 597 if ( FunctionType *funtype = dynamic_cast<FunctionType *>( ret->get_type() ) ) { … … 603 605 604 606 Expression *EliminateTypedef::mutate( CastExpr * castExpr ) { 605 TypedefMap oldNames = typedefNames;607 typedefNames.beginScope(); 606 608 Expression *ret = Mutator::mutate( castExpr ); 607 typedefNames = oldNames;609 typedefNames.endScope(); 608 610 return ret; 609 611 } 610 612 611 613 CompoundStmt *EliminateTypedef::mutate( CompoundStmt * compoundStmt ) { 612 TypedefMap oldNames = typedefNames;614 typedefNames.beginScope(); 613 615 scopeLevel += 1; 614 616 CompoundStmt *ret = Mutator::mutate( compoundStmt ); … … 625 627 i = next; 626 628 } // while 627 typedefNames = oldNames;629 typedefNames.endScope(); 628 630 return ret; 629 631 } … … 656 658 type = new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ); 657 659 } // if 658 TypedefDecl * tyDecl = new TypedefDecl( aggDecl->get_name(), DeclarationNode::NoStorageClass, type);659 typedefNames[ aggDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel );660 TypedefDeclPtr tyDecl( new TypedefDecl( aggDecl->get_name(), DeclarationNode::NoStorageClass, type ) ); 661 typedefNames[ aggDecl->get_name() ] = std::make_pair( std::move( tyDecl ), scopeLevel ); 660 662 } // if 661 663 } -
src/SynTree/Declaration.h
r5e644d3e r46f6134 153 153 public: 154 154 NamedTypeDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type ); 155 NamedTypeDecl( const TypeDecl &other );155 NamedTypeDecl( const NamedTypeDecl &other ); 156 156 virtual ~NamedTypeDecl(); 157 157 -
src/SynTree/NamedTypeDecl.cc
r5e644d3e r46f6134 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // NamedTypeDecl.cc -- 7 // NamedTypeDecl.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 21 21 : Parent( name, sc, LinkageSpec::Cforall ), base( base ) {} 22 22 23 NamedTypeDecl::NamedTypeDecl( const TypeDecl &other )23 NamedTypeDecl::NamedTypeDecl( const NamedTypeDecl &other ) 24 24 : Parent( other ), base( maybeClone( other.base ) ) { 25 25 cloneAll( other.parameters, parameters ); … … 35 35 void NamedTypeDecl::print( std::ostream &os, int indent ) const { 36 36 using namespace std; 37 37 38 38 if ( get_name() != "" ) { 39 39 os << get_name() << ": "; … … 59 59 void NamedTypeDecl::printShort( std::ostream &os, int indent ) const { 60 60 using namespace std; 61 61 62 62 if ( get_name() != "" ) { 63 63 os << get_name() << ": "; -
src/main.cc
r5e644d3e r46f6134 84 84 << " backtrace:" << endl; 85 85 86 char ** messages = backtrace_symbols( array, size ); 86 char ** messages = backtrace_symbols( array, size ); 87 87 88 88 // skip first stack frame (points here) … … 91 91 for ( char *p = messages[i]; *p; ++p ) { // find parantheses and +offset 92 92 if (*p == '(') { 93 mangled_name = p; 93 mangled_name = p; 94 94 } else if (*p == '+') { 95 95 offset_begin = p; … … 109 109 char * real_name = __cxxabiv1::__cxa_demangle( mangled_name, 0, 0, &status ); 110 110 if ( status == 0 ) { // demangling successful ? 111 cerr << "(" << i - 2 << ") " << messages[i] << " : " 111 cerr << "(" << i - 2 << ") " << messages[i] << " : " 112 112 << real_name << "+" << offset_begin << offset_end << endl; 113 113 114 114 } else { // otherwise, output mangled name 115 cerr << "(" << i - 2 << ") " << messages[i] << " : " 115 cerr << "(" << i - 2 << ") " << messages[i] << " : " 116 116 << mangled_name << "+" << offset_begin << offset_end << endl; 117 117 } // if … … 198 198 SymTab::validate( translationUnit, symtabp ); 199 199 if ( symtabp ) { 200 deleteAll( translationUnit ); 200 201 return 0; 201 202 } // if
Note: See TracChangeset
for help on using the changeset viewer.