aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc
diff options
context:
space:
mode:
authorGravatar Thomas Van Lenten <thomasvl@google.com>2015-05-21 17:14:52 -0400
committerGravatar Thomas Van Lenten <thomasvl@google.com>2015-05-22 14:27:31 -0400
commit1dcc329427fd103a0abd96ab787270f5d0a31861 (patch)
treecf1c52df0e1effa3d0985a3406a71c38c3a4e487 /src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc
parentc3480926f98eb7c45224daae5cf0373e120b3b8d (diff)
Objective C Second Alpha Drop
- Style fixups in the code. - map<> serialization fixes and more tests. - Autocreation of map<> fields (to match repeated fields). - @@protoc_insertion_point(global_scope|imports). - Fixup proto2 syntax extension support. - Move all startup code to +initialize so it happen on class usage and not app startup. - Have generated headers use forward declarations and move imports into generated code, reduces what is need at compile time to speed up compiled and avoid pointless rippling of rebuilds.
Diffstat (limited to 'src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc')
-rw-r--r--src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc
index 739282b2..d6609692 100644
--- a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc
+++ b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc
@@ -48,6 +48,13 @@ void SetEnumVariables(const FieldDescriptor* descriptor,
map<string, string>* variables) {
string type = EnumName(descriptor->enum_type());
(*variables)["storage_type"] = type;
+ // For non repeated fields, if it was defined in a different file, the
+ // property decls need to use "enum NAME" rather than just "NAME" to support
+ // the forward declaration of the enums.
+ if (!descriptor->is_repeated() &&
+ (descriptor->file() != descriptor->enum_type()->file())) {
+ (*variables)["property_type"] = "enum " + type;
+ }
// TODO(thomasvl): Make inclusion of descriptor compile time and output
// both of these. Note: Extensions currently have to have the EnumDescription.
(*variables)["enum_verifier"] = type + "_IsValidValue";
@@ -76,7 +83,9 @@ void EnumFieldGenerator::GenerateFieldDescriptionTypeSpecific(
void EnumFieldGenerator::GenerateCFunctionDeclarations(
io::Printer* printer) const {
- if (!HasPreservingUnknownEnumSemantics(descriptor_->file())) return;
+ if (!HasPreservingUnknownEnumSemantics(descriptor_->file())) {
+ return;
+ }
printer->Print(
variables_,
@@ -105,6 +114,18 @@ void EnumFieldGenerator::GenerateCFunctionImplementations(
"\n");
}
+void EnumFieldGenerator::DetermineForwardDeclarations(
+ set<string>* fwd_decls) const {
+ // If it is an enum defined in a different file, then we'll need a forward
+ // declaration for it. When it is in our file, all the enums are output
+ // before the message, so it will be declared before it is needed.
+ if (descriptor_->file() != descriptor_->enum_type()->file()) {
+ // Enum name is already in "storage_type".
+ const string& name = variable("storage_type");
+ fwd_decls->insert("GPB_ENUM_FWD_DECLARE(" + name + ")");
+ }
+}
+
RepeatedEnumFieldGenerator::RepeatedEnumFieldGenerator(
const FieldDescriptor* descriptor)
: RepeatedFieldGenerator(descriptor) {