Changeset 1048b31 for doc/refrat
- Timestamp:
- May 2, 2016, 3:28:16 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 1b7ea43
- Parents:
- 1f6e009 (diff), e945826 (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. - Location:
- doc/refrat
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/refrat/Makefile
r1f6e009 r1048b31 1 1 ## Define the appropriate configuration variables. 2 2 3 Macros = 4 TeXLIB = .:${Macros}: 3 TeXLIB = .:../bibliography/:../LaTeXmacros/: 5 4 LaTeX = TEXINPUTS=${TeXLIB} && export TEXINPUTS && latex 6 BibTeX = B STINPUTS=${TeXLIB} && export BSTINPUTS && bibtex5 BibTeX = BIBINPUTS=${TeXLIB} && export BIBINPUTS && bibtex 7 6 8 7 ## Define the text source files. … … 44 43 dvips $< -o $@ 45 44 46 ${basename ${DOCUMENT}}.dvi : Makefile ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} ${basename ${DOCUMENT}}.tex ${basename ${DOCUMENT}}.bib 45 ${basename ${DOCUMENT}}.dvi : Makefile ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} ${basename ${DOCUMENT}}.tex \ 46 ../LaTeXmacros/common.tex ../LaTeXmacros/indexstyle ../bibliography/cfa.bib 47 47 # Conditionally create an empty *.ind (index) file for inclusion until makeindex is run. 48 48 if [ ! -r ${basename $@}.ind ] ; then touch ${basename $@}.ind ; fi … … 54 54 -${BibTeX} ${basename $@} 55 55 # Make index from *.aux entries and input index at end of document 56 makeindex -s indexstyle ${basename $@}.idx56 makeindex -s ../LaTeXmacros/indexstyle ${basename $@}.idx 57 57 ${LaTeX} ${basename $@}.tex 58 58 # Run again to get index title into table of contents -
doc/refrat/refrat.tex
r1f6e009 r1048b31 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -*- Mode: Latex -*- %%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 %% 3 %% Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo 4 %% 5 %% The contents of this file are covered under the licence agreement in the 6 %% file "LICENCE" distributed with Cforall. 7 %% 8 %% refrat.tex -- 9 %% 10 %% Author : Peter A. Buhr 11 %% Created On : Wed Apr 6 14:52:25 2016 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Sat Apr 30 13:45:40 2016 14 %% Update Count : 29 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 1 17 % requires tex packages: texlive-base texlive-latex-base tex-common texlive-humanities texlive-latex-extra texlive-fonts-recommended 18 19 % red highlighting ®...® (registered trademark sumbol) 20 % blue highlighting ©...© (copyright symbol) 21 % latex escape §...§ (section symbol) 22 % keyword escape ¶...¶ (pilcrow symbol) 23 % math escape $...$ (dollar symbol) 2 24 3 25 \documentclass[openright,twoside]{report} … … 5 27 6 28 % Latex packages used in the document. 7 8 29 \usepackage{fullpage,times} 9 30 \usepackage{xspace} … … 11 32 \usepackage{listings} 12 33 \usepackage{comment} 13 \usepackage{latexsym} 14 \usepackage{mathptmx} 34 \usepackage{latexsym} % \Box 35 \usepackage{mathptmx} % better math font with "times" 15 36 \usepackage[pagewise]{lineno} 16 37 \renewcommand{\linenumberfont}{\scriptsize\sffamily} … … 21 42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 22 43 23 % Names used in the document. 24 25 \newcommand{\CFA}{C$\forall$\xspace} % set language symbolic name 26 \newcommand{\CFL}{Cforall\xspace} % set language text name 27 \newcommand{\CC}{C\kern-.1em\hbox{+\kern-.25em+}\xspace} % CC symbolic name 28 \def\c11{ISO/IEC C} % C11 name (cannot have numbers in latex command name) 44 % Bespoke macros used in the document. 45 \input{common} 29 46 30 47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 31 48 32 % Bespoke macros used in the document. 33 34 \makeatletter 35 % allow escape sequence in lstinline 36 %\usepackage{etoolbox} 37 %\patchcmd{\lsthk@TextStyle}{\let\lst@DefEsc\@empty}{}{}{\errmessage{failed to patch}} 38 39 \renewcommand\small{% 40 \@setfontsize\small{8.5}{11}% 41 \abovedisplayskip 8.5pt \@plus 3pt \@minus 4pt 42 \abovedisplayshortskip \z@ \@plus 2pt 43 \belowdisplayshortskip 4pt \@plus 2pt \@minus 2pt 44 \def\@listi{\leftmargin\leftmargini 45 \topsep 4pt \@plus 2pt \@minus 2pt 46 \parsep 2pt \@pluspt \@minuspt 47 \itemsep \parsep}% 48 \belowdisplayskip \abovedisplayskip 49 } 50 \usepackage{relsize} % must be after change to small 51 52 \renewcommand{\labelitemi}{{\raisebox{0.25ex}{\footnotesize$\bullet$}}} 53 \renewenvironment{itemize}{\begin{list}{\labelitemi}{\topsep=5pt\itemsep=5pt\parsep=0pt}}{\end{list}} 54 55 % Reduce size of chapter/section titles 56 \def\@makechapterhead#1{% 57 \vspace*{50\p@}% 58 {\parindent \z@ \raggedright \normalfont 59 \ifnum \c@secnumdepth >\m@ne 60 \large\bfseries \@chapapp\space \thechapter 61 \par\nobreak 62 \vskip 5\p@ 63 \fi 64 \interlinepenalty\@M 65 \Large \bfseries #1\par\nobreak 66 \vskip 50\p@ 67 }} 68 \def\@makeschapterhead#1{% 69 \vspace*{50\p@}% 70 {\parindent \z@ \raggedright 71 \normalfont 72 \interlinepenalty\@M 73 \Large \bfseries #1\par\nobreak 74 \vskip 50\p@ 75 }} 76 \renewcommand\section{\@startsection{section}{1}{\z@}{-3.0ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\large\bfseries}} 77 \renewcommand\subsection{\@startsection{subsection}{2}{\z@}{-2.5ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\normalsize\bfseries}} 78 \renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}{-2.5ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\normalsize\bfseries}} 79 \renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}{-2.0ex \@plus -1ex \@minus -.2ex}{-1em}{\normalfont\normalsize\bfseries}} 80 81 % index macros 82 \newcommand{\italic}[1]{\emph{\hyperpage{#1}}} 83 \newcommand{\definition}[1]{\textbf{\hyperpage{#1}}} 84 \newcommand{\see}[1]{\emph{see} #1} 85 86 % Define some commands that produce formatted index entries suitable for cross-references. 87 % ``\spec'' produces entries for specifications of entities. ``\impl'' produces entries for their 88 % implementations, and ``\use'' for their uses. 89 90 % \newcommand{\bold}[1]{{\bf #1}} 91 % \def\spec{\@bsphack\begingroup 92 % \def\protect##1{\string##1\space}\@sanitize 93 % \@wrxref{|bold}} 94 \def\impl{\@bsphack\begingroup 95 \def\protect##1{\string##1\space}\@sanitize 96 \@wrxref{|definition}} 97 \newcommand{\indexcode}[1]{{\lstinline$#1$}} 98 \def\use{\@bsphack\begingroup 99 \def\protect##1{\string##1\space}\@sanitize 100 \@wrxref{|hyperpage}} 101 \def\@wrxref#1#2{\let\thepage\relax 102 \xdef\@gtempa{\write\@indexfile{\string 103 \indexentry{#2@{\lstinline$#2$}#1}{\thepage}}}\endgroup\@gtempa 104 \if@nobreak \ifvmode\nobreak\fi\fi\@esphack} 105 %\newcommand{\use}[1]{\index{#1@{\lstinline$#1$}}} 106 %\newcommand{\impl}[1]{\index{\protect#1@{\lstinline$\protect#1$}|definition}} 107 108 % inline text and lowercase index: \Index{inline and lowercase index text} 109 % inline text and as-in index: \Index[as-is index text]{inline text} 110 % inline text but index with different as-is text: \Index[index text]{inline text} 111 \newcommand{\Index}{\@ifstar\@sIndex\@Index} 112 \newcommand{\@Index}[2][\@empty]{\lowercase{\def\temp{#2}}#2\ifx#1\@empty\index{\temp}\else\index{#1@{\protect#2}}\fi} 113 \newcommand{\@sIndex}[2][\@empty]{#2\ifx#1\@empty\index{#2}\else\index{#1@{\protect#2}}\fi} 114 \makeatother 115 116 % blocks and titles 117 \newenvironment{rationale}{% 118 \begin{quotation}\noindent$\Box$\enspace 119 }{% 120 \hfill\enspace$\Box$\end{quotation} 121 }% 122 \newcommand{\define}[1]{\emph{#1\/}\index{#1}} 123 \newcommand{\rewrite}{\(\Rightarrow\)} 124 \newcommand{\rewriterules}{\paragraph{Rewrite Rules}~\par\noindent} 125 \newcommand{\examples}{\paragraph{Examples}~\par\noindent} 126 \newcommand{\semantics}{\paragraph{Semantics}~\par\noindent} 127 \newcommand{\constraints}{\paragraph{Constraints}~\par\noindent} 128 \newcommand{\predefined}{\paragraph{Predefined Identifiers}~\par\noindent} 129 130 % BNF macros 131 \def\syntax{\paragraph{Syntax}\trivlist\parindent=.5in\item[\hskip.5in]} 132 \let\endsyntax=\endtrivlist 133 \newcommand{\lhs}[1]{\par{\emph{#1:}}\index{#1@{\emph{#1}}|italic}} 134 \newcommand{\rhs}{\hfil\break\hbox{\hskip1in}} 135 \newcommand{\oldlhs}[1]{\emph{#1: \ldots}\index{#1@{\emph{#1}}|italic}} 136 \newcommand{\nonterm}[1]{\emph{#1\/}\index{#1@{\emph{#1}}|italic}} 137 \newcommand{\opt}{$_{opt}$\ } 138 139 % adjust varioref package with default "section" and "page" titles, and optional title with faraway page numbers 140 % \VRef{label} => Section 2.7, \VPageref{label} => page 17 141 % \VRef[Figure]{label} => Figure 3.4, \VPageref{label} => page 17 142 \renewcommand{\reftextfaceafter}{\unskip} 143 \renewcommand{\reftextfacebefore}{\unskip} 144 \renewcommand{\reftextafter}{\unskip} 145 \renewcommand{\reftextbefore}{\unskip} 146 \renewcommand{\reftextfaraway}[1]{\unskip, p.~\pageref{#1}} 147 \renewcommand{\reftextpagerange}[2]{\unskip, pp.~\pageref{#1}--\pageref{#2}} 148 \newcommand{\VRef}[2][Section]{\ifx#1\@empty\else{#1}\nobreakspace\fi\vref{#2}} 149 \newcommand{\VPageref}[2][page]{\ifx#1\@empty\else{#1}\nobreakspace\fi\pageref{#2}} 150 151 % CFA based on ANSI C 152 \lstdefinelanguage{CFA}[ANSI]{C}% 153 {morekeywords={asm,_Alignas,_Alignof,_At,_Atomic,_Bool,catch,catchResume,choose,_Complex,trait,disable,dtype,enable, 154 fallthru,finally,forall,ftype,_Generic,_Imaginary,inline,lvalue,_Noreturn,otype,restrict,_Static_assert, 155 _Thread_local,throw,throwResume,try,}, 156 }% 157 158 \lstset{ 159 language=CFA, 160 columns=flexible, 161 basicstyle=\sf\relsize{-1}, 162 tabsize=4, 163 xleftmargin=\parindent, 164 escapechar=@, 165 keepspaces=true, 166 showstringspaces=false, 167 showlines=true, 168 }% 169 170 \makeatletter 171 % replace/adjust listings characters that look bad in sanserif 172 \lst@CCPutMacro 173 \lst@ProcessOther{"2D}{\lst@ttfamily{-{}}{{\ttfamily\upshape -}}} % replace minus 174 \lst@ProcessOther{"3C}{\lst@ttfamily{<}{\texttt{<}}} % replace less than 175 \lst@ProcessOther{"3E}{\lst@ttfamily{<}{\texttt{>}}} % replace greater than 176 \lst@ProcessOther{"5E}{\raisebox{0.4ex}{$\scriptstyle\land\,$}} % replace circumflex 177 \lst@ProcessLetter{"5F}{\lst@ttfamily{\char95}{{\makebox[1.2ex][c]{\rule{1ex}{0.1ex}}}}} % replace underscore 178 \lst@ProcessOther{"7E}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}} % replace tilde 179 %\lst@ProcessOther{"7E}{\raisebox{-.4ex}[1ex][0pt]{\textasciitilde}} % lower tilde 180 \@empty\z@\@empty 181 \makeatother 182 183 \setcounter{secnumdepth}{3} % number subsubsections 184 \setcounter{tocdepth}{3} % subsubsections in table of contents 49 \setcounter{secnumdepth}{3} % number subsubsections 50 \setcounter{tocdepth}{3} % subsubsections in table of contents 185 51 \makeindex 186 52 … … 189 55 \begin{document} 190 56 \pagestyle{headings} 191 \linenumbers 57 \linenumbers % comment out to turn off line numbering 192 58 193 59 \title{\Huge 60 \vspace*{1in} 194 61 \CFA (\CFL) Reference Manual and Rationale 195 62 }% title … … 226 93 227 94 This document is a reference manual and rationale for \CFA, a polymorphic extension of the C programming language. 228 It makes frequent reference to the {\c11} standard \cite{ ANS:C11}, and occasionally compares \CFA to {\CC} \cite{c++}.95 It makes frequent reference to the {\c11} standard \cite{C11}, and occasionally compares \CFA to {\CC} \cite{C++}. 229 96 230 97 The manual deliberately imitates the ordering of the {\c11} standard (although the section numbering differs). … … 264 131 \CFA's scope rules differ from C's in one major respect: a declaration of an identifier may overload\index{overloading} outer declarations of lexically identical identifiers in the same 265 132 \Index{name space}, instead of hiding them. 266 The outer declaration is hidden if the two declarations have \Index{compatible type}, or if one declares an array type and the other declares a pointer type and the element type and pointed-at type are compatible, or if one has function type and the other is a pointer to a compatible function type, or if one declaration is a \lstinline $type$\use{type} or267 \lstinline $typedef$\use{typedef} declaration and the other is not. The outer declaration becomes133 The outer declaration is hidden if the two declarations have \Index{compatible type}, or if one declares an array type and the other declares a pointer type and the element type and pointed-at type are compatible, or if one has function type and the other is a pointer to a compatible function type, or if one declaration is a \lstinline@type@\use{type} or 134 \lstinline@typedef@\use{typedef} declaration and the other is not. The outer declaration becomes 268 135 \Index{visible} when the scope of the inner declaration terminates. 269 136 \begin{rationale} 270 Hence, a \CFA program can declare an \lstinline $int v$ and a \lstinline$float v$in the same scope;137 Hence, a \CFA program can declare an \lstinline@int v@ and a \lstinline@float v@ in the same scope; 271 138 a {\CC} program can not. 272 139 \end{rationale} … … 282 149 Identifiers with \Index{no linkage} always denote unique entities. 283 150 \begin{rationale} 284 A \CFA program can declare an \lstinline $extern int v$ and an \lstinline$extern float v$;151 A \CFA program can declare an \lstinline@extern int v@ and an \lstinline@extern float v@; 285 152 a C program cannot. 286 153 \end{rationale} … … 305 172 \end{lstlisting} 306 173 307 The type parameters in an instantiation of a generic type must satisfy any constraints in the forall specifier on the type generator declaration, e.g., \lstinline $sumable$.174 The type parameters in an instantiation of a generic type must satisfy any constraints in the forall specifier on the type generator declaration, e.g., \lstinline@sumable@. 308 175 The instantiation then has the semantics that would result if the type parameters were substituted into the type generator declaration by macro substitution. 309 176 … … 366 233 In \CFA, these conversions play a role in overload resolution, and collectively are called the \define{safe arithmetic conversion}s. 367 234 368 Let \ (int_r\) and \(unsigned_r\)be the signed and unsigned integer types with integer conversion rank\index{integer conversion rank}\index{rank|see{integer conversion rank}} $r$.369 Let \ (unsigned_{mr}\)be the unsigned integer type with maximal rank.235 Let \lstinline@int$_r$@ and \lstinline@unsigned$_r$@ be the signed and unsigned integer types with integer conversion rank\index{integer conversion rank}\index{rank|see{integer conversion rank}} $r$. 236 Let \lstinline@unsigned$_{mr}$@ be the unsigned integer type with maximal rank. 370 237 371 238 The following conversions are \emph{direct} safe arithmetic conversions. … … 374 241 The \Index{integer promotion}s. 375 242 \item 376 For every rank $r$ greater than or equal to the rank of \lstinline $int$, conversion from \(int_r\) to \(unsigned_r\).377 \item 378 For every rank $r$ greater than or equal to the rank of \lstinline $int$, where \(int_{r+1}\) exists and can represent all values of \(unsigned_r\), conversion from \(unsigned_r\) to \(int_{r+1}\).379 \item 380 Conversion from \ (unsigned_{mr}\) to \lstinline$float$.243 For every rank $r$ greater than or equal to the rank of \lstinline@int@, conversion from \lstinline@int$_r$@ to \lstinline@unsigned$_r$@. 244 \item 245 For every rank $r$ greater than or equal to the rank of \lstinline@int@, where \lstinline@int$_{r+1}$@ exists and can represent all values of \lstinline@unsigned$_r$@, conversion from \lstinline@unsigned$_r$@ to \lstinline@int$_{r+1}$@. 246 \item 247 Conversion from \lstinline@unsigned$_{mr}$@ to \lstinline@float@. 381 248 \item 382 249 Conversion from an enumerated type to its compatible integer type. 383 250 \item 384 Conversion from \lstinline $float$ to \lstinline$double$, and from \lstinline$double$ to \lstinline$long double$.385 \item 386 Conversion from \lstinline $float _Complex$ to \lstinline$double _Complex$, and from \lstinline$double _Complex$ to \lstinline$long double _Complex$.251 Conversion from \lstinline@float@ to \lstinline@double@, and from \lstinline@double@ to \lstinline@long double@. 252 \item 253 Conversion from \lstinline@float _Complex@ to \lstinline@double _Complex@, and from \lstinline@double _Complex@ to \lstinline@long double _Complex@. 387 254 \begin{sloppypar} 388 255 \item 389 Conversion from \lstinline $float _Imaginary$ to \lstinline$double _Imaginary$, and from \lstinline$double _Imaginary$ to \lstinline$long double$ \lstinline$_Imaginary$, if the implementation supports imaginary types.256 Conversion from \lstinline@float _Imaginary@ to \lstinline@double _Imaginary@, and from \lstinline@double _Imaginary@ to \lstinline@long double _Imaginary@, if the implementation supports imaginary types. 390 257 \end{sloppypar} 391 258 \end{itemize} 392 259 393 If type \lstinline $T$ can be converted to type \lstinline$U$ by a safe direct arithmetic conversion and type \lstinline$U$ can be converted to type \lstinline$V$ by a safe arithmetic conversion, then the conversion from \lstinline$T$ to type \lstinline$V$is an \emph{indirect} safe arithmetic conversion.260 If type \lstinline@T@ can be converted to type \lstinline@U@ by a safe direct arithmetic conversion and type \lstinline@U@ can be converted to type \lstinline@V@ by a safe arithmetic conversion, then the conversion from \lstinline@T@ to type \lstinline@V@ is an \emph{indirect} safe arithmetic conversion. 394 261 395 262 \begin{rationale} … … 414 281 int x, y; 415 282 }; 416 void move_by( struct point * p1, struct point * p2 ) { @\impl{move_by}@283 void move_by( struct point * p1, struct point * p2 ) {§\impl{move_by}§ 417 284 p1->x += p2.x; 418 285 p1->y += p2.y; … … 424 291 move_to( &cp1, &cp2 ); 425 292 \end{lstlisting} 426 Thanks to implicit conversion, the two arguments that \lstinline $move_by()$receives are pointers to427 \lstinline $cp1$'s second member and \lstinline$cp2$'s second member.293 Thanks to implicit conversion, the two arguments that \lstinline@move_by()@ receives are pointers to 294 \lstinline@cp1@'s second member and \lstinline@cp2@'s second member. 428 295 429 296 … … 467 334 a direct safe arithmetic conversion; 468 335 \item 469 from any object type or incomplete type to \lstinline $void$;470 \item 471 from a pointer to any non-\lstinline $void$ type to a pointer to \lstinline$void$;336 from any object type or incomplete type to \lstinline@void@; 337 \item 338 from a pointer to any non-\lstinline@void@ type to a pointer to \lstinline@void@; 472 339 \item 473 340 from a pointer to any type to a pointer to a more qualified version of the type\index{qualified type}; … … 480 347 Conversions that are not safe conversions are \define{unsafe conversion}s. 481 348 \begin{rationale} 482 As in C, there is an implicit conversion from \lstinline $void *$to any pointer type.349 As in C, there is an implicit conversion from \lstinline@void *@ to any pointer type. 483 350 This is clearly dangerous, and {\CC} does not have this implicit conversion. 484 351 \CFA\index{deficiencies!void * conversion} keeps it, in the interest of remaining as pure a superset of C as possible, but discourages it by making it unsafe. … … 506 373 \begin{itemize} 507 374 \item 508 The cost of an implicit conversion from \lstinline $int$ to \lstinline$long$is 1.509 The cost of an implicit conversion from \lstinline $long$ to \lstinline$double$ is 3, because it is defined in terms of conversions from \lstinline$long$ to \lstinline$unsigned long$, then to \lstinline$float$, and then to \lstinline$double$.510 511 \item 512 If \lstinline $int$ can represent all the values of \lstinline$unsigned short$, then the cost of an implicit conversion from \lstinline$unsigned short$ to \lstinline$unsigned$is 2:513 \lstinline $unsigned short$ to \lstinline$int$ to \lstinline$unsigned$.514 Otherwise, \lstinline $unsigned short$ is converted directly to \lstinline$unsigned$, and the cost is 1.515 516 \item 517 If \lstinline $long$ can represent all the values of \lstinline$unsigned$, then the conversion cost of \lstinline$unsigned$ to \lstinline$long$is 1.375 The cost of an implicit conversion from \lstinline@int@ to \lstinline@long@ is 1. 376 The cost of an implicit conversion from \lstinline@long@ to \lstinline@double@ is 3, because it is defined in terms of conversions from \lstinline@long@ to \lstinline@unsigned long@, then to \lstinline@float@, and then to \lstinline@double@. 377 378 \item 379 If \lstinline@int@ can represent all the values of \lstinline@unsigned short@, then the cost of an implicit conversion from \lstinline@unsigned short@ to \lstinline@unsigned@ is 2: 380 \lstinline@unsigned short@ to \lstinline@int@ to \lstinline@unsigned@. 381 Otherwise, \lstinline@unsigned short@ is converted directly to \lstinline@unsigned@, and the cost is 1. 382 383 \item 384 If \lstinline@long@ can represent all the values of \lstinline@unsigned@, then the conversion cost of \lstinline@unsigned@ to \lstinline@long@ is 1. 518 385 Otherwise, the conversion is an unsafe conversion, and its conversion cost is undefined. 519 386 \end{itemize} … … 523 390 \begin{syntax} 524 391 \oldlhs{keyword} 525 \rhs \lstinline $forall$526 \rhs \lstinline $lvalue$527 \rhs \lstinline $trait$528 \rhs \lstinline $dtype$529 \rhs \lstinline $ftype$530 \rhs \lstinline $type$392 \rhs \lstinline@forall@ 393 \rhs \lstinline@lvalue@ 394 \rhs \lstinline@trait@ 395 \rhs \lstinline@dtype@ 396 \rhs \lstinline@ftype@ 397 \rhs \lstinline@otype@ 531 398 \end{syntax} 532 399 … … 535 402 536 403 \CFA allows operator \Index{overloading} by associating operators with special function identifiers. 537 Furthermore, the constants ``\lstinline $0$'' and ``\lstinline$1$'' have special status for many of C's data types (and for many programmer-defined data types as well), so \CFA treats them as overloadable identifiers.404 Furthermore, the constants ``\lstinline@0@'' and ``\lstinline@1@'' have special status for many of C's data types (and for many programmer-defined data types as well), so \CFA treats them as overloadable identifiers. 538 405 Programmers can use these identifiers to declare functions and objects that implement operators and constants for their own types. 539 406 … … 544 411 \begin{syntax} 545 412 \oldlhs{identifier} 546 \rhs \lstinline $0$547 \rhs \lstinline $1$413 \rhs \lstinline@0@ 414 \rhs \lstinline@1@ 548 415 \end{syntax} 549 416 550 \index{constant identifiers}\index{identifiers!for constants} The tokens ``\lstinline $0$''\impl{0} and ``\lstinline$1$''\impl{1} are identifiers.417 \index{constant identifiers}\index{identifiers!for constants} The tokens ``\lstinline@0@''\impl{0} and ``\lstinline@1@''\impl{1} are identifiers. 551 418 No other tokens defined by the rules for integer constants are considered to be identifiers. 552 419 \begin{rationale} 553 Why ``\lstinline $0$'' and ``\lstinline$1$''? Those integers have special status in C.420 Why ``\lstinline@0@'' and ``\lstinline@1@''? Those integers have special status in C. 554 421 All scalar types can be incremented and decremented, which is defined in terms of adding or subtracting 1. 555 The operations ``\lstinline $&&$'', ``\lstinline$||$'', and ``\lstinline$!$'' can be applied to any scalar arguments, and are defined in terms of comparison against 0.422 The operations ``\lstinline@&&@'', ``\lstinline@||@'', and ``\lstinline@!@'' can be applied to any scalar arguments, and are defined in terms of comparison against 0. 556 423 A \nonterm{constant-expression} that evaluates to 0 is effectively compatible with every pointer type. 557 424 558 425 In C, the integer constants 0 and 1 suffice because the integer promotion rules can convert them to any arithmetic type, and the rules for pointer expressions treat constant expressions evaluating to 0 as a special case. 559 426 However, user-defined arithmetic types often need the equivalent of a 1 or 0 for their functions or operators, polymorphic functions often need 0 and 1 constants of a type matching their polymorphic parameters, and user-defined pointer-like types may need a null value. 560 Defining special constants for a user-defined type is more efficient than defining a conversion to the type from \lstinline $_Bool$.561 562 Why \emph{just} ``\lstinline $0$'' and ``\lstinline$1$''? Why not other integers? No other integers have special status in C.563 A facility that let programmers declare specific constants---``\lstinline $const Rational 12$'', for instance---would not be much of an improvement.427 Defining special constants for a user-defined type is more efficient than defining a conversion to the type from \lstinline@_Bool@. 428 429 Why \emph{just} ``\lstinline@0@'' and ``\lstinline@1@''? Why not other integers? No other integers have special status in C. 430 A facility that let programmers declare specific constants---``\lstinline@const Rational 12@'', for instance---would not be much of an improvement. 564 431 Some facility for defining the creation of values of programmer-defined types from arbitrary integer tokens would be needed. 565 432 The complexity of such a feature doesn't seem worth the gain. … … 577 444 \begin{tabular}[t]{ll} 578 445 %identifier & operation \\ \hline 579 \lstinline $?[?]$& subscripting \impl{?[?]}\\580 \lstinline $?()$& function call \impl{?()}\\581 \lstinline $?++$& postfix increment \impl{?++}\\582 \lstinline $?--$& postfix decrement \impl{?--}\\583 \lstinline $++?$& prefix increment \impl{++?}\\584 \lstinline $--?$& prefix decrement \impl{--?}\\585 \lstinline $*?$& dereference \impl{*?}\\586 \lstinline $+?$& unary plus \impl{+?}\\587 \lstinline $-?$& arithmetic negation \impl{-?}\\588 \lstinline $~?$& bitwise negation \impl{~?}\\589 \lstinline $!?$& logical complement \impl{"!?}\\590 \lstinline $?*?$& multiplication \impl{?*?}\\591 \lstinline $?/?$& division \impl{?/?}\\446 \lstinline@?[?]@ & subscripting \impl{?[?]}\\ 447 \lstinline@?()@ & function call \impl{?()}\\ 448 \lstinline@?++@ & postfix increment \impl{?++}\\ 449 \lstinline@?--@ & postfix decrement \impl{?--}\\ 450 \lstinline@++?@ & prefix increment \impl{++?}\\ 451 \lstinline@--?@ & prefix decrement \impl{--?}\\ 452 \lstinline@*?@ & dereference \impl{*?}\\ 453 \lstinline@+?@ & unary plus \impl{+?}\\ 454 \lstinline@-?@ & arithmetic negation \impl{-?}\\ 455 \lstinline@~?@ & bitwise negation \impl{~?}\\ 456 \lstinline@!?@ & logical complement \impl{"!?}\\ 457 \lstinline@?*?@ & multiplication \impl{?*?}\\ 458 \lstinline@?/?@ & division \impl{?/?}\\ 592 459 \end{tabular}\hfil 593 460 \begin{tabular}[t]{ll} 594 461 %identifier & operation \\ \hline 595 \lstinline $?%?$& remainder \impl{?%?}\\596 \lstinline $?+?$& addition \impl{?+?}\\597 \lstinline $?-?$& subtraction \impl{?-?}\\598 \lstinline $?<<?$& left shift \impl{?<<?}\\599 \lstinline $?>>?$& right shift \impl{?>>?}\\600 \lstinline $?<?$& less than \impl{?<?}\\601 \lstinline $?<=?$& less than or equal \impl{?<=?}\\602 \lstinline $?>=?$& greater than or equal \impl{?>=?}\\603 \lstinline $?>?$& greater than \impl{?>?}\\604 \lstinline $?==?$& equality \impl{?==?}\\605 \lstinline $?!=?$& inequality \impl{?"!=?}\\606 \lstinline $?&?$& bitwise AND \impl{?&?}\\462 \lstinline@?%?@ & remainder \impl{?%?}\\ 463 \lstinline@?+?@ & addition \impl{?+?}\\ 464 \lstinline@?-?@ & subtraction \impl{?-?}\\ 465 \lstinline@?<<?@ & left shift \impl{?<<?}\\ 466 \lstinline@?>>?@ & right shift \impl{?>>?}\\ 467 \lstinline@?<?@ & less than \impl{?<?}\\ 468 \lstinline@?<=?@ & less than or equal \impl{?<=?}\\ 469 \lstinline@?>=?@ & greater than or equal \impl{?>=?}\\ 470 \lstinline@?>?@ & greater than \impl{?>?}\\ 471 \lstinline@?==?@ & equality \impl{?==?}\\ 472 \lstinline@?!=?@ & inequality \impl{?"!=?}\\ 473 \lstinline@?&?@ & bitwise AND \impl{?&?}\\ 607 474 \end{tabular}\hfil 608 475 \begin{tabular}[t]{ll} 609 476 %identifier & operation \\ \hline 610 \lstinline $?^?$& exclusive OR \impl{?^?}\\611 \lstinline $?|?$& inclusive OR \impl{?"|?}\\612 \lstinline $?=?$& simple assignment \impl{?=?}\\613 \lstinline $?*=?$& multiplication assignment \impl{?*=?}\\614 \lstinline $?/=?$& division assignment \impl{?/=?}\\615 \lstinline $?%=?$& remainder assignment \impl{?%=?}\\616 \lstinline $?+=?$& addition assignment \impl{?+=?}\\617 \lstinline $?-=?$& subtraction assignment \impl{?-=?}\\618 \lstinline $?<<=?$& left-shift assignment \impl{?<<=?}\\619 \lstinline $?>>=?$& right-shift assignment \impl{?>>=?}\\620 \lstinline $?&=?$& bitwise AND assignment \impl{?&=?}\\621 \lstinline $?^=?$& exclusive OR assignment \impl{?^=?}\\622 \lstinline $?|=?$& inclusive OR assignment \impl{?"|=?}\\477 \lstinline@?^?@ & exclusive OR \impl{?^?}\\ 478 \lstinline@?|?@ & inclusive OR \impl{?"|?}\\ 479 \lstinline@?=?@ & simple assignment \impl{?=?}\\ 480 \lstinline@?*=?@ & multiplication assignment \impl{?*=?}\\ 481 \lstinline@?/=?@ & division assignment \impl{?/=?}\\ 482 \lstinline@?%=?@ & remainder assignment \impl{?%=?}\\ 483 \lstinline@?+=?@ & addition assignment \impl{?+=?}\\ 484 \lstinline@?-=?@ & subtraction assignment \impl{?-=?}\\ 485 \lstinline@?<<=?@ & left-shift assignment \impl{?<<=?}\\ 486 \lstinline@?>>=?@ & right-shift assignment \impl{?>>=?}\\ 487 \lstinline@?&=?@ & bitwise AND assignment \impl{?&=?}\\ 488 \lstinline@?^=?@ & exclusive OR assignment \impl{?^=?}\\ 489 \lstinline@?|=?@ & inclusive OR assignment \impl{?"|=?}\\ 623 490 \end{tabular} 624 491 \hfil … … 635 502 636 503 \begin{rationale} 637 The use of ``\lstinline $?$'' in identifiers means that some C programs are not \CFA programs. For instance, the sequence of characters ``\lstinline$(i < 0)?--i:i$'' is legal in a C program, but a638 \CFA compiler detects a syntax error because it treats ``\lstinline $?--$'' as an identifier, not as the two tokens ``\lstinline$?$'' and ``\lstinline$--$''.504 The use of ``\lstinline@?@'' in identifiers means that some C programs are not \CFA programs. For instance, the sequence of characters ``\lstinline@(i < 0)?--i:i@'' is legal in a C program, but a 505 \CFA compiler detects a syntax error because it treats ``\lstinline@?--@'' as an identifier, not as the two tokens ``\lstinline@?@'' and ``\lstinline@--@''. 639 506 \end{rationale} 640 507 … … 643 510 \begin{itemize} 644 511 \item 645 The logical operators ``\lstinline $&&$'' and ``\lstinline$||$'', and the conditional operator646 ``\lstinline $?:$''.512 The logical operators ``\lstinline@&&@'' and ``\lstinline@||@'', and the conditional operator 513 ``\lstinline@?:@''. 647 514 These operators do not always evaluate their operands, and hence can not be properly defined by functions unless some mechanism like call-by-name is added to the language. 648 Note that the definitions of ``\lstinline $&&$'' and ``\lstinline$||$'' say that they work by checking that their arguments are unequal to 0, so defining ``\lstinline$!=$'' and ``\lstinline$0$'' for user-defined types is enough to allow them to be used in logical expressions.515 Note that the definitions of ``\lstinline@&&@'' and ``\lstinline@||@'' say that they work by checking that their arguments are unequal to 0, so defining ``\lstinline@!=@'' and ``\lstinline@0@'' for user-defined types is enough to allow them to be used in logical expressions. 649 516 650 517 \item … … 655 522 \item 656 523 The ``address of'' operator. 657 It would seem useful to define a unary ``\lstinline $&$'' operator that returns values of some programmer-defined pointer-like type.524 It would seem useful to define a unary ``\lstinline@&@'' operator that returns values of some programmer-defined pointer-like type. 658 525 The problem lies with the type of the operator. 659 Consider the expression ``\lstinline $p = &x$'', where \lstinline$x$is of type660 \lstinline $T$ and \lstinline$p$ has the programmer-defined type \lstinline$T_ptr$.661 The expression might be treated as a call to the unary function ``\lstinline $&?$''.662 Now what is the type of the function's parameter? It can not be \lstinline $T$, because then \lstinline$x$would be passed by value, and there is no way to create a useful pointer-like result from a value.663 Hence the parameter must have type \lstinline $T *$.664 But then the expression must be rewritten as ``\lstinline $p = &?( &x )$''526 Consider the expression ``\lstinline@p = &x@'', where \lstinline@x@ is of type 527 \lstinline@T@ and \lstinline@p@ has the programmer-defined type \lstinline@T_ptr@. 528 The expression might be treated as a call to the unary function ``\lstinline@&?@''. 529 Now what is the type of the function's parameter? It can not be \lstinline@T@, because then \lstinline@x@ would be passed by value, and there is no way to create a useful pointer-like result from a value. 530 Hence the parameter must have type \lstinline@T *@. 531 But then the expression must be rewritten as ``\lstinline@p = &?( &x )@'' 665 532 ---which doesn't seem like progress! 666 533 667 534 The rule for address-of expressions would have to be something like ``keep applying address-of functions until you get one that takes a pointer argument, then use the built-in operator and stop''. 668 It seems simpler to define a conversion function from \lstinline $T *$ to \lstinline$T_ptr$.669 670 \item 671 The \lstinline $sizeof$operator.535 It seems simpler to define a conversion function from \lstinline@T *@ to \lstinline@T_ptr@. 536 537 \item 538 The \lstinline@sizeof@ operator. 672 539 It is already defined for every object type, and intimately tied into the language's storage allocation model. 673 540 Redefining it seems pointless. 674 541 675 542 \item 676 The ``member of'' operators ``\lstinline $.$'' and ``\lstinline$->$''.543 The ``member of'' operators ``\lstinline@.@'' and ``\lstinline@->@''. 677 544 These are not really infix operators, since their right ``operand'' is not a value or object. 678 545 … … 711 578 The ``fewest unsafe conversions'' rule ensures that the usual conversions are done, if possible. 712 579 The ``lowest total expression cost'' rule chooses the proper common type. 713 The odd-looking ``highest argument conversion cost'' rule ensures that, when unary expressions must be converted, conversions of function results are preferred to conversion of function arguments: \lstinline $(double)-i$ will be preferred to \lstinline$-(double)i$.580 The odd-looking ``highest argument conversion cost'' rule ensures that, when unary expressions must be converted, conversions of function results are preferred to conversion of function arguments: \lstinline@(double)-i@ will be preferred to \lstinline@-(double)i@. 714 581 715 582 The ``least polymorphic'' rule reduces the number of polymorphic function calls, since such functions are presumably more expensive than monomorphic functions and since the more specific function is presumably more appropriate. 716 583 It also gives preference to monomorphic values (such as the 717 \lstinline $int$ \lstinline$0$) over polymorphic values (such as the \Index{null pointer}718 \lstinline $0$\use{0}).584 \lstinline@int@ \lstinline@0@) over polymorphic values (such as the \Index{null pointer} 585 \lstinline@0@\use{0}). 719 586 However, interpretations that call polymorphic functions are preferred to interpretations that perform unsafe conversions, because those conversions potentially lose accuracy or violate strong typing. 720 587 721 588 There are two notable differences between \CFA's overload resolution rules and the rules for 722 {\CC} defined in \cite{ c++}.589 {\CC} defined in \cite{C++}. 723 590 First, the result type of a function plays a role. 724 591 In {\CC}, a function call must be completely resolved based on the arguments to the call in most circumstances. … … 736 603 \begin{rationale} 737 604 Predefined functions and constants have internal linkage because that simplifies optimization in traditional compile-and-link environments. 738 For instance, ``\lstinline $an_int + an_int$'' is equivalent to ``\lstinline$?+?(an_int, an_int)$''.605 For instance, ``\lstinline@an_int + an_int@'' is equivalent to ``\lstinline@?+?(an_int, an_int)@''. 739 606 If integer addition has not been redefined in the current scope, a compiler can generate code to perform the addition directly. 740 607 If predefined functions had external linkage, this optimization would be difficult. … … 762 629 \rhs \nonterm{constant} 763 630 \rhs \nonterm{string-literal} 764 \rhs \lstinline $($ \nonterm{expression} \lstinline$)$631 \rhs \lstinline@(@ \nonterm{expression} \lstinline@)@ 765 632 \rhs \nonterm{generic-selection} 766 633 \end{syntax} … … 768 635 \predefined 769 636 \begin{lstlisting} 770 const int 1; @\use{1}@771 const int 0; @\use{0}@637 const int 1;§\use{1}§ 638 const int 0;§\use{0}§ 772 639 forall( dtype DT ) DT * const 0; 773 640 forall( ftype FT ) FT * const 0; … … 778 645 779 646 A \nonterm{constant} or \nonterm{string-literal} has one valid interpretation, which has the type and value defined by {\c11}. 780 The predefined integer identifiers ``\lstinline $1$'' and ``\lstinline$0$'' have the integer values 1 and 0, respectively.781 The other two predefined ``\lstinline $0$'' identifiers are bound to polymorphic pointer values that, when specialized\index{specialization} with a data type or function type respectively, produce a null pointer of that type.647 The predefined integer identifiers ``\lstinline@1@'' and ``\lstinline@0@'' have the integer values 1 and 0, respectively. 648 The other two predefined ``\lstinline@0@'' identifiers are bound to polymorphic pointer values that, when specialized\index{specialization} with a data type or function type respectively, produce a null pointer of that type. 782 649 783 650 A parenthesised expression has the same interpretations as the contained \nonterm{expression}. 784 651 785 652 \examples 786 The expression \lstinline $(void *)0$\use{0} specializes the (polymorphic) null pointer to a null pointer to \lstinline$void$. \lstinline$(const void *)0$ does the same, and also uses a safe conversion from \lstinline$void *$ to \lstinline$const void *$.653 The expression \lstinline@(void *)0@\use{0} specializes the (polymorphic) null pointer to a null pointer to \lstinline@void@. \lstinline@(const void *)0@ does the same, and also uses a safe conversion from \lstinline@void *@ to \lstinline@const void *@. 787 654 In each case, the null pointer conversion is better\index{best valid interpretations} than the unsafe conversion of the integer 788 \lstinline $0$to a pointer.655 \lstinline@0@ to a pointer. 789 656 790 657 \begin{rationale} … … 792 659 793 660 \CFA does not have C's concept of ``null pointer constants'', which are not typed values but special strings of tokens. 794 The C token ``\lstinline $0$'' is an expression of type \lstinline$int$with the value ``zero'', and it \emph{also} is a null pointer constant.661 The C token ``\lstinline@0@'' is an expression of type \lstinline@int@ with the value ``zero'', and it \emph{also} is a null pointer constant. 795 662 Similarly, 796 ``\lstinline $(void *)0$ is an expression of type \lstinline$(void *)$whose value is a null pointer, and it also is a null pointer constant.797 However, in C, ``\lstinline $(void *)(void *)0$'' is663 ``\lstinline@(void *)0@ is an expression of type \lstinline@(void *)@ whose value is a null pointer, and it also is a null pointer constant. 664 However, in C, ``\lstinline@(void *)(void *)0@'' is 798 665 \emph{not} a null pointer constant, even though it is null-valued, a pointer, and constant! The semantics of C expressions contain many special cases to deal with subexpressions that are null pointer constants. 799 666 … … 802 669 \begin{lstlisting} 803 670 forall( dtype DT ) DT * const 0; 804 \end{lstlisting} means that \lstinline $0$is a polymorphic object, and contains a value that can have \emph{any} pointer-to-object type or pointer-to-incomplete type.671 \end{lstlisting} means that \lstinline@0@ is a polymorphic object, and contains a value that can have \emph{any} pointer-to-object type or pointer-to-incomplete type. 805 672 The only such value is the null pointer. 806 673 Therefore the type \emph{alone} is enough to identify a null pointer. … … 812 679 813 680 \constraints The best interpretation of the controlling expression shall be unambiguous\index{ambiguous interpretation}, and shall have type compatible with at most one of the types named in its generic association list. 814 If a generic selection has no \lstinline $default$generic association, the best interpretation of its controlling expression shall have type compatible with exactly one of the types named in its generic association list.681 If a generic selection has no \lstinline@default@ generic association, the best interpretation of its controlling expression shall have type compatible with exactly one of the types named in its generic association list. 815 682 816 683 \semantics … … 823 690 \lhs{postfix-expression} 824 691 \rhs \nonterm{primary-expression} 825 \rhs \nonterm{postfix-expression} \lstinline $[$ \nonterm{expression} \lstinline$]$826 \rhs \nonterm{postfix-expression} \lstinline $($827 \nonterm{argument-expression-list}\opt \lstinline $)$828 \rhs \nonterm{postfix-expression} \lstinline $.$\nonterm{identifier}829 \rhs \nonterm{postfix-expression} \lstinline $->$\nonterm{identifier}830 \rhs \nonterm{postfix-expression} \lstinline $++$831 \rhs \nonterm{postfix-expression} \lstinline $--$832 \rhs \lstinline $($ \nonterm{type-name} \lstinline$)$ \lstinline${$ \nonterm{initializer-list} \lstinline$}$833 \rhs \lstinline $($ \nonterm{type-name} \lstinline$)$ \lstinline${$ \nonterm{initializer-list} \lstinline$,$ \lstinline$}$692 \rhs \nonterm{postfix-expression} \lstinline@[@ \nonterm{expression} \lstinline@]@ 693 \rhs \nonterm{postfix-expression} \lstinline@(@ 694 \nonterm{argument-expression-list}\opt \lstinline@)@ 695 \rhs \nonterm{postfix-expression} \lstinline@.@ \nonterm{identifier} 696 \rhs \nonterm{postfix-expression} \lstinline@->@ \nonterm{identifier} 697 \rhs \nonterm{postfix-expression} \lstinline@++@ 698 \rhs \nonterm{postfix-expression} \lstinline@--@ 699 \rhs \lstinline@(@ \nonterm{type-name} \lstinline@)@ \lstinline@{@ \nonterm{initializer-list} \lstinline@}@ 700 \rhs \lstinline@(@ \nonterm{type-name} \lstinline@)@ \lstinline@{@ \nonterm{initializer-list} \lstinline@,@ \lstinline@}@ 834 701 \lhs{argument-expression-list} 835 702 \rhs \nonterm{assignment-expression} 836 \rhs \nonterm{argument-expression-list} \lstinline $,$703 \rhs \nonterm{argument-expression-list} \lstinline@,@ 837 704 \nonterm{assignment-expression} 838 705 \end{syntax} … … 840 707 \rewriterules 841 708 \begin{lstlisting} 842 a[b] @\rewrite@ ?[?]( b, a ) // if a has integer type@\use{?[?]}@843 a[b] @\rewrite@?[?]( a, b ) // otherwise844 a( @\emph{arguments}@ ) @\rewrite@ ?()( a, @\emph{arguments}@ )@\use{?()}@845 a++ @\rewrite@ ?++(&( a ))@\use{?++}@846 a-- @\rewrite@ ?--(&( a ))@\use{?--}@709 a[b] §\rewrite§ ?[?]( b, a ) // if a has integer type§\use{?[?]}§ 710 a[b] §\rewrite§ ?[?]( a, b ) // otherwise 711 a( §\emph{arguments}§ ) §\rewrite§ ?()( a, §\emph{arguments}§ )§\use{?()}§ 712 a++ §\rewrite§ ?++(&( a ))§\use{?++}§ 713 a-- §\rewrite§ ?--(&( a ))§\use{?--}§ 847 714 \end{lstlisting} 848 715 … … 852 719 \predefined 853 720 \begin{lstlisting} 854 forall( otype T ) lvalue T ?[?]( T *, ptrdiff_t ); @\use{ptrdiff_t}@721 forall( otype T ) lvalue T ?[?]( T *, ptrdiff_t );§\use{ptrdiff_t}§ 855 722 forall( otype T ) lvalue _Atomic T ?[?]( _Atomic T *, ptrdiff_t ); 856 723 forall( otype T ) lvalue const T ?[?]( const T *, ptrdiff_t ); … … 872 739 The interpretations of subscript expressions are the interpretations of the corresponding function call expressions. 873 740 \begin{rationale} 874 C defines subscripting as pointer arithmetic in a way that makes \lstinline $a[i]$and875 \lstinline $i[a]$ equivalent. \CFA provides the equivalence through a rewrite rule to reduce the number of overloadings of \lstinline$?[?]$.741 C defines subscripting as pointer arithmetic in a way that makes \lstinline@a[i]@ and 742 \lstinline@i[a]@ equivalent. \CFA provides the equivalence through a rewrite rule to reduce the number of overloadings of \lstinline@?[?]@. 876 743 877 744 Subscript expressions are rewritten as function calls that pass the first parameter by value. 878 745 This is somewhat unfortunate, since array-like types tend to be large. 879 The alternative is to use the rewrite rule ``\lstinline $a[b]$ \rewrite \lstinline$?[?](&(a), b)$''.880 However, C semantics forbid this approach: the \lstinline $a$ in ``\lstinline$a[b]$'' can be an arbitrary pointer value, which does not have an address.746 The alternative is to use the rewrite rule ``\lstinline@a[b]@ \rewrite \lstinline@?[?](&(a), b)@''. 747 However, C semantics forbid this approach: the \lstinline@a@ in ``\lstinline@a[b]@'' can be an arbitrary pointer value, which does not have an address. 881 748 882 749 The repetitive form of the predefined identifiers shows up a deficiency\index{deficiencies!pointers … … 893 760 \nonterm{postfix-expression} in a function call may have some interpretations that are function designators and some that are not. 894 761 895 For those interpretations of the \nonterm{postfix-expression} that are not function designators, the expression is rewritten and becomes a call of a function named ``\lstinline $?()$''.762 For those interpretations of the \nonterm{postfix-expression} that are not function designators, the expression is rewritten and becomes a call of a function named ``\lstinline@?()@''. 896 763 The valid interpretations of the rewritten expression are determined in the manner described below. 897 764 … … 901 768 \item if the argument corresponds to a parameter in the function designator's prototype, the argument interpretation must have the same type as the corresponding parameter, or be implicitly convertible to the parameter's type 902 769 \item if the function designator's type does not include a prototype or if the argument corresponds to 903 ``\lstinline $...$'' in a prototype, a \Index{default argument promotion} is applied to it.770 ``\lstinline@...@'' in a prototype, a \Index{default argument promotion} is applied to it. 904 771 \end{itemize} 905 772 The type of the valid interpretation is the return type of the function designator. … … 909 776 \begin{itemize} 910 777 \item 911 If the declaration of the implicit parameter uses \Index{type-class} \lstinline $type$\use{type}, the implicit argument must be an object type;912 if it uses \lstinline $dtype$, the implicit argument must be an object type or an incomplete type;913 and if it uses \lstinline $ftype$, the implicit argument must be a function type.778 If the declaration of the implicit parameter uses \Index{type-class} \lstinline@type@\use{type}, the implicit argument must be an object type; 779 if it uses \lstinline@dtype@, the implicit argument must be an object type or an incomplete type; 780 and if it uses \lstinline@ftype@, the implicit argument must be a function type. 914 781 915 782 \item if an explicit parameter's type uses any implicit parameters, then the corresponding explicit argument must have a type that is (or can be safely converted\index{safe conversion} to) the type produced by substituting the implicit arguments for the implicit parameters in the explicit parameter type. … … 930 797 \begin{rationale} 931 798 One desirable property of a polymorphic programming language is \define{generalizability}: the ability to replace an abstraction with a more general but equivalent abstraction without requiring changes in any of the uses of the original\cite{Cormack90}. 932 For instance, it should be possible to replace a function ``\lstinline $int f( int );$'' with ``\lstinline$forall( otype T ) T f( T );$'' without affecting any calls of \lstinline$f$.799 For instance, it should be possible to replace a function ``\lstinline@int f( int );@'' with ``\lstinline@forall( otype T ) T f( T );@'' without affecting any calls of \lstinline@f@. 933 800 934 801 \CFA\index{deficiencies!generalizability} does not fully possess this property, because … … 944 811 f = g( d, f ); // (3) (unsafe conversion to float) 945 812 \end{lstlisting} 946 If \lstinline $g$ was replaced by ``\lstinline$forall( otype T ) T g( T, T );$'', the first and second calls would be unaffected, but the third would change: \lstinline$f$would be converted to947 \lstinline $double$, and the result would be a \lstinline$double$.948 949 Another example is the function ``\lstinline $void h( int *);$''.813 If \lstinline@g@ was replaced by ``\lstinline@forall( otype T ) T g( T, T );@'', the first and second calls would be unaffected, but the third would change: \lstinline@f@ would be converted to 814 \lstinline@double@, and the result would be a \lstinline@double@. 815 816 Another example is the function ``\lstinline@void h( int *);@''. 950 817 This function can be passed a 951 \lstinline $void *$ argument, but the generalization ``\lstinline$forall( otype T ) void h( T *);$'' can not.952 In this case, \lstinline $void$ is not a valid value for \lstinline$T$because it is not an object type.953 If unsafe conversions were allowed, \lstinline $T$could be inferred to be \emph{any} object type, which is undesirable.818 \lstinline@void *@ argument, but the generalization ``\lstinline@forall( otype T ) void h( T *);@'' can not. 819 In this case, \lstinline@void@ is not a valid value for \lstinline@T@ because it is not an object type. 820 If unsafe conversions were allowed, \lstinline@T@ could be inferred to be \emph{any} object type, which is undesirable. 954 821 \end{rationale} 955 822 956 823 \examples 957 A function called ``\lstinline $?()$'' might be part of a numerical differentiation package.824 A function called ``\lstinline@?()@'' might be part of a numerical differentiation package. 958 825 \begin{lstlisting} 959 826 extern otype Derivative; … … 966 833 d = sin_dx( 12.9 ); 967 834 \end{lstlisting} 968 Here, the only interpretation of \lstinline $sin_dx$ is as an object of type \lstinline$Derivative$.969 For that interpretation, the function call is treated as ``\lstinline $?()( sin_dx, 12.9 )$''.835 Here, the only interpretation of \lstinline@sin_dx@ is as an object of type \lstinline@Derivative@. 836 For that interpretation, the function call is treated as ``\lstinline@?()( sin_dx, 12.9 )@''. 970 837 \begin{lstlisting} 971 838 int f( long ); // (1) … … 974 841 int i = f( 5 ); // calls (1) 975 842 \end{lstlisting} 976 Function (1) provides a valid interpretation of ``\lstinline $f( 5 )$'', using an implicit \lstinline$int$ to \lstinline$long$conversion.977 The other functions do not, since the second requires two arguments, and since there is no implicit conversion from \lstinline $int$ to \lstinline$int *$that could be used with the third function.843 Function (1) provides a valid interpretation of ``\lstinline@f( 5 )@'', using an implicit \lstinline@int@ to \lstinline@long@ conversion. 844 The other functions do not, since the second requires two arguments, and since there is no implicit conversion from \lstinline@int@ to \lstinline@int *@ that could be used with the third function. 978 845 979 846 \begin{lstlisting} … … 981 848 double d = h( 1.5 ); 982 849 \end{lstlisting} 983 ``\lstinline $1.5$'' is a \lstinline$double$ constant, so \lstinline$T$is inferred to be984 \lstinline $double$, and the result of the function call is a \lstinline$double$.850 ``\lstinline@1.5@'' is a \lstinline@double@ constant, so \lstinline@T@ is inferred to be 851 \lstinline@double@, and the result of the function call is a \lstinline@double@. 985 852 986 853 \begin{lstlisting} … … 997 864 g( i, p ); // calls (4) 998 865 \end{lstlisting} 999 The first call has valid interpretations for all four versions of \lstinline $g$. (6) and (7) are discarded because they involve unsafe \lstinline$double$-to-\lstinline$long$conversions. (5) is chosen because it is less polymorphic than (4).866 The first call has valid interpretations for all four versions of \lstinline@g@. (6) and (7) are discarded because they involve unsafe \lstinline@double@-to-\lstinline@long@ conversions. (5) is chosen because it is less polymorphic than (4). 1000 867 1001 868 For the second call, (7) is again discarded. 1002 Of the remaining interpretations for (4), (5), and (6) (with \lstinline $i$ converted to \lstinline$long$), (6) is chosen because it is the least polymorphic.869 Of the remaining interpretations for (4), (5), and (6) (with \lstinline@i@ converted to \lstinline@long@), (6) is chosen because it is the least polymorphic. 1003 870 1004 871 The third call has valid interpretations for all of the functions; … … 1009 876 forall( otype T ) T min( T, T ); 1010 877 double max( double, double ); 1011 trait min_max( T ) { @\impl{min_max}@878 trait min_max( T ) {§\impl{min_max}§ 1012 879 T min( T, T ); 1013 880 T max( T, T ); … … 1016 883 shuffle( 9, 10 ); 1017 884 \end{lstlisting} 1018 The only possibility for \lstinline $U$ is \lstinline$double$, because that is the type used in the only visible \lstinline$max$ function. 9 and 10 must be converted to \lstinline$double$, and1019 \lstinline $min$ must be specialized with \lstinline$T$ bound to \lstinline$double$.885 The only possibility for \lstinline@U@ is \lstinline@double@, because that is the type used in the only visible \lstinline@max@ function. 9 and 10 must be converted to \lstinline@double@, and 886 \lstinline@min@ must be specialized with \lstinline@T@ bound to \lstinline@double@. 1020 887 \begin{lstlisting} 1021 888 extern void q( int ); // (8) … … 1025 892 r( 0 ); 1026 893 \end{lstlisting} 1027 The \lstinline $int 0$ could be passed to (8), or the \lstinline$(void *)$ \Index{specialization} of the null pointer\index{null pointer} \lstinline$0$\use{0} could be passed to (9).1028 The former is chosen because the \lstinline $int$ \lstinline$0$is \Index{less polymorphic}.1029 For the same reason, \lstinline $int$ \lstinline$0$ is passed to \lstinline$r()$, even though it has \emph{no} declared parameter types.894 The \lstinline@int 0@ could be passed to (8), or the \lstinline@(void *)@ \Index{specialization} of the null pointer\index{null pointer} \lstinline@0@\use{0} could be passed to (9). 895 The former is chosen because the \lstinline@int@ \lstinline@0@ is \Index{less polymorphic}. 896 For the same reason, \lstinline@int@ \lstinline@0@ is passed to \lstinline@r()@, even though it has \emph{no} declared parameter types. 1030 897 1031 898 1032 899 \subsubsection{Structure and union members} 1033 900 1034 \semantics In the member selection expression ``\lstinline $s$.\lstinline$m$'', there shall be at least one interpretation of \lstinline$s$ whose type is a structure type or union type containing a member named \lstinline$m$.1035 If two or more interpretations of \lstinline $s$have members named1036 \lstinline $m$with mutually compatible types, then the expression has an \Index{ambiguous interpretation} whose type is the composite type of the types of the members.1037 If an interpretation of \lstinline $s$ has a member \lstinline$m$whose type is not compatible with any other1038 \lstinline $s$'s \lstinline$m$, then the expression has an interpretation with the member's type.901 \semantics In the member selection expression ``\lstinline@s@.\lstinline@m@'', there shall be at least one interpretation of \lstinline@s@ whose type is a structure type or union type containing a member named \lstinline@m@. 902 If two or more interpretations of \lstinline@s@ have members named 903 \lstinline@m@ with mutually compatible types, then the expression has an \Index{ambiguous interpretation} whose type is the composite type of the types of the members. 904 If an interpretation of \lstinline@s@ has a member \lstinline@m@ whose type is not compatible with any other 905 \lstinline@s@'s \lstinline@m@, then the expression has an interpretation with the member's type. 1039 906 The expression has no other interpretations. 1040 907 1041 The expression ``\lstinline$p->m$'' has the same interpretations as the expression 1042 ``\lstinline$(*p).m$''. 908 The expression ``\lstinline@p->m@'' has the same interpretations as the expression ``\lstinline@(*p).m@''. 1043 909 1044 910 … … 1135 1001 * ?--( _Atomic const restrict volatile T * _Atomic restrict volatile * ); 1136 1002 \end{lstlisting} 1137 For every extended integer type \lstinline $X$there exist1003 For every extended integer type \lstinline@X@ there exist 1138 1004 % Don't use predefined: keep this out of prelude.cf. 1139 1005 \begin{lstlisting} … … 1141 1007 ?--( volatile X * ), ?--( _Atomic volatile X * ); 1142 1008 \end{lstlisting} 1143 For every complete enumerated type \lstinline $E$there exist1009 For every complete enumerated type \lstinline@E@ there exist 1144 1010 % Don't use predefined: keep this out of prelude.cf. 1145 1011 \begin{lstlisting} … … 1149 1015 1150 1016 \begin{rationale} 1151 Note that ``\lstinline $++$'' and ``\lstinline$--$'' are rewritten as function calls that are given a pointer to that operand. (This is true of all operators that modify an operand.) As Hamish Macdonald has pointed out, this forces the modified operand of such expressions to be an lvalue.1017 Note that ``\lstinline@++@'' and ``\lstinline@--@'' are rewritten as function calls that are given a pointer to that operand. (This is true of all operators that modify an operand.) As Hamish Macdonald has pointed out, this forces the modified operand of such expressions to be an lvalue. 1152 1018 This partially enforces the C semantic rule that such operands must be \emph{modifiable} lvalues. 1153 1019 \end{rationale} … … 1155 1021 \begin{rationale} 1156 1022 In C, a semantic rule requires that pointer operands of increment and decrement be pointers to object types. 1157 Hence, \lstinline $void *$objects cannot be incremented.1158 In \CFA, the restriction follows from the use of a \lstinline $type$ parameter in the predefined function definitions, as opposed to \lstinline$dtype$, since only object types can be inferred arguments corresponding to the type parameter \lstinline$T$.1023 Hence, \lstinline@void *@ objects cannot be incremented. 1024 In \CFA, the restriction follows from the use of a \lstinline@type@ parameter in the predefined function definitions, as opposed to \lstinline@dtype@, since only object types can be inferred arguments corresponding to the type parameter \lstinline@T@. 1159 1025 \end{rationale} 1160 1026 1161 1027 \semantics 1162 1028 First, each interpretation of the operand of an increment or decrement expression is considered separately. 1163 For each interpretation that is a bit-field or is declared with the 1164 \lstinline$register$\index{register@{\lstinline$register$}} \index{Itorage-class specifier}, the expression has one valid interpretation, with the type of the operand, and the expression is ambiguous if the operand is. 1029 For each interpretation that is a bit-field or is declared with the \Indexc{register}\index{storage-class specifier}, the expression has one valid interpretation, with the type of the operand, and the expression is ambiguous if the operand is. 1165 1030 1166 1031 For the remaining interpretations, the expression is rewritten, and the interpretations of the expression are the interpretations of the corresponding function call. … … 1175 1040 \end{lstlisting} 1176 1041 \begin{sloppypar} 1177 Since \lstinline$&(vs)$ has type \lstinline$volatile short int *$, the best valid interpretation of 1178 \lstinline$vs++$ calls the \lstinline$?++$ function with the \lstinline$volatile short *$ parameter. 1179 \lstinline$s++$ does the same, applying the safe conversion from \lstinline$short int *$ to 1180 \lstinline$volatile short int *$. 1181 Note that there is no conversion that adds an \lstinline$_Atomic$ qualifier, so the \lstinline$_Atomic volatile short int$ overloading does not provide a valid interpretation. 1042 Since \lstinline@&(vs)@ has type \lstinline@volatile short int *@, the best valid interpretation of 1043 \lstinline@vs++@ calls the \lstinline@?++@ function with the \lstinline@volatile short *@ parameter. 1044 \lstinline@s++@ does the same, applying the safe conversion from \lstinline@short int *@ to \lstinline@volatile short int *@. 1045 Note that there is no conversion that adds an \lstinline@_Atomic@ qualifier, so the \lstinline@_Atomic volatile short int@ overloading does not provide a valid interpretation. 1182 1046 \end{sloppypar} 1183 1047 1184 There is no safe conversion from \lstinline $const short int *$ to \lstinline$volatile short int *$, and no \lstinline$?++$ function that accepts a \lstinline$const *$ parameter, so \lstinline$cs++$has no valid interpretations.1185 1186 The best valid interpretation of \lstinline $as++$ calls the \lstinline$short ?++$ function with the \lstinline$_Atomic volatile short int *$ parameter, applying a safe conversion to add the \lstinline$volatile$qualifier.1048 There is no safe conversion from \lstinline@const short int *@ to \lstinline@volatile short int *@, and no \lstinline@?++@ function that accepts a \lstinline@const *@ parameter, so \lstinline@cs++@ has no valid interpretations. 1049 1050 The best valid interpretation of \lstinline@as++@ calls the \lstinline@short ?++@ function with the \lstinline@_Atomic volatile short int *@ parameter, applying a safe conversion to add the \lstinline@volatile@ qualifier. 1187 1051 \begin{lstlisting} 1188 1052 char * const restrict volatile * restrict volatile pqpc; … … 1191 1055 ppc++; 1192 1056 \end{lstlisting} 1193 Since \lstinline $&(pqpc)$ has type \lstinline$char * const restrict volatile * restrict volatile *$, the best valid interpretation of \lstinline$pqpc++$ calls the polymorphic \lstinline$?++$ function with the \lstinline$const restrict volatile T * restrict volatile *$ parameter, inferring \lstinline$T$ to be \lstinline$char *$.1194 1195 \lstinline $ppc++$ calls the same function, again inferring \lstinline$T$ to be \lstinline$char *$, and using the safe conversions from \lstinline$T$ to \lstinline$T const$ \lstinline$restrict volatile$.1057 Since \lstinline@&(pqpc)@ has type \lstinline@char * const restrict volatile * restrict volatile *@, the best valid interpretation of \lstinline@pqpc++@ calls the polymorphic \lstinline@?++@ function with the \lstinline@const restrict volatile T * restrict volatile *@ parameter, inferring \lstinline@T@ to be \lstinline@char *@. 1058 1059 \lstinline@ppc++@ calls the same function, again inferring \lstinline@T@ to be \lstinline@char *@, and using the safe conversions from \lstinline@T@ to \lstinline@T const@ \lstinline@restrict volatile@. 1196 1060 1197 1061 \begin{rationale} … … 1207 1071 \begin{enumerate} 1208 1072 \item 1209 ``\lstinline $char * p; p++;$''.1210 The argument to \lstinline $?++$ has type \lstinline$char * *$, and the result has type \lstinline$char *$.1211 The expression would be valid if \lstinline $?++$were declared by1073 ``\lstinline@char * p; p++;@''. 1074 The argument to \lstinline@?++@ has type \lstinline@char * *@, and the result has type \lstinline@char *@. 1075 The expression would be valid if \lstinline@?++@ were declared by 1212 1076 \begin{lstlisting} 1213 1077 forall( otype T ) T * ?++( T * * ); 1214 \end{lstlisting} with \lstinline $T$ inferred to be \lstinline$char$.1215 1216 \item 1217 ``\lstinline $char *restrict volatile qp; qp++$''.1218 The result again has type \lstinline $char *$, but the argument now has type \lstinline$char *restrict volatile *$, so it cannot be passed to the hypothetical function declared in point 1.1078 \end{lstlisting} with \lstinline@T@ inferred to be \lstinline@char@. 1079 1080 \item 1081 ``\lstinline@char *restrict volatile qp; qp++@''. 1082 The result again has type \lstinline@char *@, but the argument now has type \lstinline@char *restrict volatile *@, so it cannot be passed to the hypothetical function declared in point 1. 1219 1083 Hence the actual predefined function is 1220 1084 \begin{lstlisting} 1221 1085 forall( otype T ) T * ?++( T * restrict volatile * ); 1222 \end{lstlisting} which also accepts a \lstinline $char * *$argument, because of the safe conversions that add1223 \lstinline $volatile$ and \lstinline$restrict$qualifiers. (The parameter is not const-qualified, so constant pointers cannot be incremented.)1224 1225 \item 1226 ``\lstinline $char *_Atomic ap; ap++$''.1227 The result again has type \lstinline $char *$, but no safe conversion adds an \lstinline$_Atomic$qualifier, so the function in point 2 is not applicable.1228 A separate overloading of \lstinline $?++$is required.1229 1230 \item 1231 ``\lstinline $char const volatile * pq; pq++$''.1086 \end{lstlisting} which also accepts a \lstinline@char * *@ argument, because of the safe conversions that add 1087 \lstinline@volatile@ and \lstinline@restrict@ qualifiers. (The parameter is not const-qualified, so constant pointers cannot be incremented.) 1088 1089 \item 1090 ``\lstinline@char *_Atomic ap; ap++@''. 1091 The result again has type \lstinline@char *@, but no safe conversion adds an \lstinline@_Atomic@ qualifier, so the function in point 2 is not applicable. 1092 A separate overloading of \lstinline@?++@ is required. 1093 1094 \item 1095 ``\lstinline@char const volatile * pq; pq++@''. 1232 1096 Here the result has type 1233 \lstinline $char const volatile *$, so a new overloading is needed:1097 \lstinline@char const volatile *@, so a new overloading is needed: 1234 1098 \begin{lstlisting} 1235 1099 forall( otype T ) T const volatile * ?++( T const volatile *restrict volatile * ); … … 1238 1102 1239 1103 \item 1240 ``\lstinline $float *restrict * prp; prp++$''.1241 The \lstinline $restrict$ qualifier is handled just like \lstinline$const$ and \lstinline$volatile$in the previous case:1104 ``\lstinline@float *restrict * prp; prp++@''. 1105 The \lstinline@restrict@ qualifier is handled just like \lstinline@const@ and \lstinline@volatile@ in the previous case: 1242 1106 \begin{lstlisting} 1243 1107 forall( otype T ) T restrict * ?++( T restrict *restrict volatile * ); 1244 \end{lstlisting} with \lstinline $T$ inferred to be \lstinline$float *$.1245 This looks odd, because {\c11} contains a constraint that requires restrict-qualified types to be pointer-to-object types, and \lstinline $T$is not syntactically a pointer type. \CFA loosens the constraint.1108 \end{lstlisting} with \lstinline@T@ inferred to be \lstinline@float *@. 1109 This looks odd, because {\c11} contains a constraint that requires restrict-qualified types to be pointer-to-object types, and \lstinline@T@ is not syntactically a pointer type. \CFA loosens the constraint. 1246 1110 \end{enumerate} 1247 1111 \end{rationale} … … 1259 1123 \lhs{unary-expression} 1260 1124 \rhs \nonterm{postfix-expression} 1261 \rhs \lstinline $++$\nonterm{unary-expression}1262 \rhs \lstinline $--$\nonterm{unary-expression}1125 \rhs \lstinline@++@ \nonterm{unary-expression} 1126 \rhs \lstinline@--@ \nonterm{unary-expression} 1263 1127 \rhs \nonterm{unary-operator} \nonterm{cast-expression} 1264 \rhs \lstinline $sizeof$\nonterm{unary-expression}1265 \rhs \lstinline $sizeof$ \lstinline$($ \nonterm{type-name} \lstinline$)$1266 \lhs{unary-operator} one of \rhs \lstinline $&$ \lstinline$*$ \lstinline$+$ \lstinline$-$ \lstinline$~$ \lstinline$!$1128 \rhs \lstinline@sizeof@ \nonterm{unary-expression} 1129 \rhs \lstinline@sizeof@ \lstinline@(@ \nonterm{type-name} \lstinline@)@ 1130 \lhs{unary-operator} one of \rhs \lstinline@&@ \lstinline@*@ \lstinline@+@ \lstinline@-@ \lstinline@~@ \lstinline@!@ 1267 1131 \end{syntax} 1268 1132 1269 1133 \rewriterules 1270 1134 \begin{lstlisting} 1271 *a @\rewrite@ *?( a ) @\use{*?}@1272 +a @\rewrite@ +?( a ) @\use{+?}@1273 -a @\rewrite@ -?( a ) @\use{-?}@1274 ~a @\rewrite@ ~?( a ) @\use{~?}@1275 !a @\rewrite@ !?( a ) @\use{"!?}@1276 ++a @\rewrite@ ++?(&( a )) @\use{++?}@1277 --a @\rewrite@ --?(&( a )) @\use{--?}@1135 *a §\rewrite§ *?( a ) §\use{*?}§ 1136 +a §\rewrite§ +?( a ) §\use{+?}§ 1137 -a §\rewrite§ -?( a ) §\use{-?}§ 1138 ~a §\rewrite§ ~?( a ) §\use{~?}§ 1139 !a §\rewrite§ !?( a ) §\use{"!?}§ 1140 ++a §\rewrite§ ++?(&( a )) §\use{++?}§ 1141 --a §\rewrite§ --?(&( a )) §\use{--?}§ 1278 1142 \end{lstlisting} 1279 1143 … … 1371 1235 * --?( _Atomic const restrict volatile T * _Atomic restrict volatile * ); 1372 1236 \end{lstlisting} 1373 For every extended integer type \lstinline $X$there exist1237 For every extended integer type \lstinline@X@ there exist 1374 1238 % Don't use predefined: keep this out of prelude.cf. 1375 1239 \begin{lstlisting} … … 1379 1243 --?( _Atomic volatile X * ); 1380 1244 \end{lstlisting} 1381 For every complete enumerated type \lstinline $E$there exist1245 For every complete enumerated type \lstinline@E@ there exist 1382 1246 % Don't use predefined: keep this out of prelude.cf. 1383 1247 \begin{lstlisting} … … 1416 1280 1417 1281 \constraints 1418 The operand of the unary ``\lstinline $&$'' operator shall have exactly one1282 The operand of the unary ``\lstinline@&@'' operator shall have exactly one 1419 1283 \Index{interpretation}\index{ambiguous interpretation}, which shall be unambiguous. 1420 1284 1421 1285 \semantics 1422 The ``\lstinline $&$'' expression has one interpretation which is of type \lstinline$T *$, where1423 \lstinline $T$is the type of the operand.1286 The ``\lstinline@&@'' expression has one interpretation which is of type \lstinline@T *@, where 1287 \lstinline@T@ is the type of the operand. 1424 1288 1425 1289 The interpretations of an indirection expression are the interpretations of the corresponding function call. … … 1450 1314 forall( ftype FT ) int !?( FT * ); 1451 1315 \end{lstlisting} 1452 For every extended integer type \lstinline $X$ with \Index{integer conversion rank} greater than the rank of \lstinline$int$there exist1316 For every extended integer type \lstinline@X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@ there exist 1453 1317 % Don't use predefined: keep this out of prelude.cf. 1454 1318 \begin{lstlisting} … … 1463 1327 \begin{lstlisting} 1464 1328 long int li; 1465 void eat_double( double ); @\use{eat_double}@1466 eat_double(-li ); // @\rewrite@eat_double( -?( li ) );1467 \end{lstlisting} 1468 The valid interpretations of ``\lstinline $-li$'' (assuming no extended integer types exist) are1329 void eat_double( double );§\use{eat_double}§ 1330 eat_double(-li ); // §\rewrite§ eat_double( -?( li ) ); 1331 \end{lstlisting} 1332 The valid interpretations of ``\lstinline@-li@'' (assuming no extended integer types exist) are 1469 1333 \begin{center} 1470 1334 \begin{tabular}{llc} interpretation & result type & expression conversion cost \\ 1471 1335 \hline 1472 \lstinline $-?( (int)li )$ & \lstinline$int$& (unsafe) \\1473 \lstinline $-?( (unsigned)li)$ & \lstinline$unsigned int$& (unsafe) \\1474 \lstinline $-?( (long)li)$ & \lstinline$long$& 0 \\1475 \lstinline $-?( (long unsigned int)li)$ & \lstinline$long unsigned int$& 1 \\1476 \lstinline $-?( (long long int)li)$ & \lstinline$long long int$& 2 \\1477 \lstinline $-?( (long long unsigned int)li)$ & \lstinline$long long unsigned int$& 3 \\1478 \lstinline $-?( (float)li)$ & \lstinline$float$& 4 \\1479 \lstinline $-?( (double)li)$ & \lstinline$double$& 5 \\1480 \lstinline $-?( (long double)li)$ & \lstinline$long double$& 6 \\1481 \lstinline $-?( (_Complex float)li)$ & \lstinline$float$& (unsafe) \\1482 \lstinline $-?( (_Complex double)li)$ & \lstinline$double$& (unsafe) \\1483 \lstinline $-?( (_Complex long double)li)$ & \lstinline$long double$& (unsafe) \\1336 \lstinline@-?( (int)li )@ & \lstinline@int@ & (unsafe) \\ 1337 \lstinline@-?( (unsigned)li)@ & \lstinline@unsigned int@ & (unsafe) \\ 1338 \lstinline@-?( (long)li)@ & \lstinline@long@ & 0 \\ 1339 \lstinline@-?( (long unsigned int)li)@ & \lstinline@long unsigned int@ & 1 \\ 1340 \lstinline@-?( (long long int)li)@ & \lstinline@long long int@ & 2 \\ 1341 \lstinline@-?( (long long unsigned int)li)@ & \lstinline@long long unsigned int@& 3 \\ 1342 \lstinline@-?( (float)li)@ & \lstinline@float@ & 4 \\ 1343 \lstinline@-?( (double)li)@ & \lstinline@double@ & 5 \\ 1344 \lstinline@-?( (long double)li)@ & \lstinline@long double@ & 6 \\ 1345 \lstinline@-?( (_Complex float)li)@ & \lstinline@float@ & (unsafe) \\ 1346 \lstinline@-?( (_Complex double)li)@ & \lstinline@double@ & (unsafe) \\ 1347 \lstinline@-?( (_Complex long double)li)@ & \lstinline@long double@ & (unsafe) \\ 1484 1348 \end{tabular} 1485 1349 \end{center} 1486 The valid interpretations of the \lstinline $eat_double$call, with the cost of the argument conversion and the cost of the entire expression, are1350 The valid interpretations of the \lstinline@eat_double@ call, with the cost of the argument conversion and the cost of the entire expression, are 1487 1351 \begin{center} 1488 1352 \begin{tabular}{lcc} interpretation & argument cost & expression cost \\ 1489 1353 \hline 1490 \lstinline $eat_double( (double)-?( (int)li) )$& 7 & (unsafe) \\1491 \lstinline $eat_double( (double)-?( (unsigned)li) )$& 6 & (unsafe) \\1492 \lstinline $eat_double( (double)-?(li) )$& 5 & \(0+5=5\) \\1493 \lstinline $eat_double( (double)-?( (long unsigned int)li) )$& 4 & \(1+4=5\) \\1494 \lstinline $eat_double( (double)-?( (long long int)li) )$& 3 & \(2+3=5\) \\1495 \lstinline $eat_double( (double)-?( (long long unsigned int)li) )$& 2 & \(3+2=5\) \\1496 \lstinline $eat_double( (double)-?( (float)li) )$& 1 & \(4+1=5\) \\1497 \lstinline $eat_double( (double)-?( (double)li) )$& 0 & \(5+0=5\) \\1498 \lstinline $eat_double( (double)-?( (long double)li) )$& (unsafe) & (unsafe) \\1499 \lstinline $eat_double( (double)-?( (_Complex float)li) )$& (unsafe) & (unsafe) \\1500 \lstinline $eat_double( (double)-?( (_Complex double)li) )$& (unsafe) & (unsafe) \\1501 \lstinline $eat_double( (double)-?( (_Complex long double)li) )$& (unsafe) & (unsafe) \\1354 \lstinline@eat_double( (double)-?( (int)li) )@ & 7 & (unsafe) \\ 1355 \lstinline@eat_double( (double)-?( (unsigned)li) )@ & 6 & (unsafe) \\ 1356 \lstinline@eat_double( (double)-?(li) )@ & 5 & \(0+5=5\) \\ 1357 \lstinline@eat_double( (double)-?( (long unsigned int)li) )@ & 4 & \(1+4=5\) \\ 1358 \lstinline@eat_double( (double)-?( (long long int)li) )@ & 3 & \(2+3=5\) \\ 1359 \lstinline@eat_double( (double)-?( (long long unsigned int)li) )@& 2 & \(3+2=5\) \\ 1360 \lstinline@eat_double( (double)-?( (float)li) )@ & 1 & \(4+1=5\) \\ 1361 \lstinline@eat_double( (double)-?( (double)li) )@ & 0 & \(5+0=5\) \\ 1362 \lstinline@eat_double( (double)-?( (long double)li) )@ & (unsafe) & (unsafe) \\ 1363 \lstinline@eat_double( (double)-?( (_Complex float)li) )@ & (unsafe) & (unsafe) \\ 1364 \lstinline@eat_double( (double)-?( (_Complex double)li) )@ & (unsafe) & (unsafe) \\ 1365 \lstinline@eat_double( (double)-?( (_Complex long double)li) )@ & (unsafe) & (unsafe) \\ 1502 1366 \end{tabular} 1503 1367 \end{center} 1504 Each has result type \lstinline $void$, so the best must be selected.1368 Each has result type \lstinline@void@, so the best must be selected. 1505 1369 The interpretations involving unsafe conversions are discarded. 1506 1370 The remainder have equal expression conversion costs, so the 1507 1371 ``highest argument conversion cost'' rule is invoked, and the chosen interpretation is 1508 \lstinline $eat_double( (double)-?(li) )$.1509 1510 1511 \subsubsection {The \lstinline$sizeof$ and \lstinline$_Alignof$operators}1372 \lstinline@eat_double( (double)-?(li) )@. 1373 1374 1375 \subsubsection[The sizeof and \_Alignof operators]{The \lstinline@sizeof@ and \lstinline@_Alignof@ operators} 1512 1376 1513 1377 \constraints 1514 The operand of \lstinline$sizeof$ or \lstinline$_Alignof$ shall not be \lstinline$type$, 1515 \lstinline$dtype$, or \lstinline$ftype$. 1516 1517 When the \lstinline$sizeof$\use{sizeof} operator is applied to an expression, the expression shall have exactly one \Index{interpretation}\index{ambiguous interpretation}, which shall be unambiguous. \semantics A \lstinline$sizeof$ or \lstinline$_Alignof$ expression has one interpretation, of type \lstinline$size_t$. 1518 1519 When \lstinline$sizeof$ is applied to an identifier declared by a \nonterm{type-declaration} or a 1378 The operand of \lstinline@sizeof@ or \lstinline@_Alignof@ shall not be \lstinline@type@, \lstinline@dtype@, or \lstinline@ftype@. 1379 1380 When the \lstinline@sizeof@\use{sizeof} operator is applied to an expression, the expression shall have exactly one \Index{interpretation}\index{ambiguous interpretation}, which shall be unambiguous. \semantics A \lstinline@sizeof@ or \lstinline@_Alignof@ expression has one interpretation, of type \lstinline@size_t@. 1381 1382 When \lstinline@sizeof@ is applied to an identifier declared by a \nonterm{type-declaration} or a 1520 1383 \nonterm{type-parameter}, it yields the size in bytes of the type that implements the operand. 1521 1384 When the operand is an opaque type or an inferred type parameter\index{inferred parameter}, the expression is not a constant expression. 1522 1385 1523 When \lstinline $_Alignof$is applied to an identifier declared by a \nonterm{type-declaration} or a1386 When \lstinline@_Alignof@ is applied to an identifier declared by a \nonterm{type-declaration} or a 1524 1387 \nonterm{type-parameter}, it yields the alignment requirement of the type that implements the operand. 1525 1388 When the operand is an opaque type or an inferred type parameter\index{inferred parameter}, the expression is not a constant expression. … … 1528 1391 otype Pair = struct { int first, second; }; 1529 1392 size_t p_size = sizeof(Pair); // constant expression 1530 extern otype Rational; @\use{Rational}@1393 extern otype Rational;§\use{Rational}§ 1531 1394 size_t c_size = sizeof(Rational); // non-constant expression 1532 1395 forall(type T) T f(T p1, T p2) { … … 1535 1398 } 1536 1399 \end{lstlisting} 1537 ``\lstinline $sizeof Rational$'', although not statically known, is fixed.1538 Within \lstinline $f()$,1539 ``\lstinline $sizeof(T)$'' is fixed for each call of \lstinline$f()$, but may vary from call to call.1400 ``\lstinline@sizeof Rational@'', although not statically known, is fixed. 1401 Within \lstinline@f()@, 1402 ``\lstinline@sizeof(T)@'' is fixed for each call of \lstinline@f()@, but may vary from call to call. 1540 1403 \end{rationale} 1541 1404 … … 1546 1409 \lhs{cast-expression} 1547 1410 \rhs \nonterm{unary-expression} 1548 \rhs \lstinline $($ \nonterm{type-name} \lstinline$)$\nonterm{cast-expression}1411 \rhs \lstinline@(@ \nonterm{type-name} \lstinline@)@ \nonterm{cast-expression} 1549 1412 \end{syntax} 1550 1413 1551 1414 \constraints 1552 The \nonterm{type-name} in a \nonterm{cast-expression} shall not be \lstinline $type$,1553 \lstinline $dtype$, or \lstinline$ftype$.1415 The \nonterm{type-name} in a \nonterm{cast-expression} shall not be \lstinline@type@, 1416 \lstinline@dtype@, or \lstinline@ftype@. 1554 1417 1555 1418 \semantics 1556 1419 1557 In a \Index{cast expression} ``\lstinline $($\nonterm{type-name}\lstinline$)e$'', if1558 \nonterm{type-name} is the type of an interpretation of \lstinline $e$, then that interpretation is the only interpretation of the cast expression;1559 otherwise, \lstinline $e$shall have some interpretation that can be converted to \nonterm{type-name}, and the interpretation of the cast expression is the cast of the interpretation that can be converted at the lowest cost.1420 In a \Index{cast expression} ``\lstinline@(@\nonterm{type-name}\lstinline@)e@'', if 1421 \nonterm{type-name} is the type of an interpretation of \lstinline@e@, then that interpretation is the only interpretation of the cast expression; 1422 otherwise, \lstinline@e@ shall have some interpretation that can be converted to \nonterm{type-name}, and the interpretation of the cast expression is the cast of the interpretation that can be converted at the lowest cost. 1560 1423 The cast expression's interpretation is ambiguous\index{ambiguous interpretation} if more than one interpretation can be converted at the lowest cost or if the selected interpretation is ambiguous. 1561 1424 … … 1570 1433 \lhs{multiplicative-expression} 1571 1434 \rhs \nonterm{cast-expression} 1572 \rhs \nonterm{multiplicative-expression} \lstinline $*$\nonterm{cast-expression}1573 \rhs \nonterm{multiplicative-expression} \lstinline $/$\nonterm{cast-expression}1574 \rhs \nonterm{multiplicative-expression} \lstinline $%$\nonterm{cast-expression}1435 \rhs \nonterm{multiplicative-expression} \lstinline@*@ \nonterm{cast-expression} 1436 \rhs \nonterm{multiplicative-expression} \lstinline@/@ \nonterm{cast-expression} 1437 \rhs \nonterm{multiplicative-expression} \lstinline@%@ \nonterm{cast-expression} 1575 1438 \end{syntax} 1576 1439 1577 1440 \rewriterules 1578 1441 \begin{lstlisting} 1579 a * b @\rewrite@ ?*?( a, b )@\use{?*?}@1580 a / b @\rewrite@ ?/?( a, b )@\use{?/?}@1581 a % b @\rewrite@ ?%?( a, b )@\use{?%?}@1442 a * b §\rewrite§ ?*?( a, b )§\use{?*?}§ 1443 a / b §\rewrite§ ?/?( a, b )§\use{?/?}§ 1444 a % b §\rewrite§ ?%?( a, b )§\use{?%?}§ 1582 1445 \end{lstlisting} 1583 1446 … … 1606 1469 ?*?( _Complex long double, _Complex long double ), ?/?( _Complex long double, _Complex long double ); 1607 1470 \end{lstlisting} 1608 For every extended integer type \lstinline $X$ with \Index{integer conversion rank} greater than the rank of \lstinline$int$there exist1471 For every extended integer type \lstinline@X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@ there exist 1609 1472 % Don't use predefined: keep this out of prelude.cf. 1610 1473 \begin{lstlisting} … … 1624 1487 int i; 1625 1488 long li; 1626 void eat_double( double ); @\use{eat_double}@1489 void eat_double( double );§\use{eat_double}§ 1627 1490 eat_double( li % i ); 1628 1491 \end{lstlisting} 1629 ``\lstinline $li % i$'' is rewritten as ``\lstinline$?%?(li, i )$''.1630 The valid interpretations of \lstinline $?%?(li, i )$, the cost\index{conversion cost} of converting their arguments, and the cost of converting the result to \lstinline$double$(assuming no extended integer types are present ) are1492 ``\lstinline@li % i@'' is rewritten as ``\lstinline@?%?(li, i )@''. 1493 The valid interpretations of \lstinline@?%?(li, i )@, the cost\index{conversion cost} of converting their arguments, and the cost of converting the result to \lstinline@double@ (assuming no extended integer types are present ) are 1631 1494 \begin{center} 1632 1495 \begin{tabular}{lcc} interpretation & argument cost & result cost \\ 1633 1496 \hline 1634 \lstinline $ ?%?( (int)li, i )$& (unsafe) & 6 \\1635 \lstinline $ ?%?( (unsigned)li,(unsigned)i )$& (unsafe) & 5 \\1636 \lstinline $ ?%?( li, (long)i )$& 1 & 4 \\1637 \lstinline $ ?%?( (long unsigned)li,(long unsigned)i )$& 3 & 3 \\1638 \lstinline $ ?%?( (long long)li,(long long)i )$& 5 & 2 \\1639 \lstinline $ ?%?( (long long unsigned)li, (long long unsigned)i )$& 7 & 1 \\1497 \lstinline@ ?%?( (int)li, i )@ & (unsafe) & 6 \\ 1498 \lstinline@ ?%?( (unsigned)li,(unsigned)i )@ & (unsafe) & 5 \\ 1499 \lstinline@ ?%?( li, (long)i )@ & 1 & 4 \\ 1500 \lstinline@ ?%?( (long unsigned)li,(long unsigned)i )@ & 3 & 3 \\ 1501 \lstinline@ ?%?( (long long)li,(long long)i )@ & 5 & 2 \\ 1502 \lstinline@ ?%?( (long long unsigned)li, (long long unsigned)i )@ & 7 & 1 \\ 1640 1503 \end{tabular} 1641 1504 \end{center} 1642 The best interpretation of \lstinline $eat_double( li, i )$is1643 \lstinline $eat_double( (double)?%?(li, (long)i ))$, which has no unsafe conversions and the lowest total cost.1644 1645 \begin{rationale} 1646 {\c11} defines most arithmetic operations to apply an \Index{integer promotion} to any argument that belongs to a type that has an \Index{integer conversion rank} less than that of \lstinline $int$.If1647 \lstinline $s$ is a \lstinline$short int$, ``\lstinline$s *s$'' does not have type \lstinline$short int$;1648 it is treated as ``\lstinline $( (int)s ) * ( (int)s )$'', and has type \lstinline$int$. \CFA matches that pattern;1649 it does not predefine ``\lstinline $short ?*?( short, short )$''.1505 The best interpretation of \lstinline@eat_double( li, i )@ is 1506 \lstinline@eat_double( (double)?%?(li, (long)i ))@, which has no unsafe conversions and the lowest total cost. 1507 1508 \begin{rationale} 1509 {\c11} defines most arithmetic operations to apply an \Index{integer promotion} to any argument that belongs to a type that has an \Index{integer conversion rank} less than that of \lstinline@int@.If 1510 \lstinline@s@ is a \lstinline@short int@, ``\lstinline@s *s@'' does not have type \lstinline@short int@; 1511 it is treated as ``\lstinline@( (int)s ) * ( (int)s )@'', and has type \lstinline@int@. \CFA matches that pattern; 1512 it does not predefine ``\lstinline@short ?*?( short, short )@''. 1650 1513 1651 1514 These ``missing'' operators limit polymorphism. … … 1656 1519 square( s ); 1657 1520 \end{lstlisting} 1658 Since \CFA does not define a multiplication operator for \lstinline $short int$,1659 \lstinline $square( s )$ is treated as \lstinline$square( (int)s )$, and the result has type1660 \lstinline $int$.1521 Since \CFA does not define a multiplication operator for \lstinline@short int@, 1522 \lstinline@square( s )@ is treated as \lstinline@square( (int)s )@, and the result has type 1523 \lstinline@int@. 1661 1524 This is mildly surprising, but it follows the {\c11} operator pattern. 1662 1525 … … 1668 1531 \end{lstlisting} 1669 1532 This has no valid interpretations, because \CFA has no conversion from ``array of 1670 \lstinline $short int$'' to ``array of \lstinline$int$''.1533 \lstinline@short int@'' to ``array of \lstinline@int@''. 1671 1534 The alternatives in such situations include 1672 1535 \begin{itemize} 1673 1536 \item 1674 Defining monomorphic overloadings of \lstinline $product$ for \lstinline$short$and the other1537 Defining monomorphic overloadings of \lstinline@product@ for \lstinline@short@ and the other 1675 1538 ``small'' types. 1676 1539 \item 1677 Defining ``\lstinline $short ?*?( short, short )$'' within the scope containing the call to1678 \lstinline $product$.1679 \item 1680 Defining \lstinline $product$to take as an argument a conversion function from the ``small'' type to the operator's argument type.1540 Defining ``\lstinline@short ?*?( short, short )@'' within the scope containing the call to 1541 \lstinline@product@. 1542 \item 1543 Defining \lstinline@product@ to take as an argument a conversion function from the ``small'' type to the operator's argument type. 1681 1544 \end{itemize} 1682 1545 \end{rationale} … … 1688 1551 \lhs{additive-expression} 1689 1552 \rhs \nonterm{multiplicative-expression} 1690 \rhs \nonterm{additive-expression} \lstinline $+$\nonterm{multiplicative-expression}1691 \rhs \nonterm{additive-expression} \lstinline $-$\nonterm{multiplicative-expression}1553 \rhs \nonterm{additive-expression} \lstinline@+@ \nonterm{multiplicative-expression} 1554 \rhs \nonterm{additive-expression} \lstinline@-@ \nonterm{multiplicative-expression} 1692 1555 \end{syntax} 1693 1556 1694 1557 \rewriterules 1695 1558 \begin{lstlisting} 1696 a + b @\rewrite@ ?+?( a, b )@\use{?+?}@1697 a - b @\rewrite@ ?-?( a, b )@\use{?-?}@1559 a + b §\rewrite§ ?+?( a, b )§\use{?+?}§ 1560 a - b §\rewrite§ ?-?( a, b )§\use{?-?}§ 1698 1561 \end{lstlisting} 1699 1562 … … 1748 1611 * ?-?( _Atomic const restrict volatile T *, _Atomic const restrict volatile T * ); 1749 1612 \end{lstlisting} 1750 For every extended integer type \lstinline $X$ with \Index{integer conversion rank} greater than the rank of \lstinline$int$there exist1613 For every extended integer type \lstinline@X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@ there exist 1751 1614 % Don't use predefined: keep this out of prelude.cf. 1752 1615 \begin{lstlisting} … … 1758 1621 1759 1622 \begin{rationale} 1760 \lstinline $ptrdiff_t$ is an implementation-defined identifier defined in \lstinline$<stddef.h>$that is synonymous with a signed integral type that is large enough to hold the difference between two pointers.1623 \lstinline@ptrdiff_t@ is an implementation-defined identifier defined in \lstinline@<stddef.h>@ that is synonymous with a signed integral type that is large enough to hold the difference between two pointers. 1761 1624 It seems reasonable to use it for pointer addition as well. (This is technically a difference between \CFA and C, which only specifies that pointer addition uses an \emph{integral} argument.) Hence it is also used for subscripting, which is defined in terms of pointer addition. 1762 The {\c11} standard uses \lstinline $size_t$ in several cases where a library function takes an argument that is used as a subscript, but \lstinline$size_t$is unsuitable here because it is an unsigned type.1625 The {\c11} standard uses \lstinline@size_t@ in several cases where a library function takes an argument that is used as a subscript, but \lstinline@size_t@ is unsuitable here because it is an unsigned type. 1763 1626 \end{rationale} 1764 1627 … … 1769 1632 \lhs{shift-expression} 1770 1633 \rhs \nonterm{additive-expression} 1771 \rhs \nonterm{shift-expression} \lstinline $<<$\nonterm{additive-expression}1772 \rhs \nonterm{shift-expression} \lstinline $>>$\nonterm{additive-expression}1634 \rhs \nonterm{shift-expression} \lstinline@<<@ \nonterm{additive-expression} 1635 \rhs \nonterm{shift-expression} \lstinline@>>@ \nonterm{additive-expression} 1773 1636 \end{syntax} 1774 1637 1775 1638 \rewriterules \use{?>>?}%use{?<<?} 1776 1639 \begin{lstlisting} 1777 a << b @\rewrite@?<<?( a, b )1778 a >> b @\rewrite@?>>?( a, b )1640 a << b §\rewrite§ ?<<?( a, b ) 1641 a >> b §\rewrite§ ?>>?( a, b ) 1779 1642 \end{lstlisting} 1780 1643 … … 1788 1651 long long unsigned int ?<<?( long long unsigned int, int ), ?>>?( long long unsigned int, int); 1789 1652 \end{lstlisting} 1790 For every extended integer type \lstinline $X$ with \Index{integer conversion rank} greater than the rank of \lstinline$int$there exist1653 For every extended integer type \lstinline@X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@ there exist 1791 1654 % Don't use predefined: keep this out of prelude.cf. 1792 1655 \begin{lstlisting} … … 1808 1671 \lhs{relational-expression} 1809 1672 \rhs \nonterm{shift-expression} 1810 \rhs \nonterm{relational-expression} \lstinline $< $\nonterm{shift-expression}1811 \rhs \nonterm{relational-expression} \lstinline $> $\nonterm{shift-expression}1812 \rhs \nonterm{relational-expression} \lstinline $<=$\nonterm{shift-expression}1813 \rhs \nonterm{relational-expression} \lstinline $>=$\nonterm{shift-expression}1673 \rhs \nonterm{relational-expression} \lstinline@< @ \nonterm{shift-expression} 1674 \rhs \nonterm{relational-expression} \lstinline@> @ \nonterm{shift-expression} 1675 \rhs \nonterm{relational-expression} \lstinline@<=@ \nonterm{shift-expression} 1676 \rhs \nonterm{relational-expression} \lstinline@>=@ \nonterm{shift-expression} 1814 1677 \end{syntax} 1815 1678 1816 1679 \rewriterules\use{?>?}\use{?>=?}%use{?<?}%use{?<=?} 1817 1680 \begin{lstlisting} 1818 a < b @\rewrite@?<?( a, b )1819 a > b @\rewrite@?>?( a, b )1820 a <= b @\rewrite@?<=?( a, b )1821 a >= b @\rewrite@?>=?( a, b )1681 a < b §\rewrite§ ?<?( a, b ) 1682 a > b §\rewrite§ ?>?( a, b ) 1683 a <= b §\rewrite§ ?<=?( a, b ) 1684 a >= b §\rewrite§ ?>=?( a, b ) 1822 1685 \end{lstlisting} 1823 1686 … … 1851 1714 ?>=?( _Atomic const restrict volatile DT *, _Atomic const restrict volatile DT * ); 1852 1715 \end{lstlisting} 1853 For every extended integer type \lstinline $X$ with \Index{integer conversion rank} greater than the rank of \lstinline$int$there exist1716 For every extended integer type \lstinline@X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@ there exist 1854 1717 % Don't use predefined: keep this out of prelude.cf. 1855 1718 \begin{lstlisting} … … 1869 1732 \lhs{equality-expression} 1870 1733 \rhs \nonterm{relational-expression} 1871 \rhs \nonterm{equality-expression} \lstinline $==$\nonterm{relational-expression}1872 \rhs \nonterm{equality-expression} \lstinline $!=$\nonterm{relational-expression}1734 \rhs \nonterm{equality-expression} \lstinline@==@ \nonterm{relational-expression} 1735 \rhs \nonterm{equality-expression} \lstinline@!=@ \nonterm{relational-expression} 1873 1736 \end{syntax} 1874 1737 1875 1738 \rewriterules 1876 1739 \begin{lstlisting} 1877 a == b @\rewrite@ ?==?( a, b )@\use{?==?}@1878 a != b @\rewrite@ ?!=?( a, b )@\use{?"!=?}@1740 a == b §\rewrite§ ?==?( a, b )§\use{?==?}§ 1741 a != b §\rewrite§ ?!=?( a, b )§\use{?"!=?}§ 1879 1742 \end{lstlisting} 1880 1743 … … 1929 1792 ?==?( forall( ftype FT2) FT2*, forall( ftype FT3) FT3 * ), ?!=?( forall( ftype FT2) FT2*, forall( ftype FT3) FT3 * ); 1930 1793 \end{lstlisting} 1931 For every extended integer type \lstinline $X$ with \Index{integer conversion rank} greater than the rank of \lstinline$int$there exist1794 For every extended integer type \lstinline@X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@ there exist 1932 1795 % Don't use predefined: keep this out of prelude.cf. 1933 1796 \begin{lstlisting} … … 1937 1800 1938 1801 \begin{rationale} 1939 The polymorphic equality operations come in three styles: comparisons between pointers of compatible types, between pointers to \lstinline $void$and pointers to object types or incomplete types, and between the \Index{null pointer} constant and pointers to any type.1802 The polymorphic equality operations come in three styles: comparisons between pointers of compatible types, between pointers to \lstinline@void@ and pointers to object types or incomplete types, and between the \Index{null pointer} constant and pointers to any type. 1940 1803 In the last case, a special constraint rule for null pointer constant operands has been replaced by a consequence of the \CFA type system. 1941 1804 \end{rationale} … … 1958 1821 \lhs{AND-expression} 1959 1822 \rhs \nonterm{equality-expression} 1960 \rhs \nonterm{AND-expression} \lstinline $&$\nonterm{equality-expression}1823 \rhs \nonterm{AND-expression} \lstinline@&@ \nonterm{equality-expression} 1961 1824 \end{syntax} 1962 1825 1963 1826 \rewriterules 1964 1827 \begin{lstlisting} 1965 a & b @\rewrite@ ?&?( a, b )@\use{?&?}@1828 a & b §\rewrite§ ?&?( a, b )§\use{?&?}§ 1966 1829 \end{lstlisting} 1967 1830 … … 1975 1838 long long unsigned int ?&?( long long unsigned int, long long unsigned int ); 1976 1839 \end{lstlisting} 1977 For every extended integer type \lstinline $X$ with \Index{integer conversion rank} greater than the rank of \lstinline$int$there exist1840 For every extended integer type \lstinline@X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@ there exist 1978 1841 % Don't use predefined: keep this out of prelude.cf. 1979 1842 \begin{lstlisting} … … 1990 1853 \lhs{exclusive-OR-expression} 1991 1854 \rhs \nonterm{AND-expression} 1992 \rhs \nonterm{exclusive-OR-expression} \lstinline $^$\nonterm{AND-expression}1855 \rhs \nonterm{exclusive-OR-expression} \lstinline@^@ \nonterm{AND-expression} 1993 1856 \end{syntax} 1994 1857 1995 1858 \rewriterules 1996 1859 \begin{lstlisting} 1997 a ^ b @\rewrite@ ?^?( a, b )@\use{?^?}@1860 a ^ b §\rewrite§ ?^?( a, b )§\use{?^?}§ 1998 1861 \end{lstlisting} 1999 1862 … … 2007 1870 long long unsigned int ?^?( long long unsigned int, long long unsigned int ); 2008 1871 \end{lstlisting} 2009 For every extended integer type \lstinline $X$ with \Index{integer conversion rank} greater than the rank of \lstinline$int$there exist1872 For every extended integer type \lstinline@X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@ there exist 2010 1873 % Don't use predefined: keep this out of prelude.cf. 2011 1874 \begin{lstlisting} … … 2022 1885 \lhs{inclusive-OR-expression} 2023 1886 \rhs \nonterm{exclusive-OR-expression} 2024 \rhs \nonterm{inclusive-OR-expression} \lstinline $|$\nonterm{exclusive-OR-expression}1887 \rhs \nonterm{inclusive-OR-expression} \lstinline@|@ \nonterm{exclusive-OR-expression} 2025 1888 \end{syntax} 2026 1889 2027 1890 \rewriterules\use{?"|?} 2028 1891 \begin{lstlisting} 2029 a | b @\rewrite@?|?( a, b )1892 a | b §\rewrite§ ?|?( a, b ) 2030 1893 \end{lstlisting} 2031 1894 … … 2039 1902 long long unsigned int ?|?( long long unsigned int, long long unsigned int ); 2040 1903 \end{lstlisting} 2041 For every extended integer type \lstinline $X$ with \Index{integer conversion rank} greater than the rank of \lstinline$int$there exist1904 For every extended integer type \lstinline@X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@ there exist 2042 1905 % Don't use predefined: keep this out of prelude.cf. 2043 1906 \begin{lstlisting} … … 2054 1917 \lhs{logical-AND-expression} 2055 1918 \rhs \nonterm{inclusive-OR-expression} 2056 \rhs \nonterm{logical-AND-expression} \lstinline $&&$\nonterm{inclusive-OR-expression}1919 \rhs \nonterm{logical-AND-expression} \lstinline@&&@ \nonterm{inclusive-OR-expression} 2057 1920 \end{syntax} 2058 1921 2059 \semantics The operands of the expression ``\lstinline $a && b$'' are treated as2060 ``\lstinline $(int)((a)!=0)$'' and ``\lstinline$(int)((b)!=0)$'', which shall both be unambiguous.2061 The expression has only one interpretation, which is of type \lstinline $int$.2062 \begin{rationale} 2063 When the operands of a logical expression are values of built-in types, and ``\lstinline $!=$'' has not been redefined for those types, the compiler can optimize away the function calls.2064 2065 A common C idiom omits comparisons to \lstinline $0$in the controlling expressions of loops and2066 \lstinline $if$statements.2067 For instance, the loop below iterates as long as \lstinline $rp$ points at a \lstinline$Rational$value that is non-zero.2068 2069 \begin{lstlisting} 2070 extern otype Rational; @\use{Rational}@2071 extern const Rational 0; @\use{0}@1922 \semantics The operands of the expression ``\lstinline@a && b@'' are treated as 1923 ``\lstinline@(int)((a)!=0)@'' and ``\lstinline@(int)((b)!=0)@'', which shall both be unambiguous. 1924 The expression has only one interpretation, which is of type \lstinline@int@. 1925 \begin{rationale} 1926 When the operands of a logical expression are values of built-in types, and ``\lstinline@!=@'' has not been redefined for those types, the compiler can optimize away the function calls. 1927 1928 A common C idiom omits comparisons to \lstinline@0@ in the controlling expressions of loops and 1929 \lstinline@if@ statements. 1930 For instance, the loop below iterates as long as \lstinline@rp@ points at a \lstinline@Rational@ value that is non-zero. 1931 1932 \begin{lstlisting} 1933 extern otype Rational;§\use{Rational}§ 1934 extern const Rational 0;§\use{0}§ 2072 1935 extern int ?!=?( Rational, Rational ); 2073 1936 Rational *rp; 2074 1937 while ( rp && *rp ) { ... } 2075 1938 \end{lstlisting} 2076 The logical expression calls the \lstinline $Rational$ inequality operator, passing it \lstinline$*rp$ and the \lstinline$Rational 0$, and getting a 1 or 0 as a result.2077 In contrast, {\CC} would apply a programmer-defined \lstinline $Rational$-to-\lstinline$int$ conversion to \lstinline$*rp$in the equivalent situation.2078 The conversion to \lstinline $int$would produce a general integer value, which is unfortunate, and possibly dangerous if the conversion was not written with this situation in mind.1939 The logical expression calls the \lstinline@Rational@ inequality operator, passing it \lstinline@*rp@ and the \lstinline@Rational 0@, and getting a 1 or 0 as a result. 1940 In contrast, {\CC} would apply a programmer-defined \lstinline@Rational@-to-\lstinline@int@ conversion to \lstinline@*rp@ in the equivalent situation. 1941 The conversion to \lstinline@int@ would produce a general integer value, which is unfortunate, and possibly dangerous if the conversion was not written with this situation in mind. 2079 1942 \end{rationale} 2080 1943 … … 2085 1948 \lhs{logical-OR-expression} 2086 1949 \rhs \nonterm{logical-AND-expression} 2087 \rhs \nonterm{logical-OR-expression} \lstinline $||$\nonterm{logical-AND-expression}1950 \rhs \nonterm{logical-OR-expression} \lstinline@||@ \nonterm{logical-AND-expression} 2088 1951 \end{syntax} 2089 1952 2090 1953 \semantics 2091 1954 2092 The operands of the expression ``\lstinline $a || b$'' are treated as ``\lstinline$(int)((a)!=0)$'' and ``\lstinline$(int)((b))!=0)$'', which shall both be unambiguous.2093 The expression has only one interpretation, which is of type \lstinline $int$.1955 The operands of the expression ``\lstinline@a || b@'' are treated as ``\lstinline@(int)((a)!=0)@'' and ``\lstinline@(int)((b))!=0)@'', which shall both be unambiguous. 1956 The expression has only one interpretation, which is of type \lstinline@int@. 2094 1957 2095 1958 … … 2099 1962 \lhs{conditional-expression} 2100 1963 \rhs \nonterm{logical-OR-expression} 2101 \rhs \nonterm{logical-OR-expression} \lstinline $?$\nonterm{expression}2102 \lstinline $:$\nonterm{conditional-expression}1964 \rhs \nonterm{logical-OR-expression} \lstinline@?@ \nonterm{expression} 1965 \lstinline@:@ \nonterm{conditional-expression} 2103 1966 \end{syntax} 2104 1967 2105 1968 \semantics 2106 In the conditional expression\use{?:} ``\lstinline $a?b:c$'', if the second and third operands both have an interpretation with \lstinline$void$ type, then the expression has an interpretation with type \lstinline$void$, equivalent to1969 In the conditional expression\use{?:} ``\lstinline@a?b:c@'', if the second and third operands both have an interpretation with \lstinline@void@ type, then the expression has an interpretation with type \lstinline@void@, equivalent to 2107 1970 \begin{lstlisting} 2108 1971 ( int)(( a)!=0) ? ( void)( b) : ( void)( c) 2109 1972 \end{lstlisting} 2110 1973 2111 If the second and third operands both have interpretations with non-\lstinline $void$ types, the expression is treated as if it were the call ``\lstinline$cond((a)!=0, b, c)$'', with \lstinline$cond$declared as1974 If the second and third operands both have interpretations with non-\lstinline@void@ types, the expression is treated as if it were the call ``\lstinline@cond((a)!=0, b, c)@'', with \lstinline@cond@ declared as 2112 1975 \begin{lstlisting} 2113 1976 forall( otype T ) T cond( int, T, T ); … … 2161 2024 rand() ? i : l; 2162 2025 \end{lstlisting} 2163 The best interpretation infers the expression's type to be \lstinline $long$and applies the safe2164 \lstinline $int$-to-\lstinline$long$ conversion to \lstinline$i$.2026 The best interpretation infers the expression's type to be \lstinline@long@ and applies the safe 2027 \lstinline@int@-to-\lstinline@long@ conversion to \lstinline@i@. 2165 2028 2166 2029 \begin{lstlisting} … … 2169 2032 rand() ? cip : vip; 2170 2033 \end{lstlisting} 2171 The expression has type \lstinline $const volatile int *$, with safe conversions applied to the second and third operands to add \lstinline$volatile$ and \lstinline$const$qualifiers, respectively.2034 The expression has type \lstinline@const volatile int *@, with safe conversions applied to the second and third operands to add \lstinline@volatile@ and \lstinline@const@ qualifiers, respectively. 2172 2035 2173 2036 \begin{lstlisting} 2174 2037 rand() ? cip : 0; 2175 2038 \end{lstlisting} 2176 The expression has type \lstinline $const int *$, with a specialization conversion applied to2177 \lstinline $0$.2039 The expression has type \lstinline@const int *@, with a specialization conversion applied to 2040 \lstinline@0@. 2178 2041 2179 2042 … … 2186 2049 \nonterm{assignment-expression} 2187 2050 \lhs{assignment-operator} one of 2188 \rhs \lstinline $=$\ \ \lstinline$*=$\ \ \lstinline$/=$\ \ \lstinline$%=$\ \ \lstinline$+=$\ \ \lstinline$-=$\ \2189 \lstinline $<<=$\ \ \lstinline$>>=$\ \ \lstinline$&=$\ \ \lstinline$^=$\ \ \lstinline$|=$2051 \rhs \lstinline@=@\ \ \lstinline@*=@\ \ \lstinline@/=@\ \ \lstinline@%=@\ \ \lstinline@+=@\ \ \lstinline@-=@\ \ 2052 \lstinline@<<=@\ \ \lstinline@>>=@\ \ \lstinline@&=@\ \ \lstinline@^=@\ \ \lstinline@|=@ 2190 2053 \end{syntax} 2191 2054 … … 2196 2059 \use{?>>=?}\use{?&=?}\use{?^=?}\use{?"|=?}%use{?<<=?} 2197 2060 \begin{lstlisting} 2198 a @$\leftarrow$@ b @\rewrite@ ?@$\leftarrow$@?( &( a ), b )2061 a §$\leftarrow$§ b §\rewrite§ ?§$\leftarrow$§?( &( a ), b ) 2199 2062 \end{lstlisting} 2200 2063 2201 2064 \semantics 2202 2065 Each interpretation of the left operand of an assignment expression is considered separately. 2203 For each interpretation that is a bit-field or is declared with the \lstinline $register$storage class specifier, the expression has one valid interpretation, with the type of the left operand.2066 For each interpretation that is a bit-field or is declared with the \lstinline@register@ storage class specifier, the expression has one valid interpretation, with the type of the left operand. 2204 2067 The right operand is cast to that type, and the assignment expression is ambiguous if either operand is. 2205 2068 For the remaining interpretations, the expression is rewritten, and the interpretations of the assignment expression are the interpretations of the corresponding function call. … … 2434 2297 \end{lstlisting} 2435 2298 \begin{rationale} 2436 The pattern of overloadings for simple assignment resembles that of pointer increment and decrement, except that the polymorphic pointer assignment functions declare a \lstinline $dtype$ parameter, instead of a \lstinline$type$parameter, because the left operand may be a pointer to an incomplete type.2437 \end{rationale} 2438 2439 For every complete structure or union type \lstinline $S$there exist2299 The pattern of overloadings for simple assignment resembles that of pointer increment and decrement, except that the polymorphic pointer assignment functions declare a \lstinline@dtype@ parameter, instead of a \lstinline@type@ parameter, because the left operand may be a pointer to an incomplete type. 2300 \end{rationale} 2301 2302 For every complete structure or union type \lstinline@S@ there exist 2440 2303 % Don't use predefined: keep this out of prelude.cf. 2441 2304 \begin{lstlisting} … … 2443 2306 \end{lstlisting} 2444 2307 2445 For every extended integer type \lstinline $X$there exist2308 For every extended integer type \lstinline@X@ there exist 2446 2309 % Don't use predefined: keep this out of prelude.cf. 2447 2310 \begin{lstlisting} … … 2449 2312 \end{lstlisting} 2450 2313 2451 For every complete enumerated type \lstinline $E$there exist2314 For every complete enumerated type \lstinline@E@ there exist 2452 2315 % Don't use predefined: keep this out of prelude.cf. 2453 2316 \begin{lstlisting} … … 2455 2318 \end{lstlisting} 2456 2319 \begin{rationale} 2457 The right-hand argument is \lstinline $int$ because enumeration constants have type \lstinline$int$.2320 The right-hand argument is \lstinline@int@ because enumeration constants have type \lstinline@int@. 2458 2321 \end{rationale} 2459 2322 … … 2716 2579 \end{lstlisting} 2717 2580 2718 For every extended integer type \lstinline $X$there exist2581 For every extended integer type \lstinline@X@ there exist 2719 2582 % Don't use predefined: keep this out of prelude.cf. 2720 2583 \begin{lstlisting} … … 2731 2594 \end{lstlisting} 2732 2595 2733 For every complete enumerated type \lstinline $E$there exist2596 For every complete enumerated type \lstinline@E@ there exist 2734 2597 % Don't use predefined: keep this out of prelude.cf. 2735 2598 \begin{lstlisting} … … 2752 2615 \lhs{expression} 2753 2616 \rhs \nonterm{assignment-expression} 2754 \rhs \nonterm{expression} \lstinline $,$\nonterm{assignment-expression}2617 \rhs \nonterm{expression} \lstinline@,@ \nonterm{assignment-expression} 2755 2618 \end{syntax} 2756 2619 2757 2620 \semantics 2758 In the comma expression ``\lstinline $a, b$'', the first operand is interpreted as2759 ``\lstinline $( void )(a)$'', which shall be unambiguous\index{ambiguous interpretation}.2621 In the comma expression ``\lstinline@a, b@'', the first operand is interpreted as 2622 ``\lstinline@( void )(a)@'', which shall be unambiguous\index{ambiguous interpretation}. 2760 2623 The interpretations of the expression are the interpretations of the second operand. 2761 2624 … … 2792 2655 { ... } 2793 2656 \end{lstlisting} 2794 Without the rule, \lstinline $Complex$would be a type in the first case, and a parameter name in the second.2657 Without the rule, \lstinline@Complex@ would be a type in the first case, and a parameter name in the second. 2795 2658 \end{rationale} 2796 2659 … … 2818 2681 \examples 2819 2682 \begin{lstlisting} 2820 struct point { @\impl{point}@2683 struct point {§\impl{point}§ 2821 2684 int x, y; 2822 2685 }; 2823 struct color_point { @\impl{color_point}@2686 struct color_point {§\impl{color_point}§ 2824 2687 enum { RED, BLUE, GREEN } color; 2825 2688 struct point; … … 2828 2691 cp.x = 0; 2829 2692 cp.color = RED; 2830 struct literal { @\impl{literal}@2693 struct literal {§\impl{literal}§ 2831 2694 enum { NUMBER, STRING } tag; 2832 2695 union { … … 2849 2712 \begin{syntax} 2850 2713 \lhs{forall-specifier} 2851 \rhs \lstinline $forall$ \lstinline$($ \nonterm{type-parameter-list} \lstinline$)$2714 \rhs \lstinline@forall@ \lstinline@(@ \nonterm{type-parameter-list} \lstinline@)@ 2852 2715 \end{syntax} 2853 2716 … … 2861 2724 } mkPair( T, T ); // illegal 2862 2725 \end{lstlisting} 2863 If an instance of \lstinline $struct Pair$was declared later in the current scope, what would the members' type be?2726 If an instance of \lstinline@struct Pair@ was declared later in the current scope, what would the members' type be? 2864 2727 \end{rationale} 2865 2728 \end{comment} … … 2868 2731 The \nonterm{type-parameter-list}s and assertions of the \nonterm{forall-specifier}s declare type identifiers, function and object identifiers with \Index{no linkage}. 2869 2732 2870 If, in the declaration ``\lstinline $T D$'', \lstinline$T$contains \nonterm{forall-specifier}s and2871 \lstinline $D$has the form2872 \begin{lstlisting} 2873 D( @\normalsize\nonterm{parameter-type-list}@)2874 \end{lstlisting} then a type identifier declared by one of the \nonterm{forall-specifier}s is an \define{inferred parameter} of the function declarator if and only if it is not an inferred parameter of a function declarator in \lstinline $D$, and it is used in the type of a parameter in the following2733 If, in the declaration ``\lstinline@T D@'', \lstinline@T@ contains \nonterm{forall-specifier}s and 2734 \lstinline@D@ has the form 2735 \begin{lstlisting} 2736 D( §\normalsize\nonterm{parameter-type-list}§ ) 2737 \end{lstlisting} then a type identifier declared by one of the \nonterm{forall-specifier}s is an \define{inferred parameter} of the function declarator if and only if it is not an inferred parameter of a function declarator in \lstinline@D@, and it is used in the type of a parameter in the following 2875 2738 \nonterm{type-parameter-list} or it and an inferred parameter are used as arguments of a 2876 2739 \Index{specification} in one of the \nonterm{forall-specifier}s. … … 2883 2746 If this restriction were lifted, it would be possible to write 2884 2747 \begin{lstlisting} 2885 forall( otype T ) T * alloc( void ); @\use{alloc}@int *p = alloc();2886 \end{lstlisting} 2887 Here \lstinline $alloc()$ would receive \lstinline$int$as an inferred argument, and return an2888 \lstinline $int *$.2889 In general, if a call to \lstinline $alloc()$ is a subexpression of an expression involving polymorphic functions and overloaded identifiers, there could be considerable distance between the call and the subexpression that causes \lstinline$T$to be bound.2890 2891 With the current restriction, \lstinline $alloc()$must be given an argument that determines2892 \lstinline $T$:2893 \begin{lstlisting} 2894 forall( otype T ) T * alloc( T initial_value ); @\use{alloc}@2748 forall( otype T ) T * alloc( void );§\use{alloc}§ int *p = alloc(); 2749 \end{lstlisting} 2750 Here \lstinline@alloc()@ would receive \lstinline@int@ as an inferred argument, and return an 2751 \lstinline@int *@. 2752 In general, if a call to \lstinline@alloc()@ is a subexpression of an expression involving polymorphic functions and overloaded identifiers, there could be considerable distance between the call and the subexpression that causes \lstinline@T@ to be bound. 2753 2754 With the current restriction, \lstinline@alloc()@ must be given an argument that determines 2755 \lstinline@T@: 2756 \begin{lstlisting} 2757 forall( otype T ) T * alloc( T initial_value );§\use{alloc}§ 2895 2758 \end{lstlisting} 2896 2759 \end{rationale} … … 2917 2780 forall( otype T ) T fT( T ); 2918 2781 \end{lstlisting} 2919 \lstinline $fi()$ takes an \lstinline$int$ and returns an \lstinline$int$. \lstinline$fT()$takes a2920 \lstinline $T$ and returns a \lstinline$T$, for any type \lstinline$T$.2782 \lstinline@fi()@ takes an \lstinline@int@ and returns an \lstinline@int@. \lstinline@fT()@ takes a 2783 \lstinline@T@ and returns a \lstinline@T@, for any type \lstinline@T@. 2921 2784 \begin{lstlisting} 2922 2785 int (*pfi )( int ) = fi; 2923 2786 forall( otype T ) T (*pfT )( T ) = fT; 2924 2787 \end{lstlisting} 2925 \lstinline $pfi$ and \lstinline$pfT$ are pointers to functions. \lstinline$pfT$is not polymorphic, but the function it points at is.2788 \lstinline@pfi@ and \lstinline@pfT@ are pointers to functions. \lstinline@pfT@ is not polymorphic, but the function it points at is. 2926 2789 \begin{lstlisting} 2927 2790 int (*fvpfi( void ))( int ) { … … 2932 2795 } 2933 2796 \end{lstlisting} 2934 \lstinline $fvpfi()$ and \lstinline$fvpfT()$ are functions taking no arguments and returning pointers to functions. \lstinline$fvpfT()$is monomorphic, but the function that its return value points at is polymorphic.2797 \lstinline@fvpfi()@ and \lstinline@fvpfT()@ are functions taking no arguments and returning pointers to functions. \lstinline@fvpfT()@ is monomorphic, but the function that its return value points at is polymorphic. 2935 2798 \begin{lstlisting} 2936 2799 forall( otype T ) int ( *fTpfi( T ) )( int ); … … 2938 2801 forall( otype T, otype U ) U ( *fTpfU( T ) )( U ); 2939 2802 \end{lstlisting} 2940 \lstinline $fTpfi()$is a polymorphic function that returns a pointer to a monomorphic function taking an integer and returning an integer.2941 It could return \lstinline $pfi$. \lstinline$fTpfT()$is subtle: it is a polymorphic function returning a \emph{monomorphic} function taking and returning2942 \lstinline $T$, where \lstinline$T$ is an inferred parameter of \lstinline$fTpfT()$.2943 For instance, in the expression ``\lstinline $fTpfT(17)$'', \lstinline$T$ is inferred to be \lstinline$int$, and the returned value would have type \lstinline$int ( * )( int )$. ``\lstinline$fTpfT(17)(13)$'' and2944 ``\lstinline $fTpfT("yes")("no")$'' are legal, but ``\lstinline$fTpfT(17)("no")$'' is illegal.2945 \lstinline $fTpfU()$ is polymorphic ( in type \lstinline$T$), and returns a pointer to a function that is polymorphic ( in type \lstinline$U$). ``\lstinline$f5(17)("no")$'' is a legal expression of type2946 \lstinline $char *$.2803 \lstinline@fTpfi()@ is a polymorphic function that returns a pointer to a monomorphic function taking an integer and returning an integer. 2804 It could return \lstinline@pfi@. \lstinline@fTpfT()@ is subtle: it is a polymorphic function returning a \emph{monomorphic} function taking and returning 2805 \lstinline@T@, where \lstinline@T@ is an inferred parameter of \lstinline@fTpfT()@. 2806 For instance, in the expression ``\lstinline@fTpfT(17)@'', \lstinline@T@ is inferred to be \lstinline@int@, and the returned value would have type \lstinline@int ( * )( int )@. ``\lstinline@fTpfT(17)(13)@'' and 2807 ``\lstinline@fTpfT("yes")("no")@'' are legal, but ``\lstinline@fTpfT(17)("no")@'' is illegal. 2808 \lstinline@fTpfU()@ is polymorphic ( in type \lstinline@T@), and returns a pointer to a function that is polymorphic ( in type \lstinline@U@). ``\lstinline@f5(17)("no")@'' is a legal expression of type 2809 \lstinline@char *@. 2947 2810 \begin{lstlisting} 2948 2811 forall( otype T, otype U, otype V ) U * f( T *, U, V * const ); 2949 2812 forall( otype U, otype V, otype W ) U * g( V *, U, W * const ); 2950 2813 \end{lstlisting} 2951 The functions \lstinline $f()$ and \lstinline$g()$have compatible types.2814 The functions \lstinline@f()@ and \lstinline@g()@ have compatible types. 2952 2815 Let \(f\) and \(g\) be their types; 2953 then \(f_1\) = \lstinline $T$, \(f_2\) = \lstinline$U$, \(f_3\) = \lstinline$V$, \(g_1\)2954 = \lstinline $V$, \(g_2\) = \lstinline$U$, and \(g_3\) = \lstinline$W$.2816 then \(f_1\) = \lstinline@T@, \(f_2\) = \lstinline@U@, \(f_3\) = \lstinline@V@, \(g_1\) 2817 = \lstinline@V@, \(g_2\) = \lstinline@U@, and \(g_3\) = \lstinline@W@. 2955 2818 Replacing every \(f_i\) by \(g_i\) in \(f\) gives 2956 2819 \begin{lstlisting} … … 2958 2821 \end{lstlisting} which has a return type and parameter list that is compatible with \(g\). 2959 2822 \begin{rationale} 2960 The word ``\lstinline $type$'' in a forall specifier is redundant at the moment, but I want to leave room for inferred parameters of ordinary types in case parameterized types get added one day.2823 The word ``\lstinline@type@'' in a forall specifier is redundant at the moment, but I want to leave room for inferred parameters of ordinary types in case parameterized types get added one day. 2961 2824 2962 2825 Even without parameterized types, I might try to allow … … 2984 2847 \subsection{Type qualifiers} 2985 2848 2986 \CFA defines a new type qualifier \lstinline $lvalue$\impl{lvalue}\index{lvalue}.2849 \CFA defines a new type qualifier \lstinline@lvalue@\impl{lvalue}\index{lvalue}. 2987 2850 \begin{syntax} 2988 2851 \oldlhs{type-qualifier} 2989 \rhs \lstinline $lvalue$2852 \rhs \lstinline@lvalue@ 2990 2853 \end{syntax} 2991 2854 2992 2855 \constraints 2993 \ lstinline$restrict$\index{register@{\lstinline$restrict$}} Types other than type parameters and pointer types whose referenced type is an object type shall not be restrict-qualified.2856 \Indexc{restrict} Types other than type parameters and pointer types whose referenced type is an object type shall not be restrict-qualified. 2994 2857 2995 2858 \semantics 2996 An object's type may be a restrict-qualified type parameter. \lstinline$restrict$ does not establish any special semantics in that case. 2859 An object's type may be a restrict-qualified type parameter. 2860 \lstinline@restrict@ does not establish any special semantics in that case. 2997 2861 2998 2862 \begin{rationale} … … 3000 2864 \end{rationale} 3001 2865 3002 \lstinline $lvalue$may be used to qualify the return type of a function type.3003 Let \lstinline $T$be an unqualified version of a type;2866 \lstinline@lvalue@ may be used to qualify the return type of a function type. 2867 Let \lstinline@T@ be an unqualified version of a type; 3004 2868 then the result of calling a function with return type 3005 \lstinline $lvalue T$ is a \Index{modifiable lvalue} of type \lstinline$T$.3006 \lstinline $const$\use{const} and \lstinline$volatile$\use{volatile} qualifiers may also be added to indicate that the function result is a constant or volatile lvalue.3007 \begin{rationale} 3008 The \lstinline $const$ and \lstinline$volatile$ qualifiers can only be sensibly used to qualify the return type of a function if the \lstinline$lvalue$qualifier is also used.2869 \lstinline@lvalue T@ is a \Index{modifiable lvalue} of type \lstinline@T@. 2870 \lstinline@const@\use{const} and \lstinline@volatile@\use{volatile} qualifiers may also be added to indicate that the function result is a constant or volatile lvalue. 2871 \begin{rationale} 2872 The \lstinline@const@ and \lstinline@volatile@ qualifiers can only be sensibly used to qualify the return type of a function if the \lstinline@lvalue@ qualifier is also used. 3009 2873 \end{rationale} 3010 2874 … … 3013 2877 3014 2878 \begin{rationale} 3015 \lstinline $lvalue$ provides some of the functionality of {\CC}'s ``\lstinline$T&$'' ( reference to object of type \lstinline$T$) type.2879 \lstinline@lvalue@ provides some of the functionality of {\CC}'s ``\lstinline@T&@'' ( reference to object of type \lstinline@T@) type. 3016 2880 Reference types have four uses in {\CC}. 3017 2881 \begin{itemize} 3018 2882 \item 3019 They are necessary for user-defined operators that return lvalues, such as ``subscript'' and 3020 ``dereference''. 3021 3022 \item 3023 A reference can be used to define an alias for a complicated lvalue expression, as a way of getting some of the functionality of the Pascal \lstinline$with$ statement. 2883 They are necessary for user-defined operators that return lvalues, such as ``subscript'' and ``dereference''. 2884 2885 \item 2886 A reference can be used to define an alias for a complicated lvalue expression, as a way of getting some of the functionality of the Pascal \lstinline@with@ statement. 3024 2887 The following {\CC} code gives an example. 3025 2888 \begin{lstlisting} … … 3034 2897 A reference parameter can be used to allow a function to modify an argument without forcing the caller to pass the address of the argument. 3035 2898 This is most useful for user-defined assignment operators. 3036 In {\CC}, plain assignment is done by a function called ``\lstinline $operator=$'', and the two expressions2899 In {\CC}, plain assignment is done by a function called ``\lstinline@operator=@'', and the two expressions 3037 2900 \begin{lstlisting} 3038 2901 a = b; 3039 2902 operator=( a, b ); 3040 2903 \end{lstlisting} are equivalent. 3041 If \lstinline $a$ and \lstinline$b$ are of type \lstinline$T$, then the first parameter of \lstinline$operator=$ must have type ``\lstinline$T&$''.2904 If \lstinline@a@ and \lstinline@b@ are of type \lstinline@T@, then the first parameter of \lstinline@operator=@ must have type ``\lstinline@T&@''. 3042 2905 It cannot have type 3043 \lstinline $T$, because then assignment couldn't alter the variable, and it can't have type3044 ``\lstinline $T *$'', because the assignment would have to be written ``\lstinline$&a = b;$''.3045 3046 In the case of user-defined operators, this could just as well be handled by using pointer types and by changing the rewrite rules so that ``\lstinline $a = b;$'' is equivalent to3047 ``\lstinline $operator=(&( a), b )$''.3048 Reference parameters of ``normal'' functions are Bad Things, because they remove a useful property of C function calls: an argument can only be modified by a function if it is preceded by ``\lstinline $&$''.2906 \lstinline@T@, because then assignment couldn't alter the variable, and it can't have type 2907 ``\lstinline@T *@'', because the assignment would have to be written ``\lstinline@&a = b;@''. 2908 2909 In the case of user-defined operators, this could just as well be handled by using pointer types and by changing the rewrite rules so that ``\lstinline@a = b;@'' is equivalent to 2910 ``\lstinline@operator=(&( a), b )@''. 2911 Reference parameters of ``normal'' functions are Bad Things, because they remove a useful property of C function calls: an argument can only be modified by a function if it is preceded by ``\lstinline@&@''. 3049 2912 3050 2913 \item 3051 2914 References to \Index{const-qualified} types can be used instead of value parameters. Given the 3052 {\CC} function call ``\lstinline $fiddle( a_thing )$'', where the type of \lstinline$a_thing$is3053 \lstinline $Thing$, the type of \lstinline$fiddle$could be either of2915 {\CC} function call ``\lstinline@fiddle( a_thing )@'', where the type of \lstinline@a_thing@ is 2916 \lstinline@Thing@, the type of \lstinline@fiddle@ could be either of 3054 2917 \begin{lstlisting} 3055 2918 void fiddle( Thing ); 3056 2919 void fiddle( const Thing & ); 3057 2920 \end{lstlisting} 3058 If the second form is used, then constructors and destructors are not invoked to create a temporary variable at the call site ( and it is bad style for the caller to make any assumptions about such things), and within \lstinline $fiddle$the parameter is subject to the usual problems caused by aliases.3059 The reference form might be chosen for efficiency's sake if \lstinline $Thing$s are too large or their constructors or destructors are too expensive.2921 If the second form is used, then constructors and destructors are not invoked to create a temporary variable at the call site ( and it is bad style for the caller to make any assumptions about such things), and within \lstinline@fiddle@ the parameter is subject to the usual problems caused by aliases. 2922 The reference form might be chosen for efficiency's sake if \lstinline@Thing@s are too large or their constructors or destructors are too expensive. 3060 2923 An implementation may switch between them without causing trouble for well-behaved clients. 3061 2924 This leaves the implementor to define ``too large'' and ``too expensive''. … … 3065 2928 void fiddle( const volatile Thing ); 3066 2929 \end{lstlisting} with call-by-reference. 3067 Since it knows all about the size of \lstinline $Thing$s and the parameter passing mechanism, it should be able to come up with a better definition of ``too large'', and may be able to make a good guess at ``too expensive''.2930 Since it knows all about the size of \lstinline@Thing@s and the parameter passing mechanism, it should be able to come up with a better definition of ``too large'', and may be able to make a good guess at ``too expensive''. 3068 2931 \end{itemize} 3069 2932 … … 3085 2948 \begin{syntax} 3086 2949 \lhs{spec-definition} 3087 \rhs \lstinline $spec$\nonterm{identifier}3088 \lstinline $($ \nonterm{type-parameter-list} \lstinline$)$3089 \lstinline ${$ \nonterm{spec-declaration-list}\opt \lstinline$}$2950 \rhs \lstinline@spec@ \nonterm{identifier} 2951 \lstinline@(@ \nonterm{type-parameter-list} \lstinline@)@ 2952 \lstinline@{@ \nonterm{spec-declaration-list}\opt \lstinline@}@ 3090 2953 \lhs{spec-declaration-list} 3091 \rhs \nonterm{spec-declaration} \lstinline $;$3092 \rhs \nonterm{spec-declaration-list} \nonterm{spec-declaration} \lstinline $;$2954 \rhs \nonterm{spec-declaration} \lstinline@;@ 2955 \rhs \nonterm{spec-declaration-list} \nonterm{spec-declaration} \lstinline@;@ 3093 2956 \lhs{spec-declaration} 3094 2957 \rhs \nonterm{specifier-qualifier-list} \nonterm{declarator-list} 3095 2958 \lhs{declarator-list} 3096 2959 \rhs \nonterm{declarator} 3097 \rhs \nonterm{declarator-list} \lstinline $,$\nonterm{declarator}2960 \rhs \nonterm{declarator-list} \lstinline@,@ \nonterm{declarator} 3098 2961 \end{syntax} 3099 2962 \begin{rationale} … … 3117 2980 \rhs \nonterm{assertion-list} \nonterm{assertion} 3118 2981 \lhs{assertion} 3119 \rhs \lstinline $|$ \nonterm{identifier} \lstinline$($ \nonterm{type-name-list} \lstinline$)$3120 \rhs \lstinline $|$\nonterm{spec-declaration}2982 \rhs \lstinline@|@ \nonterm{identifier} \lstinline@(@ \nonterm{type-name-list} \lstinline@)@ 2983 \rhs \lstinline@|@ \nonterm{spec-declaration} 3121 2984 \lhs{type-name-list} 3122 2985 \rhs \nonterm{type-name} 3123 \rhs \nonterm{type-name-list} \lstinline $,$\nonterm{type-name}2986 \rhs \nonterm{type-name-list} \lstinline@,@ \nonterm{type-name} 3124 2987 \end{syntax} 3125 2988 … … 3128 2991 The \nonterm{type-name-list} shall contain one \nonterm{type-name} argument for each \nonterm{type-parameter} in that specification's \nonterm{spec-parameter-list}. 3129 2992 If the 3130 \nonterm{type-parameter} uses type-class \lstinline $type$\use{type}, the argument shall be the type name of an \Index{object type};3131 if it uses \lstinline $dtype$, the argument shall be the type name of an object type or an \Index{incomplete type};3132 and if it uses \lstinline $ftype$, the argument shall be the type name of a \Index{function type}.2993 \nonterm{type-parameter} uses type-class \lstinline@type@\use{type}, the argument shall be the type name of an \Index{object type}; 2994 if it uses \lstinline@dtype@, the argument shall be the type name of an object type or an \Index{incomplete type}; 2995 and if it uses \lstinline@ftype@, the argument shall be the type name of a \Index{function type}. 3133 2996 3134 2997 \semantics … … 3143 3006 \examples 3144 3007 \begin{lstlisting} 3145 forall( otype T | T ?*?( T, T )) @\use{?*?}@3146 T square( T val ) { @\impl{square}@3008 forall( otype T | T ?*?( T, T ))§\use{?*?}§ 3009 T square( T val ) {§\impl{square}§ 3147 3010 return val + val; 3148 3011 } 3149 trait summable( otype T ) { @\impl{summable}@3150 T ?+=?( T *, T ); @\use{?+=?}@3151 const T 0; @\use{0}@3012 trait summable( otype T ) {§\impl{summable}§ 3013 T ?+=?( T *, T );§\use{?+=?}§ 3014 const T 0;§\use{0}§ 3152 3015 }; 3153 trait list_of( otype List, otype Element ) { @\impl{list_of}@3016 trait list_of( otype List, otype Element ) {§\impl{list_of}§ 3154 3017 Element car( List ); 3155 3018 List cdr( List ); … … 3160 3023 trait sum_list( otype List, otype Element | summable( Element ) | list_of( List, Element ) ) {}; 3161 3024 \end{lstlisting} 3162 \lstinline $sum_list$contains seven declarations, which describe a list whose elements can be added up.3163 The assertion ``\lstinline $|sum_list( i_list, int )$''\use{sum_list} produces the assertion parameters3025 \lstinline@sum_list@ contains seven declarations, which describe a list whose elements can be added up. 3026 The assertion ``\lstinline@|sum_list( i_list, int )@''\use{sum_list} produces the assertion parameters 3164 3027 \begin{lstlisting} 3165 3028 int ?+=?( int *, int ); … … 3178 3041 \lhs{type-parameter-list} 3179 3042 \rhs \nonterm{type-parameter} 3180 \rhs \nonterm{type-parameter-list} \lstinline $,$\nonterm{type-parameter}3043 \rhs \nonterm{type-parameter-list} \lstinline@,@ \nonterm{type-parameter} 3181 3044 \lhs{type-parameter} 3182 3045 \rhs \nonterm{type-class} \nonterm{identifier} \nonterm{assertion-list}\opt 3183 3046 \lhs{type-class} 3184 \rhs \lstinline $type$3185 \rhs \lstinline $dtype$3186 \rhs \lstinline $ftype$3047 \rhs \lstinline@type@ 3048 \rhs \lstinline@dtype@ 3049 \rhs \lstinline@ftype@ 3187 3050 \lhs{type-declaration} 3188 \rhs \nonterm{storage-class-specifier}\opt \lstinline $type$\nonterm{type-declarator-list} \verb|;|3051 \rhs \nonterm{storage-class-specifier}\opt \lstinline@type@ \nonterm{type-declarator-list} \verb|;| 3189 3052 \lhs{type-declarator-list} 3190 3053 \rhs \nonterm{type-declarator} 3191 \rhs \nonterm{type-declarator-list} \lstinline $,$\nonterm{type-declarator}3054 \rhs \nonterm{type-declarator-list} \lstinline@,@ \nonterm{type-declarator} 3192 3055 \lhs{type-declarator} 3193 \rhs \nonterm{identifier} \nonterm{assertion-list}\opt \lstinline $=$\nonterm{type-name}3056 \rhs \nonterm{identifier} \nonterm{assertion-list}\opt \lstinline@=@ \nonterm{type-name} 3194 3057 \rhs \nonterm{identifier} \nonterm{assertion-list}\opt 3195 3058 \end{syntax} … … 3202 3065 3203 3066 An identifier declared by a \nonterm{type-parameter} has \Index{no linkage}. 3204 Identifiers declared with type-class \lstinline $type$\use{type} are \Index{object type}s;3067 Identifiers declared with type-class \lstinline@type@\use{type} are \Index{object type}s; 3205 3068 those declared with type-class 3206 \lstinline $dtype$\use{dtype} are \Index{incomplete type}s;3069 \lstinline@dtype@\use{dtype} are \Index{incomplete type}s; 3207 3070 and those declared with type-class 3208 \lstinline $ftype$\use{ftype} are \Index{function type}s.3071 \lstinline@ftype@\use{ftype} are \Index{function type}s. 3209 3072 The identifier has \Index{block scope} that terminates at the end of the \nonterm{spec-declaration-list} or polymorphic function that contains the \nonterm{type-parameter}. 3210 3073 … … 3214 3077 Within the scope of the declaration, \Index{implicit conversion}s can be performed between the defined type and the implementation type, and between pointers to the defined type and pointers to the implementation type. 3215 3078 3216 A type declaration without an \Index{initializer} and without a \Index{storage-class specifier} or with storage-class specifier \lstinline $static$\use{static} defines an \Index{incomplete type}.3079 A type declaration without an \Index{initializer} and without a \Index{storage-class specifier} or with storage-class specifier \lstinline@static@\use{static} defines an \Index{incomplete type}. 3217 3080 If a 3218 3081 \Index{translation unit} or \Index{block} contains one or more such declarations for an identifier, it must contain exactly one definition of the identifier ( but not in an enclosed block, which would define a new type known only within that block). … … 3234 3097 3235 3098 A type declaration without an initializer and with \Index{storage-class specifier} 3236 \lstinline $extern$\use{extern} is an \define{opaque type declaration}.3099 \lstinline@extern@\use{extern} is an \define{opaque type declaration}. 3237 3100 Opaque types are 3238 3101 \Index{object type}s. … … 3249 3112 \end{rationale} 3250 3113 3251 An \Index{incomplete type} which is not a qualified version\index{qualified type} of a type is a value of \Index{type-class} \lstinline $dtype$.3252 An object type\index{object types} which is not a qualified version of a type is a value of type-classes \lstinline $type$ and \lstinline$dtype$.3114 An \Index{incomplete type} which is not a qualified version\index{qualified type} of a type is a value of \Index{type-class} \lstinline@dtype@. 3115 An object type\index{object types} which is not a qualified version of a type is a value of type-classes \lstinline@type@ and \lstinline@dtype@. 3253 3116 A 3254 \Index{function type} is a value of type-class \lstinline $ftype$.3117 \Index{function type} is a value of type-class \lstinline@ftype@. 3255 3118 \begin{rationale} 3256 3119 Syntactically, a type value is a \nonterm{type-name}, which is a declaration for an object which omits the identifier being declared. … … 3262 3125 Type qualifiers are a weak point of C's type system. 3263 3126 Consider the standard library function 3264 \lstinline $strchr()$which, given a string and a character, returns a pointer to the first occurrence of the character in the string.3265 \begin{lstlisting} 3266 char *strchr( const char *s, int c ) { @\impl{strchr}@3127 \lstinline@strchr()@ which, given a string and a character, returns a pointer to the first occurrence of the character in the string. 3128 \begin{lstlisting} 3129 char *strchr( const char *s, int c ) {§\impl{strchr}§ 3267 3130 char real_c = c; // done because c was declared as int. 3268 3131 for ( ; *s != real_c; s++ ) … … 3271 3134 } 3272 3135 \end{lstlisting} 3273 The parameter \lstinline $s$ must be \lstinline$const char *$, because \lstinline$strchr()$ might be used to search a constant string, but the return type must be \lstinline$char *$, because the result might be used to modify a non-constant string.3136 The parameter \lstinline@s@ must be \lstinline@const char *@, because \lstinline@strchr()@ might be used to search a constant string, but the return type must be \lstinline@char *@, because the result might be used to modify a non-constant string. 3274 3137 Hence the body must perform a cast, and ( even worse) 3275 \lstinline $strchr()$provides a type-safe way to attempt to modify constant strings.3276 What is needed is some way to say that \lstinline $s$'s type might contain qualifiers, and the result type has exactly the same qualifiers.3138 \lstinline@strchr()@ provides a type-safe way to attempt to modify constant strings. 3139 What is needed is some way to say that \lstinline@s@'s type might contain qualifiers, and the result type has exactly the same qualifiers. 3277 3140 Polymorphic functions do not provide a fix for this deficiency\index{deficiencies!pointers to qualified types}, because type qualifiers are not part of type values. 3278 Instead, overloading can be used to define \lstinline $strchr()$for each combination of qualifiers.3141 Instead, overloading can be used to define \lstinline@strchr()@ for each combination of qualifiers. 3279 3142 \end{rationale} 3280 3143 … … 3301 3164 \end{lstlisting} 3302 3165 Without this restriction, \CFA might require ``module initialization'' code ( since 3303 \lstinline $Rational$ has external linkage, it must be created before any other translation unit instantiates it), and would force an ordering on the initialization of the translation unit that defines \lstinline$Huge$ and the translation that declares \lstinline$Rational$.3166 \lstinline@Rational@ has external linkage, it must be created before any other translation unit instantiates it), and would force an ordering on the initialization of the translation unit that defines \lstinline@Huge@ and the translation that declares \lstinline@Rational@. 3304 3167 3305 3168 A benefit of the restriction is that it prevents the declaration in separate translation units of types that contain each other, which would be hard to prevent otherwise. … … 3318 3181 \nonterm{struct-declaration}, type declarations can not be structure members. 3319 3182 The form of 3320 \nonterm{type-declaration} forbids arrays of, pointers to, and functions returning \lstinline $type$.3183 \nonterm{type-declaration} forbids arrays of, pointers to, and functions returning \lstinline@type@. 3321 3184 Hence the syntax of \nonterm{type-specifier} does not have to be extended to allow type-valued expressions. 3322 3185 It also side-steps the problem of type-valued expressions producing different values in different declarations. … … 3333 3196 #include <stdlib.h> 3334 3197 T * new( otype T ) { return ( T * )malloc( sizeof( T) ); }; 3335 @\ldots@int * ip = new( int );3336 \end{lstlisting} 3337 This looks sensible, but \CFA's declaration-before-use rules mean that ``\lstinline $T$'' in the function body refers to the parameter, but the ``\lstinline$T$'' in the return type refers to the meaning of \lstinline$T$ in the scope that contains \lstinline$new$;3198 §\ldots§ int * ip = new( int ); 3199 \end{lstlisting} 3200 This looks sensible, but \CFA's declaration-before-use rules mean that ``\lstinline@T@'' in the function body refers to the parameter, but the ``\lstinline@T@'' in the return type refers to the meaning of \lstinline@T@ in the scope that contains \lstinline@new@; 3338 3201 it could be undefined, or a type name, or a function or variable name. 3339 3202 Nothing good can result from such a situation. … … 3352 3215 f2( v2 ); 3353 3216 \end{lstlisting} 3354 \lstinline $V1$ is passed by value, so \lstinline$f1()$'s assignment to \lstinline$a[0]$ does not modify v1. \lstinline$V2$ is converted to a pointer, so \lstinline$f2()$ modifies \lstinline$v2[0]$.3217 \lstinline@V1@ is passed by value, so \lstinline@f1()@'s assignment to \lstinline@a[0]@ does not modify v1. \lstinline@V2@ is converted to a pointer, so \lstinline@f2()@ modifies \lstinline@v2[0]@. 3355 3218 3356 3219 A translation unit containing the declarations 3357 3220 \begin{lstlisting} 3358 extern type Complex; @\use{Complex}@// opaque type declaration3359 extern float abs( Complex ); @\use{abs}@3360 \end{lstlisting} can contain declarations of complex numbers, which can be passed to \lstinline $abs$.3361 Some other translation unit must implement \lstinline $Complex$ and \lstinline$abs$.3221 extern type Complex;§\use{Complex}§ // opaque type declaration 3222 extern float abs( Complex );§\use{abs}§ 3223 \end{lstlisting} can contain declarations of complex numbers, which can be passed to \lstinline@abs@. 3224 Some other translation unit must implement \lstinline@Complex@ and \lstinline@abs@. 3362 3225 That unit might contain the declarations 3363 3226 \begin{lstlisting} 3364 otype Complex = struct { float re, im; }; @\impl{Complex}@3365 Complex cplx_i = { 0.0, 1.0 }; @\impl{cplx_i}@3366 float abs( Complex c ) { @\impl{abs( Complex )}@3227 otype Complex = struct { float re, im; };§\impl{Complex}§ 3228 Complex cplx_i = { 0.0, 1.0 };§\impl{cplx_i}§ 3229 float abs( Complex c ) {§\impl{abs( Complex )}§ 3367 3230 return sqrt( c.re * c.re + c.im * c.im ); 3368 3231 } 3369 3232 \end{lstlisting} 3370 Note that \lstinline $c$ is implicitly converted to a \lstinline$struct$so that its components can be retrieved.3371 3372 \begin{lstlisting} 3373 otype Time_of_day = int; @\impl{Time_of_day}@// seconds since midnight.3374 Time_of_day ?+?( Time_of_day t1, int seconds ) { @\impl{?+?}@3233 Note that \lstinline@c@ is implicitly converted to a \lstinline@struct@ so that its components can be retrieved. 3234 3235 \begin{lstlisting} 3236 otype Time_of_day = int;§\impl{Time_of_day}§ // seconds since midnight. 3237 Time_of_day ?+?( Time_of_day t1, int seconds ) {§\impl{?+?}§ 3375 3238 return (( int)t1 + seconds ) % 86400; 3376 3239 } 3377 3240 \end{lstlisting} 3378 \lstinline $t1$must be cast to its implementation type to prevent infinite recursion.3241 \lstinline@t1@ must be cast to its implementation type to prevent infinite recursion. 3379 3242 3380 3243 \begin{rationale} 3381 3244 Within the scope of a type definition, an instance of the type can be viewed as having that type or as having the implementation type. 3382 In the \lstinline $Time_of_day$example, the difference is important.3245 In the \lstinline@Time_of_day@ example, the difference is important. 3383 3246 Different languages have treated the distinction between the abstraction and the implementation in different ways. 3384 3247 \begin{itemize} 3385 3248 \item 3386 Inside a Clu cluster \cite{ clu}, the declaration of an instance states which view applies.3387 Two primitives called \lstinline $up$ and \lstinline$down$can be used to convert between the views.3388 \item 3389 The Simula class \cite{S imula87} is essentially a record type.3249 Inside a Clu cluster \cite{CLU}, the declaration of an instance states which view applies. 3250 Two primitives called \lstinline@up@ and \lstinline@down@ can be used to convert between the views. 3251 \item 3252 The Simula class \cite{SIMULA87} is essentially a record type. 3390 3253 Since the only operations on a record are member selection and assignment, which can not be overloaded, there is never any ambiguity as to whether the abstraction or the implementation view is being used. 3391 3254 In {\CC} 3392 \cite{ c++}, operations on class instances include assignment and ``\lstinline$&$'', which can be overloaded.3255 \cite{C++}, operations on class instances include assignment and ``\lstinline@&@'', which can be overloaded. 3393 3256 A ``scope resolution'' operator can be used inside the class to specify whether the abstract or implementation version of the operation should be used. 3394 3257 \item 3395 An Ada derived type definition \cite{ ada} creates a new type from an old type, and also implicitly declares derived subprograms that correspond to the existing subprograms that use the old type as a parameter type or result type.3258 An Ada derived type definition \cite{Ada} creates a new type from an old type, and also implicitly declares derived subprograms that correspond to the existing subprograms that use the old type as a parameter type or result type. 3396 3259 The derived subprograms are clones of the existing subprograms with the old type replaced by the derived type. 3397 3260 Literals and aggregates of the old type are also cloned. … … 3403 3266 In this case, explicit conversions between the derived type and the old type can be used. 3404 3267 \end{itemize} 3405 \CFA's rules are like Clu's, except that implicit conversions and conversion costs allow it to do away with most uses of \lstinline $up$ and \lstinline$down$.3268 \CFA's rules are like Clu's, except that implicit conversions and conversion costs allow it to do away with most uses of \lstinline@up@ and \lstinline@down@. 3406 3269 \end{rationale} 3407 3270 … … 3409 3272 \subsubsection{Default functions and objects} 3410 3273 3411 A declaration\index{type declaration} of a type identifier \lstinline $T$with type-class3412 \lstinline $type$implicitly declares a \define{default assignment} function3413 \lstinline $T ?=?( T *, T )$\use{?=?}, with the same \Index{scope} and \Index{linkage} as the identifier \lstinline$T$.3274 A declaration\index{type declaration} of a type identifier \lstinline@T@ with type-class 3275 \lstinline@type@ implicitly declares a \define{default assignment} function 3276 \lstinline@T ?=?( T *, T )@\use{?=?}, with the same \Index{scope} and \Index{linkage} as the identifier \lstinline@T@. 3414 3277 \begin{rationale} 3415 3278 Assignment is central to C's imperative programming style, and every existing C object type has assignment defined for it ( except for array types, which are treated as pointer types for purposes of assignment). 3416 3279 Without this rule, nearly every inferred type parameter would need an accompanying assignment assertion parameter. 3417 3280 If a type parameter should not have an assignment operation, 3418 \lstinline $dtype$should be used.3281 \lstinline@dtype@ should be used. 3419 3282 If a type should not have assignment defined, the user can define an assignment function that causes a run-time error, or provide an external declaration but no definition and thus cause a link-time error. 3420 3283 \end{rationale} 3421 3284 3422 A definition\index{type definition} of a type identifier \lstinline $T$ with \Index{implementation type} \lstinline$I$ and type-class \lstinline$type$implicitly defines a default assignment function.3423 A definition\index{type definition} of a type identifier \lstinline $T$ with implementation type \lstinline$I$and an assertion list implicitly defines \define{default function}s and3285 A definition\index{type definition} of a type identifier \lstinline@T@ with \Index{implementation type} \lstinline@I@ and type-class \lstinline@type@ implicitly defines a default assignment function. 3286 A definition\index{type definition} of a type identifier \lstinline@T@ with implementation type \lstinline@I@ and an assertion list implicitly defines \define{default function}s and 3424 3287 \define{default object}s as declared by the assertion declarations. 3425 The default objects and functions have the same \Index{scope} and \Index{linkage} as the identifier \lstinline $T$.3288 The default objects and functions have the same \Index{scope} and \Index{linkage} as the identifier \lstinline@T@. 3426 3289 Their values are determined as follows: 3427 3290 \begin{itemize} 3428 3291 \item 3429 If at the definition of \lstinline $T$ there is visible a declaration of an object with the same name as the default object, and if the type of that object with all occurrence of \lstinline$I$ replaced by \lstinline$T$is compatible with the type of the default object, then the default object is initialized with that object.3430 Otherwise the scope of the declaration of \lstinline $T$must contain a definition of the default object.3292 If at the definition of \lstinline@T@ there is visible a declaration of an object with the same name as the default object, and if the type of that object with all occurrence of \lstinline@I@ replaced by \lstinline@T@ is compatible with the type of the default object, then the default object is initialized with that object. 3293 Otherwise the scope of the declaration of \lstinline@T@ must contain a definition of the default object. 3431 3294 3432 3295 \item 3433 If at the definition of \lstinline $T$ there is visible a declaration of a function with the same name as the default function, and if the type of that function with all occurrence of \lstinline$I$ replaced by \lstinline$T$is compatible with the type of the default function, then the default function calls that function after converting its arguments and returns the converted result.3434 3435 Otherwise, if \lstinline $I$ contains exactly one anonymous member\index{anonymous member} such that at the definition of \lstinline$T$ there is visible a declaration of a function with the same name as the default function, and the type of that function with all occurrences of the anonymous member's type in its parameter list replaced by \lstinline$T$is compatible with the type of the default function, then the default function calls that function after converting its arguments and returns the result.3436 3437 Otherwise the scope of the declaration of \lstinline $T$must contain a definition of the default function.3296 If at the definition of \lstinline@T@ there is visible a declaration of a function with the same name as the default function, and if the type of that function with all occurrence of \lstinline@I@ replaced by \lstinline@T@ is compatible with the type of the default function, then the default function calls that function after converting its arguments and returns the converted result. 3297 3298 Otherwise, if \lstinline@I@ contains exactly one anonymous member\index{anonymous member} such that at the definition of \lstinline@T@ there is visible a declaration of a function with the same name as the default function, and the type of that function with all occurrences of the anonymous member's type in its parameter list replaced by \lstinline@T@ is compatible with the type of the default function, then the default function calls that function after converting its arguments and returns the result. 3299 3300 Otherwise the scope of the declaration of \lstinline@T@ must contain a definition of the default function. 3438 3301 \end{itemize} 3439 3302 \begin{rationale} … … 3441 3304 \end{rationale} 3442 3305 3443 A function or object with the same type and name as a default function or object that is declared within the scope of the definition of \lstinline $T$replaces the default function or object.3306 A function or object with the same type and name as a default function or object that is declared within the scope of the definition of \lstinline@T@ replaces the default function or object. 3444 3307 3445 3308 \examples … … 3451 3314 Pair b = { 1, 1 }; 3452 3315 \end{lstlisting} 3453 The definition of \lstinline $Pair$ implicitly defines two objects \lstinline$a$ and \lstinline$b$.3454 \lstinline $Pair a$ inherits its value from the \lstinline$struct impl a$.3316 The definition of \lstinline@Pair@ implicitly defines two objects \lstinline@a@ and \lstinline@b@. 3317 \lstinline@Pair a@ inherits its value from the \lstinline@struct impl a@. 3455 3318 The definition of 3456 \lstinline $Pair b$ is compulsory because there is no \lstinline$struct impl b$to construct a value from.3319 \lstinline@Pair b@ is compulsory because there is no \lstinline@struct impl b@ to construct a value from. 3457 3320 \begin{lstlisting} 3458 3321 trait ss( otype T ) { … … 3460 3323 void munge( T * ); 3461 3324 } 3462 otype Whatsit | ss( Whatsit ); @\use{Whatsit}@3463 otype Doodad | ss( Doodad ) = struct doodad { @\use{Doodad}@3325 otype Whatsit | ss( Whatsit );§\use{Whatsit}§ 3326 otype Doodad | ss( Doodad ) = struct doodad {§\use{Doodad}§ 3464 3327 Whatsit; // anonymous member 3465 3328 int extra; … … 3467 3330 Doodad clone( Doodad ) { ... } 3468 3331 \end{lstlisting} 3469 The definition of \lstinline $Doodad$implicitly defines three functions:3332 The definition of \lstinline@Doodad@ implicitly defines three functions: 3470 3333 \begin{lstlisting} 3471 3334 Doodad ?=?( Doodad *, Doodad ); … … 3473 3336 void munge( Doodad * ); 3474 3337 \end{lstlisting} 3475 The assignment function inherits \lstinline $struct doodad$'s assignment function because the types match when \lstinline$struct doodad$ is replaced by \lstinline$Doodad$throughout.3476 \lstinline $munge()$ inherits \lstinline$Whatsit$'s \lstinline$munge()$because the types match when3477 \lstinline $Whatsit$ is replaced by \lstinline$Doodad$ in the parameter list. \lstinline$clone()$ does \emph{not} inherit \lstinline$Whatsit$'s \lstinline$clone()$: replacement in the parameter list yields ``\lstinline$Whatsit clone( Doodad )$'', which is not compatible with3478 \lstinline $Doodad$'s \lstinline$clone()$'s type.3338 The assignment function inherits \lstinline@struct doodad@'s assignment function because the types match when \lstinline@struct doodad@ is replaced by \lstinline@Doodad@ throughout. 3339 \lstinline@munge()@ inherits \lstinline@Whatsit@'s \lstinline@munge()@ because the types match when 3340 \lstinline@Whatsit@ is replaced by \lstinline@Doodad@ in the parameter list. \lstinline@clone()@ does \emph{not} inherit \lstinline@Whatsit@'s \lstinline@clone()@: replacement in the parameter list yields ``\lstinline@Whatsit clone( Doodad )@'', which is not compatible with 3341 \lstinline@Doodad@'s \lstinline@clone()@'s type. 3479 3342 Hence the definition of 3480 ``\lstinline $Doodad clone( Doodad )$'' is necessary.3343 ``\lstinline@Doodad clone( Doodad )@'' is necessary. 3481 3344 3482 3345 Default functions and objects are subject to the normal scope rules. 3483 3346 \begin{lstlisting} 3484 otype T = @\ldots@;3485 T a_T = @\ldots@; // Default assignment used.3347 otype T = §\ldots§; 3348 T a_T = §\ldots§; // Default assignment used. 3486 3349 T ?=?( T *, T ); 3487 T a_T = @\ldots@; // Programmer-defined assignment called.3350 T a_T = §\ldots§; // Programmer-defined assignment called. 3488 3351 \end{lstlisting} 3489 3352 \begin{rationale} … … 3518 3381 \begin{syntax} 3519 3382 \oldlhs{labeled-statement} 3520 \rhs \lstinline $case$\nonterm{case-value-list} : \nonterm{statement}3383 \rhs \lstinline@case@ \nonterm{case-value-list} : \nonterm{statement} 3521 3384 \lhs{case-value-list} 3522 3385 \rhs \nonterm{case-value} 3523 \rhs \nonterm{case-value-list} \lstinline $,$\nonterm{case-value}3386 \rhs \nonterm{case-value-list} \lstinline@,@ \nonterm{case-value} 3524 3387 \lhs{case-value} 3525 3388 \rhs \nonterm{constant-expression} 3526 3389 \rhs \nonterm{subrange} 3527 3390 \lhs{subrange} 3528 \rhs \nonterm{constant-expression} \lstinline $~$\nonterm{constant-expression}3391 \rhs \nonterm{constant-expression} \lstinline@~@ \nonterm{constant-expression} 3529 3392 \end{syntax} 3530 3393 … … 3539 3402 case 1~4, 9~14, 27~32: 3540 3403 \end{lstlisting} 3541 The \lstinline $case$ and \lstinline$default$ clauses are restricted within the \lstinline$switch$ and \lstinline$choose$statements, precluding Duff's device.3404 The \lstinline@case@ and \lstinline@default@ clauses are restricted within the \lstinline@switch@ and \lstinline@choose@ statements, precluding Duff's device. 3542 3405 3543 3406 3544 3407 \subsection{Expression and null statements} 3545 3408 3546 The expression in an expression statement is treated as being cast to \lstinline $void$.3409 The expression in an expression statement is treated as being cast to \lstinline@void@. 3547 3410 3548 3411 … … 3551 3414 \begin{syntax} 3552 3415 \oldlhs{selection-statement} 3553 \rhs \lstinline $choose$ \lstinline$($ \nonterm{expression} \lstinline$)$\nonterm{statement}3416 \rhs \lstinline@choose@ \lstinline@(@ \nonterm{expression} \lstinline@)@ \nonterm{statement} 3554 3417 \end{syntax} 3555 3418 3556 The controlling expression \lstinline $E$ in the \lstinline$switch$ and \lstinline$choose$statement:3419 The controlling expression \lstinline@E@ in the \lstinline@switch@ and \lstinline@choose@ statement: 3557 3420 \begin{lstlisting} 3558 3421 switch ( E ) ... … … 3560 3423 \end{lstlisting} may have more than one interpretation, but it shall have only one interpretation with an integral type. 3561 3424 An \Index{integer promotion} is performed on the expression if necessary. 3562 The constant expressions in \lstinline $case$statements with the switch are converted to the promoted type.3425 The constant expressions in \lstinline@case@ statements with the switch are converted to the promoted type. 3563 3426 3564 3427 3565 3428 \setcounter{subsubsection}{3} 3566 \subsubsection {The \lstinline$choose$statement}3567 3568 The \lstinline $choose$ statement is the same as the \lstinline$switch$ statement except control transfers to the end of the \lstinline$choose$ statement at a \lstinline$case$ or \lstinline$default$labeled statement.3569 The \lstinline $fallthru$ statement is used to fall through to the next \lstinline$case$ or \lstinline$default$labeled statement.3429 \subsubsection[The choose statement]{The \lstinline@choose@ statement} 3430 3431 The \lstinline@choose@ statement is the same as the \lstinline@switch@ statement except control transfers to the end of the \lstinline@choose@ statement at a \lstinline@case@ or \lstinline@default@ labeled statement. 3432 The \lstinline@fallthru@ statement is used to fall through to the next \lstinline@case@ or \lstinline@default@ labeled statement. 3570 3433 The following have identical meaning: 3571 3434 \begin{flushleft} … … 3592 3455 \end{tabular} 3593 3456 \end{flushleft} 3594 The \lstinline $choose$ statement addresses the problem of accidental fall-through associated with the \lstinline$switch$statement.3457 The \lstinline@choose@ statement addresses the problem of accidental fall-through associated with the \lstinline@switch@ statement. 3595 3458 3596 3459 3597 3460 \subsection{Iteration statements} 3598 3461 3599 The controlling expression \lstinline $E$in the loops3462 The controlling expression \lstinline@E@ in the loops 3600 3463 \begin{lstlisting} 3601 3464 if ( E ) ... 3602 3465 while ( E ) ... 3603 3466 do ... while ( E ); 3604 \end{lstlisting} is treated as ``\lstinline $( int )((E)!=0)$''.3467 \end{lstlisting} is treated as ``\lstinline@( int )((E)!=0)@''. 3605 3468 3606 3469 The statement 3607 3470 \begin{lstlisting} 3608 for ( a; b; c ) @\ldots@3471 for ( a; b; c ) §\ldots§ 3609 3472 \end{lstlisting} is treated as 3610 3473 \begin{lstlisting} … … 3617 3480 \begin{syntax} 3618 3481 \oldlhs{jump-statement} 3619 \rhs \lstinline $continue$\nonterm{identifier}\opt3620 \rhs \lstinline $break$\nonterm{identifier}\opt3482 \rhs \lstinline@continue@ \nonterm{identifier}\opt 3483 \rhs \lstinline@break@ \nonterm{identifier}\opt 3621 3484 \rhs \ldots 3622 \rhs \lstinline $throw$\nonterm{assignment-expression}\opt3623 \rhs \lstinline $throwResume$\nonterm{assignment-expression}\opt \nonterm{at-expression}\opt3624 \lhs{at-expression} \lstinline $_At$\nonterm{assignment-expression}3485 \rhs \lstinline@throw@ \nonterm{assignment-expression}\opt 3486 \rhs \lstinline@throwResume@ \nonterm{assignment-expression}\opt \nonterm{at-expression}\opt 3487 \lhs{at-expression} \lstinline@_At@ \nonterm{assignment-expression} 3625 3488 \end{syntax} 3626 3489 3627 Labeled \lstinline $continue$ and \lstinline$break$ allow useful but restricted control-flow that reduces the need for the \lstinline$goto$statement for exiting multiple nested control-structures.3490 Labeled \lstinline@continue@ and \lstinline@break@ allow useful but restricted control-flow that reduces the need for the \lstinline@goto@ statement for exiting multiple nested control-structures. 3628 3491 \begin{lstlisting} 3629 3492 L1: { // compound … … 3652 3515 3653 3516 \setcounter{subsubsection}{1} 3654 \subsubsection {The \lstinline$continue$statement}3655 3656 The identifier in a \lstinline $continue$statement shall name a label located on an enclosing iteration statement.3657 3658 3659 \subsubsection {The \lstinline$break$statement}3660 3661 The identifier in a \lstinline $break$statement shall name a label located on an enclosing compound, selection or iteration statement.3662 3663 3664 \subsubsection {The \lstinline$return$statement}3665 3666 An expression in a \lstinline $return$statement is treated as being cast to the result type of the function.3667 3668 3669 \subsubsection {The \lstinline$throw$statement}3517 \subsubsection[The continue statement]{The \lstinline@continue@ statement} 3518 3519 The identifier in a \lstinline@continue@ statement shall name a label located on an enclosing iteration statement. 3520 3521 3522 \subsubsection[The break statement]{The \lstinline@break@ statement} 3523 3524 The identifier in a \lstinline@break@ statement shall name a label located on an enclosing compound, selection or iteration statement. 3525 3526 3527 \subsubsection[The return statement]{The \lstinline@return@ statement} 3528 3529 An expression in a \lstinline@return@ statement is treated as being cast to the result type of the function. 3530 3531 3532 \subsubsection[The throw statement]{The \lstinline@throw@ statement} 3670 3533 3671 3534 When an exception is raised, \Index{propagation} directs control from a raise in the source execution to a handler in the faulting execution. 3672 3535 3673 3536 3674 \subsubsection {The \lstinline$throwResume$statement}3537 \subsubsection[The throwResume statement]{The \lstinline@throwResume@ statement} 3675 3538 3676 3539 … … 3679 3542 \begin{syntax} 3680 3543 \lhs{exception-statement} 3681 \rhs \lstinline $try$\nonterm{compound-statement} \nonterm{handler-list}3682 \rhs \lstinline $try$\nonterm{compound-statement} \nonterm{finally-clause}3683 \rhs \lstinline $try$\nonterm{compound-statement} \nonterm{handler-list} \nonterm{finally-clause}3544 \rhs \lstinline@try@ \nonterm{compound-statement} \nonterm{handler-list} 3545 \rhs \lstinline@try@ \nonterm{compound-statement} \nonterm{finally-clause} 3546 \rhs \lstinline@try@ \nonterm{compound-statement} \nonterm{handler-list} \nonterm{finally-clause} 3684 3547 \lhs{handler-list} 3685 3548 \rhs \nonterm{handler-clause} 3686 \rhs \lstinline $catch$ \lstinline$($ \ldots \lstinline$)$\nonterm{compound-statement}3687 \rhs \nonterm{handler-clause} \lstinline $catch$ \lstinline$($ \ldots \lstinline$)$\nonterm{compound-statement}3688 \rhs \lstinline $catchResume$ \lstinline$($ \ldots \lstinline$)$\nonterm{compound-statement}3689 \rhs \nonterm{handler-clause} \lstinline $catchResume$ \lstinline$($ \ldots \lstinline$)$\nonterm{compound-statement}3549 \rhs \lstinline@catch@ \lstinline@(@ \ldots \lstinline@)@ \nonterm{compound-statement} 3550 \rhs \nonterm{handler-clause} \lstinline@catch@ \lstinline@(@ \ldots \lstinline@)@ \nonterm{compound-statement} 3551 \rhs \lstinline@catchResume@ \lstinline@(@ \ldots \lstinline@)@ \nonterm{compound-statement} 3552 \rhs \nonterm{handler-clause} \lstinline@catchResume@ \lstinline@(@ \ldots \lstinline@)@ \nonterm{compound-statement} 3690 3553 \lhs{handler-clause} 3691 \rhs \lstinline $catch$ \lstinline$($ \nonterm{exception-declaration} \lstinline$)$\nonterm{compound-statement}3692 \rhs \nonterm{handler-clause} \lstinline $catch$ \lstinline$($ \nonterm{exception-declaration} \lstinline$)$\nonterm{compound-statement}3693 \rhs \lstinline $catchResume$ \lstinline$($ \nonterm{exception-declaration} \lstinline$)$\nonterm{compound-statement}3694 \rhs \nonterm{handler-clause} \lstinline $catchResume$ \lstinline$($ \nonterm{exception-declaration} \lstinline$)$\nonterm{compound-statement}3554 \rhs \lstinline@catch@ \lstinline@(@ \nonterm{exception-declaration} \lstinline@)@ \nonterm{compound-statement} 3555 \rhs \nonterm{handler-clause} \lstinline@catch@ \lstinline@(@ \nonterm{exception-declaration} \lstinline@)@ \nonterm{compound-statement} 3556 \rhs \lstinline@catchResume@ \lstinline@(@ \nonterm{exception-declaration} \lstinline@)@ \nonterm{compound-statement} 3557 \rhs \nonterm{handler-clause} \lstinline@catchResume@ \lstinline@(@ \nonterm{exception-declaration} \lstinline@)@ \nonterm{compound-statement} 3695 3558 \lhs{finally-clause} 3696 \rhs \lstinline $finally$\nonterm{compound-statement}3559 \rhs \lstinline@finally@ \nonterm{compound-statement} 3697 3560 \lhs{exception-declaration} 3698 3561 \rhs \nonterm{type-specifier} … … 3702 3565 \rhs \nonterm{new-abstract-declarator-tuple} 3703 3566 \lhs{asynchronous-statement} 3704 \rhs \lstinline $enable$\nonterm{identifier-list} \nonterm{compound-statement}3705 \rhs \lstinline $disable$\nonterm{identifier-list} \nonterm{compound-statement}3567 \rhs \lstinline@enable@ \nonterm{identifier-list} \nonterm{compound-statement} 3568 \rhs \lstinline@disable@ \nonterm{identifier-list} \nonterm{compound-statement} 3706 3569 \end{syntax} 3707 3570 … … 3709 3572 3710 3573 3711 \subsubsection {The \lstinline$try$statement}3712 3713 The \lstinline $try$statement is a block with associated handlers, called a \Index{guarded block};3574 \subsubsection[The try statement]{The \lstinline@try@ statement} 3575 3576 The \lstinline@try@ statement is a block with associated handlers, called a \Index{guarded block}; 3714 3577 all other blocks are \Index{unguarded block}s. 3715 A \lstinline $goto$, \lstinline$break$, \lstinline$return$, or \lstinline$continue$statement can be used to transfer control out of a try block or handler, but not into one.3716 3717 3718 \subsubsection {The \lstinline$enable$/\lstinline$disable$statements}3719 3720 The \lstinline $enable$/\lstinline$disable$statements toggle delivery of \Index{asynchronous exception}s.3578 A \lstinline@goto@, \lstinline@break@, \lstinline@return@, or \lstinline@continue@ statement can be used to transfer control out of a try block or handler, but not into one. 3579 3580 3581 \subsubsection[The enable/disable statements]{The \lstinline@enable@/\lstinline@disable@ statements} 3582 3583 The \lstinline@enable@/\lstinline@disable@ statements toggle delivery of \Index{asynchronous exception}s. 3721 3584 3722 3585 … … 3728 3591 \subsection{Predefined macro names} 3729 3592 3730 The implementation shall define the macro names \lstinline $__LINE__$, \lstinline$__FILE__$,3731 \lstinline $__DATE__$, and \lstinline$__TIME__$, as in the {\c11} standard.3732 It shall not define the macro name \lstinline $__STDC__$.3733 3734 In addition, the implementation shall define the macro name \lstinline $__CFORALL__$to be the decimal constant 1.3593 The implementation shall define the macro names \lstinline@__LINE__@, \lstinline@__FILE__@, 3594 \lstinline@__DATE__@, and \lstinline@__TIME__@, as in the {\c11} standard. 3595 It shall not define the macro name \lstinline@__STDC__@. 3596 3597 In addition, the implementation shall define the macro name \lstinline@__CFORALL__@ to be the decimal constant 1. 3735 3598 3736 3599 … … 3749 3612 The pointer, integral, and floating-point types are all \define{scalar types}. 3750 3613 All of these types can be logically negated and compared. 3751 The assertion ``\lstinline $scalar( Complex )$'' should be read as ``type \lstinline$Complex$is scalar''.3752 \begin{lstlisting} 3753 trait scalar( otype T ) { @\impl{scalar}@3614 The assertion ``\lstinline@scalar( Complex )@'' should be read as ``type \lstinline@Complex@ is scalar''. 3615 \begin{lstlisting} 3616 trait scalar( otype T ) {§\impl{scalar}§ 3754 3617 int !?( T ); 3755 3618 int ?<?( T, T ), ?<=?( T, T ), ?==?( T, T ), ?>=?( T, T ), ?>?( T, T ), ?!=?( T, T ); … … 3761 3624 This is equivalent to inheritance of specifications. 3762 3625 \begin{lstlisting} 3763 trait arithmetic( otype T | scalar( T ) ) { @\impl{arithmetic}@@\use{scalar}@3626 trait arithmetic( otype T | scalar( T ) ) {§\impl{arithmetic}§§\use{scalar}§ 3764 3627 T +?( T ), -?( T ); 3765 3628 T ?*?( T, T ), ?/?( T, T ), ?+?( T, T ), ?-?( T, T ); … … 3767 3630 \end{lstlisting} 3768 3631 3769 The various flavors of \lstinline $char$ and \lstinline$int$and the enumerated types make up the3632 The various flavors of \lstinline@char@ and \lstinline@int@ and the enumerated types make up the 3770 3633 \define{integral types}. 3771 3634 \begin{lstlisting} 3772 trait integral( otype T | arithmetic( T ) ) { @\impl{integral}@@\use{arithmetic}@3635 trait integral( otype T | arithmetic( T ) ) {§\impl{integral}§§\use{arithmetic}§ 3773 3636 T ~?( T ); 3774 3637 T ?&?( T, T ), ?|?( T, T ), ?^?( T, T ); … … 3784 3647 The only operation that can be applied to all modifiable lvalues is simple assignment. 3785 3648 \begin{lstlisting} 3786 trait m_lvalue( otype T ) { @\impl{m_lvalue}@3649 trait m_lvalue( otype T ) {§\impl{m_lvalue}§ 3787 3650 T ?=?( T *, T ); 3788 3651 }; … … 3794 3657 Scalars can also be incremented and decremented. 3795 3658 \begin{lstlisting} 3796 trait m_l_scalar( otype T | scalar( T ) | m_lvalue( T ) ) { @\impl{m_l_scalar}@3797 T ?++( T * ), ?--( T * ); @\use{scalar}@@\use{m_lvalue}@3659 trait m_l_scalar( otype T | scalar( T ) | m_lvalue( T ) ) {§\impl{m_l_scalar}§ 3660 T ?++( T * ), ?--( T * );§\use{scalar}§§\use{m_lvalue}§ 3798 3661 T ++?( T * ), --?( T * ); 3799 3662 }; … … 3801 3664 3802 3665 Modifiable arithmetic lvalues are both modifiable scalar lvalues and arithmetic. 3803 Note that this results in the ``inheritance'' of \lstinline $scalar$along both paths.3804 \begin{lstlisting} 3805 trait m_l_arithmetic( otype T | m_l_scalar( T ) | arithmetic( T ) ) { @\impl{m_l_arithmetic}@3806 T ?/=?( T *, T ), ?*=?( T *, T ); @\use{m_l_scalar}@@\use{arithmetic}@3666 Note that this results in the ``inheritance'' of \lstinline@scalar@ along both paths. 3667 \begin{lstlisting} 3668 trait m_l_arithmetic( otype T | m_l_scalar( T ) | arithmetic( T ) ) {§\impl{m_l_arithmetic}§ 3669 T ?/=?( T *, T ), ?*=?( T *, T );§\use{m_l_scalar}§§\use{arithmetic}§ 3807 3670 T ?+=?( T *, T ), ?-=?( T *, T ); 3808 3671 }; 3809 trait m_l_integral( otype T | m_l_arithmetic( T ) | integral( T ) ) { @\impl{m_l_integral}@3810 T ?&=?( T *, T ), ?|=?( T *, T ), ?^=?( T *, T ); @\use{m_l_arithmetic}@3811 T ?%=?( T *, T ), ?<<=?( T *, T ), ?>>=?( T *, T ); @\use{integral}@3672 trait m_l_integral( otype T | m_l_arithmetic( T ) | integral( T ) ) {§\impl{m_l_integral}§ 3673 T ?&=?( T *, T ), ?|=?( T *, T ), ?^=?( T *, T );§\use{m_l_arithmetic}§ 3674 T ?%=?( T *, T ), ?<<=?( T *, T ), ?>>=?( T *, T );§\use{integral}§ 3812 3675 }; 3813 3676 \end{lstlisting} … … 3817 3680 3818 3681 Array types can barely be said to exist in {\c11}, since in most cases an array name is treated as a constant pointer to the first element of the array, and the subscript expression 3819 ``\lstinline $a[i]$'' is equivalent to the dereferencing expression ``\lstinline$(*( a+( i )))$''.3820 Technically, pointer arithmetic and pointer comparisons other than ``\lstinline $==$'' and3821 ``\lstinline $!=$'' are only defined for pointers to array elements, but the type system does not enforce those restrictions.3682 ``\lstinline@a[i]@'' is equivalent to the dereferencing expression ``\lstinline@(*( a+( i )))@''. 3683 Technically, pointer arithmetic and pointer comparisons other than ``\lstinline@==@'' and 3684 ``\lstinline@!=@'' are only defined for pointers to array elements, but the type system does not enforce those restrictions. 3822 3685 Consequently, there is no need for a separate ``array type'' specification. 3823 3686 3824 3687 Pointer types are scalar types. 3825 Like other scalar types, they have ``\lstinline $+$'' and3826 ``\lstinline $-$'' operators, but the types do not match the types of the operations in3827 \lstinline $arithmetic$, so these operators cannot be consolidated in \lstinline$scalar$.3828 \begin{lstlisting} 3829 trait pointer( type P | scalar( P ) ) { @\impl{pointer}@@\use{scalar}@3688 Like other scalar types, they have ``\lstinline@+@'' and 3689 ``\lstinline@-@'' operators, but the types do not match the types of the operations in 3690 \lstinline@arithmetic@, so these operators cannot be consolidated in \lstinline@scalar@. 3691 \begin{lstlisting} 3692 trait pointer( type P | scalar( P ) ) {§\impl{pointer}§§\use{scalar}§ 3830 3693 P ?+?( P, long int ), ?+?( long int, P ), ?-?( P, long int ); 3831 3694 ptrdiff_t ?-?( P, P ); 3832 3695 }; 3833 trait m_l_pointer( type P | pointer( P ) | m_l_scalar( P ) ) { @\impl{m_l_pointer}@3696 trait m_l_pointer( type P | pointer( P ) | m_l_scalar( P ) ) {§\impl{m_l_pointer}§ 3834 3697 P ?+=?( P *, long int ), ?-=?( P *, long int ); 3835 3698 P ?=?( P *, void * ); … … 3840 3703 Specifications that define the dereference operator ( or subscript operator ) require two parameters, one for the pointer type and one for the pointed-at ( or element ) type. 3841 3704 Different specifications are needed for each set of \Index{type qualifier}s, because qualifiers are not included in types. 3842 The assertion ``\lstinline $|ptr_to( Safe_pointer, int )$'' should be read as3843 ``\lstinline $Safe_pointer$ acts like a pointer to \lstinline$int$''.3844 \begin{lstlisting} 3845 trait ptr_to( type P | pointer( P ), otype T ) {@\impl{ptr_to}@@\use{pointer}@3705 The assertion ``\lstinline@|ptr_to( Safe_pointer, int )@'' should be read as 3706 ``\lstinline@Safe_pointer@ acts like a pointer to \lstinline@int@''. 3707 \begin{lstlisting} 3708 trait ptr_to( otype P | pointer( P ), otype T ) {§\impl{ptr_to}§§\use{pointer}§ 3846 3709 lvalue T *?( P ); 3847 3710 lvalue T ?[?]( P, long int ); 3848 3711 }; 3849 trait ptr_to_const( type P | pointer( P ), otype T ) {@\impl{ptr_to_const}@3712 trait ptr_to_const( otype P | pointer( P ), otype T ) {§\impl{ptr_to_const}§ 3850 3713 const lvalue T *?( P ); 3851 const lvalue T ?[?]( P, long int ); @\use{pointer}@3714 const lvalue T ?[?]( P, long int );§\use{pointer}§ 3852 3715 }; 3853 trait ptr_to_volatile( type P | pointer( P ), otype T ) }@\impl{ptr_to_volatile}@3716 trait ptr_to_volatile( otype P | pointer( P ), otype T ) }§\impl{ptr_to_volatile}§ 3854 3717 volatile lvalue T *?( P ); 3855 volatile lvalue T ?[?]( P, long int ); @\use{pointer}@3718 volatile lvalue T ?[?]( P, long int );§\use{pointer}§ 3856 3719 }; 3857 trait ptr_to_const_volatile( type P | pointer( P ), otype T ) }@\impl{ptr_to_const_volatile}@3858 const volatile lvalue T *?( P ); @\use{pointer}@3720 trait ptr_to_const_volatile( otype P | pointer( P ), otype T ) }§\impl{ptr_to_const_volatile}§ 3721 const volatile lvalue T *?( P );§\use{pointer}§ 3859 3722 const volatile lvalue T ?[?]( P, long int ); 3860 3723 }; 3861 3724 \end{lstlisting} 3862 3725 3863 Assignment to pointers is more complicated than is the case with other types, because the target's type can have extra type qualifiers in the pointed-at type: a ``\lstinline $T *$'' can be assigned to a ``\lstinline$const T *$'', a ``\lstinline$volatile T *$'', and a ``\lstinline$const volatile T *$''.3726 Assignment to pointers is more complicated than is the case with other types, because the target's type can have extra type qualifiers in the pointed-at type: a ``\lstinline@T *@'' can be assigned to a ``\lstinline@const T *@'', a ``\lstinline@volatile T *@'', and a ``\lstinline@const volatile T *@''. 3864 3727 Again, the pointed-at type is passed in, so that assertions can connect these specifications to the 3865 ``\lstinline $ptr_to$'' specifications.3866 \begin{lstlisting} 3867 trait m_l_ptr_to( type P | m_l_pointer( P ),@\use{m_l_pointer}@@\impl{m_l_ptr_to}@ otype T | ptr_to( P, T )@\use{ptr_to}@{3728 ``\lstinline@ptr_to@'' specifications. 3729 \begin{lstlisting} 3730 trait m_l_ptr_to( otype P | m_l_pointer( P ),§\use{m_l_pointer}§§\impl{m_l_ptr_to}§ otype T | ptr_to( P, T )§\use{ptr_to}§ { 3868 3731 P ?=?( P *, T * ); 3869 3732 T * ?=?( T **, P ); 3870 3733 }; 3871 trait m_l_ptr_to_const( type P | m_l_pointer( P ),@\use{m_l_pointer}@@\impl{m_l_ptr_to_const}@ otype T | ptr_to_const( P, T )@\use{ptr_to_const}@) {3734 trait m_l_ptr_to_const( otype P | m_l_pointer( P ),§\use{m_l_pointer}§§\impl{m_l_ptr_to_const}§ otype T | ptr_to_const( P, T )§\use{ptr_to_const}§) { 3872 3735 P ?=?( P *, const T * ); 3873 3736 const T * ?=?( const T **, P ); 3874 3737 }; 3875 trait m_l_ptr_to_volatile( type P | m_l_pointer( P ),@\use{m_l_pointer}@@\impl{m_l_ptr_to_volatile}@ otype T | ptr_to_volatile( P, T )) {@\use{ptr_to_volatile}@3738 trait m_l_ptr_to_volatile( otype P | m_l_pointer( P ),§\use{m_l_pointer}§§\impl{m_l_ptr_to_volatile}§ otype T | ptr_to_volatile( P, T )) {§\use{ptr_to_volatile}§ 3876 3739 P ?=?( P *, volatile T * ); 3877 3740 volatile T * ?=?( volatile T **, P ); 3878 3741 }; 3879 trait m_l_ptr_to_const_volatile( type P | ptr_to_const_volatile( P ),@\use{ptr_to_const_volatile}@@\impl{m_l_ptr_to_const_volatile}@3880 type T | m_l_ptr_to_volatile( P, T ) | m_l_ptr_to_const( P )) {@\use{m_l_ptr_to_const}@@\use{m_l_ptr_to_volatile}@3742 trait m_l_ptr_to_const_volatile( otype P | ptr_to_const_volatile( P ),§\use{ptr_to_const_volatile}§§\impl{m_l_ptr_to_const_volatile}§ 3743 otype T | m_l_ptr_to_volatile( P, T ) | m_l_ptr_to_const( P )) {§\use{m_l_ptr_to_const}§§\use{m_l_ptr_to_volatile}§ 3881 3744 P ?=?( P *, const volatile T * ); 3882 3745 const volatile T * ?=?( const volatile T **, P ); … … 3887 3750 An alternative specification can make use of the fact that qualification of the pointed-at type is part of a pointer type to capture that regularity. 3888 3751 \begin{lstlisting} 3889 trait m_l_ptr_like( type MyP | m_l_pointer( MyP ), @\use{m_l_pointer}@@\impl{m_l_ptr_like}@type CP | m_l_pointer( CP ) ) {3752 trait m_l_ptr_like( type MyP | m_l_pointer( MyP ),§\use{m_l_pointer}§§\impl{m_l_ptr_like}§ type CP | m_l_pointer( CP ) ) { 3890 3753 MyP ?=?( MyP *, CP ); 3891 3754 CP ?=?( CP *, MyP ); 3892 3755 }; 3893 3756 \end{lstlisting} 3894 The assertion ``\lstinline $| m_l_ptr_like( Safe_ptr, const int * )$'' should be read as3895 ``\lstinline $Safe_ptr$ is a pointer type like \lstinline$const int *$''.3757 The assertion ``\lstinline@| m_l_ptr_like( Safe_ptr, const int * )@'' should be read as 3758 ``\lstinline@Safe_ptr@ is a pointer type like \lstinline@const int *@''. 3896 3759 This specification has two defects, compared to the original four: there is no automatic assertion that dereferencing a 3897 \lstinline $MyP$ produces an lvalue of the type that \lstinline$CP$points at, and the3898 ``\lstinline $|m_l_pointer( CP )$'' assertion provides only a weak assurance that the argument passed to \lstinline$CP$really is a pointer type.3760 \lstinline@MyP@ produces an lvalue of the type that \lstinline@CP@ points at, and the 3761 ``\lstinline@|m_l_pointer( CP )@'' assertion provides only a weak assurance that the argument passed to \lstinline@CP@ really is a pointer type. 3899 3762 3900 3763 … … 3902 3765 3903 3766 Different operators often have related meanings; 3904 for instance, in C, ``\lstinline $+$'',3905 ``\lstinline $+=$'', and the two versions of ``\lstinline$++$'' perform variations of addition.3767 for instance, in C, ``\lstinline@+@'', 3768 ``\lstinline@+=@'', and the two versions of ``\lstinline@++@'' perform variations of addition. 3906 3769 Languages like {\CC} and Ada allow programmers to define operators for new types, but do not require that these relationships be preserved, or even that all of the operators be implemented. 3907 3770 Completeness and consistency is left to the good taste and discretion of the programmer. … … 3916 3779 The different comparison operators have obvious relationships, but there is no obvious subset of the operations to use in the implementation of the others. 3917 3780 However, it is usually convenient to implement a single comparison function that returns a negative integer, 0, or a positive integer if its first argument is respectively less than, equal to, or greater than its second argument; 3918 the library function \lstinline $strcmp$is an example.3919 3920 C and \CFA have an extra, non-obvious comparison operator: ``\lstinline $!$'', logical negation, returns 1 if its operand compares equal to 0, and 0 otherwise.3781 the library function \lstinline@strcmp@ is an example. 3782 3783 C and \CFA have an extra, non-obvious comparison operator: ``\lstinline@!@'', logical negation, returns 1 if its operand compares equal to 0, and 0 otherwise. 3921 3784 \begin{lstlisting} 3922 3785 trait comparable( otype T ) { … … 3967 3830 3968 3831 Note that, although an arithmetic type would certainly provide comparison functions, and an integral type would provide arithmetic operations, there does not have to be any relationship among 3969 \lstinline $int_base$, \lstinline$arith_base$ and \lstinline$comparable$.3832 \lstinline@int_base@, \lstinline@arith_base@ and \lstinline@comparable@. 3970 3833 Note also that these declarations provide guidance and assistance, but they do not define an absolutely minimal set of requirements. 3971 A truly minimal implementation of an arithmetic type might only provide 3972 \lstinline$0$, \lstinline$1$, and \lstinline$?-=?$, which would be used by polymorphic 3973 \lstinline$?+=?$, \lstinline$?*=?$, and \lstinline$?/=?$ functions. 3974 3975 Note also that \lstinline$short$ is an integer type in C11 terms, but has no operations! 3834 A truly minimal implementation of an arithmetic type might only provide \lstinline@0@, \lstinline@1@, and \lstinline@?-=?@, which would be used by polymorphic \lstinline@?+=?@, \lstinline@?*=?@, and \lstinline@?/=?@ functions. 3835 3836 Note also that \lstinline@short@ is an integer type in C11 terms, but has no operations! 3976 3837 3977 3838 … … 3980 3841 3981 3842 Restrict allowed to qualify anything, or type/dtype parameters, but only affects pointers. 3982 This gets into \lstinline $noalias$territory.3983 Qualifying anything (``\lstinline $short restrict rs$'') means pointer parameters of \lstinline$?++$, etc, would need restrict qualifiers.3843 This gets into \lstinline@noalias@ territory. 3844 Qualifying anything (``\lstinline@short restrict rs@'') means pointer parameters of \lstinline@?++@, etc, would need restrict qualifiers. 3984 3845 3985 3846 Enumerated types. … … 3991 3852 Color, enum Color ) really make sense? ?++ does, but it adds (int)1. 3992 3853 3993 Operators on {,signed,unsigned} char and other small types. ?<?harmless;3854 Operators on {,signed,unsigned} char and other small types. \lstinline@?<?@ harmless; 3994 3855 ?*? questionable for chars. 3995 3856 Generic selections make these choices visible. … … 3997 3858 ``promotion'' function? 3998 3859 3999 \lstinline $register$assignment might be handled as assignment to a temporary with copying back and forth, but copying must not be done by assignment.4000 4001 Don't use ptrdiff\_tby name in the predefineds.3860 \lstinline@register@ assignment might be handled as assignment to a temporary with copying back and forth, but copying must not be done by assignment. 3861 3862 Don't use \lstinline@ptrdiff_t@ by name in the predefineds. 4002 3863 4003 3864 Polymorphic objects. … … 4006 3867 4007 3868 \bibliographystyle{plain} 4008 \bibliography{ refrat}3869 \bibliography{cfa} 4009 3870 4010 3871
Note:
See TracChangeset
for help on using the changeset viewer.