Changeset ae0c1c3 for libcfa/src/iostream.cfa
- Timestamp:
- Apr 25, 2025, 7:08:53 PM (9 months ago)
- Branches:
- master
- Children:
- 7d02d35, ecfa58be
- Parents:
- 65bd3c2
- File:
-
- 1 edited
-
libcfa/src/iostream.cfa (modified) (60 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.