Changeset a5a71d0 for src/libcfa


Ignore:
Timestamp:
Apr 6, 2016, 5:11:32 PM (10 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
eab39cd
Parents:
39786813 (diff), 3aba311 (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 'fix-memory-error' into ctor

Conflicts:

src/CodeGen/CodeGenerator.cc
src/Makefile.in
src/Parser/DeclarationNode.cc
src/Parser/ParseNode.h
src/Parser/TypeData.cc
src/Parser/parser.cc
src/Parser/parser.yy
src/ResolvExpr/Resolver.cc
src/SymTab/Validate.cc
src/SynTree/Declaration.h
src/SynTree/Mutator.cc
src/SynTree/Mutator.h
src/SynTree/SynTree.h
src/SynTree/Visitor.cc
src/SynTree/Visitor.h
src/libcfa/prelude.cf

Location:
src/libcfa
Files:
11 deleted
12 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/Makefile.am

    r39786813 ra5a71d0  
    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 Mar  2 22:59:23 2016
     14## Update Count     : 119
    1515###############################################################################
    1616
     
    6363libcfa_a_SOURCES = libcfa-prelude.c ${libs:=.c}
    6464
    65 cheaders = bfd bfdlink demangle dialog evdns evhttp evrpc expat fcntl form gcrypt math
     65cheaders = #  expat
    6666cfaheaders = limits
    6767include_HEADERS = ${cheaders:=.h} ${libs} ${cfaheaders}
  • src/libcfa/Makefile.in

    r39786813 ra5a71d0  
    215215libs = stdlib iostream fstream iterator
    216216libcfa_a_SOURCES = libcfa-prelude.c ${libs:=.c}
    217 cheaders = bfd bfdlink demangle dialog evdns evhttp evrpc expat fcntl form gcrypt math
     217cheaders = #  expat
    218218cfaheaders = limits
    219219include_HEADERS = ${cheaders:=.h} ${libs} ${cfaheaders}
     
    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
  • src/libcfa/builtins.cf

    r39786813 ra5a71d0  
    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

    r39786813 ra5a71d0  
    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 : Wed Mar  2 15:08:14 2016
     13// Update Count     : 78
    1414//
    1515
     
    1919#include "iostream"
    2020
    21 // implement context ostream
    22 struct ofstream;
     21enum { separateSize = 16 };
     22struct ofstream { void *file; int separate; char separator[separateSize]; };
    2323
    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 );
     24_Bool sepPrt( ofstream * );
     25void sepOn( ofstream * );
     26void sepOff( ofstream * );
     27void sepSet( ofstream *, const char * );
     28const char * sepGet( ofstream * );
     29void sepDisable( ofstream * );
     30void sepEnable( ofstream * );
     31int fail( ofstream * );
     32int flush( ofstream * );
     33void open( ofstream *, const char * name, const char * mode );
     34void close( ofstream * );
     35ofstream * write( ofstream *, const char * data, unsigned long int size );
     36int prtfmt( ofstream *, const char fmt[], ... );
    2937
    3038extern ofstream * sout, * serr;
    3139
    3240// implement context istream
    33 struct ifstream;
     41struct ifstream { void *file; };
    3442
    3543int fail( ifstream * is );
    3644int eof( ifstream * is );
    37 void open( ifstream ** is, const char * name, const char * mode );
     45void open( ifstream * is, const char * name, const char * mode );
    3846void close( ifstream * is );
    39 ifstream * get( ifstream * is, int * data );
    40 ifstream * read( ifstream * is, char * data, streamsize_type size );
     47ifstream * read( ifstream * is, char * data, unsigned long int size );
    4148ifstream * ungetc( ifstream * is, char c );
     49int scanfmt( ifstream *, const char fmt[], ... );
    4250
    4351extern ifstream *sin;
     
    4957// tab-width: 4 //
    5058// End: //
     59
  • src/libcfa/fstream.c

    r39786813 ra5a71d0  
    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 : Mon Feb 29 18:41:10 2016
     13// Update Count     : 162
    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}
    22 
    23 struct ofstream {
    24         FILE *file;
    25 };
    2626
    2727#define IO_MSG "I/O error "
    2828
     29_Bool sepPrt( ofstream * os ) { return os->separate == 1; }
     30void sepOn( ofstream * os ) { if ( os->separate != 2 ) os->separate = 1; }
     31void sepOff( ofstream * os ) { if ( os->separate != 2 ) os->separate = 0; }
     32void sepSet( ofstream * os, const char * s ) {
     33        strncpy( &(os->separator[0]), s, separateSize - 1 );
     34        os->separator[separateSize - 1] = '\0';
     35} // sepSet
     36const char * sepGet( ofstream * os ) { return &(os->separator[0]); }
     37void sepDisable( ofstream *os ) { os->separate = 2; }
     38void sepEnable( ofstream *os ) { os->separate = 0; }
     39
    2940int fail( ofstream * os ) {
    30         return ferror( os->file );
     41        return ferror( (FILE *)(os->file) );
    3142} // fail
    3243
    3344int flush( ofstream * os ) {
    34         return fflush( os->file );
     45        return fflush( (FILE *)(os->file) );
    3546} // flush
    3647
    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
     48void open( ofstream * os, const char * name, const char * mode ) {
     49        FILE *file = fopen( name, mode );
     50        if ( file == 0 ) {                                                                      // do not change unless successful
    4051                perror( IO_MSG "open output" );
    4152                exit( EXIT_FAILURE );
    4253        } // if
    43         (*os)->file = t;
     54        os->file = file;
     55        sepOff( os );
     56        sepSet( os, " " );
    4457} // open
    4558
    4659void close( ofstream * os ) {
    47         if ( os->file == stdout || os->file == stderr ) return;
     60        if ( (FILE *)(os->file) == stdout || (FILE *)(os->file) == stderr ) return;
    4861
    49         if ( fclose( os->file ) == EOF ) {
     62        if ( fclose( (FILE *)(os->file) ) == EOF ) {
    5063                perror( IO_MSG "close output" );
    5164        } // if
    5265} // close
    5366
    54 ofstream * write( ofstream * os, const char * data, streamsize_type size ) {
     67ofstream * write( ofstream * os, const char * data, unsigned long int size ) {
    5568        if ( fail( os ) ) {
    5669                fprintf( stderr, "attempt write I/O on failed stream\n" );
     
    5871        } // if
    5972
    60         if ( fwrite( data, 1, size, os->file ) != size ) {
     73        if ( fwrite( data, 1, size, (FILE *)(os->file) ) != size ) {
    6174                perror( IO_MSG "write" );
    6275                exit( EXIT_FAILURE );
     
    6578} // write
    6679
    67 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_) };
     80int prtfmt( ofstream * os, const char fmt[], ... ) {
     81    va_list args;
     82
     83    va_start( args, fmt );
     84    int len = vfprintf( (FILE *)(os->file), fmt, args );
     85        if ( len == EOF ) {
     86                if ( ferror( (FILE *)(os->file) ) ) {
     87                        fprintf( stderr, "invalid write\n" );
     88                        exit( EXIT_FAILURE );
     89                } // if
     90        } // if
     91    va_end( args );
     92        return len;
     93} // prtfmt
     94
     95
     96static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), 0, { ' ', '\0' } };
    6897ofstream *sout = &soutFile;
    69 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_) };
     98static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), 0, { ' ', '\0' } };
    7099ofstream *serr = &serrFile;
     100
    71101
    72102//---------------------------------------
    73103
    74 struct ifstream {
    75         FILE *file;
    76 };
    77104
    78105int fail( ifstream * is ) {
    79         return ferror( is->file );
     106        return ferror( (FILE *)(is->file) );
    80107} // fail
    81108
    82109int eof( ifstream * is ) {
    83         return feof( is->file );
     110        return feof( (FILE *)(is->file) );
    84111} // eof
    85112
    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
     113void open( ifstream * is, const char * name, const char * mode ) {
     114        FILE *t = fopen( name, mode );
     115        if ( t == 0 ) {                                                                         // do not change unless successful
     116                perror( IO_MSG "open input" );
     117                exit( EXIT_FAILURE );
    92118        } // if
    93         return is;
    94 } // read
     119        is->file = t;
     120} // open
    95121
    96 ifstream * read( ifstream * is, char * data, streamsize_type size ) {
     122void close( ifstream * is ) {
     123        if ( (FILE *)(is->file) == stdin ) return;
     124
     125        if ( fclose( (FILE *)(is->file) ) == EOF ) {
     126                perror( IO_MSG "close input" );
     127        } // if
     128} // close
     129
     130ifstream * read( ifstream * is, char * data, unsigned long int size ) {
    97131        if ( fail( is ) ) {
    98132                fprintf( stderr, "attempt read I/O on failed stream\n" );
     
    100134        } // if
    101135
    102         if ( fread( data, size, 1, is->file ) == 0 ) {
     136        if ( fread( data, size, 1, (FILE *)(is->file) ) == 0 ) {
    103137                perror( IO_MSG "read" );
    104138                exit( EXIT_FAILURE );
     
    113147        } // if
    114148
    115         if ( ungetc( c, is->file ) == EOF ) {
     149        if ( ungetc( c, (FILE *)(is->file) ) == EOF ) {
    116150                perror( IO_MSG "ungetc" );
    117151                exit( EXIT_FAILURE );
     
    120154} // ungetc
    121155
    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 );
     156int scanfmt( ifstream * is, const char fmt[], ... ) {
     157    va_list args;
     158
     159    va_start( args, fmt );
     160    int len = vfscanf( (FILE *)(is->file), fmt, args );
     161        if ( len == EOF ) {
     162                if ( ferror( (FILE *)(is->file) ) ) {
     163                        fprintf( stderr, "invalid read\n" );
     164                        exit( EXIT_FAILURE );
     165                } // if
    127166        } // if
    128         (*is)->file = t;
    129 } // open
     167    va_end( args );
     168        return len;
     169} // prtfmt
    130170
    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
    138171
    139172static ifstream sinFile = { (FILE *)(&_IO_2_1_stdin_) };
  • src/libcfa/iostream

    r39786813 ra5a71d0  
    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 : Wed Mar  2 18:05:27 2016
     13// Update Count     : 85
    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;
    22 
    23 context ostream( dtype ostype ) {
     21trait ostream( dtype ostype ) {
     22        _Bool sepPrt( ostype * );
     23        void sepOn( ostype * );
     24        void sepOff( ostype * );
     25        void sepSet( ostype *, const char * );
     26        const char * sepGet( ostype * );
     27        void sepDisable( ostype * );
     28        void sepEnable( ostype * );
    2429        int fail( ostype * );
    2530        int flush( ostype * );
    26         ostype * write( ostype *, const char *, streamsize_type );
     31        void open( ostype * os, const char * name, const char * mode );
     32        void close( ostype * os );
     33        ostype * write( ostype *, const char *, unsigned long int );
     34        int prtfmt( ostype *, const char fmt[], ... );
    2735};
    28 context writeable( type T ) {
     36
     37trait writeable( otype T ) {
    2938        forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, T );
    3039};
     
    3342
    3443forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, char );
     44
     45forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, short int );
     46forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned short int );
    3547forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, int );
    3648forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned int );
     
    3951forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned long int );
    4052forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned long long int );
     53
    4154forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, float ); // FIX ME: should not be required
    4255forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, double );
    4356forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, long double );
     57
    4458forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, float _Complex );
    4559forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, double _Complex );
    4660forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, long double _Complex );
     61
    4762forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, const char * );
    4863forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, const void * );
    4964
    50 forall( dtype ostype, dtype retostype | ostream( ostype ) | ostream( retostype ) ) retostype * ?|?( ostype *os, retostype * (* manip)(ostype*) );
     65forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, ostype * (*)( ostype * ) );
    5166forall( dtype ostype | ostream( ostype ) ) ostype * endl( ostype * );
     67forall( dtype ostype | ostream( ostype ) ) ostype * sepOn( ostype * );
     68forall( dtype ostype | ostream( ostype ) ) ostype * sepOff( ostype * );
    5269
    5370// 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 ) )
     71forall( otype elt_type | writeable( elt_type ), otype iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) )
    5572void write( iterator_type begin, iterator_type end, os_type *os );
    5673
    57 forall( type elt_type | writeable( elt_type ), type iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) )
     74forall( otype elt_type | writeable( elt_type ), otype iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) )
    5875void write_reverse( iterator_type begin, iterator_type end, os_type *os );
    5976
    6077//---------------------------------------
    6178
    62 context istream( dtype istype ) {
     79trait istream( dtype istype ) {
    6380        int fail( istype * );
    6481        int eof( istype * );
    65         istype * get( istype *, int * );
    66         istype * read( istype *, char *, streamsize_type );
     82        void open( istype * is, const char * name, const char * mode );
     83        void close( istype * is );
     84        istype * read( istype *, char *, unsigned long int );
    6785        istype * ungetc( istype *, char );
     86        int scanfmt( istype *, const char fmt[], ... );
    6887};
    6988
    70 context readable( type T ) {
     89trait readable( otype T ) {
    7190        forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, T );
    7291};
    7392
    74 forall( dtype istype | istream( istype ) )
    75 istype * ?|?( istype *, char * );
     93forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, char * );
    7694
    77 forall( dtype istype | istream( istype ) )
    78 istype * ?|?( istype *, int * );
     95forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, short int * );
     96forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned short int * );
     97forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, int * );
     98forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned int * );
     99forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long int * );
     100forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long long int * );
     101forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned long int * );
     102forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned long long int * );
    79103
    80 #endif // IOSTREAM_H
     104forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, float * );
     105forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, double * );
     106forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long double * );
     107
     108forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, float _Complex * );
     109forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, double _Complex * );
     110forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long double _Complex * );
     111
     112struct _Istream_str1 { char * s; };
     113_Istream_str1 str( char * );
     114forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, _Istream_str1 );
     115
     116struct _Istream_str2 { char * s; int size; };
     117_Istream_str2 str( char *, int size );
     118forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, _Istream_str2 );
     119
     120#endif // __IOSTREAM_H__
    81121
    82122// Local Variables: //
  • src/libcfa/iostream.c

    r39786813 ra5a71d0  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // iostream.c -- 
    8 //
    9 // Author           : Richard C. Bilson
     7// iostream.c --
     8//
     9// Author           : Peter A. Buhr
    1010// Created On       : Wed May 27 17:56:53 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 14:19:56 2016
    13 // Update Count     : 76
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Apr 06 14:42:52 2016
     13// Update Count     : 227
    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        return os;
     30} // ?|?
     31
     32forall( dtype ostype | ostream( ostype ) )
     33ostype * ?|?( ostype *os, short int si ) {
     34        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     35        prtfmt( os, "%hd", si );
     36        return os;
     37} // ?|?
     38
     39forall( dtype ostype | ostream( ostype ) )
     40ostype * ?|?( ostype *os, unsigned short int usi ) {
     41        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     42        prtfmt( os, "%hu", usi );
     43        return os;
    2844} // ?|?
    2945
    3046forall( dtype ostype | ostream( ostype ) )
    3147ostype * ?|?( 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 ) );
     48        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     49        prtfmt( os, "%d", i );
     50        return os;
     51} // ?|?
     52
     53forall( dtype ostype | ostream( ostype ) )
     54ostype * ?|?( ostype *os, unsigned int ui ) {
     55        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     56        prtfmt( os, "%u", ui );
     57        return os;
     58} // ?|?
     59
     60forall( dtype ostype | ostream( ostype ) )
     61ostype * ?|?( ostype *os, long int li ) {
     62        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     63        prtfmt( os, "%ld", li );
     64        return os;
     65} // ?|?
     66
     67forall( dtype ostype | ostream( ostype ) )
     68ostype * ?|?( ostype *os, unsigned long int uli ) {
     69        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     70        prtfmt( os, "%lu", uli );
     71        return os;
     72} // ?|?
     73
     74forall( dtype ostype | ostream( ostype ) )
     75ostype * ?|?( ostype *os, long long int lli ) {
     76        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     77        prtfmt( os, "%lld", lli );
     78        return os;
     79} // ?|?
     80
     81forall( dtype ostype | ostream( ostype ) )
     82ostype * ?|?( ostype *os, unsigned long long int ulli ) {
     83        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     84        prtfmt( os, "%llu", ulli );
     85        return os;
    6486} // ?|?
    6587
    6688forall( dtype ostype | ostream( ostype ) )
    6789ostype * ?|?( ostype *os, float f ) {
    68         char buffer[32];
    69         return write( os, buffer, sprintf( buffer, "%g", f ) );
     90        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     91        prtfmt( os, "%g", f );
     92        return os;
    7093} // ?|?
    7194
    7295forall( dtype ostype | ostream( ostype ) )
    7396ostype * ?|?( 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';
     97        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     98        prtfmt( os, "%.*lg", DBL_DIG, d );
     99        return os;
     100} // ?|?
     101
     102forall( dtype ostype | ostream( ostype ) )
     103ostype * ?|?( ostype *os, long double ld ) {
     104        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     105        prtfmt( os, "%.*Lg", LDBL_DIG, ld );
     106        return os;
     107} // ?|?
     108
     109forall( dtype ostype | ostream( ostype ) )
     110ostype * ?|?( ostype *os, float _Complex fc ) {
     111        os | crealf( fc );
     112        if ( cimagf( fc ) >= 0 ) os | '+';
     113        os | "" | cimagf( fc ) | 'i';
     114        return os;
     115} // ?|?
     116
     117forall( dtype ostype | ostream( ostype ) )
     118ostype * ?|?( ostype *os, double _Complex dc ) {
     119        os | creal( dc );
     120        if ( cimag( dc ) >= 0 ) os | '+';
     121        os | "" | cimag( dc ) | 'i';
     122        return os;
     123} // ?|?
     124
     125forall( dtype ostype | ostream( ostype ) )
     126ostype * ?|?( ostype *os, long double _Complex ldc ) {
     127        os | creall( ldc );
     128        if ( cimagl( ldc ) >= 0 ) os | '+';
     129        os | "" | cimagl( ldc ) | 'i';
     130        return os;
     131} // ?|?
     132
     133forall( dtype ostype | ostream( ostype ) )
     134ostype * ?|?( ostype *os, const char *cp ) {
     135        enum { Open = 1, Close, OpenClose };
     136        static const char mask[256] = {
     137                // opening delimiters
     138                ['('] : Open, ['['] : Open, ['{'] : Open,
     139                ['$'] : Open, [L'£'] : Open, [L'¥'] : Open, [L'¢'] : Open, [L'¿'] : Open, [L'«'] : Open,
     140                // closing delimiters
     141                [','] : Close, ['.'] : Close, [':'] : Close, [';'] : Close, ['!'] : Close, ['?'] : Close,
     142                [')'] : Close, [']'] : Close, ['}'] : Close,
     143                ['%'] : Close, [L'»'] : Close,
     144                // opening-closing delimiters
     145                ['\''] : OpenClose, ['`'] : OpenClose, ['"'] : OpenClose,
     146        }; // mask
     147
     148        int len = strlen( cp );
     149        // null string => no separator
     150  if ( len == 0 ) { sepOff( os ); return os; }
     151        // first character NOT spacing or closing punctuation => add left separator
     152        if ( sepPrt( os ) && isspace( cp[0] ) == 0 && mask[ cp[0] ] != Close && mask[ cp[0] ] != OpenClose ) {
     153                prtfmt( os, "%s", sepGet( os ) );
     154        } // if
     155        // last character IS spacing or opening punctuation => turn off separator for next item
     156        unsigned int posn = len - 1;
     157        if ( isspace( cp[posn] ) || mask[ cp[posn] ] == Open || mask[ cp[posn] ] == OpenClose ) {
     158                sepOff( os );
     159        } else {
     160                sepOn( os );
     161        } // if
     162        return write( os, cp, len );
    97163} // ?|?
    98164
    99165forall( dtype ostype | ostream( ostype ) )
    100166ostype * ?|?( 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 }
    115 
    116 forall( dtype ostype | ostream( ostype ) )
     167        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     168        prtfmt( os, "%p", p );
     169        return os;
     170} // ?|?
     171
     172
     173forall( dtype ostype | ostream( ostype ) )
     174ostype * ?|?( ostype *os, ostype * (* manip)( ostype * ) ) {
     175        return manip( os );
     176} // ?|?
     177
     178forall( dtype ostype | ostream( ostype ) )
    117179ostype * endl( ostype * os ) {
    118         os | "\n";
     180        os | '\n';
    119181        flush( os );
     182        sepOff( os );
    120183        return os;
    121184} // endl
    122185
     186forall( dtype ostype | ostream( ostype ) )
     187ostype * sepOn( ostype * os ) {
     188        sepOn( os );
     189        return os;
     190} // sepOn
     191
     192forall( dtype ostype | ostream( ostype ) )
     193ostype * sepOff( ostype * os ) {
     194        sepOff( os );
     195        return os;
     196} // sepOff
     197
    123198//---------------------------------------
    124199
    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 | ' '; }
     200forall( otype elttype | writeable( elttype ), otype iteratortype | iterator( iteratortype, elttype ), dtype ostype | ostream( ostype ) )
     201void write( iteratortype begin, iteratortype end, ostype *os ) {
     202        void print( elttype i ) { os | i; }
    129203        for_each( begin, end, print );
    130204} // ?|?
    131205
    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 | ' '; }
     206forall( otype elttype | writeable( elttype ), otype iteratortype | iterator( iteratortype, elttype ), dtype ostype | ostream( ostype ) )
     207void write_reverse( iteratortype begin, iteratortype end, ostype *os ) {
     208        void print( elttype i ) { os | i; }
    136209        for_each_reverse( begin, end, print );
    137210} // ?|?
     
    140213
    141214forall( 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 } // ?|?
     215istype * ?|?( istype * is, char * c ) {
     216        scanfmt( is, "%c", c );
     217        return is;
     218} // ?|?
     219
     220forall( dtype istype | istream( istype ) )
     221istype * ?|?( istype * is, short int * si ) {
     222        scanfmt( is, "%hd", si );
     223        return is;
     224} // ?|?
     225
     226forall( dtype istype | istream( istype ) )
     227istype * ?|?( istype * is, unsigned short int * usi ) {
     228        scanfmt( is, "%hu", usi );
     229        return is;
     230} // ?|?
     231
     232forall( dtype istype | istream( istype ) )
     233istype * ?|?( istype * is, int * i ) {
     234        scanfmt( is, "%d", i );
     235        return is;
     236} // ?|?
     237
     238forall( dtype istype | istream( istype ) )
     239istype * ?|?( istype * is, unsigned int * ui ) {
     240        scanfmt( is, "%u", ui );
     241        return is;
     242} // ?|?
     243
     244forall( dtype istype | istream( istype ) )
     245istype * ?|?( istype * is, long int * li ) {
     246        scanfmt( is, "%ld", li );
     247        return is;
     248} // ?|?
     249
     250forall( dtype istype | istream( istype ) )
     251istype * ?|?( istype * is, unsigned long int * ulli ) {
     252        scanfmt( is, "%lu", ulli );
     253        return is;
     254} // ?|?
     255
     256forall( dtype istype | istream( istype ) )
     257istype * ?|?( istype * is, long long int * lli ) {
     258        scanfmt( is, "%lld", lli );
     259        return is;
     260} // ?|?
     261
     262forall( dtype istype | istream( istype ) )
     263istype * ?|?( istype * is, unsigned long long int * ulli ) {
     264        scanfmt( is, "%llu", ulli );
     265        return is;
     266} // ?|?
     267
     268
     269forall( dtype istype | istream( istype ) )
     270istype * ?|?( istype * is, float * f ) {
     271        scanfmt( is, "%f", f );
     272        return is;
     273} // ?|?
     274
     275forall( dtype istype | istream( istype ) )
     276istype * ?|?( istype * is, double * d ) {
     277        scanfmt( is, "%lf", d );
     278        return is;
     279} // ?|?
     280
     281forall( dtype istype | istream( istype ) )
     282istype * ?|?( istype * is, long double * ld ) {
     283        scanfmt( is, "%Lf", ld );
     284        return is;
     285} // ?|?
     286
     287
     288forall( dtype istype | istream( istype ) )
     289istype * ?|?( istype * is, float _Complex * fc ) {
     290        float re, im;
     291        scanfmt( is, "%g%gi", &re, &im );
     292        *fc = re + im * _Complex_I;
     293        return is;
     294} // ?|?
     295
     296forall( dtype istype | istream( istype ) )
     297istype * ?|?( istype * is, double _Complex * dc ) {
     298        double re, im;
     299        scanfmt( is, "%lf%lfi", &re, &im );
     300        *dc = re + im * _Complex_I;
     301        return is;
     302} // ?|?
     303
     304forall( dtype istype | istream( istype ) )
     305istype * ?|?( istype * is, long double _Complex * ldc ) {
     306        long double re, im;
     307        scanfmt( is, "%Lf%Lfi", &re, &im );
     308        *ldc = re + im * _Complex_I;
     309        return is;
     310} // ?|?
     311
     312_Istream_str1 str( char * str ) { _Istream_str1 s = { str }; return s; }
     313forall( dtype istype | istream( istype ) )
     314istype * ?|?( istype * is, _Istream_str1 str ) {
     315        scanfmt( is, "%s", str.s );
     316        return is;
     317} // str
     318
     319_Istream_str2 str( char * str, int size ) { _Istream_str2 s = { str, size }; return s; }
     320forall( dtype istype | istream( istype ) )
     321istype * ?|?( istype * is, _Istream_str2 str ) {
     322        char buf[16];
     323        sprintf( buf, "%%%ds", str.size );
     324        scanfmt( is, buf, str.s );
     325        return is;
     326} // str
    150327
    151328// Local Variables: //
  • src/libcfa/iterator

    r39786813 ra5a71d0  
    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

    r39786813 ra5a71d0  
    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/prelude.cf

    r39786813 ra5a71d0  
     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

    r39786813 ra5a71d0  
    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 : Tue Mar 22 22:34:24 2016
     13// Update Count     : 69
    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
     22forall( otype T ) T * malloc( void );
     23forall( otype T ) T * malloc( char fill );
     24forall( otype T ) T * malloc( T * ptr, size_t size );
     25forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill );
     26forall( otype T ) T * calloc( size_t size );
     27forall( otype T ) T * realloc( T * ptr, size_t size );
     28forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill );
    2429
    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 );
     30forall( otype T ) T * aligned_alloc( size_t alignment );
     31forall( otype T ) T * memalign( size_t alignment );             // deprecated
     32forall( otype T ) int posix_memalign( T ** ptr, size_t alignment );
    3333
    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 );
     34forall( otype T ) T * memset( T * ptr, unsigned char fill ); // use default value '\0' for fill
     35forall( otype T ) T * memset( T * ptr );                                // remove when default value available
    3736
    3837//---------------------------------------
     
    6665//---------------------------------------
    6766
    68 forall( type T | { int ?<?( T, T ); } )
     67forall( otype T | { int ?<?( T, T ); } )
    6968T * bsearch( const T key, const T * arr, size_t dimension );
    7069
    71 forall( type T | { int ?<?( T, T ); } )
     70forall( otype T | { int ?<?( T, T ); } )
    7271void qsort( const T * arr, size_t dimension );
    7372
    7473//---------------------------------------
    7574
    76 forall( type T | { T ?/?( T, T ); T ?%?( T, T ); } )
     75forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } )
    7776[ T, T ] div( T t1, T t2 );
    7877
     
    9493//---------------------------------------
    9594
    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();
     95void rand48seed( long int s );
     96char rand48();
     97int rand48();
     98unsigned int rand48();
     99long int rand48();
     100unsigned long int rand48();
     101float rand48();
     102double rand48();
     103float _Complex rand48();
     104double _Complex rand48();
     105long double _Complex rand48();
    107106
    108107//---------------------------------------
    109108
    110 forall( type T | { int ?<?( T, T ); } )
     109forall( otype T | { int ?<?( T, T ); } )
    111110T min( const T t1, const T t2 );
    112111
    113 forall( type T | { int ?>?( T, T ); } )
     112forall( otype T | { int ?>?( T, T ); } )
    114113T max( const T t1, const T t2 );
    115114
    116 forall( type T )
     115forall( otype T )
    117116void swap( T * t1, T * t2 );
    118117
  • src/libcfa/stdlib.c

    r39786813 ra5a71d0  
    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 Mar 23 13:26:42 2016
     13// Update Count     : 146
    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 ) {
     29forall( otype T ) T * malloc( void ) {
    3930        printf( "malloc1\n" );
    4031    return (T *)malloc( sizeof(T) );
    4132} // malloc
    42 forall( type T ) T * malloc( size_t size ) {
     33forall( otype T ) T * malloc( size_t size ) {
    4334        printf( "malloc2\n" );
    4435    return (T *)(void *)malloc( size );
    4536} // malloc
    46 forall( type T ) T * malloc( char fill ) {
     37forall( otype T ) T * malloc( char fill ) {
    4738        printf( "malloc3\n" );
    4839        T * ptr = (T *)malloc( sizeof(T) );
     
    5041} // malloc
    5142
    52 forall( type T ) T * calloc( size_t size ) {
     43forall( otype T ) T * calloc( size_t size ) {
    5344        printf( "calloc\n" );
    5445    return (T *)calloc( size, sizeof(T) );
    5546} // calloc
    5647
    57 forall( type T ) T * realloc( T * ptr, size_t size ) {
     48forall( otype T ) T * realloc( T * ptr, size_t size ) {
    5849        printf( "realloc1\n" );
    5950    return (T *)(void *)realloc( (void *)ptr, size );
    6051} // realloc
    61 forall( type T ) T * realloc( T * ptr, size_t size, unsigned char fill ) {
     52forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill ) {
    6253        printf( "realloc2\n" );
    6354    char * nptr = (T *)(void *)realloc( (void *)ptr, size );
     
    6758} // realloc
    6859
    69 forall( type T ) T * malloc( T * ptr, size_t size ) {
     60forall( otype T ) T * malloc( T * ptr, size_t size ) {
    7061        printf( "malloc4\n" );
    7162    return (T *)realloc( ptr, size );
    7263} // malloc
    73 forall( type T ) T * malloc( T * ptr, size_t size, unsigned char fill ) {
     64forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill ) {
    7465        printf( "malloc5\n" );
    7566    return (T *)realloc( ptr, size, fill );
    7667} // malloc
    7768
    78 forall( type T ) T * aligned_alloc( size_t alignment ) {
     69forall( otype T ) T * aligned_alloc( size_t alignment ) {
    7970        printf( "aligned_alloc\n" );
    8071    return (T *)memalign( alignment, sizeof(T) );
    8172} // aligned_alloc
    8273
    83 forall( type T ) T * memalign( size_t alignment ) {
     74forall( otype T ) T * memalign( size_t alignment ) {
    8475        printf( "memalign\n" );
    8576    return (T *)memalign( alignment, sizeof(T) );
    8677} // memalign
    8778
    88 forall( type T ) int posix_memalign( T ** ptr, size_t alignment ) {
     79forall( otype T ) int posix_memalign( T ** ptr, size_t alignment ) {
    8980        printf( "posix_memalign\n" );
    9081    return posix_memalign( (void **)ptr, alignment, sizeof(T) );
    9182} // posix_memalign
     83
     84forall( otype T ) T * memset( T * ptr, unsigned char fill ) { // use default value '\0' for fill
     85        printf( "memset1\n" );
     86    return (T *)memset( ptr, (int)fill, malloc_usable_size( ptr ) );
     87} // memset
     88forall( otype T ) T * memset( T * ptr ) {                               // remove when default value available
     89        printf( "memset2\n" );
     90    return (T *)memset( ptr, 0, malloc_usable_size( ptr ) );
     91} // memset
    9292
    9393//---------------------------------------
     
    123123        return ulli;
    124124}
     125
    125126float ato( const char * ptr ) {
    126127        float f;
     
    138139        return ld;
    139140}
     141
    140142float _Complex ato( const char * ptr ) {
    141143        float re, im;
     
    172174        return strtoull( sptr, eptr, base );
    173175}
     176
    174177float strto( const char * sptr, char ** eptr ) {
    175178        return strtof( sptr, eptr );
     
    181184        return strtold( sptr, eptr );
    182185}
     186
    183187float _Complex strto( const char * sptr, char ** eptr ) {
    184188        float re, im;
     
    208212//---------------------------------------
    209213
    210 forall( type T | { int ?<?( T, T ); } )
     214forall( otype T | { int ?<?( T, T ); } )
    211215T * bsearch( const T key, const T * arr, size_t dimension ) {
    212216        int comp( const void * t1, const void * t2 ) { return *(T *)t1 < *(T *)t2 ? -1 : *(T *)t2 < *(T *)t1 ? 1 : 0; }
     
    214218} // bsearch
    215219
    216 forall( type T | { int ?<?( T, T ); } )
     220forall( otype T | { int ?<?( T, T ); } )
    217221void qsort( const T * arr, size_t dimension ) {
    218222        int comp( const void * t1, const void * t2 ) { return *(T *)t1 < *(T *)t2 ? -1 : *(T *)t2 < *(T *)t1 ? 1 : 0; }
     
    222226//---------------------------------------
    223227
    224 forall( type T | { T ?/?( T, T ); T ?%?( T, T ); } )
     228forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } )
    225229[ T, T ] div( T t1, T t2 ) { /* return [ t1 / t2, t1 % t2 ]; */ }
    226230
     
    239243//---------------------------------------
    240244
    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 ); } )
     245void rand48seed( long int s ) { srand48( s ); }
     246char rand48() { return mrand48(); }
     247int rand48() { return mrand48(); }
     248unsigned int rand48() { return lrand48(); }
     249long int rand48() { return mrand48(); }
     250unsigned long int rand48() { return lrand48(); }
     251float rand48() { return (float)drand48(); }                             // otherwise float uses lrand48
     252double rand48() { return drand48(); }
     253float _Complex rand48() { return (float)drand48() + (float _Complex)(drand48() * _Complex_I); }
     254double _Complex rand48() { return drand48() + (double _Complex)(drand48() * _Complex_I); }
     255long double _Complex rand48() { return (long double)drand48() + (long double _Complex)(drand48() * _Complex_I); }
     256
     257//---------------------------------------
     258
     259forall( otype T | { int ?<?( T, T ); } )
    256260T min( const T t1, const T t2 ) {
    257261        return t1 < t2 ? t1 : t2;
    258262} // min
    259263
    260 forall( type T | { int ?>?( T, T ); } )
     264forall( otype T | { int ?>?( T, T ); } )
    261265T max( const T t1, const T t2 ) {
    262266        return t1 > t2 ? t1 : t2;
    263267} // max
    264268
    265 forall( type T )
     269forall( otype T )
    266270void swap( T * t1, T * t2 ) {
    267271        T temp = *t1;
Note: See TracChangeset for help on using the changeset viewer.