- Timestamp:
- Apr 20, 2021, 9:32:28 PM (2 years ago)
- Branches:
- arm-eh, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 6f6b844
- Parents:
- 59f3f61
- Location:
- libcfa/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/fstream.cfa
r59f3f61 r6c5d92f 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Mar 1 21:12:15202113 // Update Count : 42 412 // Last Modified On : Tue Apr 20 19:04:46 2021 13 // Update Count : 425 14 14 // 15 15 … … 31 31 32 32 void ?{}( ofstream & os, void * file ) { 33 os. $file= file;34 os. $sepDefault= true;35 os. $sepOnOff= false;36 os. $nlOnOff= true;37 os. $prt= false;38 os. $sawNL= false;39 os. $acquired= false;40 $sepSetCur( os, sepGet( os ) );33 os.file$ = file; 34 os.sepDefault$ = true; 35 os.sepOnOff$ = false; 36 os.nlOnOff$ = true; 37 os.prt$ = false; 38 os.sawNL$ = false; 39 os.acquired$ = false; 40 sepSetCur$( os, sepGet( os ) ); 41 41 sepSet( os, " " ); 42 42 sepSetTuple( os, ", " ); … … 44 44 45 45 // private 46 bool $sepPrt( ofstream & os ) { $setNL( os, false ); return os.$sepOnOff; }47 void $sepReset( ofstream & os ) { os.$sepOnOff = os.$sepDefault; }48 void $sepReset( ofstream & os, bool reset ) { os.$sepDefault = reset; os.$sepOnOff = os.$sepDefault; }49 const char * $sepGetCur( ofstream & os ) { return os.$sepCur; }50 void $sepSetCur( ofstream & os, const char sepCur[] ) { os.$sepCur= sepCur; }51 bool $getNL( ofstream & os ) { return os.$sawNL; }52 void $setNL( ofstream & os, bool state ) { os.$sawNL= state; }53 bool $getANL( ofstream & os ) { return os.$nlOnOff; }54 bool $getPrt( ofstream & os ) { return os.$prt; }55 void $setPrt( ofstream & os, bool state ) { os.$prt= state; }46 bool sepPrt$( ofstream & os ) { setNL$( os, false ); return os.sepOnOff$; } 47 void sepReset$( ofstream & os ) { os.sepOnOff$ = os.sepDefault$; } 48 void sepReset$( ofstream & os, bool reset ) { os.sepDefault$ = reset; os.sepOnOff$ = os.sepDefault$; } 49 const char * sepGetCur$( ofstream & os ) { return os.sepCur$; } 50 void sepSetCur$( ofstream & os, const char sepCur[] ) { os.sepCur$ = sepCur; } 51 bool getNL$( ofstream & os ) { return os.sawNL$; } 52 void setNL$( ofstream & os, bool state ) { os.sawNL$ = state; } 53 bool getANL$( ofstream & os ) { return os.nlOnOff$; } 54 bool getPrt$( ofstream & os ) { return os.prt$; } 55 void setPrt$( ofstream & os, bool state ) { os.prt$ = state; } 56 56 57 57 // public 58 void ?{}( ofstream & os ) { os. $file= 0p; }58 void ?{}( ofstream & os ) { os.file$ = 0p; } 59 59 60 60 void ?{}( ofstream & os, const char name[], const char mode[] ) { … … 70 70 } // ^?{} 71 71 72 void sepOn( ofstream & os ) { os. $sepOnOff = ! $getNL( os ); }73 void sepOff( ofstream & os ) { os. $sepOnOff= false; }72 void sepOn( ofstream & os ) { os.sepOnOff$ = ! getNL$( os ); } 73 void sepOff( ofstream & os ) { os.sepOnOff$ = false; } 74 74 75 75 bool sepDisable( ofstream & os ) { 76 bool temp = os. $sepDefault;77 os. $sepDefault= false;78 $sepReset( os );76 bool temp = os.sepDefault$; 77 os.sepDefault$ = false; 78 sepReset$( os ); 79 79 return temp; 80 80 } // sepDisable 81 81 82 82 bool sepEnable( ofstream & os ) { 83 bool temp = os. $sepDefault;84 os. $sepDefault= true;85 if ( os. $sepOnOff ) $sepReset( os ); // start of line ?83 bool temp = os.sepDefault$; 84 os.sepDefault$ = true; 85 if ( os.sepOnOff$ ) sepReset$( os ); // start of line ? 86 86 return temp; 87 87 } // sepEnable 88 88 89 void nlOn( ofstream & os ) { os. $nlOnOff= true; }90 void nlOff( ofstream & os ) { os. $nlOnOff= false; }91 92 const char * sepGet( ofstream & os ) { return os. $separator; }89 void nlOn( ofstream & os ) { os.nlOnOff$ = true; } 90 void nlOff( ofstream & os ) { os.nlOnOff$ = false; } 91 92 const char * sepGet( ofstream & os ) { return os.separator$; } 93 93 void sepSet( ofstream & os, const char s[] ) { 94 94 assert( s ); 95 strncpy( os. $separator, s, sepSize - 1 );96 os. $separator[sepSize - 1] = '\0';95 strncpy( os.separator$, s, sepSize - 1 ); 96 os.separator$[sepSize - 1] = '\0'; 97 97 } // sepSet 98 98 99 const char * sepGetTuple( ofstream & os ) { return os. $tupleSeparator; }99 const char * sepGetTuple( ofstream & os ) { return os.tupleSeparator$; } 100 100 void sepSetTuple( ofstream & os, const char s[] ) { 101 101 assert( s ); 102 strncpy( os. $tupleSeparator, s, sepSize - 1 );103 os. $tupleSeparator[sepSize - 1] = '\0';102 strncpy( os.tupleSeparator$, s, sepSize - 1 ); 103 os.tupleSeparator$[sepSize - 1] = '\0'; 104 104 } // sepSet 105 105 106 106 void ends( ofstream & os ) { 107 if ( $getANL( os ) ) nl( os );108 else $setPrt( os, false ); // turn off107 if ( getANL$( os ) ) nl( os ); 108 else setPrt$( os, false ); // turn off 109 109 if ( &os == &exit ) exit( EXIT_FAILURE ); 110 110 if ( &os == &abort ) abort(); 111 if ( os. $acquired ) { os.$acquired= false; release( os ); }111 if ( os.acquired$ ) { os.acquired$ = false; release( os ); } 112 112 } // ends 113 113 114 114 int fail( ofstream & os ) { 115 return os. $file == 0 || ferror( (FILE *)(os.$file) );115 return os.file$ == 0 || ferror( (FILE *)(os.file$) ); 116 116 } // fail 117 117 118 118 int flush( ofstream & os ) { 119 return fflush( (FILE *)(os. $file) );119 return fflush( (FILE *)(os.file$) ); 120 120 } // flush 121 121 … … 136 136 137 137 void close( ofstream & os ) { 138 if ( (FILE *)(os. $file) == 0p ) return;139 if ( (FILE *)(os. $file) == (FILE *)stdout || (FILE *)(os.$file) == (FILE *)stderr ) return;140 141 if ( fclose( (FILE *)(os. $file) ) == EOF ) {138 if ( (FILE *)(os.file$) == 0p ) return; 139 if ( (FILE *)(os.file$) == (FILE *)stdout || (FILE *)(os.file$) == (FILE *)stderr ) return; 140 141 if ( fclose( (FILE *)(os.file$) ) == EOF ) { 142 142 abort | IO_MSG "close output" | nl | strerror( errno ); 143 143 } // if 144 os. $file= 0p;144 os.file$ = 0p; 145 145 } // close 146 146 … … 150 150 } // if 151 151 152 if ( fwrite( data, 1, size, (FILE *)(os. $file) ) != size ) {152 if ( fwrite( data, 1, size, (FILE *)(os.file$) ) != size ) { 153 153 abort | IO_MSG "write" | nl | strerror( errno ); 154 154 } // if … … 159 159 va_list args; 160 160 va_start( args, format ); 161 int len = vfprintf( (FILE *)(os. $file), format, args );161 int len = vfprintf( (FILE *)(os.file$), format, args ); 162 162 if ( len == EOF ) { 163 if ( ferror( (FILE *)(os. $file) ) ) {163 if ( ferror( (FILE *)(os.file$) ) ) { 164 164 abort | IO_MSG "invalid write"; 165 165 } // if … … 167 167 va_end( args ); 168 168 169 $setPrt( os, true ); // called in output cascade170 $sepReset( os ); // reset separator169 setPrt$( os, true ); // called in output cascade 170 sepReset$( os ); // reset separator 171 171 return len; 172 172 } // fmt 173 173 174 174 inline void acquire( ofstream & os ) { 175 lock( os. $lock);176 if ( ! os. $acquired ) os.$acquired= true;177 else unlock( os. $lock);175 lock( os.lock$ ); 176 if ( ! os.acquired$ ) os.acquired$ = true; 177 else unlock( os.lock$ ); 178 178 } // acquire 179 179 180 180 inline void release( ofstream & os ) { 181 unlock( os. $lock);181 unlock( os.lock$ ); 182 182 } // release 183 183 184 void ?{}( osacquire & acq, ofstream & os ) { &acq.os = &os; lock( os. $lock); }184 void ?{}( osacquire & acq, ofstream & os ) { &acq.os = &os; lock( os.lock$ ); } 185 185 void ^?{}( osacquire & acq ) { release( acq.os ); } 186 186 … … 204 204 // private 205 205 void ?{}( ifstream & is, void * file ) { 206 is. $file= file;207 is. $nlOnOff= false;208 is. $acquired= false;206 is.file$ = file; 207 is.nlOnOff$ = false; 208 is.acquired$ = false; 209 209 } // ?{} 210 210 211 211 // public 212 void ?{}( ifstream & is ) { is. $file= 0p; }212 void ?{}( ifstream & is ) { is.file$ = 0p; } 213 213 214 214 void ?{}( ifstream & is, const char name[], const char mode[] ) { … … 224 224 } // ^?{} 225 225 226 void nlOn( ifstream & os ) { os. $nlOnOff= true; }227 void nlOff( ifstream & os ) { os. $nlOnOff= false; }228 bool getANL( ifstream & os ) { return os. $nlOnOff; }226 void nlOn( ifstream & os ) { os.nlOnOff$ = true; } 227 void nlOff( ifstream & os ) { os.nlOnOff$ = false; } 228 bool getANL( ifstream & os ) { return os.nlOnOff$; } 229 229 230 230 int fail( ifstream & is ) { 231 return is. $file == 0p || ferror( (FILE *)(is.$file) );231 return is.file$ == 0p || ferror( (FILE *)(is.file$) ); 232 232 } // fail 233 233 234 234 void ends( ifstream & is ) { 235 if ( is. $acquired ) { is.$acquired= false; release( is ); }235 if ( is.acquired$ ) { is.acquired$ = false; release( is ); } 236 236 } // ends 237 237 238 238 int eof( ifstream & is ) { 239 return feof( (FILE *)(is. $file) );239 return feof( (FILE *)(is.file$) ); 240 240 } // eof 241 241 … … 248 248 } // if 249 249 #endif // __CFA_DEBUG__ 250 is. $file= file;250 is.file$ = file; 251 251 } // open 252 252 … … 256 256 257 257 void close( ifstream & is ) { 258 if ( (FILE *)(is. $file) == 0p ) return;259 if ( (FILE *)(is. $file) == (FILE *)stdin ) return;260 261 if ( fclose( (FILE *)(is. $file) ) == EOF ) {258 if ( (FILE *)(is.file$) == 0p ) return; 259 if ( (FILE *)(is.file$) == (FILE *)stdin ) return; 260 261 if ( fclose( (FILE *)(is.file$) ) == EOF ) { 262 262 abort | IO_MSG "close input" | nl | strerror( errno ); 263 263 } // if 264 is. $file= 0p;264 is.file$ = 0p; 265 265 } // close 266 266 … … 270 270 } // if 271 271 272 if ( fread( data, size, 1, (FILE *)(is. $file) ) == 0 ) {272 if ( fread( data, size, 1, (FILE *)(is.file$) ) == 0 ) { 273 273 abort | IO_MSG "read" | nl | strerror( errno ); 274 274 } // if … … 281 281 } // if 282 282 283 if ( ungetc( c, (FILE *)(is. $file) ) == EOF ) {283 if ( ungetc( c, (FILE *)(is.file$) ) == EOF ) { 284 284 abort | IO_MSG "ungetc" | nl | strerror( errno ); 285 285 } // if … … 291 291 292 292 va_start( args, format ); 293 int len = vfscanf( (FILE *)(is. $file), format, args );293 int len = vfscanf( (FILE *)(is.file$), format, args ); 294 294 if ( len == EOF ) { 295 if ( ferror( (FILE *)(is. $file) ) ) {295 if ( ferror( (FILE *)(is.file$) ) ) { 296 296 abort | IO_MSG "invalid read"; 297 297 } // if … … 302 302 303 303 inline void acquire( ifstream & is ) { 304 lock( is. $lock);305 if ( ! is. $acquired ) is.$acquired= true;306 else unlock( is. $lock);304 lock( is.lock$ ); 305 if ( ! is.acquired$ ) is.acquired$ = true; 306 else unlock( is.lock$ ); 307 307 } // acquire 308 308 309 309 inline void release( ifstream & is ) { 310 unlock( is. $lock);310 unlock( is.lock$ ); 311 311 } // release 312 312 313 void ?{}( isacquire & acq, ifstream & is ) { &acq.is = &is; lock( is. $lock); }313 void ?{}( isacquire & acq, ifstream & is ) { &acq.is = &is; lock( is.lock$ ); } 314 314 void ^?{}( isacquire & acq ) { release( acq.is ); } 315 315 -
libcfa/src/fstream.hfa
r59f3f61 r6c5d92f 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Mar 1 22:45:08202113 // Update Count : 21 712 // Last Modified On : Tue Apr 20 19:04:12 2021 13 // Update Count : 218 14 14 // 15 15 … … 26 26 enum { sepSize = 16 }; 27 27 struct ofstream { 28 void * $file;29 bool $sepDefault;30 bool $sepOnOff;31 bool $nlOnOff;32 bool $prt; // print text33 bool $sawNL;34 const char * $sepCur;35 char $separator[sepSize];36 char $tupleSeparator[sepSize];37 multiple_acquisition_lock $lock;38 bool $acquired;28 void * file$; 29 bool sepDefault$; 30 bool sepOnOff$; 31 bool nlOnOff$; 32 bool prt$; // print text 33 bool sawNL$; 34 const char * sepCur$; 35 char separator$[sepSize]; 36 char tupleSeparator$[sepSize]; 37 multiple_acquisition_lock lock$; 38 bool acquired$; 39 39 }; // ofstream 40 40 41 41 // private 42 bool $sepPrt( ofstream & );43 void $sepReset( ofstream & );44 void $sepReset( ofstream &, bool );45 const char * $sepGetCur( ofstream & );46 void $sepSetCur( ofstream &, const char [] );47 bool $getNL( ofstream & );48 void $setNL( ofstream &, bool );49 bool $getANL( ofstream & );50 bool $getPrt( ofstream & );51 void $setPrt( ofstream &, bool );42 bool sepPrt$( ofstream & ); 43 void sepReset$( ofstream & ); 44 void sepReset$( ofstream &, bool ); 45 const char * sepGetCur$( ofstream & ); 46 void sepSetCur$( ofstream &, const char [] ); 47 bool getNL$( ofstream & ); 48 void setNL$( ofstream &, bool ); 49 bool getANL$( ofstream & ); 50 bool getPrt$( ofstream & ); 51 void setPrt$( ofstream &, bool ); 52 52 53 53 // public … … 94 94 95 95 struct ifstream { 96 void * $file;97 bool $nlOnOff;98 multiple_acquisition_lock $lock;99 bool $acquired;96 void * file$; 97 bool nlOnOff$; 98 multiple_acquisition_lock lock$; 99 bool acquired$; 100 100 }; // ifstream 101 101 -
libcfa/src/gmp.hfa
r59f3f61 r6c5d92f 10 10 // Created On : Tue Apr 19 08:43:43 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Feb 9 09:56:54 202013 // Update Count : 3 112 // Last Modified On : Tue Apr 20 20:59:21 2021 13 // Update Count : 32 14 14 // 15 15 … … 263 263 forall( ostype & | ostream( ostype ) ) { 264 264 ostype & ?|?( ostype & os, Int mp ) { 265 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );265 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 266 266 gmp_printf( "%Zd", mp.mpz ); 267 267 sepOn( os ); -
libcfa/src/heap.cfa
r59f3f61 r6c5d92f 10 10 // Created On : Tue Dec 19 21:58:35 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Mar 14 10:39:24202113 // Update Count : 103 212 // Last Modified On : Tue Apr 20 21:20:48 2021 13 // Update Count : 1033 14 14 // 15 15 … … 1128 1128 1129 1129 // Set the alignment for an the allocation and return previous alignment or 0 if no alignment. 1130 size_t $malloc_alignment_set( void * addr, size_t alignment ) {1130 size_t malloc_alignment_set$( void * addr, size_t alignment ) { 1131 1131 if ( unlikely( addr == 0p ) ) return libAlign(); // minimum alignment 1132 1132 size_t ret; … … 1139 1139 } // if 1140 1140 return ret; 1141 } // $malloc_alignment_set1141 } // malloc_alignment_set$ 1142 1142 1143 1143 … … 1153 1153 1154 1154 // Set allocation is zero filled and return previous zero filled. 1155 bool $malloc_zero_fill_set( void * addr ) {1155 bool malloc_zero_fill_set$( void * addr ) { 1156 1156 if ( unlikely( addr == 0p ) ) return false; // null allocation is not zero fill 1157 1157 HeapManager.Storage.Header * header = headerAddr( addr ); … … 1162 1162 header->kind.real.blockSize |= 2; // mark as zero filled 1163 1163 return ret; 1164 } // $malloc_zero_fill_set1164 } // malloc_zero_fill_set$ 1165 1165 1166 1166 … … 1176 1176 1177 1177 // Set allocation size and return previous size. 1178 size_t $malloc_size_set( void * addr, size_t size ) {1178 size_t malloc_size_set$( void * addr, size_t size ) { 1179 1179 if ( unlikely( addr == 0p ) ) return 0; // null allocation has 0 size 1180 1180 HeapManager.Storage.Header * header = headerAddr( addr ); … … 1185 1185 header->kind.real.size = size; 1186 1186 return ret; 1187 } // $malloc_size_set1187 } // malloc_size_set$ 1188 1188 1189 1189 -
libcfa/src/iostream.cfa
r59f3f61 r6c5d92f 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Apr 13 13:05:24202113 // Update Count : 132 412 // Last Modified On : Tue Apr 20 19:09:41 2021 13 // Update Count : 1325 14 14 // 15 15 … … 38 38 forall( ostype & | ostream( ostype ) ) { 39 39 ostype & ?|?( ostype & os, bool b ) { 40 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );40 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 41 41 fmt( os, "%s", b ? "true" : "false" ); 42 42 return os; … … 48 48 ostype & ?|?( ostype & os, char c ) { 49 49 fmt( os, "%c", c ); 50 if ( c == '\n' ) $setNL( os, true );50 if ( c == '\n' ) setNL$( os, true ); 51 51 return sepOff( os ); 52 52 } // ?|? … … 56 56 57 57 ostype & ?|?( ostype & os, signed char sc ) { 58 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );58 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 59 59 fmt( os, "%hhd", sc ); 60 60 return os; … … 65 65 66 66 ostype & ?|?( ostype & os, unsigned char usc ) { 67 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );67 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 68 68 fmt( os, "%hhu", usc ); 69 69 return os; … … 74 74 75 75 ostype & ?|?( ostype & os, short int si ) { 76 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );76 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 77 77 fmt( os, "%hd", si ); 78 78 return os; … … 83 83 84 84 ostype & ?|?( ostype & os, unsigned short int usi ) { 85 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );85 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 86 86 fmt( os, "%hu", usi ); 87 87 return os; … … 92 92 93 93 ostype & ?|?( ostype & os, int i ) { 94 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );94 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 95 95 fmt( os, "%d", i ); 96 96 return os; … … 101 101 102 102 ostype & ?|?( ostype & os, unsigned int ui ) { 103 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );103 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 104 104 fmt( os, "%u", ui ); 105 105 return os; … … 110 110 111 111 ostype & ?|?( ostype & os, long int li ) { 112 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );112 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 113 113 fmt( os, "%ld", li ); 114 114 return os; … … 119 119 120 120 ostype & ?|?( ostype & os, unsigned long int uli ) { 121 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );121 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 122 122 fmt( os, "%lu", uli ); 123 123 return os; … … 128 128 129 129 ostype & ?|?( ostype & os, long long int lli ) { 130 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );130 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 131 131 fmt( os, "%lld", lli ); 132 132 return os; … … 137 137 138 138 ostype & ?|?( ostype & os, unsigned long long int ulli ) { 139 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );139 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 140 140 fmt( os, "%llu", ulli ); 141 141 return os; … … 171 171 172 172 ostype & ?|?( ostype & os, int128 llli ) { 173 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );173 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 174 174 base10_128( os, llli ); 175 175 return os; … … 180 180 181 181 ostype & ?|?( ostype & os, unsigned int128 ullli ) { 182 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );182 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 183 183 base10_128( os, ullli ); 184 184 return os; … … 204 204 205 205 ostype & ?|?( ostype & os, float f ) { 206 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );206 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 207 207 PrintWithDP( os, "%g", f ); 208 208 return os; … … 213 213 214 214 ostype & ?|?( ostype & os, double d ) { 215 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );215 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 216 216 PrintWithDP( os, "%.*lg", d, DBL_DIG ); 217 217 return os; … … 222 222 223 223 ostype & ?|?( ostype & os, long double ld ) { 224 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );224 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 225 225 PrintWithDP( os, "%.*Lg", ld, LDBL_DIG ); 226 226 return os; … … 231 231 232 232 ostype & ?|?( ostype & os, float _Complex fc ) { 233 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );233 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 234 234 // os | crealf( fc ) | nonl; 235 235 PrintWithDP( os, "%g", crealf( fc ) ); … … 243 243 244 244 ostype & ?|?( ostype & os, double _Complex dc ) { 245 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );245 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 246 246 // os | creal( dc ) | nonl; 247 247 PrintWithDP( os, "%.*lg", creal( dc ), DBL_DIG ); … … 255 255 256 256 ostype & ?|?( ostype & os, long double _Complex ldc ) { 257 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );257 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 258 258 // os | creall( ldc ) || nonl; 259 259 PrintWithDP( os, "%.*Lg", creall( ldc ), LDBL_DIG ); … … 286 286 // first character IS NOT spacing or closing punctuation => add left separator 287 287 unsigned char ch = s[0]; // must make unsigned 288 if ( $sepPrt( os ) && mask[ ch ] != Close && mask[ ch ] != OpenClose ) {289 fmt( os, "%s", $sepGetCur( os ) );288 if ( sepPrt$( os ) && mask[ ch ] != Close && mask[ ch ] != OpenClose ) { 289 fmt( os, "%s", sepGetCur$( os ) ); 290 290 } // if 291 291 292 292 // if string starts line, must reset to determine open state because separator is off 293 $sepReset( os ); // reset separator293 sepReset$( os ); // reset separator 294 294 295 295 // last character IS spacing or opening punctuation => turn off separator for next item 296 296 size_t len = strlen( s ); 297 297 ch = s[len - 1]; // must make unsigned 298 if ( $sepPrt( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) {298 if ( sepPrt$( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) { 299 299 sepOn( os ); 300 300 } else { 301 301 sepOff( os ); 302 302 } // if 303 if ( ch == '\n' ) $setNL( os, true ); // check *AFTER* $sepPrtcall above as it resets NL flag303 if ( ch == '\n' ) setNL$( os, true ); // check *AFTER* sepPrt$ call above as it resets NL flag 304 304 return write( os, s, len ); 305 305 } // ?|? … … 309 309 310 310 // ostype & ?|?( ostype & os, const char16_t * s ) { 311 // if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );311 // if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 312 312 // fmt( os, "%ls", s ); 313 313 // return os; … … 316 316 // #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous 317 317 // ostype & ?|?( ostype & os, const char32_t * s ) { 318 // if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );318 // if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 319 319 // fmt( os, "%ls", s ); 320 320 // return os; … … 323 323 324 324 // ostype & ?|?( ostype & os, const wchar_t * s ) { 325 // if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );325 // if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 326 326 // fmt( os, "%ls", s ); 327 327 // return os; … … 329 329 330 330 ostype & ?|?( ostype & os, const void * p ) { 331 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );331 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 332 332 fmt( os, "%p", p ); 333 333 return os; … … 343 343 void ?|?( ostype & os, ostype & (* manip)( ostype & ) ) { 344 344 manip( os ); 345 if ( $getPrt( os ) ) ends( os ); // something printed ?346 $setPrt( os, false ); // turn off345 if ( getPrt$( os ) ) ends( os ); // something printed ? 346 setPrt$( os, false ); // turn off 347 347 } // ?|? 348 348 … … 357 357 ostype & nl( ostype & os ) { 358 358 (ostype &)(os | '\n'); 359 $setPrt( os, false ); // turn off360 $setNL( os, true );359 setPrt$( os, false ); // turn off 360 setNL$( os, true ); 361 361 flush( os ); 362 362 return sepOff( os ); // prepare for next line … … 364 364 365 365 ostype & nonl( ostype & os ) { 366 $setPrt( os, false ); // turn off366 setPrt$( os, false ); // turn off 367 367 return os; 368 368 } // nonl … … 408 408 ostype & ?|?( ostype & os, T arg, Params rest ) { 409 409 (ostype &)(os | arg); // print first argument 410 $sepSetCur( os, sepGetTuple( os ) ); // switch to tuple separator410 sepSetCur$( os, sepGetTuple( os ) ); // switch to tuple separator 411 411 (ostype &)(os | rest); // print remaining arguments 412 $sepSetCur( os, sepGet( os ) ); // switch to regular separator412 sepSetCur$( os, sepGet( os ) ); // switch to regular separator 413 413 return os; 414 414 } // ?|? … … 416 416 // (ostype &)(?|?( os, arg, rest )); ends( os ); 417 417 (ostype &)(os | arg); // print first argument 418 $sepSetCur( os, sepGetTuple( os ) ); // switch to tuple separator418 sepSetCur$( os, sepGetTuple( os ) ); // switch to tuple separator 419 419 (ostype &)(os | rest); // print remaining arguments 420 $sepSetCur( os, sepGet( os ) ); // switch to regular separator420 sepSetCur$( os, sepGet( os ) ); // switch to regular separator 421 421 ends( os ); 422 422 } // ?|? … … 447 447 forall( ostype & | ostream( ostype ) ) { \ 448 448 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \ 449 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); \449 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); \ 450 450 \ 451 451 if ( f.base == 'b' || f.base == 'B' ) { /* bespoke binary format */ \ … … 691 691 int bufbeg = 0, i, len; \ 692 692 \ 693 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); \693 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); \ 694 694 char fmtstr[sizeof(DFMTP) + 8]; /* sizeof includes '\0' */ \ 695 695 if ( ! f.flags.pc ) memcpy( &fmtstr, DFMTNP, sizeof(DFMTNP) ); \ … … 734 734 } // if 735 735 736 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );736 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 737 737 738 738 #define CFMTNP "% * " … … 772 772 } // if 773 773 774 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );774 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 775 775 776 776 #define SFMTNP "% * " -
libcfa/src/iostream.hfa
r59f3f61 r6c5d92f 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Apr 13 13:05:11202113 // Update Count : 38 412 // Last Modified On : Tue Apr 20 19:09:44 2021 13 // Update Count : 385 14 14 // 15 15 … … 24 24 trait ostream( ostype & ) { 25 25 // private 26 bool $sepPrt( ostype & ); // get separator state (on/off)27 void $sepReset( ostype & ); // set separator state to default state28 void $sepReset( ostype &, bool ); // set separator and default state29 const char * $sepGetCur( ostype & ); // get current separator string30 void $sepSetCur( ostype &, const char [] ); // set current separator string31 bool $getNL( ostype & ); // check newline32 void $setNL( ostype &, bool ); // saw newline33 bool $getANL( ostype & ); // get auto newline (on/off)34 bool $getPrt( ostype & ); // get fmt called in output cascade35 void $setPrt( ostype &, bool ); // set fmt called in output cascade26 bool sepPrt$( ostype & ); // get separator state (on/off) 27 void sepReset$( ostype & ); // set separator state to default state 28 void sepReset$( ostype &, bool ); // set separator and default state 29 const char * sepGetCur$( ostype & ); // get current separator string 30 void sepSetCur$( ostype &, const char [] ); // set current separator string 31 bool getNL$( ostype & ); // check newline 32 void setNL$( ostype &, bool ); // saw newline 33 bool getANL$( ostype & ); // get auto newline (on/off) 34 bool getPrt$( ostype & ); // get fmt called in output cascade 35 void setPrt$( ostype &, bool ); // set fmt called in output cascade 36 36 // public 37 37 void sepOn( ostype & ); // turn separator state on -
libcfa/src/stdlib.hfa
r59f3f61 r6c5d92f 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T hu Jan 21 22:02:13 202113 // Update Count : 57 412 // Last Modified On : Tue Apr 20 21:20:03 2021 13 // Update Count : 575 14 14 // 15 15 … … 44 44 45 45 // Macro because of returns 46 #define $ARRAY_ALLOC( allocation, alignment, dim ) \46 #define ARRAY_ALLOC$( allocation, alignment, dim ) \ 47 47 if ( _Alignof(T) <= libAlign() ) return (T *)(void *)allocation( dim, (size_t)sizeof(T) ); /* C allocation */ \ 48 48 else return (T *)alignment( _Alignof(T), dim, sizeof(T) ) … … 57 57 58 58 T * aalloc( size_t dim ) { 59 $ARRAY_ALLOC( aalloc, amemalign, dim );59 ARRAY_ALLOC$( aalloc, amemalign, dim ); 60 60 } // aalloc 61 61 62 62 T * calloc( size_t dim ) { 63 $ARRAY_ALLOC( calloc, cmemalign, dim );63 ARRAY_ALLOC$( calloc, cmemalign, dim ); 64 64 } // calloc 65 65 … … 119 119 S_fill(T) ?`fill( T a[], size_t nmemb ) { S_fill(T) ret = {'a', nmemb}; ret.fill.a = a; return ret; } 120 120 121 3. Replace the $alloc_internalfunction which is outside ttype forall-block with following function:122 T * $alloc_internal( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill) {121 3. Replace the alloc_internal$ function which is outside ttype forall-block with following function: 122 T * alloc_internal$( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill) { 123 123 T * ptr = NULL; 124 124 size_t size = sizeof(T); … … 145 145 146 146 return ptr; 147 } // $alloc_internal147 } // alloc_internal$ 148 148 */ 149 149 … … 175 175 S_realloc(T) ?`realloc ( T * a ) { return (S_realloc(T)){a}; } 176 176 177 T * $alloc_internal( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill ) {177 T * alloc_internal$( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill ) { 178 178 T * ptr = NULL; 179 179 size_t size = sizeof(T); … … 206 206 207 207 return ptr; 208 } // $alloc_internal209 210 forall( TT... | { T * $alloc_internal( void *, T *, size_t, size_t, S_fill(T), TT ); } ) {211 212 T * $alloc_internal( void * , T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill, T_resize Resize, TT rest) {213 return $alloc_internal( Resize, (T*)0p, Align, Dim, Fill, rest);214 } 215 216 T * $alloc_internal( void * Resize, T * , size_t Align, size_t Dim, S_fill(T) Fill, S_realloc(T) Realloc, TT rest) {217 return $alloc_internal( (void*)0p, Realloc, Align, Dim, Fill, rest);218 } 219 220 T * $alloc_internal( void * Resize, T * Realloc, size_t , size_t Dim, S_fill(T) Fill, T_align Align, TT rest) {221 return $alloc_internal( Resize, Realloc, Align, Dim, Fill, rest);222 } 223 224 T * $alloc_internal( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T) , S_fill(T) Fill, TT rest) {225 return $alloc_internal( Resize, Realloc, Align, Dim, Fill, rest);208 } // alloc_internal$ 209 210 forall( TT... | { T * alloc_internal$( void *, T *, size_t, size_t, S_fill(T), TT ); } ) { 211 212 T * alloc_internal$( void * , T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill, T_resize Resize, TT rest) { 213 return alloc_internal$( Resize, (T*)0p, Align, Dim, Fill, rest); 214 } 215 216 T * alloc_internal$( void * Resize, T * , size_t Align, size_t Dim, S_fill(T) Fill, S_realloc(T) Realloc, TT rest) { 217 return alloc_internal$( (void*)0p, Realloc, Align, Dim, Fill, rest); 218 } 219 220 T * alloc_internal$( void * Resize, T * Realloc, size_t , size_t Dim, S_fill(T) Fill, T_align Align, TT rest) { 221 return alloc_internal$( Resize, Realloc, Align, Dim, Fill, rest); 222 } 223 224 T * alloc_internal$( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T) , S_fill(T) Fill, TT rest) { 225 return alloc_internal$( Resize, Realloc, Align, Dim, Fill, rest); 226 226 } 227 227 228 228 T * alloc( TT all ) { 229 return $alloc_internal( (void*)0p, (T*)0p, (_Alignof(T) > libAlign() ? _Alignof(T) : libAlign()), (size_t)1, (S_fill(T)){'0'}, all);229 return alloc_internal$( (void*)0p, (T*)0p, (_Alignof(T) > libAlign() ? _Alignof(T) : libAlign()), (size_t)1, (S_fill(T)){'0'}, all); 230 230 } 231 231 232 232 T * alloc( size_t dim, TT all ) { 233 return $alloc_internal( (void*)0p, (T*)0p, (_Alignof(T) > libAlign() ? _Alignof(T) : libAlign()), dim, (S_fill(T)){'0'}, all);233 return alloc_internal$( (void*)0p, (T*)0p, (_Alignof(T) > libAlign() ? _Alignof(T) : libAlign()), dim, (S_fill(T)){'0'}, all); 234 234 } 235 235
Note: See TracChangeset
for help on using the changeset viewer.