diff --git a/AK/Format.cpp b/AK/Format.cpp index 7fa10d3268..14ed0459dd 100644 --- a/AK/Format.cpp +++ b/AK/Format.cpp @@ -98,44 +98,32 @@ void vformat_impl(TypeErasedFormatParams& params, FormatBuilder& builder, Format } // namespace AK::{anonymous} -size_t TypeErasedFormatParams::decode(size_t value, size_t default_value) +size_t TypeErasedParameter::to_size() const { - if (value == StandardFormatter::value_not_set) - return default_value; + i64 svalue; - if (value == StandardFormatter::value_from_next_arg) - value = StandardFormatter::value_from_arg + take_next_index(); + if (type == TypeErasedParameter::Type::UInt8) + svalue = *reinterpret_cast(value); + else if (type == TypeErasedParameter::Type::UInt16) + svalue = *reinterpret_cast(value); + else if (type == TypeErasedParameter::Type::UInt32) + svalue = *reinterpret_cast(value); + else if (type == TypeErasedParameter::Type::UInt64) + svalue = *reinterpret_cast(value); + else if (type == TypeErasedParameter::Type::Int8) + svalue = *reinterpret_cast(value); + else if (type == TypeErasedParameter::Type::Int16) + svalue = *reinterpret_cast(value); + else if (type == TypeErasedParameter::Type::Int32) + svalue = *reinterpret_cast(value); + else if (type == TypeErasedParameter::Type::Int64) + svalue = *reinterpret_cast(value); + else + ASSERT_NOT_REACHED(); - if (value >= StandardFormatter::value_from_arg) { - const auto parameter = parameters().at(value - StandardFormatter::value_from_arg); + ASSERT(svalue >= 0); - Optional svalue; - if (parameter.type == TypeErasedParameter::Type::UInt8) - value = *reinterpret_cast(parameter.value); - else if (parameter.type == TypeErasedParameter::Type::UInt16) - value = *reinterpret_cast(parameter.value); - else if (parameter.type == TypeErasedParameter::Type::UInt32) - value = *reinterpret_cast(parameter.value); - else if (parameter.type == TypeErasedParameter::Type::UInt64) - value = *reinterpret_cast(parameter.value); - else if (parameter.type == TypeErasedParameter::Type::Int8) - svalue = *reinterpret_cast(parameter.value); - else if (parameter.type == TypeErasedParameter::Type::Int16) - svalue = *reinterpret_cast(parameter.value); - else if (parameter.type == TypeErasedParameter::Type::Int32) - svalue = *reinterpret_cast(parameter.value); - else if (parameter.type == TypeErasedParameter::Type::Int64) - svalue = *reinterpret_cast(parameter.value); - else - ASSERT_NOT_REACHED(); - - if (svalue.has_value()) { - ASSERT(svalue.value() >= 0); - value = static_cast(svalue.value()); - } - } - - return value; + return static_cast(svalue); } FormatParser::FormatParser(StringView input) @@ -467,7 +455,7 @@ void StandardFormatter::parse(TypeErasedFormatParams& params, FormatParser& pars if (index == use_next_index) index = params.take_next_index(); - m_width = value_from_arg + index; + m_width = params.parameters().at(index).to_size(); } else if (size_t width = 0; parser.consume_number(width)) { m_width = width; } @@ -477,7 +465,7 @@ void StandardFormatter::parse(TypeErasedFormatParams& params, FormatParser& pars if (index == use_next_index) index = params.take_next_index(); - m_precision = value_from_arg + index; + m_precision = params.parameters().at(index).to_size(); } else if (size_t precision = 0; parser.consume_number(precision)) { m_precision = precision; } @@ -514,7 +502,7 @@ void StandardFormatter::parse(TypeErasedFormatParams& params, FormatParser& pars ASSERT(parser.is_eof()); } -void Formatter::format(TypeErasedFormatParams& params, FormatBuilder& builder, StringView value) +void Formatter::format(FormatBuilder& builder, StringView value) { if (m_sign_mode != FormatBuilder::SignMode::Default) ASSERT_NOT_REACHED(); @@ -524,17 +512,17 @@ void Formatter::format(TypeErasedFormatParams& params, FormatBuilder ASSERT_NOT_REACHED(); if (m_mode != Mode::Default && m_mode != Mode::String && m_mode != Mode::Character) ASSERT_NOT_REACHED(); - if (m_width != value_not_set && m_precision != value_not_set) + if (m_width.has_value() && m_precision.has_value()) ASSERT_NOT_REACHED(); - const auto width = params.decode(m_width); - const auto precision = params.decode(m_precision, NumericLimits::max()); + m_width = m_width.value_or(0); + m_precision = m_precision.value_or(NumericLimits::max()); - builder.put_string(value, m_align, width, precision, m_fill); + builder.put_string(value, m_align, m_width.value(), m_precision.value(), m_fill); } template -void Formatter::value>::Type>::format(TypeErasedFormatParams& params, FormatBuilder& builder, T value) +void Formatter::value>::Type>::format(FormatBuilder& builder, T value) { if (m_mode == Mode::Character) { // FIXME: We just support ASCII for now, in the future maybe unicode? @@ -543,10 +531,10 @@ void Formatter::value>::Type>::format(TypeEra m_mode = Mode::String; Formatter formatter { *this }; - return formatter.format(params, builder, StringView { reinterpret_cast(&value), 1 }); + return formatter.format(builder, StringView { reinterpret_cast(&value), 1 }); } - if (m_precision != NumericLimits::max()) + if (m_precision.has_value()) ASSERT_NOT_REACHED(); if (m_mode == Mode::Pointer) { @@ -556,7 +544,7 @@ void Formatter::value>::Type>::format(TypeEra ASSERT_NOT_REACHED(); if (m_alternative_form) ASSERT_NOT_REACHED(); - if (m_width != value_not_set) + if (m_width.has_value()) ASSERT_NOT_REACHED(); m_mode = Mode::Hexadecimal; @@ -585,37 +573,37 @@ void Formatter::value>::Type>::format(TypeEra ASSERT_NOT_REACHED(); } - const auto width = params.decode(m_width); + m_width = m_width.value_or(0); if (IsSame::Type, T>::value) - builder.put_u64(value, base, m_alternative_form, upper_case, m_zero_pad, m_align, width, m_fill, m_sign_mode); + builder.put_u64(value, base, m_alternative_form, upper_case, m_zero_pad, m_align, m_width.value(), m_fill, m_sign_mode); else - builder.put_i64(value, base, m_alternative_form, upper_case, m_zero_pad, m_align, width, m_fill, m_sign_mode); + builder.put_i64(value, base, m_alternative_form, upper_case, m_zero_pad, m_align, m_width.value(), m_fill, m_sign_mode); } -void Formatter::format(TypeErasedFormatParams& params, FormatBuilder& builder, char value) +void Formatter::format(FormatBuilder& builder, char value) { if (m_mode == Mode::Binary || m_mode == Mode::BinaryUppercase || m_mode == Mode::Decimal || m_mode == Mode::Octal || m_mode == Mode::Hexadecimal || m_mode == Mode::HexadecimalUppercase) { // Trick: signed char != char. (Sometimes weird features are actually helpful.) Formatter formatter { *this }; - return formatter.format(params, builder, static_cast(value)); + return formatter.format(builder, static_cast(value)); } else { Formatter formatter { *this }; - return formatter.format(params, builder, { &value, 1 }); + return formatter.format(builder, { &value, 1 }); } } -void Formatter::format(TypeErasedFormatParams& params, FormatBuilder& builder, bool value) +void Formatter::format(FormatBuilder& builder, bool value) { if (m_mode == Mode::Binary || m_mode == Mode::BinaryUppercase || m_mode == Mode::Decimal || m_mode == Mode::Octal || m_mode == Mode::Hexadecimal || m_mode == Mode::HexadecimalUppercase) { Formatter formatter { *this }; - return formatter.format(params, builder, static_cast(value)); + return formatter.format(builder, static_cast(value)); } else { Formatter formatter { *this }; - return formatter.format(params, builder, value ? "true" : "false"); + return formatter.format(builder, value ? "true" : "false"); } } #ifndef KERNEL -void Formatter::format(TypeErasedFormatParams& params, FormatBuilder& builder, double value) +void Formatter::format(FormatBuilder& builder, double value) { u8 base; bool upper_case; @@ -632,15 +620,15 @@ void Formatter::format(TypeErasedFormatParams& params, FormatBuilder& bu ASSERT_NOT_REACHED(); } - const auto width = params.decode(m_width); - const auto precision = params.decode(m_precision, 6); + m_width = m_width.value_or(0); + m_precision = m_precision.value_or(6); - builder.put_f64(value, base, upper_case, m_align, width, precision, m_fill, m_sign_mode); + builder.put_f64(value, base, upper_case, m_align, m_width.value(), m_precision.value(), m_fill, m_sign_mode); } -void Formatter::format(TypeErasedFormatParams& params, FormatBuilder& builder, float value) +void Formatter::format(FormatBuilder& builder, float value) { Formatter formatter { *this }; - formatter.format(params, builder, value); + formatter.format(builder, value); } #endif diff --git a/AK/Format.h b/AK/Format.h index b269d70ac6..ea2bd6edf7 100644 --- a/AK/Format.h +++ b/AK/Format.h @@ -28,6 +28,7 @@ #include #include +#include #include #ifndef KERNEL @@ -94,6 +95,10 @@ struct TypeErasedParameter { return Type::Custom; } + size_t to_size() const; + + // FIXME: Getters and setters. + const void* value; Type type; void (*formatter)(TypeErasedFormatParams&, FormatBuilder&, FormatParser&, const void* value); @@ -197,8 +202,6 @@ public: void set_parameters(Span parameters) { m_parameters = parameters; } size_t take_next_index() { return m_next_index++; } - size_t decode(size_t value, size_t default_value = 0); - private: Span m_parameters; size_t m_next_index { 0 }; @@ -210,7 +213,7 @@ void __format_value(TypeErasedFormatParams& params, FormatBuilder& builder, Form Formatter formatter; formatter.parse(params, parser); - formatter.format(params, builder, *static_cast(value)); + formatter.format(builder, *static_cast(value)); } template @@ -249,18 +252,14 @@ struct StandardFormatter { HexfloatUppercase, }; - static constexpr size_t value_not_set = NumericLimits::max(); - static constexpr size_t value_from_next_arg = NumericLimits::max() - 1; - static constexpr size_t value_from_arg = NumericLimits::max() - max_format_arguments - 2; - FormatBuilder::Align m_align = FormatBuilder::Align::Default; FormatBuilder::SignMode m_sign_mode = FormatBuilder::SignMode::OnlyIfNeeded; Mode m_mode = Mode::Default; bool m_alternative_form = false; char m_fill = ' '; bool m_zero_pad = false; - size_t m_width = value_not_set; - size_t m_precision = value_not_set; + Optional m_width; + Optional m_precision; void parse(TypeErasedFormatParams&, FormatParser&); }; @@ -273,7 +272,7 @@ struct Formatter::value>::Type> : StandardFor { } - void format(TypeErasedFormatParams&, FormatBuilder&, T value); + void format(FormatBuilder&, T value); }; template<> @@ -284,17 +283,17 @@ struct Formatter : StandardFormatter { { } - void format(TypeErasedFormatParams&, FormatBuilder&, StringView value); + void format(FormatBuilder&, StringView value); }; template<> struct Formatter : Formatter { - void format(TypeErasedFormatParams& params, FormatBuilder& builder, const char* value) + void format(FormatBuilder& builder, const char* value) { if (m_mode == Mode::Pointer) { Formatter formatter { *this }; - formatter.format(params, builder, reinterpret_cast(value)); + formatter.format(builder, reinterpret_cast(value)); } else { - Formatter::format(params, builder, value); + Formatter::format(builder, value); } } }; @@ -313,29 +312,29 @@ struct Formatter : Formatter { template struct Formatter : StandardFormatter { - void format(TypeErasedFormatParams& params, FormatBuilder& builder, T* value) + void format(FormatBuilder& builder, T* value) { if (m_mode == Mode::Default) m_mode = Mode::Pointer; Formatter formatter { *this }; - formatter.format(params, builder, reinterpret_cast(value)); + formatter.format(builder, reinterpret_cast(value)); } }; template<> struct Formatter : StandardFormatter { - void format(TypeErasedFormatParams&, FormatBuilder&, char value); + void format(FormatBuilder&, char value); }; template<> struct Formatter : StandardFormatter { - void format(TypeErasedFormatParams&, FormatBuilder&, bool value); + void format(FormatBuilder&, bool value); }; #ifndef KERNEL template<> struct Formatter : StandardFormatter { - void format(TypeErasedFormatParams&, FormatBuilder&, float value); + void format(FormatBuilder&, float value); }; template<> struct Formatter : StandardFormatter { @@ -345,7 +344,7 @@ struct Formatter : StandardFormatter { { } - void format(TypeErasedFormatParams&, FormatBuilder&, double value); + void format(FormatBuilder&, double value); }; #endif @@ -409,16 +408,16 @@ private: }; template struct __FormatIfSupported : Formatter { - void format(TypeErasedFormatParams& params, FormatBuilder& builder, const FormatIfSupported&) + void format(FormatBuilder& builder, const FormatIfSupported&) { - Formatter::format(params, builder, "?"); + Formatter::format(builder, "?"); } }; template struct __FormatIfSupported : Formatter { - void format(TypeErasedFormatParams& params, FormatBuilder& builder, const FormatIfSupported& value) + void format(FormatBuilder& builder, const FormatIfSupported& value) { - Formatter::format(params, builder, value.value()); + Formatter::format(builder, value.value()); } }; template diff --git a/AK/JsonValue.h b/AK/JsonValue.h index 4cf90ff888..d3bf23cb2c 100644 --- a/AK/JsonValue.h +++ b/AK/JsonValue.h @@ -263,9 +263,9 @@ private: template<> struct Formatter : Formatter { - void format(TypeErasedFormatParams& params, FormatBuilder& builder, const JsonValue& value) + void format(FormatBuilder& builder, const JsonValue& value) { - Formatter::format(params, builder, value.to_string()); + Formatter::format(builder, value.to_string()); } }; diff --git a/AK/LexicalPath.h b/AK/LexicalPath.h index f198f8c2fb..2777c17b26 100644 --- a/AK/LexicalPath.h +++ b/AK/LexicalPath.h @@ -66,9 +66,9 @@ private: template<> struct Formatter : Formatter { - void format(TypeErasedFormatParams& params, FormatBuilder& builder, const LexicalPath& value) + void format(FormatBuilder& builder, const LexicalPath& value) { - Formatter::format(params, builder, value.string()); + Formatter::format(builder, value.string()); } }; diff --git a/AK/NonnullOwnPtr.h b/AK/NonnullOwnPtr.h index d06895f642..321ea67b7d 100644 --- a/AK/NonnullOwnPtr.h +++ b/AK/NonnullOwnPtr.h @@ -197,9 +197,9 @@ inline void swap(NonnullOwnPtr& a, NonnullOwnPtr& b) template struct Formatter> : Formatter { - void format(TypeErasedFormatParams& params, FormatBuilder& builder, const NonnullOwnPtr& value) + void format(FormatBuilder& builder, const NonnullOwnPtr& value) { - Formatter::format(params, builder, value.ptr()); + Formatter::format(builder, value.ptr()); } }; diff --git a/AK/NonnullRefPtr.h b/AK/NonnullRefPtr.h index a3b8309139..734c822c73 100644 --- a/AK/NonnullRefPtr.h +++ b/AK/NonnullRefPtr.h @@ -348,9 +348,9 @@ inline const LogStream& operator<<(const LogStream& stream, const NonnullRefPtr< template struct Formatter> : Formatter { - void format(TypeErasedFormatParams& params, FormatBuilder& builder, const NonnullRefPtr& value) + void format(FormatBuilder& builder, const NonnullRefPtr& value) { - Formatter::format(params, builder, value.ptr()); + Formatter::format(builder, value.ptr()); } }; diff --git a/AK/StringImpl.h b/AK/StringImpl.h index 24278ce99e..506775ef8a 100644 --- a/AK/StringImpl.h +++ b/AK/StringImpl.h @@ -132,9 +132,9 @@ constexpr u32 string_hash(const char* characters, size_t length) template<> struct Formatter : Formatter { - void format(TypeErasedFormatParams& params, FormatBuilder& builder, const StringImpl& value) + void format(FormatBuilder& builder, const StringImpl& value) { - Formatter::format(params, builder, { value.characters(), value.length() }); + Formatter::format(builder, { value.characters(), value.length() }); } }; diff --git a/AK/Tests/TestFormat.cpp b/AK/Tests/TestFormat.cpp index c88a006964..bcf9b91889 100644 --- a/AK/Tests/TestFormat.cpp +++ b/AK/Tests/TestFormat.cpp @@ -213,9 +213,9 @@ struct B { }; template<> struct AK::Formatter : Formatter { - void format(TypeErasedFormatParams& params, FormatBuilder& builder, B) + void format(FormatBuilder& builder, B) { - Formatter::format(params, builder, "B"); + Formatter::format(builder, "B"); } }; diff --git a/AK/URL.h b/AK/URL.h index 1e3bdcf54b..ee03995c3b 100644 --- a/AK/URL.h +++ b/AK/URL.h @@ -106,9 +106,9 @@ inline const LogStream& operator<<(const LogStream& stream, const URL& value) template<> struct Formatter : Formatter { - void format(TypeErasedFormatParams& params, FormatBuilder& builder, const URL& value) + void format(FormatBuilder& builder, const URL& value) { - Formatter::format(params, builder, value.to_string()); + Formatter::format(builder, value.to_string()); } }; diff --git a/AK/WeakPtr.h b/AK/WeakPtr.h index bb460e3215..72d3b8af07 100644 --- a/AK/WeakPtr.h +++ b/AK/WeakPtr.h @@ -226,13 +226,13 @@ inline const LogStream& operator<<(const LogStream& stream, const WeakPtr& va template struct Formatter> : Formatter { - void format(TypeErasedFormatParams& params, FormatBuilder& builder, const WeakPtr& value) + void format(FormatBuilder& builder, const WeakPtr& value) { #ifdef KERNEL auto ref = value.strong_ref(); - Formatter::format(params, builder, ref.ptr()); + Formatter::format(builder, ref.ptr()); #else - Formatter::format(params, builder, value.ptr()); + Formatter::format(builder, value.ptr()); #endif } }; diff --git a/DevTools/UserspaceEmulator/ValueWithShadow.h b/DevTools/UserspaceEmulator/ValueWithShadow.h index 31adf992f4..3684482642 100644 --- a/DevTools/UserspaceEmulator/ValueWithShadow.h +++ b/DevTools/UserspaceEmulator/ValueWithShadow.h @@ -164,8 +164,8 @@ inline void ValueAndShadowReference::operator=(const ValueWithShadow& othe template struct AK::Formatter> : AK::Formatter { - void format(TypeErasedFormatParams& params, FormatBuilder& builder, UserspaceEmulator::ValueWithShadow value) + void format(FormatBuilder& builder, UserspaceEmulator::ValueWithShadow value) { - return Formatter::format(params, builder, value.value()); + return Formatter::format(builder, value.value()); } }; diff --git a/Kernel/VirtualAddress.cpp b/Kernel/VirtualAddress.cpp index 0b3a8759c6..945cc0e99c 100644 --- a/Kernel/VirtualAddress.cpp +++ b/Kernel/VirtualAddress.cpp @@ -28,9 +28,9 @@ #include namespace AK { -void Formatter::format(TypeErasedFormatParams& params, FormatBuilder& builder, const VirtualAddress& value) +void Formatter::format(FormatBuilder& builder, const VirtualAddress& value) { - Formatter::format(params, builder, String::formatted("V{:p}", value.get())); + Formatter::format(builder, String::formatted("V{:p}", value.get())); } } diff --git a/Kernel/VirtualAddress.h b/Kernel/VirtualAddress.h index e26b8f0aeb..3a0fa6691f 100644 --- a/Kernel/VirtualAddress.h +++ b/Kernel/VirtualAddress.h @@ -77,8 +77,10 @@ inline const LogStream& operator<<(const LogStream& stream, VirtualAddress value } namespace AK { + template<> struct Formatter : Formatter { - void format(TypeErasedFormatParams&, FormatBuilder&, const VirtualAddress&); + void format(FormatBuilder&, const VirtualAddress&); }; + } diff --git a/Libraries/LibCore/Object.cpp b/Libraries/LibCore/Object.cpp index 7db8548073..dc9028a533 100644 --- a/Libraries/LibCore/Object.cpp +++ b/Libraries/LibCore/Object.cpp @@ -273,9 +273,9 @@ const LogStream& operator<<(const LogStream& stream, const Object& object) namespace AK { -void Formatter::format(TypeErasedFormatParams& params, FormatBuilder& builder, const Core::Object& value) +void Formatter::format(FormatBuilder& builder, const Core::Object& value) { - Formatter::format(params, builder, String::formatted("{}({})", value.class_name(), &value)); + Formatter::format(builder, String::formatted("{}({})", value.class_name(), &value)); } } diff --git a/Libraries/LibCore/Object.h b/Libraries/LibCore/Object.h index ef261564c9..de1a5f77de 100644 --- a/Libraries/LibCore/Object.h +++ b/Libraries/LibCore/Object.h @@ -175,7 +175,7 @@ private: namespace AK { template<> struct Formatter : Formatter { - void format(TypeErasedFormatParams&, FormatBuilder&, const Core::Object&); + void format(FormatBuilder&, const Core::Object&); }; } diff --git a/Libraries/LibGUI/ModelIndex.cpp b/Libraries/LibGUI/ModelIndex.cpp index 982969f0c3..e06a2d8245 100644 --- a/Libraries/LibGUI/ModelIndex.cpp +++ b/Libraries/LibGUI/ModelIndex.cpp @@ -50,14 +50,14 @@ const LogStream& operator<<(const LogStream& stream, const ModelIndex& value) namespace AK { -void Formatter::format(TypeErasedFormatParams& params, FormatBuilder& builder, const GUI::ModelIndex& value) +void Formatter::format(FormatBuilder& builder, const GUI::ModelIndex& value) { Formatter formatter { *this }; if (value.internal_data()) - formatter.format(params, builder, String::formatted("ModelIndex({},{},{:p})", value.row(), value.column(), value.internal_data())); + formatter.format(builder, String::formatted("ModelIndex({},{},{:p})", value.row(), value.column(), value.internal_data())); else - formatter.format(params, builder, String::formatted("ModelIndex({},{})", value.row(), value.column())); + formatter.format(builder, String::formatted("ModelIndex({},{})", value.row(), value.column())); } } diff --git a/Libraries/LibGUI/ModelIndex.h b/Libraries/LibGUI/ModelIndex.h index 222ea7f1b7..f0cf6a978c 100644 --- a/Libraries/LibGUI/ModelIndex.h +++ b/Libraries/LibGUI/ModelIndex.h @@ -83,7 +83,7 @@ namespace AK { template<> struct Formatter : Formatter { - void format(TypeErasedFormatParams&, FormatBuilder&, const GUI::ModelIndex&); + void format(FormatBuilder&, const GUI::ModelIndex&); }; template<> diff --git a/Libraries/LibGUI/TextPosition.h b/Libraries/LibGUI/TextPosition.h index 53732abc63..56c2a9ed97 100644 --- a/Libraries/LibGUI/TextPosition.h +++ b/Libraries/LibGUI/TextPosition.h @@ -70,12 +70,12 @@ namespace AK { template<> struct Formatter : Formatter { - void format(TypeErasedFormatParams& params, FormatBuilder& builder, const GUI::TextPosition& value) + void format(FormatBuilder& builder, const GUI::TextPosition& value) { if (value.is_valid()) - Formatter::format(params, builder, String::formatted("({},{})", value.line(), value.column())); + Formatter::format(builder, String::formatted("({},{})", value.line(), value.column())); else - Formatter::format(params, builder, "GUI::TextPosition(Invalid)"); + Formatter::format(builder, "GUI::TextPosition(Invalid)"); } }; diff --git a/Libraries/LibGUI/TextRange.h b/Libraries/LibGUI/TextRange.h index 4f62273e89..4b10a4568f 100644 --- a/Libraries/LibGUI/TextRange.h +++ b/Libraries/LibGUI/TextRange.h @@ -98,12 +98,12 @@ namespace AK { template<> struct Formatter : Formatter { - void format(TypeErasedFormatParams& params, FormatBuilder& builder, const GUI::TextRange& value) + void format(FormatBuilder& builder, const GUI::TextRange& value) { if (value.is_valid()) - Formatter::format(params, builder, String::formatted("{}-{}", value.start(), value.end())); + Formatter::format(builder, String::formatted("{}-{}", value.start(), value.end())); else - Formatter::format(params, builder, "GUI::TextRange(Invalid)"); + Formatter::format(builder, "GUI::TextRange(Invalid)"); } }; diff --git a/Libraries/LibGfx/Color.cpp b/Libraries/LibGfx/Color.cpp index 1dfcda7666..f8a0f244f4 100644 --- a/Libraries/LibGfx/Color.cpp +++ b/Libraries/LibGfx/Color.cpp @@ -434,7 +434,7 @@ bool IPC::decode(IPC::Decoder& decoder, Color& color) return true; } -void AK::Formatter::format(TypeErasedFormatParams& params, FormatBuilder& builder, const Gfx::Color& value) +void AK::Formatter::format(FormatBuilder& builder, const Gfx::Color& value) { - Formatter::format(params, builder, value.to_string()); + Formatter::format(builder, value.to_string()); } diff --git a/Libraries/LibGfx/Color.h b/Libraries/LibGfx/Color.h index 0187a2e6b7..e30cacba6c 100644 --- a/Libraries/LibGfx/Color.h +++ b/Libraries/LibGfx/Color.h @@ -317,13 +317,17 @@ const LogStream& operator<<(const LogStream&, Color); using Gfx::Color; namespace AK { + template<> struct Formatter : public Formatter { - void format(TypeErasedFormatParams& params, FormatBuilder& builder, const Gfx::Color& value); + void format(FormatBuilder& builder, const Gfx::Color& value); }; + } namespace IPC { + bool encode(Encoder&, const Gfx::Color&); bool decode(Decoder&, Gfx::Color&); + } diff --git a/Libraries/LibGfx/Rect.h b/Libraries/LibGfx/Rect.h index d485804a80..f54ff43fbf 100644 --- a/Libraries/LibGfx/Rect.h +++ b/Libraries/LibGfx/Rect.h @@ -455,9 +455,9 @@ namespace AK { template struct Formatter> : Formatter { - void format(TypeErasedFormatParams& params, FormatBuilder& builder, const Gfx::Rect& value) + void format(FormatBuilder& builder, const Gfx::Rect& value) { - Formatter::format(params, builder, value.to_string()); + Formatter::format(builder, value.to_string()); } }; diff --git a/Libraries/LibJS/Runtime/Cell.h b/Libraries/LibJS/Runtime/Cell.h index 825887f24e..4bbcb359f6 100644 --- a/Libraries/LibJS/Runtime/Cell.h +++ b/Libraries/LibJS/Runtime/Cell.h @@ -78,12 +78,12 @@ namespace AK { template<> struct Formatter : Formatter { - void format(TypeErasedFormatParams& params, FormatBuilder& builder, const JS::Cell* cell) + void format(FormatBuilder& builder, const JS::Cell* cell) { if (!cell) - Formatter::format(params, builder, "Cell{nullptr}"); + Formatter::format(builder, "Cell{nullptr}"); else - Formatter::format(params, builder, String::formatted("{}{{{}}}", cell->class_name(), static_cast(cell))); + Formatter::format(builder, String::formatted("{}{{{}}}", cell->class_name(), static_cast(cell))); } }; diff --git a/Libraries/LibJS/Runtime/PropertyAttributes.h b/Libraries/LibJS/Runtime/PropertyAttributes.h index 44a3343947..b3788bd897 100644 --- a/Libraries/LibJS/Runtime/PropertyAttributes.h +++ b/Libraries/LibJS/Runtime/PropertyAttributes.h @@ -95,9 +95,9 @@ namespace AK { template<> struct Formatter : Formatter { - void format(TypeErasedFormatParams& params, FormatBuilder& builder, const JS::PropertyAttributes& attributes) + void format(FormatBuilder& builder, const JS::PropertyAttributes& attributes) { - Formatter::format(params, builder, attributes.bits()); + Formatter::format(builder, attributes.bits()); } }; diff --git a/Libraries/LibJS/Runtime/Value.h b/Libraries/LibJS/Runtime/Value.h index b99f4ab268..2be347d09f 100644 --- a/Libraries/LibJS/Runtime/Value.h +++ b/Libraries/LibJS/Runtime/Value.h @@ -345,9 +345,9 @@ namespace AK { template<> struct Formatter : Formatter { - void format(TypeErasedFormatParams& params, FormatBuilder& builder, const JS::Value& value) + void format(FormatBuilder& builder, const JS::Value& value) { - Formatter::format(params, builder, value.is_empty() ? "" : value.to_string_without_side_effects()); + Formatter::format(builder, value.is_empty() ? "" : value.to_string_without_side_effects()); } }; diff --git a/Shell/AST.cpp b/Shell/AST.cpp index f599e74d97..f6d6ad084f 100644 --- a/Shell/AST.cpp +++ b/Shell/AST.cpp @@ -37,7 +37,7 @@ //#define EXECUTE_DEBUG -void AK::Formatter::format(TypeErasedFormatParams&, FormatBuilder& builder, const Shell::AST::Command& value) +void AK::Formatter::format(FormatBuilder& builder, const Shell::AST::Command& value) { if (m_sign_mode != FormatBuilder::SignMode::Default) ASSERT_NOT_REACHED(); @@ -47,7 +47,9 @@ void AK::Formatter::format(TypeErasedFormatParams&, FormatB ASSERT_NOT_REACHED(); if (m_mode != Mode::Default && m_mode != Mode::String) ASSERT_NOT_REACHED(); - if (m_width != value_not_set && m_precision != value_not_set) + if (m_width.has_value()) + ASSERT_NOT_REACHED(); + if (m_precision.has_value()) ASSERT_NOT_REACHED(); if (value.argv.is_empty()) { diff --git a/Shell/AST.h b/Shell/AST.h index 48043a6f44..f3fb8cd39d 100644 --- a/Shell/AST.h +++ b/Shell/AST.h @@ -1301,7 +1301,7 @@ struct Formatter : StandardFormatter { { } - void format(TypeErasedFormatParams&, FormatBuilder&, const Shell::AST::Command& value); + void format(FormatBuilder&, const Shell::AST::Command& value); }; }