[libcxx-commits] [libcxx] e983a65 - [libc++][NFC] split <charconv>.

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Tue Aug 31 09:45:24 PDT 2021


Author: Mark de Wever
Date: 2021-08-31T18:45:19+02:00
New Revision: e983a659e51c0ed2a7e0da770be6b3b4f2efcd05

URL: https://github.com/llvm/llvm-project/commit/e983a659e51c0ed2a7e0da770be6b3b4f2efcd05
DIFF: https://github.com/llvm/llvm-project/commit/e983a659e51c0ed2a7e0da770be6b3b4f2efcd05.diff

LOG: [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

Added: 
    libcxx/include/__charconv/chars_format.h
    libcxx/include/__charconv/from_chars_result.h
    libcxx/include/__charconv/to_chars_result.h
    libcxx/test/libcxx/diagnostics/detail.headers/charconv/chars_format.module.verify.cpp
    libcxx/test/libcxx/diagnostics/detail.headers/charconv/from_chars_result.module.verify.cpp
    libcxx/test/libcxx/diagnostics/detail.headers/charconv/to_chars_result.module.verify.cpp

Modified: 
    libcxx/include/CMakeLists.txt
    libcxx/include/charconv
    libcxx/include/module.modulemap

Removed: 
    


################################################################################
diff  --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 59d557284986a..07faed956dfc6 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -97,6 +97,9 @@ set(files
   __bits
   __bsd_locale_defaults.h
   __bsd_locale_fallbacks.h
+  __charconv/chars_format.h
+  __charconv/from_chars_result.h
+  __charconv/to_chars_result.h
   __compare/common_comparison_category.h
   __compare/compare_three_way_result.h
   __compare/ordering.h

diff  --git a/libcxx/include/__charconv/chars_format.h b/libcxx/include/__charconv/chars_format.h
new file mode 100644
index 0000000000000..22e70b56fb8c5
--- /dev/null
+++ b/libcxx/include/__charconv/chars_format.h
@@ -0,0 +1,77 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___CHARCONV_CHARS_FORMAT_H
+#define _LIBCPP___CHARCONV_CHARS_FORMAT_H
+
+#include <__config>
+#include <__utility/to_underlying.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#ifndef _LIBCPP_CXX03_LANG
+
+enum class _LIBCPP_ENUM_VIS chars_format
+{
+    scientific = 0x1,
+    fixed = 0x2,
+    hex = 0x4,
+    general = fixed | scientific
+};
+
+inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
+operator~(chars_format __x) {
+  return chars_format(~_VSTD::__to_underlying(__x));
+}
+
+inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
+operator&(chars_format __x, chars_format __y) {
+  return chars_format(_VSTD::__to_underlying(__x) &
+                      _VSTD::__to_underlying(__y));
+}
+
+inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
+operator|(chars_format __x, chars_format __y) {
+  return chars_format(_VSTD::__to_underlying(__x) |
+                      _VSTD::__to_underlying(__y));
+}
+
+inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
+operator^(chars_format __x, chars_format __y) {
+  return chars_format(_VSTD::__to_underlying(__x) ^
+                      _VSTD::__to_underlying(__y));
+}
+
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
+operator&=(chars_format& __x, chars_format __y) {
+  __x = __x & __y;
+  return __x;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
+operator|=(chars_format& __x, chars_format __y) {
+  __x = __x | __y;
+  return __x;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
+operator^=(chars_format& __x, chars_format __y) {
+  __x = __x ^ __y;
+  return __x;
+}
+
+#endif // _LIBCPP_CXX03_LANG
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CHARCONV_CHARS_FORMAT_H

diff  --git a/libcxx/include/__charconv/from_chars_result.h b/libcxx/include/__charconv/from_chars_result.h
new file mode 100644
index 0000000000000..6d289ba79fd5a
--- /dev/null
+++ b/libcxx/include/__charconv/from_chars_result.h
@@ -0,0 +1,34 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___CHARCONV_FROM_CHARS_RESULT_H
+#define _LIBCPP___CHARCONV_FROM_CHARS_RESULT_H
+
+#include <__config>
+#include <__errc>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#ifndef _LIBCPP_CXX03_LANG
+
+struct _LIBCPP_TYPE_VIS from_chars_result
+{
+    const char* ptr;
+    errc ec;
+};
+
+#endif // _LIBCPP_CXX03_LANG
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CHARCONV_FROM_CHARS_RESULT_H

diff  --git a/libcxx/include/__charconv/to_chars_result.h b/libcxx/include/__charconv/to_chars_result.h
new file mode 100644
index 0000000000000..b610a6adcfb42
--- /dev/null
+++ b/libcxx/include/__charconv/to_chars_result.h
@@ -0,0 +1,34 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___CHARCONV_TO_CHARS_RESULT_H
+#define _LIBCPP___CHARCONV_TO_CHARS_RESULT_H
+
+#include <__config>
+#include <__errc>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#ifndef _LIBCPP_CXX03_LANG
+
+struct _LIBCPP_TYPE_VIS to_chars_result
+{
+    char* ptr;
+    errc ec;
+};
+
+#endif // _LIBCPP_CXX03_LANG
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___CHARCONV_TO_CHARS_RESULT_H

diff  --git a/libcxx/include/charconv b/libcxx/include/charconv
index b4ac71064fd1e..2fdab7f007c82 100644
--- a/libcxx/include/charconv
+++ b/libcxx/include/charconv
@@ -75,9 +75,11 @@ namespace std {
 
 #include <__availability>
 #include <__bits>
+#include <__charconv/chars_format.h>
+#include <__charconv/from_chars_result.h>
+#include <__charconv/to_chars_result.h>
 #include <__config>
 #include <__errc>
-#include <__utility/to_underlying.h>
 #include <cmath> // for log2f
 #include <cstdint>
 #include <cstdlib> // for _LIBCPP_UNREACHABLE
@@ -103,67 +105,6 @@ _LIBCPP_AVAILABILITY_TO_CHARS _LIBCPP_FUNC_VIS char* __u32toa(uint32_t __value,
 
 #ifndef _LIBCPP_CXX03_LANG
 
-enum class _LIBCPP_ENUM_VIS chars_format
-{
-    scientific = 0x1,
-    fixed = 0x2,
-    hex = 0x4,
-    general = fixed | scientific
-};
-
-inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
-operator~(chars_format __x) {
-  return chars_format(~_VSTD::__to_underlying(__x));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
-operator&(chars_format __x, chars_format __y) {
-  return chars_format(_VSTD::__to_underlying(__x) &
-                      _VSTD::__to_underlying(__y));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
-operator|(chars_format __x, chars_format __y) {
-  return chars_format(_VSTD::__to_underlying(__x) |
-                      _VSTD::__to_underlying(__y));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY constexpr chars_format
-operator^(chars_format __x, chars_format __y) {
-  return chars_format(_VSTD::__to_underlying(__x) ^
-                      _VSTD::__to_underlying(__y));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
-operator&=(chars_format& __x, chars_format __y) {
-  __x = __x & __y;
-  return __x;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
-operator|=(chars_format& __x, chars_format __y) {
-  __x = __x | __y;
-  return __x;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 chars_format&
-operator^=(chars_format& __x, chars_format __y) {
-  __x = __x ^ __y;
-  return __x;
-}
-
-struct _LIBCPP_TYPE_VIS to_chars_result
-{
-    char* ptr;
-    errc ec;
-};
-
-struct _LIBCPP_TYPE_VIS from_chars_result
-{
-    const char* ptr;
-    errc ec;
-};
-
 void to_chars(char*, char*, bool, int = 10) = delete;
 void from_chars(const char*, const char*, bool, int = 10) = delete;
 

diff  --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap
index 783f2125adbd7..f0d6023de881d 100644
--- a/libcxx/include/module.modulemap
+++ b/libcxx/include/module.modulemap
@@ -346,6 +346,13 @@ module std [system] {
   module charconv {
     header "charconv"
     export *
+
+    module __charconv {
+      module chars_format      { private header "__charconv/chars_format.h"      }
+      module from_chars_result { private header "__charconv/from_chars_result.h" }
+      module to_chars_result   { private header "__charconv/to_chars_result.h"   }
+    }
+
   }
   module chrono {
     header "chrono"

diff  --git a/libcxx/test/libcxx/diagnostics/detail.headers/charconv/chars_format.module.verify.cpp b/libcxx/test/libcxx/diagnostics/detail.headers/charconv/chars_format.module.verify.cpp
new file mode 100644
index 0000000000000..09586b2d0b574
--- /dev/null
+++ b/libcxx/test/libcxx/diagnostics/detail.headers/charconv/chars_format.module.verify.cpp
@@ -0,0 +1,16 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: modules-build
+
+// WARNING: This test was generated by 'generate_private_header_tests.py'
+// and should not be edited manually.
+
+// expected-error@*:* {{use of private header from outside its module: '__charconv/chars_format.h'}}
+#include <__charconv/chars_format.h>

diff  --git a/libcxx/test/libcxx/diagnostics/detail.headers/charconv/from_chars_result.module.verify.cpp b/libcxx/test/libcxx/diagnostics/detail.headers/charconv/from_chars_result.module.verify.cpp
new file mode 100644
index 0000000000000..00e0927c0ed97
--- /dev/null
+++ b/libcxx/test/libcxx/diagnostics/detail.headers/charconv/from_chars_result.module.verify.cpp
@@ -0,0 +1,16 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: modules-build
+
+// WARNING: This test was generated by 'generate_private_header_tests.py'
+// and should not be edited manually.
+
+// expected-error@*:* {{use of private header from outside its module: '__charconv/from_chars_result.h'}}
+#include <__charconv/from_chars_result.h>

diff  --git a/libcxx/test/libcxx/diagnostics/detail.headers/charconv/to_chars_result.module.verify.cpp b/libcxx/test/libcxx/diagnostics/detail.headers/charconv/to_chars_result.module.verify.cpp
new file mode 100644
index 0000000000000..6d704cd47e505
--- /dev/null
+++ b/libcxx/test/libcxx/diagnostics/detail.headers/charconv/to_chars_result.module.verify.cpp
@@ -0,0 +1,16 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: modules-build
+
+// WARNING: This test was generated by 'generate_private_header_tests.py'
+// and should not be edited manually.
+
+// expected-error@*:* {{use of private header from outside its module: '__charconv/to_chars_result.h'}}
+#include <__charconv/to_chars_result.h>


        


More information about the libcxx-commits mailing list