Coverage Report

Created: 2020-02-15 09:57

/Users/buildslave/jenkins/workspace/coverage/llvm-project/libcxx/include/__std_stream
Line
Count
Source (jump to first uncovered line)
1
// -*- C++ -*-
2
//===----------------------------------------------------------------------===//
3
//
4
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5
// See https://llvm.org/LICENSE.txt for license information.
6
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7
//
8
//===----------------------------------------------------------------------===//
9
10
#ifndef _LIBCPP___STD_STREAM
11
#define _LIBCPP___STD_STREAM
12
13
#include <__config>
14
#include <ostream>
15
#include <istream>
16
#include <__locale>
17
#include <cstdio>
18
19
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20
#pragma GCC system_header
21
#endif
22
23
_LIBCPP_PUSH_MACROS
24
#include <__undef_macros>
25
26
27
_LIBCPP_BEGIN_NAMESPACE_STD
28
29
static const int __limit = 8;
30
31
// __stdinbuf
32
33
template <class _CharT>
34
class _LIBCPP_HIDDEN __stdinbuf
35
    : public basic_streambuf<_CharT, char_traits<_CharT> >
36
{
37
public:
38
    typedef _CharT                           char_type;
39
    typedef char_traits<char_type>           traits_type;
40
    typedef typename traits_type::int_type   int_type;
41
    typedef typename traits_type::pos_type   pos_type;
42
    typedef typename traits_type::off_type   off_type;
43
    typedef typename traits_type::state_type state_type;
44
45
    __stdinbuf(FILE* __fp, state_type* __st);
46
47
protected:
48
    virtual int_type underflow();
49
    virtual int_type uflow();
50
    virtual int_type pbackfail(int_type __c = traits_type::eof());
51
    virtual void imbue(const locale& __loc);
52
53
private:
54
55
    FILE* __file_;
56
    const codecvt<char_type, char, state_type>* __cv_;
57
    state_type* __st_;
58
    int __encoding_;
59
    int_type __last_consumed_;
60
    bool __last_consumed_is_next_;
61
    bool __always_noconv_;
62
63
    __stdinbuf(const __stdinbuf&);
64
    __stdinbuf& operator=(const __stdinbuf&);
65
66
    int_type __getchar(bool __consume);
67
};
68
69
template <class _CharT>
70
__stdinbuf<_CharT>::__stdinbuf(FILE* __fp, state_type* __st)
71
    : __file_(__fp),
72
      __st_(__st),
73
      __last_consumed_(traits_type::eof()),
74
      __last_consumed_is_next_(false)
