summaryrefslogtreecommitdiff
path: root/Meta/Lagom
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-01-10 16:34:55 -0500
committerLinus Groh <mail@linusgroh.de>2022-01-11 00:36:45 +0100
commitb543c3e490851cf44df45acfb6036b5a56b0ebcc (patch)
tree30b6f46973c2c542e208ef9053aaba0ba800f7ac /Meta/Lagom
parent6da1bfeeea3a3a5987e6c9228c5a9500bdce64b8 (diff)
downloadserenity-b543c3e490851cf44df45acfb6036b5a56b0ebcc.zip
Meta: Don't assume how each generator wants to generate keyed map names
The generate_mapping helper generates a series of structs like: Array<SomeType, 1> s_mapping_key_0 {}; Array<SomeType, 2> s_mapping_key_1 {}; Array<SomeType, 3> s_mapping_key_2 {}; Array<Span<SomeType const>> s_mapping { { s_mapping_key_0.span(), s_mapping_key_1.span(), s_mapping_key_2.span(), } }; Where the names of the struct were generated by the format_mapping_name lambda inside the helper. Rather than this lambda making assumptions on how each generator wants to name its structs, add a parameter for the caller to provide a naming formatter. This is because the TimeZoneData generator will want pretty specific identifier formatting rules.
Diffstat (limited to 'Meta/Lagom')
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp2
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeNumberFormat.cpp4
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h16
3 files changed, 14 insertions, 8 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp
index f203d411f3..2d0bb1faf3 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp
@@ -1814,7 +1814,7 @@ static constexpr Array<@type@, @size@> @name@ { {)~~~");
auto locales = locale_data.locales.keys();
quick_sort(locales);
- generate_mapping(generator, locale_data.locales, s_calendar_index_type, "s_locale_calendars"sv, "s_calendars_{}", [&](auto const& name, auto const& value) { append_calendars(name, value.calendars); });
+ generate_mapping(generator, locale_data.locales, s_calendar_index_type, "s_locale_calendars"sv, "s_calendars_{}", format_identifier, [&](auto const& name, auto const& value) { append_calendars(name, value.calendars); });
append_mapping(locales, locale_data.locales, s_time_zone_index_type, "s_locale_time_zones"sv, [](auto const& locale) { return locale.time_zones; });
append_mapping(locales, locale_data.locales, s_time_zone_format_index_type, "s_locale_time_zone_formats"sv, [](auto const& locale) { return locale.time_zone_formats; });
append_mapping(locales, locale_data.locales, s_day_period_index_type, "s_locale_day_periods"sv, [](auto const& locale) { return locale.day_periods; });
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeNumberFormat.cpp b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeNumberFormat.cpp
index 0b379a8fba..f3973463c3 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeNumberFormat.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeNumberFormat.cpp
@@ -827,8 +827,8 @@ static constexpr Array<@type@, @size@> @name@ { {)~~~");
generator.append(" } };");
};
- generate_mapping(generator, locale_data.locales, s_number_system_index_type, "s_locale_number_systems"sv, "s_number_systems_{}", [&](auto const& name, auto const& value) { append_map(name, s_number_system_index_type, value.number_systems); });
- generate_mapping(generator, locale_data.locales, s_unit_index_type, "s_locale_units"sv, "s_units_{}", [&](auto const& name, auto const& value) { append_map(name, s_unit_index_type, value.units); });
+ generate_mapping(generator, locale_data.locales, s_number_system_index_type, "s_locale_number_systems"sv, "s_number_systems_{}", nullptr, [&](auto const& name, auto const& value) { append_map(name, s_number_system_index_type, value.number_systems); });
+ generate_mapping(generator, locale_data.locales, s_unit_index_type, "s_locale_units"sv, "s_units_{}", nullptr, [&](auto const& name, auto const& value) { append_map(name, s_unit_index_type, value.units); });
generator.append(R"~~~(
static NumberSystem const* find_number_system(StringView locale, StringView system)
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h
index ead34e0c4b..f2ec07ce86 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h
+++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h
@@ -399,12 +399,18 @@ enum class @name@ : @underlying@ {)~~~");
)~~~");
}
-template<typename LocalesType, typename ListFormatter>
-void generate_mapping(SourceGenerator& generator, LocalesType const& locales, StringView type, StringView name, StringView format, ListFormatter&& format_list)
+template<typename LocalesType, typename IdentifierFormatter, typename ListFormatter>
+void generate_mapping(SourceGenerator& generator, LocalesType const& locales, StringView type, StringView name, StringView format, IdentifierFormatter&& format_identifier, ListFormatter&& format_list)
{
- auto format_mapping_name = [](StringView format, StringView name) {
- auto mapping_name = name.to_lowercase_string().replace("-"sv, "_"sv, true).replace("/"sv, "_"sv, true);
- return String::formatted(format, mapping_name);
+ auto format_mapping_name = [&](StringView format, StringView name) {
+ String mapping_name;
+
+ if constexpr (IsNullPointer<IdentifierFormatter>)
+ mapping_name = name.replace("-"sv, "_"sv, true);
+ else
+ mapping_name = format_identifier(type, name);
+
+ return String::formatted(format, mapping_name.to_lowercase());
};
Vector<String> mapping_names;