Ver Fonte

LibWeb: Add support for implementing an IDL class with a different name

Add support for the extended attribute "ImplementedAs" for IDL
interfaces too. This allows a class which implements an IDL interface to
have a different class name than the interface itself.
Shannon Booth há 1 ano atrás
pai
commit
1b6346ee1c

+ 2 - 2
Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/main.cpp

@@ -77,10 +77,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
         StringBuilder builder;
         builder.append(namespace_);
         builder.append("::"sv);
-        builder.append(interface.name);
+        builder.append(interface.implemented_name);
         interface.fully_qualified_name = builder.to_byte_string();
     } else {
-        interface.fully_qualified_name = interface.name;
+        interface.fully_qualified_name = interface.implemented_name;
     }
 
     if constexpr (BINDINGS_GENERATOR_DEBUG) {

+ 7 - 2
Userland/Libraries/LibIDL/IDLParser.cpp

@@ -634,8 +634,13 @@ void Parser::parse_interface(Interface& interface)
     else
         interface.namespaced_name = interface.name;
 
-    interface.constructor_class = ByteString::formatted("{}Constructor", interface.name);
-    interface.prototype_class = ByteString::formatted("{}Prototype", interface.name);
+    if (auto maybe_implemented_as = interface.extended_attributes.get("ImplementedAs"); maybe_implemented_as.has_value())
+        interface.implemented_name = maybe_implemented_as.release_value();
+    else
+        interface.implemented_name = interface.name;
+
+    interface.constructor_class = ByteString::formatted("{}Constructor", interface.implemented_name);
+    interface.prototype_class = ByteString::formatted("{}Prototype", interface.implemented_name);
     interface.prototype_base_class = ByteString::formatted("{}Prototype", interface.parent_name.is_empty() ? "Object" : interface.parent_name);
     interface.global_mixin_class = ByteString::formatted("{}GlobalMixin", interface.name);
     consume_whitespace();

+ 1 - 0
Userland/Libraries/LibIDL/Types.h

@@ -260,6 +260,7 @@ public:
     ByteString name;
     ByteString parent_name;
     ByteString namespaced_name;
+    ByteString implemented_name;
 
     bool is_namespace { false };
     bool is_mixin { false };