Explorar o código

AK+Format: Remove TypeErasedFormatParams& from format function.

asynts %!s(int64=4) %!d(string=hai) anos
pai
achega
7e62ffbc6e

+ 49 - 61
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;
-
-    if (value == StandardFormatter::value_from_next_arg)
-        value = StandardFormatter::value_from_arg + take_next_index();
-
-    if (value >= StandardFormatter::value_from_arg) {
-        const auto parameter = parameters().at(value - StandardFormatter::value_from_arg);
-
-        Optional<i64> svalue;
-        if (parameter.type == TypeErasedParameter::Type::UInt8)
-            value = *reinterpret_cast<const u8*>(parameter.value);
-        else if (parameter.type == TypeErasedParameter::Type::UInt16)
-            value = *reinterpret_cast<const u16*>(parameter.value);
-        else if (parameter.type == TypeErasedParameter::Type::UInt32)
-            value = *reinterpret_cast<const u32*>(parameter.value);
-        else if (parameter.type == TypeErasedParameter::Type::UInt64)
-            value = *reinterpret_cast<const u64*>(parameter.value);
-        else if (parameter.type == TypeErasedParameter::Type::Int8)
-            svalue = *reinterpret_cast<const i8*>(parameter.value);
-        else if (parameter.type == TypeErasedParameter::Type::Int16)
-            svalue = *reinterpret_cast<const i16*>(parameter.value);
-        else if (parameter.type == TypeErasedParameter::Type::Int32)
-            svalue = *reinterpret_cast<const i32*>(parameter.value);
-        else if (parameter.type == TypeErasedParameter::Type::Int64)
-            svalue = *reinterpret_cast<const i64*>(parameter.value);
-        else
-            ASSERT_NOT_REACHED();
+    i64 svalue;
+
+    if (type == TypeErasedParameter::Type::UInt8)
+        svalue = *reinterpret_cast<const u8*>(value);
+    else if (type == TypeErasedParameter::Type::UInt16)
+        svalue = *reinterpret_cast<const u16*>(value);
+    else if (type == TypeErasedParameter::Type::UInt32)
+        svalue = *reinterpret_cast<const u32*>(value);
+    else if (type == TypeErasedParameter::Type::UInt64)
+        svalue = *reinterpret_cast<const u64*>(value);
+    else if (type == TypeErasedParameter::Type::Int8)
+        svalue = *reinterpret_cast<const i8*>(value);
+    else if (type == TypeErasedParameter::Type::Int16)
+        svalue = *reinterpret_cast<const i16*>(value);
+    else if (type == TypeErasedParameter::Type::Int32)
+        svalue = *reinterpret_cast<const i32*>(value);
+    else if (type == TypeErasedParameter::Type::Int64)
+        svalue = *reinterpret_cast<const i64*>(value);
+    else
+        ASSERT_NOT_REACHED();
 
-        if (svalue.has_value()) {
-            ASSERT(svalue.value() >= 0);
-            value = static_cast<size_t>(svalue.value());
-        }
-    }
+    ASSERT(svalue >= 0);
 
