Changeset 846a147
- Timestamp:
- Jul 9, 2018, 6:35:09 PM (5 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- 132d276
- Parents:
- a74503ff (diff), 046959b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
Jenkins/FullBuild
ra74503ff r846a147 21 21 gcc_5_x64: { trigger_build( 'gcc-5', 'x64', false ) }, 22 22 gcc_5_x86: { trigger_build( 'gcc-5', 'x86', false ) }, 23 gcc_4_x64: { trigger_build( 'gcc-4.9', 'x64', false ) },24 gcc_4_x86: { trigger_build( 'gcc-4.9', 'x86', false ) },25 23 clang_x64: { trigger_build( 'clang', 'x64', false ) }, 26 24 clang_x86: { trigger_build( 'clang', 'x86', false ) }, -
src/Common/ScopedMap.h
ra74503ff r846a147 22 22 #include <vector> 23 23 24 /// Default (empty) ScopedMap note type 25 struct EmptyNote {}; 26 24 27 /// A map where the items are placed into nested scopes; 25 /// inserted items are placed into the innermost scope, lookup looks from the innermost scope outward 26 template<typename Key, typename Value> 28 /// inserted items are placed into the innermost scope, lookup looks from the innermost scope outward. 29 /// Scopes may be annotated with a value; the annotation defaults to empty 30 template<typename Key, typename Value, typename Note = EmptyNote> 27 31 class ScopedMap { 28 typedef std::map< Key, Value > Scope; 32 typedef std::map< Key, Value > MapType; 33 struct Scope { 34 MapType map; 35 Note note; 36 37 template<typename N> 38 Scope(N&& n) : map(), note(std::forward<N>(n)) {} 39 40 Scope() = default; 41 Scope(const Scope&) = default; 42 Scope(Scope&&) = default; 43 Scope& operator= (const Scope&) = default; 44 Scope& operator= (Scope&&) = default; 45 }; 29 46 typedef std::vector< Scope > ScopeList; 30 47 31 48 ScopeList scopes; ///< scoped list of maps 32 49 public: 33 typedef typename Scope::key_type key_type;34 typedef typename Scope::mapped_type mapped_type;35 typedef typename Scope::value_type value_type;50 typedef typename MapType::key_type key_type; 51 typedef typename MapType::mapped_type mapped_type; 52 typedef typename MapType::value_type value_type; 36 53 typedef typename ScopeList::size_type size_type; 37 54 typedef typename ScopeList::difference_type difference_type; 38 typedef typename Scope::reference reference;39 typedef typename Scope::const_reference const_reference;40 typedef typename Scope::pointer pointer;41 typedef typename Scope::const_pointer const_pointer;55 typedef typename MapType::reference reference; 56 typedef typename MapType::const_reference const_reference; 57 typedef typename MapType::pointer pointer; 58 typedef typename MapType::const_pointer const_pointer; 42 59 43 60 class iterator : public std::iterator< std::bidirectional_iterator_tag, … … 45 62 friend class ScopedMap; 46 63 friend class const_iterator; 47 typedef typename std::map< Key, Value >::iterator wrapped_iterator;48 typedef typename std::vector< std::map< Key, Value > >scope_list;64 typedef typename ScopedMap::MapType::iterator wrapped_iterator; 65 typedef typename ScopedMap::ScopeList scope_list; 49 66 typedef typename scope_list::size_type size_type; 50 67 51 68 /// Checks if this iterator points to a valid item 52 69 bool is_valid() const { 53 return it != (*scopes)[level]. end();70 return it != (*scopes)[level].map.end(); 54 71 } 55 72 … … 79 96 80 97 iterator& operator++ () { 81 if ( it == (*scopes)[level]. end() ) {98 if ( it == (*scopes)[level].map.end() ) { 82 99 if ( level == 0 ) return *this; 83 100 --level; 84 it = (*scopes)[level]. begin();101 it = (*scopes)[level].map.begin(); 85 102 } else { 86 103 ++it; … … 92 109 iterator& operator-- () { 93 110 // may fail if this is the begin iterator; allowed by STL spec 94 if ( it == (*scopes)[level]. begin() ) {111 if ( it == (*scopes)[level].map.begin() ) { 95 112 ++level; 96 it = (*scopes)[level]. end();113 it = (*scopes)[level].map.end(); 97 114 } 98 115 --it; … … 107 124 108 125 size_type get_level() const { return level; } 126 127 Note& get_note() { return (*scopes)[level].note; } 128 const Note& get_note() const { return (*scopes)[level].note; } 109 129 110 130 private: … … 117 137 value_type > { 118 138 friend class ScopedMap; 119 typedef typename std::map< Key, Value >::iterator wrapped_iterator;120 typedef typename std::map< Key, Value >::const_iterator wrapped_const_iterator;121 typedef typename std::vector< std::map< Key, Value > >scope_list;139 typedef typename ScopedMap::MapType::iterator wrapped_iterator; 140 typedef typename ScopedMap::MapType::const_iterator wrapped_const_iterator; 141 typedef typename ScopedMap::ScopeList scope_list; 122 142 typedef typename scope_list::size_type size_type; 123 143 124 144 /// Checks if this iterator points to a valid item 125 145 bool is_valid() const { 126 return it != (*scopes)[level]. end();146 return it != (*scopes)[level].map.end(); 127 147 } 128 148 … … 157 177 158 178 const_iterator& operator++ () { 159 if ( it == (*scopes)[level]. end() ) {179 if ( it == (*scopes)[level].map.end() ) { 160 180 if ( level == 0 ) return *this; 161 181 --level; 162 it = (*scopes)[level]. begin();182 it = (*scopes)[level].map.begin(); 163 183 } else { 164 184 ++it; … … 170 190 const_iterator& operator-- () { 171 191 // may fail if this is the begin iterator; allowed by STL spec 172 if ( it == (*scopes)[level]. begin() ) {192 if ( it == (*scopes)[level].map.begin() ) { 173 193 ++level; 174 it = (*scopes)[level]. end();194 it = (*scopes)[level].map.end(); 175 195 } 176 196 --it; … … 185 205 186 206 size_type get_level() const { return level; } 207 208 const Note& get_note() const { return (*scopes)[level].note; } 187 209 188 210 private: … … 197 219 } 198 220 221 // Starts a new scope with the given note 222 template<typename N> 223 void beginScope( N&& n ) { 224 scopes.emplace_back( std::forward<N>(n) ); 225 } 226 199 227 /// Ends a scope; invalidates any iterators pointing to elements of that scope 200 228 void endScope() { … … 204 232 205 233 /// Default constructor initializes with one scope 206 ScopedMap() { beginScope(); } 207 208 iterator begin() { return iterator(scopes, scopes.back().begin(), currentScope()).next_valid(); } 209 const_iterator begin() const { return const_iterator(scopes, scopes.back().begin(), currentScope()).next_valid(); } 210 const_iterator cbegin() const { return const_iterator(scopes, scopes.back().begin(), currentScope()).next_valid(); } 211 iterator end() { return iterator(scopes, scopes[0].end(), 0); } 212 const_iterator end() const { return const_iterator(scopes, scopes[0].end(), 0); } 213 const_iterator cend() const { return const_iterator(scopes, scopes[0].end(), 0); } 234 ScopedMap() : scopes() { beginScope(); } 235 236 /// Constructs with a given note on the outermost scope 237 template<typename N> 238 ScopedMap( N&& n ) : scopes() { beginScope(std::forward<N>(n)); } 239 240 iterator begin() { return iterator(scopes, scopes.back().map.begin(), currentScope()).next_valid(); } 241 const_iterator begin() const { return const_iterator(scopes, scopes.back().map.begin(), currentScope()).next_valid(); } 242 const_iterator cbegin() const { return const_iterator(scopes, scopes.back().map.begin(), currentScope()).next_valid(); } 243 iterator end() { return iterator(scopes, scopes[0].map.end(), 0); } 244 const_iterator end() const { return const_iterator(scopes, scopes[0].map.end(), 0); } 245 const_iterator cend() const { return const_iterator(scopes, scopes[0].map.end(), 0); } 214 246 215 247 /// Gets the index of the current scope (counted from 1) 216 248 size_type currentScope() const { return scopes.size() - 1; } 249 250 /// Gets the note at the given scope 251 Note& getNote( size_type i ) { return scopes[i].note; } 252 const Note& getNote( size_type i ) const { return scopes[i].note; } 217 253 218 254 /// Finds the given key in the outermost scope it occurs; returns end() for none such 219 255 iterator find( const Key &key ) { 220 256 for ( size_type i = scopes.size() - 1; ; --i ) { 221 typename Scope::iterator val = scopes[i].find( key );222 if ( val != scopes[i]. end() ) return iterator( scopes, val, i );257 typename MapType::iterator val = scopes[i].map.find( key ); 258 if ( val != scopes[i].map.end() ) return iterator( scopes, val, i ); 223 259 if ( i == 0 ) break; 224 260 } … … 226 262 } 227 263 const_iterator find( const Key &key ) const { 228 return const_iterator( const_cast< ScopedMap< Key, Value >* >(this)->find( key ) );264 return const_iterator( const_cast< ScopedMap< Key, Value, Note >* >(this)->find( key ) ); 229 265 } 230 266 231 267 /// Finds the given key in the provided scope; returns end() for none such 232 268 iterator findAt( size_type scope, const Key& key ) { 233 typename Scope::iterator val = scopes[scope].find( key );234 if ( val != scopes[scope]. end() ) return iterator( scopes, val, scope );269 typename MapType::iterator val = scopes[scope].map.find( key ); 270 if ( val != scopes[scope].map.end() ) return iterator( scopes, val, scope ); 235 271 return end(); 236 272 } 237 273 const_iterator findAt( size_type scope, const Key& key ) const { 238 return const_iterator( const_cast< ScopedMap< Key, Value >* >(this)->findAt( scope, key ) );274 return const_iterator( const_cast< ScopedMap< Key, Value, Note >* >(this)->findAt( scope, key ) ); 239 275 } 240 276 … … 243 279 if ( it.level == 0 ) return end(); 244 280 for ( size_type i = it.level - 1; ; --i ) { 245 typename Scope::iterator val = scopes[i].find( key );246 if ( val != scopes[i]. end() ) return iterator( scopes, val, i );281 typename MapType::iterator val = scopes[i].map.find( key ); 282 if ( val != scopes[i].map.end() ) return iterator( scopes, val, i ); 247 283 if ( i == 0 ) break; 248 284 } … … 250 286 } 251 287 const_iterator findNext( const_iterator &it, const Key &key ) const { 252 return const_iterator( const_cast< ScopedMap< Key, Value >* >(this)->findNext( it, key ) );288 return const_iterator( const_cast< ScopedMap< Key, Value, Note >* >(this)->findNext( it, key ) ); 253 289 } 254 290 … … 256 292 template< typename value_type_t > 257 293 std::pair< iterator, bool > insert( value_type_t&& value ) { 258 std::pair< typename Scope::iterator, bool > res = scopes.back().insert( std::forward<value_type_t>( value ) );294 std::pair< typename MapType::iterator, bool > res = scopes.back().map.insert( std::forward<value_type_t>( value ) ); 259 295 return std::make_pair( iterator(scopes, std::move( res.first ), scopes.size()-1), std::move( res.second ) ); 260 296 } … … 262 298 template< typename value_type_t > 263 299 std::pair< iterator, bool > insert( iterator at, value_type_t&& value ) { 264 Scope& scope = (*at.scopes) [ at.level ];265 std::pair< typename Scope::iterator, bool > res = scope.insert( std::forward<value_type_t>( value ) );300 MapType& scope = (*at.scopes)[ at.level ].map; 301 std::pair< typename MapType::iterator, bool > res = scope.insert( std::forward<value_type_t>( value ) ); 266 302 return std::make_pair( iterator(scopes, std::move( res.first ), at.level), std::move( res.second ) ); 267 303 } … … 272 308 template< typename value_type_t > 273 309 std::pair< iterator, bool > insertAt( size_type scope, value_type_t&& value ) { 274 std::pair< typename Scope::iterator, bool > res = scopes.at(scope).insert( std::forward<value_type_t>( value ) );310 std::pair< typename MapType::iterator, bool > res = scopes.at(scope).map.insert( std::forward<value_type_t>( value ) ); 275 311 return std::make_pair( iterator(scopes, std::move( res.first ), scope), std::move( res.second ) ); 276 312 } … … 288 324 289 325 iterator erase( iterator pos ) { 290 Scope& scope = (*pos.scopes) [ pos.level ];326 MapType& scope = (*pos.scopes)[ pos.level ].map; 291 327 const typename iterator::wrapped_iterator& new_it = scope.erase( pos.it ); 292 328 iterator it( *pos.scopes, new_it, pos.level ); -
src/Parser/TypedefTable.cc
ra74503ff r846a147 91 91 92 92 void TypedefTable::enterScope() { 93 kindTable.beginScope( );93 kindTable.beginScope(0); 94 94 debugPrint( cerr << "Entering scope " << kindTable.currentScope() << endl; print() ); 95 95 } // TypedefTable::enterScope -
src/Parser/TypedefTable.h
ra74503ff r846a147 23 23 24 24 class TypedefTable { 25 typedef ScopedMap< std::string, int > KindTable;25 typedef ScopedMap< std::string, int, int > KindTable; 26 26 KindTable kindTable; 27 unsigned int level = 0;27 unsigned int level; 28 28 public: 29 TypedefTable() : kindTable{0}, level{0} {} 29 30 ~TypedefTable(); 30 31 -
src/tests/Makefile.am
ra74503ff r846a147 17 17 debug=yes 18 18 19 quick_test=avl_test operators numericConstants expression enum array typeof cast dtor-early-exit init_onceattributes19 quick_test=avl_test operators numericConstants expression enum array typeof cast attributes 20 20 21 21 if BUILD_CONCURRENCY
Note: See TracChangeset
for help on using the changeset viewer.