diff options
| author | mikhnenko <[email protected]> | 2024-06-25 08:50:35 +0300 |
|---|---|---|
| committer | mikhnenko <[email protected]> | 2024-06-25 09:00:27 +0300 |
| commit | 509c9fc9e7b9c3b8be7307d72a4c966e5f9aa194 (patch) | |
| tree | 4b8a6a44009906ac852e59efa0bc78bb12043a5b /contrib/libs/protoc/src/google/protobuf/compiler/cpp/cpp_helpers.h | |
| parent | 7688f2313619a39a60ef3c2734d8efbc49a0a6db (diff) | |
Update protobuf to 3.20.2 and pyprotobuf to 3.20.3
Если это pull-request что-то сломал, то:
- если это тест с канонизацией и еще нет pr с переканонизацией, то переканонизируйте пожалуйста сами
- проверьте, что тест не флапает
- приходите в [DEVTOOLSSUPPORT](https://st.yandex-team.ru/createTicket?queue=DEVTOOLSSUPPORT) - там вам обязательно помогут
987be5ed151f827f7f292f32420470b04b71a91d
Diffstat (limited to 'contrib/libs/protoc/src/google/protobuf/compiler/cpp/cpp_helpers.h')
| -rw-r--r-- | contrib/libs/protoc/src/google/protobuf/compiler/cpp/cpp_helpers.h | 64 |
1 files changed, 59 insertions, 5 deletions
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/cpp/cpp_helpers.h b/contrib/libs/protoc/src/google/protobuf/compiler/cpp/cpp_helpers.h index ceb9a54f389..f7735da12f0 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/cpp/cpp_helpers.h +++ b/contrib/libs/protoc/src/google/protobuf/compiler/cpp/cpp_helpers.h @@ -41,10 +41,10 @@ #include <map> #include <string> -#include <google/protobuf/compiler/cpp/cpp_options.h> -#include <google/protobuf/compiler/cpp/cpp_names.h> #include <google/protobuf/compiler/scc.h> #include <google/protobuf/compiler/code_generator.h> +#include <google/protobuf/compiler/cpp/cpp_names.h> +#include <google/protobuf/compiler/cpp/cpp_options.h> #include <google/protobuf/descriptor.pb.h> #include <google/protobuf/io/printer.h> #include <google/protobuf/descriptor.h> @@ -59,6 +59,8 @@ namespace protobuf { namespace compiler { namespace cpp { +enum class ArenaDtorNeeds { kNone = 0, kOnDemand = 1, kRequired = 2 }; + inline TProtoStringType ProtobufNamespace(const Options& /* options */) { return "PROTOBUF_NAMESPACE_ID"; } @@ -85,6 +87,10 @@ extern const char kThinSeparator[]; void SetCommonVars(const Options& options, std::map<TProtoStringType, TProtoStringType>* variables); +// Variables to access message data from the message scope. +void SetCommonMessageDataVariables( + std::map<TProtoStringType, TProtoStringType>* variables); + void SetUnknownFieldsVariable(const Descriptor* descriptor, const Options& options, std::map<TProtoStringType, TProtoStringType>* variables); @@ -186,6 +192,9 @@ TProtoStringType ResolveKeyword(const TProtoStringType& name); // anyway, so normally this just returns field->name(). TProtoStringType FieldName(const FieldDescriptor* field); +// Returns the (unqualified) private member name for this field in C++ code. +TProtoStringType FieldMemberName(const FieldDescriptor* field); + // Returns an estimate of the compiler's alignment for the field. This // can't guarantee to be correct because the generated code could be compiled on // different systems with different alignment rules. The estimates below assume @@ -348,9 +357,16 @@ bool HasLazyFields(const FileDescriptor* file, const Options& options, bool IsLazy(const FieldDescriptor* field, const Options& options, MessageSCCAnalyzer* scc_analyzer); +// Is this an explicit (non-profile driven) lazy field, as denoted by +// lazy/unverified_lazy in the descriptor? +inline bool IsExplicitLazy(const FieldDescriptor* field) { + return field->options().lazy() || field->options().unverified_lazy(); +} + inline bool IsLazilyVerifiedLazy(const FieldDescriptor* field, const Options& options) { - return field->options().lazy() && !field->is_repeated() && + // TODO(b/211906113): Make lazy() imply eagerly verified lazy. + return IsExplicitLazy(field) && !field->is_repeated() && field->type() == FieldDescriptor::TYPE_MESSAGE && GetOptimizeFor(field->file(), options) != FileOptions::LITE_RUNTIME && !options.opensource_runtime; @@ -359,7 +375,8 @@ inline bool IsLazilyVerifiedLazy(const FieldDescriptor* field, inline bool IsEagerlyVerifiedLazy(const FieldDescriptor* field, const Options& options, MessageSCCAnalyzer* scc_analyzer) { - return IsLazy(field, options, scc_analyzer) && !field->options().lazy(); + // TODO(b/211906113): Make lazy() imply eagerly verified lazy. + return IsLazy(field, options, scc_analyzer) && !IsExplicitLazy(field); } inline bool IsFieldUsed(const FieldDescriptor* /* field */, @@ -472,6 +489,43 @@ inline TProtoStringType MakeDefaultName(const FieldDescriptor* field) { "_"; } +// Semantically distinct from MakeDefaultName in that it gives the C++ code +// referencing a default field from the message scope, rather than just the +// variable name. +// For example, declarations of default variables should always use just +// MakeDefaultName to produce code like: +// Type _i_give_permission_to_break_this_code_default_field_; +// +// Code that references these should use MakeDefaultFieldName, in case the field +// exists at some nested level like: +// internal_container_._i_give_permission_to_break_this_code_default_field_; +inline TProtoStringType MakeDefaultFieldName(const FieldDescriptor* field) { + return MakeDefaultName(field); +} + +inline TProtoStringType MakeVarintCachedSizeName(const FieldDescriptor* field) { + return StrCat("_", FieldName(field), "_cached_byte_size_"); +} + +// Semantically distinct from MakeVarintCachedSizeName in that it gives the C++ +// code referencing the object from the message scope, rather than just the +// variable name. +// For example, declarations of default variables should always use just +// MakeVarintCachedSizeName to produce code like: +// Type _field_cached_byte_size_; +// +// Code that references these variables should use +// MakeVarintCachedSizeFieldName, in case the field exists at some nested level +// like: +// internal_container_._field_cached_byte_size_; +inline TProtoStringType MakeVarintCachedSizeFieldName(const FieldDescriptor* field) { + return StrCat("_", FieldName(field), "_cached_byte_size_"); +} + +// Note: A lot of libraries detect Any protos based on Descriptor::full_name() +// while the two functions below use FileDescriptor::name(). In a sane world the +// two approaches should be equivalent. But if you are dealing with descriptors +// from untrusted sources, you might need to match semantics across libraries. bool IsAnyMessage(const FileDescriptor* descriptor, const Options& options); bool IsAnyMessage(const Descriptor* descriptor, const Options& options); @@ -956,7 +1010,7 @@ inline OneOfRangeImpl OneOfRange(const Descriptor* desc) { return {desc}; } PROTOC_EXPORT TProtoStringType StripProto(const TProtoStringType& filename); -bool EnableMessageOwnedArena(const Descriptor* desc); +bool EnableMessageOwnedArena(const Descriptor* desc, const Options& options); bool ShouldVerify(const Descriptor* descriptor, const Options& options, MessageSCCAnalyzer* scc_analyzer); |
