Changeset 0dd3a2f for translator/SymTab/StackTable.cc
- Timestamp:
- May 18, 2015, 11:20:23 AM (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:
- 51587aa
- Parents:
- a32b204
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/SymTab/StackTable.cc
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // StackTable.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Sun May 17 21:45:15 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:46:59 2015 13 // Update Count : 2 14 // 15 1 16 #include <cassert> 2 17 … … 5 20 namespace SymTab { 6 21 template< typename Element, typename ConflictFunction > 7 StackTable< Element, ConflictFunction >::StackTable() : scopeLevel( 0 ) 8 {}22 StackTable< Element, ConflictFunction >::StackTable() : scopeLevel( 0 ) { 23 } 9 24 10 25 template< typename Element, typename ConflictFunction > 11 26 void StackTable< Element, ConflictFunction >::enterScope() { 12 scopeLevel++;27 scopeLevel++; 13 28 } 14 29 15 30 template< typename Element, typename ConflictFunction > 16 31 void StackTable< Element, ConflictFunction >::leaveScope() { 17 for ( typename TableType::iterator it = table.begin(); it != table.end(); ++it ) {18 19 20 entry.pop();21 }22 }23 scopeLevel--;24 assert( scopeLevel >= 0 );32 for ( typename TableType::iterator it = table.begin(); it != table.end(); ++it ) { 33 std::stack< Entry >& entry = it->second; 34 if ( ! entry.empty() && entry.top().second == scopeLevel ) { 35 entry.pop(); 36 } // if 37 } // for 38 scopeLevel--; 39 assert( scopeLevel >= 0 ); 25 40 } 26 41 27 42 template< typename Element, typename ConflictFunction > 28 43 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 32 } else {33 34 }44 std::stack< Entry >& entry = table[ type->get_name() ]; 45 if ( ! entry.empty() && entry.top().second == scopeLevel ) { 46 entry.top().first = conflictFunction( entry.top().first, type ); 47 } else { 48 entry.push( Entry( type, scopeLevel ) ); 49 } // if 35 50 } 36 51 37 52 template< typename Element, typename ConflictFunction > 38 53 void StackTable< Element, ConflictFunction >::add( std::string fwdDeclName ) { 39 add( new Element( fwdDeclName ) );54 add( new Element( fwdDeclName ) ); 40 55 } 41 56 42 57 template< typename Element, typename ConflictFunction > 43 58 Element *StackTable< Element, ConflictFunction >::lookup( std::string id ) const { 44 typename TableType::const_iterator it = table.find( id );45 if ( it == table.end() ) {46 47 } else if ( ! it->second.empty() ) {48 49 } else {50 51 }59 typename TableType::const_iterator it = table.find( id ); 60 if ( it == table.end() ) { 61 return 0; 62 } else if ( ! it->second.empty() ) { 63 return it->second.top().first; 64 } else { 65 return 0; 66 } // if 52 67 } 53 68 54 69 template< typename Element, typename ConflictFunction > 55 70 void StackTable< Element, ConflictFunction >::dump( std::ostream &os ) const { 56 for ( typename TableType::const_iterator it = table.begin(); it != table.end(); ++it ) {57 58 59 os << it->first << std::endl;60 }61 }71 for ( typename TableType::const_iterator it = table.begin(); it != table.end(); ++it ) { 72 const std::stack< Entry >& entry = it->second; 73 if ( ! entry.empty() && entry.top().second == scopeLevel ) { 74 os << it->first << std::endl; 75 } // if 76 } // for 62 77 } 63 } // SymTab 78 } // namespace SymTab 79 80 // Local Variables: // 81 // tab-width: 4 // 82 // mode: c++ // 83 // compile-command: "make install" // 84 // End: //
Note: See TracChangeset
for help on using the changeset viewer.