Changeset 46f6134 for src/GenPoly


Ignore:
Timestamp:
Aug 29, 2016, 12:20:45 PM (9 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
ad4581b, b542bfb
Parents:
5e644d3e
Message:

Implemented owning scoped map for typedef elimination phase

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/ScopedMap.h

    r5e644d3e r46f6134  
    4242                typedef typename Scope::pointer pointer;
    4343                typedef typename Scope::const_pointer const_pointer;
    44                
     44
    4545                class iterator : public std::iterator< std::bidirectional_iterator_tag,
    4646                                                       value_type > {
     
    6868                        }
    6969
    70                         iterator(scope_list const &_scopes, const wrapped_iterator &_it, size_type _i)
     70                        iterator(scope_list &_scopes, const wrapped_iterator &_it, size_type _i)
    7171                                : scopes(&_scopes), it(_it), i(_i) {}
    7272                public:
     
    7676                                return *this;
    7777                        }
    78                        
     78
    7979                        reference operator* () { return *it; }
    8080                        pointer operator-> () { return it.operator->(); }
     
    109109
    110110                private:
    111                         scope_list const *scopes;
     111                        scope_list *scopes;
    112112                        wrapped_iterator it;
    113113                        size_type i;
     
    189189                        size_type i;
    190190                };
    191                
     191
    192192                /// Starts a new scope
    193193                void beginScope() {
    194                         Scope scope;
    195                         scopes.push_back(scope);
     194                        scopes.emplace_back();
    196195                }
    197196
     
    227226                                return const_iterator( const_cast< ScopedMap< Key, Value >* >(this)->find( key ) );
    228227                }
    229                
     228
    230229                /// Finds the given key in the outermost scope inside the given scope where it occurs
    231230                iterator findNext( const_iterator &it, const Key &key ) {
     
    247246                        return std::make_pair( iterator(scopes, res.first, scopes.size()-1), res.second );
    248247                }
     248
     249                std::pair< iterator, bool > insert( value_type &&value ) {
     250                        std::pair< typename Scope::iterator, bool > res = scopes.back().insert( std::move( value ) );
     251                        return std::make_pair( iterator(scopes, std::move( res.first ), scopes.size()-1), std::move( res.second ) );
     252                }
     253
    249254                std::pair< iterator, bool > insert( const Key &key, const Value &value ) { return insert( std::make_pair( key, value ) ); }
     255                std::pair< iterator, bool > insert( const Key &key, Value &&value ) { return insert( std::make_pair( key, std::move( value ) ) ); }
    250256
    251257                Value& operator[] ( const Key &key ) {
     
    254260                        return insert( key, Value() ).first->second;
    255261                }
     262
     263                iterator erase( iterator pos ) {
     264                        Scope& scope = (*pos.scopes) [ pos.i ];
     265                        const typename iterator::wrapped_iterator& new_it = scope.erase( pos.it );
     266                        iterator it( *pos.scopes, new_it, pos.i );
     267                        return it.next_valid();
     268                }
     269
     270                size_type count( const Key &key ) const {
     271                        size_type c = 0;
     272                        auto it = find( key );
     273                        auto end = cend();
     274
     275                        while(it != end) {
     276                                c++;
     277                                it = findNext(it, key);
     278                        }
     279
     280                        return c;
     281                }
     282
    256283        };
    257284} // namespace GenPoly
Note: See TracChangeset for help on using the changeset viewer.