AK: Make SourceGenerator::fork() infallible

This commit is contained in:
Andreas Kling 2023-08-21 16:42:48 +02:00
parent 244516142a
commit 0b83717ea2
Notes: sideshowbarker 2024-07-17 06:35:23 +09:00
17 changed files with 142 additions and 142 deletions

View file

@ -39,9 +39,9 @@ public:
// Move-assign is undefinable due to 'StringBuilder& m_builder;'
SourceGenerator& operator=(SourceGenerator&&) = delete;
ErrorOr<SourceGenerator> fork()
[[nodiscard]] SourceGenerator fork()
{
return SourceGenerator { m_builder, TRY(m_mapping.clone()), m_opening, m_closing };
return SourceGenerator { m_builder, MUST(m_mapping.clone()), m_opening, m_closing };
}
void set(StringView key, String value)

View file

@ -277,7 +277,7 @@ static ErrorOr<void> generate_loader_for_object(GUI::GML::Object const& gml_obje
value_code = TRY(String::formatted("{} {{ {} }}", type.release_value(), value_code));
}
auto property_generator = TRY(generator.fork());
auto property_generator = generator.fork();
property_generator.set("key", key);
property_generator.set("value", value_code.bytes_as_string_view());
TRY(append(property_generator, R"~~~(@object_name@->set_@key@(@value@);)~~~"));
@ -288,7 +288,7 @@ static ErrorOr<void> generate_loader_for_object(GUI::GML::Object const& gml_obje
// Layout
if (gml_object.layout_object() != nullptr) {
TRY(append(generator, "RefPtr<GUI::Layout> layout;"));
TRY(generate_loader_for_object(*gml_object.layout_object(), TRY(generator.fork()), TRY(String::from_utf8("layout"sv)), indentation + 1, UseObjectConstructor::Yes));
TRY(generate_loader_for_object(*gml_object.layout_object(), generator.fork(), TRY(String::from_utf8("layout"sv)), indentation + 1, UseObjectConstructor::Yes));
TRY(append(generator, "@object_name@->set_layout(layout.release_nonnull());"));
generator.appendln("");
}
@ -305,12 +305,12 @@ static ErrorOr<void> generate_loader_for_object(GUI::GML::Object const& gml_obje
return {};
}
auto child_generator = TRY(generator.fork());
auto child_generator = generator.fork();
auto child_variable_name = TRY(next_child_name());
child_generator.set("child_variable_name", child_variable_name.bytes_as_string_view());
child_generator.set("child_class_name", child.name());
TRY(append(child_generator, "RefPtr<@child_class_name@> @child_variable_name@;"));
TRY(generate_loader_for_object(child, TRY(child_generator.fork()), child_variable_name, indentation + 1, UseObjectConstructor::Yes));
TRY(generate_loader_for_object(child, child_generator.fork(), child_variable_name, indentation + 1, UseObjectConstructor::Yes));
// Handle the current two special cases of child adding.
if (gml_object.name() == "GUI::ScrollableContainerWidget"sv)
@ -354,7 +354,7 @@ static ErrorOr<String> generate_cpp(NonnullRefPtr<GUI::GML::GMLFile> gml, Lexica
// FIXME: Use a UTF-8 aware function once possible.
generator.set("main_class_name", main_class.name());
generator.append(function_start);
TRY(generate_loader_for_object(main_class, TRY(generator.fork()), "main_object"_string, 2, UseObjectConstructor::No));
TRY(generate_loader_for_object(main_class, generator.fork(), "main_object"_string, 2, UseObjectConstructor::No));
generator.append(footer);
return builder.to_string();

View file

@ -349,7 +349,7 @@ public:)~~~");
IPC::Decoder decoder { stream, socket };)~~~");
for (auto const& parameter : parameters) {
auto parameter_generator = message_generator.fork().release_value_but_fixme_should_propagate_errors();
auto parameter_generator = message_generator.fork();
parameter_generator.set("parameter.type", parameter.type);
parameter_generator.set("parameter.name", parameter.name);
@ -395,7 +395,7 @@ public:)~~~");
TRY(stream.encode((int)MessageID::@message.pascal_name@));)~~~");
for (auto const& parameter : parameters) {
auto parameter_generator = message_generator.fork().release_value_but_fixme_should_propagate_errors();
auto parameter_generator = message_generator.fork();
parameter_generator.set("parameter.name", parameter.name);
parameter_generator.appendln(R"~~~(
@ -407,7 +407,7 @@ public:)~~~");
})~~~");
for (auto const& parameter : parameters) {
auto parameter_generator = message_generator.fork().release_value_but_fixme_should_propagate_errors();
auto parameter_generator = message_generator.fork();
parameter_generator.set("parameter.type", parameter.type);
parameter_generator.set("parameter.name", parameter.name);
parameter_generator.appendln(R"~~~(
@ -420,7 +420,7 @@ private:
bool m_ipc_message_valid { true };)~~~");
for (auto const& parameter : parameters) {
auto parameter_generator = message_generator.fork().release_value_but_fixme_should_propagate_errors();
auto parameter_generator = message_generator.fork();
parameter_generator.set("parameter.type", parameter.type);
parameter_generator.set("parameter.name", parameter.name);
parameter_generator.appendln(R"~~~(
@ -456,7 +456,7 @@ void do_message_for_proxy(SourceGenerator message_generator, Endpoint const& end
for (size_t i = 0; i < parameters.size(); ++i) {
auto const& parameter = parameters[i];
auto argument_generator = message_generator.fork().release_value_but_fixme_should_propagate_errors();
auto argument_generator = message_generator.fork();
argument_generator.set("argument.type", parameter.type);
argument_generator.set("argument.name", parameter.name);
argument_generator.append("@argument.type@ @argument.name@");
@ -489,7 +489,7 @@ void do_message_for_proxy(SourceGenerator message_generator, Endpoint const& end
for (size_t i = 0; i < parameters.size(); ++i) {
auto const& parameter = parameters[i];
auto argument_generator = message_generator.fork().release_value_but_fixme_should_propagate_errors();
auto argument_generator = message_generator.fork();
argument_generator.set("argument.name", parameter.name);
if (is_primitive_or_simple_type(parameters[i].type))
argument_generator.append("@argument.name@");
@ -545,15 +545,15 @@ void build_endpoint(SourceGenerator generator, Endpoint const& endpoint)
generator.appendln("\nnamespace Messages::@endpoint.name@ {");
HashMap<DeprecatedString, int> message_ids = build_message_ids_for_endpoint(generator.fork().release_value_but_fixme_should_propagate_errors(), endpoint);
HashMap<DeprecatedString, int> message_ids = build_message_ids_for_endpoint(generator.fork(), endpoint);
for (auto const& message : endpoint.messages) {
DeprecatedString response_name;
if (message.is_synchronous) {
response_name = message.response_name();
do_message(generator.fork().release_value_but_fixme_should_propagate_errors(), response_name, message.outputs);
do_message(generator.fork(), response_name, message.outputs);
}
do_message(generator.fork().release_value_but_fixme_should_propagate_errors(), message.name, message.inputs, response_name);
do_message(generator.fork(), message.name, message.inputs, response_name);
}
generator.appendln(R"~~~(
@ -570,7 +570,7 @@ public:
{ })~~~");
for (auto const& message : endpoint.messages)
do_message_for_proxy(generator.fork().release_value_but_fixme_should_propagate_errors(), endpoint, message);
do_message_for_proxy(generator.fork(), endpoint, message);
generator.appendln(R"~~~(
private:
@ -612,7 +612,7 @@ public:
for (auto const& message : endpoint.messages) {
auto do_decode_message = [&](DeprecatedString const& name) {
auto message_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto message_generator = generator.fork();
message_generator.set("message.name", name);
message_generator.set("message.pascal_name", pascal_case(name));
@ -656,7 +656,7 @@ public:
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 message_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto message_generator = generator.fork();
StringBuilder argument_generator;
for (size_t i = 0; i < parameters.size(); ++i) {
@ -707,7 +707,7 @@ public:
})~~~");
for (auto const& message : endpoint.messages) {
auto message_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto message_generator = generator.fork();
auto do_handle_message_decl = [&](DeprecatedString const& name, Vector<Parameter> const& parameters, bool is_response) {
DeprecatedString return_type = "void";
@ -733,7 +733,7 @@ public:
for (size_t i = 0; i < parameters.size(); ++i) {
auto const& parameter = parameters[i];
auto argument_generator = message_generator.fork().release_value_but_fixme_should_propagate_errors();
auto argument_generator = message_generator.fork();
argument_generator.set("argument.type", make_argument_type(parameter.type));
argument_generator.set("argument.name", parameter.name);
argument_generator.append("[[maybe_unused]] @argument.type@ @argument.name@");
@ -791,7 +791,7 @@ void build(StringBuilder& builder, Vector<Endpoint> const& endpoints)
#endif)~~~");
for (auto const& endpoint : endpoints)
build_endpoint(generator.fork().release_value_but_fixme_should_propagate_errors(), endpoint);
build_endpoint(generator.fork(), endpoint);
}
ErrorOr<int> serenity_main(Main::Arguments arguments)

View file

@ -375,7 +375,7 @@ ErrorOr<void> generate_header_file(JsonObject& api_data, Core::File& file)
auto function_definitions = create_function_definitions(function_name, function);
for (auto const& function_definition : function_definitions) {
auto function_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto function_generator = generator.fork();
function_generator.set("name", function_definition.name);
function_generator.set("return_type", function_definition.return_type);
@ -387,7 +387,7 @@ ErrorOr<void> generate_header_file(JsonObject& api_data, Core::File& file)
if (!argument_definition.name.has_value() || !argument_definition.cpp_type.has_value())
continue;
auto argument_generator = function_generator.fork().release_value_but_fixme_should_propagate_errors();
auto argument_generator = function_generator.fork();
argument_generator.set("argument_type", argument_definition.cpp_type.value());
argument_generator.set("argument_name", argument_definition.name.value());
@ -426,7 +426,7 @@ ErrorOr<void> generate_implementation_file(JsonObject& api_data, Core::File& fil
auto function_definitions = create_function_definitions(function_name, function);
for (auto const& function_definition : function_definitions) {
auto function_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto function_generator = generator.fork();
auto return_type = function_definition.return_type;
function_generator.set("name"sv, function_definition.name);
@ -441,7 +441,7 @@ ErrorOr<void> generate_implementation_file(JsonObject& api_data, Core::File& fil
if (!argument_definition.name.has_value() || !argument_definition.cpp_type.has_value())
continue;
auto argument_generator = function_generator.fork().release_value_but_fixme_should_propagate_errors();
auto argument_generator = function_generator.fork();
argument_generator.set("argument_type", argument_definition.cpp_type.value());
argument_generator.set("argument_name", argument_definition.name.value());
@ -504,7 +504,7 @@ ErrorOr<void> generate_implementation_file(JsonObject& api_data, Core::File& fil
first = true;
for (auto const& argument_definition : function_definition.arguments) {
auto argument_generator = function_generator.fork().release_value_but_fixme_should_propagate_errors();
auto argument_generator = function_generator.fork();
auto cast_to = argument_definition.cast_to;
argument_generator.set("argument_name", argument_definition.name.value_or(""));

View file

@ -230,7 +230,7 @@ static DeprecatedString make_input_acceptable_cpp(DeprecatedString const& input)
static void generate_include_for_iterator(auto& generator, auto& iterator_path)
{
auto iterator_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto iterator_generator = generator.fork();
iterator_generator.set("iterator_class.path", iterator_path);
// FIXME: These may or may not exist, because REASONS.
iterator_generator.append(R"~~~(
@ -242,7 +242,7 @@ static void generate_include_for_iterator(auto& generator, auto& iterator_path)
static void generate_include_for(auto& generator, auto& path)
{
auto forked_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto forked_generator = generator.fork();
auto path_string = path;
for (auto& search_path : s_header_search_paths) {
if (!path.starts_with(search_path))
@ -396,7 +396,7 @@ static void generate_to_new_string(SourceGenerator& scoped_generator, ParameterT
template<typename ParameterType>
static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter, DeprecatedString const& js_name, DeprecatedString const& js_suffix, DeprecatedString const& cpp_name, IDL::Interface const& interface, bool legacy_null_to_empty_string = false, bool optional = false, Optional<DeprecatedString> optional_default_value = {}, bool variadic = false, size_t recursion_depth = 0)
{
auto scoped_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto scoped_generator = generator.fork();
auto acceptable_cpp_name = make_input_acceptable_cpp(cpp_name);
scoped_generator.set("cpp_name", acceptable_cpp_name);
scoped_generator.set("js_name", js_name);
@ -708,7 +708,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
}
}
} else if (interface.enumerations.contains(parameter.type->name())) {
auto enum_generator = scoped_generator.fork().release_value_but_fixme_should_propagate_errors();
auto enum_generator = scoped_generator.fork();
auto& enumeration = interface.enumerations.find(parameter.type->name())->value;
StringView enum_member_name;
if (optional_default_value.has_value()) {
@ -769,7 +769,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
} else if (interface.dictionaries.contains(parameter.type->name())) {
if (optional_default_value.has_value() && optional_default_value != "{}")
TODO();
auto dictionary_generator = scoped_generator.fork().release_value_but_fixme_should_propagate_errors();
auto dictionary_generator = scoped_generator.fork();
dictionary_generator.append(R"~~~(
if (!@js_name@@js_suffix@.is_nullish() && !@js_name@@js_suffix@.is_object())
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@");
@ -834,7 +834,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
} else if (interface.callback_functions.contains(parameter.type->name())) {
// https://webidl.spec.whatwg.org/#es-callback-function
auto callback_function_generator = scoped_generator.fork().release_value_but_fixme_should_propagate_errors();
auto callback_function_generator = scoped_generator.fork();
auto& callback_function = interface.callback_functions.find(parameter.type->name())->value;
if (callback_function.return_type->is_object() && callback_function.return_type->name() == "Promise")
@ -865,7 +865,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
} else if (parameter.type->name() == "sequence") {
// https://webidl.spec.whatwg.org/#es-sequence
auto sequence_generator = scoped_generator.fork().release_value_but_fixme_should_propagate_errors();
auto sequence_generator = scoped_generator.fork();
auto& parameterized_type = verify_cast<IDL::ParameterizedType>(*parameter.type);
sequence_generator.set("recursion_depth", DeprecatedString::number(recursion_depth));
@ -930,7 +930,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
} else if (parameter.type->name() == "record") {
// https://webidl.spec.whatwg.org/#es-record
auto record_generator = scoped_generator.fork().release_value_but_fixme_should_propagate_errors();
auto record_generator = scoped_generator.fork();
auto& parameterized_type = verify_cast<IDL::ParameterizedType>(*parameter.type);
record_generator.set("recursion_depth", DeprecatedString::number(recursion_depth));
@ -999,7 +999,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
} else if (is<IDL::UnionType>(*parameter.type)) {
// https://webidl.spec.whatwg.org/#es-union
auto union_generator = scoped_generator.fork().release_value_but_fixme_should_propagate_errors();
auto union_generator = scoped_generator.fork();
auto& union_type = verify_cast<IDL::UnionType>(*parameter.type);
union_generator.set("union_type", union_type_to_variant(union_type, interface));
@ -1023,7 +1023,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
}
if (dictionary_type) {
auto dictionary_generator = union_generator.fork().release_value_but_fixme_should_propagate_errors();
auto dictionary_generator = union_generator.fork();
dictionary_generator.set("dictionary.type", dictionary_type->name());
// The lambda must take the JS::Value to convert as a parameter instead of capturing it in order to support union types being variadic.
@ -1121,7 +1121,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
if (!IDL::is_platform_object(type))
continue;
auto union_platform_object_type_generator = union_generator.fork().release_value_but_fixme_should_propagate_errors();
auto union_platform_object_type_generator = union_generator.fork();
union_platform_object_type_generator.set("platform_object_type", type->name());
union_platform_object_type_generator.append(R"~~~(
@ -1349,7 +1349,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
// 3. Assert: Type(x) is Number.
// 4. Return the result of converting x to T.
auto union_numeric_type_generator = union_generator.fork().release_value_but_fixme_should_propagate_errors();
auto union_numeric_type_generator = union_generator.fork();
auto cpp_type = IDL::idl_type_name_to_cpp_type(*numeric_type, interface);
union_numeric_type_generator.set("numeric_type", cpp_type.name);
@ -1464,7 +1464,7 @@ static void generate_argument_count_check(SourceGenerator& generator, Deprecated
if (argument_count == 0)
return;
auto argument_count_check_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto argument_count_check_generator = generator.fork();
argument_count_check_generator.set("function.name", function_name);
argument_count_check_generator.set("function.nargs", DeprecatedString::number(argument_count));
@ -1484,7 +1484,7 @@ static void generate_argument_count_check(SourceGenerator& generator, Deprecated
static void generate_arguments(SourceGenerator& generator, Vector<IDL::Parameter> const& parameters, StringBuilder& arguments_builder, IDL::Interface const& interface)
{
auto arguments_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto arguments_generator = generator.fork();
Vector<DeprecatedString> parameter_names;
size_t argument_index = 0;
@ -1515,7 +1515,7 @@ static void generate_arguments(SourceGenerator& generator, Vector<IDL::Parameter
// https://webidl.spec.whatwg.org/#create-sequence-from-iterable
void IDL::ParameterizedType::generate_sequence_from_iterable(SourceGenerator& generator, DeprecatedString const& cpp_name, DeprecatedString const& iterable_cpp_name, DeprecatedString const& iterator_method_cpp_name, IDL::Interface const& interface, size_t recursion_depth) const
{
auto sequence_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto sequence_generator = generator.fork();
sequence_generator.set("cpp_name", cpp_name);
sequence_generator.set("iterable_cpp_name", iterable_cpp_name);
sequence_generator.set("iterator_method_cpp_name", iterator_method_cpp_name);
@ -1575,7 +1575,7 @@ enum class WrappingReference {
static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString const& value, IDL::Type const& type, IDL::Interface const& interface, StringView result_expression, WrappingReference wrapping_reference = WrappingReference::No, size_t recursion_depth = 0)
{
auto scoped_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto scoped_generator = generator.fork();
scoped_generator.set("value", value);
if (!libweb_interface_namespaces.span().contains_slow(type.name())) {
if (is_javascript_builtin(type))
@ -1718,7 +1718,7 @@ static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString
} else if (is<IDL::UnionType>(type)) {
auto& union_type = verify_cast<IDL::UnionType>(type);
auto union_types = union_type.flattened_member_types();
auto union_generator = scoped_generator.fork().release_value_but_fixme_should_propagate_errors();
auto union_generator = scoped_generator.fork();
union_generator.append(R"~~~(
@result_expression@ @value@.visit(
@ -1795,7 +1795,7 @@ static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString
}
} else if (interface.dictionaries.contains(type.name())) {
// https://webidl.spec.whatwg.org/#es-dictionary
auto dictionary_generator = scoped_generator.fork().release_value_but_fixme_should_propagate_errors();
auto dictionary_generator = scoped_generator.fork();
dictionary_generator.append(R"~~~(
auto dictionary_object@recursion_depth@ = JS::Object::create(realm, realm.intrinsics().object_prototype());
@ -1863,7 +1863,7 @@ static void generate_return_statement(SourceGenerator& generator, IDL::Type cons
static void generate_variable_statement(SourceGenerator& generator, DeprecatedString const& variable_name, IDL::Type const& value_type, DeprecatedString const& value_name, IDL::Interface const& interface)
{
auto variable_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto variable_generator = generator.fork();
variable_generator.set("variable_name", variable_name);
variable_generator.append(R"~~~(
JS::Value @variable_name@;
@ -1873,7 +1873,7 @@ static void generate_variable_statement(SourceGenerator& generator, DeprecatedSt
static void generate_function(SourceGenerator& generator, IDL::Function const& function, StaticFunction is_static_function, DeprecatedString const& class_name, DeprecatedString const& interface_fully_qualified_name, IDL::Interface const& interface)
{
auto function_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto function_generator = generator.fork();
function_generator.set("class_name", class_name);
function_generator.set("interface_fully_qualified_name", interface_fully_qualified_name);
function_generator.set("function.name:snakecase", make_input_acceptable_cpp(function.name.to_snakecase()));
@ -2128,7 +2128,7 @@ static DeprecatedString generate_constructor_for_idl_type(Type const& type)
static void generate_overload_arbiter(SourceGenerator& generator, auto const& overload_set, DeprecatedString const& class_name)
{
auto function_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto function_generator = generator.fork();
function_generator.set("class_name", class_name);
function_generator.set("function.name:snakecase", make_input_acceptable_cpp(overload_set.key.to_snakecase()));
@ -2249,7 +2249,7 @@ static void generate_prototype_or_global_mixin_declarations(IDL::Interface const
SourceGenerator generator { builder };
for (auto const& overload_set : interface.overload_sets) {
auto function_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto function_generator = generator.fork();
function_generator.set("function.name:snakecase", make_input_acceptable_cpp(overload_set.key.to_snakecase()));
function_generator.append(R"~~~(
JS_DECLARE_NATIVE_FUNCTION(@function.name:snakecase@);
@ -2265,14 +2265,14 @@ static void generate_prototype_or_global_mixin_declarations(IDL::Interface const
}
if (interface.has_stringifier) {
auto stringifier_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto stringifier_generator = generator.fork();
stringifier_generator.append(R"~~~(
JS_DECLARE_NATIVE_FUNCTION(to_string);
)~~~");
}
if (interface.pair_iterator_types.has_value()) {
auto iterator_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto iterator_generator = generator.fork();
iterator_generator.append(R"~~~(
JS_DECLARE_NATIVE_FUNCTION(entries);
JS_DECLARE_NATIVE_FUNCTION(for_each);
@ -2282,7 +2282,7 @@ static void generate_prototype_or_global_mixin_declarations(IDL::Interface const
}
for (auto& attribute : interface.attributes) {
auto attribute_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto attribute_generator = generator.fork();
attribute_generator.set("attribute.name:snakecase", attribute.name.to_snakecase());
attribute_generator.append(R"~~~(
JS_DECLARE_NATIVE_FUNCTION(@attribute.name:snakecase@_getter);
@ -2304,7 +2304,7 @@ static void generate_prototype_or_global_mixin_declarations(IDL::Interface const
for (auto& it : interface.enumerations) {
if (!it.value.is_original_definition)
continue;
auto enum_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto enum_generator = generator.fork();
enum_generator.set("enum.type.name", it.key);
enum_generator.append(R"~~~(
enum class @enum.type.name@ {
@ -2420,7 +2420,7 @@ static void collect_attribute_values_of_an_inheritance_stack(SourceGenerator& fu
if (!attribute.type->is_json(interface_in_chain))
continue;
auto attribute_generator = function_generator.fork().release_value_but_fixme_should_propagate_errors();
auto attribute_generator = function_generator.fork();
auto return_value_name = DeprecatedString::formatted("{}_retval", attribute.name.to_snakecase());
attribute_generator.set("attribute.name", attribute.name);
@ -2468,7 +2468,7 @@ static void collect_attribute_values_of_an_inheritance_stack(SourceGenerator& fu
}
for (auto& constant : interface_in_chain.constants) {
auto constant_generator = function_generator.fork().release_value_but_fixme_should_propagate_errors();
auto constant_generator = function_generator.fork();
constant_generator.set("constant.name", constant.name);
generate_wrap_statement(constant_generator, constant.value, constant.type, interface_in_chain, DeprecatedString::formatted("auto constant_{}_value =", constant.name));
@ -2485,7 +2485,7 @@ static void generate_default_to_json_function(SourceGenerator& generator, Deprec
{
// NOTE: This is done heavily out of order since the spec mixes parse time and run time type information together.
auto function_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto function_generator = generator.fork();
function_generator.set("class_name", class_name);
// 4. Let result be OrdinaryObjectCreate(%Object.prototype%).
@ -2582,7 +2582,7 @@ void @class_name@::initialize(JS::Realm& realm)
// https://webidl.spec.whatwg.org/#es-attributes
for (auto& attribute : interface.attributes) {
auto attribute_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto attribute_generator = generator.fork();
attribute_generator.set("attribute.name", attribute.name);
attribute_generator.set("attribute.getter_callback", attribute.getter_callback_name);
@ -2606,7 +2606,7 @@ void @class_name@::initialize(JS::Realm& realm)
for (auto& constant : interface.constants) {
// FIXME: Do constants need to be added to the unscopable list?
auto constant_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto constant_generator = generator.fork();
constant_generator.set("constant.name", constant.name);
generate_wrap_statement(constant_generator, constant.value, constant.type, interface, DeprecatedString::formatted("auto constant_{}_value =", constant.name));
@ -2618,7 +2618,7 @@ void @class_name@::initialize(JS::Realm& realm)
// https://webidl.spec.whatwg.org/#es-operations
for (auto const& overload_set : interface.overload_sets) {
auto function_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto function_generator = generator.fork();
function_generator.set("function.name", overload_set.key);
function_generator.set("function.name:snakecase", make_input_acceptable_cpp(overload_set.key.to_snakecase()));
function_generator.set("function.length", DeprecatedString::number(get_shortest_function_length(overload_set.value)));
@ -2638,7 +2638,7 @@ void @class_name@::initialize(JS::Realm& realm)
if (interface.has_stringifier) {
// FIXME: Do stringifiers need to be added to the unscopable list?
auto stringifier_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto stringifier_generator = generator.fork();
stringifier_generator.append(R"~~~(
define_native_function(realm, "toString", to_string, 0, default_attributes);
)~~~");
@ -2647,7 +2647,7 @@ void @class_name@::initialize(JS::Realm& realm)
// https://webidl.spec.whatwg.org/#define-the-iteration-methods
// This applies to this if block and the following if block.
if (interface.indexed_property_getter.has_value()) {
auto iterator_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto iterator_generator = generator.fork();
iterator_generator.append(R"~~~(
define_direct_property(vm.well_known_symbol_iterator(), realm.intrinsics().array_prototype()->get_without_side_effects(vm.names.values), JS::Attribute::Configurable | JS::Attribute::Writable);
)~~~");
@ -2665,7 +2665,7 @@ void @class_name@::initialize(JS::Realm& realm)
if (interface.pair_iterator_types.has_value()) {
// FIXME: Do pair iterators need to be added to the unscopable list?
auto iterator_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto iterator_generator = generator.fork();
iterator_generator.append(R"~~~(
define_native_function(realm, vm.names.entries, entries, 0, default_attributes);
define_native_function(realm, vm.names.forEach, for_each, 1, default_attributes);
@ -2728,7 +2728,7 @@ static JS::ThrowCompletionOr<@fully_qualified_name@*> impl_from(JS::VM& vm)
}
for (auto& attribute : interface.attributes) {
auto attribute_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto attribute_generator = generator.fork();
attribute_generator.set("attribute.name", attribute.name);
attribute_generator.set("attribute.getter_callback", attribute.getter_callback_name);
attribute_generator.set("attribute.setter_callback", attribute.setter_callback_name);
@ -2950,7 +2950,7 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.setter_callback@)
}
if (interface.has_stringifier) {
auto stringifier_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto stringifier_generator = generator.fork();
stringifier_generator.set("class_name", class_name);
if (interface.stringifier_attribute.has_value())
stringifier_generator.set("attribute.cpp_getter_name", interface.stringifier_attribute->to_snakecase());
@ -2985,7 +2985,7 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::to_string)
}
if (interface.pair_iterator_types.has_value()) {
auto iterator_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto iterator_generator = generator.fork();
iterator_generator.append(R"~~~(
JS_DEFINE_NATIVE_FUNCTION(@class_name@::entries)
{
@ -3064,7 +3064,7 @@ private:
}
for (auto const& overload_set : interface.overload_sets) {
auto function_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto function_generator = generator.fork();
function_generator.set("function.name:snakecase", make_input_acceptable_cpp(overload_set.key.to_snakecase()));
function_generator.append(R"~~~(
JS_DECLARE_NATIVE_FUNCTION(@function.name:snakecase@);
@ -3162,7 +3162,7 @@ void @namespace_class@::initialize(JS::Realm& realm)
// https://webidl.spec.whatwg.org/#es-operations
for (auto const& overload_set : interface.overload_sets) {
auto function_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto function_generator = generator.fork();
function_generator.set("function.name", overload_set.key);
function_generator.set("function.name:snakecase", make_input_acceptable_cpp(overload_set.key.to_snakecase()));
function_generator.set("function.length", DeprecatedString::number(get_shortest_function_length(overload_set.value)));
@ -3227,7 +3227,7 @@ private:
)~~~");
for (auto const& overload_set : interface.static_overload_sets) {
auto function_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto function_generator = generator.fork();
function_generator.set("function.name:snakecase", make_input_acceptable_cpp(overload_set.key.to_snakecase()));
function_generator.append(R"~~~(
JS_DECLARE_NATIVE_FUNCTION(@function.name:snakecase@);
@ -3557,7 +3557,7 @@ void @constructor_class@::initialize(JS::Realm& realm)
)~~~");
for (auto& constant : interface.constants) {
auto constant_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto constant_generator = generator.fork();
constant_generator.set("constant.name", constant.name);
generate_wrap_statement(constant_generator, constant.value, constant.type, interface, DeprecatedString::formatted("auto constant_{}_value =", constant.name));
@ -3569,7 +3569,7 @@ void @constructor_class@::initialize(JS::Realm& realm)
// https://webidl.spec.whatwg.org/#es-operations
for (auto const& overload_set : interface.static_overload_sets) {
auto function_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto function_generator = generator.fork();
function_generator.set("function.name", overload_set.key);
function_generator.set("function.name:snakecase", make_input_acceptable_cpp(overload_set.key.to_snakecase()));
function_generator.set("function.length", DeprecatedString::number(get_shortest_function_length(overload_set.value)));

View file

@ -55,7 +55,7 @@ namespace Web::ARIA {
VERIFY(value.is_object());
JsonObject const& value_object = value.as_object();
auto class_definition_generator = TRY(generator.fork());
auto class_definition_generator = generator.fork();
class_definition_generator.set("spec_link"sv, value_object.get_deprecated_string("specLink"sv).value());
class_definition_generator.set("description"sv, value_object.get_deprecated_string("description"sv).value());
class_definition_generator.set("name"sv, name);
@ -129,7 +129,7 @@ ErrorOr<String> generate_hash_table_population(JsonArray const& values, StringVi
ErrorOr<void> generate_hash_table_member(SourceGenerator& generator, StringView member_name, StringView hash_table_name, StringView enum_class, JsonArray const& values)
{
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("member_name"sv, member_name);
member_generator.set("hash_table_name"sv, hash_table_name);
member_generator.set("enum_class"sv, enum_class);
@ -292,7 +292,7 @@ namespace Web::ARIA {
TRY(roles_data.try_for_each_member([&](auto& name, auto& value) -> ErrorOr<void> {
VERIFY(value.is_object());
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name"sv, name);
JsonObject const& value_object = value.as_object();
@ -359,7 +359,7 @@ DefaultValueType @name@::default_value_for_property_or_state(StateAndProperties
switch (state_or_property) {
)~~~");
TRY(implicit_value_for_role.try_for_each_member([&](auto& name, auto& value) -> ErrorOr<void> {
auto case_generator = TRY(member_generator.fork());
auto case_generator = member_generator.fork();
VERIFY(value.is_string());
case_generator.set("state_or_property"sv, aria_name_to_enum_name(name));
case_generator.set("implicit_value"sv, value.as_string());

View file

@ -57,7 +57,7 @@ namespace Web::CSS {
generator.appendln("enum class EasingFunction {");
TRY(easing_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr<void> {
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name:titlecase", TRY(title_casify(name)));
member_generator.appendln(" @name:titlecase@,");
return {};
@ -109,7 +109,7 @@ Optional<EasingFunction> easing_function_from_string(StringView name)
{
)~~~");
TRY(easing_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr<void> {
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name", TRY(String::from_deprecated_string(name)));
member_generator.set("name:titlecase", TRY(title_casify(name)));
member_generator.append(R"~~~(
@ -129,7 +129,7 @@ StringView to_string(EasingFunction easing_function)
switch (easing_function) {
)~~~");
TRY(easing_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr<void> {
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name", TRY(String::from_deprecated_string(name)));
member_generator.set("name:titlecase", TRY(title_casify(name)));
member_generator.append(R"~~~(
@ -153,7 +153,7 @@ EasingFunctionMetadata easing_function_metadata(EasingFunction easing_function)
TRY(easing_data.try_for_each_member([&](auto& name, auto& value) -> ErrorOr<void> {
VERIFY(value.is_object());
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name:titlecase", TRY(title_casify(name)));
member_generator.append(R"~~~(
case EasingFunction::@name:titlecase@:

View file

@ -58,7 +58,7 @@ enum class ValueID;
VERIFY(value.is_array());
auto& members = value.as_array();
auto enum_generator = TRY(generator.fork());
auto enum_generator = generator.fork();
enum_generator.set("name:titlecase", TRY(title_casify(name)));
enum_generator.set("name:snakecase", TRY(snake_casify(name)));
@ -81,7 +81,7 @@ enum class ValueID;
// Don't include aliases in the enum.
if (member_name.contains('='))
continue;
auto member_generator = TRY(enum_generator.fork());
auto member_generator = enum_generator.fork();
member_generator.set("member:titlecase", TRY(title_casify(member_name)));
member_generator.appendln(" @member:titlecase@,");
}
@ -116,7 +116,7 @@ namespace Web::CSS {
VERIFY(value.is_array());
auto& members = value.as_array();
auto enum_generator = TRY(generator.fork());
auto enum_generator = generator.fork();
enum_generator.set("name:titlecase", TRY(title_casify(name)));
enum_generator.set("name:snakecase", TRY(snake_casify(name)));
@ -126,7 +126,7 @@ Optional<@name:titlecase@> value_id_to_@name:snakecase@(ValueID value_id)
switch (value_id) {)~~~");
for (auto& member : members.values()) {
auto member_generator = TRY(enum_generator.fork());
auto member_generator = enum_generator.fork();
auto member_name = member.to_deprecated_string();
if (member_name.contains('=')) {
auto parts = member_name.split_view('=');
@ -154,7 +154,7 @@ ValueID to_value_id(@name:titlecase@ @name:snakecase@_value)
switch (@name:snakecase@_value) {)~~~");
for (auto& member : members.values()) {
auto member_generator = TRY(enum_generator.fork());
auto member_generator = enum_generator.fork();
auto member_name = member.to_deprecated_string();
if (member_name.contains('='))
continue;
@ -178,7 +178,7 @@ StringView to_string(@name:titlecase@ value)
switch (value) {)~~~");
for (auto& member : members.values()) {
auto member_generator = TRY(enum_generator.fork());
auto member_generator = enum_generator.fork();
auto member_name = member.to_deprecated_string();
if (member_name.contains('='))
continue;

View file

@ -54,7 +54,7 @@ enum class MathFunction {
)~~~");
TRY(functions_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr<void> {
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name:titlecase", TRY(title_casify(name)));
member_generator.appendln(" @name:titlecase@,"sv);
return {};
@ -154,7 +154,7 @@ OwnPtr<CalculationNode> Parser::parse_math_function(PropertyID property_id, Func
auto& function_data = value.as_object();
auto& parameters = function_data.get_array("parameters"sv).value();
auto function_generator = TRY(generator.fork());
auto function_generator = generator.fork();
function_generator.set("name:lowercase", TRY(String::from_deprecated_string(name)));
function_generator.set("name:titlecase", TRY(title_casify(name)));
function_generator.appendln(" if (function.name().equals_ignoring_ascii_case(\"@name:lowercase@\"sv)) {");
@ -235,7 +235,7 @@ OwnPtr<CalculationNode> Parser::parse_math_function(PropertyID property_id, Func
auto parameter_type_string = parameter.get_deprecated_string("type"sv).value();
auto parameter_required = parameter.get_bool("required"sv).value();
auto parameter_generator = TRY(function_generator.fork());
auto parameter_generator = function_generator.fork();
parameter_generator.set("parameter_name", TRY(String::from_deprecated_string(parameter.get_deprecated_string("name"sv).value())));
parameter_generator.set("parameter_index", TRY(String::number(parameter_index)));
@ -347,7 +347,7 @@ OwnPtr<CalculationNode> Parser::parse_math_function(PropertyID property_id, Func
auto& parameter = parameter_value.as_object();
auto parameter_type_string = parameter.get_deprecated_string("type"sv).value();
auto parameter_generator = TRY(function_generator.fork());
auto parameter_generator = function_generator.fork();
parameter_generator.set("parameter_index"sv, TRY(String::number(parameter_index)));
if (parameter_type_string == "<rounding-strategy>"sv) {

View file

@ -61,7 +61,7 @@ enum class MediaFeatureValueType {
enum class MediaFeatureID {)~~~");
TRY(media_feature_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr<void> {
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name:titlecase", TRY(title_casify(name)));
member_generator.append(R"~~~(
@name:titlecase@,)~~~");
@ -99,7 +99,7 @@ Optional<MediaFeatureID> media_feature_id_from_string(StringView string)
{)~~~");
TRY(media_feature_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr<void> {
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name", TRY(String::from_deprecated_string(name)));
member_generator.set("name:titlecase", TRY(title_casify(name)));
member_generator.append(R"~~~(
@ -118,7 +118,7 @@ StringView string_from_media_feature_id(MediaFeatureID media_feature_id)
switch (media_feature_id) {)~~~");
TRY(media_feature_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr<void> {
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name", TRY(String::from_deprecated_string(name)));
member_generator.set("name:titlecase", TRY(title_casify(name)));
member_generator.append(R"~~~(
@ -140,7 +140,7 @@ bool media_feature_type_is_range(MediaFeatureID media_feature_id)
VERIFY(value.is_object());
auto& feature = value.as_object();
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name:titlecase", TRY(title_casify(name)));
VERIFY(feature.has("type"sv));
auto feature_type = feature.get_deprecated_string("type"sv);
@ -165,7 +165,7 @@ bool media_feature_accepts_type(MediaFeatureID media_feature_id, MediaFeatureVal
VERIFY(member.is_object());
auto& feature = member.as_object();
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name:titlecase", TRY(title_casify(name)));
member_generator.append(R"~~~(
case MediaFeatureID::@name:titlecase@:)~~~");
@ -245,7 +245,7 @@ bool media_feature_accepts_identifier(MediaFeatureID media_feature_id, ValueID i
VERIFY(member.is_object());
auto& feature = member.as_object();
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name:titlecase", TRY(title_casify(name)));
member_generator.append(R"~~~(
case MediaFeatureID::@name:titlecase@:)~~~");
@ -271,7 +271,7 @@ bool media_feature_accepts_identifier(MediaFeatureID media_feature_id, ValueID i
continue;
TRY(append_identifier_switch_if_needed());
auto ident_generator = TRY(member_generator.fork());
auto ident_generator = member_generator.fork();
ident_generator.set("identifier:titlecase", TRY(title_casify(identifier_name)));
ident_generator.append(R"~~~(
case ValueID::@identifier:titlecase@:

View file

@ -123,7 +123,7 @@ enum class PropertyID {
auto last_property_id = longhand_property_ids.last();
for (auto& name : shorthand_property_ids) {
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name:titlecase", TRY(title_casify(name)));
member_generator.append(R"~~~(
@ -132,7 +132,7 @@ enum class PropertyID {
}
for (auto& name : longhand_property_ids) {
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name:titlecase", TRY(title_casify(name)));
member_generator.append(R"~~~(
@ -231,7 +231,7 @@ struct Traits<Web::CSS::PropertyID> : public GenericTraits<Web::CSS::PropertyID>
ErrorOr<void> generate_bounds_checking_function(JsonObject& properties, SourceGenerator& parent_generator, StringView css_type_name, StringView type_name, Optional<StringView> default_unit_name, Optional<StringView> value_getter)
{
auto generator = TRY(parent_generator.fork());
auto generator = parent_generator.fork();
generator.set("css_type_name", TRY(String::from_utf8(css_type_name)));
generator.set("type_name", TRY(String::from_utf8(type_name)));
@ -249,7 +249,7 @@ bool property_accepts_@css_type_name@(PropertyID property_id, [[maybe_unused]] @
if (type_and_range.first() != css_type_name)
continue;
auto property_generator = TRY(generator.fork());
auto property_generator = generator.fork();
property_generator.set("property_name:titlecase", TRY(title_casify(name)));
property_generator.append(R"~~~(
@ -345,7 +345,7 @@ Optional<PropertyID> property_id_from_camel_case_string(StringView string)
TRY(properties.try_for_each_member([&](auto& name, auto& value) -> ErrorOr<void> {
VERIFY(value.is_object());
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name", TRY(String::from_deprecated_string(name)));
member_generator.set("name:titlecase", TRY(title_casify(name)));
member_generator.set("name:camelcase", TRY(camel_casify(name)));
@ -369,7 +369,7 @@ Optional<PropertyID> property_id_from_string(StringView string)
TRY(properties.try_for_each_member([&](auto& name, auto& value) -> ErrorOr<void> {
VERIFY(value.is_object());
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name", TRY(String::from_deprecated_string(name)));
member_generator.set("name:titlecase", TRY(title_casify(name)));
member_generator.append(R"~~~(
@ -390,7 +390,7 @@ StringView string_from_property_id(PropertyID property_id) {
TRY(properties.try_for_each_member([&](auto& name, auto& value) -> ErrorOr<void> {
VERIFY(value.is_object());
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name", TRY(String::from_deprecated_string(name)));
member_generator.set("name:titlecase", TRY(title_casify(name)));
member_generator.append(R"~~~(
@ -422,7 +422,7 @@ bool is_inherited_property(PropertyID property_id)
}
if (inherited) {
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name:titlecase", TRY(title_casify(name)));
member_generator.append(R"~~~(
case PropertyID::@name:titlecase@:
@ -451,7 +451,7 @@ bool property_affects_layout(PropertyID property_id)
affects_layout = value.as_object().get_bool("affects-layout"sv).value_or(false);
if (affects_layout) {
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name:titlecase", TRY(title_casify(name)));
member_generator.append(R"~~~(
case PropertyID::@name:titlecase@:
@ -480,7 +480,7 @@ bool property_affects_stacking_context(PropertyID property_id)
affects_stacking_context = value.as_object().get_bool("affects-stacking-context"sv).value_or(false);
if (affects_stacking_context) {
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name:titlecase", TRY(title_casify(name)));
member_generator.append(R"~~~(
case PropertyID::@name:titlecase@:
@ -519,7 +519,7 @@ NonnullRefPtr<StyleValue> property_initial_value(JS::Realm& context_realm, Prope
VERIFY(initial_value.has_value());
auto& initial_value_string = initial_value.value();
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name:titlecase", TRY(title_casify(name)));
member_generator.set("initial_value_string", TRY(String::from_deprecated_string(initial_value_string)));
member_generator.append(
@ -560,7 +560,7 @@ bool property_has_quirk(PropertyID property_id, Quirk quirk)
auto& quirks = quirks_value.value();
if (!quirks.is_empty()) {
auto property_generator = TRY(generator.fork());
auto property_generator = generator.fork();
property_generator.set("name:titlecase", TRY(title_casify(name)));
property_generator.append(R"~~~(
case PropertyID::@name:titlecase@: {
@ -568,7 +568,7 @@ bool property_has_quirk(PropertyID property_id, Quirk quirk)
)~~~");
for (auto& quirk : quirks.values()) {
VERIFY(quirk.is_string());
auto quirk_generator = TRY(property_generator.fork());
auto quirk_generator = property_generator.fork();
quirk_generator.set("quirk:titlecase", TRY(title_casify(quirk.as_string())));
quirk_generator.append(R"~~~(
case Quirk::@quirk:titlecase@:
@ -601,7 +601,7 @@ bool property_accepts_type(PropertyID property_id, ValueType value_type)
auto& object = value.as_object();
if (auto maybe_valid_types = object.get_array("valid-types"sv); maybe_valid_types.has_value() && !maybe_valid_types->is_empty()) {
auto& valid_types = maybe_valid_types.value();
auto property_generator = TRY(generator.fork());
auto property_generator = generator.fork();
property_generator.set("name:titlecase", TRY(title_casify(name)));
property_generator.append(R"~~~(
case PropertyID::@name:titlecase@: {
@ -681,7 +681,7 @@ bool property_accepts_identifier(PropertyID property_id, ValueID identifier)
VERIFY(value.is_object());
auto& object = value.as_object();
auto property_generator = TRY(generator.fork());
auto property_generator = generator.fork();
property_generator.set("name:titlecase", TRY(title_casify(name)));
property_generator.appendln(" case PropertyID::@name:titlecase@: {");
@ -689,7 +689,7 @@ bool property_accepts_identifier(PropertyID property_id, ValueID identifier)
property_generator.appendln(" switch (identifier) {");
auto& valid_identifiers = maybe_valid_identifiers.value();
for (auto& identifier : valid_identifiers.values()) {
auto identifier_generator = TRY(generator.fork());
auto identifier_generator = generator.fork();
identifier_generator.set("identifier:titlecase", TRY(title_casify(identifier.as_string())));
identifier_generator.appendln(" case ValueID::@identifier:titlecase@:");
}
@ -708,7 +708,7 @@ bool property_accepts_identifier(PropertyID property_id, ValueID identifier)
if (!type_name_is_enum(type_name))
continue;
auto type_generator = TRY(generator.fork());
auto type_generator = generator.fork();
type_generator.set("type_name:snakecase", TRY(snake_casify(type_name)));
type_generator.append(R"~~~(
if (value_id_to_@type_name:snakecase@(identifier).has_value())
@ -736,7 +736,7 @@ Optional<ValueType> property_resolves_percentages_relative_to(PropertyID propert
TRY(properties.try_for_each_member([&](auto& name, auto& value) -> ErrorOr<void> {
VERIFY(value.is_object());
if (auto resolved_type = value.as_object().get_deprecated_string("percentages-resolve-to"sv); resolved_type.has_value()) {
auto property_generator = TRY(generator.fork());
auto property_generator = generator.fork();
property_generator.set("name:titlecase", TRY(title_casify(name)));
property_generator.set("resolved_type:titlecase", TRY(title_casify(resolved_type.value())));
property_generator.append(R"~~~(
@ -763,7 +763,7 @@ size_t property_maximum_value_count(PropertyID property_id)
if (value.as_object().has("max-values"sv)) {
auto max_values = value.as_object().get("max-values"sv);
VERIFY(max_values.has_value() && max_values->is_number() && !max_values->is_double());
auto property_generator = TRY(generator.fork());
auto property_generator = generator.fork();
property_generator.set("name:titlecase", TRY(title_casify(name)));
property_generator.set("max_values", TRY(String::from_deprecated_string(max_values->to_deprecated_string())));
property_generator.append(R"~~~(
@ -799,7 +799,7 @@ Vector<PropertyID> longhands_for_shorthand(PropertyID property_id)
auto longhands = value.as_object().get("longhands"sv);
VERIFY(longhands.has_value() && longhands->is_array());
auto longhand_values = longhands->as_array();
auto property_generator = TRY(generator.fork());
auto property_generator = generator.fork();
property_generator.set("name:titlecase", TRY(title_casify(name)));
StringBuilder builder;
bool first = true;

View file

@ -54,7 +54,7 @@ enum class PseudoClass {
)~~~");
TRY(pseudo_classes_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr<void> {
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name:titlecase", TRY(title_casify(name)));
member_generator.appendln(" @name:titlecase@,");
@ -104,7 +104,7 @@ Optional<PseudoClass> pseudo_class_from_string(StringView string)
)~~~");
TRY(pseudo_classes_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr<void> {
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name", TRY(String::from_deprecated_string(name)));
member_generator.set("name:titlecase", TRY(title_casify(name)));
@ -126,7 +126,7 @@ StringView pseudo_class_name(PseudoClass pseudo_class)
)~~~");
TRY(pseudo_classes_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr<void> {
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name", TRY(String::from_deprecated_string(name)));
member_generator.set("name:titlecase", TRY(title_casify(name)));
@ -148,7 +148,7 @@ PseudoClassMetadata pseudo_class_metadata(PseudoClass pseudo_class)
)~~~");
TRY(pseudo_classes_data.try_for_each_member([&](auto& name, JsonValue const& value) -> ErrorOr<void> {
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
auto& pseudo_class = value.as_object();
auto argument_string = pseudo_class.get_deprecated_string("argument"sv).value();

View file

@ -66,7 +66,7 @@ namespace Web::CSS {
generator.appendln("enum class TransformFunction {");
TRY(transforms_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr<void> {
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name:titlecase", TRY(title_casify_transform_function(name)));
member_generator.appendln(" @name:titlecase@,");
return {};
@ -118,7 +118,7 @@ Optional<TransformFunction> transform_function_from_string(StringView name)
{
)~~~");
TRY(transforms_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr<void> {
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name", TRY(String::from_deprecated_string(name)));
member_generator.set("name:titlecase", TRY(title_casify_transform_function(name)));
member_generator.append(R"~~~(
@ -138,7 +138,7 @@ StringView to_string(TransformFunction transform_function)
switch (transform_function) {
)~~~");
TRY(transforms_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr<void> {
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name", TRY(String::from_deprecated_string(name)));
member_generator.set("name:titlecase", TRY(title_casify_transform_function(name)));
member_generator.append(R"~~~(
@ -162,7 +162,7 @@ TransformFunctionMetadata transform_function_metadata(TransformFunction transfor
TRY(transforms_data.try_for_each_member([&](auto& name, auto& value) -> ErrorOr<void> {
VERIFY(value.is_object());
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name:titlecase", TRY(title_casify_transform_function(name)));
member_generator.append(R"~~~(
case TransformFunction::@name:titlecase@:

View file

@ -56,7 +56,7 @@ enum class ValueID {
)~~~");
TRY(identifier_data.try_for_each([&](auto& name) -> ErrorOr<void> {
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name:titlecase", TRY(title_casify(name.to_deprecated_string())));
member_generator.append(R"~~~(
@ -95,7 +95,7 @@ HashMap<StringView, ValueID, AK::CaseInsensitiveASCIIStringViewTraits> g_stringv
)~~~");
TRY(identifier_data.try_for_each([&](auto& name) -> ErrorOr<void> {
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name", TRY(String::from_deprecated_string(name.to_deprecated_string())));
member_generator.set("name:titlecase", TRY(title_casify(name.to_deprecated_string())));
member_generator.append(R"~~~(
@ -117,7 +117,7 @@ StringView string_from_value_id(ValueID value_id) {
)~~~");
TRY(identifier_data.try_for_each([&](auto& name) -> ErrorOr<void> {
auto member_generator = TRY(generator.fork());
auto member_generator = generator.fork();
member_generator.set("name", TRY(String::from_deprecated_string(name.to_deprecated_string())));
member_generator.set("name:titlecase", TRY(title_casify(name.to_deprecated_string())));
member_generator.append(R"~~~(

View file

@ -92,7 +92,7 @@ class @legacy_constructor_class@;)~~~");
};
for (auto& interface : exposed_interfaces) {
auto gen = TRY(generator.fork());
auto gen = generator.fork();
if (interface.is_namespace)
add_namespace(gen, interface.namespace_class);
@ -123,7 +123,7 @@ static ErrorOr<void> generate_intrinsic_definitions(StringView output_path, Vect
#include <LibWeb/Bindings/Intrinsics.h>)~~~");
for (auto& interface : exposed_interfaces) {
auto gen = TRY(generator.fork());
auto gen = generator.fork();
gen.set("namespace_class", interface.namespace_class);
gen.set("prototype_class", interface.prototype_class);
gen.set("constructor_class", interface.constructor_class);
@ -215,7 +215,7 @@ void Intrinsics::create_web_prototype_and_constructor<@prototype_class@>(JS::Rea
};
for (auto& interface : exposed_interfaces) {
auto gen = TRY(generator.fork());
auto gen = generator.fork();
if (interface.is_namespace)
add_namespace(gen, interface.name, interface.namespace_class);
@ -274,7 +274,7 @@ static ErrorOr<void> generate_exposed_interface_implementation(StringView class_
#include <LibWeb/Bindings/@global_object_name@ExposedInterfaces.h>
)~~~");
for (auto& interface : exposed_interfaces) {
auto gen = TRY(generator.fork());
auto gen = generator.fork();
gen.set("namespace_class", interface.namespace_class);
gen.set("prototype_class", interface.prototype_class);
gen.set("constructor_class", interface.constructor_class);
@ -327,7 +327,7 @@ void add_@global_object_snake_name@_exposed_interfaces(JS::Object& global)
};
for (auto& interface : exposed_interfaces) {
auto gen = TRY(generator.fork());
auto gen = generator.fork();
if (interface.is_namespace)
add_namespace(gen, interface.name, interface.namespace_class);

View file

@ -267,7 +267,7 @@ void generate_lookup_table(StateMachine const& machine, SourceGenerator& generat
)~~~");
auto generate_for_state = [&](State const& s) {
auto table_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto table_generator = generator.fork();
table_generator.set("active_state", s.name);
table_generator.append("/* @active_state@ */ { ");
VERIFY(!s.name.is_empty());
@ -280,7 +280,7 @@ void generate_lookup_table(StateMachine const& machine, SourceGenerator& generat
}
}
for (int i = 0; i < 256; ++i) {
auto cell_generator = table_generator.fork().release_value_but_fixme_should_propagate_errors();
auto cell_generator = table_generator.fork();
cell_generator.set("cell_new_state", row[i].new_state.value_or(s.name));
cell_generator.set("cell_action", row[i].action.value_or("_Ignore"));
cell_generator.append(" {State::@cell_new_state@, Action::@cell_action@}, ");
@ -326,7 +326,7 @@ public:
for (auto a : actions(machine)) {
if (a.is_empty())
continue;
auto action_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto action_generator = generator.fork();
action_generator.set("action.name", a);
action_generator.append(R"~~~(
@action.name@,
@ -353,7 +353,7 @@ public:
switch (m_state) {
)~~~");
for (auto s : machine.states) {
auto state_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto state_generator = generator.fork();
if (s.exit_action.has_value()) {
state_generator.set("state_name", s.name);
state_generator.set("action", s.exit_action.value());
@ -381,7 +381,7 @@ public:
{
)~~~");
for (auto state : machine.states) {
auto state_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto state_generator = generator.fork();
if (state.entry_action.has_value()) {
state_generator.set("state_name", state.name);
state_generator.set("action", state.entry_action.value());
@ -405,7 +405,7 @@ private:
)~~~");
for (auto s : machine.states) {
auto state_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto state_generator = generator.fork();
state_generator.set("state.name", s.name);
state_generator.append(R"~~~(
@state.name@,
@ -440,7 +440,7 @@ private:
}
)~~~");
auto table_generator = generator.fork().release_value_but_fixme_should_propagate_errors();
auto table_generator = generator.fork();
generate_lookup_table(machine, table_generator);
generator.append(R"~~~(
}; // end @class_name@

View file

@ -41,7 +41,7 @@ TEST_CASE(scoped)
global_generator.append("@foo@ @bar@\n"); // foo-0 bar-0
{
auto scoped_generator_1 = MUST(global_generator.fork());
auto scoped_generator_1 = global_generator.fork();
scoped_generator_1.set("bar", "bar-1");
global_generator.append("@foo@ @bar@\n"); // foo-0 bar-0
}
@ -49,18 +49,18 @@ TEST_CASE(scoped)
global_generator.append("@foo@ @bar@\n"); // foo-0 bar-0
{
auto scoped_generator_2 = MUST(global_generator.fork());
auto scoped_generator_2 = global_generator.fork();
scoped_generator_2.set("foo", "foo-2");
scoped_generator_2.append("@foo@ @bar@\n"); // foo-2 bar-0
{
auto scoped_generator_3 = MUST(scoped_generator_2.fork());
auto scoped_generator_3 = scoped_generator_2.fork();
scoped_generator_3.set("bar", "bar-3");
scoped_generator_3.append("@foo@ @bar@\n"); // foo-2 bar-3
}
{
auto scoped_generator_4 = MUST(global_generator.fork());
auto scoped_generator_4 = global_generator.fork();
scoped_generator_4.append("@foo@ @bar@\n"); // foo-0 bar-0
}