Changeset a4da45e for doc


Ignore:
Timestamp:
Feb 26, 2024, 3:53:42 AM (22 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
3f9a8d0
Parents:
0522ebe (diff), 022bce0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Resolve conflict

Location:
doc
Files:
3 added
2 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • doc/LaTeXmacros/common.sty

    r0522ebe ra4da45e  
    1111%% Created On       : Sat Apr  9 10:06:17 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Sun Jan 21 13:17:48 2024
    14 %% Update Count     : 633
     13%% Last Modified On : Sun Feb 25 17:37:46 2024
     14%% Update Count     : 640
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    4040\newcommand{\CFA}{\protect\CFAIcon\xspace}                              % CFA symbolic name
    4141\newcommand{\CFL}{\textrm{Cforall}\xspace}                              % Cforall non-icon name
    42 \newcommand{\Celeven}{\textrm{C11}\xspace}                              % C11 symbolic name
     42\newcommand{\Celeven}{\textrm{C1\!1}\xspace}                    % C11 symbolic name
     43
    4344\newcommand{\CCIcon}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}} % C++ icon
    44 \newcommand{\CC}[1][]{\protect\CCIcon{#1}\xspace}               % C++ symbolic name
    45 \newcommand{\Cpp}[1][]{\CC{#1}}                                                 % C++ synonym
    4645% numbers disallowed in latex variables names => use number names
    47 \newcommand{\CCeleven}{\protect\CCIcon{11}\xspace}              % C++11 symbolic name
     46\newcommand{\CCeleven}{\protect\CCIcon{1\!1}\xspace}    % C++11 symbolic name
    4847\newcommand{\CCfourteen}{\protect\CCIcon{14}\xspace}    % C++14 symbolic name
    4948\newcommand{\CCseventeen}{\protect\CCIcon{17}\xspace}   % C++17 symbolic name
    5049\newcommand{\CCtwenty}{\protect\CCIcon{20}\xspace}              % C++20 symbolic name
     50\newcommand{\CC}[1][]{\protect\CCIcon{#1}\xspace}               % C++ symbolic name
     51\newcommand{\Cpp}[1][]{\CC{#1}}                                                 % C++ synonym
     52
    5153\newcommand{\Csharp}{C\raisebox{-0.7ex}{\relsize{2}$^\sharp$}\xspace} % C# symbolic name
    5254
     
    293295xleftmargin=\parindentlnth,                             % indent code to paragraph indentation
    294296extendedchars=true,                                             % allow ASCII characters in the range 128-255
    295 escapechar=§,                                                   % LaTeX escape in CFA code §...§ (section symbol), emacs: C-q M-'
    296297mathescape=false,                                               % disable LaTeX math escape in CFA code $...$
    297298keepspaces=true,                                                %
     
    304305literate=
    305306%  {-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.75ex}{0.1ex}}}}1
    306   {-}{\raisebox{-1pt}{\texttt{-}}}1
     307  {-}{\raisebox{-1pt}{\ttfamily-}}1
    307308  {^}{\raisebox{0.6ex}{$\scriptstyle\land\,$}}1
    308309  {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1
     310  {'}{\ttfamily'\!}1
    309311  {`}{\ttfamily\upshape\hspace*{-0.3ex}`}1
    310312  {<-}{$\leftarrow$}2
     
    318320\lstset{
    319321language=CFA,
    320 %moredelim=**[is][\color{red}]{@}{@},   % red highlighting @...@
     322escapechar=§,                                                   % LaTeX escape in CFA code §...§ (section symbol), emacs: C-q M-'
    321323moredelim=**[is][\color{red}]{®}{®},    % red highlighting ®...® (registered trademark symbol) emacs: C-q M-.
    322324%moredelim=**[is][\color{blue}]{ß}{ß},  % blue highlighting ß...ß (sharp s symbol) emacs: C-q M-_
     
    328330% inline code ©...© (copyright symbol) emacs: C-q M-)
    329331\lstMakeShortInline©                                    % single-character for \lstinline
     332
    330333\else% regular ASCI characters
     334
    331335\lstnewenvironment{cfa}[1][]{% necessary
    332336\lstset{
    333337language=CFA,
    334338escapechar=\$,                                                  % LaTeX escape in CFA code
    335 mathescape=false,                                               % LaTeX math escape in CFA code $...$
    336339moredelim=**[is][\color{red}]{@}{@},    % red highlighting @...@
    337340}% lstset
  • doc/LaTeXmacros/common.tex

    r0522ebe ra4da45e  
    1111%% Created On       : Sat Apr  9 10:06:17 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Wed Jan 24 08:43:57 2024
    14 %% Update Count     : 593
     13%% Last Modified On : Sun Feb 25 18:11:56 2024
     14%% Update Count     : 614
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    4040\newcommand{\CFA}{\protect\CFAIcon\xspace}                              % CFA symbolic name
    4141\newcommand{\CFL}{\textrm{Cforall}\xspace}                              % Cforall non-icon name
    42 \newcommand{\Celeven}{\textrm{C11}\xspace}                              % C11 symbolic name
     42\newcommand{\Celeven}{\textrm{C1\!1}\xspace}                    % C11 symbolic name
     43
    4344\newcommand{\CCIcon}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}} % C++ icon
    44 \newcommand{\CC}[1][]{\protect\CCIcon{#1}\xspace}               % C++ symbolic name
    45 \newcommand{\Cpp}[1][]{\CC{#1}}                                                 % C++ synonym
    4645% numbers disallowed in latex variables names => use number names
    47 \newcommand{\CCeleven}{\protect\CCIcon{11}\xspace}              % C++11 symbolic name
     46\newcommand{\CCeleven}{\protect\CCIcon{1\!1}\xspace}    % C++11 symbolic name
    4847\newcommand{\CCfourteen}{\protect\CCIcon{14}\xspace}    % C++14 symbolic name
    4948\newcommand{\CCseventeen}{\protect\CCIcon{17}\xspace}   % C++17 symbolic name
    5049\newcommand{\CCtwenty}{\protect\CCIcon{20}\xspace}              % C++20 symbolic name
     50\newcommand{\CC}[1][]{\protect\CCIcon{#1}\xspace}               % C++ symbolic name
     51\newcommand{\Cpp}[1][]{\CC{#1}}                                                 % C++ synonym
     52
    5153\newcommand{\Csharp}{C\raisebox{-0.7ex}{\relsize{2}$^\sharp$}\xspace} % C# symbolic name
    5254
     
    297299xleftmargin=\parindentlnth,                             % indent code to paragraph indentation
    298300extendedchars=true,                                             % allow ASCII characters in the range 128-255
    299 escapechar=§,                                                   % LaTeX escape in CFA code §...§ (section symbol), emacs: C-q M-'
    300301mathescape=false,                                               % disable LaTeX math escape in CFA code $...$
    301302keepspaces=true,                                                %
     
    308309literate=
    309310%  {-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.75ex}{0.1ex}}}}1
    310   {-}{\raisebox{-1pt}{\texttt{-}}}1
     311  {-}{\raisebox{-1pt}{\ttfamily-}}1
    311312  {^}{\raisebox{0.6ex}{$\scriptstyle\land\,$}}1
    312313  {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1
     314  {'}{\ttfamily'\!}1
    313315  {`}{\ttfamily\upshape\hspace*{-0.3ex}`}1
    314316  {<-}{$\leftarrow$}2
     
    322324\lstset{
    323325language=CFA,
    324 %moredelim=**[is][\color{red}]{@}{@},   % red highlighting @...@
     326escapechar=§,                                                   % LaTeX escape in CFA code §...§ (section symbol), emacs: C-q M-'
    325327moredelim=**[is][\color{red}]{®}{®},    % red highlighting ®...® (registered trademark symbol) emacs: C-q M-.
    326328%moredelim=**[is][\color{blue}]{ß}{ß},  % blue highlighting ß...ß (sharp s symbol) emacs: C-q M-_
     
    332334% inline code ©...© (copyright symbol) emacs: C-q M-)
    333335\lstMakeShortInline©                                    % single-character for \lstinline
     336
    334337\else% regular ASCI characters
     338
    335339\lstnewenvironment{cfa}[1][]{% necessary
    336340\lstset{
    337341language=CFA,
    338342escapechar=\$,                                                  % LaTeX escape in CFA code
    339 mathescape=false,                                               % LaTeX math escape in CFA code $...$
    340343moredelim=**[is][\color{red}]{@}{@},    % red highlighting @...@
    341344}% lstset
  • doc/LaTeXmacros/lstlang.sty

    r0522ebe ra4da45e  
    88%% Created On       : Sat May 13 16:34:42 2017
    99%% Last Modified By : Peter A. Buhr
    10 %% Last Modified On : Thu Sep 21 08:40:05 2023
    11 %% Update Count     : 31
     10%% Last Modified On : Fri Feb 16 07:59:29 2024
     11%% Update Count     : 37
    1212%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1313
     
    125125}
    126126
    127 % C++ programming language
    128 \lstdefinelanguage{C++}[ANSI]{C++}{
    129         morekeywords={nullptr,}
    130 }
    131 
    132127% uC++ programming language, based on ANSI C++
    133 \lstdefinelanguage{uC++}[ANSI]{C++}{
     128\lstdefinelanguage{uC++}[GNU]{C++}{
    134129        morekeywords={
    135130                _Accept, _AcceptReturn, _AcceptWait, _Actor, _At, _Catch, _CatchResume, _CorActor, _Cormonitor, _Coroutine,
  • doc/bibliography/pl.bib

    r0522ebe ra4da45e  
    37423742    month       = jul, year = 1987,
    37433743    volume      = 4, number = 4, pages = {9-16}
     3744}
     3745
     3746@manual{FreePascal,
     3747    keywords    = {Pascal, object oriented},
     3748    contributer = {pabuhr@plg},
     3749    author      = {Micha\"{e}l Van Canneyt},
     3750    title       = {{F}ree {P}ascal Reference Guide, version 3.2.2},
     3751    month       = may,
     3752    year        = 2021,
     3753    note        = {\url{http://downloads.freepascal.org/fpc/docs-pdf/ref.pdf}},
    37443754}
    37453755
     
    82438253}
    82448254
     8255@manual{Swift,
     8256    keywords    = {Swift programming language},
     8257    contributer = {pabuhr@plg},
     8258    key         = {Swift},
     8259    author      = {Chris Lattner and Doug Gregor and John McCall and Ted Kremenek and Joe Groff and Apple Inc.},
     8260    title       = {The Swift Programming Language},
     8261    edition     = {5.9.2},
     8262    organization= {Apple Inc.},
     8263    address     = {Cupertino, CA, USA},
     8264    year        = 2024,
     8265    note        = {\url{https://docs.swift.org/swift-book/documentation/the-swift-programming-language}},
     8266}
     8267
    82458268@inproceedings{Burns81,
    82468269    keywords    = {N-thread software-solution mutual exclusion},
  • doc/proposals/enum.tex

    r0522ebe ra4da45e  
    117117\end{abstract}
    118118
    119 \section{Background}
     119\section{Introduction}
    120120
    121121Naming values is a common practice in mathematics and engineering, e.g., $\pi$, $\tau$ (2$\pi$), $\phi$ (golden ratio), MHz (1E6), etc.
    122 Naming 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).
     122Naming 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), specific times (noon, New Years).
    123123Many programming languages capture this important software-engineering capability through a mechanism called an \newterm{enumeration}.
    124124An 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.
     
    126126
    127127Specifically, an enumerated type restricts its values to a fixed set of named constants.
    128 Fundamentally, 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.
    129 However, the values for basic types are not named, other than the programming-language supplied constants.
    130 
    131 
    132 \section{C-Style Enum}
    133 
    134 The C-Style enumeration has the following syntax and semantics, and is representative of enumerations in many other programming languages (see Section~\ref{s:RelatedWork}).
    135 \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}}
    139 \end{lstlisting}
    140 Here, the enumeration type @Weekday@ defines the ordered \newterm{enumerator}s @Monday@, @Tuesday@, @Wednesday@, @Thursday@, @Friday@, @Saturday@ and @Sunday@.
    141 By convention, the successor of @Tuesday@ is @Monday@ and the predecessor of @Tuesday@ is @Wednesday@, independent of the associated enumerator constants.
    142 Because an enumerator is a constant, it cannot appear in a mutable context, e.g. @Mon = Sun@ is meaningless, and has no address, it is an rvalue\footnote{
    143 The term rvalue defines an expression that can only appear on the right-hand side of an assignment.}.
    144 Enumerators without explicitly designated constants are auto-initialized by the compiler: from left to right, starting at zero or the next explicitly initialized constant, incrementing by @1@.
    145 For example, @Monday@ to @Wednesday@ are implicitly assigned with constants 0--2, @Thursday@ is explicitly set to constant @10@, and @Friday@ to @Sunday@ are implicitly assigned with constants 11--13.
    146 Hence, there are 3 universal enumeration attributes: \newterm{position}, \newterm{label}, and \newterm{value}:
     128While 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., these values are not named, other than the programming-language supplied constant names.
     129
     130Fundamentally, all enumeration systems have an \newterm{enumeration} type with an associated set of \newterm{enumerator} names.
     131An enumeration has three universal attributes, \newterm{position}, \newterm{label}, and \newterm{value}, as shown by this representative enumeration, where position and value can be different.
    147132\begin{cquote}
    148133\small\sf\setlength{\tabcolsep}{3pt}
    149134\begin{tabular}{rccccccccccc}
    150 @enum@ Weekday \{       & Monday,       & Tuesday,      & Wednesday,    & Thursday = 10,& Friday,       & Saturday,     & Sunday \}; \\
    151 \it\color{red}position          & 0                     & 1                     & 2                             & 3                             & 4                     & 5                     & 6                     \\
    152 \it\color{red}label                     & Monday        & Tuesday       & Wednesday             & Thursday              & Friday        & Saturday      & Sunday        \\
    153 \it\color{red}value                     & 0                     & 1                     & 2                             & {\color{red}10}& 11           & 12            & 13
     135\it\color{red}enumeration & \multicolumn{7}{c}{\it\color{red}enumerators}       \\
     136$\downarrow$\hspace*{25pt} & \multicolumn{7}{c}{$\downarrow$}                           \\
     137@enum@ Weekday \{                               & Monday,       & Tuesday,      & Wednesday,    & Thursday,& Friday,    & Saturday,     & Sunday \}; \\
     138\it\color{red}position                  & 0                     & 1                     & 2                             & 3                             & 4                     & 5                     & 6                     \\
     139\it\color{red}label                             & Monday        & Tuesday       & Wednesday             & Thursday              & Friday        & Saturday      & Sunday        \\
     140\it\color{red}value                             & 0                     & 1                     & 2                             & 3                             & 4                     & 5             & 6
    154141\end{tabular}
    155142\end{cquote}
    156 Finally, C enumerators are \newterm{unscoped}, i.e., enumerators declared inside of an @enum@ are visible in the enclosing scope of the @enum@ type.
     143Here, the \newterm{enumeration} @Weekday@ defines the ordered \newterm{enumerator}s @Monday@, @Tuesday@, @Wednesday@, @Thursday@, @Friday@, @Saturday@ and @Sunday@.
     144By convention, the successor of @Tuesday@ is @Monday@ and the predecessor of @Tuesday@ is @Wednesday@, independent of the associated enumerator constant values.
     145Because an enumerator is a constant, it cannot appear in a mutable context, e.g. @Mon = Sun@ is meaningless, and an enumerator has no address, it is an \newterm{rvalue}\footnote{
     146The term rvalue defines an expression that can only appear on the right-hand side of an assignment.}.
     147
     148
     149\section{C-Style Enum}
     150
     151The C-Style enumeration has the following syntax and semantics.
     152\begin{lstlisting}
     153enum Weekday { Monday, Tuesday, Wednesday, Thursday@ = 10@, Friday, Saturday, Sunday };
     154\end{lstlisting}
     155Enumerators without an explicitly designated constant value are \newterm{auto-initialized} by the compiler: from left to right, starting at zero or the next explicitly initialized constant, incrementing by @1@.
     156For example, @Monday@ to @Wednesday@ are implicitly assigned with constants @0@--@2@, @Thursday@ is explicitly set to constant @10@, and @Friday@ to @Sunday@ are implicitly assigned with constants @11@--@13@.
     157Initialization may occur in any order.
     158\begin{lstlisting}
     159enum Weekday { Thursday@ = 10@, Friday, Saturday, Sunday, Monday@ = 0@, Tuesday, Wednesday };
     160\end{lstlisting}
     161Note, the comma in the enumerator list can be a terminator or a separator, allowing the list to end with a dangling comma.
     162\begin{lstlisting}
     163enum Weekday {
     164        Thursday = 10, Friday, Saturday, Sunday,
     165        Monday = 0, Tuesday, Wednesday@,@ // terminating comma
     166};
     167\end{lstlisting}
     168This feature allow enumerator lines to be interchanged without moving a comma.\footnote{
     169A terminating comma appears in other C syntax, e.g., the initializer list.}
     170Finally, C enumerators are \newterm{unscoped}, i.e., enumerators declared inside of an @enum@ are visible (projected) into the enclosing scope of the @enum@ type.
    157171
    158172In theory, a C enumeration \emph{variable} is an implementation-defined integral type large enough to hold all enumerated values.
    159 In practice, since integral constants in C have type @int@ (unless qualified with a size suffix), C uses @int@ as the underlying type for enumeration variables.
    160 Furthermore, there is an implicit bidirectional conversion between an enumeration and integral types.
     173In practice, since integral constants are used, which have type @int@ (unless qualified with a size suffix), C uses @int@ as the underlying type for enumeration variables.
     174Finally, there is an implicit bidirectional conversion between an enumeration and integral types.
    161175\begin{lstlisting}[label=lst:enum_scope]
    162176{
    163         enum Weekday { ... };                           $\C{// enumerators implicitly projected into local scope}$
     177        enum Weekday { /* as above */ };        $\C{// enumerators implicitly projected into local scope}$
    164178        Weekday weekday = Monday;                       $\C{// weekday == 0}$
    165179        weekday = Friday;                                       $\C{// weekday == 11}$
    166         int i = Sunday                                          $\C{// implicit conversion to int, i == 13}$
     180        int i = Sunday;                                         $\C{// implicit conversion to int, i == 13}$
    167181        weekday = 10000;                                        $\C{// UNDEFINED! implicit conversion to Weekday}$
    168182}
     
    171185The implicit conversion from @int@ to an enumeration type is an unnecessary source of error.
    172186
     187It is common for C programmers to ``believe'' there are 3 equivalent forms of constant enumeration.
     188\begin{lstlisting}[label=lst:enum_scope]
     189#define Monday 0
     190static const int Monday = 0;
     191enum { Monday };
     192\end{lstlisting}
     193For @#define@, the programmer has to play compiler and explicitly manage the enumeration values;
     194furthermore, these are independent constants outside of any language type mechanism.
     195The same explicit management is true for @const@ declarations, and the @const@ variable cannot appear in constant-expression locations, like @case@ labels, array dimensions,\footnote{
     196C allows variable-length array-declarations (VLA), so this case does work, but it fails in \CC, which does not support VLAs, unless it is \lstinline{g++}.} and immediate operands of assembler instructions.
     197Only the @enum@ form is managed by the compiler, is part of the language type-system, and works in all C constant-expression locations.
     198
     199
    173200\section{\CFA-Style Enum}
    174201
     
    176203\CFA also extends C-Style enumeration by adding a number of new features that bring enumerations inline with other modern programming languages.
    177204
     205
     206\subsection{Enumerator Name Resolution}
     207\label{s:EnumeratorNameResolution}
     208
     209In C, unscoping of enumerators presents a \newterm{naming problem} when multiple enumeration types appear in the same scope with duplicate enumerator names.
     210There is no mechanism in C to resolve these naming conflicts other than renaming of one of the duplicates, which may be impossible.
     211
     212The \CFA type-system allows extensive overloading, including enumerators.
     213Furthermore, \CFA uses the left-hand of assignment in type resolution to pinpoint the best overloaded name.
     214Finally, qualification is provided to disambiguate any ambiguous situations.
     215\begin{lstlisting}
     216enum C1 { First, Second, Third, Fourth };
     217enum C2 { @Fourth@, @Third@, @Second@, @First@ };
     218C1 p() { return Third; }                                $\C{// correctly resolved duplicate names}$
     219C2 p() { return Fourth; }
     220void foo() {
     221        C1 e1 = First;   C2 e2 = First;
     222        e1 = Second;   e2 = Second;
     223        e1 = p();   e2 = p();                           $\C{// correctly resolved function call}$
     224        int i = @C1.@First + @C2.@First;        $\C{// ambiguous without qualification}$
     225}
     226\end{lstlisting}
     227\CFA overloading allows programmers to use the most meaningful names without fear of unresolvable clashes from included files, which are correctable with qualification.
     228
     229
     230\subsection{Enumerator Scoping}
     231
     232An enumeration can be scoped, so the enumerator constants are not projected into the enclosing scope, using @'!'@.
     233\begin{lstlisting}
     234enum Weekday @!@ { /* as above */ };
     235enum( char * ) Names @!@ { /* as above */ };
     236\end{lstlisting}
     237Now the enumerators \emph{must} be qualified with the associated enumeration.
     238\begin{lstlisting}
     239Weekday weekday = @Weekday@.Monday;
     240Names names = @Names.@Fred;
     241names = @Names.@Jane;
     242\end{lstlisting}
     243It is possible to toggle back to unscoping using the \CFA @with@ clause/statement (see also \CC \lstinline[language=c++]{using enum} in Section~\ref{s:C++RelatedWork}).
     244\begin{lstlisting}
     245Weekday weekday;
     246with ( @Weekday@, @Names@ ) {                   $\C{// type names}$
     247         Names names = @Fred@;
     248         names = @Jane@;
     249         weekday = Saturday;
     250}
     251\end{lstlisting}
     252As in Section~\ref{s:EnumeratorNameResolution}, opening multiple unscoped enumerations can result in duplicate enumeration names, but \CFA type resolution and falling back to explicit qualification handles name resolution.
     253
    178254\subsection{Enumerator Typing}
    179255
    180 \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.
    181 Figure~\ref{f:EumeratorTyping} shows a series of examples illustrating that all \CFA types can be use with an enumeration and each type's constants used to set the enumerators.
    182 
    183 Typed enumerates deals with \emph{harmonizing} problem between an enumeration and its companion data.
    184 The following example is from the \CFA compiler, written in \CC.
    185 \begin{lstlisting}
    186 enum integral_types { chr, schar, uschar, sshort, ushort, sint, usint, ..., NO_OF_ITYPES };
    187 char * integral_names[NO_OF_ITYPES] = {
    188         "char", "signed char", "unsigned char",
    189         "signed short int", "unsigned short int",
    190         "signed int", "unsigned int",
    191         ...
    192 };
    193 \end{lstlisting}
    194 The \emph{harmonizing} problem occurs because the enumeration declaration is in one header file and the names are declared in another translation unit.
    195 It is up to the programmer to ensure changes made in one location are harmonized with the other location (by identifying this requirement within a comment).
    196 The typed enumeration largely solves this problem by combining and managing the two data types.
    197 \begin{lstlisting}
    198 enum( char * ) integral_types {
    199         chr = "char", schar = "signed char", uschar = "unsigned char",
    200         sshort = "signed short int", ushort = "unsigned short int",
    201         sint = "signed int", usint = "unsigned int",
    202         ...
    203 };
     256\CFA extends the enumeration declaration by parameterizing with a type (like a generic type), allowing enumerators to be assigned any values from the declared type.
     257Figure~\ref{f:EumeratorTyping} shows a series of examples illustrating that all \CFA types can be use with an enumeration and each type's constants used to set the enumerator constants.
     258Note, the synonyms @Liz@ and @Beth@ in the last declaration.
     259
     260Because enumerators are constants, the enumeration type is implicitly @const@, so all the enumerator types in Figure~\ref{f:EumeratorTyping} are rewritten with @const@.
     261A typed enumeration has an implicit (safe) conversion to its base type.
     262\begin{lstlisting}
     263char currency = Dollar;
     264string fred = Fred;                                             $\C{// implicit conversion from char * to \CFA string type}$
     265Person student = Beth;
    204266\end{lstlisting}
    205267
     
    223285        enum( @_Complex@ ) Plane { X = 1.5+3.4i, Y = 7+3i, Z = 0+0.5i };
    224286// pointer
    225         enum( @char *@ ) Names { Fred = "Fred", Mary = "Mary", Jane = "Jane" };
     287        enum( @char *@ ) Names { Fred = "FRED", Mary = "MARY", Jane = "JANE" };
    226288        int i, j, k;
    227289        enum( @int *@ ) ptr { I = &i,  J = &j,  K = &k };
    228290        enum( @int &@ ) ref { I = i,   J = j,   K = k };
    229291// tuple
    230         enum( @[int, int]@ ) { T = [ 1, 2 ] };
     292        enum( @[int, int]@ ) { T = [ 1, 2 ] }; $\C{// new \CFA type}$
    231293// function
    232294        void f() {...}   void g() {...}
     
    234296// aggregate
    235297        struct Person { char * name; int age, height; };
    236         enum( @Person@ ) friends { Liz = { "Elizabeth", 22, 170 }, Beth = Liz, Jon = { "Jonathan", 35, 190 } };
     298@***@enum( @Person@ ) friends { @Liz@ = { "ELIZABETH", 22, 170 }, @Beth@ = Liz, Jon = { "JONATHAN", 35, 190 } };
    237299\end{lstlisting}
    238300\caption{Enumerator Typing}
     
    240302\end{figure}
    241303
     304Typed enumerations deals with the \emph{harmonizing} problem between an enumeration and any companion data.
     305The following example is from the \CFA compiler, written in \CC.
     306\begin{lstlisting}
     307enum integral_types { chr, schar, uschar, sshort, ushort, sint, usint, ..., NO_OF_ITYPES };
     308char * integral_names[NO_OF_ITYPES] = {
     309        "char", "signed char", "unsigned char",
     310        "signed short int", "unsigned short int",
     311        "signed int", "unsigned int",
     312        ...
     313};
     314\end{lstlisting}
     315The \emph{harmonizing} problem occurs because the enumeration declaration is in one header file and the names are declared in another translation unit.
     316It is up to the programmer to ensure changes made in one location are harmonized with the other location (by identifying this requirement within a comment).
     317The typed enumeration largely solves this problem by combining and managing the two data types.
     318\begin{lstlisting}
     319enum( char * ) integral_types {
     320        chr = "char", schar = "signed char", uschar = "unsigned char",
     321        sshort = "signed short int", ushort = "unsigned short int",
     322        sint = "signed int", usint = "unsigned int",
     323        ...
     324};
     325\end{lstlisting}
     326Note, the enumeration type can be a structure (see @Person@ in Figure~\ref{f:EumeratorTyping}), so it is possible to have the equivalent of multiple arrays of companion data using an array of structures.
     327
     328
    242329\subsection{Pure Enumerators}
    243330
    244 An empty type, @enum()@, implies the enumerators are pure symbols without values;
     331An empty enumerator type, @enum()@, implies the enumerators are pure symbols without values but set properties;
    245332hence, there is no default conversion to @int@.
    246333
    247334\begin{lstlisting}
    248335enum() Mode { O_RDONLY, O_WRONLY, O_CREAT, O_TRUNC, O_APPEND };
    249 Mode iomode = O_RDONLY;
     336@***@Mode iomode = O_RDONLY;
     337bool b = iomode == O_RDONLY || iomode < O_APPEND;
    250338int i = iomode;                                                 $\C{\color{red}// disallowed}$
    251 sout | O_TRUNC;                                                 $\C{\color{red}// disallowed}$
    252339\end{lstlisting}
    253340
    254341\subsection{Enumerator Subset}
    255342
    256 If follows from enumerator typing that the type of the enumerators can be another enumerator.
    257 \begin{lstlisting}
     343If follows from enumerator typing that the enumerator type can be another enumerator.
     344\begin{lstlisting}
     345enum( @char@ ) Currency { Dollar = '$\textdollar$', Euro = '$\texteuro$', Pound = '$\textsterling$'  };
     346enum( @Currency@ ) Europe { Euro = Currency.Euro, Pound = Currency.Pound }; // intersection
    258347enum( char ) Letter { A = 'A',  B = 'B', C = 'C', ..., Z = 'Z' };
    259 enum( Letter ) Greek { Alph = A, Beta = B, ..., Zeta = Z }; // alphabet intersection
     348enum( @Letter@ ) Greek { Alph = A, Beta = B, ..., Zeta = Z }; // intersection
     349\end{lstlisting}
     350Subset enumerations may have more or less enumerators than their typed enumeration, but the enumerator values must be from the typed enumeration.
     351For example, @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@.
     352\begin{lstlisting}
    260353Letter letter = A;
    261 Greak greek = Alph;
    262 letter = Alph;                                                  $\C{// allowed}$
     354@***@Greak greek = Beta;
     355letter = Beta;                                                  $\C{// allowed, letter == B}$
    263356greek = A;                                                              $\C{\color{red}// disallowed}$
    264357\end{lstlisting}
    265 Enumeration @Greek@ may have more or less enumerators than @Letter@, but the enumerator values must be from @Letter@.
    266 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@.
     358
    267359
    268360\subsection{Enumeration Inheritance}
    269361
    270 \CFA Plan-9 inheritance may be used with enumerations.
    271 \begin{lstlisting}
    272 enum( char * ) Name2 { @inline Name@, Jack = "Jack", Jill = "Jill" };
    273 enum /* inferred */ Name3 { @inline Name2@, Sue = "Sue", Tom = "Tom" };
    274 \end{lstlisting}
    275 Enumeration @Name2@ inherits all the enumerators and their values from enumeration @Name@ by containment, and a @Name@ enumeration is a subtype of enumeration @Name2@.
     362\CFA Plan-9 inheritance may be used with enumerations, where Plan-9 inheritance is containment inheritance with implicit unscoping (like a nested unnamed @struct@/@union@ in C).
     363\begin{lstlisting}
     364enum( char * ) Names { /* as above */ };
     365enum( char * ) Names2 { @inline Names@, Jack = "JACK", Jill = "JILL" };
     366@***@enum /* inferred */ Names3 { @inline Names2@, Sue = "SUE", Tom = "TOM" };
     367\end{lstlisting}
     368Enumeration @Name2@ inherits all the enumerators and their values from enumeration @Names@ by containment, and a @Names@ enumeration is a subtype of enumeration @Name2@.
    276369Note, enumerators must be unique in inheritance but enumerator values may be repeated.
    277370
    278371The enumeration type for the inheriting type must be the same as the inherited type;
    279372hence the enumeration type may be omitted for the inheriting enumeration and it is inferred from the inherited enumeration, as for @Name3@.
    280 When inheriting from integral types, automatic numbering may be used, so the inheritance placement left to right is important.
    281 
    282 Specifically, the inheritance relationship for Names is:
    283 \begin{lstlisting}
    284 Name $\(\subset\)$ Name2 $\(\subset\)$ Name3 $\(\subset\)$ const char *         // enum type of Name
     373% When inheriting from integral types, automatic numbering may be used, so the inheritance placement left to right is important.
     374Specifically, the inheritance relationship for @Names@ is:
     375\begin{lstlisting}
     376Names $\(\subset\)$ Names2 $\(\subset\)$ Names3 $\(\subset\)$ const char * $\C{// enum type of Names}$
    285377\end{lstlisting}
    286378For the given function prototypes, the following calls are valid.
     
    288380\begin{tabular}{ll}
    289381\begin{lstlisting}
    290 void f( Name );
    291 void g( Name2 );
    292 void h( Name3 );
     382void f( Names );
     383void g( Names2 );
     384void h( Names3 );
    293385void j( const char * );
    294386\end{lstlisting}
     
    298390g( Fred );   g( Jill );
    299391h( Fred );   h( Jill );   h( Sue );
    300 j( Fred );   j( Jill );   j( Sue );   j( "Will" );
     392j( Fred );   j( Jill );   j( Sue );   j( "WILL" );
    301393\end{lstlisting}
    302394\end{tabular}
    303395\end{cquote}
    304 Note, the validity of calls is the same for call-by-reference as for call-by-value, and const restrictions are the same as for other types.
    305 
    306 \subsection{Enumerator Scoping}
    307 
    308 A \CFA-enum can be scoped, meaning the enumerator constants are not projected into the enclosing scope.
    309 \begin{lstlisting}
    310 enum Weekday @!@ { /* as above */ };
    311 enum Colour( char * ) @!@ { /* as above */ };
    312 \end{lstlisting}
    313 where the @'!'@ implies the enumerators are \emph{not} projected.
    314 The enumerators of a scoped enumeration are accessed using qualifications, like the fields of an aggregate.
    315 % The syntax of $qualified\_expression$ for \CFA-enum is the following:
    316 % $$<qualified\_expression> := <enum\_type>.<enumerator>$$
    317 \begin{lstlisting}
    318 Weekday weekday = @Weekday.Monday@;             $\C{// qualification}$
    319 Colour colour = @Colour.@Red;
    320 colour = @Colour.@Blue;
    321 \end{lstlisting}
     396Note, the validity of calls is the same for call-by-reference as for call-by-value, and @const@ restrictions are the same as for other types.
     397
    322398
    323399\subsection{Enumeration Pseudo-functions}
    324400
    325 Pseudo-functions are function-like operators that do not result in any run-time computations, i.e., like @sizeof@.
     401Pseudo-functions are function-like operators that do not result in any run-time computations, i.e., like @sizeof@, @offsetof@, @typeof@.
    326402Often 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..
    327403
    328 \subsubsection{Enumerator Attributes}
    329404The attributes of an enumerator are accessed by pseudo-functions @position@, @value@, and @label@.
    330405\begin{lstlisting}
    331 int green_pos = @position@( Colour.Green );     $\C{// 1}$
    332 char * green_value = @value@( Colour.Green ); $\C{// "G"}$
    333 char * green_label = @label@( Colour.Green ); $\C{// "Green"}$
    334 \end{lstlisting}
    335 
    336 Enumeration Greek may have more or less enumerators than Letter, but the enumerator values must be from Letter.
    337 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.
    338 
    339 % An instance of \CFA-enum (denoted as @<enum_instance>@) is a label for the defined enum name.
    340 % The label can be retrieved by calling the function @label( <enum_instance> )@.
    341 % Similarly, the @value()@ function returns the value used to initialize the \CFA-enum.
    342 
    343 \subsubsection{\lstinline{enumerate()}}
    344 
    345 \begin{lstlisting}[label=lst:c_switch]
    346 enum(int) C_ENUM { First, Second, Third = First, Fourth };
    347 int v( C_ENUM e ) {
    348         switch( e ) {
    349                 case First: return 0; break;
    350                 case Second: return 1; break;
    351                 // case Third: return 2; break;
    352                 // case Fourth: return 3; break;
    353         };
    354 };
    355 \end{lstlisting}
    356 In the @C_ENUM@ example, @Third@ is an alias of @First@ and @Fourth@ is an alias of @Second@.
    357 Programmers cannot make case branches for @Third@ and @Fourth@ because the switch statement matches cases by the enumerator's value.
    358 Case @First@ and @Third@, or @Second@ and @Fourth@, has duplicate case values.
    359 
    360 @enumerate()@ is a pseudo-function that makes the switch statement match by an enumerator instead.
    361 \begin{lstlisting}[label=lst:c_switch_enumerate]
    362 enum(double) C_ENUM { First, Second, Third = First, Fourth };
    363 C_ENUM variable_a = First, variable_b = Second, variable_c = Third, variable_d = Fourth;
    364 int v(C_ENUM e) {
    365         switch( enumeratate( e ) ) {
    366                 case First: return e; break;
    367                 case Second: return value( e ); break;
    368                 case Third: return label( e ); break;
    369                 case Fourth: return position( e ); break;
    370         };
    371 };
     406@***@int jane_pos = @position@( Names.Jane );   $\C{// 2}$
     407@***@char * jane_value = @value@( Names.Jane ); $\C{// "JANE"}$
     408@***@char * jane_label = @label@( Names.Jane ); $\C{// "Jane"}$
     409sout | @label@( Names.Jane ) | @value@( Names.Jane );
     410\end{lstlisting}
     411Note the ability to print both enumerator label and value.
     412
     413
     414\subsection{Enumerator Position or Value}
     415
     416Enumerators can be used in multiple contexts.
     417In most programming languages, an enumerator is implicitly converted to its value (like a typed macro substitution).
     418However, enumerator synonyms and typed enumerations make this implicit conversion to value incorrect in some contexts.
     419In these contexts, a programmer's initition assumes an implicit conversion to postion.
     420
     421For example, an intuitive use of enumerations is with the \CFA @switch@/@choose@ statement, where @choose@ performs an implict @break@ rather than a fall-through at the end of a @case@ clause.
     422\begin{cquote}
     423\begin{lstlisting}
     424enum Count { First, Second, Third, Fourth };
     425Count e;
     426\end{lstlisting}
     427\begin{tabular}{ll}
     428\begin{lstlisting}
     429
     430choose( e ) {
     431        case @First@: ...;
     432        case @Second@: ...;
     433        case @Third@: ...;
     434        case @Fourth@: ...;
     435}
     436\end{lstlisting}
     437&
     438\begin{lstlisting}
     439// rewrite
     440choose( @value@( e ) ) {
     441        case @value@( First ): ...;
     442        case @value@( Second ): ...;
     443        case @value@( Third ): ...;
     444        case @value@( Fourth ): ...;
     445}
     446\end{lstlisting}
     447\end{tabular}
     448\end{cquote}
     449Here, the intuitive code on the left is implicitly transformed into the statndard implementation on the right, using the value of the enumeration variable and enumerators.
     450However, this implementation is fragile, e.g., if the enumeration is changed to:
     451\begin{lstlisting}
     452enum Count { First, Second, Third @= First@, Fourth };
     453\end{lstlisting}
     454which make @Third == First@ and @Fourth == Second@, causing a compilation error because of duplicase @case@ clauses.
     455To better match with programmer intuition, \CFA toggles between value and position semantics depneding on the language context.
     456For conditional clauses and switch statments, \CFA uses the robust position implementation.
     457\begin{lstlisting}
     458choose( @position@( e ) ) {
     459        case @position@( First ): ...;
     460        case @position@( Second ): ...;
     461        case @position@( Third ): ...;
     462        case @position@( Fourth ): ...;
     463}
     464\end{lstlisting}
     465
     466\begin{lstlisting}
     467Count variable_a = First, variable_b = Second, variable_c = Third, variable_d = Fourth;
    372468p(variable_a); // 0
    373469p(variable_b); // 1
     
    10151111If the @aggregation_name@ is identified as a \CFA enumeration, the compiler checks if @field@ presents in the declared \CFA enumeration.
    10161112
    1017 \subsection{\lstinline{with} Clause/Statement}
    1018 
    1019 Instead of qualifying an enumeration expression every time, the @with@ can be used to expose enumerators to the current scope, making them directly accessible.
    1020 \begin{lstlisting}[label=lst:declaration]
    1021 enum Color( char * ) { Red="R", Green="G", Blue="B" };
    1022 enum Animal( int ) { Cat=10, Dog=20 };
    1023 with ( Color, Animal ) {
    1024         char * red_string = Red; // value( Color.Red )
    1025         int cat = Cat; // value( Animal.Cat )
    1026 }
    1027 \end{lstlisting}
    1028 The \lstinline{with} might introduce ambiguity to a scope. Consider the example:
    1029 \begin{lstlisting}[label=lst:declaration]
    1030 enum Color( char * ) { Red="R", Green="G", Blue="B" };
    1031 enum RGB( int ) { Red=0, Green=1, Blue=2 };
    1032 with ( Color, RGB ) {
    1033         // int red = Red;
    1034 }
    1035 \end{lstlisting}
    1036 \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.
    1037 
    10381113\subsection{Instance Declaration}
    10391114
     
    12181293
    12191294\subsection{\CC}
    1220 
    1221 \CC is backwards compatible with C, so it inherited C's enumerations, except there is no implicit conversion from an integral value to an enumeration;
    1222 hence, the values in a \CC enumeration can only be its enumerators (without a cast).
    1223 There is no mechanism to iterate through an enumeration.
    1224 
    1225 \CC{11} added a scoped enumeration, \lstinline[language=c++]{enum class} (or \lstinline[language=c++]{enum struct}), so the enumerators are local to the enumeration and must be accessed using type qualification, e.g., @Weekday::Monday@.
     1295\label{s:C++RelatedWork}
     1296
     1297\CC is backwards compatible with C, so it inherited C's enumerations.
     1298However, the following non-backwards compatible changes have been made.
     1299\begin{quote}
     13007.2 Change: \CC objects of enumeration type can only be assigned values of the same enumeration type.
     1301In C, objects of enumeration type can be assigned values of any integral type. \\
     1302Example:
     1303\begin{lstlisting}
     1304enum color { red, blue, green };
     1305color c = 1;                                                    $\C{// valid C, invalid C++}$
     1306\end{lstlisting}
     1307\textbf{Rationale}: The type-safe nature of C++. \\
     1308\textbf{Effect on original feature}: Deletion of semantically well-defined feature. \\
     1309\textbf{Difficulty of converting}: Syntactic transformation. (The type error produced by the assignment can be automatically corrected by applying an explicit cast.) \\
     1310\textbf{How widely used}: Common.
     1311\end{quote}
     1312\begin{quote}
     13137.2 Change: In \CC, the type of an enumerator is its enumeration.
     1314In C, the type of an enumerator is @int@. \\
     1315Example:
     1316\begin{lstlisting}
     1317enum e { A };
     1318sizeof(A) == sizeof(int)                                $\C{// in C}$
     1319sizeof(A) == sizeof(e)                                  $\C{// in C++}$
     1320/* and sizeof(int) is not necessary equal to sizeof(e) */
     1321\end{lstlisting}
     1322\textbf{Rationale}: In C++, an enumeration is a distinct type. \\
     1323\textbf{Effect on original feature}: Change to semantics of well-defined feature. \\
     1324\textbf{Difficulty of converting}: Semantic transformation. \\
     1325\textbf{How widely used}: Seldom. The only time this affects existing C code is when the size of an enumerator is taken.
     1326Taking the size of an enumerator is not a common C coding practice.
     1327\end{quote}
     1328Hence, the values in a \CC enumeration can only be its enumerators (without a cast).
     1329While the storage size of an enumerator is up to the compiler, there is still an implicit cast to @int@.
     1330\begin{lstlisting}
     1331enum E { A, B, C };
     1332E e = A;
     1333int i = A;   i = e;                                             $\C{// implicit casts to int}$
     1334\end{lstlisting}
     1335\CC{11} added a scoped enumeration, \lstinline[language=c++]{enum class} (or \lstinline[language=c++]{enum struct}), so the enumerators are local to the enumeration and must be accessed using type qualification.
     1336\begin{lstlisting}[language=c++,{moredelim=**[is][\color{red}]{@}{@}}]
     1337enum class E { A, B, C };
     1338E e = @E::@A;                                                   $\C{// qualified enumerator}$
     1339e = B;                                                                  $\C{// B not in scope}$
     1340\end{lstlisting}
    12261341\CC{20} supports unscoped access with a \lstinline[language=c++]{using enum} declaration.
    1227 
    1228 For both unscoped and scoped enumerations, the underlying type is an implementation-defined integral type large enough to hold all enumerated values; it does not have to be the smallest possible type.
    1229 In \CC{11}, the underlying integral type can be explicitly specified:
    12301342\begin{lstlisting}[language=c++,{moredelim=**[is][\color{red}]{@}{@}}]
    1231 enum class RGB : @long@ { Red, Green, Blue };
    1232 enum class rgb : @char@ { Red = 'r', Green = 'g', Blue = 'b' };
    1233 enum class srgb : @signed char@ { Red = -1, Green = 0, Blue = 1 };
    1234 RGB colour1 = @RGB::@Red;
    1235 rgb colour2 = @rgb::@Red;
    1236 srgb colour3 = @srgb::@Red;
    1237 \end{lstlisting}
     1343enum class E { A, B, C };
     1344@using enum E;@
     1345E e = A;                                                                $\C{// direct access}$
     1346e = B;                                                                  $\C{// direct access}$
     1347\end{lstlisting}
     1348\CC{11} added the ability to explicitly declare the underlying integral type for \lstinline[language=c++]{enum class}.
     1349\begin{lstlisting}[language=c++,{moredelim=**[is][\color{red}]{@}{@}}]
     1350enum class RGB @: long@ { Red, Green, Blue };
     1351enum class rgb @: char@ { Red = 'r', Green = 'g', Blue = 'b' };
     1352enum class srgb @: signed char@ { Red = -1, Green = 0, Blue = 1 };
     1353\end{lstlisting}
     1354There is no implicit conversion from the \lstinline[language=c++]{enum class} type and to its type.
     1355\begin{lstlisting}[language=c++,{moredelim=**[is][\color{red}]{@}{@}}]
     1356rgb crgb = rgb::Red;
     1357char ch = rgb::Red;   ch = crgb;                $\C{// disallowed}$
     1358\end{lstlisting}
     1359Finally, there is no mechanism to iterate through an enumeration nor use the enumeration type to declare an array dimension.
     1360
    12381361
    12391362\subsection{Go}
  • doc/theses/jiada_liang_MMath/background.tex

    r0522ebe ra4da45e  
    11\chapter{Background}
     2
     3
     4\section{C-Style Enum}
     5
     6The C-Style enumeration has the following syntax and semantics.
     7\begin{cfa}
     8enum Weekday { Monday, Tuesday, Wednesday, Thursday@ = 10@, Friday, Saturday, Sunday };
     9\end{cfa}
     10Enumerators without an explicitly designated constant value are \Newterm{auto-initialized} by the compiler: from left to right, starting at zero or the next explicitly initialized constant, incrementing by @1@.
     11For example, @Monday@ to @Wednesday@ are implicitly assigned with constants @0@--@2@, @Thursday@ is explicitly set to constant @10@, and @Friday@ to @Sunday@ are implicitly assigned with constants @11@--@13@.
     12Initialization may occur in any order.
     13\begin{cfa}
     14enum Weekday { Thursday@ = 10@, Friday, Saturday, Sunday, Monday@ = 0@, Tuesday, Wednesday };
     15\end{cfa}
     16Note, the comma in the enumerator list can be a terminator or a separator, allowing the list to end with a dangling comma.
     17\begin{cfa}
     18enum Weekday {
     19        Thursday = 10, Friday, Saturday, Sunday,
     20        Monday = 0, Tuesday, Wednesday@,@ // terminating comma
     21};
     22\end{cfa}
     23This feature allow enumerator lines to be interchanged without moving a comma.\footnote{
     24A terminating comma appears in other C syntax, \eg the initializer list.}
     25Finally, C enumerators are \Newterm{unscoped}, \ie enumerators declared inside of an @enum@ are visible (projected) into the enclosing scope of the @enum@ type.
     26
     27In theory, a C enumeration \emph{variable} is an implementation-defined integral type large enough to hold all enumerated values.
     28In practice, since integral constants are used, which have type @int@ (unless qualified with a size suffix), C uses @int@ as the underlying type for enumeration variables.
     29Finally, there is an implicit bidirectional conversion between an enumeration and its integral type.
     30\begin{cfa}
     31{
     32        enum Weekday { /* as above */ };        $\C{// enumerators implicitly projected into local scope}$
     33        Weekday weekday = Monday;                       $\C{// weekday == 0}$
     34        weekday = Friday;                                       $\C{// weekday == 11}$
     35        int i = Sunday;                                         $\C{// implicit conversion to int, i == 13}$
     36        weekday = 10000;                                        $\C{// UNDEFINED! implicit conversion to Weekday}$
     37}
     38int j = Wednesday;                                              $\C{// ERROR! Wednesday is not declared in this scope}$
     39\end{cfa}
     40The implicit conversion from @int@ to an enumeration type is an unnecessary source of error.
     41
     42It is common for C programmers to ``believe'' there are 3 equivalent forms of constant enumeration.
     43\begin{cfa}
     44#define Monday 0
     45static const int Monday = 0;
     46enum { Monday };
     47\end{cfa}
     48For @#define@, the programmer has to play compiler and explicitly manage the enumeration values;
     49furthermore, these are independent constants outside of any language type mechanism.
     50The same explicit management is true for @const@ declarations, and the @const@ variable cannot appear in constant-expression locations, like @case@ labels, array dimensions,\footnote{
     51C allows variable-length array-declarations (VLA), so this case does work, but it fails in \CC, which does not support VLAs, unless it is \lstinline{g++}.} and immediate operands of assembler instructions.
     52Only the @enum@ form is managed by the compiler, is part of the language type-system, and works in all C constant-expression locations.
  • doc/theses/jiada_liang_MMath/intro.tex

    r0522ebe ra4da45e  
    11\chapter{Introduction}
    22
    3 Testing glossy abbreviations \gls{foo} and \gls{bar}, and glossy definitions \gls{git} and \gls{gulp}.
     3Naming values is a common practice in mathematics and engineering, \eg $\pi$, $\tau$ (2$\pi$), $\phi$ (golden ratio), MHz (1E6), etc.
     4Naming 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), specific times (noon, New Years).
     5Many programming languages capture this important software engineering capability through a mechanism called an \Newterm{enumeration}.
     6An 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.
     7Note, all enumeration names must be unique but different names can represent the same value (eight note, quaver), which are synonyms.
    48
    5 And use the glossy abbreviations \gls{foo} and \gls{bar}, and definitions \gls{git} and \gls{gulp} again.
     9Specifically, an enumerated type restricts its values to a fixed set of named constants.
     10While 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, \eg @3@, @3.5@, @3.5+2.1i@, @'c'@, @"abc"@, etc., these values are not named, other than the programming-language supplied constant names.
     11
     12Fundamentally, all enumeration systems have an \Newterm{enumeration} type with an associated set of \Newterm{enumerator} names.
     13An enumeration has three universal attributes, \Newterm{position}, \Newterm{label}, and \Newterm{value}, as shown by this representative enumeration, where position and value can be different.
     14\begin{cquote}
     15\small\sf\setlength{\tabcolsep}{3pt}
     16\begin{tabular}{rccccccccccc}
     17\it\color{red}enumeration & \multicolumn{7}{c}{\it\color{red}enumerators}       \\
     18$\downarrow$\hspace*{25pt} & \multicolumn{7}{c}{$\downarrow$}                           \\
     19@enum@ Weekday \{                               & Monday,       & Tuesday,      & Wednesday,    & Thursday,& Friday,    & Saturday,     & Sunday \}; \\
     20\it\color{red}position                  & 0                     & 1                     & 2                             & 3                             & 4                     & 5                     & 6                     \\
     21\it\color{red}label                             & Monday        & Tuesday       & Wednesday             & Thursday              & Friday        & Saturday      & Sunday        \\
     22\it\color{red}value                             & 0                     & 1                     & 2                             & 3                             & 4                     & 5             & 6
     23\end{tabular}
     24\end{cquote}
     25Here, the \Newterm{enumeration} @Weekday@ defines the ordered \Newterm{enumerator}s @Monday@, @Tuesday@, @Wednesday@, @Thursday@, @Friday@, @Saturday@ and @Sunday@.
     26By convention, the successor of @Tuesday@ is @Monday@ and the predecessor of @Tuesday@ is @Wednesday@, independent of the associated enumerator constant values.
     27Because an enumerator is a constant, it cannot appear in a mutable context, \eg @Mon = Sun@ is meaningless, and an enumerator has no address, it is an \Newterm{rvalue}\footnote{
     28The term rvalue defines an expression that can only appear on the right-hand side of an assignment.}.
     29
     30\section{Contributions}
  • doc/theses/jiada_liang_MMath/uw-ethesis-frontpgs.tex

    r0522ebe ra4da45e  
    131131\begin{center}\textbf{Abstract}\end{center}
    132132
    133 Enumerated type ...
     133An enumeration is a type defining an ordered set of named constant values, where a name abstracts a value, \eg @PI@ versus @3.145159@.
     134C restrict an enumeration type to the integral type @signed int@, which \CC support , meaning enumeration names bind to integer constants.
     135\CFA extends C enumerations to allow all basic and custom types for the enumeration type, like other modern programming languages.
     136Furthermore, \CFA adds other useful features for enumerations to support better software-engineering practices and simplify program development.
    134137
    135138\cleardoublepage
  • doc/theses/jiada_liang_MMath/uw-ethesis.tex

    r0522ebe ra4da45e  
    9191% cfa macros used in the document
    9292\input{common}
    93 %\usepackageinput{common}
     93%\usepackage{common}
    9494\CFAStyle                                               % CFA code-style
    95 \lstset{language=CFA}                                   % default language
    96 \lstset{basicstyle=\linespread{0.9}\sf}                 % CFA typewriter font
     95\lstset{language=cfa,belowskip=-1pt}                                    % set default language to CFA
     96
    9797\newcommand{\newtermFont}{\emph}
    9898\newcommand{\Newterm}[1]{\newtermFont{#1}}
     
    211211\input{intro}
    212212\input{background}
    213 \input{content1}
    214 \input{content2}
     213\input{CFAenum}
     214\input{implementation}
     215\input{relatedwork}
    215216\input{performance}
    216217\input{conclusion}
  • doc/user/user.tex

    r0522ebe ra4da45e  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Tue Jan 30 09:02:41 2024
    14 %% Update Count     : 6046
     13%% Last Modified On : Mon Feb 12 11:50:26 2024
     14%% Update Count     : 6199
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    41774177The \CFA header file for the I/O library is \Indexc{fstream.hfa}.
    41784178
     4179
     4180\subsubsection{Stream Output}
     4181
    41794182For implicit formatted output, the common case is printing a series of variables separated by whitespace.
    41804183\begin{cquote}
     
    42554258Note, \CFA stream variables ©stdin©, ©stdout©, ©stderr©, ©exit©, and ©abort© overload C variables ©stdin©, ©stdout©, ©stderr©, and functions ©exit© and ©abort©, respectively.
    42564259
     4260
     4261\subsubsection{Stream Input}
     4262
    42574263For implicit formatted input, the common case is reading a sequence of values separated by whitespace, where the type of an input constant must match with the type of the input variable.
    42584264\begin{cquote}
    42594265\begin{lrbox}{\myboxA}
    42604266\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    4261 int x;   double y   char z;
     4267char c;   int i;   double d
    42624268\end{cfa}
    42634269\end{lrbox}
     
    42664272\multicolumn{1}{c@{\hspace{2em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{\CC}}       & \multicolumn{1}{c}{\textbf{Python}}   \\
    42674273\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    4268 sin | x | y | z;
     4274sin | c | i | d;
    42694275\end{cfa}
    42704276&
    42714277\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    4272 cin >> x >> y >> z;
     4278cin >> c >> i >> d;
    42734279\end{cfa}
    42744280&
    42754281\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    4276 x = int(input());  y = float(input());  z = input();
     4282c = input();   i = int(input());   d = float(input());
    42774283\end{cfa}
    42784284\\
    42794285\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    4280 ®1® ®2.5® ®A®
     4286®A® ®1® ®2.5®
    42814287
    42824288
     
    42844290&
    42854291\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    4286 ®1® ®2.5® ®A®
     4292®A® ®1® ®2.5®
    42874293
    42884294
     
    42904296&
    42914297\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     4298®A®
    42924299®1®
    42934300®2.5®
    4294 ®A®
    42954301\end{cfa}
    42964302\end{tabular}
     
    43094315For floating-point types, any number of decimal digits, optionally preceded by a sign (©+© or ©-©), optionally containing a decimal point, and optionally followed by an exponent, ©e© or ©E©, with signed (optional) decimal digits.
    43104316Floating-point values can also be written in hexadecimal format preceded by ©0x© or ©0X© with hexadecimal digits and exponent denoted by ©p© or ©P©.
    4311 In all cases, all whitespace characters are skipped until an appropriate value is found.
    4312 \Textbf{If an appropriate value is not found, the exception ©missing_data© is raised.}
    4313 
    4314 For the C-string type, there are two input forms: any number of \Textbf{non-whitespace} characters or a quoted sequence containing any characters except the closing quote, \ie there is no escape character supported in the string..
    4315 In both cases, the string is null terminated ©'\0'©.
    4316 For the quoted string, the start and end quote characters can be any character and do not have to match \see{\ref{XXX}}.
    4317 
    4318 \VRef[Figure]{f:IOStreamFunctions} shows the I/O stream operations for interacting with files other than ©cin©, ©cout©, and ©cerr©.
     4317In all cases, whitespace characters are skipped until an appropriate value is found.
     4318\begin{cfa}[belowskip=0pt]
     4319char ch;  int i;  float f; double d;  _Complex double cxd;
     4320sin | ch | i | f | d | cxd;
     4321X   42   1234.5     0xfffp-2    3.5+7.1i
     4322\end{cfa}
     4323It is also possible to scan and ignore specific strings and whitespace using a string format.
     4324\begin{cfa}[belowskip=0pt]
     4325sin | "abc def";                                                §\C{// space matches arbitrary whitespace (2 blanks, 2 tabs)}§
     4326\end{cfa}
     4327\begin{cfa}[showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt]
     4328®abc            def®
     4329\end{cfa}
     4330A non-whitespace format character reads the next input character, compares the format and input characters, and if equal, the input character is discarded and the next format character is tested.
     4331Note, a single whitespace in the format string matches \Textbf{any} quantity of whitespace characters from the stream (including none).
     4332
     4333For the C-string type, the default input format is any number of \Textbf{non-whitespace} characters.
     4334There is no escape character supported in an input string, but any Latin-1 character can be typed directly in the input string.
     4335For example, if the following non-whitespace output is redirected into a file by the shell:
     4336\begin{cfa}[belowskip=0pt]
     4337sout | "\n\t\f\0234\x23";
     4338\end{cfa}
     4339it can be read back from the file by redirecting the file as input using:
     4340\begin{cfa}[belowskip=0pt]
     4341char s[64];
     4342sin | wdi( sizeof(s), s );                              §\C{// must specify string size}§
     4343\end{cfa}
     4344The input string is always null terminated ©'\0'© in the input variable.
     4345Because of potential buffer overrun when reading C strings, strings are restricted to work with input manipulators \see{\VRef{s:InputManipulators}}.
     4346As well, there are multiple input-manipulators for scanning complex input string formats, \eg a quoted character or string.
     4347
     4348\Textbf{In all cases, if an invalid data value is not found for a type or format string, the exception ©missing_data© is raised and the input variable is unchanged.}
     4349For example, when reading an integer and the string ©"abc"© is found, the exception ©missing_data© is raised to ensure the program does not proceed erroneously.
     4350If a valid data value is found, but it is larger than the capacity of the input variable, such reads are undefined.
     4351
     4352
     4353\subsubsection{Stream Files}
     4354
     4355\VRef[Figure]{f:IOStreamFunctions} shows the I/O stream operations for interacting with files other than ©sin©, ©sout©, and ©cerr©.
    43194356\begin{itemize}[topsep=4pt,itemsep=2pt,parsep=0pt]
    43204357\item
     
    49324969
    49334970\subsection{Input Manipulators}
    4934 
    4935 The following \Index{manipulator}s control scanning of input values (reading), and only affect the format of the argument.
    4936 
    4937 Certain manipulators support a \newterm{scanset}, which is a simple regular expression, where the matching set contains any Latin-1 character (8-bits) or character ranges using minus.
     4971\label{s:InputManipulators}
     4972
     4973A string variable \emph{must} be large enough to contain the input sequence.
     4974To force programmers to consider buffer overruns for C-string input, C-strings may only be read with a width field, which should specify a size less than or equal to the C-string size, \eg:
     4975\begin{cfa}
     4976char line[64];
     4977sin | wdi( ®sizeof(line)®, line );              §\C{// must specify string size}§
     4978\end{cfa}
     4979
     4980Certain input manipulators support a \newterm{scanset}, which is a simple regular expression, where the matching set contains any Latin-1 character (8-bits) or character ranges using minus.
    49384981For example, the scanset \lstinline{"a-zA-Z -/?§"} matches any number of characters between ©'a'© and ©'z'©, between ©'A'© and ©'Z'©, between space and ©'/'©, and characters ©'?'© and (Latin-1) ©'§'©.
    49394982The following string is matched by this scanset:
    49404983\begin{cfa}
    4941 !&%$  abAA () ZZZ  ??  xx§\S\S\S§
    4942 \end{cfa}
    4943 To match a minus, put it as the first character, ©"-0-9"©.
    4944 Other complex forms of regular-expression matching are not supported.
    4945 
    4946 A string variable \emph{must} be large enough to contain the input sequence.
    4947 To force programmers to consider buffer overruns for C-string input, C-strings can only be read with a width field, which should specify a size less than or equal to the C-string size, \eg:
    4948 \begin{cfa}
    4949 char line[64];
    4950 sin | wdi( ®sizeof(line)®, line ); // must specify size
    4951 \end{cfa}
    4952 
    4953 Currently, there is no mechanism to detect if a value read exceeds the capwhen Most types are finite sized, \eg integral types only store value that fit into their corresponding storage, 8, 16, 32, 64, 128 bits.
    4954 Hence, an input value may be too large, and the result of the read is often considered undefined, which leads to difficlt to locate runtime errors.
    4955 All reads in \CFA check if values do not fit into the argument variable's type and raise the exception
    4956 All types are
     4984!&%$  abAA () ZZZ  ??§\S§  xx§\S\S§
     4985\end{cfa}
     4986To match a minus, make it the first character in the set, \eg ©"©{\color{red}\raisebox{-1pt}{\texttt{-}}}©0-9"©.
     4987Other complex forms of regular-expression matching are unsupported.
     4988
     4989The following \Index{manipulator}s control scanning of input values (reading) and only affect the format of the argument.
    49574990
    49584991\begin{enumerate}
    49594992\item
    4960 \Indexc{skip}( scanset )\index{manipulator!skip@©skip©}, ©skip©( $N$ )
    4961 The first form uses a scanset to skip matching characters.
    4962 The second form skips the next $N$ characters, including newline.
    4963 If the match successes, the input characters are discarded, and input continues with the next character.
     4993\Indexc{skip}( \textit{scanset} )\index{manipulator!skip@©skip©}, ©skip©( $N$ )
     4994consumes either the \textit{scanset} or the next $N$ characters, including newlines.
     4995If the match successes, the input characters are ignored, and input continues with the next character.
    49644996If the match fails, the input characters are left unread.
    49654997\begin{cfa}[belowskip=0pt]
    4966 char sk[§\,§] = "abc";
    4967 sin | "abc " | skip( sk ) | skip( 5 ); // match input sequence
     4998char scanset[§\,§] = "abc";
     4999sin | "abc§\textvisiblespace§" | skip( scanset ) | skip( 5 ); §\C{// match and skip input sequence}§
    49685000\end{cfa}
    49695001\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    4970 ®abc   ®
    4971 ®abc  ®
    4972 ®xx®
    4973 \end{cfa}
    4974 
    4975 \item
    4976 \Indexc{wdi}( maximum, variable )\index{manipulator!wdi@©wdi©}
    4977 For all types except ©char *©, whitespace is skipped until an appropriate value is found for the specified variable type.
    4978 maximum is the maximum number of characters read for the current operation.
     5002®abc   abc  xxx®
     5003\end{cfa}
     5004Again, the blank in the format string ©"abc©\textvisiblespace©"© matches any number of whitespace characters.
     5005
     5006\item
     5007\Indexc{wdi}( \textit{maximum}, ©T & v© )\index{manipulator!wdi@©wdi©}
     5008For all types except ©char *©, whitespace is skipped and the longest sequence of non-whitespace characters matching an appropriate typed (©T©) value is read, converted into its corresponding internal form, and written into the ©T© variable.
     5009\textit{maximum} is the maximum number of characters read for the current value rather than the longest sequence.
    49795010\begin{cfa}[belowskip=0pt]
    49805011char ch;   char ca[3];   int i;   double d;   
     
    49855016\end{cfa}
    49865017Here, ©ca[0]© is type ©char©, so the width reads 3 characters \Textbf{without} a null terminator.
     5018If an input value is not found for a variable, the exception ©missing_data© is raised, and the input variable is unchanged.
    49875019
    49885020Note, input ©wdi© cannot be overloaded with output ©wd© because both have the same parameters but return different types.
     
    49905022
    49915023\item
    4992 \Indexc{wdi}( maximum size, ©char s[]© )\index{manipulator!wdi@©wdi©}
    4993 For type ©char *©, maximum is the maximum number of characters read for the current operation.
    4994 Any number of non-whitespace characters, stopping at the first whitespace character found. A terminating null character is automatically added at the end of the stored sequence
     5024\Indexc{wdi}( $maximum\ size$, ©char s[]© )\index{manipulator!wdi@©wdi©}
     5025For type ©char *©, whitespace is skippped and the longest sequence of non-whitespace characters is read, without conversion, and written into the string variable (null terminated).
     5026$maximum\ size$ is the maximum number of characters in the string variable.
     5027If the non-whitespace sequence of input characters is greater than $maximum\ size - 1$ (null termination), the exception ©cstring_length© is raised.
    49955028\begin{cfa}[belowskip=0pt]
    4996 char cstr[10];
    4997 sin | wdi( sizeof(cstr), cstr );
     5029char cs[10];
     5030sin | wdi( sizeof(cs), cs );
    49985031\end{cfa}
    49995032\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    5000 ®abcd1233.456E+2®
    5001 \end{cfa}
    5002 
    5003 \item
    5004 \Indexc{wdi}( maximum size, maximum read, ©char s[]© )\index{manipulator!wdi@©wdi©}
    5005 For type ©char *©, maximum is the maximum number of characters read for the current operation.
     5033®012345678®
     5034\end{cfa}
     5035Nine non-whitespace character are read and the null character is added to make ten.
     5036
     5037\item
     5038\Indexc{wdi}( $maximum\ size$, $maximum\ read$, ©char s[]© )\index{manipulator!wdi@©wdi©}
     5039This manipulator is the same as the previous one, except $maximum$ $read$ is the maximum number of characters read for the current value rather than the longest sequence, where $maximum\ read$ $\le$ $maximum\ size$.
    50065040\begin{cfa}[belowskip=0pt]
    5007 char ch;   char ca[3];   int i;   double d;   
    5008 sin | wdi( sizeof(ch), ch ) | wdi( sizeof(ca), ca[0] ) | wdi( 3, i ) | wdi( 8, d );  // c == 'a', ca == "bcd", i == 123, d == 345.6
     5041char cs[10];
     5042sin | wdi( sizeof(cs), 9, cs );
    50095043\end{cfa}
    50105044\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    5011 ®abcd1233.456E+2®
    5012 \end{cfa}
    5013 
    5014 \item
    5015 \Indexc{ignore}( reference-value )\index{manipulator!ignore@©ignore©}
    5016 For all types, the data is read from the stream depending on the argument type but ignored, \ie it is not stored in the argument.
     5045®012345678®9
     5046\end{cfa}
     5047The exception ©cstring_length© is not raised, because the read stops reading after nine characters.
     5048
     5049\item
     5050\Indexc{getline}( $wdi\ manipulator$, ©const char delimiter = '\n'© )\index{manipulator!getline@©getline©}
     5051consumes the scanset ©"[^D]D"©, where ©D© is the ©delimiter© character, which reads all characters from the current input position to the delimiter character into the string (null terminated), and consumes and ignores the delimiter.
     5052If the delimiter character is omitted, it defaults to ©'\n'© (newline).
    50175053\begin{cfa}[belowskip=0pt]
    5018 double d;
    5019 sin | ignore( d );  // d is unchanged
     5054char cs[10];
     5055sin | getline( wdi( sizeof(cs), cs ) );
     5056sin | getline( wdi( sizeof(cs), cs ), 'X' ); §\C{// X is the line delimiter}§
    50205057\end{cfa}
    50215058\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    5022 ®  -75.35e-4® 25
    5023 \end{cfa}
    5024 
    5025 \item
    5026 \Indexc{incl}( scanset, wdi-input-string )\index{manipulator!incl@©incl©}
    5027 For C-string types only, the scanset matches any number of characters \emph{in} the set.
    5028 Matching characters are read into the C input-string and null terminated.
     5059®abc ?? #@%®
     5060®abc ?? #@%X® w
     5061\end{cfa}
     5062The same value is read for both input strings.
     5063
     5064\item
     5065\Indexc{quoted}( ©char & ch©, ©const char Ldelimiter = '\''©, ©const char Rdelimiter = '\0'© )\index{manipulator!quoted@©quoted©}
     5066consumes the string ©"LCR"©, where ©L© is the left ©delimiter© character, ©C© is the value in ©ch©, and ©R© is the right delimiter character, which skips whitespace, consumes and ignores the left delimiter, reads a single character into ©ch©, and consumes and ignores the right delimiter (3 characters).
     5067If the delimit character is omitted, it defaults to ©'\''© (single quote).
    50295068\begin{cfa}[belowskip=0pt]
    5030 char s[10];
    5031 sin | incl( "abc", s );
     5069char ch;
     5070sin | quoted( ch );   sin | quoted( ch, '"' );   sin | quoted( ch, '[', ']' );
     5071\end{cfa}
     5072\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     5073®   'a'  "a"[a]®
     5074\end{cfa}
     5075
     5076\item
     5077\begin{sloppypar}
     5078\Indexc{quoted}( $wdi\ manipulator$, ©const char Ldelimiter = '\''©, ©const char Rdelimiter = '\0'© )\index{manipulator!quoted@©quoted©}
     5079consumes the scanset ©"L[^R]R"©, where ©L© is the left ©delimiter© character and ©R© is the right delimiter character, which skips whitespace, consumes and ignores the left delimiter, reads characters until the right-delimiter into the string variable (null terminated), and consumes and ignores the right delimiter.
     5080If the delimit character is omitted, it defaults to ©'\''© (single quote).
     5081\end{sloppypar}
     5082\begin{cfa}[belowskip=0pt]
     5083char cs[10];
     5084sin | quoted( wdi( sizeof(cs), cs ) ); §\C[3in]{// " is the start/end delimiter}§
     5085sin | quoted( wdi( sizeof(cs), cs ), '\'' ); §\C{// ' is the start/end delimiter}§
     5086sin | quoted( wdi( sizeof(cs), cs ), '[', ']' ); §\C{// [ is the start and ] is the end delimiter}\CRT§
     5087\end{cfa}
     5088\begin{cfa}[showspaces=true]
     5089®   "abc"  'abc'[abc]®
     5090\end{cfa}
     5091
     5092\item
     5093\Indexc{incl}( scanset, $wdi\ manipulator$ )\index{manipulator!incl@©incl©}
     5094consumes the scanset, which reads all the scanned characters into the string variable (null terminated).
     5095\begin{cfa}[belowskip=0pt]
     5096char cs[10];
     5097sin | incl( "abc", cs );
    50325098\end{cfa}
    50335099\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    50365102
    50375103\item
    5038 \Indexc{excl}( scanset, wdi-input-string )\index{manipulator!excl@©excl©}
    5039 For C-string types, the scanset matches any number of characters \emph{not in} the set.
    5040 Non-matching characters are read into the C input-string and null terminated.
     5104\Indexc{excl}( scanset, $wdi\ manipulator$ )\index{manipulator!excl@©excl©}
     5105consumes the \emph{not} scanset, which reads all the scanned characters into the string variable (null terminated).
    50415106\begin{cfa}[belowskip=0pt]
    5042 char s[10];
    5043 sin | excl( "abc", s );
     5107char cs[10];
     5108sin | excl( "abc", cs );
    50445109\end{cfa}
    50455110\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    50475112\end{cfa}
    50485113
    5049 \Indexc{quoted}( char delimit, wdi-input-string )\index{manipulator!quoted@©quoted©}
    5050 Is an ©excl© with scanset ©"delimit"©, which consumes all characters up to the delimit character.
    5051 If the delimit character is omitted, it defaults to ©'\n'© (newline).
    5052 
    5053 \item
    5054 \Indexc{getline}( char delimit, wdi-input-string )\index{manipulator!getline@©getline©}
    5055 Is an ©excl© with scanset ©"delimit"©, which consumes all characters up to the delimit character.
    5056 If the delimit character is omitted, it defaults to ©'\n'© (newline).
     5114\item
     5115\Indexc{ignore}( ©T & v© or ©const char cs[]© or $string\ manipulator$ )\index{manipulator!ignore@©ignore©}
     5116consumes the appropriate characters for the type and ignores them, so the input variable is unchanged.
     5117\begin{cfa}
     5118double d;
     5119char cs[10];
     5120sin | ignore( d );                                              §\C{// d is unchanged}§
     5121sin | ignore( cs );                                             §\C{// cs is unchanged, no wdi required}§
     5122sin | ignore( quoted( wdi( sizeof(cs), cs ) ) ); §\C{// cs is unchanged}§
     5123\end{cfa}
     5124\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     5125®  -75.35e-4 25 "abc"®
     5126\end{cfa}
    50575127\end{enumerate}
    50585128
Note: See TracChangeset for help on using the changeset viewer.