Changeset 85855b0 for libcfa/src
- Timestamp:
- Jun 10, 2024, 2:43:13 AM (5 months ago)
- Branches:
- master
- Children:
- 42cdd07d
- Parents:
- d68de59
- Location:
- libcfa/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/enum.cfa
rd68de59 r85855b0 1 1 #include "enum.hfa" 2 #include "fstream.hfa" 2 3 3 4 #pragma GCC visibility push(default) 4 5 5 forall(T, E| TypedEnum(T, E)) { 6 // constructors 6 forall(ostype & | basic_ostream(ostype), E, V| CfaEnum(E, V)) 7 ostype & ?|?(ostype& os, E e) { 8 return os | type_name(e) | "." | labelE(e); 9 } 7 10 8 // comparison 9 int ?==?(E l, E r) { return posE(l) == posE(r); } 10 int ?!=?(E l, E r) { return posE(l) != posE(r); } 11 int ?!=?(E l, zero_t) { return !( posE(l) == 0 ); } 12 int ?<?(E l, E r) { return posE(l) < posE(r); } 13 int ?<=?(E l, E r) { return posE(l) <= posE(r); } 14 int ?>?(E l, E r) { return posE(l) > posE(r); } 15 int ?>=?(E l, E r) { return posE(l) >= posE(r); } 11 forall(ostype & | basic_ostream(ostype), E| CfaEnum(E, quasi_void)) 12 ostype & ?|?(ostype& os, E e) { 13 return os | type_name(e) | "." | labelE(e); 16 14 } -
libcfa/src/enum.hfa
rd68de59 r85855b0 1 1 #pragma once 2 2 3 forall(T) { // T is the based type of enum(T) 4 forall(E) trait Bounded { 5 E lowerBound(); 6 E upperBound(); 7 }; 3 #include "iostream.hfa" 8 4 9 forall(E| Bounded(T, E)) trait Serial { 10 unsigned fromInstance(E e); 11 E fromInt(unsigned i); 12 E succ(E e); 13 E pred(E e); 14 }; 5 forall(E) trait Bounded { 6 E lowerBound(); 7 E upperBound(); 8 }; 15 9 16 // Opague Enum + TypedEnum 17 forall(E | Serial(T, E)) trait CfaEnum { 18 char * labelE(E e); 19 unsigned int posE(E e); 20 }; 10 forall(E | Bounded(E)) trait Serial { 11 unsigned fromInstance(E e); 12 E fromInt(unsigned i); 13 E succ(E e); 14 E pred(E e); 15 }; 21 16 22 forall(E| CfaEnum(T, E)) trait TypedEnum { 23 T valueE(E e); 24 }; 17 // Design one 18 forall(E, V | Serial(E)) trait CfaEnum { 19 char* labelE(E e); 20 unsigned int posE(E e); 21 V valueE(E e); 22 char* type_name(E e); 23 }; 25 24 26 forall(E | TypedEnum(T, E)) { 27 // comparison 28 int ?==?(E l, E r); // true if l and r are same enumerators 29 int ?!=?(E l, E r); // true if l and r are different enumerators 30 int ?!=?(E l, zero_t); // true if l is not the first enumerator 31 int ?<?(E l, E r); // true if l is an enuemerator before r 32 int ?<=?(E l, E r); // true if l before or the same as r 33 int ?>?(E l, E r); // true if l is an enuemrator after r 34 int ?>=?(E l, E r); // true if l after or the same as r 35 } 36 } 25 forall(ostype & | basic_ostream(ostype), E, V| CfaEnum(E, V)) 26 ostype & ?|?(ostype&, E); 27 28 forall(ostype & | basic_ostream(ostype), E| CfaEnum(E, quasi_void)) 29 ostype & ?|?(ostype&, E); 30 31 // Design two <- should go for this if we have change the cost model 32 // forall(E | Serial(E)) trait CfaEnum { 33 // char* labelE(E e); 34 // unsigned int posE(E e); 35 // }; 36 37 // forall(E, V| CfaEnum(E)) trait TypedEnum { 38 // V valueE(E e); 39 // };
Note: See TracChangeset
for help on using the changeset viewer.