75
10.0k
{
76
10.0k
    imbue(this->getloc());
77
10.0k
}
std::__1::__stdinbuf<char>::__stdinbuf(__sFILE*, __mbstate_t*)
Line
Count
Source
75
5.00k
{
76
5.00k
    imbue(this->getloc());
77
5.00k
}
std::__1::__stdinbuf<wchar_t>::__stdinbuf(__sFILE*, __mbstate_t*)
Line
Count
Source
75
5.00k
{
76
5.00k
    imbue(this->getloc());
77
5.00k
}
78
79
template <class _CharT>
80
void
81
__stdinbuf<_CharT>::imbue(const locale& __loc)
82
10.0k
{
83
10.0k
    __cv_ = &use_facet<codecvt<char_type, char, state_type> >(__loc);
84
10.0k
    __encoding_ = __cv_->encoding();
85
10.0k
    __always_noconv_ = __cv_->always_noconv();
86
10.0k
    if (__encoding_ > __limit)
87
0
        __throw_runtime_error("unsupported locale for standard input");
88
10.0k
}
std::__1::__stdinbuf<char>::imbue(std::__1::locale const&)
Line
Count
Source
82
5.00k
{
83
5.00k
    __cv_ = &use_facet<codecvt<char_type, char, state_type> >(__loc);
84
5.00k
    __encoding_ = __cv_->encoding();
85
5.00k
    __always_noconv_ = __cv_->always_noconv();
86
5.00k
    if (__encoding_ > __limit)
87
0
        __throw_runtime_error("unsupported locale for standard input");
88
5.00k
}
std::__1::__stdinbuf<wchar_t>::imbue(std::__1::locale const&)
Line
Count
Source
82
5.00k
{
83
5.00k
    __cv_ = &use_facet<codecvt<char_type, char, state_type> >(__loc);
84
5.00k
    __encoding_ = __cv_->encoding();
85
5.00k
    __always_noconv_ = __cv_->always_noconv();
86
5.00k
    if (__encoding_ > __limit)
87
0
        __throw_runtime_error("unsupported locale for standard input");
88
5.00k
}
89
90
template <class _CharT>
91
typename __stdinbuf<_CharT>::int_type
92
__stdinbuf<_CharT>::underflow()
93
0
{
94
0
    return __getchar(false);
95
0
}
Unexecuted instantiation: std::__1::__stdinbuf<char>::underflow()
Unexecuted instantiation: std::__1::__stdinbuf<wchar_t>::underflow()
96
97
template <class _CharT>
98
typename __stdinbuf<_CharT>::int_type
99
__stdinbuf<_CharT>::uflow()
100
0
{
101
0
    return __getchar(true);
102
0
}
Unexecuted instantiation: std::__1::__stdinbuf<char>::uflow()
Unexecuted instantiation: std::__1::__stdinbuf<wchar_t>::uflow()
103
104
template <class _CharT>
105
typename __stdinbuf<_CharT>::int_type
106
__stdinbuf<_CharT>::__getchar(bool __consume)
107
0
{
108
0
    if (__last_consumed_is_next_)
109
0
    {
110
0
        int_type __result = __last_consumed_;
111
0
        if (__consume)
112
0
        {
113
0
            __last_consumed_ = traits_type::eof();
114
0
            __last_consumed_is_next_ = false;
115
0
        }
116
0
        return __result;
117
0
    }
118
0
    char __extbuf[__limit];
119
0
    int __nread = _VSTD::max(1, __encoding_);
120
0
    for (int __i = 0; __i < __nread; ++__i)
121
0
    {
122
0
        int __c = getc(__file_);
123
0
        if (__c == EOF)
124
0
            return traits_type::eof();
125
0
        __extbuf[__i] = static_cast<char>(__c);
126
0
    }
127
0
    char_type __1buf;
128
0
    if (__always_noconv_)
129
0
        __1buf = static_cast<char_type>(__extbuf[0]);
130
0
    else
131
0
    {
132
0
        const char* __enxt;
133
0
        char_type* __inxt;
134
0
        codecvt_base::result __r;
135
0
        do
136
0
        {
137
0
            state_type __sv_st = *__st_;
138
0
            __r = __cv_->in(*__st_, __extbuf, __extbuf + __nread, __enxt,
139
0
                                   &__1buf, &__1buf + 1, __inxt);
140
0
            switch (__r)
141
0
            {
142
0
            case _VSTD::codecvt_base::ok:
143
0
                break;
144
0
            case codecvt_base::partial:
145
0
                *__st_ = __sv_st;
146
0
                if (__nread == sizeof(__extbuf))
147
0
                    return traits_type::eof();
148
0
                {
149
0
                    int __c = getc(__file_);
150
0
                    if (__c == EOF)
151
0
                        return traits_type::eof();
152
0
                    __extbuf[__nread] = static_cast<char>(__c);
153
0
                }
154
0
                ++__nread;
155
0
                break;
156
0
            case codecvt_base::error:
157
0
                return traits_type::eof();
158
0
            case _VSTD::codecvt_base::noconv:
159
0
                __1buf = static_cast<char_type>(__extbuf[0]);
160
0
                break;
161
0
            }
162
0
        } while (__r == _VSTD::codecvt_base::partial);
163
0
    }
164
0
    if (!__consume)
165
0
    {
166
0
        for (int __i = __nread; __i > 0;)
167
0
        {
168
0
            if (ungetc(traits_type::to_int_type(__extbuf[--__i]), __file_) == EOF)
169
0
                return traits_type::eof();
170
0
        }
171
0
    }
172
0
    else
173
0
        __last_consumed_ = traits_type::to_int_type(__1buf);
174
0
    return traits_type::to_int_type(__1buf);
175
0
}
Unexecuted instantiation: std::__1::__stdinbuf<char>::__getchar(bool)
Unexecuted instantiation: std::__1::__stdinbuf<wchar_t>::__getchar(bool)
176
177
template <class _CharT>
178
typename __stdinbuf<_CharT>::int_type
179
__stdinbuf<_CharT>::pbackfail(int_type __c)
180
0
{
181
0
    if (traits_type::eq_int_type(__c, traits_type::eof()))
182
0
    {
183
0
        if (!__last_consumed_is_next_)
184
0
        {
185
0
            __c = __last_consumed_;
186
0
            __last_consumed_is_next_ = !traits_type::eq_int_type(__last_consumed_,
187
0
                                                                 traits_type::eof());
188
0
        }
189
0
        return __c;
190
0
    }
191
0
    if (__last_consumed_is_next_)
192
0
    {
193
0
        char __extbuf[__limit];
194
0
        char* __enxt;
195
0
        const char_type __ci = traits_type::to_char_type(__last_consumed_);
196
0
        const char_type* __inxt;
197
0
        switch (__cv_->out(*__st_, &__ci, &__ci + 1, __inxt,
198
0
                                  __extbuf, __extbuf + sizeof(__extbuf), __enxt))
199
0
        {
200
0
        case _VSTD::codecvt_base::ok:
201
0
            break;
202
0
        case _VSTD::codecvt_base::noconv:
203
0
            __extbuf[0] = static_cast<char>(__last_consumed_);
204
0
            __enxt = __extbuf + 1;
205
0
            break;
206
0
        case codecvt_base::partial:
207
0
        case codecvt_base::error:
208
0
            return traits_type::eof();
209
0
        }
210
0
        while (__enxt > __extbuf)
211
0
            if (ungetc(*--__enxt, __file_) == EOF)
212
0
                return traits_type::eof();
213
0
    }
214
0
    __last_consumed_ = __c;
215
0
    __last_consumed_is_next_ = true;
216
0
    return __c;
217
0
}
Unexecuted instantiation: std::__1::__stdinbuf<char>::pbackfail(int)
Unexecuted instantiation: std::__1::__stdinbuf<wchar_t>::pbackfail(int)
218
219
// __stdoutbuf
220
221
template <class _CharT>
222
class _LIBCPP_HIDDEN __stdoutbuf
223
    : public basic_streambuf<_CharT, char_traits<_CharT> >