-    return value;
+    return static_cast<size_t>(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<StringView>::format(TypeErasedFormatParams& params, FormatBuilder& builder, StringView value)
+void Formatter<StringView>::format(FormatBuilder& builder, StringView value)
 {
     if (m_sign_mode != FormatBuilder::SignMode::Default)
         ASSERT_NOT_REACHED();
@@ -524,17 +512,17 @@ void Formatter<StringView>::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<size_t>::max());
+    m_width = m_width.value_or(0);
+    m_precision = m_precision.value_or(NumericLimits<size_t>::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<typename T>
-void Formatter<T, typename EnableIf<IsIntegral<T>::value>::Type>::format(TypeErasedFormatParams& params, FormatBuilder& builder, T value)
+void Formatter<T, typename EnableIf<IsIntegral<T>::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<T, typename EnableIf<IsIntegral<T>::value>::Type>::format(TypeEra
         m_mode = Mode::String;
 
         Formatter<StringView> formatter { *this };
-        return formatter.format(params, builder, StringView { reinterpret_cast<const char*>(&value), 1 });
+        return formatter.format(builder, StringView { reinterpret_cast<const char*>(&value), 1 });
     }
 
-    if (m_precision != NumericLimits<size_t>::max())
+    if (m_precision.has_value())
         ASSERT_NOT_REACHED();
 
     if (m_mode == Mode::Pointer) {
@@ -556,7 +544,7 @@ void Formatter<T, typename EnableIf<IsIntegral<T>::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<T, typename EnableIf<IsIntegral<T>::value>::Type>::format(TypeEra
         ASSERT_NOT_REACHED();
     }
 
-    const auto width = params.decode(m_width);
+    m_width = m_width.value_or(0);
 
     if (IsSame<typename MakeUnsigned<T>::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<char>::format(TypeErasedFormatParams& params, FormatBuilder& builder, char value)
+void Formatter<char>::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<signed char> formatter { *this };
-        return formatter.format(params, builder, static_cast<signed char>(value));
+        return formatter.format(builder, static_cast<signed char>(value));
     } else {
         Formatter<StringView> formatter { *this };
-        return formatter.format(params, builder, { &value, 1 });
+        return formatter.format(builder, { &value, 1 });
     }
 }
-void Formatter<bool>::format(TypeErasedFormatParams& params, FormatBuilder& builder, bool value)
+void Formatter<bool>::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<u8> formatter { *this };
-        return formatter.format(params, builder, static_cast<u8>(value));
+        return formatter.format(builder, static_cast<u8>(value));
     } else {
         Formatter<StringView> formatter { *this };
-        return formatter.format(params, builder, value ? "true" : "false");
+        return formatter.format(builder, value ? "true" : "false");
     }
 }
 #ifndef KERNEL
-void Formatter<double>::format(TypeErasedFormatParams& params, FormatBuilder& builder, double value)
+void Formatter<double>::format(FormatBuilder& builder, double value)
 {
     u8 base;
     bool upper_case;
@@ -632,15 +620,15 @@ void Formatter<double>::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<float>::format(TypeErasedFormatParams& params, FormatBuilder& builder, float value)
+void Formatter<float>::format(FormatBuilder& builder, float value)
 {
     Formatter<double> formatter { *this };
-    formatter.format(params, builder, value);
+    formatter.format(builder, value);
 }
 #endif
 

+ 23 - 24
AK/Format.h

@@ -28,6 +28,7 @@
 
 #include <AK/Array.h>
 #include <AK/GenericLexer.h>
+#include <AK/Optional.h>
 #include <AK/StringView.h>
 
 #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<const TypeErasedParameter> 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<const TypeErasedParameter> m_parameters;
     size_t m_next_index { 0 };
@@ -210,7 +213,7 @@ void __format_value(TypeErasedFormatParams& params, FormatBuilder& builder, Form
     Formatter<T> formatter;
 
     formatter.parse(params, parser);
-    formatter.format(params, builder, *static_cast<const T*>(value));
+    formatter.format(builder, *static_cast<const T*>(value));
 }
 
 template<typename... Parameters>
@@ -249,18 +252,14 @@ struct StandardFormatter {
         HexfloatUppercase,
     };
 
-    static constexpr size_t value_not_set = NumericLimits<size_t>::max();
-    static constexpr size_t value_from_next_arg = NumericLimits<size_t>::max() - 1;
-    static constexpr size_t value_from_arg = NumericLimits<size_t>::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<size_t> m_width;
+    Optional<size_t> m_precision;
 
     void parse(TypeErasedFormatParams&, FormatParser&);
 };
@@ -273,7 +272,7 @@ struct Formatter<T, typename EnableIf<IsIntegral<T>::value>::Type> : StandardFor
     {
     }
 
-    void format(TypeErasedFormatParams&, FormatBuilder&, T value);
+    void format(FormatBuilder&, T value);
 };
 
 template<>
@@ -284,17 +283,17 @@ struct Formatter<StringView> : StandardFormatter {
     {
     }
 
-    void format(TypeErasedFormatParams&, FormatBuilder&, StringView value);
+    void format(FormatBuilder&, StringView value);
 };
 template<>
 struct Formatter<const char*> : Formatter<StringView> {
-    void format(TypeErasedFormatParams& params, FormatBuilder& builder, const char* value)
+    void format(FormatBuilder& builder, const char* value)
     {
         if (m_mode == Mode::Pointer) {
             Formatter<FlatPtr> formatter { *this };
-            formatter.format(params, builder, reinterpret_cast<FlatPtr>(value));
+            formatter.format(builder, reinterpret_cast<FlatPtr>(value));
         } else {
-            Formatter<StringView>::format(params, builder, value);
+            Formatter<StringView>::format(builder, value);
         }
     }
 };
