[ObjC] Move over some custom logic to Descriptor provided info.

FieldDescriptor::has_presence works as a replacement for the custom logic we
had for FieldGenerator::WantsHasProperty(), and is already proto3 optional
aware.
pull/7429/head
Thomas Van Lenten 5 years ago
parent f494cb222d
commit 59f8dd5faf
  1. 21
      src/google/protobuf/compiler/objectivec/objectivec_field.cc
  2. 4
      src/google/protobuf/compiler/objectivec/objectivec_field.h
  3. 4
      src/google/protobuf/compiler/objectivec/objectivec_helpers.h
  4. 10
      src/google/protobuf/compiler/objectivec/objectivec_message_field.cc
  5. 1
      src/google/protobuf/compiler/objectivec/objectivec_message_field.h

@ -245,6 +245,10 @@ void FieldGenerator::SetOneofIndexBase(int index_base) {
}
}
bool FieldGenerator::WantsHasProperty(void) const {
return descriptor_->has_presence() && !descriptor_->real_containing_oneof();
}
void FieldGenerator::FinishInitialization(void) {
// If "property_type" wasn't set, make it "storage_type".
if ((variables_.find("property_type") == variables_.end()) &&
@ -289,18 +293,6 @@ void SingleFieldGenerator::GeneratePropertyImplementation(
}
}
bool SingleFieldGenerator::WantsHasProperty(void) const {
if (descriptor_->containing_oneof() != NULL) {
// If in a oneof, it uses the oneofcase instead of a has bit.
return false;
}
if (HasFieldPresence(descriptor_->file())) {
// In proto1/proto2, every field has a has_$name$() method.
return true;
}
return false;
}
bool SingleFieldGenerator::RuntimeUsesHasBit(void) const {
if (descriptor_->containing_oneof() != NULL) {
// The oneof tracks what is set instead.
@ -402,11 +394,6 @@ void RepeatedFieldGenerator::GeneratePropertyDeclaration(
printer->Print("\n");
}
bool RepeatedFieldGenerator::WantsHasProperty(void) const {
// Consumer check the array size/existence rather than a has bit.
return false;
}
bool RepeatedFieldGenerator::RuntimeUsesHasBit(void) const {
return false; // The array having anything is what is used.
}

@ -96,7 +96,7 @@ class FieldGenerator {
FieldGenerator(const FieldDescriptor* descriptor, const Options& options);
virtual void FinishInitialization(void);
virtual bool WantsHasProperty(void) const = 0;
bool WantsHasProperty(void) const;
const FieldDescriptor* descriptor_;
std::map<string, string> variables_;
@ -119,7 +119,6 @@ class SingleFieldGenerator : public FieldGenerator {
protected:
SingleFieldGenerator(const FieldDescriptor* descriptor,
const Options& options);
virtual bool WantsHasProperty(void) const;
};
// Subclass with common support for when the field ends up as an ObjC Object.
@ -156,7 +155,6 @@ class RepeatedFieldGenerator : public ObjCObjFieldGenerator {
RepeatedFieldGenerator(const FieldDescriptor* descriptor,
const Options& options);
virtual void FinishInitialization(void);
virtual bool WantsHasProperty(void) const;
};
// Convenience class which constructs FieldGenerators for a Descriptor.

@ -126,10 +126,6 @@ string PROTOC_EXPORT ObjCClass(const string& class_name);
// be refrerred to by ObjCClass.
string PROTOC_EXPORT ObjCClassDeclaration(const string& class_name);
inline bool HasFieldPresence(const FileDescriptor* file) {
return file->syntax() != FileDescriptor::SYNTAX_PROTO3;
}
inline bool HasPreservingUnknownEnumSemantics(const FileDescriptor* file) {
return file->syntax() == FileDescriptor::SYNTAX_PROTO3;
}

@ -77,16 +77,6 @@ void MessageFieldGenerator::DetermineObjectiveCClassDefinitions(
fwd_decls->insert(ObjCClassDeclaration(variable("storage_type")));
}
bool MessageFieldGenerator::WantsHasProperty(void) const {
if (descriptor_->containing_oneof() != NULL) {
// If in a oneof, it uses the oneofcase instead of a has bit.
return false;
}
// In both proto2 & proto3, message fields have a has* property to tell
// when it is a non default value.
return true;
}
RepeatedMessageFieldGenerator::RepeatedMessageFieldGenerator(
const FieldDescriptor* descriptor, const Options& options)
: RepeatedFieldGenerator(descriptor, options) {

@ -52,7 +52,6 @@ class MessageFieldGenerator : public ObjCObjFieldGenerator {
MessageFieldGenerator& operator=(const MessageFieldGenerator&) = delete;
virtual ~MessageFieldGenerator();
virtual bool WantsHasProperty(void) const;
public:
virtual void DetermineForwardDeclarations(std::set<string>* fwd_decls) const;

Loading…
Cancel
Save