source: tests/zombies/gc_no_raii/bug-repro/push_back.h @ ecaedf35

Last change on this file since ecaedf35 was fd54fef, checked in by Michael Brooks <mlbrooks@…>, 4 years ago

Converting the project to use the new syntax for otype, dtype and ttytpe.

Changed prelude (gen), libcfa and test suite to use it. Added a simple deprecation rule of the old syntax to the parser; we might wish to support both syntaxes "officially," like with an extra CLI switch, but this measure should serve as a simple reminder for our team to try the new syntax.

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[df4aea7]1//------------------------------------------------------------------------------
2//Declaration
[fd54fef]3trait allocator_c(T, allocator_t) {
[df4aea7]4        void ctor(allocator_t* const);
5        void dtor(allocator_t* const);
6        void realloc(allocator_t* const, size_t);
7        T* data(allocator_t* const);
8};
9
[fd54fef]10forall(T, allocator_t | allocator_c(T, allocator_t))
[df4aea7]11struct vector
12{
13        allocator_t storage;
14        size_t size;
15};
16
17//------------------------------------------------------------------------------
18//Initialization
[fd54fef]19forall(T, allocator_t | allocator_c(T, allocator_t))
[df4aea7]20void vector_ctor(vector(T, allocator_t) *const this);
21
[fd54fef]22forall(T, allocator_t | allocator_c(T, allocator_t))
[df4aea7]23void dtor(vector(T, allocator_t) *const this);
24
25//------------------------------------------------------------------------------
26//Allocator
[fd54fef]27forall(T)
[df4aea7]28struct heap_allocator
29{
30        T* storage;
31        size_t capacity;
32};
33
[fd54fef]34forall(T)
[df4aea7]35void ctor(heap_allocator(T) *const this);
36
[fd54fef]37forall(T)
[df4aea7]38void dtor(heap_allocator(T) *const this);
39
[fd54fef]40forall(T)
[df4aea7]41void realloc(heap_allocator(T) *const this, size_t size);
42
[fd54fef]43forall(T)
[df4aea7]44inline T* data(heap_allocator(T) *const this)
45{
46        return this->storage;
47}
48
49//------------------------------------------------------------------------------
50//Capacity
[fd54fef]51forall(T, allocator_t | allocator_c(T, allocator_t))
[df4aea7]52inline bool empty(vector(T, allocator_t) *const this)
53{
54        return this->size == 0;
55}
56
[fd54fef]57forall(T, allocator_t | allocator_c(T, allocator_t))
[df4aea7]58inline bool size(vector(T, allocator_t) *const this)
59{
60        return this->size;
61}
62
[fd54fef]63forall(T, allocator_t | allocator_c(T, allocator_t))
[df4aea7]64inline void reserve(vector(T, allocator_t) *const this, size_t size)
65{
66        realloc(&this->storage, this->size+1);
67}
68
69//------------------------------------------------------------------------------
70//Modifiers
[fd54fef]71forall(T, allocator_t | allocator_c(T, allocator_t))
[df4aea7]72void push_back(vector(T, allocator_t) *const this, T value);
Note: See TracBrowser for help on using the repository browser.