Fix bugs in our keyword conversion support for objectivec
We have code for converting C/C++/Objc keywords that appear in protos
to convert them so that they can be compiled.
One of the things we need to be careful of is accidentally overriding methods
that Apple declares in NSObject. It turns out that we have run into issues
where we conflict with "hidden" methods in NSObject or methods added by
categories. method_dump.sh collects all of the methods we care about for
macOS and iOS and dumps them into objectivec_nsobject_methods.h which
is then included in objectivec_helpers.cc as part of the build.
Added a pile of tests to verify that conversions are happening as expected.
diff --git a/objectivec/Tests/unittest_objc.proto b/objectivec/Tests/unittest_objc.proto
index 2202e6c..b0ab8d8 100644
--- a/objectivec/Tests/unittest_objc.proto
+++ b/objectivec/Tests/unittest_objc.proto
@@ -103,37 +103,89 @@
}
// Singular
- optional bool id = 1;
- optional bool _cmd = 2;
- optional bool in = 3;
- optional bool out = 4;
- optional bool inout = 5;
- optional bool bycopy = 6;
- optional bool byref = 7;
- optional bool oneway = 8;
- optional bool dealloc = 9;
- optional bool zone = 10;
- optional bool isProxy = 11;
- optional bool copy = 12;
- optional bool readonly = 13;
- optional bool default = 14;
- optional bool assign = 15;
- optional bool getter = 16;
- optional bool setter = 17;
- optional bool weak = 18;
- optional bool public = 19;
- optional bool case = 20;
+ // Objective C Keywords
+ optional bool id = 1;
+ optional bool _cmd = 2;
+ // super is used as submessage above
+ optional bool in = 4;
+ optional bool out = 5;
+ optional bool inout = 6;
+ optional bool bycopy = 7;
+ optional bool byref = 8;
+ optional bool oneway = 9;
+ optional bool self = 10;
+ optional bool instancetype = 11;
+ optional bool nullable = 12;
+ optional bool nonnull = 13;
+ optional bool nil = 14;
+ // Nil and nil can't be in the same message
+ optional bool YES = 16;
+ optional bool NO = 17;
+ optional bool weak = 18;
- optional autorelease SubEnum = 25;
+ // Some C/C++ Keywords
+ optional bool case = 30;
+ optional bool if = 31;
+ optional bool and_eq = 32;
+ optional bool public = 33;
+ optional bool private = 34;
+ optional bool typename = 35;
+ optional bool static_cast = 36;
+ optional bool typeof = 37;
+ optional bool restrict = 38;
+ optional bool NULL = 39;
- optional group New = 50 {
- optional string copy = 51;
- }
- optional group MutableCopy = 60 {
- optional int32 extensionRegistry = 61;
+ // Some NSObject Methods
+ optional bool dealloc = 110;
+ optional bool isProxy = 111;
+ optional bool copy = 112;
+ optional bool description = 113;
+ optional bool zone = 114;
+ optional bool className = 115;
+ optional bool __retain_OA = 116;
+ optional bool CAMLType = 117;
+ optional bool isNSDictionary__ = 118;
+ optional bool accessibilityLabel = 119;
+
+ // Some Objc "keywords" that we shouldn't
+ // have to worry about because they
+ // can only appear in specialized areas.
+ optional bool assign = 200;
+ optional bool getter = 201;
+ optional bool setter = 202;
+ optional bool atomic = 203;
+ optional bool nonatomic = 204;
+ optional bool strong = 205;
+ optional bool null_resettable = 206;
+ optional bool readonly = 207;
+
+ // Some GPBMessage methods
+ optional bool clear = 300;
+ optional bool data = 301;
+ optional bool descriptor = 302;
+ optional bool delimitedData = 303;
+
+ // Some MacTypes
+ optional bool Fixed = 400;
+ optional bool Point = 401;
+ optional bool FixedPoint = 402;
+ optional bool Style = 403;
+
+ // C/C++ reserved identifiers
+ optional bool _Generic = 500;
+ optional bool __block = 501;
+
+ // Try a keyword as a type
+ optional autorelease SubEnum = 1000;
+
+ optional group New = 2000 {
+ optional string copy = 1;
+ }
+ optional group MutableCopy = 2001 {
+ optional int32 extensionRegistry = 1;
}
- extensions 90 to 94;
+ extensions 3000 to 3999;
}
@@ -177,11 +229,11 @@
}
extend self {
- repeated int32 debugDescription = 90 [packed = true];
- repeated int64 finalize = 91 [packed = true];
- repeated uint32 hash = 92 [packed = true];
- repeated uint64 classForCoder = 93 [packed = true];
- repeated sint32 byref = 94 [packed = true];
+ repeated int32 debugDescription = 3000 [packed = true];
+ repeated int64 finalize = 3001 [packed = true];
+ repeated uint32 hash = 3002 [packed = true];
+ repeated uint64 classForCoder = 3003 [packed = true];
+ repeated sint32 byref = 3004 [packed = true];
}
// Test handing of fields that start with init* since Xcode 5's ARC support