Common/Assert: Actually use the ASSERT_MSG's log type parameter

Since it was unused, nonexistent values were used in a few places.  I've replaced them.
This commit is contained in:
Pokechu22
2021-11-10 18:34:28 -08:00
parent bab3ff0157
commit 558de04cfc
9 changed files with 48 additions and 38 deletions

View File

@ -577,13 +577,14 @@ void ARM64XEmitter::EncodeAddSubImmInst(u32 op, bool flags, u32 shift, u32 imm,
void ARM64XEmitter::EncodeLogicalImmInst(u32 op, ARM64Reg Rd, ARM64Reg Rn, LogicalImm imm)
{
ASSERT_MSG(DYNAREC, imm.valid, "Invalid logical immediate");
ASSERT_MSG(DYNA_REC, imm.valid, "Invalid logical immediate");
// Sometimes Rd is fixed to SP, but can still be 32bit or 64bit.
// Use Rn to determine bitness here.
bool b64Bit = Is64Bit(Rn);
ASSERT_MSG(DYNAREC, b64Bit || !imm.n, "64-bit logical immediate does not fit in 32-bit register");
ASSERT_MSG(DYNA_REC, b64Bit || !imm.n,
"64-bit logical immediate does not fit in 32-bit register");
Write32((b64Bit << 31) | (op << 29) | (0x24 << 23) | (imm.n << 22) | (imm.r << 16) |
(imm.s << 10) | (DecodeReg(Rn) << 5) | DecodeReg(Rd));

View File

@ -13,10 +13,11 @@
{ \
if (!(_a_)) \
{ \
if (!PanicYesNoFmt("An error occurred.\n\n" _fmt_ "\n\n" \
" Condition: {}\n File: {}\n Line: {}\n Function: {}\n\n" \
"Ignore and continue?", \
##__VA_ARGS__, #_a_, __FILE__, __LINE__, __func__)) \
if (!PanicYesNoFmtAssert(_t_, \
"An error occurred.\n\n" _fmt_ "\n\n" \
" Condition: {}\n File: {}\n Line: {}\n Function: {}\n\n" \
"Ignore and continue?", \
##__VA_ARGS__, #_a_, __FILE__, __LINE__, __func__)) \
Crash(); \
} \
} while (0)

View File

@ -106,10 +106,11 @@ std::string GetStringT(const char* string)
return s_str_translator(string);
}
static bool ShowMessageAlert(std::string_view text, bool yes_no, MsgType style)
static bool ShowMessageAlert(std::string_view text, bool yes_no, Common::Log::LogType log_type,
MsgType style)
{
const char* caption = GetCaption(style);
ERROR_LOG_FMT(MASTER_LOG, "{}: {}", caption, text);
GENERIC_LOG_FMT(log_type, Common::Log::LogLevel::LERROR, "{}: {}", caption, text);
// Panic alerts.
if (style == MsgType::Warning && s_abort_on_panic_alert)
@ -129,11 +130,11 @@ static bool ShowMessageAlert(std::string_view text, bool yes_no, MsgType style)
// This is the first stop for gui alerts where the log is updated and the
// correct window is shown, when using fmt
bool MsgAlertFmtImpl(bool yes_no, MsgType style, fmt::string_view format,
const fmt::format_args& args)
bool MsgAlertFmtImpl(bool yes_no, MsgType style, Common::Log::LogType log_type,
fmt::string_view format, const fmt::format_args& args)
{
const auto message = fmt::vformat(format, args);
return ShowMessageAlert(message, yes_no, style);
return ShowMessageAlert(message, yes_no, log_type, style);
}
} // namespace Common

View File

@ -10,6 +10,7 @@
#include <fmt/format.h>
#include "Common/FormatUtil.h"
#include "Common/Logging/Log.h"
namespace Common
{
@ -30,16 +31,18 @@ void RegisterStringTranslator(StringTranslator translator);
std::string GetStringT(const char* string);
bool MsgAlertFmtImpl(bool yes_no, MsgType style, fmt::string_view format,
const fmt::format_args& args);
bool MsgAlertFmtImpl(bool yes_no, MsgType style, Common::Log::LogType log_type,
fmt::string_view format, const fmt::format_args& args);
template <std::size_t NumFields, typename S, typename... Args>
bool MsgAlertFmt(bool yes_no, MsgType style, const S& format, const Args&... args)
bool MsgAlertFmt(bool yes_no, MsgType style, Common::Log::LogType log_type, const S& format,
const Args&... args)
{
static_assert(NumFields == sizeof...(args),
"Unexpected number of replacement fields in format string; did you pass too few or "
"too many arguments?");
return MsgAlertFmtImpl(yes_no, style, format, fmt::make_args_checked<Args...>(format, args...));
return MsgAlertFmtImpl(yes_no, style, log_type, format,
fmt::make_args_checked<Args...>(format, args...));
}
void SetEnableAlert(bool enable);
@ -55,51 +58,55 @@ std::string FmtFormatT(const char* string, Args&&... args)
// Fmt-capable variants of the macros
#define GenericAlertFmt(yes_no, style, format, ...) \
#define GenericAlertFmt(yes_no, style, log_type, format, ...) \
[&] { \
/* Use a macro-like name to avoid shadowing warnings */ \
constexpr auto GENERIC_ALERT_FMT_N = Common::CountFmtReplacementFields(format); \
return Common::MsgAlertFmt<GENERIC_ALERT_FMT_N>(yes_no, style, FMT_STRING(format), \
##__VA_ARGS__); \
return Common::MsgAlertFmt<GENERIC_ALERT_FMT_N>(yes_no, style, Common::Log::LogType::log_type, \
FMT_STRING(format), ##__VA_ARGS__); \
}()
#define GenericAlertFmtT(yes_no, style, format, ...) \
#define GenericAlertFmtT(yes_no, style, log_type, format, ...) \
[&] { \
static_assert(!Common::ContainsNonPositionalArguments(format), \
"Translatable strings must use positional arguments (e.g. {0} instead of {})"); \
/* Use a macro-like name to avoid shadowing warnings */ \
constexpr auto GENERIC_ALERT_FMT_N = Common::CountFmtReplacementFields(format); \
return Common::MsgAlertFmt<GENERIC_ALERT_FMT_N>(yes_no, style, FMT_STRING(format), \
##__VA_ARGS__); \
return Common::MsgAlertFmt<GENERIC_ALERT_FMT_N>(yes_no, style, Common::Log::LogType::log_type, \
FMT_STRING(format), ##__VA_ARGS__); \
}()
#define SuccessAlertFmt(format, ...) \
GenericAlertFmt(false, Common::MsgType::Information, format, ##__VA_ARGS__)
GenericAlertFmt(false, Common::MsgType::Information, MASTER_LOG, format, ##__VA_ARGS__)
#define PanicAlertFmt(format, ...) \
GenericAlertFmt(false, Common::MsgType::Warning, format, ##__VA_ARGS__)
GenericAlertFmt(false, Common::MsgType::Warning, MASTER_LOG, format, ##__VA_ARGS__)
#define PanicYesNoFmt(format, ...) \
GenericAlertFmt(true, Common::MsgType::Warning, format, ##__VA_ARGS__)
GenericAlertFmt(true, Common::MsgType::Warning, MASTER_LOG, format, ##__VA_ARGS__)
#define AskYesNoFmt(format, ...) \
GenericAlertFmt(true, Common::MsgType::Question, format, ##__VA_ARGS__)
GenericAlertFmt(true, Common::MsgType::Question, MASTER_LOG, format, ##__VA_ARGS__)
#define CriticalAlertFmt(format, ...) \
GenericAlertFmt(false, Common::MsgType::Critical, format, ##__VA_ARGS__)
GenericAlertFmt(false, Common::MsgType::Critical, MASTER_LOG, format, ##__VA_ARGS__)
// Use these macros (that do the same thing) if the message should be translated.
#define SuccessAlertFmtT(format, ...) \
GenericAlertFmtT(false, Common::MsgType::Information, format, ##__VA_ARGS__)
GenericAlertFmtT(false, Common::MsgType::Information, MASTER_LOG, format, ##__VA_ARGS__)
#define PanicAlertFmtT(format, ...) \
GenericAlertFmtT(false, Common::MsgType::Warning, format, ##__VA_ARGS__)
GenericAlertFmtT(false, Common::MsgType::Warning, MASTER_LOG, format, ##__VA_ARGS__)
#define PanicYesNoFmtT(format, ...) \
GenericAlertFmtT(true, Common::MsgType::Warning, format, ##__VA_ARGS__)
GenericAlertFmtT(true, Common::MsgType::Warning, MASTER_LOG, format, ##__VA_ARGS__)
#define AskYesNoFmtT(format, ...) \
GenericAlertFmtT(true, Common::MsgType::Question, format, ##__VA_ARGS__)
GenericAlertFmtT(true, Common::MsgType::Question, MASTER_LOG, format, ##__VA_ARGS__)
#define CriticalAlertFmtT(format, ...) \
GenericAlertFmtT(false, Common::MsgType::Critical, format, ##__VA_ARGS__)
GenericAlertFmtT(false, Common::MsgType::Critical, MASTER_LOG, format, ##__VA_ARGS__)
// Variant that takes a log type, used by the assert macros
#define PanicYesNoFmtAssert(log_type, format, ...) \
GenericAlertFmt(true, Common::MsgType::Warning, log_type, format, ##__VA_ARGS__)