aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/compiler/objectivec
diff options
context:
space:
mode:
authorThomas Van Lenten <thomasvl@google.com>2016-05-25 13:46:00 -0400
committerThomas Van Lenten <thomasvl@google.com>2016-05-25 16:42:31 -0400
commitc8a440dfb68074ff310e624928cd2dd61c101728 (patch)
tree6b2251c56e7ccd125a7cc7bcb9fc276266f5adc5 /src/google/protobuf/compiler/objectivec
parentd089f04ae53565aff77240172e1007f3959503f4 (diff)
downloadprotobuf-c8a440dfb68074ff310e624928cd2dd61c101728.tar.gz
protobuf-c8a440dfb68074ff310e624928cd2dd61c101728.tar.bz2
protobuf-c8a440dfb68074ff310e624928cd2dd61c101728.zip
Add more warnings to for the ObjC runtime build
Working on https://github.com/google/protobuf/issues/1599, specifically: - Turn on more warnings that the Xcode UI calls out with individual controls. - Manually add: -Wundef -Wswitch-enum - Manually add and then diable in the unittests because of XCTest's headers: -Wreserved-id-macro -Wdocumentation-unknown-command - Manually add -Wdirect-ivar-access, but disable it for the unittests and in the library code (via #pragmas to suppress it). This is done so proto users can enable the warning.
Diffstat (limited to 'src/google/protobuf/compiler/objectivec')
-rw-r--r--src/google/protobuf/compiler/objectivec/objectivec_file.cc28
-rw-r--r--src/google/protobuf/compiler/objectivec/objectivec_message.cc16
-rw-r--r--src/google/protobuf/compiler/objectivec/objectivec_message.h3
3 files changed, 45 insertions, 2 deletions
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_file.cc b/src/google/protobuf/compiler/objectivec/objectivec_file.cc
index ccf5fbb4..7774058e 100644
--- a/src/google/protobuf/compiler/objectivec/objectivec_file.cc
+++ b/src/google/protobuf/compiler/objectivec/objectivec_file.cc
@@ -182,6 +182,10 @@ void FileGenerator::GenerateHeader(io::Printer *printer) {
import_writer.Print(printer);
}
+ // Note:
+ // deprecated-declarations suppression is only needed if some place in this
+ // proto file is something deprecated or if it references something from
+ // another file that is deprecated.
printer->Print(
"// @@protoc_insertion_point(imports)\n"
"\n"
@@ -292,14 +296,34 @@ void FileGenerator::GenerateSource(io::Printer *printer) {
import_writer.Print(printer);
}
+ bool includes_oneof = false;
+ for (vector<MessageGenerator *>::iterator iter = message_generators_.begin();
+ iter != message_generators_.end(); ++iter) {
+ if ((*iter)->IncludesOneOfDefinition()) {
+ includes_oneof = true;
+ break;
+ }
+ }
+
+ // Note:
+ // deprecated-declarations suppression is only needed if some place in this
+ // proto file is something deprecated or if it references something from
+ // another file that is deprecated.
printer->Print(
"// @@protoc_insertion_point(imports)\n"
"\n"
"#pragma clang diagnostic push\n"
- "#pragma clang diagnostic ignored \"-Wdeprecated-declarations\"\n"
- "\n");
+ "#pragma clang diagnostic ignored \"-Wdeprecated-declarations\"\n");
+ if (includes_oneof) {
+ // The generated code for oneof's uses direct ivar access, suppress the
+ // warning incase developer turn that on in the context they compile the
+ // generated code.
+ printer->Print(
+ "#pragma clang diagnostic ignored \"-Wdirect-ivar-access\"\n");
+ }
printer->Print(
+ "\n"
"#pragma mark - $root_class_name$\n"
"\n"
"@implementation $root_class_name$\n\n",
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.cc b/src/google/protobuf/compiler/objectivec/objectivec_message.cc
index bf272596..e1a78619 100644
--- a/src/google/protobuf/compiler/objectivec/objectivec_message.cc
+++ b/src/google/protobuf/compiler/objectivec/objectivec_message.cc
@@ -246,6 +246,22 @@ void MessageGenerator::DetermineForwardDeclarations(set<string>* fwd_decls) {
}
}
+bool MessageGenerator::IncludesOneOfDefinition() const {
+ if (!oneof_generators_.empty()) {
+ return true;
+ }
+
+ for (vector<MessageGenerator*>::const_iterator iter =
+ nested_message_generators_.begin();
+ iter != nested_message_generators_.end(); ++iter) {
+ if ((*iter)->IncludesOneOfDefinition()) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
void MessageGenerator::GenerateEnumHeader(io::Printer* printer) {
for (vector<EnumGenerator*>::iterator iter = enum_generators_.begin();
iter != enum_generators_.end(); ++iter) {
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.h b/src/google/protobuf/compiler/objectivec/objectivec_message.h
index 8565e76f..910535ac 100644
--- a/src/google/protobuf/compiler/objectivec/objectivec_message.h
+++ b/src/google/protobuf/compiler/objectivec/objectivec_message.h
@@ -66,6 +66,9 @@ class MessageGenerator {
void GenerateExtensionRegistrationSource(io::Printer* printer);
void DetermineForwardDeclarations(set<string>* fwd_decls);
+ // Checks if the message or a nested message includes a oneof definition.
+ bool IncludesOneOfDefinition() const;
+
private:
void GenerateParseFromMethodsHeader(io::Printer* printer);