Changes in / [ae357ec:bed4c63e]
- Files:
-
- 11 added
- 18 edited
-
doc/refrat/refrat.tex (modified) (69 diffs)
-
src/examples/fstream_test.c (modified) (2 diffs)
-
src/examples/huge.c (modified) (1 diff)
-
src/examples/identity.c (modified) (1 diff)
-
src/examples/includes.c (modified) (6 diffs)
-
src/examples/it_out.c (modified) (5 diffs)
-
src/examples/new.c (modified) (1 diff)
-
src/examples/prolog.c (modified) (2 diffs)
-
src/examples/quad.c (modified) (1 diff)
-
src/examples/simplePoly.c (modified) (1 diff)
-
src/examples/simpler.c (modified) (1 diff)
-
src/examples/specialize.c (modified) (2 diffs)
-
src/examples/square.c (modified) (1 diff)
-
src/examples/sum.c (modified) (2 diffs)
-
src/examples/twice.c (modified) (2 diffs)
-
src/libcfa/Makefile.am (modified) (2 diffs)
-
src/libcfa/Makefile.in (modified) (1 diff)
-
src/libcfa/bfd.h (added)
-
src/libcfa/bfdlink.h (added)
-
src/libcfa/demangle.h (added)
-
src/libcfa/dialog.h (added)
-
src/libcfa/evdns.h (added)
-
src/libcfa/evhttp.h (added)
-
src/libcfa/evrpc.h (added)
-
src/libcfa/fcntl.h (added)
-
src/libcfa/form.h (added)
-
src/libcfa/gcrypt.h (added)
-
src/libcfa/iostream.c (modified) (2 diffs)
-
src/libcfa/math.h (added)
Legend:
- Unmodified
- Added
- Removed
-
doc/refrat/refrat.tex
rae357ec rbed4c63e 62 62 \renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}{-2.0ex \@plus -1ex \@minus -.2ex}{-1em}{\normalfont\normalsize\bfseries}} 63 63 64 % index macros65 64 \newcommand{\italic}[1]{\emph{\hyperpage{#1}}} 66 65 \newcommand{\definition}[1]{\textbf{\hyperpage{#1}}} … … 134 133 % adjust listings macros 135 134 \lstdefinelanguage{CFA}[ANSI]{C}% 136 {morekeywords={asm,_Alignas,_Alignof,_At,_Atomic,_Bool,catch,catchResume,choose,_Complex, trait,disable,dtype,enable,137 fallthru,finally,forall,ftype,_Generic,_Imaginary,inline,lvalue,_Noreturn, otype,restrict,_Static_assert,138 _Thread_local,throw,throwResume,try, },135 {morekeywords={asm,_Alignas,_Alignof,_At,_Atomic,_Bool,catch,catchResume,choose,_Complex,context,disable,dtype,enable, 136 fallthru,finally,forall,ftype,_Generic,_Imaginary,inline,lvalue,_Noreturn,restrict,_Static_assert, 137 _Thread_local,throw,throwResume,try,type,}, 139 138 }% 140 139 … … 281 280 An instantiation of the generic type is written by specifying the type parameters in parentheses after the name of the generic type generator: 282 281 \begin{lstlisting} 283 forall( otype T | sumable( T ) ) struct pair {282 forall( type T | sumable( T ) ) struct pair { 284 283 T x; 285 284 T y; … … 293 292 Polymorphic functions may have generic types as parameters, and those generic types may use type parameters of the polymorphic function as type parameters of the generic type: 294 293 \begin{lstlisting} 295 forall( otype T ) void swap( pair(T) *p ) {294 forall( type T ) void swap( pair(T) *p ) { 296 295 T z = p->x; 297 296 p->x = p->y; … … 303 302 \subsubsection{Constraints} 304 303 305 To avoid unduly constraining implementors, the generic type generator definition must be visible at any point where it is instantiated. 306 Forward declarations of generic type generators are not forbidden, but the definition must be visible to instantiate the generic type. Equivalently, instantiations of generic types are not allowed to be incomplete types. 304 To avoid unduly constraining implementors, the generic type generator definition must be visible at any point where it is instantiated. Forward declarations of generic type generators are not forbidden, but the definition must be visible to instantiate the generic type. Equivalently, instantiations of generic types are not allowed to be incomplete types. 307 305 308 306 \examples 309 307 \begin{lstlisting} 310 forall( otype T ) struct A;311 312 forall( otype T ) struct B {308 forall( type T ) struct A; 309 310 forall( type T ) struct B { 313 311 A(T) *a; // legal, but cannot instantiate B(T) 314 312 }; … … 316 314 B(T) x; // illegal, *x.a is of an incomplete generic type 317 315 318 forall( otype T ) struct A {316 forall( type T ) struct A { 319 317 B( T ) *b; 320 318 }; … … 323 321 324 322 // box.h: 325 forall( otype T ) struct box;326 forall( otype T ) box( T ) *make_box( T );327 forall( otype T ) void use_box( box( T ) *b );323 forall( type T ) struct box; 324 forall( type T ) box( T ) *make_box( T ); 325 forall( type T ) void use_box( box( T ) *b ); 328 326 329 327 // main.c: … … 412 410 413 411 \subsubsection{Specialization} 414 A function or value whose type is polymorphic may be implicitly converted to one whose type is \Index{less polymorphic} by binding values to one or more of its \Index{inferred parameter}. 412 A function or value whose type is polymorphic may be implicitly converted to one whose type is 413 \Index{less polymorphic} by binding values to one or more of its \Index{inferred parameter}. 415 414 Any value that is legal for the inferred parameter may be used, including other inferred parameters. 416 415 417 If, after the inferred parameter binding, an \Index{assertion parameter} has no inferred parameters in its type, then an object or function must be visible at the point of the specialization that has the same identifier as the assertion parameter and has a type that is compatible\index{compatible type} with or can be specialized to the type of the assertion parameter.418 The assertion parameter is bound to that object or function.416 If, after the inferred parameter binding, an \Index{assertion parameter} has no inferred parameters in its type, then an object or function must be visible at the point of the specialization that has the same identifier as the assertion parameter and has a type that is compatible\index{compatible 417 type} with or can be specialized to the type of the assertion parameter. The assertion parameter is bound to that object or function. 419 418 420 419 The type of the specialization is the type of the original with the bound inferred parameters and the bound assertion parameters replaced by their bound values. … … 423 422 The type 424 423 \begin{lstlisting} 425 forall( otype T, otype U ) void (*)( T, U );424 forall( type T, type U ) void (*)( T, U ); 426 425 \end{lstlisting} 427 426 can be specialized to (among other things) 428 427 \begin{lstlisting} 429 forall( otype T ) void (*)( T, T ); // U bound to T430 forall( otype T ) void (*)( T, real ); // U bound to real431 forall( otype U ) void (*)( real, U ); // T bound to real428 forall( type T ) void (*)( T, T ); // U bound to T 429 forall( type T ) void (*)( T, real ); // U bound to real 430 forall( type U ) void (*)( real, U ); // T bound to real 432 431 void f( real, real ); // both bound to real 433 432 \end{lstlisting} … … 435 434 The type 436 435 \begin{lstlisting} 437 forall( otype T | T ?+?( T, T ) ) T (*)( T );436 forall( type T | T ?+?( T, T ) ) T (*)( T ); 438 437 \end{lstlisting} 439 438 can be specialized to (among other things) … … 495 494 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: 496 495 \lstinline$unsigned short$ to \lstinline$int$ to \lstinline$unsigned$. 497 Otherwise, \lstinline$unsigned short$ is converted directly to \lstinline$unsigned$, and the cost is 1. 496 Otherwise, 497 \lstinline$unsigned short$ is converted directly to \lstinline$unsigned$, and the cost is 1. 498 498 499 499 \item … … 508 508 \rhs \lstinline$forall$ 509 509 \rhs \lstinline$lvalue$ 510 \rhs \lstinline$ trait$510 \rhs \lstinline$context$ 511 511 \rhs \lstinline$dtype$ 512 512 \rhs \lstinline$ftype$ … … 539 539 A \nonterm{constant-expression} that evaluates to 0 is effectively compatible with every pointer type. 540 540 541 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. 541 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 542 0 as a special case. 542 543 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. 543 544 Defining special constants for a user-defined type is more efficient than defining a conversion to the type from \lstinline$_Bool$. … … 835 836 \predefined 836 837 \begin{lstlisting} 837 forall( otype T ) lvalue T ?[?]( T *, ptrdiff_t );@\use{ptrdiff_t}@838 forall( otype T ) lvalue _Atomic T ?[?]( _Atomic T *, ptrdiff_t );839 forall( otype T ) lvalue const T ?[?]( const T *, ptrdiff_t );840 forall( otype T ) lvalue restrict T ?[?]( restrict T *, ptrdiff_t );841 forall( otype T ) lvalue volatile T ?[?]( volatile T *, ptrdiff_t );842 forall( otype T ) lvalue _Atomic const T ?[?]( _Atomic const T *, ptrdiff_t );843 forall( otype T ) lvalue _Atomic restrict T ?[?]( _Atomic restrict T *, ptrdiff_t );844 forall( otype T ) lvalue _Atomic volatile T ?[?]( _Atomic volatile T *, ptrdiff_t );845 forall( otype T ) lvalue const restrict T ?[?]( const restrict T *, ptrdiff_t );846 forall( otype T ) lvalue const volatile T ?[?]( const volatile T *, ptrdiff_t );847 forall( otype T ) lvalue restrict volatile T ?[?]( restrict volatile T *, ptrdiff_t );848 forall( otype T ) lvalue _Atomic const restrict T ?[?]( _Atomic const restrict T *, ptrdiff_t );849 forall( otype T ) lvalue _Atomic const volatile T ?[?]( _Atomic const volatile T *, ptrdiff_t );850 forall( otype T ) lvalue _Atomic restrict volatile T ?[?]( _Atomic restrict volatile T *, ptrdiff_t );851 forall( otype T ) lvalue const restrict volatile T ?[?]( const restrict volatile T *, ptrdiff_t );852 forall( otype T ) lvalue _Atomic const restrict volatile T ?[?]( _Atomic const restrict volatile T *, ptrdiff_t );838 forall( type T ) lvalue T ?[?]( T *, ptrdiff_t );@\use{ptrdiff_t}@ 839 forall( type T ) lvalue _Atomic T ?[?]( _Atomic T *, ptrdiff_t ); 840 forall( type T ) lvalue const T ?[?]( const T *, ptrdiff_t ); 841 forall( type T ) lvalue restrict T ?[?]( restrict T *, ptrdiff_t ); 842 forall( type T ) lvalue volatile T ?[?]( volatile T *, ptrdiff_t ); 843 forall( type T ) lvalue _Atomic const T ?[?]( _Atomic const T *, ptrdiff_t ); 844 forall( type T ) lvalue _Atomic restrict T ?[?]( _Atomic restrict T *, ptrdiff_t ); 845 forall( type T ) lvalue _Atomic volatile T ?[?]( _Atomic volatile T *, ptrdiff_t ); 846 forall( type T ) lvalue const restrict T ?[?]( const restrict T *, ptrdiff_t ); 847 forall( type T ) lvalue const volatile T ?[?]( const volatile T *, ptrdiff_t ); 848 forall( type T ) lvalue restrict volatile T ?[?]( restrict volatile T *, ptrdiff_t ); 849 forall( type T ) lvalue _Atomic const restrict T ?[?]( _Atomic const restrict T *, ptrdiff_t ); 850 forall( type T ) lvalue _Atomic const volatile T ?[?]( _Atomic const volatile T *, ptrdiff_t ); 851 forall( type T ) lvalue _Atomic restrict volatile T ?[?]( _Atomic restrict volatile T *, ptrdiff_t ); 852 forall( type T ) lvalue const restrict volatile T ?[?]( const restrict volatile T *, ptrdiff_t ); 853 forall( type T ) lvalue _Atomic const restrict volatile T ?[?]( _Atomic const restrict volatile T *, ptrdiff_t ); 853 854 \end{lstlisting} 854 855 \semantics … … 913 914 \begin{rationale} 914 915 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}. 915 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$.916 For instance, it should be possible to replace a function ``\lstinline$int f( int );$'' with ``\lstinline$forall( type T ) T f( T );$'' without affecting any calls of \lstinline$f$. 916 917 917 918 \CFA\index{deficiencies!generalizability} does not fully possess this property, because … … 927 928 f = g( d, f ); // (3) (unsafe conversion to float) 928 929 \end{lstlisting} 929 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 to930 If \lstinline$g$ was replaced by ``\lstinline$forall( type T ) T g( T, T );$'', the first and second calls would be unaffected, but the third would change: \lstinline$f$ would be converted to 930 931 \lstinline$double$, and the result would be a \lstinline$double$. 931 932 932 933 Another example is the function ``\lstinline$void h( int *);$''. 933 934 This function can be passed a 934 \lstinline$void *$ argument, but the generalization ``\lstinline$forall( otype T ) void h( T *);$'' can not.935 \lstinline$void *$ argument, but the generalization ``\lstinline$forall( type T ) void h( T *);$'' can not. 935 936 In this case, \lstinline$void$ is not a valid value for \lstinline$T$ because it is not an object type. 936 937 If unsafe conversions were allowed, \lstinline$T$ could be inferred to be \emph{any} object type, which is undesirable. … … 940 941 A function called ``\lstinline$?()$'' might be part of a numerical differentiation package. 941 942 \begin{lstlisting} 942 extern otype Derivative;943 extern type Derivative; 943 944 extern double ?()( Derivative, double ); 944 945 extern Derivative derivative_of( double (*f)( double ) ); … … 961 962 962 963 \begin{lstlisting} 963 forall( otype T ) T h( T );964 forall( type T ) T h( T ); 964 965 double d = h( 1.5 ); 965 966 \end{lstlisting} … … 968 969 969 970 \begin{lstlisting} 970 forall( otype T, otype U ) void g( T, U ); // (4)971 forall( otype T ) void g( T, T ); // (5)972 forall( otype T ) void g( T, long ); // (6)971 forall( type T, type U ) void g( T, U ); // (4) 972 forall( type T ) void g( T, T ); // (5) 973 forall( type T ) void g( T, long ); // (6) 973 974 void g( long, long ); // (7) 974 975 double d; … … 990 991 The fourth call has no interpretation for (5), because its arguments must have compatible type. (4) is chosen because it does not involve unsafe conversions. 991 992 \begin{lstlisting} 992 forall( otype T ) T min( T, T );993 forall( type T ) T min( T, T ); 993 994 double max( double, double ); 994 trait min_max( T ) {@\impl{min_max}@995 context min_max( T ) {@\impl{min_max}@ 995 996 T min( T, T ); 996 997 T max( T, T ); 997 998 } 998 forall( otype U | min_max( U ) ) void shuffle( U, U );999 forall( type U | min_max( U ) ) void shuffle( U, U ); 999 1000 shuffle( 9, 10 ); 1000 1001 \end{lstlisting} … … 1046 1047 long double ?++( volatile long double * ), ?++( _Atomic volatile long double * ); 1047 1048 1048 forall( otype T ) T * ?++( T * restrict volatile * ), * ?++( T * _Atomic restrict volatile * );1049 forall( otype T ) _Atomic T * ?++( _Atomic T * restrict volatile * ), * ?++( _Atomic T * _Atomic restrict volatile * );1050 forall( otype T ) const T * ?++( const T * restrict volatile * ), * ?++( const T * _Atomic restrict volatile * );1051 forall( otype T ) volatile T * ?++( volatile T * restrict volatile * ), * ?++( volatile T * _Atomic restrict volatile * );1052 forall( otype T ) restrict T * ?++( restrict T * restrict volatile * ), * ?++( restrict T * _Atomic restrict volatile * );1053 forall( otype T ) _Atomic const T * ?++( _Atomic const T * restrict volatile * ),1049 forall( type T ) T * ?++( T * restrict volatile * ), * ?++( T * _Atomic restrict volatile * ); 1050 forall( type T ) _Atomic T * ?++( _Atomic T * restrict volatile * ), * ?++( _Atomic T * _Atomic restrict volatile * ); 1051 forall( type T ) const T * ?++( const T * restrict volatile * ), * ?++( const T * _Atomic restrict volatile * ); 1052 forall( type T ) volatile T * ?++( volatile T * restrict volatile * ), * ?++( volatile T * _Atomic restrict volatile * ); 1053 forall( type T ) restrict T * ?++( restrict T * restrict volatile * ), * ?++( restrict T * _Atomic restrict volatile * ); 1054 forall( type T ) _Atomic const T * ?++( _Atomic const T * restrict volatile * ), 1054 1055 * ?++( _Atomic const T * _Atomic restrict volatile * ); 1055 forall( otype T ) _Atomic restrict T * ?++( _Atomic restrict T * restrict volatile * ),1056 forall( type T ) _Atomic restrict T * ?++( _Atomic restrict T * restrict volatile * ), 1056 1057 * ?++( _Atomic restrict T * _Atomic restrict volatile * ); 1057 forall( otype T ) _Atomic volatile T * ?++( _Atomic volatile T * restrict volatile * ),1058 forall( type T ) _Atomic volatile T * ?++( _Atomic volatile T * restrict volatile * ), 1058 1059 * ?++( _Atomic volatile T * _Atomic restrict volatile * ); 1059 forall( otype T ) const restrict T * ?++( const restrict T * restrict volatile * ),1060 forall( type T ) const restrict T * ?++( const restrict T * restrict volatile * ), 1060 1061 * ?++( const restrict T * _Atomic restrict volatile * ); 1061 forall( otype T ) const volatile T * ?++( const volatile T * restrict volatile * ),1062 forall( type T ) const volatile T * ?++( const volatile T * restrict volatile * ), 1062 1063 * ?++( const volatile T * _Atomic restrict volatile * ); 1063 forall( otype T ) restrict volatile T * ?++( restrict volatile T * restrict volatile * ),1064 forall( type T ) restrict volatile T * ?++( restrict volatile T * restrict volatile * ), 1064 1065 * ?++( restrict volatile T * _Atomic restrict volatile * ); 1065 forall( otype T ) _Atomic const restrict T * ?++( _Atomic const restrict T * restrict volatile * ),1066 forall( type T ) _Atomic const restrict T * ?++( _Atomic const restrict T * restrict volatile * ), 1066 1067 * ?++( _Atomic const restrict T * _Atomic restrict volatile * ); 1067 forall( otype T ) _Atomic const volatile T * ?++( _Atomic const volatile T * restrict volatile * ),1068 forall( type T ) _Atomic const volatile T * ?++( _Atomic const volatile T * restrict volatile * ), 1068 1069 * ?++( _Atomic const volatile T * _Atomic restrict volatile * ); 1069 forall( otype T ) _Atomic restrict volatile T * ?++( _Atomic restrict volatile T * restrict volatile * ),1070 forall( type T ) _Atomic restrict volatile T * ?++( _Atomic restrict volatile T * restrict volatile * ), 1070 1071 * ?++( _Atomic restrict volatile T * _Atomic restrict volatile * ); 1071 forall( otype T ) const restrict volatile T * ?++( const restrict volatile T * restrict volatile * ),1072 forall( type T ) const restrict volatile T * ?++( const restrict volatile T * restrict volatile * ), 1072 1073 * ?++( const restrict volatile T * _Atomic restrict volatile * ); 1073 forall( otype T ) _Atomic const restrict volatile T * ?++( _Atomic const restrict volatile T * restrict volatile * ),1074 forall( type T ) _Atomic const restrict volatile T * ?++( _Atomic const restrict volatile T * restrict volatile * ), 1074 1075 * ?++( _Atomic const restrict volatile T * _Atomic restrict volatile * ); 1075 1076 … … 1090 1091 long double ?--( volatile long double * ), ?--( _Atomic volatile long double * ); 1091 1092 1092 forall( otype T ) T * ?--( T * restrict volatile * ), * ?--( T * _Atomic restrict volatile * );1093 forall( otype T ) _Atomic T * ?--( _Atomic T * restrict volatile * ), * ?--( _Atomic T * _Atomic restrict volatile * );1094 forall( otype T ) const T * ?--( const T * restrict volatile * ), * ?--( const T * _Atomic restrict volatile * );1095 forall( otype T ) volatile T * ?--( volatile T * restrict volatile * ), * ?--( volatile T * _Atomic restrict volatile * );1096 forall( otype T ) restrict T * ?--( restrict T * restrict volatile * ), * ?--( restrict T * _Atomic restrict volatile * );1097 forall( otype T ) _Atomic const T * ?--( _Atomic const T * restrict volatile * ),1093 forall( type T ) T * ?--( T * restrict volatile * ), * ?--( T * _Atomic restrict volatile * ); 1094 forall( type T ) _Atomic T * ?--( _Atomic T * restrict volatile * ), * ?--( _Atomic T * _Atomic restrict volatile * ); 1095 forall( type T ) const T * ?--( const T * restrict volatile * ), * ?--( const T * _Atomic restrict volatile * ); 1096 forall( type T ) volatile T * ?--( volatile T * restrict volatile * ), * ?--( volatile T * _Atomic restrict volatile * ); 1097 forall( type T ) restrict T * ?--( restrict T * restrict volatile * ), * ?--( restrict T * _Atomic restrict volatile * ); 1098 forall( type T ) _Atomic const T * ?--( _Atomic const T * restrict volatile * ), 1098 1099 * ?--( _Atomic const T * _Atomic restrict volatile * ); 1099 forall( otype T ) _Atomic restrict T * ?--( _Atomic restrict T * restrict volatile * ),1100 forall( type T ) _Atomic restrict T * ?--( _Atomic restrict T * restrict volatile * ), 1100 1101 * ?--( _Atomic restrict T * _Atomic restrict volatile * ); 1101 forall( otype T ) _Atomic volatile T * ?--( _Atomic volatile T * restrict volatile * ),1102 forall( type T ) _Atomic volatile T * ?--( _Atomic volatile T * restrict volatile * ), 1102 1103 * ?--( _Atomic volatile T * _Atomic restrict volatile * ); 1103 forall( otype T ) const restrict T * ?--( const restrict T * restrict volatile * ),1104 forall( type T ) const restrict T * ?--( const restrict T * restrict volatile * ), 1104 1105 * ?--( const restrict T * _Atomic restrict volatile * ); 1105 forall( otype T ) const volatile T * ?--( const volatile T * restrict volatile * ),1106 forall( type T ) const volatile T * ?--( const volatile T * restrict volatile * ), 1106 1107 * ?--( const volatile T * _Atomic restrict volatile * ); 1107 forall( otype T ) restrict volatile T * ?--( restrict volatile T * restrict volatile * ),1108 forall( type T ) restrict volatile T * ?--( restrict volatile T * restrict volatile * ), 1108 1109 * ?--( restrict volatile T * _Atomic restrict volatile * ); 1109 forall( otype T ) _Atomic const restrict T * ?--( _Atomic const restrict T * restrict volatile * ),1110 forall( type T ) _Atomic const restrict T * ?--( _Atomic const restrict T * restrict volatile * ), 1110 1111 * ?--( _Atomic const restrict T * _Atomic restrict volatile * ); 1111 forall( otype T ) _Atomic const volatile T * ?--( _Atomic const volatile T * restrict volatile * ),1112 forall( type T ) _Atomic const volatile T * ?--( _Atomic const volatile T * restrict volatile * ), 1112 1113 * ?--( _Atomic const volatile T * _Atomic restrict volatile * ); 1113 forall( otype T ) _Atomic restrict volatile T * ?--( _Atomic restrict volatile T * restrict volatile * ),1114 forall( type T ) _Atomic restrict volatile T * ?--( _Atomic restrict volatile T * restrict volatile * ), 1114 1115 * ?--( _Atomic restrict volatile T * _Atomic restrict volatile * ); 1115 forall( otype T ) const restrict volatile T * ?--( const restrict volatile T * restrict volatile * ),1116 forall( type T ) const restrict volatile T * ?--( const restrict volatile T * restrict volatile * ), 1116 1117 * ?--( const restrict volatile T * _Atomic restrict volatile * ); 1117 forall( otype T ) _Atomic const restrict volatile T * ?--( _Atomic const restrict volatile T * restrict volatile * ),1118 forall( type T ) _Atomic const restrict volatile T * ?--( _Atomic const restrict volatile T * restrict volatile * ), 1118 1119 * ?--( _Atomic const restrict volatile T * _Atomic restrict volatile * ); 1119 1120 \end{lstlisting} … … 1194 1195 The expression would be valid if \lstinline$?++$ were declared by 1195 1196 \begin{lstlisting} 1196 forall( otype T ) T * ?++( T * * );1197 forall( type T ) T * ?++( T * * ); 1197 1198 \end{lstlisting} with \lstinline$T$ inferred to be \lstinline$char$. 1198 1199 … … 1202 1203 Hence the actual predefined function is 1203 1204 \begin{lstlisting} 1204 forall( otype T ) T * ?++( T * restrict volatile * );1205 forall( type T ) T * ?++( T * restrict volatile * ); 1205 1206 \end{lstlisting} which also accepts a \lstinline$char * *$ argument, because of the safe conversions that add 1206 1207 \lstinline$volatile$ and \lstinline$restrict$ qualifiers. (The parameter is not const-qualified, so constant pointers cannot be incremented.) … … 1216 1217 \lstinline$char const volatile *$, so a new overloading is needed: 1217 1218 \begin{lstlisting} 1218 forall( otype T ) T const volatile * ?++( T const volatile *restrict volatile * );1219 forall( type T ) T const volatile * ?++( T const volatile *restrict volatile * ); 1219 1220 \end{lstlisting} 1220 1221 One overloading is needed for each combination of qualifiers in the pointed-at type\index{deficiencies!pointers to qualified types}. … … 1224 1225 The \lstinline$restrict$ qualifier is handled just like \lstinline$const$ and \lstinline$volatile$ in the previous case: 1225 1226 \begin{lstlisting} 1226 forall( otype T ) T restrict * ?++( T restrict *restrict volatile * );1227 forall( type T ) T restrict * ?++( T restrict *restrict volatile * ); 1227 1228 \end{lstlisting} with \lstinline$T$ inferred to be \lstinline$float *$. 1228 1229 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. … … 1282 1283 long double ++?( volatile long double * ), ++?( _Atomic volatile long double * ); 1283 1284 1284 forall( otype T ) T * ++?( T * restrict volatile * ), * ++?( T * _Atomic restrict volatile * );1285 forall( otype T ) _Atomic T * ++?( _Atomic T * restrict volatile * ), * ++?( _Atomic T * _Atomic restrict volatile * );1286 forall( otype T ) const T * ++?( const T * restrict volatile * ), * ++?( const T * _Atomic restrict volatile * );1287 forall( otype T ) volatile T * ++?( volatile T * restrict volatile * ), * ++?( volatile T * _Atomic restrict volatile * );1288 forall( otype T ) restrict T * ++?( restrict T * restrict volatile * ), * ++?( restrict T * _Atomic restrict volatile * );1289 forall( otype T ) _Atomic const T * ++?( _Atomic const T * restrict volatile * ),1285 forall( type T ) T * ++?( T * restrict volatile * ), * ++?( T * _Atomic restrict volatile * ); 1286 forall( type T ) _Atomic T * ++?( _Atomic T * restrict volatile * ), * ++?( _Atomic T * _Atomic restrict volatile * ); 1287 forall( type T ) const T * ++?( const T * restrict volatile * ), * ++?( const T * _Atomic restrict volatile * ); 1288 forall( type T ) volatile T * ++?( volatile T * restrict volatile * ), * ++?( volatile T * _Atomic restrict volatile * ); 1289 forall( type T ) restrict T * ++?( restrict T * restrict volatile * ), * ++?( restrict T * _Atomic restrict volatile * ); 1290 forall( type T ) _Atomic const T * ++?( _Atomic const T * restrict volatile * ), 1290 1291 * ++?( _Atomic const T * _Atomic restrict volatile * ); 1291 forall( otype T ) _Atomic volatile T * ++?( _Atomic volatile T * restrict volatile * ),1292 forall( type T ) _Atomic volatile T * ++?( _Atomic volatile T * restrict volatile * ), 1292 1293 * ++?( _Atomic volatile T * _Atomic restrict volatile * ); 1293 forall( otype T ) _Atomic restrict T * ++?( _Atomic restrict T * restrict volatile * ),1294 forall( type T ) _Atomic restrict T * ++?( _Atomic restrict T * restrict volatile * ), 1294 1295 * ++?( _Atomic restrict T * _Atomic restrict volatile * ); 1295 forall( otype T ) const volatile T * ++?( const volatile T * restrict volatile * ),1296 forall( type T ) const volatile T * ++?( const volatile T * restrict volatile * ), 1296 1297 * ++?( const volatile T * _Atomic restrict volatile * ); 1297 forall( otype T ) const restrict T * ++?( const restrict T * restrict volatile * ),1298 forall( type T ) const restrict T * ++?( const restrict T * restrict volatile * ), 1298 1299 * ++?( const restrict T * _Atomic restrict volatile * ); 1299 forall( otype T ) restrict volatile T * ++?( restrict volatile T * restrict volatile * ),1300 forall( type T ) restrict volatile T * ++?( restrict volatile T * restrict volatile * ), 1300 1301 * ++?( restrict volatile T * _Atomic restrict volatile * ); 1301 forall( otype T ) _Atomic const volatile T * ++?( _Atomic const volatile T * restrict volatile * ),1302 forall( type T ) _Atomic const volatile T * ++?( _Atomic const volatile T * restrict volatile * ), 1302 1303 * ++?( _Atomic const volatile T * _Atomic restrict volatile * ); 1303 forall( otype T ) _Atomic const restrict T * ++?( _Atomic const restrict T * restrict volatile * ),1304 forall( type T ) _Atomic const restrict T * ++?( _Atomic const restrict T * restrict volatile * ), 1304 1305 * ++?( _Atomic const restrict T * _Atomic restrict volatile * ); 1305 forall( otype T ) _Atomic restrict volatile T * ++?( _Atomic restrict volatile T * restrict volatile * ),1306 forall( type T ) _Atomic restrict volatile T * ++?( _Atomic restrict volatile T * restrict volatile * ), 1306 1307 * ++?( _Atomic restrict volatile T * _Atomic restrict volatile * ); 1307 forall( otype T ) const restrict volatile T * ++?( const restrict volatile T * restrict volatile * ),1308 forall( type T ) const restrict volatile T * ++?( const restrict volatile T * restrict volatile * ), 1308 1309 * ++?( const restrict volatile T * _Atomic restrict volatile * ); 1309 forall( otype T ) _Atomic const restrict volatile T * ++?( _Atomic const restrict volatile T * restrict volatile * ),1310 forall( type T ) _Atomic const restrict volatile T * ++?( _Atomic const restrict volatile T * restrict volatile * ), 1310 1311 * ++?( _Atomic const restrict volatile T * _Atomic restrict volatile * ); 1311 1312 … … 1326 1327 long double --?( volatile long double * ), --?( _Atomic volatile long double * ); 1327 1328 1328 forall( otype T ) T * --?( T * restrict volatile * ), * --?( T * _Atomic restrict volatile * );1329 forall( otype T ) _Atomic T * --?( _Atomic T * restrict volatile * ), * --?( _Atomic T * _Atomic restrict volatile * );1330 forall( otype T ) const T * --?( const T * restrict volatile * ), * --?( const T * _Atomic restrict volatile * );1331 forall( otype T ) volatile T * --?( volatile T * restrict volatile * ), * --?( volatile T * _Atomic restrict volatile * );1332 forall( otype T ) restrict T * --?( restrict T * restrict volatile * ), * --?( restrict T * _Atomic restrict volatile * );1333 forall( otype T ) _Atomic const T * --?( _Atomic const T * restrict volatile * ),1329 forall( type T ) T * --?( T * restrict volatile * ), * --?( T * _Atomic restrict volatile * ); 1330 forall( type T ) _Atomic T * --?( _Atomic T * restrict volatile * ), * --?( _Atomic T * _Atomic restrict volatile * ); 1331 forall( type T ) const T * --?( const T * restrict volatile * ), * --?( const T * _Atomic restrict volatile * ); 1332 forall( type T ) volatile T * --?( volatile T * restrict volatile * ), * --?( volatile T * _Atomic restrict volatile * ); 1333 forall( type T ) restrict T * --?( restrict T * restrict volatile * ), * --?( restrict T * _Atomic restrict volatile * ); 1334 forall( type T ) _Atomic const T * --?( _Atomic const T * restrict volatile * ), 1334 1335 * --?( _Atomic const T * _Atomic restrict volatile * ); 1335 forall( otype T ) _Atomic volatile T * --?( _Atomic volatile T * restrict volatile * ),1336 forall( type T ) _Atomic volatile T * --?( _Atomic volatile T * restrict volatile * ), 1336 1337 * --?( _Atomic volatile T * _Atomic restrict volatile * ); 1337 forall( otype T ) _Atomic restrict T * --?( _Atomic restrict T * restrict volatile * ),1338 forall( type T ) _Atomic restrict T * --?( _Atomic restrict T * restrict volatile * ), 1338 1339 * --?( _Atomic restrict T * _Atomic restrict volatile * ); 1339 forall( otype T ) const volatile T * --?( const volatile T * restrict volatile * ),1340 forall( type T ) const volatile T * --?( const volatile T * restrict volatile * ), 1340 1341 * --?( const volatile T * _Atomic restrict volatile * ); 1341 forall( otype T ) const restrict T * --?( const restrict T * restrict volatile * ),1342 forall( type T ) const restrict T * --?( const restrict T * restrict volatile * ), 1342 1343 * --?( const restrict T * _Atomic restrict volatile * ); 1343 forall( otype T ) restrict volatile T * --?( restrict volatile T * restrict volatile * ),1344 forall( type T ) restrict volatile T * --?( restrict volatile T * restrict volatile * ), 1344 1345 * --?( restrict volatile T * _Atomic restrict volatile * ); 1345 forall( otype T ) _Atomic const volatile T * --?( _Atomic const volatile T * restrict volatile * ),1346 forall( type T ) _Atomic const volatile T * --?( _Atomic const volatile T * restrict volatile * ), 1346 1347 * --?( _Atomic const volatile T * _Atomic restrict volatile * ); 1347 forall( otype T ) _Atomic const restrict T * --?( _Atomic const restrict T * restrict volatile * ),1348 forall( type T ) _Atomic const restrict T * --?( _Atomic const restrict T * restrict volatile * ), 1348 1349 * --?( _Atomic const restrict T * _Atomic restrict volatile * ); 1349 forall( otype T ) _Atomic restrict volatile T * --?( _Atomic restrict volatile T * restrict volatile * ),1350 forall( type T ) _Atomic restrict volatile T * --?( _Atomic restrict volatile T * restrict volatile * ), 1350 1351 * --?( _Atomic restrict volatile T * _Atomic restrict volatile * ); 1351 forall( otype T ) const restrict volatile T * --?( const restrict volatile T * restrict volatile * ),1352 forall( type T ) const restrict volatile T * --?( const restrict volatile T * restrict volatile * ), 1352 1353 * --?( const restrict volatile T * _Atomic restrict volatile * ); 1353 forall( otype T ) _Atomic const restrict volatile T * --?( _Atomic const restrict volatile T * restrict volatile * ),1354 forall( type T ) _Atomic const restrict volatile T * --?( _Atomic const restrict volatile T * restrict volatile * ), 1354 1355 * --?( _Atomic const restrict volatile T * _Atomic restrict volatile * ); 1355 1356 \end{lstlisting} … … 1379 1380 \predefined 1380 1381 \begin{lstlisting} 1381 forall( otype T ) lvalue T *?( T * );1382 forall( otype T ) _Atomic lvalue T *?( _Atomic T * );1383 forall( otype T ) const lvalue T *?( const T * );1384 forall( otype T ) volatile lvalue T *?( volatile T * );1385 forall( otype T ) restrict lvalue T *?( restrict T * );1386 forall( otype T ) _Atomic const lvalue T *?( _Atomic const T * );1387 forall( otype T ) _Atomic volatile lvalue T *?( _Atomic volatile T * );1388 forall( otype T ) _Atomic restrict lvalue T *?( _Atomic restrict T * );1389 forall( otype T ) const volatile lvalue T *?( const volatile T * );1390 forall( otype T ) const restrict lvalue T *?( const restrict T * );1391 forall( otype T ) restrict volatile lvalue T *?( restrict volatile T * );1392 forall( otype T ) _Atomic const volatile lvalue T *?( _Atomic const volatile T * );1393 forall( otype T ) _Atomic const restrict lvalue T *?( _Atomic const restrict T * );1394 forall( otype T ) _Atomic restrict volatile lvalue T *?( _Atomic restrict volatile T * );1395 forall( otype T ) const restrict volatile lvalue T *?( const restrict volatile T * );1396 forall( otype T ) _Atomic const restrict volatile lvalue T *?( _Atomic const restrict volatile T * );1382 forall( type T ) lvalue T *?( T * ); 1383 forall( type T ) _Atomic lvalue T *?( _Atomic T * ); 1384 forall( type T ) const lvalue T *?( const T * ); 1385 forall( type T ) volatile lvalue T *?( volatile T * ); 1386 forall( type T ) restrict lvalue T *?( restrict T * ); 1387 forall( type T ) _Atomic const lvalue T *?( _Atomic const T * ); 1388 forall( type T ) _Atomic volatile lvalue T *?( _Atomic volatile T * ); 1389 forall( type T ) _Atomic restrict lvalue T *?( _Atomic restrict T * ); 1390 forall( type T ) const volatile lvalue T *?( const volatile T * ); 1391 forall( type T ) const restrict lvalue T *?( const restrict T * ); 1392 forall( type T ) restrict volatile lvalue T *?( restrict volatile T * ); 1393 forall( type T ) _Atomic const volatile lvalue T *?( _Atomic const volatile T * ); 1394 forall( type T ) _Atomic const restrict lvalue T *?( _Atomic const restrict T * ); 1395 forall( type T ) _Atomic restrict volatile lvalue T *?( _Atomic restrict volatile T * ); 1396 forall( type T ) const restrict volatile lvalue T *?( const restrict volatile T * ); 1397 forall( type T ) _Atomic const restrict volatile lvalue T *?( _Atomic const restrict volatile T * ); 1397 1398 forall( ftype FT ) FT *?( FT * ); 1398 1399 \end{lstlisting} … … 1509 1510 \begin{rationale} 1510 1511 \begin{lstlisting} 1511 otype Pair = struct { int first, second; };1512 type Pair = struct { int first, second; }; 1512 1513 size_t p_size = sizeof(Pair); // constant expression 1513 extern otype Rational;@\use{Rational}@1514 extern type Rational;@\use{Rational}@ 1514 1515 size_t c_size = sizeof(Rational); // non-constant expression 1515 1516 forall(type T) T f(T p1, T p2) { … … 1635 1636 Consider 1636 1637 \begin{lstlisting} 1637 forall( otype T | T ?*?( T, T ) ) T square( T );1638 forall( type T | T ?*?( T, T ) ) T square( T ); 1638 1639 short s; 1639 1640 square( s ); … … 1646 1647 A more troubling example is 1647 1648 \begin{lstlisting} 1648 forall( otype T | ?*?( T, T ) ) T product( T[], int n );1649 forall( type T | ?*?( T, T ) ) T product( T[], int n ); 1649 1650 short sa[5]; 1650 1651 product( sa, 5); … … 1703 1704 ?+?( _Complex long double, _Complex long double ), ?-?( _Complex long double, _Complex long double ); 1704 1705 1705 forall( otype T ) T * ?+?( T *, ptrdiff_t ), * ?+?( ptrdiff_t, T * ), * ?-?( T *, ptrdiff_t );1706 forall( otype T ) _Atomic T * ?+?( _Atomic T *, ptrdiff_t ), * ?+?( ptrdiff_t, _Atomic T * ),1706 forall( type T ) T * ?+?( T *, ptrdiff_t ), * ?+?( ptrdiff_t, T * ), * ?-?( T *, ptrdiff_t ); 1707 forall( type T ) _Atomic T * ?+?( _Atomic T *, ptrdiff_t ), * ?+?( ptrdiff_t, _Atomic T * ), 1707 1708 * ?-?( _Atomic T *, ptrdiff_t ); 1708 forall( otype T ) const T * ?+?( const T *, ptrdiff_t ), * ?+?( ptrdiff_t, const T * ),1709 forall( type T ) const T * ?+?( const T *, ptrdiff_t ), * ?+?( ptrdiff_t, const T * ), 1709 1710 * ?-?( const T *, ptrdiff_t ); 1710 forall( otype T ) restrict T * ?+?( restrict T *, ptrdiff_t ), * ?+?( ptrdiff_t, restrict T * ),1711 forall( type T ) restrict T * ?+?( restrict T *, ptrdiff_t ), * ?+?( ptrdiff_t, restrict T * ), 1711 1712 * ?-?( restrict T *, ptrdiff_t ); 1712 forall( otype T ) volatile T * ?+?( volatile T *, ptrdiff_t ), * ?+?( ptrdiff_t, volatile T * ),1713 forall( type T ) volatile T * ?+?( volatile T *, ptrdiff_t ), * ?+?( ptrdiff_t, volatile T * ), 1713 1714 * ?-?( volatile T *, ptrdiff_t ); 1714 forall( otype T ) _Atomic const T * ?+?( _Atomic const T *, ptrdiff_t ), * ?+?( ptrdiff_t, _Atomic const T * ),1715 forall( type T ) _Atomic const T * ?+?( _Atomic const T *, ptrdiff_t ), * ?+?( ptrdiff_t, _Atomic const T * ), 1715 1716 * ?-?( _Atomic const T *, ptrdiff_t ); 1716 forall( otype T ) _Atomic restrict T * ?+?( _Atomic restrict T *, ptrdiff_t ), * ?+?( ptrdiff_t, _Atomic restrict T * ),1717 forall( type T ) _Atomic restrict T * ?+?( _Atomic restrict T *, ptrdiff_t ), * ?+?( ptrdiff_t, _Atomic restrict T * ), 1717 1718 * ?-?( _Atomic restrict T *, ptrdiff_t ); 1718 forall( otype T ) _Atomic volatile T * ?+?( _Atomic volatile T *, ptrdiff_t ), * ?+?( ptrdiff_t, _Atomic volatile T * ),1719 forall( type T ) _Atomic volatile T * ?+?( _Atomic volatile T *, ptrdiff_t ), * ?+?( ptrdiff_t, _Atomic volatile T * ), 1719 1720 * ?-?( _Atomic volatile T *, ptrdiff_t ); 1720 forall( otype T ) const restrict T * ?+?( const restrict T *, ptrdiff_t ), * ?+?( ptrdiff_t, const restrict T * ),1721 forall( type T ) const restrict T * ?+?( const restrict T *, ptrdiff_t ), * ?+?( ptrdiff_t, const restrict T * ), 1721 1722 * ?-?( const restrict T *, ptrdiff_t ); 1722 forall( otype T ) const volatile T * ?+?( const volatile T *, ptrdiff_t ), * ?+?( ptrdiff_t, const volatile T * ),1723 forall( type T ) const volatile T * ?+?( const volatile T *, ptrdiff_t ), * ?+?( ptrdiff_t, const volatile T * ), 1723 1724 * ?-?( const volatile T *, ptrdiff_t ); 1724 forall( otype T ) restrict volatile T * ?+?( restrict volatile T *, ptrdiff_t ), * ?+?( ptrdiff_t, restrict volatile T * ),1725 forall( type T ) restrict volatile T * ?+?( restrict volatile T *, ptrdiff_t ), * ?+?( ptrdiff_t, restrict volatile T * ), 1725 1726 * ?-?( restrict volatile T *, ptrdiff_t ); 1726 forall( otype T ) _Atomic const restrict T * ?+?( _Atomic const restrict T *, ptrdiff_t ),1727 forall( type T ) _Atomic const restrict T * ?+?( _Atomic const restrict T *, ptrdiff_t ), 1727 1728 * ?+?( ptrdiff_t, _Atomic const restrict T * ), 1728 1729 * ?-?( _Atomic const restrict T *, ptrdiff_t ); 1729 forall( otype T ) ptrdiff_t1730 forall( type T ) ptrdiff_t 1730 1731 * ?-?( const restrict volatile T *, const restrict volatile T * ), 1731 1732 * ?-?( _Atomic const restrict volatile T *, _Atomic const restrict volatile T * ); … … 2051 2052 2052 2053 \begin{lstlisting} 2053 extern otype Rational;@\use{Rational}@2054 extern type Rational;@\use{Rational}@ 2054 2055 extern const Rational 0;@\use{0}@ 2055 2056 extern int ?!=?( Rational, Rational ); … … 2094 2095 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 2095 2096 \begin{lstlisting} 2096 forall( otype T ) T cond( int, T, T );2097 forall( type T ) T cond( int, T, T ); 2097 2098 forall( dtype D ) void * cond( int, D *, void * ), * cond( int, void *, D * ); 2098 2099 forall( dtype D ) _atomic void * cond( … … 2454 2455 \predefined 2455 2456 \begin{lstlisting} 2456 forall( otype T ) T2457 forall( type T ) T 2457 2458 * ?+=?( T * restrict volatile *, ptrdiff_t ), 2458 2459 * ?-=?( T * restrict volatile *, ptrdiff_t ), 2459 2460 * ?+=?( T * _Atomic restrict volatile *, ptrdiff_t ), 2460 2461 * ?-=?( T * _Atomic restrict volatile *, ptrdiff_t ); 2461 forall( otype T ) T _Atomic2462 forall( type T ) T _Atomic 2462 2463 * ?+=?( T _Atomic * restrict volatile *, ptrdiff_t ), 2463 2464 * ?-=?( T _Atomic * restrict volatile *, ptrdiff_t ), 2464 2465 * ?+=?( T _Atomic * _Atomic restrict volatile *, ptrdiff_t ), 2465 2466 * ?-=?( T _Atomic * _Atomic restrict volatile *, ptrdiff_t ); 2466 forall( otype T ) T const2467 forall( type T ) T const 2467 2468 * ?+=?( T const * restrict volatile *, ptrdiff_t ), 2468 2469 * ?-=?( T const * restrict volatile *, ptrdiff_t ), 2469 2470 * ?+=?( T const * _Atomic restrict volatile *, ptrdiff_t ), 2470 2471 * ?-=?( T const * _Atomic restrict volatile *, ptrdiff_t ); 2471 forall( otype T ) T restrict2472 forall( type T ) T restrict 2472 2473 * ?+=?( T restrict * restrict volatile *, ptrdiff_t ), 2473 2474 * ?-=?( T restrict * restrict volatile *, ptrdiff_t ), 2474 2475 * ?+=?( T restrict * _Atomic restrict volatile *, ptrdiff_t ), 2475 2476 * ?-=?( T restrict * _Atomic restrict volatile *, ptrdiff_t ); 2476 forall( otype T ) T volatile2477 forall( type T ) T volatile 2477 2478 * ?+=?( T volatile * restrict volatile *, ptrdiff_t ), 2478 2479 * ?-=?( T volatile * restrict volatile *, ptrdiff_t ), 2479 2480 * ?+=?( T volatile * _Atomic restrict volatile *, ptrdiff_t ), 2480 2481 * ?-=?( T volatile * _Atomic restrict volatile *, ptrdiff_t ); 2481 forall( otype T ) T _Atomic const2482 forall( type T ) T _Atomic const 2482 2483 * ?+=?( T _Atomic const restrict volatile *, ptrdiff_t ), 2483 2484 * ?-=?( T _Atomic const restrict volatile *, ptrdiff_t ), 2484 2485 * ?+=?( T _Atomic const _Atomic restrict volatile *, ptrdiff_t ), 2485 2486 * ?-=?( T _Atomic const _Atomic restrict volatile *, ptrdiff_t ); 2486 forall( otype T ) T _Atomic restrict2487 forall( type T ) T _Atomic restrict 2487 2488 * ?+=?( T _Atomic restrict * restrict volatile *, ptrdiff_t ), 2488 2489 * ?-=?( T _Atomic restrict * restrict volatile *, ptrdiff_t ), 2489 2490 * ?+=?( T _Atomic restrict * _Atomic restrict volatile *, ptrdiff_t ), 2490 2491 * ?-=?( T _Atomic restrict * _Atomic restrict volatile *, ptrdiff_t ); 2491 forall( otype T ) T _Atomic volatile2492 forall( type T ) T _Atomic volatile 2492 2493 * ?+=?( T _Atomic volatile * restrict volatile *, ptrdiff_t ), 2493 2494 * ?-=?( T _Atomic volatile * restrict volatile *, ptrdiff_t ), 2494 2495 * ?+=?( T _Atomic volatile * _Atomic restrict volatile *, ptrdiff_t ), 2495 2496 * ?-=?( T _Atomic volatile * _Atomic restrict volatile *, ptrdiff_t ); 2496 forall( otype T ) T const restrict2497 forall( type T ) T const restrict 2497 2498 * ?+=?( T const restrict * restrict volatile *, ptrdiff_t ), 2498 2499 * ?-=?( T const restrict * restrict volatile *, ptrdiff_t ), 2499 2500 * ?+=?( T const restrict * _Atomic restrict volatile *, ptrdiff_t ), 2500 2501 * ?-=?( T const restrict * _Atomic restrict volatile *, ptrdiff_t ); 2501 forall( otype T ) T const volatile2502 forall( type T ) T const volatile 2502 2503 * ?+=?( T const volatile * restrict volatile *, ptrdiff_t ), 2503 2504 * ?-=?( T const volatile * restrict volatile *, ptrdiff_t ), 2504 2505 * ?+=?( T const volatile * _Atomic restrict volatile *, ptrdiff_t ), 2505 2506 * ?-=?( T const volatile * _Atomic restrict volatile *, ptrdiff_t ); 2506 forall( otype T ) T restrict volatile2507 forall( type T ) T restrict volatile 2507 2508 * ?+=?( T restrict volatile * restrict volatile *, ptrdiff_t ), 2508 2509 * ?-=?( T restrict volatile * restrict volatile *, ptrdiff_t ), 2509 2510 * ?+=?( T restrict volatile * _Atomic restrict volatile *, ptrdiff_t ), 2510 2511 * ?-=?( T restrict volatile * _Atomic restrict volatile *, ptrdiff_t ); 2511 forall( otype T ) T _Atomic const restrict2512 forall( type T ) T _Atomic const restrict 2512 2513 * ?+=?( T _Atomic const restrict * restrict volatile *, ptrdiff_t ), 2513 2514 * ?-=?( T _Atomic const restrict * restrict volatile *, ptrdiff_t ), 2514 2515 * ?+=?( T _Atomic const restrict * _Atomic restrict volatile *, ptrdiff_t ), 2515 2516 * ?-=?( T _Atomic const restrict * _Atomic restrict volatile *, ptrdiff_t ); 2516 forall( otype T ) T _Atomic const volatile2517 forall( type T ) T _Atomic const volatile 2517 2518 * ?+=?( T _Atomic const volatile * restrict volatile *, ptrdiff_t ), 2518 2519 * ?-=?( T _Atomic const volatile * restrict volatile *, ptrdiff_t ), 2519 2520 * ?+=?( T _Atomic const volatile * _Atomic restrict volatile *, ptrdiff_t ), 2520 2521 * ?-=?( T _Atomic const volatile * _Atomic restrict volatile *, ptrdiff_t ); 2521 forall( otype T ) T _Atomic restrict volatile2522 forall( type T ) T _Atomic restrict volatile 2522 2523 * ?+=?( T _Atomic restrict volatile * restrict volatile *, ptrdiff_t ), 2523 2524 * ?-=?( T _Atomic restrict volatile * restrict volatile *, ptrdiff_t ), 2524 2525 * ?+=?( T _Atomic restrict volatile * _Atomic restrict volatile *, ptrdiff_t ), 2525 2526 * ?-=?( T _Atomic restrict volatile * _Atomic restrict volatile *, ptrdiff_t ); 2526 forall( otype T ) T const restrict volatile2527 forall( type T ) T const restrict volatile 2527 2528 * ?+=?( T const restrict volatile * restrict volatile *, ptrdiff_t ), 2528 2529 * ?-=?( T const restrict volatile * restrict volatile *, ptrdiff_t ), 2529 2530 * ?+=?( T const restrict volatile * _Atomic restrict volatile *, ptrdiff_t ), 2530 2531 * ?-=?( T const restrict volatile * _Atomic restrict volatile *, ptrdiff_t ); 2531 forall( otype T ) T _Atomic const restrict volatile2532 forall( type T ) T _Atomic const restrict volatile 2532 2533 * ?+=?( T _Atomic const restrict volatile * restrict volatile *, ptrdiff_t ), 2533 2534 * ?-=?( T _Atomic const restrict volatile * restrict volatile *, ptrdiff_t ), … … 2841 2842 This sort of declaration is illegal because the scope of the type identifiers ends at the end of the declaration, but the scope of the structure tag does not. 2842 2843 \begin{lstlisting} 2843 forall( otype T ) struct Pair { T a, b;2844 forall( type T ) struct Pair { T a, b; 2844 2845 } mkPair( T, T ); // illegal 2845 2846 \end{lstlisting} … … 2866 2867 If this restriction were lifted, it would be possible to write 2867 2868 \begin{lstlisting} 2868 forall( otype T ) T * alloc( void );@\use{alloc}@ int *p = alloc();2869 forall( type T ) T * alloc( void );@\use{alloc}@ int *p = alloc(); 2869 2870 \end{lstlisting} 2870 2871 Here \lstinline$alloc()$ would receive \lstinline$int$ as an inferred argument, and return an … … 2875 2876 \lstinline$T$: 2876 2877 \begin{lstlisting} 2877 forall( otype T ) T * alloc( T initial_value );@\use{alloc}@2878 forall( type T ) T * alloc( T initial_value );@\use{alloc}@ 2878 2879 \end{lstlisting} 2879 2880 \end{rationale} … … 2898 2899 \begin{lstlisting} 2899 2900 int fi( int ); 2900 forall( otype T ) T fT( T );2901 forall( type T ) T fT( T ); 2901 2902 \end{lstlisting} 2902 2903 \lstinline$fi()$ takes an \lstinline$int$ and returns an \lstinline$int$. \lstinline$fT()$ takes a … … 2904 2905 \begin{lstlisting} 2905 2906 int (*pfi )( int ) = fi; 2906 forall( otype T ) T (*pfT )( T ) = fT;2907 forall( type T ) T (*pfT )( T ) = fT; 2907 2908 \end{lstlisting} 2908 2909 \lstinline$pfi$ and \lstinline$pfT$ are pointers to functions. \lstinline$pfT$ is not polymorphic, but the function it points at is. … … 2911 2912 return pfi; 2912 2913 } 2913 forall( otype T ) T (*fvpfT( void ))( T ) {2914 forall( type T ) T (*fvpfT( void ))( T ) { 2914 2915 return pfT; 2915 2916 } … … 2917 2918 \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. 2918 2919 \begin{lstlisting} 2919 forall( otype T ) int ( *fTpfi( T ) )( int );2920 forall( otype T ) T ( *fTpfT( T ) )( T );2921 forall( otype T, otype U ) U ( *fTpfU( T ) )( U );2920 forall( type T ) int ( *fTpfi( T ) )( int ); 2921 forall( type T ) T ( *fTpfT( T ) )( T ); 2922 forall( type T, type U ) U ( *fTpfU( T ) )( U ); 2922 2923 \end{lstlisting} 2923 2924 \lstinline$fTpfi()$ is a polymorphic function that returns a pointer to a monomorphic function taking an integer and returning an integer. … … 2929 2930 \lstinline$char *$. 2930 2931 \begin{lstlisting} 2931 forall( otype T, otype U, otype V ) U * f( T *, U, V * const );2932 forall( otype U, otype V, otype W ) U * g( V *, U, W * const );2932 forall( type T, type U, type V ) U * f( T *, U, V * const ); 2933 forall( type U, type V, type W ) U * g( V *, U, W * const ); 2933 2934 \end{lstlisting} 2934 2935 The functions \lstinline$f()$ and \lstinline$g()$ have compatible types. … … 2938 2939 Replacing every \(f_i\) by \(g_i\) in \(f\) gives 2939 2940 \begin{lstlisting} 2940 forall( otype V, otype U, otype W ) U * f( V *, U, W * const );2941 forall( type V, type U, type W ) U * f( V *, U, W * const ); 2941 2942 \end{lstlisting} which has a return type and parameter list that is compatible with \(g\). 2942 2943 \begin{rationale} … … 3126 3127 \examples 3127 3128 \begin{lstlisting} 3128 forall( otype T | T ?*?( T, T ))@\use{?*?}@3129 forall( type T | T ?*?( T, T ))@\use{?*?}@ 3129 3130 T square( T val ) {@\impl{square}@ 3130 3131 return val + val; 3131 3132 } 3132 trait summable( otype T ) {@\impl{summable}@3133 context summable( type T ) {@\impl{summable}@ 3133 3134 T ?+=?( T *, T );@\use{?+=?}@ 3134 3135 const T 0;@\use{0}@ 3135 3136 }; 3136 trait list_of( otype List, otype Element ) {@\impl{list_of}@3137 context list_of( type List, type Element ) {@\impl{list_of}@ 3137 3138 Element car( List ); 3138 3139 List cdr( List ); … … 3141 3142 int is_nil( List ); 3142 3143 }; 3143 trait sum_list( otype List, otype Element | summable( Element ) | list_of( List, Element ) ) {};3144 context sum_list( type List, type Element | summable( Element ) | list_of( List, Element ) ) {}; 3144 3145 \end{lstlisting} 3145 3146 \lstinline$sum_list$ contains seven declarations, which describe a list whose elements can be added up. … … 3203 3204 Incomplete type declarations allow compact mutually-recursive types. 3204 3205 \begin{lstlisting} 3205 otype t1; // incomplete type declaration3206 otype t2 = struct { t1 * p; ... };3207 otype t1 = struct { t2 * p; ... };3206 type t1; // incomplete type declaration 3207 type t2 = struct { t1 * p; ... }; 3208 type t1 = struct { t2 * p; ... }; 3208 3209 \end{lstlisting} 3209 3210 Without them, mutual recursion could be handled by declaring mutually recursive structures, then initializing the types to those structures. 3210 3211 \begin{lstlisting} 3211 3212 struct s1; 3212 otype t2 = struct s2 { struct s1 * p; ... };3213 otype t1 = struct s1 { struct s2 * p; ... };3213 type t2 = struct s2 { struct s1 * p; ... }; 3214 type t1 = struct s1 { struct s2 * p; ... }; 3214 3215 \end{lstlisting} 3215 3216 This introduces extra names, and may force the programmer to cast between the types and their implementations. … … 3266 3267 This prevents the declaration of types that contain each other. 3267 3268 \begin{lstlisting} 3268 otype t1;3269 otype t2 = t1; // illegal: incomplete type t13270 otype t1 = t2;3269 type t1; 3270 type t2 = t1; // illegal: incomplete type t1 3271 type t1 = t2; 3271 3272 \end{lstlisting} 3272 3273 … … 3275 3276 types}. 3276 3277 \begin{lstlisting} 3277 extern otype Huge; // extended-precision integer type3278 otype Rational = struct {3278 extern type Huge; // extended-precision integer type 3279 type Rational = struct { 3279 3280 Huge numerator, denominator; // illegal 3280 3281 }; … … 3315 3316 \begin{lstlisting} 3316 3317 #include <stdlib.h> 3317 T * new( otype T ) { return ( T * )malloc( sizeof( T) ); };3318 T * new( type T ) { return ( T * )malloc( sizeof( T) ); }; 3318 3319 @\ldots@ int * ip = new( int ); 3319 3320 \end{lstlisting} … … 3326 3327 Since type declarations create new types, instances of types are always passed by value. 3327 3328 \begin{lstlisting} 3328 otype A1 = int[2];3329 type A1 = int[2]; 3329 3330 void f1( A1 a ) { a[0] = 0; }; 3330 otypedef int A2[2];3331 typedef int A2[2]; 3331 3332 void f2( A2 a ) { a[0] = 0; }; 3332 3333 A1 v1; … … 3345 3346 That unit might contain the declarations 3346 3347 \begin{lstlisting} 3347 otype Complex = struct { float re, im; };@\impl{Complex}@3348 type Complex = struct { float re, im; };@\impl{Complex}@ 3348 3349 Complex cplx_i = { 0.0, 1.0 };@\impl{cplx_i}@ 3349 3350 float abs( Complex c ) {@\impl{abs( Complex )}@ … … 3354 3355 3355 3356 \begin{lstlisting} 3356 otype Time_of_day = int;@\impl{Time_of_day}@ // seconds since midnight.3357 type Time_of_day = int;@\impl{Time_of_day}@ // seconds since midnight. 3357 3358 Time_of_day ?+?( Time_of_day t1, int seconds ) {@\impl{?+?}@ 3358 3359 return (( int)t1 + seconds ) % 86400; … … 3428 3429 \examples 3429 3430 \begin{lstlisting} 3430 trait s( otype T ) {3431 context s( type T ) { 3431 3432 T a, b; 3432 3433 } struct impl { int left, right; } a = { 0, 0 }; 3433 otype Pair | s( Pair ) = struct impl;3434 type Pair | s( Pair ) = struct impl; 3434 3435 Pair b = { 1, 1 }; 3435 3436 \end{lstlisting} … … 3439 3440 \lstinline$Pair b$ is compulsory because there is no \lstinline$struct impl b$ to construct a value from. 3440 3441 \begin{lstlisting} 3441 trait ss( otype T ) {3442 context ss( type T ) { 3442 3443 T clone( T ); 3443 3444 void munge( T * ); 3444 3445 } 3445 otype Whatsit | ss( Whatsit );@\use{Whatsit}@3446 otype Doodad | ss( Doodad ) = struct doodad {@\use{Doodad}@3446 type Whatsit | ss( Whatsit );@\use{Whatsit}@ 3447 type Doodad | ss( Doodad ) = struct doodad {@\use{Doodad}@ 3447 3448 Whatsit; // anonymous member 3448 3449 int extra; … … 3465 3466 Default functions and objects are subject to the normal scope rules. 3466 3467 \begin{lstlisting} 3467 otype T = @\ldots@;3468 type T = @\ldots@; 3468 3469 T a_T = @\ldots@; // Default assignment used. 3469 3470 T ?=?( T *, T ); … … 3734 3735 The assertion ``\lstinline$scalar( Complex )$'' should be read as ``type \lstinline$Complex$ is scalar''. 3735 3736 \begin{lstlisting} 3736 trait scalar( otype T ) {@\impl{scalar}@3737 context scalar( type T ) {@\impl{scalar}@ 3737 3738 int !?( T ); 3738 3739 int ?<?( T, T ), ?<=?( T, T ), ?==?( T, T ), ?>=?( T, T ), ?>?( T, T ), ?!=?( T, T ); … … 3744 3745 This is equivalent to inheritance of specifications. 3745 3746 \begin{lstlisting} 3746 trait arithmetic( otype T | scalar( T ) ) {@\impl{arithmetic}@@\use{scalar}@3747 context arithmetic( type T | scalar( T ) ) {@\impl{arithmetic}@@\use{scalar}@ 3747 3748 T +?( T ), -?( T ); 3748 3749 T ?*?( T, T ), ?/?( T, T ), ?+?( T, T ), ?-?( T, T ); … … 3753 3754 \define{integral types}. 3754 3755 \begin{lstlisting} 3755 trait integral( otype T | arithmetic( T ) ) {@\impl{integral}@@\use{arithmetic}@3756 context integral( type T | arithmetic( T ) ) {@\impl{integral}@@\use{arithmetic}@ 3756 3757 T ~?( T ); 3757 3758 T ?&?( T, T ), ?|?( T, T ), ?^?( T, T ); … … 3767 3768 The only operation that can be applied to all modifiable lvalues is simple assignment. 3768 3769 \begin{lstlisting} 3769 trait m_lvalue( otype T ) {@\impl{m_lvalue}@3770 context m_lvalue( type T ) {@\impl{m_lvalue}@ 3770 3771 T ?=?( T *, T ); 3771 3772 }; … … 3777 3778 Scalars can also be incremented and decremented. 3778 3779 \begin{lstlisting} 3779 trait m_l_scalar( otype T | scalar( T ) | m_lvalue( T ) ) {@\impl{m_l_scalar}@3780 context m_l_scalar( type T | scalar( T ) | m_lvalue( T ) ) {@\impl{m_l_scalar}@ 3780 3781 T ?++( T * ), ?--( T * );@\use{scalar}@@\use{m_lvalue}@ 3781 3782 T ++?( T * ), --?( T * ); … … 3786 3787 Note that this results in the ``inheritance'' of \lstinline$scalar$ along both paths. 3787 3788 \begin{lstlisting} 3788 trait m_l_arithmetic( otype T | m_l_scalar( T ) | arithmetic( T ) ) {@\impl{m_l_arithmetic}@3789 context m_l_arithmetic( type T | m_l_scalar( T ) | arithmetic( T ) ) {@\impl{m_l_arithmetic}@ 3789 3790 T ?/=?( T *, T ), ?*=?( T *, T );@\use{m_l_scalar}@@\use{arithmetic}@ 3790 3791 T ?+=?( T *, T ), ?-=?( T *, T ); 3791 3792 }; 3792 trait m_l_integral( otype T | m_l_arithmetic( T ) | integral( T ) ) {@\impl{m_l_integral}@3793 context m_l_integral( type T | m_l_arithmetic( T ) | integral( T ) ) {@\impl{m_l_integral}@ 3793 3794 T ?&=?( T *, T ), ?|=?( T *, T ), ?^=?( T *, T );@\use{m_l_arithmetic}@ 3794 3795 T ?%=?( T *, T ), ?<<=?( T *, T ), ?>>=?( T *, T );@\use{integral}@ … … 3810 3811 \lstinline$arithmetic$, so these operators cannot be consolidated in \lstinline$scalar$. 3811 3812 \begin{lstlisting} 3812 trait pointer( type P | scalar( P ) ) {@\impl{pointer}@@\use{scalar}@3813 context pointer( type P | scalar( P ) ) {@\impl{pointer}@@\use{scalar}@ 3813 3814 P ?+?( P, long int ), ?+?( long int, P ), ?-?( P, long int ); 3814 3815 ptrdiff_t ?-?( P, P ); 3815 3816 }; 3816 trait m_l_pointer( type P | pointer( P ) | m_l_scalar( P ) ) {@\impl{m_l_pointer}@3817 context m_l_pointer( type P | pointer( P ) | m_l_scalar( P ) ) {@\impl{m_l_pointer}@ 3817 3818 P ?+=?( P *, long int ), ?-=?( P *, long int ); 3818 3819 P ?=?( P *, void * ); … … 3826 3827 ``\lstinline$Safe_pointer$ acts like a pointer to \lstinline$int$''. 3827 3828 \begin{lstlisting} 3828 trait ptr_to( type P | pointer( P ), otype T ) {@\impl{ptr_to}@@\use{pointer}@3829 context ptr_to( type P | pointer( P ), type T ) {@\impl{ptr_to}@@\use{pointer}@ 3829 3830 lvalue T *?( P ); 3830 3831 lvalue T ?[?]( P, long int ); 3831 3832 }; 3832 trait ptr_to_const( type P | pointer( P ), otype T ) {@\impl{ptr_to_const}@3833 context ptr_to_const( type P | pointer( P ), type T ) {@\impl{ptr_to_const}@ 3833 3834 const lvalue T *?( P ); 3834 3835 const lvalue T ?[?]( P, long int );@\use{pointer}@ 3835 3836 }; 3836 trait ptr_to_volatile( type P | pointer( P ), otype T ) }@\impl{ptr_to_volatile}@3837 context ptr_to_volatile( type P | pointer( P ), type T ) }@\impl{ptr_to_volatile}@ 3837 3838 volatile lvalue T *?( P ); 3838 3839 volatile lvalue T ?[?]( P, long int );@\use{pointer}@ 3839 3840 }; 3840 trait ptr_to_const_volatile( type P | pointer( P ), otype T ) }@\impl{ptr_to_const_volatile}@3841 context ptr_to_const_volatile( type P | pointer( P ), type T ) }@\impl{ptr_to_const_volatile}@ 3841 3842 const volatile lvalue T *?( P );@\use{pointer}@ 3842 3843 const volatile lvalue T ?[?]( P, long int ); … … 3848 3849 ``\lstinline$ptr_to$'' specifications. 3849 3850 \begin{lstlisting} 3850 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}@ {3851 context m_l_ptr_to( type P | m_l_pointer( P ),@\use{m_l_pointer}@@\impl{m_l_ptr_to}@ type T | ptr_to( P, T )@\use{ptr_to}@ { 3851 3852 P ?=?( P *, T * ); 3852 3853 T * ?=?( T **, P ); 3853 3854 }; 3854 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}@) {3855 context m_l_ptr_to_const( type P | m_l_pointer( P ),@\use{m_l_pointer}@@\impl{m_l_ptr_to_const}@ type T | ptr_to_const( P, T )@\use{ptr_to_const}@) { 3855 3856 P ?=?( P *, const T * ); 3856 3857 const T * ?=?( const T **, P ); 3857 3858 }; 3858 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}@3859 context m_l_ptr_to_volatile( type P | m_l_pointer( P ),@\use{m_l_pointer}@@\impl{m_l_ptr_to_volatile}@ type T | ptr_to_volatile( P, T )) {@\use{ptr_to_volatile}@ 3859 3860 P ?=?( P *, volatile T * ); 3860 3861 volatile T * ?=?( volatile T **, P ); 3861 3862 }; 3862 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}@3863 context 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}@ 3863 3864 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}@ 3864 3865 P ?=?( P *, const volatile T * ); … … 3870 3871 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. 3871 3872 \begin{lstlisting} 3872 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 ) ) {3873 context 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 ) ) { 3873 3874 MyP ?=?( MyP *, CP ); 3874 3875 CP ?=?( CP *, MyP ); … … 3903 3904 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. 3904 3905 \begin{lstlisting} 3905 trait comparable( otype T ) {3906 context comparable( type T ) { 3906 3907 const T 0; 3907 3908 int compare( T, T ); 3908 3909 } 3909 forall( otype T | comparable( T ) ) int ?<?( T l, T r ) {3910 forall( type T | comparable( T ) ) int ?<?( T l, T r ) { 3910 3911 return compare( l, r ) < 0; 3911 3912 } 3912 3913 // ... similarly for <=, ==, >=, >, and !=. 3913 forall( otype T | comparable( T ) ) int !?( T operand ) {3914 forall( type T | comparable( T ) ) int !?( T operand ) { 3914 3915 return !compare( operand, 0 ); 3915 3916 } … … 3923 3924 Similarly, a complete integral type would provide integral operations based on integral assignment operations. 3924 3925 \begin{lstlisting} 3925 trait arith_base( otype T ) {3926 context arith_base( type T ) { 3926 3927 const T 1; 3927 3928 T ?+=?( T *, T ), ?-=?( T *, T ), ?*=?( T *, T ), ?/=?( T *, T ); 3928 3929 } 3929 forall( otype T | arith_base( T ) ) T ?+?( T l, T r ) {3930 forall( type T | arith_base( T ) ) T ?+?( T l, T r ) { 3930 3931 return l += r; 3931 3932 } 3932 forall( otype T | arith_base( T ) ) T ?++( T * operand ) {3933 forall( type T | arith_base( T ) ) T ?++( T * operand ) { 3933 3934 T temporary = *operand; 3934 3935 *operand += 1; 3935 3936 return temporary; 3936 3937 } 3937 forall( otype T | arith_base( T ) ) T ++?( T * operand ) {3938 forall( type T | arith_base( T ) ) T ++?( T * operand ) { 3938 3939 return *operand += 1; 3939 3940 } 3940 3941 // ... similarly for -, --, *, and /. 3941 trait int_base( otype T ) {3942 context int_base( type T ) { 3942 3943 T ?&=?( T *, T ), ?|=?( T *, T ), ?^=?( T *, T ); 3943 3944 T ?%=?( T *, T ), ?<<=?( T *, T ), ?>>=?( T *, T ); 3944 3945 } 3945 forall( otype T | int_base( T ) ) T ?&?( T l, T r ) {3946 forall( type T | int_base( T ) ) T ?&?( T l, T r ) { 3946 3947 return l &= r; 3947 3948 } -
src/examples/fstream_test.c
rae357ec rbed4c63e 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Mar 6 20:58:29201613 // Update Count : 5 412 // Last Modified On : Wed Mar 2 15:12:21 2016 13 // Update Count : 51 14 14 // 15 15 … … 28 28 int i, j, k; 29 29 sin | &i | &j | &k; 30 sout | "Vous avez entré" | "i:" | "" | i | "j:" | "" | j | "k:" | "" | k | endl;30 sout | "Vous avez entré" | "i:" | i | "j:" | j | "k:" | k | endl; 31 31 } 32 32 -
src/examples/huge.c
rae357ec rbed4c63e 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Mar 8 22:16:32 201613 // Update Count : 212 // Last Modified On : Wed May 27 18:15:34 2015 13 // Update Count : 1 14 14 // 15 15 16 int huge( int n, forall( otype T ) T (*f)( T ) ) {16 int huge( int n, forall( type T ) T (*f)( T ) ) { 17 17 if ( n <= 0 ) 18 18 return f( 0 ); -
src/examples/identity.c
rae357ec rbed4c63e 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Mar 8 22:15:08201613 // Update Count : 1 312 // Last Modified On : Mon Feb 29 23:40:45 2016 13 // Update Count : 12 14 14 // 15 15 16 16 #include <fstream> 17 17 18 forall( otype T )18 forall( type T ) 19 19 T identity( T t ) { 20 20 return t; -
src/examples/includes.c
rae357ec rbed4c63e 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 2 23:28:02 201613 // Update Count : 32 812 // Last Modified On : Mon Dec 21 13:54:09 2015 13 // Update Count : 322 14 14 // 15 15 … … 43 43 #include <ctype.h> 44 44 #include <curses.h> 45 #include <demangle.h> 46 #include <dialog.h> 45 #include <demangle.h> // enum / contains "type" 46 #include <dialog.h> // enum / contains "type" 47 47 #include <dirent.h> 48 48 #include <dis-asm.h> … … 56 56 #include <err.h> 57 57 #include <errno.h> 58 #include <error.h> 58 59 #if 0 59 #include <error.h>60 #endif61 60 #include <eti.h> 62 #include <evdns.h> 61 #include <evdns.h> // subdirectory event2 contains "type" 63 62 #include <event.h> 64 #include <evhttp.h> 65 #if 0 63 #include <evhttp.h> // enum / subdirectory event2 contains "type" 66 64 #include <evrpc.h> 67 65 #include <evutil.h> 68 66 #include <execinfo.h> 69 #include <expat.h> 67 #include <expat.h> // enum / contains "type" and "context" 70 68 #include <expat_config.h> 71 69 #include <expat_external.h> … … 76 74 #include <fmtmsg.h> 77 75 #include <fnmatch.h> 78 #include <form.h> 76 #include <form.h> // contains "type" 79 77 #include <fpu_control.h> 80 78 #include <fstab.h> … … 83 81 #include <ftw.h> 84 82 #include <gconv.h> 85 //#include <gcrypt.h> 83 //#include <gcrypt.h> // enum / contains "type" 86 84 //#include <gcrypt-module.h> 87 85 #include <getopt.h> … … 109 107 #include <limits.h> 110 108 #include <locale.h> 111 #include <math.h> 109 #include <math.h> // contains "type" 112 110 #include <ncurses.h> 113 111 #include <setjmp.h> -
src/examples/it_out.c
rae357ec rbed4c63e 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Mar 8 22:14:39201613 // Update Count : 812 // Last Modified On : Wed Mar 2 18:11:00 2016 13 // Update Count : 5 14 14 // 15 15 … … 21 21 }; 22 22 23 trait writeable( otype T ) {23 trait writeable( type T ) { 24 24 forall( dtype os_type | ostream( os_type ) ) os_type * ?<<?( os_type *, T ); 25 25 }; … … 36 36 }; 37 37 38 trait readable( otype T ) {38 trait readable( type T ) { 39 39 forall( dtype is_type | istream( is_type ) ) is_type * ?<<?( is_type *, T ); 40 40 }; … … 43 43 forall( dtype is_type | istream( is_type ) ) is_type * ?>>?( is_type *, int* ); 44 44 45 trait iterator( otype iterator_type, otype elt_type ) {45 trait iterator( type iterator_type, type elt_type ) { 46 46 iterator_type ?++( iterator_type* ); 47 47 iterator_type ++?( iterator_type* ); … … 52 52 }; 53 53 54 forall( otype elt_type | writeable( elt_type ),55 otype iterator_type | iterator( iterator_type, elt_type ),54 forall( type elt_type | writeable( elt_type ), 55 type iterator_type | iterator( iterator_type, elt_type ), 56 56 dtype os_type | ostream( os_type ) ) 57 57 void write_all( iterator_type begin, iterator_type end, os_type *os ); 58 58 59 forall( otype elt_type | writeable( elt_type ),60 otype iterator_type | iterator( iterator_type, elt_type ),59 forall( type elt_type | writeable( elt_type ), 60 type iterator_type | iterator( iterator_type, elt_type ), 61 61 dtype os_type | ostream( os_type ) ) 62 62 void write_all( elt_type begin, iterator_type end, os_type *os ) { -
src/examples/new.c
rae357ec rbed4c63e 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Mar 8 22:13:20201613 // Update Count : 412 // Last Modified On : Mon Jan 25 23:33:55 2016 13 // Update Count : 2 14 14 // 15 15 16 forall( otype T )16 forall( type T ) 17 17 void f( T *t ) { 18 18 t--; -
src/examples/prolog.c
rae357ec rbed4c63e 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Mar 8 22:09:39201613 // Update Count : 512 // Last Modified On : Wed Mar 2 18:11:18 2016 13 // Update Count : 2 14 14 // 15 15 16 #include <fstream> 16 extern "C" { extern int printf( const char *fmt, ... ); } 17 17 18 void printResult( int x ) { sout | "int" | endl; }19 void printResult( double x ) { sout | "double" | endl; }20 void printResult( char * x ) { sout | "char*" | endl; }18 void printResult( int x ) { printf( "int\n" ); } 19 void printResult( double x ) { printf( "double\n" ); } 20 void printResult( char * x ) { printf( "char*\n" ); } 21 21 22 22 void is_arithmetic( int x ) {} … … 25 25 void is_integer( int x ) {} 26 26 27 trait ArithmeticType( otype T ) {27 trait ArithmeticType( type T ) { 28 28 void is_arithmetic( T ); 29 29 }; 30 30 31 trait IntegralType( otype T | ArithmeticType( T ) ) {31 trait IntegralType( type T | ArithmeticType( T ) ) { 32 32 void is_integer( T ); 33 33 }; 34 34 35 forall( otype T | IntegralType( T ) | { void printResult( T ); } )35 forall( type T | IntegralType( T ) | { void printResult( T ); } ) 36 36 void hornclause( T param ) { 37 37 printResult( param ); -
src/examples/quad.c
rae357ec rbed4c63e 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Mar 8 22:07:02201613 // Update Count : 812 // Last Modified On : Tue Mar 1 08:24:56 2016 13 // Update Count : 7 14 14 // 15 15 16 16 #include <fstream> 17 17 18 forall( otype T | { T ?*?( T, T ); } )18 forall( type T | { T ?*?( T, T ); } ) 19 19 T square( T t ) { 20 20 return t * t; 21 21 } 22 22 23 forall( otype U | { U square( U ); } )23 forall( type U | { U square( U ); } ) 24 24 U quad( U u ) { 25 25 return square( square( u ) ); -
src/examples/simplePoly.c
rae357ec rbed4c63e 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Mar 8 22:06:41 201613 // Update Count : 312 // Last Modified On : Wed May 27 18:31:17 2015 13 // Update Count : 2 14 14 // 15 15 16 forall( otype T, otype U | { T f( T, U ); } )16 forall( type T, type U | { T f( T, U ); } ) 17 17 T q( T t, U u ) { 18 18 return f( t, u ); -
src/examples/simpler.c
rae357ec rbed4c63e 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Mar 8 22:06:30 201613 // Update Count : 212 // Last Modified On : Wed May 27 18:31:48 2015 13 // Update Count : 1 14 14 // 15 15 16 forall( otype T ) T id( T, T );16 forall( type T ) T id( T, T ); 17 17 18 18 int main() { -
src/examples/specialize.c
rae357ec rbed4c63e 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Mar 8 22:06:17 201613 // Update Count : 312 // Last Modified On : Wed May 27 18:32:26 2015 13 // Update Count : 2 14 14 // 15 15 … … 39 39 } 40 40 41 forall( otype T ) T f( T t )41 forall( type T ) T f( T t ) 42 42 { 43 43 printf( "in f; sizeof T is %d\n", sizeof( T ) ); -
src/examples/square.c
rae357ec rbed4c63e 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Mar 8 22:05:48 201613 // Update Count : 2 712 // Last Modified On : Wed Feb 17 12:21:58 2016 13 // Update Count : 26 14 14 // 15 15 16 16 #include <fstream> 17 17 18 forall( otype T | { T ?*?( T, T ); } )18 forall( type T | { T ?*?( T, T ); } ) 19 19 T square( T t ) { 20 20 return t * t; -
src/examples/sum.c
rae357ec rbed4c63e 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 4 15:06:47201613 // Update Count : 19 612 // Last Modified On : Wed Mar 2 18:12:01 2016 13 // Update Count : 194 14 14 // 15 15 16 16 #include <fstream> 17 17 18 trait sumable( otype T ) {18 trait sumable( type T ) { 19 19 const T 0; 20 20 T ?+?( T, T ); … … 24 24 }; // sumable 25 25 26 forall( otype T | sumable( T ) )26 forall( type T | sumable( T ) ) 27 27 T sum( unsigned int n, T a[] ) { 28 28 T total = 0; // instantiate T, select 0 -
src/examples/twice.c
rae357ec rbed4c63e 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Mar 8 22:04:58201613 // Update Count : 1 612 // Last Modified On : Wed Feb 17 12:23:25 2016 13 // Update Count : 13 14 14 // 15 15 16 16 #include <fstream> 17 17 18 forall( otype T | { T ?+?( T, T ); T ?++( T * ); [T] ?+=?( T *, T ); } )18 forall( type T | { T ?+?( T, T ); T ?++( T * ); [T] ?+=?( T *, T ); } ) 19 19 T twice( const T t ) { 20 20 return t + t; … … 27 27 char ?++( char *op ) { char temp = *op; *op += 1; return temp; } 28 28 29 sout | twice( 'a' ) | ' ' | twice( 1 ) | twice( 3.2 ) | endl;29 sout | twice( 'a' ) | ' ' | twice( 1 ) | ' ' | twice( 3.2 ) | endl; 30 30 } 31 31 -
src/libcfa/Makefile.am
rae357ec rbed4c63e 11 11 ## Created On : Sun May 31 08:54:01 2015 12 12 ## Last Modified By : Peter A. Buhr 13 ## Last Modified On : Wed Mar 2 22:59:23201614 ## Update Count : 11 913 ## Last Modified On : Wed Feb 3 11:19:35 2016 14 ## Update Count : 117 15 15 ############################################################################### 16 16 … … 63 63 libcfa_a_SOURCES = libcfa-prelude.c ${libs:=.c} 64 64 65 cheaders = # expat65 cheaders = bfd bfdlink demangle dialog evdns evhttp evrpc expat fcntl form gcrypt math 66 66 cfaheaders = limits 67 67 include_HEADERS = ${cheaders:=.h} ${libs} ${cfaheaders} -
src/libcfa/Makefile.in
rae357ec rbed4c63e 215 215 libs = stdlib iostream fstream iterator 216 216 libcfa_a_SOURCES = libcfa-prelude.c ${libs:=.c} 217 cheaders = # expat217 cheaders = bfd bfdlink demangle dialog evdns evhttp evrpc expat fcntl form gcrypt math 218 218 cfaheaders = limits 219 219 include_HEADERS = ${cheaders:=.h} ${libs} ${cfaheaders} -
src/libcfa/iostream.c
rae357ec rbed4c63e 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Mar 7 13:51:23201613 // Update Count : 2 2712 // Last Modified On : Wed Mar 2 18:06:35 2016 13 // Update Count : 208 14 14 // 15 15 … … 133 133 forall( dtype ostype | ostream( ostype ) ) 134 134 ostype * ?|?( ostype *os, const char *cp ) { 135 enum { Open = 1, Close, OpenClose };136 static const char mask[256] = {137 // opening delimiters138 ['('] : Open, ['['] : Open, ['{'] : Open,139 ['$'] : Open, [L'£'] : Open, [L'¥'] : Open, [L'¢'] : Open, [L'¿'] : Open, [L'«'] : Open,140 // closing delimiters141 [','] : Close, ['.'] : Close, [':'] : Close, [';'] : Close, ['!'] : Close, ['?'] : Close,142 [')'] : Close, [']'] : Close, ['}'] : Close,143 ['%'] : Close, [L'»'] : Close,144 // opening-closing delimiters145 ['\''] : OpenClose, ['`'] : OpenClose, ['"'] : OpenClose,146 }; // mask147 148 135 int len = strlen( cp ); 149 136 // null string => no separator 150 137 if ( len == 0 ) { sepOff( os ); return os; } 151 // first character NOT spacing or closingpunctuation => add left separator152 if ( sepPrt( os ) && isspace( cp[0] ) == 0 && mask[ cp[0] ] != Close && mask[ cp[0] ] != OpenClose) {138 // first character NOT spacing or special punctuation => add left separator 139 if ( sepPrt( os ) && isspace( cp[0] ) == 0 && cp[0] != '.' && cp[0] != ',' ) { 153 140 prtfmt( os, "%s", sepGet( os ) ); 154 141 } // if 155 // last character IS spacing or openingpunctuation => turn off separator for next item142 // last character is spacing or special punctuation => turn off separator for next item 156 143 unsigned int posn = len - 1; 157 if ( isspace( cp[posn] ) || mask[ cp[posn] ] == Open || mask[ cp[posn] ] == OpenClose) {144 if ( isspace( cp[posn] ) || cp[posn] == ':' || cp[posn] == '$' ) { 158 145 sepOff( os ); 159 146 } else {
Note:
See TracChangeset
for help on using the changeset viewer.