Changeset 5ba653c for src/GenPoly


Ignore:
Timestamp:
Apr 11, 2016, 4:41:22 PM (8 years ago)
Author:
Aaron Moss <a3moss@…>
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, string, with_gc
Children:
df2be83
Parents:
6f49cdf
Message:

Fix latent empty-scope iteration bug in ScopedMap/Set?

Location:
src/GenPoly
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/ScopedMap.h

    r6f49cdf r5ba653c  
    5151                        typedef typename scope_list::size_type size_type;
    5252
     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
    5370                        iterator(scope_list const &_scopes, const wrapped_iterator &_it, size_type _i)
    5471                                : scopes(&_scopes), it(_it), i(_i) {}
     
    6885                                        --i;
    6986                                        it = (*scopes)[i].begin();
    70                                         return *this;
    71                                 }
    72                                 ++it;
    73                                 return *this;
     87                                } else {
     88                                        ++it;
     89                                }
     90                                return next_valid();
    7491                        }
    7592                        iterator& operator++ (int) { iterator tmp = *this; ++(*this); return tmp; }
     
    8299                                }
    83100                                --it;
    84                                 return *this;
     101                                return prev_valid();
    85102                        }
    86103                        iterator& operator-- (int) { iterator tmp = *this; --(*this); return tmp; }
     
    105122                        typedef typename scope_list::size_type size_type;
    106123
     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
    107141                        const_iterator(scope_list const &_scopes, const wrapped_const_iterator &_it, size_type _i)
    108142                                : scopes(&_scopes), it(_it), i(_i) {}
     
    127161                                        --i;
    128162                                        it = (*scopes)[i].begin();
    129                                         return *this;
    130                                 }
    131                                 ++it;
    132                                 return *this;
     163                                } else {
     164                                        ++it;
     165                                }
     166                                return next_valid();
    133167                        }
    134168                        const_iterator& operator++ (int) { const_iterator tmp = *this; ++(*this); return tmp; }
     
    141175                                }
    142176                                --it;
    143                                 return *this;
     177                                return prev_valid();
    144178                        }
    145179                        const_iterator& operator-- (int) { const_iterator tmp = *this; --(*this); return tmp; }
     
    171205                ScopedMap() { beginScope(); }
    172206
    173                 iterator begin() { return iterator(scopes, scopes.back().begin(), scopes.size()-1); }
    174                 const_iterator begin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1); }
    175                 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(); }
    176210                iterator end() { return iterator(scopes, scopes[0].end(), 0); }
    177211                const_iterator end() const { return const_iterator(scopes, scopes[0].end(), 0); }
  • src/GenPoly/ScopedSet.h

    r6f49cdf r5ba653c  
    4848                        typedef typename scope_list::size_type size_type;
    4949
     50                        /// Checks if this iterator points to a valid item
     51                        bool is_valid() const {
     52                                return it != (*scopes)[i].end();
     53                        }
     54
     55                        /// Increments on invalid
     56                        iterator& next_valid() {
     57                                if ( ! is_valid() ) { ++(*this); }
     58                                return *this;
     59                        }
     60
     61                        /// Decrements on invalid
     62                        iterator& prev_valid() {
     63                                if ( ! is_valid() ) { --(*this); }
     64                                return *this;
     65                        }
     66
    5067                        iterator(scope_list const &_scopes, const wrapped_iterator &_it, size_type _i)
    5168                                : scopes(&_scopes), it(_it), i(_i) {}
     
    6582                                        --i;
    6683                                        it = (*scopes)[i].begin();
    67                                         return *this;
    68                                 }
    69                                 ++it;
    70                                 return *this;
     84                                } else {
     85                                        ++it;
     86                                }
     87                                return next_valid();
    7188                        }
    7289                        iterator& operator++ (int) { iterator tmp = *this; ++(*this); return tmp; }
     
    7996                                }
    8097                                --it;
    81                                 return *this;
     98                                return prev_valid();
    8299                        }
    83100                        iterator& operator-- (int) { iterator tmp = *this; --(*this); return tmp; }
     
    102119                        typedef typename scope_list::size_type size_type;
    103120
     121                        /// Checks if this iterator points to a valid item
     122                        bool is_valid() const {
     123                                return it != (*scopes)[i].end();
     124                        }
     125
     126                        /// Increments on invalid
     127                        const_iterator& next_valid() {
     128                                if ( ! is_valid() ) { ++(*this); }
     129                                return *this;
     130                        }
     131
     132                        /// Decrements on invalid
     133                        const_iterator& prev_valid() {
     134                                if ( ! is_valid() ) { --(*this); }
     135                                return *this;
     136                        }
     137
    104138                        const_iterator(scope_list const &_scopes, const wrapped_const_iterator &_it, size_type _i)
    105139                                : scopes(&_scopes), it(_it), i(_i) {}
     
    124158                                        --i;
    125159                                        it = (*scopes)[i].begin();
    126                                         return *this;
    127                                 }
    128                                 ++it;
    129                                 return *this;
     160                                } else {
     161                                        ++it;
     162                                }
     163                                return next_valid();
    130164                        }
    131165                        const_iterator& operator++ (int) { const_iterator tmp = *this; ++(*this); return tmp; }
     
    138172                                }
    139173                                --it;
    140                                 return *this;
     174                                return prev_valid();
    141175                        }
    142176                        const_iterator& operator-- (int) { const_iterator tmp = *this; --(*this); return tmp; }
     
    167201                ScopedSet() { beginScope(); }
    168202
    169                 iterator begin() { return iterator(scopes, scopes.back().begin(), scopes.size()-1); }
    170                 const_iterator begin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1); }
    171                 const_iterator cbegin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1); }
     203                iterator begin() { return iterator(scopes, scopes.back().begin(), scopes.size()-1).next_valid(); }
     204                const_iterator begin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1).next_valid(); }
     205                const_iterator cbegin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1).next_valid(); }
    172206                iterator end() { return iterator(scopes, scopes[0].end(), 0); }
    173207                const_iterator end() const { return const_iterator(scopes, scopes[0].end(), 0); }
Note: See TracChangeset for help on using the changeset viewer.