Fixed a few clang-tidy warnings in libdebug.

This commit is contained in:
Alexander Shaduri
2021-03-03 16:53:50 +04:00
parent ff3b07a086
commit f8369fe436
7 changed files with 75 additions and 92 deletions
+1 -1
View File
@@ -69,7 +69,7 @@ class DebugChannelOStream : public DebugChannelBase {
// Non-debug-API members:
/// Get the ostream.
std::ostream& get_ostream()
[[nodiscard]] std::ostream& get_ostream()
{
return os_;
}
+3 -5
View File
@@ -57,13 +57,11 @@ namespace debug_internal {
/// Libdebug global command-line arguments
static DebugCmdArgs s_debug_cmd_args;
/// Get libdebug command-line arguments
inline DebugCmdArgs* debug_get_args_holder()
inline DebugCmdArgs* get_debug_get_args_holder()
{
return &s_debug_cmd_args;
static DebugCmdArgs args;
return &args;
}
+18 -23
View File
@@ -14,50 +14,45 @@ Copyright:
#include <map>
namespace {
namespace debug_level {
/// Debug level names
const std::map<debug_level::flag, const char*> s_level_names = {
/// Get debug level name
const char* get_name(flag level)
{
static const std::map<debug_level::flag, const char*> level_names = {
{debug_level::fatal, "fatal"},
{debug_level::error, "error"},
{debug_level::warn, "warn"},
{debug_level::info, "info"},
{debug_level::dump, "dump"}
};
return level_names.at(level);
}
/// Debug level color start sequences
const std::map<debug_level::flag, const char*> s_level_colors = {
/// Get debug level color start sequence
const char* get_color_start(flag level)
{
static const std::map<debug_level::flag, const char*> level_colors = {
{debug_level::fatal, "\033[1;4;31m"}, // red underlined
{debug_level::error, "\033[1;4;31m"}, // red
{debug_level::warn, "\033[1;35m"}, // magenta
{debug_level::info, "\033[1;36m"}, // cyan
{debug_level::dump, "\033[1;32m"} // green
};
return level_colors.at(level);
}
namespace debug_level {
/// Get debug level color stop sequence
const char* get_color_stop([[maybe_unused]] flag level)
{
return "\033[0m";
}
const char* get_name(flag level)
{
return s_level_names.at(level);
}
const char* get_color_start(flag level)
{
return s_level_colors.at(level);
}
const char* get_color_stop([[maybe_unused]] flag level)
{
return "\033[0m";
}
}
+5 -28
View File
@@ -31,17 +31,8 @@ std::ostream& debug_out(debug_level::flag level, const std::string& domain)
auto level_map = dm.find(domain);
if (level_map == dm.end()) { // no such domain
std::string msg = "debug_out(): Debug state doesn't contain the requested domain: \"" + domain + "\".";
if (domain != "default") {
debug_out(debug_level::warn, "default") << msg << "\n";
debug_out(debug_level::info, "default") << "Auto-creating the missing domain.\n";
debug_register_domain(domain);
debug_out(debug_level::warn, "default") << "The message follows:\n";
return debug_out(level, domain); // try again
}
// this is an internal error
std::string msg = "debug_out(): Debug state doesn't contain the requested domain: \"" + domain + "\".";
throw debug_internal_error(msg.c_str());
}
@@ -103,20 +94,20 @@ namespace debug_internal {
std::ostringstream os;
os << "(";
if (enabled_types.to_ulong() & debug_pos::func_name) {
if (enabled_types.test(debug_pos::func_name)) {
os << "function: " << func_name;
} else if (enabled_types.to_ulong() & debug_pos::func) {
} else if (enabled_types.test(debug_pos::func)) {
os << "function: " << func << "()";
}
if (enabled_types.to_ulong() & debug_pos::file) {
if (enabled_types.test(debug_pos::file)) {
if (os.str() != "(")
os << ", ";
os << "file: " << file;
}
if (enabled_types.to_ulong() & debug_pos::line) {
if (enabled_types.test(debug_pos::line)) {
if (os.str() != "(")
os << ", ";
os << "line: " << line;
@@ -161,20 +152,6 @@ void debug_indent_reset()
namespace debug_internal {
// manupulator objects
DebugIndent debug_indent;
DebugUnindent debug_unindent;
DebugResetIndent debug_resindent;
}
+39 -26
View File
@@ -16,6 +16,7 @@ Copyright:
// Note: Sun compiler refuses to compile without <ostream> (iosfwd is not enough).
// Since every useful operator << is defined in ostream, we include it here anyway.
#include <ostream> // std::ostream
#include <utility>
#include "hz/system_specific.h" // HZ_FUNC_PRINTF_ISO_CHECK
@@ -109,17 +110,18 @@ namespace debug_internal {
struct DebugSourcePos {
/// Constructor
inline DebugSourcePos(const std::string& file_, int line_, const std::string& func_name_, const std::string& func_)
: func_name(func_name_), func(func_), line(line_), file(file_), enabled_types(debug_pos::def)
inline DebugSourcePos(std::string par_file, int line_, std::string par_func_name, std::string par_func)
: func_name(std::move(par_func_name)), func(std::move(par_func)), line(line_), file(std::move(par_file)),
enabled_types(debug_pos::def)
{ }
/// Formatted output string
std::string str() const;
[[nodiscard]] std::string str() const;
std::string func_name; ///< Function name only
std::string func; ///< Function name with namespaces and classes
int line; ///< Source line
int line = 0; ///< Source line
std::string file; ///< Source file
debug_pos::type enabled_types; ///< Enabled formatting types
@@ -230,6 +232,28 @@ namespace debug_internal {
} else (void)0
/// Prints generic message to error-level if assertion fails. Don't need to send into stream, it prints by itself.
/// Returns from the function on assertion failure.
#define DBG_ASSERT_RETURN(cond, return_value) \
do { \
if (!(cond)) { \
debug_out_error("default", "ASSERTION FAILED: " << #cond << " at " << DBG_POS << "\n"); \
return (return_value); \
} \
} while(false)
/// Prints generic message to error-level if assertion fails. Don't need to send into stream, it prints by itself.
/// Returns from the function on assertion failure.
#define DBG_ASSERT_RETURN_NONE(cond) \
do { \
if (!(cond)) { \
debug_out_error("default", "ASSERTION FAILED: " << #cond << " at " << DBG_POS << "\n"); \
return; \
} \
} while(false)
// ------------------ Indentation and manipulators
@@ -259,7 +283,7 @@ namespace debug_internal {
/// A stream manipulator that increases the indentation level
struct DebugIndent {
/// Constructor
DebugIndent(int indent_level = 1) : by(indent_level)
constexpr explicit DebugIndent(int indent_level = 1) : by(indent_level)
{ }
/// Constructs a new DebugIndent object
@@ -275,7 +299,7 @@ namespace debug_internal {
/// A stream manipulator that decreases the indentation level
struct DebugUnindent {
/// Constructor
DebugUnindent(int unindent_level = 1) : by(unindent_level)
constexpr explicit DebugUnindent(int unindent_level = 1) : by(unindent_level)
{ }
/// Constructs a new DebugUnindent object
@@ -304,7 +328,7 @@ namespace debug_internal {
// operands are for ADL to work inside _other_ namespaces.
/// A stream manipulator operator
inline std::ostream& operator<< (std::ostream& os, debug_internal::DebugIndent& m)
inline std::ostream& operator<< (std::ostream& os, const debug_internal::DebugIndent& m)
{
debug_indent_inc(m.by);
return os;
@@ -312,7 +336,7 @@ namespace debug_internal {
/// A stream manipulator operator
inline std::ostream& operator<< (std::ostream& os, debug_internal::DebugUnindent& m)
inline std::ostream& operator<< (std::ostream& os, const debug_internal::DebugUnindent& m)
{
debug_indent_dec(m.by);
return os;
@@ -320,36 +344,25 @@ namespace debug_internal {
/// A stream manipulator operator
inline std::ostream& operator<< (std::ostream& os, [[maybe_unused]] debug_internal::DebugResetIndent& m)
inline std::ostream& operator<< (std::ostream& os, [[maybe_unused]] const debug_internal::DebugResetIndent& m)
{
debug_indent_reset();
return os;
}
// Manipulator objects:
/// Send this to libdebug-backed stream to increase the indentation level by 1.
extern DebugIndent debug_indent;
/// Send this to libdebug-backed stream to decrease the indentation level by 1.
extern DebugUnindent debug_unindent;
/// Send this to libdebug-backed stream to reset the indentation level to 0.
extern DebugResetIndent debug_resindent;
} // ns
// manupulator objects
using debug_internal::debug_indent;
using debug_internal::debug_unindent;
using debug_internal::debug_resindent;
/// Manupulator object - send this to libdebug-backed stream to increase the indentation level by 1.
constexpr inline debug_internal::DebugIndent debug_indent;
/// Manupulator object - send this to libdebug-backed stream to decrease the indentation level by 1.
constexpr inline debug_internal::DebugUnindent debug_unindent;
/// Manupulator object - send this to libdebug-backed stream to reset the indentation level to 0.
constexpr inline debug_internal::DebugResetIndent debug_resindent;
+3 -3
View File
@@ -56,14 +56,14 @@ namespace debug_internal {
/// Get the domain/level mapping.
domain_map_t& get_domain_map()
[[nodiscard]] domain_map_t& get_domain_map()
{
return domain_map;
}
/// Get current indentation level.
int get_indent_level() const
[[nodiscard]] int get_indent_level() const
{
return indent_level_;
}
@@ -91,7 +91,7 @@ namespace debug_internal {
}
/// Check if we're inside a debug_begin() context.
bool get_inside_begin() const
[[nodiscard]] bool get_inside_begin() const
{
if (inside_begin_.empty())
return false;
+6 -6
View File
@@ -48,7 +48,7 @@ namespace debug_internal {
public:
/// Constructor
DebugStreamBuf(DebugOutStream* dos) : dos_(dos)
explicit DebugStreamBuf(DebugOutStream* dos) : dos_(dos)
{
// in case of overflow for output, overflow() will be called to _output_ the data.
@@ -70,7 +70,7 @@ namespace debug_internal {
/// Virtual destructor
virtual ~DebugStreamBuf()
~DebugStreamBuf() override
{
sync();
delete[] pbase(); // delete the buffer
@@ -109,7 +109,7 @@ namespace debug_internal {
/// Sort-of flush the buffer. Only makes sense if there is a buffer.
/// Reimplemented.
int sync() override
int sync() final
{
if (pbase() != pptr()) { // pptr() - current position; condition is true only if there is something in the buffer.
// write_out(std::string(pbase(), pptr() - pbase()));
@@ -193,7 +193,7 @@ namespace debug_internal {
}
/// Get format flags
debug_format::type get_format() const
[[nodiscard]] debug_format::type get_format() const
{
return format_;
}
@@ -210,7 +210,7 @@ namespace debug_internal {
}
/// Check whether the stream is enabled or not.
bool get_enabled() const
[[nodiscard]] bool get_enabled() const
{
return (rdbuf() == &buf_);
}
@@ -238,7 +238,7 @@ namespace debug_internal {
/// Check if the last sent output is still on the same line
/// as the first one.
bool get_is_first_line()
[[nodiscard]] bool get_is_first_line()
{
return is_first_line_;
}