Changeset adaee12 for libcfa/src
- Timestamp:
- Apr 28, 2021, 1:06:13 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- b7fd2db6
- Parents:
- e9c0b4c (diff), c7015e6b (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. - Location:
- libcfa/src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/coroutine.cfa
re9c0b4c radaee12 61 61 forall(T & | is_coroutine(T)) 62 62 void __cfaehm_cancelled_coroutine( 63 T & cor, $coroutine * desc, _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable) {63 T & cor, $coroutine * desc, EHM_DEFAULT_VTABLE(CoroutineCancelled, (T)) ) { 64 64 verify( desc->cancellation ); 65 65 desc->state = Cancelled; … … 145 145 // Part of the Public API 146 146 // Not inline since only ever called once per coroutine 147 forall(T & | is_coroutine(T) | { _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable; })147 forall(T & | is_coroutine(T) | { EHM_DEFAULT_VTABLE(CoroutineCancelled, (T)); }) 148 148 void prime(T& cor) { 149 149 $coroutine* this = get_coroutine(cor); -
libcfa/src/concurrency/coroutine.hfa
re9c0b4c radaee12 60 60 //----------------------------------------------------------------------------- 61 61 // Public coroutine API 62 forall(T & | is_coroutine(T) | { _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable; })62 forall(T & | is_coroutine(T) | { EHM_DEFAULT_VTABLE(CoroutineCancelled, (T)); }) 63 63 void prime(T & cor); 64 64 … … 131 131 forall(T & | is_coroutine(T)) 132 132 void __cfaehm_cancelled_coroutine( 133 T & cor, $coroutine * desc, _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable);133 T & cor, $coroutine * desc, EHM_DEFAULT_VTABLE(CoroutineCancelled, (T)) ); 134 134 135 135 // Resume implementation inlined for performance 136 forall(T & | is_coroutine(T) | { _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable; })136 forall(T & | is_coroutine(T) | { EHM_DEFAULT_VTABLE(CoroutineCancelled, (T)); }) 137 137 static inline T & resume(T & cor) { 138 138 // optimization : read TLS once and reuse it -
libcfa/src/concurrency/stats.cfa
re9c0b4c radaee12 126 126 127 127 char buf[1024]; 128 strstream sstr = { buf, 1024 };128 ostrstream sstr = { buf, 1024 }; 129 129 130 130 if( flags & CFA_STATS_READY_Q ) { -
libcfa/src/concurrency/thread.cfa
re9c0b4c radaee12 82 82 83 83 forall(T & | is_thread(T) | IS_EXCEPTION(ThreadCancelled, (T)) 84 | { _EHM_VTABLE_TYPE(ThreadCancelled)(T) & const _default_vtable; })84 | { EHM_DEFAULT_VTABLE(ThreadCancelled, (T)); }) 85 85 void ?{}( thread_dtor_guard_t & this, 86 86 T & thrd, void(*cancelHandler)(ThreadCancelled(T) &)) { … … 161 161 //----------------------------------------------------------------------------- 162 162 forall(T & | is_thread(T) | IS_RESUMPTION_EXCEPTION(ThreadCancelled, (T)) 163 | { _EHM_VTABLE_TYPE(ThreadCancelled)(T) & const _default_vtable; })163 | { EHM_DEFAULT_VTABLE(ThreadCancelled, (T)); }) 164 164 T & join( T & this ) { 165 165 thread_dtor_guard_t guard = { this, defaultResumptionHandler }; -
libcfa/src/concurrency/thread.hfa
re9c0b4c radaee12 80 80 81 81 forall( T & | is_thread(T) | IS_EXCEPTION(ThreadCancelled, (T)) 82 | { _EHM_VTABLE_TYPE(ThreadCancelled)(T) & const _default_vtable; })82 | { EHM_DEFAULT_VTABLE(ThreadCancelled, (T)); }) 83 83 void ?{}( thread_dtor_guard_t & this, T & thrd, void(*)(ThreadCancelled(T) &) ); 84 84 void ^?{}( thread_dtor_guard_t & this ); … … 127 127 // join 128 128 forall( T & | is_thread(T) | IS_RESUMPTION_EXCEPTION(ThreadCancelled, (T)) 129 | { _EHM_VTABLE_TYPE(ThreadCancelled)(T) & const _default_vtable; })129 | { EHM_DEFAULT_VTABLE(ThreadCancelled, (T)); }) 130 130 T & join( T & this ); 131 131 -
libcfa/src/exception.hfa
re9c0b4c radaee12 64 64 _EHM_VIRTUAL_TABLE(exception_name, arguments, table_name) 65 65 66 #define EHM_TYPE_ID(exception_name) _EHM_TYPE_ID_TYPE(exception_name) 67 68 #define EHM_MATCH_ALL __cfa__parent_vtable 66 // EHM_DEFAULT_VTABLE(exception_name, (arguments)) 67 // Create a declaration for a (possibly polymorphic) default vtable. 68 #define EHM_DEFAULT_VTABLE(exception_name, arguments) \ 69 _EHM_VTABLE_TYPE(exception_name) arguments & const _default_vtable 69 70 70 71 // IS_EXCEPTION(exception_name [, (...parameters)]) -
libcfa/src/fstream.cfa
re9c0b4c radaee12 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Apr 24 09:05:16202113 // Update Count : 4 2614 // 15 16 #include "fstream.hfa" 12 // Last Modified On : Tue Apr 27 22:08:57 2021 13 // Update Count : 442 14 // 15 16 #include "fstream.hfa" // also includes iostream.hfa 17 17 18 18 #include <stdio.h> // vfprintf, vfscanf … … 196 196 ofstream & abort = abortFile; 197 197 198 ofstream & nl( ofstream & os ) { 199 nl$( os ); // call basic_ostream nl 200 flush( os ); 201 return os; 202 // (ofstream &)(os | '\n'); 203 // setPrt$( os, false ); // turn off 204 // setNL$( os, true ); 205 // flush( os ); 206 // return sepOff( os ); // prepare for next line 207 } // nl 198 208 199 209 // *********************************** ifstream *********************************** -
libcfa/src/fstream.hfa
re9c0b4c radaee12 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Apr 24 09:04:03202113 // Update Count : 2 1912 // Last Modified On : Tue Apr 27 22:00:30 2021 13 // Update Count : 226 14 14 // 15 15 … … 71 71 bool fail( ofstream & ); 72 72 int flush( ofstream & ); 73 void open( ofstream &, const char name[], const char mode[] ); 73 void open( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w" 74 74 void open( ofstream &, const char name[] ); 75 75 void close( ofstream & ); … … 86 86 87 87 void ?{}( ofstream & ); 88 void ?{}( ofstream &, const char name[], const char mode[] ); 88 void ?{}( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w" 89 89 void ?{}( ofstream &, const char name[] ); 90 90 void ^?{}( ofstream & ); 91 92 // private 93 static inline ofstream & nl$( ofstream & os ) { return nl( os ); } // remember basic_ostream nl 94 // public 95 ofstream & nl( ofstream & os ); // override basic_ostream nl 91 96 92 97 extern ofstream & sout, & stdout, & serr, & stderr; // aliases … … 111 116 bool getANL( ifstream & ); 112 117 void ends( ifstream & ); 118 int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) )); 119 113 120 bool fail( ifstream & is ); 114 121 int eof( ifstream & is ); 115 void open( ifstream & is, const char name[], const char mode[] ); 122 void open( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r" 116 123 void open( ifstream & is, const char name[] ); 117 124 void close( ifstream & is ); 118 125 ifstream & read( ifstream & is, char * data, size_t size ); 119 126 ifstream & ungetc( ifstream & is, char c ); 120 int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) )); 127 121 128 void acquire( ifstream & is ); 122 129 void release( ifstream & is ); … … 129 136 130 137 void ?{}( ifstream & is ); 131 void ?{}( ifstream & is, const char name[], const char mode[] ); 138 void ?{}( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r" 132 139 void ?{}( ifstream & is, const char name[] ); 133 140 void ^?{}( ifstream & is ); -
libcfa/src/iostream.cfa
re9c0b4c radaee12 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Apr 24 10:03:54202113 // Update Count : 13 2912 // Last Modified On : Tue Apr 27 18:01:03 2021 13 // Update Count : 1330 14 14 // 15 15 … … 145 145 } // ?|? 146 146 147 #if defined( __SIZEOF_INT128__ )147 #if defined( __SIZEOF_INT128__ ) 148 148 // UINT64_MAX 18_446_744_073_709_551_615_ULL 149 149 #define P10_UINT64 10_000_000_000_000_000_000_ULL // 19 zeroes 150 150 151 151 static inline void base10_128( ostype & os, unsigned int128 val ) { 152 #if defined(__GNUC__) && __GNUC_PREREQ(7,0)// gcc version >= 7152 #if defined(__GNUC__) && __GNUC_PREREQ(7,0) // gcc version >= 7 153 153 if ( val > P10_UINT64 ) { 154 #else154 #else 155 155 if ( (uint64_t)(val >> 64) != 0 || (uint64_t)val > P10_UINT64 ) { // patch gcc 5 & 6 -O3 bug 156 #endif // __GNUC_PREREQ(7,0)156 #endif // __GNUC_PREREQ(7,0) 157 157 base10_128( os, val / P10_UINT64 ); // recursive 158 158 fmt( os, "%.19lu", (uint64_t)(val % P10_UINT64) ); … … 187 187 (ostype &)(os | ullli); ends( os ); 188 188 } // ?|? 189 #endif // __SIZEOF_INT128__189 #endif // __SIZEOF_INT128__ 190 190 191 191 #define PrintWithDP( os, format, val, ... ) \ … … 361 361 setPrt$( os, false ); // turn off 362 362 setNL$( os, true ); 363 flush( os );364 363 return sepOff( os ); // prepare for next line 365 364 } // nl … … 808 807 809 808 810 forall( istype & | istream( istype ) ) {809 forall( istype & | basic_istream( istype ) ) { 811 810 istype & ?|?( istype & is, bool & b ) { 812 811 char val[6]; … … 918 917 } // ?|? 919 918 920 #if defined( __SIZEOF_INT128__ )919 #if defined( __SIZEOF_INT128__ ) 921 920 istype & ?|?( istype & is, int128 & llli ) { 922 921 return (istype &)(is | (unsigned int128 &)llli); … … 944 943 (istype &)(is | ullli); ends( is ); 945 944 } // ?|? 946 #endif // __SIZEOF_INT128__945 #endif // __SIZEOF_INT128__ 947 946 948 947 istype & ?|?( istype & is, float & f ) { … … 1035 1034 return is; 1036 1035 } // nlOff 1037 1036 } // distribution 1037 1038 forall( istype & | istream( istype ) ) { 1038 1039 istype & acquire( istype & is ) { 1039 1040 acquire( is ); // call void returning … … 1044 1045 // *********************************** manipulators *********************************** 1045 1046 1046 forall( istype & | istream( istype ) ) {1047 forall( istype & | basic_istream( istype ) ) { 1047 1048 istype & ?|?( istype & is, _Istream_Cstr f ) { 1048 1049 // skip xxx … … 1092 1093 1093 1094 #define InputFMTImpl( T, CODE ) \ 1094 forall( istype & | istream( istype ) ) { \1095 forall( istype & | basic_istream( istype ) ) { \ 1095 1096 istype & ?|?( istype & is, _Istream_Manip(T) f ) { \ 1096 1097 enum { size = 16 }; \ … … 1125 1126 InputFMTImpl( long double, "Lf" ) 1126 1127 1127 forall( istype & | istream( istype ) ) {1128 forall( istype & | basic_istream( istype ) ) { 1128 1129 istype & ?|?( istype & is, _Istream_Manip(float _Complex) fc ) { 1129 1130 float re, im; -
libcfa/src/iostream.hfa
re9c0b4c radaee12 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Apr 24 09:28:56202113 // Update Count : 39 312 // Last Modified On : Tue Apr 27 17:59:21 2021 13 // Update Count : 398 14 14 // 15 15 … … 49 49 void ends( ostype & ); // end of output statement 50 50 int fmt( ostype &, const char format[], ... ) __attribute__(( format(printf, 2, 3) )); 51 int flush( ostype & );52 51 }; // basic_ostream 53 52 54 53 trait ostream( ostype & | basic_ostream( ostype ) ) { 54 int flush( ostype & ); 55 55 bool fail( ostype & ); // operation failed? 56 56 void open( ostype &, const char name[], const char mode[] ); … … 97 97 ostype & ?|?( ostype &, unsigned long long int ); 98 98 void ?|?( ostype &, unsigned long long int ); 99 #if defined( __SIZEOF_INT128__ )99 #if defined( __SIZEOF_INT128__ ) 100 100 ostype & ?|?( ostype &, int128 ); 101 101 void ?|?( ostype &, int128 ); 102 102 ostype & ?|?( ostype &, unsigned int128 ); 103 103 void ?|?( ostype &, unsigned int128 ); 104 #endif // __SIZEOF_INT128__104 #endif // __SIZEOF_INT128__ 105 105 106 106 ostype & ?|?( ostype &, float ); … … 121 121 void ?|?( ostype &, const char [] ); 122 122 // ostype & ?|?( ostype &, const char16_t * ); 123 #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous123 #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous 124 124 // ostype & ?|?( ostype &, const char32_t * ); 125 #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 )125 #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) 126 126 // ostype & ?|?( ostype &, const wchar_t * ); 127 127 ostype & ?|?( ostype &, const void * ); … … 164 164 struct _Ostream_Manip { 165 165 T val; // polymorphic base-type 166 int wd, pc; // width, precision 166 int wd, pc; // width, precision: signed for computations 167 167 char base; // numeric base / floating-point style 168 168 union { … … 192 192 _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'x', { .all : 0 } }; } \ 193 193 _Ostream_Manip(T) wd( unsigned int w, T val ) { return (_Ostream_Manip(T))@{ val, w, 0, CODE, { .all : 0 } }; } \ 194 _Ostream_Manip(T) wd( unsigned int w, unsigned charpc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, CODE, { .flags.pc : true } }; } \194 _Ostream_Manip(T) wd( unsigned int w, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, CODE, { .flags.pc : true } }; } \ 195 195 _Ostream_Manip(T) & wd( unsigned int w, _Ostream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \ 196 _Ostream_Manip(T) & wd( unsigned int w, unsigned charpc, _Ostream_Manip(T) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \196 _Ostream_Manip(T) & wd( unsigned int w, unsigned int pc, _Ostream_Manip(T) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \ 197 197 _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \ 198 198 _Ostream_Manip(T) & upcase( _Ostream_Manip(T) & fmt ) { if ( fmt.base == 'x' || fmt.base == 'b' ) fmt.base -= 32; /* upper case */ return fmt; } \ … … 231 231 _Ostream_Manip(T) eng( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.eng : true } }; } \ 232 232 _Ostream_Manip(T) wd( unsigned int w, T val ) { return (_Ostream_Manip(T))@{ val, w, 0, 'g', { .all : 0 } }; } \ 233 _Ostream_Manip(T) wd( unsigned int w, unsigned charpc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'f', { .flags.pc : true } }; } \234 _Ostream_Manip(T) ws( unsigned int w, unsigned charpc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'g', { .flags.pc : true } }; } \233 _Ostream_Manip(T) wd( unsigned int w, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'f', { .flags.pc : true } }; } \ 234 _Ostream_Manip(T) ws( unsigned int w, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'g', { .flags.pc : true } }; } \ 235 235 _Ostream_Manip(T) & wd( unsigned int w, _Ostream_Manip(T) & fmt ) { if ( fmt.flags.eng ) fmt.base = 'f'; fmt.wd = w; return fmt; } \ 236 _Ostream_Manip(T) & wd( unsigned int w, unsigned charpc, _Ostream_Manip(T) & fmt ) { if ( fmt.flags.eng ) fmt.base = 'f'; fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \237 _Ostream_Manip(T) & ws( unsigned int w, unsigned charpc, _Ostream_Manip(T) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \236 _Ostream_Manip(T) & wd( unsigned int w, unsigned int pc, _Ostream_Manip(T) & fmt ) { if ( fmt.flags.eng ) fmt.base = 'f'; fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \ 237 _Ostream_Manip(T) & ws( unsigned int w, unsigned int pc, _Ostream_Manip(T) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \ 238 238 _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \ 239 239 _Ostream_Manip(T) upcase( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'G', { .all : 0 } }; } \ … … 279 279 _Ostream_Manip(const char *) hex( const char s[] ) { return (_Ostream_Manip(const char *))@{ s, 1, 0, 'x', { .all : 0 } }; } 280 280 _Ostream_Manip(const char *) wd( unsigned int w, const char s[] ) { return (_Ostream_Manip(const char *))@{ s, w, 0, 's', { .all : 0 } }; } 281 _Ostream_Manip(const char *) wd( unsigned int w, unsigned charpc, const char s[] ) { return (_Ostream_Manip(const char *))@{ s, w, pc, 's', { .flags.pc : true } }; }281 _Ostream_Manip(const char *) wd( unsigned int w, unsigned int pc, const char s[] ) { return (_Ostream_Manip(const char *))@{ s, w, pc, 's', { .flags.pc : true } }; } 282 282 _Ostream_Manip(const char *) & wd( unsigned int w, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; return fmt; } 283 _Ostream_Manip(const char *) & wd( unsigned int w, unsigned charpc, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; }283 _Ostream_Manip(const char *) & wd( unsigned int w, unsigned int pc, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } 284 284 _Ostream_Manip(const char *) & left( _Ostream_Manip(const char *) & fmt ) { fmt.flags.left = true; return fmt; } 285 285 _Ostream_Manip(const char *) & nobase( _Ostream_Manip(const char *) & fmt ) { fmt.flags.nobsdp = true; return fmt; } … … 294 294 295 295 296 trait istream( istype & ) { 296 trait basic_istream( istype & ) { 297 bool getANL( istype & ); // get scan newline (on/off) 297 298 void nlOn( istype & ); // read newline 298 299 void nlOff( istype & ); // scan newline 299 bool getANL( istype & ); // get scan newline (on/off)300 300 301 301 void ends( istype & os ); // end of output statement 302 int fmt( istype &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) )); 303 istype & ungetc( istype &, char ); 304 int eof( istype & ); 305 }; // basic_istream 306 307 trait istream( istype & | basic_istream( istype ) ) { 302 308 bool fail( istype & ); 303 int eof( istype & );304 309 void open( istype & is, const char name[] ); 305 310 void close( istype & is ); 306 311 istype & read( istype &, char *, size_t ); 307 istype & ungetc( istype &, char ); 308 int fmt( istype &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) )); 309 void acquire( istype & ); 312 void acquire( istype & ); // concurrent access 310 313 }; // istream 311 314 … … 314 317 }; // readable 315 318 316 forall( istype & | istream( istype ) ) {319 forall( istype & | basic_istream( istype ) ) { 317 320 istype & ?|?( istype &, bool & ); 318 321 void ?|?( istype &, bool & ); … … 341 344 istype & ?|?( istype &, unsigned long long int & ); 342 345 void ?|?( istype &, unsigned long long int & ); 343 #if defined( __SIZEOF_INT128__ )346 #if defined( __SIZEOF_INT128__ ) 344 347 istype & ?|?( istype &, int128 & ); 345 348 void ?|?( istype &, int128 & ); 346 349 istype & ?|?( istype &, unsigned int128 & ); 347 350 void ?|?( istype &, unsigned int128 & ); 348 #endif // __SIZEOF_INT128__351 #endif // __SIZEOF_INT128__ 349 352 350 353 istype & ?|?( istype &, float & ); … … 372 375 istype & nlOn( istype & ); 373 376 istype & nlOff( istype & ); 377 } // distribution 378 379 forall( istype & | istream( istype ) ) { 374 380 istype & acquire( istype & ); 375 381 } // distribution … … 391 397 392 398 static inline { 399 _Istream_Cstr skip( const char scanset[] ) { return (_Istream_Cstr){ 0p, scanset, -1, { .all : 0 } }; } 393 400 _Istream_Cstr skip( unsigned int n ) { return (_Istream_Cstr){ 0p, 0p, n, { .all : 0 } }; } 394 _Istream_Cstr skip( const char scanset[] ) { return (_Istream_Cstr){ 0p, scanset, -1, { .all : 0 } }; }395 401 _Istream_Cstr incl( const char scanset[], char * s ) { return (_Istream_Cstr){ s, scanset, -1, { .flags.inex : false } }; } 396 402 _Istream_Cstr & incl( const char scanset[], _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = false; return fmt; } … … 402 408 _Istream_Cstr & wdi( unsigned int w, _Istream_Cstr & fmt ) { fmt.wd = w; return fmt; } 403 409 } // distribution 404 forall( istype & | istream( istype ) ) {410 forall( istype & | basic_istream( istype ) ) { 405 411 istype & ?|?( istype & is, _Istream_Cstr f ); 406 412 void ?|?( istype & is, _Istream_Cstr f ); … … 415 421 _Istream_Char & ignore( _Istream_Char & fmt ) { fmt.ignore = true; return fmt; } 416 422 } // distribution 417 forall( istype & | istream( istype ) ) {423 forall( istype & | basic_istream( istype ) ) { 418 424 istype & ?|?( istype & is, _Istream_Char f ); 419 425 void ?|?( istype & is, _Istream_Char f ); … … 434 440 _Istream_Manip(T) & wdi( unsigned int w, _Istream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \ 435 441 } /* distribution */ \ 436 forall( istype & | istream( istype ) ) { \442 forall( istype & | basic_istream( istype ) ) { \ 437 443 istype & ?|?( istype & is, _Istream_Manip(T) f ); \ 438 444 void ?|?( istype & is, _Istream_Manip(T) f ); \ -
libcfa/src/strstream.cfa
re9c0b4c radaee12 10 10 // Created On : Thu Apr 22 22:24:35 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Apr 24 11:15:47202113 // Update Count : 7 312 // Last Modified On : Tue Apr 27 20:59:53 2021 13 // Update Count : 78 14 14 // 15 15 … … 23 23 #include <unistd.h> // sbrk, sysconf 24 24 25 25 26 // *********************************** strstream *********************************** 26 27 … … 29 30 30 31 // private 31 bool sepPrt$( strstream & os ) { setNL$( os, false ); return os.sepOnOff$; }32 void sepReset$( strstream & os ) { os.sepOnOff$ = os.sepDefault$; }33 void sepReset$( strstream & os, bool reset ) { os.sepDefault$ = reset; os.sepOnOff$ = os.sepDefault$; }34 const char * sepGetCur$( strstream & os ) { return os.sepCur$; }35 void sepSetCur$( strstream & os, const char sepCur[] ) { os.sepCur$ = sepCur; }36 bool getNL$( strstream & os ) { return os.sawNL$; }37 void setNL$( strstream & os, bool state ) { os.sawNL$ = state; }38 bool getANL$( strstream & os ) { return os.nlOnOff$; }39 bool getPrt$( strstream & os ) { return os.prt$; }40 void setPrt$( strstream & os, bool state ) { os.prt$ = state; }32 bool sepPrt$( ostrstream & os ) { setNL$( os, false ); return os.sepOnOff$; } 33 void sepReset$( ostrstream & os ) { os.sepOnOff$ = os.sepDefault$; } 34 void sepReset$( ostrstream & os, bool reset ) { os.sepDefault$ = reset; os.sepOnOff$ = os.sepDefault$; } 35 const char * sepGetCur$( ostrstream & os ) { return os.sepCur$; } 36 void sepSetCur$( ostrstream & os, const char sepCur[] ) { os.sepCur$ = sepCur; } 37 bool getNL$( ostrstream & os ) { return os.sawNL$; } 38 void setNL$( ostrstream & os, bool state ) { os.sawNL$ = state; } 39 bool getANL$( ostrstream & os ) { return os.nlOnOff$; } 40 bool getPrt$( ostrstream & os ) { return os.prt$; } 41 void setPrt$( ostrstream & os, bool state ) { os.prt$ = state; } 41 42 42 43 // public 43 void ?{}( strstream & os, char buf[], size_t size ) {44 void ?{}( ostrstream & os, char buf[], size_t size ) { 44 45 os.buf$ = buf; 45 46 os.size$ = size; … … 55 56 } // ?{} 56 57 57 void sepOn( strstream & os ) { os.sepOnOff$ = ! getNL$( os ); }58 void sepOff( strstream & os ) { os.sepOnOff$ = false; }58 void sepOn( ostrstream & os ) { os.sepOnOff$ = ! getNL$( os ); } 59 void sepOff( ostrstream & os ) { os.sepOnOff$ = false; } 59 60 60 bool sepDisable( strstream & os ) {61 bool sepDisable( ostrstream & os ) { 61 62 bool temp = os.sepDefault$; 62 63 os.sepDefault$ = false; … … 65 66 } // sepDisable 66 67 67 bool sepEnable( strstream & os ) {68 bool sepEnable( ostrstream & os ) { 68 69 bool temp = os.sepDefault$; 69 70 os.sepDefault$ = true; … … 72 73 } // sepEnable 73 74 74 void nlOn( strstream & os ) { os.nlOnOff$ = true; }75 void nlOff( strstream & os ) { os.nlOnOff$ = false; }75 void nlOn( ostrstream & os ) { os.nlOnOff$ = true; } 76 void nlOff( ostrstream & os ) { os.nlOnOff$ = false; } 76 77 77 const char * sepGet( strstream & os ) { return os.separator$; }78 void sepSet( strstream & os, const char s[] ) {78 const char * sepGet( ostrstream & os ) { return os.separator$; } 79 void sepSet( ostrstream & os, const char s[] ) { 79 80 assert( s ); 80 strncpy( os.separator$, s, strstream_sepSize - 1 );81 os.separator$[ strstream_sepSize - 1] = '\0';81 strncpy( os.separator$, s, ostrstream_sepSize - 1 ); 82 os.separator$[ostrstream_sepSize - 1] = '\0'; 82 83 } // sepSet 83 84 84 const char * sepGetTuple( strstream & os ) { return os.tupleSeparator$; }85 void sepSetTuple( strstream & os, const char s[] ) {85 const char * sepGetTuple( ostrstream & os ) { return os.tupleSeparator$; } 86 void sepSetTuple( ostrstream & os, const char s[] ) { 86 87 assert( s ); 87 strncpy( os.tupleSeparator$, s, strstream_sepSize - 1 );88 os.tupleSeparator$[ strstream_sepSize - 1] = '\0';88 strncpy( os.tupleSeparator$, s, ostrstream_sepSize - 1 ); 89 os.tupleSeparator$[ostrstream_sepSize - 1] = '\0'; 89 90 } // sepSet 90 91 91 void ends( strstream & os ) {92 void ends( ostrstream & os ) { 92 93 if ( getANL$( os ) ) nl( os ); 93 94 else setPrt$( os, false ); // turn off 94 95 } // ends 95 96 96 int fmt( strstream & os, const char format[], ... ) {97 int fmt( ostrstream & os, const char format[], ... ) { 97 98 va_list args; 98 99 va_start( args, format ); 99 100 int len = vsnprintf( os.buf$ + os.cursor$, os.size$ - os.cursor$, format, args ); 101 va_end( args ); 100 102 os.cursor$ += len; 101 103 if ( os.cursor$ >= os.size$ ) { // cursor exceeded buffer size? 102 #define fmtmsg IO_MSG " strstream truncated write, buffer too small.\n"104 #define fmtmsg IO_MSG "ostrstream truncated write, buffer too small.\n" 103 105 write( STDERR_FILENO, fmtmsg, sizeof(fmtmsg) - 1 ); 104 106 abort(); 105 107 } // if 106 va_end( args );107 108 108 109 setPrt$( os, true ); // called in output cascade … … 111 112 } // fmt 112 113 113 int flush( strstream & ) { // match trait, not used 114 return 0; 115 } // flush 116 117 strstream & write( strstream & os ) { 118 return write( os, stdout ); 119 } // write 120 strstream & write( strstream & os, FILE * stream ) { 114 ostrstream & write( ostrstream & os, FILE * stream ) { 121 115 if ( fwrite( os.buf$, 1, os.cursor$, stream ) != os.cursor$ ) { 122 #define writemsg IO_MSG "strstream write error.\n"123 write( STDERR_FILENO, writemsg, sizeof(writemsg) - 1 );116 #define ostrwritemsg IO_MSG "ostrstream write error.\n" 117 write( STDERR_FILENO, ostrwritemsg, sizeof(ostrwritemsg) - 1 ); 124 118 abort(); 125 119 } // if … … 127 121 } // write 128 122 129 strstream & sstr; 123 ostrstream & write( ostrstream & os ) { 124 return write( os, stdout ); 125 } // write 126 127 128 // *********************************** istrstream *********************************** 129 130 131 // public 132 void ?{}( istrstream & is, char buf[] ) { 133 is.buf$ = buf; 134 is.cursor$ = 0; 135 is.nlOnOff$ = false; 136 } // ?{} 137 138 bool getANL( istrstream & is ) { return is.nlOnOff$; } 139 void nlOn( istrstream & is ) { is.nlOnOff$ = true; } 140 void nlOff( istrstream & is ) { is.nlOnOff$ = false; } 141 142 void ends( istrstream & is ) { 143 } // ends 144 145 int eof( istrstream & is ) { 146 return 0; 147 } // eof 148 149 istrstream &ungetc( istrstream & is, char c ) { 150 // if ( ungetc( c, (FILE *)(is.file$) ) == EOF ) { 151 // abort | IO_MSG "ungetc" | nl | strerror( errno ); 152 // } // if 153 return is; 154 } // ungetc 155 156 int fmt( istrstream & is, const char format[], ... ) { 157 va_list args; 158 va_start( args, format ); 159 // This does not work because vsscanf does not return buffer position. 160 int len = vsscanf( is.buf$ + is.cursor$, format, args ); 161 va_end( args ); 162 if ( len == EOF ) { 163 int j; 164 printf( "X %d%n\n", len, &j ); 165 } // if 166 is.cursor$ += len; 167 return len; 168 } // fmt 130 169 131 170 // Local Variables: // -
libcfa/src/strstream.hfa
re9c0b4c radaee12 10 10 // Created On : Thu Apr 22 22:20:59 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Apr 24 11:17:33202113 // Update Count : 3712 // Last Modified On : Tue Apr 27 20:58:50 2021 13 // Update Count : 41 14 14 // 15 15 … … 20 20 21 21 22 // *********************************** strstream ***********************************22 // *********************************** ostrstream *********************************** 23 23 24 24 25 enum { strstream_sepSize = 16 };26 struct strstream { // satisfied basic_ostream25 enum { ostrstream_sepSize = 16 }; 26 struct ostrstream { // satisfied basic_ostream 27 27 char * buf$; 28 28 size_t size$; … … 34 34 bool sawNL$; 35 35 const char * sepCur$; 36 char separator$[ strstream_sepSize];37 char tupleSeparator$[ strstream_sepSize];38 }; // strstream36 char separator$[ostrstream_sepSize]; 37 char tupleSeparator$[ostrstream_sepSize]; 38 }; // ostrstream 39 39 40 40 // Satisfies basic_ostream 41 41 42 42 // private 43 bool sepPrt$( strstream & );44 void sepReset$( strstream & );45 void sepReset$( strstream &, bool );46 const char * sepGetCur$( strstream & );47 void sepSetCur$( strstream &, const char [] );48 bool getNL$( strstream & );49 void setNL$( strstream &, bool );50 bool getANL$( strstream & );51 bool getPrt$( strstream & );52 void setPrt$( strstream &, bool );43 bool sepPrt$( ostrstream & ); 44 void sepReset$( ostrstream & ); 45 void sepReset$( ostrstream &, bool ); 46 const char * sepGetCur$( ostrstream & ); 47 void sepSetCur$( ostrstream &, const char [] ); 48 bool getNL$( ostrstream & ); 49 void setNL$( ostrstream &, bool ); 50 bool getANL$( ostrstream & ); 51 bool getPrt$( ostrstream & ); 52 void setPrt$( ostrstream &, bool ); 53 53 54 54 // public 55 void sepOn( strstream & );56 void sepOff( strstream & );57 bool sepDisable( strstream & );58 bool sepEnable( strstream & );59 void nlOn( strstream & );60 void nlOff( strstream & );55 void sepOn( ostrstream & ); 56 void sepOff( ostrstream & ); 57 bool sepDisable( ostrstream & ); 58 bool sepEnable( ostrstream & ); 59 void nlOn( ostrstream & ); 60 void nlOff( ostrstream & ); 61 61 62 const char * sepGet( strstream & );63 void sepSet( strstream &, const char [] );64 const char * sepGetTuple( strstream & );65 void sepSetTuple( strstream &, const char [] );62 const char * sepGet( ostrstream & ); 63 void sepSet( ostrstream &, const char [] ); 64 const char * sepGetTuple( ostrstream & ); 65 void sepSetTuple( ostrstream &, const char [] ); 66 66 67 void ends( strstream & ); 68 int fmt( strstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) )); 69 int flush( strstream & ); 67 void ends( ostrstream & ); 68 int fmt( ostrstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) )); 70 69 71 strstream & write( strstream & os ); // use stdout, default value not working 72 strstream & write( strstream & os, FILE * stream = stdout);70 ostrstream & write( ostrstream & os, FILE * stream ); // FIX ME: use default = stdout 71 ostrstream & write( ostrstream & os ); 73 72 74 void ?{}( strstream &, char buf[], size_t size );73 void ?{}( ostrstream &, char buf[], size_t size ); 75 74 76 extern strstream & sstr; 75 76 // *********************************** istrstream *********************************** 77 78 79 struct istrstream { 80 char * buf$; 81 size_t cursor$; 82 bool nlOnOff$; 83 }; // istrstream 84 85 // Satisfies basic_istream 86 87 // public 88 bool getANL( istrstream & ); 89 void nlOn( istrstream & ); 90 void nlOff( istrstream & ); 91 void ends( istrstream & ); 92 int fmt( istrstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) )); 93 istrstream & ungetc( istrstream & is, char c ); 94 int eof( istrstream & is ); 95 96 void ?{}( istrstream & is, char buf[] ); 77 97 78 98 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.