- Timestamp:
- Jun 5, 2019, 4:28:28 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 0ce063b
- Parents:
- 2a8f0c1
- Location:
- src/AST
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Node.cpp
r2a8f0c1 r4864a73 34 34 template< typename node_t, enum ast::Node::ref_type ref_t > 35 35 void ast::ptr_base<node_t, ref_t>::_dec( const node_t * node ) { node->decrement(ref_t); } 36 37 template< typename node_t, enum ast::Node::ref_type ref_t > 38 void ast::ptr_base<node_t, ref_t>::_check() const { if(node) assert(node->was_ever_strong == false || node->strong_count > 0); } 36 39 37 40 template< typename node_t, enum ast::Node::ref_type ref_t > -
src/AST/Node.hpp
r2a8f0c1 r4864a73 46 46 }; 47 47 48 bool unique() const { return strong_count == 1; } 49 48 50 private: 49 51 /// Make a copy of this node; should be overridden in subclass with more precise return type … … 56 58 mutable size_t strong_count = 0; 57 59 mutable size_t weak_count = 0; 60 mutable bool was_ever_strong = false; 58 61 59 62 void increment(ref_type ref) const { 60 63 switch (ref) { 61 case ref_type::strong: strong_count++; break;64 case ref_type::strong: strong_count++; was_ever_strong = true; break; 62 65 case ref_type::weak : weak_count ++; break; 63 66 } … … 176 179 } 177 180 178 const node_t * get() const { return node; }179 const node_t * operator->() const { return node; }180 const node_t & operator* () const { return *node; }181 explicit operator bool() const { return node; }182 operator const node_t * () const { return node; }181 const node_t * get() const { _check(); return node; } 182 const node_t * operator->() const { _check(); return node; } 183 const node_t & operator* () const { _check(); return *node; } 184 explicit operator bool() const { _check(); return node; } 185 operator const node_t * () const { _check(); return node; } 183 186 184 187 /// wrapper for convenient access to dynamic_cast 185 188 template<typename o_node_t> 186 const o_node_t * as() const { return dynamic_cast<const o_node_t *>(node); }189 const o_node_t * as() const { _check(); return dynamic_cast<const o_node_t *>(node); } 187 190 188 191 /// wrapper for convenient access to strict_dynamic_cast … … 208 211 void _inc( const node_t * other ); 209 212 void _dec( const node_t * other ); 213 void _check() const; 210 214 211 215 protected:
Note: See TracChangeset
for help on using the changeset viewer.