Changeset ea3eb06 for translator/SymTab/StackTable.cc
- Timestamp:
- Nov 22, 2014, 4:51:46 PM (10 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:
- d11f789
- Parents:
- 3c70d38
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/SymTab/StackTable.cc
r3c70d38 rea3eb06 1 /*2 * This file is part of the Cforall project3 *4 * $Id: StackTable.cc,v 1.3 2002/09/19 21:02:44 rcbilson Exp $5 *6 */7 8 1 #include <cassert> 9 2 … … 11 4 12 5 namespace SymTab { 6 template< typename Element, typename ConflictFunction > 7 StackTable< Element, ConflictFunction >::StackTable() : scopeLevel( 0 ) 8 {} 13 9 14 template< typename Element, typename ConflictFunction > 15 StackTable< Element, ConflictFunction >::StackTable() 16 : scopeLevel( 0 ) 17 { 18 } 10 template< typename Element, typename ConflictFunction > 11 void StackTable< Element, ConflictFunction >::enterScope() { 12 scopeLevel++; 13 } 19 14 20 template< typename Element, typename ConflictFunction > 21 void 22 StackTable< Element, ConflictFunction >::enterScope() 23 { 24 scopeLevel++; 25 } 15 template< typename Element, typename ConflictFunction > 16 void StackTable< Element, ConflictFunction >::leaveScope() { 17 for ( typename TableType::iterator it = table.begin(); it != table.end(); ++it ) { 18 std::stack< Entry >& entry = it->second; 19 if ( !entry.empty() && entry.top().second == scopeLevel ) { 20 entry.pop(); 21 } 22 } 23 scopeLevel--; 24 assert( scopeLevel >= 0 ); 25 } 26 26 27 template< typename Element, typename ConflictFunction >28 void 29 StackTable< Element, ConflictFunction >::leaveScope() 30 {31 for( typename TableType::iterator it = table.begin(); it != table.end(); ++it ) { 32 std::stack< Entry >& entry = it->second; 33 if( !entry.empty() && entry.top().second == scopeLevel ) { 34 entry.pop(); 27 template< typename Element, typename ConflictFunction > 28 void StackTable< Element, ConflictFunction >::add( Element *type ) { 29 std::stack< Entry >& entry = table[ type->get_name() ]; 30 if ( !entry.empty() && entry.top().second == scopeLevel ) { 31 entry.top().first = conflictFunction( entry.top().first, type ); 32 } else { 33 entry.push( Entry( type, scopeLevel ) ); 34 } 35 35 } 36 }37 38 scopeLevel--;39 assert( scopeLevel >= 0 );40 }41 36 42 template< typename Element, typename ConflictFunction > 43 void 44 StackTable< Element, ConflictFunction >::add( Element *type ) 45 { 46 std::stack< Entry >& entry = table[ type->get_name() ]; 47 if( !entry.empty() && entry.top().second == scopeLevel ) { 48 entry.top().first = conflictFunction( entry.top().first, type ); 49 } else { 50 entry.push( Entry( type, scopeLevel ) ); 51 } 52 } 37 template< typename Element, typename ConflictFunction > 38 void StackTable< Element, ConflictFunction >::add( std::string fwdDeclName ) { 39 add( new Element( fwdDeclName ) ); 40 } 53 41 54 template< typename Element, typename ConflictFunction > 55 void 56 StackTable< Element, ConflictFunction >::add( std::string fwdDeclName ) 57 { 58 add( new Element( fwdDeclName ) ); 59 } 42 template< typename Element, typename ConflictFunction > 43 Element *StackTable< Element, ConflictFunction >::lookup( std::string id ) const { 44 typename TableType::const_iterator it = table.find( id ); 45 if ( it == table.end() ) { 46 return 0; 47 } else if ( !it->second.empty() ) { 48 return it->second.top().first; 49 } else { 50 return 0; 51 } 52 } 60 53 61 template< typename Element, typename ConflictFunction > 62 Element * 63 StackTable< Element, ConflictFunction >::lookup( std::string id ) const 64 { 65 typename TableType::const_iterator it = table.find( id ); 66 if( it == table.end() ) { 67 return 0; 68 } else if( !it->second.empty() ) { 69 return it->second.top().first; 70 } else { 71 return 0; 72 } 73 } 74 75 template< typename Element, typename ConflictFunction > 76 void 77 StackTable< Element, ConflictFunction >::dump( std::ostream &os ) const 78 { 79 for( typename TableType::const_iterator it = table.begin(); it != table.end(); ++it ) { 80 const std::stack< Entry >& entry = it->second; 81 if( !entry.empty() && entry.top().second == scopeLevel ) { 82 os << it->first << std::endl; 54 template< typename Element, typename ConflictFunction > 55 void StackTable< Element, ConflictFunction >::dump( std::ostream &os ) const { 56 for ( typename TableType::const_iterator it = table.begin(); it != table.end(); ++it ) { 57 const std::stack< Entry >& entry = it->second; 58 if ( !entry.empty() && entry.top().second == scopeLevel ) { 59 os << it->first << std::endl; 60 } 61 } 83 62 } 84 } 85 } 86 87 } // namespace SymTab 63 } // SymTab
Note: See TracChangeset
for help on using the changeset viewer.