Repository: SerenityOS/serenity
File: Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp (C++)

Code before:
{
    SourceGenerator generator { builder };

    generator.appendln("#pragma once");

    // This must occur before LibIPC/Decoder.h
    for (auto const& endpoint : endpoints) {
        for (auto const& include : endpoint.includes) {
            generator.appendln(include);
        }
    }

    generator.appendln(R"~~~(#include <AK/Error.h>
#include <AK/MemoryStream.h>
#include <AK/OwnPtr.h>
#include <AK/Result.h>
#include <AK/Utf8View.h>
#include <LibIPC/Connection.h>
#include <LibIPC/Decoder.h>
#include <LibIPC/Encoder.h>
#include <LibIPC/File.h>
#include <LibIPC/Message.h>
#include <LibIPC/Stub.h>

#if defined(AK_COMPILER_CLANG)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdefaulted-function-deleted"
#else
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdefaulted-function-deleted"
#endif
)~~~");

    for (auto const& endpoint : endpoints)
        build_endpoint(generator.fork(), endpoint);
}
} // end anonymous namespace

ErrorOr<int> serenity_main(Main::Arguments arguments)
{
    StringView ipc_file;
    StringView output_file = "-"sv;

    Core::ArgsParser parser;
    parser.add_positional_argument(ipc_file, "IPC endpoint definition file", "input");
    parser.add_option(output_file, "Place to write file", "output", 'o', "output-file");
    parser.parse(arguments);

    auto output = TRY(Core::File::open_file_or_standard_stream(output_file, Core::File::OpenMode::Write));

    auto file = TRY(Core::File::open(ipc_file, Core::File::OpenMode::Read));

Review comment (suggestion):
Clang accepts `#pragma GCC` too, so the `#if defined(AK_COMPILER_CLANG)` part does not need to stay.

Code after:

    generator.appendln("#pragma once");

    // This must occur before LibIPC/Decoder.h
    for (auto const& endpoint : endpoints) {
        for (auto const& include : endpoint.includes) {
            generator.appendln(include);
        }
    }

    generator.appendln(R"~~~(#include <AK/Error.h>
#include <AK/MemoryStream.h>
#include <AK/OwnPtr.h>
#include <AK/Result.h>
#include <AK/Utf8View.h>
#include <LibIPC/Connection.h>
#include <LibIPC/Decoder.h>
#include <LibIPC/Encoder.h>
#include <LibIPC/File.h>
#include <LibIPC/Message.h>
#include <LibIPC/Stub.h>

#if defined(AK_COMPILER_CLANG) || __GNUC__ >= 15
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdefaulted-function-deleted"
#endif
)~~~");

    for (auto const& endpoint : endpoints)
        build_endpoint(generator.fork(), endpoint);
}
} // end anonymous namespace

ErrorOr<int> serenity_main(Main::Arguments arguments)
{
    StringView ipc_file;
    StringView output_file = "-"sv;

    Core::ArgsParser parser;
    parser.add_positional_argument(ipc_file, "IPC endpoint definition file", "input");
    parser.add_option(output_file, "Place to write file", "output", 'o', "output-file");
    parser.parse(arguments);

    auto output = TRY(Core::File::open_file_or_standard_stream(output_file, Core::File::OpenMode::Write));

    auto file = TRY(Core::File::open(ipc_file, Core::File::OpenMode::Read));

    auto file_contents = TRY(file->read_until_eof());

    auto endpoints = parse(file_contents);