Changeset 6d51bd7 for src/AST/Node.hpp
- Timestamp:
- May 15, 2019, 10:15:44 AM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- be567e9
- Parents:
- 712348a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Node.hpp
r712348a r6d51bd7 30 30 // change/share reference counts 31 31 Node() = default; 32 Node(const Node&) : strong_ ref(0), weak_ref(0) {}33 Node(Node&&) : strong_ ref(0), weak_ref(0) {}32 Node(const Node&) : strong_count(0), weak_count(0) {} 33 Node(Node&&) : strong_count(0), weak_count(0) {} 34 34 Node& operator= (const Node&) = delete; 35 35 Node& operator= (Node&&) = delete; 36 36 virtual ~Node() = default; 37 37 38 virtual Node* accept( Visitor& v )= 0;38 virtual const Node * accept( Visitor & v ) const = 0; 39 39 40 40 /// Types of node references … … 46 46 inline void increment(ref_type ref) const { 47 47 switch (ref) { 48 case ref_type::strong: strong_ ref++; break;49 case ref_type::weak : weak_ ref++; break;48 case ref_type::strong: strong_count++; break; 49 case ref_type::weak : weak_count ++; break; 50 50 } 51 51 } … … 53 53 inline void decrement(ref_type ref) const { 54 54 switch (ref) { 55 case ref_type::strong: strong_ ref--; break;56 case ref_type::weak : weak_ ref--; break;55 case ref_type::strong: strong_count--; break; 56 case ref_type::weak : weak_count --; break; 57 57 } 58 58 59 if(!strong_ ref && !weak_ref) {59 if(!strong_count && !weak_count) { 60 60 delete this; 61 61 } 62 62 } 63 private: 64 /// Make a copy of this node; should be overridden in subclass with more precise return type 65 virtual const Node * clone() const = 0; 63 66 67 /// Must be copied in ALL derived classes 64 68 template<typename node_t> 65 69 friend auto mutate(const node_t * node); 66 70 67 private: 68 /// Make a copy of this node; should be overridden in subclass with more precise return type 69 virtual Node* clone() const = 0; 70 71 mutable size_t strong_ref = 0; 72 mutable size_t weak_ref = 0; 71 mutable size_t strong_count = 0; 72 mutable size_t weak_count = 0; 73 73 }; 74 74 … … 100 100 public: 101 101 ptr_base() : node(nullptr) {} 102 ptr_base( node_t * n ) : node(n) { if( !node ) node->increment(ref_t); }103 ~ptr_base() { if( node ) node->decrement(ref_t); }102 ptr_base( const node_t * n ) : node(n) { if( !node ) increment(node, ref_t); } 103 ~ptr_base() { if( node ) decrement(node, ref_t); } 104 104 105 105 template< enum Node::ref_type o_ref_t > 106 106 ptr_base( const ptr_base<node_t, o_ref_t> & o ) : node(o.node) { 107 107 if( !node ) return; 108 node->increment(ref_t);108 increment(node, ref_t); 109 109 } 110 110 111 111 template< enum Node::ref_type o_ref_t > 112 112 ptr_base( ptr_base<node_t, o_ref_t> && o ) : node(o.node) { 113 if( node ) node->increment(ref_t); 113 if( node ) increment(node, ref_t); 114 } 115 116 template<typename o_node_t> 117 ptr_base & operator=( const o_node_t * node ) { 118 assign(strict_dynamic_cast<const node_t *>(node)); 119 return *this; 114 120 } 115 121 … … 136 142 137 143 private: 138 void assign( node_t * other ) {139 if( other ) other->increment(ref_t);140 if( node ) node ->decrement(ref_t);144 void assign(const node_t * other ) { 145 if( other ) increment(other, ref_t); 146 if( node ) decrement(node , ref_t); 141 147 node = other; 142 148 } 143 149 144 150 protected: 145 node_t * node;151 const node_t * node; 146 152 }; 147 153
Note: See TracChangeset
for help on using the changeset viewer.