From 437b9fe20421245bd7905460683644fc6604ff49 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 4 Jan 2022 13:26:43 -0500 Subject: [PATCH] LibUnicode: Convert UnicodeData to link with weak symbols --- .../LibUnicode/GenerateUnicodeData.cpp | 13 ++- .../Libraries/LibUnicode/CharacterTypes.cpp | 80 ++++--------------- .../Libraries/LibUnicode/CharacterTypes.h | 7 +- 3 files changed, 25 insertions(+), 75 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeData.cpp b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeData.cpp index 53cc9fb2e1..c8b2865582 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeData.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeData.cpp @@ -625,9 +625,10 @@ static void generate_unicode_data_implementation(Core::File& file, UnicodeData c #include #include #include +#include #include -namespace Unicode::Detail { +namespace Unicode { )~~~"); auto append_list_and_size = [&](auto const& list, StringView format) { @@ -851,7 +852,6 @@ static constexpr Array s_code_po )~~~"); generator.append(R"~~~( -Optional code_point_display_name(u32 code_point) asm("unicode_code_point_display_name"); Optional code_point_display_name(u32 code_point) { if (auto const* entry = binary_search(s_code_point_display_names, code_point, nullptr, CodePointNameComparator {})) { @@ -870,7 +870,6 @@ Optional code_point_display_name(u32 code_point) generator.set("mappings", mappings); generator.set("fallback", fallback); generator.append(R"~~~( -u32 @method@(u32 code_point) asm("unicode_@method@"); u32 @method@(u32 code_point) { auto const* mapping = binary_search(@mappings@, code_point, nullptr, CodePointComparator {}); @@ -880,11 +879,10 @@ u32 @method@(u32 code_point) }; append_code_point_mapping_search("canonical_combining_class"sv, "s_combining_class_mappings"sv, "0"sv); - append_code_point_mapping_search("simple_uppercase_mapping"sv, "s_uppercase_mappings"sv, "code_point"sv); - append_code_point_mapping_search("simple_lowercase_mapping"sv, "s_lowercase_mappings"sv, "code_point"sv); + append_code_point_mapping_search("to_unicode_uppercase"sv, "s_uppercase_mappings"sv, "code_point"sv); + append_code_point_mapping_search("to_unicode_lowercase"sv, "s_lowercase_mappings"sv, "code_point"sv); generator.append(R"~~~( -Span special_case_mapping(u32 code_point) asm("unicode_special_case_mapping"); Span special_case_mapping(u32 code_point) { auto const* mapping = binary_search(s_special_case_mappings, code_point, nullptr, CodePointComparator {}); @@ -900,7 +898,6 @@ Span special_case_mapping(u32 code_point) generator.set("enum_snake", enum_snake); generator.set("collection_name", collection_name); generator.append(R"~~~( -bool code_point_has_@enum_snake@(u32 code_point, @enum_title@ @enum_snake@) asm("unicode_code_point_has_@enum_snake@"); bool code_point_has_@enum_snake@(u32 code_point, @enum_title@ @enum_snake@) { auto index = static_cast<@enum_title@UnderlyingType>(@enum_snake@); @@ -921,7 +918,7 @@ bool code_point_has_@enum_snake@(u32 code_point, @enum_title@ @enum_snake@) for (auto const& alias : aliases) hashes.set(alias.alias.hash(), alias.alias); - generate_value_from_string_for_dynamic_loading(generator, "{}_from_string"sv, enum_title, enum_snake, move(hashes)); + generate_value_from_string(generator, "{}_from_string"sv, enum_title, enum_snake, move(hashes)); }; append_prop_search("GeneralCategory"sv, "general_category"sv, "s_general_categories"sv); diff --git a/Userland/Libraries/LibUnicode/CharacterTypes.cpp b/Userland/Libraries/LibUnicode/CharacterTypes.cpp index c394650e2c..901d7f606a 100644 --- a/Userland/Libraries/LibUnicode/CharacterTypes.cpp +++ b/Userland/Libraries/LibUnicode/CharacterTypes.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #if ENABLE_UNICODE_DATA # include @@ -22,20 +21,12 @@ namespace Unicode { +Optional __attribute__((weak)) code_point_display_name(u32) { return {}; } +u32 __attribute__((weak)) canonical_combining_class(u32) { return {}; } +Span __attribute__((weak)) special_case_mapping(u32) { return {}; } + #if ENABLE_UNICODE_DATA -static u32 canonical_combining_class(u32 code_point) -{ - static auto const& symbols = Detail::Symbols::ensure_loaded(); - return symbols.canonical_combining_class(code_point); -} - -static Span special_case_mapping(u32 code_point) -{ - static auto const& symbols = Detail::Symbols::ensure_loaded(); - return symbols.special_case_mapping(code_point); -} - static bool is_after_uppercase_i(Utf8View const& string, size_t index) { // There is an uppercase I before C, and there is no intervening combining character class 230 (Above) or 0. @@ -217,22 +208,14 @@ static SpecialCasing const* find_matching_special_case(u32 code_point, Utf8View #endif -u32 to_unicode_lowercase(u32 code_point) +u32 __attribute__((weak)) to_unicode_lowercase(u32 code_point) { - static auto const& symbols = Detail::Symbols::ensure_loaded(); - return symbols.simple_lowercase_mapping(code_point); + return to_ascii_lowercase(code_point); } -u32 to_unicode_uppercase(u32 code_point) +u32 __attribute__((weak)) to_unicode_uppercase(u32 code_point) { - static auto const& symbols = Detail::Symbols::ensure_loaded(); - return symbols.simple_uppercase_mapping(code_point); -} - -Optional code_point_display_name(u32 code_point) -{ - static auto const& symbols = Detail::Symbols::ensure_loaded(); - return symbols.code_point_display_name(code_point); + return to_ascii_uppercase(code_point); } String to_unicode_lowercase_full(StringView string, [[maybe_unused]] Optional locale) @@ -293,29 +276,10 @@ String to_unicode_uppercase_full(StringView string, [[maybe_unused]] Optional general_category_from_string(StringView general_category) -{ - static auto const& symbols = Detail::Symbols::ensure_loaded(); - return symbols.general_category_from_string(general_category); -} - -bool code_point_has_general_category(u32 code_point, GeneralCategory general_category) -{ - static auto const& symbols = Detail::Symbols::ensure_loaded(); - return symbols.code_point_has_general_category(code_point, general_category); -} - -Optional property_from_string(StringView property) -{ - static auto const& symbols = Detail::Symbols::ensure_loaded(); - return symbols.property_from_string(property); -} - -bool code_point_has_property(u32 code_point, Property property) -{ - static auto const& symbols = Detail::Symbols::ensure_loaded(); - return symbols.code_point_has_property(code_point, property); -} +Optional __attribute__((weak)) general_category_from_string(StringView) { return {}; } +bool __attribute__((weak)) code_point_has_general_category(u32, GeneralCategory) { return {}; } +Optional __attribute__((weak)) property_from_string(StringView) { return {}; } +bool __attribute__((weak)) code_point_has_property(u32, Property) { return {}; } bool is_ecma262_property([[maybe_unused]] Property property) { @@ -384,22 +348,8 @@ bool is_ecma262_property([[maybe_unused]] Property property) #endif } -Optional