Migrate syntax reflection to new feature-based system.

PiperOrigin-RevId: 513358980
pull/12114/head
Mike Kruskal 2 years ago committed by Copybara-Service
parent af791f28a8
commit a66f75dfeb
  1. 4
      src/google/protobuf/compiler/cpp/helpers.cc
  2. 6
      src/google/protobuf/compiler/cpp/helpers.h
  3. 17
      src/google/protobuf/compiler/cpp/message.cc

@ -1092,10 +1092,6 @@ bool ShouldVerify(const FileDescriptor* file, const Options& options,
return false;
}
bool IsUtf8String(const FieldDescriptor* field) {
return IsProto3(field->file()) &&
field->type() == FieldDescriptor::TYPE_STRING;
}
VerifySimpleType ShouldVerifySimple(const Descriptor* descriptor) {
(void)descriptor;

@ -465,10 +465,6 @@ bool IsStringOrMessage(const FieldDescriptor* field);
std::string UnderscoresToCamelCase(absl::string_view input,
bool cap_next_letter);
inline bool IsProto3(const FileDescriptor* file) {
return file->syntax() == FileDescriptor::SYNTAX_PROTO3;
}
inline bool IsCrossFileMessage(const FieldDescriptor* field) {
return field->type() == FieldDescriptor::TYPE_MESSAGE &&
field->message_type()->file() != field->file();
@ -1045,8 +1041,6 @@ enum class VerifySimpleType {
// Returns VerifySimpleType if messages can be verified by predefined methods.
VerifySimpleType ShouldVerifySimple(const Descriptor* descriptor);
bool IsUtf8String(const FieldDescriptor* field);
bool HasMessageFieldOrExtension(const Descriptor* desc);
// Generates a vector of substitutions for use with Printer::WithVars that

@ -252,18 +252,6 @@ bool EmitFieldNonDefaultCondition(io::Printer* p, const std::string& prefix,
return false;
}
// Does the given field have a has_$name$() method?
bool HasHasMethod(const FieldDescriptor* field) {
if (!IsProto3(field->file())) {
// In proto1/proto2, every field has a has_$name$() method.
return true;
}
// For message types without true field presence, only fields with a message
// type or inside an one-of have a has_$name$() method.
return field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE ||
field->has_optional_keyword() || field->real_containing_oneof();
}
bool HasInternalHasMethod(const FieldDescriptor* field) {
return !HasHasbit(field) &&
field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE;
@ -1040,7 +1028,7 @@ void MessageGenerator::GenerateOneofMemberHasBits(const FieldDescriptor* field,
// N.B.: Without field presence, we do not use has-bits or generate
// has_$name$() methods, but oneofs still have set_has_$name$().
// Oneofs also have private _internal_has_$name$() a helper method.
if (HasHasMethod(field)) {
if (field->has_presence()) {
format(
"inline bool $classname$::has_$name$() const {\n"
"$annotate_has$"
@ -3651,7 +3639,8 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody(io::Printer* p) {
LazySerializerEmitter(MessageGenerator* mg, io::Printer* p)
: mg_(mg),
p_(p),
eager_(IsProto3(mg->descriptor_->file())),
eager_(mg->descriptor_->file()->syntax() ==
FileDescriptor::SYNTAX_PROTO3),
cached_has_bit_index_(kNoHasbit) {}
~LazySerializerEmitter() { Flush(); }

Loading…
Cancel
Save