diff --git a/libcxx/include/__std_clang_module b/libcxx/include/__std_clang_module --- a/libcxx/include/__std_clang_module +++ b/libcxx/include/__std_clang_module @@ -30,6 +30,12 @@ #include #include #include +#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) +#include +#endif +#if !defined(_LIBCPP_HAS_NO_THREADS) +#include +#endif #include #include #include @@ -43,7 +49,13 @@ #include #include #include +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +#include +#endif #include +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +#include +#endif #include #include #include @@ -63,6 +75,12 @@ #include #include #include +#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) +#include +#endif +#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) +#include +#endif #include #include #include @@ -75,6 +93,9 @@ #include #include #include +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +#include +#endif #include #include #include @@ -88,14 +109,41 @@ #include #include #include +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +#include +#endif #include +#if !defined(_LIBCPP_HAS_NO_THREADS) +#include +#endif #include #include +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +#include +#endif +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +#include +#endif #include +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +#include +#endif +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +#include +#endif #include +#if !defined(_LIBCPP_HAS_NO_THREADS) +#include +#endif #include #include #include +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +#include +#endif +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +#include +#endif #include #include #include @@ -106,28 +154,58 @@ #include #include #include +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +#include +#endif #include #include #include #include #include +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +#include +#endif #include +#if !defined(_LIBCPP_HAS_NO_THREADS) +#include +#endif #include #include +#if !defined(_LIBCPP_HAS_NO_THREADS) +#include +#endif #include #include +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +#include +#endif #include +#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) +#include +#endif #include #include #include #include #include #include +#if !defined(_LIBCPP_HAS_NO_THREADS) +#include +#endif +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +#include +#endif #include #include #include +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +#include +#endif #include #include +#if !defined(_LIBCPP_HAS_NO_THREADS) +#include +#endif #include #include #include @@ -140,43 +218,9 @@ #include #include #include - -#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER -# include -# include -#endif - -#ifndef _LIBCPP_HAS_NO_LOCALIZATION -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -#endif - -#ifndef _LIBCPP_HAS_NO_THREADS -# include -# include -# include -# include -# include -# include -# include +#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) +#include #endif - -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -# include -# include -# include -# include +#if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) +#include #endif diff --git a/libcxx/utils/generate_std_clang_module_header.py b/libcxx/utils/generate_std_clang_module_header.py --- a/libcxx/utils/generate_std_clang_module_header.py +++ b/libcxx/utils/generate_std_clang_module_header.py @@ -11,11 +11,7 @@ import libcxx.header_information -public_headers = libcxx.header_information.public_headers -header_include_requirements = libcxx.header_information.header_include_requirements -always_available_headers = frozenset(public_headers).difference( - *header_include_requirements.values() -) +header_restrictions = libcxx.header_information.header_restrictions libcxx_include_directory = os.path.join( os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "include" @@ -58,25 +54,10 @@ ) # Include the angle brackets in sorting so that sorts before # like check-format wants. - for include in sorted([f"<{header}>" for header in always_available_headers]): + for include, header in sorted([(f"<{header}>", header) for header in libcxx.header_information.public_headers]): + header_restriction = header_restrictions.get(header) + if header_restriction: + std_clang_module_header.write(f"#if {header_restriction}\n") std_clang_module_header.write(f"#include {include}\n") - - for requirements, headers in sorted( - header_include_requirements.items(), key=operator.itemgetter(0) - ): - std_clang_module_header.write("\n") - if len(requirements) == 1: - std_clang_module_header.write("#ifndef ") - std_clang_module_header.write(requirements[0]) - else: - std_clang_module_header.write("#if") - for index, requirement in enumerate(requirements): - if index > 0: - std_clang_module_header.write(" &&") - std_clang_module_header.write(f" !defined({requirement})") - std_clang_module_header.write("\n") - - for include in sorted([f"<{header}>" for header in headers]): - std_clang_module_header.write(f"# include {include}\n") - - std_clang_module_header.write("#endif\n") + if header_restriction: + std_clang_module_header.write(f"#endif\n") diff --git a/libcxx/utils/libcxx/header_information.py b/libcxx/utils/libcxx/header_information.py --- a/libcxx/utils/libcxx/header_information.py +++ b/libcxx/utils/libcxx/header_information.py @@ -8,6 +8,46 @@ import os, pathlib +header_restrictions = { + # headers with #error directives + "atomic": "!defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)", + "stdatomic.h": "!defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)", + + # headers with #error directives + "ios": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)", + "locale.h": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)", + # transitive includers of the above headers + "clocale": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)", + "codecvt": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)", + "experimental/regex": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)", + "fstream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)", + "iomanip": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)", + "iostream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)", + "istream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)", + "locale": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)", + "ostream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)", + "regex": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)", + "sstream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)", + "streambuf": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)", + "strstream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)", + + # headers with #error directives + "barrier": "!defined(_LIBCPP_HAS_NO_THREADS)", + "future": "!defined(_LIBCPP_HAS_NO_THREADS)", + "latch": "!defined(_LIBCPP_HAS_NO_THREADS)", + "semaphore": "!defined(_LIBCPP_HAS_NO_THREADS)", + "shared_mutex": "!defined(_LIBCPP_HAS_NO_THREADS)", + "stop_token": "!defined(_LIBCPP_HAS_NO_THREADS)", + "thread": "!defined(_LIBCPP_HAS_NO_THREADS)", + + # headers with #error directives + "wchar.h": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)", + "wctype.h": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)", + # transitive includers of the above headers + "cwchar": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)", + "cwctype": "!defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)", +} + lit_header_restrictions = { "barrier": "// UNSUPPORTED: no-threads, c++03, c++11, c++14, c++17", "clocale": "// UNSUPPORTED: no-localization", @@ -57,52 +97,6 @@ "wctype.h": "// UNSUPPORTED: no-wide-characters", } -header_include_requirements = { - ("_LIBCPP_HAS_NO_ATOMIC_HEADER",): ( - # headers with #error directives - "atomic", - # transitive includers of the above headers - "stdatomic.h", - ), - ("_LIBCPP_HAS_NO_LOCALIZATION",): ( - # headers with #error directives - "ios", - "locale.h", - # transitive includers of the above headers - "clocale", - "codecvt", - "experimental/regex", - "fstream", - "iomanip", - "iostream", - "istream", - "locale", - "ostream", - "regex", - "sstream", - "streambuf", - "strstream", - ), - ("_LIBCPP_HAS_NO_THREADS",): ( - # headers with #error directives - "barrier", - "future", - "latch", - "semaphore", - "shared_mutex", - "stop_token", - "thread", - ), - ("_LIBCPP_HAS_NO_WIDE_CHARACTERS",): ( - # headers with #error directives - "wchar.h", - "wctype.h", - # transitive includers of the above headers - "cwchar", - "cwctype", - ), -} - # This table was produced manually, by grepping the TeX source of the Standard's # library clauses for the string "#include". Each header's synopsis contains # explicit "#include" directives for its mandatory inclusions.