Changes in src/AST/Node.hpp [302ef2a:18e683b]
- File:
-
- 1 edited
-
src/AST/Node.hpp (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Node.hpp
r302ef2a r18e683b 10 10 // Created On : Wed May 8 10:27:04 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Jun 5 9:47:00 202013 // Update Count : 612 // Last Modified On : Mon Jun 3 13:26:00 2019 13 // Update Count : 5 14 14 // 15 15 … … 38 38 Node& operator= (const Node&) = delete; 39 39 Node& operator= (Node&&) = delete; 40 virtual ~Node() {}40 virtual ~Node() = default; 41 41 42 42 virtual const Node * accept( Visitor & v ) const = 0; … … 49 49 50 50 bool unique() const { return strong_count == 1; } 51 bool isManaged() const {return strong_count > 0; }52 51 53 52 private: … … 58 57 template<typename node_t> 59 58 friend node_t * mutate(const node_t * node); 60 template<typename node_t>61 friend node_t * shallowCopy(const node_t * node);62 59 63 60 mutable size_t strong_count = 0; … … 72 69 } 73 70 74 void decrement(ast::Node::ref_type ref , bool do_delete = true) const {71 void decrement(ast::Node::ref_type ref) const { 75 72 switch (ref) { 76 73 case ref_type::strong: strong_count--; break; … … 78 75 } 79 76 80 if( do_delete &&!strong_count && !weak_count) {77 if(!strong_count && !weak_count) { 81 78 delete this; 82 79 } … … 97 94 assertf( 98 95 node->weak_count == 0, 99 "Error: mutating node with weak references to it will invalid atesome references"96 "Error: mutating node with weak references to it will invalided some references" 100 97 ); 101 98 return node->clone(); … … 107 104 // skip mutate if equivalent 108 105 if ( node->*field == val ) return node; 109 106 110 107 // mutate and return 111 108 node_t * ret = mutate( node ); … … 126 123 (ret->*field)[i] = std::forward< field_t >( val ); 127 124 return ret; 128 }129 130 /// Mutate an entire indexed collection by cloning to accepted value131 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;137 125 } 138 126 … … 229 217 const node_t & operator* () const { _check(); return *node; } 230 218 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; } 242 220 243 221 /// wrapper for convenient access to dynamic_cast … … 245 223 const o_node_t * as() const { _check(); return dynamic_cast<const o_node_t *>(node); } 246 224 247 /// Wrapper that makes sure dynamic_cast returns non-null.225 /// wrapper for convenient access to strict_dynamic_cast 248 226 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); } 257 228 258 229 /// Returns a mutable version of the pointer in this node. … … 273 244 274 245 void _inc( const node_t * other ); 275 void _dec( const node_t * other , bool do_delete = true);246 void _dec( const node_t * other ); 276 247 void _check() const; 277 void _strict_fail() const __attribute__((noreturn));278 248 279 249 const node_t * node;
Note:
See TracChangeset
for help on using the changeset viewer.