From 0078c7c66106d50433014cf2f80664e22380e260 Mon Sep 17 00:00:00 2001 From: Qudix <17361645+Qudix@users.noreply.github.com> Date: Fri, 25 Apr 2025 11:14:01 -0500 Subject: [PATCH 1/4] feat: use `std::format` --- Caprica/common/CapricaReportingContext.cpp | 14 +++++------ Caprica/common/CapricaReportingContext.h | 29 +++++++++++----------- Caprica/common/identifier_ref.h | 12 ++++----- Caprica/papyrus/PapyrusIdentifier.h | 8 +++--- Caprica/papyrus/PapyrusType.h | 8 +++--- 5 files changed, 33 insertions(+), 38 deletions(-) diff --git a/Caprica/common/CapricaReportingContext.cpp b/Caprica/common/CapricaReportingContext.cpp index a90694c..d23ce12 100644 --- a/Caprica/common/CapricaReportingContext.cpp +++ b/Caprica/common/CapricaReportingContext.cpp @@ -24,7 +24,7 @@ void CapricaReportingContext::breakIfDebugging() { void CapricaReportingContext::exitIfErrors() { if (errorCount > 0) { - pushToErrorStream(fmt::format("Compilation of '{}' failed; {} warnings and {} errors were encountered.", filename, warningCount, errorCount)); + pushToErrorStream(std::format("Compilation of '{}' failed; {} warnings and {} errors were encountered.", filename, warningCount, errorCount)); throw std::runtime_error(""); } } @@ -63,7 +63,7 @@ size_t CapricaReportingContext::getLocationLine(CapricaFileLocation location, si } } // TODO: Fix line offsets during parsing for reals, remove this hack - // maybePushMessage(this, nullptr, "Warning:", 0, fmt::format("Unable to locate line at offset {}, using last known line {}...", location.startOffset, lineOffsets.size()), true); + // maybePushMessage(this, nullptr, "Warning:", 0, std::format("Unable to locate line at offset {}, using last known line {}...", location.startOffset, lineOffsets.size()), true); return lineOffsets.size(); // CapricaReportingContext::logicalFatal("Unable to locate line at offset {}.", location.startOffset); } @@ -74,7 +74,7 @@ std::string CapricaReportingContext::formatLocation(CapricaFileLocation loc) { auto line = getLocationLine(loc); auto column = loc.startOffset - lineOffsets.at(line - 1) + 1; auto columnEnd = loc.endOffset - loc.startOffset + column; - return fmt::format("{} ({}, {}:{})", filename, line, column, columnEnd); + return std::format("{} ({}, {}:{})", filename, line, column, columnEnd); } void CapricaReportingContext::maybePushMessage(CapricaReportingContext* ctx, @@ -87,16 +87,16 @@ void CapricaReportingContext::maybePushMessage(CapricaReportingContext* ctx, if (ctx->isWarningEnabled(*location, warningNumber)) { if (ctx->isWarningError(*location, warningNumber)) { ctx->errorCount++; - pushToErrorStream(fmt::format("{}: Error W{}: {}", ctx->formatLocation(*location), warningNumber, msg), true); + pushToErrorStream(std::format("{}: Error W{}: {}", ctx->formatLocation(*location), warningNumber, msg), true); } else { ctx->warningCount++; - pushToErrorStream(fmt::format("{}: Warning W{}: {}", ctx->formatLocation(*location), warningNumber, msg)); + pushToErrorStream(std::format("{}: Warning W{}: {}", ctx->formatLocation(*location), warningNumber, msg)); } } } else if (location != nullptr) { - pushToErrorStream(fmt::format("{}: {}: {}", ctx->formatLocation(*location), msgType, msg), forceAsError); + pushToErrorStream(std::format("{}: {}: {}", ctx->formatLocation(*location), msgType, msg), forceAsError); } else { - pushToErrorStream(fmt::format("{}: {}", msgType, msg), forceAsError); + pushToErrorStream(std::format("{}: {}", msgType, msg), forceAsError); } } diff --git a/Caprica/common/CapricaReportingContext.h b/Caprica/common/CapricaReportingContext.h index 22deaec..b546850 100644 --- a/Caprica/common/CapricaReportingContext.h +++ b/Caprica/common/CapricaReportingContext.h @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include @@ -42,15 +42,22 @@ struct CapricaReportingContext final { void exitIfErrors(); template - NEVER_INLINE void error(CapricaFileLocation location, fmt::format_string msg, Args&&... args) { + ALWAYS_INLINE void warning(CapricaFileLocation location, size_t warningNumber, std::string_view msg, Args&&... args) { + // TODO: fix Imports hack + if (!m_QuietWarnings) + maybePushMessage(this, &location, "", warningNumber, std::vformat(msg, std::make_format_args(args...))); + } + + template + NEVER_INLINE void error(CapricaFileLocation location, std::string_view msg, Args&&... args) { errorCount++; - maybePushMessage(this, &location, "Error", 0, fmt::format(msg, std::forward(args)...), true); + maybePushMessage(this, &location, "Error", 0, std::vformat(msg, std::make_format_args(args...)), true); breakIfDebugging(); } template - [[noreturn]] NEVER_INLINE void fatal(CapricaFileLocation location, fmt::format_string msg, Args&&... args) { - maybePushMessage(this, &location, "Fatal Error", 0, fmt::format(msg, std::forward(args)...), true); + [[noreturn]] NEVER_INLINE void fatal(CapricaFileLocation location, std::string_view msg, Args&&... args) { + maybePushMessage(this, &location, "Fatal Error", 0, std::vformat(msg, std::make_format_args(args...)), true); throw std::runtime_error(""); } @@ -58,8 +65,8 @@ struct CapricaReportingContext final { // where the logic of Caprica itself has failed, and a location in a source // file is likely not available. template - [[noreturn]] NEVER_INLINE static void logicalFatal(fmt::format_string msg, Args&&... args) { - maybePushMessage(nullptr, nullptr, "Fatal Error", 0, fmt::format(msg, std::forward(args)...), true); + [[noreturn]] NEVER_INLINE static void logicalFatal(std::string_view msg, Args&&... args) { + maybePushMessage(nullptr, nullptr, "Fatal Error", 0, std::vformat(msg, std::make_format_args(args...)), true); throw std::runtime_error(""); } @@ -334,14 +341,6 @@ struct CapricaReportingContext final { size_t warnNum, const std::string& msg, bool forceAsError = false); - - template - ALWAYS_INLINE void - warning(CapricaFileLocation location, size_t warningNumber, fmt::format_string msg, Args&&... args) { - // TODO: fix Imports hack - if (!m_QuietWarnings) - maybePushMessage(this, &location, "", warningNumber, fmt::format(msg, std::forward(args)...)); - } }; } diff --git a/Caprica/common/identifier_ref.h b/Caprica/common/identifier_ref.h index b3820dc..74f0409 100644 --- a/Caprica/common/identifier_ref.h +++ b/Caprica/common/identifier_ref.h @@ -7,7 +7,7 @@ #include #include -#include +#include #include @@ -97,10 +97,11 @@ bool operator!=(const char* x, const identifier_ref& y); } -namespace fmt { template <> -struct formatter { - constexpr auto parse(format_parse_context& ctx) { +struct std::formatter +{ + template + constexpr auto parse(ParseContext& ctx) { if (ctx.begin() != ctx.end()) throw format_error("invalid format"); return ctx.end(); @@ -108,7 +109,6 @@ struct formatter { template auto format(const caprica::identifier_ref& str, FormatContext& ctx) const { - return fmt::format_to(ctx.out(), "{}", str.to_string_view()); + return std::format_to(ctx.out(), "{}", str.to_string_view()); } }; -} diff --git a/Caprica/papyrus/PapyrusIdentifier.h b/Caprica/papyrus/PapyrusIdentifier.h index ef01fee..8c83697 100644 --- a/Caprica/papyrus/PapyrusIdentifier.h +++ b/Caprica/papyrus/PapyrusIdentifier.h @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include @@ -176,9 +176,8 @@ struct PapyrusIdentifier final { }} -namespace fmt { template <> -struct formatter { +struct std::formatter { constexpr auto parse(format_parse_context& ctx) { if (ctx.begin() != ctx.end()) throw format_error("invalid format"); @@ -187,7 +186,6 @@ struct formatter { template auto format(const caprica::papyrus::PapyrusIdentifierType& tp, FormatContext& ctx) const { - return fmt::format_to(ctx.out(), "{}", caprica::papyrus::PapyrusIdentifier::prettyTypeString(tp)); + return std::format_to(ctx.out(), "{}", caprica::papyrus::PapyrusIdentifier::prettyTypeString(tp)); } }; -} diff --git a/Caprica/papyrus/PapyrusType.h b/Caprica/papyrus/PapyrusType.h index 68fa926..7004523 100644 --- a/Caprica/papyrus/PapyrusType.h +++ b/Caprica/papyrus/PapyrusType.h @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include @@ -152,9 +152,8 @@ inline auto& operator|=(PapyrusType::PoisonKind& a, PapyrusType::PoisonKind b) { }} -namespace fmt { template <> -struct formatter { +struct std::formatter { constexpr auto parse(format_parse_context& ctx) { if (ctx.begin() != ctx.end()) throw format_error("invalid format"); @@ -163,7 +162,6 @@ struct formatter { template auto format(const caprica::papyrus::PapyrusType& tp, FormatContext& ctx) const { - return fmt::format_to(ctx.out(), "{}", tp.prettyString()); + return std::format_to(ctx.out(), "{}", tp.prettyString()); } }; -} From cd67f104b210702c4a5e992400f2d6ca3bed3a76 Mon Sep 17 00:00:00 2001 From: Qudix <17361645+Qudix@users.noreply.github.com> Date: Fri, 25 Apr 2025 11:15:54 -0500 Subject: [PATCH 2/4] feat: `xmake` support --- .gitignore | 2 ++ xmake.lua | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 xmake.lua diff --git a/.gitignore b/.gitignore index 25cd78b..20d3163 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .vs/ .vscode/ .idea/ +.xmake/ *.db *.vcxproj.user @@ -46,3 +47,4 @@ Caprica/INSTALL.vcxproj.filters Caprica/cmake_install.cmake x64/ +vs*/ diff --git a/xmake.lua b/xmake.lua new file mode 100644 index 0000000..ff64fde --- /dev/null +++ b/xmake.lua @@ -0,0 +1,31 @@ +-- set project +set_project("caprica") +set_languages("c++23") +set_license("MIT") +set_version("0.3.0") + +-- require packages +add_requires("boost", { configs = { filesystem = true, program_options = true, container = true } }) +add_requires("pugixml") + +-- define targets +target("caprica", function() + set_kind("$(kind)") + + -- bind package dependencies + add_packages("boost", "pugixml", { public = true }) + + -- add all source files + add_files("caprica/**/**.cpp") + + if is_kind("binary") then + add_files("caprica/**.cpp") + end + + -- add all header files + add_includedirs("caprica", { public = true }) + add_headerfiles("(caprica/**.h)") + + -- add flags + add_cxxflags("cl::/Zc:inline", "cl::/bigobj") +end) From 7a763258de2ab1dc7d7dbce882405942555c4195 Mon Sep 17 00:00:00 2001 From: Qudix <17361645+Qudix@users.noreply.github.com> Date: Fri, 25 Apr 2025 12:35:17 -0500 Subject: [PATCH 3/4] feat: use `xmake` namespacing --- xmake.lua | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/xmake.lua b/xmake.lua index ff64fde..b3a1a37 100644 --- a/xmake.lua +++ b/xmake.lua @@ -8,24 +8,26 @@ set_version("0.3.0") add_requires("boost", { configs = { filesystem = true, program_options = true, container = true } }) add_requires("pugixml") --- define targets -target("caprica", function() - set_kind("$(kind)") +namespace("caprica", function() + -- define targets + target("caprica", function() + set_kind("$(kind)") - -- bind package dependencies - add_packages("boost", "pugixml", { public = true }) + -- bind package dependencies + add_packages("boost", "pugixml", { public = true }) - -- add all source files - add_files("caprica/**/**.cpp") + -- add all source files + add_files("caprica/**/**.cpp") - if is_kind("binary") then - add_files("caprica/**.cpp") - end + if is_kind("binary") then + add_files("caprica/**.cpp") + end - -- add all header files - add_includedirs("caprica", { public = true }) - add_headerfiles("(caprica/**.h)") + -- add all header files + add_includedirs("caprica", { public = true }) + add_headerfiles("(caprica/**.h)") - -- add flags - add_cxxflags("cl::/Zc:inline", "cl::/bigobj") + -- add flags + add_cxxflags("cl::/Zc:inline", "cl::/bigobj") + end) end) From 0b2d329071f81ceecf7ead70d5b4d8b8b564befb Mon Sep 17 00:00:00 2001 From: Qudix <17361645+Qudix@users.noreply.github.com> Date: Fri, 25 Apr 2025 12:53:08 -0500 Subject: [PATCH 4/4] feat: set minimum `xmake` version --- xmake.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xmake.lua b/xmake.lua index b3a1a37..284eba0 100644 --- a/xmake.lua +++ b/xmake.lua @@ -1,3 +1,6 @@ +-- set minimum xmake version +set_xmakever("2.9.8") + -- set project set_project("caprica") set_languages("c++23")