diff options
author | kartynnik <kartynnik@yandex-team.ru> | 2022-02-10 16:48:07 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:07 +0300 |
commit | df6128370874866447314ec18d8e67fc7bde40b4 (patch) | |
tree | b222e5ac2e2e98872661c51ccceee5da0d291e13 /library/cpp/dbg_output | |
parent | ca2a705e6e39e85df30054d7e806e572de9cfe23 (diff) | |
download | ydb-df6128370874866447314ec18d8e67fc7bde40b4.tar.gz |
Restoring authorship annotation for <kartynnik@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/dbg_output')
-rw-r--r-- | library/cpp/dbg_output/DONT_COMMIT.h | 14 | ||||
-rw-r--r-- | library/cpp/dbg_output/auto.h | 28 | ||||
-rw-r--r-- | library/cpp/dbg_output/colorscheme.h | 54 | ||||
-rw-r--r-- | library/cpp/dbg_output/dump.h | 16 | ||||
-rw-r--r-- | library/cpp/dbg_output/dumpers.h | 24 | ||||
-rw-r--r-- | library/cpp/dbg_output/engine.h | 30 | ||||
-rw-r--r-- | library/cpp/dbg_output/ut/dbg_output_ut.cpp | 92 | ||||
-rw-r--r-- | library/cpp/dbg_output/ut/ya.make | 14 | ||||
-rw-r--r-- | library/cpp/dbg_output/ya.make | 6 |
9 files changed, 139 insertions, 139 deletions
diff --git a/library/cpp/dbg_output/DONT_COMMIT.h b/library/cpp/dbg_output/DONT_COMMIT.h index 0493d7e0941..e7b3182c206 100644 --- a/library/cpp/dbg_output/DONT_COMMIT.h +++ b/library/cpp/dbg_output/DONT_COMMIT.h @@ -1,9 +1,9 @@ -#pragma once - -// Including this file is possible without modifying PEERDIR (for debug purposes). -// The latter is allowed only locally, so this file is named -// in such a way that including it prevents from committing the #include via ARC-1205. - +#pragma once + +// Including this file is possible without modifying PEERDIR (for debug purposes). +// The latter is allowed only locally, so this file is named +// in such a way that including it prevents from committing the #include via ARC-1205. + #define DBGDUMP_INLINE_IF_INCLUDED inline #include "dump.cpp" @@ -12,5 +12,5 @@ #include <library/cpp/colorizer/colors.cpp> #include <library/cpp/colorizer/output.cpp> - + #undef DBGDUMP_INLINE_IF_INCLUDED diff --git a/library/cpp/dbg_output/auto.h b/library/cpp/dbg_output/auto.h index bfac869ae60..8d96167f6ac 100644 --- a/library/cpp/dbg_output/auto.h +++ b/library/cpp/dbg_output/auto.h @@ -1,15 +1,15 @@ -#pragma once - -#include <util/generic/va_args.h> - -// int a = 1, b = 2; Cout << LabeledDump(a, b, 1 + 2); yields {"a": 1, "b": 2, "1 + 2": 3} -#define LabeledDump(...) \ +#pragma once + +#include <util/generic/va_args.h> + +// int a = 1, b = 2; Cout << LabeledDump(a, b, 1 + 2); yields {"a": 1, "b": 2, "1 + 2": 3} +#define LabeledDump(...) \ '{' Y_PASS_VA_ARGS(Y_MAP_ARGS_WITH_LAST(__LABELED_DUMP_NONLAST__, __LABELED_DUMP_IMPL__, __VA_ARGS__)) << '}' -#define __LABELED_DUMP_IMPL__(x) << "\"" #x "\": " << DbgDump(x) -#define __LABELED_DUMP_NONLAST__(x) __LABELED_DUMP_IMPL__(x) << ", " - -// Usage: struct TMyStruct { int A, B; }; DEFINE_DUMPER(TMyStruct, A, B); Cout << TMyStruct{3, 4}; -// yields {"A": 3, "B": 4} +#define __LABELED_DUMP_IMPL__(x) << "\"" #x "\": " << DbgDump(x) +#define __LABELED_DUMP_NONLAST__(x) __LABELED_DUMP_IMPL__(x) << ", " + +// Usage: struct TMyStruct { int A, B; }; DEFINE_DUMPER(TMyStruct, A, B); Cout << TMyStruct{3, 4}; +// yields {"A": 3, "B": 4} #define DEFINE_DUMPER(C, ...) \ template <> \ struct TDumper<C> { \ @@ -17,6 +17,6 @@ static inline void Dump(S& s, const C& v) { \ s << DumpRaw("{") Y_PASS_VA_ARGS(Y_MAP_ARGS_WITH_LAST(__DEFINE_DUMPER_NONLAST__, __DEFINE_DUMPER_IMPL__, __VA_ARGS__)) << DumpRaw("}"); \ } \ - }; -#define __DEFINE_DUMPER_IMPL__(x) << DumpRaw("\"" #x "\": ") << v.x -#define __DEFINE_DUMPER_NONLAST__(x) __DEFINE_DUMPER_IMPL__(x) << DumpRaw(", ") + }; +#define __DEFINE_DUMPER_IMPL__(x) << DumpRaw("\"" #x "\": ") << v.x +#define __DEFINE_DUMPER_NONLAST__(x) __DEFINE_DUMPER_IMPL__(x) << DumpRaw(", ") diff --git a/library/cpp/dbg_output/colorscheme.h b/library/cpp/dbg_output/colorscheme.h index 1c2b12f00b1..a5b9cf749a8 100644 --- a/library/cpp/dbg_output/colorscheme.h +++ b/library/cpp/dbg_output/colorscheme.h @@ -1,17 +1,17 @@ -#pragma once - -#include "engine.h" +#pragma once + +#include "engine.h" #include <library/cpp/colorizer/output.h> - -#ifndef DBG_OUTPUT_DEFAULT_COLOR_SCHEME + +#ifndef DBG_OUTPUT_DEFAULT_COLOR_SCHEME #define DBG_OUTPUT_DEFAULT_COLOR_SCHEME NDbgDump::NColorScheme::TPlain -#endif - -#define DBG_OUTPUT_COLOR_HANDLER(NAME) \ +#endif + +#define DBG_OUTPUT_COLOR_HANDLER(NAME) \ template <class S> \ - inline void NAME(S& stream) - -namespace NDbgDump { + inline void NAME(S& stream) + +namespace NDbgDump { namespace NColorScheme { /// Start by copying this one if you want to define a custom color scheme. struct TPlain { @@ -28,7 +28,7 @@ namespace NDbgDump { DBG_OUTPUT_COLOR_HANDLER(ResetType) { Y_UNUSED(stream); } - + // Background color modifiers DBG_OUTPUT_COLOR_HANDLER(Key) { Y_UNUSED(stream); @@ -40,7 +40,7 @@ namespace NDbgDump { Y_UNUSED(stream); } }; - + /// Use this one if you want colors but are lazy enough to define a custom color scheme. /// Be careful enough to use DumpRaw for avoiding an endless recursion. /// Enforce controls whether colors should be applied even if stdout is not a TTY. @@ -51,8 +51,8 @@ namespace NDbgDump { if (Enforce) { Colors.Enable(); } - } - + } + // Foreground color modifiers DBG_OUTPUT_COLOR_HANDLER(Markup) { stream << DumpRaw(Colors.LightGreenColor()); @@ -66,35 +66,35 @@ namespace NDbgDump { DBG_OUTPUT_COLOR_HANDLER(ResetType) { stream << DumpRaw(Colors.OldColor()); } - + // Background color modifiers // TODO: support backgrounds in library/cpp/colorizer DBG_OUTPUT_COLOR_HANDLER(Key) { if (Depth++ == 0 && Colors.IsTTY()) { stream << DumpRaw(TStringBuf("\033[42m")); } - } + } DBG_OUTPUT_COLOR_HANDLER(Value) { if (Depth++ == 0 && Colors.IsTTY()) { stream << DumpRaw(TStringBuf("\033[44m")); } - } + } DBG_OUTPUT_COLOR_HANDLER(ResetRole) { if (--Depth == 0 && Colors.IsTTY()) { stream << DumpRaw(TStringBuf("\033[49m")); } - } - + } + private: NColorizer::TColors Colors; size_t Depth = 0; }; } } - -namespace NPrivate { - template <typename CS> - struct TColorSchemeContainer { - CS ColorScheme; - }; -} + +namespace NPrivate { + template <typename CS> + struct TColorSchemeContainer { + CS ColorScheme; + }; +} diff --git a/library/cpp/dbg_output/dump.h b/library/cpp/dbg_output/dump.h index bb64ca36d51..c7efa105ee6 100644 --- a/library/cpp/dbg_output/dump.h +++ b/library/cpp/dbg_output/dump.h @@ -2,8 +2,8 @@ #include "engine.h" #include "dumpers.h" -#include "auto.h" -#include "colorscheme.h" +#include "auto.h" +#include "colorscheme.h" #include <util/stream/format.h> #include <util/system/type_name.h> @@ -21,7 +21,7 @@ namespace NPrivate { template <class TColorScheme> struct TTraitsShallow { - struct TDump: public TDumpBase, public TColorSchemeContainer<TColorScheme> { + struct TDump: public TDumpBase, public TColorSchemeContainer<TColorScheme> { template <typename... Args> inline TDump(Args&&... args) : TDumpBase(std::forward<Args>(args)...) @@ -41,7 +41,7 @@ namespace NPrivate { template <class TColorScheme> struct TTraitsDeep { - struct TDump: public TDumpBase, public TColorSchemeContainer<TColorScheme> { + struct TDump: public TDumpBase, public TColorSchemeContainer<TColorScheme> { template <typename... Args> inline TDump(Args&&... args) : TDumpBase(std::forward<Args>(args)...) @@ -95,12 +95,12 @@ namespace NPrivate { } } -template <class T, class TColorScheme = DBG_OUTPUT_DEFAULT_COLOR_SCHEME> -static inline ::NPrivate::TDbgDump<T, ::NPrivate::TTraitsShallow<TColorScheme>> DbgDump(const T& t) { +template <class T, class TColorScheme = DBG_OUTPUT_DEFAULT_COLOR_SCHEME> +static inline ::NPrivate::TDbgDump<T, ::NPrivate::TTraitsShallow<TColorScheme>> DbgDump(const T& t) { return {std::addressof(t)}; } -template <class T, class TColorScheme = DBG_OUTPUT_DEFAULT_COLOR_SCHEME> -static inline ::NPrivate::TDbgDump<T, ::NPrivate::TTraitsDeep<TColorScheme>> DbgDumpDeep(const T& t) { +template <class T, class TColorScheme = DBG_OUTPUT_DEFAULT_COLOR_SCHEME> +static inline ::NPrivate::TDbgDump<T, ::NPrivate::TTraitsDeep<TColorScheme>> DbgDumpDeep(const T& t) { return {std::addressof(t)}; } diff --git a/library/cpp/dbg_output/dumpers.h b/library/cpp/dbg_output/dumpers.h index 43a21c208eb..4868e97da07 100644 --- a/library/cpp/dbg_output/dumpers.h +++ b/library/cpp/dbg_output/dumpers.h @@ -74,18 +74,18 @@ template <class A, class B> struct TDumper<std::pair<A, B>> { template <class S> static inline void Dump(S& s, const std::pair<A, B>& v) { - s.ColorScheme.Key(s); - s.ColorScheme.Literal(s); - s << v.first; - s.ColorScheme.ResetType(s); - s.ColorScheme.ResetRole(s); - s.ColorScheme.Markup(s); - s << DumpRaw(" -> "); - s.ColorScheme.Value(s); - s.ColorScheme.Literal(s); - s << v.second; - s.ColorScheme.ResetType(s); - s.ColorScheme.ResetRole(s); + s.ColorScheme.Key(s); + s.ColorScheme.Literal(s); + s << v.first; + s.ColorScheme.ResetType(s); + s.ColorScheme.ResetRole(s); + s.ColorScheme.Markup(s); + s << DumpRaw(" -> "); + s.ColorScheme.Value(s); + s.ColorScheme.Literal(s); + s << v.second; + s.ColorScheme.ResetType(s); + s.ColorScheme.ResetRole(s); } }; diff --git a/library/cpp/dbg_output/engine.h b/library/cpp/dbg_output/engine.h index 140a766952d..f13c728c391 100644 --- a/library/cpp/dbg_output/engine.h +++ b/library/cpp/dbg_output/engine.h @@ -76,10 +76,10 @@ struct TRawLiteral { template <class TChar> static inline TRawLiteral<TChar> DumpRaw(const TBasicStringBuf<TChar>& s) noexcept { - return {s}; -} - -template <class TChar> + return {s}; +} + +template <class TChar> static inline TRawLiteral<TChar> DumpRaw(const TChar* s) noexcept { return {s}; } @@ -130,7 +130,7 @@ struct TCharDumper { template <class S, class V> static inline void OutSequence(S& s, const V& v, const char* openTag, const char* closeTag) { - s.ColorScheme.Markup(s); + s.ColorScheme.Markup(s); s << DumpRaw(openTag); { @@ -139,21 +139,21 @@ static inline void OutSequence(S& s, const V& v, const char* openTag, const char for (const auto& x : v) { if (cnt) { - s.ColorScheme.Markup(s); + s.ColorScheme.Markup(s); s << DumpRaw(", "); } - s << IndentNewLine(); - s.ColorScheme.Literal(s); - s << x; + s << IndentNewLine(); + s.ColorScheme.Literal(s); + s << x; ++cnt; } } - s << IndentNewLine(); - s.ColorScheme.Markup(s); - s << DumpRaw(closeTag); - s.ColorScheme.ResetType(s); + s << IndentNewLine(); + s.ColorScheme.Markup(s); + s << DumpRaw(closeTag); + s.ColorScheme.ResetType(s); } struct TAssocDumper { @@ -173,8 +173,8 @@ struct TSeqDumper { struct TStrDumper { template <class S, class V> static inline void Dump(S& s, const V& v) { - s.ColorScheme.String(s); + s.ColorScheme.String(s); s.String(v); - s.ColorScheme.ResetType(s); + s.ColorScheme.ResetType(s); } }; diff --git a/library/cpp/dbg_output/ut/dbg_output_ut.cpp b/library/cpp/dbg_output/ut/dbg_output_ut.cpp index 7839504bcef..7b285c84cb7 100644 --- a/library/cpp/dbg_output/ut/dbg_output_ut.cpp +++ b/library/cpp/dbg_output/ut/dbg_output_ut.cpp @@ -1,17 +1,17 @@ #include <library/cpp/dbg_output/dump.h> #include <library/cpp/testing/unittest/registar.h> - -#include <util/stream/str.h> + +#include <util/stream/str.h> #include <util/string/builder.h> -#include <util/string/escape.h> +#include <util/string/escape.h> #include <util/generic/map.h> - + namespace { struct TX { inline TX() { N = this; } - + TX* N; }; } @@ -24,22 +24,22 @@ struct TDumper<TX> { } }; -namespace TMyNS { - struct TMyStruct { - int A, B; - }; -} -DEFINE_DUMPER(TMyNS::TMyStruct, A, B) - +namespace TMyNS { + struct TMyStruct { + int A, B; + }; +} +DEFINE_DUMPER(TMyNS::TMyStruct, A, B) + Y_UNIT_TEST_SUITE(TContainerPrintersTest) { Y_UNIT_TEST(TestVectorInt) { - TStringStream out; + TStringStream out; out << DbgDump(TVector<int>({1, 2, 3, 4, 5})); UNIT_ASSERT_STRINGS_EQUAL(out.Str(), "[1, 2, 3, 4, 5]"); - } - + } + Y_UNIT_TEST(TestMapCharToCharArray) { - TStringStream out; + TStringStream out; TMap<char, const char*> m; @@ -49,51 +49,51 @@ Y_UNIT_TEST_SUITE(TContainerPrintersTest) { out << DbgDump(m); UNIT_ASSERT_STRINGS_EQUAL(out.Str(), "{'a' -> \"SMALL LETTER A\", 'b' -> (empty)}"); - } - + } + Y_UNIT_TEST(TestVectorOfVectors) { - TStringStream out; + TStringStream out; TVector<TVector<wchar16>> vec(2); - vec[0].push_back(0); + vec[0].push_back(0); vec[1] = {wchar16('a')}; out << DbgDump(vec); UNIT_ASSERT_STRINGS_EQUAL(out.Str(), "[[w'\\0'], [w'a']]"); - } + } Y_UNIT_TEST(TestInfinite) { UNIT_ASSERT(!!(TStringBuilder() << DbgDumpDeep(TX()))); } - + Y_UNIT_TEST(TestLabeledDump) { - TStringStream out; - int a = 1, b = 2; - out << LabeledDump(a, b, 1 + 2); + TStringStream out; + int a = 1, b = 2; + out << LabeledDump(a, b, 1 + 2); UNIT_ASSERT_STRINGS_EQUAL(out.Str(), "{\"a\": 1, \"b\": 2, \"1 + 2\": 3}"); - } - + } + Y_UNIT_TEST(TestStructDumper) { - TStringStream out; - out << DbgDump(TMyNS::TMyStruct{3, 4}); + TStringStream out; + out << DbgDump(TMyNS::TMyStruct{3, 4}); UNIT_ASSERT_STRINGS_EQUAL(out.Str(), "{\"A\": 3, \"B\": 4}"); - } - + } + Y_UNIT_TEST(TestColors) { using TComplex = TMap<TString, TMap<int, char>>; - TComplex test; - test["a"][1] = '7'; - test["b"][2] = '6'; - TStringStream out; - out << DbgDump<TComplex, NDbgDump::NColorScheme::TEyebleed</* Enforce = */ true>>(test); - UNIT_ASSERT_STRINGS_EQUAL( - EscapeC(out.Str()), - "\\x1B[1;32m{\\x1B[1;31m\\x1B[42m\\x1B[1;31m\\x1B[1;33m\\\"a\\\"\\x1B[22;39m\\x1B[22;39m" - "\\x1B[49m\\x1B[1;32m -> \\x1B[44m\\x1B[1;31m\\x1B[1;32m{\\x1B[1;31m\\x1B[1;31m1" - "\\x1B[22;39m\\x1B[1;32m -> \\x1B[1;31m'7'\\x1B[22;39m\\x1B[1;32m}" - "\\x1B[22;39m\\x1B[22;39m\\x1B[49m\\x1B[1;32m, \\x1B[1;31m\\x1B[42m\\x1B[1;31m\\x1B[1;33m" - "\\\"b\\\"\\x1B[22;39m\\x1B[22;39m\\x1B[49m\\x1B[1;32m -> " - "\\x1B[44m\\x1B[1;31m\\x1B[1;32m{\\x1B[1;31m\\x1B[1;31m2\\x1B[22;39m\\x1B[1;32m -> " + TComplex test; + test["a"][1] = '7'; + test["b"][2] = '6'; + TStringStream out; + out << DbgDump<TComplex, NDbgDump::NColorScheme::TEyebleed</* Enforce = */ true>>(test); + UNIT_ASSERT_STRINGS_EQUAL( + EscapeC(out.Str()), + "\\x1B[1;32m{\\x1B[1;31m\\x1B[42m\\x1B[1;31m\\x1B[1;33m\\\"a\\\"\\x1B[22;39m\\x1B[22;39m" + "\\x1B[49m\\x1B[1;32m -> \\x1B[44m\\x1B[1;31m\\x1B[1;32m{\\x1B[1;31m\\x1B[1;31m1" + "\\x1B[22;39m\\x1B[1;32m -> \\x1B[1;31m'7'\\x1B[22;39m\\x1B[1;32m}" + "\\x1B[22;39m\\x1B[22;39m\\x1B[49m\\x1B[1;32m, \\x1B[1;31m\\x1B[42m\\x1B[1;31m\\x1B[1;33m" + "\\\"b\\\"\\x1B[22;39m\\x1B[22;39m\\x1B[49m\\x1B[1;32m -> " + "\\x1B[44m\\x1B[1;31m\\x1B[1;32m{\\x1B[1;31m\\x1B[1;31m2\\x1B[22;39m\\x1B[1;32m -> " "\\x1B[1;31m'6'\\x1B[22;39m\\x1B[1;32m}\\x1B[22;39m\\x1B[22;39m\\x1B[49m\\x1B[1;32m}\\x1B[22;39m"); - } + } Y_UNIT_TEST(SmallIntOrChar) { char c = 'e'; @@ -103,4 +103,4 @@ Y_UNIT_TEST_SUITE(TContainerPrintersTest) { UNIT_ASSERT_VALUES_EQUAL(TStringBuilder() << DbgDump(i), "-100"); UNIT_ASSERT_VALUES_EQUAL(TStringBuilder() << DbgDump(u), "10"); } -} +} diff --git a/library/cpp/dbg_output/ut/ya.make b/library/cpp/dbg_output/ut/ya.make index 77a8f389763..201601295da 100644 --- a/library/cpp/dbg_output/ut/ya.make +++ b/library/cpp/dbg_output/ut/ya.make @@ -1,9 +1,9 @@ UNITTEST_FOR(library/cpp/dbg_output) - + OWNER(pg) - -SRCS( - dbg_output_ut.cpp -) - -END() + +SRCS( + dbg_output_ut.cpp +) + +END() diff --git a/library/cpp/dbg_output/ya.make b/library/cpp/dbg_output/ya.make index f8f75fa3305..7d54108f93d 100644 --- a/library/cpp/dbg_output/ya.make +++ b/library/cpp/dbg_output/ya.make @@ -2,10 +2,10 @@ LIBRARY() OWNER(pg) -PEERDIR( +PEERDIR( library/cpp/colorizer -) - +) + SRCS( dump.cpp dumpers.cpp |