Changeset 5eb3f65
- Timestamp:
- Jun 24, 2024, 11:06:35 PM (4 months ago)
- Branches:
- master
- Children:
- 089b39e1, 6803ff1
- Parents:
- 253d0b4
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/enum.cfa
r253d0b4 r5eb3f65 6 6 forall(ostype & | basic_ostream(ostype), E, V| CfaEnum(E, V)) 7 7 ostype & ?|?(ostype& os, E e) { 8 return os | type_name(e) | "." | label E(e);8 return os | type_name(e) | "." | label(e); 9 9 } 10 10 11 11 forall(ostype & | basic_ostream(ostype), E| CfaEnum(E, quasi_void)) 12 12 ostype & ?|?(ostype& os, E e) { 13 return os | type_name(e) | "." | label E(e);13 return os | type_name(e) | "." | label(e); 14 14 } 15 15 16 16 forall(ostype & | basic_ostream(ostype), E, V| CfaEnum(E, V)) { 17 int ?==?(E l, E r) { return pos E(l) == posE(r); }18 int ?<=?(E l, E r) { return pos E(l) <= posE(r); }19 int ?>=?(E l, E r) { return pos E(l) >= posE(r); }20 int ?<?(E l, E r) { return pos E(l) < posE(r); }21 int ?>?(E l, E r) { return pos E(l) > posE(r); }17 int ?==?(E l, E r) { return posn(l) == posn(r); } 18 int ?<=?(E l, E r) { return posn(l) <= posn(r); } 19 int ?>=?(E l, E r) { return posn(l) >= posn(r); } 20 int ?<?(E l, E r) { return posn(l) < posn(r); } 21 int ?>?(E l, E r) { return posn(l) > posn(r); } 22 22 } -
libcfa/src/enum.hfa
r253d0b4 r5eb3f65 17 17 // Design one 18 18 forall(E, V | Serial(E)) trait CfaEnum { 19 char * labelE(E e);20 unsigned int pos E(E e);21 V value E(E e);22 char * type_name(E e);19 char * label(E e); 20 unsigned int posn(E e); 21 V value(E e); 22 char * type_name(E e); 23 23 }; 24 24 25 forall(ostype & | basic_ostream(ostype), E, V | CfaEnum(E, V))25 forall(ostype & | basic_ostream(ostype), E, V | CfaEnum(E, V)) 26 26 ostype & ?|?(ostype&, E); 27 27 … … 31 31 // Design two <- should go for this if we have change the cost model 32 32 // forall(E | Serial(E)) trait CfaEnum { 33 // char * labelE(E e);34 // unsigned int pos E(E e);33 // char * label(E e); 34 // unsigned int posn(E e); 35 35 // }; 36 36 37 37 // forall(E, V| CfaEnum(E)) trait TypedEnum { 38 // V value E(E e);38 // V value(E e); 39 39 // }; 40 40 -
src/ResolvExpr/CandidateFinder.cpp
r253d0b4 r5eb3f65 9 9 // Author : Aaron B. Moss 10 10 // Created On : Wed Jun 5 14:30:00 2019 11 // Last Modified By : Andrew Beach12 // Last Modified On : Wed Mar 16 11:58:00 202213 // Update Count : 311 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jun 22 08:07:26 2024 13 // Update Count : 4 14 14 // 15 15 … … 909 909 auto location = expr->location; 910 910 auto callExpr = new ast::UntypedExpr( 911 location, new ast::NameExpr( location, "value E" ), {expr}911 location, new ast::NameExpr( location, "value" ), {expr} 912 912 ); 913 913 finder.find( callExpr ); 914 914 CandidateList winners = findMinCost( finder.candidates ); 915 915 if (winners.size() != 1) { 916 SemanticError( callExpr, "Ambiguous expression in value E..." );916 SemanticError( callExpr, "Ambiguous expression in value..." ); 917 917 } 918 918 CandidateRef & choice = winners.front(); -
src/Validate/ImplementEnumFunc.cpp
r253d0b4 r5eb3f65 175 175 ast::FunctionDecl* EnumAttrFuncGenerator::genPosnProto() const { 176 176 return genProto( 177 "pos E",177 "posn", 178 178 {new ast::ObjectDecl(getLocation(), "_i", new ast::EnumInstType(decl))}, 179 179 {new ast::ObjectDecl(getLocation(), "_ret", … … 183 183 ast::FunctionDecl* EnumAttrFuncGenerator::genLabelProto() const { 184 184 return genProto( 185 "label E",185 "label", 186 186 {new ast::ObjectDecl(getLocation(), "_i", new ast::EnumInstType(decl))}, 187 187 {new ast::ObjectDecl( … … 193 193 if (decl->base) 194 194 return genProto( 195 "value E",195 "value", 196 196 {new ast::ObjectDecl(getLocation(), "_i", new ast::EnumInstType(decl))}, 197 197 {new ast::ObjectDecl(getLocation(), "_ret", … … 203 203 ast::FunctionDecl* EnumAttrFuncGenerator::genQuasiValueProto() const { 204 204 return genProto( 205 "value E",205 "value", 206 206 {new ast::ObjectDecl(getLocation(), "_i", new ast::EnumInstType(decl))}, 207 207 {new ast::ObjectDecl(getLocation(), "_ret", … … 254 254 auto param = params.front(); 255 255 ast::UntypedExpr* untyped = ast::UntypedExpr::createCall( 256 func->location, "pos E", { new ast::VariableExpr(func->location, param) });256 func->location, "posn", { new ast::VariableExpr(func->location, param) }); 257 257 func->stmts = new ast::CompoundStmt( 258 258 func->location, {new ast::ReturnStmt(func->location, untyped)} -
tests/enum_tests/enumInlineValue.cfa
r253d0b4 r5eb3f65 38 38 // Note: variable name (cat in this case) cannot be overloaded with those declared in enum, 39 39 // Probably for the same reason as const overloading problem 40 // i.e. int identity_t(enum ACD a) would not work as the value E(a) is ambigious currently40 // i.e. int identity_t(enum ACD a) would not work as the value(a) is ambigious currently 41 41 int identity_t(enum ACD cat) { 42 return value E(cat);42 return value(cat); 43 43 } 44 44 … … 47 47 // Because Inline introduce ambiguity on symbols 48 48 sout | "Symbols (enumerator) should have the same values:" |nl; 49 sout | "Symbol a: (10) " | value E(A.a) | "," | valueE(AB.a) | "," | valueE(ACD.a) | nl;50 sout | "Symbol b: (20) " | value E(B.b) | "," | valueE(AB.b) | nl;51 sout | "Symbol ab: (30) " | value E(AB.ab) | nl;52 sout | "Symbol c: (40) " | value E(C.c) | "," | valueE(CD.c) | "," | valueE(ACD.c) | nl;53 sout | "Symbol d: (50) " | value E(D.d) | "," | valueE(CD.d) | "," | valueE(ACD.d) | nl;54 sout | "Symbol cd: (60) " | value E(CD.cd) | "," | valueE(ACD.cd) | nl;55 sout | "Symbol acd: (70) " | value E(ACD.acd) | nl;49 sout | "Symbol a: (10) " | value(A.a) | "," | value(AB.a) | "," | value(ACD.a) | nl; 50 sout | "Symbol b: (20) " | value(B.b) | "," | value(AB.b) | nl; 51 sout | "Symbol ab: (30) " | value(AB.ab) | nl; 52 sout | "Symbol c: (40) " | value(C.c) | "," | value(CD.c) | "," | value(ACD.c) | nl; 53 sout | "Symbol d: (50) " | value(D.d) | "," | value(CD.d) | "," | value(ACD.d) | nl; 54 sout | "Symbol cd: (60) " | value(CD.cd) | "," | value(ACD.cd) | nl; 55 sout | "Symbol acd: (70) " | value(ACD.acd) | nl; 56 56 57 57 sout | "Casting/Upcasting:" | nl; 58 sout | "Symbol a: (10) " | value E((A)A.a) | "," | valueE((AB)A.a) | "," | valueE((ACD)A.a) | nl;59 sout | "Symbol b: (20) " | value E((B)B.b) | "," | valueE((AB)B.b) | nl;60 sout | "Symbol ab: (30) " | value E((AB)AB.ab) | nl;61 sout | "Symbol c: (40) " | value E((C)C.c) | "," | valueE((CD)C.c) | "," | valueE((ACD)C.c) | "," | valueE((CD)CD.c)| "," | valueE((ACD)CD.c) | nl;62 sout | "Symbol d: (50) " | value E((D)D.d) | "," | valueE((CD)D.d) | "," | valueE((ACD)D.d) | "," | valueE((ACD)CD.d) | nl;63 sout | "Symbol cd: (60) " | value E((CD)CD.cd) | "," | valueE((ACD)CD.cd) | nl;64 sout | "Symbol acd: (70) " | value E((ACD)ACD.acd) | nl;58 sout | "Symbol a: (10) " | value((A)A.a) | "," | value((AB)A.a) | "," | value((ACD)A.a) | nl; 59 sout | "Symbol b: (20) " | value((B)B.b) | "," | value((AB)B.b) | nl; 60 sout | "Symbol ab: (30) " | value((AB)AB.ab) | nl; 61 sout | "Symbol c: (40) " | value((C)C.c) | "," | value((CD)C.c) | "," | value((ACD)C.c) | "," | value((CD)CD.c)| "," | value((ACD)CD.c) | nl; 62 sout | "Symbol d: (50) " | value((D)D.d) | "," | value((CD)D.d) | "," | value((ACD)D.d) | "," | value((ACD)CD.d) | nl; 63 sout | "Symbol cd: (60) " | value((CD)CD.cd) | "," | value((ACD)CD.cd) | nl; 64 sout | "Symbol acd: (70) " | value((ACD)ACD.acd) | nl; 65 65 66 66 sout | "Function Call:" | nl; -
tests/enum_tests/position.cfa
r253d0b4 r5eb3f65 17 17 Colour c2 = fishy; 18 18 19 sout | "Compile Time: blue value: " | value E(Colour.Blue) | ", position: " | posE(Colour.Blue) | ", label: " | labelE(Colour.Blue) | ", default return value: " | Colour.Blue;20 sout | "Runtime: fishy value: " | value E(fishy) | ", position: " | posE(fishy) | ", label: " | labelE(fishy) | ", default return value: " | fishy;21 sout | "Runtime: C2 value: " | value E(c2) | ", position: " | posE(c2) | ", label: " | labelE(c2) | ", default return value: " | c2;19 sout | "Compile Time: blue value: " | value(Colour.Blue) | ", position: " | posn(Colour.Blue) | ", label: " | label(Colour.Blue) | ", default return value: " | Colour.Blue; 20 sout | "Runtime: fishy value: " | value(fishy) | ", position: " | posn(fishy) | ", label: " | label(fishy) | ", default return value: " | fishy; 21 sout | "Runtime: C2 value: " | value(c2) | ", position: " | posn(c2) | ", label: " | label(c2) | ", default return value: " | c2; 22 22 Colour.Red; 23 23 char * ao = Colour.Red; -
tests/enum_tests/voidEnum.cfa
r253d0b4 r5eb3f65 28 28 sout | b; 29 29 30 sout | labelE(v_1); 31 sout | labelE(v_2); 32 30 sout | label(v_1); 31 sout | label(v_2); 33 32 }
Note: See TracChangeset
for help on using the changeset viewer.