Changeset c4aca65 for doc/theses
- Timestamp:
- Aug 8, 2024, 5:25:41 PM (4 months ago)
- Branches:
- master
- Children:
- 11cced6
- Parents:
- ab11ab1
- Location:
- doc/theses/jiada_liang_MMath
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/Cenum.tex
rab11ab1 rc4aca65 1 1 \chapter{C Enumeration in \texorpdfstring{\CFA}{Cforall}} 2 2 3 \CFA supports legacy C enumeration using the same syntax for backward scompatibility.3 \CFA supports legacy C enumeration using the same syntax for backward compatibility. 4 4 A C-style enumeration in \CFA is called a \newterm{C Enum}. 5 5 The semantics of the C Enum is mostly consistent with C with some restrictions. … … 15 15 enum E2 { @Fourth@, @Third@, @Second@, @First@ }; $\C{// same enumerator names}$ 16 16 \end{cfa} 17 There is no mechanism in C to resolve these naming conflicts other than renaming one of the duplicates, which may be impossible if the conflict comes from system 17 There is no mechanism in C to resolve these naming conflicts other than renaming one of the duplicates, which may be impossible if the conflict comes from system-include files. 18 18 19 19 The \CFA type-system allows extensive overloading, including enumerators. 20 20 Hence, most ambiguities among C enumerators are implicitly resolved by the \CFA type system, possibly without any programmer knowledge of the conflict. 21 In addition, C Enum qualification is added, exactly like aggregate field -qualification, to disambiguate.21 In addition, C Enum qualification is added, exactly like aggregate field qualification, to disambiguate. 22 22 \VRef[Figure]{f:EnumeratorVisibility} shows how resolution, qualification, and casting are used to disambiguate situations for enumerations @E1@ and @E2@. 23 23 … … 66 66 As in Section~\ref{s:CVisibility}, opening multiple scoped enumerations in a @with@ can result in duplicate enumeration names, but \CFA implicit type resolution and explicit qualification/casting handle this localized scenario. 67 67 68 A partially implemented extension to enumerator scoping is providing a combination of scoped and unscoped enumerators, using individual denotations, where @'^'@ means unscoped.69 \begin{cfa}70 enum E1 { @!@A, @^@B, C };71 enum E2 @!@ { @!@A, @^@B, C };72 \end{cfa}73 For @E1@, @A@ is scoped; @B@ and @C@ are unscoped.74 For @E2@, @A@ and @C@ are scoped; @B@ is unscoped.75 Finding a use case is important to justify completing this extension.76 77 68 78 69 \section{Type Safety} … … 80 71 As in Section~\ref{s:Usage}, C's implicit bidirectional conversion between enumeration and integral type raises a safety concern. 81 72 In \CFA, the conversion is changed to unidirectional: an enumeration can be implicitly converted into an integral type, with an associated @safe@ conversion cost. 82 Butan integral type cannot be implicitly converted into a C enumeration because the conversion cost is set to @infinity@.73 However, an integral type cannot be implicitly converted into a C enumeration because the conversion cost is set to @infinity@. 83 74 \begin{cfa} 84 75 enum Bird { Penguin, Robin, Eagle }; -
doc/theses/jiada_liang_MMath/conclusion.tex
rab11ab1 rc4aca65 2 2 \label{c:conclusion} 3 3 4 The goal of this work is 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 backwardscompatibility with C.4 The goal of this work is 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 5 Within this goal, the new \CFA enumeration should align with the analogous enumeration features in other languages to match modern programming expectations. 6 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 7 8 Additional safety is provided by strong type-checking of enumeration initialization and assignment, ensuring an enumeration only contains its enumerators.8 Strong type-checking of enumeration initialization and assignment provides additional safety, ensuring an enumeration only contains its enumerators. 9 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 10 Typed enumerations solve the data-harmonization problem increasing safety through better software engineering. 11 As well, 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.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 12 Generalization and reuse are supported by incorporating the new enumeration type using the \CFA trait system. 13 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 an enumeration. 14 14 Using advanced duck typing, existing 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, I expanded the \CFA project's test -suite 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 accident ly break the new enumeration system.15 Finally, I expanded the \CFA project's test suite 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 17 18 The conclusion is that the new \CFA enumeration mechanisms achieve sthe initial goals, providing C programmers with an intuitive enumeration mechanism for handling modern programming requirements.18 The conclusion is that the new \CFA enumeration mechanisms achieve the initial goals, providing C programmers with an intuitive enumeration mechanism for handling modern programming requirements. 19 19 20 20 … … 22 22 23 23 There are still corner cases being found in the current \CFA enumeration implementation. 24 Fixing some of these corner cases ,requires changes to the \CFA resolver or extensions to \CFA, like compile-time constant-expression evaluation.24 Fixing some of these corner cases requires changes to the \CFA resolver or extensions to \CFA, like compile-time constant-expression evaluation. 25 25 When these changes are made, it should be straightforward to update the \CFA enumeration implementation to work with them. 26 26 27 Currently, some aspects of the enumeration trait system require explicitly including file @enum.hfa@, which easily leadsto problems.27 Currently, some aspects of the enumeration trait system require explicitly including the file @enum.hfa@, which can lead to problems. 28 28 It should be possible to have this file included implicitly by updating the \CFA prelude. 29 29 … … 42 42 enum( wchar_t * ) { Jack = L"John" }; 43 43 \end{cfa} 44 The enumerating feature was developed in parallel with the \CFA iterator. In the forseeable future when iterator come to matuity, \CFA enumeration can adapt iterator-related traits and 45 be rewritten with iterator. 44 There are several new features have been proposed or are developing in parallel with enumerations. 45 Two closely related features are iterator and namespace. 46 47 Enumerating features, and range loops in particular, are currently implemented as loops unique to \CFA enumeration and do not align with the 48 general iterator pattern. They can be adapted to the iterator interface when it comes to maturity. 49 50 Currently, \CFA implements a namespace feature for enumerated types only. There is recently a proposal by Andrew to 51 generalize the concept of namespace to other types. The enumeration scope will be revisited to follow the semantics 52 with other types. Also to improve the granularity of scope control, we propose the following extension: 53 \begin{cfa} 54 enum E1 { @!@A, @^@B, C }; 55 enum E2 @!@ { @!@A, @^@B, C }; 56 \end{cfa} 57 which provides a combination of scoped and unscoped enumerators. 58 For @E1@, @A@ is scoped; @B@ and @C@ are unscoped. 59 For @E2@, @A@, and @C@ are scoped; @B@ is unscoped. 60 Finding a use case is important to justify completing this extension.
Note: See TracChangeset
for help on using the changeset viewer.