[ObjC] Move the property decls over to the new api.

PiperOrigin-RevId: 566695697
pull/14135/head
Thomas Van Lenten 1 year ago committed by Copybara-Service
parent 215154eb2c
commit b70e0fe3fd
  1. 2
      src/google/protobuf/compiler/objectivec/enum_field.cc
  2. 72
      src/google/protobuf/compiler/objectivec/field.cc
  3. 2
      src/google/protobuf/compiler/objectivec/field.h
  4. 11
      src/google/protobuf/compiler/objectivec/map_field.cc
  5. 5
      src/google/protobuf/compiler/objectivec/message_field.cc
  6. 3
      src/google/protobuf/compiler/objectivec/primitive_field.cc
  7. 1351
      upb/cmake/google/protobuf/descriptor.upb_minitable.c
  8. 78
      upb/cmake/google/protobuf/descriptor.upb_minitable.h

@ -37,7 +37,7 @@ void SetEnumVariables(
// the forward declaration of the enums.
if (!descriptor->is_repeated() &&
(descriptor->file() != descriptor->enum_type()->file())) {
(*variables)["property_type"] = absl::StrCat("enum ", type);
(*variables)["property_type"] = absl::StrCat("enum ", type, " ");
}
(*variables)["enum_verifier"] = absl::StrCat(type, "_IsValidValue");
(*variables)["enum_desc_func"] = enum_desc_func;

@ -58,6 +58,10 @@ void SetCommonFieldVariables(
(*variables)["field_number_name"] =
absl::StrCat(classname, "_FieldNumber_", capitalized_name);
(*variables)["field_number"] = absl::StrCat(descriptor->number());
(*variables)["property_type"] = FieldObjCType(
descriptor, static_cast<FieldObjCTypeOptions>(
kFieldObjCTypeOptions_IncludeSpaceAfterBasicTypes |
kFieldObjCTypeOptions_IncludeSpaceBeforeStar));
(*variables)["field_type"] = GetCapitalizedType(descriptor);
(*variables)["deprecated_attribute"] =
GetOptionalDeprecatedAttribute(descriptor);
@ -148,44 +152,35 @@ bool HasNonZeroDefaultValue(const FieldDescriptor* field) {
} // namespace
FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field) {
FieldGenerator* result = nullptr;
if (field->is_repeated()) {
switch (GetObjectiveCType(field)) {
case OBJECTIVECTYPE_MESSAGE: {
if (field->is_map()) {
result = new MapFieldGenerator(field);
return new MapFieldGenerator(field);
} else {
result = new RepeatedMessageFieldGenerator(field);
return new RepeatedMessageFieldGenerator(field);
}
break;
}
case OBJECTIVECTYPE_ENUM:
result = new RepeatedEnumFieldGenerator(field);
break;
return new RepeatedEnumFieldGenerator(field);
default:
result = new RepeatedPrimitiveFieldGenerator(field);
break;
return new RepeatedPrimitiveFieldGenerator(field);
}
} else {
switch (GetObjectiveCType(field)) {
case OBJECTIVECTYPE_MESSAGE: {
result = new MessageFieldGenerator(field);
break;
}
case OBJECTIVECTYPE_ENUM:
result = new EnumFieldGenerator(field);
break;
default:
if (IsReferenceType(field)) {
result = new PrimitiveObjFieldGenerator(field);
} else {
result = new PrimitiveFieldGenerator(field);
}
break;
}
switch (GetObjectiveCType(field)) {
case OBJECTIVECTYPE_MESSAGE: {
return new MessageFieldGenerator(field);
}
case OBJECTIVECTYPE_ENUM:
return new EnumFieldGenerator(field);
default:
if (IsReferenceType(field)) {
return new PrimitiveObjFieldGenerator(field);
} else {
return new PrimitiveFieldGenerator(field);
}
}
result->FinishInitialization();
return result;
}
FieldGenerator::FieldGenerator(const FieldDescriptor* descriptor)
@ -275,14 +270,6 @@ bool FieldGenerator::WantsHasProperty() const {
return descriptor_->has_presence() && !descriptor_->real_containing_oneof();
}
void FieldGenerator::FinishInitialization() {
// If "property_type" wasn't set, make it "storage_type".
if ((variables_.find("property_type") == variables_.end()) &&
(variables_.find("storage_type") != variables_.end())) {
variables_["property_type"] = variable("storage_type");
}
}
SingleFieldGenerator::SingleFieldGenerator(const FieldDescriptor* descriptor)
: FieldGenerator(descriptor) {
// Nothing
@ -301,7 +288,7 @@ void SingleFieldGenerator::GeneratePropertyDeclaration(
{{"comments", [&] { EmitCommentsString(printer, descriptor_); }}},
R"objc(
$comments$
@property(nonatomic, readwrite) $property_type$ $name$$ deprecated_attribute$;
@property(nonatomic, readwrite) $property_type$$name$$ deprecated_attribute$;
)objc");
if (WantsHasProperty()) {
printer->Emit(R"objc(
@ -354,7 +341,7 @@ void ObjCObjFieldGenerator::GeneratePropertyDeclaration(
{{"comments", [&] { EmitCommentsString(printer, descriptor_); }}},
R"objc(
$comments$
@property(nonatomic, readwrite, $property_storage_attribute$, null_resettable) $property_type$ *$name$$storage_attribute$$ deprecated_attribute$;
@property(nonatomic, readwrite, $property_storage_attribute$, null_resettable) $property_type$$name$$storage_attribute$$ deprecated_attribute$;
)objc");
if (WantsHasProperty()) {
printer->Emit(R"objc(
@ -366,7 +353,7 @@ void ObjCObjFieldGenerator::GeneratePropertyDeclaration(
// If property name starts with init we need to annotate it to get past ARC.
// http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-property-with-an-objc-method-family/18723227#18723227
printer->Emit(R"objc(
- ($property_type$ *)$name$ GPB_METHOD_FAMILY_NONE$ deprecated_attribute$;
- ($property_type$)$name$ GPB_METHOD_FAMILY_NONE$ deprecated_attribute$;
)objc");
}
printer->Emit("\n");
@ -376,13 +363,6 @@ RepeatedFieldGenerator::RepeatedFieldGenerator(
const FieldDescriptor* descriptor)
: ObjCObjFieldGenerator(descriptor) {}
void RepeatedFieldGenerator::FinishInitialization() {
FieldGenerator::FinishInitialization();
if (variables_.find("array_property_type") == variables_.end()) {
variables_["array_property_type"] = variable("array_storage_type");
}
}
void RepeatedFieldGenerator::GenerateFieldStorageDeclaration(
io::Printer* printer) const {
auto vars = printer->WithVars(variables_);
@ -410,7 +390,7 @@ void RepeatedFieldGenerator::GeneratePropertyDeclaration(
R"objc(
$comments$
$array_comment$
@property(nonatomic, readwrite, strong, null_resettable) $array_property_type$ *$name$$storage_attribute$$ deprecated_attribute$;
@property(nonatomic, readwrite, strong, null_resettable) $property_type$$name$$storage_attribute$$ deprecated_attribute$;
/** The number of items in @c $name$ without causing the container to be created. */
@property(nonatomic, readonly) NSUInteger $name$_Count$ deprecated_attribute$;
)objc");
@ -418,7 +398,7 @@ void RepeatedFieldGenerator::GeneratePropertyDeclaration(
// If property name starts with init we need to annotate it to get past ARC.
// http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-property-with-an-objc-method-family/18723227#18723227
printer->Emit(R"objc(
- ($array_property_type$ *)$name$ GPB_METHOD_FAMILY_NONE$ deprecated_attribute$;
- ($property_type$)$name$ GPB_METHOD_FAMILY_NONE$ deprecated_attribute$;
)objc");
}
printer->Emit("\n");

@ -82,7 +82,6 @@ class FieldGenerator {
protected:
explicit FieldGenerator(const FieldDescriptor* descriptor);
virtual void FinishInitialization();
bool WantsHasProperty() const;
const FieldDescriptor* descriptor_;
@ -140,7 +139,6 @@ class RepeatedFieldGenerator : public ObjCObjFieldGenerator {
protected:
explicit RepeatedFieldGenerator(const FieldDescriptor* descriptor);
void FinishInitialization() override;
};
// Convenience class which constructs FieldGenerators for a Descriptor.

@ -110,19 +110,10 @@ MapFieldGenerator::MapFieldGenerator(const FieldDescriptor* descriptor)
if ((GetObjectiveCType(key_descriptor) == OBJECTIVECTYPE_STRING) &&
value_is_object_type) {
variables_["array_storage_type"] = "NSMutableDictionary";
variables_["array_property_type"] =
absl::StrCat("NSMutableDictionary<NSString*, ",
value_field_generator_->variable("storage_type"), "*>");
} else {
std::string class_name =
variables_["array_storage_type"] =
absl::StrCat("GPB", MapEntryTypeName(key_descriptor, true),
MapEntryTypeName(value_descriptor, false), "Dictionary");
variables_["array_storage_type"] = class_name;
if (value_is_object_type) {
variables_["array_property_type"] =
absl::StrCat(class_name, "<",
value_field_generator_->variable("storage_type"), "*>");
}
}
variables_["dataTypeSpecific_name"] =

@ -35,8 +35,6 @@ void SetMessageVariables(
(*variables)["type"] = message_type;
(*variables)["containing_class"] = containing_class;
(*variables)["storage_type"] = message_type;
(*variables)["group_or_message"] =
(descriptor->type() == FieldDescriptor::TYPE_GROUP) ? "Group" : "Message";
(*variables)["dataTypeSpecific_value"] = ObjCClass(message_type);
}
@ -79,10 +77,7 @@ RepeatedMessageFieldGenerator::RepeatedMessageFieldGenerator(
const FieldDescriptor* descriptor)
: RepeatedFieldGenerator(descriptor) {
SetMessageVariables(descriptor, &variables_);
std::string storage_type = variables_["storage_type"];
variables_["array_storage_type"] = "NSMutableArray";
variables_["array_property_type"] =
absl::StrCat("NSMutableArray<", storage_type, "*>");
}
void RepeatedMessageFieldGenerator::DetermineForwardDeclarations(

@ -150,10 +150,7 @@ RepeatedPrimitiveFieldGenerator::RepeatedPrimitiveFieldGenerator(
if (!base_name.empty()) {
variables_["array_storage_type"] = absl::StrCat("GPB", base_name, "Array");
} else {
std::string storage_type = variables_["storage_type"];
variables_["array_storage_type"] = "NSMutableArray";
variables_["array_property_type"] =
absl::StrCat("NSMutableArray<", storage_type, "*>");
}
}

File diff suppressed because it is too large Load Diff

@ -1,78 +0,0 @@
/* This file was generated by upbc (the upb compiler) from the input
* file:
*
* google/protobuf/descriptor.proto
*
* Do not edit -- your changes will be discarded when the file is
* regenerated. */
#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_MINITABLE_H_
#define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_MINITABLE_H_
#include "upb/upb/generated_code_support.h"
// Must be last.
#include "upb/upb/port/def.inc"
#ifdef __cplusplus
extern "C" {
#endif
extern const upb_MiniTable google_protobuf_FileDescriptorSet_msg_init;
extern const upb_MiniTable google_protobuf_FileDescriptorProto_msg_init;
extern const upb_MiniTable google_protobuf_DescriptorProto_msg_init;
extern const upb_MiniTable google_protobuf_DescriptorProto_ExtensionRange_msg_init;
extern const upb_MiniTable google_protobuf_DescriptorProto_ReservedRange_msg_init;
extern const upb_MiniTable google_protobuf_ExtensionRangeOptions_msg_init;
extern const upb_MiniTable google_protobuf_ExtensionRangeOptions_Declaration_msg_init;
extern const upb_MiniTable google_protobuf_FieldDescriptorProto_msg_init;
extern const upb_MiniTable google_protobuf_OneofDescriptorProto_msg_init;
extern const upb_MiniTable google_protobuf_EnumDescriptorProto_msg_init;
extern const upb_MiniTable google_protobuf_EnumDescriptorProto_EnumReservedRange_msg_init;
extern const upb_MiniTable google_protobuf_EnumValueDescriptorProto_msg_init;
extern const upb_MiniTable google_protobuf_ServiceDescriptorProto_msg_init;
extern const upb_MiniTable google_protobuf_MethodDescriptorProto_msg_init;
extern const upb_MiniTable google_protobuf_FileOptions_msg_init;
extern const upb_MiniTable google_protobuf_MessageOptions_msg_init;
extern const upb_MiniTable google_protobuf_FieldOptions_msg_init;
extern const upb_MiniTable google_protobuf_FieldOptions_EditionDefault_msg_init;
extern const upb_MiniTable google_protobuf_OneofOptions_msg_init;
extern const upb_MiniTable google_protobuf_EnumOptions_msg_init;
extern const upb_MiniTable google_protobuf_EnumValueOptions_msg_init;
extern const upb_MiniTable google_protobuf_ServiceOptions_msg_init;
extern const upb_MiniTable google_protobuf_MethodOptions_msg_init;
extern const upb_MiniTable google_protobuf_UninterpretedOption_msg_init;
extern const upb_MiniTable google_protobuf_UninterpretedOption_NamePart_msg_init;
extern const upb_MiniTable google_protobuf_FeatureSet_msg_init;
extern const upb_MiniTable google_protobuf_FeatureSetDefaults_msg_init;
extern const upb_MiniTable google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_msg_init;
extern const upb_MiniTable google_protobuf_SourceCodeInfo_msg_init;
extern const upb_MiniTable google_protobuf_SourceCodeInfo_Location_msg_init;
extern const upb_MiniTable google_protobuf_GeneratedCodeInfo_msg_init;
extern const upb_MiniTable google_protobuf_GeneratedCodeInfo_Annotation_msg_init;
extern const upb_MiniTableEnum google_protobuf_Edition_enum_init;
extern const upb_MiniTableEnum google_protobuf_ExtensionRangeOptions_VerificationState_enum_init;
extern const upb_MiniTableEnum google_protobuf_FeatureSet_EnumType_enum_init;
extern const upb_MiniTableEnum google_protobuf_FeatureSet_FieldPresence_enum_init;
extern const upb_MiniTableEnum google_protobuf_FeatureSet_JsonFormat_enum_init;
extern const upb_MiniTableEnum google_protobuf_FeatureSet_MessageEncoding_enum_init;
extern const upb_MiniTableEnum google_protobuf_FeatureSet_RepeatedFieldEncoding_enum_init;
extern const upb_MiniTableEnum google_protobuf_FieldDescriptorProto_Label_enum_init;
extern const upb_MiniTableEnum google_protobuf_FieldDescriptorProto_Type_enum_init;
extern const upb_MiniTableEnum google_protobuf_FieldOptions_CType_enum_init;
extern const upb_MiniTableEnum google_protobuf_FieldOptions_JSType_enum_init;
extern const upb_MiniTableEnum google_protobuf_FieldOptions_OptionRetention_enum_init;
extern const upb_MiniTableEnum google_protobuf_FieldOptions_OptionTargetType_enum_init;
extern const upb_MiniTableEnum google_protobuf_FileOptions_OptimizeMode_enum_init;
extern const upb_MiniTableEnum google_protobuf_GeneratedCodeInfo_Annotation_Semantic_enum_init;
extern const upb_MiniTableEnum google_protobuf_MethodOptions_IdempotencyLevel_enum_init;
extern const upb_MiniTableFile google_protobuf_descriptor_proto_upb_file_layout;
#ifdef __cplusplus
} /* extern "C" */
#endif
#include "upb/upb/port/undef.inc"
#endif /* GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_MINITABLE_H_ */
Loading…
Cancel
Save