Changes in / [2ed1d50:7bb6bd8]
- Location:
- src
- Files:
-
- 7 edited
-
AST/Node.hpp (modified) (3 diffs)
-
Common/Assert.cc (modified) (1 diff)
-
Common/PassVisitor.impl.h (modified) (1 diff)
-
Common/PassVisitor.proto.h (modified) (1 diff)
-
ControlStruct/ExceptTranslate.cc (modified) (2 diffs)
-
include/cassert (modified) (1 diff)
-
main.cc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Node.hpp
r2ed1d50 r7bb6bd8 32 32 } 33 33 34 template<typename node_t>35 friend auto mutate(const node_t * node);36 37 34 private: 38 35 size_t strong_ref = 0; … … 40 37 }; 41 38 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> 39 template< typename node_t, enum Node::ref_type ref_t> 78 40 class ptr_base { 79 41 public: … … 125 87 126 88 template< typename node_t > 127 using ptr = ptr_base< node_t, Node::ref_type::strong >; 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 }; 128 128 129 129 template< typename node_t > 130 using readonly = ptr_base< node_t, Node::ref_type::weak >; 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 }; 131 156 } -
src/Common/Assert.cc
r2ed1d50 r7bb6bd8 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 51 41 // Local Variables: // 52 42 // tab-width: 4 // -
src/Common/PassVisitor.impl.h
r2ed1d50 r7bb6bd8 20 20 21 21 #define MUTATE_END( type, node ) \ 22 auto __return = call_postmutate< type * >( node ); \ 23 assert( __return ); \ 24 return __return; 22 return call_postmutate< type * >( node ); \ 25 23 26 24 -
src/Common/PassVisitor.proto.h
r2ed1d50 r7bb6bd8 174 174 FIELD_PTR( PassVisitor<pass_type> * const, visitor ) 175 175 176 #undef FIELD_PTR177 178 176 //--------------------------------------------------------- 179 177 // Indexer -
src/ControlStruct/ExceptTranslate.cc
r2ed1d50 r7bb6bd8 617 617 return create_terminate_rethrow( throwStmt ); 618 618 } else { 619 a bort("Invalid throw in %s at %i\n",619 assertf(false, "Invalid throw in %s at %i\n", 620 620 throwStmt->location.filename.c_str(), 621 621 throwStmt->location.first_line); 622 return nullptr; 622 623 } 623 624 } else { … … 627 628 return create_resume_rethrow( throwStmt ); 628 629 } else { 629 a bort("Invalid throwResume in %s at %i\n",630 assertf(false, "Invalid throwResume in %s at %i\n", 630 631 throwStmt->location.filename.c_str(), 631 632 throwStmt->location.first_line); 633 return nullptr; 632 634 } 633 635 } -
src/include/cassert
r2ed1d50 r7bb6bd8 45 45 } 46 46 47 extern void abort(const char *fmt, ... ) noexcept __attribute__((noreturn, format(printf, 1, 2)));48 47 // Local Variables: // 49 48 // tab-width: 4 // -
src/main.cc
r2ed1d50 r7bb6bd8 40 40 #include "Common/Stats.h" 41 41 #include "Common/PassVisitor.h" 42 // #include "AST/Pass.hpp"43 42 #include "Common/SemanticError.h" // for SemanticError 44 43 #include "Common/UnimplementedError.h" // for UnimplementedError
Note:
See TracChangeset
for help on using the changeset viewer.