Changeset a73d57a


Ignore:
Timestamp:
Feb 17, 2016, 3:08:28 PM (9 years ago)
Author:
Aaron Moss <a3moss@…>
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, string, with_gc
Children:
30aeb27
Parents:
9407ed8 (diff), 658f6de0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src
Files:
2 added
19 edited

Legend:

Unmodified
Added
Removed
  • src/Tests/Makefile

    r9407ed8 ra73d57a  
    88OUTPUTS = ${addprefix ${OUTPUTDIR}/,${EXAMPLES:.c=.txt}}
    99
    10 .SILENT :
     10#.SILENT :
    1111
    1212all :
     
    1919
    2020${OUTPUTDIR}/%.txt : %.c ${CFA} Makefile
    21         -${CFA} -n ${CFAOPT} < $< > $@ 2>&1
     21        -${CFA} -n ${CFAOPT} $< > $@ 2>&1
    2222
    2323${OUTPUTDIR}/report : ${OUTPUTS} ${EXPECTDIR}
  • src/examples/abs.c

    r9407ed8 ra73d57a  
    1010// Created On       : Thu Jan 28 18:26:16 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb  3 11:14:58 2016
    13 // Update Count     : 43
     12// Last Modified On : Wed Feb 17 09:32:04 2016
     13// Update Count     : 44
    1414//
    1515
     
    1818
    1919int main( void ) {
    20         ofstream *sout = ofstream_stdout();
    21 
    2220        char ch = -65;
    2321        sout | "char\t\t\t"                                     | ch     | "\tabs " | abs( ch ) | endl;
  • src/examples/alloc.c

    r9407ed8 ra73d57a  
    1111// Created On       : Wed Feb  3 07:56:22 2016
    1212// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Wed Feb  3 16:32:04 2016
    14 // Update Count     : 38
     13// Last Modified On : Wed Feb 17 11:43:23 2016
     14// Update Count     : 40
    1515//
    1616
     
    2727
    2828int main( void ) {
    29     ofstream * sout = ofstream_stdout();
    30 
    3129    size_t size = 10;
    3230    int * p;
     
    10098    free( x );
    10199#endif
    102     free( sout );
    103100}
    104101
  • src/examples/fstream_test.c

    r9407ed8 ra73d57a  
    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:11:33 2016
    13 // Update Count     : 42
     12// Last Modified On : Wed Feb 17 11:45:43 2016
     13// Update Count     : 43
    1414//
    1515
     
    1717
    1818int main( void ) {
    19         ofstream *sout = ofstream_stdout();
    20         ifstream *sin = ifstream_stdin();
    2119        int nombre;
    2220        sout | "Entrez un nombre, s'il vous plaît:\n";
  • src/examples/hello.c

    r9407ed8 ra73d57a  
    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:11:49 2016
    13 // Update Count     : 7
     12// Last Modified On : Wed Feb 17 12:11:45 2016
     13// Update Count     : 8
    1414//
    1515
     
    1717
    1818int main() {
    19         ofstream *sout = ofstream_stdout();
    20         ifstream *sin = ifstream_stdin();
    2119        sout | "Bonjour au monde!\n";
    2220}
  • src/examples/identity.c

    r9407ed8 ra73d57a  
    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:11:58 2016
    13 // Update Count     : 8
     12// Last Modified On : Wed Feb 17 12:17:32 2016
     13// Update Count     : 10
    1414//
    1515
     
    2222
    2323int main() {
    24         ofstream *sout = ofstream_stdout();
    2524        sout | "char\t\t\t"                                     | identity( 'z' ) | endl;
    2625        sout | "signed int\t\t"                         | identity( 4 ) | endl;
     
    3029        sout | "signed long long int\t"         | identity( 4ll ) | endl;
    3130        sout | "unsigned long long int\t"       | identity( 4ull ) | endl;
    32         sout | "float\t\t\t"                            | identity( 4.0f ) | endl;
    33         sout | "double\t\t\t"                           | identity( 4.0 ) | endl;
    34         sout | "long double\t\t"                        | identity( 4.0l ) | endl;
     31        sout | "float\t\t\t"                            | identity( 4.1f ) | endl;
     32        sout | "double\t\t\t"                           | identity( 4.1 ) | endl;
     33        sout | "long double\t\t"                        | identity( 4.1l ) | endl;
    3534}
    3635
  • src/examples/minmax.c

    r9407ed8 ra73d57a  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb  3 11:14:49 2016
    13 // Update Count     : 46
     12// Last Modified On : Wed Feb 17 12:17:53 2016
     13// Update Count     : 47
    1414//
    1515
     
    1818
    1919int main( void ) {
    20         ofstream *sout = ofstream_stdout();
    2120        // char does not have less or greater than.
    2221        int ?<?( char op1, char op2 ) { return (int)op1 < (int)op2; }
  • src/examples/quad.c

    r9407ed8 ra73d57a  
    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:13:48 2016
    13 // Update Count     : 5
     12// Last Modified On : Wed Feb 17 12:19:24 2016
     13// Update Count     : 6
    1414//
    1515
     
    2727
    2828int main() {
    29         ofstream *sout = ofstream_stdout();
    3029        int N = 2;
    3130        sout | "result of quad of " | N | " is " | quad( N ) | endl;
  • src/examples/quoted_keyword.c

    r9407ed8 ra73d57a  
    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:13:58 2016
    13 // Update Count     : 8
     12// Last Modified On : Wed Feb 17 12:19:45 2016
     13// Update Count     : 9
    1414//
    1515
     
    2828
    2929int main() {
    30         ofstream *sout = ofstream_stdout();
    3130        sout | `catch` + st.`type` + st.`struct` + `throw` | endl;
    3231}
  • src/examples/random.c

    r9407ed8 ra73d57a  
    77
    88int main() {
    9         ofstream *sout = ofstream_stdout();
    10 
    119        randseed( getpid() );                                                           // set random seed
    1210
  • src/examples/square.c

    r9407ed8 ra73d57a  
    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:14:16 2016
    13 // Update Count     : 25
     12// Last Modified On : Wed Feb 17 12:21:58 2016
     13// Update Count     : 26
    1414//
    1515
     
    2323int main() {
    2424#if 0
    25         ofstream *sout = ofstream_stdout();
    2625        sout | "result of squaring 9 is " | endl;
    2726
  • src/examples/sum.c

    r9407ed8 ra73d57a  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Feb  6 11:57:42 2016
    13 // Update Count     : 182
     12// Last Modified On : Tue Feb 16 23:49:31 2016
     13// Update Count     : 189
    1414//
    1515
     
    4141int main( void ) {
    4242        const int low = 5, High = 15, size = High - low;
    43         ofstream *sout = ofstream_stdout();
    4443
    4544        char s = 0, a[size], v = low;
  • src/examples/swap.c

    r9407ed8 ra73d57a  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb  3 11:14:04 2016
    13 // Update Count     : 63
     12// Last Modified On : Wed Feb 17 12:22:12 2016
     13// Update Count     : 64
    1414//
    1515
     
    1818
    1919int main( void ) {
    20         ofstream *sout = ofstream_stdout();
    21 
    2220        char c1 = 'a', c2 = 'b';
    2321        sout | "char\t\t\t" | c1 | ' ' | c2 | "\t\t\tswap ";
  • src/examples/twice.c

    r9407ed8 ra73d57a  
    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:14:44 2016
    13 // Update Count     : 12
     12// Last Modified On : Wed Feb 17 12:23:25 2016
     13// Update Count     : 13
    1414//
    1515
     
    2727        char ?++( char *op ) { char temp = *op; *op += 1; return temp; }
    2828
    29         ofstream *sout = ofstream_stdout();
    3029        sout | twice( 'a' ) | ' ' | twice( 1 ) | ' ' | twice( 3.2 ) | endl;
    3130}
  • src/examples/vector_test.c

    r9407ed8 ra73d57a  
    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:14:52 2016
    13 // Update Count     : 17
     12// Last Modified On : Wed Feb 17 12:23:55 2016
     13// Update Count     : 18
    1414//
    1515
     
    2020
    2121int main( void ) {
    22         ofstream *sout = ofstream_stdout();
    23         ifstream *sin = ifstream_stdin();
    2422        vector_int vec = vector_int_allocate();
    2523
  • src/libcfa/fstream

    r9407ed8 ra73d57a  
    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:47:41 2016
    13 // Update Count     : 3
     12// Last Modified On : Wed Feb 17 14:02:01 2016
     13// Update Count     : 22
    1414//
    1515
     
    1919#include "iostream"
    2020
    21 typedef struct ofstream ofstream;
     21// implement context ostream
     22struct ofstream;
    2223
    23 // implement context ostream
    24 ofstream *write( ofstream *, const char *, streamsize_type );
    25 int fail( ofstream * );
     24int fail( ofstream * os );
     25int flush( ofstream * os );
     26void open( ofstream ** os, const char * name, const char * mode );
     27void close( ofstream * os );
     28ofstream * write( ofstream * os, const char * data, streamsize_type size );
    2629
    27 ofstream *ofstream_stdout();
    28 ofstream *ofstream_stderr();
    29 ofstream *ofstream_fromfile( const char *name );
    30 void ofstream_close( ofstream *os );
    31 
    32 typedef struct ifstream ifstream;
     30extern ofstream * sout, * serr;
    3331
    3432// implement context istream
    35 ifstream *read( ifstream *, char *, streamsize_type );
    36 ifstream *unread( ifstream *, char );
    37 int fail( ifstream * );
    38 int eof( ifstream * );
     33struct ifstream;
    3934
    40 ifstream *ifstream_stdin();
    41 ifstream *ifstream_fromfile( const char *name );
     35int fail( ifstream * is );
     36int eof( ifstream * is );
     37void open( ifstream ** is, const char * name, const char * mode );
     38void close( ifstream * is );
     39ifstream * get( ifstream * is, int * data );
     40ifstream * read( ifstream * is, char * data, streamsize_type size );
     41ifstream * ungetc( ifstream * is, char c );
     42
     43extern ifstream *sin;
    4244
    4345#endif // __FSTREAM_H__
  • src/libcfa/fstream.c

    r9407ed8 ra73d57a  
    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:12:59 2016
    13 // Update Count     : 6
     12// Last Modified On : Wed Feb 17 14:03:05 2016
     13// Update Count     : 76
    1414//
    1515
     
    2323struct ofstream {
    2424        FILE *file;
    25         int fail;
    2625};
    2726
    28 ofstream *write( ofstream *os, const char *data, streamsize_type size ) {
    29         if ( ! os->fail ) {
    30                 fwrite( data, size, 1, os->file );
    31                 os->fail = ferror( os->file );
     27#define IO_MSG "I/O error "
     28
     29int fail( ofstream * os ) {
     30        return ferror( os->file );
     31} // fail
     32
     33int flush( ofstream * os ) {
     34        return fflush( os->file );
     35} // flush
     36
     37void 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" );
     41                exit( EXIT_FAILURE );
     42        } // if
     43        (*os)->file = t;
     44} // open
     45
     46void close( ofstream * os ) {
     47        if ( os->file == stdout || os->file == stderr ) return;
     48
     49        if ( fclose( os->file ) == EOF ) {
     50                perror( IO_MSG "close output" );
     51        } // if
     52} // close
     53
     54ofstream * write( ofstream * os, const char * data, streamsize_type size ) {
     55        if ( fail( os ) ) {
     56                fprintf( stderr, "attempt write I/O on failed stream\n" );
     57                exit( EXIT_FAILURE );
     58        } // if
     59
     60        if ( fwrite( data, 1, size, os->file ) != size ) {
     61                perror( IO_MSG "write" );
     62                exit( EXIT_FAILURE );
    3263        } // if
    3364        return os;
    3465} // write
    3566
    36 int fail( ofstream *os ) {
    37         return os->fail;
    38 } // fail
     67static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_) };
     68ofstream *sout = &soutFile;
     69static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_) };
     70ofstream *serr = &serrFile;
    3971
    40 static ofstream *make_ofstream() {
    41         ofstream *new_stream = malloc( sizeof( ofstream ) );
    42         new_stream->fail = 0;
    43         return new_stream;
    44 } // make_ofstream
    45 
    46 ofstream *ofstream_stdout() {
    47         ofstream *stdout_stream = make_ofstream();
    48         stdout_stream->file = stdout;
    49         return stdout_stream;
    50 } // ofstream_stdout
    51 
    52 ofstream *ofstream_stderr() {
    53         ofstream *stderr_stream = make_ofstream();
    54         stderr_stream->file = stderr;
    55         return stderr_stream;
    56 } // ofstream_stderr
    57 
    58 ofstream *ofstream_fromfile( const char *name ) {
    59         ofstream *file_stream = make_ofstream();
    60         file_stream->file = fopen( name, "w" );
    61         file_stream->fail = file_stream->file == 0;
    62         return file_stream;
    63 }
    64 
    65 void ofstream_close( ofstream *os ) {
    66         if ( os->file != stdout && os->file != stderr ) {
    67                 os->fail = fclose( os->file );
    68         }
    69         free( os );
    70 }
     72//---------------------------------------
    7173
    7274struct ifstream {
    7375        FILE *file;
    74         int fail;
    75         int eof;
    7676};
    7777
    78 ifstream *read( ifstream *is, char *data, streamsize_type size ) {
    79         if ( ! is->fail && ! is->eof ) {
    80                 fread( data, size, 1, is->file );
    81                 is->fail = ferror( is->file );
    82                 is->eof = feof( is->file );
    83         }
     78int fail( ifstream * is ) {
     79        return ferror( is->file );
     80} // fail
     81
     82int eof( ifstream * is ) {
     83        return feof( is->file );
     84} // eof
     85
     86ifstream * 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
     92        } // if
    8493        return is;
    85 }
     94} // read
     95
     96ifstream * read( ifstream * is, char * data, streamsize_type size ) {
     97        if ( fail( is ) ) {
     98                fprintf( stderr, "attempt read I/O on failed stream\n" );
     99                exit( EXIT_FAILURE );
     100        } // if
     101
     102        if ( fread( data, size, 1, is->file ) == 0 ) {
     103                perror( IO_MSG "read" );
     104                exit( EXIT_FAILURE );
     105        } // if
     106        return is;
     107} // read
    86108 
    87 ifstream *unread( ifstream *is, char c ) {
    88         if ( ! is->fail ) {
    89                 if ( ! EOF == ungetc( c, is->file ) ) {
    90                         is->fail = 1;
    91                 }
    92         }
     109ifstream *ungetc( ifstream * is, char c ) {
     110        if ( fail( is ) ) {
     111                fprintf( stderr, "attempt ungetc I/O on failed stream\n" );
     112                exit( EXIT_FAILURE );
     113        } // if
     114
     115        if ( ungetc( c, is->file ) == EOF ) {
     116                perror( IO_MSG "ungetc" );
     117                exit( EXIT_FAILURE );
     118        } // if
    93119        return is;
    94 }
     120} // ungetc
    95121
    96 int fail( ifstream *is ) {
    97         return is->fail;
    98 }
     122void 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 );
     127        } // if
     128        (*is)->file = t;
     129} // open
    99130
    100 int eof( ifstream *is ) {
    101         return is->eof;
    102 }
     131void close( ifstream * is ) {
     132        if ( is->file == stdin ) return;
    103133
    104 static ifstream *make_ifstream() {
    105         ifstream *new_stream = malloc( sizeof( ifstream ) );
    106         new_stream->fail = 0;
    107         new_stream->eof = 0;
    108         return new_stream;
    109 }
     134        if ( fclose( is->file ) == EOF ) {
     135                perror( IO_MSG "close input" );
     136        } // if
     137} // close
    110138
    111 ifstream *ifstream_stdin() {
    112         ifstream *stdin_stream = make_ifstream();
    113         stdin_stream->file = stdin;
    114         return stdin_stream;
    115 }
    116 
    117 ifstream *ifstream_fromfile( const char *name ) {
    118         ifstream *file_stream = make_ifstream();
    119         file_stream->file = fopen( name, "r" );
    120         file_stream->fail = file_stream->file == 0;
    121         return file_stream;
    122 }
     139static ifstream sinFile = { (FILE *)(&_IO_2_1_stdin_) };
     140ifstream *sin = &sinFile;
    123141
    124142// Local Variables: //
  • src/libcfa/iostream

    r9407ed8 ra73d57a  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jan 29 15:50:36 2016
    13 // Update Count     : 29
     12// Last Modified On : Wed Feb 17 14:04:24 2016
     13// Update Count     : 32
    1414//
    1515
     
    2222
    2323context ostream( dtype ostype ) {
    24         ostype *write( ostype *, const char *, streamsize_type );
    2524        int fail( ostype * );
     25        int flush( ostype * );
     26        ostype * write( ostype *, const char *, streamsize_type );
    2627};
    27 
    2828context writeable( type T ) {
    2929        forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, T );
     
    5252
    5353// writes the range [begin, end) to the given stream
    54 forall( type elt_type | writeable( elt_type ),
    55                 type iterator_type | iterator( iterator_type, elt_type ),
    56                 dtype os_type | ostream( os_type ) )
     54forall( type elt_type | writeable( elt_type ), type iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) )
    5755void write( iterator_type begin, iterator_type end, os_type *os );
    5856
    59 forall( type elt_type | writeable( elt_type ),
    60                 type iterator_type | iterator( iterator_type, elt_type ),
    61                 dtype os_type | ostream( os_type ) )
     57forall( type elt_type | writeable( elt_type ), type iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) )
    6258void write_reverse( iterator_type begin, iterator_type end, os_type *os );
    6359
    64 //******************************************************************************
     60//---------------------------------------
    6561
    6662context istream( dtype istype ) {
    67         istype *read( istype *, char *, streamsize_type );
    68         istype *unread( istype *, char );
    6963        int fail( istype * );
    7064        int eof( istype * );
     65        istype * get( istype *, int * );
     66        istype * read( istype *, char *, streamsize_type );
     67        istype * ungetc( istype *, char );
    7168};
    7269
  • src/libcfa/iostream.c

    r9407ed8 ra73d57a  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 10 15:48:46 2016
    13 // Update Count     : 66
     12// Last Modified On : Wed Feb 17 14:19:56 2016
     13// Update Count     : 76
    1414//
    1515
     
    111111forall( dtype ostype, dtype retostype | ostream( ostype ) | ostream( retostype ) )
    112112retostype * ?|?( ostype *os, retostype * (*manip)(ostype*) ) {
    113   return manip(os);
     113  return manip( os );
    114114}
    115115
    116116forall( dtype ostype | ostream( ostype ) )
    117117ostype * endl( ostype * os ) {
    118   os | "\n";
    119   // flush
    120   return os;
     118        os | "\n";
     119        flush( os );
     120        return os;
    121121} // endl
    122122
    123 forall( type elt_type | writeable( elt_type ),
    124                 type iterator_type | iterator( iterator_type, elt_type ),
     123//---------------------------------------
     124
     125forall( type elt_type | writeable( elt_type ), type iterator_type | iterator( iterator_type, elt_type ),
    125126                dtype os_type | ostream( os_type ) )
    126127void write( iterator_type begin, iterator_type end, os_type *os ) {
    127         void print( elt_type i ) {
    128                 os | i | ' ';
    129         }
     128        void print( elt_type i ) { os | i | ' '; }
    130129        for_each( begin, end, print );
    131130} // ?|?
    132131
    133 forall( type elt_type | writeable( elt_type ),
    134                 type iterator_type | iterator( iterator_type, elt_type ),
     132forall( type elt_type | writeable( elt_type ), type iterator_type | iterator( iterator_type, elt_type ),
    135133                dtype os_type | ostream( os_type ) )
    136134void write_reverse( iterator_type begin, iterator_type end, os_type *os ) {
     
    139137} // ?|?
    140138
     139//---------------------------------------
    141140
    142141forall( dtype istype | istream( istype ) )
     
    147146forall( dtype istype | istream( istype ) )
    148147istype * ?|?( istype *is, int *ip ) {
    149         char cur;
    150  
    151         // skip some whitespace
    152         do {
    153                 is | &cur;
    154                 if ( fail( is ) || eof( is ) ) return is;
    155         } while ( !( cur >= '0' && cur <= '9' ) );
    156  
    157         // accumulate digits
    158         *ip = 0;
    159         while ( cur >= '0' && cur <= '9' ) {
    160                 *ip = *ip * 10 + ( cur - '0' );
    161                 is | &cur;
    162                 if ( fail( is ) || eof( is ) ) return is;
    163         }
    164  
    165         unread( is, cur );
    166         return is;
     148        return get( is, ip );
    167149} // ?|?
    168150
Note: See TracChangeset for help on using the changeset viewer.