source: src/examples/gc_no_raii/src/gcpointers.h @ f1e42c1

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since f1e42c1 was f1e42c1, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

added some basic tests and modified compilation to support them

  • Property mode set to 100644
File size: 1.7 KB
Line 
1#pragma once
2
3#include <stdbool.h>
4#include <stdint.h>
5
6struct gcpointer_t
7{
8        intptr_t ptr;
9        struct gcpointer_t* next;
10};
11
12void gcpointer_ctor(gcpointer_t* this);
13void gcpointer_ctor(gcpointer_t* this, void* address);
14void gcpointer_ctor(gcpointer_t* this, gcpointer_t* other);
15void gcpointer_dtor(gcpointer_t* this);
16gcpointer_t* gcpointer_assign(gcpointer_t* this, gcpointer_t* rhs);
17
18//Logical operators
19bool gcpointer_equal(gcpointer_t* this, gcpointer_t* rhs);
20bool gcpointer_not_equal(gcpointer_t* this, gcpointer_t* rhs);
21bool gcpointer_null(gcpointer_t* this);
22
23forall(otype T)
24struct gcpointer
25{
26        gcpointer_t internal;
27};
28
29forall(otype T)
30static inline void ctor(gcpointer(T)* this)
31{
32        gcpointer_ctor(&this->internal);
33}
34
35// forall(otype T)
36// static inline void ctor(gcpointer(T)* this, int null)
37// {
38//      gcpointer_ctor(&this->internal, NULL);
39// }
40
41forall(otype T)
42static inline void ctor(gcpointer(T)* this, void* address)
43{
44        gcpointer_ctor(&this->internal, address);
45}
46
47forall(otype T)
48static inline void ctor(gcpointer(T)* this, gcpointer(T)* other)
49{
50        gcpointer_ctor(&this->internal, other);
51}
52
53forall(otype T)
54static inline void dtor(gcpointer(T)* this)
55{
56        gcpointer_dtor(&this->internal);
57}
58
59forall(otype T)
60static inline gcpointer(T)* ?=?(gcpointer(T)* this, gcpointer(T)* rhs)
61{
62        gcpointer_assign(&this->internal, &rhs->internal);
63        return this;
64}
65
66forall(otype T)
67static inline T *?(gcpointer(T) this)
68{
69        return *(T*)this.internal.ptr;
70}
71
72//Logical operators
73forall(otype T)
74static inline int ?!=?(gcpointer(T) this, gcpointer(T) rhs)
75{
76        return this.internal.ptr != rhs.internal.ptr;
77}
78
79forall(otype T)
80static inline int ?==?(gcpointer(T) this, gcpointer(T) rhs)
81{
82        return !(this == rhs);
83}
84
85forall(otype T)
86extern struct gcpointer(T) 0;
Note: See TracBrowser for help on using the repository browser.