[libcxx-commits] [libcxx] [libc++][modules] Adds std.compat module. (PR #71438)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Nov 21 09:57:53 PST 2023
================
@@ -0,0 +1,307 @@
+# ===----------------------------------------------------------------------===##
+#
+# 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
+#
+# ===----------------------------------------------------------------------===##
+
+from libcxx.header_information import module_headers
+from libcxx.header_information import header_restrictions
+
+### SkipDeclarations
+
+# Ignore several declarations found in the includes.
+#
+# Part of these items are bugs other are not yet implemented features.
+SkipDeclarations = dict()
+
+# See comment in the header.
+SkipDeclarations["cuchar"] = ["std::mbstate_t", "std::size_t"]
+
+# Not in the synopsis.
+SkipDeclarations["cwchar"] = ["std::FILE"]
+
+# The operators are added for private types like __iom_t10.
+SkipDeclarations["iomanip"] = ["std::operator<<", "std::operator>>"]
+
+SkipDeclarations["iosfwd"] = ["std::ios_base", "std::vector"]
+
+# This header also provides declarations in the namespace that might be
+# an error.
+SkipDeclarations["filesystem"] = [
+ "std::filesystem::operator==",
+ "std::filesystem::operator!=",
+]
+
+# This is a specialization for a private type
+SkipDeclarations["iterator"] = ["std::pointer_traits"]
+
+# TODO MODULES
+# This definition is declared in string and defined in istream
+# This declaration should be part of string
+SkipDeclarations["istream"] = ["std::getline"]
+
+# P1614 (at many places) and LWG3519 too.
+SkipDeclarations["random"] = [
+ "std::operator!=",
+ # LWG3519 makes these hidden friends.
+ # Note the older versions had the requirement of these operations but not in
+ # the synopsis.
+ "std::operator<<",
+ "std::operator>>",
+ "std::operator==",
+]
+
+# Declared in the forward header since std::string uses std::allocator
+SkipDeclarations["string"] = ["std::allocator"]
+# TODO MODULES remove zombie names
+# https://libcxx.llvm.org/Status/Cxx20.html#note-p0619
+SkipDeclarations["memory"] = [
+ "std::return_temporary_buffer",
+ "std::get_temporary_buffer",
+]
+
+# TODO MODULES this should be part of ios instead
+SkipDeclarations["streambuf"] = ["std::basic_ios"]
+
+# include/__type_traits/is_swappable.h
+SkipDeclarations["type_traits"] = [
+ "std::swap",
+ # TODO MODULES gotten through __functional/unwrap_ref.h
+ "std::reference_wrapper",
+]
+
+### ExtraDeclarations
+
+# Add declarations in headers.
+#
+# Some headers have their defines in a different header, which may have
+# additional declarations.
+ExtraDeclarations = dict()
+# This declaration is in the ostream header.
+ExtraDeclarations["system_error"] = ["std::operator<<"]
+
+### ExtraHeader
+
+# Adds extra headers file to scan
+#
+# Some C++ headers in libc++ are stored in multiple physical files. There is a
+# pattern to find these files. However there are some exceptions these are
+# listed here.
+ExtraHeader = dict()
+# locale has a file and not a subdirectory
+ExtraHeader["locale"] = "v1/__locale$"
+ExtraHeader["thread"] = "v1/__threading_support$"
+ExtraHeader["ranges"] = "v1/__fwd/subrange.h$"
+
+# The extra header is needed since two headers are required to provide the
+# same definition.
+ExtraHeader["functional"] = "v1/__compare/compare_three_way.h$"
+
+
+# newline needs to be escaped for the module partition output.
+nl = "\\\\n"
+
+
+class module_test_generator:
+ def __init__(
+ self,
+ tmp_prefix,
+ module_path,
+ clang_tidy,
+ clang_tidy_plugin,
+ compiler,
+ compiler_flags,
+ ):
+ self.tmp_prefix = tmp_prefix
+ self.module_path = module_path
+ self.clang_tidy = clang_tidy
+ self.clang_tidy_plugin = clang_tidy_plugin
+ self.compiler = compiler
+ self.compiler_flags = compiler_flags
+
+ def write_lit_configuration(self):
+ print(
+ f"""\
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: libcpp-has-no-std-modules
+// UNSUPPORTED: clang-modules-build
+
+// REQUIRES: has-clang-tidy
+
+// The GCC compiler flags are not always compatible with clang-tidy.
+// UNSUPPORTED: gcc
+
+// RUN: echo -n > {self.tmp_prefix}.all_partitions
+"""
+ )
+
+ def process_module_partition(self, header, is_c_header):
+ # Some headers cannot be included when a libc++ feature is disabled.
+ # In that case include the header conditionally. The header __config
+ # ensures the libc++ feature macros are available.
+ if header in header_restrictions:
+ include = (
+ f"#include <__config>{nl}"
+ f"#if {header_restrictions[header]}{nl}"
+ f"# include <{header}>{nl}"
+ f"#endif{nl}"
+ )
+ elif header == "chrono":
+ # When localization is disabled the header string is not included.
+ # When string is included chrono's operator""s is a named declaration
+ # using std::chrono_literals::operator""s;
+ # else it is a named declaration
+ # using std::operator""s;
+ # TODO MODULES investigate why
+ include = f"#include <string>{nl}#include <chrono>{nl}"
+ else:
+ include = f"#include <{header}>{nl}"
+
+ module_files = f'#include \\"%{{module}}/std/{header}.inc\\"{nl}'
+ if is_c_header:
+ module_files += f'#include \\"%{{module}}/std.compat/{header}.inc\\"{nl}'
----------------
ldionne wrote:
```suggestion
module_files += f'#include \\"{self.module_path}/std.compat/{header}.inc\\"{nl}'
```
https://github.com/llvm/llvm-project/pull/71438
More information about the libcxx-commits
mailing list