@@ -313,29 +312,29 @@ struct Formatter<FlyString> : Formatter<StringView> {
 
 template<typename T>
 struct Formatter<T*> : 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<FlatPtr> formatter { *this };
-        formatter.format(params, builder, reinterpret_cast<FlatPtr>(value));
+        formatter.format(builder, reinterpret_cast<FlatPtr>(value));
     }
 };
 
 template<>
 struct Formatter<char> : StandardFormatter {
-    void format(TypeErasedFormatParams&, FormatBuilder&, char value);
+    void format(FormatBuilder&, char value);
 };
 template<>
 struct Formatter<bool> : StandardFormatter {
-    void format(TypeErasedFormatParams&, FormatBuilder&, bool value);
+    void format(FormatBuilder&, bool value);
 };
 
 #ifndef KERNEL
 template<>
 struct Formatter<float> : StandardFormatter {
-    void format(TypeErasedFormatParams&, FormatBuilder&, float value);
+    void format(FormatBuilder&, float value);
 };
 template<>
 struct Formatter<double> : StandardFormatter {
@@ -345,7 +344,7 @@ struct Formatter<double> : StandardFormatter {
     {
     }
 
-    void format(TypeErasedFormatParams&, FormatBuilder&, double value);
+    void format(FormatBuilder&, double value);
 };
 #endif
 
@@ -409,16 +408,16 @@ private:
 };
 template<typename T, bool Supported = false>
 struct __FormatIfSupported : Formatter<StringView> {
-    void format(TypeErasedFormatParams& params, FormatBuilder& builder, const FormatIfSupported<T>&)
+    void format(FormatBuilder& builder, const FormatIfSupported<T>&)
     {
-        Formatter<StringView>::format(params, builder, "?");
+        Formatter<StringView>::format(builder, "?");
     }
 };
 template<typename T>
 struct __FormatIfSupported<T, true> : Formatter<T> {
-    void format(TypeErasedFormatParams& params, FormatBuilder& builder, const FormatIfSupported<T>& value)
+    void format(FormatBuilder& builder, const FormatIfSupported<T>& value)
     {
-        Formatter<T>::format(params, builder, value.value());
+        Formatter<T>::format(builder, value.value());
     }
 };
 template<typename T>

+ 2 - 2
AK/JsonValue.h

@@ -263,9 +263,9 @@ private:
 
 template<>
 struct Formatter<JsonValue> : Formatter<StringView> {
-    void format(TypeErasedFormatParams& params, FormatBuilder& builder, const JsonValue& value)
+    void format(FormatBuilder& builder, const JsonValue& value)
     {
-        Formatter<StringView>::format(params, builder, value.to_string());
+        Formatter<StringView>::format(builder, value.to_string());
     }
 };
 

+ 2 - 2
AK/LexicalPath.h

@@ -66,9 +66,9 @@ private:
 
 template<>
 struct Formatter<LexicalPath> : Formatter<StringView> {
-    void format(TypeErasedFormatParams& params, FormatBuilder& builder, const LexicalPath& value)
+    void format(FormatBuilder& builder, const LexicalPath& value)
     {
-        Formatter<StringView>::format(params, builder, value.string());
+        Formatter<StringView>::format(builder, value.string());
     }
 };
 

+ 2 - 2
AK/NonnullOwnPtr.h

@@ -197,9 +197,9 @@ inline void swap(NonnullOwnPtr<T>& a, NonnullOwnPtr<U>& b)
 
 template<typename T>
 struct Formatter<NonnullOwnPtr<T>> : Formatter<const T*> {
-    void format(TypeErasedFormatParams& params, FormatBuilder& builder, const NonnullOwnPtr<T>& value)
+    void format(FormatBuilder& builder, const NonnullOwnPtr<T>& value)
     {
-        Formatter<const T*>::format(params, builder, value.ptr());
+        Formatter<const T*>::format(builder, value.ptr());
     }
 };
 

+ 2 - 2
AK/NonnullRefPtr.h

