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