diff --git a/.gitmodules b/.gitmodules index a8200ea..a6b2225 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,6 +4,3 @@ [submodule "external/doctest"] path = external/doctest url = ../../doctest/doctest.git -[submodule "external/fmt"] - path = external/fmt - url = ../../fmtlib/fmt.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f3fb2b..f38f429 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,15 +17,6 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) add_library(fe INTERFACE) -check_include_file_cxx("format" CXX_FORMAT_SUPPORT) -message(STATUS "CXX_FORMAT_SUPPORT: ${CXX_FORMAT_SUPPORT}") -if(CXX_FORMAT_SUPPORT) - target_compile_definitions(fe INTERFACE FE_STD_FORMAT_SUPPORT) -else() - add_subdirectory(external/fmt) - target_link_libraries(fe INTERFACE fmt::fmt) -endif() - target_sources(fe INTERFACE FILE_SET headers diff --git a/cmake/fe-config.cmake.in b/cmake/fe-config.cmake.in index ac2cfd1..3df8c67 100644 --- a/cmake/fe-config.cmake.in +++ b/cmake/fe-config.cmake.in @@ -1,8 +1,3 @@ @PACKAGE_INIT@ -set(FE_STD_FORMAT_SUPPORT @CXX_FORMAT_SUPPORT@) -if(NOT FE_STD_FORMAT_SUPPORT) - include(${CMAKE_CURRENT_LIST_DIR}/../fmt/fmt-config.cmake) -endif() - include(${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake) diff --git a/external/fmt b/external/fmt deleted file mode 160000 index 6b0082e..0000000 --- a/external/fmt +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6b0082e6c799c42c41596c008b2891fb6b786143 diff --git a/include/fe/driver.h b/include/fe/driver.h index df326db..0082863 100644 --- a/include/fe/driver.h +++ b/include/fe/driver.h @@ -17,9 +17,9 @@ struct Driver : public SymPool { /// @name Diagnostics ///@{ // clang-format off - template static void note(Loc loc, format::format_string fmt, Args&&... args) { std::cerr << loc << ": note: " << format::format(fmt, std::forward(args)...) << std::endl; } - template void warn(Loc loc, format::format_string fmt, Args&&... args) { ++num_warnings_; std::cerr << loc << ": warning: " << format::format(fmt, std::forward(args)...) << std::endl; } - template void err (Loc loc, format::format_string fmt, Args&&... args) { ++num_errors_; std::cerr << loc << ": error: " << format::format(fmt, std::forward(args)...) << std::endl; } + template static void note(Loc loc, std::format_string fmt, Args&&... args) { std::cerr << loc << ": note: " << std::format(fmt, std::forward(args)...) << std::endl; } + template void warn(Loc loc, std::format_string fmt, Args&&... args) { ++num_warnings_; std::cerr << loc << ": warning: " << std::format(fmt, std::forward(args)...) << std::endl; } + template void err (Loc loc, std::format_string fmt, Args&&... args) { ++num_errors_; std::cerr << loc << ": error: " << std::format(fmt, std::forward(args)...) << std::endl; } // clang-format on unsigned num_errors() const { return num_errors_; } diff --git a/include/fe/format.h b/include/fe/format.h index d303be8..b4feeae 100644 --- a/include/fe/format.h +++ b/include/fe/format.h @@ -1,24 +1,12 @@ #pragma once -#ifdef FE_STD_FORMAT_SUPPORT -# include -#else -# include -#endif +#include #include "fe/loc.h" #include "fe/utf8.h" namespace fe { -namespace format { -#ifdef FE_STD_FORMAT_SUPPORT -using namespace ::std; -#else -using namespace ::fmt; -#endif -} // namespace format - /// Make types that support ostream operators available for `std::format`. /// Use like this: /// ``` @@ -26,15 +14,15 @@ using namespace ::fmt; /// ``` /// @sa [Stack Overflow](https://stackoverflow.com/a/75738462). template -struct basic_ostream_formatter : format::formatter, Char> { +struct basic_ostream_formatter : std::formatter, Char> { template - O format(const T& value, format::basic_format_context& ctx) const { + O format(const T& value, std::basic_format_context& ctx) const { std::basic_stringstream ss; ss << value; #if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 170000 return std::formatter, Char>::format(ss.str(), ctx); #else - return format::formatter, Char>::format(ss.view(), ctx); + return std::formatter, Char>::format(ss.view(), ctx); #endif } }; @@ -45,10 +33,10 @@ using ostream_formatter = basic_ostream_formatter; /// Print to `std::cout`/`std::cerr` via `std::format`; the `*ln` variants conclude with `std::endl`. ///@{ // clang-format off -template void err (format::format_string fmt, Args&&... args) { std::cerr << format::format(fmt, std::forward(args)...); } -template void out (format::format_string fmt, Args&&... args) { std::cout << format::format(fmt, std::forward(args)...); } -template void errln(format::format_string fmt, Args&&... args) { std::cerr << format::format(fmt, std::forward(args)...) << std::endl; } -template void outln(format::format_string fmt, Args&&... args) { std::cout << format::format(fmt, std::forward(args)...) << std::endl; } +template void err (std::format_string fmt, Args&&... args) { std::cerr << std::format(fmt, std::forward(args)...); } +template void out (std::format_string fmt, Args&&... args) { std::cout << std::format(fmt, std::forward(args)...); } +template void errln(std::format_string fmt, Args&&... args) { std::cerr << std::format(fmt, std::forward(args)...) << std::endl; } +template void outln(std::format_string fmt, Args&&... args) { std::cout << std::format(fmt, std::forward(args)...) << std::endl; } // clang-format on /// Keeps track of indentation level during output @@ -105,14 +93,11 @@ class Tab { } // namespace fe #ifndef DOXYGEN -template<> -struct fe::format::formatter : fe::ostream_formatter {}; -template<> -struct fe::format::formatter : fe::ostream_formatter {}; -template<> -struct fe::format::formatter : fe::ostream_formatter {}; -template<> -struct fe::format::formatter : fe::ostream_formatter {}; -template<> -struct fe::format::formatter : fe::ostream_formatter {}; +// clang-format off +template<> struct std::formatter : fe::ostream_formatter {}; +template<> struct std::formatter : fe::ostream_formatter {}; +template<> struct std::formatter : fe::ostream_formatter {}; +template<> struct std::formatter : fe::ostream_formatter {}; +template<> struct std::formatter : fe::ostream_formatter {}; +// clang-format on #endif diff --git a/tests/lexer.cpp b/tests/lexer.cpp index db49b26..b9c2a6e 100644 --- a/tests/lexer.cpp +++ b/tests/lexer.cpp @@ -102,7 +102,7 @@ class Tok { }; }; -template<> struct fe::format::formatter : fe::ostream_formatter {}; +template<> struct std::formatter : fe::ostream_formatter {}; template class Lexer : public fe::Lexer> { public: @@ -186,7 +186,7 @@ template void test_lexer() { auto tb = lexer.lex(); auto tc = lexer.lex(); auto td = lexer.lex(); - auto s = fe::format::format("{} {} {} {} {} {} {} {} {} {} {} {} {} {}", t1, t2, t3, t4, t5, t6, t7, t8, t9, t0, ta, + auto s = std::format("{} {} {} {} {} {} {} {} {} {} {} {} {} {}", t1, t2, t3, t4, t5, t6, t7, t8, t9, t0, ta, tb, tc, td); CHECK(s == "test abc def if while λ foo « n ; X » ");