Changes in / [846a147:a74503ff]


Ignore:
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • Jenkins/FullBuild

    r846a147 ra74503ff  
    2121                                        gcc_5_x64: { trigger_build( 'gcc-5',   'x64', false ) },
    2222                                        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 ) },
    2325                                        clang_x64: { trigger_build( 'clang',   'x64', false ) },
    2426                                        clang_x86: { trigger_build( 'clang',   'x86', false ) },
  • src/Common/ScopedMap.h

    r846a147 ra74503ff  
    2222#include <vector>
    2323
    24 /// Default (empty) ScopedMap note type
    25 struct EmptyNote {};
    26 
    2724/// 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
     26template<typename Key, typename Value>
    3127class 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;
    4629        typedef std::vector< Scope > ScopeList;
    4730
    4831        ScopeList scopes; ///< scoped list of maps
    4932public:
    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;
    5336        typedef typename ScopeList::size_type size_type;
    5437        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;
    5942
    6043        class iterator : public std::iterator< std::bidirectional_iterator_tag,
     
    6245        friend class ScopedMap;
    6346        friend class const_iterator;
    64                 typedef typename ScopedMap::MapType::iterator wrapped_iterator;
    65                 typedef typename ScopedMap::ScopeList scope_list;
     47                typedef typename std::map< Key, Value >::iterator wrapped_iterator;
     48                typedef typename std::vector< std::map< Key, Value > > scope_list;
    6649                typedef typename scope_list::size_type size_type;
    6750
    6851                /// Checks if this iterator points to a valid item
    6952                bool is_valid() const {
    70                         return it != (*scopes)[level].map.end();
     53                        return it != (*scopes)[level].end();
    7154                }
    7255
     
    9679
    9780                iterator& operator++ () {
    98                         if ( it == (*scopes)[level].map.end() ) {
     81                        if ( it == (*scopes)[level].end() ) {
    9982                                if ( level == 0 ) return *this;
    10083                                --level;
    101                                 it = (*scopes)[level].map.begin();
     84                                it = (*scopes)[level].begin();
    10285                        } else {
    10386                                ++it;
     
    10992                iterator& operator-- () {
    11093                        // 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() ) {
    11295                                ++level;
    113                                 it = (*scopes)[level].map.end();
     96                                it = (*scopes)[level].end();
    11497                        }
    11598                        --it;
     
    124107
    125108                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; }
    129109
    130110        private:
     
    137117                                                     value_type > {
    138118        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::ScopeList scope_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;
    142122                typedef typename scope_list::size_type size_type;
    143123
    144124                /// Checks if this iterator points to a valid item
    145125                bool is_valid() const {
    146                         return it != (*scopes)[level].map.end();
     126                        return it != (*scopes)[level].end();
    147127                }
    148128
     
    177157
    178158                const_iterator& operator++ () {
    179                         if ( it == (*scopes)[level].map.end() ) {
     159                        if ( it == (*scopes)[level].end() ) {
    180160                                if ( level == 0 ) return *this;
    181161                                --level;
    182                                 it = (*scopes)[level].map.begin();
     162                                it = (*scopes)[level].begin();
    183163                        } else {
    184164                                ++it;
     
    190170                const_iterator& operator-- () {
    191171                        // 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() ) {
    193173                                ++level;
    194                                 it = (*scopes)[level].map.end();
     174                                it = (*scopes)[level].end();
    195175                        }
    196176                        --it;
     
    205185
    206186                size_type get_level() const { return level; }
    207 
    208                 const Note& get_note() const { return (*scopes)[level].note; }
    209187
    210188        private:
     
    219197        }
    220198
    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 
    227199        /// Ends a scope; invalidates any iterators pointing to elements of that scope
    228200        void endScope() {
     
    232204
    233205        /// 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); }
    246214
    247215        /// Gets the index of the current scope (counted from 1)
    248216        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; }
    253217
    254218        /// Finds the given key in the outermost scope it occurs; returns end() for none such
    255219        iterator find( const Key &key ) {
    256220                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 );
    259223                        if ( i == 0 ) break;
    260224                }
     
    262226        }
    263227        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 ) );
    265229        }
    266230
    267231        /// Finds the given key in the provided scope; returns end() for none such
    268232        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 );
    271235                return end();
    272236        }
    273237        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 ) );
    275239        }
    276240
     
    279243                if ( it.level == 0 ) return end();
    280244                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 );
    283247                        if ( i == 0 ) break;
    284248                }
     
    286250        }
    287251        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 ) );
    289253        }
    290254
     
    292256        template< typename value_type_t >
    293257        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 ) );
    295259                return std::make_pair( iterator(scopes, std::move( res.first ), scopes.size()-1), std::move( res.second ) );
    296260        }
     
    298262        template< typename value_type_t >
    299263        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 ) );
    302266                return std::make_pair( iterator(scopes, std::move( res.first ), at.level), std::move( res.second ) );
    303267        }
     
    308272        template< typename value_type_t >
    309273        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 ) );
    311275                return std::make_pair( iterator(scopes, std::move( res.first ), scope), std::move( res.second ) );
    312276        }
     
    324288
    325289        iterator erase( iterator pos ) {
    326                 MapType& scope = (*pos.scopes)[ pos.level ].map;
     290                Scope& scope = (*pos.scopes) [ pos.level ];
    327291                const typename iterator::wrapped_iterator& new_it = scope.erase( pos.it );
    328292                iterator it( *pos.scopes, new_it, pos.level );
  • src/Parser/TypedefTable.cc

    r846a147 ra74503ff  
    9191
    9292void TypedefTable::enterScope() {
    93         kindTable.beginScope(0);
     93        kindTable.beginScope();
    9494        debugPrint( cerr << "Entering scope " << kindTable.currentScope() << endl; print() );
    9595} // TypedefTable::enterScope
  • src/Parser/TypedefTable.h

    r846a147 ra74503ff  
    2323
    2424class TypedefTable {
    25         typedef ScopedMap< std::string, int, int > KindTable;
     25        typedef ScopedMap< std::string, int > KindTable;
    2626        KindTable kindTable;   
    27         unsigned int level;
     27        unsigned int level = 0;
    2828  public:
    29     TypedefTable() : kindTable{0}, level{0} {}
    3029        ~TypedefTable();
    3130
  • src/tests/Makefile.am

    r846a147 ra74503ff  
    1717debug=yes
    1818
    19 quick_test=avl_test operators numericConstants expression enum array typeof cast attributes
     19quick_test=avl_test operators numericConstants expression enum array typeof cast dtor-early-exit init_once attributes
    2020
    2121if BUILD_CONCURRENCY
Note: See TracChangeset for help on using the changeset viewer.