Changeset 7d0881c


Ignore:
Timestamp:
Jun 28, 2019, 11:59:00 AM (2 years ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast, new-ast-unique-expr
Children:
55b6476
Parents:
e0e9a0b
Message:

Aaron added decrement-without delete option to Node infrastructure

Location:
src/AST
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Node.cpp

    re0e9a0b r7d0881c  
    5050
    5151template< typename node_t, enum ast::Node::ref_type ref_t >
    52 void ast::ptr_base<node_t, ref_t>::_dec( const node_t * node ) {
     52void ast::ptr_base<node_t, ref_t>::_dec( const node_t * node, bool do_delete ) {
    5353        _trap( node );
    54         node->decrement(ref_t);
     54        node->decrement(ref_t, do_delete );
    5555}
    5656
  • src/AST/Node.hpp

    re0e9a0b r7d0881c  
    6969        }
    7070
    71         void decrement(ast::Node::ref_type ref) const {
     71        void decrement(ast::Node::ref_type ref, bool do_delete = true) const {
    7272                switch (ref) {
    7373                        case ref_type::strong: strong_count--; break;
     
    7575                }
    7676
    77                 if(!strong_count && !weak_count) {
     77                if( do_delete && !strong_count && !weak_count) {
    7878                        delete this;
    7979                }
     
    228228        operator const node_t * () const { _check(); return node; }
    229229
     230        const node_t * release() {
     231                const node_t * ret = node;
     232                if ( node ) {
     233                        _dec(node, false);
     234                        node = nullptr;
     235                }
     236                return ret;
     237        }
     238
    230239        /// wrapper for convenient access to dynamic_cast
    231240        template<typename o_node_t>
     
    253262
    254263        void _inc( const node_t * other );
    255         void _dec( const node_t * other );
     264        void _dec( const node_t * other, bool do_delete = true );
    256265        void _check() const;
    257266
Note: See TracChangeset for help on using the changeset viewer.