Changeset a4943d8c for src/libcfa/containers
- Timestamp:
- May 25, 2017, 12:55:12 PM (8 years ago)
- 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:
- 58daf53, 84d58c5, cc38669
- Parents:
- bc37a83 (diff), e883a4b (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. - Location:
- src/libcfa/containers
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/containers/maybe
rbc37a83 ra4943d8c 18 18 #define MAYBE_H 19 19 20 #include <stdbool.h> 20 21 21 22 // DO NOT USE DIRECTLY! 22 23 forall(otype T) 23 24 struct maybe { 24 _Bool has_value;25 bool has_value; 25 26 T value; 26 27 }; … … 40 41 41 42 forall(otype T) 42 _Bool ?!=?(result(T, E) this, zero_t);43 bool ?!=?(maybe(T) this, zero_t); 43 44 44 45 forall(otype T) … … 49 50 50 51 forall(otype T) 51 _Bool has_value(maybe(T) * this);52 bool has_value(maybe(T) * this); 52 53 53 54 forall(otype T) -
src/libcfa/containers/maybe.c
rbc37a83 ra4943d8c 40 40 void ^?{}(maybe(T) * this) { 41 41 if (this->has_value) { 42 ^( this->value){};42 ^(&this->value){}; 43 43 } 44 44 } 45 45 46 46 forall(otype T) 47 _Bool ?!=?(result(T, E) this, zero_t) {48 return !this ->has_value;47 bool ?!=?(maybe(T) this, zero_t) { 48 return !this.has_value; 49 49 } 50 50 51 51 forall(otype T) 52 52 maybe(T) maybe_value(T value) { 53 return ( Maybe(T)){value};53 return (maybe(T)){value}; 54 54 } 55 55 56 56 forall(otype T) 57 57 maybe(T) maybe_none() { 58 return ( Maybe(T)){};58 return (maybe(T)){}; 59 59 } 60 60 61 61 forall(otype T) 62 _Bool has_value(maybe(T) * this) {62 bool has_value(maybe(T) * this) { 63 63 return this->has_value; 64 64 } -
src/libcfa/containers/result
rbc37a83 ra4943d8c 18 18 #define RESULT_H 19 19 20 #include <stdbool.h> 20 21 21 22 // DO NOT USE DIRECTLY! 22 23 forall(otype T, otype E) 24 union inner_result{ 25 T value; 26 E error; 27 }; 28 29 forall(otype T, otype E) 23 30 struct result { 24 _Bool has_value; 25 union { 26 T value; 27 E error; 28 }; 31 bool has_value; 32 inner_result(T, E); 29 33 }; 30 34 … … 46 50 47 51 forall(otype T, otype E) 48 _Bool ?!=?(result(T, E) this, zero_t);52 bool ?!=?(result(T, E) this, zero_t); 49 53 50 54 forall(otype T, otype E) … … 55 59 56 60 forall(otype T, otype E) 57 _Bool has_value(result(T, E) * this);61 bool has_value(result(T, E) * this); 58 62 59 63 forall(otype T, otype E) -
src/libcfa/containers/result.c
rbc37a83 ra4943d8c 21 21 void ?{}(result(T, E) * this) { 22 22 this->has_value = false; 23 ( this->error){};23 (&this->error){}; 24 24 } 25 25 … … 49 49 void ^?{}(result(T, E) * this) { 50 50 if (this->has_value) { 51 ^( this->value){};51 ^(&this->value){}; 52 52 } else { 53 ^( this->error){};53 ^(&this->error){}; 54 54 } 55 55 } 56 56 57 57 forall(otype T, otype E) 58 _Bool ?!=?(result(T, E) this, zero_t) {59 return !this ->has_value;58 bool ?!=?(result(T, E) this, zero_t) { 59 return !this.has_value; 60 60 } 61 61 62 62 forall(otype T, otype E) 63 63 result(T, E) result_value(T value) { 64 return ( Result(T, E)){1, value};64 return (result(T, E)){1, value}; 65 65 } 66 66 67 67 forall(otype T, otype E) 68 68 result(T, E) result_error(E error) { 69 return ( Result(T, E)){0, value};69 return (result(T, E)){0, error}; 70 70 } 71 71 72 72 forall(otype T, otype E) 73 _Bool has_value(result(T, E) * this) {73 bool has_value(result(T, E) * this) { 74 74 return this->has_value; 75 75 } … … 77 77 forall(otype T, otype E) 78 78 T get(result(T, E) * this) { 79 79 assertf(this->has_value, "attempt to get from result without value"); 80 80 return this->value; 81 81 } … … 83 83 forall(otype T, otype E) 84 84 E get_error(result(T, E) * this) { 85 85 assertf(this->has_value, "attempt to get from result without error"); 86 86 return this->error; 87 87 }
Note:
See TracChangeset
for help on using the changeset viewer.