224
{
225
public:
226
    typedef _CharT                           char_type;
227
    typedef char_traits<char_type>           traits_type;
228
    typedef typename traits_type::int_type   int_type;
229
    typedef typename traits_type::pos_type   pos_type;
230
    typedef typename traits_type::off_type   off_type;
231
    typedef typename traits_type::state_type state_type;
232
233
    __stdoutbuf(FILE* __fp, state_type* __st);
234
235
protected:
236
    virtual int_type overflow (int_type __c = traits_type::eof());
237
    virtual streamsize xsputn(const char_type* __s, streamsize __n);
238
    virtual int sync();
239
    virtual void imbue(const locale& __loc);
240
241
private:
242
    FILE* __file_;
243
    const codecvt<char_type, char, state_type>* __cv_;
244
    state_type* __st_;
245
    bool __always_noconv_;
246
247
    __stdoutbuf(const __stdoutbuf&);
248
    __stdoutbuf& operator=(const __stdoutbuf&);
249
};
250
251
template <class _CharT>
252
__stdoutbuf<_CharT>::__stdoutbuf(FILE* __fp, state_type* __st)
253
    : __file_(__fp),
254
      __cv_(&use_facet<codecvt<char_type, char, state_type> >(this->getloc())),
255
      __st_(__st),
256
      __always_noconv_(__cv_->always_noconv())
257
20.0k
{
258
20.0k
}
std::__1::__stdoutbuf<char>::__stdoutbuf(__sFILE*, __mbstate_t*)
Line
Count
Source
257
10.0k
{
258
10.0k
}
std::__1::__stdoutbuf<wchar_t>::__stdoutbuf(__sFILE*, __mbstate_t*)
Line
Count
Source
257
10.0k
{
258
10.0k
}
259
260
template <class _CharT>
261
typename __stdoutbuf<_CharT>::int_type
262
__stdoutbuf<_CharT>::overflow(int_type __c)
263
0
{
264
0
    char __extbuf[__limit];
265
0
    char_type __1buf;
266
0
    if (!traits_type::eq_int_type(__c, traits_type::eof()))
267
0
    {
268
0
        __1buf = traits_type::to_char_type(__c);
269
0
        if (__always_noconv_)
270
0
        {
271
0
            if (fwrite(&__1buf, sizeof(char_type), 1, __file_) != 1)
272
0
                return traits_type::eof();
273
0
        }
274
0
        else
275
0
        {
276
0
            char* __extbe = __extbuf;
277
0
            codecvt_base::result __r;
278
0
            char_type* pbase = &__1buf;
279
0
            char_type* pptr = pbase + 1;
280
0
            do
281
0
            {
282
0
                const char_type* __e;
283
0
                __r = __cv_->out(*__st_, pbase, pptr, __e,
284
0
                                        __extbuf,
285
0
                                        __extbuf + sizeof(__extbuf),
286
0
                                        __extbe);
287
0
                if (__e == pbase)
288
0
                    return traits_type::eof();
289
0
                if (__r == codecvt_base::noconv)
290
0
                {
291
0
                    if (fwrite(pbase, 1, 1, __file_) != 1)
292
0
                        return traits_type::eof();
293
0
                }
294
0
                else if (__r == codecvt_base::ok || __r == codecvt_base::partial)
295
0
                {
296
0
                    size_t __nmemb = static_cast<size_t>(__extbe - __extbuf);
297
0
                    if (fwrite(__extbuf, 1, __nmemb, __file_) != __nmemb)
298
0
                        return traits_type::eof();
299
0
                    if (__r == codecvt_base::partial)
300
0
                    {
301
0
                        pbase = const_cast<char_type*>(__e);
302
0
                    }
303
0
                }
304
0
                else
305
0
                    return traits_type::eof();
306
0
            } while (__r == codecvt_base::partial);
307
0
        }
308
0
    }
309
0
    return traits_type::not_eof(__c);
310
0
}
Unexecuted instantiation: std::__1::__stdoutbuf<char>::overflow(int)
Unexecuted instantiation: std::__1::__stdoutbuf<wchar_t>::overflow(int)
311
312
template <class _CharT>
313
streamsize
314
__stdoutbuf<_CharT>::xsputn(const char_type* __s, streamsize __n)
315
6
{
316
6
    if (__always_noconv_)
317
6
        return fwrite(__s, sizeof(char_type), __n, __file_);
318
0
    streamsize __i = 0;
319
0
    for (; __i < __n; ++__i, ++__s)
320
0
        if (overflow(traits_type::to_int_type(*__s)) == traits_type::eof())
321
0
            break;
322
0
    return __i;
323
0
}
std::__1::__stdoutbuf<char>::xsputn(char const*, long)
Line
Count
Source
315
6
{
316
6
    if (__always_noconv_)
317
6
        return fwrite(__s, sizeof(char_type), __n, __file_);
318
0
    streamsize __i = 0;
319
0
    for (; __i < __n; ++__i, ++__s)
320
0
        if (overflow(traits_type::to_int_type(*__s)) == traits_type::eof())
321
0
            break;
322
0
    return __i;
323
0
}
Unexecuted instantiation: std::__1::__stdoutbuf<wchar_t>::xsputn(wchar_t const*, long)
324
325
template <class _CharT>
326
int
327
__stdoutbuf<_CharT>::sync()
328
20.0k
{
329
20.0k
    char __extbuf[__limit];
330
20.0k
    codecvt_base::result __r;
331
20.0k
    do
332
20.0k
    {
333
20.0k
        char* __extbe;
334
20.0k
        __r = __cv_->unshift(*__st_, __extbuf,
335
20.0k
                                    __extbuf + sizeof(__extbuf),
336
20.0k
                                    __extbe);
337
20.0k
        size_t __nmemb = static_cast<size_t>(__extbe - __extbuf);
338
20.0k
        if (fwrite(__extbuf, 1, __nmemb, __file_) != __nmemb)
339
0
            return -1;
340
20.0k
    } while (__r == codecvt_base::partial);
341
20.0k
    if (__r == codecvt_base::error)
342
0
        return -1;
343
20.0k
    if (fflush(__file_))
344
0
        return -1;
345
20.0k
    return 0;
346
20.0k
}
std::__1::__stdoutbuf<char>::sync()
Line
Count
Source
328
10.0k
{
329
10.0k
    char __extbuf[__limit];
330
10.0k
    codecvt_base::result __r;
331
10.0k
    do
332
10.0k
    {
333
10.0k
        char* __extbe;
334
10.0k
        __r = __cv_->unshift(*__st_, __extbuf,
335
10.0k
                                    __extbuf + sizeof(__extbuf),
336
10.0k
                                    __extbe);
337
10.0k
        size_t __nmemb = static_cast<size_t>(__extbe - __extbuf);
338
10.0k
        if (fwrite(__extbuf, 1, __nmemb, __file_) != __nmemb)
339
0
            return -1;
340
10.0k
    } while (__r == codecvt_base::partial);
341
10.0k
    if (__r == codecvt_base::error)
342
0
        return -1;
343
10.0k
    if (fflush(__file_))
344
0
        return -1;
345
10.0k
    return 0;
346
10.0k
}
std::__1::__stdoutbuf<wchar_t>::sync()
Line
Count
Source
328
10.0k
{
329
10.0k
    char __extbuf[__limit];
330
10.0k
    codecvt_base::result __r;
331
10.0k
    do
332
10.0k
    {
333
10.0k
        char* __extbe;
334
10.0k
        __r = __cv_->unshift(*__st_, __extbuf,
335
10.0k
                                    __extbuf + sizeof(__extbuf),
336
10.0k
                                    __extbe);
337
10.0k
        size_t __nmemb = static_cast<size_t>(__extbe - __extbuf);
338
10.0k
        if (fwrite(__extbuf, 1, __nmemb, __file_) != __nmemb)
339
0
            return -1;
340
10.0k
    } while (__r == codecvt_base::partial);
341
10.0k
    if (__r == codecvt_base::error)
342
0
        return -1;
343
10.0k
    if (fflush(__file_))
344
0
        return -1;
345
10.0k
    return 0;
346
10.0k
}
347
348
template <class _CharT>
349
void
350
__stdoutbuf<_CharT>::imbue(const locale& __loc)
351
0
{
352
0
    sync();
353
0
    __cv_ = &use_facet<codecvt<char_type, char, state_type> >(__loc);
354
0
    __always_noconv_ = __cv_->always_noconv();
355
0
}
Unexecuted instantiation: std::__1::__stdoutbuf<char>::imbue(std::__1::locale const&)
Unexecuted instantiation: std::__1::__stdoutbuf<wchar_t>::imbue(std::__1::locale const&)
356
357
_LIBCPP_END_NAMESPACE_STD
358
359
_LIBCPP_POP_MACROS
360
361
#endif  // _LIBCPP___STD_STREAM