Commit 5e933847 authored by Thomas Van Lenten's avatar Thomas Van Lenten

Merge pull request #1325 from thomasvl/shrink_overhead

Shrink ObjC overhead (generated size and some runtime sizes)
parents ca3dc15d 79a23c43
......@@ -381,13 +381,11 @@ objectivec_EXTRA_DIST= \
objectivec/DevTools/full_mac_build.sh \
objectivec/DevTools/pddm.py \
objectivec/DevTools/pddm_tests.py \
objectivec/generate_descriptors_proto.sh \
objectivec/generate_well_known_types.sh \
objectivec/google/protobuf/Any.pbobjc.h \
objectivec/google/protobuf/Any.pbobjc.m \
objectivec/google/protobuf/Api.pbobjc.h \
objectivec/google/protobuf/Api.pbobjc.m \
objectivec/google/protobuf/Descriptor.pbobjc.h \
objectivec/google/protobuf/Descriptor.pbobjc.m \
objectivec/google/protobuf/Duration.pbobjc.h \
objectivec/google/protobuf/Duration.pbobjc.m \
objectivec/google/protobuf/Empty.pbobjc.h \
......
......@@ -17,7 +17,6 @@ Pod::Spec.new do |s|
s.source_files = 'objectivec/*.{h,m}',
'objectivec/google/protobuf/Any.pbobjc.{h,m}',
'objectivec/google/protobuf/Api.pbobjc.{h,m}',
'objectivec/google/protobuf/Descriptor.pbobjc.{h,m}',
'objectivec/google/protobuf/Duration.pbobjc.h',
'objectivec/google/protobuf/Empty.pbobjc.{h,m}',
'objectivec/google/protobuf/FieldMask.pbobjc.{h,m}',
......
......@@ -92,9 +92,9 @@ do
done
cd ..
if test -x objectivec/generate_descriptors_proto.sh; then
if test -x objectivec/generate_well_known_types.sh; then
echo "Generating messages for objc."
objectivec/generate_descriptors_proto.sh $@
objectivec/generate_well_known_types.sh $@
fi
if test -x csharp/generate_protos.sh; then
......
......@@ -67,29 +67,36 @@ fi
# Ensure the output dir exists
mkdir -p "${OUTPUT_DIR}/google/protobuf"
CORE_PROTO_FILES=( \
src/google/protobuf/unittest_arena.proto \
src/google/protobuf/unittest_custom_options.proto \
src/google/protobuf/unittest_enormous_descriptor.proto \
src/google/protobuf/unittest_embed_optimize_for.proto \
src/google/protobuf/unittest_empty.proto \
src/google/protobuf/unittest_import.proto \
src/google/protobuf/unittest_import_lite.proto \
src/google/protobuf/unittest_lite.proto \
src/google/protobuf/unittest_mset.proto \
src/google/protobuf/unittest_mset_wire_format.proto \
src/google/protobuf/unittest_no_arena.proto \
src/google/protobuf/unittest_no_arena_import.proto \
src/google/protobuf/unittest_no_generic_services.proto \
src/google/protobuf/unittest_optimize_for.proto \
src/google/protobuf/unittest.proto \
src/google/protobuf/unittest_import_public.proto \
src/google/protobuf/unittest_import_public_lite.proto \
src/google/protobuf/unittest_drop_unknown_fields.proto \
src/google/protobuf/unittest_preserve_unknown_enum.proto \
src/google/protobuf/map_lite_unittest.proto \
src/google/protobuf/map_proto2_unittest.proto \
src/google/protobuf/map_unittest.proto \
CORE_PROTO_FILES=(
src/google/protobuf/unittest_arena.proto
src/google/protobuf/unittest_custom_options.proto
src/google/protobuf/unittest_enormous_descriptor.proto
src/google/protobuf/unittest_embed_optimize_for.proto
src/google/protobuf/unittest_empty.proto
src/google/protobuf/unittest_import.proto
src/google/protobuf/unittest_import_lite.proto
src/google/protobuf/unittest_lite.proto
src/google/protobuf/unittest_mset.proto
src/google/protobuf/unittest_mset_wire_format.proto
src/google/protobuf/unittest_no_arena.proto
src/google/protobuf/unittest_no_arena_import.proto
src/google/protobuf/unittest_no_generic_services.proto
src/google/protobuf/unittest_optimize_for.proto
src/google/protobuf/unittest.proto
src/google/protobuf/unittest_import_public.proto
src/google/protobuf/unittest_import_public_lite.proto
src/google/protobuf/unittest_drop_unknown_fields.proto
src/google/protobuf/unittest_preserve_unknown_enum.proto
src/google/protobuf/map_lite_unittest.proto
src/google/protobuf/map_proto2_unittest.proto
src/google/protobuf/map_unittest.proto
)
# The unittest_custom_options.proto extends the messages in descriptor.proto
# so we build it in to test extending in general. The library doesn't provide
# a descriptor as it doesn't use the classes/enums.
CORE_PROTO_FILES+=(
src/google/protobuf/descriptor.proto
)
compile_proto() {
......@@ -104,12 +111,12 @@ for a_proto in "${CORE_PROTO_FILES[@]}" ; do
compile_proto "${a_proto}"
done
OBJC_PROTO_FILES=( \
objectivec/Tests/unittest_cycle.proto \
objectivec/Tests/unittest_runtime_proto2.proto \
objectivec/Tests/unittest_runtime_proto3.proto \
objectivec/Tests/unittest_objc.proto \
objectivec/Tests/unittest_objc_startup.proto \
OBJC_PROTO_FILES=(
objectivec/Tests/unittest_cycle.proto
objectivec/Tests/unittest_runtime_proto2.proto
objectivec/Tests/unittest_runtime_proto3.proto
objectivec/Tests/unittest_objc.proto
objectivec/Tests/unittest_objc_startup.proto
)
for a_proto in "${OBJC_PROTO_FILES[@]}" ; do
......
......@@ -190,7 +190,7 @@ header "Ensuring the ObjC descriptors are current."
readonly NewestInput=$(find \
src/google/protobuf/*.proto \
src/.libs src/*.la src/protoc \
objectivec/generate_descriptors_proto.sh \
objectivec/generate_well_known_types.sh \
-type f -print0 \
| xargs -0 stat -f "%m %N" \
| sort -n | tail -n1 | cut -f2- -d" ")
......@@ -203,7 +203,7 @@ readonly OldestOutput=$(find \
# If the newest input is newer than the oldest output, regenerate.
if [[ "${NewestInput}" -nt "${OldestOutput}" ]] ; then
echo ">> Newest input is newer than oldest output, regenerating."
objectivec/generate_descriptors_proto.sh -j "${NUM_MAKE_JOBS}"
objectivec/generate_well_known_types.sh -j "${NUM_MAKE_JOBS}"
else
echo ">> Newest input is older than oldest output, no need to regenerating."
fi
......
......@@ -37,13 +37,6 @@
#define GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS 0
#endif
// Most uses of protocol buffers don't need field options, by default the
// static data will be compiled out, define this to 1 to include it. The only
// time you need this is if you are doing introspection of the protocol buffers.
#ifndef GPBOBJC_INCLUDE_FIELD_OPTIONS
#define GPBOBJC_INCLUDE_FIELD_OPTIONS 0
#endif
// Used in the generated code to give sizes to enums. int32_t was chosen based
// on the fact that Protocol Buffers enums are limited to this range.
#if !__has_feature(objc_fixed_enum)
......@@ -89,4 +82,4 @@
// generated Objective C sources. In general we don't want to change the
// runtime interfaces (or this version) as it means everything has to be
// regenerated.
#define GOOGLE_PROTOBUF_OBJC_GEN_VERSION 30000
#define GOOGLE_PROTOBUF_OBJC_GEN_VERSION 30001
......@@ -34,19 +34,18 @@
@class GPBEnumDescriptor;
@class GPBFieldDescriptor;
@class GPBFieldOptions;
@class GPBFileDescriptor;
@class GPBOneofDescriptor;
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger, GPBFileSyntax) {
typedef NS_ENUM(uint8_t, GPBFileSyntax) {
GPBFileSyntaxUnknown = 0,
GPBFileSyntaxProto2 = 2,
GPBFileSyntaxProto3 = 3,
};
typedef NS_ENUM(NSInteger, GPBFieldType) {
typedef NS_ENUM(uint8_t, GPBFieldType) {
GPBFieldTypeSingle, // optional/required
GPBFieldTypeRepeated, // repeated
GPBFieldTypeMap, // map<K,V>
......@@ -57,9 +56,8 @@ typedef NS_ENUM(NSInteger, GPBFieldType) {
@property(nonatomic, readonly, copy) NSString *name;
@property(nonatomic, readonly, strong, nullable) NSArray<GPBFieldDescriptor*> *fields;
@property(nonatomic, readonly, strong, nullable) NSArray<GPBOneofDescriptor*> *oneofs;
@property(nonatomic, readonly, strong, nullable) NSArray<GPBEnumDescriptor*> *enums;
@property(nonatomic, readonly, nullable) const GPBExtensionRange *extensionRanges;
@property(nonatomic, readonly) NSUInteger extensionRangesCount;
@property(nonatomic, readonly) uint32_t extensionRangesCount;
@property(nonatomic, readonly, assign) GPBFileDescriptor *file;
@property(nonatomic, readonly, getter=isWireFormat) BOOL wireFormat;
......@@ -68,7 +66,6 @@ typedef NS_ENUM(NSInteger, GPBFieldType) {
- (nullable GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber;
- (nullable GPBFieldDescriptor *)fieldWithName:(NSString *)name;
- (nullable GPBOneofDescriptor *)oneofWithName:(NSString *)name;
- (nullable GPBEnumDescriptor *)enumWithName:(NSString *)name;
@end
......@@ -103,8 +100,6 @@ typedef NS_ENUM(NSInteger, GPBFieldType) {
@property(nonatomic, readonly, assign, nullable) GPBOneofDescriptor *containingOneof;
@property(nonatomic, readonly, nullable) GPBFieldOptions *fieldOptions;
// Message properties
@property(nonatomic, readonly, assign, nullable) Class msgClass;
......
This diff is collapsed.
This diff is collapsed.
......@@ -54,18 +54,6 @@ NSString *const GPBExceptionMessageKey =
static NSString *const kGPBDataCoderKey = @"GPBData";
#ifndef _GPBCompileAssert
#if __has_feature(c_static_assert) || __has_extension(c_static_assert)
#define _GPBCompileAssert(test, msg) _Static_assert((test), #msg)
#else
// Pre-Xcode 7 support.
#define _GPBCompileAssertSymbolInner(line, msg) _GPBCompileAssert ## line ## __ ## msg
#define _GPBCompileAssertSymbol(line, msg) _GPBCompileAssertSymbolInner(line, msg)
#define _GPBCompileAssert(test, msg) \
typedef char _GPBCompileAssertSymbol(__LINE__, msg) [ ((test) ? 1 : -1) ]
#endif // __has_feature(c_static_assert) || __has_extension(c_static_assert)
#endif // _GPBCompileAssert
//
// PLEASE REMEMBER:
//
......@@ -789,14 +777,8 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
file:fileDescriptor
fields:NULL
fieldCount:0
oneofs:NULL
oneofCount:0
enums:NULL
enumCount:0
ranges:NULL
rangeCount:0
storageSize:0
wireFormat:NO];
flags:0];
}
return descriptor;
}
......@@ -3096,7 +3078,7 @@ static void ResolveIvarSet(GPBFieldDescriptor *field,
} else {
GPBOneofDescriptor *oneof = field->containingOneof_;
if (oneof && (sel == oneof->caseSel_)) {
int32_t index = oneof->oneofDescription_->index;
int32_t index = GPBFieldHasIndex(field);
result.impToAdd = imp_implementationWithBlock(^(id obj) {
return GPBGetHasOneof(obj, index);
});
......
......@@ -46,8 +46,6 @@
#import "GPBWellKnownTypes.m"
#import "GPBWireFormat.m"
#import "google/protobuf/Descriptor.pbobjc.m"
// Duration and Timestamp are #imported into GPBWellKnownTypes.m to the
// Objective C categories added will always be linked in with the classes.
#import "google/protobuf/Any.pbobjc.m"
......
......@@ -67,7 +67,7 @@ typedef union {
// Do not change the order of this enum (or add things to it) without thinking
// about it very carefully. There are several things that depend on the order.
typedef enum {
typedef NS_ENUM(uint8_t, GPBDataType) {
GPBDataTypeBool = 0,
GPBDataTypeFixed32,
GPBDataTypeSFixed32,
......@@ -86,7 +86,7 @@ typedef enum {
GPBDataTypeMessage,
GPBDataTypeGroup,
GPBDataTypeEnum,
} GPBDataType;
};
enum {
// A count of the number of types in GPBDataType. Separated out from the
......
......@@ -145,9 +145,8 @@ void GPBSetHasIvar(GPBMessage *self, int32_t idx, uint32_t fieldNumber,
}
void GPBMaybeClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof,
uint32_t fieldNumberNotToClear) {
int32_t hasIndex = oneof->oneofDescription_->index;
uint32_t fieldNumberSet = GPBGetHasOneof(self, hasIndex);
int32_t oneofHasIndex, uint32_t fieldNumberNotToClear) {
uint32_t fieldNumberSet = GPBGetHasOneof(self, oneofHasIndex);
if ((fieldNumberSet == fieldNumberNotToClear) || (fieldNumberSet == 0)) {
// Do nothing/nothing set in the oneof.
return;
......@@ -168,7 +167,7 @@ void GPBMaybeClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof,
// Set to nothing stored in the oneof.
// (field number doesn't matter since setting to nothing).
GPBSetHasIvar(self, hasIndex, 1, NO);
GPBSetHasIvar(self, oneofHasIndex, 1, NO);
}
#pragma mark - IVar accessors
......@@ -200,7 +199,8 @@ void GPBMaybeClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof,
//% NAME$S GPBFileSyntax syntax) {
//% GPBOneofDescriptor *oneof = field->containingOneof_;
//% if (oneof) {
//% GPBMaybeClearOneof(self, oneof, GPBFieldNumber(field));
//% GPBMessageFieldDescription *fieldDesc = field->description_;
//% GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
//% }
//% NSCAssert(self->messageStorage_ != NULL,
//% @"%@: All messages should have storage (from init)",
......@@ -321,7 +321,8 @@ void GPBSetRetainedObjectIvarWithFieldInternal(GPBMessage *self,
// oneof.
GPBOneofDescriptor *oneof = field->containingOneof_;
if (oneof) {
GPBMaybeClearOneof(self, oneof, GPBFieldNumber(field));
GPBMessageFieldDescription *fieldDesc = field->description_;
GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
}
// Clear "has" if they are being set to nil.
BOOL setHasValue = (value != nil);
......@@ -476,15 +477,15 @@ void GPBSetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field,
GPBSetInt32IvarWithFieldInternal(self, field, value, syntax);
}
//%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(Bool, BOOL)
// This block of code is generated, do not edit it directly.
BOOL GPBGetMessageBoolField(GPBMessage *self,
GPBFieldDescriptor *field) {
if (GPBGetHasIvarField(self, field)) {
uint8_t *storage = (uint8_t *)self->messageStorage_;
BOOL *typePtr = (BOOL *)&storage[field->description_->offset];
return *typePtr;
// Bools are stored in the has bits to avoid needing explicit space in the
// storage structure.
// (the field number passed to the HasIvar helper doesn't really matter
// since the offset is never negative)
GPBMessageFieldDescription *fieldDesc = field->description_;
return GPBGetHasIvar(self, (int32_t)(fieldDesc->offset), fieldDesc->number);
} else {
return field.defaultValue.valueBool;
}
......@@ -503,19 +504,18 @@ void GPBSetBoolIvarWithFieldInternal(GPBMessage *self,
GPBFieldDescriptor *field,
BOOL value,
GPBFileSyntax syntax) {
GPBMessageFieldDescription *fieldDesc = field->description_;
GPBOneofDescriptor *oneof = field->containingOneof_;
if (oneof) {
GPBMaybeClearOneof(self, oneof, GPBFieldNumber(field));
GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
}
NSCAssert(self->messageStorage_ != NULL,
@"%@: All messages should have storage (from init)",
[self class]);
#if defined(__clang_analyzer__)
if (self->messageStorage_ == NULL) return;
#endif
uint8_t *storage = (uint8_t *)self->messageStorage_;
BOOL *typePtr = (BOOL *)&storage[field->description_->offset];
*typePtr = value;
// Bools are stored in the has bits to avoid needing explicit space in the
// storage structure.
// (the field number passed to the HasIvar helper doesn't really matter since
// the offset is never negative)
GPBSetHasIvar(self, (int32_t)(fieldDesc->offset), fieldDesc->number, value);
// proto2: any value counts as having been set; proto3, it
// has to be a non zero value.
BOOL hasValue =
......@@ -553,7 +553,8 @@ void GPBSetInt32IvarWithFieldInternal(GPBMessage *self,
GPBFileSyntax syntax) {
GPBOneofDescriptor *oneof = field->containingOneof_;
if (oneof) {
GPBMaybeClearOneof(self, oneof, GPBFieldNumber(field));
GPBMessageFieldDescription *fieldDesc = field->description_;
GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
}
NSCAssert(self->messageStorage_ != NULL,
@"%@: All messages should have storage (from init)",
......@@ -601,7 +602,8 @@ void GPBSetUInt32IvarWithFieldInternal(GPBMessage *self,
GPBFileSyntax syntax) {
GPBOneofDescriptor *oneof = field->containingOneof_;
if (oneof) {
GPBMaybeClearOneof(self, oneof, GPBFieldNumber(field));
GPBMessageFieldDescription *fieldDesc = field->description_;
GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
}
NSCAssert(self->messageStorage_ != NULL,
@"%@: All messages should have storage (from init)",
......@@ -649,7 +651,8 @@ void GPBSetInt64IvarWithFieldInternal(GPBMessage *self,
GPBFileSyntax syntax) {
GPBOneofDescriptor *oneof = field->containingOneof_;
if (oneof) {
GPBMaybeClearOneof(self, oneof, GPBFieldNumber(field));
GPBMessageFieldDescription *fieldDesc = field->description_;
GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
}
NSCAssert(self->messageStorage_ != NULL,
@"%@: All messages should have storage (from init)",
......@@ -697,7 +700,8 @@ void GPBSetUInt64IvarWithFieldInternal(GPBMessage *self,
GPBFileSyntax syntax) {
GPBOneofDescriptor *oneof = field->containingOneof_;
if (oneof) {
GPBMaybeClearOneof(self, oneof, GPBFieldNumber(field));
GPBMessageFieldDescription *fieldDesc = field->description_;
GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
}
NSCAssert(self->messageStorage_ != NULL,
@"%@: All messages should have storage (from init)",
......@@ -745,7 +749,8 @@ void GPBSetFloatIvarWithFieldInternal(GPBMessage *self,
GPBFileSyntax syntax) {
GPBOneofDescriptor *oneof = field->containingOneof_;
if (oneof) {
GPBMaybeClearOneof(self, oneof, GPBFieldNumber(field));
GPBMessageFieldDescription *fieldDesc = field->description_;
GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
}
NSCAssert(self->messageStorage_ != NULL,
@"%@: All messages should have storage (from init)",
......@@ -793,7 +798,8 @@ void GPBSetDoubleIvarWithFieldInternal(GPBMessage *self,
GPBFileSyntax syntax) {
GPBOneofDescriptor *oneof = field->containingOneof_;
if (oneof) {
GPBMaybeClearOneof(self, oneof, GPBFieldNumber(field));
GPBMessageFieldDescription *fieldDesc = field->description_;
GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
}
NSCAssert(self->messageStorage_ != NULL,
@"%@: All messages should have storage (from init)",
......@@ -812,7 +818,7 @@ void GPBSetDoubleIvarWithFieldInternal(GPBMessage *self,
GPBBecomeVisibleToAutocreator(self);
}
//%PDDM-EXPAND-END (7 expansions)
//%PDDM-EXPAND-END (6 expansions)
// Aliases are function calls that are virtually the same.
......
......@@ -185,7 +185,7 @@ GPB_INLINE void GPBSetHasIvarField(GPBMessage *self, GPBFieldDescriptor *field,
}
void GPBMaybeClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof,
uint32_t fieldNumberNotToClear);
int32_t oneofHasIndex, uint32_t fieldNumberNotToClear);
//%PDDM-DEFINE GPB_IVAR_SET_DECL(NAME, TYPE)
//%void GPBSet##NAME##IvarWithFieldInternal(GPBMessage *self,
......
......@@ -7,7 +7,6 @@
objects = {
/* Begin PBXBuildFile section */
2CFB390415C718CE00CBF84D /* Descriptor.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BD3982214BE5B0C0081D629 /* Descriptor.pbobjc.m */; };
5102DABC1891A073002037B6 /* GPBConcurrencyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5102DABB1891A052002037B6 /* GPBConcurrencyTests.m */; };
7461B5360F94FB4600A0C422 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
7461B53C0F94FB4E00A0C422 /* GPBCodedInputStream.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B48F0F94F99000A0C422 /* GPBCodedInputStream.m */; };
......@@ -27,7 +26,6 @@
8B79657D14992E3F002FFBFC /* GPBRootObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B79657914992E3E002FFBFC /* GPBRootObject.m */; };
8B8B615D17DF7056002EE618 /* GPBARCUnittestProtos.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B8B615C17DF7056002EE618 /* GPBARCUnittestProtos.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; };
8B96157414C8C38C00A2AC0B /* GPBDescriptor.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B96157314C8C38C00A2AC0B /* GPBDescriptor.m */; };
8B96157514CA019D00A2AC0B /* Descriptor.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BD3982214BE5B0C0081D629 /* Descriptor.pbobjc.m */; };
8BBEA4A9147C727D00C4ADB7 /* GPBCodedInputStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B69B0F94FDF800A0C422 /* GPBCodedInputStreamTests.m */; };
8BBEA4AA147C727D00C4ADB7 /* GPBCodedOuputStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B69D0F94FDF800A0C422 /* GPBCodedOuputStreamTests.m */; };
8BBEA4AC147C727D00C4ADB7 /* GPBMessageTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */; };
......@@ -140,10 +138,8 @@
8B4248D51A92826400BC1EC6 /* Timestamp.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Timestamp.pbobjc.h; path = google/protobuf/Timestamp.pbobjc.h; sourceTree = "<group>"; };
8B4248D61A92826400BC1EC6 /* Timestamp.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Timestamp.pbobjc.m; path = google/protobuf/Timestamp.pbobjc.m; sourceTree = "<group>"; };
8B4248DB1A92933A00BC1EC6 /* GPBWellKnownTypesTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBWellKnownTypesTest.m; sourceTree = "<group>"; };
8B42494B1A92A16600BC1EC6 /* descriptor.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = descriptor.proto; path = ../src/google/protobuf/descriptor.proto; sourceTree = "<group>"; };
8B42494C1A92A16600BC1EC6 /* duration.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = duration.proto; path = ../src/google/protobuf/duration.proto; sourceTree = "<group>"; };
8B42494D1A92A16600BC1EC6 /* timestamp.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = timestamp.proto; path = ../src/google/protobuf/timestamp.proto; sourceTree = "<group>"; };
8B54585814DCC34E003D7338 /* Descriptor.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Descriptor.pbobjc.h; path = google/protobuf/Descriptor.pbobjc.h; sourceTree = SOURCE_ROOT; };
8B79657814992E3E002FFBFC /* GPBRootObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBRootObject.h; sourceTree = "<group>"; };
8B79657914992E3E002FFBFC /* GPBRootObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBRootObject.m; sourceTree = "<group>"; };
8B7E6A7414893DBA00F8884A /* unittest_custom_options.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_custom_options.proto; path = ../../src/google/protobuf/unittest_custom_options.proto; sourceTree = "<group>"; };
......@@ -162,7 +158,6 @@
8BCF338814ED799900BC5317 /* GPBProtocolBuffers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GPBProtocolBuffers.m; sourceTree = "<group>"; };
8BD3981D14BE54220081D629 /* unittest_enormous_descriptor.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_enormous_descriptor.proto; path = ../../src/google/protobuf/unittest_enormous_descriptor.proto; sourceTree = "<group>"; };
8BD3981E14BE59D70081D629 /* GPBUnittestProtos.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnittestProtos.m; sourceTree = "<group>"; };
8BD3982214BE5B0C0081D629 /* Descriptor.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Descriptor.pbobjc.m; path = google/protobuf/Descriptor.pbobjc.m; sourceTree = SOURCE_ROOT; };
8BEB5AE01498033E0078BF9D /* GPBRuntimeTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBRuntimeTypes.h; sourceTree = "<group>"; };
F401DC2A1A8D444600FCC765 /* GPBArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBArray.h; sourceTree = "<group>"; };
F401DC2B1A8D444600FCC765 /* GPBArray.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBArray.m; sourceTree = "<group>"; };
......@@ -300,9 +295,6 @@
F4E675881B21D0000054530B /* Api.pbobjc.h */,
F4E675891B21D0000054530B /* Api.pbobjc.m */,
F4E675A71B21D05C0054530B /* api.proto */,
8B54585814DCC34E003D7338 /* Descriptor.pbobjc.h */,
8BD3982214BE5B0C0081D629 /* Descriptor.pbobjc.m */,
8B42494B1A92A16600BC1EC6 /* descriptor.proto */,
8B4248D31A92826400BC1EC6 /* Duration.pbobjc.h */,
8B4248D41A92826400BC1EC6 /* Duration.pbobjc.m */,
8B42494C1A92A16600BC1EC6 /* duration.proto */,
......@@ -634,7 +626,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
2CFB390415C718CE00CBF84D /* Descriptor.pbobjc.m in Sources */,
7461B53C0F94FB4E00A0C422 /* GPBCodedInputStream.m in Sources */,
F4E6759B1B21D0000054530B /* Empty.pbobjc.m in Sources */,
7461B53D0F94FB4E00A0C422 /* GPBCodedOutputStream.m in Sources */,
......@@ -696,7 +687,6 @@
8B79657D14992E3F002FFBFC /* GPBRootObject.m in Sources */,
8BD3981F14BE59D70081D629 /* GPBUnittestProtos.m in Sources */,
F4E675B11B21D0A70054530B /* FieldMask.pbobjc.m in Sources */,
8B96157514CA019D00A2AC0B /* Descriptor.pbobjc.m in Sources */,
8B8B615D17DF7056002EE618 /* GPBARCUnittestProtos.m in Sources */,
F4E675AF1B21D0A70054530B /* Api.pbobjc.m in Sources */,
);
......
......@@ -7,7 +7,6 @@
objects = {
/* Begin PBXBuildFile section */
2CFB390415C718CE00CBF84D /* Descriptor.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BD3982214BE5B0C0081D629 /* Descriptor.pbobjc.m */; };
5102DABC1891A073002037B6 /* GPBConcurrencyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5102DABB1891A052002037B6 /* GPBConcurrencyTests.m */; };
7461B5360F94FB4600A0C422 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
7461B53C0F94FB4E00A0C422 /* GPBCodedInputStream.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B48F0F94F99000A0C422 /* GPBCodedInputStream.m */; };
......@@ -27,7 +26,6 @@
8B79657D14992E3F002FFBFC /* GPBRootObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B79657914992E3E002FFBFC /* GPBRootObject.m */; };
8B8B615D17DF7056002EE618 /* GPBARCUnittestProtos.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B8B615C17DF7056002EE618 /* GPBARCUnittestProtos.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; };
8B96157414C8C38C00A2AC0B /* GPBDescriptor.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B96157314C8C38C00A2AC0B /* GPBDescriptor.m */; };
8B96157514CA019D00A2AC0B /* Descriptor.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BD3982214BE5B0C0081D629 /* Descriptor.pbobjc.m */; };
8B9742331A89D19F00DCE92C /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8B9742321A89D19F00DCE92C /* LaunchScreen.xib */; };
8B9742431A8AAA7800DCE92C /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9742421A8AAA7800DCE92C /* CoreGraphics.framework */; };
8B9A5EA61831993600A9D33B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
......@@ -155,7 +153,6 @@
8B4248E21A929C8900BC1EC6 /* GPBWellKnownTypes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBWellKnownTypes.m; sourceTree = "<group>"; };
8B4248E51A929C9900BC1EC6 /* GPBWellKnownTypesTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBWellKnownTypesTest.m; sourceTree = "<group>"; };
8B4249481A92A02300BC1EC6 /* timestamp.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = timestamp.proto; path = ../src/google/protobuf/timestamp.proto; sourceTree = "<group>"; };
8B4249491A92A0BA00BC1EC6 /* descriptor.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = descriptor.proto; path = ../src/google/protobuf/descriptor.proto; sourceTree = "<group>"; };
8B42494A1A92A0BA00BC1EC6 /* duration.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = duration.proto; path = ../src/google/protobuf/duration.proto; sourceTree = "<group>"; };
8B79657814992E3E002FFBFC /* GPBRootObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBRootObject.h; sourceTree = "<group>"; };
8B79657914992E3E002FFBFC /* GPBRootObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBRootObject.m; sourceTree = "<group>"; };
......@@ -183,7 +180,6 @@
8BCF338814ED799900BC5317 /* GPBProtocolBuffers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GPBProtocolBuffers.m; sourceTree = "<group>"; };
8BD3981D14BE54220081D629 /* unittest_enormous_descriptor.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_enormous_descriptor.proto; path = ../../src/google/protobuf/unittest_enormous_descriptor.proto; sourceTree = "<group>"; };
8BD3981E14BE59D70081D629 /* GPBUnittestProtos.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnittestProtos.m; sourceTree = "<group>"; };
8BD3982214BE5B0C0081D629 /* Descriptor.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Descriptor.pbobjc.m; path = google/protobuf/Descriptor.pbobjc.m; sourceTree = SOURCE_ROOT; };
8BEB5AE01498033E0078BF9D /* GPBRuntimeTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBRuntimeTypes.h; sourceTree = "<group>"; };
F401DC341A8E5C6F00FCC765 /* GPBArrayTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBArrayTests.m; sourceTree = "<group>"; };
F41C175C1833D3310064ED4D /* GPBPerfTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBPerfTests.m; sourceTree = "<group>"; };
......@@ -224,7 +220,6 @@
F4E675B71B21D1440054530B /* Any.pbobjc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = Any.pbobjc.m; path = google/protobuf/Any.pbobjc.m; sourceTree = "<group>"; };
F4E675B81B21D1440054530B /* Api.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Api.pbobjc.h; path = google/protobuf/Api.pbobjc.h; sourceTree = "<group>"; };
F4E675B91B21D1440054530B /* Api.pbobjc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = Api.pbobjc.m; path = google/protobuf/Api.pbobjc.m; sourceTree = "<group>"; };
F4E675BA1B21D1440054530B /* Descriptor.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Descriptor.pbobjc.h; path = google/protobuf/Descriptor.pbobjc.h; sourceTree = "<group>"; };
F4E675BB1B21D1440054530B /* Empty.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Empty.pbobjc.h; path = google/protobuf/Empty.pbobjc.h; sourceTree = "<group>"; };
F4E675BC1B21D1440054530B /* Empty.pbobjc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = Empty.pbobjc.m; path = google/protobuf/Empty.pbobjc.m; sourceTree = "<group>"; };
F4E675BD1B21D1440054530B /* FieldMask.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = FieldMask.pbobjc.h; path = google/protobuf/FieldMask.pbobjc.h; sourceTree = "<group>"; };
......@@ -335,9 +330,6 @@
F4E675B81B21D1440054530B /* Api.pbobjc.h */,
F4E675B91B21D1440054530B /* Api.pbobjc.m */,
F4E675D91B21D1DE0054530B /* api.proto */,
F4E675BA1B21D1440054530B /* Descriptor.pbobjc.h */,
8BD3982214BE5B0C0081D629 /* Descriptor.pbobjc.m */,
8B4249491A92A0BA00BC1EC6 /* descriptor.proto */,
8B4248DD1A929C7D00BC1EC6 /* Duration.pbobjc.h */,
8B4248DE1A929C7D00BC1EC6 /* Duration.pbobjc.m */,
8B42494A1A92A0BA00BC1EC6 /* duration.proto */,
......@@ -722,7 +714,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
2CFB390415C718CE00CBF84D /* Descriptor.pbobjc.m in Sources */,
7461B53C0F94FB4E00A0C422 /* GPBCodedInputStream.m in Sources */,
F4E675D21B21D1620054530B /* Empty.pbobjc.m in Sources */,
F4487C731A9F906200531423 /* GPBArray.m in Sources */,
......@@ -792,7 +783,6 @@
8B79657D14992E3F002FFBFC /* GPBRootObject.m in Sources */,
8BD3981F14BE59D70081D629 /* GPBUnittestProtos.m in Sources */,
F4E675CB1B21D1610054530B /* FieldMask.pbobjc.m in Sources */,
8B96157514CA019D00A2AC0B /* Descriptor.pbobjc.m in Sources */,
8B8B615D17DF7056002EE618 /* GPBARCUnittestProtos.m in Sources */,
F4E675C91B21D1610054530B /* Api.pbobjc.m in Sources */,
);
......
......@@ -34,6 +34,11 @@
// Makes sure all the generated headers compile with ARC on.
// The unittest_custom_options.proto extends the messages in descriptor.proto
// so we build it in to test extending in general. The library doesn't provide
// a descriptor as it doesn't use the classes/enums.
#import "google/protobuf/Descriptor.pbobjc.h"
#import "google/protobuf/Unittest.pbobjc.h"
#import "google/protobuf/UnittestCustomOptions.pbobjc.h"
#import "google/protobuf/UnittestCycle.pbobjc.h"
......
......@@ -153,19 +153,6 @@
XCTAssertFalse([fieldDescriptor isValidEnumValue:-2]);
}
- (void)testEnumDescriptorLookup {
GPBDescriptor *descriptor = [TestAllTypes descriptor];
GPBEnumDescriptor *enumDescriptor =
[descriptor enumWithName:@"TestAllTypes_NestedEnum"];
XCTAssertNotNil(enumDescriptor);
// Descriptor cannot find foreign or imported enums.
enumDescriptor = [descriptor enumWithName:@"ForeignEnumEnum"];
XCTAssertNil(enumDescriptor);
enumDescriptor = [descriptor enumWithName:@"ImportEnumEnum"];
XCTAssertNil(enumDescriptor);
}
- (void)testOneofDescriptor {
GPBDescriptor *descriptor = [TestOneof2 descriptor];
......
......@@ -31,6 +31,11 @@
// Collects all the compiled protos into one file and compiles them to make sure
// the compiler is generating valid code.
// The unittest_custom_options.proto extends the messages in descriptor.proto
// so we build it in to test extending in general. The library doesn't provide
// a descriptor as it doesn't use the classes/enums.
#import "google/protobuf/Descriptor.pbobjc.m"
#import "google/protobuf/MapProto2Unittest.pbobjc.m"
#import "google/protobuf/MapUnittest.pbobjc.m"
#import "google/protobuf/Unittest.pbobjc.m"
......
#!/bin/bash
# Run this script to regenerate descriptor.pbobjc.{h,m} after the protocol
# compiler changes.
# Run this script to regenerate *.pbobjc.{h,m} for the well known types after
# the protocol compiler changes.
# HINT: Flags passed to generate_descriptor_proto.sh will be passed directly
# HINT: Flags passed to generate_well_known_types.sh will be passed directly
# to make when building protoc. This is particularly useful for passing
# -j4 to run 4 jobs simultaneously.
......@@ -37,7 +37,6 @@ make $@ protoc
declare -a RUNTIME_PROTO_FILES=( \
google/protobuf/any.proto \
google/protobuf/api.proto \
google/protobuf/descriptor.proto \
google/protobuf/duration.proto \
google/protobuf/empty.proto \
google/protobuf/field_mask.proto \
......
......@@ -3,7 +3,7 @@
#import "GPBProtocolBuffers.h"
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 30000
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 30001
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#endif
......
......@@ -46,47 +46,36 @@ typedef struct GPBAny__storage_ {
static GPBMessageFieldDescription fields[] = {
{
.name = "typeURL",
.dataTypeSpecific.className = NULL,
.number = GPBAny_FieldNumber_TypeURL,
.hasIndex = 0,
.offset = (uint32_t)offsetof(GPBAny__storage_, typeURL),
.flags = GPBFieldOptional | GPBFieldTextFormatNameCustom,
.dataType = GPBDataTypeString,
.offset = offsetof(GPBAny__storage_, typeURL),
.defaultValue.valueString = nil,
.dataTypeSpecific.className = NULL,
.fieldOptions = NULL,
},
{
.name = "value",
.dataTypeSpecific.className = NULL,
.number = GPBAny_FieldNumber_Value,
.hasIndex = 1,
.offset = (uint32_t)offsetof(GPBAny__storage_, value),
.flags = GPBFieldOptional,
.dataType = GPBDataTypeBytes,
.offset = offsetof(GPBAny__storage_, value),
.defaultValue.valueData = nil,
.dataTypeSpecific.className = NULL,
.fieldOptions = NULL,
},
};
#if GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
const char *extraTextFormatInfo = NULL;
#else
static const char *extraTextFormatInfo = "\001\001\004\241!!\000";
#endif // GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
GPBDescriptor *localDescriptor =
[GPBDescriptor allocDescriptorForClass:[GPBAny class]
rootClass:[GPBAnyRoot class]
file:GPBAnyRoot_FileDescriptor()
fields:fields
fieldCount:sizeof(fields) / sizeof(GPBMessageFieldDescription)
oneofs:NULL
oneofCount:0
enums:NULL
enumCount:0
ranges:NULL
rangeCount:0
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBAny__storage_)
wireFormat:NO
extraTextFormatInfo:extraTextFormatInfo];
flags:0];
#if !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
static const char *extraTextFormatInfo =
"\001\001\004\241!!\000";
[localDescriptor setupExtraTextInfo:extraTextFormatInfo];
#endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
NSAssert(descriptor == nil, @"Startup recursed!");
descriptor = localDescriptor;
}
......
......@@ -3,7 +3,7 @@
#import "GPBProtocolBuffers.h"
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 30000
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 30001
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#endif
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -3,7 +3,7 @@
#import "GPBProtocolBuffers.h"
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 30000
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 30001
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#endif
......
......@@ -46,25 +46,21 @@ typedef struct GPBDuration__storage_ {
static GPBMessageFieldDescription fields[] = {
{
.name = "seconds",
.dataTypeSpecific.className = NULL,
.number = GPBDuration_FieldNumber_Seconds,
.hasIndex = 0,
.offset = (uint32_t)offsetof(GPBDuration__storage_, seconds),
.flags = GPBFieldOptional,
.dataType = GPBDataTypeInt64,
.offset = offsetof(GPBDuration__storage_, seconds),
.defaultValue.valueInt64 = 0LL,
.dataTypeSpecific.className = NULL,
.fieldOptions = NULL,
},
{
.name = "nanos",
.dataTypeSpecific.className = NULL,
.number = GPBDuration_FieldNumber_Nanos,
.hasIndex = 1,
.offset = (uint32_t)offsetof(GPBDuration__storage_, nanos),
.flags = GPBFieldOptional,
.dataType = GPBDataTypeInt32,
.offset = offsetof(GPBDuration__storage_, nanos),
.defaultValue.valueInt32 = 0,
.dataTypeSpecific.className = NULL,
.fieldOptions = NULL,
},
};
GPBDescriptor *localDescriptor =
......@@ -72,15 +68,9 @@ typedef struct GPBDuration__storage_ {
rootClass:[GPBDurationRoot class]
file:GPBDurationRoot_FileDescriptor()
fields:fields
fieldCount:sizeof(fields) / sizeof(GPBMessageFieldDescription)
oneofs:NULL
oneofCount:0
enums:NULL
enumCount:0
ranges:NULL
rangeCount:0
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBDuration__storage_)
wireFormat:NO];
flags:0];
NSAssert(descriptor == nil, @"Startup recursed!");
descriptor = localDescriptor;
}
......
......@@ -3,7 +3,7 @@
#import "GPBProtocolBuffers.h"
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 30000
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 30001
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#endif
......
......@@ -31,7 +31,7 @@ static GPBFileDescriptor *GPBEmptyRoot_FileDescriptor(void) {
typedef struct GPBEmpty__storage_ {
uint32_t _has_storage_[0];
uint32_t _has_storage_[1];
} GPBEmpty__storage_;
// This method is threadsafe because it is initially called
......@@ -45,14 +45,8 @@ typedef struct GPBEmpty__storage_ {
file:GPBEmptyRoot_FileDescriptor()
fields:NULL
fieldCount:0
oneofs:NULL
oneofCount:0
enums:NULL
enumCount:0
ranges:NULL
rangeCount:0
storageSize:sizeof(GPBEmpty__storage_)
wireFormat:NO];
flags:0];
NSAssert(descriptor == nil, @"Startup recursed!");
descriptor = localDescriptor;
}
......
......@@ -3,7 +3,7 @@
#import "GPBProtocolBuffers.h"
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 30000
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 30001
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#endif
......
......@@ -44,14 +44,12 @@ typedef struct GPBFieldMask__storage_ {
static GPBMessageFieldDescription fields[] = {
{
.name = "pathsArray",
.dataTypeSpecific.className = NULL,
.number = GPBFieldMask_FieldNumber_PathsArray,
.hasIndex = GPBNoHasBit,
.offset = (uint32_t)offsetof(GPBFieldMask__storage_, pathsArray),
.flags = GPBFieldRepeated,
.dataType = GPBDataTypeString,
.offset = offsetof(GPBFieldMask__storage_, pathsArray),
.defaultValue.valueMessage = nil,
.dataTypeSpecific.className = NULL,
.fieldOptions = NULL,
},
};
GPBDescriptor *localDescriptor =
......@@ -59,15 +57,9 @@ typedef struct GPBFieldMask__storage_ {
rootClass:[GPBFieldMaskRoot class]
file:GPBFieldMaskRoot_FileDescriptor()
fields:fields
fieldCount:sizeof(fields) / sizeof(GPBMessageFieldDescription)
oneofs:NULL
oneofCount:0
enums:NULL
enumCount:0
ranges:NULL
rangeCount:0
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBFieldMask__storage_)
wireFormat:NO];
flags:0];
NSAssert(descriptor == nil, @"Startup recursed!");
descriptor = localDescriptor;
}
......
......@@ -3,7 +3,7 @@
#import "GPBProtocolBuffers.h"
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 30000
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 30001
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#endif
......
......@@ -44,14 +44,12 @@ typedef struct GPBSourceContext__storage_ {
static GPBMessageFieldDescription fields[] = {
{
.name = "fileName",
.dataTypeSpecific.className = NULL,
.number = GPBSourceContext_FieldNumber_FileName,
.hasIndex = 0,
.offset = (uint32_t)offsetof(GPBSourceContext__storage_, fileName),
.flags = GPBFieldOptional,
.dataType = GPBDataTypeString,
.offset = offsetof(GPBSourceContext__storage_, fileName),
.defaultValue.valueString = nil,
.dataTypeSpecific.className = NULL,
.fieldOptions = NULL,
},
};
GPBDescriptor *localDescriptor =
......@@ -59,15 +57,9 @@ typedef struct GPBSourceContext__storage_ {
rootClass:[GPBSourceContextRoot class]
file:GPBSourceContextRoot_FileDescriptor()
fields:fields
fieldCount:sizeof(fields) / sizeof(GPBMessageFieldDescription)
oneofs:NULL
oneofCount:0
enums:NULL
enumCount:0
ranges:NULL
rangeCount:0
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBSourceContext__storage_)
wireFormat:NO];
flags:0];
NSAssert(descriptor == nil, @"Startup recursed!");
descriptor = localDescriptor;
}
......
......@@ -3,7 +3,7 @@
#import "GPBProtocolBuffers.h"
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 30000
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 30001
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#endif
......
This diff is collapsed.
......@@ -3,7 +3,7 @@
#import "GPBProtocolBuffers.h"
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 30000
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 30001
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#endif
......
......@@ -46,25 +46,21 @@ typedef struct GPBTimestamp__storage_ {
static GPBMessageFieldDescription fields[] = {
{
.name = "seconds",
.dataTypeSpecific.className = NULL,
.number = GPBTimestamp_FieldNumber_Seconds,
.hasIndex = 0,
.offset = (uint32_t)offsetof(GPBTimestamp__storage_, seconds),
.flags = GPBFieldOptional,
.dataType = GPBDataTypeInt64,
.offset = offsetof(GPBTimestamp__storage_, seconds),
.defaultValue.valueInt64 = 0LL,
.dataTypeSpecific.className = NULL,
.fieldOptions = NULL,
},
{
.name = "nanos",
.dataTypeSpecific.className = NULL,
.number = GPBTimestamp_FieldNumber_Nanos,
.hasIndex = 1,
.offset = (uint32_t)offsetof(GPBTimestamp__storage_, nanos),
.flags = GPBFieldOptional,
.dataType = GPBDataTypeInt32,
.offset = offsetof(GPBTimestamp__storage_, nanos),
.defaultValue.valueInt32 = 0,
.dataTypeSpecific.className = NULL,
.fieldOptions = NULL,
},
};
GPBDescriptor *localDescriptor =
......@@ -72,15 +68,9 @@ typedef struct GPBTimestamp__storage_ {
rootClass:[GPBTimestampRoot class]
file:GPBTimestampRoot_FileDescriptor()
fields:fields
fieldCount:sizeof(fields) / sizeof(GPBMessageFieldDescription)
oneofs:NULL
oneofCount:0
enums:NULL
enumCount:0
ranges:NULL
rangeCount:0
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBTimestamp__storage_)
wireFormat:NO];
flags:0];
NSAssert(descriptor == nil, @"Startup recursed!");
descriptor = localDescriptor;
}
......
......@@ -3,7 +3,7 @@
#import "GPBProtocolBuffers.h"
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 30000
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 30001
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#endif
......
This diff is collapsed.
......@@ -3,7 +3,7 @@
#import "GPBProtocolBuffers.h"
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 30000
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 30001
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#endif
......
......@@ -122,16 +122,6 @@ void EnumGenerator::GenerateSource(io::Printer* printer) {
"\n",
"name", name_);
printer->Print(
"GPBEnumDescriptor *$name$_EnumDescriptor(void) {\n"
" static GPBEnumDescriptor *descriptor = NULL;\n"
" if (!descriptor) {\n"
" static GPBMessageEnumValueDescription values[] = {\n",
"name", name_);
printer->Indent();
printer->Indent();
printer->Indent();
// Note: For the TextFormat decode info, we can't use the enum value as
// the key because protocol buffer enums have 'allow_alias', which lets
// a value be used more than once. Instead, the index into the list of
......@@ -139,41 +129,66 @@ void EnumGenerator::GenerateSource(io::Printer* printer) {
// will be zero.
TextFormatDecodeData text_format_decode_data;
int enum_value_description_key = -1;
string text_blob;
for (int i = 0; i < all_values_.size(); i++) {
++enum_value_description_key;
string short_name(EnumValueShortName(all_values_[i]));
printer->Print("{ .name = \"$short_name$\", .number = $name$ },\n",
"short_name", short_name,
"name", EnumValueName(all_values_[i]));
text_blob += short_name + '\0';
if (UnCamelCaseEnumShortName(short_name) != all_values_[i]->name()) {
text_format_decode_data.AddString(enum_value_description_key, short_name,
all_values_[i]->name());
}
}
printer->Outdent();
printer->Outdent();
printer->Outdent();
printer->Print(
"GPBEnumDescriptor *$name$_EnumDescriptor(void) {\n"
" static GPBEnumDescriptor *descriptor = NULL;\n"
" if (!descriptor) {\n",
"name", name_);
static const int kBytesPerLine = 40; // allow for escaping
printer->Print(
" static const char *valueNames =");
for (int i = 0; i < text_blob.size(); i += kBytesPerLine) {
printer->Print(
"\n \"$data$\"",
"data", EscapeTrigraphs(CEscape(text_blob.substr(i, kBytesPerLine))));
}
printer->Print(
";\n"
" static const int32_t values[] = {\n");
for (int i = 0; i < all_values_.size(); i++) {
printer->Print(" $name$,\n", "name", EnumValueName(all_values_[i]));
}
printer->Print(" };\n");
if (text_format_decode_data.num_entries() == 0) {
printer->Print(
" descriptor = [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol($name$)\n"
" values:values\n"
" valueCount:sizeof(values) / sizeof(GPBMessageEnumValueDescription)\n"
" enumVerifier:$name$_IsValidValue];\n",
" GPBEnumDescriptor *worker =\n"
" [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol($name$)\n"
" valueNames:valueNames\n"
" values:values\n"
" count:(uint32_t)(sizeof(values) / sizeof(int32_t))\n"
" enumVerifier:$name$_IsValidValue];\n",
"name", name_);
} else {
printer->Print(
" static const char *extraTextFormatInfo = \"$extraTextFormatInfo$\";\n"
" descriptor = [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol($name$)\n"
" values:values\n"
" valueCount:sizeof(values) / sizeof(GPBMessageEnumValueDescription)\n"
" enumVerifier:$name$_IsValidValue\n"
" extraTextFormatInfo:extraTextFormatInfo];\n",
" GPBEnumDescriptor *worker =\n"
" [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol($name$)\n"
" valueNames:valueNames\n"
" values:values\n"
" count:(uint32_t)(sizeof(values) / sizeof(int32_t))\n"
" enumVerifier:$name$_IsValidValue\n"
" extraTextFormatInfo:extraTextFormatInfo];\n",
"name", name_,
"extraTextFormatInfo", CEscape(text_format_decode_data.Data()));
}
printer->Print(
" if (!OSAtomicCompareAndSwapPtrBarrier(nil, worker, (void * volatile *)&descriptor)) {\n"
" [worker release];\n"
" }\n"
" }\n"
" return descriptor;\n"
"}\n\n");
......
......@@ -59,6 +59,9 @@ void SetEnumVariables(const FieldDescriptor* descriptor,
(*variables)["enum_verifier"] = type + "_IsValidValue";
(*variables)["enum_desc_func"] = type + "_EnumDescriptor";
(*variables)["dataTypeSpecific_name"] = "enumDescFunc";
(*variables)["dataTypeSpecific_value"] = (*variables)["enum_desc_func"];
const Descriptor* msg_descriptor = descriptor->containing_type();
(*variables)["owning_message_class"] = ClassName(msg_descriptor);
}
......@@ -72,13 +75,6 @@ EnumFieldGenerator::EnumFieldGenerator(const FieldDescriptor* descriptor,
EnumFieldGenerator::~EnumFieldGenerator() {}
void EnumFieldGenerator::GenerateFieldDescriptionTypeSpecific(
io::Printer* printer) const {
printer->Print(
variables_,
" .dataTypeSpecific.enumDescFunc = $enum_desc_func$,\n");
}
void EnumFieldGenerator::GenerateCFunctionDeclarations(
io::Printer* printer) const {
if (!HasPreservingUnknownEnumSemantics(descriptor_->file())) {
......@@ -145,13 +141,6 @@ void RepeatedEnumFieldGenerator::FinishInitialization(void) {
"// |" + variables_["name"] + "| contains |" + variables_["storage_type"] + "|\n";
}
void RepeatedEnumFieldGenerator::GenerateFieldDescriptionTypeSpecific(
io::Printer* printer) const {
printer->Print(
variables_,
" .dataTypeSpecific.enumDescFunc = $enum_desc_func$,\n");
}
} // namespace objectivec
} // namespace compiler
} // namespace protobuf
......
......@@ -45,7 +45,6 @@ class EnumFieldGenerator : public SingleFieldGenerator {
const Options& options);
public:
virtual void GenerateFieldDescriptionTypeSpecific(io::Printer* printer) const;
virtual void GenerateCFunctionDeclarations(io::Printer* printer) const;
virtual void GenerateCFunctionImplementations(io::Printer* printer) const;
virtual void DetermineForwardDeclarations(set<string>* fwd_decls) const;
......@@ -64,7 +63,6 @@ class RepeatedEnumFieldGenerator : public RepeatedFieldGenerator {
public:
virtual void FinishInitialization();
virtual void GenerateFieldDescriptionTypeSpecific(io::Printer* printer) const;
protected:
RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor,
......
......@@ -114,14 +114,14 @@ void ExtensionGenerator::GenerateStaticVariablesInitialization(
printer->Print(vars,
"{\n"
" .defaultValue.$default_name$ = $default$,\n"
" .singletonName = GPBStringifySymbol($root_class_and_method_name$),\n"
" .dataType = $extension_type$,\n"
" .extendedClass = GPBStringifySymbol($extended_type$),\n"
" .fieldNumber = $number$,\n"
" .defaultValue.$default_name$ = $default$,\n"
" .messageOrGroupClassName = $type$,\n"
" .options = $options$,\n"
" .enumDescriptorFunc = $enum_desc_func_name$,\n"
" .fieldNumber = $number$,\n"
" .dataType = $extension_type$,\n"
" .options = $options$,\n"
"},\n");
}
......
......@@ -28,6 +28,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <iostream>
#include <google/protobuf/compiler/objectivec/objectivec_field.h>
#include <google/protobuf/compiler/objectivec/objectivec_helpers.h>
#include <google/protobuf/compiler/objectivec/objectivec_enum_field.h>
......@@ -75,7 +77,6 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor,
(*variables)["field_number_name"] =
classname + "_FieldNumber_" + capitalized_name;
(*variables)["field_number"] = SimpleItoa(descriptor->number());
(*variables)["has_index"] = SimpleItoa(descriptor->index());
(*variables)["field_type"] = GetCapitalizedType(descriptor);
std::vector<string> field_flags;
if (descriptor->is_repeated()) field_flags.push_back("GPBFieldRepeated");
......@@ -99,18 +100,9 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor,
(*variables)["dataTypeSpecific_name"] = "className";
(*variables)["dataTypeSpecific_value"] = "NULL";
string field_options = descriptor->options().SerializeAsString();
// Must convert to a standard byte order for packing length into
// a cstring.
uint32 length = ghtonl(field_options.length());
if (length > 0) {
string bytes((const char*)&length, sizeof(length));
bytes.append(field_options);
string options_str = "\"" + CEscape(bytes) + "\"";
(*variables)["fieldoptions"] = "\"" + CEscape(bytes) + "\"";
} else {
(*variables)["fieldoptions"] = "";
}
(*variables)["storage_offset_value"] =
"(uint32_t)offsetof(" + classname + "__storage_, " + camel_case_name + ")";
(*variables)["storage_offset_comment"] = "";
// Clear some common things so they can be set just when needed.
(*variables)["storage_attribute"] = "";
......@@ -190,52 +182,54 @@ void FieldGenerator::DetermineForwardDeclarations(
}
void FieldGenerator::GenerateFieldDescription(
io::Printer* printer) const {
printer->Print(
variables_,
"{\n"
" .name = \"$name$\",\n"
" .number = $field_number_name$,\n"
" .hasIndex = $has_index$,\n"
" .flags = $fieldflags$,\n"
" .dataType = GPBDataType$field_type$,\n"
" .offset = offsetof($classname$__storage_, $name$),\n"
" .defaultValue.$default_name$ = $default$,\n");
// TODO(thomasvl): It might be useful to add a CPP wrapper to support
// compiling away the EnumDescriptors. To do that, we'd need a #if here
// to control setting the descriptor vs. the validator, and above in
// SetCommonFieldVariables() we'd want to wrap how we add
// GPBFieldHasDefaultValue to the flags.
// " .dataTypeSpecific.value* = [something],"
GenerateFieldDescriptionTypeSpecific(printer);
const string& field_options(variables_.find("fieldoptions")->second);
if (field_options.empty()) {
printer->Print(" .fieldOptions = NULL,\n");
io::Printer* printer, bool include_default) const {
// Printed in the same order as the structure decl.
if (include_default) {
printer->Print(
variables_,
"{\n"
" .defaultValue.$default_name$ = $default$,\n"
" .core.name = \"$name$\",\n"
" .core.dataTypeSpecific.$dataTypeSpecific_name$ = $dataTypeSpecific_value$,\n"
" .core.number = $field_number_name$,\n"
" .core.hasIndex = $has_index$,\n"
" .core.offset = $storage_offset_value$,$storage_offset_comment$\n"
" .core.flags = $fieldflags$,\n"
" .core.dataType = GPBDataType$field_type$,\n"
"},\n");
} else {
// Can't use PrintRaw() here to get the #if/#else/#endif lines completely
// outdented because the need for indent captured on the previous
// printing of a \n and there is no way to get the current indent level
// to call the right number of Outdent()/Indents() to maintain state.
printer->Print(
variables_,
"#if GPBOBJC_INCLUDE_FIELD_OPTIONS\n"
" .fieldOptions = $fieldoptions$,\n"
"#else\n"
" .fieldOptions = NULL,\n"
"#endif // GPBOBJC_INCLUDE_FIELD_OPTIONS\n");
"{\n"
" .name = \"$name$\",\n"
" .dataTypeSpecific.$dataTypeSpecific_name$ = $dataTypeSpecific_value$,\n"
" .number = $field_number_name$,\n"
" .hasIndex = $has_index$,\n"
" .offset = $storage_offset_value$,$storage_offset_comment$\n"
" .flags = $fieldflags$,\n"
" .dataType = GPBDataType$field_type$,\n"
"},\n");
}
}
printer->Print("},\n");
void FieldGenerator::SetRuntimeHasBit(int has_index) {
variables_["has_index"] = SimpleItoa(has_index);
}
void FieldGenerator::GenerateFieldDescriptionTypeSpecific(
io::Printer* printer) const {
printer->Print(
variables_,
" .dataTypeSpecific.$dataTypeSpecific_name$ = $dataTypeSpecific_value$,\n");
void FieldGenerator::SetNoHasBit(void) {
variables_["has_index"] = "GPBNoHasBit";
}
int FieldGenerator::ExtraRuntimeHasBitsNeeded(void) const {
return 0;
}
void FieldGenerator::SetExtraRuntimeHasBitsBase(int index_base) {
// NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some
// error cases, so it seems to be ok to use as a back door for errors.
cerr << "Error: should have overriden SetExtraRuntimeHasBitsBase()." << endl;
cerr.flush();
abort();
}
void FieldGenerator::SetOneofIndexBase(int index_base) {
......@@ -302,6 +296,14 @@ bool SingleFieldGenerator::WantsHasProperty(void) const {
return false;
}
bool SingleFieldGenerator::RuntimeUsesHasBit(void) const {
if (descriptor_->containing_oneof() != NULL) {
// The oneof tracks what is set instead.
return false;
}
return true;
}
ObjCObjFieldGenerator::ObjCObjFieldGenerator(const FieldDescriptor* descriptor,
const Options& options)
: SingleFieldGenerator(descriptor, options) {
......@@ -347,8 +349,6 @@ void ObjCObjFieldGenerator::GeneratePropertyDeclaration(
RepeatedFieldGenerator::RepeatedFieldGenerator(
const FieldDescriptor* descriptor, const Options& options)
: ObjCObjFieldGenerator(descriptor, options) {
// Repeated fields don't use the has index.
variables_["has_index"] = "GPBNoHasBit";
// Default to no comment and let the cases needing it fill it in.
variables_["array_comment"] = "";
}
......@@ -402,6 +402,10 @@ bool RepeatedFieldGenerator::WantsHasProperty(void) const {
return false;
}
bool RepeatedFieldGenerator::RuntimeUsesHasBit(void) const {
return false; // The array having anything is what is used.
}
FieldGeneratorMap::FieldGeneratorMap(const Descriptor* descriptor,
const Options& options)
: descriptor_(descriptor),
......@@ -432,12 +436,40 @@ const FieldGenerator& FieldGeneratorMap::get_extension(int index) const {
return *extension_generators_[index];
}
int FieldGeneratorMap::CalculateHasBits(void) {
int total_bits = 0;
for (int i = 0; i < descriptor_->field_count(); i++) {
if (field_generators_[i]->RuntimeUsesHasBit()) {
field_generators_[i]->SetRuntimeHasBit(total_bits);
++total_bits;
} else {
field_generators_[i]->SetNoHasBit();
}
int extra_bits = field_generators_[i]->ExtraRuntimeHasBitsNeeded();
if (extra_bits) {
field_generators_[i]->SetExtraRuntimeHasBitsBase(total_bits);
total_bits += extra_bits;
}
}
return total_bits;
}
void FieldGeneratorMap::SetOneofIndexBase(int index_base) {
for (int i = 0; i < descriptor_->field_count(); i++) {
field_generators_[i]->SetOneofIndexBase(index_base);
}
}
bool FieldGeneratorMap::DoesAnyFieldHaveNonZeroDefault(void) const {
for (int i = 0; i < descriptor_->field_count(); i++) {
if (HasNonZeroDefaultValue(descriptor_->field(i))) {
return true;
}
}
return false;
}
} // namespace objectivec
} // namespace compiler
} // namespace protobuf
......
......@@ -61,7 +61,6 @@ class FieldGenerator {
// Called by GenerateFieldDescription, exposed for classes that need custom
// generation.
virtual void GenerateFieldDescriptionTypeSpecific(io::Printer* printer) const;
// Exposed for subclasses to extend, base does nothing.
virtual void GenerateCFunctionDeclarations(io::Printer* printer) const;
......@@ -71,9 +70,16 @@ class FieldGenerator {
virtual void DetermineForwardDeclarations(set<string>* fwd_decls) const;
// Used during generation, not intended to be extended by subclasses.
void GenerateFieldDescription(io::Printer* printer) const;
void GenerateFieldDescription(
io::Printer* printer, bool include_default) const;
void GenerateFieldNumberConstant(io::Printer* printer) const;
// Exposed to get and set the has bits information.
virtual bool RuntimeUsesHasBit(void) const = 0;
void SetRuntimeHasBit(int has_index);
void SetNoHasBit(void);
virtual int ExtraRuntimeHasBitsNeeded(void) const;
virtual void SetExtraRuntimeHasBitsBase(int index_base);
void SetOneofIndexBase(int index_base);
string variable(const char* key) const {
......@@ -109,6 +115,8 @@ class SingleFieldGenerator : public FieldGenerator {
virtual void GeneratePropertyImplementation(io::Printer* printer) const;
virtual bool RuntimeUsesHasBit(void) const;
protected:
SingleFieldGenerator(const FieldDescriptor* descriptor,
const Options& options);
......@@ -143,6 +151,8 @@ class RepeatedFieldGenerator : public ObjCObjFieldGenerator {
virtual void GeneratePropertyImplementation(io::Printer* printer) const;
virtual bool RuntimeUsesHasBit(void) const;
protected:
RepeatedFieldGenerator(const FieldDescriptor* descriptor,
const Options& options);
......@@ -162,8 +172,14 @@ class FieldGeneratorMap {
const FieldGenerator& get(const FieldDescriptor* field) const;
const FieldGenerator& get_extension(int index) const;
// Assigns the has bits and returns the number of bits needed.
int CalculateHasBits(void);
void SetOneofIndexBase(int index_base);
// Check if any field of this message has a non zero default.
bool DoesAnyFieldHaveNonZeroDefault(void) const;
private:
const Descriptor* descriptor_;
scoped_array<scoped_ptr<FieldGenerator> > field_generators_;
......
......@@ -45,7 +45,7 @@ namespace protobuf {
// This is also found in GPBBootstrap.h, and needs to be kept in sync. It
// is the version check done to ensure generated code works with the current
// runtime being used.
const int32 GOOGLE_PROTOBUF_OBJC_GEN_VERSION = 30000;
const int32 GOOGLE_PROTOBUF_OBJC_GEN_VERSION = 30001;
namespace compiler {
namespace objectivec {
......
......@@ -220,11 +220,6 @@ string NameFromFieldDescriptor(const FieldDescriptor* field) {
}
}
// Escape C++ trigraphs by escaping question marks to \?
string EscapeTrigraphs(const string& to_escape) {
return StringReplace(to_escape, "?", "\\?", true);
}
void PathSplit(const string& path, string* directory, string* basename) {
string::size_type last_slash = path.rfind('/');
if (last_slash == string::npos) {
......@@ -264,6 +259,11 @@ bool IsSpecialName(const string& name, const string* special_names,
} // namespace
// Escape C++ trigraphs by escaping question marks to \?
string EscapeTrigraphs(const string& to_escape) {
return StringReplace(to_escape, "?", "\\?", true);
}
string StripProto(const string& filename) {
if (HasSuffixString(filename, ".protodevel")) {
return StripSuffixString(filename, ".protodevel");
......@@ -734,7 +734,7 @@ string DefaultValue(const FieldDescriptor* field) {
uint32 length = ghtonl(default_string.length());
string bytes((const char*)&length, sizeof(length));
bytes.append(default_string);
return "(NSData*)\"" + CEscape(bytes) + "\"";
return "(NSData*)\"" + EscapeTrigraphs(CEscape(bytes)) + "\"";
} else {
return "@\"" + EscapeTrigraphs(CEscape(default_string)) + "\"";
}
......@@ -751,6 +751,50 @@ string DefaultValue(const FieldDescriptor* field) {
return NULL;
}
bool HasNonZeroDefaultValue(const FieldDescriptor* field) {
// Repeated fields don't have defaults.
if (field->is_repeated()) {
return false;
}
if (!field->has_default_value()) {
// No custom default set in the proto file.
return false;
}
// Some proto file set the default to the zero value, so make sure the value
// isn't the zero case.
switch (field->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32:
return field->default_value_int32() != 0;
case FieldDescriptor::CPPTYPE_UINT32:
return field->default_value_uint32() != 0U;
case FieldDescriptor::CPPTYPE_INT64:
return field->default_value_int64() != 0LL;
case FieldDescriptor::CPPTYPE_UINT64:
return field->default_value_uint64() != 0ULL;
case FieldDescriptor::CPPTYPE_DOUBLE:
return field->default_value_double() != 0.0;
case FieldDescriptor::CPPTYPE_FLOAT:
return field->default_value_float() != 0.0f;
case FieldDescriptor::CPPTYPE_BOOL:
return field->default_value_bool();
case FieldDescriptor::CPPTYPE_STRING: {
const string& default_string = field->default_value_string();
return default_string.length() != 0;
}
case FieldDescriptor::CPPTYPE_ENUM:
return field->default_value_enum()->number() != 0;
case FieldDescriptor::CPPTYPE_MESSAGE:
return false;
}
// Some compilers report reaching end of function even though all cases of
// the enum are handed in the switch.
GOOGLE_LOG(FATAL) << "Can't get here.";
return false;
}
string BuildFlagsString(const vector<string>& strings) {
if (strings.size() == 0) {
return "0";
......
......@@ -48,6 +48,9 @@ struct Options {
string expected_prefixes_path;
};
// Escape C++ trigraphs by escaping question marks to "\?".
string EscapeTrigraphs(const string& to_escape);
// Strips ".proto" or ".protodevel" from the end of a filename.
string StripProto(const string& filename);
......@@ -143,6 +146,7 @@ bool IsReferenceType(const FieldDescriptor* field);
string GPBGenericValueFieldName(const FieldDescriptor* field);
string DefaultValue(const FieldDescriptor* field);
bool HasNonZeroDefaultValue(const FieldDescriptor* field);
string BuildFlagsString(const vector<string>& strings);
......
......@@ -140,13 +140,18 @@ MapFieldGenerator::MapFieldGenerator(const FieldDescriptor* descriptor,
value_field_generator_->variable("storage_type") + "*>";
}
}
variables_["dataTypeSpecific_name"] =
value_field_generator_->variable("dataTypeSpecific_name");
variables_["dataTypeSpecific_value"] =
value_field_generator_->variable("dataTypeSpecific_value");
}
MapFieldGenerator::~MapFieldGenerator() {}
void MapFieldGenerator::FinishInitialization(void) {
RepeatedFieldGenerator::FinishInitialization();
// Use the array_comment suport in RepeatedFieldGenerator to output what the
// Use the array_comment support in RepeatedFieldGenerator to output what the
// values in the map are.
const FieldDescriptor* value_descriptor =
descriptor_->message_type()->FindFieldByName("value");
......@@ -156,13 +161,6 @@ void MapFieldGenerator::FinishInitialization(void) {
}
}
void MapFieldGenerator::GenerateFieldDescriptionTypeSpecific(
io::Printer* printer) const {
// Relay it to the value generator to provide enum validator, message
// class, etc.
value_field_generator_->GenerateFieldDescriptionTypeSpecific(printer);
}
void MapFieldGenerator::DetermineForwardDeclarations(
set<string>* fwd_decls) const {
RepeatedFieldGenerator::DetermineForwardDeclarations(fwd_decls);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment