print full function name

This commit is contained in:
Johannes Kapfhammer 2019-10-07 14:29:45 +02:00
parent 0aee7de352
commit 4b5a124aa1
2 changed files with 50 additions and 23 deletions

View file

@ -74,7 +74,7 @@ std::string replace_all(std::string str, const std::string &from,
return str;
}
std::string sanitize_type(std::string s) {
inline std::string sanitize_type(std::string s) {
auto f = [&](const char *a, const char *b) {
s = replace_all(std::move(s), a, b);
};
@ -92,6 +92,14 @@ template <class T> std::string sanitized_type_name() {
return sanitize_type(std::string(t.data, t.size));
}
inline std::string extract_method_name(std::string const& pretty_function) {
size_t colons = pretty_function.find("::");
size_t begin = pretty_function.substr(0,colons).rfind(" ") + 1;
size_t end = pretty_function.rfind("(") - begin;
return pretty_function.substr(begin,end);
}
// ----------------------------------------------------------------------------
// colorized output
@ -157,11 +165,11 @@ void dbg_init() { dbg_init(are_colors_enabled()); }
// printer
template <typename T>
T &&dbg_print(T &&value, std::string const &type, char const *file, int line,
char const *function_name, char const *expression) {
T &&dbg_print(T &&value, std::string const& type, char const *file, int line,
std::string const& function_name, char const *expression) {
const T &ref = value;
std::stringstream
value_buffer; // avoid nesting of dbg macros within print functinos
value_buffer; // avoid nesting of dbg macros within print functions
soi::print(value_buffer, ref);
std::cerr << ANSI_DEBUG << "[" << file << ":" << line << " (" << function_name
@ -175,7 +183,7 @@ T &&dbg_print(T &&value, std::string const &type, char const *file, int line,
template <unsigned int N>
auto dbg_print(const char (&msg)[N], std::string const &, char const *file,
int line, char const *function_name, char const *expression)
int line, std::string const& function_name, char const *expression)
-> decltype(msg) {
std::cerr << ANSI_DEBUG << "[" << file << ":" << line << " (" << function_name
<< ")] " << ANSI_RESET << ANSI_MESSAGE << msg << ANSI_RESET << '\n';
@ -204,29 +212,19 @@ template <typename T> T &&identity(T &&t) { return std::forward<T>(t); }
_15
#define SOI_IS_NONEMPTY(...) \
SOI_ARG16(1, ##__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0)
#else
#define SOI_IS_NONEMPTY(...) __VA_OPT__(1)
#define SOI_DBG_IMPL_ SOI_DBG_IMPL_0
#endif
#define SOI_DBG_IMPL_0() \
soi::detail::dbg_print_status(__FILE__, __LINE__, __func__)
#define SOI_DBG_IMPL_1(...) \
soi::detail::dbg_print( \
(__VA_ARGS__), \
soi::detail::sanitized_type_name<decltype(__VA_ARGS__)>(), __FILE__, \
__LINE__, __func__, #__VA_ARGS__)
#else
#define SOI_IS_NONEMPTY(...) __VA_OPT__(HAS)
#define SOI_DBG_IMPL_() \
soi::detail::dbg_print_status(__FILE__, __LINE__, __func__)
#define SOI_DBG_IMPL_HAS(...) \
soi::detail::dbg_print( \
(__VA_ARGS__), \
soi::detail::sanitized_type_name<decltype(__VA_ARGS__)>(), __FILE__, \
__LINE__, __func__, #__VA_ARGS__)
#endif
__LINE__, soi::detail::extract_method_name(__PRETTY_FUNCTION__), #__VA_ARGS__)
#define SOI_CAT(a, ...) PRIMITIVE_CAT(a, __VA_ARGS__)
#define SOI_PRIMITIVE_CAT(a, ...) a##__VA_ARGS__