source: tests/enum_tests/test_enum.cfa @ 115ac1ce

Last change on this file since 115ac1ce was 7ee5d6d, checked in by JiadaL <j82liang@…>, 3 years ago

Add the test_enum.cfa authored by Peter. Many features are not yet supported

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[7ee5d6d]1// Only Limited features are supported currently
2
3enum Days;
4enum Days { Mon, Tues, Wed, Num };                                              // int type, integral type => auto number
5Days x0;
6enum Days x1;
7enum( char ) { A = 'A', B, C, D };                                              // char type, integral type => auto number
8enum( double ) { F = 3.5, G = 7.7 };                                    // double type, non-integral type => programmer must assign ALL enums
9enum( double ) X { R = 3.5, QQ = 7.7 };                                 // double type, non-integral type => programmer must assign ALL enums
10enum( char * ) names { X = "X", Y = "Y" };                              // char * type, non-integral type => programmer must assign ALL enums
11enum( int ) { Q, W, E };                                                                // int type, integral type => auto number
12
13int w;
14enum( int * ) addr { W = &w };                                                  // int * type, non-integral type => programmer must assign ALL enums
15enum( * int ) addr2 { WW = &w };                                                // int * type, non-integral type => programmer must assign ALL enums
16
17/*
18void f() {}
19void g() {}
20enum( void (*)() ) { FF = f, FG = g };                                  // void (*)() type, non-integral type => programmer must assign ALL enums
21enum( void (*)() ) funs { FF = f, FG = g };                             // void (*)() type, non-integral type => programmer must assign ALL enums
22enum( * [void] () ) { FF1 = f, FG1 = g };                               // void (*)() type, non-integral type => programmer must assign ALL enums
23enum( * [void] () ) funs1 { FF1 = f, FG1 = g };                 // void (*)() type, non-integral type => programmer must assign ALL enums
24
25enum( [int, int] ) { XXX = [1,2] };
26enum( [int, int] ) na { XXX = [1,2] };
27
28enum fred;
29struct S {};
30
31enum S { UX = { { 3 }, 4 }, UY = { { 7 }, 8 } };
32enum( struct S ) mary { MX };
33enum mary { MX };
34enum( struct S * ) mary { MX = { { 3 }, 4 }, MY = { { 7 }, 8 } };
35enum( S * ) mary { MX = { { 3 }, 4 }, MY = { { 7 }, 8 } };
36enum( * S ) mary { MX = { { 3 }, 4 }, MY = { { 7 }, 8 } };
37enum( enum fred ) mary { C };
38
39struct HH {
40        enum hh { h };
41};
42//enum HH.hh h;
43
44// Fred is a subset of char *
45enum( char * ) Fred { A = "A", B = "B", C = "C" };
46
47// Jack is a subset of Fred
48// these are same
49enum( enum Fred ) Jack { W = A, Y = C};
50enum( enum Fred ) Jack { W, Y = C};
51enum( Fred ) Jack { W, Y = C}; // desirable, but hard to parse
52
53// Mack is a subset of char *
54// these are same
55enum( char * ) Mack { W1 = A, Y1 = "whee" };
56
57// Mary is a SUPERSET of Fred
58// these are same
59enum Mary { inline Fred, D  = "hello" };
60enum( char * ) Mary { inline Fred, D  = "hello" };
61
62enum( char * ) Charlie { G = "G", H = "H" };
63enum Jane { inline Fred, inline Charlie, K = "K" };
64enum( char * ) Jane { inline Fred, inline Charlie, K = "K" };
65
66typedef long int size_t;
67enum( size_t ) Lisa { L1, L2, L3};
68
69// bad: Fred is char*; Lisa is size_t
70enum Jane { inline Fred, inline Lisa, M = "M" };
71enum( char * ) Jane { inline Fred, inline Lisa, M = "M" };
72
73enum( char ) Steve { steveA = 'A' };
74enum Don1 { inline Steve, daveB = (char) 2 }; // ok
75enum Don2 { inline Steve, daveB = 2 }; // typeof( readLine() ? steveA : 2 )
76
77// desirable, may cause constexpr problems
78enum( struct vec3f ) Axis { Up @= {1,0,0}, Left @= {0,1,1}, Front @= {0,1,0} };
79*/
80
81// enum struct S.T jane { JX = { 3 } };
82// enum S.T jane2 { JX = { 3 } };
83
84// enum Fred { A, B, C };
85// enum enum Fred Mary { D, E, F };             // enumeration inheritance, auto number starting at C + 1
86// enum enum Fred Mary { D, E, F };             // enumeration inheritance, auto number starting at C + 1
87// Fred f = A;
88// //Mary m1 = A, m2 = D;
89// #if 0
90// #endif // 0
91
92// enum Fred Jane { D = C, E = B, F = A }       // alternate reverse names
93// Jane j1 = A, J2 = F; // both value 0
94
95// struct Color {                               // C++ scoped enumerations
96//     enum { red, green = 20, blue };
97// };
98// //Color color = Color.red;
99
100// Local Variables: //
101// tab-width: 4 //
102// compile-command: "~/software/mary/cfa-cc/driver/cfa -XCFA -P -XCFA parse -XCFA -n test_enum.cfa" //
103// End: //
Note: See TracBrowser for help on using the repository browser.