source: src/SymTab/StackTable.cc @ 6e7e2b36

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 6e7e2b36 was 843054c2, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

licencing: seventh groups of files

  • Property mode set to 100644
File size: 2.5 KB
Line 
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 : Tue May 19 16:51:53 2015
13// Update Count     : 3
14//
15
16#include <cassert>
17
18#include "StackTable.h"
19
20namespace SymTab {
21        template< typename Element, typename ConflictFunction >
22        StackTable< Element, ConflictFunction >::StackTable() : scopeLevel( 0 ) {
23        }
24
25        template< typename Element, typename ConflictFunction >
26        void StackTable< Element, ConflictFunction >::enterScope() {
27                scopeLevel++;
28        }
29
30        template< typename Element, typename ConflictFunction >
31        void StackTable< Element, ConflictFunction >::leaveScope() {
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 );
40        }
41
42        template< typename Element, typename ConflictFunction >
43        void StackTable< Element, ConflictFunction >::add( Element *type ) {
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
50        }
51
52        template< typename Element, typename ConflictFunction >
53        void StackTable< Element, ConflictFunction >::add( std::string fwdDeclName ) {
54                add( new Element( fwdDeclName ) );
55        }
56
57        template< typename Element, typename ConflictFunction >
58        Element *StackTable< Element, ConflictFunction >::lookup( std::string id ) const {
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
67        }
68
69        template< typename Element, typename ConflictFunction >
70        void StackTable< Element, ConflictFunction >::dump( std::ostream &os ) const {
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
77        }
78} // namespace SymTab
79
80// Local Variables: //
81// tab-width: 4 //
82// mode: c++ //
83// compile-command: "make install" //
84// End: //
Note: See TracBrowser for help on using the repository browser.