Changeset 1697c40 for doc/theses/jiada_liang_MMath/CFAenum.tex
- Timestamp:
- Aug 4, 2024, 11:47:20 AM (42 hours ago)
- Branches:
- master
- Children:
- 065de93
- Parents:
- b797fe36
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/CFAenum.tex
rb797fe36 r1697c40 202 202 203 203 \CFA Plan-9 inheritance may be used with \CFA enumerations, where Plan-9 inheritance is containment inheritance with implicit unscoping (like a nested unnamed @struct@/@union@ in C). 204 Containment is norminative: an enumeration inherits all enumerators from another enumeration by declaring an @inline statement@ in its enumerator lists. 205 \begin{cfa} 206 enum( char * ) Names { /* as above */ }; 207 enum( char * ) Names2 { @inline Names@, Jack = "JACK", Jill = "JILL" }; 208 enum( char * ) Names3 { @inline Names2@, Sue = "SUE", Tom = "TOM" }; 209 \end{cfa} 210 In the preceding example, @Names2@ is defined with five enumerators, three of which are from @Name@ through containment, and two are self-declared. 211 @Names3@ inherits all five members from @Names2@ and declare two additional enumerators. 212 213 Enumeration inheritance forms a subset relationship. Specifically, the inheritance relationship for the example above is: 214 \begin{cfa} 215 Names $\(\subset\)$ Names2 $\(\subset\)$ Names3 $\C{// enum type of Names}$ 216 \end{cfa} 217 204 218 Inheritance can be nested, and a \CFA enumeration can inline enumerators from more than one \CFA enumeration, forming a tree-like hierarchy. 205 219 However, the uniqueness of enumeration name applies to enumerators, including those from supertypes, meaning an enumeration cannot name enumerator with the same label as its subtype's members, or inherits … … 207 221 common supertype (the diamond problem), since such would unavoidably introduce duplicate enumerator labels. 208 222 209 \begin{cfa}210 enum( char * ) Names { /* as above */ };211 enum( char * ) Names2 { @inline Names@, Jack = "JACK", Jill = "JILL" };212 enum( char * ) Names3 { @inline Names2@, Sue = "SUE", Tom = "TOM" };213 \end{cfa}214 223 215 224 % Enumeration @Name2@ inherits all the enumerators and their values from enumeration @Names@ by containment, and a @Names@ enumeration is a @subtype@ of enumeration @Name2@. 216 225 % Note, that enumerators must be unique in inheritance but enumerator values may be repeated. 217 226 218 @Names2@ is defined with five enumerators, three of which are from @Name@ through containment, and two are self-declared. 219 @Names3@ inherits all five members from @Names2@ and declare two additional enumerators. 227 220 228 221 229 % The enumeration type for the inheriting type must be the same as the inherited type; 222 230 % hence the enumeration type may be omitted for the inheriting enumeration and it is inferred from the inherited enumeration, as for @Name3@. 223 231 % When inheriting from integral types, automatic numbering may be used, so the inheritance placement left to right is important. 224 Specifically, the inheritance relationship for @Names@ is: 225 \begin{cfa} 226 Names $\(\subset\)$ Names2 $\(\subset\)$ Names3 $\C{// enum type of Names}$ 227 \end{cfa} 232 228 233 229 234 % The enumeration base for the subtype must be the same as the super type.
Note: See TracChangeset
for help on using the changeset viewer.