Changeset 0f9e4403 for src/libcfa
- Timestamp:
- Apr 15, 2016, 12:03:11 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, 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. - Location:
- src/libcfa
- Files:
-
- 3 added
- 11 deleted
- 13 edited
-
Makefile.am (modified) (2 diffs)
-
Makefile.in (modified) (4 diffs)
-
bfd.h (deleted)
-
bfdlink.h (deleted)
-
builtins.cf (modified) (4 diffs)
-
demangle.h (deleted)
-
dialog.h (deleted)
-
evdns.h (deleted)
-
evhttp.h (deleted)
-
evrpc.h (deleted)
-
fcntl.h (deleted)
-
form.h (deleted)
-
fstream (modified) (3 diffs)
-
fstream.c (modified) (8 diffs)
-
gcrypt.h (deleted)
-
iostream (modified) (3 diffs)
-
iostream.c (modified) (3 diffs)
-
iterator (modified) (4 diffs)
-
iterator.c (modified) (2 diffs)
-
limits (modified) (1 diff)
-
limits.c (added)
-
math.h (deleted)
-
prelude.cf (modified) (6 diffs)
-
rational (added)
-
rational.c (added)
-
stdlib (modified) (5 diffs)
-
stdlib.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/Makefile.am
rc5833e8 r0f9e4403 11 11 ## Created On : Sun May 31 08:54:01 2015 12 12 ## Last Modified By : Peter A. Buhr 13 ## Last Modified On : Wed Feb 3 11:19:35201614 ## Update Count : 1 1713 ## Last Modified On : Wed Apr 6 21:10:44 2016 14 ## Update Count : 123 15 15 ############################################################################### 16 16 … … 60 60 ${CC} ${CFLAGS} -c -o $@ $< 61 61 62 libs = stdlib iostream fstream iterator62 libs = limits stdlib iostream fstream iterator rational 63 63 libcfa_a_SOURCES = libcfa-prelude.c ${libs:=.c} 64 64 65 cheaders = bfd bfdlink demangle dialog evdns evhttp evrpc expat fcntl form gcrypt math66 cfaheaders = limits65 cheaders = # expat 66 cfaheaders = # limits 67 67 include_HEADERS = ${cheaders:=.h} ${libs} ${cfaheaders} 68 68 -
src/libcfa/Makefile.in
rc5833e8 r0f9e4403 83 83 libcfa_a_AR = $(AR) $(ARFLAGS) 84 84 libcfa_a_LIBADD = 85 am__objects_1 = stdlib.$(OBJEXT) iostream.$(OBJEXT) fstream.$(OBJEXT) \86 iterator.$(OBJEXT)85 am__objects_1 = limits.$(OBJEXT) stdlib.$(OBJEXT) iostream.$(OBJEXT) \ 86 fstream.$(OBJEXT) iterator.$(OBJEXT) rational.$(OBJEXT) 87 87 am_libcfa_a_OBJECTS = libcfa-prelude.$(OBJEXT) $(am__objects_1) 88 88 libcfa_a_OBJECTS = $(am_libcfa_a_OBJECTS) … … 213 213 MAINTAINERCLEANFILES = ${addprefix ${libdir}/,${cfalib_DATA}} \ 214 214 ${addprefix ${libdir}/,${lib_LIBRARIES}} ${includedir}/* 215 libs = stdlib iostream fstream iterator215 libs = limits stdlib iostream fstream iterator rational 216 216 libcfa_a_SOURCES = libcfa-prelude.c ${libs:=.c} 217 cheaders = bfd bfdlink demangle dialog evdns evhttp evrpc expat fcntl form gcrypt math218 cfaheaders = limits217 cheaders = # expat 218 cfaheaders = # limits 219 219 include_HEADERS = ${cheaders:=.h} ${libs} ${cfaheaders} 220 220 all: all-am … … 231 231 esac; \ 232 232 done; \ 233 echo ' cd $(top_srcdir) && $(AUTOMAKE) -- gnusrc/libcfa/Makefile'; \233 echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/libcfa/Makefile'; \ 234 234 $(am__cd) $(top_srcdir) && \ 235 $(AUTOMAKE) -- gnusrc/libcfa/Makefile235 $(AUTOMAKE) --foreign src/libcfa/Makefile 236 236 .PRECIOUS: Makefile 237 237 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status … … 297 297 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/iterator.Po@am__quote@ 298 298 @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@ 299 301 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stdlib.Po@am__quote@ 300 302 -
src/libcfa/builtins.cf
rc5833e8 r0f9e4403 390 390 int __builtin_sprintf(char *, const char *, ...); 391 391 int __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 **);392 int __builtin_vfprintf(struct _IO_FILE *, const char *, __builtin_va_list); 393 int __builtin_vfscanf(struct _IO_FILE *, const char *, __builtin_va_list); 394 int __builtin_vprintf(const char *, __builtin_va_list); 395 int __builtin_vscanf(const char *, __builtin_va_list); 396 int __builtin_vsnprintf(char *, unsigned long, const char *, __builtin_va_list); 397 int __builtin_vsprintf(char *, const char *, __builtin_va_list); 398 int __builtin_vsscanf(const char *, const char *, __builtin_va_list); 399 399 int __builtin_isalnum(int); 400 400 int __builtin_isalpha(int); … … 534 534 void __builtin_unwind_init(); 535 535 void __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 **, ...);536 void __builtin_va_copy(__builtin_va_list, __builtin_va_list); 537 void __builtin_va_end(__builtin_va_list); 538 void __builtin_va_start(__builtin_va_list, ...); 539 539 int __builtin_va_arg_pack(); 540 540 int __builtin_va_arg_pack_len(); … … 563 563 int __builtin___snprintf_chk(char *, unsigned long, int, unsigned long, const char *, ...); 564 564 int __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 **);565 int __builtin___vsnprintf_chk(char *, unsigned long, int, unsigned long, const char *, __builtin_va_list); 566 int __builtin___vsprintf_chk(char *, int, unsigned long, const char *, __builtin_va_list); 567 567 int __builtin___fprintf_chk(struct _IO_FILE *, int, const char *, ...); 568 568 int __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 **);569 int __builtin___vfprintf_chk(struct _IO_FILE *, int, const char *, __builtin_va_list); 570 int __builtin___vprintf_chk(int, const char *, __builtin_va_list); 571 571 void __cyg_profile_func_enter(void *, void *); 572 572 void __cyg_profile_func_exit(void *, void *); … … 583 583 const char * __builtin_FUNCTION(); 584 584 int __builtin_LINE(); 585 typedef void ** __builtin_va_list;586 585 extern const char *__PRETTY_FUNCTION__; 587 typedef int wchar_t; -
src/libcfa/fstream
rc5833e8 r0f9e4403 7 7 // fstream -- 8 8 // 9 // Author : Richard C. Bilson9 // Author : Peter A. Buhr 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 17 14:02:01201613 // Update Count : 2212 // Last Modified On : Tue Apr 5 22:37:12 2016 13 // Update Count : 82 14 14 // 15 15 … … 19 19 #include "iostream" 20 20 21 // implement context ostream 22 struct ofstream; 21 enum { separateSize = 16 }; 22 struct ofstream { 23 void *file; 24 _Bool sepDefault; 25 _Bool sepOnOff; 26 char separator[separateSize]; 27 }; // ofstream 23 28 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 * ); 30 void sepOn( ofstream * ); 31 void sepOff( ofstream * ); 32 void sepReset( ofstream * ); 33 void sepReset( ofstream *, _Bool ); 34 void sepSet( ofstream *, const char * ); 35 const char * sepGet( ofstream * ); 36 _Bool sepDisable( ofstream * ); 37 _Bool sepEnable( ofstream * ); 38 int fail( ofstream * ); 39 int flush( ofstream * ); 40 void open( ofstream *, const char * name, const char * mode ); 41 void close( ofstream * ); 42 ofstream * write( ofstream *, const char * data, unsigned long int size ); 43 int prtfmt( ofstream *, const char fmt[], ... ); 29 44 30 45 extern ofstream * sout, * serr; 31 46 32 47 // implement context istream 33 struct ifstream; 48 struct ifstream { 49 void *file; 50 }; // ifstream 34 51 35 52 int fail( ifstream * is ); 36 53 int eof( ifstream * is ); 37 void open( ifstream * *is, const char * name, const char * mode );54 void open( ifstream * is, const char * name, const char * mode ); 38 55 void close( ifstream * is ); 39 ifstream * get( ifstream * is, int * data ); 40 ifstream * read( ifstream * is, char * data, streamsize_type size ); 56 ifstream * read( ifstream * is, char * data, unsigned long int size ); 41 57 ifstream * ungetc( ifstream * is, char c ); 58 int scanfmt( ifstream *, const char fmt[], ... ); 42 59 43 60 extern ifstream *sin; … … 49 66 // tab-width: 4 // 50 67 // End: // 68 -
src/libcfa/fstream.c
rc5833e8 r0f9e4403 7 7 // fstream.c -- 8 8 // 9 // Author : Richard C. Bilson9 // Author : Peter A. Buhr 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 17 14:03:05201613 // Update Count : 7612 // Last Modified On : Wed Apr 6 17:55:27 2016 13 // Update Count : 176 14 14 // 15 15 … … 17 17 18 18 extern "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 21 25 } 22 26 23 struct ofstream { 24 FILE *file; 25 }; 27 #define IO_MSG "I/O error: " 26 28 27 #define IO_MSG "I/O error " 29 _Bool sepPrt( ofstream * os ) { return os->sepOnOff; } 30 void sepOn( ofstream * os ) { os->sepOnOff = 1; } 31 void sepOff( ofstream * os ) { os->sepOnOff = 0; } 32 void sepReset( ofstream * os ) { os->sepOnOff = os->sepDefault; } 33 void sepReset( ofstream * os, _Bool reset ) { os->sepDefault = reset; os->sepOnOff = os->sepDefault; } 34 void sepSet( ofstream * os, const char * s ) { 35 strncpy( &(os->separator[0]), s, separateSize - 1 ); 36 os->separator[separateSize - 1] = '\0'; 37 } // sepSet 38 const 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 28 51 29 52 int fail( ofstream * os ) { 30 return ferror( os->file);53 return ferror( (FILE *)(os->file) ); 31 54 } // fail 32 55 33 56 int flush( ofstream * os ) { 34 return fflush( os->file);57 return fflush( (FILE *)(os->file) ); 35 58 } // flush 36 59 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" ); 60 void 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 ); 41 65 exit( EXIT_FAILURE ); 42 66 } // if 43 (*os)->file = t; 67 os->file = file; 68 sepOff( os ); 69 sepSet( os, " " ); 44 70 } // open 45 71 46 72 void close( ofstream * os ) { 47 if ( os->file == stdout || os->file== stderr ) return;73 if ( (FILE *)(os->file) == stdout || (FILE *)(os->file) == stderr ) return; 48 74 49 if ( fclose( os->file) == EOF ) {75 if ( fclose( (FILE *)(os->file) ) == EOF ) { 50 76 perror( IO_MSG "close output" ); 51 77 } // if 52 78 } // close 53 79 54 ofstream * write( ofstream * os, const char * data, streamsize_typesize ) {80 ofstream * write( ofstream * os, const char * data, unsigned long int size ) { 55 81 if ( fail( os ) ) { 56 82 fprintf( stderr, "attempt write I/O on failed stream\n" ); … … 58 84 } // if 59 85 60 if ( fwrite( data, 1, size, os->file) != size ) {86 if ( fwrite( data, 1, size, (FILE *)(os->file) ) != size ) { 61 87 perror( IO_MSG "write" ); 62 88 exit( EXIT_FAILURE ); … … 65 91 } // write 66 92 67 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_) }; 93 int 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 109 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), 1, 0, { ' ', '\0' } }; 68 110 ofstream *sout = &soutFile; 69 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_) };111 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), 1, 0, { ' ', '\0' } }; 70 112 ofstream *serr = &serrFile; 113 71 114 72 115 //--------------------------------------- 73 116 74 struct ifstream {75 FILE *file;76 };77 117 78 118 int fail( ifstream * is ) { 79 return ferror( is->file);119 return ferror( (FILE *)(is->file) ); 80 120 } // fail 81 121 82 122 int eof( ifstream * is ) { 83 return feof( is->file);123 return feof( (FILE *)(is->file) ); 84 124 } // eof 85 125 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 } // if126 void 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 ); 92 132 } // if 93 return is;94 } // read133 is->file = t; 134 } // open 95 135 96 ifstream * read( ifstream * is, char * data, streamsize_type size ) { 136 void 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 144 ifstream * read( ifstream * is, char * data, unsigned long int size ) { 97 145 if ( fail( is ) ) { 98 146 fprintf( stderr, "attempt read I/O on failed stream\n" ); … … 100 148 } // if 101 149 102 if ( fread( data, size, 1, is->file) == 0 ) {150 if ( fread( data, size, 1, (FILE *)(is->file) ) == 0 ) { 103 151 perror( IO_MSG "read" ); 104 152 exit( EXIT_FAILURE ); … … 113 161 } // if 114 162 115 if ( ungetc( c, is->file) == EOF ) {163 if ( ungetc( c, (FILE *)(is->file) ) == EOF ) { 116 164 perror( IO_MSG "ungetc" ); 117 165 exit( EXIT_FAILURE ); … … 120 168 } // ungetc 121 169 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 ); 170 int 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 127 180 } // if 128 (*is)->file = t; 129 } // open 181 va_end( args ); 182 return len; 183 } // prtfmt 130 184 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 } // if137 } // close138 185 139 186 static ifstream sinFile = { (FILE *)(&_IO_2_1_stdin_) }; … … 142 189 // Local Variables: // 143 190 // tab-width: 4 // 144 // compile-command: "cfa fstream.c" //145 191 // End: // -
src/libcfa/iostream
rc5833e8 r0f9e4403 7 7 // iostream -- 8 8 // 9 // Author : Richard C. Bilson9 // Author : Peter A. Buhr 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 17 14:04:24201613 // Update Count : 3212 // Last Modified On : Sun Apr 10 23:00:12 2016 13 // Update Count : 92 14 14 // 15 15 16 #ifndef IOSTREAM_H17 #define IOSTREAM_H16 #ifndef __IOSTREAM_H__ 17 #define __IOSTREAM_H__ 18 18 19 19 #include "iterator" 20 20 21 typedef unsigned long streamsize_type; 21 trait 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 22 31 23 context ostream( dtype ostype ) {24 32 int fail( ostype * ); 25 33 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[], ... ); 27 38 }; 28 context writeable( type T ) { 39 40 trait writeable( otype T ) { 29 41 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, T ); 30 42 }; … … 33 45 34 46 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, char ); 47 48 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, short int ); 49 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned short int ); 35 50 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, int ); 36 51 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned int ); … … 39 54 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned long int ); 40 55 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned long long int ); 56 41 57 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, float ); // FIX ME: should not be required 42 58 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, double ); 43 59 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, long double ); 60 44 61 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, float _Complex ); 45 62 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, double _Complex ); 46 63 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, long double _Complex ); 64 47 65 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, const char * ); 48 66 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, const void * ); 49 67 50 forall( dtype ostype , dtype retostype | ostream( ostype ) | ostream( retostype ) ) retostype * ?|?( ostype *os, retostype * (* manip)(ostype*) );68 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, ostype * (*)( ostype * ) ); 51 69 forall( dtype ostype | ostream( ostype ) ) ostype * endl( ostype * ); 70 forall( dtype ostype | ostream( ostype ) ) ostype * sepOn( ostype * ); 71 forall( dtype ostype | ostream( ostype ) ) ostype * sepOff( ostype * ); 72 forall( dtype ostype | ostream( ostype ) ) ostype * sepDisable( ostype * ); 73 forall( dtype ostype | ostream( ostype ) ) ostype * sepEnable( ostype * ); 52 74 53 75 // 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 ) )76 forall( otype elt_type | writeable( elt_type ), otype iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) ) 55 77 void write( iterator_type begin, iterator_type end, os_type *os ); 56 78 57 forall( type elt_type | writeable( elt_type ),type iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) )79 forall( otype elt_type | writeable( elt_type ), otype iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) ) 58 80 void write_reverse( iterator_type begin, iterator_type end, os_type *os ); 59 81 60 82 //--------------------------------------- 61 83 62 context istream( dtype istype ) {84 trait istream( dtype istype ) { 63 85 int fail( istype * ); 64 86 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 ); 67 90 istype * ungetc( istype *, char ); 91 int scanfmt( istype *, const char fmt[], ... ); 68 92 }; 69 93 70 context readable(type T ) {94 trait readable( otype T ) { 71 95 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, T ); 72 96 }; 73 97 74 forall( dtype istype | istream( istype ) ) 75 istype * ?|?( istype *, char * ); 98 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, char * ); 76 99 77 forall( dtype istype | istream( istype ) ) 78 istype * ?|?( istype *, int * ); 100 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, short int * ); 101 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned short int * ); 102 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, int * ); 103 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned int * ); 104 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long int * ); 105 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long long int * ); 106 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned long int * ); 107 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned long long int * ); 79 108 80 #endif // IOSTREAM_H 109 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, float * ); 110 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, double * ); 111 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long double * ); 112 113 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, float _Complex * ); 114 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, double _Complex * ); 115 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long double _Complex * ); 116 117 struct _Istream_cstrUC { char * s; }; 118 _Istream_cstrUC cstr( char * ); 119 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, _Istream_cstrUC ); 120 121 struct _Istream_cstrC { char * s; int size; }; 122 _Istream_cstrC cstr( char *, int size ); 123 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, _Istream_cstrC ); 124 125 #endif // __IOSTREAM_H__ 81 126 82 127 // Local Variables: // -
src/libcfa/iostream.c
rc5833e8 r0f9e4403 7 7 // iostream.c -- 8 8 // 9 // Author : Richard C. Bilson9 // Author : Peter A. Buhr 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 17 14:19:56201613 // Update Count : 7612 // Last Modified On : Wed Apr 6 16:13:29 2016 13 // Update Count : 278 14 14 // 15 15 … … 21 21 #include <float.h> // DBL_DIG, LDBL_DIG 22 22 #include <complex.h> // creal, cimag 23 #include <ctype.h> // isspace, ispunct 23 24 } 24 25 25 26 forall( dtype ostype | ostream( ostype ) ) 26 27 ostype * ?|?( ostype *os, char c ) { 27 return write( os, &c, 1 ); 28 prtfmt( os, "%c", c ); 29 sepOff( os ); 30 return os; 31 } // ?|? 32 33 forall( dtype ostype | ostream( ostype ) ) 34 ostype * ?|?( 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 41 forall( dtype ostype | ostream( ostype ) ) 42 ostype * ?|?( 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; 28 47 } // ?|? 29 48 30 49 forall( dtype ostype | ostream( ostype ) ) 31 50 ostype * ?|?( 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 57 forall( dtype ostype | ostream( ostype ) ) 58 ostype * ?|?( 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 65 forall( dtype ostype | ostream( ostype ) ) 66 ostype * ?|?( 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 73 forall( dtype ostype | ostream( ostype ) ) 74 ostype * ?|?( 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 81 forall( dtype ostype | ostream( ostype ) ) 82 ostype * ?|?( 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 89 forall( dtype ostype | ostream( ostype ) ) 90 ostype * ?|?( 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; 64 95 } // ?|? 65 96 66 97 forall( dtype ostype | ostream( ostype ) ) 67 98 ostype * ?|?( 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; 70 103 } // ?|? 71 104 72 105 forall( dtype ostype | ostream( ostype ) ) 73 106 ostype * ?|?( 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 113 forall( dtype ostype | ostream( ostype ) ) 114 ostype * ?|?( 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 121 forall( dtype ostype | ostream( ostype ) ) 122 ostype * ?|?( 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 131 forall( dtype ostype | ostream( ostype ) ) 132 ostype * ?|?( 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 141 forall( dtype ostype | ostream( ostype ) ) 142 ostype * ?|?( 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 151 forall( dtype ostype | ostream( ostype ) ) 152 ostype * ?|?( 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 ); 97 184 } // ?|? 98 185 99 186 forall( dtype ostype | ostream( ostype ) ) 100 187 ostype * ?|?( 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 195 forall( dtype ostype | ostream( ostype ) ) 196 ostype * ?|?( ostype *os, ostype * (* manip)( ostype * ) ) { 197 return manip( os ); 198 } // ?|? 115 199 116 200 forall( dtype ostype | ostream( ostype ) ) 117 201 ostype * endl( ostype * os ) { 118 os | "\n";202 os | '\n'; 119 203 flush( os ); 204 sepOff( os ); 120 205 return os; 121 206 } // endl 122 207 208 forall( dtype ostype | ostream( ostype ) ) 209 ostype * sepOn( ostype * os ) { 210 sepOn( os ); 211 return os; 212 } // sepOn 213 214 forall( dtype ostype | ostream( ostype ) ) 215 ostype * sepOff( ostype * os ) { 216 sepOff( os ); 217 return os; 218 } // sepOff 219 220 forall( dtype ostype | ostream( ostype ) ) 221 ostype * sepEnable( ostype * os ) { 222 sepEnable( os ); 223 return os; 224 } // sepEnable 225 226 forall( dtype ostype | ostream( ostype ) ) 227 ostype * sepDisable( ostype * os ) { 228 sepDisable( os ); 229 return os; 230 } // sepDisable 231 123 232 //--------------------------------------- 124 233 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 | ' '; } 234 forall( otype elttype | writeable( elttype ), otype iteratortype | iterator( iteratortype, elttype ), dtype ostype | ostream( ostype ) ) 235 void write( iteratortype begin, iteratortype end, ostype *os ) { 236 void print( elttype i ) { os | i; } 129 237 for_each( begin, end, print ); 130 238 } // ?|? 131 239 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 | ' '; } 240 forall( otype elttype | writeable( elttype ), otype iteratortype | iterator( iteratortype, elttype ), dtype ostype | ostream( ostype ) ) 241 void write_reverse( iteratortype begin, iteratortype end, ostype *os ) { 242 void print( elttype i ) { os | i; } 136 243 for_each_reverse( begin, end, print ); 137 244 } // ?|? … … 140 247 141 248 forall( 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 } // ?|? 249 istype * ?|?( istype * is, char * c ) { 250 scanfmt( is, "%c", c ); 251 return is; 252 } // ?|? 253 254 forall( dtype istype | istream( istype ) ) 255 istype * ?|?( istype * is, short int * si ) { 256 scanfmt( is, "%hd", si ); 257 return is; 258 } // ?|? 259 260 forall( dtype istype | istream( istype ) ) 261 istype * ?|?( istype * is, unsigned short int * usi ) { 262 scanfmt( is, "%hu", usi ); 263 return is; 264 } // ?|? 265 266 forall( dtype istype | istream( istype ) ) 267 istype * ?|?( istype * is, int * i ) { 268 scanfmt( is, "%d", i ); 269 return is; 270 } // ?|? 271 272 forall( dtype istype | istream( istype ) ) 273 istype * ?|?( istype * is, unsigned int * ui ) { 274 scanfmt( is, "%u", ui ); 275 return is; 276 } // ?|? 277 278 forall( dtype istype | istream( istype ) ) 279 istype * ?|?( istype * is, long int * li ) { 280 scanfmt( is, "%ld", li ); 281 return is; 282 } // ?|? 283 284 forall( dtype istype | istream( istype ) ) 285 istype * ?|?( istype * is, unsigned long int * ulli ) { 286 scanfmt( is, "%lu", ulli ); 287 return is; 288 } // ?|? 289 290 forall( dtype istype | istream( istype ) ) 291 istype * ?|?( istype * is, long long int * lli ) { 292 scanfmt( is, "%lld", lli ); 293 return is; 294 } // ?|? 295 296 forall( dtype istype | istream( istype ) ) 297 istype * ?|?( istype * is, unsigned long long int * ulli ) { 298 scanfmt( is, "%llu", ulli ); 299 return is; 300 } // ?|? 301 302 303 forall( dtype istype | istream( istype ) ) 304 istype * ?|?( istype * is, float * f ) { 305 scanfmt( is, "%f", f ); 306 return is; 307 } // ?|? 308 309 forall( dtype istype | istream( istype ) ) 310 istype * ?|?( istype * is, double * d ) { 311 scanfmt( is, "%lf", d ); 312 return is; 313 } // ?|? 314 315 forall( dtype istype | istream( istype ) ) 316 istype * ?|?( istype * is, long double * ld ) { 317 scanfmt( is, "%Lf", ld ); 318 return is; 319 } // ?|? 320 321 322 forall( dtype istype | istream( istype ) ) 323 istype * ?|?( 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 330 forall( dtype istype | istream( istype ) ) 331 istype * ?|?( 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 338 forall( dtype istype | istream( istype ) ) 339 istype * ?|?( 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; } 347 forall( dtype istype | istream( istype ) ) 348 istype * ?|?( 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; } 354 forall( dtype istype | istream( istype ) ) 355 istype * ?|?( 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 150 361 151 362 // Local Variables: // -
src/libcfa/iterator
rc5833e8 r0f9e4403 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jan 27 23:49:13201613 // Update Count : 712 // Last Modified On : Wed Mar 2 18:06:05 2016 13 // Update Count : 9 14 14 // 15 15 … … 18 18 19 19 // An iterator can be used to traverse a data structure. 20 context iterator( type iterator_type,type elt_type ) {20 trait iterator( otype iterator_type, otype elt_type ) { 21 21 // point to the next element 22 22 // iterator_type ?++( iterator_type * ); … … 32 32 }; 33 33 34 context iterator_for( type iterator_type, type collection_type,type elt_type | iterator( iterator_type, elt_type ) ) {34 trait iterator_for( otype iterator_type, otype collection_type, otype elt_type | iterator( iterator_type, elt_type ) ) { 35 35 // [ iterator_type begin, iterator_type end ] get_iterators( collection_type ); 36 36 iterator_type begin( collection_type ); … … 38 38 }; 39 39 40 forall( type iterator_type,type elt_type | iterator( iterator_type, elt_type ) )40 forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) ) 41 41 void for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) ); 42 42 43 forall( type iterator_type,type elt_type | iterator( iterator_type, elt_type ) )43 forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) ) 44 44 void for_each_reverse( iterator_type begin, iterator_type end, void (*func)( elt_type ) ); 45 45 -
src/libcfa/iterator.c
rc5833e8 r0f9e4403 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jan 26 17:16:07201613 // Update Count : 2 612 // Last Modified On : Wed Mar 2 18:08:11 2016 13 // Update Count : 27 14 14 // 15 15 16 16 #include "iterator" 17 17 18 forall( type iterator_type,type elt_type | iterator( iterator_type, elt_type ) )18 forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) ) 19 19 void for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) ) { 20 20 for ( iterator_type i = begin; i != end; ++i ) { … … 23 23 } 24 24 25 forall( type iterator_type,type elt_type | iterator( iterator_type, elt_type ) )25 forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) ) 26 26 void for_each_reverse( iterator_type begin, iterator_type end, void (*func)( elt_type ) ) { 27 27 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 1 16 // Integral Constants 2 17 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;18 extern const short int MIN; 19 extern const int MIN; 20 extern const long int MIN; 21 extern const long long int MIN; 7 22 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;23 extern const short int MAX; 24 extern const unsigned short int MAX; 25 extern const int MAX; 26 extern const unsigned int MAX; 27 extern const long int MAX; 28 extern const unsigned long int MAX; 29 extern const long long int MAX; 30 extern const unsigned long long int MAX; 16 31 17 32 // Floating-Point Constants 18 33 19 const float PI = 3.141592_F;// pi20 const float PI_2 = 1.570796_F;// pi / 221 const float PI_4 = 0.7853981_F;// pi / 422 const float _1_PI = 0.3183098_F;// 1 / pi23 const float _2_PI = 0.6366197_F;// 2 / pi24 const float _2_SQRT_PI = 1.128379_F;// 2 / sqrt(pi)34 extern const float PI; // pi 35 extern const float PI_2; // pi / 2 36 extern const float PI_4; // pi / 4 37 extern const float _1_PI; // 1 / pi 38 extern const float _2_PI; // 2 / pi 39 extern const float _2_SQRT_PI; // 2 / sqrt(pi) 25 40 26 const double PI = 3.14159265358979323846_D;// pi27 const double PI_2 = 1.57079632679489661923_D;// pi / 228 const double PI_4 = 0.78539816339744830962_D;// pi / 429 const double _1_PI = 0.31830988618379067154_D;// 1 / pi30 const double _2_PI = 0.63661977236758134308_D;// 2 / pi31 const double _2_SQRT_PI = 1.12837916709551257390_D;// 2 / sqrt(pi)41 extern const double PI; // pi 42 extern const double PI_2; // pi / 2 43 extern const double PI_4; // pi / 4 44 extern const double _1_PI; // 1 / pi 45 extern const double _2_PI; // 2 / pi 46 extern const double _2_SQRT_PI; // 2 / sqrt(pi) 32 47 33 const long double PI = 3.1415926535897932384626433832795029_DL;// pi34 const long double PI_2 = 1.5707963267948966192313216916397514_DL;// pi / 235 const long double PI_4 = 0.7853981633974483096156608458198757_DL;// pi / 436 const long double _1_PI = 0.3183098861837906715377675267450287_DL;// 1 / pi37 const long double _2_PI = 0.6366197723675813430755350534900574_DL;// 2 / pi38 const long double _2_SQRT_PI = 1.1283791670955125738961589031215452_DL;// 2 / sqrt(pi)48 extern const long double PI; // pi 49 extern const long double PI_2; // pi / 2 50 extern const long double PI_4; // pi / 4 51 extern const long double _1_PI; // 1 / pi 52 extern const long double _2_PI; // 2 / pi 53 extern const long double _2_SQRT_PI; // 2 / sqrt(pi) 39 54 40 const _Complex PI = 3.14159265358979323846_D+0.0_iD;// pi41 const _Complex PI_2 = 1.57079632679489661923_D+0.0_iD;// pi / 242 const _Complex PI_4 = 0.78539816339744830962_D+0.0_iD;// pi / 443 const _Complex _1_PI = 0.31830988618379067154_D+0.0_iD;// 1 / pi44 const _Complex _2_PI = 0.63661977236758134308_D+0.0_iD;// 2 / pi45 const _Complex _2_SQRT_PI = 1.12837916709551257390_D+0.0_iD;// 2 / sqrt(pi)55 extern const _Complex PI; // pi 56 extern const _Complex PI_2; // pi / 2 57 extern const _Complex PI_4; // pi / 4 58 extern const _Complex _1_PI; // 1 / pi 59 extern const _Complex _2_PI; // 2 / pi 60 extern const _Complex _2_SQRT_PI; // 2 / sqrt(pi) 46 61 47 const long _Complex PI = 3.1415926535897932384626433832795029_L+0.0iL;// pi48 const long _Complex PI_2 = 1.5707963267948966192313216916397514_L+0.0iL;// pi / 249 const long _Complex PI_4 = 0.7853981633974483096156608458198757_L+0.0iL;// pi / 450 const long _Complex _1_PI = 0.3183098861837906715377675267450287_L+0.0iL;// 1 / pi51 const long _Complex _2_PI = 0.6366197723675813430755350534900574_L+0.0iL;// 2 / pi52 const long _Complex _2_SQRT_PI = 1.1283791670955125738961589031215452_L+0.0iL;// 2 / sqrt(pi)62 extern const long _Complex PI; // pi 63 extern const long _Complex PI_2; // pi / 2 64 extern const long _Complex PI_4; // pi / 4 65 extern const long _Complex _1_PI; // 1 / pi 66 extern const long _Complex _2_PI; // 2 / pi 67 extern const long _Complex _2_SQRT_PI; // 2 / sqrt(pi) 53 68 54 const float E = 2.718281;// e55 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)69 extern const float E; // e 70 extern const float LOG2_E; // log_2(e) 71 extern const float LOG10_E; // log_10(e) 72 extern const float LN_2; // log_e(2) 73 extern const float LN_10; // log_e(10) 74 extern const float SQRT_2; // sqrt(2) 75 extern const float _1_SQRT_2; // 1 / sqrt(2) 61 76 62 const double E = 2.7182818284590452354_D;// e63 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)77 extern const double E; // e 78 extern const double LOG2_E; // log_2(e) 79 extern const double LOG10_E; // log_10(e) 80 extern const double LN_2; // log_e(2) 81 extern const double LN_10; // log_e(10) 82 extern const double SQRT_2; // sqrt(2) 83 extern const double _1_SQRT_2; // 1 / sqrt(2) 69 84 70 const long double E = 2.7182818284590452353602874713526625_DL;// e71 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)85 extern const long double E; // e 86 extern const long double LOG2_E; // log_2(e) 87 extern const long double LOG10_E; // log_10(e) 88 extern const long double LN_2; // log_e(2) 89 extern const long double LN_10; // log_e(10) 90 extern const long double SQRT_2; // sqrt(2) 91 extern const long double _1_SQRT_2; // 1/sqrt(2) 77 92 78 const _Complex E = 2.7182818284590452354_D+0.0_iD;// e79 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)93 extern const _Complex E; // e 94 extern const _Complex LOG2_E; // log_2(e) 95 extern const _Complex LOG10_E; // log_10(e) 96 extern const _Complex LN_2; // log_e(2) 97 extern const _Complex LN_10; // log_e(10) 98 extern const _Complex SQRT_2; // sqrt(2) 99 extern const _Complex _1_SQRT_2; // 1 / sqrt(2) 85 100 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) 101 extern const long _Complex E; // e 102 extern const long _Complex LOG2_E; // log_2(e) 103 extern const long _Complex LOG10_E; // log_10(e) 104 extern const long _Complex LN_2; // log_e(2) 105 extern const long _Complex LN_10; // log_e(10) 106 extern const long _Complex SQRT_2; // sqrt(2) 107 extern 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 1 2 // -*- Mode: C -*- 2 3 // … … 8 9 // Created On : Sat Nov 29 07:23:41 2014 9 10 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Mon Jan 4 11:13:26201611 // Update Count : 8 111 // Last Modified On : Wed Mar 2 18:03:41 2016 12 // Update Count : 89 12 13 // 13 14 … … 63 64 long double _Complex ?--( long double _Complex * ), ?--( volatile long double _Complex * ); 64 65 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 * );66 forall( otype T ) T * ?++( T ** ); 67 forall( otype T ) const T * ?++( const T ** ); 68 forall( otype T ) volatile T * ?++( volatile T ** ); 69 forall( otype T ) const volatile T * ?++( const volatile T ** ); 70 forall( otype T ) T * ?--( T ** ); 71 forall( otype T ) const T * ?--( const T ** ); 72 forall( otype T ) volatile T * ?--( volatile T ** ); 73 forall( otype T ) const volatile T * ?--( const volatile T ** ); 74 75 forall( otype T ) lvalue T ?[?]( T *, ptrdiff_t ); 76 forall( otype T ) const lvalue T ?[?]( const T *, ptrdiff_t ); 77 forall( otype T ) volatile lvalue T ?[?]( volatile T *, ptrdiff_t ); 78 forall( otype T ) const volatile lvalue T ?[?]( const volatile T *, ptrdiff_t ); 79 forall( otype T ) lvalue T ?[?]( ptrdiff_t, T * ); 80 forall( otype T ) const lvalue T ?[?]( ptrdiff_t, const T * ); 81 forall( otype T ) volatile lvalue T ?[?]( ptrdiff_t, volatile T * ); 82 forall( otype T ) const volatile lvalue T ?[?]( ptrdiff_t, const volatile T * ); 82 83 83 84 // ------------------------------------------------------------ … … 101 102 long double _Complex ++?( long double _Complex * ), --?( long double _Complex * ); 102 103 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 * );104 forall( otype T ) T * ++?( T ** ); 105 forall( otype T ) const T * ++?( const T ** ); 106 forall( otype T ) volatile T * ++?( volatile T ** ); 107 forall( otype T ) const volatile T * ++?( const volatile T ** ); 108 forall( otype T ) T * --?( T ** ); 109 forall( otype T ) const T * --?( const T ** ); 110 forall( otype T ) volatile T * --?( volatile T ** ); 111 forall( otype T ) const volatile T * --?( const volatile T ** ); 112 113 forall( otype T ) lvalue T *?( T * ); 114 forall( otype T ) const lvalue T *?( const T * ); 115 forall( otype T ) volatile lvalue T *?( volatile T * ); 116 forall( otype T ) const volatile lvalue T *?( const volatile T * ); 116 117 forall( ftype FT ) lvalue FT *?( FT * ); 117 118 … … 183 184 long double _Complex ?+?( long double _Complex, long double _Complex ), ?-?( long double _Complex, long double _Complex ); 184 185 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 * );186 forall( otype T ) T * ?+?( T *, ptrdiff_t ); 187 forall( otype T ) T * ?+?( ptrdiff_t, T * ); 188 forall( otype T ) const T * ?+?( const T *, ptrdiff_t ); 189 forall( otype T ) const T * ?+?( ptrdiff_t, const T * ); 190 forall( otype T ) volatile T * ?+?( volatile T *, ptrdiff_t ); 191 forall( otype T ) volatile T * ?+?( ptrdiff_t, volatile T * ); 192 forall( otype T ) const volatile T * ?+?( const volatile T *, ptrdiff_t ); 193 forall( otype T ) const volatile T * ?+?( ptrdiff_t, const volatile T * ); 194 forall( otype T ) T * ?-?( T *, ptrdiff_t ); 195 forall( otype T ) const T * ?-?( const T *, ptrdiff_t ); 196 forall( otype T ) volatile T * ?-?( volatile T *, ptrdiff_t ); 197 forall( otype T ) const volatile T * ?-?( const volatile T *, ptrdiff_t ); 198 forall( otype T ) ptrdiff_t ?-?( const volatile T *, const volatile T * ); 198 199 199 200 // ------------------------------------------------------------ … … 431 432 forall( ftype FT ) FT * ?=?( FT * volatile *, forall( ftype FT2 ) FT2 * ); 432 433 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 );434 forall( otype T ) T * ?+=?( T * *, ptrdiff_t ); 435 forall( otype T ) T * ?+=?( T * volatile *, ptrdiff_t ); 436 forall( otype T ) const T * ?+=?( const T * *, ptrdiff_t ); 437 forall( otype T ) const T * ?+=?( const T * volatile *, ptrdiff_t ); 438 forall( otype T ) volatile T * ?+=?( volatile T * *, ptrdiff_t ); 439 forall( otype T ) volatile T * ?+=?( volatile T * volatile *, ptrdiff_t ); 440 forall( otype T ) const volatile T * ?+=?( const volatile T * *, ptrdiff_t ); 441 forall( otype T ) const volatile T * ?+=?( const volatile T * volatile *, ptrdiff_t ); 442 forall( otype T ) T * ?-=?( T * *, ptrdiff_t ); 443 forall( otype T ) T * ?-=?( T * volatile *, ptrdiff_t ); 444 forall( otype T ) const T * ?-=?( const T * *, ptrdiff_t ); 445 forall( otype T ) const T * ?-=?( const T * volatile *, ptrdiff_t ); 446 forall( otype T ) volatile T * ?-=?( volatile T * *, ptrdiff_t ); 447 forall( otype T ) volatile T * ?-=?( volatile T * volatile *, ptrdiff_t ); 448 forall( otype T ) const volatile T * ?-=?( const volatile T * *, ptrdiff_t ); 449 forall( otype T ) const volatile T * ?-=?( const volatile T * volatile *, ptrdiff_t ); 449 450 450 451 _Bool ?=?( _Bool *, _Bool ), ?=?( volatile _Bool *, _Bool ); -
src/libcfa/stdlib
rc5833e8 r0f9e4403 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Feb 5 15:21:18201613 // Update Count : 6112 // Last Modified On : Wed Apr 13 14:45:53 2016 13 // Update Count : 85 14 14 // 15 15 … … 20 20 } // extern "C" 21 21 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 //--------------------------------------- 24 23 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 ); 24 extern "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 29 void exit( int rc ); 30 } // extern "C" 33 31 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 34 extern "C" { 35 void * malloc( size_t ); // use default C routine for void * 36 } // extern "C" 37 forall( otype T ) T * malloc( void ); 38 forall( otype T ) T * malloc( char fill ); 39 forall( otype T ) T * malloc( T * ptr, size_t size ); 40 forall( 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" 44 forall( 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" 48 forall( otype T ) T * realloc( T * ptr, size_t size ); 49 forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill ); 50 51 forall( otype T ) T * aligned_alloc( size_t alignment ); 52 forall( otype T ) T * memalign( size_t alignment ); // deprecated 53 forall( otype T ) int posix_memalign( T ** ptr, size_t alignment ); 54 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 37 57 38 58 //--------------------------------------- … … 66 86 //--------------------------------------- 67 87 68 forall( type T | { int ?<?( T, T ); } )88 forall( otype T | { int ?<?( T, T ); } ) 69 89 T * bsearch( const T key, const T * arr, size_t dimension ); 70 90 71 forall( type T | { int ?<?( T, T ); } )91 forall( otype T | { int ?<?( T, T ); } ) 72 92 void qsort( const T * arr, size_t dimension ); 73 93 74 94 //--------------------------------------- 75 95 76 forall( type T | { T ?/?( T, T ); T ?%?( T, T ); } )96 forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } ) 77 97 [ T, T ] div( T t1, T t2 ); 78 98 … … 81 101 char abs( char ); 82 102 extern "C" { 83 int abs( int ); // use default C routine for int84 } // extern 103 int abs( int ); // use default C routine for int 104 } // extern "C" 85 105 long int abs( long int ); 86 106 long long int abs( long long int ); … … 94 114 //--------------------------------------- 95 115 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();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 ); 107 127 108 128 //--------------------------------------- 109 129 110 forall( type T | { int ?<?( T, T ); } ) 130 void rand48seed( long int s ); 131 char rand48(); 132 int rand48(); 133 unsigned int rand48(); 134 long int rand48(); 135 unsigned long int rand48(); 136 float rand48(); 137 double rand48(); 138 float _Complex rand48(); 139 double _Complex rand48(); 140 long double _Complex rand48(); 141 142 //--------------------------------------- 143 144 forall( otype T | { int ?<?( T, T ); } ) 111 145 T min( const T t1, const T t2 ); 112 146 113 forall( type T | { int ?>?( T, T ); } )147 forall( otype T | { int ?>?( T, T ); } ) 114 148 T max( const T t1, const T t2 ); 115 149 116 forall( type T )150 forall( otype T ) 117 151 void swap( T * t1, T * t2 ); 118 152 -
src/libcfa/stdlib.c
rc5833e8 r0f9e4403 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 10 15:45:56201613 // Update Count : 1 4012 // Last Modified On : Wed Apr 13 14:49:58 2016 13 // Update Count : 155 14 14 // 15 15 … … 27 27 } // extern "C" 28 28 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" ); 29 forall( otype T ) T * malloc( void ) { 30 //printf( "malloc1\n" ); 40 31 return (T *)malloc( sizeof(T) ); 41 32 } // 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" ); 33 forall( otype T ) T * malloc( char fill ) { 34 //printf( "malloc3\n" ); 48 35 T * ptr = (T *)malloc( sizeof(T) ); 49 36 return memset( ptr ); 50 37 } // malloc 51 38 52 forall( type T ) T * calloc( size_t size) {53 printf( "calloc\n" );54 return (T *)calloc( size, sizeof(T) );39 forall( otype T ) T * calloc( size_t nmemb ) { 40 //printf( "calloc\n" ); 41 return (T *)calloc( nmemb, sizeof(T) ); 55 42 } // calloc 56 43 57 forall( type T ) T * realloc( T * ptr, size_t size ) {58 printf( "realloc1\n" );44 forall( otype T ) T * realloc( T * ptr, size_t size ) { 45 //printf( "realloc1\n" ); 59 46 return (T *)(void *)realloc( (void *)ptr, size ); 60 47 } // realloc 61 forall( type T ) T * realloc( T * ptr, size_t size, unsigned char fill ) {62 printf( "realloc2\n" );48 forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill ) { 49 //printf( "realloc2\n" ); 63 50 char * nptr = (T *)(void *)realloc( (void *)ptr, size ); 64 51 size_t unused = malloc_usable_size( nptr ); … … 67 54 } // realloc 68 55 69 forall( type T ) T * malloc( T * ptr, size_t size ) {70 printf( "malloc4\n" );56 forall( otype T ) T * malloc( T * ptr, size_t size ) { 57 //printf( "malloc4\n" ); 71 58 return (T *)realloc( ptr, size ); 72 59 } // malloc 73 forall( type T ) T * malloc( T * ptr, size_t size, unsigned char fill ) {74 printf( "malloc5\n" );60 forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill ) { 61 //printf( "malloc5\n" ); 75 62 return (T *)realloc( ptr, size, fill ); 76 63 } // malloc 77 64 78 forall( type T ) T * aligned_alloc( size_t alignment ) {79 printf( "aligned_alloc\n" );65 forall( otype T ) T * aligned_alloc( size_t alignment ) { 66 //printf( "aligned_alloc\n" ); 80 67 return (T *)memalign( alignment, sizeof(T) ); 81 68 } // aligned_alloc 82 69 83 forall( type T ) T * memalign( size_t alignment ) {84 printf( "memalign\n" );70 forall( otype T ) T * memalign( size_t alignment ) { 71 //printf( "memalign\n" ); 85 72 return (T *)memalign( alignment, sizeof(T) ); 86 73 } // memalign 87 74 88 forall( type T ) int posix_memalign( T ** ptr, size_t alignment ) {89 printf( "posix_memalign\n" );75 forall( otype T ) int posix_memalign( T ** ptr, size_t alignment ) { 76 //printf( "posix_memalign\n" ); 90 77 return posix_memalign( (void **)ptr, alignment, sizeof(T) ); 91 78 } // posix_memalign 79 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 92 88 93 89 //--------------------------------------- … … 123 119 return ulli; 124 120 } 121 125 122 float ato( const char * ptr ) { 126 123 float f; … … 138 135 return ld; 139 136 } 137 140 138 float _Complex ato( const char * ptr ) { 141 139 float re, im; … … 172 170 return strtoull( sptr, eptr, base ); 173 171 } 172 174 173 float strto( const char * sptr, char ** eptr ) { 175 174 return strtof( sptr, eptr ); … … 181 180 return strtold( sptr, eptr ); 182 181 } 182 183 183 float _Complex strto( const char * sptr, char ** eptr ) { 184 184 float re, im; … … 208 208 //--------------------------------------- 209 209 210 forall( type T | { int ?<?( T, T ); } )210 forall( otype T | { int ?<?( T, T ); } ) 211 211 T * bsearch( const T key, const T * arr, size_t dimension ) { 212 212 int comp( const void * t1, const void * t2 ) { return *(T *)t1 < *(T *)t2 ? -1 : *(T *)t2 < *(T *)t1 ? 1 : 0; } … … 214 214 } // bsearch 215 215 216 forall( type T | { int ?<?( T, T ); } )216 forall( otype T | { int ?<?( T, T ); } ) 217 217 void qsort( const T * arr, size_t dimension ) { 218 218 int comp( const void * t1, const void * t2 ) { return *(T *)t1 < *(T *)t2 ? -1 : *(T *)t2 < *(T *)t1 ? 1 : 0; } … … 222 222 //--------------------------------------- 223 223 224 forall( type T | { T ?/?( T, T ); T ?%?( T, T ); } )224 forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } ) 225 225 [ T, T ] div( T t1, T t2 ) { /* return [ t1 / t2, t1 % t2 ]; */ } 226 226 … … 239 239 //--------------------------------------- 240 240 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 ); } ) 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 ); } 246 247 //--------------------------------------- 248 249 void rand48seed( long int s ) { srand48( s ); } 250 char rand48() { return mrand48(); } 251 int rand48() { return mrand48(); } 252 unsigned int rand48() { return lrand48(); } 253 long int rand48() { return mrand48(); } 254 unsigned long int rand48() { return lrand48(); } 255 float rand48() { return (float)drand48(); } // otherwise float uses lrand48 256 double rand48() { return drand48(); } 257 float _Complex rand48() { return (float)drand48() + (float _Complex)(drand48() * _Complex_I); } 258 double _Complex rand48() { return drand48() + (double _Complex)(drand48() * _Complex_I); } 259 long double _Complex rand48() { return (long double)drand48() + (long double _Complex)(drand48() * _Complex_I); } 260 261 //--------------------------------------- 262 263 forall( otype T | { int ?<?( T, T ); } ) 256 264 T min( const T t1, const T t2 ) { 257 265 return t1 < t2 ? t1 : t2; 258 266 } // min 259 267 260 forall( type T | { int ?>?( T, T ); } )268 forall( otype T | { int ?>?( T, T ); } ) 261 269 T max( const T t1, const T t2 ) { 262 270 return t1 > t2 ? t1 : t2; 263 271 } // max 264 272 265 forall( type T )273 forall( otype T ) 266 274 void swap( T * t1, T * t2 ) { 267 275 T temp = *t1;
Note:
See TracChangeset
for help on using the changeset viewer.