Changeset 236f133
- Timestamp:
- Jul 11, 2024, 3:04:34 PM (9 months ago)
- Branches:
- master
- Children:
- 9c447e2
- Parents:
- 9d5eacb
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/enum.cfa
r9d5eacb r236f133 10 10 } // scmp 11 11 12 forall( istype & | istream( istype ), E , V | CfaEnum( E, V) )12 forall( istype & | istream( istype ), E | CfaEnum( E ) ) 13 13 istype & ?|?( istype & is, E & e ) { 14 14 // printf( "here0\n" ); … … 70 70 } 71 71 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 79 forall( ostype & | ostream( ostype ), E | CfaEnum( E ) ) { 73 80 ostype & ?|?( ostype & os, E e ) { 74 81 return os | label( e ); … … 77 84 } 78 85 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 15 15 }; 16 16 17 // Design one 18 forall( E, V | Serial( E ) ) trait CfaEnum { 17 forall( E | Serial( E ) ) trait CfaEnum { 19 18 const char * label( E e ); 20 19 unsigned int posn( E e ); 20 }; 21 22 forall( E, V | CfaEnum( E ) ) trait TypedEnum { 21 23 V value( E e ); 22 24 }; … … 24 26 // I/O 25 27 26 forall( istype & | istream( istype ), E , V | CfaEnum( E, V) )28 forall( istype & | istream( istype ), E | CfaEnum( E ) ) 27 29 istype & ?|?( istype &, E & ); 28 30 29 forall( ostype & | ostream( ostype ), E , V | CfaEnum( E, V) ) {31 forall( ostype & | ostream( ostype ), E | CfaEnum( E ) ) { 30 32 ostype & ?|?( ostype &, E ); 31 33 OSTYPE_VOID( E ); 32 34 } 33 35 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 // } 38 40 39 41 // Design two <- should go for this if we have change the cost model … … 48 50 49 51 static inline 50 forall( E , V | CfaEnum( E, V) ) {52 forall( E | CfaEnum( E ) ) { 51 53 int ?==?( E l, E r ) { return posn( l ) == posn( r ); } // relational operators 52 54 int ?!=?( E l, E r ) { return posn( l ) != posn( r ); } -
src/Validate/ImplementEnumFunc.cpp
r9d5eacb r236f133 25 25 : decl(decl), 26 26 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)), 30 30 proto_linkage{ast::Linkage::Cforall} {} 31 31 … … 208 208 209 209 ast::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()); 221 211 return genProto( 222 212 "value", 223 213 {new ast::ObjectDecl(getLocation(), "_i", new ast::EnumInstType(decl))}, 224 214 {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 // } 227 227 228 228 ast::FunctionDecl* EnumAttrFuncGenerator::genFromIntProto() const { … … 390 390 } 391 391 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 // } 404 404 405 405 void EnumAttrFuncGenerator::genPosnBody(ast::FunctionDecl* func) const { … … 433 433 genValueOrLabelBody(funcProto, arrayProto); 434 434 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 // } 441 442 } else if (attr == ast::EnumAttribute::Label) { 442 443 std::vector<ast::ptr<ast::Init>> inits = genLabelInit(); -
tests/enum_tests/voidEnum.cfa
r9d5eacb r236f133 1 1 #include <fstream.hfa> 2 2 #include <enum.hfa> 3 enum() voidEnum {4 a, b, c5 /***6 * ,d = 10 // Disable;7 * //error: Enumerator of enum(void) cannot have an explicit initial value.8 */9 };10 3 11 char* a[voidEnum] = { 12 "A", 13 "B", 14 "C" 15 }; 16 4 enum() E { A, B, C }; 17 5 int 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 ); 32 8 }
Note: See TracChangeset
for help on using the changeset viewer.