From a6f0508f9fb94b51ec522b5a8d9d133bc72e8f62 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 5 Apr 2022 16:09:42 +0100 Subject: [PATCH] BindingsGenerator+LibIDL: Parse "inherit" attributes An "inherit attribute" calls an ancestor's getter with the same name, but defines its own setter. Since a parent class's public methods are exposed to child classes, we don't have to do any special handling here to call the parent's methods, it just works. :^) --- .../CodeGenerators/LibWeb/BindingsGenerator/main.cpp | 3 ++- Userland/Libraries/LibIDL/IDLParser.cpp | 9 +++++++-- Userland/Libraries/LibIDL/Types.h | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/main.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/main.cpp index e0417632b4..52dbbd9d59 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/main.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/main.cpp @@ -111,7 +111,8 @@ int main(int argc, char** argv) if constexpr (BINDINGS_GENERATOR_DEBUG) { dbgln("Attributes:"); for (auto& attribute : interface.attributes) { - dbgln(" {}{}{} {}", + dbgln(" {}{}{}{} {}", + attribute.inherit ? "inherit " : "", attribute.readonly ? "readonly " : "", attribute.type->name(), attribute.type->is_nullable() ? "?" : "", diff --git a/Userland/Libraries/LibIDL/IDLParser.cpp b/Userland/Libraries/LibIDL/IDLParser.cpp index 4b89822e46..c576b0193d 100644 --- a/Userland/Libraries/LibIDL/IDLParser.cpp +++ b/Userland/Libraries/LibIDL/IDLParser.cpp @@ -217,6 +217,10 @@ NonnullRefPtr Parser::parse_type() void Parser::parse_attribute(HashMap& extended_attributes, Interface& interface) { + bool inherit = lexer.consume_specific("inherit"); + if (inherit) + consume_whitespace(); + bool readonly = lexer.consume_specific("readonly"); if (readonly) consume_whitespace(); @@ -236,6 +240,7 @@ void Parser::parse_attribute(HashMap& extended_attributes, Inter auto setter_callback_name = String::formatted("{}_setter", name_as_string.to_snakecase()); Attribute attribute { + inherit, readonly, move(type), move(name_as_string), @@ -361,7 +366,7 @@ void Parser::parse_stringifier(HashMap& extended_attributes, Int assert_string("stringifier"sv); consume_whitespace(); interface.has_stringifier = true; - if (lexer.next_is("readonly"sv) || lexer.next_is("attribute"sv)) { + if (lexer.next_is("attribute"sv) || lexer.next_is("inherit"sv) || lexer.next_is("readonly"sv)) { parse_attribute(extended_attributes, interface); interface.stringifier_attribute = interface.attributes.last().name; } else { @@ -547,7 +552,7 @@ void Parser::parse_interface(Interface& interface) continue; } - if (lexer.next_is("readonly") || lexer.next_is("attribute")) { + if (lexer.next_is("inherit") || lexer.next_is("readonly") || lexer.next_is("attribute")) { parse_attribute(extended_attributes, interface); continue; } diff --git a/Userland/Libraries/LibIDL/Types.h b/Userland/Libraries/LibIDL/Types.h index e90af91074..e06c8f2a8f 100644 --- a/Userland/Libraries/LibIDL/Types.h +++ b/Userland/Libraries/LibIDL/Types.h @@ -176,6 +176,7 @@ struct Constant { }; struct Attribute { + bool inherit { false }; bool readonly { false }; NonnullRefPtr type; String name;