Changes in src/AST/Node.hpp [52a4d69:18e683b]
- File:
-
- 1 edited
-
src/AST/Node.hpp (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Node.hpp
r52a4d69 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; … … 57 57 template<typename node_t> 58 58 friend node_t * mutate(const node_t * node); 59 template<typename node_t>60 friend node_t * shallowCopy(const node_t * node);61 59 62 60 mutable size_t strong_count = 0; … … 71 69 } 72 70 73 void decrement(ast::Node::ref_type ref , bool do_delete = true) const {71 void decrement(ast::Node::ref_type ref) const { 74 72 switch (ref) { 75 73 case ref_type::strong: strong_count--; break; … … 77 75 } 78 76 79 if( do_delete &&!strong_count && !weak_count) {77 if(!strong_count && !weak_count) { 80 78 delete this; 81 79 } … … 96 94 assertf( 97 95 node->weak_count == 0, 98 "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" 99 97 ); 100 98 return node->clone(); … … 106 104 // skip mutate if equivalent 107 105 if ( node->*field == val ) return node; 108 106 109 107 // mutate and return 110 108 node_t * ret = mutate( node ); … … 125 123 (ret->*field)[i] = std::forward< field_t >( val ); 126 124 return ret; 127 }128 129 /// Mutate an entire indexed collection by cloning to accepted value130 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;136 125 } 137 126 … … 230 219 operator const node_t * () const { _check(); return node; } 231 220 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 241 221 /// wrapper for convenient access to dynamic_cast 242 222 template<typename o_node_t> 243 223 const o_node_t * as() const { _check(); return dynamic_cast<const o_node_t *>(node); } 244 224 245 /// Wrapper that makes sure dynamic_cast returns non-null.225 /// wrapper for convenient access to strict_dynamic_cast 246 226 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); } 255 228 256 229 /// Returns a mutable version of the pointer in this node. … … 271 244 272 245 void _inc( const node_t * other ); 273 void _dec( const node_t * other , bool do_delete = true);246 void _dec( const node_t * other ); 274 247 void _check() const; 275 void _strict_fail() const __attribute__((noreturn));276 248 277 249 const node_t * node;
Note:
See TracChangeset
for help on using the changeset viewer.