Ignore:
Timestamp:
Jul 18, 2017, 4:35:52 PM (7 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:
f19339e
Parents:
795d450
Message:

Convert more library files to use references

File:
1 edited

Legend:

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

    r795d450 r242a902  
    1919
    2020forall(otype T, otype E)
    21 void ?{}(result(T, E) * this) {
    22         this->has_value = false;
    23         (&this->error){};
     21void ?{}(result(T, E) & this) {
     22        this.has_value = false;
     23        (this.error){};
    2424}
    2525
    2626forall(otype T, otype E)
    27 void ?{}(result(T, E) * this, one_t, T value) {
    28         this->has_value = true;
    29         (&this->value){value};
     27void ?{}(result(T, E) & this, one_t, T value) {
     28        this.has_value = true;
     29        (this.value){value};
    3030}
    3131
    3232forall(otype T, otype E)
    33 void ?{}(result(T, E) * this, zero_t, E error) {
    34         this->has_value = false;
    35         (&this->error){error};
     33void ?{}(result(T, E) & this, zero_t, E error) {
     34        this.has_value = false;
     35        (this.error){error};
    3636}
    3737
    3838forall(otype T, otype E)
    39 void ?{}(result(T, E) * this, result(T, E) other) {
    40         this->has_value = other.has_value;
     39void ?{}(result(T, E) & this, result(T, E) other) {
     40        this.has_value = other.has_value;
    4141        if (other.has_value) {
    42                 (&this->value){other.value};
     42                (this.value){other.value};
    4343        } else {
    44                 (&this->error){other.error};
     44                (this.error){other.error};
    4545        }
    4646}
    4747
    4848forall(otype T, otype E)
    49 result(T, E) ?=?(result(T, E) * this, result(T, E) that) {
    50         if (this->has_value & that.has_value) {
    51                 this->value = that.value;
    52         } else if (this->has_value) {
    53                 ^(&this->value){};
    54                 this->has_value = false;
    55                 (&this->error){that.error};
     49result(T, E) ?=?(result(T, E) & this, result(T, E) that) {
     50        if (this.has_value & that.has_value) {
     51                this.value = that.value;
     52        } else if (this.has_value) {
     53                ^(this.value){};
     54                this.has_value = false;
     55                (this.error){that.error};
    5656        } else if (that.has_value) {
    57                 ^(&this->error){};
    58                 this->has_value = true;
    59                 (&this->value){that.value};
     57                ^(this.error){};
     58                this.has_value = true;
     59                (this.value){that.value};
    6060        } else {
    61                 this->error = that.error;
     61                this.error = that.error;
    6262        }
    6363}
    6464
    6565forall(otype T, otype E)
    66 void ^?{}(result(T, E) * this) {
    67         if (this->has_value) {
    68                 ^(&this->value){};
     66void ^?{}(result(T, E) & this) {
     67        if (this.has_value) {
     68                ^(this.value){};
    6969        } else {
    70                 ^(&this->error){};
     70                ^(this.error){};
    7171        }
    7272}
     
    109109                this->value = value;
    110110        } else {
    111                 ^(&this->error){};
     111                ^(this->error){};
    112112                this->has_value = true;
    113                 (&this->value){value};
     113                (this->value){value};
    114114        }
    115115}
     
    118118void set_error(result(T, E) * this, E error) {
    119119        if (this->has_value) {
    120                 ^(&this->value){};
     120                ^(this->value){};
    121121                this->has_value = false;
    122                 (&this->error){error};
     122                (this->error){error};
    123123        } else {
    124124                this->error = error;
Note: See TracChangeset for help on using the changeset viewer.