Ignore:
Timestamp:
May 4, 2016, 10:45:18 AM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
eb4f201
Parents:
8a74081
Message:

fixed compilation of garbage collector

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/examples/gc_no_raii/src/vector.h

    r8a74081 r4ef8fb3  
    2121        size_t size;
    2222};
    23 //
    24 // //------------------------------------------------------------------------------
    25 // //Initialization
    26 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    27 // void ctor(vector(T, allocator_t) *const this);
    28 //
    29 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    30 // void dtor(vector(T, allocator_t) *const this);
    31 //
    32 // //------------------------------------------------------------------------------
    33 // //Capacity
    34 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    35 // static inline bool empty(vector(T, allocator_t) *const this)
    36 // {
    37 //      return this->size == 0;
    38 // }
    39 //
    40 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    41 // static inline bool size(vector(T, allocator_t) *const this)
    42 // {
    43 //      return this->size;
    44 // }
    45 //
    46 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    47 // static inline void reserve(vector(T, allocator_t) *const this, size_t size)
    48 // {
    49 //      realloc(&this->storage, this->size+1);
    50 // }
    51 //
    52 // //------------------------------------------------------------------------------
    53 // //Element access
    54 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    55 // static inline T at(vector(T, allocator_t) *const this, size_t index)
    56 // {
    57 //      return data(&this->storage)[index];
    58 // }
    59 //
    60 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    61 // static inline T ?[?](vector(T, allocator_t) *const this, size_t index)
    62 // {
    63 //      return data(&this->storage)[index];
    64 // }
    65 //
    66 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    67 // static inline T front(vector(T, allocator_t) *const this)
    68 // {
    69 //      return data(&this->storage)[0];
    70 // }
    71 //
    72 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    73 // static inline T back(vector(T, allocator_t) *const this)
    74 // {
    75 //      return data(&this->storage)[this->size - 1];
    76 // }
    77 //
    78 // //------------------------------------------------------------------------------
    79 // //Modifiers
    80 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    81 // void push_back(vector(T, allocator_t) *const this, T value);
    82 //
    83 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    84 // void pop_back(vector(T, allocator_t) *const this);
    85 //
    86 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    87 // void clear(vector(T, allocator_t) *const this);
    88 //
    89 // //------------------------------------------------------------------------------
    90 // //Iterators
    91 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    92 // static inline T* begin(vector(T, allocator_t) *const this)
    93 // {
    94 //      return data(&this->storage);
    95 // }
    96 //
    97 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    98 // static inline const T* cbegin(const vector(T, allocator_t) *const this)
    99 // {
    100 //      return data(&this->storage);
    101 // }
    102 //
    103 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    104 // static inline T* end(vector(T, allocator_t) *const this)
    105 // {
    106 //      return data(&this->storage) + this->size;
    107 // }
    108 //
    109 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    110 // static inline const T* cend(const vector(T, allocator_t) *const this)
    111 // {
    112 //      return data(&this->storage) + this->size;
    113 // }
    114 //
    115 // //------------------------------------------------------------------------------
    116 // //Allocator
    117 // forall(otype T)
    118 // struct heap_allocator
    119 // {
    120 //      T* storage;
    121 //      size_t capacity;
    122 // };
    123 //
    124 // forall(otype T)
    125 // void ctor(heap_allocator(T) *const this);
    126 //
    127 // forall(otype T)
    128 // void dtor(heap_allocator(T) *const this);
    129 //
    130 // forall(otype T)
    131 // void realloc(heap_allocator(T) *const this, size_t size);
    132 //
    133 // forall(otype T)
    134 // static inline T* data(heap_allocator(T) *const this)
    135 // {
    136 //      return this->storage;
    137 // }
     23
     24//------------------------------------------------------------------------------
     25//Initialization
     26forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     27void ctor(vector(T, allocator_t) *const this);
     28
     29forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     30void dtor(vector(T, allocator_t) *const this);
     31
     32//------------------------------------------------------------------------------
     33//Capacity
     34forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     35static inline bool empty(vector(T, allocator_t) *const this)
     36{
     37        return this->size == 0;
     38}
     39
     40forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     41static inline bool size(vector(T, allocator_t) *const this)
     42{
     43        return this->size;
     44}
     45
     46forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     47static inline void reserve(vector(T, allocator_t) *const this, size_t size)
     48{
     49        realloc(&this->storage, this->size+1);
     50}
     51
     52//------------------------------------------------------------------------------
     53//Element access
     54forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     55static inline T at(vector(T, allocator_t) *const this, size_t index)
     56{
     57        return data(&this->storage)[index];
     58}
     59
     60forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     61static inline T ?[?](vector(T, allocator_t) *const this, size_t index)
     62{
     63        return data(&this->storage)[index];
     64}
     65
     66forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     67static inline T front(vector(T, allocator_t) *const this)
     68{
     69        return data(&this->storage)[0];
     70}
     71
     72forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     73static inline T back(vector(T, allocator_t) *const this)
     74{
     75        return data(&this->storage)[this->size - 1];
     76}
     77
     78//------------------------------------------------------------------------------
     79//Modifiers
     80forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     81void push_back(vector(T, allocator_t) *const this, T value);
     82
     83forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     84void pop_back(vector(T, allocator_t) *const this);
     85
     86forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     87void clear(vector(T, allocator_t) *const this);
     88
     89//------------------------------------------------------------------------------
     90//Iterators
     91forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     92static inline T* begin(vector(T, allocator_t) *const this)
     93{
     94        return data(&this->storage);
     95}
     96
     97forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     98static inline const T* cbegin(const vector(T, allocator_t) *const this)
     99{
     100        return data(&this->storage);
     101}
     102
     103forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     104static inline T* end(vector(T, allocator_t) *const this)
     105{
     106        return data(&this->storage) + this->size;
     107}
     108
     109forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     110static inline const T* cend(const vector(T, allocator_t) *const this)
     111{
     112        return data(&this->storage) + this->size;
     113}
     114
     115//------------------------------------------------------------------------------
     116//Allocator
     117forall(otype T)
     118struct heap_allocator
     119{
     120        T* storage;
     121        size_t capacity;
     122};
     123
     124forall(otype T)
     125void ctor(heap_allocator(T) *const this);
     126
     127forall(otype T)
     128void dtor(heap_allocator(T) *const this);
     129
     130forall(otype T)
     131void realloc(heap_allocator(T) *const this, size_t size);
     132
     133forall(otype T)
     134static inline T* data(heap_allocator(T) *const this)
     135{
     136        return this->storage;
     137}
Note: See TracChangeset for help on using the changeset viewer.