Changeset 6a625de
- Timestamp:
- May 8, 2019, 4:19:13 PM (6 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:
- 2ed1d50
- Parents:
- b1d3ee1
- Location:
- src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Node.hpp
rb1d3ee1 r6a625de 32 32 } 33 33 34 template<typename node_t> 35 friend auto mutate(const node_t * node); 36 34 37 private: 35 38 size_t strong_ref = 0; … … 37 40 }; 38 41 39 template< typename node_t, enum Node::ref_type ref_t> 42 // Mutate a node, non-member function to avoid static type 43 // problems and be able to use auto return 44 template<typename node_t> 45 auto mutate(const node_t * node) { 46 assertf( 47 node->strong_count >= 1, 48 "Error: attempting to mutate a node that appears to have been linked" 49 ); 50 if (node->strong_count == 1) { 51 return const_cast<node_t *>(node); 52 } 53 54 assertf( 55 node->weak_count == 0, 56 "Error: mutating node with weak references to it will invalided some references" 57 ); 58 return node->clone(); 59 } 60 61 // All accept routines should look as follows : 62 // virtual void accept( Visitor &v ) override { 63 // return v.visit(this); 64 // } 65 // Using the following wrapper to handle the node type 66 template< typename node_t > 67 auto visit_this( visitor & v, node_t * node ) { 68 ptr<node_t> p; 69 p.node = node; 70 auto r = v.visit(p); 71 p.node = nullptr; 72 return r; 73 } 74 75 // Base class for the smart pointer types 76 // should never really be used. 77 template< typename node_t, enum Node::ref_type ref_t> 40 78 class ptr_base { 41 79 public: … … 87 125 88 126 template< typename node_t > 89 class ptr : public ptr_base< node_t, Node::ref_type::strong > { 90 public: 91 typedef ptr_base< node_t, Node::ref_type::strong > base_t; 92 93 ptr() = default; 94 ptr( node_t node ) : base_t( node ) {} 95 ~ptr() = default; 96 97 template< enum Node::ref_type ref_t > 98 ptr( const ptr_base<node_t, ref_t> & o ) : base_t(o) {} 99 100 template< enum Node::ref_type ref_t > 101 ptr( ptr_base<node_t, ref_t> && o ) : base_t( std::move(o) ) {} 102 103 template< enum Node::ref_type o_ref_t > 104 ptr & operator=( const ptr_base<node_t, o_ref_t> & o ) { 105 base_t::operator=(o); 106 return *this; 107 } 108 109 template< enum Node::ref_type o_ref_t > 110 ptr & operator=( ptr_base<node_t, o_ref_t> && o ) { 111 base_t::operator=(std::move(o)); 112 return *this; 113 } 114 115 node_t * mutate() { 116 using base_t::node; 117 assert(node->strong_count); 118 if (node->strong_count == 1) { 119 return node; 120 } 121 122 assertf(node->weak_count == 0, "Error: mutating node with weak references to it will invalided some references"); 123 auto n = new node_t(*node); 124 assign(n); 125 return node; 126 } 127 }; 127 using ptr = ptr_base< node_t, Node::ref_type::strong >; 128 128 129 129 template< typename node_t > 130 class readonly : public ptr_base< node_t, Node::ref_type::weak > { 131 public: 132 typedef ptr_base< node_t, Node::ref_type::strong > base_t; 133 134 readonly() = default; 135 readonly( node_t node ) : base_t( node ) {} 136 ~readonly() = default; 137 138 template< enum Node::ref_type ref_t > 139 readonly( const ptr_base<node_t, ref_t> & o ) : base_t(o) {} 140 141 template< enum Node::ref_type ref_t > 142 readonly( ptr_base<node_t, ref_t> && o ) : base_t( std::move(o) ) {} 143 144 template< enum Node::ref_type o_ref_t > 145 readonly & operator=( const ptr_base<node_t, o_ref_t> & o ) { 146 base_t::operator=(o); 147 return *this; 148 } 149 150 template< enum Node::ref_type o_ref_t > 151 readonly & operator=( ptr_base<node_t, o_ref_t> && o ) { 152 base_t::operator=(std::move(o)); 153 return *this; 154 } 155 }; 130 using readonly = ptr_base< node_t, Node::ref_type::weak >; 156 131 } -
src/Common/Assert.cc
rb1d3ee1 r6a625de 39 39 } 40 40 41 void abort(const char *fmt, ... ) noexcept __attribute__((noreturn, format(printf, 1, 2))); 42 void abort(const char *fmt, ... ) noexcept { 43 va_list args; 44 va_start( args, fmt ); 45 vfprintf( stderr, fmt, args ); 46 va_end( args ); 47 fprintf( stderr, "\n" ); 48 abort(); 49 } 50 41 51 // Local Variables: // 42 52 // tab-width: 4 // -
src/Common/PassVisitor.impl.h
rb1d3ee1 r6a625de 20 20 21 21 #define MUTATE_END( type, node ) \ 22 return call_postmutate< type * >( node ); \ 22 auto __return = call_postmutate< type * >( node ); \ 23 assert( __return ); \ 24 return __return; 23 25 24 26 -
src/Common/PassVisitor.proto.h
rb1d3ee1 r6a625de 174 174 FIELD_PTR( PassVisitor<pass_type> * const, visitor ) 175 175 176 #undef FIELD_PTR 177 176 178 //--------------------------------------------------------- 177 179 // Indexer -
src/ControlStruct/ExceptTranslate.cc
rb1d3ee1 r6a625de 617 617 return create_terminate_rethrow( throwStmt ); 618 618 } else { 619 a ssertf(false,"Invalid throw in %s at %i\n",619 abort("Invalid throw in %s at %i\n", 620 620 throwStmt->location.filename.c_str(), 621 621 throwStmt->location.first_line); 622 return nullptr;623 622 } 624 623 } else { … … 628 627 return create_resume_rethrow( throwStmt ); 629 628 } else { 630 a ssertf(false,"Invalid throwResume in %s at %i\n",629 abort("Invalid throwResume in %s at %i\n", 631 630 throwStmt->location.filename.c_str(), 632 631 throwStmt->location.first_line); 633 return nullptr;634 632 } 635 633 } -
src/include/cassert
rb1d3ee1 r6a625de 45 45 } 46 46 47 extern void abort(const char *fmt, ... ) noexcept __attribute__((noreturn, format(printf, 1, 2))); 47 48 // Local Variables: // 48 49 // tab-width: 4 // -
src/main.cc
rb1d3ee1 r6a625de 40 40 #include "Common/Stats.h" 41 41 #include "Common/PassVisitor.h" 42 // #include "AST/Pass.hpp" 42 43 #include "Common/SemanticError.h" // for SemanticError 43 44 #include "Common/UnimplementedError.h" // for UnimplementedError
Note: See TracChangeset
for help on using the changeset viewer.