diff --git a/include/libassert/assert.hpp b/include/libassert/assert.hpp index f439486..b11296d 100644 --- a/include/libassert/assert.hpp +++ b/include/libassert/assert.hpp @@ -404,7 +404,7 @@ namespace libassert::detail { Args&&... args ) { const size_t sizeof_extra_diagnostics = sizeof...(args) - 1; // - 1 for pretty function signature - LIBASSERT_PRIMITIVE_ASSERT(sizeof...(args) <= params->args_strings.size); + LIBASSERT_PRIMITIVE_DEBUG_ASSERT(sizeof...(args) <= params->args_strings.size); assertion_info info( params, cpptrace::generate_raw_trace(), @@ -449,7 +449,7 @@ namespace libassert::detail { Args&&... args ) { const size_t sizeof_extra_diagnostics = sizeof...(args) - 1; // - 1 for pretty function signature - LIBASSERT_PRIMITIVE_ASSERT(sizeof...(args) <= params->args_strings.size); + LIBASSERT_PRIMITIVE_DEBUG_ASSERT(sizeof...(args) <= params->args_strings.size); assertion_info info( params, cpptrace::generate_raw_trace(), diff --git a/include/libassert/utilities.hpp b/include/libassert/utilities.hpp index 92367e1..4e4e27c 100644 --- a/include/libassert/utilities.hpp +++ b/include/libassert/utilities.hpp @@ -31,7 +31,7 @@ namespace libassert::detail { // bootstrap with primitive implementations LIBASSERT_EXPORT void primitive_assert_impl( bool condition, - bool verify, + bool normal_assert, const char* expression, const char* signature, source_location location, @@ -48,10 +48,10 @@ namespace libassert::detail { #define LIBASSERT_PHONY_USE(E) ((void)libassert::detail::always_false) #ifndef NDEBUG - #define LIBASSERT_PRIMITIVE_ASSERT(c, ...) \ + #define LIBASSERT_PRIMITIVE_DEBUG_ASSERT(c, ...) \ libassert::detail::primitive_assert_impl(c, false, #c, LIBASSERT_PFUNC, {} LIBASSERT_VA_ARGS(__VA_ARGS__)) #else - #define LIBASSERT_PRIMITIVE_ASSERT(c, ...) LIBASSERT_PHONY_USE(c) + #define LIBASSERT_PRIMITIVE_DEBUG_ASSERT(c, ...) LIBASSERT_PHONY_USE(c) #endif #define LIBASSERT_PRIMITIVE_PANIC(message) libassert::detail::primitive_panic_impl(LIBASSERT_PFUNC, {}, message) diff --git a/src/analysis.cpp b/src/analysis.cpp index d215ea9..8abb8e8 100644 --- a/src/analysis.cpp +++ b/src/analysis.cpp @@ -279,7 +279,7 @@ namespace libassert::detail { while(std::regex_search(str.data() + i, str.data() + str.size(), match, escapes_re)) { // add string part // TODO: I don't know why this assert was added, I might have done it in dev on a whim. Re-evaluate. - // LIBASSERT_PRIMITIVE_ASSERT(match.position() > 0); + // LIBASSERT_PRIMITIVE_DEBUG_ASSERT(match.position() > 0); if(match.position() > 0) { output.push_back({scheme.string, str.substr(i, match.position())}); } @@ -313,7 +313,7 @@ namespace libassert::detail { } } } - LIBASSERT_PRIMITIVE_ASSERT(j != 0); + LIBASSERT_PRIMITIVE_DEBUG_ASSERT(j != 0); return token_t { token_e::whitespace, "" }; }; switch(token.type) { @@ -442,7 +442,7 @@ namespace libassert::detail { } } if(i == tokens.size() && count != -1) { - LIBASSERT_PRIMITIVE_ASSERT(false, "ill-formed expression input"); + LIBASSERT_PRIMITIVE_DEBUG_ASSERT(false, "ill-formed expression input"); } return empty; }; @@ -472,7 +472,7 @@ namespace libassert::detail { } else if(token.str == "<" && normalize_brace(find_last_non_ws(tokens, i).str) == "]") { // this must be a template parameter list, part of a generic lambda const bool empty = scan_forward("<", ">"); - LIBASSERT_PRIMITIVE_ASSERT(!empty); + LIBASSERT_PRIMITIVE_DEBUG_ASSERT(!empty); state = expecting_operator; continue; } @@ -532,7 +532,7 @@ namespace libassert::detail { } state = expecting_operator; } else { - LIBASSERT_PRIMITIVE_ASSERT(false, "unhandled punctuation?"); + LIBASSERT_PRIMITIVE_DEBUG_ASSERT(false, "unhandled punctuation?"); } break; case token_e::keyword: diff --git a/src/assert.cpp b/src/assert.cpp index c3dd885..75ec5d0 100644 --- a/src/assert.cpp +++ b/src/assert.cpp @@ -134,7 +134,7 @@ namespace libassert::detail { const size_t line_number_width = std::max(line_number.size(), max_line_number_width); const size_t remaining_width = term_width - (left + line_number_width + 2 /* spaces */ + 1 /* : */); const size_t file_width = std::min({max_file_length, remaining_width / 2, max_file_length}); - LIBASSERT_PRIMITIVE_ASSERT(remaining_width >= 2); + LIBASSERT_PRIMITIVE_DEBUG_ASSERT(remaining_width >= 2); const size_t sig_width = remaining_width - file_width; std::vector location_blocks = concat( {{"", std::string(path_handler->resolve_path(source_path)) + ":"}}, @@ -179,7 +179,7 @@ namespace libassert::detail { LIBASSERT_ATTR_COLD static std::string print_values(const std::vector& vec, size_t lw, const color_scheme& scheme) { - LIBASSERT_PRIMITIVE_ASSERT(!vec.empty()); + LIBASSERT_PRIMITIVE_DEBUG_ASSERT(!vec.empty()); std::string values; if(vec.size() == 1) { values += microfmt::format("{}\n", indent(highlight(vec[0], scheme), 8 + lw + 4, ' ', true)); @@ -200,7 +200,7 @@ namespace libassert::detail { LIBASSERT_ATTR_COLD static std::vector get_values(const std::vector& vec, const color_scheme& scheme) { - LIBASSERT_PRIMITIVE_ASSERT(!vec.empty()); + LIBASSERT_PRIMITIVE_DEBUG_ASSERT(!vec.empty()); if(vec.size() == 1) { return highlight_blocks(vec[0], scheme); } else { @@ -239,8 +239,8 @@ namespace libassert::detail { // TODO: Temporary hack while reworking std::vector lstrings = { left_stringification }; std::vector rstrings = { right_stringification }; - LIBASSERT_PRIMITIVE_ASSERT(!lstrings.empty()); - LIBASSERT_PRIMITIVE_ASSERT(!rstrings.empty()); + LIBASSERT_PRIMITIVE_DEBUG_ASSERT(!lstrings.empty()); + LIBASSERT_PRIMITIVE_DEBUG_ASSERT(!rstrings.empty()); // pad all columns where there is overlap // TODO: Use column printer instead of manual padding. for(size_t i = 0; i < std::min(lstrings.size(), rstrings.size()); i++) { @@ -442,7 +442,7 @@ namespace libassert { // this library break; default: - LIBASSERT_PRIMITIVE_ASSERT(false); + LIBASSERT_PRIMITIVE_DEBUG_ASSERT(false); } } } diff --git a/src/paths.cpp b/src/paths.cpp index dac49bd..453f9d6 100644 --- a/src/paths.cpp +++ b/src/paths.cpp @@ -44,14 +44,14 @@ namespace libassert::detail { } } } - LIBASSERT_PRIMITIVE_ASSERT(!parts.empty()); - LIBASSERT_PRIMITIVE_ASSERT(parts.back() != "." && parts.back() != ".."); + LIBASSERT_PRIMITIVE_DEBUG_ASSERT(!parts.empty()); + LIBASSERT_PRIMITIVE_DEBUG_ASSERT(parts.back() != "." && parts.back() != ".."); return parts; } LIBASSERT_ATTR_COLD void path_trie::insert(const path_components& path) { - LIBASSERT_PRIMITIVE_ASSERT(path.back() == root); + LIBASSERT_PRIMITIVE_DEBUG_ASSERT(path.back() == root); insert(path, (int)path.size() - 2); } @@ -59,15 +59,15 @@ namespace libassert::detail { path_components path_trie::disambiguate(const path_components& path) { path_components result; path_trie* current = this; - LIBASSERT_PRIMITIVE_ASSERT(path.back() == root); + LIBASSERT_PRIMITIVE_DEBUG_ASSERT(path.back() == root); result.push_back(current->root); for(size_t i = path.size() - 2; i >= 1; i--) { - LIBASSERT_PRIMITIVE_ASSERT(current->downstream_branches >= 1); + LIBASSERT_PRIMITIVE_DEBUG_ASSERT(current->downstream_branches >= 1); if(current->downstream_branches == 1) { break; } const std::string& component = path[i]; - LIBASSERT_PRIMITIVE_ASSERT(current->edges.count(component)); + LIBASSERT_PRIMITIVE_DEBUG_ASSERT(current->edges.count(component)); current = current->edges.at(component).get(); result.push_back(current->root); } @@ -96,11 +96,11 @@ namespace libassert::detail { } void path_handler::add_path(std::string_view) { - LIBASSERT_PRIMITIVE_ASSERT(false, "Improper path_handler::add_path"); + LIBASSERT_PRIMITIVE_DEBUG_ASSERT(false, "Improper path_handler::add_path"); } void path_handler::finalize() { - LIBASSERT_PRIMITIVE_ASSERT(false, "Improper path_handler::finalize"); + LIBASSERT_PRIMITIVE_DEBUG_ASSERT(false, "Improper path_handler::finalize"); } LIBASSERT_ATTR_COLD @@ -143,7 +143,7 @@ namespace libassert::detail { std::unordered_map files; for(auto& [raw, parsed_path] : parsed_paths) { const std::string new_path = join(tries.at(parsed_path.back()).disambiguate(parsed_path), "/"); - internal_verify(files.insert({raw, new_path}).second); + LIBASSERT_PRIMITIVE_ASSERT(files.insert({raw, new_path}).second); } path_map = std::move(files); // return {files, std::min(longest_file_width, size_t(50))}; diff --git a/src/printing.cpp b/src/printing.cpp index 9be1e7e..66631be 100644 --- a/src/printing.cpp +++ b/src/printing.cpp @@ -27,7 +27,7 @@ namespace libassert::detail { } // number of characters we can extract from the block size_t extract = std::min(width - lines[current_line][i].length, block.content.size() - block_i); - LIBASSERT_PRIMITIVE_ASSERT(block_i + extract <= block.content.size()); + LIBASSERT_PRIMITIVE_DEBUG_ASSERT(block_i + extract <= block.content.size()); auto substr = std::string_view(block.content).substr(block_i, extract); // handle newlines if(auto x = substr.find('\n'); x != std::string_view::npos) { diff --git a/src/stringification.cpp b/src/stringification.cpp index 64b6f5c..3834ff2 100644 --- a/src/stringification.cpp +++ b/src/stringification.cpp @@ -80,7 +80,7 @@ namespace libassert::detail { } else if(mode == literal_format_mode::fixed_variations) { set_thread_current_literal_format(fixed_format); } else { - LIBASSERT_PRIMITIVE_ASSERT(false); + LIBASSERT_PRIMITIVE_DEBUG_ASSERT(false); } return previous; } @@ -176,7 +176,7 @@ namespace libassert::detail { case literal_format::default_format: break; default: - LIBASSERT_PRIMITIVE_ASSERT(false, "unexpected literal format requested for printing"); + LIBASSERT_PRIMITIVE_DEBUG_ASSERT(false, "unexpected literal format requested for printing"); } oss<>(res)); } else { - internal_verify(res.index() == 1); + LIBASSERT_PRIMITIVE_ASSERT(res.index() == 1); return std::nullopt; } } diff --git a/src/utils.cpp b/src/utils.cpp index 9dfce77..acb6c67 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -25,7 +25,7 @@ namespace libassert::detail { va_start(args1, format); va_start(args2, format); const int length = vsnprintf(nullptr, 0, format, args1); - if(length < 0) { LIBASSERT_PRIMITIVE_ASSERT(false, "Invalid arguments to stringf"); } + if(length < 0) { LIBASSERT_PRIMITIVE_DEBUG_ASSERT(false, "Invalid arguments to stringf"); } std::string str(length, 0); (void)vsnprintf(str.data(), length + 1, format, args2); va_end(args1); @@ -36,15 +36,15 @@ namespace libassert::detail { LIBASSERT_ATTR_COLD void primitive_assert_impl( bool condition, - bool verify, + bool normal_assert, const char* expression, const char* signature, source_location location, const char* message ) { if(!condition) { - const char* action = verify ? "Verification" : "Assertion"; - const char* name = verify ? "verify" : "assert"; + const char* action = normal_assert ? "Assert" : "Debug assert"; + const char* name = normal_assert ? "LIBASSERT_PRIMITIVE_ASSERT" : "LIBASSERT_PRIMITIVE_DEBUG_ASSERT"; std::string out_message; if(message == nullptr) { out_message += microfmt::format( @@ -64,7 +64,7 @@ namespace libassert::detail { message ); } - out_message += microfmt::format(" primitive_{}({});\n", name, expression); + out_message += microfmt::format(" {}({});\n", name, expression); throw cpptrace::runtime_error(std::move(out_message)); } } @@ -81,7 +81,7 @@ namespace libassert::detail { signature, message ); - out_message += " primitive_panic(...);\n"; + out_message += " LIBASSERT_PRIMITIVE_PANIC(...);\n"; throw cpptrace::runtime_error(std::move(out_message)); } diff --git a/src/utils.hpp b/src/utils.hpp index 18b90e5..347c9d9 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -19,7 +19,7 @@ namespace libassert::detail { // Still present in release mode, nonfatal - #define internal_verify(c, ...) primitive_assert_impl(c, true, #c, LIBASSERT_PFUNC, {} LIBASSERT_VA_ARGS(__VA_ARGS__)) + #define LIBASSERT_PRIMITIVE_ASSERT(c, ...) primitive_assert_impl(c, true, #c, LIBASSERT_PFUNC, {} LIBASSERT_VA_ARGS(__VA_ARGS__)) /* * string utilities @@ -89,7 +89,7 @@ namespace libassert::detail { constexpr V lookup(const K& option, const V& result, const Rest&... rest) { if(needle_value == option) { return result; } if constexpr(sizeof...(Rest) > 0) { return lookup(rest...); } - else { LIBASSERT_PRIMITIVE_ASSERT(false); LIBASSERT_UNREACHABLE_CALL; } + else { LIBASSERT_PRIMITIVE_DEBUG_ASSERT(false); LIBASSERT_UNREACHABLE_CALL; } } template constexpr bool is_in(const Args&... option) {