Changeset bcb311b


Ignore:
Timestamp:
Jun 25, 2019, 2:49:56 PM (5 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
92f5279
Parents:
9ea38de
Message:

Move trap to ref count updates from create/destroy

Location:
src/AST
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Node.cpp

    r9ea38de rbcb311b  
    3030#include "Print.hpp"
    3131
    32 /// MEMORY DEBUG -- allows breaking on construction/destruction of dynamically chosen object.
     32/// MEMORY DEBUG -- allows breaking on ref-count changes of dynamically chosen object.
    3333/// Process to use in GDB:
    3434///   break ast::Node::_trap()
     
    3939void * MEM_TRAP_OBJ = nullptr;
    4040
    41 void ast::Node::_trap() {
    42         if ( this == MEM_TRAP_OBJ ) std::raise(SIGTRAP);
    43 }
    44 
    45 template< typename node_t, enum ast::Node::ref_type ref_t >
    46 void ast::ptr_base<node_t, ref_t>::_inc( const node_t * node ) { node->increment(ref_t); }
    47 
    48 template< typename node_t, enum ast::Node::ref_type ref_t >
    49 void ast::ptr_base<node_t, ref_t>::_dec( const node_t * node ) { node->decrement(ref_t); }
     41void _trap( const void * node ) {
     42        if ( node == MEM_TRAP_OBJ ) std::raise(SIGTRAP);
     43}
     44
     45template< typename node_t, enum ast::Node::ref_type ref_t >
     46void ast::ptr_base<node_t, ref_t>::_inc( const node_t * node ) {
     47        node->increment(ref_t);
     48        _trap( node );
     49}
     50
     51template< typename node_t, enum ast::Node::ref_type ref_t >
     52void ast::ptr_base<node_t, ref_t>::_dec( const node_t * node ) {
     53        _trap( node );
     54        node->decrement(ref_t);
     55}
    5056
    5157template< typename node_t, enum ast::Node::ref_type ref_t >
  • src/AST/Node.hpp

    r9ea38de rbcb311b  
    3030/// Keeps both strong and weak reference counts.
    3131class Node {
    32         /// call to debug on node creation/deletion
    33         void _trap();
    3432public:
    3533        // override defaults to ensure assignment doesn't
    3634        // change/share reference counts
    37         Node() { _trap(); }
    38         Node(const Node&) : strong_count(0), weak_count(0) { _trap(); }
    39         Node(Node&&) : strong_count(0), weak_count(0) { _trap(); }
     35        Node() = default;
     36        Node(const Node&) : strong_count(0), weak_count(0) {}
     37        Node(Node&&) : strong_count(0), weak_count(0) {}
    4038        Node& operator= (const Node&) = delete;
    4139        Node& operator= (Node&&) = delete;
    42         virtual ~Node() { _trap(); }
     40        virtual ~Node() {}
    4341
    4442        virtual const Node * accept( Visitor & v ) const = 0;
Note: See TracChangeset for help on using the changeset viewer.