Changes in / [2ed1d50:7bb6bd8]


Ignore:
Location:
src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Node.hpp

    r2ed1d50 r7bb6bd8  
    3232                }
    3333
    34                 template<typename node_t>
    35                 friend auto mutate(const node_t * node);
    36 
    3734        private:
    3835                size_t strong_ref = 0;
     
    4037        };
    4138
    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>
    7840        class ptr_base {
    7941        public:
     
    12587
    12688        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        };
    128128
    129129        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        };
    131156}
  • src/Common/Assert.cc

    r2ed1d50 r7bb6bd8  
    3939}
    4040
    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 
    5141// Local Variables: //
    5242// tab-width: 4 //
  • src/Common/PassVisitor.impl.h

    r2ed1d50 r7bb6bd8  
    2020
    2121#define MUTATE_END( type, node )                \
    22         auto __return = call_postmutate< type * >( node ); \
    23         assert( __return ); \
    24         return __return;
     22        return call_postmutate< type * >( node ); \
    2523
    2624
  • src/Common/PassVisitor.proto.h

    r2ed1d50 r7bb6bd8  
    174174FIELD_PTR( PassVisitor<pass_type> * const, visitor )
    175175
    176 #undef FIELD_PTR
    177 
    178176//---------------------------------------------------------
    179177// Indexer
  • src/ControlStruct/ExceptTranslate.cc

    r2ed1d50 r7bb6bd8  
    617617                                return create_terminate_rethrow( throwStmt );
    618618                        } else {
    619                                 abort("Invalid throw in %s at %i\n",
     619                                assertf(false, "Invalid throw in %s at %i\n",
    620620                                        throwStmt->location.filename.c_str(),
    621621                                        throwStmt->location.first_line);
     622                                return nullptr;
    622623                        }
    623624                } else {
     
    627628                                return create_resume_rethrow( throwStmt );
    628629                        } else {
    629                                 abort("Invalid throwResume in %s at %i\n",
     630                                assertf(false, "Invalid throwResume in %s at %i\n",
    630631                                        throwStmt->location.filename.c_str(),
    631632                                        throwStmt->location.first_line);
     633                                return nullptr;
    632634                        }
    633635                }
  • src/include/cassert

    r2ed1d50 r7bb6bd8  
    4545}
    4646
    47 extern void abort(const char *fmt, ...  ) noexcept __attribute__((noreturn, format(printf, 1, 2)));
    4847// Local Variables: //
    4948// tab-width: 4 //
  • src/main.cc

    r2ed1d50 r7bb6bd8  
    4040#include "Common/Stats.h"
    4141#include "Common/PassVisitor.h"
    42 // #include "AST/Pass.hpp"
    4342#include "Common/SemanticError.h"           // for SemanticError
    4443#include "Common/UnimplementedError.h"      // for UnimplementedError
Note: See TracChangeset for help on using the changeset viewer.