libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

iostream.cpp (5379B)


      1 //===------------------------ iostream.cpp --------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 #include "__std_stream"
     11 #include "string"
     12 #include "new"
     13 
     14 #define _str(s) #s
     15 #define str(s) _str(s)
     16 #define _LIBCPP_ABI_NAMESPACE_STR str(_LIBCPP_ABI_NAMESPACE)
     17 
     18 _LIBCPP_BEGIN_NAMESPACE_STD
     19 
     20 #ifndef _LIBCPP_HAS_NO_STDIN
     21 _ALIGNAS_TYPE (istream) _LIBCPP_FUNC_VIS char cin[sizeof(istream)]
     22 #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
     23 __asm__("?cin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
     24 #endif
     25 ;
     26 _ALIGNAS_TYPE (__stdinbuf<char> ) static char __cin[sizeof(__stdinbuf <char>)];
     27 static mbstate_t mb_cin;
     28 _ALIGNAS_TYPE (wistream) _LIBCPP_FUNC_VIS char wcin[sizeof(wistream)]
     29 #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
     30 __asm__("?wcin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
     31 #endif
     32 ;
     33 _ALIGNAS_TYPE (__stdinbuf<wchar_t> ) static char __wcin[sizeof(__stdinbuf <wchar_t>)];
     34 static mbstate_t mb_wcin;
     35 #endif
     36 
     37 #ifndef _LIBCPP_HAS_NO_STDOUT
     38 _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cout[sizeof(ostream)]
     39 #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
     40 __asm__("?cout@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
     41 #endif
     42 ;
     43 _ALIGNAS_TYPE (__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)];
     44 static mbstate_t mb_cout;
     45 _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcout[sizeof(wostream)]
     46 #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
     47 __asm__("?wcout@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
     48 #endif
     49 ;
     50 _ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)];
     51 static mbstate_t mb_wcout;
     52 #endif
     53 
     54 _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cerr[sizeof(ostream)]
     55 #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
     56 __asm__("?cerr@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
     57 #endif
     58 ;
     59 _ALIGNAS_TYPE (__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)];
     60 static mbstate_t mb_cerr;
     61 _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcerr[sizeof(wostream)]
     62 #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
     63 __asm__("?wcerr@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
     64 #endif
     65 ;
     66 _ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)];
     67 static mbstate_t mb_wcerr;
     68 
     69 _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char clog[sizeof(ostream)]
     70 #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
     71 __asm__("?clog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
     72 #endif
     73 ;
     74 _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wclog[sizeof(wostream)]
     75 #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
     76 __asm__("?wclog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
     77 #endif
     78 ;
     79 
     80 _LIBCPP_HIDDEN ios_base::Init __start_std_streams;
     81 
     82 ios_base::Init::Init()
     83 {
     84 #ifndef _LIBCPP_HAS_NO_STDIN
     85     istream* cin_ptr  = ::new(cin)  istream(::new(__cin)  __stdinbuf <char>(stdin, &mb_cin));
     86 #ifdef _LIBCPP_SUPPORT_WCHAR
     87     wistream* wcin_ptr  = ::new(wcin)  wistream(::new(__wcin)  __stdinbuf <wchar_t>(stdin, &mb_wcin));
     88 #endif
     89 #endif
     90 #ifndef _LIBCPP_HAS_NO_STDOUT
     91     ostream* cout_ptr = ::new(cout) ostream(::new(__cout) __stdoutbuf<char>(stdout, &mb_cout));
     92 #ifdef _LIBCPP_SUPPORT_WCHAR
     93     wostream* wcout_ptr = ::new(wcout) wostream(::new(__wcout) __stdoutbuf<wchar_t>(stdout, &mb_wcout));
     94 #endif
     95 #endif
     96     ostream* cerr_ptr = ::new(cerr) ostream(::new(__cerr) __stdoutbuf<char>(stderr, &mb_cerr));
     97                         ::new(clog) ostream(cerr_ptr->rdbuf());
     98 #ifdef _LIBCPP_SUPPORT_WCHAR
     99     wostream* wcerr_ptr = ::new(wcerr) wostream(::new(__wcerr) __stdoutbuf<wchar_t>(stderr, &mb_wcerr));
    100                           ::new(wclog) wostream(wcerr_ptr->rdbuf());
    101 #endif
    102 
    103 #if !defined(_LIBCPP_HAS_NO_STDIN) && !defined(_LIBCPP_HAS_NO_STDOUT)
    104     cin_ptr->tie(cout_ptr);
    105 #ifdef _LIBCPP_SUPPORT_WCHAR
    106     wcin_ptr->tie(wcout_ptr);
    107 #endif
    108 #endif
    109     _VSTD::unitbuf(*cerr_ptr);
    110 #ifdef _LIBCPP_SUPPORT_WCHAR
    111     _VSTD::unitbuf(*wcerr_ptr);
    112 #endif
    113 #ifndef _LIBCPP_HAS_NO_STDOUT
    114     cerr_ptr->tie(cout_ptr);
    115 #ifdef _LIBCPP_SUPPORT_WCHAR
    116     wcerr_ptr->tie(wcout_ptr);
    117 #endif
    118 #endif
    119 }
    120 
    121 ios_base::Init::~Init()
    122 {
    123 #ifndef _LIBCPP_HAS_NO_STDOUT
    124     ostream* cout_ptr = reinterpret_cast<ostream*>(cout);
    125 #ifdef _LIBCPP_SUPPORT_WCHAR
    126     wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout);
    127 #endif
    128     cout_ptr->flush();
    129 #ifdef _LIBCPP_SUPPORT_WCHAR
    130     wcout_ptr->flush();
    131 #endif
    132 #endif
    133 
    134     ostream* clog_ptr = reinterpret_cast<ostream*>(clog);
    135 #ifdef _LIBCPP_SUPPORT_WCHAR
    136     wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog);
    137 #endif
    138     clog_ptr->flush();
    139 #ifdef _LIBCPP_SUPPORT_WCHAR
    140     wclog_ptr->flush();
    141 #endif
    142 }
    143 
    144 _LIBCPP_END_NAMESPACE_STD