Ignore:
Timestamp:
Jul 12, 2017, 4:40:02 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:
0698aa1
Parents:
469f709
Message:

Convert several library files to use references

Location:
src/libcfa/containers
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/containers/maybe

    r469f709 raca65621  
    2929
    3030forall(otype T)
    31 void ?{}(maybe(T) * this);
     31void ?{}(maybe(T) & this);
    3232
    3333forall(otype T)
    34 void ?{}(maybe(T) * this, T value);
     34void ?{}(maybe(T) & this, T value);
    3535
    3636forall(otype T)
    37 void ?{}(maybe(T) * this, maybe(T) other);
     37void ?{}(maybe(T) & this, maybe(T) other);
    3838
    3939forall(otype T)
    40 void ^?{}(maybe(T) * this);
     40void ^?{}(maybe(T) & this);
    4141
    4242forall(otype T)
    43 maybe(T) ?=?(maybe(T) * this, maybe(T) other);
     43maybe(T) ?=?(maybe(T) & this, maybe(T) other);
    4444
    4545forall(otype T)
  • src/libcfa/containers/maybe.c

    r469f709 raca65621  
    1919
    2020forall(otype T)
    21 void ?{}(maybe(T) * this) {
    22         this->has_value = false;
     21void ?{}(maybe(T) & this) {
     22        this.has_value = false;
    2323}
    2424
    2525forall(otype T)
    26 void ?{}(maybe(T) * this, T value) {
    27         this->has_value = true;
    28         (&this->value){value};
     26void ?{}(maybe(T) & this, T value) {
     27        this.has_value = true;
     28        (this.value){value};
    2929}
    3030
    3131forall(otype T)
    32 void ?{}(maybe(T) * this, maybe(T) other) {
    33         this->has_value = other.has_value;
     32void ?{}(maybe(T) & this, maybe(T) other) {
     33        this.has_value = other.has_value;
    3434        if (other.has_value) {
    35                 (&this->value){other.value};
     35                (this.value){other.value};
    3636        }
    3737}
    3838
    3939forall(otype T)
    40 maybe(T) ?=?(maybe(T) * this, maybe(T) that) {
    41         if (this->has_value & that.has_value) {
    42                 this->value = that.value;
    43         } else if (this->has_value) {
    44                 ^(&this->value){};
    45                 this->has_value = false;
     40maybe(T) ?=?(maybe(T) & this, maybe(T) that) {
     41        if (this.has_value & that.has_value) {
     42                this.value = that.value;
     43        } else if (this.has_value) {
     44                ^(this.value){};
     45                this.has_value = false;
    4646        } else if (that.has_value) {
    47                 this->has_value = true;
    48                 (&this->value){that.value};
     47                this.has_value = true;
     48                (this.value){that.value};
    4949        }
     50        return this;
    5051}
    5152
    5253forall(otype T)
    53 void ^?{}(maybe(T) * this) {
    54         if (this->has_value) {
    55                 ^(&this->value){};
     54void ^?{}(maybe(T) & this) {
     55        if (this.has_value) {
     56                ^(this.value){};
    5657        }
    5758}
     
    8990        } else {
    9091                this->has_value = true;
    91                 (&this->value){value};
     92                (this->value){value};
    9293        }
    9394}
     
    9798        if (this->has_value) {
    9899                this->has_value = false;
    99                 ^(&this->value){};
     100                ^(this->value){};
    100101        }
    101102}
  • src/libcfa/containers/vector

    r469f709 raca65621  
    3131
    3232forall(otype T)
    33 void ?{}(heap_allocator(T)* this);
     33void ?{}(heap_allocator(T)& this);
    3434
    3535forall(otype T)
    36 void ?{}(heap_allocator(T)* this, heap_allocator(T) rhs);
     36void ?{}(heap_allocator(T)& this, heap_allocator(T) rhs);
    3737
    3838forall(otype T)
    39 heap_allocator(T) ?=?(heap_allocator(T)* this, heap_allocator(T) rhs);
     39heap_allocator(T) ?=?(heap_allocator(T)& this, heap_allocator(T) rhs);
    4040
    4141forall(otype T)
    42 void ^?{}(heap_allocator(T)* this);
     42void ^?{}(heap_allocator(T)& this);
    4343
    4444forall(otype T)
     
    6565//Initialization
    6666forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    67 void ?{}(vector(T, allocator_t)* this);
     67void ?{}(vector(T, allocator_t)& this);
    6868
    6969forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    70 void ?{}(vector(T, allocator_t)* this, vector(T, allocator_t) rhs);
     70void ?{}(vector(T, allocator_t)& this, vector(T, allocator_t) rhs);
    7171
    7272forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    73 vector(T, allocator_t) ?=?(vector(T, allocator_t)* this, vector(T, allocator_t) rhs);
     73vector(T, allocator_t) ?=?(vector(T, allocator_t)& this, vector(T, allocator_t) rhs);
    7474
    7575forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    76 void ^?{}(vector(T, allocator_t)* this);
     76void ^?{}(vector(T, allocator_t)& this);
    7777
    7878forall(otype T, otype allocator_t = heap_allocator(T) | allocator_c(T, allocator_t))
  • src/libcfa/containers/vector.c

    r469f709 raca65621  
    2424//Initialization
    2525forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    26 void ?{}(vector(T, allocator_t)* this)
     26void ?{}(vector(T, allocator_t)& this)
    2727{
    28         (&this->storage){};
    29         this->size = 0;
     28        (this.storage){};
     29        this.size = 0;
    3030}
    3131
    3232forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    33 void ?{}(vector(T, allocator_t)* this, vector(T, allocator_t) rhs)
     33void ?{}(vector(T, allocator_t)& this, vector(T, allocator_t) rhs)
    3434{
    35         (&this->storage){ rhs.storage };
    36         copy_internal(this, &rhs);
     35        (this.storage){ rhs.storage };
     36        copy_internal(&this, &rhs);
    3737}
    3838
     
    4646
    4747forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    48 void ^?{}(vector(T, allocator_t)* this)
     48void ^?{}(vector(T, allocator_t)& this)
    4949{
    50         clear(this);
    51         ^(&this->storage){};
     50        clear(&this);
     51        ^(this.storage){};
    5252}
    5353
     
    6666{
    6767        this->size--;
    68         ^(&data(&this->storage)[this->size]){};
     68        ^(data(&this->storage)[this->size]){};
    6969}
    7070
     
    7474        for(size_t i = 0; i < this->size; i++)
    7575        {
    76                 ^(&data(&this->storage)[this->size]){};
     76                ^(data(&this->storage)[this->size]){};
    7777        }
    7878        this->size = 0;
     
    8787        this->size = other->size;
    8888        for(size_t i = 0; i < this->size; i++) {
    89                 (&data(&this->storage)[this->size]){ data(&other->storage)[other->size] };
     89                (data(&this->storage)[this->size]){ data(&other->storage)[other->size] };
    9090        }
    9191}
     
    9494//Allocator
    9595forall(otype T)
    96 void ?{}(heap_allocator(T)* this)
     96void ?{}(heap_allocator(T)& this)
    9797{
    98         this->storage = 0;
    99         this->capacity = 0;
     98        this.storage = 0;
     99        this.capacity = 0;
    100100}
    101101
    102102forall(otype T)
    103 void ?{}(heap_allocator(T)* this, heap_allocator(T) rhs)
     103void ?{}(heap_allocator(T)& this, heap_allocator(T) rhs)
    104104{
    105         this->capacity = rhs.capacity;
    106         this->storage = (T*)realloc((void*)this->storage, this->capacity * sizeof(T));
     105        this.capacity = rhs.capacity;
     106        this.storage = (T*)realloc((void*)this.storage, this.capacity * sizeof(T));
    107107}
    108108
    109109forall(otype T)
    110 heap_allocator(T) ?=?(heap_allocator(T)* this, heap_allocator(T) rhs)
     110heap_allocator(T) ?=?(heap_allocator(T)& this, heap_allocator(T) rhs)
    111111{
    112         this->capacity = rhs.capacity;
    113         this->storage = (T*)realloc((void*)this->storage, this->capacity * sizeof(T));
    114         return *this;
     112        this.capacity = rhs.capacity;
     113        this.storage = (T*)realloc((void*)this.storage, this.capacity * sizeof(T));
     114        return this;
    115115}
    116116
    117117forall(otype T)
    118 void ^?{}(heap_allocator(T)* this)
     118void ^?{}(heap_allocator(T)& this)
    119119{
    120         free(this->storage);
     120        free(this.storage);
    121121}
    122122
Note: See TracChangeset for help on using the changeset viewer.