Ignore:
Timestamp:
Jul 19, 2017, 11:49:33 AM (8 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
9cc0472
Parents:
fea3faa (diff), a57cb58 (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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/iostream.c

    rfea3faa rb826e6b  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May  8 18:24:23 2017
    13 // Update Count     : 369
     12// Last Modified On : Sun Jul 16 21:12:03 2017
     13// Update Count     : 398
    1414//
    1515
     
    1818extern "C" {
    1919#include <stdio.h>
     20#include <stdbool.h>                                                                    // true/false
    2021#include <string.h>                                                                             // strlen
    2122#include <float.h>                                                                              // DBL_DIG, LDBL_DIG
     
    2425
    2526forall( dtype ostype | ostream( ostype ) )
    26 ostype * ?|?( ostype * os, char c ) {
    27         fmt( os, "%c", c );
     27ostype * ?|?( ostype * os, char ch ) {
     28        fmt( os, "%c", ch );
     29        if ( ch == '\n' ) setNL( os, true );
    2830        sepOff( os );
    2931        return os;
     
    123125forall( dtype ostype | ostream( ostype ) )
    124126ostype * ?|?( ostype * os, float _Complex fc ) {
    125         os | crealf( fc );
    126         _Bool temp = sepDisable( os );                                          // disable separators within complex value
    127         if ( cimagf( fc ) >= 0 ) os | '+';                                      // negative value prints '-'
    128         os | cimagf( fc ) | 'i';
    129         sepReset( os, temp );                                                           // reset separator
     127        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     128        fmt( os, "%g%+gi", crealf( fc ), cimagf( fc ) );
    130129        return os;
    131130} // ?|?
     
    133132forall( dtype ostype | ostream( ostype ) )
    134133ostype * ?|?( ostype * os, double _Complex dc ) {
    135         os | creal( dc );
    136         _Bool temp = sepDisable( os );                                          // disable separators within complex value
    137         if ( cimag( dc ) >= 0 ) os | '+';                                       // negative value prints '-'
    138         os | cimag( dc ) | 'i';
    139         sepReset( os, temp );                                                           // reset separator
     134        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     135        fmt( os, "%.*lg%+.*lgi", DBL_DIG, creal( dc ), DBL_DIG, cimag( dc ) );
    140136        return os;
    141137} // ?|?
     
    143139forall( dtype ostype | ostream( ostype ) )
    144140ostype * ?|?( ostype * os, long double _Complex ldc ) {
    145         os | creall( ldc );
    146         _Bool temp = sepDisable( os );                                          // disable separators within complex value
    147         if ( cimagl( ldc ) >= 0 ) os | '+';                                     // negative value prints '-'
    148         os | cimagl( ldc ) | 'i';
    149         sepReset( os, temp );                                                           // reset separator
     141        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     142        fmt( os, "%.*Lg%+.*Lgi", LDBL_DIG, creall( ldc ), LDBL_DIG, cimagl( ldc ) );
    150143        return os;
    151144} // ?|?
     
    180173
    181174        // last character IS spacing or opening punctuation => turn off separator for next item
    182         unsigned int len = strlen( cp ), posn = len - 1;
    183         ch = cp[posn];                                                                          // must make unsigned
     175        size_t len = strlen( cp );
     176        ch = cp[len - 1];                                                                       // must make unsigned
    184177        if ( sepPrt( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) {
    185178                sepOn( os );
     
    187180                sepOff( os );
    188181        } // if
     182        if ( ch == '\n' ) setNL( os, true );                            // check *AFTER* sepPrt call above as it resets NL flag
    189183        return write( os, cp, len );
    190184} // ?|?
     
    201195forall( dtype ostype, otype T, ttype Params | ostream( ostype ) | writeable( T ) | { ostype * ?|?( ostype *, Params ); } )
    202196ostype * ?|?( ostype * os, T arg, Params rest ) {
     197        os | arg;                                                                                       // print first argument
    203198        sepSetCur( os, sepGetTuple( os ) );                                     // switch to tuple separator
    204         os | arg;                                                                                       // print first argument
    205199        os | rest;                                                                                      // print remaining arguments
    206200        sepSetCur( os, sepGet( os ) );                                          // switch to regular separator
     
    216210
    217211forall( dtype ostype | ostream( ostype ) )
     212ostype * sep( ostype * os ) {
     213        os | sepGet( os );
     214        return os;
     215} // sep
     216
     217forall( dtype ostype | ostream( ostype ) )
     218ostype * sepTuple( ostype * os ) {
     219        os | sepGetTuple( os );
     220        return os;
     221} // sepTuple
     222
     223forall( dtype ostype | ostream( ostype ) )
    218224ostype * endl( ostype * os ) {
    219225        os | '\n';
     226        setNL( os, true );
    220227        flush( os );
    221228        sepOff( os );                                                                           // prepare for next line
Note: See TracChangeset for help on using the changeset viewer.