Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===------------------------ iostream.cpp --------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "__std_stream" |
| 11 | #include "string" |
Howard Hinnant | 1378397 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 12 | #include "new" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 13 | |
Shoaib Meenai | 98086a8 | 2017-08-07 19:59:58 +0000 | [diff] [blame] | 14 | #define _str(s) #s |
| 15 | #define str(s) _str(s) |
| 16 | #define _LIBCPP_NAMESPACE_STR str(_LIBCPP_NAMESPACE) |
| 17 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 18 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 19 | |
Ed Schouten | abd06b4 | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 20 | #ifndef _LIBCPP_HAS_NO_STDIN |
Eric Fiselier | 4d15e8a | 2017-01-07 06:09:12 +0000 | [diff] [blame] | 21 | _ALIGNAS_TYPE (istream) _LIBCPP_FUNC_VIS char cin[sizeof(istream)] |
Shoaib Meenai | 2d282d7 | 2017-04-19 20:11:04 +0000 | [diff] [blame] | 22 | #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__) |
Shoaib Meenai | 98086a8 | 2017-08-07 19:59:58 +0000 | [diff] [blame] | 23 | __asm__("?cin@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_istream@DU?$char_traits@D@" _LIBCPP_NAMESPACE_STR "@std@@@12@A") |
Eric Fiselier | 4d15e8a | 2017-01-07 06:09:12 +0000 | [diff] [blame] | 24 | #endif |
| 25 | ; |
| 26 | _ALIGNAS_TYPE (__stdinbuf<char> ) static char __cin[sizeof(__stdinbuf <char>)]; |
Ed Schouten | 43dbeea | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 27 | static mbstate_t mb_cin; |
Eric Fiselier | 4d15e8a | 2017-01-07 06:09:12 +0000 | [diff] [blame] | 28 | _ALIGNAS_TYPE (wistream) _LIBCPP_FUNC_VIS char wcin[sizeof(wistream)] |
Shoaib Meenai | 2d282d7 | 2017-04-19 20:11:04 +0000 | [diff] [blame] | 29 | #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__) |
Shoaib Meenai | 98086a8 | 2017-08-07 19:59:58 +0000 | [diff] [blame] | 30 | __asm__("?wcin@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_istream@_WU?$char_traits@_W@" _LIBCPP_NAMESPACE_STR "@std@@@12@A") |
Eric Fiselier | 4d15e8a | 2017-01-07 06:09:12 +0000 | [diff] [blame] | 31 | #endif |
| 32 | ; |
| 33 | _ALIGNAS_TYPE (__stdinbuf<wchar_t> ) static char __wcin[sizeof(__stdinbuf <wchar_t>)]; |
Ed Schouten | 43dbeea | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 34 | static mbstate_t mb_wcin; |
Ed Schouten | abd06b4 | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 35 | #endif |
Ed Schouten | 62a06f9 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 36 | |
Ed Schouten | abd06b4 | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 37 | #ifndef _LIBCPP_HAS_NO_STDOUT |
Eric Fiselier | 4d15e8a | 2017-01-07 06:09:12 +0000 | [diff] [blame] | 38 | _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cout[sizeof(ostream)] |
Shoaib Meenai | 2d282d7 | 2017-04-19 20:11:04 +0000 | [diff] [blame] | 39 | #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__) |
Shoaib Meenai | 98086a8 | 2017-08-07 19:59:58 +0000 | [diff] [blame] | 40 | __asm__("?cout@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_NAMESPACE_STR "@std@@@12@A") |
Eric Fiselier | 4d15e8a | 2017-01-07 06:09:12 +0000 | [diff] [blame] | 41 | #endif |
| 42 | ; |
Ed Schouten | 62a06f9 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 43 | _ALIGNAS_TYPE (__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)]; |
Ed Schouten | 43dbeea | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 44 | static mbstate_t mb_cout; |
Eric Fiselier | 4d15e8a | 2017-01-07 06:09:12 +0000 | [diff] [blame] | 45 | _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcout[sizeof(wostream)] |
Shoaib Meenai | 2d282d7 | 2017-04-19 20:11:04 +0000 | [diff] [blame] | 46 | #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__) |
Shoaib Meenai | 98086a8 | 2017-08-07 19:59:58 +0000 | [diff] [blame] | 47 | __asm__("?wcout@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_NAMESPACE_STR "@std@@@12@A") |
Eric Fiselier | 4d15e8a | 2017-01-07 06:09:12 +0000 | [diff] [blame] | 48 | #endif |
| 49 | ; |
Howard Hinnant | cbdd089 | 2012-05-31 19:31:14 +0000 | [diff] [blame] | 50 | _ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)]; |
Ed Schouten | 43dbeea | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 51 | static mbstate_t mb_wcout; |
Ed Schouten | abd06b4 | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 52 | #endif |
Ed Schouten | 62a06f9 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 53 | |
Eric Fiselier | 4d15e8a | 2017-01-07 06:09:12 +0000 | [diff] [blame] | 54 | _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cerr[sizeof(ostream)] |
Shoaib Meenai | 2d282d7 | 2017-04-19 20:11:04 +0000 | [diff] [blame] | 55 | #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__) |
Shoaib Meenai | 98086a8 | 2017-08-07 19:59:58 +0000 | [diff] [blame] | 56 | __asm__("?cerr@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_NAMESPACE_STR "@std@@@12@A") |
Eric Fiselier | 4d15e8a | 2017-01-07 06:09:12 +0000 | [diff] [blame] | 57 | #endif |
| 58 | ; |
Ed Schouten | 62a06f9 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 59 | _ALIGNAS_TYPE (__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)]; |
Ed Schouten | 43dbeea | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 60 | static mbstate_t mb_cerr; |
Eric Fiselier | 4d15e8a | 2017-01-07 06:09:12 +0000 | [diff] [blame] | 61 | _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcerr[sizeof(wostream)] |
Shoaib Meenai | 2d282d7 | 2017-04-19 20:11:04 +0000 | [diff] [blame] | 62 | #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__) |
Shoaib Meenai | 98086a8 | 2017-08-07 19:59:58 +0000 | [diff] [blame] | 63 | __asm__("?wcerr@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_NAMESPACE_STR "@std@@@12@A") |
Eric Fiselier | 4d15e8a | 2017-01-07 06:09:12 +0000 | [diff] [blame] | 64 | #endif |
| 65 | ; |
Howard Hinnant | cbdd089 | 2012-05-31 19:31:14 +0000 | [diff] [blame] | 66 | _ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)]; |
Ed Schouten | 43dbeea | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 67 | static mbstate_t mb_wcerr; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 68 | |
Eric Fiselier | 4d15e8a | 2017-01-07 06:09:12 +0000 | [diff] [blame] | 69 | _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char clog[sizeof(ostream)] |
Shoaib Meenai | 2d282d7 | 2017-04-19 20:11:04 +0000 | [diff] [blame] | 70 | #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__) |
Shoaib Meenai | 98086a8 | 2017-08-07 19:59:58 +0000 | [diff] [blame] | 71 | __asm__("?clog@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_NAMESPACE_STR "@std@@@12@A") |
Eric Fiselier | 4d15e8a | 2017-01-07 06:09:12 +0000 | [diff] [blame] | 72 | #endif |
| 73 | ; |
| 74 | _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wclog[sizeof(wostream)] |
Shoaib Meenai | 2d282d7 | 2017-04-19 20:11:04 +0000 | [diff] [blame] | 75 | #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__) |
Shoaib Meenai | 98086a8 | 2017-08-07 19:59:58 +0000 | [diff] [blame] | 76 | __asm__("?wclog@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_NAMESPACE_STR "@std@@@12@A") |
Eric Fiselier | 4d15e8a | 2017-01-07 06:09:12 +0000 | [diff] [blame] | 77 | #endif |
| 78 | ; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 79 | |
| 80 | ios_base::Init __start_std_streams; |
| 81 | |
| 82 | ios_base::Init::Init() |
| 83 | { |
Ed Schouten | abd06b4 | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 84 | #ifndef _LIBCPP_HAS_NO_STDIN |
Ed Schouten | 43dbeea | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 85 | istream* cin_ptr = ::new(cin) istream(::new(__cin) __stdinbuf <char>(stdin, &mb_cin)); |
| 86 | wistream* wcin_ptr = ::new(wcin) wistream(::new(__wcin) __stdinbuf <wchar_t>(stdin, &mb_wcin)); |
Ed Schouten | abd06b4 | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 87 | #endif |
| 88 | #ifndef _LIBCPP_HAS_NO_STDOUT |
Ed Schouten | 43dbeea | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 89 | ostream* cout_ptr = ::new(cout) ostream(::new(__cout) __stdoutbuf<char>(stdout, &mb_cout)); |
| 90 | wostream* wcout_ptr = ::new(wcout) wostream(::new(__wcout) __stdoutbuf<wchar_t>(stdout, &mb_wcout)); |
Ed Schouten | abd06b4 | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 91 | #endif |
Ed Schouten | 43dbeea | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 92 | ostream* cerr_ptr = ::new(cerr) ostream(::new(__cerr) __stdoutbuf<char>(stderr, &mb_cerr)); |
Howard Hinnant | 1378397 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 93 | ::new(clog) ostream(cerr_ptr->rdbuf()); |
Ed Schouten | 43dbeea | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 94 | wostream* wcerr_ptr = ::new(wcerr) wostream(::new(__wcerr) __stdoutbuf<wchar_t>(stderr, &mb_wcerr)); |
Howard Hinnant | 1378397 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 95 | ::new(wclog) wostream(wcerr_ptr->rdbuf()); |
Ed Schouten | 62a06f9 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 96 | |
Ed Schouten | abd06b4 | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 97 | #if !defined(_LIBCPP_HAS_NO_STDIN) && !defined(_LIBCPP_HAS_NO_STDOUT) |
Ed Schouten | 62a06f9 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 98 | cin_ptr->tie(cout_ptr); |
Howard Hinnant | 1378397 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 99 | wcin_ptr->tie(wcout_ptr); |
Ed Schouten | abd06b4 | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 100 | #endif |
Ed Schouten | 62a06f9 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 101 | _VSTD::unitbuf(*cerr_ptr); |
Howard Hinnant | 1378397 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 102 | _VSTD::unitbuf(*wcerr_ptr); |
Ed Schouten | abd06b4 | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 103 | #ifndef _LIBCPP_HAS_NO_STDOUT |
Ed Schouten | 62a06f9 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 104 | cerr_ptr->tie(cout_ptr); |
Howard Hinnant | 1378397 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 105 | wcerr_ptr->tie(wcout_ptr); |
Ed Schouten | abd06b4 | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 106 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | ios_base::Init::~Init() |
| 110 | { |
Ed Schouten | abd06b4 | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 111 | #ifndef _LIBCPP_HAS_NO_STDOUT |
Joerg Sonnenberger | d3b5b6b | 2013-04-27 19:12:36 +0000 | [diff] [blame] | 112 | ostream* cout_ptr = reinterpret_cast<ostream*>(cout); |
Joerg Sonnenberger | d3b5b6b | 2013-04-27 19:12:36 +0000 | [diff] [blame] | 113 | wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout); |
Ed Schouten | 62a06f9 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 114 | cout_ptr->flush(); |
Howard Hinnant | 1378397 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 115 | wcout_ptr->flush(); |
Ed Schouten | abd06b4 | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 116 | #endif |
Ed Schouten | 62a06f9 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 117 | |
| 118 | ostream* clog_ptr = reinterpret_cast<ostream*>(clog); |
| 119 | wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog); |
| 120 | clog_ptr->flush(); |
Howard Hinnant | 1378397 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 121 | wclog_ptr->flush(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | _LIBCPP_END_NAMESPACE_STD |