Ignore:
Timestamp:
May 25, 2017, 3:39:02 PM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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:
41634098, 8712514
Parents:
7f612112 (diff), f851015 (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' of plg2:software/cfa/cfa-cc

File:
1 edited

Legend:

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

    r7f612112 r1eeab94  
    88//
    99// Author           : Andrew Beach
    10 // Created On       : Wed May 25 15:40:00 2017
     10// Created On       : Wed May 24 15:40:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed May 25 17:02:00 2017
     12// Last Modified On : Thr May 25 15:27:00 2017
    1313// Update Count     : 1
    1414//
     
    2727void ?{}(result(T, E) * this, one_t, T value) {
    2828        this->has_value = true;
    29         this->value = value;
     29        (&this->value){value};
    3030}
    3131
     
    3333void ?{}(result(T, E) * this, zero_t, E error) {
    3434        this->has_value = false;
    35         this->error = error;
     35        (&this->error){error};
    3636}
    3737
     
    4040        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};
     45        }
     46}
     47
     48forall(otype T, otype E)
     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};
     56        } else if (that.has_value) {
     57                ^(&this->error){};
     58                this->has_value = true;
     59                (&this->value){that.value};
     60        } else {
     61                this->error = that.error;
    4562        }
    4663}
     
    86103        return this->error;
    87104}
     105
     106forall(otype T, otype E)
     107void set(result(T, E) * this, T value) {
     108        if (this->has_value) {
     109                this->value = value;
     110        } else {
     111                ^(&this->error){};
     112                this->has_value = true;
     113                (&this->value){value};
     114        }
     115}
     116
     117forall(otype T, otype E)
     118void set_error(result(T, E) * this, E error) {
     119        if (this->has_value) {
     120                ^(&this->value){};
     121                this->has_value = false;
     122                (&this->error){error};
     123        } else {
     124                this->error = error;
     125        }
     126}
Note: See TracChangeset for help on using the changeset viewer.