LibWeb: Stop generating C++ includes for non-code-generating IDL files

Specifically, IDL files that do not include interface or enumeration
declarations do not generate any code, and as such should not be
included.
This commit is contained in:
Idan Horowitz 2022-03-30 23:30:12 +03:00 committed by Andreas Kling
parent eb34015748
commit f0cd28dedd
Notes: sideshowbarker 2024-07-17 16:27:01 +09:00
4 changed files with 25 additions and 7 deletions

View file

@ -222,6 +222,9 @@ static void emit_includes_for_all_imports(auto& interface, auto& generator, bool
interfaces.enqueue(&imported_interface);
}
if (!interface->will_generate_code())
continue;
generate_include_for(generator, interface->module_own_path);
if (is_iterator) {
@ -1543,7 +1546,7 @@ void generate_header(IDL::Interface const& interface)
#include <LibWeb/Bindings/Wrapper.h>
)~~~");
for (auto& path : interface.imported_paths)
for (auto& path : interface.required_imported_paths)
generate_include_for(generator, path);
emit_includes_for_all_imports(interface, generator, true);
@ -2886,7 +2889,7 @@ void generate_prototype_implementation(IDL::Interface const& interface)
)~~~");
for (auto& path : interface.imported_paths)
for (auto& path : interface.required_imported_paths)
generate_include_for(generator, path);
emit_includes_for_all_imports(interface, generator, false, interface.pair_iterator_types.has_value());
@ -3334,7 +3337,7 @@ void generate_iterator_implementation(IDL::Interface const& interface)
)~~~");
for (auto& path : interface.imported_paths)
for (auto& path : interface.required_imported_paths)
generate_include_for(generator, path);
emit_includes_for_all_imports(interface, generator, false, true);

View file

@ -141,7 +141,10 @@ Optional<NonnullOwnPtr<Interface>> Parser::resolve_import(auto path)
report_parsing_error(String::formatted("Failed to open {}: {}", real_path, file_or_error.error()), filename, input, lexer.tell());
auto data = file_or_error.value()->read_all();
return Parser(real_path, data, import_base_path).parse();
auto result = Parser(real_path, data, import_base_path).parse();
if (result->will_generate_code())
required_imported_paths.set(real_path);
return result;
}
NonnullRefPtr<Type> Parser::parse_type()
@ -745,13 +748,16 @@ NonnullOwnPtr<Interface> Parser::parse()
lexer.ignore();
auto maybe_interface = resolve_import(path);
if (maybe_interface.has_value()) {
for (auto& entry : maybe_interface.value()->imported_paths)
for (auto& entry : maybe_interface.value()->all_imported_paths)
s_all_imported_paths.set(entry);
for (auto& entry : maybe_interface.value()->required_imported_paths)
required_imported_paths.set(entry);
imports.append(maybe_interface.release_value());
}
consume_whitespace();
}
interface->imported_paths = s_all_imported_paths;
interface->all_imported_paths = s_all_imported_paths;
interface->required_imported_paths = required_imported_paths;
if (lexer.consume_specific('['))
interface->extended_attributes = parse_extended_attributes();
@ -828,6 +834,8 @@ NonnullOwnPtr<Interface> Parser::parse()
}
// FIXME: Add support for overloading constructors
if (interface->will_generate_code())
interface->required_imported_paths.set(this_module);
interface->imported_modules = move(imports);
return interface;

View file

@ -52,6 +52,7 @@ private:
void parse_constant(Interface&);
static HashTable<String> s_all_imported_paths;
HashTable<String> required_imported_paths;
String import_base_path;
String filename;
StringView input;

View file

@ -196,7 +196,8 @@ struct Interface {
HashMap<String, HashTable<String>> included_mixins;
String module_own_path;
HashTable<String> imported_paths;
HashTable<String> all_imported_paths;
HashTable<String> required_imported_paths;
NonnullOwnPtrVector<Interface> imported_modules;
HashMap<String, Vector<Function&>> overload_sets;
@ -210,6 +211,11 @@ struct Interface {
// https://webidl.spec.whatwg.org/#dfn-legacy-platform-object
bool is_legacy_platform_object() const { return !extended_attributes.contains("Global") && (supports_indexed_properties() || supports_named_properties()); }
bool will_generate_code() const
{
return !name.is_empty() || any_of(enumerations, [](auto& entry) { return entry.value.is_original_definition; });
}
};
CppType idl_type_name_to_cpp_type(Type const& type, IDL::Interface const& interface);