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/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()); } }; -} diff --git a/xmake.lua b/xmake.lua new file mode 100644 index 0000000..284eba0 --- /dev/null +++ b/xmake.lua @@ -0,0 +1,36 @@ +-- set minimum xmake version +set_xmakever("2.9.8") + +-- 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") + +namespace("caprica", function() + -- 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) +end)