@@ -348,9 +348,9 @@ inline const LogStream& operator<<(const LogStream& stream, const NonnullRefPtr<
 
 template<typename T>
 struct Formatter<NonnullRefPtr<T>> : Formatter<const T*> {
-    void format(TypeErasedFormatParams& params, FormatBuilder& builder, const NonnullRefPtr<T>& value)
+    void format(FormatBuilder& builder, const NonnullRefPtr<T>& value)
     {
-        Formatter<const T*>::format(params, builder, value.ptr());
+        Formatter<const T*>::format(builder, value.ptr());
     }
 };
 

+ 2 - 2
AK/StringImpl.h

@@ -132,9 +132,9 @@ constexpr u32 string_hash(const char* characters, size_t length)
 
 template<>
 struct Formatter<StringImpl> : Formatter<StringView> {
-    void format(TypeErasedFormatParams& params, FormatBuilder& builder, const StringImpl& value)
+    void format(FormatBuilder& builder, const StringImpl& value)
     {
-        Formatter<StringView>::format(params, builder, { value.characters(), value.length() });
+        Formatter<StringView>::format(builder, { value.characters(), value.length() });
     }
 };
 

+ 2 - 2
AK/Tests/TestFormat.cpp

@@ -213,9 +213,9 @@ struct B {
 };
 template<>
 struct AK::Formatter<B> : Formatter<StringView> {
-    void format(TypeErasedFormatParams& params, FormatBuilder& builder, B)
+    void format(FormatBuilder& builder, B)
     {
-        Formatter<StringView>::format(params, builder, "B");
+        Formatter<StringView>::format(builder, "B");
     }
 };
 

+ 2 - 2
AK/URL.h

@@ -106,9 +106,9 @@ inline const LogStream& operator<<(const LogStream& stream, const URL& value)
 
 template<>
 struct Formatter<URL> : Formatter<StringView> {
-    void format(TypeErasedFormatParams& params, FormatBuilder& builder, const URL& value)
+    void format(FormatBuilder& builder, const URL& value)
     {
-        Formatter<StringView>::format(params, builder, value.to_string());
+        Formatter<StringView>::format(builder, value.to_string());
     }
 };
 

+ 3 - 3
AK/WeakPtr.h

@@ -226,13 +226,13 @@ inline const LogStream& operator<<(const LogStream& stream, const WeakPtr<T>& va
 
 template<typename T>
 struct Formatter<WeakPtr<T>> : Formatter<const T*> {
-    void format(TypeErasedFormatParams& params, FormatBuilder& builder, const WeakPtr<T>& value)
+    void format(FormatBuilder& builder, const WeakPtr<T>& value)
     {
 #ifdef KERNEL
         auto ref = value.strong_ref();
-        Formatter<const T*>::format(params, builder, ref.ptr());
+        Formatter<const T*>::format(builder, ref.ptr());
 #else
-        Formatter<const T*>::format(params, builder, value.ptr());
+        Formatter<const T*>::format(builder, value.ptr());
 #endif
     }
 };

+ 2 - 2
DevTools/UserspaceEmulator/ValueWithShadow.h

@@ -164,8 +164,8 @@ inline void ValueAndShadowReference<T>::operator=(const ValueWithShadow<T>& othe
 
 template<typename T>
 struct AK::Formatter<UserspaceEmulator::ValueWithShadow<T>> : AK::Formatter<T> {
-    void format(TypeErasedFormatParams& params, FormatBuilder& builder, UserspaceEmulator::ValueWithShadow<T> value)
+    void format(FormatBuilder& builder, UserspaceEmulator::ValueWithShadow<T> value)
     {
-        return Formatter<T>::format(params, builder, value.value());
+        return Formatter<T>::format(builder, value.value());
     }
 };

+ 2 - 2
Kernel/VirtualAddress.cpp

@@ -28,9 +28,9 @@
 #include <Kernel/VirtualAddress.h>
 
 namespace AK {
-void Formatter<VirtualAddress>::format(TypeErasedFormatParams& params, FormatBuilder& builder, const VirtualAddress& value)
+void Formatter<VirtualAddress>::format(FormatBuilder& builder, const VirtualAddress& value)
 {
-    Formatter<StringView>::format(params, builder, String::formatted("V{:p}", value.get()));
+    Formatter<StringView>::format(builder, String::formatted("V{:p}", value.get()));
 }
 
 }

+ 3 - 1
Kernel/VirtualAddress.h

@@ -77,8 +77,10 @@ inline const LogStream& operator<<(const LogStream& stream, VirtualAddress value
 }
 
 namespace AK {
+
 template<>
 struct Formatter<VirtualAddress> : Formatter<StringView> {
-    void format(TypeErasedFormatParams&, FormatBuilder&, const VirtualAddress&);
+    void format(FormatBuilder&, const VirtualAddress&);
 };
+
 }

+ 2 - 2
Libraries/LibCore/Object.cpp

@@ -273,9 +273,9 @@ const LogStream& operator<<(const LogStream& stream, const Object& object)
 
 namespace AK {
 
-void Formatter<Core::Object>::format(TypeErasedFormatParams& params, FormatBuilder& builder, const Core::Object& value)
+void Formatter<Core::Object>::format(FormatBuilder& builder, const Core::Object& value)
 {
-    Formatter<StringView>::format(params, builder, String::formatted("{}({})", value.class_name(), &value));
+    Formatter<StringView>::format(builder, String::formatted("{}({})", value.class_name(), &value));
 }
 
 }

+ 1 - 1
Libraries/LibCore/Object.h

@@ -175,7 +175,7 @@ private:
 namespace AK {
 template<>
 struct Formatter<Core::Object> : Formatter<StringView> {
-    void format(TypeErasedFormatParams&, FormatBuilder&, const Core::Object&);
+    void format(FormatBuilder&, const Core::Object&);
 };
 }
 

+ 3 - 3
Libraries/LibGUI/ModelIndex.cpp

@@ -50,14 +50,14 @@ const LogStream& operator<<(const LogStream& stream, const ModelIndex& value)
 
 namespace AK {
 
-void Formatter<GUI::ModelIndex>::format(TypeErasedFormatParams& params, FormatBuilder& builder, const GUI::ModelIndex& value)
+void Formatter<GUI::ModelIndex>::format(FormatBuilder& builder, const GUI::ModelIndex& value)
 {
     Formatter<StringView> 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()));
 }
 
 }

+ 1 - 1
Libraries/LibGUI/ModelIndex.h

@@ -83,7 +83,7 @@ namespace AK {
 
 template<>
 struct Formatter<GUI::ModelIndex> : Formatter<StringView> {
-    void format(TypeErasedFormatParams&, FormatBuilder&, const GUI::ModelIndex&);
+    void format(FormatBuilder&, const GUI::ModelIndex&);
 };
 
 template<>

+ 3 - 3
Libraries/LibGUI/TextPosition.h

@@ -70,12 +70,12 @@ namespace AK {
 
 template<>
 struct Formatter<GUI::TextPosition> : Formatter<StringView> {
-    void format(TypeErasedFormatParams& params, FormatBuilder& builder, const GUI::TextPosition& value)
+    void format(FormatBuilder& builder, const GUI::TextPosition& value)
     {
         if (value.is_valid())
-            Formatter<StringView>::format(params, builder, String::formatted("({},{})", value.line(), value.column()));
+            Formatter<StringView>::format(builder, String::formatted("({},{})", value.line(), value.column()));
         else
-            Formatter<StringView>::format(params, builder, "GUI::TextPosition(Invalid)");
+            Formatter<StringView>::format(builder, "GUI::TextPosition(Invalid)");
     }
 };
 

+ 3 - 3
Libraries/LibGUI/TextRange.h

@@ -98,12 +98,12 @@ namespace AK {
 
 template<>
 struct Formatter<GUI::TextRange> : Formatter<StringView> {
-    void format(TypeErasedFormatParams& params, FormatBuilder& builder, const GUI::TextRange& value)
+    void format(FormatBuilder& builder, const GUI::TextRange& value)
     {
         if (value.is_valid())
-            Formatter<StringView>::format(params, builder, String::formatted("{}-{}", value.start(), value.end()));
+            Formatter<StringView>::format(builder, String::formatted("{}-{}", value.start(), value.end()));
         else
-            Formatter<StringView>::format(params, builder, "GUI::TextRange(Invalid)");
+            Formatter<StringView>::format(builder, "GUI::TextRange(Invalid)");
     }
 };
 

+ 2 - 2
Libraries/LibGfx/Color.cpp

@@ -434,7 +434,7 @@ bool IPC::decode(IPC::Decoder& decoder, Color& color)
     return true;
 }
 
-void AK::Formatter<Gfx::Color>::format(TypeErasedFormatParams& params, FormatBuilder& builder, const Gfx::Color& value)
+void AK::Formatter<Gfx::Color>::format(FormatBuilder& builder, const Gfx::Color& value)
 {
-    Formatter<StringView>::format(params, builder, value.to_string());
+    Formatter<StringView>::format(builder, value.to_string());
 }

+ 5 - 1
Libraries/LibGfx/Color.h

@@ -317,13 +317,17 @@ const LogStream& operator<<(const LogStream&, Color);
 using Gfx::Color;
 
 namespace AK {
+
 template<>
 struct Formatter<Gfx::Color> : public Formatter<StringView> {
-    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&);
+
 }

+ 2 - 2
Libraries/LibGfx/Rect.h

@@ -455,9 +455,9 @@ namespace AK {
 
 template<typename T>
 struct Formatter<Gfx::Rect<T>> : Formatter<StringView> {
-    void format(TypeErasedFormatParams& params, FormatBuilder& builder, const Gfx::Rect<T>& value)
+    void format(FormatBuilder& builder, const Gfx::Rect<T>& value)
     {
-        Formatter<StringView>::format(params, builder, value.to_string());
+        Formatter<StringView>::format(builder, value.to_string());
     }
 };
 

+ 3 - 3
Libraries/LibJS/Runtime/Cell.h

@@ -78,12 +78,12 @@ namespace AK {
 
 template<>
 struct Formatter<JS::Cell> : Formatter<StringView> {
-    void format(TypeErasedFormatParams& params, FormatBuilder& builder, const JS::Cell* cell)
+    void format(FormatBuilder& builder, const JS::Cell* cell)
     {
         if (!cell)
-            Formatter<StringView>::format(params, builder, "Cell{nullptr}");
+            Formatter<StringView>::format(builder, "Cell{nullptr}");
         else
-            Formatter<StringView>::format(params, builder, String::formatted("{}{{{}}}", cell->class_name(), static_cast<const void*>(cell)));
+            Formatter<StringView>::format(builder, String::formatted("{}{{{}}}", cell->class_name(), static_cast<const void*>(cell)));
     }
 };
 

+ 2 - 2
Libraries/LibJS/Runtime/PropertyAttributes.h

@@ -95,9 +95,9 @@ namespace AK {
 
 template<>
 struct Formatter<JS::PropertyAttributes> : Formatter<u8> {
-    void format(TypeErasedFormatParams& params, FormatBuilder& builder, const JS::PropertyAttributes& attributes)
+    void format(FormatBuilder& builder, const JS::PropertyAttributes& attributes)
     {
-        Formatter<u8>::format(params, builder, attributes.bits());
+        Formatter<u8>::format(builder, attributes.bits());
     }
 };
 

+ 2 - 2
Libraries/LibJS/Runtime/Value.h

@@ -345,9 +345,9 @@ namespace AK {
 
 template<>
 struct Formatter<JS::Value> : Formatter<StringView> {
-    void format(TypeErasedFormatParams& params, FormatBuilder& builder, const JS::Value& value)
+    void format(FormatBuilder& builder, const JS::Value& value)
     {
-        Formatter<StringView>::format(params, builder, value.is_empty() ? "<empty>" : value.to_string_without_side_effects());
+        Formatter<StringView>::format(builder, value.is_empty() ? "<empty>" : value.to_string_without_side_effects());
     }
 };
 

+ 4 - 2
Shell/AST.cpp

@@ -37,7 +37,7 @@
 
 //#define EXECUTE_DEBUG
 
-void AK::Formatter<Shell::AST::Command>::format(TypeErasedFormatParams&, FormatBuilder& builder, const Shell::AST::Command& value)
+void AK::Formatter<Shell::AST::Command>::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<Shell::AST::Command>::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()) {

+ 1 - 1
Shell/AST.h

@@ -1301,7 +1301,7 @@ struct Formatter<Shell::AST::Command> : StandardFormatter {
     {
     }
 
-    void format(TypeErasedFormatParams&, FormatBuilder&, const Shell::AST::Command& value);
+    void format(FormatBuilder&, const Shell::AST::Command& value);
 };
 
 }