Ignore:
Timestamp:
Sep 20, 2016, 4:47:34 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
1132b62
Parents:
aefcc3b (diff), db46512 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into tuples

Conflicts:

src/Makefile.in
src/ResolvExpr/Unify.cc
src/SynTree/Type.h

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/containers/vector.c

    raefcc3b r23b6643f  
    1818#include <stdlib>
    1919
     20forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     21void copy_internal(vector(T, allocator_t)* this, vector(T, allocator_t)* other);
     22
    2023//------------------------------------------------------------------------------
    2124//Initialization
    2225forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    23 void ctor(vector(T, allocator_t) *const this)
     26void ?{}(vector(T, allocator_t)* this)
    2427{
    25         ctor(&this->storage);
     28        (&this->storage){};
    2629        this->size = 0;
    2730}
    2831
    2932forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    30 void dtor(vector(T, allocator_t) *const this)
     33void ?{}(vector(T, allocator_t)* this, vector(T, allocator_t) rhs)
     34{
     35        (&this->storage){ rhs.storage };
     36        copy_internal(this, &rhs);
     37}
     38
     39// forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     40// vector(T, allocator_t) ?=?(vector(T, allocator_t)* this, vector(T, allocator_t) rhs)
     41// {
     42//      (&this->storage){};
     43//      copy_internal(this, &rhs);
     44//      return *this;
     45// }
     46
     47forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     48void ^?{}(vector(T, allocator_t)* this)
    3149{
    3250        clear(this);
    33         dtor(&this->storage);
     51        ^(&this->storage){};
    3452}
    3553
     
    3755//Modifiers
    3856forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    39 void push_back(vector(T, allocator_t) *const this, T value)
     57void push_back(vector(T, allocator_t)* this, T value)
    4058{
    4159        realloc_storage(&this->storage, this->size+1);
     
    4563
    4664forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    47 void pop_back(vector(T, allocator_t) *const this)
     65void pop_back(vector(T, allocator_t)* this)
    4866{
    4967        this->size--;
    50         DESTROY(data(&this->storage)[this->size]);
     68        ^(&data(&this->storage)[this->size]){};
    5169}
    5270
    5371forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    54 void clear(vector(T, allocator_t) *const this)
     72void clear(vector(T, allocator_t)* this)
    5573{
    5674        for(size_t i = 0; i < this->size; i++)
    5775        {
    58                 DESTROY(data(&this->storage)[this->size]);
     76                ^(&data(&this->storage)[this->size]){};
    5977        }
    6078        this->size = 0;
     
    6280
    6381//------------------------------------------------------------------------------
     82//Internal Helpers
     83
     84forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
     85void copy_internal(vector(T, allocator_t)* this, vector(T, allocator_t)* other)
     86{
     87        this->size = other->size;
     88        for(size_t i = 0; i < this->size; i++) {
     89                (&data(&this->storage)[this->size]){ data(&other->storage)[other->size] };
     90        }
     91}
     92
     93//------------------------------------------------------------------------------
    6494//Allocator
    6595forall(otype T)
    66 void ctor(heap_allocator(T) *const this)
     96void ?{}(heap_allocator(T)* this)
    6797{
    6898        this->storage = 0;
     
    71101
    72102forall(otype T)
    73 void dtor(heap_allocator(T) *const this)
     103void ?{}(heap_allocator(T)* this, heap_allocator(T) rhs)
     104{
     105        this->capacity = rhs.capacity;
     106        this->storage = (T*)realloc((void*)this->storage, this->capacity * sizeof(T));
     107}
     108
     109forall(otype T)
     110heap_allocator(T) ?=?(heap_allocator(T)* this, heap_allocator(T) rhs)
     111{
     112        this->capacity = rhs.capacity;
     113        this->storage = (T*)realloc((void*)this->storage, this->capacity * sizeof(T));
     114        return *this;
     115}
     116
     117forall(otype T)
     118void ^?{}(heap_allocator(T)* this)
    74119{
    75120        free(this->storage);
     
    77122
    78123forall(otype T)
    79 inline void realloc_storage(heap_allocator(T) *const this, size_t size)
     124inline void realloc_storage(heap_allocator(T)* this, size_t size)
    80125{
    81126        enum { GROWTH_RATE = 2 };
Note: See TracChangeset for help on using the changeset viewer.