Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Node.hpp

    r52a4d69 r18e683b  
    1010// Created On       : Wed May 8 10:27:04 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Jun 5 9:47:00 2020
    13 // Update Count     : 6
     12// Last Modified On : Mon Jun  3 13:26:00 2019
     13// Update Count     : 5
    1414//
    1515
     
    3838        Node& operator= (const Node&) = delete;
    3939        Node& operator= (Node&&) = delete;
    40         virtual ~Node() {}
     40        virtual ~Node() = default;
    4141
    4242        virtual const Node * accept( Visitor & v ) const = 0;
     
    5757        template<typename node_t>
    5858        friend node_t * mutate(const node_t * node);
    59         template<typename node_t>
    60         friend node_t * shallowCopy(const node_t * node);
    6159
    6260        mutable size_t strong_count = 0;
     
    7169        }
    7270
    73         void decrement(ast::Node::ref_type ref, bool do_delete = true) const {
     71        void decrement(ast::Node::ref_type ref) const {
    7472                switch (ref) {
    7573                        case ref_type::strong: strong_count--; break;
     
    7775                }
    7876
    79                 if( do_delete && !strong_count && !weak_count) {
     77                if(!strong_count && !weak_count) {
    8078                        delete this;
    8179                }
     
    9694        assertf(
    9795                node->weak_count == 0,
    98                 "Error: mutating node with weak references to it will invalidate some references"
     96                "Error: mutating node with weak references to it will invalided some references"
    9997        );
    10098        return node->clone();
     
    106104        // skip mutate if equivalent
    107105        if ( node->*field == val ) return node;
    108 
     106       
    109107        // mutate and return
    110108        node_t * ret = mutate( node );
     
    125123        (ret->*field)[i] = std::forward< field_t >( val );
    126124        return ret;
    127 }
    128 
    129 /// Mutate an entire indexed collection by cloning to accepted value
    130 template<typename node_t, typename parent_t, typename coll_t>
    131 const node_t * mutate_each( const node_t * node, coll_t parent_t::* field, Visitor & v ) {
    132         for ( unsigned i = 0; i < (node->*field).size(); ++i ) {
    133                 node = mutate_field_index( node, field, i, (node->*field)[i]->accept( v ) );
    134         }
    135         return node;
    136125}
    137126
     
    230219        operator const node_t * () const { _check(); return node; }
    231220
    232         const node_t * release() {
    233                 const node_t * ret = node;
    234                 if ( node ) {
    235                         _dec(node, false);
    236                         node = nullptr;
    237                 }
    238                 return ret;
    239         }
    240 
    241221        /// wrapper for convenient access to dynamic_cast
    242222        template<typename o_node_t>
    243223        const o_node_t * as() const { _check(); return dynamic_cast<const o_node_t *>(node); }
    244224
    245         /// Wrapper that makes sure dynamic_cast returns non-null.
     225        /// wrapper for convenient access to strict_dynamic_cast
    246226        template<typename o_node_t>
    247         const o_node_t * strict_as() const {
    248                 if (const o_node_t * ret = as<o_node_t>()) return ret;
    249                 _strict_fail();
    250         }
    251 
    252         /// Wrapper that makes sure dynamic_cast does not fail.
    253         template<typename o_node_t, decltype(nullptr) null>
    254         const o_node_t * strict_as() const { return node ? strict_as<o_node_t>() : nullptr; }
     227        const o_node_t * strict_as() const { _check(); return strict_dynamic_cast<const o_node_t *>(node); }
    255228
    256229        /// Returns a mutable version of the pointer in this node.
     
    271244
    272245        void _inc( const node_t * other );
    273         void _dec( const node_t * other, bool do_delete = true );
     246        void _dec( const node_t * other );
    274247        void _check() const;
    275         void _strict_fail() const __attribute__((noreturn));
    276248
    277249        const node_t * node;
Note: See TracChangeset for help on using the changeset viewer.