Changeset ae0c1c3 for libcfa/src
- Timestamp:
- Apr 25, 2025, 7:08:53 PM (6 months ago)
- Branches:
- master
- Children:
- 7d02d35, ecfa58be
- Parents:
- 65bd3c2
- Location:
- libcfa/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/collections/string.cfa
r65bd3c2 rae0c1c3 216 216 } 217 217 218 void ?|?( ostype & out, string s ) {218 void ?|?( ostype & out, string s ) with ( basic_ostream_table ) { 219 219 (ostype &)(out | (*s.inner)); ends( out ); 220 220 } … … 229 229 } // ?|? 230 230 231 void ?|?( ostype & os, _Ostream_Manip(string) f ) {231 void ?|?( ostype & os, _Ostream_Manip(string) f ) with ( basic_ostream_table ) { 232 232 (ostype &)(os | f); ends( os ); 233 233 } -
libcfa/src/collections/string_res.cfa
r65bd3c2 rae0c1c3 201 201 forall( ostype & | basic_ostream( ostype ) ) 202 202 void ?|?( ostype & out, const string_res & s ) { 203 (ostype &)(out | s); ends( out ); 203 (ostype &)(out | s); 204 basic_ostream_table.ends( out ); 204 205 } 205 206 … … 249 250 250 251 forall( istype & | basic_istream( istype ) ) 251 istype & ?|?( istype & is, _Istream_Rquote f ) with( f.rstr ) {252 istype & ?|?( istype & is, _Istream_Rquote f ) with( basic_istream_table, f.rstr ) { 252 253 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 253 254 int args; -
libcfa/src/fstream.cfa
r65bd3c2 rae0c1c3 202 202 } // nl 203 203 204 static basic_ostream_data(ofstream) ofstream_basic_data = { 205 sepPrt$, 206 sepReset$, 207 sepReset$, 208 sepGetCur$, 209 sepSetCur$, 210 getNL$, 211 setNL$, 212 getANL$, 213 setANL$, 214 getPrt$, 215 setPrt$, 216 nlOn, 217 nlOff, 218 sep, 219 nosep, 220 sepOn, 221 sepOff, 222 sepGet, 223 sepSet, 224 sepGetTuple, 225 sepSetTuple, 226 ends, 227 fmt, 228 }; 229 230 basic_ostream_data(ofstream) const & basic_ostream_table = ofstream_basic_data; 231 232 static ostream_data(ofstream) ofstream_data; 233 234 // This should be an initializer like for the basic table. 235 // But, initialization of a structure with an inline structure doesn't work. 236 __attribute__((constructor(200))) 237 static void __ofstream_data_init__() { 238 basic_ostream_data(ofstream) & basic = ofstream_data; 239 basic.sepPrt$ = sepPrt$; 240 basic.sepReset$ = (void(*)(ofstream&))sepReset$; 241 basic.sepReset$ = (void(*)(ofstream&, bool))sepReset$; 242 basic.sepGetCur$ = sepGetCur$; 243 basic.sepSetCur$ = sepSetCur$; 244 basic.getNL$ = getNL$; 245 basic.setNL$ = setNL$; 246 basic.getANL$ = getANL$; 247 basic.setANL$ = setANL$; 248 basic.getPrt$ = getPrt$; 249 basic.setPrt$ = setPrt$; 250 basic.nlOn = nlOn; 251 basic.nlOff = nlOff; 252 basic.sep = sep; 253 basic.nosep = nosep; 254 basic.sepOn = sepOn; 255 basic.sepOff = sepOff; 256 basic.sepGet = sepGet; 257 basic.sepSet = sepSet; 258 basic.sepGetTuple = sepGetTuple; 259 basic.sepSetTuple = sepSetTuple; 260 basic.ends = ends; 261 basic.fmt = fmt; 262 ofstream_data.fail = fail; 263 ofstream_data.clearerr = clearerr; 264 ofstream_data.flush = flush; 265 ofstream_data.open = open; 266 ofstream_data.close = close; 267 ofstream_data.write = write; 268 } 269 270 ostream_data(ofstream) const & ostream_table = ofstream_data; 204 271 205 272 // *********************************** ifstream *********************************** … … 211 278 nlOnOff$ = false; // => skip newlines when reading single characters 212 279 } // ?{} 280 281 static basic_istream_data(ifstream) ifstream_basic_data = { 282 getANL$, 283 setANL$, 284 nlOn, 285 nlOff, 286 fmt, 287 ungetc, 288 eof, 289 clearerr, 290 }; 291 292 basic_istream_data(ifstream) const & basic_istream_table = ifstream_basic_data; 293 294 static istream_data(ifstream) ifstream_data; 295 296 // This should be an initializer like for the basic table. 297 // But, initialization of a structure with an inline structure doesn't work. 298 __attribute__((constructor(200))) 299 static void __ifstream_data_init__() { 300 basic_istream_data(ifstream) & basic = ifstream_data; 301 basic.getANL$ = getANL$; 302 basic.setANL$ = setANL$; 303 basic.nlOn = nlOn; 304 basic.nlOff = nlOff; 305 basic.fmt = fmt; 306 basic.ungetc = ungetc; 307 basic.eof = eof; 308 basic.clearerr = clearerr; 309 ifstream_data.fail = fail; 310 ifstream_data.open = (void(*)(ifstream &, const char *, const char *))open; 311 ifstream_data.open = (void(*)(ifstream &, const char *))open; 312 ifstream_data.close = close; 313 ifstream_data.read = read; 314 } 315 316 istream_data(ifstream) const & istream_table = ifstream_data; 213 317 214 318 bool getANL$( ifstream & os ) { return os.nlOnOff$; } -
libcfa/src/fstream.hfa
r65bd3c2 rae0c1c3 38 38 39 39 // Satisfies ostream 40 extern basic_ostream_data(ofstream) const & basic_ostream_table; 41 extern ostream_data(ofstream) const & ostream_table; 40 42 41 43 // private … … 106 108 107 109 // Satisfies istream 110 extern basic_istream_data(ifstream) const & basic_istream_table; 111 extern istream_data(ifstream) const & istream_table; 108 112 109 113 // private -
libcfa/src/gmp.hfa
r65bd3c2 rae0c1c3 263 263 forall( ostype & | ostream( ostype ) ) { 264 264 ostype & ?|?( ostype & os, Int mp ) { 265 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 265 ostream_data(ostype) const & table = ostream_table; 266 if ( table.sepPrt$( os ) ) table.fmt( os, "%s", table.sepGetCur$( os ) ); 266 267 gmp_printf( "%Zd", mp.mpz ); 267 sep( os );268 table.sep( os ); 268 269 return os; 269 270 } // ?|? -
libcfa/src/iostream.cfa
r65bd3c2 rae0c1c3 42 42 43 43 forall( ostype & | basic_ostream( ostype ) ) { 44 ostype & ?|?( ostype & os, bool b ) {44 ostype & ?|?( ostype & os, bool b ) with ( basic_ostream_table ) { 45 45 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 46 46 fmt( os, "%s", b ? "true" : "false" ); … … 49 49 OSTYPE_VOID_IMPL( os, bool ) 50 50 51 ostype & ?|?( ostype & os, char c ) {51 ostype & ?|?( ostype & os, char c ) with ( basic_ostream_table ) { 52 52 fmt( os, "%c", c ); 53 53 if ( c == '\n' ) setNL$( os, true ); … … 56 56 OSTYPE_VOID_IMPL( os, char ) 57 57 58 ostype & ?|?( ostype & os, signed char sc ) {58 ostype & ?|?( ostype & os, signed char sc ) with ( basic_ostream_table ) { 59 59 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 60 60 fmt( os, "%'hhd", sc ); … … 63 63 OSTYPE_VOID_IMPL( os, signed char ) 64 64 65 ostype & ?|?( ostype & os, unsigned char usc ) {65 ostype & ?|?( ostype & os, unsigned char usc ) with ( basic_ostream_table ) { 66 66 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 67 67 fmt( os, "%'hhu", usc ); … … 70 70 OSTYPE_VOID_IMPL( os, unsigned char ) 71 71 72 ostype & ?|?( ostype & os, short int si ) {72 ostype & ?|?( ostype & os, short int si ) with ( basic_ostream_table ) { 73 73 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 74 74 fmt( os, "%'hd", si ); … … 77 77 OSTYPE_VOID_IMPL( os, short int ) 78 78 79 ostype & ?|?( ostype & os, unsigned short int usi ) {79 ostype & ?|?( ostype & os, unsigned short int usi ) with ( basic_ostream_table ) { 80 80 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 81 81 fmt( os, "%'hu", usi ); … … 84 84 OSTYPE_VOID_IMPL( os, unsigned short int ) 85 85 86 ostype & ?|?( ostype & os, int i ) {86 ostype & ?|?( ostype & os, int i ) with ( basic_ostream_table ) { 87 87 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 88 88 fmt( os, "%'d", i ); … … 91 91 OSTYPE_VOID_IMPL( os, int ) 92 92 93 ostype & ?|?( ostype & os, unsigned int ui ) {93 ostype & ?|?( ostype & os, unsigned int ui ) with ( basic_ostream_table ) { 94 94 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 95 95 fmt( os, "%'u", ui ); … … 98 98 OSTYPE_VOID_IMPL( os, unsigned int ) 99 99 100 ostype & ?|?( ostype & os, long int li ) {100 ostype & ?|?( ostype & os, long int li ) with ( basic_ostream_table ) { 101 101 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 102 102 fmt( os, "%'ld", li ); … … 105 105 OSTYPE_VOID_IMPL( os, long int ) 106 106 107 ostype & ?|?( ostype & os, unsigned long int uli ) {107 ostype & ?|?( ostype & os, unsigned long int uli ) with ( basic_ostream_table ) { 108 108 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 109 109 fmt( os, "%'lu", uli ); … … 112 112 OSTYPE_VOID_IMPL( os, unsigned long int ) 113 113 114 ostype & ?|?( ostype & os, long long int lli ) {114 ostype & ?|?( ostype & os, long long int lli ) with ( basic_ostream_table ) { 115 115 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 116 116 fmt( os, "%'lld", lli ); … … 119 119 OSTYPE_VOID_IMPL( os, long long int ) 120 120 121 ostype & ?|?( ostype & os, unsigned long long int ulli ) {121 ostype & ?|?( ostype & os, unsigned long long int ulli ) with ( basic_ostream_table ) { 122 122 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 123 123 fmt( os, "%'llu", ulli ); … … 130 130 #define P10_UINT64 10_000_000_000_000_000_000_ULL // 19 zeroes 131 131 132 static inline void base10_128( ostype & os, unsigned int128 val ) {132 static inline void base10_128( ostype & os, unsigned int128 val ) with ( basic_ostream_table ) { 133 133 #if defined(__GNUC__) && __GNUC_PREREQ(7,0) // gcc version >= 7 134 134 if ( val > P10_UINT64 ) { … … 143 143 } // base10_128 144 144 145 static inline void base10_128( ostype & os, int128 val ) {145 static inline void base10_128( ostype & os, int128 val ) with ( basic_ostream_table ) { 146 146 if ( val < 0 ) { 147 147 fmt( os, "-" ); // leading negative sign … … 151 151 } // base10_128 152 152 153 ostype & ?|?( ostype & os, int128 llli ) {153 ostype & ?|?( ostype & os, int128 llli ) with ( basic_ostream_table ) { 154 154 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 155 155 base10_128( os, llli ); … … 158 158 OSTYPE_VOID_IMPL( os, int128 ) 159 159 160 ostype & ?|?( ostype & os, unsigned int128 ullli ) {160 ostype & ?|?( ostype & os, unsigned int128 ullli ) with ( basic_ostream_table ) { 161 161 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 162 162 base10_128( os, ullli ); … … 181 181 } 182 182 183 ostype & ?|?( ostype & os, float f ) {183 ostype & ?|?( ostype & os, float f ) with ( basic_ostream_table ) { 184 184 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 185 185 PRINT_WITH_DP( os, "%'g", f ); … … 188 188 OSTYPE_VOID_IMPL( os, float ) 189 189 190 ostype & ?|?( ostype & os, double d ) {190 ostype & ?|?( ostype & os, double d ) with ( basic_ostream_table ) { 191 191 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 192 192 PRINT_WITH_DP( os, "%'.*lg", d, DBL_DIG ); … … 195 195 OSTYPE_VOID_IMPL( os, double ) 196 196 197 ostype & ?|?( ostype & os, long double ld ) {197 ostype & ?|?( ostype & os, long double ld ) with ( basic_ostream_table ) { 198 198 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 199 199 PRINT_WITH_DP( os, "%'.*Lg", ld, LDBL_DIG ); … … 202 202 OSTYPE_VOID_IMPL( os, long double ) 203 203 204 ostype & ?|?( ostype & os, float _Complex fc ) {204 ostype & ?|?( ostype & os, float _Complex fc ) with ( basic_ostream_table ) { 205 205 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 206 206 // os | crealf( fc ) | nonl; … … 212 212 OSTYPE_VOID_IMPL( os, float _Complex ) 213 213 214 ostype & ?|?( ostype & os, double _Complex dc ) {214 ostype & ?|?( ostype & os, double _Complex dc ) with ( basic_ostream_table ) { 215 215 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 216 216 // os | creal( dc ) | nonl; … … 222 222 OSTYPE_VOID_IMPL( os, double _Complex ) 223 223 224 ostype & ?|?( ostype & os, long double _Complex ldc ) {224 ostype & ?|?( ostype & os, long double _Complex ldc ) with ( basic_ostream_table ) { 225 225 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 226 226 // os | creall( ldc ) || nonl; … … 232 232 OSTYPE_VOID_IMPL( os, long double _Complex ) 233 233 234 ostype & ?|?( ostype & os, const char s[] ) {234 ostype & ?|?( ostype & os, const char s[] ) with ( basic_ostream_table ) { 235 235 enum { Open = 1, Close, OpenClose }; 236 236 static const unsigned char mask[256] @= { // 256 covers all Latin-1 characters … … 295 295 // } // ?|? 296 296 297 ostype & ?|?( ostype & os, const void * p ) {297 ostype & ?|?( ostype & os, const void * p ) with ( basic_ostream_table ) { 298 298 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 299 299 fmt( os, "%p", p ); … … 306 306 return manip( os ); 307 307 } // ?|? 308 void ?|?( ostype & os, ostype & (* manip)( ostype & ) ) {308 void ?|?( ostype & os, ostype & (* manip)( ostype & ) ) with ( basic_ostream_table ) { 309 309 manip( os ); 310 310 if ( getPrt$( os ) ) ends( os ); // something printed ? … … 312 312 } // ?|? 313 313 314 ostype & nl( ostype & os ) {314 ostype & nl( ostype & os ) with ( basic_ostream_table ) { 315 315 (ostype &)(os | '\n'); 316 316 setPrt$( os, false ); // turn off … … 319 319 } // nl 320 320 321 ostype & nonl( ostype & os ) {321 ostype & nonl( ostype & os ) with ( basic_ostream_table ) { 322 322 setPrt$( os, false ); // turn off 323 323 return os; 324 324 } // nonl 325 325 326 ostype & nlOn( ostype & os ) {326 ostype & nlOn( ostype & os ) with ( basic_ostream_table ) { 327 327 nlOn( os ); // call void returning 328 328 return os; 329 329 } // nlOn 330 330 331 ostype & nlOff( ostype & os ) {331 ostype & nlOff( ostype & os ) with ( basic_ostream_table ) { 332 332 nlOff( os ); // call void returning 333 333 return os; 334 334 } // nlOff 335 335 336 ostype & sepVal( ostype & os ) {336 ostype & sepVal( ostype & os ) with ( basic_ostream_table ) { 337 337 return (ostype &)(os | sepGet( os )); 338 338 } // sepVal 339 339 340 ostype & sepTupleVal( ostype & os ) {340 ostype & sepTupleVal( ostype & os ) with ( basic_ostream_table ) { 341 341 return os | sepGetTuple( os ); 342 342 } // sepTupleVal 343 343 344 ostype & sep( ostype & os ) {344 ostype & sep( ostype & os ) with ( basic_ostream_table ) { 345 345 sep( os ); // call void returning 346 346 return os; 347 347 } // sep 348 348 349 ostype & nosep( ostype & os ) {349 ostype & nosep( ostype & os ) with ( basic_ostream_table ) { 350 350 nosep( os ); // call void returning 351 351 return os; 352 352 } // nosep 353 353 354 ostype & sepOn( ostype & os ) {354 ostype & sepOn( ostype & os ) with ( basic_ostream_table ) { 355 355 sepOn( os ); // call void returning 356 356 return os; 357 357 } // sepOn 358 358 359 ostype & sepOff( ostype & os ) {359 ostype & sepOff( ostype & os ) with ( basic_ostream_table ) { 360 360 sepOff( os ); // call void returning 361 361 return os; … … 365 365 // tuples 366 366 forall( ostype &, T, Params... | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) { 367 ostype & ?|?( ostype & os, T arg, Params rest ) {367 ostype & ?|?( ostype & os, T arg, Params rest ) with ( basic_ostream_table ) { 368 368 (ostype &)(os | arg); // print first argument 369 369 sepSetCur$( os, sepGetTuple( os ) ); // switch to tuple separator … … 372 372 return os; 373 373 } // ?|? 374 void ?|?( ostype & os, T arg, Params rest ) {374 void ?|?( ostype & os, T arg, Params rest ) with ( basic_ostream_table ) { 375 375 // (ostype &)(?|?( os, arg, rest )); ends( os ); 376 376 (ostype &)(os | arg); // print first argument … … 405 405 #define INTEGRAL_FMT_IMPL( T, IFMTNP, IFMTP ) \ 406 406 forall( ostype & | basic_ostream( ostype ) ) { \ 407 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \407 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) with ( basic_ostream_table ) { \ 408 408 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); \ 409 409 \ … … 653 653 } /* eng */ \ 654 654 \ 655 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \655 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) with ( basic_ostream_table ) { \ 656 656 enum { size = 48 }; \ 657 657 char buf[size]; \ … … 692 692 693 693 forall( ostype & | basic_ostream( ostype ) ) { 694 ostype & ?|?( ostype & os, _Ostream_Manip(char) f ) {694 ostype & ?|?( ostype & os, _Ostream_Manip(char) f ) with ( basic_ostream_table ) { 695 695 if ( f.base != 'c' ) { // bespoke binary/octal/hex format 696 696 _Ostream_Manip(unsigned char) fmtuc @= { f.val, f.wd, f.pc, f.base, {'\0'} }; … … 724 724 725 725 forall( ostype & | basic_ostream( ostype ) ) { 726 ostype & ?|?( ostype & os, _Ostream_Manip(const char *) f ) {726 ostype & ?|?( ostype & os, _Ostream_Manip(const char *) f ) with ( basic_ostream_table ) { 727 727 if ( ! f.val ) return os; // null pointer ? 728 728 … … 776 776 777 777 forall( istype & | basic_istream( istype ) ) { 778 istype & ?|?( istype & is, bool & b ) {778 istype & ?|?( istype & is, bool & b ) with ( basic_istream_table ) { 779 779 int len = -1; // len not set if no match 780 780 fmt( is, " " ); // remove leading whitespace … … 792 792 } // ?|? 793 793 794 istype & ?|?( istype & is, char & c ) {794 istype & ?|?( istype & is, char & c ) with ( basic_istream_table ) { 795 795 char temp; 796 796 for () { … … 804 804 } // ?|? 805 805 806 istype & ?|?( istype & is, signed char & sc ) {806 istype & ?|?( istype & is, signed char & sc ) with ( basic_istream_table ) { 807 807 int args = fmt( is, "%hhi", &sc ); // can be multiple characters (100) 808 808 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 811 811 } // ?|? 812 812 813 istype & ?|?( istype & is, unsigned char & usc ) {813 istype & ?|?( istype & is, unsigned char & usc ) with ( basic_istream_table ) { 814 814 int args = fmt( is, "%hhi", &usc ); // can be multiple characters (-100) 815 815 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 818 818 } // ?|? 819 819 820 istype & ?|?( istype & is, short int & si ) {820 istype & ?|?( istype & is, short int & si ) with ( basic_istream_table ) { 821 821 int args = fmt( is, "%hi", &si ); // can be called with EOF on 822 822 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 825 825 } // ?|? 826 826 827 istype & ?|?( istype & is, unsigned short int & usi ) {827 istype & ?|?( istype & is, unsigned short int & usi ) with ( basic_istream_table ) { 828 828 int args = fmt( is, "%hi", &usi ); // can be called with EOF on 829 829 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 832 832 } // ?|? 833 833 834 istype & ?|?( istype & is, int & i ) {834 istype & ?|?( istype & is, int & i ) with ( basic_istream_table ) { 835 835 int args = fmt( is, "%i", &i ); // can be called with EOF on 836 836 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 839 839 } // ?|? 840 840 841 istype & ?|?( istype & is, unsigned int & ui ) {841 istype & ?|?( istype & is, unsigned int & ui ) with ( basic_istream_table ) { 842 842 int args = fmt( is, "%i", &ui ); // can be called with EOF on 843 843 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 846 846 } // ?|? 847 847 848 istype & ?|?( istype & is, long int & li ) {848 istype & ?|?( istype & is, long int & li ) with ( basic_istream_table ) { 849 849 int args = fmt( is, "%li", &li ); // can be called with EOF on 850 850 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 853 853 } // ?|? 854 854 855 istype & ?|?( istype & is, unsigned long int & ulli ) {855 istype & ?|?( istype & is, unsigned long int & ulli ) with ( basic_istream_table ) { 856 856 int args = fmt( is, "%li", &ulli ); // can be called with EOF on 857 857 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 860 860 } // ?|? 861 861 862 istype & ?|?( istype & is, long long int & lli ) {862 istype & ?|?( istype & is, long long int & lli ) with ( basic_istream_table ) { 863 863 int args = fmt( is, "%lli", &lli ); // can be called with EOF on 864 864 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 867 867 } // ?|? 868 868 869 istype & ?|?( istype & is, unsigned long long int & ulli ) {869 istype & ?|?( istype & is, unsigned long long int & ulli ) with ( basic_istream_table ) { 870 870 int args = fmt( is, "%lli", &ulli ); // can be called with EOF on 871 871 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 879 879 } // ?|? 880 880 881 istype & ?|?( istype & is, unsigned int128 & ullli ) {881 istype & ?|?( istype & is, unsigned int128 & ullli ) with ( basic_istream_table ) { 882 882 char s[40]; 883 883 bool sign = false; … … 896 896 #endif // __SIZEOF_INT128__ 897 897 898 istype & ?|?( istype & is, float & f ) {898 istype & ?|?( istype & is, float & f ) with ( basic_istream_table ) { 899 899 int args = fmt( is, "%f", &f ); // can be called with EOF on 900 900 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 903 903 } // ?|? 904 904 905 istype & ?|?( istype & is, double & d ) {905 istype & ?|?( istype & is, double & d ) with ( basic_istream_table ) { 906 906 int args = fmt( is, "%lf", &d ); // can be called with EOF on 907 907 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 910 910 } // ?|? 911 911 912 istype & ?|?( istype & is, long double & ld ) {912 istype & ?|?( istype & is, long double & ld ) with ( basic_istream_table ) { 913 913 int args = fmt( is, "%Lf", &ld ); // can be called with EOF on 914 914 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 917 917 } // ?|? 918 918 919 istype & ?|?( istype & is, float _Complex & fc ) {919 istype & ?|?( istype & is, float _Complex & fc ) with ( basic_istream_table ) { 920 920 float re, im; 921 921 int args = fmt( is, "%f%fi", &re, &im ); // can be called with EOF on … … 926 926 } // ?|? 927 927 928 istype & ?|?( istype & is, double _Complex & dc ) {928 istype & ?|?( istype & is, double _Complex & dc ) with ( basic_istream_table ) { 929 929 double re, im; 930 930 int args = fmt( is, "%lf%lfi", &re, &im ); // can be called with EOF on … … 935 935 } // ?|? 936 936 937 istype & ?|?( istype & is, long double _Complex & ldc ) {937 istype & ?|?( istype & is, long double _Complex & ldc ) with ( basic_istream_table ) { 938 938 long double re, im; 939 939 int args = fmt( is, "%Lf%Lfi", &re, &im ); // can be called with EOF on … … 944 944 } // ?|? 945 945 946 istype & ?|?( istype & is, const char fmt[] ) { // match text946 istype & ?|?( istype & is, const char fmt[] ) with ( basic_istream_table ) { // match text 947 947 size_t len = strlen( fmt ); 948 948 char fmtstr[len + 16]; … … 966 966 } // ?|? 967 967 968 istype & nl( istype & is ) {968 istype & nl( istype & is ) with ( basic_istream_table ) { 969 969 fmt( is, "%*[^\n]" ); // ignore characters to newline 970 970 if ( ! eof( is ) ) fmt( is, "%*c" ); // read newline … … 972 972 } // nl 973 973 974 istype & nlOn( istype & is ) {974 istype & nlOn( istype & is ) with ( basic_istream_table ) { 975 975 nlOn( is ); // call void returning 976 976 return is; 977 977 } // nlOn 978 978 979 istype & nlOff( istype & is ) {979 istype & nlOff( istype & is ) with ( basic_istream_table ) { 980 980 nlOff( is ); // call void returning 981 981 return is; … … 986 986 987 987 forall( istype & | basic_istream( istype ) ) { 988 istype & ?|?( istype & is, _Istream_Cskip f ) {988 istype & ?|?( istype & is, _Istream_Cskip f ) with ( basic_istream_table ) { 989 989 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 990 990 if ( f.scanset ) { … … 1006 1006 } 1007 1007 1008 istype & ?|?( istype & is, _Istream_Cquote f ) with( f.cstr ) {1008 istype & ?|?( istype & is, _Istream_Cquote f ) with( basic_istream_table, f.cstr ) { 1009 1009 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 1010 1010 int args; … … 1031 1031 } 1032 1032 1033 istype & ?|?( istype & is, _Istream_Cstr f ) with( f.cstr ) { 1033 istype & ?|?( istype & is, _Istream_Cstr f ) with( basic_istream_table, f.cstr ) { 1034 assert(eof); 1034 1035 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 1035 1036 const char * scanset; … … 1139 1140 #define INPUT_FMT_IMPL( T, CODE ) \ 1140 1141 forall( istype & | basic_istream( istype ) ) { \ 1141 istype & ?|?( istype & is, _Istream_Manip(T) f ) { \1142 istype & ?|?( istype & is, _Istream_Manip(T) f ) with ( basic_istream_table ) { \ 1142 1143 enum { size = 16 }; \ 1143 1144 char fmtstr[size]; \ … … 1203 1204 1204 1205 forall( istype & | istream( istype ), E | CfaEnum( E ) | Serial( E ) ) 1205 istype & ?|?( istype & is, E & e ) {1206 istype & ?|?( istype & is, E & e ) with ( basic_istream_table ) { 1206 1207 // if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 1207 1208 -
libcfa/src/iostream.hfa
r65bd3c2 rae0c1c3 22 22 23 23 forall( ostype & ) 24 struct basic_ostream_data { 25 // private 26 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 & ); // get newline 32 bool (*setNL$)( ostype &, bool ); // set newline 33 bool (*getANL$)( ostype & ); // get auto newline (on/off) 34 bool (*setANL$)( ostype &, bool ); // set auto newline (on/off), and return previous state 35 bool (*getPrt$)( ostype & ); // get fmt called in output cascade 36 bool (*setPrt$)( ostype &, bool ); // set fmt called in output cascade 37 // public 38 void (*nlOn)( ostype & ); // turn auto-newline state on 39 void (*nlOff)( ostype & ); // turn auto-newline state off 40 41 void (*sep)( ostype & ); // turn separator state on 42 void (*nosep)( ostype & ); // turn separator state off 43 bool (*sepOn)( ostype & ); // set default state to on, and return previous state 44 bool (*sepOff)( ostype & ); // set default state to off, and return previous state 45 const char * (*sepGet)( ostype & ); // get separator string 46 void (*sepSet)( ostype &, const char [] ); // set separator to string (15 character maximum) 47 const char * (*sepGetTuple)( ostype & ); // get tuple separator string 48 void (*sepSetTuple)( ostype &, const char [] ); // set tuple separator to string (15 character maximum) 49 50 void (*ends)( ostype & ); // end of output statement 51 int (*fmt)( ostype &, const char format[], ... ) __attribute__(( format(printf, 2, 3) )); 52 }; // basic_ostream 53 54 forall( ostype & ) 55 struct ostream_data { 56 inline basic_ostream_data( ostype ); 57 bool (*fail)( ostype & ); // operation failed? 58 void (*clearerr)( ostype & ); 59 int (*flush)( ostype & ); 60 void (*open)( ostype &, const char name[], const char mode[] ); 61 void (*close)( ostype & ); 62 ostype & (*write)( ostype &, const char [], size_t ); 63 }; // ostream 64 65 forall( ostype & ) 24 66 trait basic_ostream { 25 // private 26 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 & ); // get newline 32 bool setNL$( ostype &, bool ); // set newline 33 bool getANL$( ostype & ); // get auto newline (on/off) 34 bool setANL$( ostype &, bool ); // set auto newline (on/off), and return previous state 35 bool getPrt$( ostype & ); // get fmt called in output cascade 36 bool setPrt$( ostype &, bool ); // set fmt called in output cascade 37 // public 38 void nlOn( ostype & ); // turn auto-newline state on 39 void nlOff( ostype & ); // turn auto-newline state off 40 41 void sep( ostype & ); // turn separator state on 42 void nosep( ostype & ); // turn separator state off 43 bool sepOn( ostype & ); // set default state to on, and return previous state 44 bool sepOff( ostype & ); // set default state to off, and return previous state 45 const char * sepGet( ostype & ); // get separator string 46 void sepSet( ostype &, const char [] ); // set separator to string (15 character maximum) 47 const char * sepGetTuple( ostype & ); // get tuple separator string 48 void sepSetTuple( ostype &, const char [] ); // set tuple separator to string (15 character maximum) 49 50 void ends( ostype & ); // end of output statement 51 int fmt( ostype &, const char format[], ... ) __attribute__(( format(printf, 2, 3) )); 52 }; // basic_ostream 67 basic_ostream_data(ostype) const & basic_ostream_table; 68 }; 53 69 54 70 forall( ostype & | basic_ostream( ostype ) ) 55 71 trait ostream { 56 bool fail( ostype & ); // operation failed? 57 void clearerr( ostype & ); 58 int flush( ostype & ); 59 void open( ostype &, const char name[], const char mode[] ); 60 void close( ostype & ); 61 ostype & write( ostype &, const char [], size_t ); 62 }; // ostream 72 ostream_data(ostype) const & ostream_table; 73 }; 63 74 64 75 // forall( T ) … … 77 88 #define OSTYPE_VOID_IMPL( os, T ) \ 78 89 void ?|?( ostype & os, T t ) { \ 79 (ostype &)(os | t); ends( os ); \ 90 (ostype &)(os | t); \ 91 basic_ostream_table.ends( os ); \ 80 92 } // ?|? 81 93 … … 308 320 309 321 forall( istype & ) 322 struct basic_istream_data { 323 // private 324 bool (*getANL$)( istype & ); // get scan newline (on/off) 325 bool (*setANL$)( istype &, bool ); // set scan newline (on/off) 326 // public 327 void (*nlOn)( istype & ); // read newline 328 void (*nlOff)( istype & ); // scan newline 329 int (*fmt)( istype &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) )); 330 istype & (*ungetc)( char, istype & ); 331 bool (*eof)( istype & ); 332 void (*clearerr)( istype & ); 333 }; // basic_istream 334 335 forall( istype & ) 336 struct istream_data { 337 inline basic_istream_data( istype ); 338 bool (*fail)( istype & ); 339 void (*open)( istype & is, const char name[], const char mode[] ); 340 void (*open)( istype & is, const char name[] ); 341 void (*close)( istype & is ); 342 istype & (*read)( istype &, char [], size_t ); 343 }; // istream 344 345 forall( istype & ) 310 346 trait basic_istream { 311 // private 312 bool getANL$( istype & ); // get scan newline (on/off) 313 bool setANL$( istype &, bool ); // set scan newline (on/off) 314 // public 315 void nlOn( istype & ); // read newline 316 void nlOff( istype & ); // scan newline 317 int fmt( istype &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) )); 318 istype & ungetc( char, istype & ); 319 bool eof( istype & ); 320 void clearerr( istype & ); 321 }; // basic_istream 347 basic_istream_data(istype) const & basic_istream_table; 348 }; 322 349 323 350 forall( istype & | basic_istream( istype ) ) 324 351 trait istream { 325 bool fail( istype & ); 326 void open( istype & is, const char name[], const char mode[] ); 327 void open( istype & is, const char name[] ); 328 void close( istype & is ); 329 istype & read( istype &, char [], size_t ); 330 }; // istream 352 istream_data(istype) const & istream_table; 353 }; 331 354 332 355 forall( T ) -
libcfa/src/strstream.cfa
r65bd3c2 rae0c1c3 28 28 // *********************************** strstream *********************************** 29 29 30 static basic_ostream_data(ostrstream) ostrstream_basic_data = { 31 sepPrt$, 32 sepReset$, 33 sepReset$, 34 sepGetCur$, 35 sepSetCur$, 36 getNL$, 37 setNL$, 38 getANL$, 39 setANL$, 40 getPrt$, 41 setPrt$, 42 nlOn, 43 nlOff, 44 sep, 45 nosep, 46 sepOn, 47 sepOff, 48 sepGet, 49 sepSet, 50 sepGetTuple, 51 sepSetTuple, 52 ends, 53 fmt, 54 }; 55 56 basic_ostream_data(ostrstream) const & basic_ostream_table = ostrstream_basic_data; 30 57 31 58 #define IO_MSG "I/O error: " … … 130 157 131 158 // *********************************** istrstream *********************************** 159 160 static basic_istream_data(istrstream) istrstream_basic_data = { 161 getANL$, 162 setANL$, 163 nlOn, 164 nlOff, 165 fmt, 166 ungetc, 167 eof, 168 clearerr, 169 }; 170 171 basic_istream_data(istrstream) const & basic_istream_data = istrstream_basic_data; 132 172 133 173 // private -
libcfa/src/strstream.hfa
r65bd3c2 rae0c1c3 39 39 40 40 // Satisfies basic_ostream 41 extern basic_ostream_data(ostrstream) const & basic_ostream_table; 41 42 42 43 // private … … 90 91 91 92 // Satisfies basic_istream 93 extern basic_istream_data(istrstream) const & basic_istream_table; 92 94 93 95 // private
Note:
See TracChangeset
for help on using the changeset viewer.