Changeset 0f9e4403 for src/libcfa


Ignore:
Timestamp:
Apr 15, 2016, 12:03:11 PM (10 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
29ad0ac
Parents:
c5833e8 (diff), 37f0da8 (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 gc_noraii

Location:
src/libcfa
Files:
3 added
11 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/Makefile.am

    rc5833e8 r0f9e4403  
    1111## Created On       : Sun May 31 08:54:01 2015
    1212## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Wed Feb  3 11:19:35 2016
    14 ## Update Count     : 117
     13## Last Modified On : Wed Apr  6 21:10:44 2016
     14## Update Count     : 123
    1515###############################################################################
    1616
     
    6060        ${CC} ${CFLAGS} -c -o $@ $<
    6161
    62 libs = stdlib iostream fstream iterator
     62libs = limits stdlib iostream fstream iterator rational
    6363libcfa_a_SOURCES = libcfa-prelude.c ${libs:=.c}
    6464
    65 cheaders = bfd bfdlink demangle dialog evdns evhttp evrpc expat fcntl form gcrypt math
    66 cfaheaders = limits
     65cheaders = # expat
     66cfaheaders = # limits
    6767include_HEADERS = ${cheaders:=.h} ${libs} ${cfaheaders}
    6868
  • src/libcfa/Makefile.in

    rc5833e8 r0f9e4403  
    8383libcfa_a_AR = $(AR) $(ARFLAGS)
    8484libcfa_a_LIBADD =
    85 am__objects_1 = stdlib.$(OBJEXT) iostream.$(OBJEXT) fstream.$(OBJEXT) \
    86         iterator.$(OBJEXT)
     85am__objects_1 = limits.$(OBJEXT) stdlib.$(OBJEXT) iostream.$(OBJEXT) \
     86        fstream.$(OBJEXT) iterator.$(OBJEXT) rational.$(OBJEXT)
    8787am_libcfa_a_OBJECTS = libcfa-prelude.$(OBJEXT) $(am__objects_1)
    8888libcfa_a_OBJECTS = $(am_libcfa_a_OBJECTS)
     
    213213MAINTAINERCLEANFILES = ${addprefix ${libdir}/,${cfalib_DATA}} \
    214214        ${addprefix ${libdir}/,${lib_LIBRARIES}} ${includedir}/*
    215 libs = stdlib iostream fstream iterator
     215libs = limits stdlib iostream fstream iterator rational
    216216libcfa_a_SOURCES = libcfa-prelude.c ${libs:=.c}
    217 cheaders = bfd bfdlink demangle dialog evdns evhttp evrpc expat fcntl form gcrypt math
    218 cfaheaders = limits
     217cheaders = # expat
     218cfaheaders = # limits
    219219include_HEADERS = ${cheaders:=.h} ${libs} ${cfaheaders}
    220220all: all-am
     
    231231          esac; \
    232232        done; \
    233         echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/libcfa/Makefile'; \
     233        echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/libcfa/Makefile'; \
    234234        $(am__cd) $(top_srcdir) && \
    235           $(AUTOMAKE) --gnu src/libcfa/Makefile
     235          $(AUTOMAKE) --foreign src/libcfa/Makefile
    236236.PRECIOUS: Makefile
    237237Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
     
    297297@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/iterator.Po@am__quote@
    298298@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcfa-prelude.Po@am__quote@
     299@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/limits.Po@am__quote@
     300@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rational.Po@am__quote@
    299301@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stdlib.Po@am__quote@
    300302
  • src/libcfa/builtins.cf

    rc5833e8 r0f9e4403  
    390390int __builtin_sprintf(char *, const char *, ...);
    391391int __builtin_sscanf(const char *, const char *, ...);
    392 int __builtin_vfprintf(struct _IO_FILE *, const char *, void **);
    393 int __builtin_vfscanf(struct _IO_FILE *, const char *, void **);
    394 int __builtin_vprintf(const char *, void **);
    395 int __builtin_vscanf(const char *, void **);
    396 int __builtin_vsnprintf(char *, unsigned long, const char *, void **);
    397 int __builtin_vsprintf(char *, const char *, void **);
    398 int __builtin_vsscanf(const char *, const char *, void **);
     392int __builtin_vfprintf(struct _IO_FILE *, const char *, __builtin_va_list);
     393int __builtin_vfscanf(struct _IO_FILE *, const char *, __builtin_va_list);
     394int __builtin_vprintf(const char *, __builtin_va_list);
     395int __builtin_vscanf(const char *, __builtin_va_list);
     396int __builtin_vsnprintf(char *, unsigned long, const char *, __builtin_va_list);
     397int __builtin_vsprintf(char *, const char *, __builtin_va_list);
     398int __builtin_vsscanf(const char *, const char *, __builtin_va_list);
    399399int __builtin_isalnum(int);
    400400int __builtin_isalpha(int);
     
    534534void __builtin_unwind_init();
    535535void __builtin_update_setjmp_buf(void *, int);
    536 void __builtin_va_copy(void **, void **);
    537 void __builtin_va_end(void **);
    538 void __builtin_va_start(void **, ...);
     536void __builtin_va_copy(__builtin_va_list, __builtin_va_list);
     537void __builtin_va_end(__builtin_va_list);
     538void __builtin_va_start(__builtin_va_list, ...);
    539539int __builtin_va_arg_pack();
    540540int __builtin_va_arg_pack_len();
     
    563563int __builtin___snprintf_chk(char *, unsigned long, int, unsigned long, const char *, ...);
    564564int __builtin___sprintf_chk(char *, int, unsigned long, const char *, ...);
    565 int __builtin___vsnprintf_chk(char *, unsigned long, int, unsigned long, const char *, void **);
    566 int __builtin___vsprintf_chk(char *, int, unsigned long, const char *, void **);
     565int __builtin___vsnprintf_chk(char *, unsigned long, int, unsigned long, const char *, __builtin_va_list);
     566int __builtin___vsprintf_chk(char *, int, unsigned long, const char *, __builtin_va_list);
    567567int __builtin___fprintf_chk(struct _IO_FILE *, int, const char *, ...);
    568568int __builtin___printf_chk(int, const char *, ...);
    569 int __builtin___vfprintf_chk(struct _IO_FILE *, int, const char *, void **);
    570 int __builtin___vprintf_chk(int, const char *, void **);
     569int __builtin___vfprintf_chk(struct _IO_FILE *, int, const char *, __builtin_va_list);
     570int __builtin___vprintf_chk(int, const char *, __builtin_va_list);
    571571void __cyg_profile_func_enter(void *, void *);
    572572void __cyg_profile_func_exit(void *, void *);
     
    583583const char * __builtin_FUNCTION();
    584584int __builtin_LINE();
    585 typedef void ** __builtin_va_list;
    586585extern const char *__PRETTY_FUNCTION__;
    587 typedef int wchar_t;
  • src/libcfa/fstream

    rc5833e8 r0f9e4403  
    77// fstream --
    88//
    9 // Author           : Richard C. Bilson
     9// Author           : Peter A. Buhr
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 14:02:01 2016
    13 // Update Count     : 22
     12// Last Modified On : Tue Apr  5 22:37:12 2016
     13// Update Count     : 82
    1414//
    1515
     
    1919#include "iostream"
    2020
    21 // implement context ostream
    22 struct ofstream;
     21enum { separateSize = 16 };
     22struct ofstream {
     23        void *file;
     24        _Bool sepDefault;
     25        _Bool sepOnOff;
     26        char separator[separateSize];
     27}; // ofstream
    2328
    24 int fail( ofstream * os );
    25 int flush( ofstream * os );
    26 void open( ofstream ** os, const char * name, const char * mode );
    27 void close( ofstream * os );
    28 ofstream * write( ofstream * os, const char * data, streamsize_type size );
     29_Bool sepPrt( ofstream * );
     30void sepOn( ofstream * );
     31void sepOff( ofstream * );
     32void sepReset( ofstream * );
     33void sepReset( ofstream *, _Bool );
     34void sepSet( ofstream *, const char * );
     35const char * sepGet( ofstream * );
     36_Bool sepDisable( ofstream * );
     37_Bool sepEnable( ofstream * );
     38int fail( ofstream * );
     39int flush( ofstream * );
     40void open( ofstream *, const char * name, const char * mode );
     41void close( ofstream * );
     42ofstream * write( ofstream *, const char * data, unsigned long int size );
     43int prtfmt( ofstream *, const char fmt[], ... );
    2944
    3045extern ofstream * sout, * serr;
    3146
    3247// implement context istream
    33 struct ifstream;
     48struct ifstream {
     49        void *file;
     50}; // ifstream
    3451
    3552int fail( ifstream * is );
    3653int eof( ifstream * is );
    37 void open( ifstream ** is, const char * name, const char * mode );
     54void open( ifstream * is, const char * name, const char * mode );
    3855void close( ifstream * is );
    39 ifstream * get( ifstream * is, int * data );
    40 ifstream * read( ifstream * is, char * data, streamsize_type size );
     56ifstream * read( ifstream * is, char * data, unsigned long int size );
    4157ifstream * ungetc( ifstream * is, char c );
     58int scanfmt( ifstream *, const char fmt[], ... );
    4259
    4360extern ifstream *sin;
     
    4966// tab-width: 4 //
    5067// End: //
     68
  • src/libcfa/fstream.c

    rc5833e8 r0f9e4403  
    77// fstream.c --
    88//
    9 // Author           : Richard C. Bilson
     9// Author           : Peter A. Buhr
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 14:03:05 2016
    13 // Update Count     : 76
     12// Last Modified On : Wed Apr  6 17:55:27 2016
     13// Update Count     : 176
    1414//
    1515
     
    1717
    1818extern "C" {
    19 #include <stdio.h>
    20 #include <stdlib.h>
     19#include <stdio.h>                                                                              // vfprintf, vfscanf
     20#include <stdlib.h>                                                                             // exit
     21#include <stdarg.h>                                                                             // varargs
     22#include <string.h>                                                                             // strlen
     23#include <float.h>                                                                              // DBL_DIG, LDBL_DIG
     24#include <complex.h>                                                                    // creal, cimag
    2125}
    2226
    23 struct ofstream {
    24         FILE *file;
    25 };
     27#define IO_MSG "I/O error: "
    2628
    27 #define IO_MSG "I/O error "
     29_Bool sepPrt( ofstream * os ) { return os->sepOnOff; }
     30void sepOn( ofstream * os ) { os->sepOnOff = 1; }
     31void sepOff( ofstream * os ) { os->sepOnOff = 0; }
     32void sepReset( ofstream * os ) { os->sepOnOff = os->sepDefault; }
     33void sepReset( ofstream * os, _Bool reset ) { os->sepDefault = reset; os->sepOnOff = os->sepDefault; }
     34void sepSet( ofstream * os, const char * s ) {
     35        strncpy( &(os->separator[0]), s, separateSize - 1 );
     36        os->separator[separateSize - 1] = '\0';
     37} // sepSet
     38const char * sepGet( ofstream * os ) { return &(os->separator[0]); }
     39_Bool sepDisable( ofstream *os ) {
     40        _Bool temp = os->sepDefault;
     41        os->sepDefault = 0;
     42        sepReset( os );
     43        return temp;
     44} // sepDisable
     45_Bool sepEnable( ofstream *os ) {
     46        _Bool temp = os->sepDefault;
     47        os->sepDefault = 1;
     48        sepReset( os );
     49        return temp;
     50} // sepEnable
    2851
    2952int fail( ofstream * os ) {
    30         return ferror( os->file );
     53        return ferror( (FILE *)(os->file) );
    3154} // fail
    3255
    3356int flush( ofstream * os ) {
    34         return fflush( os->file );
     57        return fflush( (FILE *)(os->file) );
    3558} // flush
    3659
    37 void open( ofstream ** os, const char * name, const char * mode ) {
    38         FILE *t = fopen( name, mode );
    39         if ( t == 0 ) {                                                                         // do not change unless successful
    40                 perror( IO_MSG "open output" );
     60void open( ofstream * os, const char * name, const char * mode ) {
     61        FILE *file = fopen( name, mode );
     62        if ( file == 0 ) {                                                                      // do not change unless successful
     63                fprintf( stderr, IO_MSG "open output file \"%s\", ", name );
     64                perror( 0 );
    4165                exit( EXIT_FAILURE );
    4266        } // if
    43         (*os)->file = t;
     67        os->file = file;
     68        sepOff( os );
     69        sepSet( os, " " );
    4470} // open
    4571
    4672void close( ofstream * os ) {
    47         if ( os->file == stdout || os->file == stderr ) return;
     73        if ( (FILE *)(os->file) == stdout || (FILE *)(os->file) == stderr ) return;
    4874
    49         if ( fclose( os->file ) == EOF ) {
     75        if ( fclose( (FILE *)(os->file) ) == EOF ) {
    5076                perror( IO_MSG "close output" );
    5177        } // if
    5278} // close
    5379
    54 ofstream * write( ofstream * os, const char * data, streamsize_type size ) {
     80ofstream * write( ofstream * os, const char * data, unsigned long int size ) {
    5581        if ( fail( os ) ) {
    5682                fprintf( stderr, "attempt write I/O on failed stream\n" );
     
    5884        } // if
    5985
    60         if ( fwrite( data, 1, size, os->file ) != size ) {
     86        if ( fwrite( data, 1, size, (FILE *)(os->file) ) != size ) {
    6187                perror( IO_MSG "write" );
    6288                exit( EXIT_FAILURE );
     
    6591} // write
    6692
    67 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_) };
     93int prtfmt( ofstream * os, const char fmt[], ... ) {
     94    va_list args;
     95
     96    va_start( args, fmt );
     97    int len = vfprintf( (FILE *)(os->file), fmt, args );
     98        if ( len == EOF ) {
     99                if ( ferror( (FILE *)(os->file) ) ) {
     100                        fprintf( stderr, "invalid write\n" );
     101                        exit( EXIT_FAILURE );
     102                } // if
     103        } // if
     104    va_end( args );
     105        return len;
     106} // prtfmt
     107
     108
     109static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), 1, 0, { ' ', '\0' } };
    68110ofstream *sout = &soutFile;
    69 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_) };
     111static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), 1, 0, { ' ', '\0' } };
    70112ofstream *serr = &serrFile;
     113
    71114
    72115//---------------------------------------
    73116
    74 struct ifstream {
    75         FILE *file;
    76 };
    77117
    78118int fail( ifstream * is ) {
    79         return ferror( is->file );
     119        return ferror( (FILE *)(is->file) );
    80120} // fail
    81121
    82122int eof( ifstream * is ) {
    83         return feof( is->file );
     123        return feof( (FILE *)(is->file) );
    84124} // eof
    85125
    86 ifstream * get( ifstream * is, int * data ) {
    87         if ( fscanf( is->file, "%d", data ) == EOF ) {
    88                 if ( ferror( is->file ) ) {
    89                         fprintf( stderr, "invalid int read\n" );
    90                         exit( EXIT_FAILURE );
    91                 } // if
     126void open( ifstream * is, const char * name, const char * mode ) {
     127        FILE *t = fopen( name, mode );
     128        if ( t == 0 ) {                                                                         // do not change unless successful
     129                fprintf( stderr, IO_MSG "open input file \"%s\", ", name );
     130                perror( 0 );
     131                exit( EXIT_FAILURE );
    92132        } // if
    93         return is;
    94 } // read
     133        is->file = t;
     134} // open
    95135
    96 ifstream * read( ifstream * is, char * data, streamsize_type size ) {
     136void close( ifstream * is ) {
     137        if ( (FILE *)(is->file) == stdin ) return;
     138
     139        if ( fclose( (FILE *)(is->file) ) == EOF ) {
     140                perror( IO_MSG "close input" );
     141        } // if
     142} // close
     143
     144ifstream * read( ifstream * is, char * data, unsigned long int size ) {
    97145        if ( fail( is ) ) {
    98146                fprintf( stderr, "attempt read I/O on failed stream\n" );
     
    100148        } // if
    101149
    102         if ( fread( data, size, 1, is->file ) == 0 ) {
     150        if ( fread( data, size, 1, (FILE *)(is->file) ) == 0 ) {
    103151                perror( IO_MSG "read" );
    104152                exit( EXIT_FAILURE );
     
    113161        } // if
    114162
    115         if ( ungetc( c, is->file ) == EOF ) {
     163        if ( ungetc( c, (FILE *)(is->file) ) == EOF ) {
    116164                perror( IO_MSG "ungetc" );
    117165                exit( EXIT_FAILURE );
     
    120168} // ungetc
    121169
    122 void open( ifstream ** is, const char * name, const char * mode ) {
    123         FILE *t = fopen( name, mode );
    124         if ( t == 0 ) {                                                                         // do not change unless successful
    125                 perror( IO_MSG "open input" );
    126                 exit( EXIT_FAILURE );
     170int scanfmt( ifstream * is, const char fmt[], ... ) {
     171    va_list args;
     172
     173    va_start( args, fmt );
     174    int len = vfscanf( (FILE *)(is->file), fmt, args );
     175        if ( len == EOF ) {
     176                if ( ferror( (FILE *)(is->file) ) ) {
     177                        fprintf( stderr, "invalid read\n" );
     178                        exit( EXIT_FAILURE );
     179                } // if
    127180        } // if
    128         (*is)->file = t;
    129 } // open
     181    va_end( args );
     182        return len;
     183} // prtfmt
    130184
    131 void close( ifstream * is ) {
    132         if ( is->file == stdin ) return;
    133 
    134         if ( fclose( is->file ) == EOF ) {
    135                 perror( IO_MSG "close input" );
    136         } // if
    137 } // close
    138185
    139186static ifstream sinFile = { (FILE *)(&_IO_2_1_stdin_) };
     
    142189// Local Variables: //
    143190// tab-width: 4 //
    144 // compile-command: "cfa fstream.c" //
    145191// End: //
  • src/libcfa/iostream

    rc5833e8 r0f9e4403  
    77// iostream --
    88//
    9 // Author           : Richard C. Bilson
     9// Author           : Peter A. Buhr
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 14:04:24 2016
    13 // Update Count     : 32
     12// Last Modified On : Sun Apr 10 23:00:12 2016
     13// Update Count     : 92
    1414//
    1515
    16 #ifndef IOSTREAM_H
    17 #define IOSTREAM_H
     16#ifndef __IOSTREAM_H__
     17#define __IOSTREAM_H__
    1818
    1919#include "iterator"
    2020
    21 typedef unsigned long streamsize_type;
     21trait ostream( dtype ostype ) {
     22        _Bool sepPrt( ostype * );                                                       // return separator state (on/off)
     23        void sepOn( ostype * );                                                         // turn separator state on
     24        void sepOff( ostype * );                                                        // turn separator state off
     25        void sepReset( ostype * );                                                      // set separator state to default state
     26        void sepReset( ostype *, _Bool );                                       // set separator and default state
     27        void sepSet( ostype *, const char * );                          // set separator to string (15 character maximum)
     28        const char * sepGet( ostype * );                                        // get separator string
     29        _Bool sepDisable( ostype * );                                           // set default state to off, and return previous state
     30        _Bool sepEnable( ostype * );                                            // set default state to on, and return previous state
    2231
    23 context ostream( dtype ostype ) {
    2432        int fail( ostype * );
    2533        int flush( ostype * );
    26         ostype * write( ostype *, const char *, streamsize_type );
     34        void open( ostype * os, const char * name, const char * mode );
     35        void close( ostype * os );
     36        ostype * write( ostype *, const char *, unsigned long int );
     37        int prtfmt( ostype *, const char fmt[], ... );
    2738};
    28 context writeable( type T ) {
     39
     40trait writeable( otype T ) {
    2941        forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, T );
    3042};
     
    3345
    3446forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, char );
     47
     48forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, short int );
     49forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned short int );
    3550forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, int );
    3651forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned int );
     
    3954forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned long int );
    4055forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned long long int );
     56
    4157forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, float ); // FIX ME: should not be required
    4258forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, double );
    4359forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, long double );
     60
    4461forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, float _Complex );
    4562forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, double _Complex );
    4663forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, long double _Complex );
     64
    4765forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, const char * );
    4866forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, const void * );
    4967
    50 forall( dtype ostype, dtype retostype | ostream( ostype ) | ostream( retostype ) ) retostype * ?|?( ostype *os, retostype * (* manip)(ostype*) );
     68forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, ostype * (*)( ostype * ) );
    5169forall( dtype ostype | ostream( ostype ) ) ostype * endl( ostype * );
     70forall( dtype ostype | ostream( ostype ) ) ostype * sepOn( ostype * );
     71forall( dtype ostype | ostream( ostype ) ) ostype * sepOff( ostype * );
     72forall( dtype ostype | ostream( ostype ) ) ostype * sepDisable( ostype * );
     73forall( dtype ostype | ostream( ostype ) ) ostype * sepEnable( ostype * );
    5274
    5375// writes the range [begin, end) to the given stream
    54 forall( type elt_type | writeable( elt_type ), type iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) )
     76forall( otype elt_type | writeable( elt_type ), otype iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) )
    5577void write( iterator_type begin, iterator_type end, os_type *os );
    5678
    57 forall( type elt_type | writeable( elt_type ), type iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) )
     79forall( otype elt_type | writeable( elt_type ), otype iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) )
    5880void write_reverse( iterator_type begin, iterator_type end, os_type *os );
    5981
    6082//---------------------------------------
    6183
    62 context istream( dtype istype ) {
     84trait istream( dtype istype ) {
    6385        int fail( istype * );
    6486        int eof( istype * );
    65         istype * get( istype *, int * );
    66         istype * read( istype *, char *, streamsize_type );
     87        void open( istype * is, const char * name, const char * mode );
     88        void close( istype * is );
     89        istype * read( istype *, char *, unsigned long int );
    6790        istype * ungetc( istype *, char );
     91        int scanfmt( istype *, const char fmt[], ... );
    6892};
    6993
    70 context readable( type T ) {
     94trait readable( otype T ) {
    7195        forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, T );
    7296};
    7397
    74 forall( dtype istype | istream( istype ) )
    75 istype * ?|?( istype *, char * );
     98forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, char * );
    7699
    77 forall( dtype istype | istream( istype ) )
    78 istype * ?|?( istype *, int * );
     100forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, short int * );
     101forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned short int * );
     102forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, int * );
     103forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned int * );
     104forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long int * );
     105forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long long int * );
     106forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned long int * );
     107forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned long long int * );
    79108
    80 #endif // IOSTREAM_H
     109forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, float * );
     110forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, double * );
     111forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long double * );
     112
     113forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, float _Complex * );
     114forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, double _Complex * );
     115forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long double _Complex * );
     116
     117struct _Istream_cstrUC { char * s; };
     118_Istream_cstrUC cstr( char * );
     119forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, _Istream_cstrUC );
     120
     121struct _Istream_cstrC { char * s; int size; };
     122_Istream_cstrC cstr( char *, int size );
     123forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, _Istream_cstrC );
     124
     125#endif // __IOSTREAM_H__
    81126
    82127// Local Variables: //
  • src/libcfa/iostream.c

    rc5833e8 r0f9e4403  
    77// iostream.c --
    88//
    9 // Author           : Richard C. Bilson
     9// Author           : Peter A. Buhr
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 14:19:56 2016
    13 // Update Count     : 76
     12// Last Modified On : Wed Apr  6 16:13:29 2016
     13// Update Count     : 278
    1414//
    1515
     
    2121#include <float.h>                                                                              // DBL_DIG, LDBL_DIG
    2222#include <complex.h>                                                                    // creal, cimag
     23#include <ctype.h>                                                                              // isspace, ispunct
    2324}
    2425
    2526forall( dtype ostype | ostream( ostype ) )
    2627ostype * ?|?( ostype *os, char c ) {
    27         return write( os, &c, 1 );
     28        prtfmt( os, "%c", c );
     29        sepOff( os );
     30        return os;
     31} // ?|?
     32
     33forall( dtype ostype | ostream( ostype ) )
     34ostype * ?|?( ostype *os, short int si ) {
     35        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     36        sepReset( os );
     37        prtfmt( os, "%hd", si );
     38        return os;
     39} // ?|?
     40
     41forall( dtype ostype | ostream( ostype ) )
     42ostype * ?|?( ostype *os, unsigned short int usi ) {
     43        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     44        sepReset( os );
     45        prtfmt( os, "%hu", usi );
     46        return os;
    2847} // ?|?
    2948
    3049forall( dtype ostype | ostream( ostype ) )
    3150ostype * ?|?( ostype *os, int i ) {
    32         char buffer[32];
    33         return write( os, buffer, sprintf( buffer, "%d", i ) );
    34 } // ?|?
    35 
    36 forall( dtype ostype | ostream( ostype ) )
    37 ostype * ?|?( ostype *os, unsigned int i ) {
    38         char buffer[32];
    39         return write( os, buffer, sprintf( buffer, "%u", i ) );
    40 } // ?|?
    41 
    42 forall( dtype ostype | ostream( ostype ) )
    43 ostype * ?|?( ostype *os, long int i ) {
    44         char buffer[32];
    45         return write( os, buffer, sprintf( buffer, "%ld", i ) );
    46 } // ?|?
    47 
    48 forall( dtype ostype | ostream( ostype ) )
    49 ostype * ?|?( ostype *os, long long int i ) {
    50         char buffer[32];
    51         return write( os, buffer, sprintf( buffer, "%lld", i ) );
    52 } // ?|?
    53 
    54 forall( dtype ostype | ostream( ostype ) )
    55 ostype * ?|?( ostype *os, unsigned long int i ) {
    56         char buffer[32];
    57         return write( os, buffer, sprintf( buffer, "%lu", i ) );
    58 } // ?|?
    59 
    60 forall( dtype ostype | ostream( ostype ) )
    61 ostype * ?|?( ostype *os, unsigned long long int i ) {
    62         char buffer[32];
    63         return write( os, buffer, sprintf( buffer, "%llu", i ) );
     51        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     52        sepReset( os );
     53        prtfmt( os, "%d", i );
     54        return os;
     55} // ?|?
     56
     57forall( dtype ostype | ostream( ostype ) )
     58ostype * ?|?( ostype *os, unsigned int ui ) {
     59        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     60        sepReset( os );
     61        prtfmt( os, "%u", ui );
     62        return os;
     63} // ?|?
     64
     65forall( dtype ostype | ostream( ostype ) )
     66ostype * ?|?( ostype *os, long int li ) {
     67        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     68        sepReset( os );
     69        prtfmt( os, "%ld", li );
     70        return os;
     71} // ?|?
     72
     73forall( dtype ostype | ostream( ostype ) )
     74ostype * ?|?( ostype *os, unsigned long int uli ) {
     75        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     76        sepReset( os );
     77        prtfmt( os, "%lu", uli );
     78        return os;
     79} // ?|?
     80
     81forall( dtype ostype | ostream( ostype ) )
     82ostype * ?|?( ostype *os, long long int lli ) {
     83        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     84        sepReset( os );
     85        prtfmt( os, "%lld", lli );
     86        return os;
     87} // ?|?
     88
     89forall( dtype ostype | ostream( ostype ) )
     90ostype * ?|?( ostype *os, unsigned long long int ulli ) {
     91        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     92        sepReset( os );
     93        prtfmt( os, "%llu", ulli );
     94        return os;
    6495} // ?|?
    6596
    6697forall( dtype ostype | ostream( ostype ) )
    6798ostype * ?|?( ostype *os, float f ) {
    68         char buffer[32];
    69         return write( os, buffer, sprintf( buffer, "%g", f ) );
     99        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     100        sepReset( os );
     101        prtfmt( os, "%g", f );
     102        return os;
    70103} // ?|?
    71104
    72105forall( dtype ostype | ostream( ostype ) )
    73106ostype * ?|?( ostype *os, double d ) {
    74         char buffer[32];
    75         return write( os, buffer, sprintf( buffer, "%.*lg", DBL_DIG, d ) );
    76 } // ?|?
    77 
    78 forall( dtype ostype | ostream( ostype ) )
    79 ostype * ?|?( ostype *os, long double d ) {
    80         char buffer[32];
    81         return write( os, buffer, sprintf( buffer, "%.*Lg", LDBL_DIG, d ) );
    82 } // ?|?
    83 
    84 forall( dtype ostype | ostream( ostype ) )
    85 ostype * ?|?( ostype *os, float _Complex c ) {
    86         return os | crealf( c ) | (cimagf( c ) < 0 ? "" : "+") | cimagf( c ) | 'i';
    87 } // ?|?
    88 
    89 forall( dtype ostype | ostream( ostype ) )
    90 ostype * ?|?( ostype *os, double _Complex c ) {
    91         return os | creal( c ) | (cimag( c ) < 0 ? "" : "+") | cimag( c ) | 'i';
    92 } // ?|?
    93 
    94 forall( dtype ostype | ostream( ostype ) )
    95 ostype * ?|?( ostype *os, long double _Complex c ) {
    96         return os | creall( c ) | (cimagl( c ) < 0 ? "" : "+") | cimagl( c ) | 'i';
     107        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     108        sepReset( os );
     109        prtfmt( os, "%.*lg", DBL_DIG, d );
     110        return os;
     111} // ?|?
     112
     113forall( dtype ostype | ostream( ostype ) )
     114ostype * ?|?( ostype *os, long double ld ) {
     115        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     116        sepReset( os );
     117        prtfmt( os, "%.*Lg", LDBL_DIG, ld );
     118        return os;
     119} // ?|?
     120
     121forall( dtype ostype | ostream( ostype ) )
     122ostype * ?|?( ostype *os, float _Complex fc ) {
     123        os | crealf( fc );
     124        _Bool temp = sepDisable( os );                                          // disable separators within complex value
     125        if ( cimagf( fc ) >= 0 ) os | '+';                                      // negative value prints '-'
     126        os | cimagf( fc ) | 'i';
     127        sepReset( os, temp );                                                           // reset separator
     128        return os;
     129} // ?|?
     130
     131forall( dtype ostype | ostream( ostype ) )
     132ostype * ?|?( ostype *os, double _Complex dc ) {
     133        os | creal( dc );
     134        _Bool temp = sepDisable( os );                                          // disable separators within complex value
     135        if ( cimag( dc ) >= 0 ) os | '+';                                       // negative value prints '-'
     136        os | cimag( dc ) | 'i';
     137        sepReset( os, temp );                                                           // reset separator
     138        return os;
     139} // ?|?
     140
     141forall( dtype ostype | ostream( ostype ) )
     142ostype * ?|?( ostype *os, long double _Complex ldc ) {
     143        os | creall( ldc );
     144        _Bool temp = sepDisable( os );                                          // disable separators within complex value
     145        if ( cimagl( ldc ) >= 0 ) os | '+';                                     // negative value prints '-'
     146        os | cimagl( ldc ) | 'i';
     147        sepReset( os, temp );                                                           // reset separator
     148        return os;
     149} // ?|?
     150
     151forall( dtype ostype | ostream( ostype ) )
     152ostype * ?|?( ostype *os, const char *cp ) {
     153        enum { Open = 1, Close, OpenClose };
     154        static const unsigned char mask[256] = {
     155                // opening delimiters
     156                ['('] : Open, ['['] : Open, ['{'] : Open,
     157                ['$'] : Open, [(unsigned char)'£'] : Open, [(unsigned char)'¥'] : Open, [(unsigned char)'¿'] : Open, [(unsigned char)'«'] : Open,
     158                // closing delimiters
     159                [','] : Close, ['.'] : Close, [':'] : Close, [';'] : Close, ['!'] : Close, ['?'] : Close,
     160                [')'] : Close, [']'] : Close, ['}'] : Close,
     161                ['%'] : Close, [(unsigned char)'¢'] : Close, [(unsigned char)'»'] : Close,
     162                // opening-closing delimiters
     163                ['\''] : OpenClose, ['`'] : OpenClose, ['"'] : OpenClose,
     164                ['\f'] : OpenClose, ['\n'] : OpenClose, ['\r'] : OpenClose, ['\t'] : OpenClose, ['\v'] : OpenClose, // isspace
     165        }; // mask
     166
     167        int len = strlen( cp );
     168        // null string => no separator
     169  if ( len == 0 ) { sepOff( os ); return os; }
     170        // first character IS NOT spacing or closing punctuation => add left separator
     171        unsigned char ch = cp[0];                                                       // must make unsigned
     172        if ( sepPrt( os ) && mask[ ch ] != Close && mask[ ch ] != OpenClose ) {
     173                prtfmt( os, "%s", sepGet( os ) );
     174        } // if
     175        // last character IS spacing or opening punctuation => turn off separator for next item
     176        unsigned int posn = len - 1;
     177        ch = cp[posn];                                                                          // must make unsigned
     178        if ( mask[ ch ] == Open || mask[ ch ] == OpenClose ) {
     179                sepOff( os );
     180        } else {
     181                sepOn( os );
     182        } // if
     183        return write( os, cp, len );
    97184} // ?|?
    98185
    99186forall( dtype ostype | ostream( ostype ) )
    100187ostype * ?|?( ostype *os, const void *p ) {
    101         char buffer[32];
    102         return write( os, buffer, sprintf( buffer, "%p", p ) );
    103 } // ?|?
    104 
    105 forall( dtype ostype | ostream( ostype ) )
    106 ostype * ?|?( ostype *os, const char *cp ) {
    107         return write( os, cp, strlen( cp ) );
    108 } // ?|?
    109 
    110 
    111 forall( dtype ostype, dtype retostype | ostream( ostype ) | ostream( retostype ) )
    112 retostype * ?|?( ostype *os, retostype * (*manip)(ostype*) ) {
    113   return manip( os );
    114 }
     188        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     189        sepReset( os );
     190        prtfmt( os, "%p", p );
     191        return os;
     192} // ?|?
     193
     194
     195forall( dtype ostype | ostream( ostype ) )
     196ostype * ?|?( ostype *os, ostype * (* manip)( ostype * ) ) {
     197        return manip( os );
     198} // ?|?
    115199
    116200forall( dtype ostype | ostream( ostype ) )
    117201ostype * endl( ostype * os ) {
    118         os | "\n";
     202        os | '\n';
    119203        flush( os );
     204        sepOff( os );
    120205        return os;
    121206} // endl
    122207
     208forall( dtype ostype | ostream( ostype ) )
     209ostype * sepOn( ostype * os ) {
     210        sepOn( os );
     211        return os;
     212} // sepOn
     213
     214forall( dtype ostype | ostream( ostype ) )
     215ostype * sepOff( ostype * os ) {
     216        sepOff( os );
     217        return os;
     218} // sepOff
     219
     220forall( dtype ostype | ostream( ostype ) )
     221ostype * sepEnable( ostype * os ) {
     222        sepEnable( os );
     223        return os;
     224} // sepEnable
     225
     226forall( dtype ostype | ostream( ostype ) )
     227ostype * sepDisable( ostype * os ) {
     228        sepDisable( os );
     229        return os;
     230} // sepDisable
     231
    123232//---------------------------------------
    124233
    125 forall( type elt_type | writeable( elt_type ), type iterator_type | iterator( iterator_type, elt_type ),
    126                 dtype os_type | ostream( os_type ) )
    127 void write( iterator_type begin, iterator_type end, os_type *os ) {
    128         void print( elt_type i ) { os | i | ' '; }
     234forall( otype elttype | writeable( elttype ), otype iteratortype | iterator( iteratortype, elttype ), dtype ostype | ostream( ostype ) )
     235void write( iteratortype begin, iteratortype end, ostype *os ) {
     236        void print( elttype i ) { os | i; }
    129237        for_each( begin, end, print );
    130238} // ?|?
    131239
    132 forall( type elt_type | writeable( elt_type ), type iterator_type | iterator( iterator_type, elt_type ),
    133                 dtype os_type | ostream( os_type ) )
    134 void write_reverse( iterator_type begin, iterator_type end, os_type *os ) {
    135         void print( elt_type i ) { os | i | ' '; }
     240forall( otype elttype | writeable( elttype ), otype iteratortype | iterator( iteratortype, elttype ), dtype ostype | ostream( ostype ) )
     241void write_reverse( iteratortype begin, iteratortype end, ostype *os ) {
     242        void print( elttype i ) { os | i; }
    136243        for_each_reverse( begin, end, print );
    137244} // ?|?
     
    140247
    141248forall( dtype istype | istream( istype ) )
    142 istype * ?|?( istype *is, char *cp ) {
    143         return read( is, cp, 1 );
    144 } // ?|?
    145 
    146 forall( dtype istype | istream( istype ) )
    147 istype * ?|?( istype *is, int *ip ) {
    148         return get( is, ip );
    149 } // ?|?
     249istype * ?|?( istype * is, char * c ) {
     250        scanfmt( is, "%c", c );
     251        return is;
     252} // ?|?
     253
     254forall( dtype istype | istream( istype ) )
     255istype * ?|?( istype * is, short int * si ) {
     256        scanfmt( is, "%hd", si );
     257        return is;
     258} // ?|?
     259
     260forall( dtype istype | istream( istype ) )
     261istype * ?|?( istype * is, unsigned short int * usi ) {
     262        scanfmt( is, "%hu", usi );
     263        return is;
     264} // ?|?
     265
     266forall( dtype istype | istream( istype ) )
     267istype * ?|?( istype * is, int * i ) {
     268        scanfmt( is, "%d", i );
     269        return is;
     270} // ?|?
     271
     272forall( dtype istype | istream( istype ) )
     273istype * ?|?( istype * is, unsigned int * ui ) {
     274        scanfmt( is, "%u", ui );
     275        return is;
     276} // ?|?
     277
     278forall( dtype istype | istream( istype ) )
     279istype * ?|?( istype * is, long int * li ) {
     280        scanfmt( is, "%ld", li );
     281        return is;
     282} // ?|?
     283
     284forall( dtype istype | istream( istype ) )
     285istype * ?|?( istype * is, unsigned long int * ulli ) {
     286        scanfmt( is, "%lu", ulli );
     287        return is;
     288} // ?|?
     289
     290forall( dtype istype | istream( istype ) )
     291istype * ?|?( istype * is, long long int * lli ) {
     292        scanfmt( is, "%lld", lli );
     293        return is;
     294} // ?|?
     295
     296forall( dtype istype | istream( istype ) )
     297istype * ?|?( istype * is, unsigned long long int * ulli ) {
     298        scanfmt( is, "%llu", ulli );
     299        return is;
     300} // ?|?
     301
     302
     303forall( dtype istype | istream( istype ) )
     304istype * ?|?( istype * is, float * f ) {
     305        scanfmt( is, "%f", f );
     306        return is;
     307} // ?|?
     308
     309forall( dtype istype | istream( istype ) )
     310istype * ?|?( istype * is, double * d ) {
     311        scanfmt( is, "%lf", d );
     312        return is;
     313} // ?|?
     314
     315forall( dtype istype | istream( istype ) )
     316istype * ?|?( istype * is, long double * ld ) {
     317        scanfmt( is, "%Lf", ld );
     318        return is;
     319} // ?|?
     320
     321
     322forall( dtype istype | istream( istype ) )
     323istype * ?|?( istype * is, float _Complex * fc ) {
     324        float re, im;
     325        scanfmt( is, "%g%gi", &re, &im );
     326        *fc = re + im * _Complex_I;
     327        return is;
     328} // ?|?
     329
     330forall( dtype istype | istream( istype ) )
     331istype * ?|?( istype * is, double _Complex * dc ) {
     332        double re, im;
     333        scanfmt( is, "%lf%lfi", &re, &im );
     334        *dc = re + im * _Complex_I;
     335        return is;
     336} // ?|?
     337
     338forall( dtype istype | istream( istype ) )
     339istype * ?|?( istype * is, long double _Complex * ldc ) {
     340        long double re, im;
     341        scanfmt( is, "%Lf%Lfi", &re, &im );
     342        *ldc = re + im * _Complex_I;
     343        return is;
     344} // ?|?
     345
     346_Istream_cstrUC cstr( char * s ) { _Istream_cstrUC s = { s }; return s; }
     347forall( dtype istype | istream( istype ) )
     348istype * ?|?( istype * is, _Istream_cstrUC cstr ) {
     349        scanfmt( is, "%s", cstr.s );
     350        return is;
     351} // cstr
     352
     353_Istream_cstrC cstr( char * s, int size ) { _Istream_cstrC s = { s, size }; return s; }
     354forall( dtype istype | istream( istype ) )
     355istype * ?|?( istype * is, _Istream_cstrC cstr ) {
     356        char buf[16];
     357        sprintf( buf, "%%%ds", cstr.size );
     358        scanfmt( is, buf, cstr.s );
     359        return is;
     360} // cstr
    150361
    151362// Local Variables: //
  • src/libcfa/iterator

    rc5833e8 r0f9e4403  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jan 27 23:49:13 2016
    13 // Update Count     : 7
     12// Last Modified On : Wed Mar  2 18:06:05 2016
     13// Update Count     : 9
    1414//
    1515
     
    1818
    1919// An iterator can be used to traverse a data structure.
    20 context iterator( type iterator_type, type elt_type ) {
     20trait iterator( otype iterator_type, otype elt_type ) {
    2121        // point to the next element
    2222//      iterator_type ?++( iterator_type * );
     
    3232};
    3333
    34 context iterator_for( type iterator_type, type collection_type, type elt_type | iterator( iterator_type, elt_type ) ) {
     34trait iterator_for( otype iterator_type, otype collection_type, otype elt_type | iterator( iterator_type, elt_type ) ) {
    3535//      [ iterator_type begin, iterator_type end ] get_iterators( collection_type );
    3636        iterator_type begin( collection_type );
     
    3838};
    3939
    40 forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) )
     40forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) )
    4141void for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) );
    4242
    43 forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) )
     43forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) )
    4444void for_each_reverse( iterator_type begin, iterator_type end, void (*func)( elt_type ) );
    4545
  • src/libcfa/iterator.c

    rc5833e8 r0f9e4403  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jan 26 17:16:07 2016
    13 // Update Count     : 26
     12// Last Modified On : Wed Mar  2 18:08:11 2016
     13// Update Count     : 27
    1414//
    1515
    1616#include "iterator"
    1717
    18 forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) )
     18forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) )
    1919void for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) ) {
    2020        for ( iterator_type i = begin; i != end; ++i ) {
     
    2323}
    2424
    25 forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) )
     25forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) )
    2626void for_each_reverse( iterator_type begin, iterator_type end, void (*func)( elt_type ) ) {
    2727        for ( iterator_type i = end; i != begin; ) {
  • src/libcfa/limits

    rc5833e8 r0f9e4403  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// limits --
     8//
     9// Author           : Peter A. Buhr
     10// Created On       : Wed Apr  6 18:06:52 2016
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Apr  6 21:08:16 2016
     13// Update Count     : 6
     14//
     15
    116// Integral Constants
    217
    3 const short int MIN = -32768;
    4 const int MIN = -2147483648;
    5 const long int MIN = -9223372036854775807L - 1L;
    6 const long long int MIN = -9223372036854775807LL - 1LL;
     18extern const short int MIN;
     19extern const int MIN;
     20extern const long int MIN;
     21extern const long long int MIN;
    722
    8 const short int MAX = 32767;
    9 const unsigned short int MAX = 65535;
    10 const int MAX = 2147483647;
    11 const unsigned int MAX = 4294967295_U;
    12 const long int MAX = 9223372036854775807_L;
    13 const unsigned long int MAX = 4294967295_U;
    14 const long long int MAX = 9223372036854775807_LL;
    15 const unsigned long long int MAX = 18446744073709551615_ULL;
     23extern const short int MAX;
     24extern const unsigned short int MAX;
     25extern const int MAX;
     26extern const unsigned int MAX;
     27extern const long int MAX;
     28extern const unsigned long int MAX;
     29extern const long long int MAX;
     30extern const unsigned long long int MAX;
    1631
    1732// Floating-Point Constants
    1833
    19 const float PI = 3.141592_F;                            // pi
    20 const float PI_2 = 1.570796_F;                          // pi / 2
    21 const float PI_4 = 0.7853981_F;                         // pi / 4
    22 const float _1_PI = 0.3183098_F;                        // 1 / pi
    23 const float _2_PI = 0.6366197_F;                        // 2 / pi
    24 const float _2_SQRT_PI = 1.128379_F;                    // 2 / sqrt(pi)
     34extern const float PI;                                                                  // pi
     35extern const float PI_2;                                                                // pi / 2
     36extern const float PI_4;                                                                // pi / 4
     37extern const float _1_PI;                                                               // 1 / pi
     38extern const float _2_PI;                                                               // 2 / pi
     39extern const float _2_SQRT_PI;                                                  // 2 / sqrt(pi)
    2540
    26 const double PI = 3.14159265358979323846_D;             // pi
    27 const double PI_2 = 1.57079632679489661923_D;           // pi / 2
    28 const double PI_4 = 0.78539816339744830962_D;           // pi / 4
    29 const double _1_PI = 0.31830988618379067154_D;          // 1 / pi
    30 const double _2_PI = 0.63661977236758134308_D;          // 2 / pi
    31 const double _2_SQRT_PI = 1.12837916709551257390_D;     // 2 / sqrt(pi)
     41extern const double PI;                                                                 // pi
     42extern const double PI_2;                                                               // pi / 2
     43extern const double PI_4;                                                               // pi / 4
     44extern const double _1_PI;                                                              // 1 / pi
     45extern const double _2_PI;                                                              // 2 / pi
     46extern const double _2_SQRT_PI;                                                 // 2 / sqrt(pi)
    3247
    33 const long double PI = 3.1415926535897932384626433832795029_DL; // pi
    34 const long double PI_2 = 1.5707963267948966192313216916397514_DL; // pi / 2
    35 const long double PI_4 = 0.7853981633974483096156608458198757_DL; // pi / 4
    36 const long double _1_PI = 0.3183098861837906715377675267450287_DL; // 1 / pi
    37 const long double _2_PI = 0.6366197723675813430755350534900574_DL; // 2 / pi
    38 const long double _2_SQRT_PI = 1.1283791670955125738961589031215452_DL; // 2 / sqrt(pi)
     48extern const long double PI;                                                    // pi
     49extern const long double PI_2;                                                  // pi / 2
     50extern const long double PI_4;                                                  // pi / 4
     51extern const long double _1_PI;                                                 // 1 / pi
     52extern const long double _2_PI;                                                 // 2 / pi
     53extern const long double _2_SQRT_PI;                                    // 2 / sqrt(pi)
    3954
    40 const _Complex PI = 3.14159265358979323846_D+0.0_iD;    // pi
    41 const _Complex PI_2 = 1.57079632679489661923_D+0.0_iD;  // pi / 2
    42 const _Complex PI_4 = 0.78539816339744830962_D+0.0_iD;  // pi / 4
    43 const _Complex _1_PI = 0.31830988618379067154_D+0.0_iD; // 1 / pi
    44 const _Complex _2_PI = 0.63661977236758134308_D+0.0_iD; // 2 / pi
    45 const _Complex _2_SQRT_PI = 1.12837916709551257390_D+0.0_iD; // 2 / sqrt(pi)
     55extern const _Complex PI;                                                               // pi
     56extern const _Complex PI_2;                                                             // pi / 2
     57extern const _Complex PI_4;                                                             // pi / 4
     58extern const _Complex _1_PI;                                                    // 1 / pi
     59extern const _Complex _2_PI;                                                    // 2 / pi
     60extern const _Complex _2_SQRT_PI;                                               // 2 / sqrt(pi)
    4661
    47 const long _Complex PI = 3.1415926535897932384626433832795029_L+0.0iL; // pi
    48 const long _Complex PI_2 = 1.5707963267948966192313216916397514_L+0.0iL; // pi / 2
    49 const long _Complex PI_4 = 0.7853981633974483096156608458198757_L+0.0iL; // pi / 4
    50 const long _Complex _1_PI = 0.3183098861837906715377675267450287_L+0.0iL; // 1 / pi
    51 const long _Complex _2_PI = 0.6366197723675813430755350534900574_L+0.0iL; // 2 / pi
    52 const long _Complex _2_SQRT_PI = 1.1283791670955125738961589031215452_L+0.0iL; // 2 / sqrt(pi)
     62extern const long _Complex PI;                                                  // pi
     63extern const long _Complex PI_2;                                                // pi / 2
     64extern const long _Complex PI_4;                                                // pi / 4
     65extern const long _Complex _1_PI;                                               // 1 / pi
     66extern const long _Complex _2_PI;                                               // 2 / pi
     67extern const long _Complex _2_SQRT_PI;                                  // 2 / sqrt(pi)
    5368
    54 const float E = 2.718281;                               // e
    55 const float LOG2_E = 1.442695;                          // log_2(e)
    56 const float LOG10_E = 0.4342944;                        // log_10(e)
    57 const float LN_2 = 0.6931471;                           // log_e(2)
    58 const float LN_10 = 2.302585;                           // log_e(10)
    59 const float SQRT_2 = 1.414213;                          // sqrt(2)
    60 const float _1_SQRT_2 = 0.7071067;                      // 1 / sqrt(2)
     69extern const float E;                                                                   // e
     70extern const float LOG2_E;                                                              // log_2(e)
     71extern const float LOG10_E;                                                             // log_10(e)
     72extern const float LN_2;                                                                // log_e(2)
     73extern const float LN_10;                                                               // log_e(10)
     74extern const float SQRT_2;                                                              // sqrt(2)
     75extern const float _1_SQRT_2;                                                   // 1 / sqrt(2)
    6176
    62 const double E = 2.7182818284590452354_D;               // e
    63 const double LOG2_E = 1.4426950408889634074_D;          // log_2(e)
    64 const double LOG10_E = 0.43429448190325182765_D;        // log_10(e)
    65 const double LN_2 = 0.69314718055994530942_D;           // log_e(2)
    66 const double LN_10 = 2.30258509299404568402_D;          // log_e(10)
    67 const double SQRT_2 = 1.41421356237309504880_D;         // sqrt(2)
    68 const double _1_SQRT_2 = 0.70710678118654752440_D;      // 1 / sqrt(2)
     77extern const double E;                                                                  // e
     78extern const double LOG2_E;                                                             // log_2(e)
     79extern const double LOG10_E;                                                    // log_10(e)
     80extern const double LN_2;                                                               // log_e(2)
     81extern const double LN_10;                                                              // log_e(10)
     82extern const double SQRT_2;                                                             // sqrt(2)
     83extern const double _1_SQRT_2;                                                  // 1 / sqrt(2)
    6984
    70 const long double E = 2.7182818284590452353602874713526625_DL; // e
    71 const long double LOG2_E = 1.4426950408889634073599246810018921_DL; // log_2(e)
    72 const long double LOG10_E = 0.4342944819032518276511289189166051_DL; // log_10(e)
    73 const long double LN_2 = 0.6931471805599453094172321214581766_DL; // log_e(2)
    74 const long double LN_10 = 2.3025850929940456840179914546843642_DL; // log_e(10)
    75 const long double SQRT_2 = 1.4142135623730950488016887242096981_DL; // sqrt(2)
    76 const long double _1_SQRT_2 = 0.7071067811865475244008443621048490_DL; // 1/sqrt(2)
     85extern const long double E;                                                             // e
     86extern const long double LOG2_E;                                                // log_2(e)
     87extern const long double LOG10_E;                                               // log_10(e)
     88extern const long double LN_2;                                                  // log_e(2)
     89extern const long double LN_10;                                                 // log_e(10)
     90extern const long double SQRT_2;                                                // sqrt(2)
     91extern const long double _1_SQRT_2;                                             // 1/sqrt(2)
    7792
    78 const _Complex E = 2.7182818284590452354_D+0.0_iD;      // e
    79 const _Complex LOG2_E = 1.4426950408889634074_D+0.0_iD; // log_2(e)
    80 const _Complex LOG10_E = 0.43429448190325182765_D+0.0_iD; // log_10(e)
    81 const _Complex LN_2 = 0.69314718055994530942_D+0.0_iD;  // log_e(2)
    82 const _Complex LN_10 = 2.30258509299404568402_D+0.0_iD; // log_e(10)
    83 const _Complex SQRT_2 = 1.41421356237309504880_D+0.0_iD;        // sqrt(2)
    84 const _Complex _1_SQRT_2 = 0.70710678118654752440_D+0.0_iD; // 1 / sqrt(2)
     93extern const _Complex E;                                                                // e
     94extern const _Complex LOG2_E;                                                   // log_2(e)
     95extern const _Complex LOG10_E;                                                  // log_10(e)
     96extern const _Complex LN_2;                                                             // log_e(2)
     97extern const _Complex LN_10;                                                    // log_e(10)
     98extern const _Complex SQRT_2;                                                   // sqrt(2)
     99extern const _Complex _1_SQRT_2;                                                // 1 / sqrt(2)
    85100
    86 const long _Complex E = 2.7182818284590452353602874713526625_L+0.0_iL; // e
    87 const long _Complex LOG2_E = 1.4426950408889634073599246810018921_L+0.0_iL; // log_2(e)
    88 const long _Complex LOG10_E = 0.4342944819032518276511289189166051_L+0.0_iL; // log_10(e)
    89 const long _Complex LN_2 = 0.6931471805599453094172321214581766_L+0.0_iL; // log_e(2)
    90 const long _Complex LN_10 = 2.3025850929940456840179914546843642_L+0.0_iL; // log_e(10)
    91 const long _Complex SQRT_2 = 1.4142135623730950488016887242096981_L+0.0_iL; // sqrt(2)
    92 const long _Complex _1_SQRT_2 = 0.7071067811865475244008443621048490_L+0.0_iL; // 1 / sqrt(2)
     101extern const long _Complex E;                                                   // e
     102extern const long _Complex LOG2_E;                                              // log_2(e)
     103extern const long _Complex LOG10_E;                                             // log_10(e)
     104extern const long _Complex LN_2;                                                // log_e(2)
     105extern const long _Complex LN_10;                                               // log_e(10)
     106extern const long _Complex SQRT_2;                                              // sqrt(2)
     107extern const long _Complex _1_SQRT_2;                                   // 1 / sqrt(2)
     108
     109// Local Variables: //
     110// mode: c //
     111// tab-width: 4 //
     112// End: //
  • src/libcfa/prelude.cf

    rc5833e8 r0f9e4403  
     1# 2 "prelude.cf"  // needed for error messages from this file
    12//                               -*- Mode: C -*-
    23//
     
    89// Created On       : Sat Nov 29 07:23:41 2014
    910// Last Modified By : Peter A. Buhr
    10 // Last Modified On : Mon Jan  4 11:13:26 2016
    11 // Update Count     : 81
     11// Last Modified On : Wed Mar  2 18:03:41 2016
     12// Update Count     : 89
    1213//
    1314
     
    6364long double _Complex    ?--( long double _Complex * ),          ?--( volatile long double _Complex * );
    6465
    65 forall( type T ) T *                     ?++(                T ** );
    66 forall( type T ) const T *               ?++( const          T ** );
    67 forall( type T ) volatile T *            ?++(       volatile T ** );
    68 forall( type T ) const volatile T *      ?++( const volatile T ** );
    69 forall( type T ) T *                     ?--(                T ** );
    70 forall( type T ) const T *               ?--( const          T ** );
    71 forall( type T ) volatile T *            ?--(       volatile T ** );
    72 forall( type T ) const volatile T *      ?--( const volatile T ** );
    73 
    74 forall( type T ) lvalue T                ?[?](                T *,          ptrdiff_t );
    75 forall( type T ) const lvalue T          ?[?]( const          T *,          ptrdiff_t );
    76 forall( type T ) volatile lvalue T       ?[?](       volatile T *,          ptrdiff_t );
    77 forall( type T ) const volatile lvalue T ?[?]( const volatile T *,          ptrdiff_t );
    78 forall( type T ) lvalue T                ?[?](          ptrdiff_t,                T * );
    79 forall( type T ) const lvalue T          ?[?](          ptrdiff_t, const          T * );
    80 forall( type T ) volatile lvalue T       ?[?](          ptrdiff_t,       volatile T * );
    81 forall( type T ) const volatile lvalue T ?[?](          ptrdiff_t, const volatile T * );
     66forall( otype T ) T *                    ?++(                T ** );
     67forall( otype T ) const T *              ?++( const          T ** );
     68forall( otype T ) volatile T *           ?++(       volatile T ** );
     69forall( otype T ) const volatile T *     ?++( const volatile T ** );
     70forall( otype T ) T *                    ?--(                T ** );
     71forall( otype T ) const T *              ?--( const          T ** );
     72forall( otype T ) volatile T *           ?--(       volatile T ** );
     73forall( otype T ) const volatile T *     ?--( const volatile T ** );
     74
     75forall( otype T ) lvalue T               ?[?](                T *,          ptrdiff_t );
     76forall( otype T ) const lvalue T         ?[?]( const          T *,          ptrdiff_t );
     77forall( otype T ) volatile lvalue T      ?[?](       volatile T *,          ptrdiff_t );
     78forall( otype T ) const volatile lvalue T ?[?]( const volatile T *,         ptrdiff_t );
     79forall( otype T ) lvalue T               ?[?](          ptrdiff_t,                T * );
     80forall( otype T ) const lvalue T         ?[?](          ptrdiff_t, const          T * );
     81forall( otype T ) volatile lvalue T      ?[?](          ptrdiff_t,       volatile T * );
     82forall( otype T ) const volatile lvalue T ?[?](         ptrdiff_t, const volatile T * );
    8283
    8384// ------------------------------------------------------------
     
    101102long double _Complex    ++?( long double _Complex * ),          --?( long double _Complex * );
    102103
    103 forall( type T ) T *                     ++?(                T ** );
    104 forall( type T ) const T *               ++?( const          T ** );
    105 forall( type T ) volatile T *            ++?(       volatile T ** );
    106 forall( type T ) const volatile T *      ++?( const volatile T ** );
    107 forall( type T ) T *                     --?(                T ** );
    108 forall( type T ) const T *               --?( const          T ** );
    109 forall( type T ) volatile T *            --?(       volatile T ** );
    110 forall( type T ) const volatile T *      --?( const volatile T ** );
    111 
    112 forall( type T ) lvalue T                *?(                 T * );
    113 forall( type T ) const lvalue T          *?( const           T * );
    114 forall( type T ) volatile lvalue T       *?(       volatile  T * );
    115 forall( type T ) const volatile lvalue T *?( const volatile  T * );
     104forall( otype T ) T *                    ++?(                T ** );
     105forall( otype T ) const T *              ++?( const          T ** );
     106forall( otype T ) volatile T *           ++?(       volatile T ** );
     107forall( otype T ) const volatile T *     ++?( const volatile T ** );
     108forall( otype T ) T *                    --?(                T ** );
     109forall( otype T ) const T *              --?( const          T ** );
     110forall( otype T ) volatile T *           --?(       volatile T ** );
     111forall( otype T ) const volatile T *     --?( const volatile T ** );
     112
     113forall( otype T ) lvalue T               *?(                 T * );
     114forall( otype T ) const lvalue T                 *?( const           T * );
     115forall( otype T ) volatile lvalue T      *?(       volatile  T * );
     116forall( otype T ) const volatile lvalue T *?( const volatile  T * );
    116117forall( ftype FT ) lvalue FT             *?( FT * );
    117118
     
    183184long double _Complex    ?+?( long double _Complex, long double _Complex ),      ?-?( long double _Complex, long double _Complex );
    184185
    185 forall( type T ) T *                    ?+?(                T *,          ptrdiff_t );
    186 forall( type T ) T *                    ?+?(          ptrdiff_t,                T * );
    187 forall( type T ) const T *              ?+?( const          T *,          ptrdiff_t );
    188 forall( type T ) const T *              ?+?(          ptrdiff_t, const          T * );
    189 forall( type T ) volatile T *           ?+?(       volatile T *,          ptrdiff_t );
    190 forall( type T ) volatile T *           ?+?(          ptrdiff_t,       volatile T * );
    191 forall( type T ) const volatile T *     ?+?( const volatile T *,          ptrdiff_t );
    192 forall( type T ) const volatile T *     ?+?(          ptrdiff_t, const volatile T * );
    193 forall( type T ) T *                    ?-?(                T *,          ptrdiff_t );
    194 forall( type T ) const T *              ?-?( const          T *,          ptrdiff_t );
    195 forall( type T ) volatile T *           ?-?(       volatile T *,          ptrdiff_t );
    196 forall( type T ) const volatile T *     ?-?( const volatile T *,          ptrdiff_t );
    197 forall( type T ) ptrdiff_t              ?-?( const volatile T *, const volatile T * );
     186forall( otype T ) T *                   ?+?(                T *,          ptrdiff_t );
     187forall( otype T ) T *                   ?+?(          ptrdiff_t,                T * );
     188forall( otype T ) const T *             ?+?( const          T *,          ptrdiff_t );
     189forall( otype T ) const T *             ?+?(          ptrdiff_t, const          T * );
     190forall( otype T ) volatile T *          ?+?(       volatile T *,          ptrdiff_t );
     191forall( otype T ) volatile T *          ?+?(          ptrdiff_t,       volatile T * );
     192forall( otype T ) const volatile T *    ?+?( const volatile T *,          ptrdiff_t );
     193forall( otype T ) const volatile T *    ?+?(          ptrdiff_t, const volatile T * );
     194forall( otype T ) T *                   ?-?(                T *,          ptrdiff_t );
     195forall( otype T ) const T *             ?-?( const          T *,          ptrdiff_t );
     196forall( otype T ) volatile T *          ?-?(       volatile T *,          ptrdiff_t );
     197forall( otype T ) const volatile T *    ?-?( const volatile T *,          ptrdiff_t );
     198forall( otype T ) ptrdiff_t             ?-?( const volatile T *, const volatile T * );
    198199
    199200// ------------------------------------------------------------
     
    431432forall( ftype FT ) FT *                 ?=?( FT * volatile *, forall( ftype FT2 ) FT2 * );
    432433
    433 forall( type T ) T *                    ?+=?(                T *          *, ptrdiff_t );
    434 forall( type T ) T *                    ?+=?(                T * volatile *, ptrdiff_t );
    435 forall( type T ) const T *              ?+=?( const          T *          *, ptrdiff_t );
    436 forall( type T ) const T *              ?+=?( const          T * volatile *, ptrdiff_t );
    437 forall( type T ) volatile T *           ?+=?(       volatile T *          *, ptrdiff_t );
    438 forall( type T ) volatile T *           ?+=?(       volatile T * volatile *, ptrdiff_t );
    439 forall( type T ) const volatile T *     ?+=?( const volatile T *          *, ptrdiff_t );
    440 forall( type T ) const volatile T *     ?+=?( const volatile T * volatile *, ptrdiff_t );
    441 forall( type T ) T *                    ?-=?(                T *          *, ptrdiff_t );
    442 forall( type T ) T *                    ?-=?(                T * volatile *, ptrdiff_t );
    443 forall( type T ) const T *              ?-=?( const          T *          *, ptrdiff_t );
    444 forall( type T ) const T *              ?-=?( const          T * volatile *, ptrdiff_t );
    445 forall( type T ) volatile T *           ?-=?(       volatile T *          *, ptrdiff_t );
    446 forall( type T ) volatile T *           ?-=?(       volatile T * volatile *, ptrdiff_t );
    447 forall( type T ) const volatile T *     ?-=?( const volatile T *          *, ptrdiff_t );
    448 forall( type T ) const volatile T *     ?-=?( const volatile T * volatile *, ptrdiff_t );
     434forall( otype T ) T *                   ?+=?(                T *          *, ptrdiff_t );
     435forall( otype T ) T *                   ?+=?(                T * volatile *, ptrdiff_t );
     436forall( otype T ) const T *             ?+=?( const          T *          *, ptrdiff_t );
     437forall( otype T ) const T *             ?+=?( const          T * volatile *, ptrdiff_t );
     438forall( otype T ) volatile T *          ?+=?(       volatile T *          *, ptrdiff_t );
     439forall( otype T ) volatile T *          ?+=?(       volatile T * volatile *, ptrdiff_t );
     440forall( otype T ) const volatile T *    ?+=?( const volatile T *          *, ptrdiff_t );
     441forall( otype T ) const volatile T *    ?+=?( const volatile T * volatile *, ptrdiff_t );
     442forall( otype T ) T *                   ?-=?(                T *          *, ptrdiff_t );
     443forall( otype T ) T *                   ?-=?(                T * volatile *, ptrdiff_t );
     444forall( otype T ) const T *             ?-=?( const          T *          *, ptrdiff_t );
     445forall( otype T ) const T *             ?-=?( const          T * volatile *, ptrdiff_t );
     446forall( otype T ) volatile T *          ?-=?(       volatile T *          *, ptrdiff_t );
     447forall( otype T ) volatile T *          ?-=?(       volatile T * volatile *, ptrdiff_t );
     448forall( otype T ) const volatile T *    ?-=?( const volatile T *          *, ptrdiff_t );
     449forall( otype T ) const volatile T *    ?-=?( const volatile T * volatile *, ptrdiff_t );
    449450
    450451_Bool                   ?=?( _Bool *, _Bool ),                                  ?=?( volatile _Bool *, _Bool );
  • src/libcfa/stdlib

    rc5833e8 r0f9e4403  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Feb  5 15:21:18 2016
    13 // Update Count     : 61
     12// Last Modified On : Wed Apr 13 14:45:53 2016
     13// Update Count     : 85
    1414//
    1515
     
    2020} // extern "C"
    2121
    22 forall( type T ) T * memset( T * ptr, unsigned char fill ); // use default value '\0' for fill
    23 forall( type T ) T * memset( T * ptr );                                 // remove when default value available
     22//---------------------------------------
    2423
    25 forall( type T ) T * malloc( void );
    26 forall( type T ) T * malloc( char fill );
    27 forall( type T ) T * malloc( size_t size );
    28 forall( type T ) T * malloc( T * ptr, size_t size );
    29 forall( type T ) T * malloc( T * ptr, size_t size, unsigned char fill );
    30 forall( type T ) T * calloc( size_t size );
    31 forall( type T ) T * realloc( T * ptr, size_t size );
    32 forall( type T ) T * realloc( T * ptr, size_t size, unsigned char fill );
     24extern "C" {
     25#ifndef EXIT_FAILURE
     26#define EXIT_FAILURE    1                                                               // failing exit status
     27#define EXIT_SUCCESS    0                                                               // successful exit status
     28#endif // ! EXIT_FAILURE
     29void exit( int rc );
     30} // extern "C"
    3331
    34 forall( type T ) T * aligned_alloc( size_t alignment );
    35 forall( type T ) T * memalign( size_t alignment );              // deprecated
    36 forall( type T ) int posix_memalign( T ** ptr, size_t alignment );
     32//---------------------------------------
     33
     34extern "C" {
     35void * malloc( size_t );                                                                // use default C routine for void *
     36} // extern "C"
     37forall( otype T ) T * malloc( void );
     38forall( otype T ) T * malloc( char fill );
     39forall( otype T ) T * malloc( T * ptr, size_t size );
     40forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill );
     41extern "C" {
     42void * calloc( size_t nmemb, size_t size );                             // use default C routine for void *
     43} // extern "C"
     44forall( otype T ) T * calloc( size_t nmemb );
     45extern "C" {
     46void * realloc( void * ptr, size_t size );                              // use default C routine for void *
     47} // extern "C"
     48forall( otype T ) T * realloc( T * ptr, size_t size );
     49forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill );
     50
     51forall( otype T ) T * aligned_alloc( size_t alignment );
     52forall( otype T ) T * memalign( size_t alignment );             // deprecated
     53forall( otype T ) int posix_memalign( T ** ptr, size_t alignment );
     54
     55forall( otype T ) T * memset( T * ptr, unsigned char fill ); // use default value '\0' for fill
     56forall( otype T ) T * memset( T * ptr );                                // remove when default value available
    3757
    3858//---------------------------------------
     
    6686//---------------------------------------
    6787
    68 forall( type T | { int ?<?( T, T ); } )
     88forall( otype T | { int ?<?( T, T ); } )
    6989T * bsearch( const T key, const T * arr, size_t dimension );
    7090
    71 forall( type T | { int ?<?( T, T ); } )
     91forall( otype T | { int ?<?( T, T ); } )
    7292void qsort( const T * arr, size_t dimension );
    7393
    7494//---------------------------------------
    7595
    76 forall( type T | { T ?/?( T, T ); T ?%?( T, T ); } )
     96forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } )
    7797[ T, T ] div( T t1, T t2 );
    7898
     
    81101char abs( char );
    82102extern "C" {
    83 int abs( int );         // use default C routine for int
    84 } // extern
     103int abs( int );                                                                                 // use default C routine for int
     104} // extern "C"
    85105long int abs( long int );
    86106long long int abs( long long int );
     
    94114//---------------------------------------
    95115
    96 void randseed( long int s );
    97 char random();
    98 int random();
    99 unsigned int random();
    100 long int random();
    101 unsigned long int random();
    102 float random();
    103 double random();
    104 float _Complex random();
    105 double _Complex random();
    106 long double _Complex random();
     116float floor( float );
     117extern "C" {
     118double floor( double );                                                                 // use C routine for double
     119} // extern "C"
     120long double floor( long double );
     121
     122float ceil( float );
     123extern "C" {
     124double ceil( double );                                                                  // use C routine for double
     125} // extern "C"
     126long double ceil( long double );
    107127
    108128//---------------------------------------
    109129
    110 forall( type T | { int ?<?( T, T ); } )
     130void rand48seed( long int s );
     131char rand48();
     132int rand48();
     133unsigned int rand48();
     134long int rand48();
     135unsigned long int rand48();
     136float rand48();
     137double rand48();
     138float _Complex rand48();
     139double _Complex rand48();
     140long double _Complex rand48();
     141
     142//---------------------------------------
     143
     144forall( otype T | { int ?<?( T, T ); } )
    111145T min( const T t1, const T t2 );
    112146
    113 forall( type T | { int ?>?( T, T ); } )
     147forall( otype T | { int ?>?( T, T ); } )
    114148T max( const T t1, const T t2 );
    115149
    116 forall( type T )
     150forall( otype T )
    117151void swap( T * t1, T * t2 );
    118152
  • src/libcfa/stdlib.c

    rc5833e8 r0f9e4403  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 10 15:45:56 2016
    13 // Update Count     : 140
     12// Last Modified On : Wed Apr 13 14:49:58 2016
     13// Update Count     : 155
    1414//
    1515
     
    2727} // extern "C"
    2828
    29 forall( type T ) T * memset( T * ptr, unsigned char fill ) { // use default value '\0' for fill
    30         printf( "memset1\n" );
    31     return (T *)memset( ptr, (int)fill, malloc_usable_size( ptr ) );
    32 } // memset
    33 forall( type T ) T * memset( T * ptr ) {                                // remove when default value available
    34         printf( "memset2\n" );
    35     return (T *)memset( ptr, 0, malloc_usable_size( ptr ) );
    36 } // memset
    37 
    38 forall( type T ) T * malloc( void ) {
    39         printf( "malloc1\n" );
     29forall( otype T ) T * malloc( void ) {
     30        //printf( "malloc1\n" );
    4031    return (T *)malloc( sizeof(T) );
    4132} // malloc
    42 forall( type T ) T * malloc( size_t size ) {
    43         printf( "malloc2\n" );
    44     return (T *)(void *)malloc( size );
    45 } // malloc
    46 forall( type T ) T * malloc( char fill ) {
    47         printf( "malloc3\n" );
     33forall( otype T ) T * malloc( char fill ) {
     34        //printf( "malloc3\n" );
    4835        T * ptr = (T *)malloc( sizeof(T) );
    4936    return memset( ptr );
    5037} // malloc
    5138
    52 forall( type T ) T * calloc( size_t size ) {
    53         printf( "calloc\n" );
    54     return (T *)calloc( size, sizeof(T) );
     39forall( otype T ) T * calloc( size_t nmemb ) {
     40        //printf( "calloc\n" );
     41    return (T *)calloc( nmemb, sizeof(T) );
    5542} // calloc
    5643
    57 forall( type T ) T * realloc( T * ptr, size_t size ) {
    58         printf( "realloc1\n" );
     44forall( otype T ) T * realloc( T * ptr, size_t size ) {
     45        //printf( "realloc1\n" );
    5946    return (T *)(void *)realloc( (void *)ptr, size );
    6047} // realloc
    61 forall( type T ) T * realloc( T * ptr, size_t size, unsigned char fill ) {
    62         printf( "realloc2\n" );
     48forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill ) {
     49        //printf( "realloc2\n" );
    6350    char * nptr = (T *)(void *)realloc( (void *)ptr, size );
    6451    size_t unused = malloc_usable_size( nptr );
     
    6754} // realloc
    6855
    69 forall( type T ) T * malloc( T * ptr, size_t size ) {
    70         printf( "malloc4\n" );
     56forall( otype T ) T * malloc( T * ptr, size_t size ) {
     57        //printf( "malloc4\n" );
    7158    return (T *)realloc( ptr, size );
    7259} // malloc
    73 forall( type T ) T * malloc( T * ptr, size_t size, unsigned char fill ) {
    74         printf( "malloc5\n" );
     60forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill ) {
     61        //printf( "malloc5\n" );
    7562    return (T *)realloc( ptr, size, fill );
    7663} // malloc
    7764
    78 forall( type T ) T * aligned_alloc( size_t alignment ) {
    79         printf( "aligned_alloc\n" );
     65forall( otype T ) T * aligned_alloc( size_t alignment ) {
     66        //printf( "aligned_alloc\n" );
    8067    return (T *)memalign( alignment, sizeof(T) );
    8168} // aligned_alloc
    8269
    83 forall( type T ) T * memalign( size_t alignment ) {
    84         printf( "memalign\n" );
     70forall( otype T ) T * memalign( size_t alignment ) {
     71        //printf( "memalign\n" );
    8572    return (T *)memalign( alignment, sizeof(T) );
    8673} // memalign
    8774
    88 forall( type T ) int posix_memalign( T ** ptr, size_t alignment ) {
    89         printf( "posix_memalign\n" );
     75forall( otype T ) int posix_memalign( T ** ptr, size_t alignment ) {
     76        //printf( "posix_memalign\n" );
    9077    return posix_memalign( (void **)ptr, alignment, sizeof(T) );
    9178} // posix_memalign
     79
     80forall( 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
     84forall( 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
    9288
    9389//---------------------------------------
     
    123119        return ulli;
    124120}
     121
    125122float ato( const char * ptr ) {
    126123        float f;
     
    138135        return ld;
    139136}
     137
    140138float _Complex ato( const char * ptr ) {
    141139        float re, im;
     
    172170        return strtoull( sptr, eptr, base );
    173171}
     172
    174173float strto( const char * sptr, char ** eptr ) {
    175174        return strtof( sptr, eptr );
     
    181180        return strtold( sptr, eptr );
    182181}
     182
    183183float _Complex strto( const char * sptr, char ** eptr ) {
    184184        float re, im;
     
    208208//---------------------------------------
    209209
    210 forall( type T | { int ?<?( T, T ); } )
     210forall( otype T | { int ?<?( T, T ); } )
    211211T * bsearch( const T key, const T * arr, size_t dimension ) {
    212212        int comp( const void * t1, const void * t2 ) { return *(T *)t1 < *(T *)t2 ? -1 : *(T *)t2 < *(T *)t1 ? 1 : 0; }
     
    214214} // bsearch
    215215
    216 forall( type T | { int ?<?( T, T ); } )
     216forall( otype T | { int ?<?( T, T ); } )
    217217void qsort( const T * arr, size_t dimension ) {
    218218        int comp( const void * t1, const void * t2 ) { return *(T *)t1 < *(T *)t2 ? -1 : *(T *)t2 < *(T *)t1 ? 1 : 0; }
     
    222222//---------------------------------------
    223223
    224 forall( type T | { T ?/?( T, T ); T ?%?( T, T ); } )
     224forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } )
    225225[ T, T ] div( T t1, T t2 ) { /* return [ t1 / t2, t1 % t2 ]; */ }
    226226
     
    239239//---------------------------------------
    240240
    241 void randseed( long int s ) { srand48( s ); }
    242 char random() { return lrand48(); }
    243 int random() { return mrand48(); }
    244 unsigned int random() { return lrand48(); }
    245 long int random() { return mrand48(); }
    246 unsigned long int random() { return lrand48(); }
    247 float random() { return (float)drand48(); }                             // otherwise float uses lrand48
    248 double random() { return drand48(); }
    249 float _Complex random() { return (float)drand48() + (float _Complex)(drand48() * _Complex_I); }
    250 double _Complex random() { return drand48() + (double _Complex)(drand48() * _Complex_I); }
    251 long double _Complex random() { return (long double)drand48() + (long double _Complex)(drand48() * _Complex_I); }
    252 
    253 //---------------------------------------
    254 
    255 forall( type T | { int ?<?( T, T ); } )
     241float floor( float v ) { return floorf( v ); }
     242long double floor( long double v ) { return floorl( v ); }
     243
     244float ceil( float v ) { return ceilf( v ); }
     245long double ceil( long double v ) { return ceill( v ); }
     246
     247//---------------------------------------
     248
     249void rand48seed( long int s ) { srand48( s ); }
     250char rand48() { return mrand48(); }
     251int rand48() { return mrand48(); }
     252unsigned int rand48() { return lrand48(); }
     253long int rand48() { return mrand48(); }
     254unsigned long int rand48() { return lrand48(); }
     255float rand48() { return (float)drand48(); }                             // otherwise float uses lrand48
     256double rand48() { return drand48(); }
     257float _Complex rand48() { return (float)drand48() + (float _Complex)(drand48() * _Complex_I); }
     258double _Complex rand48() { return drand48() + (double _Complex)(drand48() * _Complex_I); }
     259long double _Complex rand48() { return (long double)drand48() + (long double _Complex)(drand48() * _Complex_I); }
     260
     261//---------------------------------------
     262
     263forall( otype T | { int ?<?( T, T ); } )
    256264T min( const T t1, const T t2 ) {
    257265        return t1 < t2 ? t1 : t2;
    258266} // min
    259267
    260 forall( type T | { int ?>?( T, T ); } )
     268forall( otype T | { int ?>?( T, T ); } )
    261269T max( const T t1, const T t2 ) {
    262270        return t1 > t2 ? t1 : t2;
    263271} // max
    264272
    265 forall( type T )
     273forall( otype T )
    266274void swap( T * t1, T * t2 ) {
    267275        T temp = *t1;
Note: See TracChangeset for help on using the changeset viewer.