• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 _LIBCPP_BEGIN_NAMESPACE_STD
15 
16 #ifndef _LIBCPP_HAS_NO_STDIN
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>)];
23 static mbstate_t mb_cin;
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>)];
30 static mbstate_t mb_wcin;
31 #endif
32 
33 #ifndef _LIBCPP_HAS_NO_STDOUT
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 ;
39 _ALIGNAS_TYPE (__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)];
40 static mbstate_t mb_cout;
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 ;
46 _ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)];
47 static mbstate_t mb_wcout;
48 #endif
49 
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 ;
55 _ALIGNAS_TYPE (__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)];
56 static mbstate_t mb_cerr;
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 ;
62 _ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)];
63 static mbstate_t mb_wcerr;
64 
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 ;
75 
76 ios_base::Init __start_std_streams;
77 
Init()78 ios_base::Init::Init()
79 {
80 #ifndef _LIBCPP_HAS_NO_STDIN
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));
83 #endif
84 #ifndef _LIBCPP_HAS_NO_STDOUT
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));
87 #endif
88     ostream* cerr_ptr = ::new(cerr) ostream(::new(__cerr) __stdoutbuf<char>(stderr, &mb_cerr));
89                         ::new(clog) ostream(cerr_ptr->rdbuf());
90     wostream* wcerr_ptr = ::new(wcerr) wostream(::new(__wcerr) __stdoutbuf<wchar_t>(stderr, &mb_wcerr));
91                           ::new(wclog) wostream(wcerr_ptr->rdbuf());
92 
93 #if !defined(_LIBCPP_HAS_NO_STDIN) && !defined(_LIBCPP_HAS_NO_STDOUT)
94     cin_ptr->tie(cout_ptr);
95     wcin_ptr->tie(wcout_ptr);
96 #endif
97     _VSTD::unitbuf(*cerr_ptr);
98     _VSTD::unitbuf(*wcerr_ptr);
99 #ifndef _LIBCPP_HAS_NO_STDOUT
100     cerr_ptr->tie(cout_ptr);
101     wcerr_ptr->tie(wcout_ptr);
102 #endif
103 }
104 
~Init()105 ios_base::Init::~Init()
106 {
107 #ifndef _LIBCPP_HAS_NO_STDOUT
108     ostream* cout_ptr = reinterpret_cast<ostream*>(cout);
109     wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout);
110     cout_ptr->flush();
111     wcout_ptr->flush();
112 #endif
113 
114     ostream* clog_ptr = reinterpret_cast<ostream*>(clog);
115     wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog);
116     clog_ptr->flush();
117     wclog_ptr->flush();
118 }
119 
120 _LIBCPP_END_NAMESPACE_STD
121