mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:17:42 +00:00
Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte string. As the null state has already been removed, there are no other particularly hairy blockers in repurposing this type as a byte string (what it _really_ is). This commit is auto-generated: $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \ Meta Ports Ladybird Tests Kernel) $ perl -pie 's/\bDeprecatedString\b/ByteString/g; s/deprecated_string/byte_string/g' $xs $ clang-format --style=file -i \ $(git diff --name-only | grep \.cpp\|\.h) $ gn format $(git ls-files '*.gn' '*.gni')
This commit is contained in:
parent
38d62563b3
commit
5e1499d104
1615 changed files with 10257 additions and 10257 deletions
|
@ -17,12 +17,12 @@
|
|||
#include <stdio.h>
|
||||
|
||||
struct Parameter {
|
||||
Vector<DeprecatedString> attributes;
|
||||
DeprecatedString type;
|
||||
DeprecatedString name;
|
||||
Vector<ByteString> attributes;
|
||||
ByteString type;
|
||||
ByteString name;
|
||||
};
|
||||
|
||||
static DeprecatedString pascal_case(DeprecatedString const& identifier)
|
||||
static ByteString pascal_case(ByteString const& identifier)
|
||||
{
|
||||
StringBuilder builder;
|
||||
bool was_new_word = true;
|
||||
|
@ -37,48 +37,48 @@ static DeprecatedString pascal_case(DeprecatedString const& identifier)
|
|||
} else
|
||||
builder.append(ch);
|
||||
}
|
||||
return builder.to_deprecated_string();
|
||||
return builder.to_byte_string();
|
||||
}
|
||||
|
||||
struct Message {
|
||||
DeprecatedString name;
|
||||
ByteString name;
|
||||
bool is_synchronous { false };
|
||||
Vector<Parameter> inputs;
|
||||
Vector<Parameter> outputs;
|
||||
|
||||
DeprecatedString response_name() const
|
||||
ByteString response_name() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.append(pascal_case(name));
|
||||
builder.append("Response"sv);
|
||||
return builder.to_deprecated_string();
|
||||
return builder.to_byte_string();
|
||||
}
|
||||
};
|
||||
|
||||
struct Endpoint {
|
||||
Vector<DeprecatedString> includes;
|
||||
DeprecatedString name;
|
||||
Vector<ByteString> includes;
|
||||
ByteString name;
|
||||
u32 magic;
|
||||
Vector<Message> messages;
|
||||
};
|
||||
|
||||
static bool is_primitive_type(DeprecatedString const& type)
|
||||
static bool is_primitive_type(ByteString const& type)
|
||||
{
|
||||
return type.is_one_of("u8", "i8", "u16", "i16", "u32", "i32", "u64", "i64", "size_t", "bool", "double", "float", "int", "unsigned", "unsigned int");
|
||||
}
|
||||
|
||||
static bool is_simple_type(DeprecatedString const& type)
|
||||
static bool is_simple_type(ByteString const& type)
|
||||
{
|
||||
// Small types that it makes sense just to pass by value.
|
||||
return type.is_one_of("Gfx::Color", "Web::DevicePixels", "Gfx::IntPoint", "Gfx::FloatPoint", "Web::DevicePixelPoint", "Gfx::IntSize", "Gfx::FloatSize", "Web::DevicePixelSize", "Core::File::OpenMode");
|
||||
}
|
||||
|
||||
static bool is_primitive_or_simple_type(DeprecatedString const& type)
|
||||
static bool is_primitive_or_simple_type(ByteString const& type)
|
||||
{
|
||||
return is_primitive_type(type) || is_simple_type(type);
|
||||
}
|
||||
|
||||
static DeprecatedString message_name(DeprecatedString const& endpoint, DeprecatedString const& message, bool is_response)
|
||||
static ByteString message_name(ByteString const& endpoint, ByteString const& message, bool is_response)
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.append("Messages::"sv);
|
||||
|
@ -87,7 +87,7 @@ static DeprecatedString message_name(DeprecatedString const& endpoint, Deprecate
|
|||
builder.append(pascal_case(message));
|
||||
if (is_response)
|
||||
builder.append("Response"sv);
|
||||
return builder.to_deprecated_string();
|
||||
return builder.to_byte_string();
|
||||
}
|
||||
|
||||
Vector<Endpoint> parse(ByteBuffer const& file_contents)
|
||||
|
@ -133,7 +133,7 @@ Vector<Endpoint> parse(ByteBuffer const& file_contents)
|
|||
consume_whitespace();
|
||||
}
|
||||
}
|
||||
// FIXME: This is not entirely correct. Types can have spaces, for example `HashMap<int, DeprecatedString>`.
|
||||
// FIXME: This is not entirely correct. Types can have spaces, for example `HashMap<int, ByteString>`.
|
||||
// Maybe we should use LibCpp::Parser for parsing types.
|
||||
parameter.type = lexer.consume_until([](char ch) { return isspace(ch); });
|
||||
if (parameter.type.ends_with(',')) {
|
||||
|
@ -208,7 +208,7 @@ Vector<Endpoint> parse(ByteBuffer const& file_contents)
|
|||
};
|
||||
|
||||
auto parse_include = [&] {
|
||||
DeprecatedString include;
|
||||
ByteString include;
|
||||
consume_whitespace();
|
||||
include = lexer.consume_while([](char ch) { return ch != '\n'; });
|
||||
consume_whitespace();
|
||||
|
@ -234,7 +234,7 @@ Vector<Endpoint> parse(ByteBuffer const& file_contents)
|
|||
lexer.consume_specific("endpoint");
|
||||
consume_whitespace();
|
||||
endpoints.last().name = lexer.consume_while([](char ch) { return !isspace(ch); });
|
||||
endpoints.last().magic = Traits<DeprecatedString>::hash(endpoints.last().name);
|
||||
endpoints.last().magic = Traits<ByteString>::hash(endpoints.last().name);
|
||||
consume_whitespace();
|
||||
assert_specific('{');
|
||||
parse_messages();
|
||||
|
@ -248,22 +248,22 @@ Vector<Endpoint> parse(ByteBuffer const& file_contents)
|
|||
return endpoints;
|
||||
}
|
||||
|
||||
HashMap<DeprecatedString, int> build_message_ids_for_endpoint(SourceGenerator generator, Endpoint const& endpoint)
|
||||
HashMap<ByteString, int> build_message_ids_for_endpoint(SourceGenerator generator, Endpoint const& endpoint)
|
||||
{
|
||||
HashMap<DeprecatedString, int> message_ids;
|
||||
HashMap<ByteString, int> message_ids;
|
||||
|
||||
generator.appendln("\nenum class MessageID : i32 {");
|
||||
for (auto const& message : endpoint.messages) {
|
||||
|
||||
message_ids.set(message.name, message_ids.size() + 1);
|
||||
generator.set("message.pascal_name", pascal_case(message.name));
|
||||
generator.set("message.id", DeprecatedString::number(message_ids.size()));
|
||||
generator.set("message.id", ByteString::number(message_ids.size()));
|
||||
|
||||
generator.appendln(" @message.pascal_name@ = @message.id@,");
|
||||
if (message.is_synchronous) {
|
||||
message_ids.set(message.response_name(), message_ids.size() + 1);
|
||||
generator.set("message.pascal_name", pascal_case(message.response_name()));
|
||||
generator.set("message.id", DeprecatedString::number(message_ids.size()));
|
||||
generator.set("message.id", ByteString::number(message_ids.size()));
|
||||
|
||||
generator.appendln(" @message.pascal_name@ = @message.id@,");
|
||||
}
|
||||
|
@ -272,14 +272,14 @@ HashMap<DeprecatedString, int> build_message_ids_for_endpoint(SourceGenerator ge
|
|||
return message_ids;
|
||||
}
|
||||
|
||||
DeprecatedString constructor_for_message(DeprecatedString const& name, Vector<Parameter> const& parameters)
|
||||
ByteString constructor_for_message(ByteString const& name, Vector<Parameter> const& parameters)
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.append(name);
|
||||
|
||||
if (parameters.is_empty()) {
|
||||
builder.append("() {}"sv);
|
||||
return builder.to_deprecated_string();
|
||||
return builder.to_byte_string();
|
||||
}
|
||||
builder.append('(');
|
||||
for (size_t i = 0; i < parameters.size(); ++i) {
|
||||
|
@ -296,10 +296,10 @@ DeprecatedString constructor_for_message(DeprecatedString const& name, Vector<Pa
|
|||
builder.append(", "sv);
|
||||
}
|
||||
builder.append(" {}"sv);
|
||||
return builder.to_deprecated_string();
|
||||
return builder.to_byte_string();
|
||||
}
|
||||
|
||||
void do_message(SourceGenerator message_generator, DeprecatedString const& name, Vector<Parameter> const& parameters, DeprecatedString const& response_type = {})
|
||||
void do_message(SourceGenerator message_generator, ByteString const& name, Vector<Parameter> const& parameters, ByteString const& response_type = {})
|
||||
{
|
||||
auto pascal_name = pascal_case(name);
|
||||
message_generator.set("message.name", name);
|
||||
|
@ -377,7 +377,7 @@ public:)~~~");
|
|||
builder.append(", "sv);
|
||||
}
|
||||
|
||||
message_generator.set("message.constructor_call_parameters", builder.to_deprecated_string());
|
||||
message_generator.set("message.constructor_call_parameters", builder.to_byte_string());
|
||||
message_generator.appendln(R"~~~(
|
||||
return make<@message.pascal_name@>(@message.constructor_call_parameters@);
|
||||
})~~~");
|
||||
|
@ -432,17 +432,17 @@ private:
|
|||
|
||||
void do_message_for_proxy(SourceGenerator message_generator, Endpoint const& endpoint, Message const& message)
|
||||
{
|
||||
auto do_implement_proxy = [&](DeprecatedString const& name, Vector<Parameter> const& parameters, bool is_synchronous, bool is_try) {
|
||||
DeprecatedString return_type = "void";
|
||||
auto do_implement_proxy = [&](ByteString const& name, Vector<Parameter> const& parameters, bool is_synchronous, bool is_try) {
|
||||
ByteString return_type = "void";
|
||||
if (is_synchronous) {
|
||||
if (message.outputs.size() == 1)
|
||||
return_type = message.outputs[0].type;
|
||||
else if (!message.outputs.is_empty())
|
||||
return_type = message_name(endpoint.name, message.name, true);
|
||||
}
|
||||
DeprecatedString inner_return_type = return_type;
|
||||
ByteString inner_return_type = return_type;
|
||||
if (is_try)
|
||||
return_type = DeprecatedString::formatted("IPC::IPCErrorOr<{}>", return_type);
|
||||
return_type = ByteString::formatted("IPC::IPCErrorOr<{}>", return_type);
|
||||
|
||||
message_generator.set("message.name", message.name);
|
||||
message_generator.set("message.pascal_name", pascal_case(message.name));
|
||||
|
@ -541,14 +541,14 @@ void do_message_for_proxy(SourceGenerator message_generator, Endpoint const& end
|
|||
void build_endpoint(SourceGenerator generator, Endpoint const& endpoint)
|
||||
{
|
||||
generator.set("endpoint.name", endpoint.name);
|
||||
generator.set("endpoint.magic", DeprecatedString::number(endpoint.magic));
|
||||
generator.set("endpoint.magic", ByteString::number(endpoint.magic));
|
||||
|
||||
generator.appendln("\nnamespace Messages::@endpoint.name@ {");
|
||||
|
||||
HashMap<DeprecatedString, int> message_ids = build_message_ids_for_endpoint(generator.fork(), endpoint);
|
||||
HashMap<ByteString, int> message_ids = build_message_ids_for_endpoint(generator.fork(), endpoint);
|
||||
|
||||
for (auto const& message : endpoint.messages) {
|
||||
DeprecatedString response_name;
|
||||
ByteString response_name;
|
||||
if (message.is_synchronous) {
|
||||
response_name = message.response_name();
|
||||
do_message(generator.fork(), response_name, message.outputs);
|
||||
|
@ -611,7 +611,7 @@ public:
|
|||
switch (message_id) {)~~~");
|
||||
|
||||
for (auto const& message : endpoint.messages) {
|
||||
auto do_decode_message = [&](DeprecatedString const& name) {
|
||||
auto do_decode_message = [&](ByteString const& name) {
|
||||
auto message_generator = generator.fork();
|
||||
|
||||
message_generator.set("message.name", name);
|
||||
|
@ -649,13 +649,13 @@ public:
|
|||
virtual ~@endpoint.name@Stub() override { }
|
||||
|
||||
virtual u32 magic() const override { return @endpoint.magic@; }
|
||||
virtual DeprecatedString name() const override { return "@endpoint.name@"; }
|
||||
virtual ByteString name() const override { return "@endpoint.name@"; }
|
||||
|
||||
virtual ErrorOr<OwnPtr<IPC::MessageBuffer>> handle(const IPC::Message& message) override
|
||||
{
|
||||
switch (message.message_id()) {)~~~");
|
||||
for (auto const& message : endpoint.messages) {
|
||||
auto do_handle_message = [&](DeprecatedString const& name, Vector<Parameter> const& parameters, bool returns_something) {
|
||||
auto do_handle_message = [&](ByteString const& name, Vector<Parameter> const& parameters, bool returns_something) {
|
||||
auto message_generator = generator.fork();
|
||||
|
||||
StringBuilder argument_generator;
|
||||
|
@ -671,7 +671,7 @@ public:
|
|||
message_generator.set("message.pascal_name", pascal_case(name));
|
||||
message_generator.set("message.response_type", pascal_case(message.response_name()));
|
||||
message_generator.set("handler_name", name);
|
||||
message_generator.set("arguments", argument_generator.to_deprecated_string());
|
||||
message_generator.set("arguments", argument_generator.to_byte_string());
|
||||
message_generator.appendln(R"~~~(
|
||||
case (int)Messages::@endpoint.name@::MessageID::@message.pascal_name@: {)~~~");
|
||||
if (returns_something) {
|
||||
|
@ -709,8 +709,8 @@ public:
|
|||
for (auto const& message : endpoint.messages) {
|
||||
auto message_generator = generator.fork();
|
||||
|
||||
auto do_handle_message_decl = [&](DeprecatedString const& name, Vector<Parameter> const& parameters, bool is_response) {
|
||||
DeprecatedString return_type = "void";
|
||||
auto do_handle_message_decl = [&](ByteString const& name, Vector<Parameter> const& parameters, bool is_response) {
|
||||
ByteString return_type = "void";
|
||||
if (message.is_synchronous && !message.outputs.is_empty() && !is_response)
|
||||
return_type = message_name(endpoint.name, message.name, true);
|
||||
message_generator.set("message.complex_return_type", return_type);
|
||||
|
@ -719,7 +719,7 @@ public:
|
|||
message_generator.appendln(R"~~~(
|
||||
virtual @message.complex_return_type@ @handler_name@()~~~");
|
||||
|
||||
auto make_argument_type = [](DeprecatedString const& type) {
|
||||
auto make_argument_type = [](ByteString const& type) {
|
||||
StringBuilder builder;
|
||||
|
||||
bool const_ref = !is_primitive_or_simple_type(type);
|
||||
|
@ -728,7 +728,7 @@ public:
|
|||
if (const_ref)
|
||||
builder.append(" const&"sv);
|
||||
|
||||
return builder.to_deprecated_string();
|
||||
return builder.to_byte_string();
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < parameters.size(); ++i) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue