Changeset 2bb4a01
- Timestamp:
- May 9, 2019, 3:21:39 PM (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:
- 8d90b6b, a300e4a
- Parents:
- f47f887
- Location:
- src/AST
- Files:
-
- 15 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Node.hpp
rf47f887 r2bb4a01 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // Node.hpp -- 8 // 9 // Author : Thierry Delisle 10 // Created On : Wed May 8 10:27:04 2019 11 // Last Modified By : Aaron B. Moss 12 // Last Modified On : Wed May 8 11:00:00 2019 13 // Update Count : 2 14 // 15 1 16 #pragma once 2 17 3 #include <memory> 18 #include <cassert> 19 #include <iosfwd> 4 20 5 21 namespace ast { 22 23 class Visitor; 24 25 /// Base class for all AST nodes. 26 /// Keeps both strong and weak reference counts. 6 27 class Node { 7 28 public: 29 // override defaults to ensure assignment doesn't 30 // change/share reference counts 31 Node() = default; 32 Node(const Node&) : strong_ref(0), weak_ref(0) {} 33 Node(Node&&) : strong_ref(0), weak_ref(0) {} 34 Node& operator= (const Node&) = delete; 35 Node& operator= (Node&&) = delete; 8 36 virtual ~Node() = default; 9 37 38 virtual Node* accept( Visitor& v ) = 0; 39 40 /// Types of node references 10 41 enum class ref_type { 11 42 strong, … … 35 66 36 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 37 71 mutable size_t strong_ref = 0; 38 72 mutable size_t weak_ref = 0; … … 58 92 } 59 93 94 std::ostream& operator<< ( std::ostream& out, const Node* node ); 95 60 96 // Base class for the smart pointer types 61 97 // should never really be used. … … 76 112 ptr_base( ptr_base<node_t, o_ref_t> && o ) : node(o.node) { 77 113 if( node ) node->increment(ref_t); 78 if( node ) node->decrement(o_ref_t);79 114 } 80 115 … … 89 124 if(o.node == node) return *this; 90 125 assign(o.node); 91 if( node ) node->decrement(o_ref_t);92 126 return *this; 93 127 } … … 112 146 }; 113 147 148 /// Owning pointer to node 114 149 template< typename node_t > 115 150 using ptr = ptr_base< node_t, Node::ref_type::strong >; 116 151 152 /// Observing pointer to node 117 153 template< typename node_t > 118 154 using readonly = ptr_base< node_t, Node::ref_type::weak >; 119 155 } 156 157 // Local Variables: // 158 // tab-width: 4 // 159 // mode: c++ // 160 // compile-command: "make install" // 161 // End: //
Note: See TracChangeset
for help on using the changeset viewer.