Refactor log.

This commit is contained in:
ykiko
2024-11-27 23:21:52 +08:00
parent 3ea080c93d
commit 939dbc3dc5
12 changed files with 273 additions and 294 deletions

View File

@@ -3,16 +3,38 @@
#include <format>
#include "llvm/ADT/StringRef.h"
#include "Error.h"
template <>
struct std::formatter<llvm::StringRef> : std::formatter<std::string_view> {
using Base = std::formatter<std::string_view>;
template <typename ParseContext>
constexpr auto parse(ParseContext& ctx) {
return std::formatter<std::string_view>::parse(ctx);
return Base::parse(ctx);
}
template <typename FormatContext>
auto format(llvm::StringRef s, FormatContext& ctx) const {
return std::formatter<std::string_view>::format(std::string_view(s.str()), ctx);
return Base::format(std::string_view(s.str()), ctx);
}
};
template <>
struct std::formatter<llvm::Error> : std::formatter<llvm::StringRef> {
using Base = std::formatter<llvm::StringRef>;
template <typename ParseContext>
constexpr auto parse(ParseContext& ctx) {
return Base::parse(ctx);
}
template <typename FormatContext>
auto format(const llvm::Error& e, FormatContext& ctx) const {
llvm::SmallString<128> buffer;
llvm::raw_svector_ostream os(buffer);
os << e;
return Base::format(buffer, ctx);
}
};