1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:38:11 +00:00

AK+Format: Remove TypeErasedFormatParams& from format function.

This commit is contained in:
asynts 2020-12-30 12:14:15 +01:00 committed by Andreas Kling
parent 865f5ed4f6
commit 7e62ffbc6e
27 changed files with 129 additions and 134 deletions

View file

@ -98,44 +98,32 @@ void vformat_impl(TypeErasedFormatParams& params, FormatBuilder& builder, Format
} // namespace AK::{anonymous} } // 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) i64 svalue;
return default_value;
if (value == StandardFormatter::value_from_next_arg) if (type == TypeErasedParameter::Type::UInt8)
value = StandardFormatter::value_from_arg + take_next_index(); 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 (value >= StandardFormatter::value_from_arg) { ASSERT(svalue >= 0);
const auto parameter = parameters().at(value - StandardFormatter::value_from_arg);
Optional<i64> svalue; return static_cast<size_t>(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();
if (svalue.has_value()) {
ASSERT(svalue.value() >= 0);
value = static_cast<size_t>(svalue.value());
}
}
return value;
} }
FormatParser::FormatParser(StringView input) FormatParser::FormatParser(StringView input)
@ -467,7 +455,7 @@ void StandardFormatter::parse(TypeErasedFormatParams& params, FormatParser& pars
if (index == use_next_index) if (index == use_next_index)
index = params.take_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)) { } else if (size_t width = 0; parser.consume_number(width)) {
m_width = width; m_width = width;
} }
@ -477,7 +465,7 @@ void StandardFormatter::parse(TypeErasedFormatParams& params, FormatParser& pars
if (index == use_next_index) if (index == use_next_index)
index = params.take_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)) { } else if (size_t precision = 0; parser.consume_number(precision)) {
m_precision = precision; m_precision = precision;
} }
@ -514,7 +502,7 @@ void StandardFormatter::parse(TypeErasedFormatParams& params, FormatParser& pars
ASSERT(parser.is_eof()); 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) if (m_sign_mode != FormatBuilder::SignMode::Default)
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
@ -524,17 +512,17 @@ void Formatter<StringView>::format(TypeErasedFormatParams& params, FormatBuilder
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
if (m_mode != Mode::Default && m_mode != Mode::String && m_mode != Mode::Character) if (m_mode != Mode::Default && m_mode != Mode::String && m_mode != Mode::Character)
ASSERT_NOT_REACHED(); 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(); ASSERT_NOT_REACHED();
const auto width = params.decode(m_width); m_width = m_width.value_or(0);
const auto precision = params.decode(m_precision, NumericLimits<size_t>::max()); 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> 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) { if (m_mode == Mode::Character) {
// FIXME: We just support ASCII for now, in the future maybe unicode? // 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; m_mode = Mode::String;
Formatter<StringView> formatter { *this }; 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(); ASSERT_NOT_REACHED();
if (m_mode == Mode::Pointer) { if (m_mode == Mode::Pointer) {
@ -556,7 +544,7 @@ void Formatter<T, typename EnableIf<IsIntegral<T>::value>::Type>::format(TypeEra
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
if (m_alternative_form) if (m_alternative_form)
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
if (m_width != value_not_set) if (m_width.has_value())
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
m_mode = Mode::Hexadecimal; m_mode = Mode::Hexadecimal;
@ -585,37 +573,37 @@ void Formatter<T, typename EnableIf<IsIntegral<T>::value>::Type>::format(TypeEra
ASSERT_NOT_REACHED(); 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) 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 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) { 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.) // Trick: signed char != char. (Sometimes weird features are actually helpful.)
Formatter<signed char> formatter { *this }; 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 { } else {
Formatter<StringView> formatter { *this }; 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) { 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 }; Formatter<u8> formatter { *this };
return formatter.format(params, builder, static_cast<u8>(value)); return formatter.format(builder, static_cast<u8>(value));
} else { } else {
Formatter<StringView> formatter { *this }; Formatter<StringView> formatter { *this };
return formatter.format(params, builder, value ? "true" : "false"); return formatter.format(builder, value ? "true" : "false");
} }
} }
#ifndef KERNEL #ifndef KERNEL
void Formatter<double>::format(TypeErasedFormatParams& params, FormatBuilder& builder, double value) void Formatter<double>::format(FormatBuilder& builder, double value)
{ {
u8 base; u8 base;
bool upper_case; bool upper_case;
@ -632,15 +620,15 @@ void Formatter<double>::format(TypeErasedFormatParams& params, FormatBuilder& bu
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
} }
const auto width = params.decode(m_width); m_width = m_width.value_or(0);
const auto precision = params.decode(m_precision, 6); 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<double> formatter { *this };
formatter.format(params, builder, value); formatter.format(builder, value);
} }
#endif #endif

View file

@ -28,6 +28,7 @@
#include <AK/Array.h> #include <AK/Array.h>
#include <AK/GenericLexer.h> #include <AK/GenericLexer.h>
#include <AK/Optional.h>
#include <AK/StringView.h> #include <AK/StringView.h>
#ifndef KERNEL #ifndef KERNEL
@ -94,6 +95,10 @@ struct TypeErasedParameter {
return Type::Custom; return Type::Custom;
} }
size_t to_size() const;
// FIXME: Getters and setters.
const void* value; const void* value;
Type type; Type type;
void (*formatter)(TypeErasedFormatParams&, FormatBuilder&, FormatParser&, const void* value); void (*formatter)(TypeErasedFormatParams&, FormatBuilder&, FormatParser&, const void* value);
@ -197,8 +202,6 @@ public:
void set_parameters(Span<const TypeErasedParameter> parameters) { m_parameters = parameters; } void set_parameters(Span<const TypeErasedParameter> parameters) { m_parameters = parameters; }
size_t take_next_index() { return m_next_index++; } size_t take_next_index() { return m_next_index++; }
size_t decode(size_t value, size_t default_value = 0);
private: private:
Span<const TypeErasedParameter> m_parameters; Span<const TypeErasedParameter> m_parameters;
size_t m_next_index { 0 }; size_t m_next_index { 0 };
@ -210,7 +213,7 @@ void __format_value(TypeErasedFormatParams& params, FormatBuilder& builder, Form
Formatter<T> formatter; Formatter<T> formatter;
formatter.parse(params, parser); formatter.parse(params, parser);
formatter.format(params, builder, *static_cast<const T*>(value)); formatter.format(builder, *static_cast<const T*>(value));
} }
template<typename... Parameters> template<typename... Parameters>
@ -249,18 +252,14 @@ struct StandardFormatter {
HexfloatUppercase, 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::Align m_align = FormatBuilder::Align::Default;
FormatBuilder::SignMode m_sign_mode = FormatBuilder::SignMode::OnlyIfNeeded; FormatBuilder::SignMode m_sign_mode = FormatBuilder::SignMode::OnlyIfNeeded;
Mode m_mode = Mode::Default; Mode m_mode = Mode::Default;
bool m_alternative_form = false; bool m_alternative_form = false;
char m_fill = ' '; char m_fill = ' ';
bool m_zero_pad = false; bool m_zero_pad = false;
size_t m_width = value_not_set; Optional<size_t> m_width;
size_t m_precision = value_not_set; Optional<size_t> m_precision;
void parse(TypeErasedFormatParams&, FormatParser&); 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<> template<>
@ -284,17 +283,17 @@ struct Formatter<StringView> : StandardFormatter {
{ {
} }
void format(TypeErasedFormatParams&, FormatBuilder&, StringView value); void format(FormatBuilder&, StringView value);
}; };
template<> template<>
struct Formatter<const char*> : Formatter<StringView> { 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) { if (m_mode == Mode::Pointer) {
Formatter<FlatPtr> formatter { *this }; Formatter<FlatPtr> formatter { *this };
formatter.format(params, builder, reinterpret_cast<FlatPtr>(value)); formatter.format(builder, reinterpret_cast<FlatPtr>(value));
} else { } else {
Formatter<StringView>::format(params, builder, value); Formatter<StringView>::format(builder, value);
} }
} }
}; };
@ -313,29 +312,29 @@ struct Formatter<FlyString> : Formatter<StringView> {
template<typename T> template<typename T>
struct Formatter<T*> : StandardFormatter { struct Formatter<T*> : StandardFormatter {
void format(TypeErasedFormatParams& params, FormatBuilder& builder, T* value) void format(FormatBuilder& builder, T* value)
{ {
if (m_mode == Mode::Default) if (m_mode == Mode::Default)
m_mode = Mode::Pointer; m_mode = Mode::Pointer;
Formatter<FlatPtr> formatter { *this }; Formatter<FlatPtr> formatter { *this };
formatter.format(params, builder, reinterpret_cast<FlatPtr>(value)); formatter.format(builder, reinterpret_cast<FlatPtr>(value));
} }
}; };
template<> template<>
struct Formatter<char> : StandardFormatter { struct Formatter<char> : StandardFormatter {
void format(TypeErasedFormatParams&, FormatBuilder&, char value); void format(FormatBuilder&, char value);
}; };
template<> template<>
struct Formatter<bool> : StandardFormatter { struct Formatter<bool> : StandardFormatter {
void format(TypeErasedFormatParams&, FormatBuilder&, bool value); void format(FormatBuilder&, bool value);
}; };
#ifndef KERNEL #ifndef KERNEL
template<> template<>
struct Formatter<float> : StandardFormatter { struct Formatter<float> : StandardFormatter {
void format(TypeErasedFormatParams&, FormatBuilder&, float value); void format(FormatBuilder&, float value);
}; };
template<> template<>
struct Formatter<double> : StandardFormatter { struct Formatter<double> : StandardFormatter {
@ -345,7 +344,7 @@ struct Formatter<double> : StandardFormatter {
{ {
} }
void format(TypeErasedFormatParams&, FormatBuilder&, double value); void format(FormatBuilder&, double value);
}; };
#endif #endif
@ -409,16 +408,16 @@ private:
}; };
template<typename T, bool Supported = false> template<typename T, bool Supported = false>
struct __FormatIfSupported : Formatter<StringView> { 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> template<typename T>
struct __FormatIfSupported<T, true> : Formatter<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> template<typename T>

View file

@ -263,9 +263,9 @@ private:
template<> template<>
struct Formatter<JsonValue> : Formatter<StringView> { 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());
} }
}; };

