Ignore:
Timestamp:
Jun 10, 2024, 2:43:13 AM (4 weeks ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
42cdd07d
Parents:
d68de59
Message:
  1. Implement enum cast; 2. Change valueE so that opague enum returns quasi_void; 3. change enum hiding interpretation and pass visiting scheme
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/enum.hfa

    rd68de59 r85855b0  
    11#pragma once
    22
    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"
    84
    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     };
     5forall(E) trait Bounded {
     6    E lowerBound();
     7    E upperBound();
     8};
    159
    16     // Opague Enum + TypedEnum
    17     forall(E | Serial(T, E)) trait CfaEnum {
    18         char * labelE(E e);
    19         unsigned int posE(E e);
    20     };
     10forall(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};
    2116
    22     forall(E| CfaEnum(T, E)) trait TypedEnum {
    23         T valueE(E e);
    24     };
     17// Design one
     18forall(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};
    2524
    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 }
     25forall(ostype & | basic_ostream(ostype), E, V| CfaEnum(E, V))
     26ostype & ?|?(ostype&, E);
     27
     28forall(ostype & | basic_ostream(ostype), E| CfaEnum(E, quasi_void))
     29ostype & ?|?(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.