From f7be909f042349e92b1ae54787e746edfd497c7b Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Fri, 8 Nov 2024 20:29:36 +0100 Subject: [PATCH 1/5] chore: Improve headers search --- src/parser/cxx/preprocessor.cc | 121 ++++++++++++++++++++------------- 1 file changed, 74 insertions(+), 47 deletions(-) diff --git a/src/parser/cxx/preprocessor.cc b/src/parser/cxx/preprocessor.cc index ba94e700..cb9ff3dc 100644 --- a/src/parser/cxx/preprocessor.cc +++ b/src/parser/cxx/preprocessor.cc @@ -1035,62 +1035,86 @@ struct Preprocessor::Private { [[nodiscard]] auto checkPragmaOnceProtected(TokList *ts) const -> bool; - [[nodiscard]] auto resolve(const Include &include, bool next) const - -> std::optional { - if (!canResolveFiles_) return std::nullopt; + struct Resolve { + const Private *d; + bool wantNextInlude; + bool didFindCurrentPath = false; + std::optional firstMatch; - struct Resolve { - const Private *d; - bool next; - - Resolve(const Private *d, bool next) : d(d), next(next) {} - - [[nodiscard]] auto operator()(const SystemInclude &include) const - -> std::optional { - bool hit = false; - for (const auto &includePath : - d->systemIncludePaths_ | std::views::reverse) { - const auto path = fs::path(includePath) / include.fileName; - if (d->fileExists(path)) { - if (!next || hit) return path; - hit = true; - } - } - return {}; - } + Resolve(const Private *d, bool next) : d(d), wantNextInlude(next) {} - [[nodiscard]] auto operator()(const QuoteInclude &include) const - -> std::optional { - bool hit = false; + [[nodiscard]] auto search(auto view, const std::string &headerName) + -> std::optional { + auto transformToIncludePath = std::views::transform( + [&](const fs::path &path) { return path / headerName; }); - if (auto path = d->currentPath_ / include.fileName; - d->fileExists(path)) { - if (!next) return path; - hit = true; - } + auto filterExistingFiles = std::views::filter( + [&](const fs::path &path) { return d->fileExists(path); }); - for (const auto &includePath : - d->quoteIncludePaths_ | std::views::reverse) { - const auto path = fs::path(includePath) / include.fileName; - if (d->fileExists(path)) { - if (!next || hit) return path; - hit = true; - } + for (const auto &path : view | transformToIncludePath | + filterExistingFiles | std::views::reverse) { + firstMatch = path; + + if (wantNextInlude && path == d->currentPath_) { + didFindCurrentPath = true; + continue; } - for (const auto &includePath : - d->systemIncludePaths_ | std::views::reverse) { - const auto path = fs::path(includePath) / include.fileName; - if (d->fileExists(path)) { - if (!next || hit) return path; - hit = true; - } + if (wantNextInlude && !didFindCurrentPath) { + continue; } - return {}; + + return path; + } + + return std::nullopt; + } + + [[nodiscard]] auto operator()(const QuoteInclude &include) + -> std::optional { + const auto &headerName = include.fileName; + + // search in the current path + if (auto p = search(std::views::single(d->currentPath_), headerName)) { + return p; + } + + // search in the quote include paths + if (auto p = search(d->quoteIncludePaths_, headerName)) { + return p; } - }; - return std::visit(Resolve(this, next), include); + // fallback to system include paths + if (auto p = search(d->systemIncludePaths_, headerName)) { + return p; + } + + if (wantNextInlude && !didFindCurrentPath) { + return firstMatch; + } + + return std::nullopt; + } + + [[nodiscard]] auto operator()(const SystemInclude &include) + -> std::optional { + if (auto p = search(d->systemIncludePaths_, include.fileName)) { + return p; + } + + if (wantNextInlude && !didFindCurrentPath) { + return firstMatch; + } + + return std::nullopt; + } + }; + + [[nodiscard]] auto resolve(const Include &include, bool next) const + -> std::optional { + if (!canResolveFiles_) return std::nullopt; + + return std::visit(Resolve{this, next}, include); } [[nodiscard]] auto isDefined(const std::string_view &id) const -> bool { @@ -2979,6 +3003,9 @@ auto Preprocessor::systemIncludePaths() const } void Preprocessor::addSystemIncludePath(std::string path) { + while (path.length() > 1 && path.ends_with(fs::path::preferred_separator)) { + path.pop_back(); + } d->systemIncludePaths_.push_back(std::move(path)); } From ceb3750ac36d5b6962e673d3f3714d6dabdf2ebe Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Fri, 8 Nov 2024 20:29:36 +0100 Subject: [PATCH 2/5] chore: Update the macos toolchain --- src/parser/cxx/macos_toolchain.cc | 1000 +++++++++++++++-------------- src/parser/cxx/macos_toolchain.h | 2 + 2 files changed, 504 insertions(+), 498 deletions(-) diff --git a/src/parser/cxx/macos_toolchain.cc b/src/parser/cxx/macos_toolchain.cc index 72b14cdf..fa53bac1 100644 --- a/src/parser/cxx/macos_toolchain.cc +++ b/src/parser/cxx/macos_toolchain.cc @@ -77,9 +77,6 @@ void MacOSToolchain::addPredefinedMacros() { defineMacro("_Nullable", ""); defineMacro("_Pragma(x)", ""); - // std=c++26 - defineMacro("__cplusplus", "202400L"); - addCommonMacros(); addCxx26Macros(); @@ -90,489 +87,262 @@ void MacOSToolchain::addPredefinedMacros() { } } -// clang-format off +void MacOSToolchain::addCxx20Macros() { + // clang-format off + defineMacro("__cplusplus", "202002L"); + defineMacro("__cpp_constexpr", "201907L"); + defineMacro("__cpp_range_based_for", "201603L"); + defineMacro("__cpp_static_assert", "201411L"); + // clang-format on +} + +void MacOSToolchain::addCxx23Macros() { + // clang-format off + defineMacro("__cplusplus", "202302L"); + defineMacro("__cpp_auto_cast", "202110L"); + defineMacro("__cpp_constexpr", "202211L"); + defineMacro("__cpp_if_consteval", "202106L"); + defineMacro("__cpp_implicit_move", "202207L"); + defineMacro("__cpp_multidimensional_subscript", "202211L"); + defineMacro("__cpp_range_based_for", "202211L"); + defineMacro("__cpp_size_t_suffix", "202011L"); + defineMacro("__cpp_static_assert", "201411L"); + // clang-format on +} + +void MacOSToolchain::addCxx26Macros() { + // clang-format off + defineMacro("__cplusplus", "202400L"); + defineMacro("__cpp_auto_cast", "202110L"); + defineMacro("__cpp_constexpr", "202306L"); + defineMacro("__cpp_if_consteval", "202106L"); + defineMacro("__cpp_implicit_move", "202207L"); + defineMacro("__cpp_multidimensional_subscript", "202211L"); + defineMacro("__cpp_range_based_for", "202211L"); + defineMacro("__cpp_size_t_suffix", "202011L"); + defineMacro("__cpp_static_assert", "202306L"); + // clang-format on +} + void MacOSToolchain::addCommonMacros() { - defineMacro("__weak", "__attribute__((objc_gc(weak)))"); - defineMacro("__unsafe_unretained", ""); - defineMacro("__strong", ""); - defineMacro("__private_extern__", "extern"); - defineMacro("__pic__", "2"); - defineMacro("__nullable", "_Nullable"); - defineMacro("__null_unspecified", "_Null_unspecified"); - defineMacro("__nonnull", "_Nonnull"); - defineMacro("__llvm__", "1"); - defineMacro("__cpp_variadic_using", "201611L"); - defineMacro("__cpp_variadic_templates", "200704L"); - defineMacro("__cpp_variable_templates", "201304L"); - defineMacro("__cpp_using_enum", "201907L"); - defineMacro("__cpp_user_defined_literals", "200809L"); - defineMacro("__cpp_unicode_literals", "200710L"); - defineMacro("__cpp_unicode_characters", "200704L"); - defineMacro("__cpp_threadsafe_static_init", "200806L"); - defineMacro("__cpp_template_template_args", "201611L"); - defineMacro("__cpp_template_auto", "201606L"); - defineMacro("__cpp_structured_bindings", "202403L"); - defineMacro("__cpp_static_call_operator", "202207L"); - defineMacro("__cpp_sized_deallocation", "201309L"); - defineMacro("__cpp_rvalue_references", "200610L"); - defineMacro("__cpp_rtti", "199711L"); - defineMacro("__cpp_return_type_deduction", "201304L"); - defineMacro("__cpp_ref_qualifiers", "200710L"); - defineMacro("__cpp_raw_strings", "200710L"); - defineMacro("__cpp_placeholder_variables", "202306L"); - defineMacro("__cpp_pack_indexing", "202311L"); - defineMacro("__cpp_nsdmi", "200809L"); - defineMacro("__cpp_nontype_template_parameter_auto", "201606L"); - defineMacro("__cpp_nontype_template_args", "201411L"); - defineMacro("__cpp_noexcept_function_type", "201510L"); - defineMacro("__cpp_nested_namespace_definitions", "201411L"); - defineMacro("__cpp_namespace_attributes", "201411L"); - defineMacro("__cpp_named_character_escapes", "202207L"); - defineMacro("__cpp_lambdas", "200907L"); - defineMacro("__cpp_inline_variables", "201606L"); - defineMacro("__cpp_initializer_lists", "200806L"); - defineMacro("__cpp_init_captures", "201803L"); - defineMacro("__cpp_inheriting_constructors", "201511L"); - defineMacro("__cpp_impl_three_way_comparison", "201907L"); - defineMacro("__cpp_impl_destroying_delete", "201806L"); - defineMacro("__cpp_impl_coroutine", "201902L"); - defineMacro("__cpp_if_constexpr", "201606L"); - defineMacro("__cpp_hex_float", "201603L"); - defineMacro("__cpp_guaranteed_copy_elision", "201606L"); - defineMacro("__cpp_generic_lambdas", "201707L"); - defineMacro("__cpp_fold_expressions", "201603L"); - defineMacro("__cpp_exceptions", "199711L"); - defineMacro("__cpp_enumerator_attributes", "201411L"); - defineMacro("__cpp_digit_separators", "201309L"); - defineMacro("__cpp_designated_initializers", "201707L"); - defineMacro("__cpp_deleted_function", "202403L"); - defineMacro("__cpp_delegating_constructors", "200604L"); - defineMacro("__cpp_deduction_guides", "201703L"); - defineMacro("__cpp_decltype_auto", "201304L"); - defineMacro("__cpp_decltype", "200707L"); - defineMacro("__cpp_constinit", "201907L"); - defineMacro("__cpp_constexpr_in_decltype", "201711L"); - defineMacro("__cpp_constexpr_dynamic_alloc", "201907L"); - defineMacro("__cpp_consteval", "202211L"); - defineMacro("__cpp_conditional_explicit", "201806L"); - defineMacro("__cpp_concepts", "202002"); - defineMacro("__cpp_char8_t", "202207L"); - defineMacro("__cpp_capture_star_this", "201603L"); - defineMacro("__cpp_binary_literals", "201304L"); - defineMacro("__cpp_attributes", "200809L"); - defineMacro("__cpp_aligned_new", "201606L"); - defineMacro("__cpp_alias_templates", "200704L"); - defineMacro("__cpp_aggregate_paren_init", "201902L"); - defineMacro("__cpp_aggregate_nsdmi", "201304L"); - defineMacro("__cpp_aggregate_bases", "201603L"); - defineMacro("__clang_wide_literal_encoding__", "\"UTF-32\""); - defineMacro("__clang_version__", "\"19.1.3"); - defineMacro("__clang_patchlevel__", "3"); - defineMacro("__clang_minor__", "1"); - defineMacro("__clang_major__", "19"); - defineMacro("__clang_literal_encoding__", "\"UTF-8\""); - defineMacro("__clang__", "1"); - defineMacro("__block", "__attribute__((__blocks__(byref)))"); - defineMacro("__WINT_WIDTH__", "32"); - defineMacro("__WINT_TYPE__", "int"); - defineMacro("__WINT_MAX__", "2147483647"); - defineMacro("__WCHAR_WIDTH__", "32"); - defineMacro("__WCHAR_TYPE__", "int"); - defineMacro("__WCHAR_MAX__", "2147483647"); - defineMacro("__VERSION__", "\"Homebrew"); - defineMacro("__USER_LABEL_PREFIX__", "_"); - defineMacro("__UINT_LEAST8_TYPE__", "unsigned"); - defineMacro("__UINT_LEAST8_MAX__", "255"); - defineMacro("__UINT_LEAST8_FMTx__", "\"hhx\""); - defineMacro("__UINT_LEAST8_FMTu__", "\"hhu\""); - defineMacro("__UINT_LEAST8_FMTo__", "\"hho\""); - defineMacro("__UINT_LEAST8_FMTX__", "\"hhX\""); - defineMacro("__UINT_LEAST64_TYPE__", "long"); - defineMacro("__UINT_LEAST64_MAX__", "18446744073709551615ULL"); - defineMacro("__UINT_LEAST64_FMTx__", "\"llx\""); - defineMacro("__UINT_LEAST64_FMTu__", "\"llu\""); - defineMacro("__UINT_LEAST64_FMTo__", "\"llo\""); - defineMacro("__UINT_LEAST64_FMTX__", "\"llX\""); - defineMacro("__UINT_LEAST32_TYPE__", "unsigned"); - defineMacro("__UINT_LEAST32_MAX__", "4294967295U"); - defineMacro("__UINT_LEAST32_FMTx__", "\"x\""); - defineMacro("__UINT_LEAST32_FMTu__", "\"u\""); - defineMacro("__UINT_LEAST32_FMTo__", "\"o\""); - defineMacro("__UINT_LEAST32_FMTX__", "\"X\""); - defineMacro("__UINT_LEAST16_TYPE__", "unsigned"); - defineMacro("__UINT_LEAST16_MAX__", "65535"); - defineMacro("__UINT_LEAST16_FMTx__", "\"hx\""); - defineMacro("__UINT_LEAST16_FMTu__", "\"hu\""); - defineMacro("__UINT_LEAST16_FMTo__", "\"ho\""); - defineMacro("__UINT_LEAST16_FMTX__", "\"hX\""); - defineMacro("__UINT_FAST8_TYPE__", "unsigned"); - defineMacro("__UINT_FAST8_MAX__", "255"); - defineMacro("__UINT_FAST8_FMTx__", "\"hhx\""); - defineMacro("__UINT_FAST8_FMTu__", "\"hhu\""); - defineMacro("__UINT_FAST8_FMTo__", "\"hho\""); - defineMacro("__UINT_FAST8_FMTX__", "\"hhX\""); - defineMacro("__UINT_FAST64_TYPE__", "long"); - defineMacro("__UINT_FAST64_MAX__", "18446744073709551615ULL"); - defineMacro("__UINT_FAST64_FMTx__", "\"llx\""); - defineMacro("__UINT_FAST64_FMTu__", "\"llu\""); - defineMacro("__UINT_FAST64_FMTo__", "\"llo\""); - defineMacro("__UINT_FAST64_FMTX__", "\"llX\""); - defineMacro("__UINT_FAST32_TYPE__", "unsigned"); - defineMacro("__UINT_FAST32_MAX__", "4294967295U"); - defineMacro("__UINT_FAST32_FMTx__", "\"x\""); - defineMacro("__UINT_FAST32_FMTu__", "\"u\""); - defineMacro("__UINT_FAST32_FMTo__", "\"o\""); - defineMacro("__UINT_FAST32_FMTX__", "\"X\""); - defineMacro("__UINT_FAST16_TYPE__", "unsigned"); - defineMacro("__UINT_FAST16_MAX__", "65535"); - defineMacro("__UINT_FAST16_FMTx__", "\"hx\""); - defineMacro("__UINT_FAST16_FMTu__", "\"hu\""); - defineMacro("__UINT_FAST16_FMTo__", "\"ho\""); - defineMacro("__UINT_FAST16_FMTX__", "\"hX\""); - defineMacro("__UINTPTR_WIDTH__", "64"); - defineMacro("__UINTPTR_TYPE__", "long"); - defineMacro("__UINTPTR_MAX__", "18446744073709551615UL"); - defineMacro("__UINTPTR_FMTx__", "\"lx\""); - defineMacro("__UINTPTR_FMTu__", "\"lu\""); - defineMacro("__UINTPTR_FMTo__", "\"lo\""); - defineMacro("__UINTPTR_FMTX__", "\"lX\""); - defineMacro("__UINTMAX_WIDTH__", "64"); - defineMacro("__UINTMAX_TYPE__", "long"); - defineMacro("__UINTMAX_MAX__", "18446744073709551615UL"); - defineMacro("__UINTMAX_FMTx__", "\"lx\""); - defineMacro("__UINTMAX_FMTu__", "\"lu\""); - defineMacro("__UINTMAX_FMTo__", "\"lo\""); - defineMacro("__UINTMAX_FMTX__", "\"lX\""); - defineMacro("__UINTMAX_C_SUFFIX__", "UL"); - defineMacro("__UINT8_TYPE__", "unsigned"); - defineMacro("__UINT8_MAX__", "255"); - defineMacro("__UINT8_FMTx__", "\"hhx\""); - defineMacro("__UINT8_FMTu__", "\"hhu\""); - defineMacro("__UINT8_FMTo__", "\"hho\""); - defineMacro("__UINT8_FMTX__", "\"hhX\""); - defineMacro("__UINT8_C_SUFFIX__", ""); - defineMacro("__UINT64_TYPE__", "long"); - defineMacro("__UINT64_MAX__", "18446744073709551615ULL"); - defineMacro("__UINT64_FMTx__", "\"llx\""); - defineMacro("__UINT64_FMTu__", "\"llu\""); - defineMacro("__UINT64_FMTo__", "\"llo\""); - defineMacro("__UINT64_FMTX__", "\"llX\""); - defineMacro("__UINT64_C_SUFFIX__", "ULL"); - defineMacro("__UINT32_TYPE__", "unsigned"); - defineMacro("__UINT32_MAX__", "4294967295U"); - defineMacro("__UINT32_FMTx__", "\"x\""); - defineMacro("__UINT32_FMTu__", "\"u\""); - defineMacro("__UINT32_FMTo__", "\"o\""); - defineMacro("__UINT32_FMTX__", "\"X\""); - defineMacro("__UINT32_C_SUFFIX__", "U"); - defineMacro("__UINT16_TYPE__", "unsigned"); - defineMacro("__UINT16_MAX__", "65535"); - defineMacro("__UINT16_FMTx__", "\"hx\""); - defineMacro("__UINT16_FMTu__", "\"hu\""); - defineMacro("__UINT16_FMTo__", "\"ho\""); - defineMacro("__UINT16_FMTX__", "\"hX\""); - defineMacro("__UINT16_C_SUFFIX__", ""); - defineMacro("__STRICT_ANSI__", "1"); - defineMacro("__STDC__", "1"); - defineMacro("__STDC_UTF_32__", "1"); - defineMacro("__STDC_UTF_16__", "1"); - defineMacro("__STDC_NO_THREADS__", "1"); - defineMacro("__STDC_HOSTED__", "1"); - defineMacro("__STDC_EMBED_NOT_FOUND__", "0"); - defineMacro("__STDC_EMBED_FOUND__", "1"); - defineMacro("__STDC_EMBED_EMPTY__", "2"); - defineMacro("__STDCPP_THREADS__", "1"); - defineMacro("__STDCPP_DEFAULT_NEW_ALIGNMENT__", "16UL"); - defineMacro("__SSP__", "1"); - defineMacro("__SIZE_WIDTH__", "64"); - defineMacro("__SIZE_TYPE__", "long"); - defineMacro("__SIZE_MAX__", "18446744073709551615UL"); - defineMacro("__SIZE_FMTx__", "\"lx\""); - defineMacro("__SIZE_FMTu__", "\"lu\""); - defineMacro("__SIZE_FMTo__", "\"lo\""); - defineMacro("__SIZE_FMTX__", "\"lX\""); - defineMacro("__SIZEOF_WINT_T__", "4"); - defineMacro("__SIZEOF_WCHAR_T__", "4"); - defineMacro("__SIZEOF_SIZE_T__", "8"); - defineMacro("__SIZEOF_SHORT__", "2"); - defineMacro("__SIZEOF_PTRDIFF_T__", "8"); - defineMacro("__SIZEOF_POINTER__", "8"); - defineMacro("__SIZEOF_LONG__", "8"); - defineMacro("__SIZEOF_LONG_LONG__", "8"); - defineMacro("__SIZEOF_INT__", "4"); - defineMacro("__SIZEOF_INT128__", "16"); - defineMacro("__SIZEOF_FLOAT__", "4"); - defineMacro("__SIZEOF_DOUBLE__", "8"); - defineMacro("__SIG_ATOMIC_WIDTH__", "32"); - defineMacro("__SIG_ATOMIC_MAX__", "2147483647"); - defineMacro("__SHRT_WIDTH__", "16"); - defineMacro("__SHRT_MAX__", "32767"); - defineMacro("__SCHAR_MAX__", "127"); - defineMacro("__REGISTER_PREFIX__", ""); - defineMacro("__PTRDIFF_WIDTH__", "64"); - defineMacro("__PTRDIFF_TYPE__", "long"); - defineMacro("__PTRDIFF_MAX__", "9223372036854775807L"); - defineMacro("__PTRDIFF_FMTi__", "\"li\""); - defineMacro("__PTRDIFF_FMTd__", "\"ld\""); - defineMacro("__PRAGMA_REDEFINE_EXTNAME", "1"); - defineMacro("__POINTER_WIDTH__", "64"); - defineMacro("__PIC__", "2"); - defineMacro("__ORDER_PDP_ENDIAN__", "3412"); - defineMacro("__ORDER_LITTLE_ENDIAN__", "1234"); - defineMacro("__ORDER_BIG_ENDIAN__", "4321"); - defineMacro("__OPENCL_MEMORY_SCOPE_WORK_ITEM", "0"); - defineMacro("__OPENCL_MEMORY_SCOPE_WORK_GROUP", "1"); - defineMacro("__OPENCL_MEMORY_SCOPE_SUB_GROUP", "4"); - defineMacro("__OPENCL_MEMORY_SCOPE_DEVICE", "2"); - defineMacro("__OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES", "3"); - defineMacro("__NO_MATH_ERRNO__", "1"); - defineMacro("__NO_INLINE__", "1"); - defineMacro("__MEMORY_SCOPE_WVFRNT", "3"); - defineMacro("__MEMORY_SCOPE_WRKGRP", "2"); - defineMacro("__MEMORY_SCOPE_SYSTEM", "0"); - defineMacro("__MEMORY_SCOPE_SINGLE", "4"); - defineMacro("__MEMORY_SCOPE_DEVICE", "1"); - defineMacro("__MACH__", "1"); - defineMacro("__LP64__", "1"); - defineMacro("__LONG_WIDTH__", "64"); - defineMacro("__LONG_MAX__", "9223372036854775807L"); - defineMacro("__LONG_LONG_MAX__", "9223372036854775807LL"); - defineMacro("__LLONG_WIDTH__", "64"); - defineMacro("__LITTLE_ENDIAN__", "1"); - defineMacro("__LDBL_HAS_QUIET_NAN__", "1"); - defineMacro("__LDBL_HAS_INFINITY__", "1"); - defineMacro("__LDBL_HAS_DENORM__", "1"); - defineMacro("__INT_WIDTH__", "32"); - defineMacro("__INT_MAX__", "2147483647"); - defineMacro("__INT_LEAST8_WIDTH__", "8"); - defineMacro("__INT_LEAST8_TYPE__", "signed"); - defineMacro("__INT_LEAST8_MAX__", "127"); - defineMacro("__INT_LEAST8_FMTi__", "\"hhi\""); - defineMacro("__INT_LEAST8_FMTd__", "\"hhd\""); - defineMacro("__INT_LEAST64_WIDTH__", "64"); - defineMacro("__INT_LEAST64_TYPE__", "long"); - defineMacro("__INT_LEAST64_MAX__", "9223372036854775807LL"); - defineMacro("__INT_LEAST64_FMTi__", "\"lli\""); - defineMacro("__INT_LEAST64_FMTd__", "\"lld\""); - defineMacro("__INT_LEAST32_WIDTH__", "32"); - defineMacro("__INT_LEAST32_TYPE__", "int"); - defineMacro("__INT_LEAST32_MAX__", "2147483647"); - defineMacro("__INT_LEAST32_FMTi__", "\"i\""); - defineMacro("__INT_LEAST32_FMTd__", "\"d\""); - defineMacro("__INT_LEAST16_WIDTH__", "16"); - defineMacro("__INT_LEAST16_TYPE__", "short"); - defineMacro("__INT_LEAST16_MAX__", "32767"); - defineMacro("__INT_LEAST16_FMTi__", "\"hi\""); - defineMacro("__INT_LEAST16_FMTd__", "\"hd\""); - defineMacro("__INT_FAST8_WIDTH__", "8"); - defineMacro("__INT_FAST8_TYPE__", "signed"); - defineMacro("__INT_FAST8_MAX__", "127"); - defineMacro("__INT_FAST8_FMTi__", "\"hhi\""); - defineMacro("__INT_FAST8_FMTd__", "\"hhd\""); - defineMacro("__INT_FAST64_WIDTH__", "64"); - defineMacro("__INT_FAST64_TYPE__", "long"); - defineMacro("__INT_FAST64_MAX__", "9223372036854775807LL"); - defineMacro("__INT_FAST64_FMTi__", "\"lli\""); - defineMacro("__INT_FAST64_FMTd__", "\"lld\""); - defineMacro("__INT_FAST32_WIDTH__", "32"); - defineMacro("__INT_FAST32_TYPE__", "int"); - defineMacro("__INT_FAST32_MAX__", "2147483647"); - defineMacro("__INT_FAST32_FMTi__", "\"i\""); - defineMacro("__INT_FAST32_FMTd__", "\"d\""); - defineMacro("__INT_FAST16_WIDTH__", "16"); - defineMacro("__INT_FAST16_TYPE__", "short"); - defineMacro("__INT_FAST16_MAX__", "32767"); - defineMacro("__INT_FAST16_FMTi__", "\"hi\""); - defineMacro("__INT_FAST16_FMTd__", "\"hd\""); - defineMacro("__INTPTR_WIDTH__", "64"); - defineMacro("__INTPTR_TYPE__", "long"); - defineMacro("__INTPTR_MAX__", "9223372036854775807L"); - defineMacro("__INTPTR_FMTi__", "\"li\""); - defineMacro("__INTPTR_FMTd__", "\"ld\""); - defineMacro("__INTMAX_WIDTH__", "64"); - defineMacro("__INTMAX_TYPE__", "long"); - defineMacro("__INTMAX_MAX__", "9223372036854775807L"); - defineMacro("__INTMAX_FMTi__", "\"li\""); - defineMacro("__INTMAX_FMTd__", "\"ld\""); - defineMacro("__INTMAX_C_SUFFIX__", "L"); - defineMacro("__INT8_TYPE__", "signed"); - defineMacro("__INT8_MAX__", "127"); - defineMacro("__INT8_FMTi__", "\"hhi\""); - defineMacro("__INT8_FMTd__", "\"hhd\""); - defineMacro("__INT8_C_SUFFIX__", ""); - defineMacro("__INT64_TYPE__", "long"); - defineMacro("__INT64_MAX__", "9223372036854775807LL"); - defineMacro("__INT64_FMTi__", "\"lli\""); - defineMacro("__INT64_FMTd__", "\"lld\""); - defineMacro("__INT64_C_SUFFIX__", "LL"); - defineMacro("__INT32_TYPE__", "int"); - defineMacro("__INT32_MAX__", "2147483647"); - defineMacro("__INT32_FMTi__", "\"i\""); - defineMacro("__INT32_FMTd__", "\"d\""); - defineMacro("__INT32_C_SUFFIX__", ""); - defineMacro("__INT16_TYPE__", "short"); - defineMacro("__INT16_MAX__", "32767"); - defineMacro("__INT16_FMTi__", "\"hi\""); - defineMacro("__INT16_FMTd__", "\"hd\""); - defineMacro("__INT16_C_SUFFIX__", ""); - defineMacro("__GXX_WEAK__", "1"); - defineMacro("__GXX_RTTI", "1"); - defineMacro("__GXX_EXPERIMENTAL_CXX0X__", "1"); - defineMacro("__GXX_ABI_VERSION", "1002"); - defineMacro("__GNUG__", "4"); - defineMacro("__GNUC__", "4"); - defineMacro("__GNUC_PATCHLEVEL__", "1"); - defineMacro("__GNUC_MINOR__", "2"); - defineMacro("__GNUC_GNU_INLINE__", "1"); - defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8", "1"); - defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4", "1"); - defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2", "1"); - defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16", "1"); - defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1", "1"); - defineMacro("__GCC_HAVE_DWARF2_CFI_ASM", "1"); - defineMacro("__GCC_DESTRUCTIVE_SIZE", "64"); - defineMacro("__GCC_CONSTRUCTIVE_SIZE", "64"); - defineMacro("__GCC_ATOMIC_WCHAR_T_LOCK_FREE", "2"); - defineMacro("__GCC_ATOMIC_TEST_AND_SET_TRUEVAL", "1"); - defineMacro("__GCC_ATOMIC_SHORT_LOCK_FREE", "2"); - defineMacro("__GCC_ATOMIC_POINTER_LOCK_FREE", "2"); - defineMacro("__GCC_ATOMIC_LONG_LOCK_FREE", "2"); - defineMacro("__GCC_ATOMIC_LLONG_LOCK_FREE", "2"); - defineMacro("__GCC_ATOMIC_INT_LOCK_FREE", "2"); - defineMacro("__GCC_ATOMIC_CHAR_LOCK_FREE", "2"); - defineMacro("__GCC_ATOMIC_CHAR8_T_LOCK_FREE", "2"); - defineMacro("__GCC_ATOMIC_CHAR32_T_LOCK_FREE", "2"); - defineMacro("__GCC_ATOMIC_CHAR16_T_LOCK_FREE", "2"); - defineMacro("__GCC_ATOMIC_BOOL_LOCK_FREE", "2"); - defineMacro("__GCC_ASM_FLAG_OUTPUTS__", "1"); - defineMacro("__FPCLASS_SNAN", "0x0001"); - defineMacro("__FPCLASS_QNAN", "0x0002"); - defineMacro("__FPCLASS_POSZERO", "0x0040"); - defineMacro("__FPCLASS_POSSUBNORMAL", "0x0080"); - defineMacro("__FPCLASS_POSNORMAL", "0x0100"); - defineMacro("__FPCLASS_POSINF", "0x0200"); - defineMacro("__FPCLASS_NEGZERO", "0x0020"); - defineMacro("__FPCLASS_NEGSUBNORMAL", "0x0010"); - defineMacro("__FPCLASS_NEGNORMAL", "0x0008"); - defineMacro("__FPCLASS_NEGINF", "0x0004"); - defineMacro("__FLT_RADIX__", "2"); - defineMacro("__FLT_NORM_MAX__", "3.40282347e+38F"); - defineMacro("__FLT_MIN__", "1.17549435e-38F"); - defineMacro("__FLT_MIN_EXP__", "(-125)"); - defineMacro("__FLT_MIN_10_EXP__", "(-37)"); - defineMacro("__FLT_MAX__", "3.40282347e+38F"); - defineMacro("__FLT_MAX_EXP__", "128"); - defineMacro("__FLT_MAX_10_EXP__", "38"); - defineMacro("__FLT_MANT_DIG__", "24"); - defineMacro("__FLT_HAS_QUIET_NAN__", "1"); - defineMacro("__FLT_HAS_INFINITY__", "1"); - defineMacro("__FLT_HAS_DENORM__", "1"); - defineMacro("__FLT_EPSILON__", "1.19209290e-7F"); - defineMacro("__FLT_DIG__", "6"); - defineMacro("__FLT_DENORM_MIN__", "1.40129846e-45F"); - defineMacro("__FLT_DECIMAL_DIG__", "9"); - defineMacro("__FLT16_NORM_MAX__", "6.5504e+4F16"); - defineMacro("__FLT16_MIN__", "6.103515625e-5F16"); - defineMacro("__FLT16_MIN_EXP__", "(-13)"); - defineMacro("__FLT16_MIN_10_EXP__", "(-4)"); - defineMacro("__FLT16_MAX__", "6.5504e+4F16"); - defineMacro("__FLT16_MAX_EXP__", "16"); - defineMacro("__FLT16_MAX_10_EXP__", "4"); - defineMacro("__FLT16_MANT_DIG__", "11"); - defineMacro("__FLT16_HAS_QUIET_NAN__", "1"); - defineMacro("__FLT16_HAS_INFINITY__", "1"); - defineMacro("__FLT16_HAS_DENORM__", "1"); - defineMacro("__FLT16_EPSILON__", "9.765625e-4F16"); - defineMacro("__FLT16_DIG__", "3"); - defineMacro("__FLT16_DENORM_MIN__", "5.9604644775390625e-8F16"); - defineMacro("__FLT16_DECIMAL_DIG__", "5"); - defineMacro("__FINITE_MATH_ONLY__", "0"); - defineMacro("__EXCEPTIONS", "1"); - defineMacro("__ENVIRONMENT_OS_VERSION_MIN_REQUIRED__", "150000"); - defineMacro("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", "150000"); - defineMacro("__DYNAMIC__", "1"); - defineMacro("__DEPRECATED", "1"); - defineMacro("__DECIMAL_DIG__", "__LDBL_DECIMAL_DIG__"); - defineMacro("__DBL_NORM_MAX__", "1.7976931348623157e+308"); - defineMacro("__DBL_MIN__", "2.2250738585072014e-308"); - defineMacro("__DBL_MIN_EXP__", "(-1021)"); - defineMacro("__DBL_MIN_10_EXP__", "(-307)"); - defineMacro("__DBL_MAX__", "1.7976931348623157e+308"); - defineMacro("__DBL_MAX_EXP__", "1024"); - defineMacro("__DBL_MAX_10_EXP__", "308"); - defineMacro("__DBL_MANT_DIG__", "53"); - defineMacro("__DBL_HAS_QUIET_NAN__", "1"); - defineMacro("__DBL_HAS_INFINITY__", "1"); - defineMacro("__DBL_HAS_DENORM__", "1"); - defineMacro("__DBL_EPSILON__", "2.2204460492503131e-16"); - defineMacro("__DBL_DIG__", "15"); - defineMacro("__DBL_DENORM_MIN__", "4.9406564584124654e-324"); - defineMacro("__DBL_DECIMAL_DIG__", "17"); - defineMacro("__CONSTANT_CFSTRINGS__", "1"); - defineMacro("__CLANG_ATOMIC_WCHAR_T_LOCK_FREE", "2"); - defineMacro("__CLANG_ATOMIC_SHORT_LOCK_FREE", "2"); - defineMacro("__CLANG_ATOMIC_POINTER_LOCK_FREE", "2"); - defineMacro("__CLANG_ATOMIC_LONG_LOCK_FREE", "2"); - defineMacro("__CLANG_ATOMIC_LLONG_LOCK_FREE", "2"); - defineMacro("__CLANG_ATOMIC_INT_LOCK_FREE", "2"); - defineMacro("__CLANG_ATOMIC_CHAR_LOCK_FREE", "2"); - defineMacro("__CLANG_ATOMIC_CHAR8_T_LOCK_FREE", "2"); - defineMacro("__CLANG_ATOMIC_CHAR32_T_LOCK_FREE", "2"); - defineMacro("__CLANG_ATOMIC_CHAR16_T_LOCK_FREE", "2"); - defineMacro("__CLANG_ATOMIC_BOOL_LOCK_FREE", "2"); - defineMacro("__CHAR_BIT__", "8"); - defineMacro("__CHAR32_TYPE__", "unsigned"); - defineMacro("__CHAR16_TYPE__", "unsigned"); - defineMacro("__BYTE_ORDER__", "__ORDER_LITTLE_ENDIAN__"); - defineMacro("__BOOL_WIDTH__", "8"); - defineMacro("__ATOMIC_SEQ_CST", "5"); - defineMacro("__ATOMIC_RELEASE", "3"); - defineMacro("__ATOMIC_RELAXED", "0"); - defineMacro("__ATOMIC_CONSUME", "1"); - defineMacro("__ATOMIC_ACQ_REL", "4"); - defineMacro("__ATOMIC_ACQUIRE", "2"); - defineMacro("__APPLE__", "1"); - defineMacro("__APPLE_CC__", "6000"); - defineMacro("_LP64", "1"); - defineMacro("TARGET_OS_WINDOWS", "0"); - defineMacro("TARGET_OS_WIN32", "0"); - defineMacro("TARGET_OS_WATCH", "0"); - defineMacro("TARGET_OS_VISION", "0"); - defineMacro("TARGET_OS_UNIX", "0"); - defineMacro("TARGET_OS_UIKITFORMAC", "0"); - defineMacro("TARGET_OS_TV", "0"); - defineMacro("TARGET_OS_SIMULATOR", "0"); - defineMacro("TARGET_OS_OSX", "1"); - defineMacro("TARGET_OS_NANO", "0"); - defineMacro("TARGET_OS_MACCATALYST", "0"); - defineMacro("TARGET_OS_MAC", "1"); - defineMacro("TARGET_OS_LINUX", "0"); - defineMacro("TARGET_OS_IPHONE", "0"); - defineMacro("TARGET_OS_IOS", "0"); - defineMacro("TARGET_OS_EMBEDDED", "0"); - defineMacro("TARGET_OS_DRIVERKIT", "0"); + // clang-format off defineMacro("TARGET_IPHONE_SIMULATOR", "0"); -} - -void MacOSToolchain::addCxx26Macros() { - defineMacro("__cpp_static_assert", "201411L"); - defineMacro("__cpp_size_t_suffix", "202011L"); - defineMacro("__cpp_range_based_for", "202211L"); - defineMacro("__cpp_multidimensional_subscript", "202211L"); - defineMacro("__cpp_implicit_move", "202207L"); - defineMacro("__cpp_if_consteval", "202106L"); - defineMacro("__cpp_auto_cast", "202110L"); -} - -void MacOSToolchain::addAmd64Macros() { + defineMacro("TARGET_OS_DRIVERKIT", "0"); + defineMacro("TARGET_OS_EMBEDDED", "0"); + defineMacro("TARGET_OS_IOS", "0"); + defineMacro("TARGET_OS_IPHONE", "0"); + defineMacro("TARGET_OS_LINUX", "0"); + defineMacro("TARGET_OS_MAC", "1"); + defineMacro("TARGET_OS_MACCATALYST", "0"); + defineMacro("TARGET_OS_NANO", "0"); + defineMacro("TARGET_OS_OSX", "1"); + defineMacro("TARGET_OS_SIMULATOR", "0"); + defineMacro("TARGET_OS_TV", "0"); + defineMacro("TARGET_OS_UIKITFORMAC", "0"); + defineMacro("TARGET_OS_UNIX", "0"); + defineMacro("TARGET_OS_VISION", "0"); + defineMacro("TARGET_OS_WATCH", "0"); + defineMacro("TARGET_OS_WIN32", "0"); + defineMacro("TARGET_OS_WINDOWS", "0"); + defineMacro("_LP64", "1"); + defineMacro("__APPLE_CC__", "6000"); + defineMacro("__APPLE__", "1"); + defineMacro("__ATOMIC_ACQUIRE", "2"); + defineMacro("__ATOMIC_ACQ_REL", "4"); + defineMacro("__ATOMIC_CONSUME", "1"); + defineMacro("__ATOMIC_RELAXED", "0"); + defineMacro("__ATOMIC_RELEASE", "3"); + defineMacro("__ATOMIC_SEQ_CST", "5"); defineMacro("__BIGGEST_ALIGNMENT__", "16"); defineMacro("__BITINT_MAXWIDTH__", "8388608"); - defineMacro("__FXSR__", "1"); - defineMacro("__LAHF_SAHF__", "1"); + defineMacro("__BLOCKS__", "1"); + defineMacro("__BOOL_WIDTH__", "8"); + defineMacro("__BYTE_ORDER__", "__ORDER_LITTLE_ENDIAN__"); + defineMacro("__CHAR16_TYPE__", "unsigned short"); + defineMacro("__CHAR32_TYPE__", "unsigned int"); + defineMacro("__CHAR_BIT__", "8"); + defineMacro("__CLANG_ATOMIC_BOOL_LOCK_FREE", "2"); + defineMacro("__CLANG_ATOMIC_CHAR16_T_LOCK_FREE", "2"); + defineMacro("__CLANG_ATOMIC_CHAR32_T_LOCK_FREE", "2"); + defineMacro("__CLANG_ATOMIC_CHAR8_T_LOCK_FREE", "2"); + defineMacro("__CLANG_ATOMIC_CHAR_LOCK_FREE", "2"); + defineMacro("__CLANG_ATOMIC_INT_LOCK_FREE", "2"); + defineMacro("__CLANG_ATOMIC_LLONG_LOCK_FREE", "2"); + defineMacro("__CLANG_ATOMIC_LONG_LOCK_FREE", "2"); + defineMacro("__CLANG_ATOMIC_POINTER_LOCK_FREE", "2"); + defineMacro("__CLANG_ATOMIC_SHORT_LOCK_FREE", "2"); + defineMacro("__CLANG_ATOMIC_WCHAR_T_LOCK_FREE", "2"); + defineMacro("__CONSTANT_CFSTRINGS__", "1"); + defineMacro("__DBL_DECIMAL_DIG__", "17"); + defineMacro("__DBL_DENORM_MIN__", "4.9406564584124654e-324"); + defineMacro("__DBL_DIG__", "15"); + defineMacro("__DBL_EPSILON__", "2.2204460492503131e-16"); + defineMacro("__DBL_HAS_DENORM__", "1"); + defineMacro("__DBL_HAS_INFINITY__", "1"); + defineMacro("__DBL_HAS_QUIET_NAN__", "1"); + defineMacro("__DBL_MANT_DIG__", "53"); + defineMacro("__DBL_MAX_10_EXP__", "308"); + defineMacro("__DBL_MAX_EXP__", "1024"); + defineMacro("__DBL_MAX__", "1.7976931348623157e+308"); + defineMacro("__DBL_MIN_10_EXP__", "(-307)"); + defineMacro("__DBL_MIN_EXP__", "(-1021)"); + defineMacro("__DBL_MIN__", "2.2250738585072014e-308"); + defineMacro("__DBL_NORM_MAX__", "1.7976931348623157e+308"); + defineMacro("__DECIMAL_DIG__", "__LDBL_DECIMAL_DIG__"); + defineMacro("__DEPRECATED", "1"); + defineMacro("__DYNAMIC__", "1"); + defineMacro("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", "150000"); + defineMacro("__ENVIRONMENT_OS_VERSION_MIN_REQUIRED__", "150000"); + defineMacro("__EXCEPTIONS", "1"); + defineMacro("__FINITE_MATH_ONLY__", "0"); + defineMacro("__FLT16_DECIMAL_DIG__", "5"); + defineMacro("__FLT16_DENORM_MIN__", "5.9604644775390625e-8F16"); + defineMacro("__FLT16_DIG__", "3"); + defineMacro("__FLT16_EPSILON__", "9.765625e-4F16"); + defineMacro("__FLT16_HAS_DENORM__", "1"); + defineMacro("__FLT16_HAS_INFINITY__", "1"); + defineMacro("__FLT16_HAS_QUIET_NAN__", "1"); + defineMacro("__FLT16_MANT_DIG__", "11"); + defineMacro("__FLT16_MAX_10_EXP__", "4"); + defineMacro("__FLT16_MAX_EXP__", "16"); + defineMacro("__FLT16_MAX__", "6.5504e+4F16"); + defineMacro("__FLT16_MIN_10_EXP__", "(-4)"); + defineMacro("__FLT16_MIN_EXP__", "(-13)"); + defineMacro("__FLT16_MIN__", "6.103515625e-5F16"); + defineMacro("__FLT16_NORM_MAX__", "6.5504e+4F16"); + defineMacro("__FLT_DECIMAL_DIG__", "9"); + defineMacro("__FLT_DENORM_MIN__", "1.40129846e-45F"); + defineMacro("__FLT_DIG__", "6"); + defineMacro("__FLT_EPSILON__", "1.19209290e-7F"); + defineMacro("__FLT_HAS_DENORM__", "1"); + defineMacro("__FLT_HAS_INFINITY__", "1"); + defineMacro("__FLT_HAS_QUIET_NAN__", "1"); + defineMacro("__FLT_MANT_DIG__", "24"); + defineMacro("__FLT_MAX_10_EXP__", "38"); + defineMacro("__FLT_MAX_EXP__", "128"); + defineMacro("__FLT_MAX__", "3.40282347e+38F"); + defineMacro("__FLT_MIN_10_EXP__", "(-37)"); + defineMacro("__FLT_MIN_EXP__", "(-125)"); + defineMacro("__FLT_MIN__", "1.17549435e-38F"); + defineMacro("__FLT_NORM_MAX__", "3.40282347e+38F"); + defineMacro("__FLT_RADIX__", "2"); + defineMacro("__FPCLASS_NEGINF", "0x0004"); + defineMacro("__FPCLASS_NEGNORMAL", "0x0008"); + defineMacro("__FPCLASS_NEGSUBNORMAL", "0x0010"); + defineMacro("__FPCLASS_NEGZERO", "0x0020"); + defineMacro("__FPCLASS_POSINF", "0x0200"); + defineMacro("__FPCLASS_POSNORMAL", "0x0100"); + defineMacro("__FPCLASS_POSSUBNORMAL", "0x0080"); + defineMacro("__FPCLASS_POSZERO", "0x0040"); + defineMacro("__FPCLASS_QNAN", "0x0002"); + defineMacro("__FPCLASS_SNAN", "0x0001"); + defineMacro("__GCC_ASM_FLAG_OUTPUTS__", "1"); + defineMacro("__GCC_ATOMIC_BOOL_LOCK_FREE", "2"); + defineMacro("__GCC_ATOMIC_CHAR16_T_LOCK_FREE", "2"); + defineMacro("__GCC_ATOMIC_CHAR32_T_LOCK_FREE", "2"); + defineMacro("__GCC_ATOMIC_CHAR8_T_LOCK_FREE", "2"); + defineMacro("__GCC_ATOMIC_CHAR_LOCK_FREE", "2"); + defineMacro("__GCC_ATOMIC_INT_LOCK_FREE", "2"); + defineMacro("__GCC_ATOMIC_LLONG_LOCK_FREE", "2"); + defineMacro("__GCC_ATOMIC_LONG_LOCK_FREE", "2"); + defineMacro("__GCC_ATOMIC_POINTER_LOCK_FREE", "2"); + defineMacro("__GCC_ATOMIC_SHORT_LOCK_FREE", "2"); + defineMacro("__GCC_ATOMIC_TEST_AND_SET_TRUEVAL", "1"); + defineMacro("__GCC_ATOMIC_WCHAR_T_LOCK_FREE", "2"); + defineMacro("__GCC_CONSTRUCTIVE_SIZE", "64"); + defineMacro("__GCC_DESTRUCTIVE_SIZE", "64"); + defineMacro("__GCC_HAVE_DWARF2_CFI_ASM", "1"); + defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1", "1"); + defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16", "1"); + defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2", "1"); + defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4", "1"); + defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8", "1"); + defineMacro("__GNUC_GNU_INLINE__", "1"); + defineMacro("__GNUC_MINOR__", "2"); + defineMacro("__GNUC_PATCHLEVEL__", "1"); + defineMacro("__GNUC__", "4"); + defineMacro("__GNUG__", "4"); + defineMacro("__GXX_ABI_VERSION", "1002"); + defineMacro("__GXX_EXPERIMENTAL_CXX0X__", "1"); + defineMacro("__GXX_RTTI", "1"); + defineMacro("__GXX_WEAK__", "1"); + defineMacro("__INT16_FMTd__", "\"hd\""); + defineMacro("__INT16_FMTi__", "\"hi\""); + defineMacro("__INT16_MAX__", "32767"); + defineMacro("__INT16_TYPE__", "short"); + defineMacro("__INT32_FMTd__", "\"d\""); + defineMacro("__INT32_FMTi__", "\"i\""); + defineMacro("__INT32_MAX__", "2147483647"); + defineMacro("__INT32_TYPE__", "int"); + defineMacro("__INT64_C_SUFFIX__", "LL"); + defineMacro("__INT64_FMTd__", "\"lld\""); + defineMacro("__INT64_FMTi__", "\"lli\""); + defineMacro("__INT64_MAX__", "9223372036854775807LL"); + defineMacro("__INT64_TYPE__", "long long int"); + defineMacro("__INT8_FMTd__", "\"hhd\""); + defineMacro("__INT8_FMTi__", "\"hhi\""); + defineMacro("__INT8_MAX__", "127"); + defineMacro("__INT8_TYPE__", "signed char"); + defineMacro("__INTMAX_C_SUFFIX__", "L"); + defineMacro("__INTMAX_FMTd__", "\"ld\""); + defineMacro("__INTMAX_FMTi__", "\"li\""); + defineMacro("__INTMAX_MAX__", "9223372036854775807L"); + defineMacro("__INTMAX_TYPE__", "long int"); + defineMacro("__INTMAX_WIDTH__", "64"); + defineMacro("__INTPTR_FMTd__", "\"ld\""); + defineMacro("__INTPTR_FMTi__", "\"li\""); + defineMacro("__INTPTR_MAX__", "9223372036854775807L"); + defineMacro("__INTPTR_TYPE__", "long int"); + defineMacro("__INTPTR_WIDTH__", "64"); + defineMacro("__INT_FAST16_FMTd__", "\"hd\""); + defineMacro("__INT_FAST16_FMTi__", "\"hi\""); + defineMacro("__INT_FAST16_MAX__", "32767"); + defineMacro("__INT_FAST16_TYPE__", "short"); + defineMacro("__INT_FAST16_WIDTH__", "16"); + defineMacro("__INT_FAST32_FMTd__", "\"d\""); + defineMacro("__INT_FAST32_FMTi__", "\"i\""); + defineMacro("__INT_FAST32_MAX__", "2147483647"); + defineMacro("__INT_FAST32_TYPE__", "int"); + defineMacro("__INT_FAST32_WIDTH__", "32"); + defineMacro("__INT_FAST64_FMTd__", "\"lld\""); + defineMacro("__INT_FAST64_FMTi__", "\"lli\""); + defineMacro("__INT_FAST64_MAX__", "9223372036854775807LL"); + defineMacro("__INT_FAST64_TYPE__", "long long int"); + defineMacro("__INT_FAST64_WIDTH__", "64"); + defineMacro("__INT_FAST8_FMTd__", "\"hhd\""); + defineMacro("__INT_FAST8_FMTi__", "\"hhi\""); + defineMacro("__INT_FAST8_MAX__", "127"); + defineMacro("__INT_FAST8_TYPE__", "signed char"); + defineMacro("__INT_FAST8_WIDTH__", "8"); + defineMacro("__INT_LEAST16_FMTd__", "\"hd\""); + defineMacro("__INT_LEAST16_FMTi__", "\"hi\""); + defineMacro("__INT_LEAST16_MAX__", "32767"); + defineMacro("__INT_LEAST16_TYPE__", "short"); + defineMacro("__INT_LEAST16_WIDTH__", "16"); + defineMacro("__INT_LEAST32_FMTd__", "\"d\""); + defineMacro("__INT_LEAST32_FMTi__", "\"i\""); + defineMacro("__INT_LEAST32_MAX__", "2147483647"); + defineMacro("__INT_LEAST32_TYPE__", "int"); + defineMacro("__INT_LEAST32_WIDTH__", "32"); + defineMacro("__INT_LEAST64_FMTd__", "\"lld\""); + defineMacro("__INT_LEAST64_FMTi__", "\"lli\""); + defineMacro("__INT_LEAST64_MAX__", "9223372036854775807LL"); + defineMacro("__INT_LEAST64_TYPE__", "long long int"); + defineMacro("__INT_LEAST64_WIDTH__", "64"); + defineMacro("__INT_LEAST8_FMTd__", "\"hhd\""); + defineMacro("__INT_LEAST8_FMTi__", "\"hhi\""); + defineMacro("__INT_LEAST8_MAX__", "127"); + defineMacro("__INT_LEAST8_TYPE__", "signed char"); + defineMacro("__INT_LEAST8_WIDTH__", "8"); + defineMacro("__INT_MAX__", "2147483647"); + defineMacro("__INT_WIDTH__", "32"); defineMacro("__LDBL_DECIMAL_DIG__", "21"); defineMacro("__LDBL_DENORM_MIN__", "3.64519953188247460253e-4951L"); defineMacro("__LDBL_DIG__", "18"); defineMacro("__LDBL_EPSILON__", "1.08420217248550443401e-19L"); + defineMacro("__LDBL_HAS_DENORM__", "1"); + defineMacro("__LDBL_HAS_INFINITY__", "1"); + defineMacro("__LDBL_HAS_QUIET_NAN__", "1"); defineMacro("__LDBL_MANT_DIG__", "64"); defineMacro("__LDBL_MAX_10_EXP__", "4932"); defineMacro("__LDBL_MAX_EXP__", "16384"); @@ -581,12 +351,261 @@ void MacOSToolchain::addAmd64Macros() { defineMacro("__LDBL_MIN_EXP__", "(-16381)"); defineMacro("__LDBL_MIN__", "3.36210314311209350626e-4932L"); defineMacro("__LDBL_NORM_MAX__", "1.18973149535723176502e+4932L"); + defineMacro("__LITTLE_ENDIAN__", "1"); + defineMacro("__LLONG_WIDTH__", "64"); + defineMacro("__LONG_LONG_MAX__", "9223372036854775807LL"); + defineMacro("__LONG_MAX__", "9223372036854775807L"); + defineMacro("__LONG_WIDTH__", "64"); + defineMacro("__LP64__", "1"); + defineMacro("__MACH__", "1"); + defineMacro("__MEMORY_SCOPE_DEVICE", "1"); + defineMacro("__MEMORY_SCOPE_SINGLE", "4"); + defineMacro("__MEMORY_SCOPE_SYSTEM", "0"); + defineMacro("__MEMORY_SCOPE_WRKGRP", "2"); + defineMacro("__MEMORY_SCOPE_WVFRNT", "3"); + defineMacro("__NO_INLINE__", "1"); + defineMacro("__NO_MATH_ERRNO__", "1"); + defineMacro("__OBJC_BOOL_IS_BOOL", "0"); + defineMacro("__OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES", "3"); + defineMacro("__OPENCL_MEMORY_SCOPE_DEVICE", "2"); + defineMacro("__OPENCL_MEMORY_SCOPE_SUB_GROUP", "4"); + defineMacro("__OPENCL_MEMORY_SCOPE_WORK_GROUP", "1"); + defineMacro("__OPENCL_MEMORY_SCOPE_WORK_ITEM", "0"); + defineMacro("__ORDER_BIG_ENDIAN__", "4321"); + defineMacro("__ORDER_LITTLE_ENDIAN__", "1234"); + defineMacro("__ORDER_PDP_ENDIAN__", "3412"); + defineMacro("__PIC__", "2"); + defineMacro("__POINTER_WIDTH__", "64"); + defineMacro("__PRAGMA_REDEFINE_EXTNAME", "1"); + defineMacro("__PTRDIFF_FMTd__", "\"ld\""); + defineMacro("__PTRDIFF_FMTi__", "\"li\""); + defineMacro("__PTRDIFF_MAX__", "9223372036854775807L"); + defineMacro("__PTRDIFF_TYPE__", "long int"); + defineMacro("__PTRDIFF_WIDTH__", "64"); + defineMacro("__SCHAR_MAX__", "127"); + defineMacro("__SHRT_MAX__", "32767"); + defineMacro("__SHRT_WIDTH__", "16"); + defineMacro("__SIG_ATOMIC_MAX__", "2147483647"); + defineMacro("__SIG_ATOMIC_WIDTH__", "32"); + defineMacro("__SIZEOF_DOUBLE__", "8"); + defineMacro("__SIZEOF_FLOAT__", "4"); + defineMacro("__SIZEOF_INT128__", "16"); + defineMacro("__SIZEOF_INT__", "4"); + defineMacro("__SIZEOF_LONG_DOUBLE__", "16"); + defineMacro("__SIZEOF_LONG_LONG__", "8"); + defineMacro("__SIZEOF_LONG__", "8"); + defineMacro("__SIZEOF_POINTER__", "8"); + defineMacro("__SIZEOF_PTRDIFF_T__", "8"); + defineMacro("__SIZEOF_SHORT__", "2"); + defineMacro("__SIZEOF_SIZE_T__", "8"); + defineMacro("__SIZEOF_WCHAR_T__", "4"); + defineMacro("__SIZEOF_WINT_T__", "4"); + defineMacro("__SIZE_FMTX__", "\"lX\""); + defineMacro("__SIZE_FMTo__", "\"lo\""); + defineMacro("__SIZE_FMTu__", "\"lu\""); + defineMacro("__SIZE_FMTx__", "\"lx\""); + defineMacro("__SIZE_MAX__", "18446744073709551615UL"); + defineMacro("__SIZE_TYPE__", "long unsigned int"); + defineMacro("__SIZE_WIDTH__", "64"); + defineMacro("__SSP__", "1"); + defineMacro("__STDCPP_DEFAULT_NEW_ALIGNMENT__", "16UL"); + defineMacro("__STDCPP_THREADS__", "1"); + defineMacro("__STDC_EMBED_EMPTY__", "2"); + defineMacro("__STDC_EMBED_FOUND__", "1"); + defineMacro("__STDC_EMBED_NOT_FOUND__", "0"); + defineMacro("__STDC_HOSTED__", "1"); + defineMacro("__STDC_NO_THREADS__", "1"); + defineMacro("__STDC_UTF_16__", "1"); + defineMacro("__STDC_UTF_32__", "1"); + defineMacro("__STDC__", "1"); + defineMacro("__STRICT_ANSI__", "1"); + defineMacro("__UINT16_FMTX__", "\"hX\""); + defineMacro("__UINT16_FMTo__", "\"ho\""); + defineMacro("__UINT16_FMTu__", "\"hu\""); + defineMacro("__UINT16_FMTx__", "\"hx\""); + defineMacro("__UINT16_MAX__", "65535"); + defineMacro("__UINT16_TYPE__", "unsigned short"); + defineMacro("__UINT32_C_SUFFIX__", "U"); + defineMacro("__UINT32_FMTX__", "\"X\""); + defineMacro("__UINT32_FMTo__", "\"o\""); + defineMacro("__UINT32_FMTu__", "\"u\""); + defineMacro("__UINT32_FMTx__", "\"x\""); + defineMacro("__UINT32_MAX__", "4294967295U"); + defineMacro("__UINT32_TYPE__", "unsigned int"); + defineMacro("__UINT64_C_SUFFIX__", "ULL"); + defineMacro("__UINT64_FMTX__", "\"llX\""); + defineMacro("__UINT64_FMTo__", "\"llo\""); + defineMacro("__UINT64_FMTu__", "\"llu\""); + defineMacro("__UINT64_FMTx__", "\"llx\""); + defineMacro("__UINT64_MAX__", "18446744073709551615ULL"); + defineMacro("__UINT64_TYPE__", "long long unsigned int"); + defineMacro("__UINT8_FMTX__", "\"hhX\""); + defineMacro("__UINT8_FMTo__", "\"hho\""); + defineMacro("__UINT8_FMTu__", "\"hhu\""); + defineMacro("__UINT8_FMTx__", "\"hhx\""); + defineMacro("__UINT8_MAX__", "255"); + defineMacro("__UINT8_TYPE__", "unsigned char"); + defineMacro("__UINTMAX_C_SUFFIX__", "UL"); + defineMacro("__UINTMAX_FMTX__", "\"lX\""); + defineMacro("__UINTMAX_FMTo__", "\"lo\""); + defineMacro("__UINTMAX_FMTu__", "\"lu\""); + defineMacro("__UINTMAX_FMTx__", "\"lx\""); + defineMacro("__UINTMAX_MAX__", "18446744073709551615UL"); + defineMacro("__UINTMAX_TYPE__", "long unsigned int"); + defineMacro("__UINTMAX_WIDTH__", "64"); + defineMacro("__UINTPTR_FMTX__", "\"lX\""); + defineMacro("__UINTPTR_FMTo__", "\"lo\""); + defineMacro("__UINTPTR_FMTu__", "\"lu\""); + defineMacro("__UINTPTR_FMTx__", "\"lx\""); + defineMacro("__UINTPTR_MAX__", "18446744073709551615UL"); + defineMacro("__UINTPTR_TYPE__", "long unsigned int"); + defineMacro("__UINTPTR_WIDTH__", "64"); + defineMacro("__UINT_FAST16_FMTX__", "\"hX\""); + defineMacro("__UINT_FAST16_FMTo__", "\"ho\""); + defineMacro("__UINT_FAST16_FMTu__", "\"hu\""); + defineMacro("__UINT_FAST16_FMTx__", "\"hx\""); + defineMacro("__UINT_FAST16_MAX__", "65535"); + defineMacro("__UINT_FAST16_TYPE__", "unsigned short"); + defineMacro("__UINT_FAST32_FMTX__", "\"X\""); + defineMacro("__UINT_FAST32_FMTo__", "\"o\""); + defineMacro("__UINT_FAST32_FMTu__", "\"u\""); + defineMacro("__UINT_FAST32_FMTx__", "\"x\""); + defineMacro("__UINT_FAST32_MAX__", "4294967295U"); + defineMacro("__UINT_FAST32_TYPE__", "unsigned int"); + defineMacro("__UINT_FAST64_FMTX__", "\"llX\""); + defineMacro("__UINT_FAST64_FMTo__", "\"llo\""); + defineMacro("__UINT_FAST64_FMTu__", "\"llu\""); + defineMacro("__UINT_FAST64_FMTx__", "\"llx\""); + defineMacro("__UINT_FAST64_MAX__", "18446744073709551615ULL"); + defineMacro("__UINT_FAST64_TYPE__", "long long unsigned int"); + defineMacro("__UINT_FAST8_FMTX__", "\"hhX\""); + defineMacro("__UINT_FAST8_FMTo__", "\"hho\""); + defineMacro("__UINT_FAST8_FMTu__", "\"hhu\""); + defineMacro("__UINT_FAST8_FMTx__", "\"hhx\""); + defineMacro("__UINT_FAST8_MAX__", "255"); + defineMacro("__UINT_FAST8_TYPE__", "unsigned char"); + defineMacro("__UINT_LEAST16_FMTX__", "\"hX\""); + defineMacro("__UINT_LEAST16_FMTo__", "\"ho\""); + defineMacro("__UINT_LEAST16_FMTu__", "\"hu\""); + defineMacro("__UINT_LEAST16_FMTx__", "\"hx\""); + defineMacro("__UINT_LEAST16_MAX__", "65535"); + defineMacro("__UINT_LEAST16_TYPE__", "unsigned short"); + defineMacro("__UINT_LEAST32_FMTX__", "\"X\""); + defineMacro("__UINT_LEAST32_FMTo__", "\"o\""); + defineMacro("__UINT_LEAST32_FMTu__", "\"u\""); + defineMacro("__UINT_LEAST32_FMTx__", "\"x\""); + defineMacro("__UINT_LEAST32_MAX__", "4294967295U"); + defineMacro("__UINT_LEAST32_TYPE__", "unsigned int"); + defineMacro("__UINT_LEAST64_FMTX__", "\"llX\""); + defineMacro("__UINT_LEAST64_FMTo__", "\"llo\""); + defineMacro("__UINT_LEAST64_FMTu__", "\"llu\""); + defineMacro("__UINT_LEAST64_FMTx__", "\"llx\""); + defineMacro("__UINT_LEAST64_MAX__", "18446744073709551615ULL"); + defineMacro("__UINT_LEAST64_TYPE__", "long long unsigned int"); + defineMacro("__UINT_LEAST8_FMTX__", "\"hhX\""); + defineMacro("__UINT_LEAST8_FMTo__", "\"hho\""); + defineMacro("__UINT_LEAST8_FMTu__", "\"hhu\""); + defineMacro("__UINT_LEAST8_FMTx__", "\"hhx\""); + defineMacro("__UINT_LEAST8_MAX__", "255"); + defineMacro("__UINT_LEAST8_TYPE__", "unsigned char"); + defineMacro("__USER_LABEL_PREFIX__", "_"); + defineMacro("__VERSION__", "\"Homebrew Clang 19.1.3\""); + defineMacro("__WCHAR_MAX__", "2147483647"); + defineMacro("__WCHAR_TYPE__", "int"); + defineMacro("__WCHAR_WIDTH__", "32"); + defineMacro("__WINT_MAX__", "2147483647"); + defineMacro("__WINT_TYPE__", "int"); + defineMacro("__WINT_WIDTH__", "32"); + defineMacro("__block", "__attribute__((__blocks__(byref)))"); + defineMacro("__clang__", "1"); + defineMacro("__clang_literal_encoding__", "\"UTF-8\""); + defineMacro("__clang_major__", "19"); + defineMacro("__clang_minor__", "1"); + defineMacro("__clang_patchlevel__", "3"); + defineMacro("__clang_version__", "\"19.1.3 \""); + defineMacro("__clang_wide_literal_encoding__", "\"UTF-32\""); + defineMacro("__cpp_aggregate_bases", "201603L"); + defineMacro("__cpp_aggregate_nsdmi", "201304L"); + defineMacro("__cpp_aggregate_paren_init", "201902L"); + defineMacro("__cpp_alias_templates", "200704L"); + defineMacro("__cpp_aligned_new", "201606L"); + defineMacro("__cpp_attributes", "200809L"); + defineMacro("__cpp_binary_literals", "201304L"); + defineMacro("__cpp_capture_star_this", "201603L"); + defineMacro("__cpp_char8_t", "202207L"); + defineMacro("__cpp_concepts", "202002"); + defineMacro("__cpp_conditional_explicit", "201806L"); + defineMacro("__cpp_consteval", "202211L"); + defineMacro("__cpp_constexpr_dynamic_alloc", "201907L"); + defineMacro("__cpp_constexpr_in_decltype", "201711L"); + defineMacro("__cpp_constinit", "201907L"); + defineMacro("__cpp_decltype", "200707L"); + defineMacro("__cpp_decltype_auto", "201304L"); + defineMacro("__cpp_deduction_guides", "201703L"); + defineMacro("__cpp_delegating_constructors", "200604L"); + defineMacro("__cpp_deleted_function", "202403L"); + defineMacro("__cpp_designated_initializers", "201707L"); + defineMacro("__cpp_digit_separators", "201309L"); + defineMacro("__cpp_enumerator_attributes", "201411L"); + defineMacro("__cpp_exceptions", "199711L"); + defineMacro("__cpp_fold_expressions", "201603L"); + defineMacro("__cpp_generic_lambdas", "201707L"); + defineMacro("__cpp_guaranteed_copy_elision", "201606L"); + defineMacro("__cpp_hex_float", "201603L"); + defineMacro("__cpp_if_constexpr", "201606L"); + defineMacro("__cpp_impl_coroutine", "201902L"); + defineMacro("__cpp_impl_destroying_delete", "201806L"); + defineMacro("__cpp_impl_three_way_comparison", "201907L"); + defineMacro("__cpp_inheriting_constructors", "201511L"); + defineMacro("__cpp_init_captures", "201803L"); + defineMacro("__cpp_initializer_lists", "200806L"); + defineMacro("__cpp_inline_variables", "201606L"); + defineMacro("__cpp_lambdas", "200907L"); + defineMacro("__cpp_named_character_escapes", "202207L"); + defineMacro("__cpp_namespace_attributes", "201411L"); + defineMacro("__cpp_nested_namespace_definitions", "201411L"); + defineMacro("__cpp_noexcept_function_type", "201510L"); + defineMacro("__cpp_nontype_template_args", "201411L"); + defineMacro("__cpp_nontype_template_parameter_auto", "201606L"); + defineMacro("__cpp_nsdmi", "200809L"); + defineMacro("__cpp_pack_indexing", "202311L"); + defineMacro("__cpp_placeholder_variables", "202306L"); + defineMacro("__cpp_raw_strings", "200710L"); + defineMacro("__cpp_ref_qualifiers", "200710L"); + defineMacro("__cpp_return_type_deduction", "201304L"); + defineMacro("__cpp_rtti", "199711L"); + defineMacro("__cpp_rvalue_references", "200610L"); + defineMacro("__cpp_sized_deallocation", "201309L"); + defineMacro("__cpp_static_call_operator", "202207L"); + defineMacro("__cpp_structured_bindings", "202403L"); + defineMacro("__cpp_template_auto", "201606L"); + defineMacro("__cpp_template_template_args", "201611L"); + defineMacro("__cpp_threadsafe_static_init", "200806L"); + defineMacro("__cpp_unicode_characters", "200704L"); + defineMacro("__cpp_unicode_literals", "200710L"); + defineMacro("__cpp_user_defined_literals", "200809L"); + defineMacro("__cpp_using_enum", "201907L"); + defineMacro("__cpp_variable_templates", "201304L"); + defineMacro("__cpp_variadic_templates", "200704L"); + defineMacro("__cpp_variadic_using", "201611L"); + defineMacro("__llvm__", "1"); + defineMacro("__nonnull", "_Nonnull"); + defineMacro("__null_unspecified", "_Null_unspecified"); + defineMacro("__nullable", "_Nullable"); + defineMacro("__pic__", "2"); + defineMacro("__private_extern__", "extern"); + defineMacro("__weak", "__attribute__((objc_gc(weak)))"); + // clang-format on +} + +void MacOSToolchain::addAmd64Macros() { + // clang-format off + defineMacro("__FXSR__", "1"); + defineMacro("__LAHF_SAHF__", "1"); defineMacro("__MMX__", "1"); defineMacro("__NO_MATH_INLINES", "1"); - defineMacro("__OBJC_BOOL_IS_BOOL", "0"); defineMacro("__SEG_FS", "1"); defineMacro("__SEG_GS", "1"); - defineMacro("__SIZEOF_LONG_DOUBLE__", "16"); defineMacro("__SSE2_MATH__", "1"); defineMacro("__SSE2__", "1"); defineMacro("__SSE3__", "1"); @@ -604,9 +623,11 @@ void MacOSToolchain::addAmd64Macros() { defineMacro("__tune_core2__", "1"); defineMacro("__x86_64", "1"); defineMacro("__x86_64__", "1"); + // clang-format on } void MacOSToolchain::addArm64Macros() { + // clang-format off defineMacro("__AARCH64EL__", "1"); defineMacro("__AARCH64_CMODEL_SMALL__", "1"); defineMacro("__AARCH64_SIMD__", "1"); @@ -652,30 +673,13 @@ void MacOSToolchain::addArm64Macros() { defineMacro("__ARM_SIZEOF_WCHAR_T", "4"); defineMacro("__ARM_STATE_ZA", "1"); defineMacro("__ARM_STATE_ZT0", "1"); - defineMacro("__BIGGEST_ALIGNMENT__", "8"); - defineMacro("__BITINT_MAXWIDTH__", "128"); defineMacro("__FP_FAST_FMA", "1"); defineMacro("__FP_FAST_FMAF", "1"); defineMacro("__HAVE_FUNCTION_MULTI_VERSIONING", "1"); - defineMacro("__LDBL_DECIMAL_DIG__", "17"); - defineMacro("__LDBL_DENORM_MIN__", "4.9406564584124654e-324L"); - defineMacro("__LDBL_DIG__", "15"); - defineMacro("__LDBL_EPSILON__", "2.2204460492503131e-16L"); - defineMacro("__LDBL_MANT_DIG__", "53"); - defineMacro("__LDBL_MAX_10_EXP__", "308"); - defineMacro("__LDBL_MAX_EXP__", "1024"); - defineMacro("__LDBL_MAX__", "1.7976931348623157e+308L"); - defineMacro("__LDBL_MIN_10_EXP__", "(-307)"); - defineMacro("__LDBL_MIN_EXP__", "(-1021)"); - defineMacro("__LDBL_MIN__", "2.2250738585072014e-308L"); - defineMacro("__LDBL_NORM_MAX__", "1.7976931348623157e+308L"); - defineMacro("__OBJC_BOOL_IS_BOOL", "1"); - defineMacro("__SIZEOF_LONG_DOUBLE__", "8"); defineMacro("__aarch64__", "1"); defineMacro("__arm64", "1"); defineMacro("__arm64__", "1"); + // clang-format on } -// clang-format on - } // namespace cxx diff --git a/src/parser/cxx/macos_toolchain.h b/src/parser/cxx/macos_toolchain.h index 809cc80d..721309b7 100644 --- a/src/parser/cxx/macos_toolchain.h +++ b/src/parser/cxx/macos_toolchain.h @@ -40,6 +40,8 @@ class MacOSToolchain final : public Toolchain { void addPredefinedMacros() override; void addCommonMacros(); + void addCxx20Macros(); + void addCxx23Macros(); void addCxx26Macros(); void addArm64Macros(); void addAmd64Macros(); From 3ba6b5b895a34a7935db58097db9567eb01be636 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Fri, 8 Nov 2024 20:29:36 +0100 Subject: [PATCH 3/5] feat: Add PP_INTERNAL_VARIABLE to track header dependencies Signed-off-by: Roberto Raggi --- packages/cxx-frontend/src/TokenKind.ts | 1 + packages/cxx-gen-ast/src/tokens.ts | 1 + src/parser/cxx/preprocessor.cc | 41 ++++++++++++++++++++++++-- src/parser/cxx/token_fwd.h | 3 +- 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/packages/cxx-frontend/src/TokenKind.ts b/packages/cxx-frontend/src/TokenKind.ts index ceb8e3d7..02e8ec15 100644 --- a/packages/cxx-frontend/src/TokenKind.ts +++ b/packages/cxx-frontend/src/TokenKind.ts @@ -32,6 +32,7 @@ export enum TokenKind { UTF32_STRING_LITERAL, UTF8_STRING_LITERAL, WIDE_STRING_LITERAL, + PP_INTERNAL_VARIABLE, AMP_AMP, AMP_EQUAL, AMP, diff --git a/packages/cxx-gen-ast/src/tokens.ts b/packages/cxx-gen-ast/src/tokens.ts index 122561f2..51e3c1b0 100644 --- a/packages/cxx-gen-ast/src/tokens.ts +++ b/packages/cxx-gen-ast/src/tokens.ts @@ -32,6 +32,7 @@ export const BASE_TOKENS: string[] = [ "UTF32_STRING_LITERAL", "UTF8_STRING_LITERAL", "WIDE_STRING_LITERAL", + "PP_INTERNAL_VARIABLE", ]; export const OPERATORS: Array<[kind: string, spelling: string]> = [ diff --git a/src/parser/cxx/preprocessor.cc b/src/parser/cxx/preprocessor.cc index cb9ff3dc..08612abb 100644 --- a/src/parser/cxx/preprocessor.cc +++ b/src/parser/cxx/preprocessor.cc @@ -731,6 +731,15 @@ struct Preprocessor::Private { std::function readFile_; std::function willIncludeHeader_; std::vector buffers_; + struct Dep { + std::string_view local; + Include include; + bool isIncludeNext = false; + int value = 0; + }; + std::vector dependencies_; + int localCount_ = 0; + int counter_ = 0; int includeDepth_ = 0; bool omitLineMarkers_ = false; @@ -1379,6 +1388,15 @@ void Preprocessor::Private::initialize() { return cons(tk, ts); }; + auto replaceWithLocal = [this](const Tok *token, std::string_view local, + TokList *ts) { + auto tk = gen(TokenKind::T_PP_INTERNAL_VARIABLE, local); + tk->sourceFile = token->sourceFile; + tk->space = token->space; + tk->bol = token->bol; + return cons(tk, ts); + }; + adddBuiltinFunctionMacro( "__has_feature", [this, replaceWithBoolLiteral]( @@ -1435,7 +1453,7 @@ void Preprocessor::Private::initialize() { return replaceWithBoolLiteral(macroId, enabled, ts); }); - auto hasInclude = [this, replaceWithBoolLiteral]( + auto hasInclude = [this, replaceWithLocal, replaceWithBoolLiteral]( const MacroExpansionContext &context) -> TokList * { auto ts = context.ts; @@ -1478,9 +1496,11 @@ void Preprocessor::Private::initialize() { include = SystemInclude(std::move(fn)); } - const auto value = resolve(include, isIncludeNext); + std::string_view local = string(std::format("@{}", localCount_++)); + + dependencies_.push_back({local, include, isIncludeNext}); - return replaceWithBoolLiteral(macroName, value.has_value(), rest); + return replaceWithLocal(macroName, local, rest); }; adddBuiltinFunctionMacro("__has_include", hasInclude); @@ -1710,6 +1730,8 @@ auto Preprocessor::Private::parseDirective(SourceFile *source, TokList *start) if (!lookat(directive, TokenKind::T_IDENTIFIER)) return std::nullopt; + dependencies_.clear(); + const auto directiveKind = classifyDirective(directive->tok->text.data(), directive->tok->text.length()); @@ -2344,8 +2366,14 @@ auto Preprocessor::Private::copyLine(TokList *ts, bool inMacroBody) auto Preprocessor::Private::constantExpression(TokList *ts) -> long { auto line = copyLine(ts); + dependencies_.clear(); auto it = expandTokens(TokIterator{line}, TokIterator{}, /*inConditionalExpression*/ true); + // evaluate the deps + for (auto &d : dependencies_) { + auto resolved = resolve(d.include, d.isIncludeNext); + d.value = resolved.has_value(); + } auto e = it.toTokList(); return conditionalExpression(e); } @@ -2527,6 +2555,13 @@ auto Preprocessor::Private::primaryExpression(TokList *&ts) -> long { auto result = conditionalExpression(ts); expect(ts, TokenKind::T_RPAREN); return result; + } else if (tk->is(TokenKind::T_PP_INTERNAL_VARIABLE)) { + for (const auto &dep : dependencies_) { + if (dep.local == tk->text) { + ts = ts->next; + return dep.value; + } + } } ts = ts->next; diff --git a/src/parser/cxx/token_fwd.h b/src/parser/cxx/token_fwd.h index 50a054f6..e06bad54 100644 --- a/src/parser/cxx/token_fwd.h +++ b/src/parser/cxx/token_fwd.h @@ -42,7 +42,8 @@ class Token; V(UTF16_STRING_LITERAL, "") \ V(UTF32_STRING_LITERAL, "") \ V(UTF8_STRING_LITERAL, "") \ - V(WIDE_STRING_LITERAL, "") + V(WIDE_STRING_LITERAL, "") \ + V(PP_INTERNAL_VARIABLE, "") #define FOR_EACH_OPERATOR(V) \ V(AMP_AMP, "&&") \ From b40137a9cb5c05f79d2b0f4bdc08de6632044cde Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Fri, 8 Nov 2024 20:29:36 +0100 Subject: [PATCH 4/5] chore: Expose QuotedInclude and SystemInclude --- src/parser/cxx/macos_toolchain.cc | 1 - src/parser/cxx/preprocessor.cc | 129 ++++++++++++++---------------- src/parser/cxx/preprocessor.h | 30 ++++++- 3 files changed, 88 insertions(+), 72 deletions(-) diff --git a/src/parser/cxx/macos_toolchain.cc b/src/parser/cxx/macos_toolchain.cc index fa53bac1..a9c4b741 100644 --- a/src/parser/cxx/macos_toolchain.cc +++ b/src/parser/cxx/macos_toolchain.cc @@ -155,7 +155,6 @@ void MacOSToolchain::addCommonMacros() { defineMacro("__ATOMIC_SEQ_CST", "5"); defineMacro("__BIGGEST_ALIGNMENT__", "16"); defineMacro("__BITINT_MAXWIDTH__", "8388608"); - defineMacro("__BLOCKS__", "1"); defineMacro("__BOOL_WIDTH__", "8"); defineMacro("__BYTE_ORDER__", "__ORDER_LITTLE_ENDIAN__"); defineMacro("__CHAR16_TYPE__", "unsigned short"); diff --git a/src/parser/cxx/preprocessor.cc b/src/parser/cxx/preprocessor.cc index 08612abb..f162698f 100644 --- a/src/parser/cxx/preprocessor.cc +++ b/src/parser/cxx/preprocessor.cc @@ -219,26 +219,7 @@ class Hideset { std::set names_; }; -struct SystemInclude { - std::string fileName; - - SystemInclude() = default; - - explicit SystemInclude(std::string fileName) - : fileName(std::move(fileName)) {} -}; - -struct QuoteInclude { - std::string fileName; - - QuoteInclude() = default; - - explicit QuoteInclude(std::string fileName) : fileName(std::move(fileName)) {} -}; - -using Include = std::variant; - -inline auto getHeaderName(const Include &include) -> std::string { +inline auto getHeaderName(const cxx::Include &include) -> std::string { return std::visit([](const auto &include) { return include.fileName; }, include); } @@ -1053,7 +1034,7 @@ struct Preprocessor::Private { Resolve(const Private *d, bool next) : d(d), wantNextInlude(next) {} [[nodiscard]] auto search(auto view, const std::string &headerName) - -> std::optional { + -> std::optional { auto transformToIncludePath = std::views::transform( [&](const fs::path &path) { return path / headerName; }); @@ -1073,14 +1054,14 @@ struct Preprocessor::Private { continue; } - return path; + return path.string(); } return std::nullopt; } [[nodiscard]] auto operator()(const QuoteInclude &include) - -> std::optional { + -> std::optional { const auto &headerName = include.fileName; // search in the current path @@ -1099,20 +1080,20 @@ struct Preprocessor::Private { } if (wantNextInlude && !didFindCurrentPath) { - return firstMatch; + return firstMatch->string(); } return std::nullopt; } [[nodiscard]] auto operator()(const SystemInclude &include) - -> std::optional { + -> std::optional { if (auto p = search(d->systemIncludePaths_, include.fileName)) { return p; } if (wantNextInlude && !didFindCurrentPath) { - return firstMatch; + return firstMatch->string(); } return std::nullopt; @@ -1120,7 +1101,7 @@ struct Preprocessor::Private { }; [[nodiscard]] auto resolve(const Include &include, bool next) const - -> std::optional { + -> std::optional { if (!canResolveFiles_) return std::nullopt; return std::visit(Resolve{this, next}, include); @@ -1192,8 +1173,11 @@ struct Preprocessor::Private { [[nodiscard]] auto parseIncludeDirective(TokList *directive, TokList *ts) -> std::optional; - [[nodiscard]] auto resolveIncludeDirective( - const ParsedIncludeDirective &directive) -> SourceFile *; + [[nodiscard]] auto findOrCreateSourceFile(const Include &include, + bool isIncludeNext) -> SourceFile *; + + [[nodiscard]] auto findOrCreateSourceFile(const std::string &fileName) + -> SourceFile *; [[nodiscard]] auto parseHeaderName(TokList *ts) -> std::tuple>; @@ -1691,9 +1675,7 @@ auto Preprocessor::Private::expand( if (auto parsedInclude = parseDirective(source, start.toTokList())) { NeedToResolveInclude status{ .preprocessor = *preprocessor_, - .fileName = getHeaderName(parsedInclude->header), - .isQuoted = - std::holds_alternative(parsedInclude->header), + .include = parsedInclude->header, .isIncludeNext = parsedInclude->includeNext, .loc = parsedInclude->loc, }; @@ -1946,31 +1928,33 @@ auto Preprocessor::Private::parseIncludeDirective(TokList *directive, return std::nullopt; } -auto Preprocessor::Private::resolveIncludeDirective( - const ParsedIncludeDirective &directive) -> SourceFile * { - const auto path = resolve(directive.header, directive.includeNext); - - if (!path) { - const auto file = getHeaderName(directive.header); - error(directive.loc, std::format("file '{}' not found", file)); - return nullptr; +auto Preprocessor::Private::findOrCreateSourceFile(const Include &include, + bool isIncludeNext) + -> SourceFile * { + if (auto path = resolve(include, isIncludeNext)) { + auto sourceFile = findOrCreateSourceFile(path.value()); + return sourceFile; } - std::string currentFileName = path->string(); + return nullptr; +} - if (auto it = ifndefProtectedFiles_.find(currentFileName); +auto Preprocessor::Private::findOrCreateSourceFile(const std::string &fileName) + -> SourceFile * { + if (auto it = ifndefProtectedFiles_.find(fileName); it != ifndefProtectedFiles_.end() && macros_.contains(it->second)) { return nullptr; } - auto sourceFile = findSourceFile(currentFileName); + auto sourceFile = findSourceFile(fileName); if (sourceFile && sourceFile->pragmaOnceProtected) { + // nothing to do return nullptr; } if (!sourceFile) { - sourceFile = createSourceFile(path->string(), readFile(*path)); + sourceFile = createSourceFile(fileName, readFile(fileName)); sourceFile->pragmaOnceProtected = checkPragmaOnceProtected(sourceFile->tokens); @@ -1986,7 +1970,7 @@ auto Preprocessor::Private::resolveIncludeDirective( } if (willIncludeHeader_) { - willIncludeHeader_(currentFileName, includeDepth_ + 1); + willIncludeHeader_(fileName, includeDepth_ + 1); } return sourceFile; @@ -2879,34 +2863,19 @@ void Preprocessor::preprocess(std::string source, std::string fileName, } void operator()(const NeedToResolveInclude &status) { - // the header file resolution may be asynchronous - Include header; + auto d = self.d.get(); - if (status.isQuoted) { - header = QuoteInclude(status.fileName); - } else { - header = SystemInclude(status.fileName); + if (auto resolvedInclude = + d->resolve(status.include, status.isIncludeNext)) { + status.continueWith(resolvedInclude.value()); + return; } - Private::ParsedIncludeDirective parsedInclude{ - .header = header, - .includeNext = status.isIncludeNext, - .loc = static_cast(const_cast(status.loc)), - }; - - auto continuation = self.d->resolveIncludeDirective(parsedInclude); - if (!continuation) return; + auto loc = static_cast(status.loc); - // make the continuation the current file - fs::path dirpath = fs::path(continuation->fileName); - dirpath.remove_filename(); + const auto file = getHeaderName(status.include); - self.d->buffers_.push_back(Private::Buffer{ - .source = continuation, - .currentPath = dirpath, - .ts = continuation->tokens, - .includeDepth = self.d->includeDepth_ + 1, - }); + d->error(loc, std::format("file '{}' not found", file)); } void operator()(const NeedToKnowIfFileExists &status) { @@ -2929,6 +2898,25 @@ void Preprocessor::preprocess(std::string source, std::string fileName, endPreprocessing(tokens); } +void Preprocessor::NeedToResolveInclude::continueWith( + std::string fileName) const { + auto d = preprocessor.d.get(); + + auto continuation = d->findOrCreateSourceFile(fileName); + if (!continuation) return; + + // make the continuation the current file + fs::path dirpath = fs::path(continuation->fileName); + dirpath.remove_filename(); + + d->buffers_.push_back(Private::Buffer{ + .source = continuation, + .currentPath = dirpath, + .ts = continuation->tokens, + .includeDepth = d->includeDepth_ + 1, + }); +} + void Preprocessor::NeedToKnowIfFileExists::setFileExists(bool exists) const {} void Preprocessor::NeedToReadFile::setContents(std::string contents) const {} @@ -3165,4 +3153,9 @@ auto Preprocessor::getTokenText(const Token &token) const -> std::string_view { return source.substr(token.offset(), token.length()); } +auto Preprocessor::resolve(const Include &include, bool isIncludeNext) const + -> std::optional { + return d->resolve(include, isIncludeNext); +} + } // namespace cxx diff --git a/src/parser/cxx/preprocessor.h b/src/parser/cxx/preprocessor.h index a0533e0b..c1890c6e 100644 --- a/src/parser/cxx/preprocessor.h +++ b/src/parser/cxx/preprocessor.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -39,6 +40,25 @@ class Preprocessor; class PreprocessorDelegate; class SourcePosition; +struct SystemInclude { + std::string fileName; + + SystemInclude() = default; + + explicit SystemInclude(std::string fileName) + : fileName(std::move(fileName)) {} +}; + +struct QuoteInclude { + std::string fileName; + + QuoteInclude() = default; + + explicit QuoteInclude(std::string fileName) : fileName(std::move(fileName)) {} +}; + +using Include = std::variant; + class CommentHandler { public: virtual ~CommentHandler() = default; @@ -90,10 +110,11 @@ class Preprocessor { struct NeedToResolveInclude { Preprocessor &preprocessor; - std::string fileName; - bool isQuoted = false; + Include include; bool isIncludeNext = false; - const void *loc = nullptr; + void *loc = nullptr; + + void continueWith(std::string fileName) const; }; struct NeedToKnowIfFileExists { @@ -151,6 +172,9 @@ class Preprocessor { [[nodiscard]] auto getTokenText(const Token &token) const -> std::string_view; + [[nodiscard]] auto resolve(const Include &include, bool isIncludeNext) const + -> std::optional; + void squeeze(); private: From 7dbe6819e6cc915b55431ea15e5889b9ac27dfed Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Fri, 8 Nov 2024 21:04:38 +0100 Subject: [PATCH 5/5] chore: Fix typo --- src/frontend/cxx/frontend.cc | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/frontend/cxx/frontend.cc b/src/frontend/cxx/frontend.cc index c4ef4ca3..d8f2d981 100644 --- a/src/frontend/cxx/frontend.cc +++ b/src/frontend/cxx/frontend.cc @@ -101,13 +101,13 @@ auto runOnFile(const CLI& cli, const std::string& fileName) -> bool { VerifyDiagnosticsClient diagnosticsClient; TranslationUnit unit(&diagnosticsClient); - auto preprocesor = unit.preprocessor(); + auto preprocessor = unit.preprocessor(); std::unique_ptr toolchain; if (cli.opt_verify) { diagnosticsClient.setVerify(true); - preprocesor->setCommentHandler(&diagnosticsClient); + preprocessor->setCommentHandler(&diagnosticsClient); } auto toolchainId = cli.getSingle("-toolchain"); @@ -117,7 +117,7 @@ auto runOnFile(const CLI& cli, const std::string& fileName) -> bool { } if (toolchainId == "darwin" || toolchainId == "macos") { - auto macosToolchain = std::make_unique(preprocesor); + auto macosToolchain = std::make_unique(preprocessor); std::string host; #ifdef __aarch64__ host = "aarch64"; @@ -128,7 +128,7 @@ auto runOnFile(const CLI& cli, const std::string& fileName) -> bool { toolchain = std::move(macosToolchain); } else if (toolchainId == "wasm32") { - auto wasmToolchain = std::make_unique(preprocesor); + auto wasmToolchain = std::make_unique(preprocessor); fs::path app_dir; @@ -162,9 +162,9 @@ auto runOnFile(const CLI& cli, const std::string& fileName) -> bool { #endif std::string arch = cli.getSingle("-arch").value_or(host); - toolchain = std::make_unique(preprocesor, arch); + toolchain = std::make_unique(preprocessor, arch); } else if (toolchainId == "windows") { - auto windowsToolchain = std::make_unique(preprocesor); + auto windowsToolchain = std::make_unique(preprocessor); if (auto paths = cli.get("-vctoolsdir"); !paths.empty()) { windowsToolchain->setVctoolsdir(paths.back()); @@ -192,12 +192,12 @@ auto runOnFile(const CLI& cli, const std::string& fileName) -> bool { } for (const auto& path : cli.get("-I")) { - preprocesor->addSystemIncludePath(path); + preprocessor->addSystemIncludePath(path); } if (cli.opt_v) { std::cerr << std::format("#include <...> search starts here:\n"); - const auto& paths = preprocesor->systemIncludePaths(); + const auto& paths = preprocessor->systemIncludePaths(); for (auto it = rbegin(paths); it != rend(paths); ++it) { std::cerr << std::format(" {}\n", *it); } @@ -208,14 +208,14 @@ auto runOnFile(const CLI& cli, const std::string& fileName) -> bool { auto sep = macro.find_first_of("="); if (sep == std::string::npos) { - preprocesor->defineMacro(macro, "1"); + preprocessor->defineMacro(macro, "1"); } else { - preprocesor->defineMacro(macro.substr(0, sep), macro.substr(sep + 1)); + preprocessor->defineMacro(macro.substr(0, sep), macro.substr(sep + 1)); } } for (const auto& macro : cli.get("-U")) { - preprocesor->undefMacro(macro); + preprocessor->undefMacro(macro); } auto outputs = cli.get("-o"); @@ -229,11 +229,11 @@ auto runOnFile(const CLI& cli, const std::string& fileName) -> bool { bool shouldExit = false; if (cli.opt_P) { - preprocesor->setOmitLineMarkers(true); + preprocessor->setOmitLineMarkers(true); } if (cli.opt_H && (cli.opt_E || cli.opt_Eonly)) { - preprocesor->setOnWillIncludeHeader( + preprocessor->setOnWillIncludeHeader( [&](const std::string& header, int level) { std::string fill(level, '.'); std::cout << std::format("{} {}\n", fill, header); @@ -243,14 +243,14 @@ auto runOnFile(const CLI& cli, const std::string& fileName) -> bool { if (auto source = readAll(fileName)) { if (cli.opt_E && !cli.opt_dM) { std::vector tokens; - preprocesor->preprocess(std::move(*source), fileName, tokens); - preprocesor->getPreprocessedText(tokens, output); + preprocessor->preprocess(std::move(*source), fileName, tokens); + preprocessor->getPreprocessedText(tokens, output); shouldExit = true; } else { unit.setSource(std::move(*source), fileName); if (cli.opt_dM) { - preprocesor->printMacros(output); + preprocessor->printMacros(output); shouldExit = true; } else if (cli.opt_dump_tokens) { dumpTokens(cli, unit, output); @@ -266,7 +266,7 @@ auto runOnFile(const CLI& cli, const std::string& fileName) -> bool { } if (!shouldExit) { - preprocesor->squeeze(); + preprocessor->squeeze(); unit.parse(ParserConfiguration{ .checkTypes = cli.opt_fcheck,