Changeset 41b3ddd
- Timestamp:
- Sep 23, 2015, 11:02:48 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, string, with_gc
- Children:
- bfee448
- Parents:
- 01414f1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/refrat/refrat.tex
r01414f1 r41b3ddd 10 10 \usepackage{varioref} 11 11 \usepackage{listings} 12 \usepackage{comment} 12 13 \usepackage{latexsym} % \Box 13 14 \usepackage{mathptmx} % better math font with "times" … … 112 113 113 114 \lstdefinelanguage{CFA}[ANSI]{C}% 114 {morekeywords={asm,_At omic,catch,catchResume,choose,_Complex,context,disable,dtype,enable,115 {morekeywords={asm,_At,_Atomic,catch,catchResume,choose,_Complex,context,disable,dtype,enable, 115 116 fallthru,finally,forall,ftype,_Imaginary,lvalue,restrict,throw,throwResume,try,type,}, 116 117 } … … 184 185 185 186 % No ``Scope'' or ``Normative references'' chapters yet. 187 188 186 189 \setcounter{chapter}{2} 187 190 \chapter{Terms, definitions, and symbols} 191 188 192 Terms from the {\c11} standard used in this document have the same meaning as in the {\c11} 189 193 standard. 190 194 191 195 % No ``Conformance'' or ``Environment'' chapters yet. 196 197 192 198 \setcounter{chapter}{5} 193 199 \chapter{Language} 200 201 194 202 \section{Notation} 195 203 The syntax notation used in this document is the same as is used in the {\c11} standard, with one … … 235 243 \end{rationale} 236 244 245 246 \setcounter{subsection}{8} 247 \subsection{Generic Types} 248 249 250 \subsubsection{Semantics} 251 252 CFA provides a capability for generic types; using this capability a single "generic type generator" 253 can be written that can represent multiple concrete type instantiations by substitution of the "type 254 parameters" of the generic type for concrete types. Syntactically a generic type generator is 255 represented by putting a forall specifier on a struct or union declaration, as defined in section 256 6.7.2.5. An instantiation of the generic type is written by specifying the type parameters in 257 parentheses after the name of the generic type generator, as in the following example: 258 \begin{lstlisting} 259 forall( type T ) struct pair { 260 T x; 261 T y; 262 }; 263 264 pair( int ) p = { 3, 14 }; 265 \end{lstlisting} 266 267 The type parameters in an instantiation of a generic type must satisfy any constraints in the forall 268 specifier on the type generator declaration. The instantiation then has the semantics that would 269 result if the type parameters were substituted into the type generator declaration by macro 270 substitution. 271 272 Polymorphic functions may have generic types as parameters, and those generic types may use type 273 parameters of the polymorphic function as type parameters of the generic type, as in the following 274 example: 275 \begin{lstlisting} 276 forall( type T ) void swap( pair(T) *p ) { 277 T z = p->x; 278 p->x = p->y; 279 p->y = z; 280 } 281 \end{lstlisting} 282 283 284 \subsubsection{Constraints} 285 286 To avoid unduly constraining implementors, the generic type generator definition must be visible at 287 any point where it is instantiated. Forward declarations of generic type generators are not 288 forbidden, but the definition must be visible to instantiate the generic type. Equivalently, 289 instantiations of generic types are not allowed to be incomplete types. 290 291 \examples 292 \begin{lstlisting} 293 forall( type T ) struct A; 294 295 forall( type T ) struct B { 296 A(T) *a; // legal, but cannot instantiate B(T) 297 }; 298 299 B(T) x; // illegal, *x.a is of an incomplete generic type 300 301 forall( type T ) struct A { 302 B( T ) *b; 303 }; 304 305 B( T ) y; // legal, *x.a is now of a complete generic type 306 307 308 // box.h: 309 forall( type T ) struct box; 310 forall( type T ) box( T ) *make_box( T ); 311 forall( type T ) void use_box( box( T ) *b ); 312 313 // main.c: 314 box( int ) *b = make_box( 42 ); // illegal, def'n of box not visible 315 use_box( b ); // illegal 316 \end{lstlisting} 317 318 237 319 \section{Conversions} 238 320 \CFA defines situations where values of one type are automatically converted to another type. … … 242 324 243 325 \subsection{Arithmetic operands} 244 \setcounter{subsubsection}{7} 245 246 326 327 328 \setcounter{subsubsection}{8} 247 329 \subsubsection{Safe arithmetic conversions} 330 248 331 In C, a pattern of conversions known as the \define{usual arithmetic conversion}s is used with most 249 332 binary arithmetic operators to convert the operands to a common type and determine the type of the … … 302 385 303 386 \subsection{Other operands} 387 388 304 389 \setcounter{subsubsection}{3} 305 306 307 390 \subsubsection{Anonymous structures and unions} 308 391 \label{anon-conv} … … 3319 3402 3320 3403 \setcounter{subsubsection}{4} 3321 \subsubsection{Forall specifiers}\label{forall} 3404 \subsubsection{Forall specifiers} 3405 \label{forall} 3322 3406 3323 3407 \begin{syntax} … … 3326 3410 \end{syntax} 3327 3411 3412 \begin{comment} 3328 3413 \constraints 3329 3414 If the \nonterm{declaration-specifiers} of a declaration that contains a \nonterm{forall-specifier} … … 3339 3424 members' type be? 3340 3425 \end{rationale} 3426 \end{comment} 3341 3427 3342 3428 \semantics … … 3344 3430 identifiers, function and object identifiers with \Index{no linkage}. 3345 3431 3346 If, in the declaration ``\lstinline$T D 1$'', \lstinline$T$ contains \nonterm{forall-specifier}s and3347 \lstinline$D 1$ has the form3432 If, in the declaration ``\lstinline$T D$'', \lstinline$T$ contains \nonterm{forall-specifier}s and 3433 \lstinline$D$ has the form 3348 3434 \begin{lstlisting} 3349 3435 D( @\normalsize\nonterm{parameter-type-list}@ ) … … 3356 3442 assertions that use an inferred parameter of a function declarator are \Index{assertion parameter}s 3357 3443 of that function declarator. 3444 3445 \begin{comment} 3358 3446 \begin{rationale} 3359 3447 Since every inferred parameter is used by some parameter, inference can be understood as a single … … 3376 3464 \end{lstlisting} 3377 3465 \end{rationale} 3466 \end{comment} 3378 3467 3379 3468 If a function declarator is part of a function definition, its inferred parameters and assertion
Note: See TracChangeset
for help on using the changeset viewer.