source: translator/SymTab/StackTable.cc @ 8c17ab0

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 8c17ab0 was 51b7345, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

initial commit

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 * This file is part of the Cforall project
3 *
4 * $Id: StackTable.cc,v 1.3 2002/09/19 21:02:44 rcbilson Exp $
5 *
6 */
7 
8#include <cassert>
9
10#include "StackTable.h"
11
12namespace SymTab {
13
14template< typename Element, typename ConflictFunction >
15StackTable< Element, ConflictFunction >::StackTable()
16  : scopeLevel( 0 )
17{
18}
19
20template< typename Element, typename ConflictFunction >
21void 
22StackTable< Element, ConflictFunction >::enterScope()
23{
24  scopeLevel++;
25}
26
27template< typename Element, typename ConflictFunction >
28void 
29StackTable< 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();
35    }
36  }
37     
38  scopeLevel--;
39  assert( scopeLevel >= 0 );
40}
41
42template< typename Element, typename ConflictFunction >
43void 
44StackTable< 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}
53
54template< typename Element, typename ConflictFunction >
55void 
56StackTable< Element, ConflictFunction >::add( std::string fwdDeclName )
57{
58  add( new Element( fwdDeclName ) );
59}
60
61template< typename Element, typename ConflictFunction >
62Element *
63StackTable< 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
75template< typename Element, typename ConflictFunction >
76void 
77StackTable< 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;
83    }
84  }
85}
86
87} // namespace SymTab
Note: See TracBrowser for help on using the repository browser.