Changeset 236f133


Ignore:
Timestamp:
Jul 11, 2024, 3:04:34 PM (4 days ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
9c447e2
Parents:
9d5eacb
Message:

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

Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/enum.cfa

    r9d5eacb r236f133  
    1010} // scmp
    1111
    12 forall( istype & | istream( istype ), E, V | CfaEnum( E, V ) )
     12forall( istype & | istream( istype ), E | CfaEnum( E ) )
    1313istype & ?|?( istype & is, E & e ) {
    1414//      printf( "here0\n" );
     
    7070}
    7171
    72 forall( ostype & | ostream( ostype ), E, V | CfaEnum( E, V ) ) {
     72// forall( ostype & | ostream( ostype ), E | CfaEnum( E, quasi_void ) ) {
     73//      ostype & ?|?( ostype & os, E e ) {
     74//              return os | label( e );
     75//      }
     76//      OSTYPE_VOID_IMPL( E )
     77// }
     78
     79forall( ostype & | ostream( ostype ), E | CfaEnum( E ) ) {
    7380        ostype & ?|?( ostype & os, E e ) {
    7481                return os | label( e );
     
    7784}
    7885
    79 forall( ostype & | ostream( ostype ), E | CfaEnum( E, quasi_void ) ) {
    80         ostype & ?|?( ostype & os, E e ) {
    81                 return os | label( e );
    82         }
    83         OSTYPE_VOID_IMPL( E )
    84 }
     86//
  • libcfa/src/enum.hfa

    r9d5eacb r236f133  
    1515};
    1616
    17 // Design one
    18 forall( E, V | Serial( E ) ) trait CfaEnum {
     17forall( E | Serial( E ) ) trait CfaEnum {
    1918    const char * label( E e );
    2019    unsigned int posn( E e );
     20};
     21
     22forall( E, V | CfaEnum( E ) ) trait TypedEnum {
    2123    V value( E e );
    2224};
     
    2426// I/O
    2527
    26 forall( istype & | istream( istype ), E, V | CfaEnum( E, V ) )
     28forall( istype & | istream( istype ), E | CfaEnum( E ) )
    2729istype & ?|?( istype &, E & );
    2830
    29 forall( ostype & | ostream( ostype ), E, V | CfaEnum( E, V ) ) {
     31forall( ostype & | ostream( ostype ), E | CfaEnum( E ) ) {
    3032        ostype & ?|?( ostype &, E );
    3133        OSTYPE_VOID( E );
    3234}
    3335
    34 forall( ostype & | ostream( ostype ), E | CfaEnum( E, quasi_void ) ) {
    35         ostype & ?|?( ostype &, E );
    36         OSTYPE_VOID( E );
    37 }
     36// forall( ostype & | ostream( ostype ), E | CfaEnum( E, quasi_void ) ) {
     37//      ostype & ?|?( ostype &, E );
     38//      OSTYPE_VOID( E );
     39// }
    3840
    3941// Design two <- should go for this if we have change the cost model
     
    4850
    4951static inline
    50 forall( E, V | CfaEnum( E, V ) ) {
     52forall( E | CfaEnum( E ) ) {
    5153    int ?==?( E l, E r ) { return posn( l ) == posn( r ); }     // relational operators
    5254    int ?!=?( E l, E r ) { return posn( l ) != posn( r ); }
  • src/Validate/ImplementEnumFunc.cpp

    r9d5eacb r236f133  
    2525                : decl(decl),
    2626                  functionNesting{functionNesting},
    27                   quasi_void_decl(new ast::StructDecl(decl->location,
    28                         "quasi_void", ast::AggregateDecl::Struct,
    29                         {}, ast::Linkage::AutoGen)),
     27                //   quasi_void_decl(new ast::StructDecl(decl->location,
     28                //      "quasi_void", ast::AggregateDecl::Struct,
     29                //      {}, ast::Linkage::AutoGen)),
    3030                  proto_linkage{ast::Linkage::Cforall} {}
    3131
     
    208208
    209209ast::FunctionDecl* EnumAttrFuncGenerator::genValueProto() const {
    210         if (decl->isTyped())
    211                 return genProto(
    212                         "value",
    213                         {new ast::ObjectDecl(getLocation(), "_i", new ast::EnumInstType(decl))},
    214                         {new ast::ObjectDecl(getLocation(), "_ret",
    215                                                                 ast::deepCopy(decl->base))});
    216         else
    217                 return genQuasiValueProto();
    218 }
    219 
    220 ast::FunctionDecl* EnumAttrFuncGenerator::genQuasiValueProto() const {
     210        assert (decl->isTyped());
    221211        return genProto(
    222212                "value",
    223213                {new ast::ObjectDecl(getLocation(), "_i", new ast::EnumInstType(decl))},
    224214                {new ast::ObjectDecl(getLocation(), "_ret",
    225                                                 new ast::StructInstType(quasi_void_decl))});
    226 }
     215                                                        ast::deepCopy(decl->base))});
     216        // else
     217        //      return genQuasiValueProto();
     218}
     219
     220// ast::FunctionDecl* EnumAttrFuncGenerator::genQuasiValueProto() const {
     221//      return genProto(
     222//              "value",
     223//              {new ast::ObjectDecl(getLocation(), "_i", new ast::EnumInstType(decl))},
     224//              {new ast::ObjectDecl(getLocation(), "_ret",
     225//                                              new ast::StructInstType(quasi_void_decl))});
     226// }
    227227
    228228ast::FunctionDecl* EnumAttrFuncGenerator::genFromIntProto() const {
     
    390390}
    391391
    392 void EnumAttrFuncGenerator::genQuasiValueBody(ast::FunctionDecl* func) const {
    393         auto location = func->location;
    394         const ast::ObjectDecl * objDecl = new ast::ObjectDecl(
    395                 location, "_out", new ast::StructInstType( quasi_void_decl ));
    396         const ast::DeclStmt * declStmt = new ast::DeclStmt(location, objDecl);
    397         const ast::VariableExpr * varExpr = new ast::VariableExpr(location, objDecl);
    398         const ast::ReturnStmt * retStmt = new ast::ReturnStmt(location, varExpr);
    399 
    400         func->stmts = new ast::CompoundStmt(
    401                 location, {declStmt, retStmt}
    402         );
    403 }
     392// void EnumAttrFuncGenerator::genQuasiValueBody(ast::FunctionDecl* func) const {
     393//      auto location = func->location;
     394//      const ast::ObjectDecl * objDecl = new ast::ObjectDecl(
     395//              location, "_out", new ast::StructInstType( quasi_void_decl ));
     396//      const ast::DeclStmt * declStmt = new ast::DeclStmt(location, objDecl);
     397//      const ast::VariableExpr * varExpr = new ast::VariableExpr(location, objDecl);
     398//      const ast::ReturnStmt * retStmt = new ast::ReturnStmt(location, varExpr);
     399
     400//      func->stmts = new ast::CompoundStmt(
     401//              location, {declStmt, retStmt}
     402//      );
     403// }
    404404
    405405void EnumAttrFuncGenerator::genPosnBody(ast::FunctionDecl* func) const {
     
    433433                        genValueOrLabelBody(funcProto, arrayProto);
    434434                        produceDecl(funcProto);
    435                 }  else {
    436                         ast::FunctionDecl* funcProto = genQuasiValueProto();
    437                         produceForwardDecl(funcProto);
    438                         genQuasiValueBody(funcProto);
    439                         produceDecl(funcProto);
    440                 }
     435                } 
     436                // else {
     437                //      ast::FunctionDecl* funcProto = genQuasiValueProto();
     438                //      produceForwardDecl(funcProto);
     439                //      // genQuasiValueBody(funcProto);
     440                //      produceDecl(funcProto);
     441                // }
    441442        } else if (attr == ast::EnumAttribute::Label) {
    442443                std::vector<ast::ptr<ast::Init>> inits = genLabelInit();
  • tests/enum_tests/voidEnum.cfa

    r9d5eacb r236f133  
    11#include <fstream.hfa>
    22#include <enum.hfa>
    3 enum() voidEnum {
    4     a, b, c
    5     /***
    6     * ,d = 10 // Disable;
    7     * //error: Enumerator of enum(void) cannot have an explicit initial value.
    8     */
    9 };
    103
    11 char* a[voidEnum] = {
    12     "A",
    13     "B",
    14     "C"
    15 };
    16 
     4enum() E { A, B, C };
    175int main() {
    18     enum voidEnum v_1 = a;
    19     enum voidEnum v_2 = b;
    20     sout | "Two different Opague Enum Should not be the same:";
    21     if ( v_1 == v_2 ) {
    22         sout | "a and b are Equal" | nl;
    23     } else {
    24         sout | "a and b are Not Equal" | nl;
    25     }
    26     sout | "Default Output:";
    27     sout | a;
    28     sout | b;
    29    
    30     sout | label(v_1);
    31     sout | label(v_2);
     6    E e = A;
     7    sout | e | posn( e ) | label( e );
    328}
Note: See TracChangeset for help on using the changeset viewer.