source: doc/theses/jiada_liang_MMath/conclusion.tex @ 17fdf6f

Last change on this file since 17fdf6f was 17fdf6f, checked in by Peter A. Buhr <pabuhr@…>, 7 weeks ago

missed proofreading in conclusion

  • Property mode set to 100644
File size: 7.9 KB
Line 
1\chapter{Conclusion}
2\label{c:conclusion}
3
4This 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.
5Within this goal, the new \CFA enumeration should align with the analogous enumeration features in other languages to match modern programming expectations.
6Hence, 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
8Strong type-checking of enumeration initialization and assignment provides additional safety, ensuring an enumeration only contains its enumerators.
9Overloading 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.
10Typed enumerations solve the data-harmonization problem, increasing safety through better software engineering.
11Moreover, 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.
12Generalization and reuse are supported by incorporating the new enumeration type using the \CFA trait system.
13Enumeration 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.
14With 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.
15Finally, 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.
16These tests ensure future \CFA work does not accidentally break the new enumeration system.
17
18In 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
23The following are ideas to improve and extend the work in this thesis.
24\begin{enumerate}
25\item
26There are still corner cases being found in the current \CFA enumeration implementation.
27Fixing some of these corner cases requires changes to the \CFA resolver or extensions to \CFA. %, like compile-time constant-expression evaluation.
28When these changes are made, it should be straightforward to update the \CFA enumeration implementation to work with them.
29
30\item
31Currently, some aspects of the enumeration trait system require explicitly including the file \lstinline[deletekeywords={enum}]{enum.hfa}, which can lead to problems.
32It should be possible to have this file included implicitly by updating the \CFA prelude.
33\item
34There are multiple \CFA features being developed in parallel with enumerations.
35Two closely related features are iterator and namespace.
36Enumerations may have to be modified to dovetail with these features.
37For example, enumerating with range loops does not align with the current iterator design, so some changes will be necessary.
38
39\item
40C 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).
41Given the existence of this form, it is conceivable to extend it with types other than @int@.
42\begin{cfa}
43enum { Size = 20u, PI = 3.14159L, Jack = L"John" };
44\end{cfa}
45which matches with @const@ aliasing in other programming languages.
46Here, the type of the enumerator is the type of the initialization constant, \eg @typeof( 20u )@ for @Size@ implies @unsigned int@.
47Auto-initialization is restricted to the case where all constants are @int@, matching with C.
48As seen in \VRef{s:EnumeratorTyping}, this feature is just a shorthand for multiple typed-enumeration declarations.
49\begin{cfa}
50enum( unsigned int ) { Size = 20u };
51enum( long double ) { PI = 3.14159L };
52enum( wchar_t * ) { Jack = L"John" };
53\end{cfa}
54
55\item
56Currently, enumeration scoping is all or nothing. In some cases, it might be useful to
57increase the scoping granularity to individual enumerators.
58\begin{cfa}
59enum E1 { @!@A, @^@B, C };
60enum E2 @!@ { @!@A, @^@B, C };
61\end{cfa}
62Here, @'!'@ means the enumerator is scoped, and @'^'@ means the enumerator is unscoped.
63For @E1@, @A@ is scoped; @B@ and @C@ are unscoped.
64For @E2@, @A@, and @C@ are scoped; @B@ is unscoped.
65Finding a use case is important to justify this extension.
66
67\item
68An extension mentioned in \VRef{s:Ada} is using @typedef@ to create an enumerator alias.
69\begin{cfa}
70enum( int ) RGB { @Red@, @Green@, Blue };
71enum( int ) Traffic_Light { @Red@, Yellow, @Green@ };
72typedef RGB.Red OtherRed; // alias
73\end{cfa}
74
75\item
76Label and values arrays are auxiliary data structures that are always generated for \CFA enumeration, which is a program overhead when unused.
77It might be possible to provide a new syntax or annotation for a \CFA enumeration definition indicating these arrays are not used.
78Therefore, \CFA does not generated them.
79@label@ can still be used on an enumeration constant, as the call reduces to a @char *@ constant expression that holds the name of the enumerator.
80But calls on an enumeration variable, generate a compile-time error.
81The best alternative is for the linker to discard these arrays if unused.
82
83\item
84The \CFA enumeration has limitations with separate compilation.
85Consider the following:
86\begin{cquote}
87\setlength{\tabcolsep}{20pt}
88\begin{tabular}{@{}ll@{}}
89\begin{cfa}
90enum C_Codec {
91        FIRST_VIDEO = 0,
92        VP8 = 0,
93        VP9,
94        LAST_VIDEO,
95
96        FIRST_AUDIO = 64,
97        VORBIS = 64,
98        OPUS,
99        LAST_AUDIO
100};
101\end{cfa}
102&
103\begin{cfa}
104enum( int ) CFA_Codec {
105        FIRST_VIDEO = 0,
106        VP8 = 0,
107        VP9,
108        LAST_VIDEO,
109
110        FIRST_AUDIO = 64,
111        VORBIS = 64,
112        OPUS,
113        LAST_AUDIO
114};
115\end{cfa}
116\\
117\begin{cfa}
118C_Codec c_code = OPUS;
119CFA_Codec cfa_code = OPUS;
120\end{cfa}
121\end{tabular}
122\end{cquote}
123@c_code@ has value 65, the integral value of @c_code.OPUS@, while @cfa_code@ has value 6, the position of @CFA_Codec.OPUS@.
124
125If the enumerator @AV1@ is inserted in @C_Codec@ and @CFA_Codec@,
126\begin{cquote}
127\setlength{\tabcolsep}{20pt}
128\begin{tabular}{@{}ll@{}}
129\begin{cfa}
130enum C_Codec {
131        FIRST_VIDEO = 0,
132        VP8 = 0,
133        VP9,
134        @AV1@,
135        LAST_VIDEO,
136
137        FIRST_AUDIO = 64,
138        VORBIS = 64,
139        OPUS,
140        LAST_AUDIO
141};
142\end{cfa}
143&
144\begin{cfa}
145enum( int ) CFA_Codec {
146        FIRST_VIDEO = 0,
147        VP8 = 0,
148        VP9,
149        @AV1@,
150        LAST_VIDEO,
151
152        FIRST_AUDIO = 64,
153        VORBIS = 64,
154        OPUS,
155        LAST_AUDIO
156};
157\end{cfa}
158\end{tabular}
159\end{cquote}
160the assignments still result in @c_code@ with value 65, but @cfa_code@ is now 7.
161For \CFA, if all translation units including @CFA_Codec@ are not recompiled, some could assign the old 6 and some the new 7, while partially compiled C translation units all continue to assign 65.
162
163For \CFA to achieve the same behaviour for positions as C does with value for partial recompilation, enumeration positions could be represented as @const@ declarations with corresponding @extern@ declarations in the include file.
164\begin{cquote}
165\setlength{\tabcolsep}{20pt}
166\begin{tabular}{@{}ll@{}}
167\begin{cfa}
168const int FIRST_VIDEO_posn = 0;
169const int VP8_posn = 1;
170const int VP9_posn = 2;
171
172const int LAST_VIDEO_posn = 3;
173const int FIRST_AUDIO_posn = 4;
174const int VORBIS_posn = 5;
175const int OPUS_posn = 6;
176const int LAST_AUDIO_posn = 7;
177\end{cfa}
178&\begin{cfa}
179const int FIRST_VIDEO_posn = 0;
180const int VP8_posn = 1;
181const int VP9_posn = 2;
182const int AV1_posn = 3;
183const int LAST_VIDEO_posn = 4;
184const int FIRST_AUDIO_posn = 5;
185const int VORBIS_posn = 6;
186const int OPUS_posn = 7;
187const int LAST_AUDIO_posn = 8;
188\end{cfa}
189\end{tabular}
190\end{cquote}
191Then the linker always uses the most recent object file with the up-to-date positions.
192However, this implementation means the equivalent of a position array is generated using more storage.
193\end{enumerate}
Note: See TracBrowser for help on using the repository browser.