From 76faf6c5b1da06ac1ebc7c38ee7d211292d6ab77 Mon Sep 17 00:00:00 2001 From: Makoto Kato Date: Wed, 18 Oct 2023 18:52:13 +0900 Subject: [PATCH] Add FFI --- ffi/capi/c/include/ICU4XCodePointMapData8.h | 2 ++ .../ICU4XPropertyValueNameToEnumMapper.h | 2 ++ .../cpp/docs/source/properties_maps_ffi.rst | 5 +++++ .../cpp/docs/source/properties_names_ffi.rst | 5 +++++ ffi/capi/cpp/include/ICU4XCodePointMapData8.h | 2 ++ .../cpp/include/ICU4XCodePointMapData8.hpp | 17 ++++++++++++++++ .../ICU4XPropertyValueNameToEnumMapper.h | 2 ++ .../ICU4XPropertyValueNameToEnumMapper.hpp | 17 ++++++++++++++++ .../js/docs/source/properties_maps_ffi.rst | 5 +++++ .../js/docs/source/properties_names_ffi.rst | 5 +++++ .../js/include/ICU4XCodePointMapData8.d.ts | 7 +++++++ ffi/capi/js/include/ICU4XCodePointMapData8.js | 17 ++++++++++++++++ .../ICU4XPropertyValueNameToEnumMapper.d.ts | 7 +++++++ .../ICU4XPropertyValueNameToEnumMapper.js | 17 ++++++++++++++++ ffi/capi/src/properties_maps.rs | 12 +++++++++++ ffi/capi/src/properties_names.rs | 20 ++++++++++++++++++- tools/ffi_coverage/src/allowlist.rs | 1 + 17 files changed, 142 insertions(+), 1 deletion(-) diff --git a/ffi/capi/c/include/ICU4XCodePointMapData8.h b/ffi/capi/c/include/ICU4XCodePointMapData8.h index 69a6a46b900..87fe8854b2e 100644 --- a/ffi/capi/c/include/ICU4XCodePointMapData8.h +++ b/ffi/capi/c/include/ICU4XCodePointMapData8.h @@ -43,6 +43,8 @@ diplomat_result_box_ICU4XCodePointMapData8_ICU4XError ICU4XCodePointMapData8_loa diplomat_result_box_ICU4XCodePointMapData8_ICU4XError ICU4XCodePointMapData8_load_east_asian_width(const ICU4XDataProvider* provider); +diplomat_result_box_ICU4XCodePointMapData8_ICU4XError ICU4XCodePointMapData8_load_indic_syllabic_category(const ICU4XDataProvider* provider); + diplomat_result_box_ICU4XCodePointMapData8_ICU4XError ICU4XCodePointMapData8_load_line_break(const ICU4XDataProvider* provider); diplomat_result_box_ICU4XCodePointMapData8_ICU4XError ICU4XCodePointMapData8_try_grapheme_cluster_break(const ICU4XDataProvider* provider); diff --git a/ffi/capi/c/include/ICU4XPropertyValueNameToEnumMapper.h b/ffi/capi/c/include/ICU4XPropertyValueNameToEnumMapper.h index 7598c183720..54000ce3384 100644 --- a/ffi/capi/c/include/ICU4XPropertyValueNameToEnumMapper.h +++ b/ffi/capi/c/include/ICU4XPropertyValueNameToEnumMapper.h @@ -31,6 +31,8 @@ diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError ICU4XPropertyV diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError ICU4XPropertyValueNameToEnumMapper_load_east_asian_width(const ICU4XDataProvider* provider); +diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError ICU4XPropertyValueNameToEnumMapper_load_indic_syllabic_category(const ICU4XDataProvider* provider); + diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError ICU4XPropertyValueNameToEnumMapper_load_line_break(const ICU4XDataProvider* provider); diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError ICU4XPropertyValueNameToEnumMapper_load_grapheme_cluster_break(const ICU4XDataProvider* provider); diff --git a/ffi/capi/cpp/docs/source/properties_maps_ffi.rst b/ffi/capi/cpp/docs/source/properties_maps_ffi.rst index 0fd6f64d75a..200c95427d0 100644 --- a/ffi/capi/cpp/docs/source/properties_maps_ffi.rst +++ b/ffi/capi/cpp/docs/source/properties_maps_ffi.rst @@ -143,6 +143,11 @@ See the `Rust documentation for east_asian_width `__ for more information. + .. cpp:function:: static diplomat::result load_indic_syllabic_category(const ICU4XDataProvider& provider) + + See the `Rust documentation for indic_syllabic_category `__ for more information. + + .. cpp:function:: static diplomat::result load_line_break(const ICU4XDataProvider& provider) See the `Rust documentation for line_break `__ for more information. diff --git a/ffi/capi/cpp/docs/source/properties_names_ffi.rst b/ffi/capi/cpp/docs/source/properties_names_ffi.rst index 15ee44d8ed2..2ae5d9e4eb1 100644 --- a/ffi/capi/cpp/docs/source/properties_names_ffi.rst +++ b/ffi/capi/cpp/docs/source/properties_names_ffi.rst @@ -71,6 +71,11 @@ See the `Rust documentation for name_to_enum_mapper `__ for more information. + .. cpp:function:: static diplomat::result load_indic_syllabic_category(const ICU4XDataProvider& provider) + + See the `Rust documentation for name_to_enum_mapper `__ for more information. + + .. cpp:function:: static diplomat::result load_line_break(const ICU4XDataProvider& provider) See the `Rust documentation for name_to_enum_mapper `__ for more information. diff --git a/ffi/capi/cpp/include/ICU4XCodePointMapData8.h b/ffi/capi/cpp/include/ICU4XCodePointMapData8.h index 69a6a46b900..87fe8854b2e 100644 --- a/ffi/capi/cpp/include/ICU4XCodePointMapData8.h +++ b/ffi/capi/cpp/include/ICU4XCodePointMapData8.h @@ -43,6 +43,8 @@ diplomat_result_box_ICU4XCodePointMapData8_ICU4XError ICU4XCodePointMapData8_loa diplomat_result_box_ICU4XCodePointMapData8_ICU4XError ICU4XCodePointMapData8_load_east_asian_width(const ICU4XDataProvider* provider); +diplomat_result_box_ICU4XCodePointMapData8_ICU4XError ICU4XCodePointMapData8_load_indic_syllabic_category(const ICU4XDataProvider* provider); + diplomat_result_box_ICU4XCodePointMapData8_ICU4XError ICU4XCodePointMapData8_load_line_break(const ICU4XDataProvider* provider); diplomat_result_box_ICU4XCodePointMapData8_ICU4XError ICU4XCodePointMapData8_try_grapheme_cluster_break(const ICU4XDataProvider* provider); diff --git a/ffi/capi/cpp/include/ICU4XCodePointMapData8.hpp b/ffi/capi/cpp/include/ICU4XCodePointMapData8.hpp index 339bdf11825..c806b747515 100644 --- a/ffi/capi/cpp/include/ICU4XCodePointMapData8.hpp +++ b/ffi/capi/cpp/include/ICU4XCodePointMapData8.hpp @@ -123,6 +123,13 @@ class ICU4XCodePointMapData8 { */ static diplomat::result load_east_asian_width(const ICU4XDataProvider& provider); + /** + * + * + * See the [Rust documentation for `indic_syllabic_category`](https://docs.rs/icu/latest/icu/properties/maps/fn.indic_syllabic_category.html) for more information. + */ + static diplomat::result load_indic_syllabic_category(const ICU4XDataProvider& provider); + /** * * @@ -215,6 +222,16 @@ inline diplomat::result ICU4XCodePointMapDat } return diplomat_result_out_value; } +inline diplomat::result ICU4XCodePointMapData8::load_indic_syllabic_category(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointMapData8_load_indic_syllabic_category(provider.AsFFI()); + diplomat::result diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(ICU4XCodePointMapData8(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err(static_cast(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} inline diplomat::result ICU4XCodePointMapData8::load_line_break(const ICU4XDataProvider& provider) { auto diplomat_result_raw_out_value = capi::ICU4XCodePointMapData8_load_line_break(provider.AsFFI()); diplomat::result diplomat_result_out_value; diff --git a/ffi/capi/cpp/include/ICU4XPropertyValueNameToEnumMapper.h b/ffi/capi/cpp/include/ICU4XPropertyValueNameToEnumMapper.h index 7598c183720..54000ce3384 100644 --- a/ffi/capi/cpp/include/ICU4XPropertyValueNameToEnumMapper.h +++ b/ffi/capi/cpp/include/ICU4XPropertyValueNameToEnumMapper.h @@ -31,6 +31,8 @@ diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError ICU4XPropertyV diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError ICU4XPropertyValueNameToEnumMapper_load_east_asian_width(const ICU4XDataProvider* provider); +diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError ICU4XPropertyValueNameToEnumMapper_load_indic_syllabic_category(const ICU4XDataProvider* provider); + diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError ICU4XPropertyValueNameToEnumMapper_load_line_break(const ICU4XDataProvider* provider); diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError ICU4XPropertyValueNameToEnumMapper_load_grapheme_cluster_break(const ICU4XDataProvider* provider); diff --git a/ffi/capi/cpp/include/ICU4XPropertyValueNameToEnumMapper.hpp b/ffi/capi/cpp/include/ICU4XPropertyValueNameToEnumMapper.hpp index d87e475336d..850e7de0d21 100644 --- a/ffi/capi/cpp/include/ICU4XPropertyValueNameToEnumMapper.hpp +++ b/ffi/capi/cpp/include/ICU4XPropertyValueNameToEnumMapper.hpp @@ -73,6 +73,13 @@ class ICU4XPropertyValueNameToEnumMapper { */ static diplomat::result load_east_asian_width(const ICU4XDataProvider& provider); + /** + * + * + * See the [Rust documentation for `name_to_enum_mapper`](https://docs.rs/icu/latest/icu/properties/struct.IndicSyllabicCategory.html#method.name_to_enum_mapper) for more information. + */ + static diplomat::result load_indic_syllabic_category(const ICU4XDataProvider& provider); + /** * * @@ -155,6 +162,16 @@ inline diplomat::result ICU4XPro } return diplomat_result_out_value; } +inline diplomat::result ICU4XPropertyValueNameToEnumMapper::load_indic_syllabic_category(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XPropertyValueNameToEnumMapper_load_indic_syllabic_category(provider.AsFFI()); + diplomat::result diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(ICU4XPropertyValueNameToEnumMapper(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err(static_cast(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} inline diplomat::result ICU4XPropertyValueNameToEnumMapper::load_line_break(const ICU4XDataProvider& provider) { auto diplomat_result_raw_out_value = capi::ICU4XPropertyValueNameToEnumMapper_load_line_break(provider.AsFFI()); diplomat::result diplomat_result_out_value; diff --git a/ffi/capi/js/docs/source/properties_maps_ffi.rst b/ffi/capi/js/docs/source/properties_maps_ffi.rst index faa6a477240..8fc7c1625b4 100644 --- a/ffi/capi/js/docs/source/properties_maps_ffi.rst +++ b/ffi/capi/js/docs/source/properties_maps_ffi.rst @@ -133,6 +133,11 @@ See the `Rust documentation for east_asian_width `__ for more information. + .. js:function:: load_indic_syllabic_category(provider) + + See the `Rust documentation for indic_syllabic_category `__ for more information. + + .. js:function:: load_line_break(provider) See the `Rust documentation for line_break `__ for more information. diff --git a/ffi/capi/js/docs/source/properties_names_ffi.rst b/ffi/capi/js/docs/source/properties_names_ffi.rst index 52c3bd28c13..b500224c469 100644 --- a/ffi/capi/js/docs/source/properties_names_ffi.rst +++ b/ffi/capi/js/docs/source/properties_names_ffi.rst @@ -71,6 +71,11 @@ See the `Rust documentation for name_to_enum_mapper `__ for more information. + .. js:function:: load_indic_syllabic_category(provider) + + See the `Rust documentation for name_to_enum_mapper `__ for more information. + + .. js:function:: load_line_break(provider) See the `Rust documentation for name_to_enum_mapper `__ for more information. diff --git a/ffi/capi/js/include/ICU4XCodePointMapData8.d.ts b/ffi/capi/js/include/ICU4XCodePointMapData8.d.ts index c12b6adc9c2..700695044e7 100644 --- a/ffi/capi/js/include/ICU4XCodePointMapData8.d.ts +++ b/ffi/capi/js/include/ICU4XCodePointMapData8.d.ts @@ -100,6 +100,13 @@ export class ICU4XCodePointMapData8 { */ static load_east_asian_width(provider: ICU4XDataProvider): ICU4XCodePointMapData8 | never; + /** + + * See the {@link https://docs.rs/icu/latest/icu/properties/maps/fn.indic_syllabic_category.html Rust documentation for `indic_syllabic_category`} for more information. + * @throws {@link FFIError}<{@link ICU4XError}> + */ + static load_indic_syllabic_category(provider: ICU4XDataProvider): ICU4XCodePointMapData8 | never; + /** * See the {@link https://docs.rs/icu/latest/icu/properties/maps/fn.line_break.html Rust documentation for `line_break`} for more information. diff --git a/ffi/capi/js/include/ICU4XCodePointMapData8.js b/ffi/capi/js/include/ICU4XCodePointMapData8.js index 3fc2d65d61f..4af999f4be2 100644 --- a/ffi/capi/js/include/ICU4XCodePointMapData8.js +++ b/ffi/capi/js/include/ICU4XCodePointMapData8.js @@ -97,6 +97,23 @@ export class ICU4XCodePointMapData8 { })(); } + static load_indic_syllabic_category(arg_provider) { + return (() => { + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + wasm.ICU4XCodePointMapData8_load_indic_syllabic_category(diplomat_receive_buffer, arg_provider.underlying); + const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); + if (is_ok) { + const ok_value = new ICU4XCodePointMapData8(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + return ok_value; + } else { + const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + throw new diplomatRuntime.FFIError(throw_value); + } + })(); + } + static load_line_break(arg_provider) { return (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); diff --git a/ffi/capi/js/include/ICU4XPropertyValueNameToEnumMapper.d.ts b/ffi/capi/js/include/ICU4XPropertyValueNameToEnumMapper.d.ts index 8ebef776008..f12131e1e7c 100644 --- a/ffi/capi/js/include/ICU4XPropertyValueNameToEnumMapper.d.ts +++ b/ffi/capi/js/include/ICU4XPropertyValueNameToEnumMapper.d.ts @@ -54,6 +54,13 @@ export class ICU4XPropertyValueNameToEnumMapper { */ static load_east_asian_width(provider: ICU4XDataProvider): ICU4XPropertyValueNameToEnumMapper | never; + /** + + * See the {@link https://docs.rs/icu/latest/icu/properties/struct.IndicSyllabicCategory.html#method.name_to_enum_mapper Rust documentation for `name_to_enum_mapper`} for more information. + * @throws {@link FFIError}<{@link ICU4XError}> + */ + static load_indic_syllabic_category(provider: ICU4XDataProvider): ICU4XPropertyValueNameToEnumMapper | never; + /** * See the {@link https://docs.rs/icu/latest/icu/properties/struct.LineBreak.html#method.name_to_enum_mapper Rust documentation for `name_to_enum_mapper`} for more information. diff --git a/ffi/capi/js/include/ICU4XPropertyValueNameToEnumMapper.js b/ffi/capi/js/include/ICU4XPropertyValueNameToEnumMapper.js index 2029aab5085..ef0ddf1f377 100644 --- a/ffi/capi/js/include/ICU4XPropertyValueNameToEnumMapper.js +++ b/ffi/capi/js/include/ICU4XPropertyValueNameToEnumMapper.js @@ -81,6 +81,23 @@ export class ICU4XPropertyValueNameToEnumMapper { })(); } + static load_indic_syllabic_category(arg_provider) { + return (() => { + const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); + wasm.ICU4XPropertyValueNameToEnumMapper_load_indic_syllabic_category(diplomat_receive_buffer, arg_provider.underlying); + const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); + if (is_ok) { + const ok_value = new ICU4XPropertyValueNameToEnumMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + return ok_value; + } else { + const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; + wasm.diplomat_free(diplomat_receive_buffer, 5, 4); + throw new diplomatRuntime.FFIError(throw_value); + } + })(); + } + static load_line_break(arg_provider) { return (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); diff --git a/ffi/capi/src/properties_maps.rs b/ffi/capi/src/properties_maps.rs index d8c14189475..768776f40c8 100644 --- a/ffi/capi/src/properties_maps.rs +++ b/ffi/capi/src/properties_maps.rs @@ -165,6 +165,18 @@ pub mod ffi { )?)) } + #[diplomat::rust_link(icu::properties::maps::indic_syllabic_category, Fn)] + #[diplomat::rust_link(icu::properties::maps::load_indic_syllabic_category, Fn, hidden)] + pub fn load_indic_syllabic_category( + provider: &ICU4XDataProvider, + ) -> Result, ICU4XError> { + Ok(convert_8(call_constructor_unstable!( + maps::indic_syllabic_category [r => Ok(r.static_to_owned())], + maps::load_indic_syllabic_category, + provider, + )?)) + } + #[diplomat::rust_link(icu::properties::maps::line_break, Fn)] #[diplomat::rust_link(icu::properties::maps::load_line_break, Fn, hidden)] pub fn load_line_break( diff --git a/ffi/capi/src/properties_names.rs b/ffi/capi/src/properties_names.rs index 4bb95d55ed8..a5ab0e143aa 100644 --- a/ffi/capi/src/properties_names.rs +++ b/ffi/capi/src/properties_names.rs @@ -8,7 +8,8 @@ pub mod ffi { use alloc::boxed::Box; use icu_properties::{ names::PropertyValueNameToEnumMapper, BidiClass, EastAsianWidth, GeneralCategory, - GeneralCategoryGroup, GraphemeClusterBreak, LineBreak, Script, SentenceBreak, WordBreak, + GeneralCategoryGroup, GraphemeClusterBreak, IndicSyllabicCategory, LineBreak, Script, + SentenceBreak, WordBreak, }; use crate::errors::ffi::ICU4XError; @@ -110,6 +111,23 @@ pub mod ffi { ))) } + #[diplomat::rust_link( + icu::properties::IndicSyllabicCategory::name_to_enum_mapper, + FnInStruct + )] + pub fn load_indic_syllabic_category( + provider: &ICU4XDataProvider, + ) -> Result, ICU4XError> { + Ok(Box::new(ICU4XPropertyValueNameToEnumMapper( + call_constructor_unstable!( + IndicSyllabicCategory::name_to_enum_mapper [r => Ok(r.static_to_owned())], + IndicSyllabicCategory::get_name_to_enum_mapper, + provider, + )? + .erase(), + ))) + } + #[diplomat::rust_link(icu::properties::LineBreak::name_to_enum_mapper, FnInStruct)] pub fn load_line_break( provider: &ICU4XDataProvider, diff --git a/tools/ffi_coverage/src/allowlist.rs b/tools/ffi_coverage/src/allowlist.rs index 9b7e1afd2bc..369ebd961ee 100644 --- a/tools/ffi_coverage/src/allowlist.rs +++ b/tools/ffi_coverage/src/allowlist.rs @@ -226,6 +226,7 @@ lazy_static::lazy_static! { "icu::properties::GeneralCategory", "icu::properties::GeneralCategoryGroup", "icu::properties::GraphemeClusterBreak", + "icu::properties::IndicSyllabicCategory", "icu::properties::LineBreak", "icu::properties::Script", "icu::properties::SentenceBreak",