Group PDProto related helper code.

PiperOrigin-RevId: 544945349
pull/13197/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent 93b5905c89
commit fa4f15e320
  1. 63
      src/google/protobuf/compiler/cpp/helpers.cc
  2. 65
      src/google/protobuf/compiler/cpp/helpers.h

@ -62,6 +62,7 @@
#include "absl/synchronization/mutex.h"
#include "google/protobuf/compiler/cpp/names.h"
#include "google/protobuf/compiler/cpp/options.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/io/printer.h"
#include "google/protobuf/io/strtod.h"
@ -203,10 +204,6 @@ std::string IntTypeName(const Options& options, absl::string_view type) {
} // namespace
bool IsRarelyPresent(const FieldDescriptor* field, const Options& options) {
return false;
}
bool IsLazy(const FieldDescriptor* field, const Options& options,
MessageSCCAnalyzer* scc_analyzer) {
return IsLazilyVerifiedLazy(field, options) ||
@ -894,9 +891,13 @@ std::string SafeFunctionName(const Descriptor* descriptor,
bool IsProfileDriven(const Options& options) {
return options.access_info_map != nullptr;
}
bool IsStringInlined(const FieldDescriptor* descriptor,
const Options& options) {
(void)descriptor;
bool IsRarelyPresent(const FieldDescriptor* field, const Options& options) {
return false;
}
bool IsStringInlined(const FieldDescriptor* field, const Options& options) {
(void)field;
(void)options;
return false;
}
@ -938,6 +939,32 @@ bool HasLazyFields(const FileDescriptor* file, const Options& options,
return false;
}
bool ShouldVerify(const Descriptor* descriptor, const Options& options,
MessageSCCAnalyzer* scc_analyzer) {
(void)descriptor;
(void)options;
(void)scc_analyzer;
return false;
}
bool ShouldVerify(const FileDescriptor* file, const Options& options,
MessageSCCAnalyzer* scc_analyzer) {
(void)file;
(void)options;
(void)scc_analyzer;
return false;
}
bool ShouldVerifyRecursively(const FieldDescriptor* field) {
(void)field;
return false;
}
VerifySimpleType ShouldVerifySimple(const Descriptor* descriptor) {
(void)descriptor;
return VerifySimpleType::kCustom;
}
bool ShouldSplit(const Descriptor*, const Options&) { return false; }
bool ShouldSplit(const FieldDescriptor*, const Options&) { return false; }
@ -1069,28 +1096,6 @@ bool HasEnumDefinitions(const FileDescriptor* file) {
return false;
}
bool ShouldVerify(const Descriptor* descriptor, const Options& options,
MessageSCCAnalyzer* scc_analyzer) {
(void)descriptor;
(void)options;
(void)scc_analyzer;
return false;
}
bool ShouldVerify(const FileDescriptor* file, const Options& options,
MessageSCCAnalyzer* scc_analyzer) {
(void)file;
(void)options;
(void)scc_analyzer;
return false;
}
VerifySimpleType ShouldVerifySimple(const Descriptor* descriptor) {
(void)descriptor;
return VerifySimpleType::kCustom;
}
bool IsStringOrMessage(const FieldDescriptor* field) {
switch (field->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32:

@ -345,10 +345,6 @@ inline bool IsWeak(const FieldDescriptor* field, const Options& options) {
return false;
}
bool IsProfileDriven(const Options& options);
bool IsStringInlined(const FieldDescriptor* descriptor, const Options& options);
inline bool IsCord(const FieldDescriptor* field, const Options& options) {
return field->cpp_type() == FieldDescriptor::CPPTYPE_STRING &&
internal::cpp::EffectiveStringCType(field) == FieldOptions::CORD;
@ -366,6 +362,14 @@ inline bool IsStringPiece(const FieldDescriptor* field,
FieldOptions::STRING_PIECE;
}
bool IsProfileDriven(const Options& options);
// Returns true if `field` is unlikely to be present based on PDProto profile.
bool IsRarelyPresent(const FieldDescriptor* field, const Options& options);
// Returns true if `field` should be inlined based on PDProto profile.
bool IsStringInlined(const FieldDescriptor* field, const Options& options);
// Does the given FileDescriptor use lazy fields?
bool HasLazyFields(const FileDescriptor* file, const Options& options,
MessageSCCAnalyzer* scc_analyzer);
@ -385,6 +389,32 @@ bool IsEagerlyVerifiedLazy(const FieldDescriptor* field, const Options& options,
bool IsLazilyVerifiedLazy(const FieldDescriptor* field, const Options& options);
bool ShouldVerify(const Descriptor* descriptor, const Options& options,
MessageSCCAnalyzer* scc_analyzer);
bool ShouldVerify(const FileDescriptor* file, const Options& options,
MessageSCCAnalyzer* scc_analyzer);
bool ShouldVerifyRecursively(const FieldDescriptor* field);
// Indicates whether to use predefined verify methods for a given message. If a
// message is "simple" and needs no special verification per field (e.g. message
// field, repeated packed, UTF8 string, etc.), we can use either VerifySimple or
// VerifySimpleAlwaysCheckInt32 methods as all verification can be done based on
// the wire type.
//
// Otherwise, we need "custom" verify methods tailored to a message to pass
// which field needs a special verification; i.e. InternalVerify.
enum class VerifySimpleType {
kSimpleInt32Never, // Use VerifySimple
kSimpleInt32Always, // Use VerifySimpleAlwaysCheckInt32
kCustom, // Use InternalVerify and check only for int32
kCustomInt32Never, // Use InternalVerify but never check for int32
kCustomInt32Always, // Use InternalVerify and always check for int32
};
// Returns VerifySimpleType if messages can be verified by predefined methods.
VerifySimpleType ShouldVerifySimple(const Descriptor* descriptor);
// Is the given message being split (go/pdsplit)?
bool ShouldSplit(const Descriptor* desc, const Options& options);
@ -1013,30 +1043,6 @@ inline OneOfRangeImpl OneOfRange(const Descriptor* desc) { return {desc}; }
// Strips ".proto" or ".protodevel" from the end of a filename.
PROTOC_EXPORT std::string StripProto(absl::string_view filename);
bool ShouldVerify(const Descriptor* descriptor, const Options& options,
MessageSCCAnalyzer* scc_analyzer);
bool ShouldVerify(const FileDescriptor* file, const Options& options,
MessageSCCAnalyzer* scc_analyzer);
// Indicates whether to use predefined verify methods for a given message. If a
// message is "simple" and needs no special verification per field (e.g. message
// field, repeated packed, UTF8 string, etc.), we can use either VerifySimple or
// VerifySimpleAlwaysCheckInt32 methods as all verification can be done based on
// the wire type.
//
// Otherwise, we need "custom" verify methods tailored to a message to pass
// which field needs a special verification; i.e. InternalVerify.
enum class VerifySimpleType {
kSimpleInt32Never, // Use VerifySimple
kSimpleInt32Always, // Use VerifySimpleAlwaysCheckInt32
kCustom, // Use InternalVerify and check only for int32
kCustomInt32Never, // Use InternalVerify but never check for int32
kCustomInt32Always, // Use InternalVerify and always check for int32
};
// Returns VerifySimpleType if messages can be verified by predefined methods.
VerifySimpleType ShouldVerifySimple(const Descriptor* descriptor);
bool HasMessageFieldOrExtension(const Descriptor* desc);
// Generates a vector of substitutions for use with Printer::WithVars that
@ -1054,9 +1060,6 @@ std::vector<io::Printer::Sub> AnnotatedAccessors(
// dynamic initialization.
bool IsFileDescriptorProto(const FileDescriptor* file, const Options& options);
// Returns true if `field` is unlikely to be present based on PDProto profile.
bool IsRarelyPresent(const FieldDescriptor* field, const Options& options);
} // namespace cpp
} // namespace compiler
} // namespace protobuf

Loading…
Cancel
Save