View file

@ -66,9 +66,9 @@ private:
template<> template<>
struct Formatter<LexicalPath> : Formatter<StringView> { 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());
} }
}; };

View file

@ -197,9 +197,9 @@ inline void swap(NonnullOwnPtr<T>& a, NonnullOwnPtr<U>& b)
template<typename T> template<typename T>
struct Formatter<NonnullOwnPtr<T>> : Formatter<const 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());
} }
}; };

View file

@ -348,9 +348,9 @@ inline const LogStream& operator<<(const LogStream& stream, const NonnullRefPtr<
template<typename T> template<typename T>
struct Formatter<NonnullRefPtr<T>> : Formatter<const 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());
} }
}; };

View file

@ -132,9 +132,9 @@ constexpr u32 string_hash(const char* characters, size_t length)
template<> template<>
struct Formatter<StringImpl> : Formatter<StringView> { 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() });
} }
}; };

View file

@ -213,9 +213,9 @@ struct B {
}; };
template<> template<>
struct AK::Formatter<B> : Formatter<StringView> { 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");
} }
}; };

View file

@ -106,9 +106,9 @@ inline const LogStream& operator<<(const LogStream& stream, const URL& value)
template<> template<>
struct Formatter<URL> : Formatter<StringView> { 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());
} }
}; };

View file

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

View file

@ -164,8 +164,8 @@ inline void ValueAndShadowReference<T>::operator=(const ValueWithShadow<T>& othe
template<typename T> template<typename T>
struct AK::Formatter<UserspaceEmulator::ValueWithShadow<T>> : AK::Formatter<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());
} }
}; };

View file

@ -28,9 +28,9 @@
#include <Kernel/VirtualAddress.h> #include <Kernel/VirtualAddress.h>
namespace AK { 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()));
} }
} }

View file

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

View file

@ -273,9 +273,9 @@ const LogStream& operator<<(const LogStream& stream, const Object& object)
namespace AK { 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));
} }
} }

View file

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

View file

@ -50,14 +50,14 @@ const LogStream& operator<<(const LogStream& stream, const ModelIndex& value)
namespace AK { 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 }; Formatter<StringView> formatter { *this };
if (value.internal_data()) 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 else
formatter.format(params, builder, String::formatted("ModelIndex({},{})", value.row(), value.column())); formatter.format(builder, String::formatted("ModelIndex({},{})", value.row(), value.column()));
} }
} }

View file

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

View file

@ -70,12 +70,12 @@ namespace AK {
template<> template<>
struct Formatter<GUI::TextPosition> : Formatter<StringView> { 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()) 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 else
Formatter<StringView>::format(params, builder, "GUI::TextPosition(Invalid)"); Formatter<StringView>::format(builder, "GUI::TextPosition(Invalid)");
} }
}; };

View file

@ -98,12 +98,12 @@ namespace AK {
template<> template<>
struct Formatter<GUI::TextRange> : Formatter<StringView> { 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()) 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 else
Formatter<StringView>::format(params, builder, "GUI::TextRange(Invalid)"); Formatter<StringView>::format(builder, "GUI::TextRange(Invalid)");
} }
}; };

View file

@ -434,7 +434,7 @@ bool IPC::decode(IPC::Decoder& decoder, Color& color)
return true; 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());
} }

View file

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

View file

@ -455,9 +455,9 @@ namespace AK {
template<typename T> template<typename T>
struct Formatter<Gfx::Rect<T>> : Formatter<StringView> { 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());
} }
}; };

View file

@ -78,12 +78,12 @@ namespace AK {
template<> template<>
struct Formatter<JS::Cell> : Formatter<StringView> { 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) if (!cell)
Formatter<StringView>::format(params, builder, "Cell{nullptr}"); Formatter<StringView>::format(builder, "Cell{nullptr}");
else 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)));
} }
}; };

View file

@ -95,9 +95,9 @@ namespace AK {
template<> template<>
struct Formatter<JS::PropertyAttributes> : Formatter<u8> { 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());
} }
}; };

View file

@ -345,9 +345,9 @@ namespace AK {
template<> template<>
struct Formatter<JS::Value> : Formatter<StringView> { 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());
} }
}; };

View file

@ -37,7 +37,7 @@
//#define EXECUTE_DEBUG //#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) if (m_sign_mode != FormatBuilder::SignMode::Default)
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
@ -47,7 +47,9 @@ void AK::Formatter<Shell::AST::Command>::format(TypeErasedFormatParams&, FormatB
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
if (m_mode != Mode::Default && m_mode != Mode::String) if (m_mode != Mode::Default && m_mode != Mode::String)
ASSERT_NOT_REACHED(); 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(); ASSERT_NOT_REACHED();
if (value.argv.is_empty()) { if (value.argv.is_empty()) {

View file

@ -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);
}; };
} }