Skip to content

Commit

Permalink
Update naming of internal assertion macro names
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-rifkin committed Dec 21, 2024
1 parent e46463d commit 63a0409
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions include/libassert/assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
6 changes: 3 additions & 3 deletions include/libassert/utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -48,10 +48,10 @@ namespace libassert::detail {
#define LIBASSERT_PHONY_USE(E) ((void)libassert::detail::always_false<decltype(E)>)

#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)
Expand Down
10 changes: 5 additions & 5 deletions src/analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())});
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions src/assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<highlight_block> location_blocks = concat(
{{"", std::string(path_handler->resolve_path(source_path)) + ":"}},
Expand Down Expand Up @@ -179,7 +179,7 @@ namespace libassert::detail {

LIBASSERT_ATTR_COLD
static std::string print_values(const std::vector<std::string>& 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));
Expand All @@ -200,7 +200,7 @@ namespace libassert::detail {

LIBASSERT_ATTR_COLD
static std::vector<highlight_block> get_values(const std::vector<std::string>& 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 {
Expand Down Expand Up @@ -239,8 +239,8 @@ namespace libassert::detail {
// TODO: Temporary hack while reworking
std::vector<std::string> lstrings = { left_stringification };
std::vector<std::string> 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++) {
Expand Down Expand Up @@ -442,7 +442,7 @@ namespace libassert {
// this library
break;
default:
LIBASSERT_PRIMITIVE_ASSERT(false);
LIBASSERT_PRIMITIVE_DEBUG_ASSERT(false);
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,30 @@ 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);
}

LIBASSERT_ATTR_COLD
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);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -143,7 +143,7 @@ namespace libassert::detail {
std::unordered_map<std::string, std::string> 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))};
Expand Down
2 changes: 1 addition & 1 deletion src/printing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/stringification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<<value;
r: return std::move(oss).str();
Expand Down
6 changes: 3 additions & 3 deletions src/tokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ namespace libassert::detail {
auto begin = pos();
std::size_t count = 0;
while(isspace(peek())) {
internal_verify(advance() == std::nullopt);
LIBASSERT_PRIMITIVE_ASSERT(advance() == std::nullopt);
count++;
}
return {token_e::whitespace, std::string_view(source.data() + begin, count)};
Expand Down Expand Up @@ -541,7 +541,7 @@ namespace libassert::detail {

void rollback(std::size_t count) {
while(count--) {
internal_verify(it != source.begin(), "Tokenizer rollback() failed, please report this bug");
LIBASSERT_PRIMITIVE_ASSERT(it != source.begin(), "Tokenizer rollback() failed, please report this bug");
it--;
}
}
Expand All @@ -566,7 +566,7 @@ namespace libassert::detail {
if(res.index() == 0) {
return std::move(std::get<std::vector<token_t>>(res));
} else {
internal_verify(res.index() == 1);
LIBASSERT_PRIMITIVE_ASSERT(res.index() == 1);
return std::nullopt;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(
Expand All @@ -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));
}
}
Expand All @@ -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));
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<typename... Args>
constexpr bool is_in(const Args&... option) {
Expand Down

0 comments on commit 63a0409

Please sign in to comment.