1 | \chapter{Conclusion} |
---|
2 | \label{c:conclusion} |
---|
3 | |
---|
4 | This work aims to extend the simple and unsafe enumeration type in the C programming language into a complex and safe enumeration type in the \CFA programming language while maintaining backward compatibility with C. |
---|
5 | Within this goal, the new \CFA enumeration should align with the analogous enumeration features in other languages to match modern programming expectations. |
---|
6 | Hence, the \CFA enumeration features are borrowed from a number of programming languages, but engineered to work and play with \CFA's type system and feature set. |
---|
7 | |
---|
8 | Strong type-checking of enumeration initialization and assignment provides additional safety, ensuring an enumeration only contains its enumerators. |
---|
9 | Overloading and scoping of enumerators significantly reduces the naming problem, providing a better software-engineering environment, with fewer name clashes and the ability to disambiguate those that cannot be implicitly resolved. |
---|
10 | Typed enumerations solve the data-harmonization problem, increasing safety through better software engineering. |
---|
11 | Moreover, integrating enumerations with existing control structures provides a consistent upgrade for programmers and a succinct and secure mechanism to enumerate with the new loop-range feature. |
---|
12 | Generalization and reuse are supported by incorporating the new enumeration type using the \CFA trait system. |
---|
13 | Enumeration traits define the meaning of an enumeration, allowing functions to be written that work on any enumeration, such as the reading and printing of an enumeration. |
---|
14 | With advanced structural typing, C enumerations can be extended so they work with all of the enumeration features, providing for legacy C code to be moved forward into the modern \CFA programming domain. |
---|
15 | Finally, the \CFA project's test suite has been expanded with multiple enumeration features tests with respect to implicit conversions, control structures, inheritance, interaction with the polymorphic types, and the features built on top of enumeration traits. |
---|
16 | These tests ensure future \CFA work does not accidentally break the new enumeration system. |
---|
17 | |
---|
18 | In summary, the new \CFA enumeration mechanisms achieve the initial goals, providing C programmers with an intuitive enumeration mechanism for handling modern programming requirements. |
---|
19 | |
---|
20 | |
---|
21 | \section{Future Work} |
---|
22 | |
---|
23 | The following are ideas to improve and extend the work in this thesis. |
---|
24 | \begin{enumerate} |
---|
25 | \item |
---|
26 | There are still corner cases being found in the current \CFA enumeration implementation. |
---|
27 | Fixing some of these corner cases requires changes to the \CFA resolver or extensions to \CFA. %, like compile-time constant-expression evaluation. |
---|
28 | When these changes are made, it should be straightforward to update the \CFA enumeration implementation to work with them. |
---|
29 | \item |
---|
30 | Currently, some aspects of the enumeration trait system require explicitly including the file @enum.hfa@, which can lead to problems. |
---|
31 | It should be possible to have this file included implicitly by updating the \CFA prelude. |
---|
32 | \item |
---|
33 | There are multiple \CFA features being developed in parallel with enumerations. |
---|
34 | Two closely related features are iterator and namespace. |
---|
35 | Enumerations may have to be modified to dovetail with these features. |
---|
36 | For example, enumerating with range loops does not align with the current iterator design, so some changes will be necessary. |
---|
37 | \item |
---|
38 | C already provides @const@-style aliasing using the \emph{unnamed} enumerator \see{\VRef{s:TypeName}}, even if the name @enum@ is misleading (@const@ would be better). |
---|
39 | Given the existence of this form, it is conceivable to extend it with types other than @int@. |
---|
40 | \begin{cfa} |
---|
41 | enum { Size = 20u, PI = 3.14159L, Jack = L"John" }; |
---|
42 | \end{cfa} |
---|
43 | which matches with @const@ aliasing in other programming languages. |
---|
44 | Here, the type of the enumerator is the type of the initialization constant, \eg @typeof( 20u )@ for @Size@ implies @unsigned int@. |
---|
45 | Auto-initialization is restricted to the case where all constants are @int@, matching with C. |
---|
46 | As seen in \VRef{s:EnumeratorTyping}, this feature is just a shorthand for multiple typed-enumeration declarations. |
---|
47 | \begin{cfa} |
---|
48 | enum( unsigned int ) { Size = 20u }; |
---|
49 | enum( long double ) { PI = 3.14159L }; |
---|
50 | enum( wchar_t * ) { Jack = L"John" }; |
---|
51 | \end{cfa} |
---|
52 | \item |
---|
53 | Currently, enumeration scoping is all or nothing. In some cases, it might be useful to |
---|
54 | increase the scoping granularity to individual enumerators. |
---|
55 | \begin{cfa} |
---|
56 | enum E1 { @!@A, @^@B, C }; |
---|
57 | enum E2 @!@ { @!@A, @^@B, C }; |
---|
58 | \end{cfa} |
---|
59 | Here, @'!'@ means the enumerator is scoped, and @'^'@ means the enumerator is unscoped. |
---|
60 | For @E1@, @A@ is scoped; @B@ and @C@ are unscoped. |
---|
61 | For @E2@, @A@, and @C@ are scoped; @B@ is unscoped. |
---|
62 | Finding a use case is important to justify this extension. |
---|
63 | \item |
---|
64 | An extension mentioned in \VRef{s:Ada} is using @typedef@ to create an enumerator alias. |
---|
65 | \begin{cfa} |
---|
66 | enum(int) RGB { @Red@, @Green@, Blue }; |
---|
67 | enum(int) Traffic_Light { @Red@, Yellow, @Green@ }; |
---|
68 | typedef RGB.Red OtherRed; // alias |
---|
69 | \end{cfa} |
---|
70 | \item |
---|
71 | Label arrays are auxiliary data structures that are always generated for \CFA enumeration, which is a considerable program overhead. |
---|
72 | It is helpful to provide a new syntax or annotation for a \CFA enumeration definition that tells the compiler the labels will not be used |
---|
73 | throughout the execution. Therefore, \CFA optimizes the label array away. The @value()@ function can still be used on an enumeration constant, |
---|
74 | and the function called is reduced to a @char *@ constant expression that holds the name of the enumerator. But if @value()@ is called on |
---|
75 | a variable with an enumerated type, it returns an empty string since the label information is lost for the runtime. |
---|
76 | \end{enumerate} |
---|