source: libcfa/src/enum.hfa@ 3e135c8

Last change on this file since 3e135c8 was 236f133, checked in by JiadaL <j82liang@…>, 15 months ago

Remove quasi_void for enums. The idea of quasi_void from Mike was to get around some resolution problem that enum pick function defines for Bounded over CfaEnum/TypedEnum. But it is not clear that how often this can happen, and cfa might change the cast function scheme in the future. (change cost comparison scheme) Deprecate quasi_void for now so that enum traits looks cleaner without the dummy type for opaque enums

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[72713e5]1#pragma once
2
[85855b0]3#include "iostream.hfa"
4
[d5efcb7]5forall( E ) trait Bounded {
[85855b0]6 E lowerBound();
7 E upperBound();
8};
9
[64eeb06]10forall( E | Bounded( E ) ) trait Serial {
[d5efcb7]11 unsigned fromInstance( E e );
12 E fromInt( unsigned i );
13 E succ( E e );
14 E pred( E e );
[85855b0]15};
16
[236f133]17forall( E | Serial( E ) ) trait CfaEnum {
[bb336a6]18 const char * label( E e );
[d5efcb7]19 unsigned int posn( E e );
[236f133]20};
21
22forall( E, V | CfaEnum( E ) ) trait TypedEnum {
[d5efcb7]23 V value( E e );
[85855b0]24};
25
[d5efcb7]26// I/O
[85855b0]27
[236f133]28forall( istype & | istream( istype ), E | CfaEnum( E ) )
[bc48c0d]29istype & ?|?( istype &, E & );
[64eeb06]30
[236f133]31forall( ostype & | ostream( ostype ), E | CfaEnum( E ) ) {
[d5efcb7]32 ostype & ?|?( ostype &, E );
33 OSTYPE_VOID( E );
34}
35
[236f133]36// forall( ostype & | ostream( ostype ), E | CfaEnum( E, quasi_void ) ) {
37// ostype & ?|?( ostype &, E );
38// OSTYPE_VOID( E );
39// }
[85855b0]40
41// Design two <- should go for this if we have change the cost model
[64eeb06]42// forall( E | Serial( E ) ) trait CfaEnum {
43// char * label( E e );
44// unsigned int posn( E e );
[85855b0]45// };
46
[64eeb06]47// forall( E, V| CfaEnum( E)) trait TypedEnum {
48// V value( E e);
[85855b0]49// };
[525f7ad]50
[062467b]51static inline
[236f133]52forall( E | CfaEnum( E ) ) {
[062467b]53 int ?==?( E l, E r ) { return posn( l ) == posn( r ); } // relational operators
54 int ?!=?( E l, E r ) { return posn( l ) != posn( r ); }
55 int ?<?( E l, E r ) { return posn( l ) < posn( r ); }
56 int ?<=?( E l, E r ) { return posn( l ) <= posn( r ); }
57 int ?>?( E l, E r ) { return posn( l ) > posn( r ); }
58 int ?>=?( E l, E r ) { return posn( l ) >= posn( r ); }
59
60 E ++?( E & l ) { // increment operators
61 l = succ( l );
62 return l;
63 }
64
65 E ?++( E & l ) {
66 E ret = l;
67 l = succ( l );
68 return ret;
69 }
70
71 E --?( E & l ) {
72 l = pred( l );
73 return l;
74 }
75
76 E ?--( E & l ) {
77 E ret = l;
78 l = pred( l );
79 return ret;
80 }
[64eeb06]81}
Note: See TracBrowser for help on using the repository browser.