Changes in / [7329b0a:3da5885]


Ignore:
Location:
doc
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • doc/proposals/enum.tex

    r7329b0a r3da5885  
    77\usepackage{graphics}
    88\usepackage{xspace}
     9\usepackage{relsize}                                                                    % must be after change to small or selects old size
    910\usepackage{calc}                                                                               % latex arithmetic
    1011
     
    6465\newcommand{\CCIcon}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}} % C++ icon
    6566\newcommand{\CC}[1][]{\protect\CCIcon{#1}\xspace}               % C++ symbolic name
     67\newcommand{\Csharp}{C\raisebox{-0.7ex}{\relsize{2}$^\sharp$}\xspace} % C# symbolic name
    6668\newcommand{\PAB}[1]{{\color{red}PAB: #1}}
    6769
     
    110112\begin{abstract}
    111113An enumeration is a type defining an ordered set of named constant values, where a name abstracts a value, e.g., @PI@ versus @3.145159@.
    112 C and \CC restrict an enumeration type to the integral type @signed int@, meaning enumeration names bind to integer constants.
     114C restrict an enumeration type to the integral type @signed int@, which \CC support , meaning enumeration names bind to integer constants.
    113115\CFA extends C enumerations to allow all basic and custom types for the enumeration type, like other modern programming languages.
    114116Furthermore, \CFA adds other useful features for enumerations to support better software-engineering practices and simplify program development.
     
    132134The C-Style enumeration has the following syntax and semantics.
    133135\begin{lstlisting}[label=lst:weekday]
    134 enum Weekday { Monday, Tuesday, Wednesday, Thursday@=10@, Friday, Saturday, Sunday };
    135                 $\(\uparrow\)$                                                                      $\(\uparrow\)$
    136     ${\rm \newterm{enumeration name}}$                                        ${\rm \newterm{enumerator names}}
     136enum Weekday { Monday, Tuesday, Wednesday, Thursday@ = 10@, Friday, Saturday, Sunday };
     137                $\(\uparrow\)$                                                                        $\(\uparrow\)$
     138    ${\rm \newterm{enumeration name}}$                                          ${\rm \newterm{enumerator names}}
    137139\end{lstlisting}
    138140Here, the enumeration type @Weekday@ defines the ordered \newterm{enumerator}s @Monday@, @Tuesday@, @Wednesday@, @Thursday@, @Friday@, @Saturday@ and @Sunday@.
     
    190192A \CFA-enum can be scoped, meaning the enumerator constants are not projected into the enclosing scope.
    191193\begin{lstlisting}
    192 enum Colour( char * ) @!@ { ... };
     194enum Weekday @!@ { /* as above */ };
     195enum Colour( char * ) @!@ { /* as above */ };
    193196\end{lstlisting}
    194197where the @'!'@ implies the enumerators are \emph{not} projected.
     
    197200% $$<qualified\_expression> := <enum\_type>.<enumerator>$$
    198201\begin{lstlisting}
    199 Colour colour = @Colour.@Red;                   $\C{// qualification}$
     202Weekday weekday = @Weekday.Monday@;             $\C{// qualification}$
     203Colour colour = @Colour.@Red;
    200204colour = @Colour.@Blue;
    201205\end{lstlisting}
    202206
    203207\subsection{Enumeration Pseudo-functions}
    204 Pseudo-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.
     208
     209Pseudo-functions are function-like operators that do not result in any run-time computations, i.e., like @sizeof@.
     210Often 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..
    205211
    206212\subsubsection{Enumerator Attributes}
     
    212218\end{lstlisting}
    213219
    214 Enumeration 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.
     220Enumeration Greek may have more or less enumerators than Letter, but the enumerator values must be from Letter.
     221Therefore, 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.
    215222
    216223\subsubsection{\lstinline{enumerate()}}
     
    920927\section{Related Work}
    921928
     929Enumerations 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.
     930There 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
     940Because \CC is backwards compatible with C, it inherited C's enumerations, except there is no implicit conversion from an integral value to an enumeration;
     941hence, 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
     946For 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.
     947The underlying integral type can be explicitly specified:
     948\begin{lstlisting}[language=c++,{moredelim=**[is][\color{red}]{@}{@}}]
     949enum class RGB : @long@ { Red, Green, Blue };
     950enum class rgb : @char@ { Red = 'r', Green = 'g', Blue = 'b' };
     951enum 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}
    922967
    923968\end{document}
  • doc/uC++toCFA/Makefile

    r7329b0a r3da5885  
    88BibTeX = BIBINPUTS=../bibliography: && export BIBINPUTS && bibtex
    99
    10 MAKEFLAGS = --no-print-directory --silent #
     10MAKEFLAGS = --no-print-directory # --silent
    1111VPATH = ${Build} ${Figures}
    1212
  • doc/uC++toCFA/uC++toCFA.tex

    r7329b0a r3da5885  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Sun Oct 15 23:09:58 2023
    14 %% Update Count     : 5926
     13%% Last Modified On : Thu Jan 11 14:46:14 2024
     14%% Update Count     : 5942
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    428428\begin{uC++}
    429429struct S {
    430         int i = 0;
     430        int i = 0;  // cheat, implicit default constructor
    431431        int setter( int j ) { int t = i; i = j; return t; }
    432432        int getter() { return i; }
     
    434434
    435435S s;
    436 @s.@setter( 3 );  // object-oriented call
     436@s.@setter( 3 );  // object-oriented calls
    437437int k = @s.@getter();
    438438\end{uC++}
     
    442442        int i;
    443443};
    444 void ?{}( S & s ) { s.i = 0; }
     444void ?{}( S & s ) { s.i = 0; } // explicit default constructor
    445445int setter( @S & s,@ int j ) @with(s)@ { int t = i; i = j; return t; }
    446446int getter( @S & s@ ) @with(s)@ { return i; }
    447447S s;
    448 setter( @s,@ 3 );  // normal routine call
     448setter( @s,@ 3 );  // normal routine calls
    449449int k = getter( @s@ );
    450450\end{cfa}
     
    458458\begin{tabular}{l|l}
    459459\begin{uC++}
     460
    460461struct S {
    461462        int i;
    462         S( int i ) { S::i = i; cout << S::i << endl; }
    463 };
    464 @uNoCtor<S>@ s[10];
     463        S( int i ) { S::i = i; cout << "ctor " << S::i << endl; }
     464        ~S() { S::i = i; cout << "dtor " << S::i << endl; }
     465};
    465466int main() {
    466         for ( int i = 0; i < 10; i += 1 ) {
    467                 s[i].ctor( i );
    468         }
    469         for ( int i = 0; i < 10; i += 1 ) {
    470                 cout << s[i]@->@i << endl;
    471         }
    472 }
    473 \end{uC++}
    474 &
    475 \begin{cfa}
     467        enum { N = 5 };
     468        @uNoCtor<S>@ s[N];   // no constructor calls
     469        for ( int i = 0; i < N; i += 1 ) @s[i].ctor( i )@;
     470        for ( int i = 0; i < N; i += 1 ) cout << s[i]@->@i << endl;
     471}
     472\end{uC++}
     473&
     474\begin{cfa}
     475#include @<raii.hfa>@          // uninit
    476476struct S {
    477477        int i;
    478478};
    479 void ?{}( S & s, int i ) { s.i = i; sout | s.i; }
    480 S s[10] @$\color{red}@$= {}@;
     479void ?{}( S & s, int i ) { s.i = i; sout | "ctor" | s.i; }
     480void ^?{}( S & s ) { sout | "dtor" | s.i; }
    481481int main() {
    482         for ( i; 10 ) {
    483                 ?{}( s[i], i );  // call constructor
    484         }
    485         for ( i; 10 ) {
    486                 sout | s[i]@.@i; // dot not arrow
    487         }
     482        enum { N = 5 };
     483        @uninit(S)@ s[N];   // no constructor calls
     484        for ( i; N ) @s[i]{ i }@;
     485        for ( i; N ) sout | s[i]@.@i;
    488486}
    489487\end{cfa}
Note: See TracChangeset for help on using the changeset viewer.