diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /tools/enum_parser/parse_enum/parse_enum.h | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'tools/enum_parser/parse_enum/parse_enum.h')
-rw-r--r-- | tools/enum_parser/parse_enum/parse_enum.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tools/enum_parser/parse_enum/parse_enum.h b/tools/enum_parser/parse_enum/parse_enum.h new file mode 100644 index 0000000000..ef8b512ae4 --- /dev/null +++ b/tools/enum_parser/parse_enum/parse_enum.h @@ -0,0 +1,78 @@ +#pragma once + +#include <util/stream/output.h> +#include <util/stream/input.h> +#include <util/stream/mem.h> +#include <util/string/strip.h> +#include <util/generic/maybe.h> +#include <util/generic/string.h> +#include <util/generic/vector.h> + +class TEnumParser { +public: + + struct TItem { + TMaybe<TString> Value; + TString CppName; + TVector<TString> Aliases; + TString CommentText; + + void Clear() { + *this = TItem(); + } + + void NormalizeValue() { + if (!Value) + return; + StripInPlace(*Value); + } + + }; + + // vector is to preserve declaration order + typedef TVector<TItem> TItems; + + typedef TVector<TString> TScope; + + struct TEnum { + TItems Items; + TString CppName; + TScope Scope; + // enum or enum class + bool EnumClass = false; + bool BodyDetected = false; + bool ForwardDeclaration = false; + + void Clear() { + *this = TEnum(); + } + }; + + typedef TVector<TEnum> TEnums; + + /// Parse results stored here + TEnums Enums; + + /// Parse enums from file containing C++ code + TEnumParser(const TString& fileName); + + /// Parse enums from memory buffer containing C++ code + TEnumParser(const char* data, size_t length); + + /// Parse enums from input stream + TEnumParser(IInputStream& in); + + static TString ScopeStr(const TScope& scope) { + TString result; + for (const TString& name : scope) { + result += name; + result += "::"; + } + return result; + } + +private: + void Parse(const char* data, size_t length); +protected: + TString SourceFileName; +}; |