Skip to content

Commit e983a65

Browse files
committed
[libc++][NFC] split <charconv>.
This move the helper types `chars_format`, `to_chars_result` and `from_chars_result` to a separate header. The first two are needed for D70631 the third for consistency. The header `__charconv/ryu.h` uses these types and it can't depend on the types in `<charconv>` in a modular build. Moving them to the ryu header would be an odd place and doesn't work since the header is included in the middle of `<charconv>`. Reviewed By: #libc, ldionne, Quuxplusone Differential Revision: https://reviews.llvm.org/D108927
1 parent b604fcb commit e983a65

File tree

9 files changed

+206
-62
lines changed

9 files changed

+206
-62
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ set(files
9797
__bits
9898
__bsd_locale_defaults.h
9999
__bsd_locale_fallbacks.h
100+
__charconv/chars_format.h
101+
__charconv/from_chars_result.h
102+
__charconv/to_chars_result.h
100103
__compare/common_comparison_category.h
101104
__compare/compare_three_way_result.h
102105
__compare/ordering.h
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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___CHARCONV_CHARS_FORMAT_H
11+
#define _LIBCPP___CHARCONV_CHARS_FORMAT_H
12+
13+
#include <__config>
14+
#include <__utility/to_underlying.h>
15+
16+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17+
#pragma GCC system_header
18+
#endif
19+
20+
_LIBCPP_BEGIN_NAMESPACE_STD
21+
22+
#ifndef _LIBCPP_CXX03_LANG
23+
24+
enum class _LIBCPP_ENUM_VIS chars_format
25+
{
26+
scientific = 0x1,
27+
fixed = 0x2,
28+
hex = 0x4,
29+
general = fixed | scientific
30+
};
31+
32+
inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
33+
operator~(chars_format __x) {
34+
return chars_format(~_VSTD::__to_underlying(__x));
35+
}
36+
37+
inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
38+
operator&(chars_format __x, chars_format __y) {
39+
return chars_format(_VSTD::__to_underlying(__x) &
40+
_VSTD::__to_underlying(__y));
41+
}
42+
43+
inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
44+
operator|(chars_format __x, chars_format __y) {
45+
return chars_format(_VSTD::__to_underlying(__x) |
46+
_VSTD::__to_underlying(__y));
47+
}
48+
49+
inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
50+
operator^(chars_format __x, chars_format __y) {
51+
return chars_format(_VSTD::__to_underlying(__x) ^
52+
_VSTD::__to_underlying(__y));
53+
}
54+
55+
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
56+
operator&=(chars_format& __x, chars_format __y) {
57+
__x = __x & __y;
58+
return __x;
59+
}
60+
61+
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
62+
operator|=(chars_format& __x, chars_format __y) {
63+
__x = __x | __y;
64+
return __x;
65+
}
66+
67+
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
68+
operator^=(chars_format& __x, chars_format __y) {
69+
__x = __x ^ __y;
70+
return __x;
71+
}
72+
73+
#endif // _LIBCPP_CXX03_LANG
74+
75+
_LIBCPP_END_NAMESPACE_STD
76+
77+
#endif // _LIBCPP___CHARCONV_CHARS_FORMAT_H
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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___CHARCONV_FROM_CHARS_RESULT_H
11+
#define _LIBCPP___CHARCONV_FROM_CHARS_RESULT_H
12+
13+
#include <__config>
14+
#include <__errc>
15+
16+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17+
#pragma GCC system_header
18+
#endif
19+
20+
_LIBCPP_BEGIN_NAMESPACE_STD
21+
22+
#ifndef _LIBCPP_CXX03_LANG
23+
24+
struct _LIBCPP_TYPE_VIS from_chars_result
25+
{
26+
const char* ptr;
27+
errc ec;
28+
};
29+
30+
#endif // _LIBCPP_CXX03_LANG
31+
32+
_LIBCPP_END_NAMESPACE_STD
33+
34+
#endif // _LIBCPP___CHARCONV_FROM_CHARS_RESULT_H
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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___CHARCONV_TO_CHARS_RESULT_H
11+
#define _LIBCPP___CHARCONV_TO_CHARS_RESULT_H
12+
13+
#include <__config>
14+
#include <__errc>
15+
16+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17+
#pragma GCC system_header
18+
#endif
19+
20+
_LIBCPP_BEGIN_NAMESPACE_STD
21+
22+
#ifndef _LIBCPP_CXX03_LANG
23+
24+
struct _LIBCPP_TYPE_VIS to_chars_result
25+
{
26+
char* ptr;
27+
errc ec;
28+
};
29+
30+
#endif // _LIBCPP_CXX03_LANG
31+
32+
_LIBCPP_END_NAMESPACE_STD
33+
34+
#endif // _LIBCPP___CHARCONV_TO_CHARS_RESULT_H

libcxx/include/charconv

Lines changed: 3 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ namespace std {
7575

7676
#include <__availability>
7777
#include <__bits>
78+
#include <__charconv/chars_format.h>
79+
#include <__charconv/from_chars_result.h>
80+
#include <__charconv/to_chars_result.h>
7881
#include <__config>
7982
#include <__errc>
80-
#include <__utility/to_underlying.h>
8183
#include <cmath> // for log2f
8284
#include <cstdint>
8385
#include <cstdlib> // for _LIBCPP_UNREACHABLE
@@ -103,67 +105,6 @@ _LIBCPP_AVAILABILITY_TO_CHARS _LIBCPP_FUNC_VIS char* __u32toa(uint32_t __value,
103105

104106
#ifndef _LIBCPP_CXX03_LANG
105107

106-
enum class _LIBCPP_ENUM_VIS chars_format
107-
{
108-
scientific = 0x1,
109-
fixed = 0x2,
110-
hex = 0x4,
111-
general = fixed | scientific
112-
};
113-
114-
inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
115-
operator~(chars_format __x) {
116-
return chars_format(~_VSTD::__to_underlying(__x));
117-
}
118-
119-
inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
120-
operator&(chars_format __x, chars_format __y) {
121-
return chars_format(_VSTD::__to_underlying(__x) &
122-
_VSTD::__to_underlying(__y));
123-
}
124-
125-
inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
126-
operator|(chars_format __x, chars_format __y) {
127-
return chars_format(_VSTD::__to_underlying(__x) |
128-
_VSTD::__to_underlying(__y));
129-
}
130-
131-
inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
132-
operator^(chars_format __x, chars_format __y) {
133-
return chars_format(_VSTD::__to_underlying(__x) ^
134-
_VSTD::__to_underlying(__y));
135-
}
136-
137-
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
138-
operator&=(chars_format& __x, chars_format __y) {
139-
__x = __x & __y;
140-
return __x;
141-
}
142-
143-
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
144-
operator|=(chars_format& __x, chars_format __y) {
145-
__x = __x | __y;
146-
return __x;
147-
}
148-
149-
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
150-
operator^=(chars_format& __x, chars_format __y) {
151-
__x = __x ^ __y;
152-
return __x;
153-
}
154-
155-
struct _LIBCPP_TYPE_VIS to_chars_result
156-
{
157-
char* ptr;
158-
errc ec;
159-
};
160-
161-
struct _LIBCPP_TYPE_VIS from_chars_result
162-
{
163-
const char* ptr;
164-
errc ec;
165-
};
166-
167108
void to_chars(char*, char*, bool, int = 10) = delete;
168109
void from_chars(const char*, const char*, bool, int = 10) = delete;
169110

libcxx/include/module.modulemap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,13 @@ module std [system] {
346346
module charconv {
347347
header "charconv"
348348
export *
349+
350+
module __charconv {
351+
module chars_format { private header "__charconv/chars_format.h" }
352+
module from_chars_result { private header "__charconv/from_chars_result.h" }
353+
module to_chars_result { private header "__charconv/to_chars_result.h" }
354+
}
355+
349356
}
350357
module chrono {
351358
header "chrono"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
// REQUIRES: modules-build
11+
12+
// WARNING: This test was generated by 'generate_private_header_tests.py'
13+
// and should not be edited manually.
14+
15+
// expected-error@*:* {{use of private header from outside its module: '__charconv/chars_format.h'}}
16+
#include <__charconv/chars_format.h>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
// REQUIRES: modules-build
11+
12+
// WARNING: This test was generated by 'generate_private_header_tests.py'
13+
// and should not be edited manually.
14+
15+
// expected-error@*:* {{use of private header from outside its module: '__charconv/from_chars_result.h'}}
16+
#include <__charconv/from_chars_result.h>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
// REQUIRES: modules-build
11+
12+
// WARNING: This test was generated by 'generate_private_header_tests.py'
13+
// and should not be edited manually.
14+
15+
// expected-error@*:* {{use of private header from outside its module: '__charconv/to_chars_result.h'}}
16+
#include <__charconv/to_chars_result.h>

0 commit comments

Comments
 (0)