Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/proposals/enum.tex

    r2989d6f rdd1ebb1  
    77\usepackage{graphics}
    88\usepackage{xspace}
    9 \usepackage{relsize}                                                                    % must be after change to small or selects old size
    109\usepackage{calc}                                                                               % latex arithmetic
    1110
     
    6564\newcommand{\CCIcon}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}} % C++ icon
    6665\newcommand{\CC}[1][]{\protect\CCIcon{#1}\xspace}               % C++ symbolic name
    67 \newcommand{\Csharp}{C\raisebox{-0.7ex}{\relsize{2}$^\sharp$}\xspace} % C# symbolic name
    6866\newcommand{\PAB}[1]{{\color{red}PAB: #1}}
    6967
     
    112110\begin{abstract}
    113111An enumeration is a type defining an ordered set of named constant values, where a name abstracts a value, e.g., @PI@ versus @3.145159@.
    114 C restrict an enumeration type to the integral type @signed int@, which \CC support , meaning enumeration names bind to integer constants.
     112C and \CC restrict an enumeration type to the integral type @signed int@, meaning enumeration names bind to integer constants.
    115113\CFA extends C enumerations to allow all basic and custom types for the enumeration type, like other modern programming languages.
    116114Furthermore, \CFA adds other useful features for enumerations to support better software-engineering practices and simplify program development.
     
    134132The C-Style enumeration has the following syntax and semantics.
    135133\begin{lstlisting}[label=lst:weekday]
    136 enum Weekday { Monday, Tuesday, Wednesday, Thursday@ = 10@, Friday, Saturday, Sunday };
    137                 $\(\uparrow\)$                                                                        $\(\uparrow\)$
    138     ${\rm \newterm{enumeration name}}$                                          ${\rm \newterm{enumerator names}}
     134enum Weekday { Monday, Tuesday, Wednesday, Thursday@=10@, Friday, Saturday, Sunday };
     135                $\(\uparrow\)$                                                                      $\(\uparrow\)$
     136    ${\rm \newterm{enumeration name}}$                                        ${\rm \newterm{enumerator names}}
    139137\end{lstlisting}
    140138Here, the enumeration type @Weekday@ defines the ordered \newterm{enumerator}s @Monday@, @Tuesday@, @Wednesday@, @Thursday@, @Friday@, @Saturday@ and @Sunday@.
     
    192190A \CFA-enum can be scoped, meaning the enumerator constants are not projected into the enclosing scope.
    193191\begin{lstlisting}
    194 enum Weekday @!@ { /* as above */ };
    195 enum Colour( char * ) @!@ { /* as above */ };
     192enum Colour( char * ) @!@ { ... };
    196193\end{lstlisting}
    197194where the @'!'@ implies the enumerators are \emph{not} projected.
     
    200197% $$<qualified\_expression> := <enum\_type>.<enumerator>$$
    201198\begin{lstlisting}
    202 Weekday weekday = @Weekday.Monday@;             $\C{// qualification}$
    203 Colour colour = @Colour.@Red;
     199Colour colour = @Colour.@Red;                   $\C{// qualification}$
    204200colour = @Colour.@Blue;
    205201\end{lstlisting}
    206202
    207203\subsection{Enumeration Pseudo-functions}
    208 
    209 Pseudo-functions are function-like operators that do not result in any run-time computations, i.e., like @sizeof@.
    210 Often a call to a pseudo-function is substituted with information extracted from the symbol table at compilation time, like storage size or alignment associated with the underlying architecture..
     204Pseudo-functions are function-like operators that do not result in any run-time computations, i.e., like @sizeof@. Instead, the call to functions will be substituted into other expressions in compilation time.
    211205
    212206\subsubsection{Enumerator Attributes}
     
    218212\end{lstlisting}
    219213
    220 Enumeration Greek may have more or less enumerators than Letter, but the enumerator values must be from Letter.
    221 Therefore, Greek enumerators are a subset of type Letter and are type compatible with enumeration Letter, but Letter enumerators are not type compatible with enumeration Greek.
     214Enumeration Greek may have more or less enumerators than Letter, but the enumerator values must be from Letter. Therefore, Greek enumerators are a subset of type Letter and are type compatible with enumeration Letter, but Letter enumerators are not type compatible with enumeration Greek.
    222215
    223216\subsubsection{\lstinline{enumerate()}}
     
    927920\section{Related Work}
    928921
    929 Enumerations exist in many popular programming languages, e.g., Pascal, Ada, \Csharp, \CC, Go, Java, Modula-3, Rust, Swift, Python, and Algebraic data type in functional programming.
    930 There are a large set of overlapping features for all the languages, but each language has its own unique restrictions and extensions.
    931 
    932 \subsection{Pascal}
    933 
    934 \subsection{Ada}
    935 
    936 \subsection{\Csharp}
    937 
    938 \subsection{\CC}
    939 
    940 Because \CC is backwards compatible with C, it inherited C's enumerations, except there is no implicit conversion from an integral value to an enumeration;
    941 hence, the values in a \CC enumeration can only be its enumerators.
    942 
    943 \CC{11} extended enumeration with a scoped enumeration, \lstinline[language=c++]{enum class} (or \lstinline[language=c++]{enum struct}), where the enumerators are local to the enumeration and are accessed using type qualification, e.g., @Weekday::Monday@.
    944 \CC{20} supports unscoped access with a \lstinline[language=c++]{using enum} declaration.
    945 
    946 For both unscoped and scoped enumerations, the underlying type is an implementation-defined integral type that is large enough to hold all enumerated values; it does not have to be the smallest possible type.
    947 The underlying integral type can be explicitly specified:
    948 \begin{lstlisting}[language=c++,{moredelim=**[is][\color{red}]{@}{@}}]
    949 enum class RGB : @long@ { Red, Green, Blue };
    950 enum class rgb : @char@ { Red = 'r', Green = 'g', Blue = 'b' };
    951 enum class srgb : @signed char@ { Red = -1, Green = 0, Blue = 1 };
    952 \end{lstlisting}
    953 
    954 \subsection{Go}
    955 
    956 \subsection{Java}
    957 
    958 \subsection{Modula-3}
    959 
    960 \subsection{Rust}
    961 
    962 \subsection{Swift}
    963 
    964 \subsection{Python}
    965 
    966 \subsection{Algebraic Data Type}
    967922
    968923\end{document}
Note: See TracChangeset for help on using the changeset viewer.