aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc')
-rw-r--r--src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc53
1 files changed, 37 insertions, 16 deletions
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc
index c185b66d..d49350f4 100644
--- a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc
+++ b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc
@@ -74,7 +74,7 @@ const char* PrimitiveTypeName(const FieldDescriptor* descriptor) {
case OBJECTIVECTYPE_ENUM:
return "int32_t";
case OBJECTIVECTYPE_MESSAGE:
- return NULL;
+ return NULL; // Messages go through objectivec_message_field.cc|h.
}
// Some compilers report reaching end of function even though all cases of
@@ -107,7 +107,8 @@ const char* PrimitiveArrayTypeName(const FieldDescriptor* descriptor) {
case OBJECTIVECTYPE_ENUM:
return "Enum";
case OBJECTIVECTYPE_MESSAGE:
- return ""; // Want NSArray
+ // Want NSArray (but goes through objectivec_message_field.cc|h).
+ return "";
}
// Some compilers report reaching end of function even though all cases of
@@ -126,16 +127,42 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
} // namespace
PrimitiveFieldGenerator::PrimitiveFieldGenerator(
- const FieldDescriptor* descriptor)
- : SingleFieldGenerator(descriptor) {
+ const FieldDescriptor* descriptor, const Options& options)
+ : SingleFieldGenerator(descriptor, options) {
SetPrimitiveVariables(descriptor, &variables_);
}
PrimitiveFieldGenerator::~PrimitiveFieldGenerator() {}
+void PrimitiveFieldGenerator::GenerateFieldStorageDeclaration(
+ io::Printer* printer) const {
+ if (GetObjectiveCType(descriptor_) == OBJECTIVECTYPE_BOOLEAN) {
+ // Nothing, BOOLs are stored in the has bits.
+ } else {
+ SingleFieldGenerator::GenerateFieldStorageDeclaration(printer);
+ }
+}
+
+int PrimitiveFieldGenerator::ExtraRuntimeHasBitsNeeded(void) const {
+ if (GetObjectiveCType(descriptor_) == OBJECTIVECTYPE_BOOLEAN) {
+ // Reserve a bit for the storage of the boolean.
+ return 1;
+ }
+ return 0;
+}
+
+void PrimitiveFieldGenerator::SetExtraRuntimeHasBitsBase(int has_base) {
+ if (GetObjectiveCType(descriptor_) == OBJECTIVECTYPE_BOOLEAN) {
+ // Set into the offset the has bit to use for the actual value.
+ variables_["storage_offset_value"] = SimpleItoa(has_base);
+ variables_["storage_offset_comment"] =
+ " // Stored in _has_storage_ to save space.";
+ }
+}
+
PrimitiveObjFieldGenerator::PrimitiveObjFieldGenerator(
- const FieldDescriptor* descriptor)
- : ObjCObjFieldGenerator(descriptor) {
+ const FieldDescriptor* descriptor, const Options& options)
+ : ObjCObjFieldGenerator(descriptor, options) {
SetPrimitiveVariables(descriptor, &variables_);
variables_["property_storage_attribute"] = "copy";
}
@@ -143,8 +170,8 @@ PrimitiveObjFieldGenerator::PrimitiveObjFieldGenerator(
PrimitiveObjFieldGenerator::~PrimitiveObjFieldGenerator() {}
RepeatedPrimitiveFieldGenerator::RepeatedPrimitiveFieldGenerator(
- const FieldDescriptor* descriptor)
- : RepeatedFieldGenerator(descriptor) {
+ const FieldDescriptor* descriptor, const Options& options)
+ : RepeatedFieldGenerator(descriptor, options) {
SetPrimitiveVariables(descriptor, &variables_);
string base_name = PrimitiveArrayTypeName(descriptor);
@@ -152,19 +179,13 @@ RepeatedPrimitiveFieldGenerator::RepeatedPrimitiveFieldGenerator(
variables_["array_storage_type"] = "GPB" + base_name + "Array";
} else {
variables_["array_storage_type"] = "NSMutableArray";
+ variables_["array_property_type"] =
+ "NSMutableArray<" + variables_["storage_type"] + "*>";
}
}
RepeatedPrimitiveFieldGenerator::~RepeatedPrimitiveFieldGenerator() {}
-void RepeatedPrimitiveFieldGenerator::FinishInitialization(void) {
- RepeatedFieldGenerator::FinishInitialization();
- if (IsPrimitiveType(descriptor_)) {
- // No comment needed for primitive types.
- variables_["array_comment"] = "";
- }
-}
-
} // namespace objectivec
} // namespace compiler
} // namespace protobuf