Meta: Cherry-pick lagom -Wmissing-declarations prep

This cherry-picks the CodeGenerators changes from the second commit in
https://github.com/LadybirdBrowser/ladybird/pull/626

We'll want to enable -Wmissing-declarations (gcc) /
-Wmissing-prototypes (lagom) for Lagom too, but that can happen
in a separate PR.

(cherry picked from commit c62240aa80dceddd7e6ba5bf779a56c84ab8c624;
amended to remove half of the changes. Many of them were in
ladybird-only code. Changed commit message.)
This commit is contained in:
Daniel Bertalan
2024-07-14 18:29:33 +02:00
committed by Nico Weber
parent 727e7c4fe7
commit aa4f0a7ec2
8 changed files with 101 additions and 79 deletions

View File

@@ -10,34 +10,7 @@
#include <LibCore/ArgsParser.h>
#include <LibMain/Main.h>
ErrorOr<void> generate_header_file(JsonObject& functions_data, Core::File& file);
ErrorOr<void> generate_implementation_file(JsonObject& functions_data, Core::File& file);
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
StringView generated_header_path;
StringView generated_implementation_path;
StringView identifiers_json_path;
Core::ArgsParser args_parser;
args_parser.add_option(generated_header_path, "Path to the MathFunctions header file to generate", "generated-header-path", 'h', "generated-header-path");
args_parser.add_option(generated_implementation_path, "Path to the MathFunctions implementation file to generate", "generated-implementation-path", 'c', "generated-implementation-path");
args_parser.add_option(identifiers_json_path, "Path to the JSON file to read from", "json-path", 'j', "json-path");
args_parser.parse(arguments);
auto json = TRY(read_entire_file_as_json(identifiers_json_path));
VERIFY(json.is_object());
auto math_functions_data = json.as_object();
auto generated_header_file = TRY(Core::File::open(generated_header_path, Core::File::OpenMode::Write));
auto generated_implementation_file = TRY(Core::File::open(generated_implementation_path, Core::File::OpenMode::Write));
TRY(generate_header_file(math_functions_data, *generated_header_file));
TRY(generate_implementation_file(math_functions_data, *generated_implementation_file));
return 0;
}
namespace {
ErrorOr<void> generate_header_file(JsonObject& functions_data, Core::File& file)
{
StringBuilder builder;
@@ -378,3 +351,29 @@ OwnPtr<CalculationNode> Parser::parse_math_function(PropertyID property_id, Func
TRY(file.write_until_depleted(generator.as_string_view().bytes()));
return {};
}
} // end anonymous namespace
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
StringView generated_header_path;
StringView generated_implementation_path;
StringView identifiers_json_path;
Core::ArgsParser args_parser;
args_parser.add_option(generated_header_path, "Path to the MathFunctions header file to generate", "generated-header-path", 'h', "generated-header-path");
args_parser.add_option(generated_implementation_path, "Path to the MathFunctions implementation file to generate", "generated-implementation-path", 'c', "generated-implementation-path");
args_parser.add_option(identifiers_json_path, "Path to the JSON file to read from", "json-path", 'j', "json-path");
args_parser.parse(arguments);
auto json = TRY(read_entire_file_as_json(identifiers_json_path));
VERIFY(json.is_object());
auto math_functions_data = json.as_object();
auto generated_header_file = TRY(Core::File::open(generated_header_path, Core::File::OpenMode::Write));
auto generated_implementation_file = TRY(Core::File::open(generated_implementation_path, Core::File::OpenMode::Write));
TRY(generate_header_file(math_functions_data, *generated_header_file));
TRY(generate_implementation_file(math_functions_data, *generated_implementation_file));
return 0;
}