Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Node.hpp

    r302ef2a 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;
     
    4949
    5050        bool unique() const { return strong_count == 1; }
    51         bool isManaged() const {return strong_count > 0; }
    5251
    5352private:
     
    5857        template<typename node_t>
    5958        friend node_t * mutate(const node_t * node);
    60         template<typename node_t>
    61         friend node_t * shallowCopy(const node_t * node);
    6259
    6360        mutable size_t strong_count = 0;
     
    7269        }
    7370
    74         void decrement(ast::Node::ref_type ref, bool do_delete = true) const {
     71        void decrement(ast::Node::ref_type ref) const {
    7572                switch (ref) {
    7673                        case ref_type::strong: strong_count--; break;
     
    7875                }
    7976
    80                 if( do_delete && !strong_count && !weak_count) {
     77                if(!strong_count && !weak_count) {
    8178                        delete this;
    8279                }
     
    9794        assertf(
    9895                node->weak_count == 0,
    99                 "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"
    10097        );
    10198        return node->clone();
     
    107104        // skip mutate if equivalent
    108105        if ( node->*field == val ) return node;
    109 
     106       
    110107        // mutate and return
    111108        node_t * ret = mutate( node );
     
    126123        (ret->*field)[i] = std::forward< field_t >( val );
    127124        return ret;
    128 }
    129 
    130 /// Mutate an entire indexed collection by cloning to accepted value
    131 template<typename node_t, typename parent_t, typename coll_t>
    132 const node_t * mutate_each( const node_t * node, coll_t parent_t::* field, Visitor & v ) {
    133         for ( unsigned i = 0; i < (node->*field).size(); ++i ) {
    134                 node = mutate_field_index( node, field, i, (node->*field)[i]->accept( v ) );
    135         }
    136         return node;
    137125}
    138126
     
    229217        const node_t & operator* () const { _check(); return *node; }
    230218        explicit operator bool() const { _check(); return node; }
    231         operator const node_t * () const & { _check(); return node; }
    232         operator const node_t * () && = delete;
    233 
    234         const node_t * release() {
    235                 const node_t * ret = node;
    236                 if ( node ) {
    237                         _dec(node, false);
    238                         node = nullptr;
    239                 }
    240                 return ret;
    241         }
     219        operator const node_t * () const { _check(); return node; }
    242220
    243221        /// wrapper for convenient access to dynamic_cast
     
    245223        const o_node_t * as() const { _check(); return dynamic_cast<const o_node_t *>(node); }
    246224
    247         /// Wrapper that makes sure dynamic_cast returns non-null.
     225        /// wrapper for convenient access to strict_dynamic_cast
    248226        template<typename o_node_t>
    249         const o_node_t * strict_as() const {
    250                 if (const o_node_t * ret = as<o_node_t>()) return ret;
    251                 _strict_fail();
    252         }
    253 
    254         /// Wrapper that makes sure dynamic_cast does not fail.
    255         template<typename o_node_t, decltype(nullptr) null>
    256         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); }
    257228
    258229        /// Returns a mutable version of the pointer in this node.
     
    273244
    274245        void _inc( const node_t * other );
    275         void _dec( const node_t * other, bool do_delete = true );
     246        void _dec( const node_t * other );
    276247        void _check() const;
    277         void _strict_fail() const __attribute__((noreturn));
    278248
    279249        const node_t * node;
Note: See TracChangeset for help on using the changeset viewer.