- Timestamp:
- Jul 17, 2017, 2:24:00 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 5688056, 5bd0aad
- Parents:
- 4d84cb2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/user/user.tex
r4d84cb2 r59e86eb 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Thu Jul 13 11:44:57201714 %% Update Count : 2 69013 %% Last Modified On : Mon Jul 17 13:06:40 2017 14 %% Update Count : 2825 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 353 353 The 1999 C standard plus GNU extensions. 354 354 \item 355 {\lstset{deletekeywords={inline}} 356 \Indexc{-fgnu89-inline}\index{compilation option!-fgnu89-inline@{©-fgnu89-inline©}} 355 \Indexc[deletekeywords=inline]{-fgnu89-inline}\index{compilation option!-fgnu89-inline@{\lstinline[deletekeywords=inline]$-fgnu89-inline$}} 357 356 Use the traditional GNU semantics for inline routines in C99 mode, which allows inline routines in header files. 358 }%359 357 \end{description} 360 358 The following new \CFA options are available: … … 479 477 \end{cfa} 480 478 Existing C programs with keyword clashes can be converted by enclosing keyword identifiers in backquotes, and eventually the identifier name can be changed to a non-keyword name. 481 \VRef[Figure]{f: InterpositionHeaderFile} shows how clashes in C header files (see~\VRef{s:StandardHeaders}) can be handled using preprocessor \newterm{interposition}: ©#include_next© and ©-I filename©:479 \VRef[Figure]{f:HeaderFileInterposition} shows how clashes in C header files (see~\VRef{s:StandardHeaders}) can be handled using preprocessor \newterm{interposition}: ©#include_next© and ©-I filename©: 482 480 483 481 \begin{figure} … … 487 485 #define otype ®`®otype®`® §\C{// make keyword an identifier}§ 488 486 #define __CFA_BFD_H__ 489 #endif // ! otype490 491 #®include_next®<bfd.h> §\C{// must have internal check for multiple expansion}§492 487 #endif 488 489 ®#include_next <bfd.h> §\C{// must have internal check for multiple expansion}§ 490 ® 493 491 #if defined( otype ) && defined( __CFA_BFD_H__ ) §\C{// reset only if set}§ 494 492 #undef otype 495 493 #undef __CFA_BFD_H__ 496 #endif // otype && __CFA_BFD_H__497 \end{cfa} 498 \caption{ Interposition of Header File}499 \label{f: InterpositionHeaderFile}494 #endif 495 \end{cfa} 496 \caption{Header-File Interposition} 497 \label{f:HeaderFileInterposition} 500 498 \end{figure} 499 500 501 \section{Exponentiation Operator} 502 503 C, \CC, and Java (and many other programming languages) have no exponentiation operator\index{exponentiation!operator}\index{operator!exponentiation}, \ie $x^y$, and instead use a routine, like \Indexc{pow}, to perform the exponentiation operation. 504 \CFA extends the basic operators with the exponentiation operator ©?\?©\index{?\\?@\lstinline$?\?$} and ©?\=?©\index{?\\=?@\lstinline$?\=?$}, as in, ©x \ y© and ©x \= y©, which means $x^y$ and $x \leftarrow x^y$. 505 The priority of the exponentiation operator is between the cast and multiplicative operators, so that ©w * (int)x \ (int)y * z© is parenthesized as ©((w * (((int)x) \ ((int)y))) * z)©. 506 507 As for \Index{division}, there are exponentiation operators for integral and floating-point types, including the builtin \Index{complex} types. 508 Unsigned integral exponentiation\index{exponentiation!unsigned integral} is performed with repeated multiplication (or shifting if the base is 2). 509 Signed integral exponentiation\index{exponentiation!signed integral} is performed with repeated multiplication (or shifting if the base is 2), but yields a floating-point result because $b^{-e}=1/b^e$. 510 Hence, it is important to designate exponent integral-constants as unsigned or signed: ©3 \ 3u© return an integral result, while ©3 \ 3© returns a floating-point result. 511 Floating-point exponentiation\index{exponentiation!floating point} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the base cannot be negative. 512 \begin{cfa} 513 sout | 2 ®\® 8u | 4 ®\® 3u | -4 ®\® 3u | 4 ®\® -3 | -4 ®\® -3 | 4.0 ®\® 2.1 | (1.0f+2.0fi) ®\® (3.0f+2.0fi) | endl; 514 256 64 -64 0.015625 -0.015625 18.3791736799526 0.264715-1.1922i 515 \end{cfa} 516 Parenthesis are necessary for the complex constants or the expresion is parsed as ©1.0f+(2.0fi \ 3.0f)+2.0fi©. 517 The exponentiation operator is available for all the basic types, but for user-defined types, only the integral version is available, if the user type defines multiplication, ©*©, and one, ©1©. 501 518 502 519 … … 922 939 int i, j; 923 940 int mem() { ®// implicit "this" parameter 924 i = 1; ®// this->i941 ® i = 1; ®// this->i 925 942 ® j = 3; ®// this->j 926 943 ® } … … 929 946 Since CFA is non-object-oriented, the equivalent object-oriented program looks like: 930 947 \begin{cfa} 931 struct C { 932 int i, j; 933 }; 934 int mem( C &this ) { // explicit "this" parameter 948 struct S { int i, j; }; 949 int mem( S &this ) { // explicit "this" parameter 935 950 ®this.®i = 1; // "this" is not elided 936 951 ®this.®j = 2; … … 938 953 \end{cfa} 939 954 but it is cumbersome having to write "©this.©" many times in a member. 940 \CFA provides a ©with© clause/statement to elided the "©this.©". 941 \begin{cfa} 942 int mem( C &this ) ®with this® { 955 956 \CFA provides a ©with© clause/statement to elided the "©this.©" by opening a scope containing field identifiers and changing the qualified fields into variables, giving an opportunity for optimizing qualified references.\footnote{ 957 The ©with© statement comes from Pascal~\cite[\S~4.F]{Pascal}.} 958 \begin{cfa} 959 int mem( S &this ) ®with this® { 943 960 i = 1; ®// this.i 944 961 ® j = 2; ®// this.j … … 947 964 which extends to multiple routine parameters: 948 965 \begin{cfa} 949 struct D { 950 double m, n; 951 }; 952 int mem2( C &this1, D &this2 ) ®with this1, this2® { 966 struct T { double m, n; }; 967 int mem2( S &this1, T &this2 ) ®with this1, this2® { 953 968 i = 1; j = 2; 954 969 m = 1.0; n = 2.0; 955 970 } 956 971 \end{cfa} 957 The ©with© clause/statement comes from Pascal~\cite[\S~4.F]{Pascal}.958 972 959 973 The statement form is used within a block: … … 965 979 // access fields of s1 without qualification 966 980 ®with s2® { // nesting 967 // access fields of s 2 without qualification981 // access fields of s1 and s2 without qualification 968 982 } 969 983 } … … 974 988 \end{cfa} 975 989 976 Names clashes when opening multiple structures are ambiguous. 977 \begin{cfa} 978 struct A { int i; int j; } a, c; 979 struct B { int i; int k; } b, c; 990 When opening multiple structures, fields with the same name and type are ambiguous and must be fully qualified. 991 For fields with the same name but different type, context/cast can be used to disambiguate. 992 \begin{cfa} 993 struct S { int i; int j; double m; } a, c; 994 struct T { int i; int k; int m } b, c; 980 995 ®with a, b® { 981 j + k; §\C{// unambiguous}§ 982 i; §\C{// ambiguous}§ 983 a.i + b.i; §\C{// unambiguous}§ 984 } 985 ®with c® { §\C{// ambiguous}§ 986 // ... 987 } 996 j + k; §\C{// unambiguous, unique names define unique type}§ 997 i; §\C{// ambiguous, same name and type}§ 998 a.i + b.i; §\C{// unambiguous, qualification defines unique type}§ 999 m; §\C{// ambiguous, no context to define unique type}§ 1000 m = 5.0; §\C{// unambiguous, context defines unique type}§ 1001 m = 1; §\C{// unambiguous, context defines unique type}§ 1002 } 1003 ®with c® { ... } §\C{// ambiguous, no context}§ 1004 ®with (S)c® { ... } §\C{// unambiguous, cast defines unique type}§ 988 1005 \end{cfa} 989 1006 990 1007 991 1008 \section{Exception Handling} 1009 \label{s:ExceptionHandling} 992 1010 993 1011 Exception handling provides two mechanism: change of control flow from a raise to a handler, and communication from the raise to the handler. 994 \begin{cfa} 995 exception void h( int i ); 996 exception int h( int i, double d ); 997 1012 Transfer of control can be local, within a routine, or non-local, among routines. 1013 Non-local transfer can cause stack unwinding, i.e., non-local routine termination, depending on the kind of raise. 1014 \begin{cfa} 1015 exception_t E {}; §\C{// exception type}§ 998 1016 void f(...) { 999 ... throw h( 3 ); 1000 ... i = resume h( 3, 5.1 ); 1001 } 1002 1017 ... throw E{}; ... §\C{// termination}§ 1018 ... throwResume E{}; ... §\C{// resumption}§ 1019 } 1003 1020 try { 1004 1021 f(...); 1005 } catch h( int w ) {1006 // re set1007 } resume h( int p, double x ) {1008 return 17; // recover1022 } catch( E e : §boolean-predicate§ ) { §\C{// termination handler}§ 1023 // recover and continue 1024 } catchResume( E e : §boolean-predicate§ ) { §\C{// resumption handler}§ 1025 // repair and return 1009 1026 } finally { 1010 } 1011 \end{cfa} 1012 So the type raised would be the mangled name of the exception prototype and that name would be matched at the handler clauses by comparing the strings. 1013 The arguments for the call would have to be packed in a message and unpacked at handler clause and then a call made to the handler. 1027 // always executed 1028 } 1029 \end{cfa} 1030 The kind of raise and handler match: ©throw© with ©catch© and @throwResume@ with @catchResume@. 1031 Then the exception type must match along with any additonal predicate must be true. 1032 The ©catch© and ©catchResume© handlers may appear in any oder. 1033 However, the ©finally© clause must 1014 1034 1015 1035 … … 1571 1591 1572 1592 \item 1573 lvalue to reference conversion: \lstinline[deletekeywords= {lvalue}]@lvalue-type cv1 T@converts to ©cv2 T &©, which allows implicitly converting variables to references.1593 lvalue to reference conversion: \lstinline[deletekeywords=lvalue]$lvalue-type cv1 T$ converts to ©cv2 T &©, which allows implicitly converting variables to references. 1574 1594 \begin{cfa} 1575 1595 int x, &r = ®x®, f( int & p ); // lvalue variable (int) convert to reference (int &) … … 2680 2700 \begin{cfa}[belowskip=0pt] 2681 2701 char store[®sepSize®]; §\C{// sepSize is the maximum separator size}§ 2682 strcpy( store, sepGet( sout ) ); 2683 sepSet( sout, "_" ); 2702 strcpy( store, sepGet( sout ) ); §\C{// copy current separator}§ 2703 sepSet( sout, "_" ); §\C{// change separator to underscore}§ 2684 2704 sout | 1 | 2 | 3 | endl; 2685 2705 \end{cfa} … … 2688 2708 \end{cfa} 2689 2709 \begin{cfa}[belowskip=0pt] 2690 sepSet( sout, store ); 2710 sepSet( sout, store ); §\C{// change separator back to original}§ 2691 2711 sout | 1 | 2 | 3 | endl; 2692 2712 \end{cfa} … … 5563 5583 \Celeven prescribes the following standard header-files~\cite[\S~7.1.2]{C11} and \CFA adds to this list: 5564 5584 \begin{quote2} 5565 \lstset{deletekeywords={float}} 5566 \begin{tabular}{@{}llll|l@{}} 5567 \multicolumn{4}{c|}{C11} & \multicolumn{1}{c}{\CFA} \\ 5585 \begin{tabular}{@{}lllll|l@{}} 5586 \multicolumn{5}{c|}{C11} & \multicolumn{1}{c}{\CFA} \\ 5568 5587 \hline 5569 5588 \begin{tabular}{@{}l@{}} … … 5573 5592 \Indexc{errno.h} \\ 5574 5593 \Indexc{fenv.h} \\ 5575 \Indexc{float.h} \\ 5576 \Indexc{inttypes.h} \\ 5577 \Indexc{iso646.h} \\ 5594 \Indexc[deletekeywords=float]{float.h} \\ 5578 5595 \end{tabular} 5579 5596 & 5580 5597 \begin{tabular}{@{}l@{}} 5598 \Indexc{inttypes.h} \\ 5599 \Indexc{iso646.h} \\ 5581 5600 \Indexc{limits.h} \\ 5582 5601 \Indexc{locale.h} \\ 5583 5602 \Indexc{math.h} \\ 5584 5603 \Indexc{setjmp.h} \\ 5604 \end{tabular} 5605 & 5606 \begin{tabular}{@{}l@{}} 5585 5607 \Indexc{signal.h} \\ 5586 5608 \Indexc{stdalign.h} \\ 5587 5609 \Indexc{stdarg.h} \\ 5588 5610 \Indexc{stdatomic.h} \\ 5611 \Indexc{stdbool.h} \\ 5612 \Indexc{stddef.h} \\ 5589 5613 \end{tabular} 5590 5614 & 5591 5615 \begin{tabular}{@{}l@{}} 5592 \Indexc{stdbool.h} \\5593 \Indexc{stddef.h} \\5594 5616 \Indexc{stdint.h} \\ 5595 5617 \Indexc{stdio.h} \\ … … 5607 5629 \Indexc{wctype.h} \\ 5608 5630 \\ 5609 \\5610 \\5611 5631 \end{tabular} 5612 5632 & … … 5614 5634 \Indexc{unistd.h} \\ 5615 5635 \Indexc{gmp.h} \\ 5616 \\5617 \\5618 5636 \\ 5619 5637 \\ … … 5655 5673 The table shows allocation routines supporting different combinations of storage-management capabilities: 5656 5674 \begin{center} 5657 \begin{tabular}{@{} lr|l|l|l|l@{}}5658 && \multicolumn{1}{c|}{fill} & resize & alignment & array \\5675 \begin{tabular}{@{}r|r|l|l|l|l@{}} 5676 \multicolumn{1}{c}{}& & \multicolumn{1}{c|}{fill} & resize & alignment & array \\ 5659 5677 \hline 5660 5678 C & ©malloc© & no & no & no & no \\ … … 5663 5681 & ©memalign© & no & no & yes & no \\ 5664 5682 & ©posix_memalign© & no & no & yes & no \\ 5683 \hline 5665 5684 C11 & ©aligned_alloc© & no & no & yes & no \\ 5685 \hline 5666 5686 \CFA & ©alloc© & no/copy/yes & no/yes & no & yes \\ 5667 5687 & ©align_alloc© & no/yes & no & yes & yes \\
Note: See TracChangeset
for help on using the changeset viewer.