aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc
diff options
context:
space:
mode:
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) {