Ignore:
Timestamp:
Apr 14, 2016, 4:13:10 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
356189a
Parents:
db4ecc5 (diff), 37f0da8 (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.
Message:

Merge branch 'master' into ctor

Conflicts:

src/CodeGen/CodeGenerator.cc
src/GenPoly/Box.cc
src/Parser/DeclarationNode.cc
src/Parser/ParseNode.h
src/Parser/parser.cc
src/Parser/parser.yy
src/SymTab/AddVisit.h
src/SymTab/Validate.cc
src/SynTree/Expression.cc
src/SynTree/Expression.h
src/SynTree/Mutator.cc
src/SynTree/Mutator.h
src/SynTree/SynTree.h
src/SynTree/Visitor.cc
src/SynTree/Visitor.h
src/libcfa/iostream.c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/ScopedMap.h

    rdb4ecc5 r70a06f6  
    1717#define _SCOPEDMAP_H
    1818
     19#include <cassert>
    1920#include <iterator>
    2021#include <map>
     
    5051                        typedef typename scope_list::size_type size_type;
    5152
     53                        /// Checks if this iterator points to a valid item
     54                        bool is_valid() const {
     55                                return it != (*scopes)[i].end();
     56                        }
     57
     58                        /// Increments on invalid
     59                        iterator& next_valid() {
     60                                if ( ! is_valid() ) { ++(*this); }
     61                                return *this;
     62                        }
     63
     64                        /// Decrements on invalid
     65                        iterator& prev_valid() {
     66                                if ( ! is_valid() ) { --(*this); }
     67                                return *this;
     68                        }
     69
    5270                        iterator(scope_list const &_scopes, const wrapped_iterator &_it, size_type _i)
    5371                                : scopes(&_scopes), it(_it), i(_i) {}
     
    6785                                        --i;
    6886                                        it = (*scopes)[i].begin();
    69                                         return *this;
    70                                 }
    71                                 ++it;
    72                                 return *this;
     87                                } else {
     88                                        ++it;
     89                                }
     90                                return next_valid();
    7391                        }
    7492                        iterator& operator++ (int) { iterator tmp = *this; ++(*this); return tmp; }
     
    8199                                }
    82100                                --it;
    83                                 return *this;
     101                                return prev_valid();
    84102                        }
    85103                        iterator& operator-- (int) { iterator tmp = *this; --(*this); return tmp; }
     
    104122                        typedef typename scope_list::size_type size_type;
    105123
     124                        /// Checks if this iterator points to a valid item
     125                        bool is_valid() const {
     126                                return it != (*scopes)[i].end();
     127                        }
     128
     129                        /// Increments on invalid
     130                        const_iterator& next_valid() {
     131                                if ( ! is_valid() ) { ++(*this); }
     132                                return *this;
     133                        }
     134
     135                        /// Decrements on invalid
     136                        const_iterator& prev_valid() {
     137                                if ( ! is_valid() ) { --(*this); }
     138                                return *this;
     139                        }
     140
    106141                        const_iterator(scope_list const &_scopes, const wrapped_const_iterator &_it, size_type _i)
    107142                                : scopes(&_scopes), it(_it), i(_i) {}
     
    126161                                        --i;
    127162                                        it = (*scopes)[i].begin();
    128                                         return *this;
    129                                 }
    130                                 ++it;
    131                                 return *this;
     163                                } else {
     164                                        ++it;
     165                                }
     166                                return next_valid();
    132167                        }
    133168                        const_iterator& operator++ (int) { const_iterator tmp = *this; ++(*this); return tmp; }
     
    140175                                }
    141176                                --it;
    142                                 return *this;
     177                                return prev_valid();
    143178                        }
    144179                        const_iterator& operator-- (int) { const_iterator tmp = *this; --(*this); return tmp; }
     
    164199                void endScope() {
    165200                        scopes.pop_back();
     201                        assert( ! scopes.empty() );
    166202                }
    167203
     
    169205                ScopedMap() { beginScope(); }
    170206
    171                 iterator begin() { return iterator(scopes, scopes.back().begin(), scopes.size()-1); }
    172                 const_iterator begin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1); }
    173                 const_iterator cbegin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1); }
     207                iterator begin() { return iterator(scopes, scopes.back().begin(), scopes.size()-1).next_valid(); }
     208                const_iterator begin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1).next_valid(); }
     209                const_iterator cbegin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1).next_valid(); }
    174210                iterator end() { return iterator(scopes, scopes[0].end(), 0); }
    175211                const_iterator end() const { return const_iterator(scopes, scopes[0].end(), 0); }
     
    188224                        return end();
    189225                }
    190                 const_iterator find( const Key &key ) const { return const_iterator( find( key ) ); }
     226                const_iterator find( const Key &key ) const {
     227                                return const_iterator( const_cast< ScopedMap< Key, Value >* >(this)->find( key ) );
     228                }
    191229               
    192230                /// Finds the given key in the outermost scope inside the given scope where it occurs
     
    200238                        return end();
    201239                }
    202                 const_iterator findNext( const_iterator &it, const Key &key ) const { return const_iterator( findNext( it, key ) ); }
     240                const_iterator findNext( const_iterator &it, const Key &key ) const {
     241                                return const_iterator( const_cast< ScopedMap< Key, Value >* >(this)->findNext( it, key ) );
     242                }
    203243
    204244                /// Inserts the given key-value pair into the outermost scope
     
    208248                }
    209249                std::pair< iterator, bool > insert( const Key &key, const Value &value ) { return insert( std::make_pair( key, value ) ); }
    210                
     250
     251                Value& operator[] ( const Key &key ) {
     252                        iterator slot = find( key );
     253                        if ( slot != end() ) return slot->second;
     254                        return insert( key, Value() ).first->second;
     255                }
    211256        };
    212257} // namespace GenPoly
Note: See TracChangeset for help on using the changeset viewer.