Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===------------------------ iostream.cpp --------------------------------===// |
| 2 | // |
Howard Hinnant | c566dc3 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | ee11c31 | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "__std_stream" |
| 11 | #include "string" |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 12 | #include "new" |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 13 | |
| 14 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 15 | |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 16 | #ifndef _LIBCPP_HAS_NO_STDIN |
Eric Fiselier | a53c6ea | 2017-01-07 06:09:12 +0000 | [diff] [blame] | 17 | _ALIGNAS_TYPE (istream) _LIBCPP_FUNC_VIS char cin[sizeof(istream)] |
| 18 | #if defined(_MSC_VER) && defined(__clang__) |
| 19 | __asm__("?cin@__1@std@@3V?$basic_istream@DU?$char_traits@D@__1@std@@@12@A") |
| 20 | #endif |
| 21 | ; |
| 22 | _ALIGNAS_TYPE (__stdinbuf<char> ) static char __cin[sizeof(__stdinbuf <char>)]; |
Ed Schouten | 0d354bd | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 23 | static mbstate_t mb_cin; |
Eric Fiselier | a53c6ea | 2017-01-07 06:09:12 +0000 | [diff] [blame] | 24 | _ALIGNAS_TYPE (wistream) _LIBCPP_FUNC_VIS char wcin[sizeof(wistream)] |
| 25 | #if defined(_MSC_VER) && defined(__clang__) |
| 26 | __asm__("?wcin@__1@std@@3V?$basic_istream@_WU?$char_traits@_W@__1@std@@@12@A") |
| 27 | #endif |
| 28 | ; |
| 29 | _ALIGNAS_TYPE (__stdinbuf<wchar_t> ) static char __wcin[sizeof(__stdinbuf <wchar_t>)]; |
Ed Schouten | 0d354bd | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 30 | static mbstate_t mb_wcin; |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 31 | #endif |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 32 | |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 33 | #ifndef _LIBCPP_HAS_NO_STDOUT |
Eric Fiselier | a53c6ea | 2017-01-07 06:09:12 +0000 | [diff] [blame] | 34 | _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cout[sizeof(ostream)] |
| 35 | #if defined(_MSC_VER) && defined(__clang__) |
| 36 | __asm__("?cout@__1@std@@3V?$basic_ostream@DU?$char_traits@D@__1@std@@@12@A") |
| 37 | #endif |
| 38 | ; |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 39 | _ALIGNAS_TYPE (__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)]; |
Ed Schouten | 0d354bd | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 40 | static mbstate_t mb_cout; |
Eric Fiselier | a53c6ea | 2017-01-07 06:09:12 +0000 | [diff] [blame] | 41 | _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcout[sizeof(wostream)] |
| 42 | #if defined(_MSC_VER) && defined(__clang__) |
| 43 | __asm__("?wcout@__1@std@@3V?$basic_ostream@_WU?$char_traits@_W@__1@std@@@12@A") |
| 44 | #endif |
| 45 | ; |
Howard Hinnant | 62cad69 | 2012-05-31 19:31:14 +0000 | [diff] [blame] | 46 | _ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)]; |
Ed Schouten | 0d354bd | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 47 | static mbstate_t mb_wcout; |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 48 | #endif |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 49 | |
Eric Fiselier | a53c6ea | 2017-01-07 06:09:12 +0000 | [diff] [blame] | 50 | _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cerr[sizeof(ostream)] |
| 51 | #if defined(_MSC_VER) && defined(__clang__) |
| 52 | __asm__("?cerr@__1@std@@3V?$basic_ostream@DU?$char_traits@D@__1@std@@@12@A") |
| 53 | #endif |
| 54 | ; |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 55 | _ALIGNAS_TYPE (__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)]; |
Ed Schouten | 0d354bd | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 56 | static mbstate_t mb_cerr; |
Eric Fiselier | a53c6ea | 2017-01-07 06:09:12 +0000 | [diff] [blame] | 57 | _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcerr[sizeof(wostream)] |
| 58 | #if defined(_MSC_VER) && defined(__clang__) |
| 59 | __asm__("?wcerr@__1@std@@3V?$basic_ostream@_WU?$char_traits@_W@__1@std@@@12@A") |
| 60 | #endif |
| 61 | ; |
Howard Hinnant | 62cad69 | 2012-05-31 19:31:14 +0000 | [diff] [blame] | 62 | _ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)]; |
Ed Schouten | 0d354bd | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 63 | static mbstate_t mb_wcerr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 64 | |
Eric Fiselier | a53c6ea | 2017-01-07 06:09:12 +0000 | [diff] [blame] | 65 | _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char clog[sizeof(ostream)] |
| 66 | #if defined(_MSC_VER) && defined(__clang__) |
| 67 | __asm__("?clog@__1@std@@3V?$basic_ostream@DU?$char_traits@D@__1@std@@@12@A") |
| 68 | #endif |
| 69 | ; |
| 70 | _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wclog[sizeof(wostream)] |
| 71 | #if defined(_MSC_VER) && defined(__clang__) |
| 72 | __asm__("?wclog@__1@std@@3V?$basic_ostream@_WU?$char_traits@_W@__1@std@@@12@A") |
| 73 | #endif |
| 74 | ; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 75 | |
| 76 | ios_base::Init __start_std_streams; |
| 77 | |
| 78 | ios_base::Init::Init() |
| 79 | { |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 80 | #ifndef _LIBCPP_HAS_NO_STDIN |
Ed Schouten | 0d354bd | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 81 | istream* cin_ptr = ::new(cin) istream(::new(__cin) __stdinbuf <char>(stdin, &mb_cin)); |
| 82 | wistream* wcin_ptr = ::new(wcin) wistream(::new(__wcin) __stdinbuf <wchar_t>(stdin, &mb_wcin)); |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 83 | #endif |
| 84 | #ifndef _LIBCPP_HAS_NO_STDOUT |
Ed Schouten | 0d354bd | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 85 | ostream* cout_ptr = ::new(cout) ostream(::new(__cout) __stdoutbuf<char>(stdout, &mb_cout)); |
| 86 | wostream* wcout_ptr = ::new(wcout) wostream(::new(__wcout) __stdoutbuf<wchar_t>(stdout, &mb_wcout)); |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 87 | #endif |
Ed Schouten | 0d354bd | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 88 | ostream* cerr_ptr = ::new(cerr) ostream(::new(__cerr) __stdoutbuf<char>(stderr, &mb_cerr)); |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 89 | ::new(clog) ostream(cerr_ptr->rdbuf()); |
Ed Schouten | 0d354bd | 2015-03-26 14:33:46 +0000 | [diff] [blame] | 90 | wostream* wcerr_ptr = ::new(wcerr) wostream(::new(__wcerr) __stdoutbuf<wchar_t>(stderr, &mb_wcerr)); |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 91 | ::new(wclog) wostream(wcerr_ptr->rdbuf()); |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 92 | |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 93 | #if !defined(_LIBCPP_HAS_NO_STDIN) && !defined(_LIBCPP_HAS_NO_STDOUT) |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 94 | cin_ptr->tie(cout_ptr); |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 95 | wcin_ptr->tie(wcout_ptr); |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 96 | #endif |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 97 | _VSTD::unitbuf(*cerr_ptr); |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 98 | _VSTD::unitbuf(*wcerr_ptr); |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 99 | #ifndef _LIBCPP_HAS_NO_STDOUT |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 100 | cerr_ptr->tie(cout_ptr); |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 101 | wcerr_ptr->tie(wcout_ptr); |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 102 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | ios_base::Init::~Init() |
| 106 | { |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 107 | #ifndef _LIBCPP_HAS_NO_STDOUT |
Joerg Sonnenberger | b5bfdec | 2013-04-27 19:12:36 +0000 | [diff] [blame] | 108 | ostream* cout_ptr = reinterpret_cast<ostream*>(cout); |
Joerg Sonnenberger | b5bfdec | 2013-04-27 19:12:36 +0000 | [diff] [blame] | 109 | wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout); |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 110 | cout_ptr->flush(); |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 111 | wcout_ptr->flush(); |
Ed Schouten | 3a75c0b | 2015-03-26 14:35:46 +0000 | [diff] [blame] | 112 | #endif |
Ed Schouten | 34f9b54 | 2015-03-17 18:40:58 +0000 | [diff] [blame] | 113 | |
| 114 | ostream* clog_ptr = reinterpret_cast<ostream*>(clog); |
| 115 | wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog); |
| 116 | clog_ptr->flush(); |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 117 | wclog_ptr->flush(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | _LIBCPP_END_NAMESPACE_STD |