source: doc/proposals/enum.tex @ baa1d5d

Last change on this file since baa1d5d was dd1ebb1, checked in by Peter A. Buhr <pabuhr@…>, 6 months ago

some updates on the enum proposal

  • Property mode set to 100644
File size: 44.6 KB
Line 
1\documentclass[12pt]{article}
2\usepackage{fullpage,times}
3\usepackage{pslatex}                    % reduce size of san serif font
4\usepackage{xcolor}
5\usepackage{listings}
6%\usepackage{array}
7\usepackage{graphics}
8\usepackage{xspace}
9\usepackage{calc}                                                                               % latex arithmetic
10
11\makeatletter
12\renewcommand\section{\@startsection{section}{1}{\z@}{-3.0ex \@plus -1ex \@minus -.2ex}{1.5ex \@plus .2ex}{\normalfont\large\bfseries}}
13\renewcommand\subsection{\@startsection{subsection}{2}{\z@}{-2.75ex \@plus -1ex \@minus -.2ex}{1.25ex \@plus .2ex}{\normalfont\normalsize\bfseries}}
14\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}{-2.5ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\normalsize\bfseries}}
15\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}{-2.0ex \@plus -1ex \@minus -.2ex}{-1em}{\normalfont\normalsize\bfseries}}
16\renewcommand\subparagraph{\@startsection{subparagraph}{4}{\z@}{-1.5ex \@plus -1ex \@minus -.2ex}{-1em}{\normalfont\normalsize\bfseries\itshape}}
17
18% Denote newterms in particular font and index them without particular font and in lowercase, e.g., \newterm{abc}.
19% The option parameter provides an index term different from the new term, e.g., \newterm[\texttt{abc}]{abc}
20% The star version does not lowercase the index information, e.g., \newterm*{IBM}.
21\newcommand{\newtermFontInline}{\emph}
22\newcommand{\newterm}{\protect\@ifstar\@snewterm\@newterm}
23\newcommand{\@newterm}[2][\@empty]{\lowercase{\def\temp{#2}}{\newtermFontInline{#2}}\ifx#1\@empty\index{\temp}\else\index{#1@{\protect#2}}\fi}
24\newcommand{\@snewterm}[2][\@empty]{{\newtermFontInline{#2}}\ifx#1\@empty\index{#2}\else\index{#1@{\protect#2}}\fi}
25
26\newcommand{\LstBasicStyle}[1]{{\lst@basicstyle{#1}}}
27\newcommand{\LstKeywordStyle}[1]{{\lst@basicstyle{\lst@keywordstyle{#1}}}}
28\newcommand{\LstCommentStyle}[1]{{\lst@basicstyle{\lst@commentstyle{#1}}}}
29\newcommand{\LstStringStyle}[1]{{\lst@basicstyle{\lst@stringstyle{#1}}}}
30\newcommand{\LstNumberStyle}[1]{{\lst@basicstyle{\lst@numberstyle{#1}}}}
31
32\newlength{\gcolumnposn}                                % temporary hack because lstlisting does not handle tabs correctly
33\newlength{\columnposn}
34\setlength{\gcolumnposn}{3in}
35\setlength{\columnposn}{\gcolumnposn}
36\newcommand{\setgcolumn}[1]{\global\gcolumnposn=#1\global\columnposn=\gcolumnposn}
37\newcommand{\C}[2][\@empty]{\ifx#1\@empty\else\global\setlength{\columnposn}{#1}\global\columnposn=\columnposn\fi\hfill\makebox[\textwidth-\columnposn][l]{\LstCommentStyle{#2}}}
38\newcommand{\CD}[2][\@empty]{\ifx#1\@empty\else\global\setlength{\columnposn}{#1}\global\columnposn=\columnposn\fi\hfill\makebox[\textwidth-\columnposn][l]{\LstBasicStyle{#2}}}
39\newcommand{\CRT}{\global\columnposn=\gcolumnposn}
40\makeatother
41
42\usepackage[ignoredisplayed]{enumitem}  % do not affect trivlist
43\setlist{labelsep=1ex}% global
44\setlist[itemize]{topsep=0.5ex,parsep=0.25ex,itemsep=0.25ex,listparindent=\parindent,leftmargin=\parindent}% global
45\setlist[itemize,1]{label=\textbullet}% local
46%\renewcommand{\labelitemi}{{\raisebox{0.25ex}{\footnotesize$\bullet$}}}
47\setlist[enumerate]{topsep=0.5ex,parsep=0.25ex,itemsep=0.25ex,listparindent=\parindent}% global
48\setlist[enumerate,2]{leftmargin=\parindent,labelsep=*,align=parleft,label=\alph*.}% local
49\setlist[description]{topsep=0.5ex,itemsep=0pt,listparindent=\parindent,leftmargin=\parindent,labelsep=1.5ex}
50
51\newenvironment{cquote}{%
52        \list{}{\lstset{resetmargins=true,aboveskip=0pt,belowskip=0pt}\topsep=4pt\parsep=0pt\leftmargin=\parindent\rightmargin\leftmargin}%
53        \item\relax
54}{%
55        \endlist
56}% cquote
57
58\setlength{\topmargin}{-0.45in}                                                 % move running title into header
59\setlength{\headsep}{0.25in}
60\setlength{\textheight}{9.0in}
61
62\newcommand{\CFAIcon}{\textsf{C\raisebox{\depth}{\rotatebox{180}A}}} % Cforall icon
63\newcommand{\CFA}{\protect\CFAIcon\xspace}                              % CFA symbolic name
64\newcommand{\CCIcon}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}} % C++ icon
65\newcommand{\CC}[1][]{\protect\CCIcon{#1}\xspace}               % C++ symbolic name
66\newcommand{\PAB}[1]{{\color{red}PAB: #1}}
67
68% \definecolor{mGreen}{rgb}{0,0.6,0}
69% \definecolor{mGray}{rgb}{0.5,0.5,0.5}
70% \definecolor{mPurple}{rgb}{0.58,0,0.82}
71% \definecolor{backgroundColour}{rgb}{0.95,0.95,0.92}
72
73\lstdefinestyle{CStyle}{
74%    backgroundcolor=\color{backgroundColour},
75%    commentstyle=\color{mGreen},
76%    keywordstyle=\color{magenta},
77        stringstyle=\small\tt,                                  % use typewriter font
78%    stringstyle=\color{mPurple},
79    columns=fullflexible,
80    basicstyle=\small\linespread{0.9}\sf,       % reduce line spacing and use sanserif font
81%   basicstyle=\footnotesize,
82    breakatwhitespace=false,
83%    breaklines=true,
84    captionpos=b,
85    keepspaces=true,
86        escapechar=\$,                                                  % LaTeX escape in CFA code
87%    numbers=left,
88%    numbersep=5pt,
89%    numberstyle=\tiny\color{mGray},
90%    showspaces=false,
91    showstringspaces=false,
92%    showtabs=false,
93        showlines=true,                                                 % show blank lines at end of code
94    tabsize=5,
95    language=C,
96        aboveskip=4pt,                                                  % spacing above/below code block
97        belowskip=2pt,
98        xleftmargin=\parindent,                 % indent code to paragraph indentation
99}
100\lstset{style=CStyle,moredelim=**[is][\color{red}]{@}{@}}
101\lstMakeShortInline@                            % single-character for \lstinline
102
103\begin{document}
104
105\title{\vspace*{-0.5in}Enumeration in \CFA}
106\author{Jiada Liang}
107
108\maketitle
109
110\begin{abstract}
111An enumeration is a type defining an ordered set of named constant values, where a name abstracts a value, e.g., @PI@ versus @3.145159@.
112C and \CC restrict an enumeration type to the integral type @signed int@, meaning enumeration names bind to integer constants.
113\CFA extends C enumerations to allow all basic and custom types for the enumeration type, like other modern programming languages.
114Furthermore, \CFA adds other useful features for enumerations to support better software-engineering practices and simplify program development.
115\end{abstract}
116
117\section{Background}
118
119Naming values is a common practice in mathematics and engineering, e.g., $\pi$, $\tau$ (2$\pi$), $\phi$ (golden ratio), MHz (1E6), etc.
120Naming is also commonly used to represent many other numerical phenomenon, such as days of the week, months of a year, floors of a building (basement), time (noon, New Years).
121Many programming languages capture this important capability through a mechanism called an \newterm{enumeration}.
122An enumeration is similar to other programming-language types by providing a set of constrained values, but adds the ability to name \emph{all} the values in its set.
123Note, all enumeration names must be unique but different names can represent the same value (eight note, quaver), which are synonyms.
124
125Specifically, an enumerated type is a type whose values are restricted to a fixed set of named constants.
126Fundamentally, all types are restricted to a fixed set of values because of the underlying von Neumann architecture, and hence, to a corresponding set of constants, e.g., @3@, @3.5@, @3.5+2.1i@, @'c'@, @"abc"@, etc.
127However, the values for basic types are not named, other than the programming-language supplied constants.
128
129
130\section{C-Style Enum}
131
132The C-Style enumeration has the following syntax and semantics.
133\begin{lstlisting}[label=lst:weekday]
134enum Weekday { Monday, Tuesday, Wednesday, Thursday@=10@, Friday, Saturday, Sunday };
135                $\(\uparrow\)$                                                                      $\(\uparrow\)$
136    ${\rm \newterm{enumeration name}}$                                        ${\rm \newterm{enumerator names}}
137\end{lstlisting}
138Here, the enumeration type @Weekday@ defines the ordered \newterm{enumerator}s @Monday@, @Tuesday@, @Wednesday@, @Thursday@, @Friday@, @Saturday@ and @Sunday@.
139The successor of @Tuesday@ is @Monday@ and the predecessor of @Tuesday@ is @Wednesday@.
140A C enumeration is implemented by an integral type, with consecutive enumerator values assigned by the compiler starting at zero or the next explicitly initialized value.
141For example, @Monday@ to @Wednesday@ have values 0--2 implicitly set by the compiler, @Thursday@ is explicitly set to @10@, and @Friday@ to @Sunday@ have values 11--13 implicitly set by the compiler.
142
143There are 3 attributes for an enumeration: \newterm{position}, \newterm{label}, and \newterm{value}:
144\begin{cquote}
145\small\sf\setlength{\tabcolsep}{3pt}
146\begin{tabular}{rccccccccccc}
147@enum@ Weekday \{       & Monday,       & Tuesday,      & Wednesday,    & Thursday=10,  & Friday,       & Saturday,     & Sunday \}; \\
148\it position            & 0                     & 1                     & 2                             & 3                             & 4                     & 5                     & 6                     \\
149\it label                       & Monday        & Tuesday       & Wednesday             & Thursday              & Friday        & Saturday      & Sunday        \\
150\it value                       & 0                     & 1                     & 2                             & {\color{red}10}& 11           & 12            & 13
151\end{tabular}
152\end{cquote}
153
154The enumerators of an enumeration are unscoped, i.e., enumerators declared inside of an @enum@ are visible in the enclosing scope of the @enum@ type.
155Furthermore, there is an implicit bidirectional conversion between an enumeration and integral types.
156\begin{lstlisting}[label=lst:enum_scope]
157{
158        enum Weekday { ... };                           $\C{// enumerators implicitly projected into local scope}$
159        Weekday weekday = Monday;
160        weekday = Friday;                                       $\C{// weekday == 11}$
161        int i = Sunday                                          $\C{// i == 13}$
162        weekday = 10000;                                        $\C{// undefined behaviour}$
163}
164int j = Wednesday;                                              $\C{// ERROR! Wednesday is not declared in this scope}$
165\end{lstlisting}
166
167\section{\CFA-Style Enum}
168
169\CFA supports C-Style enumeration using the same syntax and semantics for backwards compatibility.
170\CFA also extends C-Style enumeration by adding a number of new features that bring enumerations inline with other modern programming languages.
171
172\subsection{Enumerator Typing}
173
174\CFA extends the enumeration by parameterizing the enumeration with a type for the enumerators, allowing enumerators to be assigned any values from the declared type.
175\begin{lstlisting}[label=lst:color]
176enum( @char@ ) Currency { Dollar = '$\textdollar$', Euro = '$\texteuro$', Pound = '$\textsterling$};
177enum( @double@ ) Planet { Venus = 4.87, Earth = 5.97, Mars = 0.642  }; // mass
178enum( @char *@ ) Colour { Red = "red", Green = "green", Blue = "blue"  };
179enum( @Currency@ ) Europe { Euro = '$\texteuro$', Pound = '$\textsterling$' }; // intersection
180\end{lstlisting}
181The types of the enumerators are @char@, @double@, and @char *@ and each enumerator is initialized with corresponding type values.
182% Only types with a defined ordering can be automatically initialized (see Section~\ref{s:AutoInitializable}).
183
184% An instance of \CFA-enum (denoted as @<enum_instance>@) is a label for the defined enum name.
185% The label can be retrieved by calling the function @label( <enum_instance> )@.
186% Similarly, the @value()@ function returns the value used to initialize the \CFA-enum.
187
188\subsection{Enumerator Scoping}
189
190A \CFA-enum can be scoped, meaning the enumerator constants are not projected into the enclosing scope.
191\begin{lstlisting}
192enum Colour( char * ) @!@ { ... };
193\end{lstlisting}
194where the @'!'@ implies the enumerators are \emph{not} projected.
195The enumerators of a scoped enumeration are accessed using qualifications, like the fields of an aggregate.
196% The syntax of $qualified\_expression$ for \CFA-enum is the following:
197% $$<qualified\_expression> := <enum\_type>.<enumerator>$$
198\begin{lstlisting}
199Colour colour = @Colour.@Red;                   $\C{// qualification}$
200colour = @Colour.@Blue;
201\end{lstlisting}
202
203\subsection{Enumeration Pseudo-functions}
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.
205
206\subsubsection{Enumerator Attributes}
207The attributes of an enumerator are accessed by pseudo-functions @position@, @value@, and @label@.
208\begin{lstlisting}
209int green_pos = @position@( Colour.Green );     $\C{// 1}$
210char * green_value = @value@( Colour.Green ); $\C{// "G"}$
211char * green_label = @label@( Colour.Green ); $\C{// "Green"}$
212\end{lstlisting}
213
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.
215
216\subsubsection{\lstinline{enumerate()}}
217
218\begin{lstlisting}[label=lst:c_switch]
219enum(int) C_ENUM { First, Second, Third = First, Fourth };
220int v( C_ENUM e ) {
221        switch( e ) {
222                case First: return 0; break;
223                case Second: return 1; break;
224                // case Third: return 2; break;
225                // case Fourth: return 3; break;
226        };
227};
228\end{lstlisting}
229In the @C_ENUM@ example, @Third@ is an alias of @First@ and @Fourth@ is an alias of @Second@.
230Programmers cannot make case branches for @Third@ and @Fourth@ because the switch statement matches cases by the enumerator's value.
231Case @First@ and @Third@, or @Second@ and @Fourth@, has duplicate case values.
232
233@enumerate()@ is a pseudo-function that makes the switch statement match by an enumerator instead.
234\begin{lstlisting}[label=lst:c_switch_enumerate]
235enum(double) C_ENUM { First, Second, Third = First, Fourth };
236C_ENUM variable_a = First, variable_b = Second, variable_c = Third, variable_d = Fourth;
237int v(C_ENUM e) {
238        switch( enumeratate( e ) ) {
239                case First: return e; break;
240                case Second: return value( e ); break;
241                case Third: return label( e ); break;
242                case Fourth: return position( e ); break;
243        };
244};
245p(variable_a); // 0
246p(variable_b); // 1
247p(variable_c); // "Third"
248p(variable_d); // 3
249\end{lstlisting}
250
251
252\section{Enumeration Storage}
253
254
255\subsection{Enumeration Variable}
256
257Although \CFA enumeration captures three different attributes, an enumeration instance does not store all this information.
258The @sizeof@ a \CFA enumeration instance is always 4 bytes, the same size as a C enumeration instance (@sizeof( int )@).
259It comes from the fact that:
260\begin{enumerate}
261\item
262a \CFA enumeration is always statically typed;
263\item
264it is always resolved as one of its attributes regarding real usage.
265\end{enumerate}
266When creating an enumeration instance @colour@ and assigning it with the enumerator @Color.Green@, the compiler allocates an integer variable and stores the position 1.
267The invocations of $positions()$, $value()$, and $label()$ turn into calls to special functions defined in the prelude:
268\begin{lstlisting}[label=lst:companion_call]
269position( green );
270>>> position( Colour, 1 ) -> int
271value( green );
272>>> value( Colour, 1 ) -> T
273label( green );
274>>> label( Colour, 1) -> char *
275\end{lstlisting}
276@T@ represents the type declared in the \CFA enumeration defined and @char *@ in the example.
277These generated functions are $Companion Functions$, they take an $companion$ object and the position as parameters.
278
279
280\subsection{Enumeration Data}
281
282\begin{lstlisting}[label=lst:enumeration_backing_data]
283enum(T) E { ... };
284// backing data
285T * E_values;
286char ** E_labels;
287\end{lstlisting}
288Storing values and labels as arrays can sometimes help support enumeration features.
289However, the data structures are the overhead for the programs. We want to reduce the memory usage for enumeration support by:
290\begin{itemize}
291        \item Only generates the data array if necessary
292        \item The compilation units share the data structures.
293        No extra overhead if the data structures are requested multiple times.
294\end{itemize}
295
296
297\section{Unification}
298
299\subsection{Enumeration as Value}
300\label{section:enumeration_as_value}
301An \CFA enumeration with base type T can be used seamlessly as T, without explicitly calling the pseudo-function value.
302\begin{lstlisting}[label=lst:implicit_conversion]
303char * green_value = Colour.Green; // "G"
304// Is equivalent to
305// char * green_value = value( Color.Green ); "G"
306\end{lstlisting}
307
308
309\subsection{Unification Distance}
310
311\begin{lstlisting}[label=lst:unification_distance_example]
312T_2 Foo(T1);
313\end{lstlisting}
314The @Foo@ function expects a parameter with type @T1@. In C, only a value with the exact type T1 can be used as a parameter for @Foo@. In \CFA, @Foo@ accepts value with some type @T3@ as long as @distance(T1, T3)@ is not @Infinite@.
315
316@path(A, B)@ is a compiler concept that returns one of the following:
317\begin{itemize}
318        \item Zero or 0, if and only if $A == B$.
319        \item Safe, if B can be used as A without losing its precision, or B is a subtype of A.
320        \item Unsafe, if B loses its precision when used as A, or A is a subtype of B.
321        \item Infinite, if B cannot be used as A. A is not a subtype of B and B is not a subtype of A.
322\end{itemize}
323
324For example, @path(int, int)==Zero@, @path(int, char)==Safe@, @path(int, double)==Unsafe@, @path(int, struct S)@ is @Infinite@ for @struct S{}@.
325@distance(A, C)@ is the minimum sum of paths from A to C. For example, if @path(A, B)==i@, @path(B, C)==j@, and @path(A, C)=k@, then $$distance(A,C)==min(path(A,B), path(B,C))==i+j$$.
326
327(Skip over the distance matrix here because it is mostly irrelevant for enumeration discussion. In the actual implementation, distance( E, T ) is 1.)
328
329The arithmetic of distance is the following:
330\begin{itemize}
331        \item $Zero + v= v$, for some value v.
332        \item $Safe * k <  Unsafe$, for finite k.
333        \item $Unsafe * k < Infinite$, for finite k.
334        \item $Infinite + v = Infinite$, for some value v.
335\end{itemize}
336
337For @enum(T) E@, @path(T, E)==Safe@ and @path(E,T)==Infinite@. In other words, enumeration type E can be @safely@ used as type T, but type T cannot be used when the resolution context expects a variable with enumeration type @E@.
338
339
340\subsection{Variable Overloading and Parameter Unification}
341
342\CFA allows variable names to be overloaded. It is possible to overload a variable that has type T and an enumeration with type T.
343\begin{lstlisting}[label=lst:variable_overload]
344char * green = "Green";
345Colour green = Colour.Green; // "G"
346
347void bar(char * s) { return s; }
348void foo(Colour c) { return value( c ); }
349
350foo( green ); // "G"
351bar( green ); // "Green"
352\end{lstlisting}
353\CFA's conversion distance helps disambiguation in this overloading. For the function @bar@ which expects the parameter s to have type @char *@, $distance(char *,char *) == Zero$ while $distance(char *, Colour) == Safe$, the path from @char *@ to the enumeration with based type @char *@, \CFA chooses the @green@ with type @char *@ unambiguously. On the other hand, for the function @foo@, @distance(Colour, char *)@ is @Infinite@, @foo@ picks the @green@ with type @char *@.
354
355\subsection{Function Overloading}
356Similarly, functions can be overloaded with different signatures. \CFA picks the correct function entity based on the distance between parameter types and the arguments.
357\begin{lstlisting}[label=lst:function_overload]
358Colour green = Colour.Green;
359void foo(Colour c) { sout | "It is an enum"; } // First foo
360void foo(char * s) { sout | "It is a string"; } // Second foo
361foo( green ); // "It is an enum"
362\end{lstlisting}
363Because @distance(Colour, Colour)@ is @Zero@ and @distance(char *, Colour)@ is @Safe@, \CFA determines the @foo( green )@ is a call to the first foo.
364
365\subsection{Attributes Functions}
366The pseudo-function @value()@ "unboxes" the enumeration and the type of the expression is the underlying type. Therefore, in the section~\ref{section:enumeration_as_value} when assigning @Colour.Green@ to variable typed @char *@, the resolution distance is @Safe@, while assigning @value(Color.Green) to @char *) has resolution distance @Zero@.
367
368\begin{lstlisting}[label=lst:declaration_code]
369int s1;
370\end{lstlisting}
371The generated code for an enumeration instance is simply an int. It is to hold the position of an enumeration. And usage of variable @s1@ will be converted to return one of its attributes: label, value, or position, concerning the @Unification@ rule
372
373% \subsection{Unification and Resolution (this implementation will probably not be used, safe as reference for now)}
374
375% \begin{lstlisting}
376% enum Colour( char * ) { Red = "R", Green = "G", Blue = "B"  };
377% \end{lstlisting}
378% The @EnumInstType@ is convertible to other types.
379% A \CFA enumeration expression is implicitly \emph{overloaded} with its three different attributes: value, position, and label.
380% The \CFA compilers need to resolve an @EnumInstType@ as one of its attributes based on the current context.
381
382% \begin{lstlisting}[caption={Null Context}, label=lst:null_context]
383% {
384%       Colour.Green;
385% }
386% \end{lstlisting}
387% In example~\ref{lst:null_context}, the environment gives no information to help with the resolution of @Colour.Green@.
388% In this case, any of the attributes is resolvable.
389% According to the \textit{precedence rule}, the expression with @EnumInstType@ resolves as @value( Colour.Green )@.
390% The @EnumInstType@ is converted to the type of the value, which is statically known to the compiler as @char *@.
391% When the compilation reaches the code generation, the compiler outputs code for type @char *@ with the value @"G"@.
392% \begin{lstlisting}[caption={Null Context Generated Code}, label=lst:null_context]
393% {
394%       "G";
395% }
396% \end{lstlisting}
397% \begin{lstlisting}[caption={int Context}, label=lst:int_context]
398% {
399%       int g = Colour.Green;
400% }
401% \end{lstlisting}
402% The assignment expression gives a context for the EnumInstType resolution.
403% The EnumInstType is used as an @int@, and \CFA needs to determine which of the attributes can be resolved as an @int@ type.
404% The functions $Unify( T1, T2 ): bool$ take two types as parameters and determine if one type can be used as another.
405% In example~\ref{lst:int_context}, the compiler is trying to unify @int@ and @EnumInstType@ of @Colour@.
406% $$Unification( int, EnumInstType<Colour> )$$ which turns into three Unification call
407% \begin{lstlisting}[label=lst:attr_resolution_1]
408% {
409%       Unify( int, char * ); // unify with the type of value
410%       Unify( int, int ); // unify with the type of position
411%       Unify( int, char * ); // unify with the type of label
412% }
413% \end{lstlisting}
414% \begin{lstlisting}[label=lst:attr_resolution_precedence]
415% {
416%       Unification( T1, EnumInstType<T2> ) {
417%               if ( Unify( T1, T2 ) ) return T2;
418%               if ( Unify( T1, int ) ) return int;
419%               if ( Unify( T1, char * ) ) return char *;
420%               Error: Cannot Unify T1 with EnumInstType<T2>;
421%       }
422% }
423% \end{lstlisting}
424% After the unification, @EnumInstType@ is replaced by its attributes.
425
426% \begin{lstlisting}[caption={Unification Functions}, label=lst:unification_func_call]
427% {
428%       T2 foo ( T1 ); // function take variable with T1 as a parameter
429%       foo( EnumInstType<T3> ); // Call foo with a variable has type EnumInstType<T3>
430%       >>>> Unification( T1, EnumInstType<T3> )
431% }
432% \end{lstlisting}
433% % The conversion can work backward: in restrictive cases, attributes of can be implicitly converted back to the EnumInstType.
434% Backward conversion:
435% \begin{lstlisting}[caption={Unification Functions}, label=lst:unification_func_call]
436% {
437%       enum Colour colour = 1;
438% }
439% \end{lstlisting}
440
441% \begin{lstlisting}[caption={Unification Functions}, label=lst:unification_func_call]
442% {
443%       Unification( EnumInstType<Colour>, int ) >>> label
444% }
445% \end{lstlisting}
446% @int@ can be unified with the label of Colour.
447% @5@ is a constant expression $\Rightarrow$ Compiler knows the value during the compilation $\Rightarrow$ turns it into
448% \begin{lstlisting}
449% {
450%       enum Colour colour = Colour.Green;
451% }
452% \end{lstlisting}
453% Steps:
454% \begin{enumerate}
455% \item
456% identify @1@ as a constant expression with type @int@, and the value is statically known as @1@
457% \item
458% @unification( EnumInstType<Colour>, int )@: @position( EnumInstType< Colour > )@
459% \item
460% return the enumeration constant at position 1
461% \end{enumerate}
462% \begin{lstlisting}
463% {
464%       enum T (int) { ... } // Declaration
465%       enum T t = 1;
466% }
467% \end{lstlisting}
468% Steps:
469% \begin{enumerate}
470% \item
471% identify @1@ as a constant expression with type @int@, and the value is statically known as @1@
472% \item
473% @unification( EnumInstType<Colour>, int )@: @value( EnumInstType< Colour > )@
474% \item
475% return the FIRST enumeration constant that has the value 1, by searching through the values array
476% \end{enumerate}
477% The downside of the precedence rule: @EnumInstType@ $\Rightarrow$ @int ( value )@ $\Rightarrow$ @EnumInstType@ may return a different @EnumInstType@ because the value can be repeated and there is no way to know which one is expected $\Rightarrow$ want uniqueness
478
479% \subsection{Casting}
480% Casting an EnumInstType to some other type T works similarly to unify the EnumInstType with T. For example:
481% \begin{lstlisting}
482% enum( int ) Foo { A = 10, B = 100, C = 1000 };
483% (int) Foo.A;
484% \end{lstlisting}
485% The \CFA-compiler unifies @EnumInstType<int>@ with int, with returns @value( Foo.A )@, which has statically known value 10. In other words, \CFA-compiler is aware of a cast expression, and it forms the context for EnumInstType resolution. The expression with type @EnumInstType<int>@ can be replaced by the compile with a constant expression 10, and optionally discard the cast expression.
486
487% \subsection{Value Conversion}
488% As discussed in section~\ref{lst:var_declaration}, \CFA only saves @position@ as the necessary information. It is necessary for \CFA to generate intermediate code to retrieve other attributes.
489
490% \begin{lstlisting}
491% Foo a; // int a;
492% int j = a;
493% char * s = a;
494% \end{lstlisting}
495% Assume stores a value x, which cannot be statically determined. When assigning a to j in line 2, the compiler @Unify@ j with a, and returns @value( a )@. The generated code for the second line will be
496% \begin{lstlisting}
497% int j = value( Foo, a )
498% \end{lstlisting}
499% Similarly, the generated code for the third line is
500% \begin{lstlisting}
501% char * j = label( Foo, a )
502% \end{lstlisting}
503
504
505\section{Enumerator Initialization}
506An enumerator must have a deterministic immutable value, either be explicitly initialized in the enumeration definition, or implicitly initialized by rules.
507
508\subsection{C Enumeration Rule}
509A C enumeration has an integral type. If not initialized, the first enumerator implicitly has the integral value 0, and other enumerators have a value equal to its $predecessor + 1$.
510
511\subsection{Auto Initializable}
512\label{s:AutoInitializable}
513
514
515\CFA enumerations have the same rule in enumeration constant initialization.
516However, only \CFA types that have defined traits for @zero_t@, @one_t@, and an addition operator can be automatically initialized by \CFA.
517
518Specifically, a type is auto-initializable only if it satisfies the trait @AutoInitializable@:
519\begin{lstlisting}
520forall(T)
521trait AutoInitializable {
522        void ?()( T & t, zero_t );
523        S ?++( T & t);
524};
525\end{lstlisting}
526An example of a user-defined @AutoInitializable@ is:
527\begin{lstlisting}[label=lst:sample_auto_Initializable]
528struct Odd { int i; };
529void ?()( Odd & t, zero_t ) { t.i = 1; };
530Odd ?++( Odd t1 ) { return Odd( t1.i + 2); };
531\end{lstlisting}
532When the type of an enumeration is @AutoInitializable@, implicit initialization is available.
533\begin{lstlisting}[label=lst:sample_auto_Initializable_usage]
534enum AutoInitUsage(Odd) {
535        A, B, C = 7, D
536};
537\end{lstlisting}
538In the example, no initializer is specified for the first enumeration constant @A@, so \CFA initializes it with the value of @zero_t@, which is 1.
539@B@ and @D@ have the values of their $predecessor++$, where @one_t@ has the value 2.
540Therefore, the enumeration is initialized as follows:
541\begin{lstlisting}[label=lst:sample_auto_Initializable_usage_gen]
542enum AutoInitUsage(Odd) {
543        A = 1, B = 3, C = 7, D = 9
544};
545\end{lstlisting}
546Note that there is no mechanism to prevent an even value for the direct initialization, such as @C = 6@.
547
548In \CFA, character, integral, float, and imaginary types are all @AutoInitialiable@.
549\begin{lstlisting}[label=lst:letter]
550enum Alphabet( int ) {
551        A = 'A', B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
552        a = 'a', b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
553};
554print( "%c, %c, %c", Alphabet.F, Alphabet.o, Alphabet.z );
555>>> F, o, z
556\end{lstlisting}
557\section{Enumeration Features}
558\subsection{Iteration and Range}
559
560It is convenient to iterate over a \CFA enumeration value, e.g.:
561\begin{lstlisting}[label=lst:range_functions]
562for ( Alphabet alph; Alphabet ) { sout | alph; }
563>>> A B C ... D
564\end{lstlisting}
565The for-loop uses the enumeration type @Alphabet@ its range, and iterates through all enumerators in the order defined in the enumeration.
566@alph@ is the iterating enumeration object, which returns the value of an @Alphabet@ in this context according to the precedence rule.
567
568\textbullet\ \CFA offers a shorthand for iterating all enumeration constants:
569\begin{lstlisting}[label=lst:range_functions]
570for ( Alphabet alph ) { sout | alph; }
571>>> A B C ... D
572\end{lstlisting}
573
574The following are examples for constructing for-control using an enumeration. Note that the type declaration of the iterating variable is optional, because \CFA can infer the type as EnumInstType based on the range expression, and possibly convert it to one of its attribute types.
575
576\textbullet\ H is implicit up-to exclusive range [0, H).
577\begin{lstlisting}[label=lst:range_function_1]
578for ( alph; Alphabet.D ) { sout | alph; }
579>>> A B C
580\end{lstlisting}
581
582\textbullet\ ~= H is implicit up-to inclusive range [0,H].
583\begin{lstlisting}[label=lst:range_function_2]
584for ( alph; ~= Alphabet.D ) { sout | alph; }
585>>> A B C D
586\end{lstlisting}
587
588\textbullet\ L ~ H is explicit up-to exclusive range [L,H).
589\begin{lstlisting}[label=lst:range_function_3]
590for ( alph; Alphabet.B ~ Alphabet.D  ) { sout | alph; }
591// for ( Alphabet alph = Alphabet.B; alph < Alphabet.D; alph += 1  ); 1 is one_t
592>>> B C
593\end{lstlisting}
594
595\textbullet\ L ~= H is explicit up-to inclusive range [L,H].
596\begin{lstlisting}[label=lst:range_function_4]
597for ( alph; Alphabet.B ~= Alphabet.D  ) { sout | alph; }
598>>> B C D
599\end{lstlisting}
600
601\textbullet\ L -~ H is explicit down-to exclusive range [H,L), where L and H are implicitly interchanged to make the range down-to.
602\begin{lstlisting}[label=lst:range_function_5]
603for ( alph; Alphabet.D -~ Alphabet.B  ) { sout | alph; }
604>>> D C
605\end{lstlisting}
606
607\textbullet\ L -~= H is explicit down-to exclusive range [H,L], where L and H are implicitly interchanged to make the range down-to.
608\begin{lstlisting}[label=lst:range_function_6]
609for ( alph; Alphabet.D -~= Alphabet.B  ) { sout | alph; }
610>>> D C B
611\end{lstlisting}
612
613A user can specify the ``step size'' of an iteration. There are two different stepping schemes of enumeration for-loop.
614\begin{lstlisting}[label=lst:range_function_stepping]
615enum(int) Sequence { A = 10, B = 12, C = 14, D = 16, D  = 18 };
616for ( s; Sequence.A ~= Sequence.D ~ 1  ) { sout | alph; }
617>>> 10 12 14 16 18
618for ( s; Sequence.A ~= Sequence.D; s+=1  ) { sout | alph; }
619>>> 10 11 12 13 14 15 16 17 18
620\end{lstlisting}
621The first syntax is stepping to the next enumeration constant, which is the default stepping scheme if not explicitly specified. The second syntax, on the other hand, is to call @operator+=@ @one_type@ on the @value( s )@. Therefore, the second syntax is equivalent to
622\begin{lstlisting}[label=lst:range_function_stepping_converted]
623for ( typeof( value(Sequence.A) ) s=value( Sequence.A ); s <= Sequence.D; s+=1  ) { sout | alph; }
624>>> 10 11 12 13 14 15 16 17 18
625\end{lstlisting}
626
627% \PAB{Explain what each loop does.}
628
629It is also possible to iterate over an enumeration's labels, implicitly or explicitly:
630\begin{lstlisting}[label=lst:range_functions_label_implicit]
631for ( char * alph; Alphabet )
632\end{lstlisting}
633This for-loop implicitly iterates every label of the enumeration, because a label is the only valid resolution to @ch@ with type @char *@ in this case.
634If the value can also be resolved as the @char *@, you might iterate the labels explicitly with the array iteration.
635\begin{lstlisting}[label=lst:range_functions_label_implicit]
636for ( char * ch; labels( Alphabet ) )
637\end{lstlisting}
638
639
640% \subsection{Non-uniform Type}
641% TODO: Working in Progress, might need to change other sections. Conflict with the resolution right now.
642
643% \begin{lstlisting}
644% enum T( int, char * ) {
645%        a=42, b="Hello World"
646% };
647% \end{lstlisting}
648% The enum T declares two different types: int and char *. The enumerators of T hold values of one of the declared types.
649
650\subsection{Enumeration Inheritance}
651
652\begin{lstlisting}[label=lst:EnumInline]
653enum( char * ) Name { Jack = "Jack", Jill = "Jill" };
654enum /* inferred */ Name2 { inline Name, Sue = "Sue", Tom = "Tom" };
655\end{lstlisting}
656\lstinline{Inline} allows Enumeration Name2 to inherit enumerators from Name1 by containment, and a Name enumeration is a subtype of enumeration Name2. An enumeration instance of type Name can be used where an instance of Name2 is expected.
657\begin{lstlisting}[label=lst:EnumInline]
658Name Fred;
659void f( Name2 );
660f( Fred );
661\end{lstlisting}
662If enumeration A declares @inline B@ in its enumeration body, enumeration A is the "inlining enum" and enumeration B is the "inlined enum".
663
664An enumeration can inline at most one other enumeration. The inline declaration must be placed before the first enumerator of the inlining enum. The inlining enum has all the enumerators from the inlined enum, with the same labels, values, and position.
665\begin{lstlisting}[label=lst:EnumInline]
666enum /* inferred */ Name2 { inline Name, Sue = "Sue", Tom = "Tom" };
667// is equivalent to enum Name2 { Jack = "Jack", Jill="Jill", Sue = "Sue", Tom = "Tom" };
668\end{lstlisting}
669Name.Jack is equivalent to Name2.Jack. Their attributes are all identical. Opening both Name and Name2 in the same scope will not introduce ambiguity.
670\begin{lstlisting}[label=lst:EnumInline]
671with( Name, Name2 ) { Jack; } // Name.Jack and Name2.Jack are equivalent. No ambiguity
672\end{lstlisting}
673
674\section{Implementation}
675
676\subsection{Static Attribute Expression}
677\begin{lstlisting}[label=lst:static_attr]
678enum( char * ) Colour {
679        Red = "red", Blue = "blue", Green = "green"
680};
681\end{lstlisting}
682An enumerator expression returns its enumerator value as a constant expression with no runtime cost. For example, @Colour.Red@ is equivalent to the constant expression "red", and \CFA finishes the expression evaluation before generating the corresponding C code. Applying a pseudo-function to a constant enumerator expression results in a constant expression as well. @value( Colour.Red )@, @position( Colour. Red )@, and @label( Colour.Red )@ are equivalent to constant expression with char * value "red", int value 0, and char * value "Red", respectively.
683
684\subsection{Runtime Attribute Expression and Weak Referenced Data}
685\begin{lstlisting}[label=lst:dynamic_attr]
686Colour c;
687...
688value( c ); // or c
689\end{lstlisting}
690An enumeration variable c is equivalent to an integer variable with the value of @position( c )@ In Example~\ref{lst:dynamic_attr}, the value of enumeration variable c is unknown at compile time. In this case, the pseudo-function calls are reduced to expression that returns the enumerator values at runtime.
691
692\CFA stores the variables and labels in @const@ arrays to provide runtime lookup for enumeration information.
693
694\begin{lstlisting}[label=lst:attr_array]
695const char * Colour_labels [3] = { "Red", "Blue", "Green" };
696const char * Colour_values [3] = { "red", "blue", "green" };
697\end{lstlisting}
698The \CFA compiles transforms the attribute expressions into array access.
699\begin{lstlisting}[label=lst:attr_array_access]
700position( c ) // c; an integer
701value( c ); // Colour_values[c]
702label( c ); // Colour_labels[c]
703\end{lstlisting}
704
705To avoid unnecessary memory usage, the labels and values array are only generated as needed, and only generate once across all compilation units. By default, \CFA defers the declaration of the label and value arrays until an call to attribute function with a dynamic value. If an attribute function is never called on a dynamic value of an enumerator, the array will never be allocated. Once the arrays are created, all compilation units share a weak reference to the allocation array.
706
707\subsection{Enum Prelude}
708
709\begin{lstlisting}[label=lst:enum_func_dec]
710forall( T ) {
711        unsigned position( unsigned );
712        T value( unsigned );
713        char * label( unsigned );
714}
715\end{lstlisting}
716\CFA loads the declaration of enumeration function from the enum.hfa.
717
718\subsection{Internal Representation}
719
720The definition of an enumeration is represented by an internal type called @EnumDecl@. At the minimum, it stores all the information needed to construct the companion object. Therefore, an @EnumDecl@ can be represented as the following:
721\begin{lstlisting}[label=lst:EnumDecl]
722forall(T)
723class EnumDecl {
724        T* values;
725        char** label;
726};
727\end{lstlisting}
728
729The internal representation of an enumeration constant is @EnumInstType@.
730An @EnumInstType@ has a reference to the \CFA-enumeration declaration and the position of the enumeration constant.
731\begin{lstlisting}[label=lst:EnumInstType]
732class EnumInstType {
733        EnumDecl enumDecl;
734        int position;
735};
736\end{lstlisting}
737In the later discussion, we will use @EnumDecl<T>@ to symbolize a @EnumDecl@ parameterized by type T, and @EnumInstType<T>@ is a declared instance of @EnumDecl<T>@.
738
739\begin{lstlisting}[caption={Enum Type Functions}, label=lst:cforall_enum_data]
740const T * const values;
741const char * label;
742int length;
743\end{lstlisting}
744Companion data are necessary information to represent an enumeration. They are stored as standalone pieces, rather than a structure. Those data will be loaded "on demand".
745Companion data are needed only if the according pseudo-functions are called. For example, the value of the enumeration Workday is loaded only if there is at least one compilation that has call $value(Workday)$. Once the values are loaded, all compilations share these values array to reduce memory usage.
746
747
748% \subsection{(Rework) Companion Object and Companion Function}
749
750% \begin{lstlisting}[caption={Enum Type Functions}, label=lst:cforall_enum_functions]
751% forall( T )
752% struct Companion {
753%       const T * const values;
754%                const char * label;
755%       int length;
756% };
757% \end{lstlisting}
758% \CFA generates companion objects, an instance of structure that encloses @necessary@ data to represent an enumeration. The size of the companion is unknown at the compilation time, and it "grows" in size to compensate for the @usage@.
759
760% The companion object is singleton across the compilation (investigation).
761
762% \CFA generates the definition of companion functions.
763% Because \CFA implicitly stores an enumeration instance as its position, the companion function @position@ does nothing but return the position it is passed.
764% Companions function @value@ and @label@ return the array item at the given position of @values@ and @labels@, respectively.
765% \begin{lstlisting}[label=lst:companion_definition]
766% int position( Companion o, int pos ) { return pos; }
767% T value( Companion o, int pos ) { return o.values[ pos ]; }
768% char * label( Companion o, int pos ) { return o.labels[ pos ]; }
769% \end{lstlisting}
770% Notably, the @Companion@ structure definition, and all companion objects, are visible to users.
771% A user can retrieve values and labels defined in an enumeration by accessing the values and labels directly, or indirectly by calling @Companion@ functions @values@ and @labels@
772% \begin{lstlisting}[label=lst:companion_definition_values_labels]
773% Colour.values; // read the Companion's values
774% values( Colour ); // same as Colour.values
775% \end{lstlisting}
776
777\subsection{Companion Traits (experimental)}
778Not sure its semantics yet, and it might replace a companion object.
779\begin{lstlisting}[label=lst:companion_trait]
780forall(T1) {
781        trait Companion(otype T2<otype T1>) {
782                T1 value((otype T2<otype T1> const &);
783                int position(otype T2<otype T1> const &);
784                char * label(otype T2<otype T1> const &);
785        }
786}
787\end{lstlisting}
788All enumerations implicitly implement the Companion trait, an interface to access attributes. The Companion can be a data type because it fulfills to requirements to have concrete instances, which are:
789
790\begin{enumerate}
791  \item The instance of enumeration has a single polymorphic type.
792  \item Each assertion should use the type once as a parameter.
793\end{enumerate}
794
795\begin{lstlisting}
796enum(int) Weekday {
797        Monday=10, Tuesday, ...
798};
799
800T value( enum Weekday<T> & this);
801int position( enum Weekday<T> & this )
802char * label( enum Weekday<T> & this )
803
804trait Companion obj = (enum(int)) Workday.Weekday;
805value(obj); // 10
806\end{lstlisting}
807The enumeration comes with default implementation to the Companion traits functions. The usage of Companion functions would make \CFA allocates and initializes the necessary companion arrays, and return the data at the position represented by the enumeration.
808(...)
809
810\subsection{User Define Enumeration Functions}
811
812Companion objects make extending features for \CFA enumeration easy.
813\begin{lstlisting}[label=lst:companion_user_definition]
814char * charastic_string( Companion o, int position ) {
815        return sprintf( "Label: %s; Value: %s", label( o, position ), value( o, position) );
816}
817printf( charactic_string ( Color, 1 ) );
818>>> Label: Green; Value: G
819\end{lstlisting}
820Defining a function takes a Companion object effectively defines functions for all \CFA enumeration.
821
822The \CFA compiler turns a function call that takes an enumeration instance as a parameter into a function call with a companion object plus a position.
823Therefore, a user can use the syntax with a user-defined enumeration function call:
824\begin{lstlisting}[label=lst:companion_user_definition]
825charactic_string( Color.Green ); // equivalent to charactic_string( Color, 1 )
826>>> Label: Green; Value: G
827\end{lstlisting}
828Similarly, the user can work with the enumeration type itself: (see section ref...)
829\begin{lstlisting}[ label=lst:companion_user_definition]
830void print_enumerators ( Companion o ) {
831        for ( c : Companion o ) {
832                sout | label (c) | value( c ) ;
833        }
834}
835print_enumerators( Colour );
836\end{lstlisting}
837
838
839\subsection{Declaration}
840
841The qualified enumeration syntax is dedicated to \CFA enumeration.
842\begin{lstlisting}[label=lst:range_functions]
843enum (type_declaration) name { enumerator = const_expr, enumerator = const_expr, ... }
844\end{lstlisting}
845A compiler stores the name, the underlying type, and all enumerators in an @enumeration table@.
846During the $Validation$ pass, the compiler links the type declaration to the type's definition.
847It ensures that the name of an enumerator is unique within the enumeration body, and checks if all values of the enumerator have the declaration type.
848If the declared type is not @AutoInitializable@, \CFA rejects the enumeration definition.
849Otherwise, it attempts to initialize enumerators with the enumeration initialization pattern. (a reference to a future initialization pattern section)
850
851\begin{lstlisting}[label=lst:init]
852struct T { ... };
853void ?{}( T & t, zero_t ) { ... };
854void ?{}( T & t, one_t ) { ... };
855T ?+?( T & lhs, T & rhs ) { ... };
856
857enum (T) Sample {
858        Zero: 0 /* zero_t */,
859        One: Zero + 1 /* ?+?( Zero, one_t ) */ , ...
860};
861\end{lstlisting}
862Challenge: \\
863The value of an enumerator, or the initializer, requires @const_expr@.
864While previously getting around the issue by pushing it to the C compiler, it might not work anymore because of the user-defined types, user-defined @zero_t@, @one_t@, and addition operation.
865Might not be able to implement a \emph{correct} static check.
866
867\CFA $autogens$ a Companion object for the declared enumeration.
868\begin{lstlisting}[label=lst:companion]
869Companion( T ) Sample {
870        .values: { 0, 0+1, 0+1+1, 0+1+1+1, ... }, /* 0: zero_t, 1: one_t, +: ?+?{} */
871        .labels: { "Zero", "One", "Two", "Three", ...},
872        .length: /* number of enumerators */
873};
874\end{lstlisting}
875\CFA stores values as intermediate expressions because the result of the function call to the function @?+?{}(T&, T&)@ is statically unknown to \CFA.
876But the result is computed at run time, and the compiler ensures the @values@ are not changed.
877
878\subsection{Qualified Expression}
879
880\CFA uses qualified expression to address the scoping of \CFA-enumeration.
881\begin{lstlisting}[label=lst:qualified_expression]
882aggregation_name.field;
883\end{lstlisting}
884The qualified expression is not dedicated to \CFA enumeration.
885It is a feature that is supported by other aggregation in \CFA as well, including a C enumeration.
886When C enumerations are unscoped, the qualified expression syntax still helps to disambiguate names in the context.
887\CFA recognizes if the expression references a \CFA aggregation by searching the presence of @aggregation_name@ in the \CFA enumeration table.
888If the @aggregation_name@ is identified as a \CFA enumeration, the compiler checks if @field@ presents in the declared \CFA enumeration.
889
890\subsection{\lstinline{with} Clause/Statement}
891
892Instead of qualifying an enumeration expression every time, the @with@ can be used to expose enumerators to the current scope, making them directly accessible.
893\begin{lstlisting}[label=lst:declaration]
894enum Color( char * ) { Red="R", Green="G", Blue="B" };
895enum Animal( int ) { Cat=10, Dog=20 };
896with ( Color, Animal ) {
897        char * red_string = Red; // value( Color.Red )
898        int cat = Cat; // value( Animal.Cat )
899}
900\end{lstlisting}
901The \lstinline{with} might introduce ambiguity to a scope. Consider the example:
902\begin{lstlisting}[label=lst:declaration]
903enum Color( char * ) { Red="R", Green="G", Blue="B" };
904enum RGB( int ) { Red=0, Green=1, Blue=2 };
905with ( Color, RGB ) {
906        // int red = Red;
907}
908\end{lstlisting}
909\CFA will not try to resolve the expression with ambiguity. It would report an error. In this case, it is necessary to qualify @Red@ even inside of the \lstinline{with} clause.
910
911\subsection{Instance Declaration}
912
913
914\begin{lstlisting}[label=lst:var_declaration]
915enum Sample s1;
916\end{lstlisting}
917
918The declaration \CFA-enumeration variable has the same syntax as the C-enumeration. Internally, such a variable will be represented as an EnumInstType.
919
920\section{Related Work}
921
922
923\end{document}
924
925% Local Variables: %
926% tab-width: 4 %
927% compile-command: "pdflatex enum.tex" %
928% End: %
Note: See TracBrowser for help on using the repository browser.