From 8de4c06c7468a41ee7c5f2063aca6265146c30ca Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Mon, 14 Jul 2025 18:07:09 -0300 Subject: [PATCH] remove dependency on fmt library, using std::format instead This bumps the standard version to C++23, so that the `formattable` concept becomes available. This removes the color support from `diff.cpp`, since that is not available in std::format. --- .github/workflows/ci.yml | 23 +--- CMakeLists.txt | 6 +- docs/modules/ROOT/pages/install.adoc | 23 +--- include/mrdocs/Dom/Object.ipp | 9 +- include/mrdocs/Dom/String.hpp | 20 ++-- include/mrdocs/Dom/Value.hpp | 29 +++-- include/mrdocs/Metadata/Javadoc.hpp | 15 +-- include/mrdocs/Support/Error.hpp | 46 ++++---- include/mrdocs/Support/Expected.hpp | 9 +- include/mrdocs/Support/Handlebars.hpp | 26 ++--- include/mrdocs/Support/Lua.hpp | 24 ++-- include/mrdocs/Support/Report.hpp | 33 ++---- src/lib/AST/ParseJavadoc.cpp | 57 +++++----- src/lib/AST/ParseRef.cpp | 23 ++-- src/lib/Dom/Object.cpp | 7 +- src/lib/Dom/String.cpp | 3 +- src/lib/Gen/hbs/Builder.cpp | 77 +++++++------ src/lib/Gen/hbs/HandlebarsCorpus.cpp | 4 +- src/lib/Lib/Diagnostics.hpp | 19 ++-- src/lib/Lib/MrDocsCompilationDatabase.cpp | 24 ++-- .../Finalizers/BaseMembersFinalizer.cpp | 9 +- .../Metadata/Finalizers/Javadoc/Function.hpp | 15 +-- .../Metadata/Finalizers/JavadocFinalizer.cpp | 22 ++-- .../Metadata/Finalizers/JavadocFinalizer.hpp | 6 +- src/lib/Metadata/Info/Overloads.cpp | 15 ++- src/lib/Metadata/Javadoc.cpp | 18 ++- src/lib/Metadata/Specifiers.cpp | 5 +- src/lib/Support/Assert.cpp | 9 +- src/lib/Support/Chrono.hpp | 12 +- src/lib/Support/Debug.cpp | 79 ++++--------- src/lib/Support/Debug.hpp | 70 ++++++------ src/lib/Support/Handlebars.cpp | 104 +++++++++--------- src/lib/Support/JavaScript.cpp | 11 +- src/lib/Support/LegibleNames.cpp | 11 +- src/lib/Support/Lua.cpp | 30 +++-- src/lib/Support/Report.cpp | 38 +++---- src/lib/Support/Report.hpp | 42 +++---- src/test/lib/Dom/Dom.cpp | 5 +- src/test/lib/Support/Handlebars.cpp | 67 ++++++----- src/test_suite/detail/decomposer.hpp | 28 ++--- src/test_suite/diff.cpp | 63 +++-------- util/generate-config-info.py | 11 ++ vcpkg.json.example | 4 - 43 files changed, 503 insertions(+), 648 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c05cd7754..dd5b7bf31 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,7 +38,7 @@ jobs: clang >=18 msvc >=14.40 apple-clang * - standards: '20' + standards: '23' latest-factors: | msvc Optimized-Debug gcc Coverage @@ -287,26 +287,6 @@ jobs: run-tests: false trace-commands: true - - name: Install Fmt - uses: alandefreitas/cpp-actions/cmake-workflow@v1.8.10 - with: - source-dir: ../third-party/fmt - git-repository: https://github.com/fmtlib/fmt - git-tag: 10.2.1 - build-dir: ${sourceDir}/build - cc: ${{ steps.setup-cpp.outputs.cc }} - cxx: ${{ steps.setup-cpp.outputs.cxx }} - ccflags: ${{ matrix.ccflags }} - cxxflags: ${{ matrix.cxxflags }} - build-type: ${{ matrix.build-type }} - extra-args: | - -D FMT_DOC=OFF - -D FMT_TEST=OFF - install: true - install-prefix: ${sourceDir}/install - run-tests: false - trace-commands: true - - name: Install Libxml2 uses: alandefreitas/cpp-actions/cmake-workflow@v1.8.10 if: matrix.compiler == 'msvc' @@ -384,7 +364,6 @@ jobs: -D Clang_ROOT=../third-party/llvm-project/install -D duktape_ROOT=../third-party/duktape/install -D Duktape_ROOT=../third-party/duktape/install - -D fmt_ROOT=../third-party/fmt/install ${{ runner.os == 'Windows' && '-D libxml2_ROOT=../third-party/libxml2/install' || '' }} ${{ runner.os == 'Windows' && '-D LibXml2_ROOT=../third-party/libxml2/install' || '' }} export-compile-commands: true diff --git a/CMakeLists.txt b/CMakeLists.txt index 8cf953cd8..b6f1c987d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,9 +119,6 @@ llvm_map_components_to_libnames(llvm_libs all) string(REGEX REPLACE " /W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -# fmt -find_package(fmt REQUIRED CONFIG) - # Duktape find_package(Duktape CONFIG) if (NOT DUKTAPE_FOUND) @@ -214,7 +211,7 @@ list(APPEND LIB_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/src/lib/Lib/PublicSettings.cpp ) add_library(mrdocs-core ${LIB_SOURCES}) -target_compile_features(mrdocs-core PUBLIC cxx_std_20) +target_compile_features(mrdocs-core PUBLIC cxx_std_23) target_include_directories(mrdocs-core PUBLIC "$" @@ -234,7 +231,6 @@ target_compile_definitions( # Dependencies target_include_directories(mrdocs-core SYSTEM PUBLIC ${LLVM_INCLUDE_DIRS}) target_include_directories(mrdocs-core SYSTEM PUBLIC ${CLANG_INCLUDE_DIRS}) -target_link_libraries(mrdocs-core PUBLIC fmt::fmt) target_include_directories(mrdocs-core SYSTEM PRIVATE ${DUKTAPE_INCLUDE_DIRS}) target_link_libraries(mrdocs-core PRIVATE ${DUKTAPE_LIBRARY}) diff --git a/docs/modules/ROOT/pages/install.adoc b/docs/modules/ROOT/pages/install.adoc index 1b662d0a4..44a21dc1d 100644 --- a/docs/modules/ROOT/pages/install.adoc +++ b/docs/modules/ROOT/pages/install.adoc @@ -116,27 +116,6 @@ These instructions assume all dependencies are installed in the `third-party` di Feel free to install them anywhere you want and adjust the main MrDocs configuration command later. ==== -[#install-fmt] -=== Fmt - -MrDocs uses the `fmt` library for formatting strings. -From the `third-party` directory, you can clone the `fmt` repository and install it with the following commands: - -[source,bash] ----- -git clone https://github.com/fmtlib/fmt --branch 10.2.1 --depth 1 <.> -cd fmt -cmake -S . -B ./build -DCMAKE_BUILD_TYPE=Release -D FMT_DOC=OFF -D FMT_TEST=OFF <.> -cmake --build ./build --config Release <.> -cmake --install ./build --prefix ./install <.> -cd .. ----- - -<.> Shallow clones the fmt repository. -<.> Configure the fmt library with CMake, excluding the documentation and tests. -<.> Builds the fmt library in the `build` directory. -<.> Installs the fmt library in the `install` directory. - [IMPORTANT] ==== All instructions in this document assume you are using a CMake version above 3.26. @@ -376,7 +355,7 @@ cd ../.. The MrDocs repository also includes a `CMakePresets.json` file that contains the parameters to configure MrDocs with CMake. -To specify the installation directories, you can use the `LLVM_ROOT`, `DUKTAPE_ROOT`, `FMT_ROOT`, and `LIBXML2_ROOT` environment variables. +To specify the installation directories, you can use the `LLVM_ROOT`, `DUKTAPE_ROOT`, and `LIBXML2_ROOT` environment variables. To specify a generator (`-G`) and platform name (`-A`), you can use the `CMAKE_GENERATOR` and `CMAKE_GENERATOR_PLATFORM` environment variables. You can also customize the presets by duplicating and editing the `CMakeUserPresets.json.example` file in the `mrdocs` directory. diff --git a/include/mrdocs/Dom/Object.ipp b/include/mrdocs/Dom/Object.ipp index f3c332eca..4eef5b1b3 100644 --- a/include/mrdocs/Dom/Object.ipp +++ b/include/mrdocs/Dom/Object.ipp @@ -149,14 +149,15 @@ Object::visit(F&& fn) const //------------------------------------------------ template<> -struct fmt::formatter - : fmt::formatter +struct std::formatter + : std::formatter { + template auto format( clang::mrdocs::dom::Object const& value, - fmt::format_context& ctx) const + FmtContext& ctx) const { - return fmt::formatter::format( + return std::formatter::format( toString(value), ctx); } }; diff --git a/include/mrdocs/Dom/String.hpp b/include/mrdocs/Dom/String.hpp index ff690c8f5..fb6c5de71 100644 --- a/include/mrdocs/Dom/String.hpp +++ b/include/mrdocs/Dom/String.hpp @@ -11,9 +11,9 @@ #ifndef MRDOCS_API_DOM_STRING_HPP #define MRDOCS_API_DOM_STRING_HPP +#include #include #include -#include namespace clang { namespace mrdocs { @@ -341,17 +341,13 @@ class MRDOCS_DECL //------------------------------------------------ -template<> -struct fmt::formatter - : fmt::formatter -{ - auto format( - clang::mrdocs::dom::String const& value, - fmt::format_context& ctx) const - { - return fmt::formatter::format( - value.get(), ctx); - } +template <> +struct std::formatter + : std::formatter { + template + auto format(clang::mrdocs::dom::String const &value, FmtContext &ctx) const { + return std::formatter::format(value.get(), ctx); + } }; #endif diff --git a/include/mrdocs/Dom/Value.hpp b/include/mrdocs/Dom/Value.hpp index e05686c91..74f1a75fd 100644 --- a/include/mrdocs/Dom/Value.hpp +++ b/include/mrdocs/Dom/Value.hpp @@ -11,18 +11,19 @@ #ifndef MRDOCS_API_DOM_VALUE_HPP #define MRDOCS_API_DOM_VALUE_HPP -#include +#include +#include +#include +#include #include -#include #include +#include #include #include -#include +#include #include #include // BAD #include -#include -#include namespace clang { namespace mrdocs { @@ -849,17 +850,13 @@ safeString(SV const& str) { //------------------------------------------------ -template<> -struct fmt::formatter - : public fmt::formatter -{ - auto format( - clang::mrdocs::dom::Value const& value, - fmt::format_context& ctx) const - { - return fmt::formatter::format( - toString(value), ctx); - } +template <> +struct std::formatter + : public std::formatter { + template + auto format(clang::mrdocs::dom::Value const &value, FmtContext &ctx) const { + return std::formatter::format(toString(value), ctx); + } }; #endif diff --git a/include/mrdocs/Metadata/Javadoc.hpp b/include/mrdocs/Metadata/Javadoc.hpp index b00d249cb..0f8d57b83 100644 --- a/include/mrdocs/Metadata/Javadoc.hpp +++ b/include/mrdocs/Metadata/Javadoc.hpp @@ -13,15 +13,16 @@ #ifndef MRDOCS_API_METADATA_JAVADOC_HPP #define MRDOCS_API_METADATA_JAVADOC_HPP -#include -#include -#include -#include +#include +#include #include -#include -#include #include -#include +#include +#include +#include +#include +#include +#include #include #include #include diff --git a/include/mrdocs/Support/Error.hpp b/include/mrdocs/Support/Error.hpp index dbef752fd..dc24e5110 100644 --- a/include/mrdocs/Support/Error.hpp +++ b/include/mrdocs/Support/Error.hpp @@ -12,17 +12,18 @@ #ifndef MRDOCS_API_SUPPORT_ERROR_HPP #define MRDOCS_API_SUPPORT_ERROR_HPP -#include -#include -#include #include +#include +#include #include +#include +#include #include #include +#include #include #include #include -#include namespace clang::mrdocs { @@ -256,28 +257,20 @@ struct std::hash<::clang::mrdocs::Error> } }; -template<> -struct fmt::formatter - : fmt::formatter -{ - auto format( - clang::mrdocs::Error const& err, - fmt::format_context& ctx) const - { - return fmt::formatter::format(err.message(), ctx); - } +template <> +struct std::formatter : std::formatter { + template + auto format(clang::mrdocs::Error const &err, FmtContext &ctx) const { + return std::formatter::format(err.message(), ctx); + } }; -template<> -struct fmt::formatter - : fmt::formatter -{ - auto format( - std::error_code const& ec, - fmt::format_context& ctx) const - { - return fmt::formatter::format(ec.message(), ctx); - } +template <> +struct std::formatter : std::formatter { + template + auto format(std::error_code const &ec, FmtContext &ctx) const { + return std::formatter::format(ec.message(), ctx); + } }; namespace clang::mrdocs { @@ -353,9 +346,8 @@ formatError( Args&&... args) { std::string s; - fmt::vformat_to( - std::back_inserter(s), - fs.fs, fmt::make_format_args(args...)); + std::vformat_to(std::back_inserter(s), fs.fs, + std::make_format_args(args...)); return Error(std::move(s), fs.loc); } diff --git a/include/mrdocs/Support/Expected.hpp b/include/mrdocs/Support/Expected.hpp index 729d89268..f40f74919 100644 --- a/include/mrdocs/Support/Expected.hpp +++ b/include/mrdocs/Support/Expected.hpp @@ -12,19 +12,18 @@ #ifndef MRDOCS_API_SUPPORT_EXPECTED_HPP #define MRDOCS_API_SUPPORT_EXPECTED_HPP -#include -#include -#include -#include #include +#include #include #include +#include +#include +#include #include #include #include #include #include -#include namespace clang::mrdocs { diff --git a/include/mrdocs/Support/Handlebars.hpp b/include/mrdocs/Support/Handlebars.hpp index 1109f759a..784c9bd6a 100644 --- a/include/mrdocs/Support/Handlebars.hpp +++ b/include/mrdocs/Support/Handlebars.hpp @@ -11,14 +11,15 @@ #ifndef MRDOCS_TOOL_SUPPORT_PATH_HPP #define MRDOCS_TOOL_SUPPORT_PATH_HPP -#include +#include +#include #include +#include #include -#include -#include #include -#include +#include #include +#include namespace clang { namespace mrdocs { @@ -45,15 +46,10 @@ struct HandlebarsError HandlebarsError(std::string_view msg) : std::runtime_error(std::string(msg)) {} - HandlebarsError( - std::string_view msg, - std::size_t line_, - std::size_t column_, - std::size_t pos_) - : std::runtime_error(fmt::format("{} - {}:{}", msg, line_, column_)) - , line(line_) - , column(column_) - , pos(pos_) {} + HandlebarsError(std::string_view msg, std::size_t line_, + std::size_t column_, std::size_t pos_) + : std::runtime_error(std::format("{} - {}:{}", msg, line_, column_)), + line(line_), column(column_), pos(pos_) {} }; namespace detail { @@ -218,9 +214,9 @@ class MRDOCS_DECL OutputRef @return A reference to this object */ template - requires fmt::is_formattable::value + requires std::formattable friend OutputRef &operator<<(OutputRef &os, T v) { - std::string s = fmt::format("{}", v); + std::string s = std::format("{}", v); return os.write_impl(s); } diff --git a/include/mrdocs/Support/Lua.hpp b/include/mrdocs/Support/Lua.hpp index a4fb532b5..89bca4049 100644 --- a/include/mrdocs/Support/Lua.hpp +++ b/include/mrdocs/Support/Lua.hpp @@ -11,13 +11,12 @@ #ifndef MRDOCS_SUPPORT_LUA_HPP #define MRDOCS_SUPPORT_LUA_HPP -#include +#include +#include #include +#include #include #include -#include -#include -#include #include #include @@ -470,17 +469,12 @@ class Table : public Value //------------------------------------------------ -template<> -struct fmt::formatter - : fmt::formatter -{ - auto format( - clang::mrdocs::lua::Value const& value, - fmt::format_context& ctx) const - { - return fmt::formatter::format( - value.displayString(), ctx); - } +template <> +struct std::formatter : std::formatter { + template + auto format(clang::mrdocs::lua::Value const &value, FmtContext &ctx) const { + return std::formatter::format(value.displayString(), ctx); + } }; #endif diff --git a/include/mrdocs/Support/Report.hpp b/include/mrdocs/Support/Report.hpp index db893db16..050b1ae1f 100644 --- a/include/mrdocs/Support/Report.hpp +++ b/include/mrdocs/Support/Report.hpp @@ -12,19 +12,19 @@ #ifndef MRDOCS_API_SUPPORT_REPORT_HPP #define MRDOCS_API_SUPPORT_REPORT_HPP -#include -#include -#include -#include #include +#include +#include #include #include +#include +#include +#include #include #include #include #include #include -#include namespace clang::mrdocs::report { @@ -142,13 +142,9 @@ log_impl( Arg0&& arg0, Args&&... args) { - std::string str = fmt::vformat( - fs.value, - fmt::make_format_args(arg0, args...)); - return print( - level, - str, - &fs.where); + std::string str = + std::vformat(fs.value, std::make_format_args(arg0, args...)); + return print(level, str, &fs.where); } template @@ -163,9 +159,8 @@ log_impl( // the information relevant to the user from // the information relevant for bug tracking // so that users can understand the message. - std::string str = fmt::vformat( - fs.value, - fmt::make_format_args(e.reason(), args...)); + std::string str = + std::vformat(fs.value, std::make_format_args(e.reason(), args...)); return print( level, str, @@ -179,12 +174,8 @@ log_impl( Level level, Located fs) { - std::string str = fmt::vformat( - fs.value, fmt::make_format_args()); - return print( - level, - str, - &fs.where); + std::string str = std::vformat(fs.value, std::make_format_args()); + return print(level, str, &fs.where); } } diff --git a/src/lib/AST/ParseJavadoc.cpp b/src/lib/AST/ParseJavadoc.cpp index 1a9006ef1..a8cefb277 100644 --- a/src/lib/AST/ParseJavadoc.cpp +++ b/src/lib/AST/ParseJavadoc.cpp @@ -13,19 +13,20 @@ // #include "ParseJavadoc.hpp" +#include "lib/AST/ParseRef.hpp" +#include +#include +#include +#include +#include +#include +#include #include +#include #include #include -#include #include -#include -#include -#include -#include -#include -#include -#include "lib/AST/ParseRef.hpp" -#include +#include #ifdef _MSC_VER #pragma warning(push) @@ -466,14 +467,10 @@ class JavadocVisitor //------------------------------------------------ -std::string& -JavadocVisitor:: -ensureUTF8( - std::string&& s) -{ - if (!llvm::json::isUTF8(s)) - s = llvm::json::fixUTF8(s); - return s; +std::string &JavadocVisitor::ensureUTF8(std::string &&s) { + if (!llvm::json::isUTF8(s)) + s = llvm::json::fixUTF8(s); + return static_cast(s); } /* Parse the inline content of a text @@ -785,7 +782,9 @@ parseHTMLTag(HTMLStartTagComment const* C) *static_cast(*tagEndIt); if(cEndTag.getTagName() != res.tag) { - return Unexpected(Error(fmt::format("warning: HTML <{}> tag not followed by same end tag ( found)", res.tag, cEndTag.getTagName().str()))); + return Unexpected(Error(std::format( + "warning: HTML <{}> tag not followed by same end tag ( found)", + res.tag, cEndTag.getTagName().str()))); } // Check if all the siblings are text nodes @@ -795,7 +794,8 @@ parseHTMLTag(HTMLStartTagComment const* C) }); if (!areAllText) { - return Unexpected(Error(fmt::format("warning: HTML <{}> tag not followed by text", res.tag))); + return Unexpected(Error( + std::format("warning: HTML <{}> tag not followed by text", res.tag))); } // Extract text from all the siblings @@ -829,7 +829,9 @@ visitHTMLStartTagComment( }); if (attr_it == idxs.end()) { - return Unexpected(Error(fmt::format("warning: HTML <{}> tag has no {} attribute", C->getTagName().str(), name.str()))); + return Unexpected( + Error(std::format("warning: HTML <{}> tag has no {} attribute", + C->getTagName().str(), name.str()))); } return C->getAttr(*attr_it).Value.str(); }; @@ -870,7 +872,9 @@ visitHTMLStartTagComment( } else { - report::warn(fmt::format("warning: unsupported HTML tag <{}>", tagComponents.tag), filename, loc.getLine()); + report::warn( + std::format("warning: unsupported HTML tag <{}>", tagComponents.tag), + filename, loc.getLine()); } // Skip the children we consumed in parseHTMLTag it_ += tagComponents.n_siblings; @@ -1756,13 +1760,10 @@ goodArgCount(std::size_t n, { auto loc = sm_.getPresumedLoc(C.getBeginLoc()); - diags_.error(fmt::format( - "Expected {} but got {} args\n" - "File: {}, line {}, col {}\n", - n, C.getNumArgs(), - loc.getFilename(), - loc.getLine(), - loc.getColumn())); + diags_.error(std::format("Expected {} but got {} args\n" + "File: {}, line {}, col {}\n", + n, C.getNumArgs(), loc.getFilename(), + loc.getLine(), loc.getColumn())); return false; } diff --git a/src/lib/AST/ParseRef.cpp b/src/lib/AST/ParseRef.cpp index 6209f011c..626ee8594 100644 --- a/src/lib/AST/ParseRef.cpp +++ b/src/lib/AST/ParseRef.cpp @@ -16,6 +16,8 @@ #include #include +#include + namespace clang::mrdocs { namespace { @@ -991,17 +993,19 @@ class RefParser // Check if the type is named if (!dest->isNamed()) { - setError(fmt::format("expected named type for '{}' specifier", signStr)); - ptr_ = start; - return false; + setError(std::format("expected named type for '{}' specifier", + signStr)); + ptr_ = start; + return false; } // Check if the type is "int" or "char" auto& namedParam = dynamic_cast(*dest); if (!namedParam.FundamentalType) { - setError(fmt::format("expected fundamental type for '{}' specifier", signStr)); - ptr_ = start; - return false; + setError(std::format( + "expected fundamental type for '{}' specifier", signStr)); + ptr_ = start; + return false; } bool promoted = explicitlySigned ? @@ -1009,9 +1013,10 @@ class RefParser makeUnsigned(*namedParam.FundamentalType); if (!promoted) { - setError(fmt::format("expected 'int' or 'char' for '{}' specifier", signStr)); - ptr_ = start; - return false; + setError(std::format( + "expected 'int' or 'char' for '{}' specifier", signStr)); + ptr_ = start; + return false; } // Add the specifier to the type name namedParam.Name->Name = toString(*namedParam.FundamentalType); diff --git a/src/lib/Dom/Object.cpp b/src/lib/Dom/Object.cpp index a3b046e10..fcdab886a 100644 --- a/src/lib/Dom/Object.cpp +++ b/src/lib/Dom/Object.cpp @@ -8,10 +8,10 @@ // Official repository: https://github.com/cppalliance/mrdocs // +#include +#include #include #include -#include -#include #include namespace clang { @@ -90,8 +90,7 @@ operator==(Object const& a, Object const& b) noexcept std::string toString(Object const& obj) { - return fmt::format( - "[object {}]", obj.type_key()); + return std::format("[object {}]", obj.type_key()); } //------------------------------------------------ diff --git a/src/lib/Dom/String.cpp b/src/lib/Dom/String.cpp index 572606579..6e1b5d147 100644 --- a/src/lib/Dom/String.cpp +++ b/src/lib/Dom/String.cpp @@ -8,8 +8,9 @@ // Official repository: https://github.com/cppalliance/mrdocs // -#include #include +#include +#include namespace clang { namespace mrdocs { diff --git a/src/lib/Gen/hbs/Builder.cpp b/src/lib/Gen/hbs/Builder.cpp index c6f1eddeb..e9fcf30a0 100644 --- a/src/lib/Gen/hbs/Builder.cpp +++ b/src/lib/Gen/hbs/Builder.cpp @@ -10,13 +10,13 @@ // #include "Builder.hpp" +#include +#include #include +#include #include #include #include -#include -#include -#include namespace clang { namespace mrdocs { @@ -246,8 +246,10 @@ Builder( hbs_.registerHelper("relativize", dom::makeInvocable(relativize_fn)); // Load layout templates - std::string indexTemplateFilename = fmt::format("index.{}.hbs", domCorpus.fileExtension); - std::string wrapperTemplateFilename = fmt::format("wrapper.{}.hbs", domCorpus.fileExtension); + std::string indexTemplateFilename = + std::format("index.{}.hbs", domCorpus.fileExtension); + std::string wrapperTemplateFilename = + std::format("wrapper.{}.hbs", domCorpus.fileExtension); for (std::string const& filename : {indexTemplateFilename, wrapperTemplateFilename}) { std::string pathName = files::appendPath(layoutDir(), filename); @@ -319,22 +321,22 @@ Expected Builder:: operator()(std::ostream& os, T const& I) { - std::string const templateFile = fmt::format("index.{}.hbs", domCorpus.fileExtension); - dom::Object const ctx = createContext(I); + std::string const templateFile = + std::format("index.{}.hbs", domCorpus.fileExtension); + dom::Object const ctx = createContext(I); - if (auto& config = domCorpus->config; - config->embedded || - !config->multipage) - { - // Single page or embedded pages render the index template directly - // without the wrapper - return callTemplate(os, templateFile, ctx); - } + if (auto &config = domCorpus->config; + config->embedded || !config->multipage) { + // Single page or embedded pages render the index template directly + // without the wrapper + return callTemplate(os, templateFile, ctx); + } // Multipage output: render the wrapper template // The context receives the original symbol and the contents from rendering // the index template - auto const wrapperFile = fmt::format("wrapper.{}.hbs", domCorpus.fileExtension); + auto const wrapperFile = + std::format("wrapper.{}.hbs", domCorpus.fileExtension); dom::Object const wrapperCtx = createFrame(ctx); wrapperCtx.set("contents", dom::makeInvocable([this, &I, templateFile, &os]( dom::Value const&) -> Expected @@ -356,29 +358,26 @@ renderWrapped( std::ostream& os, std::function()> contentsCb) { - auto const wrapperFile = fmt::format( - "wrapper.{}.hbs", domCorpus.fileExtension); - dom::Object ctx; - ctx.set("contents", dom::makeInvocable([&]( - dom::Value const&) -> Expected - { - MRDOCS_TRY(contentsCb()); - return {}; - })); - - // Render the wrapper directly to ostream - auto pathName = files::appendPath(layoutDir(), wrapperFile); - MRDOCS_TRY(auto fileText, files::getFileText(pathName)); - HandlebarsOptions options; - options.escapeFunction = escapeFn_; - OutputRef outRef(os); - Expected exp = - hbs_.try_render_to( - outRef, fileText, ctx, options); - if (!exp) - { - Error(exp.error().what()).Throw(); - } + auto const wrapperFile = + std::format("wrapper.{}.hbs", domCorpus.fileExtension); + dom::Object ctx; + ctx.set("contents", + dom::makeInvocable([&](dom::Value const &) -> Expected { + MRDOCS_TRY(contentsCb()); + return {}; + })); + + // Render the wrapper directly to ostream + auto pathName = files::appendPath(layoutDir(), wrapperFile); + MRDOCS_TRY(auto fileText, files::getFileText(pathName)); + HandlebarsOptions options; + options.escapeFunction = escapeFn_; + OutputRef outRef(os); + Expected exp = + hbs_.try_render_to(outRef, fileText, ctx, options); + if (!exp) { + Error(exp.error().what()).Throw(); + } return {}; } diff --git a/src/lib/Gen/hbs/HandlebarsCorpus.cpp b/src/lib/Gen/hbs/HandlebarsCorpus.cpp index d83722b0f..5e4314025 100644 --- a/src/lib/Gen/hbs/HandlebarsCorpus.cpp +++ b/src/lib/Gen/hbs/HandlebarsCorpus.cpp @@ -12,11 +12,9 @@ #include "HandlebarsCorpus.hpp" #include "VisitorHelpers.hpp" -#include #include -#include -#include #include +#include #include #include diff --git a/src/lib/Lib/Diagnostics.hpp b/src/lib/Lib/Diagnostics.hpp index 18e8434c5..c3f6c0141 100644 --- a/src/lib/Lib/Diagnostics.hpp +++ b/src/lib/Lib/Diagnostics.hpp @@ -11,8 +11,9 @@ #ifndef MRDOCS_LIB_TOOL_DIAGNOSTICS_HPP #define MRDOCS_LIB_TOOL_DIAGNOSTICS_HPP -#include +#include #include +#include #include #include @@ -86,23 +87,19 @@ class Diagnostics auto const warnCount = messages_.size() - errorCount_; if (errorCount_ > 0) { - fmt::format_to( - std::back_inserter(s), - "{} error{}", errorCount_, - errorCount_ > 1 ? "s" : ""); + std::format_to(std::back_inserter(s), "{} error{}", errorCount_, + errorCount_ > 1 ? "s" : ""); } if (warnCount > 0) { if(errorCount_ > 0) { - fmt::format_to(std::back_inserter(s), " and " ); + std::format_to(std::back_inserter(s), " and "); } - fmt::format_to( - std::back_inserter(s), - "{} warning{}.\n", warnCount, - warnCount > 1 ? "s" : ""); + std::format_to(std::back_inserter(s), "{} warning{}.\n", warnCount, + warnCount > 1 ? "s" : ""); } - fmt::format_to(std::back_inserter(s), " total."); + std::format_to(std::back_inserter(s), " total."); report::print(level, s); } diff --git a/src/lib/Lib/MrDocsCompilationDatabase.cpp b/src/lib/Lib/MrDocsCompilationDatabase.cpp index 9f8df357d..42e9b6623 100644 --- a/src/lib/Lib/MrDocsCompilationDatabase.cpp +++ b/src/lib/Lib/MrDocsCompilationDatabase.cpp @@ -9,22 +9,22 @@ // Official repository: https://github.com/cppalliance/mrdocs // -#include "lib/Support/Debug.hpp" -#include "lib/Support/Path.hpp" +#include "lib/Lib/MrDocsCompilationDatabase.hpp" #include "lib/Lib/ConfigImpl.hpp" #include "lib/Lib/ExecuteAndWaitWithLogging.hpp" -#include "lib/Lib/MrDocsCompilationDatabase.hpp" -#include -#include +#include "lib/Support/Debug.hpp" +#include "lib/Support/Path.hpp" #include #include #include #include +#include #include #include #include #include #include +#include #include namespace clang { @@ -413,7 +413,7 @@ adjustCommandLine( // These are additional defines specified in the config file for(auto const& def : (*config)->defines) { - new_cmdline.emplace_back(fmt::format("-D{}", def)); + new_cmdline.emplace_back(std::format("-D{}", def)); } new_cmdline.emplace_back("-D__MRDOCS__"); @@ -430,7 +430,7 @@ adjustCommandLine( it != implicitIncludeDirectories.end()) { for (auto const& inc : it->second) { - new_cmdline.emplace_back(fmt::format("-isystem{}", inc)); + new_cmdline.emplace_back(std::format("-isystem{}", inc)); } } } @@ -449,7 +449,7 @@ adjustCommandLine( new_cmdline.emplace_back("-nostdlib++"); for (auto const& inc : (*config)->stdlibIncludes) { - new_cmdline.emplace_back(fmt::format("-isystem{}", inc)); + new_cmdline.emplace_back(std::format("-isystem{}", inc)); } } @@ -458,7 +458,7 @@ adjustCommandLine( new_cmdline.emplace_back("-nostdinc"); for (auto const& inc : (*config)->libcIncludes) { - new_cmdline.emplace_back(fmt::format("-isystem{}", inc)); + new_cmdline.emplace_back(std::format("-isystem{}", inc)); } } @@ -467,11 +467,11 @@ adjustCommandLine( // ------------------------------------------------------ for (auto const& inc : (*config)->systemIncludes) { - new_cmdline.emplace_back(fmt::format("-isystem{}", inc)); + new_cmdline.emplace_back(std::format("-isystem{}", inc)); } for (auto const& inc : (*config)->includes) { - new_cmdline.emplace_back(fmt::format("-I{}", inc)); + new_cmdline.emplace_back(std::format("-I{}", inc)); } // ------------------------------------------------------ @@ -564,7 +564,7 @@ MrDocsCompilationDatabase( } else { - report::info(fmt::format("Skipping non-C++ file: {}", cmd.Filename)); + report::info(std::format("Skipping non-C++ file: {}", cmd.Filename)); } } } diff --git a/src/lib/Metadata/Finalizers/BaseMembersFinalizer.cpp b/src/lib/Metadata/Finalizers/BaseMembersFinalizer.cpp index 0a59c2f23..a5db8b1f8 100644 --- a/src/lib/Metadata/Finalizers/BaseMembersFinalizer.cpp +++ b/src/lib/Metadata/Finalizers/BaseMembersFinalizer.cpp @@ -9,8 +9,9 @@ // #include "BaseMembersFinalizer.hpp" -#include +#include #include +#include namespace clang::mrdocs { @@ -160,10 +161,8 @@ inheritBaseMembers( }); otherCopy->Parent = derivedId; otherCopy->id = SymbolID::createFromString( - fmt::format( - "{}-{}", - toBase16Str(otherCopy->Parent), - toBase16Str(otherInfo.id))); + std::format("{}-{}", toBase16Str(otherCopy->Parent), + toBase16Str(otherInfo.id))); derived.push_back(otherCopy->id); // Get the extraction mode from the derived class if (otherCopy->Extraction == ExtractionMode::Dependency) diff --git a/src/lib/Metadata/Finalizers/Javadoc/Function.hpp b/src/lib/Metadata/Finalizers/Javadoc/Function.hpp index d4d1484b9..74fcefe09 100644 --- a/src/lib/Metadata/Finalizers/Javadoc/Function.hpp +++ b/src/lib/Metadata/Finalizers/Javadoc/Function.hpp @@ -13,6 +13,7 @@ #include "lib/Lib/CorpusImpl.hpp" #include "lib/Lib/InfoSet.hpp" +#include #include #include @@ -101,9 +102,9 @@ std::optional innermostTypenameString(Polymorphic const& T) { auto& R = innermostType(T); - MRDOCS_CHECK_OR(R->isNamed(), nullptr); - MRDOCS_CHECK_OR(get(R).Name, nullptr); - MRDOCS_CHECK_OR(!get(R).Name->Name.empty(), nullptr); + MRDOCS_CHECK_OR(R->isNamed(), {}); + MRDOCS_CHECK_OR(get(R).Name, {}); + MRDOCS_CHECK_OR(!get(R).Name->Name.empty(), {}); auto& RStr = get(R).Name->Name; return RStr; } @@ -652,8 +653,8 @@ setCntrOrAssignParamDoc( } return !isAssign ? "construct" : "assign"; }(); - I.javadoc->params.emplace_back(*param.Name, fmt::format( - "The {} to {} from", paramNoun, functionVerb)); + I.javadoc->params.emplace_back( + *param.Name, std::format("The {} to {} from", paramNoun, functionVerb)); return true; } @@ -671,8 +672,8 @@ setBinaryOpParamDoc( // Set the parameter description if we can std::string_view const paramAdj = indexFree == 0 ? "left" : "right"; - I.javadoc->params.emplace_back(*param.Name, fmt::format( - "The {} operand", paramAdj)); + I.javadoc->params.emplace_back(*param.Name, + std::format("The {} operand", paramAdj)); return true; } diff --git a/src/lib/Metadata/Finalizers/JavadocFinalizer.cpp b/src/lib/Metadata/Finalizers/JavadocFinalizer.cpp index dec812355..c55492cf6 100644 --- a/src/lib/Metadata/Finalizers/JavadocFinalizer.cpp +++ b/src/lib/Metadata/Finalizers/JavadocFinalizer.cpp @@ -10,11 +10,12 @@ // #include "JavadocFinalizer.hpp" -#include "Javadoc/Overloads.hpp" #include "Javadoc/Function.hpp" -#include -#include +#include "Javadoc/Overloads.hpp" #include +#include +#include +#include namespace clang::mrdocs { @@ -1650,15 +1651,12 @@ emitWarnings() auto const level = !corpus_.config->warnAsError ? report::Level::warn : report::Level::error; for (auto const& [loc, msgs] : warnings_) { - std::string locWarning = fmt::format( - "{}:{}\n", - loc.FullPath, - loc.LineNumber); - int i = 1; - for (auto const& msg : msgs) - { - locWarning += fmt::format(" {}) {}\n", i++, msg); - } + std::string locWarning = + std::format("{}:{}\n", loc.FullPath, loc.LineNumber); + int i = 1; + for (auto const &msg : msgs) { + locWarning += std::format(" {}) {}\n", i++, msg); + } report::log(level, locWarning); } } diff --git a/src/lib/Metadata/Finalizers/JavadocFinalizer.hpp b/src/lib/Metadata/Finalizers/JavadocFinalizer.hpp index d45665a76..899b9b83d 100644 --- a/src/lib/Metadata/Finalizers/JavadocFinalizer.hpp +++ b/src/lib/Metadata/Finalizers/JavadocFinalizer.hpp @@ -14,8 +14,9 @@ #include "lib/Lib/CorpusImpl.hpp" #include "lib/Lib/InfoSet.hpp" -#include +#include #include +#include #include #include @@ -386,7 +387,8 @@ class JavadocFinalizer Args&&... args) { MRDOCS_CHECK_OR(corpus_.config->warnings); - std::string const str = fmt::vformat(format.value, fmt::make_format_args(args...)); + std::string const str = + std::vformat(format.value, std::make_format_args(args...)); warnings_[loc].push_back(str); } diff --git a/src/lib/Metadata/Info/Overloads.cpp b/src/lib/Metadata/Info/Overloads.cpp index 0fb1e3e4c..d105619af 100644 --- a/src/lib/Metadata/Info/Overloads.cpp +++ b/src/lib/Metadata/Info/Overloads.cpp @@ -9,10 +9,11 @@ // #include "lib/Support/Radix.hpp" -#include +#include #include #include #include +#include #include #include #include @@ -20,13 +21,11 @@ namespace clang::mrdocs { -OverloadsInfo:: -OverloadsInfo(SymbolID const& Parent, std::string_view Name, AccessKind access, bool isStatic) noexcept - : InfoCommonBase( - SymbolID::createFromString( - fmt::format("{}-{}-{}-{}", toBase16(Parent), Name, toString(access), isStatic))) -{ - this->Parent = Parent; +OverloadsInfo::OverloadsInfo(SymbolID const &Parent, std::string_view Name, + AccessKind access, bool isStatic) noexcept + : InfoCommonBase(SymbolID::createFromString(std::format( + "{}-{}-{}-{}", toBase16(Parent), Name, toString(access), isStatic))) { + this->Parent = Parent; } void diff --git a/src/lib/Metadata/Javadoc.cpp b/src/lib/Metadata/Javadoc.cpp index cffec9c77..188d11acc 100644 --- a/src/lib/Metadata/Javadoc.cpp +++ b/src/lib/Metadata/Javadoc.cpp @@ -11,12 +11,12 @@ // #include "lib/Support/Debug.hpp" -#include -#include -#include +#include #include #include -#include +#include +#include +#include namespace clang { namespace mrdocs { @@ -269,9 +269,8 @@ emplace_back( auto u = dynamic_cast(q.operator->()); if(u->name == t->name) { - result = fmt::format( - "duplicate param {}", t->name); - break; + result = std::format("duplicate param {}", t->name); + break; } } } @@ -288,9 +287,8 @@ emplace_back( auto u = dynamic_cast(q.operator->()); if(u->name == t->name) { - result = fmt::format( - "duplicate tparam {}", t->name); - break; + result = std::format("duplicate tparam {}", t->name); + break; } } } diff --git a/src/lib/Metadata/Specifiers.cpp b/src/lib/Metadata/Specifiers.cpp index 75cefcee3..38b7b97f6 100644 --- a/src/lib/Metadata/Specifiers.cpp +++ b/src/lib/Metadata/Specifiers.cpp @@ -9,6 +9,7 @@ // #include "mrdocs/Support/Algorithm.hpp" +#include #include namespace clang { @@ -94,7 +95,7 @@ toString( if(info.Kind == NoexceptKind::True && (resolved || info.Operand.empty())) return "noexcept"; - return fmt::format("noexcept({})", info.Operand); + return std::format("noexcept({})", info.Operand); } dom::String @@ -114,7 +115,7 @@ toString( if(info.Kind == ExplicitKind::True && (resolved || info.Operand.empty())) return "explicit"; - return fmt::format("explicit({})", info.Operand); + return std::format("explicit({})", info.Operand); } dom::String toString(ReferenceKind kind) noexcept diff --git a/src/lib/Support/Assert.cpp b/src/lib/Support/Assert.cpp index c8eb8698b..d54ba7bac 100644 --- a/src/lib/Support/Assert.cpp +++ b/src/lib/Support/Assert.cpp @@ -8,10 +8,10 @@ // Official repository: https://github.com/cppalliance/mrdocs // +#include +#include #include #include -#include -#include namespace SourceFileNames { extern char const* getFileName(char const*) noexcept; @@ -26,9 +26,8 @@ assert_failed( char const* file, std::uint_least32_t line) { - llvm::errs() << fmt::format( - "assertion failed: {} on line {} in {}\n", - msg, line, ::SourceFileNames::getFileName(file)); + llvm::errs() << std::format("assertion failed: {} on line {} in {}\n", msg, + line, ::SourceFileNames::getFileName(file)); } } // mrdocs diff --git a/src/lib/Support/Chrono.hpp b/src/lib/Support/Chrono.hpp index 2b2f432f1..f98ccad67 100644 --- a/src/lib/Support/Chrono.hpp +++ b/src/lib/Support/Chrono.hpp @@ -14,8 +14,8 @@ #define MRDOCS_LIB_SUPPORT_CHRONO_HPP #include +#include #include -#include namespace clang { namespace mrdocs { @@ -37,14 +37,14 @@ format_duration( auto delta_ms = std::chrono::duration_cast(delta); if (delta < std::chrono::seconds(1)) { - return fmt::format("{}ms", delta_ms.count()); + return std::format("{}ms", delta_ms.count()); } auto delta_s = std::chrono::duration_cast(delta); if (delta < std::chrono::minutes(1)) { delta_ms -= delta_s; - return fmt::format("{}s {}ms", delta_s.count(), delta_ms.count()); + return std::format("{}s {}ms", delta_s.count(), delta_ms.count()); } auto delta_min = std::chrono::duration_cast(delta); @@ -52,14 +52,16 @@ format_duration( { delta_ms -= delta_s; delta_s -= delta_min; - return fmt::format("{}min {}s {}ms", delta_min.count(), delta_s.count(), delta_ms.count()); + return std::format("{}min {}s {}ms", delta_min.count(), delta_s.count(), + delta_ms.count()); } auto delta_h = std::chrono::duration_cast(delta); delta_ms -= delta_s; delta_s -= delta_min; delta_min -= delta_h; - return fmt::format("{}h {}min {}s {}ms", delta_h.count(), delta_min.count(), delta_s.count(), delta_ms.count()); + return std::format("{}h {}min {}s {}ms", delta_h.count(), delta_min.count(), + delta_s.count(), delta_ms.count()); } } // mrdocs diff --git a/src/lib/Support/Debug.cpp b/src/lib/Support/Debug.cpp index 0cf249943..f3218166d 100644 --- a/src/lib/Support/Debug.cpp +++ b/src/lib/Support/Debug.cpp @@ -11,9 +11,10 @@ #include "lib/Support/Debug.hpp" #include "lib/Support/Radix.hpp" +#include #include -#include #include +#include #include namespace clang { @@ -33,62 +34,24 @@ debugEnableHeapChecking() } // mrdocs } // clang -fmt::format_context::iterator -fmt::formatter:: -format( - clang::mrdocs::SymbolID const& s, - fmt::format_context& ctx) const -{ - std::string str = s ? - "" : - clang::mrdocs::toBase64(s); - return fmt::formatter::format(std::move(str), ctx); -} - -fmt::format_context::iterator -fmt::formatter:: -format( - clang::mrdocs::InfoKind t, - fmt::format_context& ctx) const -{ - return fmt::formatter::format(toString(t).str(), ctx); -} - -fmt::format_context::iterator -fmt::formatter:: -format( - clang::mrdocs::AccessKind a, - fmt::format_context& ctx) const -{ - return fmt::formatter::format(toString(a).str(), ctx); -} - -fmt::format_context::iterator -fmt::formatter:: -format( - clang::mrdocs::Info const& i, - fmt::format_context& ctx) const -{ - std::string str = fmt::format("Info: kind = {}", i.Kind); - if (!i.Name.empty()) - { - str += fmt::format(", name = '{}'", i.Name); - } - str += fmt::format(", ID = {}", i.id); - clang::mrdocs::SymbolID curParent = i.Parent; - std::string namespaces; - while (curParent) - { - namespaces += fmt::format("{}", curParent); - curParent = i.Parent; - if (curParent) - { - namespaces += "::"; - } - } - if (!namespaces.empty()) - { - str += fmt::format(", namespace = {}", namespaces); +std::string +std::formatter::toString(clang::mrdocs::Info const &i) { + std::string str = std::format("Info: kind = {}", i.Kind); + if (!i.Name.empty()) { + str += std::format(", name = '{}'", i.Name); + } + str += std::format(", ID = {}", i.id); + clang::mrdocs::SymbolID curParent = i.Parent; + std::string namespaces; + while (curParent) { + namespaces += std::format("{}", curParent); + curParent = i.Parent; + if (curParent) { + namespaces += "::"; } - return fmt::formatter::format(std::move(str), ctx); + } + if (!namespaces.empty()) { + str += std::format(", namespace = {}", namespaces); + } + return str; } diff --git a/src/lib/Support/Debug.hpp b/src/lib/Support/Debug.hpp index 67048759f..c3d893b59 100644 --- a/src/lib/Support/Debug.hpp +++ b/src/lib/Support/Debug.hpp @@ -16,51 +16,51 @@ #if ! defined(NDEBUG) #include #endif +#include "lib/Support/Radix.hpp" +#include #include +#include #include -#include #include -namespace clang::mrdocs { - enum class InfoKind; - enum class AccessKind; - struct Info; -} - -template<> -struct fmt::formatter - : fmt::formatter -{ - fmt::format_context::iterator format( - clang::mrdocs::SymbolID const& s, - fmt::format_context& ctx) const; +template <> +struct std::formatter : std::formatter { + template + std::format_context::iterator format(clang::mrdocs::SymbolID const &s, + FmtContext &ctx) const { + std::string str = s ? "" : clang::mrdocs::toBase64(s); + return std::formatter::format(std::move(str), ctx); + } }; -template<> -struct fmt::formatter - : fmt::formatter -{ - fmt::format_context::iterator format( - clang::mrdocs::InfoKind t, - fmt::format_context& ctx) const; +template <> +struct std::formatter : std::formatter { + template + std::format_context::iterator format(clang::mrdocs::InfoKind t, + FmtContext &ctx) const { + return std::formatter::format(toString(t).str(), ctx); + } }; -template<> -struct fmt::formatter - : fmt::formatter -{ - fmt::format_context::iterator format( - clang::mrdocs::AccessKind a, - fmt::format_context& ctx) const; +template <> +struct std::formatter : std::formatter { + template + std::format_context::iterator format(clang::mrdocs::AccessKind a, + FmtContext &ctx) const { + return std::formatter::format(toString(a).str(), ctx); + } }; -template<> -struct fmt::formatter - : fmt::formatter -{ - fmt::format_context::iterator format( - clang::mrdocs::Info const& i, - fmt::format_context& ctx) const; +template <> +struct std::formatter : std::formatter { + template + std::format_context::iterator format(clang::mrdocs::Info const &i, + FmtContext &ctx) const { + return std::formatter::format(toString(i), ctx); + } + +private: + static std::string toString(clang::mrdocs::Info const &i); }; // Some nice odds and ends such as leak checking diff --git a/src/lib/Support/Handlebars.cpp b/src/lib/Support/Handlebars.cpp index 43db33169..eb17a63be 100644 --- a/src/lib/Support/Handlebars.cpp +++ b/src/lib/Support/Handlebars.cpp @@ -8,15 +8,16 @@ // Official repository: https://github.com/cppalliance/mrdocs // +#include +#include +#include +#include +#include +#include #include #include -#include +#include #include -#include -#include -#include -#include -#include #include #include @@ -809,13 +810,13 @@ lookupPropertyImpl( { if (opt.strict || (opt.assumeObjects && !path.empty())) { - std::string msg = fmt::format( - "\"{}\" not defined in {}", literalSegment, toString(context)); - auto res = find_position_in_text(state.rootTemplateText, literalSegment); - if (res) - { - throw HandlebarsError(msg, res.line, res.column, res.pos); - } + std::string msg = std::format("\"{}\" not defined in {}", + literalSegment, toString(context)); + auto res = + find_position_in_text(state.rootTemplateText, literalSegment); + if (res) { + throw HandlebarsError(msg, res.line, res.column, res.pos); + } throw HandlebarsError(msg); } else @@ -848,13 +849,13 @@ lookupPropertyImpl( { if (opt.strict) { - std::string msg = fmt::format( - "\"{}\" not defined in {}", literalSegment, toString(cur)); - auto res = find_position_in_text(state.rootTemplateText, literalSegment); - if (res) - { - throw HandlebarsError(msg, res.line, res.column, res.pos); - } + std::string msg = std::format("\"{}\" not defined in {}", + literalSegment, toString(cur)); + auto res = find_position_in_text(state.rootTemplateText, + literalSegment); + if (res) { + throw HandlebarsError(msg, res.line, res.column, res.pos); + } throw HandlebarsError(msg); } else @@ -923,12 +924,13 @@ lookupPropertyImpl( if (context.kind() != dom::Kind::Object) { if (opt.strict || opt.assumeObjects) { - std::string msg = fmt::format("\"{}\" not defined in {}", path, context); - auto res = find_position_in_text(state.rootTemplateText, path); - if (res) - { - return Unexpected(HandlebarsError(msg, res.line, res.column, res.pos)); - } + std::string msg = + std::format("\"{}\" not defined in {}", path, context); + auto res = find_position_in_text(state.rootTemplateText, path); + if (res) { + return Unexpected( + HandlebarsError(msg, res.line, res.column, res.pos)); + } return Unexpected(HandlebarsError(msg)); } return Res{nullptr, false}; @@ -1009,7 +1011,7 @@ struct defaultLogger { format_to(os, args.at(i), opt); os << " "; } - fmt::println("{}", out); + std::println("{}", out); } dom::Value @@ -2077,8 +2079,8 @@ evalExpr( if (opt.strict) { - std::string msg = fmt::format("\"{}\" not defined", expression); - return Unexpected(HandlebarsError(msg)); + std::string msg = std::format("\"{}\" not defined", expression); + return Unexpected(HandlebarsError(msg)); } return Res{dom::Kind::Undefined, false, false}; } @@ -2496,8 +2498,9 @@ renderExpression( } else if (opt.strict) { - std::string msg = fmt::format("\"{}\" not defined in {}", helper_expr, toString(context)); - return Unexpected(HandlebarsError(msg)); + std::string msg = std::format("\"{}\" not defined in {}", helper_expr, + toString(context)); + return Unexpected(HandlebarsError(msg)); } // ============================================================== @@ -2600,13 +2603,13 @@ setupArgs( expression = expression.substr(exprEndPos); if (!expression.empty() && expression.front() != ' ') { - std::string msg = fmt::format( - "Parse error. Invalid helper expression. {}{}", expr, expression); - auto res = find_position_in_text(expression, state.rootTemplateText); - if (res) - { - return Unexpected(HandlebarsError(msg, res.line, res.column, res.pos)); - } + std::string msg = std::format( + "Parse error. Invalid helper expression. {}{}", expr, expression); + auto res = find_position_in_text(expression, state.rootTemplateText); + if (res) { + return Unexpected( + HandlebarsError(msg, res.line, res.column, res.pos)); + } return Unexpected(HandlebarsError(msg)); } expression = trim_ldelimiters(expression, " "); @@ -2699,8 +2702,9 @@ renderDecorator( // ============================================================== if (tag.helper != "inline") { - out << fmt::format(R"([undefined decorator "{}" in "{}"])", tag.helper, tag.buffer); - return {}; + out << std::format(R"([undefined decorator "{}" in "{}"])", tag.helper, + tag.buffer); + return {}; } // ============================================================== @@ -2711,8 +2715,9 @@ renderDecorator( MRDOCS_TRY(auto res, evalExpr(context, expr, state, opt, true)); if (!res.value.isString()) { - out << fmt::format(R"([invalid decorator expression "{}" in "{}"])", tag.arguments, tag.buffer); - return {}; + out << std::format(R"([invalid decorator expression "{}" in "{}"])", + tag.arguments, tag.buffer); + return {}; } std::string_view partial_name = res.value.getString(); @@ -2796,8 +2801,8 @@ renderPartial( } else { - return Unexpected(HandlebarsError(fmt::format( - "The partial {} could not be found", partialName))); + return Unexpected(HandlebarsError( + std::format("The partial {} could not be found", partialName))); } } @@ -2876,7 +2881,7 @@ renderPartial( } ++n; } - std::string msg = fmt::format( + std::string msg = std::format( "Unsupported number of partial arguments: {}", n); auto res = find_position_in_text(state.rootTemplateText, tag.buffer); if (res) @@ -3081,8 +3086,8 @@ renderBlock( // ============================================ // Strict mode: throw when helper is not found // ============================================ - std::string msg = fmt::format( - "\"{}\" not defined in {}", tag.helper, toString(context)); + std::string msg = std::format("\"{}\" not defined in {}", tag.helper, + toString(context)); auto res = find_position_in_text(state.rootTemplateText, tag.helper); if (res) { @@ -3738,9 +3743,8 @@ helper_missing_fn(dom::Array const& arguments) return {}; } - return Unexpected(Error(fmt::format( - R"(Missing helper: "{}")", - arguments.back().get("name")))); + return Unexpected(Error( + std::format(R"(Missing helper: "{}")", arguments.back().get("name")))); } Expected diff --git a/src/lib/Support/JavaScript.cpp b/src/lib/Support/JavaScript.cpp index abbf3165d..e7fc49a4f 100644 --- a/src/lib/Support/JavaScript.cpp +++ b/src/lib/Support/JavaScript.cpp @@ -10,13 +10,14 @@ // #include "lib/Support/Report.hpp" +#include +#include +#include #include -#include #include -#include +#include #include #include -#include namespace clang { namespace mrdocs { @@ -1904,8 +1905,8 @@ registerHelper( MRDOCS_TRY(Value JSFn, s.compile_function(script)); if (!JSFn.isFunction()) { - return Unexpected(Error(fmt::format( - "helper \"{}\" is not a function", name))); + return Unexpected( + Error(std::format("helper \"{}\" is not a function", name))); } helpers.set(name, JSFn); } diff --git a/src/lib/Support/LegibleNames.cpp b/src/lib/Support/LegibleNames.cpp index 8b10d3192..bbe83b7db 100644 --- a/src/lib/Support/LegibleNames.cpp +++ b/src/lib/Support/LegibleNames.cpp @@ -10,18 +10,17 @@ // Official repository: https://github.com/cppalliance/mrdocs // -#include "lib/Support/Radix.hpp" #include "lib/Support/LegibleNames.hpp" -#include "lib/Support/Validate.hpp" #include "lib/Support/Debug.hpp" +#include "lib/Support/Radix.hpp" +#include "lib/Support/Validate.hpp" +#include +#include #include #include -#include #include +#include #include -#include -#include -#include #include #include #include diff --git a/src/lib/Support/Lua.cpp b/src/lib/Support/Lua.cpp index eee6bde0c..9499f070a 100644 --- a/src/lib/Support/Lua.cpp +++ b/src/lib/Support/Lua.cpp @@ -8,11 +8,12 @@ // Official repository: https://github.com/cppalliance/mrdocs // +#include "../../../third-party/lua/src/lua.hpp" +#include #include -#include #include -#include "../../../third-party/lua/src/lua.hpp" -#include +#include +#include #include #include "lib/Support/LuaHandlebars.hpp" @@ -214,13 +215,12 @@ luaM_report( source_location::current()) { SourceLocation Loc(err.location()); - fmt::print( - "{}\n" - //" at {}({})\n", - ,err.message() - ,Loc.file_name() - //,Loc.line() - ); + std::print("{}\n" + //" at {}({})\n", + , + err.message(), Loc.file_name() + //,Loc.line() + ); } // Pop the Lua error off the stack @@ -644,12 +644,8 @@ loadChunk( source_location loc) { SourceLocation Loc(loc); - return loadChunk( - luaChunk, - fmt::format("{}({})", - Loc.file_name(), - Loc.line()), - loc); + return loadChunk(luaChunk, + std::format("{}({})", Loc.file_name(), Loc.line()), loc); } Expected @@ -1205,7 +1201,7 @@ lua_main() { "x", "0" }, { "y", "1" } }); - fmt::println("{}", testFunc(obj)); + std::println("{}", testFunc(obj)); } } // lua diff --git a/src/lib/Support/Report.cpp b/src/lib/Support/Report.cpp index 20642e4d5..ae0e0b4d8 100644 --- a/src/lib/Support/Report.cpp +++ b/src/lib/Support/Report.cpp @@ -9,12 +9,13 @@ // #include "lib/Support/Report.hpp" -#include -#include +#include +#include #include -#include #include -#include +#include +#include +#include #include #ifdef _MSC_VER @@ -43,12 +44,10 @@ Error:: formatWhere( source_location const& loc) { - return fmt::format("{}:{}", - ::SourceFileNames::getFileName( - loc.file_name()), - loc.line()); + return std::format("{}:{}", ::SourceFileNames::getFileName(loc.file_name()), + loc.line()); #if 0 - return fmt::format( + return std::format( "{}@{}({})", loc.function_name(), ::SourceFileNames::getFileName( @@ -120,8 +119,7 @@ Error( } where_ = formatWhere(loc); - reason_ = fmt::format( - "{} errors occurred:\n", errors.size()); + reason_ = std::format("{} errors occurred:\n", errors.size()); for(auto const& err : errors) { reason_.append(" "); @@ -277,18 +275,18 @@ call_impl( os << "An issue occurred during execution.\n"; os << "If you believe this is a bug, please report it at https://github.com/cppalliance/mrdocs/issues\n" "with the following details:\n"; - os << fmt::format(" MrDocs Version: {} (Build: {})\n", project_version, project_version_build); + os << std::format(" MrDocs Version: {} (Build: {})\n", + project_version, project_version_build); if (e) { - os << fmt::format( - " Error Location: `{}` at line {}\n", - ::SourceFileNames::getFileName(e->location().file_name()), - e->location().line()); + os << std::format( + " Error Location: `{}` at line {}\n", + ::SourceFileNames::getFileName(e->location().file_name()), + e->location().line()); } - os << fmt::format( - " Reported From: `{}` at line {}\n", - ::SourceFileNames::getFileName(loc->file_name()), - loc->line()); + os << std::format(" Reported From: `{}` at line {}\n", + ::SourceFileNames::getFileName(loc->file_name()), + loc->line()); // VFALCO attach a stack trace for Level::fatal } os << '\n'; diff --git a/src/lib/Support/Report.hpp b/src/lib/Support/Report.hpp index 837972db3..d8800a8a2 100644 --- a/src/lib/Support/Report.hpp +++ b/src/lib/Support/Report.hpp @@ -11,11 +11,12 @@ #ifndef MRDOCS_LIB_SUPPORT_ERROR_HPP #define MRDOCS_LIB_SUPPORT_ERROR_HPP -#include +#include +#include #include #include #include -#include +#include #include #include @@ -129,30 +130,23 @@ call( } // clang::mrdocs -template<> -struct fmt::formatter - : fmt::formatter -{ - auto format( - llvm::StringRef s, - fmt::format_context& ctx) const - { - return fmt::formatter::format( - std::string_view(s.data(), s.size()), ctx); - } +template <> +struct std::formatter : std::formatter { + template + auto format(llvm::StringRef s, FmtContext &ctx) const { + return std::formatter::format( + std::string_view(s.data(), s.size()), ctx); + } }; -template -struct fmt::formatter> - : fmt::formatter -{ - auto format( - llvm::SmallString const& s, - fmt::format_context& ctx) const - { - return fmt::formatter::format( - std::string_view(s.data(), s.size()), ctx); - } +template +struct std::formatter> + : std::formatter { + template + auto format(llvm::SmallString const &s, FmtContext &ctx) const { + return std::formatter::format( + std::string_view(s.data(), s.size()), ctx); + } }; #endif diff --git a/src/test/lib/Dom/Dom.cpp b/src/test/lib/Dom/Dom.cpp index 59dd90aeb..4e5f17861 100644 --- a/src/test/lib/Dom/Dom.cpp +++ b/src/test/lib/Dom/Dom.cpp @@ -8,6 +8,7 @@ // Official repository: https://github.com/cppalliance/mrdocs // +#include #include #include @@ -226,10 +227,10 @@ struct Dom_test BOOST_TEST(s3 == "helloworld"); } - // fmt::formatter + // std::formatter { String s("hello"); - BOOST_TEST(fmt::format("{}", s) == "hello"); + BOOST_TEST(std::format("{}", s) == "hello"); } } diff --git a/src/test/lib/Support/Handlebars.cpp b/src/test/lib/Support/Handlebars.cpp index 61434fc3c..7a0a10c74 100644 --- a/src/test/lib/Support/Handlebars.cpp +++ b/src/test/lib/Support/Handlebars.cpp @@ -5,17 +5,17 @@ // https://www.boost.org/LICENSE_1_0.txt // -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include #include -#include -#include -#include +#include +#include +#include #include namespace clang { @@ -329,27 +329,27 @@ setup_helpers() std::size_t const n = arguments.size(); if (n < 4) { - return fmt::format( - "progress helper requires 3 arguments: {} provided", - arguments.size()); + return std::format( + "progress helper requires 3 arguments: {} provided", + arguments.size()); } if (!arguments.get(0).isString()) { - return fmt::format( - "progress helper requires string argument: {} received", - arguments.get(0)); + return std::format( + "progress helper requires string argument: {} received", + arguments.get(0)); } if (!arguments.get(1).isInteger()) { - return fmt::format( - "progress helper requires number argument: {} received", - arguments.get(1)); + return std::format( + "progress helper requires number argument: {} received", + arguments.get(1)); } if (!arguments.get(2).isBoolean()) { - return fmt::format( - "progress helper requires boolean argument: {} received", - arguments.get(2)); + return std::format( + "progress helper requires boolean argument: {} received", + arguments.get(2)); } dom::Value nameV = arguments.get(0); std::string_view name = nameV.getString(); @@ -381,7 +381,7 @@ setup_helpers() } if (arguments.size() > 1) { - return fmt::format(R"(Missing helper: "{}")", options.get("name")); + return std::format(R"(Missing helper: "{}")", options.get("name")); } return {}; }); @@ -400,7 +400,9 @@ setup_helpers() { if (!args.get(i).isString()) { - return fmt::format("link helper requires string arguments: {} provided", args.size()); + return std::format( + "link helper requires string arguments: {} provided", + args.size()); } } @@ -416,7 +418,9 @@ setup_helpers() { if (!args.get(1).isString()) { - return fmt::format("link helper requires string argument: {} provided", toString(args.get(1).kind())); + return std::format( + "link helper requires string argument: {} provided", + toString(args.get(1).kind())); } auto href = args.get(1); out += href.getString(); @@ -470,7 +474,9 @@ setup_helpers() dom::Array::value_type const& firstArg = args.get(0); if (!firstArg.isString()) { - return fmt::format("loud helper requires string argument: {} provided", toString(firstArg.kind())); + return std::format( + "loud helper requires string argument: {} provided", + toString(firstArg.kind())); } res = firstArg.getString(); } @@ -490,7 +496,8 @@ setup_helpers() master.hbs.registerHelper("bold", dom::makeVariadicInvocable([]( dom::Array const& args) { dom::Value options = args.back(); - return fmt::format(R"(
{}
)", options.get("fn")()); + return std::format(R"(
{}
)", + options.get("fn")()); })); master.hbs.registerHelper("list", dom::makeVariadicInvocable([]( @@ -498,11 +505,13 @@ setup_helpers() // Built-in helper to change the context for each object in args if (args.size() < 2) { - return fmt::format("list helper requires 1 argument: {} provided", args.size() - 1); + return std::format("list helper requires 1 argument: {} provided", + args.size() - 1); } if (!args.get(0).isArray()) { - return fmt::format("list helper requires array argument: {} provided", toString(args.get(0).kind())); + return std::format("list helper requires array argument: {} provided", + toString(args.get(0).kind())); } dom::Value options = args.back(); @@ -588,7 +597,7 @@ setup_logger() dom::Array const& args) { dom::Value level = args.get(0); - master.log += fmt::format("[{}] ", level); + master.log += std::format("[{}] ", level); for (std::size_t i = 1; i < args.size(); ++i) { if (i != 1) @@ -670,7 +679,7 @@ safe_string() if (!str) { return "bold helper requires at least one argument"; } - return fmt::format("{}", str); + return std::format("{}", str); }); std::string templ = "{{bold 'text'}}"; std::string res = hbs.render(templ, {}); @@ -687,7 +696,7 @@ safe_string() if (!str) { return safeString("bold helper requires at least one argument"); } - return safeString(fmt::format("{}", str)); + return safeString(std::format("{}", str)); }); res = hbs.render(templ, {}); BOOST_TEST(res == "text"); diff --git a/src/test_suite/detail/decomposer.hpp b/src/test_suite/detail/decomposer.hpp index dab136ae8..21d2a7011 100644 --- a/src/test_suite/detail/decomposer.hpp +++ b/src/test_suite/detail/decomposer.hpp @@ -8,17 +8,12 @@ #ifndef MRDOCS_TEST_DECOMPOSER_HPP #define MRDOCS_TEST_DECOMPOSER_HPP -#include -#include +#include #include +#include +#include #include -#if defined(__has_include) && __has_include() -#include -#include -#define MRDOCS_TEST_HAS_FMT -#endif - // These are test macros we can use to test our code without having to // integrate a test framework for now. @@ -52,17 +47,14 @@ namespace test_suite::detail { out += '\"'; } -#ifdef MRDOCS_TEST_HAS_FMT - if constexpr (fmt::is_formattable::value) { - out += fmt::format("{}", value); - } else -#endif - if constexpr (has_ostream_op::value) { - std::stringstream ss; - ss << value; - out += ss.str(); + if constexpr (std::formattable) { + out += std::format("{}", value); + } else if constexpr (has_ostream_op::value) { + std::stringstream ss; + ss << value; + out += ss.str(); } else { - out += demangle(); + out += demangle(); } if constexpr (std::is_convertible_v, std::string_view>) { diff --git a/src/test_suite/diff.cpp b/src/test_suite/diff.cpp index bb8a01718..341bba588 100644 --- a/src/test_suite/diff.cpp +++ b/src/test_suite/diff.cpp @@ -8,17 +8,12 @@ // #include "diff.hpp" -#include -#include #include "test_suite.hpp" - -#if defined(__has_include) && __has_include() -#include -#include -#define MRDOCS_TEST_HAS_FMT -#else -#include -#endif +#include +#include +#include +#include +#include namespace test_suite { // Diff two strings and return the result as a string with additional stats @@ -213,42 +208,24 @@ diffStrings(std::string_view str1, std::string_view str2, std::size_t context_si } if (out_of_context > 0) { -#ifdef MRDOCS_TEST_HAS_FMT - result.diff += fmt::format(fmt::fg(fmt::color::gray), "... {} unmodified line(s)\n", out_of_context); -#else - result.diff += "... " + std::to_string(out_of_context) + " unmodified line(s)\n"; -#endif - out_of_context = 0; + result.diff += + std::format("... {} unmodified line(s)\n", out_of_context); + out_of_context = 0; } if (diffLine.added || diffLine.removed) { -#ifdef MRDOCS_TEST_HAS_FMT - result.diff += fmt::format( - fmt::fg(diffLine.added ? fmt::color::light_green : fmt::color::orange_red), - "{} {}\n", - diffLine.added ? '+' : '-', - diffLine.line.empty() ? " (empty line)" : diffLine.line); -#else - result.diff += (diffLine.added ? '+' : '-') + diffLine.line + '\n'; - result.diff += (diffLine.line.empty() ? " (empty line)" : diffLine.line) + '\n'; -#endif + result.diff += std::format("{} {}\n", diffLine.added ? '+' : '-', + diffLine.line.empty() ? " (empty line)" + : diffLine.line); } else { -#ifdef MRDOCS_TEST_HAS_FMT - result.diff += fmt::format("{}\n", diffLine.line); -#else - result.diff += diffLine.line + '\n'; -#endif + result.diff += std::format("{}\n", diffLine.line); } } if (out_of_context > 0) { -#ifdef MRDOCS_TEST_HAS_FMT - result.diff += fmt::format(fmt::fg(fmt::color::gray), "... {} unmodified line(s)", out_of_context); -#else - result.diff += "... " + std::to_string(out_of_context) + " unmodified line(s)"; -#endif + result.diff += std::format("... {} unmodified line(s)", out_of_context); } return result; @@ -267,11 +244,7 @@ BOOST_TEST_DIFF( // Write rendered template to file with ofstream std::ofstream out((std::string(expected_contents_path))); BOOST_TEST(out); -#ifdef MRDOCS_TEST_HAS_FMT - fmt::println("Parsed template:\n{}", rendered_contents); -#else - std::cout << "Parsed template:\n" << rendered_contents << std::endl; -#endif + std::println("Parsed template:\n{}", rendered_contents); out << rendered_contents; } else @@ -286,11 +259,9 @@ BOOST_TEST_DIFF( BOOST_TEST(out); out << rendered_contents; } -#ifdef MRDOCS_TEST_HAS_FMT - fmt::println("DIFF:\n=====================\n{}\n=====================", diff.diff); -#else - std::cout << "DIFF:\n=====================\n" << diff.diff << "\n=====================" << std::endl; -#endif + std::println( + "DIFF:\n=====================\n{}\n=====================", + diff.diff); BOOST_TEST(diff.added == 0); BOOST_TEST(diff.removed == 0); } diff --git a/util/generate-config-info.py b/util/generate-config-info.py index 2eba3c859..e7d0031fb 100644 --- a/util/generate-config-info.py +++ b/util/generate-config-info.py @@ -940,6 +940,17 @@ def generate_public_toolargs_cpp(config): contents += f'#include {header}\n' contents += '\n' + contents += ''' +template +struct std::formatter> + : std::formatter { + template + auto format(llvm::cl::opt const &value, FmtContext &ctx) const { + return std::formatter::format(value.getValue(), ctx); + } +}; + ''' + contents += 'namespace clang::mrdocs {\n\n' # Main constructor that initializes all options diff --git a/vcpkg.json.example b/vcpkg.json.example index fb260f570..d93ea0b82 100644 --- a/vcpkg.json.example +++ b/vcpkg.json.example @@ -2,10 +2,6 @@ "name": "mrdocs", "version": "0.1.0", "dependencies": [ - { - "name": "fmt", - "version>=": "10.0.0" - }, "duktape" ], "features": {