Changeset fbfb38e


Ignore:
Timestamp:
Apr 22, 2016, 1:42:36 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
67b1180
Parents:
dc2e7e0 (diff), 6812d89 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into ctor

Files:
3 added
15 edited

Legend:

Unmodified
Added
Removed
  • doc/user/Makefile

    rdc2e7e0 rfbfb38e  
    1212
    1313FIGURES = ${addsuffix .tex, \
     14Cdecl \
    1415}
    1516
  • doc/user/user.tex

    rdc2e7e0 rfbfb38e  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Sun Apr 10 22:50:15 2016
    14 %% Update Count     : 72
     13%% Last Modified On : Thu Apr 21 08:15:37 2016
     14%% Update Count     : 131
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    2626\usepackage{upquote}
    2727\usepackage{fullpage,times}
     28\usepackage{epic,eepic}
    2829\usepackage{xspace}
    2930\usepackage{varioref}
     
    4849% Names used in the document.
    4950
     51\newcommand{\Version}{1.0.0}
    5052\newcommand{\CS}{C\raisebox{-0.9ex}{\large$^\sharp$}\xspace}
    5153
     
    105107The syntax of the \CFA language builds from C, and should look immediately familiar to C programmers.
    106108% Any language feature that is not described here can be assumed to be using the standard C11 syntax.
    107 \CFA adds many modern programming-language features, which directly leads to increased safety and productivity, while maintaining interoperability with existing C programs and maintaining C-like performance.
     109\CFA adds many modern programming-language features, which directly leads to increased safety and productivity, while maintaining interoperability with existing C programs and achieving C performance.
    108110Like C, \CFA is a statically typed, procedural language with a low-overhead runtime, meaning there is no global garbage-collection.
    109111The primary new features include parametric-polymorphism routines and types, exceptions, concurrency, and modules.
     
    224226
    225227
    226 \section{Compiling \CFA}
     228\section{Compiling \CFA Program}
    227229
    228230The command \lstinline@cfa@ is used to compile \CFA program(s).
     
    231233cfa [ gcc-options ] C/@{\CFA}@-files [ assembler/loader-files ]
    232234\end{lstlisting}
     235\index{cfa@\lstinline$cfa$}\index{compilation!cfa@\lstinline$cfa$}
    233236By default, \CFA programs having the following \lstinline@gcc@ flags turned on:
    234237\begin{description}
    235238\item
    236239\hspace*{-4pt}\lstinline@-std=gnu99@
     240\index{-std=gnu99@{\lstinline$-std=gnu99$}}\index{compilation option!-std=gnu99@{\lstinline$-std=gnu99$}}
    237241The 1999 C standard plus GNU extensions.
     242\item
     243\hspace*{-4pt}\lstinline@-fgnu89-inline@
     244\index{-fgnu89-inline@{\lstinline$-fgnu89-inline$}}\index{compilation option!-fgnu89-inline@{\lstinline$-fgnu89-inline$}}
     245Use the traditional GNU semantics for inline routines in C99 mode.
    238246\end{description}
    239247The following new \CFA option is available:
     
    241249\item
    242250\hspace*{-4pt}\lstinline@-CFA@
     251\index{-CFA@{\lstinline$-CFA$}}\index{compilation option!-CFA@{\lstinline$-CFA$}}
    243252Only the C preprocessor and the \CFA translator steps are performed and the transformed program is written to standard output, which makes it possible to examine the code generated by the \CFA translator.
    244253\end{description}
     254
     255The following preprocessor variables are available:
     256\begin{description}
     257\item
     258\hspace*{-4pt}\lstinline$__CFA__$
     259\index{__CFA__@{\lstinline$__CFA__$}}\index{preprocessor variables!__CFA__@{\lstinline$__CFA__$}}
     260is always available during preprocessing and its value is the current major \Index{version number} of \CFA.\footnote{
     261The C preprocessor allows only integer values in a preprocessor variable so a value like ``\Version'' is not allowed.
     262Hence, the need to have three variables for the major, minor and patch version number.}
     263
     264\item
     265\hspace*{-4pt}\lstinline$__CFA_MINOR__$
     266\index{__CFA_MINOR__@{\lstinline$__CFA_MINOR__$}}\index{preprocessor variables!__CFA_MINOR__@{\lstinline$__CFA_MINOR__$}}
     267is always available during preprocessing and its value is the current minor \Index{version number} of \CFA.
     268
     269\item
     270\hspace*{-4pt}\lstinline$__CFA_PATCH__$
     271\index{__CFA_PATCH__@%(__CFA_PATCH__%)}\index{preprocessor variables!__CFA_PATCH__@%(__CFA_PATCH__%)}
     272is always available during preprocessing and its value is the current patch \Index{version number} of \CFA.
     273
     274\item
     275\hspace*{-4pt}\lstinline$__CFORALL__$
     276\index{__CFORALL__@%(__CFORALL__%)}\index{preprocessor variables!__CFORALL__@%(__CFORALL__%)}
     277is always available during preprocessing and it has no value.
     278\end{description}
     279
     280These preprocessor variables allow conditional compilation of programs that must work differently in these situations.
     281For example, to toggle between C and \CFA extensions, using the following:
     282\begin{lstlisting}
     283#ifndef __CFORALL__
     284#include <stdio.h>              // C header file
     285#else
     286#include <fstream>              // @\CFA{}@ header file
     287#endif
     288\end{lstlisting}
     289which conditionally includes the correct header file, if the program is compiled using \lstinline@gcc@ or \lstinline@cfa@.
    245290
    246291
     
    284329C declaration syntax is notoriously confusing and error prone.
    285330For example, many C programmers are confused by a declaration as simple as:
    286 \begin{lstlisting}
    287 int *x[ 10 ]
    288 \end{lstlisting}
    289 Is this a pointer to an array of 10 integers or an array of 10 pointers to integers?
     331\begin{quote2}
     332\begin{tabular}{@{}ll@{}}
     333\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
     334int *x[ 5 ]
     335\end{lstlisting}
     336&
     337\raisebox{-0.75\totalheight}{\input{Cdecl}}
     338\end{tabular}
     339\end{quote2}
     340Is this an array of 5 pointers to integers or a pointer to an array of 5 integers?
    290341Another example of confusion results from the fact that a routine name and its parameters are embedded within the return type, mimicking the way the return value is used at the routine's call site.
    291342For example, a routine returning a pointer to an array of integers is defined and used in the following way:
    292343\begin{lstlisting}
    293 int (*f())[ 10 ] {...};
    294 ... (*f())[  3 ] += 1;  // definition mimics usage
     344int (*f())[ 5 ] {...};  // definition mimics usage
     345... (*f())[ 3 ] += 1;
    295346\end{lstlisting}
    296347Essentially, the return type is wrapped around the routine name in successive layers (like an onion).
     
    322373\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c@{\hspace{20pt}}}{\textbf{C}}        \\
    323374\begin{lstlisting}
    324 [ 10 ] int z;
    325 [ 10 ] * char w;
    326 * [ 10 ] double v;
     375[ 5 ] int z;
     376[ 5 ] * char w;
     377* [ 5 ] double v;
    327378struct s {
    328379        int f0:3;
    329380        * int f1;
    330         [ 10 ] * int f2;
     381        [ 5 ] * int f2;
    331382};
    332383\end{lstlisting}
    333384&
    334385\begin{lstlisting}
    335 int z[ 10 ];
    336 char *w[ 10 ];
    337 double (*v)[ 10 ];
     386int z[ 5 ];
     387char *w[ 5 ];
     388double (*v)[ 5 ];
    338389struct s {
    339390        int f0:3;
    340391        int *f1;
    341         int *f2[ 10 ]
     392        int *f2[ 5 ]
    342393};
    343394\end{lstlisting}
    344395&
    345396\begin{lstlisting}
    346 // array of 10 integers
    347 // array of 10 pointers to char
    348 // pointer to array of 10 doubles
     397// array of 5 integers
     398// array of 5 pointers to char
     399// pointer to array of 5 doubles
    349400
    350401// common bit field syntax
     
    362413\begin{lstlisting}
    363414const * const int x;
    364 const * [ 10 ] const int y;
     415const * [ 5 ] const int y;
    365416\end{lstlisting}
    366417&
    367418\begin{lstlisting}
    368419int const * const x;
    369 const int (* const y)[ 10 ]
     420const int (* const y)[ 5 ]
    370421\end{lstlisting}
    371422&
    372423\begin{lstlisting}
    373424// const pointer to const integer
    374 // const pointer to array of 10 const integers
     425// const pointer to array of 5 const integers
    375426\end{lstlisting}
    376427\end{tabular}
     
    382433\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c@{\hspace{20pt}}}{\textbf{C}}        \\
    383434\begin{lstlisting}
    384 extern [ 10 ] int x;
     435extern [ 5 ] int x;
    385436static * const int y;
    386437\end{lstlisting}
    387438&
    388439\begin{lstlisting}
    389 int extern x[ 10 ];
     440int extern x[ 5 ];
    390441const int static *y;
    391442\end{lstlisting}
    392443&
    393444\begin{lstlisting}
    394 // externally visible array of 10 integers
     445// externally visible array of 5 integers
    395446// internally visible pointer to constant int
    396447\end{lstlisting}
     
    421472\begin{lstlisting}
    422473y = (* int)x;
    423 i = sizeof([ 10 ] * int);
     474i = sizeof([ 5 ] * int);
    424475\end{lstlisting}
    425476&
    426477\begin{lstlisting}
    427478y = (int *)x;
    428 i = sizeof(int *[ 10 ]);
     479i = sizeof(int *[ 5 ]);
    429480\end{lstlisting}
    430481\end{tabular}
     
    466517\CFA style declarations cannot be used to declare parameters for K\&R style routine definitions because of the following ambiguity:
    467518\begin{lstlisting}
    468 int (*f(x))[ 10 ] int x; {}
    469 \end{lstlisting}
    470 The string ``\lstinline@int (*f(x))[ 10 ]@'' declares a K\&R style routine of type returning a pointer to an array of 10 integers, while the string ``\lstinline@[ 10 ] int x@'' declares a \CFA style parameter x of type array of 10 integers.
     519int (*f(x))[ 5 ] int x; {}
     520\end{lstlisting}
     521The string ``\lstinline@int (*f(x))[ 5 ]@'' declares a K\&R style routine of type returning a pointer to an array of 5 integers, while the string ``\lstinline@[ 5 ] int x@'' declares a \CFA style parameter x of type array of 5 integers.
    471522Since the strings overlap starting with the open bracket, \lstinline@[@, there is an ambiguous interpretation for the string.
    472523As well, \CFA-style declarations cannot be used to declare parameters for C-style routine-definitions because of the following ambiguity:
     
    487538\begin{lstlisting}
    488539#define ptoa( n, d ) int (*n)[ d ]
    489 int f( ptoa(p,10) ) ...         // expands to int f( int (*p)[ 10 ] )
    490 [ int ] f( ptoa(p,10) ) ...     // expands to [ int ] f( int (*p)[ 10 ] )
     540int f( ptoa(p,5) ) ...          // expands to int f( int (*p)[ 5 ] )
     541[ int ] f( ptoa(p,5) ) ...      // expands to [ int ] f( int (*p)[ 5 ] )
    491542\end{lstlisting}
    492543Again, programmers are highly encouraged to use one declaration form or the other, rather than mixing the forms.
     
    807858which can be used to sort in ascending and descending order by locally redefining the less-than operator into greater-than.
    808859\begin{lstlisting}
    809 const unsigned int size = 10;
     860const unsigned int size = 5;
    810861int ia[size];
    811862...                                             // assign values to array ia
     
    874925[ double, double, double ]
    875926[ * int, int * ]                // mix of CFA and ANSI
    876 [ * [ 10 ] int, * * char, * [ [ int, int ] ] (int, int) ]
     927[ * [ 5 ] int, * * char, * [ [ int, int ] ] (int, int) ]
    877928\end{lstlisting}
    878929Like tuples, tuple types may be nested, such as \lstinline@[ [ int, int ], int ]@, which is a 2-element tuple type whose first element is itself a tuple type.
     
    22162267
    22172268        try {
    2218         throw 13;
     2269                throw 13;
    22192270        }
    22202271        catch(int e) {
    2221         printf(.caught an exception: %d\n., e);
     2272                printf(.caught an exception: %d\n., e);
    22222273        }
    22232274\end{lstlisting}
  • src/ResolvExpr/CastCost.cc

    rdc2e7e0 rfbfb38e  
    6969                PointerType *destAsPointer = dynamic_cast< PointerType* >( dest );
    7070                if ( destAsPointer && basicType->isInteger() ) {
    71                         //cost = Cost( 1, 0, 0 );
    72                         cost = Cost::infinity;
     71                        // necessary for, e.g. unsigned long => void*
     72                        cost = Cost( 1, 0, 0 );
    7373                } else {
    7474                        ConversionCost::visit( basicType );
     
    8989                                } else if ( castResult < 0 ) {
    9090                                        cost = Cost::infinity;
    91                                         //cost = Cost( 1, 0, 0 );
    9291                                } // if
    9392                        } // if
    9493                } else if ( BasicType *destAsBasic = dynamic_cast< BasicType* >( dest ) ) {
    9594                        if ( destAsBasic->isInteger() ) {
    96                                 //cost = Cost( 1, 0, 0 );
    97                                 cost = Cost::infinity;
     95                                // necessary for, e.g. void* => unsigned long
     96                                cost = Cost( 1, 0, 0 );
    9897                        } // if
    9998                }
  • src/SymTab/Indexer.cc

    rdc2e7e0 rfbfb38e  
    511511        }
    512512
    513         bool Indexer::hasIncompatibleCDecl( const std::string &id, const std::string &mangleName ) const {
     513        bool Indexer::hasIncompatibleCDecl( const std::string &id, const std::string &mangleName, unsigned long scope ) const {
    514514                if ( ! tables ) return false;
     515                if ( tables->scope < scope ) return false;
    515516
    516517                IdTable::const_iterator decls = tables->idTable.find( id );
     
    524525                }
    525526
    526                 return tables->base.hasIncompatibleCDecl( id, mangleName );
     527                return tables->base.hasIncompatibleCDecl( id, mangleName, scope );
    527528        }
    528529       
     
    617618                DeclarationWithType *existing = lookupIdAtScope( name, mangleName, scope );
    618619                if ( ! existing || ! addedIdConflicts( existing, decl ) ) {
    619                         // this ensures that no two declarations with the same unmangled name both have C linkage
    620                         if ( decl->get_linkage() == LinkageSpec::C && hasIncompatibleCDecl( name, mangleName ) ) {
     620                        // this ensures that no two declarations with the same unmangled name at the same scope both have C linkage
     621                        if ( decl->get_linkage() == LinkageSpec::C && hasIncompatibleCDecl( name, mangleName, scope ) ) {
    621622                                throw SemanticError( "invalid overload of C function ", decl );
    622623                        } // NOTE this is broken in Richard's original code in such a way that it never triggers (it
     
    783784            using std::cerr;
    784785
    785             cerr << "===idTable===" << std::endl;
    786             if ( tables ) dump( tables->idTable, os );
    787             cerr << "===typeTable===" << std::endl;
    788             if ( tables ) dump( tables->typeTable, os );
    789             cerr << "===structTable===" << std::endl;
    790             if ( tables ) dump( tables->structTable, os );
    791             cerr << "===enumTable===" << std::endl;
    792             if ( tables ) dump( tables->enumTable, os );
    793             cerr << "===unionTable===" << std::endl;
    794             if ( tables ) dump( tables->unionTable, os );
    795             cerr << "===contextTable===" << std::endl;
    796             if ( tables ) dump( tables->traitTable, os );
     786                if ( tables ) {
     787                        os << "--- scope " << tables->scope << " ---" << std::endl;
     788
     789                        os << "===idTable===" << std::endl;
     790                        dump( tables->idTable, os );
     791                        os << "===typeTable===" << std::endl;
     792                        dump( tables->typeTable, os );
     793                        os << "===structTable===" << std::endl;
     794                        dump( tables->structTable, os );
     795                        os << "===enumTable===" << std::endl;
     796                        dump( tables->enumTable, os );
     797                        os << "===unionTable===" << std::endl;
     798                        dump( tables->unionTable, os );
     799                        os << "===contextTable===" << std::endl;
     800                        dump( tables->traitTable, os );
     801
     802                        tables->base.print( os, indent );
     803                } else {
     804                        os << "--- end ---" << std::endl;
     805                }
     806               
    797807        }
    798808} // namespace SymTab
  • src/SymTab/Indexer.h

    rdc2e7e0 rfbfb38e  
    9999                DeclarationWithType *lookupIdAtScope( const std::string &id, const std::string &mangleName, unsigned long scope ) const;
    100100                /// returns true if there exists a declaration with C linkage and the given name with a different mangled name
    101                 bool hasIncompatibleCDecl( const std::string &id, const std::string &mangleName ) const;
     101                bool hasIncompatibleCDecl( const std::string &id, const std::string &mangleName, unsigned long scope ) const;
    102102                // equivalents to lookup functions that only look at tables at scope `scope` (which should be >= tables->scope)
    103103                NamedTypeDecl *lookupTypeAtScope( const std::string &id, unsigned long scope ) const;
  • src/SymTab/Validate.cc

    rdc2e7e0 rfbfb38e  
    515515                                }
    516516                                rtt->get_parameters().clear();
    517                                 cloneAll(typeInst->get_parameters(), rtt->get_parameters());
     517                                cloneAll( typeInst->get_parameters(), rtt->get_parameters() );
     518                                mutateAll( rtt->get_parameters(), *this );  // recursively fix typedefs on parameters
    518519                        } // if
    519520                        delete typeInst;
  • src/driver/cfa.cc

    rdc2e7e0 rfbfb38e  
    1010// Created On       : Tue Aug 20 13:44:49 2002
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr  6 14:04:22 2016
    13 // Update Count     : 132
     12// Last Modified On : Wed Apr 20 18:31:28 2016
     13// Update Count     : 133
    1414//
    1515
     
    310310                        nargs += 1;
    311311                } // if
     312                args[nargs] = "-fgnu89-inline";
     313                nargs += 1;
    312314                args[nargs] = ( *new string( string("-B") + Bprefix + "/" ) ).c_str();
    313315                nargs += 1;
  • src/examples/io.c

    rdc2e7e0 rfbfb38e  
    1111// Created On       : Wed Mar  2 16:56:02 2016
    1212// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Wed Apr  6 14:58:27 2016
    14 // Update Count     : 15
     13// Last Modified On : Wed Apr 13 23:03:14 2016
     14// Update Count     : 22
    1515//
    1616
     
    3636
    3737        ifstream in;                                                                                            // create / open file
    38         open( &in, "input.data", "r" );
     38        open( &in, "io.data", "r" );
    3939
    4040        &in | &c                                                                                                        // character
     
    5959                 | fc | dc | ldc | endl                                                                 // complex without separator
    6060                 | s1 | s2 | endl;
     61        sout | endl;
     62        sepSet( sout, " " );
     63
     64        sout
     65                // opening delimiters
     66                | "v(" | 27
     67                | "v[" | 27
     68                | "v{" | 27
     69                | "$" | 27
     70                | "£" | 27
     71                | "¥" | 27
     72                | "¿" | 27
     73                | "«" | 27
     74                | endl
     75                // closing delimiters
     76                | 25 | ","
     77                | 25 | "."
     78                | 25 | ":"
     79                | 25 | ";"
     80                | 25 | "!"
     81                | 25 | "?"
     82                | 25 | ")"
     83                | 25 | "]"
     84                | 25 | "}"
     85                | 25 | "%"
     86                | 25 | "¢"
     87                | 25 | "»"
     88                | endl
     89                // opening-closing delimiters
     90                | 25 | "'" | 27
     91                | 25 | "`" | 27
     92                | 25 | "\"" | 27
     93                | 25 | "\f" | 27
     94                | 25 | "\n" | 27
     95                | 25 | "\r" | 27
     96                | 25 | "\t" | 27
     97                | 25 | "\v" | 27
     98                | endl;
    6199}
    62100
  • src/examples/swap.c

    rdc2e7e0 rfbfb38e  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 16:15:11 2016
    13 // Update Count     : 65
     12// Last Modified On : Thu Apr 21 08:10:41 2016
     13// Update Count     : 69
    1414//
    1515
     
    2424
    2525        signed int i1 = -1, i2 = -2;
    26         sout | "signed int\t\t" | i1 | ' ' | i2 | "\t\t\tswap ";
     26        sout | "signed int\t\t" | i1 | i2 | "\t\t\tswap ";
    2727        swap( &i1, &i2 );
    28         sout | '\t' | i1 | ' ' | i2 | endl;
     28        sout | '\t' | i1 | i2 | endl;
    2929
    3030        unsigned int ui1 = 1, ui2 = 2;
    31         sout | "unsigned int\t\t" | ui1 | ' ' | ui2 | "\t\t\tswap ";
     31        sout | "unsigned int\t\t" | ui1 | ui2 | "\t\t\tswap ";
    3232        swap( &ui1, &ui2 );
    33         sout | '\t' | ui1 | ' ' | ui2 | endl;
     33        sout | '\t' | ui1 | ui2 | endl;
    3434
    3535        signed long int li1 = -1, li2 = -2;
    36         sout | "signed long int\t\t" | li1 | ' ' | li2 | "\t\t\tswap ";
     36        sout | "signed long int\t\t" | li1 | li2 | "\t\t\tswap ";
    3737        swap( &li1, &li2 );
    38         sout | '\t' | li1 | ' ' | li2 | endl;
     38        sout | '\t' | li1 | li2 | endl;
    3939
    4040        unsigned long int uli1 = 1, uli2 = 2;
    41         sout | "unsigned long int\t" | uli1 | ' ' | uli2 | "\t\t\tswap ";
     41        sout | "unsigned long int\t" | uli1 | uli2 | "\t\t\tswap ";
    4242        swap( &uli1, &uli2 );
    43         sout | '\t' | uli1 | ' ' | uli2 | endl;
     43        sout | '\t' | uli1 | uli2 | endl;
    4444
    4545        signed long long int lli1 = -1, lli2 = -2;
    46         sout | "signed long long int\t" | lli1 | ' ' | lli2 | "\t\t\tswap ";
     46        sout | "signed long long int\t" | lli1 | lli2 | "\t\t\tswap ";
    4747        swap( &lli1, &lli2 );
    48         sout | '\t' | lli1 | ' ' | lli2 | endl;
     48        sout | '\t' | lli1 | lli2 | endl;
    4949
    5050        unsigned long long int ulli1 = 1, ulli2 = 2;
    51         sout | "unsigned long long int\t" | ulli1 | ' ' | ulli2 | "\t\t\tswap ";
     51        sout | "unsigned long long int\t" | ulli1 | ulli2 | "\t\t\tswap ";
    5252        swap( &ulli1, &ulli2 );
    53         sout | '\t' | ulli1 | ' ' | ulli2 | endl;
     53        sout | '\t' | ulli1 | ulli2 | endl;
    5454
    5555        float f1 = 1.5, f2 = 2.5;
    56         sout | "float\t\t\t" | f1 | ' ' | f2 | "\t\tswap ";
     56        sout | "float\t\t\t" | f1 | f2 | "\t\t\tswap ";
    5757        swap( &f1, &f2 );
    58         sout | '\t' | f1 | ' ' | f2 | endl;
     58        sout | '\t' | f1 | f2 | endl;
    5959
    6060        double d1 = 1.5, d2 = 2.5;
    61         sout | "double\t\t\t" | d1 | ' ' | d2 | "\t\tswap ";
     61        sout | "double\t\t\t" | d1 | d2 | "\t\t\tswap ";
    6262        swap( &d1, &d2 );
    63         sout | '\t' | d1 | ' ' | d2 | endl;
     63        sout | '\t' | d1 | d2 | endl;
    6464
    6565        long double ld1 = 1.5, ld2 = 2.5;
    66         sout | "long double\t\t" | ld1 | ' ' | ld2 | "\t\tswap ";
     66        sout | "long double\t\t" | ld1 | ld2 | "\t\t\tswap ";
    6767        swap( &ld1, &ld2 );
    68         sout | '\t' | ld1 | ' ' | ld2 | endl;
     68        sout | '\t' | ld1 | ld2 | endl;
    6969
    7070        float _Complex fc1 = 1.5f+1.5if, fc2 = 2.5f+2.5if;
    71         sout | "float _Complex\t\t" | fc1 | ' ' | fc2 | "\tswap ";
     71        sout | "float _Complex\t\t" | fc1 | fc2 | "\tswap ";
    7272        swap( &fc1, &fc2 );
    73         sout | '\t' | fc1 | ' ' | fc2 | endl;
     73        sout | '\t' | fc1 | fc2 | endl;
    7474
    7575        double _Complex dc1 = 1.5d+1.5id, dc2 = 2.5d+2.5id;
    76         sout | "double _Complex\t\t" | dc1 | ' ' | dc2 | "\tswap ";
     76        sout | "double _Complex\t\t" | dc1 | dc2 | "\tswap ";
    7777        swap( &dc1, &dc2 );
    78         sout | '\t' | dc1 | ' ' | dc2 | endl;
     78        sout | '\t' | dc1 | dc2 | endl;
    7979
    8080        long double _Complex ldc1 = 1.5d+1.5il, ldc2 = 2.5d+2.5il;
    81         sout | "long double _Complex\t" | ldc1 | ' ' | ldc2 | "\tswap ";
     81        sout | "long double _Complex\t" | ldc1 | ldc2 | "\tswap ";
    8282        swap( &ldc1, &ldc2 );
    83         sout | '\t' | ldc1 | ' ' | ldc2 | endl;
     83        sout | '\t' | ldc1 | ldc2 | endl;
    8484
    8585        struct S { int i, j; } s1 = { 1, 2 }, s2 = { 2, 1 };
    86         ofstream * ?|?( ofstream * os, S s ) { return os | s.i | ' ' | s.j; }
    87         sout | "struct S\t\t" | s1 | "  " | s2 | "\t\tswap ";
     86        ofstream * ?|?( ofstream * os, S s ) { return os | s.i | s.j; }
     87        sout | "struct S\t\t" | s1 | "," | s2 | "\t\tswap ";
    8888        swap( &s1, &s2 );
    89         sout | '\t' | s1 | "  " | s2 | endl;
     89        sout | '\t' | s1 | "," | s2 | endl;
    9090} // main
    9191
  • src/libcfa/Makefile.am

    rdc2e7e0 rfbfb38e  
    1111## Created On       : Sun May 31 08:54:01 2015
    1212## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Wed Apr  6 21:10:44 2016
    14 ## Update Count     : 123
     13## Last Modified On : Tue Apr 19 22:30:17 2016
     14## Update Count     : 124
    1515###############################################################################
    1616
     
    6060        ${CC} ${CFLAGS} -c -o $@ $<
    6161
    62 libs = limits stdlib iostream fstream iterator rational
     62libs = limits stdlib math iostream fstream iterator rational
    6363libcfa_a_SOURCES = libcfa-prelude.c ${libs:=.c}
    6464
  • src/libcfa/Makefile.in

    rdc2e7e0 rfbfb38e  
    8383libcfa_a_AR = $(AR) $(ARFLAGS)
    8484libcfa_a_LIBADD =
    85 am__objects_1 = limits.$(OBJEXT) stdlib.$(OBJEXT) iostream.$(OBJEXT) \
    86         fstream.$(OBJEXT) iterator.$(OBJEXT) rational.$(OBJEXT)
     85am__objects_1 = limits.$(OBJEXT) stdlib.$(OBJEXT) math.$(OBJEXT) \
     86        iostream.$(OBJEXT) fstream.$(OBJEXT) iterator.$(OBJEXT) \
     87        rational.$(OBJEXT)
    8788am_libcfa_a_OBJECTS = libcfa-prelude.$(OBJEXT) $(am__objects_1)
    8889libcfa_a_OBJECTS = $(am_libcfa_a_OBJECTS)
     
    213214MAINTAINERCLEANFILES = ${addprefix ${libdir}/,${cfalib_DATA}} \
    214215        ${addprefix ${libdir}/,${lib_LIBRARIES}} ${includedir}/*
    215 libs = limits stdlib iostream fstream iterator rational
     216libs = limits stdlib math iostream fstream iterator rational
    216217libcfa_a_SOURCES = libcfa-prelude.c ${libs:=.c}
    217218cheaders = # expat
     
    299300@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcfa-prelude.Po@am__quote@
    300301@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/limits.Po@am__quote@
     302@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/math.Po@am__quote@
    301303@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rational.Po@am__quote@
    302304@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stdlib.Po@am__quote@
  • src/libcfa/fstream

    rdc2e7e0 rfbfb38e  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Apr  5 22:37:12 2016
    13 // Update Count     : 82
     12// Last Modified On : Tue Apr 19 20:44:10 2016
     13// Update Count     : 84
    1414//
    1515
     
    2222struct ofstream {
    2323        void *file;
    24         _Bool sepDefault;
    25         _Bool sepOnOff;
     24        int sepDefault;
     25        int sepOnOff;
    2626        char separator[separateSize];
    2727}; // ofstream
  • src/libcfa/rational.c

    rdc2e7e0 rfbfb38e  
    1111// Created On       : Wed Apr  6 17:54:28 2016
    1212// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Tue Apr 12 21:26:42 2016
    14 // Update Count     : 21
     13// Last Modified On : Thu Apr 21 07:33:03 2016
     14// Update Count     : 22
    1515//
    1616
     
    1818#include "fstream"
    1919#include "stdlib"
     20#include "math"                                                                                 // floor
    2021
    2122
  • src/libcfa/stdlib

    rdc2e7e0 rfbfb38e  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr 13 14:45:53 2016
    13 // Update Count     : 85
     12// Last Modified On : Thu Apr 21 07:55:21 2016
     13// Update Count     : 95
    1414//
    1515
     
    2828#endif // ! EXIT_FAILURE
    2929void exit( int rc );
     30void abort( void );
    3031} // extern "C"
    3132
    3233//---------------------------------------
    3334
    34 extern "C" {
    35 void * malloc( size_t );                                                                // use default C routine for void *
    36 } // extern "C"
     35extern "C" { void * malloc( size_t ); }                                 // use default C routine for void *
    3736forall( otype T ) T * malloc( void );
    3837forall( otype T ) T * malloc( char fill );
    3938forall( otype T ) T * malloc( T * ptr, size_t size );
    4039forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill );
    41 extern "C" {
    42 void * calloc( size_t nmemb, size_t size );                             // use default C routine for void *
    43 } // extern "C"
     40extern "C" { void * calloc( size_t nmemb, size_t size ); } // use default C routine for void *
    4441forall( otype T ) T * calloc( size_t nmemb );
    45 extern "C" {
    46 void * realloc( void * ptr, size_t size );                              // use default C routine for void *
    47 } // extern "C"
     42extern "C" { void * realloc( void * ptr, size_t size ); } // use default C routine for void *
    4843forall( otype T ) T * realloc( T * ptr, size_t size );
    4944forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill );
    5045
    5146forall( otype T ) T * aligned_alloc( size_t alignment );
    52 forall( otype T ) T * memalign( size_t alignment );             // deprecated
     47forall( otype T ) T * memalign( size_t alignment );
    5348forall( otype T ) int posix_memalign( T ** ptr, size_t alignment );
    5449
    55 forall( otype T ) T * memset( T * ptr, unsigned char fill ); // use default value '\0' for fill
    56 forall( otype T ) T * memset( T * ptr );                                // remove when default value available
     50extern "C" {
     51void * memset( void * ptr, int fill, size_t size );
     52void free( void * ptr );
     53} // extern "C"
    5754
    5855//---------------------------------------
     
    10097
    10198char abs( char );
    102 extern "C" {
    103 int abs( int );                                                                                 // use default C routine for int
    104 } // extern "C"
     99extern "C" { int abs( int ); }                                                  // use default C routine for int
    105100long int abs( long int );
    106101long long int abs( long long int );
     
    108103double abs( double );
    109104long double abs( long double );
    110 float _Complex abs( float _Complex );
    111 double _Complex abs( double _Complex );
    112 long double _Complex abs( long double _Complex );
    113 
    114 //---------------------------------------
    115 
    116 float floor( float );
    117 extern "C" {
    118 double floor( double );                                                                 // use C routine for double
    119 } // extern "C"
    120 long double floor( long double );
    121 
    122 float ceil( float );
    123 extern "C" {
    124 double ceil( double );                                                                  // use C routine for double
    125 } // extern "C"
    126 long double ceil( long double );
     105float abs( float _Complex );
     106double abs( double _Complex );
     107long double abs( long double _Complex );
    127108
    128109//---------------------------------------
  • src/libcfa/stdlib.c

    rdc2e7e0 rfbfb38e  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr 13 14:49:58 2016
    13 // Update Count     : 155
     12// Last Modified On : Thu Apr 21 07:58:29 2016
     13// Update Count     : 165
    1414//
    1515
     
    2424#include <malloc.h>                                                                             // malloc_usable_size
    2525#include <math.h>                                                                               // fabsf, fabs, fabsl
    26 #include <complex.h>                                                                    // _Complex_I, cabsf, cabs, cabsl
     26#include <complex.h>                                                                    // _Complex_I
    2727} // extern "C"
    2828
     
    3434        //printf( "malloc3\n" );
    3535        T * ptr = (T *)malloc( sizeof(T) );
    36     return memset( ptr );
     36    return memset( ptr, (int)fill, sizeof(T) );
    3737} // malloc
    3838
     
    7878} // posix_memalign
    7979
    80 forall( otype T ) T * memset( T * ptr, unsigned char fill ) { // use default value '\0' for fill
    81         //printf( "memset1\n" );
    82     return (T *)memset( ptr, (int)fill, malloc_usable_size( ptr ) );
    83 } // memset
    84 forall( otype T ) T * memset( T * ptr ) {                               // remove when default value available
    85         //printf( "memset2\n" );
    86     return (T *)memset( ptr, 0, malloc_usable_size( ptr ) );
    87 } // memset
    88 
    8980//---------------------------------------
    9081
    9182int ato( const char * ptr ) {
    9283        int i;
    93         if ( sscanf( ptr, "%d", &i ) == EOF ) {}                        // check return code
     84        if ( sscanf( ptr, "%d", &i ) == EOF ) {}
    9485        return i;
    9586}
    9687unsigned int ato( const char * ptr ) {
    9788        unsigned int ui;
    98         if ( sscanf( ptr, "%u", &ui ) == EOF ) {}                       // check return code
     89        if ( sscanf( ptr, "%u", &ui ) == EOF ) {}
    9990        return ui;
    10091}
    10192long int ato( const char * ptr ) {
    10293        long int li;
    103         if ( sscanf( ptr, "%ld", &li ) == EOF ) {}                      // check return code
     94        if ( sscanf( ptr, "%ld", &li ) == EOF ) {}
    10495        return li;
    10596}
    10697unsigned long int ato( const char * ptr ) {
    10798        unsigned long int uli;
    108         if ( sscanf( ptr, "%lu", &uli ) == EOF ) {}                     // check return code
     99        if ( sscanf( ptr, "%lu", &uli ) == EOF ) {}
    109100        return uli;
    110101}
    111102long long int ato( const char * ptr ) {
    112103        long long int lli;
    113         if ( sscanf( ptr, "%lld", &lli ) == EOF ) {}            // check return code
     104        if ( sscanf( ptr, "%lld", &lli ) == EOF ) {}
    114105        return lli;
    115106}
    116107unsigned long long int ato( const char * ptr ) {
    117108        unsigned long long int ulli;
    118         if ( sscanf( ptr, "%llu", &ulli ) == EOF ) {}           // check return code
     109        if ( sscanf( ptr, "%llu", &ulli ) == EOF ) {}
    119110        return ulli;
    120111}
     
    122113float ato( const char * ptr ) {
    123114        float f;
    124         if ( sscanf( ptr, "%f", &f ) == EOF ) {}                        // check return code
     115        if ( sscanf( ptr, "%f", &f ) == EOF ) {}
    125116        return f;
    126117}
    127118double ato( const char * ptr ) {
    128119        double d;
    129         if ( sscanf( ptr, "%lf", &d ) == EOF ) {}                       // check return code
     120        if ( sscanf( ptr, "%lf", &d ) == EOF ) {}
    130121        return d;
    131122}
    132123long double ato( const char * ptr ) {
    133124        long double ld;
    134         if ( sscanf( ptr, "%Lf", &ld ) == EOF ) {}                      // check return code
     125        if ( sscanf( ptr, "%Lf", &ld ) == EOF ) {}
    135126        return ld;
    136127}
     
    138129float _Complex ato( const char * ptr ) {
    139130        float re, im;
    140         if ( sscanf( ptr, "%g%gi", &re, &im ) == EOF ) {}       // check return code
     131        if ( sscanf( ptr, "%g%gi", &re, &im ) == EOF ) {}
    141132        return re + im * _Complex_I;
    142133}
    143134double _Complex ato( const char * ptr ) {
    144135        double re, im;
    145         if ( sscanf( ptr, "%lf%lfi", &re, &im ) == EOF ) {} // check return code
     136        if ( sscanf( ptr, "%lf%lfi", &re, &im ) == EOF ) {}
    146137        return re + im * _Complex_I;
    147138}
    148139long double _Complex ato( const char * ptr ) {
    149140        long double re, im;
    150         if ( sscanf( ptr, "%Lf%Lfi", &re, &im ) == EOF ) {}     // check return code
     141        if ( sscanf( ptr, "%Lf%Lfi", &re, &im ) == EOF ) {}
    151142        return re + im * _Complex_I;
    152143}       
     
    230221long int abs( long int v ) { return labs( v ); }
    231222long long int abs( long long int v ) { return llabs( v ); }
    232 float abs( float v ) { return fabsf( v ); }
    233 double abs( double v ) { return fabs( v ); }
    234 long double abs( long double v ) { return fabsl( v ); }
    235 float _Complex abs( float _Complex v ) { return cabsf( v ); }
    236 double _Complex abs( double _Complex v ) { return cabs( v ); }
    237 long double _Complex abs( long double _Complex v ) { return cabsl( v ); }
    238 
    239 //---------------------------------------
    240 
    241 float floor( float v ) { return floorf( v ); }
    242 long double floor( long double v ) { return floorl( v ); }
    243 
    244 float ceil( float v ) { return ceilf( v ); }
    245 long double ceil( long double v ) { return ceill( v ); }
     223float abs( float x ) { return fabsf( x ); }
     224double abs( double x ) { return fabs( x ); }
     225long double abs( long double x ) { return fabsl( x ); }
     226float abs( float _Complex x ) { return cabsf( x ); }
     227double abs( double _Complex x ) { return cabs( x ); }
     228long double abs( long double _Complex x ) { return cabsl( x ); }
    246229
    247230//---------------------------------------
Note: See TracChangeset for help on using the changeset viewer.