mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 03:55:24 +00:00
WrapperGenerator: Move generation code out of IDLTypes.h
This commit is contained in:
parent
6c87c98ed0
commit
4424a50bc4
Notes:
sideshowbarker
2024-07-18 02:47:59 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/4424a50bc4 Pull-request: https://github.com/SerenityOS/serenity/pull/15170
2 changed files with 27 additions and 28 deletions
|
@ -173,6 +173,31 @@ static bool impl_is_wrapper(Type const& type)
|
|||
return false;
|
||||
}
|
||||
|
||||
CppType idl_type_name_to_cpp_type(Type const& type, Interface const& interface);
|
||||
|
||||
static String union_type_to_variant(UnionType const& union_type, Interface const& interface)
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.append("Variant<"sv);
|
||||
|
||||
auto flattened_types = union_type.flattened_member_types();
|
||||
for (size_t type_index = 0; type_index < flattened_types.size(); ++type_index) {
|
||||
auto& type = flattened_types.at(type_index);
|
||||
|
||||
if (type_index > 0)
|
||||
builder.append(", "sv);
|
||||
|
||||
auto cpp_type = idl_type_name_to_cpp_type(type, interface);
|
||||
builder.append(cpp_type.name);
|
||||
}
|
||||
|
||||
if (union_type.includes_undefined())
|
||||
builder.append(", Empty"sv);
|
||||
|
||||
builder.append('>');
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
CppType idl_type_name_to_cpp_type(Type const& type, Interface const& interface)
|
||||
{
|
||||
if (is_wrappable_type(type)) {
|
||||
|
@ -243,7 +268,7 @@ CppType idl_type_name_to_cpp_type(Type const& type, Interface const& interface)
|
|||
|
||||
if (is<UnionType>(type)) {
|
||||
auto& union_type = verify_cast<UnionType>(type);
|
||||
return { .name = union_type.to_variant(interface), .sequence_storage_type = SequenceStorageType::Vector };
|
||||
return { .name = union_type_to_variant(union_type, interface), .sequence_storage_type = SequenceStorageType::Vector };
|
||||
}
|
||||
|
||||
if (!type.nullable) {
|
||||
|
@ -921,7 +946,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
|||
auto union_generator = scoped_generator.fork();
|
||||
|
||||
auto& union_type = verify_cast<IDL::UnionType>(*parameter.type);
|
||||
union_generator.set("union_type", union_type.to_variant(interface));
|
||||
union_generator.set("union_type", union_type_to_variant(union_type, interface));
|
||||
union_generator.set("recursion_depth", String::number(recursion_depth));
|
||||
|
||||
// NOTE: This is handled out here as we need the dictionary conversion code for the {} optional default value.
|
||||
|
@ -2805,5 +2830,4 @@ JS_DEFINE_NATIVE_FUNCTION(@prototype_class@::next)
|
|||
|
||||
outln("{}", generator.as_string_view());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -238,8 +238,6 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
CppType idl_type_name_to_cpp_type(Type const& type, IDL::Interface const& interface);
|
||||
|
||||
struct UnionType : public Type {
|
||||
UnionType() = default;
|
||||
|
||||
|
@ -336,29 +334,6 @@ struct UnionType : public Type {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
String to_variant(IDL::Interface const& interface) const
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.append("Variant<"sv);
|
||||
|
||||
auto flattened_types = flattened_member_types();
|
||||
for (size_t type_index = 0; type_index < flattened_types.size(); ++type_index) {
|
||||
auto& type = flattened_types.at(type_index);
|
||||
|
||||
if (type_index > 0)
|
||||
builder.append(", "sv);
|
||||
|
||||
auto cpp_type = idl_type_name_to_cpp_type(type, interface);
|
||||
builder.append(cpp_type.name);
|
||||
}
|
||||
|
||||
if (includes_undefined())
|
||||
builder.append(", Empty"sv);
|
||||
|
||||
builder.append('>');
|
||||
return builder.to_string();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue