diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-08-22 13:10:24 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-09-17 21:27:17 +0200 |
commit | 4424a50bc4c12424dea5bfb7ed65a884dc0598d7 (patch) | |
tree | 98ad3a750a5b8d68d3777c826750450379e09b8c /Meta | |
parent | 6c87c98ed0eff6766457e9d701c9f0dc126e00f5 (diff) | |
download | serenity-4424a50bc4c12424dea5bfb7ed65a884dc0598d7.zip |
WrapperGenerator: Move generation code out of IDLTypes.h
Diffstat (limited to 'Meta')
-rw-r--r-- | Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp | 30 | ||||
-rw-r--r-- | Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLTypes.h | 25 |
2 files changed, 27 insertions, 28 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp index 40684cff88..1bfeff97c1 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp @@ -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()); } - } diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLTypes.h b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLTypes.h index 975b3d06ef..dbb5aa6d6a 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLTypes.h +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLTypes.h @@ -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(); - } }; } |