Go to the documentation of this file.
35 #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_HELPERS_H__
36 #define GOOGLE_PROTOBUF_COMPILER_CPP_HELPERS_H__
44 #include <google/protobuf/compiler/cpp/cpp_options.h>
46 #include <google/protobuf/compiler/scc.h>
47 #include <google/protobuf/compiler/code_generator.h>
48 #include <google/protobuf/descriptor.pb.h>
49 #include <google/protobuf/io/printer.h>
50 #include <google/protobuf/descriptor.h>
51 #include <google/protobuf/port.h>
52 #include <google/protobuf/stubs/strutil.h>
55 #include <google/protobuf/port_def.inc>
63 return "PROTOBUF_NAMESPACE_ID";
67 return "GOOGLE_PROTOBUF";
72 return d->options().deprecated() ?
"PROTOBUF_DEPRECATED " :
"";
77 return d->options().deprecated() ?
"PROTOBUF_DEPRECATED_ENUM " :
"";
86 std::map<std::string, std::string>* variables);
90 std::map<std::string, std::string>* variables);
202 return field->is_extension() ?
field->extension_scope()
203 :
field->containing_type();
258 options.opensource_runtime =
false;
311 if (
field->options().weak()) {
341 class MessageSCCAnalyzer;
345 MessageSCCAnalyzer* scc_analyzer);
349 MessageSCCAnalyzer* scc_analyzer);
353 return field->options().lazy() && !
field->is_repeated() &&
415 return file->service_count() > 0 &&
417 file->options().cc_generic_services();
422 return !
options.opensource_runtime &&
424 !
options.lite_implicit_weak_fields &&
425 descriptor->options().message_set_wire_format() &&
426 descriptor->full_name() ==
"google.protobuf.bridge.MessageSet";
437 bool cap_next_letter);
455 return (
field->has_optional_keyword() ||
field->is_required()) &&
456 !
field->options().weak();
467 field->message_type()->file() !=
field->file();
471 return "_i_give_permission_to_break_this_code_default_" +
FieldName(
field) +
500 return "GOOGLE_PROTOBUF_INCLUDED_" + filename_identifier;
510 bool* has_opt_codesize_extension);
517 bool has_opt_codesize_extension;
520 has_opt_codesize_extension) {
535 std::vector<const Descriptor*>*
result);
538 std::vector<const Descriptor*>
result;
543 template <
typename F>
550 template <
typename F>
567 struct MessageAnalysis {
587 return result.contains_required ||
result.contains_extension;
591 return result.contains_weak;
598 struct DepsGenerator {
600 std::vector<const Descriptor*>
deps;
601 for (
int i = 0;
i <
desc->field_count();
i++) {
602 if (
desc->field(
i)->message_type()) {
603 deps.push_back(
desc->field(
i)->message_type());
611 std::map<const SCC*, MessageAnalysis> analysis_cache_;
615 std::vector<const FieldDescriptor*>*
fields);
617 std::vector<const FieldDescriptor*>*
fields);
621 for (
int i = 0;
i < d->nested_type_count();
i++) {
624 for (
int i = 0;
i < d->extension_count();
i++) {
625 func(d->extension(i));
627 for (
int i = 0;
i < d->field_count();
i++) {
634 for (
int i = 0;
i <
d->message_type_count();
i++) {
637 for (
int i = 0;
i <
d->extension_count();
i++) {
638 func(
d->extension(i));
643 std::vector<const Descriptor*>*
types);
651 MessageSCCAnalyzer* scc_analyzer);
655 if (
desc->extension_range_count() != 0)
return false;
656 if (
desc->field_count() == 0)
return true;
674 if (
desc->extension_range_count() != 0)
return "";
675 if (
desc->field_count() == 0) {
676 return "ZeroFieldsBase";
725 const std::map<std::string, std::string>& vars)
728 template <
typename T>
733 void AddMap(
const std::map<std::string, std::string>& vars) {
734 for (
const auto& keyval : vars) vars_[keyval.first] = keyval.second;
737 template <
typename...
Args>
760 template <
typename...
Args>
767 class PROTOC_EXPORT SaveState {
775 std::map<std::string, std::string> vars_;
780 std::map<std::string, std::string> vars_;
784 template <
typename I,
typename =
typename std::enable_if<
798 template <
typename Descriptor>
800 std::vector<int>
path;
807 return annotation.SerializeAsString();
817 options.elide_group_body =
true;
818 options.elide_oneof_body =
true;
820 format(
"// $1$\n",
def.substr(0,
def.find_first_of(
'\n')));
823 class PROTOC_EXPORT NamespaceOpener {
834 std::vector<std::string> new_stack_ =
836 size_t len =
std::min(name_stack_.size(), new_stack_.size());
837 size_t common_idx = 0;
838 while (common_idx <
len) {
839 if (name_stack_[common_idx] != new_stack_[common_idx])
break;
842 for (
auto it = name_stack_.crbegin();
843 it != name_stack_.crend() - common_idx; ++
it) {
844 if (*
it ==
"PROTOBUF_NAMESPACE_ID") {
850 name_stack_.swap(new_stack_);
851 for (
size_t i = common_idx;
i < name_stack_.size(); ++
i) {
852 if (name_stack_[
i] ==
"PROTOBUF_NAMESPACE_ID") {
862 std::vector<std::string> name_stack_;
875 const Options&
options,
bool for_parse,
880 const Options&
options,
bool for_parse,
884 template <
typename T>
885 struct FieldRangeImpl {
895 return a.idx ==
b.idx;
916 template <
typename T>
921 struct OneOfRangeImpl {
931 return a.idx ==
b.idx;
961 MessageSCCAnalyzer* scc_analyzer);
963 MessageSCCAnalyzer* scc_analyzer);
969 #include <google/protobuf/port_undef.inc>
971 #endif // GOOGLE_PROTOBUF_COMPILER_CPP_HELPERS_H__
bool IsBootstrapProto(const Options &options, const FileDescriptor *file)
static _upb_DefPool_Init * deps[4]
bool IsAnyMessage(const FileDescriptor *descriptor, const Options &options)
bool IsProto3(const FileDescriptor *file)
bool HasGeneratedMethods(const FileDescriptor *file, const Options &options)
const Descriptor::ReservedRange value
std::string DefaultInstancePtr(const Descriptor *descriptor, const Options &options)
bool IsStringOrMessage(const FieldDescriptor *field)
NamespaceOpener(const Formatter &format)
bool IsCord(const FieldDescriptor *field, const Options &options)
bool HasHasbit(const FieldDescriptor *field)
std::string FieldName(const FieldDescriptor *field)
std::string ProtobufNamespace(const Options &options)
std::string StripProto(const std::string &filename)
int real_oneof_decl_count() const
virtual void Print(const std::map< std::string, std::string > &vars, const char *template_string)=0
NamespaceOpener(const std::string &name, const Formatter &format)
bool IsFieldUsed(const FieldDescriptor *, const Options &)
def parameters(*testcases)
std::string FieldConstantName(const FieldDescriptor *field)
void ForEachMessage(const Descriptor *descriptor, F &&func)
static bool HasEnumDefinitions(const Descriptor *message_type)
static bool HasLazyFields(const Descriptor *descriptor, const Options &options)
const Descriptor * FieldScope(const FieldDescriptor *field)
std::string QualifiedClassName(const Descriptor *d, const Options &options)
void add_path(::PROTOBUF_NAMESPACE_ID::int32 value)
void set_source_file(const std::string &value)
bool IsStringInlined(const FieldDescriptor *descriptor, const Options &options)
bool HasPreservingUnknownEnumSemantics(const FieldDescriptor *field)
std::string SuperClassName(const Descriptor *descriptor, const Options &options)
int EstimateAlignmentSize(const FieldDescriptor *field)
std::string MakeDefaultName(const FieldDescriptor *field)
friend bool operator!=(const Iterator &a, const Iterator &b)
void SetUnknownFieldsVariable(const Descriptor *descriptor, const Options &options, std::map< std::string, std::string > *variables)
string UniqueName(const std::string &name, const std::string &filename, const Options &options)
FileOptions_OptimizeMode GetOptimizeFor(const FileDescriptor *file, const Options &options)
#define T(upbtypeconst, upbtype, ctype, default_value)
string StrCat(const AlphaNum &a, const AlphaNum &b)
const char * DeclaredTypeMethodName(FieldDescriptor::Type type)
static constexpr CType CORD
static bool HasMapFields(const Descriptor *descriptor)
void FlattenMessagesInFile(const FileDescriptor *file, std::vector< const Descriptor * > *result)
bool IsWeak(const FieldDescriptor *field, const Options &options)
bool HasWeakFields(const Descriptor *descriptor, const Options &options)
void GenerateUtf8CheckCodeForString(const FieldDescriptor *field, const Options &options, bool for_parse, const char *parameters, const Formatter &format)
std::string FileDllExport(const FileDescriptor *file, const Options &options)
std::forward_iterator_tag iterator_category
static bool HasStringPieceFields(const Descriptor *descriptor, const Options &options)
bool UsingImplicitWeakFields(const FileDescriptor *file, const Options &options)
bool HasSimpleBaseClasses(const FileDescriptor *file, const Options &options)
std::string ExtensionName(const FieldDescriptor *d)
bool HasWeakField(const Descriptor *descriptor)
std::string ToString(const grpc::string_ref &r)
std::string SafeFunctionName(const Descriptor *descriptor, const FieldDescriptor *field, const std::string &prefix)
std::string QualifiedDefaultInstancePtr(const Descriptor *descriptor, const Options &options)
friend bool operator!=(const Iterator &a, const Iterator &b)
FieldOptions::CType EffectiveStringCType(const FieldDescriptor *field, const Options &options)
std::string SimpleBaseClass(const Descriptor *desc, const Options &options)
bool IsLazy(const FieldDescriptor *field, const Options &options)
bool IsLazilyVerifiedLazy(const FieldDescriptor *field, const Options &options)
const Descriptor * descriptor
std::string ResolveKeyword(const string &name)
bool IsImplicitWeakField(const FieldDescriptor *field, const Options &options, MessageSCCAnalyzer *scc_analyzer)
const OneofDescriptor * oneof_decl(int index) const
std::string QualifiedFileLevelSymbol(const FileDescriptor *file, const std::string &name, const Options &options)
bool IsMapEntryMessage(const Descriptor *descriptor)
grpc_generator::Printer * printer_
int def(FILE *source, FILE *dest, int level)
std::string FieldMessageTypeName(const FieldDescriptor *field, const Options &options)
OneOfRangeImpl OneOfRange(const Descriptor *desc)
static constexpr OptimizeMode LITE_RUNTIME
std::forward_iterator_tag iterator_category
std::string DefaultInstanceType(const Descriptor *descriptor, const Options &options)
void ChangeTo(const std::string &name)
std::string DescriptorTableName(const FileDescriptor *file, const Options &options)
bool IsStringPiece(const FieldDescriptor *field, const Options &options)
static constexpr CType STRING_PIECE
std::string DefaultValue(const FieldDescriptor *field)
std::string DeprecatedAttribute(const Options &options, bool deprecated)
bool UseUnknownFieldSet(const FileDescriptor *file, const Options &options)
void SetCommonVars(const Options &options, std::map< std::string, std::string > *variables)
bool GetBootstrapBasename(const Options &options, const std::string &basename, std::string *bootstrap_basename)
friend bool operator==(const Iterator &a, const Iterator &b)
std::string IncludeGuard(const FileDescriptor *file, bool pb_h, const Options &options)
Options InternalRuntimeOptions()
std::string QualifiedDefaultInstanceName(const Descriptor *descriptor, const Options &options)
bool IsCrossFileMessage(const FieldDescriptor *field)
bool HasDescriptorMethods(const FileDescriptor *file, const Options &options)
void ListAllFields(const Descriptor *d, std::vector< const FieldDescriptor * > *fields)
MessageSCCAnalyzer(const Options &options)
static constexpr CType STRING
bool NeedsEagerDescriptorAssignment(const FileDescriptor *file, const Options &options)
FieldRangeImpl< T > FieldRange(const T *desc)
static bool HasCordFields(const Descriptor *descriptor, const Options &options)
const char kThickSeparator[]
std::string Int32ToString(int number)
bool HasRequiredFields(const Descriptor *descriptor)
void PrintFieldComment(const Formatter &format, const T *field)
std::string Namespace(const std::string &package)
bool IsWellKnownMessage(const FileDescriptor *file)
std::vector< const Descriptor * > operator()(const Descriptor *desc) const
const FieldDescriptor * field
DebugStringOptions options_
bool HasGenericServices(const FileDescriptor *file, const Options &options)
bool EnableMessageOwnedArena(const Descriptor *desc)
const SCC * GetSCC(const Descriptor *descriptor)
bool IsString(const FieldDescriptor *field, const Options &options)
std::string FilenameIdentifier(const std::string &filename)
std::string DefaultInstanceName(const Descriptor *descriptor, const Options &options)
bool IsFieldStripped(const FieldDescriptor *, const Options &)
void GenerateUtf8CheckCodeForCord(const FieldDescriptor *field, const Options &options, bool for_parse, const char *parameters, const Formatter &format)
static bool HasExtensionsOrExtendableMessage(const Descriptor *descriptor)
std::string EscapeTrigraphs(const std::string &to_escape)
std::string QualifiedExtensionName(const FieldDescriptor *d, const Options &options)
static const char prefix[]
std::vector< string > Split(const string &full, const char *delim, bool skip_empty=true)
std::string ClassName(const Descriptor *descriptor)
static bool HasRepeatedFields(const Descriptor *descriptor)
#define GOOGLE_CHECK(EXPRESSION)
bool HasSimpleBaseClass(const Descriptor *desc, const Options &options)
static const struct nv types[]
std::string UnderscoresToCamelCase(const std::string &input, bool cap_next_letter)
const char * PrimitiveTypeName(FieldDescriptor::CppType type)
void ForEachField(const Descriptor *d, T &&func)
void ListAllTypesForServices(const FileDescriptor *fd, std::vector< const Descriptor * > *types)
static bool ShouldIgnoreRequiredFieldCheck(const FieldDescriptor *field, const Options &options)
static Utf8CheckMode GetUtf8CheckMode(const FieldDescriptor *field, const Options &options)
bool PublicUnknownFieldsAccessors(const Descriptor *message)
std::string MacroPrefix(const Options &options)
bool IsProto2MessageSet(const Descriptor *descriptor, const Options &options)
const char kThinSeparator[]
VALUE enum_descriptor(VALUE self)
bool ShouldVerify(const Descriptor *descriptor, const Options &options, MessageSCCAnalyzer *scc_analyzer)
static const char descriptor[1336]
GRPC_CUSTOM_SERVICEDESCRIPTOR ServiceDescriptor
bool CanInitializeByZeroing(const FieldDescriptor *field)
static constexpr OptimizeMode CODE_SIZE
const Descriptor * descriptor
friend bool operator==(const Iterator &a, const Iterator &b)
bool MaybeBootstrap(const Options &options, GeneratorContext *generator_context, bool bootstrap_flag, std::string *basename)
bool IsEagerlyVerifiedLazy(const FieldDescriptor *field, const Options &options, MessageSCCAnalyzer *scc_analyzer)
grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:05